From b69a5d17e266401901adf5e62ca7d4f4e94d82e0 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Thu, 5 Apr 2007 18:23:21 +0200 Subject: Added a new callback. This callback is called when a new entry is registered. The plan is register and call back a plugin loader function. --- src/xine-engine/configfile.c | 49 +++++++++++++++++++++++++++++++++----------- src/xine-engine/configfile.h | 19 ++++++++++++++++- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index 28b44fd51..c7cf30968 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -455,6 +455,8 @@ static void config_reset_value(cfg_entry_t *entry) { entry->num_value = 0; } +static void config_shallow_copy(xine_cfg_entry_t *dest, cfg_entry_t *src); + static cfg_entry_t *config_register_key (config_values_t *this, const char *key, int exp_level, @@ -488,6 +490,14 @@ static cfg_entry_t *config_register_key (config_values_t *this, entry->callback_data = cb_data; } + /* we created a new entry, call the callback */ + if (this->new_entry_cb) { + xine_cfg_entry_t cb_entry; + + config_shallow_copy(&cb_entry, entry); + this->new_entry_cb(this->new_entry_cbdata, &cb_entry); + } + return entry; } @@ -1186,6 +1196,19 @@ static void config_unregister_cb (config_values_t *this, const char *key) { } } +static void config_set_new_entry_callback (config_values_t *this, xine_config_cb_t new_entry_cb, void* cbdata) { + pthread_mutex_lock(&this->config_lock); + this->new_entry_cb = new_entry_cb; + this->new_entry_cbdata = cbdata; + pthread_mutex_unlock(&this->config_lock); +} + +static void config_unset_new_entry_callback (config_values_t *this) { + pthread_mutex_lock(&this->config_lock); + this->new_entry_cb = NULL; + this->new_entry_cbdata = NULL; + pthread_mutex_unlock(&this->config_lock); +} config_values_t *_x_config_init (void) { @@ -1212,18 +1235,20 @@ config_values_t *_x_config_init (void) { pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&this->config_lock, &attr); - this->register_string = config_register_string; - this->register_filename = config_register_filename; - this->register_range = config_register_range; - this->register_enum = config_register_enum; - this->register_num = config_register_num; - this->register_bool = config_register_bool; - this->update_num = config_update_num; - this->update_string = config_update_string; - this->parse_enum = config_parse_enum; - this->lookup_entry = config_lookup_entry; - this->unregister_callback = config_unregister_cb; - this->dispose = config_dispose; + this->register_string = config_register_string; + this->register_filename = config_register_filename; + this->register_range = config_register_range; + this->register_enum = config_register_enum; + this->register_num = config_register_num; + this->register_bool = config_register_bool; + this->update_num = config_update_num; + this->update_string = config_update_string; + this->parse_enum = config_parse_enum; + this->lookup_entry = config_lookup_entry; + this->unregister_callback = config_unregister_cb; + this->dispose = config_dispose; + this->set_new_entry_callback = config_set_new_entry_callback; + this->unset_new_entry_callback = config_unset_new_entry_callback; return this; } diff --git a/src/xine-engine/configfile.h b/src/xine-engine/configfile.h index 859214d1c..e98138fa3 100644 --- a/src/xine-engine/configfile.h +++ b/src/xine-engine/configfile.h @@ -50,6 +50,7 @@ extern "C" { typedef struct cfg_entry_s cfg_entry_t; typedef struct config_values_s config_values_t; + struct cfg_entry_s { cfg_entry_t *next; config_values_t *config; @@ -175,7 +176,7 @@ struct config_values_s { cfg_entry_t* (*lookup_entry) (config_values_t *self, const char *key); /* - * unregister callback function + * unregister entry callback function */ void (*unregister_callback) (config_values_t *self, const char *key); @@ -184,11 +185,27 @@ struct config_values_s { */ void (*dispose) (config_values_t *self); + /* + * callback called when a new config entry is registered + */ + void (*set_new_entry_callback) (config_values_t *self, xine_config_cb_t new_entry_cb, void *cb_data); + + /* + * unregister the callback + */ + void (*unset_new_entry_callback) (config_values_t *self); + /* * config values are stored here: */ cfg_entry_t *first, *last, *cur; + /* + * new entry callback + */ + xine_config_cb_t new_entry_cb; + void *new_entry_cbdata; + /* * mutex for modification to the config */ -- cgit v1.2.3 From 54ad01301df2b562e316a7910436ac1ff7494ac3 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Thu, 5 Apr 2007 19:00:10 +0200 Subject: Defined a callback for config entry registration. The next step is to add the entries to the node. --- src/xine-engine/load_plugins.c | 25 ++++++++++++++++++++++--- src/xine-engine/plugin_catalog.h | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index d35eba736..320fc0dd2 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -338,6 +338,7 @@ static void _insert_node (xine_t *this, entry->file = file; entry->ref = 0; entry->priority = 0; /* default priority */ + entry->config_entry_list = NULL; switch (info->type & PLUGIN_TYPE_MASK){ @@ -694,6 +695,17 @@ static inline int _plugin_info_equal(const plugin_info_t *a, return 1; } +/* + * This callback is called by the config entry system when a plugin register a + * new config entry. + */ +static void _new_entry_cb (void *user_data, xine_cfg_entry_t *entry) { + plugin_node_t *node = (plugin_node_t *)user_data; + /* + printf("_new_entry_cb: key %s, plugin id: %s\n", entry->key, node->info->id); + */ +} + static int _load_plugin_class(xine_t *this, plugin_node_t *node, void *data) { @@ -721,9 +733,16 @@ static int _load_plugin_class(xine_t *this, if ((info = dlsym(node->file->lib_handle, "xine_plugin_info"))) { /* TODO: use sigsegv handler */ - while (info->type != PLUGIN_NONE){ - if (_plugin_info_equal(info, target)){ - if ((node->plugin_class = info->init(this, data))) { + while (info->type != PLUGIN_NONE) { + if (_plugin_info_equal(info, target)) { + config_values_t *config = this->config; + + /* the callback is called for each entry registered by this plugin */ + config->set_new_entry_callback(config, _new_entry_cb, node); + node->plugin_class = info->init(this, data); + config->unset_new_entry_callback(config); + + if (node->plugin_class) { inc_file_ref(node->file); return 1; } else { diff --git a/src/xine-engine/plugin_catalog.h b/src/xine-engine/plugin_catalog.h index 5bd1c4701..26905ebff 100644 --- a/src/xine-engine/plugin_catalog.h +++ b/src/xine-engine/plugin_catalog.h @@ -57,6 +57,7 @@ typedef struct { plugin_file_t *file; plugin_info_t *info; void *plugin_class; + xine_list_t *config_entry_list; int ref; /* count intances of plugins */ int priority; } plugin_node_t ; -- cgit v1.2.3 From 90ec5563d6d3ce1abd5fc52d4aee1b0ecf6c7516 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Thu, 5 Apr 2007 19:14:48 +0200 Subject: Filled the config entry list when the callback is called. --- src/xine-engine/load_plugins.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index 320fc0dd2..f4be27587 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -704,6 +704,12 @@ static void _new_entry_cb (void *user_data, xine_cfg_entry_t *entry) { /* printf("_new_entry_cb: key %s, plugin id: %s\n", entry->key, node->info->id); */ + if (!node->config_entry_list) { + node->config_entry_list = xine_list_new(); + } + + xine_list_push_back(node->config_entry_list, (void *)entry->key); + } static int _load_plugin_class(xine_t *this, @@ -2603,6 +2609,10 @@ static void dispose_plugin_list (xine_sarray_t *list) { /* free info structure and string copies */ free (node->info->id); free (node->info); + + if (node->config_entry_list) { + xine_list_delete(node->config_entry_list); + } free (node); } xine_sarray_delete(list); -- cgit v1.2.3 From 42cbd632976d2c9d5293ad03418dce3c7db2797d Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Fri, 6 Apr 2007 15:28:37 +0200 Subject: - Moved base64 stuff to xine-utils. - Added config entry serialization. - Added serialized config entries to the plugin cache. --HG-- rename : src/input/base64.c => src/xine-utils/base64.c rename : src/input/base64.h => src/xine-utils/base64.h --- src/input/Makefile.am | 2 +- src/input/base64.c | 135 ---------------------------- src/input/base64.h | 95 -------------------- src/xine-engine/configfile.c | 136 ++++++++++++++++++++++++++++ src/xine-engine/configfile.h | 15 ++++ src/xine-engine/load_plugins.c | 45 ++++++---- src/xine-utils/Makefile.am | 6 +- src/xine-utils/base64.c | 198 +++++++++++++++++++++++++++++++++++++++++ src/xine-utils/base64.h | 98 ++++++++++++++++++++ src/xine-utils/xineutils.h | 2 + 10 files changed, 483 insertions(+), 249 deletions(-) delete mode 100644 src/input/base64.c delete mode 100644 src/input/base64.h create mode 100644 src/xine-utils/base64.c create mode 100644 src/xine-utils/base64.h diff --git a/src/input/Makefile.am b/src/input/Makefile.am index 68adf84be..1b6378efc 100644 --- a/src/input/Makefile.am +++ b/src/input/Makefile.am @@ -126,7 +126,7 @@ xineplug_inp_rtsp_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) libreal/libreal.la lib xineplug_inp_rtsp_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) xineplug_inp_rtsp_la_LDFLAGS = -avoid-version -module -xineplug_inp_cdda_la_SOURCES = input_cdda.c media_helper.c sha1.c sha1.h base64.c base64.h +xineplug_inp_cdda_la_SOURCES = input_cdda.c media_helper.c sha1.c sha1.h xineplug_inp_cdda_la_LIBADD = $(XINE_LIB) xineplug_inp_cdda_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) xineplug_inp_cdda_la_LDFLAGS = -avoid-version -module diff --git a/src/input/base64.c b/src/input/base64.c deleted file mode 100644 index 0eccbe84e..000000000 --- a/src/input/base64.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2000 Robert Kaye - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * Base64 encoding modified for Musicbrainz - * relicensed under the GNU General Public License for use in xine-lib - * - */ -/* -------------------------------------------------------------------------- - - MusicBrainz -- The Internet music metadatabase - - Copyright (C) 2000 Robert Kaye - - This library 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. - - This library 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 this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - $Id: base64.c,v 1.2 2004/05/05 18:44:19 mroi Exp $ - -----------------------------------------------------------------------------*/ -/* - * Program: RFC-822 routines (originally from SMTP) - * - * Author: Mark Crispin - * Networks and Distributed Computing - * Computing & Communications - * University of Washington - * Administration Building, AG-44 - * Seattle, WA 98195 - * Internet: MRC@CAC.Washington.EDU - * - * Date: 27 July 1988 - * Last Edited: 10 September 1998 - * - * Sponsorship: The original version of this work was developed in the - * Symbolic Systems Resources Group of the Knowledge Systems - * Laboratory at Stanford University in 1987-88, and was funded - * by the Biomedical Research Technology Program of the National - * Institutes of Health under grant number RR-00785. - * - * Original version Copyright 1988 by The Leland Stanford Junior University - * Copyright 1998 by the University of Washington - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, provided - * that the above copyright notices appear in all copies and that both the - * above copyright notices and this permission notice appear in supporting - * documentation, and that the name of the University of Washington or The - * Leland Stanford Junior University not be used in advertising or publicity - * pertaining to distribution of the software without specific, written prior - * permission. This software is made available "as is", and - * THE UNIVERSITY OF WASHINGTON AND THE LELAND STANFORD JUNIOR UNIVERSITY - * DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO THIS SOFTWARE, - * INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF - * WASHINGTON OR THE LELAND STANFORD JUNIOR UNIVERSITY BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -#include -#include -#include -#include - -#include "base64.h" - - -/* NOTE: This is not true RFC822 anymore. The use of the characters - '/', '+', and '=' is no bueno when the ID will be used as part of a URL. - '_', '.', and '-' have been used instead -*/ - -/* Convert binary contents to BASE64 - * Accepts: source - * length of source - * pointer to return destination length - * Returns: destination as BASE64 - */ - -unsigned char *rfc822_binary (void *src,unsigned long srcl,unsigned long *len) -{ - unsigned char *ret,*d; - unsigned char *s = (unsigned char *) src; - char *v = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._"; - unsigned long i = ((srcl + 2) / 3) * 4; - *len = i += 2 * ((i / 60) + 1); - d = ret = (unsigned char *) malloc ((size_t) ++i); - for (i = 0; srcl; s += 3) { /* process tuplets */ - *d++ = v[s[0] >> 2]; /* byte 1: high 6 bits (1) */ - /* byte 2: low 2 bits (1), high 4 bits (2) */ - *d++ = v[((s[0] << 4) + (--srcl ? (s[1] >> 4) : 0)) & 0x3f]; - /* byte 3: low 4 bits (2), high 2 bits (3) */ - *d++ = srcl ? v[((s[1] << 2) + (--srcl ? (s[2] >> 6) : 0)) & 0x3f] : '-'; - /* byte 4: low 6 bits (3) */ - *d++ = srcl ? v[s[2] & 0x3f] : '-'; - if (srcl) srcl--; /* count third character if processed */ - if ((++i) == 15) { /* output 60 characters? */ - i = 0; /* restart line break count, insert CRLF */ - *d++ = '\015'; *d++ = '\012'; - } - } - *d = '\0'; /* tie off string */ - - return ret; /* return the resulting string */ -} diff --git a/src/input/base64.h b/src/input/base64.h deleted file mode 100644 index 72feef885..000000000 --- a/src/input/base64.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2000 Robert Kaye - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA - * - * Base64 encoding modified for Musicbrainz - * relicensed under the GNU General Public License for use in xine-lib - * - */ -/* -------------------------------------------------------------------------- - - MusicBrainz -- The Internet music metadatabase - - Copyright (C) 2000 Robert Kaye - - This library 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. - - This library 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 this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - $Id: base64.h,v 1.1 2004/05/05 09:11:39 hadess Exp $ - -----------------------------------------------------------------------------*/ -/* - * Program: RFC-822 routines (originally from SMTP) - * - * Author: Mark Crispin - * Networks and Distributed Computing - * Computing & Communications - * University of Washington - * Administration Building, AG-44 - * Seattle, WA 98195 - * Internet: MRC@CAC.Washington.EDU - * - * Date: 27 July 1988 - * Last Edited: 10 September 1998 - * - * Sponsorship: The original version of this work was developed in the - * Symbolic Systems Resources Group of the Knowledge Systems - * Laboratory at Stanford University in 1987-88, and was funded - * by the Biomedical Research Technology Program of the National - * Institutes of Health under grant number RR-00785. - * - * Original version Copyright 1988 by The Leland Stanford Junior University - * Copyright 1998 by the University of Washington - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, provided - * that the above copyright notices appear in all copies and that both the - * above copyright notices and this permission notice appear in supporting - * documentation, and that the name of the University of Washington or The - * Leland Stanford Junior University not be used in advertising or publicity - * pertaining to distribution of the software without specific, written prior - * permission. This software is made available "as is", and - * THE UNIVERSITY OF WASHINGTON AND THE LELAND STANFORD JUNIOR UNIVERSITY - * DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO THIS SOFTWARE, - * INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF - * WASHINGTON OR THE LELAND STANFORD JUNIOR UNIVERSITY BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -#ifndef BASE64_H -#define BASE64_H - -unsigned char *rfc822_binary (void *src,unsigned long srcl,unsigned long *len); - -#endif diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index c7cf30968..fce6e4a30 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -1210,6 +1210,139 @@ static void config_unset_new_entry_callback (config_values_t *this) { pthread_mutex_unlock(&this->config_lock); } +static void config_register_entry (config_values_t *this, cfg_entry_t* entry) { + /* FIXME: TODO */ +} + +static int put_int(uint8_t *buffer, int pos, int value) { + int32_t value_int32 = (int32_t)value; + + buffer[pos] = value_int32 & 0xFF; + buffer[pos + 1] = (value_int32 >> 8) & 0xFF; + buffer[pos + 2] = (value_int32 >> 16) & 0xFF; + buffer[pos + 3] = (value_int32 >> 24) & 0xFF; + + return 4; +} + +static int put_string(uint8_t *buffer, int pos, const char *value, int value_len) { + pos += put_int(buffer, pos, value_len); + memcpy(&buffer[pos], value, value_len); + + return 4 + value_len; +} + +static unsigned char* config_serialize_entry (config_values_t *this, const char *key) { + unsigned char *output = NULL; + cfg_entry_t *entry, *prev; + + pthread_mutex_lock(&this->config_lock); + config_lookup_entry_int(this, key, &entry, &prev); + + if (entry) { + /* now serialize this stuff + fields to serialize : + int type; + int range_min; + int range_max; + int exp_level; + char *key; + char *str_default; + char *description; + char *help; + char **enum_values; + */ + + int key_len = 0; + int str_default_len = 0; + int description_len = 0; + int help_len = 0; + + if (entry->key) + key_len = strlen(entry->key); + if (entry->str_default) + str_default_len = strlen(entry->str_default); + if (entry->description) + description_len = strlen(entry->description); + if (entry->help) + help_len = strlen(entry->help); + + // integers + // value: 4 bytes + unsigned long total_len = 4 * sizeof(int32_t); + + // strings (size + char buffer) + // length: 4 bytes + // buffer: length bytes + total_len += sizeof(int32_t) + key_len; + total_len += sizeof(int32_t) + str_default_len; + total_len += sizeof(int32_t) + description_len; + total_len += sizeof(int32_t) + help_len; + + /* enum values... */ + // value count: 4 bytes + // for each value: + // length: 4 bytes + // buffer: length bytes + int value_count = 0; + int value_len[10]; + total_len += sizeof(int32_t); /* value count */ + + char **cur_value = entry->enum_values; + if (cur_value) { + while (*cur_value && (value_count < (sizeof(value_len) / sizeof(int) ))) { + value_len[value_count] = strlen(*cur_value); + total_len += sizeof(int32_t) + value_len[value_count]; + value_count++; + cur_value++; + } + } + + /* Now we have the length needed to serialize the entry and the length of each string */ + uint8_t *buffer = malloc (total_len); + if (!buffer) return NULL; + + /* Let's go */ + int pos = 0; + + // the integers + pos += put_int(buffer, pos, entry->type); + pos += put_int(buffer, pos, entry->range_min); + pos += put_int(buffer, pos, entry->range_max); + pos += put_int(buffer, pos, entry->exp_level); + + // the strings + pos += put_string(buffer, pos, entry->key, key_len); + pos += put_string(buffer, pos, entry->str_default, str_default_len); + pos += put_string(buffer, pos, entry->description, description_len); + pos += put_string(buffer, pos, entry->help, help_len); + + // the enum stuff + pos += put_int(buffer, pos, value_count); + cur_value = entry->enum_values; + + int i; + for (i = 0; i < value_count; i++) { + pos += put_string(buffer, pos, *cur_value, value_len[i]); + cur_value++; + } + + // and now the output encoding + unsigned long output_len; + output = base64_encode (buffer, total_len, &output_len); + + free(buffer); + } + pthread_mutex_unlock(&this->config_lock); + + return output; +} + +static cfg_entry_t* config_deserialize_entry (config_values_t *this, const char *value) { + /* FIXME: TODO */ + return NULL; +} + config_values_t *_x_config_init (void) { #ifdef HAVE_IRIXAL @@ -1249,6 +1382,9 @@ config_values_t *_x_config_init (void) { this->dispose = config_dispose; this->set_new_entry_callback = config_set_new_entry_callback; this->unset_new_entry_callback = config_unset_new_entry_callback; + this->register_entry = config_register_entry; + this->serialize_entry = config_serialize_entry; + this->deserialize_entry = config_deserialize_entry; return this; } diff --git a/src/xine-engine/configfile.h b/src/xine-engine/configfile.h index e98138fa3..e1416432b 100644 --- a/src/xine-engine/configfile.h +++ b/src/xine-engine/configfile.h @@ -157,6 +157,8 @@ struct config_values_s { xine_config_cb_t changed_cb, void *cb_data); + void (*register_entry) (config_values_t *self, cfg_entry_t* entry); + /* convenience function to update range, enum, num and bool values */ void (*update_num) (config_values_t *self, const char *key, int value); @@ -195,6 +197,19 @@ struct config_values_s { */ void (*unset_new_entry_callback) (config_values_t *self); + /* + * serialize a config entry. + * return a base64 null terminated string. + */ + char* (*serialize_entry) (config_values_t *self, const char *key); + + /* + * deserialize a config entry. + * value is a base 64 encoded string + */ + cfg_entry_t* (*deserialize_entry) (config_values_t *self, const char *value); + + /* * config values are stored here: */ diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index f4be27587..b2d2f1d9d 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -701,15 +701,12 @@ static inline int _plugin_info_equal(const plugin_info_t *a, */ static void _new_entry_cb (void *user_data, xine_cfg_entry_t *entry) { plugin_node_t *node = (plugin_node_t *)user_data; - /* - printf("_new_entry_cb: key %s, plugin id: %s\n", entry->key, node->info->id); - */ + if (!node->config_entry_list) { node->config_entry_list = xine_list_new(); } xine_list_push_back(node->config_entry_list, (void *)entry->key); - } static int _load_plugin_class(xine_t *this, @@ -857,7 +854,7 @@ static void load_required_plugins(xine_t *this) { /* * save plugin list information to file (cached catalog) */ -static void save_plugin_list(FILE *fp, xine_sarray_t *list) { +static void save_plugin_list(xine_t *this, FILE *fp, xine_sarray_t *list) { const plugin_node_t *node; const plugin_file_t *file; @@ -867,7 +864,6 @@ static void save_plugin_list(FILE *fp, xine_sarray_t *list) { const vo_info_t *vo_info; const ao_info_t *ao_info; const post_info_t *post_info; - int i; int list_id = 0; int list_size; @@ -884,9 +880,9 @@ static void save_plugin_list(FILE *fp, xine_sarray_t *list) { fprintf(fp, "api=%d\n", node->info->API ); fprintf(fp, "id=%s\n", node->info->id ); fprintf(fp, "version=%lu\n", (unsigned long) node->info->version ); - + switch (node->info->type & PLUGIN_TYPE_MASK){ - + case PLUGIN_VIDEO_OUT: vo_info = node->info->special_info; fprintf(fp, "visual_type=%d\n", vo_info->visual_type ); @@ -914,7 +910,7 @@ static void save_plugin_list(FILE *fp, xine_sarray_t *list) { demuxer_info = node->info->special_info; fprintf(fp, "demuxer_priority=%d\n", demuxer_info->priority); break; - + case PLUGIN_INPUT: input_info = node->info->special_info; fprintf(fp, "input_priority=%d\n", input_info->priority); @@ -922,10 +918,27 @@ static void save_plugin_list(FILE *fp, xine_sarray_t *list) { case PLUGIN_POST: post_info = node->info->special_info; - fprintf(fp, "post_type=%lu\n", (unsigned long)post_info->type); - break; - } - + fprintf(fp, "post_type=%lu\n", (unsigned long)post_info->type); + break; + } + + if (node->config_entry_list) + { + xine_list_iterator_t ite = xine_list_front(node->config_entry_list); + while (ite) { + char *key = xine_list_get_value(node->config_entry_list, ite); + + /* now get the representation of the config key */ + char *key_value = this->config->serialize_entry(this->config, key); + + printf(" config key: %s, serialization: %d bytes\n", key, strlen(key_value)); + fprintf(fp, "config_key=%s\n", key_value); + + free (key_value); + ite = xine_list_next(node->config_entry_list, ite); + } + } + fprintf(fp, "\n"); list_id++; } @@ -1120,7 +1133,7 @@ static void save_catalog (xine_t *this) { fprintf(fp, "cache_catalog_version=%d\n\n", CACHE_CATALOG_VERSION); for (i = 0; i < PLUGIN_TYPE_MAX; i++) { - save_plugin_list (fp, this->plugin_catalog->plugin_lists[i]); + save_plugin_list (this, fp, this->plugin_catalog->plugin_lists[i]); } fclose(fp); } @@ -1206,9 +1219,9 @@ void _x_scan_plugins (xine_t *this) { free(pluginpath); free(homedir); - save_catalog (this); - load_required_plugins (this); + + save_catalog (this); map_decoders (this); } diff --git a/src/xine-utils/Makefile.am b/src/xine-utils/Makefile.am index 95de06b9e..8bef77b4c 100644 --- a/src/xine-utils/Makefile.am +++ b/src/xine-utils/Makefile.am @@ -30,7 +30,8 @@ libxineutils_la_SOURCES = $(pppc_files) \ array.c \ sorted_array.c \ pool.c \ - ring_buffer.c + ring_buffer.c \ + base64.c xineinclude_HEADERS = \ attributes.h \ @@ -43,7 +44,8 @@ xineinclude_HEADERS = \ array.h \ sorted_array.h \ pool.h \ - ring_buffer.h + ring_buffer.h \ + base64.h noinst_HEADERS = ppcasm_string.h xine_check.h diff --git a/src/xine-utils/base64.c b/src/xine-utils/base64.c new file mode 100644 index 000000000..358cbbada --- /dev/null +++ b/src/xine-utils/base64.c @@ -0,0 +1,198 @@ +/* + * Copyright (C) 2000 Robert Kaye + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * Base64 encoding modified for Musicbrainz + * relicensed under the GNU General Public License for use in xine-lib + * + */ +/* -------------------------------------------------------------------------- + + MusicBrainz -- The Internet music metadatabase + + Copyright (C) 2000 Robert Kaye + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + $Id: base64.c,v 1.2 2004/05/05 18:44:19 mroi Exp $ + +----------------------------------------------------------------------------*/ +/* + * Program: RFC-822 routines (originally from SMTP) + * + * Author: Mark Crispin + * Networks and Distributed Computing + * Computing & Communications + * University of Washington + * Administration Building, AG-44 + * Seattle, WA 98195 + * Internet: MRC@CAC.Washington.EDU + * + * Date: 27 July 1988 + * Last Edited: 10 September 1998 + * + * Sponsorship: The original version of this work was developed in the + * Symbolic Systems Resources Group of the Knowledge Systems + * Laboratory at Stanford University in 1987-88, and was funded + * by the Biomedical Research Technology Program of the National + * Institutes of Health under grant number RR-00785. + * + * Original version Copyright 1988 by The Leland Stanford Junior University + * Copyright 1998 by the University of Washington + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notices appear in all copies and that both the + * above copyright notices and this permission notice appear in supporting + * documentation, and that the name of the University of Washington or The + * Leland Stanford Junior University not be used in advertising or publicity + * pertaining to distribution of the software without specific, written prior + * permission. This software is made available "as is", and + * THE UNIVERSITY OF WASHINGTON AND THE LELAND STANFORD JUNIOR UNIVERSITY + * DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO THIS SOFTWARE, + * INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF + * WASHINGTON OR THE LELAND STANFORD JUNIOR UNIVERSITY BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#include +#include +#include +#include + +#include "base64.h" + + +/* NOTE: This is not true RFC822 anymore. The use of the characters + '/', '+', and '=' is no bueno when the ID will be used as part of a URL. + '_', '.', and '-' have been used instead +*/ + +/* Convert binary contents to BASE64 + * Accepts: source + * length of source + * pointer to return destination length + * Returns: destination as BASE64 + */ + +unsigned char *rfc822_binary (void *src,unsigned long srcl,unsigned long *len) +{ + unsigned char *ret,*d; + unsigned char *s = (unsigned char *) src; + char *v = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._"; + unsigned long i = ((srcl + 2) / 3) * 4; + *len = i += 2 * ((i / 60) + 1); + d = ret = (unsigned char *) malloc ((size_t) ++i); + for (i = 0; srcl; s += 3) { /* process tuplets */ + *d++ = v[s[0] >> 2]; /* byte 1: high 6 bits (1) */ + /* byte 2: low 2 bits (1), high 4 bits (2) */ + *d++ = v[((s[0] << 4) + (--srcl ? (s[1] >> 4) : 0)) & 0x3f]; + /* byte 3: low 4 bits (2), high 2 bits (3) */ + *d++ = srcl ? v[((s[1] << 2) + (--srcl ? (s[2] >> 6) : 0)) & 0x3f] : '-'; + /* byte 4: low 6 bits (3) */ + *d++ = srcl ? v[s[2] & 0x3f] : '-'; + if (srcl) srcl--; /* count third character if processed */ + if ((++i) == 15) { /* output 60 characters? */ + i = 0; /* restart line break count, insert CRLF */ + *d++ = '\015'; *d++ = '\012'; + } + } + *d = '\0'; /* tie off string */ + + return ret; /* return the resulting string */ +} + +unsigned char *base64_encode (void *src,unsigned long srcl,unsigned long *len) +{ + unsigned char *ret,*d; + unsigned char *s = (unsigned char *) src; + char *v = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._"; + unsigned long i = ((srcl + 2) / 3) * 4; + *len = i; + d = ret = (unsigned char *) malloc ((size_t) ++i); + for (i = 0; srcl; s += 3) { /* process tuplets */ + *d++ = v[s[0] >> 2]; /* byte 1: high 6 bits (1) */ + /* byte 2: low 2 bits (1), high 4 bits (2) */ + *d++ = v[((s[0] << 4) + (--srcl ? (s[1] >> 4) : 0)) & 0x3f]; + /* byte 3: low 4 bits (2), high 2 bits (3) */ + *d++ = srcl ? v[((s[1] << 2) + (--srcl ? (s[2] >> 6) : 0)) & 0x3f] : '-'; + /* byte 4: low 6 bits (3) */ + *d++ = srcl ? v[s[2] & 0x3f] : '-'; + if (srcl) srcl--; /* count third character if processed */ + } + *d = '\0'; /* tie off string */ + + return ret; /* return the resulting string */ +} + +void *base64_decode (unsigned char *src,unsigned long srcl,unsigned long *len) +{ + void *ret; + unsigned char *d; + unsigned long i = ((srcl + 3) / 4) * 3; + *len = i; + d = ret = (void *) malloc ((size_t)i); + for (i = 0; srcl; src += 4) { /* process tuplets */ + unsigned char tuplet[4]; + int j; + + for (j = 0; j < 4; j += 1) { + if (srcl) { + if ((src[j] >= 'A') && (src[j] <= 'Z')) { + tuplet[j] = src[j] - 'A'; + } else if ((src[j] >= 'a') && (src[j] <= 'z')) { + tuplet[j] = src[j] - 'a' + 26; + } else if ((src[j] >= '0') && (src[j] <= '9')) { + tuplet[j] = src[j] - '0' + 52; + } else if (src[j] == '.') { + tuplet[j] = 62; + } else if (src[j] == '_') { + tuplet[j] = 63; + } else { + tuplet[j] = 64; + } + srcl--; + } else { + tuplet[j] = 64; + } + } + + *d++ = (tuplet[0] << 2) + ((tuplet[1] & 0x3f) >> 4); + *d++ = (tuplet[1] << 4) + ((tuplet[2] & 0x3f) >> 2); + *d++ = (tuplet[2] << 6) + (tuplet[3] & 0x3f); + } + + return ret; /* return the resulting string */ +} diff --git a/src/xine-utils/base64.h b/src/xine-utils/base64.h new file mode 100644 index 000000000..6a45aebc6 --- /dev/null +++ b/src/xine-utils/base64.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2000 Robert Kaye + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * Base64 encoding modified for Musicbrainz + * relicensed under the GNU General Public License for use in xine-lib + * + */ +/* -------------------------------------------------------------------------- + + MusicBrainz -- The Internet music metadatabase + + Copyright (C) 2000 Robert Kaye + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + $Id: base64.h,v 1.1 2004/05/05 09:11:39 hadess Exp $ + +----------------------------------------------------------------------------*/ +/* + * Program: RFC-822 routines (originally from SMTP) + * + * Author: Mark Crispin + * Networks and Distributed Computing + * Computing & Communications + * University of Washington + * Administration Building, AG-44 + * Seattle, WA 98195 + * Internet: MRC@CAC.Washington.EDU + * + * Date: 27 July 1988 + * Last Edited: 10 September 1998 + * + * Sponsorship: The original version of this work was developed in the + * Symbolic Systems Resources Group of the Knowledge Systems + * Laboratory at Stanford University in 1987-88, and was funded + * by the Biomedical Research Technology Program of the National + * Institutes of Health under grant number RR-00785. + * + * Original version Copyright 1988 by The Leland Stanford Junior University + * Copyright 1998 by the University of Washington + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notices appear in all copies and that both the + * above copyright notices and this permission notice appear in supporting + * documentation, and that the name of the University of Washington or The + * Leland Stanford Junior University not be used in advertising or publicity + * pertaining to distribution of the software without specific, written prior + * permission. This software is made available "as is", and + * THE UNIVERSITY OF WASHINGTON AND THE LELAND STANFORD JUNIOR UNIVERSITY + * DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO THIS SOFTWARE, + * INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF + * WASHINGTON OR THE LELAND STANFORD JUNIOR UNIVERSITY BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#ifndef BASE64_H +#define BASE64_H + +unsigned char *rfc822_binary (void *src,unsigned long srcl,unsigned long *len); + +unsigned char *base64_encode (void *src,unsigned long srcl,unsigned long *len); +void *base64_decode (unsigned char *src,unsigned long srcl,unsigned long *len); + +#endif diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h index 03c5f689a..9985c133b 100644 --- a/src/xine-utils/xineutils.h +++ b/src/xine-utils/xineutils.h @@ -46,6 +46,7 @@ extern "C" { # include "list.h" # include "array.h" # include "sorted_array.h" +# include "base64.h" #else # ifdef WIN32 # include @@ -61,6 +62,7 @@ extern "C" { # include # include # include +# include #endif #include -- cgit v1.2.3 From 0ce330ec329e1d15a49ae5c5ea4741bcfbf924d3 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Tue, 10 Apr 2007 18:45:53 +0200 Subject: Config entry deserialization. --- src/xine-engine/configfile.c | 228 ++++++++++++++++++++++++++++++++++------- src/xine-engine/configfile.h | 5 +- src/xine-engine/load_plugins.c | 73 ++++++++----- src/xine-utils/base64.c | 10 +- src/xine-utils/base64.h | 4 +- 5 files changed, 252 insertions(+), 68 deletions(-) diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index fce6e4a30..22d677e0b 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -34,6 +34,7 @@ #include #include #include +#include "bswap.h" #include "configfile.h" #define LOG_MODULE "configfile" @@ -1210,10 +1211,6 @@ static void config_unset_new_entry_callback (config_values_t *this) { pthread_mutex_unlock(&this->config_lock); } -static void config_register_entry (config_values_t *this, cfg_entry_t* entry) { - /* FIXME: TODO */ -} - static int put_int(uint8_t *buffer, int pos, int value) { int32_t value_int32 = (int32_t)value; @@ -1232,8 +1229,8 @@ static int put_string(uint8_t *buffer, int pos, const char *value, int value_len return 4 + value_len; } -static unsigned char* config_serialize_entry (config_values_t *this, const char *key) { - unsigned char *output = NULL; +static char* config_get_serialized_entry (config_values_t *this, const char *key) { + char *output = NULL; cfg_entry_t *entry, *prev; pthread_mutex_lock(&this->config_lock); @@ -1246,6 +1243,8 @@ static unsigned char* config_serialize_entry (config_values_t *this, const char int range_min; int range_max; int exp_level; + int num_default; + int num_value; char *key; char *str_default; char *description; @@ -1257,6 +1256,12 @@ static unsigned char* config_serialize_entry (config_values_t *this, const char int str_default_len = 0; int description_len = 0; int help_len = 0; + unsigned long output_len; + unsigned long total_len; + int value_count; + int value_len[10]; + int pos = 0; + int i; if (entry->key) key_len = strlen(entry->key); @@ -1269,7 +1274,7 @@ static unsigned char* config_serialize_entry (config_values_t *this, const char // integers // value: 4 bytes - unsigned long total_len = 4 * sizeof(int32_t); + total_len = 6 * sizeof(int32_t); // strings (size + char buffer) // length: 4 bytes @@ -1284,8 +1289,7 @@ static unsigned char* config_serialize_entry (config_values_t *this, const char // for each value: // length: 4 bytes // buffer: length bytes - int value_count = 0; - int value_len[10]; + value_count = 0; total_len += sizeof(int32_t); /* value count */ char **cur_value = entry->enum_values; @@ -1303,32 +1307,31 @@ static unsigned char* config_serialize_entry (config_values_t *this, const char if (!buffer) return NULL; /* Let's go */ - int pos = 0; - // the integers + /* the integers */ pos += put_int(buffer, pos, entry->type); pos += put_int(buffer, pos, entry->range_min); pos += put_int(buffer, pos, entry->range_max); pos += put_int(buffer, pos, entry->exp_level); + pos += put_int(buffer, pos, entry->num_default); + pos += put_int(buffer, pos, entry->num_value); - // the strings + /* the strings */ pos += put_string(buffer, pos, entry->key, key_len); pos += put_string(buffer, pos, entry->str_default, str_default_len); pos += put_string(buffer, pos, entry->description, description_len); pos += put_string(buffer, pos, entry->help, help_len); - // the enum stuff + /* the enum stuff */ pos += put_int(buffer, pos, value_count); cur_value = entry->enum_values; - int i; for (i = 0; i < value_count; i++) { pos += put_string(buffer, pos, *cur_value, value_len[i]); cur_value++; } - // and now the output encoding - unsigned long output_len; + /* and now the output encoding */ output = base64_encode (buffer, total_len, &output_len); free(buffer); @@ -1336,10 +1339,166 @@ static unsigned char* config_serialize_entry (config_values_t *this, const char pthread_mutex_unlock(&this->config_lock); return output; + } -static cfg_entry_t* config_deserialize_entry (config_values_t *this, const char *value) { - /* FIXME: TODO */ +static int get_int(uint8_t *buffer, int buffer_size, int pos, int *value) { + int32_t value_int32; + + if ((pos + sizeof(int32_t)) > buffer_size) + return 0; + + value_int32 = LE_32(&buffer[pos]); + *value = (int)value_int32; + return sizeof(int32_t); +} + +static int get_string(uint8_t *buffer, int buffer_size, int pos, char **value) { + int len; + int bytes = get_int(buffer, buffer_size, pos, &len); + *value = NULL; + + if (!bytes || (len < 0) || (len > 1024*64)) + return 0; + + char *str = malloc(len + 1); + pos += bytes; + memcpy(str, &buffer[pos], len); + str[len] = 0; + + *value = str; + return bytes + len; +} + +static char* config_register_serialized_entry (config_values_t *this, const char *value) { + + /* + fields serialized : + int type; + int range_min; + int range_max; + int exp_level; + int num_default; + int num_value; + char *key; + char *str_default; + char *description; + char *help; + char **enum_values; + */ + int type; + int range_min; + int range_max; + int exp_level; + int num_default; + int num_value; + char *key; + char *str_default; + char *description; + char *help; + char **enum_values; + + int bytes; + int pos; + void *output; + unsigned long output_len; + int value_count; + int i; + + output = base64_decode (value, strlen(value), &output_len); + + pos = 0; + pos += bytes = get_int(output, output_len, pos, &type); + if (!bytes) goto error; + + pos += bytes = get_int(output, output_len, pos, &range_min); + if (!bytes) goto error; + + pos += bytes = get_int(output, output_len, pos, &range_max); + if (!bytes) goto error; + + pos += bytes = get_int(output, output_len, pos, &exp_level); + if (!bytes) goto error; + + pos += bytes = get_int(output, output_len, pos, &num_default); + if (!bytes) goto error; + + pos += bytes = get_int(output, output_len, pos, &num_value); + if (!bytes) goto error; + + pos += bytes = get_string(output, output_len, pos, &key); + if (!bytes) goto error; + + pos += bytes = get_string(output, output_len, pos, &str_default); + if (!bytes) goto error; + + pos += bytes = get_string(output, output_len, pos, &description); + if (!bytes) goto error; + + pos += bytes = get_string(output, output_len, pos, &help); + if (!bytes) goto error; + + pos += bytes = get_int(output, output_len, pos, &value_count); + if (!bytes) goto error; + if ((value_count < 0) || (value_count > 256)) goto error; + + enum_values = malloc (sizeof(void*) * value_count + 1); + for (i = 0; i < value_count; i++) { + pos += bytes = get_string(output, output_len, pos, &enum_values[i]); + if (!bytes) goto error; + } + enum_values[value_count] = NULL; + +#if LOG + printf("config entry deserialization:\n"); + printf(" key : %s\n", key); + printf(" type : %d\n", type); + printf(" exp_level : %d\n", exp_level); + printf(" num_default: %d\n", num_default); + printf(" num_value : %d\n", num_value); + printf(" str_default: %s\n", str_default); + printf(" range_min : %d\n", range_min); + printf(" range_max : %d\n", range_max); + printf(" description: %s\n", description); + printf(" help : %s\n", help); + printf(" enum : %d values\n", value_count); + + for (i = 0; i < value_count; i++) { + printf(" enum[%2d]: %s\n", i, enum_values[i]); + } + printf("\n"); +#endif + + switch (type) { + case XINE_CONFIG_TYPE_STRING: + switch (num_value) { + case 0: + this->register_string(this, key, str_default, description, help, exp_level, NULL, NULL); + default: + this->register_filename(this, key, str_default, num_value, description, help, exp_level, NULL, NULL); + } + break; + case XINE_CONFIG_TYPE_RANGE: + this->register_range(this, key, num_default, range_min, range_max, description, help, exp_level, NULL, NULL); + break; + case XINE_CONFIG_TYPE_ENUM: + this->register_enum(this, key, num_default, enum_values, description, help, exp_level, NULL, NULL); + break; + case XINE_CONFIG_TYPE_NUM: + this->register_num(this, key, num_default, description, help, exp_level, NULL, NULL); + break; + case XINE_CONFIG_TYPE_BOOL: + this->register_bool(this, key, num_default, description, help, exp_level, NULL, NULL); + break; + case XINE_CONFIG_TYPE_UNKNOWN: + break; + } + + + return key; + +error: + /* serialization error */ return NULL; } @@ -1368,23 +1527,22 @@ config_values_t *_x_config_init (void) { pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&this->config_lock, &attr); - this->register_string = config_register_string; - this->register_filename = config_register_filename; - this->register_range = config_register_range; - this->register_enum = config_register_enum; - this->register_num = config_register_num; - this->register_bool = config_register_bool; - this->update_num = config_update_num; - this->update_string = config_update_string; - this->parse_enum = config_parse_enum; - this->lookup_entry = config_lookup_entry; - this->unregister_callback = config_unregister_cb; - this->dispose = config_dispose; - this->set_new_entry_callback = config_set_new_entry_callback; - this->unset_new_entry_callback = config_unset_new_entry_callback; - this->register_entry = config_register_entry; - this->serialize_entry = config_serialize_entry; - this->deserialize_entry = config_deserialize_entry; + this->register_string = config_register_string; + this->register_filename = config_register_filename; + this->register_range = config_register_range; + this->register_enum = config_register_enum; + this->register_num = config_register_num; + this->register_bool = config_register_bool; + this->register_serialized_entry = config_register_serialized_entry; + this->update_num = config_update_num; + this->update_string = config_update_string; + this->parse_enum = config_parse_enum; + this->lookup_entry = config_lookup_entry; + this->unregister_callback = config_unregister_cb; + this->dispose = config_dispose; + this->set_new_entry_callback = config_set_new_entry_callback; + this->unset_new_entry_callback = config_unset_new_entry_callback; + this->get_serialized_entry = config_get_serialized_entry; return this; } diff --git a/src/xine-engine/configfile.h b/src/xine-engine/configfile.h index e1416432b..a4f4b34ec 100644 --- a/src/xine-engine/configfile.h +++ b/src/xine-engine/configfile.h @@ -201,13 +201,14 @@ struct config_values_s { * serialize a config entry. * return a base64 null terminated string. */ - char* (*serialize_entry) (config_values_t *self, const char *key); + char* (*get_serialized_entry) (config_values_t *self, const char *key); /* * deserialize a config entry. * value is a base 64 encoded string + * return the key of the serialized entry */ - cfg_entry_t* (*deserialize_entry) (config_values_t *self, const char *value); + char* (*register_serialized_entry) (config_values_t *self, const char *value); /* diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index b2d2f1d9d..2b7177511 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -64,6 +64,8 @@ #include "xineutils.h" #include "compat.h" +#define LINE_MAX_LENGTH (1024 * 32) /* 32 KiB */ + #if 0 static char *plugin_name; @@ -695,6 +697,15 @@ static inline int _plugin_info_equal(const plugin_info_t *a, return 1; } +static void _attach_entry_to_node (plugin_node_t *node, void *key) { + + if (!node->config_entry_list) { + node->config_entry_list = xine_list_new(); + } + + xine_list_push_back(node->config_entry_list, key); +} + /* * This callback is called by the config entry system when a plugin register a * new config entry. @@ -702,11 +713,7 @@ static inline int _plugin_info_equal(const plugin_info_t *a, static void _new_entry_cb (void *user_data, xine_cfg_entry_t *entry) { plugin_node_t *node = (plugin_node_t *)user_data; - if (!node->config_entry_list) { - node->config_entry_list = xine_list_new(); - } - - xine_list_push_back(node->config_entry_list, (void *)entry->key); + _attach_entry_to_node(node, (void *)entry->key); } static int _load_plugin_class(xine_t *this, @@ -922,16 +929,16 @@ static void save_plugin_list(xine_t *this, FILE *fp, xine_sarray_t *list) { break; } - if (node->config_entry_list) - { + /* config entries */ + if (node->config_entry_list) { xine_list_iterator_t ite = xine_list_front(node->config_entry_list); while (ite) { char *key = xine_list_get_value(node->config_entry_list, ite); /* now get the representation of the config key */ - char *key_value = this->config->serialize_entry(this->config, key); + char *key_value = this->config->get_serialized_entry(this->config, key); - printf(" config key: %s, serialization: %d bytes\n", key, strlen(key_value)); + lprintf(" config key: %s, serialization: %d bytes\n", key, strlen(key_value)); fprintf(fp, "config_key=%s\n", key_value); free (key_value); @@ -947,7 +954,7 @@ static void save_plugin_list(xine_t *this, FILE *fp, xine_sarray_t *list) { /* * load plugin list information from file (cached catalog) */ -static void load_plugin_list(FILE *fp, xine_sarray_t *plugins) { +static void load_plugin_list(xine_t *this, FILE *fp, xine_sarray_t *plugins) { plugin_node_t *node; plugin_file_t *file; @@ -960,20 +967,29 @@ static void load_plugin_list(FILE *fp, xine_sarray_t *plugins) { int i; uint64_t llu; unsigned long lu; - char line[1024]; + char *line; char *value; + size_t line_len; int version_ok = 0; + line = malloc(LINE_MAX_LENGTH); + if (!line) + return; + node = NULL; file = NULL; - while (fgets (line, 1023, fp)) { + while (fgets (line, LINE_MAX_LENGTH, fp)) { if (line[0] == '#') continue; - - if( (value = strchr(line, '\r')) || (value = strchr(line, '\n')) ) - *value = (char) 0; /* eliminate any cr/lf */ + line_len = strlen(line); + if (line_len < 3) + continue; + + value = &line[line_len - 1]; + if( (*value == '\r') || (*value == '\n') ) + *value-- = (char) 0; /* eliminate any cr/lf */ - if( (value = strchr(line, '\r')) || (value = strchr(line, '\n')) ) + if( (*value == '\r') || (*value == '\n') ) *value = (char) 0; /* eliminate any cr/lf */ if (line[0] == '[' && version_ok) { @@ -1048,11 +1064,11 @@ static void load_plugin_list(FILE *fp, xine_sarray_t *plugins) { xine_xmalloc(sizeof(decoder_info_t)); break; - case PLUGIN_POST: - node->info->special_info = post_info = - xine_xmalloc(sizeof(post_info_t)); - break; - } + case PLUGIN_POST: + node->info->special_info = post_info = + xine_xmalloc(sizeof(post_info_t)); + break; + } } else if( !strcmp("api",line) ) { sscanf(value," %d",&i); @@ -1092,8 +1108,15 @@ static void load_plugin_list(FILE *fp, xine_sarray_t *plugins) { sscanf(value," %d",&i); input_info->priority = i; } else if( !strcmp("post_type",line) && post_info ) { - sscanf(value," %lu",&lu); - post_info->type = lu; + sscanf(value," %lu",&lu); + post_info->type = lu; + } else if( !strcmp("config_key",line) ) { + char* cfg_key; + + cfg_key = this->config->register_serialized_entry(this->config, value); + if (cfg_key != NULL) { + _attach_entry_to_node(node, cfg_key); + } } } } @@ -1102,6 +1125,8 @@ static void load_plugin_list(FILE *fp, xine_sarray_t *plugins) { if( node ) { xine_sarray_add (plugins, node); } + + free (line); } @@ -1154,7 +1179,7 @@ static void load_cached_catalog (xine_t *this) { sprintf(cachefile, "%s/%s", xine_get_homedir(), relname); if( (fp = fopen(cachefile,"r")) != NULL ) { - load_plugin_list (fp, this->plugin_catalog->cache_list); + load_plugin_list (this, fp, this->plugin_catalog->cache_list); fclose(fp); } free(cachefile); diff --git a/src/xine-utils/base64.c b/src/xine-utils/base64.c index 358cbbada..af6e2eadf 100644 --- a/src/xine-utils/base64.c +++ b/src/xine-utils/base64.c @@ -134,14 +134,14 @@ unsigned char *rfc822_binary (void *src,unsigned long srcl,unsigned long *len) return ret; /* return the resulting string */ } -unsigned char *base64_encode (void *src,unsigned long srcl,unsigned long *len) +char *base64_encode (const void *src, unsigned long srcl, unsigned long *len) { - unsigned char *ret,*d; + char *ret, *d; unsigned char *s = (unsigned char *) src; char *v = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._"; unsigned long i = ((srcl + 2) / 3) * 4; *len = i; - d = ret = (unsigned char *) malloc ((size_t) ++i); + d = ret = (char *) malloc ((size_t) ++i); for (i = 0; srcl; s += 3) { /* process tuplets */ *d++ = v[s[0] >> 2]; /* byte 1: high 6 bits (1) */ /* byte 2: low 2 bits (1), high 4 bits (2) */ @@ -157,7 +157,7 @@ unsigned char *base64_encode (void *src,unsigned long srcl,unsigned long *len) return ret; /* return the resulting string */ } -void *base64_decode (unsigned char *src,unsigned long srcl,unsigned long *len) +void *base64_decode (const char *src, unsigned long srcl, unsigned long *len) { void *ret; unsigned char *d; @@ -185,7 +185,7 @@ void *base64_decode (unsigned char *src,unsigned long srcl,unsigned long *len) } srcl--; } else { - tuplet[j] = 64; + (*len)--; } } diff --git a/src/xine-utils/base64.h b/src/xine-utils/base64.h index 6a45aebc6..409d4c64e 100644 --- a/src/xine-utils/base64.h +++ b/src/xine-utils/base64.h @@ -92,7 +92,7 @@ unsigned char *rfc822_binary (void *src,unsigned long srcl,unsigned long *len); -unsigned char *base64_encode (void *src,unsigned long srcl,unsigned long *len); -void *base64_decode (unsigned char *src,unsigned long srcl,unsigned long *len); +char *base64_encode (const void *src, unsigned long srcl, unsigned long *len); +void *base64_decode (const char *src, unsigned long srcl, unsigned long *len); #endif -- cgit v1.2.3 From 3dc931e217272f0781ef8f7d7ed228467fe5604c Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Wed, 11 Apr 2007 14:49:02 +0200 Subject: Released allocated strings. Added some profiling (XINE_PROFILE). --- src/xine-engine/configfile.c | 60 ++++++++++++++++++++++++------------------ src/xine-engine/load_plugins.c | 23 ++++++++++------ src/xine-engine/xine.c | 3 ++- 3 files changed, 52 insertions(+), 34 deletions(-) diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index 22d677e0b..294da5700 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -1371,7 +1371,6 @@ static int get_string(uint8_t *buffer, int buffer_size, int pos, char **value) { } static char* config_register_serialized_entry (config_values_t *this, const char *value) { - /* fields serialized : int type; @@ -1392,60 +1391,60 @@ static char* config_register_serialized_entry (config_values_t *this, const char int exp_level; int num_default; int num_value; - char *key; - char *str_default; - char *description; - char *help; - char **enum_values; + char *key = NULL; + char *str_default = NULL; + char *description = NULL; + char *help = NULL; + char **enum_values = NULL; int bytes; int pos; - void *output; + void *output = NULL; unsigned long output_len; - int value_count; + int value_count = 0; int i; output = base64_decode (value, strlen(value), &output_len); pos = 0; pos += bytes = get_int(output, output_len, pos, &type); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_int(output, output_len, pos, &range_min); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_int(output, output_len, pos, &range_max); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_int(output, output_len, pos, &exp_level); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_int(output, output_len, pos, &num_default); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_int(output, output_len, pos, &num_value); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_string(output, output_len, pos, &key); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_string(output, output_len, pos, &str_default); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_string(output, output_len, pos, &description); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_string(output, output_len, pos, &help); - if (!bytes) goto error; + if (!bytes) goto exit; pos += bytes = get_int(output, output_len, pos, &value_count); - if (!bytes) goto error; - if ((value_count < 0) || (value_count > 256)) goto error; + if (!bytes) goto exit; + if ((value_count < 0) || (value_count > 256)) goto exit; enum_values = malloc (sizeof(void*) * value_count + 1); for (i = 0; i < value_count; i++) { pos += bytes = get_string(output, output_len, pos, &enum_values[i]); - if (!bytes) goto error; + if (!bytes) goto exit; } enum_values[value_count] = NULL; @@ -1474,8 +1473,10 @@ static char* config_register_serialized_entry (config_values_t *this, const char switch (num_value) { case 0: this->register_string(this, key, str_default, description, help, exp_level, NULL, NULL); + break; default: this->register_filename(this, key, str_default, num_value, description, help, exp_level, NULL, NULL); + break; } break; case XINE_CONFIG_TYPE_RANGE: @@ -1494,12 +1495,21 @@ static char* config_register_serialized_entry (config_values_t *this, const char break; } +exit: + /* cleanup */ + free(str_default); + free(description); + free(help); + free(output); + + if (enum_values) { + for (i = 0; i < value_count; i++) { + free(enum_values[i]); + } + free(enum_values); + } return key; - -error: - /* serialization error */ - return NULL; } config_values_t *_x_config_init (void) { diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index 2b7177511..fc708db13 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -48,6 +48,7 @@ /* #define LOG +#define DEBUG */ #define XINE_ENABLE_EXPERIMENTAL_FEATURES 1 @@ -697,7 +698,7 @@ static inline int _plugin_info_equal(const plugin_info_t *a, return 1; } -static void _attach_entry_to_node (plugin_node_t *node, void *key) { +static void _attach_entry_to_node (plugin_node_t *node, char *key) { if (!node->config_entry_list) { node->config_entry_list = xine_list_new(); @@ -713,7 +714,7 @@ static void _attach_entry_to_node (plugin_node_t *node, void *key) { static void _new_entry_cb (void *user_data, xine_cfg_entry_t *entry) { plugin_node_t *node = (plugin_node_t *)user_data; - _attach_entry_to_node(node, (void *)entry->key); + _attach_entry_to_node(node, strdup(entry->key)); } static int _load_plugin_class(xine_t *this, @@ -935,7 +936,7 @@ static void save_plugin_list(xine_t *this, FILE *fp, xine_sarray_t *list) { while (ite) { char *key = xine_list_get_value(node->config_entry_list, ite); - /* now get the representation of the config key */ + /* now serialize the config key */ char *key_value = this->config->get_serialized_entry(this->config, key); lprintf(" config key: %s, serialization: %d bytes\n", key, strlen(key_value)); @@ -1205,7 +1206,7 @@ void _x_scan_plugins (xine_t *this) { homedir = strdup(xine_get_homedir()); this->plugin_catalog = _new_catalog(); - load_cached_catalog (this); + XINE_PROFILE(load_cached_catalog (this)); if ((pluginpath = getenv("XINE_PLUGIN_PATH")) != NULL) { pluginpath = strdup(pluginpath); @@ -1227,7 +1228,7 @@ void _x_scan_plugins (xine_t *this) { case XINE_PATH_SEPARATOR_CHAR: case '\0': plugindir[j] = '\0'; - collect_plugins(this, plugindir); + XINE_PROFILE(collect_plugins(this, plugindir)); j = 0; break; case '~': @@ -1244,9 +1245,9 @@ void _x_scan_plugins (xine_t *this) { free(pluginpath); free(homedir); - load_required_plugins (this); + /* load_required_plugins (this); */ - save_catalog (this); + XINE_PROFILE(save_catalog (this)); map_decoders (this); } @@ -2649,7 +2650,13 @@ static void dispose_plugin_list (xine_sarray_t *list) { free (node->info); if (node->config_entry_list) { - xine_list_delete(node->config_entry_list); + xine_list_iterator_t ite = xine_list_front (node->config_entry_list); + while (ite) { + char *key = xine_list_get_value (node->config_entry_list, ite); + free (key); + ite = xine_list_next (node->config_entry_list, ite); + } + xine_list_delete(node->config_entry_list); } free (node); } diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index f49a988c9..32c2d7672 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -51,6 +51,7 @@ #define LOG_VERBOSE /* #define LOG +#define DEBUG */ #define XINE_ENABLE_EXPERIMENTAL_FEATURES @@ -1547,7 +1548,7 @@ void xine_init (xine_t *this) { /* * plugins */ - _x_scan_plugins(this); + XINE_PROFILE(_x_scan_plugins(this)); #ifdef HAVE_SETLOCALE if (!setlocale(LC_CTYPE, "")) -- cgit v1.2.3 From ab2c5817538265f0e8411b3ebabf8ad29bce807b Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Thu, 12 Apr 2007 17:15:47 +0200 Subject: Fixed double free problem. --- src/xine-engine/configfile.c | 22 +++++++------ src/xine-engine/load_plugins.c | 71 +++++++++++++++++++++++++--------------- src/xine-engine/plugin_catalog.h | 2 +- 3 files changed, 57 insertions(+), 38 deletions(-) diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index 294da5700..0d3ec4bd1 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -1272,23 +1272,25 @@ static char* config_get_serialized_entry (config_values_t *this, const char *key if (entry->help) help_len = strlen(entry->help); - // integers - // value: 4 bytes + /* integers */ + /* value: 4 bytes */ total_len = 6 * sizeof(int32_t); - // strings (size + char buffer) - // length: 4 bytes - // buffer: length bytes + /* strings (size + char buffer) + * length: 4 bytes + * buffer: length bytes + */ total_len += sizeof(int32_t) + key_len; total_len += sizeof(int32_t) + str_default_len; total_len += sizeof(int32_t) + description_len; total_len += sizeof(int32_t) + help_len; - /* enum values... */ - // value count: 4 bytes - // for each value: - // length: 4 bytes - // buffer: length bytes + /* enum values... + * value count: 4 bytes + * for each value: + * length: 4 bytes + * buffer: length bytes + */ value_count = 0; total_len += sizeof(int32_t); /* value count */ diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index fc708db13..f34b3bb66 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -252,26 +252,26 @@ static void _decoder_priority_cb(void *data, xine_cfg_entry_t *cfg) { map_decoders((xine_t *)data); } -static plugin_info_t *_get_cached_info (xine_t *this, +static plugin_node_t *_get_cached_node (xine_t *this, char *filename, off_t filesize, time_t filemtime, - plugin_info_t *previous_info) { + plugin_node_t *previous_node) { xine_sarray_t *list = this->plugin_catalog->cache_list; int list_id, list_size; list_size = xine_sarray_size (list); for (list_id = 0; list_id < list_size; list_id++) { plugin_node_t *node = xine_sarray_get (list, list_id); - if( !previous_info && + if( !previous_node && node->file->filesize == filesize && node->file->filemtime == filemtime && !strcmp( node->file->filename, filename )) { - return node->info; + return node; } /* skip previously returned items */ - if( node->info == previous_info ) - previous_info = NULL; + if( node == previous_node ) + previous_node = NULL; } return NULL; @@ -301,6 +301,7 @@ static plugin_file_t *_insert_file (xine_t *this, static void _insert_node (xine_t *this, xine_sarray_t *list, plugin_file_t *file, + plugin_node_t *node_cache, plugin_info_t *info, int api_version){ @@ -341,7 +342,7 @@ static void _insert_node (xine_t *this, entry->file = file; entry->ref = 0; entry->priority = 0; /* default priority */ - entry->config_entry_list = NULL; + entry->config_entry_list = (node_cache) ? node_cache->config_entry_list : NULL; switch (info->type & PLUGIN_TYPE_MASK){ @@ -489,7 +490,8 @@ static plugin_catalog_t *_new_catalog(void){ return catalog; } -static void _register_plugins_internal(xine_t *this, plugin_file_t *file, plugin_info_t *info) { +static void _register_plugins_internal(xine_t *this, plugin_file_t *file, + plugin_node_t *node_cache, plugin_info_t *info) { _x_assert(this); _x_assert(info); @@ -515,7 +517,7 @@ static void _register_plugins_internal(xine_t *this, plugin_file_t *file, plugin int plugin_type = info->type & PLUGIN_TYPE_MASK; if ((plugin_type > 0) && (plugin_type <= PLUGIN_TYPE_MAX)) { - _insert_node (this, this->plugin_catalog->plugin_lists[plugin_type - 1], file, info, + _insert_node (this, this->plugin_catalog->plugin_lists[plugin_type - 1], file, node_cache, info, plugin_iface_versions[plugin_type - 1]); if ((plugin_type == PLUGIN_AUDIO_DECODER) || @@ -539,15 +541,17 @@ static void _register_plugins_internal(xine_t *this, plugin_file_t *file, plugin /* get next info */ if( file && !file->lib_handle ) { lprintf("get cached info\n"); - info = _get_cached_info (this, file->filename, file->filesize, file->filemtime, info); + node_cache = _get_cached_node (this, file->filename, file->filesize, file->filemtime, node_cache); + info = (node_cache) ? node_cache->info : NULL; } else { + info++; } } } void xine_register_plugins(xine_t *self, plugin_info_t *info) { - _register_plugins_internal(self, NULL, info); + _register_plugins_internal(self, NULL, NULL, info); } /* @@ -578,6 +582,7 @@ static void collect_plugins(xine_t *this, char *path){ size_t new_str_size, d_len; void *lib = NULL; plugin_info_t *info = NULL; + plugin_node_t *node = NULL; struct stat statbuffer; @@ -620,7 +625,8 @@ static void collect_plugins(xine_t *this, char *path){ lib = NULL; /* get the first plugin_info_t */ - info = _get_cached_info (this, str, statbuffer.st_size, statbuffer.st_mtime, NULL); + node = _get_cached_node (this, str, statbuffer.st_size, statbuffer.st_mtime, NULL); + info = (node) ? node->info : NULL; #ifdef LOG if( info ) printf("load_plugins: using cached %s\n", str); @@ -641,7 +647,7 @@ static void collect_plugins(xine_t *this, char *path){ file = _insert_file(this, this->plugin_catalog->file_list, str, &statbuffer, lib); - _register_plugins_internal(this, file, info); + _register_plugins_internal(this, file, node, info); } else { const char *error = dlerror(); @@ -749,6 +755,7 @@ static int _load_plugin_class(xine_t *this, config_values_t *config = this->config; /* the callback is called for each entry registered by this plugin */ + lprintf("plugin init %s\n", node->info->id); config->set_new_entry_callback(config, _new_entry_cb, node); node->plugin_class = info->init(this, data); config->unset_new_entry_callback(config); @@ -832,8 +839,12 @@ static void _load_required_plugins(xine_t *this, xine_sarray_t *list) { while (list_id < list_size) { plugin_node_t *node = xine_sarray_get(list, list_id); - if( (node->info->type & PLUGIN_MUST_PRELOAD) && !node->plugin_class ) { - + /* + * preload plugins if not cached + */ + if( (node->info->type & PLUGIN_MUST_PRELOAD) && !node->plugin_class && + node->file->lib_handle ) { + lprintf("preload plugin %s from %s\n", node->info->id, node->file->filename); if (! _load_plugin_class (this, node, NULL)) { @@ -1115,8 +1126,11 @@ static void load_plugin_list(xine_t *this, FILE *fp, xine_sarray_t *plugins) { char* cfg_key; cfg_key = this->config->register_serialized_entry(this->config, value); - if (cfg_key != NULL) { + if (cfg_key) { + /* this node is a cached node */ _attach_entry_to_node(node, cfg_key); + } else { + lprintf("failed to deserialize config entry key\n"); } } } @@ -1245,7 +1259,7 @@ void _x_scan_plugins (xine_t *this) { free(pluginpath); free(homedir); - /* load_required_plugins (this); */ + load_required_plugins (this); XINE_PROFILE(save_catalog (this)); @@ -2611,7 +2625,7 @@ char *xine_get_demux_for_mime_type (xine_t *self, const char *mime_type) { } -static void dispose_plugin_list (xine_sarray_t *list) { +static void dispose_plugin_list (xine_sarray_t *list, int is_cache) { plugin_node_t *node; decoder_info_t *decoder_info; @@ -2649,14 +2663,17 @@ static void dispose_plugin_list (xine_sarray_t *list) { free (node->info->id); free (node->info); - if (node->config_entry_list) { - xine_list_iterator_t ite = xine_list_front (node->config_entry_list); - while (ite) { - char *key = xine_list_get_value (node->config_entry_list, ite); - free (key); - ite = xine_list_next (node->config_entry_list, ite); + /* don't free the entry list if the node is cache */ + if (!is_cache) { + if (node->config_entry_list) { + xine_list_iterator_t ite = xine_list_front (node->config_entry_list); + while (ite) { + char *key = xine_list_get_value (node->config_entry_list, ite); + free (key); + ite = xine_list_next (node->config_entry_list, ite); + } + xine_list_delete(node->config_entry_list); } - xine_list_delete(node->config_entry_list); } free (node); } @@ -2690,10 +2707,10 @@ void _x_dispose_plugins (xine_t *this) { int i; for (i = 0; i < PLUGIN_TYPE_MAX; i++) { - dispose_plugin_list (this->plugin_catalog->plugin_lists[i]); + dispose_plugin_list (this->plugin_catalog->plugin_lists[i], 0); } - dispose_plugin_list (this->plugin_catalog->cache_list); + dispose_plugin_list (this->plugin_catalog->cache_list, 1); dispose_plugin_file_list (this->plugin_catalog->file_list); for (i = 0; this->plugin_catalog->prio_desc[i]; i++) diff --git a/src/xine-engine/plugin_catalog.h b/src/xine-engine/plugin_catalog.h index 26905ebff..909756e2b 100644 --- a/src/xine-engine/plugin_catalog.h +++ b/src/xine-engine/plugin_catalog.h @@ -40,7 +40,7 @@ /* the engine takes this many plugins for one stream type */ #define PLUGINS_PER_TYPE 10 -#define CACHE_CATALOG_VERSION 2 +#define CACHE_CATALOG_VERSION 3 #define CACHE_CATALOG_FILE ".xine/catalog.cache" #define CACHE_CATALOG_DIR ".xine" -- cgit v1.2.3 From 7598a6152ba55ef0ff8dda7f1b7729d2bb22a594 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Wed, 6 Jun 2007 23:36:19 +0100 Subject: Correctly check for LOG being defined. --HG-- extra : transplant_source : %DFs%84N%8AG%00%5B%EFv%FF%E6%CD%93%23%D8%E6%A1%C2%18 --- src/xine-engine/configfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index 0d3ec4bd1..38f2c5a6c 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -1450,7 +1450,7 @@ static char* config_register_serialized_entry (config_values_t *this, const char } enum_values[value_count] = NULL; -#if LOG +#ifdef LOG printf("config entry deserialization:\n"); printf(" key : %s\n", key); printf(" type : %d\n", type); -- cgit v1.2.3 From 417f829c79afef229ef61c77672686f2b644b5c4 Mon Sep 17 00:00:00 2001 From: Christophe Giraud Date: Tue, 1 Jan 2008 22:02:11 +0100 Subject: Updated French translation. --- po/fr.po | 863 ++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 437 insertions(+), 426 deletions(-) diff --git a/po/fr.po b/po/fr.po index 62a74b1b7..e96d85c55 100644 --- a/po/fr.po +++ b/po/fr.po @@ -1,57 +1,59 @@ -# Frensh xine-lib.po file. -# Copyright (C) 2002 Free Software Foundation, Inc. -# Daniel Caujolle-Bert , 2001 -# +# translation of fr.po to français +# Daniel Caujolle-Bert , 2001. +# Christophe Giraud , 2007, 2008. +# French xine-lib.po file. +# Copyright (C) 2002, 2007, 2008 Free Software Foundation, Inc. msgid "" msgstr "" -"Project-Id-Version: xine-lib 0.9.13\n" +"Project-Id-Version: xine-lib 1.1.9\n" "Report-Msgid-Bugs-To: xine-devel@lists.sourceforge.net\n" "POT-Creation-Date: 2007-12-24 18:34+0000\n" -"PO-Revision-Date: 2002-06-07 15:08 +0200\n" -"Last-Translator: Daniel Caujolle-Bert \n" -"Language-Team: French \n" +"PO-Revision-Date: 2008-01-01 15:18+0100\n" +"Last-Translator: Christophe Giraud \n" +"Language-Team: french \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8-bit\n" +"Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" +"X-Generator: KBabel 1.11.4\n" #: lib/hstrerror.c:17 msgid "No error" -msgstr "" +msgstr "Aucune erreur" #: lib/hstrerror.c:18 msgid "Unknown host" -msgstr "" +msgstr "Hôte inconnu" #: lib/hstrerror.c:19 msgid "No address associated with name" -msgstr "" +msgstr "Aucune adresse associée à ce nom" #: lib/hstrerror.c:20 msgid "Unknown server error" -msgstr "" +msgstr "Erreur du serveur inconnue" #: lib/hstrerror.c:21 msgid "Host name lookup failure" -msgstr "" +msgstr "La recherche du nom d'hôte a échouée" #: lib/hstrerror.c:22 msgid "Unknown error" -msgstr "" +msgstr "Erreur inconnue" #: src/audio_out/audio_alsa_out.c:350 #, c-format msgid "audio_alsa_out:Already open...WHY!" -msgstr "" +msgstr "audio_alsa_out: Déjà ouvert...POURQUOI!" #: src/audio_out/audio_alsa_out.c:378 #, c-format msgid "audio_alsa_out: snd_pcm_open() of %s failed: %s\n" -msgstr "" +msgstr "audio_alsa_out: snd_pcm_open() de %s a echoué: %s\n" #: src/audio_out/audio_alsa_out.c:380 msgid "audio_alsa_out: >>> check if another program already uses PCM <<<\n" -msgstr "" +msgstr "audio_alsa_out: >>> Vérifie si un autre programme utilise déjà PCM <<<\n" #: src/audio_out/audio_alsa_out.c:393 #, c-format @@ -59,10 +61,12 @@ msgid "" "audio_alsa_out: broken configuration for this PCM: no configurations " "available: %s\n" msgstr "" +"audio_alsa_out: Mauvaise configuration pour ce PCM: aucune configuration " +"disponible: %s\n" #: src/audio_out/audio_alsa_out.c:1295 msgid "notify changes to the hardware mixer" -msgstr "" +msgstr "Notifie les changements au mixeur matériel" #: src/audio_out/audio_alsa_out.c:1296 msgid "" @@ -70,15 +74,18 @@ msgid "" "notification so that it can update its graphical representation of the mixer " "settings on the fly." msgstr "" +"A chaque modification du mixeur matériel , votre application recevra " +"une notification afin qu'elle puisse automatiquement mettre à jour " +"sa représentation graphique du mixeur ." #: src/audio_out/audio_alsa_out.c:1361 #, c-format msgid "snd_lib_error_set_handler() failed: %d" -msgstr "" +msgstr "snd_lib_error_set_handler() a échoué: %d" #: src/audio_out/audio_alsa_out.c:1368 msgid "sound card can do mmap" -msgstr "" +msgstr "La carte son peut utiliser mmap" #: src/audio_out/audio_alsa_out.c:1369 msgid "" @@ -86,6 +93,9 @@ msgid "" "You can try enabling it and check, if everything works. If it does, this " "will increase performance." msgstr "" +"Activez ceci si votre carte son et votre pilote alsa supportent memory mapped IO.\n" +"Essayez de l'activer et contrôlez que tout fonctionne correctement.Si c'est le cas," +"cela augmentera les performances ." #: src/audio_out/audio_alsa_out.c:1378 msgid "device used for mono output" @@ -96,6 +106,9 @@ msgid "" "xine will use this alsa device to output mono sound.\n" "See the alsa documentation for information on alsa devices." msgstr "" +"xine utilisera ce périphérique alsa pour la sortie son mono.\n" +"Voir la documentation alsa pour toutes informations complémentaires " +"sur les périphériques alsa." #: src/audio_out/audio_alsa_out.c:1387 msgid "device used for stereo output" @@ -106,6 +119,9 @@ msgid "" "xine will use this alsa device to output stereo sound.\n" "See the alsa documentation for information on alsa devices." msgstr "" +"xine utilisera ce périphérique alsa pour la sortie son stéréo.\n" +"Voir la documentation alsa pour toutes informations complémentaires " +"sur les périphériques alsa" #: src/audio_out/audio_alsa_out.c:1396 msgid "device used for 4-channel output" @@ -116,6 +132,8 @@ msgid "" "xine will use this alsa device to output 4 channel (4.0) surround sound.\n" "See the alsa documentation for information on alsa devices." msgstr "" +"xine utilisera ce périphérique alsa pour la sortie son 4 canaux ( 4.0 ) surround.\n" +"Voir la documentation alsa pour toutes informations complémentaires sur les périphériques alsa." #: src/audio_out/audio_alsa_out.c:1406 src/audio_out/audio_alsa_out.c:1416 msgid "device used for 5.1-channel output" @@ -127,6 +145,9 @@ msgid "" "sound.\n" "See the alsa documentation for information on alsa devices." msgstr "" +"xine utilisera ce périphérique alsa pour la sortie son 5 canaux plus LFE (5.1) " +"surround.\n" +"Voir la documentation alsa pour toutes informations complémentaires sur les périphériques alsa." #: src/audio_out/audio_alsa_out.c:1417 msgid "" @@ -134,20 +155,23 @@ msgid "" "This can be used be external surround decoders.\n" "See the alsa documentation for information on alsa devices." msgstr "" +"xine utilisera ce périphérique alsa pour une sortie son numérique surround non décodée. " +"Celle-ci peut être utilisée par un décodeur surround externe.\n" +"Voir la documentation alsa pour toutes informations complémentaires sur les périphériques alsa." #: src/audio_out/audio_alsa_out.c:1437 -#, fuzzy, c-format +#, c-format msgid "snd_pcm_open() failed:%d:%s\n" -msgstr "input_cda: open(%s) a échoué: %s.\n" +msgstr "snd_pcm_open() a échoué:%d:%s\n" #: src/audio_out/audio_alsa_out.c:1439 #, c-format msgid ">>> Check if another program already uses PCM <<<\n" -msgstr "" +msgstr ">>> Vérifie si un autre programme utilise déjà PCM <<<\n" #: src/audio_out/audio_alsa_out.c:1470 src/audio_out/audio_oss_out.c:926 msgid "speaker arrangement" -msgstr "" +msgstr "Arrangement des haut-parleurs" #: src/audio_out/audio_alsa_out.c:1471 src/audio_out/audio_oss_out.c:927 msgid "" @@ -180,70 +204,98 @@ msgid "" "xine. You need to connect a digital surround decoder capable of decoding the " "formats you want to play to your sound card's digital output." msgstr "" +"Choisissez parmi les choix suivants selon les haut-parleurs à votre disposition , " +"Cela déterminera quels haut-parleurs xine utilisera pour la sortie son. " +"Les valeurs individuelles sont:\n" +"\n" +"Mono 1.0: Vous avez seulement un haut-parleur.\n" +"Stereo 2.0: Vous avez deux haut-parleurs , un pour le canal gauche et un pour " +" le canal droit\n" +"Headphones 2.0: Vous utilisez un casque audio.\n" +"Stereo 2.1: Vous avez deux haut-parleurs: 1 gauche et 1 droit, plus un subwoofer " +"pour les basses fréquences.\n" +"Surround 3.0: Vous avez trois haut-parleurs : 1 avant gauche et 1 avant droit, " +"plus un arrière.\n" +"Surround 4.0: Vous avez quatre haut-parleurs : 1 avant gauche , 1 avant droit, " +"1 arrière gauche et 1 arrière droit.\n" +"Surround 4.1: Vous avez quatre haut-parleurs : 1 avant gauche, 1 avant droit, " +"1 arrière gauche et 1 arrière droit, plus un subwoofer pour les basses fréquences.\n" +"Surround 5.0: Vous avez cinq haut-parleurs : 1 avant gauche, 1 avant droit, " +"1 voie centrale, 1 arrière gauche et 1 arrière droit.\n" +"Surround 5.1: Vous avez cinq haut-parleurs : 1 avant gauche, 1 avant droit, " +"1 voie centrale, 1 arrière gauche et 1 arrière droit, plus un subwoofer " +"pour les basses fréquences .\n" +"Surround 6.0: Vous avez six haut-parleurs : 1 avant gauche, 1 avant droit, " +"1 voie centrale avant, 1 arrière gauche, 1 arrière droit et 1 voie centrale arrière.\n" +"Surround 6.1: Vous avez six haut-parleurs : 1 avant gauche, 1 avant droit, " +"1 voie centrale avant, 1 arrière gauche, 1 arrière droit et 1 voie centrale arrière, " +"plus un subwoofer pour les basses fréquences.\n" +"Surround 7.1: Vous avez sept haut-parleurs : 1 avant gauche, 1 avant droit, " +"1 voie centrale avant droite et 1 avant gauche, 1 arrière gauche et 1 arrière droit, " +"plus un subwoofer pour les basses fréquences.\n" +"Pass Through: Votre système de son recevra un signal numérique non décodé " +"provenant de xine .Vous aurez besoin de connecter un décodeur numérique " +" surround capable de traiter le signal envoyé par votre carte son. " #: src/audio_out/audio_alsa_out.c:1500 msgid "audio_alsa_out : supported modes are " -msgstr "" +msgstr "audio_alsa_out : les modes supportés sont " #: src/audio_out/audio_alsa_out.c:1503 msgid "8bit " -msgstr "" +msgstr "8bit " #: src/audio_out/audio_alsa_out.c:1508 msgid "16bit " -msgstr "" +msgstr "16bit " #: src/audio_out/audio_alsa_out.c:1512 msgid "24bit " -msgstr "" +msgstr "24bit " #: src/audio_out/audio_alsa_out.c:1516 msgid "32bit " -msgstr "" +msgstr "32bit " #: src/audio_out/audio_alsa_out.c:1527 msgid "mono " -msgstr "" +msgstr "mono " #: src/audio_out/audio_alsa_out.c:1531 msgid "stereo " -msgstr "" +msgstr "stéréo " #: src/audio_out/audio_alsa_out.c:1536 -#, fuzzy msgid "4-channel " -msgstr "canal" +msgstr "4-canaux" #: src/audio_out/audio_alsa_out.c:1539 msgid "(4-channel not enabled in xine config) " -msgstr "" +msgstr "(sortie 4 canaux non activée dans la configuration de xine)" #: src/audio_out/audio_alsa_out.c:1544 -#, fuzzy msgid "4.1-channel " -msgstr "canal" +msgstr "sortie 4.1 canaux" #: src/audio_out/audio_alsa_out.c:1547 msgid "(4.1-channel not enabled in xine config) " -msgstr "" +msgstr "(sortie 4.1 canaux non activée dans la configuration de xine)" #: src/audio_out/audio_alsa_out.c:1552 -#, fuzzy msgid "5-channel " -msgstr "canal" +msgstr "Sortie 5 canaux" #: src/audio_out/audio_alsa_out.c:1555 msgid "(5-channel not enabled in xine config) " -msgstr "" +msgstr "(Sortie 5 canaux non activée dans la configuration de xine)" #: src/audio_out/audio_alsa_out.c:1560 -#, fuzzy msgid "5.1-channel " -msgstr "canal" +msgstr "Sortie 5.1 canaux" #: src/audio_out/audio_alsa_out.c:1563 msgid "(5.1-channel not enabled in xine config) " -msgstr "" +msgstr "(Sortie 5.1 canaux non activée dans la configuration de xine)" #: src/audio_out/audio_alsa_out.c:1586 msgid "a/52 and DTS pass-through\n" @@ -251,7 +303,7 @@ msgstr "" #: src/audio_out/audio_alsa_out.c:1589 msgid "(a/52 and DTS pass-through not enabled in xine config)\n" -msgstr "" +msgstr "(a/52 et DTS pass-through non activés dans la configuration de xine)\n" #: src/audio_out/audio_alsa_out.c:1596 msgid "alsa mixer device" @@ -262,110 +314,109 @@ msgid "" "xine will use this alsa mixer device to change the volume.\n" "See the alsa documentation for information on alsa devices." msgstr "" +"xine utilisera ce périphérique du mixeur alsa pour changer le volume.\n" +"Voir la documentation alsa pour toutes informations complémentaires sur les périphériques alsa." #: src/audio_out/audio_alsa_out.c:1671 msgid "xine audio output plugin using alsa-compliant audio devices/drivers" -msgstr "" -"plugin de sortie audio de xine utilisant les pilotes/périphériques alsa" +msgstr "plugin de sortie audio xine utilisant les pilotes/périphériques compatible alsa " #: src/audio_out/audio_arts_out.c:371 -#, fuzzy msgid "xine audio output plugin using kde artsd" -msgstr "plugin de sortie audio de xine utilisant esd" +msgstr "plugin de sortie audio xine utilisant arts de kde" #: src/audio_out/audio_coreaudio_out.c:569 -#, fuzzy msgid "xine output plugin for Coreaudio/Mac OS X" -msgstr "plugin de sortie audio de xine utilisant esd" +msgstr "plugin de sortie audio xine pour Coreaudio/Mac OS X" #: src/audio_out/audio_directx2_out.c:161 msgid "Error" -msgstr "" +msgstr "Erreur" #: src/audio_out/audio_directx2_out.c:168 msgid "success" -msgstr "" +msgstr "succès" #: src/audio_out/audio_directx2_out.c:170 msgid "access denied" -msgstr "" +msgstr "accès interdit" #: src/audio_out/audio_directx2_out.c:172 msgid "resource is already in use" -msgstr "" +msgstr "la ressource est déjà en cours d'utilisation" #: src/audio_out/audio_directx2_out.c:173 msgid "object was already initialized" -msgstr "" +msgstr "L'objet était déjà initialisé" #: src/audio_out/audio_directx2_out.c:174 msgid "specified wave format is not supported" -msgstr "" +msgstr "Le format wave spécifié n'est pas supporté" #: src/audio_out/audio_directx2_out.c:175 msgid "memory buffer has been lost and must be restored" -msgstr "" +msgstr "le tampon mémoire a été perdu et doit être restauré" #: src/audio_out/audio_directx2_out.c:176 msgid "requested buffer control is not available" -msgstr "" +msgstr "Le contrôle du buffer requis n'est pas disponible" #: src/audio_out/audio_directx2_out.c:177 msgid "undetermined error inside DirectSound subsystem" -msgstr "" +msgstr "Erreur interne indéterminée du sous-système DirectSound" #: src/audio_out/audio_directx2_out.c:179 msgid "DirectSound hardware device is unavailable" -msgstr "" +msgstr "Le périphérique matériel DirectSound est indisponible" #: src/audio_out/audio_directx2_out.c:181 msgid "function is not valid for the current state of the object" -msgstr "" +msgstr "La fonction n'est pas valide pour l'état actuel de l'objet" #: src/audio_out/audio_directx2_out.c:182 msgid "invalid parameter was passed" -msgstr "" +msgstr "Un paramètre invalide a été passé" #: src/audio_out/audio_directx2_out.c:183 msgid "object doesn't support aggregation" -msgstr "" +msgstr "L'objet ne supporte pas l'agrégation" #: src/audio_out/audio_directx2_out.c:184 msgid "no sound driver available for use" -msgstr "" +msgstr "pas de pilote son disponible" #: src/audio_out/audio_directx2_out.c:185 msgid "requested COM interface not available" -msgstr "" +msgstr "L'interface COM requise n'est pas disponible" #: src/audio_out/audio_directx2_out.c:186 msgid "another application has a higher priority level" -msgstr "" +msgstr "une autre application a un niveau de priorité plus élevé" #: src/audio_out/audio_directx2_out.c:187 msgid "insufficient memory" -msgstr "" +msgstr "mémoire insuffisante" #: src/audio_out/audio_directx2_out.c:188 msgid "low priority level for this function" -msgstr "" +msgstr "Niveau de priorité bas pour cette fonction" #: src/audio_out/audio_directx2_out.c:189 msgid "DirectSound wasn't initialized" -msgstr "" +msgstr "DirectSound n'était pas initialisé" #: src/audio_out/audio_directx2_out.c:190 msgid "function is not supported" -msgstr "" +msgstr "cette fonction n'est pas supportée" #: src/audio_out/audio_directx2_out.c:191 msgid "unknown error" -msgstr "" +msgstr "erreur inconnue" #: src/audio_out/audio_directx2_out.c:201 #, c-format msgid "Unable to create direct sound object." -msgstr "" +msgstr "Impossible de créer l'objet direct sound." #: src/audio_out/audio_directx2_out.c:207 #, c-format @@ -374,7 +425,7 @@ msgstr "" #: src/audio_out/audio_directx2_out.c:281 msgid "Unable to create secondary direct sound buffer" -msgstr "" +msgstr "Impossible de créer un second tampon pour direct sound " #: src/audio_out/audio_directx2_out.c:305 #, c-format @@ -383,7 +434,7 @@ msgstr "" #: src/audio_out/audio_directx2_out.c:313 msgid "Unable to get notification interface" -msgstr "" +msgstr "Impossible d'obtenir une notification de l'interface" #: src/audio_out/audio_directx2_out.c:318 msgid "Unable to set notification positions" @@ -391,41 +442,41 @@ msgstr "" #: src/audio_out/audio_directx2_out.c:338 msgid "Couldn't play sound buffer" -msgstr "" +msgstr "Ne peut pas utiliser le buffer audio" #: src/audio_out/audio_directx2_out.c:350 msgid "Couldn't stop sound buffer" -msgstr "" +msgstr "Ne peut pas stopper le buffer audio" #: src/audio_out/audio_directx2_out.c:363 msgid "Can't get buffer position" -msgstr "" +msgstr "Ne peut pas obtenir la position du buffer" #: src/audio_out/audio_directx2_out.c:377 msgid "Can't set buffer position" -msgstr "" +msgstr "Ne peut pas ajuster la position du buffer" #: src/audio_out/audio_directx2_out.c:409 msgid "Can't set sound volume" -msgstr "" +msgstr "Impossible de régler le volume sonore" #: src/audio_out/audio_directx2_out.c:427 #, c-format msgid ": buffer lost, tryig to restore\n" -msgstr "" +msgstr ": buffer perdu, tentative de restauration\n" #: src/audio_out/audio_directx2_out.c:431 msgid "Couldn't lock direct sound buffer" -msgstr "" +msgstr "Impossible de verrouiller le buffer de direct sound" #: src/audio_out/audio_directx2_out.c:442 msgid "Couldn't unlock direct sound buffer" -msgstr "" +msgstr "Impossible de déverrouiller le buffer de direct sound" #: src/audio_out/audio_directx2_out.c:539 -#, fuzzy, c-format +#, c-format msgid "Unable to create primary direct sound buffer." -msgstr "incapable d'allouer le buffer d'entrée.\n" +msgstr "incapable d'allouer le buffer d'entré." #: src/audio_out/audio_directx2_out.c:632 #, c-format @@ -435,66 +486,64 @@ msgstr "" #: src/audio_out/audio_directx2_out.c:650 #, c-format msgid ": delayed by %ld msec\n" -msgstr "" +msgstr ": retardé de %ld msec\n" #: src/audio_out/audio_directx2_out.c:754 -#, fuzzy, c-format +#, c-format msgid ": can't create pthread condition: %s\n" -msgstr "input_rtp: ne peux pas créer le nouveau thread (%s)\n" +msgstr ": ne peux pas créer la condition pthread: %s\n" #: src/audio_out/audio_directx2_out.c:758 -#, fuzzy, c-format +#, c-format msgid ": can't create pthread mutex: %s\n" -msgstr "input_rtp: ne peux pas créer le nouveau thread (%s)\n" +msgstr ": ne peut pas créer pthread mutex: %s\n" #: src/audio_out/audio_directx2_out.c:765 -#, fuzzy, c-format +#, c-format msgid ": can't create buffer pthread: %s\n" -msgstr "input_rtp: ne peux pas créer le nouveau thread (%s)\n" +msgstr ": ne peut pas créer le pthread du buffer: %s\n" #: src/audio_out/audio_directx2_out.c:872 -#, fuzzy, c-format +#, c-format msgid ": can't destroy buffer pthread: %s\n" -msgstr "input_rtp: ne peux pas créer le nouveau thread (%s)\n" +msgstr ": ne peut pas détruire le pthread du buffer: %s\n" #: src/audio_out/audio_directx2_out.c:879 #, c-format msgid ": can't destroy pthread condition: %s\n" -msgstr "" +msgstr ":ne peut pas détruire la condition pthread: %s\n" #: src/audio_out/audio_directx2_out.c:882 #, c-format msgid ": can't destroy pthread mutex: %s\n" -msgstr "" +msgstr ": ne peut pas détruire pthread mutex: %s\n" #: src/audio_out/audio_directx2_out.c:942 #, c-format msgid ": unknown control command %d\n" -msgstr "" +msgstr ": commande inconnu %d\n" #: src/audio_out/audio_directx2_out.c:998 -#, fuzzy msgid "second xine audio output plugin using directx" -msgstr "plugin de sortie audio de xine utilisant esd" +msgstr "second plugin de sortie audio xine utilisant directx" #: src/audio_out/audio_directx_out.c:827 -#, fuzzy msgid "xine audio output plugin for win32 using directx" -msgstr "plugin de sortie audio de xine utilisant esd" +msgstr "plugin de sortie audio xine pour win32 utilisant directx" #: src/audio_out/audio_esd_out.c:165 #, c-format msgid "audio_esd_out: connecting to ESD server %s: %s\n" -msgstr "" +msgstr "audio_esd_out: connexion au serveur ESD en cours %s: %s\n" #: src/audio_out/audio_esd_out.c:497 msgid "audio_esd_out: connecting to esd server...\n" -msgstr "" +msgstr "audio_esd_out: connexion au serveur esd en cours...\n" #: src/audio_out/audio_esd_out.c:509 #, c-format msgid "audio_esd_out: can't connect to %s ESD server: %s\n" -msgstr "" +msgstr "audio_esd_out: ne peut pas se connecter au %s serveur ESD: %s\n" #: src/audio_out/audio_esd_out.c:539 msgid "esd audio output latency (adjust a/v sync)" @@ -506,21 +555,21 @@ msgid "" "fixed offset here to compensate.\n" "The unit of the value is one PTS tick, which is the 90000th part of a second." msgstr "" +"Si vous rencontrez des problèmes de synchronisation du son par rapport a la vidéo, " +"Vous pouvez entrer une valeur de décalage fixe pour compenser.\n" +"L'unité de valeur est un PTS tick, ce qui représente 1/90000 de seconde." #: src/audio_out/audio_esd_out.c:572 -#, fuzzy msgid "xine audio output plugin using esound" -msgstr "plugin de sortie audio de xine utilisant esd" +msgstr "plugin de sortie audio xine utilisant esound" #: src/audio_out/audio_file_out.c:362 -#, fuzzy msgid "xine file audio output plugin" -msgstr "plugin de sortie audio de xine utilisant esd" +msgstr "plugin de sortie audio xine utilisant un fichier " #: src/audio_out/audio_irixal_out.c:385 -#, fuzzy msgid "irixal audio output maximum gap length" -msgstr "taille maximale du gap pour la sortie audio irixal en 1/90000s" +msgstr "" #: src/audio_out/audio_irixal_out.c:386 msgid "" @@ -532,28 +581,25 @@ msgstr "" #: src/audio_out/audio_irixal_out.c:415 msgid "xine audio output plugin using IRIX libaudio" -msgstr "Sortie audio de Xine utilise IRIX libaudio" +msgstr "plugin de sortie audio xine utilisant IRIX libaudio" #: src/audio_out/audio_jack_out.c:406 -#, fuzzy msgid "xine output plugin for JACK Audio Connection Kit" -msgstr "plugin de sortie audio de xine utilisant esd" +msgstr "plugin de sortie audio xine pour JACK Audio Connection Kit" #: src/audio_out/audio_none_out.c:223 -#, fuzzy msgid "xine dummy audio output plugin" -msgstr "plugin de sortie audio de xine utilisant esd" +msgstr "plugin de sortie audio xine utilisant dummy" #: src/audio_out/audio_oss_out.c:196 #, c-format msgid "audio_oss_out: Opening audio device %s: %s\n" -msgstr "" +msgstr "audio_oss_out: Ouverture du périphérique audio %s: %s\n" #: src/audio_out/audio_oss_out.c:218 #, c-format -msgid "" -"audio_oss_out: warning: sampling rate %d Hz not supported, trying 44100 Hz\n" -msgstr "" +msgid "audio_oss_out: warning: sampling rate %d Hz not supported, trying 44100 Hz\n" +msgstr "audio_oss_out: Attention: un taux d'échantillonage de %d Hz n'est pas supporté , essayez 44100 Hz\n" #: src/audio_out/audio_oss_out.c:230 #, c-format @@ -562,7 +608,7 @@ msgstr "" #: src/audio_out/audio_oss_out.c:743 msgid "OSS audio device name" -msgstr "" +msgstr "Nom du périphérique audio OSS" #: src/audio_out/audio_oss_out.c:744 msgid "" @@ -570,6 +616,9 @@ msgid "" "number is appended to get the full device name.\n" "Select \"auto\" if you want xine to auto detect the corret setting." msgstr "" +"Specifies the base part of the audio device name, to which the OSS device " +"number is appended to get the full device name.\n" +"Choisissez \"auto\" si vous voulez que xine détecte automatiquement le réglage adéquat." #: src/audio_out/audio_oss_out.c:751 msgid "OSS audio device number, -1 for none" @@ -596,7 +645,7 @@ msgstr "" #: src/audio_out/audio_oss_out.c:780 #, c-format msgid "audio_oss_out: using device >%s<\n" -msgstr "" +msgstr "audio_oss_out: utilise le périphérique >%s<\n" #: src/audio_out/audio_oss_out.c:786 src/audio_out/audio_oss_out.c:901 #, c-format @@ -604,11 +653,12 @@ msgid "" "audio_oss_out: opening audio device %s failed:\n" "%s\n" msgstr "" +"audio_oss_out: l'ouverture du périphérique audio %s a échouée:\n" +"%s\n" #: src/audio_out/audio_oss_out.c:807 -#, fuzzy msgid "a/v sync method to use by OSS" -msgstr "méthode A/V sync a utiliser par OSS, dépend du pilote/périphérique" +msgstr "méthode A/V sync à utiliser par OSS" #: src/audio_out/audio_oss_out.c:808 msgid "" @@ -648,9 +698,8 @@ msgid "" msgstr "" #: src/audio_out/audio_oss_out.c:863 -#, fuzzy msgid "OSS audio output latency (adjust a/v sync)" -msgstr "Temps de latence de la sortie audio esd (ajustement de a/v sync) " +msgstr "Temps de latence de la sortie audio OSS (ajustement de a/v sync) " #: src/audio_out/audio_oss_out.c:877 msgid "" @@ -680,36 +729,34 @@ msgid "" msgstr "" #: src/audio_out/audio_oss_out.c:1081 -#, fuzzy, c-format +#, c-format msgid "audio_oss_out: open() mixer %s failed: %s\n" -msgstr "input_cda: open(%s) a échoué: %s.\n" +msgstr "audio_oss_out: l'ouverture() du mixeur %s a échouée: %s\n" #: src/audio_out/audio_oss_out.c:1154 msgid "xine audio output plugin using oss-compliant audio devices/drivers" -msgstr "plugin de sortie audio de xine utilisant les pilotes/périphériques oss" +msgstr "plugin de sortie audio xine utilisant les pilotes/périphériques audio compatible oss" #: src/audio_out/audio_pulse_out.c:548 -#, fuzzy msgid "device used for pulseaudio" -msgstr "périphérique utilisé pour la sortie 4 canaux" +msgstr "périphérique utilisé pour pulseaudio" #: src/audio_out/audio_pulse_out.c:549 msgid "use 'server[:sink]' for setting the pulseaudio sink device." msgstr "" #: src/audio_out/audio_pulse_out.c:582 -#, fuzzy msgid "xine audio output plugin using pulseaudio sound server" -msgstr "plugin de sortie audio de xine utilisant esd" +msgstr "plugin de sortie audio xine utilisant le serveur de son pulseaudio" #: src/audio_out/audio_sun_out.c:457 src/audio_out/audio_sun_out.c:950 #, c-format msgid "audio_sun_out: opening audio device %s failed: %s\n" -msgstr "" +msgstr "audio_sun_out: l'ouverture du périphérique audio %s a échouée : %s\n" #: src/audio_out/audio_sun_out.c:925 msgid "Sun audio device name" -msgstr "" +msgstr "Nom du périphérique audio Sun" #: src/audio_out/audio_sun_out.c:926 msgid "" @@ -720,26 +767,26 @@ msgid "" msgstr "" #: src/audio_out/audio_sun_out.c:968 -#, fuzzy, c-format +#, c-format msgid "audio_sun_out: audio ioctl on device %s failed: %s\n" -msgstr "input_cda: open(%s) a échoué: %s.\n" +msgstr "audio_sun_out: audio ioctl sur le périphérique %s a échoué: %s\n" #: src/audio_out/audio_sun_out.c:1022 msgid "xine audio output plugin using sun-compliant audio devices/drivers" -msgstr "plugin de sortie audio de xine utilisant les pilotes/périphériques sun" +msgstr "plugin de sortie audio xine utilisant les pilotes/périphériques compatible sun" #: src/demuxers/demux_asf.c:426 #, c-format msgid "demux_asf: warning: The stream id=%d is encrypted.\n" -msgstr "" +msgstr "demux_asf: attention: Le flux id=%d est crypté.\n" #: src/demuxers/demux_asf.c:428 msgid "Media stream scrambled/encrypted" -msgstr "" +msgstr "Flux média brouillé/crypté" #: src/demuxers/demux_avi.c:528 src/demuxers/demux_avi.c:642 msgid "Restoring index..." -msgstr "" +msgstr "Restauration de l'index..." #: src/demuxers/demux_avi.c:628 src/demuxers/demux_avi.c:1683 #, c-format @@ -772,19 +819,18 @@ msgid "unsupported FLV version (%d).\n" msgstr "" #: src/demuxers/demux_flv.c:185 -#, fuzzy msgid "neither video nor audio stream in this file.\n" -msgstr "metronom: fin de flux audio ignoré\n" +msgstr "aucun flux audio ou vidéo n'est présent dans ce fichier.\n" #: src/demuxers/demux_iff.c:233 #, c-format msgid "iff-8svx/16sv: unknown compression: %d\n" -msgstr "" +msgstr "iff-8svx/16sv: compression inconnue: %d\n" #: src/demuxers/demux_iff.c:367 #, c-format msgid "iff-ilbm: unknown compression: %d\n" -msgstr "" +msgstr "iff-ilbm: compression inconnue: %d\n" #: src/demuxers/demux_iff.c:568 #, c-format @@ -803,8 +849,7 @@ msgid "" msgstr "" #: src/demuxers/demux_mpeg_block.c:305 -msgid "" -"demux_mpeg_block: error! freeing. Please report this to xine developers.\n" +msgid "demux_mpeg_block: error! freeing. Please report this to xine developers.\n" msgstr "" #: src/demuxers/demux_mpeg_block.c:637 @@ -813,12 +858,12 @@ msgid "demux_mpeg_block: warning: PES header reserved 10 bits not found\n" msgstr "" #: src/demuxers/demux_mpeg_block.c:647 -#, fuzzy, c-format +#, c-format msgid "" "demux_mpeg_block: warning: PES header indicates that this stream may be " "encrypted (encryption mode %d)\n" msgstr "" -"demux_mpeg_block: attention: l'entête pes indique que ce flux sera crypté " +"demux_mpeg_block: attention: l'entête PES indique que ce flux peut être crypté " "(mode de cryptage %d)\n" #: src/demuxers/demux_mpeg_pes.c:415 @@ -826,7 +871,7 @@ msgstr "" msgid "" "xine-lib:demux_mpeg_pes: Unrecognised stream_id 0x%02x. Please report this " "to xine developers.\n" -msgstr "" +msgstr "xine-lib:demux_mpeg_pes: stream_id 0x%02x non reconnu. Veuillez reporter ceci aux développeurs xine.\n" #: src/demuxers/demux_mpeg_pes.c:424 #, c-format @@ -839,12 +884,12 @@ msgid "demux_mpeg_pes: warning: PES header reserved 10 bits not found\n" msgstr "" #: src/demuxers/demux_mpeg_pes.c:816 -#, fuzzy, c-format +#, c-format msgid "" "demux_mpeg_pes: warning: PES header indicates that this stream may be " "encrypted (encryption mode %d)\n" msgstr "" -"demux_mpeg_block: attention: l'entête pes indique que ce flux sera crypté " +"demux_mpeg_block: attention: l'entête PES indique que ce flux peut être crypté " "(mode de cryptage %d)\n" #: src/demuxers/demux_mpeg_pes.c:1090 @@ -852,12 +897,12 @@ msgstr "" msgid "" "demux_mpeg_pes:Unrecognised private stream 1 0x%02x. Please report this to " "xine developers.\n" -msgstr "" +msgstr "demux_mpeg_pes:Flux privé non reconnu 1 0x%02x. Veuillez reporter ceci aux développeurs xine.\n" #: src/demuxers/demux_ogg.c:805 #, c-format msgid "ogg: vorbis audio track indicated but no vorbis stream header found.\n" -msgstr "" +msgstr "ogg: piste audio vorbis indiquée mais aucune entête de flux vorbis n'a été trouvée.\n" #: src/demuxers/demux_snd.c:102 #, c-format @@ -865,9 +910,9 @@ msgid "demux_snd: bad header parameters\n" msgstr "" #: src/demuxers/demux_snd.c:147 -#, fuzzy, c-format +#, c-format msgid "demux_snd: unsupported audio type: %d\n" -msgstr "demus_avi: type audio inconnu 0x%lx\n" +msgstr "demux_snd: type audio non supporté: %d\n" #: src/demuxers/demux_tta.c:86 msgid "demux_tta: total frames count too high\n" @@ -880,8 +925,7 @@ msgstr "" #: src/demuxers/demux_voc.c:118 #, c-format -msgid "" -"unknown VOC compression type (0x%02X); please report to xine developers\n" +msgid "unknown VOC compression type (0x%02X); please report to xine developers\n" msgstr "" #: src/demuxers/demux_wc3movie.c:190 @@ -971,9 +1015,9 @@ msgid "" msgstr "" #: src/dxr3/dxr3_decode_video.c:545 -#, fuzzy, c-format +#, c-format msgid "dxr3_decode_video: Failed to open video device %s (%s)\n" -msgstr "input_dvd: impossible d'ouvrir le périphérique dvd (%s): %s\n" +msgstr "dxr3_decode_video: L'ouverture du périphérique vidéo a echouée %s (%s)\n" #: src/dxr3/dxr3_decode_video.c:613 msgid "dxr3_decode_video: write to device would block. flushing\n" @@ -990,8 +1034,7 @@ msgid "dxr3_decode_video: WARNING: unknown frame rate code %d\n" msgstr "" #: src/dxr3/dxr3_decode_video.c:760 -msgid "" -"dxr3_decode_video: WARNING: correcting frame rate code from PAL to NTSC\n" +msgid "dxr3_decode_video: WARNING: correcting frame rate code from PAL to NTSC\n" msgstr "" #: src/dxr3/dxr3_mpeg_encoders.c:123 @@ -1030,7 +1073,7 @@ msgstr "" #: src/dxr3/dxr3_mpeg_encoders.c:240 #, c-format msgid "dxr3_mpeg_encoder: cannot start encoding: %s\n" -msgstr "" +msgstr "dxr3_mpeg_encoder: ne peut pas démarrer l'encodage: %s\n" #: src/dxr3/dxr3_mpeg_encoders.c:370 msgid "dxr3_mpeg_encoder: Couldn't start the FAME library\n" @@ -1083,19 +1126,18 @@ msgid "use smooth play mode for mpeg encoder playback" msgstr "" #: src/dxr3/video_out_dxr3.c:272 -msgid "" -"Enabling this option will utilise a smoother play mode for non-MPEG content." +msgid "Enabling this option will utilise a smoother play mode for non-MPEG content." msgstr "" #: src/dxr3/video_out_dxr3.c:280 -#, fuzzy, c-format +#, c-format msgid "video_out_dxr3: Failed to open control device %s (%s)\n" -msgstr "input_dvd: impossible d'ouvrir le périphérique dvd (%s): %s\n" +msgstr "" #: src/dxr3/video_out_dxr3.c:288 -#, fuzzy, c-format +#, c-format msgid "video_out_dxr3: Failed to open video device %s (%s)\n" -msgstr "input_dvd: impossible d'ouvrir le périphérique dvd (%s): %s\n" +msgstr "video_out_dxr3: L'ouverture du périphérique vidéo a échouée %s (%s)\n" #: src/dxr3/video_out_dxr3.c:334 msgid "encoder for non mpeg content" @@ -1249,34 +1291,35 @@ msgid "video_out_dxr3: ERROR Reading overlay init file. Run autocal!\n" msgstr "" #: src/input/input_cdda.c:1616 -#, fuzzy, c-format +#, c-format msgid "%s: can't connect to %s:%d\n" -msgstr "input_net: impossible de se connecter à '%s'.\n" +msgstr "%s: ne peut pas se connecter à %s:%d\n" #: src/input/input_cdda.c:1663 -#, fuzzy, c-format +#, c-format msgid "input_cdda: successfully connected to cddb server '%s:%d'.\n" -msgstr "input_cda: serveur '%s:%d' connecté avec succés.\n" +msgstr "input_cdda: serveur cddb '%s:%d' connecté avec succés.\n" #: src/input/input_cdda.c:1668 -#, fuzzy, c-format +#, c-format msgid "input_cdda: failed to connect to cddb server '%s:%d' (%s).\n" -msgstr "input_net: impossible de se connecter à '%s'.\n" +msgstr "input_cdda: impossible de se connecter au serveur cddb '%s:%d' (%s).\n" #: src/input/input_cdda.c:2702 msgid "CD Digital Audio (aka. CDDA)" msgstr "" #: src/input/input_cdda.c:2755 -#, fuzzy msgid "device used for CD audio" -msgstr "périphérique utilisé pour la sortie 4 canaux" +msgstr "périphérique utilisé pour les cd audio" #: src/input/input_cdda.c:2756 msgid "" "The path to the device, usually a CD or DVD drive, which you intend to use " "for playing audio CDs." msgstr "" +"Le chemin d'accès vers le périphérique, généralement un lecteur CD ou DVD, " +"choisissez celui que vous souhaitez utiliser pour lire vos CD audio." #: src/input/input_cdda.c:2762 msgid "query CDDB" @@ -1293,7 +1336,7 @@ msgstr "" #: src/input/input_cdda.c:2770 msgid "CDDB server name" -msgstr "" +msgstr "Nom du serveur CDDB" #: src/input/input_cdda.c:2770 msgid "" @@ -1305,7 +1348,7 @@ msgstr "" #: src/input/input_cdda.c:2778 msgid "CDDB server port" -msgstr "" +msgstr "Port du serveur CDDB " #: src/input/input_cdda.c:2778 msgid "The server port used to retrieve the title and track information from." @@ -1337,24 +1380,22 @@ msgid "" msgstr "" #: src/input/input_dvb.c:895 -#, fuzzy, c-format +#, c-format msgid "input_dvb: failed to open dvb channel file '%s': %s\n" -msgstr "input_file: tente d'ouvrir le fichier de sous-titre '%s'\n" +msgstr "" #: src/input/input_dvb.c:901 -#, fuzzy, c-format +#, c-format msgid "input_dvb: dvb channel file '%s' is not a plain file\n" -msgstr "input_file: tente d'ouvrir le fichier de sous-titre '%s'\n" +msgstr "" #: src/input/input_dvb.c:2139 src/input/input_dvb.c:2971 -#, fuzzy msgid "input_dvb: tuner_set_channel failed\n" -msgstr "input_cda: fopen(%s) à échoué: %s\n" +msgstr "" #: src/input/input_dvb.c:2771 src/input/input_dvb.c:3197 -#, fuzzy msgid "input_dvb: cannot open dvb device\n" -msgstr "input_dvd: ne peux pas ouvrir le périphérique dvd >%s<\n" +msgstr "input_dvb: ne peux pas ouvrir le périphérique dvb\n" #: src/input/input_dvb.c:2795 #, c-format @@ -1362,9 +1403,9 @@ msgid "input_dvb: channel %d out of range, defaulting to 0\n" msgstr "" #: src/input/input_dvb.c:2806 -#, fuzzy, c-format +#, c-format msgid "input_dvb: searching for channel %s\n" -msgstr "input_file: tente d'ouvrir le fichier de sous-titre '%s'\n" +msgstr "input_dvb: recherche pour le canal %s\n" #: src/input/input_dvb.c:2829 #, c-format @@ -1372,9 +1413,9 @@ msgid "input_dvb: exact match for %s not found: trying partial matches\n" msgstr "" #: src/input/input_dvb.c:2836 -#, fuzzy, c-format +#, c-format msgid "input_dvb: found matching channel %s\n" -msgstr "input_file: tente d'ouvrir le fichier de sous-titre '%s'\n" +msgstr "" #: src/input/input_dvb.c:2849 #, c-format @@ -1416,14 +1457,13 @@ msgid "" msgstr "" #: src/input/input_dvb.c:2977 -#, fuzzy, c-format +#, c-format msgid "input_dvb: cannot open dvr device '%s'\n" -msgstr "input_dvd: ne peux pas ouvrir le périphérique dvd >%s<\n" +msgstr "input_dvb: ne peut pas ouvrir le périhérique dvr '%s'\n" #: src/input/input_dvb.c:2999 -#, fuzzy msgid "input_dvb: cannot create EPG updater thread\n" -msgstr "input_rtp: ne peux pas créer le nouveau thread (%s)\n" +msgstr "" #: src/input/input_dvb.c:3061 msgid "use DVB 'center cutout' (zoom)" @@ -1472,8 +1512,7 @@ msgid "Number of dvb card to use." msgstr "" #: src/input/input_dvb.c:3306 -msgid "" -"Leave this at zero unless you really have more than 1 card in your system." +msgid "Leave this at zero unless you really have more than 1 card in your system." msgstr "" #: src/input/input_dvd.c:588 @@ -1486,20 +1525,20 @@ msgid "input_dvd: Error getting next block from DVD (%s)\n" msgstr "" #: src/input/input_dvd.c:1497 -#, fuzzy msgid "input_dvd: Error opening DVD device\n" -msgstr "input_dvd: ne peux pas ouvrir le fichier >%s<\n" +msgstr "input_dvd: Erreur à l'ouverture du périphérique DVD\n" #: src/input/input_dvd.c:1784 -#, fuzzy msgid "device used for DVD playback" -msgstr "périphérique utilisé pour la sortie mono" +msgstr "périphérique utilisé pour la lecture des DVD" #: src/input/input_dvd.c:1785 msgid "" "The path to the device, usually a DVD drive, which you intend to use for " "playing DVDs." msgstr "" +"Le chemin d'accès vers le périphérique, généralement un lecteur CD ou DVD, " +"choisissez celui que vous souhaitez utiliser pour lire vos DVD ." #: src/input/input_dvd.c:1803 msgid "raw device set up for DVD access" @@ -1553,7 +1592,7 @@ msgstr "" #: src/input/input_dvd.c:1856 msgid "default language for DVD playback" -msgstr "" +msgstr "langue par défaut pour la lecture des DVD" #: src/input/input_dvd.c:1857 msgid "" @@ -1636,19 +1675,19 @@ msgid "input_file: read error (%s)\n" msgstr "input_file: erreur de lecture (%s)\n" #: src/input/input_file.c:361 -#, fuzzy, c-format +#, c-format msgid "input_file: Permission denied: >%s<\n" -msgstr "input_cda: fopen(%s) à échoué: %s\n" +msgstr "input_file: Permission refusée: >%s<\n" #: src/input/input_file.c:365 -#, fuzzy, c-format +#, c-format msgid "input_file: File not found: >%s<\n" -msgstr "input_file: erreur de lecture (%s)\n" +msgstr "input_file: Fichier non trouvé: >%s<\n" #: src/input/input_file.c:403 src/input/input_gnome_vfs.c:290 -#, fuzzy, c-format +#, c-format msgid "input_file: File empty: >%s<\n" -msgstr "input_file: erreur de lecture (%s)\n" +msgstr "input_file: Fichier vide: >%s<\n" #: src/input/input_file.c:624 msgid "file input plugin" @@ -1664,42 +1703,43 @@ msgstr "" #: src/input/input_file.c:1001 msgid "list hidden files" -msgstr "" +msgstr "lister les fichiers cachés" #: src/input/input_file.c:1002 msgid "" "If enabled, the browser to select the file to play will also show hidden " "files." msgstr "" +"Si activé, le navigateur qui vous permet de sélectionner " +"les fichiers à jouer vous montrera également ceux qui sont cachés." #: src/input/input_gnome_vfs.c:216 -#, fuzzy msgid "gnome-vfs input plugin as shipped with xine" -msgstr "plugin d'entrée réseau fournis avec xine" +msgstr "plugin d'entré gnome-vfs fourni avec xine" #: src/input/input_http.c:176 -#, fuzzy, c-format +#, c-format msgid "input_http: gethostbyname(%s) failed: %s\n" -msgstr "input_cda: fopen(%s) à échoué: %s\n" +msgstr "input_http: gethostbyname(%s) a echoué: %s\n" #: src/input/input_http.c:421 src/input/input_http.c:1002 -#, fuzzy, c-format +#, c-format msgid "input_http: read error %d\n" -msgstr "input_file: erreur de lecture (%s)\n" +msgstr "input_http: erreur de lecture %d\n" #: src/input/input_http.c:648 msgid "Connecting HTTP server..." -msgstr "" +msgstr "Connexion au serveur HTTP..." #: src/input/input_http.c:840 #, c-format msgid "input_http: invalid http answer\n" -msgstr "" +msgstr "input_http: réponse http invalide\n" #: src/input/input_http.c:846 -#, fuzzy, c-format +#, c-format msgid "input_http: 3xx redirection: >%d %s<\n" -msgstr "input_file: erreur de lecture (%s)\n" +msgstr "input_http: 3xx redirection: >%d %s<\n" #: src/input/input_http.c:851 src/input/input_http.c:857 #: src/input/input_http.c:864 @@ -1713,13 +1753,13 @@ msgid "input_http: content length = % bytes\n" msgstr "" #: src/input/input_http.c:957 -#, fuzzy, c-format +#, c-format msgid "input_http: buffer exhausted after %d bytes." -msgstr "input_file: erreur de lecture (%s)\n" +msgstr "input_http: buffer épuisé après %d bytes." #: src/input/input_http.c:1055 msgid "http input plugin" -msgstr "" +msgstr "plugin d'entré http" #: src/input/input_http.c:1121 msgid "HTTP proxy host" @@ -1727,7 +1767,7 @@ msgstr "" #: src/input/input_http.c:1121 msgid "The hostname of the HTTP proxy." -msgstr "" +msgstr "Le nom d'hôte pour le proxy HTTP." #: src/input/input_http.c:1125 msgid "HTTP proxy port" @@ -1782,7 +1822,7 @@ msgstr "" #: src/input/input_mms.c:487 msgid "MMS protocol" -msgstr "" +msgstr "Protocole MMS" #: src/input/input_mms.c:488 msgid "" @@ -1803,7 +1843,7 @@ msgstr "input_net: connect(): %s\n" #: src/input/input_net.c:180 src/input/input_net.c:222 #, c-format msgid "input_net: unable to resolve '%s'.\n" -msgstr "input_net: impossible de resoudre '%s'.\n" +msgstr "input_net: impossible de résoudre '%s'.\n" #: src/input/input_net.c:193 src/input/input_net.c:239 #, c-format @@ -1812,51 +1852,51 @@ msgstr "input_net: impossible de se connecter à '%s'.\n" #: src/input/input_net.c:508 msgid "net input plugin as shipped with xine" -msgstr "plugin d'entrée réseau fournis avec xine" +msgstr "plugin d'entré réseau fournis avec xine" #: src/input/input_pnm.c:262 msgid "pnm streaming input plugin" msgstr "" #: src/input/input_pvr.c:601 -#, fuzzy, c-format +#, c-format msgid "input_pvr: error creating pvr file (%s)\n" -msgstr "input_dvd: ne peux pas ouvrir le fichier >%s<\n" +msgstr "input_pvr: erreur à la création du fichier pvr (%s)\n" #: src/input/input_pvr.c:758 -#, fuzzy, c-format +#, c-format msgid "input_pvr: error opening pvr file (%s)\n" -msgstr "input_dvd: ne peux pas ouvrir le fichier >%s<\n" +msgstr "input_pvr: erreur à l'ouverture du fichier pvr (%s)\n" #: src/input/input_pvr.c:834 -#, fuzzy, c-format +#, c-format msgid "input_pvr: read error (%s)\n" -msgstr "input_file: erreur de lecture (%s)\n" +msgstr "input_pvr: erreur de lecture (%s)\n" #: src/input/input_pvr.c:1150 src/input/input_pvr.c:1403 -#, fuzzy, c-format +#, c-format msgid "input_pvr: error opening device %s\n" -msgstr "input_dvd: ne peux pas ouvrir le fichier >%s<\n" +msgstr "input_pvr: erreur à l'ouverture du périphérique %s\n" #: src/input/input_pvr.c:1156 src/input/input_pvr.c:1409 msgid "input_pvr: IVTV_IOC_G_CODEC failed, maybe API changed?\n" -msgstr "" +msgstr "input_pvr: IVTV_IOC_G_CODEC a échoué, peut-être que l' API a changé ?\n" #: src/input/input_pvr.c:1164 src/input/input_pvr.c:1418 msgid "input_pvr: IVTV_IOC_S_CODEC failed, maybe API changed?\n" -msgstr "" +msgstr "input_pvr: IVTV_IOC_S_CODEC a échoué, peut-être que l' API a changé ?\n" #: src/input/input_pvr.c:1526 msgid "WinTV-PVR 250/350 input plugin" -msgstr "" +msgstr "plugin d'entré WinTV-PVR 250/350" #: src/input/input_pvr.c:1552 msgid "device used for WinTV-PVR 250/350 (pvr plugin)" -msgstr "" +msgstr "périphérique utilisé pour WinTV-PVR 250/350 (pvr plugin)" #: src/input/input_pvr.c:1553 msgid "The path to the device of your WinTV card." -msgstr "" +msgstr "Le chemin d'accès vers le périphérique de votre carte WinTV." #: src/input/input_rtp.c:183 #, c-format @@ -1865,17 +1905,17 @@ msgstr "socket(): %s.\n" #: src/input/input_rtp.c:193 msgid "IP address specified is multicast\n" -msgstr "" +msgstr "L'adresse IP spécifiée est multicast\n" #: src/input/input_rtp.c:202 -#, fuzzy, c-format +#, c-format msgid "setsockopt(SO_RCVBUF): %s.\n" -msgstr "socket(): %s.\n" +msgstr "setsockopt(SO_RCVBUF): %s.\n" #: src/input/input_rtp.c:210 -#, fuzzy, c-format +#, c-format msgid "setsockopt(SO_REUSEADDR): %s.\n" -msgstr "socket(): %s.\n" +msgstr "" #: src/input/input_rtp.c:217 #, c-format @@ -1898,18 +1938,18 @@ msgid "unable to resolve '%s'.\n" msgstr "incapable de resoudre '%s'.\n" #: src/input/input_rtp.c:287 -#, fuzzy, c-format +#, c-format msgid "unable to bind to '%s'.\n" msgstr "incapable de se connecter à '%s'.\n" #: src/input/input_rtp.c:336 -#, fuzzy, c-format +#, c-format msgid "recv(): %s.\n" -msgstr "socket(): %s.\n" +msgstr "" #: src/input/input_rtp.c:630 msgid "RTP: stopping reading thread...\n" -msgstr "" +msgstr "RTP: arrêt de la lecture du thread...\n" #: src/input/input_rtp.c:633 msgid "RTP: reading thread terminated\n" @@ -1926,9 +1966,8 @@ msgid "input_rtp: can't create new thread (%s)\n" msgstr "input_rtp: ne peux pas créer le nouveau thread (%s)\n" #: src/input/input_rtp.c:769 -#, fuzzy msgid "RTP and UDP input plugin as shipped with xine" -msgstr "plugin d'entrée réseau fournis avec xine" +msgstr "plugin d'entré RTP et UDP fournis avec xine" #: src/input/input_rtsp.c:284 msgid "rtsp streaming input plugin" @@ -1936,7 +1975,7 @@ msgstr "" #: src/input/input_smb.c:156 msgid "CIFS/SMB input plugin based on libsmbclient" -msgstr "" +msgstr "plugin d'entré CIFS/SMB basé sur libsmbclient" #: src/input/input_stdin_fifo.c:164 #, c-format @@ -1944,9 +1983,9 @@ msgid "stdin: cannot seek back! (% > %)\n" msgstr "" #: src/input/input_stdin_fifo.c:252 -#, fuzzy, c-format +#, c-format msgid "stdin: failed to open '%s'\n" -msgstr "incapable de resoudre '%s'.\n" +msgstr "stdin: impossible d'ouvrir '%s'\n" #: src/input/input_stdin_fifo.c:348 msgid "stdin streaming input plugin" @@ -1966,92 +2005,90 @@ msgstr "" #: src/input/input_v4l.c:658 msgid "Tuner name not found\n" -msgstr "" +msgstr "Tuner non trouvé\n" #: src/input/input_v4l.c:1874 msgid "v4l tv input plugin" -msgstr "" +msgstr "plugin d'entré tv V4l" #: src/input/input_v4l.c:1878 msgid "v4l radio input plugin" -msgstr "" +msgstr "plugin d'entré radio v4l" #: src/input/input_v4l.c:1910 -#, fuzzy msgid "v4l video device" -msgstr "périphérique du mixeur alsa" +msgstr "périphérique vidéo v4l" #: src/input/input_v4l.c:1911 msgid "The path to your Video4Linux video device." -msgstr "" +msgstr "Le chemin d'accès vers votre périphérique vidéo Video4Linux" #: src/input/input_v4l.c:1936 -#, fuzzy msgid "v4l radio device" -msgstr "périphérique du mixeur alsa" +msgstr "périphérique radio v4l" #: src/input/input_v4l.c:1937 msgid "The path to your Video4Linux radio device." -msgstr "" +msgstr "Le chemin d'accès vers votre périphérique radio Video4Linux" #: src/input/input_vcd.c:847 -#, fuzzy msgid "input_vcd: malformed MRL. Use vcdo:/\n" -msgstr "input_cda: MRL malformée. Utilisez cda://\n" +msgstr "input_vcd: MRL mal formée. Utilisez vcdo:/\n" #: src/input/input_vcd.c:853 -#, fuzzy, c-format +#, c-format msgid "input_vcd: invalid track %d (valid range: 0 .. %d)\n" -msgstr "input_cda: piste %d invalide (limites correctes: 1 .. %d)\n" +msgstr "input_vcd: piste %d invalide (limites correctes: 0 .. %d)\n" #: src/input/input_vcd.c:920 msgid "Video CD input plugin" -msgstr "" +msgstr "plugin d'entré Video CD" #: src/input/input_vcd.c:965 -#, fuzzy, c-format +#, c-format msgid "unable to open %s: %s.\n" -msgstr "incapable de resoudre '%s'.\n" +msgstr "incapable d'ouvrir %s: %s.\n" #: src/input/input_vcd.c:1041 -#, fuzzy, c-format +#, c-format msgid "input_vcd: unable to open %s: %s.\n" -msgstr "input_dvd: impossible d'ouvrir le périphérique dvd (%s): %s\n" +msgstr "input_vcd: incapable d'ouvrir %s: %s.\n" #: src/input/input_vcd.c:1095 -#, fuzzy msgid "device used for VCD playback" -msgstr "périphérique utilisé pour la sortie mono" +msgstr "périphérique utilisé pour la lecture des VCD" #: src/input/input_vcd.c:1096 msgid "" "The path to the device, usually a CD or DVD drive, you intend to play your " "VideoCDs with." msgstr "" +"Le chemin d'accès vers le périphérique, généralement un lecteur CD ou DVD, " +"choisissez celui que vous souhaitez utiliser pour lire vos VideoCD ." #: src/input/librtsp/rtsp.c:448 #, c-format msgid "rtsp: bad mrl: %s\n" -msgstr "" +msgstr "rtsp: mauvaise mrl: %s\n" #: src/input/librtsp/rtsp.c:508 -#, fuzzy, c-format +#, c-format msgid "rtsp: failed to connect to '%s'\n" -msgstr "input_net: impossible de se connecter à '%s'.\n" +msgstr "rtsp: impossible de se connecter à '%s'\n" #: src/input/librtsp/rtsp_session.c:107 -#, fuzzy, c-format +#, c-format msgid "rtsp_session: failed to connect to server %s\n" -msgstr "input_net: impossible de se connecter à '%s'.\n" +msgstr "rtsp_session: impossible de se connecter au serveur %s\n" #: src/input/librtsp/rtsp_session.c:141 msgid "rtsp_session: session can not be established.\n" -msgstr "" +msgstr "rtsp_session: la session ne peut pas être établie.\n" #: src/input/librtsp/rtsp_session.c:159 #, c-format msgid "rtsp_session: rtsp server type '%s' not supported yet. sorry.\n" -msgstr "" +msgstr "rtsp_session: ce type de serveur rtsp '%s' n'est pas encore supporté. Désolé.\n" #: src/input/media_helper.c:148 #, c-format @@ -2060,7 +2097,7 @@ msgstr "" #: src/input/mms.c:559 msgid "Connecting MMS server (over tcp)..." -msgstr "" +msgstr "Connexion au serveur MMS (over tcp)..." #: src/input/mmsh.c:199 msgid "libmmsh: send error\n" @@ -2069,12 +2106,12 @@ msgstr "" #: src/input/mmsh.c:244 #, c-format msgid "libmmsh: bad response format\n" -msgstr "" +msgstr "libmmsh: mauvais format de réponse\n" #: src/input/mmsh.c:250 -#, fuzzy, c-format +#, c-format msgid "libmmsh: 3xx redirection not implemented: >%d %s<\n" -msgstr "input_file: erreur de lecture (%s)\n" +msgstr "libmmsh: 3xx redirection non effectuée: >%d %s<\n" #: src/input/mmsh.c:257 #, c-format @@ -2112,14 +2149,13 @@ msgid "" msgstr "" #: src/input/pnm.c:753 -#, fuzzy, c-format +#, c-format msgid "input_pnm: failed to connect '%s'\n" -msgstr "input_net: impossible de se connecter à '%s'.\n" +msgstr "input_pnm: impossible de se connecter '%s'\n" #: src/input/pnm.c:764 -#, fuzzy msgid "input_pnm: failed to set up stream\n" -msgstr "input_net: impossible de se connecter à '%s'.\n" +msgstr "" #: src/input/vcd/vcdio.c:222 msgid "SEEK_CUR not implemented for non-zero offset" @@ -2166,8 +2202,7 @@ msgid "Invalid current entry type" msgstr "" #: src/input/vcd/xineplug_inp_vcd.c:1014 -msgid "" -"Video CD plugin with PBC and support for: (X)VCD, (X)SVCD, HQVCD, CVD ... " +msgid "Video CD plugin with PBC and support for: (X)VCD, (X)SVCD, HQVCD, CVD ... " msgstr "" #: src/input/vcd/xineplug_inp_vcd.c:1115 @@ -2188,7 +2223,7 @@ msgstr "" #: src/input/vcd/xineplug_inp_vcd.c:1164 msgid "Unknown event type: " -msgstr "" +msgstr "type d'évènement inconnu:" #: src/input/vcd/xineplug_inp_vcd.c:1460 src/input/vcd/xineplug_inp_vcd.c:1507 msgid "The above message had unknown vcdimager log level" @@ -2219,8 +2254,7 @@ msgid "VCD position slider range" msgstr "" #: src/input/vcd/xineplug_inp_vcd.c:1861 -msgid "" -"range that the stream playback position slider represents playing a VCD." +msgid "range that the stream playback position slider represents playing a VCD." msgstr "" #: src/input/vcd/xineplug_inp_vcd.c:1869 @@ -2351,20 +2385,20 @@ msgstr "" #: src/libfaad/xine_faad_decoder.c:128 msgid "libfaad: libfaad NeAACDecOpen() failed.\n" -msgstr "" +msgstr "libfaad: libfaad NeAACDecOpen() a échoué.\n" #: src/libfaad/xine_faad_decoder.c:137 msgid "libfaad: libfaad NeAACDecInit2 failed.\n" -msgstr "" +msgstr "libfaad: libfaad NeAACDecInit2 a échoué.\n" #: src/libfaad/xine_faad_decoder.c:148 msgid "libfaad: libfaad NeAACDecInit failed.\n" -msgstr "" +msgstr "libfaad: libfaad NeAACDecInit a échoué.\n" #: src/libffmpeg/ff_audio_decoder.c:117 #, c-format msgid "ffmpeg_audio_dec: increasing buffer to %d to avoid overflow.\n" -msgstr "" +msgstr "ffmpeg_audio_dec: augmentation du buffer à %d pour éviter sa saturation.\n" #: src/libffmpeg/ff_audio_decoder.c:161 #, c-format @@ -2382,7 +2416,7 @@ msgstr "" #: src/libffmpeg/ff_dvaudio_decoder.c:283 #, c-format msgid "dvaudio: increasing buffer to %d to avoid overflow.\n" -msgstr "" +msgstr "dvaudio: augmentation du buffer à %d pour éviter sa saturation.\n" #: src/libffmpeg/ff_video_decoder.c:156 msgid "ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n" @@ -2408,11 +2442,11 @@ msgstr "" #: src/libffmpeg/ff_video_decoder.c:836 #, c-format msgid "ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n" -msgstr "" +msgstr "ffmpeg_video_dec: augmentation du buffer à %d pour éviter sa saturation.\n" #: src/libffmpeg/ff_video_decoder.c:1562 msgid "MPEG-4 postprocessing quality" -msgstr "" +msgstr "Qualité du post-traitement MPEG-4" #: src/libffmpeg/ff_video_decoder.c:1563 msgid "" @@ -2422,6 +2456,12 @@ msgid "" "heavy post processing can actually make the image worse by blurring it too " "much." msgstr "" +"Vous pouvez ajuster le niveau de post-traitement a appliqué au vidéo MPEG-4.\n" +"De hautes valeurs donnent une meilleure qualité d'image mais sollicite davantage " +"le processeur.De faibles valeurs peuvent provoquer une dégradation de l'image " +"comme par exemple l'apparition d'artefacts. Dans le cas d'une vidéo de haute " +"qualité, un post-traitement trop important peut actuellement dégrader l'image " +"en la rendant plus floue . " #: src/libffmpeg/ff_video_decoder.c:1571 msgid "FFmpeg video decoding thread count" @@ -2495,7 +2535,7 @@ msgstr "" #: src/libreal/real_common.c:139 msgid "path to RealPlayer codecs" -msgstr "" +msgstr "chemin d'accès vers les codecs RealPlayer" #: src/libreal/real_common.c:140 msgid "" @@ -2534,8 +2574,7 @@ msgid "display closed captions in MPEG-2 streams" msgstr "" #: src/libspucc/xine_cc_decoder.c:190 -msgid "" -"Closed Captions are subtitles mostly meant to help the hearing impaired." +msgid "Closed Captions are subtitles mostly meant to help the hearing impaired." msgstr "" #: src/libspucc/xine_cc_decoder.c:197 @@ -2700,14 +2739,12 @@ msgstr "" #: src/libw32dll/w32codec.c:684 #, c-format -msgid "" -"w32codec: DS_VideoDecoder failed! unknown codec %08lx / wrong parameters?\n" +msgid "w32codec: DS_VideoDecoder failed! unknown codec %08lx / wrong parameters?\n" msgstr "" #: src/libw32dll/w32codec.c:695 #, c-format -msgid "" -"w32codec: DMO_VideoDecoder failed! unknown codec %08lx / wrong parameters?\n" +msgid "w32codec: DMO_VideoDecoder failed! unknown codec %08lx / wrong parameters?\n" msgstr "" #: src/libw32dll/w32codec.c:815 src/libw32dll/w32codec.c:1484 @@ -3066,12 +3103,11 @@ msgstr "" #: src/video_out/video_out_aa.c:308 msgid "xine video output plugin using the ascii-art library" -msgstr "plugin de sortie video de xine utilisant la librairie ascii-art" +msgstr "plugin de sortie video xine utilisant la bibliothèque ascii-art" #: src/video_out/video_out_caca.c:315 -#, fuzzy msgid "xine video output plugin using the Color AsCii Art library" -msgstr "plugin de sortie video de xine utilisant la librairie ascii-art" +msgstr "plugin de sortie video xine utilisant la bibliothèque Color AsCii Art" #: src/video_out/video_out_directfb.c:1341 msgid "video layer buffering mode" @@ -3152,8 +3188,7 @@ msgid "video_out_directfb: layer doesn't support YUY2!\n" msgstr "" #: src/video_out/video_out_directfb.c:1557 -msgid "" -"video_out_directfb:need at least DirectFB 0.9.25 to play on this layer!\n" +msgid "video_out_directfb:need at least DirectFB 0.9.25 to play on this layer!\n" msgstr "" #: src/video_out/video_out_directfb.c:1592 @@ -3191,23 +3226,20 @@ msgid "video_out_directfb: using display layer #%d.\n" msgstr "" #: src/video_out/video_out_directfb.c:1888 -#, fuzzy msgid "xine video output plugin using DirectFB." -msgstr "plugin de sortie audio de xine utilisant libvidix" +msgstr "plugin de sortie vidéo xine utilisant DirectFB." #: src/video_out/video_out_directfb.c:2007 msgid "video_out_directfb: no usable display layer was found!\n" msgstr "" #: src/video_out/video_out_directfb.c:2096 -#, fuzzy msgid "xine video output plugin using DirectFB under XDirectFB." -msgstr "plugin de sortie audio de xine utilisant libvidix" +msgstr "plugin de sortie vidéo xine utilisant DirectFB sous XDirectFB." #: src/video_out/video_out_directx.c:1236 -#, fuzzy msgid "xine video output plugin for win32 using directx" -msgstr "plugin de sortie audio de xine utilisant libvidix" +msgstr "plugin de sortie vidéo xine pour win32 utilisant directx" #: src/video_out/video_out_fb.c:758 #, c-format @@ -3217,9 +3249,8 @@ msgid "" msgstr "" #: src/video_out/video_out_fb.c:818 src/video_out/video_out_vidix.c:1236 -#, fuzzy msgid "framebuffer device name" -msgstr "périphérique framebuffer" +msgstr "Nom du périphérique framebuffer" #: src/video_out/video_out_fb.c:819 src/video_out/video_out_vidix.c:1237 msgid "" @@ -3262,15 +3293,12 @@ msgid "" msgstr "" #: src/video_out/video_out_fb.c:1067 -#, fuzzy msgid "Xine video output plugin using the Linux frame buffer device" -msgstr "" -"plugin de sortie video de xine utilisant le périphérique framebuffer de linux" +msgstr "plugin de sortie video xine utilisant le périphérique framebuffer de linux" #: src/video_out/video_out_none.c:277 -#, fuzzy msgid "xine video output plugin which displays nothing" -msgstr "plugin de sortie video de xine pour cartes dxr3" +msgstr "plugin de sortie video xine qui n'affiche rien" #: src/video_out/video_out_opengl.c:1886 msgid "OpenGL renderer" @@ -3329,18 +3357,17 @@ msgid "" msgstr "" #: src/video_out/video_out_opengl.c:1963 -#, fuzzy msgid "xine video output plugin using the OpenGL 3D graphics API" -msgstr "plugin de sortie audio de xine utilisant libvidix" +msgstr "plugin de sortie vidéo xine utilisant l'API graphique 3D OpenGL" #: src/video_out/video_out_pgx32.c:187 msgid "video_out_pgx32: Error: can't grab DGA drawable for video window\n" msgstr "" #: src/video_out/video_out_pgx32.c:206 src/video_out/video_out_pgx32.c:220 -#, fuzzy, c-format +#, c-format msgid "video_out_pgx32: Error: ioctl failed, bad device (%s)\n" -msgstr "input_dvd: impossible d'ouvrir le périphérique dvd (%s): %s\n" +msgstr "video_out_pgx32: Erreur: ioctl a échoué, mauvais périphérique (%s)\n" #: src/video_out/video_out_pgx32.c:213 #, c-format @@ -3352,25 +3379,22 @@ msgid "video_out_pgx64: Error: can't grab DGA drawable for video window\n" msgstr "" #: src/video_out/video_out_pgx64.c:296 -#, fuzzy, c-format +#, c-format msgid "video_out_pgx64: Error: can't open framebuffer device '%s'\n" -msgstr "input_dvd: impossible d'ouvrir le périphérique dvd (%s): %s\n" +msgstr "video_out_pgx64: Erreur: ne peut pas ouvrir le périphérique framebuffer '%s'\n" #: src/video_out/video_out_pgx64.c:303 #, c-format -msgid "" -"video_out_pgx64: Error: ioctl failed (VIS_GETIDENTIFIER), bad device (%s)\n" -msgstr "" +msgid "video_out_pgx64: Error: ioctl failed (VIS_GETIDENTIFIER), bad device (%s)\n" +msgstr "video_out_pgx64: Erreur: ioctl a échoué (VIS_GETIDENTIFIER), mauvais périphérique (%s)\n" #: src/video_out/video_out_pgx64.c:316 #, c-format -msgid "" -"video_out_pgx64: Error: '%s' is not a xvr100/pgx64/pgx24 framebuffer device\n" -msgstr "" +msgid "video_out_pgx64: Error: '%s' is not a xvr100/pgx64/pgx24 framebuffer device\n" +msgstr "video_out_pgx64: Erreur: '%s' n'est pas un périphérique framebuffer xvr100/pgx64/pgx24\n" #: src/video_out/video_out_pgx64.c:337 -msgid "" -"video_out_pgx64: Error: video overlay on this screen is already in use\n" +msgid "video_out_pgx64: Error: video overlay on this screen is already in use\n" msgstr "" #: src/video_out/video_out_pgx64.c:352 @@ -3391,7 +3415,7 @@ msgstr "" #: src/video_out/video_out_pgx64.c:1394 msgid "video_out_pgx64: Error: ioctl failed (FBIOGATTR)\n" -msgstr "" +msgstr "video_out_pgx64: Erreur: ioctl a échoué (FBIOGATTR)\n" #: src/video_out/video_out_pgx64.c:1461 src/video_out/video_out_xcbxv.c:1437 #: src/video_out/video_out_xv.c:1490 src/video_out/video_out_xvmc.c:1444 @@ -3446,14 +3470,12 @@ msgid "video_out_sdl: fullscreen mode is NOT supported\n" msgstr "" #: src/video_out/video_out_sdl.c:571 -#, fuzzy msgid "xine video output plugin using the Simple Direct Media Layer" -msgstr "plugin de sortie video de xine utilisant Simple DirectMedia Layer" +msgstr "plugin de sortie video xine utilisant Simple Direct Media Layer" #: src/video_out/video_out_stk.c:452 -#, fuzzy msgid "xine video output plugin using the Libstk Surface Set-top Toolkit" -msgstr "plugin de sortie video de xine utilisant la librairie ascii-art" +msgstr "plugin de sortie video xine utilisant le toolkit Libstk Surface Set-top" #: src/video_out/video_out_syncfb.c:280 msgid "video_out_syncfb: error. (YUY2 not supported by your graphic card)\n" @@ -3507,8 +3529,7 @@ msgid "" msgstr "" #: src/video_out/video_out_syncfb.c:1058 -msgid "" -"xine video output plugin using the SyncFB module for Matrox G200/G400 cards" +msgid "xine video output plugin using the SyncFB module for Matrox G200/G400 cards" msgstr "" #: src/video_out/video_out_syncfb.c:1076 @@ -3590,15 +3611,12 @@ msgid "video overlay colour key blue component" msgstr "" #: src/video_out/video_out_vidix.c:1201 -#, fuzzy msgid "xine video output plugin using libvidix for x11" -msgstr "plugin de sortie audio de xine utilisant libvidix" +msgstr "plugin de sortie vidéo xine utilisant libvidix pour x11" #: src/video_out/video_out_vidix.c:1283 -#, fuzzy msgid "xine video output plugin using libvidix for linux frame buffer" -msgstr "" -"plugin de sortie video de xine utilisant le périphérique framebuffer de linux" +msgstr "plugin de sortie video xine utilisant libvidix pour le framebuffer linux" #: src/video_out/video_out_xcbshm.c:155 #, c-format @@ -3727,7 +3745,7 @@ msgstr "" #: src/video_out/video_out_xcbxv.c:1521 src/video_out/video_out_xv.c:1585 #: src/video_out/video_out_xxmc.c:2631 msgid "Some buggy video drivers need a workaround to function properly." -msgstr "" +msgstr "Certains pilotes vidéo buggés ont besoin d'un workaround ( une solution de rechange/contournement ) pour fonctionner correctement." #: src/video_out/video_out_xcbxv.c:1527 src/video_out/video_out_xv.c:1591 #: src/video_out/video_out_xvmc.c:1522 @@ -3776,7 +3794,7 @@ msgstr "" #: src/video_out/video_out_xcbxv.c:1582 src/video_out/video_out_xv.c:1665 #: src/video_out/video_out_xxmc.c:2725 msgid "xine video output plugin using the MIT X video extension" -msgstr "plugin de sortie video de xine utilisant l'extension video MIT X" +msgstr "plugin de sortie video xine utilisant l'extension video MIT X" #: src/video_out/video_out_xshm.c:199 msgid "" @@ -3863,9 +3881,8 @@ msgid "video_out_xv: this adaptor supports the yuy2 format.\n" msgstr "" #: src/video_out/video_out_xvmc.c:1591 -#, fuzzy msgid "xine video output plugin using the XvMC X video extension" -msgstr "plugin de sortie video de xine utilisant l'extension video MIT X" +msgstr "plugin de sortie video xine utilisant l'extension video XvMC " #: src/video_out/video_out_xvmc.c:1637 msgid "video_out_xvmc: XvMC extension not present.\n" @@ -4067,8 +4084,7 @@ msgid "" msgstr "" #: src/xine-engine/audio_out.c:1109 -msgid "" -"audio_out: delay calculation impossible with an unavailable audio device\n" +msgid "audio_out: delay calculation impossible with an unavailable audio device\n" msgstr "" #: src/xine-engine/audio_out.c:1248 @@ -4225,8 +4241,7 @@ msgstr "" #: src/xine-engine/info_helper.c:242 #, c-format -msgid "" -"info_helper: unsupported conversion %s -> UTF-8, no conversion performed\n" +msgid "info_helper: unsupported conversion %s -> UTF-8, no conversion performed\n" msgstr "" #: src/xine-engine/input_cache.c:170 @@ -4235,25 +4250,25 @@ msgid ": open() function should never be called\n" msgstr "" #: src/xine-engine/input_cache.c:353 -#, fuzzy, c-format +#, c-format msgid ": input plugin not defined!\n" -msgstr "input_dvd: ne peux pas ouvrir le fichier >%s<\n" +msgstr ": plugin d'entré non défini!\n" #: src/xine-engine/input_rip.c:138 src/xine-engine/input_rip.c:258 -#, fuzzy, c-format +#, c-format msgid "input_rip: reading of saved data failed: %s\n" -msgstr "input_cda: l'ouverture du serveur '%s:%d' a échouée: %s\n" +msgstr "input_rip: la lecture des données sauvegardées a échouée: %s\n" #: src/xine-engine/input_rip.c:153 -#, fuzzy, c-format +#, c-format msgid "input_rip: reading by input plugin failed\n" -msgstr "input_dvd: erreur de lecture dans le plugin input_dvd\n" +msgstr "input_rip: la lecture par le plugin d'entré a echoué\n" #: src/xine-engine/input_rip.c:161 src/xine-engine/input_rip.c:290 #: src/xine-engine/input_rip.c:656 -#, fuzzy, c-format +#, c-format msgid "input_rip: error writing to file % bytes: %s\n" -msgstr "input_dvd: ne peux pas ouvrir le fichier >%s<\n" +msgstr "" #: src/xine-engine/input_rip.c:182 #, c-format @@ -4261,14 +4276,14 @@ msgid "input_rip: open() function should never be called\n" msgstr "" #: src/xine-engine/input_rip.c:313 src/xine-engine/input_rip.c:418 -#, fuzzy, c-format +#, c-format msgid "input_rip: seeking failed\n" -msgstr "input_cda: fopen(%s) à échoué: %s\n" +msgstr "input_rip: la recherche a échouée\n" #: src/xine-engine/input_rip.c:370 src/xine-engine/input_rip.c:388 -#, fuzzy, c-format +#, c-format msgid "input_rip: seeking failed: %s\n" -msgstr "input_cda: fopen(%s) à échoué: %s\n" +msgstr "input_rip: la recherche a échouée: %s\n" #: src/xine-engine/input_rip.c:396 #, c-format @@ -4310,9 +4325,9 @@ msgid "input_rip: file name not given!\n" msgstr "" #: src/xine-engine/input_rip.c:626 -#, fuzzy, c-format +#, c-format msgid "input_rip: error opening file %s: %s\n" -msgstr "input_dvd: ne peux pas ouvrir le fichier >%s<\n" +msgstr "input_rip: erreur à l'ouverture du fichier %s: %s\n" #: src/xine-engine/io_helper.c:252 #, c-format @@ -4320,9 +4335,9 @@ msgid "io_helper: waiting abandoned\n" msgstr "" #: src/xine-engine/io_helper.c:259 -#, fuzzy, c-format +#, c-format msgid "io_helper: waiting failed: %s\n" -msgstr "input_cda: fopen(%s) à échoué: %s\n" +msgstr "" #: src/xine-engine/io_helper.c:314 msgid "failed to get status of socket" @@ -4331,17 +4346,17 @@ msgstr "" #: src/xine-engine/io_helper.c:388 #, c-format msgid "io_helper: Permission denied\n" -msgstr "" +msgstr "io_helper: Permission refusée\n" #: src/xine-engine/io_helper.c:392 #, c-format msgid "io_helper: File not found\n" -msgstr "" +msgstr "io_helper: Fichier non trouvé\n" #: src/xine-engine/io_helper.c:396 #, c-format msgid "io_helper: Connection Refused\n" -msgstr "" +msgstr "io_helper: Connexion refusée\n" #: src/xine-engine/load_plugins.c:208 #, c-format @@ -4350,8 +4365,7 @@ msgstr "" #: src/xine-engine/load_plugins.c:323 #, c-format -msgid "" -"load_plugins: ignoring plugin %s, wrong iface version %d (should be %d)\n" +msgid "load_plugins: ignoring plugin %s, wrong iface version %d (should be %d)\n" msgstr "" #: src/xine-engine/load_plugins.c:380 @@ -4386,9 +4400,9 @@ msgid "load_plugins: plugin %s found\n" msgstr "" #: src/xine-engine/load_plugins.c:495 -#, fuzzy, c-format +#, c-format msgid "load_plugins: static plugin found\n" -msgstr "input_net: impossible de se connecter à '%s'.\n" +msgstr "" #: src/xine-engine/load_plugins.c:502 #, c-format @@ -4406,21 +4420,23 @@ msgid "load_plugins: unknown plugin type %d in %s\n" msgstr "" #: src/xine-engine/load_plugins.c:526 -#, fuzzy, c-format +#, c-format msgid "load_plugins: unknown statically linked plugin type %d\n" -msgstr "input_net: impossible de se connecter à '%s'.\n" +msgstr "" #: src/xine-engine/load_plugins.c:586 -#, fuzzy, c-format +#, c-format msgid "load_plugins: unable to stat %s\n" -msgstr "input_net: impossible de se connecter à '%s'.\n" +msgstr "" #: src/xine-engine/load_plugins.c:627 -#, fuzzy, c-format +#, c-format msgid "" "load_plugins: cannot open plugin lib %s:\n" "%s\n" -msgstr "input_net: impossible de se connecter à '%s'.\n" +msgstr "" +"load_plugins: impossible d'ouvrir plugin lib %s:\n" +"%s\n" #: src/xine-engine/load_plugins.c:642 #, c-format @@ -4430,9 +4446,9 @@ msgid "" msgstr "" #: src/xine-engine/load_plugins.c:660 -#, fuzzy, c-format +#, c-format msgid "load_plugins: skipping unreadable plugin directory %s.\n" -msgstr "input_net: impossible de se connecter à '%s'.\n" +msgstr "" #: src/xine-engine/load_plugins.c:709 #, c-format @@ -4447,19 +4463,19 @@ msgid "load_plugins: Yikes! %s doesn't contain plugin info.\n" msgstr "" #: src/xine-engine/load_plugins.c:1301 -#, fuzzy, c-format +#, c-format msgid "load_plugins: unknown content detection strategy %d\n" -msgstr "input_net: impossible de se connecter à '%s'.\n" +msgstr "" #: src/xine-engine/load_plugins.c:1411 -#, fuzzy, c-format +#, c-format msgid "load_plugins: using demuxer '%s'\n" -msgstr "input_net: impossible de se connecter à '%s'.\n" +msgstr "load_plugins: utilise le demuxer '%s'\n" #: src/xine-engine/load_plugins.c:1707 src/xine-engine/load_plugins.c:1754 -#, fuzzy, c-format +#, c-format msgid "load_plugins: failed to load audio output plugin <%s>\n" -msgstr "input_net: impossible de se connecter à '%s'.\n" +msgstr "load_plugins: impossible de charger le plugin de sortie audio <%s>\n" #: src/xine-engine/load_plugins.c:1757 msgid "" @@ -4468,11 +4484,13 @@ msgid "" msgstr "" #: src/xine-engine/load_plugins.c:2061 -#, fuzzy, c-format +#, c-format msgid "" "load_plugins: cannot unload plugin lib %s:\n" "%s\n" -msgstr "input_net: impossible de se connecter à '%s'.\n" +msgstr "" +"load_plugins: ne peut pas décharger plugin lib %s:\n" +"%s\n" #: src/xine-engine/osd.c:735 #, c-format @@ -4531,7 +4549,7 @@ msgstr "" #: src/xine-engine/osd.c:1077 #, c-format msgid "osd: unsupported conversion %s -> %s, no conversion performed\n" -msgstr "" +msgstr "osd: conversion non supportée %s -> %s, pas de conversion effectuée\n" #: src/xine-engine/osd.c:1132 src/xine-engine/osd.c:1300 msgid "osd: font isn't defined\n" @@ -4681,19 +4699,19 @@ msgid "xine: error while parsing mrl\n" msgstr "" #: src/xine-engine/xine.c:831 -#, fuzzy, c-format +#, c-format msgid "xine: found input plugin : %s\n" -msgstr "plugin de sortie video de xine pour cartes dxr3" +msgstr "xine: plugin d'entré trouvé : %s\n" #: src/xine-engine/xine.c:848 -#, fuzzy, c-format +#, c-format msgid "xine: input plugin cannot open MRL [%s]\n" -msgstr "input_dvd: ne peux pas ouvrir le fichier >%s<\n" +msgstr "xine: le plugin d'entré ne peut pas ouvrir la MRL [%s]\n" #: src/xine-engine/xine.c:859 -#, fuzzy, c-format +#, c-format msgid "xine: cannot find input plugin for MRL [%s]\n" -msgstr "plugin de sortie video de xine pour cartes dxr3" +msgstr "" #: src/xine-engine/xine.c:885 #, c-format @@ -4706,9 +4724,8 @@ msgid "xine: join rip input plugin\n" msgstr "" #: src/xine-engine/xine.c:928 -#, fuzzy msgid "xine: error opening rip input plugin instance\n" -msgstr "input_dvd: erreur de lecture dans le plugin input_dvd\n" +msgstr "" #: src/xine-engine/xine.c:959 #, c-format @@ -4737,9 +4754,8 @@ msgid "subtitle mrl opened '%s'\n" msgstr "" #: src/xine-engine/xine.c:1102 -#, fuzzy msgid "xine: error opening subtitle mrl\n" -msgstr "input_dvd: ne peux pas ouvrir le fichier >%s<\n" +msgstr "xine: erreur à l'ouverture des sous-titres de la mrl\n" #: src/xine-engine/xine.c:1134 #, c-format @@ -4861,7 +4877,7 @@ msgstr "messages" #: src/xine-engine/xine.c:2052 msgid "plugin" -msgstr "" +msgstr "plugin" #: src/xine-engine/xine.c:2053 msgid "trace" @@ -4869,60 +4885,55 @@ msgstr "" #: src/xine-engine/xine_interface.c:955 msgid "Warning:" -msgstr "" +msgstr "Attention:" #: src/xine-engine/xine_interface.c:956 msgid "Unknown host:" -msgstr "" +msgstr "Hôte inconnu:" #: src/xine-engine/xine_interface.c:957 msgid "Unknown device:" -msgstr "" +msgstr "Périphérique inconnu:" #: src/xine-engine/xine_interface.c:958 msgid "Network unreachable" -msgstr "" +msgstr "Réseau inaccessible" #: src/xine-engine/xine_interface.c:959 msgid "Connection refused:" -msgstr "" +msgstr "Connexion refusée:" #: src/xine-engine/xine_interface.c:960 -#, fuzzy msgid "File not found:" -msgstr "input_file: erreur de lecture (%s)\n" +msgstr "Fichier non trouvé:" #: src/xine-engine/xine_interface.c:961 msgid "Read error from:" -msgstr "" +msgstr "Erreur de lecture provenant de:" #: src/xine-engine/xine_interface.c:962 msgid "Error loading library:" msgstr "" #: src/xine-engine/xine_interface.c:963 -#, fuzzy msgid "Encrypted media stream detected" -msgstr "" -"ogg: flux audio vorbis detecté\n" -"\n" +msgstr "Flux média crypté détecté" #: src/xine-engine/xine_interface.c:964 msgid "Security message:" -msgstr "" +msgstr "Message de sécurité:" #: src/xine-engine/xine_interface.c:965 -#, fuzzy msgid "Audio device unavailable" -msgstr "fifo non disponible (%d)\n" +msgstr "Périphérique audio non disponible" #: src/xine-engine/xine_interface.c:966 msgid "Permission error" -msgstr "" +msgstr "Erreur de permission" #: src/xine-engine/xine_interface.c:967 msgid "File is empty:" -msgstr "" +msgstr "Le fichier est vide:" #: src/xine-utils/memcpy.c:479 msgid "memcopy method used by xine" -- cgit v1.2.3 From 5b973c4dff6d3b816d6227b2e458dfa2d40809b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 1 Jan 2008 22:03:30 +0100 Subject: Add ChangeLog entry for previous change. --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index 2599f4add..b91297536 100644 --- a/ChangeLog +++ b/ChangeLog @@ -38,6 +38,7 @@ xine-lib (1.1.9) (unreleased) reading the COMM_TAG. [Bug #6] * Avoid potential mislinkage at install time if a system-wide libxine.so is present but is *not* pointing at libxine.so.1. + * Update French translation, thanks to Christophe Giraud. [Bug #15] xine-lib (1.1.8) * Send a channel-changed event to the frontend when receiving the SYNC -- cgit v1.2.3 From 7c595de7352a17ae6ebe7e5a1cf18d5f7de37b57 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 1 Jan 2008 22:33:19 +0000 Subject: Remove all reference to automake.diff. --- Makefile.am | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 0b8d346da..5c86dcb68 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,7 +13,6 @@ DEBFILES = debian/README.Debian debian/changelog debian/control \ debian/shlibdeps.sh debian/libxine-dev.install debian/libxine1.install EXTRA_DIST = config.rpath autogen.sh \ - automake.diff \ ChangeLog \ configure \ config.guess \ -- cgit v1.2.3 From 46c59ae8695a4b6f62af89afef68895e70985d77 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Thu, 3 Jan 2008 15:16:07 +0100 Subject: Detect corrupted or broken seek tables for CBR MP3 files. [Bug #3] --HG-- extra : transplant_source : %00%11%94ZZG%2A%A0%2A%3B%DA%CDx%AC%02%A8%E8%C3%DF%A5 --- ChangeLog | 1 + src/demuxers/demux_mpgaudio.c | 70 ++++++++++++++++++++++++++++++------------- 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index b91297536..fa98c24cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -39,6 +39,7 @@ xine-lib (1.1.9) (unreleased) * Avoid potential mislinkage at install time if a system-wide libxine.so is present but is *not* pointing at libxine.so.1. * Update French translation, thanks to Christophe Giraud. [Bug #15] + * Detect corrupted or broken seek tables in CBR MP3 files. [Bug #3] xine-lib (1.1.8) * Send a channel-changed event to the frontend when receiving the SYNC diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c index 73e43c199..8e716f095 100644 --- a/src/demuxers/demux_mpgaudio.c +++ b/src/demuxers/demux_mpgaudio.c @@ -64,6 +64,7 @@ /* Xing header stuff */ #define XING_TAG FOURCC_TAG('X', 'i', 'n', 'g') +#define INFO_TAG FOURCC_TAG('I', 'n', 'f', 'o') #define XING_FRAMES_FLAG 0x0001 #define XING_BYTES_FLAG 0x0002 #define XING_TOC_FLAG 0x0004 @@ -295,16 +296,8 @@ static int parse_frame_header(mpg_audio_frame_t *const frame, const uint8_t *con */ static xing_header_t* parse_xing_header(mpg_audio_frame_t *frame, uint8_t *buf, int bufsize) { - -#ifdef LOG - int i; -#endif uint8_t *ptr = buf; - xing_header_t *xing; - - xing = xine_xmalloc (sizeof (xing_header_t)); - if (!xing) - return NULL; + xing_header_t *xing = NULL; /* offset of the Xing header */ if (frame->lsf_bit) { @@ -319,52 +312,87 @@ static xing_header_t* parse_xing_header(mpg_audio_frame_t *frame, ptr += (9 + 4); } - if (ptr >= (buf + bufsize - 4)) return 0; + if (ptr >= (buf + bufsize - 4)) goto exit_error; lprintf("checking %08X\n", *ptr); + if (_X_BE_32(ptr) == XING_TAG) { + int has_frames_flag = 0; + int has_bytes_flag = 0; + + xing = xine_xmalloc (sizeof (xing_header_t)); + if (!xing) + goto exit_error; + lprintf("Xing header found\n"); ptr += 4; - if (ptr >= (buf + bufsize - 4)) return 0; + if (ptr >= (buf + bufsize - 4)) goto exit_error; xing->flags = _X_BE_32(ptr); ptr += 4; if (xing->flags & XING_FRAMES_FLAG) { - if (ptr >= (buf + bufsize - 4)) return 0; + if (ptr >= (buf + bufsize - 4)) goto exit_error; xing->stream_frames = _X_BE_32(ptr); ptr += 4; lprintf("stream frames: %d\n", xing->stream_frames); + has_frames_flag = 1; } if (xing->flags & XING_BYTES_FLAG) { - if (ptr >= (buf + bufsize - 4)) return 0; + if (ptr >= (buf + bufsize - 4)) goto exit_error; xing->stream_size = _X_BE_32(ptr); ptr += 4; lprintf("stream size: %d\n", xing->stream_size); + has_bytes_flag = 1; + } + + /* check if it's a useful Xing header */ + if (!has_frames_flag || !has_bytes_flag) { + lprintf("Stupid Xing tag, cannot do anything with it !\n"); + goto exit_error; } + if (xing->flags & XING_TOC_FLAG) { + int i; + lprintf("toc found\n"); - if (ptr >= (buf + bufsize - XING_TOC_LENGTH)) return 0; + if (ptr >= (buf + bufsize - XING_TOC_LENGTH)) goto exit_error; memcpy(xing->toc, ptr, XING_TOC_LENGTH); #ifdef LOG for (i = 0; i < XING_TOC_LENGTH; i++) { - lprintf("%d ", xing->toc[i]); + printf("%d ", xing->toc[i]); } - lprintf("\n"); + printf("\n"); #endif + /* check the table validity + * - MUST start with 0 + * - values MUST increase + */ + if (xing->toc[0] != 0) { + lprintf("invalid Xing toc\n"); + goto exit_error; + } + for (i = 1; i < XING_TOC_LENGTH; i++) { + if (xing->toc[i] < xing->toc[i-1]) { + lprintf("invalid Xing toc\n"); + goto exit_error; + } + } ptr += XING_TOC_LENGTH; } xing->vbr_scale = -1; if (xing->flags & XING_VBR_SCALE_FLAG) { - if (ptr >= (buf + bufsize - 4)) return 0; + if (ptr >= (buf + bufsize - 4)) goto exit_error; xing->vbr_scale = _X_BE_32(ptr); lprintf("vbr_scale: %d\n", xing->vbr_scale); } - - return xing; } else { lprintf("Xing header not found\n"); + } + return xing; + +exit_error: + lprintf("Xing header parse error\n"); free(xing); return NULL; } -} /* * Parse a Vbri header @@ -922,7 +950,7 @@ static int demux_mpgaudio_seek (demux_plugin_t *this_gen, if (this->stream_length > 0) { if (this->xing_header && - (this->xing_header->flags & (XING_TOC_FLAG | XING_BYTES_FLAG))) { + (this->xing_header->flags & XING_TOC_FLAG)) { seek_pos += xing_get_seek_point(this->xing_header, start_time, this->stream_length); lprintf("time seek: xing: time=%d, pos=%"PRId64"\n", start_time, seek_pos); } else if (this->vbri_header) { -- cgit v1.2.3 From 9276e56845b6c048cdf1e98574fa8fc80ffe8488 Mon Sep 17 00:00:00 2001 From: Richard van Paasen Date: Fri, 4 Jan 2008 00:00:08 +0100 Subject: Fixed an issue in input_pvr with setting the frequency of the tuner for ivtv versions 0.10.6+ Note: the old code divided the frequency by 62.5. But, the ivtv driver expects a different format. I changed the implementation in input_pvr such that the frequency can be given as provided by cable companies, multiplied by 1000: e.g. 503250 for 503.250 MHz. --- ChangeLog | 2 ++ src/input/input_pvr.c | 30 ++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index fa98c24cd..414092b20 100644 --- a/ChangeLog +++ b/ChangeLog @@ -40,6 +40,8 @@ xine-lib (1.1.9) (unreleased) is present but is *not* pointing at libxine.so.1. * Update French translation, thanks to Christophe Giraud. [Bug #15] * Detect corrupted or broken seek tables in CBR MP3 files. [Bug #3] + * Fixed an issue in input_pvr with setting the frequency of the tuner for + ivtv versions 0.10.6+ xine-lib (1.1.8) * Send a channel-changed event to the frontend when receiving the SYNC diff --git a/src/input/input_pvr.c b/src/input/input_pvr.c index f07e98133..1b8000072 100644 --- a/src/input/input_pvr.c +++ b/src/input/input_pvr.c @@ -1016,19 +1016,21 @@ static void pvr_event_handler (pvr_input_plugin_t *this) { /* change input */ if (v4l2_data->input != -1 && v4l2_data->input != this->input) { - lprintf("change input to:%d\n", v4l2_data->input); this->input = v4l2_data->input; /* as of ivtv 0.10.6: must close and reopen to set input */ close(this->dev_fd); this->dev_fd = open (this->class->devname, O_RDWR); - if (this->dev_fd == -1) { + if (this->dev_fd < 0) { xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "input_pvr: error opening device %s\n", this->class->devname ); } else { - if( ioctl(this->dev_fd, VIDIOC_S_INPUT, &this->input) ) + if( ioctl(this->dev_fd, VIDIOC_S_INPUT, &this->input) == 0 ) { + lprintf("Tuner Input set to:%d\n", v4l2_data->input); + } else { xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "input_pvr: error setting v4l2 input\n"); + } } } @@ -1040,14 +1042,30 @@ static void pvr_event_handler (pvr_input_plugin_t *this) { /* change frequency */ if (v4l2_data->frequency != -1 && v4l2_data->frequency != this->frequency) { - lprintf("changing frequency to:%.2f\n", (float)v4l2_data->frequency * 62.5); + double freq = (double)v4l2_data->frequency / 1000.0; struct v4l2_frequency vf; + struct v4l2_tuner vt; + double fac = 16; + + memset(&vf, 0, sizeof(vf)); + memset(&vt, 0, sizeof(vt)); + this->frequency = v4l2_data->frequency; - vf.frequency = this->frequency; + + if (ioctl(this->dev_fd, VIDIOC_G_TUNER, &vt) == 0) { + fac = (vt.capability & V4L2_TUNER_CAP_LOW) ? 16000 : 16; + } + vf.tuner = 0; - if( ioctl(this->dev_fd, VIDIOC_S_FREQUENCY, &vf) ) + vf.type = vt.type; + vf.frequency = (__u32)(freq * fac); + + if (ioctl(this->dev_fd, VIDIOC_S_FREQUENCY, &vf) == 0) { + lprintf("Tuner Frequency set to %d (%f.3 MHz)\n", vf.frequency, vf.frequency / fac); + } else { xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, "input_pvr: error setting v4l2 frequency\n"); + } } pthread_mutex_unlock(&this->dev_lock); -- cgit v1.2.3 From 283be73779b8113fe5f2f86531a03fd9471c6eef Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Fri, 4 Jan 2008 18:03:14 +0000 Subject: Protect against multiple inclusion of include/configure.h. --- configure.ac | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/configure.ac b/configure.ac index 09130f06b..9bb6eca4f 100644 --- a/configure.ac +++ b/configure.ac @@ -2725,6 +2725,13 @@ win32/include/Makefile]) AC_CONFIG_COMMANDS([default],[[chmod +x ./misc/SlackBuild ./misc/build_rpms.sh ./misc/relchk.sh]],[[]]) AC_OUTPUT +dnl Guard against multiple inclusion +AH_TOP([#ifndef _XINE_CONFIGURE_H_ +#define _XINE_CONFIGURE_H_ +]) +AH_BOTTOM([#endif +]) + dnl --------------------------------------------- dnl Work around a suspected bug in libtool: dnl -- cgit v1.2.3 From 29de3d76ef4761e34aee107d458bfabe3ce96298 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Fri, 4 Jan 2008 18:12:53 +0000 Subject: Pass $(X_CFLAGS) when compiling syncfb. Noticed by Thomas Koeller . --- src/video_out/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video_out/Makefile.am b/src/video_out/Makefile.am index c40535d9e..d447417c5 100644 --- a/src/video_out/Makefile.am +++ b/src/video_out/Makefile.am @@ -136,7 +136,7 @@ xineplug_vo_out_opengl_la_CFLAGS = $(VISIBILITY_FLAG) $(X_CFLAGS) $(MLIB_CFLAGS) xineplug_vo_out_syncfb_la_SOURCES = video_out_syncfb.c xineplug_vo_out_syncfb_la_LIBADD = $(XINE_LIB) $(X_LIBS) $(PTHREAD_LIBS) $(LTLIBINTL) -xineplug_vo_out_syncfb_la_CFLAGS = $(VISIBILITY_FLAG) +xineplug_vo_out_syncfb_la_CFLAGS = $(VISIBILITY_FLAG) $(X_CFLAGS) xineplug_vo_out_pgx64_la_SOURCES = video_out_pgx64.c xineplug_vo_out_pgx64_la_LIBADD = $(XINE_LIB) $(X_LIBS) $(SUNDGA_LIBS) $(PTHREAD_LIBS) $(LTLIBINTL) -- cgit v1.2.3 From f23e0e47c09a2cabb1f87104480b56c665304c3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Sat, 5 Jan 2008 20:36:27 +0100 Subject: =?UTF-8?q?Add=20translation=20to=20T=C3=BCrk=C3=A7e=20by=20Serdar?= =?UTF-8?q?=20Soytetir=20and=20Server=20Acim.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --HG-- extra : transplant_source : %0D7%2B%AC%15%14%B6%E9%7F%F0%A7%E2%EC%D3t3%9A%B29%9E --- po/LINGUAS | 1 + po/tr.po | 5424 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 5425 insertions(+) create mode 100644 po/tr.po diff --git a/po/LINGUAS b/po/LINGUAS index 636f4dfff..8a29b895c 100644 --- a/po/LINGUAS +++ b/po/LINGUAS @@ -7,3 +7,4 @@ it pl pt_BR sk +tr diff --git a/po/tr.po b/po/tr.po new file mode 100644 index 000000000..7965a185e --- /dev/null +++ b/po/tr.po @@ -0,0 +1,5424 @@ +# translation of libxine1.po to Türkçe +# translation of libxine1.po to +# Copyright (C) YEAR Copyright (C) 2000-2006 the xine project +# This file is distributed under the same license as the PACKAGE package. +# +# Serdar Soytetir , 2007. +# Server Acim , 2007, 2008. +# Serdar Soytetir , 2008. +msgid "" +msgstr "" +"Project-Id-Version: libxine1\n" +"Report-Msgid-Bugs-To: xine-devel@lists.sourceforge.net\n" +"POT-Creation-Date: 2007-12-24 12:54+0100\n" +"PO-Revision-Date: 2008-01-05 18:22+0200\n" +"Last-Translator: Server Acim \n" +"Language-Team: Türkçe \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" +"X-Generator: KBabel 1.11.4\n" + +#: lib/hstrerror.c:17 +msgid "No error" +msgstr "Hata yok" + +#: lib/hstrerror.c:18 +msgid "Unknown host" +msgstr "Bilinmeyen makine" + +#: lib/hstrerror.c:19 +msgid "No address associated with name" +msgstr "Bu isim ile ile iliÅŸkilendirilmiÅŸ bir adres yok" + +#: lib/hstrerror.c:20 +msgid "Unknown server error" +msgstr "Bilinmeyen sunucu hatası" + +#: lib/hstrerror.c:21 +msgid "Host name lookup failure" +msgstr "Makine adını bakma hatası" + +#: lib/hstrerror.c:22 +msgid "Unknown error" +msgstr "Bilinmeyen hata" + +#: src/audio_out/audio_alsa_out.c:350 +#, c-format +msgid "audio_alsa_out:Already open...WHY!" +msgstr "audio_alsa_out:Zaten açık...NEDEN!" + +#: src/audio_out/audio_alsa_out.c:378 +#, c-format +msgid "audio_alsa_out: snd_pcm_open() of %s failed: %s\n" +msgstr "audio_alsa_out: snd_pcm_open() of %s baÅŸarısız oldu: %s\n" + +#: src/audio_out/audio_alsa_out.c:380 +msgid "audio_alsa_out: >>> check if another program already uses PCM <<<\n" +msgstr "audio_alsa_out: >>>baÅŸka bir uygulamanın PCM'yi kullanıp kullanmadığını kontrol edin<<<\n" + +#: src/audio_out/audio_alsa_out.c:393 +#, c-format +msgid "" +"audio_alsa_out: broken configuration for this PCM: no configurations " +"available: %s\n" +msgstr "audio_alsa_out: bu PCM: için bozuk yapılandırma: hiç bir yapılandırma uygun deÄŸil: %s\n" + +#: src/audio_out/audio_alsa_out.c:1295 +msgid "notify changes to the hardware mixer" +msgstr "donanım karıştırıcısına deÄŸiÅŸiklikleri bildir" + +#: src/audio_out/audio_alsa_out.c:1296 +msgid "" +"When the hardware mixer changes, your application will receive a " +"notification so that it can update its graphical representation of the mixer " +"settings on the fly." +msgstr "Donanım karıştırıcısı deÄŸiÅŸtiÄŸinde, uygulamanız karıştırıcı ayarlarının görsel yeniden sunumunun güncelleneceÄŸi uyarısını alacaktır." + +#: src/audio_out/audio_alsa_out.c:1361 +#, c-format +msgid "snd_lib_error_set_handler() failed: %d" +msgstr "snd_lib_error_set_handler() baÅŸarısız oldu: %d" + +#: src/audio_out/audio_alsa_out.c:1368 +msgid "sound card can do mmap" +msgstr "ses kartı mmap iÅŸlerimi yapamıyor" + +#: src/audio_out/audio_alsa_out.c:1369 +msgid "" +"Enable this, if your sound card and alsa driver support memory mapped IO.\n" +"You can try enabling it and check, if everything works. If it does, this " +"will increase performance." +msgstr "" +"EÄŸer ses kartınız ve alsa sürücünüz hafızayla eÅŸlenmiÅŸ IO'ya destek veriyorsa bunu etkinleÅŸtirin./n " +"EÄŸer her ÅŸey çalışıyorsa, onu etkinleÅŸtirmeyi ve kontrol etmeyi deneyebilirsiniz. EÄŸer çalışırsa, bu baÅŸarını arttıracaktır." + +#: src/audio_out/audio_alsa_out.c:1378 +msgid "device used for mono output" +msgstr "mono çıktı için kullanılan aygıt" + +#: src/audio_out/audio_alsa_out.c:1379 +msgid "" +"xine will use this alsa device to output mono sound.\n" +"See the alsa documentation for information on alsa devices." +msgstr "" +"xine mono ses çıkışı için bu alsa aygıtını kullanacaktır.\n" +"Alsa aygıtları hakkında daha fazla bilgi için alsa belgesine bakınız." + +#: src/audio_out/audio_alsa_out.c:1387 +msgid "device used for stereo output" +msgstr "stereo çıktı için kullanılan aygıt" + +#: src/audio_out/audio_alsa_out.c:1388 +msgid "" +"xine will use this alsa device to output stereo sound.\n" +"See the alsa documentation for information on alsa devices." +msgstr "" +"xine stereo ses çıkışı için bu alsa aygıtını kullanacaktır.\n" +"Alsa aygıtları hakkında daha fazla bilgi için alsa belgesine bakınız." + +#: src/audio_out/audio_alsa_out.c:1396 +msgid "device used for 4-channel output" +msgstr "4-kanal çıktı için kullanılan aygıt" + +#: src/audio_out/audio_alsa_out.c:1397 +msgid "" +"xine will use this alsa device to output 4 channel (4.0) surround sound.\n" +"See the alsa documentation for information on alsa devices." +msgstr "" +"xine mono 4 kanal (4.0) surround ses çıkışı için bu alsa aygıtını kullanacaktır.\n" +"Alsa aygıtları hakkında daha fazla bilgi için alsa belgesine bakınız." + +#: src/audio_out/audio_alsa_out.c:1406 src/audio_out/audio_alsa_out.c:1416 +msgid "device used for 5.1-channel output" +msgstr "5.1-kanal çıktı için kullanılan aygıt" + +#: src/audio_out/audio_alsa_out.c:1407 +msgid "" +"xine will use this alsa device to output 5 channel plus LFE (5.1) surround " +"sound.\n" +"See the alsa documentation for information on alsa devices." +msgstr "" +"xine 5 kanal artı LFE (5.1) surround ses çıkışı için bu alsa aygıtını kullanacaktır.\n" +"Alsa aygıtları hakkında daha fazla bilgi için alsa belgesine bakınız." + +#: src/audio_out/audio_alsa_out.c:1417 +msgid "" +"xine will use this alsa device to output undecoded digital surround sound. " +"This can be used be external surround decoders.\n" +"See the alsa documentation for information on alsa devices." +msgstr "" +"xine kodlanmamış sayısal surround ses çıkışı için bu alsa aygıtını kullanacaktır.\n" +"Alsa aygıtları hakkında daha fazla bilgi için alsa belgesine bakınız." + +#: src/audio_out/audio_alsa_out.c:1437 +#, c-format +msgid "snd_pcm_open() failed:%d:%s\n" +msgstr "snd_pcm_open() baÅŸarısız oldu:%d:%s\n" + +#: src/audio_out/audio_alsa_out.c:1439 +#, c-format +msgid ">>> Check if another program already uses PCM <<<\n" +msgstr ">>>BaÅŸka bir uygulamanın PCM'yi kullanıp kullanmadığını kontrol edin<<<\n" + +#: src/audio_out/audio_alsa_out.c:1470 src/audio_out/audio_oss_out.c:926 +msgid "speaker arrangement" +msgstr "hoparlör ayarları" + +#: src/audio_out/audio_alsa_out.c:1471 src/audio_out/audio_oss_out.c:927 +msgid "" +"Select how your speakers are arranged, this determines which speakers xine " +"uses for sound output. The individual values are:\n" +"\n" +"Mono 1.0: You have only one speaker.\n" +"Stereo 2.0: You have two speakers for left and right channel.\n" +"Headphones 2.0: You use headphones.\n" +"Stereo 2.1: You have two speakers for left and right channel, and one " +"subwoofer for the low frequencies.\n" +"Surround 3.0: You have three speakers for left, right and rear channel.\n" +"Surround 4.0: You have four speakers for front left and right and rear left " +"and right channels.\n" +"Surround 4.1: You have four speakers for front left and right and rear left " +"and right channels, and one subwoofer for the low frequencies.\n" +"Surround 5.0: You have five speakers for front left, center and right and " +"rear left and right channels.\n" +"Surround 5.1: You have five speakers for front left, center and right and " +"rear left and right channels, and one subwoofer for the low frequencies.\n" +"Surround 6.0: You have six speakers for front left, center and right and " +"rear left, center and right channels.\n" +"Surround 6.1: You have six speakers for front left, center and right and " +"rear left, center and right channels, and one subwoofer for the low " +"frequencies.\n" +"Surround 7.1: You have seven speakers for front left, center and right, left " +"and right and rear left and right channels, and one subwoofer for the low " +"frequencies.\n" +"Pass Through: Your sound system will receive undecoded digital sound from " +"xine. You need to connect a digital surround decoder capable of decoding the " +"formats you want to play to your sound card's digital output." +msgstr "" +"Hoparlörlerin nasıl düzenlendiÄŸine bakınız, bu xine'nin ses çıkışı için hangi hoparlörlerin kullanıldığını belirler. Bireysel deÄŸerler şöyledir:\n" +"\n" +"Mono 1.0: Sadece tek hoparlörünüz var demektir. " +"Stereo 2.0: Sol ve saÄŸ kanal için iki hoparlörünüz var demektir." + +#: src/audio_out/audio_alsa_out.c:1500 +msgid "audio_alsa_out : supported modes are " +msgstr "audio_alsa_out : desteklenen kipler" + +#: src/audio_out/audio_alsa_out.c:1503 +msgid "8bit " +msgstr "8bit " + +#: src/audio_out/audio_alsa_out.c:1508 +msgid "16bit " +msgstr "16bit " + +#: src/audio_out/audio_alsa_out.c:1512 +msgid "24bit " +msgstr "24bit " + +#: src/audio_out/audio_alsa_out.c:1516 +msgid "32bit " +msgstr "32bit " + +#: src/audio_out/audio_alsa_out.c:1527 +msgid "mono " +msgstr "mono " + +#: src/audio_out/audio_alsa_out.c:1531 +msgid "stereo " +msgstr "stereo " + +#: src/audio_out/audio_alsa_out.c:1536 +msgid "4-channel " +msgstr "4-kanal " + +#: src/audio_out/audio_alsa_out.c:1539 +msgid "(4-channel not enabled in xine config) " +msgstr "(4-kanal xine yapılandırmasında etkinleÅŸtirilmemiÅŸ) " + +#: src/audio_out/audio_alsa_out.c:1544 +msgid "4.1-channel " +msgstr "4.1-kanal" + +#: src/audio_out/audio_alsa_out.c:1547 +msgid "(4.1-channel not enabled in xine config) " +msgstr "(4.1-kanal xine yapılandırmasında etkinleÅŸtirilmemiÅŸ) " + +#: src/audio_out/audio_alsa_out.c:1552 +msgid "5-channel " +msgstr "5-kanal" + +#: src/audio_out/audio_alsa_out.c:1555 +msgid "(5-channel not enabled in xine config) " +msgstr "(5-kanal xine yapılandırmasında etkinleÅŸtirilmemiÅŸ) " + +#: src/audio_out/audio_alsa_out.c:1560 +msgid "5.1-channel " +msgstr "5.1-kanal " + +#: src/audio_out/audio_alsa_out.c:1563 +msgid "(5.1-channel not enabled in xine config) " +msgstr "(5.1-kanal xine yapılandırmasında etkinleÅŸtirilmemiÅŸ) " + +#: src/audio_out/audio_alsa_out.c:1586 +msgid "a/52 and DTS pass-through\n" +msgstr "a/52 and DTS pass-through\n" + +#: src/audio_out/audio_alsa_out.c:1589 +msgid "(a/52 and DTS pass-through not enabled in xine config)\n" +msgstr "(a/52 and DTS pass-through xine yapılandırmasında etkinleÅŸtirilmemiÅŸ))\n" + +#: src/audio_out/audio_alsa_out.c:1596 +msgid "alsa mixer device" +msgstr "alsa karıştırıcı aygıtı" + +#: src/audio_out/audio_alsa_out.c:1597 +msgid "" +"xine will use this alsa mixer device to change the volume.\n" +"See the alsa documentation for information on alsa devices." +msgstr "" +"xine ses gürlüğünü deÄŸiÅŸtirmek bu alsa karıştırıcısını kullanacaktır.\n" +"Alsa aygıtları hakkında daha fazla bilgi için alsa belgesine bakınız." + +#: src/audio_out/audio_alsa_out.c:1671 +msgid "xine audio output plugin using alsa-compliant audio devices/drivers" +msgstr "xine ses çıkışı eklentisi alsa uyumlu aygıtları/sürücüleri kullanıyor" + +#: src/audio_out/audio_arts_out.c:371 +msgid "xine audio output plugin using kde artsd" +msgstr "Kde arts kullanan xine ses çıktısı eklentisi" + +#: src/audio_out/audio_coreaudio_out.c:569 +msgid "xine output plugin for Coreaudio/Mac OS X" +msgstr "Coreaudio/Mac OS X için xine ses çıktısı eklentisi" + +#: src/audio_out/audio_directx2_out.c:161 +msgid "Error" +msgstr "Hata" + +#: src/audio_out/audio_directx2_out.c:168 +msgid "success" +msgstr "baÅŸarılı" + +#: src/audio_out/audio_directx2_out.c:170 +msgid "access denied" +msgstr "eriÅŸim engellendi" + +#: src/audio_out/audio_directx2_out.c:172 +msgid "resource is already in use" +msgstr "kaynak zaten kullanımda" + +#: src/audio_out/audio_directx2_out.c:173 +msgid "object was already initialized" +msgstr "nesne zaten algılanmıştı" + +#: src/audio_out/audio_directx2_out.c:174 +msgid "specified wave format is not supported" +msgstr "belirtilen dalga biçimi desteklenmiyor" + +#: src/audio_out/audio_directx2_out.c:175 +msgid "memory buffer has been lost and must be restored" +msgstr "hafıza arabelleÄŸi kayıp ve onarılması gerekiyor" + +#: src/audio_out/audio_directx2_out.c:176 +msgid "requested buffer control is not available" +msgstr "istenen ara bellek kontrolü uygun deÄŸil" + +#: src/audio_out/audio_directx2_out.c:177 +msgid "undetermined error inside DirectSound subsystem" +msgstr "DirectSound alt sistemi içinde belirlenemeyen hata" + +#: src/audio_out/audio_directx2_out.c:179 +msgid "DirectSound hardware device is unavailable" +msgstr "DirectSound donanım aygıtı geçerli deÄŸil" + +#: src/audio_out/audio_directx2_out.c:181 +msgid "function is not valid for the current state of the object" +msgstr "uygulamanın geçerli durumu için iÅŸlev uygun deÄŸil" + +#: src/audio_out/audio_directx2_out.c:182 +msgid "invalid parameter was passed" +msgstr "geçersiz parametre geçirildi" + +#: src/audio_out/audio_directx2_out.c:183 +msgid "object doesn't support aggregation" +msgstr "nesne kümeyi desteklemiyor" + +#: src/audio_out/audio_directx2_out.c:184 +msgid "no sound driver available for use" +msgstr "kullanılabilecek bir ses sürücüsü yok" + +#: src/audio_out/audio_directx2_out.c:185 +msgid "requested COM interface not available" +msgstr "istenilen COM arayüzü kullanılabilir deÄŸil" + +#: src/audio_out/audio_directx2_out.c:186 +msgid "another application has a higher priority level" +msgstr "baÅŸka bir uygulamanın daha yüksek öncelik düzeyi var" + +#: src/audio_out/audio_directx2_out.c:187 +msgid "insufficient memory" +msgstr "yetersiz bellek" + +#: src/audio_out/audio_directx2_out.c:188 +msgid "low priority level for this function" +msgstr "bu fonksiyon için düşük öncelik düzeyi" + +#: src/audio_out/audio_directx2_out.c:189 +msgid "DirectSound wasn't initialized" +msgstr "DirectSound baÅŸlatılamadı" + +#: src/audio_out/audio_directx2_out.c:190 +msgid "function is not supported" +msgstr "fonksiyon desteklenmiyor" + +#: src/audio_out/audio_directx2_out.c:191 +msgid "unknown error" +msgstr "bilinmeyen hata" + +#: src/audio_out/audio_directx2_out.c:201 +#, c-format +msgid "Unable to create direct sound object." +msgstr "DoÄŸrudan ses nesnesi oluÅŸturulamadı." + +#: src/audio_out/audio_directx2_out.c:207 +#, c-format +msgid "Could not set direct sound cooperative level." +msgstr "DoÄŸrudan ses iÅŸbirliÄŸi düzeyi ayarlanamadı." + +#: src/audio_out/audio_directx2_out.c:281 +msgid "Unable to create secondary direct sound buffer" +msgstr "İkincil doÄŸrudan ses önbelleÄŸi oluÅŸturulamadı" + +#: src/audio_out/audio_directx2_out.c:305 +#, c-format +msgid "Unable to create buffer position events." +msgstr "Önbellek konum olayları oluÅŸturulamadı." + +#: src/audio_out/audio_directx2_out.c:313 +msgid "Unable to get notification interface" +msgstr "Bildirim arayüzü alınamadı" + +#: src/audio_out/audio_directx2_out.c:318 +msgid "Unable to set notification positions" +msgstr "Bildirim konumları ayarlanamadı" + +#: src/audio_out/audio_directx2_out.c:338 +msgid "Couldn't play sound buffer" +msgstr "Ses önbelleÄŸi çalınamadı" + +#: src/audio_out/audio_directx2_out.c:350 +msgid "Couldn't stop sound buffer" +msgstr "Ses önbelleÄŸi durdurulamadı" + +#: src/audio_out/audio_directx2_out.c:363 +msgid "Can't get buffer position" +msgstr "Önbellek konumu alınamadı" + +#: src/audio_out/audio_directx2_out.c:377 +msgid "Can't set buffer position" +msgstr "Önbellek konumu ayarlanamadı" + +#: src/audio_out/audio_directx2_out.c:409 +msgid "Can't set sound volume" +msgstr "Ses düzeyi ayarlanamadı" + +#: src/audio_out/audio_directx2_out.c:427 +#, c-format +msgid ": buffer lost, tryig to restore\n" +msgstr ": önbellek kayıp, geri yüklenmeye çalışılıyor\n" + +#: src/audio_out/audio_directx2_out.c:431 +msgid "Couldn't lock direct sound buffer" +msgstr "DoÄŸrudan ses önbelleÄŸinin kilitlenemedi" + +#: src/audio_out/audio_directx2_out.c:442 +msgid "Couldn't unlock direct sound buffer" +msgstr "DoÄŸrudan ses önbelleÄŸinin kilidi açılamadı" + +#: src/audio_out/audio_directx2_out.c:539 +#, c-format +msgid "Unable to create primary direct sound buffer." +msgstr "Birincil doÄŸrudan ses önbelleÄŸi oluÅŸturulamadı." + +#: src/audio_out/audio_directx2_out.c:632 +#, c-format +msgid ": play cursor overran, flushing buffers\n" +msgstr ": ara belleÄŸi dolduran imleç geçiÅŸini çal, \n" + +#: src/audio_out/audio_directx2_out.c:650 +#, c-format +msgid ": delayed by %ld msec\n" +msgstr ": %ld tarafından milisaniye geciktirildi\n" + +#: src/audio_out/audio_directx2_out.c:754 +#, c-format +msgid ": can't create pthread condition: %s\n" +msgstr ": iÅŸ parçacığı durumu yaratamaz: %s\n" + +#: src/audio_out/audio_directx2_out.c:758 +#, c-format +msgid ": can't create pthread mutex: %s\n" +msgstr ": mutex iÅŸ parçacığı oluÅŸturamaz: %s\n" + +#: src/audio_out/audio_directx2_out.c:765 +#, c-format +msgid ": can't create buffer pthread: %s\n" +msgstr ": tampon bellek iÅŸ parçacığı oluÅŸturamaz: %s\n" + +#: src/audio_out/audio_directx2_out.c:872 +#, c-format +msgid ": can't destroy buffer pthread: %s\n" +msgstr ": tampon bellek iÅŸ parçacığını yok edemez: %s\n" + +#: src/audio_out/audio_directx2_out.c:879 +#, c-format +msgid ": can't destroy pthread condition: %s\n" +msgstr ": iÅŸ parçacığı ÅŸartını yok edemez : %s\n" + +#: src/audio_out/audio_directx2_out.c:882 +#, c-format +msgid ": can't destroy pthread mutex: %s\n" +msgstr ": mutex iÅŸ parçacığını yok edemez : %s\n" + +#: src/audio_out/audio_directx2_out.c:942 +#, c-format +msgid ": unknown control command %d\n" +msgstr ": bilinmeyen denetim komutu %d\n" + +#: src/audio_out/audio_directx2_out.c:998 +msgid "second xine audio output plugin using directx" +msgstr "directx kullanan ikinci xine ses çıktısı eklentisi" + +#: src/audio_out/audio_directx_out.c:827 +msgid "xine audio output plugin for win32 using directx" +msgstr "win32 için directx kullanan xine ses çıktısı eklentisi" + +#: src/audio_out/audio_esd_out.c:165 +#, c-format +msgid "audio_esd_out: connecting to ESD server %s: %s\n" +msgstr "audio_esd_out: ESD sunucusuna baÄŸlanılıyor %s: %s\n" + +#: src/audio_out/audio_esd_out.c:497 +msgid "audio_esd_out: connecting to esd server...\n" +msgstr "audio_esd_out: esd sunucusuna baÄŸlanılıyor...\n" + +#: src/audio_out/audio_esd_out.c:509 +#, c-format +msgid "audio_esd_out: can't connect to %s ESD server: %s\n" +msgstr "audio_esd_out: %s ESD sunucusuna baÄŸlanılamadı: %s\n" + +#: src/audio_out/audio_esd_out.c:539 +msgid "esd audio output latency (adjust a/v sync)" +msgstr "esd ses çıkışı gecikme süresi (a/v senkronunu ayarla)" + +#: src/audio_out/audio_esd_out.c:540 src/audio_out/audio_oss_out.c:864 +msgid "" +"If you experience audio being not in sync with the video, you can enter a " +"fixed offset here to compensate.\n" +"The unit of the value is one PTS tick, which is the 90000th part of a second." +msgstr "" +"EÄŸer, sesin görüntü ile senkronize olmadığını fark ederseniz, eÅŸitlemek için buraya sabitlenmiÅŸ göreli konum girebilirsiniz.\n" +"DeÄŸerin birimi saniyenin 90000de bir olan bir PTS tıklamasıdır." + +#: src/audio_out/audio_esd_out.c:572 +msgid "xine audio output plugin using esound" +msgstr "esound kullanan xine ses çıktısı eklentisi" + +#: src/audio_out/audio_file_out.c:362 +msgid "xine file audio output plugin" +msgstr "xine dosyası ses çıkışı eklentisi" + +#: src/audio_out/audio_irixal_out.c:385 +msgid "irixal audio output maximum gap length" +msgstr "iriksiyal ses çıkışı en fazla boÅŸluk uzunluÄŸu" + +#: src/audio_out/audio_irixal_out.c:386 +msgid "" +"You can specify the maximum offset between audio and video xine will " +"tolerate before trying to resync them.\n" +"The unit of this value is one PTS tick, which is the 90000th part of a " +"second." +msgstr "" +"Ses ve görüntü arasındaki en fazla konumu belirlerseniz, xine ikisi arasındaki senkronu yeniden denemeden önce bunu tolere edecektir.\n" +"Bu ünitenin deÄŸeri, saniyenin 90000'de biri deÄŸerindeki bir PTS tıklamasıdır." + +#: src/audio_out/audio_irixal_out.c:415 +msgid "xine audio output plugin using IRIX libaudio" +msgstr "IRIX libaudio kullanan xine ses çıktısı eklentisi" + +#: src/audio_out/audio_jack_out.c:406 +msgid "xine output plugin for JACK Audio Connection Kit" +msgstr "JACK Audio Connection Kit kullanan xine ses çıktısı eklentisi" + +#: src/audio_out/audio_none_out.c:223 +msgid "xine dummy audio output plugin" +msgstr "xine sahte ses çıktısı eklentisi" + +#: src/audio_out/audio_oss_out.c:196 +#, c-format +msgid "audio_oss_out: Opening audio device %s: %s\n" +msgstr "audio_oss_out: Ses aygıtı açılıyor %s: %s\n" + +#: src/audio_out/audio_oss_out.c:218 +#, c-format +msgid "audio_oss_out: warning: sampling rate %d Hz not supported, trying 44100 Hz\n" +msgstr "audio_oss_out: uyarı: örnekleme oranı %d Hz desteklenmiyor, 44100 Hz deneniyor\n" + +#: src/audio_out/audio_oss_out.c:230 +#, c-format +msgid "audio_oss_out: audio rate : %d requested, %d provided by device\n" +msgstr "audio_oss_out: ses oranı : %d istendi, %d aygıt tarafından saÄŸlandı\n" + +#: src/audio_out/audio_oss_out.c:743 +msgid "OSS audio device name" +msgstr "OSS ses aygıtı adı" + +#: src/audio_out/audio_oss_out.c:744 +msgid "" +"Specifies the base part of the audio device name, to which the OSS device " +"number is appended to get the full device name.\n" +"Select \"auto\" if you want xine to auto detect the corret setting." +msgstr "" +"hangi OSS aygıtı numarasının tam aygıt ismini almayı üstlendiÄŸini belirlemek için ses aygıtı adının temel kısmını belirler .\n" +"EÄŸer xine'nin doÄŸru ayarı otomatik olarak algılamasını isterseniz \"auto\"yu seçiniz." + +#: src/audio_out/audio_oss_out.c:751 +msgid "OSS audio device number, -1 for none" +msgstr "OSS ses aygıtı numarası, hiçbiri için -1" + +#: src/audio_out/audio_oss_out.c:752 +msgid "" +"The full audio device name is created by concatenating the OSS device name " +"and the audio device number.\n" +"If you do not need a number because you are happy with your system's default " +"audio device, set this to -1.\n" +"The range of this value is -1 or 0-15. This setting is ignored, when the OSS " +"audio device name is set to \"auto\"." +msgstr "" +"Ses aygıtının tam ismi OSS aygıt adına ve ses aygıtı numarasından oluÅŸturulmuÅŸtur.\n" +"EÄŸer numaraya ihtiyacınız yoksa ve varsayılan sistem ses aygıtından memnunsanız bunu -1'e ayarlayın.\n" +"Bu deÄŸerin geniÅŸliÄŸi -1 veya 0-15 arasındadır. Bu ayar, OSS ses aygıt adı \"otomatik\" olarak saptanmış ise göz ardı edilir." + +#: src/audio_out/audio_oss_out.c:761 +msgid "audio_oss_out: audio.device.oss_device_name = auto, probing devs\n" +msgstr "audio_oss_out: audio.device.oss_device_name = auto, probing devs\n" + +#: src/audio_out/audio_oss_out.c:764 +msgid "audio_oss_out: Auto probe for audio device failed\n" +msgstr "audio_oss_out: Ses aygıtı için otomatik hazırlama baÅŸarısız oldu\n" + +#: src/audio_out/audio_oss_out.c:780 +#, c-format +msgid "audio_oss_out: using device >%s<\n" +msgstr "audio_oss_out: kullanılan aygıt >%s<\n" + +#: src/audio_out/audio_oss_out.c:786 src/audio_out/audio_oss_out.c:901 +#, c-format +msgid "" +"audio_oss_out: opening audio device %s failed:\n" +"%s\n" +msgstr "" +"audio_oss_out: %s ses aygıtının açılamadı:\n" +"%s\n" + +#: src/audio_out/audio_oss_out.c:807 +msgid "a/v sync method to use by OSS" +msgstr "OSS tarafından kullanılması için a/v senkron yöntemi" + +#: src/audio_out/audio_oss_out.c:808 +msgid "" +"xine can use different methods to keep audio and video synchronized. Which " +"setting works best depends on the OSS driver and sound hardware you are " +"using. Try the various methods, if you experience sync problems.\n" +"\n" +"The meaning of the values is as follows:\n" +"\n" +"auto\n" +"xine attempts to automatically detect the optimal setting\n" +"\n" +"getodelay\n" +"uses the SNDCTL_DSP_GETODELAY ioctl to achieve true a/v sync even if the " +"driver claims not to support realtime playback\n" +"\n" +"getoptr\n" +"uses the SNDCTL_DSP_GETOPTR ioctl to achieve true a/v sync even if the " +"driver supports the preferred SNDCTL_DSP_GETODELAY ioctl\n" +"\n" +"softsync\n" +"uses software synchronization with the system clock; audio and video can get " +"severely out of sync if the system clock speed does not precisely match your " +"sound card's playback speed\n" +"\n" +"probebuffer\n" +"probes the sound card buffer size on initialization to calculate the latency " +"for a/v sync; try this if your system does not support any of the realtime " +"ioctls and you experience sync errors after long playback" +msgstr "" +"xine ses ve görüntünün senkronize olması için farklı yöntemler kullanabilir. Kullandığınız ses donanımından hangi ayarın en iyi çalışacağı OSS sürücünüze ve kullandığınız ses donanımına baÄŸlıdır. EÄŸer senkron sorunları yaÅŸarsanız deÄŸiÅŸik yöntemler deneyin. \n" +"\n" +"DeÄŸerlerin anlamları aÅŸağıdadır:\n" +"\n" +"otomatik\n" +"xine en ayarı bulmak için otomatik seçeneÄŸini atar\n" +"\n" +"getodelay\n" +"Sürücü gerçek zamanlı çalmayı desteklemese bile, SNDCTL_DSP_GETODELAY ioctl parametresini gerçek a/v senkronunu baÅŸarmak için kullanır.\n" +"\n" +"getoptr\n" +"Sürücü tercih edilen SNDCTL_DSP_GETODELAY ioctl parametresini kullansa bile, SNDCTL_DSP_GETOPTR ioctl parametresini gerçek a/v senkronunu baÅŸarmak için kullanır.\n" +"\n" +"softsync\n" +"sistem saati ile birlikte yazılım senkronizasyonunu kullanır;eÄŸer sistem saati kızı ses kartınızın çalma hızı ile uyuÅŸmaz ise ses ve görüntü, senkronize çalışmaz\n" +"\n" +"probebuffer\n" +"ses kartı tampon boyutunu sıfırlamak için tüm a/v senkronizasyonundaki gecikme süresini hesaplamayı araÅŸtırır; sisteminizin gerçek zamanlı ioctl (GiriÅŸ/Çıkış Kontrolu) uygulamalarından birini destekleyip desteklemediÄŸini denetlemek için veya uzun süreli çalmalardan sonra senkron hatası alırsanız bunu deneyin" + +#: src/audio_out/audio_oss_out.c:856 +msgid "" +"audio_oss_out: Audio driver realtime sync disabled...\n" +"audio_oss_out: ...will use system real-time clock for soft-sync instead\n" +"audio_oss_out: ...there may be audio/video synchronization issues\n" +msgstr "" +"audio_oss_out: Ses sürücüsü gerçek zamanlı senkron etkisizleÅŸtirildi...\n" +"audio_oss_out: ...soft-sync yerine sistem gerçek zamanlı saatini kullanacak\n" +"audio_oss_out: ...burada ses/görüntü senkronizasyon sorunları olabilir\n" + +#: src/audio_out/audio_oss_out.c:863 +msgid "OSS audio output latency (adjust a/v sync)" +msgstr "OSS ses çıkışı gecikme süresi (a/v/ senkronunu ayarlayın)" + +#: src/audio_out/audio_oss_out.c:877 +msgid "" +"audio_oss_out: Audio driver realtime sync disabled...\n" +"audio_oss_out: ...probing output buffer size: " +msgstr "" +"audio_oss_out: Ses sürücüsü gerçek zamanlı senkron etkisizleÅŸtirildi...\n" +"audio_oss_out: ...çıkış tampon boyutunu araÅŸtırıyor: " + +#: src/audio_out/audio_oss_out.c:894 +#, c-format +msgid "" +"%d bytes\n" +"audio_oss_out: ...there may be audio/video synchronization issues\n" +msgstr "" +"%d bytes\n" +"audio_oss_out: ...burada ses/görüntü senkronizasyon sorunları olabilir\n" + +#: src/audio_out/audio_oss_out.c:1023 +msgid "OSS audio mixer number, -1 for none" +msgstr "OSS ses karıştırıcısı numarası, hiçbiri için -1" + +#: src/audio_out/audio_oss_out.c:1024 +msgid "" +"The full mixer device name is created by taking the OSS device name, " +"replacing \"dsp\" with \"mixer\" and adding the mixer number.\n" +"If you do not need a number because you are happy with your system's default " +"mixer device, set this to -1.\n" +"The range of this value is -1 or 0-15. This setting is ignored, when the OSS " +"audio device name is set to \"auto\"." +msgstr "" +"Tam karıştırıcı aygıt adı OSS aygıtı adından alınarak oluÅŸturuldu, " +"\"dsp\" ile \"karıştırıcı\" yer deÄŸiÅŸtiriyor ve karıştırıcı numarası ekliyor.\n" +"EÄŸer sisteminizin varsayılan karıştırıcı aygıtınızdan memnun olduÄŸunuz için bir numaraya ihtiyacınız yoksa, bunu -1'e ayarlayın.\n" +"Bu deÄŸerin oranı -1 veya 0-15 arasındadır. Bu ayar OSS ses aygıt numarası \"auto\" olarak ayarlandığında göz ardı edilir." + +#: src/audio_out/audio_oss_out.c:1081 +#, c-format +msgid "audio_oss_out: open() mixer %s failed: %s\n" +msgstr "audio_oss_out: karıştırıcı() açılması %s baÅŸarılamadı: %s\n" + +#: src/audio_out/audio_oss_out.c:1154 +msgid "xine audio output plugin using oss-compliant audio devices/drivers" +msgstr "xine ses çıkışı eklentisi oss uyumlu aygıtları/sürücüleri kullanıyor" + +#: src/audio_out/audio_pulse_out.c:548 +msgid "device used for pulseaudio" +msgstr "pulseaudio için kullanılan aygıt" + +#: src/audio_out/audio_pulse_out.c:549 +msgid "use 'server[:sink]' for setting the pulseaudio sink device." +msgstr "sesatımı kısma aygıtını ayarlamak için sunucuyu [:kısma] kullanın." + +#: src/audio_out/audio_pulse_out.c:582 +msgid "xine audio output plugin using pulseaudio sound server" +msgstr "xine ses çıkışı eklentisi sesatımı uyumlu aygıtları/sürücüleri kullanıyor" + +#: src/audio_out/audio_sun_out.c:457 src/audio_out/audio_sun_out.c:950 +#, c-format +msgid "audio_sun_out: opening audio device %s failed: %s\n" +msgstr "audio_sun_out: ses aygıtı açılması baÅŸarılamadı %s failed: %s\n" + +#: src/audio_out/audio_sun_out.c:925 +msgid "Sun audio device name" +msgstr "Sun ses aygıtı adı" + +#: src/audio_out/audio_sun_out.c:926 +msgid "" +"Specifies the file name for the Sun audio device to be used.\n" +"This setting is security critical, because when changed to a different file, " +"xine can be used to fill this file with arbitrary content. So you should be " +"careful that the value you enter really is a proper Sun audio device." +msgstr "" +"Sun ses aygıtı kullanımı için dosya adını belirler.\n" +"Bu ayar güvenlik açısından tehlikelidir, çünkü farklı bir dosya olarak deÄŸiÅŸtirilirse, xine bu dosyayı keyfi bir içerikle doldurabilir. Bu nedenle, girdiÄŸiniz deÄŸerin Sun ses aygıtına uyması konusunda dikkatli olmalısınız." + +#: src/audio_out/audio_sun_out.c:968 +#, c-format +msgid "audio_sun_out: audio ioctl on device %s failed: %s\n" +msgstr "audio_sun_out: %s aygıtının ses ioctl (GiriÅŸ/Çıkış Denetimi) baÅŸarılamadı: %s\n" + +#: src/audio_out/audio_sun_out.c:1022 +msgid "xine audio output plugin using sun-compliant audio devices/drivers" +msgstr "xine ses çıkışı eklentisi sun uyumlu aygıtları/sürücüleri kullanıyor" + +#: src/demuxers/demux_asf.c:426 +#, c-format +msgid "demux_asf: warning: The stream id=%d is encrypted.\n" +msgstr "demux_asf: uyarı: Akış kimliÄŸi=%d ÅŸifrelidir.\n" + +#: src/demuxers/demux_asf.c:428 +msgid "Media stream scrambled/encrypted" +msgstr "Ortam akışı ÅŸifrelidir" + +#: src/demuxers/demux_avi.c:528 src/demuxers/demux_avi.c:642 +msgid "Restoring index..." +msgstr "İndeks Yeniden Yükleniyor..." + +#: src/demuxers/demux_avi.c:628 src/demuxers/demux_avi.c:1683 +#, c-format +msgid "demux_avi: invalid avi chunk \"%c%c%c%c\" at pos %\n" +msgstr "demux_avi: geçersiz avi yığını \"%c%c%c%c\" at pos %\n" + +#: src/demuxers/demux_avi.c:823 +#, c-format +msgid "demux_avi: avi index is broken\n" +msgstr "demux_avi: avi indeksi bozuk\n" + +#: src/demuxers/demux_avi.c:831 +#, c-format +msgid "demux_avi: failed to seek to the next chunk (pos %)\n" +msgstr "demux_avi: sonraki yığın bulunamadı (konum %)\n" + +#: src/demuxers/demux_film.c:186 +#, c-format +msgid "invalid FILM chunk size\n" +msgstr "geçersiz FILM yığını\n" + +#: src/demuxers/demux_film.c:340 +#, c-format +msgid "unrecognized FILM chunk\n" +msgstr "tanınmayan FILM yığını\n" + +#: src/demuxers/demux_flv.c:178 +#, c-format +msgid "unsupported FLV version (%d).\n" +msgstr "desteklenmeyen FLV sürümü (%d).\n" + +#: src/demuxers/demux_flv.c:185 +msgid "neither video nor audio stream in this file.\n" +msgstr "bu dosya içerisinde ses ya da görüntü akışı yok.\n" + +#: src/demuxers/demux_iff.c:233 +#, c-format +msgid "iff-8svx/16sv: unknown compression: %d\n" +msgstr "iff-8svx/16sv: bilinmeyen sıkıştırma: %d\n" + +#: src/demuxers/demux_iff.c:367 +#, c-format +msgid "iff-ilbm: unknown compression: %d\n" +msgstr "iff-ilbm: bilinmeyen sıkıştırma: %d\n" + +#: src/demuxers/demux_iff.c:568 +#, c-format +msgid "iff: unknown Chunk: %s\n" +msgstr "iff: bilinmeyen Yığın: %s\n" + +#: src/demuxers/demux_mpc.c:210 +msgid "demux_mpc: frame too big for buffer" +msgstr "demux_mpc: çerçeve önbellek için çok büyük" + +#: src/demuxers/demux_mpeg_block.c:294 +#, c-format +msgid "" +"xine-lib:demux_mpeg_block: Unrecognised stream_id 0x%02x. Please report this " +"to xine developers.\n" +msgstr "" +"xine-lib:demux_mpeg_block: Tanınmayan akış_kimliÄŸi 0x%02x. Lütfen bunu " +"xine geliÅŸtiricilerine bildirin.\n" + +#: src/demuxers/demux_mpeg_block.c:305 +msgid "demux_mpeg_block: error! freeing. Please report this to xine developers.\n" +msgstr "" +"demux_mpeg_block: hata! boÅŸaltılıyor.Lütfen bunu " +"xine geliÅŸtiricilerine bildirin.\n" + +#: src/demuxers/demux_mpeg_block.c:637 +#, c-format +msgid "demux_mpeg_block: warning: PES header reserved 10 bits not found\n" +msgstr "demux_mpeg_block: uyarı: 10 bit olarak saklanan PES baÅŸlığı bulunamadı\n" + +#: src/demuxers/demux_mpeg_block.c:647 +#, c-format +msgid "" +"demux_mpeg_block: warning: PES header indicates that this stream may be " +"encrypted (encryption mode %d)\n" +msgstr "demux_mpeg_block: uyarı: PES baÅŸlığı bu akışın ÅŸifrelenmiÅŸ olabileceÄŸini bildiriyor (ÅŸifrelenmiÅŸ kip %d)\n" + +#: src/demuxers/demux_mpeg_pes.c:415 +#, c-format +msgid "" +"xine-lib:demux_mpeg_pes: Unrecognised stream_id 0x%02x. Please report this " +"to xine developers.\n" +msgstr "" +"xine-lib:demux_mpeg_pes: Tanınmayan akış_kimliÄŸi 0x%02x. Lütfen bunu " +"xine geliÅŸtiricilerine bildirin.\n" + +#: src/demuxers/demux_mpeg_pes.c:424 +#, c-format +msgid "demux_mpeg_pes: warning: PACK stream id=0x%x decode failed.\n" +msgstr "demux_mpeg_pes: uyarı: PACK akış kimliÄŸi=0x%x kodlamasının açılması iÅŸlemi baÅŸarısız oldu.\n" + +#: src/demuxers/demux_mpeg_pes.c:806 +#, c-format +msgid "demux_mpeg_pes: warning: PES header reserved 10 bits not found\n" +msgstr "demux_mpeg_pes: uyarı: 10 bit olarak saklanan PES baÅŸlığı bulunamadı\n" + +#: src/demuxers/demux_mpeg_pes.c:816 +#, c-format +msgid "" +"demux_mpeg_pes: warning: PES header indicates that this stream may be " +"encrypted (encryption mode %d)\n" +msgstr "demux_mpeg_pes: uyarı: PES baÅŸlığı bu akışın ÅŸifrelenmiÅŸ olabileceÄŸini bildiriyor (ÅŸifrelenmiÅŸ kip %d)\n" + +#: src/demuxers/demux_mpeg_pes.c:1090 +#, c-format +msgid "" +"demux_mpeg_pes:Unrecognised private stream 1 0x%02x. Please report this to " +"xine developers.\n" +msgstr "" +"demux_mpeg_pes:Tanınmayan gizli akış 1 0x%02x. Lütfen bunu " +"xine geliÅŸtiricilerine bildirin.\n" + +#: src/demuxers/demux_ogg.c:805 +#, c-format +msgid "ogg: vorbis audio track indicated but no vorbis stream header found.\n" +msgstr "ogg: vorbis ses izi bulundu ama hiç vorbis akış baÅŸlığı bulunamadı.\n" + +#: src/demuxers/demux_snd.c:102 +#, c-format +msgid "demux_snd: bad header parameters\n" +msgstr "demux_snd: kötü baÅŸlık parametreleri\n" + +#: src/demuxers/demux_snd.c:147 +#, c-format +msgid "demux_snd: unsupported audio type: %d\n" +msgstr "demux_snd: desteklenmeyen ses tipi: %d\n" + +#: src/demuxers/demux_tta.c:86 +msgid "demux_tta: total frames count too high\n" +msgstr "demux_tta: toplam çerçeve sayısı çok yüksek\n" + +#: src/demuxers/demux_voc.c:103 +#, c-format +msgid "unknown VOC block type (0x%02X); please report to xine developers\n" +msgstr "bilinmeyen VOC blok tipi (0x%02X); lütfen bunu xine geliÅŸtiricilerine bildirin.\n" + +#: src/demuxers/demux_voc.c:118 +#, c-format +msgid "unknown VOC compression type (0x%02X); please report to xine developers\n" +msgstr "bilinmeyen VOC sıkıştırma tipi (0x%02X); lütfen bunu xine geliÅŸtiricilerine bildirin.\n" + +#: src/demuxers/demux_wc3movie.c:190 +#, c-format +msgid "demux_wc3movie: SHOT chunk referenced invalid palette (%d >= %d)\n" +msgstr "demux_wc3movie: SHOT yığını geçersiz paleti gösterdi (%d >= %d)\n" + +#: src/demuxers/demux_wc3movie.c:404 +#, c-format +msgid "demux_wc3movie: There was a problem while loading palette chunks\n" +msgstr "demux_wc3movie: Palet yığınlarını yüklerken bir sorunla karşılaÅŸtı\n" + +#: src/dxr3/dxr3.h:30 +msgid "DXR3 device number" +msgstr "DXR3 aygıt numarası" + +#: src/dxr3/dxr3.h:31 +msgid "" +"If you have more than one DXR3 in your computer, you can specify which one " +"to use here." +msgstr "EÄŸer bilgisayarınızda birden fazla DXR3 varsa, burada hangisini kullanacağınızı belirlemelisiniz." + +#: src/dxr3/dxr3_decode_spu.c:251 +#, c-format +msgid "dxr3_decode_spu: Failed to open spu device %s (%s)\n" +msgstr "dxr3_decode_spu: spu device %s (%s) yüklenemedi\n" + +#: src/dxr3/dxr3_decode_spu.c:661 +msgid "requested button not available\n" +msgstr "istenilen düğme kullanılabilir deÄŸil\n" + +#: src/dxr3/dxr3_decode_video.c:248 +#, c-format +msgid "dxr3_decode_video: Failed to open control device %s (%s)\n" +msgstr "dxr3_decode_video: Denetim aygıtı %s (%s) açılamadı\n" + +#: src/dxr3/dxr3_decode_video.c:254 +msgid "use Pan & Scan info" +msgstr "Panla & Tara bilgisini kullanın" + +#: src/dxr3/dxr3_decode_video.c:255 +msgid "" +"\"Pan & Scan\" is a special display mode which is sometimes used in MPEG " +"encoded material. You can specify here, how to handle such content.\n" +"\n" +"only when forced\n" +"Use Pan & Scan only, when the content you are playing enforces it.\n" +"\n" +"use MPEG hint\n" +"Enable Pan & Scan based on information embedded in the MPEG video stream.\n" +"\n" +"use DVB hint\n" +"Enable Pan & Scan based on information embedded in DVB streams. This makes " +"use of the Active Format Descriptor (AFD) used in some European DVB channels." +msgstr "" +"\"Panla & Tara\" bazen MPEG kodlama malzemesinde kullanılan özel bir görüntüleme kipidir. Böyle bir içeriÄŸin nasıl kullanılacağını burada belirleyebilirsiniz.\n" +"\n" +"sadece zorunluluk halinde\n" +"Yalnızca çalmakta olduÄŸunuz içerik sizi mecbur bıraktığında Panla & Tara özelliÄŸini kullanınız.\n" +"\n" +"MPEG iÅŸareti\n" +"MPEG görüntü akışına gömülü bilgiyi temel alan Panla & Tara seçeneÄŸini etkinleÅŸtiriniz.\n" +"\n" +"DVB iÅŸaretini kullan\n" +"DVB görüntü akışına gömülü bilgiyi temel alan Panla & Tara seçeneÄŸini etkinleÅŸtiriniz. Bu bazı Avrupa DVB kanallarında kullanılan Etkin Kip Tanımlayıcısı'nın (AFD) kullanımını saÄŸlar." + +#: src/dxr3/dxr3_decode_video.c:274 +msgid "try to sync video every frame" +msgstr "her çerçevede görüntüyü eÅŸzamanlamayı dene" + +#: src/dxr3/dxr3_decode_video.c:275 +msgid "" +"Tries to set a synchronization timestamp for every frame. Normally this is " +"not necessary, because sync is sufficent even when the timestamp is set only " +"every now and then.\n" +"This is relevant for progressive video only (most PAL films)." +msgstr "" +"EÄŸer kare için zaman çizelgesinin senkronize edilmesini dener. Normalde bu gerekli deÄŸildir, çünkü zaman çizelgesi ayarlanmış olsun veya olması senkron uygundur.\n" +"Bu sadece yürüyen görüntü için geçerlidir (çoÄŸu PAL görüntüde oluÄŸu gibi)." + +#: src/dxr3/dxr3_decode_video.c:281 +msgid "use smooth play mode" +msgstr "düz oynatma kipini kullan" + +#: src/dxr3/dxr3_decode_video.c:282 +msgid "Enabling this option will utilise a smoother play mode." +msgstr "Bu seçeneÄŸi etkinleÅŸtirmek daha yumuÅŸak bir çalma kipine geçiÅŸi saÄŸlayacaktır." + +#: src/dxr3/dxr3_decode_video.c:285 +msgid "correct frame durations in broken streams" +msgstr "kırık akışlarda çerçeve sürelerini düzelt" + +#: src/dxr3/dxr3_decode_video.c:286 +msgid "" +"Enables a small logic that corrects the frame durations of some mpeg streams " +"with wrong framerate codes. Currently a correction for NTSC streams " +"erroneously labeled as PAL streams is implemented. Enable only, when you " +"encounter such streams." +msgstr "Bazı hatalı kare sürelerine sahip mpeg akışlarındaki yanlış kare hatası kodlarını düzelten bir küçük mantığı etkinleÅŸtirir. Bu hata karşımıza daha çok yanlışlıkla PAL akışı olarak etiketlenmiÅŸ NTSC akışlarında karşımıza çıkar. Bu özelliÄŸi böylesi akışlarla karşılaÅŸtığınızda etkinleÅŸtirin." + +#: src/dxr3/dxr3_decode_video.c:545 +#, c-format +msgid "dxr3_decode_video: Failed to open video device %s (%s)\n" +msgstr "dxr3_decode_video: Aygıt açılamadı %s (%s)\n" + +#: src/dxr3/dxr3_decode_video.c:613 +msgid "dxr3_decode_video: write to device would block. flushing\n" +msgstr "dxr3_decode_video: kızarmayı önlemesi için aygıta yazar\n" + +#: src/dxr3/dxr3_decode_video.c:617 +#, c-format +msgid "dxr3_decode_video: video device write failed (%s)\n" +msgstr "dxr3_decode_video: görüntü aygıtına yazılamadı (%s)\n" + +#: src/dxr3/dxr3_decode_video.c:732 +#, c-format +msgid "dxr3_decode_video: WARNING: unknown frame rate code %d\n" +msgstr "dxr3_decode_video: UYARI: bilinmeyen çerçevesi oranı kodu %d\n" + +#: src/dxr3/dxr3_decode_video.c:760 +msgid "dxr3_decode_video: WARNING: correcting frame rate code from PAL to NTSC\n" +msgstr "dxr3_decode_video: UYARI: çerçeve oranı kodu PAL'den NTSC'ye çevriliyor\n" + +#: src/dxr3/dxr3_mpeg_encoders.c:123 +msgid "dxr3_mpeg_encoder: failed to init librte\n" +msgstr "dxr3_mpeg_encoder: librte baÅŸlatılamadı\n" + +#: src/dxr3/dxr3_mpeg_encoders.c:158 +msgid "" +"dxr3_mpeg_encoder: rte only handles video dimensions which are multiples of " +"16\n" +msgstr "dxr3_mpeg_encoder: 16 çoklamasına sahip görüntü boyutlarında sadece rte \n" + +#: src/dxr3/dxr3_mpeg_encoders.c:168 +msgid "dxr3_mpeg_encoder: failed to get rte context.\n" +msgstr "dxr3_mpeg_encoder: rte baÄŸlamı alınamadı.\n" + +#: src/dxr3/dxr3_mpeg_encoders.c:179 +msgid "dxr3_mpeg_encoder: could not create codec.\n" +msgstr "dxr3_mpeg_encoder: kodlayıcı oluÅŸturulamadı.\n" + +#: src/dxr3/dxr3_mpeg_encoders.c:187 +msgid "rte mpeg output bitrate (kbit/s)" +msgstr "rte mpeg çıktısı bit oranı (kbit/s)" + +#: src/dxr3/dxr3_mpeg_encoders.c:188 +msgid "" +"The bitrate the mpeg encoder library librte should use for DXR3's encoding " +"mode. Higher values will increase quality and CPU usage." +msgstr "Mpeg kodlama kütüphanesi bit boyu olan librte, DXR3 kodlama kipini kullanmalı. Daha yüksek deÄŸerle kaliteyi ve iÅŸlemci kullanımını arttıracaktır." + +#: src/dxr3/dxr3_mpeg_encoders.c:232 +#, c-format +msgid "dxr3_mpeg_encoder: cannot init the context: %s\n" +msgstr "dxr3_mpeg_encoder: baÄŸlam baÅŸlatılamadı: %s\n" + +#: src/dxr3/dxr3_mpeg_encoders.c:240 +#, c-format +msgid "dxr3_mpeg_encoder: cannot start encoding: %s\n" +msgstr "dxr3_mpeg_encoder: kodlamaya baÅŸlanamadı: %s\n" + +#: src/dxr3/dxr3_mpeg_encoders.c:370 +msgid "dxr3_mpeg_encoder: Couldn't start the FAME library\n" +msgstr "dxr3_mpeg_encoder: FAME kütüphanesi baÅŸlatılamadı\n" + +#: src/dxr3/dxr3_mpeg_encoders.c:385 +msgid "fame mpeg encoding quality" +msgstr "fame mpeg kodlama kalitesi" + +#: src/dxr3/dxr3_mpeg_encoders.c:386 +msgid "" +"The encoding quality of the libfame mpeg encoder library. Lower is faster " +"but gives noticeable artifacts. Higher is better but slower." +msgstr "Libfame mpeg kodlama kütüphanesinin kodlama kalitesi. YavaÅŸ, daha hızlıdır ama dikkat çekici bir özellik katar. Daha hızlı, daha iyidir, fakat daha yavaÅŸtır." + +#: src/dxr3/dxr3_scr.c:96 +msgid "SCR plugin priority" +msgstr "SCR eklenti önceliÄŸi" + +#: src/dxr3/dxr3_scr.c:97 +msgid "" +"Priority of the DXR3 SCR plugin. Values less than 5 mean that the unix " +"system timer will be used. Values greater 5 force to use DXR3's internal " +"clock as sync source." +msgstr "DXR3 SCR eklentisinin önceliÄŸi. 5'den daha az olan deÄŸerler unix sistem zamanlayıcısının kullanılacağı anlamına gelir. 5'den daha büyük deÄŸerler DXR3'ü senkron kaynağı olarak dahili saati kullanması için zorlarlar." + +#: src/dxr3/video_out_dxr3.c:260 +msgid "swap odd and even lines" +msgstr "tek ve çift satırları deÄŸiÅŸtir" + +#: src/dxr3/video_out_dxr3.c:261 +msgid "" +"Swaps the even and odd field of the image.\n" +"Enable this option for non-MPEG material which produces a vertical jitter on " +"screen." +msgstr "" +"Resmin tek ve çift alanlarını deÄŸiÅŸtirir.\n" +"Bu seçeneÄŸi MPEG malzemesi dışında ekranda dikey oynamalar üretmek için etkinleÅŸtirin." + +#: src/dxr3/video_out_dxr3.c:265 +msgid "add black bars to correct aspect ratio" +msgstr "görünüm oranını düzeltmek için siyah çubuklar ekle" + +#: src/dxr3/video_out_dxr3.c:266 +msgid "" +"Adds black bars when the image has an aspect ratio the card cannot handle " +"natively. This is needed to maintain proper image proportions." +msgstr "Resim görüntü oranı kartı ile baÅŸa çıkamadığında siyah çizgiler ekler. Bu uygun görüntü kesitleri oluÅŸturulmak isteniÄŸinde gereklidir." + +#: src/dxr3/video_out_dxr3.c:271 +msgid "use smooth play mode for mpeg encoder playback" +msgstr "mpeg kodlayıcı oynatması için pürüzsüz oynatmayı kullan" + +#: src/dxr3/video_out_dxr3.c:272 +msgid "Enabling this option will utilise a smoother play mode for non-MPEG content." +msgstr "Bu seçeneÄŸi etkinleÅŸtirmek MPEG içeriÄŸi dışındaki kaynaklar için daha yumuÅŸak oynatma kipine geçiÅŸi saÄŸlayacaktır." + +#: src/dxr3/video_out_dxr3.c:280 +#, c-format +msgid "video_out_dxr3: Failed to open control device %s (%s)\n" +msgstr "video_out_dxr3: Denetim aygıtı %s (%s) açılamadı\n" + +#: src/dxr3/video_out_dxr3.c:288 +#, c-format +msgid "video_out_dxr3: Failed to open video device %s (%s)\n" +msgstr "video_out_dxr3: Görüntü aygıtı %s (%s) açılamadı\n" + +#: src/dxr3/video_out_dxr3.c:334 +msgid "encoder for non mpeg content" +msgstr "mpeg olmayan içerik için kodlayıcı" + +#: src/dxr3/video_out_dxr3.c:335 +msgid "" +"Content other than MPEG has to pass an additional reencoding stage, because " +"the dxr3 handles only MPEG.\n" +"Depending on what is supported by your xine, this setting can be \"fame\", " +"\"rte\", \"libavcodec\" or \"none\".\n" +"The \"libavcodec\" encoder makes use of the ffmpeg plugin that already ships " +"with xine, so you do not need to install any additional library for that. " +"Even better is that libavcodec also provides high quality with low CPU " +"usage. Using \"libavcodec\" is therefore strongly suggested.\n" +"\"fame\" and \"rte\" are still there, but xine support for them is outdated, " +"so these might fail to work." +msgstr "" +"MPEG dışındaki içeriÄŸin, ek bir yeniden kodlanma aÅŸamasından geçmesi gereklidir, çünkü dxr3 sadece MPEG ile baÅŸa çıkabilir.\n" +"xine'nin neyi desteklediÄŸine baÄŸlı olarak, bu ayar \"fame\", \"rte\", \"libavcodec\" veya \"hiçbiri\". olarak ayarlanabilir.\n" +"\"libavcodec\" kodlayıcısı xine ile çalışan ffmpeg eklentisinin çalışmasına sebep olur, böylece bunun için ek bir kütüphane dosyası yüklemek zorunda kalmazsınız. Hatta daha iyi bir olanak olarak, libavcodec'in aynı zamanda düşük iÅŸlemci hızıyla yüksek kalitede performans gösterdiÄŸidir. \"libavcodec\" kullanılması bu yüzden ÅŸiddetle tavsiye edilir.\n" +"\"fame\" ve \"rtre\" hala oradadırlar, fakat xine onları güncel olarak desteklemezler, bu yüzden çalışmazlar." + +#: src/dxr3/video_out_dxr3.c:346 +msgid "video_out_dxr3: Mpeg encoder libavcodec failed to init.\n" +msgstr "video_out_dxr3: Mpeg kodlayıcı libavcodec baÅŸlatılamadı.\n" + +#: src/dxr3/video_out_dxr3.c:352 +msgid "video_out_dxr3: Mpeg encoder rte failed to init.\n" +msgstr "video_out_dxr3: Mpeg kodlayıcı rte baÅŸlatılamadı.\n" + +#: src/dxr3/video_out_dxr3.c:359 +msgid "video_out_dxr3: Mpeg encoder fame failed to init.\n" +msgstr "video_out_dxr3: Mpeg kodlayıcı fame baÅŸlatılamadı.\n" + +#: src/dxr3/video_out_dxr3.c:365 +msgid "" +"video_out_dxr3: Mpeg encoding disabled.\n" +"video_out_dxr3: that's ok, you don't need it for mpeg video like DVDs, but\n" +"video_out_dxr3: you will not be able to play non-mpeg content using this " +"video out\n" +"video_out_dxr3: driver. See the README.dxr3 for details on configuring an " +"encoder.\n" +msgstr "" +"video_out_dxr3: Mpeg kodlaması edilgenleÅŸtirilmiÅŸ.\n" +"video_out_dxr3: burası tamamdır, ona DVDler gibi mpeg video amacıyla ihtiyacınız yoktur, fakat\n" +"video_out_dxr3: bu görüntü çıkışını kullanarak mpeg-dışı içeriÄŸi oynatamazsınız\n" +"video_out_dxr3: sürücü. kodlayıcıyı yapılandırmak hakkında daha detaylı bilgiler için README.dxr3 dosyasını okuyunuz.\n" + +#: src/dxr3/video_out_dxr3.c:371 +msgid "" +"video_out_dxr3: No mpeg encoder compiled in.\n" +"video_out_dxr3: that's ok, you don't need it for mpeg video like DVDs, but\n" +"video_out_dxr3: you will not be able to play non-mpeg content using this " +"video out\n" +"video_out_dxr3: driver. See the README.dxr3 for details on configuring an " +"encoder.\n" +msgstr "" +"video_out_dxr3: Hiç bir mpeg kodlayıcısı derlenmemiÅŸtir.\n" +"video_out_dxr3: burası tamamdır, ona DVDler gibi mpeg görüntü amacıyla ihtiyacınız yoktur, fakat\n" +"video_out_dxr3: bu görüntü çıkışını kullanarak mpeg-dışı içeriÄŸi oynatamazsınız\n" +"video_out_dxr3: sürücü. kodlayıcıyı yapılandırmak hakkında daha detaylı bilgiler için README.dxr3 dosyasını okuyunuz.\n" + +#: src/dxr3/video_out_dxr3.c:386 +msgid "video output mode (TV or overlay)" +msgstr "görüntü çıktı kipi (TV ya da üstyazım)" + +#: src/dxr3/video_out_dxr3.c:387 +msgid "" +"The way the DXR3 outputs the final video can be set here. The individual " +"values are:\n" +"\n" +"letterboxed tv\n" +"Send video to the TV out connector only. This is the mode used for the " +"standard 4:3 television set. Anamorphic (16:9) video will be displayed " +"letterboxed, pan&scan material will have the image cropped at the left and " +"right side. This is the common setting for TV viewing and acts like a " +"standalone DVD player.\n" +"\n" +"widescreen tv\n" +"Send video to the tv out connector only. This mode is intended for 16:9 " +"widescreen TV sets. Anamorphic and pan&scan content will fill the entire " +"screen, but you have to set the TV's aspect ratio manually to 16:9 using " +"your.\n" +"\n" +"letterboxed overlay\n" +"Overlay Video output on the computer screen with the option of on-the-fly " +"switching to TV out by hiding the video window. The overlay will be " +"displayed with black borders if it is anamorphic (16:9).\n" +"This setting is only useful in the rare case of a DVD subtitle channel that " +"would only display properly in letterbox mode. A good example for that are " +"the animated commentator's silhouettes on \"Ghostbusters\".\n" +"\n" +"widescreen overlay\n" +"Overlay Video output on the computer screen with the option of on-the-fly " +"switching to TV out by hiding the video window. This is the common variant " +"of DXR3 overlay." +msgstr "" +"BitmiÅŸ görüntü için DXR3 çıkışlarının yolları buradan ayarlanabilir. KiÅŸisel deÄŸerler:\n" +"\n" +"harfkutucuklu tv\n" +"görüntüyü sadece TV çıkış baÄŸlantılarına gönderme. Bu standart 4:3 televizyonlar için kullanılan bir kiptir. Anamorfik (16:9) görüntü harfkutucuklu görüntülenecektir, panla&tara malzemesi görüntünün saÄŸ ve sol tarafta kesilmiÅŸ gibi görüntülenmesine yol açacaktır. Bu televizyonun bağımsız DVD çalıcı gibi kullanıldığı ortak bir ayardır.\n" +"\n" +"geniÅŸ ekran tv\n" +"Görüntüyü sadece TV çıkış baÄŸlantılarına gönderme. Bu kip 16:9 geniÅŸ ekran TV setleri için oluÅŸturulmuÅŸtur. Anamorfik ve panla&tara içeriÄŸi tüm ekranı kaplayacaktır, fakat televizyonun görüntü ayarlarını elle 16:9 ekran boyutunda kullanacak ÅŸekilde ayarlamalısınız.\n" +"\n" +"harfkutucuklu kaplama\n" +"Bilgisayar ekranındaki üstyazım görüntü çıkışının, görüntü ekranının gizlenmesi suretiyle TV çıkışına geçirilmesidir. EÄŸer kaynak anamorfik (16:9) ise, üstyazım siyah çerçeveyle görüntülenecektir.\n" +"Bu ayar, DVD altyazı kanalının sadece harfkutucuklu kipte düzgün görüntülenebildiÄŸi ender durumlarda faydalı olabilecektir. Bunun için en iyi örnek \"Ghostbusters\" filmindeki hareketli yorumcu silüetleridir.\n" +"\n" +"geniÅŸ ekran kaplama\n" +"Bilgisayar ekranındaki üstyazım görüntü çıkışının, görüntü ekranının gizlenmesi suretiyle TV çıkışına geçirilmesidir. Bu DXR3 kaplamasının ortak deÄŸiÅŸkenidir." + +#: src/dxr3/video_out_dxr3.c:434 +msgid "overlay colorkey value" +msgstr "katman renk deÄŸeri" + +#: src/dxr3/video_out_dxr3.c:434 +msgid "" +"Hexadecimal RGB value of the key color.\n" +"You can try different values, if you experience windows becoming transparent " +"when using DXR3 overlay mode." +msgstr "" +"Anahtar rengin onaltılık RGB deÄŸeri.\n" +"EÄŸer DXR3 katman kipini kullandığınızda pencereler ÅŸeffaflaşırsa deÄŸiÅŸik deÄŸerler deneyebilirsiniz." + +#: src/dxr3/video_out_dxr3.c:439 +msgid "overlay colorkey tolerance" +msgstr "katman renk toleransı" + +#: src/dxr3/video_out_dxr3.c:439 +msgid "" +"A greater value widens the tolerance for the overlay keycolor.\n" +"You can try lower values, if you experience windows becoming transparent " +"when using DXR3 overlay mode, but parts of the image borders may disappear " +"when using a too low setting." +msgstr "" +"Daha büyük bir deÄŸer katmak renginin toleransını geniÅŸletebilir.\n" +"EÄŸer DXR3 katman kipini kullandığınızda pencereler ÅŸeffaflaşırsa daha düşük deÄŸerler deneyebilirsiniz, fakat çok daha düşük bir deÄŸer denediÄŸinizde görüntü sınırlarının bazı kısımları kaybolabilir." + +#: src/dxr3/video_out_dxr3.c:445 +msgid "crop the overlay area at top and bottom" +msgstr "Üst ve altın katman bölgesini kesin" + +#: src/dxr3/video_out_dxr3.c:446 +msgid "" +"Removes one pixel line from the top and bottom of the overlay. Enable this, " +"if you see green lines at the top or bottom of the overlay." +msgstr "Katmanın üst ve altından bir piksel satırını çıkarır. Katmanın üst ve altındaki yeÅŸil satırı görmek isterseniz bunu etkinleÅŸtirin." + +#: src/dxr3/video_out_dxr3.c:450 +msgid "video_out_dxr3: please run autocal, overlay disabled\n" +msgstr "video_out_dxr3: lütfen otomatik ayarı çalıştırın, katman kayboldu\n" + +#: src/dxr3/video_out_dxr3.c:460 +msgid "preferred tv mode" +msgstr "tercih edilen tv kipi" + +#: src/dxr3/video_out_dxr3.c:460 +msgid "" +"Selects the TV mode to be used by the DXR3. The values mean:\n" +"\n" +"ntsc: NTSC at 60Hz\n" +"pal: PAL at 50Hz\n" +"pal60: PAL at 60Hz\n" +"default: keep the card's setting" +msgstr "" +"DXR3 kullanarak TV kipini seçer. DeÄŸerlerin anlamları şöyledir:\n" +"\n" +"ntsc: saniyede 60Hz hızındaki NTSC\n" +"pal: saniyede 50Hz hızındaki PAL\n" +"pal60: saniyede 60Hz hızındaki PAL\n" +"varsayılan: ekran kartının ayarlarını korur" + +#: src/dxr3/video_out_dxr3.c:482 +msgid "video_out_dxr3: setting video mode failed.\n" +msgstr "video_out_dxr3: görüntü kipi ayarlanamadı.\n" + +#: src/dxr3/video_out_dxr3.c:712 +msgid "" +"video_out_dxr3: Need an mpeg encoder to play non-mpeg videos on dxr3\n" +"video_out_dxr3: Read the README.dxr3 for details.\n" +msgstr "" +"video_out_dxr3: mpeg-dışı görüntüleri oynatmak için dxr3 üzerinde bir mpeg kodlayıcısına ihtiyaç duyar\n" +"video_out_dxr3: Detaylar için README.dxr3 dosyasını okuyun.\n" + +#: src/dxr3/video_out_dxr3.c:1371 +msgid "video_out_dxr3: ERROR Reading overlay init file. Run autocal!\n" +msgstr "video_out_dxr3: HATA Katman init dosyasını okuyor. Otomatik kullanımı çalıştırın!\n" + +#: src/input/input_cdda.c:1616 +#, c-format +msgid "%s: can't connect to %s:%d\n" +msgstr "%s: %s konumuna baÄŸlanılamadı:%d\n" + +#: src/input/input_cdda.c:1663 +#, c-format +msgid "input_cdda: successfuly connected to cddb server '%s:%d'.\n" +msgstr "input_cdda: cddb sunucusuna baÅŸarılı bir ÅŸekilde baÄŸlandı '%s:%d'.\n" + +#: src/input/input_cdda.c:1668 +#, c-format +msgid "input_cdda: failed to connect to cddb server '%s:%d' (%s).\n" +msgstr "input_cdda: cddb sunucusuna '%s:%d' (%s) baÄŸlanma iÅŸlemi baÅŸarısız oldu.\n" + +#: src/input/input_cdda.c:2702 +msgid "CD Digital Audio (aka. CDDA)" +msgstr "CD Dijital Ses (CDDA olarak da bilinir)" + +#: src/input/input_cdda.c:2755 +msgid "device used for CD audio" +msgstr "CD sesi için kullanılan aygıt" + +#: src/input/input_cdda.c:2756 +msgid "" +"The path to the device, usually a CD or DVD drive, which you intend to use " +"for playing audio CDs." +msgstr "Aygıta giden yol, ses CDlerini çalmak amacıyla kullandığınız CD yada DVD sürücüsü." + +#: src/input/input_cdda.c:2762 +msgid "query CDDB" +msgstr "CDDB sorgusu" + +#: src/input/input_cdda.c:2762 +msgid "" +"Enables CDDB queries, which will give you convenient title and track names " +"for your audio CDs.\n" +"Keep in mind that, unless you use your own private CDDB, this information is " +"retrieved from an internet server which might collect a profile of your " +"listening habits." +msgstr "" +"Ses CD'niz için uygun baÅŸlıklar ve iz isimleri sunan CDDB sorgularını etkinleÅŸtirir.\n" +"Size özel, kiÅŸisel CDDB'yi kullanmadığınız taktirde sizin dinlediÄŸiniz müziklerinizin toplanmasından yola çıkarak oluÅŸturulan profiliniz paralelinde bir aÄŸ sunucusundan ilgili bilgilerin toplandığını aklınızdan çıkarmayınız." + +#: src/input/input_cdda.c:2770 +msgid "CDDB server name" +msgstr "CDDB sunucu adı" + +#: src/input/input_cdda.c:2770 +msgid "" +"The CDDB server used to retrieve the title and track information from.\n" +"This setting is security critical, because the sever will receive " +"information about your listening habits and could answer the queries with " +"malicious replies. Be sure to enter a server you can trust." +msgstr "" +"CDDB sunucusu baÅŸlık ve iz bilgilerinin toplanması için kullanılır.\n" +"Bu ayar güvenlik açısından kritiktir, çünkü sunucu sizin dinleme alışkanlıklarınız hakkında bilgiler toplayacak ve kötü niyetli sorguları cevaplandıracaktır. Güvenilir sunucuları kullanmayı deneyin." + +#: src/input/input_cdda.c:2778 +msgid "CDDB server port" +msgstr "CDDB sunucu portu" + +#: src/input/input_cdda.c:2778 +msgid "The server port used to retrieve the title and track information from." +msgstr "Sunucu portu baÅŸlık ve iz bilgisini almak için kullanıldı." + +#: src/input/input_cdda.c:2784 +msgid "CDDB cache directory" +msgstr "CDDB önbellek dizini" + +#: src/input/input_cdda.c:2784 +msgid "" +"The replies from the CDDB server will be cached in this directory.\n" +"This setting is security critical, because files with uncontrollable names " +"will be created in this directory. Be sure to use a dedicated directory not " +"used for anything but CDDB caching." +msgstr "" +"CDDB sunucusundan gelen cevaplar bu dizinde saklanacaktır.\n" +"Bu ayar güvenlik açısından kritiktir, çünkü bu dizinde dosyalara verilen isimler denetlenemeyecektir. Bu dizini CDDB depolanması dışında baÅŸka amaçla kullanmamaya özen gösterin." + +#: src/input/input_cdda.c:2792 +msgid "slow down disc drive to this speed factor" +msgstr "disk sürücüsünün hızını seviyesine düşür" + +#: src/input/input_cdda.c:2793 +msgid "" +"Since some CD or DVD drives make some really loud noises because of the fast " +"disc rotation, xine will try to slow them down. With standard CD or DVD " +"playback, the high datarates that require the fast rotation are not needed, " +"so the slowdown should not affect playback performance.\n" +"A value of zero here will disable the slowdown." +msgstr "" +"Bazı CD ve DVD sürücüler hızlı disk dönüşü nedeniyle çok ses çıkaracağı için, xine onları yavaÅŸlatmayı deneyecektir. Standart CD veya DVD çalınırken, hızlı dönüşü gerektiren yüksek verilere ihtiyaç duyulmaz, böylece yavaÅŸlama, çalma performansını etkilemez.\n" +"Buradaki sıfır deÄŸeri yavaÅŸlamayı devre dışı bırakacaktır." + +#: src/input/input_dvb.c:895 +#, c-format +msgid "input_dvb: failed to open dvb channel file '%s': %s\n" +msgstr "input_dvb: dvb kanal dosyası açılamadı '%s': %s\n" + +#: src/input/input_dvb.c:901 +#, c-format +msgid "input_dvb: dvb channel file '%s' is not a plain file\n" +msgstr "input_dvb: dvb kanal dosyası '%s' düz bir dosya deÄŸil\n" + +#: src/input/input_dvb.c:2139 src/input/input_dvb.c:2971 +msgid "input_dvb: tuner_set_channel failed\n" +msgstr "input_dvb: tuner_set_channel baÅŸarısız oldu\n" + +#: src/input/input_dvb.c:2771 src/input/input_dvb.c:3197 +msgid "input_dvb: cannot open dvb device\n" +msgstr "input_dvb: dvb aygıtı açılamadı\n" + +#: src/input/input_dvb.c:2795 +#, c-format +msgid "input_dvb: channel %d out of range, defaulting to 0\n" +msgstr "input_dvb: kanal %d sınırların dışında, Sıfırlanıyor\n" + +#: src/input/input_dvb.c:2806 +#, c-format +msgid "input_dvb: searching for channel %s\n" +msgstr "input_dvb: %s kanalını arıyor\n" + +#: src/input/input_dvb.c:2829 +#, c-format +msgid "input_dvb: exact match for %s not found: trying partial matches\n" +msgstr "input_dvb: %s için tam eÅŸleÅŸme bulunamadı: kısmi eÅŸleÅŸmeler deneniyor\n" + +#: src/input/input_dvb.c:2836 +#, c-format +msgid "input_dvb: found matching channel %s\n" +msgstr "input_dvb: %s eÅŸleÅŸen kanal bulundu\n" + +#: src/input/input_dvb.c:2849 +#, c-format +msgid "input_dvb: channel %s not found in channels.conf, defaulting.\n" +msgstr "input_dvb: %s kanalı channels.conf dosyasında bulunamadı, öntanımlı deÄŸerlere dönülüyor.\n" + +#: src/input/input_dvb.c:2855 +msgid "" +"input_dvb: invalid channel specification, defaulting to last viewed " +"channel.\n" +msgstr "" +"input_dvb: geçersiz kanal belirtimi, son görüntülenen kanala " +"dönülüyor.\n" + +#: src/input/input_dvb.c:2861 +msgid "input_dvb: invalid channel specification, defaulting to channel 0\n" +msgstr "input_dvb: geçersiz kanal belirtimi, kanal 0(sıfır)'a dönülüyor.\n" + +#: src/input/input_dvb.c:2873 +msgid "" +"input_dvb: dvbs mrl specified but the tuner doesn't appear to be QPSK (DVB-" +"S)\n" +msgstr "input_dvb: dvb'nin mrl deÄŸeri belirtilmiÅŸ fakat alıcı QPSK (DVB-S) gibi gözükmemekte.\n" + +#: src/input/input_dvb.c:2893 +msgid "" +"input_dvb: dvbt mrl specified but the tuner doesn't appear to be OFDM (DVB-" +"T)\n" +msgstr "input_dvb: dvbt'nin mrl deÄŸeri belirtilmiÅŸ fakat alıcı OFDM (DVB-T) gibi gözükmemekte.\n" + +#: src/input/input_dvb.c:2916 +msgid "" +"input_dvb: dvbc mrl specified but the tuner doesn't appear to be QAM (DVB-" +"C)\n" +msgstr "input_dvb: dvbc'nin mrl deÄŸeri belirtilmiÅŸ fakat alıcı QAM (DVB-C) gibi gözükmemekte.\n" + +#: src/input/input_dvb.c:2942 +msgid "" +"input_dvb: dvba mrl specified but the tuner doesn't appear to be ATSC (DVB-" +"A)\n" +msgstr "input_dvb: dvba'nın mrl deÄŸeri belirtilmiÅŸ fakat alıcı ATSC (DVB-A) gibi gözükmemekte.\n" + +#: src/input/input_dvb.c:2977 +#, c-format +msgid "input_dvb: cannot open dvr device '%s'\n" +msgstr "input_dvb: dvr aygıtını açamıyor '%s'\n" + +#: src/input/input_dvb.c:2999 +msgid "input_dvb: cannot create EPG updater thread\n" +msgstr "input_dvb: EPG güncelleyici bağı yaratamıyor\n" + +#: src/input/input_dvb.c:3061 +msgid "use DVB 'center cutout' (zoom)" +msgstr "DVB merkez kesmesini kullan (yakınlaÅŸtır)" + +#: src/input/input_dvb.c:3062 +msgid "" +"This will allow fullscreen playback of 4:3 content transmitted in a 16:9 " +"frame." +msgstr "Bu, 4:3 tam ekran oynatımı içeriÄŸinin 16:9 çerçevesinde gösterilmesine izin verecektır." + +#: src/input/input_dvb.c:3155 +msgid "DVB (Digital TV) input plugin" +msgstr "DVB (Dijital TV) girdi eklentisi" + +#: src/input/input_dvb.c:3284 +msgid "Remember last DVB channel watched" +msgstr "Son izlenen DVB kanalını hatırla" + +#: src/input/input_dvb.c:3285 +msgid "" +"On autoplay, xine will remember and switch to the channel indicated in media." +"dvb.last_channel. " +msgstr "" +"Otomatik çalmada, xine hatırlayacak ve ortamdaki ilgili kanala geçecektir. " +"dvb.son_kanal." + +#: src/input/input_dvb.c:3292 +msgid "Last DVB channel viewed" +msgstr "Görüntülenen son DVB kanalı" + +#: src/input/input_dvb.c:3293 +msgid "If enabled xine will remember and switch to this channel. " +msgstr "EÄŸer etkinleÅŸtirilmiÅŸse, xine hatırlayacak ve bu kanala geçecektir." + +#: src/input/input_dvb.c:3298 +msgid "Number of seconds until tuning times out." +msgstr "Ayarın süresinin dolmasına kalan saniyelerin sayısı" + +#: src/input/input_dvb.c:3299 +msgid "" +"Leave at 0 means try forever. Greater than 0 means wait that many seconds to " +"get a lock. Minimum is 5 seconds." +msgstr "0'da bırakmak, sürekli dene anlamına gelir. 0'dan büyükler kilitlenmeye kadar bekleyin anlamına gelir. En az olanı 5 saniyedir." + +#: src/input/input_dvb.c:3305 +msgid "Number of dvb card to use." +msgstr "Kullanılacak dvb kartların sayısı." + +#: src/input/input_dvb.c:3306 +msgid "Leave this at zero unless you really have more than 1 card in your system." +msgstr "EÄŸer sisteminizde birden fazla kart yoksa bunu sıfırda bırakın." + +#: src/input/input_dvd.c:588 +msgid "input_dvd: values of \\beta will give rise to dom!\n" +msgstr "input_dvd: values of \\beta will give rise to dom!\n" + +#: src/input/input_dvd.c:607 +#, c-format +msgid "input_dvd: Error getting next block from DVD (%s)\n" +msgstr "input_dvd: DVD (%s) ortamından sonraki blok alınamadı\n" + +#: src/input/input_dvd.c:1497 +msgid "input_dvd: Error opening DVD device\n" +msgstr "input_dvd: DVD aygıtı açılırken hata oluÅŸtu\n" + +#: src/input/input_dvd.c:1784 +msgid "device used for DVD playback" +msgstr "DVD oynatmak için kullanılacak aygıt" + +#: src/input/input_dvd.c:1785 +msgid "" +"The path to the device, usually a DVD drive, which you intend to use for " +"playing DVDs." +msgstr "Aygıta giden yol, genellikle DVDleri oynatmak amacıyla kullanılan DVD sürücüsü." + +#: src/input/input_dvd.c:1803 +msgid "raw device set up for DVD access" +msgstr "DVD giriÅŸi için yeni aygıt ayarı" + +#: src/input/input_dvd.c:1804 +msgid "" +"If this points to a raw device connected to your DVD device, xine will use " +"the raw device for playback. This has the advantage of being slightly faster " +"and of bypassing the block device cache, which avoids throwing away " +"important cache content by keeping DVD data cached. Using the block device " +"cache for DVDs is useless, because almost all DVD data will be used only " +"once.\n" +"See the documentation on raw device setup (man raw) for further information." +msgstr "" +"EÄŸer bu, yeni aygıtın DVD aygıtına baÄŸlı olduÄŸunu gösterirse, xine çalmak için yeni aygıtı kullanacaktır. Bu daha hızlı olma konusunda bir avantajdır ve DVD verilerinin tutulduÄŸu önemli bellek içeriklerinin kaybolmasını önleyen blok belleÄŸin atlanmasını saÄŸlar. Aygıt belleÄŸinin DVD için bloke edilmesi kullanışsızdır, çünkü tüm DVD verisi sadece bir kez kullanılacaktır.\n" +"Daha fazla bilgi için yeni aygıt ayarı (man raw) belgesine bakınız." + +#: src/input/input_dvd.c:1817 +msgid "CSS decryption method" +msgstr "CSS ÅŸifre çözme yöntemi" + +#: src/input/input_dvd.c:1818 +msgid "" +"Selects the decryption method libdvdcss will use to descramble copy " +"protected DVDs. Try the various methods, if you have problems playing " +"scrambled DVDs." +msgstr "Åžifreyi kırma yöntemini seçer, libdvdcss kopya korumalı DVDlerin ÅŸifrelerini çözmekte kullanılacaktır. EÄŸer ÅŸifreli DVD'leri çalmakta problemler yaÅŸarsanzı deÄŸiÅŸik yöntemler deneyin." + +#: src/input/input_dvd.c:1826 +msgid "path to the title key cache" +msgstr "anahtar bellek baÅŸlığı yolu" + +#: src/input/input_dvd.c:1827 +msgid "" +"Since cracking the copy protection of scrambled DVDs can be quite time " +"consuming, libdvdcss will cache the cracked keys in this directory.\n" +"This setting is security critical, because files with uncontrollable names " +"will be created in this directory. Be sure to use a dedicated directory not " +"used for anything but DVD key caching." +msgstr "" +"Åžifre korumalı DVDlerin çözümlenmesi zaman alacağından, libdvdcss kırılmış anahtarların bu dizinde saklayacaktır.\n" +"Bu ayar güvenlik açısından kritiktir, çünkü bu dizinde denetlenemeyen adlara sahip dosyalar oluÅŸturulabilir. Bu önemli dizini DVD anahtar saklamanın dışında baÅŸka amaçlarla kullanmamaya özen gösterin." + +#: src/input/input_dvd.c:1849 +msgid "region the DVD player claims to be in (1 to 8)" +msgstr "DVD çaların kapsadığı bölge (1 ile 8 arası)" + +#: src/input/input_dvd.c:1850 +msgid "" +"This only needs to be changed if your DVD jumps to a screen complaining " +"about a wrong region code. It has nothing to do with the region code set in " +"DVD drives, this is purely software." +msgstr "EÄŸer DVDniz hatalı bölge kodunu ekranda gösterirse, sadece bu durumda gereklidir. Yazılımın özelliÄŸinden dolayı, DVD sürücülerine ayarlanan bölge kodları ile ilgili bir deÄŸiÅŸikli yapılamaz." + +#: src/input/input_dvd.c:1856 +msgid "default language for DVD playback" +msgstr "DVD oynatmak için öntanımlı dil" + +#: src/input/input_dvd.c:1857 +msgid "" +"xine tries to use this language as a default for DVD playback. As far as the " +"DVD supports it, menus and audio tracks will be presented in this language.\n" +"The value must be a two character ISO639 language code." +msgstr "" +"xine, ön tanımlı DVD çalma dili olarak bunu kullanmayı dener. DVD'nin desteklediÄŸi ölçüde, menüler ve ses izleri bu dilde sunulacaktır.\n" +"Dil kodu deÄŸerinin iki karakterli ISO639 dil kodu olması gereklidir." + +#: src/input/input_dvd.c:1863 +msgid "read-ahead caching" +msgstr "tamponlama boyunca oku" + +#: src/input/input_dvd.c:1864 +msgid "" +"xine can use a read ahead cache for DVD drive access.\n" +"This may lead to jerky playback on slow drives, but it improves the impact " +"of the DVD layer change on faster drives." +msgstr "" +"xine, DVD sürücü yolu için tamponlama boyunca oku özelliÄŸini kullanabilir.\n" +"Bu özellik, yavaÅŸ çalışan sürücülerde kötü çalmalara sebebiyet verebilir, fakat o daha hızlı sürücülerde DVD katman deÄŸiÅŸiminin etkisini güçlendirir." + +#: src/input/input_dvd.c:1870 +msgid "unit for the skip action" +msgstr "atlama eylemi için birim" + +#: src/input/input_dvd.c:1871 +msgid "" +"You can configure the behaviour when issuing a skip command (using the skip " +"buttons for example). The individual values mean:\n" +"\n" +"skip program\n" +"will skip a DVD program, which is a navigational unit similar to the index " +"marks on an audio CD; this is the normal behaviour for DVD players\n" +"\n" +"skip part\n" +"will skip a DVD part, which is a structural unit similar to the track marks " +"on an audio CD; parts usually coincide with programs, but parts can be " +"larger than programs\n" +"\n" +"skip title\n" +"will skip a DVD title, which is a structural unit representing entire " +"features on the DVD" +msgstr "" +"Bir atlama komutunu kullanırken davranışı yapılandırlabilirsiniz (örneÄŸin atlama tuÅŸlarını kullanarak). Bireysel deÄŸerler ÅŸu anlama gelir:\n" +"\n" +"program atla\n" +"Ses CD'sindeki içindekileri gösteren yapıya benzer ÅŸekilde görüntülenebilir bir ünite olan DVD programına atlayacaktır\n" +"\n " +"kısım atla\n" +"bir ses CD'sindeki iz iÅŸaretlerine benzeyen yapısal bir ünite olan DVD kısmına atlayacaktır, kısımlar programlarla uyumludur, fakat kısımlar programlardan daha büyük olabilirler.\n" +"\n" +"baÅŸlığı atla\n" +"DVD'deki tüm özellikleri gösteren yapısal bir birim olan DVD başılığını atlayacaktır" + +#: src/input/input_dvd.c:1886 +msgid "unit for seeking" +msgstr "arama birimi" + +#: src/input/input_dvd.c:1887 +msgid "" +"You can configure the domain spanned by the seek slider. The individual " +"values mean:\n" +"\n" +"seek in program chain\n" +"seeking will span an entire DVD program chain, which is a navigational unit " +"representing the entire video stream of the current feature\n" +"\n" +"seek in program\n" +"seeking will span a DVD program, which is a navigational unit representing a " +"chapter of the current feature" +msgstr "" +"Arama kaydıracı ile kullanılan alanı yapılandırabilirsiniz. KiÅŸisel deÄŸerlerin anlamları:\n" +"\n" +"program zincirinde ara\n" +"arama tüm DVD program zincirini baÄŸlayacaktır, geçerli özelliÄŸin tüm görüntü akışını gösteren gözlemsel bir birimdir bu\n" +"n " +"programda arama\n" +"arama tüm DVD program zincirini baÄŸlayacaktır, geçerli özelliÄŸin bölümlerini gösteren gözlemsel bir birimdir bu" + +#: src/input/input_dvd.c:1898 +msgid "play mode when title/chapter is given" +msgstr "baÅŸlık/bölüm verildiÄŸindeki çalma kipi" + +#: src/input/input_dvd.c:1899 +msgid "" +"You can configure the behaviour when playing a dvd from a given title/" +"chapter (eg. using MRL 'dvd:/1.2'). The individual values mean:\n" +"\n" +"entire dvd\n" +"play the entire dvd starting on the specified position.\n" +"\n" +"one chapter\n" +"play just the specified title/chapter and then stop" +msgstr "" +"VerilmiÅŸ bir baÅŸlık/bölüm'den bir dvd çalarken davranış modelini yapılandırabilirsiniz (örneÄŸin MRL kullanıyor dvd:/1.2). Bireysel deÄŸerlerin anlamları:\n" +"\n" +"tüm dvd\n" +"tüm dvd'yi belirlenen konumdan baÅŸlayarak çal.\n" +"bir bölüm\n" +"sadece belirlenen baÅŸlık/bölüm'ü çal ve dur" + +#: src/input/input_file.c:201 +#, c-format +msgid "input_file: read error (%s)\n" +msgstr "input_file: okuma hatası (%s)\n" + +#: src/input/input_file.c:361 +#, c-format +msgid "input_file: Permission denied: >%s<\n" +msgstr "input_file: İzin verilmedi: >%s<\n" + +#: src/input/input_file.c:365 +#, c-format +msgid "input_file: File not found: >%s<\n" +msgstr "input_file: Dosya bulunamadı: >%s<\n" + +#: src/input/input_file.c:403 src/input/input_gnome_vfs.c:290 +#, c-format +msgid "input_file: File empty: >%s<\n" +msgstr "input_file: Dosya boÅŸ: >%s<\n" + +#: src/input/input_file.c:624 +msgid "file input plugin" +msgstr "dosya girdi eklentisi" + +#: src/input/input_file.c:993 +msgid "file browsing start location" +msgstr "dosya açma baÅŸlangıç konumu" + +#: src/input/input_file.c:994 +msgid "The browser to select the file to play will start at this location." +msgstr "Çalınması istenen dosyanın bu konumdan baÄŸlayacağını seçen tarayıcı." + +#: src/input/input_file.c:1001 +msgid "list hidden files" +msgstr "gizli dosyaları listele" + +#: src/input/input_file.c:1002 +msgid "" +"If enabled, the browser to select the file to play will also show hidden " +"files." +msgstr "EÄŸer etkinleÅŸtirilmiÅŸse, çalınacak dosyayı seçen tarayıcı aynı zamanda gizli dosyaları da gösterebilir." + +#: src/input/input_gnome_vfs.c:216 +msgid "gnome-vfs input plugin as shipped with xine" +msgstr "xine ile birlikte gelen gnome vfs giriÅŸi" + +#: src/input/input_http.c:176 +#, c-format +msgid "input_http: gethostbyname(%s) failed: %s\n" +msgstr "input_http: gethostbyname(%s) baÅŸarısız oldu: %s\n" + +#: src/input/input_http.c:421 src/input/input_http.c:1002 +#, c-format +msgid "input_http: read error %d\n" +msgstr "input_http: okuma hatası %d\n" + +#: src/input/input_http.c:648 +msgid "Connecting HTTP server..." +msgstr "HTTP sunucusuna baÄŸlanılıyor..." + +#: src/input/input_http.c:840 +#, c-format +msgid "input_http: invalid http answer\n" +msgstr "input_http: geçersiz http yanıtı\n" + +#: src/input/input_http.c:846 +#, c-format +msgid "input_http: 3xx redirection: >%d %s<\n" +msgstr "input_http: 3xx yeniden yönlendirme: >%d %s<\n" + +#: src/input/input_http.c:851 src/input/input_http.c:857 +#: src/input/input_http.c:864 +#, c-format +msgid "input_http: http status not 2xx: >%d %s<\n" +msgstr "input_http: http durumu 2xx deÄŸil: >%d %s<\n" + +#: src/input/input_http.c:874 +#, c-format +msgid "input_http: content length = % bytes\n" +msgstr "input_http: içerik büyüklüğü = % byte\n" + +#: src/input/input_http.c:957 +#, c-format +msgid "input_http: buffer exhausted after %d bytes." +msgstr "input_http: %d byte ardından önbellek boÅŸaltıldı." + +#: src/input/input_http.c:1055 +msgid "http input plugin" +msgstr "http girdi eklentisi" + +#: src/input/input_http.c:1121 +msgid "HTTP proxy host" +msgstr "HTTP vekil sunucu makinesi" + +#: src/input/input_http.c:1121 +msgid "The hostname of the HTTP proxy." +msgstr "HTTP vekil sunucusu için makine adı." + +#: src/input/input_http.c:1125 +msgid "HTTP proxy port" +msgstr "HTTP vekil sunucu portu" + +#: src/input/input_http.c:1125 +msgid "The port number of the HTTP proxy." +msgstr "HTTP vekil sunucusu için port numarası." + +#: src/input/input_http.c:1135 +msgid "HTTP proxy username" +msgstr "HTTP vekil sunucu kullanıcı adı" + +#: src/input/input_http.c:1136 +msgid "The user name for the HTTP proxy." +msgstr "HTTP vekil sunucusu için kullanıcı adı." + +#: src/input/input_http.c:1139 +msgid "HTTP proxy password" +msgstr "HTTP vekil sunucu parolası" + +#: src/input/input_http.c:1140 +msgid "The password for the HTTP proxy." +msgstr "HTTP vekil sunucusu için parola." + +#: src/input/input_http.c:1143 +msgid "Domains for which to ignore the HTTP proxy" +msgstr "HTTP vekilini göz ardı etmek için alanlar" + +#: src/input/input_http.c:1144 +msgid "" +"A comma-separated list of domain names for which the proxy is to be " +"ignored.\n" +"If a domain name is prefixed with '=' then it is treated as a host name only " +"(full match required)." +msgstr "" +"Vekilin göz ardı edilmesi için birbirinden virgülle ayrılan alan adları listesi.\n" +"EÄŸer bir alan adı '=' ile ön ek almışsa, o zaman ona sadece ana makina adı olarak bakmak gerekir (tam uyuÅŸum gereklidir)." + +#: src/input/input_mms.c:441 +msgid "mms streaming input plugin" +msgstr "mms yayın girdi eklentisi" + +#: src/input/input_mms.c:477 src/input/librtsp/rtsp_session.c:91 +msgid "network bandwidth" +msgstr "aÄŸ bant geniÅŸliÄŸi" + +#: src/input/input_mms.c:478 src/input/librtsp/rtsp_session.c:92 +msgid "" +"Specify the bandwidth of your internet connection here. This will be used " +"when streaming servers offer different versions with different bandwidth " +"requirements of the same stream." +msgstr "İnternet baÄŸlantınızın bant geniÅŸliÄŸini burada belirtiniz. Bu, yayın akışı sunucularının aynı yayın akışını farklı bant geniÅŸliÄŸi gereksinimleriyle önerdiklerinde kullanılacaktır." + +#: src/input/input_mms.c:487 +msgid "MMS protocol" +msgstr "MMS protokolü" + +#: src/input/input_mms.c:488 +msgid "" +"Select the protocol to encapsulate MMS.\n" +"TCP is better but you may need HTTP behind a firewall." +msgstr "" +"MMS için kullanılacak protokolü seçin.\n" +"TCP daha iyidir ancak bir güvenlik duvarı kullanıyorsanız HTTP seçmeniz gerekir." + +#: src/input/input_net.c:121 src/input/input_net.c:151 +#, c-format +msgid "input_net: socket(): %s\n" +msgstr "input_net: socket(): %s\n" + +#: src/input/input_net.c:136 src/input/input_net.c:162 +#, c-format +msgid "input_net: connect(): %s\n" +msgstr "input_net: connect(): %s\n" + +#: src/input/input_net.c:180 src/input/input_net.c:222 +#, c-format +msgid "input_net: unable to resolve '%s'.\n" +msgstr "input_net: '%s' çözümlenemedi.\n" + +#: src/input/input_net.c:193 src/input/input_net.c:239 +#, c-format +msgid "input_net: unable to connect to '%s'.\n" +msgstr "input_net: '%s' konumuna baÄŸlanılamadı.\n" + +#: src/input/input_net.c:508 +msgid "net input plugin as shipped with xine" +msgstr "xine ile birlikte gelen aÄŸ giriÅŸi eklentisi" + +#: src/input/input_pnm.c:262 +msgid "pnm streaming input plugin" +msgstr "pnm yayın girdi eklentisi" + +#: src/input/input_pvr.c:601 +#, c-format +msgid "input_pvr: error creating pvr file (%s)\n" +msgstr "input_pvr: pvr dosyası oluÅŸturma hatası (%s)\n" + +#: src/input/input_pvr.c:758 +#, c-format +msgid "input_pvr: error opening pvr file (%s)\n" +msgstr "input_pvr: pvr dosyası açma hatası (%s)\n" + +#: src/input/input_pvr.c:834 +#, c-format +msgid "input_pvr: read error (%s)\n" +msgstr "input_pvr: okuma hatası (%s)\n" + +#: src/input/input_pvr.c:1150 src/input/input_pvr.c:1403 +#, c-format +msgid "input_pvr: error opening device %s\n" +msgstr "input_pvr: %s aygıtı açılamadı\n" + +#: src/input/input_pvr.c:1156 src/input/input_pvr.c:1409 +msgid "input_pvr: IVTV_IOC_G_CODEC failed, maybe API changed?\n" +msgstr "input_pvr: IVTV_IOC_G_CODEC baÅŸarısız oldu, API deÄŸiÅŸmiÅŸ olabilir mi?\n" + +#: src/input/input_pvr.c:1164 src/input/input_pvr.c:1418 +msgid "input_pvr: IVTV_IOC_S_CODEC failed, maybe API changed?\n" +msgstr "input_pvr: IVTV_IOC_S_CODEC baÅŸarısız oldu, API deÄŸiÅŸmiÅŸ olabilir mi?\n" + +#: src/input/input_pvr.c:1526 +msgid "WinTV-PVR 250/350 input plugin" +msgstr "WinTV-PVR 250/350 girdi eklentisi" + +#: src/input/input_pvr.c:1552 +msgid "device used for WinTV-PVR 250/350 (pvr plugin)" +msgstr "WinTV-PVR 250/350 (pvr eklentisi) için kullanılan aygıt" + +#: src/input/input_pvr.c:1553 +msgid "The path to the device of your WinTV card." +msgstr "WinTV kartınızın aygıt yolu." + +#: src/input/input_rtp.c:183 +#, c-format +msgid "socket(): %s.\n" +msgstr "socket(): %s.\n" + +#: src/input/input_rtp.c:193 +msgid "IP address specified is multicast\n" +msgstr "IP adresi çoklu yayın olarak belirlendi\n" + +#: src/input/input_rtp.c:202 +#, c-format +msgid "setsockopt(SO_RCVBUF): %s.\n" +msgstr "setsockopt(SO_RCVBUF): %s.\n" + +#: src/input/input_rtp.c:210 +#, c-format +msgid "setsockopt(SO_REUSEADDR): %s.\n" +msgstr "setsockopt(SO_REUSEADDR): %s.\n" + +#: src/input/input_rtp.c:217 +#, c-format +msgid "bind(): %s.\n" +msgstr "bind(): %s.\n" + +#: src/input/input_rtp.c:237 +#, c-format +msgid "Can't find address for iface %s:%s\n" +msgstr "%s iface için adres bulunamadı:%s\n" + +#: src/input/input_rtp.c:255 +#, c-format +msgid "setsockopt(IP_ADD_MEMBERSHIP) failed (multicast kernel?): %s.\n" +msgstr "setsockopt(IP_ADD_MEMBERSHIP) baÅŸarısız oldu (multicast kernel?): %s.\n" + +#: src/input/input_rtp.c:277 +#, c-format +msgid "unable to resolve '%s'.\n" +msgstr "'%s' çözümlenemedi.\n" + +#: src/input/input_rtp.c:287 +#, c-format +msgid "unable to bind to '%s'.\n" +msgstr "Buraya baÄŸlanamadı %s'.\n" + +#: src/input/input_rtp.c:336 +#, c-format +msgid "recv(): %s.\n" +msgstr "recv(): %s.\n" + +#: src/input/input_rtp.c:630 +msgid "RTP: stopping reading thread...\n" +msgstr "RTP: okuma iÅŸini durduruyor...\n" + +#: src/input/input_rtp.c:633 +msgid "RTP: reading thread terminated\n" +msgstr "RTP: okuma iÅŸi kapatıldı\n" + +#: src/input/input_rtp.c:648 +#, c-format +msgid "Opening >filename:%s port:%d interface:%s<\n" +msgstr "Dosya adını >açıyor:%s baÄŸlantı noktası:%d arabirim:%s<\n" + +#: src/input/input_rtp.c:665 +#, c-format +msgid "input_rtp: can't create new thread (%s)\n" +msgstr "input_rtp: yeni iÅŸ üretemez (%s)\n" + +#: src/input/input_rtp.c:769 +msgid "RTP and UDP input plugin as shipped with xine" +msgstr "xine ile birlikte gelen RTP ve UDP giriÅŸ eklentisi" + +#: src/input/input_rtsp.c:284 +msgid "rtsp streaming input plugin" +msgstr "rtsp yayın girdi eklentisi" + +#: src/input/input_smb.c:156 +msgid "CIFS/SMB input plugin based on libsmbclient" +msgstr "libsmbclient temelli CIFS/SMB girdi eklentisi" + +#: src/input/input_stdin_fifo.c:164 +#, c-format +msgid "stdin: cannot seek back! (% > %)\n" +msgstr "stdin: geri arama yapamaz! (% > %)\n" + +#: src/input/input_stdin_fifo.c:252 +#, c-format +msgid "stdin: failed to open '%s'\n" +msgstr "stdin: '%s' açılamadı\n" + +#: src/input/input_stdin_fifo.c:348 +msgid "stdin streaming input plugin" +msgstr "stdin yayın girdi eklentisi" + +#: src/input/input_v4l.c:379 +msgid "Buffer underrun..." +msgstr "Tampon bellek zayıfladı..." + +#: src/input/input_v4l.c:383 +msgid "Buffer overrun..." +msgstr "Tampon bellek aşımı..." + +#: src/input/input_v4l.c:386 +msgid "Adjusting..." +msgstr "Ayarlanıyor..." + +#: src/input/input_v4l.c:658 +msgid "Tuner name not found\n" +msgstr "Tuner adı bulunamadı\n" + +#: src/input/input_v4l.c:1874 +msgid "v4l tv input plugin" +msgstr "v4l tv girdi eklentisi" + +#: src/input/input_v4l.c:1878 +msgid "v4l radio input plugin" +msgstr "v4l radyo girdi eklentisi" + +#: src/input/input_v4l.c:1910 +msgid "v4l video device" +msgstr "v4l görüntü aygıtı" + +#: src/input/input_v4l.c:1911 +msgid "The path to your Video4Linux video device." +msgstr "Video4Linux görüntü aygıtının yolu." + +#: src/input/input_v4l.c:1936 +msgid "v4l radio device" +msgstr "v4l radyo aygıtı" + +#: src/input/input_v4l.c:1937 +msgid "The path to your Video4Linux radio device." +msgstr "Video4Linux radyo aygıtının yolu." + +#: src/input/input_vcd.c:847 +msgid "input_vcd: malformed MRL. Use vcdo:/\n" +msgstr "input_vcd: bozuk MRL. vcdo:/ kullanın\n" + +#: src/input/input_vcd.c:853 +#, c-format +msgid "input_vcd: invalid track %d (valid range: 0 .. %d)\n" +msgstr "input_vcd: geçersiz iz %d (geçerli oran: 0 .. %d)\n" + +#: src/input/input_vcd.c:920 +msgid "Video CD input plugin" +msgstr "Video CD girdi eklentisi" + +#: src/input/input_vcd.c:965 +#, c-format +msgid "unable to open %s: %s.\n" +msgstr "%s açılamadı: %s.\n" + +#: src/input/input_vcd.c:1041 +#, c-format +msgid "input_vcd: unable to open %s: %s.\n" +msgstr "input_vcd: %s açılamadı: %s.\n" + +#: src/input/input_vcd.c:1095 +msgid "device used for VCD playback" +msgstr "VCD oynatmak için kullanılan aygıt" + +#: src/input/input_vcd.c:1096 +msgid "" +"The path to the device, usually a CD or DVD drive, you intend to play your " +"VideoCDs with." +msgstr "Video CD'lerinizi çalmak istediÄŸiniz ve genellikle CD veya DVD sürücü olarak bilinen aygıta giden yol." + +#: src/input/librtsp/rtsp.c:448 +#, c-format +msgid "rtsp: bad mrl: %s\n" +msgstr "rtsp: bozuk mrl: %s\n" + +#: src/input/librtsp/rtsp.c:508 +#, c-format +msgid "rtsp: failed to connect to '%s'\n" +msgstr "rtsp: '%s' konumuna baÄŸlanılamadı\n" + +#: src/input/librtsp/rtsp_session.c:107 +#, c-format +msgid "rtsp_session: failed to connect to server %s\n" +msgstr "rtsp_session: %s sunucusuna baÄŸlanılamadı\n" + +#: src/input/librtsp/rtsp_session.c:141 +msgid "rtsp_session: session can not be established.\n" +msgstr "rtsp_session: oturuma eriÅŸilemedi.\n" + +#: src/input/librtsp/rtsp_session.c:159 +#, c-format +msgid "rtsp_session: rtsp server type '%s' not supported yet. sorry.\n" +msgstr "rtsp_session: rtsp sunucu tipi '%s' henüz desteklenmiyor. üzgünüm.\n" + +#: src/input/media_helper.c:148 +#, c-format +msgid "input_dvd: Device %s failed to open during eject calls\n" +msgstr "input_dvd: eject çaÄŸrıları sırasında %s aygıtı açılamadı\n" + +#: src/input/mms.c:559 +msgid "Connecting MMS server (over tcp)..." +msgstr "MMS sunucusuna baÄŸlanılıyor (tcp üzerinden)..." + +#: src/input/mmsh.c:199 +msgid "libmmsh: send error\n" +msgstr "libmmsh: gönderme hatası\n" + +#: src/input/mmsh.c:244 +#, c-format +msgid "libmmsh: bad response format\n" +msgstr "libmmsh: kötü yanıt biçimi\n" + +#: src/input/mmsh.c:250 +#, c-format +msgid "libmmsh: 3xx redirection not implemented: >%d %s<\n" +msgstr "libmmsh: 3xx yeniden yönlendirme uygulamaya eklenmedi: >%d %s<\n" + +#: src/input/mmsh.c:257 +#, c-format +msgid "libmmsh: http status not 2xx: >%d %s<\n" +msgstr "libmmsh: http durumu 2xx deÄŸil: >%d %s<\n" + +#: src/input/mmsh.c:265 +#, c-format +msgid "libmmsh: Location redirection not implemented\n" +msgstr "libmmsh: Konum yeniden yönlendirmesi uygulamaya eklenmedi\n" + +#: src/input/mmsh.c:474 +msgid "Connecting MMS server (over http)..." +msgstr "MMS sunucuya baÄŸlanılıyor (http üzerinden)..." + +#: src/input/mmsh.c:655 +#, c-format +msgid "invalid url\n" +msgstr "geçersiz adres\n" + +#: src/input/mmsh.c:660 +#, c-format +msgid "unsupported protocol\n" +msgstr "desteklenmeyen protokol\n" + +#: src/input/net_buf_ctrl.c:89 +msgid "Buffering..." +msgstr "ÖnbelleÄŸe alınıyor..." + +#: src/input/pnm.c:615 +#, c-format +msgid "" +"input_pnm: got message from server while reading stream:\n" +"%s\n" +msgstr "" +"input_pnm: yayın akışıniı okurken sunucdan mesaj geldi:\n" +"%s\n" + +#: src/input/pnm.c:753 +#, c-format +msgid "input_pnm: failed to connect '%s'\n" +msgstr "input_pnm: '%s' konumuna baÄŸlanılamadı\n" + +#: src/input/pnm.c:764 +msgid "input_pnm: failed to set up stream\n" +msgstr "input_pnm: akış ayarlaması baÅŸarısız oldu\n" + +#: src/input/vcd/vcdio.c:222 +msgid "SEEK_CUR not implemented for non-zero offset" +msgstr "SEEK_CUR sıfır-dışı kolu için yerine getirilemedi" + +#: src/input/vcd/vcdio.c:250 +msgid "SEEK_END not implemented yet." +msgstr "SEEK_END henüz tamamlanmadı." + +#: src/input/vcd/vcdio.c:253 +msgid "seek not implemented yet for" +msgstr "için arama henüz tamamlanmadı" + +#: src/input/vcd/vcdplayer.c:94 +msgid "bad item type" +msgstr "hatalı öge tipi" + +#: src/input/vcd/vcdplayer.c:458 +msgid "bad entry number" +msgstr "hatalı girdi numarası" + +#: src/input/vcd/vcdplayer.c:491 +msgid "bad segment number" +msgstr "hatalı parça numarası" + +#: src/input/vcd/vcdplayer.c:501 +msgid "Error in getting current segment number" +msgstr "Geçerli bölüm numarası alma hatası" + +#: src/input/vcd/vcdplayer.c:589 +msgid "Should have converted this above" +msgstr "Bunun yukarıdakine dönüştürülmesi gerekirdi" + +#: src/input/vcd/xineplug_inp_vcd.c:191 +msgid "failed to find a device with a VCD" +msgstr "VCD içeren aygıt bulunamadı" + +#: src/input/vcd/xineplug_inp_vcd.c:328 +msgid "was passed a null class parameter" +msgstr "geçersiz sınıf parametresi atlandı" + +#: src/input/vcd/xineplug_inp_vcd.c:990 +msgid "Invalid current entry type" +msgstr "Geçersiz güncel girdi tipi" + +#: src/input/vcd/xineplug_inp_vcd.c:1014 +msgid "Video CD plugin with PBC and support for: (X)VCD, (X)SVCD, HQVCD, CVD ... " +msgstr "Åžunlar için PBC ile Video CD eklentisi ve desteÄŸi: (X)VCD, (X)SVCD, HQVCD, CVD ... " + +#: src/input/vcd/xineplug_inp_vcd.c:1115 +msgid "selection has no RETURN entry" +msgstr "seçim hiç RETURN giriÅŸe sahip deÄŸil" + +#: src/input/vcd/xineplug_inp_vcd.c:1144 +msgid "DEFAULT selected, but PBC is not on." +msgstr "DEFAULT seçili, fakat PBC açık deÄŸil." + +#: src/input/vcd/xineplug_inp_vcd.c:1149 +msgid "selection has no NEXT entry" +msgstr "seçim hiç NEXT giriÅŸe sahip deÄŸil" + +#: src/input/vcd/xineplug_inp_vcd.c:1157 +msgid "selection has no PREVIOUS entry" +msgstr "seçim hiç PREVIOUS giriÅŸe sahip deÄŸil" + +#: src/input/vcd/xineplug_inp_vcd.c:1164 +msgid "Unknown event type: " +msgstr "Bilinmeyen olay tipi: " + +#: src/input/vcd/xineplug_inp_vcd.c:1460 src/input/vcd/xineplug_inp_vcd.c:1507 +msgid "The above message had unknown vcdimager log level" +msgstr "Yukarıdaki ileti bilinmeyen vcdimager günlük seviyesine sahip" + +#: src/input/vcd/xineplug_inp_vcd.c:1838 +msgid "VCD default type to use on autoplay" +msgstr "Otomatik çalmayı kullanmak için VCD öntanımlı türü" + +#: src/input/vcd/xineplug_inp_vcd.c:1839 +msgid "" +"The VCD play unit to use when none is specified in an MRL, e.g. vcd:// or " +"vcd:///dev/dvd:" +msgstr "" +"Bir MRL'de hiçbirinin belirtilmediÄŸi konumu kullanan VCD çalma birimi, örn. vcd:// veya " +"vcd:///dev/dvd:" + +#: src/input/vcd/xineplug_inp_vcd.c:1849 +msgid "CD-ROM drive used for VCD when none given" +msgstr "Aksi belirtilmedikçe CD-ROM sürücüsü VCD için kullanılanacak" + +#: src/input/vcd/xineplug_inp_vcd.c:1850 +msgid "" +"What to use if no drive specified. If the setting is empty, xine will scan " +"for CD drives." +msgstr "EÄŸer hiç sürücü belirtilmemiÅŸse ne kullanmalı. EÄŸer ayarlar boÅŸ ise, xine CD sürücülerini bulmak üzere taramaya baÅŸlayacak." + +#: src/input/vcd/xineplug_inp_vcd.c:1860 +msgid "VCD position slider range" +msgstr "VCD konumu kaydırma alanı" + +#: src/input/vcd/xineplug_inp_vcd.c:1861 +msgid "range that the stream playback position slider represents playing a VCD." +msgstr "akış çalma konumu kaydırma alanının bir VCD çalmakta olduÄŸunu belirten bölge." + +#: src/input/vcd/xineplug_inp_vcd.c:1869 +msgid "VCD read-ahead caching?" +msgstr "Bellekleme yerine doÄŸrudan VCD'yi okusun mu?" + +#: src/input/vcd/xineplug_inp_vcd.c:1870 +msgid "Class may lead to jerky playback on low-end machines." +msgstr "Son-kullanıcı cihazlarında sınıf, kötü çalma sonuçlarına sebep olur." + +#: src/input/vcd/xineplug_inp_vcd.c:1880 +msgid "automatically advance VCD track/entry" +msgstr "VCD iz/giriÅŸ yapılarında otomatik ilerleme" + +#: src/input/vcd/xineplug_inp_vcd.c:1881 +msgid "" +"If enabled, we should automatically advance to the next entry or track. Used " +"only when playback control (PBC) is disabled." +msgstr "EÄŸer etkinleÅŸtirilmiÅŸse, otomatik olarak sonraki giriÅŸ veya ize geçebiliriz. Bu özellik, sadece eÄŸer çalma denetimi (PBC) devre dışı ise kullanılır." + +#: src/input/vcd/xineplug_inp_vcd.c:1890 +msgid "show 'rejected' VCD LIDs" +msgstr "reddedilen VCD'leri göster" + +#: src/input/vcd/xineplug_inp_vcd.c:1891 +msgid "" +"Some playback list IDs (LIDs) are marked not showable, but you can see them " +"in the MRL list if this is set. Rejected entries are marked with an asterisk " +"(*) appended to the MRL." +msgstr "Bazı çalma listeleri gösterilemez olarak iÅŸaretlenmiÅŸtir, fakat onları eÄŸer ayarlanmışsa MRL listesinde görebilirsiniz. Reddedilen girdiler yıldız (*) ile iÅŸaretlenmiÅŸ olup MRL'ye eklenmiÅŸtir." + +#: src/input/vcd/xineplug_inp_vcd.c:1902 +msgid "VCD format string for display banner" +msgstr "BaÅŸlığı görüntülemen için VCD kipi dizgesi" + +#: src/input/vcd/xineplug_inp_vcd.c:1903 +msgid "" +"VCD format used in the GUI Title. Similar to the Unix date command. Format " +"specifiers start with a percent sign. Specifiers are:\n" +" %A : The album information\n" +" %C : The VCD volume count - the number of CD's in the collection.\n" +" %c : The VCD volume num - the number of the CD in the collection.\n" +" %F : The VCD Format, e.g. VCD 1.0, VCD 1.1, VCD 2.0, or SVCD\n" +" %I : The current entry/segment/playback type, e.g. ENTRY, TRACK, ...\n" +" %L : The playlist ID prefixed with \" LID\" if it exists\n" +" %N : The current number of the above - a decimal number\n" +" %P : The publisher ID\n" +" %p : The preparer ID\n" +" %S : If we are in a segment (menu), the kind of segment\n" +" %T : The track number\n" +" %V : The volume set ID\n" +" %v : The volume ID\n" +" A number between 1 and the volume count.\n" +" %% : a %\n" +msgstr "" +"GUI BaÅŸlığı'nda kullanılan VCD kipi. Unix tarih komutuna benzer. Kip belirteci yüzde iÅŸaretiyle baÅŸlar. Belirteçler şöyledir: " +"\n" +" %A : Albüm bilgisi\n" +" %C : VCD ses seviyesi sayacı - seçimdeki CD'lerin numarası.\n" +" %c : VCD ses seviyesi numarası - seçimdeki CD'nin sayısı.\n" +" %F : Åžu anki girdi/kesit/çalma türü, v.b. GİRDİ, İZ, ...\n" +" %L : EÄŸer varsa \" LID\" önekli liste bilgisi\n" +" %N : Yukardakinin numarası - bir ondalık sayı\n" +" %P : Yayımcı kimliÄŸi\n" +" %p : Hazırlayıcı kimliÄŸi\n" +" %S : eÄŸer bir kesitte isek (menüdeysek), kesitin türü\n" +" %T : İz numarası\n" +" %V : Ses ayarı kimliÄŸi\\ " +" %v : Ses kimliÄŸi\n" +".......Ses ayarı sayısı ile 1 arası bir sayı.\n" +" %% : a %\n" + +#: src/input/vcd/xineplug_inp_vcd.c:1928 +msgid "VCD format string for stream comment field" +msgstr "Yayın akışı yorum alanı için VCD kipi dizgesi" + +#: src/input/vcd/xineplug_inp_vcd.c:1929 +msgid "" +"VCD format used in the GUI Title. Similar to the Unix date command. Format " +"specifiers start with a percent sign. Specifiers are %A, %C, %c, %F, %I, %L, " +"%N, %P, %p, %S, %T, %V, %v, and %%.\n" +"See the help for the title_format for the meanings of these." +msgstr "" +"GUI BaÅŸlığı'nda kullanılan VCD kipi. Unix tarih komutuna benzer. Kip belirteci yüzde iÅŸaretiyle baÅŸlar. Belirteçler şöyledir: %A, %C, %c, %F, %I, %L, " +"%N, %P, %p, %S, %T, %V, %v, and %%.\n" +"Bunların anlamları için baÅŸlık_kipi yardım dosyasına bakınız." + +#: src/input/vcd/xineplug_inp_vcd.c:1941 +msgid "VCD debug flag mask" +msgstr "VCD hata ayıklaması bayrak maskesi" + +#: src/input/vcd/xineplug_inp_vcd.c:1942 +msgid "" +"For tracking down bugs in the VCD plugin. Mask values are:\n" +" 1: Meta information\n" +" 2: input (keyboard/mouse) events\n" +" 4: MRL parsing\n" +" 8: Calls from external routines\n" +" 16: routine calls\n" +" 32: LSN changes\n" +" 64: Playback control\n" +" 128: Debugging from CDIO\n" +" 256: Seeks to set location\n" +" 512: Seeks to find current location\n" +"1024: Still-frame\n" +"2048: Debugging from VCDINFO\n" +msgstr "" +"VCD eklentilerindeki hataların izlerini sürmek için, Maske deÄŸerleri ÅŸunlardır:\n" +"...1: Meta bilgisi\n" +"...2: giriÅŸ (klavye/fare) olayları\n" +"...4: MRL incelemesi\n" +"...8: Dış yordamlar gelen çaÄŸrılar\n" +"..16: yordam çaÄŸrıları\n" +"..32: LSN deÄŸiÅŸiklikleri\n" +" 64: Çalma denetimi\n" +".128: CDIO'dan hata ayıklama\n" +".256: Bölgeyi ayarlama için yapılan arama\n" +" 512: Åžu anki bölgesi bulmak için yapılan arama\n" +"1024: DonmuÅŸ kare\n" +"2048: VCDINFO'dan hata ayıklama\n" + +#: src/liba52/xine_a52_decoder.c:757 src/libdts/xine_dts_decoder.c:548 +msgid "HELP! a mono-only audio driver?!\n" +msgstr "YARDIM! sadece mono olan bir ses sürücüsü mü?!\n" + +#: src/liba52/xine_a52_decoder.c:820 +msgid "A/52 volume" +msgstr "A/52 sesi" + +#: src/liba52/xine_a52_decoder.c:821 +msgid "" +"With A/52 audio, you can modify the volume at the decoder level. This has " +"the advantage of the audio being already decoded for the specified volume, " +"so later operations like channel downmixing will work on an audio stream of " +"the given volume." +msgstr "A/52 ses ile, sesi kodlama seviyesinde deÄŸiÅŸtirebilirsiniz. Bu özel bir ses ÅŸiddeti için ayarlanmış olan ses kaynakları açısından bir avantajdır, böylece daha sonra yapacağınız kanalın ses yayın akışlarının ses dengelerinin ayarlanması sırasında bu iÅŸinize yarayacaktır." + +#: src/liba52/xine_a52_decoder.c:829 +msgid "use A/52 dynamic range compression" +msgstr "dinamik alan sıkıştırılması için A/52 kullan" + +#: src/liba52/xine_a52_decoder.c:830 +msgid "" +"Dynamic range compression limits the dynamic range of the audio. This means " +"making the loud sounds softer, and the soft sounds louder, so you can more " +"easily listen to the audio in a noisy environment without disturbing anyone." +msgstr "Dinamik alan sıkıştırma sesin dinamik boyunu sınırlar. Bu yüksek seslerin yumuÅŸak ve yumuÅŸak seslerin yüksek olması demektir ki, bu sayede müziÄŸi kimseyi rahatsız etmeden gürültülü bir ortamda rahatlıkla dinleyebilirsiniz." + +#: src/liba52/xine_a52_decoder.c:837 +msgid "downmix audio to 2 channel surround stereo" +msgstr "sesi 2 kanal surround stereo'ya indirge" + +#: src/liba52/xine_a52_decoder.c:838 +msgid "" +"When you want to listen to multichannel surround sound, but you have only " +"two speakers or a surround decoder or amplifier which does some sort of " +"matrix surround decoding like prologic, you should enable this option so " +"that the additional channels are mixed into the stereo signal." +msgstr "Çokkanallı surround bir ses dinlemek isteyip de, sadece iki hoparlörünüz veya surround kod çözücünüz veya prologic gibi bir matrix surround kod çözümleme imkanınız varsa, bu ek kanalların stereo sinyale çevrilebilmesi için bu seçeneÄŸi etkin hale getirmelisiniz" + +#: src/libfaad/xine_faad_decoder.c:128 +msgid "libfaad: libfaad NeAACDecOpen() failed.\n" +msgstr "libfaad: libfaad NeAACDecOpen() baÅŸarılamadı.\n" + +#: src/libfaad/xine_faad_decoder.c:137 +msgid "libfaad: libfaad NeAACDecInit2 failed.\n" +msgstr "libfaad: libfaad NeAACDecInit2 baÅŸarılamadı.\n" + +#: src/libfaad/xine_faad_decoder.c:148 +msgid "libfaad: libfaad NeAACDecInit failed.\n" +msgstr "libfaad: libfaad NeAACDecInit baÅŸarılamadı.\n" + +#: src/libffmpeg/ff_audio_decoder.c:117 +#, c-format +msgid "ffmpeg_audio_dec: increasing buffer to %d to avoid overflow.\n" +msgstr "ffmpeg_audio_dec: tampon belleÄŸi %d seviyesine taÅŸmayı önlemek için arttırıyor.\n" + +#: src/libffmpeg/ff_audio_decoder.c:161 +#, c-format +msgid "ffmpeg_audio_dec: couldn't find ffmpeg decoder for buf type 0x%X\n" +msgstr "ffmpeg_audio_dec: 0x%X türü dışında ffmpeg kod çözücü bulamıyor\n" + +#: src/libffmpeg/ff_audio_decoder.c:253 +msgid "ffmpeg_audio_dec: trying to open null codec\n" +msgstr "ffmpeg_audio_dec: boÅŸ kodu açmaya çalışıyor\n" + +#: src/libffmpeg/ff_audio_decoder.c:262 +msgid "ffmpeg_audio_dec: couldn't open decoder\n" +msgstr "ffmpeg_audio_dec: kod çözücüyü açamıyor\n" + +#: src/libffmpeg/ff_dvaudio_decoder.c:283 +#, c-format +msgid "dvaudio: increasing buffer to %d to avoid overflow.\n" +msgstr "dvaudio: taÅŸmayı önlemek için tampon belleÄŸi %d seviyesine çıkartıyor.\n" + +#: src/libffmpeg/ff_video_decoder.c:156 +msgid "ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n" +msgstr "ffmpeg_video_dec: desteklenmeyen çerçeve kipi, DR1 devre dışı.\n" + +#: src/libffmpeg/ff_video_decoder.c:174 +msgid "ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n" +msgstr "ffmpeg_video_dec: desteklenmeyen çerçeve boyutları, DR1 devre dışı.\n" + +#: src/libffmpeg/ff_video_decoder.c:338 +#, c-format +msgid "ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n" +msgstr "ffmpeg_video_dec: 0x%Xtürü için ffmpeg kod çözücüyü bulamıyor\n" + +#: src/libffmpeg/ff_video_decoder.c:367 +msgid "ffmpeg_video_dec: couldn't open decoder\n" +msgstr "ffmpeg_video_dec: kod çözücüyü açamıyor\n" + +#: src/libffmpeg/ff_video_decoder.c:408 +msgid "ffmpeg_video_dec: direct rendering enabled\n" +msgstr "ffmpeg_video_dec: doÄŸrudan iÅŸleme etkin\n" + +#: src/libffmpeg/ff_video_decoder.c:836 +#, c-format +msgid "ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n" +msgstr "ffmpeg_video_dec: taÅŸmayı önlemek için tampon belleÄŸi %d seviyesine yükseltiyor.\n" + +#: src/libffmpeg/ff_video_decoder.c:1562 +msgid "MPEG-4 postprocessing quality" +msgstr "MPEG 4 iÅŸleme kalitesi" + +#: src/libffmpeg/ff_video_decoder.c:1563 +msgid "" +"You can adjust the amount of post processing applied to MPEG-4 video.\n" +"Higher values result in better quality, but need more CPU. Lower values may " +"result in image defects like block artifacts. For high quality content, too " +"heavy post processing can actually make the image worse by blurring it too " +"much." +msgstr "" +"MPEG 4 görüntüye uygulanan iÅŸlemenin oranını ayarlayabilirsiniz.\n" +"Yüksek deÄŸerler daha iyi sonuç verir, fakat daha çok iÅŸlemci gücü gerektirir. Düşük deÄŸerler görüntü bozulmalarınına sebebiyet verir. Yüksek kalite içeriÄŸi için, ağır iÅŸleme iÅŸlemleri doÄŸal olarak onun netliÄŸinin bozulmasına neden olabilir ve görüntünün kötüleÅŸmesi sonucunu doÄŸurabilir." + +#: src/libffmpeg/ff_video_decoder.c:1571 +msgid "FFmpeg video decoding thread count" +msgstr "FFmpeg görüntü kodlaması iÅŸ sayısı" + +#: src/libffmpeg/ff_video_decoder.c:1572 +msgid "" +"You can adjust the number of video decoding threads which FFmpeg may use.\n" +"Higher values should speed up decoding but it depends on the codec used " +"whether parallel decoding is supported. A rule of thumb is to have one " +"decoding thread per logical CPU (typically 1 to 4). A change will take " +"effect with playing the next stream." +msgstr "" +"FFmpeg'nin kullanabileceÄŸi görüntü kodlama iÅŸlerinin sayılarını ayarlayabilirsiniz.\n" +"Yüksek deÄŸerler kodlama iÅŸleminin hızını yükseltir fakat bu kodlamada paralel kodlamanın yapılıp yapılmadığıyla da baÄŸlantılıdır. Mimari kuralına göre mantıksal iÅŸlemci başına bir adet kodlama iÅŸlemi yapılmalıdır (tipik olarak 1den14'e kadar). Bu deÄŸiÅŸim sonraki yayın akışında etkili olacaktır." + +#: src/libffmpeg/ffmpeg_encoder.c:165 +msgid "libavcodec mpeg output bitrate (kbit/s)" +msgstr "libavcodec mpeg çıkış bit oranı (kbit/s)" + +#: src/libffmpeg/ffmpeg_encoder.c:166 +msgid "" +"The bitrate the libavcodec mpeg encoder should use for DXR3's encoding mode. " +"Higher values will increase quality and CPU usage.\n" +"This setting is only considered, when constant quality mode is disabled." +msgstr "" +"libavcodec mpeg çıkış bit oranı, DXR3 kodlama kipini kullanmalıdır. Yüksek deÄŸerler kaliteyi ve iÅŸlemci kullanımını yükseltir.\n" +"Bu ayar sadece sabit kalite kipi devre dışı ise etkilidir." + +#: src/libffmpeg/ffmpeg_encoder.c:173 +msgid "constant quality mode" +msgstr "sabit kalite kipi" + +#: src/libffmpeg/ffmpeg_encoder.c:174 +msgid "" +"When enabled, libavcodec will use a constant quality mode by dynamically " +"compressing the images based on their complexity. When disabled, libavcodec " +"will use constant bitrate mode." +msgstr "EtkinleÅŸtirildiÄŸinde libavcodec, görüntünün karmaşık yapısına göre dinamik olarak sıkıştırılmış sabit kalite kipini kullanacaktır " + +#: src/libffmpeg/ffmpeg_encoder.c:181 +msgid "minimum compression" +msgstr "en düşük sıkıştırma" + +#: src/libffmpeg/ffmpeg_encoder.c:182 +msgid "The minimum compression to apply to an image in constant quality mode." +msgstr "Sabit kalite kipindeki bir resme uygulanacak ola en düşük sıkıştırma." + +#: src/libffmpeg/ffmpeg_encoder.c:187 +msgid "maximum quantizer" +msgstr "en yüksek nicelikler" + +#: src/libffmpeg/ffmpeg_encoder.c:188 +msgid "The maximum compression to apply to an image in constant quality mode." +msgstr "Sabit kalite kipindeki bir resme uygulanacak ola en yüksek sıkıştırma." + +#: src/libmusepack/xine_musepack_decoder.c:239 +#, c-format +msgid "libmusepack: mpc_streaminfo_read failed: %d\n" +msgstr "libmusepack: mpc_streaminfo_read baÅŸarılamadı: %d\n" + +#: src/libmusepack/xine_musepack_decoder.c:313 +msgid "libmusepack: data after last frame ignored\n" +msgstr "libmusepack: son çerçeveden sonraki veri görmezden gelindi\n" + +#: src/libmusepack/xine_musepack_decoder.c:324 +msgid "libmusepack: mpc_decoder_initialise failed\n" +msgstr "libmusepack: mpc_decoder_initialise baÅŸarılamadı\n" + +#: src/libmusepack/xine_musepack_decoder.c:344 +#: src/libmusepack/xine_musepack_decoder.c:359 +#, c-format +msgid "libmusepack: mpc_decoder_decode failed: %d\n" +msgstr "libmusepack: mpc_decoder_decode baÅŸarılamadı: %d\n" + +#: src/libreal/real_common.c:139 +msgid "path to RealPlayer codecs" +msgstr "RealPlayer kodları yolu" + +#: src/libreal/real_common.c:140 +msgid "" +"If you have RealPlayer installed, specify the path to its codec directory " +"here. You can easily find the codec directory by looking for a file named " +"\"drvc.so\" in it. If xine can find the RealPlayer codecs, it will use them " +"to decode RealPlayer content for you. Consult the xine FAQ for more " +"information on how to install the codecs." +msgstr "EÄŸer RealPlayer yüklüyse, buraya onun kod dizinini belirtiniz. Kod dizinini \"drvc.so\" dosyasını arayarak kolayca bulabilirisiniz. EÄŸer xine, RealPlayer kodlarını bulursa, onu RealPlayer kodlarını sizin için çözmek üzere kullanacaktır. Kodların yüklenmesi hakkında daha fazla bilgi için SSS baÅŸvrunuz." + +#: src/libreal/xine_real_video_decoder.c:162 +msgid "libreal: Error resolving symbols! (version incompatibility?)\n" +msgstr "libreal: Simgeleri çözmede hata! (sürüm uyumu?)\n" + +#: src/libreal/xine_real_audio_decoder.c:128 +#, c-format +msgid "libareal: (audio) Cannot resolve symbols - incompatible dll: %s\n" +msgstr "libareal: (ses) Simgeleri çözümleyemiyor - uyumsuz dll: %s\n" + +#: src/libreal/xine_real_audio_decoder.c:285 +#, c-format +msgid "libareal: decoder init failed, error code: 0x%x\n" +msgstr "libareal: kod çözücü init baÅŸarılamadı, hata kodu: 0x%x\n" + +#: src/libreal/xine_real_audio_decoder.c:299 +#, c-format +msgid "libareal: decoder flavor setup failed, error code: 0x%x\n" +msgstr "libareal: kod çözücü yapısal ayarı baÅŸarılamadı, hata kodu: 0x%x\n" + +#: src/libreal/xine_real_audio_decoder.c:336 +msgid "libareal: oups, real can do more than 2 channels ?\n" +msgstr "libareal: ops, real 2 kanaldan daha fazlasıyla baÅŸ edebilir ?\n" + +#: src/libspucc/xine_cc_decoder.c:189 +msgid "display closed captions in MPEG-2 streams" +msgstr "MPEG yayın akışlarında kapalı baÅŸlıkları görüntüle" + +#: src/libspucc/xine_cc_decoder.c:190 +msgid "Closed Captions are subtitles mostly meant to help the hearing impaired." +msgstr "Kapalı BaÅŸlıklar daha çok duyma özürlülere yardımcı olmayı amaçlayan altyazılardır." + +#: src/libspucc/xine_cc_decoder.c:197 +msgid "closed-captioning foreground/background scheme" +msgstr "kapalı baÅŸlık ön/arka ÅŸeması" + +#: src/libspucc/xine_cc_decoder.c:198 +msgid "Choose your favourite rendering of the closed captions." +msgstr "Sık kullandığınız kapalı baÅŸlık iÅŸlemini seçin." + +#: src/libspucc/xine_cc_decoder.c:204 +msgid "standard closed captioning font" +msgstr "standart kapalı baÅŸlık yazı tipi" + +#: src/libspucc/xine_cc_decoder.c:205 +msgid "Choose the font for standard closed captions text." +msgstr "Standart kapalı baÅŸlık metni için yazı tipini seçin." + +#: src/libspucc/xine_cc_decoder.c:211 +msgid "italic closed captioning font" +msgstr "italik kapalı baÅŸlık yazı tipi" + +#: src/libspucc/xine_cc_decoder.c:212 +msgid "Choose the font for italic closed captions text." +msgstr "İtalik kapalı baÅŸlık metni için yazı tipini seçin." + +#: src/libspucc/xine_cc_decoder.c:218 +msgid "closed captioning font size" +msgstr "Kapalı baÅŸlık yazı tipi boyutu" + +#: src/libspucc/xine_cc_decoder.c:219 +msgid "Choose the font size for closed captions text." +msgstr "Kapalı baÅŸlık metni için yazı tipini boyutunu seçin." + +#: src/libspucc/xine_cc_decoder.c:223 +msgid "center-adjust closed captions" +msgstr "Ortalanmış kapalı baÅŸlıklar" + +#: src/libspucc/xine_cc_decoder.c:224 +msgid "" +"When enabled, closed captions will be positioned by the center of the " +"individual lines." +msgstr "EtkinleÅŸtirildiÄŸinde, bireysel satırlar ortalanacaktır." + +#: src/libspucmml/xine_cmml_decoder.c:477 +msgid "font for external subtitles" +msgstr "dış altyazılar için yazı tipi" + +#: src/libspucmml/xine_cmml_decoder.c:483 +msgid "subtitle vertical offset (relative window size)" +msgstr "altyazı dikey konumu (pencere boyutuna göre deÄŸiÅŸir)" + +#: src/libspucmml/xine_cmml_decoder.c:529 +msgid "encoding of subtitles" +msgstr "altyazıların kodlanması" + +#: src/libsputext/demux_sputext.c:1504 +msgid "default duration of subtitle display in seconds" +msgstr "altyazı görünümünün saniye bazında ön tanımlı süresi" + +#: src/libsputext/demux_sputext.c:1505 +msgid "" +"Some subtitle formats do not explicitly give a duration for each subtitle. " +"For these, you can set a default duration here. Setting to zero will result " +"in the subtitle being shown until the next one takes over." +msgstr "Bazı altyazı kipleri her altyazı için kesin süre vermez. Bunun için, buradan kesin bir süre ayarlayabilirsiniz. Ayarı sıfır yapmak bir sonraki altyazı gelene kadar altyazının gösterilmesi sonucunu doÄŸurur." + +#: src/libsputext/xine_sputext_decoder.c:928 +msgid "subtitle size" +msgstr "altyazı büyüklüğü" + +#: src/libsputext/xine_sputext_decoder.c:929 +msgid "" +"You can adjust the subtitle size here. The setting will be evaluated " +"relative to the window size." +msgstr "Altyazı büyüklüğünü buradan ayarlayabilirsiniz. Bu ayar pencere boyutunuza göre yeniden deÄŸerlendirilecektir." + +#: src/libsputext/xine_sputext_decoder.c:935 +msgid "subtitle vertical offset" +msgstr "altyazı dikey konumu" + +#: src/libsputext/xine_sputext_decoder.c:936 +msgid "" +"You can adjust the vertical position of the subtitle. The setting will be " +"evaluated relative to the window size." +msgstr "Altyazı dikey konumunu buradan ayarlayabilirsiniz. Bu ayar pencere boyutunuza göre yeniden deÄŸerlendirilecektir." + +#: src/libsputext/xine_sputext_decoder.c:942 +#: src/libsputext/xine_sputext_decoder.c:951 +msgid "font for subtitles" +msgstr "altyazılar için yazı tipi" + +#: src/libsputext/xine_sputext_decoder.c:943 +msgid "A font from the xine font directory to be used for the subtitle text." +msgstr "Altyazı metni olarak xine yazı tipi dizininden bir yazı tipi kullanılacaktır." + +#: src/libsputext/xine_sputext_decoder.c:952 +msgid "An outline font file (e.g. a .ttf) to be used for the subtitle text." +msgstr "Altyazı metni olarak kullanılacak olan bir çerçeve yazı tipi dosyası (örn. bir .ttf)" + +#: src/libsputext/xine_sputext_decoder.c:958 +msgid "whether to use a freetype font" +msgstr "bir freetype yazı tipinin kullanılıp kullanılmayacağı" + +#: src/libsputext/xine_sputext_decoder.c:965 +msgid "encoding of the subtitles" +msgstr "alt yazılar kodlanıyor" + +#: src/libsputext/xine_sputext_decoder.c:966 +msgid "" +"The encoding of the subtitle text in the stream. This setting is used to " +"render non-ASCII characters correctly. If non-ASCII characters are not " +"displayed as you expect, ask the creator of the subtitles what encoding was " +"used." +msgstr "Yayın akışındaki altyazı metninin kod çözümü. Bu ayar, ASCII-dışı karakterlerin doÄŸru görüntülenmesi için kullanılır. EÄŸer ASCII-dışı karakterler beklediÄŸiniz gibi görüntülenmezse, bunu oluÅŸturan kiÅŸiye altyazılarda kullanılan kodlamanın ne olduÄŸunu sormalısınız." + +#: src/libsputext/xine_sputext_decoder.c:974 +msgid "use unscaled OSD if possible" +msgstr "eÄŸer mümkünse hesaplanmamış OSD kullanın" + +#: src/libsputext/xine_sputext_decoder.c:975 +msgid "" +"The unscaled OSD will be rendered independently of the video frame and will " +"always be sharp, even if the video is magnified. This will look better, but " +"does not work with all graphics hardware. The alternative is the scaled OSD, " +"which will become blurry, if you enlarge a low resolution video to " +"fullscreen, but it works with all graphics cards." +msgstr "Hesaplanmamış OSD görüntü çerçevesinden bağımsız olarak iÅŸlenecek ve görüntü büyütülmüş olsa bile daima keskin olacaktır. Bu daha iyi görünecek, fakat tüm grafik donanımla çalışamayabilecektir. Bunun çözümü ise hesaplanmış OSD'dir, fakat eÄŸer düşük çözünürlüğe sahip bir görüntüyü tam ekran yaparsanız bulanık gözükecektir, buna raÄŸmen tüm grafik kartlarla çalışır." + +#: src/libw32dll/common.c:17 +msgid "path to Win32 codecs" +msgstr "lWin32 kodlayıcılarının yolu" + +#: src/libw32dll/common.c:18 +msgid "" +"If you have the Windows or Apple Quicktime codec packs installed, specify " +"the path the codec directory here. If xine can find the Windows or Apple " +"Quicktime codecs, it will use them to decode various Windows Media and " +"Quicktime streams for you. Consult the xine FAQ for more information on how " +"to install the codecs." +msgstr "EÄŸer Windows veya Apple Quicktime kod paketleri kuruluysa, burada kod dizini yolunu belirtiniz. EÄŸer xine Windows veya Apple Quicktime kodlarını bulursa, bunu sizin için farklı Windows veya Apple Quicktime yayın akışlarının kodlarını çözümlemede kullanacaktır. Kodların kurulması konusundaki daha fazla bilgiye ulaÅŸmak için xine SSS'ye baÅŸvurun." + +#: src/libw32dll/w32codec.c:585 +#, c-format +msgid "w32codec: ICOpen failed! unknown codec %08lx / wrong parameters?\n" +msgstr "w32codec: ICOpen baÅŸarılamadı! bilinmeyen kod %08lx / parametreler yanlış?\n" + +#: src/libw32dll/w32codec.c:594 +#, c-format +msgid "w32codec: ICDecompressGetFormat (%.4s %08lx/%d) failed: Error %ld\n" +msgstr "w32codec: ICDecompressGetFormat (%.4s %08lx/%d) baÅŸarılamadı: Hata %ld\n" + +#: src/libw32dll/w32codec.c:627 +#, c-format +msgid "w32codec: ICDecompressQuery failed: Error %ld\n" +msgstr "w32codec: ICDecompressQuery baÅŸarılamadı: Hata %ld\n" + +#: src/libw32dll/w32codec.c:638 +#, c-format +msgid "w32codec: ICDecompressBegin failed: Error %ld\n" +msgstr "w32codec: ICDecompressBegin baÅŸarılamadı: Error %ld\n" + +#: src/libw32dll/w32codec.c:684 +#, c-format +msgid "w32codec: DS_VideoDecoder failed! unknown codec %08lx / wrong parameters?\n" +msgstr "w32codec: DS_VideoDecoder baÅŸarılamadı! bilinmeyen kod %08lx / parametreler yanlış?\n" + +#: src/libw32dll/w32codec.c:695 +#, c-format +msgid "w32codec: DMO_VideoDecoder failed! unknown codec %08lx / wrong parameters?\n" +msgstr "w32codec: DMO_VideoDecoder baÅŸarılamadı! bilinmeyen kod %08lx / parametreler yanlış?\n" + +#: src/libw32dll/w32codec.c:815 src/libw32dll/w32codec.c:1484 +#, c-format +msgid "w32codec: decoder failed to start. Is '%s' installed?\n" +msgstr "w32codec: kod çözümleyici baÅŸlayamadı. Yoksa '%s' kurulmadı mı?\n" + +#: src/libw32dll/w32codec.c:1218 +#, c-format +msgid "w32codec: (ACM_Decoder) Unappropriate audio format\n" +msgstr "w32codec: (ACM_Decoder) Uyumusuz ses kipi\n" + +#: src/libw32dll/w32codec.c:1221 +#, c-format +msgid "w32codec: (ACM_Decoder) acmStreamOpen error %d\n" +msgstr "w32codec: (ACM_Decoder) acmStreamOpen hatası %d\n" + +#: src/libw32dll/w32codec.c:1240 +#, c-format +msgid "w32codec: Error initializing DirectShow Audio\n" +msgstr "w32codec: DirectShow Audio sıfırlamada hata\n" + +#: src/libw32dll/w32codec.c:1258 +#, c-format +msgid "w32codec: Error initializing DMO Audio\n" +msgstr "w32codec: DMO Audio sıfırlamada hata\n" + +#: src/libxinevdec/bitplane.c:1270 +#, c-format +msgid "bitplane: error doing ByteRun1 decompression\n" +msgstr "bitplane: ByteRun1 sıkıştırmasında hata\n" + +#: src/libxinevdec/bitplane.c:1329 +#, c-format +msgid "bitplane: Anim Opt 1 is not supported at the moment\n" +msgstr "bitplane: Anim Opt 1 ÅŸu anda desteklenmiyor\n" + +#: src/libxinevdec/bitplane.c:1336 +#, c-format +msgid "bitplane: Anim Opt 2 is not supported at the moment\n" +msgstr "bitplane: Anim Opt 2 ÅŸu anda desteklenmiyor\n" + +#: src/libxinevdec/bitplane.c:1386 +#, c-format +msgid "bitplane: Anim ASCIIJ is not supported at the moment\n" +msgstr "bitplane: Anim ASCIIJ ÅŸu anda desteklenmiyor\n" + +#: src/libxinevdec/bitplane.c:1392 +#, c-format +msgid "bitplane: This anim-type is not supported at the moment\n" +msgstr "bitplane: Bu hareket türü ÅŸu anda desteklenmiyor\n" + +#: src/post/audio/stretch.c:263 +msgid "" +"This filter will perform a time stretch, playing the stream faster or slower " +"by a factor. Pitch is optionally preserved, so it is possible, for example, " +"to use it to watch a movie in less time than it was originaly shot.\n" +msgstr "Bu süzgeç bir etmenden dolayı yayın akışını daha hızlı veya daha yavaÅŸ oynatılmasına yol açan zaman uzamasına etki edecektir. Oran büyük olasılıkla korunacaktır, böylece bir filmi gerçek süresine göre daha az zamanda izlemek için kullanılabilir.\n" + +#: src/post/audio/upmix.c:134 +msgid "" +"Upmix functions. e.g. Take stereo input and produce Surround 5.1 output.\n" +"Parameters\n" +" cut_off_freq\n" +"\n" +"Note: It is possible to use frontend's control window to set these " +"parameters.\n" +"\n" +msgstr "" +"ÇoÄŸaltma fonksiyonları. örn. Stereo giriÅŸ alın ve Surround 5.1 çıkışa dönüştürün.\n" +"Parametreler\n" +" cut_off_freq\n" +"\n" +"Dikkat: Bu parametreleri öndeki denetim penceresinden ayarlamak mümkündür.\n" + +#: src/post/audio/upmix_mono.c:106 +msgid "" +"This filter will upmix a mono stream to stereo, by duplicating channels. " +"Alternatively, one may use this plugin to listen just one channel of a given " +"stream.\n" +msgstr "Bu süzgeç, mono akışı kanalları çiftleyerek stereo'ya dönüştürecektir. Alternatif olarak, bu eklenti sadece bir kanalın ya da verilen yayın akışının dinlenmesi için de kullanılabilir.\n" + +#: src/post/audio/upmix_mono.c:144 +msgid ": upmixing Mono to Stereo.\n" +msgstr ": Mono'dan Stereo'ya dönüştürme.\n" + +#: src/post/audio/upmix_mono.c:149 +#, c-format +msgid ": upmixing a single channel from original %d channel stream.\n" +msgid_plural ": upmixing a single channel from original %d channels stream.\n" +msgstr[0] ": tek kanalı özgün %d kanal yayın akışlarına dönüştürme.\n" +msgstr[1] "" + +#: src/post/audio/upmix_mono.c:154 +msgid ": audio device not capable of AO_CAP_MODE_STEREO.\n" +msgstr ": ses aygıtının AO_CAP_MODE_STEREO özelliÄŸi yok.\n" + +#: src/post/audio/volnorm.c:147 +msgid "" +"Normalizes audio by maximizing the volume without distorting the sound.\n" +"\n" +"Parameters:\n" +" method: 1: use a single sample to smooth the variations via the standard " +"weighted mean over past samples (default); 2: use several samples to smooth " +"the variations via the standard weighted mean over past samples.\n" +msgstr "" +"Sesin bozmadan sesi yükselterek ses kaynağını normalleÅŸtiriyor.\n" +"\n" +"Parametreler:\n" +" yöntem: 1: çeÅŸitlemeleri yumuÅŸatmak ya da eski ses örneklerini temel alarak tek bir örnek kullanınız (varsayılan); 2: çeÅŸitlemeleri yumuÅŸatmak " +"ya da eski ses örneklerini temel alarak farklı örnekler kullanınız.\n" + +#: src/post/deinterlace/xine_plugin.c:202 +msgid "" +"Advanced tvtime/deinterlacer plugin with pulldown detection\n" +"This plugin aims to provide deinterlacing mechanisms comparable to high " +"quality progressive DVD players and so called line-doublers, for use with " +"computer monitors, projectors and other progressive display devices.\n" +"\n" +"Parameters\n" +"\n" +" Method: Select deinterlacing method/algorithm to use, see below for " +"explanation of each method.\n" +"\n" +" Enabled: Enable/disable the plugin.\n" +"\n" +" Pulldown: Choose the 2-3 pulldown detection algorithm. 24 FPS films that " +"have being converted to NTSC can be detected and intelligently reconstructed " +"to their original (non-interlaced) frames.\n" +"\n" +" Framerate_mode: Selecting 'full' will deinterlace every field to an unique " +"frame for television quality and beyond. This feature will effetively double " +"the frame rate, improving smoothness. Note, however, that full 59.94 FPS is " +"not possible with plain 2.4 Linux kernel (that use a timer interrupt " +"frequency of 100Hz). Newer RedHat and 2.6 kernels use higher HZ settings " +"(512 and 1000, respectively) and should work fine.\n" +"\n" +" Judder_correction: Once 2-3 pulldown is enabled and a film material is " +"detected, it is possible to reduce the frame rate to original rate used (24 " +"FPS). This will make the frames evenly spaced in time, matching the speed " +"they were shot and eliminating the judder effect.\n" +"\n" +" Use_progressive_frame_flag: Well mastered MPEG2 streams uses a flag to " +"indicate progressive material. This setting control whether we trust this " +"flag or not (some rare and buggy mpeg2 streams set it wrong).\n" +"\n" +" Chroma_filter: DVD/MPEG2 use an interlaced image format that has a very " +"poor vertical chroma resolution. Upsampling the chroma for purposes of " +"deinterlacing may cause some artifacts to occur (eg. color stripes). Use " +"this option to blur the chroma vertically after deinterlacing to remove the " +"artifacts. Warning: cpu intensive.\n" +"\n" +" Cheap_mode: This will skip the expensive YV12->YUY2 image conversion, " +"tricking tvtime/dscaler routines like if they were still handling YUY2 " +"images. Of course, this is not correct, not all pixels will be evaluated by " +"the algorithms to decide the regions to deinterlace and chroma will be " +"processed separately. Nevertheless, it allows people with not so fast " +"systems to try deinterlace algorithms, in a tradeoff between quality and cpu " +"usage.\n" +"\n" +"* Uses several algorithms from tvtime and dscaler projects.\n" +"Deinterlacing methods: (Not all methods are available for all plataforms)\n" +"\n" +msgstr "" +"GeliÅŸmiÅŸ seçenek tanımalı tvtime/dönüştürücü eklentisi \n" +"Bu eklentinin amacı dönüştürme mekanizmasına yüksek kaliteli DVD çalarlarla yarışacak bir ortam saÄŸlamaktır ve buna bilgisayar ekranları, yansıtıcılar ve diÄŸer ileri seviyede görüntü cihazlarıyla kullanılması için çizgi çiftleyici denir.\n" +"\n" +"Parametreler\n" +"\n" +"Method: Kullanılacak dönüştürme yöntemini/algoritmasını seçer, her yöntemin açıklaması için aÅŸağıda bakınız.\n" +"\n" +"Etkin: Eklenti etkin/etkisiz\n" +"\n" +" Pulldown: 2-3 indirme tanıma algoritmasını seçin, 24 fps NTSC kipine dönüştürülmüşlerdir ve rahatlıkla algılanabilir ve eski hallerine döndürülebilirler (dönüştürülmemiÅŸ).\n" +"\n" +" Framerate_mode: Tam'ı seçmek her alanı televizyon ve ötesi kalitede bir noktaya dönüştürecektir. Bu özellik yumuÅŸaklığı arttırarak çerçeve oranını ikiye katlayacaktır. Yalnız, düz 2.4 Linux çekirdeÄŸi ile tam 59.94 FPS olanaklı deÄŸildir (zaman kesme oranı olarak 100Hz'i kullanan. Daha yeni Red Hat veya 2.6 çekirdekleri daha yüksek HZ ayarları kullanırlar (büyük olasılıkla 512 veya 1000) ve daha güzel çalışır.\n" +"\n" +" Judder_correction: Bir kez 2-3 indirme etkinleÅŸtirilirse ve film malzemesi tanınırsa çerçeve oranını kullanılan özgün orana (24 FPS) indirmek mümkün olabilir. Bu çerçevelerin düzgün görüntülenmesine ve titreme etkisini eleyerek hızının normalleÅŸmesine imkan tanıyacaktır.\n" +"\n" +" Use_progressive_frame_flag: İyi master edilmiÅŸ MPEG2 yayın akışları ilerleyen malzemeyi belirten bir bayrak kullanırlar. Bu ayar, bu bayraÄŸa güvenip güvenemeyeceÄŸimizi denetler (bazı ender ve böcekli! mpeg yayın akışlarında bu yanlış ayarlanmıştır).\n" +" Chroma-filter: DVD/MPEG2, çok zayıf bir kroma çözünürlüğe sahip dönüştürülmüş resim kipi kullanır. Dönüşüm amacıyla kromayı deÄŸiÅŸtirmek bazı hatalara sebep olabilir (renk karışımı gibi...). Bu seçeneÄŸi yapılanları silip dönüştürdükten sonra renk parlaklığını dikey olarak bulanıklaÅŸtırmak için kullanın. Uyarı: iÅŸlemci yoÄŸunluÄŸu\n" +"\n" +" Cheap-mode. " +"Bu geniÅŸ YV12->YUY2 görüntü çevrimini tvtime/dscaler yordamlarını sanki onlar hala YUY2 görüntüleriyle uÄŸraşıyormuÅŸ gibi kandırarak atlayacaktır, Tabii ki, bu doÄŸru deÄŸildir, saptanan algoritmalar tarafından dönüştürme ve renk parlaklığının ayrı ayrı iÅŸlem görüp görmeyeceÄŸine baÄŸlı olarak tüm pikseller deÄŸerlendirilmeyecektir. Ne yazık ki, sistemi yavaÅŸ olan makinalarda kalite ve iÅŸlemci rekabetine a göre algoritmaları dönüştürme iÅŸlemleri yapılmaya çalışılacaktır.\n" +"\n" +"* tvtime ve dscaler projeleri için farklı algoritmalar kullanır.\n" +"Dönüştürme yöntemleri: (Tüm yöntemler tüm platformlar için geçerli olmayabilir)\n" +"\n" + +#: src/post/deinterlace/xine_plugin.c:323 +msgid "tvtime: No deinterlacing methods available, exiting.\n" +msgstr "" +"tvtime: Hiç bir dönüştürme yöntemi uygun deÄŸil. Kapatılıyor. " +"\n" + +#: src/post/goom/xine_goom.c:206 +msgid "frames per second to generate" +msgstr "oluÅŸturulmak üzere saniye başına kareler" + +#: src/post/goom/xine_goom.c:207 +msgid "" +"With more frames per second, the animation will get smoother and faster, but " +"will also require more CPU power." +msgstr "Saniye başına daha çok kareler için, hareket daha yumuÅŸayacak ve hızlanacak, fakat aynı zamanda daha çok iÅŸlemci gücü gerektirecek." + +#: src/post/goom/xine_goom.c:212 +msgid "goom image width" +msgstr "goom resim geniÅŸliÄŸi" + +#: src/post/goom/xine_goom.c:213 +msgid "The width in pixels of the image to be generated." +msgstr "İşlenecek olan resmin piksel olarak geniÅŸliÄŸi." + +#: src/post/goom/xine_goom.c:217 +msgid "goom image height" +msgstr "goom resim yüksekliÄŸi" + +#: src/post/goom/xine_goom.c:218 +msgid "The height in pixels of the image to be generated." +msgstr "İşlenecek olan resmin piksel olarak yüksekliÄŸi." + +#: src/post/goom/xine_goom.c:224 +msgid "colorspace conversion method" +msgstr "renk dizgesi dönüştürme yöntemi " + +#: src/post/goom/xine_goom.c:225 +msgid "" +"You can choose the colorspace conversion method used by goom.\n" +"The available selections should be self-explaining." +msgstr "" +"Goom tarafından kullanılan renk dizgesi dönüştürme yöntemini seçebilirsiniz.\n" +"Uygun seçimler açıklamalılar olabilir. " + +#: src/post/mosaico/mosaico.c:271 +msgid "" +"Mosaico does simple picture in picture effects.\n" +"\n" +"Parameters\n" +" pip_num: the number of the picture slot the following settings apply to\n" +" x: the x coordinate of the left upper corner of the picture\n" +" y: the y coordinate of the left upper corner of the picture\n" +" w: the width of the picture\n" +" h: the height of the picture\n" +msgstr "" +"Mosaico resim içinde resim efektidir.\n" +"\n" +"Parametreler\n" +" pip_num: gelen ayarların uygulanacağı resimlerin aralığı\n" +" x: x, resmin sol üst köşesine giden baÄŸlantıdır\n" +" y: y resmin sol üst köşesine giden baÄŸlantıdır\n" +" w: w resmin geniÅŸliÄŸidir\n" +" h: h resmin yüksekliÄŸidir\n" + +#: src/post/mosaico/switch.c:228 +msgid "" +"Switch can be used for fast switching between multiple inputs.\n" +"\n" +"Parameters\n" +" select: the number of the input which will be passed to the output\n" +msgstr "" +"Düğme, çoklu giriÅŸler arasında hızlı geçiÅŸ yapmak için kullanılabilir.\n" +"\n" +"Parametreler\n" +" seç: çıkışa gönderilecek olan giriÅŸin sayısı\n" + +#: src/post/planar/boxblur.c:101 +msgid "" +"Box blur does a simple blurring of the image.\n" +"\n" +"Parameters\n" +" Radius: size of the filter\n" +" Power: how often the filter should be applied\n" +"\n" +"* mplayer's boxblur (C) 2002 Michael Niedermayer\n" +msgstr "" +"Kutu lekesi resmi basit olarak bulanıklaÅŸtırır.\n" +"\n" +"Parametreler\n" +" Radius: süzgeçlerin sayısı\n" +" Power: süzgeçin ne kadar sıklıkla uygulanacağı ile ilgilidir\n" +"\n" +"* mplayer's boxblur (C) 2002 Michael Niedermayer\n" + +#: src/post/planar/denoise3d.c:134 +msgid "" +"This filter aims to reduce image noise producing smooth images and making " +"still images really still (This should enhance compressibility.). It can be " +"given from 0 to 3 parameters. If you omit a parameter, a reasonable value " +"will be inferred.\n" +"\n" +"Parameters\n" +" Luma: Spatial luma strength (default = 4)\n" +" Chroma: Spatial chroma strength (default = 3)\n" +" Time: Temporal strength (default = 6)\n" +"\n" +"* mplayer's denoise3d (C) 2003 Daniel Moreno\n" +msgstr "" +"Bu süzgeç, düz ve donmuÅŸ resimler üreten resim gürültüsünü azaltmayı amaçlar (Bu sıkıştırmayı azaltır). 0 ile 3 parametleri verilmiÅŸ olabilir. EÄŸer bir parametreyi atlarsanız, önemli bir deÄŸer kaybolmuÅŸ olur.\n" +"\n" +"Parametreler\n" +" Luma: Uzamsal luma kuvveti (öntanımlı = 4)\n" +" Chroma: Uzamsal renk berraklığı kuvveti (öntanımlı = 3)\n" +" Time: Maddesel kuvvet (öntanımlı = 6)\n" +"\n" +"* mplayer's denoise3d (C) 2003 Daniel Moreno\n" + +#: src/post/planar/eq.c:184 +msgid "" +"Software equalizer with interactive controls just like the hardware " +"equalizer, for cards/drivers that do not support brightness and contrast " +"controls in hardware.\n" +"\n" +"Parameters\n" +" brightness\n" +" contrast\n" +"\n" +"Note: It is possible to use frontend's control window to set these " +"parameters.\n" +"\n" +"* mplayer's eq (C) Richard Felker\n" +msgstr "" +"Aynen donanım eÅŸitleyicisi gibi olan etkileÅŸimli denetimlere sahip yazılım eÅŸitleyicisi, bu, kartlar/sürücüler için donanımdaki parlaklık ve zıtlığı desteklemez.\n" +"\n" +"Parametreler\n" +" parlaklık\n" +" zıtlık\n" +"\n" +"Dikkat: Bu parametreleri kullanmak için ön pencere denetimleri kullanabilir.\n" +"\n" +"* mplayer's eq (C) Richard Felker\n" + +#: src/post/planar/eq2.c:357 +msgid "" +"Alternative software equalizer that uses lookup tables (very slow), allowing " +"gamma correction in addition to simple brightness, contrast and saturation " +"adjustment.\n" +"Note that it uses the same MMX optimized code as 'eq' if all gamma values " +"are 1.0.\n" +"\n" +"Parameters\n" +" gamma\n" +" brightness\n" +" contrast\n" +" saturation\n" +" rgamma (gamma for the red component)\n" +" ggamma (gamma for the green component)\n" +" bgamma (gamma for the blue component)\n" +"\n" +"Value ranges are 0.1 - 10 for gammas, -2 - 2 for contrast (negative values " +"result in a negative image), -1 - 1 for brightness and 0 - 3 for " +"saturation.\n" +"\n" +"* mplayer's eq2 (C) Hampa Hug, Daniel Moreno, Richard Felker\n" +msgstr "" +"Tabloları kullanan (çok yavaÅŸ) alternatif yazılım eÅŸitleyicisi, gamma düzeltmesine ve ek olarak basit parlaklık, zıtlık ve doyum ayarlarına izin veriyor.\n" +"EÄŸer gamma deÄŸerleri 1.0 ise Eq olarak aynı MMX iyileÅŸtirilmiÅŸ kodun kullanıldığına dikkat ediniz.\n" +"\n" +"Parametreler\n" +" gamma\n" +" parlaklık\n" +" zıtlık\n" +" doyum\n" +" rgamma (kırmızı bileÅŸen için gamma)\n" +" ggamma (yeÅŸil bileÅŸen için gamma)\n" +" bgamma (mavi bileÅŸen için gamma)\n" +"\n" +"Gammalar için deÄŸerler 0.1 - 10 arasındadır, -2 - 2 zıtlık için (negative deÄŸerler negatif resim sonucu doÄŸururlar), -1 - 1 parlaklık için ve 0 - 3 doyum için.\n" +"\n" +"* mplayer's eq2 (C) Hampa Hug, Daniel Moreno, Richard Felker\n" + +#: src/post/planar/expand.c:251 +msgid "" +"The expand plugin is meant to take frames of arbitrary aspect ratio and " +"converts them to a different aspect (4:3 by default) by adding black bars on " +"the top and bottom of the frame. This allows us to shift overlays down into " +"the black area so they don't cover the image.\n" +"\n" +"Parameters (FIXME: better help)\n" +" Enable_automatic_shift: Enable automatic overlay shifting\n" +" Overlay_y_offset: Manually shift the overlay vertically\n" +" aspect: The target aspect ratio (default 4:3)\n" +" Centre_cut_out_mode: extracts 4:3 image contained in 16:9 frame\n" +"\n" +msgstr "" +"Eklenti büyümesi, keyfi durum oranının karelerini almak ve onları çerçevenin üst ve altlarına siyah çizgiler ekleyerek farklı görünüme çevirmek (4:3 öntanımlı'dır) anlamına gelmektedir. Bu bize katmanları siyaha alana döndürme olanağı tanır böylece onlar resmi kaplamazlar.\n" +"\n" +"Parametreler (FIXME: daha çok yardım)\n" +" " +"Enable_automatic_shift: Katman deÄŸiÅŸimini otomatik olarak etkinleÅŸtirir\n" +" Overlay_y_offset: Elle tabakayı dikey olarak deÄŸiÅŸtirir\n" +" aspect: The hedef görünüm oranı (öntanımlı 4:3)\n" +" Centre_cut_out_mode: 16:9 çerçevesindekileri 4:3 oranına çıkarır\n" +"\n" + +#: src/post/planar/noise.c:400 +msgid "" +"Adds random noise to the video.\n" +"\n" +"Parameters:\n" +" luma_strength: strength of noise added to luma channel (0-100, default: " +"8)\n" +" chroma_strength: strength of noise added to chroma channel (0-100, " +"default: 5)\n" +" quality: quality level of the noise. fixed: constant noise pattern; " +"temporal: noise pattern changes between frames; averaged temporal: smoother " +"noise pattern that changes between frames. (default: averaged temporal)\n" +" type: Type of noise: uniform or gaussian. (default: gaussian)\n" +" pattern: Mix random noise with a (semi)regular pattern. (default: False)\n" +"\n" +"* mplayer's noise (C) Michael Niedermayer\n" +msgstr "" +"Görüntüye rastgele gürültü ekler.\n" +"\n" +"Parametreler:\n" +" luma_strength: luma kanalına eklenen gürültünün gücü (0-100, öntanımlı: " +"8)\n" +" chroma_strength: chroma kanalına eklenen gürültünün gücü (0-100, " +"öntanımlı: 5)\n" +" quality: gürültünün kalite seviyesi. düzeltilmiÅŸ: sürekli gürültü modeli; " +"temporal: gürültü modeli kareler arasında deÄŸiÅŸir; ortalama zaman: kareler arasında deÄŸiÅŸen daha düz gürültü modeli. (öntanımlı: ortalama zaman)\n" +" type: Gürltü türü: birörnek veya veya gaussian. (öntanımlı: gaussian)\n" +" pattern: Rastgele gürültünün bir (yarı) düzenli model ile karışımı. (öntanımlı: False)\n" +"\n" +"* mplayer's noise (C) Michael Niedermayer\n" + +#: src/post/planar/pp.c:106 +msgid "" +"FFmpeg libpostprocess plugin.\n" +"\n" +"Parameters\n" +"\n" +msgstr "" +"FFmpeg libpostprocess eklentisi.\n" +"\n" +"Parametreler\n" +"\n" + +#: src/post/planar/pp.c:112 +msgid "" +"\n" +"* libpostprocess (C) Michael Niedermayer\n" +msgstr "" +"\n" +"* libpostprocess (C) Michael Niedermayer\n" + +#: src/post/planar/unsharp.c:218 +msgid "" +"Unsharp mask / gaussian blur\n" +"It is possible to set the width and height of the matrix, odd sized in both " +"directions (min = 3x3, max = 13x11 or 11x13, usually something between 3x3 " +"and 7x7) and the relative amount of sharpness/blur to add to the image (a " +"sane range should be -1.5 - 1.5).\n" +"\n" +"Parameters\n" +"\n" +" Luma_matrix_width: Width of the matrix (must be odd)\n" +"\n" +" Luma_matrix_height: Height of the matrix (must be odd)\n" +"\n" +" Luma_amount: Relative amount of sharpness/blur (=0 disable, <0 blur, >0 " +"sharpen)\n" +"\n" +" Chroma_matrix_width: Width of the matrix (must be odd)\n" +"\n" +" Chroma_matrix_height: Height of the matrix (must be odd)\n" +"\n" +" Chroma_amount: Relative amount of sharpness/blur (=0 disable, <0 blur, >0 " +"sharpen)\n" +"\n" +"\n" +"* mplayer's unsharp (C) 2002 Remi Guyomarch\n" +msgstr "" +"YumuÅŸak maske / gaussian blur\n" +"Dizey'in geniÅŸlik ve yüksekliÄŸini ayarlamak mümkündür, tek sayılı ayarlar her iki yönde de ayarlanmıştır (min = 3x3, max = 13x11 or 11x13, genellikle 3x3 ve 7x7 arasında bir ÅŸey olabilir.) ve keskinlik/bulanıklığın resme eklenecek olan ilgili büyüklüğü de ayarlanmıştır (makul bir oran -1.5 - 1.5 olabilir).\n" +"\n" +"Parametreler\n" +"\n" +" Luma_matrix_width: Dizey'in geniÅŸliÄŸi (tek sayı olmalı)\n" +"\n" +" Luma_matrix_height: Dizey'in yüksekliÄŸi (tek sayı olmalı)\n" +"\n" +" Luma_amount: Keskinlik/bulanıklığın iliÅŸkili oranı (=0 devre dışı bırak, <0 bulanıklaÅŸtır, >0 " +"keskinleÅŸtir)\n" +"\n" +" Chroma_matrix_width: Dizey'in geniÅŸliÄŸi (tek sayı olmalı)\n" +"\n" +" Chroma_matrix_height: Dizey'in yüksekliÄŸi (tek sayı olmalı)\n" +"\n" +" Chroma_amount: Keskinlik/bulanıklığın iliÅŸkili oranı (=0 devre dışı bırak, <0 bulanıklaÅŸtır, >0 " +"keskinleÅŸtir)\n" +"\n" +"\n" +"* mplayer's unsharp (C) 2002 Remi Guyomarch\n" + +#: src/video_out/video_out_aa.c:308 +msgid "xine video output plugin using the ascii-art library" +msgstr "ascii-art kütüphanesinin kullanan xine görüntü çıkış eklentisi" + +#: src/video_out/video_out_caca.c:315 +msgid "xine video output plugin using the Color AsCii Art library" +msgstr "Color AsCii Art kütüphanesinin kullanan xine görüntü çıkış eklentisi" + +#: src/video_out/video_out_directfb.c:1341 +msgid "video layer buffering mode" +msgstr "görüntü katmanı tamponlama kipi" + +#: src/video_out/video_out_directfb.c:1342 +msgid "" +"Select the buffering mode of the output layer. Double or triple buffering " +"give a smoother playback, but consume more video memory." +msgstr "Çıkış katmanının tamponlama kipini seçin. İkili veya üçlü tamponlama, daha yumuÅŸak bir çalma sonucu doÄŸurur, fakat daha çok görüntü belleÄŸi tüketir." + +#: src/video_out/video_out_directfb.c:1349 +msgid "wait for vertical retrace" +msgstr "dikey takip için bekleyiniz" + +#: src/video_out/video_out_directfb.c:1350 +msgid "" +"Enable synchronizing the update of the video image to the repainting of the " +"entire screen (\"vertical retrace\")." +msgstr "Tüm ekranın yeniden oluÅŸturulması amacıyla video görüntüsünün güncellenmesi için senkronizasyonu etkinleÅŸtiriniz. (\"dikey takip\")." + +#: src/video_out/video_out_directfb.c:1357 +msgid "enable video color key" +msgstr "görüntü renk anahtarını etkinleÅŸtirin" + +#: src/video_out/video_out_directfb.c:1358 +msgid "" +"Enable using a color key to tell the graphics card where to overlay the " +"video image." +msgstr "Görüntü renk anahtarını etkinleÅŸtirme kullanımı, video görüntüsünün nerede ekranı kaplayacağını ekran kartına bildirir." + +#: src/video_out/video_out_directfb.c:1364 +msgid "video color key" +msgstr "görüntü renk anahtarı" + +#: src/video_out/video_out_directfb.c:1365 +msgid "" +"The color key is used to tell the graphics card where to overlay the video " +"image. Try different values, if you experience windows becoming transparent." +msgstr "Renk anahtarı, video görüntüsünün nerede ekranı kaplayacağını ekran kartına bildirmek için kullanılır. EÄŸer pencereleriniz ÅŸeffaf hale geliyorsa deÄŸiÅŸik deÄŸerler deneyin." + +#: src/video_out/video_out_directfb.c:1374 +msgid "flicker filtering" +msgstr "titreme filtreleme" + +#: src/video_out/video_out_directfb.c:1375 +msgid "Enable Flicker Filetring for a smooth output on an interlaced display." +msgstr "Titreme Filtreleme, karmaşık görünümün daha düz bir çıkış haline dönüşmesine olanak tanır." + +#: src/video_out/video_out_directfb.c:1382 +msgid "field parity" +msgstr "alan eÅŸliÄŸi" + +#: src/video_out/video_out_directfb.c:1383 +msgid "" +"For an interlaced display, enable controlling the field parity (\"none" +"\"=disabled)." +msgstr "" +"Görüntü karmaÅŸası için, alan eÅŸliÄŸi denetimini etkinleÅŸtirin (\"hiçbiri" +"\"=devre dışı)." + +#: src/video_out/video_out_directfb.c:1516 +msgid "video_out_directfb: using hardware subpicture acceleration.\n" +msgstr "video_out_directfb: donanım altresim hızlandırmasını kullanıyor.\n" + +#: src/video_out/video_out_directfb.c:1530 +msgid "video_out_directfb: layer supports video output.\n" +msgstr "video_out_directfb: katman görüntü çıktısını destekler.\n" + +#: src/video_out/video_out_directfb.c:1539 +msgid "video_out_directfb: layer doesn't support YV12!\n" +msgstr "video_out_directfb: katman YV12 desteÄŸi vermez!\n" + +#: src/video_out/video_out_directfb.c:1546 +msgid "video_out_directfb: layer doesn't support YUY2!\n" +msgstr "video_out_directfb: katman YUY2 desteÄŸi vermez!\n" + +#: src/video_out/video_out_directfb.c:1557 +msgid "video_out_directfb:need at least DirectFB 0.9.25 to play on this layer!\n" +msgstr "video_out_directfb:bu katmanda çalmak için en az DirectFB 0.9.25 desteÄŸi gereklidir!\n" + +#: src/video_out/video_out_directfb.c:1592 +#, c-format +msgid "video_out_directfb: layer doesn't support buffermode %d!\n" +msgstr "video_out_directfb: katman tampon bellek kipini %d desteklemez !\n" + +#: src/video_out/video_out_directfb.c:1598 +#, c-format +msgid "video_out_directfb: layer doesn't support options 0x%08x!\n" +msgstr "video_out_directfb: katmanın desteklemediÄŸi seçenekler 0x%08x!\n" + +#: src/video_out/video_out_directfb.c:1692 +msgid "video_out_directfb: using hardware accelerated image scaling.\n" +msgstr "video_out_directfb: donanım tarafından hızlandırılan resim ölçeklemesini kullanıyor.\n" + +#: src/video_out/video_out_directfb.c:1704 +msgid "" +"video_out_directfb: image scaling with deinterlacing is hardware " +"accelerated.\n" +msgstr "video_out_directfb: dönüştürme destekli resim ölçekleme donanım hızlandırmalıdır.\n" + +#: src/video_out/video_out_directfb.c:1782 +msgid "video layer id (auto: -1)" +msgstr "görüntü katman kimliÄŸi (otomatik: -1)" + +#: src/video_out/video_out_directfb.c:1783 +msgid "Select the video output layer by its id." +msgstr "Görüntü çıkış katmanını kendi kimliÄŸiyle birlikte seçiniz." + +#: src/video_out/video_out_directfb.c:1804 +#: src/video_out/video_out_directfb.c:2014 +#, c-format +msgid "video_out_directfb: using display layer #%d.\n" +msgstr "video_out_directfb: kullanılan görüntü katmanı #%d.\n" + +#: src/video_out/video_out_directfb.c:1888 +msgid "xine video output plugin using DirectFB." +msgstr "xine görüntü çıkış eklentisi DirectFB kullanıyor." + +#: src/video_out/video_out_directfb.c:2007 +msgid "video_out_directfb: no usable display layer was found!\n" +msgstr "video_out_directfb: kullanılabilecek görüntü katmanı bulunamadı!\n" + +#: src/video_out/video_out_directfb.c:2096 +msgid "xine video output plugin using DirectFB under XDirectFB." +msgstr "xine video çıkış eklentisi XDirectFB altında yer alan DirectFB kullanıyor." + +#: src/video_out/video_out_directx.c:1236 +msgid "xine video output plugin for win32 using directx" +msgstr "directx kullanan win32 için xine video çıkış eklentisi" + +#: src/video_out/video_out_fb.c:758 +#, c-format +msgid "" +"video_out_fb: only packed truecolor/directcolor is supported (%d).\n" +" Check 'fbset -i' or try 'fbset -depth 16'.\n" +msgstr "" +"video_out_fb: sadece paketlenmiÅŸ truecolor/directcolor desteklenmektedir (%d).\n" +" Åžu komutu 'fbset -i' veya 'fbset -depth 16' seçeneÄŸini deneyin.\n" + +#: src/video_out/video_out_fb.c:818 src/video_out/video_out_vidix.c:1236 +msgid "framebuffer device name" +msgstr "çerçevearabellek aygıtı ismi" + +#: src/video_out/video_out_fb.c:819 src/video_out/video_out_vidix.c:1237 +msgid "" +"Specifies the file name for the framebuffer device to be used.\n" +"This setting is security critical, because when changed to a different file, " +"xine can be used to fill this file with arbitrary content. So you should be " +"careful that the value you enter really is a proper framebuffer device." +msgstr "" +"Kullanılacak olan çerçevearabellek aygıtı ismi için dosya adını belirler.\n" +"Bu ayarlar güvenlik açısından kritiktir, çünkü dosya deÄŸiÅŸtirildiÄŸinde, xine bu dosyayı ilgisiz içerikle doldurmak için kullanılabilir. Bu yüzden, bu yüzden girdiÄŸiniz deÄŸerin çerçevearabellek aygıtı için uygun olmasına özen göstermelisiniz." + +#: src/video_out/video_out_fb.c:893 +msgid "video_out_fb: Your video mode was not recognized, sorry.\n" +msgstr "video_out_fb: Video kipiniz tanınamadı, üzgünüm.\n" + +#: src/video_out/video_out_fb.c:950 +#, c-format +msgid "video_out_fb: %d video RAM buffers are available.\n" +msgstr "video_out_fb: %d video RAM ara belleÄŸi kullanılabilir.\n" + +#: src/video_out/video_out_fb.c:956 +#, c-format +msgid "" +"WARNING: video_out_fb: Zero copy buffers are DISABLED because only %d " +"buffers\n" +" are available which is less than the recommended %d buffers. Lowering\n" +" the frame buffer resolution might help.\n" +msgstr "" +"UYARI: video_out_fb: Tampon belleÄŸin sıfır kopyası DEVRE DIÅžI çünkü sadece %d ara belleÄŸe alır\n" +" önerilen %d tampon belleÄŸe göre daha düşük seviyededir. Düşürüyor\n" +" çerçeve tampon bellek çözünürlüğü yardımcı olabilir.\n" + +#: src/video_out/video_out_fb.c:967 +msgid "" +"WARNING: video_out_fb: Zero copy buffers are DISABLED because kernel driver\n" +" do not support screen panning (used for frame flips).\n" +msgstr "" +"UYARI: video_out_fb: Tampon belleÄŸin sıfır kopyası DEVRE DIÅžI sorun çekirdek sürücüsündedir\n" +" ekran panlamasını desteklemez (çerçeve hareketleri için kullanılır.).\n" + +#: src/video_out/video_out_fb.c:1036 +#, c-format +msgid "" +"WARNING: video_out_fb: current display depth is %d. For better performance\n" +" a depth of 16 bpp is recommended!\n" +"\n" +msgstr "" +"UYARI: video_out_fb: ÅŸu anki görüntü derinliÄŸi %d. Daha iyi sonuç için\n" +" 16 bpp'nin derinliÄŸi önerilir!\n" +"\n" + +#: src/video_out/video_out_fb.c:1067 +msgid "Xine video output plugin using the Linux frame buffer device" +msgstr "Linux çerçeve ara bellek aygıtı için Xine video çıkış eklentisi" + +#: src/video_out/video_out_none.c:277 +msgid "xine video output plugin which displays nothing" +msgstr "hiçbir ÅŸey göstermeyen xine video çıkış eklentisi" + +#: src/video_out/video_out_opengl.c:1886 +msgid "OpenGL renderer" +msgstr "OpenGL uygulayıcısı" + +#: src/video_out/video_out_opengl.c:1887 +msgid "" +"The OpenGL plugin provides several render modules:\n" +"\n" +"2D_Tex_Fragprog\n" +"This module downloads the images as YUV 2D textures and renders a textured " +"slice\n" +"using fragment programs for reconstructing RGB.\n" +"This is the best and fastest method on modern graphics cards.\n" +"\n" +"2D_Tex\n" +"This module downloads the images as 2D textures and renders a textured " +"slice.\n" +"2D_Tex_Tiled\n" +"This module downloads the images as multiple 2D textures and renders a " +"textured\n" +"slice. Thus this works with smaller maximum texture sizes as well.\n" +"Image_Pipeline\n" +"This module uses glDraw() to render the images.\n" +"Only accelerated on few drivers.\n" +"Does not interpolate on scaling.\n" +"\n" +"Cylinder\n" +"Shows images on a rotating cylinder. Nice effect :)\n" +"\n" +"Environment_Mapped_Torus\n" +"Show images reflected in a spinning torus. Way cool =)" +msgstr "" +"OpenGL eklentisi pek çok iÅŸleme modülü saÄŸlar:\n" +"\n" +"2D_Tex_Fragprog\n" +"Bu modül resimleri YUV 2D dokuları olarak indirir ve dokulanmış dilim olarak iÅŸler\n" +"ve RGB'yi yeniden oluÅŸturmak için dilimlere programları kullanır.\n" +"Bu, modern grafik kartları için en iyi ve en hızlı yöntemdir.\n" +"\n" +"2D_Tex\n" +"Bu modül resimleri 2D dokular olarak indirir ve dokulanmış dilim olarak iÅŸler.\n" +"2D_Tex_Tiled\n" +"Bu modül resimleri çoklu 2D dokular olarak indirir ve dokulanmış\n" +"dilim olarak iÅŸler. Böylece, daha küçük oranda ama en büyük doku boyutlarıyla çalışılmış olur.\n" +"Image_Pipeline\n" +"Bu modül resimleri iÅŸlemek için glDraw() kullanır.\n" +"Ancak, birkaç hızlandırılmış sürücülerle bu mümkündür.\n" +"Ölçeklemeyi etkilemez.\n" +"\n" +"Cylinder\n" +"Resimlerin dönen silindirde gösterir. Güzel efekt :)\n" +"\n" +"Environment_Mapped_Torus\n" +"Resimleri eÄŸilip bükülen halkada yansıtarak gösterir. Harika =)" + +#: src/video_out/video_out_opengl.c:1909 +msgid "OpenGL minimum framerate" +msgstr "OpenGL en az çerçeve oranı" + +#: src/video_out/video_out_opengl.c:1910 +msgid "" +"Minimum framerate for animated render routines.\n" +"Ignored for static render routines.\n" +msgstr "" +"Hareketli iÅŸleme yolları için en az çerçeve oranı\n" +"DuraÄŸan iÅŸleme yolları göz ardı edilmiÅŸtir.\n" + +#: src/video_out/video_out_opengl.c:1915 src/video_out/video_out_vidix.c:1012 +#: src/video_out/video_out_xcbxv.c:1470 src/video_out/video_out_xv.c:1523 +#: src/video_out/video_out_xvmc.c:1459 src/video_out/video_out_xxmc.c:2561 +msgid "enable double buffering" +msgstr "çift ara belleÄŸe almayı etkinleÅŸtir" + +#: src/video_out/video_out_opengl.c:1916 +msgid "" +"For OpenGL double buffering does not only remove tearing artifacts,\n" +"it also reduces flickering a lot.\n" +"It should not have any performance impact." +msgstr "" +"OpenGL çift ara belleÄŸe alma iÅŸlemi için sadece parçalanan görüntüleri kaldırmakla kalmaz,\n" +"aynı zamanda titremeyi de oldukça azaltır.\n" +"Bunun performansa herhangi bir etkisi olmaz." + +#: src/video_out/video_out_opengl.c:1963 +msgid "xine video output plugin using the OpenGL 3D graphics API" +msgstr "OpenGL 3D grafikleri API'sini kullanan xine video çıkış eklentisi" + +#: src/video_out/video_out_pgx32.c:187 +msgid "video_out_pgx32: Error: can't grab DGA drawable for video window\n" +msgstr "video_out_pgx32: Hata: video penceresi için DGA yakalanamıyor\n" + +#: src/video_out/video_out_pgx32.c:206 src/video_out/video_out_pgx32.c:220 +#, c-format +msgid "video_out_pgx32: Error: ioctl failed, bad device (%s)\n" +msgstr "video_out_pgx32: Hata: ioctl baÅŸarılamadı, kötü aygıt (%s)\n" + +#: src/video_out/video_out_pgx32.c:213 +#, c-format +msgid "video_out_pgx32: Error: '%s' is not a pgx32 framebuffer device\n" +msgstr "video_out_pgx32: Hata: '%s' bir pgx32 çerçeve ara belleÄŸi aygıtı deÄŸildir\n" + +#: src/video_out/video_out_pgx64.c:278 +msgid "video_out_pgx64: Error: can't grab DGA drawable for video window\n" +msgstr "video_out_pgx64: Hata: video penceresi için DGA yakalanamıyor\n" + +#: src/video_out/video_out_pgx64.c:296 +#, c-format +msgid "video_out_pgx64: Error: can't open framebuffer device '%s'\n" +msgstr "video_out_pgx64: Hata: çerçeve ara belleÄŸi aygıtını açamıyor '%s'\n" + +#: src/video_out/video_out_pgx64.c:303 +#, c-format +msgid "video_out_pgx64: Error: ioctl failed (VIS_GETIDENTIFIER), bad device (%s)\n" +msgstr "video_out_pgx64: Hata: Hata: ioctl baÅŸarılamadı (VIS_GETIDENTIFIER), kötü aygıt (%s)\n" + +#: src/video_out/video_out_pgx64.c:316 +#, c-format +msgid "video_out_pgx64: Error: '%s' is not a xvr100/pgx64/pgx24 framebuffer device\n" +msgstr "video_out_pgx64: Hata: '%s' bir xvr100/pgx64/pgx24 çerçeve ara belleÄŸi aygıtı deÄŸildir\n" + +#: src/video_out/video_out_pgx64.c:337 +msgid "video_out_pgx64: Error: video overlay on this screen is already in use\n" +msgstr "video_out_pgx64: Hata: bu ekrandaki video üstyazım halen kullanımdadır\n" + +#: src/video_out/video_out_pgx64.c:352 +msgid "video_out_pgx64: Error: unable to set window properties\n" +msgstr "video_out_pgx64: Hata: pencere özellikleri ayarlanamıyor\n" + +#: src/video_out/video_out_pgx64.c:808 +msgid "video_out_pgx64: Warning: low video memory, multi-buffering disabled\n" +msgstr "video_out_pgx64: Uyarı: düşük görüntü hafızası, çift-ara bellekleme devre dışı\n" + +#: src/video_out/video_out_pgx64.c:840 +msgid "video_out_pgx64: Error: insuffucient video memory\n" +msgstr "video_out_pgx64: Hata: yetersiz video hafızası\n" + +#: src/video_out/video_out_pgx64.c:856 +msgid "video_out_pgx64: Warning: low video memory, double-buffering disabled\n" +msgstr "video_out_pgx64: Uyarı: düşük video hafızası, çift-ara bellekleme devre dışı\n" + +#: src/video_out/video_out_pgx64.c:1394 +msgid "video_out_pgx64: Error: ioctl failed (FBIOGATTR)\n" +msgstr "video_out_pgx64: Hata: ioctl baÅŸarılamadı (FBIOGATTR)\n" + +#: src/video_out/video_out_pgx64.c:1461 src/video_out/video_out_xcbxv.c:1437 +#: src/video_out/video_out_xv.c:1490 src/video_out/video_out_xvmc.c:1444 +#: src/video_out/video_out_xxmc.c:2528 +msgid "video overlay colour key" +msgstr "görüntü üstyazım renk anahtarı" + +#: src/video_out/video_out_pgx64.c:1462 +msgid "" +"The colour key is used to tell the graphics card where it can overlay the " +"video image. Try using different values if you see the video showing through " +"other windows." +msgstr "Renk anahtarı, video görüntüsünün nerede ekranı kaplayacağını ekran kartına bildirmek için kullanılır. EÄŸer videonun farklı pencerelerde gösterdiÄŸini saptarsanız deÄŸiÅŸik deÄŸerler deneyin." + +#: src/video_out/video_out_pgx64.c:1469 +msgid "enable chroma keying" +msgstr "renk berraklığı anahtarlamayı etkinleÅŸtir" + +#: src/video_out/video_out_pgx64.c:1470 +msgid "" +"Draw OSD graphics on top of the overlay colour key rather than blend them " +"into each frame." +msgstr "OSD grafiklerini her çerçevede harmanlamak yerine üstyazım renk anahtarının üzerine çizin." + +#: src/video_out/video_out_pgx64.c:1473 +msgid "enable multi-buffering" +msgstr "çoklu-tamponlamayı etkinleÅŸtir" + +#: src/video_out/video_out_pgx64.c:1474 +msgid "" +"Multi buffering increases performance at the expense of using more graphics " +"memory." +msgstr "Çoklu Tamponlama, daha fazla görüntü hafızası kullanılmasına yol açar." + +#: src/video_out/video_out_sdl.c:480 +msgid "use hardware acceleration if available" +msgstr "olanaklı ise donanım hızlandırması kullan" + +#: src/video_out/video_out_sdl.c:481 +msgid "" +"When your system supports it, hardware acceleration provided by your " +"graphics hardware will be used. This might not work, so you can disable it, " +"if things go wrong." +msgstr "Sisteminiz desteklediÄŸinde, grafik donanımız tarafından saÄŸlanan donanım hızlandırması kullanılacaktır. EÄŸer bir ÅŸeyler yanlış giderse, bu çalışmayabilir, o zaman devre dışı bırakabilirsiniz." + +#: src/video_out/video_out_sdl.c:523 +msgid "sdl has to emulate a 16 bit surfaces, that will slow things down.\n" +msgstr "sdl 16 bit yüzeylerine öykünmek zorundadır, ki bu da iÅŸleri yavaÅŸlatır.\n" + +#: src/video_out/video_out_sdl.c:560 +msgid "video_out_sdl: fullscreen mode is NOT supported\n" +msgstr "video_out_sdl: tam ekran kipi desteklenmiyor\n" + +#: src/video_out/video_out_sdl.c:571 +msgid "xine video output plugin using the Simple Direct Media Layer" +msgstr "Simple Direct Media Layer özelliÄŸini kullanan xine görüntü çıkışı eklentisi" + +#: src/video_out/video_out_stk.c:452 +msgid "xine video output plugin using the Libstk Surface Set-top Toolkit" +msgstr "Libstk Surface Set-top Toolkit özelliÄŸini kullanan xine görüntü çıkışı eklentisi" + +#: src/video_out/video_out_syncfb.c:280 +msgid "video_out_syncfb: error. (YUY2 not supported by your graphic card)\n" +msgstr "video_out_syncfb: hata. (YUY2 ekran kartını tarafından desteklenmiyor)\n" + +#: src/video_out/video_out_syncfb.c:296 +msgid "video_out_syncfb: error. (YV12 not supported by your graphic card)\n" +msgstr "video_out_syncfb: hata. (YV12 ekran kartınız tarafından desteklenmiyor)\n" + +#: src/video_out/video_out_syncfb.c:938 +msgid "video_out_syncfb: info. (SyncFB module supports YUV 4:2:0 (3 plane))\n" +msgstr "video_out_syncfb: bilgi. (SyncFB modülü YUV 4:2:0 (3 plane)) parametresini destekler\n" + +#: src/video_out/video_out_syncfb.c:943 +msgid "video_out_syncfb: info. (SyncFB module supports YUV 4:2:0 (2 plane))\n" +msgstr "video_out_syncfb: bilgi. (SyncFB modülü YUV 4:2:0 (2 plane)) parametresini destekler\n" + +#: src/video_out/video_out_syncfb.c:948 +msgid "video_out_syncfb: info. (SyncFB module supports YUV 4:2:2)\n" +msgstr "video_out_syncfb: bilgi. (SyncFB modülü YUV 4:2:2) parametresini destekler\n" + +#: src/video_out/video_out_syncfb.c:954 +msgid "video_out_syncfb: info. (SyncFB module supports YUY2)\n" +msgstr "video_out_syncfb: bilgi. (SyncFB modülü YUY2) parametresini destekler\n" + +#: src/video_out/video_out_syncfb.c:961 +msgid "video_out_syncfb: info. (SyncFB module supports RGB565)\n" +msgstr "video_out_syncfb: bilgi. (SyncFB modülü RGB565) parametresini destekler\n" + +#: src/video_out/video_out_syncfb.c:966 +msgid "" +"video_out_syncfb: aborting. (SyncFB module does not support YV12, YUY2 nor " +"RGB565)\n" +msgstr "" +"video_out_syncfb: durduruyor. (SyncFB modülü, ne YV12 ve YUY2 parametrelerini, ne de " +"RGB565) parametresini destekler\n" + +#: src/video_out/video_out_syncfb.c:985 +msgid "" +"video_out_syncfb: info. (brightness/contrast control won't be available " +"because your SyncFB kernel module seems to be outdated. Please refer to " +"README.syncfb for informations on how to update it.)\n" +msgstr "" +"video_out_syncfb: bilgi. (parlaklık/zıtlık denetimi uygun olmayacak " +"çünkü SyncFB çekirdek modülünüz güncelliÄŸini yitirmiÅŸ gözüküyor. Onu nasıl güncelleyeceÄŸinizi öğrenmek için " +"README.syncfb belgesine bakınız.)\n" + +#: src/video_out/video_out_syncfb.c:1009 +msgid "default number of frame repetitions" +msgstr "çerçeve tekrarlarının öntanımlı numarası" + +#: src/video_out/video_out_syncfb.c:1010 +msgid "" +"This specifies how many times a single video frame will be displayed " +"consecutively." +msgstr "Bu, tek video çerçevenizin ardışık olarak kaç defa görüntülenebileceÄŸini belirler." + +#: src/video_out/video_out_syncfb.c:1058 +msgid "xine video output plugin using the SyncFB module for Matrox G200/G400 cards" +msgstr "Matrox G200/G400 kartları için SyncFB modülünü kullanan xine görüntü çıkışı eklentisi" + +#: src/video_out/video_out_syncfb.c:1076 +msgid "SyncFB device name" +msgstr "SyncFB aygıt ismi" + +#: src/video_out/video_out_syncfb.c:1077 +msgid "" +"Specifies the file name for the SyncFB (TeleTux) device to be used.\n" +"This setting is security critical, because when changed to a different file, " +"xine can be used to fill this file with arbitrary content. So you should be " +"careful that the value you enter really is a proper framebuffer device." +msgstr "" +"Kullanılacak olan SyncFB (TeleTux) aygıtı için dosya ismini belirler.\n" +"Bu güvenlik açısından kritiktir, çünkü dosya adı deÄŸiÅŸtirildiÄŸinde, xine bu dosyanın içini ilgisiz içerikle doldurması için kullanılabilir.bu yüzden çerçeve belleÄŸi aygıtı için gerçekten uygun bir deÄŸer girmeye dikkat etmelisiniz." + +#: src/video_out/video_out_vidix.c:990 +msgid "red intensity" +msgstr "kırmızı yoÄŸunluÄŸu" + +#: src/video_out/video_out_vidix.c:990 +msgid "The intensity of the red colour components." +msgstr "Kırmızı renk bileÅŸenlerinin yoÄŸunluÄŸu." + +#: src/video_out/video_out_vidix.c:995 +msgid "green intensity" +msgstr "yeÅŸil yoÄŸunluÄŸu" + +#: src/video_out/video_out_vidix.c:995 +msgid "The intensity of the green colour components." +msgstr "YeÅŸil renk bileÅŸenlerinin yoÄŸunluÄŸu." + +#: src/video_out/video_out_vidix.c:1000 +msgid "blue intensity" +msgstr "mavi yoÄŸunluÄŸu" + +#: src/video_out/video_out_vidix.c:1000 +msgid "The intensity of the blue colour components." +msgstr "Mavi renk bileÅŸenlerinin yoÄŸunluÄŸu." + +#: src/video_out/video_out_vidix.c:1013 src/video_out/video_out_xcbxv.c:1471 +#: src/video_out/video_out_xv.c:1524 src/video_out/video_out_xvmc.c:1460 +#: src/video_out/video_out_xxmc.c:2562 +msgid "" +"Double buffering will synchronize the update of the video image to the " +"repainting of the entire screen (\"vertical retrace\"). This eliminates " +"flickering and tearing artifacts, but will use more graphics memory." +msgstr "Çift ara bellekleme tüm ekranı yeniden oluÅŸturan görüntünün güncellenmesi için senkron çalışacaktır (\"dikey takip\"). Bu, görüntüde titreme ve parçalanmayı önler, fakat bu iÅŸlem daha çok ekran kartı hafızası kullanımına sebebiyet verecektr." + +#: src/video_out/video_out_vidix.c:1060 +msgid "video_out_vidix: adaptor supports the yuy2 format\n" +msgstr "video_out_vidix: çevirici yuy2 kipini destekler\n" + +#: src/video_out/video_out_vidix.c:1071 +msgid "video_out_vidix: adaptor supports the yv12 format\n" +msgstr "video_out_vidix: paralel bilgisayar yv12 kipini destekler\n" + +#: src/video_out/video_out_vidix.c:1087 +msgid "video_out_vidix: You have wrong version of VIDIX library\n" +msgstr "video_out_vidix: VIDIX kütüphanesinin hatalı sürümüne sahipsiniz\n" + +#: src/video_out/video_out_vidix.c:1095 +msgid "video_out_vidix: Couldn't find working VIDIX driver\n" +msgstr "video_out_vidix: Çalışan VIDIX sürücünü bulamıyor\n" + +#: src/video_out/video_out_vidix.c:1108 +#, c-format +msgid "video_out_vidix: using driver: %s by %s\n" +msgstr "video_out_vidix: kullanılan sürücü: %s by %s\n" + +#: src/video_out/video_out_vidix.c:1155 +msgid "video overlay colour key red component" +msgstr "görüntü üstyazım renk anahtarı kırmızı bileÅŸeni" + +#: src/video_out/video_out_vidix.c:1156 src/video_out/video_out_vidix.c:1163 +#: src/video_out/video_out_vidix.c:1170 src/video_out/video_out_xcbxv.c:1438 +#: src/video_out/video_out_xv.c:1491 src/video_out/video_out_xvmc.c:1445 +#: src/video_out/video_out_xxmc.c:2529 +msgid "" +"The colour key is used to tell the graphics card where to overlay the video " +"image. Try different values, if you experience windows becoming transparent." +msgstr "Renk anahtarı, video görüntüsünün nerede ekranı kaplayacağını ekran kartına bildirmek için kullanılır. EÄŸer pencereleriniz ÅŸeffaf hale geliyorsa deÄŸiÅŸik deÄŸerler deneyin." + +#: src/video_out/video_out_vidix.c:1162 +msgid "video overlay colour key green component" +msgstr "görüntü üstyazım renk anahtarı yeÅŸil bileÅŸeni" + +#: src/video_out/video_out_vidix.c:1169 +msgid "video overlay colour key blue component" +msgstr "görüntü üstyazım renk anahtarı mavi bileÅŸeni" + +#: src/video_out/video_out_vidix.c:1201 +msgid "xine video output plugin using libvidix for x11" +msgstr "x11 için libvidix kullanan xine görüntü çıkışı eklentisi" + +#: src/video_out/video_out_vidix.c:1283 +msgid "xine video output plugin using libvidix for linux frame buffer" +msgstr "linux çerçeve ara belleÄŸi için libvidix kullanan xine görüntü çıkışı eklentisi" + +#: src/video_out/video_out_xcbshm.c:155 +#, c-format +msgid "" +"video_out_xcbshm: %s: allocating image\n" +"video_out_xcbshm: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xcbshm: %s: resmin yerini alıyor\n" +"video_out_xcbshm: => MIT Paylaşılan Bellek uzantısını kullanmıyor.\n" + +#: src/video_out/video_out_xcbshm.c:164 +msgid "" +"video_out_xcbshm: shared memory error (address error) when allocating " +"image \n" +"video_out_xcbshm: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xcbshm: resmin yerini geçerken paylaşılan bellek hatası (adres hatası ) \n" +"video_out_xcbshm: => MIT Paylaşılan Bellek uzantısını kullanmıyor.\n" + +#: src/video_out/video_out_xcbshm.c:175 +msgid "" +"video_out_xcbshm: x11 error during shared memory XImage creation\n" +"video_out_xcbshm: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xcbshm: paylaşılan bellek XImage oluÅŸturma boyunca x11 hatası\n" +"video_out_xcbshm: => MIT Paylaşılan Bellek uzantısını kullanmıyor.\n" + +#: src/video_out/video_out_xcbshm.c:1098 src/video_out/video_out_xshm.c:1154 +#, c-format +msgid "" +"\n" +"\n" +"WARNING: current display depth is %d. For better performance\n" +"a depth of 16 bpp is recommended!\n" +"\n" +msgstr "" +"\n" +"\n" +"UYARI: ÅŸu anki görüntü derinliÄŸi %d. Ama, daha iyi performanstır\n" +"16 bpp derinliÄŸi önerilir!\n" +"\n" + +#: src/video_out/video_out_xcbshm.c:1111 +msgid "video_out_xcbshm: MIT shared memory extension not present on display.\n" +msgstr "video_out_xcbshm: MIT Paylaşılan Bellek uzantısı ÅŸu and ekranda deÄŸildir.\n" + +#: src/video_out/video_out_xcbshm.c:1210 +msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n" +msgstr "video_out_xcbshm: görüntü kipiniz algılanamadı, üzgünüm :-(\n" + +#: src/video_out/video_out_xcbshm.c:1240 src/video_out/video_out_xshm.c:1300 +msgid "xine video output plugin using the MIT X shared memory extension" +msgstr "MIT X paylaşılan bellek uzantısını kullanan xine görüntü eklentisi" + +#: src/video_out/video_out_xcbxv.c:268 +msgid "" +"video_out_xcbxv: XvShmCreateImage returned a zero size\n" +"video_out_xcbxv: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xcbxv: XvShmCreateImage sıfır boyutuna dönüştü\n" +"video_out_xcbxv: => MIT Paylaşılan Bellek uzantısını kullanmıyor.\n" + +#: src/video_out/video_out_xcbxv.c:277 +#, c-format +msgid "" +"video_out_xcbxv: shared memory error in shmget: %s\n" +"video_out_xcbxv: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xcbxv: shmget'de paylaşılan bellek hatası: %s\n" +"video_out_xcbxv: => MIT Paylaşılan Bellek uzantısını kullanmıyor.\n" + +#: src/video_out/video_out_xcbxv.c:296 +msgid "" +"video_out_xcbxv: x11 error during shared memory XImage creation\n" +"video_out_xcbxv: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xcbxv: XImage oluÅŸturması boyunca x11 hatası\n" +"video_out_xcbxv: => MIT Paylaşılan Bellek uzantısını kullanmıyor.\n" + +#: src/video_out/video_out_xcbxv.c:1289 +msgid "video_out_xcbxv: Xv extension not present.\n" +msgstr "video_out_xcbxv: Xv uzantısı ÅŸu anda hazır deÄŸil.\n" + +#: src/video_out/video_out_xcbxv.c:1331 +msgid "" +"video_out_xcbxv: Xv extension is present but I couldn't find a usable yuv12 " +"port.\n" +" Looks like your graphics hardware driver doesn't support " +"Xv?!\n" +msgstr "" +"video_out_xcbxv: Xv extension ÅŸu anda hazır fakat kullanılabilir yuv12 portunu bulamıyorum" +".\n" +" Ekran donanım sürücünüz Xv desteÄŸi vermiyor gibi gözüküyor?!\n" + +#: src/video_out/video_out_xcbxv.c:1339 +#, c-format +msgid "" +"video_out_xcbxv: using Xv port %d from adaptor %s for hardware colorspace " +"conversion and scaling.\n" +msgstr "video_out_xcbxv: Xv portunu %d çeviriciden %s for donanım renk modeli çevrimi ve yükseltmesi için kullanıyor.\n" + +#: src/video_out/video_out_xcbxv.c:1446 src/video_out/video_out_xv.c:1499 +#: src/video_out/video_out_xvmc.c:1453 src/video_out/video_out_xxmc.c:2537 +msgid "autopaint colour key" +msgstr "otomatik boyama renk anahtarı" + +#: src/video_out/video_out_xcbxv.c:1447 src/video_out/video_out_xv.c:1500 +#: src/video_out/video_out_xvmc.c:1454 src/video_out/video_out_xxmc.c:2538 +msgid "Make Xv autopaint its colorkey." +msgstr "XV'yi onun otomatik boyama renk anahtarı yap." + +#: src/video_out/video_out_xcbxv.c:1454 src/video_out/video_out_xv.c:1507 +#: src/video_out/video_out_xxmc.c:2545 +msgid "bilinear scaling mode" +msgstr "çift çizgili arıtma kipi" + +#: src/video_out/video_out_xcbxv.c:1455 src/video_out/video_out_xv.c:1508 +#: src/video_out/video_out_xxmc.c:2546 +msgid "" +"Selects the bilinear scaling mode for Permedia cards. The individual values " +"are:\n" +"\n" +"Permedia 2\n" +"0 - disable bilinear filtering\n" +"1 - enable bilinear filtering\n" +"\n" +"Permedia 3\n" +"0 - disable bilinear filtering\n" +"1 - horizontal linear filtering\n" +"2 - enable full bilinear filtering" +msgstr "" +"Çift çizgili arıtma kipini, Permedia kartlar için seçer. Bireysel deÄŸerler ÅŸunlardır:\n" +"\n" +"Permedia 2\n" +"0 - çift çizgili filtrelemeyi devre dışı bırak\n" +"1 - çift çizgili filtrelemeyi etkinleÅŸtir\n" +"\n" +"Permedia 3\n" +"0 - çift çizgili filtrelemeyi devre dışı bırak\n" +"1 - yatay doÄŸrusal filtreleme\n" +"2 - tam çift çizgili filtrelemeyi etkinleÅŸtir" + +#: src/video_out/video_out_xcbxv.c:1507 +msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n" +msgstr "video_out_xcbxv: bu çevirici yv12 kipini destekler.\n" + +#: src/video_out/video_out_xcbxv.c:1512 +msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n" +msgstr "video_out_xcbxv: bu çevirici yuy2 kipini destekler.\n" + +#: src/video_out/video_out_xcbxv.c:1520 src/video_out/video_out_xv.c:1584 +#: src/video_out/video_out_xxmc.c:2630 +msgid "pitch alignment workaround" +msgstr "karakter hizalama düzeltmesi" + +#: src/video_out/video_out_xcbxv.c:1521 src/video_out/video_out_xv.c:1585 +#: src/video_out/video_out_xxmc.c:2631 +msgid "Some buggy video drivers need a workaround to function properly." +msgstr "Bazı sorunlu video sürücüleri doÄŸru çalışmaları için bazı düzeltmelere ihtiyaç duyarlar." + +#: src/video_out/video_out_xcbxv.c:1527 src/video_out/video_out_xv.c:1591 +#: src/video_out/video_out_xvmc.c:1522 +msgid "deinterlace method (deprecated)" +msgstr "dönüştürme yöntemi (arındırılmış)" + +#: src/video_out/video_out_xcbxv.c:1528 src/video_out/video_out_xv.c:1592 +#: src/video_out/video_out_xvmc.c:1523 +msgid "" +"This config setting is deprecated. You should use the new deinterlacing post " +"processing settings instead.\n" +"\n" +"From the old days of analog television, where the even and odd numbered " +"lines of a video frame would be displayed at different times comes the idea " +"to increase motion smoothness by also recording the lines at different " +"times. This is called \"interlacing\". But unfortunately, todays displays " +"show the even and odd numbered lines as one complete frame all at the same " +"time (called \"progressive display\"), which results in ugly frame errors " +"known as comb artifacts. Software deinterlacing is an approach to reduce " +"these artifacts. The individual values are:\n" +"\n" +"none\n" +"Disables software deinterlacing.\n" +"\n" +"bob\n" +"Interpolates between the lines for moving parts of the image.\n" +"\n" +"weave\n" +"Similar to bob, but with a tendency to preserve the full resolution, better " +"for high detail in low movement scenes.\n" +"\n" +"greedy\n" +"Very good adaptive deinterlacer, but needs a lot of CPU power.\n" +"\n" +"onefield\n" +"Always interpolates and reduces vertical resolution.\n" +"\n" +"onefieldxv\n" +"Same as onefield, but does the interpolation in hardware.\n" +"\n" +"linearblend\n" +"Applies a slight vertical blur to remove the comb artifacts. Good results " +"with medium CPU usage." +msgstr "" +"Bu yapılandırma ayarı arındırılmıştır. Bunun yerine yeni bir son iÅŸleme dönümünü kullanabilirsiniz.\n" +"\n" +"Eski analog televizyon günlerinde, tek ve çift sayılı video çerçeveleri çizgileri farklı zamanlarda görüntülenebilirdi. Bir fikir olarak bu çizgileri hareket düzlüğünü arttırmak için farklı zamanlarda kaydetme düşüncesi ortaya çıktı. Buna \"dönüştürme\" denildi. Fakat ne yazık ki, bugün ekranlar, tek ve çift sayılara sahip olan çizgileri tek bir zamanda, tek bir çerçeve olarak gösterebilmektedirler (buna da \"geliÅŸmiÅŸ ekran \" denilmektedir), fakat bunlar tepe sonuçları olarak bilinen çirkin çerçeve hatalarına sebep olmaktadırlar. Yazılım dönüştürmesi bu sonuçları azaltmayı amaçlayan bir yaklaşımdır. Bireysel deÄŸerler ÅŸunlardır:\n" +"\n" +"none\n" +"Yazılım dönüştürmesine devre dışı bırakır.\n" +"\n" +"bob\n" +"Resmin hareketleri kısımlarını atmak için çizgiler arasında gider gelir.\n" +"\n" +"weave\n" +"Bob'a benzer ÅŸekilde, fakat tüm çözünürlüğü koruma eÄŸilimiyle, yavaÅŸ hareketli sahnelerde çok detay daha iyidir.\n" +"\n" +"greedy\n" +"Çok iyi uyarlanabilir döünÅŸtürücü, fakat daha fazla iÅŸlemci gücü gerektirir.\n" +"\n" +"onefield\n" +"Daima karıştırı ve dikey çözünürlüğü azaltır.\n" +"\n" +"onefieldxv\n" +"Onefield ile aynıdır, fakat karışımı donanımda gerçekleÅŸtirir.\n" +"\n" +"linearblend\n" +"Tarak sonuçlarını kaldırmak için hafif bir dikey bulandırma uygular. Ortalama bir iÅŸlemci hızıyla " +"iyi sonuçlar alınabilir." + +#: src/video_out/video_out_xcbxv.c:1582 src/video_out/video_out_xv.c:1665 +#: src/video_out/video_out_xxmc.c:2725 +msgid "xine video output plugin using the MIT X video extension" +msgstr "MIT X görüntü geniÅŸlemesini kullanmak için xine görüntü eklentisi" + +#: src/video_out/video_out_xshm.c:199 +msgid "" +"video_out_xshm: shared memory error when allocating image\n" +"video_out_xshm: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xshm: shared memory error when allocating image\n" +"video_out_xshm: => not using MIT Shared Memory extension.\n" + +#: src/video_out/video_out_xshm.c:215 +#, c-format +msgid "" +"video_out_xshm: %s: allocating image\n" +"video_out_xshm: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xshm: %s: resmin yerine geçiyor\n" +"video_out_xshm: => MIT Paylaşılan Bellek uzantısını kullanmıyor.\n" + +#: src/video_out/video_out_xshm.c:225 +msgid "" +"video_out_xshm: shared memory error (address error) when allocating image \n" +"video_out_xshm: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xshm: resmin yerini geçerken paylaşılan bellek hatası (adres hatası ) \n" +"video_out_xshm: => MIT Paylaşılan Bellek uzantısını kullanmıyor.\n" + +#: src/video_out/video_out_xshm.c:242 +msgid "" +"video_out_xshm: x11 error during shared memory XImage creation\n" +"video_out_xshm: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xshm: paylaşılan bellek XImage oluÅŸturma boyunca x11 hatası\n" +"video_out_xshm: => MIT Paylaşılan Bellek uzantısını kullanmıyor.\n" + +#: src/video_out/video_out_xshm.c:1167 +msgid "video_out_xshm: MIT shared memory extension not present on display.\n" +msgstr "video_out_xshm: MIT Paylaşılan Bellek uzantısı ÅŸu and ekranda deÄŸildir.\n" + +#: src/video_out/video_out_xshm.c:1251 +msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n" +msgstr "video_out_xshm: görüntü kipiniz algılanamadı, üzgünüm :-(\n" + +#: src/video_out/video_out_xv.c:291 +msgid "" +"video_out_xv: XvShmCreateImage failed\n" +"video_out_xv: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xv: XvShmCreateImage baÅŸarılamadı\n" +"video_out_xv: => MIT Paylaşılan Bellek uzantısını kullanmıyor.\n" + +#: src/video_out/video_out_xv.c:317 +msgid "" +"video_out_xv: XvShmCreateImage returned a zero size\n" +"video_out_xv: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xv: XvShmCreateImage bir sıfır boyutuna dönüştü\n" +"video_out_xv: => MIT Paylaşılan Bellek uzantısını kullanmıyor.\n" + +#: src/video_out/video_out_xv.c:325 +#, c-format +msgid "" +"video_out_xv: shared memory error in shmget: %s\n" +"video_out_xv: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xv: shmget: %s de paylaşılan bellek hatası\n" +"video_out_xv: => MIT Paylaşılan Bellek uzantısını kullanmıyor.\n" + +#: src/video_out/video_out_xv.c:357 +msgid "" +"video_out_xv: x11 error during shared memory XImage creation\n" +"video_out_xv: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xv: paylaşılan bellek XImage oluÅŸturma boyunca x11 hatası\n" +"video_out_xv: => MIT Paylaşılan Bellek uzantısını kullanmıyor.\n" + +#: src/video_out/video_out_xv.c:1336 +msgid "video_out_xv: Xv extension not present.\n" +msgstr "video_out_xv: Xv uzantısı hazır deÄŸil.\n" + +#: src/video_out/video_out_xv.c:1373 +msgid "" +"video_out_xv: Xv extension is present but I couldn't find a usable yuv12 " +"port.\n" +" Looks like your graphics hardware driver doesn't support Xv?!\n" +msgstr "" +"video_out_xv: Xv extension ÅŸu anda hazır fakat kullanılabilir yuv12 portunu bulamıyorum.\n" +" Ekran donanım sürücünüz Xv desteÄŸi vermiyor gibi gözüküyor?!\n" + +#: src/video_out/video_out_xv.c:1382 +#, c-format +msgid "" +"video_out_xv: using Xv port %ld from adaptor %s for hardware colorspace " +"conversion and scaling.\n" +msgstr "video_out_xv: Xv portunu %ld çeviriciden %s donanım renk modeli çevrimi ve yükseltmesi için kullanıyor.\n" + +#: src/video_out/video_out_xv.c:1557 +msgid "video_out_xv: this adaptor supports the yv12 format.\n" +msgstr "video_out_xv: bu çevirici yv12 kipini destekler.\n" + +#: src/video_out/video_out_xv.c:1562 +msgid "video_out_xv: this adaptor supports the yuy2 format.\n" +msgstr "video_out_xv: bu çevirici yuy2 kipini destekler.\n" + +#: src/video_out/video_out_xvmc.c:1591 +msgid "xine video output plugin using the XvMC X video extension" +msgstr "XvMC X görüntü uzantısını kullanması için xine görüntü eklentisi" + +#: src/video_out/video_out_xvmc.c:1637 +msgid "video_out_xvmc: XvMC extension not present.\n" +msgstr "video_out_xvmc: XvMC uzantısı ÅŸu an hazır deÄŸil.\n" + +#: src/video_out/video_out_xvmc.c:1735 +msgid "" +"video_out_xvmc: Xv extension is present but I couldn't find a usable yuv12 " +"port.\n" +msgstr "video_out_xvmc: Xv uzantısı hazır fakat kullanılabilir durumda bir yuv12 portu bulamıyorum.\n" + +#: src/video_out/video_out_xvmc.c:1744 +#, c-format +msgid "" +"video_out_xvmc: using Xv port %ld from adaptor %s\n" +" for hardware colorspace conversion and scaling\n" +msgstr "" +"video_out_xvmc: Xv portunu %ld çeviriciden %s kullanıyor\n" +" donanım renk modeli çevrimi ve yükselmesi için\n" + +#: src/video_out/video_out_xvmc.c:1749 +msgid " idct and motion compensation acceleration \n" +msgstr " idct ve hareket bedeli hızlandırılması \n" + +#: src/video_out/video_out_xvmc.c:1751 +msgid " motion compensation acceleration only\n" +msgstr " sadece hareket bedeli hızlandırılması\n" + +#: src/video_out/video_out_xvmc.c:1753 +msgid " no XvMC support \n" +msgstr " hiçbir XvMC desteÄŸi yok \n" + +#: src/video_out/video_out_xvmc.c:1754 +#, c-format +msgid " With Overlay = %d; UnsignedIntra = %d.\n" +msgstr " Üstyazımlı = %d; İmzalanmamış Intra = %d.\n" + +#: src/video_out/video_out_xxmc.c:642 +msgid "" +"video_out_xxmc: XvShmCreateImage failed\n" +"video_out_xxmc: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xxmc: XvShmCreateImage baÅŸarılamadı\n" +"video_out_xxmc: => MIT Paylaşılan Bellek uzantısını kullanmıyor.\n" + +#: src/video_out/video_out_xxmc.c:652 +msgid "" +"video_out_xxmc: XvShmCreateImage returned a zero size\n" +"video_out_xxmc: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xxmc: XvShmCreateImage sıfır boyutuna dönüştü\n" +"video_out_xxmc: => MIT Paylaşılan Bellek uzantısını kullanmıyor.\n" + +#: src/video_out/video_out_xxmc.c:660 +#, c-format +msgid "" +"video_out_xxmc: shared memory error in shmget: %s\n" +"video_out_xxmc: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xxmc: shmget'de paylaşılan bellek hatası: %s\n" +"video_out_xxmc: => MIT Paylaşılan Bellek uzantısını kullanmıyor.\n" + +#: src/video_out/video_out_xxmc.c:692 +msgid "" +"video_out_xxmc: x11 error during shared memory XImage creation\n" +"video_out_xxmc: => not using MIT Shared Memory extension.\n" +msgstr "" +"video_out_xxmc: XImage oluÅŸturması boyunca x11 hatası\n" +"video_out_xxmc: => MIT Paylaşılan Bellek uzantısını kullanmıyor.\n" + +#: src/video_out/video_out_xxmc.c:2380 +msgid "video_out_xxmc: Xv extension not present.\n" +msgstr "video_out_xxmc: Xv uzantısı ÅŸu anda hazır deÄŸil.\n" + +#: src/video_out/video_out_xxmc.c:2417 +msgid "" +"video_out_xxmc: Xv extension is present but I couldn't find a usable yuv12 " +"port.\n" +" Looks like your graphics hardware driver doesn't support Xv?!\n" +msgstr "" +"video_out_xxmc: Xv extension ÅŸu anda hazır fakat kullanılabilir yuv12 portunu bulamıyorum" +".\n" +" Ekran donanım sürücünüz Xv desteÄŸi vermiyor gibi gözüküyor?!\n" + +#: src/video_out/video_out_xxmc.c:2426 +#, c-format +msgid "" +"video_out_xxmc: using Xv port %ld from adaptor %s for hardware colorspace " +"conversion and scaling.\n" +msgstr "video_out_xxmc: donanım renk modeli çevrimi ve yükselmesi için Xv portunu %ld çevirividen %s kullanıyor\n" + +#: src/video_out/video_out_xxmc.c:2602 +msgid "video_out_xxmc: this adaptor supports the yv12 format.\n" +msgstr "video_out_xxmc: bu çevirici yv12 kipini destekler.\n" + +#: src/video_out/video_out_xxmc.c:2607 +msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n" +msgstr "video_out_xxmc: bu çevirici yuy2 kipini destekler.\n" + +#: src/video_out/video_out_xxmc.c:2636 +msgid "Make XvMC allocate more frames for better buffering." +msgstr "Daha iyi tamponlama için XvMC belirlemesini daha fazla çerçeveye atayın." + +#: src/video_out/video_out_xxmc.c:2637 +msgid "" +"Some XvMC implementations allow more than 8 frames.\n" +"This option, when turned on, makes the driver try to\n" +"allocate 15 frames. A must for unichrome and live VDR.\n" +msgstr "" +"Bazı XvMC yürütmeleri 8 kareden daha fazlasına izin verir..\n" +"Bu seçenek, açıldığında, sürücülerin\n" +"15 kareyi denemesine izin verir. BirleÅŸik renk berraklığı ve canlı VDR için bu yapılmalıdır.\n" + +#: src/video_out/video_out_xxmc.c:2643 +msgid "Unichrome cpu save" +msgstr "BirleÅŸik Renk Berraklığı iÅŸlemci koruması" + +#: src/video_out/video_out_xxmc.c:2644 +msgid "" +"Saves CPU time by sleeping while decoder works.\n" +"Only for Linux kernel 2.6 series or 2.4 with multimedia patch.\n" +"Experimental.\n" +msgstr "" +"Kod çözücü çalışırken iÅŸlemci zamanını uyuyarak korur.\n" +"Sadece 2.6 veya 2.4 serisi Linux çekirdeÄŸi için ve çokluortam yamasıyla birlikte.\n" +"Deneysel.\n" + +#: src/video_out/video_out_xxmc.c:2650 +msgid "Fix buggy NVIDIA XvMC subpicture colors" +msgstr "Sorunlu NVIDIA XvMC altresim renklerini düzeltin." + +#: src/video_out/video_out_xxmc.c:2651 +msgid "" +"There's a bug in NVIDIA's XvMC lib that makes red OSD colors\n" +"look blue and vice versa. This option provides a workaround.\n" +msgstr "" +"NVIDIA'nın XvMC kütüphanesinde kırmızı OSD renklerinin mavi veya baÅŸka\n" +"gözükmelerine sebep olanen bir hata vardır." +"Bu seçenek temizleme gerektir.\n" + +#: src/video_out/video_out_xxmc.c:2656 +msgid "Use bob as accelerated deinterlace method." +msgstr "Hızlandırılmış dönüştürme yöntemi olarak bob'u kullanın." + +#: src/video_out/video_out_xxmc.c:2657 +msgid "" +"When interlacing is enabled for hardware accelerated frames,\n" +"alternate between top and bottom field at double the frame rate.\n" +msgstr "" +"Donanımca hızlandırılmış kareler için dönüştürme devrede olduÄŸunda,\n" +"çerçeve oranındaki üst ve alt alanlara göz atmalı.\n" + +#: src/video_out/video_out_xxmc.c:2663 +msgid "Don't use bob deinterlacing for progressive frames." +msgstr "İlerleyen kareler için bob dönüştürmeyi kullanmayın." + +#: src/video_out/video_out_xxmc.c:2664 +msgid "" +"Progressive frames don't need deinterlacing, so disabling it on\n" +"demand should result in a better picture.\n" +msgstr "" +"İlerleyen karelerin dönüştürmeye ihtiyaçları yoktur, bu yüzden onu devre dışı bırakmak\n" +"daha iyi bir görüntü elde etmenizi saÄŸlayabilir.\n" + +#: src/video_out/video_out_xxmc.c:2670 +msgid "Don't use bob deinterlacing while a scaled OSD is active." +msgstr "Ayarlanmış OSD etkin olduÄŸunda bob dönüştürmesini kullanmayın." + +#: src/video_out/video_out_xxmc.c:2671 +msgid "" +"Bob deinterlacing adds some noise to horizontal lines, so disabling it\n" +"on demand should result in a better OSD picture.\n" +msgstr "" +"Bob geri dönüştürme yatay çizgilere bazı gürültüler ekler, bu durumda\n" +"onu devre dışı bırakırsanız daha iyi bir OSD resmi elde edebilirsiniz.\n" + +#: src/video_out/x11osd.c:274 src/video_out/xcbosd.c:268 +msgid "x11osd: XShape extension not available. unscaled overlay disabled.\n" +msgstr "x11osd: XShape uzantısı uygun deÄŸildir. ayarlanmamış üstyazım devre dışı bırakıldı.\n" + +#: src/video_out/x11osd.c:287 src/video_out/xcbosd.c:281 +msgid "x11osd: error creating window. unscaled overlay disabled.\n" +msgstr "x11osd: pencere oluÅŸturmakta hata, ayarlanmamış üstyazım devre dışı bırakıldı.\n" + +#: src/video_out/x11osd.c:295 src/video_out/x11osd.c:336 +#: src/video_out/xcbosd.c:291 +msgid "x11osd: error creating pixmap. unscaled overlay disabled.\n" +msgstr "x11osd: piksel harıtası oluÅŸturmada hata. ayarlanmamış üstyazım devre dışı bırakıldı.\n" + +#: src/video_out/x11osd.c:346 src/video_out/xcbosd.c:330 +#, c-format +msgid "x11osd: unscaled overlay created (%s mode).\n" +msgstr "x11osd: ayarlanmamış üstyazım oluÅŸturuldu (%s kipi).\n" + +#: src/xine-engine/alphablend.c:2146 +msgid "disable exact alpha blending of overlays" +msgstr "üstyazımların tam alfa karışımını devre dışı bırak" + +#: src/xine-engine/alphablend.c:2147 +msgid "" +"If you experience a performance impact when an On Screen Display or other " +"overlays like DVD subtitles are active, then you might want to enable this " +"option.\n" +"The result is that alpha blending of overlays is less accurate than before, " +"but the CPU usage will be decreased as well." +msgstr "" +"EÄŸer Ekran Ayarları veya DVD altyazıları gibi üstyazımlar etkin olup da bir performans kaybı yaÅŸarsanız, bu seçeneÄŸi etkinleÅŸtirmek isteyebilirsiniz.\n" +"Sonuç olarak, üstyazımların alfa karışımı eskisine oranla daha iyidir fakat iÅŸlemci kullanımı da buna baÄŸlı olarak azalmıştır." + +#: src/xine-engine/audio_decoder.c:365 +#, c-format +msgid "audio_decoder: no plugin available to handle '%s'\n" +msgstr "audio_decoder: kullanılacak bir eklenti yok '%s'\n" + +#: src/xine-engine/audio_decoder.c:382 +#, c-format +msgid "audio_decoder: error, unknown buffer type: %08x\n" +msgstr "audio_decoder: hata, bilinmeyen ön bellek türü: %08x\n" + +#: src/xine-engine/audio_decoder.c:484 +msgid "number of audio buffers" +msgstr "ses ön belleklerinin sayısı" + +#: src/xine-engine/audio_decoder.c:485 +msgid "" +"The number of audio buffers (each is 8k in size) xine uses in its internal " +"queue. Higher values mean smoother playback for unreliable inputs, but also " +"increased latency and memory consumption." +msgstr "Ses ön belleklerinin sayısı (her biri 8k büyüklüğünde) kendi iç kuyruÄŸunu kullanır. Daha yüksek deÄŸerler uyumsuz giriÅŸler için daha düz bir çalma sonucu doÄŸuracağı anlamına gelir, fakat aynı zamanda da gecikme ve bellek tüketiminin artması anlamına da gelir." + +#: src/xine-engine/audio_out.c:1109 +msgid "audio_out: delay calculation impossible with an unavailable audio device\n" +msgstr "audio_out: uyumsuz ses aygıtıyla gecikme hesaplaması yapmak olanaksızdır.\n" + +#: src/xine-engine/audio_out.c:1248 +msgid "write to sound card failed. Assuming the device was unplugged.\n" +msgstr "ses kartına yazma baÅŸarılamadı. Aygıtın baÄŸlı olmadığı varsayılıyor.\n" + +#: src/xine-engine/audio_out.c:1420 +msgid "8 bits not supported by driver, converting to 16 bits.\n" +msgstr "8 bit sürücü tarafından desteklenmiyor, onu 16 bit'e çeviriyor.\n" + +#: src/xine-engine/audio_out.c:1428 +msgid "mono not supported by driver, converting to stereo.\n" +msgstr "mono sürücü tarafından desteklenmiyor, stereo'ya dönüştürülüyor.\n" + +#: src/xine-engine/audio_out.c:1434 +msgid "stereo not supported by driver, converting to mono.\n" +msgstr "stereo sürücü tarafından desteklenmiyor, mono'ya dönüştürülüyor.\n" + +#: src/xine-engine/audio_out.c:2093 +msgid "method to sync audio and video" +msgstr "ses ve görüntü arasındaki senkronu saÄŸlama yöntemi" + +#: src/xine-engine/audio_out.c:2094 +msgid "" +"When playing audio and video, there are at least two clocks involved: The " +"system clock, to which video frames are synchronized and the clock in your " +"sound hardware, which determines the speed of the audio playback. These " +"clocks are never ticking at the same speed except for some rare cases where " +"they are physically identical. In general, the two clocks will run drift " +"after some time, for which xine offers two ways to keep audio and video " +"synchronized:\n" +"\n" +"metronom feedback\n" +"This is the standard method, which applies a countereffecting video drift, " +"as soon as the audio drift has accumulated over a threshold.\n" +"\n" +"resample\n" +"For some video hardware, which is limited to a fixed frame rate (like the " +"DXR3 or other decoder cards) the above does not work, because the video " +"cannot drift. Therefore we resample the audio stream to make it longer or " +"shorter to compensate the audio drift error. This does not work for digital " +"passthrough, where audio data is passed to an external decoder in digital " +"form." +msgstr "" +"Ses ve video çalarken, en az iki saat çalışmaktadır: Sistem saati, görüntü karelerinin senkronize olduÄŸu ve ses çalımının hızını belirleyen ses donanımındaki saat. Bu saatler, hiç bir zaman aynı hızda çalışmazlar, bazı fiziksel koÅŸullar haricinde. Genel olarak, bir süre sonra iki saat kendi baÅŸlarına çalışmaya baÅŸlayacaktır, xine bu durumda ses ve görüntü arasındaki senkronizasyonu saÄŸlamak için iki yol önerecektir:\n" +"\n" +"metronom geri bildirimi\n" +"bu görüntü sürüklenmesinin etkisini azaltırken, bir yandan da ses sürklenmesini bir sınıra dayayan standart bir yoldur,\n" +"\n" +"yeniden örnekleme\\ " +"SabitlenmiÅŸ kare oranlarında sahip (DXR3 veya diÄŸer kod çözücü kartlar gibi) bazı görüntü donanımları için yukarıdaki çözüm bir iÅŸe yaramaz, çünkü görüntü hareket edemez. Bu yüzden, ses hareket hatasını dengelemek için onu kısaltıp uzatarak ses akışını yeniden örnekleriz. Bu, ses verisinin harici kod çözücü aracılığıyla sayısal biçimlere dönüştürülen sayısal ürünlerde iÅŸe yaramaz." + +#: src/xine-engine/audio_out.c:2122 +msgid "enable resampling" +msgstr "yeniden örneklemeyi etkinleÅŸtir " + +#: src/xine-engine/audio_out.c:2123 +msgid "" +"When the sample rate of the decoded audio does not match the capabilities of " +"your sound hardware, an adaptation called \"resampling\" is required. Here " +"you can select, whether resampling is enabled, disabled or used " +"automatically when necessary." +msgstr "Kodlanmış sesin örnekleme oranı ses donanımınızın olanaklarına uymuyorsa, bu noktada \"yeniden örnekleme\" yapmak gereklidir. Burada, yeniden örneklemenin devrede olması veya olmamasını ya da gerektiÄŸinde otomatik olarak devreye girip girmeyeceÄŸini siz seçebilirsiniz." + +#: src/xine-engine/audio_out.c:2130 +msgid "always resample to this rate (0 to disable)" +msgstr "daima bu orada yeniden örnekle (devre dışı için 0)" + +#: src/xine-engine/audio_out.c:2131 +msgid "" +"Some audio drivers do not correctly announce the capabilities of the audio " +"hardware. By setting a value other than zero here, you can force the audio " +"stream to be resampled to the given rate." +msgstr "Bazı ses sürücüleri, o ses donanımının olanaklarını tam olarak bildiremezler. DeÄŸeri burada sıfırdan baÅŸka bir yere ayarlayarak, ses akışının verilmiÅŸ orana yeniden örneklenmesini saÄŸlayabilirsiniz." + +#: src/xine-engine/audio_out.c:2140 +msgid "offset for digital passthrough" +msgstr "sayısal dönüşüm için eÅŸitleme" + +#: src/xine-engine/audio_out.c:2141 +msgid "" +"If you use an external surround decoder and audio is ahead or behind video, " +"you can enter a fixed offset here to compensate.\n" +"The unit of the value is one PTS tick, which is the 90000th part of a second." +msgstr "" +"EÄŸer harici bir surround kod çözücü kullanırsanız ve ses görüntünün önünde veya gerisinde ise, dengelemek için buraya sabit bir deÄŸer girebilirsiniz.\n" +"DeÄŸerin birimi bir PTS tıklamasıdır, ki bu da saniyenin 90000de biridir." + +#: src/xine-engine/audio_out.c:2150 +msgid "play audio even on slow/fast speeds" +msgstr "sesi eÅŸit olarak yavaÅŸ/hızlı hızlarında çal" + +#: src/xine-engine/audio_out.c:2151 +msgid "" +"If you enable this option, the audio will be heard even when playback speed " +"is different than 1X. Of course, it will sound distorted (lower/higher " +"pitch). If want to experiment preserving the pitch you may try the 'stretch' " +"audio post plugin instead." +msgstr "Bu seçeneÄŸi devreye sokarsanız, çalma hızı bir mislinden hızlı olsa bile ses eÅŸit duyulacaktır. DoÄŸal olarak, ses bozulmuÅŸ gelecektir (düşük/yüksek ses hızında). Ses bölgesini korumak isterseniz, ses .. eklentisini uzatmayı denemek için deneyebilirsiniz." + +#: src/xine-engine/audio_out.c:2224 +msgid "startup audio volume" +msgstr "baÅŸlangıç ses düzeyi" + +#: src/xine-engine/audio_out.c:2225 +msgid "The overall audio volume set at xine startup." +msgstr "Xine baÅŸladığında duyulacak olan ayrıntılı ses gürlüğü ayarı." + +#: src/xine-engine/audio_out.c:2228 +msgid "restore volume level at startup" +msgstr "baÅŸlangıçtaki ses seviyesini yeniden yapılandır" + +#: src/xine-engine/audio_out.c:2229 +msgid "If disabled, xine will not modify any mixer settings at startup." +msgstr "eÄŸer etkin deÄŸilse, xine baÅŸlangıçta herhangi bir karşıtırıcı ayarı yapmayacaktır." + +#: src/xine-engine/audio_out.c:2259 +msgid "audio_out: sorry, this should not happen. please restart xine.\n" +msgstr "audio_out: üzgünüm, bu olay yaÅŸanmamalıydı, lütfen xine uygulamasını baÅŸtan baÅŸlatın.\n" + +#: src/xine-engine/buffer.c:64 +#, c-format +msgid "xine-lib: buffer.c: There has been a fatal error: TOO MANY FREE's\n" +msgstr "xine-lib: buffer.c: Sonlandırıcı bir hata var: TOO MANY FREE's\n" + +#: src/xine-engine/configfile.c:933 +#, c-format +msgid "The current config file has been modified by a newer version of xine." +msgstr "Åžu anki yapılandırma dosyası xine'nin daha yeni bir uygulaması tarafından deÄŸiÅŸtirilmiÅŸ durumdadır." + +#: src/xine-engine/configfile.c:1038 +#, c-format +msgid "configfile: WARNING: backing up configfile to %s failed\n" +msgstr "configfile: UYARI: configfile dosyasının ÅŸuraya %s yedeklenmesi baÅŸarılamadı\n" + +#: src/xine-engine/configfile.c:1039 +msgid "configfile: WARNING: your configuration will not be saved\n" +msgstr "configfile: UYARI: yapılandırmanız kaydedilmeyecektir\n" + +#: src/xine-engine/configfile.c:1138 +#, c-format +msgid "configfile: WARNING: writing configuration to %s failed\n" +msgstr "configfile: UYARI: yapılandırmanın ÅŸuraya %s yazılması baÅŸarılamadı\n" + +#: src/xine-engine/configfile.c:1139 +#, c-format +msgid "configfile: WARNING: removing possibly broken config file %s\n" +msgstr "configfile: UYARI: büyük ihtimaller bozulmuÅŸ olan yapılandırma dosyasını kaldırıyor %s\n" + +#: src/xine-engine/configfile.c:1140 +#, c-format +msgid "configfile: WARNING: you should check the backup file %s\n" +msgstr "configfile: UYARI: yedekleme dosyasını denetlemelisiniz %s\n" + +#: src/xine-engine/configfile.c:1275 +#, c-format +msgid "configfile: entry '%s' mustn't be modified from MRL\n" +msgstr "configfile: girdi '%s' MRL tarafından deÄŸiÅŸtirilmiÅŸ olmamalı\n" + +#: src/xine-engine/info_helper.c:228 +msgid "info_helper: can't find out current locale character set\n" +msgstr "info_helper: ÅŸu anki yerel karakter ayarını çözümleyemez\n" + +#: src/xine-engine/info_helper.c:242 +#, c-format +msgid "info_helper: unsupported conversion %s -> UTF-8, no conversion performed\n" +msgstr "info_helper: desteklenmeyen dönüşüm %s -> UTF-8, hiç bir dönüşüm gerçekleÅŸmedi\n" + +#: src/xine-engine/input_cache.c:170 +#, c-format +msgid ": open() function should never be called\n" +msgstr ": open() fonksiyonu asla çaÄŸrılamaz\n" + +#: src/xine-engine/input_cache.c:353 +#, c-format +msgid ": input plugin not defined!\n" +msgstr ": girdi eklentisi tanımlanmadı!\n" + +#: src/xine-engine/input_rip.c:138 src/xine-engine/input_rip.c:258 +#, c-format +msgid "input_rip: reading of saved data failed: %s\n" +msgstr "input_rip: kaydedilen veriyi okuma hatası: %s\n" + +#: src/xine-engine/input_rip.c:153 +#, c-format +msgid "input_rip: reading by input plugin failed\n" +msgstr "input_rip: giriÅŸ eklentisini okuma hatası\n" + +#: src/xine-engine/input_rip.c:161 src/xine-engine/input_rip.c:290 +#: src/xine-engine/input_rip.c:656 +#, c-format +msgid "input_rip: error writing to file % bytes: %s\n" +msgstr "input_rip: dosyaya yazmada hata % byte: %s\n" + +#: src/xine-engine/input_rip.c:182 +#, c-format +msgid "input_rip: open() function should never be called\n" +msgstr "input_rip: open() fonksiyonu asla çaÄŸrılamaz\n" + +#: src/xine-engine/input_rip.c:313 src/xine-engine/input_rip.c:418 +#, c-format +msgid "input_rip: seeking failed\n" +msgstr "input_rip: aramada hata\n" + +#: src/xine-engine/input_rip.c:370 src/xine-engine/input_rip.c:388 +#, c-format +msgid "input_rip: seeking failed: %s\n" +msgstr "input_rip: aramada hata: %s\n" + +#: src/xine-engine/input_rip.c:396 +#, c-format +msgid "input_rip: % bytes dropped\n" +msgstr "input_rip: % byte iptal edildi\n" + +#: src/xine-engine/input_rip.c:561 +#, c-format +msgid "input_rip: input plugin not defined!\n" +msgstr "input_rip: giriÅŸ eklentisi belirtilmedi!\n" + +#: src/xine-engine/input_rip.c:567 +#, c-format +msgid "" +"input_rip: target directory wasn't specified, please fill out the option " +"'media.capture.save_dir'\n" +msgstr "" +"input_rip: hedef dizin belirtilmedi, lütfen " +"'media.capture.save_dir' seçeneÄŸini yayınız\n" + +#: src/xine-engine/input_rip.c:569 +msgid "" +"The stream save feature is disabled until you set media.capture.save_dir in " +"the configuration." +msgstr "Yapılandırmada siz media.capture.save_dir ayarını yapana kadar, yayın akışını kaydet seçeneÄŸi devre dışı bırakıldı." + +#: src/xine-engine/input_rip.c:576 +#, c-format +msgid "input_rip: ripping/caching of this source is not permitted!\n" +msgstr "input_rip: bu kaynağın açılması/belleÄŸe alınmasına izin verilmedi!\n" + +#: src/xine-engine/input_rip.c:578 +msgid "" +"xine is not allowed to save from this source. (possibly copyrighted " +"material?)" +msgstr "xine bu kaynaktan kaydedilmesine izin vermedi. (bir ihtimal telif hakları ile korunmuÅŸ malzeme?)" + +#: src/xine-engine/input_rip.c:584 +#, c-format +msgid "input_rip: file name not given!\n" +msgstr "input_rip: dosya adı verilmemiÅŸ!\n" + +#: src/xine-engine/input_rip.c:626 +#, c-format +msgid "input_rip: error opening file %s: %s\n" +msgstr "input_rip: %s dosyası açılırken hata oluÅŸtu: %s\n" + +#: src/xine-engine/io_helper.c:252 +#, c-format +msgid "io_helper: waiting abandoned\n" +msgstr "io_helper: bekleme bırakıldı\n" + +#: src/xine-engine/io_helper.c:259 +#, c-format +msgid "io_helper: waiting failed: %s\n" +msgstr "io_helper: bekleme baÅŸarısız oldu: %s\n" + +#: src/xine-engine/io_helper.c:314 +msgid "failed to get status of socket" +msgstr "soket durumu alınamadı" + +#: src/xine-engine/io_helper.c:388 +#, c-format +msgid "io_helper: Permission denied\n" +msgstr "io_helper: İzin verilmedi\n" + +#: src/xine-engine/io_helper.c:392 +#, c-format +msgid "io_helper: File not found\n" +msgstr "io_helper: Dosya bulunamadı\n" + +#: src/xine-engine/io_helper.c:396 +#, c-format +msgid "io_helper: Connection Refused\n" +msgstr "io_helper: BaÄŸlantı Reddedildi\n" + +#: src/xine-engine/load_plugins.c:208 +#, c-format +msgid "map_decoder_list: no space for decoder, skipped.\n" +msgstr "map_decoder_list: kod çözücü için yer yok, atlandı.\n" + +#: src/xine-engine/load_plugins.c:323 +#, c-format +msgid "load_plugins: ignoring plugin %s, wrong iface version %d (should be %d)\n" +msgstr "load_plugins: eklentileri göz ardı ediyor %s, yanlış iface sürümü %d (olması gereken %d)\n" + +#: src/xine-engine/load_plugins.c:380 +#, c-format +msgid "priority for %s decoder" +msgstr "%s kod çözücü için öncelik" + +#: src/xine-engine/load_plugins.c:391 +msgid "" +"The priority provides a ranking in case some media can be handled by more " +"than one decoder.\n" +"A priority of 0 enables the decoder's default priority." +msgstr "" +"Öncelik bazı ortamların diÄŸerlerine göre birden fazla kod çözücü ile uÄŸraÅŸacağı göz önüne alınarak sınıflandırılır.\n" +"0 önceliÄŸi kod çözücünün öntanımlı önceliÄŸini ektinleÅŸtirir." + +#: src/xine-engine/load_plugins.c:419 +#, c-format +msgid "" +"load_plugins: demuxer plugin %s does not provide a priority, xine-lib will " +"use the default priority.\n" +msgstr "load_plugins: demuxer eklentisi %s öncelik saÄŸlamaz, xine-lib öntanımlı önceliÄŸi kullanacak.\n" + +#: src/xine-engine/load_plugins.c:436 +#, c-format +msgid "" +"load_plugins: input plugin %s does not provide a priority, xine-lib will use " +"the default priority.\n" +msgstr "load_plugins: giriÅŸ eklentisi %s öncelik saÄŸlamaz, xine-lib öntanımlı önceliÄŸi kullanacak.\n" + +#: src/xine-engine/load_plugins.c:492 +#, c-format +msgid "load_plugins: plugin %s found\n" +msgstr "load_plugins: %s eklentisi bulundu\n" + +#: src/xine-engine/load_plugins.c:495 +#, c-format +msgid "load_plugins: static plugin found\n" +msgstr "load_plugins: sabit eklenti bulundu\n" + +#: src/xine-engine/load_plugins.c:502 +#, c-format +msgid "load_plugins: plugin limit reached, %s could not be loaded\n" +msgstr "load_plugins: eklenti sınırına ulaşıldı, %s yüklenemez\n" + +#: src/xine-engine/load_plugins.c:505 +#, c-format +msgid "load_plugins: plugin limit reached, static plugin could not be loaded\n" +msgstr "load_plugins: eklenti sınırına ulaşıldı, statik eklenti yüklenemez\n" + +#: src/xine-engine/load_plugins.c:522 +#, c-format +msgid "load_plugins: unknown plugin type %d in %s\n" +msgstr "load_plugins: bilinmeyen eklenti türü %d in %s\n" + +#: src/xine-engine/load_plugins.c:526 +#, c-format +msgid "load_plugins: unknown statically linked plugin type %d\n" +msgstr "load_plugins: bilinmeyen statik baÄŸlantılı eklenti türü %d\n" + +#: src/xine-engine/load_plugins.c:586 +#, c-format +msgid "load_plugins: unable to stat %s\n" +msgstr "load_plugins: stat yapamaz %s\n" + +#: src/xine-engine/load_plugins.c:627 +#, c-format +msgid "" +"load_plugins: cannot open plugin lib %s:\n" +"%s\n" +msgstr "" +"load_plugins: eklenti kütüphanesini açamıyor %s:\n" +"%s\n" + +#: src/xine-engine/load_plugins.c:642 +#, c-format +msgid "" +"load_plugins: can't get plugin info from %s:\n" +"%s\n" +msgstr "" +"load_plugins: ekleni bilgisini ÅŸuradan alabilir %s:\n" +"%s\n" + +#: src/xine-engine/load_plugins.c:660 +#, c-format +msgid "load_plugins: skipping unreadable plugin directory %s.\n" +msgstr "load_plugins: okunamayan eklenti dizinini atlıyor %s.\n" + +#: src/xine-engine/load_plugins.c:709 +#, c-format +msgid "" +"load_plugins: cannot (stage 2) open plugin lib %s:\n" +"%s\n" +msgstr "" +"load_plugins: eklenti (aÅŸama 2) eklenti kütüphanesini açamıyor %s:\n" +"%s\n" + +#: src/xine-engine/load_plugins.c:735 +#, c-format +msgid "load_plugins: Yikes! %s doesn't contain plugin info.\n" +msgstr "load_plugins: Aman! %s eklenti bilgisi yok.\n" + +#: src/xine-engine/load_plugins.c:1301 +#, c-format +msgid "load_plugins: unknown content detection strategy %d\n" +msgstr "load_plugins: bilinmeyen içerik bulma yöntemi %d\n" + +#: src/xine-engine/load_plugins.c:1411 +#, c-format +msgid "load_plugins: using demuxer '%s'\n" +msgstr "load_plugins: demuxer eklentisini kullanıyor '%s'\n" + +#: src/xine-engine/load_plugins.c:1707 src/xine-engine/load_plugins.c:1754 +#, c-format +msgid "load_plugins: failed to load audio output plugin <%s>\n" +msgstr "load_plugins: ses çıkış eklentisini yüklemede hata <%s>\n" + +#: src/xine-engine/load_plugins.c:1757 +msgid "" +"load_plugins: audio output auto-probing didn't find any usable audio " +"driver.\n" +msgstr "" +"load_plugins: ses çıktısı otomatik bulma iÅŸlemi kullanılabilir bir sürücü " +"bulamadı.\n" + +#: src/xine-engine/load_plugins.c:2061 +#, c-format +msgid "" +"load_plugins: cannot unload plugin lib %s:\n" +"%s\n" +msgstr "" +"load_plugins: eklenti kütüphanesi %s kaldırılamadı:\n" +"%s\n" + +#: src/xine-engine/osd.c:735 +#, c-format +msgid "font '%s-%d' already loaded, weird.\n" +msgstr "'%s-%d' yazı tipi zaten yüklü.\n" + +#: src/xine-engine/osd.c:747 +#, c-format +msgid "font '%s' loading failed (%d < %d)\n" +msgstr "'%s' yazı tipi yüklenemedi (%d < %d)\n" + +#: src/xine-engine/osd.c:757 +#, c-format +msgid "wrong version for font '%s'. expected %d found %d.\n" +msgstr "'%s' yazı tipi için yanlış sürüm. beklenen %d bulunan %d.\n" + +#: src/xine-engine/osd.c:824 +msgid "osd: cannot initialize ft2 library\n" +msgstr "osd: ft2 kütüphanesi baÅŸlatılamadı\n" + +#: src/xine-engine/osd.c:847 +#, c-format +msgid "osd: error matching font %s with FontConfig" +msgstr "osd: %s yazı tipi FontConfig ile eÅŸlenirken hata oluÅŸtu" + +#: src/xine-engine/osd.c:861 +#, c-format +msgid "osd: error loading font %s with FontConfig" +msgstr "osd: %s yazı tipi FontConfig ile yüklenirken hata oluÅŸtu" + +#: src/xine-engine/osd.c:864 +#, c-format +msgid "osd: error looking up font %s with FontConfig" +msgstr "osd: %s yazı tipine FontConfig ile bakılırken hata oluÅŸtu" + +#: src/xine-engine/osd.c:885 +#, c-format +msgid "osd: error loading font %s with ft2\n" +msgstr "osd: %s yazı tipi ft2 ile yüklenirken hata oluÅŸtu\n" + +#: src/xine-engine/osd.c:895 +msgid "osd: error setting font size (no scalable font?)\n" +msgstr "osd: yazı tipi boyutu ayarlama hatası (boyutlandırılabilir yazı tipi yok mudur?)\n" + +#: src/xine-engine/osd.c:1011 +#, c-format +msgid "" +"osd: unknown sequence starting with byte 0x%02X in encoding \"%s\", " +"skipping\n" +msgstr "" +"osd: 0x%02X ile baÅŸlayan ve \"%s\" kodlamasında bulunan bilinmeyen sıralama, " +"atlanıyor\n" + +#: src/xine-engine/osd.c:1067 +msgid "osd: can't find out current locale character set\n" +msgstr "osd: yerel karakter seti anlaşılamadı\n" + +#: src/xine-engine/osd.c:1077 +#, c-format +msgid "osd: unsupported conversion %s -> %s, no conversion performed\n" +msgstr "osd: desteklenmeyen dönüşüm %s -> %s, dönüşüm yapılmadı\n" + +#: src/xine-engine/osd.c:1132 src/xine-engine/osd.c:1300 +msgid "osd: font isn't defined\n" +msgstr "osd: yazı tipi belirtilmedi\n" + +#: src/xine-engine/osd.c:1171 +msgid "osd: error loading glyph\n" +msgstr "osd: glyph yüklenirken hata oluÅŸtu\n" + +#: src/xine-engine/osd.c:1177 +msgid "osd: error in rendering glyph\n" +msgstr "osd: glyph hazırlanırken hata oluÅŸtu\n" + +#: src/xine-engine/osd.c:1337 +#, c-format +msgid "osd: error loading glyph %i\n" +msgstr "osd: glyph %i yüklenirken hata oluÅŸtu\n" + +#: src/xine-engine/osd.c:1344 +msgid "osd: error in rendering\n" +msgstr "osd: hazırlama hatası\n" + +#: src/xine-engine/osd.c:1601 +msgid "palette (foreground-border-background) to use for subtitles and OSD" +msgstr "Altyazılar ve OSD için kullanılacak palet (ön yüz-sınır-arka plan)" + +#: src/xine-engine/osd.c:1602 +msgid "" +"The palette for on-screen-display and some subtitle formats that do not " +"specify any colouring themselves. The palettes are listed in the form: " +"foreground-border-background." +msgstr "" +"Ekranda görüntülemek için palet ve bazı altyazı kipleri kendi renklendirmelerini belirlemezler. Paletler formda listelenmiÅŸtir: " +"ün yüz-sınır-arka plan." + +#: src/xine-engine/video_decoder.c:377 +#, c-format +msgid "video_decoder: no plugin available to handle '%s'\n" +msgstr "video_decoder: '%s' dosyasını iÅŸleyebilmek için uygun eklenti yok\n" + +#: src/xine-engine/video_decoder.c:456 +#, c-format +msgid "video_decoder: error, unknown buffer type: %08x\n" +msgstr "video_decoder: hata, bilinmeyen tampon bellek türü: %08x\n" + +#: src/xine-engine/video_decoder.c:492 +msgid "number of video buffers" +msgstr "video tamponlarının sayısı" + +#: src/xine-engine/video_decoder.c:493 +msgid "" +"The number of video buffers (each is 8k in size) xine uses in its internal " +"queue. Higher values mean smoother playback for unreliable inputs, but also " +"increased latency and memory consumption." +msgstr "Video tamponlarının sayısı (her biri 8k büyüklüğünde) kendi iç kuyruÄŸunu kullanır. Daha yüksek deÄŸerler uyumsuz giriÅŸler için daha düz bir çalma sonucu doÄŸuracağı anlamına gelir, fakat aynı zamanda da gecikme ve bellek tüketiminin artması anlamına da gelir." + +#: src/xine-engine/video_out.c:640 +#, c-format +msgid "%d frames delivered, %d frames skipped, %d frames discarded\n" +msgstr "%d kare alındı, %d kare atlandı, %d kare atıldı\n" + +#: src/xine-engine/video_out.c:813 +#, c-format +msgid "" +"video_out: throwing away image with pts % because it's too old " +"(diff : %).\n" +msgstr "" +"video_out: resmi pts ile atıyor % çünkü çok eski " +"(diff : %).\n" + +#: src/xine-engine/video_out.c:1793 +msgid "default number of video frames" +msgstr "video çerçevelerinin öntanımlı sayısı" + +#: src/xine-engine/video_out.c:1794 +msgid "" +"The default number of video frames to request from xine video out driver. " +"Some drivers will override this setting with their own values." +msgstr "Xine video çıkış sürücüsünden istenecek olan video çerçevelerinin öntanımlı sayısı. Bazı sürücüler kendi deÄŸerlerini koruyarak bu ayara önem vermeyecektir." + +#: src/xine-engine/video_out.c:1833 +msgid "percentage of skipped frames to tolerate" +msgstr "görmezden gelinecek atlanan çerçeve sayısı" + +#: src/xine-engine/video_out.c:1834 +msgid "" +"When more than this percentage of frames are not shown, because they were " +"not decoded in time, xine sends a notification." +msgstr "Bu çerçeve oranlarından daha fazlası gösterilmezse, zamanında kodlanmadıklarındandır, xine bir uyarı gönderir." + +#: src/xine-engine/video_out.c:1839 +msgid "percentage of discarded frames to tolerate" +msgstr "görmezden gelinecek yoksayılan çerçeve sayısı" + +#: src/xine-engine/video_out.c:1840 +msgid "" +"When more than this percentage of frames are not shown, because they were " +"not scheduled for display in time, xine sends a notification." +msgstr "Bu çerçeve oranlarından daha fazlası gösterilmezse, zamanında görüntülenmeleri için programlanmadıklarındandır, xine bir uyarı gönderir." + +#: src/xine-engine/video_out.c:1874 +msgid "video_out: sorry, this should not happen. please restart xine.\n" +msgstr "video_out: üzgünüm, bu olmamalıydı. lütfen xine uygulamasını yeniden baÅŸlatın.\n" + +#: src/xine-engine/vo_scale.c:387 +msgid "horizontal image position in the output window" +msgstr "çıktı penceresindeki yatay resim konumu" + +#: src/xine-engine/vo_scale.c:388 +msgid "" +"If the video window's horizontal size is bigger than the actual image to " +"show, you can adjust the position where the image will be placed.\n" +"The position is given as a percentage, so a value of 50 means \"in the middle" +"\", while 0 means \"at the very left\" and 100 \"at the very right\"." +msgstr "" +"EÄŸer video penceresinin yatay boyutu olması gerekenden büyükse, görüntünün yerleÅŸeceÄŸi konumu ayarlayabilirsiniz.\n" +"Konum yüzdesel olarak verilmiÅŸtir, böylece 50 deÄŸeri \"ortada\", 0 deÄŸeri \"çok solda\" ve 100 deÄŸeri \"çok saÄŸda\" anlamına gelecektir." + +#: src/xine-engine/vo_scale.c:395 +msgid "vertical image position in the output window" +msgstr "çıktı penceresindeki dikey resim konumu" + +#: src/xine-engine/vo_scale.c:396 +msgid "" +"If the video window's vertical size is bigger than the actual image to show, " +"you can adjust the position where the image will be placed.\n" +"The position is given as a percentage, so a value of 50 means \"in the middle" +"\", while 0 means \"at the top\" and 100 \"at the bottom\"." +msgstr "" +"EÄŸer video penceresinin yatay boyutu olması gerekenden büyükse, görüntünün yerleÅŸeceÄŸi konumu ayarlayabilirsiniz.\n" +"Konum yüzdesel olarak verilmiÅŸtir, böylece 50 deÄŸeri \"ortada\", 0 deÄŸeri \"yukarıda\" ve 100 deÄŸeri \"aÅŸağıda\" anlamına gelecektir." + +#: src/xine-engine/vo_scale.c:403 +msgid "disable all video scaling" +msgstr "tüm video ölçeklemelerini pasifleÅŸtir" + +#: src/xine-engine/vo_scale.c:404 +msgid "" +"If you want the video image to be always shown at its original resolution, " +"you can disable all image scaling here.\n" +"This of course means that the image will no longer adapt to the size of the " +"video window and that videos with a pixel aspect ratio other than 1:1, like " +"anamorphic DVDs, will be shown distorted. But on the other hand, with some " +"video output drivers like XShm, where the image scaling is not hardware " +"accelerated, this can dramatically reduce CPU usage." +msgstr "" +"EÄŸer video görüntüsünün daima kendi orijinal çözünürlüğünde gösterilmesini istiyorsanız, buradaki tüm resim ölçeklemelerini devre dışı bırakabilirsiniz.\n" +"Bu doÄŸal olarak anamorfik DVD'ler gibi 1:1 ölçeÄŸinden farklı özelliklerde olduÄŸu gibi görüntü video penceresinin boyutuyla uyumlu olamayabilecek ve görüntüde bozukluklar meydana gelebilecektir. Fakat diÄŸer taraftan, XShm gibi bazı video sürücülerinin resim ölçeklemesi donanım hızlandırmalı olmadığı için, bu iÅŸlemci kullanımını dramatik olarak azaltacaktır." + +#: src/xine-engine/xine.c:789 src/xine-engine/xine.c:896 +#: src/xine-engine/xine.c:935 src/xine-engine/xine.c:971 +#: src/xine-engine/xine.c:983 src/xine-engine/xine.c:996 +#: src/xine-engine/xine.c:1009 src/xine-engine/xine.c:1022 +#: src/xine-engine/xine.c:1048 src/xine-engine/xine.c:1073 +#: src/xine-engine/xine.c:1108 +msgid "xine: error while parsing mrl\n" +msgstr "xine: mrl ayrıştırma hatası\n" + +#: src/xine-engine/xine.c:831 +#, c-format +msgid "xine: found input plugin : %s\n" +msgstr "xine: bulunan girdi eklentisi : %s\n" + +#: src/xine-engine/xine.c:848 +#, c-format +msgid "xine: input plugin cannot open MRL [%s]\n" +msgstr "xine: girdi eklentisi MRL [%s] dosyasını açamadı\n" + +#: src/xine-engine/xine.c:859 +#, c-format +msgid "xine: cannot find input plugin for MRL [%s]\n" +msgstr "xine: MRL [%s] için girdi eklentisi bulunamadı\n" + +#: src/xine-engine/xine.c:885 +#, c-format +msgid "xine: specified demuxer %s failed to start\n" +msgstr "xine: belirlenmiÅŸ demuxer %s baÅŸlatılamadı\n" + +#: src/xine-engine/xine.c:921 +#, c-format +msgid "xine: join rip input plugin\n" +msgstr "xine: hızlı giriÅŸ eklentisini ekle\n" + +#: src/xine-engine/xine.c:928 +msgid "xine: error opening rip input plugin instance\n" +msgstr "xine: hızlı giriÅŸ eklentisini açmada hata\n" + +#: src/xine-engine/xine.c:959 +#, c-format +msgid "xine: last_probed demuxer %s failed to start\n" +msgstr "xine: en son_kullanılan demuxer %s baÅŸlatılamadı\n" + +#: src/xine-engine/xine.c:988 +msgid "ignoring video\n" +msgstr "video yoksayılıyor\n" + +#: src/xine-engine/xine.c:1001 +msgid "ignoring audio\n" +msgstr "ses yoksayılıyor\n" + +#: src/xine-engine/xine.c:1014 +msgid "ignoring subpicture\n" +msgstr "altresmi göz ardı ediyor\n" + +#: src/xine-engine/xine.c:1027 +msgid "input cache plugin disabled\n" +msgstr "girdi önbellek eklentisi pasifleÅŸtirildi\n" + +#: src/xine-engine/xine.c:1098 +#, c-format +msgid "subtitle mrl opened '%s'\n" +msgstr "alt yazı mrl dosyası '%s' açıldı\n" + +#: src/xine-engine/xine.c:1102 +msgid "xine: error opening subtitle mrl\n" +msgstr "xine: alt yazı mrl dosyası açılırken hata oluÅŸtu\n" + +#: src/xine-engine/xine.c:1134 +#, c-format +msgid "xine: error while parsing MRL\n" +msgstr "xine: MRL ayrıştırılırken hata oluÅŸtu\n" + +#: src/xine-engine/xine.c:1141 +#, c-format +msgid "xine: changing option '%s' from MRL isn't permitted\n" +msgstr "xine: MRL dosyasındaki '%s' seçeneÄŸinin deÄŸiÅŸtirilmesine izin verilmiyor\n" + +#: src/xine-engine/xine.c:1161 +#, c-format +msgid "xine: couldn't find demux for >%s<\n" +msgstr "xine: demux bunun için bulunamıyor >%s<\n" + +#: src/xine-engine/xine.c:1177 +#, c-format +msgid "xine: found demuxer plugin: %s\n" +msgstr "xine: demuxer eklentisi bulundu: %s\n" + +#: src/xine-engine/xine.c:1198 +#, c-format +msgid "xine: demuxer is already done. that was fast!\n" +msgstr "xine: demuxer hazır durumda. bu hızlıydı!\n" + +#: src/xine-engine/xine.c:1200 +#, c-format +msgid "xine: demuxer failed to start\n" +msgstr "xine: demuxer baÅŸlatılamadı\n" + +#: src/xine-engine/xine.c:1266 +#, c-format +msgid "xine_play: no demux available\n" +msgstr "xine_play: hiç bir demux uygun deÄŸil\n" + +#: src/xine-engine/xine.c:1336 +#, c-format +msgid "xine_play: demux failed to start\n" +msgstr "xine_play: demux baÅŸlatılamadı\n" + +#: src/xine-engine/xine.c:1612 +#, c-format +msgid "xine: The specified save_dir \"%s\" might be a security risk.\n" +msgstr "xine: Belirtilen save_dir \"%s\" bir güvenlik riski oluÅŸturabilir.\n" + +#: src/xine-engine/xine.c:1617 +msgid "The specified save_dir might be a security risk." +msgstr "Belirtilen save_dir bir güvenlik riski oluÅŸturabilir." + +#: src/xine-engine/xine.c:1643 +msgid "xine: locale not supported by C library\n" +msgstr "xine: sistem yereliniz C kütüphanesi tarafından desteklenmiyor\n" + +#: src/xine-engine/xine.c:1652 +msgid "media format detection strategy" +msgstr "ortam biçimi belirleme yöntemi" + +#: src/xine-engine/xine.c:1653 +msgid "" +"xine offers various methods to detect the media format of input to play. The " +"individual values are:\n" +"\n" +"default\n" +"First try to detect by content, then by file name extension.\n" +"\n" +"reverse\n" +"First try to detect by file name extension, then by content.\n" +"\n" +"content\n" +"Detect by content only.\n" +"\n" +"extension\n" +"Detect by file name extension only.\n" +msgstr "" +"xine çalınacak ortam kipini tanımak için farklı yönetmler önerir. Bireysel deÄŸerler şöyledir:\n" +"\n" +"default\n" +"Önce, içerikten tanımaya, sonra da dosya uzantısıyla tanımaya çalışır.\n" +"\n" +"reverse\n" +"Önce, dosya uzantısından tanımaya, sonra da içerikten tanımaya çalışır.\n" +"\n" +"content\n" +"Sadece içerikten tanır.\n" +"\n" +"extension\n" +"Sadece dosya adı uzantısından tanır.\n" + +#: src/xine-engine/xine.c:1671 +msgid "directory for saving streams" +msgstr "yayınların kaydedileceÄŸi dizin" + +#: src/xine-engine/xine.c:1672 +msgid "" +"When using the stream save feature, files will be written only into this " +"directory.\n" +"This setting is security critical, because when changed to a different " +"directory, xine can be used to fill files in it with arbitrary content. So " +"you should be careful that the directory you specify is robust against any " +"content in any file." +msgstr "" +"Yayın akışının kaydedilmesi özelliÄŸi kullanıldığında, dosyalar sadece bu dizine yazılacaktır.\n" +"Bu ayar güvenlik açısından kritiktir, çünkü dizinin deÄŸiÅŸtirilmesi denendiÄŸinde, xine dosyaları alakasız içerikle doldurmak için kullanabilir. Bu yüzden, belirttiÄŸiniz dizinin her türlü içeriÄŸe karşı dirençli olmasına özen göstermelisiniz." + +#: src/xine-engine/xine.c:1683 +msgid "allow implicit changes to the configuration (e.g. by MRL)" +msgstr "yapılandırmada kesin deÄŸiÅŸikliklere izin ver (örn. MRL tarafından yapılan deÄŸiÅŸikliklere)" + +#: src/xine-engine/xine.c:1684 +msgid "" +"If enabled, you allow xine to change your configuration without explicit " +"actions from your side. For example configuration changes demanded by MRLs " +"or embedded into playlist will be executed.\n" +"This setting is security critcal, because xine can receive MRLs or playlists " +"from untrusted remote sources. If you allow them to arbitrarily change your " +"configuration, you might end with a totally messed up xine." +msgstr "" +"EÄŸer devrede ise, xine'nin sizin net bir katkınız olmayan deÄŸiÅŸiklikler yapmasına izin veriyorsunuz demektir. ÖrneÄŸin, MRL tarafından talep edilen deÄŸiÅŸiklikler veya çalma listesine gömülü olan istekler yerine getirilecektir.\n" +"Bu ayar, güvenlik açısından kritiktir, çünkü xine güvenilmeyen uzak kaynaklardan MRL veya çalma listelerini alabilir. EÄŸer onların yapılandırmanızı kendi istedikleri gibi deÄŸiÅŸtirmelerine izin verirseniz, xine'nin tamamen iÅŸleri berbat etmesiyle her ÅŸey sona erebilir." + +#: src/xine-engine/xine.c:1698 +msgid "Timeout for network stream reading (in seconds)" +msgstr "AÄŸ yayını okumada zaman aşımı (saniye olarak)" + +#: src/xine-engine/xine.c:1699 +msgid "" +"Specifies the timeout when reading from network streams, in seconds. Too low " +"values might stop streaming when the source is slow or the bandwidth is " +"occupied, too high values will freeze the player if the connection is lost." +msgstr "AÄŸ'dan gelen yayın akışını okurken zaman aşımını saniye bazında belirtir. EÄŸer kaynak yavaÅŸ veya bant geniÅŸliÄŸi yoÄŸun ise çok küçük deÄŸerler yayın akışını durdurabilir, çok yüksek deÄŸerler ise baÄŸlantı kesilirse çalıcının donmasına neden olabilir." + +#: src/xine-engine/xine.c:2051 +msgid "messages" +msgstr "iletiler" + +#: src/xine-engine/xine.c:2052 +msgid "plugin" +msgstr "eklenti" + +#: src/xine-engine/xine.c:2053 +msgid "trace" +msgstr "iz" + +#: src/xine-engine/xine_interface.c:955 +msgid "Warning:" +msgstr "Uyarı:" + +#: src/xine-engine/xine_interface.c:956 +msgid "Unknown host:" +msgstr "Bilinmeyen makine:" + +#: src/xine-engine/xine_interface.c:957 +msgid "Unknown device:" +msgstr "Bilinmeyen aygıt:" + +#: src/xine-engine/xine_interface.c:958 +msgid "Network unreachable" +msgstr "AÄŸ eriÅŸilebilir deÄŸil" + +#: src/xine-engine/xine_interface.c:959 +msgid "Connection refused:" +msgstr "BaÄŸlantı reddedildi:" + +#: src/xine-engine/xine_interface.c:960 +msgid "File not found:" +msgstr "Dosya bulunamadı:" + +#: src/xine-engine/xine_interface.c:961 +msgid "Read error from:" +msgstr "Okuma hatası alınan konum:" + +#: src/xine-engine/xine_interface.c:962 +msgid "Error loading library:" +msgstr "Kütüphane yükleme hatası:" + +#: src/xine-engine/xine_interface.c:963 +msgid "Encrypted media stream detected" +msgstr "ÅžifrelenmiÅŸ ortam yayını bulundu" + +#: src/xine-engine/xine_interface.c:964 +msgid "Security message:" +msgstr "Güvenlik iletisi:" + +#: src/xine-engine/xine_interface.c:965 +msgid "Audio device unavailable" +msgstr "Ses aygıtı kullanılamaz" + +#: src/xine-engine/xine_interface.c:966 +msgid "Permission error" +msgstr "Yetki hatası" + +#: src/xine-engine/xine_interface.c:967 +msgid "File is empty:" +msgstr "Dosya boÅŸ:" + +#: src/xine-utils/memcpy.c:479 +msgid "memcopy method used by xine" +msgstr "xine tarafından kullanılan memcopy metodu" + +#: src/xine-utils/memcpy.c:480 +msgid "" +"The copying of large memory blocks is one of the most expensive operations " +"on todays computers. Therefore xine provides various tuned methods to do " +"this copying. Usually, the best method is detected automatically." +msgstr "Günümüz bilgisayarlarında, büyük bellek kütlelerinin kopyalanması en pahalı iÅŸlemlerden biridir. Bu yüzden, xine bu kopyalamayı gerçekleÅŸtirmek için farklı ayarlanmış yöntemler sunar. Genellikle, en iyi yöntem otomatik olarak algılanacaktır." + +#: src/xine-utils/memcpy.c:507 +msgid "Benchmarking memcpy methods (smaller is better):\n" +msgstr "Memcpy karşılaÅŸtırma yöntemleri (daha küçük olan daha iyidir):\n" + -- cgit v1.2.3 From ee3d84362281291f081c4a2ad37542b73057d04f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Sat, 5 Jan 2008 20:37:52 +0100 Subject: Add ChangeLog entry for the translation. --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index 414092b20..6637a71c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -42,6 +42,7 @@ xine-lib (1.1.9) (unreleased) * Detect corrupted or broken seek tables in CBR MP3 files. [Bug #3] * Fixed an issue in input_pvr with setting the frequency of the tuner for ivtv versions 0.10.6+ + * Add Turkish translation by Serdar Soytetir and Server Acim. xine-lib (1.1.8) * Send a channel-changed event to the frontend when receiving the SYNC -- cgit v1.2.3 From 051c124db8a2ab27f45530323d9cbd673e277794 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sat, 5 Jan 2008 22:18:27 +0000 Subject: Enable the VMware Screen codec (ffmpeg). --- ChangeLog | 2 +- src/libffmpeg/ff_video_decoder.c | 4 ++++ src/xine-engine/buffer.h | 1 + src/xine-engine/buffer_types.c | 8 ++++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 6637a71c3..4e5b24b61 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,7 +25,7 @@ xine-lib (1.1.9) (unreleased) buffer. * DXR3 encoding with external ffmpeg should be fixed now. (This was broken by ffmpeg revision 9283). - * Enabled the WMV VC1 (ffmpeg) codec. + * Enabled the WMV VC1 & VMware Screen (ffmpeg) codecs. * Fixed a crash that happened when a video output was closed * Made the Real demuxer recognise http references. * Require correct URL encoding of '#'s which aren't separators. diff --git a/src/libffmpeg/ff_video_decoder.c b/src/libffmpeg/ff_video_decoder.c index dc1176e78..dc07abb9f 100644 --- a/src/libffmpeg/ff_video_decoder.c +++ b/src/libffmpeg/ff_video_decoder.c @@ -315,6 +315,7 @@ static const ff_codec_t ff_video_lookup[] = { {BUF_VIDEO_KMVC, CODEC_ID_KMVC, "Karl Morton's Video Codec (ffmpeg)"}, {BUF_VIDEO_FLASHSV, CODEC_ID_FLASHSV, "Flash Screen Video (ffmpeg)"}, {BUF_VIDEO_CAVS, CODEC_ID_CAVS, "Chinese AVS (ffmpeg)"}, + {BUF_VIDEO_VMNC, CODEC_ID_VMNC, "VMware Screen Codec (ffmpeg)"}, {BUF_VIDEO_THEORA_RAW, CODEC_ID_THEORA, "Theora (ffmpeg)"}, }; @@ -1855,6 +1856,9 @@ static uint32_t supported_video_types[] = { #ifdef CONFIG_CAVS_DECODER BUF_VIDEO_CAVS, #endif + #ifdef CONFIG_VMNC_DECODER + BUF_VIDEO_VMNC, + #endif BUF_VIDEO_THEORA_RAW, 0 }; diff --git a/src/xine-engine/buffer.h b/src/xine-engine/buffer.h index 35ab1e620..2bcc29510 100644 --- a/src/xine-engine/buffer.h +++ b/src/xine-engine/buffer.h @@ -190,6 +190,7 @@ extern "C" { #define BUF_VIDEO_VP6F 0x02630000 #define BUF_VIDEO_THEORA_RAW 0x02640000 #define BUF_VIDEO_VC1 0x02650000 +#define BUF_VIDEO_VMNC 0x02660000 /* audio buffer types: (please keep in sync with buffer_types.c) */ diff --git a/src/xine-engine/buffer_types.c b/src/xine-engine/buffer_types.c index ee50e5391..7242738e1 100644 --- a/src/xine-engine/buffer_types.c +++ b/src/xine-engine/buffer_types.c @@ -771,6 +771,14 @@ static const video_db_t video_db[] = { BUF_VIDEO_KMVC, "Karl Morton's Video Codec" }, +{ + { + ME_FOURCC('V','M','n','c'), + 0 + }, + BUF_VIDEO_VMNC, + "VMware Screen Codec" +}, { { 0 }, 0, "last entry" } }; -- cgit v1.2.3 From ff632b94b6b25c35239ebb49a8e123d11f2fa8f4 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 6 Jan 2008 03:30:02 +0000 Subject: Tell the Real demuxer about lists of http references. Such broken wrong-extension wrong-MIME-type lists exist in the wild... --- ChangeLog | 2 +- src/demuxers/demux_real.c | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4e5b24b61..47ece9b70 100644 --- a/ChangeLog +++ b/ChangeLog @@ -27,7 +27,7 @@ xine-lib (1.1.9) (unreleased) (This was broken by ffmpeg revision 9283). * Enabled the WMV VC1 & VMware Screen (ffmpeg) codecs. * Fixed a crash that happened when a video output was closed - * Made the Real demuxer recognise http references. + * Made the Real demuxer recognise simple lists of http references. * Require correct URL encoding of '#'s which aren't separators. * Don't decode %nn in raw filenames. [Bug 1784272] * Always enable a52dec capabilities for external a52dec, this makes it diff --git a/src/demuxers/demux_real.c b/src/demuxers/demux_real.c index 85d7dc5a3..9206bfc74 100644 --- a/src/demuxers/demux_real.c +++ b/src/demuxers/demux_real.c @@ -806,12 +806,22 @@ static int demux_real_parse_references( demux_real_t *this) { if (!strncmp(buf,"http://",7)) { - for (i = 0; buf[i] && !isspace(buf[i]); ++i) - /**/; - buf[i] = 0; - lprintf("reference [%s] found\n", buf); - - _x_demux_send_mrl_reference (this->stream, 0, buf, NULL, 0, 0); + i = 0; + while (buf[i]) + { + j = i; + while (buf[i] && !isspace(buf[i])) + ++i; /* skip non-space */ + len = buf[i]; + buf[i] = 0; + if (strncmp (buf + j, "http://", 7) || (i - j) < 8) + break; /* stop at the first non-http reference */ + lprintf("reference [%s] found\n", buf + j); + _x_demux_send_mrl_reference (this->stream, 0, buf + j, NULL, 0, 0); + buf[i] = (char) len; + while (buf[i] && isspace(buf[i])) + ++i; /* skip spaces */ + } } else for (i = 0; i < buf_used; ++i) { -- cgit v1.2.3 From 45aa7ebe596abd3263c747c642a2416a7ebbbbba Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Sun, 6 Jan 2008 16:03:20 +0000 Subject: for resolving Korean subtitle bug In draw_subtitle(), if the given encoding is one the CJK charset, colored typefaces functionality is disabled and subtitles are printed with the render_text() method. Otherwise subtitles are drawn by ogm_render_line() function. --- src/libsputext/xine_sputext_decoder.c | 50 ++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/libsputext/xine_sputext_decoder.c b/src/libsputext/xine_sputext_decoder.c index 1de1eb099..d45886300 100644 --- a/src/libsputext/xine_sputext_decoder.c +++ b/src/libsputext/xine_sputext_decoder.c @@ -506,11 +506,54 @@ static void read_ssa_tag(sputext_decoder_t *this, const char* text, (*sub_x), (*sub_y), (*max_width), (*alignment)); } +static int is_cjk_encoding(const char *enc) { + char **pstr; + + /* CJK charset strings defined in iconvdata/gconv-modules of glibc */ + static char *cjk_encoding_strings[] = { + "SJIS", + "CP932", + "EUC-KR", + "UHC", + "JOHAB", + "BIG5", + "BIG5HKSCS", + "EUC-JP-MS", + "EUC-JP", + "EUC-CN", + "GBBIG5", + "GBK", + "GBGBK", + "EUC-TW", + "ISO-2022-JP", + "ISO-2022-JP-2", + "ISO-2022-JP-3", + "ISO-2022-KR", + "ISO-2022-CN", + "ISO-2022-CN-EXT", + "GB18030", + "EUC-JISX0213", + "SHIFT_JISX0213", + NULL + }; + + /* return 1 if encoding string is one of the CJK(Chinese,Jananese,Korean) + * character set strings. */ + for (pstr = cjk_encoding_strings; *pstr; pstr++) { + if (strcasecmp(enc, *pstr) == 0) + return 1; + } + + return 0; +} + static void draw_subtitle(sputext_decoder_t *this, int64_t sub_start, int64_t sub_end ) { int line, y; int font_size; char *font; + char *encoding = (this->buf_encoding)?this->buf_encoding: + this->class->src_encoding; int sub_x, sub_y, max_width; int alignment; int rebuild_all; @@ -719,7 +762,12 @@ static void draw_subtitle(sputext_decoder_t *this, int64_t sub_start, int64_t su } } - ogm_render_line(this, x, y + line*this->line_height, this->text[line]); + if( is_cjk_encoding(encoding) ) { + this->renderer->render_text (this->osd, x, y + line * this->line_height, + this->text[line], OSD_TEXT1); + } else { + ogm_render_line(this, x, y + line*this->line_height, this->text[line]); + } } if( font_size != this->font_size ) -- cgit v1.2.3 From 3b8eab0196256be7240878cb718fceb7cd373549 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 6 Jan 2008 15:56:24 +0000 Subject: Constify bits of the OGM subtitle hack. Add a changelog entry. --- ChangeLog | 2 ++ src/libsputext/xine_sputext_decoder.c | 14 ++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 47ece9b70..274c4117c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -43,6 +43,8 @@ xine-lib (1.1.9) (unreleased) * Fixed an issue in input_pvr with setting the frequency of the tuner for ivtv versions 0.10.6+ * Add Turkish translation by Serdar Soytetir and Server Acim. + * Workaround for subtitle rendering when using variable-length character + encodings other than UTF-8. (There is probably still some breakage here.) xine-lib (1.1.8) * Send a channel-changed event to the frontend when receiving the SYNC diff --git a/src/libsputext/xine_sputext_decoder.c b/src/libsputext/xine_sputext_decoder.c index d45886300..d0cab9cbf 100644 --- a/src/libsputext/xine_sputext_decoder.c +++ b/src/libsputext/xine_sputext_decoder.c @@ -507,10 +507,8 @@ static void read_ssa_tag(sputext_decoder_t *this, const char* text, } static int is_cjk_encoding(const char *enc) { - char **pstr; - /* CJK charset strings defined in iconvdata/gconv-modules of glibc */ - static char *cjk_encoding_strings[] = { + static const char cjk_encoding_strings[][16] = { "SJIS", "CP932", "EUC-KR", @@ -534,15 +532,15 @@ static int is_cjk_encoding(const char *enc) { "GB18030", "EUC-JISX0213", "SHIFT_JISX0213", - NULL }; + int pstr; + /* return 1 if encoding string is one of the CJK(Chinese,Jananese,Korean) * character set strings. */ - for (pstr = cjk_encoding_strings; *pstr; pstr++) { - if (strcasecmp(enc, *pstr) == 0) + for (pstr = 0; pstr < sizeof (cjk_encoding_strings) / sizeof (cjk_encoding_strings[0]); pstr++) + if (strcasecmp (enc, cjk_encoding_strings[pstr]) == 0) return 1; - } return 0; } @@ -552,7 +550,7 @@ static void draw_subtitle(sputext_decoder_t *this, int64_t sub_start, int64_t su int line, y; int font_size; char *font; - char *encoding = (this->buf_encoding)?this->buf_encoding: + const char *encoding = (this->buf_encoding)?this->buf_encoding: this->class->src_encoding; int sub_x, sub_y, max_width; int alignment; -- cgit v1.2.3 From b78e068f0348e9461a96a30fff88ae987fd45a10 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 6 Jan 2008 17:02:47 +0000 Subject: Mark a translated string as fuzzy else "make -C po update-po" fails. --- po/tr.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/po/tr.po b/po/tr.po index 7965a185e..a4fb503b8 100644 --- a/po/tr.po +++ b/po/tr.po @@ -2962,7 +2962,7 @@ msgid ": upmixing Mono to Stereo.\n" msgstr ": Mono'dan Stereo'ya dönüştürme.\n" #: src/post/audio/upmix_mono.c:149 -#, c-format +#, fuzzy, c-format msgid ": upmixing a single channel from original %d channel stream.\n" msgid_plural ": upmixing a single channel from original %d channels stream.\n" msgstr[0] ": tek kanalı özgün %d kanal yayın akışlarına dönüştürme.\n" -- cgit v1.2.3 From 775a0f241ac823b1bbb4433e44d969ede2679ec9 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 6 Jan 2008 17:03:16 +0000 Subject: Mark release. --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 274c4117c..18a94dd93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -xine-lib (1.1.9) (unreleased) +xine-lib (1.1.9) * Fix dvd://.../title[.chapter] handling (somewhat broken in 1.1.8). * Fix switching DVB subtitles channels. * DVB sub: switch to dyn mem alloc and allow multiple CLUTs per page. -- cgit v1.2.3 From c9b3a3c1f946e235c2bcbbf3909d199be905aba0 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 6 Jan 2008 17:19:23 +0000 Subject: Release tag. --- .hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags b/.hgtags index 9000dcadc..b483eab8c 100644 --- a/.hgtags +++ b/.hgtags @@ -62,3 +62,4 @@ fd12068ebd3fab2438f77b06e312c4244e97950a DXR3_095 7b60f85a95345c41fb074dc5e3f7355d9e72968e xine-lib-1_1_6-release ab1531337553ad5eac24a69ac665eae33916b423 xine-lib-1_1_7-release e0a332b9d3e8bb3fad4d7feac1e519292b062056 xine-lib-1_1_8-release +b6be674453e922114b55d4613cb197c77d19f094 xine-lib-1_1_9-release -- cgit v1.2.3 From 6255dcb866af030b0122c061459ab587a0d8c074 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 6 Jan 2008 17:19:34 +0000 Subject: Added signature for changeset 1dbf784bebc791266fcca02e917ee63034ac2e0b --- .hgsigs | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgsigs b/.hgsigs index bcd9cb88d..4a6a1294f 100644 --- a/.hgsigs +++ b/.hgsigs @@ -1,2 +1,3 @@ 5e6d0656ac4efdc1a89ed0fc32f11050f4a22970 0 iD8DBQBGZ207sBKtjPGfWZ8RAhdEAKCrkwiBT6bTof7ro5QQwewRfF/dMACffsvfK42+ahQrjpSfQxEp6k7RpCI= 42358e16442fe54fa554006e0b0bafd51e065c32 0 iD8DBQBG0xz0zbwfTn7RbcARAoD3AJ4012pabmpQvCKKDokZNyZzfPIbWgCfRk5FRly/Eei/xXnSaT54XHAT5KM= +1dbf784bebc791266fcca02e917ee63034ac2e0b 0 iD8DBQBHgQ2mzbwfTn7RbcARArl9AKCslqZDrrm0GiU3IbBvcQVbOdSXlwCgyEMuHY2y/+T6WEeB2CXvCTs5ulI= -- cgit v1.2.3 From 108b12c4b3abb63f4ac39bfed1fe44f2e1bab6c3 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Wed, 9 Jan 2008 18:37:35 +0000 Subject: Some lexer state tokenisation which somehow slipped through a crack somewhere. --- src/xine-utils/xmllexer.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/xine-utils/xmllexer.c b/src/xine-utils/xmllexer.c index 579007e52..75a1aafec 100644 --- a/src/xine-utils/xmllexer.c +++ b/src/xine-utils/xmllexer.c @@ -531,27 +531,28 @@ int lexer_get_token_d(char ** _tok, int * _tok_size, int fixed) { /* Terminate the current token */ tok[tok_pos] = '\0'; switch (state) { - case 0: - case 1: - case 2: + case STATE_IDLE: + case STATE_EOL: + case STATE_SEPAR: return T_EOF; break; - case 3: + case STATE_T_M_START: return T_M_START_1; break; - case 4: + case STATE_T_M_STOP_1: return T_M_STOP_1; break; - case 5: + case STATE_T_M_STOP_2: return T_ERROR; break; - case 6: + case STATE_T_EQUAL: return T_EQUAL; break; - case 7: + case STATE_T_STRING_SINGLE: + case STATE_T_STRING_DOUBLE: return T_STRING; break; - case 100: + case STATE_IDENT: return T_DATA; break; default: -- cgit v1.2.3 From c749ef5ef58af5f1a1856c802b0726bf6912601a Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Wed, 9 Jan 2008 22:18:11 +0000 Subject: Allow for patch-level numbering; initialise to ".1". --- ChangeLog | 2 ++ configure.ac | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 18a94dd93..b43e2b5d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ +xine-lib (1.1.9.1) (unreleased) + xine-lib (1.1.9) * Fix dvd://.../title[.chapter] handling (somewhat broken in 1.1.8). * Fix switching DVB subtitles channels. diff --git a/configure.ac b/configure.ac index 9bb6eca4f..f92318924 100644 --- a/configure.ac +++ b/configure.ac @@ -12,16 +12,18 @@ dnl AC_PREREQ(2.59) dnl Making releases: -dnl XINE_SUB += 1; continue with XINE_LT_* values below +dnl XINE_SUB += 1; XINE_PATCH = ''; continue with XINE_LT_* values below dnl XINE_MAJOR=1 XINE_MINOR=1 XINE_SUB=9 +# XINE_PATCH should be left empty or set to ".1" or ".2" or something similar +XINE_PATCH=.1 #if test $XINE_SUB -eq 0 ; then # XINE_SUBPART=""; #else - XINE_SUBPART=".$XINE_SUB" + XINE_SUBPART=".$XINE_SUB$XINE_PATCH" #fi dnl The libtool version numbers (XINE_LT_*); Don't even think about faking this! @@ -69,6 +71,7 @@ AC_SUBST(XINE_BIN_AGE) AC_DEFINE_UNQUOTED(XINE_MAJOR, $XINE_MAJOR,[xine major version number]) AC_DEFINE_UNQUOTED(XINE_MINOR, $XINE_MINOR,[xine minor version number]) AC_DEFINE_UNQUOTED(XINE_SUB, $XINE_SUB, [xine sub version number]) +AC_DEFINE_UNQUOTED(XINE_PATCH, $XINE_PATCH, [xine patch version number]) AC_SUBST(XINE_LT_CURRENT) AC_SUBST(XINE_LT_REVISION) @@ -2388,7 +2391,7 @@ makeexpand () { echo "$i" } -XINE_PLUGINDIR="$libdir/xine/plugins/$XINE_MAJOR.$XINE_MINOR.$XINE_SUB" +XINE_PLUGINDIR="$libdir/xine/plugins/$XINE_MAJOR.$XINE_MINOR.$XINE_SUB$XINE_PATCH" XINE_FONTDIR="${datadir}/xine/libxine$XINE_MAJOR/fonts" XINE_LOCALEDIR="${datadir}/locale" XINE_REL_PLUGINDIR="`makeexpand "$XINE_PLUGINDIR"`" -- cgit v1.2.3 From 2a9d1fe9f99cc2329a762f6e30a8ee0dc8e84014 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Wed, 9 Jan 2008 22:19:42 +0000 Subject: Fix a read-past-end bug in xine-lib's internal strtok_r replacement. --- ChangeLog | 2 ++ lib/strtok_r.c | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index b43e2b5d0..c2a6a74de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ xine-lib (1.1.9.1) (unreleased) + * Fix a read-past-end bug in xine-lib's internal strtok_r replacement. + (Only affects systems without strtok_r.) xine-lib (1.1.9) * Fix dvd://.../title[.chapter] handling (somewhat broken in 1.1.8). diff --git a/lib/strtok_r.c b/lib/strtok_r.c index cead029a2..8a5284a42 100644 --- a/lib/strtok_r.c +++ b/lib/strtok_r.c @@ -19,7 +19,7 @@ char *xine_private_strtok_r(char *s, const char *delim, char **ptrptr) { else s = *ptrptr; /* end of searching */ - if (!s || s == '\0') return NULL; + if (!s || !*s) return NULL; /* cut the initial garbage */ cutlen = strspn(s, delim); @@ -32,12 +32,12 @@ char *xine_private_strtok_r(char *s, const char *delim, char **ptrptr) { } next = s + toklen; + /* prepare next call */ + *ptrptr = *next ? next + 1 : NULL; + /* cut current token */ *next = '\0'; - /* prepare next call */ - *ptrptr = next + 1; - /* return the token */ return s; } -- cgit v1.2.3 From c02256b2b1cfe165e76da9f307887bb35c968735 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Wed, 9 Jan 2008 22:51:40 +0000 Subject: Allow for patch-level numbering. --- configure.ac | 5 ++++- version.sh | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 301f95f15..926620303 100644 --- a/configure.ac +++ b/configure.ac @@ -63,6 +63,9 @@ AC_DEFINE_UNQUOTED([XINE_MINOR], [$XINE_MINOR], [xine minor version number]) XINE_SUB=XINE_VERSION_SUB AC_SUBST(XINE_SUB) AC_DEFINE_UNQUOTED([XINE_SUB], [$XINE_SUB], [xine sub version number]) +XINE_PATCH=XINE_VERSION_PATCH +AC_SUBST(XINE_PATCH) +AC_DEFINE_UNQUOTED([XINE_PATCH], [$XINE_PATCH], [xine patch version number]) XINE_LT_CURRENT=__XINE_LT_CURRENT AC_SUBST(XINE_LT_CURRENT) @@ -984,7 +987,7 @@ xinedatadir='${datadir}/xine' AC_SUBST(xinelibdir) AC_SUBST(xinedatadir) -XINE_PLUGINDIR="\${xinelibdir}/plugins/$XINE_MAJOR.$XINE_MINOR.$XINE_SUB" +XINE_PLUGINDIR="\${xinelibdir}/plugins/$XINE_MAJOR.$XINE_MINOR.$XINE_SUB$XINE_PATCH" XINE_FONTDIR="\${xinedatadir}/libxine$XINE_MAJOR/fonts" XINE_LOCALEDIR='${datadir}/locale' XINE_REL_PLUGINDIR="`makeexpand "$XINE_PLUGINDIR"`" diff --git a/version.sh b/version.sh index 37649ecda..9e5611126 100755 --- a/version.sh +++ b/version.sh @@ -1,7 +1,11 @@ #!/bin/sh # Making releases: -# 1. Increment XINE_VERSION_SUB +# 1. For normal releases +# Increment XINE_VERSION_SUB +# Clear XINE_VERSION_PATCH +# For patch releases +# Increment XINE_VERSION_PATCH (use ".1", ".2" etc.) # 2. Remove .cvsversion before running make dist # 3. Adjust the values of XINE_LT_CURRENT, XINE_LT_REVISION, and XINE_LT_AGE # according to the following rules: @@ -27,13 +31,14 @@ XINE_VERSION_MAJOR=1 XINE_VERSION_MINOR=1 XINE_VERSION_SUB=90 +XINE_VERSION_PATCH= XINE_LT_CURRENT=2 XINE_LT_REVISION=0 XINE_LT_AGE=0 test -f "`dirname $0`/.cvsversion" && XINE_VERSION_SUFFIX="hg" -XINE_VERSION_SPEC="${XINE_VERSION_MAJOR}.${XINE_VERSION_MINOR}.${XINE_VERSION_SUB}${XINE_VERSION_SUFFIX}" +XINE_VERSION_SPEC="${XINE_VERSION_MAJOR}.${XINE_VERSION_MINOR}.${XINE_VERSION_SUB}${XINE_VERSION_PATCH}${XINE_VERSION_SUFFIX}" #### #### You should not need to touch anything beyond this point @@ -42,6 +47,7 @@ XINE_VERSION_SPEC="${XINE_VERSION_MAJOR}.${XINE_VERSION_MINOR}.${XINE_VERSION_SU echo "m4_define([XINE_VERSION_MAJOR], [${XINE_VERSION_MAJOR}])dnl" echo "m4_define([XINE_VERSION_MINOR], [${XINE_VERSION_MINOR}])dnl" echo "m4_define([XINE_VERSION_SUB], [${XINE_VERSION_SUB}])dnl" +echo "m4_define([XINE_VERSION_PATCH], [${XINE_VERSION_PATCH}])dnl" echo "m4_define([XINE_VERSION_SUFFIX], [${XINE_VERSION_SUFFIX}])dnl" echo "m4_define([XINE_VERSION_SPEC], [${XINE_VERSION_SPEC}])dnl" echo "m4_define([__XINE_LT_CURRENT], [${XINE_LT_CURRENT}])dnl" -- cgit v1.2.3 From 05b60afb93b690e01acdaa30c747dbe8715a8932 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Wed, 9 Jan 2008 23:51:40 +0000 Subject: Add the bug no. for the strtok_r fix. --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c2a6a74de..b3ba9c3eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,6 @@ xine-lib (1.1.9.1) (unreleased) * Fix a read-past-end bug in xine-lib's internal strtok_r replacement. - (Only affects systems without strtok_r.) + (Only affects systems without strtok_r.) [Bug #19] xine-lib (1.1.9) * Fix dvd://.../title[.chapter] handling (somewhat broken in 1.1.8). -- cgit v1.2.3 From ff41358936294b3522429eaecc15edeba1bc1880 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Wed, 9 Jan 2008 23:57:29 +0000 Subject: Mark bugs from the Sourceforge tracker as such. --- ChangeLog | 111 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 56 insertions(+), 55 deletions(-) diff --git a/ChangeLog b/ChangeLog index b3ba9c3eb..89c0beddb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,11 +13,11 @@ xine-lib (1.1.9) * Improve handling of invalid or unknown frame sizes. * Fixed handling of streamed Flash videos (broken in 1.1.5). * Fixed division by zero in sputext decoder - * Build fix for when using Linux 2.6.23 headers. [Bug 1820958] + * Build fix for when using Linux 2.6.23 headers. [Bug SF 1820958] * Implemented decoding of XML character entities with codes >= 256. This requires conversion to UTF-8 of entities with codes >= 128. * Handle initial Unicde BOMs in XML; convert other UTF encodings to UTF-8. - * Fixed ATSC support. [Bug 1749508] + * Fixed ATSC support. [Bug SF 1749508] * Fixed a possible DVB plugin crash when switching channels. * Fixed a crash closing the frontend. [Bug #7] * Fixed deadlock on ao_close while paused. @@ -33,7 +33,7 @@ xine-lib (1.1.9) * Fixed a crash that happened when a video output was closed * Made the Real demuxer recognise simple lists of http references. * Require correct URL encoding of '#'s which aren't separators. - * Don't decode %nn in raw filenames. [Bug 1784272] + * Don't decode %nn in raw filenames. [Bug SF 1784272] * Always enable a52dec capabilities for external a52dec, this makes it possible to use the DJB accelerated FFT when using the external a52dec liba52 library. [Bug #9] @@ -68,7 +68,7 @@ xine-lib (1.1.8) * DVB subtitle fixes: deadlock prevention, thread leakage, spec compliance. * Allow the DVB input plugin to timeout if it is receiving no signal. * Fix an audio resampling problem which was causing regular clicking. - * Fix build with recent glibc and a debugging #define. [Bug 1773769] + * Fix build with recent glibc and a debugging #define. [Bug SF 1773769] * Fix handling of multiple MPEG TS audio streams & subtitle languages. * Add colouring for bold & italic in text subtitles. * Simple scaling of subtitles to fit the frame width (intended to cope @@ -78,10 +78,10 @@ xine-lib (1.1.8) xine-lib (1.1.7) * Support libdca (new name for libdts) by shuffling around the dts.h file. - * Add support for MDHD version 1 atom in demux_qt. [bug #1679398] + * Add support for MDHD version 1 atom in demux_qt. [Bug SF 1679398] * Handle single-quoted attribute values in XML. * Fix default paths for RealPlayer libraries (broken in 1.1.5). - [Bug 1707526] + [Bug SF 1707526] * Fix proxy usage when the hostnames cannot be resolved. Thanks to Jeff Mitchell for reporting and testing the fix. * Avoid zero-sized frames when demuxing MPEG PES. @@ -121,7 +121,7 @@ xine-lib (1.1.6) xine-lib (1.1.5) * Security fixes: - - Fix heap overflow in DMO loader. (CVE-2007-1246) [bug #1676925] + - Fix heap overflow in DMO loader. (CVE-2007-1246) [Bug SF 1676925] Thanks to Kees Cook for reporting. * Improved PulseAudio plugin, now only one connection per instance is opened and the mainloop is threaded to reduce latency during playback. @@ -130,7 +130,7 @@ xine-lib (1.1.5) The plugins are contributed by Christoph Pfister with the help of Vincent Torri, Jamey Sharp and Christophe Thommeret. * Fix race condition in alsa audio out driver. - * Fixed a crash in the eq2 plugin. [Bug 1644312] + * Fixed a crash in the eq2 plugin. [Bug SF 1644312] * Fixed content type detection for AAC (seekable) streams with ID3v2 tags prefixed clobbering the preview buffer, by skipping over the tag. * Parse ID3v2 tags on AAC and FLAC files, as well as mp3 files. @@ -183,41 +183,42 @@ xine-lib (1.1.4) and previously applied by other distributions as well. Fixes the non-PIC code being generated. Note: patch reverted for tomsmocomp (segfault). * Fix race condition in audio_out by using a recursive mutex; patch by - Reinhard Nissl. [bug #1551911] + Reinhard Nissl. [Bug SF 1551911] * Allow building with Sun CC by fixing the lprintf variadic macro; patch by - Taso N. Devetzis. [bug #1614406] + Taso N. Devetzis. [Bug SF 1614406] * Fix disposing of image buffers in video_out_xv when SHM get disabled by - exhaustion of memory; patch by Matthias Drochner. [bug #1620339] + exhaustion of memory; patch by Matthias Drochner. [Bug SF 1620339] * Fix invalid memory access in Real Media ASM parser; reported by Roland - Kay. [bug #1603503] + Kay. [Bug SF 1603503] * Fix program termination due to invalid Real Media SDP; reported by Roland - Kay. [bug #1602663] + Kay. [Bug SF 1602663] * Fix invalid memory access in Real Media SDP with tailored stream; reported - by Roland Kay. [bug #1602631] + by Roland Kay. [Bug SF 1602631] * Don't check for libpostproc version and assume that if libavcodec is found correctly, libpostproc is of the same version, too. Reported by Ville - Skyttä. [bug #1617344] + Skyttä. [Bug SF 1617344] * Fix Shorten demuxer: the whole "ajkg" signature has to be found, not only - one character of it. [bug #1601134] + one character of it. [Bug SF 1601134] * Implement at least a partial content-based detection of ModPlug-decoded module files, using the magic numbers from GNU file. This allows to open module files based on content rather than on their extension only. - [bug #1445746] + [Bug SF 1445746] * Make the libFLAC-based decoder and demuxer for FLAC files work with recent FLAC release 1.1.3. * Replace --enable-flac configure option with --with-libflac, as the FLAC support is always built-in through the audio demuxer plugin and the FFmpeg decoder plugin, the option only controls the extra FLAC plugin that uses libFLAC both for demuxing and decoding. - * Implement a True Audio files demuxer. [bug #1586381] + * Implement a True Audio files demuxer. [Bug SF 1586381] * Allow decoding of MusePack SV 7.x files (7.1 files at least play fine). * Fix demuxing of uncompressed VobSub subtitles in Matroska files * ffmpeg update to 51.29.0 * Workaround ffmpeg buggy codecs that don't release their DR1 frames. - [bugs #1599975, #1601299, #1319154] + [Bugs SF 1599975, SF 1601299, SF 1319154] * Fix several segfaults and freezing problem with H264 streams that use a lot - of reference frames (eg. 15) [bugs #1603305, #1576588, #1267713] - * Fix mpeg4 artifacts introduced in cvs (not present in 1.1.3) [#1625911] + of reference frames (eg. 15) [Bugs SF 1603305, SF 1576588, SF 1267713] + * Fix mpeg4 artifacts introduced in cvs (not present in 1.1.3) + [Bug SF 1625911] * Initial support to enable/disable ffmpeg codecs. Codecs may be disabled in groups by --disable-ffmpeg-uncommon-codecs/--disable-ffmpeg-popular-codecs Think of "uncommon" codecs what people would never want to play with their @@ -236,12 +237,12 @@ xine-lib (1.1.4) * Don't crash when caching a file opened through Samba plugin, thanks to Timothy Redaelli from Gentoo. * Fix audio/video sync problem with NTSC DVDs (introduced in 1.1.2). - [bugs #1544349 and #1589644] + [Bugs SF 1544349, SF 1589644] xine-lib (1.1.3) * Security fixes: - Heap overflow in libmms (related to CVE-2006-2200) - - Buffer overrun in Real Media input plugin. [bug #1603458] + - Buffer overrun in Real Media input plugin. [Bug SF 1603458] Thanks to Roland Kay for reporting and JW for the patch. * Update build system to support x86 Darwin setups, and merge patches to support Darwin OS better. @@ -259,26 +260,26 @@ xine-lib (1.1.3) supported by upstream, and it's replaced by PulseAudio. * Allow 0 for DVD title/chapter (navigation or full title). * New experimental JACK audio driver. - * Fix switch from alsa/dmix 2.0 to 5.1 [bug #1226595] - * Don't use proxy for localhost connection. [bug #1553633] + * Fix switch from alsa/dmix 2.0 to 5.1 [Bug SF 1226595] + * Don't use proxy for localhost connection. [Bug SF 1553633] * Use mmap() to open local files if available. * Use pkg-config to look for external FFmpeg. * Allow FFmpeg to play MP3s in case MAD is not present. * Reduce the dead time when trying to connect to dead hosts, by falling back to non-blocking sockets on the last address found for an host, and allowing - users to provide a connection timeout. [bug #1550844] + users to provide a connection timeout. [Bug SF 1550844] * Return the correct error message to frontends when a file is inaccessible or - the network connection is broken. [bug #1550763] + the network connection is broken. [Bug SF 1550763] * Support libcaca 0.99, thanks to cjacker huang. - * Fix crash on video-only WMV streams. [bug #1564598] + * Fix crash on video-only WMV streams. [Bug SF 1564598] * Report audio stream on Shorten files (required for Amarok to play them). - * Optionally use fontconfig to look up fonts to use for OSD. [bug #1551042] + * Optionally use fontconfig to look up fonts to use for OSD. [Bug SF 1551042] * Prefer FreeType2 rendered fonts to bitmap fonts. * Stone age platforms update * Enabled TrueSpeech codec * New X11 visual type: xine-lib may now use frontend's mutex/lock mechanism instead of XLockDisplay/XUnlockDisplay. - * Allow playing of OggFlac files. [bug #1590690] + * Allow playing of OggFlac files. [Bug SF 1590690] * Allow playing FLAC files with an ID3 tag at the start. * Fix some crashes caused by MP3 files (and possibly others) being misdetected as AAC. @@ -342,7 +343,7 @@ xine-lib (1.1.1) * support gapless playback while switching streams (requires UI cooperation) * fix speed changing race causing deadlock with v4l plugin * cddb improvements/fixes (DTITLE/DYEAR parsing, timeout increase and - multiline entries support) [#1205274] + multiline entries support) [Bug SF 1205274] xine-lib (1.1.0) * new quality deinterlacer from dscaler: GreedyH (Greedy High Motion) @@ -370,20 +371,20 @@ xine-lib (1.0.2) rtsp://stream.samurai.fm/broadcast/live_hi.rm * fixed xxmc / xvmc mocomp / IDCT rendering errors caused by the big update. * support --enable-fpic with recent versions of gcc - * clip goom fps value to >= 1 [bug #1193783] + * clip goom fps value to >= 1 [Bug SF 1193783] * fixed xvmc plugin segfault when it tried software blending on nonexistant xv image * cleaned up libmpeg2 behaviour on xxmc plugin abrupt software fallback * use -fno-inline-functions with gcc < 3.4.0 (bug known to be in 3.3.5) * fix xxmc plugin wanting to change vld xvmc context when stream changes from - non-interlaced to interlaced [bug #1194350] + non-interlaced to interlaced [Bug SF 1194350] * speed up xx44 alphablending of large transparent areas * stop libmpeg2 XvMC IDCT / MOCOMP attempting software motion compensation - [bug #1194754] + [Bug SF 1194754] * improve xxmc cpu-usage for IDCT / MOCOMP acceleration through better locking - [bug #1195282] - * gcc4 build patches [bug #1175002] - * don't assume that file is in /usr/bin (build fix) [bug #1195539] - * plugin loader fixes - could cause xine to lock up hard on startup [bug #1196819] + [Bug SF 1195282] + * gcc4 build patches [Bug SF 1175002] + * don't assume that file is in /usr/bin (build fix) [Bug SF 1195539] + * plugin loader fixes - could cause xine to lock up hard on startup [Bug SF 1196819] * Fix xxmc bob deinterlacing for field-coded interlaced streams * Fix LE_64/BE_64 macros on non-x86 plataforms. may fixes issues with some demuxers like avi, asf and ogg. @@ -404,10 +405,10 @@ xine-lib (1.0.2) greater installed xine-lib (1.0.1) - * Big XvMC quality / correctness / cpu-usage fix. [bug #1114517] + * Big XvMC quality / correctness / cpu-usage fix. [Bug SF 1114517] * fixed builds with Xv or the entire X11 unavailable * updated internal copies of VCD libraries to libcdio 0.71 and vcdimager 0.7.21 - * fixed compatibility with new libtool versions [bug #1094262] + * fixed compatibility with new libtool versions [Bug SF 1094262] * renamed input.http_no_proxy to media.network.http_no_proxy * tightened no-proxy domain matching & added exact host match ('=' prefix) * assume that front ends can handle tabs (ffmpeg pp plugin help text) @@ -420,15 +421,15 @@ xine-lib (1.0.1) * fixed support of icecast 2 server * fixed some memleaks related to DVD playback and MPEG PES * fixed PNG/MNG image distortion and incorrect colouring - * fixed build on solaris and other platforms [bugs #1062987, #1114677 and - #1115001] + * fixed build on solaris and other platforms [Bugs SF 1062987, SF 1114677, + SF 1115001] * published documentation about Win32 platform * brand new DirectX audio output plugin for Windows * updated win32 MSVC port * used only ASCII characters for C locale * fixed cropping and zooming with vidix * fixed status reporting to honour IDLE status as documented - * fixed aborts on DVB channel switching [bug #1090707] + * fixed aborts on DVB channel switching [Bug SF 1090707] * updated vidix to 0.9.9 * plugin description accessor functions (may load plugins) * fixed translations, they were not used in some cases @@ -448,7 +449,7 @@ xine-lib (1.0) * unbreak DXR3 plugin * fix crash in the AIFF demuxer on oversized chunks * fix crash in the sputext decoder when subtitles have too many lines - [bug #1086775] + [Bug SF 1086775] * added support for OGG chained streams * fixed deadlock with ASF chained streams due to fifo buffer leak * DVB Subtitles: fixed flashing, repeating subs, fix sync & timeouts @@ -465,9 +466,9 @@ xine-lib (1-rc8) * Fixed segfault when seeking with the "xvmc" and "xxmc" plugins playing files with IDCT / mocomp XvMC acceleration. * polypaudio sound server support - * fixed playback of MMS streams with the new input cache layer [bug #1066926] - * fixed builds without X11 [bug #1067705] - * added support for 24-bit LPCM from DVDs [bug #843786] + * fixed playback of MMS streams with the new input cache layer [Bug SF 1066926] + * fixed builds without X11 [Bug SF 1067705] + * added support for 24-bit LPCM from DVDs [Bug SF 843786] * Fixed segfault in xxmc plugin when switch from software decoding to accelerated decoding occured while software surfaces still needed to be duplicated. @@ -518,9 +519,9 @@ xine-lib (1-rc7) "The Lord of the Rings - The Two Towers" * fixed wrong subtitle appearing in the trailer of "Girl, Interrupted" RC2 * fixed "NAV packet expected, but none found" error when toggling between - menu and feature with the Escape key [bug #1025469] + menu and feature with the Escape key [Bug SF 1025469] * video image scaling can now be disabled for more video output plugins - than XShm [feature requests #987635, #856408] + than XShm [feature requests SF 987635, SF 856408] * Updated the xxmc driver with a better software fallback mechanism * Fixed playback of OpenDML streams generated by mencoder * Fixed playback of incomplete OpenDML streams @@ -534,7 +535,7 @@ xine-lib (1-rc7) overhead of expensive system calls for reading just a couple of bytes. may be disabled with MRL parameter "#nocache". * use monotonic clock where available (eg. linux 2.6) so system clock - updates won't disturb xine playback. [bug #781532] + updates won't disturb xine playback. [Bug SF 781532] * fixed seeking unresponsiveness when using external subtitles * Allowed multiple simultaneous thread access in parts of the xxmc driver, assuming that XvMC libraries are thread-safe. @@ -554,9 +555,9 @@ xine-lib (1-rc6) * Added quality improvements for full frame rate deinterlacing modes * Added support for 44100Hz DTS in .wav files. * Added ability to Restore initial xv port attributes on exit - [bugs #965572, #957599] - * Fixed brightness drift problem (loss of color) [bugs #947520, #963587] - * Fixed rare heap overflow with some DVD subpictures [bug #923843] + [Bugs SF 965572, SF 957599] + * Fixed brightness drift problem (loss of color) [Bugs SF 947520, SF 963587] + * Fixed rare heap overflow with some DVD subpictures [Bug SF 923843] * Fixed stack overflows in the VCD plugin * Added experimental time stretching plugin: play stream faster or slower than original speed, optionally preserving pitch @@ -570,8 +571,8 @@ xine-lib (1-rc6) * next stage of MINGW port - engine library compiles now * Improved DVD MRL handling. * Improved Transport stream handling. - * Fixed wrong, very bright overlays on some DVDs [bug #1018193] - * Fixed WIN32 replacement of gettimeofday [bug #995961] + * Fixed wrong, very bright overlays on some DVDs [Bug SF 1018193] + * Fixed WIN32 replacement of gettimeofday [Bug SF 995961] * Removed unistd.h from public header * Added experimental support for H.264/AVC video * Added support for 3ivx video -- cgit v1.2.3 From de085a0169d4a3701c67a74869ce0fb8ced6d6ae Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Thu, 10 Jan 2008 18:29:48 +0000 Subject: Oops. Re-mark a translated string as fuzzy else "make -C po update-po" fails. (Got lost in the previous commit.) --- po/tr.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/po/tr.po b/po/tr.po index 7965a185e..a4fb503b8 100644 --- a/po/tr.po +++ b/po/tr.po @@ -2962,7 +2962,7 @@ msgid ": upmixing Mono to Stereo.\n" msgstr ": Mono'dan Stereo'ya dönüştürme.\n" #: src/post/audio/upmix_mono.c:149 -#, c-format +#, fuzzy, c-format msgid ": upmixing a single channel from original %d channel stream.\n" msgid_plural ": upmixing a single channel from original %d channels stream.\n" msgstr[0] ": tek kanalı özgün %d kanal yayın akışlarına dönüştürme.\n" -- cgit v1.2.3 From f3e691cf556bd4ad1338f222ffcf5eaecafd6a24 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Fri, 11 Jan 2008 13:49:08 +0000 Subject: Fix a buffer overflow in the RTSP header-handling code. CVE-2008-0225; ported from mplayer changeset 22821. --- ChangeLog | 3 ++ src/input/libreal/rmff.c | 85 +++++++++++++++++++++++++++++----------- src/input/libreal/rmff.h | 6 +++ src/input/librtsp/rtsp_session.c | 6 +++ 4 files changed, 78 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 89c0beddb..ab355ba75 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ xine-lib (1.1.9.1) (unreleased) + * Security fixes: + - Fix a buffer overflow in RTSP header-handling code. (CVE-2008-0225) + (Fix ported from mplayer changeset 22821) * Fix a read-past-end bug in xine-lib's internal strtok_r replacement. (Only affects systems without strtok_r.) [Bug #19] diff --git a/src/input/libreal/rmff.c b/src/input/libreal/rmff.c index 159b81ee6..b79eb5e0f 100644 --- a/src/input/libreal/rmff.c +++ b/src/input/libreal/rmff.c @@ -35,9 +35,13 @@ * writes header data to a buffer */ -static void rmff_dump_fileheader(rmff_fileheader_t *fileheader, char *buffer) { +static int rmff_dump_fileheader(rmff_fileheader_t *fileheader, uint8_t *buffer, int bufsize) { + + if (!fileheader) return 0; + + if (bufsize < RMFF_FILEHEADER_SIZE) + return -1; - if (!fileheader) return; fileheader->object_id=_X_BE_32(&fileheader->object_id); fileheader->size=_X_BE_32(&fileheader->size); fileheader->object_version=_X_BE_16(&fileheader->object_version); @@ -53,11 +57,17 @@ static void rmff_dump_fileheader(rmff_fileheader_t *fileheader, char *buffer) { fileheader->file_version=_X_BE_32(&fileheader->file_version); fileheader->num_headers=_X_BE_32(&fileheader->num_headers); fileheader->object_id=_X_BE_32(&fileheader->object_id); + + return RMFF_FILEHEADER_SIZE; } -static void rmff_dump_prop(rmff_prop_t *prop, char *buffer) { +static int rmff_dump_prop(rmff_prop_t *prop, uint8_t *buffer, int bufsize) { + + if (!prop) return 0; + + if (bufsize < RMFF_PROPHEADER_SIZE) + return -1; - if (!prop) return; prop->object_id=_X_BE_32(&prop->object_id); prop->size=_X_BE_32(&prop->size); prop->object_version=_X_BE_16(&prop->object_version); @@ -93,13 +103,19 @@ static void rmff_dump_prop(rmff_prop_t *prop, char *buffer) { prop->num_streams=_X_BE_16(&prop->num_streams); prop->flags=_X_BE_16(&prop->flags); prop->object_id=_X_BE_32(&prop->object_id); + + return RMFF_PROPHEADER_SIZE; } -static void rmff_dump_mdpr(rmff_mdpr_t *mdpr, char *buffer) { +static int rmff_dump_mdpr(rmff_mdpr_t *mdpr, uint8_t *buffer, int bufsize) { int s1, s2, s3; - if (!mdpr) return; + if (!mdpr) return 0; + + if (bufsize < RMFF_MDPRHEADER_SIZE + mdpr->type_specific_len + mdpr->stream_name_size + mdpr->mime_type_size) + return -1; + mdpr->object_id=_X_BE_32(&mdpr->object_id); mdpr->size=_X_BE_32(&mdpr->size); mdpr->object_version=_X_BE_16(&mdpr->object_version); @@ -141,13 +157,19 @@ static void rmff_dump_mdpr(rmff_mdpr_t *mdpr, char *buffer) { mdpr->duration=_X_BE_32(&mdpr->duration); mdpr->object_id=_X_BE_32(&mdpr->object_id); + return RMFF_MDPRHEADER_SIZE + s1 + s2 + s3; } -static void rmff_dump_cont(rmff_cont_t *cont, char *buffer) { +static int rmff_dump_cont(rmff_cont_t *cont, uint8_t *buffer, int bufsize) { int p; - if (!cont) return; + if (!cont) return 0; + + if (bufsize < RMFF_CONTHEADER_SIZE + cont->title_len + cont->author_len + + cont->copyright_len + cont->comment_len) + return -1; + cont->object_id=_X_BE_32(&cont->object_id); cont->size=_X_BE_32(&cont->size); cont->object_version=_X_BE_16(&cont->object_version); @@ -181,11 +203,18 @@ static void rmff_dump_cont(rmff_cont_t *cont, char *buffer) { cont->size=_X_BE_32(&cont->size); cont->object_version=_X_BE_16(&cont->object_version); cont->object_id=_X_BE_32(&cont->object_id); + + return RMFF_CONTHEADER_SIZE + cont->title_len + cont->author_len + + cont->copyright_len + cont->comment_len; } -static void rmff_dump_dataheader(rmff_data_t *data, char *buffer) { +static int rmff_dump_dataheader(rmff_data_t *data, uint8_t *buffer, int bufsize) { + + if (!data) return 0; + + if (bufsize < RMFF_DATAHEADER_SIZE) + return -1; - if (!data) return; data->object_id=_X_BE_32(&data->object_id); data->size=_X_BE_32(&data->size); data->object_version=_X_BE_16(&data->object_version); @@ -201,31 +230,43 @@ static void rmff_dump_dataheader(rmff_data_t *data, char *buffer) { data->size=_X_BE_32(&data->size); data->object_version=_X_BE_16(&data->object_version); data->object_id=_X_BE_32(&data->object_id); + + return RMFF_DATAHEADER_SIZE; } -int rmff_dump_header(rmff_header_t *h, char *buffer, int max) { +int rmff_dump_header(rmff_header_t *h, void *buf_gen, int max) { + uint8_t *buffer = buf_gen; - int written=0; + int written=0, size; rmff_mdpr_t **stream=h->streams; - rmff_dump_fileheader(h->fileheader, &buffer[written]); - written+=h->fileheader->size; - rmff_dump_prop(h->prop, &buffer[written]); - written+=h->prop->size; - rmff_dump_cont(h->cont, &buffer[written]); - written+=h->cont->size; + if ((size=rmff_dump_fileheader(h->fileheader, &buffer[written], max)) < 0) + return -1; + written+=size; + max -= size; + if ((size=rmff_dump_prop(h->prop, &buffer[written], max)) < 0) + return -1; + written+=size; + max -= size; + if ((size=rmff_dump_cont(h->cont, &buffer[written], max)) < 0) + return -1; + written+=size; + max -= size; if (stream) { while(*stream) { - rmff_dump_mdpr(*stream, &buffer[written]); - written+=(*stream)->size; + if ((size=rmff_dump_mdpr(*stream, &buffer[written], max)) < 0) + return -1; + written+=size; + max -= size; stream++; } } - rmff_dump_dataheader(h->data, &buffer[written]); - written+=18; + if ((size=rmff_dump_dataheader(h->data, &buffer[written], max)) < 0) + return -1; + written+=size; return written; } diff --git a/src/input/libreal/rmff.h b/src/input/libreal/rmff.h index d39942088..5288fc558 100644 --- a/src/input/libreal/rmff.h +++ b/src/input/libreal/rmff.h @@ -39,6 +39,12 @@ #define RMFF_HEADER_SIZE 0x12 +#define RMFF_FILEHEADER_SIZE 18 +#define RMFF_PROPHEADER_SIZE 50 +#define RMFF_MDPRHEADER_SIZE 46 +#define RMFF_CONTHEADER_SIZE 18 +#define RMFF_DATAHEADER_SIZE 18 + #define FOURCC_TAG( ch0, ch1, ch2, ch3 ) \ (((long)(unsigned char)(ch3) ) | \ ( (long)(unsigned char)(ch2) << 8 ) | \ diff --git a/src/input/librtsp/rtsp_session.c b/src/input/librtsp/rtsp_session.c index f3ddb59bc..5b02282e9 100644 --- a/src/input/librtsp/rtsp_session.c +++ b/src/input/librtsp/rtsp_session.c @@ -148,6 +148,11 @@ connect: rtsp_session->header_left = rtsp_session->header_len = rmff_dump_header(h,rtsp_session->header,HEADER_SIZE); + if (rtsp_session->header_len < 0) { + xprintf (stream->xine, XINE_VERBOSITY_LOG, + _("rtsp_session: rtsp server returned overly-large headers, session can not be established.\n")); + goto session_abort; + } xine_buffer_copyin(rtsp_session->recv, 0, rtsp_session->header, rtsp_session->header_len); rtsp_session->recv_size = rtsp_session->header_len; @@ -157,6 +162,7 @@ connect: { xprintf(stream->xine, XINE_VERBOSITY_LOG, _("rtsp_session: rtsp server type '%s' not supported yet. sorry.\n"), server); + session_abort: rtsp_close(rtsp_session->s); free(server); xine_buffer_free(rtsp_session->recv); -- cgit v1.2.3 From a9aa9d58524fd95b1babe4a47308b126899c1113 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Fri, 11 Jan 2008 15:21:53 +0000 Subject: Correct the prototype of rmff_dump_header. (Build fix.) --- src/input/libreal/rmff.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input/libreal/rmff.h b/src/input/libreal/rmff.h index 5288fc558..b03d12b1b 100644 --- a/src/input/libreal/rmff.h +++ b/src/input/libreal/rmff.h @@ -251,7 +251,7 @@ int rmff_get_header_size(rmff_header_t *h); /* * dumps the header to . is the size of */ -int rmff_dump_header(rmff_header_t *h, char *buffer, int max); +int rmff_dump_header(rmff_header_t *h, void *buf_gen, int max); /* * dumps a packet header -- cgit v1.2.3 From 0c0bc8da469f415f3558010658df40349f9eca74 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 11 Jan 2008 15:35:04 +0000 Subject: XineOpenViewGL bug on PPC/Darwin Typo of WORDS_BIGENDIAN in in /src/video_out/macosx/XineVOpenGLView.m. It only affects big-endian systems (PowerPC) as it defaults to little-endian. --- src/video_out/macosx/XineOpenGLView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video_out/macosx/XineOpenGLView.m b/src/video_out/macosx/XineOpenGLView.m index a9ffee00f..1f947ca16 100644 --- a/src/video_out/macosx/XineOpenGLView.m +++ b/src/video_out/macosx/XineOpenGLView.m @@ -340,7 +340,7 @@ NSColorToYUV(NSColor *color) // http://developer.apple.com/samplecode/Sample_Code/Graphics_3D/TextureRange/MainOpenGLView.m.htm glTexSubImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, 0, 0, videoSize.width, videoSize.height, GL_YCBCR_422_APPLE, -#if WORDS_BIG_ENDIAN +#if WORDS_BIGENDIAN GL_UNSIGNED_SHORT_8_8_APPLE, #else GL_UNSIGNED_SHORT_8_8_REV_APPLE, -- cgit v1.2.3 From 33705e739deb34b959d4a3ecb0b3a6a6b60420c8 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Fri, 11 Jan 2008 15:37:37 +0000 Subject: Changelog entry for the PPC/Darwin display fix. --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index ab355ba75..de00895fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ xine-lib (1.1.9.1) (unreleased) (Fix ported from mplayer changeset 22821) * Fix a read-past-end bug in xine-lib's internal strtok_r replacement. (Only affects systems without strtok_r.) [Bug #19] + * Fix a bug which causes video playback display errors on PPC/Darwin. xine-lib (1.1.9) * Fix dvd://.../title[.chapter] handling (somewhat broken in 1.1.8). -- cgit v1.2.3 From 3187480880c001ffde34169980926bfed1acb7de Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Fri, 11 Jan 2008 15:37:47 +0000 Subject: Mark 1.1.9.1 as released. --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index de00895fc..f7e8b3243 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -xine-lib (1.1.9.1) (unreleased) +xine-lib (1.1.9.1) * Security fixes: - Fix a buffer overflow in RTSP header-handling code. (CVE-2008-0225) (Fix ported from mplayer changeset 22821) -- cgit v1.2.3 From cb297e293074b679e69837f54f7ce28fda0f7f53 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Fri, 11 Jan 2008 16:11:04 +0000 Subject: Added tag xine-lib-1_1_9_1-release for changeset 9438947f88ad --- .hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags b/.hgtags index b483eab8c..8b9b6199b 100644 --- a/.hgtags +++ b/.hgtags @@ -63,3 +63,4 @@ fd12068ebd3fab2438f77b06e312c4244e97950a DXR3_095 ab1531337553ad5eac24a69ac665eae33916b423 xine-lib-1_1_7-release e0a332b9d3e8bb3fad4d7feac1e519292b062056 xine-lib-1_1_8-release b6be674453e922114b55d4613cb197c77d19f094 xine-lib-1_1_9-release +9438947f88ad2bed1832385301c6b4e62709625a xine-lib-1_1_9_1-release -- cgit v1.2.3 From 4e63c284d8e45a33041806d201124985b8089e3e Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Fri, 11 Jan 2008 16:11:12 +0000 Subject: Added signature for changeset b591d00fcd386cdd3779378c34b2d42b7504afc4 --- .hgsigs | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgsigs b/.hgsigs index 4a6a1294f..528d1e655 100644 --- a/.hgsigs +++ b/.hgsigs @@ -1,3 +1,4 @@ 5e6d0656ac4efdc1a89ed0fc32f11050f4a22970 0 iD8DBQBGZ207sBKtjPGfWZ8RAhdEAKCrkwiBT6bTof7ro5QQwewRfF/dMACffsvfK42+ahQrjpSfQxEp6k7RpCI= 42358e16442fe54fa554006e0b0bafd51e065c32 0 iD8DBQBG0xz0zbwfTn7RbcARAoD3AJ4012pabmpQvCKKDokZNyZzfPIbWgCfRk5FRly/Eei/xXnSaT54XHAT5KM= 1dbf784bebc791266fcca02e917ee63034ac2e0b 0 iD8DBQBHgQ2mzbwfTn7RbcARArl9AKCslqZDrrm0GiU3IbBvcQVbOdSXlwCgyEMuHY2y/+T6WEeB2CXvCTs5ulI= +b591d00fcd386cdd3779378c34b2d42b7504afc4 0 iD8DBQBHh5UfsBKtjPGfWZ8RAgvMAJ9xwnDNifmaobFYe2nR7+rJlLTkEQCgguGMqwqRZY68HWQXhEx918hp4Yg= -- cgit v1.2.3 From 519f3e9ac3a920fe8a04668f38fbd0eb7b10942a Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Fri, 11 Jan 2008 17:30:35 +0000 Subject: Build-dep fixes: remove duplicate libdirectfb-dev, add gs-gpl | gs. --- debian/control | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/debian/control b/debian/control index c4a127b4f..7d93d2f7e 100644 --- a/debian/control +++ b/debian/control @@ -11,7 +11,6 @@ Build-Depends: debhelper (>= 5.0.1), binutils (>= 2.12.90.0.9), pkg-config, libxcb-xvmc0-dev | libxv-dev (<< 1:1.0.3), libxcb-shm0-dev | libxv-dev (<< 1:1.0.3), libxcb-shape0-dev | libxv-dev (<< 1:1.0.3), libxinerama-dev, libxv-dev, libxvmc-dev, libxt-dev, - libdirectfb-dev (>= 0.9.22), libasound2-dev [!kfreebsd-i386 !kfreebsd-amd64 !hurd-i386], libaa1-dev, libcaca-dev, libmodplug-dev, libmagick9-dev, libpng12-dev, libfreetype6-dev, @@ -19,11 +18,11 @@ Build-Depends: debhelper (>= 5.0.1), binutils (>= 2.12.90.0.9), pkg-config, libesd0-dev, libgnomevfs2-dev, zlib1g-dev, libartsc0-dev, liblircclient-dev, libjack0.100.0-dev | libjack-dev, - libdirectfb-dev, libgtk2.0-dev, + libdirectfb-dev (>= 0.9.22), libgtk2.0-dev, libflac-dev, libpulse-dev, libsdl1.2-dev, libwavpack-dev, libsmbclient-dev, libspeex-dev, libmng-dev, libmad0-dev, libmpcdec-dev, libcdio-dev (>= 0.76-1), - w3m, transfig, sgmltools-lite + w3m, transfig, sgmltools-lite, gs-gpl | gs Build-Conflicts: libdvdnav-dev, libvcdinfo-dev Standards-Version: 3.7.2 -- cgit v1.2.3 From 37e7a5aa4c03f8793dc9da8058a5625f5ff84d4b Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Sat, 12 Jan 2008 15:48:13 +0100 Subject: Don't send BUF_FLAG_FRAME_START twice per frame, otherwise the ffmpeg plugin skips the first part of the frame. Fixed wmv playback with ffmpeg. --- src/demuxers/demux_asf.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/demuxers/demux_asf.c b/src/demuxers/demux_asf.c index 9aab59977..c4a154f99 100644 --- a/src/demuxers/demux_asf.c +++ b/src/demuxers/demux_asf.c @@ -723,6 +723,9 @@ static void asf_send_buffer_nodefrag (demux_asf_t *this, asf_demux_stream_t *str buf->size = bufsize; timestamp = 0; + if (stream->frag_offset == 0) + buf->decoder_flags |= BUF_FLAG_FRAME_START; + stream->frag_offset += bufsize; frag_len -= bufsize; @@ -733,10 +736,6 @@ static void asf_send_buffer_nodefrag (demux_asf_t *this, asf_demux_stream_t *str else check_newpts (this, buf->pts, PTS_AUDIO, package_done); - - if (frag_offset == 0) - buf->decoder_flags |= BUF_FLAG_FRAME_START; - /* test if whole packet read */ if (package_done) { buf->decoder_flags |= BUF_FLAG_FRAME_END; -- cgit v1.2.3 From 1324f12dc8213fc0f7e4549665f7d3f5b7f3100e Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Sat, 12 Jan 2008 16:51:25 +0100 Subject: Fixed metadata reading when length=0. Fixed bug id=17. --- src/demuxers/asfheader.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/demuxers/asfheader.c b/src/demuxers/asfheader.c index ea92f878b..eb74c0886 100644 --- a/src/demuxers/asfheader.c +++ b/src/demuxers/asfheader.c @@ -142,9 +142,9 @@ static uint8_t *asf_reader_get_bytes(asf_reader_t *reader, size_t size) { static char *asf_reader_get_string(asf_reader_t *reader, size_t size, iconv_t cd) { char *inbuf, *outbuf; size_t inbytesleft, outbytesleft; - char scratch[2048]; + char scratch[2048]; - if ((reader->size - reader->pos) < size) + if ((size == 0) ||((reader->size - reader->pos) < size)) return NULL; inbuf = (char *)reader->buffer + reader->pos; @@ -599,6 +599,12 @@ static int asf_header_parse_content_description(asf_header_t *header_pub, uint8_ content->description = asf_reader_get_string(&reader, description_length, header->iconv_cd); content->rating = asf_reader_get_string(&reader, rating_length, header->iconv_cd); + lprintf("title: %d chars: \"%s\"\n", title_length, content->title); + lprintf("author: %d chars: \"%s\"\n", author_length, content->author); + lprintf("copyright: %d chars: \"%s\"\n", copyright_length, content->copyright); + lprintf("description: %d chars: \"%s\"\n", description_length, content->description); + lprintf("rating: %d chars: \"%s\"\n", rating_length, content->rating); + header->pub.content = content; return 1; } -- cgit v1.2.3 From 1a2ce4b7f270a680f2510a525926ba31b8b385f0 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Sun, 13 Jan 2008 17:27:39 +0100 Subject: Added data accumulation logic. Fixed bug id=2. --- src/libxineadec/xine_vorbis_decoder.c | 250 +++++++++++++++++++--------------- 1 file changed, 141 insertions(+), 109 deletions(-) diff --git a/src/libxineadec/xine_vorbis_decoder.c b/src/libxineadec/xine_vorbis_decoder.c index 4b7a6c15d..b3acff811 100644 --- a/src/libxineadec/xine_vorbis_decoder.c +++ b/src/libxineadec/xine_vorbis_decoder.c @@ -41,6 +41,7 @@ #include #define MAX_NUM_SAMPLES 4096 +#define INIT_BUFSIZE 8192 typedef struct { audio_decoder_class_t decoder_class; @@ -70,6 +71,11 @@ typedef struct vorbis_decoder_s { xine_stream_t *stream; + /* data accumulation stuff */ + unsigned char *buf; + int bufsize; + int size; + } vorbis_decoder_t; @@ -78,6 +84,7 @@ static void vorbis_reset (audio_decoder_t *this_gen) { vorbis_decoder_t *this = (vorbis_decoder_t *) this_gen; if( this->header_count ) return; + this->size = 0; /* clear block first, as it might contain allocated data */ vorbis_block_clear(&this->vb); @@ -136,126 +143,147 @@ static void get_metadata (vorbis_decoder_t *this) { _x_meta_info_set_utf8(this->stream, XINE_META_INFO_AUDIOCODEC, "vorbis"); } +static void vorbis_check_bufsize (vorbis_decoder_t *this, int size) { + if (size > this->bufsize) { + this->bufsize = size + size / 2; + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + _("vorbis: increasing buffer to %d to avoid overflow.\n"), + this->bufsize); + this->buf = realloc(this->buf, this->bufsize); + } +} + static void vorbis_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { vorbis_decoder_t *this = (vorbis_decoder_t *) this_gen; memset( &this->op, 0, sizeof(this->op) ); - this->op.packet = buf->content; - this->op.bytes = buf->size; - - if ( (buf->decoder_flags & BUF_FLAG_HEADER) && - !(buf->decoder_flags & BUF_FLAG_STDHEADER) ) { - lprintf ("%d headers to go\n", this->header_count); - if (this->header_count) { - int res = 0; + /* data accumulation */ + vorbis_check_bufsize(this, this->size + buf->size); + xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); + this->size += buf->size; - if (this->header_count == 3) - this->op.b_o_s = 1; + if (buf->decoder_flags & BUF_FLAG_FRAME_END) { + this->op.packet = this->buf; + this->op.bytes = this->size; - - if( (res = vorbis_synthesis_headerin(&this->vi,&this->vc,&this->op)) < 0 ){ - /* error case; not a vorbis header */ - xine_log(this->stream->xine, XINE_LOG_MSG, "libvorbis: this bitstream does not contain vorbis audio data. Following first 64 bytes (return: %d).\n", res); - xine_hexdump((char *)this->op.packet, this->op.bytes < 64 ? this->op.bytes : 64); - return; - } - - this->header_count--; - - if (!this->header_count) { - - int mode = AO_CAP_MODE_MONO; - - get_metadata (this); - - mode = _x_ao_channels2mode(this->vi.channels); - - this->convsize=MAX_NUM_SAMPLES/this->vi.channels; - - if (!this->output_open) { - this->output_open = (this->stream->audio_out->open) (this->stream->audio_out, - this->stream, - 16, - this->vi.rate, - mode) ; - - _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, - this->vi.bitrate_nominal); - - } - - /* OK, got and parsed all three headers. Initialize the Vorbis - * packet->PCM decoder. */ - lprintf("all three headers parsed. initializing decoder.\n"); - /* initialize central decode state */ - vorbis_synthesis_init(&this->vd,&this->vi); - /* initialize local state for most of the decode so multiple - * block decodes can proceed in parallel. We could init - * multiple vorbis_block structures for vd here */ - vorbis_block_init(&this->vd,&this->vb); + /* reset accumultaion buffer */ + this->size = 0; + + if ( (buf->decoder_flags & BUF_FLAG_HEADER) && + !(buf->decoder_flags & BUF_FLAG_STDHEADER) ) { + + lprintf ("%d headers to go\n", this->header_count); + + if (this->header_count) { + int res = 0; + + if (this->header_count == 3) + this->op.b_o_s = 1; + + if ( (res = vorbis_synthesis_headerin(&this->vi,&this->vc,&this->op)) < 0 ) { + /* error case; not a vorbis header */ + xine_log(this->stream->xine, XINE_LOG_MSG, "libvorbis: this bitstream does not contain vorbis audio data. Following first 64 bytes (return: %d).\n", res); + xine_hexdump((char *)this->op.packet, this->op.bytes < 64 ? this->op.bytes : 64); + return; + } + + this->header_count--; + + if (!this->header_count) { + + int mode = AO_CAP_MODE_MONO; + + get_metadata (this); + + mode = _x_ao_channels2mode(this->vi.channels); + + this->convsize=MAX_NUM_SAMPLES/this->vi.channels; + + if (!this->output_open) { + this->output_open = (this->stream->audio_out->open) (this->stream->audio_out, + this->stream, + 16, + this->vi.rate, + mode) ; + + _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_BITRATE, + this->vi.bitrate_nominal); + + } + + /* OK, got and parsed all three headers. Initialize the Vorbis + * packet->PCM decoder. */ + lprintf("all three headers parsed. initializing decoder.\n"); + /* initialize central decode state */ + vorbis_synthesis_init(&this->vd,&this->vi); + /* initialize local state for most of the decode so multiple + * block decodes can proceed in parallel. We could init + * multiple vorbis_block structures for vd here */ + vorbis_block_init(&this->vd,&this->vb); + } } - } - - } else if (this->output_open) { - - float **pcm; - int samples; - - if(vorbis_synthesis(&this->vb,&this->op)==0) - vorbis_synthesis_blockin(&this->vd,&this->vb); - - if (buf->pts!=0) - this->pts=buf->pts; - - while ((samples=vorbis_synthesis_pcmout(&this->vd,&pcm))>0){ - - /* **pcm is a multichannel float vector. In stereo, for - * example, pcm[0][...] is left, and pcm[1][...] is right. - * samples is the size of each channel. Convert the float - * values (-1.<=range<=1.) to whatever PCM format and write - * it out - */ - - int i,j; - int bout=(samplesconvsize?samples:this->convsize); - audio_buffer_t *audio_buffer; - - audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); - - /* convert floats to 16 bit signed ints (host order) and - interleave */ - for(i=0;ivi.channels;i++){ - ogg_int16_t *ptr=audio_buffer->mem+i; - float *mono=pcm[i]; - for(j=0;j32767){ - val=32767; - } else if(val<-32768){ - val=-32768; - } - *ptr=val; - ptr+=this->vi.channels; - } + + } else if (this->output_open) { + + float **pcm; + int samples; + + if(vorbis_synthesis(&this->vb,&this->op)==0) + vorbis_synthesis_blockin(&this->vd,&this->vb); + + if (buf->pts!=0) + this->pts=buf->pts; + + while ((samples=vorbis_synthesis_pcmout(&this->vd,&pcm))>0){ + + /* **pcm is a multichannel float vector. In stereo, for + * example, pcm[0][...] is left, and pcm[1][...] is right. + * samples is the size of each channel. Convert the float + * values (-1.<=range<=1.) to whatever PCM format and write + * it out + */ + + int i,j; + int bout=(samplesconvsize?samples:this->convsize); + audio_buffer_t *audio_buffer; + + audio_buffer = this->stream->audio_out->get_buffer (this->stream->audio_out); + + /* convert floats to 16 bit signed ints (host order) and + interleave */ + for(i=0;ivi.channels;i++){ + ogg_int16_t *ptr=audio_buffer->mem+i; + float *mono=pcm[i]; + for(j=0;j32767){ + val=32767; + } else if(val<-32768){ + val=-32768; + } + *ptr=val; + ptr+=this->vi.channels; + } + } + + audio_buffer->vpts = this->pts; + this->pts=0; + audio_buffer->num_frames = bout; + + this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); + + buf->pts=0; + + /* tell libvorbis how many samples we actually consumed */ + vorbis_synthesis_read(&this->vd,bout); } - - audio_buffer->vpts = this->pts; - this->pts=0; - audio_buffer->num_frames = bout; - - this->stream->audio_out->put_buffer (this->stream->audio_out, audio_buffer, this->stream); - - buf->pts=0; - - /* tell libvorbis how many samples we actually consumed */ - vorbis_synthesis_read(&this->vd,bout); + } else { + lprintf("output not open\n"); } - } else { - lprintf("output not open\n"); } } @@ -299,6 +327,10 @@ static audio_decoder_t *open_plugin (audio_decoder_class_t *class_gen, this->header_count = 3; this->convsize = 0; + this->bufsize = INIT_BUFSIZE; + this->buf = xine_xmalloc(INIT_BUFSIZE); + this->size = 0; + vorbis_info_init(&this->vi); vorbis_comment_init(&this->vc); -- cgit v1.2.3 From 88f40cf978d542151b289b4ca1ded713b6eb812a Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 13 Jan 2008 17:48:08 +0000 Subject: Bump version no. ready for what I expect to be the next release. --HG-- extra : transplant_source : q%B3q%EEC%D4p%E7%7F%8Eb%BE%F8%81%D3c%F6%C8%1AF --- ChangeLog | 2 ++ configure.ac | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index f7e8b3243..1b4526e66 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ +xine-lib (1.1.10) (unreleased) + xine-lib (1.1.9.1) * Security fixes: - Fix a buffer overflow in RTSP header-handling code. (CVE-2008-0225) diff --git a/configure.ac b/configure.ac index f92318924..813c5c83a 100644 --- a/configure.ac +++ b/configure.ac @@ -16,9 +16,9 @@ dnl XINE_SUB += 1; XINE_PATCH = ''; continue with XINE_LT_* values below dnl XINE_MAJOR=1 XINE_MINOR=1 -XINE_SUB=9 +XINE_SUB=10 # XINE_PATCH should be left empty or set to ".1" or ".2" or something similar -XINE_PATCH=.1 +XINE_PATCH= #if test $XINE_SUB -eq 0 ; then # XINE_SUBPART=""; -- cgit v1.2.3 From 934857924c40f5fc075359f8ad60bf49e4687d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Mon, 14 Jan 2008 19:45:14 +0100 Subject: Support all the extensions reported by xiph's documentation (plus ogm). --- src/demuxers/demux_ogg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/demuxers/demux_ogg.c b/src/demuxers/demux_ogg.c index 9ed39f12d..43ab3cb36 100644 --- a/src/demuxers/demux_ogg.c +++ b/src/demuxers/demux_ogg.c @@ -2155,7 +2155,7 @@ static const char *ogg_get_identifier (demux_class_t *this_gen) { } static const char *ogg_get_extensions (demux_class_t *this_gen) { - return "ogg ogm spx"; + return "ogx ogv oga ogg spx ogm"; } static const char *ogg_get_mimetypes (demux_class_t *this_gen) { -- cgit v1.2.3 From 7558fb41b257c2d05e243c9c3640bf5c08c4808d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Mon, 14 Jan 2008 20:05:42 +0100 Subject: Update mimetypes for Annodex and Ogg. --- src/demuxers/demux_ogg.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/demuxers/demux_ogg.c b/src/demuxers/demux_ogg.c index 43ab3cb36..d1b522727 100644 --- a/src/demuxers/demux_ogg.c +++ b/src/demuxers/demux_ogg.c @@ -2118,7 +2118,9 @@ static const char *anx_get_extensions (demux_class_t *this_gen) { } static const char *anx_get_mimetypes (demux_class_t *this_gen) { - return "application/x-annodex: ogg: Annodex media;"; + return "application/annodex: anx: Annodex media;" + "audio/annodex: axa: Annodex audio;" + "video/annodex: axv: Annodex video;"; } static void anx_class_dispose (demux_class_t *this_gen) { @@ -2159,10 +2161,9 @@ static const char *ogg_get_extensions (demux_class_t *this_gen) { } static const char *ogg_get_mimetypes (demux_class_t *this_gen) { - return "audio/x-ogg: ogg: OggVorbis Audio;" - "audio/x-speex: ogg: Speex Audio;" - "application/x-ogg: ogg: Ogg Stream;" - "application/ogg: ogg: Ogg Stream;"; + return "application/ogg: ogx: Ogg Stream;" + "audio/ogg: oga: Ogg Audio;" + "video/ogg: ogv: Ogg Video;"; } static void ogg_class_dispose (demux_class_t *this_gen) { -- cgit v1.2.3 From 748929e7950069870e350668542814c3ee0fd2e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Mon, 14 Jan 2008 20:06:44 +0100 Subject: ChangeLog entries for the last two revisions. --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index 1b4526e66..cdcab1d00 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ xine-lib (1.1.10) (unreleased) + * Update Ogg and Annodex mimetypes and extensions. xine-lib (1.1.9.1) * Security fixes: -- cgit v1.2.3 From 4392eb46e57120ef2c17d34ed07df089c16cd730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Mon, 14 Jan 2008 20:08:23 +0100 Subject: Update demuxer for 1.2 branch to the correct extensions and mimetype declared by Xiph. --- src/combined/xine_ogg_demuxer.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/combined/xine_ogg_demuxer.c b/src/combined/xine_ogg_demuxer.c index d6b5ea214..f5a1e5306 100644 --- a/src/combined/xine_ogg_demuxer.c +++ b/src/combined/xine_ogg_demuxer.c @@ -2079,7 +2079,10 @@ static void *anx_init_class (xine_t *xine, void *data) { this->demux_class.open_plugin = anx_open_plugin; this->demux_class.description = N_("Annodex demux plugin"); this->demux_class.identifier = "Annodex"; - this->demux_class.mimetypes = "application/x-annodex: ogg: Annodex media;"; + this->demux_class.mimetypes = + "application/annodex: anx: Annodex media;" + "audio/annodex: axa: Annodex audio;" + "video/annodex: axv: Annodex video;"; this->demux_class.extensions = "anx axa axv"; this->demux_class.dispose = default_demux_class_dispose; @@ -2098,11 +2101,10 @@ static void *ogg_init_class (xine_t *xine, void *data) { this->demux_class.description = N_("OGG demux plugin"); this->demux_class.identifier = "OGG"; this->demux_class.mimetypes = - "audio/x-ogg: ogg: OggVorbis Audio;" - "audio/x-speex: ogg: Speex Audio;" - "application/x-ogg: ogg: Ogg Stream;" - "application/ogg: ogg: Ogg Stream;"; - this->demux_class.extensions = "ogg ogm spx"; + "application/ogg: ogx: Ogg Stream;" + "audio/ogg: oga: Ogg Audio;" + "video/ogg: ogv: Ogg Video;" + this->demux_class.extensions = "ogx ogv oga ogg spx ogm"; this->demux_class.dispose = default_demux_class_dispose; return this; -- cgit v1.2.3 From 0c0e9b541318da072be829d920d5ae47676d3dba Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Mon, 14 Jan 2008 22:59:05 +0000 Subject: Bump the Debian package version no. --HG-- extra : transplant_source : %D9%DE%C7%C9%CB%D9%84%1E%A2%A0%AD%A9%E1%C27%EA%C6%E5%A3A --- debian/changelog | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 91999074d..6c3d1ab7d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -xine-lib (1.1.9~hg-0) unstable; urgency=low +xine-lib (1.1.10~hg-0) unstable; urgency=low [ Darren Salt ] * Hg snapshot. @@ -7,7 +7,7 @@ xine-lib (1.1.9~hg-0) unstable; urgency=low * remove gs from build-dependencies * change the maintainer field to xine-devel@lists.sourceforge.net. - -- Reinhard Tartler Sun, 25 Nov 2007 23:45:52 +0100 + -- Darren Salt Mon, 14 Jan 2008 22:57:42 +0000 xine-lib (1.1.5~cvs-0) unstable; urgency=low -- cgit v1.2.3 From bc09805e004f1a68d7a632a38ed6309f6c9ec356 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Mon, 14 Jan 2008 23:24:15 +0000 Subject: Change the default v4l device paths to /dev/{video,radio}0. --- ChangeLog | 1 + src/input/input_v4l.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index cdcab1d00..ec47096eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ xine-lib (1.1.10) (unreleased) * Update Ogg and Annodex mimetypes and extensions. + * Change the default v4l device paths to /dev/video0 and /dev/radio0. xine-lib (1.1.9.1) * Security fixes: diff --git a/src/input/input_v4l.c b/src/input/input_v4l.c index b43a2684a..34f6a0684 100644 --- a/src/input/input_v4l.c +++ b/src/input/input_v4l.c @@ -91,8 +91,8 @@ static const resolution_t resolutions[] = { }; #define NUM_RESOLUTIONS (sizeof(resolutions)/sizeof(resolutions[0])) -#define RADIO_DEV "/dev/v4l/radio0" -#define VIDEO_DEV "/dev/v4l/video0" +#define RADIO_DEV "/dev/radio0" +#define VIDEO_DEV "/dev/video0" #if !defined(NDELAY) && defined(O_NDELAY) #define FNDELAY O_NDELAY -- cgit v1.2.3 From fa109cc055ecf40ec01f82f313ed2cccf094bbaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 15 Jan 2008 16:31:32 +0100 Subject: Fix missing semicolon. --- src/combined/xine_ogg_demuxer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/combined/xine_ogg_demuxer.c b/src/combined/xine_ogg_demuxer.c index f5a1e5306..e0610f5ca 100644 --- a/src/combined/xine_ogg_demuxer.c +++ b/src/combined/xine_ogg_demuxer.c @@ -2103,7 +2103,7 @@ static void *ogg_init_class (xine_t *xine, void *data) { this->demux_class.mimetypes = "application/ogg: ogx: Ogg Stream;" "audio/ogg: oga: Ogg Audio;" - "video/ogg: ogv: Ogg Video;" + "video/ogg: ogv: Ogg Video;"; this->demux_class.extensions = "ogx ogv oga ogg spx ogm"; this->demux_class.dispose = default_demux_class_dispose; -- cgit v1.2.3 From 07b372828b7b4b1337331ff16ebdab1482609e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 15 Jan 2008 16:49:29 +0100 Subject: Check if the linker supports --gc-sections, and if so use it for the plugins. This way the unused parts of internal copies of libraries can be get rid of by the linker. --- configure.ac | 3 +++ misc/Makefile.common | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 926620303..cdb196f79 100644 --- a/configure.ac +++ b/configure.ac @@ -480,6 +480,9 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[int a; memset(&a, [warnflags="$warnflags -Wpointer-arith" AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])]) +CC_CHECK_LDFLAGS([-Wl,--gc-sections], [GCSECTIONS="-Wl,--gc-sections"]) +AC_SUBST([GCSECTIONS]) + dnl FreeBSD (et al.) does not complete linking for shared objects when pthreads dnl are requested, as different implementations are present; to avoid problems dnl use -Wl,-z,defs only for those platforms not behaving this way. diff --git a/misc/Makefile.common b/misc/Makefile.common index edafcea4b..447b558e2 100644 --- a/misc/Makefile.common +++ b/misc/Makefile.common @@ -3,7 +3,7 @@ XINE_LIB = $(top_builddir)/src/xine-engine/libxine.la xineincludedir = $(includedir)/xine xineplugdir = $(XINE_PLUGINDIR) -xineplug_ldflags = $(NOUNDEF) -avoid-version -module +xineplug_ldflags = $(NOUNDEF) $(GCSECTIONS) -avoid-version -module xinepostdir = $(XINE_PLUGINDIR)/post vidixdir = $(XINE_PLUGINDIR)/vidix -- cgit v1.2.3 From c5cfb81f1de09183e045568e7b72e47d43733b36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 15 Jan 2008 17:01:37 +0100 Subject: Fix test for external dts that caused internal copy to be used instead. --- m4/decoders.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/m4/decoders.m4 b/m4/decoders.m4 index 3552ba6a2..0ab38af29 100644 --- a/m4/decoders.m4 +++ b/m4/decoders.m4 @@ -173,7 +173,7 @@ use internal ffmpeg. else AC_MSG_RESULT([Using included libdts support]) fi - if test x"$have_external_libdts" != x"yes"; then + if test x"$have_external_dts" != x"yes"; then LIBDTS_CFLAGS='-I$(top_srcdir)/contrib/libdca/include' LIBDTS_DEPS='$(top_builddir)/contrib/libdca/libdca.la' LIBDTS_LIBS='$(top_builddir)/contrib/libdca/libdca.la' -- cgit v1.2.3 From e5ad26d14f37f097be7284dbf972ddae35dfec36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Tue, 15 Jan 2008 17:09:22 +0100 Subject: Use GCSECTIONS for libxine too. --- src/xine-engine/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xine-engine/Makefile.am b/src/xine-engine/Makefile.am index 49757f841..2942d3560 100644 --- a/src/xine-engine/Makefile.am +++ b/src/xine-engine/Makefile.am @@ -33,7 +33,7 @@ libxine_la_LIBADD = $(PTHREAD_LIBS) $(DYNAMIC_LD_LIBS) $(LTLIBINTL) $(ZLIB_LIBS) -lm $(XINEUTILS_LIB) $(LTLIBICONV) $(FT2_LIBS) $(FONTCONFIG_LIBS) \ $(LIBXINEPOSIX) $(RT_LIBS) $(NET_LIBS) $(XDG_BASEDIR_LIBS) -libxine_la_LDFLAGS = $(AM_LDFLAGS) $(def_ldflags) \ +libxine_la_LDFLAGS = $(AM_LDFLAGS) $(def_ldflags) $(GCSECTIONS) \ -version-info $(XINE_LT_CURRENT):$(XINE_LT_REVISION):$(XINE_LT_AGE) $(XINEUTILS_LIB): -- cgit v1.2.3 From eef1dd9c03642f1abeee307a6786566ce3ef7e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 16 Jan 2008 19:45:26 +0100 Subject: Remove deprecated unused functions. --- src/input/input_dvb.c | 3 --- src/input/input_pnm.c | 2 -- src/input/input_rtsp.c | 2 -- src/input/net_buf_ctrl.c | 23 ----------------------- src/input/net_buf_ctrl.h | 6 ------ 5 files changed, 36 deletions(-) diff --git a/src/input/input_dvb.c b/src/input/input_dvb.c index b3a9d8e46..07aefc362 100644 --- a/src/input/input_dvb.c +++ b/src/input/input_dvb.c @@ -2496,9 +2496,6 @@ static off_t dvb_plugin_read (input_plugin_t *this_gen, "input_dvb: reading %" PRIdMAX " bytes...\n", (intmax_t)len); #endif -#ifndef DVB_NO_BUFFERING - nbc_check_buffers (this->nbc); -#endif /* protect against channel changes */ have_mutex = pthread_mutex_lock(&this->channel_change_mutex); total=0; diff --git a/src/input/input_pnm.c b/src/input/input_pnm.c index 3271a04c9..e11e3b361 100644 --- a/src/input/input_pnm.c +++ b/src/input/input_pnm.c @@ -83,8 +83,6 @@ static off_t pnm_plugin_read (input_plugin_t *this_gen, lprintf ("pnm_plugin_read: %"PRId64" bytes ...\n", len); - nbc_check_buffers (this->nbc); - n = pnm_read (this->pnm, buf, len); this->curpos += n; diff --git a/src/input/input_rtsp.c b/src/input/input_rtsp.c index bee192c0d..e2b1bae99 100644 --- a/src/input/input_rtsp.c +++ b/src/input/input_rtsp.c @@ -83,8 +83,6 @@ static off_t rtsp_plugin_read (input_plugin_t *this_gen, lprintf ("rtsp_plugin_read: %"PRId64" bytes ...\n", len); - nbc_check_buffers (this->nbc); - n = rtsp_session_read (this->rtsp, buf, len); this->curpos += n; diff --git a/src/input/net_buf_ctrl.c b/src/input/net_buf_ctrl.c index aaf575e40..03a24d38f 100644 --- a/src/input/net_buf_ctrl.c +++ b/src/input/net_buf_ctrl.c @@ -113,10 +113,6 @@ static void nbc_set_speed_normal (nbc_t *this) { stream->xine->clock->set_option (stream->xine->clock, CLOCK_SCR_ADJUSTABLE, 1); } -void nbc_check_buffers (nbc_t *this) { - /* Deprecated */ -} - static void display_stats (nbc_t *this) { static const char buffering[2][4] = {" ", "buf"}; static const char enabled[2][4] = {"off", "on "}; @@ -564,22 +560,3 @@ void nbc_close (nbc_t *this) { free (this); xprintf(xine, XINE_VERBOSITY_DEBUG, "\nnet_buf_ctrl: nbc_close: done\n"); } - - -void nbc_set_high_water_mark(nbc_t *this, int value) { -/* - Deprecated - this->high_water_mark = value; -*/ - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "\nnet_buf_ctrl: this method is deprecated, please fix the input plugin\n"); -} - -void nbc_set_low_water_mark(nbc_t *this, int value) { -/* - Deprecated - this->low_water_mark = value; -*/ - xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, - "\nnet_buf_ctrl: this method is deprecated, please fix the input plugin\n"); -} diff --git a/src/input/net_buf_ctrl.h b/src/input/net_buf_ctrl.h index c35187179..87d6d84a1 100644 --- a/src/input/net_buf_ctrl.h +++ b/src/input/net_buf_ctrl.h @@ -29,12 +29,6 @@ typedef struct nbc_s nbc_t; nbc_t *nbc_init (xine_stream_t *xine); -void nbc_check_buffers (nbc_t *this); - void nbc_close (nbc_t *this); -void nbc_set_high_water_mark(nbc_t *this, int value); - -void nbc_set_low_water_mark(nbc_t *this, int value); - #endif -- cgit v1.2.3 From abef42f0fb968e8489b2ac46963530ab81e2f3c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 16 Jan 2008 19:49:58 +0100 Subject: Make _x_canonicalise_url an inline function, as it's only ever used once (either in input_http or in the test for http_helper). --- src/input/http_helper.c | 23 ----------------------- src/input/http_helper.h | 24 +++++++++++++++++++++++- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/input/http_helper.c b/src/input/http_helper.c index 83562c9dc..f4950a084 100644 --- a/src/input/http_helper.c +++ b/src/input/http_helper.c @@ -220,29 +220,6 @@ error: return 0; } -char *_x_canonicalise_url (const char *base, const char *url) { - - size_t base_length; - char *cut, *ret; - - if ((cut = strstr (url, "://"))) - return strdup (url); - - cut = strstr (base, "://"); - if (url[0] == '/') { - /* absolute - base up to first '/' after "://", then url */ - cut = strchr (cut + 3, '/'); - } - else { - /* relative - base up to & inc. last '/', then url */ - cut = strrchr (cut, '/'); - if (cut) - ++cut; - } - base_length = cut ? (size_t)(cut - base) : strlen (base); - asprintf (&ret, "%.*s%s", (int)base_length, base, url); - return ret; -} #ifdef TEST_URL /* diff --git a/src/input/http_helper.h b/src/input/http_helper.h index 3ce3f2b7c..9baa05235 100644 --- a/src/input/http_helper.h +++ b/src/input/http_helper.h @@ -43,6 +43,28 @@ int _x_parse_url (char *url, char **proto, char** host, int *port, * return: * the canonicalised URL (caller must free() it) */ -char *_x_canonicalise_url (const char *base, const char *url); +static inline char *_x_canonicalise_url (const char *base, const char *url) { + + size_t base_length; + char *cut, *ret; + + if ((cut = strstr (url, "://"))) + return strdup (url); + + cut = strstr (base, "://"); + if (url[0] == '/') { + /* absolute - base up to first '/' after "://", then url */ + cut = strchr (cut + 3, '/'); + } + else { + /* relative - base up to & inc. last '/', then url */ + cut = strrchr (cut, '/'); + if (cut) + ++cut; + } + base_length = cut ? (size_t)(cut - base) : strlen (base); + asprintf (&ret, "%.*s%s", (int)base_length, base, url); + return ret; +} #endif /* HTTP_HELPER_H */ -- cgit v1.2.3 From 1adcc214c14fb6d8a5c78ff62e4bb16f1c1d1e28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 16 Jan 2008 20:00:50 +0100 Subject: Put under #if 0 a few functions that never gets used in xine at all. --- src/input/libreal/rmff.c | 6 ++++++ src/input/libreal/rmff.h | 6 ++++++ src/input/librtsp/rtsp.c | 6 ++++++ src/input/librtsp/rtsp.h | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/src/input/libreal/rmff.c b/src/input/libreal/rmff.c index 0e803e4d4..1600e967a 100644 --- a/src/input/libreal/rmff.c +++ b/src/input/libreal/rmff.c @@ -475,6 +475,7 @@ rmff_header_t *rmff_scan_header(const char *data) { return header; } +#if 0 rmff_header_t *rmff_scan_header_stream(int fd) { rmff_header_t *header; @@ -525,6 +526,7 @@ void rmff_scan_pheader(rmff_pheader_t *h, char *data) { h->reserved=(uint8_t)data[10]; h->flags=(uint8_t)data[11]; } +#endif rmff_fileheader_t *rmff_new_fileheader(uint32_t num_headers) { @@ -670,6 +672,7 @@ rmff_data_t *rmff_new_dataheader(uint32_t num_packets, uint32_t next_data_header return data; } +#if 0 void rmff_print_header(rmff_header_t *h) { rmff_mdpr_t **stream; @@ -736,6 +739,7 @@ void rmff_print_header(rmff_header_t *h) { printf("next DATA : 0x%08x\n", h->data->next_data_header); } } +#endif void rmff_fix_header(rmff_header_t *h) { @@ -844,6 +848,7 @@ void rmff_fix_header(rmff_header_t *h) { } } +#if 0 int rmff_get_header_size(rmff_header_t *h) { if (!h) return 0; @@ -883,3 +888,4 @@ void rmff_free_header(rmff_header_t *h) { } free(h); } +#endif diff --git a/src/input/libreal/rmff.h b/src/input/libreal/rmff.h index 2521ebda6..3fe3af284 100644 --- a/src/input/libreal/rmff.h +++ b/src/input/libreal/rmff.h @@ -222,6 +222,7 @@ rmff_data_t *rmff_new_dataheader( */ rmff_header_t *rmff_scan_header(const char *data); +#if 0 /* * scans a data packet header. Notice, that this function does not allocate * the header struct itself. @@ -237,16 +238,19 @@ rmff_header_t *rmff_scan_header_stream(int fd); * prints header information in human readible form to stdout */ void rmff_print_header(rmff_header_t *h); +#endif /* * does some checks and fixes header if possible */ void rmff_fix_header(rmff_header_t *h); +#if 0 /* * returns the size of the header (incl. first data-header) */ int rmff_get_header_size(rmff_header_t *h); +#endif /* * dumps the header to . is the size of @@ -258,9 +262,11 @@ int rmff_dump_header(rmff_header_t *h, void *buffer, int max); */ void rmff_dump_pheader(rmff_pheader_t *h, uint8_t *data); +#if 0 /* * frees a header struct */ void rmff_free_header(rmff_header_t *h); +#endif #endif diff --git a/src/input/librtsp/rtsp.c b/src/input/librtsp/rtsp.c index cd844654b..c660751fe 100644 --- a/src/input/librtsp/rtsp.c +++ b/src/input/librtsp/rtsp.c @@ -359,12 +359,14 @@ int rtsp_request_play(rtsp_t *s, const char *what) { return rtsp_get_answers(s); } +#if 0 int rtsp_request_tearoff(rtsp_t *s, const char *what) { rtsp_send_request(s,"TEAROFF",what); return rtsp_get_answers(s); } +#endif /* * read opaque data from stream @@ -557,6 +559,7 @@ char *rtsp_search_answers(rtsp_t *s, const char *tag) { return NULL; } +#if 0 /* * session id management */ @@ -574,6 +577,7 @@ char *rtsp_get_session(rtsp_t *s) { return s->session; } +#endif char *rtsp_get_mrl(rtsp_t *s) { @@ -597,6 +601,7 @@ void rtsp_schedule_field(rtsp_t *s, const char *string) { s->scheduled[i]=strdup(string); } +#if 0 /* * removes the first scheduled field which prefix matches string. */ @@ -617,6 +622,7 @@ void rtsp_unschedule_field(rtsp_t *s, const char *string) { *(ptr-1)=*ptr; } while(*ptr); } +#endif /* * unschedule all fields diff --git a/src/input/librtsp/rtsp.h b/src/input/librtsp/rtsp.h index 3c829e2e8..1cec57e1e 100644 --- a/src/input/librtsp/rtsp.h +++ b/src/input/librtsp/rtsp.h @@ -47,7 +47,9 @@ int rtsp_request_describe(rtsp_t *s, const char *what); int rtsp_request_setup(rtsp_t *s, const char *what); int rtsp_request_setparameter(rtsp_t *s, const char *what); int rtsp_request_play(rtsp_t *s, const char *what); +#if 0 int rtsp_request_tearoff(rtsp_t *s, const char *what); +#endif int rtsp_send_ok(rtsp_t *s); @@ -61,15 +63,19 @@ void rtsp_free_answers(rtsp_t *this); int rtsp_read (rtsp_t *this, char *data, int len); void rtsp_close (rtsp_t *this); +#if 0 void rtsp_set_session(rtsp_t *s, const char *id); char *rtsp_get_session(rtsp_t *s); +#endif char *rtsp_get_mrl(rtsp_t *s); /*int rtsp_peek_header (rtsp_t *this, char *data); */ void rtsp_schedule_field(rtsp_t *s, const char *string); +#if 0 void rtsp_unschedule_field(rtsp_t *s, const char *string); +#endif void rtsp_unschedule_all(rtsp_t *s); #endif -- cgit v1.2.3 From e0f1a28dfc53c6ef22307e6e474605e47539f035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 16 Jan 2008 20:03:10 +0100 Subject: Put under #if 0 a few functions that never gets used in xine at all. --- src/demuxers/ebml.c | 4 ++++ src/demuxers/ebml.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/demuxers/ebml.c b/src/demuxers/ebml.c index 772b848eb..41a91371e 100644 --- a/src/demuxers/ebml.c +++ b/src/demuxers/ebml.c @@ -234,6 +234,7 @@ int ebml_read_uint(ebml_parser_t *ebml, ebml_elem_t *elem, uint64_t *num) { return 1; } +#if 0 int ebml_read_sint (ebml_parser_t *ebml, ebml_elem_t *elem, int64_t *num) { uint8_t data[8]; uint64_t size = elem->len; @@ -260,6 +261,7 @@ int ebml_read_sint (ebml_parser_t *ebml, ebml_elem_t *elem, int64_t *num) { return 1; } +#endif int ebml_read_float (ebml_parser_t *ebml, ebml_elem_t *elem, double *num) { @@ -304,6 +306,7 @@ int ebml_read_ascii(ebml_parser_t *ebml, ebml_elem_t *elem, char *str) { return 1; } +#if 0 int ebml_read_utf8 (ebml_parser_t *ebml, ebml_elem_t *elem, char *str) { return ebml_read_ascii (ebml, elem, str); } @@ -311,6 +314,7 @@ int ebml_read_utf8 (ebml_parser_t *ebml, ebml_elem_t *elem, char *str) { int ebml_read_date (ebml_parser_t *ebml, ebml_elem_t *elem, int64_t *date) { return ebml_read_sint (ebml, elem, date); } +#endif int ebml_read_master (ebml_parser_t *ebml, ebml_elem_t *elem) { ebml_elem_t *top_elem; diff --git a/src/demuxers/ebml.h b/src/demuxers/ebml.h index 7ebd68da2..31d825e35 100644 --- a/src/demuxers/ebml.h +++ b/src/demuxers/ebml.h @@ -83,15 +83,19 @@ int ebml_skip(ebml_parser_t *ebml, ebml_elem_t *elem); /* EBML types */ int ebml_read_uint(ebml_parser_t *ebml, ebml_elem_t *elem, uint64_t *val); +#if 0 int ebml_read_sint(ebml_parser_t *ebml, ebml_elem_t *elem, int64_t *val); +#endif int ebml_read_float(ebml_parser_t *ebml, ebml_elem_t *elem, double *val); int ebml_read_ascii(ebml_parser_t *ebml, ebml_elem_t *elem, char *str); +#if 0 int ebml_read_utf8(ebml_parser_t *ebml, ebml_elem_t *elem, char *str); int ebml_read_date(ebml_parser_t *ebml, ebml_elem_t *elem, int64_t *date); +#endif int ebml_read_master(ebml_parser_t *ebml, ebml_elem_t *elem); -- cgit v1.2.3 From e454b8cfad52523f96edafefd6e6392646c005de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 16 Jan 2008 20:03:58 +0100 Subject: Remove function never used in xine. --- src/post/visualizations/fft.c | 12 ------------ src/post/visualizations/fft.h | 1 - 2 files changed, 13 deletions(-) diff --git a/src/post/visualizations/fft.c b/src/post/visualizations/fft.c index e9a99911a..01044987b 100644 --- a/src/post/visualizations/fft.c +++ b/src/post/visualizations/fft.c @@ -183,18 +183,6 @@ double fft_amp (int n, complex_t wave[], int bits) return (hypot (REAL(n), IMAG(n))); } -/* - * Calculate phase of component n in the decimated wave[] array. - */ -double fft_phase (int n, complex_t wave[], int bits) -{ - n = PERMUTE (n, bits); - if (REAL(n) != 0.0) - return (atan (IMAG(n) / REAL(n))); - else - return (0.0); -} - /* * Scale sampled values. * Do this *before* the fft. diff --git a/src/post/visualizations/fft.h b/src/post/visualizations/fft.h index dff3cd7e8..1600430bc 100644 --- a/src/post/visualizations/fft.h +++ b/src/post/visualizations/fft.h @@ -44,7 +44,6 @@ void fft_compute (fft_t *fft, complex_t wave[]); void fft_window (fft_t *fft, complex_t wave[]); double fft_amp (int n, complex_t wave[], int bits); -double fft_phase (int n, complex_t wave[], int bits); void fft_scale (complex_t wave[], int bits); #endif /* FFT_H */ -- cgit v1.2.3 From 19e1fa84aafee1f845e39afd20deb9d7783ad935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 16 Jan 2008 20:09:47 +0100 Subject: Remove two unused files, don't define (x)mmx_supported on non-x86. --- src/post/goom/Makefile.am | 2 +- src/post/goom/goomsl_lex.c | 2108 ------------------------------ src/post/goom/goomsl_yacc.c | 2997 ------------------------------------------- src/post/goom/mmx.c | 2 + src/post/goom/mmx.h | 2 + src/post/goom/xmmx.c | 2 + 6 files changed, 7 insertions(+), 5106 deletions(-) delete mode 100644 src/post/goom/goomsl_lex.c delete mode 100644 src/post/goom/goomsl_yacc.c diff --git a/src/post/goom/Makefile.am b/src/post/goom/Makefile.am index 22b4af79f..81e2eff32 100644 --- a/src/post/goom/Makefile.am +++ b/src/post/goom/Makefile.am @@ -30,7 +30,7 @@ xinepost_LTLIBRARIES = xineplug_post_goom.la xineplug_post_goom_la_SOURCES = mmx.c xine_goom.c \ config_param.c convolve_fx.c cpu_info.c drawmethods.c filters.c flying_stars_fx.c \ gfontlib.c goom_core.c goom_tools.c goomsl.c goomsl_hash.c goomsl_heap.c \ - goomsl_lex.c goomsl_yacc.c graphic.c ifs.c lines.c \ + graphic.c ifs.c lines.c \ plugin_info.c sound_tester.c surf3d.c tentacle3d.c v3d.c xineplug_post_goom_la_LIBADD = $(XINE_LIB) $(GOOM_LIBS) $(PTHREAD_LIBS) $(LTLIBINTL) -lm $(noinst_LTLIBRARIES) xineplug_post_goom_la_CFLAGS = $(DEFAULT_OCFLAGS) $(AM_CFLAGS) diff --git a/src/post/goom/goomsl_lex.c b/src/post/goom/goomsl_lex.c deleted file mode 100644 index 988fb99da..000000000 --- a/src/post/goom/goomsl_lex.c +++ /dev/null @@ -1,2108 +0,0 @@ -#line 2 "goomsl_lex.c" - -#line 4 "goomsl_lex.c" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 31 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; -#endif /* ! C99 */ - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! FLEXINT_H */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -#if __STDC__ - -#define YY_USE_CONST - -#endif /* __STDC__ */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN (yy_start) = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START (((yy_start) - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart(yyin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#define YY_BUF_SIZE 16384 -#endif - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -extern int yyleng; - -extern FILE *yyin, *yyout; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires - * access to the local variable yy_act. Since yyless() is a macro, it would break - * existing scanners that call yyless() from OUTSIDE yylex. - * One obvious solution it to make yy_act a global. I tried that, and saw - * a 5% performance hit in a non-yylineno scanner, because yy_act is - * normally declared as a register variable-- so it is not worth it. - */ - #define YY_LESS_LINENO(n) \ - do { \ - int yyl;\ - for ( yyl = n; yyl < yyleng; ++yyl )\ - if ( yytext[yyl] == '\n' )\ - --yylineno;\ - }while(0) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, (yytext_ptr) ) - -/* The following is because we cannot portably get our hands on size_t - * (without autoconf's help, which isn't available because we want - * flex-generated scanners to compile on their own). - */ - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef unsigned int yy_size_t; -#endif - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) - -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] - -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -int yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 1; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void yyrestart (FILE *input_file ); -void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); -void yy_delete_buffer (YY_BUFFER_STATE b ); -void yy_flush_buffer (YY_BUFFER_STATE b ); -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state (void ); - -static void yyensure_buffer_stack (void ); -static void yy_load_buffer_state (void ); -static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); - -#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); - -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); - -#define yy_new_buffer yy_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ - -typedef unsigned char YY_CHAR; - -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; - -typedef int yy_state_type; - -#define YY_FLEX_LEX_COMPAT -extern int yylineno; - -int yylineno = 1; - -extern char yytext[]; - -static yy_state_type yy_get_previous_state (void ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); -static int yy_get_next_buffer (void ); -static void yy_fatal_error (yyconst char msg[] ); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - if ( yyleng + (yy_more_offset) >= YYLMAX ) \ - YY_FATAL_ERROR( "token too large, exceeds YYLMAX" ); \ - yy_flex_strncpy( &yytext[(yy_more_offset)], (yytext_ptr), yyleng + 1 ); \ - yyleng += (yy_more_offset); \ - (yy_prev_more_offset) = (yy_more_offset); \ - (yy_more_offset) = 0; \ - (yy_c_buf_p) = yy_cp; - -#define YY_NUM_RULES 49 -#define YY_END_OF_BUFFER 50 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_acclist[214] = - { 0, - 50, 48, 49, 47, 48, 49, 4, 49, 48, 49, - 13, 48, 49, 10, 48, 49, 33, 48, 49, 48, - 49, 48, 49, 48, 49, 48, 49, 48, 49, 34, - 48, 49, 34, 48, 49, 48, 49, 48, 49, 33, - 48, 49, 33, 48, 49, 33, 48, 49, 33, 48, - 49, 33, 48, 49, 33, 48, 49, 33, 48, 49, - 33, 48, 49, 33, 48, 49, 33, 48, 49, 47, - 48, 49, 1, 4, 49, 48, 49, 7, 49, 6, - 49, 7, 49, 7, 49, 1, 6, 49, 7, 49, - 3, 49, 1, 3, 49, 17, 49, 49, 16, 17, - - 49, 17, 49, 47, 45, 10, 10, 10, 33, 40, - 39, 41, 11, 12, 42, 38, 37, 34, 43, 46, - 44, 33, 33, 28, 33, 33, 33, 33, 33, 30, - 33, 33, 33, 33, 33, 33, 47, 1, 12, 5, - 15, 14, 10, 10, 35, 37, 36, 33, 33, 33, - 33, 33, 29, 33, 19, 33, 26, 33, 21, 33, - 33, 33, 33, 2, 10, 10, 33, 33, 33, 33, - 33, 33, 33, 31, 33, 33, 10, 10, 33, 33, - 33, 32, 33, 18, 33, 33, 33, 27, 33, 10, - 10, 33, 33, 33, 22, 33, 25, 33, 10, 9, - - 10, 10, 20, 33, 23, 33, 33, 10, 24, 33, - 10, 8, 10 - } ; - -static yyconst flex_int16_t yy_accept[152] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, - 4, 7, 9, 11, 14, 17, 20, 22, 24, 26, - 28, 30, 33, 36, 38, 40, 43, 46, 49, 52, - 55, 58, 61, 64, 67, 70, 73, 76, 78, 80, - 82, 84, 86, 89, 91, 93, 96, 98, 99, 102, - 104, 105, 106, 107, 108, 109, 110, 110, 111, 112, - 113, 114, 115, 116, 117, 118, 119, 119, 120, 121, - 122, 123, 124, 126, 127, 128, 129, 130, 132, 133, - 134, 135, 136, 137, 138, 139, 139, 140, 141, 141, - 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, - - 151, 152, 153, 155, 157, 159, 161, 162, 163, 164, - 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, - 174, 176, 177, 178, 179, 180, 181, 182, 184, 186, - 187, 188, 190, 191, 192, 193, 194, 195, 197, 199, - 200, 202, 203, 205, 207, 208, 209, 211, 212, 214, - 214 - } ; - -static yyconst flex_int32_t yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 4, 5, 6, 7, 1, 8, 9, 10, 1, - 1, 11, 12, 1, 13, 14, 15, 16, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 1, 1, 18, - 19, 20, 1, 9, 21, 21, 21, 21, 22, 23, - 21, 21, 24, 21, 21, 25, 21, 26, 21, 21, - 21, 27, 28, 29, 21, 21, 21, 21, 21, 21, - 1, 30, 1, 1, 31, 1, 32, 33, 34, 35, - - 36, 37, 38, 39, 40, 21, 21, 41, 21, 42, - 43, 44, 21, 45, 46, 47, 48, 21, 49, 50, - 21, 21, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst flex_int32_t yy_meta[51] = - { 0, - 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 3, 1, 4, 4, 1, 1, 1, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, - 3, 4, 4, 4, 4, 4, 4, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 - } ; - -static yyconst flex_int16_t yy_base[159] = - { 0, - 0, 49, 51, 54, 221, 57, 60, 64, 223, 225, - 69, 225, 203, 225, 51, 0, 0, 202, 201, 200, - 64, 68, 72, 72, 199, 174, 57, 166, 55, 173, - 171, 166, 165, 166, 171, 99, 225, 93, 225, 225, - 194, 107, 225, 193, 225, 225, 225, 225, 225, 71, - 93, 225, 0, 183, 178, 0, 195, 225, 225, 225, - 225, 225, 225, 225, 89, 107, 0, 225, 225, 225, - 161, 169, 0, 155, 160, 157, 154, 151, 150, 151, - 150, 146, 153, 123, 225, 177, 188, 225, 126, 187, - 225, 225, 164, 159, 225, 100, 0, 146, 145, 149, - - 138, 151, 0, 0, 0, 0, 59, 146, 140, 177, - 225, 157, 147, 141, 144, 130, 138, 126, 130, 137, - 0, 134, 165, 143, 133, 112, 109, 0, 0, 102, - 92, 0, 130, 112, 93, 98, 101, 0, 0, 125, - 124, 94, 0, 0, 78, 59, 0, 61, 0, 225, - 141, 145, 149, 151, 155, 51, 159, 163 - } ; - -static yyconst flex_int16_t yy_def[159] = - { 0, - 150, 1, 151, 151, 151, 151, 152, 152, 150, 150, - 150, 150, 150, 150, 153, 154, 155, 150, 150, 150, - 150, 150, 150, 150, 150, 154, 154, 154, 154, 154, - 154, 154, 154, 154, 154, 150, 150, 150, 150, 150, - 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, - 150, 150, 153, 153, 153, 154, 150, 150, 150, 150, - 150, 150, 150, 150, 150, 150, 156, 150, 150, 150, - 154, 154, 154, 154, 154, 154, 154, 154, 154, 154, - 154, 154, 154, 150, 150, 150, 157, 150, 150, 157, - 150, 150, 153, 153, 150, 150, 156, 154, 154, 154, - - 154, 154, 154, 154, 154, 154, 154, 154, 154, 157, - 150, 153, 153, 154, 154, 154, 154, 154, 154, 154, - 154, 154, 153, 153, 154, 154, 154, 154, 154, 154, - 154, 154, 158, 153, 154, 154, 154, 154, 154, 158, - 158, 153, 154, 154, 154, 153, 154, 153, 153, 0, - 150, 150, 150, 150, 150, 150, 150, 150 - } ; - -static yyconst flex_int16_t yy_nxt[276] = - { 0, - 10, 11, 12, 11, 13, 14, 15, 10, 16, 17, - 18, 19, 20, 10, 21, 22, 23, 24, 10, 25, - 16, 16, 16, 16, 16, 16, 16, 16, 16, 10, - 16, 16, 26, 16, 27, 28, 29, 16, 16, 30, - 16, 31, 16, 32, 16, 33, 34, 16, 35, 16, - 36, 37, 36, 40, 97, 42, 43, 42, 42, 46, - 42, 41, 48, 38, 41, 49, 48, 149, 44, 49, - 51, 44, 51, 54, 61, 64, 91, 55, 62, 64, - 148, 65, 63, 66, 66, 65, 75, 66, 66, 50, - 68, 69, 72, 50, 51, 76, 51, 77, 119, 73, - - 84, 85, 84, 61, 96, 96, 120, 87, 89, 85, - 89, 63, 92, 86, 64, 96, 96, 67, 147, 146, - 65, 86, 66, 66, 84, 85, 84, 89, 85, 89, - 141, 141, 145, 144, 143, 142, 141, 86, 139, 138, - 86, 39, 39, 39, 39, 47, 47, 47, 47, 53, - 137, 53, 53, 56, 56, 57, 136, 57, 57, 110, - 110, 110, 110, 140, 135, 140, 140, 134, 133, 132, - 131, 130, 129, 128, 127, 126, 125, 124, 123, 111, - 122, 121, 118, 117, 116, 115, 114, 113, 112, 111, - 111, 90, 109, 108, 107, 106, 105, 104, 103, 102, - - 101, 100, 99, 98, 95, 94, 93, 90, 88, 83, - 82, 81, 80, 79, 78, 74, 71, 70, 60, 59, - 58, 52, 150, 45, 9, 150, 150, 150, 150, 150, - 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, - 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, - 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, - 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, - 150, 150, 150, 150, 150 - } ; - -static yyconst flex_int16_t yy_chk[276] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 2, 2, 2, 3, 156, 4, 4, 4, 6, 6, - 6, 3, 7, 2, 4, 7, 8, 148, 4, 8, - 11, 6, 11, 15, 21, 22, 50, 15, 21, 23, - 146, 22, 21, 22, 22, 23, 29, 23, 23, 7, - 24, 24, 27, 8, 51, 29, 51, 29, 107, 27, - - 36, 36, 36, 38, 65, 65, 107, 38, 42, 42, - 42, 38, 50, 36, 66, 96, 96, 22, 145, 142, - 66, 42, 66, 66, 84, 84, 84, 89, 89, 89, - 141, 140, 137, 136, 135, 134, 133, 84, 131, 130, - 89, 151, 151, 151, 151, 152, 152, 152, 152, 153, - 127, 153, 153, 154, 154, 155, 126, 155, 155, 157, - 157, 157, 157, 158, 125, 158, 158, 124, 123, 122, - 120, 119, 118, 117, 116, 115, 114, 113, 112, 110, - 109, 108, 102, 101, 100, 99, 98, 94, 93, 90, - 87, 86, 83, 82, 81, 80, 79, 78, 77, 76, - - 75, 74, 72, 71, 57, 55, 54, 44, 41, 35, - 34, 33, 32, 31, 30, 28, 26, 25, 20, 19, - 18, 13, 9, 5, 150, 150, 150, 150, 150, 150, - 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, - 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, - 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, - 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, - 150, 150, 150, 150, 150 - } ; - -/* Table of booleans, true if rule could match eol. */ -static yyconst flex_int32_t yy_rule_can_match_eol[50] = - { 0, -1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - -static yy_state_type *yy_state_buf=0, *yy_state_ptr=0; -static char *yy_full_match; -static int yy_lp; -#define REJECT \ -{ \ -*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ \ -yy_cp = (yy_full_match); /* restore poss. backed-over text */ \ -++(yy_lp); \ -goto find_rule; \ -} - -static int yy_more_offset = 0; -static int yy_prev_more_offset = 0; -#define yymore() ((yy_more_offset) = yy_flex_strlen( yytext )) -#define YY_NEED_STRLEN -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET \ - { \ - (yy_more_offset) = (yy_prev_more_offset); \ - yyleng -= (yy_more_offset); \ - } -#ifndef YYLMAX -#define YYLMAX 8192 -#endif - -char yytext[YYLMAX]; -char *yytext_ptr; -#line 1 "goomsl_lex.l" -#line 2 "goomsl_lex.l" - -#include -#include -#include -#include "goomsl.h" -#include "goomsl_private.h" -#include "goomsl_yacc.h" -void yyerror(char *); -void yyparse(void); - -GoomSL *currentGoomSL; -static int string_size; -static char string[1024]; - - - -#line 639 "goomsl_lex.c" - -#define INITIAL 0 -#define C_COMMENT 1 -#define LINE_COMMENT 2 -#define STRING 3 - -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap (void ); -#else -extern int yywrap (void ); -#endif -#endif - - static void yyunput (int c,char *buf_ptr ); - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); -#endif - -#ifndef YY_NO_INPUT - -#ifdef __cplusplus -static int yyinput (void ); -#else -static int input (void ); -#endif - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#define YY_READ_BUF_SIZE 8192 -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - size_t n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int yylex (void); - -#define YY_DECL int yylex (void) -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK break; -#endif - -#define YY_RULE_SETUP \ - if ( yyleng > 0 ) \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \ - (yytext[yyleng - 1] == '\n'); \ - YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - register yy_state_type yy_current_state; - register char *yy_cp, *yy_bp; - register int yy_act; - -#line 25 "goomsl_lex.l" - - -#line 797 "goomsl_lex.c" - - if ( (yy_init) ) - { - (yy_init) = 0; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! (yy_state_buf) ) - (yy_state_buf) = (yy_state_type *)yyalloc(YY_BUF_SIZE + 2 ); - - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_load_buffer_state( ); - } - - while ( 1 ) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); - - /* Support of yytext. */ - *yy_cp = (yy_hold_char); - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = (yy_start); - yy_current_state += YY_AT_BOL(); - - (yy_state_ptr) = (yy_state_buf); - *(yy_state_ptr)++ = yy_current_state; - -yy_match: - do - { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 151 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - *(yy_state_ptr)++ = yy_current_state; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 225 ); - -yy_find_action: - yy_current_state = *--(yy_state_ptr); - (yy_lp) = yy_accept[yy_current_state]; -find_rule: /* we branch to this label when backing up */ - for ( ; ; ) /* until we find what rule we matched */ - { - if ( (yy_lp) && (yy_lp) < yy_accept[yy_current_state + 1] ) - { - yy_act = yy_acclist[(yy_lp)]; - { - (yy_full_match) = yy_cp; - break; - } - } - --yy_cp; - yy_current_state = *--(yy_state_ptr); - (yy_lp) = yy_accept[yy_current_state]; - } - - YY_DO_BEFORE_ACTION; - - if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] ) - { - int yyl; - for ( yyl = (yy_prev_more_offset); yyl < yyleng; ++yyl ) - if ( yytext[yyl] == '\n' ) - - yylineno++; -; - } - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ -case 1: -/* rule 1 can match eol */ -YY_RULE_SETUP -#line 27 "goomsl_lex.l" -{ ++currentGoomSL->num_lines; /* Ignore empty lines */ } - YY_BREAK -case 2: -/* rule 2 can match eol */ -YY_RULE_SETUP -#line 28 "goomsl_lex.l" -{ ++currentGoomSL->num_lines; /* Ignore empty lines */ } - YY_BREAK -case 3: -/* rule 3 can match eol */ -YY_RULE_SETUP -#line 30 "goomsl_lex.l" -{ ++currentGoomSL->num_lines; yylval.charValue=*yytext; BEGIN INITIAL; return '\n'; } - YY_BREAK -case 4: -/* rule 4 can match eol */ -YY_RULE_SETUP -#line 31 "goomsl_lex.l" -{ ++currentGoomSL->num_lines; yylval.charValue=*yytext; return '\n'; } - YY_BREAK -case 5: -YY_RULE_SETUP -#line 33 "goomsl_lex.l" -{ BEGIN INITIAL; } - YY_BREAK -case 6: -/* rule 6 can match eol */ -YY_RULE_SETUP -#line 34 "goomsl_lex.l" -{ ++currentGoomSL->num_lines; } - YY_BREAK -case 7: -YY_RULE_SETUP -#line 35 "goomsl_lex.l" -{ /* eat up comment */ } - YY_BREAK -case 8: -YY_RULE_SETUP -#line 37 "goomsl_lex.l" -{ currentGoomSL->num_lines = 0; } - YY_BREAK -case 9: -YY_RULE_SETUP -#line 38 "goomsl_lex.l" -{ currentGoomSL->num_lines = 0; printf("%s\n", yytext); } - YY_BREAK -case 10: -YY_RULE_SETUP -#line 39 "goomsl_lex.l" -{ /* ignore preprocessor lines */ } - YY_BREAK -case 11: -YY_RULE_SETUP -#line 41 "goomsl_lex.l" -{ BEGIN C_COMMENT; } - YY_BREAK -case 12: -YY_RULE_SETUP -#line 42 "goomsl_lex.l" -{ BEGIN LINE_COMMENT; } - YY_BREAK -case 13: -YY_RULE_SETUP -#line 43 "goomsl_lex.l" -{ BEGIN STRING; string_size=0; } - YY_BREAK -case 14: -YY_RULE_SETUP -#line 45 "goomsl_lex.l" -{ string[string_size++] = '\n'; } - YY_BREAK -case 15: -YY_RULE_SETUP -#line 46 "goomsl_lex.l" -{ string[string_size++] = '\"'; } - YY_BREAK -case 16: -YY_RULE_SETUP -#line 47 "goomsl_lex.l" -{ /* fin de la chaine: on cree le pointeur qui va bien */ - unsigned int tmp; - BEGIN INITIAL; - string[string_size]=0; - tmp = gsl_malloc(currentGoomSL, string_size+1); - strcpy((char*)currentGoomSL->ptrArray[tmp],string); - sprintf(yylval.strValue, "0x%08x", tmp); - return LTYPE_PTR; - } - YY_BREAK -case 17: -YY_RULE_SETUP -#line 56 "goomsl_lex.l" -{ string[string_size++] = *yytext; } - YY_BREAK -case 18: -YY_RULE_SETUP -#line 58 "goomsl_lex.l" -{ return FLOAT_TK; } - YY_BREAK -case 19: -YY_RULE_SETUP -#line 59 "goomsl_lex.l" -{ return INT_TK; } - YY_BREAK -case 20: -YY_RULE_SETUP -#line 60 "goomsl_lex.l" -{ return INT_TK; } - YY_BREAK -case 21: -YY_RULE_SETUP -#line 61 "goomsl_lex.l" -{ return PTR_TK; } - YY_BREAK -case 22: -YY_RULE_SETUP -#line 62 "goomsl_lex.l" -{ return PTR_TK; } - YY_BREAK -case 23: -YY_RULE_SETUP -#line 63 "goomsl_lex.l" -{ return DECLARE; } - YY_BREAK -case 24: -YY_RULE_SETUP -#line 64 "goomsl_lex.l" -{ return EXTERNAL; } - YY_BREAK -case 25: -YY_RULE_SETUP -#line 65 "goomsl_lex.l" -{ return STRUCT; } - YY_BREAK -case 26: -YY_RULE_SETUP -#line 66 "goomsl_lex.l" -{ return NOT; } - YY_BREAK -case 27: -YY_RULE_SETUP -#line 67 "goomsl_lex.l" -{ return WHILE; } - YY_BREAK -case 28: -YY_RULE_SETUP -#line 68 "goomsl_lex.l" -{ return DO; } - YY_BREAK -case 29: -YY_RULE_SETUP -#line 69 "goomsl_lex.l" -{ return FOR; } - YY_BREAK -case 30: -YY_RULE_SETUP -#line 70 "goomsl_lex.l" -{ return IN; } - YY_BREAK -case 31: -YY_RULE_SETUP -#line 71 "goomsl_lex.l" -{ strncpy(yylval.strValue, "1", 2047); return LTYPE_INTEGER; } - YY_BREAK -case 32: -YY_RULE_SETUP -#line 72 "goomsl_lex.l" -{ strncpy(yylval.strValue, "0", 2047); return LTYPE_INTEGER; } - YY_BREAK -case 33: -YY_RULE_SETUP -#line 73 "goomsl_lex.l" -{ strncpy(yylval.strValue, yytext, 2047); return LTYPE_VAR; } - YY_BREAK -case 34: -YY_RULE_SETUP -#line 74 "goomsl_lex.l" -{ strncpy(yylval.strValue, yytext, 2047); return LTYPE_INTEGER; } - YY_BREAK -case 35: -YY_RULE_SETUP -#line 75 "goomsl_lex.l" -{ sprintf(yylval.strValue, "%d", (int)yytext[1]); return LTYPE_INTEGER; } - YY_BREAK -case 36: -YY_RULE_SETUP -#line 76 "goomsl_lex.l" -{ strncpy(yylval.strValue, yytext, 2047); return LTYPE_INTEGER; } - YY_BREAK -case 37: -YY_RULE_SETUP -#line 77 "goomsl_lex.l" -{ strncpy(yylval.strValue, yytext, 2047); return LTYPE_FLOAT; } - YY_BREAK -case 38: -YY_RULE_SETUP -#line 78 "goomsl_lex.l" -{ sprintf(yylval.strValue, "%3.2f", atof(yytext)/100.0f); return LTYPE_FLOAT; } - YY_BREAK -case 39: -YY_RULE_SETUP -#line 79 "goomsl_lex.l" -{ return PLUS_EQ; } - YY_BREAK -case 40: -YY_RULE_SETUP -#line 80 "goomsl_lex.l" -{ return MUL_EQ; } - YY_BREAK -case 41: -YY_RULE_SETUP -#line 81 "goomsl_lex.l" -{ return SUB_EQ; } - YY_BREAK -case 42: -YY_RULE_SETUP -#line 82 "goomsl_lex.l" -{ return DIV_EQ; } - YY_BREAK -case 43: -YY_RULE_SETUP -#line 83 "goomsl_lex.l" -{ return LOW_EQ; } - YY_BREAK -case 44: -YY_RULE_SETUP -#line 84 "goomsl_lex.l" -{ return SUP_EQ; } - YY_BREAK -case 45: -YY_RULE_SETUP -#line 85 "goomsl_lex.l" -{ return NOT_EQ; } - YY_BREAK -case 46: -YY_RULE_SETUP -#line 86 "goomsl_lex.l" -{ return NOT_EQ; } - YY_BREAK -case 47: -YY_RULE_SETUP -#line 87 "goomsl_lex.l" -/* eat up whitespace */ - YY_BREAK -case 48: -YY_RULE_SETUP -#line 88 "goomsl_lex.l" -{ yylval.charValue = *yytext; return *yytext; } - YY_BREAK -case 49: -YY_RULE_SETUP -#line 90 "goomsl_lex.l" -ECHO; - YY_BREAK -#line 1155 "goomsl_lex.c" - case YY_STATE_EOF(INITIAL): - case YY_STATE_EOF(C_COMMENT): - case YY_STATE_EOF(LINE_COMMENT): - case YY_STATE_EOF(STRING): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = (yy_c_buf_p); - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; - - if ( yywrap( ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ -} /* end of yylex */ - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (void) -{ - register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - register char *source = (yytext_ptr); - register int number_to_move, i; - int ret_val; - - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - - else - { - size_t num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - YY_FATAL_ERROR( -"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - if ( (yy_n_chars) == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart(yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; - - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - static yy_state_type yy_get_previous_state (void) -{ - register yy_state_type yy_current_state; - register char *yy_cp; - - yy_current_state = (yy_start); - yy_current_state += YY_AT_BOL(); - - (yy_state_ptr) = (yy_state_buf); - *(yy_state_ptr)++ = yy_current_state; - - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) - { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 151 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - *(yy_state_ptr)++ = yy_current_state; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) -{ - register int yy_is_jam; - - register YY_CHAR yy_c = 1; - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 151 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 150); - if ( ! yy_is_jam ) - *(yy_state_ptr)++ = yy_current_state; - - return yy_is_jam ? 0 : yy_current_state; -} - - static void yyunput (int c, register char * yy_bp ) -{ - register char *yy_cp; - - yy_cp = (yy_c_buf_p); - - /* undo effects of setting up yytext */ - *yy_cp = (yy_hold_char); - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - register int number_to_move = (yy_n_chars) + 2; - register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - register char *source = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; - - while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - *--dest = *--source; - - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } - - *--yy_cp = (char) c; - - if ( c == '\n' ){ - --yylineno; - } - - (yytext_ptr) = yy_bp; - (yy_hold_char) = *yy_cp; - (yy_c_buf_p) = yy_cp; -} - -#ifndef YY_NO_INPUT -#ifdef __cplusplus - static int yyinput (void) -#else - static int input (void) -#endif - -{ - int c; - - *(yy_c_buf_p) = (yy_hold_char); - - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; - - else - { /* need more input */ - int offset = (yy_c_buf_p) - (yytext_ptr); - ++(yy_c_buf_p); - - switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart(yyin ); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( ) ) - return EOF; - - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } - - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); - - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n'); - if ( YY_CURRENT_BUFFER_LVALUE->yy_at_bol ) - - yylineno++; -; - - return c; -} -#endif /* ifndef YY_NO_INPUT */ - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * - * @note This function does not reset the start condition to @c INITIAL . - */ - void yyrestart (FILE * input_file ) -{ - - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_init_buffer(YY_CURRENT_BUFFER,input_file ); - yy_load_buffer_state( ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * - */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) -{ - - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack (); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; -} - -static void yy_load_buffer_state (void) -{ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * - * @return the allocated buffer state. - */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer(b,file ); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with yy_create_buffer() - * - */ - void yy_delete_buffer (YY_BUFFER_STATE b ) -{ - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yyfree((void *) b->yy_ch_buf ); - - yyfree((void *) b ); -} - -#ifndef __cplusplus -extern int isatty (int ); -#endif /* __cplusplus */ - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a yyrestart() or at EOF. - */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) - -{ - int oerrno = errno; - - yy_flush_buffer(b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; - - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * - */ - void yy_flush_buffer (YY_BUFFER_STATE b ) -{ - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * - */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) -{ - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(); - - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * - */ -void yypop_buffer_state (void) -{ - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -static void yyensure_buffer_stack (void) -{ - int num_to_alloc; - - if (!(yy_buffer_stack)) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } - - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - int grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state*) - ); - - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - } -} - -/** Setup the input buffer state to scan directly from a user-specified character buffer. - * @param base the character buffer - * @param size the size in bytes of the character buffer - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) -{ - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer(b ); - - return b; -} - -/** Setup the input buffer state to scan a string. The next call to yylex() will - * scan from a @e copy of @a str. - * @param str a NUL-terminated string to scan - * - * @return the newly allocated buffer state object. - * @note If you want to scan bytes that may contain NUL values, then use - * yy_scan_bytes() instead. - */ -YY_BUFFER_STATE yy_scan_string (yyconst char * str ) -{ - - return yy_scan_bytes(str,strlen(str) ); -} - -/** Setup the input buffer state to scan the given bytes. The next call to yylex() will - * scan from a @e copy of @a bytes. - * @param bytes the byte buffer to scan - * @param len the number of bytes in the buffer pointed to by @a bytes. - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_bytes (yyconst char * bytes, int len ) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - int i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = len + 2; - buf = (char *) yyalloc(n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < len; ++i ) - buf[i] = bytes[i]; - - buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer(buf,n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -static void yy_fatal_error (yyconst char* msg ) -{ - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/** Get the current line number. - * - */ -int yyget_lineno (void) -{ - - return yylineno; -} - -/** Get the input stream. - * - */ -FILE *yyget_in (void) -{ - return yyin; -} - -/** Get the output stream. - * - */ -FILE *yyget_out (void) -{ - return yyout; -} - -/** Get the length of the current token. - * - */ -int yyget_leng (void) -{ - return yyleng; -} - -/** Get the current token. - * - */ - -char *yyget_text (void) -{ - return yytext; -} - -/** Set the current line number. - * @param line_number - * - */ -void yyset_lineno (int line_number ) -{ - - yylineno = line_number; -} - -/** Set the input stream. This does not discard the current - * input buffer. - * @param in_str A readable stream. - * - * @see yy_switch_to_buffer - */ -void yyset_in (FILE * in_str ) -{ - yyin = in_str ; -} - -void yyset_out (FILE * out_str ) -{ - yyout = out_str ; -} - -int yyget_debug (void) -{ - return yy_flex_debug; -} - -void yyset_debug (int bdebug ) -{ - yy_flex_debug = bdebug ; -} - -/* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) -{ - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); - } - - /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; - - yyfree ( (yy_state_buf) ); - - return 0; -} - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) -{ - register int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) -{ - register int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *yyalloc (yy_size_t size ) -{ - return (void *) malloc( size ); -} - -void *yyrealloc (void * ptr, yy_size_t size ) -{ - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); -} - -void yyfree (void * ptr ) -{ - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - -#undef YY_NEW_FILE -#undef YY_FLUSH_BUFFER -#undef yy_set_bol -#undef yy_new_buffer -#undef yy_set_interactive -#undef YY_DO_BEFORE_ACTION - -#ifdef YY_DECL_IS_OURS -#undef YY_DECL_IS_OURS -#undef YY_DECL -#endif -#line 90 "goomsl_lex.l" - - - - -int yywrap(void) { return 1; yyunput(0,0); } - - diff --git a/src/post/goom/goomsl_yacc.c b/src/post/goom/goomsl_yacc.c deleted file mode 100644 index 589b171be..000000000 --- a/src/post/goom/goomsl_yacc.c +++ /dev/null @@ -1,2997 +0,0 @@ -/* A Bison parser, made by GNU Bison 1.875. */ - -/* Skeleton parser for Yacc-like parsing with Bison, - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* As a special exception, when this file is copied by Bison into a - Bison output file, you may use that output file without restriction. - This special exception was added by the Free Software Foundation - in version 1.24 of Bison. */ - -/* Written by Richard Stallman by simplifying the original so called - ``semantic'' parser. */ - -/* All symbols defined below should begin with yy or YY, to avoid - infringing on user name space. This should be done even for local - variables, as they might otherwise be expanded by user macros. - There are some unavoidable exceptions within include files to - define necessary library symbols; they are noted "INFRINGES ON - USER NAME SPACE" below. */ - -/* Identify Bison output. */ -#define YYBISON 1 - -/* Skeleton name. */ -#define YYSKELETON_NAME "yacc.c" - -/* Pure parsers. */ -#define YYPURE 0 - -/* Using locations. */ -#define YYLSP_NEEDED 0 - - - -/* Tokens. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - /* Put the tokens into the symbol table, so that GDB and other debuggers - know about them. */ - enum yytokentype { - LTYPE_INTEGER = 258, - LTYPE_FLOAT = 259, - LTYPE_VAR = 260, - LTYPE_PTR = 261, - PTR_TK = 262, - INT_TK = 263, - FLOAT_TK = 264, - DECLARE = 265, - EXTERNAL = 266, - WHILE = 267, - DO = 268, - NOT = 269, - PLUS_EQ = 270, - SUB_EQ = 271, - DIV_EQ = 272, - MUL_EQ = 273, - SUP_EQ = 274, - LOW_EQ = 275, - NOT_EQ = 276, - STRUCT = 277, - FOR = 278, - IN = 279 - }; -#endif -#define LTYPE_INTEGER 258 -#define LTYPE_FLOAT 259 -#define LTYPE_VAR 260 -#define LTYPE_PTR 261 -#define PTR_TK 262 -#define INT_TK 263 -#define FLOAT_TK 264 -#define DECLARE 265 -#define EXTERNAL 266 -#define WHILE 267 -#define DO 268 -#define NOT 269 -#define PLUS_EQ 270 -#define SUB_EQ 271 -#define DIV_EQ 272 -#define MUL_EQ 273 -#define SUP_EQ 274 -#define LOW_EQ 275 -#define NOT_EQ 276 -#define STRUCT 277 -#define FOR 278 -#define IN 279 - - - - -/* Copy the first part of user declarations. */ -#line 6 "goomsl_yacc.y" - - #include - #include - #include - #include "goomsl.h" - #include "goomsl_private.h" - -#define STRUCT_ALIGNMENT 16 -/* #define VERBOSE */ - - int yylex(void); - void yyerror(char *); - extern GoomSL *currentGoomSL; - - static NodeType *nodeNew(const char *str, int type, int line_number); - static NodeType *nodeClone(NodeType *node); - static void nodeFreeInternals(NodeType *node); - static void nodeFree(NodeType *node); - - static void commit_node(NodeType *node, int releaseIfTemp); - static void precommit_node(NodeType *node); - - static NodeType *new_constInt(const char *str, int line_number); - static NodeType *new_constFloat(const char *str, int line_number); - static NodeType *new_constPtr(const char *str, int line_number); - static NodeType *new_var(const char *str, int line_number); - static NodeType *new_nop(const char *str); - static NodeType *new_op(const char *str, int type, int nbOp); - - static int allocateLabel(); - static int allocateTemp(); - static void releaseTemp(int n); - static void releaseAllTemps(); - - static int is_tmp_expr(NodeType *node) { - if (node->str) { - return (!strncmp(node->str,"_i_tmp_",7)) - || (!strncmp(node->str,"_f_tmp_",7)) - || (!strncmp(node->str,"_p_tmp",7)); - } - return 0; - } - /* pre: is_tmp_expr(node); */ - static int get_tmp_id(NodeType *node) { return atoi((node->str)+5); } - - static int is_commutative_expr(int itype) - { /* {{{ */ - return (itype == INSTR_ADD) - || (itype == INSTR_MUL) - || (itype == INSTR_ISEQUAL); - } /* }}} */ - - static void GSL_PUT_LABEL(char *name, int line_number) - { /* {{{ */ -#ifdef VERBOSE - printf("label %s\n", name); -#endif - currentGoomSL->instr = gsl_instr_init(currentGoomSL, "label", INSTR_LABEL, 1, line_number); - gsl_instr_add_param(currentGoomSL->instr, name, TYPE_LABEL); - } /* }}} */ - static void GSL_PUT_JUMP(char *name, int line_number) - { /* {{{ */ -#ifdef VERBOSE - printf("jump %s\n", name); -#endif - currentGoomSL->instr = gsl_instr_init(currentGoomSL, "jump", INSTR_JUMP, 1, line_number); - gsl_instr_add_param(currentGoomSL->instr, name, TYPE_LABEL); - } /* }}} */ - - static void GSL_PUT_JXXX(char *name, char *iname, int instr_id, int line_number) - { /* {{{ */ -#ifdef VERBOSE - printf("%s %s\n", iname, name); -#endif - currentGoomSL->instr = gsl_instr_init(currentGoomSL, iname, instr_id, 1, line_number); - gsl_instr_add_param(currentGoomSL->instr, name, TYPE_LABEL); - } /* }}} */ - static void GSL_PUT_JZERO(char *name,int line_number) - { /* {{{ */ - GSL_PUT_JXXX(name,"jzero.i",INSTR_JZERO,line_number); - } /* }}} */ - static void GSL_PUT_JNZERO(char *name, int line_number) - { /* {{{ */ - GSL_PUT_JXXX(name,"jnzero.i",INSTR_JNZERO,line_number); - } /* }}} */ - - /* Structures Management */ - -#define ALIGN_ADDR(_addr,_align) {\ - if (_align>1) {\ - int _dec = (_addr%_align);\ - if (_dec != 0) _addr += _align - _dec;\ - }} - - /* */ - void gsl_prepare_struct(GSL_Struct *s, int s_align, int i_align, int f_align) - { - int i; - int consumed = 0; - int iblk=0, fblk=0; - - s->iBlock[0].size = 0; - s->iBlock[0].data = 0; - s->fBlock[0].size = 0; - s->fBlock[0].data = 0; - - /* Prepare sub-struct and calculate space needed for their storage */ - for (i = 0; i < s->nbFields; ++i) - { - if (s->fields[i]->type < FIRST_RESERVED) - { - int j=0; - GSL_Struct *substruct = currentGoomSL->gsl_struct[s->fields[i]->type]; - consumed += sizeof(int); /* stocke le prefix */ - ALIGN_ADDR(consumed, s_align); - s->fields[i]->offsetInStruct = consumed; - gsl_prepare_struct(substruct, s_align, i_align, f_align); - for(j=0;substruct->iBlock[j].size>0;++j) { - s->iBlock[iblk].data = consumed + substruct->iBlock[j].data; - s->iBlock[iblk].size = substruct->iBlock[j].size; - iblk++; - } - for(j=0;substruct->fBlock[j].size>0;++j) { - s->fBlock[fblk].data = consumed + substruct->fBlock[j].data; - s->fBlock[fblk].size = substruct->fBlock[j].size; - fblk++; - } - consumed += substruct->size; - } - } - - /* Then prepare integers */ - ALIGN_ADDR(consumed, i_align); - for (i = 0; i < s->nbFields; ++i) - { - if (s->fields[i]->type == INSTR_INT) - { - if (s->iBlock[iblk].size == 0) { - s->iBlock[iblk].size = 1; - s->iBlock[iblk].data = consumed; - } else { - s->iBlock[iblk].size += 1; - } - s->fields[i]->offsetInStruct = consumed; - consumed += sizeof(int); - } - } - - iblk++; - s->iBlock[iblk].size = 0; - s->iBlock[iblk].data = 0; - - /* Then prepare floats */ - ALIGN_ADDR(consumed, f_align); - for (i = 0; i < s->nbFields; ++i) - { - if (s->fields[i]->type == INSTR_FLOAT) - { - if (s->fBlock[fblk].size == 0) { - s->fBlock[fblk].size = 1; - s->fBlock[fblk].data = consumed; - } else { - s->fBlock[fblk].size += 1; - } - s->fields[i]->offsetInStruct = consumed; - consumed += sizeof(int); - } - } - - fblk++; - s->fBlock[fblk].size = 0; - s->fBlock[fblk].data = 0; - - /* Finally prepare pointers */ - ALIGN_ADDR(consumed, i_align); - for (i = 0; i < s->nbFields; ++i) - { - if (s->fields[i]->type == INSTR_PTR) - { - s->fields[i]->offsetInStruct = consumed; - consumed += sizeof(int); - } - } - s->size = consumed; - } - - /* Returns the ID of a struct from its name */ - int gsl_get_struct_id(const char *name) /* {{{ */ - { - HashValue *ret = goom_hash_get(currentGoomSL->structIDS, name); - if (ret != NULL) return ret->i; - return -1; - } /* }}} */ - - /* Adds the definition of a struct */ - void gsl_add_struct(const char *name, GSL_Struct *gsl_struct) /* {{{ */ - { - /* Prepare the struct: ie calculate internal storage format */ - gsl_prepare_struct(gsl_struct, STRUCT_ALIGNMENT, STRUCT_ALIGNMENT, STRUCT_ALIGNMENT); - - /* If the struct does not already exists */ - if (gsl_get_struct_id(name) < 0) - { - /* adds it */ - int id = currentGoomSL->nbStructID++; - goom_hash_put_int(currentGoomSL->structIDS, name, id); - if (currentGoomSL->gsl_struct_size <= id) { - currentGoomSL->gsl_struct_size *= 2; - currentGoomSL->gsl_struct = (GSL_Struct**)realloc(currentGoomSL->gsl_struct, - sizeof(GSL_Struct*) * currentGoomSL->gsl_struct_size); - } - currentGoomSL->gsl_struct[id] = gsl_struct; - } - } /* }}} */ - - /* Creates a field for a struct */ - GSL_StructField *gsl_new_struct_field(const char *name, int type) - { - GSL_StructField *field = (GSL_StructField*)malloc(sizeof(GSL_StructField)); - strcpy(field->name, name); - field->type = type; - return field; - } - - /* Create as field for a struct which will be a struct itself */ - GSL_StructField *gsl_new_struct_field_struct(const char *name, const char *type) - { - GSL_StructField *field = gsl_new_struct_field(name, gsl_get_struct_id(type)); - if (field->type < 0) { - fprintf(stderr, "ERROR: Line %d, Unknown structure: '%s'\n", - currentGoomSL->num_lines, type); - exit(1); - } - return field; - } - - /* Creates a Struct */ - GSL_Struct *gsl_new_struct(GSL_StructField *field) - { - GSL_Struct *s = (GSL_Struct*)malloc(sizeof(GSL_Struct)); - s->nbFields = 1; - s->fields[0] = field; - return s; - } - - /* Adds a field to a struct */ - void gsl_add_struct_field(GSL_Struct *s, GSL_StructField *field) - { - s->fields[s->nbFields++] = field; - } - - int gsl_type_of_var(GoomHash *ns, const char *name) - { - char type_of[256]; - HashValue *hv; - sprintf(type_of, "__type_of_%s", name); - hv = goom_hash_get(ns, type_of); - if (hv != NULL) - return hv->i; - fprintf(stderr, "ERROR: Unknown variable type: '%s'\n", name); - return -1; - } - - static void gsl_declare_var(GoomHash *ns, const char *name, int type, void *space) - { - char type_of[256]; - if (name[0] == '@') { ns = currentGoomSL->vars; } - - if (space == NULL) { - switch (type) { - case INSTR_INT: - case INSTR_FLOAT: - case INSTR_PTR: - space = goom_heap_malloc_with_alignment(currentGoomSL->data_heap, - sizeof(int), sizeof(int)); - break; - case -1: - fprintf(stderr, "What the fuck!\n"); - exit(1); - default: /* On a un struct_id */ - space = goom_heap_malloc_with_alignment_prefixed(currentGoomSL->data_heap, - currentGoomSL->gsl_struct[type]->size, STRUCT_ALIGNMENT, sizeof(int)); - } - } - goom_hash_put_ptr(ns, name, (void*)space); - sprintf(type_of, "__type_of_%s", name); - goom_hash_put_int(ns, type_of, type); - - /* Ensuite le hack: on ajoute les champs en tant que variables. */ - if (type < FIRST_RESERVED) - { - int i; - GSL_Struct *gsl_struct = currentGoomSL->gsl_struct[type]; - ((int*)space)[-1] = type; /* stockage du type dans le prefixe de structure */ - for (i = 0; i < gsl_struct->nbFields; ++i) - { - char full_name[256]; - char *cspace = (char*)space + gsl_struct->fields[i]->offsetInStruct; - sprintf(full_name, "%s.%s", name, gsl_struct->fields[i]->name); - gsl_declare_var(ns, full_name, gsl_struct->fields[i]->type, cspace); - } - } - } - - /* Declare a variable which will be a struct */ - static void gsl_struct_decl(GoomHash *namespace, const char *struct_name, const char *name) - { - int struct_id = gsl_get_struct_id(struct_name); - gsl_declare_var(namespace, name, struct_id, NULL); - } - - static void gsl_float_decl_global(const char *name) - { - gsl_declare_var(currentGoomSL->vars, name, INSTR_FLOAT, NULL); - } - static void gsl_int_decl_global(const char *name) - { - gsl_declare_var(currentGoomSL->vars, name, INSTR_INT, NULL); - } - static void gsl_ptr_decl_global(const char *name) - { - gsl_declare_var(currentGoomSL->vars, name, INSTR_PTR, NULL); - } - static void gsl_struct_decl_global_from_id(const char *name, int id) - { - gsl_declare_var(currentGoomSL->vars, name, id, NULL); - } - - /* FLOAT */ - static void gsl_float_decl_local(const char *name) - { - gsl_declare_var(currentGoomSL->namespaces[currentGoomSL->currentNS], name, INSTR_FLOAT, NULL); - } - /* INT */ - static void gsl_int_decl_local(const char *name) - { - gsl_declare_var(currentGoomSL->namespaces[currentGoomSL->currentNS], name, INSTR_INT, NULL); - } - /* PTR */ - static void gsl_ptr_decl_local(const char *name) - { - gsl_declare_var(currentGoomSL->namespaces[currentGoomSL->currentNS], name, INSTR_PTR, NULL); - } - /* STRUCT */ - static void gsl_struct_decl_local(const char *struct_name, const char *name) - { - gsl_struct_decl(currentGoomSL->namespaces[currentGoomSL->currentNS],struct_name,name); - } - - - static void commit_test2(NodeType *set,const char *type, int instr); - static NodeType *new_call(const char *name, NodeType *affect_list); - - /* SETTER */ - static NodeType *new_set(NodeType *lvalue, NodeType *expression) - { /* {{{ */ - NodeType *set = new_op("set", OPR_SET, 2); - set->unode.opr.op[0] = lvalue; - set->unode.opr.op[1] = expression; - return set; - } /* }}} */ - static void commit_set(NodeType *set) - { /* {{{ */ - commit_test2(set,"set",INSTR_SET); - } /* }}} */ - - /* PLUS_EQ */ - static NodeType *new_plus_eq(NodeType *lvalue, NodeType *expression) /* {{{ */ - { - NodeType *set = new_op("plus_eq", OPR_PLUS_EQ, 2); - set->unode.opr.op[0] = lvalue; - set->unode.opr.op[1] = expression; - return set; - } - static void commit_plus_eq(NodeType *set) - { - precommit_node(set->unode.opr.op[1]); -#ifdef VERBOSE - printf("add %s %s\n", set->unode.opr.op[0]->str, set->unode.opr.op[1]->str); -#endif - currentGoomSL->instr = gsl_instr_init(currentGoomSL, "add", INSTR_ADD, 2, set->line_number); - commit_node(set->unode.opr.op[0],0); - commit_node(set->unode.opr.op[1],1); - } /* }}} */ - - /* SUB_EQ */ - static NodeType *new_sub_eq(NodeType *lvalue, NodeType *expression) /* {{{ */ - { - NodeType *set = new_op("sub_eq", OPR_SUB_EQ, 2); - set->unode.opr.op[0] = lvalue; - set->unode.opr.op[1] = expression; - return set; - } - static void commit_sub_eq(NodeType *set) - { - precommit_node(set->unode.opr.op[1]); -#ifdef VERBOSE - printf("sub %s %s\n", set->unode.opr.op[0]->str, set->unode.opr.op[1]->str); -#endif - currentGoomSL->instr = gsl_instr_init(currentGoomSL, "sub", INSTR_SUB, 2, set->line_number); - commit_node(set->unode.opr.op[0],0); - commit_node(set->unode.opr.op[1],1); - } /* }}} */ - - /* MUL_EQ */ - static NodeType *new_mul_eq(NodeType *lvalue, NodeType *expression) /* {{{ */ - { - NodeType *set = new_op("mul_eq", OPR_MUL_EQ, 2); - set->unode.opr.op[0] = lvalue; - set->unode.opr.op[1] = expression; - return set; - } - static void commit_mul_eq(NodeType *set) - { - precommit_node(set->unode.opr.op[1]); -#ifdef VERBOSE - printf("mul %s %s\n", set->unode.opr.op[0]->str, set->unode.opr.op[1]->str); -#endif - currentGoomSL->instr = gsl_instr_init(currentGoomSL, "mul", INSTR_MUL, 2, set->line_number); - commit_node(set->unode.opr.op[0],0); - commit_node(set->unode.opr.op[1],1); - } /* }}} */ - - /* DIV_EQ */ - static NodeType *new_div_eq(NodeType *lvalue, NodeType *expression) /* {{{ */ - { - NodeType *set = new_op("div_eq", OPR_DIV_EQ, 2); - set->unode.opr.op[0] = lvalue; - set->unode.opr.op[1] = expression; - return set; - } - static void commit_div_eq(NodeType *set) - { - precommit_node(set->unode.opr.op[1]); -#ifdef VERBOSE - printf("div %s %s\n", set->unode.opr.op[0]->str, set->unode.opr.op[1]->str); -#endif - currentGoomSL->instr = gsl_instr_init(currentGoomSL, "div", INSTR_DIV, 2, set->line_number); - commit_node(set->unode.opr.op[0],0); - commit_node(set->unode.opr.op[1],1); - } /* }}} */ - - /* commodity method for add, mult, ... */ - - static void precommit_expr(NodeType *expr, const char *type, int instr_id) - { /* {{{ */ - NodeType *tmp, *tmpcpy; - int toAdd; - - /* compute "left" and "right" */ - switch (expr->unode.opr.nbOp) { - case 2: - precommit_node(expr->unode.opr.op[1]); - case 1: - precommit_node(expr->unode.opr.op[0]); - } - - if (is_tmp_expr(expr->unode.opr.op[0])) { - tmp = expr->unode.opr.op[0]; - toAdd = 1; - } - else if (is_commutative_expr(instr_id) && (expr->unode.opr.nbOp==2) && is_tmp_expr(expr->unode.opr.op[1])) { - tmp = expr->unode.opr.op[1]; - toAdd = 0; - } - else { - char stmp[256]; - /* declare a temporary variable to store the result */ - if (expr->unode.opr.op[0]->type == CONST_INT_NODE) { - sprintf(stmp,"_i_tmp_%i",allocateTemp()); - gsl_int_decl_global(stmp); - } - else if (expr->unode.opr.op[0]->type == CONST_FLOAT_NODE) { - sprintf(stmp,"_f_tmp%i",allocateTemp()); - gsl_float_decl_global(stmp); - } - else if (expr->unode.opr.op[0]->type == CONST_PTR_NODE) { - sprintf(stmp,"_p_tmp%i",allocateTemp()); - gsl_ptr_decl_global(stmp); - } - else { - int type = gsl_type_of_var(expr->unode.opr.op[0]->vnamespace, expr->unode.opr.op[0]->str); - if (type == INSTR_FLOAT) { - sprintf(stmp,"_f_tmp_%i",allocateTemp()); - gsl_float_decl_global(stmp); - } - else if (type == INSTR_PTR) { - sprintf(stmp,"_p_tmp_%i",allocateTemp()); - gsl_ptr_decl_global(stmp); - } - else if (type == INSTR_INT) { - sprintf(stmp,"_i_tmp_%i",allocateTemp()); - gsl_int_decl_global(stmp); - } - else if (type == -1) { - fprintf(stderr, "ERROR: Line %d, Could not find variable '%s'\n", - expr->line_number, expr->unode.opr.op[0]->str); - exit(1); - } - else { /* type is a struct_id */ - sprintf(stmp,"_s_tmp_%i",allocateTemp()); - gsl_struct_decl_global_from_id(stmp,type); - } - } - tmp = new_var(stmp,expr->line_number); - - /* set the tmp to the value of "op1" */ - tmpcpy = nodeClone(tmp); - commit_node(new_set(tmp,expr->unode.opr.op[0]),0); - toAdd = 1; - - tmp = tmpcpy; - } - - /* add op2 to tmp */ -#ifdef VERBOSE - if (expr->unode.opr.nbOp == 2) - printf("%s %s %s\n", type, tmp->str, expr->unode.opr.op[toAdd]->str); - else - printf("%s %s\n", type, tmp->str); -#endif - currentGoomSL->instr = gsl_instr_init(currentGoomSL, type, instr_id, expr->unode.opr.nbOp, expr->line_number); - tmpcpy = nodeClone(tmp); - commit_node(tmp,0); - if (expr->unode.opr.nbOp == 2) { - commit_node(expr->unode.opr.op[toAdd],1); - } - - /* redefine the ADD node now as the computed variable */ - nodeFreeInternals(expr); - *expr = *tmpcpy; - free(tmpcpy); - } /* }}} */ - - static NodeType *new_expr1(const char *name, int id, NodeType *expr1) - { /* {{{ */ - NodeType *add = new_op(name, id, 1); - add->unode.opr.op[0] = expr1; - return add; - } /* }}} */ - - static NodeType *new_expr2(const char *name, int id, NodeType *expr1, NodeType *expr2) - { /* {{{ */ - NodeType *add = new_op(name, id, 2); - add->unode.opr.op[0] = expr1; - add->unode.opr.op[1] = expr2; - return add; - } /* }}} */ - - /* ADD */ - static NodeType *new_add(NodeType *expr1, NodeType *expr2) { /* {{{ */ - return new_expr2("add", OPR_ADD, expr1, expr2); - } - static void precommit_add(NodeType *add) { - precommit_expr(add,"add",INSTR_ADD); - } /* }}} */ - - /* SUB */ - static NodeType *new_sub(NodeType *expr1, NodeType *expr2) { /* {{{ */ - return new_expr2("sub", OPR_SUB, expr1, expr2); - } - static void precommit_sub(NodeType *sub) { - precommit_expr(sub,"sub",INSTR_SUB); - } /* }}} */ - - /* NEG */ - static NodeType *new_neg(NodeType *expr) { /* {{{ */ - NodeType *zeroConst = NULL; - if (expr->type == CONST_INT_NODE) - zeroConst = new_constInt("0", currentGoomSL->num_lines); - else if (expr->type == CONST_FLOAT_NODE) - zeroConst = new_constFloat("0.0", currentGoomSL->num_lines); - else if (expr->type == CONST_PTR_NODE) { - fprintf(stderr, "ERROR: Line %d, Could not negate const pointer.\n", - currentGoomSL->num_lines); - exit(1); - } - else { - int type = gsl_type_of_var(expr->vnamespace, expr->str); - if (type == INSTR_FLOAT) - zeroConst = new_constFloat("0.0", currentGoomSL->num_lines); - else if (type == INSTR_PTR) { - fprintf(stderr, "ERROR: Line %d, Could not negate pointer.\n", - currentGoomSL->num_lines); - exit(1); - } - else if (type == INSTR_INT) - zeroConst = new_constInt("0", currentGoomSL->num_lines); - else if (type == -1) { - fprintf(stderr, "ERROR: Line %d, Could not find variable '%s'\n", - expr->line_number, expr->unode.opr.op[0]->str); - exit(1); - } - else { /* type is a struct_id */ - fprintf(stderr, "ERROR: Line %d, Could not negate struct '%s'\n", - expr->line_number, expr->str); - exit(1); - } - } - return new_expr2("sub", OPR_SUB, zeroConst, expr); - } - /* }}} */ - - /* MUL */ - static NodeType *new_mul(NodeType *expr1, NodeType *expr2) { /* {{{ */ - return new_expr2("mul", OPR_MUL, expr1, expr2); - } - static void precommit_mul(NodeType *mul) { - precommit_expr(mul,"mul",INSTR_MUL); - } /* }}} */ - - /* DIV */ - static NodeType *new_div(NodeType *expr1, NodeType *expr2) { /* {{{ */ - return new_expr2("div", OPR_DIV, expr1, expr2); - } - static void precommit_div(NodeType *mul) { - precommit_expr(mul,"div",INSTR_DIV); - } /* }}} */ - - /* CALL EXPRESSION */ - static NodeType *new_call_expr(const char *name, NodeType *affect_list) { /* {{{ */ - NodeType *call = new_call(name,affect_list); - NodeType *node = new_expr1(name, OPR_CALL_EXPR, call); - node->vnamespace = gsl_find_namespace(name); - if (node->vnamespace == NULL) - fprintf(stderr, "ERROR: Line %d, No return type for: '%s'\n", currentGoomSL->num_lines, name); - return node; - } - static void precommit_call_expr(NodeType *call) { - char stmp[256]; - NodeType *tmp,*tmpcpy; - int type = gsl_type_of_var(call->vnamespace, call->str); - if (type == INSTR_FLOAT) { - sprintf(stmp,"_f_tmp_%i",allocateTemp()); - gsl_float_decl_global(stmp); - } - else if (type == INSTR_PTR) { - sprintf(stmp,"_p_tmp_%i",allocateTemp()); - gsl_ptr_decl_global(stmp); - } - else if (type == INSTR_INT) { - sprintf(stmp,"_i_tmp_%i",allocateTemp()); - gsl_int_decl_global(stmp); - } - else if (type == -1) { - fprintf(stderr, "ERROR: Line %d, Could not find variable '%s'\n", - call->line_number, call->str); - exit(1); - } - else { /* type is a struct_id */ - sprintf(stmp,"_s_tmp_%i",allocateTemp()); - gsl_struct_decl_global_from_id(stmp,type); - } - tmp = new_var(stmp,call->line_number); - commit_node(call->unode.opr.op[0],0); - tmpcpy = nodeClone(tmp); - commit_node(new_set(tmp,new_var(call->str,call->line_number)),0); - - nodeFreeInternals(call); - *call = *tmpcpy; - free(tmpcpy); - } /* }}} */ - - static void commit_test2(NodeType *set,const char *type, int instr) - { /* {{{ */ - NodeType *tmp; - char stmp[256]; - precommit_node(set->unode.opr.op[0]); - precommit_node(set->unode.opr.op[1]); - tmp = set->unode.opr.op[0]; - - stmp[0] = 0; - if (set->unode.opr.op[0]->type == CONST_INT_NODE) { - sprintf(stmp,"_i_tmp_%i",allocateTemp()); - gsl_int_decl_global(stmp); - } - else if (set->unode.opr.op[0]->type == CONST_FLOAT_NODE) { - sprintf(stmp,"_f_tmp%i",allocateTemp()); - gsl_float_decl_global(stmp); - } - else if (set->unode.opr.op[0]->type == CONST_PTR_NODE) { - sprintf(stmp,"_p_tmp%i",allocateTemp()); - gsl_ptr_decl_global(stmp); - } - if (stmp[0]) { - NodeType *tmpcpy; - tmp = new_var(stmp, set->line_number); - tmpcpy = nodeClone(tmp); - commit_node(new_set(tmp,set->unode.opr.op[0]),0); - tmp = tmpcpy; - } - -#ifdef VERBOSE - printf("%s %s %s\n", type, tmp->str, set->unode.opr.op[1]->str); -#endif - currentGoomSL->instr = gsl_instr_init(currentGoomSL, type, instr, 2, set->line_number); - commit_node(tmp,instr!=INSTR_SET); - commit_node(set->unode.opr.op[1],1); - } /* }}} */ - - /* NOT */ - static NodeType *new_not(NodeType *expr1) { /* {{{ */ - return new_expr1("not", OPR_NOT, expr1); - } - static void commit_not(NodeType *set) - { - commit_node(set->unode.opr.op[0],0); -#ifdef VERBOSE - printf("not\n"); -#endif - currentGoomSL->instr = gsl_instr_init(currentGoomSL, "not", INSTR_NOT, 1, set->line_number); - gsl_instr_add_param(currentGoomSL->instr, "|dummy|", TYPE_LABEL); - } /* }}} */ - - /* EQU */ - static NodeType *new_equ(NodeType *expr1, NodeType *expr2) { /* {{{ */ - return new_expr2("isequal", OPR_EQU, expr1, expr2); - } - static void commit_equ(NodeType *mul) { - commit_test2(mul,"isequal",INSTR_ISEQUAL); - } /* }}} */ - - /* INF */ - static NodeType *new_low(NodeType *expr1, NodeType *expr2) { /* {{{ */ - return new_expr2("islower", OPR_LOW, expr1, expr2); - } - static void commit_low(NodeType *mul) { - commit_test2(mul,"islower",INSTR_ISLOWER); - } /* }}} */ - - /* WHILE */ - static NodeType *new_while(NodeType *expression, NodeType *instr) { /* {{{ */ - NodeType *node = new_op("while", OPR_WHILE, 2); - node->unode.opr.op[0] = expression; - node->unode.opr.op[1] = instr; - return node; - } - - static void commit_while(NodeType *node) - { - int lbl = allocateLabel(); - char start_while[1024], test_while[1024]; - sprintf(start_while, "|start_while_%d|", lbl); - sprintf(test_while, "|test_while_%d|", lbl); - - GSL_PUT_JUMP(test_while,node->line_number); - GSL_PUT_LABEL(start_while,node->line_number); - - /* code */ - commit_node(node->unode.opr.op[1],0); - - GSL_PUT_LABEL(test_while,node->line_number); - commit_node(node->unode.opr.op[0],0); - GSL_PUT_JNZERO(start_while,node->line_number); - } /* }}} */ - - /* FOR EACH */ - static NodeType *new_static_foreach(NodeType *var, NodeType *var_list, NodeType *instr) { /* {{{ */ - NodeType *node = new_op("for", OPR_FOREACH, 3); - node->unode.opr.op[0] = var; - node->unode.opr.op[1] = var_list; - node->unode.opr.op[2] = instr; - node->line_number = currentGoomSL->num_lines; - return node; - } - static void commit_foreach(NodeType *node) - { - NodeType *cur = node->unode.opr.op[1]; - char tmp_func[256], tmp_loop[256]; - int lbl = allocateLabel(); - sprintf(tmp_func, "|foreach_func_%d|", lbl); - sprintf(tmp_loop, "|foreach_loop_%d|", lbl); - - GSL_PUT_JUMP(tmp_loop, node->line_number); - GSL_PUT_LABEL(tmp_func, node->line_number); - - precommit_node(node->unode.opr.op[2]); - commit_node(node->unode.opr.op[2], 0); - - currentGoomSL->instr = gsl_instr_init(currentGoomSL, "ret", INSTR_RET, 1, node->line_number); - gsl_instr_add_param(currentGoomSL->instr, "|dummy|", TYPE_LABEL); -#ifdef VERBOSE - printf("ret\n"); -#endif - - GSL_PUT_LABEL(tmp_loop, node->line_number); - - while (cur != NULL) - { - NodeType *x, *var; - - /* 1: x=var */ - x = nodeClone(node->unode.opr.op[0]); - var = nodeClone(cur->unode.opr.op[0]); - commit_node(new_set(x, var),0); - - /* 2: instr */ - currentGoomSL->instr = gsl_instr_init(currentGoomSL, "call", INSTR_CALL, 1, node->line_number); - gsl_instr_add_param(currentGoomSL->instr, tmp_func, TYPE_LABEL); -#ifdef VERBOSE - printf("call %s\n", tmp_func); -#endif - - /* 3: var=x */ - x = nodeClone(node->unode.opr.op[0]); - var = cur->unode.opr.op[0]; - commit_node(new_set(var, x),0); - cur = cur->unode.opr.op[1]; - } - nodeFree(node->unode.opr.op[0]); - } /* }}} */ - - /* IF */ - static NodeType *new_if(NodeType *expression, NodeType *instr) { /* {{{ */ - NodeType *node = new_op("if", OPR_IF, 2); - node->unode.opr.op[0] = expression; - node->unode.opr.op[1] = instr; - return node; - } - static void commit_if(NodeType *node) { - - char slab[1024]; - sprintf(slab, "|eif%d|", allocateLabel()); - commit_node(node->unode.opr.op[0],0); - GSL_PUT_JZERO(slab,node->line_number); - /* code */ - commit_node(node->unode.opr.op[1],0); - GSL_PUT_LABEL(slab,node->line_number); - } /* }}} */ - - /* BLOCK */ - static NodeType *new_block(NodeType *lastNode) { /* {{{ */ - NodeType *blk = new_op("block", OPR_BLOCK, 2); - blk->unode.opr.op[0] = new_nop("start_of_block"); - blk->unode.opr.op[1] = lastNode; - return blk; - } - static void commit_block(NodeType *node) { - commit_node(node->unode.opr.op[0]->unode.opr.next,0); - } /* }}} */ - - /* FUNCTION INTRO */ - static NodeType *new_function_intro(const char *name) { /* {{{ */ - char stmp[256]; - if (strlen(name) < 200) { - sprintf(stmp, "|__func_%s|", name); - } - return new_op(stmp, OPR_FUNC_INTRO, 0); - } - static void commit_function_intro(NodeType *node) { - currentGoomSL->instr = gsl_instr_init(currentGoomSL, "label", INSTR_LABEL, 1, node->line_number); - gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_LABEL); -#ifdef VERBOSE - printf("label %s\n", node->str); -#endif - } /* }}} */ - - /* FUNCTION OUTRO */ - static NodeType *new_function_outro() { /* {{{ */ - return new_op("ret", OPR_FUNC_OUTRO, 0); - } - static void commit_function_outro(NodeType *node) { - currentGoomSL->instr = gsl_instr_init(currentGoomSL, "ret", INSTR_RET, 1, node->line_number); - gsl_instr_add_param(currentGoomSL->instr, "|dummy|", TYPE_LABEL); - releaseAllTemps(); -#ifdef VERBOSE - printf("ret\n"); -#endif - } /* }}} */ - - /* AFFECTATION LIST */ - static NodeType *new_affec_list(NodeType *set, NodeType *next) /* {{{ */ - { - NodeType *node = new_op("affect_list", OPR_AFFECT_LIST, 2); - node->unode.opr.op[0] = set; - node->unode.opr.op[1] = next; - return node; - } - static NodeType *new_affect_list_after(NodeType *affect_list) - { - NodeType *ret = NULL; - NodeType *cur = affect_list; - while(cur != NULL) { - NodeType *set = cur->unode.opr.op[0]; - NodeType *next = cur->unode.opr.op[1]; - NodeType *lvalue = set->unode.opr.op[0]; - NodeType *expression = set->unode.opr.op[1]; - if ((lvalue->str[0] == '&') && (expression->type == VAR_NODE)) { - NodeType *nset = new_set(nodeClone(expression), nodeClone(lvalue)); - ret = new_affec_list(nset, ret); - } - cur = next; - } - return ret; - } - static void commit_affect_list(NodeType *node) - { - NodeType *cur = node; - while(cur != NULL) { - NodeType *set = cur->unode.opr.op[0]; - precommit_node(set->unode.opr.op[0]); - precommit_node(set->unode.opr.op[1]); - cur = cur->unode.opr.op[1]; - } - cur = node; - while(cur != NULL) { - NodeType *set = cur->unode.opr.op[0]; - commit_node(set,0); - cur = cur->unode.opr.op[1]; - } - } /* }}} */ - - /* VAR LIST */ - static NodeType *new_var_list(NodeType *var, NodeType *next) /* {{{ */ - { - NodeType *node = new_op("var_list", OPR_VAR_LIST, 2); - node->unode.opr.op[0] = var; - node->unode.opr.op[1] = next; - return node; - } - static void commit_var_list(NodeType *node) - { - } /* }}} */ - - /* FUNCTION CALL */ - static NodeType *new_call(const char *name, NodeType *affect_list) { /* {{{ */ - HashValue *fval; - fval = goom_hash_get(currentGoomSL->functions, name); - if (!fval) { - gsl_declare_task(name); - fval = goom_hash_get(currentGoomSL->functions, name); - } - if (!fval) { - fprintf(stderr, "ERROR: Line %d, Could not find function %s\n", currentGoomSL->num_lines, name); - exit(1); - return NULL; - } - else { - ExternalFunctionStruct *gef = (ExternalFunctionStruct*)fval->ptr; - if (gef->is_extern) { - NodeType *node = new_op(name, OPR_EXT_CALL, 1); - node->unode.opr.op[0] = affect_list; - return node; - } - else { - NodeType *node; - char stmp[256]; - if (strlen(name) < 200) { - sprintf(stmp, "|__func_%s|", name); - } - node = new_op(stmp, OPR_CALL, 1); - node->unode.opr.op[0] = affect_list; - return node; - } - } - } - static void commit_ext_call(NodeType *node) { - NodeType *alafter = new_affect_list_after(node->unode.opr.op[0]); - commit_node(node->unode.opr.op[0],0); - currentGoomSL->instr = gsl_instr_init(currentGoomSL, "extcall", INSTR_EXT_CALL, 1, node->line_number); - gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_VAR); -#ifdef VERBOSE - printf("extcall %s\n", node->str); -#endif - commit_node(alafter,0); - } - static void commit_call(NodeType *node) { - NodeType *alafter = new_affect_list_after(node->unode.opr.op[0]); - commit_node(node->unode.opr.op[0],0); - currentGoomSL->instr = gsl_instr_init(currentGoomSL, "call", INSTR_CALL, 1, node->line_number); - gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_LABEL); -#ifdef VERBOSE - printf("call %s\n", node->str); -#endif - commit_node(alafter,0); - } /* }}} */ - - /** **/ - - static NodeType *rootNode = 0; /* TODO: reinitialiser a chaque compilation. */ - static NodeType *lastNode = 0; - static NodeType *gsl_append(NodeType *curNode) { - if (curNode == 0) return 0; /* {{{ */ - if (lastNode) - lastNode->unode.opr.next = curNode; - lastNode = curNode; - while(lastNode->unode.opr.next) lastNode = lastNode->unode.opr.next; - if (rootNode == 0) - rootNode = curNode; - return curNode; - } /* }}} */ - -#if 1 - int allocateTemp() { - return allocateLabel(); - } - void releaseAllTemps() {} - void releaseTemp(int n) {} -#else - static int nbTemp = 0; - static int *tempArray = 0; - static int tempArraySize = 0; - int allocateTemp() { /* TODO: allocateITemp, allocateFTemp */ - int i = 0; /* {{{ */ - if (tempArray == 0) { - tempArraySize = 256; - tempArray = (int*)malloc(tempArraySize * sizeof(int)); - } - while (1) { - int j; - for (j=0;jtype == OPR_NODE) - switch(node->unode.opr.type) { - case OPR_ADD: precommit_add(node); break; - case OPR_SUB: precommit_sub(node); break; - case OPR_MUL: precommit_mul(node); break; - case OPR_DIV: precommit_div(node); break; - case OPR_CALL_EXPR: precommit_call_expr(node); break; - } - } /* }}} */ - - void commit_node(NodeType *node, int releaseIfTmp) - { /* {{{ */ - if (node == 0) return; - - switch(node->type) { - case OPR_NODE: - switch(node->unode.opr.type) { - case OPR_SET: commit_set(node); break; - case OPR_PLUS_EQ: commit_plus_eq(node); break; - case OPR_SUB_EQ: commit_sub_eq(node); break; - case OPR_MUL_EQ: commit_mul_eq(node); break; - case OPR_DIV_EQ: commit_div_eq(node); break; - case OPR_IF: commit_if(node); break; - case OPR_WHILE: commit_while(node); break; - case OPR_BLOCK: commit_block(node); break; - case OPR_FUNC_INTRO: commit_function_intro(node); break; - case OPR_FUNC_OUTRO: commit_function_outro(node); break; - case OPR_CALL: commit_call(node); break; - case OPR_EXT_CALL: commit_ext_call(node); break; - case OPR_EQU: commit_equ(node); break; - case OPR_LOW: commit_low(node); break; - case OPR_NOT: commit_not(node); break; - case OPR_AFFECT_LIST: commit_affect_list(node); break; - case OPR_FOREACH: commit_foreach(node); break; - case OPR_VAR_LIST: commit_var_list(node); break; -#ifdef VERBOSE - case EMPTY_NODE: printf("NOP\n"); break; -#endif - } - - commit_node(node->unode.opr.next,0); /* recursive for the moment, maybe better to do something iterative? */ - break; - - case VAR_NODE: gsl_instr_set_namespace(currentGoomSL->instr, node->vnamespace); - gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_VAR); break; - case CONST_INT_NODE: gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_INTEGER); break; - case CONST_FLOAT_NODE: gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_FLOAT); break; - case CONST_PTR_NODE: gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_PTR); break; - } - if (releaseIfTmp && is_tmp_expr(node)) - releaseTemp(get_tmp_id(node)); - - nodeFree(node); - } /* }}} */ - - NodeType *nodeNew(const char *str, int type, int line_number) { - NodeType *node = (NodeType*)malloc(sizeof(NodeType)); /* {{{ */ - node->type = type; - node->str = (char*)malloc(strlen(str)+1); - node->vnamespace = NULL; - node->line_number = line_number; - strcpy(node->str, str); - return node; - } /* }}} */ - static NodeType *nodeClone(NodeType *node) { - NodeType *ret = nodeNew(node->str, node->type, node->line_number); /* {{{ */ - ret->vnamespace = node->vnamespace; - ret->unode = node->unode; - return ret; - } /* }}} */ - - void nodeFreeInternals(NodeType *node) { - free(node->str); /* {{{ */ - } /* }}} */ - - void nodeFree(NodeType *node) { - nodeFreeInternals(node); /* {{{ */ - free(node); - } /* }}} */ - - NodeType *new_constInt(const char *str, int line_number) { - NodeType *node = nodeNew(str, CONST_INT_NODE, line_number); /* {{{ */ - node->unode.constInt.val = atoi(str); - return node; - } /* }}} */ - - NodeType *new_constPtr(const char *str, int line_number) { - NodeType *node = nodeNew(str, CONST_PTR_NODE, line_number); /* {{{ */ - node->unode.constPtr.id = strtol(str,NULL,0); - return node; - } /* }}} */ - - NodeType *new_constFloat(const char *str, int line_number) { - NodeType *node = nodeNew(str, CONST_FLOAT_NODE, line_number); /* {{{ */ - node->unode.constFloat.val = atof(str); - return node; - } /* }}} */ - - NodeType *new_var(const char *str, int line_number) { - NodeType *node = nodeNew(str, VAR_NODE, line_number); /* {{{ */ - node->vnamespace = gsl_find_namespace(str); - if (node->vnamespace == 0) { - fprintf(stderr, "ERROR: Line %d, Variable not found: '%s'\n", line_number, str); - exit(1); - } - return node; - } /* }}} */ - - NodeType *new_nop(const char *str) { - NodeType *node = new_op(str, EMPTY_NODE, 0); /* {{{ */ - return node; - } /* }}} */ - - NodeType *new_op(const char *str, int type, int nbOp) { - int i; /* {{{ */ - NodeType *node = nodeNew(str, OPR_NODE, currentGoomSL->num_lines); - node->unode.opr.next = 0; - node->unode.opr.type = type; - node->unode.opr.nbOp = nbOp; - for (i=0;iunode.opr.op[i] = 0; - return node; - } /* }}} */ - - - void gsl_declare_global_variable(int type, char *name) { - switch(type){ - case -1: break; - case FLOAT_TK:gsl_float_decl_global(name);break; - case INT_TK: gsl_int_decl_global(name);break; - case PTR_TK: gsl_ptr_decl_global(name);break; - default: - { - int id = type - 1000; - gsl_struct_decl_global_from_id(name,id); - } - } - } - - - -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif - -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 0 -#endif - -#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) -#line 1199 "goomsl_yacc.y" -typedef union YYSTYPE { - int intValue; - float floatValue; - char charValue; - char strValue[2048]; - NodeType *nPtr; - GoomHash *namespace; - GSL_Struct *gsl_struct; - GSL_StructField *gsl_struct_field; - } YYSTYPE; -/* Line 191 of yacc.c. */ -#line 1327 "goomsl_yacc.c" -# define yystype YYSTYPE /* obsolescent; will be withdrawn */ -# define YYSTYPE_IS_DECLARED 1 -# define YYSTYPE_IS_TRIVIAL 1 -#endif - - - -/* Copy the second part of user declarations. */ - - -/* Line 214 of yacc.c. */ -#line 1339 "goomsl_yacc.c" - -#if ! defined (yyoverflow) || YYERROR_VERBOSE - -/* The parser invokes alloca or malloc; define the necessary symbols. */ - -# if YYSTACK_USE_ALLOCA -# define YYSTACK_ALLOC alloca -# else -# ifndef YYSTACK_USE_ALLOCA -# if defined (alloca) || defined (_ALLOCA_H) -# define YYSTACK_ALLOC alloca -# else -# ifdef __GNUC__ -# define YYSTACK_ALLOC __builtin_alloca -# endif -# endif -# endif -# endif - -# ifdef YYSTACK_ALLOC - /* Pacify GCC's `empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) -# else -# if defined (__STDC__) || defined (__cplusplus) -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# endif -# define YYSTACK_ALLOC malloc -# define YYSTACK_FREE free -# endif -#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */ - - -#if (! defined (yyoverflow) \ - && (! defined (__cplusplus) \ - || (YYSTYPE_IS_TRIVIAL))) - -/* A type that is properly aligned for any stack member. */ -union yyalloc -{ - short yyss; - YYSTYPE yyvs; - }; - -/* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) - -/* The size of an array large to enough to hold all stacks, each with - N elements. */ -# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (short) + sizeof (YYSTYPE)) \ - + YYSTACK_GAP_MAXIMUM) - -/* Copy COUNT objects from FROM to TO. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if 1 < __GNUC__ -# define YYCOPY(To, From, Count) \ - __builtin_memcpy (To, From, (Count) * sizeof (*(From))) -# else -# define YYCOPY(To, From, Count) \ - do \ - { \ - register YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ - } \ - while (0) -# endif -# endif - -/* Relocate STACK from its old location to the new one. The - local variables YYSIZE and YYSTACKSIZE give the old and new number of - elements in the stack, and YYPTR gives the new location of the - stack. Advance YYPTR to a properly aligned location for the next - stack. */ -# define YYSTACK_RELOCATE(Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack, Stack, yysize); \ - Stack = &yyptr->Stack; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ - } \ - while (0) - -#endif - -#if defined (__STDC__) || defined (__cplusplus) - typedef signed char yysigned_char; -#else - typedef short yysigned_char; -#endif - -/* YYFINAL -- State number of the termination state. */ -#define YYFINAL 3 -/* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 229 - -/* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 42 -/* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 30 -/* YYNRULES -- Number of rules. */ -#define YYNRULES 89 -/* YYNRULES -- Number of states. */ -#define YYNSTATES 217 - -/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ -#define YYUNDEFTOK 2 -#define YYMAXUTOK 279 - -#define YYTRANSLATE(YYX) \ - ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) - -/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ -static const unsigned char yytranslate[] = -{ - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 25, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 35, 36, 32, 29, 34, 30, 2, 31, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 33, 2, - 27, 26, 28, 37, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 40, 2, 41, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 38, 2, 39, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 -}; - -#if YYDEBUG -/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in - YYRHS. */ -static const unsigned short yyprhs[] = -{ - 0, 0, 3, 7, 10, 19, 30, 39, 50, 53, - 56, 57, 65, 68, 73, 76, 79, 82, 85, 87, - 89, 90, 93, 96, 99, 102, 104, 108, 111, 112, - 116, 122, 130, 131, 132, 137, 142, 147, 152, 154, - 157, 160, 163, 166, 169, 172, 179, 186, 193, 195, - 199, 203, 207, 211, 218, 222, 224, 227, 231, 232, - 234, 236, 240, 244, 248, 252, 255, 259, 261, 265, - 269, 273, 277, 281, 285, 288, 290, 292, 294, 298, - 304, 310, 318, 323, 330, 333, 335, 340, 344, 346 -}; - -/* YYRHS -- A `-1'-separated list of the rules' RHS. */ -static const yysigned_char yyrhs[] = -{ - 43, 0, -1, 44, 55, 52, -1, 44, 59, -1, - 44, 11, 27, 48, 28, 50, 25, 56, -1, 44, - 11, 27, 48, 33, 51, 28, 50, 25, 56, -1, - 44, 10, 27, 49, 28, 50, 25, 56, -1, 44, - 10, 27, 49, 33, 51, 28, 50, 25, 56, -1, - 44, 45, -1, 44, 25, -1, -1, 22, 27, 5, - 33, 46, 28, 25, -1, 71, 47, -1, 46, 34, - 71, 47, -1, 8, 5, -1, 9, 5, -1, 7, - 5, -1, 5, 5, -1, 5, -1, 5, -1, -1, - 33, 8, -1, 33, 9, -1, 33, 7, -1, 33, - 5, -1, 58, -1, 58, 34, 51, -1, 52, 53, - -1, -1, 54, 44, 55, -1, 27, 49, 28, 50, - 25, -1, 27, 49, 33, 51, 28, 50, 25, -1, - -1, -1, 9, 5, 26, 64, -1, 8, 5, 26, - 64, -1, 7, 5, 26, 64, -1, 5, 5, 26, - 64, -1, 58, -1, 9, 5, -1, 8, 5, -1, - 7, 5, -1, 5, 5, -1, 62, 25, -1, 57, - 25, -1, 35, 65, 36, 37, 71, 59, -1, 12, - 65, 71, 13, 71, 59, -1, 38, 25, 63, 44, - 39, 25, -1, 67, -1, 5, 15, 64, -1, 5, - 16, 64, -1, 5, 18, 64, -1, 5, 17, 64, - -1, 23, 5, 24, 60, 13, 59, -1, 35, 61, - 36, -1, 5, -1, 5, 61, -1, 5, 26, 64, - -1, -1, 5, -1, 66, -1, 64, 32, 64, -1, - 64, 31, 64, -1, 64, 29, 64, -1, 64, 30, - 64, -1, 30, 64, -1, 35, 64, 36, -1, 68, - -1, 64, 26, 64, -1, 64, 27, 64, -1, 64, - 28, 64, -1, 64, 19, 64, -1, 64, 20, 64, - -1, 64, 21, 64, -1, 14, 65, -1, 4, -1, - 3, -1, 6, -1, 49, 25, 56, -1, 49, 33, - 69, 25, 56, -1, 40, 49, 41, 25, 56, -1, - 40, 49, 33, 69, 41, 25, 56, -1, 40, 49, - 56, 41, -1, 40, 49, 33, 69, 41, 56, -1, - 70, 69, -1, 70, -1, 5, 26, 56, 64, -1, - 33, 56, 64, -1, 25, -1, -1 -}; - -/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ -static const unsigned short yyrline[] = -{ - 0, 1236, 1236, 1238, 1239, 1240, 1241, 1242, 1243, 1244, - 1245, 1250, 1253, 1254, 1257, 1258, 1259, 1260, 1265, 1267, - 1270, 1271, 1272, 1273, 1274, 1277, 1278, 1283, 1284, 1287, - 1289, 1291, 1294, 1296, 1300, 1301, 1302, 1303, 1304, 1307, - 1308, 1309, 1310, 1315, 1316, 1317, 1318, 1319, 1320, 1321, - 1322, 1323, 1324, 1325, 1328, 1330, 1331, 1334, 1336, 1339, - 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1350, 1351, - 1352, 1353, 1354, 1355, 1356, 1359, 1360, 1361, 1366, 1367, - 1368, 1369, 1373, 1374, 1377, 1378, 1380, 1384, 1393, 1393 -}; -#endif - -#if YYDEBUG || YYERROR_VERBOSE -/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. - First, the terminals, then, starting at YYNTOKENS, nonterminals. */ -static const char *const yytname[] = -{ - "$end", "error", "$undefined", "LTYPE_INTEGER", "LTYPE_FLOAT", - "LTYPE_VAR", "LTYPE_PTR", "PTR_TK", "INT_TK", "FLOAT_TK", "DECLARE", - "EXTERNAL", "WHILE", "DO", "NOT", "PLUS_EQ", "SUB_EQ", "DIV_EQ", - "MUL_EQ", "SUP_EQ", "LOW_EQ", "NOT_EQ", "STRUCT", "FOR", "IN", "'\\n'", - "'='", "'<'", "'>'", "'+'", "'-'", "'/'", "'*'", "':'", "','", "'('", - "')'", "'?'", "'{'", "'}'", "'['", "']'", "$accept", "gsl", "gsl_code", - "struct_declaration", "struct_members", "struct_member", - "ext_task_name", "task_name", "return_type", "arglist", - "gsl_def_functions", "function", "function_intro", "function_outro", - "leave_namespace", "declaration", "empty_declaration", "instruction", - "var_list", "var_list_content", "affectation", "start_block", - "expression", "test", "constValue", "func_call", "func_call_expression", - "affectation_list", "affectation_in_list", "opt_nl", 0 -}; -#endif - -# ifdef YYPRINT -/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to - token YYLEX-NUM. */ -static const unsigned short yytoknum[] = -{ - 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 279, 10, 61, 60, 62, 43, - 45, 47, 42, 58, 44, 40, 41, 63, 123, 125, - 91, 93 -}; -# endif - -/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const unsigned char yyr1[] = -{ - 0, 42, 43, 44, 44, 44, 44, 44, 44, 44, - 44, 45, 46, 46, 47, 47, 47, 47, 48, 49, - 50, 50, 50, 50, 50, 51, 51, 52, 52, 53, - 54, 54, 55, 56, 57, 57, 57, 57, 57, 58, - 58, 58, 58, 59, 59, 59, 59, 59, 59, 59, - 59, 59, 59, 59, 60, 61, 61, 62, 63, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 65, 65, - 65, 65, 65, 65, 65, 66, 66, 66, 67, 67, - 67, 67, 68, 68, 69, 69, 70, 70, 71, 71 -}; - -/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ -static const unsigned char yyr2[] = -{ - 0, 2, 3, 2, 8, 10, 8, 10, 2, 2, - 0, 7, 2, 4, 2, 2, 2, 2, 1, 1, - 0, 2, 2, 2, 2, 1, 3, 2, 0, 3, - 5, 7, 0, 0, 4, 4, 4, 4, 1, 2, - 2, 2, 2, 2, 2, 6, 6, 6, 1, 3, - 3, 3, 3, 6, 3, 1, 2, 3, 0, 1, - 1, 3, 3, 3, 3, 2, 3, 1, 3, 3, - 3, 3, 3, 3, 2, 1, 1, 1, 3, 5, - 5, 7, 4, 6, 2, 1, 4, 3, 1, 0 -}; - -/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state - STATE-NUM when YYTABLE doesn't specify something else to do. Zero - means the default is an error. */ -static const unsigned char yydefact[] = -{ - 10, 0, 32, 1, 19, 0, 0, 0, 0, 0, - 0, 0, 0, 9, 0, 0, 0, 8, 0, 28, - 0, 38, 3, 0, 48, 42, 0, 0, 0, 0, - 0, 41, 40, 39, 0, 0, 76, 75, 59, 77, - 0, 0, 0, 0, 0, 89, 60, 67, 0, 0, - 0, 58, 19, 0, 33, 0, 2, 44, 43, 0, - 49, 50, 52, 51, 57, 0, 0, 0, 0, 18, - 0, 74, 65, 0, 33, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 88, 0, 0, 0, 0, - 10, 0, 0, 78, 0, 33, 0, 85, 0, 27, - 10, 37, 36, 35, 34, 20, 0, 20, 0, 66, - 0, 0, 71, 72, 73, 68, 69, 70, 63, 64, - 62, 61, 89, 89, 0, 0, 89, 0, 0, 33, - 33, 0, 33, 84, 0, 32, 0, 0, 0, 0, - 0, 0, 0, 25, 0, 0, 0, 82, 0, 0, - 0, 55, 0, 0, 0, 0, 0, 80, 0, 87, - 79, 20, 0, 29, 24, 23, 21, 22, 33, 42, - 41, 40, 39, 20, 0, 33, 20, 33, 46, 0, - 89, 0, 0, 0, 0, 12, 56, 54, 53, 45, - 47, 33, 86, 0, 0, 6, 0, 26, 4, 0, - 83, 11, 0, 17, 16, 14, 15, 81, 30, 20, - 33, 33, 13, 0, 7, 5, 31 -}; - -/* YYDEFGOTO[NTERM-NUM]. */ -static const short yydefgoto[] = -{ - -1, 1, 2, 17, 149, 185, 70, 18, 137, 142, - 56, 99, 100, 19, 93, 20, 21, 22, 125, 152, - 23, 90, 44, 45, 46, 24, 47, 96, 97, 86 -}; - -/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -#define YYPACT_NINF -116 -static const short yypact[] = -{ - -116, 40, 136, -116, 103, 39, 66, 68, 61, 65, - 1, 77, 101, -116, 1, 84, 109, -116, 12, -116, - 91, -116, -116, 97, -116, 98, 72, 72, 72, 72, - 72, 99, 104, 113, 109, 130, -116, -116, -116, -116, - 1, 72, 72, 109, 166, 115, -116, -116, 145, 131, - 118, -116, -116, -24, -116, -3, 138, -116, -116, 72, - 159, 159, 159, 159, 159, 72, 72, 72, 14, -116, - 51, -116, 22, 102, 124, 72, 72, 72, 72, 72, - 72, 72, 72, 72, 72, -116, 160, 139, 140, 141, - -116, -3, 152, -116, 154, -116, 156, -3, 109, -116, - -116, 159, 159, 159, 159, 150, 82, 150, 82, -116, - -3, 158, 159, 159, 159, 159, 159, 159, 22, 22, - -116, -116, 115, 115, 195, 188, 115, 88, 162, -116, - -116, 72, -116, -116, 52, 136, 155, 177, 199, 200, - 201, 202, 180, 175, 185, 183, 171, -116, 144, 18, - 161, 195, 178, 144, 144, 190, 191, -116, 72, 159, - -116, 150, 82, -116, -116, -116, -116, -116, -116, -116, - -116, -116, -116, 150, 82, -116, 150, -116, -116, 192, - 115, 208, 213, 214, 215, -116, -116, -116, -116, -116, - -116, -116, 159, 196, 194, -116, 198, -116, -116, 203, - -116, -116, 161, -116, -116, -116, -116, -116, -116, 150, - -116, -116, -116, 204, -116, -116, -116 -}; - -/* YYPGOTO[NTERM-NUM]. */ -static const yysigned_char yypgoto[] = -{ - -116, -116, -68, -116, -116, 23, -116, -15, -104, -92, - -116, -116, -116, 89, -74, -116, -88, -115, -116, 75, - -116, -116, -16, -6, -116, -116, -116, -62, -116, -99 -}; - -/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule which - number is the opposite. If zero, do what YYDEFACT says. - If YYTABLE_NINF, syntax error. */ -#define YYTABLE_NINF -1 -static const unsigned char yytable[] = -{ - 111, 53, 94, 144, 36, 37, 38, 39, 50, 91, - 60, 61, 62, 63, 64, 40, 145, 92, 143, 68, - 143, 131, 127, 148, 150, 72, 73, 154, 74, 128, - 95, 41, 135, 178, 71, 133, 42, 54, 188, 189, - 3, 43, 105, 101, 31, 55, 179, 106, 146, 102, - 103, 104, 180, 83, 84, 157, 158, 193, 160, 112, - 113, 114, 115, 116, 117, 118, 119, 120, 121, 196, - 194, 32, 199, 33, 143, 36, 37, 38, 39, 107, - 161, 202, 197, 134, 108, 162, 143, 138, 34, 139, - 140, 141, 35, 4, 195, 5, 6, 7, 8, 9, - 10, 198, 41, 200, 48, 213, 49, 42, 25, 51, - 11, 12, 43, 13, 52, 159, 57, 207, 26, 27, - 28, 29, 58, 14, 59, 65, 15, 155, 16, 30, - 66, 81, 82, 83, 84, 69, 214, 215, 109, 67, - 85, 4, 192, 5, 6, 7, 8, 9, 10, 4, - 87, 5, 6, 7, 89, 88, 10, 110, 11, 12, - 164, 13, 165, 166, 167, 98, 181, 12, 182, 183, - 184, 14, 123, 122, 15, 124, 16, 129, 126, 14, - 130, 132, 15, 136, 16, 75, 76, 77, 81, 82, - 83, 84, 78, 79, 80, 81, 82, 83, 84, 147, - 151, 153, 168, 156, 169, 170, 171, 172, 173, 174, - 175, 176, 177, 203, 187, 190, 191, 201, 204, 205, - 206, 208, 209, 210, 163, 212, 186, 0, 211, 216 -}; - -static const short yycheck[] = -{ - 74, 16, 5, 107, 3, 4, 5, 6, 14, 33, - 26, 27, 28, 29, 30, 14, 108, 41, 106, 34, - 108, 95, 90, 122, 123, 41, 42, 126, 43, 91, - 33, 30, 100, 148, 40, 97, 35, 25, 153, 154, - 0, 40, 28, 59, 5, 33, 28, 33, 110, 65, - 66, 67, 34, 31, 32, 129, 130, 161, 132, 75, - 76, 77, 78, 79, 80, 81, 82, 83, 84, 173, - 162, 5, 176, 5, 162, 3, 4, 5, 6, 28, - 28, 180, 174, 98, 33, 33, 174, 5, 27, 7, - 8, 9, 27, 5, 168, 7, 8, 9, 10, 11, - 12, 175, 30, 177, 27, 209, 5, 35, 5, 25, - 22, 23, 40, 25, 5, 131, 25, 191, 15, 16, - 17, 18, 25, 35, 26, 26, 38, 39, 40, 26, - 26, 29, 30, 31, 32, 5, 210, 211, 36, 26, - 25, 5, 158, 7, 8, 9, 10, 11, 12, 5, - 5, 7, 8, 9, 36, 24, 12, 33, 22, 23, - 5, 25, 7, 8, 9, 27, 5, 23, 7, 8, - 9, 35, 33, 13, 38, 35, 40, 25, 37, 35, - 26, 25, 38, 33, 40, 19, 20, 21, 29, 30, - 31, 32, 26, 27, 28, 29, 30, 31, 32, 41, - 5, 13, 25, 41, 5, 5, 5, 5, 28, 34, - 25, 28, 41, 5, 36, 25, 25, 25, 5, 5, - 5, 25, 28, 25, 135, 202, 151, -1, 25, 25 -}; - -/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const unsigned char yystos[] = -{ - 0, 43, 44, 0, 5, 7, 8, 9, 10, 11, - 12, 22, 23, 25, 35, 38, 40, 45, 49, 55, - 57, 58, 59, 62, 67, 5, 15, 16, 17, 18, - 26, 5, 5, 5, 27, 27, 3, 4, 5, 6, - 14, 30, 35, 40, 64, 65, 66, 68, 27, 5, - 65, 25, 5, 49, 25, 33, 52, 25, 25, 26, - 64, 64, 64, 64, 64, 26, 26, 26, 49, 5, - 48, 65, 64, 64, 49, 19, 20, 21, 26, 27, - 28, 29, 30, 31, 32, 25, 71, 5, 24, 36, - 63, 33, 41, 56, 5, 33, 69, 70, 27, 53, - 54, 64, 64, 64, 64, 28, 33, 28, 33, 36, - 33, 56, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 13, 33, 35, 60, 37, 44, 69, 25, - 26, 56, 25, 69, 49, 44, 33, 50, 5, 7, - 8, 9, 51, 58, 50, 51, 69, 41, 71, 46, - 71, 5, 61, 13, 71, 39, 41, 56, 56, 64, - 56, 28, 33, 55, 5, 7, 8, 9, 25, 5, - 5, 5, 5, 28, 34, 25, 28, 41, 59, 28, - 34, 5, 7, 8, 9, 47, 61, 36, 59, 59, - 25, 25, 64, 50, 51, 56, 50, 51, 56, 50, - 56, 25, 71, 5, 5, 5, 5, 56, 25, 28, - 25, 25, 47, 50, 56, 56, 25 -}; - -#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) -# define YYSIZE_T __SIZE_TYPE__ -#endif -#if ! defined (YYSIZE_T) && defined (size_t) -# define YYSIZE_T size_t -#endif -#if ! defined (YYSIZE_T) -# if defined (__STDC__) || defined (__cplusplus) -# include /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# endif -#endif -#if ! defined (YYSIZE_T) -# define YYSIZE_T unsigned int -#endif - -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 - -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrlab1 - - -/* Like YYERROR except do call yyerror. This remains here temporarily - to ease the transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. */ - -#define YYFAIL goto yyerrlab - -#define YYRECOVERING() (!!yyerrstatus) - -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY && yylen == 1) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - yytoken = YYTRANSLATE (yychar); \ - YYPOPSTACK; \ - goto yybackup; \ - } \ - else \ - { \ - yyerror ("syntax error: cannot back up");\ - YYERROR; \ - } \ -while (0) - -#define YYTERROR 1 -#define YYERRCODE 256 - -/* YYLLOC_DEFAULT -- Compute the default location (before the actions - are run). */ - -#ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - Current.first_line = Rhs[1].first_line; \ - Current.first_column = Rhs[1].first_column; \ - Current.last_line = Rhs[N].last_line; \ - Current.last_column = Rhs[N].last_column; -#endif - -/* YYLEX -- calling `yylex' with the right arguments. */ - -#ifdef YYLEX_PARAM -# define YYLEX yylex (YYLEX_PARAM) -#else -# define YYLEX yylex () -#endif - -/* Enable debugging if requested. */ -#if YYDEBUG - -# ifndef YYFPRINTF -# include /* INFRINGES ON USER NAME SPACE */ -# define YYFPRINTF fprintf -# endif - -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (0) - -# define YYDSYMPRINT(Args) \ -do { \ - if (yydebug) \ - yysymprint Args; \ -} while (0) - -# define YYDSYMPRINTF(Title, Token, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yysymprint (stderr, \ - Token, Value); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (0) - -/*------------------------------------------------------------------. -| yy_stack_print -- Print the state stack from its BOTTOM up to its | -| TOP (cinluded). | -`------------------------------------------------------------------*/ - -#if defined (__STDC__) || defined (__cplusplus) -static void -yy_stack_print (short *bottom, short *top) -#else -static void -yy_stack_print (bottom, top) - short *bottom; - short *top; -#endif -{ - YYFPRINTF (stderr, "Stack now"); - for (/* Nothing. */; bottom <= top; ++bottom) - YYFPRINTF (stderr, " %d", *bottom); - YYFPRINTF (stderr, "\n"); -} - -# define YY_STACK_PRINT(Bottom, Top) \ -do { \ - if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ -} while (0) - - -/*------------------------------------------------. -| Report that the YYRULE is going to be reduced. | -`------------------------------------------------*/ - -#if defined (__STDC__) || defined (__cplusplus) -static void -yy_reduce_print (int yyrule) -#else -static void -yy_reduce_print (yyrule) - int yyrule; -#endif -{ - int yyi; - unsigned int yylineno = yyrline[yyrule]; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ", - yyrule - 1, yylineno); - /* Print the symbols being reduced, and their result. */ - for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) - YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]); - YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]); -} - -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug) \ - yy_reduce_print (Rule); \ -} while (0) - -/* Nonzero means print parse trace. It is left uninitialized so that - multiple parsers can coexist. */ -int yydebug; -#else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YYDSYMPRINT(Args) -# define YYDSYMPRINTF(Title, Token, Value, Location) -# define YY_STACK_PRINT(Bottom, Top) -# define YY_REDUCE_PRINT(Rule) -#endif /* !YYDEBUG */ - - -/* YYINITDEPTH -- initial size of the parser's stacks. */ -#ifndef YYINITDEPTH -# define YYINITDEPTH 200 -#endif - -/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only - if the built-in stack extension method is used). - - Do not make this value too large; the results are undefined if - SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH) - evaluated with infinite-precision integer arithmetic. */ - -#if YYMAXDEPTH == 0 -# undef YYMAXDEPTH -#endif - -#ifndef YYMAXDEPTH -# define YYMAXDEPTH 10000 -#endif - - - -#if YYERROR_VERBOSE - -# ifndef yystrlen -# if defined (__GLIBC__) && defined (_STRING_H) -# define yystrlen strlen -# else -/* Return the length of YYSTR. */ -static YYSIZE_T -# if defined (__STDC__) || defined (__cplusplus) -yystrlen (const char *yystr) -# else -yystrlen (yystr) - const char *yystr; -# endif -{ - register const char *yys = yystr; - - while (*yys++ != '\0') - continue; - - return yys - yystr - 1; -} -# endif -# endif - -# ifndef yystpcpy -# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) -# define yystpcpy stpcpy -# else -/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in - YYDEST. */ -static char * -# if defined (__STDC__) || defined (__cplusplus) -yystpcpy (char *yydest, const char *yysrc) -# else -yystpcpy (yydest, yysrc) - char *yydest; - const char *yysrc; -# endif -{ - register char *yyd = yydest; - register const char *yys = yysrc; - - while ((*yyd++ = *yys++) != '\0') - continue; - - return yyd - 1; -} -# endif -# endif - -#endif /* !YYERROR_VERBOSE */ - - - -#if YYDEBUG -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ - -#if defined (__STDC__) || defined (__cplusplus) -static void -yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep) -#else -static void -yysymprint (yyoutput, yytype, yyvaluep) - FILE *yyoutput; - int yytype; - YYSTYPE *yyvaluep; -#endif -{ - /* Pacify ``unused variable'' warnings. */ - (void) yyvaluep; - - if (yytype < YYNTOKENS) - { - YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); -# ifdef YYPRINT - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# endif - } - else - YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); - - switch (yytype) - { - default: - break; - } - YYFPRINTF (yyoutput, ")"); -} - -#endif /* ! YYDEBUG */ -/*-----------------------------------------------. -| Release the memory associated to this symbol. | -`-----------------------------------------------*/ - -#if defined (__STDC__) || defined (__cplusplus) -static void -yydestruct (int yytype, YYSTYPE *yyvaluep) -#else -static void -yydestruct (yytype, yyvaluep) - int yytype; - YYSTYPE *yyvaluep; -#endif -{ - /* Pacify ``unused variable'' warnings. */ - (void) yyvaluep; - - switch (yytype) - { - - default: - break; - } -} - - -/* Prevent warnings from -Wmissing-prototypes. */ - -#ifdef YYPARSE_PARAM -# if defined (__STDC__) || defined (__cplusplus) -int yyparse (void *YYPARSE_PARAM); -# else -int yyparse (); -# endif -#else /* ! YYPARSE_PARAM */ -#if defined (__STDC__) || defined (__cplusplus) -int yyparse (void); -#else -int yyparse (); -#endif -#endif /* ! YYPARSE_PARAM */ - - - -/* The lookahead symbol. */ -int yychar; - -/* The semantic value of the lookahead symbol. */ -YYSTYPE yylval; - -/* Number of syntax errors so far. */ -int yynerrs; - - - -/*----------. -| yyparse. | -`----------*/ - -#ifdef YYPARSE_PARAM -# if defined (__STDC__) || defined (__cplusplus) -int yyparse (void *YYPARSE_PARAM) -# else -int yyparse (YYPARSE_PARAM) - void *YYPARSE_PARAM; -# endif -#else /* ! YYPARSE_PARAM */ -#if defined (__STDC__) || defined (__cplusplus) -int -yyparse (void) -#else -int -yyparse () - -#endif -#endif -{ - - register int yystate; - register int yyn; - int yyresult; - /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; - /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; - - /* Three stacks and their tools: - `yyss': related to states, - `yyvs': related to semantic values, - `yyls': related to locations. - - Refer to the stacks thru separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ - - /* The state stack. */ - short yyssa[YYINITDEPTH]; - short *yyss = yyssa; - register short *yyssp; - - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs = yyvsa; - register YYSTYPE *yyvsp; - - - -#define YYPOPSTACK (yyvsp--, yyssp--) - - YYSIZE_T yystacksize = YYINITDEPTH; - - /* The variables used to return semantic value and location from the - action routines. */ - YYSTYPE yyval; - - - /* When reducing, the number of symbols on the RHS of the reduced - rule. */ - int yylen; - - YYDPRINTF ((stderr, "Starting parse\n")); - - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; - yychar = YYEMPTY; /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ - - yyssp = yyss; - yyvsp = yyvs; - - goto yysetstate; - -/*------------------------------------------------------------. -| yynewstate -- Push a new state, which is found in yystate. | -`------------------------------------------------------------*/ - yynewstate: - /* In all cases, when you get here, the value and location stacks - have just been pushed. so pushing a state here evens the stacks. - */ - yyssp++; - - yysetstate: - *yyssp = yystate; - - if (yyss + yystacksize - 1 <= yyssp) - { - /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = yyssp - yyss + 1; - -#ifdef yyoverflow - { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - YYSTYPE *yyvs1 = yyvs; - short *yyss1 = yyss; - - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow ("parser stack overflow", - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - - &yystacksize); - - yyss = yyss1; - yyvs = yyvs1; - } -#else /* no yyoverflow */ -# ifndef YYSTACK_RELOCATE - goto yyoverflowlab; -# else - /* Extend the stack our own way. */ - if (YYMAXDEPTH <= yystacksize) - goto yyoverflowlab; - yystacksize *= 2; - if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; - - { - short *yyss1 = yyss; - union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyoverflowlab; - YYSTACK_RELOCATE (yyss); - YYSTACK_RELOCATE (yyvs); - -# undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); - } -# endif -#endif /* no yyoverflow */ - - yyssp = yyss + yysize - 1; - yyvsp = yyvs + yysize - 1; - - - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); - - if (yyss + yystacksize - 1 <= yyssp) - YYABORT; - } - - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); - - goto yybackup; - -/*-----------. -| yybackup. | -`-----------*/ -yybackup: - -/* Do appropriate processing given the current state. */ -/* Read a lookahead token if we need one and don't already have one. */ -/* yyresume: */ - - /* First try to decide what to do without reference to lookahead token. */ - - yyn = yypact[yystate]; - if (yyn == YYPACT_NINF) - goto yydefault; - - /* Not known => get a lookahead token if don't already have one. */ - - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ - if (yychar == YYEMPTY) - { - YYDPRINTF ((stderr, "Reading a token: ")); - yychar = YYLEX; - } - - if (yychar <= YYEOF) - { - yychar = yytoken = YYEOF; - YYDPRINTF ((stderr, "Now at end of input.\n")); - } - else - { - yytoken = YYTRANSLATE (yychar); - YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc); - } - - /* If the proper action on seeing token YYTOKEN is to reduce or to - detect an error, take that action. */ - yyn += yytoken; - if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) - goto yydefault; - yyn = yytable[yyn]; - if (yyn <= 0) - { - if (yyn == 0 || yyn == YYTABLE_NINF) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } - - if (yyn == YYFINAL) - YYACCEPT; - - /* Shift the lookahead token. */ - YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken])); - - /* Discard the token being shifted unless it is eof. */ - if (yychar != YYEOF) - yychar = YYEMPTY; - - *++yyvsp = yylval; - - - /* Count tokens shifted since error; after three, turn off error - status. */ - if (yyerrstatus) - yyerrstatus--; - - yystate = yyn; - goto yynewstate; - - -/*-----------------------------------------------------------. -| yydefault -- do the default action for the current state. | -`-----------------------------------------------------------*/ -yydefault: - yyn = yydefact[yystate]; - if (yyn == 0) - goto yyerrlab; - goto yyreduce; - - -/*-----------------------------. -| yyreduce -- Do a reduction. | -`-----------------------------*/ -yyreduce: - /* yyn is the number of a rule to reduce with. */ - yylen = yyr2[yyn]; - - /* If YYLEN is nonzero, implement the default value of the action: - `$$ = $1'. - - Otherwise, the following line sets YYVAL to garbage. - This behavior is undocumented and Bison - users should not rely upon it. Assigning to YYVAL - unconditionally makes the parser a bit smaller, and it avoids a - GCC warning that YYVAL may be used uninitialized. */ - yyval = yyvsp[1-yylen]; - - - YY_REDUCE_PRINT (yyn); - switch (yyn) - { - case 3: -#line 1238 "goomsl_yacc.y" - { gsl_append(yyvsp[0].nPtr); } - break; - - case 4: -#line 1239 "goomsl_yacc.y" - { gsl_declare_global_variable(yyvsp[-2].intValue,yyvsp[-4].strValue); } - break; - - case 5: -#line 1240 "goomsl_yacc.y" - { gsl_declare_global_variable(yyvsp[-2].intValue,yyvsp[-6].strValue); } - break; - - case 6: -#line 1241 "goomsl_yacc.y" - { gsl_declare_global_variable(yyvsp[-2].intValue,yyvsp[-4].strValue); } - break; - - case 7: -#line 1242 "goomsl_yacc.y" - { gsl_declare_global_variable(yyvsp[-2].intValue,yyvsp[-6].strValue); } - break; - - case 11: -#line 1250 "goomsl_yacc.y" - { gsl_add_struct(yyvsp[-4].strValue, yyvsp[-2].gsl_struct); } - break; - - case 12: -#line 1253 "goomsl_yacc.y" - { yyval.gsl_struct = gsl_new_struct(yyvsp[0].gsl_struct_field); } - break; - - case 13: -#line 1254 "goomsl_yacc.y" - { yyval.gsl_struct = yyvsp[-3].gsl_struct; gsl_add_struct_field(yyvsp[-3].gsl_struct, yyvsp[0].gsl_struct_field); } - break; - - case 14: -#line 1257 "goomsl_yacc.y" - { yyval.gsl_struct_field = gsl_new_struct_field(yyvsp[0].strValue, INSTR_INT); } - break; - - case 15: -#line 1258 "goomsl_yacc.y" - { yyval.gsl_struct_field = gsl_new_struct_field(yyvsp[0].strValue, INSTR_FLOAT); } - break; - - case 16: -#line 1259 "goomsl_yacc.y" - { yyval.gsl_struct_field = gsl_new_struct_field(yyvsp[0].strValue, INSTR_PTR); } - break; - - case 17: -#line 1260 "goomsl_yacc.y" - { yyval.gsl_struct_field = gsl_new_struct_field_struct(yyvsp[0].strValue, yyvsp[-1].strValue); } - break; - - case 18: -#line 1265 "goomsl_yacc.y" - { gsl_declare_external_task(yyvsp[0].strValue); gsl_enternamespace(yyvsp[0].strValue); strcpy(yyval.strValue,yyvsp[0].strValue); } - break; - - case 19: -#line 1267 "goomsl_yacc.y" - { gsl_declare_task(yyvsp[0].strValue); gsl_enternamespace(yyvsp[0].strValue); strcpy(yyval.strValue,yyvsp[0].strValue); strcpy(yyval.strValue,yyvsp[0].strValue); } - break; - - case 20: -#line 1270 "goomsl_yacc.y" - { yyval.intValue=-1; } - break; - - case 21: -#line 1271 "goomsl_yacc.y" - { yyval.intValue=INT_TK; } - break; - - case 22: -#line 1272 "goomsl_yacc.y" - { yyval.intValue=FLOAT_TK; } - break; - - case 23: -#line 1273 "goomsl_yacc.y" - { yyval.intValue=PTR_TK; } - break; - - case 24: -#line 1274 "goomsl_yacc.y" - { yyval.intValue= 1000 + gsl_get_struct_id(yyvsp[0].strValue); } - break; - - case 29: -#line 1287 "goomsl_yacc.y" - { gsl_leavenamespace(); } - break; - - case 30: -#line 1289 "goomsl_yacc.y" - { gsl_append(new_function_intro(yyvsp[-3].strValue)); - gsl_declare_global_variable(yyvsp[-1].intValue,yyvsp[-3].strValue); } - break; - - case 31: -#line 1291 "goomsl_yacc.y" - { gsl_append(new_function_intro(yyvsp[-5].strValue)); - gsl_declare_global_variable(yyvsp[-1].intValue,yyvsp[-5].strValue); } - break; - - case 32: -#line 1294 "goomsl_yacc.y" - { gsl_append(new_function_outro()); } - break; - - case 33: -#line 1296 "goomsl_yacc.y" - { yyval.namespace = gsl_leavenamespace(); } - break; - - case 34: -#line 1300 "goomsl_yacc.y" - { gsl_float_decl_local(yyvsp[-2].strValue); yyval.nPtr = new_set(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines), yyvsp[0].nPtr); } - break; - - case 35: -#line 1301 "goomsl_yacc.y" - { gsl_int_decl_local(yyvsp[-2].strValue); yyval.nPtr = new_set(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines), yyvsp[0].nPtr); } - break; - - case 36: -#line 1302 "goomsl_yacc.y" - { gsl_ptr_decl_local(yyvsp[-2].strValue); yyval.nPtr = new_set(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines), yyvsp[0].nPtr); } - break; - - case 37: -#line 1303 "goomsl_yacc.y" - { gsl_struct_decl_local(yyvsp[-3].strValue,yyvsp[-2].strValue); yyval.nPtr = new_set(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines), yyvsp[0].nPtr); } - break; - - case 38: -#line 1304 "goomsl_yacc.y" - { yyval.nPtr = 0; } - break; - - case 39: -#line 1307 "goomsl_yacc.y" - { gsl_float_decl_local(yyvsp[0].strValue); } - break; - - case 40: -#line 1308 "goomsl_yacc.y" - { gsl_int_decl_local(yyvsp[0].strValue); } - break; - - case 41: -#line 1309 "goomsl_yacc.y" - { gsl_ptr_decl_local(yyvsp[0].strValue); } - break; - - case 42: -#line 1310 "goomsl_yacc.y" - { gsl_struct_decl_local(yyvsp[-1].strValue,yyvsp[0].strValue); } - break; - - case 43: -#line 1315 "goomsl_yacc.y" - { yyval.nPtr = yyvsp[-1].nPtr; } - break; - - case 44: -#line 1316 "goomsl_yacc.y" - { yyval.nPtr = yyvsp[-1].nPtr; } - break; - - case 45: -#line 1317 "goomsl_yacc.y" - { yyval.nPtr = new_if(yyvsp[-4].nPtr,yyvsp[0].nPtr); } - break; - - case 46: -#line 1318 "goomsl_yacc.y" - { yyval.nPtr = new_while(yyvsp[-4].nPtr,yyvsp[0].nPtr); } - break; - - case 47: -#line 1319 "goomsl_yacc.y" - { lastNode = yyvsp[-3].nPtr->unode.opr.op[1]; yyval.nPtr=yyvsp[-3].nPtr; } - break; - - case 48: -#line 1320 "goomsl_yacc.y" - { yyval.nPtr = yyvsp[0].nPtr; } - break; - - case 49: -#line 1321 "goomsl_yacc.y" - { yyval.nPtr = new_plus_eq(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines),yyvsp[0].nPtr); } - break; - - case 50: -#line 1322 "goomsl_yacc.y" - { yyval.nPtr = new_sub_eq(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines),yyvsp[0].nPtr); } - break; - - case 51: -#line 1323 "goomsl_yacc.y" - { yyval.nPtr = new_mul_eq(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines),yyvsp[0].nPtr); } - break; - - case 52: -#line 1324 "goomsl_yacc.y" - { yyval.nPtr = new_div_eq(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines),yyvsp[0].nPtr); } - break; - - case 53: -#line 1325 "goomsl_yacc.y" - { yyval.nPtr = new_static_foreach(new_var(yyvsp[-4].strValue, currentGoomSL->num_lines), yyvsp[-2].nPtr, yyvsp[0].nPtr); } - break; - - case 54: -#line 1328 "goomsl_yacc.y" - { yyval.nPtr = yyvsp[-1].nPtr; } - break; - - case 55: -#line 1330 "goomsl_yacc.y" - { yyval.nPtr = new_var_list(new_var(yyvsp[0].strValue,currentGoomSL->num_lines), NULL); } - break; - - case 56: -#line 1331 "goomsl_yacc.y" - { yyval.nPtr = new_var_list(new_var(yyvsp[-1].strValue,currentGoomSL->num_lines), yyvsp[0].nPtr); } - break; - - case 57: -#line 1334 "goomsl_yacc.y" - { yyval.nPtr = new_set(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines),yyvsp[0].nPtr); } - break; - - case 58: -#line 1336 "goomsl_yacc.y" - { yyval.nPtr = new_block(lastNode); lastNode = yyval.nPtr->unode.opr.op[0]; } - break; - - case 59: -#line 1339 "goomsl_yacc.y" - { yyval.nPtr = new_var(yyvsp[0].strValue,currentGoomSL->num_lines); } - break; - - case 60: -#line 1340 "goomsl_yacc.y" - { yyval.nPtr = yyvsp[0].nPtr; } - break; - - case 61: -#line 1341 "goomsl_yacc.y" - { yyval.nPtr = new_mul(yyvsp[-2].nPtr,yyvsp[0].nPtr); } - break; - - case 62: -#line 1342 "goomsl_yacc.y" - { yyval.nPtr = new_div(yyvsp[-2].nPtr,yyvsp[0].nPtr); } - break; - - case 63: -#line 1343 "goomsl_yacc.y" - { yyval.nPtr = new_add(yyvsp[-2].nPtr,yyvsp[0].nPtr); } - break; - - case 64: -#line 1344 "goomsl_yacc.y" - { yyval.nPtr = new_sub(yyvsp[-2].nPtr,yyvsp[0].nPtr); } - break; - - case 65: -#line 1345 "goomsl_yacc.y" - { yyval.nPtr = new_neg(yyvsp[0].nPtr); } - break; - - case 66: -#line 1346 "goomsl_yacc.y" - { yyval.nPtr = yyvsp[-1].nPtr; } - break; - - case 67: -#line 1347 "goomsl_yacc.y" - { yyval.nPtr = yyvsp[0].nPtr; } - break; - - case 68: -#line 1350 "goomsl_yacc.y" - { yyval.nPtr = new_equ(yyvsp[-2].nPtr,yyvsp[0].nPtr); } - break; - - case 69: -#line 1351 "goomsl_yacc.y" - { yyval.nPtr = new_low(yyvsp[-2].nPtr,yyvsp[0].nPtr); } - break; - - case 70: -#line 1352 "goomsl_yacc.y" - { yyval.nPtr = new_low(yyvsp[0].nPtr,yyvsp[-2].nPtr); } - break; - - case 71: -#line 1353 "goomsl_yacc.y" - { yyval.nPtr = new_not(new_low(yyvsp[-2].nPtr,yyvsp[0].nPtr)); } - break; - - case 72: -#line 1354 "goomsl_yacc.y" - { yyval.nPtr = new_not(new_low(yyvsp[0].nPtr,yyvsp[-2].nPtr)); } - break; - - case 73: -#line 1355 "goomsl_yacc.y" - { yyval.nPtr = new_not(new_equ(yyvsp[-2].nPtr,yyvsp[0].nPtr)); } - break; - - case 74: -#line 1356 "goomsl_yacc.y" - { yyval.nPtr = new_not(yyvsp[0].nPtr); } - break; - - case 75: -#line 1359 "goomsl_yacc.y" - { yyval.nPtr = new_constFloat(yyvsp[0].strValue,currentGoomSL->num_lines); } - break; - - case 76: -#line 1360 "goomsl_yacc.y" - { yyval.nPtr = new_constInt(yyvsp[0].strValue,currentGoomSL->num_lines); } - break; - - case 77: -#line 1361 "goomsl_yacc.y" - { yyval.nPtr = new_constPtr(yyvsp[0].strValue,currentGoomSL->num_lines); } - break; - - case 78: -#line 1366 "goomsl_yacc.y" - { yyval.nPtr = new_call(yyvsp[-2].strValue,NULL); } - break; - - case 79: -#line 1367 "goomsl_yacc.y" - { yyval.nPtr = new_call(yyvsp[-4].strValue,yyvsp[-2].nPtr); } - break; - - case 80: -#line 1368 "goomsl_yacc.y" - { yyval.nPtr = new_call(yyvsp[-3].strValue,NULL); } - break; - - case 81: -#line 1369 "goomsl_yacc.y" - { yyval.nPtr = new_call(yyvsp[-5].strValue,yyvsp[-3].nPtr); } - break; - - case 82: -#line 1373 "goomsl_yacc.y" - { yyval.nPtr = new_call_expr(yyvsp[-2].strValue,NULL); } - break; - - case 83: -#line 1374 "goomsl_yacc.y" - { yyval.nPtr = new_call_expr(yyvsp[-4].strValue,yyvsp[-2].nPtr); } - break; - - case 84: -#line 1377 "goomsl_yacc.y" - { yyval.nPtr = new_affec_list(yyvsp[-1].nPtr,yyvsp[0].nPtr); } - break; - - case 85: -#line 1378 "goomsl_yacc.y" - { yyval.nPtr = new_affec_list(yyvsp[0].nPtr,NULL); } - break; - - case 86: -#line 1380 "goomsl_yacc.y" - { - gsl_reenternamespace(yyvsp[-1].namespace); - yyval.nPtr = new_set(new_var(yyvsp[-3].strValue,currentGoomSL->num_lines),yyvsp[0].nPtr); - } - break; - - case 87: -#line 1384 "goomsl_yacc.y" - { - gsl_reenternamespace(yyvsp[-1].namespace); - yyval.nPtr = new_set(new_var("&this", currentGoomSL->num_lines),yyvsp[0].nPtr); - } - break; - - - } - -/* Line 999 of yacc.c. */ -#line 2792 "goomsl_yacc.c" - - yyvsp -= yylen; - yyssp -= yylen; - - - YY_STACK_PRINT (yyss, yyssp); - - *++yyvsp = yyval; - - - /* Now `shift' the result of the reduction. Determine what state - that goes to, based on the state we popped back to and the rule - number reduced by. */ - - yyn = yyr1[yyn]; - - yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; - if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) - yystate = yytable[yystate]; - else - yystate = yydefgoto[yyn - YYNTOKENS]; - - goto yynewstate; - - -/*------------------------------------. -| yyerrlab -- here on detecting error | -`------------------------------------*/ -yyerrlab: - /* If not already recovering from an error, report this error. */ - if (!yyerrstatus) - { - ++yynerrs; -#if YYERROR_VERBOSE - yyn = yypact[yystate]; - - if (YYPACT_NINF < yyn && yyn < YYLAST) - { - YYSIZE_T yysize = 0; - int yytype = YYTRANSLATE (yychar); - char *yymsg; - int yyx, yycount; - - yycount = 0; - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. */ - for (yyx = yyn < 0 ? -yyn : 0; - yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - yysize += yystrlen (yytname[yyx]) + 15, yycount++; - yysize += yystrlen ("syntax error, unexpected ") + 1; - yysize += yystrlen (yytname[yytype]); - yymsg = (char *) YYSTACK_ALLOC (yysize); - if (yymsg != 0) - { - char *yyp = yystpcpy (yymsg, "syntax error, unexpected "); - yyp = yystpcpy (yyp, yytname[yytype]); - - if (yycount < 5) - { - yycount = 0; - for (yyx = yyn < 0 ? -yyn : 0; - yyx < (int) (sizeof (yytname) / sizeof (char *)); - yyx++) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - { - const char *yyq = ! yycount ? ", expecting " : " or "; - yyp = yystpcpy (yyp, yyq); - yyp = yystpcpy (yyp, yytname[yyx]); - yycount++; - } - } - yyerror (yymsg); - YYSTACK_FREE (yymsg); - } - else - yyerror ("syntax error; also virtual memory exhausted"); - } - else -#endif /* YYERROR_VERBOSE */ - yyerror ("syntax error"); - } - - - - if (yyerrstatus == 3) - { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - /* Return failure if at end of input. */ - if (yychar == YYEOF) - { - /* Pop the error token. */ - YYPOPSTACK; - /* Pop the rest of the stack. */ - while (yyss < yyssp) - { - YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); - yydestruct (yystos[*yyssp], yyvsp); - YYPOPSTACK; - } - YYABORT; - } - - YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc); - yydestruct (yytoken, &yylval); - yychar = YYEMPTY; - - } - - /* Else will try to reuse lookahead token after shifting the error - token. */ - goto yyerrlab1; - - -/*----------------------------------------------------. -| yyerrlab1 -- error raised explicitly by an action. | -`----------------------------------------------------*/ -yyerrlab1: - yyerrstatus = 3; /* Each real token shifted decrements this. */ - - for (;;) - { - yyn = yypact[yystate]; - if (yyn != YYPACT_NINF) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; - } - } - - /* Pop the current state because it cannot handle the error token. */ - if (yyssp == yyss) - YYABORT; - - YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); - yydestruct (yystos[yystate], yyvsp); - yyvsp--; - yystate = *--yyssp; - - YY_STACK_PRINT (yyss, yyssp); - } - - if (yyn == YYFINAL) - YYACCEPT; - - YYDPRINTF ((stderr, "Shifting error token, ")); - - *++yyvsp = yylval; - - - yystate = yyn; - goto yynewstate; - - -/*-------------------------------------. -| yyacceptlab -- YYACCEPT comes here. | -`-------------------------------------*/ -yyacceptlab: - yyresult = 0; - goto yyreturn; - -/*-----------------------------------. -| yyabortlab -- YYABORT comes here. | -`-----------------------------------*/ -yyabortlab: - yyresult = 1; - goto yyreturn; - -#ifndef yyoverflow -/*----------------------------------------------. -| yyoverflowlab -- parser overflow comes here. | -`----------------------------------------------*/ -yyoverflowlab: - yyerror ("parser stack overflow"); - yyresult = 2; - /* Fall through. */ -#endif - -yyreturn: -#ifndef yyoverflow - if (yyss != yyssa) - YYSTACK_FREE (yyss); -#endif - return yyresult; -} - - -#line 1396 "goomsl_yacc.y" - - - -void yyerror(char *str) -{ /* {{{ */ - fprintf(stderr, "ERROR: Line %d, %s\n", currentGoomSL->num_lines, str); - currentGoomSL->compilationOK = 0; - exit(1); -} /* }}} */ - - diff --git a/src/post/goom/mmx.c b/src/post/goom/mmx.c index 3c9d0ee4a..953b59152 100644 --- a/src/post/goom/mmx.c +++ b/src/post/goom/mmx.c @@ -16,9 +16,11 @@ // faire : a / sqrtperte <=> a >> PERTEDEC #define PERTEDEC 4 +#ifdef CPU_X86 int mmx_supported (void) { return (mm_support()&0x1); } +#endif void zoom_filter_mmx (int prevX, int prevY, Pixel *expix1, Pixel *expix2, diff --git a/src/post/goom/mmx.h b/src/post/goom/mmx.h index 6861b7cfe..d422eac20 100644 --- a/src/post/goom/mmx.h +++ b/src/post/goom/mmx.h @@ -244,8 +244,10 @@ mmx_ok(void) return ( mm_support() & 0x1 ); } +#ifdef CPU_X86 int mmx_supported (void); int xmmx_supported (void); +#endif /* MMX optimized implementations */ diff --git a/src/post/goom/xmmx.c b/src/post/goom/xmmx.c index 6b76a86a3..2b9103a3e 100644 --- a/src/post/goom/xmmx.c +++ b/src/post/goom/xmmx.c @@ -23,6 +23,7 @@ /*#include "xmmx.h"*/ #include "goom_graphic.h" +#ifdef CPU_X86 int xmmx_supported (void) { #ifdef ARCH_X86_64 return 0; /* Haven't yet converted zoom_filter_xmmx @@ -31,6 +32,7 @@ int xmmx_supported (void) { return (mm_support()&0x8)>>3; #endif } +#endif void zoom_filter_xmmx (int prevX, int prevY, Pixel *expix1, Pixel *expix2, -- cgit v1.2.3 From d4422c12b810ff9af859ed141f064e137f6bf3be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Wed, 16 Jan 2008 20:28:21 +0100 Subject: Fix libdts vs dts to avoid building libdca. --- m4/decoders.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/m4/decoders.m4 b/m4/decoders.m4 index 0ab38af29..42f76b1a3 100644 --- a/m4/decoders.m4 +++ b/m4/decoders.m4 @@ -181,7 +181,7 @@ use internal ffmpeg. fi fi AM_CONDITIONAL([ENABLE_DTS], [test x"$enable_dts" != x"no"]) - AM_CONDITIONAL([WITH_EXTERNAL_LIBDTS], [test x"$have_external_libdts" = x"yes"]) + AM_CONDITIONAL([WITH_EXTERNAL_LIBDTS], [test x"$have_external_dts" = x"yes"]) dnl libFLAC (optional; disabled by default) -- cgit v1.2.3 From c13524a87fb997ef260d397a0e14d5649af323ef Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Thu, 17 Jan 2008 16:00:49 +0000 Subject: Update documentation to match filename-parsing changes in 1.1.9. [Bug 22] --- doc/faq/faq.sgml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/faq/faq.sgml b/doc/faq/faq.sgml index 9743cf361..77502d618 100644 --- a/doc/faq/faq.sgml +++ b/doc/faq/faq.sgml @@ -946,7 +946,7 @@ Latest xine-lib modules (1-beta3 or newer) support external subtitles for any media file, not only AVI. In order to use it you can pass a special MRL construction like: -    xine test.mpg#subtitle:file.sub +    xine file://path/to/test.mpg#subtitle:/path/to/file.sub The external subtitles support can also be used by any xine frontend. Currently xine-ui and kaffeine implement this feature with a subtitle selection dialog. -- cgit v1.2.3 From 4b30fc7d0ad482d4449703e9270df933cdd755ee Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Thu, 17 Jan 2008 16:13:23 +0000 Subject: Update the copyright info in the FAQ list. --- doc/faq/faq.sgml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/faq/faq.sgml b/doc/faq/faq.sgml index 77502d618..1176024e0 100644 --- a/doc/faq/faq.sgml +++ b/doc/faq/faq.sgml @@ -6,7 +6,7 @@ The xine engine FAQ xine FAQ - 2001-2003 + 2001-2008 the xine project team -- cgit v1.2.3 From 2b3df508106c0cf311132baeab89a2049fe22a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Thu, 17 Jan 2008 20:25:53 +0100 Subject: Remove SyncFB video output plugin, and related documentation and code. Matthias Dahl, the last maintainer of the code, confirms that the needed Linux kernel module is not building anymore, and thus this is unusable. Please consider using VIDIX or DirectFB instead, which should both work fine with Matrox cards. --- ChangeLog | 3 + doc/Makefile.am | 2 +- doc/README | 3 - doc/README.syncfb | 280 ---------- doc/faq/faq.docbook | 2 +- m4/summary.m4 | 3 - m4/video_out.m4 | 19 +- misc/xine-lib.spec.in | 39 -- po/POTFILES.in | 1 - src/video_out/Makefile.am | 10 +- src/video_out/video_out_syncfb.c | 1120 -------------------------------------- src/video_out/video_out_syncfb.h | 236 -------- src/xine-engine/configfile.c | 2 - 13 files changed, 7 insertions(+), 1713 deletions(-) delete mode 100644 doc/README.syncfb delete mode 100644 src/video_out/video_out_syncfb.c delete mode 100644 src/video_out/video_out_syncfb.h diff --git a/ChangeLog b/ChangeLog index aa626d700..1ea6c2484 100644 --- a/ChangeLog +++ b/ChangeLog @@ -52,6 +52,9 @@ xine-lib (1.1.90) (Unreleased) for specific input protocols. * Check for supported extensions before opening the plugin and remove redundant core from plugins. + * Remove SyncFB video output plugin, the kernel module needed is no more + active and thus it's no more usable. If you were using SyncFB somehow, + please use DirectFB or VIDIX instead. xine-lib (1.1.9.1) * Security fixes: diff --git a/doc/Makefile.am b/doc/Makefile.am index c456d8438..f5ba23474 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -4,7 +4,7 @@ SUBDIRS = man hackersguide faq doc_DATA = README README.dvb README.dxr3 \ README.freebsd README.irix README.network_dvd README.opengl \ - README.solaris README.syncfb README_xxmc.html README.MINGWCROSS \ + README.solaris README_xxmc.html README.MINGWCROSS \ README.WIN32 README.macosx EXTRA_DIST = $(doc_DATA) diff --git a/doc/README b/doc/README index 2674a0869..2c01dc5ce 100644 --- a/doc/README +++ b/doc/README @@ -40,6 +40,3 @@ README.opengl README.solaris hints on running xine on Solaris - -README.syncfb - information about xine's SyncFB video output plugin diff --git a/doc/README.syncfb b/doc/README.syncfb deleted file mode 100644 index fc90ff586..000000000 --- a/doc/README.syncfb +++ /dev/null @@ -1,280 +0,0 @@ - - ===== ===== - XINE video output plugin for MATROX G200/G400/G450 cards *only* - ===== ===== - - -* WHAT IS THIS PLUGIN ABOUT and WHY SHOULD I EVEN CONSIDER TO USE IT? :) - - This xine video output plugin uses the so called SyncFB driver (from - the Teletux project) which provides special hardware features of - Matrox G200 and newer cards like hardware deinterlacing, scaling and - synchronization of your video output to the vertical retrace of your - monitor - just to name a few. The plugin makes all those features - available to xine and because all this tasks are done by the graphic - card there is no need for xine to do them in software -- so you save - precious CPU time which you may gonna need for other things. :-) - - Ok ok -- why should you want to have your video output synchronized to - something called the vertical retrace of your monitor?! Well... :) - - In order to have an optimal DVD playback the update of the image needs - to be syncronized with the vertical refresh of the screen. Otherwise - you will sometimes see part of frame n and part of frame n+1 during - playback of a movie. Resulting in tearing artefacts on moving objects. - - When using this plugin the update of the screen is done during the - vertical retrace of your monitor and those tearing artefacts are gone - forever. - - Also the SyncFB kernel module and this plugin totally by-pass XFree86 - for anything else but some data gathering routines needed to place the - overlay at the right spot. So on some machines you will gain some - performance too because of the different way the SyncFB kernel module - handles your video output. - - Last but not least, you may ask what's so special about deinterlacing? - There are already several deinterlacing methods available in xine and - why should you care about another one? Well (again)... ;-)) - - All current deinterlacers in xine are done in software and therefore - will cost you some CPU power. The SyncFB video out plugin will use the - hardware deinterlacing support of your graphic card, thus saving your - CPU power because everything is done by your GPU... - - -* WILL IT WORK WITH MY G200/G400/G450/... CARD? - - So far the plugin and the kernel module itself are only being tested - on G400 cards by its developers thus we cannot tell about newer - or older generation chips. - - Nevertheless we have received positive feedback that the SyncFB kernel - module and this plugin work fine with G450 cards too. - - If you have got things working on older/newer chips, please let us - know about your success and we will place a note here... :-) - - -* AND HOW DOES IT WORK? - - The SyncFB driver is a kernel module you will have to load that makes - a special device (e.g. /dev/syncfb) available which is opened by the - plugin and controlled with certain ioctl calls. Easy, isn't it? ;-) - - That module is based on the mga_vid driver from Aaron Holzmann and was - advanced (and reworked) by Matthias Oelmann. - - -* OK I HEARD ENOUGH - HOW DO I INSTALL and USE IT? :) - - Currently the Teletux project which maintains the kernel module seems - orphaned and therefore there hasn't been any progress nor release in a - fair amount of time. :( We will try to resolve this situation so that - the development continues again. As soon as there are any news on this - matter, this README will be updated accordingly. For the time being - you can still use the current Teletux SyncFB kernel module which works - just fine, so there is no need to worry. :-) - - Back to the original subject. In order to install and use the SyncFB - kernel module, you *will* need a fresh CVS checkout of the sources - because the last official release is rather outdated. - - This sounds more complicated than it actually is. You will only have - to execute the following two commands to get the sources in a sub-dir - called teletux. When you are asked for password, just press return. - - cvs -d:pserver:anonymous@cvs.teletux.sf.net:/cvsroot/teletux login - cvs -d:pserver:anonymous@cvs.teletux.sf.net:/cvsroot/teletux co -P teletux - - Now enter the directory teletux/syncfb, that's where the actual kernel - modul sources are located. Before you can compile the module, you will - have to change two lines in the Makefile itself to make it work. - - In the second line, there is a phrase like "-I/usr/include" which you - have to change to "-I/usr/src/linux/include". In line seven, you need - to remove syncfbtv and syncfb_test from the OBJ list. - - Now execute a "make" and the module will be compiled. Place the - resulting syncfb.o in your modules dir which is usually... - - /lib/modules/KERNEL_VERSION/ - - ... and issue a "depmod -a" after it. That's it - the kernel module is - installed. To load the syncfb module, execute "modprobe syncfb" every - time you (re)start your computer. This will automatically create the - required /dev/syncfb device if you have devfs support, otherwise you - need to issue a "mknod /dev/syncfb c 178 0" once to create the - device yourself permanently. - - Once the module is loaded, you can start xine with the "-V SyncFB" - option to use this plugin. xine automatically remembers the video out - plugin you last used, so you only have to use this option once too. :) - But don't forget, the module *always* has to be already loaded before - you start xine, otherwise xine will fallback to Xv/XShm or some other - available video out plugin. - - -* THE VIDEO IS JERKING - WHAT'S THE MATTER?! - - Playing back video material that is mastered for e.g. NTSC can cause - this jerking if your monitor is not running at a refresh rate that is - a multiple of 30 (PAL: 25). - - You can try to fix that by switching your monitor to the appropriate - refresh rates (e.g. 50/75/100 Hz for PAL, 60/90/120 Hz for NTSC). You - will need to add so called modelines to your XFree86 config to make - those modes available, if you don't already have them. - - Here is is a short listing of some sample modelines. Please add only - those two lines (for NTSC and PAL) which exactly fit the screensize - you are running your X Server with. You need to add those lines to the - monitor section of your XF86Config file as well as include their names - in the screen section (subsection display of the color depth your are - using). - - USE THE FOLLOWING MODELINES AT YOUR OWN RISK. THEY COULD DAMAGE YOUR - MONITOR PERMANTELY - PLEASE TAKE CAUTION AND DON'T BLAME US. YOU HAVE - BEEN WARNED. - - So much for the standard disclaimer. :) - - Note: If you want to be on the safe side, generate your very own - modelines with an application like kvideogen for example. - - Also the modelines may need some fine tuning for your setup. You - can use xvidtune (comes with XFree86) to do that. - - # 1024x768 - - Modeline "1024x768pal" 64.94 1024 1040 1216 1328 768 768 775 802 - Modeline "1024x768ntsc" 54.32 1024 1040 1216 1328 768 768 774 802 - - # 1152x864 - - Modeline "1152x864pal" 68.82 1152 1168 1384 1496 864 864 871 902 - Modeline "1152x864ntsc" 80.93 1152 1168 1384 1496 864 864 872 902 - - # 1280x1024 - - none yet - might be added in the future - - So before you run xine just turn to the appropriate refresh rate and - the jerking *should* be gone. (you may also want to have a look at the - XF86VidMode support included in xine which makes on-the-fly resolution - switching possible when fullscreen is toggled) - - -* WHAT SCREENSIZE SHOULD I PREFER? - - Well. It is important that the screensize you choose for DVD playback - is exactly the same screensize you're starting up your X Server with - if you are not using the XF86VidMode extension which will properly do - the switching for you and take care that the plugin is updated - accordingly. So you shouldn't switch down to 1024x768 yourself if you - are running 1280x1024 because that gives you a virtual screensize - of 1280x1024 in a resolution of 1024x768 - and the plugin can't handle - that - and probably never will... ok... never say never. ;) - - You may want to have a look at the XF86VidMode support in xine which - will enable on-the-fly resolution switching when activating fullscreen. - - Now back to the question. A screensize of 800x600 should be it for - non-anamorphic DVDs because their resolution is 720x576 for pal DVDs - and 720x480 for ntsc ones. If you've an anamorphic DVD, you should use - a higher resolution - 1024x768 will be best because the image only has - to be horizontally scaled to get back to the original geometry of 16:9 - which is easier to be done. - - -* WHAT ABOUT DEINTERLACING?! - - Pressing 'i' during playback will toggle hardware deinterlacing. A - decrease in picture quality is a known side effect, yet you won't see - any artefacts caused by interlacing anymore. :-) - - One more note, hardware deinterlacing uses BOB as deinterlacing method - and is totally independent from the software deinterlacing in xine. So - specifing a different deinterlacing method in your .xinerc won't have - any effect on this feature. - - Nevertheless we are thinking about making software deinterlacing also - available as an option. It's on the TODO list... :) - - -* HEY! THE OVERLAY TURNS OFF WHEN THE WINDOW IS PARTLY OFF THE DESKTOP!? - - That's done on purpose. It prevents possible yet harmless screen - corruption. And by the way - why would you want to see a movie just - partly?! ;-) - - -* MY DESKTOP BACKGROUND IMAGE GETS CORRUPTED WHEN USING THIS PLUGIN! - - Even though it doesn't look nice, it's nevertheless harmless. So no - need to worry about it. XFree86 is using your free video memory as - cache for certain things. Now when you use this plugin that part of - your video memory could also be used by the syncfb module. So your - image data cached there will be corrupted. Unfortunately there is no - way to avoid it. Yet, like stated earlier, it is truely harmless and - just a cosmetical side effect. - - -* THE XINE PANEL DOES NOT APPEAR WHEN I WATCH A MOVIE IN FULLSCREEN?! - - Actually it does appear - you just don't see it. :) This is a side - effect of how SyncFB works. The X server can't display anything where - the actual overlay from SyncFB is being displayed because this area in - your video memory is constantly over written - so are the changes done - by your X Server (like a window graphic that is placed there). - - This is just cosmetical and harmless, so no need to worry. If you want - to do something with the xine panel when the video overlay is taking - all your screen, just switch back to window mode and do what you have - to do and after that, back to fullscreen it goes. :-) - - -* KNOWN BUGs - - + the default_repeat config option is currently hardcoded to 0 because - any higher value than 1 will trigger a bug with the SyncFB kernel module - that results in a distorted picture (depending on video resolution) - [this bug is hard to trace, so don't hold your breath for now] - - + SyncFB overlay won't turn off when video window is minimized or - somehow else hidden. - [currently there is no way for the SyncFB plugin to know about the - state of the video window except if the original xine-ui hide function - is used to hide the video window... this will be fixed soon] - - + zooming feature is currently deactivated because it exposes a bug - with the SyncFB kernel module - [for now, don't expect this to be fixed soon - sorry] - - + the syncfb kernel module needs updating pretty badly - - -* WHAT IS ON THE TODO LIST? - - + fix above listed bugs in the SyncFB kernel module - - + make software deinterlacing available as an option - - + RGB support - (unlikely at the moment because there is no need for it) - - + check if the video source is not too big in terms of dimensions for - the video memory left (video memory - X reserved video memory) - - + bug fixes - + more sanity checks - + new features - + optimizations - - -* CONTACTS and FEEDBACK - - Your first starting point should be this README followed by the FAQ. :-) - If you don't find your answers there or if you found a bug, please leave - a message on the xine user mailinglist (see the general README). - diff --git a/doc/faq/faq.docbook b/doc/faq/faq.docbook index fa414f1e9..57da1c5bd 100644 --- a/doc/faq/faq.docbook +++ b/doc/faq/faq.docbook @@ -1828,7 +1828,7 @@ Drivers that access hardware directly includes VIDIX (warning: requires - root priviledges or kernel helper) and SyncFB (requires kernel helper - Matrox only). + root priviledges or kernel helper). User may try one of those, but should be warned that with root access they can cause the system to crash hard. The support is also limited to a couple of graphics cards only. diff --git a/m4/summary.m4 b/m4/summary.m4 index a96e11e5a..9661f072b 100644 --- a/m4/summary.m4 +++ b/m4/summary.m4 @@ -179,9 +179,6 @@ AC_DEFUN([XINE_LIB_SUMMARY], [ echo " * video driver plugins:" if test x"$no_x" != x"yes"; then echo " - XShm (X11 shared memory)" - if test x"$have_syncfb" = x"yes"; then - echo " - SyncFB (for Matrox G200/G400 cards)" - fi if test x"$have_xv" = x"yes"; then if test x"$have_xv_static" = x"yes"; then echo " - Xv (XVideo *static*)" diff --git a/m4/video_out.m4 b/m4/video_out.m4 index 043d563e8..df782ff06 100644 --- a/m4/video_out.m4 +++ b/m4/video_out.m4 @@ -2,7 +2,7 @@ dnl ----------------- dnl Video out plugins dnl ----------------- AC_DEFUN([XINE_VIDEO_OUT_PLUGINS], [ - dnl Setup defaults for the target operating system. For example, syncfb is + dnl Setup defaults for the target operating system. For example, linuxfb is dnl only ever available on Linux, so don't bother checking for it unless dnl explicitly requested to do so on other operating systems. dnl Notes: @@ -11,7 +11,6 @@ AC_DEFUN([XINE_VIDEO_OUT_PLUGINS], [ dnl - dxr3 is Linux only dnl - Mac OS X video is Mac OS X only dnl - OpenGL requires Xwindows - dnl - SyncFB is Linux only, but disabled by default dnl - Vidix is FreeBSD and Linux only dnl - XvMC and xxmc depend on Xv @@ -24,7 +23,6 @@ AC_DEFUN([XINE_VIDEO_OUT_PLUGINS], [ default_enable_linuxfb=disable default_enable_macosx_video=disable default_enable_opengl=enable - default_enable_syncfb=disable default_enable_vidix=disable default_enable_xinerama=enable default_enable_xvmc=enable @@ -293,21 +291,6 @@ AC_DEFUN([XINE_VIDEO_OUT_PLUGINS], [ AM_CONDITIONAL([ENABLE_SUNFB], [test x"$have_sunfb" = x"yes"]) - dnl syncfb (Linux only) - AC_ARG_ENABLE([syncfb], - [AS_HELP_STRING([--enable-syncfb], [enable support for syncfb (Linux only)])], - [test x"$enableval" != x"no" && enable_syncfb="yes"], - [test $default_enable_syncfb = disable && enable_syncfb="no"]) - dnl There's no good test for this. If the user says so, then do it - if test x"$enable_syncfb" != x"no" && test x"$no_x" != x"yes"; then - have_syncfb=yes - fi - if test x"$enable_syncfb" = x"yes" && test x"$have_syncfb" != x"yes"; then - AC_MSG_ERROR([Linux syncfb support requested, but required X support is disabled]) - fi - AM_CONDITIONAL([ENABLE_SYNCFB], [test x"$have_syncfb" = x"yes"]) - - dnl xcb AC_ARG_WITH([xcb], [AS_HELP_STRING([--with-xcb], [Enable support for XCB video out plugins])], diff --git a/misc/xine-lib.spec.in b/misc/xine-lib.spec.in index 6c5d9b96c..30a54a114 100644 --- a/misc/xine-lib.spec.in +++ b/misc/xine-lib.spec.in @@ -51,9 +51,6 @@ %if %{?BUILD_DIRECTFB:0}%{!?BUILD_DIRECTFB:1} %define BUILD_DIRECTFB 0 %endif -%if %{?BUILD_SYNCFB:0}%{!?BUILD_SYNCFB:1} -%define BUILD_SYNCFB 0 -%endif %if %{?BUILD_W32DLL:0}%{!?BUILD_W32DLL:1} %define BUILD_W32DLL 0 %endif @@ -364,30 +361,6 @@ Videovýstupní modul libxine, který používá OpenGL (3D grafické karty). libxine Videoausgabeplugin per OpenGL (3D Grafikkarte) %endif -%if %BUILD_SYNCFB -%package syncfb -Summary: libxine video output plugin using synchroniced framebuffer (Matrox cards) -Summary(cs): Videovýstupní modul libxine používající framebuffer (karty Matrox) -Summary(de): libxine Videoausgabeplugin per synchronisiertem Framebuffer (Matrox Karten) -Summary(fi): libxine-Videolisdke Matrox-ndyttvkorttien synkronisoitua ndyttvmuistia varten. -Group: Development/Libraries -Obsoletes: libxine0-syncfb -Requires: %{libname} = %{version}-%{release} - -%description syncfb -libxine video output plugin using synchroniced framebuffer (Matrox cards) - -%description syncfb -l cs -Videovýstupní modul libxine, který používá synchronizovaný framebuffer (karty -Matrox). - -%description syncfb -l de -libxine Videoausgabeplugin per synchronisiertem Framebuffer (Matrox Karten) - -%description syncfb -l fi -libxine-Videolisdke Matrox-ndyttvkorttien synkronisoitua ndyttvmuistia varten. -%endif - %if %BUILD_DVD %package dvd Summary: libxine input plugin for playing video-dvd's with dvd-navigation @@ -762,14 +735,6 @@ grep -v -E "xineplug_vo_out_opengl\.|README.opengl" ${RPM_BUILD_DIR}/filelist_li rm ${RPM_BUILD_DIR}/filelist_libxine2_old %endif -%if %BUILD_SYNCFB -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_syncfb -mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old -grep -E "xineplug_vo_out_syncfb\.|README\.syncfb" ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine2_syncfb -grep -v -E "xineplug_vo_out_syncfb\.|README\.syncfb" ${RPM_BUILD_DIR}/filelist_libxine2_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine2 -rm ${RPM_BUILD_DIR}/filelist_libxine2_old -%endif - %if %BUILD_DIRECTFB echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine2_directfb mv ${RPM_BUILD_DIR}/filelist_libxine2 ${RPM_BUILD_DIR}/filelist_libxine2_old @@ -896,10 +861,6 @@ rm ${RPM_BUILD_DIR}/filelist_libxine2_old %files opengl -f ../filelist_libxine2_opengl %endif -%if %BUILD_SYNCFB -%files syncfb -f ../filelist_libxine2_syncfb -%endif - %if %BUILD_DIRECTFB %files directfb -f ../filelist_libxine2_directfb %endif diff --git a/po/POTFILES.in b/po/POTFILES.in index 6247b521d..b067431df 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -109,7 +109,6 @@ src/video_out/video_out_pgx32.c src/video_out/video_out_pgx64.c src/video_out/video_out_sdl.c src/video_out/video_out_stk.c -src/video_out/video_out_syncfb.c src/video_out/video_out_vidix.c src/video_out/video_out_xcbshm.c src/video_out/video_out_xcbxv.c diff --git a/src/video_out/Makefile.am b/src/video_out/Makefile.am index b7e24d088..3b5703792 100644 --- a/src/video_out/Makefile.am +++ b/src/video_out/Makefile.am @@ -12,7 +12,7 @@ endif EXTRA_DIST = video_out_directx.c video_out_macosx.m -noinst_HEADERS = video_out_syncfb.h yuv2rgb.h x11osd.h xcbosd.h +noinst_HEADERS = yuv2rgb.h x11osd.h xcbosd.h if HAVE_X11 X11OSD = x11osd.c @@ -29,9 +29,6 @@ endif if ENABLE_OPENGL opengl_module = xineplug_vo_out_opengl.la endif -if ENABLE_SYNCFB -syncfb_module = xineplug_vo_out_syncfb.la -endif if ENABLE_SUNFB if ENABLE_SUNDGA pgx64_module = xineplug_vo_out_pgx64.la @@ -93,7 +90,6 @@ endif xineplug_LTLIBRARIES = $(xshm_module) $(xv_module) $(xvmc_module) \ $(opengl_module) \ - $(syncfb_module) \ $(pgx64_module) $(pgx32_module)\ $(vidix_module) \ $(aa_module) \ @@ -140,10 +136,6 @@ xineplug_vo_out_opengl_la_LIBADD = $(MLIB_LIBS) $(OPENGL_LIBS) $(GLUT_LIBS) \ $(GLU_LIBS) $(X_LIBS) $(XINE_LIB) $(PTHREAD_LIBS) $(DYNAMIC_LD_LIBS) $(LTLIBINTL) xineplug_vo_out_opengl_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) $(MLIB_CFLAGS) -fno-strict-aliasing -xineplug_vo_out_syncfb_la_SOURCES = video_out_syncfb.c -xineplug_vo_out_syncfb_la_LIBADD = $(XINE_LIB) $(X_LIBS) $(PTHREAD_LIBS) $(LTLIBINTL) -xineplug_vo_out_syncfb_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) - xineplug_vo_out_pgx64_la_SOURCES = video_out_pgx64.c xineplug_vo_out_pgx64_la_LIBADD = $(XINE_LIB) $(X_LIBS) $(SUNDGA_LIBS) $(PTHREAD_LIBS) $(LTLIBINTL) xineplug_vo_out_pgx64_la_CFLAGS = $(AM_CFLAGS) $(X_CFLAGS) diff --git a/src/video_out/video_out_syncfb.c b/src/video_out/video_out_syncfb.c deleted file mode 100644 index 49c0d371a..000000000 --- a/src/video_out/video_out_syncfb.c +++ /dev/null @@ -1,1120 +0,0 @@ -/* - * Copyright (C) 2000-2003 the xine project - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * video_out_syncfb.c, SyncFB (for Matrox G200/G400 cards) interface for xine - * - * based on video_out_xv.c by (see file for original authors) - * - * with lot's of code from: - * video_out_syncfb.c by Joachim Koenig - * and by Matthias Oelmann - * video_out_mga by Aaron Holtzman - * - * glued together for xine by Matthias Dahl - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#ifdef __sun -#include -#endif - -#include -#if defined (__FreeBSD__) -#include -#endif -#include -#include -#include -#include - -#include -#include - -#include "video_out_syncfb.h" - -#include "xine.h" -#include -#include -#include -#include - -/*#define DEBUG_OUTPUT*/ - -typedef struct syncfb_driver_s syncfb_driver_t; - -typedef struct { - int value; - int min; - int max; -} syncfb_property_t; - -typedef struct { - vo_frame_t vo_frame; -/* uint8_t* data_mem[3];*/ - int width, height, format; - double ratio; -} syncfb_frame_t; - -struct syncfb_driver_s { - - vo_driver_t vo_driver; - - config_values_t *config; - - /* X11 related stuff */ - Display *display; - int screen; - Drawable drawable; - XVisualInfo vinfo; - GC gc; - XColor black; - - vo_scale_t sc; - - int virtual_screen_width; - int virtual_screen_height; - int screen_depth; - - syncfb_property_t props[VO_NUM_PROPERTIES]; - - syncfb_frame_t* cur_frame; - vo_overlay_t* overlay; - - /* syncfb module related stuff */ - int fd; /* file descriptor of the syncfb device */ - int yuv_format; /* either YUV420P3, YUV420P2 or YUV422 */ - int overlay_state; /* 0 = off, 1 = on */ - uint8_t* video_mem; /* mmapped video memory */ - int default_repeat; /* how many times a frame will be repeatedly displayed */ - uint32_t supported_capabilities; - - syncfb_config_t syncfb_config; - syncfb_capability_t capabilities; - syncfb_buffer_info_t bufinfo; - syncfb_param_t params; - - int video_win_visibility; - xine_t *xine; - - alphablend_t alphablend_extra_data; -}; - -typedef struct { - video_driver_class_t driver_class; - - config_values_t *config; - char *device_name; - xine_t *xine; -} syncfb_class_t; - -/* - * internal video_out_syncfb functions - */ - -/* returns boolean value (1 success, 0 failure) */ -static int syncfb_overlay_on(syncfb_driver_t* this) -{ - if(ioctl(this->fd, SYNCFB_ON)) { - xprintf(this->xine, XINE_VERBOSITY_DEBUG, - "video_out_syncfb: error. (on ioctl failed)\n"); - return 0; - } else { - this->overlay_state = 1; - return 1; - } -} - -/* returns boolean value (1 success, 0 failure) */ -static int syncfb_overlay_off(syncfb_driver_t* this) -{ - if(ioctl(this->fd, SYNCFB_OFF)) { - xprintf(this->xine, XINE_VERBOSITY_DEBUG, - "video_out_syncfb: error. (off ioctl failed)\n"); - return 0; - } else { - this->overlay_state = 0; - return 1; - } -} - -static void write_frame_YUV422(syncfb_driver_t* this, syncfb_frame_t* frame) -{ - uint8_t* y = (uint_8 *)frame->vo_frame.base[0]; - uint8_t* cb = (uint_8 *)frame->vo_frame.base[1]; - uint8_t* cr = (uint_8 *)frame->vo_frame.base[2]; - uint8_t* crp; - uint8_t* cbp; - uint32_t* dst32 = (uint32_t *)(this->video_mem + this->bufinfo.offset); - int h,w; - - for(h = 0; h < (frame->height / 2); h++) { - cbp = cb; - crp = cr; - - for(w = 0; w < (frame->width / 2); w++) { - *dst32++ = (*y) + ((*cb)<<8) + ((*(y+1))<<16) + ((*cr)<<24); - y++; y++; cb++; cr++; - } - - dst32 += (this->syncfb_config.src_pitch - frame->width) / 2; - - for(w=0; w < (frame->width / 2); w++) { - *dst32++ = (*y) + ((*cbp)<<8) + ((*(y+1))<<16) + ((*crp)<<24); - y++; y++; cbp++; crp++; - } - - dst32 += (this->syncfb_config.src_pitch - frame->width) / 2; - } -} - -static void write_frame_YUV420P2(syncfb_driver_t* this, syncfb_frame_t* frame) -{ - uint8_t* y = (uint8_t *)frame->vo_frame.base[0]; - uint8_t* cb = (uint8_t *)frame->vo_frame.base[1]; - uint8_t* cr = (uint8_t *)frame->vo_frame.base[2]; - uint8_t* dst8 = this->video_mem + this->bufinfo.offset_p2; - int h, w; - - register uint32_t* tmp32; - register uint8_t* rcr; - register uint8_t* rcb; - - rcr = cr; - rcb = cb; - - for(h = 0; h < (frame->height / 2); h++) { - tmp32 = (uint32_t *)dst8; - w = (frame->width / 8) * 2; - - while(w--) { - register uint32_t temp; - - temp = (*rcb) | (*rcr << 8); - rcr++; - rcb++; - temp |= (*rcb << 16) | (*rcr << 24); - rcr++; - rcb++; - *tmp32 = temp; - tmp32++; - } - - dst8 += this->syncfb_config.src_pitch; - } - - dst8 = this->video_mem + this->bufinfo.offset; - for(h = 0; h < frame->height; h++) { - xine_fast_memcpy(dst8, y, frame->width); - y += frame->width; - dst8 += this->syncfb_config.src_pitch; - } -} - -static void write_frame_YUV420P3(syncfb_driver_t* this, syncfb_frame_t* frame) -{ - uint8_t* y = (uint8_t *)frame->vo_frame.base[0]; - uint8_t* cb = (uint8_t *)frame->vo_frame.base[1]; - uint8_t* cr = (uint8_t *)frame->vo_frame.base[2]; - uint8_t* dst8 = this->video_mem + this->bufinfo.offset; - int h, half_width = (frame->width/2); - - for(h = 0; h < frame->height; h++) { - xine_fast_memcpy(dst8, y, frame->width); - y += frame->width; - dst8 += this->syncfb_config.src_pitch; - } - - dst8 = this->video_mem; - for(h = 0; h < (frame->height / 2); h++) { - xine_fast_memcpy((dst8 + this->bufinfo.offset_p2), cb, half_width); - xine_fast_memcpy((dst8 + this->bufinfo.offset_p3), cr, half_width); - - cb += half_width; - cr += half_width; - - dst8 += (this->syncfb_config.src_pitch / 2); - } -} - -static void write_frame_YUY2(syncfb_driver_t* this, syncfb_frame_t* frame) -{ - uint8_t* src8 = (uint8_t *)frame->vo_frame.base[0]; - uint8_t* dst8 = (uint8_t *)(this->video_mem + this->bufinfo.offset); - int h, double_width = (frame->width * 2); - - for(h = 0; h < frame->height; h++) { - xine_fast_memcpy(dst8, src8, double_width); - - dst8 += (this->syncfb_config.src_pitch * 2); - src8 += double_width; - } -} - -static void write_frame_sfb(syncfb_driver_t* this, syncfb_frame_t* frame) -{ - switch(frame->format) { - case XINE_IMGFMT_YUY2: - if(this->capabilities.palettes & (1<xine, XINE_VERBOSITY_LOG, - _("video_out_syncfb: error. (YUY2 not supported by your graphic card)\n")); - break; - - case XINE_IMGFMT_YV12: - switch(this->yuv_format) { - case VIDEO_PALETTE_YUV422: - write_frame_YUV422(this, frame); - break; - case VIDEO_PALETTE_YUV420P2: - write_frame_YUV420P2(this, frame); - break; - case VIDEO_PALETTE_YUV420P3: - write_frame_YUV420P3(this, frame); - break; - default: - xprintf(this->xine, XINE_VERBOSITY_LOG, - _("video_out_syncfb: error. (YV12 not supported by your graphic card)\n")); - } - break; - - default: - xprintf(this->xine, XINE_VERBOSITY_DEBUG, "video_out_syncfb: error. (unknown frame format)\n"); - break; - } - - frame->vo_frame.free(&frame->vo_frame); -} - -static void free_framedata(syncfb_frame_t* frame) -{ -/* if(frame->data_mem[0]) { - free(frame->data_mem[0]); - frame->data_mem[0] = NULL; - } - - if(frame->data_mem[1]) { - free(frame->data_mem[1]); - frame->data_mem[1] = NULL; - } - - if(frame->data_mem[2]) { - free(frame->data_mem[2]); - frame->data_mem[2] = NULL; - }*/ - - if(frame->vo_frame.base[0]) { - free(frame->vo_frame.base[0]); - frame->vo_frame.base[0] = NULL; - } - - if(frame->vo_frame.base[1]) { - free(frame->vo_frame.base[1]); - frame->vo_frame.base[1] = NULL; - } - - if(frame->vo_frame.base[2]) { - free(frame->vo_frame.base[2]); - frame->vo_frame.base[2] = NULL; - } -} - -static void syncfb_clean_output_area(syncfb_driver_t* this) -{ - XLockDisplay (this->display); - - XSetForeground (this->display, this->gc, this->black.pixel); - - XFillRectangle(this->display, this->drawable, this->gc, - this->sc.gui_x, this->sc.gui_y, this->sc.gui_width, this->sc.gui_height); - - XUnlockDisplay (this->display); -} - - -static void syncfb_compute_ideal_size (syncfb_driver_t *this) -{ - _x_vo_scale_compute_ideal_size( &this->sc ); -} - -/* make ideal width/height "fit" into the gui */ -static void syncfb_compute_output_size(syncfb_driver_t *this) -{ - _x_vo_scale_compute_output_size( &this->sc ); - -#ifdef DEBUG_OUTPUT - printf("video_out_syncfb: debug. (frame source %d x %d, screen output %d x %d)\n", - this->sc.delivered_width, this->sc.delivered_height, - this->sc.output_width, this->sc.output_height); -#endif - - /* - * configuring SyncFB module from this point on. - */ - syncfb_overlay_off(this); - - /* sanity checking - certain situations *may* crash the SyncFB module, so - * take care that we always have valid numbers. - */ - if(this->sc.output_xoffset >= 0 && this->sc.output_yoffset >= 0 && - this->cur_frame->width > 0 && this->cur_frame->height > 0 && - this->sc.output_width > 0 && this->sc.output_height > 0 && - this->cur_frame->format > 0 && this->video_win_visibility) { - - if(ioctl(this->fd, SYNCFB_GET_CONFIG, &this->syncfb_config)) - xprintf(this->xine, XINE_VERBOSITY_DEBUG, - "video_out_syncfb: error. (get_config ioctl failed)\n"); - - this->syncfb_config.syncfb_mode = SYNCFB_FEATURE_SCALE | SYNCFB_FEATURE_CROP; - - if(this->props[VO_PROP_INTERLACED].value) - this->syncfb_config.syncfb_mode |= SYNCFB_FEATURE_DEINTERLACE; - - switch(this->cur_frame->format) { - case XINE_IMGFMT_YV12: - this->syncfb_config.src_palette = this->yuv_format; - break; - case XINE_IMGFMT_YUY2: - this->syncfb_config.src_palette = VIDEO_PALETTE_YUV422; - break; - default: - xprintf(this->xine, XINE_VERBOSITY_DEBUG, - "video_out_syncfb: error. (unknown frame format)\n"); - this->syncfb_config.src_palette = 0; - break; - } - - this->syncfb_config.fb_screen_size = this->virtual_screen_width * this->virtual_screen_height * (this->screen_depth / 8) * 2; - this->syncfb_config.src_width = this->cur_frame->width; - this->syncfb_config.src_height = this->cur_frame->height; - - this->syncfb_config.image_width = this->sc.output_width; - this->syncfb_config.image_height = this->sc.output_height; - - this->syncfb_config.image_xorg = this->sc.output_xoffset + this->sc.gui_win_x; - this->syncfb_config.image_yorg = this->sc.output_yoffset + this->sc.gui_win_y; - - this->syncfb_config.src_crop_top = this->sc.displayed_yoffset; - this->syncfb_config.src_crop_bot = (this->props[VO_PROP_INTERLACED].value && this->sc.displayed_yoffset == 0) ? 1 : this->sc.displayed_yoffset; - this->syncfb_config.src_crop_left = this->sc.displayed_xoffset; - this->syncfb_config.src_crop_right = this->sc.displayed_xoffset; - - this->syncfb_config.default_repeat = (this->props[VO_PROP_INTERLACED].value) ? 1 : this->default_repeat; - - if(this->capabilities.palettes & (1<syncfb_config.src_palette)) { - if(ioctl(this->fd,SYNCFB_SET_CONFIG,&this->syncfb_config)) - xprintf(this->xine, XINE_VERBOSITY_DEBUG, "video_out_syncfb: error. (set_config ioctl failed)\n"); - - syncfb_overlay_on(this); - } - } -} - -/* - * public functions defined and used by the xine interface - */ - -static int syncfb_redraw_needed(vo_driver_t* this_gen) -{ - syncfb_driver_t* this = (syncfb_driver_t *) this_gen; - - int ret = 0; - - if( _x_vo_scale_redraw_needed( &this->sc ) ) { - - syncfb_compute_output_size (this); - - syncfb_clean_output_area (this); - - ret = 1; - } - - return ret; -} - -static uint32_t syncfb_get_capabilities (vo_driver_t *this_gen) -{ - syncfb_driver_t *this = (syncfb_driver_t *) this_gen; - - return this->supported_capabilities; -} - -static void syncfb_frame_field (vo_frame_t *vo_img, int which_field) -{ - /* not needed for SyncFB */ -} - -static void syncfb_frame_dispose(vo_frame_t* vo_img) -{ - syncfb_frame_t* frame = (syncfb_frame_t *) vo_img; - - if(frame) { - free_framedata(frame); - free(frame); - } -} - -static vo_frame_t* syncfb_alloc_frame(vo_driver_t* this_gen) -{ - /* syncfb_driver_t *this = (syncfb_driver_t *) this_gen; */ - syncfb_frame_t *frame; - - frame = (syncfb_frame_t *) xine_xmalloc(sizeof(syncfb_frame_t)); - if(!frame) - return NULL; - - pthread_mutex_init(&frame->vo_frame.mutex, NULL); - - frame->vo_frame.base[0] = NULL; - frame->vo_frame.base[1] = NULL; - frame->vo_frame.base[2] = NULL; - - /* - * supply required functions - */ - frame->vo_frame.proc_slice = NULL; - frame->vo_frame.proc_frame = NULL; - frame->vo_frame.field = syncfb_frame_field; - frame->vo_frame.dispose = syncfb_frame_dispose; - - frame->vo_frame.driver = this_gen; - - return (vo_frame_t *) frame; -} - -static void syncfb_update_frame_format(vo_driver_t* this_gen, - vo_frame_t* frame_gen, - uint32_t width, uint32_t height, - double ratio, int format, int flags) -{ - syncfb_driver_t *this = (syncfb_driver_t *) this_gen; - syncfb_frame_t *frame = (syncfb_frame_t *) frame_gen; - /* uint32_t frame_size = width*height; */ - - if((frame->width != width) - || (frame->height != height) - || (frame->format != format)) { - -#ifdef DEBUG_OUTPUT - printf("video_out_syncfb: debug. (update frame format: old values [width=%d, height=%d, format=%04x], new values [width=%d, height=%d, format=%04x])\n", frame->width, frame->height, frame->format, width, height, format); -#endif - free_framedata(frame); - - frame->width = width; - frame->height = height; - frame->format = format; - - switch(format) { - case XINE_IMGFMT_YV12: -/* frame->vo_frame.base[0] = xine_xmalloc_aligned(16, frame_size, (void **)&frame->data_mem[0]); - frame->vo_frame.base[1] = xine_xmalloc_aligned(16, frame_size/4, (void **)&frame->data_mem[1]); - frame->vo_frame.base[2] = xine_xmalloc_aligned(16, frame_size/4, (void **)&frame->data_mem[2]);*/ - frame->vo_frame.pitches[0] = 8*((width + 7) / 8); - frame->vo_frame.pitches[1] = 8*((width + 15) / 16); - frame->vo_frame.pitches[2] = 8*((width + 15) / 16); - frame->vo_frame.base[0] = malloc(frame->vo_frame.pitches[0] * height); - frame->vo_frame.base[1] = malloc(frame->vo_frame.pitches[1] * ((height+1)/2)); - frame->vo_frame.base[2] = malloc(frame->vo_frame.pitches[2] * ((height+1)/2)); - break; - case XINE_IMGFMT_YUY2: -/* frame->vo_frame.base[0] = xine_xmalloc_aligned(16, (frame_size*2), (void **)&frame->data_mem[0]);*/ - frame->vo_frame.pitches[0] = 8*((width + 3) / 4); - frame->vo_frame.base[0] = malloc(frame->vo_frame.pitches[0] * height); - frame->vo_frame.base[1] = NULL; - frame->vo_frame.base[2] = NULL; - break; - default: - xprintf(this->xine, XINE_VERBOSITY_DEBUG, - "video_out_syncfb: error. (unable to allocate " - "framedata because of unknown frame format: %04x)\n", format); - } - -/* if((format == IMGFMT_YV12 && (frame->data_mem[0] == NULL || frame->data_mem[1] == NULL || frame->data_mem[2] == NULL)) - || (format == IMGFMT_YUY2 && frame->data_mem[0] == NULL)) {*/ - if((format == XINE_IMGFMT_YV12 && (frame->vo_frame.base[0] == NULL || frame->vo_frame.base[1] == NULL || frame->vo_frame.base[2] == NULL)) - || (format == XINE_IMGFMT_YUY2 && frame->vo_frame.base[0] == NULL)) { - xprintf(this->xine, XINE_VERBOSITY_DEBUG, - "video_out_syncfb: error. (framedata allocation failed: out of memory)\n"); - - free_framedata(frame); - } - } - - frame->ratio = ratio; -} - -static void syncfb_overlay_blend(vo_driver_t* this_gen, vo_frame_t* frame_gen, vo_overlay_t* overlay) -{ - syncfb_frame_t* frame = (syncfb_frame_t *) frame_gen; - syncfb_driver_t* this = (syncfb_driver_t *) this_gen; - - this->alphablend_extra_data.offset_x = frame_gen->overlay_offset_x; - this->alphablend_extra_data.offset_y = frame_gen->overlay_offset_y; - - /* alpha blend here */ - if (overlay->rle) { - if (frame->format == XINE_IMGFMT_YV12) - _x_blend_yuv(frame->vo_frame.base, overlay, frame->width, frame->height, frame->vo_frame.pitches, &this->alphablend_extra_data); - else - _x_blend_yuy2(frame->vo_frame.base[0], overlay, frame->width, frame->height, frame->vo_frame.pitches[0], &this->alphablend_extra_data); - } -} - -static void syncfb_display_frame(vo_driver_t* this_gen, vo_frame_t* frame_gen) -{ - syncfb_driver_t* this = (syncfb_driver_t *) this_gen; - syncfb_frame_t* frame = (syncfb_frame_t *) frame_gen; - - this->cur_frame = frame; - - /* - * let's see if this frame is different in size / aspect - * ratio from the previous one - */ - if((frame->width != this->sc.delivered_width) - || (frame->height != this->sc.delivered_height) - || (frame->ratio != this->sc.delivered_ratio)) { -#ifdef DEBUG_OUTPUT - printf("video_out_syncfb: debug. (frame format changed)\n"); -#endif - - this->sc.delivered_width = frame->width; - this->sc.delivered_height = frame->height; - this->sc.delivered_ratio = frame->ratio; - - this->sc.crop_left = frame->vo_frame.crop_left; - this->sc.crop_right = frame->vo_frame.crop_right; - this->sc.crop_top = frame->vo_frame.crop_top; - this->sc.crop_bottom = frame->vo_frame.crop_bottom; - - syncfb_compute_ideal_size(this); - - this->sc.force_redraw = 1; - } - - /* - * tell gui that we are about to display a frame, - * ask for offset and output size - */ - syncfb_redraw_needed(this_gen); - - /* the rest is only successful and safe, if the overlay is really on */ - if(this->overlay_state) { - if(this->bufinfo.id != -1) { - xprintf(this->xine, XINE_VERBOSITY_DEBUG, - "video_out_syncfb: error. (invalid syncfb image buffer state)\n"); - frame->vo_frame.free(&frame->vo_frame); - - return; - } - - if(ioctl(this->fd, SYNCFB_REQUEST_BUFFER, &this->bufinfo)) - xprintf(this->xine, XINE_VERBOSITY_DEBUG, "video_out_syncfb: error. (request ioctl failed)\n"); - - if(this->bufinfo.id == -1) { - xprintf(this->xine, XINE_VERBOSITY_DEBUG, - "video_out_syncfb: error. (syncfb module couldn't allocate image buffer)\n"); - frame->vo_frame.free(&frame->vo_frame); - - /* - * there are several "fixable" situations when this request will fail. - * for example when the screen resolution changes, the kernel module - * will get confused - reinitializing everything will fix things for - * the next frame in that case. - */ - syncfb_compute_ideal_size(this); - syncfb_compute_output_size(this); - syncfb_clean_output_area(this); - - return; - } - - write_frame_sfb(this, frame); - - if(ioctl(this->fd, SYNCFB_COMMIT_BUFFER, &this->bufinfo)) - xprintf(this->xine, XINE_VERBOSITY_DEBUG, "video_out_syncfb: error. (commit ioctl failed)\n"); - } - else - frame->vo_frame.free(&frame->vo_frame); - - this->bufinfo.id = -1; -} - -static int syncfb_get_property(vo_driver_t* this_gen, int property) -{ - syncfb_driver_t* this = (syncfb_driver_t *) this_gen; - - switch (property) { - case VO_PROP_WINDOW_WIDTH: - this->props[property].value = this->sc.gui_width; - break; - case VO_PROP_WINDOW_HEIGHT: - this->props[property].value = this->sc.gui_height; - break; - case VO_PROP_OUTPUT_WIDTH: - this->props[property].value = this->sc.output_width; - break; - case VO_PROP_OUTPUT_HEIGHT: - this->props[property].value = this->sc.output_height; - break; - case VO_PROP_OUTPUT_XOFFSET: - this->props[property].value = this->sc.output_xoffset; - break; - case VO_PROP_OUTPUT_YOFFSET: - this->props[property].value = this->sc.output_yoffset; - break; - } - - return this->props[property].value; -} - -static int syncfb_set_property(vo_driver_t* this_gen, int property, int value) -{ - syncfb_driver_t* this = (syncfb_driver_t *) this_gen; - - switch (property) { - case VO_PROP_INTERLACED: - this->props[property].value = value; - -#ifdef DEBUG_OUTPUT - printf("video_out_syncfb: debug. (VO_PROP_INTERLACED(%d))\n", - this->props[property].value); -#endif - - syncfb_compute_ideal_size(this); - syncfb_compute_output_size(this); - syncfb_clean_output_area(this); - break; - - case VO_PROP_ASPECT_RATIO: - if(value >= XINE_VO_ASPECT_NUM_RATIOS) - value = XINE_VO_ASPECT_AUTO; - - this->props[property].value = value; - this->sc.user_ratio = value; - -#ifdef DEBUG_OUTPUT - printf("video_out_syncfb: debug. (VO_PROP_ASPECT_RATIO(%d))\n", - this->props[property].value); -#endif - - syncfb_compute_ideal_size(this); - syncfb_compute_output_size(this); - syncfb_clean_output_area(this); - break; - - case VO_PROP_ZOOM_X: - if ((value >= XINE_VO_ZOOM_MIN) && (value <= XINE_VO_ZOOM_MAX)) { - this->props[property].value = value; - this->sc.zoom_factor_x = (double)value / (double)XINE_VO_ZOOM_STEP; - - syncfb_compute_ideal_size (this); - - this->sc.force_redraw = 1; - } -/* - printf("video_out_syncfb: info. (the zooming feature is not supported at the moment because of a bug with the SyncFB kernel driver, please refer to README.syncfb)\n"); -*/ - break; - - case VO_PROP_ZOOM_Y: - if ((value >= XINE_VO_ZOOM_MIN) && (value <= XINE_VO_ZOOM_MAX)) { - this->props[property].value = value; - this->sc.zoom_factor_y = (double)value / (double)XINE_VO_ZOOM_STEP; - - syncfb_compute_ideal_size (this); - - this->sc.force_redraw = 1; - } -/* - printf("video_out_syncfb: info. (the zooming feature is not supported at the moment because of a bug with the SyncFB kernel driver, please refer to README.syncfb)\n"); -*/ - break; - - case VO_PROP_CONTRAST: - this->props[property].value = value; - -#ifdef DEBUG_OUTPUT - printf("video_out_syncfb: debug. (VO_PROP_CONTRAST(%d))\n", - this->props[property].value); -#endif - - this->params.contrast = value; - this->params.brightness = this->props[VO_PROP_BRIGHTNESS].value; - this->params.image_width = this->syncfb_config.image_width; /* FIXME */ - this->params.image_height = this->syncfb_config.image_height; - this->params.image_xorg = this->syncfb_config.image_xorg; - this->params.image_yorg = this->syncfb_config.image_yorg; - - if(ioctl(this->fd,SYNCFB_SET_PARAMS,&this->params)) - xprintf(this->xine, XINE_VERBOSITY_DEBUG, - "video_out_syncfb: error. (setting of contrast value failed)\n"); - - break; - - case VO_PROP_BRIGHTNESS: - this->props[property].value = value; - -#ifdef DEBUG_OUTPUT - printf("video_out_syncfb: debug. (VO_PROP_BRIGHTNESS(%d))\n", - this->props[property].value); -#endif - - this->params.brightness = value; - this->params.contrast = this->props[VO_PROP_CONTRAST].value; - this->params.image_width = this->syncfb_config.image_width; /* FIXME */ - this->params.image_height = this->syncfb_config.image_height; - this->params.image_xorg = this->syncfb_config.image_xorg; - this->params.image_yorg = this->syncfb_config.image_yorg; - - if(ioctl(this->fd,SYNCFB_SET_PARAMS,&this->params)) - xprintf(this->xine, XINE_VERBOSITY_DEBUG, - "video_out_syncfb: error. (setting of brightness value failed)\n"); - - break; - } - - return value; -} - -static void syncfb_get_property_min_max(vo_driver_t *this_gen, - int property, int *min, int *max) -{ - syncfb_driver_t* this = (syncfb_driver_t *) this_gen; - - *min = this->props[property].min; - *max = this->props[property].max; -} - -static int syncfb_gui_data_exchange(vo_driver_t* this_gen, int data_type, - void *data) -{ - syncfb_driver_t* this = (syncfb_driver_t *) this_gen; - - switch (data_type) { - case XINE_GUI_SEND_DRAWABLE_CHANGED: - this->drawable = (Drawable) data; - - XLockDisplay (this->display); - XFreeGC(this->display, this->gc); - this->gc = XCreateGC (this->display, this->drawable, 0, NULL); - XUnlockDisplay (this->display); - break; - case XINE_GUI_SEND_TRANSLATE_GUI_TO_VIDEO: - { - int x1, y1, x2, y2; - x11_rectangle_t *rect = data; - - _x_vo_scale_translate_gui2video(&this->sc, rect->x, rect->y, - &x1, &y1); - _x_vo_scale_translate_gui2video(&this->sc, rect->x + rect->w, rect->y + rect->h, - &x2, &y2); - rect->x = x1; - rect->y = y1; - rect->w = x2-x1; - rect->h = y2-y1; - } - break; - /* - case XINE_GUI_DATA_EX_VIDEOWIN_VISIBLE: - this->video_win_visibility = (int)(int *)data; - syncfb_compute_output_size(this); - break; - */ - - default: - return -1; - } - - return 0; -} - -static void syncfb_dispose(vo_driver_t *this_gen) -{ - syncfb_driver_t *this = (syncfb_driver_t *) this_gen; - - /* get it off the screen - I wanna see my desktop again :-) */ - syncfb_overlay_off(this); - - /* don't know if it is necessary are even right, but anyway...?! */ - munmap(0, this->capabilities.memory_size); - - close(this->fd); - - XLockDisplay (this->display); - XFreeGC(this->display, this->gc); - XUnlockDisplay (this->display); - - _x_alphablend_free(&this->alphablend_extra_data); - - free(this); -} - -static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *visual_gen) { - - syncfb_class_t *class = (syncfb_class_t *) class_gen; - config_values_t *config = class->config; - syncfb_driver_t* this; - Display* display = NULL; - unsigned int i; - x11_visual_t* visual = (x11_visual_t *) visual_gen; - XColor dummy; - XWindowAttributes attr; - - display = visual->display; - - if(!(this = xine_xmalloc(sizeof (syncfb_driver_t)))) - return NULL; - - _x_alphablend_init(&this->alphablend_extra_data, class->xine); - - /* check for syncfb device */ - if((this->fd = open(class->device_name, O_RDWR)) < 0) { - xprintf(class->xine, XINE_VERBOSITY_DEBUG, - "video_out_syncfb: aborting. (unable to open syncfb device \"%s\")\n", class->device_name); - free(this); - return NULL; - } - - this->xine = class->xine; - - /* get capabilities from the syncfb module */ - if(ioctl(this->fd, SYNCFB_GET_CAPS, &this->capabilities)) { - xprintf(this->xine, XINE_VERBOSITY_DEBUG, - "video_out_syncfb: aborting. (syncfb_get_caps ioctl failed)\n"); - - close(this->fd); - free(this); - - return NULL; - } - - /* mmap whole video memory */ - this->video_mem = (uint8_t *) mmap(0, this->capabilities.memory_size, PROT_WRITE, MAP_SHARED, this->fd, 0); - - if(this->video_mem == MAP_FAILED) { - xprintf(this->xine, XINE_VERBOSITY_DEBUG, - "video_out_syncfb: aborting. (mmap of video memory failed)\n"); - - close(this->fd); - free(this); - - return NULL; - } - - /* - * init properties and capabilities - */ - for (i = 0; iprops[i].value = 0; - this->props[i].min = 0; - this->props[i].max = 0; - } - - this->props[VO_PROP_INTERLACED].value = 0; - this->sc.user_ratio = this->props[VO_PROP_ASPECT_RATIO].value = XINE_VO_ASPECT_AUTO; - this->props[VO_PROP_ZOOM_X].value = 100; - this->props[VO_PROP_ZOOM_Y].value = 100; - - /* check for formats we need... */ - this->supported_capabilities = VO_CAP_CROP; - this->yuv_format = 0; - - /* - * simple fallback mechanism - we want YUV 4:2:0 (3 plane) but we can also - * convert YV12 material to YUV 4:2:0 (2 plane) and YUV 4:2:2 ... - */ - if(this->capabilities.palettes & (1<supported_capabilities |= VO_CAP_YV12; - this->yuv_format = VIDEO_PALETTE_YUV420P3; - xprintf(this->xine, XINE_VERBOSITY_LOG, - _("video_out_syncfb: info. (SyncFB module supports YUV 4:2:0 (3 plane))\n")); - } else if(this->capabilities.palettes & (1<supported_capabilities |= VO_CAP_YV12; - this->yuv_format = VIDEO_PALETTE_YUV420P2; - xprintf(this->xine, XINE_VERBOSITY_LOG, - _("video_out_syncfb: info. (SyncFB module supports YUV 4:2:0 (2 plane))\n")); - } else if(this->capabilities.palettes & (1<supported_capabilities |= VO_CAP_YV12; - this->yuv_format = VIDEO_PALETTE_YUV422; - xprintf(this->xine, XINE_VERBOSITY_DEBUG, - _("video_out_syncfb: info. (SyncFB module supports YUV 4:2:2)\n")); - } - - if(this->capabilities.palettes & (1<supported_capabilities |= VO_CAP_YUY2; - xprintf(this->xine, XINE_VERBOSITY_DEBUG, - _("video_out_syncfb: info. (SyncFB module supports YUY2)\n")); - } - if(this->capabilities.palettes & (1<supported_capabilities |= VO_CAP_RGB; - */ - xprintf(this->xine, XINE_VERBOSITY_DEBUG, - _("video_out_syncfb: info. (SyncFB module supports RGB565)\n")); - } - - if(!this->supported_capabilities) { - xprintf(this->xine, XINE_VERBOSITY_DEBUG, - _("video_out_syncfb: aborting. (SyncFB module does not support YV12, YUY2 nor RGB565)\n")); - - munmap(0, this->capabilities.memory_size); - close(this->fd); - free(this); - - return NULL; - } - - if(ioctl(this->fd,SYNCFB_GET_PARAMS,&this->params) == 0) { - this->props[VO_PROP_CONTRAST].value = this->params.contrast; - this->props[VO_PROP_CONTRAST].min = 0; - this->props[VO_PROP_CONTRAST].max = 255; - - this->props[VO_PROP_BRIGHTNESS].value = this->params.brightness; - this->props[VO_PROP_BRIGHTNESS].min = -128; - this->props[VO_PROP_BRIGHTNESS].max = 127; - } else { - xprintf(this->xine, XINE_VERBOSITY_LOG, - _("video_out_syncfb: info. (brightness/contrast control won\'t be available because " - "your SyncFB kernel module seems to be outdated. Please refer to README." - "syncfb for informations on how to update it.)\n")); - } - - /* check for virtual screen size and screen depth - this is rather important - because that data is later used for free memory calculation */ - XGetWindowAttributes(visual->display, DefaultRootWindow(visual->display), &attr); - - this->virtual_screen_height = attr.height; - this->virtual_screen_width = attr.width; - this->screen_depth = attr.depth; - - /* initialize the rest of the variables now with default values */ - this->bufinfo.id = -1; - this->config = config; - this->cur_frame = NULL; - - /* FIXME: setting the default_repeat to anything higher than 1 will result - in a distorted video, so for now, set this manually to 0 until - the kernel driver is fixed... */ -#if 0 - this->default_repeat = config->register_range(config, - "video.device.syncfb_default_repeat", 3, 1, 4, - _("default number of frame repetitions"), - _("This specifies how many times a single video " - "frame will be displayed consecutively."), - 10, NULL, NULL); -#endif - this->default_repeat = 0; - - this->display = visual->display; - this->drawable = visual->d; - this->gc = XCreateGC (this->display, this->drawable, 0, NULL); - - _x_vo_scale_init (&this->sc, 1, 0, config ); - this->sc.frame_output_cb = visual->frame_output_cb; - this->sc.user_data = visual->user_data; - - this->overlay = NULL; - this->screen = visual->screen; - this->video_win_visibility = 1; - - XAllocNamedColor(this->display, - DefaultColormap(this->display, this->screen), - "black", &this->black, &dummy); - - this->vo_driver.get_capabilities = syncfb_get_capabilities; - this->vo_driver.alloc_frame = syncfb_alloc_frame; - this->vo_driver.update_frame_format = syncfb_update_frame_format; - this->vo_driver.overlay_begin = NULL; /* not used */ - this->vo_driver.overlay_blend = syncfb_overlay_blend; - this->vo_driver.overlay_end = NULL; /* not used */ - this->vo_driver.display_frame = syncfb_display_frame; - this->vo_driver.get_property = syncfb_get_property; - this->vo_driver.set_property = syncfb_set_property; - this->vo_driver.get_property_min_max = syncfb_get_property_min_max; - this->vo_driver.gui_data_exchange = syncfb_gui_data_exchange; - this->vo_driver.dispose = syncfb_dispose; - this->vo_driver.redraw_needed = syncfb_redraw_needed; - - return &this->vo_driver; -} - -/* - * class functions - */ -static void *init_class (xine_t *xine, void *visual_gen) { - - syncfb_class_t *this; - char* device_name; - int fd; - - device_name = xine->config->register_filename(xine->config, "video.device.syncfb_device", "/dev/syncfb", - XINE_CONFIG_STRING_IS_DEVICE_NAME, - _("SyncFB device name"), - _("Specifies the file name for the SyncFB (TeleTux) device " - "to be used.\nThis setting is security critical, " - "because when changed to a different file, xine " - "can be used to fill this file with arbitrary content. " - "So you should be careful that the value you enter " - "really is a proper framebuffer device."), - XINE_CONFIG_SECURITY, NULL, NULL); - - /* check for syncfb device */ - if((fd = open(device_name, O_RDWR)) < 0) { - xprintf(xine, XINE_VERBOSITY_DEBUG, - "video_out_syncfb: aborting. (unable to open syncfb device \"%s\")\n", device_name); - return NULL; - } - close(fd); - - /* - * from this point on, nothing should go wrong anymore - */ - this = (syncfb_class_t *) xine_xmalloc (sizeof (syncfb_class_t)); - - this->driver_class.open_plugin = open_plugin; - this->driver_class.identifier = "SyncFB"; - this->driver_class.description = N_("xine video output plugin using the SyncFB module for Matrox G200/G400 cards"); - this->driver_class.dispose = default_video_driver_class_dispose; - - this->config = xine->config; - this->xine = xine; - this->device_name = device_name; - - return this; -} - -static const vo_info_t vo_info_syncfb = { - 7, /* priority */ - XINE_VISUAL_TYPE_X11 /* visual type */ -}; - -/* - * exported plugin catalog entry - */ - -const plugin_info_t xine_plugin_info[] EXPORTED = { - /* type, API, "name", version, special_info, init_function */ - { PLUGIN_VIDEO_OUT, 22, "SyncFB", XINE_VERSION_CODE, &vo_info_syncfb, init_class }, - { PLUGIN_NONE, 0, "", 0, NULL, NULL } -}; - diff --git a/src/video_out/video_out_syncfb.h b/src/video_out/video_out_syncfb.h deleted file mode 100644 index 1fc3df83a..000000000 --- a/src/video_out/video_out_syncfb.h +++ /dev/null @@ -1,236 +0,0 @@ -#ifndef __LINUX_SYNCFB_H -#define __LINUX_SYNCFB_H - -#ifdef __KERNEL__ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#define TRUE 1 -#define FALSE 0 - -#define SFB_STATUS_FREE 0 -#define SFB_STATUS_OFFS 1 -#define SFB_STATUS_WAIT 2 -#define SFB_STATUS_LIVE 3 - -#endif /* KERNEL */ - - -#ifndef AARONS_TYPES -typedef unsigned long uint_32; -typedef unsigned char uint_8; -#endif - -#define SYNCFB_MAJOR 178 - -#define SYNCFB_ERROR_NO_ERROR 0; -#define SYNCFB_ERROR_NO_BUFFER_AVAILABLE 1; -#define SYNCFB_ERROR_PALETTE_NOT_SUPPORTED 2; -#define SYNCFB_ERROR_NOT_ENOUGH_MEMORY 3; - - - -#ifndef __LINUX_VIDEODEV_H -#define VIDEO_PALETTE_GREY 1 /* Linear greyscale */ -#define VIDEO_PALETTE_HI240 2 /* High 240 cube (BT848) */ -#define VIDEO_PALETTE_RGB565 3 /* 565 16 bit RGB */ -#define VIDEO_PALETTE_RGB24 4 /* 24bit RGB */ -#define VIDEO_PALETTE_RGB32 5 /* 32bit RGB */ -#define VIDEO_PALETTE_RGB555 6 /* 555 15bit RGB */ -#define VIDEO_PALETTE_YUV422 7 /* YUV422 capture */ -#define VIDEO_PALETTE_YUYV 8 -#define VIDEO_PALETTE_UYVY 9 /* The great thing about standards is ... */ -#define VIDEO_PALETTE_YUV420 10 -#define VIDEO_PALETTE_YUV411 11 /* YUV411 capture */ -#define VIDEO_PALETTE_RAW 12 /* RAW capture (BT848) */ -#define VIDEO_PALETTE_YUV422P 13 /* YUV 4:2:2 Planar */ -#define VIDEO_PALETTE_YUV411P 14 /* YUV 4:1:1 Planar */ -#define VIDEO_PALETTE_YUV420P 15 /* YUV 4:2:0 Planar */ -#define VIDEO_PALETTE_YUV410P 16 /* YUV 4:1:0 Planar */ -#define VIDEO_PALETTE_PLANAR 13 /* start of planar entries */ -#define VIDEO_PALETTE_COMPONENT 7 /* start of component entries */ -#endif - - -#define VIDEO_PALETTE_YUV422P3 13 /* YUV 4:2:2 Planar (3 Plane, same as YUV422P) */ -#define VIDEO_PALETTE_YUV422P2 17 /* YUV 4:2:2 Planar (2 Plane) */ - -#define VIDEO_PALETTE_YUV411P3 14 /* YUV 4:1:1 Planar (3 Plane, same as YUV411P) */ -#define VIDEO_PALETTE_YUV411P2 18 /* YUV 4:1:1 Planar (2 Plane) */ - -#define VIDEO_PALETTE_YUV420P3 15 /* YUV 4:2:0 Planar (3 Plane, same as YUV420P) */ -#define VIDEO_PALETTE_YUV420P2 19 /* YUV 4:2:0 Planar (2 Plane) */ - -#define VIDEO_PALETTE_YUV410P3 16 /* YUV 4:1:0 Planar (3 Plane, same as YUV410P) */ -#define VIDEO_PALETTE_YUV410P2 20 /* YUV 4:1:0 Planar (2 Plane) */ - - - -#define SYNCFB_FEATURE_SCALE_H 1 -#define SYNCFB_FEATURE_SCALE_V 2 -#define SYNCFB_FEATURE_SCALE 3 -#define SYNCFB_FEATURE_CROP 4 -#define SYNCFB_FEATURE_OFFSET 8 -#define SYNCFB_FEATURE_DEINTERLACE 16 -#define SYNCFB_FEATURE_PROCAMP 32 -#define SYNCFB_FEATURE_TRANSITIONS 64 -#define SYNCFB_FEATURE_COLKEY 128 -#define SYNCFB_FEATURE_MIRROR_H 256 -#define SYNCFB_FEATURE_MIRROR_V 512 -#define SYNCFB_FEATURE_BLOCK_REQUEST 1024 -#define SYNCFB_FEATURE_FREQDIV2 2048 - - -typedef struct syncfb_config_s -{ - uint_32 syncfb_mode; /* bitfield: turn on/off the available features */ - uint_32 error_code; /* RO: returns 0 on successful config calls, error code otherwise */ - - uint_32 fb_screen_size; /* WO, size in bytes of video memory reserved for fbdev */ - uint_32 fb_screen_width; /* WO, visible screen width in pixel */ - uint_32 fb_screen_height; /* WO, visible screen height in pixel */ - - uint_32 buffers; /* RO, number of available buffers */ - uint_32 buffer_size; /* RO, filled in by syncfb */ - - uint_32 default_repeat; /* default repeat time for a single frame, can be overridden in syncfb_buffer_info_t */ - - uint_32 src_width; /* source image width in pixel */ - uint_32 src_height; /* source image height in pixel */ - uint_32 src_palette; /* set palette mode, see videodev.h for palettes */ - uint_32 src_pitch; /* RO: filled in by ioctl: actual line length in pixel */ - - uint_32 image_xorg; /* x position of the image on the screen */ - uint_32 image_yorg; /* y position of the image on the screen */ - - /* if syncfb has FEATURE_SCALE */ - uint_32 scale_filters; /* 0: no filtering, 255: all filters on */ - uint_32 image_width; /* onscreen image width */ - uint_32 image_height; /* onscreen image height */ - - /* if syncfb has FEATURE_CROP */ - uint_32 src_crop_left; /* */ - uint_32 src_crop_right; /* */ - uint_32 src_crop_top; /* */ - uint_32 src_crop_bot; /* */ - - /* if syncfb has FEATURE_OFFSET */ - uint_32 image_offset_left; /* */ - uint_32 image_offset_right; /* */ - uint_32 image_offset_top; /* */ - uint_32 image_offset_bot; /* */ - - /* if syncfb has FEATURE_COLKEY */ - uint_8 colkey_red; - uint_8 colkey_green; - uint_8 colkey_blue; - -} syncfb_config_t; - - -/* - picture parameters, -*/ -typedef struct syncfb_param_s -{ - /* the idea is to enable smooth transitions between eg. image sizes (not yet implemented) */ - /* if syncfb has FEATURE_TRANSITIONS */ - uint_32 transition_time; - - /* if syncfb has FEATURE_PROCAMP */ - uint_32 contrast; /* 0: least contrast, 1000: normal contrast, */ - uint_32 brightness; - uint_32 color; /* for syncfb_matrox: color=0: b/w else: full color */ - - /* if syncfb has FEATURE_SCALE , currently only supported in CONFIG call */ - uint_8 scale_filters; /* 0: no filtering, 255: all filters on */ - uint_32 image_xorg; /* x position of the image on the screen */ - uint_32 image_yorg; /* y position of the image on the screen */ - uint_32 image_width; /* onscreen image width */ - uint_32 image_height; /* onscreen image height */ - -} syncfb_param_t; - - - -typedef struct syncfb_status_info_s -{ - uint_32 field_cnt; /* basically all vbi's since the start of syncfb */ - uint_32 frame_cnt; /* number of frames comitted & output */ - - uint_32 hold_field_cnt; /* number of repeated fields becaus no new data was available */ - uint_32 skip_field_cnt; /* skipped fields when fifo was about to fill up */ - - uint_32 request_frames; /* number of request_buffer calls */ - uint_32 commit_frames; /* number of commit_buffer calls */ - - uint_32 failed_requests; /* number of calls to request_buffer that failed */ - - uint_32 buffers_waiting; - uint_32 buffers_free; - -} syncfb_status_info_t; - - - - -typedef struct syncfb_capability_s -{ - char name[64]; /* A name for the syncfb ... */ - uint_32 palettes; /* supported palettes - see videodev.h for palettes, test the corresponding bit here */ - uint_32 features; /* supported features - see SYNCFB_FEATURE_* */ - uint_32 memory_size; /* total size of mappable video memory */ - -} syncfb_capability_t; - - - -typedef struct syncfb_buffer_info_s -{ - int id; /* buffer id: a return value of -1 means no buffer available */ - uint_32 repeat; /* the buffer will be shown times */ - uint_32 offset; /* buffer offset from start of video memory */ - uint_32 offset_p2; /* yuv plane 2 buffer offset from start of video memory */ - uint_32 offset_p3; /* yuv plane 3 buffer offset from start of video memory */ - -} syncfb_buffer_info_t; - - - - - - - -/* get syncfb capabilities */ -#define SYNCFB_GET_CAPS _IOR('J', 1, syncfb_config_t) - -#define SYNCFB_GET_CONFIG _IOR('J', 2, syncfb_config_t) -#define SYNCFB_SET_CONFIG _IOR('J', 3, syncfb_config_t) -#define SYNCFB_ON _IO ('J', 4) -#define SYNCFB_OFF _IO ('J', 5) -#define SYNCFB_REQUEST_BUFFER _IOR ('J', 6, syncfb_buffer_info_t) -#define SYNCFB_COMMIT_BUFFER _IOR ('J', 7, syncfb_buffer_info_t) -#define SYNCFB_STATUS _IOR ('J', 8, syncfb_status_info_t) -#define SYNCFB_VBI _IO ('J', 9) /* simulate interrupt - debugging only */ -#define SYNCFB_SET_PARAMS _IOR('J', 10, syncfb_param_t) -#define SYNCFB_GET_PARAMS _IOR('J', 11, syncfb_param_t) - - - - -#endif /* __LINUX_SYNCFB_H */ - diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index 3e3c0f7b5..2934b7fef 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -182,8 +182,6 @@ static const xine_config_entry_translation_t config_entry_translation[] = { { "video.pgx64_overlay_mode", "" }, { "video.pgx64_saturation", "video.output.pgx64_saturation" }, { "video.sdl_hw_accel", "video.device.sdl_hw_accel" }, - { "video.syncfb_default_repeat", "video.device.syncfb_default_repeat" }, - { "video.syncfb_device", "video.device.syncfb_device" }, { "video.unichrome_cpu_save", "video.device.unichrome_cpu_save" }, { "video.vertical_position", "video.output.vertical_position" }, { "video.vidix_blue_intensity", "video.output.vidix_blue_intensity" }, -- cgit v1.2.3 From 70dc13d0f5a33871b6e1f4ede9ed3a50159f4ad6 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Thu, 17 Jan 2008 19:29:32 +0000 Subject: Remove syncfb references from the Debian-specific code. --- debian/libxine2-doc.docs | 1 - debian/rules | 5 ----- 2 files changed, 6 deletions(-) diff --git a/debian/libxine2-doc.docs b/debian/libxine2-doc.docs index a1e62bcf1..799c2c091 100644 --- a/debian/libxine2-doc.docs +++ b/debian/libxine2-doc.docs @@ -2,7 +2,6 @@ debian/tmp/usr/share/doc/libxine2/faq/* debian/tmp/usr/share/doc/libxine2/README_xxmc.html debian/tmp/usr/share/doc/libxine2/README debian/tmp/usr/share/doc/libxine2/faq.* -debian/tmp/usr/share/doc/libxine2/README.syncfb* debian/tmp/usr/share/doc/libxine2/README.opengl* debian/tmp/usr/share/doc/libxine2/README.dxr3* debian/tmp/usr/share/doc/libxine2/README.dvb* diff --git a/debian/rules b/debian/rules index 0f38fb778..afc201add 100755 --- a/debian/rules +++ b/debian/rules @@ -58,11 +58,6 @@ ifeq (,$(findstring optimize,$(DEB_BUILD_OPTIONS))) DEB_BUILD_CONFIG_OPTIONS += --build=$(DEB_BUILD_GNU_TYPE) endif -# enable SyncFB video output plugin on Linux -ifeq (linux,$(filter linux,$(subst -, ,$(DEB_BUILD_GNU_TYPE)))) - DEB_BUILD_CONFIG_OPTIONS += --enable-syncfb -endif - # --mandir - remove after etch released (autoconf >= 2.59c gets it right) CONFIGURE_FLAGS := --prefix=/usr \ --with-external-libmad \ -- cgit v1.2.3 From 7d9294e060283d36cc1ac996cba807e95de5dc31 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Thu, 17 Jan 2008 22:37:10 +0000 Subject: Backed out changeset d35b87a8b361 due to build failure. --- src/post/goom/Makefile.am | 2 +- src/post/goom/goomsl_lex.c | 2108 ++++++++++++++++++++++++++++++ src/post/goom/goomsl_yacc.c | 2997 +++++++++++++++++++++++++++++++++++++++++++ src/post/goom/mmx.c | 2 - src/post/goom/mmx.h | 2 - src/post/goom/xmmx.c | 2 - 6 files changed, 5106 insertions(+), 7 deletions(-) create mode 100644 src/post/goom/goomsl_lex.c create mode 100644 src/post/goom/goomsl_yacc.c diff --git a/src/post/goom/Makefile.am b/src/post/goom/Makefile.am index 81e2eff32..22b4af79f 100644 --- a/src/post/goom/Makefile.am +++ b/src/post/goom/Makefile.am @@ -30,7 +30,7 @@ xinepost_LTLIBRARIES = xineplug_post_goom.la xineplug_post_goom_la_SOURCES = mmx.c xine_goom.c \ config_param.c convolve_fx.c cpu_info.c drawmethods.c filters.c flying_stars_fx.c \ gfontlib.c goom_core.c goom_tools.c goomsl.c goomsl_hash.c goomsl_heap.c \ - graphic.c ifs.c lines.c \ + goomsl_lex.c goomsl_yacc.c graphic.c ifs.c lines.c \ plugin_info.c sound_tester.c surf3d.c tentacle3d.c v3d.c xineplug_post_goom_la_LIBADD = $(XINE_LIB) $(GOOM_LIBS) $(PTHREAD_LIBS) $(LTLIBINTL) -lm $(noinst_LTLIBRARIES) xineplug_post_goom_la_CFLAGS = $(DEFAULT_OCFLAGS) $(AM_CFLAGS) diff --git a/src/post/goom/goomsl_lex.c b/src/post/goom/goomsl_lex.c new file mode 100644 index 000000000..988fb99da --- /dev/null +++ b/src/post/goom/goomsl_lex.c @@ -0,0 +1,2108 @@ +#line 2 "goomsl_lex.c" + +#line 4 "goomsl_lex.c" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 31 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; +#endif /* ! C99 */ + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! FLEXINT_H */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +#if __STDC__ + +#define YY_USE_CONST + +#endif /* __STDC__ */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart(yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#define YY_BUF_SIZE 16384 +#endif + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +extern int yyleng; + +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires + * access to the local variable yy_act. Since yyless() is a macro, it would break + * existing scanners that call yyless() from OUTSIDE yylex. + * One obvious solution it to make yy_act a global. I tried that, and saw + * a 5% performance hit in a non-yylineno scanner, because yy_act is + * normally declared as a register variable-- so it is not worth it. + */ + #define YY_LESS_LINENO(n) \ + do { \ + int yyl;\ + for ( yyl = n; yyl < yyleng; ++yyl )\ + if ( yytext[yyl] == '\n' )\ + --yylineno;\ + }while(0) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, (yytext_ptr) ) + +/* The following is because we cannot portably get our hands on size_t + * (without autoconf's help, which isn't available because we want + * flex-generated scanners to compile on their own). + */ + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef unsigned int yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +int yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 1; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart (FILE *input_file ); +void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); +void yy_delete_buffer (YY_BUFFER_STATE b ); +void yy_flush_buffer (YY_BUFFER_STATE b ); +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state (void ); + +static void yyensure_buffer_stack (void ); +static void yy_load_buffer_state (void ); +static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); + +#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); +YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); + +void *yyalloc (yy_size_t ); +void *yyrealloc (void *,yy_size_t ); +void yyfree (void * ); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +typedef unsigned char YY_CHAR; + +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; + +typedef int yy_state_type; + +#define YY_FLEX_LEX_COMPAT +extern int yylineno; + +int yylineno = 1; + +extern char yytext[]; + +static yy_state_type yy_get_previous_state (void ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); +static int yy_get_next_buffer (void ); +static void yy_fatal_error (yyconst char msg[] ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (size_t) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + if ( yyleng + (yy_more_offset) >= YYLMAX ) \ + YY_FATAL_ERROR( "token too large, exceeds YYLMAX" ); \ + yy_flex_strncpy( &yytext[(yy_more_offset)], (yytext_ptr), yyleng + 1 ); \ + yyleng += (yy_more_offset); \ + (yy_prev_more_offset) = (yy_more_offset); \ + (yy_more_offset) = 0; \ + (yy_c_buf_p) = yy_cp; + +#define YY_NUM_RULES 49 +#define YY_END_OF_BUFFER 50 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_acclist[214] = + { 0, + 50, 48, 49, 47, 48, 49, 4, 49, 48, 49, + 13, 48, 49, 10, 48, 49, 33, 48, 49, 48, + 49, 48, 49, 48, 49, 48, 49, 48, 49, 34, + 48, 49, 34, 48, 49, 48, 49, 48, 49, 33, + 48, 49, 33, 48, 49, 33, 48, 49, 33, 48, + 49, 33, 48, 49, 33, 48, 49, 33, 48, 49, + 33, 48, 49, 33, 48, 49, 33, 48, 49, 47, + 48, 49, 1, 4, 49, 48, 49, 7, 49, 6, + 49, 7, 49, 7, 49, 1, 6, 49, 7, 49, + 3, 49, 1, 3, 49, 17, 49, 49, 16, 17, + + 49, 17, 49, 47, 45, 10, 10, 10, 33, 40, + 39, 41, 11, 12, 42, 38, 37, 34, 43, 46, + 44, 33, 33, 28, 33, 33, 33, 33, 33, 30, + 33, 33, 33, 33, 33, 33, 47, 1, 12, 5, + 15, 14, 10, 10, 35, 37, 36, 33, 33, 33, + 33, 33, 29, 33, 19, 33, 26, 33, 21, 33, + 33, 33, 33, 2, 10, 10, 33, 33, 33, 33, + 33, 33, 33, 31, 33, 33, 10, 10, 33, 33, + 33, 32, 33, 18, 33, 33, 33, 27, 33, 10, + 10, 33, 33, 33, 22, 33, 25, 33, 10, 9, + + 10, 10, 20, 33, 23, 33, 33, 10, 24, 33, + 10, 8, 10 + } ; + +static yyconst flex_int16_t yy_accept[152] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, + 4, 7, 9, 11, 14, 17, 20, 22, 24, 26, + 28, 30, 33, 36, 38, 40, 43, 46, 49, 52, + 55, 58, 61, 64, 67, 70, 73, 76, 78, 80, + 82, 84, 86, 89, 91, 93, 96, 98, 99, 102, + 104, 105, 106, 107, 108, 109, 110, 110, 111, 112, + 113, 114, 115, 116, 117, 118, 119, 119, 120, 121, + 122, 123, 124, 126, 127, 128, 129, 130, 132, 133, + 134, 135, 136, 137, 138, 139, 139, 140, 141, 141, + 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, + + 151, 152, 153, 155, 157, 159, 161, 162, 163, 164, + 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, + 174, 176, 177, 178, 179, 180, 181, 182, 184, 186, + 187, 188, 190, 191, 192, 193, 194, 195, 197, 199, + 200, 202, 203, 205, 207, 208, 209, 211, 212, 214, + 214 + } ; + +static yyconst flex_int32_t yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 4, 5, 6, 7, 1, 8, 9, 10, 1, + 1, 11, 12, 1, 13, 14, 15, 16, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 1, 1, 18, + 19, 20, 1, 9, 21, 21, 21, 21, 22, 23, + 21, 21, 24, 21, 21, 25, 21, 26, 21, 21, + 21, 27, 28, 29, 21, 21, 21, 21, 21, 21, + 1, 30, 1, 1, 31, 1, 32, 33, 34, 35, + + 36, 37, 38, 39, 40, 21, 21, 41, 21, 42, + 43, 44, 21, 45, 46, 47, 48, 21, 49, 50, + 21, 21, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int32_t yy_meta[51] = + { 0, + 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 3, 1, 4, 4, 1, 1, 1, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, + 3, 4, 4, 4, 4, 4, 4, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 + } ; + +static yyconst flex_int16_t yy_base[159] = + { 0, + 0, 49, 51, 54, 221, 57, 60, 64, 223, 225, + 69, 225, 203, 225, 51, 0, 0, 202, 201, 200, + 64, 68, 72, 72, 199, 174, 57, 166, 55, 173, + 171, 166, 165, 166, 171, 99, 225, 93, 225, 225, + 194, 107, 225, 193, 225, 225, 225, 225, 225, 71, + 93, 225, 0, 183, 178, 0, 195, 225, 225, 225, + 225, 225, 225, 225, 89, 107, 0, 225, 225, 225, + 161, 169, 0, 155, 160, 157, 154, 151, 150, 151, + 150, 146, 153, 123, 225, 177, 188, 225, 126, 187, + 225, 225, 164, 159, 225, 100, 0, 146, 145, 149, + + 138, 151, 0, 0, 0, 0, 59, 146, 140, 177, + 225, 157, 147, 141, 144, 130, 138, 126, 130, 137, + 0, 134, 165, 143, 133, 112, 109, 0, 0, 102, + 92, 0, 130, 112, 93, 98, 101, 0, 0, 125, + 124, 94, 0, 0, 78, 59, 0, 61, 0, 225, + 141, 145, 149, 151, 155, 51, 159, 163 + } ; + +static yyconst flex_int16_t yy_def[159] = + { 0, + 150, 1, 151, 151, 151, 151, 152, 152, 150, 150, + 150, 150, 150, 150, 153, 154, 155, 150, 150, 150, + 150, 150, 150, 150, 150, 154, 154, 154, 154, 154, + 154, 154, 154, 154, 154, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 153, 153, 153, 154, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 156, 150, 150, 150, + 154, 154, 154, 154, 154, 154, 154, 154, 154, 154, + 154, 154, 154, 150, 150, 150, 157, 150, 150, 157, + 150, 150, 153, 153, 150, 150, 156, 154, 154, 154, + + 154, 154, 154, 154, 154, 154, 154, 154, 154, 157, + 150, 153, 153, 154, 154, 154, 154, 154, 154, 154, + 154, 154, 153, 153, 154, 154, 154, 154, 154, 154, + 154, 154, 158, 153, 154, 154, 154, 154, 154, 158, + 158, 153, 154, 154, 154, 153, 154, 153, 153, 0, + 150, 150, 150, 150, 150, 150, 150, 150 + } ; + +static yyconst flex_int16_t yy_nxt[276] = + { 0, + 10, 11, 12, 11, 13, 14, 15, 10, 16, 17, + 18, 19, 20, 10, 21, 22, 23, 24, 10, 25, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 10, + 16, 16, 26, 16, 27, 28, 29, 16, 16, 30, + 16, 31, 16, 32, 16, 33, 34, 16, 35, 16, + 36, 37, 36, 40, 97, 42, 43, 42, 42, 46, + 42, 41, 48, 38, 41, 49, 48, 149, 44, 49, + 51, 44, 51, 54, 61, 64, 91, 55, 62, 64, + 148, 65, 63, 66, 66, 65, 75, 66, 66, 50, + 68, 69, 72, 50, 51, 76, 51, 77, 119, 73, + + 84, 85, 84, 61, 96, 96, 120, 87, 89, 85, + 89, 63, 92, 86, 64, 96, 96, 67, 147, 146, + 65, 86, 66, 66, 84, 85, 84, 89, 85, 89, + 141, 141, 145, 144, 143, 142, 141, 86, 139, 138, + 86, 39, 39, 39, 39, 47, 47, 47, 47, 53, + 137, 53, 53, 56, 56, 57, 136, 57, 57, 110, + 110, 110, 110, 140, 135, 140, 140, 134, 133, 132, + 131, 130, 129, 128, 127, 126, 125, 124, 123, 111, + 122, 121, 118, 117, 116, 115, 114, 113, 112, 111, + 111, 90, 109, 108, 107, 106, 105, 104, 103, 102, + + 101, 100, 99, 98, 95, 94, 93, 90, 88, 83, + 82, 81, 80, 79, 78, 74, 71, 70, 60, 59, + 58, 52, 150, 45, 9, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150 + } ; + +static yyconst flex_int16_t yy_chk[276] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 3, 156, 4, 4, 4, 6, 6, + 6, 3, 7, 2, 4, 7, 8, 148, 4, 8, + 11, 6, 11, 15, 21, 22, 50, 15, 21, 23, + 146, 22, 21, 22, 22, 23, 29, 23, 23, 7, + 24, 24, 27, 8, 51, 29, 51, 29, 107, 27, + + 36, 36, 36, 38, 65, 65, 107, 38, 42, 42, + 42, 38, 50, 36, 66, 96, 96, 22, 145, 142, + 66, 42, 66, 66, 84, 84, 84, 89, 89, 89, + 141, 140, 137, 136, 135, 134, 133, 84, 131, 130, + 89, 151, 151, 151, 151, 152, 152, 152, 152, 153, + 127, 153, 153, 154, 154, 155, 126, 155, 155, 157, + 157, 157, 157, 158, 125, 158, 158, 124, 123, 122, + 120, 119, 118, 117, 116, 115, 114, 113, 112, 110, + 109, 108, 102, 101, 100, 99, 98, 94, 93, 90, + 87, 86, 83, 82, 81, 80, 79, 78, 77, 76, + + 75, 74, 72, 71, 57, 55, 54, 44, 41, 35, + 34, 33, 32, 31, 30, 28, 26, 25, 20, 19, + 18, 13, 9, 5, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, + 150, 150, 150, 150, 150 + } ; + +/* Table of booleans, true if rule could match eol. */ +static yyconst flex_int32_t yy_rule_can_match_eol[50] = + { 0, +1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; + +extern int yy_flex_debug; +int yy_flex_debug = 0; + +static yy_state_type *yy_state_buf=0, *yy_state_ptr=0; +static char *yy_full_match; +static int yy_lp; +#define REJECT \ +{ \ +*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ \ +yy_cp = (yy_full_match); /* restore poss. backed-over text */ \ +++(yy_lp); \ +goto find_rule; \ +} + +static int yy_more_offset = 0; +static int yy_prev_more_offset = 0; +#define yymore() ((yy_more_offset) = yy_flex_strlen( yytext )) +#define YY_NEED_STRLEN +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET \ + { \ + (yy_more_offset) = (yy_prev_more_offset); \ + yyleng -= (yy_more_offset); \ + } +#ifndef YYLMAX +#define YYLMAX 8192 +#endif + +char yytext[YYLMAX]; +char *yytext_ptr; +#line 1 "goomsl_lex.l" +#line 2 "goomsl_lex.l" + +#include +#include +#include +#include "goomsl.h" +#include "goomsl_private.h" +#include "goomsl_yacc.h" +void yyerror(char *); +void yyparse(void); + +GoomSL *currentGoomSL; +static int string_size; +static char string[1024]; + + + +#line 639 "goomsl_lex.c" + +#define INITIAL 0 +#define C_COMMENT 1 +#define LINE_COMMENT 2 +#define STRING 3 + +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap (void ); +#else +extern int yywrap (void ); +#endif +#endif + + static void yyunput (int c,char *buf_ptr ); + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ); +#endif + +#ifndef YY_NO_INPUT + +#ifdef __cplusplus +static int yyinput (void ); +#else +static int input (void ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + size_t n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex (void); + +#define YY_DECL int yylex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + if ( yyleng > 0 ) \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = \ + (yytext[yyleng - 1] == '\n'); \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + +#line 25 "goomsl_lex.l" + + +#line 797 "goomsl_lex.c" + + if ( (yy_init) ) + { + (yy_init) = 0; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_state_buf) ) + (yy_state_buf) = (yy_state_type *)yyalloc(YY_BUF_SIZE + 2 ); + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_load_buffer_state( ); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); + yy_current_state += YY_AT_BOL(); + + (yy_state_ptr) = (yy_state_buf); + *(yy_state_ptr)++ = yy_current_state; + +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 151 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + *(yy_state_ptr)++ = yy_current_state; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 225 ); + +yy_find_action: + yy_current_state = *--(yy_state_ptr); + (yy_lp) = yy_accept[yy_current_state]; +find_rule: /* we branch to this label when backing up */ + for ( ; ; ) /* until we find what rule we matched */ + { + if ( (yy_lp) && (yy_lp) < yy_accept[yy_current_state + 1] ) + { + yy_act = yy_acclist[(yy_lp)]; + { + (yy_full_match) = yy_cp; + break; + } + } + --yy_cp; + yy_current_state = *--(yy_state_ptr); + (yy_lp) = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + + if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] ) + { + int yyl; + for ( yyl = (yy_prev_more_offset); yyl < yyleng; ++yyl ) + if ( yytext[yyl] == '\n' ) + + yylineno++; +; + } + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ +case 1: +/* rule 1 can match eol */ +YY_RULE_SETUP +#line 27 "goomsl_lex.l" +{ ++currentGoomSL->num_lines; /* Ignore empty lines */ } + YY_BREAK +case 2: +/* rule 2 can match eol */ +YY_RULE_SETUP +#line 28 "goomsl_lex.l" +{ ++currentGoomSL->num_lines; /* Ignore empty lines */ } + YY_BREAK +case 3: +/* rule 3 can match eol */ +YY_RULE_SETUP +#line 30 "goomsl_lex.l" +{ ++currentGoomSL->num_lines; yylval.charValue=*yytext; BEGIN INITIAL; return '\n'; } + YY_BREAK +case 4: +/* rule 4 can match eol */ +YY_RULE_SETUP +#line 31 "goomsl_lex.l" +{ ++currentGoomSL->num_lines; yylval.charValue=*yytext; return '\n'; } + YY_BREAK +case 5: +YY_RULE_SETUP +#line 33 "goomsl_lex.l" +{ BEGIN INITIAL; } + YY_BREAK +case 6: +/* rule 6 can match eol */ +YY_RULE_SETUP +#line 34 "goomsl_lex.l" +{ ++currentGoomSL->num_lines; } + YY_BREAK +case 7: +YY_RULE_SETUP +#line 35 "goomsl_lex.l" +{ /* eat up comment */ } + YY_BREAK +case 8: +YY_RULE_SETUP +#line 37 "goomsl_lex.l" +{ currentGoomSL->num_lines = 0; } + YY_BREAK +case 9: +YY_RULE_SETUP +#line 38 "goomsl_lex.l" +{ currentGoomSL->num_lines = 0; printf("%s\n", yytext); } + YY_BREAK +case 10: +YY_RULE_SETUP +#line 39 "goomsl_lex.l" +{ /* ignore preprocessor lines */ } + YY_BREAK +case 11: +YY_RULE_SETUP +#line 41 "goomsl_lex.l" +{ BEGIN C_COMMENT; } + YY_BREAK +case 12: +YY_RULE_SETUP +#line 42 "goomsl_lex.l" +{ BEGIN LINE_COMMENT; } + YY_BREAK +case 13: +YY_RULE_SETUP +#line 43 "goomsl_lex.l" +{ BEGIN STRING; string_size=0; } + YY_BREAK +case 14: +YY_RULE_SETUP +#line 45 "goomsl_lex.l" +{ string[string_size++] = '\n'; } + YY_BREAK +case 15: +YY_RULE_SETUP +#line 46 "goomsl_lex.l" +{ string[string_size++] = '\"'; } + YY_BREAK +case 16: +YY_RULE_SETUP +#line 47 "goomsl_lex.l" +{ /* fin de la chaine: on cree le pointeur qui va bien */ + unsigned int tmp; + BEGIN INITIAL; + string[string_size]=0; + tmp = gsl_malloc(currentGoomSL, string_size+1); + strcpy((char*)currentGoomSL->ptrArray[tmp],string); + sprintf(yylval.strValue, "0x%08x", tmp); + return LTYPE_PTR; + } + YY_BREAK +case 17: +YY_RULE_SETUP +#line 56 "goomsl_lex.l" +{ string[string_size++] = *yytext; } + YY_BREAK +case 18: +YY_RULE_SETUP +#line 58 "goomsl_lex.l" +{ return FLOAT_TK; } + YY_BREAK +case 19: +YY_RULE_SETUP +#line 59 "goomsl_lex.l" +{ return INT_TK; } + YY_BREAK +case 20: +YY_RULE_SETUP +#line 60 "goomsl_lex.l" +{ return INT_TK; } + YY_BREAK +case 21: +YY_RULE_SETUP +#line 61 "goomsl_lex.l" +{ return PTR_TK; } + YY_BREAK +case 22: +YY_RULE_SETUP +#line 62 "goomsl_lex.l" +{ return PTR_TK; } + YY_BREAK +case 23: +YY_RULE_SETUP +#line 63 "goomsl_lex.l" +{ return DECLARE; } + YY_BREAK +case 24: +YY_RULE_SETUP +#line 64 "goomsl_lex.l" +{ return EXTERNAL; } + YY_BREAK +case 25: +YY_RULE_SETUP +#line 65 "goomsl_lex.l" +{ return STRUCT; } + YY_BREAK +case 26: +YY_RULE_SETUP +#line 66 "goomsl_lex.l" +{ return NOT; } + YY_BREAK +case 27: +YY_RULE_SETUP +#line 67 "goomsl_lex.l" +{ return WHILE; } + YY_BREAK +case 28: +YY_RULE_SETUP +#line 68 "goomsl_lex.l" +{ return DO; } + YY_BREAK +case 29: +YY_RULE_SETUP +#line 69 "goomsl_lex.l" +{ return FOR; } + YY_BREAK +case 30: +YY_RULE_SETUP +#line 70 "goomsl_lex.l" +{ return IN; } + YY_BREAK +case 31: +YY_RULE_SETUP +#line 71 "goomsl_lex.l" +{ strncpy(yylval.strValue, "1", 2047); return LTYPE_INTEGER; } + YY_BREAK +case 32: +YY_RULE_SETUP +#line 72 "goomsl_lex.l" +{ strncpy(yylval.strValue, "0", 2047); return LTYPE_INTEGER; } + YY_BREAK +case 33: +YY_RULE_SETUP +#line 73 "goomsl_lex.l" +{ strncpy(yylval.strValue, yytext, 2047); return LTYPE_VAR; } + YY_BREAK +case 34: +YY_RULE_SETUP +#line 74 "goomsl_lex.l" +{ strncpy(yylval.strValue, yytext, 2047); return LTYPE_INTEGER; } + YY_BREAK +case 35: +YY_RULE_SETUP +#line 75 "goomsl_lex.l" +{ sprintf(yylval.strValue, "%d", (int)yytext[1]); return LTYPE_INTEGER; } + YY_BREAK +case 36: +YY_RULE_SETUP +#line 76 "goomsl_lex.l" +{ strncpy(yylval.strValue, yytext, 2047); return LTYPE_INTEGER; } + YY_BREAK +case 37: +YY_RULE_SETUP +#line 77 "goomsl_lex.l" +{ strncpy(yylval.strValue, yytext, 2047); return LTYPE_FLOAT; } + YY_BREAK +case 38: +YY_RULE_SETUP +#line 78 "goomsl_lex.l" +{ sprintf(yylval.strValue, "%3.2f", atof(yytext)/100.0f); return LTYPE_FLOAT; } + YY_BREAK +case 39: +YY_RULE_SETUP +#line 79 "goomsl_lex.l" +{ return PLUS_EQ; } + YY_BREAK +case 40: +YY_RULE_SETUP +#line 80 "goomsl_lex.l" +{ return MUL_EQ; } + YY_BREAK +case 41: +YY_RULE_SETUP +#line 81 "goomsl_lex.l" +{ return SUB_EQ; } + YY_BREAK +case 42: +YY_RULE_SETUP +#line 82 "goomsl_lex.l" +{ return DIV_EQ; } + YY_BREAK +case 43: +YY_RULE_SETUP +#line 83 "goomsl_lex.l" +{ return LOW_EQ; } + YY_BREAK +case 44: +YY_RULE_SETUP +#line 84 "goomsl_lex.l" +{ return SUP_EQ; } + YY_BREAK +case 45: +YY_RULE_SETUP +#line 85 "goomsl_lex.l" +{ return NOT_EQ; } + YY_BREAK +case 46: +YY_RULE_SETUP +#line 86 "goomsl_lex.l" +{ return NOT_EQ; } + YY_BREAK +case 47: +YY_RULE_SETUP +#line 87 "goomsl_lex.l" +/* eat up whitespace */ + YY_BREAK +case 48: +YY_RULE_SETUP +#line 88 "goomsl_lex.l" +{ yylval.charValue = *yytext; return *yytext; } + YY_BREAK +case 49: +YY_RULE_SETUP +#line 90 "goomsl_lex.l" +ECHO; + YY_BREAK +#line 1155 "goomsl_lex.c" + case YY_STATE_EOF(INITIAL): + case YY_STATE_EOF(C_COMMENT): + case YY_STATE_EOF(LINE_COMMENT): + case YY_STATE_EOF(STRING): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_c_buf_p); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ +} /* end of yylex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = (yytext_ptr); + register int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + size_t num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + YY_FATAL_ERROR( +"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart(yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = (yy_start); + yy_current_state += YY_AT_BOL(); + + (yy_state_ptr) = (yy_state_buf); + *(yy_state_ptr)++ = yy_current_state; + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 151 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + *(yy_state_ptr)++ = yy_current_state; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + register int yy_is_jam; + + register YY_CHAR yy_c = 1; + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 151 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 150); + if ( ! yy_is_jam ) + *(yy_state_ptr)++ = yy_current_state; + + return yy_is_jam ? 0 : yy_current_state; +} + + static void yyunput (int c, register char * yy_bp ) +{ + register char *yy_cp; + + yy_cp = (yy_c_buf_p); + + /* undo effects of setting up yytext */ + *yy_cp = (yy_hold_char); + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + register int number_to_move = (yy_n_chars) + 2; + register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + register char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + if ( c == '\n' ){ + --yylineno; + } + + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; +} + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + int offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart(yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return EOF; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); + + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = (c == '\n'); + if ( YY_CURRENT_BUFFER_LVALUE->yy_at_bol ) + + yylineno++; +; + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void yyrestart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_init_buffer(YY_CURRENT_BUFFER,input_file ); + yy_load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void yy_load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer(b,file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yy_delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yyfree((void *) b->yy_ch_buf ); + + yyfree((void *) b ); +} + +#ifndef __cplusplus +extern int isatty (int ); +#endif /* __cplusplus */ + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + yy_flush_buffer(b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void yy_flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void yyensure_buffer_stack (void) +{ + int num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer(b ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to yylex() will + * scan from a @e copy of @a str. + * @param str a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * yy_scan_bytes() instead. + */ +YY_BUFFER_STATE yy_scan_string (yyconst char * str ) +{ + + return yy_scan_bytes(str,strlen(str) ); +} + +/** Setup the input buffer state to scan the given bytes. The next call to yylex() will + * scan from a @e copy of @a bytes. + * @param bytes the byte buffer to scan + * @param len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_bytes (yyconst char * bytes, int len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = len + 2; + buf = (char *) yyalloc(n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < len; ++i ) + buf[i] = bytes[i]; + + buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer(buf,n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yy_fatal_error (yyconst char* msg ) +{ + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int yyget_lineno (void) +{ + + return yylineno; +} + +/** Get the input stream. + * + */ +FILE *yyget_in (void) +{ + return yyin; +} + +/** Get the output stream. + * + */ +FILE *yyget_out (void) +{ + return yyout; +} + +/** Get the length of the current token. + * + */ +int yyget_leng (void) +{ + return yyleng; +} + +/** Get the current token. + * + */ + +char *yyget_text (void) +{ + return yytext; +} + +/** Set the current line number. + * @param line_number + * + */ +void yyset_lineno (int line_number ) +{ + + yylineno = line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param in_str A readable stream. + * + * @see yy_switch_to_buffer + */ +void yyset_in (FILE * in_str ) +{ + yyin = in_str ; +} + +void yyset_out (FILE * out_str ) +{ + yyout = out_str ; +} + +int yyget_debug (void) +{ + return yy_flex_debug; +} + +void yyset_debug (int bdebug ) +{ + yy_flex_debug = bdebug ; +} + +/* yylex_destroy is for both reentrant and non-reentrant scanners. */ +int yylex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } + + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + yyfree ( (yy_state_buf) ); + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s ) +{ + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *yyalloc (yy_size_t size ) +{ + return (void *) malloc( size ); +} + +void *yyrealloc (void * ptr, yy_size_t size ) +{ + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} + +void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#undef YY_NEW_FILE +#undef YY_FLUSH_BUFFER +#undef yy_set_bol +#undef yy_new_buffer +#undef yy_set_interactive +#undef YY_DO_BEFORE_ACTION + +#ifdef YY_DECL_IS_OURS +#undef YY_DECL_IS_OURS +#undef YY_DECL +#endif +#line 90 "goomsl_lex.l" + + + + +int yywrap(void) { return 1; yyunput(0,0); } + + diff --git a/src/post/goom/goomsl_yacc.c b/src/post/goom/goomsl_yacc.c new file mode 100644 index 000000000..589b171be --- /dev/null +++ b/src/post/goom/goomsl_yacc.c @@ -0,0 +1,2997 @@ +/* A Bison parser, made by GNU Bison 1.875. */ + +/* Skeleton parser for Yacc-like parsing with Bison, + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* As a special exception, when this file is copied by Bison into a + Bison output file, you may use that output file without restriction. + This special exception was added by the Free Software Foundation + in version 1.24 of Bison. */ + +/* Written by Richard Stallman by simplifying the original so called + ``semantic'' parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Using locations. */ +#define YYLSP_NEEDED 0 + + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + LTYPE_INTEGER = 258, + LTYPE_FLOAT = 259, + LTYPE_VAR = 260, + LTYPE_PTR = 261, + PTR_TK = 262, + INT_TK = 263, + FLOAT_TK = 264, + DECLARE = 265, + EXTERNAL = 266, + WHILE = 267, + DO = 268, + NOT = 269, + PLUS_EQ = 270, + SUB_EQ = 271, + DIV_EQ = 272, + MUL_EQ = 273, + SUP_EQ = 274, + LOW_EQ = 275, + NOT_EQ = 276, + STRUCT = 277, + FOR = 278, + IN = 279 + }; +#endif +#define LTYPE_INTEGER 258 +#define LTYPE_FLOAT 259 +#define LTYPE_VAR 260 +#define LTYPE_PTR 261 +#define PTR_TK 262 +#define INT_TK 263 +#define FLOAT_TK 264 +#define DECLARE 265 +#define EXTERNAL 266 +#define WHILE 267 +#define DO 268 +#define NOT 269 +#define PLUS_EQ 270 +#define SUB_EQ 271 +#define DIV_EQ 272 +#define MUL_EQ 273 +#define SUP_EQ 274 +#define LOW_EQ 275 +#define NOT_EQ 276 +#define STRUCT 277 +#define FOR 278 +#define IN 279 + + + + +/* Copy the first part of user declarations. */ +#line 6 "goomsl_yacc.y" + + #include + #include + #include + #include "goomsl.h" + #include "goomsl_private.h" + +#define STRUCT_ALIGNMENT 16 +/* #define VERBOSE */ + + int yylex(void); + void yyerror(char *); + extern GoomSL *currentGoomSL; + + static NodeType *nodeNew(const char *str, int type, int line_number); + static NodeType *nodeClone(NodeType *node); + static void nodeFreeInternals(NodeType *node); + static void nodeFree(NodeType *node); + + static void commit_node(NodeType *node, int releaseIfTemp); + static void precommit_node(NodeType *node); + + static NodeType *new_constInt(const char *str, int line_number); + static NodeType *new_constFloat(const char *str, int line_number); + static NodeType *new_constPtr(const char *str, int line_number); + static NodeType *new_var(const char *str, int line_number); + static NodeType *new_nop(const char *str); + static NodeType *new_op(const char *str, int type, int nbOp); + + static int allocateLabel(); + static int allocateTemp(); + static void releaseTemp(int n); + static void releaseAllTemps(); + + static int is_tmp_expr(NodeType *node) { + if (node->str) { + return (!strncmp(node->str,"_i_tmp_",7)) + || (!strncmp(node->str,"_f_tmp_",7)) + || (!strncmp(node->str,"_p_tmp",7)); + } + return 0; + } + /* pre: is_tmp_expr(node); */ + static int get_tmp_id(NodeType *node) { return atoi((node->str)+5); } + + static int is_commutative_expr(int itype) + { /* {{{ */ + return (itype == INSTR_ADD) + || (itype == INSTR_MUL) + || (itype == INSTR_ISEQUAL); + } /* }}} */ + + static void GSL_PUT_LABEL(char *name, int line_number) + { /* {{{ */ +#ifdef VERBOSE + printf("label %s\n", name); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "label", INSTR_LABEL, 1, line_number); + gsl_instr_add_param(currentGoomSL->instr, name, TYPE_LABEL); + } /* }}} */ + static void GSL_PUT_JUMP(char *name, int line_number) + { /* {{{ */ +#ifdef VERBOSE + printf("jump %s\n", name); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "jump", INSTR_JUMP, 1, line_number); + gsl_instr_add_param(currentGoomSL->instr, name, TYPE_LABEL); + } /* }}} */ + + static void GSL_PUT_JXXX(char *name, char *iname, int instr_id, int line_number) + { /* {{{ */ +#ifdef VERBOSE + printf("%s %s\n", iname, name); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, iname, instr_id, 1, line_number); + gsl_instr_add_param(currentGoomSL->instr, name, TYPE_LABEL); + } /* }}} */ + static void GSL_PUT_JZERO(char *name,int line_number) + { /* {{{ */ + GSL_PUT_JXXX(name,"jzero.i",INSTR_JZERO,line_number); + } /* }}} */ + static void GSL_PUT_JNZERO(char *name, int line_number) + { /* {{{ */ + GSL_PUT_JXXX(name,"jnzero.i",INSTR_JNZERO,line_number); + } /* }}} */ + + /* Structures Management */ + +#define ALIGN_ADDR(_addr,_align) {\ + if (_align>1) {\ + int _dec = (_addr%_align);\ + if (_dec != 0) _addr += _align - _dec;\ + }} + + /* */ + void gsl_prepare_struct(GSL_Struct *s, int s_align, int i_align, int f_align) + { + int i; + int consumed = 0; + int iblk=0, fblk=0; + + s->iBlock[0].size = 0; + s->iBlock[0].data = 0; + s->fBlock[0].size = 0; + s->fBlock[0].data = 0; + + /* Prepare sub-struct and calculate space needed for their storage */ + for (i = 0; i < s->nbFields; ++i) + { + if (s->fields[i]->type < FIRST_RESERVED) + { + int j=0; + GSL_Struct *substruct = currentGoomSL->gsl_struct[s->fields[i]->type]; + consumed += sizeof(int); /* stocke le prefix */ + ALIGN_ADDR(consumed, s_align); + s->fields[i]->offsetInStruct = consumed; + gsl_prepare_struct(substruct, s_align, i_align, f_align); + for(j=0;substruct->iBlock[j].size>0;++j) { + s->iBlock[iblk].data = consumed + substruct->iBlock[j].data; + s->iBlock[iblk].size = substruct->iBlock[j].size; + iblk++; + } + for(j=0;substruct->fBlock[j].size>0;++j) { + s->fBlock[fblk].data = consumed + substruct->fBlock[j].data; + s->fBlock[fblk].size = substruct->fBlock[j].size; + fblk++; + } + consumed += substruct->size; + } + } + + /* Then prepare integers */ + ALIGN_ADDR(consumed, i_align); + for (i = 0; i < s->nbFields; ++i) + { + if (s->fields[i]->type == INSTR_INT) + { + if (s->iBlock[iblk].size == 0) { + s->iBlock[iblk].size = 1; + s->iBlock[iblk].data = consumed; + } else { + s->iBlock[iblk].size += 1; + } + s->fields[i]->offsetInStruct = consumed; + consumed += sizeof(int); + } + } + + iblk++; + s->iBlock[iblk].size = 0; + s->iBlock[iblk].data = 0; + + /* Then prepare floats */ + ALIGN_ADDR(consumed, f_align); + for (i = 0; i < s->nbFields; ++i) + { + if (s->fields[i]->type == INSTR_FLOAT) + { + if (s->fBlock[fblk].size == 0) { + s->fBlock[fblk].size = 1; + s->fBlock[fblk].data = consumed; + } else { + s->fBlock[fblk].size += 1; + } + s->fields[i]->offsetInStruct = consumed; + consumed += sizeof(int); + } + } + + fblk++; + s->fBlock[fblk].size = 0; + s->fBlock[fblk].data = 0; + + /* Finally prepare pointers */ + ALIGN_ADDR(consumed, i_align); + for (i = 0; i < s->nbFields; ++i) + { + if (s->fields[i]->type == INSTR_PTR) + { + s->fields[i]->offsetInStruct = consumed; + consumed += sizeof(int); + } + } + s->size = consumed; + } + + /* Returns the ID of a struct from its name */ + int gsl_get_struct_id(const char *name) /* {{{ */ + { + HashValue *ret = goom_hash_get(currentGoomSL->structIDS, name); + if (ret != NULL) return ret->i; + return -1; + } /* }}} */ + + /* Adds the definition of a struct */ + void gsl_add_struct(const char *name, GSL_Struct *gsl_struct) /* {{{ */ + { + /* Prepare the struct: ie calculate internal storage format */ + gsl_prepare_struct(gsl_struct, STRUCT_ALIGNMENT, STRUCT_ALIGNMENT, STRUCT_ALIGNMENT); + + /* If the struct does not already exists */ + if (gsl_get_struct_id(name) < 0) + { + /* adds it */ + int id = currentGoomSL->nbStructID++; + goom_hash_put_int(currentGoomSL->structIDS, name, id); + if (currentGoomSL->gsl_struct_size <= id) { + currentGoomSL->gsl_struct_size *= 2; + currentGoomSL->gsl_struct = (GSL_Struct**)realloc(currentGoomSL->gsl_struct, + sizeof(GSL_Struct*) * currentGoomSL->gsl_struct_size); + } + currentGoomSL->gsl_struct[id] = gsl_struct; + } + } /* }}} */ + + /* Creates a field for a struct */ + GSL_StructField *gsl_new_struct_field(const char *name, int type) + { + GSL_StructField *field = (GSL_StructField*)malloc(sizeof(GSL_StructField)); + strcpy(field->name, name); + field->type = type; + return field; + } + + /* Create as field for a struct which will be a struct itself */ + GSL_StructField *gsl_new_struct_field_struct(const char *name, const char *type) + { + GSL_StructField *field = gsl_new_struct_field(name, gsl_get_struct_id(type)); + if (field->type < 0) { + fprintf(stderr, "ERROR: Line %d, Unknown structure: '%s'\n", + currentGoomSL->num_lines, type); + exit(1); + } + return field; + } + + /* Creates a Struct */ + GSL_Struct *gsl_new_struct(GSL_StructField *field) + { + GSL_Struct *s = (GSL_Struct*)malloc(sizeof(GSL_Struct)); + s->nbFields = 1; + s->fields[0] = field; + return s; + } + + /* Adds a field to a struct */ + void gsl_add_struct_field(GSL_Struct *s, GSL_StructField *field) + { + s->fields[s->nbFields++] = field; + } + + int gsl_type_of_var(GoomHash *ns, const char *name) + { + char type_of[256]; + HashValue *hv; + sprintf(type_of, "__type_of_%s", name); + hv = goom_hash_get(ns, type_of); + if (hv != NULL) + return hv->i; + fprintf(stderr, "ERROR: Unknown variable type: '%s'\n", name); + return -1; + } + + static void gsl_declare_var(GoomHash *ns, const char *name, int type, void *space) + { + char type_of[256]; + if (name[0] == '@') { ns = currentGoomSL->vars; } + + if (space == NULL) { + switch (type) { + case INSTR_INT: + case INSTR_FLOAT: + case INSTR_PTR: + space = goom_heap_malloc_with_alignment(currentGoomSL->data_heap, + sizeof(int), sizeof(int)); + break; + case -1: + fprintf(stderr, "What the fuck!\n"); + exit(1); + default: /* On a un struct_id */ + space = goom_heap_malloc_with_alignment_prefixed(currentGoomSL->data_heap, + currentGoomSL->gsl_struct[type]->size, STRUCT_ALIGNMENT, sizeof(int)); + } + } + goom_hash_put_ptr(ns, name, (void*)space); + sprintf(type_of, "__type_of_%s", name); + goom_hash_put_int(ns, type_of, type); + + /* Ensuite le hack: on ajoute les champs en tant que variables. */ + if (type < FIRST_RESERVED) + { + int i; + GSL_Struct *gsl_struct = currentGoomSL->gsl_struct[type]; + ((int*)space)[-1] = type; /* stockage du type dans le prefixe de structure */ + for (i = 0; i < gsl_struct->nbFields; ++i) + { + char full_name[256]; + char *cspace = (char*)space + gsl_struct->fields[i]->offsetInStruct; + sprintf(full_name, "%s.%s", name, gsl_struct->fields[i]->name); + gsl_declare_var(ns, full_name, gsl_struct->fields[i]->type, cspace); + } + } + } + + /* Declare a variable which will be a struct */ + static void gsl_struct_decl(GoomHash *namespace, const char *struct_name, const char *name) + { + int struct_id = gsl_get_struct_id(struct_name); + gsl_declare_var(namespace, name, struct_id, NULL); + } + + static void gsl_float_decl_global(const char *name) + { + gsl_declare_var(currentGoomSL->vars, name, INSTR_FLOAT, NULL); + } + static void gsl_int_decl_global(const char *name) + { + gsl_declare_var(currentGoomSL->vars, name, INSTR_INT, NULL); + } + static void gsl_ptr_decl_global(const char *name) + { + gsl_declare_var(currentGoomSL->vars, name, INSTR_PTR, NULL); + } + static void gsl_struct_decl_global_from_id(const char *name, int id) + { + gsl_declare_var(currentGoomSL->vars, name, id, NULL); + } + + /* FLOAT */ + static void gsl_float_decl_local(const char *name) + { + gsl_declare_var(currentGoomSL->namespaces[currentGoomSL->currentNS], name, INSTR_FLOAT, NULL); + } + /* INT */ + static void gsl_int_decl_local(const char *name) + { + gsl_declare_var(currentGoomSL->namespaces[currentGoomSL->currentNS], name, INSTR_INT, NULL); + } + /* PTR */ + static void gsl_ptr_decl_local(const char *name) + { + gsl_declare_var(currentGoomSL->namespaces[currentGoomSL->currentNS], name, INSTR_PTR, NULL); + } + /* STRUCT */ + static void gsl_struct_decl_local(const char *struct_name, const char *name) + { + gsl_struct_decl(currentGoomSL->namespaces[currentGoomSL->currentNS],struct_name,name); + } + + + static void commit_test2(NodeType *set,const char *type, int instr); + static NodeType *new_call(const char *name, NodeType *affect_list); + + /* SETTER */ + static NodeType *new_set(NodeType *lvalue, NodeType *expression) + { /* {{{ */ + NodeType *set = new_op("set", OPR_SET, 2); + set->unode.opr.op[0] = lvalue; + set->unode.opr.op[1] = expression; + return set; + } /* }}} */ + static void commit_set(NodeType *set) + { /* {{{ */ + commit_test2(set,"set",INSTR_SET); + } /* }}} */ + + /* PLUS_EQ */ + static NodeType *new_plus_eq(NodeType *lvalue, NodeType *expression) /* {{{ */ + { + NodeType *set = new_op("plus_eq", OPR_PLUS_EQ, 2); + set->unode.opr.op[0] = lvalue; + set->unode.opr.op[1] = expression; + return set; + } + static void commit_plus_eq(NodeType *set) + { + precommit_node(set->unode.opr.op[1]); +#ifdef VERBOSE + printf("add %s %s\n", set->unode.opr.op[0]->str, set->unode.opr.op[1]->str); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "add", INSTR_ADD, 2, set->line_number); + commit_node(set->unode.opr.op[0],0); + commit_node(set->unode.opr.op[1],1); + } /* }}} */ + + /* SUB_EQ */ + static NodeType *new_sub_eq(NodeType *lvalue, NodeType *expression) /* {{{ */ + { + NodeType *set = new_op("sub_eq", OPR_SUB_EQ, 2); + set->unode.opr.op[0] = lvalue; + set->unode.opr.op[1] = expression; + return set; + } + static void commit_sub_eq(NodeType *set) + { + precommit_node(set->unode.opr.op[1]); +#ifdef VERBOSE + printf("sub %s %s\n", set->unode.opr.op[0]->str, set->unode.opr.op[1]->str); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "sub", INSTR_SUB, 2, set->line_number); + commit_node(set->unode.opr.op[0],0); + commit_node(set->unode.opr.op[1],1); + } /* }}} */ + + /* MUL_EQ */ + static NodeType *new_mul_eq(NodeType *lvalue, NodeType *expression) /* {{{ */ + { + NodeType *set = new_op("mul_eq", OPR_MUL_EQ, 2); + set->unode.opr.op[0] = lvalue; + set->unode.opr.op[1] = expression; + return set; + } + static void commit_mul_eq(NodeType *set) + { + precommit_node(set->unode.opr.op[1]); +#ifdef VERBOSE + printf("mul %s %s\n", set->unode.opr.op[0]->str, set->unode.opr.op[1]->str); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "mul", INSTR_MUL, 2, set->line_number); + commit_node(set->unode.opr.op[0],0); + commit_node(set->unode.opr.op[1],1); + } /* }}} */ + + /* DIV_EQ */ + static NodeType *new_div_eq(NodeType *lvalue, NodeType *expression) /* {{{ */ + { + NodeType *set = new_op("div_eq", OPR_DIV_EQ, 2); + set->unode.opr.op[0] = lvalue; + set->unode.opr.op[1] = expression; + return set; + } + static void commit_div_eq(NodeType *set) + { + precommit_node(set->unode.opr.op[1]); +#ifdef VERBOSE + printf("div %s %s\n", set->unode.opr.op[0]->str, set->unode.opr.op[1]->str); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "div", INSTR_DIV, 2, set->line_number); + commit_node(set->unode.opr.op[0],0); + commit_node(set->unode.opr.op[1],1); + } /* }}} */ + + /* commodity method for add, mult, ... */ + + static void precommit_expr(NodeType *expr, const char *type, int instr_id) + { /* {{{ */ + NodeType *tmp, *tmpcpy; + int toAdd; + + /* compute "left" and "right" */ + switch (expr->unode.opr.nbOp) { + case 2: + precommit_node(expr->unode.opr.op[1]); + case 1: + precommit_node(expr->unode.opr.op[0]); + } + + if (is_tmp_expr(expr->unode.opr.op[0])) { + tmp = expr->unode.opr.op[0]; + toAdd = 1; + } + else if (is_commutative_expr(instr_id) && (expr->unode.opr.nbOp==2) && is_tmp_expr(expr->unode.opr.op[1])) { + tmp = expr->unode.opr.op[1]; + toAdd = 0; + } + else { + char stmp[256]; + /* declare a temporary variable to store the result */ + if (expr->unode.opr.op[0]->type == CONST_INT_NODE) { + sprintf(stmp,"_i_tmp_%i",allocateTemp()); + gsl_int_decl_global(stmp); + } + else if (expr->unode.opr.op[0]->type == CONST_FLOAT_NODE) { + sprintf(stmp,"_f_tmp%i",allocateTemp()); + gsl_float_decl_global(stmp); + } + else if (expr->unode.opr.op[0]->type == CONST_PTR_NODE) { + sprintf(stmp,"_p_tmp%i",allocateTemp()); + gsl_ptr_decl_global(stmp); + } + else { + int type = gsl_type_of_var(expr->unode.opr.op[0]->vnamespace, expr->unode.opr.op[0]->str); + if (type == INSTR_FLOAT) { + sprintf(stmp,"_f_tmp_%i",allocateTemp()); + gsl_float_decl_global(stmp); + } + else if (type == INSTR_PTR) { + sprintf(stmp,"_p_tmp_%i",allocateTemp()); + gsl_ptr_decl_global(stmp); + } + else if (type == INSTR_INT) { + sprintf(stmp,"_i_tmp_%i",allocateTemp()); + gsl_int_decl_global(stmp); + } + else if (type == -1) { + fprintf(stderr, "ERROR: Line %d, Could not find variable '%s'\n", + expr->line_number, expr->unode.opr.op[0]->str); + exit(1); + } + else { /* type is a struct_id */ + sprintf(stmp,"_s_tmp_%i",allocateTemp()); + gsl_struct_decl_global_from_id(stmp,type); + } + } + tmp = new_var(stmp,expr->line_number); + + /* set the tmp to the value of "op1" */ + tmpcpy = nodeClone(tmp); + commit_node(new_set(tmp,expr->unode.opr.op[0]),0); + toAdd = 1; + + tmp = tmpcpy; + } + + /* add op2 to tmp */ +#ifdef VERBOSE + if (expr->unode.opr.nbOp == 2) + printf("%s %s %s\n", type, tmp->str, expr->unode.opr.op[toAdd]->str); + else + printf("%s %s\n", type, tmp->str); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, type, instr_id, expr->unode.opr.nbOp, expr->line_number); + tmpcpy = nodeClone(tmp); + commit_node(tmp,0); + if (expr->unode.opr.nbOp == 2) { + commit_node(expr->unode.opr.op[toAdd],1); + } + + /* redefine the ADD node now as the computed variable */ + nodeFreeInternals(expr); + *expr = *tmpcpy; + free(tmpcpy); + } /* }}} */ + + static NodeType *new_expr1(const char *name, int id, NodeType *expr1) + { /* {{{ */ + NodeType *add = new_op(name, id, 1); + add->unode.opr.op[0] = expr1; + return add; + } /* }}} */ + + static NodeType *new_expr2(const char *name, int id, NodeType *expr1, NodeType *expr2) + { /* {{{ */ + NodeType *add = new_op(name, id, 2); + add->unode.opr.op[0] = expr1; + add->unode.opr.op[1] = expr2; + return add; + } /* }}} */ + + /* ADD */ + static NodeType *new_add(NodeType *expr1, NodeType *expr2) { /* {{{ */ + return new_expr2("add", OPR_ADD, expr1, expr2); + } + static void precommit_add(NodeType *add) { + precommit_expr(add,"add",INSTR_ADD); + } /* }}} */ + + /* SUB */ + static NodeType *new_sub(NodeType *expr1, NodeType *expr2) { /* {{{ */ + return new_expr2("sub", OPR_SUB, expr1, expr2); + } + static void precommit_sub(NodeType *sub) { + precommit_expr(sub,"sub",INSTR_SUB); + } /* }}} */ + + /* NEG */ + static NodeType *new_neg(NodeType *expr) { /* {{{ */ + NodeType *zeroConst = NULL; + if (expr->type == CONST_INT_NODE) + zeroConst = new_constInt("0", currentGoomSL->num_lines); + else if (expr->type == CONST_FLOAT_NODE) + zeroConst = new_constFloat("0.0", currentGoomSL->num_lines); + else if (expr->type == CONST_PTR_NODE) { + fprintf(stderr, "ERROR: Line %d, Could not negate const pointer.\n", + currentGoomSL->num_lines); + exit(1); + } + else { + int type = gsl_type_of_var(expr->vnamespace, expr->str); + if (type == INSTR_FLOAT) + zeroConst = new_constFloat("0.0", currentGoomSL->num_lines); + else if (type == INSTR_PTR) { + fprintf(stderr, "ERROR: Line %d, Could not negate pointer.\n", + currentGoomSL->num_lines); + exit(1); + } + else if (type == INSTR_INT) + zeroConst = new_constInt("0", currentGoomSL->num_lines); + else if (type == -1) { + fprintf(stderr, "ERROR: Line %d, Could not find variable '%s'\n", + expr->line_number, expr->unode.opr.op[0]->str); + exit(1); + } + else { /* type is a struct_id */ + fprintf(stderr, "ERROR: Line %d, Could not negate struct '%s'\n", + expr->line_number, expr->str); + exit(1); + } + } + return new_expr2("sub", OPR_SUB, zeroConst, expr); + } + /* }}} */ + + /* MUL */ + static NodeType *new_mul(NodeType *expr1, NodeType *expr2) { /* {{{ */ + return new_expr2("mul", OPR_MUL, expr1, expr2); + } + static void precommit_mul(NodeType *mul) { + precommit_expr(mul,"mul",INSTR_MUL); + } /* }}} */ + + /* DIV */ + static NodeType *new_div(NodeType *expr1, NodeType *expr2) { /* {{{ */ + return new_expr2("div", OPR_DIV, expr1, expr2); + } + static void precommit_div(NodeType *mul) { + precommit_expr(mul,"div",INSTR_DIV); + } /* }}} */ + + /* CALL EXPRESSION */ + static NodeType *new_call_expr(const char *name, NodeType *affect_list) { /* {{{ */ + NodeType *call = new_call(name,affect_list); + NodeType *node = new_expr1(name, OPR_CALL_EXPR, call); + node->vnamespace = gsl_find_namespace(name); + if (node->vnamespace == NULL) + fprintf(stderr, "ERROR: Line %d, No return type for: '%s'\n", currentGoomSL->num_lines, name); + return node; + } + static void precommit_call_expr(NodeType *call) { + char stmp[256]; + NodeType *tmp,*tmpcpy; + int type = gsl_type_of_var(call->vnamespace, call->str); + if (type == INSTR_FLOAT) { + sprintf(stmp,"_f_tmp_%i",allocateTemp()); + gsl_float_decl_global(stmp); + } + else if (type == INSTR_PTR) { + sprintf(stmp,"_p_tmp_%i",allocateTemp()); + gsl_ptr_decl_global(stmp); + } + else if (type == INSTR_INT) { + sprintf(stmp,"_i_tmp_%i",allocateTemp()); + gsl_int_decl_global(stmp); + } + else if (type == -1) { + fprintf(stderr, "ERROR: Line %d, Could not find variable '%s'\n", + call->line_number, call->str); + exit(1); + } + else { /* type is a struct_id */ + sprintf(stmp,"_s_tmp_%i",allocateTemp()); + gsl_struct_decl_global_from_id(stmp,type); + } + tmp = new_var(stmp,call->line_number); + commit_node(call->unode.opr.op[0],0); + tmpcpy = nodeClone(tmp); + commit_node(new_set(tmp,new_var(call->str,call->line_number)),0); + + nodeFreeInternals(call); + *call = *tmpcpy; + free(tmpcpy); + } /* }}} */ + + static void commit_test2(NodeType *set,const char *type, int instr) + { /* {{{ */ + NodeType *tmp; + char stmp[256]; + precommit_node(set->unode.opr.op[0]); + precommit_node(set->unode.opr.op[1]); + tmp = set->unode.opr.op[0]; + + stmp[0] = 0; + if (set->unode.opr.op[0]->type == CONST_INT_NODE) { + sprintf(stmp,"_i_tmp_%i",allocateTemp()); + gsl_int_decl_global(stmp); + } + else if (set->unode.opr.op[0]->type == CONST_FLOAT_NODE) { + sprintf(stmp,"_f_tmp%i",allocateTemp()); + gsl_float_decl_global(stmp); + } + else if (set->unode.opr.op[0]->type == CONST_PTR_NODE) { + sprintf(stmp,"_p_tmp%i",allocateTemp()); + gsl_ptr_decl_global(stmp); + } + if (stmp[0]) { + NodeType *tmpcpy; + tmp = new_var(stmp, set->line_number); + tmpcpy = nodeClone(tmp); + commit_node(new_set(tmp,set->unode.opr.op[0]),0); + tmp = tmpcpy; + } + +#ifdef VERBOSE + printf("%s %s %s\n", type, tmp->str, set->unode.opr.op[1]->str); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, type, instr, 2, set->line_number); + commit_node(tmp,instr!=INSTR_SET); + commit_node(set->unode.opr.op[1],1); + } /* }}} */ + + /* NOT */ + static NodeType *new_not(NodeType *expr1) { /* {{{ */ + return new_expr1("not", OPR_NOT, expr1); + } + static void commit_not(NodeType *set) + { + commit_node(set->unode.opr.op[0],0); +#ifdef VERBOSE + printf("not\n"); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "not", INSTR_NOT, 1, set->line_number); + gsl_instr_add_param(currentGoomSL->instr, "|dummy|", TYPE_LABEL); + } /* }}} */ + + /* EQU */ + static NodeType *new_equ(NodeType *expr1, NodeType *expr2) { /* {{{ */ + return new_expr2("isequal", OPR_EQU, expr1, expr2); + } + static void commit_equ(NodeType *mul) { + commit_test2(mul,"isequal",INSTR_ISEQUAL); + } /* }}} */ + + /* INF */ + static NodeType *new_low(NodeType *expr1, NodeType *expr2) { /* {{{ */ + return new_expr2("islower", OPR_LOW, expr1, expr2); + } + static void commit_low(NodeType *mul) { + commit_test2(mul,"islower",INSTR_ISLOWER); + } /* }}} */ + + /* WHILE */ + static NodeType *new_while(NodeType *expression, NodeType *instr) { /* {{{ */ + NodeType *node = new_op("while", OPR_WHILE, 2); + node->unode.opr.op[0] = expression; + node->unode.opr.op[1] = instr; + return node; + } + + static void commit_while(NodeType *node) + { + int lbl = allocateLabel(); + char start_while[1024], test_while[1024]; + sprintf(start_while, "|start_while_%d|", lbl); + sprintf(test_while, "|test_while_%d|", lbl); + + GSL_PUT_JUMP(test_while,node->line_number); + GSL_PUT_LABEL(start_while,node->line_number); + + /* code */ + commit_node(node->unode.opr.op[1],0); + + GSL_PUT_LABEL(test_while,node->line_number); + commit_node(node->unode.opr.op[0],0); + GSL_PUT_JNZERO(start_while,node->line_number); + } /* }}} */ + + /* FOR EACH */ + static NodeType *new_static_foreach(NodeType *var, NodeType *var_list, NodeType *instr) { /* {{{ */ + NodeType *node = new_op("for", OPR_FOREACH, 3); + node->unode.opr.op[0] = var; + node->unode.opr.op[1] = var_list; + node->unode.opr.op[2] = instr; + node->line_number = currentGoomSL->num_lines; + return node; + } + static void commit_foreach(NodeType *node) + { + NodeType *cur = node->unode.opr.op[1]; + char tmp_func[256], tmp_loop[256]; + int lbl = allocateLabel(); + sprintf(tmp_func, "|foreach_func_%d|", lbl); + sprintf(tmp_loop, "|foreach_loop_%d|", lbl); + + GSL_PUT_JUMP(tmp_loop, node->line_number); + GSL_PUT_LABEL(tmp_func, node->line_number); + + precommit_node(node->unode.opr.op[2]); + commit_node(node->unode.opr.op[2], 0); + + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "ret", INSTR_RET, 1, node->line_number); + gsl_instr_add_param(currentGoomSL->instr, "|dummy|", TYPE_LABEL); +#ifdef VERBOSE + printf("ret\n"); +#endif + + GSL_PUT_LABEL(tmp_loop, node->line_number); + + while (cur != NULL) + { + NodeType *x, *var; + + /* 1: x=var */ + x = nodeClone(node->unode.opr.op[0]); + var = nodeClone(cur->unode.opr.op[0]); + commit_node(new_set(x, var),0); + + /* 2: instr */ + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "call", INSTR_CALL, 1, node->line_number); + gsl_instr_add_param(currentGoomSL->instr, tmp_func, TYPE_LABEL); +#ifdef VERBOSE + printf("call %s\n", tmp_func); +#endif + + /* 3: var=x */ + x = nodeClone(node->unode.opr.op[0]); + var = cur->unode.opr.op[0]; + commit_node(new_set(var, x),0); + cur = cur->unode.opr.op[1]; + } + nodeFree(node->unode.opr.op[0]); + } /* }}} */ + + /* IF */ + static NodeType *new_if(NodeType *expression, NodeType *instr) { /* {{{ */ + NodeType *node = new_op("if", OPR_IF, 2); + node->unode.opr.op[0] = expression; + node->unode.opr.op[1] = instr; + return node; + } + static void commit_if(NodeType *node) { + + char slab[1024]; + sprintf(slab, "|eif%d|", allocateLabel()); + commit_node(node->unode.opr.op[0],0); + GSL_PUT_JZERO(slab,node->line_number); + /* code */ + commit_node(node->unode.opr.op[1],0); + GSL_PUT_LABEL(slab,node->line_number); + } /* }}} */ + + /* BLOCK */ + static NodeType *new_block(NodeType *lastNode) { /* {{{ */ + NodeType *blk = new_op("block", OPR_BLOCK, 2); + blk->unode.opr.op[0] = new_nop("start_of_block"); + blk->unode.opr.op[1] = lastNode; + return blk; + } + static void commit_block(NodeType *node) { + commit_node(node->unode.opr.op[0]->unode.opr.next,0); + } /* }}} */ + + /* FUNCTION INTRO */ + static NodeType *new_function_intro(const char *name) { /* {{{ */ + char stmp[256]; + if (strlen(name) < 200) { + sprintf(stmp, "|__func_%s|", name); + } + return new_op(stmp, OPR_FUNC_INTRO, 0); + } + static void commit_function_intro(NodeType *node) { + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "label", INSTR_LABEL, 1, node->line_number); + gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_LABEL); +#ifdef VERBOSE + printf("label %s\n", node->str); +#endif + } /* }}} */ + + /* FUNCTION OUTRO */ + static NodeType *new_function_outro() { /* {{{ */ + return new_op("ret", OPR_FUNC_OUTRO, 0); + } + static void commit_function_outro(NodeType *node) { + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "ret", INSTR_RET, 1, node->line_number); + gsl_instr_add_param(currentGoomSL->instr, "|dummy|", TYPE_LABEL); + releaseAllTemps(); +#ifdef VERBOSE + printf("ret\n"); +#endif + } /* }}} */ + + /* AFFECTATION LIST */ + static NodeType *new_affec_list(NodeType *set, NodeType *next) /* {{{ */ + { + NodeType *node = new_op("affect_list", OPR_AFFECT_LIST, 2); + node->unode.opr.op[0] = set; + node->unode.opr.op[1] = next; + return node; + } + static NodeType *new_affect_list_after(NodeType *affect_list) + { + NodeType *ret = NULL; + NodeType *cur = affect_list; + while(cur != NULL) { + NodeType *set = cur->unode.opr.op[0]; + NodeType *next = cur->unode.opr.op[1]; + NodeType *lvalue = set->unode.opr.op[0]; + NodeType *expression = set->unode.opr.op[1]; + if ((lvalue->str[0] == '&') && (expression->type == VAR_NODE)) { + NodeType *nset = new_set(nodeClone(expression), nodeClone(lvalue)); + ret = new_affec_list(nset, ret); + } + cur = next; + } + return ret; + } + static void commit_affect_list(NodeType *node) + { + NodeType *cur = node; + while(cur != NULL) { + NodeType *set = cur->unode.opr.op[0]; + precommit_node(set->unode.opr.op[0]); + precommit_node(set->unode.opr.op[1]); + cur = cur->unode.opr.op[1]; + } + cur = node; + while(cur != NULL) { + NodeType *set = cur->unode.opr.op[0]; + commit_node(set,0); + cur = cur->unode.opr.op[1]; + } + } /* }}} */ + + /* VAR LIST */ + static NodeType *new_var_list(NodeType *var, NodeType *next) /* {{{ */ + { + NodeType *node = new_op("var_list", OPR_VAR_LIST, 2); + node->unode.opr.op[0] = var; + node->unode.opr.op[1] = next; + return node; + } + static void commit_var_list(NodeType *node) + { + } /* }}} */ + + /* FUNCTION CALL */ + static NodeType *new_call(const char *name, NodeType *affect_list) { /* {{{ */ + HashValue *fval; + fval = goom_hash_get(currentGoomSL->functions, name); + if (!fval) { + gsl_declare_task(name); + fval = goom_hash_get(currentGoomSL->functions, name); + } + if (!fval) { + fprintf(stderr, "ERROR: Line %d, Could not find function %s\n", currentGoomSL->num_lines, name); + exit(1); + return NULL; + } + else { + ExternalFunctionStruct *gef = (ExternalFunctionStruct*)fval->ptr; + if (gef->is_extern) { + NodeType *node = new_op(name, OPR_EXT_CALL, 1); + node->unode.opr.op[0] = affect_list; + return node; + } + else { + NodeType *node; + char stmp[256]; + if (strlen(name) < 200) { + sprintf(stmp, "|__func_%s|", name); + } + node = new_op(stmp, OPR_CALL, 1); + node->unode.opr.op[0] = affect_list; + return node; + } + } + } + static void commit_ext_call(NodeType *node) { + NodeType *alafter = new_affect_list_after(node->unode.opr.op[0]); + commit_node(node->unode.opr.op[0],0); + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "extcall", INSTR_EXT_CALL, 1, node->line_number); + gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_VAR); +#ifdef VERBOSE + printf("extcall %s\n", node->str); +#endif + commit_node(alafter,0); + } + static void commit_call(NodeType *node) { + NodeType *alafter = new_affect_list_after(node->unode.opr.op[0]); + commit_node(node->unode.opr.op[0],0); + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "call", INSTR_CALL, 1, node->line_number); + gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_LABEL); +#ifdef VERBOSE + printf("call %s\n", node->str); +#endif + commit_node(alafter,0); + } /* }}} */ + + /** **/ + + static NodeType *rootNode = 0; /* TODO: reinitialiser a chaque compilation. */ + static NodeType *lastNode = 0; + static NodeType *gsl_append(NodeType *curNode) { + if (curNode == 0) return 0; /* {{{ */ + if (lastNode) + lastNode->unode.opr.next = curNode; + lastNode = curNode; + while(lastNode->unode.opr.next) lastNode = lastNode->unode.opr.next; + if (rootNode == 0) + rootNode = curNode; + return curNode; + } /* }}} */ + +#if 1 + int allocateTemp() { + return allocateLabel(); + } + void releaseAllTemps() {} + void releaseTemp(int n) {} +#else + static int nbTemp = 0; + static int *tempArray = 0; + static int tempArraySize = 0; + int allocateTemp() { /* TODO: allocateITemp, allocateFTemp */ + int i = 0; /* {{{ */ + if (tempArray == 0) { + tempArraySize = 256; + tempArray = (int*)malloc(tempArraySize * sizeof(int)); + } + while (1) { + int j; + for (j=0;jtype == OPR_NODE) + switch(node->unode.opr.type) { + case OPR_ADD: precommit_add(node); break; + case OPR_SUB: precommit_sub(node); break; + case OPR_MUL: precommit_mul(node); break; + case OPR_DIV: precommit_div(node); break; + case OPR_CALL_EXPR: precommit_call_expr(node); break; + } + } /* }}} */ + + void commit_node(NodeType *node, int releaseIfTmp) + { /* {{{ */ + if (node == 0) return; + + switch(node->type) { + case OPR_NODE: + switch(node->unode.opr.type) { + case OPR_SET: commit_set(node); break; + case OPR_PLUS_EQ: commit_plus_eq(node); break; + case OPR_SUB_EQ: commit_sub_eq(node); break; + case OPR_MUL_EQ: commit_mul_eq(node); break; + case OPR_DIV_EQ: commit_div_eq(node); break; + case OPR_IF: commit_if(node); break; + case OPR_WHILE: commit_while(node); break; + case OPR_BLOCK: commit_block(node); break; + case OPR_FUNC_INTRO: commit_function_intro(node); break; + case OPR_FUNC_OUTRO: commit_function_outro(node); break; + case OPR_CALL: commit_call(node); break; + case OPR_EXT_CALL: commit_ext_call(node); break; + case OPR_EQU: commit_equ(node); break; + case OPR_LOW: commit_low(node); break; + case OPR_NOT: commit_not(node); break; + case OPR_AFFECT_LIST: commit_affect_list(node); break; + case OPR_FOREACH: commit_foreach(node); break; + case OPR_VAR_LIST: commit_var_list(node); break; +#ifdef VERBOSE + case EMPTY_NODE: printf("NOP\n"); break; +#endif + } + + commit_node(node->unode.opr.next,0); /* recursive for the moment, maybe better to do something iterative? */ + break; + + case VAR_NODE: gsl_instr_set_namespace(currentGoomSL->instr, node->vnamespace); + gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_VAR); break; + case CONST_INT_NODE: gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_INTEGER); break; + case CONST_FLOAT_NODE: gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_FLOAT); break; + case CONST_PTR_NODE: gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_PTR); break; + } + if (releaseIfTmp && is_tmp_expr(node)) + releaseTemp(get_tmp_id(node)); + + nodeFree(node); + } /* }}} */ + + NodeType *nodeNew(const char *str, int type, int line_number) { + NodeType *node = (NodeType*)malloc(sizeof(NodeType)); /* {{{ */ + node->type = type; + node->str = (char*)malloc(strlen(str)+1); + node->vnamespace = NULL; + node->line_number = line_number; + strcpy(node->str, str); + return node; + } /* }}} */ + static NodeType *nodeClone(NodeType *node) { + NodeType *ret = nodeNew(node->str, node->type, node->line_number); /* {{{ */ + ret->vnamespace = node->vnamespace; + ret->unode = node->unode; + return ret; + } /* }}} */ + + void nodeFreeInternals(NodeType *node) { + free(node->str); /* {{{ */ + } /* }}} */ + + void nodeFree(NodeType *node) { + nodeFreeInternals(node); /* {{{ */ + free(node); + } /* }}} */ + + NodeType *new_constInt(const char *str, int line_number) { + NodeType *node = nodeNew(str, CONST_INT_NODE, line_number); /* {{{ */ + node->unode.constInt.val = atoi(str); + return node; + } /* }}} */ + + NodeType *new_constPtr(const char *str, int line_number) { + NodeType *node = nodeNew(str, CONST_PTR_NODE, line_number); /* {{{ */ + node->unode.constPtr.id = strtol(str,NULL,0); + return node; + } /* }}} */ + + NodeType *new_constFloat(const char *str, int line_number) { + NodeType *node = nodeNew(str, CONST_FLOAT_NODE, line_number); /* {{{ */ + node->unode.constFloat.val = atof(str); + return node; + } /* }}} */ + + NodeType *new_var(const char *str, int line_number) { + NodeType *node = nodeNew(str, VAR_NODE, line_number); /* {{{ */ + node->vnamespace = gsl_find_namespace(str); + if (node->vnamespace == 0) { + fprintf(stderr, "ERROR: Line %d, Variable not found: '%s'\n", line_number, str); + exit(1); + } + return node; + } /* }}} */ + + NodeType *new_nop(const char *str) { + NodeType *node = new_op(str, EMPTY_NODE, 0); /* {{{ */ + return node; + } /* }}} */ + + NodeType *new_op(const char *str, int type, int nbOp) { + int i; /* {{{ */ + NodeType *node = nodeNew(str, OPR_NODE, currentGoomSL->num_lines); + node->unode.opr.next = 0; + node->unode.opr.type = type; + node->unode.opr.nbOp = nbOp; + for (i=0;iunode.opr.op[i] = 0; + return node; + } /* }}} */ + + + void gsl_declare_global_variable(int type, char *name) { + switch(type){ + case -1: break; + case FLOAT_TK:gsl_float_decl_global(name);break; + case INT_TK: gsl_int_decl_global(name);break; + case PTR_TK: gsl_ptr_decl_global(name);break; + default: + { + int id = type - 1000; + gsl_struct_decl_global_from_id(name,id); + } + } + } + + + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 0 +#endif + +#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) +#line 1199 "goomsl_yacc.y" +typedef union YYSTYPE { + int intValue; + float floatValue; + char charValue; + char strValue[2048]; + NodeType *nPtr; + GoomHash *namespace; + GSL_Struct *gsl_struct; + GSL_StructField *gsl_struct_field; + } YYSTYPE; +/* Line 191 of yacc.c. */ +#line 1327 "goomsl_yacc.c" +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +# define YYSTYPE_IS_TRIVIAL 1 +#endif + + + +/* Copy the second part of user declarations. */ + + +/* Line 214 of yacc.c. */ +#line 1339 "goomsl_yacc.c" + +#if ! defined (yyoverflow) || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# if YYSTACK_USE_ALLOCA +# define YYSTACK_ALLOC alloca +# else +# ifndef YYSTACK_USE_ALLOCA +# if defined (alloca) || defined (_ALLOCA_H) +# define YYSTACK_ALLOC alloca +# else +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's `empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) +# else +# if defined (__STDC__) || defined (__cplusplus) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# endif +# define YYSTACK_ALLOC malloc +# define YYSTACK_FREE free +# endif +#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */ + + +#if (! defined (yyoverflow) \ + && (! defined (__cplusplus) \ + || (YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + short yyss; + YYSTYPE yyvs; + }; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (short) + sizeof (YYSTYPE)) \ + + YYSTACK_GAP_MAXIMUM) + +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + register YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (0) +# endif +# endif + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack, Stack, yysize); \ + Stack = &yyptr->Stack; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (0) + +#endif + +#if defined (__STDC__) || defined (__cplusplus) + typedef signed char yysigned_char; +#else + typedef short yysigned_char; +#endif + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 3 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 229 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 42 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 30 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 89 +/* YYNRULES -- Number of states. */ +#define YYNSTATES 217 + +/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 279 + +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +static const unsigned char yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 25, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 35, 36, 32, 29, 34, 30, 2, 31, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 33, 2, + 27, 26, 28, 37, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 40, 2, 41, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 38, 2, 39, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 +}; + +#if YYDEBUG +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ +static const unsigned short yyprhs[] = +{ + 0, 0, 3, 7, 10, 19, 30, 39, 50, 53, + 56, 57, 65, 68, 73, 76, 79, 82, 85, 87, + 89, 90, 93, 96, 99, 102, 104, 108, 111, 112, + 116, 122, 130, 131, 132, 137, 142, 147, 152, 154, + 157, 160, 163, 166, 169, 172, 179, 186, 193, 195, + 199, 203, 207, 211, 218, 222, 224, 227, 231, 232, + 234, 236, 240, 244, 248, 252, 255, 259, 261, 265, + 269, 273, 277, 281, 285, 288, 290, 292, 294, 298, + 304, 310, 318, 323, 330, 333, 335, 340, 344, 346 +}; + +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const yysigned_char yyrhs[] = +{ + 43, 0, -1, 44, 55, 52, -1, 44, 59, -1, + 44, 11, 27, 48, 28, 50, 25, 56, -1, 44, + 11, 27, 48, 33, 51, 28, 50, 25, 56, -1, + 44, 10, 27, 49, 28, 50, 25, 56, -1, 44, + 10, 27, 49, 33, 51, 28, 50, 25, 56, -1, + 44, 45, -1, 44, 25, -1, -1, 22, 27, 5, + 33, 46, 28, 25, -1, 71, 47, -1, 46, 34, + 71, 47, -1, 8, 5, -1, 9, 5, -1, 7, + 5, -1, 5, 5, -1, 5, -1, 5, -1, -1, + 33, 8, -1, 33, 9, -1, 33, 7, -1, 33, + 5, -1, 58, -1, 58, 34, 51, -1, 52, 53, + -1, -1, 54, 44, 55, -1, 27, 49, 28, 50, + 25, -1, 27, 49, 33, 51, 28, 50, 25, -1, + -1, -1, 9, 5, 26, 64, -1, 8, 5, 26, + 64, -1, 7, 5, 26, 64, -1, 5, 5, 26, + 64, -1, 58, -1, 9, 5, -1, 8, 5, -1, + 7, 5, -1, 5, 5, -1, 62, 25, -1, 57, + 25, -1, 35, 65, 36, 37, 71, 59, -1, 12, + 65, 71, 13, 71, 59, -1, 38, 25, 63, 44, + 39, 25, -1, 67, -1, 5, 15, 64, -1, 5, + 16, 64, -1, 5, 18, 64, -1, 5, 17, 64, + -1, 23, 5, 24, 60, 13, 59, -1, 35, 61, + 36, -1, 5, -1, 5, 61, -1, 5, 26, 64, + -1, -1, 5, -1, 66, -1, 64, 32, 64, -1, + 64, 31, 64, -1, 64, 29, 64, -1, 64, 30, + 64, -1, 30, 64, -1, 35, 64, 36, -1, 68, + -1, 64, 26, 64, -1, 64, 27, 64, -1, 64, + 28, 64, -1, 64, 19, 64, -1, 64, 20, 64, + -1, 64, 21, 64, -1, 14, 65, -1, 4, -1, + 3, -1, 6, -1, 49, 25, 56, -1, 49, 33, + 69, 25, 56, -1, 40, 49, 41, 25, 56, -1, + 40, 49, 33, 69, 41, 25, 56, -1, 40, 49, + 56, 41, -1, 40, 49, 33, 69, 41, 56, -1, + 70, 69, -1, 70, -1, 5, 26, 56, 64, -1, + 33, 56, 64, -1, 25, -1, -1 +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const unsigned short yyrline[] = +{ + 0, 1236, 1236, 1238, 1239, 1240, 1241, 1242, 1243, 1244, + 1245, 1250, 1253, 1254, 1257, 1258, 1259, 1260, 1265, 1267, + 1270, 1271, 1272, 1273, 1274, 1277, 1278, 1283, 1284, 1287, + 1289, 1291, 1294, 1296, 1300, 1301, 1302, 1303, 1304, 1307, + 1308, 1309, 1310, 1315, 1316, 1317, 1318, 1319, 1320, 1321, + 1322, 1323, 1324, 1325, 1328, 1330, 1331, 1334, 1336, 1339, + 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1350, 1351, + 1352, 1353, 1354, 1355, 1356, 1359, 1360, 1361, 1366, 1367, + 1368, 1369, 1373, 1374, 1377, 1378, 1380, 1384, 1393, 1393 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE +/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "LTYPE_INTEGER", "LTYPE_FLOAT", + "LTYPE_VAR", "LTYPE_PTR", "PTR_TK", "INT_TK", "FLOAT_TK", "DECLARE", + "EXTERNAL", "WHILE", "DO", "NOT", "PLUS_EQ", "SUB_EQ", "DIV_EQ", + "MUL_EQ", "SUP_EQ", "LOW_EQ", "NOT_EQ", "STRUCT", "FOR", "IN", "'\\n'", + "'='", "'<'", "'>'", "'+'", "'-'", "'/'", "'*'", "':'", "','", "'('", + "')'", "'?'", "'{'", "'}'", "'['", "']'", "$accept", "gsl", "gsl_code", + "struct_declaration", "struct_members", "struct_member", + "ext_task_name", "task_name", "return_type", "arglist", + "gsl_def_functions", "function", "function_intro", "function_outro", + "leave_namespace", "declaration", "empty_declaration", "instruction", + "var_list", "var_list_content", "affectation", "start_block", + "expression", "test", "constValue", "func_call", "func_call_expression", + "affectation_list", "affectation_in_list", "opt_nl", 0 +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to + token YYLEX-NUM. */ +static const unsigned short yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 10, 61, 60, 62, 43, + 45, 47, 42, 58, 44, 40, 41, 63, 123, 125, + 91, 93 +}; +# endif + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const unsigned char yyr1[] = +{ + 0, 42, 43, 44, 44, 44, 44, 44, 44, 44, + 44, 45, 46, 46, 47, 47, 47, 47, 48, 49, + 50, 50, 50, 50, 50, 51, 51, 52, 52, 53, + 54, 54, 55, 56, 57, 57, 57, 57, 57, 58, + 58, 58, 58, 59, 59, 59, 59, 59, 59, 59, + 59, 59, 59, 59, 60, 61, 61, 62, 63, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 65, 65, + 65, 65, 65, 65, 65, 66, 66, 66, 67, 67, + 67, 67, 68, 68, 69, 69, 70, 70, 71, 71 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const unsigned char yyr2[] = +{ + 0, 2, 3, 2, 8, 10, 8, 10, 2, 2, + 0, 7, 2, 4, 2, 2, 2, 2, 1, 1, + 0, 2, 2, 2, 2, 1, 3, 2, 0, 3, + 5, 7, 0, 0, 4, 4, 4, 4, 1, 2, + 2, 2, 2, 2, 2, 6, 6, 6, 1, 3, + 3, 3, 3, 6, 3, 1, 2, 3, 0, 1, + 1, 3, 3, 3, 3, 2, 3, 1, 3, 3, + 3, 3, 3, 3, 2, 1, 1, 1, 3, 5, + 5, 7, 4, 6, 2, 1, 4, 3, 1, 0 +}; + +/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state + STATE-NUM when YYTABLE doesn't specify something else to do. Zero + means the default is an error. */ +static const unsigned char yydefact[] = +{ + 10, 0, 32, 1, 19, 0, 0, 0, 0, 0, + 0, 0, 0, 9, 0, 0, 0, 8, 0, 28, + 0, 38, 3, 0, 48, 42, 0, 0, 0, 0, + 0, 41, 40, 39, 0, 0, 76, 75, 59, 77, + 0, 0, 0, 0, 0, 89, 60, 67, 0, 0, + 0, 58, 19, 0, 33, 0, 2, 44, 43, 0, + 49, 50, 52, 51, 57, 0, 0, 0, 0, 18, + 0, 74, 65, 0, 33, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 88, 0, 0, 0, 0, + 10, 0, 0, 78, 0, 33, 0, 85, 0, 27, + 10, 37, 36, 35, 34, 20, 0, 20, 0, 66, + 0, 0, 71, 72, 73, 68, 69, 70, 63, 64, + 62, 61, 89, 89, 0, 0, 89, 0, 0, 33, + 33, 0, 33, 84, 0, 32, 0, 0, 0, 0, + 0, 0, 0, 25, 0, 0, 0, 82, 0, 0, + 0, 55, 0, 0, 0, 0, 0, 80, 0, 87, + 79, 20, 0, 29, 24, 23, 21, 22, 33, 42, + 41, 40, 39, 20, 0, 33, 20, 33, 46, 0, + 89, 0, 0, 0, 0, 12, 56, 54, 53, 45, + 47, 33, 86, 0, 0, 6, 0, 26, 4, 0, + 83, 11, 0, 17, 16, 14, 15, 81, 30, 20, + 33, 33, 13, 0, 7, 5, 31 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const short yydefgoto[] = +{ + -1, 1, 2, 17, 149, 185, 70, 18, 137, 142, + 56, 99, 100, 19, 93, 20, 21, 22, 125, 152, + 23, 90, 44, 45, 46, 24, 47, 96, 97, 86 +}; + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +#define YYPACT_NINF -116 +static const short yypact[] = +{ + -116, 40, 136, -116, 103, 39, 66, 68, 61, 65, + 1, 77, 101, -116, 1, 84, 109, -116, 12, -116, + 91, -116, -116, 97, -116, 98, 72, 72, 72, 72, + 72, 99, 104, 113, 109, 130, -116, -116, -116, -116, + 1, 72, 72, 109, 166, 115, -116, -116, 145, 131, + 118, -116, -116, -24, -116, -3, 138, -116, -116, 72, + 159, 159, 159, 159, 159, 72, 72, 72, 14, -116, + 51, -116, 22, 102, 124, 72, 72, 72, 72, 72, + 72, 72, 72, 72, 72, -116, 160, 139, 140, 141, + -116, -3, 152, -116, 154, -116, 156, -3, 109, -116, + -116, 159, 159, 159, 159, 150, 82, 150, 82, -116, + -3, 158, 159, 159, 159, 159, 159, 159, 22, 22, + -116, -116, 115, 115, 195, 188, 115, 88, 162, -116, + -116, 72, -116, -116, 52, 136, 155, 177, 199, 200, + 201, 202, 180, 175, 185, 183, 171, -116, 144, 18, + 161, 195, 178, 144, 144, 190, 191, -116, 72, 159, + -116, 150, 82, -116, -116, -116, -116, -116, -116, -116, + -116, -116, -116, 150, 82, -116, 150, -116, -116, 192, + 115, 208, 213, 214, 215, -116, -116, -116, -116, -116, + -116, -116, 159, 196, 194, -116, 198, -116, -116, 203, + -116, -116, 161, -116, -116, -116, -116, -116, -116, 150, + -116, -116, -116, 204, -116, -116, -116 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yysigned_char yypgoto[] = +{ + -116, -116, -68, -116, -116, 23, -116, -15, -104, -92, + -116, -116, -116, 89, -74, -116, -88, -115, -116, 75, + -116, -116, -16, -6, -116, -116, -116, -62, -116, -99 +}; + +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If zero, do what YYDEFACT says. + If YYTABLE_NINF, syntax error. */ +#define YYTABLE_NINF -1 +static const unsigned char yytable[] = +{ + 111, 53, 94, 144, 36, 37, 38, 39, 50, 91, + 60, 61, 62, 63, 64, 40, 145, 92, 143, 68, + 143, 131, 127, 148, 150, 72, 73, 154, 74, 128, + 95, 41, 135, 178, 71, 133, 42, 54, 188, 189, + 3, 43, 105, 101, 31, 55, 179, 106, 146, 102, + 103, 104, 180, 83, 84, 157, 158, 193, 160, 112, + 113, 114, 115, 116, 117, 118, 119, 120, 121, 196, + 194, 32, 199, 33, 143, 36, 37, 38, 39, 107, + 161, 202, 197, 134, 108, 162, 143, 138, 34, 139, + 140, 141, 35, 4, 195, 5, 6, 7, 8, 9, + 10, 198, 41, 200, 48, 213, 49, 42, 25, 51, + 11, 12, 43, 13, 52, 159, 57, 207, 26, 27, + 28, 29, 58, 14, 59, 65, 15, 155, 16, 30, + 66, 81, 82, 83, 84, 69, 214, 215, 109, 67, + 85, 4, 192, 5, 6, 7, 8, 9, 10, 4, + 87, 5, 6, 7, 89, 88, 10, 110, 11, 12, + 164, 13, 165, 166, 167, 98, 181, 12, 182, 183, + 184, 14, 123, 122, 15, 124, 16, 129, 126, 14, + 130, 132, 15, 136, 16, 75, 76, 77, 81, 82, + 83, 84, 78, 79, 80, 81, 82, 83, 84, 147, + 151, 153, 168, 156, 169, 170, 171, 172, 173, 174, + 175, 176, 177, 203, 187, 190, 191, 201, 204, 205, + 206, 208, 209, 210, 163, 212, 186, 0, 211, 216 +}; + +static const short yycheck[] = +{ + 74, 16, 5, 107, 3, 4, 5, 6, 14, 33, + 26, 27, 28, 29, 30, 14, 108, 41, 106, 34, + 108, 95, 90, 122, 123, 41, 42, 126, 43, 91, + 33, 30, 100, 148, 40, 97, 35, 25, 153, 154, + 0, 40, 28, 59, 5, 33, 28, 33, 110, 65, + 66, 67, 34, 31, 32, 129, 130, 161, 132, 75, + 76, 77, 78, 79, 80, 81, 82, 83, 84, 173, + 162, 5, 176, 5, 162, 3, 4, 5, 6, 28, + 28, 180, 174, 98, 33, 33, 174, 5, 27, 7, + 8, 9, 27, 5, 168, 7, 8, 9, 10, 11, + 12, 175, 30, 177, 27, 209, 5, 35, 5, 25, + 22, 23, 40, 25, 5, 131, 25, 191, 15, 16, + 17, 18, 25, 35, 26, 26, 38, 39, 40, 26, + 26, 29, 30, 31, 32, 5, 210, 211, 36, 26, + 25, 5, 158, 7, 8, 9, 10, 11, 12, 5, + 5, 7, 8, 9, 36, 24, 12, 33, 22, 23, + 5, 25, 7, 8, 9, 27, 5, 23, 7, 8, + 9, 35, 33, 13, 38, 35, 40, 25, 37, 35, + 26, 25, 38, 33, 40, 19, 20, 21, 29, 30, + 31, 32, 26, 27, 28, 29, 30, 31, 32, 41, + 5, 13, 25, 41, 5, 5, 5, 5, 28, 34, + 25, 28, 41, 5, 36, 25, 25, 25, 5, 5, + 5, 25, 28, 25, 135, 202, 151, -1, 25, 25 +}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const unsigned char yystos[] = +{ + 0, 43, 44, 0, 5, 7, 8, 9, 10, 11, + 12, 22, 23, 25, 35, 38, 40, 45, 49, 55, + 57, 58, 59, 62, 67, 5, 15, 16, 17, 18, + 26, 5, 5, 5, 27, 27, 3, 4, 5, 6, + 14, 30, 35, 40, 64, 65, 66, 68, 27, 5, + 65, 25, 5, 49, 25, 33, 52, 25, 25, 26, + 64, 64, 64, 64, 64, 26, 26, 26, 49, 5, + 48, 65, 64, 64, 49, 19, 20, 21, 26, 27, + 28, 29, 30, 31, 32, 25, 71, 5, 24, 36, + 63, 33, 41, 56, 5, 33, 69, 70, 27, 53, + 54, 64, 64, 64, 64, 28, 33, 28, 33, 36, + 33, 56, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 13, 33, 35, 60, 37, 44, 69, 25, + 26, 56, 25, 69, 49, 44, 33, 50, 5, 7, + 8, 9, 51, 58, 50, 51, 69, 41, 71, 46, + 71, 5, 61, 13, 71, 39, 41, 56, 56, 64, + 56, 28, 33, 55, 5, 7, 8, 9, 25, 5, + 5, 5, 5, 28, 34, 25, 28, 41, 59, 28, + 34, 5, 7, 8, 9, 47, 61, 36, 59, 59, + 25, 25, 64, 50, 51, 56, 50, 51, 56, 50, + 56, 25, 71, 5, 5, 5, 5, 56, 25, 28, + 25, 25, 47, 50, 56, 56, 25 +}; + +#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) +# define YYSIZE_T __SIZE_TYPE__ +#endif +#if ! defined (YYSIZE_T) && defined (size_t) +# define YYSIZE_T size_t +#endif +#if ! defined (YYSIZE_T) +# if defined (__STDC__) || defined (__cplusplus) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# endif +#endif +#if ! defined (YYSIZE_T) +# define YYSIZE_T unsigned int +#endif + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrlab1 + + +/* Like YYERROR except do call yyerror. This remains here temporarily + to ease the transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. */ + +#define YYFAIL goto yyerrlab + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + yytoken = YYTRANSLATE (yychar); \ + YYPOPSTACK; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror ("syntax error: cannot back up");\ + YYERROR; \ + } \ +while (0) + +#define YYTERROR 1 +#define YYERRCODE 256 + +/* YYLLOC_DEFAULT -- Compute the default location (before the actions + are run). */ + +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + Current.first_line = Rhs[1].first_line; \ + Current.first_column = Rhs[1].first_column; \ + Current.last_line = Rhs[N].last_line; \ + Current.last_column = Rhs[N].last_column; +#endif + +/* YYLEX -- calling `yylex' with the right arguments. */ + +#ifdef YYLEX_PARAM +# define YYLEX yylex (YYLEX_PARAM) +#else +# define YYLEX yylex () +#endif + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) + +# define YYDSYMPRINT(Args) \ +do { \ + if (yydebug) \ + yysymprint Args; \ +} while (0) + +# define YYDSYMPRINTF(Title, Token, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yysymprint (stderr, \ + Token, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (0) + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (cinluded). | +`------------------------------------------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yy_stack_print (short *bottom, short *top) +#else +static void +yy_stack_print (bottom, top) + short *bottom; + short *top; +#endif +{ + YYFPRINTF (stderr, "Stack now"); + for (/* Nothing. */; bottom <= top; ++bottom) + YYFPRINTF (stderr, " %d", *bottom); + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (0) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yy_reduce_print (int yyrule) +#else +static void +yy_reduce_print (yyrule) + int yyrule; +#endif +{ + int yyi; + unsigned int yylineno = yyrline[yyrule]; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ", + yyrule - 1, yylineno); + /* Print the symbols being reduced, and their result. */ + for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) + YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]); + YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]); +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (Rule); \ +} while (0) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YYDSYMPRINT(Args) +# define YYDSYMPRINTF(Title, Token, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#if YYMAXDEPTH == 0 +# undef YYMAXDEPTH +#endif + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined (__GLIBC__) && defined (_STRING_H) +# define yystrlen strlen +# else +/* Return the length of YYSTR. */ +static YYSIZE_T +# if defined (__STDC__) || defined (__cplusplus) +yystrlen (const char *yystr) +# else +yystrlen (yystr) + const char *yystr; +# endif +{ + register const char *yys = yystr; + + while (*yys++ != '\0') + continue; + + return yys - yystr - 1; +} +# endif +# endif + +# ifndef yystpcpy +# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +static char * +# if defined (__STDC__) || defined (__cplusplus) +yystpcpy (char *yydest, const char *yysrc) +# else +yystpcpy (yydest, yysrc) + char *yydest; + const char *yysrc; +# endif +{ + register char *yyd = yydest; + register const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +#endif /* !YYERROR_VERBOSE */ + + + +#if YYDEBUG +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep) +#else +static void +yysymprint (yyoutput, yytype, yyvaluep) + FILE *yyoutput; + int yytype; + YYSTYPE *yyvaluep; +#endif +{ + /* Pacify ``unused variable'' warnings. */ + (void) yyvaluep; + + if (yytype < YYNTOKENS) + { + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); +# ifdef YYPRINT + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# endif + } + else + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + + switch (yytype) + { + default: + break; + } + YYFPRINTF (yyoutput, ")"); +} + +#endif /* ! YYDEBUG */ +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yydestruct (int yytype, YYSTYPE *yyvaluep) +#else +static void +yydestruct (yytype, yyvaluep) + int yytype; + YYSTYPE *yyvaluep; +#endif +{ + /* Pacify ``unused variable'' warnings. */ + (void) yyvaluep; + + switch (yytype) + { + + default: + break; + } +} + + +/* Prevent warnings from -Wmissing-prototypes. */ + +#ifdef YYPARSE_PARAM +# if defined (__STDC__) || defined (__cplusplus) +int yyparse (void *YYPARSE_PARAM); +# else +int yyparse (); +# endif +#else /* ! YYPARSE_PARAM */ +#if defined (__STDC__) || defined (__cplusplus) +int yyparse (void); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + + + +/* The lookahead symbol. */ +int yychar; + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; + +/* Number of syntax errors so far. */ +int yynerrs; + + + +/*----------. +| yyparse. | +`----------*/ + +#ifdef YYPARSE_PARAM +# if defined (__STDC__) || defined (__cplusplus) +int yyparse (void *YYPARSE_PARAM) +# else +int yyparse (YYPARSE_PARAM) + void *YYPARSE_PARAM; +# endif +#else /* ! YYPARSE_PARAM */ +#if defined (__STDC__) || defined (__cplusplus) +int +yyparse (void) +#else +int +yyparse () + +#endif +#endif +{ + + register int yystate; + register int yyn; + int yyresult; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + /* Lookahead token as an internal (translated) token number. */ + int yytoken = 0; + + /* Three stacks and their tools: + `yyss': related to states, + `yyvs': related to semantic values, + `yyls': related to locations. + + Refer to the stacks thru separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + short yyssa[YYINITDEPTH]; + short *yyss = yyssa; + register short *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs = yyvsa; + register YYSTYPE *yyvsp; + + + +#define YYPOPSTACK (yyvsp--, yyssp--) + + YYSIZE_T yystacksize = YYINITDEPTH; + + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + + + /* When reducing, the number of symbols on the RHS of the reduced + rule. */ + int yylen; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + + yyssp = yyss; + yyvsp = yyvs; + + goto yysetstate; + +/*------------------------------------------------------------. +| yynewstate -- Push a new state, which is found in yystate. | +`------------------------------------------------------------*/ + yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. so pushing a state here evens the stacks. + */ + yyssp++; + + yysetstate: + *yyssp = yystate; + + if (yyss + yystacksize - 1 <= yyssp) + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; + +#ifdef yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + short *yyss1 = yyss; + + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow ("parser stack overflow", + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + + &yystacksize); + + yyss = yyss1; + yyvs = yyvs1; + } +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyoverflowlab; +# else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyoverflowlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + short *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyoverflowlab; + YYSTACK_RELOCATE (yyss); + YYSTACK_RELOCATE (yyvs); + +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif +#endif /* no yyoverflow */ + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + + + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + + goto yybackup; + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + +/* Do appropriate processing given the current state. */ +/* Read a lookahead token if we need one and don't already have one. */ +/* yyresume: */ + + /* First try to decide what to do without reference to lookahead token. */ + + yyn = yypact[yystate]; + if (yyn == YYPACT_NINF) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yyn == 0 || yyn == YYTABLE_NINF) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + if (yyn == YYFINAL) + YYACCEPT; + + /* Shift the lookahead token. */ + YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken])); + + /* Discard the token being shifted unless it is eof. */ + if (yychar != YYEOF) + yychar = YYEMPTY; + + *++yyvsp = yylval; + + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + yystate = yyn; + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- Do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 3: +#line 1238 "goomsl_yacc.y" + { gsl_append(yyvsp[0].nPtr); } + break; + + case 4: +#line 1239 "goomsl_yacc.y" + { gsl_declare_global_variable(yyvsp[-2].intValue,yyvsp[-4].strValue); } + break; + + case 5: +#line 1240 "goomsl_yacc.y" + { gsl_declare_global_variable(yyvsp[-2].intValue,yyvsp[-6].strValue); } + break; + + case 6: +#line 1241 "goomsl_yacc.y" + { gsl_declare_global_variable(yyvsp[-2].intValue,yyvsp[-4].strValue); } + break; + + case 7: +#line 1242 "goomsl_yacc.y" + { gsl_declare_global_variable(yyvsp[-2].intValue,yyvsp[-6].strValue); } + break; + + case 11: +#line 1250 "goomsl_yacc.y" + { gsl_add_struct(yyvsp[-4].strValue, yyvsp[-2].gsl_struct); } + break; + + case 12: +#line 1253 "goomsl_yacc.y" + { yyval.gsl_struct = gsl_new_struct(yyvsp[0].gsl_struct_field); } + break; + + case 13: +#line 1254 "goomsl_yacc.y" + { yyval.gsl_struct = yyvsp[-3].gsl_struct; gsl_add_struct_field(yyvsp[-3].gsl_struct, yyvsp[0].gsl_struct_field); } + break; + + case 14: +#line 1257 "goomsl_yacc.y" + { yyval.gsl_struct_field = gsl_new_struct_field(yyvsp[0].strValue, INSTR_INT); } + break; + + case 15: +#line 1258 "goomsl_yacc.y" + { yyval.gsl_struct_field = gsl_new_struct_field(yyvsp[0].strValue, INSTR_FLOAT); } + break; + + case 16: +#line 1259 "goomsl_yacc.y" + { yyval.gsl_struct_field = gsl_new_struct_field(yyvsp[0].strValue, INSTR_PTR); } + break; + + case 17: +#line 1260 "goomsl_yacc.y" + { yyval.gsl_struct_field = gsl_new_struct_field_struct(yyvsp[0].strValue, yyvsp[-1].strValue); } + break; + + case 18: +#line 1265 "goomsl_yacc.y" + { gsl_declare_external_task(yyvsp[0].strValue); gsl_enternamespace(yyvsp[0].strValue); strcpy(yyval.strValue,yyvsp[0].strValue); } + break; + + case 19: +#line 1267 "goomsl_yacc.y" + { gsl_declare_task(yyvsp[0].strValue); gsl_enternamespace(yyvsp[0].strValue); strcpy(yyval.strValue,yyvsp[0].strValue); strcpy(yyval.strValue,yyvsp[0].strValue); } + break; + + case 20: +#line 1270 "goomsl_yacc.y" + { yyval.intValue=-1; } + break; + + case 21: +#line 1271 "goomsl_yacc.y" + { yyval.intValue=INT_TK; } + break; + + case 22: +#line 1272 "goomsl_yacc.y" + { yyval.intValue=FLOAT_TK; } + break; + + case 23: +#line 1273 "goomsl_yacc.y" + { yyval.intValue=PTR_TK; } + break; + + case 24: +#line 1274 "goomsl_yacc.y" + { yyval.intValue= 1000 + gsl_get_struct_id(yyvsp[0].strValue); } + break; + + case 29: +#line 1287 "goomsl_yacc.y" + { gsl_leavenamespace(); } + break; + + case 30: +#line 1289 "goomsl_yacc.y" + { gsl_append(new_function_intro(yyvsp[-3].strValue)); + gsl_declare_global_variable(yyvsp[-1].intValue,yyvsp[-3].strValue); } + break; + + case 31: +#line 1291 "goomsl_yacc.y" + { gsl_append(new_function_intro(yyvsp[-5].strValue)); + gsl_declare_global_variable(yyvsp[-1].intValue,yyvsp[-5].strValue); } + break; + + case 32: +#line 1294 "goomsl_yacc.y" + { gsl_append(new_function_outro()); } + break; + + case 33: +#line 1296 "goomsl_yacc.y" + { yyval.namespace = gsl_leavenamespace(); } + break; + + case 34: +#line 1300 "goomsl_yacc.y" + { gsl_float_decl_local(yyvsp[-2].strValue); yyval.nPtr = new_set(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines), yyvsp[0].nPtr); } + break; + + case 35: +#line 1301 "goomsl_yacc.y" + { gsl_int_decl_local(yyvsp[-2].strValue); yyval.nPtr = new_set(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines), yyvsp[0].nPtr); } + break; + + case 36: +#line 1302 "goomsl_yacc.y" + { gsl_ptr_decl_local(yyvsp[-2].strValue); yyval.nPtr = new_set(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines), yyvsp[0].nPtr); } + break; + + case 37: +#line 1303 "goomsl_yacc.y" + { gsl_struct_decl_local(yyvsp[-3].strValue,yyvsp[-2].strValue); yyval.nPtr = new_set(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines), yyvsp[0].nPtr); } + break; + + case 38: +#line 1304 "goomsl_yacc.y" + { yyval.nPtr = 0; } + break; + + case 39: +#line 1307 "goomsl_yacc.y" + { gsl_float_decl_local(yyvsp[0].strValue); } + break; + + case 40: +#line 1308 "goomsl_yacc.y" + { gsl_int_decl_local(yyvsp[0].strValue); } + break; + + case 41: +#line 1309 "goomsl_yacc.y" + { gsl_ptr_decl_local(yyvsp[0].strValue); } + break; + + case 42: +#line 1310 "goomsl_yacc.y" + { gsl_struct_decl_local(yyvsp[-1].strValue,yyvsp[0].strValue); } + break; + + case 43: +#line 1315 "goomsl_yacc.y" + { yyval.nPtr = yyvsp[-1].nPtr; } + break; + + case 44: +#line 1316 "goomsl_yacc.y" + { yyval.nPtr = yyvsp[-1].nPtr; } + break; + + case 45: +#line 1317 "goomsl_yacc.y" + { yyval.nPtr = new_if(yyvsp[-4].nPtr,yyvsp[0].nPtr); } + break; + + case 46: +#line 1318 "goomsl_yacc.y" + { yyval.nPtr = new_while(yyvsp[-4].nPtr,yyvsp[0].nPtr); } + break; + + case 47: +#line 1319 "goomsl_yacc.y" + { lastNode = yyvsp[-3].nPtr->unode.opr.op[1]; yyval.nPtr=yyvsp[-3].nPtr; } + break; + + case 48: +#line 1320 "goomsl_yacc.y" + { yyval.nPtr = yyvsp[0].nPtr; } + break; + + case 49: +#line 1321 "goomsl_yacc.y" + { yyval.nPtr = new_plus_eq(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines),yyvsp[0].nPtr); } + break; + + case 50: +#line 1322 "goomsl_yacc.y" + { yyval.nPtr = new_sub_eq(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines),yyvsp[0].nPtr); } + break; + + case 51: +#line 1323 "goomsl_yacc.y" + { yyval.nPtr = new_mul_eq(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines),yyvsp[0].nPtr); } + break; + + case 52: +#line 1324 "goomsl_yacc.y" + { yyval.nPtr = new_div_eq(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines),yyvsp[0].nPtr); } + break; + + case 53: +#line 1325 "goomsl_yacc.y" + { yyval.nPtr = new_static_foreach(new_var(yyvsp[-4].strValue, currentGoomSL->num_lines), yyvsp[-2].nPtr, yyvsp[0].nPtr); } + break; + + case 54: +#line 1328 "goomsl_yacc.y" + { yyval.nPtr = yyvsp[-1].nPtr; } + break; + + case 55: +#line 1330 "goomsl_yacc.y" + { yyval.nPtr = new_var_list(new_var(yyvsp[0].strValue,currentGoomSL->num_lines), NULL); } + break; + + case 56: +#line 1331 "goomsl_yacc.y" + { yyval.nPtr = new_var_list(new_var(yyvsp[-1].strValue,currentGoomSL->num_lines), yyvsp[0].nPtr); } + break; + + case 57: +#line 1334 "goomsl_yacc.y" + { yyval.nPtr = new_set(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines),yyvsp[0].nPtr); } + break; + + case 58: +#line 1336 "goomsl_yacc.y" + { yyval.nPtr = new_block(lastNode); lastNode = yyval.nPtr->unode.opr.op[0]; } + break; + + case 59: +#line 1339 "goomsl_yacc.y" + { yyval.nPtr = new_var(yyvsp[0].strValue,currentGoomSL->num_lines); } + break; + + case 60: +#line 1340 "goomsl_yacc.y" + { yyval.nPtr = yyvsp[0].nPtr; } + break; + + case 61: +#line 1341 "goomsl_yacc.y" + { yyval.nPtr = new_mul(yyvsp[-2].nPtr,yyvsp[0].nPtr); } + break; + + case 62: +#line 1342 "goomsl_yacc.y" + { yyval.nPtr = new_div(yyvsp[-2].nPtr,yyvsp[0].nPtr); } + break; + + case 63: +#line 1343 "goomsl_yacc.y" + { yyval.nPtr = new_add(yyvsp[-2].nPtr,yyvsp[0].nPtr); } + break; + + case 64: +#line 1344 "goomsl_yacc.y" + { yyval.nPtr = new_sub(yyvsp[-2].nPtr,yyvsp[0].nPtr); } + break; + + case 65: +#line 1345 "goomsl_yacc.y" + { yyval.nPtr = new_neg(yyvsp[0].nPtr); } + break; + + case 66: +#line 1346 "goomsl_yacc.y" + { yyval.nPtr = yyvsp[-1].nPtr; } + break; + + case 67: +#line 1347 "goomsl_yacc.y" + { yyval.nPtr = yyvsp[0].nPtr; } + break; + + case 68: +#line 1350 "goomsl_yacc.y" + { yyval.nPtr = new_equ(yyvsp[-2].nPtr,yyvsp[0].nPtr); } + break; + + case 69: +#line 1351 "goomsl_yacc.y" + { yyval.nPtr = new_low(yyvsp[-2].nPtr,yyvsp[0].nPtr); } + break; + + case 70: +#line 1352 "goomsl_yacc.y" + { yyval.nPtr = new_low(yyvsp[0].nPtr,yyvsp[-2].nPtr); } + break; + + case 71: +#line 1353 "goomsl_yacc.y" + { yyval.nPtr = new_not(new_low(yyvsp[-2].nPtr,yyvsp[0].nPtr)); } + break; + + case 72: +#line 1354 "goomsl_yacc.y" + { yyval.nPtr = new_not(new_low(yyvsp[0].nPtr,yyvsp[-2].nPtr)); } + break; + + case 73: +#line 1355 "goomsl_yacc.y" + { yyval.nPtr = new_not(new_equ(yyvsp[-2].nPtr,yyvsp[0].nPtr)); } + break; + + case 74: +#line 1356 "goomsl_yacc.y" + { yyval.nPtr = new_not(yyvsp[0].nPtr); } + break; + + case 75: +#line 1359 "goomsl_yacc.y" + { yyval.nPtr = new_constFloat(yyvsp[0].strValue,currentGoomSL->num_lines); } + break; + + case 76: +#line 1360 "goomsl_yacc.y" + { yyval.nPtr = new_constInt(yyvsp[0].strValue,currentGoomSL->num_lines); } + break; + + case 77: +#line 1361 "goomsl_yacc.y" + { yyval.nPtr = new_constPtr(yyvsp[0].strValue,currentGoomSL->num_lines); } + break; + + case 78: +#line 1366 "goomsl_yacc.y" + { yyval.nPtr = new_call(yyvsp[-2].strValue,NULL); } + break; + + case 79: +#line 1367 "goomsl_yacc.y" + { yyval.nPtr = new_call(yyvsp[-4].strValue,yyvsp[-2].nPtr); } + break; + + case 80: +#line 1368 "goomsl_yacc.y" + { yyval.nPtr = new_call(yyvsp[-3].strValue,NULL); } + break; + + case 81: +#line 1369 "goomsl_yacc.y" + { yyval.nPtr = new_call(yyvsp[-5].strValue,yyvsp[-3].nPtr); } + break; + + case 82: +#line 1373 "goomsl_yacc.y" + { yyval.nPtr = new_call_expr(yyvsp[-2].strValue,NULL); } + break; + + case 83: +#line 1374 "goomsl_yacc.y" + { yyval.nPtr = new_call_expr(yyvsp[-4].strValue,yyvsp[-2].nPtr); } + break; + + case 84: +#line 1377 "goomsl_yacc.y" + { yyval.nPtr = new_affec_list(yyvsp[-1].nPtr,yyvsp[0].nPtr); } + break; + + case 85: +#line 1378 "goomsl_yacc.y" + { yyval.nPtr = new_affec_list(yyvsp[0].nPtr,NULL); } + break; + + case 86: +#line 1380 "goomsl_yacc.y" + { + gsl_reenternamespace(yyvsp[-1].namespace); + yyval.nPtr = new_set(new_var(yyvsp[-3].strValue,currentGoomSL->num_lines),yyvsp[0].nPtr); + } + break; + + case 87: +#line 1384 "goomsl_yacc.y" + { + gsl_reenternamespace(yyvsp[-1].namespace); + yyval.nPtr = new_set(new_var("&this", currentGoomSL->num_lines),yyvsp[0].nPtr); + } + break; + + + } + +/* Line 999 of yacc.c. */ +#line 2792 "goomsl_yacc.c" + + yyvsp -= yylen; + yyssp -= yylen; + + + YY_STACK_PRINT (yyss, yyssp); + + *++yyvsp = yyval; + + + /* Now `shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; + + goto yynewstate; + + +/*------------------------------------. +| yyerrlab -- here on detecting error | +`------------------------------------*/ +yyerrlab: + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +#if YYERROR_VERBOSE + yyn = yypact[yystate]; + + if (YYPACT_NINF < yyn && yyn < YYLAST) + { + YYSIZE_T yysize = 0; + int yytype = YYTRANSLATE (yychar); + char *yymsg; + int yyx, yycount; + + yycount = 0; + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + for (yyx = yyn < 0 ? -yyn : 0; + yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + yysize += yystrlen (yytname[yyx]) + 15, yycount++; + yysize += yystrlen ("syntax error, unexpected ") + 1; + yysize += yystrlen (yytname[yytype]); + yymsg = (char *) YYSTACK_ALLOC (yysize); + if (yymsg != 0) + { + char *yyp = yystpcpy (yymsg, "syntax error, unexpected "); + yyp = yystpcpy (yyp, yytname[yytype]); + + if (yycount < 5) + { + yycount = 0; + for (yyx = yyn < 0 ? -yyn : 0; + yyx < (int) (sizeof (yytname) / sizeof (char *)); + yyx++) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + { + const char *yyq = ! yycount ? ", expecting " : " or "; + yyp = yystpcpy (yyp, yyq); + yyp = yystpcpy (yyp, yytname[yyx]); + yycount++; + } + } + yyerror (yymsg); + YYSTACK_FREE (yymsg); + } + else + yyerror ("syntax error; also virtual memory exhausted"); + } + else +#endif /* YYERROR_VERBOSE */ + yyerror ("syntax error"); + } + + + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + /* Return failure if at end of input. */ + if (yychar == YYEOF) + { + /* Pop the error token. */ + YYPOPSTACK; + /* Pop the rest of the stack. */ + while (yyss < yyssp) + { + YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); + yydestruct (yystos[*yyssp], yyvsp); + YYPOPSTACK; + } + YYABORT; + } + + YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc); + yydestruct (yytoken, &yylval); + yychar = YYEMPTY; + + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*----------------------------------------------------. +| yyerrlab1 -- error raised explicitly by an action. | +`----------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (yyn != YYPACT_NINF) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); + yydestruct (yystos[yystate], yyvsp); + yyvsp--; + yystate = *--yyssp; + + YY_STACK_PRINT (yyss, yyssp); + } + + if (yyn == YYFINAL) + YYACCEPT; + + YYDPRINTF ((stderr, "Shifting error token, ")); + + *++yyvsp = yylval; + + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + +#ifndef yyoverflow +/*----------------------------------------------. +| yyoverflowlab -- parser overflow comes here. | +`----------------------------------------------*/ +yyoverflowlab: + yyerror ("parser stack overflow"); + yyresult = 2; + /* Fall through. */ +#endif + +yyreturn: +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif + return yyresult; +} + + +#line 1396 "goomsl_yacc.y" + + + +void yyerror(char *str) +{ /* {{{ */ + fprintf(stderr, "ERROR: Line %d, %s\n", currentGoomSL->num_lines, str); + currentGoomSL->compilationOK = 0; + exit(1); +} /* }}} */ + + diff --git a/src/post/goom/mmx.c b/src/post/goom/mmx.c index 953b59152..3c9d0ee4a 100644 --- a/src/post/goom/mmx.c +++ b/src/post/goom/mmx.c @@ -16,11 +16,9 @@ // faire : a / sqrtperte <=> a >> PERTEDEC #define PERTEDEC 4 -#ifdef CPU_X86 int mmx_supported (void) { return (mm_support()&0x1); } -#endif void zoom_filter_mmx (int prevX, int prevY, Pixel *expix1, Pixel *expix2, diff --git a/src/post/goom/mmx.h b/src/post/goom/mmx.h index d422eac20..6861b7cfe 100644 --- a/src/post/goom/mmx.h +++ b/src/post/goom/mmx.h @@ -244,10 +244,8 @@ mmx_ok(void) return ( mm_support() & 0x1 ); } -#ifdef CPU_X86 int mmx_supported (void); int xmmx_supported (void); -#endif /* MMX optimized implementations */ diff --git a/src/post/goom/xmmx.c b/src/post/goom/xmmx.c index 2b9103a3e..6b76a86a3 100644 --- a/src/post/goom/xmmx.c +++ b/src/post/goom/xmmx.c @@ -23,7 +23,6 @@ /*#include "xmmx.h"*/ #include "goom_graphic.h" -#ifdef CPU_X86 int xmmx_supported (void) { #ifdef ARCH_X86_64 return 0; /* Haven't yet converted zoom_filter_xmmx @@ -32,7 +31,6 @@ int xmmx_supported (void) { return (mm_support()&0x8)>>3; #endif } -#endif void zoom_filter_xmmx (int prevX, int prevY, Pixel *expix1, Pixel *expix2, -- cgit v1.2.3 From 3da56be672f9512818066fe5cad66c8482a8f5da Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Thu, 17 Jan 2008 22:54:19 +0000 Subject: Force external ffmpeg usage (where it's new enough) when building .debs. --- debian/rules | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/rules b/debian/rules index afc201add..76b0a6c63 100755 --- a/debian/rules +++ b/debian/rules @@ -64,6 +64,7 @@ CONFIGURE_FLAGS := --prefix=/usr \ --with-external-a52dec \ --with-external-libdts \ --with-external-faad \ + --with-external-ffmpeg=soft \ --with-freetype \ --with-wavpack \ $(DEB_BUILD_CONFIG_OPTIONS) \ -- cgit v1.2.3 From 9c59211e1b6f6c41c5915a49e42737408ba7a680 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Sat, 19 Jan 2008 13:43:30 +0100 Subject: Be sure libmad has enough data. Fixed random glitches. --- src/libmad/xine_mad_decoder.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/libmad/xine_mad_decoder.c b/src/libmad/xine_mad_decoder.c index 2f6d7cfe3..be616be36 100644 --- a/src/libmad/xine_mad_decoder.c +++ b/src/libmad/xine_mad_decoder.c @@ -48,6 +48,20 @@ #define INPUT_BUF_SIZE 16384 +/* According to Rob Leslie (libmad author) : + * The absolute theoretical maximum frame size is 2881 bytes: MPEG 2.5 Layer II, + * 8000 Hz @ 160 kbps, with a padding slot. (Such a frame is unlikely, but it was + * a useful exercise to compute all possible frame sizes.) Add to this an 8 byte + * MAD_BUFFER_GUARD, and the minimum buffer size you should be streaming to + * libmad in the general case is 2889 bytes. + + * Theoretical frame sizes for Layer III range from 24 to 1441 bytes, but there + * is a "soft" limit imposed by the standard of 960 bytes. Nonetheless MAD can + * decode frames of any size as long as they fit entirely in the buffer you pass, + * not including the MAD_BUFFER_GUARD bytes. + */ +#define MAD_MIN_SIZE 2889 + typedef struct { audio_decoder_class_t decoder_class; } mad_class_t; @@ -136,8 +150,8 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { mad_decoder_t *this = (mad_decoder_t *) this_gen; - lprintf ("decode data, decoder_flags: %d\n", buf->decoder_flags); - + lprintf ("decode data, size: %d, decoder_flags: %d\n", buf->size, buf->decoder_flags); + if (buf->size>(INPUT_BUF_SIZE-this->bytes_in_buffer)) { xprintf (this->xstream->xine, XINE_VERBOSITY_DEBUG, "libmad: ALERT input buffer too small (%d bytes, %d avail)!\n", @@ -167,6 +181,9 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { mad_stream_buffer (&this->stream, this->buffer, this->bytes_in_buffer); + if (this->bytes_in_buffer < MAD_MIN_SIZE) + return; + while (1) { if (mad_frame_decode (&this->frame, &this->stream) != 0) { @@ -187,6 +204,7 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { return; default: + lprintf ("error 0x%04X, mad_stream_buffer %d bytes\n", this->stream.error, this->bytes_in_buffer); mad_stream_buffer (&this->stream, this->buffer, this->bytes_in_buffer); } -- cgit v1.2.3 From ce16be132cec33879e3f1521997aa30993d7fd93 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Sat, 19 Jan 2008 13:52:43 +0100 Subject: Initial support of free bitrate streams. --- src/demuxers/demux_mpgaudio.c | 284 ++++++++++++++++++++++++++++++------------ 1 file changed, 203 insertions(+), 81 deletions(-) diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c index 8e716f095..027c46c45 100644 --- a/src/demuxers/demux_mpgaudio.c +++ b/src/demuxers/demux_mpgaudio.c @@ -35,9 +35,9 @@ #define LOG_MODULE "demux_mpeg_audio" #define LOG_VERBOSE -/* + #define LOG -*/ + #include "xine_internal.h" #include "xineutils.h" #include "demux.h" @@ -52,7 +52,6 @@ */ #define NUM_PREVIEW_BUFFERS 2 -#define WRAP_THRESHOLD 120000 #define FOURCC_TAG BE_FOURCC #define RIFF_CHECK_BYTES 1024 @@ -77,16 +76,16 @@ /* mp3 frame struct */ typedef struct { /* header */ - double duration; - uint32_t size; /* in bytes */ + double duration; /* in milliseconds */ + uint32_t size; /* in bytes; including padding */ uint32_t bitrate; /* in bit per second */ uint16_t freq; /* in Hz */ - uint8_t layer; - uint8_t version_idx:2; /* 0: mpeg1, 1: mpeg2, 2: mpeg2.5 */ uint8_t lsf_bit:1; uint8_t channel_mode:3; + uint8_t padding:3; /* in bytes */ + uint8_t is_free_bitrate:1; } mpg_audio_frame_t; /* Xing Vbr Header struct */ @@ -125,7 +124,16 @@ typedef struct { int br; /* bitrate in bits/second */ uint32_t blocksize; + /* current mp3 frame */ mpg_audio_frame_t cur_frame; + + /* next mp3 frame, used when the frame size cannot be computed from the + * current frame header */ + mpg_audio_frame_t next_frame; + + /* reference mp3 frame, used for extra validation when sync is lost */ + mpg_audio_frame_t ref_frame; + double cur_time; /* in milliseconds */ off_t mpg_frame_start; /* offset */ @@ -135,7 +143,12 @@ typedef struct { int check_vbr_header; xing_header_t *xing_header; vbri_header_t *vbri_header; - + + int found_next_frame:1; + int has_ref_frame:1; + off_t free_bitrate_size; + uint8_t next_header[4]; + } demux_mpgaudio_t ; /* demuxer class struct */ @@ -206,14 +219,14 @@ static int parse_frame_header(mpg_audio_frame_t *const frame, const uint8_t *con const uint32_t head = _X_BE_32(buf); const uint16_t frame_sync = head >> 21; - lprintf("header: %08X\n", head); if (frame_sync != 0x7ff) { - lprintf("invalid frame sync\n"); + lprintf("invalid frame sync %08X\n", head); return 0; } + lprintf("header: %08X\n", head); frame_header.mpeg25_bit = (head >> 20) & 0x1; - frame->lsf_bit = (head >> 19) & 0x1; + frame->lsf_bit = (head >> 19) & 0x1; if (!frame_header.mpeg25_bit) { if (frame->lsf_bit) { lprintf("reserved mpeg25 lsf combination\n"); @@ -234,14 +247,14 @@ static int parse_frame_header(mpg_audio_frame_t *const frame, const uint8_t *con } frame_header.bitrate_idx = (head >> 12) & 0xf; - if ((frame_header.bitrate_idx == 0) || (frame_header.bitrate_idx == 15)) { - lprintf("invalid bitrate index\n"); + if (frame_header.bitrate_idx == 15) { + lprintf("invalid bitrate index: %d\n", frame_header.bitrate_idx); return 0; } frame_header.freq_idx = (head >> 10) & 0x3; if (frame_header.freq_idx == 3) { - lprintf("invalid frequence index\n"); + lprintf("invalid frequence index: %d\n", frame_header.freq_idx); return 0; } @@ -274,19 +287,27 @@ static int parse_frame_header(mpg_audio_frame_t *const frame, const uint8_t *con const uint16_t samples = mp3_samples[frame->version_idx][frame->layer - 1]; frame->bitrate = mp3_bitrates[frame->version_idx][frame->layer - 1][frame_header.bitrate_idx] * 1000; frame->freq = mp3_freqs[frame->version_idx][frame_header.freq_idx]; - - frame->size = samples * (frame->bitrate / 8); - frame->size /= frame->freq; - /* Padding: only if padding_bit is set; 4 bytes for Layer 1 and 1 byte for others */ - frame->size += ( frame_header.padding_bit ? ( frame->layer == 1 ? 4 : 1 ) : 0 ); - frame->duration = 1000.0f * (double)samples / (double)frame->freq; + frame->padding = ( frame_header.padding_bit ? ( frame->layer == 1 ? 4 : 1 ) : 0 ); + frame->channel_mode = frame_header.channel_mode; + + if (frame->bitrate > 0) { + frame->size = samples * (frame->bitrate / 8); + frame->size /= frame->freq; + /* Padding: only if padding_bit is set; 4 bytes for Layer 1 and 1 byte for others */ + frame->size += frame->padding; + } else { + /* Free bitrate frame, the size of the frame cannot be computed from the header. */ + frame->is_free_bitrate = 1; + frame->size = 0; + } } - lprintf("mpeg %d, layer %d\n", frame->version_idx + 1, frame->layer); - lprintf("bitrate: %d bps, samplerate: %d Hz\n", frame->bitrate, frame->freq); + lprintf("mpeg %d, layer %d, channel_mode: %d\n", frame->version_idx + 1, + frame->layer, frame->channel_mode); + lprintf("bitrate: %d bps, output freq: %d Hz\n", frame->bitrate, frame->freq); lprintf("length: %d bytes, %f ms\n", frame->size, frame->duration); - lprintf("padding: %d bytes\n", ( frame_header.padding_bit ? ( frame->layer == 1 ? 4 : 1 ) : 0 )); + lprintf("padding: %d bytes\n", frame->padding); return 1; } @@ -478,6 +499,25 @@ static vbri_header_t* parse_vbri_header(mpg_audio_frame_t *frame, } } +static int check_frame_validity(demux_mpgaudio_t *const this, mpg_audio_frame_t *const frame) { + int result = 0; + + if (this->ref_frame.is_free_bitrate) { + if ((frame->bitrate == 0) && + (this->ref_frame.freq == frame->freq) && + (this->ref_frame.version_idx == frame->version_idx) && + (this->ref_frame.channel_mode == frame->channel_mode)) { + result = 1; + } + } else { + if ((this->ref_frame.version_idx == frame->version_idx) && + (this->ref_frame.channel_mode == frame->channel_mode)) { + result = 1; + } + } + return result; +} + /* * Parse a mp3 frame paylod * return 1 on success, 0 on error @@ -488,9 +528,10 @@ static int parse_frame_payload(demux_mpgaudio_t *this, buf_element_t *buf; off_t frame_pos, len; uint64_t pts = 0; + int payload_size = 0; frame_pos = this->input->get_current_pos(this->input) - 4; - lprintf("frame_pos = %"PRId64"\n", frame_pos); + lprintf("frame_pos = %"PRId64", header: %08X\n", frame_pos, _X_BE_32(frame_header)); buf = this->audio_fifo->buffer_pool_alloc(this->audio_fifo); @@ -500,31 +541,93 @@ static int parse_frame_payload(demux_mpgaudio_t *this, buf->free_buffer(buf); return 0; } - + /* the decoder needs the frame header */ - memcpy(buf->mem, frame_header, 4); + if (!this->found_next_frame) { + memcpy(buf->content, frame_header, 4); + } - len = this->input->read(this->input, buf->mem + 4, this->cur_frame.size - 4); - if (len != (this->cur_frame.size - 4)) { - buf->free_buffer(buf); - return 0; + /* compute the payload size */ + if (this->cur_frame.size > 0) { + payload_size = this->cur_frame.size - 4; + } else if (this->free_bitrate_size > 0) { +// payload_size = this->free_bitrate_size + this->cur_frame.padding - 4; +// this->cur_frame.size = payload_size + 4; + payload_size = 0; + } else { + payload_size = 0; + } + + /* Read the payload data. */ + if (payload_size > 0) { + off_t len; + + /* If we know the payload size, it's easy */ + this->found_next_frame = 0; + len = this->input->read(this->input, buf->content + 4, payload_size); + if (len != payload_size) { + buf->free_buffer(buf); + return 0; + } + } else { + /* Search for the beginning of the next frame and deduce the size of the + * current frame from the position of the next one. */ + int payload_size = 0; + int max_size = buf->max_size - 4; + int header_size = 4 * !this->found_next_frame; + + while (payload_size < max_size) { + len = this->input->read(this->input, + &buf->content[header_size + payload_size], 1); + if (len != 1) { + lprintf("EOF\n"); + buf->free_buffer(buf); + return 0; + } + payload_size += len; + + if ((header_size + payload_size) >= 4) { + if (parse_frame_header(&this->next_frame, + &buf->content[header_size + payload_size - 4])) { + if (check_frame_validity(this, &this->next_frame)) { + lprintf("found next frame header\n"); + if (this->free_bitrate_size == 0) { + this->free_bitrate_size = payload_size - this->cur_frame.padding; + } + /* don't read the frame header twice */ + this->found_next_frame = 1; + memcpy(&this->next_header[0], &buf->content[header_size + payload_size], 4); + payload_size -= 4; + break; + } else { + lprintf("invalid frame\n"); + } + } + } + } + this->cur_frame.size = header_size + payload_size + 4; + if (this->br == 0) { + this->br = 8000 * this->cur_frame.size / this->cur_frame.duration; + } + this->cur_frame.bitrate = this->br; + lprintf("free bitrate: bitrate: %d, frame size: %d\n", this->br, this->cur_frame.size); + } if (this->check_vbr_header) { this->check_vbr_header = 0; this->mpg_frame_start = frame_pos; - this->xing_header = parse_xing_header(&this->cur_frame, buf->mem, this->cur_frame.size); + this->xing_header = parse_xing_header(&this->cur_frame, buf->content, this->cur_frame.size); if (this->xing_header) { buf->free_buffer(buf); return 1; } - this->vbri_header = parse_vbri_header(&this->cur_frame, buf->mem, this->cur_frame.size); + this->vbri_header = parse_vbri_header(&this->cur_frame, buf->content, this->cur_frame.size); if (this->vbri_header) { buf->free_buffer(buf); return 1; } } - pts = (int64_t)(this->cur_time * 90.0f); @@ -533,14 +636,13 @@ static int parse_frame_payload(demux_mpgaudio_t *this, buf->extra_info->input_time = this->cur_time; buf->pts = pts; - buf->size = len + 4; - buf->content = buf->mem; + buf->size = this->cur_frame.size; buf->type = BUF_AUDIO_MPEG; buf->decoder_info[0] = 1; buf->decoder_flags = decoder_flags|BUF_FLAG_FRAME_END; + lprintf("send buffer: size=%d, pts=%"PRId64"\n", buf->size, pts); this->audio_fifo->put(this->audio_fifo, buf); - lprintf("send buffer: pts=%"PRId64"\n", pts); this->cur_time += this->cur_frame.duration; return 1; } @@ -604,56 +706,74 @@ static int read_frame_header(demux_mpgaudio_t *this, uint8_t *header_buf, int by * Parse next mp3 frame */ static int demux_mpgaudio_next (demux_mpgaudio_t *this, int decoder_flags, int send_header) { - uint8_t header_buf[4]; - int bytes = 4; - - for (;;) { - - if (read_frame_header(this, header_buf, bytes)) { - - if (parse_frame_header(&this->cur_frame, header_buf)) { - - /* send header buffer */ - if ( send_header ) { - buf_element_t *buf; - - buf = this->audio_fifo->buffer_pool_alloc(this->audio_fifo); - - buf->type = BUF_AUDIO_MPEG; - buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_STDHEADER|BUF_FLAG_FRAME_END; - - buf->decoder_info[0] = 0; - buf->decoder_info[1] = this->cur_frame.freq; - buf->decoder_info[2] = 0; /* bits_per_sample */ - - /* Only for channel_mode == 3 (mono) there is one channel, for any other case, there are 2 */ - buf->decoder_info[3] = ( this->cur_frame.channel_mode == 3 ) ? 1 : 2; - - buf->size = 0; /* No extra header data */ - - this->audio_fifo->put(this->audio_fifo, buf); - } - - return parse_frame_payload(this, header_buf, decoder_flags); - - } else if ( id3v2_istag(header_buf) ) { - if (!id3v2_parse_tag(this->input, this->stream, header_buf)) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - LOG_MODULE ": ID3V2 tag parsing error\n"); - bytes = 1; /* resync */ + uint8_t buffer[4]; + uint8_t *header = buffer; + + if (this->found_next_frame) { + lprintf("skip header reading\n"); + header = this->next_header; + memcpy(&this->cur_frame, &this->next_frame, sizeof(mpg_audio_frame_t)); + } else { + int bytes = 4; + + for (;;) { + if (!read_frame_header(this, header, bytes)) + return 0; + if (parse_frame_header(&this->cur_frame, header)) { + if (!this->has_ref_frame) { + this->has_ref_frame = 1; + memcpy(&this->ref_frame, &this->cur_frame, sizeof(mpg_audio_frame_t)); + lprintf("ref frame saved\n"); } else { - bytes = 4; + if (!check_frame_validity(this, &this->cur_frame)) { + lprintf("invalid frame\n"); + bytes = 1; /* resync */ + continue; + } } + lprintf("frame found\n"); + break; } else { - /* skip */ - bytes = 1; + lprintf("loose sync\n"); + + if ( id3v2_istag(header) ) { + if (!id3v2_parse_tag(this->input, this->stream, header)) { + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + LOG_MODULE ": ID3V2 tag parsing error\n"); + bytes = 1; /* resync */ + } else { + bytes = 4; + } + } else { + /* skip */ + bytes = 1; + } } - - } else { - lprintf("read error\n"); - return 0; } } + + /* send header buffer */ + if ( send_header ) { + buf_element_t *buf; + + buf = this->audio_fifo->buffer_pool_alloc(this->audio_fifo); + + buf->type = BUF_AUDIO_MPEG; + buf->decoder_flags = BUF_FLAG_HEADER|BUF_FLAG_STDHEADER|BUF_FLAG_FRAME_END; + + buf->decoder_info[0] = 0; + buf->decoder_info[1] = this->cur_frame.freq; + buf->decoder_info[2] = 0; /* bits_per_sample */ + + /* Only for channel_mode == 3 (mono) there is one channel, for any other case, there are 2 */ + buf->decoder_info[3] = ( this->cur_frame.channel_mode == 3 ) ? 1 : 2; + + buf->size = 0; /* No extra header data */ + + this->audio_fifo->put(this->audio_fifo, buf); + } + + return parse_frame_payload(this, header, decoder_flags); } static int demux_mpgaudio_send_chunk (demux_plugin_t *this_gen) { @@ -779,6 +899,7 @@ static void demux_mpgaudio_send_headers (demux_plugin_t *this_gen) { */ this->check_vbr_header = 1; for (i = 0; i < NUM_PREVIEW_BUFFERS; i++) { + lprintf("preview buffer number %d / %d\n", i + 1, NUM_PREVIEW_BUFFERS); if (!demux_mpgaudio_next (this, BUF_FLAG_PREVIEW, i == 0)) { break; } @@ -965,7 +1086,8 @@ static int demux_mpgaudio_seek (demux_plugin_t *this_gen, /* assume seeking is always perfect... */ this->cur_time = start_time; this->input->seek (this->input, seek_pos, SEEK_SET); - + this->found_next_frame = 0; + if (playing) { _x_demux_flush_engine(this->stream); } -- cgit v1.2.3 From ead9fc9aabadff4ea507e442a272ca2847ec537d Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Sat, 19 Jan 2008 20:33:21 +0100 Subject: Cleanup. --- src/demuxers/demux_mpgaudio.c | 50 ++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c index 027c46c45..afd695d84 100644 --- a/src/demuxers/demux_mpgaudio.c +++ b/src/demuxers/demux_mpgaudio.c @@ -542,17 +542,14 @@ static int parse_frame_payload(demux_mpgaudio_t *this, return 0; } - /* the decoder needs the frame header */ - if (!this->found_next_frame) { - memcpy(buf->content, frame_header, 4); - } + memcpy(buf->content, frame_header, 4); /* compute the payload size */ if (this->cur_frame.size > 0) { payload_size = this->cur_frame.size - 4; } else if (this->free_bitrate_size > 0) { -// payload_size = this->free_bitrate_size + this->cur_frame.padding - 4; -// this->cur_frame.size = payload_size + 4; + payload_size = this->free_bitrate_size + this->cur_frame.padding - 4; + this->cur_frame.size = payload_size + 4; payload_size = 0; } else { payload_size = 0; @@ -574,11 +571,9 @@ static int parse_frame_payload(demux_mpgaudio_t *this, * current frame from the position of the next one. */ int payload_size = 0; int max_size = buf->max_size - 4; - int header_size = 4 * !this->found_next_frame; while (payload_size < max_size) { - len = this->input->read(this->input, - &buf->content[header_size + payload_size], 1); + len = this->input->read(this->input, &buf->content[payload_size], 1); if (len != 1) { lprintf("EOF\n"); buf->free_buffer(buf); @@ -586,32 +581,29 @@ static int parse_frame_payload(demux_mpgaudio_t *this, } payload_size += len; - if ((header_size + payload_size) >= 4) { - if (parse_frame_header(&this->next_frame, - &buf->content[header_size + payload_size - 4])) { - if (check_frame_validity(this, &this->next_frame)) { - lprintf("found next frame header\n"); - if (this->free_bitrate_size == 0) { - this->free_bitrate_size = payload_size - this->cur_frame.padding; - } - /* don't read the frame header twice */ - this->found_next_frame = 1; - memcpy(&this->next_header[0], &buf->content[header_size + payload_size], 4); - payload_size -= 4; - break; - } else { - lprintf("invalid frame\n"); + if (parse_frame_header(&this->next_frame, + &buf->content[payload_size - 4])) { + if (check_frame_validity(this, &this->next_frame)) { + lprintf("found next frame header\n"); + if (this->free_bitrate_size == 0) { + this->free_bitrate_size = payload_size - this->cur_frame.padding; } + /* don't read the frame header twice */ + this->found_next_frame = 1; + memcpy(&this->next_header[0], &buf->content[payload_size], 4); + payload_size -= 4; + break; + } else { + lprintf("invalid frame\n"); } } } - this->cur_frame.size = header_size + payload_size + 4; + this->cur_frame.size = payload_size + 4; if (this->br == 0) { this->br = 8000 * this->cur_frame.size / this->cur_frame.duration; } this->cur_frame.bitrate = this->br; lprintf("free bitrate: bitrate: %d, frame size: %d\n", this->br, this->cur_frame.size); - } if (this->check_vbr_header) { @@ -904,7 +896,7 @@ static void demux_mpgaudio_send_headers (demux_plugin_t *this_gen) { break; } } - + if (this->xing_header) { xing_header_t *xing = this->xing_header; @@ -915,7 +907,7 @@ static void demux_mpgaudio_send_headers (demux_plugin_t *this_gen) { if (this->stream_length) { this->br = ((uint64_t)xing->stream_size * 8 * 1000) / this->stream_length; } - + } else if (this->vbri_header) { vbri_header_t *vbri = this->vbri_header; @@ -958,7 +950,7 @@ static void demux_mpgaudio_send_headers (demux_plugin_t *this_gen) { { char scratch_buf[256]; char *mpeg_ver[3] = {"1", "2", "2.5"}; - + snprintf(scratch_buf, 256, "MPEG %s Layer %1d%s", mpeg_ver[this->cur_frame.version_idx], this->cur_frame.layer, (this->xing_header)? " VBR" : " CBR" ); -- cgit v1.2.3 From 831fa3d538480c035102864007dc4eb4969f2fd7 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Thu, 17 Jan 2008 23:51:26 +0000 Subject: Correct the changelog entry for the security fix in 1.1.9.1. --HG-- extra : transplant_source : AR%05H%29fH%3B%A37F%22h%85%7D%09%11/%FE%DF --- ChangeLog | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ec47096eb..9da723f22 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,7 +4,8 @@ xine-lib (1.1.10) (unreleased) xine-lib (1.1.9.1) * Security fixes: - - Fix a buffer overflow in RTSP header-handling code. (CVE-2008-0225) + - Buffer overflow which allows a remote attacker to execute arbitrary + code via a crafted SDP Abstract attribute. (CVE-2008-0225) (Fix ported from mplayer changeset 22821) * Fix a read-past-end bug in xine-lib's internal strtok_r replacement. (Only affects systems without strtok_r.) [Bug #19] -- cgit v1.2.3 From 4a85a1853424d220a4488b1e158b778ab9d7e56b Mon Sep 17 00:00:00 2001 From: Claudio Ciccani Date: Sat, 19 Jan 2008 13:30:23 +0100 Subject: Introducing new features from FusionSound-1.1.0 (dolby surround). --- src/audio_out/audio_fusionsound_out.c | 45 ++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/src/audio_out/audio_fusionsound_out.c b/src/audio_out/audio_fusionsound_out.c index a79d21213..b33850c5e 100644 --- a/src/audio_out/audio_fusionsound_out.c +++ b/src/audio_out/audio_fusionsound_out.c @@ -47,6 +47,12 @@ #define FUSIONSOUND_VERSION_CODE VERSION_CODE( FUSIONSOUND_MAJOR_VERSION, \ FUSIONSOUND_MINOR_VERSION, \ FUSIONSOUND_MICRO_VERSION ) + +#if FUSIONSOUND_VERSION_CODE >= VERSION_CODE(1,1,0) +# include /* defines FS_MAX_CHANNELS */ +#else +# define FS_MAX_CHANNELS 2 +#endif #define AO_OUT_FS_IFACE_VERSION 9 @@ -100,7 +106,29 @@ static int ao_fusionsound_open(ao_driver_t *ao_driver, break; case AO_CAP_MODE_STEREO: dsc.channels = 2; - break; + break; +#if FS_MAX_CHANNELS > 2 + case AO_CAP_MODE_4CHANNEL: + dsc.channels = 4; + dsc.channelmode = FSCM_SURROUND40_2F2R; + dsc.flags |= FSBDF_CHANNELMODE; + break; + case AO_CAP_MODE_4_1CHANNEL: + dsc.channels = 5; + dsc.channelmode = FSCM_SURROUND41_2F2R; + dsc.flags |= FSBDF_CHANNELMODE; + break; + case AO_CAP_MODE_5CHANNEL: + dsc.channels = 5; + dsc.channelmode = FSCM_SURROUND50; + dsc.flags |= FSBDF_CHANNELMODE; + break; + case AO_CAP_MODE_5_1CHANNEL: + dsc.channels = 6; + dsc.channelmode = FSCM_SURROUND51; + dsc.flags |= FSBDF_CHANNELMODE; + break; +#endif default: xprintf (this->xine, XINE_VERBOSITY_LOG, "audio_fusionsound_out: mode %#x not supported\n", mode); @@ -250,13 +278,18 @@ static void ao_fusionsound_close(ao_driver_t *ao_driver){ */ static uint32_t ao_fusionsound_get_capabilities(ao_driver_t *ao_driver) { + uint32_t caps = AO_CAP_MODE_MONO | AO_CAP_MODE_STEREO | + AO_CAP_MIXER_VOL | AO_CAP_MUTE_VOL | + AO_CAP_8BITS | AO_CAP_16BITS | + AO_CAP_24BITS; #if FUSIONSOUND_VERSION_CODE >= VERSION_CODE(0,9,26) - return (AO_CAP_MODE_MONO | AO_CAP_MODE_STEREO | AO_CAP_MIXER_VOL | - AO_CAP_8BITS | AO_CAP_16BITS | AO_CAP_24BITS | AO_CAP_FLOAT32); -#else - return (AO_CAP_MODE_MONO | AO_CAP_MODE_STEREO | AO_CAP_MIXER_VOL | - AO_CAP_8BITS | AO_CAP_16BITS | AO_CAP_24BITS); + caps |= AO_CAP_FLOAT32; +#endif +#if FS_MAX_CHANNELS > 2 + caps |= AO_CAP_MODE_4CHANNEL | AO_CAP_MODE_4_1CHANNEL | + AO_CAP_MODE_5CHANNEL | AO_CAP_MODE_5_1CHANNEL; #endif + return caps; } static void ao_fusionsound_exit(ao_driver_t *ao_driver) { -- cgit v1.2.3 From e372abc3772aa47b90fa0aadddb65ba33c54f574 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 20 Jan 2008 01:09:10 +0000 Subject: Comment out "#define LOG" again. --- src/demuxers/demux_mpgaudio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c index afd695d84..ee1dc915c 100644 --- a/src/demuxers/demux_mpgaudio.c +++ b/src/demuxers/demux_mpgaudio.c @@ -35,9 +35,9 @@ #define LOG_MODULE "demux_mpeg_audio" #define LOG_VERBOSE - +/* #define LOG - +*/ #include "xine_internal.h" #include "xineutils.h" #include "demux.h" -- cgit v1.2.3 From 21cdfa5236fa3a76c87ef9ea9a783fcce394eafe Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 20 Jan 2008 01:40:38 +0000 Subject: Update suggested packages: drop libartsc0, move -doc from Recommends. --- debian/control | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/control b/debian/control index 7d93d2f7e..de1467cc5 100644 --- a/debian/control +++ b/debian/control @@ -64,8 +64,8 @@ Description: the xine video player library, development packages Package: libxine1 Architecture: any Depends: ${shlibs:Depends} -Recommends: ${shlibs:Recommends}, libxine1-doc | libxine-doc -Suggests: ${shlibs:Suggests}, libartsc0 +Recommends: ${shlibs:Recommends} +Suggests: ${shlibs:Suggests}, libxine1-doc | libxine-doc Conflicts: libxine1-all-plugins, libxine1-bin, libxine1-console, libxine1-ffmpeg, libxine1-gnome, libxine1-misc-plugins, libxine1-plugins, libxine1-x Replaces: libxine1-all-plugins, libxine1-bin, libxine1-console, libxine1-ffmpeg, libxine1-gnome, libxine1-misc-plugins, libxine1-plugins, libxine1-x Provides: libxine1-all-plugins, libxine1-bin, libxine1-console, libxine1-ffmpeg, libxine1-gnome, libxine1-misc-plugins, libxine1-plugins, libxine1-x -- cgit v1.2.3 From dd125c93bdfbef26909ad684b678781abfd88c4a Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 20 Jan 2008 15:14:25 +0000 Subject: Don't unescape #subtitle:scheme://data. This was broken in 1.1.8 when #subtitle:/file was fixed. --- ChangeLog | 2 ++ src/xine-engine/xine.c | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 9da723f22..97c69817b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ xine-lib (1.1.10) (unreleased) * Update Ogg and Annodex mimetypes and extensions. * Change the default v4l device paths to /dev/video0 and /dev/radio0. + * Fix support for subtitles with schemes (e.g. http://), partly broken + since 1.1.8. xine-lib (1.1.9.1) * Security fixes: diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index eae13bec9..4f6ba2a80 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -780,6 +780,19 @@ void _x_flush_events_queues (xine_stream_t *stream) { pthread_mutex_unlock (&stream->event_queues_lock); } +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; @@ -1091,7 +1104,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 ) ) { -- cgit v1.2.3 From 94cf4ac059aa99952196af650401cdfa684e04a2 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 20 Jan 2008 15:35:05 +0000 Subject: Unescape the "#save:" filename, allowing ";" etc. in file names. This has a side effect: versions older than 1.1.10 do not unescape, so "#save:foo%23.ts" will result in a file named "foo%23.ts". Front end maintainers, beware :-) --- ChangeLog | 3 +++ src/xine-engine/xine.c | 1 + 2 files changed, 4 insertions(+) diff --git a/ChangeLog b/ChangeLog index 97c69817b..34cf8ddb4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,9 @@ xine-lib (1.1.10) (unreleased) * Change the default v4l device paths to /dev/video0 and /dev/radio0. * Fix support for subtitles with schemes (e.g. http://), partly broken since 1.1.8. + * Unescape the filename in "#save:". This allows filenames to contain ';' + etc. without ambiguity, e.g. "#save:foo%3B1.ts" -> "foo;1.ts", but front + end authors should be careful with xine-lib older than 1.1.10. xine-lib (1.1.9.1) * Security fixes: diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index 4f6ba2a80..13c6d19e9 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -930,6 +930,7 @@ static inline int _x_path_looks_like_mrl (const char *path) 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); -- cgit v1.2.3 From d19e7735c81d329742dd4a75d7115d2a2e2ed969 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Sun, 20 Jan 2008 16:06:31 +0000 Subject: Unmaking a # of it. --- src/xine-engine/xine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c index 13c6d19e9..0558f2f81 100644 --- a/src/xine-engine/xine.c +++ b/src/xine-engine/xine.c @@ -930,7 +930,7 @@ static inline int _x_path_looks_like_mrl (const char *path) memcpy(filename, tmp, strlen(tmp)); filename[strlen(tmp)] = '\0'; } - _x_mrl_unescape(filename);# + _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); -- cgit v1.2.3 From 76f79f2572257261d451b89d7c4f8a0d05a3aefe Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Mon, 21 Jan 2008 22:40:54 +0100 Subject: Fixed problems introduced by the free bitrate handling when frame sync is lost. --- src/demuxers/demux_mpgaudio.c | 133 ++++++++++++++++++++---------------------- 1 file changed, 63 insertions(+), 70 deletions(-) diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c index ee1dc915c..8ccaa9810 100644 --- a/src/demuxers/demux_mpgaudio.c +++ b/src/demuxers/demux_mpgaudio.c @@ -126,14 +126,11 @@ typedef struct { /* current mp3 frame */ mpg_audio_frame_t cur_frame; - + /* next mp3 frame, used when the frame size cannot be computed from the * current frame header */ mpg_audio_frame_t next_frame; - - /* reference mp3 frame, used for extra validation when sync is lost */ - mpg_audio_frame_t ref_frame; - + double cur_time; /* in milliseconds */ off_t mpg_frame_start; /* offset */ @@ -145,9 +142,12 @@ typedef struct { vbri_header_t *vbri_header; int found_next_frame:1; - int has_ref_frame:1; - off_t free_bitrate_size; + int free_bitrate_count; + off_t free_bitrate_size; /* use this size if 3 free bitrate frames are encountered */ uint8_t next_header[4]; + int mpg_version; + int mpg_layer; + int valid_frames; } demux_mpgaudio_t ; @@ -344,7 +344,7 @@ static xing_header_t* parse_xing_header(mpg_audio_frame_t *frame, if (!xing) goto exit_error; - lprintf("Xing header found\n"); + lprintf("found Xing header\n"); ptr += 4; if (ptr >= (buf + bufsize - 4)) goto exit_error; @@ -435,7 +435,7 @@ static vbri_header_t* parse_vbri_header(mpg_audio_frame_t *frame, if ((ptr + 4) >= (buf + bufsize)) return 0; lprintf("Checking %08X\n", *ptr); if (_X_BE_32(ptr) == VBRI_TAG) { - lprintf("Vbri header found\n"); + lprintf("found Vbri header\n"); ptr += 4; if ((ptr + 22) >= (buf + bufsize)) return 0; @@ -499,24 +499,6 @@ static vbri_header_t* parse_vbri_header(mpg_audio_frame_t *frame, } } -static int check_frame_validity(demux_mpgaudio_t *const this, mpg_audio_frame_t *const frame) { - int result = 0; - - if (this->ref_frame.is_free_bitrate) { - if ((frame->bitrate == 0) && - (this->ref_frame.freq == frame->freq) && - (this->ref_frame.version_idx == frame->version_idx) && - (this->ref_frame.channel_mode == frame->channel_mode)) { - result = 1; - } - } else { - if ((this->ref_frame.version_idx == frame->version_idx) && - (this->ref_frame.channel_mode == frame->channel_mode)) { - result = 1; - } - } - return result; -} /* * Parse a mp3 frame paylod @@ -547,11 +529,12 @@ static int parse_frame_payload(demux_mpgaudio_t *this, /* compute the payload size */ if (this->cur_frame.size > 0) { payload_size = this->cur_frame.size - 4; - } else if (this->free_bitrate_size > 0) { + this->free_bitrate_count = 0; + } else if (this->free_bitrate_count >= 3) { payload_size = this->free_bitrate_size + this->cur_frame.padding - 4; this->cur_frame.size = payload_size + 4; - payload_size = 0; } else { + this->free_bitrate_count++; payload_size = 0; } @@ -573,7 +556,7 @@ static int parse_frame_payload(demux_mpgaudio_t *this, int max_size = buf->max_size - 4; while (payload_size < max_size) { - len = this->input->read(this->input, &buf->content[payload_size], 1); + len = this->input->read(this->input, &buf->content[4 + payload_size], 1); if (len != 1) { lprintf("EOF\n"); buf->free_buffer(buf); @@ -581,28 +564,22 @@ static int parse_frame_payload(demux_mpgaudio_t *this, } payload_size += len; - if (parse_frame_header(&this->next_frame, - &buf->content[payload_size - 4])) { - if (check_frame_validity(this, &this->next_frame)) { - lprintf("found next frame header\n"); - if (this->free_bitrate_size == 0) { - this->free_bitrate_size = payload_size - this->cur_frame.padding; - } - /* don't read the frame header twice */ - this->found_next_frame = 1; - memcpy(&this->next_header[0], &buf->content[payload_size], 4); - payload_size -= 4; - break; - } else { - lprintf("invalid frame\n"); + if (parse_frame_header(&this->next_frame, &buf->content[payload_size])) { + lprintf("found next frame header\n"); + + if (this->free_bitrate_size == 0) { + this->free_bitrate_size = payload_size - this->cur_frame.padding; } + + /* don't read the frame header twice */ + this->found_next_frame = 1; + memcpy(&this->next_header[0], &buf->content[payload_size], 4); + payload_size -= 4; + break; } } this->cur_frame.size = payload_size + 4; - if (this->br == 0) { - this->br = 8000 * this->cur_frame.size / this->cur_frame.duration; - } - this->cur_frame.bitrate = this->br; + this->cur_frame.bitrate = 8000 * this->cur_frame.size / this->cur_frame.duration; lprintf("free bitrate: bitrate: %d, frame size: %d\n", this->br, this->cur_frame.size); } @@ -612,11 +589,15 @@ static int parse_frame_payload(demux_mpgaudio_t *this, this->xing_header = parse_xing_header(&this->cur_frame, buf->content, this->cur_frame.size); if (this->xing_header) { buf->free_buffer(buf); + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + "demux_mpgaudio: found Xing header at offset %PRId64\n", frame_pos); return 1; } this->vbri_header = parse_vbri_header(&this->cur_frame, buf->content, this->cur_frame.size); if (this->vbri_header) { buf->free_buffer(buf); + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + "demux_mpgaudio: found Vbri header at offset %PRId64\n", frame_pos); return 1; } } @@ -707,39 +688,51 @@ static int demux_mpgaudio_next (demux_mpgaudio_t *this, int decoder_flags, int s memcpy(&this->cur_frame, &this->next_frame, sizeof(mpg_audio_frame_t)); } else { int bytes = 4; + int loose_sync = 0; for (;;) { if (!read_frame_header(this, header, bytes)) return 0; if (parse_frame_header(&this->cur_frame, header)) { - if (!this->has_ref_frame) { - this->has_ref_frame = 1; - memcpy(&this->ref_frame, &this->cur_frame, sizeof(mpg_audio_frame_t)); - lprintf("ref frame saved\n"); - } else { - if (!check_frame_validity(this, &this->cur_frame)) { - lprintf("invalid frame\n"); - bytes = 1; /* resync */ - continue; - } - } lprintf("frame found\n"); - break; - } else { - lprintf("loose sync\n"); - if ( id3v2_istag(header) ) { - if (!id3v2_parse_tag(this->input, this->stream, header)) { - xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - LOG_MODULE ": ID3V2 tag parsing error\n"); - bytes = 1; /* resync */ + /* additionnal checks */ + if ((this->mpg_version == (this->cur_frame.version_idx + 1)) && + (this->mpg_layer == this->cur_frame.layer)) { + this->valid_frames++; + break; + } else { + if (this->valid_frames > 3) { + lprintf("invalid frame. expected mpeg %d, layer %d\n", this->mpg_version, this->mpg_layer); } else { - bytes = 4; + this->mpg_version = this->cur_frame.version_idx + 1; + this->mpg_layer = this->cur_frame.layer; + this->valid_frames = 0; + break; } + } + } + + if (!loose_sync) { + off_t frame_pos = this->input->get_current_pos(this->input) - 4; + loose_sync = 1; + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + LOG_MODULE ": loose mp3 sync at offset %"PRId64"\n", frame_pos); + } + /* the stream is broken, don't keep info about previous frames */ + this->free_bitrate_size = 0; + + if ( id3v2_istag(header) ) { + if (!id3v2_parse_tag(this->input, this->stream, header)) { + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + LOG_MODULE ": ID3V2 tag parsing error\n"); + bytes = 1; /* resync */ } else { - /* skip */ - bytes = 1; + bytes = 4; } + } else { + /* skip */ + bytes = 1; } } } -- cgit v1.2.3 From e6a7cabd6e6bf25145eaef168823ab3f42dcbdc8 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Mon, 21 Jan 2008 23:05:28 +0100 Subject: Fixed logging. Replaced a magic number by #define. --- src/demuxers/demux_mpgaudio.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c index 8ccaa9810..180a9752c 100644 --- a/src/demuxers/demux_mpgaudio.c +++ b/src/demuxers/demux_mpgaudio.c @@ -33,7 +33,7 @@ #include #include -#define LOG_MODULE "demux_mpeg_audio" +#define LOG_MODULE "demux_mpgaudio" #define LOG_VERBOSE /* #define LOG @@ -51,6 +51,7 @@ * the second mp3 frame is sent to the decoder */ #define NUM_PREVIEW_BUFFERS 2 +#define NUM_VALID_FRAMES 3 #define FOURCC_TAG BE_FOURCC @@ -519,7 +520,7 @@ static int parse_frame_payload(demux_mpgaudio_t *this, if (this->cur_frame.size > buf->max_size) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - "demux_mpgaudio: frame size is greater than fifo buffer size\n"); + LOG_MODULE ": frame size is greater than fifo buffer size\n"); buf->free_buffer(buf); return 0; } @@ -530,7 +531,7 @@ static int parse_frame_payload(demux_mpgaudio_t *this, if (this->cur_frame.size > 0) { payload_size = this->cur_frame.size - 4; this->free_bitrate_count = 0; - } else if (this->free_bitrate_count >= 3) { + } else if (this->free_bitrate_count >= NUM_VALID_FRAMES) { payload_size = this->free_bitrate_size + this->cur_frame.padding - 4; this->cur_frame.size = payload_size + 4; } else { @@ -590,14 +591,14 @@ static int parse_frame_payload(demux_mpgaudio_t *this, if (this->xing_header) { buf->free_buffer(buf); xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - "demux_mpgaudio: found Xing header at offset %PRId64\n", frame_pos); + LOG_MODULE ": found Xing header at offset %PRId64\n", frame_pos); return 1; } this->vbri_header = parse_vbri_header(&this->cur_frame, buf->content, this->cur_frame.size); if (this->vbri_header) { buf->free_buffer(buf); xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - "demux_mpgaudio: found Vbri header at offset %PRId64\n", frame_pos); + LOG_MODULE ": found Vbri header at offset %PRId64\n", frame_pos); return 1; } } @@ -702,7 +703,7 @@ static int demux_mpgaudio_next (demux_mpgaudio_t *this, int decoder_flags, int s this->valid_frames++; break; } else { - if (this->valid_frames > 3) { + if (this->valid_frames >= NUM_VALID_FRAMES) { lprintf("invalid frame. expected mpeg %d, layer %d\n", this->mpg_version, this->mpg_layer); } else { this->mpg_version = this->cur_frame.version_idx + 1; -- cgit v1.2.3 From 9c0f263985b4612e7e67244d6140c087f880602c Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Mon, 21 Jan 2008 23:06:12 +0100 Subject: Fixed logging. --- src/demuxers/id3.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/demuxers/id3.c b/src/demuxers/id3.c index 6b36cc666..cd72646ef 100644 --- a/src/demuxers/id3.c +++ b/src/demuxers/id3.c @@ -349,21 +349,21 @@ int id3v22_parse_tag(input_plugin_t *input, if (tag_header.flags & ID3V22_ZERO_FLAG) { /* invalid flags */ xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: invalid header flags (%02x)\n", tag_header.flags); + LOG_MODULE ": invalid header flags (%02x)\n", tag_header.flags); input->seek (input, tag_header.size - pos, SEEK_CUR); return 0; } if (tag_header.flags & ID3V22_COMPRESS_FLAG) { /* compressed tag: not supported */ xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: compressed tags are not supported\n"); + LOG_MODULE ": compressed tags are not supported\n"); input->seek (input, tag_header.size - pos, SEEK_CUR); return 0; } if (tag_header.flags & ID3V22_UNSYNCH_FLAG) { /* unsynchronized tag: not supported */ xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: unsynchronized tags are not supported\n"); + LOG_MODULE ": unsynchronized tags are not supported\n"); input->seek (input, tag_header.size - pos, SEEK_CUR); return 0; } @@ -375,11 +375,11 @@ int id3v22_parse_tag(input_plugin_t *input, if ((pos + tag_frame_header.size) <= tag_header.size) { if (!id3v22_interp_frame(input, stream, &tag_frame_header)) { xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: invalid frame content\n"); + LOG_MODULE ": invalid frame content\n"); } } else { xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: invalid frame header\n"); + LOG_MODULE ": invalid frame header\n"); input->seek (input, tag_header.size - pos, SEEK_CUR); return 1; } @@ -391,13 +391,13 @@ int id3v22_parse_tag(input_plugin_t *input, } } else { xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: id3v2_parse_frame_header problem\n"); + LOG_MODULE ": id3v2_parse_frame_header problem\n"); return 0; } } return 1; } else { - xprintf(stream->xine, XINE_VERBOSITY_DEBUG, "id3: id3v2_parse_header problem\n"); + xprintf(stream->xine, XINE_VERBOSITY_DEBUG, LOG_MODULE ": id3v2_parse_header problem\n"); return 0; } } @@ -543,14 +543,14 @@ int id3v23_parse_tag(input_plugin_t *input, if (tag_header.flags & ID3V23_ZERO_FLAG) { /* invalid flags */ xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: invalid header flags (%02x)\n", tag_header.flags); + LOG_MODULE ": invalid header flags (%02x)\n", tag_header.flags); input->seek (input, tag_header.size - pos, SEEK_CUR); return 0; } if (tag_header.flags & ID3V23_UNSYNCH_FLAG) { /* unsynchronized tag: not supported */ xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: unsynchronized tags are not supported\n"); + LOG_MODULE ": unsynchronized tags are not supported\n"); input->seek (input, tag_header.size - pos, SEEK_CUR); return 0; } @@ -568,11 +568,11 @@ int id3v23_parse_tag(input_plugin_t *input, if ((pos + tag_frame_header.size) <= tag_header.size) { if (!id3v23_interp_frame(input, stream, &tag_frame_header)) { xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: invalid frame content\n"); + LOG_MODULE ": invalid frame content\n"); } } else { xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: invalid frame header\n"); + LOG_MODULE ": invalid frame header\n"); input->seek (input, tag_header.size - pos, SEEK_CUR); return 1; } @@ -584,13 +584,13 @@ int id3v23_parse_tag(input_plugin_t *input, } } else { xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: id3v2_parse_frame_header problem\n"); + LOG_MODULE ": id3v2_parse_frame_header problem\n"); return 0; } } return 1; } else { - xprintf(stream->xine, XINE_VERBOSITY_DEBUG, "id3v23: id3v2_parse_header problem\n"); + xprintf(stream->xine, XINE_VERBOSITY_DEBUG, LOG_MODULE ": id3v2_parse_header problem\n"); return 0; } } @@ -794,7 +794,7 @@ int id3v24_parse_tag(input_plugin_t *input, if (tag_header.flags & ID3V24_ZERO_FLAG) { /* invalid flags */ xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: invalid header flags (%02x)\n", tag_header.flags); + LOG_MODULE ": invalid header flags (%02x)\n", tag_header.flags); input->seek (input, tag_header.size - pos, SEEK_CUR); return 0; } @@ -818,11 +818,11 @@ int id3v24_parse_tag(input_plugin_t *input, if ((pos + tag_frame_header.size) <= tag_header.size) { if (!id3v24_interp_frame(input, stream, &tag_frame_header)) { xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: invalid frame content\n"); + LOG_MODULE ": invalid frame content\n"); } } else { xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: invalid frame header\n"); + LOG_MODULE ": invalid frame header\n"); input->seek (input, tag_header.size - pos, SEEK_CUR); return 1; } @@ -834,7 +834,7 @@ int id3v24_parse_tag(input_plugin_t *input, } } else { xprintf(stream->xine, XINE_VERBOSITY_DEBUG, - "id3: id3v2_parse_frame_header problem\n"); + LOG_MODULE ": id3v2_parse_frame_header problem\n"); return 0; } } @@ -844,7 +844,7 @@ int id3v24_parse_tag(input_plugin_t *input, } return 1; } else { - xprintf(stream->xine, XINE_VERBOSITY_DEBUG, "id3v23: id3v2_parse_header problem\n"); + xprintf(stream->xine, XINE_VERBOSITY_DEBUG, LOG_MODULE ": id3v2_parse_header problem\n"); return 0; } } @@ -858,22 +858,22 @@ int id3v2_parse_tag(input_plugin_t *input, switch(mp3_frame_header[3]) { case 2: - xprintf(stream->xine, XINE_VERBOSITY_LOG, "ID3V2.2 tag\n"); + xprintf(stream->xine, XINE_VERBOSITY_LOG, LOG_MODULE ": ID3V2.2 tag\n"); result = id3v22_parse_tag(input, stream, mp3_frame_header); break; case 3: - xprintf(stream->xine, XINE_VERBOSITY_LOG, "ID3V2.3 tag\n"); + xprintf(stream->xine, XINE_VERBOSITY_LOG, LOG_MODULE ": ID3V2.3 tag\n"); result = id3v23_parse_tag(input, stream, mp3_frame_header); break; case 4: - xprintf(stream->xine, XINE_VERBOSITY_LOG, "ID3V2.4 tag\n"); + xprintf(stream->xine, XINE_VERBOSITY_LOG, LOG_MODULE ": ID3V2.4 tag\n"); result = id3v24_parse_tag(input, stream, mp3_frame_header); break; default: - xprintf(stream->xine, XINE_VERBOSITY_LOG, "Unknown ID3v2 version: 0x%02x.\n", mp3_frame_header[3]); + xprintf(stream->xine, XINE_VERBOSITY_LOG, LOG_MODULE ": Unknown ID3v2 version: 0x%02x.\n", mp3_frame_header[3]); } return result; -- cgit v1.2.3 From ada8ce027fc69e8a660e64849f3568c7396a84ae Mon Sep 17 00:00:00 2001 From: Thibaut Mattern Date: Wed, 23 Jan 2008 00:41:55 +0100 Subject: Fixed pts handling, used the amount of data stored in the internal buffer to compensate pts. --- src/libmad/xine_mad_decoder.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/libmad/xine_mad_decoder.c b/src/libmad/xine_mad_decoder.c index be616be36..46464d23b 100644 --- a/src/libmad/xine_mad_decoder.c +++ b/src/libmad/xine_mad_decoder.c @@ -149,6 +149,7 @@ static int head_check(mad_decoder_t *this) { static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { mad_decoder_t *this = (mad_decoder_t *) this_gen; + int bytes_in_buffer_at_pts; lprintf ("decode data, size: %d, decoder_flags: %d\n", buf->size, buf->decoder_flags); @@ -170,6 +171,8 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { this->preview_mode = 1; } + bytes_in_buffer_at_pts = this->bytes_in_buffer; + xine_fast_memcpy (&this->buffer[this->bytes_in_buffer], buf->content, buf->size); this->bytes_in_buffer += buf->size; @@ -271,6 +274,8 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { struct mad_pcm *pcm = &this->synth.pcm; audio_buffer_t *audio_buffer; uint16_t *output; + int bitrate; + int pts_offset; audio_buffer = this->xstream->audio_out->get_buffer (this->xstream->audio_out); output = audio_buffer->mem; @@ -291,7 +296,22 @@ static void mad_decode_data (audio_decoder_t *this_gen, buf_element_t *buf) { } audio_buffer->num_frames = pcm->length; - audio_buffer->vpts = buf->pts; + + /* pts computing */ + if (this->frame.header.bitrate > 0) { + bitrate = this->frame.header.bitrate; + } else { + bitrate = _x_stream_info_get(this->xstream, XINE_STREAM_INFO_AUDIO_BITRATE); + lprintf("offset %d bps\n", bitrate); + } + audio_buffer->vpts = buf->pts; + if (audio_buffer->vpts && (bitrate > 0)) { + pts_offset = (bytes_in_buffer_at_pts * 8 * 90) / (bitrate / 1000); + lprintf("pts: %"PRId64", offset: %d pts, %d bytes\n", buf->pts, pts_offset, bytes_in_buffer_at_pts); + if (audio_buffer->vpts < pts_offset) + pts_offset = audio_buffer->vpts; + audio_buffer->vpts -= pts_offset; + } this->xstream->audio_out->put_buffer (this->xstream->audio_out, audio_buffer, this->xstream); -- cgit v1.2.3 From 13d765ca841b06759ffcabbd606b4b01e4c1524e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Tue, 22 Jan 2008 02:29:02 +0000 Subject: Patch version missing from xine-config, libxine.pc The possible patch digit is missing from "xine-lib --version" and "pkg-config --modversion libxine", as witnessed in 1.1.9.1. --HG-- extra : transplant_source : %3C%0E%E4%28%F3%AD%C5%7F%8F%13%D7%1Ck%10tAQ%85Oh --- configure.ac | 1 + misc/libxine.pc.in | 2 +- misc/xine-config.in | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 813c5c83a..3797f7c63 100644 --- a/configure.ac +++ b/configure.ac @@ -65,6 +65,7 @@ fi AC_SUBST(XINE_MAJOR) AC_SUBST(XINE_MINOR) AC_SUBST(XINE_SUB) +AC_SUBST(XINE_PATCH) AC_SUBST(XINE_IFACE_AGE) AC_SUBST(XINE_BIN_AGE) diff --git a/misc/libxine.pc.in b/misc/libxine.pc.in index c27e8aa94..623d2b657 100644 --- a/misc/libxine.pc.in +++ b/misc/libxine.pc.in @@ -5,7 +5,7 @@ includedir=@includedir@ Name: libxine Description: The xine engine library -Version: @XINE_MAJOR@.@XINE_MINOR@.@XINE_SUB@ +Version: @XINE_MAJOR@.@XINE_MINOR@.@XINE_SUB@@XINE_PATCH@ Requires: Libs: -L${libdir} -lxine Libs.private: @ZLIB_LIBS@ @NET_LIBS@ @PTHREAD_LIBS@ @LIBICONV@ @RT_LIBS@ diff --git a/misc/xine-config.in b/misc/xine-config.in index 8d288b22b..8f25d5cc5 100644 --- a/misc/xine-config.in +++ b/misc/xine-config.in @@ -54,7 +54,7 @@ while test $# -gt 0; do echo_exec_prefix=yes ;; --version) - echo @XINE_MAJOR@.@XINE_MINOR@.@XINE_SUB@ + echo @XINE_MAJOR@.@XINE_MINOR@.@XINE_SUB@@XINE_PATCH@ ;; --acflags) echo_acflags=yes -- cgit v1.2.3 From d73fc5192cf51b115695a0121629a2fe076324cb Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Tue, 22 Jan 2008 23:24:52 +0000 Subject: Add release dates to the changelog; tidy up earliest entries. Wherever possible, dates are from the release tarballs on Sourceforge. --HG-- extra : transplant_source : %7C%9F%C7H%90%0C%87%D9bA%94%F8%F2%0A%7F%40%CE%5E%A0%04 --- ChangeLog | 206 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 104 insertions(+), 102 deletions(-) diff --git a/ChangeLog b/ChangeLog index 34cf8ddb4..b618b5099 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,7 +7,7 @@ xine-lib (1.1.10) (unreleased) etc. without ambiguity, e.g. "#save:foo%3B1.ts" -> "foo;1.ts", but front end authors should be careful with xine-lib older than 1.1.10. -xine-lib (1.1.9.1) +xine-lib (1.1.9.1) 2008-01-11 * Security fixes: - Buffer overflow which allows a remote attacker to execute arbitrary code via a crafted SDP Abstract attribute. (CVE-2008-0225) @@ -16,7 +16,7 @@ xine-lib (1.1.9.1) (Only affects systems without strtok_r.) [Bug #19] * Fix a bug which causes video playback display errors on PPC/Darwin. -xine-lib (1.1.9) +xine-lib (1.1.9) 2008-01-06 * Fix dvd://.../title[.chapter] handling (somewhat broken in 1.1.8). * Fix switching DVB subtitles channels. * DVB sub: switch to dyn mem alloc and allow multiple CLUTs per page. @@ -64,7 +64,7 @@ xine-lib (1.1.9) * Workaround for subtitle rendering when using variable-length character encodings other than UTF-8. (There is probably still some breakage here.) -xine-lib (1.1.8) +xine-lib (1.1.8) 2007-08-27 * Send a channel-changed event to the frontend when receiving the SYNC string from last.fm streaming server. * Disable mediaLib support by default (the licenses probably disallow the @@ -90,7 +90,7 @@ xine-lib (1.1.8) * Various small video frame-handling bug fixes. * Add options to control bob deinterlacing in the XxMC video output plugin. -xine-lib (1.1.7) +xine-lib (1.1.7) 2007-06-07 * Support libdca (new name for libdts) by shuffling around the dts.h file. * Add support for MDHD version 1 atom in demux_qt. [Bug SF 1679398] * Handle single-quoted attribute values in XML. @@ -121,7 +121,7 @@ xine-lib (1.1.7) in 1.2 series. * Fix a colour format conversion crash in the fb video output driver. -xine-lib (1.1.6) +xine-lib (1.1.6) 2007-04-17 * Split the DirectFB plugin into X11 and non-X versions. * Improve the Mac OS X video output plugin. Thanks to Matt Messier. * Fixed the XcbXv plugin - an empty plugin would be built if "old" Xv @@ -133,7 +133,7 @@ xine-lib (1.1.6) * Fixed a CDDA-related crash and a DVD-related hang, both caused by the same change in 1.1.5. -xine-lib (1.1.5) +xine-lib (1.1.5) 2007-04-10 * Security fixes: - Fix heap overflow in DMO loader. (CVE-2007-1246) [Bug SF 1676925] Thanks to Kees Cook for reporting. @@ -187,7 +187,7 @@ xine-lib (1.1.5) * Support multiple audio PID in MPEG TS. Patch by Julian Scheel. * Improvement in portability to OpenBSD, thanks to Pascal S. de Kloe. -xine-lib (1.1.4) +xine-lib (1.1.4) 2007-01-28 * Mark string-type configuration items according to whether they're plain strings or names of files, device nodes or directories. This information is available to front ends (via .num_value) so that they can present @@ -253,7 +253,7 @@ xine-lib (1.1.4) * Fix audio/video sync problem with NTSC DVDs (introduced in 1.1.2). [Bugs SF 1544349, SF 1589644] -xine-lib (1.1.3) +xine-lib (1.1.3) 2006-12-03 * Security fixes: - Heap overflow in libmms (related to CVE-2006-2200) - Buffer overrun in Real Media input plugin. [Bug SF 1603458] @@ -298,7 +298,7 @@ xine-lib (1.1.3) * Fix some crashes caused by MP3 files (and possibly others) being misdetected as AAC. -xine-lib (1.1.2) +xine-lib (1.1.2) 2006-07-09 * Security fixes: - CVE-2005-4048: possible buffer overflow in libavcodec (crafted PNGs). - CVE-2006-2802: possible buffer overflow in the HTTP plugin. @@ -334,7 +334,7 @@ xine-lib (1.1.2) * Fixed some win32 codec freezes when configured w32-path doesn't exist * Add support for RealPlayer 10 codecs (from SUSE) -xine-lib (1.1.1) +xine-lib (1.1.1) 2005-11-15 * Improve sound quality when using alsa 1.0.9 or above. When playing a 44.1khz stream on a 48khz only capable sound card. It bypasses alsa-lib resampler and uses xine's @@ -359,7 +359,7 @@ xine-lib (1.1.1) * cddb improvements/fixes (DTITLE/DYEAR parsing, timeout increase and multiline entries support) [Bug SF 1205274] -xine-lib (1.1.0) +xine-lib (1.1.0) 2005-07-26 * new quality deinterlacer from dscaler: GreedyH (Greedy High Motion) * new quality deinterlacer from dscaler: TomsMoComp (Tom's Motion Compensated) * added help for most deinterlace methods @@ -459,7 +459,7 @@ xine-lib (1.0.1) flexible plugin linking * support for Windows Media Audio Lossless -xine-lib (1.0) +xine-lib (1.0) 2004-12-25 * unbreak DXR3 plugin * fix crash in the AIFF demuxer on oversized chunks * fix crash in the sputext decoder when subtitles have too many lines @@ -474,7 +474,7 @@ xine-lib (1.0) * fixed crash related to relative HTTP redirect URLs (implemented canonicalisation) * linking libXv dynamically, fixes breakage of Xv plugin -xine-lib (1-rc8) +xine-lib (1-rc8) 2004-12-15 * Multiple security vulnerabilities fixed on PNM and Real RTSP clients * Rewrote OpenGL output plugin. * Fixed segfault when seeking with the "xvmc" and "xxmc" plugins playing @@ -508,7 +508,7 @@ xine-lib (1-rc8) * meta info (title, artist, etc) returned by the xine-lib is now UTF8 * new XINE_META_INFO_TRACK_NUMBER meta info -xine-lib (1-rc7) +xine-lib (1-rc7) 2004-11-04 * Build system improvements: replacement functions, better work with headers * Set the codec name for Real Media even if we can't play the files * Fix win32 playback on recent versions of Linux @@ -554,7 +554,7 @@ xine-lib (1-rc7) * Allowed multiple simultaneous thread access in parts of the xxmc driver, assuming that XvMC libraries are thread-safe. -xine-lib (1-rc6) +xine-lib (1-rc6) 2004-09-16 * Moved win32 frontend into separate module. * Fixed Xv initialization to enable multiple instances of the Xv plugin * Removed XInitThreads() call from some video out plugins because it @@ -625,7 +625,7 @@ xine-lib (1-rc5) * fix DVD playback from a specified title/part with dvd:/.<part> MRLs -xine-lib (1-rc4a) +xine-lib (1-rc4a) 2004-05-12 * audio out now uses a more user friendly "Speaker arrangement" config item; this defaults to stereo, so if you use a different speaker arragement, like 5.1 or other surround setups, you have to reconfigure xine using this item @@ -641,7 +641,7 @@ xine-lib (1-rc4a) * several DVB improvements. add dvbs://, dvbc:// and dvbt:// mrls * fix static noise produced by WMA streams in some systems -xine-lib (1-rc4) +xine-lib (1-rc4) 2004-04-28 * experimental DTS software decoder using libdts * SPU decoder: timestamp handling for NAV packets fixes the menu on the first DVD of "24" season 1 @@ -680,7 +680,7 @@ xine-lib (1-rc4) * seeking support for matroska files * libmpeg2 now has native VIS motion compensation routines on SPARC -xine-lib (1-rc3c) +xine-lib (1-rc3c) 2004-04-08 * fix the deadlock with non-seekable input plugins * guess codeset for OSD if nl_langinfo(CODESET) is missing or not working * new option - list of domains, where don't use proxy @@ -700,7 +700,7 @@ xine-lib (1-rc3c) DVD of "24" season 1 * fixed audio sync method "resampling" -xine-lib (1-rc3b) +xine-lib (1-rc3b) 2004-03-17 * fix SDL plugin that was broken in rc3 * updated libfaad 2.0 RC3 cvs (fix some raw aac problems, HE support) * Win32 Cygwin updates, using DirectX @@ -756,7 +756,7 @@ xine-lib (1-rc3b) Sound is now continuous. * fix playback of ogg/ogm files larger than 2GB -xine-lib (1-rc3a) +xine-lib (1-rc3a) 2003-12-28 * new subtitle formats: jacobsub, subviewer 2.0, subrip 0.9 * auto hiding of the subtitles * raw AAC file demuxer @@ -768,7 +768,7 @@ xine-lib (1-rc3a) * update win32 port, working ffmpeg decode plugin * fixed segfault when running in verbose mode -xine-lib (1-rc3) +xine-lib (1-rc3) 2003-12-16 * fix dvd menu blending when using tvtime plugin (yuy2 blend) * fix problems with some more elaborate post plugin setups * discontinuity problems in audio only streams fixed @@ -810,7 +810,7 @@ xine-lib (1-rc3) * fix playback of 8 bit sound when the soundcard doesn't support them -xine-lib (1-rc2) +xine-lib (1-rc2) 2003-10-25 * XvMC support for hardware accelerated mpeg2 playback (-V xvmc) * Fix some errors in sound state when exiting xine and using alsa. * new tvtime/deinterlacer algorithm scalerbob @@ -886,11 +886,11 @@ xine-lib (1-rc1) * initial id3v2 support (id3v2.3 and id3v2.4 are not yet supported) * Fix blocking on xine start when using alsa. -xine-lib (1-rc0a) +xine-lib (1-rc0a) 2003-08-02 * includes ffmpeg's MPEG encode in dist tarball (fixes DXR3 support) * don't abort on MPEG_block stream errors -xine-lib (1-rc0) +xine-lib (1-rc0) 2003-08-01 * improved seeking accuracy of ogg_demuxer * xine broadcaster (send stream to multiple xine clients simultaneously) start master with 'xine --broadcast-port xxxx' @@ -939,7 +939,7 @@ xine-lib (1-beta12) * input_pvr (ivtv) updates * demux_mpeg_block improved to cure problems with VCDs and bogus encrypted messages. -xine-lib (1-beta11) +xine-lib (1-beta11) 2003-04-28 * fix bugs in selecting ogm subtitles * fix multiple lines subtitles' display in OGM container * fix fastforward bug (slow playback with unused cpu cicles) @@ -958,7 +958,7 @@ xine-lib (1-beta11) * Quicktime fixes (now all Matrix: Reloaded teasers and trailers play) * fix playback of video files created by Canon digital cameras -xine-lib (1-beta10) +xine-lib (1-beta10) 2003-04-08 * loading and displaying png images (e.g. for logos) * capability of on-the-fly stream rewiring * libdvdnav: PGC based positioning: @@ -979,7 +979,7 @@ xine-lib (1-beta10) * DVD: menu calls ("Escape" in xine-ui) can now jump back from the menu into the movie as well -xine-lib (1-beta9) +xine-lib (1-beta9) 2003-03-22 * implement XINE_PARAM_AUDIO_AMP_LEVEL so xine's volume can be set independantly from other applications * mpeg-4 postprocessing support added to ffmpeg video decoder @@ -1001,7 +1001,7 @@ xine-lib (1-beta9) xine-lib (1-beta8) * fix DVD highlight problems -xine-lib (1-beta7) +xine-lib (1-beta7) 2003-03-07 * libdvdnav updated to 0.1.6cvs: fixes a whole class of problems caused by dvdnav being a bit ahead in the stream due to xine's fifos * libdvdread updated to 0.9.4 @@ -1018,7 +1018,7 @@ xine-lib (1-beta7) * .rm file reference handling bugfxi * mute console output unless XINE_PARAM_VERBOSE is set -xine-lib (1-beta6) +xine-lib (1-beta6) 2003-02-24 * inform the width and height for the v4l input plugin * ffmpeg aspect ratio detection code fixed * demux_ogg arm patch by dilb @@ -1026,7 +1026,7 @@ xine-lib (1-beta6) * plugin loader segfault fix * fb configure check fixed -xine-lib (1-beta5) +xine-lib (1-beta5) 2003-02-21 * new AV sync strategy (audio resample) for DXR3 users * improved fb driver with zero copy * fix the v4l plugin for lower resolution devices (webcam) @@ -1056,13 +1056,13 @@ xine-lib (1-beta5) * make number of video buffer configurable by the user (performance tuning option) -xine-lib (1-beta4) +xine-lib (1-beta4) 2003-01-29 * http input fixes * rtsp input fixes (remove long wait on end of stream) * build fixes * support for reference streams (.asx, .ram) -xine-lib (1-beta3) +xine-lib (1-beta3) 2003-01-28 * PSX STR file demuxer * Westwood Studios AUD demuxer * PVA file demuxer @@ -1089,14 +1089,14 @@ xine-lib (1-beta3) * fixed yuy2 overlays on big-endian systems * experimental tvout support using nvtvd (configure --enable-nvtv) -xine-lib (1-beta2) +xine-lib (1-beta2) 2003-01-02 * what a GOOM! post plugin * Digital TV (DVB) input plugin (experimental) * Interplay MVE playback system (file demuxer, video decoder, audio decoder) * support for real video 4.0 (through external real binary plugins) * quicktime binary-only codec support bugfixes -xine-lib (1-beta1) +xine-lib (1-beta1) 2002-12-24 * updated libfaad * improved engine for seeking and slider positioning * network input plugin is working again @@ -1113,7 +1113,7 @@ xine-lib (1-beta1) * raw dv demuxer added * many FLI/FLC fixes -xine-lib (1-beta0) +xine-lib (1-beta0) 2002-12-11 * fix decoder priority configuration * cache available plugins for faster xine loading * metronom's improvements for streams with slightly wrong sample rates @@ -1126,7 +1126,7 @@ xine-lib (1-beta0) * MPEG-4 file (*.mp4) support * closed caption support ported to new architecture -xine-lib (1-alpha2) +xine-lib (1-alpha2) 2002-11-27 * configurable image position * DVD menu button highlight position fixes * internal engine changes to allow a new layer of post effect plugins @@ -1138,7 +1138,7 @@ xine-lib (1-alpha2) * arts audio output plugin ported to new architecture * esound audio output plugin ported to new architecture -xine-lib (1-alpha1) +xine-lib (1-alpha1) 2002-11-20 * transport stream demuxer fixes * DVD playback should be working again (please report DVDs that don't play!) * stdin_fifo input plugin @@ -1147,7 +1147,7 @@ xine-lib (1-alpha1) * XviD decoder is working again * DV decoder (ffmpeg) -xine-lib (1-alpha0) +xine-lib (1-alpha0) 2002-11-04 * dvd plugin replaced by dvdnav with full menu support * fix segfault on exit for w32codecs @@ -1191,7 +1191,7 @@ xine-lib (1-alpha0) * URI conforming MRL syntax, new delimiter # for various stream parameters * variuos fixes for dxr3 overlay mode -xine-lib (0.9.13) unstable; urgency=low +xine-lib (0.9.13) 2002-08-03 * improved audio resampling for cards limited to 16 bits, stereo or mono * native wmv7 decoder using ffmpeg @@ -1216,7 +1216,7 @@ xine-lib (0.9.13) unstable; urgency=low -- Siggi Langauf <siggi@debian.org> Sat, 3 Aug 2002 22:44:16 +0200 -xine-lib (0.9.12) unstable; urgency=low +xine-lib (0.9.12) 2002-06-23 * demux_ts fixes for ATSC streams * configurable size of avi subtitles @@ -1228,7 +1228,7 @@ xine-lib (0.9.12) unstable; urgency=low -- Guenter Bartsch <guenter@users.sourceforge.net> -xine-lib (0.9.11) unstable; urgency=low +xine-lib (0.9.11) 2002-06-20 * sync with ffmpeg cvs * some endianess and 64bit machine fixes @@ -1250,7 +1250,7 @@ xine-lib (0.9.11) unstable; urgency=low -- Guenter Bartsch <guenter@users.sourceforge.net> -xine (0.9.10) unstable; urgency=low +xine (0.9.10) 2002-05-28 * fixed snapshot: capture current frame with overlays * AVI progressive index reconstruction @@ -1271,7 +1271,7 @@ xine (0.9.10) unstable; urgency=low -- Guenter Bartsch <guenter@users.sourceforge.net> -xine (0.9.9) unstable; urgency=low +xine (0.9.9) 2002-05-28 * new (fast) demuxer seeking * libdivx4 updated to support divx5 @@ -1297,7 +1297,7 @@ xine (0.9.9) unstable; urgency=low -- Guenter Bartsch <guenter@users.sourceforge.net> Sat Apr 20 20:32:33 CEST 2002 -xine (0.9.8) unstable; urgency=low +xine (0.9.8) 2002-01-16 * Linux framebuffer video out driver (experimental) * several bugfixes @@ -1314,7 +1314,7 @@ xine (0.9.8) unstable; urgency=low -- Guenter Bartsch <guenter@users.sourceforge.net> Sun Jan 13 16:15:07 CET 2002 -xine (0.9.7) unstable; urgency=low +xine (0.9.7) 2001-12-11 * fix some win32 dll segfaults * seamless branching on input_dvd @@ -1326,7 +1326,7 @@ xine (0.9.7) unstable; urgency=low -- Guenter Bartsch <guenter@users.sourceforge.net> Tue Nov 27 01:20:06 CET 2001 -xine (0.9.6) unstable; urgency=low +xine (0.9.6) 2001-11-28 * demux_asf big fragments handling * working setup dialog (experimental) @@ -1338,7 +1338,7 @@ xine (0.9.6) unstable; urgency=low -- Guenter Bartsch <guenter@users.sourceforge.net> Tue Nov 27 01:20:06 CET 2001 -xine (0.9.5) unstable; urgency=low +xine (0.9.5) 2001-11-23 * improved responsiveness (pause, stop, resume, seek) * catch segfaults when loading plugins @@ -1357,7 +1357,7 @@ xine (0.9.5) unstable; urgency=low -- Guenter Bartsch <guenter@users.sourceforge.net> Fri Nov 23 14:10:26 CET 2001 -xine (0.9.4) unstable; urgency=low +xine (0.9.4) 2001-11-04 * new SyncFB video out plugin (see README.syncfb) * catch SIGSEGV during libdivxdecore version probing. see README.divx4. @@ -1365,7 +1365,7 @@ xine (0.9.4) unstable; urgency=low -- Guenter Bartsch <guenter@users.sourceforge.net> Sun Nov 4 23:43:55 CET 2001 -xine (0.9.3) unstable; urgency=low +xine (0.9.3) 2001-11-02 * XShm gamma adjusting (brightness) * bugfix: lot skipped frames and low cpu @@ -1384,7 +1384,7 @@ xine (0.9.3) unstable; urgency=low * dxr3 still-menu/audio sync fixes / menu buttons now auto-display * dxr3 now keeps BCS values in .xinerc / Aspect ratio autodetection -xine (0.9.2) unstable; urgency=low +xine (0.9.2) 2001-10-16 * bugfixes * ogg/vorbis support @@ -1398,7 +1398,7 @@ xine (0.9.2) unstable; urgency=low -- Guenter Bartsch <guenter@users.sourceforge.net> Sun Oct 14 20:13:20 CEST 2001 -xine (0.9.1) unstable; urgency=low +xine (0.9.1) 2001-09-17 * support for subtitle names * new software deinterlacer (try --deinterlace; caution: CPU intensive!) @@ -1408,7 +1408,7 @@ xine (0.9.1) unstable; urgency=low -- Siggi Langauf <siggi@debian.org> Tue, 18 Sep 2001 01:48:38 +0200 -xine (0.9.0) unstable; urgency=low +xine (0.9.0) 2001-09-13 * generic menu support * many bugfixes @@ -1417,13 +1417,13 @@ xine (0.9.0) unstable; urgency=low -- Guenter Bartsch <guenter@users.sourceforge.net> Fri Sep 14 01:37:31 CEST 2001 -xine (0.5.3) unstable; urgency=low +xine (0.5.3) 2001-09-05 * small bugfix release -- Guenter Bartsch <guenter@users.sourceforge.net> Wed Sep 5 02:41:11 CEST 2001 -xine (0.5.2) unstable; urgency=low +xine (0.5.2) 2001-09-03 * many bugfixes * ffmpeg (mpeg4, opendivx ...) works on bigendian machines now @@ -1435,14 +1435,14 @@ xine (0.5.2) unstable; urgency=low -- Guenter Bartsch <guenter@users.sourceforge.net> Sun Sep 2 23:47:00 CEST 2001 -xine (0.5.1) unstable; urgency=low +xine (0.5.1) 2001-08-10 * ffmpeg plugin (OpenDivX, MS mpeg 4, motion-jpeg support) * various bugfixes -- Guenter Bartsch <guenter@users.sourceforge.net> Sat, 11 Aug 2001 01:39:12 +0200 -xine (0.5.0) unstable; urgency=low +xine (0.5.0) 2001-08-05 This is the big, long-awaited architecture change @@ -1459,7 +1459,7 @@ xine (0.5.0) unstable; urgency=low -- Guenter Bartsch <guenter@users.sourceforge.net> Sun, 22 Jul 2001 13:10:52 +0200 -xine (0.4.3) unstable; urgency=low +xine (0.4.3) 2001-05-16 This is a minor bugfix release @@ -1472,7 +1472,7 @@ xine (0.4.3) unstable; urgency=low -- Guenter Bartsch <guenter@users.sourceforge.net> Sun, 16 May 2001 22:59:00 +0200 -xine (0.4.2) unstable; urgency=low +xine (0.4.2) 2001-05-06 This is mainly a bugfix release for those who want a stable xine _now_, before the new, better, universal 0.5 architecture has stabilized. @@ -1490,7 +1490,7 @@ xine (0.4.2) unstable; urgency=low -- Siggi Langauf <siggi@debian.org> Sun, 6 May 2001 14:24:01 +0200 -xine (0.4.0) unstable; urgency=low +xine (0.4.0) 2001-03-02 * new multithreaded architecture - xine becomes idle * notable performance improvements @@ -1502,7 +1502,7 @@ xine (0.4.0) unstable; urgency=low -- Siggi Langauf <siggi@debian.org> Sat, 3 Mar 2001 01:36:39 +0100 -xine (0.3.7) unstable; urgency=low +xine (0.3.7) 2001-02-04 * subpicture/subtitle support * experimental AC3 digital output with some ALSA drivers @@ -1512,7 +1512,7 @@ xine (0.3.7) unstable; urgency=low -- Siggi Langauf <siggi@debian.org> Sun, 4 Feb 2001 14:44:23 +0100 -xine (0.3.6) unstable; urgency=low +xine (0.3.6) 2001-01-22 * support for field pictures * added autoprobing for audio driver @@ -1526,7 +1526,7 @@ xine (0.3.6) unstable; urgency=low -- Siggi Langauf <siggi@debian.org> Mon, 22 Jan 2001 02:06:08 +0100 -xine (0.3.5) unstable; urgency=low +xine (0.3.5) 2001-01-10 * (hopefully) fixed autoconf for Athlon processors * fixed aspect ratio calculation (=> SVCD support) @@ -1539,7 +1539,7 @@ xine (0.3.5) unstable; urgency=low -- Siggi Langauf <siggi@users.sourceforge.net> Wed, 10 Jan 2001 11:10:57 +0100 -xine (0.3.4) unstable; urgency=low +xine (0.3.4) 2001-01-08 * re-debianized package using debhelper (much cleaner debian packages) @@ -1550,8 +1550,7 @@ xine (0.3.4) unstable; urgency=low -- Siggi Langauf <siggi@users.sourceforge.net> Mon, 8 Jan 2001 04:03:11 +0100 - -xine (0.3.3) unstable; urgency=low +xine (0.3.3) 2001-01-04 * playlist, autoplay function * seamless branching @@ -1562,8 +1561,7 @@ xine (0.3.3) unstable; urgency=low -- Siggi Langauf <siggi@users.sourceforge.net> Thu, 04 Jan 2001 01:37:42 +0100 - -xine (0.3.2) unstable; urgency=low +xine (0.3.2) 2000-12-13 * audio rate up/downsampling * new yuv2rgb routines @@ -1577,16 +1575,14 @@ xine (0.3.2) unstable; urgency=low -- Siggi Langauf <siggi@users.sourceforge.net> Wed, 13 Dec 2000 02:44:18 +0100 - -xine (0.3.1p1) unstable; urgency=high +xine (0.3.1p1) 2000-11-21 * Bugfix for Debian package: 0.3.1 always segfaulted. This release should work... -- Siggi Langauf <siggi@users.sourceforge.net> Tue, 21 Nov 2000 21:43:18 +0100 - -xine (0.3.1) unstable; urgency=low +xine (0.3.1) 2000-11-20 * Initial release of Debian package. @@ -1598,36 +1594,42 @@ xine (0.3.1) unstable; urgency=low -- Siggi Langauf <siggi@users.sourceforge.net> Sun, 19 Nov 2000 15:33:28 +0100 -xine (0.3.0+older) unstable; urgency=low - - 0.3.0 - - NULL audio driver (ability to run without sound card) - - ALSA audio driver - - pause function - - simple playlist function - - massive performance improvements for xshm - through subslice output - - gui/skin improvements - - improved build process - - improved internal architecture - - many minor updates/bugfixes - - 0.2.4 - this is a maintenance/bugfix - release, just wanted to release all the small little changes - before we go for the next big architecture update that will - be in the 0.3.x series - - - 0.2.3 - - included patches by Alan Cox: - net_plugin, bug fixes (i.e. VCD ...) - - xshm video output module fixed for bpp>16 - (but don't use that for speed reasons!) - - new iDCT_mmx code from walken - => picture quality massively improved :)) - - FAQ update - - speed improvements due to new compiler switches - - minor Makefile fixes for FreeBSD ports +xine (0.3.0) 2000-11-18 + + - NULL audio driver (ability to run without sound card) + - ALSA audio driver + - pause function + - simple playlist function + - massive performance improvements for xshm through subslice output + - gui/skin improvements + - improved build process + - improved internal architecture + - many minor updates/bugfixes + +xine (0.2.4) 2000-10-30 + + - this is a maintenance/bugfix release, just wanted to release all the + small little changes before we go for the next big architecture update + that will be in the 0.3.x series + +xine (0.2.3) 2000-10-15 + + - included patches by Alan Cox: + net_plugin, bug fixes (i.e. VCD ...) + - xshm video output module fixed for bpp>16 + (but don't use that for speed reasons!) + - new iDCT_mmx code from walken + => picture quality massively improved :)) + - FAQ update + - speed improvements due to new compiler switches + - minor Makefile fixes for FreeBSD ports -- Siggi Langauf <siggi@users.sourceforge.net> Sun, 7 Jan 2001 23:59:12 +0100 + +xine (0.2.2) 2000-10-10 + +xine (0.2.1) 2000-10-10 + +xine (0.2.0) 2000-09-28 + +xine (0.1.3) 2000-08-17 -- cgit v1.2.3 From 87d72726273d21a3e61b68968c0be68762dc1ccb Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Wed, 23 Jan 2008 00:37:33 +0000 Subject: Finish the backport of libxine.pc.in; do xine-config (now requires pkg-config). Remove the "deprecated" warnings since xine-config is not deprecated in 1.1.x. --skindir no longer works. --HG-- rename : misc/xine-config.in => misc/xine-config --- ChangeLog | 2 + configure.ac | 18 ++++--- debian/control | 2 +- doc/man/en/xine-config.1 | 3 -- misc/libxine.pc.in | 12 +++++ misc/xine-config | 69 ++++++++++++++++++++++++++ misc/xine-config.in | 123 ----------------------------------------------- 7 files changed, 95 insertions(+), 134 deletions(-) create mode 100644 misc/xine-config delete mode 100644 misc/xine-config.in diff --git a/ChangeLog b/ChangeLog index b618b5099..104778708 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ xine-lib (1.1.10) (unreleased) * Unescape the filename in "#save:". This allows filenames to contain ';' etc. without ambiguity, e.g. "#save:foo%3B1.ts" -> "foo;1.ts", but front end authors should be careful with xine-lib older than 1.1.10. + * Backported xine-config & libxine.pc from 1.2. + Consequently, xine-config now requires pkg-config. xine-lib (1.1.9.1) 2008-01-11 * Security fixes: diff --git a/configure.ac b/configure.ac index 3797f7c63..884d64e8e 100644 --- a/configure.ac +++ b/configure.ac @@ -2392,9 +2392,14 @@ makeexpand () { echo "$i" } -XINE_PLUGINDIR="$libdir/xine/plugins/$XINE_MAJOR.$XINE_MINOR.$XINE_SUB$XINE_PATCH" -XINE_FONTDIR="${datadir}/xine/libxine$XINE_MAJOR/fonts" -XINE_LOCALEDIR="${datadir}/locale" +xinelibdir='${libdir}/xine' +xinedatadir='${datadir}/xine' +AC_SUBST(xinelibdir) +AC_SUBST(xinedatadir) + +XINE_PLUGINDIR="\${xinelibdir}/plugins/$XINE_MAJOR.$XINE_MINOR.$XINE_SUB$XINE_PATCH" +XINE_FONTDIR="\${xinedatadir}/xine/libxine$XINE_MAJOR/fonts" +XINE_LOCALEDIR='${datadir}/locale' XINE_REL_PLUGINDIR="`makeexpand "$XINE_PLUGINDIR"`" XINE_REL_PLUGINDIR="`makeexpand "$XINE_REL_PLUGINDIR" | sed -e "s,^${prefix}/,,"`" XINE_REL_FONTDIR="`makeexpand "$XINE_FONTDIR" | sed -e "s,^${prefix}/,,"`" @@ -2438,16 +2443,16 @@ AC_SUBST(XINE_FONTDIR) AC_SUBST(XINE_LOCALEDIR) dnl Where aclocal m4 files should be installed -XINE_ACFLAGS="-I `makeexpand "${datarootdir}/aclocal"`" +XINE_ACFLAGS="-I ${datarootdir}/aclocal" AC_DEFINE_UNQUOTED(XINE_ACFLAGS, "$XINE_ACFLAGS", [Path where aclocal m4 files will be.]) AC_SUBST(XINE_ACFLAGS) dnl Where architecture independent data (e.g. logo) will/should be installed -XINE_DATADIR="`makeexpand "${datarootdir}/xine"`" +XINE_DATADIR="\${xinedatadir}" AC_SUBST(XINE_DATADIR) dnl Where scripts will/should be installed. -eval XINE_SCRIPTPATH="$XINE_DATADIR/xine/scripts" +XINE_SCRIPTPATH="\${xinedatadir}/scripts" AC_SUBST(XINE_SCRIPTPATH) @@ -2651,7 +2656,6 @@ misc/build_rpms.sh misc/fonts/Makefile misc/libxine.pc misc/relchk.sh -misc/xine-config misc/xine-lib.spec po/Makefile.in src/Makefile diff --git a/debian/control b/debian/control index de1467cc5..a1faae54c 100644 --- a/debian/control +++ b/debian/control @@ -29,7 +29,7 @@ Standards-Version: 3.7.2 Package: libxine-dev Architecture: any Section: libdevel -Depends: libxine1 (= ${Source-Version}), libc6-dev, zlib1g-dev | libz-dev, libslang2-dev | slang1-dev, libfreetype6-dev +Depends: libxine1 (= ${Source-Version}), libc6-dev, zlib1g-dev | libz-dev, libslang2-dev | slang1-dev, libfreetype6-dev, pkg-config Conflicts: xine-ui (<< 0.9.10), libxine2-dev Description: the xine video player library, development packages This contains development files (headers, documentation and the like) diff --git a/doc/man/en/xine-config.1 b/doc/man/en/xine-config.1 index 0a2d8bcc6..accde1088 100644 --- a/doc/man/en/xine-config.1 +++ b/doc/man/en/xine-config.1 @@ -30,9 +30,6 @@ Print the compiler flags that are necessary to compile a program that uses .B \-\-plugindir Print the directory where \fIlibxine\fP plugins are stored/expected. .TP 8 -.B \-\-skindir -Print the directory in which \fIlibxine\fP skins are stored/expected. -.TP 8 .B \-\-prefix=PREFIX If specified, use PREFIX instead of the installation prefix that \fIxine-lib\fP was built with when computing the output for the \-\-cflags and diff --git a/misc/libxine.pc.in b/misc/libxine.pc.in index 623d2b657..a6565bad0 100644 --- a/misc/libxine.pc.in +++ b/misc/libxine.pc.in @@ -3,6 +3,18 @@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ +datarootdir=@datarootdir@ +datadir=@datadir@ + +xinelibdir=@xinelibdir@ +xinedatadir=@xinedatadir@ + +acflags=@XINE_ACFLAGS@ +plugindir=@XINE_PLUGINDIR@ +scriptdir=@XINE_SCRIPTPATH@ +localedir=@XINE_LOCALEDIR@ +objcflags=@OBJCFLAGS@ + Name: libxine Description: The xine engine library Version: @XINE_MAJOR@.@XINE_MINOR@.@XINE_SUB@@XINE_PATCH@ diff --git a/misc/xine-config b/misc/xine-config new file mode 100644 index 000000000..f5993f471 --- /dev/null +++ b/misc/xine-config @@ -0,0 +1,69 @@ +#!/bin/sh +# +# + +unset prefix +unset exec_prefix +unset args + +usage() +{ + cat <<EOF +Usage: xine-config [OPTIONS] [LIBRARIES] +Options: + [--prefix[=DIR]] + [--exec-prefix[=DIR]] + [--version] + [--libs] + [--acflags] + [--cflags] + [--plugindir] + [--datadir] + [--scriptdir] + [--localedir] + [--objcflags] +EOF + exit $1 +} + +if test $# -eq 0; then + usage 1 1>&2 +fi + +while test $# -gt 0; do + case "$1" in + -*=*) optarg="${1#--*=}" ;; + *) optarg= ;; + esac + + case "$1" in + --prefix=*) + prefix="$optarg" + if [ "$exec_prefix" = '' ]; then + exec_prefix="$optarg" + fi + ;; + --exec-prefix=*) + exec_prefix="$optarg" + ;; + --prefix|--exec-prefix) + ;; + --version) + args="$args${args+ }--modversion" + ;; + --cflags|--libs) + args="$args${args+ }$1" + ;; + --acflags|--plugindir|--datadir|--scriptdir|--localedir|--objcflags) + args="$args${args+ }--variable=${1#--}" + ;; + *) + usage 1 1>&2 + ;; + esac + shift +done + +exec pkg-config "${prefix+--define-variable=prefix=}$prefix" \ + "${exec_prefix+--define-variable=exc_prefix=}$exec_prefix" \ + $args libxine diff --git a/misc/xine-config.in b/misc/xine-config.in deleted file mode 100644 index 8f25d5cc5..000000000 --- a/misc/xine-config.in +++ /dev/null @@ -1,123 +0,0 @@ -#!/bin/sh -# -# - -prefix=@XINE_CONFIG_PREFIX@ -exec_prefix=@exec_prefix@ -exec_prefix_set=no - -usage() -{ - cat <<EOF -Usage: xine-config [OPTIONS] [LIBRARIES] -Options: - [--prefix[=DIR]] - [--exec-prefix[=DIR]] - [--version] - [--libs] - [--acflags] - [--cflags] - [--plugindir] - [--datadir] - [--scriptdir] - [--localedir] - [--objcflags] -EOF - exit $1 -} - -if test $# -eq 0; then - usage 1 1>&2 -fi - -while test $# -gt 0; do - case "$1" in - -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; - *) optarg= ;; - esac - - case $1 in - --prefix=*) - prefix=$optarg - if test $exec_prefix_set = no ; then - exec_prefix=$optarg - fi - ;; - --prefix) - echo_prefix=yes - ;; - --exec-prefix=*) - exec_prefix=$optarg - exec_prefix_set=yes - ;; - --exec-prefix) - echo_exec_prefix=yes - ;; - --version) - echo @XINE_MAJOR@.@XINE_MINOR@.@XINE_SUB@@XINE_PATCH@ - ;; - --acflags) - echo_acflags=yes - ;; - --cflags) - echo_cflags=yes - ;; - --libs) - echo_libs=yes - ;; - --plugindir) - echo_plugindir=yes - ;; - --datadir) - echo_datadir=yes - ;; - --scriptdir) - echo_scriptdir=yes - ;; - --localedir) - echo_localedir=yes - ;; - --objcflags) - echo_objcflags=yes - ;; - *) - usage 1 1>&2 - ;; - esac - shift -done - -if test "$echo_prefix" = "yes"; then - echo $prefix -fi - -if test "$echo_exec_prefix" = "yes"; then - echo $exec_prefix -fi - -if test "$echo_acflags" = "yes"; then - echo "@XINE_ACFLAGS@" -fi - -if test "$echo_cflags" = "yes"; then - echo -I@includedir@ @PTHREAD_CFLAGS@ -fi - -if test "$echo_libs" = "yes"; then - echo -L@libdir@ -lxine @ZLIB_LIBS@ @NET_LIBS@ @PTHREAD_LIBS@ @LIBICONV@ @RT_LIBS@ -fi -if test "$echo_plugindir" = "yes"; then - echo "@XINE_PLUGINPATH@" -fi -if test "$echo_datadir" = "yes"; then - echo "@XINE_DATADIR@" -fi -if test "$echo_scriptdir" = "yes"; then - echo "@XINE_SCRIPTPATH@" -fi -if test "$echo_localedir" = "yes"; then - echo "@XINE_LOCALEPATH@" -fi -if test "$echo_objcflags" = "yes"; then - echo "@OBJCFLAGS@" -fi -- cgit v1.2.3 From a5203938aa08ae901dc0383848afe13272d345d6 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Wed, 23 Jan 2008 00:45:13 +0000 Subject: Fix xine-config bugs related to --prefix & --exec-prefix. Output the values, and correctly set exec_prefix. --- misc/xine-config | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/misc/xine-config b/misc/xine-config index f5993f471..3e67e5dc7 100644 --- a/misc/xine-config +++ b/misc/xine-config @@ -42,11 +42,11 @@ while test $# -gt 0; do if [ "$exec_prefix" = '' ]; then exec_prefix="$optarg" fi + args="$args${args+ }--variable=prefix" ;; --exec-prefix=*) exec_prefix="$optarg" - ;; - --prefix|--exec-prefix) + args="$args${args+ }--variable=exec_prefix" ;; --version) args="$args${args+ }--modversion" @@ -54,9 +54,12 @@ while test $# -gt 0; do --cflags|--libs) args="$args${args+ }$1" ;; - --acflags|--plugindir|--datadir|--scriptdir|--localedir|--objcflags) + --prefix|--acflags|--plugindir|--datadir|--scriptdir|--localedir|--objcflags) args="$args${args+ }--variable=${1#--}" ;; + --exec-prefix) + args="$args${args+ }--variable=exec_prefix" + ;; *) usage 1 1>&2 ;; @@ -65,5 +68,5 @@ while test $# -gt 0; do done exec pkg-config "${prefix+--define-variable=prefix=}$prefix" \ - "${exec_prefix+--define-variable=exc_prefix=}$exec_prefix" \ + "${exec_prefix+--define-variable=exec_prefix=}$exec_prefix" \ $args libxine -- cgit v1.2.3 From 86ecb07bd758c92b590439877fd6aac09603f249 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Wed, 23 Jan 2008 01:05:02 +0000 Subject: Revert the --{,exec-}prefix=* changes (to match the old xine-config). --- misc/xine-config | 2 -- 1 file changed, 2 deletions(-) diff --git a/misc/xine-config b/misc/xine-config index 3e67e5dc7..5723a1a46 100644 --- a/misc/xine-config +++ b/misc/xine-config @@ -42,11 +42,9 @@ while test $# -gt 0; do if [ "$exec_prefix" = '' ]; then exec_prefix="$optarg" fi - args="$args${args+ }--variable=prefix" ;; --exec-prefix=*) exec_prefix="$optarg" - args="$args${args+ }--variable=exec_prefix" ;; --version) args="$args${args+ }--modversion" -- cgit v1.2.3 From 3f51525e97a2787611a2cbf91dd609c7f2ddb2fb Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Wed, 23 Jan 2008 18:29:51 +0000 Subject: Add missing CVE nos. --- ChangeLog | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 104778708..0442e5d2d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,7 +12,8 @@ xine-lib (1.1.10) (unreleased) xine-lib (1.1.9.1) 2008-01-11 * Security fixes: - Buffer overflow which allows a remote attacker to execute arbitrary - code via a crafted SDP Abstract attribute. (CVE-2008-0225) + code via a crafted SDP Abstract attribute. + (CVE-2008-0225, a.k.a. CVE-2008-0238) (Fix ported from mplayer changeset 22821) * Fix a read-past-end bug in xine-lib's internal strtok_r replacement. (Only affects systems without strtok_r.) [Bug #19] @@ -137,8 +138,9 @@ xine-lib (1.1.6) 2007-04-17 xine-lib (1.1.5) 2007-04-10 * Security fixes: - - Fix heap overflow in DMO loader. (CVE-2007-1246) [Bug SF 1676925] + - Fix heap overflow in DMO and DirectShow loaders. Thanks to Kees Cook for reporting. + (CVE-2007-1246 & CVE-2007-1387) [Bug SF 1676925] * Improved PulseAudio plugin, now only one connection per instance is opened and the mainloop is threaded to reduce latency during playback. * Added XCB-based output plugins (Xv and XShm), to use in software using @@ -258,8 +260,9 @@ xine-lib (1.1.4) 2007-01-28 xine-lib (1.1.3) 2006-12-03 * Security fixes: - Heap overflow in libmms (related to CVE-2006-2200) - - Buffer overrun in Real Media input plugin. [Bug SF 1603458] + - Buffer overrun in Real Media input plugin. Thanks to Roland Kay for reporting and JW for the patch. + (CVE-2006-6172) [Bug SF 1603458] * Update build system to support x86 Darwin setups, and merge patches to support Darwin OS better. * Replace custom ALSA check with pkg-config check, and make sure 0.9.0 is -- cgit v1.2.3 From 3a3fa364d3380c95f453f8f225a601279d8ed056 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Wed, 23 Jan 2008 19:40:16 +0000 Subject: Sanity-check ASF header sizes. This fixes a crash in the ASF demuxer, caused by the example exploit file given for CVE-2006-1664. --- ChangeLog | 2 ++ src/demuxers/demux_asf.c | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0442e5d2d..3dfa097e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,8 @@ xine-lib (1.1.10) (unreleased) end authors should be careful with xine-lib older than 1.1.10. * Backported xine-config & libxine.pc from 1.2. Consequently, xine-config now requires pkg-config. + * Sanity-check ASF header sizes. This fixes a crash in the ASF demuxer, + caused by the example exploit given for CVE-2006-1664. xine-lib (1.1.9.1) 2008-01-11 * Security fixes: diff --git a/src/demuxers/demux_asf.c b/src/demuxers/demux_asf.c index c4a154f99..4eb9398be 100644 --- a/src/demuxers/demux_asf.c +++ b/src/demuxers/demux_asf.c @@ -379,10 +379,21 @@ static int asf_read_header (demux_asf_t *this) { char *asf_header_buffer = NULL; asf_header_len = get_le64(this); - asf_header_buffer = alloca(asf_header_len); + if (asf_header_len > 4 * 1024 * 1024) + { + xprintf(this->stream->xine, XINE_VERBOSITY_DEBUG, + "demux_asf: asf_read_header: overly-large header? (%"PRIu64" bytes)\n", + asf_header_len); + return 0; + } + + asf_header_buffer = malloc (asf_header_len); if (this->input->read (this->input, asf_header_buffer, asf_header_len) != asf_header_len) + { + free (asf_header_buffer); return 0; + } /* delete previous header */ if (this->asf_header) { @@ -395,7 +406,11 @@ static int asf_read_header (demux_asf_t *this) { */ this->asf_header = asf_header_new(asf_header_buffer, asf_header_len); if (!this->asf_header) + { + free (asf_header_buffer); return 0; + } + free (asf_header_buffer); lprintf("asf header parsing ok\n"); -- cgit v1.2.3 From a6e720ee0284c0c9ec6eb5894ab8e87ee1e53f09 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern <thibaut.mattern@gmail.com> Date: Thu, 24 Jan 2008 19:28:43 +0100 Subject: Don't discard audio samples forever. Fixed streaming playback --- ChangeLog | 1 + src/xine-engine/audio_out.c | 1 + 2 files changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index 3dfa097e0..2b88720f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ xine-lib (1.1.10) (unreleased) Consequently, xine-config now requires pkg-config. * Sanity-check ASF header sizes. This fixes a crash in the ASF demuxer, caused by the example exploit given for CVE-2006-1664. + * Don't discard audio samples forever. Fixed streaming playback. xine-lib (1.1.9.1) 2008-01-11 * Security fixes: diff --git a/src/xine-engine/audio_out.c b/src/xine-engine/audio_out.c index 7fe92d9fe..e9bda70fb 100644 --- a/src/xine-engine/audio_out.c +++ b/src/xine-engine/audio_out.c @@ -1619,6 +1619,7 @@ static void ao_close(xine_audio_port_t *this_gen, xine_stream_t *stream) { } /* make sure there are no more buffers on queue */ fifo_wait_empty(this->out_fifo); + ao_set_property(this_gen, AO_PROP_DISCARD_BUFFERS, 0); } pthread_mutex_lock( &this->driver_lock ); -- cgit v1.2.3 From e2dd04a9d3cd3549a409c50107810242d5320fac Mon Sep 17 00:00:00 2001 From: Manfred Tremmel <Manfred.Tremmel@iiv.de> Date: Thu, 24 Jan 2008 19:30:37 +0000 Subject: spec-file update - stk and arts plugins are no longer build by default, enable them, when subpackages are selected - added optional subpackage for pulseaudio - switched to external vcdlibs - using macros for shell commands, when rpm provides them - some other cleanups - some little changes to enable caca plugin --- misc/xine-lib.spec.in | 351 ++++++++++++++++++++++++++++---------------------- 1 file changed, 195 insertions(+), 156 deletions(-) diff --git a/misc/xine-lib.spec.in b/misc/xine-lib.spec.in index 6382b9b9a..453ffa306 100644 --- a/misc/xine-lib.spec.in +++ b/misc/xine-lib.spec.in @@ -66,6 +66,9 @@ %if %{?BUILD_JACK:0}%{!?BUILD_JACK:1} %define BUILD_JACK 0 %endif +%if %{?BUILD_PULSE:0}%{!?BUILD_PULSE:1} +%define BUILD_PULSE 0 +%endif Name: %{name} Summary: A portable video/audio library for unix-like systems. @@ -77,7 +80,7 @@ Release: %{release} License: GPL Group: Development/Libraries URL: http://xinehq.de -Source: http://xinehq.de/files/@PACKAGE@-@VERSION@.tar.gz +Source: http://xinehq.de/files/@PACKAGE@-@VERSION@.tar.bz2 Packager: Manfred Tremmel <Manfred.Tremmel@iiv.de> Obsoletes: xine Obsoletes: xine-lib @@ -145,20 +148,21 @@ lisenssin kanssa yhteensopivia. lisätietoja GPL-lisenssistä löytyy osoitteest http://www.gnu.org/licenses/gpl.html %if %BUILD_DEVEL -%package devel +%package -n %{shortname}-devel Summary: Header files and documentation to develope programs with libxine. Summary(cs): HlaviÄkové soubory a dokumentace pro vývoj programů používající libxine Summary(de): Headerdateien und Dokumentationen, um Programme mit libxine entwickeln zu können. Summary(fi): Header-tiedostot ja dokumentaatio, joita tarvitset kehittäessäsi ohjelmia libxine:n kanssa. -Group: Development/Libraries +Group: Development/Libraries Obsoletes: xine-lib-devel Obsoletes: xine-devel Obsoletes: libxine0-devel -Provides: %{shortname}-devel = %{version}-%{release} +Obsoletes: %{name}-devel +Provides: %{name}-devel = %{version}-%{release} Provides: xine-devel Requires: %{libname} = %{version}-%{release} -%description devel +%description -n %{shortname}-devel This package contains header files and documentation required to develope programs with libxine. @@ -173,7 +177,7 @@ Don't hesitate to use libxine in your own projects as long as your usage complies to the GPL. More information about GPL-license can be found at http://www.gnu.org/licenses/gpl.html -%description devel -l cs +%description -n %{shortname}-devel -l cs Tento balíÄek obsahuje hlaviÄkové soubory a dokumentaci potÅ™ebnou pro vývoj programů, které používají libxine. @@ -188,7 +192,7 @@ Dokud to bude ve shodÄ› s GPL, neváhejte použít libxine ve vaÅ¡ich vlastních projektech. Více informací o GPL licenci můžete nalézt na http://www.gnu.org/licenses/gpl.html. -%description devel -l de +%description -n %{shortname}-devel -l de Dieses Paket enthält die Headerdateien und Dokumentationen, um Programme mit libxine entwickeln zu können. @@ -205,7 +209,7 @@ Zögern Sie nicht libxine in Ihren eigenen Projekten zu nutzen. Beachten Sie hierzu jedoch die in der GPL Lizenz vereinbarten Bestimmungen. Weitere Informationen zur GPL-Lizenz finden Sie unter http://www.gnu.org/licenses/gpl.html -%description devel -l fi +%description -n %{shortname}-devel -l fi libxine on xinen sydän (vapaa GPL-linsensoitu videosoitinohjelma Unix-tyylisille käyttöjärjestelmille), joka muun muassa tarjoaa mahdollisuudet pakatun videon ja äänen purkamiseen (sekä näyttämiseen) suurimmalla osalla nykyaikaista äänen- @@ -547,7 +551,6 @@ libxine Videoausgabeplugin per libstk (Set-top Toolkit) %endif %if %BUILD_DXR3 -%ifarch i386 i486 i586 i686 i786 i868 i986 k6 k7 athlon x86_64 amd64 ia32e %package dxr3 Summary: libxine video output plugin using mpeg2 decoding cards with dxr3 decoder-chip Summary(cs): Videovýstupní modul libxine používající karty s Äipem DXR3 @@ -571,10 +574,8 @@ libxine Videoausgabeplugin, nutzt MPEG2-decoder-Karten mit dxr3 Decoder-Chip %description dxr3 -l fi libxine-Videolisdke MPEG2-videopurkukorteille, joissa on DXR3 purkusiru %endif -%endif %if %BUILD_XVMC -%ifarch i386 i486 i586 i686 i786 i868 i986 k6 k7 athlon x86_64 amd64 ia32e %package xvmc Summary: libxine video output plugin using XVideo-extension with motion compensation Summary(cs): Videovýstupní modul libxine používající rozšíření XVideo MC @@ -593,7 +594,6 @@ Videovýstupní modul libxine, který používá rozšíření XVideo s kompenza %description xvmc -l de libxine Videoausgabeplugin per XVideo-Erweiterung mit Motion Compensation %endif -%endif %if %BUILD_W32DLL %ifarch i386 i486 i586 i686 i786 i868 i986 k6 k7 athlon @@ -624,7 +624,7 @@ libxine-Purkulisdke, joka mahdollistaa Win32 DLL:n kdytvn. %if %BUILD_JACK %package jack -Summary: libxine sound output plugin for the jack sooundserver +Summary: libxine sound output plugin for the jack soundserver Summary(de): libxine Soundausgabeplugin für den jack-Soundserver Group: Development/Libraries Obsoletes: xine-lib-jack @@ -632,7 +632,7 @@ Obsoletes: libxine0-jack Requires: %{libname} = %{version}-%{release} %description jack -libxine sound output plugin for the jack sooundserver +libxine sound output plugin for the jack soundserver %description jack -l cs Zvukový výstupní modul libxine pro zvukový server jack. @@ -641,12 +641,33 @@ Zvukový výstupní modul libxine pro zvukový server jack. libxine Soundausgabeplugin für den jack-Soundserver %endif +%if %BUILD_PULSE +%package pulse +Summary: libxine sound output plugin for the pulseaudio soundserver +Summary(de): libxine Soundausgabeplugin für den pulseaudio-Soundserver +Group: Development/Libraries +Obsoletes: xine-lib-pulse +Obsoletes: libxine0-pulse +Requires: %{libname} = %{version}-%{release} + +%description pulse +libxine sound output plugin for the pulseaudio soundserver + +%description pulse -l cs +Zvukový výstupní modul libxine pro zvukový server pulseaudio. + +%description pulse -l de +libxine Soundausgabeplugin für den pulseaudio-Soundserver +%endif + + %prep %setup -q -n @TAR_NAME@ %build export CFLAGS="${RPM_OPT_FLAGS}" -export XINE_DOCPATH="%{_docdir}/libxine1" +export XINE_DOCPATH="%{_docdir}/%{name}" +export PKG_CONFIG="%{_bindir}/pkg-config" if [ ! -f configure ]; then NO_CONFIGURE=1 ./autogen.sh @@ -665,286 +686,304 @@ fi --localstatedir=%{_localstatedir} \ --sharedstatedir=%{_sharedstatedir} --mandir=%{_mandir} \ --infodir=%{_infodir} --enable-directfb --enable-modplug \ - --with-internal-vcdlibs +%if %BUILD_STK + --with-libstk \ +%endif +%if %BUILD_ARTS + --with-arts \ +%endif + --enable-syncfb --without-internal-vcdlibs # Error in libfaad when compiling with mmx or sse enabled, remove it -mv src/libfaad/Makefile src/libfaad/Makefile_save -cat src/libfaad/Makefile_save | sed -e "s/-mmmx/-mno-mmx/g" -e "s/-msse/-mno-sse/g" > src/libfaad/Makefile +%{__mv} src/libfaad/Makefile src/libfaad/Makefile_save +%{__cat} src/libfaad/Makefile_save | %{__sed} -e "s/-mmmx/-mno-mmx/g" -e "s/-msse/-mno-sse/g" > src/libfaad/Makefile # another problem with libavcodec -mv src/libffmpeg/libavcodec/i386/Makefile src/libffmpeg/libavcodec/i386/Makefile_save -cat src/libffmpeg/libavcodec/i386/Makefile_save | sed -e "s/-O3/-Os/g" -e "s/-O2/-Os/g" > src/libffmpeg/libavcodec/i386/Makefile +%{__mv} src/libffmpeg/libavcodec/i386/Makefile src/libffmpeg/libavcodec/i386/Makefile_save +%{__cat} src/libffmpeg/libavcodec/i386/Makefile_save | %{__sed} -e "s/-O3/-Os/g" -e "s/-O2/-Os/g" > src/libffmpeg/libavcodec/i386/Makefile -make +%{__make} %{?jobs:-j%{jobs}} %install -rm -rf $RPM_BUILD_ROOT +[ "${RPM_BUILD_ROOT}" != "/" ] && %{__rm} -rf ${RPM_BUILD_ROOT} make DESTDIR=%{?buildroot:%{buildroot}} LIBRARY_PATH=%{?buildroot:%{buildroot}}%{_libdir} install cd ${RPM_BUILD_ROOT} -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_zw +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_zw %if %BUILD_DEVEL -echo "%doc README TODO AUTHORS COPYING ChangeLog" >> ${RPM_BUILD_DIR}/filelist_libxine1_zw +echo "%doc README TODO AUTHORS COPYING ChangeLog" >> ${RPM_BUILD_DIR}/filelist_%{name}_zw %else -echo "%doc README TODO AUTHORS COPYING ChangeLog doc/hackersguide/*.sgml doc/hackersguide/*.fig doc/hackersguide/README" >> ${RPM_BUILD_DIR}/filelist_libxine1_zw +echo "%doc README TODO AUTHORS COPYING ChangeLog doc/hackersguide/*.sgml doc/hackersguide/*.fig doc/hackersguide/README" >> ${RPM_BUILD_DIR}/filelist_%{name}_zw %endif -find . -type f | sed 's,^\.%{_datadir}/doc,\%doc %{_datadir}/doc,' | sed 's,^\.,,' >> ${RPM_BUILD_DIR}/filelist_libxine1_zw -find . -type l | sed 's,^\.%{_datadir}/doc,\%doc %{_datadir}/doc,' | sed 's,^\.,,' >> ${RPM_BUILD_DIR}/filelist_libxine1_zw -find . -type d | grep xine | sed 's,^\.,\%dir ,' >> ${RPM_BUILD_DIR}/filelist_libxine1_zw -grep -v "/man/" ${RPM_BUILD_DIR}/filelist_libxine1_zw | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -grep "/man/" ${RPM_BUILD_DIR}/filelist_libxine1_zw | sed -e 's/$/\*/g' | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_zw +find . -type f | %{__sed} 's,^\.%{_datadir}/doc,\%doc %{_datadir}/doc,' | %{__sed} 's,^\.,,' >> ${RPM_BUILD_DIR}/filelist_%{name}_zw +find . -type l | %{__sed} 's,^\.%{_datadir}/doc,\%doc %{_datadir}/doc,' | %{__sed} 's,^\.,,' >> ${RPM_BUILD_DIR}/filelist_%{name}_zw +find . -type d | %{__grep} xine | %{__sed} 's,^\.,\%dir ,' >> ${RPM_BUILD_DIR}/filelist_%{name}_zw +%{__grep} -v "/man/" ${RPM_BUILD_DIR}/filelist_%{name}_zw | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__grep} "/man/" ${RPM_BUILD_DIR}/filelist_%{name}_zw | %{__sed} -e 's/$/\*/g' | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_zw %if %BUILD_DEVEL -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_devel -echo "%doc doc/hackersguide/*.sgml doc/hackersguide/*.fig doc/hackersguide/README" >> ${RPM_BUILD_DIR}/filelist_libxine1_devel -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep -E "/include/|dhahelper\.o|libxine*\.(so|la)$|\.m4$" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_devel -grep -v -E "/include/|dhahelper\.o|libxine*\.(so|la)$|\.m4$" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_devel +echo "%doc doc/hackersguide/*.sgml doc/hackersguide/*.fig doc/hackersguide/README" >> ${RPM_BUILD_DIR}/filelist_%{name}_devel +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} -E "/include/|dhahelper\.o|libxine*\.(so|la)$|\.m4$" ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_devel +%{__grep} -v -E "/include/|dhahelper\.o|libxine*\.(so|la)$|\.m4$" ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %if %BUILD_ALSA -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_alsa -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep "xineplug_ao_out_alsa\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_alsa -grep -v "xineplug_ao_out_alsa\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_alsa +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} "xineplug_ao_out_alsa\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_alsa +%{__grep} -v "xineplug_ao_out_alsa\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %if %BUILD_ARTS -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_arts -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep "xineplug_ao_out_arts\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_arts -grep -v "xineplug_ao_out_arts\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_arts +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} "xineplug_ao_out_arts\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_arts +%{__grep} -v "xineplug_ao_out_arts\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %if %BUILD_ESD -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_esd -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep "xineplug_ao_out_esd\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_esd -grep -v "xineplug_ao_out_esd\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_esd +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} "xineplug_ao_out_esd\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_esd +%{__grep} -v "xineplug_ao_out_esd\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %if %BUILD_DXR3 -%ifarch i386 i486 i586 i686 i786 i868 i986 k6 k7 athlon x86_64 amd64 ia32e -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_dxr3 -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep "dxr3" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_dxr3 -grep -v "dxr3" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old -%endif +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_dxr3 +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} "dxr3" ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_dxr3 +%{__grep} -v "dxr3" ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %if %BUILD_SDL -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_sdl -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep "xineplug_vo_out_sdl\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_sdl -grep -v "xineplug_vo_out_sdl\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_sdl +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} "xineplug_vo_out_sdl\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_sdl +%{__grep} -v "xineplug_vo_out_sdl\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %if %BUILD_AA -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_aa -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep "xineplug_vo_out_aa\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_aa -grep -v "xineplug_vo_out_aa\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_aa +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} "xineplug_vo_out_aa\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_aa +%{__grep} -v "xineplug_vo_out_aa\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %if %BUILD_OPENGL -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_opengl -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep -E "xineplug_vo_out_opengl\.|README.opengl" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_opengl -grep -v -E "xineplug_vo_out_opengl\.|README.opengl" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_opengl +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} -E "xineplug_vo_out_opengl\.|README.opengl" ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_opengl +%{__grep} -v -E "xineplug_vo_out_opengl\.|README.opengl" ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %if %BUILD_SYNCFB -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_syncfb -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep -E "xineplug_vo_out_syncfb\.|README\.syncfb" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_syncfb -grep -v -E "xineplug_vo_out_syncfb\.|README\.syncfb" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_syncfb +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} -E "xineplug_vo_out_syncfb\.|README\.syncfb" ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_syncfb +%{__grep} -v -E "xineplug_vo_out_syncfb\.|README\.syncfb" ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %if %BUILD_DIRECTFB -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_directfb -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep -E "xineplug_vo_out_directfb\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_directfb -grep -v -E "xineplug_vo_out_directfb\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_directfb +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} -E "xineplug_vo_out_(xd|d)irectfb\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_directfb +%{__grep} -v -E "xineplug_vo_out_(xd|d)irectfb\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %if %BUILD_STK -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_stk -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep -E "xineplug_vo_out_stk\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_stk -grep -v -E "xineplug_vo_out_stk\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_stk +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} -E "xineplug_vo_out_stk\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_stk +%{__grep} -v -E "xineplug_vo_out_stk\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %if %BUILD_XVMC -%ifarch i386 i486 i586 i686 i786 i868 i986 k6 k7 athlon x86_64 amd64 ia32e -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_xvmc -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep "xineplug_vo_out_x[x|v]mc\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_xvmc -grep -v "xineplug_vo_out_x[x|v]mc\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old -%endif +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_xvmc +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} "xineplug_vo_out_x[x|v]mc\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_xvmc +%{__grep} -v "xineplug_vo_out_x[x|v]mc\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %if %BUILD_W32DLL %ifarch i386 i486 i586 i686 i786 i868 i986 k6 k7 athlon -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_w32dll -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep -E "xineplug_decode_qt\.|xineplug_decode_w32dll\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_w32dll -grep -v -E "xineplug_decode_qt\.|xineplug_decode_w32dll\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_w32dll +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} -E "xineplug_decode_qt\.|xineplug_decode_w32dll\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_w32dll +%{__grep} -v -E "xineplug_decode_qt\.|xineplug_decode_w32dll\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %endif %if %BUILD_DVB -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_dvb -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep -E "xineplug_inp_dvb\.|README\.dvb" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_dvb -grep -v -E "xineplug_inp_dvb\.|README\.dvb" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_dvb +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} -E "xineplug_inp_dvb\.|README\.dvb" ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_dvb +%{__grep} -v -E "xineplug_inp_dvb\.|README\.dvb" ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %if %BUILD_DVD -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_dvd -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep -E "xineplug_inp_dvd\.|README\.network_dvd" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_dvd -grep -v -E "xineplug_inp_dvd\.|README\.network_dvd" ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_dvd +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} -E "xineplug_inp_dvd\.|README\.network_dvd" ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_dvd +%{__grep} -v -E "xineplug_inp_dvd\.|README\.network_dvd" ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %if %BUILD_GNOME_VFS -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_gnome_vfs -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep "xineplug_inp_gnome_vfs\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_gnome_vfs -grep -v "xineplug_inp_gnome_vfs\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_gnome_vfs +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} "xineplug_inp_gnome_vfs\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_gnome_vfs +%{__grep} -v "xineplug_inp_gnome_vfs\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %if %BUILD_FLAC -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_flac -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep "xineplug_flac\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_flac -grep -v "xineplug_flac\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_flac +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} "xineplug_flac\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_flac +%{__grep} -v "xineplug_flac\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %if %BUILD_OGG -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_ogg -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep -E "xineplug_decode_vorbis\.|xineplug_dmx_ogg\.|xineplug_decode_theora\.|xineplug_decode_speex\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_ogg -grep -v -E "xineplug_decode_vorbis\.|xineplug_dmx_ogg\.|xineplug_decode_theora\.|xineplug_decode_speex\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_ogg +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} -E "xineplug_decode_vorbis\.|xineplug_dmx_ogg\.|xineplug_decode_theora\.|xineplug_decode_speex\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_ogg +%{__grep} -v -E "xineplug_decode_vorbis\.|xineplug_dmx_ogg\.|xineplug_decode_theora\.|xineplug_decode_speex\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %if %BUILD_JACK -echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_libxine1_jack -mv ${RPM_BUILD_DIR}/filelist_libxine1 ${RPM_BUILD_DIR}/filelist_libxine1_old -grep "xineplug_ao_out_jack\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - >> ${RPM_BUILD_DIR}/filelist_libxine1_jack -grep -v "xineplug_ao_out_jack\." ${RPM_BUILD_DIR}/filelist_libxine1_old | cat - > ${RPM_BUILD_DIR}/filelist_libxine1 -rm ${RPM_BUILD_DIR}/filelist_libxine1_old +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_jack +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} "xineplug_ao_out_jack\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_jack +%{__grep} -v "xineplug_ao_out_jack\." ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old +%endif +%if %BUILD_PULSE +echo "%defattr(-,root,root)" > ${RPM_BUILD_DIR}/filelist_%{name}_pulse +%{__mv} ${RPM_BUILD_DIR}/filelist_%{name} ${RPM_BUILD_DIR}/filelist_%{name}_old +%{__grep} "xineplug_ao_out_pulse" ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - >> ${RPM_BUILD_DIR}/filelist_%{name}_pulse +%{__grep} -v "xineplug_ao_out_pulse" ${RPM_BUILD_DIR}/filelist_%{name}_old | %{__cat} - > ${RPM_BUILD_DIR}/filelist_%{name} +%{__rm} ${RPM_BUILD_DIR}/filelist_%{name}_old %endif %clean -[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT +[ "${RPM_BUILD_ROOT}" != "/" ] && %{__rm} -rf ${RPM_BUILD_ROOT} %post -p /sbin/ldconfig %postun -p /sbin/ldconfig -%files -f ../filelist_libxine1 +%files -f ../filelist_%{name} %if %BUILD_DEVEL -%files devel -f ../filelist_libxine1_devel +%files -n %{shortname}-devel -f ../filelist_%{name}_devel %endif %if %BUILD_ALSA -%files alsa -f ../filelist_libxine1_alsa +%files alsa -f ../filelist_%{name}_alsa %endif %if %BUILD_ARTS -%files arts -f ../filelist_libxine1_arts +%files arts -f ../filelist_%{name}_arts %endif %if %BUILD_ESD -%files esd -f ../filelist_libxine1_esd +%files esd -f ../filelist_%{name}_esd %endif %if %BUILD_DXR3 -%ifarch i386 i486 i586 i686 i786 i868 i986 k6 k7 athlon x86_64 amd64 ia32e -%files dxr3 -f ../filelist_libxine1_dxr3 -%endif +%files dxr3 -f ../filelist_%{name}_dxr3 %endif %if %BUILD_SDL -%files sdl -f ../filelist_libxine1_sdl +%files sdl -f ../filelist_%{name}_sdl %endif %if %BUILD_AA -%files aa -f ../filelist_libxine1_aa +%files aa -f ../filelist_%{name}_aa %endif %if %BUILD_OPENGL -%files opengl -f ../filelist_libxine1_opengl +%files opengl -f ../filelist_%{name}_opengl %endif %if %BUILD_SYNCFB -%files syncfb -f ../filelist_libxine1_syncfb +%files syncfb -f ../filelist_%{name}_syncfb %endif %if %BUILD_DIRECTFB -%files directfb -f ../filelist_libxine1_directfb +%files directfb -f ../filelist_%{name}_directfb %endif %if %BUILD_STK -%files stk -f ../filelist_libxine1_stk +%files stk -f ../filelist_%{name}_stk %endif %if %BUILD_XVMC -%ifarch i386 i486 i586 i686 i786 i868 i986 k6 k7 athlon x86_64 amd64 ia32e -%files xvmc -f ../filelist_libxine1_xvmc -%endif +%files xvmc -f ../filelist_%{name}_xvmc %endif %if %BUILD_W32DLL %ifarch i386 i486 i586 i686 i786 i868 i986 k6 k7 athlon -%files w32dll -f ../filelist_libxine1_w32dll +%files w32dll -f ../filelist_%{name}_w32dll %endif %endif %if %BUILD_DVB -%files dvb -f ../filelist_libxine1_dvb +%files dvb -f ../filelist_%{name}_dvb %endif %if %BUILD_DVD -%files dvd -f ../filelist_libxine1_dvd +%files dvd -f ../filelist_%{name}_dvd %endif %if %BUILD_GNOME_VFS -%files gnome-vfs -f ../filelist_libxine1_gnome_vfs +%files gnome-vfs -f ../filelist_%{name}_gnome_vfs %endif %if %BUILD_FLAC -%files flac -f ../filelist_libxine1_flac +%files flac -f ../filelist_%{name}_flac %endif %if %BUILD_OGG -%files ogg -f ../filelist_libxine1_ogg +%files ogg -f ../filelist_%{name}_ogg %endif %if %BUILD_JACK -%files jack -f ../filelist_libxine1_jack +%files jack -f ../filelist_%{name}_jack +%endif + +%if %BUILD_PULSE +%files pulse -f ../filelist_%{name}_pulse %endif %changelog +* Sun Dec 09 2007 Manfred Tremmel <Manfred.Tremmel@iiv.de> +- stk and arts plugins are no longer build by default, enable + them, when subpackages are selected +- added optional subpackage for pulseaudio +- switched to external vcdlibs +- using macros for shell commands, when rpm provides them +- some other cleanups +* Sun Oct 15 2006 Manfred Tremmel <Manfred.Tremmel@iiv.de> +- some little changes to enable caca plugin * Sat Aug 26 2006 FrantiÅ¡ek Dvořák <valtri@users.sourceforge.net> - tiny translation update - fixed rpmbuild -- cgit v1.2.3 From b24d41f54d441f518c68c120b8ee1a2673bfbe0d Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Thu, 24 Jan 2008 23:38:09 +0000 Subject: Only restore the audio buffer discard setting if it was altered. (Cset 1a0447486a13 broke things differently.) --- src/xine-engine/audio_out.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/xine-engine/audio_out.c b/src/xine-engine/audio_out.c index e9bda70fb..4dcdb5af0 100644 --- a/src/xine-engine/audio_out.c +++ b/src/xine-engine/audio_out.c @@ -287,6 +287,7 @@ struct audio_fifo_s { int num_buffers; }; +static int ao_get_property (xine_audio_port_t *this_gen, int property); static int ao_set_property (xine_audio_port_t *this_gen, int property, int value); static audio_fifo_t *fifo_new (xine_t *xine) { @@ -1612,14 +1613,17 @@ static void ao_close(xine_audio_port_t *this_gen, xine_stream_t *stream) { xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_out: no streams left, closing driver\n"); if (this->audio_loop_running) { + /* make sure there are no more buffers on queue */ if (this->clock->speed == XINE_SPEED_PAUSE || (this->clock->speed != XINE_FINE_SPEED_NORMAL && !this->slow_fast_audio)) { - /* discard buffers, otherwise we'll wait forever */ + int discard = ao_get_property(this_gen, AO_PROP_DISCARD_BUFFERS); + /* discard buffers while waiting, otherwise we'll wait forever */ ao_set_property(this_gen, AO_PROP_DISCARD_BUFFERS, 1); + fifo_wait_empty(this->out_fifo); + ao_set_property(this_gen, AO_PROP_DISCARD_BUFFERS, discard); } - /* make sure there are no more buffers on queue */ - fifo_wait_empty(this->out_fifo); - ao_set_property(this_gen, AO_PROP_DISCARD_BUFFERS, 0); + else + fifo_wait_empty(this->out_fifo); } pthread_mutex_lock( &this->driver_lock ); -- cgit v1.2.3 From 6c456a0d597c2a96aadee33c7af5845de279e478 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Thu, 24 Jan 2008 23:47:36 +0000 Subject: Fix a possible crash on channel change in the DVB plugin. Some 0-sized sections were observed in the TS PMT parser. Test setup details: Test channel is Film 4 on Freeview. Test hardware is a Nova-T Stick (older dib7000m variant). Drivers from v4l-dvb hg, id a1c94c4a05f5, with dib7000m_set_frontend() patched to select OUTMODE_HIGH_Z while tuning. --- ChangeLog | 1 + src/demuxers/demux_ts.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index 2b88720f2..39be0ed4e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,7 @@ xine-lib (1.1.10) (unreleased) * Sanity-check ASF header sizes. This fixes a crash in the ASF demuxer, caused by the example exploit given for CVE-2006-1664. * Don't discard audio samples forever. Fixed streaming playback. + * Fix a possible crash on channel change in the DVB plugin. xine-lib (1.1.9.1) 2008-01-11 * Security fixes: diff --git a/src/demuxers/demux_ts.c b/src/demuxers/demux_ts.c index 86a14f019..0fa0c971c 100644 --- a/src/demuxers/demux_ts.c +++ b/src/demuxers/demux_ts.c @@ -1193,6 +1193,15 @@ printf("Program Number is %i, looking for %i\n",program_number,this->program_num return; } + if (!section_length) { + free (this->pmt[program_count]); + this->pmt[program_count] = NULL; +#ifdef TS_PMT_LOG + printf ("ts_demux: eek, zero-length section?\n"); +#endif + return; + } + #ifdef TS_PMT_LOG printf ("ts_demux: have all TS packets for the PMT section\n"); #endif -- cgit v1.2.3 From 4e96930cdea7c448f8a47405166575a54c454588 Mon Sep 17 00:00:00 2001 From: Claudio Ciccani <klan@directfb.org> Date: Fri, 25 Jan 2008 12:30:58 +0100 Subject: Fixed parsing of keyframes indices (do not assume a specific order betwen "times" and "filepositions"). Parse flv script data only once upon send_headers(). Use relative seeking instead of absolute seeking when seek_time-current_time is below 5 seconds. --- src/demuxers/demux_flv.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/demuxers/demux_flv.c b/src/demuxers/demux_flv.c index e6a7e234a..a65702207 100644 --- a/src/demuxers/demux_flv.c +++ b/src/demuxers/demux_flv.c @@ -306,9 +306,12 @@ static int parse_flv_var(demux_flv_t *this, num = _X_BE_32(tmp); tmp += 4; if (key && keylen == 5 && !strncmp(key, "times", 5)) { - free (this->index); - this->index = xine_xcalloc(num, sizeof(flv_index_entry_t)); - this->num_indices = num; + if (!this->index || this->num_indices != num) { + if (this->index) + free(this->index); + this->index = xine_xcalloc(num, sizeof(flv_index_entry_t)); + this->num_indices = num; + } for (num = 0; num < this->num_indices && tmp < end; num++) { if (*tmp++ == FLV_DATA_TYPE_NUMBER) { lprintf(" got number (%f)\n", BE_F64(tmp)); @@ -319,16 +322,20 @@ static int parse_flv_var(demux_flv_t *this, break; } if (key && keylen == 13 && !strncmp(key, "filepositions", 13)) { - if (this->index && this->num_indices == num) { - for (num = 0; num < this->num_indices && tmp < end; num++) { - if (*tmp++ == FLV_DATA_TYPE_NUMBER) { - lprintf(" got number (%f)\n", BE_F64(tmp)); - this->index[num].offset = BE_F64(tmp); - tmp += 8; - } + if (!this->index || this->num_indices != num) { + if (this->index) + free(this->index); + this->index = xine_xcalloc(num, sizeof(flv_index_entry_t)); + this->num_indices = num; + } + for (num = 0; num < this->num_indices && tmp < end; num++) { + if (*tmp++ == FLV_DATA_TYPE_NUMBER) { + lprintf(" got number (%f)\n", BE_F64(tmp)); + this->index[num].offset = BE_F64(tmp); + tmp += 8; } - break; } + break; } while (num-- && tmp < end) { len = parse_flv_var(this, tmp, end-tmp, NULL, 0); @@ -501,9 +508,9 @@ static int read_flv_packet(demux_flv_t *this, int preview) { case FLV_TAG_TYPE_SCRIPT: lprintf(" got script tag...\n"); - parse_flv_script(this, remaining_bytes); - if (preview) { + parse_flv_script(this, remaining_bytes); + /* send init info to decoders using script information as reference */ if (!this->got_audio_header && this->audiocodec) { buf = this->audio_fifo->buffer_pool_alloc(this->audio_fifo); @@ -569,7 +576,9 @@ static int read_flv_packet(demux_flv_t *this, int preview) { } return this->status; - } + } + /* no preview */ + this->input->seek(this->input, remaining_bytes, SEEK_CUR); continue; default: @@ -661,7 +670,7 @@ static void seek_flv_file(demux_flv_t *this, off_t seek_pos, int seek_pts) { } } - if (seek_pos && this->videocodec) { + if (seek_pos && this->videocodec && abs(seek_pts-this->cur_pts) > 300000) { off_t pos, size; pos = this->input->get_current_pos(this->input); -- cgit v1.2.3 From d8d66952029c89a0b4ffcedc0c22f56c9c01c0ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Fri, 25 Jan 2008 22:46:31 +0100 Subject: Advertise proper support for FLAC files. application/x-flac is not reported anywhere. Both file(1) and shared-mime-info report audio/x-flac. Xiph wiki[1] reports audio/flac as being queued for registration. Report both audio/x-flac and audio/flac for compatibility. [1] http://wiki.xiph.org/index.php/MIME_Types_and_File_Extensions --- src/combined/demux_flac.c | 3 ++- src/demuxers/demux_flac.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/combined/demux_flac.c b/src/combined/demux_flac.c index 85f98e876..fdc7ab7ea 100644 --- a/src/combined/demux_flac.c +++ b/src/combined/demux_flac.c @@ -732,7 +732,8 @@ get_extensions (demux_class_t *this_gen) { static char * get_mimetypes (demux_class_t *this_gen) { - return "application/x-flac: flac: FLAC Audio;"; + return "audio/x-flac: flac: FLAC Audio;" + "audio/flac: flac: FLAC Audio;"; } static void diff --git a/src/demuxers/demux_flac.c b/src/demuxers/demux_flac.c index 3afb5b031..23e2faef9 100644 --- a/src/demuxers/demux_flac.c +++ b/src/demuxers/demux_flac.c @@ -544,7 +544,8 @@ static const char *get_extensions (demux_class_t *this_gen) { } static const char *get_mimetypes (demux_class_t *this_gen) { - return NULL; + return "audio/x-flac: flac: FLAC Audio;" + "audio/flac: flac: FLAC Audio;"; } static void class_dispose (demux_class_t *this_gen) { -- cgit v1.2.3 From 499a81b162ecb54d061f103b51b33f024cd2eb30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Fri, 25 Jan 2008 22:49:26 +0100 Subject: Report unofficial mimetypes (x- variants) for the Ogg demuxer too. --- src/demuxers/demux_ogg.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/demuxers/demux_ogg.c b/src/demuxers/demux_ogg.c index d1b522727..82eefdf75 100644 --- a/src/demuxers/demux_ogg.c +++ b/src/demuxers/demux_ogg.c @@ -2119,8 +2119,11 @@ static const char *anx_get_extensions (demux_class_t *this_gen) { static const char *anx_get_mimetypes (demux_class_t *this_gen) { return "application/annodex: anx: Annodex media;" + "application/x-annodex: anx: Annodex media;" "audio/annodex: axa: Annodex audio;" + "audio/x-annodex: axa: Annodex audio;" "video/annodex: axv: Annodex video;"; + "video/x-annodex: axv: Annodex video;"; } static void anx_class_dispose (demux_class_t *this_gen) { @@ -2162,8 +2165,11 @@ static const char *ogg_get_extensions (demux_class_t *this_gen) { static const char *ogg_get_mimetypes (demux_class_t *this_gen) { return "application/ogg: ogx: Ogg Stream;" + "application/x-ogg: ogx: Ogg Stream;" "audio/ogg: oga: Ogg Audio;" + "audio/x-ogg: oga: Ogg Audio;" "video/ogg: ogv: Ogg Video;"; + "video/x-ogg: ogv: Ogg Video;"; } static void ogg_class_dispose (demux_class_t *this_gen) { -- cgit v1.2.3 From ef96216c903e38dc3c8b835efc9bf27605179249 Mon Sep 17 00:00:00 2001 From: Claudio Ciccani <klan@directfb.org> Date: Fri, 25 Jan 2008 12:30:58 +0100 Subject: Fixed parsing of keyframes indices (do not assume a specific order betwen "times" and "filepositions"). Parse flv script data only once upon send_headers(). Use relative seeking instead of absolute seeking when seek_time-current_time is below 5 seconds. (transplanted from 689daba9823670864eaef213733987196be21acc) --HG-- extra : transplant_source : %3CA%D9%CBuM%14%DAR%F8%89K%EF%13%83%17%9A%F7%AB%8F --- src/demuxers/demux_flv.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/demuxers/demux_flv.c b/src/demuxers/demux_flv.c index bdb33d21d..a1f0b3a7b 100644 --- a/src/demuxers/demux_flv.c +++ b/src/demuxers/demux_flv.c @@ -306,10 +306,12 @@ static int parse_flv_var(demux_flv_t *this, num = _X_BE_32(tmp); tmp += 4; if (key && keylen == 5 && !strncmp(key, "times", 5)) { - if (this->index) - free (this->index); - this->index = xine_xmalloc(num*sizeof(flv_index_entry_t)); - this->num_indices = num; + if (!this->index || this->num_indices != num) { + if (this->index) + free(this->index); + this->index = xine_xmalloc(num*sizeof(flv_index_entry_t)); + this->num_indices = num; + } for (num = 0; num < this->num_indices && tmp < end; num++) { if (*tmp++ == FLV_DATA_TYPE_NUMBER) { lprintf(" got number (%f)\n", BE_F64(tmp)); @@ -320,16 +322,20 @@ static int parse_flv_var(demux_flv_t *this, break; } if (key && keylen == 13 && !strncmp(key, "filepositions", 13)) { - if (this->index && this->num_indices == num) { - for (num = 0; num < this->num_indices && tmp < end; num++) { - if (*tmp++ == FLV_DATA_TYPE_NUMBER) { - lprintf(" got number (%f)\n", BE_F64(tmp)); - this->index[num].offset = BE_F64(tmp); - tmp += 8; - } + if (!this->index || this->num_indices != num) { + if (this->index) + free(this->index); + this->index = xine_xmalloc(num*sizeof(flv_index_entry_t)); + this->num_indices = num; + } + for (num = 0; num < this->num_indices && tmp < end; num++) { + if (*tmp++ == FLV_DATA_TYPE_NUMBER) { + lprintf(" got number (%f)\n", BE_F64(tmp)); + this->index[num].offset = BE_F64(tmp); + tmp += 8; } - break; } + break; } while (num-- && tmp < end) { len = parse_flv_var(this, tmp, end-tmp, NULL, 0); @@ -502,9 +508,9 @@ static int read_flv_packet(demux_flv_t *this, int preview) { case FLV_TAG_TYPE_SCRIPT: lprintf(" got script tag...\n"); - parse_flv_script(this, remaining_bytes); - if (preview) { + parse_flv_script(this, remaining_bytes); + /* send init info to decoders using script information as reference */ if (!this->got_audio_header && this->audiocodec) { buf = this->audio_fifo->buffer_pool_alloc(this->audio_fifo); @@ -570,7 +576,9 @@ static int read_flv_packet(demux_flv_t *this, int preview) { } return this->status; - } + } + /* no preview */ + this->input->seek(this->input, remaining_bytes, SEEK_CUR); continue; default: @@ -662,7 +670,7 @@ static void seek_flv_file(demux_flv_t *this, off_t seek_pos, int seek_pts) { } } - if (seek_pos && this->videocodec) { + if (seek_pos && this->videocodec && abs(seek_pts-this->cur_pts) > 300000) { off_t pos, size; pos = this->input->get_current_pos(this->input); -- cgit v1.2.3 From d9e8c92bbc90bc0c2d8a4b71059936176bf2d6d0 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Fri, 25 Jan 2008 13:30:34 +0000 Subject: Always use xine_xmalloc in plugin class init; avoids uninitialised pointers. --- src/post/audio/stretch.c | 2 +- src/post/audio/upmix.c | 2 +- src/post/audio/upmix_mono.c | 2 +- src/post/audio/volnorm.c | 2 +- src/post/visualizations/fftgraph.c | 2 +- src/post/visualizations/fftscope.c | 2 +- src/post/visualizations/fooviz.c | 2 +- src/post/visualizations/oscope.c | 2 +- src/vdr/post_vdr_audio.c | 2 +- src/vdr/post_vdr_video.c | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/post/audio/stretch.c b/src/post/audio/stretch.c index bc079fd8d..5a0382895 100644 --- a/src/post/audio/stretch.c +++ b/src/post/audio/stretch.c @@ -662,7 +662,7 @@ static post_plugin_t *stretch_open_plugin(post_class_t *class_gen, int inputs, /* plugin class initialization function */ void *stretch_init_plugin(xine_t *xine, void *data) { - post_class_stretch_t *class = (post_class_stretch_t *)malloc(sizeof(post_class_stretch_t)); + post_class_stretch_t *class = (post_class_stretch_t *)xine_xmalloc(sizeof(post_class_stretch_t)); if (!class) return NULL; diff --git a/src/post/audio/upmix.c b/src/post/audio/upmix.c index 30fbb452b..573354450 100644 --- a/src/post/audio/upmix.c +++ b/src/post/audio/upmix.c @@ -417,7 +417,7 @@ static post_plugin_t *upmix_open_plugin(post_class_t *class_gen, int inputs, /* plugin class initialization function */ void *upmix_init_plugin(xine_t *xine, void *data) { - post_class_upmix_t *class = (post_class_upmix_t *)malloc(sizeof(post_class_upmix_t)); + post_class_upmix_t *class = (post_class_upmix_t *)xine_xmalloc(sizeof(post_class_upmix_t)); if (!class) return NULL; diff --git a/src/post/audio/upmix_mono.c b/src/post/audio/upmix_mono.c index 53fd23109..82ceb1877 100644 --- a/src/post/audio/upmix_mono.c +++ b/src/post/audio/upmix_mono.c @@ -332,7 +332,7 @@ static post_plugin_t *upmix_mono_open_plugin(post_class_t *class_gen, int inputs /* plugin class initialization function */ void *upmix_mono_init_plugin(xine_t *xine, void *data) { - post_class_upmix_mono_t *class = (post_class_upmix_mono_t *)malloc(sizeof(post_class_upmix_mono_t)); + post_class_upmix_mono_t *class = (post_class_upmix_mono_t *)xine_xmalloc(sizeof(post_class_upmix_mono_t)); if (!class) return NULL; diff --git a/src/post/audio/volnorm.c b/src/post/audio/volnorm.c index 4fb2a0411..de4ebde87 100644 --- a/src/post/audio/volnorm.c +++ b/src/post/audio/volnorm.c @@ -450,7 +450,7 @@ static post_plugin_t *volnorm_open_plugin(post_class_t *class_gen, int inputs, /* plugin class initialization function */ void *volnorm_init_plugin(xine_t *xine, void *data) { - post_class_volnorm_t *class = (post_class_volnorm_t *)malloc(sizeof(post_class_volnorm_t)); + post_class_volnorm_t *class = (post_class_volnorm_t *)xine_xmalloc(sizeof(post_class_volnorm_t)); if (!class) return NULL; diff --git a/src/post/visualizations/fftgraph.c b/src/post/visualizations/fftgraph.c index c31c529f2..39d17c730 100644 --- a/src/post/visualizations/fftgraph.c +++ b/src/post/visualizations/fftgraph.c @@ -455,7 +455,7 @@ static post_plugin_t *fftgraph_open_plugin(post_class_t *class_gen, int inputs, /* plugin class initialization function */ void *fftgraph_init_plugin(xine_t *xine, void *data) { - post_class_fftgraph_t *class = (post_class_fftgraph_t *)malloc(sizeof(post_class_fftgraph_t)); + post_class_fftgraph_t *class = (post_class_fftgraph_t *)xine_xmalloc(sizeof(post_class_fftgraph_t)); if (!class) return NULL; diff --git a/src/post/visualizations/fftscope.c b/src/post/visualizations/fftscope.c index dd474bd6f..1a9ea905a 100644 --- a/src/post/visualizations/fftscope.c +++ b/src/post/visualizations/fftscope.c @@ -476,7 +476,7 @@ static post_plugin_t *fftscope_open_plugin(post_class_t *class_gen, int inputs, /* plugin class initialization function */ void *fftscope_init_plugin(xine_t *xine, void *data) { - post_class_fftscope_t *class = (post_class_fftscope_t *)malloc(sizeof(post_class_fftscope_t)); + post_class_fftscope_t *class = (post_class_fftscope_t *)xine_xmalloc(sizeof(post_class_fftscope_t)); if (!class) return NULL; diff --git a/src/post/visualizations/fooviz.c b/src/post/visualizations/fooviz.c index 2cf77cadc..3e5702168 100644 --- a/src/post/visualizations/fooviz.c +++ b/src/post/visualizations/fooviz.c @@ -287,7 +287,7 @@ static post_plugin_t *fooviz_open_plugin(post_class_t *class_gen, int inputs, /* plugin class initialization function */ static void *fooviz_init_plugin(xine_t *xine, void *data) { - post_class_fooviz_t *class = (post_class_fooviz_t *)malloc(sizeof(post_class_fooviz_t)); + post_class_fooviz_t *class = (post_class_fooviz_t *)xine_xmalloc(sizeof(post_class_fooviz_t)); if (!class) return NULL; diff --git a/src/post/visualizations/oscope.c b/src/post/visualizations/oscope.c index 1d498980a..7c9faeeaa 100644 --- a/src/post/visualizations/oscope.c +++ b/src/post/visualizations/oscope.c @@ -358,7 +358,7 @@ static post_plugin_t *oscope_open_plugin(post_class_t *class_gen, int inputs, /* plugin class initialization function */ void *oscope_init_plugin(xine_t *xine, void *data) { - post_class_oscope_t *class = (post_class_oscope_t *)malloc(sizeof(post_class_oscope_t)); + post_class_oscope_t *class = (post_class_oscope_t *)xine_xmalloc(sizeof(post_class_oscope_t)); if (!class) return NULL; diff --git a/src/vdr/post_vdr_audio.c b/src/vdr/post_vdr_audio.c index ca45ecd35..49de8f9cf 100644 --- a/src/vdr/post_vdr_audio.c +++ b/src/vdr/post_vdr_audio.c @@ -71,7 +71,7 @@ static void vdr_audio_port_put_buffer(xine_audio_port_t *port_gen, aud void *vdr_audio_init_plugin(xine_t *xine, void *data) { - post_class_t *class = (post_class_t *)malloc(sizeof (post_class_t)); + post_class_t *class = (post_class_t *)xine_xmalloc(sizeof (post_class_t)); if (!class) return NULL; diff --git a/src/vdr/post_vdr_video.c b/src/vdr/post_vdr_video.c index ff6c32504..4d1055aaf 100644 --- a/src/vdr/post_vdr_video.c +++ b/src/vdr/post_vdr_video.c @@ -94,7 +94,7 @@ static int vdr_video_draw(vo_frame_t *frame, xine_stream_t *stream); void *vdr_video_init_plugin(xine_t *xine, void *data) { - post_class_t *class = (post_class_t *)malloc(sizeof (post_class_t)); + post_class_t *class = (post_class_t *)xine_xmalloc(sizeof (post_class_t)); if (!class) return NULL; -- cgit v1.2.3 From c83889f17b35876c9575ca5cc9644e63b006981a Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Fri, 25 Jan 2008 21:58:29 +0000 Subject: Changelog update. --- ChangeLog | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 39be0ed4e..75ac42bf8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ xine-lib (1.1.10) (unreleased) + * Security fixes: + - Buffer overflow which allows a remote attacker to execute arbitrary + code or crash the client program via a crafted ASF header. + (Related to CVE-2006-1664) * Update Ogg and Annodex mimetypes and extensions. * Change the default v4l device paths to /dev/video0 and /dev/radio0. * Fix support for subtitles with schemes (e.g. http://), partly broken @@ -8,10 +12,9 @@ xine-lib (1.1.10) (unreleased) end authors should be careful with xine-lib older than 1.1.10. * Backported xine-config & libxine.pc from 1.2. Consequently, xine-config now requires pkg-config. - * Sanity-check ASF header sizes. This fixes a crash in the ASF demuxer, - caused by the example exploit given for CVE-2006-1664. * Don't discard audio samples forever. Fixed streaming playback. * Fix a possible crash on channel change in the DVB plugin. + * Flash video demuxer improvements and bug fixes. xine-lib (1.1.9.1) 2008-01-11 * Security fixes: -- cgit v1.2.3 From c20f6876baae32c2ef18999def0245bf0c23000a Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Tue, 12 Feb 2008 16:39:57 +0000 Subject: Avoid possible excess linkage in the tvtime plugin. Its convenience lib needs $(XINE_LIB) but it gets that when it's linked into the shared lib. --- src/post/deinterlace/plugins/Makefile.am | 1 - 1 file changed, 1 deletion(-) diff --git a/src/post/deinterlace/plugins/Makefile.am b/src/post/deinterlace/plugins/Makefile.am index 2bc8abd58..1ff139d29 100644 --- a/src/post/deinterlace/plugins/Makefile.am +++ b/src/post/deinterlace/plugins/Makefile.am @@ -48,7 +48,6 @@ libdeinterlaceplugins_la_SOURCES = \ scalerbob.c \ kdetv_greedyh.c \ kdetv_tomsmocomp.c -libdeinterlaceplugins_la_LIBADD = $(XINE_LIB) libdeinterlaceplugins_la_CFLAGS = $(VISIBILITY_FLAG) $(AM_CFLAGS) libdeinterlaceplugins_la_LDFLAGS = -avoid-version -module -- cgit v1.2.3 From 07a99628d88294244393abc463ae193e2e97f08b Mon Sep 17 00:00:00 2001 From: Thibaut Mattern <thibaut.mattern@gmail.com> Date: Thu, 14 Feb 2008 21:16:43 +0100 Subject: Fixed mp3 sniff code. Fixed bug 4 sample playback (nilbymouthclapton.112.mp3). (transplanted from 4843103240d4fc85d31bd210194a98c1e1bdbd7a) --HG-- extra : transplant_source : HC%102%40%D4%FC%85%D3%1B%D2%10%19J%98%C1%E1%BD%BDz --- src/demuxers/demux_mpgaudio.c | 59 +++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c index 82a7dd7ab..56759dd4b 100644 --- a/src/demuxers/demux_mpgaudio.c +++ b/src/demuxers/demux_mpgaudio.c @@ -626,11 +626,12 @@ static int parse_frame_payload(demux_mpgaudio_t *this, * 32-bit MP3 frame header. * return 1 if found, 0 if not found */ -static int sniff_buffer_looks_like_mp3 (uint8_t *buf, int buflen) +static int sniff_buffer_looks_like_mp3 (uint8_t *buf, int buflen, int *version, int *layer) { int offset; mpg_audio_frame_t frame; + *version = *layer = 0; if (buf == NULL) return 0; @@ -639,20 +640,21 @@ static int sniff_buffer_looks_like_mp3 (uint8_t *buf, int buflen) if (parse_frame_header(&frame, buf + offset)) { size_t size = frame.size; - /* Since one frame is available, is there another frame - * just to be sure this is more likely to be a real MP3 - * buffer? */ - offset += size; - - if (offset + 4 >= buflen) { - return 0; - } + if (size > 0) { + /* Since one frame is available, is there another frame + * just to be sure this is more likely to be a real MP3 + * buffer? */ + if (offset + size + 4 >= buflen) { + return 0; + } - if (parse_frame_header(&frame, buf + offset)) { - lprintf("mpeg audio frame detected\n"); - return 1; + if (parse_frame_header(&frame, buf + offset + size)) { + *version = frame.version_idx + 1; + *layer = frame.layer; + lprintf("frame detected, mpeg %d layer %d\n", *version, *layer); + return 1; + } } - break; } } return 0; @@ -806,11 +808,13 @@ static int demux_mpgaudio_read_head(input_plugin_t *input, uint8_t *buf) { * mp3 stream detection * return 1 if detected, 0 otherwise */ -static int detect_mpgaudio_file(input_plugin_t *input) { +static int detect_mpgaudio_file(input_plugin_t *input, + int *version, int *layer) { uint8_t buf[MAX_PREVIEW_SIZE]; int preview_len; uint32_t head; + *version = *layer = 0; preview_len = demux_mpgaudio_read_head(input, buf); if (preview_len < 4) return 0; @@ -837,7 +841,7 @@ static int detect_mpgaudio_file(input_plugin_t *input) { lprintf("cannot read mp3 frame header\n"); return 0; } - if (!sniff_buffer_looks_like_mp3(&buf[10 + tag_size], preview_len - 10 - tag_size)) { + if (!sniff_buffer_looks_like_mp3(&buf[10 + tag_size], preview_len - 10 - tag_size, version, layer)) { lprintf ("sniff_buffer_looks_like_mp3 failed\n"); return 0; } else { @@ -845,7 +849,7 @@ static int detect_mpgaudio_file(input_plugin_t *input) { } } else if (head == MPEG_MARKER) { return 0; - } else if (!sniff_buffer_looks_like_mp3(buf, preview_len)) { + } else if (!sniff_buffer_looks_like_mp3(buf, preview_len, version, layer)) { lprintf ("sniff_buffer_looks_like_mp3 failed\n"); return 0; } @@ -1112,13 +1116,15 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str input_plugin_t *input) { demux_mpgaudio_t *this; + int version = 0; + int layer = 0; lprintf("trying to open %s...\n", input->get_mrl(input)); switch (stream->content_detection_method) { case METHOD_BY_CONTENT: { - if (!detect_mpgaudio_file(input)) + if (!detect_mpgaudio_file(input, &version, &layer)) return NULL; } break; @@ -1141,7 +1147,7 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str default: return NULL; } - + this = xine_xmalloc (sizeof (demux_mpgaudio_t)); this->demux_plugin.send_headers = demux_mpgaudio_send_headers; @@ -1153,12 +1159,17 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str this->demux_plugin.get_capabilities = demux_mpgaudio_get_capabilities; this->demux_plugin.get_optional_data = demux_mpgaudio_get_optional_data; this->demux_plugin.demux_class = class_gen; - - this->input = input; - this->audio_fifo = stream->audio_fifo; - this->status = DEMUX_FINISHED; - this->stream = stream; - + + this->input = input; + this->audio_fifo = stream->audio_fifo; + this->status = DEMUX_FINISHED; + this->stream = stream; + + this->mpg_version = version; + this->mpg_layer = layer; + if (version || layer) { + this->valid_frames = NUM_VALID_FRAMES; + } return &this->demux_plugin; } -- cgit v1.2.3 From b0c97c912f4ee5bc34692d7d737979b390ac621b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Fri, 25 Jan 2008 23:02:29 +0100 Subject: Advertise audio/x-wavpack mime type for WavPack demuxer. --HG-- extra : transplant_source : iT%08m0%F6%E0%8B-%24%1F%BC%EB%24%25.%C0p%E2%14 --- src/combined/demux_wavpack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/combined/demux_wavpack.c b/src/combined/demux_wavpack.c index e8081bca9..a79f70627 100644 --- a/src/combined/demux_wavpack.c +++ b/src/combined/demux_wavpack.c @@ -391,7 +391,7 @@ static const char *get_extensions (demux_class_t *const this_gen) { } static const char *get_mimetypes (demux_class_t *const this_gen) { - return NULL; + return "audio/x-wavpack"; } static void class_dispose (demux_class_t *const this_gen) { -- cgit v1.2.3 From da5afb9cc5c1369b99db81f3c254eaf69642b777 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 26 Jan 2008 01:39:52 +0000 Subject: Fix a few recently-caused compiler warnings. --- src/demuxers/demux_mpgaudio.c | 4 ++-- src/demuxers/demux_ogg.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c index 180a9752c..1bea02302 100644 --- a/src/demuxers/demux_mpgaudio.c +++ b/src/demuxers/demux_mpgaudio.c @@ -591,14 +591,14 @@ static int parse_frame_payload(demux_mpgaudio_t *this, if (this->xing_header) { buf->free_buffer(buf); xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - LOG_MODULE ": found Xing header at offset %PRId64\n", frame_pos); + LOG_MODULE ": found Xing header at offset %"PRId64"\n", frame_pos); return 1; } this->vbri_header = parse_vbri_header(&this->cur_frame, buf->content, this->cur_frame.size); if (this->vbri_header) { buf->free_buffer(buf); xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - LOG_MODULE ": found Vbri header at offset %PRId64\n", frame_pos); + LOG_MODULE ": found Vbri header at offset %"PRId64"\n", frame_pos); return 1; } } diff --git a/src/demuxers/demux_ogg.c b/src/demuxers/demux_ogg.c index 82eefdf75..dc867e5f1 100644 --- a/src/demuxers/demux_ogg.c +++ b/src/demuxers/demux_ogg.c @@ -2122,7 +2122,7 @@ static const char *anx_get_mimetypes (demux_class_t *this_gen) { "application/x-annodex: anx: Annodex media;" "audio/annodex: axa: Annodex audio;" "audio/x-annodex: axa: Annodex audio;" - "video/annodex: axv: Annodex video;"; + "video/annodex: axv: Annodex video;" "video/x-annodex: axv: Annodex video;"; } @@ -2168,7 +2168,7 @@ static const char *ogg_get_mimetypes (demux_class_t *this_gen) { "application/x-ogg: ogx: Ogg Stream;" "audio/ogg: oga: Ogg Audio;" "audio/x-ogg: oga: Ogg Audio;" - "video/ogg: ogv: Ogg Video;"; + "video/ogg: ogv: Ogg Video;" "video/x-ogg: ogv: Ogg Video;"; } -- cgit v1.2.3 From 728b56b78c6cbc6e239714b58eb440683c93d847 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 26 Jan 2008 15:07:16 +0000 Subject: Unbreak xine-config distribution. --- misc/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/misc/Makefile.am b/misc/Makefile.am index a5ef28635..70cbe59ee 100644 --- a/misc/Makefile.am +++ b/misc/Makefile.am @@ -7,6 +7,7 @@ EXTRA_DIST = build_rpms.sh \ SlackBuild.in \ SlackBuild \ vga.xinefont.gz \ + xine-config \ xine-fontconv.c \ xine-lib.spec.in \ xine-lib.spec \ -- cgit v1.2.3 From b6dfc3fc918b6067028121e660341c623942ced1 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 26 Jan 2008 16:46:09 +0000 Subject: Resync translation source file. --- po/libxine1.pot | 511 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 271 insertions(+), 240 deletions(-) diff --git a/po/libxine1.pot b/po/libxine1.pot index 94d07aee3..3a9a95f4b 100644 --- a/po/libxine1.pot +++ b/po/libxine1.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: xine-devel@lists.sourceforge.net\n" -"POT-Creation-Date: 2007-12-24 18:34+0000\n" +"POT-Creation-Date: 2008-01-26 14:49+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -712,12 +712,12 @@ msgstr "" msgid "xine audio output plugin using sun-compliant audio devices/drivers" msgstr "" -#: src/demuxers/demux_asf.c:426 +#: src/demuxers/demux_asf.c:441 #, c-format msgid "demux_asf: warning: The stream id=%d is encrypted.\n" msgstr "" -#: src/demuxers/demux_asf.c:428 +#: src/demuxers/demux_asf.c:443 msgid "Media stream scrambled/encrypted" msgstr "" @@ -1782,7 +1782,7 @@ msgstr "" msgid "input_net: unable to connect to '%s'.\n" msgstr "" -#: src/input/input_net.c:508 +#: src/input/input_net.c:514 msgid "net input plugin as shipped with xine" msgstr "" @@ -1805,28 +1805,28 @@ msgstr "" msgid "input_pvr: read error (%s)\n" msgstr "" -#: src/input/input_pvr.c:1150 src/input/input_pvr.c:1403 +#: src/input/input_pvr.c:1173 src/input/input_pvr.c:1426 #, c-format msgid "input_pvr: error opening device %s\n" msgstr "" -#: src/input/input_pvr.c:1156 src/input/input_pvr.c:1409 +#: src/input/input_pvr.c:1179 src/input/input_pvr.c:1432 msgid "input_pvr: IVTV_IOC_G_CODEC failed, maybe API changed?\n" msgstr "" -#: src/input/input_pvr.c:1164 src/input/input_pvr.c:1418 +#: src/input/input_pvr.c:1187 src/input/input_pvr.c:1441 msgid "input_pvr: IVTV_IOC_S_CODEC failed, maybe API changed?\n" msgstr "" -#: src/input/input_pvr.c:1526 +#: src/input/input_pvr.c:1549 msgid "WinTV-PVR 250/350 input plugin" msgstr "" -#: src/input/input_pvr.c:1552 +#: src/input/input_pvr.c:1575 msgid "device used for WinTV-PVR 250/350 (pvr plugin)" msgstr "" -#: src/input/input_pvr.c:1553 +#: src/input/input_pvr.c:1576 msgid "The path to the device of your WinTV card." msgstr "" @@ -2015,7 +2015,13 @@ msgstr "" msgid "rtsp_session: session can not be established.\n" msgstr "" -#: src/input/librtsp/rtsp_session.c:159 +#: src/input/librtsp/rtsp_session.c:153 +msgid "" +"rtsp_session: rtsp server returned overly-large headers, session can not be " +"established.\n" +msgstr "" + +#: src/input/librtsp/rtsp_session.c:164 #, c-format msgid "rtsp_session: rtsp server type '%s' not supported yet. sorry.\n" msgstr "" @@ -2350,37 +2356,37 @@ msgstr "" msgid "dvaudio: increasing buffer to %d to avoid overflow.\n" msgstr "" -#: src/libffmpeg/ff_video_decoder.c:156 +#: src/libffmpeg/ff_video_decoder.c:158 msgid "ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n" msgstr "" -#: src/libffmpeg/ff_video_decoder.c:174 +#: src/libffmpeg/ff_video_decoder.c:176 msgid "ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n" msgstr "" -#: src/libffmpeg/ff_video_decoder.c:338 +#: src/libffmpeg/ff_video_decoder.c:359 #, c-format msgid "ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n" msgstr "" -#: src/libffmpeg/ff_video_decoder.c:367 +#: src/libffmpeg/ff_video_decoder.c:391 msgid "ffmpeg_video_dec: couldn't open decoder\n" msgstr "" -#: src/libffmpeg/ff_video_decoder.c:408 +#: src/libffmpeg/ff_video_decoder.c:434 msgid "ffmpeg_video_dec: direct rendering enabled\n" msgstr "" -#: src/libffmpeg/ff_video_decoder.c:836 +#: src/libffmpeg/ff_video_decoder.c:874 #, c-format msgid "ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n" msgstr "" -#: src/libffmpeg/ff_video_decoder.c:1562 +#: src/libffmpeg/ff_video_decoder.c:1600 msgid "MPEG-4 postprocessing quality" msgstr "" -#: src/libffmpeg/ff_video_decoder.c:1563 +#: src/libffmpeg/ff_video_decoder.c:1601 msgid "" "You can adjust the amount of post processing applied to MPEG-4 video.\n" "Higher values result in better quality, but need more CPU. Lower values may " @@ -2389,17 +2395,42 @@ msgid "" "much." msgstr "" -#: src/libffmpeg/ff_video_decoder.c:1571 +#: src/libffmpeg/ff_video_decoder.c:1609 msgid "FFmpeg video decoding thread count" msgstr "" -#: src/libffmpeg/ff_video_decoder.c:1572 +#: src/libffmpeg/ff_video_decoder.c:1610 msgid "" "You can adjust the number of video decoding threads which FFmpeg may use.\n" "Higher values should speed up decoding but it depends on the codec used " "whether parallel decoding is supported. A rule of thumb is to have one " -"decoding thread per logical CPU (typically 1 to 4). A change will take " -"effect with playing the next stream." +"decoding thread per logical CPU (typically 1 to 4).\n" +"A change of this setting will take effect with playing the next stream." +msgstr "" + +#: src/libffmpeg/ff_video_decoder.c:1619 +msgid "Skip loop filter" +msgstr "" + +#: src/libffmpeg/ff_video_decoder.c:1620 +msgid "" +"You can control for which frames the loop filter shall be skipped after " +"decoding.\n" +"Skipping the loop filter will speedup decoding but may lead to artefacts. " +"The number of frames for which it is skipped increases from 'none' to 'all'. " +"The default value leaves the decision up to the implementation.\n" +"A change of this setting will take effect with playing the next stream." +msgstr "" + +#: src/libffmpeg/ff_video_decoder.c:1629 +msgid "Choose speed over specification compliance" +msgstr "" + +#: src/libffmpeg/ff_video_decoder.c:1630 +msgid "" +"You may want to allow speed cheats which violate codec specification.\n" +"Cheating may speed up decoding but can also lead to decoding artefacts.\n" +"A change of this setting will take effect with playing the next stream." msgstr "" #: src/libffmpeg/ffmpeg_encoder.c:165 @@ -2558,59 +2589,59 @@ msgstr "" msgid "encoding of subtitles" msgstr "" -#: src/libsputext/demux_sputext.c:1504 +#: src/libsputext/demux_sputext.c:1479 msgid "default duration of subtitle display in seconds" msgstr "" -#: src/libsputext/demux_sputext.c:1505 +#: src/libsputext/demux_sputext.c:1480 msgid "" "Some subtitle formats do not explicitly give a duration for each subtitle. " "For these, you can set a default duration here. Setting to zero will result " "in the subtitle being shown until the next one takes over." msgstr "" -#: src/libsputext/xine_sputext_decoder.c:928 +#: src/libsputext/xine_sputext_decoder.c:1151 msgid "subtitle size" msgstr "" -#: src/libsputext/xine_sputext_decoder.c:929 +#: src/libsputext/xine_sputext_decoder.c:1152 msgid "" "You can adjust the subtitle size here. The setting will be evaluated " "relative to the window size." msgstr "" -#: src/libsputext/xine_sputext_decoder.c:935 +#: src/libsputext/xine_sputext_decoder.c:1158 msgid "subtitle vertical offset" msgstr "" -#: src/libsputext/xine_sputext_decoder.c:936 +#: src/libsputext/xine_sputext_decoder.c:1159 msgid "" "You can adjust the vertical position of the subtitle. The setting will be " "evaluated relative to the window size." msgstr "" -#: src/libsputext/xine_sputext_decoder.c:942 -#: src/libsputext/xine_sputext_decoder.c:951 +#: src/libsputext/xine_sputext_decoder.c:1165 +#: src/libsputext/xine_sputext_decoder.c:1174 msgid "font for subtitles" msgstr "" -#: src/libsputext/xine_sputext_decoder.c:943 +#: src/libsputext/xine_sputext_decoder.c:1166 msgid "A font from the xine font directory to be used for the subtitle text." msgstr "" -#: src/libsputext/xine_sputext_decoder.c:952 +#: src/libsputext/xine_sputext_decoder.c:1175 msgid "An outline font file (e.g. a .ttf) to be used for the subtitle text." msgstr "" -#: src/libsputext/xine_sputext_decoder.c:958 +#: src/libsputext/xine_sputext_decoder.c:1181 msgid "whether to use a freetype font" msgstr "" -#: src/libsputext/xine_sputext_decoder.c:965 +#: src/libsputext/xine_sputext_decoder.c:1188 msgid "encoding of the subtitles" msgstr "" -#: src/libsputext/xine_sputext_decoder.c:966 +#: src/libsputext/xine_sputext_decoder.c:1189 msgid "" "The encoding of the subtitle text in the stream. This setting is used to " "render non-ASCII characters correctly. If non-ASCII characters are not " @@ -2618,11 +2649,11 @@ msgid "" "used." msgstr "" -#: src/libsputext/xine_sputext_decoder.c:974 +#: src/libsputext/xine_sputext_decoder.c:1197 msgid "use unscaled OSD if possible" msgstr "" -#: src/libsputext/xine_sputext_decoder.c:975 +#: src/libsputext/xine_sputext_decoder.c:1198 msgid "" "The unscaled OSD will be rendered independently of the video frame and will " "always be sharp, even if the video is magnified. This will look better, but " @@ -3073,10 +3104,10 @@ msgid "video colour key" msgstr "" #: src/video_out/video_out_directfb.c:1365 -#: src/video_out/video_out_vidix.c:1156 src/video_out/video_out_vidix.c:1163 -#: src/video_out/video_out_vidix.c:1170 src/video_out/video_out_xcbxv.c:1438 -#: src/video_out/video_out_xv.c:1491 src/video_out/video_out_xvmc.c:1445 -#: src/video_out/video_out_xxmc.c:2529 +#: src/video_out/video_out_vidix.c:1168 src/video_out/video_out_vidix.c:1175 +#: src/video_out/video_out_vidix.c:1182 src/video_out/video_out_xcbxv.c:1445 +#: src/video_out/video_out_xv.c:1503 src/video_out/video_out_xvmc.c:1464 +#: src/video_out/video_out_xxmc.c:2541 msgid "" "The colour key is used to tell the graphics card where to overlay the video " "image. Try different values, if you experience windows becoming transparent." @@ -3171,18 +3202,18 @@ msgstr "" msgid "xine video output plugin for win32 using directx" msgstr "" -#: src/video_out/video_out_fb.c:758 +#: src/video_out/video_out_fb.c:770 #, c-format msgid "" "video_out_fb: only packed truecolour/directcolour is supported (%d).\n" " Check 'fbset -i' or try 'fbset -depth 16'.\n" msgstr "" -#: src/video_out/video_out_fb.c:818 src/video_out/video_out_vidix.c:1236 +#: src/video_out/video_out_fb.c:830 src/video_out/video_out_vidix.c:1248 msgid "framebuffer device name" msgstr "" -#: src/video_out/video_out_fb.c:819 src/video_out/video_out_vidix.c:1237 +#: src/video_out/video_out_fb.c:831 src/video_out/video_out_vidix.c:1249 msgid "" "Specifies the file name for the framebuffer device to be used.\n" "This setting is security critical, because when changed to a different file, " @@ -3190,16 +3221,16 @@ msgid "" "careful that the value you enter really is a proper framebuffer device." msgstr "" -#: src/video_out/video_out_fb.c:893 +#: src/video_out/video_out_fb.c:905 msgid "video_out_fb: Your video mode was not recognized, sorry.\n" msgstr "" -#: src/video_out/video_out_fb.c:950 +#: src/video_out/video_out_fb.c:962 #, c-format msgid "video_out_fb: %d video RAM buffers are available.\n" msgstr "" -#: src/video_out/video_out_fb.c:956 +#: src/video_out/video_out_fb.c:968 #, c-format msgid "" "WARNING: video_out_fb: Zero copy buffers are DISABLED because only %d " @@ -3208,13 +3239,13 @@ msgid "" " the frame buffer resolution might help.\n" msgstr "" -#: src/video_out/video_out_fb.c:967 +#: src/video_out/video_out_fb.c:979 msgid "" "WARNING: video_out_fb: Zero copy buffers are DISABLED because kernel driver\n" " do not support screen panning (used for frame flips).\n" msgstr "" -#: src/video_out/video_out_fb.c:1036 +#: src/video_out/video_out_fb.c:1048 #, c-format msgid "" "WARNING: video_out_fb: current display depth is %d. For better performance\n" @@ -3222,7 +3253,7 @@ msgid "" "\n" msgstr "" -#: src/video_out/video_out_fb.c:1067 +#: src/video_out/video_out_fb.c:1079 msgid "Xine video output plugin using the Linux frame buffer device" msgstr "" @@ -3273,9 +3304,9 @@ msgid "" "Ignored for static render routines.\n" msgstr "" -#: src/video_out/video_out_opengl.c:1915 src/video_out/video_out_vidix.c:1012 -#: src/video_out/video_out_xcbxv.c:1470 src/video_out/video_out_xv.c:1523 -#: src/video_out/video_out_xvmc.c:1459 src/video_out/video_out_xxmc.c:2561 +#: src/video_out/video_out_opengl.c:1915 src/video_out/video_out_vidix.c:1024 +#: src/video_out/video_out_xcbxv.c:1477 src/video_out/video_out_xv.c:1535 +#: src/video_out/video_out_xvmc.c:1478 src/video_out/video_out_xxmc.c:2573 msgid "enable double buffering" msgstr "" @@ -3350,9 +3381,9 @@ msgstr "" msgid "video_out_pgx64: Error: ioctl failed (FBIOGATTR)\n" msgstr "" -#: src/video_out/video_out_pgx64.c:1461 src/video_out/video_out_xcbxv.c:1437 -#: src/video_out/video_out_xv.c:1490 src/video_out/video_out_xvmc.c:1444 -#: src/video_out/video_out_xxmc.c:2528 +#: src/video_out/video_out_pgx64.c:1461 src/video_out/video_out_xcbxv.c:1444 +#: src/video_out/video_out_xv.c:1502 src/video_out/video_out_xvmc.c:1463 +#: src/video_out/video_out_xxmc.c:2540 msgid "video overlay colour key" msgstr "" @@ -3383,26 +3414,26 @@ msgid "" "memory." msgstr "" -#: src/video_out/video_out_sdl.c:480 +#: src/video_out/video_out_sdl.c:488 msgid "use hardware acceleration if available" msgstr "" -#: src/video_out/video_out_sdl.c:481 +#: src/video_out/video_out_sdl.c:489 msgid "" "When your system supports it, hardware acceleration provided by your " "graphics hardware will be used. This might not work, so you can disable it, " "if things go wrong." msgstr "" -#: src/video_out/video_out_sdl.c:523 +#: src/video_out/video_out_sdl.c:531 msgid "sdl has to emulate a 16 bit surfaces, that will slow things down.\n" msgstr "" -#: src/video_out/video_out_sdl.c:560 +#: src/video_out/video_out_sdl.c:568 msgid "video_out_sdl: fullscreen mode is NOT supported\n" msgstr "" -#: src/video_out/video_out_sdl.c:571 +#: src/video_out/video_out_sdl.c:579 msgid "xine video output plugin using the Simple Direct Media Layer" msgstr "" @@ -3418,59 +3449,59 @@ msgstr "" msgid "video_out_syncfb: error. (YV12 not supported by your graphic card)\n" msgstr "" -#: src/video_out/video_out_syncfb.c:938 +#: src/video_out/video_out_syncfb.c:950 msgid "video_out_syncfb: info. (SyncFB module supports YUV 4:2:0 (3 plane))\n" msgstr "" -#: src/video_out/video_out_syncfb.c:943 +#: src/video_out/video_out_syncfb.c:955 msgid "video_out_syncfb: info. (SyncFB module supports YUV 4:2:0 (2 plane))\n" msgstr "" -#: src/video_out/video_out_syncfb.c:948 +#: src/video_out/video_out_syncfb.c:960 msgid "video_out_syncfb: info. (SyncFB module supports YUV 4:2:2)\n" msgstr "" -#: src/video_out/video_out_syncfb.c:954 +#: src/video_out/video_out_syncfb.c:966 msgid "video_out_syncfb: info. (SyncFB module supports YUY2)\n" msgstr "" -#: src/video_out/video_out_syncfb.c:961 +#: src/video_out/video_out_syncfb.c:973 msgid "video_out_syncfb: info. (SyncFB module supports RGB565)\n" msgstr "" -#: src/video_out/video_out_syncfb.c:966 +#: src/video_out/video_out_syncfb.c:978 msgid "" "video_out_syncfb: aborting. (SyncFB module does not support YV12, YUY2 nor " "RGB565)\n" msgstr "" -#: src/video_out/video_out_syncfb.c:985 +#: src/video_out/video_out_syncfb.c:997 msgid "" "video_out_syncfb: info. (brightness/contrast control won't be available " "because your SyncFB kernel module seems to be outdated. Please refer to " "README.syncfb for informations on how to update it.)\n" msgstr "" -#: src/video_out/video_out_syncfb.c:1009 +#: src/video_out/video_out_syncfb.c:1021 msgid "default number of frame repetitions" msgstr "" -#: src/video_out/video_out_syncfb.c:1010 +#: src/video_out/video_out_syncfb.c:1022 msgid "" "This specifies how many times a single video frame will be displayed " "consecutively." msgstr "" -#: src/video_out/video_out_syncfb.c:1058 +#: src/video_out/video_out_syncfb.c:1070 msgid "" "xine video output plugin using the SyncFB module for Matrox G200/G400 cards" msgstr "" -#: src/video_out/video_out_syncfb.c:1076 +#: src/video_out/video_out_syncfb.c:1088 msgid "SyncFB device name" msgstr "" -#: src/video_out/video_out_syncfb.c:1077 +#: src/video_out/video_out_syncfb.c:1089 msgid "" "Specifies the file name for the SyncFB (TeleTux) device to be used.\n" "This setting is security critical, because when changed to a different file, " @@ -3478,101 +3509,101 @@ msgid "" "careful that the value you enter really is a proper framebuffer device." msgstr "" -#: src/video_out/video_out_vidix.c:990 +#: src/video_out/video_out_vidix.c:1002 msgid "red intensity" msgstr "" -#: src/video_out/video_out_vidix.c:990 +#: src/video_out/video_out_vidix.c:1002 msgid "The intensity of the red colour components." msgstr "" -#: src/video_out/video_out_vidix.c:995 +#: src/video_out/video_out_vidix.c:1007 msgid "green intensity" msgstr "" -#: src/video_out/video_out_vidix.c:995 +#: src/video_out/video_out_vidix.c:1007 msgid "The intensity of the green colour components." msgstr "" -#: src/video_out/video_out_vidix.c:1000 +#: src/video_out/video_out_vidix.c:1012 msgid "blue intensity" msgstr "" -#: src/video_out/video_out_vidix.c:1000 +#: src/video_out/video_out_vidix.c:1012 msgid "The intensity of the blue colour components." msgstr "" -#: src/video_out/video_out_vidix.c:1013 src/video_out/video_out_xcbxv.c:1471 -#: src/video_out/video_out_xv.c:1524 src/video_out/video_out_xvmc.c:1460 -#: src/video_out/video_out_xxmc.c:2562 +#: src/video_out/video_out_vidix.c:1025 src/video_out/video_out_xcbxv.c:1478 +#: src/video_out/video_out_xv.c:1536 src/video_out/video_out_xvmc.c:1479 +#: src/video_out/video_out_xxmc.c:2574 msgid "" "Double buffering will synchronize the update of the video image to the " "repainting of the entire screen (\"vertical retrace\"). This eliminates " "flickering and tearing artifacts, but will use more graphics memory." msgstr "" -#: src/video_out/video_out_vidix.c:1060 +#: src/video_out/video_out_vidix.c:1072 msgid "video_out_vidix: adaptor supports the yuy2 format\n" msgstr "" -#: src/video_out/video_out_vidix.c:1071 +#: src/video_out/video_out_vidix.c:1083 msgid "video_out_vidix: adaptor supports the yv12 format\n" msgstr "" -#: src/video_out/video_out_vidix.c:1087 +#: src/video_out/video_out_vidix.c:1099 msgid "video_out_vidix: You have wrong version of VIDIX library\n" msgstr "" -#: src/video_out/video_out_vidix.c:1095 +#: src/video_out/video_out_vidix.c:1107 msgid "video_out_vidix: Couldn't find working VIDIX driver\n" msgstr "" -#: src/video_out/video_out_vidix.c:1108 +#: src/video_out/video_out_vidix.c:1120 #, c-format msgid "video_out_vidix: using driver: %s by %s\n" msgstr "" -#: src/video_out/video_out_vidix.c:1155 +#: src/video_out/video_out_vidix.c:1167 msgid "video overlay colour key red component" msgstr "" -#: src/video_out/video_out_vidix.c:1162 +#: src/video_out/video_out_vidix.c:1174 msgid "video overlay colour key green component" msgstr "" -#: src/video_out/video_out_vidix.c:1169 +#: src/video_out/video_out_vidix.c:1181 msgid "video overlay colour key blue component" msgstr "" -#: src/video_out/video_out_vidix.c:1201 +#: src/video_out/video_out_vidix.c:1213 msgid "xine video output plugin using libvidix for x11" msgstr "" -#: src/video_out/video_out_vidix.c:1283 +#: src/video_out/video_out_vidix.c:1295 msgid "xine video output plugin using libvidix for linux frame buffer" msgstr "" -#: src/video_out/video_out_xcbshm.c:155 +#: src/video_out/video_out_xcbshm.c:150 #, c-format msgid "" "video_out_xcbshm: %s: allocating image\n" "video_out_xcbshm: => not using MIT Shared Memory extension.\n" msgstr "" -#: src/video_out/video_out_xcbshm.c:164 +#: src/video_out/video_out_xcbshm.c:159 msgid "" "video_out_xcbshm: shared memory error (address error) when allocating " "image \n" "video_out_xcbshm: => not using MIT Shared Memory extension.\n" msgstr "" -#: src/video_out/video_out_xcbshm.c:175 +#: src/video_out/video_out_xcbshm.c:170 msgid "" "video_out_xcbshm: x11 error during shared memory XImage creation\n" "video_out_xcbshm: => not using MIT Shared Memory extension.\n" msgstr "" -#: src/video_out/video_out_xcbshm.c:1098 src/video_out/video_out_xshm.c:1154 +#: src/video_out/video_out_xcbshm.c:1101 src/video_out/video_out_xshm.c:1157 #, c-format msgid "" "\n" @@ -3582,42 +3613,42 @@ msgid "" "\n" msgstr "" -#: src/video_out/video_out_xcbshm.c:1111 +#: src/video_out/video_out_xcbshm.c:1114 msgid "video_out_xcbshm: MIT shared memory extension not present on display.\n" msgstr "" -#: src/video_out/video_out_xcbshm.c:1210 +#: src/video_out/video_out_xcbshm.c:1213 msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n" msgstr "" -#: src/video_out/video_out_xcbshm.c:1240 src/video_out/video_out_xshm.c:1300 +#: src/video_out/video_out_xcbshm.c:1243 src/video_out/video_out_xshm.c:1303 msgid "xine video output plugin using the MIT X shared memory extension" msgstr "" -#: src/video_out/video_out_xcbxv.c:268 +#: src/video_out/video_out_xcbxv.c:263 msgid "" "video_out_xcbxv: XvShmCreateImage returned a zero size\n" "video_out_xcbxv: => not using MIT Shared Memory extension.\n" msgstr "" -#: src/video_out/video_out_xcbxv.c:277 +#: src/video_out/video_out_xcbxv.c:272 #, c-format msgid "" "video_out_xcbxv: shared memory error in shmget: %s\n" "video_out_xcbxv: => not using MIT Shared Memory extension.\n" msgstr "" -#: src/video_out/video_out_xcbxv.c:296 +#: src/video_out/video_out_xcbxv.c:291 msgid "" "video_out_xcbxv: x11 error during shared memory XImage creation\n" "video_out_xcbxv: => not using MIT Shared Memory extension.\n" msgstr "" -#: src/video_out/video_out_xcbxv.c:1289 +#: src/video_out/video_out_xcbxv.c:1296 msgid "video_out_xcbxv: Xv extension not present.\n" msgstr "" -#: src/video_out/video_out_xcbxv.c:1331 +#: src/video_out/video_out_xcbxv.c:1338 msgid "" "video_out_xcbxv: Xv extension is present but I couldn't find a usable yuv12 " "port.\n" @@ -3625,30 +3656,30 @@ msgid "" "Xv?!\n" msgstr "" -#: src/video_out/video_out_xcbxv.c:1339 +#: src/video_out/video_out_xcbxv.c:1346 #, c-format msgid "" "video_out_xcbxv: using Xv port %d from adaptor %s for hardware colour space " "conversion and scaling.\n" msgstr "" -#: src/video_out/video_out_xcbxv.c:1446 src/video_out/video_out_xv.c:1499 -#: src/video_out/video_out_xvmc.c:1453 src/video_out/video_out_xxmc.c:2537 +#: src/video_out/video_out_xcbxv.c:1453 src/video_out/video_out_xv.c:1511 +#: src/video_out/video_out_xvmc.c:1472 src/video_out/video_out_xxmc.c:2549 msgid "autopaint colour key" msgstr "" -#: src/video_out/video_out_xcbxv.c:1447 src/video_out/video_out_xv.c:1500 -#: src/video_out/video_out_xvmc.c:1454 src/video_out/video_out_xxmc.c:2538 +#: src/video_out/video_out_xcbxv.c:1454 src/video_out/video_out_xv.c:1512 +#: src/video_out/video_out_xvmc.c:1473 src/video_out/video_out_xxmc.c:2550 msgid "Make Xv autopaint its colour key." msgstr "" -#: src/video_out/video_out_xcbxv.c:1454 src/video_out/video_out_xv.c:1507 -#: src/video_out/video_out_xxmc.c:2545 +#: src/video_out/video_out_xcbxv.c:1461 src/video_out/video_out_xv.c:1519 +#: src/video_out/video_out_xxmc.c:2557 msgid "bilinear scaling mode" msgstr "" -#: src/video_out/video_out_xcbxv.c:1455 src/video_out/video_out_xv.c:1508 -#: src/video_out/video_out_xxmc.c:2546 +#: src/video_out/video_out_xcbxv.c:1462 src/video_out/video_out_xv.c:1520 +#: src/video_out/video_out_xxmc.c:2558 msgid "" "Selects the bilinear scaling mode for Permedia cards. The individual values " "are:\n" @@ -3663,31 +3694,31 @@ msgid "" "2 - enable full bilinear filtering" msgstr "" -#: src/video_out/video_out_xcbxv.c:1507 +#: src/video_out/video_out_xcbxv.c:1514 msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n" msgstr "" -#: src/video_out/video_out_xcbxv.c:1512 +#: src/video_out/video_out_xcbxv.c:1519 msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n" msgstr "" -#: src/video_out/video_out_xcbxv.c:1520 src/video_out/video_out_xv.c:1584 -#: src/video_out/video_out_xxmc.c:2630 +#: src/video_out/video_out_xcbxv.c:1527 src/video_out/video_out_xv.c:1596 +#: src/video_out/video_out_xxmc.c:2642 msgid "pitch alignment workaround" msgstr "" -#: src/video_out/video_out_xcbxv.c:1521 src/video_out/video_out_xv.c:1585 -#: src/video_out/video_out_xxmc.c:2631 +#: src/video_out/video_out_xcbxv.c:1528 src/video_out/video_out_xv.c:1597 +#: src/video_out/video_out_xxmc.c:2643 msgid "Some buggy video drivers need a workaround to function properly." msgstr "" -#: src/video_out/video_out_xcbxv.c:1527 src/video_out/video_out_xv.c:1591 -#: src/video_out/video_out_xvmc.c:1522 +#: src/video_out/video_out_xcbxv.c:1534 src/video_out/video_out_xv.c:1603 +#: src/video_out/video_out_xvmc.c:1541 msgid "deinterlace method (deprecated)" msgstr "" -#: src/video_out/video_out_xcbxv.c:1528 src/video_out/video_out_xv.c:1592 -#: src/video_out/video_out_xvmc.c:1523 +#: src/video_out/video_out_xcbxv.c:1535 src/video_out/video_out_xv.c:1604 +#: src/video_out/video_out_xvmc.c:1542 msgid "" "This config setting is deprecated. You should use the new deinterlacing post " "processing settings instead.\n" @@ -3725,41 +3756,41 @@ msgid "" "with medium CPU usage." msgstr "" -#: src/video_out/video_out_xcbxv.c:1582 src/video_out/video_out_xv.c:1665 -#: src/video_out/video_out_xxmc.c:2725 +#: src/video_out/video_out_xcbxv.c:1589 src/video_out/video_out_xv.c:1677 +#: src/video_out/video_out_xxmc.c:2737 msgid "xine video output plugin using the MIT X video extension" msgstr "" -#: src/video_out/video_out_xshm.c:199 +#: src/video_out/video_out_xshm.c:194 msgid "" "video_out_xshm: shared memory error when allocating image\n" "video_out_xshm: => not using MIT Shared Memory extension.\n" msgstr "" -#: src/video_out/video_out_xshm.c:215 +#: src/video_out/video_out_xshm.c:210 #, c-format msgid "" "video_out_xshm: %s: allocating image\n" "video_out_xshm: => not using MIT Shared Memory extension.\n" msgstr "" -#: src/video_out/video_out_xshm.c:225 +#: src/video_out/video_out_xshm.c:220 msgid "" "video_out_xshm: shared memory error (address error) when allocating image \n" "video_out_xshm: => not using MIT Shared Memory extension.\n" msgstr "" -#: src/video_out/video_out_xshm.c:242 +#: src/video_out/video_out_xshm.c:237 msgid "" "video_out_xshm: x11 error during shared memory XImage creation\n" "video_out_xshm: => not using MIT Shared Memory extension.\n" msgstr "" -#: src/video_out/video_out_xshm.c:1167 +#: src/video_out/video_out_xshm.c:1170 msgid "video_out_xshm: MIT shared memory extension not present on display.\n" msgstr "" -#: src/video_out/video_out_xshm.c:1251 +#: src/video_out/video_out_xshm.c:1254 msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n" msgstr "" @@ -3788,66 +3819,66 @@ msgid "" "video_out_xv: => not using MIT Shared Memory extension.\n" msgstr "" -#: src/video_out/video_out_xv.c:1336 +#: src/video_out/video_out_xv.c:1348 msgid "video_out_xv: Xv extension not present.\n" msgstr "" -#: src/video_out/video_out_xv.c:1373 +#: src/video_out/video_out_xv.c:1385 msgid "" "video_out_xv: Xv extension is present but I couldn't find a usable yuv12 " "port.\n" " Looks like your graphics hardware driver doesn't support Xv?!\n" msgstr "" -#: src/video_out/video_out_xv.c:1382 +#: src/video_out/video_out_xv.c:1394 #, c-format msgid "" "video_out_xv: using Xv port %ld from adaptor %s for hardware colour space " "conversion and scaling.\n" msgstr "" -#: src/video_out/video_out_xv.c:1557 +#: src/video_out/video_out_xv.c:1569 msgid "video_out_xv: this adaptor supports the yv12 format.\n" msgstr "" -#: src/video_out/video_out_xv.c:1562 +#: src/video_out/video_out_xv.c:1574 msgid "video_out_xv: this adaptor supports the yuy2 format.\n" msgstr "" -#: src/video_out/video_out_xvmc.c:1591 +#: src/video_out/video_out_xvmc.c:1610 msgid "xine video output plugin using the XvMC X video extension" msgstr "" -#: src/video_out/video_out_xvmc.c:1637 +#: src/video_out/video_out_xvmc.c:1656 msgid "video_out_xvmc: XvMC extension not present.\n" msgstr "" -#: src/video_out/video_out_xvmc.c:1735 +#: src/video_out/video_out_xvmc.c:1754 msgid "" "video_out_xvmc: Xv extension is present but I couldn't find a usable yuv12 " "port.\n" msgstr "" -#: src/video_out/video_out_xvmc.c:1744 +#: src/video_out/video_out_xvmc.c:1763 #, c-format msgid "" "video_out_xvmc: using Xv port %ld from adaptor %s\n" " for hardware colour space conversion and scaling\n" msgstr "" -#: src/video_out/video_out_xvmc.c:1749 +#: src/video_out/video_out_xvmc.c:1768 msgid " idct and motion compensation acceleration \n" msgstr "" -#: src/video_out/video_out_xvmc.c:1751 +#: src/video_out/video_out_xvmc.c:1770 msgid " motion compensation acceleration only\n" msgstr "" -#: src/video_out/video_out_xvmc.c:1753 +#: src/video_out/video_out_xvmc.c:1772 msgid " no XvMC support \n" msgstr "" -#: src/video_out/video_out_xvmc.c:1754 +#: src/video_out/video_out_xvmc.c:1773 #, c-format msgid " With Overlay = %d; UnsignedIntra = %d.\n" msgstr "" @@ -3877,89 +3908,89 @@ msgid "" "video_out_xxmc: => not using MIT Shared Memory extension.\n" msgstr "" -#: src/video_out/video_out_xxmc.c:2380 +#: src/video_out/video_out_xxmc.c:2392 msgid "video_out_xxmc: Xv extension not present.\n" msgstr "" -#: src/video_out/video_out_xxmc.c:2417 +#: src/video_out/video_out_xxmc.c:2429 msgid "" "video_out_xxmc: Xv extension is present but I couldn't find a usable yuv12 " "port.\n" " Looks like your graphics hardware driver doesn't support Xv?!\n" msgstr "" -#: src/video_out/video_out_xxmc.c:2426 +#: src/video_out/video_out_xxmc.c:2438 #, c-format msgid "" "video_out_xxmc: using Xv port %ld from adaptor %s for hardware colour space " "conversion and scaling.\n" msgstr "" -#: src/video_out/video_out_xxmc.c:2602 +#: src/video_out/video_out_xxmc.c:2614 msgid "video_out_xxmc: this adaptor supports the yv12 format.\n" msgstr "" -#: src/video_out/video_out_xxmc.c:2607 +#: src/video_out/video_out_xxmc.c:2619 msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n" msgstr "" -#: src/video_out/video_out_xxmc.c:2636 +#: src/video_out/video_out_xxmc.c:2648 msgid "Make XvMC allocate more frames for better buffering." msgstr "" -#: src/video_out/video_out_xxmc.c:2637 +#: src/video_out/video_out_xxmc.c:2649 msgid "" "Some XvMC implementations allow more than 8 frames.\n" "This option, when turned on, makes the driver try to\n" "allocate 15 frames. A must for unichrome and live VDR.\n" msgstr "" -#: src/video_out/video_out_xxmc.c:2643 +#: src/video_out/video_out_xxmc.c:2655 msgid "Unichrome cpu save" msgstr "" -#: src/video_out/video_out_xxmc.c:2644 +#: src/video_out/video_out_xxmc.c:2656 msgid "" "Saves CPU time by sleeping while decoder works.\n" "Only for Linux kernel 2.6 series or 2.4 with multimedia patch.\n" "Experimental.\n" msgstr "" -#: src/video_out/video_out_xxmc.c:2650 +#: src/video_out/video_out_xxmc.c:2662 msgid "Fix buggy NVIDIA XvMC subpicture colours" msgstr "" -#: src/video_out/video_out_xxmc.c:2651 +#: src/video_out/video_out_xxmc.c:2663 msgid "" "There's a bug in NVIDIA's XvMC lib that makes red OSD colours\n" "look blue and vice versa. This option provides a workaround.\n" msgstr "" -#: src/video_out/video_out_xxmc.c:2656 +#: src/video_out/video_out_xxmc.c:2668 msgid "Use bob as accelerated deinterlace method." msgstr "" -#: src/video_out/video_out_xxmc.c:2657 +#: src/video_out/video_out_xxmc.c:2669 msgid "" "When interlacing is enabled for hardware accelerated frames,\n" "alternate between top and bottom field at double the frame rate.\n" msgstr "" -#: src/video_out/video_out_xxmc.c:2663 +#: src/video_out/video_out_xxmc.c:2675 msgid "Don't use bob deinterlacing for progressive frames." msgstr "" -#: src/video_out/video_out_xxmc.c:2664 +#: src/video_out/video_out_xxmc.c:2676 msgid "" "Progressive frames don't need deinterlacing, so disabling it on\n" "demand should result in a better picture.\n" msgstr "" -#: src/video_out/video_out_xxmc.c:2670 +#: src/video_out/video_out_xxmc.c:2682 msgid "Don't use bob deinterlacing while a scaled OSD is active." msgstr "" -#: src/video_out/video_out_xxmc.c:2671 +#: src/video_out/video_out_xxmc.c:2683 msgid "" "Bob deinterlacing adds some noise to horizontal lines, so disabling it\n" "on demand should result in a better OSD picture.\n" @@ -4017,32 +4048,32 @@ msgid "" "increased latency and memory consumption." msgstr "" -#: src/xine-engine/audio_out.c:1109 +#: src/xine-engine/audio_out.c:1110 msgid "" "audio_out: delay calculation impossible with an unavailable audio device\n" msgstr "" -#: src/xine-engine/audio_out.c:1248 +#: src/xine-engine/audio_out.c:1249 msgid "write to sound card failed. Assuming the device was unplugged.\n" msgstr "" -#: src/xine-engine/audio_out.c:1420 +#: src/xine-engine/audio_out.c:1421 msgid "8 bits not supported by driver, converting to 16 bits.\n" msgstr "" -#: src/xine-engine/audio_out.c:1428 +#: src/xine-engine/audio_out.c:1429 msgid "mono not supported by driver, converting to stereo.\n" msgstr "" -#: src/xine-engine/audio_out.c:1434 +#: src/xine-engine/audio_out.c:1435 msgid "stereo not supported by driver, converting to mono.\n" msgstr "" -#: src/xine-engine/audio_out.c:2093 +#: src/xine-engine/audio_out.c:2098 msgid "method to sync audio and video" msgstr "" -#: src/xine-engine/audio_out.c:2094 +#: src/xine-engine/audio_out.c:2099 msgid "" "When playing audio and video, there are at least two clocks involved: The " "system clock, to which video frames are synchronized and the clock in your " @@ -4065,11 +4096,11 @@ msgid "" "form." msgstr "" -#: src/xine-engine/audio_out.c:2122 +#: src/xine-engine/audio_out.c:2127 msgid "enable resampling" msgstr "" -#: src/xine-engine/audio_out.c:2123 +#: src/xine-engine/audio_out.c:2128 msgid "" "When the sample rate of the decoded audio does not match the capabilities of " "your sound hardware, an adaptation called \"resampling\" is required. Here " @@ -4077,33 +4108,33 @@ msgid "" "automatically when necessary." msgstr "" -#: src/xine-engine/audio_out.c:2130 +#: src/xine-engine/audio_out.c:2135 msgid "always resample to this rate (0 to disable)" msgstr "" -#: src/xine-engine/audio_out.c:2131 +#: src/xine-engine/audio_out.c:2136 msgid "" "Some audio drivers do not correctly announce the capabilities of the audio " "hardware. By setting a value other than zero here, you can force the audio " "stream to be resampled to the given rate." msgstr "" -#: src/xine-engine/audio_out.c:2140 +#: src/xine-engine/audio_out.c:2145 msgid "offset for digital passthrough" msgstr "" -#: src/xine-engine/audio_out.c:2141 +#: src/xine-engine/audio_out.c:2146 msgid "" "If you use an external surround decoder and audio is ahead or behind video, " "you can enter a fixed offset here to compensate.\n" "The unit of the value is one PTS tick, which is the 90000th part of a second." msgstr "" -#: src/xine-engine/audio_out.c:2150 +#: src/xine-engine/audio_out.c:2155 msgid "play audio even on slow/fast speeds" msgstr "" -#: src/xine-engine/audio_out.c:2151 +#: src/xine-engine/audio_out.c:2156 msgid "" "If you enable this option, the audio will be heard even when playback speed " "is different than 1X. Of course, it will sound distorted (lower/higher " @@ -4111,23 +4142,23 @@ msgid "" "audio post plugin instead." msgstr "" -#: src/xine-engine/audio_out.c:2224 +#: src/xine-engine/audio_out.c:2229 msgid "startup audio volume" msgstr "" -#: src/xine-engine/audio_out.c:2225 +#: src/xine-engine/audio_out.c:2230 msgid "The overall audio volume set at xine startup." msgstr "" -#: src/xine-engine/audio_out.c:2228 +#: src/xine-engine/audio_out.c:2233 msgid "restore volume level at startup" msgstr "" -#: src/xine-engine/audio_out.c:2229 +#: src/xine-engine/audio_out.c:2234 msgid "If disabled, xine will not modify any mixer settings at startup." msgstr "" -#: src/xine-engine/audio_out.c:2259 +#: src/xine-engine/audio_out.c:2264 msgid "audio_out: sorry, this should not happen. please restart xine.\n" msgstr "" @@ -4150,22 +4181,22 @@ msgstr "" msgid "configfile: WARNING: your configuration will not be saved\n" msgstr "" -#: src/xine-engine/configfile.c:1138 +#: src/xine-engine/configfile.c:1139 #, c-format msgid "configfile: WARNING: writing configuration to %s failed\n" msgstr "" -#: src/xine-engine/configfile.c:1139 +#: src/xine-engine/configfile.c:1140 #, c-format msgid "configfile: WARNING: removing possibly broken config file %s\n" msgstr "" -#: src/xine-engine/configfile.c:1140 +#: src/xine-engine/configfile.c:1141 #, c-format msgid "configfile: WARNING: you should check the backup file %s\n" msgstr "" -#: src/xine-engine/configfile.c:1275 +#: src/xine-engine/configfile.c:1276 #, c-format msgid "configfile: entry '%s' mustn't be modified from MRL\n" msgstr "" @@ -4516,70 +4547,70 @@ msgid "" "foreground-border-background." msgstr "" -#: src/xine-engine/video_decoder.c:377 +#: src/xine-engine/video_decoder.c:387 #, c-format msgid "video_decoder: no plugin available to handle '%s'\n" msgstr "" -#: src/xine-engine/video_decoder.c:456 +#: src/xine-engine/video_decoder.c:466 #, c-format msgid "video_decoder: error, unknown buffer type: %08x\n" msgstr "" -#: src/xine-engine/video_decoder.c:492 +#: src/xine-engine/video_decoder.c:502 msgid "number of video buffers" msgstr "" -#: src/xine-engine/video_decoder.c:493 +#: src/xine-engine/video_decoder.c:503 msgid "" "The number of video buffers (each is 8k in size) xine uses in its internal " "queue. Higher values mean smoother playback for unreliable inputs, but also " "increased latency and memory consumption." msgstr "" -#: src/xine-engine/video_out.c:640 +#: src/xine-engine/video_out.c:666 #, c-format msgid "%d frames delivered, %d frames skipped, %d frames discarded\n" msgstr "" -#: src/xine-engine/video_out.c:813 +#: src/xine-engine/video_out.c:839 #, c-format msgid "" "video_out: throwing away image with pts %<PRId64> because it's too old " "(diff : %<PRId64>).\n" msgstr "" -#: src/xine-engine/video_out.c:1793 +#: src/xine-engine/video_out.c:1817 msgid "default number of video frames" msgstr "" -#: src/xine-engine/video_out.c:1794 +#: src/xine-engine/video_out.c:1818 msgid "" "The default number of video frames to request from xine video out driver. " "Some drivers will override this setting with their own values." msgstr "" -#: src/xine-engine/video_out.c:1833 +#: src/xine-engine/video_out.c:1875 msgid "percentage of skipped frames to tolerate" msgstr "" -#: src/xine-engine/video_out.c:1834 +#: src/xine-engine/video_out.c:1876 msgid "" "When more than this percentage of frames are not shown, because they were " "not decoded in time, xine sends a notification." msgstr "" -#: src/xine-engine/video_out.c:1839 +#: src/xine-engine/video_out.c:1881 msgid "percentage of discarded frames to tolerate" msgstr "" -#: src/xine-engine/video_out.c:1840 +#: src/xine-engine/video_out.c:1882 msgid "" "When more than this percentage of frames are not shown, because they were " "not scheduled for display in time, xine sends a notification." msgstr "" -#: src/xine-engine/video_out.c:1874 +#: src/xine-engine/video_out.c:1916 msgid "video_out: sorry, this should not happen. please restart xine.\n" msgstr "" @@ -4622,132 +4653,132 @@ msgid "" "accelerated, this can dramatically reduce CPU usage." msgstr "" -#: src/xine-engine/xine.c:789 src/xine-engine/xine.c:896 -#: src/xine-engine/xine.c:935 src/xine-engine/xine.c:971 -#: src/xine-engine/xine.c:983 src/xine-engine/xine.c:996 -#: src/xine-engine/xine.c:1009 src/xine-engine/xine.c:1022 -#: src/xine-engine/xine.c:1048 src/xine-engine/xine.c:1073 -#: src/xine-engine/xine.c:1108 +#: src/xine-engine/xine.c:802 src/xine-engine/xine.c:909 +#: src/xine-engine/xine.c:949 src/xine-engine/xine.c:985 +#: src/xine-engine/xine.c:997 src/xine-engine/xine.c:1010 +#: src/xine-engine/xine.c:1023 src/xine-engine/xine.c:1036 +#: src/xine-engine/xine.c:1062 src/xine-engine/xine.c:1087 +#: src/xine-engine/xine.c:1124 msgid "xine: error while parsing mrl\n" msgstr "" -#: src/xine-engine/xine.c:831 +#: src/xine-engine/xine.c:844 #, c-format msgid "xine: found input plugin : %s\n" msgstr "" -#: src/xine-engine/xine.c:848 +#: src/xine-engine/xine.c:861 #, c-format msgid "xine: input plugin cannot open MRL [%s]\n" msgstr "" -#: src/xine-engine/xine.c:859 +#: src/xine-engine/xine.c:872 #, c-format msgid "xine: cannot find input plugin for MRL [%s]\n" msgstr "" -#: src/xine-engine/xine.c:885 +#: src/xine-engine/xine.c:898 #, c-format msgid "xine: specified demuxer %s failed to start\n" msgstr "" -#: src/xine-engine/xine.c:921 +#: src/xine-engine/xine.c:935 #, c-format msgid "xine: join rip input plugin\n" msgstr "" -#: src/xine-engine/xine.c:928 +#: src/xine-engine/xine.c:942 msgid "xine: error opening rip input plugin instance\n" msgstr "" -#: src/xine-engine/xine.c:959 +#: src/xine-engine/xine.c:973 #, c-format msgid "xine: last_probed demuxer %s failed to start\n" msgstr "" -#: src/xine-engine/xine.c:988 +#: src/xine-engine/xine.c:1002 msgid "ignoring video\n" msgstr "" -#: src/xine-engine/xine.c:1001 +#: src/xine-engine/xine.c:1015 msgid "ignoring audio\n" msgstr "" -#: src/xine-engine/xine.c:1014 +#: src/xine-engine/xine.c:1028 msgid "ignoring subpicture\n" msgstr "" -#: src/xine-engine/xine.c:1027 +#: src/xine-engine/xine.c:1041 msgid "input cache plugin disabled\n" msgstr "" -#: src/xine-engine/xine.c:1098 +#: src/xine-engine/xine.c:1114 #, c-format msgid "subtitle mrl opened '%s'\n" msgstr "" -#: src/xine-engine/xine.c:1102 +#: src/xine-engine/xine.c:1118 msgid "xine: error opening subtitle mrl\n" msgstr "" -#: src/xine-engine/xine.c:1134 +#: src/xine-engine/xine.c:1150 #, c-format msgid "xine: error while parsing MRL\n" msgstr "" -#: src/xine-engine/xine.c:1141 +#: src/xine-engine/xine.c:1157 #, c-format msgid "xine: changing option '%s' from MRL isn't permitted\n" msgstr "" -#: src/xine-engine/xine.c:1161 +#: src/xine-engine/xine.c:1177 #, c-format msgid "xine: couldn't find demux for >%s<\n" msgstr "" -#: src/xine-engine/xine.c:1177 +#: src/xine-engine/xine.c:1193 #, c-format msgid "xine: found demuxer plugin: %s\n" msgstr "" -#: src/xine-engine/xine.c:1198 +#: src/xine-engine/xine.c:1214 #, c-format msgid "xine: demuxer is already done. that was fast!\n" msgstr "" -#: src/xine-engine/xine.c:1200 +#: src/xine-engine/xine.c:1216 #, c-format msgid "xine: demuxer failed to start\n" msgstr "" -#: src/xine-engine/xine.c:1266 +#: src/xine-engine/xine.c:1282 #, c-format msgid "xine_play: no demux available\n" msgstr "" -#: src/xine-engine/xine.c:1336 +#: src/xine-engine/xine.c:1352 #, c-format msgid "xine_play: demux failed to start\n" msgstr "" -#: src/xine-engine/xine.c:1612 +#: src/xine-engine/xine.c:1628 #, c-format msgid "xine: The specified save_dir \"%s\" might be a security risk.\n" msgstr "" -#: src/xine-engine/xine.c:1617 +#: src/xine-engine/xine.c:1633 msgid "The specified save_dir might be a security risk." msgstr "" -#: src/xine-engine/xine.c:1643 +#: src/xine-engine/xine.c:1659 msgid "xine: locale not supported by C library\n" msgstr "" -#: src/xine-engine/xine.c:1652 +#: src/xine-engine/xine.c:1668 msgid "media format detection strategy" msgstr "" -#: src/xine-engine/xine.c:1653 +#: src/xine-engine/xine.c:1669 msgid "" "xine offers various methods to detect the media format of input to play. The " "individual values are:\n" @@ -4765,11 +4796,11 @@ msgid "" "Detect by file name extension only.\n" msgstr "" -#: src/xine-engine/xine.c:1671 +#: src/xine-engine/xine.c:1687 msgid "directory for saving streams" msgstr "" -#: src/xine-engine/xine.c:1672 +#: src/xine-engine/xine.c:1688 msgid "" "When using the stream save feature, files will be written only into this " "directory.\n" @@ -4779,11 +4810,11 @@ msgid "" "content in any file." msgstr "" -#: src/xine-engine/xine.c:1683 +#: src/xine-engine/xine.c:1699 msgid "allow implicit changes to the configuration (e.g. by MRL)" msgstr "" -#: src/xine-engine/xine.c:1684 +#: src/xine-engine/xine.c:1700 msgid "" "If enabled, you allow xine to change your configuration without explicit " "actions from your side. For example configuration changes demanded by MRLs " @@ -4793,26 +4824,26 @@ msgid "" "configuration, you might end with a totally messed up xine." msgstr "" -#: src/xine-engine/xine.c:1698 +#: src/xine-engine/xine.c:1714 msgid "Timeout for network stream reading (in seconds)" msgstr "" -#: src/xine-engine/xine.c:1699 +#: src/xine-engine/xine.c:1715 msgid "" "Specifies the timeout when reading from network streams, in seconds. Too low " "values might stop streaming when the source is slow or the bandwidth is " "occupied, too high values will freeze the player if the connection is lost." msgstr "" -#: src/xine-engine/xine.c:2051 +#: src/xine-engine/xine.c:2067 msgid "messages" msgstr "" -#: src/xine-engine/xine.c:2052 +#: src/xine-engine/xine.c:2068 msgid "plugin" msgstr "" -#: src/xine-engine/xine.c:2053 +#: src/xine-engine/xine.c:2069 msgid "trace" msgstr "" -- cgit v1.2.3 From c018c8408df06dcf47c2c924e0b88a6a048573de Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 26 Jan 2008 17:42:56 +0000 Subject: Quick hack to allow configuration of the V4L ALSA audio input device. --- ChangeLog | 1 + src/input/input_v4l.c | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 75ac42bf8..80791eb18 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,7 @@ xine-lib (1.1.10) (unreleased) * Don't discard audio samples forever. Fixed streaming playback. * Fix a possible crash on channel change in the DVB plugin. * Flash video demuxer improvements and bug fixes. + * Make the V4L ALSA audio input device configurable. (This needs more work.) xine-lib (1.1.9.1) 2008-01-11 * Security fixes: diff --git a/src/input/input_v4l.c b/src/input/input_v4l.c index 34f6a0684..d0558b492 100644 --- a/src/input/input_v4l.c +++ b/src/input/input_v4l.c @@ -93,6 +93,9 @@ static const resolution_t resolutions[] = { #define NUM_RESOLUTIONS (sizeof(resolutions)/sizeof(resolutions[0])) #define RADIO_DEV "/dev/radio0" #define VIDEO_DEV "/dev/video0" +#ifdef HAVE_ALSA +#define AUDIO_DEV "plughw:0,0" +#endif #if !defined(NDELAY) && defined(O_NDELAY) #define FNDELAY O_NDELAY @@ -1701,6 +1704,9 @@ static input_plugin_t *v4l_class_get_instance (input_class_t *cls_gen, { /* v4l_input_class_t *cls = (v4l_input_class_t *) cls_gen; */ v4l_input_plugin_t *this; +#ifdef HAVE_ALSA + cfg_entry_t *entry; +#endif char *mrl = strdup(data); /* Example mrl: v4l:/Television/62500 */ @@ -1721,13 +1727,14 @@ static input_plugin_t *v4l_class_get_instance (input_class_t *cls_gen, this->event_queue = NULL; this->scr = NULL; #ifdef HAVE_ALSA - this->pcm_name = NULL; this->pcm_data = NULL; this->pcm_hwparams = NULL; /* Audio */ this->pcm_stream = SND_PCM_STREAM_CAPTURE; - this->pcm_name = strdup("plughw:0,0"); + entry = this->stream->xine->config->lookup_entry(this->stream->xine->config, + "media.video4linux.audio_device"); + this->pcm_name = strdup (entry->str_value); this->audio_capture = 1; #endif this->rate = 44100; @@ -1910,7 +1917,15 @@ static void *init_video_class (xine_t *xine, void *data) _("v4l video device"), _("The path to your Video4Linux video device."), 10, NULL, NULL); - +#ifdef HAVE_ALSA + config->register_filename (config, "media.video4linux.audio_device", + AUDIO_DEV, 0, + _("v4l ALSA audio input device"), + _("The name of the audio device which corresponds " + "to your Video4Linux video device."), + 10, NULL, NULL); +#endif + return this; } -- cgit v1.2.3 From e24b61023d44bdf561fe0a3dc5b7d5f996547d9c Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 26 Jan 2008 17:44:45 +0000 Subject: Resync translation source file (again). --- po/libxine1.pot | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/po/libxine1.pot b/po/libxine1.pot index 3a9a95f4b..fe631b703 100644 --- a/po/libxine1.pot +++ b/po/libxine1.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: xine-devel@lists.sourceforge.net\n" -"POT-Creation-Date: 2008-01-26 14:49+0000\n" +"POT-Creation-Date: 2008-01-26 17:44+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -1923,43 +1923,53 @@ msgstr "" msgid "stdin streaming input plugin" msgstr "" -#: src/input/input_v4l.c:379 +#: src/input/input_v4l.c:382 msgid "Buffer underrun..." msgstr "" -#: src/input/input_v4l.c:383 +#: src/input/input_v4l.c:386 msgid "Buffer overrun..." msgstr "" -#: src/input/input_v4l.c:386 +#: src/input/input_v4l.c:389 msgid "Adjusting..." msgstr "" -#: src/input/input_v4l.c:658 +#: src/input/input_v4l.c:661 msgid "Tuner name not found\n" msgstr "" -#: src/input/input_v4l.c:1874 +#: src/input/input_v4l.c:1881 msgid "v4l tv input plugin" msgstr "" -#: src/input/input_v4l.c:1878 +#: src/input/input_v4l.c:1885 msgid "v4l radio input plugin" msgstr "" -#: src/input/input_v4l.c:1910 +#: src/input/input_v4l.c:1917 msgid "v4l video device" msgstr "" -#: src/input/input_v4l.c:1911 +#: src/input/input_v4l.c:1918 msgid "The path to your Video4Linux video device." msgstr "" -#: src/input/input_v4l.c:1936 +#: src/input/input_v4l.c:1923 +msgid "v4l ALSA audio input device" +msgstr "" + +#: src/input/input_v4l.c:1924 +msgid "" +"The name of the audio device which corresponds to your Video4Linux video " +"device." +msgstr "" + +#: src/input/input_v4l.c:1951 msgid "v4l radio device" msgstr "" -#: src/input/input_v4l.c:1937 +#: src/input/input_v4l.c:1952 msgid "The path to your Video4Linux radio device." msgstr "" -- cgit v1.2.3 From 5dfe5ae0be904d5992c3f535962ed9fac48663e8 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 26 Jan 2008 21:02:02 +0000 Subject: Fix font installation (broken by the xine-config backport). --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 884d64e8e..c9396cf27 100644 --- a/configure.ac +++ b/configure.ac @@ -2398,7 +2398,7 @@ AC_SUBST(xinelibdir) AC_SUBST(xinedatadir) XINE_PLUGINDIR="\${xinelibdir}/plugins/$XINE_MAJOR.$XINE_MINOR.$XINE_SUB$XINE_PATCH" -XINE_FONTDIR="\${xinedatadir}/xine/libxine$XINE_MAJOR/fonts" +XINE_FONTDIR="\${xinedatadir}/libxine$XINE_MAJOR/fonts" XINE_LOCALEDIR='${datadir}/locale' XINE_REL_PLUGINDIR="`makeexpand "$XINE_PLUGINDIR"`" XINE_REL_PLUGINDIR="`makeexpand "$XINE_REL_PLUGINDIR" | sed -e "s,^${prefix}/,,"`" -- cgit v1.2.3 From d59888853ae53ff61a341d19095e866dc79db56d Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 26 Jan 2008 21:02:36 +0000 Subject: 1.1.10 release. --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 80791eb18..9c34b71d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -xine-lib (1.1.10) (unreleased) +xine-lib (1.1.10) 2008-01-26 * Security fixes: - Buffer overflow which allows a remote attacker to execute arbitrary code or crash the client program via a crafted ASF header. -- cgit v1.2.3 From 71827e5c4ab13f43e9eeefbf4f2a933b1c81727a Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 26 Jan 2008 21:22:27 +0000 Subject: Added tag xine-lib-1_1_10-release for changeset 7f1232425c6d --- .hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags b/.hgtags index 8b9b6199b..6e05d9638 100644 --- a/.hgtags +++ b/.hgtags @@ -64,3 +64,4 @@ ab1531337553ad5eac24a69ac665eae33916b423 xine-lib-1_1_7-release e0a332b9d3e8bb3fad4d7feac1e519292b062056 xine-lib-1_1_8-release b6be674453e922114b55d4613cb197c77d19f094 xine-lib-1_1_9-release 9438947f88ad2bed1832385301c6b4e62709625a xine-lib-1_1_9_1-release +7f1232425c6d715c404e6df1292075b33ecb8305 xine-lib-1_1_10-release -- cgit v1.2.3 From 082345c5b57e53633def3900b84d2a99974e8ac1 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 26 Jan 2008 21:22:43 +0000 Subject: Added signature for changeset ae1e23df14223cdacf83df75b28b223895d658c2 --- .hgsigs | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgsigs b/.hgsigs index 528d1e655..367ce4851 100644 --- a/.hgsigs +++ b/.hgsigs @@ -2,3 +2,4 @@ 42358e16442fe54fa554006e0b0bafd51e065c32 0 iD8DBQBG0xz0zbwfTn7RbcARAoD3AJ4012pabmpQvCKKDokZNyZzfPIbWgCfRk5FRly/Eei/xXnSaT54XHAT5KM= 1dbf784bebc791266fcca02e917ee63034ac2e0b 0 iD8DBQBHgQ2mzbwfTn7RbcARArl9AKCslqZDrrm0GiU3IbBvcQVbOdSXlwCgyEMuHY2y/+T6WEeB2CXvCTs5ulI= b591d00fcd386cdd3779378c34b2d42b7504afc4 0 iD8DBQBHh5UfsBKtjPGfWZ8RAgvMAJ9xwnDNifmaobFYe2nR7+rJlLTkEQCgguGMqwqRZY68HWQXhEx918hp4Yg= +ae1e23df14223cdacf83df75b28b223895d658c2 0 iD8DBQBHm6SjsBKtjPGfWZ8RAi8HAKDAHmmLu8rwN5XJJPhfEofE7BTpsgCfTyNzku+v/PhqXgl4kQnRiB6nUSE= -- cgit v1.2.3 From 7e0d060bb11590b2fc4457cfe632fc67eef327c4 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sun, 27 Jan 2008 01:42:25 +0000 Subject: Begin 1.1.11. --- ChangeLog | 2 ++ debian/changelog | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9c34b71d2..98bf6b16e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ +xine-lib (1.1.11) unreleased + xine-lib (1.1.10) 2008-01-26 * Security fixes: - Buffer overflow which allows a remote attacker to execute arbitrary diff --git a/debian/changelog b/debian/changelog index 6c3d1ab7d..ee28516de 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -xine-lib (1.1.10~hg-0) unstable; urgency=low +xine-lib (1.1.10+hg-0) unstable; urgency=low [ Darren Salt ] * Hg snapshot. @@ -7,7 +7,7 @@ xine-lib (1.1.10~hg-0) unstable; urgency=low * remove gs from build-dependencies * change the maintainer field to xine-devel@lists.sourceforge.net. - -- Darren Salt <linux@youmustbejoking.demon.co.uk> Mon, 14 Jan 2008 22:57:42 +0000 + -- Darren Salt <linux@youmustbejoking.demon.co.uk> Sun, 27 Jan 2008 01:41:45 +0000 xine-lib (1.1.5~cvs-0) unstable; urgency=low -- cgit v1.2.3 From 99a04ec01e35ff6e0c84195381ab55f2f8e04b9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 27 Jan 2008 13:10:07 +0100 Subject: Avoid one recursive make by declaring all the installed headers inside include/Makefile.am. --- configure.ac | 1 - include/Makefile.am | 22 ++++++++++++++-------- include/xine/Makefile.am | 11 ----------- src/xine-engine/audio_out.c | 1 + 4 files changed, 15 insertions(+), 20 deletions(-) delete mode 100644 include/xine/Makefile.am diff --git a/configure.ac b/configure.ac index cdb196f79..e347f1947 100644 --- a/configure.ac +++ b/configure.ac @@ -1159,7 +1159,6 @@ contrib/nosefart/Makefile contrib/vidix/Makefile contrib/vidix/drivers/Makefile include/Makefile -include/xine/Makefile include/xine/version.h lib/Makefile m4/Makefile diff --git a/include/Makefile.am b/include/Makefile.am index 1493a33f8..4af4290b3 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,17 +1,23 @@ -SUBDIRS = xine -#EXTRA_DIST = xine.h.in +EXTRA_DIST = xine/version.h.in if GENERATED_INTTYPES_H inttypes_h = inttypes.h endif -include_HEADERS = xine.h +nobase_include_HEADERS = xine.h xine/version.h xine/buffer.h \ + xine/metronom.h xine/configfile.h xine/vo_scale.h \ + xine/audio_out.h xine/resample.h xine/video_out.h \ + xine/xine_internal.h xine/spu_decoder.h xine/video_overlay.h \ + xine/osd.h xine/spu.h xine/scratch.h xine/xine_plugin.h \ + xine/xineintl.h xine/plugin_catalog.h xine/audio_decoder.h \ + xine/video_decoder.h xine/post.h xine/io_helper.h \ + xine/broadcaster.h xine/info_helper.h xine/refcounter.h \ + xine/alphablend.h xine/demux.h xine/input_plugin.h \ + xine/attributes.h xine/compat.h xine/xine_buffer.h \ + xine/xineutils.h xine/xmllexer.h xine/xmlparser.h xine/list.h \ + xine/array.h xine/sorted_array.h xine/pool.h \ + xine/ring_buffer.h xine/os_types.h xine/vdr.h $(inttypes_h) noinst_HEADERS = config.h configure.h CONFIG_CLEAN_FILES = $(inttypes_h) - -install-data-local: install-includeHEADERS -if GENERATED_INTTYPES_H - $(INSTALL) inttypes.h $(DESTDIR)$(includedir) -endif diff --git a/include/xine/Makefile.am b/include/xine/Makefile.am deleted file mode 100644 index 14eb98445..000000000 --- a/include/xine/Makefile.am +++ /dev/null @@ -1,11 +0,0 @@ -EXTRA_DIST = version.h.in - -xineincludedir = $(includedir)/xine -xineinclude_HEADERS = version.h buffer.h metronom.h configfile.h vo_scale.h \ - audio_out.h resample.h video_out.h xine_internal.h spu_decoder.h \ - video_overlay.h osd.h spu.h scratch.h xine_plugin.h xineintl.h \ - plugin_catalog.h audio_decoder.h video_decoder.h post.h \ - io_helper.h broadcaster.h info_helper.h refcounter.h alphablend.h \ - demux.h input_plugin.h attributes.h compat.h xine_buffer.h \ - xineutils.h xmllexer.h xmlparser.h list.h array.h sorted_array.h \ - pool.h ring_buffer.h os_types.h vdr.h base64.h diff --git a/src/xine-engine/audio_out.c b/src/xine-engine/audio_out.c index 855051582..34f982d18 100644 --- a/src/xine-engine/audio_out.c +++ b/src/xine-engine/audio_out.c @@ -1626,6 +1626,7 @@ static void ao_close(xine_audio_port_t *this_gen, xine_stream_t *stream) { } else fifo_wait_empty(this->out_fifo); + ao_set_property(this_gen, AO_PROP_DISCARD_BUFFERS, 0); } pthread_mutex_lock( &this->driver_lock ); -- cgit v1.2.3 From d3801a2f741ac6931824bfef41ea0e7c39aa193d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 27 Jan 2008 13:52:33 +0100 Subject: Move base64 header to xine-utils as we don't want it installed. --HG-- rename : include/xine/base64.h => src/xine-utils/base64.h --- include/xine/base64.h | 94 -------------------------------------------- include/xine/xineutils.h | 1 - src/input/input_cdda.c | 1 + src/xine-engine/configfile.c | 1 + src/xine-utils/Makefile.am | 1 + src/xine-utils/base64.c | 2 +- src/xine-utils/base64.h | 94 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 98 insertions(+), 96 deletions(-) delete mode 100644 include/xine/base64.h create mode 100644 src/xine-utils/base64.h diff --git a/include/xine/base64.h b/include/xine/base64.h deleted file mode 100644 index 61d362150..000000000 --- a/include/xine/base64.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2000 Robert Kaye - * - * This file is part of xine, a free video player. - * - * xine is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * xine 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - * - * Base64 encoding modified for Musicbrainz - * relicensed under the GNU General Public License for use in xine-lib - */ -/* -------------------------------------------------------------------------- - - MusicBrainz -- The Internet music metadatabase - - Copyright (C) 2000 Robert Kaye - - This library 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. - - This library 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 this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA - -----------------------------------------------------------------------------*/ -/* - * Program: RFC-822 routines (originally from SMTP) - * - * Author: Mark Crispin - * Networks and Distributed Computing - * Computing & Communications - * University of Washington - * Administration Building, AG-44 - * Seattle, WA 98195 - * Internet: MRC@CAC.Washington.EDU - * - * Date: 27 July 1988 - * Last Edited: 10 September 1998 - * - * Sponsorship: The original version of this work was developed in the - * Symbolic Systems Resources Group of the Knowledge Systems - * Laboratory at Stanford University in 1987-88, and was funded - * by the Biomedical Research Technology Program of the National - * Institutes of Health under grant number RR-00785. - * - * Original version Copyright 1988 by The Leland Stanford Junior University - * Copyright 1998 by the University of Washington - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, provided - * that the above copyright notices appear in all copies and that both the - * above copyright notices and this permission notice appear in supporting - * documentation, and that the name of the University of Washington or The - * Leland Stanford Junior University not be used in advertising or publicity - * pertaining to distribution of the software without specific, written prior - * permission. This software is made available "as is", and - * THE UNIVERSITY OF WASHINGTON AND THE LELAND STANFORD JUNIOR UNIVERSITY - * DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO THIS SOFTWARE, - * INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF - * WASHINGTON OR THE LELAND STANFORD JUNIOR UNIVERSITY BE LIABLE FOR ANY - * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef BASE64_H -#define BASE64_H - -unsigned char *xine_rfc822_binary (void *src,unsigned long srcl,unsigned long *len) XINE_PROTECTED; - -char *xine_base64_encode (const void *src, unsigned long srcl, unsigned long *len) XINE_PROTECTED; -void *xine_base64_decode (const char *src, unsigned long srcl, unsigned long *len) XINE_PROTECTED; - -#endif diff --git a/include/xine/xineutils.h b/include/xine/xineutils.h index 9fb1ad538..5f052ee58 100644 --- a/include/xine/xineutils.h +++ b/include/xine/xineutils.h @@ -47,7 +47,6 @@ extern "C" { #include <xine/list.h> #include <xine/array.h> #include <xine/sorted_array.h> -#include <xine/base64.h> #include <stdio.h> #include <string.h> diff --git a/src/input/input_cdda.c b/src/input/input_cdda.c index 0e378c299..e2c32d509 100644 --- a/src/input/input_cdda.c +++ b/src/input/input_cdda.c @@ -69,6 +69,7 @@ #include <xine/xineutils.h> #include <xine/input_plugin.h> #include "media_helper.h" +#include "base64.h" #if defined(__sun) #define DEFAULT_CDDA_DEVICE "/vol/dev/aliases/cdrom0" diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index 550c0372f..8ac0e7eb3 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -33,6 +33,7 @@ #include <unistd.h> #include <xine/configfile.h> #include "bswap.h" +#include "base64.h" #define LOG_MODULE "configfile" #define LOG_VERBOSE diff --git a/src/xine-utils/Makefile.am b/src/xine-utils/Makefile.am index d3b4c2b1c..6509f1178 100644 --- a/src/xine-utils/Makefile.am +++ b/src/xine-utils/Makefile.am @@ -16,6 +16,7 @@ endif endif libxineutils_la_SOURCES = $(pppc_files) \ + base64.h \ base64.c \ cpu_accel.c \ color.c \ diff --git a/src/xine-utils/base64.c b/src/xine-utils/base64.c index 102f15256..583723cdc 100644 --- a/src/xine-utils/base64.c +++ b/src/xine-utils/base64.c @@ -92,7 +92,7 @@ #include <time.h> #include <stdlib.h> -#include <xine/base64.h> +#include "base64.h" /* NOTE: This is not true RFC822 anymore. The use of the characters diff --git a/src/xine-utils/base64.h b/src/xine-utils/base64.h new file mode 100644 index 000000000..61d362150 --- /dev/null +++ b/src/xine-utils/base64.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2000 Robert Kaye + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + * + * Base64 encoding modified for Musicbrainz + * relicensed under the GNU General Public License for use in xine-lib + */ +/* -------------------------------------------------------------------------- + + MusicBrainz -- The Internet music metadatabase + + Copyright (C) 2000 Robert Kaye + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + +----------------------------------------------------------------------------*/ +/* + * Program: RFC-822 routines (originally from SMTP) + * + * Author: Mark Crispin + * Networks and Distributed Computing + * Computing & Communications + * University of Washington + * Administration Building, AG-44 + * Seattle, WA 98195 + * Internet: MRC@CAC.Washington.EDU + * + * Date: 27 July 1988 + * Last Edited: 10 September 1998 + * + * Sponsorship: The original version of this work was developed in the + * Symbolic Systems Resources Group of the Knowledge Systems + * Laboratory at Stanford University in 1987-88, and was funded + * by the Biomedical Research Technology Program of the National + * Institutes of Health under grant number RR-00785. + * + * Original version Copyright 1988 by The Leland Stanford Junior University + * Copyright 1998 by the University of Washington + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notices appear in all copies and that both the + * above copyright notices and this permission notice appear in supporting + * documentation, and that the name of the University of Washington or The + * Leland Stanford Junior University not be used in advertising or publicity + * pertaining to distribution of the software without specific, written prior + * permission. This software is made available "as is", and + * THE UNIVERSITY OF WASHINGTON AND THE LELAND STANFORD JUNIOR UNIVERSITY + * DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO THIS SOFTWARE, + * INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF + * WASHINGTON OR THE LELAND STANFORD JUNIOR UNIVERSITY BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef BASE64_H +#define BASE64_H + +unsigned char *xine_rfc822_binary (void *src,unsigned long srcl,unsigned long *len) XINE_PROTECTED; + +char *xine_base64_encode (const void *src, unsigned long srcl, unsigned long *len) XINE_PROTECTED; +void *xine_base64_decode (const char *src, unsigned long srcl, unsigned long *len) XINE_PROTECTED; + +#endif -- cgit v1.2.3 From 7d921ef9f7ff264d0165fd531e166a24e890b645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 27 Jan 2008 13:52:56 +0100 Subject: Don't distribute the generated inttypes.h file. --- include/Makefile.am | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/Makefile.am b/include/Makefile.am index 4af4290b3..3e6aae174 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -16,8 +16,10 @@ nobase_include_HEADERS = xine.h xine/version.h xine/buffer.h \ xine/attributes.h xine/compat.h xine/xine_buffer.h \ xine/xineutils.h xine/xmllexer.h xine/xmlparser.h xine/list.h \ xine/array.h xine/sorted_array.h xine/pool.h \ - xine/ring_buffer.h xine/os_types.h xine/vdr.h $(inttypes_h) + xine/ring_buffer.h xine/os_types.h xine/vdr.h noinst_HEADERS = config.h configure.h +nodist_include_HEADERS = $(inttypes_h) + CONFIG_CLEAN_FILES = $(inttypes_h) -- cgit v1.2.3 From 18e80d661a68fe45fe808ec79ea039d14291f892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 27 Jan 2008 13:54:38 +0100 Subject: Use EXTRA_PROGRAMS for xine-fontconv and cdda_server rahter than using manual rules. --- misc/Makefile.am | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/misc/Makefile.am b/misc/Makefile.am index 70cbe59ee..7e82bec87 100644 --- a/misc/Makefile.am +++ b/misc/Makefile.am @@ -3,12 +3,10 @@ include $(top_srcdir)/misc/Makefile.common SUBDIRS = fonts EXTRA_DIST = build_rpms.sh \ - cdda_server.c \ SlackBuild.in \ SlackBuild \ vga.xinefont.gz \ xine-config \ - xine-fontconv.c \ xine-lib.spec.in \ xine-lib.spec \ libxine.pc.in \ @@ -20,8 +18,13 @@ bin_SCRIPTS = xine-config pkgconfigdir=$(libdir)/pkgconfig pkgconfig_DATA=libxine.pc -xine-fontconv: xine-fontconv.c - $(CC) -W -Wall -g -o xine-fontconv xine-fontconv.c -lz `freetype-config --cflags` `freetype-config --libs` +EXTRA_PROGRAMS = xine-fontconv cdda_server -cdda_server: cdda_server.c - $(CC) -W -Wall -g -o cdda_server cdda_server.c -ldl +xine_fontconv_SOURCES = xine-fontconv.c +xine_fontconv_CFLAGS = $(FT2_CFLAGS) +xine_fontconv_LDFLAGS = $(GCSECTIONS) +xine_fontconv_LDADD = -lz $(FT2_LIBS) + +cdda_server_SOURCES = cdda_server.c +cdda_server_LDFLAGS = $(GCSECTIONS) +cdda_server_LDADD = $(DYNAMIC_LD_LIBS) -- cgit v1.2.3 From 7c166d8088e0a128a7b223c62fd2b8dc1a1b70c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 27 Jan 2008 13:58:31 +0100 Subject: Rename base64 functions to _x_ as they should not be part of the public API. Note that these will be removed as soon as -libavutil branch is merged, in favour of libavutil's base64 implementation. --- src/input/input_cdda.c | 2 +- src/xine-engine/configfile.c | 4 ++-- src/xine-utils/base64.c | 6 +++--- src/xine-utils/base64.h | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/input/input_cdda.c b/src/input/input_cdda.c index e2c32d509..64495c433 100644 --- a/src/input/input_cdda.c +++ b/src/input/input_cdda.c @@ -1936,7 +1936,7 @@ static void _cdda_cdindex(cdda_input_plugin_t *this, cdrom_toc *toc) { sha_final(digest, &sha); - base64 = xine_rfc822_binary(digest, 20, &size); + base64 = _x_rfc822_binary(digest, 20, &size); base64[size] = 0; _x_meta_info_set_utf8(this->stream, XINE_META_INFO_CDINDEX_DISCID, base64); diff --git a/src/xine-engine/configfile.c b/src/xine-engine/configfile.c index 8ac0e7eb3..37a4e38ad 100644 --- a/src/xine-engine/configfile.c +++ b/src/xine-engine/configfile.c @@ -1342,7 +1342,7 @@ static char* config_get_serialized_entry (config_values_t *this, const char *key } /* and now the output encoding */ - output = xine_base64_encode (buffer, total_len, &output_len); + output = _x_base64_encode (buffer, total_len, &output_len); free(buffer); } @@ -1414,7 +1414,7 @@ static char* config_register_serialized_entry (config_values_t *this, const char int value_count = 0; int i; - output = xine_base64_decode (value, strlen(value), &output_len); + output = _x_base64_decode (value, strlen(value), &output_len); pos = 0; pos += bytes = get_int(output, output_len, pos, &type); diff --git a/src/xine-utils/base64.c b/src/xine-utils/base64.c index 583723cdc..5730f30db 100644 --- a/src/xine-utils/base64.c +++ b/src/xine-utils/base64.c @@ -107,7 +107,7 @@ * Returns: destination as BASE64 */ -unsigned char *xine_rfc822_binary (void *src,unsigned long srcl,unsigned long *len) +unsigned char *_x_rfc822_binary (void *src,unsigned long srcl,unsigned long *len) { unsigned char *ret,*d; unsigned char *s = (unsigned char *) src; @@ -134,7 +134,7 @@ unsigned char *xine_rfc822_binary (void *src,unsigned long srcl,unsigned long *l return ret; /* return the resulting string */ } -char *xine_base64_encode (const void *src, unsigned long srcl, unsigned long *len) +char *_x_base64_encode (const void *src, unsigned long srcl, unsigned long *len) { char *ret, *d; unsigned char *s = (unsigned char *) src; @@ -157,7 +157,7 @@ char *xine_base64_encode (const void *src, unsigned long srcl, unsigned long *le return ret; /* return the resulting string */ } -void *xine_base64_decode (const char *src, unsigned long srcl, unsigned long *len) +void *_x_base64_decode (const char *src, unsigned long srcl, unsigned long *len) { void *ret; unsigned char *d; diff --git a/src/xine-utils/base64.h b/src/xine-utils/base64.h index 61d362150..f22f9b0c4 100644 --- a/src/xine-utils/base64.h +++ b/src/xine-utils/base64.h @@ -86,9 +86,9 @@ #ifndef BASE64_H #define BASE64_H -unsigned char *xine_rfc822_binary (void *src,unsigned long srcl,unsigned long *len) XINE_PROTECTED; +unsigned char *_x_rfc822_binary (void *src,unsigned long srcl,unsigned long *len) XINE_PROTECTED; -char *xine_base64_encode (const void *src, unsigned long srcl, unsigned long *len) XINE_PROTECTED; -void *xine_base64_decode (const char *src, unsigned long srcl, unsigned long *len) XINE_PROTECTED; +char *_x_base64_encode (const void *src, unsigned long srcl, unsigned long *len) XINE_PROTECTED; +void *_x_base64_decode (const char *src, unsigned long srcl, unsigned long *len) XINE_PROTECTED; #endif -- cgit v1.2.3 From 589b2c369d4810bd092c42125f134f86cff70d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 27 Jan 2008 13:59:57 +0100 Subject: Ignore xine-fontconv and cdda_server programs. --- .hgignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.hgignore b/.hgignore index 973e0a305..d4ec3bb85 100644 --- a/.hgignore +++ b/.hgignore @@ -74,6 +74,8 @@ misc/libxine.pc misc/relchk.sh misc/xine-config misc/xine-lib.spec +misc/xine-fontconv +misc/cdda_server po/POTFILES po/*.gmo -- cgit v1.2.3 From 0e00857dfb065dc9c9c443159cb453af151e4d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 27 Jan 2008 14:01:00 +0100 Subject: Use dist_bin for xine-config and remove it from EXTRA_DIST. --- misc/Makefile.am | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/misc/Makefile.am b/misc/Makefile.am index 7e82bec87..835f92f54 100644 --- a/misc/Makefile.am +++ b/misc/Makefile.am @@ -6,14 +6,13 @@ EXTRA_DIST = build_rpms.sh \ SlackBuild.in \ SlackBuild \ vga.xinefont.gz \ - xine-config \ xine-lib.spec.in \ xine-lib.spec \ libxine.pc.in \ libdvdcss-1.2.6-network.patch \ Makefile.common -bin_SCRIPTS = xine-config +dist_bin_SCRIPTS = xine-config pkgconfigdir=$(libdir)/pkgconfig pkgconfig_DATA=libxine.pc -- cgit v1.2.3 From 8734346142f2e1bb36b28c59d380aa20c2fe29dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 27 Jan 2008 14:09:09 +0100 Subject: Remove one more recursive make: move fonts declaration and installation inside misc/Makefile.am. --- configure.ac | 1 - misc/Makefile.am | 46 +++++++++++++++++++++++++++++++++++++++++++--- misc/fonts/Makefile.am | 47 ----------------------------------------------- 3 files changed, 43 insertions(+), 51 deletions(-) delete mode 100644 misc/fonts/Makefile.am diff --git a/configure.ac b/configure.ac index e347f1947..aa9294780 100644 --- a/configure.ac +++ b/configure.ac @@ -1166,7 +1166,6 @@ m4/gettext/Makefile misc/Makefile misc/SlackBuild misc/build_rpms.sh -misc/fonts/Makefile misc/libxine.pc misc/relchk.sh misc/xine-lib.spec diff --git a/misc/Makefile.am b/misc/Makefile.am index 835f92f54..10364eb18 100644 --- a/misc/Makefile.am +++ b/misc/Makefile.am @@ -1,7 +1,5 @@ include $(top_srcdir)/misc/Makefile.common -SUBDIRS = fonts - EXTRA_DIST = build_rpms.sh \ SlackBuild.in \ SlackBuild \ @@ -10,13 +8,55 @@ EXTRA_DIST = build_rpms.sh \ xine-lib.spec \ libxine.pc.in \ libdvdcss-1.2.6-network.patch \ - Makefile.common + Makefile.common \ + fonts/cetus.ttf dist_bin_SCRIPTS = xine-config pkgconfigdir=$(libdir)/pkgconfig pkgconfig_DATA=libxine.pc +fontdir = $(pkgdatadir)/fonts +dist_font_DATA = \ + fonts/cetus-16.xinefont.gz \ + fonts/cetus-20.xinefont.gz \ + fonts/cetus-24.xinefont.gz \ + fonts/cetus-32.xinefont.gz \ + fonts/cetus-48.xinefont.gz \ + fonts/cetus-64.xinefont.gz \ + fonts/cc-16.xinefont.gz \ + fonts/cc-20.xinefont.gz \ + fonts/cc-24.xinefont.gz \ + fonts/cc-32.xinefont.gz \ + fonts/cc-48.xinefont.gz \ + fonts/cc-64.xinefont.gz \ + fonts/cci-16.xinefont.gz \ + fonts/cci-20.xinefont.gz \ + fonts/cci-24.xinefont.gz \ + fonts/cci-32.xinefont.gz \ + fonts/cci-48.xinefont.gz \ + fonts/cci-64.xinefont.gz \ + fonts/mono-16.xinefont.gz \ + fonts/mono-20.xinefont.gz \ + fonts/mono-24.xinefont.gz \ + fonts/mono-32.xinefont.gz \ + fonts/mono-48.xinefont.gz \ + fonts/mono-64.xinefont.gz \ + fonts/sans-16.xinefont.gz \ + fonts/sans-20.xinefont.gz \ + fonts/sans-24.xinefont.gz \ + fonts/sans-32.xinefont.gz \ + fonts/sans-48.xinefont.gz \ + fonts/sans-64.xinefont.gz \ + fonts/serif-16.xinefont.gz \ + fonts/serif-20.xinefont.gz \ + fonts/serif-24.xinefont.gz \ + fonts/serif-32.xinefont.gz \ + fonts/serif-48.xinefont.gz \ + fonts/serif-64.xinefont.gz + +dist_doc_DATA = fonts/README.cetus + EXTRA_PROGRAMS = xine-fontconv cdda_server xine_fontconv_SOURCES = xine-fontconv.c diff --git a/misc/fonts/Makefile.am b/misc/fonts/Makefile.am deleted file mode 100644 index 32664da5c..000000000 --- a/misc/fonts/Makefile.am +++ /dev/null @@ -1,47 +0,0 @@ -include $(top_srcdir)/misc/Makefile.common - -fontdir = $(pkgdatadir)/fonts -font_DATA = \ - cetus-16.xinefont.gz \ - cetus-20.xinefont.gz \ - cetus-24.xinefont.gz \ - cetus-32.xinefont.gz \ - cetus-48.xinefont.gz \ - cetus-64.xinefont.gz \ - cc-16.xinefont.gz \ - cc-20.xinefont.gz \ - cc-24.xinefont.gz \ - cc-32.xinefont.gz \ - cc-48.xinefont.gz \ - cc-64.xinefont.gz \ - cci-16.xinefont.gz \ - cci-20.xinefont.gz \ - cci-24.xinefont.gz \ - cci-32.xinefont.gz \ - cci-48.xinefont.gz \ - cci-64.xinefont.gz \ - mono-16.xinefont.gz \ - mono-20.xinefont.gz \ - mono-24.xinefont.gz \ - mono-32.xinefont.gz \ - mono-48.xinefont.gz \ - mono-64.xinefont.gz \ - sans-16.xinefont.gz \ - sans-20.xinefont.gz \ - sans-24.xinefont.gz \ - sans-32.xinefont.gz \ - sans-48.xinefont.gz \ - sans-64.xinefont.gz \ - serif-16.xinefont.gz \ - serif-20.xinefont.gz \ - serif-24.xinefont.gz \ - serif-32.xinefont.gz \ - serif-48.xinefont.gz \ - serif-64.xinefont.gz - -doc_DATA = README.cetus - -# -# font used for osd -# -EXTRA_DIST = cetus.ttf $(doc_DATA) $(font_DATA) -- cgit v1.2.3 From b5f4ef58160be1126dd5226f89fd704b24006760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 27 Jan 2008 16:07:42 +0100 Subject: Remove another recursive make invocation, build the vcd plugin inside src/input even if the source files are in src/input/vcd. --- configure.ac | 1 - src/input/Makefile.am | 17 ++++++++++++----- src/input/vcd/Makefile.am | 13 ------------- 3 files changed, 12 insertions(+), 19 deletions(-) delete mode 100644 src/input/vcd/Makefile.am diff --git a/configure.ac b/configure.ac index aa9294780..77190b58a 100644 --- a/configure.ac +++ b/configure.ac @@ -1181,7 +1181,6 @@ src/input/Makefile src/input/libdvdnav/Makefile src/input/librtsp/Makefile src/input/libreal/Makefile -src/input/vcd/Makefile src/libw32dll/Makefile src/libw32dll/wine/Makefile src/libw32dll/DirectShow/Makefile diff --git a/src/input/Makefile.am b/src/input/Makefile.am index ca7e6dabd..64ba0ce54 100644 --- a/src/input/Makefile.am +++ b/src/input/Makefile.am @@ -11,9 +11,6 @@ AM_LDFLAGS = $(xineplug_ldflags) # SUBDIRS = libreal librtsp -if ENABLE_VCD -SUBDIRS += vcd -endif if !WITH_EXTERNAL_DVDNAV SUBDIRS += libdvdnav endif @@ -21,13 +18,16 @@ endif noinst_HEADERS = net_buf_ctrl.h mms.h mmsh.h pnm.h media_helper.h http_helper.h - if ENABLE_DVB in_dvb = xineplug_inp_dvb.la endif +if ENABLE_VCD +in_vcd = xineplug_inp_vcd.la +endif + if ENABLE_VCDO -in_vcd = xineplug_inp_vcdo.la +in_vcdo = xineplug_inp_vcdo.la endif if ENABLE_V4L @@ -62,6 +62,7 @@ xineplug_LTLIBRARIES = \ xineplug_inp_http.la \ xineplug_inp_dvd.la \ $(in_vcd) \ + $(in_vcdo) \ $(in_v4l) \ $(in_gnome_vfs) \ $(in_smb) \ @@ -92,6 +93,12 @@ xineplug_inp_mms_la_LIBADD = $(XINE_LIB) $(LTLIBICONV) $(PTHREAD_LIBS) $(LTLIBIN xineplug_inp_vcdo_la_SOURCES = input_vcd.c media_helper.c xineplug_inp_vcdo_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) +xineplug_inp_vcd_la_SOURCES = vcd/xineplug_inp_vcd.c vcd/vcdplayer.c \ + vcd/vcdio.c vcd/xine-extra.c vcd/vcdio.h \ + vcd/vcdplayer.h vcd/xine-extra.h +xineplug_inp_vcd_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) $(LIBCDIO_LIBS) $(LIBVCD_LIBS) $(LIBVCDINFO_LIBS) $(LIBISO9660_LIBS) -lm +xineplug_inp_vcd_la_CFLAGS = $(AM_CFLAGS) $(LIBCDIO_CFLAGS) $(LIBVCD_CFLAGS) + xineplug_inp_stdin_fifo_la_SOURCES = input_stdin_fifo.c net_buf_ctrl.c xineplug_inp_stdin_fifo_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) diff --git a/src/input/vcd/Makefile.am b/src/input/vcd/Makefile.am deleted file mode 100644 index 2b47415fd..000000000 --- a/src/input/vcd/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -include $(top_srcdir)/misc/Makefile.common - -AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) -AM_LDFLAGS = $(xineplug_ldflags) - -noinst_HEADERS = vcdio.h vcdplayer.h xine-extra.h - -xineplug_LTLIBRARIES = xineplug_inp_vcd.la - -xineplug_inp_vcd_la_SOURCES = xineplug_inp_vcd.c vcdplayer.c vcdio.c xine-extra.c -xineplug_inp_vcd_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) $(LIBCDIO_LIBS) $(LIBVCD_LIBS) $(LIBVCDINFO_LIBS) $(LIBISO9660_LIBS) -lm -xineplug_inp_vcd_la_DEPENDENCIES = $(LIBCDIO_DEPS) $(LIBVCD_DEPS) $(LIBVCDINFO_DEPS) $(LIBISO9660_DEPS) -xineplug_inp_vcd_la_CFLAGS = $(AM_CFLAGS) $(LIBCDIO_CFLAGS) $(LIBVCD_CFLAGS) -- cgit v1.2.3 From 9c881836d4dead995213b4863e055d32e7372a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 27 Jan 2008 16:17:47 +0100 Subject: Compile librtsp and libreal source files directly into the rtsp plugin. Avoid two recursive make calls. --- configure.ac | 2 -- src/input/Makefile.am | 14 ++++++++++---- src/input/libreal/Makefile.am | 10 ---------- src/input/librtsp/Makefile.am | 10 ---------- 4 files changed, 10 insertions(+), 26 deletions(-) delete mode 100644 src/input/libreal/Makefile.am delete mode 100644 src/input/librtsp/Makefile.am diff --git a/configure.ac b/configure.ac index 77190b58a..8c6a8cffe 100644 --- a/configure.ac +++ b/configure.ac @@ -1179,8 +1179,6 @@ src/demuxers/Makefile src/dxr3/Makefile src/input/Makefile src/input/libdvdnav/Makefile -src/input/librtsp/Makefile -src/input/libreal/Makefile src/libw32dll/Makefile src/libw32dll/wine/Makefile src/libw32dll/DirectShow/Makefile diff --git a/src/input/Makefile.am b/src/input/Makefile.am index 64ba0ce54..74aca7240 100644 --- a/src/input/Makefile.am +++ b/src/input/Makefile.am @@ -10,9 +10,8 @@ AM_LDFLAGS = $(xineplug_ldflags) # All of xine input plugins should be named like the scheme "xineplug_inp_" # -SUBDIRS = libreal librtsp if !WITH_EXTERNAL_DVDNAV -SUBDIRS += libdvdnav +SUBDIRS = libdvdnav endif @@ -116,8 +115,15 @@ xineplug_inp_dvb_la_DEPS = $(XDG_BASEDIR_DEPS) xineplug_inp_dvb_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) $(XDG_BASEDIR_LIBS) xineplug_inp_dvb_la_CPPFLAGS = $(AM_CPPFLAGS) $(XDG_BASEDIR_CPPFLAGS) -xineplug_inp_rtsp_la_SOURCES = input_rtsp.c net_buf_ctrl.c -xineplug_inp_rtsp_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) libreal/libreal.la librtsp/librtsp.la +xineplug_inp_rtsp_la_SOURCES = input_rtsp.c net_buf_ctrl.c \ + librtsp/rtsp.c librtsp/rtsp_session.c \ + librtsp/rtsp.h librtsp/rtsp_session.h \ + libreal/real.c libreal/asmrp.c \ + libreal/rmff.c libreal/sdpplin.c \ + libreal/real.h libreal/asmrp.h \ + libreal/rmff.h libreal/sdpplin.h +xineplug_inp_rtsp_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/libreal -I$(srcdir)/librtsp +xineplug_inp_rtsp_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) xineplug_inp_cdda_la_SOURCES = input_cdda.c media_helper.c sha1.c sha1.h xineplug_inp_cdda_la_DEPS = $(XDG_BASEDIR_DEPS) diff --git a/src/input/libreal/Makefile.am b/src/input/libreal/Makefile.am deleted file mode 100644 index bd97a7548..000000000 --- a/src/input/libreal/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -include $(top_srcdir)/misc/Makefile.common - -AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) -AM_CPPFLAGS = -I$(top_srcdir)/src/input/librtsp - -noinst_HEADERS = real.h asmrp.h rmff.h sdpplin.h - -noinst_LTLIBRARIES = libreal.la - -libreal_la_SOURCES = real.c asmrp.c rmff.c sdpplin.c diff --git a/src/input/librtsp/Makefile.am b/src/input/librtsp/Makefile.am deleted file mode 100644 index 68d554c2c..000000000 --- a/src/input/librtsp/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -include $(top_srcdir)/misc/Makefile.common - -AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) -AM_CPPFLAGS = -I$(top_srcdir)/src/input/libreal - -noinst_HEADERS = rtsp.h rtsp_session.h - -noinst_LTLIBRARIES = librtsp.la - -librtsp_la_SOURCES = rtsp.c rtsp_session.c -- cgit v1.2.3 From d2ddb26cccd02063d2904a303194cb6009649d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 27 Jan 2008 16:21:09 +0100 Subject: Use AM_PROG_CC_C_O as needed by the xine-fontconv program. --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index 8c6a8cffe..b40f7ae75 100644 --- a/configure.ac +++ b/configure.ac @@ -156,6 +156,7 @@ dnl checks for programs dnl ------------------- AC_PROG_CC +AM_PROG_CC_C_O AC_GNU_SOURCE AC_ISC_POSIX -- cgit v1.2.3 From 873a841ce7df818c82991dfa2eeafa019043fae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 27 Jan 2008 16:32:37 +0100 Subject: Move macosx video output library building inside src/video_out, avoid one recursive make call. --- configure.ac | 1 - src/video_out/Makefile.am | 8 +++++++- src/video_out/macosx/Makefile.am | 12 ------------ 3 files changed, 7 insertions(+), 14 deletions(-) delete mode 100644 src/video_out/macosx/Makefile.am diff --git a/configure.ac b/configure.ac index b40f7ae75..ef55a27ee 100644 --- a/configure.ac +++ b/configure.ac @@ -1199,7 +1199,6 @@ src/spu_dec/Makefile src/video_dec/Makefile src/video_dec/libmpeg2/Makefile src/video_out/Makefile -src/video_out/macosx/Makefile src/xine-utils/Makefile src/xine-engine/Makefile src/vdr/Makefile diff --git a/src/video_out/Makefile.am b/src/video_out/Makefile.am index 3b5703792..b661fdd4b 100644 --- a/src/video_out/Makefile.am +++ b/src/video_out/Makefile.am @@ -7,7 +7,8 @@ AM_OBJCFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) SUBDIRS = if ENABLE_MACOSX_VIDEO -SUBDIRS += macosx +xineinclude_HEADERS = macosx/video_window.h macosx/XineOpenGLView.h macosx/XineVideoWindow.h +lib_LTLIBRARIES = libxineMacOSXVideo.la endif EXTRA_DIST = video_out_directx.c video_out_macosx.m @@ -194,3 +195,8 @@ xineplug_vo_out_none_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) xineplug_vo_out_macosx_la_SOURCES = video_out_macosx.m xineplug_vo_out_macosx_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) xineplug_vo_out_macosx_la_LDFLAGS = $(AM_LDFLAGS) -framework Cocoa -framework OpenGL + +libxineMacOSXVideo_la_SOURCES = macosx/XineOpenGLView.m macosx/XineVideoWindow.m +libxineMacOSXVideo_la_LDFLAGS = $(AM_LDFLAGS) -framework Cocoa \ + -framework OpenGL -version-info \ + $(XINE_LT_CURRENT):$(XINE_LT_REVISION):$(XINE_LT_AGE) diff --git a/src/video_out/macosx/Makefile.am b/src/video_out/macosx/Makefile.am deleted file mode 100644 index ae6a5acc8..000000000 --- a/src/video_out/macosx/Makefile.am +++ /dev/null @@ -1,12 +0,0 @@ -include $(top_srcdir)/misc/Makefile.common - -AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) -AM_OBJCFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) - -xineinclude_HEADERS = video_window.h XineOpenGLView.h XineVideoWindow.h - -lib_LTLIBRARIES = libxineMacOSXVideo.la - -libxineMacOSXVideo_la_SOURCES = XineOpenGLView.m XineVideoWindow.m -libxineMacOSXVideo_la_LDFLAGS = $(AM_LDFLAGS) -framework Cocoa -framework OpenGL \ - -version-info $(XINE_LT_CURRENT):$(XINE_LT_REVISION):$(XINE_LT_AGE) -- cgit v1.2.3 From 435a5d525c9aa9e4a4b174949b2d67d57110aa9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 27 Jan 2008 16:40:07 +0100 Subject: Move libmpeg2-based decoder building in video_dec. Avoid one recursive make call. --- configure.ac | 1 - src/video_dec/Makefile.am | 20 +++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index ef55a27ee..743eb9468 100644 --- a/configure.ac +++ b/configure.ac @@ -1197,7 +1197,6 @@ src/post/deinterlace/Makefile src/post/deinterlace/plugins/Makefile src/spu_dec/Makefile src/video_dec/Makefile -src/video_dec/libmpeg2/Makefile src/video_out/Makefile src/xine-utils/Makefile src/xine-engine/Makefile diff --git a/src/video_dec/Makefile.am b/src/video_dec/Makefile.am index 91246eb4d..1b0fec998 100644 --- a/src/video_dec/Makefile.am +++ b/src/video_dec/Makefile.am @@ -1,5 +1,3 @@ -SUBDIRS = libmpeg2 - include $(top_srcdir)/misc/Makefile.common AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) @@ -20,7 +18,8 @@ xineplug_LTLIBRARIES = $(image_module) \ $(theora_module) \ xineplug_decode_bitplane.la \ xineplug_decode_rgb.la \ - xineplug_decode_yuv.la + xineplug_decode_yuv.la \ + xineplug_decode_mpeg2.la xineplug_decode_bitplane_la_SOURCES = bitplane.c xineplug_decode_bitplane_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) @@ -38,3 +37,18 @@ xineplug_decode_image_la_CFLAGS = $(AM_CFLAGS) $(WAND_CFLAGS) xineplug_decode_gdk_pixbuf_la_SOURCES = gdkpixbuf.c xineplug_decode_gdk_pixbuf_la_LIBADD = $(XINE_LIB) $(DYNAMIC_LD_LIBS) $(GDK_PIXBUF_LIBS) xineplug_decode_gdk_pixbuf_la_CFLAGS = $(AM_CFLAGS) $(GDK_PIXBUF_CFLAGS) + +xineplug_decode_mpeg2_la_SOURCES = libmpeg2/cpu_state.c \ + libmpeg2/decode.c libmpeg2/header.c libmpeg2/idct.c \ + libmpeg2/idct_altivec.c libmpeg2/idct_mlib.c \ + libmpeg2/idct_mmx.c libmpeg2/motion_comp.c \ + libmpeg2/motion_comp_altivec.c libmpeg2/motion_comp_mmx.c \ + libmpeg2/motion_comp_mlib.c libmpeg2/motion_comp_vis.c \ + libmpeg2/slice.c libmpeg2/slice_xvmc.c \ + libmpeg2/slice_xvmc_vld.c libmpeg2/stats.c \ + libmpeg2/xine_mpeg2_decoder.c libmpeg2/libmpeg2_accel.c \ + libmpeg2/vlc.h libmpeg2/mpeg2.h libmpeg2/xvmc.h \ + libmpeg2/xvmc_vld.h libmpeg2/mpeg2_internal.h \ + libmpeg2/idct_mlib.h libmpeg2/vis.h libmpeg2/libmpeg2_accel.h +xineplug_decode_mpeg2_la_LIBADD = $(XINE_LIB) $(MLIB_LIBS) -lm +xineplug_decode_mpeg2_la_CFLAGS = $(AM_CFLAGS) $(MLIB_CFLAGS) -- cgit v1.2.3 From fdd31b7b130a36dbd1d59b075667626e592cac70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 27 Jan 2008 16:42:52 +0100 Subject: Remove makefile I should have removed before. --- src/video_dec/libmpeg2/Makefile.am | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 src/video_dec/libmpeg2/Makefile.am diff --git a/src/video_dec/libmpeg2/Makefile.am b/src/video_dec/libmpeg2/Makefile.am deleted file mode 100644 index 2f7429942..000000000 --- a/src/video_dec/libmpeg2/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -include $(top_srcdir)/misc/Makefile.common - -AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) -AM_LDFLAGS = $(xineplug_ldflags) - -noinst_HEADERS = vlc.h mpeg2.h xvmc.h xvmc_vld.h mpeg2_internal.h idct_mlib.h vis.h \ - libmpeg2_accel.h - -xineplug_LTLIBRARIES = xineplug_decode_mpeg2.la - -xineplug_decode_mpeg2_la_SOURCES = \ - cpu_state.c \ - decode.c \ - header.c \ - idct.c \ - idct_altivec.c \ - idct_mlib.c \ - idct_mmx.c \ - motion_comp.c \ - motion_comp_altivec.c \ - motion_comp_mmx.c \ - motion_comp_mlib.c \ - motion_comp_vis.c \ - slice.c \ - slice_xvmc.c \ - slice_xvmc_vld.c \ - stats.c \ - xine_mpeg2_decoder.c \ - libmpeg2_accel.c - -xineplug_decode_mpeg2_la_LIBADD = $(XINE_LIB) $(MLIB_LIBS) -lm -xineplug_decode_mpeg2_la_CFLAGS = $(AM_CFLAGS) $(MLIB_CFLAGS) -- cgit v1.2.3 From 149a11f07c92e9b15ef5566e352b2b59ad09e3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 27 Jan 2008 16:45:09 +0100 Subject: Remove win32/include/Makefile.am. --- configure.ac | 3 +-- win32/Makefile.am | 13 +++++++++++-- win32/include/Makefile.am | 14 -------------- 3 files changed, 12 insertions(+), 18 deletions(-) delete mode 100644 win32/include/Makefile.am diff --git a/configure.ac b/configure.ac index 743eb9468..31a6f6da0 100644 --- a/configure.ac +++ b/configure.ac @@ -1201,8 +1201,7 @@ src/video_out/Makefile src/xine-utils/Makefile src/xine-engine/Makefile src/vdr/Makefile -win32/Makefile -win32/include/Makefile]) +win32/Makefile]) AC_CONFIG_COMMANDS([default],[[chmod +x ./misc/SlackBuild ./misc/build_rpms.sh ./misc/relchk.sh]],[[]]) AC_OUTPUT diff --git a/win32/Makefile.am b/win32/Makefile.am index 934ddb81a..6f8795b5c 100644 --- a/win32/Makefile.am +++ b/win32/Makefile.am @@ -1,10 +1,19 @@ include $(top_srcdir)/misc/Makefile.common -SUBDIRS = include - EXTRA_DIST = \ scripts/post_install.bat \ scripts/ffmpeg_win32.patch \ + include/msvc/sys/time.h \ + include/msvc/config.h \ + include/msvc/inttypes.h \ + include/msvc/stdint.h \ + include/msvc/unistd.h \ + include/sys/socket.h \ + include/netinet/in.h \ + include/sys/socket.h \ + include/dlfcn.h \ + include/netdb.h \ + include/pwd.h \ config.h \ README \ libdvdnav.def \ diff --git a/win32/include/Makefile.am b/win32/include/Makefile.am deleted file mode 100644 index e7f124586..000000000 --- a/win32/include/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ -include $(top_srcdir)/misc/Makefile.common - -EXTRA_DIST = \ - msvc/sys/time.h \ - msvc/config.h \ - msvc/inttypes.h \ - msvc/stdint.h \ - msvc/unistd.h \ - sys/socket.h \ - netinet/in.h \ - sys/socket.h \ - dlfcn.h \ - netdb.h \ - pwd.h -- cgit v1.2.3 From ed50aae86ce8fd29842df53ee83e0b1d4cddb828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 27 Jan 2008 16:51:38 +0100 Subject: Revert part of commit applied by mistake. --- src/xine-engine/audio_out.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/xine-engine/audio_out.c b/src/xine-engine/audio_out.c index 34f982d18..855051582 100644 --- a/src/xine-engine/audio_out.c +++ b/src/xine-engine/audio_out.c @@ -1626,7 +1626,6 @@ static void ao_close(xine_audio_port_t *this_gen, xine_stream_t *stream) { } else fifo_wait_empty(this->out_fifo); - ao_set_property(this_gen, AO_PROP_DISCARD_BUFFERS, 0); } pthread_mutex_lock( &this->driver_lock ); -- cgit v1.2.3 From 3343d52e459bfc9c9db28dcba7afb0c6e2f05f59 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Mon, 28 Jan 2008 17:03:37 +0000 Subject: Fix a RealPlayer codec detection bug. --- ChangeLog | 1 + src/libreal/real_common.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 98bf6b16e..f05ce93eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ xine-lib (1.1.11) unreleased + * Fix a RealPlayer codec detection bug. xine-lib (1.1.10) 2008-01-26 * Security fixes: diff --git a/src/libreal/real_common.c b/src/libreal/real_common.c index fcd0fac8f..6fda4ddbe 100644 --- a/src/libreal/real_common.c +++ b/src/libreal/real_common.c @@ -77,8 +77,8 @@ void _x_real_codecs_init(xine_t *const xine) { default_real_codecs_path[0] = 0; -#define UL64 0x05 /* /usr/{,local/}lib64 */ -#define UL 0x0A /* /usr/{,local/}lib */ +#define UL64 0x03 /* /usr/{,local/}lib64 */ +#define UL 0x0C /* /usr/{,local/}lib */ #define O 0x10 /* /opt */ #define OL64 0x20 /* /opt/lib64 */ #define OL 0x40 /* /opt/lib */ -- cgit v1.2.3 From 013a7a0aa76b6ec65807fecbc8a70849447f1e76 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Wed, 30 Jan 2008 14:30:03 +0000 Subject: Make sure that PKG_CONFIG_PATH is set properly by xine-config. --HG-- rename : misc/xine-config => misc/xine-config.in --- configure.ac | 5 ++++ misc/Makefile.am | 1 - misc/xine-config | 70 ------------------------------------------------- misc/xine-config.in | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 71 deletions(-) delete mode 100644 misc/xine-config create mode 100644 misc/xine-config.in diff --git a/configure.ac b/configure.ac index c9396cf27..9badb9d23 100644 --- a/configure.ac +++ b/configure.ac @@ -2394,8 +2394,10 @@ makeexpand () { xinelibdir='${libdir}/xine' xinedatadir='${datadir}/xine' +pkgconfigdir='${libdir}/pkgconfig' AC_SUBST(xinelibdir) AC_SUBST(xinedatadir) +AC_SUBST(pkgconfigdir) XINE_PLUGINDIR="\${xinelibdir}/plugins/$XINE_MAJOR.$XINE_MINOR.$XINE_SUB$XINE_PATCH" XINE_FONTDIR="\${xinedatadir}/libxine$XINE_MAJOR/fonts" @@ -2404,6 +2406,7 @@ XINE_REL_PLUGINDIR="`makeexpand "$XINE_PLUGINDIR"`" XINE_REL_PLUGINDIR="`makeexpand "$XINE_REL_PLUGINDIR" | sed -e "s,^${prefix}/,,"`" XINE_REL_FONTDIR="`makeexpand "$XINE_FONTDIR" | sed -e "s,^${prefix}/,,"`" XINE_REL_LOCALEDIR="`makeexpand "$XINE_LOCALEDIR" | sed -e "s,^${prefix}/,,"`" +XINE_PKGCONFIG_DIR="`makeexpand "$pkgconfigdir"`" if test "x$SYS" = "xmingw32" -o "x$SYS" = "xcygwin"; then dnl polish paths (MinGW runtime accepts both \ and / anyway) XINE_REL_PLUGINDIR="`echo "$XINE_REL_PLUGINDIR" | sed -e 's/\\//\\\\\\\\/g'`" @@ -2441,6 +2444,7 @@ AC_SUBST(XINE_LOCALEPATH) AC_SUBST(XINE_PLUGINDIR) AC_SUBST(XINE_FONTDIR) AC_SUBST(XINE_LOCALEDIR) +AC_SUBST(XINE_PKGCONFIG_DIR) dnl Where aclocal m4 files should be installed XINE_ACFLAGS="-I ${datarootdir}/aclocal" @@ -2656,6 +2660,7 @@ misc/build_rpms.sh misc/fonts/Makefile misc/libxine.pc misc/relchk.sh +misc/xine-config misc/xine-lib.spec po/Makefile.in src/Makefile diff --git a/misc/Makefile.am b/misc/Makefile.am index 70cbe59ee..ef61b325d 100644 --- a/misc/Makefile.am +++ b/misc/Makefile.am @@ -17,7 +17,6 @@ EXTRA_DIST = build_rpms.sh \ bin_SCRIPTS = xine-config -pkgconfigdir=$(libdir)/pkgconfig pkgconfig_DATA=libxine.pc xine-fontconv: xine-fontconv.c diff --git a/misc/xine-config b/misc/xine-config deleted file mode 100644 index 5723a1a46..000000000 --- a/misc/xine-config +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/sh -# -# - -unset prefix -unset exec_prefix -unset args - -usage() -{ - cat <<EOF -Usage: xine-config [OPTIONS] [LIBRARIES] -Options: - [--prefix[=DIR]] - [--exec-prefix[=DIR]] - [--version] - [--libs] - [--acflags] - [--cflags] - [--plugindir] - [--datadir] - [--scriptdir] - [--localedir] - [--objcflags] -EOF - exit $1 -} - -if test $# -eq 0; then - usage 1 1>&2 -fi - -while test $# -gt 0; do - case "$1" in - -*=*) optarg="${1#--*=}" ;; - *) optarg= ;; - esac - - case "$1" in - --prefix=*) - prefix="$optarg" - if [ "$exec_prefix" = '' ]; then - exec_prefix="$optarg" - fi - ;; - --exec-prefix=*) - exec_prefix="$optarg" - ;; - --version) - args="$args${args+ }--modversion" - ;; - --cflags|--libs) - args="$args${args+ }$1" - ;; - --prefix|--acflags|--plugindir|--datadir|--scriptdir|--localedir|--objcflags) - args="$args${args+ }--variable=${1#--}" - ;; - --exec-prefix) - args="$args${args+ }--variable=exec_prefix" - ;; - *) - usage 1 1>&2 - ;; - esac - shift -done - -exec pkg-config "${prefix+--define-variable=prefix=}$prefix" \ - "${exec_prefix+--define-variable=exec_prefix=}$exec_prefix" \ - $args libxine diff --git a/misc/xine-config.in b/misc/xine-config.in new file mode 100644 index 000000000..719d9667e --- /dev/null +++ b/misc/xine-config.in @@ -0,0 +1,75 @@ +#!/bin/sh +# +# + +unset prefix +unset exec_prefix +unset args + +PKG_CONFIG_PATH="$(cat <<'EOF' +@XINE_PKGCONFIG_DIR@ +EOF +)${PKG_CONFIG_PATH:+:}$PKG_CONFIG_PATH" + +usage() +{ + cat <<EOF +Usage: xine-config [OPTIONS] [LIBRARIES] +Options: + [--prefix[=DIR]] + [--exec-prefix[=DIR]] + [--version] + [--libs] + [--acflags] + [--cflags] + [--plugindir] + [--datadir] + [--scriptdir] + [--localedir] + [--objcflags] +EOF + exit $1 +} + +if test $# -eq 0; then + usage 1 1>&2 +fi + +while test $# -gt 0; do + case "$1" in + -*=*) optarg="${1#--*=}" ;; + *) optarg= ;; + esac + + case "$1" in + --prefix=*) + prefix="$optarg" + if [ "$exec_prefix" = '' ]; then + exec_prefix="$optarg" + fi + ;; + --exec-prefix=*) + exec_prefix="$optarg" + ;; + --version) + args="$args${args+ }--modversion" + ;; + --cflags|--libs) + args="$args${args+ }$1" + ;; + --prefix|--acflags|--plugindir|--datadir|--scriptdir|--localedir|--objcflags) + args="$args${args+ }--variable=${1#--}" + ;; + --exec-prefix) + args="$args${args+ }--variable=exec_prefix" + ;; + *) + usage 1 1>&2 + ;; + esac + shift +done + +exec pkg-config "${prefix+--define-variable=prefix=}$prefix" \ + "${exec_prefix+--define-variable=exec_prefix=}$exec_prefix" \ + $args libxine -- cgit v1.2.3 From e0cce33a034a98b266db827c12a1b5b51a5c5dd1 Mon Sep 17 00:00:00 2001 From: "Carlos E. R." <carloser@users.sourceforge.net> Date: Thu, 31 Jan 2008 20:39:26 +0100 Subject: [translations] xine-lib translation to Spanish --- po/es.po | 622 +++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 345 insertions(+), 277 deletions(-) diff --git a/po/es.po b/po/es.po index 8f24e13bb..560419d9a 100644 --- a/po/es.po +++ b/po/es.po @@ -1,18 +1,18 @@ -# translation of xine-lib-1.1.4.po to Spanish +# translation of xine-lib.hg.po to Spanish # Spanish .po file for xine-lib. -# Copyright (C) 2002, 2006, 2007 Free Software Foundation, Inc. +# Copyright (C) 2002, 2006, 2007, 2008 Free Software Foundation, Inc. # # Juan Manuel García Molina <juanma_gm@wanadoo.es>, 2002. -# Carlos E. Robinson M. <carloser@users.sourceforge.net>, 2006, 2007. +# Carlos E. Robinson M. <carloser@users.sourceforge.net>, 2006, 2007, 2008. # Cer: <<== marcas de revision. msgid "" msgstr "" -"Project-Id-Version: xine-lib-1.1.4\n" +"Project-Id-Version: xine-lib.hg\n" "Report-Msgid-Bugs-To: xine-devel@lists.sourceforge.net\n" -"POT-Creation-Date: 2007-12-24 18:34+0000\n" -"PO-Revision-Date: 2007-10-28 00:11+0200\n" -"Last-Translator: Carlos E. Robinson <carloser@users.sourceforge.net>\n" -"Language-Team: Spanish\n" +"POT-Creation-Date: 2008-01-26 17:44+0000\n" +"PO-Revision-Date: 2008-01-31 14:32+0100\n" +"Last-Translator: Carlos E. Robinson M. <carloser@users.sourceforge.net>\n" +"Language-Team: Spanish <none>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -863,12 +863,12 @@ msgstr "" "complemento de xine de salida de audio usando dispositivos/drivers " "compatibles sun" -#: src/demuxers/demux_asf.c:426 +#: src/demuxers/demux_asf.c:441 #, c-format msgid "demux_asf: warning: The stream id=%d is encrypted.\n" msgstr "demux_asf: aviso: El flujo de bits (stream) id=%d está encriptado.\n" -#: src/demuxers/demux_asf.c:428 +#: src/demuxers/demux_asf.c:443 msgid "Media stream scrambled/encrypted" msgstr "Flujo de bits del medio revuelto/encriptado" @@ -2209,7 +2209,7 @@ msgstr "input_net: no se puede resolver '%s'.\n" msgid "input_net: unable to connect to '%s'.\n" msgstr "input_net: no se puede conectar a '%s'.\n" -#: src/input/input_net.c:508 +#: src/input/input_net.c:514 msgid "net input plugin as shipped with xine" msgstr "complemento de entrada de red incluido en xine" @@ -2232,32 +2232,32 @@ msgstr "input_pvr: error al abrir el archivo pvr (%s)\n" msgid "input_pvr: read error (%s)\n" msgstr "input_pvr: error de lectura (%s)\n" -#: src/input/input_pvr.c:1150 src/input/input_pvr.c:1403 +#: src/input/input_pvr.c:1173 src/input/input_pvr.c:1426 #, c-format msgid "input_pvr: error opening device %s\n" msgstr "input_pvr: error al abrir el dispositivo %s\n" -#: src/input/input_pvr.c:1156 src/input/input_pvr.c:1409 +#: src/input/input_pvr.c:1179 src/input/input_pvr.c:1432 msgid "input_pvr: IVTV_IOC_G_CODEC failed, maybe API changed?\n" msgstr "" "input_pvr: IVTV_IOC_G_CODEC falló, ¿quizás cambió la API? (interfase para " "programación de aplicaciones)\n" -#: src/input/input_pvr.c:1164 src/input/input_pvr.c:1418 +#: src/input/input_pvr.c:1187 src/input/input_pvr.c:1441 msgid "input_pvr: IVTV_IOC_S_CODEC failed, maybe API changed?\n" msgstr "" "input_pvr: IVTV_IOC_S_CODEC falló, ¿quizás cambió la API? (interfase para " "programación de aplicaciones)\n" -#: src/input/input_pvr.c:1526 +#: src/input/input_pvr.c:1549 msgid "WinTV-PVR 250/350 input plugin" msgstr "complemento de entrada para WinTV-PVR 250/350" -#: src/input/input_pvr.c:1552 +#: src/input/input_pvr.c:1575 msgid "device used for WinTV-PVR 250/350 (pvr plugin)" msgstr "dispositivo usado para WinTV-PVR 250/350 (complemento pvr)" -#: src/input/input_pvr.c:1553 +#: src/input/input_pvr.c:1576 msgid "The path to the device of your WinTV card." msgstr "El camino al dispositivo de su tarjeta WinTV." @@ -2355,43 +2355,55 @@ msgstr "stdin: falló al abrir '%s'\n" msgid "stdin streaming input plugin" msgstr "complemento de entrada de flujo de bits" -#: src/input/input_v4l.c:379 +#: src/input/input_v4l.c:382 msgid "Buffer underrun..." msgstr "Memoria intermedia vacía..." -#: src/input/input_v4l.c:383 +#: src/input/input_v4l.c:386 msgid "Buffer overrun..." msgstr "Memoria intermedia rebosando..." -#: src/input/input_v4l.c:386 +#: src/input/input_v4l.c:389 msgid "Adjusting..." msgstr "Ajustando..." -#: src/input/input_v4l.c:658 +#: src/input/input_v4l.c:661 msgid "Tuner name not found\n" msgstr "Nombre del sintonizador no encontrado\n" -#: src/input/input_v4l.c:1874 +#: src/input/input_v4l.c:1881 msgid "v4l tv input plugin" msgstr "Complemento de entrada v4l tv" -#: src/input/input_v4l.c:1878 +#: src/input/input_v4l.c:1885 msgid "v4l radio input plugin" msgstr "Complemento de entrada v4l radio" -#: src/input/input_v4l.c:1910 +#: src/input/input_v4l.c:1917 msgid "v4l video device" msgstr "dispositivo vídeo v4l" -#: src/input/input_v4l.c:1911 +#: src/input/input_v4l.c:1918 msgid "The path to your Video4Linux video device." msgstr "El camino a su dispositivo de vídeo Video4Linux." -#: src/input/input_v4l.c:1936 +#: src/input/input_v4l.c:1923 +msgid "v4l ALSA audio input device" +msgstr "dispositivo entrada audio ALSA v4l" + +#: src/input/input_v4l.c:1924 +msgid "" +"The name of the audio device which corresponds to your Video4Linux video " +"device." +msgstr "" +"El nombre del dispositivo de audio que corresponde a su dispositivo de vídeo " +"Video4Linux." + +#: src/input/input_v4l.c:1951 msgid "v4l radio device" msgstr "dispositivo audio v4l" -#: src/input/input_v4l.c:1937 +#: src/input/input_v4l.c:1952 msgid "The path to your Video4Linux radio device." msgstr "El camino a su dispositivo de radio Video4Linux." @@ -2449,7 +2461,15 @@ msgstr "rtsp_session: falló en conectar al servidor %s\n" msgid "rtsp_session: session can not be established.\n" msgstr "rtsp_session: la sesión no pudo establecerse.\n" -#: src/input/librtsp/rtsp_session.c:159 +#: src/input/librtsp/rtsp_session.c:153 +msgid "" +"rtsp_session: rtsp server returned overly-large headers, session can not be " +"established.\n" +msgstr "" +"rtsp_session: el servidor rtsp devolvió cabeceras demasiado grandes, la " +"sesión no puede ser establecida.\n" + +#: src/input/librtsp/rtsp_session.c:164 #, c-format msgid "rtsp_session: rtsp server type '%s' not supported yet. sorry.\n" msgstr "" @@ -2504,9 +2524,11 @@ msgid "unsupported protocol\n" msgstr "protocolo no soportado\n" # msgstr "Tamponeando..." +# Llenando mem. tampón... +# Tamponeando... #: src/input/net_buf_ctrl.c:89 msgid "Buffering..." -msgstr "Llenando mem. tampón..." +msgstr "Precargando..." #: src/input/pnm.c:615 #, c-format @@ -2859,42 +2881,42 @@ msgstr "" "dvaudio: incrementando el tamaño de la memoria tampón a %d para evitar el " "desbordamiento.\n" -#: src/libffmpeg/ff_video_decoder.c:156 +#: src/libffmpeg/ff_video_decoder.c:158 msgid "ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n" msgstr "ffmpeg_video_dec: formato de cuadro no soportado, DR1 desactivado.\n" -#: src/libffmpeg/ff_video_decoder.c:174 +#: src/libffmpeg/ff_video_decoder.c:176 msgid "ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n" msgstr "" "ffmpeg_video_dec: dimensiones de cuadro no soportadas, DR1 desactivado.\n" -#: src/libffmpeg/ff_video_decoder.c:338 +#: src/libffmpeg/ff_video_decoder.c:359 #, c-format msgid "ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n" msgstr "" "ffmpeg_video_dec: no pude encontrar el decodificador ffmpeg para el tipo de " "tampón 0x%X\n" -#: src/libffmpeg/ff_video_decoder.c:367 +#: src/libffmpeg/ff_video_decoder.c:391 msgid "ffmpeg_video_dec: couldn't open decoder\n" msgstr "ffmpeg_video_dec: no pude abrir el decodificador\n" -#: src/libffmpeg/ff_video_decoder.c:408 +#: src/libffmpeg/ff_video_decoder.c:434 msgid "ffmpeg_video_dec: direct rendering enabled\n" msgstr "ffmpeg_video_dec: renderizado directo activado\n" -#: src/libffmpeg/ff_video_decoder.c:836 +#: src/libffmpeg/ff_video_decoder.c:874 #, c-format msgid "ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n" msgstr "" "ffmpeg_video_dec: incrementando el tamaño de la memoria tampón a %d para " "evitar el desbordamiento.\n" -#: src/libffmpeg/ff_video_decoder.c:1562 +#: src/libffmpeg/ff_video_decoder.c:1600 msgid "MPEG-4 postprocessing quality" msgstr "calidad de postprocesado MPEG-4" -#: src/libffmpeg/ff_video_decoder.c:1563 +#: src/libffmpeg/ff_video_decoder.c:1601 msgid "" "You can adjust the amount of post processing applied to MPEG-4 video.\n" "Higher values result in better quality, but need more CPU. Lower values may " @@ -2908,18 +2930,61 @@ msgstr "" "bloque. Para contenido de alta calidad, demasiado postprocesado puede de " "hecho hacer la imagen peor emborronándola demasiado." -#: src/libffmpeg/ff_video_decoder.c:1571 +#: src/libffmpeg/ff_video_decoder.c:1609 msgid "FFmpeg video decoding thread count" -msgstr "" +msgstr "Conteo de hilos decodificando vídeo FFmpeg" -#: src/libffmpeg/ff_video_decoder.c:1572 +#: src/libffmpeg/ff_video_decoder.c:1610 msgid "" "You can adjust the number of video decoding threads which FFmpeg may use.\n" "Higher values should speed up decoding but it depends on the codec used " "whether parallel decoding is supported. A rule of thumb is to have one " -"decoding thread per logical CPU (typically 1 to 4). A change will take " -"effect with playing the next stream." -msgstr "" +"decoding thread per logical CPU (typically 1 to 4).\n" +"A change of this setting will take effect with playing the next stream." +msgstr "" +"Puede ajustar el número de hilos decodificadores que pueda usar FFmpeg.\n" +"Valores más altos deben acelerar la decodificación, pero depende del códec " +"usado si se soporta procesado en paralelo. Una regla general es tener un " +"hilo decodificador por cada CPU lógica (típicamente de 1 a 4).\n" +"Un cambio de este ajuste hará efecto cuando se reproduzca el siguiente flujo." + +#: src/libffmpeg/ff_video_decoder.c:1619 +msgid "Skip loop filter" +msgstr "Saltarse filtro de bucle" + +# Cer "saltar" por"skip" suena raro. +#: src/libffmpeg/ff_video_decoder.c:1620 +msgid "" +"You can control for which frames the loop filter shall be skipped after " +"decoding.\n" +"Skipping the loop filter will speedup decoding but may lead to artefacts. " +"The number of frames for which it is skipped increases from 'none' to 'all'. " +"The default value leaves the decision up to the implementation.\n" +"A change of this setting will take effect with playing the next stream." +msgstr "" +"Puede controlar para que cuadros el filtro de bucle será saltado después de " +"decodificar.\n" +"Omitir el filtro de bucle acelerará la decodificación, pero puede llevarnos " +"a tener artefactos. El número de cuadros para los que se salta aumenta de " +"'none' a 'all' (“nada†a “todosâ€). El valor por omisión deja la decisión en " +"manos de la implementación.\n" +"Un cambio de este ajuste tendrá efecto a la reproducción de siguiente flujo." + +#: src/libffmpeg/ff_video_decoder.c:1629 +msgid "Choose speed over specification compliance" +msgstr "Elegir velocidad en vez de conformidad con la especificación" + +#: src/libffmpeg/ff_video_decoder.c:1630 +msgid "" +"You may want to allow speed cheats which violate codec specification.\n" +"Cheating may speed up decoding but can also lead to decoding artefacts.\n" +"A change of this setting will take effect with playing the next stream." +msgstr "" +"Usted puede querer permitir trampas de velocidad que violan las " +"especificaciones del códec.\n" +"Hacer trampas puede acelerar la decodificación pero también provocar " +"artefactos de decodificación.\n" +"Un cambio de este ajuste tendrá efecto a la reproducción de siguiente flujo." #: src/libffmpeg/ffmpeg_encoder.c:165 msgid "libavcodec mpeg output bitrate (kbit/s)" @@ -3103,11 +3168,11 @@ msgstr "" msgid "encoding of subtitles" msgstr "codificado de los subtítulos" -#: src/libsputext/demux_sputext.c:1504 +#: src/libsputext/demux_sputext.c:1479 msgid "default duration of subtitle display in seconds" msgstr "duración por defecto de la exhibición de los subtítulos en segundos" -#: src/libsputext/demux_sputext.c:1505 +#: src/libsputext/demux_sputext.c:1480 msgid "" "Some subtitle formats do not explicitly give a duration for each subtitle. " "For these, you can set a default duration here. Setting to zero will result " @@ -3118,11 +3183,11 @@ msgstr "" "a cero hará que el subtítulo se siga mostrando hasta que aparezca el " "siguiente." -#: src/libsputext/xine_sputext_decoder.c:928 +#: src/libsputext/xine_sputext_decoder.c:1151 msgid "subtitle size" msgstr "tamaño de subtítulo " -#: src/libsputext/xine_sputext_decoder.c:929 +#: src/libsputext/xine_sputext_decoder.c:1152 msgid "" "You can adjust the subtitle size here. The setting will be evaluated " "relative to the window size." @@ -3130,11 +3195,11 @@ msgstr "" "Puede ajustar el tamaño de los subtítulos aquí. El ajuste será evaluado " "relativo al tamaño de la ventana." -#: src/libsputext/xine_sputext_decoder.c:935 +#: src/libsputext/xine_sputext_decoder.c:1158 msgid "subtitle vertical offset" msgstr "desplazamiento vertical de los subtítulos" -#: src/libsputext/xine_sputext_decoder.c:936 +#: src/libsputext/xine_sputext_decoder.c:1159 msgid "" "You can adjust the vertical position of the subtitle. The setting will be " "evaluated relative to the window size." @@ -3142,32 +3207,32 @@ msgstr "" "Puede ajustar la posición vertical de los subtítulos aquí. El ajuste será " "evaluado relativo al tamaño de la ventana." -#: src/libsputext/xine_sputext_decoder.c:942 -#: src/libsputext/xine_sputext_decoder.c:951 +#: src/libsputext/xine_sputext_decoder.c:1165 +#: src/libsputext/xine_sputext_decoder.c:1174 msgid "font for subtitles" msgstr "tipografía para los subtítulos" -#: src/libsputext/xine_sputext_decoder.c:943 +#: src/libsputext/xine_sputext_decoder.c:1166 msgid "A font from the xine font directory to be used for the subtitle text." msgstr "" "Tipografía del directorio de xine que será usada para el texto de los " "subtítulos." -#: src/libsputext/xine_sputext_decoder.c:952 +#: src/libsputext/xine_sputext_decoder.c:1175 msgid "An outline font file (e.g. a .ttf) to be used for the subtitle text." msgstr "" "Un fichero de tipografía tipo linea (pe: a.ttf) que será usada para el texto " "de los subtítulos." -#: src/libsputext/xine_sputext_decoder.c:958 +#: src/libsputext/xine_sputext_decoder.c:1181 msgid "whether to use a freetype font" msgstr "si debemos usar una tipografía freetype" -#: src/libsputext/xine_sputext_decoder.c:965 +#: src/libsputext/xine_sputext_decoder.c:1188 msgid "encoding of the subtitles" msgstr "codificación de los subtítulos" -#: src/libsputext/xine_sputext_decoder.c:966 +#: src/libsputext/xine_sputext_decoder.c:1189 msgid "" "The encoding of the subtitle text in the stream. This setting is used to " "render non-ASCII characters correctly. If non-ASCII characters are not " @@ -3179,11 +3244,11 @@ msgstr "" "caracteres no ASCII no se muestran de la forma que usted espera, pregúntele " "al creador de los subtítulos que codificación se usó." -#: src/libsputext/xine_sputext_decoder.c:974 +#: src/libsputext/xine_sputext_decoder.c:1197 msgid "use unscaled OSD if possible" msgstr "use OSD sin escalar si es posible" -#: src/libsputext/xine_sputext_decoder.c:975 +#: src/libsputext/xine_sputext_decoder.c:1198 msgid "" "The unscaled OSD will be rendered independently of the video frame and will " "always be sharp, even if the video is magnified. This will look better, but " @@ -3378,6 +3443,12 @@ msgstr "" "varias muestras para nivelar las variaciones vía la media ponderada standard " "de las muestras pasadas.\n" +# Cer: pulldown: se refiere a curiosos mecanismos de adaptación +# de las diferentes frecuencias de cuadro entre pelicula y vídeo +# (ver http://en.wikipedia.org/wiki/Telecine#2:3_pulldown). +# Ignoro que nombre puede tener en español. Lo de “pulldown†+# viene del arrastre de la pelicula, de la que se tira con una uña +# en la cámara #: src/post/deinterlace/xine_plugin.c:202 msgid "" "Advanced tvtime/deinterlacer plugin with pulldown detection\n" @@ -3430,8 +3501,8 @@ msgid "" "Deinterlacing methods: (Not all methods are available for all plataforms)\n" "\n" msgstr "" -"Complemento avanzado tvtime/desentrelazador con detección de despliegue de " -"menú {pulldown}\n" +"Complemento avanzado tvtime/desentrelazador con detección de conversión de " +"frecuencia de cuadro en el telecine (“pulldownâ€)\n" "Este complemento trata de suministrar mecanismos de desentrelazado " "comparables a reproductores de alta calidad progresivos de DVD y los así " "llamados dobladores de linea, para usar con monitores de ordenador, " @@ -3444,10 +3515,10 @@ msgstr "" "\n" " Enabled (activado): Activar/desactivar el complemento.\n" "\n" -" Pulldown (despliegue): Escoger el algoritmo de detección de despliegue 2-3 " -"{¿de menú?}. Las películas de 24 CPS (cuadros por segundo) que han sido " -"convertidas a NTSC pueden ser detectadas e inteligentemente reconstruidas a " -"sus cuadros originales (no entrelazados).\n" +" Pulldown (ajuste de telecine): Escoger el algoritmo de detección de ajuste " +"de telecine 2-3. Las películas de 24 CPS (cuadros por segundo) que han sido " +"convertidas a NTSC con ese ajuste, pueden ser detectadas e inteligentemente " +"reconstruidas a sus cuadros originales (no entrelazados).\n" "\n" " Framerate_mode (modo de cadencia de cuadro): Seleccionar 'full' (completo) " "desentrelazará cada campo a un único cuadro en calidad de televisión y más " @@ -3457,11 +3528,11 @@ msgstr "" "Un RedHat más moderno y los kernels 2.6 usan una frecuencia mayor (512 y " "1000, respectivamente) y deberían funcionar bien.\n" "\n" -" Judder_correction (corrección de vibración): Una vez que despliegue 2-3 " -"está activado y se detecta que tenemos una película, es posible reducir la " -"cadencia de cuadro a la original (24 CPS). Esto distribuirá los cuadros " -"uniformemente en el tiempo, coincidiendo con la velocidad con que fueron " -"rodados y eliminando el efecto de vibración.\n" +" Judder_correction (corrección de vibración): Una vez que ajuste de " +"telecine 2-3 está activado y se detecta que tenemos una película, es posible " +"reducir la cadencia de cuadro a la original (24 CPS). Esto distribuirá los " +"cuadros uniformemente en el tiempo, coincidiendo con la velocidad con que " +"fueron rodados y eliminando el efecto de vibración.\n" "\n" " Use_progressive_frame_flag (use bandera de cuadro progresivo): Flujos de " "datos MPEG2 bien creados usan una bandera para indicar material progresivo. " @@ -3873,10 +3944,10 @@ msgid "video colour key" msgstr "llave de color de vídeo" #: src/video_out/video_out_directfb.c:1365 -#: src/video_out/video_out_vidix.c:1156 src/video_out/video_out_vidix.c:1163 -#: src/video_out/video_out_vidix.c:1170 src/video_out/video_out_xcbxv.c:1438 -#: src/video_out/video_out_xv.c:1491 src/video_out/video_out_xvmc.c:1445 -#: src/video_out/video_out_xxmc.c:2529 +#: src/video_out/video_out_vidix.c:1168 src/video_out/video_out_vidix.c:1175 +#: src/video_out/video_out_vidix.c:1182 src/video_out/video_out_xcbxv.c:1445 +#: src/video_out/video_out_xv.c:1503 src/video_out/video_out_xvmc.c:1464 +#: src/video_out/video_out_xxmc.c:2541 msgid "" "The colour key is used to tell the graphics card where to overlay the video " "image. Try different values, if you experience windows becoming transparent." @@ -3982,7 +4053,7 @@ msgstr "complemento de xine de salida de vídeo usando DirectFB bajo XDirectFB." msgid "xine video output plugin for win32 using directx" msgstr "complemento de xine de salida de vídeo para win32 usando directx" -#: src/video_out/video_out_fb.c:758 +#: src/video_out/video_out_fb.c:770 #, c-format msgid "" "video_out_fb: only packed truecolour/directcolour is supported (%d).\n" @@ -3992,11 +4063,11 @@ msgstr "" "directo) empaquetado (%d).\n" " Compruebe 'fbset -i' o pruebe 'fbset -depth 16'.\n" -#: src/video_out/video_out_fb.c:818 src/video_out/video_out_vidix.c:1236 +#: src/video_out/video_out_fb.c:830 src/video_out/video_out_vidix.c:1248 msgid "framebuffer device name" msgstr "nombre del dispositivo framebuffer" -#: src/video_out/video_out_fb.c:819 src/video_out/video_out_vidix.c:1237 +#: src/video_out/video_out_fb.c:831 src/video_out/video_out_vidix.c:1249 msgid "" "Specifies the file name for the framebuffer device to be used.\n" "This setting is security critical, because when changed to a different file, " @@ -4010,16 +4081,16 @@ msgstr "" "arbitrario. De modo que debería ser cuidadoso de que el valor que introduzca " "es realmente un verdadero dispositivo framebuffer." -#: src/video_out/video_out_fb.c:893 +#: src/video_out/video_out_fb.c:905 msgid "video_out_fb: Your video mode was not recognized, sorry.\n" msgstr "video_out_fb: Lo sentimos, su modo de vídeo no fue reconocido .\n" -#: src/video_out/video_out_fb.c:950 +#: src/video_out/video_out_fb.c:962 #, c-format msgid "video_out_fb: %d video RAM buffers are available.\n" msgstr "video_out_fb: están disponibles %d tampones de vídeo en RAM.\n" -#: src/video_out/video_out_fb.c:956 +#: src/video_out/video_out_fb.c:968 #, c-format msgid "" "WARNING: video_out_fb: Zero copy buffers are DISABLED because only %d " @@ -4036,7 +4107,7 @@ msgstr "" # Cer: panning --> panoramizado # frame flips --> volteos de cuadro # Zero copy buffers --> tampones copia cero -#: src/video_out/video_out_fb.c:967 +#: src/video_out/video_out_fb.c:979 msgid "" "WARNING: video_out_fb: Zero copy buffers are DISABLED because kernel driver\n" " do not support screen panning (used for frame flips).\n" @@ -4045,7 +4116,7 @@ msgstr "" "driver del kernel\n" " no soporta panoramizado de pantalla (usado para volteos de cuadro ).\n" -#: src/video_out/video_out_fb.c:1036 +#: src/video_out/video_out_fb.c:1048 #, c-format msgid "" "WARNING: video_out_fb: current display depth is %d. For better performance\n" @@ -4057,7 +4128,7 @@ msgstr "" " se recomienda una profundidad de 16 bpp!\n" "\n" -#: src/video_out/video_out_fb.c:1067 +#: src/video_out/video_out_fb.c:1079 msgid "Xine video output plugin using the Linux frame buffer device" msgstr "" "Complemento de xine de salida de vídeo usando el dispositivo Linux tampón de " @@ -4139,9 +4210,9 @@ msgstr "" "Frecuencia mínima de cuadro para rutinas animadas de renderizado.\n" "Ignorado para rutinas estáticas de renderizado.\n" -#: src/video_out/video_out_opengl.c:1915 src/video_out/video_out_vidix.c:1012 -#: src/video_out/video_out_xcbxv.c:1470 src/video_out/video_out_xv.c:1523 -#: src/video_out/video_out_xvmc.c:1459 src/video_out/video_out_xxmc.c:2561 +#: src/video_out/video_out_opengl.c:1915 src/video_out/video_out_vidix.c:1024 +#: src/video_out/video_out_xcbxv.c:1477 src/video_out/video_out_xv.c:1535 +#: src/video_out/video_out_xvmc.c:1478 src/video_out/video_out_xxmc.c:2573 msgid "enable double buffering" msgstr "activar doble tamponeado" @@ -4236,9 +4307,9 @@ msgstr "" msgid "video_out_pgx64: Error: ioctl failed (FBIOGATTR)\n" msgstr "video_out_pgx64: Error: falló ioctl (FBIOGATTR)\n" -#: src/video_out/video_out_pgx64.c:1461 src/video_out/video_out_xcbxv.c:1437 -#: src/video_out/video_out_xv.c:1490 src/video_out/video_out_xvmc.c:1444 -#: src/video_out/video_out_xxmc.c:2528 +#: src/video_out/video_out_pgx64.c:1461 src/video_out/video_out_xcbxv.c:1444 +#: src/video_out/video_out_xv.c:1502 src/video_out/video_out_xvmc.c:1463 +#: src/video_out/video_out_xxmc.c:2540 msgid "video overlay colour key" msgstr "llave de color de superposición de vídeo" @@ -4276,11 +4347,11 @@ msgstr "" "Multi-tamponeado incrementa el rendimiento a costa de usar más memoria " "gráfica." -#: src/video_out/video_out_sdl.c:480 +#: src/video_out/video_out_sdl.c:488 msgid "use hardware acceleration if available" msgstr "use aceleración gráfica si está disponible" -#: src/video_out/video_out_sdl.c:481 +#: src/video_out/video_out_sdl.c:489 msgid "" "When your system supports it, hardware acceleration provided by your " "graphics hardware will be used. This might not work, so you can disable it, " @@ -4290,17 +4361,17 @@ msgstr "" "por su hardware gráfico. Esto podría no funcionar, así que lo puede " "desactivar, si las cosas van mal." -#: src/video_out/video_out_sdl.c:523 +#: src/video_out/video_out_sdl.c:531 msgid "sdl has to emulate a 16 bit surfaces, that will slow things down.\n" msgstr "" "sdl tiene que emular superficies de16 bit, que enlentecerán las cosas.\n" -#: src/video_out/video_out_sdl.c:560 +#: src/video_out/video_out_sdl.c:568 msgid "video_out_sdl: fullscreen mode is NOT supported\n" msgstr "video_out_sdl: el modo de pantalla completa NO está soportado\n" # Cer: traducción incierta -#: src/video_out/video_out_sdl.c:571 +#: src/video_out/video_out_sdl.c:579 msgid "xine video output plugin using the Simple Direct Media Layer" msgstr "" "complemento de xine de salida de vídeo usando la Capa Simple de Medios " @@ -4321,27 +4392,27 @@ msgid "video_out_syncfb: error. (YV12 not supported by your graphic card)\n" msgstr "" "video_out_syncfb: error. (YV12 no está soportado por su tarjeta gráfica)\n" -#: src/video_out/video_out_syncfb.c:938 +#: src/video_out/video_out_syncfb.c:950 msgid "video_out_syncfb: info. (SyncFB module supports YUV 4:2:0 (3 plane))\n" msgstr "video_out_syncfb: info. (módulo SyncFB soporta YUV 4:2:0 (3 planos))\n" -#: src/video_out/video_out_syncfb.c:943 +#: src/video_out/video_out_syncfb.c:955 msgid "video_out_syncfb: info. (SyncFB module supports YUV 4:2:0 (2 plane))\n" msgstr "video_out_syncfb: info. (módulo SyncFB soporta YUV 4:2:0 (2 planos))\n" -#: src/video_out/video_out_syncfb.c:948 +#: src/video_out/video_out_syncfb.c:960 msgid "video_out_syncfb: info. (SyncFB module supports YUV 4:2:2)\n" msgstr "video_out_syncfb: info. (módulo SyncFB soporta YUV 4:2:2)\n" -#: src/video_out/video_out_syncfb.c:954 +#: src/video_out/video_out_syncfb.c:966 msgid "video_out_syncfb: info. (SyncFB module supports YUY2)\n" msgstr "video_out_syncfb: info. (módulo SyncFB soporta YUY2)\n" -#: src/video_out/video_out_syncfb.c:961 +#: src/video_out/video_out_syncfb.c:973 msgid "video_out_syncfb: info. (SyncFB module supports RGB565)\n" msgstr "video_out_syncfb: info. (módulo SyncFB soporta RGB565)\n" -#: src/video_out/video_out_syncfb.c:966 +#: src/video_out/video_out_syncfb.c:978 msgid "" "video_out_syncfb: aborting. (SyncFB module does not support YV12, YUY2 nor " "RGB565)\n" @@ -4349,7 +4420,7 @@ msgstr "" "video_out_syncfb: abortando. (módulo SyncFB no soporta YV12, YUY2 ni " "RGB565)\n" -#: src/video_out/video_out_syncfb.c:985 +#: src/video_out/video_out_syncfb.c:997 msgid "" "video_out_syncfb: info. (brightness/contrast control won't be available " "because your SyncFB kernel module seems to be outdated. Please refer to " @@ -4359,11 +4430,11 @@ msgstr "" "porque su módulo del kernel SyncFB parece estar anticuado. Por favor, " "refiérase a README.syncfb para información sobre como actualizarlo.)\n" -#: src/video_out/video_out_syncfb.c:1009 +#: src/video_out/video_out_syncfb.c:1021 msgid "default number of frame repetitions" msgstr "número por defecto de repeticiones de cuadros" -#: src/video_out/video_out_syncfb.c:1010 +#: src/video_out/video_out_syncfb.c:1022 msgid "" "This specifies how many times a single video frame will be displayed " "consecutively." @@ -4371,18 +4442,18 @@ msgstr "" "Esto especifica cuantas veces se mostrará consecutivamente el mismo cuadro " "de vídeo." -#: src/video_out/video_out_syncfb.c:1058 +#: src/video_out/video_out_syncfb.c:1070 msgid "" "xine video output plugin using the SyncFB module for Matrox G200/G400 cards" msgstr "" "complemento de vídeo de xine usando el módulo SyncFB para tarjetas Matrox " "G200/G400" -#: src/video_out/video_out_syncfb.c:1076 +#: src/video_out/video_out_syncfb.c:1088 msgid "SyncFB device name" msgstr "Nombre de dispositivo de SyncFB" -#: src/video_out/video_out_syncfb.c:1077 +#: src/video_out/video_out_syncfb.c:1089 msgid "" "Specifies the file name for the SyncFB (TeleTux) device to be used.\n" "This setting is security critical, because when changed to a different file, " @@ -4396,33 +4467,33 @@ msgstr "" "arbitrario. Así que debiera ser cuidadoso con que el valor que introduzca " "sea realmente un dispositivo framebuffer adecuado." -#: src/video_out/video_out_vidix.c:990 +#: src/video_out/video_out_vidix.c:1002 msgid "red intensity" msgstr "intensidad de rojo " -#: src/video_out/video_out_vidix.c:990 +#: src/video_out/video_out_vidix.c:1002 msgid "The intensity of the red colour components." msgstr "La intensidad de los componentes de color rojo." -#: src/video_out/video_out_vidix.c:995 +#: src/video_out/video_out_vidix.c:1007 msgid "green intensity" msgstr "intensidad de verde" -#: src/video_out/video_out_vidix.c:995 +#: src/video_out/video_out_vidix.c:1007 msgid "The intensity of the green colour components." msgstr "La intensidad de los componentes de color verde." -#: src/video_out/video_out_vidix.c:1000 +#: src/video_out/video_out_vidix.c:1012 msgid "blue intensity" msgstr "intensidad de azul" -#: src/video_out/video_out_vidix.c:1000 +#: src/video_out/video_out_vidix.c:1012 msgid "The intensity of the blue colour components." msgstr "La intensidad de los componentes de color azul." -#: src/video_out/video_out_vidix.c:1013 src/video_out/video_out_xcbxv.c:1471 -#: src/video_out/video_out_xv.c:1524 src/video_out/video_out_xvmc.c:1460 -#: src/video_out/video_out_xxmc.c:2562 +#: src/video_out/video_out_vidix.c:1025 src/video_out/video_out_xcbxv.c:1478 +#: src/video_out/video_out_xv.c:1536 src/video_out/video_out_xvmc.c:1479 +#: src/video_out/video_out_xxmc.c:2574 msgid "" "Double buffering will synchronize the update of the video image to the " "repainting of the entire screen (\"vertical retrace\"). This eliminates " @@ -4433,50 +4504,50 @@ msgstr "" "vertical). Esto elimina el parpadeo y artifactos de rajado, pero usa más " "memoria gráfica." -#: src/video_out/video_out_vidix.c:1060 +#: src/video_out/video_out_vidix.c:1072 msgid "video_out_vidix: adaptor supports the yuy2 format\n" msgstr "video_out_vidix: el adaptador soporta el formato yuy2\n" -#: src/video_out/video_out_vidix.c:1071 +#: src/video_out/video_out_vidix.c:1083 msgid "video_out_vidix: adaptor supports the yv12 format\n" msgstr "video_out_vidix: el adaptador soporta el formato yv12\n" -#: src/video_out/video_out_vidix.c:1087 +#: src/video_out/video_out_vidix.c:1099 msgid "video_out_vidix: You have wrong version of VIDIX library\n" msgstr "" "video_out_vidix: Tiene usted la versión incorrecta de la librería VIDIX\n" -#: src/video_out/video_out_vidix.c:1095 +#: src/video_out/video_out_vidix.c:1107 msgid "video_out_vidix: Couldn't find working VIDIX driver\n" msgstr "video_out_vidix: No pude localizar el driver VIDIX que funcione\n" -#: src/video_out/video_out_vidix.c:1108 +#: src/video_out/video_out_vidix.c:1120 #, c-format msgid "video_out_vidix: using driver: %s by %s\n" msgstr "video_out_vidix: usando driver: %s por %s\n" -#: src/video_out/video_out_vidix.c:1155 +#: src/video_out/video_out_vidix.c:1167 msgid "video overlay colour key red component" msgstr "clave de componente rojo en superposición de vídeo" -#: src/video_out/video_out_vidix.c:1162 +#: src/video_out/video_out_vidix.c:1174 msgid "video overlay colour key green component" msgstr "clave de componente verde en superposición de vídeo" -#: src/video_out/video_out_vidix.c:1169 +#: src/video_out/video_out_vidix.c:1181 msgid "video overlay colour key blue component" msgstr "clave de componente azul en superposición de vídeo" -#: src/video_out/video_out_vidix.c:1201 +#: src/video_out/video_out_vidix.c:1213 msgid "xine video output plugin using libvidix for x11" msgstr "complemento de salida de vídeo usando libvidix para x11" -#: src/video_out/video_out_vidix.c:1283 +#: src/video_out/video_out_vidix.c:1295 msgid "xine video output plugin using libvidix for linux frame buffer" msgstr "" "complemento de salida de vídeo usando libvidix para frame buffer de linux" -#: src/video_out/video_out_xcbshm.c:155 +#: src/video_out/video_out_xcbshm.c:150 #, c-format msgid "" "video_out_xcbshm: %s: allocating image\n" @@ -4486,7 +4557,7 @@ msgstr "" "video_out_xcbshm: => no usando la extensión de memoria compartida MIT (MIT " "Shared Memory).\n" -#: src/video_out/video_out_xcbshm.c:164 +#: src/video_out/video_out_xcbshm.c:159 msgid "" "video_out_xcbshm: shared memory error (address error) when allocating " "image \n" @@ -4497,7 +4568,7 @@ msgstr "" "video_out_xcbshm: => no usando la extensión de memoria compartida MIT (MIT " "Shared Memory).\n" -#: src/video_out/video_out_xcbshm.c:175 +#: src/video_out/video_out_xcbshm.c:170 msgid "" "video_out_xcbshm: x11 error during shared memory XImage creation\n" "video_out_xcbshm: => not using MIT Shared Memory extension.\n" @@ -4507,7 +4578,7 @@ msgstr "" "video_out_xcbshm: => no usando la extensión de memoria compartida MIT (MIT " "Shared Memory).\n" -#: src/video_out/video_out_xcbshm.c:1098 src/video_out/video_out_xshm.c:1154 +#: src/video_out/video_out_xcbshm.c:1101 src/video_out/video_out_xshm.c:1157 #, c-format msgid "" "\n" @@ -4522,23 +4593,23 @@ msgstr "" "rendimiento se recomienda una profundidad de 16 bpp!\n" "\n" -#: src/video_out/video_out_xcbshm.c:1111 +#: src/video_out/video_out_xcbshm.c:1114 msgid "video_out_xcbshm: MIT shared memory extension not present on display.\n" msgstr "" "video_out_xcbshm: la extensión de memoria compartida del MIT (MIT Shared " "Memory) no está presente en la pantalla.\n" -#: src/video_out/video_out_xcbshm.c:1210 +#: src/video_out/video_out_xcbshm.c:1213 msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n" msgstr "video_out_xcbshm: su modo de vídeo no fué reconocido, lo siento :-(\n" -#: src/video_out/video_out_xcbshm.c:1240 src/video_out/video_out_xshm.c:1300 +#: src/video_out/video_out_xcbshm.c:1243 src/video_out/video_out_xshm.c:1303 msgid "xine video output plugin using the MIT X shared memory extension" msgstr "" "complemento de salida de vídeo de xine usando la extensión de memoria " "compartida del MIT (MIT Shared Memory) " -#: src/video_out/video_out_xcbxv.c:268 +#: src/video_out/video_out_xcbxv.c:263 msgid "" "video_out_xcbxv: XvShmCreateImage returned a zero size\n" "video_out_xcbxv: => not using MIT Shared Memory extension.\n" @@ -4547,7 +4618,7 @@ msgstr "" "video_out_xcbxv: => no usando la extensión de memoria compartida MIT (MIT " "Shared Memory).\n" -#: src/video_out/video_out_xcbxv.c:277 +#: src/video_out/video_out_xcbxv.c:272 #, c-format msgid "" "video_out_xcbxv: shared memory error in shmget: %s\n" @@ -4557,7 +4628,7 @@ msgstr "" "video_out_xcbxv: => no usando la extensión de memoria compartida MIT (MIT " "Shared Memory).\n" -#: src/video_out/video_out_xcbxv.c:296 +#: src/video_out/video_out_xcbxv.c:291 msgid "" "video_out_xcbxv: x11 error during shared memory XImage creation\n" "video_out_xcbxv: => not using MIT Shared Memory extension.\n" @@ -4566,11 +4637,11 @@ msgstr "" "video_out_xcbxv: => no usando la extensión de memoria compartida MIT (MIT " "Shared Memory).\n" -#: src/video_out/video_out_xcbxv.c:1289 +#: src/video_out/video_out_xcbxv.c:1296 msgid "video_out_xcbxv: Xv extension not present.\n" msgstr "video_out_xcbxv: la extensión Xv no está presente.\n" -#: src/video_out/video_out_xcbxv.c:1331 +#: src/video_out/video_out_xcbxv.c:1338 msgid "" "video_out_xcbxv: Xv extension is present but I couldn't find a usable yuv12 " "port.\n" @@ -4581,7 +4652,7 @@ msgstr "" "puerto yuv12 usable.\n" " ¡¿Parece que su driver de hardware gráfico no soporta Xv?!\n" -#: src/video_out/video_out_xcbxv.c:1339 +#: src/video_out/video_out_xcbxv.c:1346 #, c-format msgid "" "video_out_xcbxv: using Xv port %d from adaptor %s for hardware colour space " @@ -4590,23 +4661,23 @@ msgstr "" "video_out_xcbxv: usando puerto Xv %d del adaptador %s para conversión y " "escalado de espacio de color en hardware .\n" -#: src/video_out/video_out_xcbxv.c:1446 src/video_out/video_out_xv.c:1499 -#: src/video_out/video_out_xvmc.c:1453 src/video_out/video_out_xxmc.c:2537 +#: src/video_out/video_out_xcbxv.c:1453 src/video_out/video_out_xv.c:1511 +#: src/video_out/video_out_xvmc.c:1472 src/video_out/video_out_xxmc.c:2549 msgid "autopaint colour key" msgstr "llave de color autopintado" -#: src/video_out/video_out_xcbxv.c:1447 src/video_out/video_out_xv.c:1500 -#: src/video_out/video_out_xvmc.c:1454 src/video_out/video_out_xxmc.c:2538 +#: src/video_out/video_out_xcbxv.c:1454 src/video_out/video_out_xv.c:1512 +#: src/video_out/video_out_xvmc.c:1473 src/video_out/video_out_xxmc.c:2550 msgid "Make Xv autopaint its colour key." msgstr "Hacer Xv autopintar su llave de color." -#: src/video_out/video_out_xcbxv.c:1454 src/video_out/video_out_xv.c:1507 -#: src/video_out/video_out_xxmc.c:2545 +#: src/video_out/video_out_xcbxv.c:1461 src/video_out/video_out_xv.c:1519 +#: src/video_out/video_out_xxmc.c:2557 msgid "bilinear scaling mode" msgstr "modo de escalado bilineal" -#: src/video_out/video_out_xcbxv.c:1455 src/video_out/video_out_xv.c:1508 -#: src/video_out/video_out_xxmc.c:2546 +#: src/video_out/video_out_xcbxv.c:1462 src/video_out/video_out_xv.c:1520 +#: src/video_out/video_out_xxmc.c:2558 msgid "" "Selects the bilinear scaling mode for Permedia cards. The individual values " "are:\n" @@ -4632,33 +4703,33 @@ msgstr "" "1 - filtrado horizontal lineal\n" "2 - sactivar filtrado bilineal completo" -#: src/video_out/video_out_xcbxv.c:1507 +#: src/video_out/video_out_xcbxv.c:1514 msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n" msgstr "video_out_xcbxv: éste adaptador soporta el formato yv12.\n" -#: src/video_out/video_out_xcbxv.c:1512 +#: src/video_out/video_out_xcbxv.c:1519 msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n" msgstr "video_out_xcbxv: éste adaptador soporta el formato yuy2.\n" -#: src/video_out/video_out_xcbxv.c:1520 src/video_out/video_out_xv.c:1584 -#: src/video_out/video_out_xxmc.c:2630 +#: src/video_out/video_out_xcbxv.c:1527 src/video_out/video_out_xv.c:1596 +#: src/video_out/video_out_xxmc.c:2642 msgid "pitch alignment workaround" msgstr "rodeo para alineamiento de paso" -#: src/video_out/video_out_xcbxv.c:1521 src/video_out/video_out_xv.c:1585 -#: src/video_out/video_out_xxmc.c:2631 +#: src/video_out/video_out_xcbxv.c:1528 src/video_out/video_out_xv.c:1597 +#: src/video_out/video_out_xxmc.c:2643 msgid "Some buggy video drivers need a workaround to function properly." msgstr "" "Algunos drivers de vídeo con errores necesitan un rodeo para que funcionen " "adecuadamente." -#: src/video_out/video_out_xcbxv.c:1527 src/video_out/video_out_xv.c:1591 -#: src/video_out/video_out_xvmc.c:1522 +#: src/video_out/video_out_xcbxv.c:1534 src/video_out/video_out_xv.c:1603 +#: src/video_out/video_out_xvmc.c:1541 msgid "deinterlace method (deprecated)" msgstr "método de desentrelazado (obsolescente)" -#: src/video_out/video_out_xcbxv.c:1528 src/video_out/video_out_xv.c:1592 -#: src/video_out/video_out_xvmc.c:1523 +#: src/video_out/video_out_xcbxv.c:1535 src/video_out/video_out_xv.c:1604 +#: src/video_out/video_out_xvmc.c:1542 msgid "" "This config setting is deprecated. You should use the new deinterlacing post " "processing settings instead.\n" @@ -4733,12 +4804,12 @@ msgstr "" "Aplica un ligero borrón vertical para eliminar los artifactos de peine. " "Buenos resultados con uso de CPU mediano." -#: src/video_out/video_out_xcbxv.c:1582 src/video_out/video_out_xv.c:1665 -#: src/video_out/video_out_xxmc.c:2725 +#: src/video_out/video_out_xcbxv.c:1589 src/video_out/video_out_xv.c:1677 +#: src/video_out/video_out_xxmc.c:2737 msgid "xine video output plugin using the MIT X video extension" msgstr "complemento de salida de vídeo usando la extensión MIT X vídeo" -#: src/video_out/video_out_xshm.c:199 +#: src/video_out/video_out_xshm.c:194 msgid "" "video_out_xshm: shared memory error when allocating image\n" "video_out_xshm: => not using MIT Shared Memory extension.\n" @@ -4747,7 +4818,7 @@ msgstr "" "video_out_xshm: => no usando la extensión de memoria compartida MIT (MIT " "Shared Memory).\n" -#: src/video_out/video_out_xshm.c:215 +#: src/video_out/video_out_xshm.c:210 #, c-format msgid "" "video_out_xshm: %s: allocating image\n" @@ -4757,7 +4828,7 @@ msgstr "" "video_out_xshm: => no usando la extensión de memoria compartida MIT (MIT " "Shared Memory).\n" -#: src/video_out/video_out_xshm.c:225 +#: src/video_out/video_out_xshm.c:220 msgid "" "video_out_xshm: shared memory error (address error) when allocating image \n" "video_out_xshm: => not using MIT Shared Memory extension.\n" @@ -4767,7 +4838,7 @@ msgstr "" "video_out_xshm: => no usando la extensión de memoria compartida MIT (MIT " "Shared Memory).\n" -#: src/video_out/video_out_xshm.c:242 +#: src/video_out/video_out_xshm.c:237 msgid "" "video_out_xshm: x11 error during shared memory XImage creation\n" "video_out_xshm: => not using MIT Shared Memory extension.\n" @@ -4776,13 +4847,13 @@ msgstr "" "video_out_xshm: => no usando la extensión de memoria compartida MIT (MIT " "Shared Memory).\n" -#: src/video_out/video_out_xshm.c:1167 +#: src/video_out/video_out_xshm.c:1170 msgid "video_out_xshm: MIT shared memory extension not present on display.\n" msgstr "" "video_out_xshm: la extensión de memoria compartida del MIT (MIT Shared " "Memory) no está presente en la pantalla.\n" -#: src/video_out/video_out_xshm.c:1251 +#: src/video_out/video_out_xshm.c:1254 msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n" msgstr "video_out_xshm: su modo de vídeoo no fué reconocido, lo siento :-(\n" @@ -4823,11 +4894,11 @@ msgstr "" "video_out_xv: => no usando la extensión de memoria compartida MIT (MIT " "Shared Memory).\n" -#: src/video_out/video_out_xv.c:1336 +#: src/video_out/video_out_xv.c:1348 msgid "video_out_xv: Xv extension not present.\n" msgstr "video_out_xv: la extensión Xv no está presente.\n" -#: src/video_out/video_out_xv.c:1373 +#: src/video_out/video_out_xv.c:1385 msgid "" "video_out_xv: Xv extension is present but I couldn't find a usable yuv12 " "port.\n" @@ -4837,7 +4908,7 @@ msgstr "" "puerto yuv12 usable.\n" " ¡¿Parece que su driver de hardware gráfico no soporta Xv?!\n" -#: src/video_out/video_out_xv.c:1382 +#: src/video_out/video_out_xv.c:1394 #, c-format msgid "" "video_out_xv: using Xv port %ld from adaptor %s for hardware colour space " @@ -4846,23 +4917,23 @@ msgstr "" "video_out_xv: usando puerto Xv %ld del adaptador %s para conversión y " "escalado de espacio de color en hardware .\n" -#: src/video_out/video_out_xv.c:1557 +#: src/video_out/video_out_xv.c:1569 msgid "video_out_xv: this adaptor supports the yv12 format.\n" msgstr "video_out_xv: éste adaptador soporta el formato yv12.\n" -#: src/video_out/video_out_xv.c:1562 +#: src/video_out/video_out_xv.c:1574 msgid "video_out_xv: this adaptor supports the yuy2 format.\n" msgstr "video_out_xv: éste adaptador soporta el formato yuy2.\n" -#: src/video_out/video_out_xvmc.c:1591 +#: src/video_out/video_out_xvmc.c:1610 msgid "xine video output plugin using the XvMC X video extension" msgstr "complemento de vídeo de xine usando extensión de vídeo X XvMC" -#: src/video_out/video_out_xvmc.c:1637 +#: src/video_out/video_out_xvmc.c:1656 msgid "video_out_xvmc: XvMC extension not present.\n" msgstr "video_out_xvmc: extensión XvMC no presente.\n" -#: src/video_out/video_out_xvmc.c:1735 +#: src/video_out/video_out_xvmc.c:1754 msgid "" "video_out_xvmc: Xv extension is present but I couldn't find a usable yuv12 " "port.\n" @@ -4870,7 +4941,7 @@ msgstr "" "video_out_xvmc: la extensión Xv está presente pero no pude encontrar un " "puerto yuv12 usable.\n" -#: src/video_out/video_out_xvmc.c:1744 +#: src/video_out/video_out_xvmc.c:1763 #, c-format msgid "" "video_out_xvmc: using Xv port %ld from adaptor %s\n" @@ -4879,19 +4950,19 @@ msgstr "" "video_out_xvmc: usando puerto %ld de Xv del adaptador %s\n" " para conversión del espacio de color y escalado en hardware\n" -#: src/video_out/video_out_xvmc.c:1749 +#: src/video_out/video_out_xvmc.c:1768 msgid " idct and motion compensation acceleration \n" msgstr " compensación de movimiento y aceleración idct \n" -#: src/video_out/video_out_xvmc.c:1751 +#: src/video_out/video_out_xvmc.c:1770 msgid " motion compensation acceleration only\n" msgstr " sólo compensación de aceleración \n" -#: src/video_out/video_out_xvmc.c:1753 +#: src/video_out/video_out_xvmc.c:1772 msgid " no XvMC support \n" msgstr " sin soporte XvMC \n" -#: src/video_out/video_out_xvmc.c:1754 +#: src/video_out/video_out_xvmc.c:1773 #, c-format msgid " With Overlay = %d; UnsignedIntra = %d.\n" msgstr " Con Overlay = %d; UnsignedIntra = %d.\n" @@ -4934,11 +5005,11 @@ msgstr "" "video_out_xxmc: => no se usará la extensión \"MIT Shared Memory\" (memoria " "compartida MIT).\n" -#: src/video_out/video_out_xxmc.c:2380 +#: src/video_out/video_out_xxmc.c:2392 msgid "video_out_xxmc: Xv extension not present.\n" msgstr "video_out_xxmc: extensión Xv no presente.\n" -#: src/video_out/video_out_xxmc.c:2417 +#: src/video_out/video_out_xxmc.c:2429 msgid "" "video_out_xxmc: Xv extension is present but I couldn't find a usable yuv12 " "port.\n" @@ -4949,7 +5020,7 @@ msgstr "" " ¿Parece como que su driver de hardware gráfico no soporta " "Xv?!\n" -#: src/video_out/video_out_xxmc.c:2426 +#: src/video_out/video_out_xxmc.c:2438 #, c-format msgid "" "video_out_xxmc: using Xv port %ld from adaptor %s for hardware colour space " @@ -4958,19 +5029,19 @@ msgstr "" "video_out_xxmc: usando el puerto %ld de Xv del adaptador %s para conversión " "y escalado del espacio de color en hardware.\n" -#: src/video_out/video_out_xxmc.c:2602 +#: src/video_out/video_out_xxmc.c:2614 msgid "video_out_xxmc: this adaptor supports the yv12 format.\n" msgstr "video_out_xxmc: éste adaptador soporta el formato yv12.\n" -#: src/video_out/video_out_xxmc.c:2607 +#: src/video_out/video_out_xxmc.c:2619 msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n" msgstr "video_out_xxmc: éste adaptador soporta el formato yuy2.\n" -#: src/video_out/video_out_xxmc.c:2636 +#: src/video_out/video_out_xxmc.c:2648 msgid "Make XvMC allocate more frames for better buffering." msgstr "Hacer que XvMC ubique más cuadros more cuadros para mejor tamponeado." -#: src/video_out/video_out_xxmc.c:2637 +#: src/video_out/video_out_xxmc.c:2649 msgid "" "Some XvMC implementations allow more than 8 frames.\n" "This option, when turned on, makes the driver try to\n" @@ -4980,11 +5051,11 @@ msgstr "" "Esta opción, cuando se activa, hace que el manejador trate de\n" "ubicar 15 cuadros. hay que tenerlo para VDR uni cromático y en vivo.\n" -#: src/video_out/video_out_xxmc.c:2643 +#: src/video_out/video_out_xxmc.c:2655 msgid "Unichrome cpu save" msgstr "Ahorro de cpu unichrome" -#: src/video_out/video_out_xxmc.c:2644 +#: src/video_out/video_out_xxmc.c:2656 msgid "" "Saves CPU time by sleeping while decoder works.\n" "Only for Linux kernel 2.6 series or 2.4 with multimedia patch.\n" @@ -4994,11 +5065,11 @@ msgstr "" "Sólo para Linux con kernel serie 2.6 series o 2.4 con parche multimedia.\n" "Experimental.\n" -#: src/video_out/video_out_xxmc.c:2650 +#: src/video_out/video_out_xxmc.c:2662 msgid "Fix buggy NVIDIA XvMC subpicture colours" msgstr "Arreglar colores de subimagen en NVIDIA XvMC con errores" -#: src/video_out/video_out_xxmc.c:2651 +#: src/video_out/video_out_xxmc.c:2663 msgid "" "There's a bug in NVIDIA's XvMC lib that makes red OSD colours\n" "look blue and vice versa. This option provides a workaround.\n" @@ -5007,11 +5078,11 @@ msgstr "" "rojo en el DEP aparezca como azul y viceversa.\n" "Esta opción proporciona un arreglo.\n" -#: src/video_out/video_out_xxmc.c:2656 +#: src/video_out/video_out_xxmc.c:2668 msgid "Use bob as accelerated deinterlace method." msgstr "Use «bob» como método acelerado de desentrelazado." -#: src/video_out/video_out_xxmc.c:2657 +#: src/video_out/video_out_xxmc.c:2669 msgid "" "When interlacing is enabled for hardware accelerated frames,\n" "alternate between top and bottom field at double the frame rate.\n" @@ -5020,11 +5091,11 @@ msgstr "" "en hardware, alterna entre el campo superior e inferior \n" "al doble de la frecuencia de cuadro.\n" -#: src/video_out/video_out_xxmc.c:2663 +#: src/video_out/video_out_xxmc.c:2675 msgid "Don't use bob deinterlacing for progressive frames." msgstr "No usar desentrelazado «bob» para cuadros progresivos." -#: src/video_out/video_out_xxmc.c:2664 +#: src/video_out/video_out_xxmc.c:2676 msgid "" "Progressive frames don't need deinterlacing, so disabling it on\n" "demand should result in a better picture.\n" @@ -5032,12 +5103,12 @@ msgstr "" "Los cuadros progresivos no necesitan desentrelazado, de manera\n" "que desentrelazarlos bajo demanda no resultará en una mejor imagen.\n" -#: src/video_out/video_out_xxmc.c:2670 +#: src/video_out/video_out_xxmc.c:2682 msgid "Don't use bob deinterlacing while a scaled OSD is active." msgstr "" "No usar desentrelazado «bob» mientras una escalado de VEP (OSD) está activo." -#: src/video_out/video_out_xxmc.c:2671 +#: src/video_out/video_out_xxmc.c:2683 msgid "" "Bob deinterlacing adds some noise to horizontal lines, so disabling it\n" "on demand should result in a better OSD picture.\n" @@ -5112,36 +5183,36 @@ msgstr "" "entradas poco fiables, pero también aumentan la latencia y el consumo de " "memoria." -#: src/xine-engine/audio_out.c:1109 +#: src/xine-engine/audio_out.c:1110 msgid "" "audio_out: delay calculation impossible with an unavailable audio device\n" msgstr "" "audio_out: cálculo de retardo imposible con un dispositivo de sonido no " "disponible\n" -#: src/xine-engine/audio_out.c:1248 +#: src/xine-engine/audio_out.c:1249 msgid "write to sound card failed. Assuming the device was unplugged.\n" msgstr "" "la escritura a la tarjeta de sonido falló. Supondremos que el dispositivo se " "desconectó.\n" -#: src/xine-engine/audio_out.c:1420 +#: src/xine-engine/audio_out.c:1421 msgid "8 bits not supported by driver, converting to 16 bits.\n" msgstr "8 bits no soportados por el driver, convirtiendo a 16 bits.\n" -#: src/xine-engine/audio_out.c:1428 +#: src/xine-engine/audio_out.c:1429 msgid "mono not supported by driver, converting to stereo.\n" msgstr "mono no soportado por el driver, convirtiendo a estéreo.\n" -#: src/xine-engine/audio_out.c:1434 +#: src/xine-engine/audio_out.c:1435 msgid "stereo not supported by driver, converting to mono.\n" msgstr "estéreo no soportado por el driver, convirtiendo a mono.\n" -#: src/xine-engine/audio_out.c:2093 +#: src/xine-engine/audio_out.c:2098 msgid "method to sync audio and video" msgstr "método para sincronizar audio y vídeo" -#: src/xine-engine/audio_out.c:2094 +#: src/xine-engine/audio_out.c:2099 msgid "" "When playing audio and video, there are at least two clocks involved: The " "system clock, to which video frames are synchronized and the clock in your " @@ -5183,11 +5254,11 @@ msgstr "" "audio. Esto no funciona para para paso a través digital, donde los datos de " "audio se pasan a un decodificador externo en forma digital." -#: src/xine-engine/audio_out.c:2122 +#: src/xine-engine/audio_out.c:2127 msgid "enable resampling" msgstr "activar remuestreo (resampling)" -#: src/xine-engine/audio_out.c:2123 +#: src/xine-engine/audio_out.c:2128 msgid "" "When the sample rate of the decoded audio does not match the capabilities of " "your sound hardware, an adaptation called \"resampling\" is required. Here " @@ -5199,11 +5270,11 @@ msgstr "" "\"remuestreo\". Aquí puede seleccionar si se activa el remuestreo, se " "desactiva, o se usa automáticamente cuando sea necesario." -#: src/xine-engine/audio_out.c:2130 +#: src/xine-engine/audio_out.c:2135 msgid "always resample to this rate (0 to disable)" msgstr "siempre remuestrear a ésta cadencia (0 para desactivar)" -#: src/xine-engine/audio_out.c:2131 +#: src/xine-engine/audio_out.c:2136 msgid "" "Some audio drivers do not correctly announce the capabilities of the audio " "hardware. By setting a value other than zero here, you can force the audio " @@ -5213,11 +5284,11 @@ msgstr "" "hardware de audio. Poniendo este valor a algo distinto de cero aquí, puede " "forzar el flujo de datos de audio a ser remuestreado a la cadencia dada." -#: src/xine-engine/audio_out.c:2140 +#: src/xine-engine/audio_out.c:2145 msgid "offset for digital passthrough" msgstr "compensación para paso a través digital" -#: src/xine-engine/audio_out.c:2141 +#: src/xine-engine/audio_out.c:2146 msgid "" "If you use an external surround decoder and audio is ahead or behind video, " "you can enter a fixed offset here to compensate.\n" @@ -5228,11 +5299,11 @@ msgstr "" "para compensar.\n" "Las unidades del valor es una marca PTS, que es 1/90000 segundo." -#: src/xine-engine/audio_out.c:2150 +#: src/xine-engine/audio_out.c:2155 msgid "play audio even on slow/fast speeds" msgstr "reproduzca vídeo incluso a velocidades lentas/rápidas" -#: src/xine-engine/audio_out.c:2151 +#: src/xine-engine/audio_out.c:2156 msgid "" "If you enable this option, the audio will be heard even when playback speed " "is different than 1X. Of course, it will sound distorted (lower/higher " @@ -5244,24 +5315,24 @@ msgstr "" "grave). Si desea experimentar preservando el tono, puede probar el " "postcomplemento de sonido 'stretch' en su lugar." -#: src/xine-engine/audio_out.c:2224 +#: src/xine-engine/audio_out.c:2229 msgid "startup audio volume" msgstr "volumen de audio inicial" -#: src/xine-engine/audio_out.c:2225 +#: src/xine-engine/audio_out.c:2230 msgid "The overall audio volume set at xine startup." msgstr "El volumen de sonido al arrancar xine." -#: src/xine-engine/audio_out.c:2228 +#: src/xine-engine/audio_out.c:2233 msgid "restore volume level at startup" msgstr "restaurar el nivel del volumen al arrancar" -#: src/xine-engine/audio_out.c:2229 +#: src/xine-engine/audio_out.c:2234 msgid "If disabled, xine will not modify any mixer settings at startup." msgstr "" "Si se desactiva, xine no modificará ningún ajuste del mezclador al arrancar." -#: src/xine-engine/audio_out.c:2259 +#: src/xine-engine/audio_out.c:2264 msgid "audio_out: sorry, this should not happen. please restart xine.\n" msgstr "" "audio_out: lo siento, ésto no debiera ocurrir. Por favor reinicie xine.\n" @@ -5291,23 +5362,23 @@ msgstr "" msgid "configfile: WARNING: your configuration will not be saved\n" msgstr "configfile: AVISO: su configuración no será guardada\n" -#: src/xine-engine/configfile.c:1138 +#: src/xine-engine/configfile.c:1139 #, c-format msgid "configfile: WARNING: writing configuration to %s failed\n" msgstr "configfile: AVISO: la escritura de la configuración a %s falló\n" -#: src/xine-engine/configfile.c:1139 +#: src/xine-engine/configfile.c:1140 #, c-format msgid "configfile: WARNING: removing possibly broken config file %s\n" msgstr "" "configfile: AVISO: eliminando fichero de configuración %s posiblemente roto\n" -#: src/xine-engine/configfile.c:1140 +#: src/xine-engine/configfile.c:1141 #, c-format msgid "configfile: WARNING: you should check the backup file %s\n" msgstr "configfile: AVISO: debería comprobar el fichero de respaldo %s\n" -#: src/xine-engine/configfile.c:1275 +#: src/xine-engine/configfile.c:1276 #, c-format msgid "configfile: entry '%s' mustn't be modified from MRL\n" msgstr "configfile: la entrada '%s' no debería ser modificada desde MRL\n" @@ -5354,7 +5425,7 @@ msgstr "input_rip: error escribiendo al fichero %<PRIdMAX> bytes: %s\n" #: src/xine-engine/input_rip.c:182 #, c-format msgid "input_rip: open() function should never be called\n" -msgstr "" +msgstr "input_rip: la función open() no debería ser llamada nunca\n" #: src/xine-engine/input_rip.c:313 src/xine-engine/input_rip.c:418 #, c-format @@ -5700,21 +5771,21 @@ msgstr "" "que no especifican ningún coloreado ellos mismos. Las paletas se listan en " "la forma:frente-borde-fondo." -#: src/xine-engine/video_decoder.c:377 +#: src/xine-engine/video_decoder.c:387 #, c-format msgid "video_decoder: no plugin available to handle '%s'\n" msgstr "video_decoder: no hay complemento disponible para manejar '%s'\n" -#: src/xine-engine/video_decoder.c:456 +#: src/xine-engine/video_decoder.c:466 #, c-format msgid "video_decoder: error, unknown buffer type: %08x\n" msgstr "video_decoder: error, tipo de tampón desconocido: %08x\n" -#: src/xine-engine/video_decoder.c:492 +#: src/xine-engine/video_decoder.c:502 msgid "number of video buffers" msgstr "número de tampones de vídeo" -#: src/xine-engine/video_decoder.c:493 +#: src/xine-engine/video_decoder.c:503 msgid "" "The number of video buffers (each is 8k in size) xine uses in its internal " "queue. Higher values mean smoother playback for unreliable inputs, but also " @@ -5725,12 +5796,12 @@ msgstr "" "entradas poco fiables, pero también aumentan la latencia y el consumo de " "memoria." -#: src/xine-engine/video_out.c:640 +#: src/xine-engine/video_out.c:666 #, c-format msgid "%d frames delivered, %d frames skipped, %d frames discarded\n" msgstr "%d marcos entregados, %d cuadros omitidos, %d cuadros descartados\n" -#: src/xine-engine/video_out.c:813 +#: src/xine-engine/video_out.c:839 #, c-format msgid "" "video_out: throwing away image with pts %<PRId64> because it's too old " @@ -5739,11 +5810,11 @@ msgstr "" "video_out: tirando la imagen con pts %<PRId64> porque es demasiado vieja " "(diff : %<PRId64>).\n" -#: src/xine-engine/video_out.c:1793 +#: src/xine-engine/video_out.c:1817 msgid "default number of video frames" msgstr "número por defecto de marcos de vídeo" -#: src/xine-engine/video_out.c:1794 +#: src/xine-engine/video_out.c:1818 msgid "" "The default number of video frames to request from xine video out driver. " "Some drivers will override this setting with their own values." @@ -5751,11 +5822,11 @@ msgstr "" "El número por omisión de cuadros de vídeo a pedir del manejador de vídeo de " "salida. Algunos manejadores invalidará este ajuste con sus propios valores." -#: src/xine-engine/video_out.c:1833 +#: src/xine-engine/video_out.c:1875 msgid "percentage of skipped frames to tolerate" msgstr "porcentaje de cuadros omitidos a tolerar" -#: src/xine-engine/video_out.c:1834 +#: src/xine-engine/video_out.c:1876 msgid "" "When more than this percentage of frames are not shown, because they were " "not decoded in time, xine sends a notification." @@ -5763,11 +5834,11 @@ msgstr "" "Cuando más de este porcentaje de cuadros no sean mostrados, porque no fueron " "decodificados a tiempo, xine envía una notificación." -#: src/xine-engine/video_out.c:1839 +#: src/xine-engine/video_out.c:1881 msgid "percentage of discarded frames to tolerate" msgstr "porcentaje de cuadros descartados a tolerar" -#: src/xine-engine/video_out.c:1840 +#: src/xine-engine/video_out.c:1882 msgid "" "When more than this percentage of frames are not shown, because they were " "not scheduled for display in time, xine sends a notification." @@ -5775,7 +5846,7 @@ msgstr "" "Cuando más de este porcentaje de cuadros no sean mostrados, porque no fueron " "programados para su visualización a tiempo, xine envía una notificación." -#: src/xine-engine/video_out.c:1874 +#: src/xine-engine/video_out.c:1916 msgid "video_out: sorry, this should not happen. please restart xine.\n" msgstr "" "video_out: Lo siento, esto no debería ocurrir. Por favor, reinicie xine.\n" @@ -5837,139 +5908,139 @@ msgstr "" "imagen no está acelerado en hardware, esto puede reducir drásticamente el " "uso de cpu." -#: src/xine-engine/xine.c:789 src/xine-engine/xine.c:896 -#: src/xine-engine/xine.c:935 src/xine-engine/xine.c:971 -#: src/xine-engine/xine.c:983 src/xine-engine/xine.c:996 -#: src/xine-engine/xine.c:1009 src/xine-engine/xine.c:1022 -#: src/xine-engine/xine.c:1048 src/xine-engine/xine.c:1073 -#: src/xine-engine/xine.c:1108 +#: src/xine-engine/xine.c:802 src/xine-engine/xine.c:909 +#: src/xine-engine/xine.c:949 src/xine-engine/xine.c:985 +#: src/xine-engine/xine.c:997 src/xine-engine/xine.c:1010 +#: src/xine-engine/xine.c:1023 src/xine-engine/xine.c:1036 +#: src/xine-engine/xine.c:1062 src/xine-engine/xine.c:1087 +#: src/xine-engine/xine.c:1124 msgid "xine: error while parsing mrl\n" msgstr "xine: error mientras se interpretaba mrl\n" -#: src/xine-engine/xine.c:831 +#: src/xine-engine/xine.c:844 #, c-format msgid "xine: found input plugin : %s\n" msgstr "xine: encontrado complemento de entrada : %s\n" -#: src/xine-engine/xine.c:848 +#: src/xine-engine/xine.c:861 #, c-format msgid "xine: input plugin cannot open MRL [%s]\n" msgstr "xine: el complemento de entrada no puede abrir el MRL [%s]\n" -#: src/xine-engine/xine.c:859 +#: src/xine-engine/xine.c:872 #, c-format msgid "xine: cannot find input plugin for MRL [%s]\n" msgstr "xine: no se puede encontrar el complemento de entrada para MRL [%s]\n" -#: src/xine-engine/xine.c:885 +#: src/xine-engine/xine.c:898 #, c-format msgid "xine: specified demuxer %s failed to start\n" msgstr "xine: fallo al iniciar el demultiplexor %s especificado\n" # cer: ¿join rip? -#: src/xine-engine/xine.c:921 +#: src/xine-engine/xine.c:935 #, c-format msgid "xine: join rip input plugin\n" msgstr "xine: complemento de entrada join rip \n" -#: src/xine-engine/xine.c:928 +#: src/xine-engine/xine.c:942 msgid "xine: error opening rip input plugin instance\n" msgstr "xine: error al abrir instancia de complemento de entrada rip\n" -#: src/xine-engine/xine.c:959 +#: src/xine-engine/xine.c:973 #, c-format msgid "xine: last_probed demuxer %s failed to start\n" msgstr "" "xine: el último demultiplexor probado (last_probed) %s no consiguió " "iniciarse \n" -#: src/xine-engine/xine.c:988 +#: src/xine-engine/xine.c:1002 msgid "ignoring video\n" msgstr "ignorando vídeo\n" -#: src/xine-engine/xine.c:1001 +#: src/xine-engine/xine.c:1015 msgid "ignoring audio\n" msgstr "ignorando audio\n" -#: src/xine-engine/xine.c:1014 +#: src/xine-engine/xine.c:1028 msgid "ignoring subpicture\n" msgstr "ignorando subimagen\n" -#: src/xine-engine/xine.c:1027 +#: src/xine-engine/xine.c:1041 msgid "input cache plugin disabled\n" msgstr "caché del complemento de entrada desactivado\n" -#: src/xine-engine/xine.c:1098 +#: src/xine-engine/xine.c:1114 #, c-format msgid "subtitle mrl opened '%s'\n" msgstr "abierto mrl de subtítulos '%s'\n" -#: src/xine-engine/xine.c:1102 +#: src/xine-engine/xine.c:1118 msgid "xine: error opening subtitle mrl\n" msgstr "xine: error abriendo mrl de subtítulos\n" -#: src/xine-engine/xine.c:1134 +#: src/xine-engine/xine.c:1150 #, c-format msgid "xine: error while parsing MRL\n" msgstr "xine: error al interpretar MRL\n" -#: src/xine-engine/xine.c:1141 +#: src/xine-engine/xine.c:1157 #, c-format msgid "xine: changing option '%s' from MRL isn't permitted\n" msgstr "xine: cambiar la ocpión '%s' del MRL no está permitido\n" -#: src/xine-engine/xine.c:1161 +#: src/xine-engine/xine.c:1177 #, c-format msgid "xine: couldn't find demux for >%s<\n" msgstr "xine: no se pudo encontrar un demultiplexor para >%s<\n" -#: src/xine-engine/xine.c:1177 +#: src/xine-engine/xine.c:1193 #, c-format msgid "xine: found demuxer plugin: %s\n" msgstr "xine: encontrado complemento demultiplexor: %s\n" -#: src/xine-engine/xine.c:1198 -#, fuzzy, c-format +#: src/xine-engine/xine.c:1214 +#, c-format msgid "xine: demuxer is already done. that was fast!\n" -msgstr "xine: fallo al iniciar el demultiplexor\n" +msgstr "xine: el demultiplexor ya ha terminado, ¡eso fué rápido\n" -#: src/xine-engine/xine.c:1200 +#: src/xine-engine/xine.c:1216 #, c-format msgid "xine: demuxer failed to start\n" msgstr "xine: fallo al iniciar el demultiplexor\n" -#: src/xine-engine/xine.c:1266 +#: src/xine-engine/xine.c:1282 #, c-format msgid "xine_play: no demux available\n" msgstr "xine_play: no hay disponible un demultiplexor\n" -#: src/xine-engine/xine.c:1336 +#: src/xine-engine/xine.c:1352 #, c-format msgid "xine_play: demux failed to start\n" msgstr "xine_play: fallo al iniciar el demultiplexor\n" -#: src/xine-engine/xine.c:1612 +#: src/xine-engine/xine.c:1628 #, c-format msgid "xine: The specified save_dir \"%s\" might be a security risk.\n" msgstr "" "xine: El directorio (save_dir) especificado \"%s\" pudiera ser un riesgo " "para la seguridad.\n" -#: src/xine-engine/xine.c:1617 +#: src/xine-engine/xine.c:1633 msgid "The specified save_dir might be a security risk." msgstr "" "El directorio (save_dir) especificado pudiera ser un riesgo para la " "seguridad." -#: src/xine-engine/xine.c:1643 +#: src/xine-engine/xine.c:1659 msgid "xine: locale not supported by C library\n" msgstr "xine: \"locale\" no soportada por la librería de C\n" -#: src/xine-engine/xine.c:1652 +#: src/xine-engine/xine.c:1668 msgid "media format detection strategy" msgstr "estrategia de detecciónde formato" -#: src/xine-engine/xine.c:1653 +#: src/xine-engine/xine.c:1669 msgid "" "xine offers various methods to detect the media format of input to play. The " "individual values are:\n" @@ -6003,11 +6074,11 @@ msgstr "" "extension\n" "Detectar sólo por la extensión del nombre del fichero.\n" -#: src/xine-engine/xine.c:1671 +#: src/xine-engine/xine.c:1687 msgid "directory for saving streams" msgstr "directorio para guardar flujos de bits" -#: src/xine-engine/xine.c:1672 +#: src/xine-engine/xine.c:1688 msgid "" "When using the stream save feature, files will be written only into this " "directory.\n" @@ -6023,11 +6094,11 @@ msgstr "" "arbitrario. Así que debiera ser cuidadoso que el directorio especificado sea " "robusto contra cualquier contenido en cualquier fichero." -#: src/xine-engine/xine.c:1683 +#: src/xine-engine/xine.c:1699 msgid "allow implicit changes to the configuration (e.g. by MRL)" msgstr "permitir cambios implícitos a la configuración (p.e. por MRL)" -#: src/xine-engine/xine.c:1684 +#: src/xine-engine/xine.c:1700 msgid "" "If enabled, you allow xine to change your configuration without explicit " "actions from your side. For example configuration changes demanded by MRLs " @@ -6044,11 +6115,11 @@ msgstr "" "arbitrariamente cambiar su configuración, usted podría acabar con un xine " "totalmente enredado." -#: src/xine-engine/xine.c:1698 +#: src/xine-engine/xine.c:1714 msgid "Timeout for network stream reading (in seconds)" msgstr "Temporización para lectura de flujos de bits desde red (en segundos)" -#: src/xine-engine/xine.c:1699 +#: src/xine-engine/xine.c:1715 msgid "" "Specifies the timeout when reading from network streams, in seconds. Too low " "values might stop streaming when the source is slow or the bandwidth is " @@ -6059,15 +6130,15 @@ msgstr "" "fuente es lenta o el ancho de banda está ocupado; valores demasiado altos " "congelarán el reproductor si se pierde la conexión." -#: src/xine-engine/xine.c:2051 +#: src/xine-engine/xine.c:2067 msgid "messages" msgstr "mensajes" -#: src/xine-engine/xine.c:2052 +#: src/xine-engine/xine.c:2068 msgid "plugin" msgstr "complemento" -#: src/xine-engine/xine.c:2053 +#: src/xine-engine/xine.c:2069 msgid "trace" msgstr "traza" @@ -6141,6 +6212,3 @@ msgstr "" #: src/xine-utils/memcpy.c:507 msgid "Benchmarking memcpy methods (smaller is better):\n" msgstr "Evaluando métodos \"memcpy\" (menor es mejor):\n" - -#~ msgid "demux_asf: Wrong ASX version: %s\n" -#~ msgstr "demux_asf: Versión ASX equivocada: %s\n" -- cgit v1.2.3 From 94d689190ecd84ab3f09e73572396566e730a6f5 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Thu, 31 Jan 2008 23:49:18 +0000 Subject: Revert xine-config dist_bin & EXTRA_DIST changes due to changes in 1.1. --- misc/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/misc/Makefile.am b/misc/Makefile.am index 835f92f54..7e82bec87 100644 --- a/misc/Makefile.am +++ b/misc/Makefile.am @@ -6,13 +6,14 @@ EXTRA_DIST = build_rpms.sh \ SlackBuild.in \ SlackBuild \ vga.xinefont.gz \ + xine-config \ xine-lib.spec.in \ xine-lib.spec \ libxine.pc.in \ libdvdcss-1.2.6-network.patch \ Makefile.common -dist_bin_SCRIPTS = xine-config +bin_SCRIPTS = xine-config pkgconfigdir=$(libdir)/pkgconfig pkgconfig_DATA=libxine.pc -- cgit v1.2.3 From 72abc5e53ea918cdf2813a722e14760d8e797b3d Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Fri, 1 Feb 2008 00:01:12 +0000 Subject: Back out vcd build changes: separate unit (though used only once). Also, built files don't end up in the vcd directory. --- configure.ac | 1 + src/input/Makefile.am | 17 +++++------------ src/input/vcd/Makefile.am | 13 +++++++++++++ 3 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 src/input/vcd/Makefile.am diff --git a/configure.ac b/configure.ac index 77190b58a..aa9294780 100644 --- a/configure.ac +++ b/configure.ac @@ -1181,6 +1181,7 @@ src/input/Makefile src/input/libdvdnav/Makefile src/input/librtsp/Makefile src/input/libreal/Makefile +src/input/vcd/Makefile src/libw32dll/Makefile src/libw32dll/wine/Makefile src/libw32dll/DirectShow/Makefile diff --git a/src/input/Makefile.am b/src/input/Makefile.am index 64ba0ce54..ca7e6dabd 100644 --- a/src/input/Makefile.am +++ b/src/input/Makefile.am @@ -11,6 +11,9 @@ AM_LDFLAGS = $(xineplug_ldflags) # SUBDIRS = libreal librtsp +if ENABLE_VCD +SUBDIRS += vcd +endif if !WITH_EXTERNAL_DVDNAV SUBDIRS += libdvdnav endif @@ -18,16 +21,13 @@ endif noinst_HEADERS = net_buf_ctrl.h mms.h mmsh.h pnm.h media_helper.h http_helper.h + if ENABLE_DVB in_dvb = xineplug_inp_dvb.la endif -if ENABLE_VCD -in_vcd = xineplug_inp_vcd.la -endif - if ENABLE_VCDO -in_vcdo = xineplug_inp_vcdo.la +in_vcd = xineplug_inp_vcdo.la endif if ENABLE_V4L @@ -62,7 +62,6 @@ xineplug_LTLIBRARIES = \ xineplug_inp_http.la \ xineplug_inp_dvd.la \ $(in_vcd) \ - $(in_vcdo) \ $(in_v4l) \ $(in_gnome_vfs) \ $(in_smb) \ @@ -93,12 +92,6 @@ xineplug_inp_mms_la_LIBADD = $(XINE_LIB) $(LTLIBICONV) $(PTHREAD_LIBS) $(LTLIBIN xineplug_inp_vcdo_la_SOURCES = input_vcd.c media_helper.c xineplug_inp_vcdo_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) -xineplug_inp_vcd_la_SOURCES = vcd/xineplug_inp_vcd.c vcd/vcdplayer.c \ - vcd/vcdio.c vcd/xine-extra.c vcd/vcdio.h \ - vcd/vcdplayer.h vcd/xine-extra.h -xineplug_inp_vcd_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) $(LIBCDIO_LIBS) $(LIBVCD_LIBS) $(LIBVCDINFO_LIBS) $(LIBISO9660_LIBS) -lm -xineplug_inp_vcd_la_CFLAGS = $(AM_CFLAGS) $(LIBCDIO_CFLAGS) $(LIBVCD_CFLAGS) - xineplug_inp_stdin_fifo_la_SOURCES = input_stdin_fifo.c net_buf_ctrl.c xineplug_inp_stdin_fifo_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) diff --git a/src/input/vcd/Makefile.am b/src/input/vcd/Makefile.am new file mode 100644 index 000000000..2b47415fd --- /dev/null +++ b/src/input/vcd/Makefile.am @@ -0,0 +1,13 @@ +include $(top_srcdir)/misc/Makefile.common + +AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) +AM_LDFLAGS = $(xineplug_ldflags) + +noinst_HEADERS = vcdio.h vcdplayer.h xine-extra.h + +xineplug_LTLIBRARIES = xineplug_inp_vcd.la + +xineplug_inp_vcd_la_SOURCES = xineplug_inp_vcd.c vcdplayer.c vcdio.c xine-extra.c +xineplug_inp_vcd_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) $(LIBCDIO_LIBS) $(LIBVCD_LIBS) $(LIBVCDINFO_LIBS) $(LIBISO9660_LIBS) -lm +xineplug_inp_vcd_la_DEPENDENCIES = $(LIBCDIO_DEPS) $(LIBVCD_DEPS) $(LIBVCDINFO_DEPS) $(LIBISO9660_DEPS) +xineplug_inp_vcd_la_CFLAGS = $(AM_CFLAGS) $(LIBCDIO_CFLAGS) $(LIBVCD_CFLAGS) -- cgit v1.2.3 From 07c2e149c38b01494d2a0d42b705750ebd127287 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Fri, 1 Feb 2008 00:03:19 +0000 Subject: Back out rtsp build changes: separate units (though used only once). Also, built files don't end up in the lib directories. --- configure.ac | 2 ++ src/input/Makefile.am | 14 ++++---------- src/input/libreal/Makefile.am | 10 ++++++++++ src/input/librtsp/Makefile.am | 10 ++++++++++ 4 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 src/input/libreal/Makefile.am create mode 100644 src/input/librtsp/Makefile.am diff --git a/configure.ac b/configure.ac index 8c6a8cffe..77190b58a 100644 --- a/configure.ac +++ b/configure.ac @@ -1179,6 +1179,8 @@ src/demuxers/Makefile src/dxr3/Makefile src/input/Makefile src/input/libdvdnav/Makefile +src/input/librtsp/Makefile +src/input/libreal/Makefile src/libw32dll/Makefile src/libw32dll/wine/Makefile src/libw32dll/DirectShow/Makefile diff --git a/src/input/Makefile.am b/src/input/Makefile.am index 74aca7240..64ba0ce54 100644 --- a/src/input/Makefile.am +++ b/src/input/Makefile.am @@ -10,8 +10,9 @@ AM_LDFLAGS = $(xineplug_ldflags) # All of xine input plugins should be named like the scheme "xineplug_inp_" # +SUBDIRS = libreal librtsp if !WITH_EXTERNAL_DVDNAV -SUBDIRS = libdvdnav +SUBDIRS += libdvdnav endif @@ -115,15 +116,8 @@ xineplug_inp_dvb_la_DEPS = $(XDG_BASEDIR_DEPS) xineplug_inp_dvb_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) $(XDG_BASEDIR_LIBS) xineplug_inp_dvb_la_CPPFLAGS = $(AM_CPPFLAGS) $(XDG_BASEDIR_CPPFLAGS) -xineplug_inp_rtsp_la_SOURCES = input_rtsp.c net_buf_ctrl.c \ - librtsp/rtsp.c librtsp/rtsp_session.c \ - librtsp/rtsp.h librtsp/rtsp_session.h \ - libreal/real.c libreal/asmrp.c \ - libreal/rmff.c libreal/sdpplin.c \ - libreal/real.h libreal/asmrp.h \ - libreal/rmff.h libreal/sdpplin.h -xineplug_inp_rtsp_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/libreal -I$(srcdir)/librtsp -xineplug_inp_rtsp_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) +xineplug_inp_rtsp_la_SOURCES = input_rtsp.c net_buf_ctrl.c +xineplug_inp_rtsp_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) libreal/libreal.la librtsp/librtsp.la xineplug_inp_cdda_la_SOURCES = input_cdda.c media_helper.c sha1.c sha1.h xineplug_inp_cdda_la_DEPS = $(XDG_BASEDIR_DEPS) diff --git a/src/input/libreal/Makefile.am b/src/input/libreal/Makefile.am new file mode 100644 index 000000000..bd97a7548 --- /dev/null +++ b/src/input/libreal/Makefile.am @@ -0,0 +1,10 @@ +include $(top_srcdir)/misc/Makefile.common + +AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) +AM_CPPFLAGS = -I$(top_srcdir)/src/input/librtsp + +noinst_HEADERS = real.h asmrp.h rmff.h sdpplin.h + +noinst_LTLIBRARIES = libreal.la + +libreal_la_SOURCES = real.c asmrp.c rmff.c sdpplin.c diff --git a/src/input/librtsp/Makefile.am b/src/input/librtsp/Makefile.am new file mode 100644 index 000000000..68d554c2c --- /dev/null +++ b/src/input/librtsp/Makefile.am @@ -0,0 +1,10 @@ +include $(top_srcdir)/misc/Makefile.common + +AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) +AM_CPPFLAGS = -I$(top_srcdir)/src/input/libreal + +noinst_HEADERS = rtsp.h rtsp_session.h + +noinst_LTLIBRARIES = librtsp.la + +librtsp_la_SOURCES = rtsp.c rtsp_session.c -- cgit v1.2.3 From 55eb56b71ccdee084e3ef0e1c25118b0d111efa7 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Fri, 1 Feb 2008 00:24:20 +0000 Subject: Back out macosx build changes: separate units (so far unused). Also, built files don't end up in the lib directory. --- configure.ac | 1 + src/video_out/Makefile.am | 8 +------- src/video_out/macosx/Makefile.am | 12 ++++++++++++ 3 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 src/video_out/macosx/Makefile.am diff --git a/configure.ac b/configure.ac index ef55a27ee..b40f7ae75 100644 --- a/configure.ac +++ b/configure.ac @@ -1199,6 +1199,7 @@ src/spu_dec/Makefile src/video_dec/Makefile src/video_dec/libmpeg2/Makefile src/video_out/Makefile +src/video_out/macosx/Makefile src/xine-utils/Makefile src/xine-engine/Makefile src/vdr/Makefile diff --git a/src/video_out/Makefile.am b/src/video_out/Makefile.am index b661fdd4b..3b5703792 100644 --- a/src/video_out/Makefile.am +++ b/src/video_out/Makefile.am @@ -7,8 +7,7 @@ AM_OBJCFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) SUBDIRS = if ENABLE_MACOSX_VIDEO -xineinclude_HEADERS = macosx/video_window.h macosx/XineOpenGLView.h macosx/XineVideoWindow.h -lib_LTLIBRARIES = libxineMacOSXVideo.la +SUBDIRS += macosx endif EXTRA_DIST = video_out_directx.c video_out_macosx.m @@ -195,8 +194,3 @@ xineplug_vo_out_none_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) $(LTLIBINTL) xineplug_vo_out_macosx_la_SOURCES = video_out_macosx.m xineplug_vo_out_macosx_la_LIBADD = $(XINE_LIB) $(PTHREAD_LIBS) xineplug_vo_out_macosx_la_LDFLAGS = $(AM_LDFLAGS) -framework Cocoa -framework OpenGL - -libxineMacOSXVideo_la_SOURCES = macosx/XineOpenGLView.m macosx/XineVideoWindow.m -libxineMacOSXVideo_la_LDFLAGS = $(AM_LDFLAGS) -framework Cocoa \ - -framework OpenGL -version-info \ - $(XINE_LT_CURRENT):$(XINE_LT_REVISION):$(XINE_LT_AGE) diff --git a/src/video_out/macosx/Makefile.am b/src/video_out/macosx/Makefile.am new file mode 100644 index 000000000..ae6a5acc8 --- /dev/null +++ b/src/video_out/macosx/Makefile.am @@ -0,0 +1,12 @@ +include $(top_srcdir)/misc/Makefile.common + +AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) +AM_OBJCFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) + +xineinclude_HEADERS = video_window.h XineOpenGLView.h XineVideoWindow.h + +lib_LTLIBRARIES = libxineMacOSXVideo.la + +libxineMacOSXVideo_la_SOURCES = XineOpenGLView.m XineVideoWindow.m +libxineMacOSXVideo_la_LDFLAGS = $(AM_LDFLAGS) -framework Cocoa -framework OpenGL \ + -version-info $(XINE_LT_CURRENT):$(XINE_LT_REVISION):$(XINE_LT_AGE) -- cgit v1.2.3 From 83953bfe7440f1c99118da6716bc5f7b62013cfe Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Fri, 1 Feb 2008 00:57:19 +0000 Subject: Back out mpeg2 build changes: separate unit (though used only once). Also, built files don't end up in the lib directory. --- configure.ac | 1 + src/video_dec/Makefile.am | 20 +++----------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index 743eb9468..ef55a27ee 100644 --- a/configure.ac +++ b/configure.ac @@ -1197,6 +1197,7 @@ src/post/deinterlace/Makefile src/post/deinterlace/plugins/Makefile src/spu_dec/Makefile src/video_dec/Makefile +src/video_dec/libmpeg2/Makefile src/video_out/Makefile src/xine-utils/Makefile src/xine-engine/Makefile diff --git a/src/video_dec/Makefile.am b/src/video_dec/Makefile.am index 1b0fec998..91246eb4d 100644 --- a/src/video_dec/Makefile.am +++ b/src/video_dec/Makefile.am @@ -1,3 +1,5 @@ +SUBDIRS = libmpeg2 + include $(top_srcdir)/misc/Makefile.common AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) @@ -18,8 +20,7 @@ xineplug_LTLIBRARIES = $(image_module) \ $(theora_module) \ xineplug_decode_bitplane.la \ xineplug_decode_rgb.la \ - xineplug_decode_yuv.la \ - xineplug_decode_mpeg2.la + xineplug_decode_yuv.la xineplug_decode_bitplane_la_SOURCES = bitplane.c xineplug_decode_bitplane_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) @@ -37,18 +38,3 @@ xineplug_decode_image_la_CFLAGS = $(AM_CFLAGS) $(WAND_CFLAGS) xineplug_decode_gdk_pixbuf_la_SOURCES = gdkpixbuf.c xineplug_decode_gdk_pixbuf_la_LIBADD = $(XINE_LIB) $(DYNAMIC_LD_LIBS) $(GDK_PIXBUF_LIBS) xineplug_decode_gdk_pixbuf_la_CFLAGS = $(AM_CFLAGS) $(GDK_PIXBUF_CFLAGS) - -xineplug_decode_mpeg2_la_SOURCES = libmpeg2/cpu_state.c \ - libmpeg2/decode.c libmpeg2/header.c libmpeg2/idct.c \ - libmpeg2/idct_altivec.c libmpeg2/idct_mlib.c \ - libmpeg2/idct_mmx.c libmpeg2/motion_comp.c \ - libmpeg2/motion_comp_altivec.c libmpeg2/motion_comp_mmx.c \ - libmpeg2/motion_comp_mlib.c libmpeg2/motion_comp_vis.c \ - libmpeg2/slice.c libmpeg2/slice_xvmc.c \ - libmpeg2/slice_xvmc_vld.c libmpeg2/stats.c \ - libmpeg2/xine_mpeg2_decoder.c libmpeg2/libmpeg2_accel.c \ - libmpeg2/vlc.h libmpeg2/mpeg2.h libmpeg2/xvmc.h \ - libmpeg2/xvmc_vld.h libmpeg2/mpeg2_internal.h \ - libmpeg2/idct_mlib.h libmpeg2/vis.h libmpeg2/libmpeg2_accel.h -xineplug_decode_mpeg2_la_LIBADD = $(XINE_LIB) $(MLIB_LIBS) -lm -xineplug_decode_mpeg2_la_CFLAGS = $(AM_CFLAGS) $(MLIB_CFLAGS) -- cgit v1.2.3 From fabf7238464f5f4fd1d7dab99f4b7e6bb5d47a95 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Fri, 1 Feb 2008 00:57:32 +0000 Subject: Restore libmpeg2/Makefile.am. --- src/video_dec/libmpeg2/Makefile.am | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/video_dec/libmpeg2/Makefile.am diff --git a/src/video_dec/libmpeg2/Makefile.am b/src/video_dec/libmpeg2/Makefile.am new file mode 100644 index 000000000..2f7429942 --- /dev/null +++ b/src/video_dec/libmpeg2/Makefile.am @@ -0,0 +1,32 @@ +include $(top_srcdir)/misc/Makefile.common + +AM_CFLAGS = $(DEFAULT_OCFLAGS) $(VISIBILITY_FLAG) +AM_LDFLAGS = $(xineplug_ldflags) + +noinst_HEADERS = vlc.h mpeg2.h xvmc.h xvmc_vld.h mpeg2_internal.h idct_mlib.h vis.h \ + libmpeg2_accel.h + +xineplug_LTLIBRARIES = xineplug_decode_mpeg2.la + +xineplug_decode_mpeg2_la_SOURCES = \ + cpu_state.c \ + decode.c \ + header.c \ + idct.c \ + idct_altivec.c \ + idct_mlib.c \ + idct_mmx.c \ + motion_comp.c \ + motion_comp_altivec.c \ + motion_comp_mmx.c \ + motion_comp_mlib.c \ + motion_comp_vis.c \ + slice.c \ + slice_xvmc.c \ + slice_xvmc_vld.c \ + stats.c \ + xine_mpeg2_decoder.c \ + libmpeg2_accel.c + +xineplug_decode_mpeg2_la_LIBADD = $(XINE_LIB) $(MLIB_LIBS) -lm +xineplug_decode_mpeg2_la_CFLAGS = $(AM_CFLAGS) $(MLIB_CFLAGS) -- cgit v1.2.3 From 781a8d8e26d2f19f1910b53c92d89f28e6d0a181 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Fri, 1 Feb 2008 01:10:12 +0000 Subject: Tidy up header files list. --- include/Makefile.am | 54 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/include/Makefile.am b/include/Makefile.am index 3e6aae174..7f569f498 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -4,19 +4,47 @@ if GENERATED_INTTYPES_H inttypes_h = inttypes.h endif -nobase_include_HEADERS = xine.h xine/version.h xine/buffer.h \ - xine/metronom.h xine/configfile.h xine/vo_scale.h \ - xine/audio_out.h xine/resample.h xine/video_out.h \ - xine/xine_internal.h xine/spu_decoder.h xine/video_overlay.h \ - xine/osd.h xine/spu.h xine/scratch.h xine/xine_plugin.h \ - xine/xineintl.h xine/plugin_catalog.h xine/audio_decoder.h \ - xine/video_decoder.h xine/post.h xine/io_helper.h \ - xine/broadcaster.h xine/info_helper.h xine/refcounter.h \ - xine/alphablend.h xine/demux.h xine/input_plugin.h \ - xine/attributes.h xine/compat.h xine/xine_buffer.h \ - xine/xineutils.h xine/xmllexer.h xine/xmlparser.h xine/list.h \ - xine/array.h xine/sorted_array.h xine/pool.h \ - xine/ring_buffer.h xine/os_types.h xine/vdr.h +nobase_include_HEADERS = xine.h \ + xine/alphablend.h \ + xine/array.h \ + xine/attributes.h \ + xine/audio_decoder.h \ + xine/audio_out.h \ + xine/broadcaster.h \ + xine/buffer.h \ + xine/compat.h \ + xine/configfile.h \ + xine/demux.h \ + xine/info_helper.h \ + xine/input_plugin.h \ + xine/io_helper.h \ + xine/list.h \ + xine/metronom.h \ + xine/os_types.h \ + xine/osd.h \ + xine/plugin_catalog.h \ + xine/pool.h \ + xine/post.h \ + xine/refcounter.h \ + xine/resample.h \ + xine/ring_buffer.h \ + xine/scratch.h \ + xine/sorted_array.h \ + xine/spu.h \ + xine/spu_decoder.h \ + xine/vdr.h \ + xine/version.h \ + xine/video_decoder.h \ + xine/video_out.h \ + xine/video_overlay.h \ + xine/vo_scale.h \ + xine/xine_buffer.h \ + xine/xine_internal.h \ + xine/xine_plugin.h \ + xine/xineintl.h \ + xine/xineutils.h \ + xine/xmllexer.h \ + xine/xmlparser.h noinst_HEADERS = config.h configure.h -- cgit v1.2.3 From 9524b748a27734b4cdee2d348adfd0606abdedda Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Fri, 1 Feb 2008 01:11:22 +0000 Subject: Distribute version.sh (needed for re-running autoconf). --- Makefile.am | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile.am b/Makefile.am index 424bbcbaa..ee007a87d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -79,6 +79,9 @@ install-data-hook: $(top_srcdir)/post-install.sh ; \ fi +dist-hook: + cp -p $(srcdir)/version.sh $(distdir) + mostlyclean-generic: -rm -f *~ \#* .*~ .\#* -- cgit v1.2.3 From 190ab4b1f8724208ac846b96897df0469b8f4e59 Mon Sep 17 00:00:00 2001 From: "Carlos E. R." <carloser@users.sourceforge.net> Date: Thu, 31 Jan 2008 20:41:05 +0100 Subject: [translations] xine-lib-1.2 translation to Spanish --HG-- extra : transplant_source : 2n%8B%21Y%3C%05Nf%7F%CE%FCY%9Cy%D82%DD%2CD --- po/es.po | 1314 +++++++++++++++++++++++++------------------------------------- 1 file changed, 521 insertions(+), 793 deletions(-) diff --git a/po/es.po b/po/es.po index 2fd15527e..0b4c99fbe 100644 --- a/po/es.po +++ b/po/es.po @@ -1,18 +1,18 @@ -# translation of xine-lib-1.1.4.po to Spanish +# translation of xine-lib-1.2.hg.po to Spanish # Spanish .po file for xine-lib. -# Copyright (C) 2002, 2006, 2007 Free Software Foundation, Inc. +# Copyright (C) 2002, 2006, 2007, 2008 Free Software Foundation, Inc. # # Juan Manuel García Molina <juanma_gm@wanadoo.es>, 2002. -# Carlos E. Robinson M. <carloser@users.sourceforge.net>, 2006, 2007. +# Carlos E. Robinson M. <carloser@users.sourceforge.net>, 2006, 2007, 2008. # Cer: <<== marcas de revision. msgid "" msgstr "" -"Project-Id-Version: xine-lib-1.1.4\n" +"Project-Id-Version: xine-lib-1.2.hg\n" "Report-Msgid-Bugs-To: xine-devel@lists.sourceforge.net\n" -"POT-Creation-Date: 2008-01-06 21:08+0000\n" -"PO-Revision-Date: 2007-10-28 00:11+0200\n" -"Last-Translator: Carlos E. Robinson <carloser@users.sourceforge.net>\n" -"Language-Team: Spanish\n" +"POT-Creation-Date: 2008-02-01 01:17+0000\n" +"PO-Revision-Date: 2008-01-31 14:30+0100\n" +"Last-Translator: Carlos E. Robinson M. <carloser@users.sourceforge.net>\n" +"Language-Team: Spanish <none>\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" @@ -867,26 +867,25 @@ msgstr "" "encontrada.\n" #: src/combined/xine_ogg_demuxer.c:2080 -#, fuzzy msgid "Annodex demux plugin" -msgstr "xine: encontrado complemento demultiplexor: %s\n" +msgstr "Complemento demultiplexor annodex" -#: src/combined/xine_ogg_demuxer.c:2098 +#: src/combined/xine_ogg_demuxer.c:2104 msgid "OGG demux plugin" -msgstr "" +msgstr "Complemento demultiplexor OGG" -#: src/demuxers/demux_asf.c:426 +#: src/demuxers/demux_asf.c:441 #, c-format msgid "demux_asf: warning: The stream id=%d is encrypted.\n" msgstr "demux_asf: aviso: El flujo de bits (stream) id=%d está encriptado.\n" -#: src/demuxers/demux_asf.c:428 +#: src/demuxers/demux_asf.c:443 msgid "Media stream scrambled/encrypted" msgstr "Flujo de bits del medio revuelto/encriptado" -#: src/demuxers/demux_asf.c:2091 +#: src/demuxers/demux_asf.c:2105 msgid "ASF demux plugin" -msgstr "" +msgstr "Complemento demultiplexor ASF" #: src/demuxers/demux_avi.c:528 src/demuxers/demux_avi.c:642 msgid "Restoring index..." @@ -910,7 +909,7 @@ msgstr "" #: src/demuxers/demux_avi.c:2309 msgid "AVI/RIFF demux plugin" -msgstr "" +msgstr "Complemento demultiplexor AVI/RIFF" #: src/demuxers/demux_film.c:186 #, c-format @@ -924,7 +923,7 @@ msgstr "bloque FILM no reconocido\n" #: src/demuxers/demux_film.c:896 msgid "FILM (CPK) demux plugin" -msgstr "" +msgstr "Complemento demultiplexor FILM (CPK)" #: src/demuxers/demux_flv.c:178 #, c-format @@ -935,10 +934,9 @@ msgstr "Versión FLV no soportada (%d).\n" msgid "neither video nor audio stream in this file.\n" msgstr "no hay flujo de vídeo ni audio en este fichero.\n" -#: src/demuxers/demux_flv.c:879 -#, fuzzy +#: src/demuxers/demux_flv.c:888 msgid "Flash Video file demux plugin" -msgstr "Complemento de entrada de vídeo CD" +msgstr "Complemento demultiplexor para fichero Flash Video" #: src/demuxers/demux_iff.c:233 #, c-format @@ -957,7 +955,7 @@ msgstr "iff: Bloque no reconocido: %s\n" #: src/demuxers/demux_iff.c:1217 msgid "IFF demux plugin" -msgstr "" +msgstr "Complemento demultiplexor IFF" #: src/demuxers/demux_mpc.c:210 msgid "demux_mpc: frame too big for buffer" @@ -965,7 +963,7 @@ msgstr "demux_mpc: marco demasiado grande para el búfer" #: src/demuxers/demux_mpc.c:363 msgid "Musepack demux plugin" -msgstr "" +msgstr "Complemento demultiplexor Musepack" #: src/demuxers/demux_mpeg_block.c:294 #, c-format @@ -1001,7 +999,7 @@ msgstr "" #: src/demuxers/demux_mpeg_block.c:1493 msgid "DVD/VOB demux plugin" -msgstr "" +msgstr "Complemento demultiplexor DVD/VOB" #: src/demuxers/demux_mpeg_pes.c:415 #, c-format @@ -1039,12 +1037,12 @@ msgid "" "demux_mpeg_pes:Unrecognised private stream 1 0x%02x. Please report this to " "xine developers.\n" msgstr "" -"demux_mpeg_pes:flujo de bits privado 1 0x%02x. Por favor, repórtelo a los " -"desarrolladores de xine.\n" +"demux_mpeg_pes:flujo de bits privado no reconocido 1 0x%02x. Por favor, " +"repórtelo a los desarrolladores de xine.\n" #: src/demuxers/demux_mpeg_pes.c:1754 msgid "mpeg pes demux plugin" -msgstr "" +msgstr "Complemento demultiplexor pes mpeg" #: src/demuxers/demux_snd.c:102 #, c-format @@ -1057,18 +1055,16 @@ msgid "demux_snd: unsupported audio type: %d\n" msgstr "demux_snd: tipo de audio no soportado: %d\n" #: src/demuxers/demux_snd.c:358 -#, fuzzy msgid "SND/AU file demux plugin" -msgstr "complemento de fichero entrada" +msgstr "Complemento demultiplexor para fichero SND/AU" #: src/demuxers/demux_tta.c:85 msgid "demux_tta: total frames count too high\n" msgstr "demux_tta: la cuenta total de cuadros es demasiado alta\n" #: src/demuxers/demux_tta.c:272 -#, fuzzy msgid "True Audio demux plugin" -msgstr "xine: encontrado complemento demultiplexor: %s\n" +msgstr "Complemento demultiplexor True Audio (audio verdadero)" #: src/demuxers/demux_voc.c:103 #, c-format @@ -1086,9 +1082,8 @@ msgstr "" "desarrolladores de xine\n" #: src/demuxers/demux_voc.c:336 -#, fuzzy msgid "VOC file demux plugin" -msgstr "complemento de fichero entrada" +msgstr "Complemento demultiplexor fichero VOC" #: src/demuxers/demux_wc3movie.c:190 #, c-format @@ -1104,13 +1099,15 @@ msgstr "" #: src/demuxers/demux_wc3movie.c:711 msgid "Wing Commander III Movie (MVE) demux plugin" -msgstr "" +msgstr "Complemento demultiplexor Wing Commander III Movie (MVE)" #: src/dxr3/dxr3_decode_spu.c:185 msgid "" "subtitle decoder plugin using the hardware decoding capabilities of a DXR3 " "decoder card" msgstr "" +"complemento decodificador de subtítulos usando las capacidades " +"decodificadoras en hardware de una tarjeta decodificadora DXR3" #: src/dxr3/dxr3_decode_spu.c:230 #, c-format @@ -1126,6 +1123,8 @@ msgid "" "MPEGI/II decoder plugin using the hardware decoding capabilities of a DXR3 " "decoder card." msgstr "" +"Complemento decodificador de MPEGI/II usando las capacidades decodificadoras " +"en hardware de una tarjeta decodificadora DXR3." #: src/dxr3/dxr3_decode_video.c:226 #, c-format @@ -1325,6 +1324,8 @@ msgstr "" #: src/dxr3/video_out_dxr3.c:178 msgid "video output plugin displaying images through your DXR3 decoder card" msgstr "" +"complemento de salida de vídeo mostrando imágenes a través de su tarjeta " +"decodificadora DXR3" #: src/dxr3/video_out_dxr3.c:249 msgid "swap odd and even lines" @@ -1601,13 +1602,13 @@ msgstr "" "video_out_dxr3: ERROR leyendo en fichero de inicialización de la " "superposición. ¡Ejecute autocal!\n" -#: src/input/input_cdda.c:1586 +#: src/input/input_cdda.c:1584 #, c-format msgid "%s: can't connect to %s:%d\n" msgstr "%s: no se puede conectar a %s:%d\n" #: src/input/input_cdda.c:1631 -#, fuzzy, c-format +#, c-format msgid "input_cdda: successfully connected to cddb server '%s:%d'.\n" msgstr "input_cdda: conectado con éxito al servidor cddb '%s:%d'.\n" @@ -1616,15 +1617,15 @@ msgstr "input_cdda: conectado con éxito al servidor cddb '%s:%d'.\n" msgid "input_cdda: failed to connect to cddb server '%s:%d' (%s).\n" msgstr "input_cdda: falló al conectar al servidor cddb '%s:%d' (%s).\n" -#: src/input/input_cdda.c:2687 +#: src/input/input_cdda.c:2685 msgid "CD Digital Audio (aka. CDDA)" msgstr "audio CD digital (alias CDDA)" -#: src/input/input_cdda.c:2700 +#: src/input/input_cdda.c:2698 msgid "device used for CD audio" msgstr "dispositivo usado para audio CD" -#: src/input/input_cdda.c:2701 +#: src/input/input_cdda.c:2699 msgid "" "The path to the device, usually a CD or DVD drive, which you intend to use " "for playing audio CDs." @@ -1632,11 +1633,11 @@ msgstr "" "El camino al dispositivo, normalmente un lector de de CD o DVD, que desea " "usar para reproducir CDs de audio." -#: src/input/input_cdda.c:2707 +#: src/input/input_cdda.c:2705 msgid "query CDDB" msgstr "consultar la CDDB" -#: src/input/input_cdda.c:2707 +#: src/input/input_cdda.c:2705 msgid "" "Enables CDDB queries, which will give you convenient title and track names " "for your audio CDs.\n" @@ -1650,11 +1651,11 @@ msgstr "" "información se obtiene de un servidor en Internet que podría sacar un perfil " "de sus hábitos de escucha." -#: src/input/input_cdda.c:2715 +#: src/input/input_cdda.c:2713 msgid "CDDB server name" msgstr "nombre del servidor CDDB" -#: src/input/input_cdda.c:2715 +#: src/input/input_cdda.c:2713 msgid "" "The CDDB server used to retrieve the title and track information from.\n" "This setting is security critical, because the sever will receive " @@ -1667,20 +1668,20 @@ msgstr "" "consultas con respuestas maliciosas. Asegúrese de poner un servidor del que " "se pueda fiar." -#: src/input/input_cdda.c:2723 +#: src/input/input_cdda.c:2721 msgid "CDDB server port" msgstr "puerto del servidor CDDB" -#: src/input/input_cdda.c:2723 +#: src/input/input_cdda.c:2721 msgid "The server port used to retrieve the title and track information from." msgstr "" "El puerto del servidor usado para obtener la información de título y pista." -#: src/input/input_cdda.c:2729 +#: src/input/input_cdda.c:2727 msgid "slow down disc drive to this speed factor" msgstr "enlentecer la unidad de disco a este factor de velocidad" -#: src/input/input_cdda.c:2730 +#: src/input/input_cdda.c:2728 msgid "" "Since some CD or DVD drives make some really loud noises because of the fast " "disc rotation, xine will try to slow them down. With standard CD or DVD " @@ -1706,50 +1707,50 @@ msgid "input_dvb: dvb channel file '%s' is not a plain file\n" msgstr "" "input_dvb: el fichero de canales dvb '%s' no es un fichero texto plano\n" -#: src/input/input_dvb.c:2127 src/input/input_dvb.c:2967 +#: src/input/input_dvb.c:2127 src/input/input_dvb.c:2964 msgid "input_dvb: tuner_set_channel failed\n" msgstr "input_dvb: falló tuner_set_channel\n" -#: src/input/input_dvb.c:2762 +#: src/input/input_dvb.c:2759 #, c-format msgid "input_dvb: DVB GUI %s\n" -msgstr "" +msgstr "input_dvb: IGU de DVB %s\n" -#: src/input/input_dvb.c:2767 src/input/input_dvb.c:3183 +#: src/input/input_dvb.c:2764 src/input/input_dvb.c:3180 msgid "input_dvb: cannot open dvb device\n" msgstr "input_dvb: no puedo abrir dispositivo DVB\n" -#: src/input/input_dvb.c:2791 +#: src/input/input_dvb.c:2788 #, c-format msgid "input_dvb: channel %d out of range, defaulting to 0\n" msgstr "input_dvb: canal %d fuera de rango, poniendo a 0\n" -#: src/input/input_dvb.c:2802 +#: src/input/input_dvb.c:2799 #, c-format msgid "input_dvb: searching for channel %s\n" msgstr "input_dvb: buscando el canal %s\n" -#: src/input/input_dvb.c:2825 +#: src/input/input_dvb.c:2822 #, c-format msgid "input_dvb: exact match for %s not found: trying partial matches\n" msgstr "" "input_dvb: no encontrada una coincidencia exacta para %s: probando " "coincidencias parciales\n" -#: src/input/input_dvb.c:2832 +#: src/input/input_dvb.c:2829 #, c-format msgid "input_dvb: found matching channel %s\n" msgstr "input_dvb: encontrado el canal correspondiente %s\n" # Cer: (temporal) "valores por defecto" no es la traducción exacta -#: src/input/input_dvb.c:2845 +#: src/input/input_dvb.c:2842 #, c-format msgid "input_dvb: channel %s not found in channels.conf, defaulting.\n" msgstr "" "input_dvb: canal %s no encontrado en channels.conf, yendo a valores por " "defecto.\n" -#: src/input/input_dvb.c:2851 +#: src/input/input_dvb.c:2848 msgid "" "input_dvb: invalid channel specification, defaulting to last viewed " "channel.\n" @@ -1757,11 +1758,11 @@ msgstr "" "input_dvb: especificación de canal inválida, usaremos el ultimo canal " "visualizado.\n" -#: src/input/input_dvb.c:2857 +#: src/input/input_dvb.c:2854 msgid "input_dvb: invalid channel specification, defaulting to channel 0\n" msgstr "input_dvb: especificación de canal inválida, usaremos el canal 0.\n" -#: src/input/input_dvb.c:2869 +#: src/input/input_dvb.c:2866 msgid "" "input_dvb: dvbs mrl specified but the tuner doesn't appear to be QPSK (DVB-" "S)\n" @@ -1769,7 +1770,7 @@ msgstr "" "input_dvb: se especificó mrl dvbs pero el sintonizador no aparenta ser QPSK " "(DVB-S)\n" -#: src/input/input_dvb.c:2889 +#: src/input/input_dvb.c:2886 msgid "" "input_dvb: dvbt mrl specified but the tuner doesn't appear to be OFDM (DVB-" "T)\n" @@ -1777,7 +1778,7 @@ msgstr "" "input_dvb: se especificó mrl dvbt pero el sintonizador no aparenta ser OFDM " "(DVB-T)\n" -#: src/input/input_dvb.c:2912 +#: src/input/input_dvb.c:2909 msgid "" "input_dvb: dvbc mrl specified but the tuner doesn't appear to be QAM (DVB-" "C)\n" @@ -1785,7 +1786,7 @@ msgstr "" "input_dvb: se especificó mrl dvbc pero el sintonizador no aparenta ser QAM " "(DVB-C)\n" -#: src/input/input_dvb.c:2938 +#: src/input/input_dvb.c:2935 msgid "" "input_dvb: dvba mrl specified but the tuner doesn't appear to be ATSC (DVB-" "A)\n" @@ -1793,20 +1794,20 @@ msgstr "" "input_dvb: se especificó mrl dvba pero el sintonizador no aparenta ser ATSC " "(DVB-A)\n" -#: src/input/input_dvb.c:2973 +#: src/input/input_dvb.c:2970 #, c-format msgid "input_dvb: cannot open dvr device '%s'\n" msgstr "input_dvb: no se puede abrir el dispositivo DVR '%s'\n" -#: src/input/input_dvb.c:2996 +#: src/input/input_dvb.c:2993 msgid "input_dvb: cannot create EPG updater thread\n" msgstr "input_dvb: no se puede crear el hilo actualizador de EPG\n" -#: src/input/input_dvb.c:3058 +#: src/input/input_dvb.c:3055 msgid "use DVB 'center cutout' (zoom)" msgstr "usar corte de la zona central del DVB (zoom)" -#: src/input/input_dvb.c:3059 +#: src/input/input_dvb.c:3056 msgid "" "This will allow fullscreen playback of 4:3 content transmitted in a 16:9 " "frame." @@ -1814,15 +1815,15 @@ msgstr "" "Esto permitirá reproducción a pantalla completa de contenido en formato 4:3 " "transmitido en un cuadro 16:9." -#: src/input/input_dvb.c:3252 +#: src/input/input_dvb.c:3249 msgid "DVB (Digital TV) input plugin" msgstr "complemento de entrada DVB (TV Digital)" -#: src/input/input_dvb.c:3270 +#: src/input/input_dvb.c:3267 msgid "Remember last DVB channel watched" msgstr "Recordar el último canal DVB visto" -#: src/input/input_dvb.c:3271 +#: src/input/input_dvb.c:3268 msgid "" "On autoplay, xine will remember and switch to the channel indicated in media." "dvb.last_channel. " @@ -1830,19 +1831,19 @@ msgstr "" "En autoejecución, xine recordará y cambiará al canal indicado en media.dvb." "last_channel. " -#: src/input/input_dvb.c:3278 +#: src/input/input_dvb.c:3275 msgid "Last DVB channel viewed" msgstr "Último canal DVB visto" -#: src/input/input_dvb.c:3279 +#: src/input/input_dvb.c:3276 msgid "If enabled xine will remember and switch to this channel. " msgstr "Si se activa xine recordará y cambiará a este canal. " -#: src/input/input_dvb.c:3284 +#: src/input/input_dvb.c:3281 msgid "Number of seconds until tuning times out." msgstr "Número de segundos hasta que la sintonización temporice." -#: src/input/input_dvb.c:3285 +#: src/input/input_dvb.c:3282 msgid "" "Leave at 0 means try forever. Greater than 0 means wait that many seconds to " "get a lock. Minimum is 5 seconds." @@ -1850,19 +1851,20 @@ msgstr "" "Dejar como 0 significa probar indefinidamente. Mayor que cero significa " "esperar esos segundos hasta conseguir un ajuste. El mínimo son 5 segundos." -#: src/input/input_dvb.c:3292 +#: src/input/input_dvb.c:3289 msgid "Enable the DVB GUI" -msgstr "" +msgstr "Activar el IGU de DVB" -#: src/input/input_dvb.c:3293 +#: src/input/input_dvb.c:3290 msgid "Enable the DVB GUI, mouse controlled recording and channel switching." msgstr "" +"Activar el IGU de DVB, grabación y cambio de canal controlados por ratón." -#: src/input/input_dvb.c:3298 +#: src/input/input_dvb.c:3295 msgid "Number of dvb card to use." msgstr "Número de tarjeta DVB a usar." -#: src/input/input_dvb.c:3299 +#: src/input/input_dvb.c:3296 msgid "" "Leave this at zero unless you really have more than 1 card in your system." msgstr "" @@ -1884,7 +1886,7 @@ msgstr "input_dvd: Error abriendo dispositivo DVD\n" #: src/input/input_dvd.c:1759 msgid "DVD Navigator" -msgstr "" +msgstr "Navegador de DVD" #: src/input/input_dvd.c:1776 msgid "device used for DVD playback" @@ -2264,11 +2266,11 @@ msgstr "input_net: no se puede resolver '%s'.\n" msgid "input_net: unable to connect to '%s'.\n" msgstr "input_net: no se puede conectar a '%s'.\n" -#: src/input/input_net.c:517 +#: src/input/input_net.c:523 msgid "net input plugin as shipped with xine" msgstr "complemento de entrada de red incluido en xine" -#: src/input/input_pnm.c:272 +#: src/input/input_pnm.c:270 msgid "pnm streaming input plugin" msgstr "complemento de flujo de bits pnm de entrada" @@ -2287,32 +2289,32 @@ msgstr "input_pvr: error al abrir el archivo pvr (%s)\n" msgid "input_pvr: read error (%s)\n" msgstr "input_pvr: error de lectura (%s)\n" -#: src/input/input_pvr.c:1142 src/input/input_pvr.c:1395 +#: src/input/input_pvr.c:1165 src/input/input_pvr.c:1418 #, c-format msgid "input_pvr: error opening device %s\n" msgstr "input_pvr: error al abrir el dispositivo %s\n" -#: src/input/input_pvr.c:1148 src/input/input_pvr.c:1401 +#: src/input/input_pvr.c:1171 src/input/input_pvr.c:1424 msgid "input_pvr: IVTV_IOC_G_CODEC failed, maybe API changed?\n" msgstr "" "input_pvr: IVTV_IOC_G_CODEC falló, ¿quizás cambió la API? (interfase para " "programación de aplicaciones)\n" -#: src/input/input_pvr.c:1156 src/input/input_pvr.c:1410 +#: src/input/input_pvr.c:1179 src/input/input_pvr.c:1433 msgid "input_pvr: IVTV_IOC_S_CODEC failed, maybe API changed?\n" msgstr "" "input_pvr: IVTV_IOC_S_CODEC falló, ¿quizás cambió la API? (interfase para " "programación de aplicaciones)\n" -#: src/input/input_pvr.c:1528 +#: src/input/input_pvr.c:1551 msgid "device used for WinTV-PVR 250/350 (pvr plugin)" msgstr "dispositivo usado para WinTV-PVR 250/350 (complemento pvr)" -#: src/input/input_pvr.c:1529 +#: src/input/input_pvr.c:1552 msgid "The path to the device of your WinTV card." msgstr "El camino al dispositivo de su tarjeta WinTV." -#: src/input/input_pvr.c:1535 +#: src/input/input_pvr.c:1558 msgid "WinTV-PVR 250/350 input plugin" msgstr "complemento de entrada para WinTV-PVR 250/350" @@ -2388,7 +2390,7 @@ msgstr "input_rtp: no se puede crear un hilo nuevo (%s)\n" msgid "RTP and UDP input plugin as shipped with xine" msgstr "complemento de entrada RTP y UDP original de xine" -#: src/input/input_rtsp.c:292 +#: src/input/input_rtsp.c:290 msgid "rtsp streaming input plugin" msgstr "complemento de flujo de bits de entrada rtsp" @@ -2410,52 +2412,66 @@ msgstr "stdin: falló al abrir '%s'\n" msgid "stdin streaming input plugin" msgstr "complemento de entrada de flujo de bits" -#: src/input/input_v4l.c:402 +#: src/input/input_v4l.c:405 msgid "Buffer underrun..." msgstr "Memoria intermedia vacía..." -#: src/input/input_v4l.c:406 +#: src/input/input_v4l.c:409 msgid "Buffer overrun..." msgstr "Memoria intermedia rebosando..." -#: src/input/input_v4l.c:409 +#: src/input/input_v4l.c:412 msgid "Adjusting..." msgstr "Ajustando..." -#: src/input/input_v4l.c:683 +#: src/input/input_v4l.c:686 msgid "Tuner name not found\n" msgstr "Nombre del sintonizador no encontrado\n" -#: src/input/input_v4l.c:1914 +#: src/input/input_v4l.c:1921 msgid "v4l tv input plugin" msgstr "Complemento de entrada v4l tv" -#: src/input/input_v4l.c:1922 +#: src/input/input_v4l.c:1929 msgid "v4l video device" msgstr "dispositivo vídeo v4l" -#: src/input/input_v4l.c:1923 +#: src/input/input_v4l.c:1930 msgid "The path to your Video4Linux video device." msgstr "El camino a su dispositivo de vídeo Video4Linux." -#: src/input/input_v4l.c:1927 +#: src/input/input_v4l.c:1934 msgid "v4l TV standard" -msgstr "" +msgstr "Estandar v4l de TV" -#: src/input/input_v4l.c:1928 +#: src/input/input_v4l.c:1935 msgid "" "Selects the TV standard of the input signals. Either: PAL, NTSC and SECAM. " msgstr "" +"Selecciona el estandar de TV de las señales de entrada. Ha de ser una de: " +"PAL, NTSC o SECAM. " + +#: src/input/input_v4l.c:1941 +msgid "v4l ALSA audio input device" +msgstr "dispositivo audio de entrada ALSA v4l" + +#: src/input/input_v4l.c:1942 +msgid "" +"The name of the audio device which corresponds to your Video4Linux video " +"device." +msgstr "" +"El nombre del dispositivo de audio que corresponde a su dispositivo de vídeo " +"Video4Linux." -#: src/input/input_v4l.c:1946 +#: src/input/input_v4l.c:1961 msgid "v4l radio input plugin" msgstr "Complemento de entrada v4l radio" -#: src/input/input_v4l.c:1954 +#: src/input/input_v4l.c:1969 msgid "v4l radio device" msgstr "dispositivo audio v4l" -#: src/input/input_v4l.c:1955 +#: src/input/input_v4l.c:1970 msgid "The path to your Video4Linux radio device." msgstr "El camino a su dispositivo de radio Video4Linux." @@ -2494,12 +2510,12 @@ msgstr "" "El camino al dispositivo, usualmente una unidad de CD o DVD, que quiere usar " "para reproducir sus VideoCDes." -#: src/input/librtsp/rtsp.c:435 +#: src/input/librtsp/rtsp.c:437 #, c-format msgid "rtsp: bad mrl: %s\n" msgstr "rtsp: mal mrl: %s\n" -#: src/input/librtsp/rtsp.c:493 +#: src/input/librtsp/rtsp.c:495 #, c-format msgid "rtsp: failed to connect to '%s'\n" msgstr "rtsp: falló en conectar a '%s'\n" @@ -2513,7 +2529,15 @@ msgstr "rtsp_session: falló en conectar al servidor %s\n" msgid "rtsp_session: session can not be established.\n" msgstr "rtsp_session: la sesión no pudo establecerse.\n" -#: src/input/librtsp/rtsp_session.c:159 +#: src/input/librtsp/rtsp_session.c:153 +msgid "" +"rtsp_session: rtsp server returned overly-large headers, session can not be " +"established.\n" +msgstr "" +"rtsp_session: el servidor rtsp devolvió cabeceras demasiado grandes, la " +"sesión no puede ser establecida.\n" + +#: src/input/librtsp/rtsp_session.c:164 #, c-format msgid "rtsp_session: rtsp server type '%s' not supported yet. sorry.\n" msgstr "" @@ -2568,9 +2592,11 @@ msgid "unsupported protocol\n" msgstr "protocolo no soportado\n" # msgstr "Tamponeando..." +# Llenando mem. tampón... +# Tamponeando... #: src/input/net_buf_ctrl.c:89 msgid "Buffering..." -msgstr "Llenando mem. tampón..." +msgstr "Precargando..." #: src/input/pnm.c:617 #, c-format @@ -2855,7 +2881,7 @@ msgstr "ffmpeg_audio_dec: no pude abrir el decodificador\n" #: src/combined/ffmpeg/ff_audio_decoder.c:426 msgid "ffmpeg based audio decoder plugin" -msgstr "" +msgstr "complemento decodificador de audio basado en ffmpeg" #: src/combined/ffmpeg/ff_dvaudio_decoder.c:277 #, c-format @@ -2865,9 +2891,8 @@ msgstr "" "desbordamiento.\n" #: src/combined/ffmpeg/ff_dvaudio_decoder.c:388 -#, fuzzy msgid "dv audio decoder plugin" -msgstr "Complemento de entrada v4l radio" +msgstr "complemento decodificador de audio dv" #: src/combined/ffmpeg/ffmpeg_encoder.c:161 msgid "libavcodec mpeg output bitrate (kbit/s)" @@ -2917,46 +2942,46 @@ msgid "The maximum compression to apply to an image in constant quality mode." msgstr "" "La máxima compresión a aplicar a una imagen en modo de calidad constante." -#: src/combined/ffmpeg/ff_video_decoder.c:154 +#: src/combined/ffmpeg/ff_video_decoder.c:156 msgid "ffmpeg_video_dec: unsupported frame format, DR1 disabled.\n" msgstr "ffmpeg_video_dec: formato de cuadro no soportado, DR1 desactivado.\n" -#: src/combined/ffmpeg/ff_video_decoder.c:172 +#: src/combined/ffmpeg/ff_video_decoder.c:174 msgid "ffmpeg_video_dec: unsupported frame dimensions, DR1 disabled.\n" msgstr "" "ffmpeg_video_dec: dimensiones de cuadro no soportadas, DR1 desactivado.\n" -#: src/combined/ffmpeg/ff_video_decoder.c:336 +#: src/combined/ffmpeg/ff_video_decoder.c:357 #, c-format msgid "ffmpeg_video_dec: couldn't find ffmpeg decoder for buf type 0x%X\n" msgstr "" "ffmpeg_video_dec: no pude encontrar el decodificador ffmpeg para el tipo de " "tampón 0x%X\n" -#: src/combined/ffmpeg/ff_video_decoder.c:365 +#: src/combined/ffmpeg/ff_video_decoder.c:389 msgid "ffmpeg_video_dec: couldn't open decoder\n" msgstr "ffmpeg_video_dec: no pude abrir el decodificador\n" -#: src/combined/ffmpeg/ff_video_decoder.c:406 +#: src/combined/ffmpeg/ff_video_decoder.c:432 msgid "ffmpeg_video_dec: direct rendering enabled\n" msgstr "ffmpeg_video_dec: renderizado directo activado\n" -#: src/combined/ffmpeg/ff_video_decoder.c:834 +#: src/combined/ffmpeg/ff_video_decoder.c:872 #, c-format msgid "ffmpeg_video_dec: increasing buffer to %d to avoid overflow.\n" msgstr "" "ffmpeg_video_dec: incrementando el tamaño de la memoria tampón a %d para " "evitar el desbordamiento.\n" -#: src/combined/ffmpeg/ff_video_decoder.c:1536 +#: src/combined/ffmpeg/ff_video_decoder.c:1574 msgid "ffmpeg based video decoder plugin" -msgstr "" +msgstr "complemento decodificador de vídeo basado en ffmpeg" -#: src/combined/ffmpeg/ff_video_decoder.c:1548 +#: src/combined/ffmpeg/ff_video_decoder.c:1586 msgid "MPEG-4 postprocessing quality" msgstr "calidad de postprocesado MPEG-4" -#: src/combined/ffmpeg/ff_video_decoder.c:1549 +#: src/combined/ffmpeg/ff_video_decoder.c:1587 msgid "" "You can adjust the amount of post processing applied to MPEG-4 video.\n" "Higher values result in better quality, but need more CPU. Lower values may " @@ -2970,11 +2995,11 @@ msgstr "" "bloque. Para contenido de alta calidad, demasiado postprocesado puede de " "hecho hacer la imagen peor emborronándola demasiado." -#: src/combined/ffmpeg/ff_video_decoder.c:1557 +#: src/combined/ffmpeg/ff_video_decoder.c:1595 msgid "FFmpeg video decoding thread count" -msgstr "" +msgstr "Conteo de hilos decodificando vídeo FFmpeg" -#: src/combined/ffmpeg/ff_video_decoder.c:1558 +#: src/combined/ffmpeg/ff_video_decoder.c:1596 msgid "" "You can adjust the number of video decoding threads which FFmpeg may use.\n" "Higher values should speed up decoding but it depends on the codec used " @@ -2982,11 +3007,17 @@ msgid "" "decoding thread per logical CPU (typically 1 to 4).\n" "A change of this setting will take effect with playing the next stream." msgstr "" +"Puede ajustar el número de hilos decodificadores que pueda usar FFmpeg.\n" +"Valores más altos deben acelerar la decodificación, pero depende del códec " +"si se soporta procesado en paralelo. Una regla general es tener un hilo " +"decodificador por cada CPU lógica (típicamente de 1 a 4). Un cambio hará " +"efecto cuando se reproduzca el siguiente flujo." #: src/combined/ffmpeg/ff_video_decoder.c:1605 msgid "Skip loop filter" -msgstr "" +msgstr "Saltarse filtro de bucle" +# Cer "saltar" por"skip" suena raro. #: src/combined/ffmpeg/ff_video_decoder.c:1606 msgid "" "You can control for which frames the loop filter shall be skipped after " @@ -2996,10 +3027,17 @@ msgid "" "The default value leaves the decision up to the implementation.\n" "A change of this setting will take effect with playing the next stream." msgstr "" +"Puede controlar para que cuadros el filtro de bucle será saltado después de " +"decodificar.\n" +"Omitir el filtro de bucle acelerará la decodificación, pero puede llevarnos " +"a tener artefactos. El número de cuadros para los que se salta aumenta de " +"'none' a 'all' (“nada†a “todosâ€). El valor por omisión deja la decisión en " +"manos de la implementación.\n" +"Un cambio de este ajuste tendrá efecto a la reproducción de siguiente flujo." #: src/combined/ffmpeg/ff_video_decoder.c:1615 msgid "Choose speed over specification compliance" -msgstr "" +msgstr "Elegir velocidad en vez de conformidad con la especificación" #: src/combined/ffmpeg/ff_video_decoder.c:1616 msgid "" @@ -3007,6 +3045,11 @@ msgid "" "Cheating may speed up decoding but can also lead to decoding artefacts.\n" "A change of this setting will take effect with playing the next stream." msgstr "" +"Usted puede querer permitir trampas de velocidad que violan las " +"especificaciones del códec.\n" +"Hacer trampas puede acelerar la decodificación pero también provocar " +"artefactos de decodificación.\n" +"Un cambio de este ajuste tendrá efecto a la reproducción de siguiente flujo." #: src/libreal/real_common.c:139 msgid "path to RealPlayer codecs" @@ -3049,9 +3092,11 @@ msgstr "" msgid "libareal: oups, real can do more than 2 channels ?\n" msgstr "libareal: Ostras, ¿puede real hacer más de dos canales?\n" +# Cer: dudoso #: src/libreal/xine_real_audio_decoder.c:594 msgid "real binary-only codec based audio decoder plugin" msgstr "" +"complemento decodificador de audio basado en exclusivamente binario “realâ€" #: src/libreal/xine_real_video_decoder.c:162 msgid "libreal: Error resolving symbols! (version incompatibility?)\n" @@ -3061,6 +3106,7 @@ msgstr "" #: src/libreal/xine_real_video_decoder.c:522 msgid "real binary-only codec based video decoder plugin" msgstr "" +"complemento decodificador de vídeo basado en exclusivamente binario “realâ€" #: src/spu_dec/xine_cc_decoder.c:189 msgid "display closed captions in MPEG-2 streams" @@ -3119,9 +3165,8 @@ msgstr "" "individuales." #: src/spu_dec/xine_cc_decoder.c:330 -#, fuzzy msgid "closed caption decoder plugin" -msgstr "tamaño de la tipografía del subtitulado" +msgstr "complemento decodificador de subtitulado para sordos" #: src/spu_dec/cmml_decoder.c:477 msgid "font for external subtitles" @@ -3134,22 +3179,21 @@ msgstr "" #: src/spu_dec/cmml_decoder.c:509 msgid "CMML subtitle decoder plugin" -msgstr "" +msgstr "complemento decodificador de subtítulos CMML" #: src/spu_dec/cmml_decoder.c:517 msgid "encoding of subtitles" msgstr "codificado de los subtítulos" -#: src/spu_dec/sputext_demuxer.c:1461 -#, fuzzy +#: src/spu_dec/sputext_demuxer.c:1436 msgid "sputext demuxer plugin" -msgstr "xine: encontrado complemento demultiplexor: %s\n" +msgstr "complemento demultiplexor sputext" -#: src/spu_dec/sputext_demuxer.c:1476 +#: src/spu_dec/sputext_demuxer.c:1451 msgid "default duration of subtitle display in seconds" msgstr "duración por defecto de la exhibición de los subtítulos en segundos" -#: src/spu_dec/sputext_demuxer.c:1477 +#: src/spu_dec/sputext_demuxer.c:1452 msgid "" "Some subtitle formats do not explicitly give a duration for each subtitle. " "For these, you can set a default duration here. Setting to zero will result " @@ -3160,15 +3204,15 @@ msgstr "" "a cero hará que el subtítulo se siga mostrando hasta que aparezca el " "siguiente." -#: src/spu_dec/sputext_decoder.c:912 +#: src/spu_dec/sputext_decoder.c:1135 msgid "external subtitle decoder plugin" -msgstr "" +msgstr "complemento decodificador de subtítulos externo" -#: src/spu_dec/sputext_decoder.c:921 +#: src/spu_dec/sputext_decoder.c:1144 msgid "subtitle size" msgstr "tamaño de subtítulo " -#: src/spu_dec/sputext_decoder.c:922 +#: src/spu_dec/sputext_decoder.c:1145 msgid "" "You can adjust the subtitle size here. The setting will be evaluated " "relative to the window size." @@ -3176,11 +3220,11 @@ msgstr "" "Puede ajustar el tamaño de los subtítulos aquí. El ajuste será evaluado " "relativo al tamaño de la ventana." -#: src/spu_dec/sputext_decoder.c:928 +#: src/spu_dec/sputext_decoder.c:1151 msgid "subtitle vertical offset" msgstr "desplazamiento vertical de los subtítulos" -#: src/spu_dec/sputext_decoder.c:929 +#: src/spu_dec/sputext_decoder.c:1152 msgid "" "You can adjust the vertical position of the subtitle. The setting will be " "evaluated relative to the window size." @@ -3188,31 +3232,31 @@ msgstr "" "Puede ajustar la posición vertical de los subtítulos aquí. El ajuste será " "evaluado relativo al tamaño de la ventana." -#: src/spu_dec/sputext_decoder.c:935 src/spu_dec/sputext_decoder.c:944 +#: src/spu_dec/sputext_decoder.c:1158 src/spu_dec/sputext_decoder.c:1167 msgid "font for subtitles" msgstr "tipografía para los subtítulos" -#: src/spu_dec/sputext_decoder.c:936 +#: src/spu_dec/sputext_decoder.c:1159 msgid "A font from the xine font directory to be used for the subtitle text." msgstr "" "Tipografía del directorio de xine que será usada para el texto de los " "subtítulos." -#: src/spu_dec/sputext_decoder.c:945 +#: src/spu_dec/sputext_decoder.c:1168 msgid "An outline font file (e.g. a .ttf) to be used for the subtitle text." msgstr "" "Un fichero de tipografía tipo linea (pe: a.ttf) que será usada para el texto " "de los subtítulos." -#: src/spu_dec/sputext_decoder.c:951 +#: src/spu_dec/sputext_decoder.c:1174 msgid "whether to use a freetype font" msgstr "si debemos usar una tipografía freetype" -#: src/spu_dec/sputext_decoder.c:958 +#: src/spu_dec/sputext_decoder.c:1181 msgid "encoding of the subtitles" msgstr "codificación de los subtítulos" -#: src/spu_dec/sputext_decoder.c:959 +#: src/spu_dec/sputext_decoder.c:1182 msgid "" "The encoding of the subtitle text in the stream. This setting is used to " "render non-ASCII characters correctly. If non-ASCII characters are not " @@ -3224,11 +3268,11 @@ msgstr "" "caracteres no ASCII no se muestran de la forma que usted espera, pregúntele " "al creador de los subtítulos que codificación se usó." -#: src/spu_dec/sputext_decoder.c:967 +#: src/spu_dec/sputext_decoder.c:1190 msgid "use unscaled OSD if possible" msgstr "use OSD sin escalar si es posible" -#: src/spu_dec/sputext_decoder.c:968 +#: src/spu_dec/sputext_decoder.c:1191 msgid "" "The unscaled OSD will be rendered independently of the video frame and will " "always be sharp, even if the video is magnified. This will look better, but " @@ -3326,12 +3370,11 @@ msgstr "w32codec: Error inicializando audio DMO\n" #: src/libw32dll/w32codec.c:1588 msgid "win32 binary video codec plugin" -msgstr "" +msgstr "complemento binario win32 codec de vídeo" #: src/libw32dll/w32codec.c:1637 -#, fuzzy msgid "win32 binary audio codec plugin" -msgstr "complemento de xine de salida de audio a fichero" +msgstr "complemento binario win32 codec de audio" #: src/audio_dec/xine_a52_decoder.c:757 src/audio_dec/xine_dts_decoder.c:524 msgid "HELP! a mono-only audio driver?!\n" @@ -3339,7 +3382,7 @@ msgstr "¡AYUDA! ¿¡Un manejador de audio exclusivamente mono-aural?!\n" #: src/audio_dec/xine_a52_decoder.c:798 msgid "liba52 based a52 audio decoder plugin" -msgstr "" +msgstr "complemento decodificador de audio a52 basado en liba52" #: src/audio_dec/xine_a52_decoder.c:805 msgid "A/52 volume" @@ -3390,7 +3433,7 @@ msgstr "" #: src/audio_dec/xine_dts_decoder.c:559 msgid "DTS passthru audio format decoder plugin" -msgstr "" +msgstr "complemento decodificador de formato audio paso a través DTS" #: src/audio_dec/xine_faad_decoder.c:131 msgid "libfaad: libfaad NeAACDecOpen() failed.\n" @@ -3407,6 +3450,8 @@ msgstr "libfaad: libfaad NeAACDecInit falló.\n" #: src/audio_dec/xine_faad_decoder.c:458 msgid "Freeware Advanced Audio Decoder" msgstr "" +"Decodificador de audio Freeware avanzado (“Freeware Advanced Audio Decoderâ€, " +"faad)" #: src/audio_dec/xine_musepack_decoder.c:249 #, c-format @@ -3429,7 +3474,7 @@ msgstr "libmusepack: falló mpc_decoder_decode: %d\n" #: src/audio_dec/xine_musepack_decoder.c:441 msgid "mpc: musepack audio decoder plugin" -msgstr "" +msgstr "mpc: complemento decodificador de audio musepack" #: src/video_dec/bitplane.c:1269 #, c-format @@ -3458,7 +3503,7 @@ msgstr "bitplane: Este tipo anim no está soportado de momento\n" #: src/video_dec/bitplane.c:1529 msgid "Raw bitplane video decoder plugin" -msgstr "" +msgstr "complemento decodificador de vídeo plano de bits en bruto" #: src/post/audio/stretch.c:263 msgid "" @@ -3473,7 +3518,7 @@ msgstr "" #: src/post/audio/stretch.c:672 msgid "Time stretch by a given factor, optionally preserving pitch" -msgstr "" +msgstr "Estirar el tiempo en un factor dado, opcionalmente manteniendo el tono" #: src/post/audio/upmix.c:134 msgid "" @@ -3496,7 +3541,7 @@ msgstr "" #: src/post/audio/upmix.c:427 msgid "upmix" -msgstr "" +msgstr "mezcla mejorada (“upmixâ€)" #: src/post/audio/upmix_mono.c:106 msgid "" @@ -3527,9 +3572,8 @@ msgid ": audio device not capable of AO_CAP_MODE_STEREO.\n" msgstr ": dispositivo audio incapaz de AO_CAP_MODE_STEREO.\n" #: src/post/audio/upmix_mono.c:342 -#, fuzzy msgid "converts Mono into Stereo" -msgstr ": mejorando Mono a Stereo.\n" +msgstr "convierte mono a estéreo" #: src/post/audio/volnorm.c:147 msgid "" @@ -3549,8 +3593,14 @@ msgstr "" #: src/post/audio/volnorm.c:460 msgid "Normalize volume" -msgstr "" - +msgstr "Normalizar el volumen" + +# Cer: pulldown: se refiere a curiosos mecanismos de adaptación +# de las diferentes frecuencias de cuadro entre pelicula y vídeo +# (ver http://en.wikipedia.org/wiki/Telecine#2:3_pulldown). +# Ignoro que nombre puede tener en español. Lo de “pulldown†+# viene del arrastre de la pelicula, de la que se tira con una uña +# en la cámara #: src/post/deinterlace/xine_plugin.c:202 msgid "" "Advanced tvtime/deinterlacer plugin with pulldown detection\n" @@ -3603,8 +3653,8 @@ msgid "" "Deinterlacing methods: (Not all methods are available for all plataforms)\n" "\n" msgstr "" -"Complemento avanzado tvtime/desentrelazador con detección de despliegue de " -"menú {pulldown}\n" +"Complemento avanzado tvtime/desentrelazador con detección de conversión de " +"frecuencia de cuadro en el telecine (“pulldownâ€)\n" "Este complemento trata de suministrar mecanismos de desentrelazado " "comparables a reproductores de alta calidad progresivos de DVD y los así " "llamados dobladores de linea, para usar con monitores de ordenador, " @@ -3617,10 +3667,10 @@ msgstr "" "\n" " Enabled (activado): Activar/desactivar el complemento.\n" "\n" -" Pulldown (despliegue): Escoger el algoritmo de detección de despliegue 2-3 " -"{¿de menú?}. Las películas de 24 CPS (cuadros por segundo) que han sido " -"convertidas a NTSC pueden ser detectadas e inteligentemente reconstruidas a " -"sus cuadros originales (no entrelazados).\n" +" Pulldown (ajuste de telecine): Escoger el algoritmo de detección de ajuste " +"de telecine 2-3. Las películas de 24 CPS (cuadros por segundo) que han sido " +"convertidas a NTSC con ese ajuste, pueden ser detectadas e inteligentemente " +"reconstruidas a sus cuadros originales (no entrelazados).\n" "\n" " Framerate_mode (modo de cadencia de cuadro): Seleccionar 'full' (completo) " "desentrelazará cada campo a un único cuadro en calidad de televisión y más " @@ -3630,11 +3680,11 @@ msgstr "" "Un RedHat más moderno y los kernels 2.6 usan una frecuencia mayor (512 y " "1000, respectivamente) y deberían funcionar bien.\n" "\n" -" Judder_correction (corrección de vibración): Una vez que despliegue 2-3 " -"está activado y se detecta que tenemos una película, es posible reducir la " -"cadencia de cuadro a la original (24 CPS). Esto distribuirá los cuadros " -"uniformemente en el tiempo, coincidiendo con la velocidad con que fueron " -"rodados y eliminando el efecto de vibración.\n" +" Judder_correction (corrección de vibración): Una vez que ajuste de " +"telecine 2-3 está activado y se detecta que tenemos una película, es posible " +"reducir la cadencia de cuadro a la original (24 CPS). Esto distribuirá los " +"cuadros uniformemente en el tiempo, coincidiendo con la velocidad con que " +"fueron rodados y eliminando el efecto de vibración.\n" "\n" " Use_progressive_frame_flag (use bandera de cuadro progresivo): Flujos de " "datos MPEG2 bien creados usan una bandera para indicar material progresivo. " @@ -3661,17 +3711,21 @@ msgstr "" "está disponibles para todas las plataformas)\n" "\n" +# Pull down es demoler, pero... no pega. #: src/post/deinterlace/xine_plugin.c:301 msgid "advanced deinterlacer plugin with pulldown detection" msgstr "" +"complemento desentrelazador avanzado con detección de ajuste de frecuencia " +"de cuadro en el telecine" #: src/post/deinterlace/xine_plugin.c:321 msgid "tvtime: No deinterlacing methods available, exiting.\n" msgstr "tvtime: No hay métodos de desentrelazado disponibles, saliendo.\n" +# Cer: no se que quieren decir. #: src/post/goom/xine_goom.c:196 msgid "What a GOOM" -msgstr "" +msgstr "Vaya un GOOM" #: src/post/goom/xine_goom.c:204 msgid "frames per second to generate" @@ -3718,7 +3772,7 @@ msgstr "" #: src/post/mosaico/mosaico.c:129 msgid "Mosaico is a picture in picture (pip) post plugin" -msgstr "" +msgstr "Mosaico es un post-complemento de imagen en imagen (“pipâ€) " #: src/post/mosaico/mosaico.c:252 msgid "" @@ -3745,6 +3799,8 @@ msgstr "" msgid "" "Switch is a post plugin able to switch at any time between different streams" msgstr "" +"Switch es un post-complemento capaz de conmutar en cualquier momento entre " +"dos flujos diferentes" #: src/post/mosaico/switch.c:209 msgid "" @@ -3773,13 +3829,13 @@ msgstr "" "\n" "Parámetros\n" " Radius (radio): tamaño del filtro\n" -" Power (potencia): qué a menudo debería ser aplicado el filtro\n" +" Power (potencia): cuan a menudo debería ser aplicado el filtro\n" "\n" "* mplayer's boxblur (C) 2002 Michael Niedermayer\n" #: src/post/planar/boxblur.c:143 msgid "box blur filter from mplayer" -msgstr "" +msgstr "filtro caja borrosa de mplayer" #: src/post/planar/denoise3d.c:134 msgid "" @@ -3809,7 +3865,7 @@ msgstr "" #: src/post/planar/denoise3d.c:183 msgid "3D Denoiser (variable lowpass filter)" -msgstr "" +msgstr "“3D Denoiser†(filtro variable pasobajo antiruido)" #: src/post/planar/eq2.c:357 msgid "" @@ -3857,7 +3913,7 @@ msgstr "" #: src/post/planar/eq2.c:416 msgid "Software video equalizer" -msgstr "" +msgstr "Ecualizador de vídeo en software" #: src/post/planar/eq.c:184 msgid "" @@ -3889,12 +3945,14 @@ msgstr "" #: src/post/planar/eq.c:235 msgid "soft video equalizer" -msgstr "" +msgstr "ecualizador blando de vídeo" #: src/post/planar/expand.c:137 msgid "" "add black borders to top and bottom of video to expand it to 4:3 aspect ratio" msgstr "" +"añade bordes negros al tope superior e inferior del vídeo para expandirlo a " +"la razón de aspecto 4:3" #: src/post/planar/expand.c:232 msgid "" @@ -3959,7 +4017,7 @@ msgstr "" #: src/post/planar/noise.c:452 msgid "Adds noise" -msgstr "" +msgstr "añade ruido" #: src/post/planar/pp.c:111 msgid "" @@ -3983,7 +4041,7 @@ msgstr "" #: src/post/planar/pp.c:155 msgid "plugin for ffmpeg libpostprocess" -msgstr "" +msgstr "complemento para libpostprocess ffmpeg " #: src/post/planar/unsharp.c:218 msgid "" @@ -4012,7 +4070,7 @@ msgid "" "\n" "* mplayer's unsharp (C) 2002 Remi Guyomarch\n" msgstr "" -"Unsharp mask / gaussian blur (Máscara de des-nitidez / borrosidad " +"Unsharp mask / gaussian blur (máscara de des-nitidez / borrosidad " "gaussiana)\n" "Es posible ajustar el ancho y altura de la matriz, tamaño impar en ambas " "direcciones (min = 3x3, máx = 13x11 o 11x13, usualmente algo entre 3x3 y " @@ -4041,107 +4099,111 @@ msgstr "" #: src/post/planar/unsharp.c:276 msgid "unsharp mask & gaussian blur" msgstr "" +"Unsharp mask & gaussian blur (máscara de des-nitidez y borrosidad gaussiana)" -#: src/vdr/input_vdr.c:183 src/vdr/input_vdr.c:223 src/vdr/input_vdr.c:2442 -#: src/vdr/input_vdr.c:2540 +# Cer: no lo tengo claro +#: src/vdr/input_vdr.c:183 src/vdr/input_vdr.c:223 src/vdr/input_vdr.c:1848 +#: src/vdr/input_vdr.c:1946 #, c-format msgid "%s: input event write: %s.\n" -msgstr "" +msgstr "%s: evento de entrada escribe: %s.\n" #: src/vdr/input_vdr.c:713 src/vdr/input_vdr.c:1137 #, c-format msgid "%s: buffer_pool_alloc() failed!\n" -msgstr "" +msgstr "%s: ¡buffer_pool_alloc() falló!\n" #: src/vdr/input_vdr.c:782 #, c-format msgid "%s: flush buffers (vb: %d, ab: %d, vf: %d, af: %d) %s.\n" -msgstr "" +msgstr "%s: vaciar tampones (vb: %d, ab: %d, vf: %d, af: %d) %s.\n" #: src/vdr/input_vdr.c:1476 #, c-format msgid "%s: shutting down rpc thread (timeout: %d ms) ...\n" -msgstr "" +msgstr "%s: cerrando el hilo rpc (temporizado: %d ms) ...\n" #: src/vdr/input_vdr.c:1500 -#, fuzzy, c-format +#, c-format msgid "%s: cancelling rpc thread in function %d...\n" -msgstr ": no puedo crear condición pthread: %s\n" +msgstr "%s: cancelando el hilo rpc en la función %d...\n" #: src/vdr/input_vdr.c:1507 -#, fuzzy, c-format +#, c-format msgid "%s: joining rpc thread ...\n" -msgstr "RTP: parando el hilo de lectura...\n" +msgstr "%s: uniendo el hilo rpc ...\n" #: src/vdr/input_vdr.c:1509 -#, fuzzy, c-format +#, c-format msgid "%s: rpc thread joined.\n" -msgstr "RTP: hilo de lectura terminado\n" +msgstr "%s: hilo rpc unido.\n" -#: src/vdr/input_vdr.c:2145 src/vdr/input_vdr.c:2159 src/vdr/input_vdr.c:2177 -#: src/vdr/input_vdr.c:2199 src/vdr/input_vdr.c:2221 -#, fuzzy, c-format +#: src/vdr/input_vdr.c:1587 src/vdr/input_vdr.c:1601 src/vdr/input_vdr.c:1619 +#: src/vdr/input_vdr.c:1641 src/vdr/input_vdr.c:1663 +#, c-format msgid "%s: failed to open '%s' (%s)\n" -msgstr "stdin: falló al abrir '%s'\n" +msgstr "%s: falló en abrir '%s' (%s)\n" -#: src/vdr/input_vdr.c:2161 +#: src/vdr/input_vdr.c:1603 msgid "timeout expired during setup phase" -msgstr "" +msgstr "expiró el límite de tiempo durante la fase de configuración" -#: src/vdr/input_vdr.c:2246 -#, fuzzy, c-format +#: src/vdr/input_vdr.c:1688 +#, c-format msgid "%s: failed to create socket for port %d (%s)\n" -msgstr "stdin: falló al abrir '%s'\n" +msgstr "%s: fallo al crear el socket para el puerto %d (%s)\n" -#: src/vdr/input_vdr.c:2260 -#, fuzzy, c-format +#: src/vdr/input_vdr.c:1702 +#, c-format msgid "%s: failed to connect to port %d (%s)\n" -msgstr "rtsp: falló en conectar a '%s'\n" +msgstr "%s: falló en conectar al puerto %d (%s)\n" -#: src/vdr/input_vdr.c:2267 +#: src/vdr/input_vdr.c:1709 #, c-format msgid "%s: socket opening (port %d) successful, fd = %d\n" -msgstr "" +msgstr "%s: abriendo socket (puerto %d) con éxito, fd = %d\n" -#: src/vdr/input_vdr.c:2295 -#, fuzzy, c-format +#: src/vdr/input_vdr.c:1737 +#, c-format msgid "%s: connecting to vdr.\n" -msgstr "%s: no se puede conectar a %s:%d\n" +msgstr "%s: conectando a vdr.\n" -#: src/vdr/input_vdr.c:2300 -#, fuzzy, c-format +#: src/vdr/input_vdr.c:1742 +#, c-format msgid "%s: failed to resolve hostname '%s' (%s)\n" -msgstr "stdin: falló al abrir '%s'\n" +msgstr "%s: falló al resolver el nombre de equipo '%s' (%s)\n" -#: src/vdr/input_vdr.c:2323 +#: src/vdr/input_vdr.c:1765 #, c-format msgid "%s: connecting to all sockets (port %d .. %d) was successful.\n" -msgstr "" +msgstr "%s: la conexión a todos los sockets (puerto %d .. %d) tuvo éxito.\n" -#: src/vdr/input_vdr.c:2363 +#: src/vdr/input_vdr.c:1805 #, c-format msgid "" "%s: MRL (%s) invalid! MRL should start with vdr://path/to/fifo/stream or " "netvdr://host:port where ':port' is optional.\n" msgstr "" +"%s: ¡MRL (%s) inválido! El MRL debiera empezar con vdr://camino/a/flujo/fifo " +"o netvdr://equipo:puerto donde ':puerto' es opcional.\n" -#: src/vdr/input_vdr.c:2373 -#, fuzzy, c-format +#: src/vdr/input_vdr.c:1815 +#, c-format msgid "%s: can't create new thread (%s)\n" -msgstr "input_rtp: no se puede crear un hilo nuevo (%s)\n" +msgstr "%s: no puedo crear nuevo hilo (%s)\n" -#: src/vdr/input_vdr.c:2654 +#: src/vdr/input_vdr.c:2060 msgid "VDR display device plugin" -msgstr "" +msgstr "complemento de dispositivo de visualización VDR" #: src/vdr/post_vdr_video.c:104 msgid "modifies every video frame as requested by VDR" -msgstr "" +msgstr "modifica todos los cuadros de vídeo como lo pida el VDR" #: src/vdr/post_vdr_video.c:415 #, c-format msgid ": osd: (%d, %d)-(%d, %d)@%lg\n" -msgstr "" +msgstr ": vep: (%d, %d)-(%d, %d)@%lg\n" #: src/video_out/video_out_aa.c:298 msgid "xine video output plugin using the ascii-art library" @@ -4197,10 +4259,10 @@ msgid "video colour key" msgstr "llave de color de vídeo" #: src/video_out/video_out_directfb.c:1365 -#: src/video_out/video_out_vidix.c:1148 src/video_out/video_out_vidix.c:1155 -#: src/video_out/video_out_vidix.c:1162 src/video_out/video_out_xcbxv.c:1267 -#: src/video_out/video_out_xv.c:1320 src/video_out/video_out_xvmc.c:1415 -#: src/video_out/video_out_xxmc.c:2562 +#: src/video_out/video_out_vidix.c:1160 src/video_out/video_out_vidix.c:1167 +#: src/video_out/video_out_vidix.c:1174 src/video_out/video_out_xcbxv.c:1279 +#: src/video_out/video_out_xv.c:1332 src/video_out/video_out_xvmc.c:1427 +#: src/video_out/video_out_xxmc.c:2574 msgid "" "The colour key is used to tell the graphics card where to overlay the video " "image. Try different values, if you experience windows becoming transparent." @@ -4306,7 +4368,7 @@ msgstr "complemento de xine de salida de vídeo usando DirectFB bajo XDirectFB." msgid "xine video output plugin for win32 using directx" msgstr "complemento de xine de salida de vídeo para win32 usando directx" -#: src/video_out/video_out_fb.c:746 +#: src/video_out/video_out_fb.c:758 #, c-format msgid "" "video_out_fb: only packed truecolour/directcolour is supported (%d).\n" @@ -4316,11 +4378,11 @@ msgstr "" "directo) empaquetado (%d).\n" " Compruebe 'fbset -i' o pruebe 'fbset -depth 16'.\n" -#: src/video_out/video_out_fb.c:806 src/video_out/video_out_vidix.c:1220 +#: src/video_out/video_out_fb.c:818 src/video_out/video_out_vidix.c:1232 msgid "framebuffer device name" msgstr "nombre del dispositivo framebuffer" -#: src/video_out/video_out_fb.c:807 src/video_out/video_out_vidix.c:1221 +#: src/video_out/video_out_fb.c:819 src/video_out/video_out_vidix.c:1233 msgid "" "Specifies the file name for the framebuffer device to be used.\n" "This setting is security critical, because when changed to a different file, " @@ -4334,55 +4396,56 @@ msgstr "" "arbitrario. De modo que debería ser cuidadoso de que el valor que introduzca " "es realmente un verdadero dispositivo framebuffer." -#: src/video_out/video_out_fb.c:881 -#, fuzzy, c-format +#: src/video_out/video_out_fb.c:893 +#, c-format msgid "%s: Your video mode was not recognized, sorry.\n" -msgstr "video_out_fb: Lo sentimos, su modo de vídeo no fue reconocido .\n" +msgstr "%s: Lo sentimos, su modo de vídeo no fue reconocido.\n" -#: src/video_out/video_out_fb.c:938 -#, fuzzy, c-format +# CER: hacer update-po, no coincide con el fuente. +#: src/video_out/video_out_fb.c:950 +#, c-format msgid "%s: %d video RAM buffers are available.\n" -msgstr "video_out_fb: están disponibles %d tampones de vídeo en RAM.\n" +msgstr "%s: están disponibles %d tampones de vídeo en RAM.\n" -#: src/video_out/video_out_fb.c:944 -#, fuzzy, c-format +#: src/video_out/video_out_fb.c:956 +#, c-format msgid "" "WARNING: %s: Zero copy buffers are DISABLED because only %d buffers\n" " are available which is less than the recommended %d buffers. Lowering\n" " the frame buffer resolution might help.\n" msgstr "" -"AVISO: video_out_fb: Tampones Zero copy (copia Cero) están DESACTIVADOS " -"porque sólo %d tampones\n" -" están disponibles que son menos que los recomendados %d tampones. " -"Disminuyendo\n" -" la resolución del tampón de cuadro podría ayudar.\n" +"AVISO: %s: Tampones “zero copy†(copia Cero) están DESACTIVADOS porque sólo " +"hay\n" +" disponibles %d tampones lo cual es menos que los recomendados %d " +"tampones.\n" +" Disminuir la resolución del tampón de cuadro podría ayudar.\n" # Cer: panning --> panoramizado # frame flips --> volteos de cuadro # Zero copy buffers --> tampones copia cero -#: src/video_out/video_out_fb.c:955 -#, fuzzy, c-format +#: src/video_out/video_out_fb.c:967 +#, c-format msgid "" "WARNING: %s: Zero copy buffers are DISABLED because kernel driver\n" " do not support screen panning (used for frame flips).\n" msgstr "" -"AVISO: video_out_fb: Los tampones copia cero están DESACTIVADOS porque el " -"driver del kernel\n" +"AVISO: %s: Los tampones copia cero están DESACTIVADOS porque el driver del " +"kernel\n" " no soporta panoramizado de pantalla (usado para volteos de cuadro ).\n" -#: src/video_out/video_out_fb.c:1024 -#, fuzzy, c-format +#: src/video_out/video_out_fb.c:1036 +#, c-format msgid "" "WARNING: %s: current display depth is %d. For better performance\n" " a depth of 16 bpp is recommended!\n" "\n" msgstr "" -"AVISO: video_out_fb: la profundidad actual de pantalla es %d. ¡Para tener " -"mejor rendimiento \n" +"AVISO: %s: la profundidad actual de pantalla es %d. ¡Para tener mejor " +"rendimiento \n" " se recomienda una profundidad de 16 bpp!\n" "\n" -#: src/video_out/video_out_fb.c:1055 +#: src/video_out/video_out_fb.c:1067 msgid "Xine video output plugin using the Linux frame buffer device" msgstr "" "Complemento de xine de salida de vídeo usando el dispositivo Linux tampón de " @@ -4464,9 +4527,9 @@ msgstr "" "Frecuencia mínima de cuadro para rutinas animadas de renderizado.\n" "Ignorado para rutinas estáticas de renderizado.\n" -#: src/video_out/video_out_opengl.c:1915 src/video_out/video_out_vidix.c:1012 -#: src/video_out/video_out_xcbxv.c:1299 src/video_out/video_out_xv.c:1352 -#: src/video_out/video_out_xvmc.c:1429 src/video_out/video_out_xxmc.c:2594 +#: src/video_out/video_out_opengl.c:1915 src/video_out/video_out_vidix.c:1024 +#: src/video_out/video_out_xcbxv.c:1311 src/video_out/video_out_xv.c:1364 +#: src/video_out/video_out_xvmc.c:1441 src/video_out/video_out_xxmc.c:2606 msgid "enable double buffering" msgstr "activar doble tamponeado" @@ -4503,10 +4566,8 @@ msgstr "" "(framebuffer) pgx32\n" #: src/video_out/video_out_pgx32.c:864 -#, fuzzy msgid "xine video output plugin for Sun PGX32 framebuffers" -msgstr "" -"complemento de salida de vídeo usando libvidix para frame buffer de linux" +msgstr "complemento de salida de vídeo para tampón de cuadro Sun PGX32 " # Cer: Mmm, coger :-? #: src/video_out/video_out_pgx64.c:278 @@ -4567,9 +4628,9 @@ msgstr "" msgid "video_out_pgx64: Error: ioctl failed (FBIOGATTR)\n" msgstr "video_out_pgx64: Error: falló ioctl (FBIOGATTR)\n" -#: src/video_out/video_out_pgx64.c:1453 src/video_out/video_out_xcbxv.c:1266 -#: src/video_out/video_out_xv.c:1319 src/video_out/video_out_xvmc.c:1414 -#: src/video_out/video_out_xxmc.c:2561 +#: src/video_out/video_out_pgx64.c:1453 src/video_out/video_out_xcbxv.c:1278 +#: src/video_out/video_out_xv.c:1331 src/video_out/video_out_xvmc.c:1426 +#: src/video_out/video_out_xxmc.c:2573 msgid "video overlay colour key" msgstr "llave de color de superposición de vídeo" @@ -4608,16 +4669,16 @@ msgstr "" "gráfica." #: src/video_out/video_out_pgx64.c:1487 -#, fuzzy msgid "xine video output plugin for Sun XVR100/PGX64/PGX24 framebuffers" msgstr "" -"complemento de salida de vídeo usando libvidix para frame buffer de linux" +"complemento de xine de salida de vídeo para tampones-de-cuadro Sun XVR100/" +"PGX64/PGX24" -#: src/video_out/video_out_sdl.c:480 +#: src/video_out/video_out_sdl.c:488 msgid "use hardware acceleration if available" msgstr "use aceleración gráfica si está disponible" -#: src/video_out/video_out_sdl.c:481 +#: src/video_out/video_out_sdl.c:489 msgid "" "When your system supports it, hardware acceleration provided by your " "graphics hardware will be used. This might not work, so you can disable it, " @@ -4627,17 +4688,17 @@ msgstr "" "por su hardware gráfico. Esto podría no funcionar, así que lo puede " "desactivar, si las cosas van mal." -#: src/video_out/video_out_sdl.c:523 +#: src/video_out/video_out_sdl.c:531 msgid "sdl has to emulate a 16 bit surfaces, that will slow things down.\n" msgstr "" "sdl tiene que emular superficies de16 bit, que enlentecerán las cosas.\n" -#: src/video_out/video_out_sdl.c:560 +#: src/video_out/video_out_sdl.c:568 msgid "video_out_sdl: fullscreen mode is NOT supported\n" msgstr "video_out_sdl: el modo de pantalla completa NO está soportado\n" # Cer: traducción incierta -#: src/video_out/video_out_sdl.c:582 +#: src/video_out/video_out_sdl.c:590 msgid "xine video output plugin using the Simple Direct Media Layer" msgstr "" "complemento de xine de salida de vídeo usando la Capa Simple de Medios " @@ -4648,118 +4709,33 @@ msgid "xine video output plugin using the Libstk Surface Set-top Toolkit" msgstr "" "complemento de vídeo de xine usando el \"Libstk Surface Set-top Toolkit\"" -#: src/video_out/video_out_syncfb.c:280 -msgid "video_out_syncfb: error. (YUY2 not supported by your graphic card)\n" -msgstr "" -"video_out_syncfb: error. (YUY2 no está soportado por su tarjeta gráfica)\n" - -#: src/video_out/video_out_syncfb.c:296 -msgid "video_out_syncfb: error. (YV12 not supported by your graphic card)\n" -msgstr "" -"video_out_syncfb: error. (YV12 no está soportado por su tarjeta gráfica)\n" - -#: src/video_out/video_out_syncfb.c:938 -msgid "video_out_syncfb: info. (SyncFB module supports YUV 4:2:0 (3 plane))\n" -msgstr "video_out_syncfb: info. (módulo SyncFB soporta YUV 4:2:0 (3 planos))\n" - -#: src/video_out/video_out_syncfb.c:943 -msgid "video_out_syncfb: info. (SyncFB module supports YUV 4:2:0 (2 plane))\n" -msgstr "video_out_syncfb: info. (módulo SyncFB soporta YUV 4:2:0 (2 planos))\n" - -#: src/video_out/video_out_syncfb.c:948 -msgid "video_out_syncfb: info. (SyncFB module supports YUV 4:2:2)\n" -msgstr "video_out_syncfb: info. (módulo SyncFB soporta YUV 4:2:2)\n" - -#: src/video_out/video_out_syncfb.c:954 -msgid "video_out_syncfb: info. (SyncFB module supports YUY2)\n" -msgstr "video_out_syncfb: info. (módulo SyncFB soporta YUY2)\n" - -#: src/video_out/video_out_syncfb.c:961 -msgid "video_out_syncfb: info. (SyncFB module supports RGB565)\n" -msgstr "video_out_syncfb: info. (módulo SyncFB soporta RGB565)\n" - -#: src/video_out/video_out_syncfb.c:966 -msgid "" -"video_out_syncfb: aborting. (SyncFB module does not support YV12, YUY2 nor " -"RGB565)\n" -msgstr "" -"video_out_syncfb: abortando. (módulo SyncFB no soporta YV12, YUY2 ni " -"RGB565)\n" - -#: src/video_out/video_out_syncfb.c:985 -msgid "" -"video_out_syncfb: info. (brightness/contrast control won't be available " -"because your SyncFB kernel module seems to be outdated. Please refer to " -"README.syncfb for informations on how to update it.)\n" -msgstr "" -"video_out_syncfb: info. (control de brillo/contraste no estará disponible " -"porque su módulo del kernel SyncFB parece estar anticuado. Por favor, " -"refiérase a README.syncfb para información sobre como actualizarlo.)\n" - -#: src/video_out/video_out_syncfb.c:1009 -msgid "default number of frame repetitions" -msgstr "número por defecto de repeticiones de cuadros" - -#: src/video_out/video_out_syncfb.c:1010 -msgid "" -"This specifies how many times a single video frame will be displayed " -"consecutively." -msgstr "" -"Esto especifica cuantas veces se mostrará consecutivamente el mismo cuadro " -"de vídeo." - -#: src/video_out/video_out_syncfb.c:1060 -msgid "SyncFB device name" -msgstr "Nombre de dispositivo de SyncFB" - -#: src/video_out/video_out_syncfb.c:1061 -msgid "" -"Specifies the file name for the SyncFB (TeleTux) device to be used.\n" -"This setting is security critical, because when changed to a different file, " -"xine can be used to fill this file with arbitrary content. So you should be " -"careful that the value you enter really is a proper framebuffer device." -msgstr "" -"Especifica el nombre de fichero para el dispositivo SyncFB (TeleTux) a ser " -"usado.\n" -"Este ajuste es crítico para la seguridad, porque cuando se cambia a un " -"fichero diferente, xine puede usarse para llenar este fichero con contenido " -"arbitrario. Así que debiera ser cuidadoso con que el valor que introduzca " -"sea realmente un dispositivo framebuffer adecuado." - -#: src/video_out/video_out_syncfb.c:1084 -msgid "" -"xine video output plugin using the SyncFB module for Matrox G200/G400 cards" -msgstr "" -"complemento de vídeo de xine usando el módulo SyncFB para tarjetas Matrox " -"G200/G400" - -#: src/video_out/video_out_vidix.c:990 +#: src/video_out/video_out_vidix.c:1002 msgid "red intensity" msgstr "intensidad de rojo " -#: src/video_out/video_out_vidix.c:990 +#: src/video_out/video_out_vidix.c:1002 msgid "The intensity of the red colour components." msgstr "La intensidad de los componentes de color rojo." -#: src/video_out/video_out_vidix.c:995 +#: src/video_out/video_out_vidix.c:1007 msgid "green intensity" msgstr "intensidad de verde" -#: src/video_out/video_out_vidix.c:995 +#: src/video_out/video_out_vidix.c:1007 msgid "The intensity of the green colour components." msgstr "La intensidad de los componentes de color verde." -#: src/video_out/video_out_vidix.c:1000 +#: src/video_out/video_out_vidix.c:1012 msgid "blue intensity" msgstr "intensidad de azul" -#: src/video_out/video_out_vidix.c:1000 +#: src/video_out/video_out_vidix.c:1012 msgid "The intensity of the blue colour components." msgstr "La intensidad de los componentes de color azul." -#: src/video_out/video_out_vidix.c:1013 src/video_out/video_out_xcbxv.c:1300 -#: src/video_out/video_out_xv.c:1353 src/video_out/video_out_xvmc.c:1430 -#: src/video_out/video_out_xxmc.c:2595 +#: src/video_out/video_out_vidix.c:1025 src/video_out/video_out_xcbxv.c:1312 +#: src/video_out/video_out_xv.c:1365 src/video_out/video_out_xvmc.c:1442 +#: src/video_out/video_out_xxmc.c:2607 msgid "" "Double buffering will synchronize the update of the video image to the " "repainting of the entire screen (\"vertical retrace\"). This eliminates " @@ -4770,45 +4746,45 @@ msgstr "" "vertical). Esto elimina el parpadeo y artifactos de rajado, pero usa más " "memoria gráfica." -#: src/video_out/video_out_vidix.c:1060 +#: src/video_out/video_out_vidix.c:1072 msgid "video_out_vidix: adaptor supports the yuy2 format\n" msgstr "video_out_vidix: el adaptador soporta el formato yuy2\n" -#: src/video_out/video_out_vidix.c:1071 +#: src/video_out/video_out_vidix.c:1083 msgid "video_out_vidix: adaptor supports the yv12 format\n" msgstr "video_out_vidix: el adaptador soporta el formato yv12\n" -#: src/video_out/video_out_vidix.c:1087 +#: src/video_out/video_out_vidix.c:1099 msgid "video_out_vidix: You have wrong version of VIDIX library\n" msgstr "" "video_out_vidix: Tiene usted la versión incorrecta de la librería VIDIX\n" -#: src/video_out/video_out_vidix.c:1095 +#: src/video_out/video_out_vidix.c:1107 msgid "video_out_vidix: Couldn't find working VIDIX driver\n" msgstr "video_out_vidix: No pude localizar el driver VIDIX que funcione\n" -#: src/video_out/video_out_vidix.c:1108 +#: src/video_out/video_out_vidix.c:1120 #, c-format msgid "video_out_vidix: using driver: %s by %s\n" msgstr "video_out_vidix: usando driver: %s por %s\n" -#: src/video_out/video_out_vidix.c:1147 +#: src/video_out/video_out_vidix.c:1159 msgid "video overlay colour key red component" msgstr "clave de componente rojo en superposición de vídeo" -#: src/video_out/video_out_vidix.c:1154 +#: src/video_out/video_out_vidix.c:1166 msgid "video overlay colour key green component" msgstr "clave de componente verde en superposición de vídeo" -#: src/video_out/video_out_vidix.c:1161 +#: src/video_out/video_out_vidix.c:1173 msgid "video overlay colour key blue component" msgstr "clave de componente azul en superposición de vídeo" -#: src/video_out/video_out_vidix.c:1195 +#: src/video_out/video_out_vidix.c:1207 msgid "xine video output plugin using libvidix for x11" msgstr "complemento de salida de vídeo usando libvidix para x11" -#: src/video_out/video_out_vidix.c:1269 +#: src/video_out/video_out_vidix.c:1281 msgid "xine video output plugin using libvidix for linux frame buffer" msgstr "" "complemento de salida de vídeo usando libvidix para frame buffer de linux" @@ -4816,7 +4792,7 @@ msgstr "" #: src/video_out/video_out_xcbshm.c:150 src/video_out/video_out_xshm.c:211 #, c-format msgid "%s: %s: allocating image\n" -msgstr "" +msgstr "%s: %s: ubicando imagen\n" #: src/video_out/video_out_xcbshm.c:152 src/video_out/video_out_xcbshm.c:162 #: src/video_out/video_out_xcbshm.c:174 src/video_out/video_out_xcbxv.c:260 @@ -4847,7 +4823,7 @@ msgstr "" msgid "%s: x11 error during shared memory XImage creation\n" msgstr "%s: x11 error durante creación de XImage en memoria compartida\n" -#: src/video_out/video_out_xcbshm.c:1096 src/video_out/video_out_xshm.c:1153 +#: src/video_out/video_out_xcbshm.c:1104 src/video_out/video_out_xshm.c:1161 #, c-format msgid "" "\n" @@ -4862,19 +4838,19 @@ msgstr "" "rendimiento se recomienda una profundidad de 16 bpp!\n" "\n" -#: src/video_out/video_out_xcbshm.c:1109 src/video_out/video_out_xshm.c:1166 +#: src/video_out/video_out_xcbshm.c:1117 src/video_out/video_out_xshm.c:1174 #, c-format msgid "%s: MIT shared memory extension not present on display.\n" msgstr "" "%s: la extensión de memoria compartida del MIT (MIT Shared Memory) no está " "presente en la pantalla.\n" -#: src/video_out/video_out_xcbshm.c:1208 src/video_out/video_out_xshm.c:1250 -#, fuzzy, c-format +#: src/video_out/video_out_xcbshm.c:1216 src/video_out/video_out_xshm.c:1258 +#, c-format msgid "%s: your video mode was not recognized, sorry :-(\n" -msgstr "video_out_fb: Lo sentimos, su modo de vídeo no fue reconocido .\n" +msgstr "%s: lo sentimos, su modo de vídeo no fue reconocido :-(\n" -#: src/video_out/video_out_xcbshm.c:1237 src/video_out/video_out_xshm.c:1298 +#: src/video_out/video_out_xcbshm.c:1245 src/video_out/video_out_xshm.c:1306 msgid "xine video output plugin using the MIT X shared memory extension" msgstr "" "complemento de salida de vídeo de xine usando la extensión de memoria " @@ -4893,18 +4869,18 @@ msgid "%s: shared memory error in shmget: %s\n" msgstr "%s: error de memoria compartida en shmget: %s\n" #: src/video_out/video_out_xcbxv.c:278 -#, fuzzy, c-format +#, c-format msgid "%s: shared memory error (address error)\n" -msgstr "%s: x11 error durante creación de XImage en memoria compartida\n" +msgstr "%s: error de memoria compartida (error de dirección)\n" -#: src/video_out/video_out_xcbxv.c:1120 src/video_out/video_out_xv.c:1167 -#: src/video_out/video_out_xxmc.c:2412 -#, fuzzy, c-format +#: src/video_out/video_out_xcbxv.c:1132 src/video_out/video_out_xv.c:1179 +#: src/video_out/video_out_xxmc.c:2424 +#, c-format msgid "%s: Xv extension not present.\n" -msgstr "video_out_xv: la extensión Xv no está presente.\n" +msgstr "%s: la extensión Xv no está presente.\n" -#: src/video_out/video_out_xcbxv.c:1162 src/video_out/video_out_xv.c:1204 -#: src/video_out/video_out_xxmc.c:2449 +#: src/video_out/video_out_xcbxv.c:1174 src/video_out/video_out_xv.c:1216 +#: src/video_out/video_out_xxmc.c:2461 #, c-format msgid "" "%s: Xv extension is present but I couldn't find a usable yuv12 port.\n" @@ -4914,7 +4890,7 @@ msgstr "" "usable.\n" " ¡¿Parece que su driver de hardware gráfico no soporta Xv?!\n" -#: src/video_out/video_out_xcbxv.c:1171 +#: src/video_out/video_out_xcbxv.c:1183 #, c-format msgid "" "%s: using Xv port %d from adaptor %s for hardware colour space conversion " @@ -4923,23 +4899,23 @@ msgstr "" "%s: usando puerto Xv %d del adaptador %s para conversión y escalado de " "espacio de color en hardware .\n" -#: src/video_out/video_out_xcbxv.c:1275 src/video_out/video_out_xv.c:1328 -#: src/video_out/video_out_xvmc.c:1423 src/video_out/video_out_xxmc.c:2570 +#: src/video_out/video_out_xcbxv.c:1287 src/video_out/video_out_xv.c:1340 +#: src/video_out/video_out_xvmc.c:1435 src/video_out/video_out_xxmc.c:2582 msgid "autopaint colour key" msgstr "llave de color autopintado" -#: src/video_out/video_out_xcbxv.c:1276 src/video_out/video_out_xv.c:1329 -#: src/video_out/video_out_xvmc.c:1424 src/video_out/video_out_xxmc.c:2571 +#: src/video_out/video_out_xcbxv.c:1288 src/video_out/video_out_xv.c:1341 +#: src/video_out/video_out_xvmc.c:1436 src/video_out/video_out_xxmc.c:2583 msgid "Make Xv autopaint its colour key." msgstr "Hacer Xv autopintar su llave de color." -#: src/video_out/video_out_xcbxv.c:1283 src/video_out/video_out_xv.c:1336 -#: src/video_out/video_out_xxmc.c:2578 +#: src/video_out/video_out_xcbxv.c:1295 src/video_out/video_out_xv.c:1348 +#: src/video_out/video_out_xxmc.c:2590 msgid "bilinear scaling mode" msgstr "modo de escalado bilineal" -#: src/video_out/video_out_xcbxv.c:1284 src/video_out/video_out_xv.c:1337 -#: src/video_out/video_out_xxmc.c:2579 +#: src/video_out/video_out_xcbxv.c:1296 src/video_out/video_out_xv.c:1349 +#: src/video_out/video_out_xxmc.c:2591 msgid "" "Selects the bilinear scaling mode for Permedia cards. The individual values " "are:\n" @@ -4965,40 +4941,39 @@ msgstr "" "1 - filtrado horizontal lineal\n" "2 - sactivar filtrado bilineal completo" -#: src/video_out/video_out_xcbxv.c:1336 src/video_out/video_out_xv.c:1386 -#: src/video_out/video_out_xxmc.c:2635 -#, fuzzy, c-format +#: src/video_out/video_out_xcbxv.c:1348 src/video_out/video_out_xv.c:1398 +#: src/video_out/video_out_xxmc.c:2647 +#, c-format msgid "%s: this adaptor supports the yv12 format.\n" -msgstr "video_out_directfb: ¡no se encontró una capa de salida usable!\n" +msgstr "%s: éste adaptador soporta el formato yv12.\n" -#: src/video_out/video_out_xcbxv.c:1341 src/video_out/video_out_xv.c:1391 -#: src/video_out/video_out_xxmc.c:2640 -#, fuzzy, c-format +#: src/video_out/video_out_xcbxv.c:1353 src/video_out/video_out_xv.c:1403 +#: src/video_out/video_out_xxmc.c:2652 +#, c-format msgid "%s: this adaptor supports the yuy2 format.\n" -msgstr "video_out_directfb: ¡no se encontró una capa de salida usable!\n" +msgstr "%s: éste adaptador soporta el formato yuy2.\n" -#: src/video_out/video_out_xcbxv.c:1349 src/video_out/video_out_xv.c:1413 -#: src/video_out/video_out_xxmc.c:2663 +#: src/video_out/video_out_xcbxv.c:1361 src/video_out/video_out_xv.c:1425 +#: src/video_out/video_out_xxmc.c:2675 msgid "pitch alignment workaround" msgstr "rodeo para alineamiento de paso" -#: src/video_out/video_out_xcbxv.c:1350 src/video_out/video_out_xv.c:1414 -#: src/video_out/video_out_xxmc.c:2664 +#: src/video_out/video_out_xcbxv.c:1362 src/video_out/video_out_xv.c:1426 +#: src/video_out/video_out_xxmc.c:2676 msgid "Some buggy video drivers need a workaround to function properly." msgstr "" "Algunos drivers de vídeo con errores necesitan un rodeo para que funcionen " "adecuadamente." -#: src/video_out/video_out_xcbxv.c:1377 src/video_out/video_out_xv.c:1460 -#: src/video_out/video_out_xxmc.c:2757 +#: src/video_out/video_out_xcbxv.c:1389 src/video_out/video_out_xv.c:1472 +#: src/video_out/video_out_xxmc.c:2769 msgid "xine video output plugin using the MIT X video extension" msgstr "complemento de salida de vídeo usando la extensión MIT X vídeo" #: src/video_out/video_out_xshm.c:194 -#, fuzzy, c-format +#, c-format msgid "%s: shared memory error when allocating image\n" -msgstr "" -"%s: error de memoria compartida (error de dirección) ) al ubicar imagen\n" +msgstr "%s: error de memoria compartida al ubicar imagen\n" #: src/video_out/video_out_xv.c:286 src/video_out/video_out_xxmc.c:640 #, c-format @@ -5008,7 +4983,7 @@ msgstr "" "video_out_xv: => no usando la extensión de memoria compartida MIT (MIT " "Shared Memory).\n" -#: src/video_out/video_out_xv.c:1214 src/video_out/video_out_xxmc.c:2459 +#: src/video_out/video_out_xv.c:1226 src/video_out/video_out_xxmc.c:2471 #, c-format msgid "" "%s: using Xv port %ld from adaptor %s for hardware colour space conversion " @@ -5017,11 +4992,11 @@ msgstr "" "%s: usando puerto Xv %ld del adaptador %s para conversión y escalado de " "espacio de color en hardware .\n" -#: src/video_out/video_out_xvmc.c:1540 +#: src/video_out/video_out_xvmc.c:1552 msgid "video_out_xvmc: XvMC extension not present.\n" msgstr "video_out_xvmc: extensión XvMC no presente.\n" -#: src/video_out/video_out_xvmc.c:1638 +#: src/video_out/video_out_xvmc.c:1650 msgid "" "video_out_xvmc: Xv extension is present but I couldn't find a usable yuv12 " "port.\n" @@ -5029,7 +5004,7 @@ msgstr "" "video_out_xvmc: la extensión Xv está presente pero no pude encontrar un " "puerto yuv12 usable.\n" -#: src/video_out/video_out_xvmc.c:1647 +#: src/video_out/video_out_xvmc.c:1659 #, c-format msgid "" "video_out_xvmc: using Xv port %ld from adaptor %s\n" @@ -5038,32 +5013,32 @@ msgstr "" "video_out_xvmc: usando puerto %ld de Xv del adaptador %s\n" " para conversión del espacio de color y escalado en hardware\n" -#: src/video_out/video_out_xvmc.c:1652 +#: src/video_out/video_out_xvmc.c:1664 msgid " idct and motion compensation acceleration \n" msgstr " compensación de movimiento y aceleración idct \n" -#: src/video_out/video_out_xvmc.c:1654 +#: src/video_out/video_out_xvmc.c:1666 msgid " motion compensation acceleration only\n" msgstr " sólo compensación de aceleración \n" -#: src/video_out/video_out_xvmc.c:1656 +#: src/video_out/video_out_xvmc.c:1668 msgid " no XvMC support \n" msgstr " sin soporte XvMC \n" -#: src/video_out/video_out_xvmc.c:1657 +#: src/video_out/video_out_xvmc.c:1669 #, c-format msgid " With Overlay = %d; UnsignedIntra = %d.\n" msgstr " Con Overlay = %d; UnsignedIntra = %d.\n" -#: src/video_out/video_out_xvmc.c:1670 +#: src/video_out/video_out_xvmc.c:1682 msgid "xine video output plugin using the XvMC X video extension" msgstr "complemento de vídeo de xine usando extensión de vídeo X XvMC" -#: src/video_out/video_out_xxmc.c:2669 +#: src/video_out/video_out_xxmc.c:2681 msgid "Make XvMC allocate more frames for better buffering." msgstr "Hacer que XvMC ubique más cuadros more cuadros para mejor tamponeado." -#: src/video_out/video_out_xxmc.c:2670 +#: src/video_out/video_out_xxmc.c:2682 msgid "" "Some XvMC implementations allow more than 8 frames.\n" "This option, when turned on, makes the driver try to\n" @@ -5073,11 +5048,11 @@ msgstr "" "Esta opción, cuando se activa, hace que el manejador trate de\n" "ubicar 15 cuadros. hay que tenerlo para VDR uni cromático y en vivo.\n" -#: src/video_out/video_out_xxmc.c:2676 +#: src/video_out/video_out_xxmc.c:2688 msgid "Unichrome cpu save" msgstr "Ahorro de cpu unichrome" -#: src/video_out/video_out_xxmc.c:2677 +#: src/video_out/video_out_xxmc.c:2689 msgid "" "Saves CPU time by sleeping while decoder works.\n" "Only for Linux kernel 2.6 series or 2.4 with multimedia patch.\n" @@ -5087,11 +5062,11 @@ msgstr "" "Sólo para Linux con kernel serie 2.6 series o 2.4 con parche multimedia.\n" "Experimental.\n" -#: src/video_out/video_out_xxmc.c:2683 +#: src/video_out/video_out_xxmc.c:2695 msgid "Fix buggy NVIDIA XvMC subpicture colours" msgstr "Arreglar colores de subimagen en NVIDIA XvMC con errores" -#: src/video_out/video_out_xxmc.c:2684 +#: src/video_out/video_out_xxmc.c:2696 msgid "" "There's a bug in NVIDIA's XvMC lib that makes red OSD colours\n" "look blue and vice versa. This option provides a workaround.\n" @@ -5100,25 +5075,24 @@ msgstr "" "rojo en el DEP aparezca como azul y viceversa.\n" "Esta opción proporciona un arreglo.\n" -#: src/video_out/video_out_xxmc.c:2689 +#: src/video_out/video_out_xxmc.c:2701 msgid "Use bob as accelerated deinterlace method." msgstr "Use «bob» como método acelerado de desentrelazado." -#: src/video_out/video_out_xxmc.c:2690 -#, fuzzy +#: src/video_out/video_out_xxmc.c:2702 msgid "" "When interlacing is enabled for hardware accelerated frames,\n" "alternate between top and bottom field at double the frame rate.\n" msgstr "" -"Cuando el entrelazado está activado para cuadros acelerados \n" -"en hardware, alterna entre el campo superior e inferior \n" +"Cuando el entrelazado está activado para cuadros acelerados\n" +"en hardware, alterna entre el campo superior e inferior\n" "al doble de la frecuencia de cuadro.\n" -#: src/video_out/video_out_xxmc.c:2696 +#: src/video_out/video_out_xxmc.c:2708 msgid "Don't use bob deinterlacing for progressive frames." msgstr "No usar desentrelazado «bob» para cuadros progresivos." -#: src/video_out/video_out_xxmc.c:2697 +#: src/video_out/video_out_xxmc.c:2709 msgid "" "Progressive frames don't need deinterlacing, so disabling it on\n" "demand should result in a better picture.\n" @@ -5126,12 +5100,12 @@ msgstr "" "Los cuadros progresivos no necesitan desentrelazado, de manera\n" "que desentrelazarlos bajo demanda no resultará en una mejor imagen.\n" -#: src/video_out/video_out_xxmc.c:2703 +#: src/video_out/video_out_xxmc.c:2715 msgid "Don't use bob deinterlacing while a scaled OSD is active." msgstr "" "No usar desentrelazado «bob» mientras una escalado de VEP (OSD) está activo." -#: src/video_out/video_out_xxmc.c:2704 +#: src/video_out/video_out_xxmc.c:2716 msgid "" "Bob deinterlacing adds some noise to horizontal lines, so disabling it\n" "on demand should result in a better OSD picture.\n" @@ -5206,37 +5180,36 @@ msgstr "" "entradas poco fiables, pero también aumentan la latencia y el consumo de " "memoria." -#: src/xine-engine/audio_out.c:1111 +#: src/xine-engine/audio_out.c:1112 msgid "" "audio_out: delay calculation impossible with an unavailable audio device\n" msgstr "" "audio_out: cálculo de retardo imposible con un dispositivo de sonido no " "disponible\n" -#: src/xine-engine/audio_out.c:1250 -#, fuzzy +#: src/xine-engine/audio_out.c:1251 msgid "write to sound card failed. Assuming the device was unplugged.\n" msgstr "" "la escritura a la tarjeta de sonido falló. Supondremos que el dispositivo se " "desconectó.\n" -#: src/xine-engine/audio_out.c:1422 +#: src/xine-engine/audio_out.c:1423 msgid "8 bits not supported by driver, converting to 16 bits.\n" msgstr "8 bits no soportados por el driver, convirtiendo a 16 bits.\n" -#: src/xine-engine/audio_out.c:1430 +#: src/xine-engine/audio_out.c:1431 msgid "mono not supported by driver, converting to stereo.\n" msgstr "mono no soportado por el driver, convirtiendo a estéreo.\n" -#: src/xine-engine/audio_out.c:1436 +#: src/xine-engine/audio_out.c:1437 msgid "stereo not supported by driver, converting to mono.\n" msgstr "estéreo no soportado por el driver, convirtiendo a mono.\n" -#: src/xine-engine/audio_out.c:2095 +#: src/xine-engine/audio_out.c:2100 msgid "method to sync audio and video" msgstr "método para sincronizar audio y vídeo" -#: src/xine-engine/audio_out.c:2096 +#: src/xine-engine/audio_out.c:2101 msgid "" "When playing audio and video, there are at least two clocks involved: The " "system clock, to which video frames are synchronized and the clock in your " @@ -5278,11 +5251,11 @@ msgstr "" "audio. Esto no funciona para para paso a través digital, donde los datos de " "audio se pasan a un decodificador externo en forma digital." -#: src/xine-engine/audio_out.c:2124 +#: src/xine-engine/audio_out.c:2129 msgid "enable resampling" msgstr "activar remuestreo (resampling)" -#: src/xine-engine/audio_out.c:2125 +#: src/xine-engine/audio_out.c:2130 msgid "" "When the sample rate of the decoded audio does not match the capabilities of " "your sound hardware, an adaptation called \"resampling\" is required. Here " @@ -5294,11 +5267,11 @@ msgstr "" "\"remuestreo\". Aquí puede seleccionar si se activa el remuestreo, se " "desactiva, o se usa automáticamente cuando sea necesario." -#: src/xine-engine/audio_out.c:2132 +#: src/xine-engine/audio_out.c:2137 msgid "always resample to this rate (0 to disable)" msgstr "siempre remuestrear a ésta cadencia (0 para desactivar)" -#: src/xine-engine/audio_out.c:2133 +#: src/xine-engine/audio_out.c:2138 msgid "" "Some audio drivers do not correctly announce the capabilities of the audio " "hardware. By setting a value other than zero here, you can force the audio " @@ -5308,11 +5281,11 @@ msgstr "" "hardware de audio. Poniendo este valor a algo distinto de cero aquí, puede " "forzar el flujo de datos de audio a ser remuestreado a la cadencia dada." -#: src/xine-engine/audio_out.c:2142 +#: src/xine-engine/audio_out.c:2147 msgid "offset for digital passthrough" msgstr "compensación para paso a través digital" -#: src/xine-engine/audio_out.c:2143 +#: src/xine-engine/audio_out.c:2148 msgid "" "If you use an external surround decoder and audio is ahead or behind video, " "you can enter a fixed offset here to compensate.\n" @@ -5323,11 +5296,11 @@ msgstr "" "para compensar.\n" "Las unidades del valor es una marca PTS, que es 1/90000 segundo." -#: src/xine-engine/audio_out.c:2152 +#: src/xine-engine/audio_out.c:2157 msgid "play audio even on slow/fast speeds" msgstr "reproduzca vídeo incluso a velocidades lentas/rápidas" -#: src/xine-engine/audio_out.c:2153 +#: src/xine-engine/audio_out.c:2158 msgid "" "If you enable this option, the audio will be heard even when playback speed " "is different than 1X. Of course, it will sound distorted (lower/higher " @@ -5336,27 +5309,27 @@ msgid "" msgstr "" "Si activa esta opción, el audio se escuchará incluso cuando la velocidad de " "reproducción no sea 1X. Por supuesto, sonará distorsionado (tono más agudo o " -"grave). Si desea experimentar preservando el tono, puede probar el " -"postcomplemento de sonido 'stretch' en su lugar." +"grave). Si desea experimentar preservando el tono, puede probar el post-" +"complemento de sonido 'stretch' en su lugar." -#: src/xine-engine/audio_out.c:2226 +#: src/xine-engine/audio_out.c:2231 msgid "startup audio volume" msgstr "volumen de audio inicial" -#: src/xine-engine/audio_out.c:2227 +#: src/xine-engine/audio_out.c:2232 msgid "The overall audio volume set at xine startup." msgstr "El volumen de sonido al arrancar xine." -#: src/xine-engine/audio_out.c:2230 +#: src/xine-engine/audio_out.c:2235 msgid "restore volume level at startup" msgstr "restaurar el nivel del volumen al arrancar" -#: src/xine-engine/audio_out.c:2231 +#: src/xine-engine/audio_out.c:2236 msgid "If disabled, xine will not modify any mixer settings at startup." msgstr "" "Si se desactiva, xine no modificará ningún ajuste del mezclador al arrancar." -#: src/xine-engine/audio_out.c:2261 +#: src/xine-engine/audio_out.c:2266 msgid "audio_out: sorry, this should not happen. please restart xine.\n" msgstr "" "audio_out: lo siento, ésto no debiera ocurrir. Por favor reinicie xine.\n" @@ -5368,41 +5341,41 @@ msgstr "" "xine-lib: buffer.c: Ha ocurrido un error fatal: DEMASIADAS LIBERACIONES DE " "MEMORIA (FREE'S)\n" -#: src/xine-engine/configfile.c:933 +#: src/xine-engine/configfile.c:943 #, c-format msgid "The current config file has been modified by a newer version of xine." msgstr "" "El fichero actual de configuración ha sido modificado por una versión de " "xine más nueva." -#: src/xine-engine/configfile.c:1038 +#: src/xine-engine/configfile.c:1048 #, c-format msgid "configfile: WARNING: backing up configfile to %s failed\n" msgstr "" "configfile: AVISO: la copia de seguridad del fichero de configuración a %s " "falló\n" -#: src/xine-engine/configfile.c:1039 +#: src/xine-engine/configfile.c:1049 msgid "configfile: WARNING: your configuration will not be saved\n" msgstr "configfile: AVISO: su configuración no será guardada\n" -#: src/xine-engine/configfile.c:1138 +#: src/xine-engine/configfile.c:1149 #, c-format msgid "configfile: WARNING: writing configuration to %s failed\n" msgstr "configfile: AVISO: la escritura de la configuración a %s falló\n" -#: src/xine-engine/configfile.c:1139 +#: src/xine-engine/configfile.c:1150 #, c-format msgid "configfile: WARNING: removing possibly broken config file %s\n" msgstr "" "configfile: AVISO: eliminando fichero de configuración %s posiblemente roto\n" -#: src/xine-engine/configfile.c:1140 +#: src/xine-engine/configfile.c:1151 #, c-format msgid "configfile: WARNING: you should check the backup file %s\n" msgstr "configfile: AVISO: debería comprobar el fichero de respaldo %s\n" -#: src/xine-engine/configfile.c:1275 +#: src/xine-engine/configfile.c:1606 #, c-format msgid "configfile: entry '%s' mustn't be modified from MRL\n" msgstr "configfile: la entrada '%s' no debería ser modificada desde MRL\n" @@ -5449,7 +5422,7 @@ msgstr "input_rip: error escribiendo al fichero %<PRIdMAX> bytes: %s\n" #: src/xine-engine/input_rip.c:183 #, c-format msgid "input_rip: open() function should never be called\n" -msgstr "" +msgstr "input_rip: la función open() no debiera ser nunca llamada\n" #: src/xine-engine/input_rip.c:314 src/xine-engine/input_rip.c:419 #, c-format @@ -5542,12 +5515,12 @@ msgstr "io_helper: Fichero no encontrado\n" msgid "io_helper: Connection Refused\n" msgstr "io_helper: Conexión Rechazada\n" -#: src/xine-engine/load_plugins.c:213 +#: src/xine-engine/load_plugins.c:216 #, c-format msgid "map_decoder_list: no space for decoder, skipped.\n" msgstr "map_decoder_list: no hay espacio para el decodificador, omitido.\n" -#: src/xine-engine/load_plugins.c:327 +#: src/xine-engine/load_plugins.c:331 #, c-format msgid "" "load_plugins: ignoring plugin %s, wrong iface version %d (should be %d)\n" @@ -5555,13 +5528,13 @@ msgstr "" "load_plugins: ignorando complemento%s, versión \"iface\" equivocada%d " "(debería ser %d)\n" -#: src/xine-engine/load_plugins.c:385 +#: src/xine-engine/load_plugins.c:390 #, c-format msgid "priority for %s decoder" msgstr "prioridad para decodificador %s" # CER: ¿rank? -#: src/xine-engine/load_plugins.c:390 +#: src/xine-engine/load_plugins.c:395 msgid "" "The priority provides a ranking in case some media can be handled by more " "than one decoder.\n" @@ -5571,7 +5544,7 @@ msgstr "" "manejado por más de un decodificador.\n" "Una prioridad de 0 activa la prioridad por omisión del decodificador." -#: src/xine-engine/load_plugins.c:418 +#: src/xine-engine/load_plugins.c:423 #, c-format msgid "" "load_plugins: demuxer plugin %s does not provide a priority, xine-lib will " @@ -5580,7 +5553,7 @@ msgstr "" "load_plugins: el complemento desmultiplexor %s no proporciona una prioridad, " "xine-lib usará la prioridad por defecto.\n" -#: src/xine-engine/load_plugins.c:435 +#: src/xine-engine/load_plugins.c:440 #, c-format msgid "" "load_plugins: input plugin %s does not provide a priority, xine-lib will use " @@ -5589,47 +5562,47 @@ msgstr "" "load_plugins: el complemento de entrada %s no proporciona una prioridad, " "xine-lib usará la prioridad por defecto.\n" -#: src/xine-engine/load_plugins.c:491 +#: src/xine-engine/load_plugins.c:497 #, c-format msgid "load_plugins: plugin %s found\n" msgstr "load_plugins: encontrado complemento %s\n" -#: src/xine-engine/load_plugins.c:494 +#: src/xine-engine/load_plugins.c:500 #, c-format msgid "load_plugins: static plugin found\n" msgstr "load_plugins: encontrado complemento estático\n" -#: src/xine-engine/load_plugins.c:501 +#: src/xine-engine/load_plugins.c:507 #, c-format msgid "load_plugins: plugin limit reached, %s could not be loaded\n" msgstr "" "load_plugins: alcanzado límite de complementos, %s no pudo ser cargado\n" -#: src/xine-engine/load_plugins.c:504 +#: src/xine-engine/load_plugins.c:510 #, c-format msgid "load_plugins: plugin limit reached, static plugin could not be loaded\n" msgstr "" "load_plugins: alcanzado límite de complementos, complemento estático no " "pudo ser cargado\n" -#: src/xine-engine/load_plugins.c:521 +#: src/xine-engine/load_plugins.c:527 #, c-format msgid "load_plugins: unknown plugin type %d in %s\n" msgstr "load_plugins: tipo de complemento desconocido %d en %s\n" -#: src/xine-engine/load_plugins.c:525 +#: src/xine-engine/load_plugins.c:531 #, c-format msgid "load_plugins: unknown statically linked plugin type %d\n" msgstr "" "load_plugins: tipo de complemento estáticamente ligado desconocido %d\n" # CER: ¿stat? -#: src/xine-engine/load_plugins.c:585 +#: src/xine-engine/load_plugins.c:594 #, c-format msgid "load_plugins: unable to stat %s\n" msgstr "load_plugins: incapaz de obtener estado %s\n" -#: src/xine-engine/load_plugins.c:626 +#: src/xine-engine/load_plugins.c:636 #, c-format msgid "" "load_plugins: cannot open plugin lib %s:\n" @@ -5638,7 +5611,7 @@ msgstr "" "load_plugins: no puedo abrir librería de complemento %s:\n" "%s\n" -#: src/xine-engine/load_plugins.c:641 +#: src/xine-engine/load_plugins.c:651 #, c-format msgid "" "load_plugins: can't get plugin info from %s:\n" @@ -5647,12 +5620,12 @@ msgstr "" "load_plugins: no puedo conseguir información del complemento de %s:\n" "%s\n" -#: src/xine-engine/load_plugins.c:659 +#: src/xine-engine/load_plugins.c:669 #, c-format msgid "load_plugins: skipping unreadable plugin directory %s.\n" msgstr "load_plugins: omitiendo directorio de complementos ilegible %s.\n" -#: src/xine-engine/load_plugins.c:708 +#: src/xine-engine/load_plugins.c:737 #, c-format msgid "" "load_plugins: cannot (stage 2) open plugin lib %s:\n" @@ -5661,32 +5634,32 @@ msgstr "" "load_plugins: no puedo (etapa 2) abrir librería de complementos %s:\n" "%s\n" -#: src/xine-engine/load_plugins.c:734 +#: src/xine-engine/load_plugins.c:771 #, c-format msgid "load_plugins: Yikes! %s doesn't contain plugin info.\n" msgstr "load_plugins: ¡Ondiá! %s no contiene información del complemento.\n" -#: src/xine-engine/load_plugins.c:1097 src/xine-engine/load_plugins.c:1106 -#, fuzzy, c-format +#: src/xine-engine/load_plugins.c:1175 src/xine-engine/load_plugins.c:1184 +#, c-format msgid "Unable to create %s directory: %s\n" -msgstr "Incapaz de crear el objeto de sonido directo." +msgstr "Incapaz de crear el directorio %s: %s\n" -#: src/xine-engine/load_plugins.c:1343 +#: src/xine-engine/load_plugins.c:1421 #, c-format msgid "load_plugins: unknown content detection strategy %d\n" msgstr "load_plugins: estrategia %d de detección de contenido desconocida\n" -#: src/xine-engine/load_plugins.c:1468 +#: src/xine-engine/load_plugins.c:1546 #, c-format msgid "load_plugins: using demuxer '%s'\n" msgstr "load_plugins: usando desmultiplexor '%s'\n" -#: src/xine-engine/load_plugins.c:1763 src/xine-engine/load_plugins.c:1810 +#: src/xine-engine/load_plugins.c:1841 src/xine-engine/load_plugins.c:1888 #, c-format msgid "load_plugins: failed to load audio output plugin <%s>\n" msgstr "load_plugins: fallé al cargar complemento de salida de audio <%s>\n" -#: src/xine-engine/load_plugins.c:1813 +#: src/xine-engine/load_plugins.c:1891 msgid "" "load_plugins: audio output auto-probing didn't find any usable audio " "driver.\n" @@ -5694,7 +5667,7 @@ msgstr "" "load_plugins: el auto-probado de salida de audio no encontró ningún driver " "de audio usable audio.\n" -#: src/xine-engine/load_plugins.c:2116 +#: src/xine-engine/load_plugins.c:2194 #, c-format msgid "" "load_plugins: cannot unload plugin lib %s:\n" @@ -5735,9 +5708,9 @@ msgid "osd: error looking up font %s with FontConfig" msgstr "osd: error buscando tipografía %s con FontConfig" #: src/xine-engine/osd.c:996 -#, fuzzy, c-format +#, c-format msgid "osd: error loading font %s with in XDG data directories.\n" -msgstr "osd: error cargando tipografía %s con ft2\n" +msgstr "osd: error cargando tipografía %s con directorios de datos XDG\n" #: src/xine-engine/osd.c:1005 msgid "osd: cannot initialize ft2 library\n" @@ -5802,11 +5775,12 @@ msgstr "" #: src/xine-engine/spu.c:36 msgid "opacity for the black parts of bitmapped subtitles" -msgstr "" +msgstr "opacidad para las partes negras de los subtítulos mapeados por bits" #: src/xine-engine/spu.c:41 msgid "opacity for the colour parts of bitmapped subtitles" msgstr "" +"opacidad para las partes coloreadas de los subtítulos mapeados por bits" #: src/xine-engine/video_decoder.c:387 #, c-format @@ -5888,11 +5862,11 @@ msgid "video_out: sorry, this should not happen. please restart xine.\n" msgstr "" "video_out: Lo siento, esto no debería ocurrir. Por favor, reinicie xine.\n" -#: src/xine-engine/vo_scale.c:387 +#: src/xine-engine/vo_scale.c:380 msgid "horizontal image position in the output window" msgstr "posición horizontal de la imagen en la ventana de salida" -#: src/xine-engine/vo_scale.c:388 +#: src/xine-engine/vo_scale.c:381 msgid "" "If the video window's horizontal size is bigger than the actual image to " "show, you can adjust the position where the image will be placed.\n" @@ -5905,11 +5879,11 @@ msgstr "" "\"en el centro\", mientras que 0 significa \"a la izquierda del todo\" y 100 " "\"a la deracha del todo\"." -#: src/xine-engine/vo_scale.c:395 +#: src/xine-engine/vo_scale.c:388 msgid "vertical image position in the output window" msgstr "posición vertical de la imagen en la ventana de salida" -#: src/xine-engine/vo_scale.c:396 +#: src/xine-engine/vo_scale.c:389 msgid "" "If the video window's vertical size is bigger than the actual image to show, " "you can adjust the position where the image will be placed.\n" @@ -5922,11 +5896,11 @@ msgstr "" "\"en el centro\", mientras que 0 significa\"arriba a tope\" y 100 \"abajo al " "fondo\"." -#: src/xine-engine/vo_scale.c:403 +#: src/xine-engine/vo_scale.c:396 msgid "disable all video scaling" msgstr "desactive todo escalado de vídeo" -#: src/xine-engine/vo_scale.c:404 +#: src/xine-engine/vo_scale.c:397 msgid "" "If you want the video image to be always shown at its original resolution, " "you can disable all image scaling here.\n" @@ -5945,139 +5919,139 @@ msgstr "" "imagen no está acelerado en hardware, esto puede reducir drásticamente el " "uso de cpu." -#: src/xine-engine/xine.c:831 src/xine-engine/xine.c:939 -#: src/xine-engine/xine.c:978 src/xine-engine/xine.c:1014 -#: src/xine-engine/xine.c:1026 src/xine-engine/xine.c:1039 -#: src/xine-engine/xine.c:1052 src/xine-engine/xine.c:1065 -#: src/xine-engine/xine.c:1091 src/xine-engine/xine.c:1116 -#: src/xine-engine/xine.c:1151 +#: src/xine-engine/xine.c:845 src/xine-engine/xine.c:953 +#: src/xine-engine/xine.c:993 src/xine-engine/xine.c:1029 +#: src/xine-engine/xine.c:1041 src/xine-engine/xine.c:1054 +#: src/xine-engine/xine.c:1067 src/xine-engine/xine.c:1080 +#: src/xine-engine/xine.c:1106 src/xine-engine/xine.c:1131 +#: src/xine-engine/xine.c:1168 msgid "xine: error while parsing mrl\n" msgstr "xine: error mientras se interpretaba mrl\n" -#: src/xine-engine/xine.c:873 +#: src/xine-engine/xine.c:887 #, c-format msgid "xine: found input plugin : %s\n" msgstr "xine: encontrado complemento de entrada : %s\n" -#: src/xine-engine/xine.c:891 +#: src/xine-engine/xine.c:905 #, c-format msgid "xine: input plugin cannot open MRL [%s]\n" msgstr "xine: el complemento de entrada no puede abrir el MRL [%s]\n" -#: src/xine-engine/xine.c:902 +#: src/xine-engine/xine.c:916 #, c-format msgid "xine: cannot find input plugin for MRL [%s]\n" msgstr "xine: no se puede encontrar el complemento de entrada para MRL [%s]\n" -#: src/xine-engine/xine.c:928 +#: src/xine-engine/xine.c:942 #, c-format msgid "xine: specified demuxer %s failed to start\n" msgstr "xine: fallo al iniciar el demultiplexor %s especificado\n" # cer: ¿join rip? -#: src/xine-engine/xine.c:964 +#: src/xine-engine/xine.c:979 #, c-format msgid "xine: join rip input plugin\n" msgstr "xine: complemento de entrada join rip \n" -#: src/xine-engine/xine.c:971 +#: src/xine-engine/xine.c:986 msgid "xine: error opening rip input plugin instance\n" msgstr "xine: error al abrir instancia de complemento de entrada rip\n" -#: src/xine-engine/xine.c:1002 +#: src/xine-engine/xine.c:1017 #, c-format msgid "xine: last_probed demuxer %s failed to start\n" msgstr "" "xine: el último demultiplexor probado (last_probed) %s no consiguió " "iniciarse \n" -#: src/xine-engine/xine.c:1031 +#: src/xine-engine/xine.c:1046 msgid "ignoring video\n" msgstr "ignorando vídeo\n" -#: src/xine-engine/xine.c:1044 +#: src/xine-engine/xine.c:1059 msgid "ignoring audio\n" msgstr "ignorando audio\n" -#: src/xine-engine/xine.c:1057 +#: src/xine-engine/xine.c:1072 msgid "ignoring subpicture\n" msgstr "ignorando subimagen\n" -#: src/xine-engine/xine.c:1070 +#: src/xine-engine/xine.c:1085 msgid "input cache plugin disabled\n" msgstr "caché del complemento de entrada desactivado\n" -#: src/xine-engine/xine.c:1141 +#: src/xine-engine/xine.c:1158 #, c-format msgid "subtitle mrl opened '%s'\n" msgstr "abierto mrl de subtítulos '%s'\n" -#: src/xine-engine/xine.c:1145 +#: src/xine-engine/xine.c:1162 msgid "xine: error opening subtitle mrl\n" msgstr "xine: error abriendo mrl de subtítulos\n" -#: src/xine-engine/xine.c:1177 +#: src/xine-engine/xine.c:1194 #, c-format msgid "xine: error while parsing MRL\n" msgstr "xine: error al interpretar MRL\n" -#: src/xine-engine/xine.c:1184 +#: src/xine-engine/xine.c:1201 #, c-format msgid "xine: changing option '%s' from MRL isn't permitted\n" msgstr "xine: cambiar la ocpión '%s' del MRL no está permitido\n" -#: src/xine-engine/xine.c:1204 +#: src/xine-engine/xine.c:1221 #, c-format msgid "xine: couldn't find demux for >%s<\n" msgstr "xine: no se pudo encontrar un demultiplexor para >%s<\n" -#: src/xine-engine/xine.c:1220 +#: src/xine-engine/xine.c:1237 #, c-format msgid "xine: found demuxer plugin: %s\n" msgstr "xine: encontrado complemento demultiplexor: %s\n" -#: src/xine-engine/xine.c:1242 -#, fuzzy, c-format +#: src/xine-engine/xine.c:1259 +#, c-format msgid "xine: demuxer is already done. that was fast!\n" -msgstr "xine: fallo al iniciar el demultiplexor\n" +msgstr "xine: el demultiplexor ya ha terminado, ¡eso fué rápido\n" -#: src/xine-engine/xine.c:1244 +#: src/xine-engine/xine.c:1261 #, c-format msgid "xine: demuxer failed to start\n" msgstr "xine: fallo al iniciar el demultiplexor\n" -#: src/xine-engine/xine.c:1310 +#: src/xine-engine/xine.c:1327 #, c-format msgid "xine_play: no demux available\n" msgstr "xine_play: no hay disponible un demultiplexor\n" -#: src/xine-engine/xine.c:1380 +#: src/xine-engine/xine.c:1397 #, c-format msgid "xine_play: demux failed to start\n" msgstr "xine_play: fallo al iniciar el demultiplexor\n" -#: src/xine-engine/xine.c:1657 +#: src/xine-engine/xine.c:1674 #, c-format msgid "xine: The specified save_dir \"%s\" might be a security risk.\n" msgstr "" "xine: El directorio (save_dir) especificado \"%s\" pudiera ser un riesgo " "para la seguridad.\n" -#: src/xine-engine/xine.c:1662 +#: src/xine-engine/xine.c:1679 msgid "The specified save_dir might be a security risk." msgstr "" "El directorio (save_dir) especificado pudiera ser un riesgo para la " "seguridad." -#: src/xine-engine/xine.c:1690 +#: src/xine-engine/xine.c:1707 msgid "xine: locale not supported by C library\n" msgstr "xine: \"locale\" no soportada por la librería de C\n" -#: src/xine-engine/xine.c:1699 +#: src/xine-engine/xine.c:1716 msgid "media format detection strategy" msgstr "estrategia de detecciónde formato" -#: src/xine-engine/xine.c:1700 +#: src/xine-engine/xine.c:1717 msgid "" "xine offers various methods to detect the media format of input to play. The " "individual values are:\n" @@ -6111,11 +6085,11 @@ msgstr "" "extension\n" "Detectar sólo por la extensión del nombre del fichero.\n" -#: src/xine-engine/xine.c:1718 +#: src/xine-engine/xine.c:1735 msgid "directory for saving streams" msgstr "directorio para guardar flujos de bits" -#: src/xine-engine/xine.c:1719 +#: src/xine-engine/xine.c:1736 msgid "" "When using the stream save feature, files will be written only into this " "directory.\n" @@ -6131,11 +6105,11 @@ msgstr "" "arbitrario. Así que debiera ser cuidadoso que el directorio especificado sea " "robusto contra cualquier contenido en cualquier fichero." -#: src/xine-engine/xine.c:1730 +#: src/xine-engine/xine.c:1747 msgid "allow implicit changes to the configuration (e.g. by MRL)" msgstr "permitir cambios implícitos a la configuración (p.e. por MRL)" -#: src/xine-engine/xine.c:1731 +#: src/xine-engine/xine.c:1748 msgid "" "If enabled, you allow xine to change your configuration without explicit " "actions from your side. For example configuration changes demanded by MRLs " @@ -6152,11 +6126,11 @@ msgstr "" "arbitrariamente cambiar su configuración, usted podría acabar con un xine " "totalmente enredado." -#: src/xine-engine/xine.c:1745 +#: src/xine-engine/xine.c:1762 msgid "Timeout for network stream reading (in seconds)" msgstr "Temporización para lectura de flujos de bits desde red (en segundos)" -#: src/xine-engine/xine.c:1746 +#: src/xine-engine/xine.c:1763 msgid "" "Specifies the timeout when reading from network streams, in seconds. Too low " "values might stop streaming when the source is slow or the bandwidth is " @@ -6167,15 +6141,15 @@ msgstr "" "fuente es lenta o el ancho de banda está ocupado; valores demasiado altos " "congelarán el reproductor si se pierde la conexión." -#: src/xine-engine/xine.c:2098 +#: src/xine-engine/xine.c:2115 msgid "messages" msgstr "mensajes" -#: src/xine-engine/xine.c:2099 +#: src/xine-engine/xine.c:2116 msgid "plugin" msgstr "complemento" -#: src/xine-engine/xine.c:2100 +#: src/xine-engine/xine.c:2117 msgid "trace" msgstr "traza" @@ -6231,11 +6205,11 @@ msgstr "Error de permisos" msgid "File is empty:" msgstr "El fichero está vacío:" -#: src/xine-utils/memcpy.c:479 +#: src/xine-utils/memcpy.c:478 msgid "memcopy method used by xine" msgstr "método \"memcopy\" usado por xine" -#: src/xine-utils/memcpy.c:480 +#: src/xine-utils/memcpy.c:479 msgid "" "The copying of large memory blocks is one of the most expensive operations " "on todays computers. Therefore xine provides various tuned methods to do " @@ -6246,252 +6220,6 @@ msgstr "" "ajustados para hacer este copiado. Usualmente, el método mejor se detecta " "automáticamente." -#: src/xine-utils/memcpy.c:507 +#: src/xine-utils/memcpy.c:506 msgid "Benchmarking memcpy methods (smaller is better):\n" msgstr "Evaluando métodos \"memcpy\" (menor es mejor):\n" - -#~ msgid "demux_asf: Wrong ASX version: %s\n" -#~ msgstr "demux_asf: Versión ASX equivocada: %s\n" - -#~ msgid "xine audio output plugin using kde artsd" -#~ msgstr "complemento de xine de salida de audio usando artsd de kde" - -#~ msgid "dvbsub: cannot create timer thread\n" -#~ msgstr "dvbsub: no puedo crear hilo temporizador\n" - -#~ msgid "video_out_xcbshm: your video mode was not recognized, sorry :-(\n" -#~ msgstr "" -#~ "video_out_xcbshm: su modo de vídeo no fué reconocido, lo siento :-(\n" - -#~ msgid "video_out_xcbxv: Xv extension not present.\n" -#~ msgstr "video_out_xcbxv: la extensión Xv no está presente.\n" - -#~ msgid "video_out_xcbxv: this adaptor supports the yv12 format.\n" -#~ msgstr "video_out_xcbxv: éste adaptador soporta el formato yv12.\n" - -#~ msgid "video_out_xcbxv: this adaptor supports the yuy2 format.\n" -#~ msgstr "video_out_xcbxv: éste adaptador soporta el formato yuy2.\n" - -#~ msgid "deinterlace method (deprecated)" -#~ msgstr "método de desentrelazado (obsolescente)" - -#~ msgid "" -#~ "This config setting is deprecated. You should use the new deinterlacing " -#~ "post processing settings instead.\n" -#~ "\n" -#~ "From the old days of analog television, where the even and odd numbered " -#~ "lines of a video frame would be displayed at different times comes the " -#~ "idea to increase motion smoothness by also recording the lines at " -#~ "different times. This is called \"interlacing\". But unfortunately, " -#~ "todays displays show the even and odd numbered lines as one complete " -#~ "frame all at the same time (called \"progressive display\"), which " -#~ "results in ugly frame errors known as comb artifacts. Software " -#~ "deinterlacing is an approach to reduce these artifacts. The individual " -#~ "values are:\n" -#~ "\n" -#~ "none\n" -#~ "Disables software deinterlacing.\n" -#~ "\n" -#~ "bob\n" -#~ "Interpolates between the lines for moving parts of the image.\n" -#~ "\n" -#~ "weave\n" -#~ "Similar to bob, but with a tendency to preserve the full resolution, " -#~ "better for high detail in low movement scenes.\n" -#~ "\n" -#~ "greedy\n" -#~ "Very good adaptive deinterlacer, but needs a lot of CPU power.\n" -#~ "\n" -#~ "onefield\n" -#~ "Always interpolates and reduces vertical resolution.\n" -#~ "\n" -#~ "onefieldxv\n" -#~ "Same as onefield, but does the interpolation in hardware.\n" -#~ "\n" -#~ "linearblend\n" -#~ "Applies a slight vertical blur to remove the comb artifacts. Good results " -#~ "with medium CPU usage." -#~ msgstr "" -#~ "Este ajuste de configuración es obsolescente. Debería usar los ajustes " -#~ "del postprocesado de desentrelazado nuevo en su lugar.\n" -#~ "\n" -#~ "De los antiguos dias de la televisión analógica, donde las lineas pares e " -#~ "impares de los cuadros de vídeo se visualizan en tiempos distintos viene " -#~ "la idea de mejorar el suavizado del movimiento grabando también las " -#~ "lineas en tiempos distintos. Esto se llama \"entrelazado\". Pero " -#~ "desafortunadamente, las pantallas cotidianas muestran las lineas pares e " -#~ "impares como un cuadro completo, todas de golpe (se llama \"progressive " -#~ "display\", visualización progresiva), lo que resulta en feos errores de " -#~ "cuadro conocidos como artifactos de peine. Desentrelazado en software es " -#~ "un which results in ugly frame errors known as comb artifacts. Software " -#~ "deinterlacing is an enfoque para reducir estos artifactos. Los valores " -#~ "individuales son:\n" -#~ "\n" -#~ "none (nada)\n" -#~ "Desactiva el desentrelazado en software.\n" -#~ "\n" -#~ "bob\n" -#~ "Interpola entre las lineas para las partes en movimiento de la imagen.\n" -#~ "\n" -#~ "weave (tejido)\n" -#~ "Similar a bob, pero con tendencia a preservar la resolución completa, " -#~ "mejor para mayor detalle de las escenas con poco movimiento.\n" -#~ "\n" -#~ "greedy (codicioso)\n" -#~ "Desentrelazador adaptativo muy bueno, pero necesita un montón de potencia " -#~ "de CPU.\n" -#~ "\n" -#~ "onefield (un campo)\n" -#~ "Siempre interpoa y reduce la resolución vertical.\n" -#~ "\n" -#~ "onefieldxv\n" -#~ "Igual que onefield, pero hace la interpolación en hardware.\n" -#~ "\n" -#~ "linearblend (mezcla lineal)\n" -#~ "Aplica un ligero borrón vertical para eliminar los artifactos de peine. " -#~ "Buenos resultados con uso de CPU mediano." - -#~ msgid "" -#~ "video_out_xshm: shared memory error when allocating image\n" -#~ "video_out_xshm: => not using MIT Shared Memory extension.\n" -#~ msgstr "" -#~ "video_out_xshm: error de memoria compartida al ubizar imagen\n" -#~ "video_out_xshm: => no usando la extensión de memoria compartida MIT (MIT " -#~ "Shared Memory).\n" - -#~ msgid "" -#~ "video_out_xshm: %s: allocating image\n" -#~ "video_out_xshm: => not using MIT Shared Memory extension.\n" -#~ msgstr "" -#~ "video_out_xshm: %s: ubicando imagen\n" -#~ "video_out_xshm: => no usando la extensión de memoria compartida MIT (MIT " -#~ "Shared Memory).\n" - -#~ msgid "" -#~ "video_out_xshm: shared memory error (address error) when allocating " -#~ "image \n" -#~ "video_out_xshm: => not using MIT Shared Memory extension.\n" -#~ msgstr "" -#~ "video_out_xshm: error de memoria compartida (error de dirección) al " -#~ "ubicar imagen\n" -#~ "video_out_xshm: => no usando la extensión de memoria compartida MIT (MIT " -#~ "Shared Memory).\n" - -#~ msgid "" -#~ "video_out_xshm: x11 error during shared memory XImage creation\n" -#~ "video_out_xshm: => not using MIT Shared Memory extension.\n" -#~ msgstr "" -#~ "video_out_xshm: x11 error durante creación de XImage en memoria " -#~ "compartida\n" -#~ "video_out_xshm: => no usando la extensión de memoria compartida MIT (MIT " -#~ "Shared Memory).\n" - -#~ msgid "" -#~ "video_out_xshm: MIT shared memory extension not present on display.\n" -#~ msgstr "" -#~ "video_out_xshm: la extensión de memoria compartida del MIT (MIT Shared " -#~ "Memory) no está presente en la pantalla.\n" - -#~ msgid "video_out_xshm: your video mode was not recognized, sorry :-(\n" -#~ msgstr "" -#~ "video_out_xshm: su modo de vídeoo no fué reconocido, lo siento :-(\n" - -#~ msgid "" -#~ "video_out_xv: XvShmCreateImage failed\n" -#~ "video_out_xv: => not using MIT Shared Memory extension.\n" -#~ msgstr "" -#~ "video_out_xv: falló XvShmCreateImage\n" -#~ "video_out_xv: => no usando la extensión de memoria compartida MIT (MIT " -#~ "Shared Memory).\n" - -#~ msgid "" -#~ "video_out_xv: XvShmCreateImage returned a zero size\n" -#~ "video_out_xv: => not using MIT Shared Memory extension.\n" -#~ msgstr "" -#~ "video_out_xv: XvShmCreateImage retornó un tamaño cero\n" -#~ "video_out_xv: => no usando la extensión de memoria compartida MIT (MIT " -#~ "Shared Memory).\n" - -#~ msgid "" -#~ "video_out_xv: x11 error during shared memory XImage creation\n" -#~ "video_out_xv: => not using MIT Shared Memory extension.\n" -#~ msgstr "" -#~ "video_out_xv: x11 error durante creación de XImage en memoria compartida\n" -#~ "video_out_xv: => no usando la extensión de memoria compartida MIT (MIT " -#~ "Shared Memory).\n" - -#~ msgid "" -#~ "video_out_xv: Xv extension is present but I couldn't find a usable yuv12 " -#~ "port.\n" -#~ " Looks like your graphics hardware driver doesn't support " -#~ "Xv?!\n" -#~ msgstr "" -#~ "video_out_xv: la extensión Xv está presente pero no pude encontrar un " -#~ "puerto yuv12 usable.\n" -#~ " ¡¿Parece que su driver de hardware gráfico no soporta Xv?!\n" - -#~ msgid "video_out_xv: this adaptor supports the yv12 format.\n" -#~ msgstr "video_out_xv: éste adaptador soporta el formato yv12.\n" - -#~ msgid "video_out_xv: this adaptor supports the yuy2 format.\n" -#~ msgstr "video_out_xv: éste adaptador soporta el formato yuy2.\n" - -#~ msgid "" -#~ "video_out_xxmc: XvShmCreateImage failed\n" -#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n" -#~ msgstr "" -#~ "video_out_xxmc: falló XvShmCreateImage \n" -#~ "video_out_xxmc: => no se usará la extensión \"MIT Shared Memory" -#~ "\" (memoria compartida MIT).\n" - -#~ msgid "" -#~ "video_out_xxmc: XvShmCreateImage returned a zero size\n" -#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n" -#~ msgstr "" -#~ "video_out_xxmc: XvShmCreateImage retornó un tamaño cero\n" -#~ "video_out_xxmc: => no se usará la extensión \"MIT Shared Memory" -#~ "\" (memoria compartida MIT).\n" - -#~ msgid "" -#~ "video_out_xxmc: shared memory error in shmget: %s\n" -#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n" -#~ msgstr "" -#~ "video_out_xxmc: error de memoria compartida en \"shmget\": %s\n" -#~ "video_out_xxmc: => no se usará la extensión \"MIT Shared Memory" -#~ "\" (memoria compartida MIT).\n" - -#~ msgid "" -#~ "video_out_xxmc: x11 error during shared memory XImage creation\n" -#~ "video_out_xxmc: => not using MIT Shared Memory extension.\n" -#~ msgstr "" -#~ "video_out_xxmc: x11 error durante la creación de \"XImage\" en memoria " -#~ "compartida\n" -#~ "video_out_xxmc: => no se usará la extensión \"MIT Shared Memory" -#~ "\" (memoria compartida MIT).\n" - -#~ msgid "video_out_xxmc: Xv extension not present.\n" -#~ msgstr "video_out_xxmc: extensión Xv no presente.\n" - -#~ msgid "" -#~ "video_out_xxmc: Xv extension is present but I couldn't find a usable " -#~ "yuv12 port.\n" -#~ " Looks like your graphics hardware driver doesn't support " -#~ "Xv?!\n" -#~ msgstr "" -#~ "video_out_xxmc: la extensión Xv está presente pero no pude encontrar un " -#~ "puerto yuv12 usable.\n" -#~ " ¿Parece como que su driver de hardware gráfico no soporta " -#~ "Xv?!\n" - -#~ msgid "" -#~ "video_out_xxmc: using Xv port %ld from adaptor %s for hardware colorspace " -#~ "conversion and scaling.\n" -#~ msgstr "" -#~ "video_out_xxmc: usando el puerto %ld de Xv del adaptador %s para " -#~ "conversión y escalado del espacio de color en hardware.\n" - -#~ msgid "video_out_xxmc: this adaptor supports the yv12 format.\n" -#~ msgstr "video_out_xxmc: éste adaptador soporta el formato yv12.\n" - -#~ msgid "video_out_xxmc: this adaptor supports the yuy2 format.\n" -#~ msgstr "video_out_xxmc: éste adaptador soporta el formato yuy2.\n" -- cgit v1.2.3 From 810c610bf2a4f19145e0328380797402321dab52 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Thu, 31 Jan 2008 21:32:14 +0000 Subject: Enable Esperanto translation (was missing from LINGUAS). --- po/LINGUAS | 1 + 1 file changed, 1 insertion(+) diff --git a/po/LINGUAS b/po/LINGUAS index 8a29b895c..87a156243 100644 --- a/po/LINGUAS +++ b/po/LINGUAS @@ -1,5 +1,6 @@ cs de +eo es eu fr -- cgit v1.2.3 From 4c48996da5a13a135338e745157c45f351300540 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Thu, 31 Jan 2008 22:02:04 +0000 Subject: Export PKG_CONFIG_PATH. --- misc/xine-config.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/xine-config.in b/misc/xine-config.in index 719d9667e..297b8c88b 100644 --- a/misc/xine-config.in +++ b/misc/xine-config.in @@ -6,7 +6,7 @@ unset prefix unset exec_prefix unset args -PKG_CONFIG_PATH="$(cat <<'EOF' +export PKG_CONFIG_PATH="$(cat <<'EOF' @XINE_PKGCONFIG_DIR@ EOF )${PKG_CONFIG_PATH:+:}$PKG_CONFIG_PATH" -- cgit v1.2.3 From d865cc45e9f9c9d9e1dfeef714cf7221d39fb3e8 Mon Sep 17 00:00:00 2001 From: Jean-Yves Lefort <jylefort@users.sourceforge.net> Date: Fri, 1 Feb 2008 02:16:14 +0000 Subject: patch adding video.device.xv_port option The attached patch allows to specify the Xv port to use (needed with some nvidia twinview configurations). --- src/video_out/video_out_xv.c | 53 ++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/src/video_out/video_out_xv.c b/src/video_out/video_out_xv.c index d6419c00b..da679d088 100644 --- a/src/video_out/video_out_xv.c +++ b/src/video_out/video_out_xv.c @@ -1136,6 +1136,30 @@ static void xv_update_xv_pitch_alignment(void *this_gen, xine_cfg_entry_t *entry this->use_pitch_alignment = entry->num_value; } +static int xv_open_port (xv_driver_t *this, XvPortID port) { + return ! xv_check_yv12(this->display, port) + && XvGrabPort(this->display, port, 0) == Success; +} + +static XvPortID xv_autodetect_port(xv_driver_t *this, + unsigned int adaptors, + XvAdaptorInfo *adaptor_info, + unsigned int *adaptor_num) { + unsigned int an, j; + + for (an = 0; an < adaptors; an++) + if (adaptor_info[an].type & XvImageMask) + for (j = 0; j < adaptor_info[an].num_ports; j++) { + XvPortID port = adaptor_info[an].base_id + j; + if (xv_open_port(this, port)) { + *adaptor_num = an; + return port; + } + } + + return 0; +} + /* expects XINE_VISUAL_TYPE_X11_2 with configurable locking */ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void *visual_gen) { xv_class_t *class = (xv_class_t *) class_gen; @@ -1148,7 +1172,7 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void * x11_visual_t *visual = (x11_visual_t *) visual_gen; XColor dummy; XvImage *myimage; - unsigned int adaptors, j; + unsigned int adaptors; unsigned int ver,rel,req,ev,err; XShmSegmentInfo myshminfo; XvPortID xv_port; @@ -1191,25 +1215,16 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void * return NULL; } - xv_port = 0; + xv_port = config->register_num (config, "video.device.xv_port", 0, + _("Xv port number"), + _("Selects the Xv port number to use (0 to autodetect)."), + 10, NULL, NULL); - for ( adaptor_num = 0; (adaptor_num < adaptors) && !xv_port; adaptor_num++ ) { - - if (adaptor_info[adaptor_num].type & XvImageMask) { - - for (j = 0; j < adaptor_info[adaptor_num].num_ports && !xv_port; j++) - if (( !(xv_check_yv12 (this->display, - adaptor_info[adaptor_num].base_id + j))) - && (XvGrabPort (this->display, - adaptor_info[adaptor_num].base_id + j, - 0) == Success)) { - xv_port = adaptor_info[adaptor_num].base_id + j; - } - - if( xv_port ) - break; - } - } + if (xv_port != 0) { + if (! xv_open_port(this, xv_port)) + xv_port = 0; + } else + xv_port = xv_autodetect_port(this, adaptors, adaptor_info, &adaptor_num); if (!xv_port) { xprintf(class->xine, XINE_VERBOSITY_LOG, -- cgit v1.2.3 From 3123c1c76b8eb9e6236f9d17dc6e283281495def Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Fri, 1 Feb 2008 02:17:09 +0000 Subject: Fallback to auto-detect when the specified Xv port is unavailable or unusable. --- src/video_out/video_out_xv.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/video_out/video_out_xv.c b/src/video_out/video_out_xv.c index da679d088..61b2638ec 100644 --- a/src/video_out/video_out_xv.c +++ b/src/video_out/video_out_xv.c @@ -1137,8 +1137,25 @@ static void xv_update_xv_pitch_alignment(void *this_gen, xine_cfg_entry_t *entry } static int xv_open_port (xv_driver_t *this, XvPortID port) { - return ! xv_check_yv12(this->display, port) + int ret; + x11_InstallXErrorHandler (this); + ret = ! xv_check_yv12(this->display, port) && XvGrabPort(this->display, port, 0) == Success; + x11_DeInstallXErrorHandler (this); + return ret; +} + +static unsigned int +xv_find_adaptor_by_port (int port, unsigned int adaptors, + XvAdaptorInfo *adaptor_info) +{ + unsigned int an; + for (an = 0; an < adaptors; an++) + if (adaptor_info[an].type & XvImageMask) + if (port >= adaptor_info[an].base_id && + port < adaptor_info[an].base_id + adaptor_info[an].num_ports) + return an; + return 0; /* shouldn't happen */ } static XvPortID xv_autodetect_port(xv_driver_t *this, @@ -1221,8 +1238,13 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void * 10, NULL, NULL); if (xv_port != 0) { - if (! xv_open_port(this, xv_port)) - xv_port = 0; + if (! xv_open_port(this, xv_port)) { + xprintf(class->xine, XINE_VERBOSITY_NONE, + _("%s: could not open Xv port %d - autodetecting\n"), + LOG_MODULE, xv_port); + xv_port = xv_autodetect_port(this, adaptors, adaptor_info, &adaptor_num); + } else + adaptor_num = xv_find_adaptor_by_port (xv_port, adaptors, adaptor_info); } else xv_port = xv_autodetect_port(this, adaptors, adaptor_info, &adaptor_num); -- cgit v1.2.3 From 5f2f836776194347fefa595d53ebe3d9790b4a74 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Fri, 1 Feb 2008 03:03:12 +0000 Subject: Add Xv port selection to the XCB xv plugin. --- src/video_out/video_out_xcbxv.c | 86 ++++++++++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 23 deletions(-) diff --git a/src/video_out/video_out_xcbxv.c b/src/video_out/video_out_xcbxv.c index 19a387732..cb07d949b 100644 --- a/src/video_out/video_out_xcbxv.c +++ b/src/video_out/video_out_xcbxv.c @@ -1089,13 +1089,60 @@ static void xv_update_xv_pitch_alignment(void *this_gen, xine_cfg_entry_t *entry this->use_pitch_alignment = entry->num_value; } +static xcb_xv_port_t xv_open_port (xv_driver_t *this, xcb_xv_port_t port) { + xcb_xv_grab_port_cookie_t grab_port_cookie; + xcb_xv_grab_port_reply_t *grab_port_reply; + + if (xv_check_yv12 (this->connection, port)) + return 0; + + grab_port_cookie = xcb_xv_grab_port (this->connection, port, XCB_CURRENT_TIME); + grab_port_reply = xcb_xv_grab_port_reply (this->connection, grab_port_cookie, NULL); + + if (grab_port_reply && (grab_port_reply->result == XCB_GRAB_STATUS_SUCCESS)) + { + free (grab_port_reply); + return port; + } + free (grab_port_reply); + return 0; +} + +static xcb_xv_adaptor_info_iterator_t * +xv_find_adaptor_by_port (int port, xcb_xv_adaptor_info_iterator_t *adaptor_it) +{ + for (; adaptor_it->rem; xcb_xv_adaptor_info_next(adaptor_it)) + if (adaptor_it->data->type & XCB_XV_TYPE_IMAGE_MASK) + if (port >= adaptor_it->data->base_id && + port < adaptor_it->data->base_id + adaptor_it->data->num_ports) + return adaptor_it; + return NULL; /* shouldn't happen */ +} + +static xcb_xv_port_t xv_autodetect_port(xv_driver_t *this, + xcb_xv_adaptor_info_iterator_t *adaptor_it) +{ + for (; adaptor_it->rem; xcb_xv_adaptor_info_next(adaptor_it)) + if (adaptor_it->data->type & XCB_XV_TYPE_IMAGE_MASK) + { + int j; + for (j = 0; j < adaptor_it->data->num_ports; ++j) + if (!xv_check_yv12 (this->connection, adaptor_it->data->base_id + j)) + { + xcb_xv_port_t port = xv_open_port (this, adaptor_it->data->base_id + j); + if (port) + return port; + } + } + return 0; +} + static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *visual_gen) { xv_class_t *class = (xv_class_t *) class_gen; config_values_t *config = class->config; xv_driver_t *this; int i; xcb_visual_t *visual = (xcb_visual_t *) visual_gen; - unsigned int j; xcb_xv_port_t xv_port; const xcb_query_extension_reply_t *query_extension_reply; @@ -1146,28 +1193,21 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis } adaptor_it = xcb_xv_query_adaptors_info_iterator(query_adaptors_reply); - - xv_port = 0; - - for (; adaptor_it.rem && !xv_port; xcb_xv_adaptor_info_next(&adaptor_it)) { - - if (adaptor_it.data->type & XCB_XV_TYPE_IMAGE_MASK) { - - for (j = 0; j < adaptor_it.data->num_ports; j++) - if (!xv_check_yv12(this->connection, adaptor_it.data->base_id + j)) { - xcb_xv_grab_port_cookie_t grab_port_cookie; - xcb_xv_grab_port_reply_t *grab_port_reply; - grab_port_cookie = xcb_xv_grab_port(this->connection, adaptor_it.data->base_id + j, XCB_CURRENT_TIME); - grab_port_reply = xcb_xv_grab_port_reply(this->connection, grab_port_cookie, NULL); - if (grab_port_reply && (grab_port_reply->result == XCB_GRAB_STATUS_SUCCESS)) { - free(grab_port_reply); - xv_port = adaptor_it.data->base_id + j; - break; - } - free(grab_port_reply); - } - } - } + xv_port = config->register_num (config, "video.device.xv_port", 0, + _("Xv port number"), + _("Selects the Xv port number to use (0 to autodetect)."), + 10, NULL, NULL); + + if (xv_port != 0) { + if (! xv_open_port(this, xv_port)) { + xprintf(class->xine, XINE_VERBOSITY_NONE, + _("%s: could not open Xv port %d - autodetecting\n"), + LOG_MODULE, xv_port); + xv_port = xv_autodetect_port (this, &adaptor_it); + } else + xv_find_adaptor_by_port (xv_port, &adaptor_it); + } else + xv_port = xv_autodetect_port (this, &adaptor_it); if (!xv_port) { xprintf(class->xine, XINE_VERBOSITY_LOG, -- cgit v1.2.3 From e27e5b16313734e45fa974b988f439b9c8a11894 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Fri, 1 Feb 2008 16:44:43 +0000 Subject: Port Xv port selection to xxmc. --- src/video_out/video_out_xxmc.c | 73 +++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/src/video_out/video_out_xxmc.c b/src/video_out/video_out_xxmc.c index 98ce99f1f..7fc136e94 100644 --- a/src/video_out/video_out_xxmc.c +++ b/src/video_out/video_out_xxmc.c @@ -2237,6 +2237,47 @@ static void xxmc_update_disable_bob_for_scaled_osd(void *this_gen, xine_cfg_entr this->disable_bob_for_scaled_osd = entry->num_value; } +static int xxmc_open_port (xxmc_driver_t *this, XvPortID port) { + int ret; + x11_InstallXErrorHandler (this); + ret = ! xxmc_check_yv12(this->display, port) + && XvGrabPort(this->display, port, 0) == Success; + x11_DeInstallXErrorHandler (this); + return ret; +} + +static unsigned int +xxmc_find_adaptor_by_port (int port, unsigned int adaptors, + XvAdaptorInfo *adaptor_info) +{ + unsigned int an; + for (an = 0; an < adaptors; an++) + if (adaptor_info[an].type & XvImageMask) + if (port >= adaptor_info[an].base_id && + port < adaptor_info[an].base_id + adaptor_info[an].num_ports) + return an; + return 0; /* shouldn't happen */ +} + +static XvPortID xxmc_autodetect_port(xxmc_driver_t *this, + unsigned int adaptors, + XvAdaptorInfo *adaptor_info, + unsigned int *adaptor_num) { + unsigned int an, j; + + for (an = 0; an < adaptors; an++) + if (adaptor_info[an].type & XvImageMask) + for (j = 0; j < adaptor_info[an].num_ports; j++) { + XvPortID port = adaptor_info[an].base_id + j; + if (xxmc_open_port(this, port)) { + *adaptor_num = an; + return port; + } + } + + return 0; +} + static void checkXvMCCap( xxmc_driver_t *this, XvPortID xv_port) { @@ -2436,25 +2477,21 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi return NULL; } - xv_port = 0; - - for ( adaptor_num = 0; (adaptor_num < adaptors) && !xv_port; adaptor_num++ ) { + xv_port = config->register_num (config, "video.device.xv_port", 0, + _("Xv port number"), + _("Selects the Xv port number to use (0 to autodetect)."), + 10, NULL, NULL); - if (adaptor_info[adaptor_num].type & XvImageMask) { - - for (j = 0; j < adaptor_info[adaptor_num].num_ports && !xv_port; j++) - if (( !(xxmc_check_yv12 (this->display, - adaptor_info[adaptor_num].base_id + j))) - && (XvGrabPort (this->display, - adaptor_info[adaptor_num].base_id + j, - 0) == Success)) { - xv_port = adaptor_info[adaptor_num].base_id + j; - } - - if( xv_port ) - break; - } - } + if (xv_port != 0) { + if (! xxmc_open_port(this, xv_port)) { + xprintf(class->xine, XINE_VERBOSITY_NONE, + _("%s: could not open Xv port %d - autodetecting\n"), + LOG_MODULE, xv_port); + xv_port = xxmc_autodetect_port(this, adaptors, adaptor_info, &adaptor_num); + } else + adaptor_num = xxmc_find_adaptor_by_port (xv_port, adaptors, adaptor_info); + } else + xv_port = xxmc_autodetect_port(this, adaptors, adaptor_info, &adaptor_num); if (!xv_port) { xprintf(class->xine, XINE_VERBOSITY_LOG, -- cgit v1.2.3 From 401c95b421c60b8d46485a0cb29991974b2c8190 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Fri, 1 Feb 2008 16:52:39 +0000 Subject: Changelog entry for the Xv port selection patches. --- ChangeLog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index d450fd2fb..ee10261ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -55,6 +55,8 @@ xine-lib (1.1.90) (Unreleased) * Remove SyncFB video output plugin, the kernel module needed is no more active and thus it's no more usable. If you were using SyncFB somehow, please use DirectFB or VIDIX instead. + * The Xv and XxMC video output plugins now support Xv port selection. + (XvMC does not, at present.) xine-lib (1.1.11) unreleased * Fix a RealPlayer codec detection bug. -- cgit v1.2.3 From e37643a0929038587a8517a266c4f20806542788 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 2 Feb 2008 00:18:43 +0000 Subject: Convert xshm_set_property() from if() chain to switch block. --- src/video_out/video_out_xcbshm.c | 24 +++++++++++------------- src/video_out/video_out_xshm.c | 24 +++++++++++------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/video_out/video_out_xcbshm.c b/src/video_out/video_out_xcbshm.c index bb19058f5..9895d1852 100644 --- a/src/video_out/video_out_xcbshm.c +++ b/src/video_out/video_out_xcbshm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2000-2003, 2007 the xine project + * Copyright (C) 2000-2003, 2007-2008 the xine project * * This file is part of xine, a free video player. * @@ -750,45 +750,43 @@ static int xshm_set_property (vo_driver_t *this_gen, int property, int value) { xshm_driver_t *this = (xshm_driver_t *) this_gen; - if ( property == VO_PROP_ASPECT_RATIO) { - + switch (property) { + case VO_PROP_ASPECT_RATIO: if (value>=XINE_VO_ASPECT_NUM_RATIOS) value = XINE_VO_ASPECT_AUTO; this->sc.user_ratio = value; xprintf(this->xine, XINE_VERBOSITY_DEBUG, LOG_MODULE ": aspect ratio changed to %s\n", _x_vo_scale_aspect_ratio_name_table[value]); + break; - } else if (property == VO_PROP_BRIGHTNESS) { - + case VO_PROP_BRIGHTNESS: this->yuv2rgb_brightness = value; this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory, this->yuv2rgb_brightness, this->yuv2rgb_contrast, this->yuv2rgb_saturation); - this->sc.force_redraw = 1; + break; - } else if (property == VO_PROP_CONTRAST) { - + case VO_PROP_CONTRAST: this->yuv2rgb_contrast = value; this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory, this->yuv2rgb_brightness, this->yuv2rgb_contrast, this->yuv2rgb_saturation); - this->sc.force_redraw = 1; + break; - } else if (property == VO_PROP_SATURATION) { - + case VO_PROP_SATURATION: this->yuv2rgb_saturation = value; this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory, this->yuv2rgb_brightness, this->yuv2rgb_contrast, this->yuv2rgb_saturation); - this->sc.force_redraw = 1; + break; - } else { + default: xprintf (this->xine, XINE_VERBOSITY_DEBUG, LOG_MODULE ": tried to set unsupported property %d\n", property); } diff --git a/src/video_out/video_out_xshm.c b/src/video_out/video_out_xshm.c index ecaf61f06..7801bb03b 100644 --- a/src/video_out/video_out_xshm.c +++ b/src/video_out/video_out_xshm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2000-2003 the xine project + * Copyright (C) 2000-2003, 2008 the xine project * * This file is part of xine, a free video player. * @@ -839,45 +839,43 @@ static int xshm_set_property (vo_driver_t *this_gen, int property, int value) { xshm_driver_t *this = (xshm_driver_t *) this_gen; - if ( property == VO_PROP_ASPECT_RATIO) { - + switch (property) { + case VO_PROP_ASPECT_RATIO: if (value>=XINE_VO_ASPECT_NUM_RATIOS) value = XINE_VO_ASPECT_AUTO; this->sc.user_ratio = value; xprintf(this->xine, XINE_VERBOSITY_DEBUG, LOG_MODULE ": aspect ratio changed to %s\n", _x_vo_scale_aspect_ratio_name_table[value]); + break; - } else if (property == VO_PROP_BRIGHTNESS) { - + case VO_PROP_BRIGHTNESS: this->yuv2rgb_brightness = value; this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory, this->yuv2rgb_brightness, this->yuv2rgb_contrast, this->yuv2rgb_saturation); - this->sc.force_redraw = 1; + break; - } else if (property == VO_PROP_CONTRAST) { - + case VO_PROP_CONTRAST: this->yuv2rgb_contrast = value; this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory, this->yuv2rgb_brightness, this->yuv2rgb_contrast, this->yuv2rgb_saturation); - this->sc.force_redraw = 1; + break; - } else if (property == VO_PROP_SATURATION) { - + case VO_PROP_SATURATION: this->yuv2rgb_saturation = value; this->yuv2rgb_factory->set_csc_levels (this->yuv2rgb_factory, this->yuv2rgb_brightness, this->yuv2rgb_contrast, this->yuv2rgb_saturation); - this->sc.force_redraw = 1; + break; - } else { + default: xprintf (this->xine, XINE_VERBOSITY_DEBUG, LOG_MODULE ": tried to set unsupported property %d\n", property); } -- cgit v1.2.3 From 3c7b2fa3c7f6640434d64ccfdb72ef77333f40e0 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 2 Feb 2008 00:21:41 +0000 Subject: Add a header file for some strings shared between the Xv-using plugins. --- src/video_out/Makefile.am | 2 +- src/video_out/xv_common.h | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/video_out/xv_common.h diff --git a/src/video_out/Makefile.am b/src/video_out/Makefile.am index 3b5703792..c1d142263 100644 --- a/src/video_out/Makefile.am +++ b/src/video_out/Makefile.am @@ -12,7 +12,7 @@ endif EXTRA_DIST = video_out_directx.c video_out_macosx.m -noinst_HEADERS = yuv2rgb.h x11osd.h xcbosd.h +noinst_HEADERS = yuv2rgb.h x11osd.h xcbosd.h xv_common.h if HAVE_X11 X11OSD = x11osd.c diff --git a/src/video_out/xv_common.h b/src/video_out/xv_common.h new file mode 100644 index 000000000..71eecddad --- /dev/null +++ b/src/video_out/xv_common.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2008 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA + * + * xv_common.h: X11 Xv common bits + */ + +#define VIDEO_DEVICE_XV_COLORKEY_HELP \ + _("video overlay colour key"), \ + _("The colour key is used to tell the graphics card where to " \ + "overlay the video image. Try different values, if you "\ + "experience windows becoming transparent.") + +#define VIDEO_DEVICE_XV_AUTOPAINT_COLORKEY_HELP \ + _("autopaint colour key"), \ + _("Make Xv autopaint its colour key.") + +#define VIDEO_DEVICE_XV_FILTER_HELP \ + _("bilinear scaling mode"), \ + _("Selects the bilinear scaling mode for Permedia cards. " \ + "The individual values are:\n\n" \ + "Permedia 2\n" \ + "0 - disable bilinear filtering\n" \ + "1 - enable bilinear filtering\n\n" \ + "Permedia 3\n" \ + "0 - disable bilinear filtering\n" \ + "1 - horizontal linear filtering\n" \ + "2 - enable full bilinear filtering") + +#define VIDEO_DEVICE_XV_DOUBLE_BUFFER_HELP \ + _("enable double buffering"), \ + _("Double buffering will synchronize the update of the video " \ + "image to the repainting of the entire screen (\"vertical " \ + "retrace\"). This eliminates flickering and tearing artifacts, " \ + "but will use more graphics memory.") -- cgit v1.2.3 From ca31816f2589c5908488cd0e6c8b5ec215486f31 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 2 Feb 2008 00:27:08 +0000 Subject: Convert the plain Xv plugins to use the new header file. Also, a few trivial constness cleanups. --- src/video_out/video_out_xcbxv.c | 60 ++++++++++++++-------------------------- src/video_out/video_out_xv.c | 61 ++++++++++++++--------------------------- 2 files changed, 40 insertions(+), 81 deletions(-) diff --git a/src/video_out/video_out_xcbxv.c b/src/video_out/video_out_xcbxv.c index cb07d949b..63313c43a 100644 --- a/src/video_out/video_out_xcbxv.c +++ b/src/video_out/video_out_xcbxv.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2000-2004, 2007 the xine project + * Copyright (C) 2000-2004, 2007-2008 the xine project * * This file is part of xine, a free video player. * @@ -64,6 +64,7 @@ #include <xine/xineutils.h> #include <xine/vo_scale.h> #include "xcbosd.h" +#include "xv_common.h" typedef struct xv_driver_s xv_driver_t; @@ -965,7 +966,7 @@ static void xv_check_capability (xv_driver_t *this, char *config_help) { int int_default; cfg_entry_t *entry; - char *str_prop = xcb_xv_attribute_info_name(attr); + const char *str_prop = xcb_xv_attribute_info_name(attr); xcb_xv_get_port_attribute_cookie_t get_attribute_cookie; xcb_xv_get_port_attribute_reply_t *get_attribute_reply; @@ -1285,10 +1286,11 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis for (; attribute_it.rem; xcb_xv_attribute_info_next(&attribute_it)) { if ((attribute_it.data->flags & XCB_XV_ATTRIBUTE_FLAG_SETTABLE) && (attribute_it.data->flags & XCB_XV_ATTRIBUTE_FLAG_GETTABLE)) { + const char *const name = xcb_xv_attribute_info_name(attribute_it.data); /* store initial port attribute value */ - xv_store_port_attribute(this, xcb_xv_attribute_info_name(attribute_it.data)); - - if(!strcmp(xcb_xv_attribute_info_name(attribute_it.data), "XV_HUE")) { + xv_store_port_attribute(this, name); + + if(!strcmp(name, "XV_HUE")) { if (!strncmp(xcb_xv_adaptor_info_name(adaptor_it.data), "NV", 2)) { xprintf (this->xine, XINE_VERBOSITY_NONE, LOG_MODULE ": ignoring broken XV_HUE settings on NVidia cards\n"); } else { @@ -1296,63 +1298,41 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis adaptor_it.data->base_id, NULL, NULL, NULL); } - } else if(!strcmp(xcb_xv_attribute_info_name(attribute_it.data), "XV_SATURATION")) { + } else if(!strcmp(name, "XV_SATURATION")) { xv_check_capability (this, VO_PROP_SATURATION, attribute_it.data, adaptor_it.data->base_id, NULL, NULL, NULL); - - } else if(!strcmp(xcb_xv_attribute_info_name(attribute_it.data), "XV_BRIGHTNESS")) { + } else if(!strcmp(name, "XV_BRIGHTNESS")) { xv_check_capability (this, VO_PROP_BRIGHTNESS, attribute_it.data, adaptor_it.data->base_id, NULL, NULL, NULL); - - } else if(!strcmp(xcb_xv_attribute_info_name(attribute_it.data), "XV_CONTRAST")) { + } else if(!strcmp(name, "XV_CONTRAST")) { xv_check_capability (this, VO_PROP_CONTRAST, attribute_it.data, adaptor_it.data->base_id, NULL, NULL, NULL); - - } else if(!strcmp(xcb_xv_attribute_info_name(attribute_it.data), "XV_COLORKEY")) { + } else if(!strcmp(name, "XV_COLORKEY")) { xv_check_capability (this, VO_PROP_COLORKEY, attribute_it.data, adaptor_it.data->base_id, "video.device.xv_colorkey", - _("video overlay colour key"), - _("The colour key is used to tell the graphics card where to " - "overlay the video image. Try different values, if you experience " - "windows becoming transparent.")); - - } else if(!strcmp(xcb_xv_attribute_info_name(attribute_it.data), "XV_AUTOPAINT_COLORKEY")) { + VIDEO_DEVICE_XV_COLORKEY_HELP); + } else if(!strcmp(name, "XV_AUTOPAINT_COLORKEY")) { xv_check_capability (this, VO_PROP_AUTOPAINT_COLORKEY, attribute_it.data, adaptor_it.data->base_id, "video.device.xv_autopaint_colorkey", - _("autopaint colour key"), - _("Make Xv autopaint its colour key.")); - - } else if(!strcmp(xcb_xv_attribute_info_name(attribute_it.data), "XV_FILTER")) { + VIDEO_DEVICE_XV_AUTOPAINT_COLORKEY_HELP); + } else if(!strcmp(name, "XV_FILTER")) { int xv_filter; /* This setting is specific to Permedia 2/3 cards. */ xv_filter = config->register_range (config, "video.device.xv_filter", 0, attribute_it.data->min, attribute_it.data->max, - _("bilinear scaling mode"), - _("Selects the bilinear scaling mode for Permedia cards. " - "The individual values are:\n\n" - "Permedia 2\n" - "0 - disable bilinear filtering\n" - "1 - enable bilinear filtering\n\n" - "Permedia 3\n" - "0 - disable bilinear filtering\n" - "1 - horizontal linear filtering\n" - "2 - enable full bilinear filtering"), + VIDEO_DEVICE_XV_FILTER_HELP, 20, xv_update_XV_FILTER, this); config->update_num(config,"video.device.xv_filter",xv_filter); - } else if(!strcmp(xcb_xv_attribute_info_name(attribute_it.data), "XV_DOUBLE_BUFFER")) { - int xv_double_buffer; - xv_double_buffer = + } else if(!strcmp(name, "XV_DOUBLE_BUFFER")) { + int xv_double_buffer = config->register_bool (config, "video.device.xv_double_buffer", 1, - _("enable double buffering"), - _("Double buffering will synchronize the update of the video image to the " - "repainting of the entire screen (\"vertical retrace\"). This eliminates " - "flickering and tearing artifacts, but will use more graphics memory."), - 20, xv_update_XV_DOUBLE_BUFFER, this); + VIDEO_DEVICE_XV_DOUBLE_BUFFER_HELP, + 20, xv_update_XV_DOUBLE_BUFFER, this); config->update_num(config,"video.device.xv_double_buffer",xv_double_buffer); } } diff --git a/src/video_out/video_out_xv.c b/src/video_out/video_out_xv.c index 61b2638ec..a92f6dbe8 100644 --- a/src/video_out/video_out_xv.c +++ b/src/video_out/video_out_xv.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2000-2004 the xine project + * Copyright (C) 2000-2004, 2008 the xine project * * This file is part of xine, a free video player. * @@ -69,6 +69,7 @@ #include <xine/xineutils.h> #include <xine/vo_scale.h> #include "x11osd.h" +#include "xv_common.h" #define LOCK_DISPLAY(this) {if(this->lock_display) this->lock_display(this->user_data); \ else XLockDisplay(this->display);} @@ -1028,14 +1029,13 @@ static int xv_check_yv12 (Display *display, XvPortID port) { /* called xlocked */ static void xv_check_capability (xv_driver_t *this, - int property, XvAttribute attr, - int base_id, + int property, XvAttribute attr, int base_id, const char *config_name, const char *config_desc, const char *config_help) { int int_default; cfg_entry_t *entry; - char *str_prop = attr.name; + const char *str_prop = attr.name; /* * some Xv drivers (Gatos ATI) report some ~0 as max values, this is confusing. @@ -1335,10 +1335,11 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void * for(k = 0; k < nattr; k++) { if((attr[k].flags & XvSettable) && (attr[k].flags & XvGettable)) { + const char *const name = attr[k].name; /* store initial port attribute value */ - xv_store_port_attribute(this, attr[k].name); + xv_store_port_attribute(this, name); - if(!strcmp(attr[k].name, "XV_HUE")) { + if(!strcmp(name, "XV_HUE")) { if (!strncmp(adaptor_info[adaptor_num].name, "NV", 2)) { xprintf (this->xine, XINE_VERBOSITY_NONE, LOG_MODULE ": ignoring broken XV_HUE settings on NVidia cards\n"); } else { @@ -1346,63 +1347,41 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void * adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); } - } else if(!strcmp(attr[k].name, "XV_SATURATION")) { + } else if(!strcmp(name, "XV_SATURATION")) { xv_check_capability (this, VO_PROP_SATURATION, attr[k], adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); - - } else if(!strcmp(attr[k].name, "XV_BRIGHTNESS")) { + } else if(!strcmp(name, "XV_BRIGHTNESS")) { xv_check_capability (this, VO_PROP_BRIGHTNESS, attr[k], adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); - - } else if(!strcmp(attr[k].name, "XV_CONTRAST")) { + } else if(!strcmp(name, "XV_CONTRAST")) { xv_check_capability (this, VO_PROP_CONTRAST, attr[k], adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); - - } else if(!strcmp(attr[k].name, "XV_COLORKEY")) { + } else if(!strcmp(name, "XV_COLORKEY")) { xv_check_capability (this, VO_PROP_COLORKEY, attr[k], adaptor_info[adaptor_num].base_id, "video.device.xv_colorkey", - _("video overlay colour key"), - _("The colour key is used to tell the graphics card where to " - "overlay the video image. Try different values, if you experience " - "windows becoming transparent.")); - - } else if(!strcmp(attr[k].name, "XV_AUTOPAINT_COLORKEY")) { + VIDEO_DEVICE_XV_COLORKEY_HELP); + } else if(!strcmp(name, "XV_AUTOPAINT_COLORKEY")) { xv_check_capability (this, VO_PROP_AUTOPAINT_COLORKEY, attr[k], adaptor_info[adaptor_num].base_id, "video.device.xv_autopaint_colorkey", - _("autopaint colour key"), - _("Make Xv autopaint its colour key.")); - - } else if(!strcmp(attr[k].name, "XV_FILTER")) { + VIDEO_DEVICE_XV_AUTOPAINT_COLORKEY_HELP); + } else if(!strcmp(name, "XV_FILTER")) { int xv_filter; /* This setting is specific to Permedia 2/3 cards. */ xv_filter = config->register_range (config, "video.device.xv_filter", 0, attr[k].min_value, attr[k].max_value, - _("bilinear scaling mode"), - _("Selects the bilinear scaling mode for Permedia cards. " - "The individual values are:\n\n" - "Permedia 2\n" - "0 - disable bilinear filtering\n" - "1 - enable bilinear filtering\n\n" - "Permedia 3\n" - "0 - disable bilinear filtering\n" - "1 - horizontal linear filtering\n" - "2 - enable full bilinear filtering"), + VIDEO_DEVICE_XV_FILTER_HELP, 20, xv_update_XV_FILTER, this); config->update_num(config,"video.device.xv_filter",xv_filter); - } else if(!strcmp(attr[k].name, "XV_DOUBLE_BUFFER")) { - int xv_double_buffer; - xv_double_buffer = + } else if(!strcmp(name, "XV_DOUBLE_BUFFER")) { + int xv_double_buffer = config->register_bool (config, "video.device.xv_double_buffer", 1, - _("enable double buffering"), - _("Double buffering will synchronize the update of the video image to the " - "repainting of the entire screen (\"vertical retrace\"). This eliminates " - "flickering and tearing artifacts, but will use more graphics memory."), - 20, xv_update_XV_DOUBLE_BUFFER, this); + VIDEO_DEVICE_XV_DOUBLE_BUFFER_HELP, + 20, xv_update_XV_DOUBLE_BUFFER, this); config->update_num(config,"video.device.xv_double_buffer",xv_double_buffer); } } -- cgit v1.2.3 From 5358d8d5b08bf99f43d508b63e4dcca3da79caba Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 2 Feb 2008 00:39:07 +0000 Subject: XvMC plugin uses the new header; use config_help; small var/struct cleanup. - Removed display in open_plugin(); - Converted adaptor_{info,num} in xvmc_class_t into locals in open_plugin(). Also, a few trivial constness cleanups. (Not fully tested; XvMC doesn't work for me. --- src/video_out/video_out_xvmc.c | 92 +++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 55 deletions(-) diff --git a/src/video_out/video_out_xvmc.c b/src/video_out/video_out_xvmc.c index 6aa8f430d..c0fb10be3 100644 --- a/src/video_out/video_out_xvmc.c +++ b/src/video_out/video_out_xvmc.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2000-2004 the xine project + * Copyright (C) 2000-2004, 2008 the xine project * * This file is part of xine, a free video player. * @@ -72,6 +72,7 @@ #include <xine/xineutils.h> #include <xine/vo_scale.h> +#include "xv_common.h" /* #define LOG1 */ /* #define DLOG */ @@ -217,8 +218,6 @@ typedef struct { Display *display; config_values_t *config; XvPortID xv_port; - XvAdaptorInfo *adaptor_info; - unsigned int adaptor_num; int surface_type_id; unsigned int max_surface_width; @@ -1224,13 +1223,13 @@ static void xvmc_dispose (vo_driver_t *this_gen) { /* called xlocked */ static void xvmc_check_capability (xvmc_driver_t *this, - int property, XvAttribute attr, - int base_id, char *str_prop, - char *config_name, - char *config_desc, - char *config_help) { + int property, XvAttribute attr, int base_id, + const char *config_name, + const char *config_desc, + const char *config_help) { int int_default; cfg_entry_t *entry; + const char *str_prop = attr.name; /* * some Xv drivers (Gatos ATI) report some ~0 as max values, this is confusing. @@ -1253,13 +1252,13 @@ static void xvmc_check_capability (xvmc_driver_t *this, if ((attr.min_value == 0) && (attr.max_value == 1)) { this->config->register_bool (this->config, config_name, int_default, config_desc, - NULL, 20, xvmc_property_callback, &this->props[property]); + config_help, 20, xvmc_property_callback, &this->props[property]); } else { this->config->register_range (this->config, config_name, int_default, this->props[property].min, this->props[property].max, config_desc, - NULL, 20, xvmc_property_callback, &this->props[property]); + config_help, 20, xvmc_property_callback, &this->props[property]); } entry = this->config->lookup_entry (this->config, config_name); @@ -1297,7 +1296,6 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi xvmc_class_t *class = (xvmc_class_t *) class_gen; config_values_t *config = class->config; xvmc_driver_t *this = NULL; - Display *display = NULL; unsigned int i, formats; XvPortID xv_port = class->xv_port; XvAttribute *attr; @@ -1305,13 +1303,12 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi int nattr; x11_visual_t *visual = (x11_visual_t *) visual_gen; XColor dummy; + XvAdaptorInfo *adaptor_info; + unsigned int adaptor_num; /* XvImage *myimage; */ lprintf ("open_plugin\n"); - display = visual->display; - - /* TODO ??? */ this = (xvmc_driver_t *) xine_xmalloc (sizeof (xvmc_driver_t)); if (!this) @@ -1393,56 +1390,47 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi this->capabilities |= VO_CAP_XVMC_IDCT; XLockDisplay(this->display); - attr = XvQueryPortAttributes(display, xv_port, &nattr); + attr = XvQueryPortAttributes(this->display, xv_port, &nattr); if(attr && nattr) { int k; for(k = 0; k < nattr; k++) { if((attr[k].flags & XvSettable) && (attr[k].flags & XvGettable)) { - if(!strcmp(attr[k].name, "XV_HUE")) { - xvmc_check_capability (this, VO_PROP_HUE, attr[k], - class->adaptor_info[class->adaptor_num].base_id, "XV_HUE", - NULL, NULL, NULL); - - } else if(!strcmp(attr[k].name, "XV_SATURATION")) { + const char *const name = attr[k].name; + if(!strcmp(name, "XV_HUE")) { + if (!strncmp(adaptor_info[adaptor_num].name, "NV", 2)) { + xprintf (this->xine, XINE_VERBOSITY_NONE, LOG_MODULE ": ignoring broken XV_HUE settings on NVidia cards\n"); + } else { + xvmc_check_capability (this, VO_PROP_HUE, attr[k], + adaptor_info[adaptor_num].base_id, + NULL, NULL, NULL); + } + } else if(!strcmp(name, "XV_SATURATION")) { xvmc_check_capability (this, VO_PROP_SATURATION, attr[k], - class->adaptor_info[class->adaptor_num].base_id, "XV_SATURATION", + adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); - } else if(!strcmp(attr[k].name, "XV_BRIGHTNESS")) { xvmc_check_capability (this, VO_PROP_BRIGHTNESS, attr[k], - class->adaptor_info[class->adaptor_num].base_id, "XV_BRIGHTNESS", + adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); - - } else if(!strcmp(attr[k].name, "XV_CONTRAST")) { + } else if(!strcmp(name, "XV_CONTRAST")) { xvmc_check_capability (this, VO_PROP_CONTRAST, attr[k], - class->adaptor_info[class->adaptor_num].base_id, "XV_CONTRAST", + adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); - - } else if(!strcmp(attr[k].name, "XV_COLORKEY")) { + } else if(!strcmp(name, "XV_COLORKEY")) { xvmc_check_capability (this, VO_PROP_COLORKEY, attr[k], - class->adaptor_info[class->adaptor_num].base_id, "XV_COLORKEY", + adaptor_info[adaptor_num].base_id, "video.device.xv_colorkey", - _("video overlay colour key"), - _("The colour key is used to tell the graphics card where to " - "overlay the video image. Try different values, if you experience " - "windows becoming transparent.")); - - } else if(!strcmp(attr[k].name, "XV_AUTOPAINT_COLORKEY")) { + VIDEO_DEVICE_XV_COLORKEY_HELP); + } else if(!strcmp(name, "XV_AUTOPAINT_COLORKEY")) { xvmc_check_capability (this, VO_PROP_AUTOPAINT_COLORKEY, attr[k], - class->adaptor_info[class->adaptor_num].base_id, "XV_AUTOPAINT_COLORKEY", + adaptor_info[adaptor_num].base_id, "video.device.xv_autopaint_colorkey", - _("autopaint colour key"), - _("Make Xv autopaint its colour key.")); - - } else if(!strcmp(attr[k].name, "XV_DOUBLE_BUFFER")) { - int xvmc_double_buffer; - xvmc_double_buffer = config->register_bool (config, "video.device.xv_double_buffer", 1, - _("enable double buffering"), - _("Double buffering will synchronize the update of the video image to the " - "repainting of the entire screen (\"vertical retrace\"). This eliminates " - "flickering and tearing artifacts, but will use more graphics memory."), - 20, xvmc_update_XV_DOUBLE_BUFFER, this); + VIDEO_DEVICE_XV_AUTOPAINT_COLORKEY_HELP); + } else if(!strcmp(name, "XV_DOUBLE_BUFFER")) { + int xvmc_double_buffer = config->register_bool (config, "video.device.xv_double_buffer", 1, + VIDEO_DEVICE_XV_DOUBLE_BUFFER_HELP, + 20, xvmc_update_XV_DOUBLE_BUFFER, this); config->update_num(config,"video.device.xv_double_buffer",xvmc_double_buffer); } } @@ -1457,7 +1445,7 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi /* * check supported image formats */ - fo = XvListImageFormats(display, this->xv_port, (int*)&formats); + fo = XvListImageFormats(this->display, this->xv_port, (int*)&formats); XUnlockDisplay(this->display); this->xvmc_format_yv12 = 0; @@ -1509,10 +1497,6 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi static void dispose_class (video_driver_class_t *this_gen) { xvmc_class_t *this = (xvmc_class_t *) this_gen; - XLockDisplay(this->display); - XvFreeAdaptorInfo (this->adaptor_info); - XUnlockDisplay(this->display); - free (this); } @@ -1685,8 +1669,6 @@ static void *init_class (xine_t *xine, void *visual_gen) { this->display = display; this->config = xine->config; this->xv_port = xv_port; - this->adaptor_info = adaptor_info; - this->adaptor_num = adaptor_num; this->surface_type_id = surface_type; this->max_surface_width = max_width; this->max_surface_height = max_height; -- cgit v1.2.3 From faa7ff213ca3c85b0abde257d5a65b7e4b9c1338 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 2 Feb 2008 00:47:58 +0000 Subject: Convert the XxMC plugin to use the new header file. Also, a few trivial constness cleanups. --- src/video_out/video_out_xxmc.c | 75 +++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 48 deletions(-) diff --git a/src/video_out/video_out_xxmc.c b/src/video_out/video_out_xxmc.c index 7fc136e94..af7f52f54 100644 --- a/src/video_out/video_out_xxmc.c +++ b/src/video_out/video_out_xxmc.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2000-2004 the xine project + * Copyright (C) 2000-2004, 2008 the xine project * Copyright (C) 2004 the Unichrome project * * This file is part of xine, a free video player. @@ -34,9 +34,9 @@ */ - #include "xxmc.h" #include <unistd.h> +#include "xv_common.h" static int gX11Fail; @@ -2101,13 +2101,13 @@ static int xxmc_check_yv12 (Display *display, XvPortID port) { /* called xlocked */ static void xxmc_check_capability (xxmc_driver_t *this, - int property, XvAttribute attr, - int base_id, char *str_prop, - char *config_name, - char *config_desc, - char *config_help) { + int property, XvAttribute attr, int base_id, + const char *config_name, + const char *config_desc, + const char *config_help) { int int_default; cfg_entry_t *entry; + const char *str_prop = attr.name; if (VO_PROP_COLORKEY && (attr.max_value == ~0)) attr.max_value = 2147483615; @@ -2580,70 +2580,49 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi for(k = 0; k < nattr; k++) { if((attr[k].flags & XvSettable) && (attr[k].flags & XvGettable)) { - if(!strcmp(attr[k].name, "XV_HUE")) { + const char *const name = attr[k].name; + if(!strcmp(name, "XV_HUE")) { if (!strncmp(adaptor_info[adaptor_num].name, "NV", 2)) { xprintf (this->xine, XINE_VERBOSITY_NONE, LOG_MODULE ": ignoring broken XV_HUE settings on NVidia cards\n"); } else { xxmc_check_capability (this, VO_PROP_HUE, attr[k], - adaptor_info[adaptor_num].base_id, "XV_HUE", + adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); } - } else if(!strcmp(attr[k].name, "XV_SATURATION")) { + } else if(!strcmp(name, "XV_SATURATION")) { xxmc_check_capability (this, VO_PROP_SATURATION, attr[k], - adaptor_info[adaptor_num].base_id, "XV_SATURATION", + adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); - - } else if(!strcmp(attr[k].name, "XV_BRIGHTNESS")) { + } else if(!strcmp(name, "XV_BRIGHTNESS")) { xxmc_check_capability (this, VO_PROP_BRIGHTNESS, attr[k], - adaptor_info[adaptor_num].base_id, "XV_BRIGHTNESS", + adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); - - } else if(!strcmp(attr[k].name, "XV_CONTRAST")) { + } else if(!strcmp(name, "XV_CONTRAST")) { xxmc_check_capability (this, VO_PROP_CONTRAST, attr[k], - adaptor_info[adaptor_num].base_id, "XV_CONTRAST", + adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); - - } else if(!strcmp(attr[k].name, "XV_COLORKEY")) { + } else if(!strcmp(name, "XV_COLORKEY")) { xxmc_check_capability (this, VO_PROP_COLORKEY, attr[k], - adaptor_info[adaptor_num].base_id, "XV_COLORKEY", + adaptor_info[adaptor_num].base_id, "video.device.xv_colorkey", - _("video overlay colour key"), - _("The colour key is used to tell the graphics card where to " - "overlay the video image. Try different values, if you experience " - "windows becoming transparent.")); - - } else if(!strcmp(attr[k].name, "XV_AUTOPAINT_COLORKEY")) { + VIDEO_DEVICE_XV_COLORKEY_HELP); + } else if(!strcmp(name, "XV_AUTOPAINT_COLORKEY")) { xxmc_check_capability (this, VO_PROP_AUTOPAINT_COLORKEY, attr[k], - adaptor_info[adaptor_num].base_id, "XV_AUTOPAINT_COLORKEY", + adaptor_info[adaptor_num].base_id, "video.device.xv_autopaint_colorkey", - _("autopaint colour key"), - _("Make Xv autopaint its colour key.")); - - } else if(!strcmp(attr[k].name, "XV_FILTER")) { + VIDEO_DEVICE_XV_AUTOPAINT_COLORKEY_HELP); + } else if(!strcmp(name, "XV_FILTER")) { int xv_filter; /* This setting is specific to Permedia 2/3 cards. */ xv_filter = config->register_range (config, "video.device.xv_filter", 0, attr[k].min_value, attr[k].max_value, - _("bilinear scaling mode"), - _("Selects the bilinear scaling mode for Permedia cards. " - "The individual values are:\n\n" - "Permedia 2\n" - "0 - disable bilinear filtering\n" - "1 - enable bilinear filtering\n\n" - "Permedia 3\n" - "0 - disable bilinear filtering\n" - "1 - horizontal linear filtering\n" - "2 - enable full bilinear filtering"), + VIDEO_DEVICE_XV_FILTER_HELP, 20, xxmc_update_XV_FILTER, this); config->update_num(config,"video.device.xv_filter",xv_filter); - } else if(!strcmp(attr[k].name, "XV_DOUBLE_BUFFER")) { - int xv_double_buffer; - xv_double_buffer = + } else if(!strcmp(name, "XV_DOUBLE_BUFFER")) { + int xv_double_buffer = config->register_bool (config, "video.device.xv_double_buffer", 1, - _("enable double buffering"), - _("Double buffering will synchronize the update of the video image to the " - "repainting of the entire screen (\"vertical retrace\"). This eliminates " - "flickering and tearing artifacts, but will use more graphics memory."), + VIDEO_DEVICE_XV_DOUBLE_BUFFER_HELP, 20, xxmc_update_XV_DOUBLE_BUFFER, this); config->update_num(config,"video.device.xv_double_buffer",xv_double_buffer); } -- cgit v1.2.3 From d51d909e4cad6d49827ac23b36a99abd8f485eac Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 2 Feb 2008 17:36:33 +0000 Subject: Handle invalid port nos. properly (avoids a possible xcbxv segfault). --HG-- extra : transplant_source : %8AQ%03%86%FE%20%26%92%D2%A6%13g%1E%85%60%14%A0%A9%F3%22 --- src/video_out/video_out_xcbxv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/video_out/video_out_xcbxv.c b/src/video_out/video_out_xcbxv.c index 63313c43a..5064e89ad 100644 --- a/src/video_out/video_out_xcbxv.c +++ b/src/video_out/video_out_xcbxv.c @@ -945,6 +945,8 @@ static int xv_check_yv12(xcb_connection_t *connection, xcb_xv_port_t port) { list_formats_cookie = xcb_xv_list_image_formats(connection, port); list_formats_reply = xcb_xv_list_image_formats_reply(connection, list_formats_cookie, NULL); + if (!list_formats_reply) + return 1; /* no formats listed; probably due to an invalid port no. */ format_it = xcb_xv_list_image_formats_format_iterator(list_formats_reply); for (; format_it.rem; xcb_xv_image_format_info_next(&format_it)) -- cgit v1.2.3 From 4eed5fa989c8547195f7035fd59a1430b8962c5a Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 2 Feb 2008 18:18:15 +0000 Subject: Move more shared Xv config desc. & help strings; add new location to POTFILES. --- po/POTFILES.in | 1 + src/video_out/video_out_xcbxv.c | 6 ++---- src/video_out/video_out_xv.c | 6 ++---- src/video_out/video_out_xxmc.c | 6 ++---- src/video_out/xv_common.h | 8 ++++++++ 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index b067431df..c328946c9 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -118,6 +118,7 @@ src/video_out/video_out_xvmc.c src/video_out/video_out_xxmc.c src/video_out/x11osd.c src/video_out/xcbosd.c +src/video_out/xv_common.h src/xine-engine/alphablend.c src/xine-engine/audio_decoder.c src/xine-engine/audio_out.c diff --git a/src/video_out/video_out_xcbxv.c b/src/video_out/video_out_xcbxv.c index 5064e89ad..f61ae6a9c 100644 --- a/src/video_out/video_out_xcbxv.c +++ b/src/video_out/video_out_xcbxv.c @@ -1197,8 +1197,7 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis adaptor_it = xcb_xv_query_adaptors_info_iterator(query_adaptors_reply); xv_port = config->register_num (config, "video.device.xv_port", 0, - _("Xv port number"), - _("Selects the Xv port number to use (0 to autodetect)."), + VIDEO_DEVICE_XV_PORT_HELP, 10, NULL, NULL); if (xv_port != 0) { @@ -1380,8 +1379,7 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis this->use_pitch_alignment = config->register_bool (config, "video.device.xv_pitch_alignment", 0, - _("pitch alignment workaround"), - _("Some buggy video drivers need a workaround to function properly."), + VIDEO_DEVICE_XV_PITCH_ALIGNMENT_HELP, 10, xv_update_xv_pitch_alignment, this); if(this->use_colorkey==1) { diff --git a/src/video_out/video_out_xv.c b/src/video_out/video_out_xv.c index a92f6dbe8..6cdbc6b64 100644 --- a/src/video_out/video_out_xv.c +++ b/src/video_out/video_out_xv.c @@ -1233,8 +1233,7 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void * } xv_port = config->register_num (config, "video.device.xv_port", 0, - _("Xv port number"), - _("Selects the Xv port number to use (0 to autodetect)."), + VIDEO_DEVICE_XV_PORT_HELP, 10, NULL, NULL); if (xv_port != 0) { @@ -1438,8 +1437,7 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void * this->use_pitch_alignment = config->register_bool (config, "video.device.xv_pitch_alignment", 0, - _("pitch alignment workaround"), - _("Some buggy video drivers need a workaround to function properly."), + VIDEO_DEVICE_XV_PITCH_ALIGNMENT_HELP, 10, xv_update_xv_pitch_alignment, this); LOCK_DISPLAY(this); diff --git a/src/video_out/video_out_xxmc.c b/src/video_out/video_out_xxmc.c index af7f52f54..107ed9c7b 100644 --- a/src/video_out/video_out_xxmc.c +++ b/src/video_out/video_out_xxmc.c @@ -2478,8 +2478,7 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi } xv_port = config->register_num (config, "video.device.xv_port", 0, - _("Xv port number"), - _("Selects the Xv port number to use (0 to autodetect)."), + VIDEO_DEVICE_XV_PORT_HELP, 10, NULL, NULL); if (xv_port != 0) { @@ -2688,8 +2687,7 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi this->use_pitch_alignment = config->register_bool (config, "video.device.xv_pitch_alignment", 0, - _("pitch alignment workaround"), - _("Some buggy video drivers need a workaround to function properly."), + VIDEO_DEVICE_XV_PITCH_ALIGNMENT_HELP, 10, xxmc_update_xv_pitch_alignment, this); use_more_frames= diff --git a/src/video_out/xv_common.h b/src/video_out/xv_common.h index 71eecddad..ee2ab9a10 100644 --- a/src/video_out/xv_common.h +++ b/src/video_out/xv_common.h @@ -48,3 +48,11 @@ "image to the repainting of the entire screen (\"vertical " \ "retrace\"). This eliminates flickering and tearing artifacts, " \ "but will use more graphics memory.") + +#define VIDEO_DEVICE_XV_PORT_HELP \ + _("Xv port number"), \ + _("Selects the Xv port number to use (0 to autodetect).") + +#define VIDEO_DEVICE_XV_PITCH_ALIGNMENT_HELP \ + _("pitch alignment workaround"), \ + _("Some buggy video drivers need a workaround to function properly.") -- cgit v1.2.3 From 15ed98032861393d23adf4076c704a0d85361895 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sun, 3 Feb 2008 00:34:10 +0000 Subject: The AVI demuxer already has the video type when checking for XVid. Optimise. --- src/demuxers/demux_avi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/demuxers/demux_avi.c b/src/demuxers/demux_avi.c index c6a73ebde..239517777 100644 --- a/src/demuxers/demux_avi.c +++ b/src/demuxers/demux_avi.c @@ -1899,8 +1899,8 @@ static void demux_avi_send_headers (demux_plugin_t *this_gen) { * however, at least for this case (compressor: xvid biCompression: DIVX), the * xvid fourcc must prevail as it is used by ffmpeg to detect encoder bugs. [MF] */ - if( _x_fourcc_to_buf_video(this->avi->compressor) == BUF_VIDEO_XVID && - _x_fourcc_to_buf_video(this->avi->bih->biCompression) == BUF_VIDEO_MPEG4 ) { + if( this->avi->video_type == BUF_VIDEO_MPEG4 && + _x_fourcc_to_buf_video(this->avi->compressor) == BUF_VIDEO_XVID ) { this->avi->bih->biCompression = this->avi->compressor; this->avi->video_type = BUF_VIDEO_XVID; } -- cgit v1.2.3 From 07252cde358272ec7a65f9d862462ba5ca08d682 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Mon, 4 Feb 2008 00:25:26 +0000 Subject: Fix a few remaining and apparently harmless linkage order issues. --- src/video_out/Makefile.am | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/video_out/Makefile.am b/src/video_out/Makefile.am index d447417c5..6376e7629 100644 --- a/src/video_out/Makefile.am +++ b/src/video_out/Makefile.am @@ -130,8 +130,8 @@ xineplug_vo_out_xxmc_la_CFLAGS = $(VISIBILITY_FLAG) $(X_CFLAGS) $(XV_CFLAGS) -fn xineplug_vo_out_opengl_la_SOURCES = yuv2rgb.c yuv2rgb_mmx.c yuv2rgb_mlib.c \ video_out_opengl.c myglext.h $(X11OSD) -xineplug_vo_out_opengl_la_LIBADD = $(MLIB_LIBS) $(OPENGL_LIBS) $(GLUT_LIBS) \ - $(GLU_LIBS) $(X_LIBS) $(XINE_LIB) $(PTHREAD_LIBS) $(DYNAMIC_LD_LIBS) $(LTLIBINTL) +xineplug_vo_out_opengl_la_LIBADD = $(XINE_LIB) $(MLIB_LIBS) $(OPENGL_LIBS) \ + $(GLUT_LIBS) $(GLU_LIBS) $(X_LIBS) $(PTHREAD_LIBS) $(DYNAMIC_LD_LIBS) $(LTLIBINTL) xineplug_vo_out_opengl_la_CFLAGS = $(VISIBILITY_FLAG) $(X_CFLAGS) $(MLIB_CFLAGS) -fno-strict-aliasing xineplug_vo_out_syncfb_la_SOURCES = video_out_syncfb.c @@ -193,8 +193,8 @@ xineplug_vo_out_none_la_CFLAGS = $(VISIBILITY_FLAG) xineplug_vo_out_macosx_la_SOURCES = video_out_macosx.m xineplug_vo_out_macosx_la_CPPFLAGS = $(AM_CPPFLAGS) $(X_CFLAGS) $(MLIB_CFLAGS) xineplug_vo_out_macosx_la_OBJCFLAGS = $(VISIBILITY_FLAG) -xineplug_vo_out_macosx_la_LIBADD = $(MLIB_LIBS) $(OPENGL_LIBS) $(GLUT_LIBS) \ - $(GLU_LIBS) $(X_LIBS) $(XINE_LIB) $(PTHREAD_LIBS) +xineplug_vo_out_macosx_la_LIBADD = $(XINE_LIB) $(MLIB_LIBS) $(OPENGL_LIBS) \ + $(GLUT_LIBS) $(GLU_LIBS) $(X_LIBS) $(PTHREAD_LIBS) # The "-Wl,-framework -Wl,Cocoa" is needed for libtool versions before # 1.5.x (1.257): the default version that ships with Mac OS X is 1.5 (1.1220) xineplug_vo_out_macosx_la_LDFLAGS = $(AM_LDFLAGS) \ -- cgit v1.2.3 From b9aad123aa3af9db55ce604b3eb185e26b0361a5 Mon Sep 17 00:00:00 2001 From: Mathieu Olivier <molivier@users.sourceforge.net> Date: Mon, 4 Feb 2008 15:08:25 +0000 Subject: Check block sizes & frame sizes. Use unsigned variables where appropriate. --- src/demuxers/demux_matroska.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/src/demuxers/demux_matroska.c b/src/demuxers/demux_matroska.c index b973c1caf..3c992ecca 100644 --- a/src/demuxers/demux_matroska.c +++ b/src/demuxers/demux_matroska.c @@ -1836,7 +1836,7 @@ static int parse_block (demux_matroska_t *this, uint64_t block_size, uint64_t cluster_timecode, uint64_t block_duration, int normpos, int is_key) { matroska_track_t *track; - int64_t track_num; + uint64_t track_num; uint8_t *data; uint8_t flags; int gap, lacing, num_len; @@ -1855,7 +1855,7 @@ static int parse_block (demux_matroska_t *this, uint64_t block_size, flags = *data; data += 1; - lprintf("track_num: %" PRId64 ", timecode_diff: %d, flags: 0x%x\n", track_num, timecode_diff, flags); + lprintf("track_num: %" PRIu64 ", timecode_diff: %d, flags: 0x%x\n", track_num, timecode_diff, flags); gap = flags & 1; lacing = (flags >> 1) & 0x3; @@ -1863,7 +1863,7 @@ static int parse_block (demux_matroska_t *this, uint64_t block_size, if (!find_track_by_id(this, (int)track_num, &track)) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, - "demux_matroska: invalid track id: %" PRId64 "\n", track_num); + "demux_matroska: invalid track id: %" PRIu64 "\n", track_num); return 0; } @@ -1972,24 +1972,51 @@ static int parse_block (demux_matroska_t *this, uint64_t block_size, break; case MATROSKA_EBML_LACING: { - int64_t tmp; + uint64_t first_frame_size; lprintf("ebml lacing\n"); /* size of each frame */ - if (!(num_len = parse_ebml_uint(this, data, &tmp))) + if (!(num_len = parse_ebml_uint(this, data, &first_frame_size))) return 0; + if (num_len > block_size_left) { + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + "demux_matroska: block too small\n"); + return 0; + } + if (first_frame_size > INT_MAX) { + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + "demux_matroska: invalid first frame size (%" PRId64 ")\n", + first_frame_size); + return 0; + } data += num_len; block_size_left -= num_len; - frame[0] = (int) tmp; + frame[0] = (int) first_frame_size; lprintf("first frame len: %d\n", frame[0]); block_size_left -= frame[0]; for (i = 1; i < lace_num; i++) { - if (!(num_len = parse_ebml_sint(this, data, &tmp))) + int64_t frame_size_diff; + int64_t frame_size; + + if (!(num_len = parse_ebml_sint(this, data, &frame_size_diff))) return 0; + if (num_len > block_size_left) { + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + "demux_matroska: block too small\n"); + return 0; + } data += num_len; block_size_left -= num_len; - frame[i] = frame[i-1] + tmp; + + frame_size = frame[i-1] + frame_size_diff; + if (frame_size > INT_MAX || frame_size < 0) { + xprintf(this->stream->xine, XINE_VERBOSITY_LOG, + "demux_matroska: invalid frame size (%" PRId64 ")\n", + frame_size); + return 0; + } + frame[i] = frame_size; block_size_left -= frame[i]; } -- cgit v1.2.3 From dac76e08eaf7a876df7d251d613b4a175dbbe2ff Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Mon, 4 Feb 2008 16:54:51 +0000 Subject: Backed out changeset a8b157e7359c (reported to cause a regression). A proper fix is in changeset a62d6f482a69. --- src/demuxers/demux_matroska.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/demuxers/demux_matroska.c b/src/demuxers/demux_matroska.c index f8166173a..7deceb500 100644 --- a/src/demuxers/demux_matroska.c +++ b/src/demuxers/demux_matroska.c @@ -1845,7 +1845,7 @@ static int parse_block (demux_matroska_t *this, uint64_t block_size, int decoder_flags = 0; data = this->block_data; - if (!(num_len = parse_ebml_sint(this, data, &track_num))) + if (!(num_len = parse_ebml_uint(this, data, &track_num))) return 0; data += num_len; @@ -1977,7 +1977,7 @@ static int parse_block (demux_matroska_t *this, uint64_t block_size, lprintf("ebml lacing\n"); /* size of each frame */ - if (!(num_len = parse_ebml_sint(this, data, &tmp))) + if (!(num_len = parse_ebml_uint(this, data, &tmp))) return 0; data += num_len; block_size_left -= num_len; frame[0] = (int) tmp; -- cgit v1.2.3 From 62edd260de78d783eda0174c65a991389b5343ab Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Mon, 4 Feb 2008 16:50:37 +0000 Subject: Silence vdr_video (unless LOG and LOG_VERBOSE are defined). --HG-- extra : transplant_source : %B3%7E6%F5%18%80i%20rb%10m%8AA8G%87%F5%A8r --- src/vdr/post_vdr_video.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/vdr/post_vdr_video.c b/src/vdr/post_vdr_video.c index 4d1055aaf..178538655 100644 --- a/src/vdr/post_vdr_video.c +++ b/src/vdr/post_vdr_video.c @@ -23,9 +23,9 @@ */ #define LOG_MODULE "vdr_video" -#define LOG_VERBOSE /* #define LOG +#define LOG_VERBOSE */ #include <xine/xine_internal.h> @@ -437,12 +437,14 @@ static int vdr_video_draw(vo_frame_t *frame, xine_stream_t *stream) frame->next->pts = 0; } */ +#if defined(LOG) && defined(LOG_VERBOSE) { int a = 0, b = 0, c = 0, d = 0; if (stream) _x_query_buffer_usage(stream, &a, &b, &c, &d); - fprintf(stderr, "buffer usage: %3d, %2d, %2d, %2d, %p\n", a, b, c, d, stream); + lprintf("buffer usage: %3d, %2d, %2d, %2d, %p\n", a, b, c, d, stream); } +#endif if (!this->enabled || frame->bad_frame -- cgit v1.2.3 From 9ce813b22bb06b78c97c5c249e8feeb2ec1441bd Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Mon, 4 Feb 2008 17:19:22 +0000 Subject: Tidy up Xv YUY2/YV12 checking & reporting. --- src/video_out/video_out_xcbxv.c | 13 +++++++++---- src/video_out/video_out_xv.c | 13 +++++++++---- src/video_out/video_out_xvmc.c | 20 +++++++++++++------- src/video_out/video_out_xxmc.c | 13 +++++++++---- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/video_out/video_out_xcbxv.c b/src/video_out/video_out_xcbxv.c index f61ae6a9c..6fed0f90a 100644 --- a/src/video_out/video_out_xcbxv.c +++ b/src/video_out/video_out_xcbxv.c @@ -1362,16 +1362,21 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis (format_it.data->format == XCB_XV_IMAGE_FORMAT_INFO_FORMAT_PACKED) ? "packed" : "planar"); - if (format_it.data->id == XINE_IMGFMT_YV12) { + switch (format_it.data->id) { + case XINE_IMGFMT_YV12: this->xv_format_yv12 = format_it.data->id; this->capabilities |= VO_CAP_YV12; xprintf(this->xine, XINE_VERBOSITY_LOG, - _("%s: this adaptor supports the yv12 format.\n"), LOG_MODULE); - } else if (format_it.data->id == XINE_IMGFMT_YUY2) { + _("%s: this adaptor supports the %s format.\n"), LOG_MODULE, "YV12"); + break; + case XINE_IMGFMT_YUY2: this->xv_format_yuy2 = format_it.data->id; this->capabilities |= VO_CAP_YUY2; xprintf(this->xine, XINE_VERBOSITY_LOG, - _("%s: this adaptor supports the yuy2 format.\n"), LOG_MODULE); + _("%s: this adaptor supports the %s format.\n"), LOG_MODULE, "YUY2"); + break; + default: + break; } } diff --git a/src/video_out/video_out_xv.c b/src/video_out/video_out_xv.c index 6cdbc6b64..6f5c68e51 100644 --- a/src/video_out/video_out_xv.c +++ b/src/video_out/video_out_xv.c @@ -1406,16 +1406,21 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void * fo[i].id, (char*)&fo[i].id, (fo[i].format == XvPacked) ? "packed" : "planar"); - if (fo[i].id == XINE_IMGFMT_YV12) { + switch (fo[i].id) { + case XINE_IMGFMT_YV12: this->xv_format_yv12 = fo[i].id; this->capabilities |= VO_CAP_YV12; xprintf(this->xine, XINE_VERBOSITY_LOG, - _("%s: this adaptor supports the yv12 format.\n"), LOG_MODULE); - } else if (fo[i].id == XINE_IMGFMT_YUY2) { + _("%s: this adaptor supports the %s format.\n"), LOG_MODULE, "YV12"); + break; + case XINE_IMGFMT_YUY2: this->xv_format_yuy2 = fo[i].id; this->capabilities |= VO_CAP_YUY2; xprintf(this->xine, XINE_VERBOSITY_LOG, - _("%s: this adaptor supports the yuy2 format.\n"), LOG_MODULE); + _("%s: this adaptor supports the %s format.\n"), LOG_MODULE, "YUY2"); + break; + default: + break; } } diff --git a/src/video_out/video_out_xvmc.c b/src/video_out/video_out_xvmc.c index c0fb10be3..9618b082c 100644 --- a/src/video_out/video_out_xvmc.c +++ b/src/video_out/video_out_xvmc.c @@ -1456,15 +1456,21 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi fo[i].id, (char*)&fo[i].id, (fo[i].format == XvPacked) ? "packed" : "planar"); - if (fo[i].id == XINE_IMGFMT_YV12) { + switch (fo[i].id) { + case XINE_IMGFMT_YV12: this->xvmc_format_yv12 = fo[i].id; - this->capabilities |= VO_CAP_YV12; - lprintf("this adaptor supports the yv12 format.\n"); - } - else if (fo[i].id == XINE_IMGFMT_YUY2) { + this->capabilities |= VO_CAP_YV12; + xprintf(this->xine, XINE_VERBOSITY_LOG, + _("%s: this adaptor supports the %s format.\n"), LOG_MODULE, "YV12"); + break; + case XINE_IMGFMT_YUY2: this->xvmc_format_yuy2 = fo[i].id; - this->capabilities |= VO_CAP_YUY2; - lprintf("this adaptor supports the yuy2 format.\n"); + this->capabilities |= VO_CAP_YUY2; + xprintf(this->xine, XINE_VERBOSITY_LOG, + _("%s: this adaptor supports the %s format.\n"), LOG_MODULE, "YUY2"); + break; + default: + break; } } diff --git a/src/video_out/video_out_xxmc.c b/src/video_out/video_out_xxmc.c index 107ed9c7b..2c42dda2e 100644 --- a/src/video_out/video_out_xxmc.c +++ b/src/video_out/video_out_xxmc.c @@ -2655,16 +2655,21 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi fo[i].id, (char*)&fo[i].id, (fo[i].format == XvPacked) ? "packed" : "planar"); - if (fo[i].id == XINE_IMGFMT_YV12) { + switch (fo[i].id) { + case XINE_IMGFMT_YV12: this->xv_format_yv12 = fo[i].id; this->capabilities |= VO_CAP_YV12; xprintf(this->xine, XINE_VERBOSITY_LOG, - _("%s: this adaptor supports the yv12 format.\n"), LOG_MODULE); - } else if (fo[i].id == XINE_IMGFMT_YUY2) { + _("%s: this adaptor supports the %s format.\n"), LOG_MODULE, "YV12"); + break; + case XINE_IMGFMT_YUY2: this->xv_format_yuy2 = fo[i].id; this->capabilities |= VO_CAP_YUY2; xprintf(this->xine, XINE_VERBOSITY_LOG, - _("%s: this adaptor supports the yuy2 format.\n"), LOG_MODULE); + _("%s: this adaptor supports the %s format.\n"), LOG_MODULE, "YUY2"); + break; + default: + break; } } -- cgit v1.2.3 From 1258f00aaa71c16800717caf628f69f2e8e6f4ca Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Mon, 4 Feb 2008 18:16:37 +0000 Subject: Report the identifiers of unrecognised video & audio codecs. --- include/xine/xineutils.h | 6 ++++++ src/combined/xine_ogg_demuxer.c | 9 +++++++-- src/demuxers/demux_asf.c | 9 +++------ src/demuxers/demux_avi.c | 11 +++++++++-- src/demuxers/demux_film.c | 4 ++++ src/demuxers/demux_matroska.c | 4 ++++ src/demuxers/demux_nsv.c | 8 ++++++++ src/demuxers/demux_qt.c | 8 ++++++++ src/demuxers/demux_real.c | 6 ++++++ src/demuxers/demux_smjpeg.c | 4 ++++ src/xine-engine/buffer_types.c | 39 +++++++++++++++++++++++++++++++++++++++ 11 files changed, 98 insertions(+), 10 deletions(-) diff --git a/include/xine/xineutils.h b/include/xine/xineutils.h index 5f052ee58..438954557 100644 --- a/include/xine/xineutils.h +++ b/include/xine/xineutils.h @@ -954,6 +954,12 @@ int xine_monotonic_clock(struct timeval *tv, struct timezone *tz) XINE_PROTECTED */ uint32_t _x_compute_crc32 (const uint8_t * data, int32_t length, uint32_t crc32) XINE_PROTECTED; +/** + * Unknown FourCC reporting functions + */ +void _x_report_video_fourcc (xine_t *, const char *module, uint32_t) XINE_PROTECTED; +void _x_report_audio_format_tag (xine_t *, const char *module, uint32_t) XINE_PROTECTED; + /* don't harm following code */ #ifdef extern # undef extern diff --git a/src/combined/xine_ogg_demuxer.c b/src/combined/xine_ogg_demuxer.c index b09bc1a41..88fcea08a 100644 --- a/src/combined/xine_ogg_demuxer.c +++ b/src/combined/xine_ogg_demuxer.c @@ -892,7 +892,10 @@ static void decode_video_header (demux_ogg_t *this, const int stream_num, ogg_pa this->si[stream_num]->buf_types = _x_fourcc_to_buf_video (locsubtype); if( !this->si[stream_num]->buf_types ) + { this->si[stream_num]->buf_types = BUF_VIDEO_UNKNOWN; + _x_report_video_fourcc (this->stream->xine, LOG_MODULE, locsubtype); + } this->si[stream_num]->buf_types |= channel; this->si[stream_num]->headers = 0; /* header is sent below */ @@ -977,9 +980,8 @@ static void decode_audio_header (demux_ogg_t *this, const int stream_num, ogg_pa if( this->si[stream_num]->buf_types ) { this->si[stream_num]->buf_types |= channel; } else { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "demux_ogg: unknown audio codec type 0x%x\n", codec); this->si[stream_num]->buf_types = BUF_AUDIO_UNKNOWN; + _x_report_audio_format_tag (this->stream->xine, LOG_MODULE, codec); /*break;*/ } @@ -1044,7 +1046,10 @@ static void decode_dshow_header (demux_ogg_t *this, const int stream_num, ogg_pa this->si[stream_num]->buf_types = _x_fourcc_to_buf_video (fcc); if( !this->si[stream_num]->buf_types ) + { this->si[stream_num]->buf_types = BUF_VIDEO_UNKNOWN; + _x_report_video_fourcc (this->stream->xine, LOG_MODULE, fcc); + } this->si[stream_num]->buf_types |= channel; bih.biSize = sizeof(xine_bmiheader); diff --git a/src/demuxers/demux_asf.c b/src/demuxers/demux_asf.c index 827557333..73f70eeb3 100644 --- a/src/demuxers/demux_asf.c +++ b/src/demuxers/demux_asf.c @@ -464,10 +464,9 @@ static int asf_read_header (demux_asf_t *this) { demux_stream->buf_type = _x_formattag_to_buf_audio ( ((xine_waveformatex *)asf_stream->private_data)->wFormatTag ); if ( !demux_stream->buf_type ) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "demux_asf: unknown audio type 0x%x\n", - ((xine_waveformatex *)asf_stream->private_data)->wFormatTag); demux_stream->buf_type = BUF_AUDIO_UNKNOWN; + _x_report_audio_format_tag (this->stream->xine, LOG_MODULE, + ((xine_waveformatex *)asf_stream->private_data)->wFormatTag); } _x_meta_info_set(this->stream, XINE_META_INFO_AUDIOCODEC, _x_buf_audio_name(demux_stream->buf_type)); @@ -510,10 +509,8 @@ static int asf_read_header (demux_asf_t *this) { demux_stream->buf_type = _x_fourcc_to_buf_video(bmiheader->biCompression); if( !demux_stream->buf_type ) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, - "demux_asf: unknown video format %.4s\n", (char*)&(bmiheader->biCompression)); - demux_stream->buf_type = BUF_VIDEO_UNKNOWN; + _x_report_video_fourcc (this->stream->xine, LOG_MODULE, bmiheader->biCompression); } _x_meta_info_set(this->stream, XINE_META_INFO_VIDEOCODEC, _x_buf_video_name(demux_stream->buf_type)); diff --git a/src/demuxers/demux_avi.c b/src/demuxers/demux_avi.c index 239517777..27dfce443 100644 --- a/src/demuxers/demux_avi.c +++ b/src/demuxers/demux_avi.c @@ -1871,7 +1871,12 @@ static void demux_avi_send_headers (demux_plugin_t *this_gen) { if (!this->avi->bih->biCompression) this->avi->video_type = BUF_VIDEO_RGB; else + { this->avi->video_type = _x_fourcc_to_buf_video(this->avi->bih->biCompression); + if (!this->avi->video_type) + _x_report_video_fourcc (this->stream->xine, LOG_MODULE, + this->avi->bih->biCompression); + } for(i=0; i < this->avi->n_audio; i++) { this->avi->audio[i]->audio_type = _x_formattag_to_buf_audio (this->avi->audio[i]->wavex->wFormatTag); @@ -1884,10 +1889,10 @@ static void demux_avi_send_headers (demux_plugin_t *this_gen) { } if( !this->avi->audio[i]->audio_type ) { - xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "unknown audio type 0x%x\n", - this->avi->audio[i]->wavex->wFormatTag); this->no_audio = 1; this->avi->audio[i]->audio_type = BUF_AUDIO_UNKNOWN; + _x_report_audio_format_tag (this->stream->xine, LOG_MODULE, + this->avi->audio[i]->wavex->wFormatTag); } else xprintf (this->stream->xine, XINE_VERBOSITY_DEBUG, "demux_avi: audio type %s (wFormatTag 0x%x)\n", _x_buf_audio_name(this->avi->audio[i]->audio_type), @@ -1949,6 +1954,8 @@ static void demux_avi_send_headers (demux_plugin_t *this_gen) { this->avi->compressor = this->avi->bih->biCompression; } else { this->avi->video_type = _x_fourcc_to_buf_video(this->avi->compressor); + if (!this->avi->video_type) + _x_fourcc_to_buf_video(this->avi->bih->biCompression); } _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_FOURCC, diff --git a/src/demuxers/demux_film.c b/src/demuxers/demux_film.c index cc9e90d66..193d8850b 100644 --- a/src/demuxers/demux_film.c +++ b/src/demuxers/demux_film.c @@ -201,7 +201,11 @@ static int open_film_file(demux_film_t *film) { film->video_type = _x_fourcc_to_buf_video(*(uint32_t *)&film_header[i + 8]); if( !film->video_type ) + { film->video_type = BUF_VIDEO_UNKNOWN; + _x_report_video_fourcc (film->stream->xine, LOG_MODULE, + *(uint32_t *)&film_header[i + 8]); + } /* fetch the audio information if the chunk size checks out */ if (chunk_size == 32) { diff --git a/src/demuxers/demux_matroska.c b/src/demuxers/demux_matroska.c index 9b32f02c9..ae71923d6 100644 --- a/src/demuxers/demux_matroska.c +++ b/src/demuxers/demux_matroska.c @@ -1303,6 +1303,8 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { _x_bmiheader_le2me(bih); track->buf_type = _x_fourcc_to_buf_video(bih->biCompression); + if (!track->buf_type) + _x_report_video_fourcc (this->stream->xine, LOG_MODULE, bih->biCompression); init_codec = init_codec_video; } else if (!strcmp(track->codec_id, MATROSKA_CODEC_ID_V_UNCOMPRESSED)) { @@ -1413,6 +1415,8 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { _x_waveformatex_le2me(wfh); track->buf_type = _x_formattag_to_buf_audio(wfh->wFormatTag); + if (!track->buf_type) + _x_report_audio_format_tag (this->stream->xine, LOG_MODULE, wfh->wFormatTag); init_codec = init_codec_audio; } else if (!strncmp(track->codec_id, MATROSKA_CODEC_ID_A_AAC, sizeof(MATROSKA_CODEC_ID_A_AAC) - 1)) { diff --git a/src/demuxers/demux_nsv.c b/src/demuxers/demux_nsv.c index 74f98c7cd..43b1fbc88 100644 --- a/src/demuxers/demux_nsv.c +++ b/src/demuxers/demux_nsv.c @@ -305,13 +305,21 @@ static int open_nsv_file(demux_nsv_t *this) { if (_X_BE_32(&preview[4]) == NONE_TAG) this->video_type = 0; else + { this->video_type = _x_fourcc_to_buf_video(this->video_fourcc); + if (!this->video_type) + _x_report_video_fourcc (this->stream->xine, LOG_MODULE, this->video_fourcc); + } this->audio_fourcc = _X_ME_32(&preview[8]); if (_X_BE_32(&preview[8]) == NONE_TAG) this->audio_type = 0; else + { this->audio_type = _x_formattag_to_buf_audio(this->audio_fourcc); + if (!this->audio_type) + _x_report_audio_format_tag (this->stream->xine, LOG_MODULE, this->audio_fourcc); + } this->bih.biSize = sizeof(this->bih); this->bih.biWidth = _X_LE_16(&preview[12]); diff --git a/src/demuxers/demux_qt.c b/src/demuxers/demux_qt.c index 6b2aa5eea..ecd2c319a 100644 --- a/src/demuxers/demux_qt.c +++ b/src/demuxers/demux_qt.c @@ -2628,7 +2628,11 @@ static void demux_qt_send_headers(demux_plugin_t *this_gen) { if( !video_trak->properties->video.codec_buftype && video_trak->properties->video.codec_fourcc ) + { video_trak->properties->video.codec_buftype = BUF_VIDEO_UNKNOWN; + _x_report_video_fourcc (this->stream->xine, LOG_MODULE, + video_trak->properties->video.codec_fourcc); + } _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_VIDEO, 1); _x_stream_info_set(this->stream, XINE_STREAM_INFO_VIDEO_WIDTH, @@ -2670,7 +2674,11 @@ static void demux_qt_send_headers(demux_plugin_t *this_gen) { if( !audio_trak->properties->audio.codec_buftype && audio_trak->properties->audio.codec_fourcc ) + { audio_trak->properties->audio.codec_buftype = BUF_AUDIO_UNKNOWN; + _x_report_audio_format_tag (this->stream->xine, LOG_MODULE, + audio_trak->properties->audio.codec_fourcc); + } _x_stream_info_set(this->stream, XINE_STREAM_INFO_HAS_AUDIO, 1); _x_stream_info_set(this->stream, XINE_STREAM_INFO_AUDIO_CHANNELS, diff --git a/src/demuxers/demux_real.c b/src/demuxers/demux_real.c index 8f6ce0611..41c6fb4a2 100644 --- a/src/demuxers/demux_real.c +++ b/src/demuxers/demux_real.c @@ -459,6 +459,9 @@ static void real_parse_headers (demux_real_t *this) { this->num_audio_streams++; + if (!this->audio_streams[this->num_audio_streams].buf_type) + _x_report_audio_format_tag (this->stream->xine, LOG_MODULE, fourcc); + } else if(_X_BE_32(mdpr->type_specific_data + 4) == VIDO_TAG) { if(this->num_video_streams == MAX_VIDEO_STREAMS) { @@ -479,6 +482,9 @@ static void real_parse_headers (demux_real_t *this) { this->num_video_streams++; + if (!this->video_streams[this->num_video_streams].buf_type) + _x_report_video_fourcc (this->stream->xine, LOG_MODULE, fourcc); + } else { lprintf("unrecognised type specific data\n"); diff --git a/src/demuxers/demux_smjpeg.c b/src/demuxers/demux_smjpeg.c index 10cdf8120..d9b436032 100644 --- a/src/demuxers/demux_smjpeg.c +++ b/src/demuxers/demux_smjpeg.c @@ -147,6 +147,8 @@ static int open_smjpeg_file(demux_smjpeg_t *this) { this->bih.biHeight = _X_BE_16(&header_chunk[10]); this->bih.biCompression = *(uint32_t *)&header_chunk[12]; this->video_type = _x_fourcc_to_buf_video(this->bih.biCompression); + if (!this->video_type) + _x_report_video_fourcc (this->stream->xine, LOG_MODULE, this->bih.biCompression); break; case _SND_TAG: @@ -166,6 +168,8 @@ static int open_smjpeg_file(demux_smjpeg_t *this) { } else { audio_codec = *(uint32_t *)&header_chunk[8]; this->audio_type = _x_formattag_to_buf_audio(audio_codec); + if (!this->audio_type) + _x_report_audio_format_tag (this->stream->xine, LOG_MODULE, audio_codec); } break; diff --git a/src/xine-engine/buffer_types.c b/src/xine-engine/buffer_types.c index c7b6ae860..b0e01db31 100644 --- a/src/xine-engine/buffer_types.c +++ b/src/xine-engine/buffer_types.c @@ -33,6 +33,8 @@ #include <stdlib.h> #include <inttypes.h> #include <xine/buffer.h> +#include <xine/xineutils.h> +#include <xine/xine_internal.h> #include "bswap.h" typedef struct video_db_s { @@ -1209,6 +1211,43 @@ int i; return ""; } + +static void code_to_text (char ascii[5], uint32_t code) +{ + int i; + for (i = 0; i < 4; ++i) + { + int byte = code & 0xFF; + ascii[i] = (byte < ' ') ? ' ' : (byte >= 0x7F) ? '.' : (char) byte; + code >>= 8; + } +} + +void _x_report_video_fourcc (xine_t *xine, const char *module, uint32_t code) +{ + if (code) + { + char ascii[5]; + code_to_text (ascii, code); + xprintf (xine, XINE_VERBOSITY_LOG, + _("%s: unknown video FourCC code %#x \"%s\"\n"), + module, code, ascii); + } +} + +void _x_report_audio_format_tag (xine_t *xine, const char *module, uint32_t code) +{ + if (code) + { + char ascii[5]; + code_to_text (ascii, code); + xprintf (xine, XINE_VERBOSITY_LOG, + _("%s: unknown audio format tag code %#x \"%s\"\n"), + module, code, ascii); + } +} + + void _x_bmiheader_le2me( xine_bmiheader *bih ) { /* OBS: fourcc must be read using machine endianness * so don't play with biCompression here! -- cgit v1.2.3 From fac37975dd471c945145e5f147932170d4f4198f Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Wed, 6 Feb 2008 18:27:31 +0000 Subject: Change from release numbering to ABI numbering for the plugin directory. This is to avoid having to rebuild external plugins for each new release. --HG-- extra : transplant_source : %C2%3EF%0B%EF%16%40K%FD.%EB9%E07%CB%97GhU%98 --- ChangeLog | 6 ++++ configure.ac | 26 +++++++++----- src/xine-engine/load_plugins.c | 79 +++++++++++++++++++++++------------------- 3 files changed, 67 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index f05ce93eb..e9af6b424 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ xine-lib (1.1.11) unreleased * Fix a RealPlayer codec detection bug. + * Reworked the plugin directory naming so that external plugins don't have + to be rebuilt for every release. We now use a naming scheme based on the + API/ABI versioning, checking older directories - with this release, the + plugin directory name is 1.19, and if this gets bumped to 1.20 in a + future release, 1.19 will still be available for external plugins. + (Any directories not 1.* won't be looked in.) xine-lib (1.1.10) 2008-01-26 * Security fixes: diff --git a/configure.ac b/configure.ac index 9badb9d23..51d30234b 100644 --- a/configure.ac +++ b/configure.ac @@ -78,6 +78,9 @@ AC_SUBST(XINE_LT_CURRENT) AC_SUBST(XINE_LT_REVISION) AC_SUBST(XINE_LT_AGE) +AC_DEFINE_UNQUOTED(XINE_LT_CURRENT, $XINE_LT_CURRENT, [xine interface version number]) +AC_DEFINE_UNQUOTED(XINE_LT_AGE, $XINE_LT_AGE, [xine interface version age]) + SPEC_VERSION=$XINE_MAJOR.$XINE_MINOR${XINE_SUBPART}$XINE_PRE TAR_NAME="xine-lib-"$SPEC_VERSION dnl TAR_NAME="xine-lib-"$XINE_MAJOR-$XINE_PRE @@ -2399,38 +2402,45 @@ AC_SUBST(xinelibdir) AC_SUBST(xinedatadir) AC_SUBST(pkgconfigdir) -XINE_PLUGINDIR="\${xinelibdir}/plugins/$XINE_MAJOR.$XINE_MINOR.$XINE_SUB$XINE_PATCH" +XINE_PLUGINROOT="\${xinelibdir}/plugins/$(($XINE_LT_CURRENT-$XINE_LT_AGE))" +XINE_PLUGINDIR="$XINE_PLUGINROOT.$XINE_LT_AGE" XINE_FONTDIR="\${xinedatadir}/libxine$XINE_MAJOR/fonts" XINE_LOCALEDIR='${datadir}/locale' -XINE_REL_PLUGINDIR="`makeexpand "$XINE_PLUGINDIR"`" -XINE_REL_PLUGINDIR="`makeexpand "$XINE_REL_PLUGINDIR" | sed -e "s,^${prefix}/,,"`" +XINE_REL_PLUGINROOT="`makeexpand "$XINE_PLUGINROOT"`" +XINE_REL_PLUGINROOT="`makeexpand "$XINE_REL_PLUGINROOT" | sed -e "s,^${prefix}/,,"`" +XINE_REL_PLUGINDIR="$XINE_REL_PLUGINROOT.$XINE_LT_AGE" XINE_REL_FONTDIR="`makeexpand "$XINE_FONTDIR" | sed -e "s,^${prefix}/,,"`" XINE_REL_LOCALEDIR="`makeexpand "$XINE_LOCALEDIR" | sed -e "s,^${prefix}/,,"`" XINE_PKGCONFIG_DIR="`makeexpand "$pkgconfigdir"`" if test "x$SYS" = "xmingw32" -o "x$SYS" = "xcygwin"; then dnl polish paths (MinGW runtime accepts both \ and / anyway) - XINE_REL_PLUGINDIR="`echo "$XINE_REL_PLUGINDIR" | sed -e 's/\\//\\\\\\\\/g'`" + XINE_REL_PLUGINROOT="`echo "$XINE_REL_PLUGINROOT" | sed -e 's/\\//\\\\\\\\/g'`" + XINE_REL_PLUGINDIR="$XINE_REL_PLUGINROOT.$XINE_LT_AGE" XINE_REL_FONTDIR="`echo "$XINE_REL_FONTDIR" | sed -e 's/\\//\\\\\\\\/g'`" XINE_REL_LOCALEDIR="`echo "$XINE_REL_LOCALEDIR" | sed -e 's/\\//\\\\\\\\/g'`" dnl prefix in xine-config XINE_CONFIG_PREFIX="\$(cd \$(dirname \$0)/..; pwd)" dnl installation directories (in xine-config) - XINE_PLUGINPATH="$XINE_CONFIG_PREFIX/$XINE_REL_PLUGINDIR" + XINE_PLUGINROOTPATH="$XINE_CONFIG_PREFIX/$XINE_REL_PLUGINROOT" + XINE_PLUGINPATH="$XINE_PLUGINROOTPATH.$XINE_LT_AGE" XINE_FONTPATH="$XINE_CONFIG_PREFIX/$XINE_REL_FONTDIR" XINE_LOCALEPATH="$XINE_CONFIG_PREFIX/$XINE_REL_LOCALEDIR" dnl runtime directories - AC_DEFINE(XINE_PLUGINDIR,[xine_get_plugindir()],[Define this to plugins directory location]) + AC_DEFINE(XINE_PLUGINROOT,[xine_get_pluginroot()],[Define this to general plugins directory location]) + AC_DEFINE(XINE_PLUGINDIR,[xine_get_plugindir()],[Define this to specific plugins directory location]) AC_DEFINE(XINE_FONTDIR,[xine_get_fontdir()],[Define this to osd fonts dir location]) AC_DEFINE(XINE_LOCALEDIR,[xine_get_localedir()],[Path where catalog files will be.]) else dnl prefix in xine-config XINE_CONFIG_PREFIX="`makeexpand "${prefix}"`" dnl directories from xine-config and runtime directories - XINE_PLUGINPATH="`makeexpand "$XINE_PLUGINDIR"`" + XINE_PLUGINROOTPATH="`makeexpand "$XINE_PLUGINROOT"`" + XINE_PLUGINPATH="$XINE_PLUGINROOTPATH.$XINE_LT_AGE" XINE_FONTPATH="`makeexpand "$XINE_FONTDIR"`" XINE_LOCALEPATH="`makeexpand "$XINE_LOCALEDIR"`" dnl defining runtime directories - AC_DEFINE_UNQUOTED(XINE_PLUGINDIR,"$XINE_PLUGINPATH",[Define this to plugins directory location]) + AC_DEFINE_UNQUOTED(XINE_PLUGINROOT,"$XINE_PLUGINROOTPATH",[Define this to general plugins directory location]) + AC_DEFINE_UNQUOTED(XINE_PLUGINDIR,"$XINE_PLUGINPATH",[Define this to specific plugins directory location]) AC_DEFINE_UNQUOTED(XINE_FONTDIR,"$XINE_FONTPATH",[Define this to osd fonts dir location]) AC_DEFINE_UNQUOTED(XINE_LOCALEDIR, "$XINE_LOCALEPATH",[Path where catalog files will be.]) fi diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index 71cb19d3b..11a74b097 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -1119,14 +1119,24 @@ static void load_cached_catalog (xine_t *this) { } +/* helper function for _x_scan_plugins */ +static void push_if_dir (xine_list_t *plugindirs, void *path) +{ + struct stat st; + if (!stat (path, &st) && S_ISDIR (st.st_mode)) + xine_list_push_back (plugindirs, path); + else + free (path); +} + /* * initialize catalog, load all plugins into new catalog */ void _x_scan_plugins (xine_t *this) { - - char *homedir, *plugindir, *pluginpath; - int i,j; - int lenpluginpath; + + char *homedir, *pluginpath; + xine_list_t *plugindirs = xine_list_new (); + xine_list_iterator_t iter; lprintf("_x_scan_plugins()\n"); @@ -1140,41 +1150,38 @@ void _x_scan_plugins (xine_t *this) { this->plugin_catalog = _new_catalog(); load_cached_catalog (this); - if ((pluginpath = getenv("XINE_PLUGIN_PATH")) != NULL) { - pluginpath = strdup(pluginpath); + if ((pluginpath = getenv("XINE_PLUGIN_PATH")) != NULL && *pluginpath) { + char *p = pluginpath - 1; + while (p[1]) + { + char *dir, *q = p; + p = strchr (p + 1, XINE_PATH_SEPARATOR_CHAR); + if (q[0] == '~' && q[1] == '/') + asprintf (&dir, "%s%.*s", homedir, (int)(p - q - 1), q + 1); + else + dir = strndup (q, p - q); + push_if_dir (plugindirs, dir); /* store or free it */ + } } else { - const char *str1, *str2; - int len; - - str1 = "~/.xine/plugins"; - str2 = XINE_PLUGINDIR; - len = strlen(str1) + strlen(str2) + 2; - pluginpath = xine_xmalloc(len); - snprintf(pluginpath, len, "%s" XINE_PATH_SEPARATOR_STRING "%s", str1, str2); - } - plugindir = xine_xmalloc(strlen(pluginpath)+strlen(homedir)+2); - j=0; - lenpluginpath = strlen(pluginpath); - for (i=0; i <= lenpluginpath; ++i){ - switch (pluginpath[i]){ - case XINE_PATH_SEPARATOR_CHAR: - case '\0': - plugindir[j] = '\0'; - collect_plugins(this, plugindir); - j = 0; - break; - case '~': - if (j == 0){ - strcpy(plugindir, homedir); - j = strlen(plugindir); - break; - } - default: - plugindir[j++] = pluginpath[i]; + char *dir; + int i; + asprintf (&dir, "%s/.xine/plugins", homedir); + push_if_dir (plugindirs, dir); + for (i = 0; i <= XINE_LT_AGE; ++i) + { + asprintf (&dir, "%s.%d", XINE_PLUGINROOT, i); + push_if_dir (plugindirs, dir); } } - free(plugindir); - free(pluginpath); + for (iter = xine_list_front (plugindirs); iter; + iter = xine_list_next (plugindirs, iter)) + { + char *dir = xine_list_get_value (plugindirs, iter); +fprintf (stderr, "%s\n", dir); + collect_plugins(this, dir); + free (dir); + } + xine_list_delete (plugindirs); free(homedir); save_catalog (this); -- cgit v1.2.3 From 167035abe222bad88269d296f9d819365a6c6007 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Thu, 7 Feb 2008 02:03:00 +0000 Subject: Reverse the order in which the plugin dirs are scanned; remove a stray printf. --- src/xine-engine/load_plugins.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/xine-engine/load_plugins.c b/src/xine-engine/load_plugins.c index 11a74b097..0188fb01d 100644 --- a/src/xine-engine/load_plugins.c +++ b/src/xine-engine/load_plugins.c @@ -1169,7 +1169,7 @@ void _x_scan_plugins (xine_t *this) { push_if_dir (plugindirs, dir); for (i = 0; i <= XINE_LT_AGE; ++i) { - asprintf (&dir, "%s.%d", XINE_PLUGINROOT, i); + asprintf (&dir, "%s.%d", XINE_PLUGINROOT, XINE_LT_AGE - i); push_if_dir (plugindirs, dir); } } @@ -1177,7 +1177,6 @@ void _x_scan_plugins (xine_t *this) { iter = xine_list_next (plugindirs, iter)) { char *dir = xine_list_get_value (plugindirs, iter); -fprintf (stderr, "%s\n", dir); collect_plugins(this, dir); free (dir); } -- cgit v1.2.3 From 89c18074b7f0afb74b5abbfc4a444f41c52f2344 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Thu, 7 Feb 2008 17:49:40 +0000 Subject: Keep the plugin dir name to x.y.z - x.y.z.a is inappropriate here. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 9badb9d23..3a7651fb6 100644 --- a/configure.ac +++ b/configure.ac @@ -2399,7 +2399,7 @@ AC_SUBST(xinelibdir) AC_SUBST(xinedatadir) AC_SUBST(pkgconfigdir) -XINE_PLUGINDIR="\${xinelibdir}/plugins/$XINE_MAJOR.$XINE_MINOR.$XINE_SUB$XINE_PATCH" +XINE_PLUGINDIR="\${xinelibdir}/plugins/$XINE_MAJOR.$XINE_MINOR.$XINE_SUB" XINE_FONTDIR="\${xinedatadir}/libxine$XINE_MAJOR/fonts" XINE_LOCALEDIR='${datadir}/locale' XINE_REL_PLUGINDIR="`makeexpand "$XINE_PLUGINDIR"`" -- cgit v1.2.3 From 5c051b721ee7ff79ae655660e9695563a902945c Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Thu, 7 Feb 2008 17:51:59 +0000 Subject: Add length checking in the FLAC metadata-parsing code. Make the tracknumber/tracktotal buffer larger (possible overflow). --- ChangeLog | 4 ++++ src/demuxers/demux_flac.c | 15 +++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index f05ce93eb..4a66c4c45 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ xine-lib (1.1.11) unreleased + * Security fixes: + - Array index vulnerability which may allow remote attackers to execute + arbitrary code via a crafted FLAC tag, causing a stack buffer overflow. + (CVE-2008-0486) * Fix a RealPlayer codec detection bug. xine-lib (1.1.10) 2008-01-26 diff --git a/src/demuxers/demux_flac.c b/src/demuxers/demux_flac.c index 23e2faef9..e5d1297a2 100644 --- a/src/demuxers/demux_flac.c +++ b/src/demuxers/demux_flac.c @@ -189,7 +189,7 @@ static int open_flac_file(demux_flac_t *flac) { case 4: lprintf ("VORBIS_COMMENT metadata\n"); { - char comments[block_length]; + char comments[block_length + 1]; /* last byte for NUL termination */ char *ptr = comments; uint32_t length, user_comment_list_length; int cn; @@ -202,18 +202,25 @@ static int open_flac_file(demux_flac_t *flac) { length = _X_LE_32(ptr); ptr += 4 + length; + if (length >= block_length - 8) + return 0; /* bad length or too little left in the buffer */ user_comment_list_length = _X_LE_32(ptr); ptr += 4; cn = 0; for (; cn < user_comment_list_length; cn++) { + if (ptr > comments + block_length - 4) + return 0; /* too little left in the buffer */ + length = _X_LE_32(ptr); ptr += 4; + if (length >= block_length || ptr + length > comments + block_length) + return 0; /* bad length */ comment = (char*) ptr; c = comment[length]; - comment[length] = 0; + comment[length] = 0; /* NUL termination */ lprintf ("comment[%02d] = %s\n", cn, comment); @@ -248,8 +255,8 @@ static int open_flac_file(demux_flac_t *flac) { } if ((tracknumber > 0) && (tracktotal > 0)) { - char tn[16]; - snprintf (tn, 16, "%02d/%02d", tracknumber, tracktotal); + char tn[24]; + snprintf (tn, 24, "%02d/%02d", tracknumber, tracktotal); _x_meta_info_set(flac->stream, XINE_META_INFO_TRACK_NUMBER, tn); } else if (tracknumber > 0) { -- cgit v1.2.3 From 8c4abd6c7e4dea263e699048137763967858a859 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Thu, 7 Feb 2008 17:54:46 +0000 Subject: Adjust some comments. --- configure.ac | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 3a7651fb6..5b68c369e 100644 --- a/configure.ac +++ b/configure.ac @@ -17,14 +17,14 @@ dnl XINE_MAJOR=1 XINE_MINOR=1 XINE_SUB=10 -# XINE_PATCH should be left empty or set to ".1" or ".2" or something similar +dnl XINE_PATCH should be left empty or set to ".1" or ".2" or something similar XINE_PATCH= -#if test $XINE_SUB -eq 0 ; then -# XINE_SUBPART=""; -#else +dnl if test $XINE_SUB -eq 0 ; then +dnl XINE_SUBPART=""; +dnl else XINE_SUBPART=".$XINE_SUB$XINE_PATCH" -#fi +dnl fi dnl The libtool version numbers (XINE_LT_*); Don't even think about faking this! dnl -- cgit v1.2.3 From a8d2186af1722c00b4cb9b045d96a5b16f29f7e7 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Thu, 7 Feb 2008 17:55:06 +0000 Subject: 1.1.10.1, not 1.1.11. --- ChangeLog | 2 +- configure.ac | 2 +- debian/changelog | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4a66c4c45..5cbde5090 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -xine-lib (1.1.11) unreleased +xine-lib (1.1.10.1) unreleased * Security fixes: - Array index vulnerability which may allow remote attackers to execute arbitrary code via a crafted FLAC tag, causing a stack buffer overflow. diff --git a/configure.ac b/configure.ac index 5b68c369e..6ba204361 100644 --- a/configure.ac +++ b/configure.ac @@ -18,7 +18,7 @@ XINE_MAJOR=1 XINE_MINOR=1 XINE_SUB=10 dnl XINE_PATCH should be left empty or set to ".1" or ".2" or something similar -XINE_PATCH= +XINE_PATCH=.1 dnl if test $XINE_SUB -eq 0 ; then dnl XINE_SUBPART=""; diff --git a/debian/changelog b/debian/changelog index ee28516de..9f2640f7d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -xine-lib (1.1.10+hg-0) unstable; urgency=low +xine-lib (1.1.10.1+hg-0) unstable; urgency=low [ Darren Salt ] * Hg snapshot. @@ -7,7 +7,7 @@ xine-lib (1.1.10+hg-0) unstable; urgency=low * remove gs from build-dependencies * change the maintainer field to xine-devel@lists.sourceforge.net. - -- Darren Salt <linux@youmustbejoking.demon.co.uk> Sun, 27 Jan 2008 01:41:45 +0000 + -- Darren Salt <linux@youmustbejoking.demon.co.uk> Thu, 07 Feb 2008 17:52:34 +0000 xine-lib (1.1.5~cvs-0) unstable; urgency=low -- cgit v1.2.3 From 69bc8833d2108303d7984cab5e1ad5f49dd66085 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern <thibaut.mattern@gmail.com> Date: Thu, 7 Feb 2008 22:36:52 +0100 Subject: Improve detection of MP3 streams with ID3v2 tags. Don't trust the tag size. --- ChangeLog | 2 ++ src/demuxers/demux_mpgaudio.c | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5cbde5090..02634b43d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ xine-lib (1.1.10.1) unreleased arbitrary code via a crafted FLAC tag, causing a stack buffer overflow. (CVE-2008-0486) * Fix a RealPlayer codec detection bug. + * Improve detection of MP3 streams with ID3v2 tags. Don't trust the tag + size. xine-lib (1.1.10) 2008-01-26 * Security fixes: diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c index 1bea02302..82a7dd7ab 100644 --- a/src/demuxers/demux_mpgaudio.c +++ b/src/demuxers/demux_mpgaudio.c @@ -807,7 +807,6 @@ static int demux_mpgaudio_read_head(input_plugin_t *input, uint8_t *buf) { * return 1 if detected, 0 otherwise */ static int detect_mpgaudio_file(input_plugin_t *input) { - mpg_audio_frame_t frame; uint8_t buf[MAX_PREVIEW_SIZE]; int preview_len; uint32_t head; @@ -838,8 +837,8 @@ static int detect_mpgaudio_file(input_plugin_t *input) { lprintf("cannot read mp3 frame header\n"); return 0; } - if (!parse_frame_header(&frame, &buf[10 + tag_size])) { - lprintf ("invalid mp3 frame header\n"); + if (!sniff_buffer_looks_like_mp3(&buf[10 + tag_size], preview_len - 10 - tag_size)) { + lprintf ("sniff_buffer_looks_like_mp3 failed\n"); return 0; } else { lprintf ("a valid mp3 frame follows the id3v2 tag\n"); -- cgit v1.2.3 From 27a3e33f4ce17a5e082e983258818e02606be58c Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Thu, 7 Feb 2008 23:10:15 +0000 Subject: Add release date. --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 02634b43d..c9161619d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -xine-lib (1.1.10.1) unreleased +xine-lib (1.1.10.1) 2008-02-07 * Security fixes: - Array index vulnerability which may allow remote attackers to execute arbitrary code via a crafted FLAC tag, causing a stack buffer overflow. -- cgit v1.2.3 From 18d851ea42a33a78d2e9b3687311ee5e3ea228af Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Thu, 7 Feb 2008 23:10:19 +0000 Subject: 1.1.10.1 --- .hgtags | 1 + 1 file changed, 1 insertion(+) diff --git a/.hgtags b/.hgtags index 6e05d9638..51885c59d 100644 --- a/.hgtags +++ b/.hgtags @@ -65,3 +65,4 @@ e0a332b9d3e8bb3fad4d7feac1e519292b062056 xine-lib-1_1_8-release b6be674453e922114b55d4613cb197c77d19f094 xine-lib-1_1_9-release 9438947f88ad2bed1832385301c6b4e62709625a xine-lib-1_1_9_1-release 7f1232425c6d715c404e6df1292075b33ecb8305 xine-lib-1_1_10-release +0e9e4df266f639ac7ba9e0c204f205686b56d5f9 xine-lib-1_1_10_1-release -- cgit v1.2.3 From 1675d0eec5d8c10b82a7b1e6a882e8950b7abd75 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Fri, 8 Feb 2008 22:16:45 +0000 Subject: Add automake conditionals ARCH_X86_32 and ARCH_X86_64. --- configure.ac | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 45f262159..8099051c4 100644 --- a/configure.ac +++ b/configure.ac @@ -2212,7 +2212,7 @@ case "$host_or_hostalias" in dnl AC_DEFINE_UNQUOTED(ARCH_X86_32,,[Define this if you're running x86 architecture 32 bits]) AC_DEFINE(FPM_INTEL,1,[Define to select libmad fixed point arithmetic implementation]) - arch_x86="yes" + arch_x86="32" enable_impure_text="yes" case "$host_or_hostalias" in @@ -2224,7 +2224,7 @@ case "$host_or_hostalias" in x86_64-*) AC_DEFINE_UNQUOTED(ARCH_X86_64,,[Define this if you're running x86 architecture 64 bits]) AC_DEFINE(FPM_64BIT,1,[Define to select libmad fixed point arithmetic implementation]) - arch_x86="yes" + arch_x86="64" ;; powerpc-*-darwin*) dnl avoid ppc compilation crash @@ -2303,11 +2303,13 @@ if test "x$has_vis" = "xyes"; then fi AM_CONDITIONAL(ENABLE_VIS, test "x$has_vis" = "xyes") -if test "x$arch_x86" = "xyes"; then +if test "x$arch_x86" != "xno"; then AC_DEFINE_UNQUOTED(ARCH_X86,,[Define this if you're running x86 architecture]) AC_DEFINE_UNQUOTED(HAVE_MMX,,[Define this if you can compile MMX asm instructions]) fi -AM_CONDITIONAL(ARCH_X86, test "x$arch_x86" = "xyes") +AM_CONDITIONAL(ARCH_X86, test "x$arch_x86" != "xno") +AM_CONDITIONAL(ARCH_X86_32, test "x$arch_x86" = "x32") +AM_CONDITIONAL(ARCH_X86_64, test "x$arch_x86" = "x64") AM_CONDITIONAL(HAVE_MMX, test "x$arch_x86" = "xyes") case $host_os in -- cgit v1.2.3 From 91906eeb746d96a39560471e92431a0c6632c70a Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Fri, 8 Feb 2008 22:20:47 +0000 Subject: Avoid a build failure (affects gcc 4.0 on x86_32). --- src/post/deinterlace/plugins/Makefile.am | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/post/deinterlace/plugins/Makefile.am b/src/post/deinterlace/plugins/Makefile.am index 17d170127..2bc8abd58 100644 --- a/src/post/deinterlace/plugins/Makefile.am +++ b/src/post/deinterlace/plugins/Makefile.am @@ -32,6 +32,9 @@ EXTRA_DIST = greedy2frame_template.c greedyh.asm \ AM_CFLAGS = -I$(top_srcdir)/src/post/deinterlace \ -I$(top_srcdir)/src/libffmpeg/libavcodec/libpostproc +# Avoid "can't find register" failures with -O0, -O2, -O3 (gcc 4.0) +libdeinterlaceplugins_la-kdetv_greedyh.o libdeinterlaceplugins_la-kdetv_greedyh.lo: CFLAGS=$(shell echo @CFLAGS@ | sed -e 's/$$/ -O1/') + noinst_LTLIBRARIES = libdeinterlaceplugins.la libdeinterlaceplugins_la_SOURCES = \ -- cgit v1.2.3 From 34af4adde1c65495fa8948c482ef83bd73204d89 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 9 Feb 2008 16:51:19 +0000 Subject: Remove some unnecessary tests (which the compiler would discard). --- src/xine-utils/utils.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c index c5f18a699..cc3ffdc2c 100644 --- a/src/xine-utils/utils.c +++ b/src/xine-utils/utils.c @@ -324,22 +324,18 @@ const char *xine_get_homedir(void) { char *s; int len; - if (!homedir[0]) { - len = xine_strcpy_command(GetCommandLine(), homedir, sizeof(homedir)); - s = strdup(homedir); - GetFullPathName(s, sizeof(homedir), homedir, NULL); - free(s); - if ((s = strrchr(homedir, '\\'))) *s = '\0'; - } + len = xine_strcpy_command(GetCommandLine(), homedir, sizeof(homedir)); + s = strdup(homedir); + GetFullPathName(s, sizeof(homedir), homedir, NULL); + free(s); + if ((s = strrchr(homedir, '\\'))) + *s = '\0'; return homedir; #else struct passwd pwd, *pw = NULL; static char homedir[BUFSIZ] = {0,}; - if(homedir[0]) - return homedir; - #ifdef HAVE_GETPWUID_R if(getpwuid_r(getuid(), &pwd, homedir, sizeof(homedir), &pw) != 0 || pw == NULL) { #else -- cgit v1.2.3 From dae0b9aa3ace07691519827151cffe667602d341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= <ville.skytta@iki.fi> Date: Sat, 9 Feb 2008 16:54:22 +0000 Subject: Make xine-config --version parsing more robust I think there's quite a bit more room for improvement in the sed expression: 1) The expression is not bound to start/end of line, and will thus pass possible leading/trailing garbage through. 2) It uses plain "." (== any character as far as sed is concerned) where it appears to search for the literal ".". 3) The whole "xine-config --version" output is assigned to all xine_config_*_version vars if there's no match. I think more intuitive would be them to be empty if parsing fails. 4) It uses * (0 or more) for matching digit sequences, where I think + (1 or more) would be desirable. This patch should fix issues 1 to 3. I suppose for 4) it would additionally take only replacing the first three "*" with "\+" but IIRC there are some portability issues related to "+" between different sed versions. --- m4/xine.m4 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/m4/xine.m4 b/m4/xine.m4 index cb64bad1a..2842de621 100644 --- a/m4/xine.m4 +++ b/m4/xine.m4 @@ -69,11 +69,11 @@ AC_ARG_ENABLE(xinetest, XINE_LIBS=`$XINE_CONFIG $xine_config_args --libs` XINE_ACFLAGS=`$XINE_CONFIG $xine_config_args --acflags` xine_config_major_version=`$XINE_CONFIG $xine_config_args --version | \ - sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` + sed -n 's/^\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*$/\1/p'` xine_config_minor_version=`$XINE_CONFIG $xine_config_args --version | \ - sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` + sed -n 's/^\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*$/\2/p'` xine_config_sub_version=`$XINE_CONFIG $xine_config_args --version | \ - sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` + sed -n 's/^\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*$/\3/p'` xine_data_dir=`$XINE_CONFIG $xine_config_args --datadir` xine_script_dir=`$XINE_CONFIG $xine_config_args --scriptdir` xine_plugin_dir=`$XINE_CONFIG $xine_config_args --plugindir` -- cgit v1.2.3 From 25a1e6cb1385e77a885fd7d1b8ed1da1ca06e4ca Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 9 Feb 2008 17:04:51 +0000 Subject: Changelog entry for the version-parsing fix. --- ChangeLog | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ChangeLog b/ChangeLog index 6cab98cc8..e0f73c3c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ xine-lib (1.1.11) unreleased plugin directory name is 1.19, and if this gets bumped to 1.20 in a future release, 1.19 will still be available for external plugins. (Any directories not 1.* won't be looked in.) + * Made the version parsing much more reliable; it wasn't properly coping + with four-part version numbers. This affects any program whose build + scripts use xine-lib's automake macros. xine-lib (1.1.10.1) 2008-02-07 * Security fixes: -- cgit v1.2.3 From c577d6a8073f9da8c528cce239b601e0e1366d65 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 9 Feb 2008 17:17:23 +0000 Subject: Fix a configure test which was left out of the arch_x86 changes. (Affects MMX.) --- ChangeLog | 1 + configure.ac | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e0f73c3c2..b5a41af89 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ xine-lib (1.1.11) unreleased * Made the version parsing much more reliable; it wasn't properly coping with four-part version numbers. This affects any program whose build scripts use xine-lib's automake macros. + * Whoops, broke MMX on x86 in 1.1.10.1. xine-lib (1.1.10.1) 2008-02-07 * Security fixes: diff --git a/configure.ac b/configure.ac index 8099051c4..0d51130b9 100644 --- a/configure.ac +++ b/configure.ac @@ -2310,7 +2310,7 @@ fi AM_CONDITIONAL(ARCH_X86, test "x$arch_x86" != "xno") AM_CONDITIONAL(ARCH_X86_32, test "x$arch_x86" = "x32") AM_CONDITIONAL(ARCH_X86_64, test "x$arch_x86" = "x64") -AM_CONDITIONAL(HAVE_MMX, test "x$arch_x86" = "xyes") +AM_CONDITIONAL(HAVE_MMX, test "x$arch_x86" != "xno") case $host_os in darwin*) -- cgit v1.2.3 From f0aef0a460f5fb86021e6ef13f391c9c15060302 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Sat, 9 Feb 2008 18:09:28 +0000 Subject: That last changelog entry is lying. Delete it. --- ChangeLog | 1 - 1 file changed, 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b5a41af89..e0f73c3c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,7 +8,6 @@ xine-lib (1.1.11) unreleased * Made the version parsing much more reliable; it wasn't properly coping with four-part version numbers. This affects any program whose build scripts use xine-lib's automake macros. - * Whoops, broke MMX on x86 in 1.1.10.1. xine-lib (1.1.10.1) 2008-02-07 * Security fixes: -- cgit v1.2.3 From b1c04841c72f050189af140c396729a316aedc4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 10 Feb 2008 15:39:37 +0100 Subject: Fix summary output for external libdts. --- m4/summary.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/m4/summary.m4 b/m4/summary.m4 index 9661f072b..4a8f6db07 100644 --- a/m4/summary.m4 +++ b/m4/summary.m4 @@ -120,7 +120,7 @@ AC_DEFUN([XINE_LIB_SUMMARY], [ fi fi if test x"$enable_libdts" != x"no"; then - if test x"$have_external_libdts" = x"yes"; then + if test x"$have_external_dts" = x"yes"; then echo " - DTS (external library)" else echo " - DTS (internal library)" -- cgit v1.2.3 From 30ed4f400f979adade61ca362377502464bee47a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sun, 10 Feb 2008 15:40:08 +0100 Subject: Remove --with-external-libfoo for options that have --enable-foo, and replace those with --enable-foo=external. --- m4/decoders.m4 | 40 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/m4/decoders.m4 b/m4/decoders.m4 index 42f76b1a3..9dfe20148 100644 --- a/m4/decoders.m4 +++ b/m4/decoders.m4 @@ -4,13 +4,9 @@ dnl --------------------------- AC_DEFUN([XINE_DECODER_PLUGINS], [ dnl a52dec (optional; enabled by default; external version allowed) AC_ARG_ENABLE([a52dec], - [AS_HELP_STRING([--enable-a52dec], [Enable support for a52dec decoding library (default: enabled)])], - [test x"$enableval" != x"no" && enable_a52dec="yes"]) - AC_ARG_WITH([external-a52dec], - [AS_HELP_STRING([--with-external-a52dec], [Use external a52dec library (not recommended)])], - [test x"$withval" != x"no" && with_external_a52dec="yes"], [with_external_a52dec="no"]) + [AS_HELP_STRING([--enable-a52dec], [Enable support for a52dec decoding library (default: enabled, external: use external copy)])]) if test x"$enable_a52dec" != x"no"; then - if test x"$with_external_a52dec" != x"no"; then + if test x"$enable_a52dec" == x"external"; then AC_CHECK_LIB([a52], [a52_init], [AC_CHECK_HEADERS([a52dec/a52.h a52dec/a52_internal.h], [have_external_a52dec=yes], [have_external_a52dec=no], [#ifdef HAVE_SYS_TYPES_H @@ -60,13 +56,9 @@ AC_DEFUN([XINE_DECODER_PLUGINS], [ dnl FAAD (optional; enabled by default) AC_ARG_ENABLE([faad], - [AS_HELP_STRING([--enable-faad], [Enable support for FAAD decoder (default: enabled)])], - [test x"$enableval" != x"no" && enable_faad="yes"]) - AC_ARG_WITH([external-faad], - [AS_HELP_STRING([--with-external-faad], [Use external FAAD decoeder])], - [test x"$withval" != x"no" && with_external_faad="yes"], [with_external_faad="no"]) + [AS_HELP_STRING([--enable-faad], [Enable support for FAAD decoder (default: enabled, external: use external copy)])]) if test x"$enable_faad" != x"no"; then - if test x"$with_external_faad" != x"no"; then + if test x"$enable_faad" == x"external"; then AC_CHECK_LIB([faad], [NeAACDecInit], [AC_CHECK_HEADERS([neaacdec.h], [have_external_faad=yes], [have_external_faad=no], [#include <neaacdec.h>])], [have_external_faad=no], [-lm]) @@ -159,13 +151,9 @@ use internal ffmpeg. dnl libdts (optional; enabled by default; external version allowed) AC_ARG_ENABLE([dts], - [AS_HELP_STRING([--enable-dts], [Enable support for DTS decoding library (default: enabled)])], - [test x"$enableval" != x"no" && enable_dts="yes"]) - AC_ARG_WITH([external-libdts], - [AS_HELP_STRING([--with-external-libdts], [Use external libdts/libdca library (not recommended)])], - [test x"$withval" != x"no" && with_external_libdts="yes"], [with_external_libdts="no"]) + [AS_HELP_STRING([--enable-dts], [Enable support for DTS decoding library (default: enabled, external: use external copy)])]) if test x"$enable_dts" != x"no"; then - if test x"$with_external_libdts" != x"no"; then + if test x"$enable_dts" == x"external"; then PKG_CHECK_MODULES([LIBDTS], [libdts], [have_external_dts=yes], [have_external_dts=no]) if test x"$have_external_dts" != x"yes"; then AC_MSG_RESULT([*** no usable version of libdts found, using internal copy ***]) @@ -254,13 +242,9 @@ use internal ffmpeg. dnl libmad (optional; enabled by default; external version allowed) AC_ARG_ENABLE([mad], - [AS_HELP_STRING([--enable-mad], [Enable support for MAD decoding library (default: enabled)])], - [test x"$enableval" != x"no" && enable_mad="yes"]) - AC_ARG_WITH([external-libmad], - [AS_HELP_STRING([--with-external-libmad], [use external libmad library (not recommended)])], - [test x"$withval" != x"no" && with_external_libmad="yes"], [with_external_libmad="no"]) + [AS_HELP_STRING([--enable-mad], [Enable support for MAD decoding library (default: enabled, external: use external copy)])]) if test x"$enable_mad" != x"no"; then - if test x"$with_external_libmad" != x"no"; then + if test x"$enable_mad" == x"external"; then PKG_CHECK_MODULES([LIBMAD], [mad], [AC_CHECK_HEADERS([mad.h], [have_external_libmad=yes], [have_external_libmad=no])], [have_external_libmad=no]) @@ -332,13 +316,9 @@ use internal ffmpeg. dnl libmpcdec (optional; enabled by default; external version allowed) AC_ARG_ENABLE([musepack], - [AS_HELP_STRING([--enable-musepack], [Enable support for Musepack decoding (default: enabled)])], - [test x"$enableval" != x"no" && enable_musepack="yes"]) - AC_ARG_WITH([external-libmpcdec], - [AS_HELP_STRING([--with-external-libmpcdec], [Use external libmpc library])], - [test x"$withval" != x"no" && with_external_libmpcdec="yes"], [with_external_libmpcdec="no"]) + [AS_HELP_STRING([--enable-musepack], [Enable support for Musepack decoding (default: enabled, external: use external copy)])]) if test x"$enable_musepack" != x"no"; then - if test x"$with_external_libmpcdec" != x"no"; then + if test x"$enable_musepack" == x"external"; then AC_CHECK_LIB([mpcdec], [mpc_decoder_decode], [AC_CHECK_HEADERS([mpcdec/mpcdec.h], [have_external_libmpcdec=yes], [have_external_libmpcdec=no])], [have_external_libmpcdec=no]) -- cgit v1.2.3 From cbbfd6efbf8b632fc039eb1fce729258b5ac3bdb Mon Sep 17 00:00:00 2001 From: Carlo Bramini <carlo_bramini@users.sourceforge.net> Date: Mon, 11 Feb 2008 16:38:48 +0000 Subject: Fix to timegm.c timegm.c uses tzset(), but if host does not provide it, compilation or linking will fail. I fixed it by checking the status of HAVE_TZSET. If the function is not detected at configure time, it won't be used, like it has been done in other parts of xine-lib. --- lib/timegm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/timegm.c b/lib/timegm.c index 588131afb..e86e66370 100644 --- a/lib/timegm.c +++ b/lib/timegm.c @@ -5,15 +5,19 @@ time_t xine_private_timegm(struct tm *tm) { time_t ret; +#if defined(HAVE_TZSET) char *tz; tz = getenv("TZ"); setenv("TZ", "", 1); tzset(); +#endif ret = mktime(tm); +#if defined(HAVE_TZSET) if (tz) setenv("TZ", tz, 1); else unsetenv("TZ"); tzset(); +#endif return ret; } -- cgit v1.2.3 From c280370fa3ef304b9adc9d3cf36c9aeec27034e4 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Mon, 11 Feb 2008 16:42:28 +0000 Subject: Actually check for tzset. --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 0d51130b9..90a5f1b80 100644 --- a/configure.ac +++ b/configure.ac @@ -2117,7 +2117,7 @@ dnl --------------------------------------------- AC_SYS_LARGEFILE AC_CHECK_LIB(posix4, sched_get_priority_min) -AC_CHECK_FUNCS([vsscanf sigaction sigset getpwuid_r nanosleep lstat memset readlink strchr va_copy]) +AC_CHECK_FUNCS([vsscanf sigaction sigset getpwuid_r nanosleep lstat memset readlink strchr tzset va_copy]) AC_CHECK_FUNCS([snprintf _snprintf], [some_snprintf="yes"; break]) AC_CHECK_FUNCS([vsnprintf _vsnprintf], [some_vsnprintf="yes"; break]) AC_CHECK_FUNCS([strcasecmp _stricmp], [some_strcasecmp="yes"; break]) -- cgit v1.2.3 From 82525c0275a04d84d2d577a5d7411d3e55eea8c6 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern <thibaut.mattern@gmail.com> Date: Thu, 14 Feb 2008 21:16:43 +0100 Subject: Fixed mp3 sniff code. Fixed bug 4 sample playback (nilbymouthclapton.112.mp3). --- src/demuxers/demux_mpgaudio.c | 59 +++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c index dd6c62015..dfb905520 100644 --- a/src/demuxers/demux_mpgaudio.c +++ b/src/demuxers/demux_mpgaudio.c @@ -626,11 +626,12 @@ static int parse_frame_payload(demux_mpgaudio_t *this, * 32-bit MP3 frame header. * return 1 if found, 0 if not found */ -static int sniff_buffer_looks_like_mp3 (uint8_t *buf, int buflen) +static int sniff_buffer_looks_like_mp3 (uint8_t *buf, int buflen, int *version, int *layer) { int offset; mpg_audio_frame_t frame; + *version = *layer = 0; if (buf == NULL) return 0; @@ -639,20 +640,21 @@ static int sniff_buffer_looks_like_mp3 (uint8_t *buf, int buflen) if (parse_frame_header(&frame, buf + offset)) { size_t size = frame.size; - /* Since one frame is available, is there another frame - * just to be sure this is more likely to be a real MP3 - * buffer? */ - offset += size; - - if (offset + 4 >= buflen) { - return 0; - } + if (size > 0) { + /* Since one frame is available, is there another frame + * just to be sure this is more likely to be a real MP3 + * buffer? */ + if (offset + size + 4 >= buflen) { + return 0; + } - if (parse_frame_header(&frame, buf + offset)) { - lprintf("mpeg audio frame detected\n"); - return 1; + if (parse_frame_header(&frame, buf + offset + size)) { + *version = frame.version_idx + 1; + *layer = frame.layer; + lprintf("frame detected, mpeg %d layer %d\n", *version, *layer); + return 1; + } } - break; } } return 0; @@ -806,11 +808,13 @@ static int demux_mpgaudio_read_head(input_plugin_t *input, uint8_t *buf) { * mp3 stream detection * return 1 if detected, 0 otherwise */ -static int detect_mpgaudio_file(input_plugin_t *input) { +static int detect_mpgaudio_file(input_plugin_t *input, + int *version, int *layer) { uint8_t buf[MAX_PREVIEW_SIZE]; int preview_len; uint32_t head; + *version = *layer = 0; preview_len = demux_mpgaudio_read_head(input, buf); if (preview_len < 4) return 0; @@ -834,7 +838,7 @@ static int detect_mpgaudio_file(input_plugin_t *input) { lprintf("cannot read mp3 frame header\n"); return 0; } - if (!sniff_buffer_looks_like_mp3(&buf[10 + tag_size], preview_len - 10 - tag_size)) { + if (!sniff_buffer_looks_like_mp3(&buf[10 + tag_size], preview_len - 10 - tag_size, version, layer)) { lprintf ("sniff_buffer_looks_like_mp3 failed\n"); return 0; } else { @@ -842,7 +846,7 @@ static int detect_mpgaudio_file(input_plugin_t *input) { } } else if (head == MPEG_MARKER) { return 0; - } else if (!sniff_buffer_looks_like_mp3(buf, preview_len)) { + } else if (!sniff_buffer_looks_like_mp3(buf, preview_len, version, layer)) { lprintf ("sniff_buffer_looks_like_mp3 failed\n"); return 0; } @@ -1104,13 +1108,15 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str input_plugin_t *input) { demux_mpgaudio_t *this; + int version = 0; + int layer = 0; lprintf("trying to open %s...\n", input->get_mrl(input)); switch (stream->content_detection_method) { case METHOD_BY_CONTENT: { - if (!detect_mpgaudio_file(input)) + if (!detect_mpgaudio_file(input, &version, &layer)) return NULL; } break; @@ -1122,7 +1128,7 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str default: return NULL; } - + this = xine_xmalloc (sizeof (demux_mpgaudio_t)); this->demux_plugin.send_headers = demux_mpgaudio_send_headers; @@ -1134,12 +1140,17 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str this->demux_plugin.get_capabilities = demux_mpgaudio_get_capabilities; this->demux_plugin.get_optional_data = demux_mpgaudio_get_optional_data; this->demux_plugin.demux_class = class_gen; - - this->input = input; - this->audio_fifo = stream->audio_fifo; - this->status = DEMUX_FINISHED; - this->stream = stream; - + + this->input = input; + this->audio_fifo = stream->audio_fifo; + this->status = DEMUX_FINISHED; + this->stream = stream; + + this->mpg_version = version; + this->mpg_layer = layer; + if (version || layer) { + this->valid_frames = NUM_VALID_FRAMES; + } return &this->demux_plugin; } -- cgit v1.2.3 From a53d75fb7fd3bbe4bc619658fe9ed7ed1b4f2879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Fri, 15 Feb 2008 13:21:09 +0100 Subject: Don't unlock unconditionally the mainloop on failure. --- src/audio_out/audio_pulse_out.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/audio_out/audio_pulse_out.c b/src/audio_out/audio_pulse_out.c index 26d121bf6..2811bbdbc 100644 --- a/src/audio_out/audio_pulse_out.c +++ b/src/audio_out/audio_pulse_out.c @@ -246,7 +246,7 @@ static int ao_pulse_open(ao_driver_t *this_gen, pa_threaded_mainloop_lock(this->pa_class->mainloop); ret = pa_context_connect(this->pa_class->context, this->host, 1, NULL); if ( ret < 0 ) - goto fail; + goto fail_unlock; pa_context_set_state_callback(this->pa_class->context, __xine_pa_context_status_callback, this); @@ -289,8 +289,9 @@ static int ao_pulse_open(ao_driver_t *this_gen, return this->sample_rate; -fail: + fail_unlock: pa_threaded_mainloop_unlock(this->pa_class->mainloop); + fail: this_gen->close(this_gen); return 0; } -- cgit v1.2.3 From ac63f46f26fa2bc9a0be9feacae52d55249685be Mon Sep 17 00:00:00 2001 From: Thibaut Mattern <thibaut.mattern@gmail.com> Date: Fri, 15 Feb 2008 09:33:51 +0100 Subject: Fixed endianess problem. This should allow big ID3v2 tag to be parsed (i mean tags with embedded pictures). (transplanted from ebb0d5507d3208f8e73af78f912230719d37830a) --HG-- extra : transplant_source : %EB%B0%D5P%7D2%08%F8%E7%3A%F7%8F%91%220q%9D7%83%0A --- src/demuxers/demux_mpgaudio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c index 56759dd4b..648f04410 100644 --- a/src/demuxers/demux_mpgaudio.c +++ b/src/demuxers/demux_mpgaudio.c @@ -725,8 +725,8 @@ static int demux_mpgaudio_next (demux_mpgaudio_t *this, int decoder_flags, int s /* the stream is broken, don't keep info about previous frames */ this->free_bitrate_size = 0; - if ( id3v2_istag(header) ) { - if (!id3v2_parse_tag(this->input, this->stream, header)) { + if ( id3v2_istag(_X_ME_32(header)) ) { + if (!id3v2_parse_tag(this->input, this->stream, _X_ME_32(header))) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, LOG_MODULE ": ID3V2 tag parsing error\n"); bytes = 1; /* resync */ -- cgit v1.2.3 From 977484032ff46573c8d3bf39de73cff4304b7a80 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern <thibaut.mattern@gmail.com> Date: Fri, 15 Feb 2008 09:33:51 +0100 Subject: Fixed endianess problem. This should allow big ID3v2 tag to be parsed (i mean tags with embedded pictures). --- src/demuxers/demux_mpgaudio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c index dfb905520..6eb4ee622 100644 --- a/src/demuxers/demux_mpgaudio.c +++ b/src/demuxers/demux_mpgaudio.c @@ -725,8 +725,8 @@ static int demux_mpgaudio_next (demux_mpgaudio_t *this, int decoder_flags, int s /* the stream is broken, don't keep info about previous frames */ this->free_bitrate_size = 0; - if ( id3v2_istag(header) ) { - if (!id3v2_parse_tag(this->input, this->stream, header)) { + if ( id3v2_istag(_X_ME_32(header)) ) { + if (!id3v2_parse_tag(this->input, this->stream, _X_ME_32(header))) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, LOG_MODULE ": ID3V2 tag parsing error\n"); bytes = 1; /* resync */ -- cgit v1.2.3 From b69b862d5d47f3c17cee1dbbbe4743d51bbc9d3c Mon Sep 17 00:00:00 2001 From: Thibaut Mattern <thibaut.mattern@gmail.com> Date: Sat, 16 Feb 2008 00:12:08 +0100 Subject: Take in account the size of the extended header. --HG-- extra : transplant_source : %C0%D71D1%8CQ%889P%21%20%D7%F7%B5%F2T%FE%88%FA --- src/demuxers/id3.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/demuxers/id3.c b/src/demuxers/id3.c index cd72646ef..85b42efa8 100644 --- a/src/demuxers/id3.c +++ b/src/demuxers/id3.c @@ -559,6 +559,7 @@ int id3v23_parse_tag(input_plugin_t *input, if (!id3v23_parse_frame_ext_header(input, &tag_frame_ext_header)) { return 0; } + pos += tag_frame_ext_header.size; } /* frame parsing */ while ((pos + ID3V23_FRAME_HEADER_SIZE) <= tag_header.size) { @@ -579,7 +580,8 @@ int id3v23_parse_tag(input_plugin_t *input, pos += tag_frame_header.size; } else { /* end of frames, the rest is padding */ - input->seek (input, tag_header.size - pos, SEEK_CUR); + lprintf("skipping padding %d bytes\n", tag_header.size - pos); + input->seek (input, tag_header.size - pos, SEEK_CUR); return 1; } } else { @@ -809,6 +811,7 @@ int id3v24_parse_tag(input_plugin_t *input, if (!id3v24_parse_ext_header(input, &tag_frame_ext_header)) { return 0; } + pos += tag_frame_ext_header.size; } /* frame parsing */ while ((pos + ID3V24_FRAME_HEADER_SIZE) <= tag_header.size) { -- cgit v1.2.3 From a03ad73663dc3342f3f6d2a084b55cb05229054d Mon Sep 17 00:00:00 2001 From: Miguel Freitas <miguelfreitas@users.sourceforge.net> Date: Sun, 17 Feb 2008 19:18:35 -0300 Subject: nvidia driver uses XV_SYNC_TO_VBLANK attribute, not XV_DOUBLE_BUFFER as xine expected. add code to set this attribute from xine and mention nvidia-settings, since the user may need to select a sync device as well. --- src/video_out/video_out_xcbxv.c | 33 +++++++++++++++++++++++++++++++++ src/video_out/video_out_xv.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/video_out/video_out_xcbxv.c b/src/video_out/video_out_xcbxv.c index 18ab5c6fb..f83512bd0 100644 --- a/src/video_out/video_out_xcbxv.c +++ b/src/video_out/video_out_xcbxv.c @@ -1247,6 +1247,27 @@ static void xv_update_XV_DOUBLE_BUFFER(void *this_gen, xine_cfg_entry_t *entry) "video_out_xcbxv: double buffering mode = %d\n", xv_double_buffer); } +static void xv_update_XV_SYNC_TO_VBLANK(void *this_gen, xine_cfg_entry_t *entry) { + xv_driver_t *this = (xv_driver_t *) this_gen; + int xv_sync_to_vblank; + + xcb_intern_atom_cookie_t atom_cookie; + xcb_intern_atom_reply_t *atom_reply; + + xv_sync_to_vblank = entry->num_value; + + pthread_mutex_lock(&this->main_mutex); + atom_cookie = xcb_intern_atom(this->connection, 0, sizeof("XV_SYNC_TO_VBLANK"), "XV_SYNC_TO_VBLANK"); + atom_reply = xcb_intern_atom_reply(this->connection, atom_cookie, NULL); + xcb_xv_set_port_attribute(this->connection, this->xv_port, atom_reply->atom, xv_sync_to_vblank); + free(atom_reply); + pthread_mutex_unlock(&this->main_mutex); + + xprintf(this->xine, XINE_VERBOSITY_DEBUG, + "video_out_xcbxv: sync to vblank = %d\n", xv_sync_to_vblank); +} + + static void xv_update_xv_pitch_alignment(void *this_gen, xine_cfg_entry_t *entry) { xv_driver_t *this = (xv_driver_t *) this_gen; @@ -1480,6 +1501,18 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis "flickering and tearing artifacts, but will use more graphics memory."), 20, xv_update_XV_DOUBLE_BUFFER, this); config->update_num(config,"video.device.xv_double_buffer",xv_double_buffer); + } else if(!strcmp(xcb_xv_attribute_info_name(attribute_it.data), "XV_SYNC_TO_VBLANK")) { + int xv_sync_to_vblank; + xv_sync_to_vblank = + config->register_bool (config, "video.device.xv_sync_to_vblank", 1, + _("enable vblank sync"), + _("This option will synchronize the update of the video image to the " + "repainting of the entire screen (\"vertical retrace\"). This eliminates " + "flickering and tearing artifacts. On nvidia cards one may also " + "need to run \"nvidia-settings\" and choose which display device to " + "sync to under the XVideo Settings tab"), + 20, xv_update_XV_SYNC_TO_VBLANK, this); + config->update_num(config,"video.device.xv_sync_to_vblank",xv_sync_to_vblank); } } } diff --git a/src/video_out/video_out_xv.c b/src/video_out/video_out_xv.c index 3bb0a93dc..f6bd1a429 100644 --- a/src/video_out/video_out_xv.c +++ b/src/video_out/video_out_xv.c @@ -1299,6 +1299,22 @@ static void xv_update_XV_DOUBLE_BUFFER(void *this_gen, xine_cfg_entry_t *entry) "video_out_xv: double buffering mode = %d\n", xv_double_buffer); } +static void xv_update_XV_SYNC_TO_VBLANK(void *this_gen, xine_cfg_entry_t *entry) { + xv_driver_t *this = (xv_driver_t *) this_gen; + Atom atom; + int xv_sync_to_vblank; + + xv_sync_to_vblank = entry->num_value; + + LOCK_DISPLAY(this); + atom = XInternAtom (this->display, "XV_SYNC_TO_VBLANK", False); + XvSetPortAttribute (this->display, this->xv_port, atom, xv_sync_to_vblank); + UNLOCK_DISPLAY(this); + + xprintf(this->xine, XINE_VERBOSITY_DEBUG, + "video_out_xv: sync to vblank = %d\n", xv_sync_to_vblank); +} + static void xv_update_xv_pitch_alignment(void *this_gen, xine_cfg_entry_t *entry) { xv_driver_t *this = (xv_driver_t *) this_gen; @@ -1538,6 +1554,18 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void * "flickering and tearing artifacts, but will use more graphics memory."), 20, xv_update_XV_DOUBLE_BUFFER, this); config->update_num(config,"video.device.xv_double_buffer",xv_double_buffer); + } else if(!strcmp(attr[k].name, "XV_SYNC_TO_VBLANK")) { + int xv_sync_to_vblank; + xv_sync_to_vblank = + config->register_bool (config, "video.device.xv_sync_to_vblank", 1, + _("enable vblank sync"), + _("This option will synchronize the update of the video image to the " + "repainting of the entire screen (\"vertical retrace\"). This eliminates " + "flickering and tearing artifacts. On nvidia cards one may also " + "need to run \"nvidia-settings\" and choose which display device to " + "sync to under the XVideo Settings tab"), + 20, xv_update_XV_SYNC_TO_VBLANK, this); + config->update_num(config,"video.device.xv_sync_to_vblank",xv_sync_to_vblank); } } } -- cgit v1.2.3 From 0ac9aca92944c9a3243dabace9a928916010dd55 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern <thibaut.mattern@gmail.com> Date: Mon, 18 Feb 2008 22:01:32 +0100 Subject: Backed out changeset 698d30889b29 id3v2_istag has not the same signature in 1.1 and 1.2. --- src/demuxers/demux_mpgaudio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/demuxers/demux_mpgaudio.c b/src/demuxers/demux_mpgaudio.c index 648f04410..56759dd4b 100644 --- a/src/demuxers/demux_mpgaudio.c +++ b/src/demuxers/demux_mpgaudio.c @@ -725,8 +725,8 @@ static int demux_mpgaudio_next (demux_mpgaudio_t *this, int decoder_flags, int s /* the stream is broken, don't keep info about previous frames */ this->free_bitrate_size = 0; - if ( id3v2_istag(_X_ME_32(header)) ) { - if (!id3v2_parse_tag(this->input, this->stream, _X_ME_32(header))) { + if ( id3v2_istag(header) ) { + if (!id3v2_parse_tag(this->input, this->stream, header)) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, LOG_MODULE ": ID3V2 tag parsing error\n"); bytes = 1; /* resync */ -- cgit v1.2.3 From dfaac7bec1f45bbabb8e5cfbe1001dee13829496 Mon Sep 17 00:00:00 2001 From: Thibaut Mattern <thibaut.mattern@gmail.com> Date: Mon, 18 Feb 2008 23:51:40 +0100 Subject: Timecode diff is signed. Should fix bug 35. --HG-- extra : transplant_source : %DD%95%9F%A7%8D%01%BD%98%40%E4R%AAW%F2%ED%93%B2%DE%1A%E9 --- src/demuxers/demux_matroska.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/demuxers/demux_matroska.c b/src/demuxers/demux_matroska.c index 3c992ecca..63b6ea3c8 100644 --- a/src/demuxers/demux_matroska.c +++ b/src/demuxers/demux_matroska.c @@ -1832,6 +1832,15 @@ static int read_block_data (demux_matroska_t *this, int len) { return 1; } +static int parse_int16(uint8_t *data) { + int value = (int)_X_BE_16(data); + if (value & 1<<15) + { + value -= 1<<16; + } + return value; +} + static int parse_block (demux_matroska_t *this, uint64_t block_size, uint64_t cluster_timecode, uint64_t block_duration, int normpos, int is_key) { @@ -1848,8 +1857,9 @@ static int parse_block (demux_matroska_t *this, uint64_t block_size, if (!(num_len = parse_ebml_uint(this, data, &track_num))) return 0; data += num_len; - - timecode_diff = (int)_X_BE_16(data); + + /* timecode_diff is signed */ + timecode_diff = parse_int16(data); data += 2; flags = *data; -- cgit v1.2.3 From 37f99fa644f5dab533053755ccac55ea7daf5c22 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Wed, 20 Feb 2008 21:45:48 +0000 Subject: Add a subtitles example to xine(5). --HG-- extra : transplant_source : %CA%CAD%2A%E6%5E%18Y%CB%29%D8%93R%0C%D4%F6%86j%82%F5 --- doc/man/en/xine.5 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/man/en/xine.5 b/doc/man/en/xine.5 index 7a9357640..d5b0b5afe 100644 --- a/doc/man/en/xine.5 +++ b/doc/man/en/xine.5 @@ -263,7 +263,12 @@ Text subtitle files may be appended to the MRL:. .TP .BI <mrl>#subtitle:<subtitlefile> This is the normal way to define the subtitle file to use. The frontend will -not take any notice of the subtitle file. +not take any notice of the subtitle file. For example: +.br +.I file://home/user/wibble.mpg#subtitles:/home/user/wibble.sub +.br +(Note that some front ends can detect subtitles files where the name differs +as shown in the example.) .br .SH STREAM OPTIONS .br -- cgit v1.2.3 From a2f6c4214b7f7efecd0bfddcedfdf9a413d842f8 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Wed, 20 Feb 2008 23:19:15 +0000 Subject: Off-by-one in the FLAC security fix, breaking playback of some files. --- ChangeLog | 2 ++ src/demuxers/demux_flac.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e0f73c3c2..aafb7d419 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,8 @@ xine-lib (1.1.11) unreleased * Made the version parsing much more reliable; it wasn't properly coping with four-part version numbers. This affects any program whose build scripts use xine-lib's automake macros. + * Fixed an off-by-one in the FLAC security fix patch. This breakage was + causing failure to play some files. xine-lib (1.1.10.1) 2008-02-07 * Security fixes: diff --git a/src/demuxers/demux_flac.c b/src/demuxers/demux_flac.c index e5d1297a2..f6544bb67 100644 --- a/src/demuxers/demux_flac.c +++ b/src/demuxers/demux_flac.c @@ -202,7 +202,7 @@ static int open_flac_file(demux_flac_t *flac) { length = _X_LE_32(ptr); ptr += 4 + length; - if (length >= block_length - 8) + if (length > block_length - 8) return 0; /* bad length or too little left in the buffer */ user_comment_list_length = _X_LE_32(ptr); -- cgit v1.2.3 From dff9fc9bb1e3a5593c8dcc1c77116d1647b9af99 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Mon, 25 Feb 2008 17:23:51 +0000 Subject: Add more VO_CAP_* to indicate support for colour controls & zoom properties. --HG-- extra : transplant_source : %C2%84%E8%0E%FD%DE%D3%3E%FB%B8%AF%F3%80a%5E%B3v%C5%8B%08 --- ChangeLog | 2 ++ include/xine/video_out.h | 9 ++++++++- src/video_out/video_out_directfb.c | 18 ++++++++++++++++-- src/video_out/video_out_fb.c | 2 +- src/video_out/video_out_opengl.c | 2 +- src/video_out/video_out_pgx64.c | 3 +-- src/video_out/video_out_vidix.c | 6 +++++- src/video_out/video_out_xcbshm.c | 2 +- src/video_out/video_out_xcbxv.c | 8 +++++++- src/video_out/video_out_xshm.c | 2 +- src/video_out/video_out_xv.c | 8 +++++++- src/video_out/video_out_xvmc.c | 8 +++++++- src/video_out/video_out_xxmc.c | 8 +++++++- 13 files changed, 64 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index e9b0c3ce0..efecc4ccd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -57,6 +57,8 @@ xine-lib (1.1.90) (Unreleased) please use DirectFB or VIDIX instead. * The Xv and XxMC video output plugins now support Xv port selection. (XvMC does not, at present.) + * Report more video output capabilities via (port)->get_capabilities(): + colour controls, zooming, colour keying. xine-lib (1.1.11) unreleased * Reworked the plugin directory naming so that external plugins don't have diff --git a/include/xine/video_out.h b/include/xine/video_out.h index f34380af1..02eff3cac 100644 --- a/include/xine/video_out.h +++ b/include/xine/video_out.h @@ -282,7 +282,14 @@ struct xine_video_port_s { #define VO_CAP_UNSCALED_OVERLAY 0x00000010 /* driver can blend overlay at output resolution */ #define VO_CAP_CROP 0x00000020 /* driver can crop */ #define VO_CAP_XXMC 0x00000040 /* driver can use extended XvMC */ - +#define VO_CAP_HUE 0x00010000 +#define VO_CAP_SATURATION 0x00020000 +#define VO_CAP_CONTRAST 0x00040000 +#define VO_CAP_BRIGHTNESS 0x00080000 +#define VO_CAP_COLORKEY 0x00100000 +#define VO_CAP_AUTOPAINT_COLORKEY 0x00200000 +#define VO_CAP_ZOOM_X 0x00400000 +#define VO_CAP_ZOOM_Y 0x00800000 /* * vo_driver_s contains the functions every display driver diff --git a/src/video_out/video_out_directfb.c b/src/video_out/video_out_directfb.c index d85df411a..fecc2c5b0 100644 --- a/src/video_out/video_out_directfb.c +++ b/src/video_out/video_out_directfb.c @@ -1742,6 +1742,20 @@ static void directfb_frame_output_cb (void *user_data, int video_width, int vide /*** DirectFB plugin functions ***/ +static inline int convert_caps (DFBDisplayLayerCapabilities caps) +{ + int vo = VO_CAP_YV12 | VO_CAP_YUY2 | VO_CAP_CROP | VO_CAP_ZOOM_X | VO_CAP_ZOOM_Y; + if (caps & DLCAPS_HUE) + vo |= VO_CAP_HUE; + if (caps & DLCAPS_SATURATION) + vo |= VO_CAP_SATURATION; + if (caps & DLCAPS_CONTRAST) + vo |= VO_CAP_CONTRAST; + if (caps & DLCAPS_BRIGHTNESS) + vo |= VO_CAP_BRIGHTNESS; + return vo; +} + static vo_driver_t *open_plugin_fb (video_driver_class_t *class_gen, const void *visual_gen) { directfb_class_t *class = (directfb_class_t *) class_gen; directfb_driver_t *this; @@ -1821,7 +1835,7 @@ static vo_driver_t *open_plugin_fb (video_driver_class_t *class_gen, const void return NULL; } - this->capabilities = VO_CAP_YV12 | VO_CAP_YUY2 | VO_CAP_CROP; + this->capabilities = convert_caps (this->caps); /* set default configuration */ this->buffermode = 1; // double this->vsync = 0; @@ -2000,7 +2014,7 @@ static vo_driver_t *open_plugin_x11 (video_driver_class_t *class_gen, const void xprintf (this->xine, XINE_VERBOSITY_LOG, _("video_out_directfb: using display layer #%d.\n"), id); - this->capabilities = VO_CAP_YV12 | VO_CAP_YUY2 | VO_CAP_CROP; + this->capabilities = convert_caps (this->caps); /* set default configuration */ this->buffermode = 1; // double this->vsync = 0; diff --git a/src/video_out/video_out_fb.c b/src/video_out/video_out_fb.c index 17224ecad..5a49b80a3 100644 --- a/src/video_out/video_out_fb.c +++ b/src/video_out/video_out_fb.c @@ -155,7 +155,7 @@ typedef struct static uint32_t fb_get_capabilities(vo_driver_t *this_gen) { - return VO_CAP_YV12 | VO_CAP_YUY2; + return VO_CAP_YV12 | VO_CAP_YUY2 | VO_CAP_BRIGHTNESS | VO_CAP_CONTRAST | VO_CAP_SATURATION; } static void fb_frame_proc_slice(vo_frame_t *vo_img, uint8_t **src) diff --git a/src/video_out/video_out_opengl.c b/src/video_out/video_out_opengl.c index 21383453e..2ffd83637 100644 --- a/src/video_out/video_out_opengl.c +++ b/src/video_out/video_out_opengl.c @@ -1200,7 +1200,7 @@ static void *render_run (opengl_driver_t *this) { static uint32_t opengl_get_capabilities (vo_driver_t *this_gen) { /* opengl_driver_t *this = (opengl_driver_t *) this_gen; */ - uint32_t capabilities = VO_CAP_YV12 | VO_CAP_YUY2; + uint32_t capabilities = VO_CAP_YV12 | VO_CAP_YUY2 | VO_CAP_BRIGHTNESS | VO_CAP_CONTRAST | VO_CAP_SATURATION; /* TODO: somehow performance goes down during the first few frames */ /* if (this->xoverlay) */ diff --git a/src/video_out/video_out_pgx64.c b/src/video_out/video_out_pgx64.c index d0e74b1e3..0bdcc35fe 100644 --- a/src/video_out/video_out_pgx64.c +++ b/src/video_out/video_out_pgx64.c @@ -552,8 +552,7 @@ static uint32_t pgx64_get_capabilities(vo_driver_t *this_gen) { /*pgx64_driver_t *this = (pgx64_driver_t *)(void *)this_gen;*/ - return VO_CAP_YV12 | - VO_CAP_YUY2; + return VO_CAP_YV12 | VO_CAP_YUY2 | VO_CAP_BRIGHTNESS | VO_CAP_SATURATION; } static vo_frame_t *pgx64_alloc_frame(vo_driver_t *this_gen) diff --git a/src/video_out/video_out_vidix.c b/src/video_out/video_out_vidix.c index f4b74ad2a..586268513 100644 --- a/src/video_out/video_out_vidix.c +++ b/src/video_out/video_out_vidix.c @@ -964,7 +964,7 @@ static vidix_driver_t *open_plugin (video_driver_class_t *class_gen) { this->config = config; this->got_frame_data = 0; - this->capabilities = VO_CAP_CROP; + this->capabilities = VO_CAP_CROP | VO_CAP_ZOOM_X | VO_CAP_ZOOM_Y; /* Find what equalizer flags are supported */ if(this->vidix_cap.flags & FLAG_EQUALIZER) { @@ -973,24 +973,28 @@ static vidix_driver_t *open_plugin (video_driver_class_t *class_gen) { "video_out_vidix: couldn't get equalizer capabilities: %s\n", strerror(err)); } else { if(this->vidix_eq.cap & VEQ_CAP_BRIGHTNESS) { + this->capabilities |= VO_CAP_BRIGHTNESS; this->props[VO_PROP_BRIGHTNESS].value = 0; this->props[VO_PROP_BRIGHTNESS].min = -1000; this->props[VO_PROP_BRIGHTNESS].max = 1000; } if(this->vidix_eq.cap & VEQ_CAP_CONTRAST) { + this->capabilities |= VO_CAP_CONTRAST; this->props[VO_PROP_CONTRAST].value = 0; this->props[VO_PROP_CONTRAST].min = -1000; this->props[VO_PROP_CONTRAST].max = 1000; } if(this->vidix_eq.cap & VEQ_CAP_SATURATION) { + this->capabilities |= VO_CAP_SATURATION; this->props[VO_PROP_SATURATION].value = 0; this->props[VO_PROP_SATURATION].min = -1000; this->props[VO_PROP_SATURATION].max = 1000; } if(this->vidix_eq.cap & VEQ_CAP_HUE) { + this->capabilities |= VO_CAP_HUE; this->props[VO_PROP_HUE].value = 0; this->props[VO_PROP_HUE].min = -1000; this->props[VO_PROP_HUE].max = 1000; diff --git a/src/video_out/video_out_xcbshm.c b/src/video_out/video_out_xcbshm.c index 9895d1852..1bacf50c9 100644 --- a/src/video_out/video_out_xcbshm.c +++ b/src/video_out/video_out_xcbshm.c @@ -221,7 +221,7 @@ static void dispose_ximage(xshm_driver_t *this, xshm_frame_t *frame) static uint32_t xshm_get_capabilities (vo_driver_t *this_gen) { xshm_driver_t *this = (xshm_driver_t *) this_gen; - uint32_t capabilities = VO_CAP_YV12 | VO_CAP_YUY2; + uint32_t capabilities = VO_CAP_YV12 | VO_CAP_YUY2 | VO_CAP_BRIGHTNESS | VO_CAP_CONTRAST | VO_CAP_SATURATION; if( this->xoverlay ) capabilities |= VO_CAP_UNSCALED_OVERLAY; diff --git a/src/video_out/video_out_xcbxv.c b/src/video_out/video_out_xcbxv.c index 6fed0f90a..18d752431 100644 --- a/src/video_out/video_out_xcbxv.c +++ b/src/video_out/video_out_xcbxv.c @@ -1234,7 +1234,7 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis this->gc = xcb_generate_id(this->connection); xcb_create_gc(this->connection, this->gc, this->window, 0, NULL); - this->capabilities = VO_CAP_CROP; + this->capabilities = VO_CAP_CROP | VO_CAP_ZOOM_X | VO_CAP_ZOOM_Y; this->use_shm = 1; this->use_colorkey = 0; this->colorkey = 0; @@ -1295,28 +1295,34 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis if (!strncmp(xcb_xv_adaptor_info_name(adaptor_it.data), "NV", 2)) { xprintf (this->xine, XINE_VERBOSITY_NONE, LOG_MODULE ": ignoring broken XV_HUE settings on NVidia cards\n"); } else { + this->capabilities |= VO_CAP_HUE; xv_check_capability (this, VO_PROP_HUE, attribute_it.data, adaptor_it.data->base_id, NULL, NULL, NULL); } } else if(!strcmp(name, "XV_SATURATION")) { + this->capabilities |= VO_CAP_SATURATION; xv_check_capability (this, VO_PROP_SATURATION, attribute_it.data, adaptor_it.data->base_id, NULL, NULL, NULL); } else if(!strcmp(name, "XV_BRIGHTNESS")) { + this->capabilities |= VO_CAP_BRIGHTNESS; xv_check_capability (this, VO_PROP_BRIGHTNESS, attribute_it.data, adaptor_it.data->base_id, NULL, NULL, NULL); } else if(!strcmp(name, "XV_CONTRAST")) { + this->capabilities |= VO_CAP_CONTRAST; xv_check_capability (this, VO_PROP_CONTRAST, attribute_it.data, adaptor_it.data->base_id, NULL, NULL, NULL); } else if(!strcmp(name, "XV_COLORKEY")) { + this->capabilities |= VO_CAP_COLORKEY; xv_check_capability (this, VO_PROP_COLORKEY, attribute_it.data, adaptor_it.data->base_id, "video.device.xv_colorkey", VIDEO_DEVICE_XV_COLORKEY_HELP); } else if(!strcmp(name, "XV_AUTOPAINT_COLORKEY")) { + this->capabilities |= VO_CAP_AUTOPAINT_COLORKEY; xv_check_capability (this, VO_PROP_AUTOPAINT_COLORKEY, attribute_it.data, adaptor_it.data->base_id, "video.device.xv_autopaint_colorkey", diff --git a/src/video_out/video_out_xshm.c b/src/video_out/video_out_xshm.c index 7801bb03b..8f51964e2 100644 --- a/src/video_out/video_out_xshm.c +++ b/src/video_out/video_out_xshm.c @@ -314,7 +314,7 @@ static void dispose_ximage (xshm_driver_t *this, static uint32_t xshm_get_capabilities (vo_driver_t *this_gen) { xshm_driver_t *this = (xshm_driver_t *) this_gen; - uint32_t capabilities = VO_CAP_YV12 | VO_CAP_YUY2; + uint32_t capabilities = VO_CAP_YV12 | VO_CAP_YUY2 | VO_CAP_BRIGHTNESS | VO_CAP_CONTRAST | VO_CAP_SATURATION; if( this->xoverlay ) capabilities |= VO_CAP_UNSCALED_OVERLAY; diff --git a/src/video_out/video_out_xv.c b/src/video_out/video_out_xv.c index 6f5c68e51..115489e57 100644 --- a/src/video_out/video_out_xv.c +++ b/src/video_out/video_out_xv.c @@ -1275,7 +1275,7 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void * LOCK_DISPLAY(this); this->gc = XCreateGC (this->display, this->drawable, 0, NULL); UNLOCK_DISPLAY(this); - this->capabilities = VO_CAP_CROP; + this->capabilities = VO_CAP_CROP | VO_CAP_ZOOM_X | VO_CAP_ZOOM_Y; this->use_shm = 1; this->use_colorkey = 0; this->colorkey = 0; @@ -1342,28 +1342,34 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void * if (!strncmp(adaptor_info[adaptor_num].name, "NV", 2)) { xprintf (this->xine, XINE_VERBOSITY_NONE, LOG_MODULE ": ignoring broken XV_HUE settings on NVidia cards\n"); } else { + this->capabilities |= VO_CAP_HUE; xv_check_capability (this, VO_PROP_HUE, attr[k], adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); } } else if(!strcmp(name, "XV_SATURATION")) { + this->capabilities |= VO_CAP_SATURATION; xv_check_capability (this, VO_PROP_SATURATION, attr[k], adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); } else if(!strcmp(name, "XV_BRIGHTNESS")) { + this->capabilities |= VO_CAP_BRIGHTNESS; xv_check_capability (this, VO_PROP_BRIGHTNESS, attr[k], adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); } else if(!strcmp(name, "XV_CONTRAST")) { + this->capabilities |= VO_CAP_CONTRAST; xv_check_capability (this, VO_PROP_CONTRAST, attr[k], adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); } else if(!strcmp(name, "XV_COLORKEY")) { + this->capabilities |= VO_CAP_COLORKEY; xv_check_capability (this, VO_PROP_COLORKEY, attr[k], adaptor_info[adaptor_num].base_id, "video.device.xv_colorkey", VIDEO_DEVICE_XV_COLORKEY_HELP); } else if(!strcmp(name, "XV_AUTOPAINT_COLORKEY")) { + this->capabilities |= VO_CAP_AUTOPAINT_COLORKEY; xv_check_capability (this, VO_PROP_AUTOPAINT_COLORKEY, attr[k], adaptor_info[adaptor_num].base_id, "video.device.xv_autopaint_colorkey", diff --git a/src/video_out/video_out_xvmc.c b/src/video_out/video_out_xvmc.c index 9618b082c..7f282ee53 100644 --- a/src/video_out/video_out_xvmc.c +++ b/src/video_out/video_out_xvmc.c @@ -1332,7 +1332,7 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi XLockDisplay(this->display); this->gc = XCreateGC(this->display, this->drawable, 0, NULL); XUnlockDisplay(this->display); - this->capabilities = VO_CAP_XVMC_MOCOMP | VO_CAP_CROP; + this->capabilities = VO_CAP_XVMC_MOCOMP | VO_CAP_CROP | VO_CAP_ZOOM_X | VO_CAP_ZOOM_Y; this->surface_type_id = class->surface_type_id; this->max_surface_width = class->max_surface_width; @@ -1401,28 +1401,34 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi if (!strncmp(adaptor_info[adaptor_num].name, "NV", 2)) { xprintf (this->xine, XINE_VERBOSITY_NONE, LOG_MODULE ": ignoring broken XV_HUE settings on NVidia cards\n"); } else { + this->capabilities |= VO_CAP_HUE; xvmc_check_capability (this, VO_PROP_HUE, attr[k], adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); } } else if(!strcmp(name, "XV_SATURATION")) { + this->capabilities |= VO_CAP_SATURATION; xvmc_check_capability (this, VO_PROP_SATURATION, attr[k], adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); } else if(!strcmp(attr[k].name, "XV_BRIGHTNESS")) { + this->capabilities |= VO_CAP_BRIGHTNESS; xvmc_check_capability (this, VO_PROP_BRIGHTNESS, attr[k], adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); } else if(!strcmp(name, "XV_CONTRAST")) { + this->capabilities |= VO_CAP_CONTRAST; xvmc_check_capability (this, VO_PROP_CONTRAST, attr[k], adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); } else if(!strcmp(name, "XV_COLORKEY")) { + this->capabilities |= VO_CAP_COLORKEY; xvmc_check_capability (this, VO_PROP_COLORKEY, attr[k], adaptor_info[adaptor_num].base_id, "video.device.xv_colorkey", VIDEO_DEVICE_XV_COLORKEY_HELP); } else if(!strcmp(name, "XV_AUTOPAINT_COLORKEY")) { + this->capabilities |= VO_CAP_AUTOPAINT_COLORKEY; xvmc_check_capability (this, VO_PROP_AUTOPAINT_COLORKEY, attr[k], adaptor_info[adaptor_num].base_id, "video.device.xv_autopaint_colorkey", diff --git a/src/video_out/video_out_xxmc.c b/src/video_out/video_out_xxmc.c index 2c42dda2e..35346dd1d 100644 --- a/src/video_out/video_out_xxmc.c +++ b/src/video_out/video_out_xxmc.c @@ -2520,7 +2520,7 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi XLockDisplay (this->display); this->gc = XCreateGC (this->display, this->drawable, 0, NULL); XUnlockDisplay (this->display); - this->capabilities = VO_CAP_CROP; + this->capabilities = VO_CAP_CROP | VO_CAP_ZOOM_X | VO_CAP_ZOOM_Y; this->use_shm = 1; this->use_colorkey = 0; this->colorkey = 0; @@ -2584,28 +2584,34 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi if (!strncmp(adaptor_info[adaptor_num].name, "NV", 2)) { xprintf (this->xine, XINE_VERBOSITY_NONE, LOG_MODULE ": ignoring broken XV_HUE settings on NVidia cards\n"); } else { + this->capabilities |= VO_CAP_HUE; xxmc_check_capability (this, VO_PROP_HUE, attr[k], adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); } } else if(!strcmp(name, "XV_SATURATION")) { + this->capabilities |= VO_CAP_SATURATION; xxmc_check_capability (this, VO_PROP_SATURATION, attr[k], adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); } else if(!strcmp(name, "XV_BRIGHTNESS")) { + this->capabilities |= VO_CAP_BRIGHTNESS; xxmc_check_capability (this, VO_PROP_BRIGHTNESS, attr[k], adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); } else if(!strcmp(name, "XV_CONTRAST")) { + this->capabilities |= VO_CAP_CONTRAST; xxmc_check_capability (this, VO_PROP_CONTRAST, attr[k], adaptor_info[adaptor_num].base_id, NULL, NULL, NULL); } else if(!strcmp(name, "XV_COLORKEY")) { + this->capabilities |= VO_CAP_COLORKEY; xxmc_check_capability (this, VO_PROP_COLORKEY, attr[k], adaptor_info[adaptor_num].base_id, "video.device.xv_colorkey", VIDEO_DEVICE_XV_COLORKEY_HELP); } else if(!strcmp(name, "XV_AUTOPAINT_COLORKEY")) { + this->capabilities |= VO_CAP_AUTOPAINT_COLORKEY; xxmc_check_capability (this, VO_PROP_AUTOPAINT_COLORKEY, attr[k], adaptor_info[adaptor_num].base_id, "video.device.xv_autopaint_colorkey", -- cgit v1.2.3 From e15dfd5952406f62cbceec59114920c8b758524e Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Mon, 25 Feb 2008 18:53:19 +0000 Subject: When auto-detecting Xv ports, prefer port nos. >= configured. --- src/video_out/video_out_xcbxv.c | 17 +++++++++++------ src/video_out/video_out_xv.c | 12 +++++++----- src/video_out/video_out_xxmc.c | 12 +++++++----- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/video_out/video_out_xcbxv.c b/src/video_out/video_out_xcbxv.c index 18d752431..b7001ca03 100644 --- a/src/video_out/video_out_xcbxv.c +++ b/src/video_out/video_out_xcbxv.c @@ -1123,19 +1123,23 @@ xv_find_adaptor_by_port (int port, xcb_xv_adaptor_info_iterator_t *adaptor_it) } static xcb_xv_port_t xv_autodetect_port(xv_driver_t *this, - xcb_xv_adaptor_info_iterator_t *adaptor_it) + xcb_xv_adaptor_info_iterator_t *adaptor_it, + xcb_xv_port_t base) { for (; adaptor_it->rem; xcb_xv_adaptor_info_next(adaptor_it)) if (adaptor_it->data->type & XCB_XV_TYPE_IMAGE_MASK) { int j; for (j = 0; j < adaptor_it->data->num_ports; ++j) - if (!xv_check_yv12 (this->connection, adaptor_it->data->base_id + j)) + { + xcb_xv_port_t port = adaptor_it->data->base_id + j; + if (port >= base && !xv_check_yv12 (this->connection, port)) { - xcb_xv_port_t port = xv_open_port (this, adaptor_it->data->base_id + j); + xcb_xv_port_t port = xv_open_port (this, port); if (port) return port; } + } } return 0; } @@ -1205,11 +1209,12 @@ static vo_driver_t *open_plugin(video_driver_class_t *class_gen, const void *vis xprintf(class->xine, XINE_VERBOSITY_NONE, _("%s: could not open Xv port %d - autodetecting\n"), LOG_MODULE, xv_port); - xv_port = xv_autodetect_port (this, &adaptor_it); + xv_port = xv_autodetect_port (this, &adaptor_it, xv_port); } else xv_find_adaptor_by_port (xv_port, &adaptor_it); - } else - xv_port = xv_autodetect_port (this, &adaptor_it); + } + if (!xv_port) + xv_port = xv_autodetect_port (this, &adaptor_it, 0); if (!xv_port) { xprintf(class->xine, XINE_VERBOSITY_LOG, diff --git a/src/video_out/video_out_xv.c b/src/video_out/video_out_xv.c index 115489e57..bc5928c25 100644 --- a/src/video_out/video_out_xv.c +++ b/src/video_out/video_out_xv.c @@ -1161,14 +1161,15 @@ xv_find_adaptor_by_port (int port, unsigned int adaptors, static XvPortID xv_autodetect_port(xv_driver_t *this, unsigned int adaptors, XvAdaptorInfo *adaptor_info, - unsigned int *adaptor_num) { + unsigned int *adaptor_num, + XvPortID base) { unsigned int an, j; for (an = 0; an < adaptors; an++) if (adaptor_info[an].type & XvImageMask) for (j = 0; j < adaptor_info[an].num_ports; j++) { XvPortID port = adaptor_info[an].base_id + j; - if (xv_open_port(this, port)) { + if (port >= base && xv_open_port(this, port)) { *adaptor_num = an; return port; } @@ -1241,11 +1242,12 @@ static vo_driver_t *open_plugin_2 (video_driver_class_t *class_gen, const void * xprintf(class->xine, XINE_VERBOSITY_NONE, _("%s: could not open Xv port %d - autodetecting\n"), LOG_MODULE, xv_port); - xv_port = xv_autodetect_port(this, adaptors, adaptor_info, &adaptor_num); + xv_port = xv_autodetect_port(this, adaptors, adaptor_info, &adaptor_num, xv_port); } else adaptor_num = xv_find_adaptor_by_port (xv_port, adaptors, adaptor_info); - } else - xv_port = xv_autodetect_port(this, adaptors, adaptor_info, &adaptor_num); + } + if (!xv_port) + xv_port = xv_autodetect_port(this, adaptors, adaptor_info, &adaptor_num, 0); if (!xv_port) { xprintf(class->xine, XINE_VERBOSITY_LOG, diff --git a/src/video_out/video_out_xxmc.c b/src/video_out/video_out_xxmc.c index 35346dd1d..1ef3652a9 100644 --- a/src/video_out/video_out_xxmc.c +++ b/src/video_out/video_out_xxmc.c @@ -2262,14 +2262,15 @@ xxmc_find_adaptor_by_port (int port, unsigned int adaptors, static XvPortID xxmc_autodetect_port(xxmc_driver_t *this, unsigned int adaptors, XvAdaptorInfo *adaptor_info, - unsigned int *adaptor_num) { + unsigned int *adaptor_num, + XvPortID base) { unsigned int an, j; for (an = 0; an < adaptors; an++) if (adaptor_info[an].type & XvImageMask) for (j = 0; j < adaptor_info[an].num_ports; j++) { XvPortID port = adaptor_info[an].base_id + j; - if (xxmc_open_port(this, port)) { + if (port >= base && xxmc_open_port(this, port)) { *adaptor_num = an; return port; } @@ -2486,11 +2487,12 @@ static vo_driver_t *open_plugin (video_driver_class_t *class_gen, const void *vi xprintf(class->xine, XINE_VERBOSITY_NONE, _("%s: could not open Xv port %d - autodetecting\n"), LOG_MODULE, xv_port); - xv_port = xxmc_autodetect_port(this, adaptors, adaptor_info, &adaptor_num); + xv_port = xxmc_autodetect_port(this, adaptors, adaptor_info, &adaptor_num, xv_port); } else adaptor_num = xxmc_find_adaptor_by_port (xv_port, adaptors, adaptor_info); - } else - xv_port = xxmc_autodetect_port(this, adaptors, adaptor_info, &adaptor_num); + } + if (!xv_port) + xv_port = xxmc_autodetect_port(this, adaptors, adaptor_info, &adaptor_num, 0); if (!xv_port) { xprintf(class->xine, XINE_VERBOSITY_LOG, -- cgit v1.2.3 From 6ae0d0cf4e69a301db67ec2bcfec242f8a415b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Tue, 26 Feb 2008 00:17:52 +0100 Subject: Install and distribute the base documentation files. --- Makefile.am | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Makefile.am b/Makefile.am index 5c86dcb68..211f0e8cd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,25 +13,21 @@ DEBFILES = debian/README.Debian debian/changelog debian/control \ debian/shlibdeps.sh debian/libxine-dev.install debian/libxine1.install EXTRA_DIST = config.rpath autogen.sh \ - ChangeLog \ configure \ config.guess \ config.sub \ - COPYING \ INSTALL \ install-sh \ libtool \ ltmain.sh \ missing \ - NEWS \ - README \ - TODO \ depcomp \ - CREDITS \ @DEPCOMP@ CONFIG_CLEAN_FILES = libtool +dist_doc_DATA = COPYING NEWS README TODO CREDITS ChangeLog + docs: @cd doc && $(MAKE) $@ -- cgit v1.2.3 From 2e5c9c79a47efe0df60aaea17569ea9f32d347a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Tue, 26 Feb 2008 00:19:13 +0100 Subject: Use dist_doc_DATA rather than setting EXTRA_DIST for documentation. --- doc/Makefile.am | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/doc/Makefile.am b/doc/Makefile.am index 1a757a4ca..070ef5a1e 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -2,13 +2,11 @@ include $(top_srcdir)/misc/Makefile.common SUBDIRS = man hackersguide faq -doc_DATA = README README.dvb README.dxr3 \ +dist_doc_DATA = README README.dvb README.dxr3 \ README.freebsd README.irix README.network_dvd README.opengl \ README.solaris README.syncfb README_xxmc.html README.MINGWCROSS \ README.WIN32 -EXTRA_DIST = $(doc_DATA) - docs clean-docs: @cd faq && $(MAKE) $@ @cd hackersguide && $(MAKE) $@ -- cgit v1.2.3 From 4a2a24dc98003e59ea9d7da982fefc81a82890d2 Mon Sep 17 00:00:00 2001 From: Darren Salt <linux@youmustbejoking.demon.co.uk> Date: Thu, 28 Feb 2008 13:47:59 +0000 Subject: Unbreak xcbxv port auto-detection (broken in cset f03669a2395d). --- src/video_out/video_out_xcbxv.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/video_out/video_out_xcbxv.c b/src/video_out/video_out_xcbxv.c index b7001ca03..204f59c2c 100644 --- a/src/video_out/video_out_xcbxv.c +++ b/src/video_out/video_out_xcbxv.c @@ -1133,12 +1133,8 @@ static xcb_xv_port_t xv_autodetect_port(xv_driver_t *this, for (j = 0; j < adaptor_it->data->num_ports; ++j) { xcb_xv_port_t port = adaptor_it->data->base_id + j; - if (port >= base && !xv_check_yv12 (this->connection, port)) - { - xcb_xv_port_t port = xv_open_port (this, port); - if (port) - return port; - } + if (port >= base && xv_open_port (this, port)) + return port; } } return 0; -- cgit v1.2.3 From fb54f247855376800b65585e5868cd4d2062c0a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sat, 1 Mar 2008 02:45:44 +0100 Subject: Support the new FFmpeg include layout. Now the same include directive should work for both internal and external FFmpeg (with new layout). --- configure.ac | 4 ++++ src/libffmpeg/Makefile.am | 2 ++ src/libffmpeg/ff_dvaudio_decoder.c | 8 ++++---- src/libffmpeg/ff_video_decoder.c | 4 ++-- src/libffmpeg/ffmpeg_decoder.h | 4 ++-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 90a5f1b80..0ecd5ab75 100644 --- a/configure.ac +++ b/configure.ac @@ -350,6 +350,10 @@ if test "x$with_external_ffmpeg" = "xyes"; then AC_SUBST([FFMPEG_POSTPROC_CFLAGS]) AC_SUBST([FFMPEG_POSTPROC_LIBS]) AC_DEFINE([HAVE_FFMPEG], [1], [Define this if you have ffmpeg library]) + + dnl Check presence of ffmpeg/avutil.h to see if it's old or new + dnl style for headers. The new style would be preferred actually... + AC_CHECK_HEADER([ffmpeg/avutil.h]) AC_MSG_NOTICE([ ********************************************************************* diff --git a/src/libffmpeg/Makefile.am b/src/libffmpeg/Makefile.am index 61acdd0d1..96d269278 100644 --- a/src/libffmpeg/Makefile.am +++ b/src/libffmpeg/Makefile.am @@ -1,5 +1,7 @@ include $(top_srcdir)/misc/Makefile.common +DEFAULT_INCLUDES = -I. + if HAVE_FFMPEG AM_CFLAGS = $(FFMPEG_CFLAGS) $(FFMPEG_POSTPROC_CFLAGS) link_ffmpeg = $(FFMPEG_LIBS) $(FFMPEG_POSTPROC_LIBS) diff --git a/src/libffmpeg/ff_dvaudio_decoder.c b/src/libffmpeg/ff_dvaudio_decoder.c index 0796b3862..a394e6615 100644 --- a/src/libffmpeg/ff_dvaudio_decoder.c +++ b/src/libffmpeg/ff_dvaudio_decoder.c @@ -52,14 +52,14 @@ # undef uint64_t #endif -#ifdef HAVE_FFMPEG +#ifdef HAVE_FFMPEG_AVCODEC_H # include <avcodec.h> -# include "libavcodec/dvdata.h" #else -# include "libavcodec/avcodec.h" -# include "libavcodec/dvdata.h" +# include <libavcodec/avcodec.h> #endif +#include "libavcodec/dvdata.h" + #ifdef _MSC_VER # undef malloc # undef free diff --git a/src/libffmpeg/ff_video_decoder.c b/src/libffmpeg/ff_video_decoder.c index dc07abb9f..d1d69416e 100644 --- a/src/libffmpeg/ff_video_decoder.c +++ b/src/libffmpeg/ff_video_decoder.c @@ -45,10 +45,10 @@ #include "ffmpeg_decoder.h" #include "ff_mpeg_parser.h" -#ifdef HAVE_FFMPEG +#ifdef HAVE_FFMPEG_AVCODEC_H # include <postprocess.h> #else -# include "libavcodec/libpostproc/postprocess.h" +# include <libpostproc/postprocess.h> #endif #define VIDEOBUFSIZE (128*1024) diff --git a/src/libffmpeg/ffmpeg_decoder.h b/src/libffmpeg/ffmpeg_decoder.h index 14788cf29..adf0908dd 100644 --- a/src/libffmpeg/ffmpeg_decoder.h +++ b/src/libffmpeg/ffmpeg_decoder.h @@ -25,10 +25,10 @@ #include "config.h" #endif -#ifdef HAVE_FFMPEG +#ifdef HAVE_FFMPEG_AVCODEC_H # include <avcodec.h> #else -# include "libavcodec/avcodec.h" +# include <libavcodec/avcodec.h> #endif typedef struct ff_codec_s { -- cgit v1.2.3 From 344d6df02ac4d1ed1214ead4f3419405ee699177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sat, 1 Mar 2008 02:53:23 +0100 Subject: Add test for ffmpeg's include directory style to 1.2 autotools. --- m4/decoders.m4 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/m4/decoders.m4 b/m4/decoders.m4 index 9dfe20148..b8f03e231 100644 --- a/m4/decoders.m4 +++ b/m4/decoders.m4 @@ -107,6 +107,10 @@ AC_DEFUN([XINE_DECODER_PLUGINS], [ PKG_CHECK_MODULES([FFMPEG_POSTPROC], [libpostproc]) AC_DEFINE([HAVE_FFMPEG], 1, [Define this if you have ffmpeg library]) + dnl Check presence of ffmpeg/avutil.h to see if it's old or new + dnl style for headers. The new style would be preferred actually... + AC_CHECK_HEADER([ffmpeg/avutil.h]) + AC_MSG_NOTICE([ ********************************************************************* xine-lib is configured with external ffmpeg. -- cgit v1.2.3 From 6cfb0e7a31d0cb5da6b10bdb4cb2a41d55531812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sat, 1 Mar 2008 02:54:13 +0100 Subject: Only include the toplevel ffmpeg directory, with the new style include it works better. --- src/combined/ffmpeg/Makefile.am | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/combined/ffmpeg/Makefile.am b/src/combined/ffmpeg/Makefile.am index b9dee7ea6..93d9b8143 100644 --- a/src/combined/ffmpeg/Makefile.am +++ b/src/combined/ffmpeg/Makefile.am @@ -8,9 +8,7 @@ if WITH_EXTERNAL_FFMPEG AM_CFLAGS += $(FFMPEG_CFLAGS) $(FFMPEG_POSTPROC_CFLAGS) link_ffmpeg = $(FFMPEG_LIBS) $(FFMPEG_POSTPROC_LIBS) else -AM_CPPFLAGS += -I$(top_srcdir)/contrib/ffmpeg/libavutil \ - -I$(top_srcdir)/contrib/ffmpeg/libavcodec \ - -I$(top_srcdir)/contrib/ffmpeg/libpostproc +AM_CPPFLAGS += -I$(top_srcdir)/contrib/ffmpeg link_ffmpeg = $(top_builddir)/contrib/ffmpeg/libavcodec/libavcodec.a \ $(top_builddir)/contrib/ffmpeg/libavutil/libavutil.a \ $(top_builddir)/contrib/ffmpeg/libpostproc/libpostproc.a @@ -59,4 +57,4 @@ xineplug_decode_ff_la_LDFLAGS = $(AM_LDFLAGS) $(IMPURE_TEXT_LDFLAGS) xineplug_decode_dvaudio_la_SOURCES = ff_dvaudio_decoder.c xineplug_decode_dvaudio_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) -xineplug_decode_dvaudio_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/contrib/ffmpeg/libavcodec +xineplug_decode_dvaudio_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/contrib/ffmpeg -- cgit v1.2.3 From df2107b51d969709c851b5cffe76cd0c9c2f4335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sat, 1 Mar 2008 02:54:39 +0100 Subject: dvdata.h is no more in include path alone. --- src/combined/ffmpeg/ff_dvaudio_decoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/combined/ffmpeg/ff_dvaudio_decoder.c b/src/combined/ffmpeg/ff_dvaudio_decoder.c index 293f35e7c..be7e8025f 100644 --- a/src/combined/ffmpeg/ff_dvaudio_decoder.c +++ b/src/combined/ffmpeg/ff_dvaudio_decoder.c @@ -58,7 +58,7 @@ # include <libavcodec/avcodec.h> #endif -#include <dvdata.h> /* This is not installed by FFmpeg, its usage has to be cleared up */ +#include <libavcodec/dvdata.h> /* This is not installed by FFmpeg, its usage has to be cleared up */ #ifdef _MSC_VER # undef malloc -- cgit v1.2.3 From 09496ad3469a0ade8dbd9a351e639b78f20b7942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sat, 1 Mar 2008 03:02:31 +0100 Subject: Use hg status . rather than hg status to avoid extra stuff to snicker in. --- contrib/README.contrib | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/README.contrib b/contrib/README.contrib index 6b2a58c1c..59863f12b 100644 --- a/contrib/README.contrib +++ b/contrib/README.contrib @@ -37,8 +37,8 @@ were added by FFmpeg upstream. A way to handle this is (assuming that you didn't try to compile xine-lib with the updated ffmpeg yet): cd ${xine-lib-checkout}/contrib/ffmpeg - hg status | egrep '^!' | cut -d ' ' -f 2 | xargs hg rm - hg status | egrep '^?' | cut -d ' ' -f 2 | xargs hg add + hg status . | egrep '^!' | cut -d ' ' -f 2 | xargs hg rm + hg status . | egrep '^?' | cut -d ' ' -f 2 | xargs hg add This should register the file changes that happened. -- cgit v1.2.3 From 1d0b3b20c34517b9d1ddf3ea347776304b0c4b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= <flameeyes@gmail.com> Date: Sat, 1 Mar 2008 03:05:13 +0100 Subject: Update internal FFmpeg copy. --- contrib/ffmpeg-distfiles | 1060 ++-- contrib/ffmpeg/COPYING | 504 -- contrib/ffmpeg/COPYING.GPL | 339 ++ contrib/ffmpeg/COPYING.LGPL | 504 ++ contrib/ffmpeg/CREDITS | 2 + contrib/ffmpeg/Changelog | 57 +- contrib/ffmpeg/Doxyfile | 2 +- contrib/ffmpeg/MAINTAINERS | 45 +- contrib/ffmpeg/Makefile | 415 +- contrib/ffmpeg/README | 17 +- contrib/ffmpeg/build_avopt | 9 - contrib/ffmpeg/clean-diff | 11 - contrib/ffmpeg/cmdutils.c | 129 +- contrib/ffmpeg/cmdutils.h | 60 +- contrib/ffmpeg/common.mak | 87 +- contrib/ffmpeg/configure | 2012 ++++---- contrib/ffmpeg/cws2fws.c | 127 - contrib/ffmpeg/doc/Makefile | 20 - contrib/ffmpeg/doc/TODO | 13 +- contrib/ffmpeg/doc/avutil.txt | 2 +- contrib/ffmpeg/doc/faq.texi | 371 +- contrib/ffmpeg/doc/ffmpeg-doc.texi | 961 +--- contrib/ffmpeg/doc/ffserver-doc.texi | 4 +- contrib/ffmpeg/doc/ffserver.conf | 5 +- contrib/ffmpeg/doc/general.texi | 985 ++++ contrib/ffmpeg/doc/hooks.texi | 45 +- contrib/ffmpeg/doc/issue_tracker.txt | 222 + contrib/ffmpeg/doc/optimization.txt | 82 +- contrib/ffmpeg/doc/snow.txt | 385 +- contrib/ffmpeg/ffinstall.nsi | 4 +- contrib/ffmpeg/ffmpeg.c | 1208 +++-- contrib/ffmpeg/ffplay.c | 264 +- contrib/ffmpeg/ffserver.c | 803 ++- contrib/ffmpeg/ffserver.h | 6 +- contrib/ffmpeg/libavcodec/4xm.c | 175 +- contrib/ffmpeg/libavcodec/8bps.c | 17 +- contrib/ffmpeg/libavcodec/Makefile | 491 +- contrib/ffmpeg/libavcodec/a52dec.c | 259 - contrib/ffmpeg/libavcodec/aac_ac3_parser.c | 88 + contrib/ffmpeg/libavcodec/aac_ac3_parser.h | 43 + contrib/ffmpeg/libavcodec/aac_parser.c | 100 + contrib/ffmpeg/libavcodec/aasc.c | 9 +- contrib/ffmpeg/libavcodec/ac3.c | 168 +- contrib/ffmpeg/libavcodec/ac3.h | 120 +- contrib/ffmpeg/libavcodec/ac3_parser.c | 156 + contrib/ffmpeg/libavcodec/ac3_parser.h | 47 + contrib/ffmpeg/libavcodec/ac3dec.c | 1173 +++++ contrib/ffmpeg/libavcodec/ac3enc.c | 237 +- contrib/ffmpeg/libavcodec/ac3tab.c | 249 + contrib/ffmpeg/libavcodec/ac3tab.h | 254 +- contrib/ffmpeg/libavcodec/adpcm.c | 556 +- contrib/ffmpeg/libavcodec/adx.c | 412 -- contrib/ffmpeg/libavcodec/adx.h | 49 + contrib/ffmpeg/libavcodec/adxdec.c | 169 + contrib/ffmpeg/libavcodec/adxenc.c | 193 + contrib/ffmpeg/libavcodec/alac.c | 583 +-- contrib/ffmpeg/libavcodec/allcodecs.c | 466 +- contrib/ffmpeg/libavcodec/alpha/asm.h | 6 +- contrib/ffmpeg/libavcodec/alpha/dsputil_alpha.c | 2 +- contrib/ffmpeg/libavcodec/alpha/motion_est_alpha.c | 2 +- contrib/ffmpeg/libavcodec/alpha/mpegvideo_alpha.c | 4 +- contrib/ffmpeg/libavcodec/alpha/regdef.h | 6 +- .../ffmpeg/libavcodec/alpha/simple_idct_alpha.c | 14 +- contrib/ffmpeg/libavcodec/amr.c | 715 --- contrib/ffmpeg/libavcodec/apedec.c | 922 ++++ contrib/ffmpeg/libavcodec/apiexample.c | 11 +- contrib/ffmpeg/libavcodec/armv4l/dsputil_arm.c | 80 +- contrib/ffmpeg/libavcodec/armv4l/dsputil_arm_s.S | 38 +- contrib/ffmpeg/libavcodec/armv4l/dsputil_iwmmxt.c | 23 +- .../ffmpeg/libavcodec/armv4l/dsputil_iwmmxt_rnd.h | 4 + contrib/ffmpeg/libavcodec/armv4l/mathops.h | 5 + contrib/ffmpeg/libavcodec/armv4l/mpegvideo_arm.c | 9 +- .../ffmpeg/libavcodec/armv4l/mpegvideo_armv5te.c | 16 +- .../ffmpeg/libavcodec/armv4l/mpegvideo_iwmmxt.c | 6 +- contrib/ffmpeg/libavcodec/armv4l/simple_idct_arm.S | 11 +- .../ffmpeg/libavcodec/armv4l/simple_idct_armv5te.S | 9 +- .../ffmpeg/libavcodec/armv4l/simple_idct_armv6.S | 9 +- contrib/ffmpeg/libavcodec/asv1.c | 5 +- contrib/ffmpeg/libavcodec/atrac3.c | 1068 ++++ contrib/ffmpeg/libavcodec/atrac3data.h | 140 + contrib/ffmpeg/libavcodec/audioconvert.c | 5 +- contrib/ffmpeg/libavcodec/avcodec.h | 1887 ++++--- contrib/ffmpeg/libavcodec/avs.c | 7 +- contrib/ffmpeg/libavcodec/beosthread.c | 6 +- contrib/ffmpeg/libavcodec/bethsoftvideo.c | 139 + contrib/ffmpeg/libavcodec/bethsoftvideo.h | 36 + contrib/ffmpeg/libavcodec/bfin/config_bfin.h | 21 +- contrib/ffmpeg/libavcodec/bfin/dsputil_bfin.c | 102 +- contrib/ffmpeg/libavcodec/bfin/dsputil_bfin.h | 74 + contrib/ffmpeg/libavcodec/bfin/fdct_bfin.S | 12 +- contrib/ffmpeg/libavcodec/bfin/idct_bfin.S | 14 +- contrib/ffmpeg/libavcodec/bfin/mathops.h | 52 + contrib/ffmpeg/libavcodec/bfin/mpegvideo_bfin.c | 152 + contrib/ffmpeg/libavcodec/bfin/pixels_bfin.S | 18 + contrib/ffmpeg/libavcodec/bfin/vp3_bfin.c | 50 + contrib/ffmpeg/libavcodec/bfin/vp3_idct_bfin.S | 281 + contrib/ffmpeg/libavcodec/bitstream.c | 60 +- contrib/ffmpeg/libavcodec/bitstream.h | 74 +- contrib/ffmpeg/libavcodec/bitstream_filter.c | 233 +- contrib/ffmpeg/libavcodec/bmp.c | 9 +- contrib/ffmpeg/libavcodec/bmp.h | 7 + contrib/ffmpeg/libavcodec/bytestream.h | 35 +- contrib/ffmpeg/libavcodec/c93.c | 253 + contrib/ffmpeg/libavcodec/cabac.c | 11 +- contrib/ffmpeg/libavcodec/cabac.h | 41 +- contrib/ffmpeg/libavcodec/cavs.c | 956 +--- contrib/ffmpeg/libavcodec/cavs.h | 314 ++ contrib/ffmpeg/libavcodec/cavs_parser.c | 107 + contrib/ffmpeg/libavcodec/cavsdata.h | 180 +- contrib/ffmpeg/libavcodec/cavsdec.c | 702 +++ contrib/ffmpeg/libavcodec/cavsdsp.c | 2 +- contrib/ffmpeg/libavcodec/cinepak.c | 27 +- contrib/ffmpeg/libavcodec/cljr.c | 3 +- contrib/ffmpeg/libavcodec/colorspace.h | 111 + contrib/ffmpeg/libavcodec/cook.c | 268 +- contrib/ffmpeg/libavcodec/cookdata.h | 8 +- contrib/ffmpeg/libavcodec/cscd.c | 22 +- contrib/ffmpeg/libavcodec/cyuv.c | 20 +- contrib/ffmpeg/libavcodec/dca.c | 254 +- contrib/ffmpeg/libavcodec/dca.h | 34 + contrib/ffmpeg/libavcodec/dca_parser.c | 126 + contrib/ffmpeg/libavcodec/dcadata.h | 26 +- contrib/ffmpeg/libavcodec/dcahuff.h | 8 + contrib/ffmpeg/libavcodec/dct-test.c | 21 +- contrib/ffmpeg/libavcodec/dnxhddata.c | 443 ++ contrib/ffmpeg/libavcodec/dnxhddata.h | 115 +- contrib/ffmpeg/libavcodec/dnxhddec.c | 168 +- contrib/ffmpeg/libavcodec/dnxhdenc.c | 847 +++ contrib/ffmpeg/libavcodec/dpcm.c | 73 +- contrib/ffmpeg/libavcodec/dsicinav.c | 30 +- contrib/ffmpeg/libavcodec/dsputil.c | 542 +- contrib/ffmpeg/libavcodec/dsputil.h | 178 +- contrib/ffmpeg/libavcodec/dtsdec.c | 268 - contrib/ffmpeg/libavcodec/dump_extradata_bsf.c | 50 + contrib/ffmpeg/libavcodec/dv.c | 8 +- contrib/ffmpeg/libavcodec/dvbsub.c | 76 +- contrib/ffmpeg/libavcodec/dvbsub_parser.c | 196 + contrib/ffmpeg/libavcodec/dvbsubdec.c | 407 +- contrib/ffmpeg/libavcodec/dvdata.h | 18 +- contrib/ffmpeg/libavcodec/dvdsub_parser.c | 83 + contrib/ffmpeg/libavcodec/dvdsubdec.c | 275 +- contrib/ffmpeg/libavcodec/dvdsubenc.c | 42 +- contrib/ffmpeg/libavcodec/dxa.c | 10 +- contrib/ffmpeg/libavcodec/elbg.c | 417 ++ contrib/ffmpeg/libavcodec/elbg.h | 55 + contrib/ffmpeg/libavcodec/error_resilience.c | 10 +- contrib/ffmpeg/libavcodec/eval.c | 16 +- contrib/ffmpeg/libavcodec/eval.h | 19 +- contrib/ffmpeg/libavcodec/faac.c | 136 - contrib/ffmpeg/libavcodec/faad.c | 333 -- contrib/ffmpeg/libavcodec/faandct.c | 84 +- contrib/ffmpeg/libavcodec/faandct.h | 8 +- contrib/ffmpeg/libavcodec/faanidct.c | 168 + contrib/ffmpeg/libavcodec/faanidct.h | 32 + contrib/ffmpeg/libavcodec/fdctref.c | 1 - contrib/ffmpeg/libavcodec/fft-test.c | 29 +- contrib/ffmpeg/libavcodec/ffv1.c | 7 +- contrib/ffmpeg/libavcodec/flac.c | 105 +- contrib/ffmpeg/libavcodec/flacenc.c | 242 +- contrib/ffmpeg/libavcodec/flashsv.c | 10 +- contrib/ffmpeg/libavcodec/flashsvenc.c | 85 +- contrib/ffmpeg/libavcodec/flicvideo.c | 52 +- contrib/ffmpeg/libavcodec/fraps.c | 103 +- contrib/ffmpeg/libavcodec/g726.c | 49 +- contrib/ffmpeg/libavcodec/gif.c | 12 +- contrib/ffmpeg/libavcodec/gifdec.c | 20 +- contrib/ffmpeg/libavcodec/golomb.c | 19 +- contrib/ffmpeg/libavcodec/golomb.h | 52 +- contrib/ffmpeg/libavcodec/h261.c | 1009 +--- contrib/ffmpeg/libavcodec/h261.h | 51 + contrib/ffmpeg/libavcodec/h261_parser.c | 90 + contrib/ffmpeg/libavcodec/h261data.h | 9 +- contrib/ffmpeg/libavcodec/h261dec.c | 650 +++ contrib/ffmpeg/libavcodec/h261enc.c | 334 ++ contrib/ffmpeg/libavcodec/h263.c | 199 +- contrib/ffmpeg/libavcodec/h263.h | 46 + contrib/ffmpeg/libavcodec/h263_parser.c | 91 + contrib/ffmpeg/libavcodec/h263_parser.h | 29 + contrib/ffmpeg/libavcodec/h263data.h | 6 + contrib/ffmpeg/libavcodec/h263dec.c | 147 +- contrib/ffmpeg/libavcodec/h264.c | 3196 +++++------- contrib/ffmpeg/libavcodec/h264.h | 419 ++ contrib/ffmpeg/libavcodec/h264_mp4toannexb_bsf.c | 154 + contrib/ffmpeg/libavcodec/h264_parser.c | 148 + contrib/ffmpeg/libavcodec/h264_parser.h | 39 + contrib/ffmpeg/libavcodec/h264data.h | 50 +- contrib/ffmpeg/libavcodec/h264dsp.c | 81 - contrib/ffmpeg/libavcodec/h264dspenc.c | 81 + contrib/ffmpeg/libavcodec/h264idct.c | 1 - contrib/ffmpeg/libavcodec/h264pred.c | 1073 ++++ contrib/ffmpeg/libavcodec/h264pred.h | 77 + contrib/ffmpeg/libavcodec/huffman.c | 105 + contrib/ffmpeg/libavcodec/huffman.h | 39 + contrib/ffmpeg/libavcodec/huffyuv.c | 362 +- contrib/ffmpeg/libavcodec/i386/cavsdsp_mmx.c | 30 +- contrib/ffmpeg/libavcodec/i386/cputest.c | 44 +- .../libavcodec/i386/dsputil_h264_template_mmx.c | 18 +- contrib/ffmpeg/libavcodec/i386/dsputil_mmx.c | 1936 ++----- contrib/ffmpeg/libavcodec/i386/dsputil_mmx.h | 123 + contrib/ffmpeg/libavcodec/i386/dsputil_mmx_avg.h | 90 +- contrib/ffmpeg/libavcodec/i386/dsputil_mmx_qns.h | 105 + contrib/ffmpeg/libavcodec/i386/dsputil_mmx_rnd.h | 58 +- contrib/ffmpeg/libavcodec/i386/dsputilenc_mmx.c | 1422 +++++ contrib/ffmpeg/libavcodec/i386/fdct_mmx.c | 190 +- contrib/ffmpeg/libavcodec/i386/fft_3dn.c | 2 +- contrib/ffmpeg/libavcodec/i386/fft_3dn2.c | 2 +- contrib/ffmpeg/libavcodec/i386/fft_sse.c | 82 +- contrib/ffmpeg/libavcodec/i386/flacdsp_mmx.c | 138 + contrib/ffmpeg/libavcodec/i386/h264dsp_mmx.c | 896 +++- contrib/ffmpeg/libavcodec/i386/idct_mmx.c | 418 +- contrib/ffmpeg/libavcodec/i386/idct_mmx_xvid.c | 100 +- contrib/ffmpeg/libavcodec/i386/mathops.h | 4 + contrib/ffmpeg/libavcodec/i386/mmx.h | 8 +- contrib/ffmpeg/libavcodec/i386/motion_est_mmx.c | 270 +- contrib/ffmpeg/libavcodec/i386/mpegvideo_mmx.c | 41 +- .../libavcodec/i386/mpegvideo_mmx_template.c | 200 +- contrib/ffmpeg/libavcodec/i386/simple_idct_mmx.c | 12 +- contrib/ffmpeg/libavcodec/i386/snowdsp_mmx.c | 732 ++- contrib/ffmpeg/libavcodec/i386/vc1dsp_mmx.c | 490 ++ contrib/ffmpeg/libavcodec/i386/vp3dsp_mmx.c | 14 +- contrib/ffmpeg/libavcodec/i386/vp3dsp_mmx.h | 32 + contrib/ffmpeg/libavcodec/i386/vp3dsp_sse2.c | 18 +- contrib/ffmpeg/libavcodec/i386/vp3dsp_sse2.h | 31 + contrib/ffmpeg/libavcodec/idcinvideo.c | 13 +- contrib/ffmpeg/libavcodec/imc.c | 23 +- contrib/ffmpeg/libavcodec/imcdata.h | 7 +- contrib/ffmpeg/libavcodec/imgconvert.c | 387 +- contrib/ffmpeg/libavcodec/imgconvert.h | 33 + contrib/ffmpeg/libavcodec/imgconvert_template.h | 8 +- contrib/ffmpeg/libavcodec/imgresample.c | 148 +- contrib/ffmpeg/libavcodec/imx_dump_header_bsf.c | 59 + contrib/ffmpeg/libavcodec/indeo2.c | 7 +- contrib/ffmpeg/libavcodec/indeo2data.h | 7 + contrib/ffmpeg/libavcodec/indeo3.c | 56 +- contrib/ffmpeg/libavcodec/indeo3data.h | 7 + contrib/ffmpeg/libavcodec/interplayvideo.c | 40 +- contrib/ffmpeg/libavcodec/intrax8.c | 764 +++ contrib/ffmpeg/libavcodec/intrax8.h | 57 + contrib/ffmpeg/libavcodec/intrax8dsp.c | 432 ++ contrib/ffmpeg/libavcodec/intrax8huf.h | 918 ++++ contrib/ffmpeg/libavcodec/jpeg_ls.c | 860 ---- contrib/ffmpeg/libavcodec/jpegls.c | 96 + contrib/ffmpeg/libavcodec/jpegls.h | 111 + contrib/ffmpeg/libavcodec/jpeglsdec.c | 375 ++ contrib/ffmpeg/libavcodec/jpeglsdec.h | 41 + contrib/ffmpeg/libavcodec/jpeglsenc.c | 393 ++ contrib/ffmpeg/libavcodec/kmvc.c | 20 +- contrib/ffmpeg/libavcodec/lcl.c | 928 ---- contrib/ffmpeg/libavcodec/lcl.h | 49 + contrib/ffmpeg/libavcodec/lcldec.c | 715 +++ contrib/ffmpeg/libavcodec/lclenc.c | 231 + contrib/ffmpeg/libavcodec/liba52.c | 225 + contrib/ffmpeg/libavcodec/libamr.c | 712 +++ contrib/ffmpeg/libavcodec/libfaac.c | 154 + contrib/ffmpeg/libavcodec/libfaad.c | 338 ++ contrib/ffmpeg/libavcodec/libgsm.c | 10 +- contrib/ffmpeg/libavcodec/libmp3lame.c | 221 + contrib/ffmpeg/libavcodec/libtheoraenc.c | 6 +- contrib/ffmpeg/libavcodec/libvorbis.c | 220 + contrib/ffmpeg/libavcodec/libx264.c | 300 ++ contrib/ffmpeg/libavcodec/libxvid_internal.h | 32 + contrib/ffmpeg/libavcodec/libxvid_rc.c | 148 + contrib/ffmpeg/libavcodec/libxvidff.c | 765 +++ contrib/ffmpeg/libavcodec/ljpegenc.c | 197 + contrib/ffmpeg/libavcodec/loco.c | 6 +- contrib/ffmpeg/libavcodec/lzw.c | 6 +- contrib/ffmpeg/libavcodec/lzw.h | 20 +- contrib/ffmpeg/libavcodec/lzwenc.c | 262 + contrib/ffmpeg/libavcodec/mace.c | 14 +- contrib/ffmpeg/libavcodec/mathops.h | 12 +- contrib/ffmpeg/libavcodec/mdct.c | 23 + contrib/ffmpeg/libavcodec/mdec.c | 15 +- contrib/ffmpeg/libavcodec/mjpeg.c | 2540 +-------- contrib/ffmpeg/libavcodec/mjpeg.h | 156 + contrib/ffmpeg/libavcodec/mjpeg_parser.c | 101 + contrib/ffmpeg/libavcodec/mjpega_dump_header_bsf.c | 92 + contrib/ffmpeg/libavcodec/mjpegbdec.c | 149 + contrib/ffmpeg/libavcodec/mjpegdec.c | 1380 +++++ contrib/ffmpeg/libavcodec/mjpegdec.h | 112 + contrib/ffmpeg/libavcodec/mjpegenc.c | 458 ++ contrib/ffmpeg/libavcodec/mjpegenc.h | 60 + contrib/ffmpeg/libavcodec/mlib/dsputil_mlib.c | 6 +- contrib/ffmpeg/libavcodec/mlp_parser.c | 307 ++ contrib/ffmpeg/libavcodec/mlp_parser.h | 60 + contrib/ffmpeg/libavcodec/mmvideo.c | 5 +- contrib/ffmpeg/libavcodec/motion-test.c | 164 + contrib/ffmpeg/libavcodec/motion_est.c | 11 +- contrib/ffmpeg/libavcodec/motion_est_template.c | 11 +- contrib/ffmpeg/libavcodec/motion_test.c | 160 - contrib/ffmpeg/libavcodec/movsub_bsf.c | 55 + .../ffmpeg/libavcodec/mp3_header_compress_bsf.c | 86 + .../ffmpeg/libavcodec/mp3_header_decompress_bsf.c | 96 + contrib/ffmpeg/libavcodec/mp3lameaudio.c | 221 - contrib/ffmpeg/libavcodec/mpc.c | 275 +- contrib/ffmpeg/libavcodec/mpc.h | 80 + contrib/ffmpeg/libavcodec/mpc7.c | 276 + contrib/ffmpeg/libavcodec/mpc7data.h | 171 + contrib/ffmpeg/libavcodec/mpc8.c | 364 ++ contrib/ffmpeg/libavcodec/mpc8data.h | 121 + contrib/ffmpeg/libavcodec/mpc8huff.h | 578 +++ contrib/ffmpeg/libavcodec/mpcdata.h | 152 +- contrib/ffmpeg/libavcodec/mpeg12.c | 1563 +----- contrib/ffmpeg/libavcodec/mpeg12.h | 31 + contrib/ffmpeg/libavcodec/mpeg12data.c | 374 ++ contrib/ffmpeg/libavcodec/mpeg12data.h | 458 +- contrib/ffmpeg/libavcodec/mpeg12decdata.h | 124 + contrib/ffmpeg/libavcodec/mpeg12enc.c | 954 ++++ contrib/ffmpeg/libavcodec/mpeg4data.h | 11 +- contrib/ffmpeg/libavcodec/mpeg4video_parser.c | 138 + contrib/ffmpeg/libavcodec/mpeg4video_parser.h | 34 + contrib/ffmpeg/libavcodec/mpegaudio.c | 785 +-- contrib/ffmpeg/libavcodec/mpegaudio.h | 71 +- contrib/ffmpeg/libavcodec/mpegaudio_parser.c | 252 + contrib/ffmpeg/libavcodec/mpegaudiodata.c | 225 + contrib/ffmpeg/libavcodec/mpegaudiodata.h | 43 + contrib/ffmpeg/libavcodec/mpegaudiodec.c | 374 +- contrib/ffmpeg/libavcodec/mpegaudiodecheader.c | 109 + contrib/ffmpeg/libavcodec/mpegaudiodecheader.h | 39 + contrib/ffmpeg/libavcodec/mpegaudiodectab.h | 201 +- contrib/ffmpeg/libavcodec/mpegaudioenc.c | 801 +++ contrib/ffmpeg/libavcodec/mpegaudiotab.h | 7 + contrib/ffmpeg/libavcodec/mpegvideo.c | 4956 +----------------- contrib/ffmpeg/libavcodec/mpegvideo.h | 96 +- contrib/ffmpeg/libavcodec/mpegvideo_common.h | 836 +++ contrib/ffmpeg/libavcodec/mpegvideo_enc.c | 3847 ++++++++++++++ contrib/ffmpeg/libavcodec/mpegvideo_parser.c | 180 + contrib/ffmpeg/libavcodec/msmpeg4.c | 134 +- contrib/ffmpeg/libavcodec/msmpeg4.h | 65 + contrib/ffmpeg/libavcodec/msmpeg4data.c | 2005 ++++++++ contrib/ffmpeg/libavcodec/msmpeg4data.h | 2014 +------- contrib/ffmpeg/libavcodec/msrle.c | 12 +- contrib/ffmpeg/libavcodec/msvideo1.c | 13 +- contrib/ffmpeg/libavcodec/nellymoserdec.c | 411 ++ contrib/ffmpeg/libavcodec/noise_bsf.c | 46 + contrib/ffmpeg/libavcodec/nuv.c | 153 +- contrib/ffmpeg/libavcodec/oggvorbis.c | 383 -- contrib/ffmpeg/libavcodec/opt.c | 52 +- contrib/ffmpeg/libavcodec/opt.h | 11 +- contrib/ffmpeg/libavcodec/os2thread.c | 6 +- contrib/ffmpeg/libavcodec/parser.c | 542 +- contrib/ffmpeg/libavcodec/parser.h | 11 +- contrib/ffmpeg/libavcodec/pcm.c | 171 +- contrib/ffmpeg/libavcodec/pcx.c | 247 + contrib/ffmpeg/libavcodec/png.c | 911 +--- contrib/ffmpeg/libavcodec/png.h | 77 + contrib/ffmpeg/libavcodec/pngdec.c | 621 +++ contrib/ffmpeg/libavcodec/pngenc.c | 448 ++ contrib/ffmpeg/libavcodec/pnm.c | 473 +- contrib/ffmpeg/libavcodec/pnm.h | 37 + contrib/ffmpeg/libavcodec/pnm_parser.c | 93 + contrib/ffmpeg/libavcodec/pnmenc.c | 425 ++ contrib/ffmpeg/libavcodec/ppc/check_altivec.c | 75 + contrib/ffmpeg/libavcodec/ppc/dsputil_altivec.c | 199 +- contrib/ffmpeg/libavcodec/ppc/dsputil_altivec.h | 80 +- contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.c | 12 +- contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.h | 14 +- contrib/ffmpeg/libavcodec/ppc/fdct_altivec.c | 4 +- contrib/ffmpeg/libavcodec/ppc/fft_altivec.c | 6 +- contrib/ffmpeg/libavcodec/ppc/float_altivec.c | 2 +- contrib/ffmpeg/libavcodec/ppc/gcc_fixes.h | 31 +- contrib/ffmpeg/libavcodec/ppc/gmc_altivec.c | 15 +- contrib/ffmpeg/libavcodec/ppc/h264_altivec.c | 601 ++- .../ffmpeg/libavcodec/ppc/h264_template_altivec.c | 613 ++- contrib/ffmpeg/libavcodec/ppc/idct_altivec.c | 7 +- .../ffmpeg/libavcodec/ppc/imgresample_altivec.c | 153 + .../ffmpeg/libavcodec/ppc/imgresample_altivec.h | 26 + contrib/ffmpeg/libavcodec/ppc/int_altivec.c | 80 + contrib/ffmpeg/libavcodec/ppc/mathops.h | 5 + contrib/ffmpeg/libavcodec/ppc/mpegvideo_altivec.c | 82 +- contrib/ffmpeg/libavcodec/ppc/mpegvideo_ppc.c | 87 - contrib/ffmpeg/libavcodec/ppc/snow_altivec.c | 61 +- contrib/ffmpeg/libavcodec/ppc/types_altivec.h | 5 + contrib/ffmpeg/libavcodec/ppc/util_altivec.h | 105 + contrib/ffmpeg/libavcodec/ppc/vc1dsp_altivec.c | 88 +- contrib/ffmpeg/libavcodec/ps2/dsputil_mmi.c | 8 +- contrib/ffmpeg/libavcodec/ps2/idct_mmi.c | 7 +- contrib/ffmpeg/libavcodec/ps2/mmi.h | 7 +- contrib/ffmpeg/libavcodec/ps2/mpegvideo_mmi.c | 12 +- contrib/ffmpeg/libavcodec/pthread.c | 6 +- contrib/ffmpeg/libavcodec/ptx.c | 117 + contrib/ffmpeg/libavcodec/qdm2.c | 31 +- contrib/ffmpeg/libavcodec/qdm2data.h | 9 +- contrib/ffmpeg/libavcodec/qdrw.c | 41 +- contrib/ffmpeg/libavcodec/qpeg.c | 11 +- contrib/ffmpeg/libavcodec/qtrle.c | 13 +- contrib/ffmpeg/libavcodec/qtrleenc.c | 326 ++ contrib/ffmpeg/libavcodec/ra144.c | 14 +- contrib/ffmpeg/libavcodec/ra144.h | 6 +- contrib/ffmpeg/libavcodec/ra288.c | 6 +- contrib/ffmpeg/libavcodec/ra288.h | 6 +- contrib/ffmpeg/libavcodec/rangecoder.c | 15 +- contrib/ffmpeg/libavcodec/rangecoder.h | 18 +- contrib/ffmpeg/libavcodec/ratecontrol.c | 43 +- contrib/ffmpeg/libavcodec/ratecontrol.h | 8 +- contrib/ffmpeg/libavcodec/raw.c | 165 +- contrib/ffmpeg/libavcodec/raw.h | 39 + contrib/ffmpeg/libavcodec/rawdec.c | 165 + contrib/ffmpeg/libavcodec/rawenc.c | 54 + contrib/ffmpeg/libavcodec/rectangle.h | 121 + contrib/ffmpeg/libavcodec/remove_extradata_bsf.c | 55 + contrib/ffmpeg/libavcodec/resample.c | 16 +- contrib/ffmpeg/libavcodec/resample2.c | 10 +- contrib/ffmpeg/libavcodec/rl.h | 33 +- contrib/ffmpeg/libavcodec/rle.c | 84 + contrib/ffmpeg/libavcodec/rle.h | 39 + contrib/ffmpeg/libavcodec/roqaudioenc.c | 177 + contrib/ffmpeg/libavcodec/roqvideo.c | 513 +- contrib/ffmpeg/libavcodec/roqvideo.h | 92 + contrib/ffmpeg/libavcodec/roqvideodec.c | 224 + contrib/ffmpeg/libavcodec/roqvideoenc.c | 1069 ++++ contrib/ffmpeg/libavcodec/rpza.c | 13 +- contrib/ffmpeg/libavcodec/rtjpeg.c | 8 +- contrib/ffmpeg/libavcodec/rtjpeg.h | 13 +- contrib/ffmpeg/libavcodec/rv10.c | 91 +- contrib/ffmpeg/libavcodec/rv30.c | 147 + contrib/ffmpeg/libavcodec/rv30data.h | 174 + contrib/ffmpeg/libavcodec/rv30dsp.c | 249 + contrib/ffmpeg/libavcodec/rv34.c | 1299 +++++ contrib/ffmpeg/libavcodec/rv34.h | 122 + contrib/ffmpeg/libavcodec/rv34data.h | 148 + contrib/ffmpeg/libavcodec/rv34vlc.h | 4054 +++++++++++++++ contrib/ffmpeg/libavcodec/rv40.c | 279 + contrib/ffmpeg/libavcodec/rv40data.h | 115 + contrib/ffmpeg/libavcodec/rv40vlc2.h | 706 +++ contrib/ffmpeg/libavcodec/s3tc.c | 96 + contrib/ffmpeg/libavcodec/s3tc.h | 53 + contrib/ffmpeg/libavcodec/sgi.h | 36 + contrib/ffmpeg/libavcodec/sgidec.c | 267 + contrib/ffmpeg/libavcodec/sgienc.c | 156 + contrib/ffmpeg/libavcodec/sh4/dsputil_align.c | 4 +- contrib/ffmpeg/libavcodec/sh4/dsputil_sh4.c | 4 +- contrib/ffmpeg/libavcodec/sh4/idct_sh4.c | 2 +- contrib/ffmpeg/libavcodec/sh4/qpel.c | 84 +- contrib/ffmpeg/libavcodec/shorten.c | 10 +- contrib/ffmpeg/libavcodec/simple_idct.c | 32 +- contrib/ffmpeg/libavcodec/simple_idct.h | 21 +- contrib/ffmpeg/libavcodec/smacker.c | 64 +- contrib/ffmpeg/libavcodec/smc.c | 13 +- contrib/ffmpeg/libavcodec/snow.c | 2107 ++++---- contrib/ffmpeg/libavcodec/snow.h | 32 +- contrib/ffmpeg/libavcodec/sonic.c | 11 +- contrib/ffmpeg/libavcodec/sp5x.h | 8 +- contrib/ffmpeg/libavcodec/sp5xdec.c | 213 + contrib/ffmpeg/libavcodec/sparc/dsputil_vis.c | 63 +- contrib/ffmpeg/libavcodec/sparc/simple_idct_vis.c | 528 ++ contrib/ffmpeg/libavcodec/sparc/vis.h | 5 + contrib/ffmpeg/libavcodec/sunrast.c | 195 + contrib/ffmpeg/libavcodec/svq1.c | 1396 +---- contrib/ffmpeg/libavcodec/svq1.h | 61 + contrib/ffmpeg/libavcodec/svq1_cb.h | 81 +- contrib/ffmpeg/libavcodec/svq1_vlc.h | 18 +- contrib/ffmpeg/libavcodec/svq1dec.c | 829 +++ contrib/ffmpeg/libavcodec/svq1enc.c | 588 +++ contrib/ffmpeg/libavcodec/svq1enc_cb.h | 96 + contrib/ffmpeg/libavcodec/svq3.c | 84 +- contrib/ffmpeg/libavcodec/targa.c | 5 +- contrib/ffmpeg/libavcodec/targaenc.c | 66 +- contrib/ffmpeg/libavcodec/tiertexseqv.c | 24 +- contrib/ffmpeg/libavcodec/tiff.c | 87 +- contrib/ffmpeg/libavcodec/tiff.h | 86 + contrib/ffmpeg/libavcodec/tiffenc.c | 461 ++ contrib/ffmpeg/libavcodec/truemotion1.c | 64 +- contrib/ffmpeg/libavcodec/truemotion1data.h | 10 +- contrib/ffmpeg/libavcodec/truemotion2.c | 12 +- contrib/ffmpeg/libavcodec/truespeech.c | 12 +- contrib/ffmpeg/libavcodec/truespeech_data.h | 8 +- contrib/ffmpeg/libavcodec/tscc.c | 12 +- contrib/ffmpeg/libavcodec/tta.c | 4 +- contrib/ffmpeg/libavcodec/txd.c | 166 + contrib/ffmpeg/libavcodec/ulti.c | 28 +- contrib/ffmpeg/libavcodec/ulti_cb.h | 5 + contrib/ffmpeg/libavcodec/unary.h | 56 + contrib/ffmpeg/libavcodec/utils.c | 303 +- contrib/ffmpeg/libavcodec/vb.c | 282 + contrib/ffmpeg/libavcodec/vc1.c | 1023 +--- contrib/ffmpeg/libavcodec/vc1.h | 312 ++ contrib/ffmpeg/libavcodec/vc1_parser.c | 118 + contrib/ffmpeg/libavcodec/vc1acdata.h | 7 + contrib/ffmpeg/libavcodec/vc1data.c | 712 +++ contrib/ffmpeg/libavcodec/vc1data.h | 671 +-- contrib/ffmpeg/libavcodec/vc1dsp.c | 394 +- contrib/ffmpeg/libavcodec/vcr1.c | 4 +- contrib/ffmpeg/libavcodec/vmdav.c | 58 +- contrib/ffmpeg/libavcodec/vmnc.c | 24 +- contrib/ffmpeg/libavcodec/vorbis.c | 1634 +----- contrib/ffmpeg/libavcodec/vorbis.h | 6 +- contrib/ffmpeg/libavcodec/vorbis_dec.c | 1638 ++++++ contrib/ffmpeg/libavcodec/vorbis_enc.c | 4 +- contrib/ffmpeg/libavcodec/vorbis_enc_data.h | 9 +- contrib/ffmpeg/libavcodec/vp3.c | 121 +- contrib/ffmpeg/libavcodec/vp3data.h | 9 +- contrib/ffmpeg/libavcodec/vp3dsp.c | 1 - contrib/ffmpeg/libavcodec/vp5.c | 76 +- contrib/ffmpeg/libavcodec/vp56.c | 361 +- contrib/ffmpeg/libavcodec/vp56.h | 73 +- contrib/ffmpeg/libavcodec/vp56data.c | 6 +- contrib/ffmpeg/libavcodec/vp56data.h | 14 +- contrib/ffmpeg/libavcodec/vp5data.h | 10 +- contrib/ffmpeg/libavcodec/vp6.c | 299 +- contrib/ffmpeg/libavcodec/vp6data.h | 16 +- contrib/ffmpeg/libavcodec/vqavideo.c | 17 +- contrib/ffmpeg/libavcodec/w32thread.c | 8 +- contrib/ffmpeg/libavcodec/wavpack.c | 99 +- contrib/ffmpeg/libavcodec/wma.c | 6 + contrib/ffmpeg/libavcodec/wma.h | 9 +- contrib/ffmpeg/libavcodec/wmadata.h | 8 + contrib/ffmpeg/libavcodec/wmadec.c | 119 +- contrib/ffmpeg/libavcodec/wmaenc.c | 20 +- contrib/ffmpeg/libavcodec/wmv2.c | 720 +-- contrib/ffmpeg/libavcodec/wmv2.h | 58 + contrib/ffmpeg/libavcodec/wmv2dec.c | 495 ++ contrib/ffmpeg/libavcodec/wmv2enc.c | 240 + contrib/ffmpeg/libavcodec/wnv1.c | 2 - contrib/ffmpeg/libavcodec/ws-snd1.c | 10 +- contrib/ffmpeg/libavcodec/x264.c | 300 -- contrib/ffmpeg/libavcodec/xan.c | 40 +- contrib/ffmpeg/libavcodec/xiph.h | 5 + contrib/ffmpeg/libavcodec/xl.c | 3 +- contrib/ffmpeg/libavcodec/xsubdec.c | 136 + contrib/ffmpeg/libavcodec/xvid_internal.h | 32 - contrib/ffmpeg/libavcodec/xvid_rc.c | 148 - contrib/ffmpeg/libavcodec/xvidff.c | 768 --- contrib/ffmpeg/libavcodec/xvmc_render.h | 43 +- contrib/ffmpeg/libavcodec/xvmcvideo.c | 6 +- contrib/ffmpeg/libavcodec/zmbv.c | 50 +- contrib/ffmpeg/libavcodec/zmbvenc.c | 16 +- contrib/ffmpeg/libavdevice/alldevices.c | 50 + contrib/ffmpeg/libavdevice/audio.c | 344 ++ contrib/ffmpeg/libavdevice/avdevice.h | 41 + contrib/ffmpeg/libavdevice/beosaudio.cpp | 465 ++ contrib/ffmpeg/libavdevice/bktr.c | 320 ++ contrib/ffmpeg/libavdevice/dv1394.c | 236 + contrib/ffmpeg/libavdevice/dv1394.h | 356 ++ contrib/ffmpeg/libavdevice/libdc1394.c | 372 ++ contrib/ffmpeg/libavdevice/v4l.c | 354 ++ contrib/ffmpeg/libavdevice/v4l2.c | 643 +++ contrib/ffmpeg/libavdevice/x11grab.c | 529 ++ contrib/ffmpeg/libavfilter/allfilters.c | 43 + contrib/ffmpeg/libavfilter/avfilter.c | 390 ++ contrib/ffmpeg/libavfilter/avfilter.h | 616 +++ contrib/ffmpeg/libavfilter/defaults.c | 158 + contrib/ffmpeg/libavfilter/formats.c | 148 + contrib/ffmpeg/libavformat/4xm.c | 50 +- contrib/ffmpeg/libavformat/Makefile | 209 +- contrib/ffmpeg/libavformat/adtsenc.c | 12 +- contrib/ffmpeg/libavformat/aiff.c | 173 +- contrib/ffmpeg/libavformat/allformats.c | 267 +- contrib/ffmpeg/libavformat/allformats.h | 182 - contrib/ffmpeg/libavformat/amr.c | 34 +- contrib/ffmpeg/libavformat/apc.c | 90 + contrib/ffmpeg/libavformat/ape.c | 523 ++ contrib/ffmpeg/libavformat/asf-enc.c | 39 +- contrib/ffmpeg/libavformat/asf.c | 182 +- contrib/ffmpeg/libavformat/asf.h | 13 +- contrib/ffmpeg/libavformat/asfcrypt.c | 172 + contrib/ffmpeg/libavformat/asfcrypt.h | 29 + contrib/ffmpeg/libavformat/au.c | 23 +- contrib/ffmpeg/libavformat/audio.c | 344 -- contrib/ffmpeg/libavformat/avc.c | 135 + contrib/ffmpeg/libavformat/avc.h | 32 + contrib/ffmpeg/libavformat/avformat.h | 335 +- contrib/ffmpeg/libavformat/avidec.c | 148 +- contrib/ffmpeg/libavformat/avienc.c | 19 +- contrib/ffmpeg/libavformat/avio.c | 40 +- contrib/ffmpeg/libavformat/avio.h | 123 +- contrib/ffmpeg/libavformat/aviobuf.c | 189 +- contrib/ffmpeg/libavformat/avisynth.c | 4 +- contrib/ffmpeg/libavformat/avs.c | 48 +- contrib/ffmpeg/libavformat/beosaudio.cpp | 465 -- contrib/ffmpeg/libavformat/bethsoftvid.c | 233 + contrib/ffmpeg/libavformat/c93.c | 198 + contrib/ffmpeg/libavformat/crc.c | 98 - contrib/ffmpeg/libavformat/crcenc.c | 67 + contrib/ffmpeg/libavformat/cutils.c | 92 +- contrib/ffmpeg/libavformat/daud.c | 6 +- contrib/ffmpeg/libavformat/dc1394.c | 193 - contrib/ffmpeg/libavformat/dsicin.c | 25 +- contrib/ffmpeg/libavformat/dv.c | 15 +- contrib/ffmpeg/libavformat/dv.h | 7 + contrib/ffmpeg/libavformat/dv1394.c | 236 - contrib/ffmpeg/libavformat/dv1394.h | 357 -- contrib/ffmpeg/libavformat/dvenc.c | 268 +- contrib/ffmpeg/libavformat/dxa.c | 34 +- contrib/ffmpeg/libavformat/eacdata.c | 100 + contrib/ffmpeg/libavformat/electronicarts.c | 398 +- contrib/ffmpeg/libavformat/ffm.c | 37 +- contrib/ffmpeg/libavformat/file.c | 47 +- contrib/ffmpeg/libavformat/flic.c | 76 +- contrib/ffmpeg/libavformat/flv.h | 8 +- contrib/ffmpeg/libavformat/flvdec.c | 136 +- contrib/ffmpeg/libavformat/flvenc.c | 41 +- contrib/ffmpeg/libavformat/framecrcenc.c | 46 + contrib/ffmpeg/libavformat/framehook.c | 4 +- contrib/ffmpeg/libavformat/framehook.h | 8 +- contrib/ffmpeg/libavformat/gif.c | 16 +- contrib/ffmpeg/libavformat/gifdec.c | 12 +- contrib/ffmpeg/libavformat/grab.c | 860 ---- contrib/ffmpeg/libavformat/grab_bktr.c | 320 -- contrib/ffmpeg/libavformat/gxf.c | 50 +- contrib/ffmpeg/libavformat/gxf.h | 29 +- contrib/ffmpeg/libavformat/gxfenc.c | 56 +- contrib/ffmpeg/libavformat/http.c | 25 +- contrib/ffmpeg/libavformat/idcin.c | 38 +- contrib/ffmpeg/libavformat/idroq.c | 33 +- contrib/ffmpeg/libavformat/img2.c | 44 +- contrib/ffmpeg/libavformat/ipmovie.c | 22 +- contrib/ffmpeg/libavformat/isom.c | 28 +- contrib/ffmpeg/libavformat/isom.h | 7 +- contrib/ffmpeg/libavformat/libnut.c | 14 +- contrib/ffmpeg/libavformat/lmlm4.c | 126 + contrib/ffmpeg/libavformat/matroska.c | 2827 +--------- contrib/ffmpeg/libavformat/matroska.h | 210 + contrib/ffmpeg/libavformat/matroskadec.c | 2842 ++++++++++ contrib/ffmpeg/libavformat/matroskaenc.c | 845 +++ contrib/ffmpeg/libavformat/mm.c | 28 +- contrib/ffmpeg/libavformat/mmf.c | 26 +- contrib/ffmpeg/libavformat/mov.c | 913 ++-- contrib/ffmpeg/libavformat/movenc.c | 487 +- contrib/ffmpeg/libavformat/mp3.c | 374 +- contrib/ffmpeg/libavformat/mpc.c | 46 +- contrib/ffmpeg/libavformat/mpc8.c | 244 + contrib/ffmpeg/libavformat/mpeg.c | 1495 +----- contrib/ffmpeg/libavformat/mpeg.h | 69 + contrib/ffmpeg/libavformat/mpegenc.c | 1294 +++++ contrib/ffmpeg/libavformat/mpegts.c | 589 +-- contrib/ffmpeg/libavformat/mpegts.h | 10 +- contrib/ffmpeg/libavformat/mpegtsenc.c | 12 +- contrib/ffmpeg/libavformat/mpjpeg.c | 12 +- contrib/ffmpeg/libavformat/mtv.c | 21 +- contrib/ffmpeg/libavformat/mxf.c | 389 +- contrib/ffmpeg/libavformat/network.h | 40 +- contrib/ffmpeg/libavformat/nsvdec.c | 28 +- contrib/ffmpeg/libavformat/nut.c | 1449 +----- contrib/ffmpeg/libavformat/nut.h | 35 +- contrib/ffmpeg/libavformat/nutdec.c | 321 +- contrib/ffmpeg/libavformat/nutenc.c | 775 +++ contrib/ffmpeg/libavformat/nuv.c | 33 +- contrib/ffmpeg/libavformat/ogg.c | 283 - contrib/ffmpeg/libavformat/ogg2.c | 700 --- contrib/ffmpeg/libavformat/ogg2.h | 86 - contrib/ffmpeg/libavformat/oggdec.c | 596 +++ contrib/ffmpeg/libavformat/oggdec.h | 90 + contrib/ffmpeg/libavformat/oggenc.c | 292 ++ contrib/ffmpeg/libavformat/oggparseflac.c | 20 +- contrib/ffmpeg/libavformat/oggparseogm.c | 71 +- contrib/ffmpeg/libavformat/oggparsespeex.c | 61 + contrib/ffmpeg/libavformat/oggparsetheora.c | 37 +- contrib/ffmpeg/libavformat/oggparsevorbis.c | 123 +- contrib/ffmpeg/libavformat/os_support.c | 114 +- contrib/ffmpeg/libavformat/os_support.h | 32 +- contrib/ffmpeg/libavformat/psxstr.c | 26 +- contrib/ffmpeg/libavformat/pva.c | 211 + contrib/ffmpeg/libavformat/qtpalette.h | 14 +- contrib/ffmpeg/libavformat/raw.c | 216 +- contrib/ffmpeg/libavformat/raw.h | 30 + contrib/ffmpeg/libavformat/riff.c | 143 +- contrib/ffmpeg/libavformat/riff.h | 13 +- contrib/ffmpeg/libavformat/rm.c | 1147 ----- contrib/ffmpeg/libavformat/rm.h | 108 + contrib/ffmpeg/libavformat/rmdec.c | 801 +++ contrib/ffmpeg/libavformat/rmenc.c | 444 ++ contrib/ffmpeg/libavformat/rtp.c | 927 +--- contrib/ffmpeg/libavformat/rtp.h | 26 +- contrib/ffmpeg/libavformat/rtp_aac.c | 88 + contrib/ffmpeg/libavformat/rtp_aac.h | 27 + contrib/ffmpeg/libavformat/rtp_h264.c | 21 +- contrib/ffmpeg/libavformat/rtp_h264.h | 10 +- contrib/ffmpeg/libavformat/rtp_internal.h | 31 +- contrib/ffmpeg/libavformat/rtp_mpv.c | 118 + contrib/ffmpeg/libavformat/rtp_mpv.h | 27 + contrib/ffmpeg/libavformat/rtpdec.c | 552 ++ contrib/ffmpeg/libavformat/rtpenc.c | 366 ++ contrib/ffmpeg/libavformat/rtpenc_h264.c | 78 + contrib/ffmpeg/libavformat/rtpproto.c | 29 +- contrib/ffmpeg/libavformat/rtsp.c | 204 +- contrib/ffmpeg/libavformat/rtsp.h | 15 +- contrib/ffmpeg/libavformat/rtspcodes.h | 4 + contrib/ffmpeg/libavformat/sdp.c | 320 ++ contrib/ffmpeg/libavformat/segafilm.c | 39 +- contrib/ffmpeg/libavformat/sierravmd.c | 34 +- contrib/ffmpeg/libavformat/siff.c | 237 + contrib/ffmpeg/libavformat/smacker.c | 51 +- contrib/ffmpeg/libavformat/sol.c | 10 +- contrib/ffmpeg/libavformat/swf.c | 379 +- contrib/ffmpeg/libavformat/tcp.c | 35 +- contrib/ffmpeg/libavformat/thp.c | 195 +- contrib/ffmpeg/libavformat/tiertexseq.c | 24 +- contrib/ffmpeg/libavformat/tta.c | 91 +- contrib/ffmpeg/libavformat/txd.c | 103 + contrib/ffmpeg/libavformat/udp.c | 320 +- contrib/ffmpeg/libavformat/utils.c | 1048 ++-- contrib/ffmpeg/libavformat/v4l2.c | 631 --- contrib/ffmpeg/libavformat/vc1test.c | 112 + contrib/ffmpeg/libavformat/voc.c | 2 +- contrib/ffmpeg/libavformat/voc.h | 8 +- contrib/ffmpeg/libavformat/vocdec.c | 26 +- contrib/ffmpeg/libavformat/vocenc.c | 10 +- contrib/ffmpeg/libavformat/wav.c | 34 +- contrib/ffmpeg/libavformat/wc3movie.c | 40 +- contrib/ffmpeg/libavformat/westwood.c | 40 +- contrib/ffmpeg/libavformat/wv.c | 25 +- contrib/ffmpeg/libavformat/x11grab.c | 529 -- contrib/ffmpeg/libavformat/yuv4mpeg.c | 24 +- contrib/ffmpeg/libavutil/Makefile | 60 +- contrib/ffmpeg/libavutil/adler32.c | 4 +- contrib/ffmpeg/libavutil/adler32.h | 8 +- contrib/ffmpeg/libavutil/aes.c | 12 +- contrib/ffmpeg/libavutil/aes.h | 12 +- contrib/ffmpeg/libavutil/avstring.h | 90 + contrib/ffmpeg/libavutil/avutil.h | 38 +- contrib/ffmpeg/libavutil/base64.c | 28 +- contrib/ffmpeg/libavutil/base64.h | 8 +- contrib/ffmpeg/libavutil/bswap.h | 132 +- contrib/ffmpeg/libavutil/common.h | 126 +- contrib/ffmpeg/libavutil/crc.c | 76 +- contrib/ffmpeg/libavutil/crc.h | 29 +- contrib/ffmpeg/libavutil/crc_data.h | 213 + contrib/ffmpeg/libavutil/des.c | 330 ++ contrib/ffmpeg/libavutil/des.h | 39 + contrib/ffmpeg/libavutil/fifo.h | 8 +- contrib/ffmpeg/libavutil/integer.c | 6 +- contrib/ffmpeg/libavutil/integer.h | 9 +- contrib/ffmpeg/libavutil/internal.h | 173 +- contrib/ffmpeg/libavutil/intfloat_readwrite.h | 6 +- contrib/ffmpeg/libavutil/intreadwrite.h | 194 +- contrib/ffmpeg/libavutil/lls.c | 10 +- contrib/ffmpeg/libavutil/lls.h | 8 +- contrib/ffmpeg/libavutil/log.c | 6 - contrib/ffmpeg/libavutil/log.h | 13 +- contrib/ffmpeg/libavutil/lzo.c | 10 +- contrib/ffmpeg/libavutil/lzo.h | 8 +- contrib/ffmpeg/libavutil/mathematics.c | 20 +- contrib/ffmpeg/libavutil/mathematics.h | 6 +- contrib/ffmpeg/libavutil/md5.c | 30 +- contrib/ffmpeg/libavutil/md5.h | 8 +- contrib/ffmpeg/libavutil/mem.c | 6 +- contrib/ffmpeg/libavutil/mem.h | 75 +- contrib/ffmpeg/libavutil/random.h | 6 +- contrib/ffmpeg/libavutil/rational.c | 1 - contrib/ffmpeg/libavutil/rational.h | 11 +- contrib/ffmpeg/libavutil/rc4.c | 48 + contrib/ffmpeg/libavutil/rc4.h | 28 + contrib/ffmpeg/libavutil/sha1.c | 36 +- contrib/ffmpeg/libavutil/sha1.h | 31 +- contrib/ffmpeg/libavutil/softfloat.c | 2 +- contrib/ffmpeg/libavutil/softfloat.h | 8 +- contrib/ffmpeg/libavutil/string.c | 78 + contrib/ffmpeg/libavutil/tree.c | 128 +- contrib/ffmpeg/libavutil/tree.h | 38 +- contrib/ffmpeg/libavutil/x86_cpu.h | 70 +- contrib/ffmpeg/libpostproc/Makefile | 14 +- contrib/ffmpeg/libpostproc/mangle.h | 47 - contrib/ffmpeg/libpostproc/postprocess.c | 96 +- contrib/ffmpeg/libpostproc/postprocess.h | 42 +- .../libpostproc/postprocess_altivec_template.c | 14 +- contrib/ffmpeg/libpostproc/postprocess_internal.h | 29 +- contrib/ffmpeg/libpostproc/postprocess_template.c | 41 +- contrib/ffmpeg/libswscale/Makefile | 14 +- contrib/ffmpeg/libswscale/cs_test.c | 344 +- contrib/ffmpeg/libswscale/internal_bfin.S | 607 +++ contrib/ffmpeg/libswscale/rgb2rgb.c | 749 ++- contrib/ffmpeg/libswscale/rgb2rgb.h | 81 +- contrib/ffmpeg/libswscale/rgb2rgb_template.c | 4667 ++++++++--------- contrib/ffmpeg/libswscale/swscale-example.c | 328 +- contrib/ffmpeg/libswscale/swscale.c | 4507 ++++++++-------- contrib/ffmpeg/libswscale/swscale.h | 138 +- .../ffmpeg/libswscale/swscale_altivec_template.c | 906 ++-- contrib/ffmpeg/libswscale/swscale_bfin.c | 94 + contrib/ffmpeg/libswscale/swscale_internal.h | 318 +- contrib/ffmpeg/libswscale/swscale_template.c | 5423 ++++++++++---------- contrib/ffmpeg/libswscale/yuv2rgb.c | 949 ++-- contrib/ffmpeg/libswscale/yuv2rgb_altivec.c | 1352 ++--- contrib/ffmpeg/libswscale/yuv2rgb_bfin.c | 207 + contrib/ffmpeg/libswscale/yuv2rgb_init.c | 412 -- contrib/ffmpeg/libswscale/yuv2rgb_mlib.c | 88 +- contrib/ffmpeg/libswscale/yuv2rgb_template.c | 744 ++- contrib/ffmpeg/libswscale/yuv2rgb_vis.c | 206 + contrib/ffmpeg/output_example.c | 10 +- contrib/ffmpeg/pktdumper.c | 117 - contrib/ffmpeg/qt-faststart.c | 311 -- contrib/ffmpeg/tests/Makefile | 114 - contrib/ffmpeg/tests/audiogen.c | 2 +- contrib/ffmpeg/tests/dsptest.c | 178 - contrib/ffmpeg/tests/ffmpeg.regression.ref | 315 +- contrib/ffmpeg/tests/libav.regression.ref | 242 +- contrib/ffmpeg/tests/regression.sh | 363 +- contrib/ffmpeg/tests/rotozoom.regression.ref | 317 +- contrib/ffmpeg/tests/seek.regression.ref | 3685 +++++++++++++ contrib/ffmpeg/tests/seek_test.c | 12 +- contrib/ffmpeg/tests/seek_test.sh | 22 +- contrib/ffmpeg/tests/server-regression.sh | 29 +- contrib/ffmpeg/tests/tiny_psnr.c | 17 +- contrib/ffmpeg/tests/videogen.c | 2 +- contrib/ffmpeg/tools/build_avopt | 9 + contrib/ffmpeg/tools/clean-diff | 11 + contrib/ffmpeg/tools/cws2fws.c | 130 + contrib/ffmpeg/tools/pktdumper.c | 119 + contrib/ffmpeg/tools/qt-faststart.c | 311 ++ contrib/ffmpeg/tools/trasher.c | 70 + contrib/ffmpeg/tools/unwrap-diff | 2 + contrib/ffmpeg/unwrap-diff | 2 - contrib/ffmpeg/version.sh | 20 +- contrib/ffmpeg/vhook/Makefile | 50 - contrib/ffmpeg/vhook/drawtext.c | 6 +- contrib/ffmpeg/vhook/fish.c | 2 +- contrib/ffmpeg/vhook/imlib2.c | 183 +- contrib/ffmpeg/vhook/ppm.c | 5 +- contrib/ffmpeg/vhook/watermark.c | 8 +- 808 files changed, 121339 insertions(+), 77600 deletions(-) delete mode 100644 contrib/ffmpeg/COPYING create mode 100644 contrib/ffmpeg/COPYING.GPL create mode 100644 contrib/ffmpeg/COPYING.LGPL delete mode 100755 contrib/ffmpeg/build_avopt delete mode 100755 contrib/ffmpeg/clean-diff delete mode 100644 contrib/ffmpeg/cws2fws.c delete mode 100644 contrib/ffmpeg/doc/Makefile create mode 100644 contrib/ffmpeg/doc/general.texi create mode 100644 contrib/ffmpeg/doc/issue_tracker.txt delete mode 100644 contrib/ffmpeg/libavcodec/a52dec.c create mode 100644 contrib/ffmpeg/libavcodec/aac_ac3_parser.c create mode 100644 contrib/ffmpeg/libavcodec/aac_ac3_parser.h create mode 100644 contrib/ffmpeg/libavcodec/aac_parser.c create mode 100644 contrib/ffmpeg/libavcodec/ac3_parser.c create mode 100644 contrib/ffmpeg/libavcodec/ac3_parser.h create mode 100644 contrib/ffmpeg/libavcodec/ac3dec.c create mode 100644 contrib/ffmpeg/libavcodec/ac3tab.c delete mode 100644 contrib/ffmpeg/libavcodec/adx.c create mode 100644 contrib/ffmpeg/libavcodec/adx.h create mode 100644 contrib/ffmpeg/libavcodec/adxdec.c create mode 100644 contrib/ffmpeg/libavcodec/adxenc.c delete mode 100644 contrib/ffmpeg/libavcodec/amr.c create mode 100644 contrib/ffmpeg/libavcodec/apedec.c create mode 100644 contrib/ffmpeg/libavcodec/atrac3.c create mode 100644 contrib/ffmpeg/libavcodec/atrac3data.h create mode 100644 contrib/ffmpeg/libavcodec/bethsoftvideo.c create mode 100644 contrib/ffmpeg/libavcodec/bethsoftvideo.h create mode 100644 contrib/ffmpeg/libavcodec/bfin/dsputil_bfin.h create mode 100644 contrib/ffmpeg/libavcodec/bfin/mathops.h create mode 100644 contrib/ffmpeg/libavcodec/bfin/mpegvideo_bfin.c create mode 100644 contrib/ffmpeg/libavcodec/bfin/vp3_bfin.c create mode 100644 contrib/ffmpeg/libavcodec/bfin/vp3_idct_bfin.S create mode 100644 contrib/ffmpeg/libavcodec/c93.c create mode 100644 contrib/ffmpeg/libavcodec/cavs.h create mode 100644 contrib/ffmpeg/libavcodec/cavs_parser.c create mode 100644 contrib/ffmpeg/libavcodec/cavsdec.c create mode 100644 contrib/ffmpeg/libavcodec/colorspace.h create mode 100644 contrib/ffmpeg/libavcodec/dca.h create mode 100644 contrib/ffmpeg/libavcodec/dca_parser.c create mode 100644 contrib/ffmpeg/libavcodec/dnxhddata.c create mode 100644 contrib/ffmpeg/libavcodec/dnxhdenc.c delete mode 100644 contrib/ffmpeg/libavcodec/dtsdec.c create mode 100644 contrib/ffmpeg/libavcodec/dump_extradata_bsf.c create mode 100644 contrib/ffmpeg/libavcodec/dvbsub_parser.c create mode 100644 contrib/ffmpeg/libavcodec/dvdsub_parser.c create mode 100644 contrib/ffmpeg/libavcodec/elbg.c create mode 100644 contrib/ffmpeg/libavcodec/elbg.h delete mode 100644 contrib/ffmpeg/libavcodec/faac.c delete mode 100644 contrib/ffmpeg/libavcodec/faad.c create mode 100644 contrib/ffmpeg/libavcodec/faanidct.c create mode 100644 contrib/ffmpeg/libavcodec/faanidct.h create mode 100644 contrib/ffmpeg/libavcodec/h261.h create mode 100644 contrib/ffmpeg/libavcodec/h261_parser.c create mode 100644 contrib/ffmpeg/libavcodec/h261dec.c create mode 100644 contrib/ffmpeg/libavcodec/h261enc.c create mode 100644 contrib/ffmpeg/libavcodec/h263.h create mode 100644 contrib/ffmpeg/libavcodec/h263_parser.c create mode 100644 contrib/ffmpeg/libavcodec/h263_parser.h create mode 100644 contrib/ffmpeg/libavcodec/h264.h create mode 100644 contrib/ffmpeg/libavcodec/h264_mp4toannexb_bsf.c create mode 100644 contrib/ffmpeg/libavcodec/h264_parser.c create mode 100644 contrib/ffmpeg/libavcodec/h264_parser.h delete mode 100644 contrib/ffmpeg/libavcodec/h264dsp.c create mode 100644 contrib/ffmpeg/libavcodec/h264dspenc.c create mode 100644 contrib/ffmpeg/libavcodec/h264pred.c create mode 100644 contrib/ffmpeg/libavcodec/h264pred.h create mode 100644 contrib/ffmpeg/libavcodec/huffman.c create mode 100644 contrib/ffmpeg/libavcodec/huffman.h create mode 100644 contrib/ffmpeg/libavcodec/i386/dsputil_mmx.h create mode 100644 contrib/ffmpeg/libavcodec/i386/dsputil_mmx_qns.h create mode 100644 contrib/ffmpeg/libavcodec/i386/dsputilenc_mmx.c create mode 100644 contrib/ffmpeg/libavcodec/i386/flacdsp_mmx.c create mode 100644 contrib/ffmpeg/libavcodec/i386/vc1dsp_mmx.c create mode 100644 contrib/ffmpeg/libavcodec/i386/vp3dsp_mmx.h create mode 100644 contrib/ffmpeg/libavcodec/i386/vp3dsp_sse2.h create mode 100644 contrib/ffmpeg/libavcodec/imgconvert.h create mode 100644 contrib/ffmpeg/libavcodec/imx_dump_header_bsf.c create mode 100644 contrib/ffmpeg/libavcodec/intrax8.c create mode 100644 contrib/ffmpeg/libavcodec/intrax8.h create mode 100644 contrib/ffmpeg/libavcodec/intrax8dsp.c create mode 100644 contrib/ffmpeg/libavcodec/intrax8huf.h delete mode 100644 contrib/ffmpeg/libavcodec/jpeg_ls.c create mode 100644 contrib/ffmpeg/libavcodec/jpegls.c create mode 100644 contrib/ffmpeg/libavcodec/jpegls.h create mode 100644 contrib/ffmpeg/libavcodec/jpeglsdec.c create mode 100644 contrib/ffmpeg/libavcodec/jpeglsdec.h create mode 100644 contrib/ffmpeg/libavcodec/jpeglsenc.c delete mode 100644 contrib/ffmpeg/libavcodec/lcl.c create mode 100644 contrib/ffmpeg/libavcodec/lcl.h create mode 100644 contrib/ffmpeg/libavcodec/lcldec.c create mode 100644 contrib/ffmpeg/libavcodec/lclenc.c create mode 100644 contrib/ffmpeg/libavcodec/liba52.c create mode 100644 contrib/ffmpeg/libavcodec/libamr.c create mode 100644 contrib/ffmpeg/libavcodec/libfaac.c create mode 100644 contrib/ffmpeg/libavcodec/libfaad.c create mode 100644 contrib/ffmpeg/libavcodec/libmp3lame.c create mode 100644 contrib/ffmpeg/libavcodec/libvorbis.c create mode 100644 contrib/ffmpeg/libavcodec/libx264.c create mode 100644 contrib/ffmpeg/libavcodec/libxvid_internal.h create mode 100644 contrib/ffmpeg/libavcodec/libxvid_rc.c create mode 100644 contrib/ffmpeg/libavcodec/libxvidff.c create mode 100644 contrib/ffmpeg/libavcodec/ljpegenc.c create mode 100644 contrib/ffmpeg/libavcodec/lzwenc.c create mode 100644 contrib/ffmpeg/libavcodec/mjpeg.h create mode 100644 contrib/ffmpeg/libavcodec/mjpeg_parser.c create mode 100644 contrib/ffmpeg/libavcodec/mjpega_dump_header_bsf.c create mode 100644 contrib/ffmpeg/libavcodec/mjpegbdec.c create mode 100644 contrib/ffmpeg/libavcodec/mjpegdec.c create mode 100644 contrib/ffmpeg/libavcodec/mjpegdec.h create mode 100644 contrib/ffmpeg/libavcodec/mjpegenc.c create mode 100644 contrib/ffmpeg/libavcodec/mjpegenc.h create mode 100644 contrib/ffmpeg/libavcodec/mlp_parser.c create mode 100644 contrib/ffmpeg/libavcodec/mlp_parser.h create mode 100644 contrib/ffmpeg/libavcodec/motion-test.c delete mode 100644 contrib/ffmpeg/libavcodec/motion_test.c create mode 100644 contrib/ffmpeg/libavcodec/movsub_bsf.c create mode 100644 contrib/ffmpeg/libavcodec/mp3_header_compress_bsf.c create mode 100644 contrib/ffmpeg/libavcodec/mp3_header_decompress_bsf.c delete mode 100644 contrib/ffmpeg/libavcodec/mp3lameaudio.c create mode 100644 contrib/ffmpeg/libavcodec/mpc.h create mode 100644 contrib/ffmpeg/libavcodec/mpc7.c create mode 100644 contrib/ffmpeg/libavcodec/mpc7data.h create mode 100644 contrib/ffmpeg/libavcodec/mpc8.c create mode 100644 contrib/ffmpeg/libavcodec/mpc8data.h create mode 100644 contrib/ffmpeg/libavcodec/mpc8huff.h create mode 100644 contrib/ffmpeg/libavcodec/mpeg12.h create mode 100644 contrib/ffmpeg/libavcodec/mpeg12data.c create mode 100644 contrib/ffmpeg/libavcodec/mpeg12decdata.h create mode 100644 contrib/ffmpeg/libavcodec/mpeg12enc.c create mode 100644 contrib/ffmpeg/libavcodec/mpeg4video_parser.c create mode 100644 contrib/ffmpeg/libavcodec/mpeg4video_parser.h create mode 100644 contrib/ffmpeg/libavcodec/mpegaudio_parser.c create mode 100644 contrib/ffmpeg/libavcodec/mpegaudiodata.c create mode 100644 contrib/ffmpeg/libavcodec/mpegaudiodata.h create mode 100644 contrib/ffmpeg/libavcodec/mpegaudiodecheader.c create mode 100644 contrib/ffmpeg/libavcodec/mpegaudiodecheader.h create mode 100644 contrib/ffmpeg/libavcodec/mpegaudioenc.c create mode 100644 contrib/ffmpeg/libavcodec/mpegvideo_common.h create mode 100644 contrib/ffmpeg/libavcodec/mpegvideo_enc.c create mode 100644 contrib/ffmpeg/libavcodec/mpegvideo_parser.c create mode 100644 contrib/ffmpeg/libavcodec/msmpeg4.h create mode 100644 contrib/ffmpeg/libavcodec/msmpeg4data.c create mode 100644 contrib/ffmpeg/libavcodec/nellymoserdec.c create mode 100644 contrib/ffmpeg/libavcodec/noise_bsf.c delete mode 100644 contrib/ffmpeg/libavcodec/oggvorbis.c create mode 100644 contrib/ffmpeg/libavcodec/pcx.c create mode 100644 contrib/ffmpeg/libavcodec/png.h create mode 100644 contrib/ffmpeg/libavcodec/pngdec.c create mode 100644 contrib/ffmpeg/libavcodec/pngenc.c create mode 100644 contrib/ffmpeg/libavcodec/pnm.h create mode 100644 contrib/ffmpeg/libavcodec/pnm_parser.c create mode 100644 contrib/ffmpeg/libavcodec/pnmenc.c create mode 100644 contrib/ffmpeg/libavcodec/ppc/check_altivec.c create mode 100644 contrib/ffmpeg/libavcodec/ppc/imgresample_altivec.c create mode 100644 contrib/ffmpeg/libavcodec/ppc/imgresample_altivec.h create mode 100644 contrib/ffmpeg/libavcodec/ppc/int_altivec.c delete mode 100644 contrib/ffmpeg/libavcodec/ppc/mpegvideo_ppc.c create mode 100644 contrib/ffmpeg/libavcodec/ppc/util_altivec.h create mode 100644 contrib/ffmpeg/libavcodec/ptx.c create mode 100644 contrib/ffmpeg/libavcodec/qtrleenc.c create mode 100644 contrib/ffmpeg/libavcodec/raw.h create mode 100644 contrib/ffmpeg/libavcodec/rawdec.c create mode 100644 contrib/ffmpeg/libavcodec/rawenc.c create mode 100644 contrib/ffmpeg/libavcodec/rectangle.h create mode 100644 contrib/ffmpeg/libavcodec/remove_extradata_bsf.c create mode 100644 contrib/ffmpeg/libavcodec/rle.c create mode 100644 contrib/ffmpeg/libavcodec/rle.h create mode 100644 contrib/ffmpeg/libavcodec/roqaudioenc.c create mode 100644 contrib/ffmpeg/libavcodec/roqvideo.h create mode 100644 contrib/ffmpeg/libavcodec/roqvideodec.c create mode 100644 contrib/ffmpeg/libavcodec/roqvideoenc.c create mode 100644 contrib/ffmpeg/libavcodec/rv30.c create mode 100644 contrib/ffmpeg/libavcodec/rv30data.h create mode 100644 contrib/ffmpeg/libavcodec/rv30dsp.c create mode 100644 contrib/ffmpeg/libavcodec/rv34.c create mode 100644 contrib/ffmpeg/libavcodec/rv34.h create mode 100644 contrib/ffmpeg/libavcodec/rv34data.h create mode 100644 contrib/ffmpeg/libavcodec/rv34vlc.h create mode 100644 contrib/ffmpeg/libavcodec/rv40.c create mode 100644 contrib/ffmpeg/libavcodec/rv40data.h create mode 100644 contrib/ffmpeg/libavcodec/rv40vlc2.h create mode 100644 contrib/ffmpeg/libavcodec/s3tc.c create mode 100644 contrib/ffmpeg/libavcodec/s3tc.h create mode 100644 contrib/ffmpeg/libavcodec/sgi.h create mode 100644 contrib/ffmpeg/libavcodec/sgidec.c create mode 100644 contrib/ffmpeg/libavcodec/sgienc.c create mode 100644 contrib/ffmpeg/libavcodec/sp5xdec.c create mode 100644 contrib/ffmpeg/libavcodec/sparc/simple_idct_vis.c create mode 100644 contrib/ffmpeg/libavcodec/sunrast.c create mode 100644 contrib/ffmpeg/libavcodec/svq1.h create mode 100644 contrib/ffmpeg/libavcodec/svq1dec.c create mode 100644 contrib/ffmpeg/libavcodec/svq1enc.c create mode 100644 contrib/ffmpeg/libavcodec/svq1enc_cb.h create mode 100644 contrib/ffmpeg/libavcodec/tiff.h create mode 100644 contrib/ffmpeg/libavcodec/tiffenc.c create mode 100644 contrib/ffmpeg/libavcodec/txd.c create mode 100644 contrib/ffmpeg/libavcodec/unary.h create mode 100644 contrib/ffmpeg/libavcodec/vb.c create mode 100644 contrib/ffmpeg/libavcodec/vc1.h create mode 100644 contrib/ffmpeg/libavcodec/vc1_parser.c create mode 100644 contrib/ffmpeg/libavcodec/vc1data.c create mode 100644 contrib/ffmpeg/libavcodec/vorbis_dec.c create mode 100644 contrib/ffmpeg/libavcodec/wmv2.h create mode 100644 contrib/ffmpeg/libavcodec/wmv2dec.c create mode 100644 contrib/ffmpeg/libavcodec/wmv2enc.c delete mode 100644 contrib/ffmpeg/libavcodec/x264.c create mode 100644 contrib/ffmpeg/libavcodec/xsubdec.c delete mode 100644 contrib/ffmpeg/libavcodec/xvid_internal.h delete mode 100644 contrib/ffmpeg/libavcodec/xvid_rc.c delete mode 100644 contrib/ffmpeg/libavcodec/xvidff.c create mode 100644 contrib/ffmpeg/libavdevice/alldevices.c create mode 100644 contrib/ffmpeg/libavdevice/audio.c create mode 100644 contrib/ffmpeg/libavdevice/avdevice.h create mode 100644 contrib/ffmpeg/libavdevice/beosaudio.cpp create mode 100644 contrib/ffmpeg/libavdevice/bktr.c create mode 100644 contrib/ffmpeg/libavdevice/dv1394.c create mode 100644 contrib/ffmpeg/libavdevice/dv1394.h create mode 100644 contrib/ffmpeg/libavdevice/libdc1394.c create mode 100644 contrib/ffmpeg/libavdevice/v4l.c create mode 100644 contrib/ffmpeg/libavdevice/v4l2.c create mode 100644 contrib/ffmpeg/libavdevice/x11grab.c create mode 100644 contrib/ffmpeg/libavfilter/allfilters.c create mode 100644 contrib/ffmpeg/libavfilter/avfilter.c create mode 100644 contrib/ffmpeg/libavfilter/avfilter.h create mode 100644 contrib/ffmpeg/libavfilter/defaults.c create mode 100644 contrib/ffmpeg/libavfilter/formats.c delete mode 100644 contrib/ffmpeg/libavformat/allformats.h create mode 100644 contrib/ffmpeg/libavformat/apc.c create mode 100644 contrib/ffmpeg/libavformat/ape.c create mode 100644 contrib/ffmpeg/libavformat/asfcrypt.c create mode 100644 contrib/ffmpeg/libavformat/asfcrypt.h delete mode 100644 contrib/ffmpeg/libavformat/audio.c create mode 100644 contrib/ffmpeg/libavformat/avc.c create mode 100644 contrib/ffmpeg/libavformat/avc.h delete mode 100644 contrib/ffmpeg/libavformat/beosaudio.cpp create mode 100644 contrib/ffmpeg/libavformat/bethsoftvid.c create mode 100644 contrib/ffmpeg/libavformat/c93.c delete mode 100644 contrib/ffmpeg/libavformat/crc.c create mode 100644 contrib/ffmpeg/libavformat/crcenc.c delete mode 100644 contrib/ffmpeg/libavformat/dc1394.c delete mode 100644 contrib/ffmpeg/libavformat/dv1394.c delete mode 100644 contrib/ffmpeg/libavformat/dv1394.h create mode 100644 contrib/ffmpeg/libavformat/eacdata.c create mode 100644 contrib/ffmpeg/libavformat/framecrcenc.c delete mode 100644 contrib/ffmpeg/libavformat/grab.c delete mode 100644 contrib/ffmpeg/libavformat/grab_bktr.c create mode 100644 contrib/ffmpeg/libavformat/lmlm4.c create mode 100644 contrib/ffmpeg/libavformat/matroska.h create mode 100644 contrib/ffmpeg/libavformat/matroskadec.c create mode 100644 contrib/ffmpeg/libavformat/matroskaenc.c create mode 100644 contrib/ffmpeg/libavformat/mpc8.c create mode 100644 contrib/ffmpeg/libavformat/mpeg.h create mode 100644 contrib/ffmpeg/libavformat/mpegenc.c create mode 100644 contrib/ffmpeg/libavformat/nutenc.c delete mode 100644 contrib/ffmpeg/libavformat/ogg.c delete mode 100644 contrib/ffmpeg/libavformat/ogg2.c delete mode 100644 contrib/ffmpeg/libavformat/ogg2.h create mode 100644 contrib/ffmpeg/libavformat/oggdec.c create mode 100644 contrib/ffmpeg/libavformat/oggdec.h create mode 100644 contrib/ffmpeg/libavformat/oggenc.c create mode 100644 contrib/ffmpeg/libavformat/oggparsespeex.c create mode 100644 contrib/ffmpeg/libavformat/pva.c create mode 100644 contrib/ffmpeg/libavformat/raw.h delete mode 100644 contrib/ffmpeg/libavformat/rm.c create mode 100644 contrib/ffmpeg/libavformat/rm.h create mode 100644 contrib/ffmpeg/libavformat/rmdec.c create mode 100644 contrib/ffmpeg/libavformat/rmenc.c create mode 100644 contrib/ffmpeg/libavformat/rtp_aac.c create mode 100644 contrib/ffmpeg/libavformat/rtp_aac.h create mode 100644 contrib/ffmpeg/libavformat/rtp_mpv.c create mode 100644 contrib/ffmpeg/libavformat/rtp_mpv.h create mode 100644 contrib/ffmpeg/libavformat/rtpdec.c create mode 100644 contrib/ffmpeg/libavformat/rtpenc.c create mode 100644 contrib/ffmpeg/libavformat/rtpenc_h264.c create mode 100644 contrib/ffmpeg/libavformat/sdp.c create mode 100644 contrib/ffmpeg/libavformat/siff.c create mode 100644 contrib/ffmpeg/libavformat/txd.c delete mode 100644 contrib/ffmpeg/libavformat/v4l2.c create mode 100644 contrib/ffmpeg/libavformat/vc1test.c delete mode 100644 contrib/ffmpeg/libavformat/x11grab.c create mode 100644 contrib/ffmpeg/libavutil/avstring.h create mode 100644 contrib/ffmpeg/libavutil/crc_data.h create mode 100644 contrib/ffmpeg/libavutil/des.c create mode 100644 contrib/ffmpeg/libavutil/des.h create mode 100644 contrib/ffmpeg/libavutil/rc4.c create mode 100644 contrib/ffmpeg/libavutil/rc4.h create mode 100644 contrib/ffmpeg/libavutil/string.c delete mode 100644 contrib/ffmpeg/libpostproc/mangle.h create mode 100644 contrib/ffmpeg/libswscale/internal_bfin.S create mode 100644 contrib/ffmpeg/libswscale/swscale_bfin.c create mode 100644 contrib/ffmpeg/libswscale/yuv2rgb_bfin.c delete mode 100644 contrib/ffmpeg/libswscale/yuv2rgb_init.c create mode 100644 contrib/ffmpeg/libswscale/yuv2rgb_vis.c delete mode 100644 contrib/ffmpeg/pktdumper.c delete mode 100644 contrib/ffmpeg/qt-faststart.c delete mode 100644 contrib/ffmpeg/tests/Makefile delete mode 100644 contrib/ffmpeg/tests/dsptest.c create mode 100644 contrib/ffmpeg/tests/seek.regression.ref create mode 100755 contrib/ffmpeg/tools/build_avopt create mode 100755 contrib/ffmpeg/tools/clean-diff create mode 100644 contrib/ffmpeg/tools/cws2fws.c create mode 100644 contrib/ffmpeg/tools/pktdumper.c create mode 100644 contrib/ffmpeg/tools/qt-faststart.c create mode 100644 contrib/ffmpeg/tools/trasher.c create mode 100755 contrib/ffmpeg/tools/unwrap-diff delete mode 100755 contrib/ffmpeg/unwrap-diff delete mode 100644 contrib/ffmpeg/vhook/Makefile diff --git a/contrib/ffmpeg-distfiles b/contrib/ffmpeg-distfiles index 28735bc3c..ca16d6b6c 100644 --- a/contrib/ffmpeg-distfiles +++ b/contrib/ffmpeg-distfiles @@ -1,57 +1,39 @@ ffmpeg +ffmpeg/configure +ffmpeg/Doxyfile +ffmpeg/ffmpeg.c ffmpeg/vhook ffmpeg/vhook/imlib2.c ffmpeg/vhook/drawtext.c ffmpeg/vhook/fish.c ffmpeg/vhook/null.c -ffmpeg/vhook/Makefile ffmpeg/vhook/ppm.c ffmpeg/vhook/watermark.c -ffmpeg/libavutil -ffmpeg/libavutil/lls.h -ffmpeg/libavutil/mathematics.c -ffmpeg/libavutil/adler32.h -ffmpeg/libavutil/x86_cpu.h -ffmpeg/libavutil/integer.h -ffmpeg/libavutil/mathematics.h -ffmpeg/libavutil/crc.c -ffmpeg/libavutil/avutil.h -ffmpeg/libavutil/rational.c -ffmpeg/libavutil/crc.h -ffmpeg/libavutil/mem.c -ffmpeg/libavutil/rational.h -ffmpeg/libavutil/log.c -ffmpeg/libavutil/internal.h -ffmpeg/libavutil/bswap.h -ffmpeg/libavutil/md5.c -ffmpeg/libavutil/intfloat_readwrite.c -ffmpeg/libavutil/log.h -ffmpeg/libavutil/lls.c -ffmpeg/libavutil/md5.h -ffmpeg/libavutil/intfloat_readwrite.h -ffmpeg/libavutil/adler32.c -ffmpeg/libavutil/Makefile -ffmpeg/libavutil/integer.c -ffmpeg/libavutil/common.h -ffmpeg/libavutil/softfloat.c -ffmpeg/libavutil/softfloat.h -ffmpeg/libavutil/fifo.c -ffmpeg/libavutil/fifo.h -ffmpeg/libavutil/tree.c -ffmpeg/libavutil/tree.h -ffmpeg/libavutil/intreadwrite.h -ffmpeg/libavutil/aes.c -ffmpeg/libavutil/aes.h -ffmpeg/libavutil/lzo.c -ffmpeg/libavutil/lzo.h -ffmpeg/libavutil/random.c -ffmpeg/libavutil/base64.c -ffmpeg/libavutil/random.h -ffmpeg/libavutil/base64.h -ffmpeg/libavutil/sha1.h -ffmpeg/libavutil/mem.h -ffmpeg/libavutil/sha1.c +ffmpeg/Changelog +ffmpeg/COPYING.GPL ffmpeg/libavcodec +ffmpeg/libavcodec/h261data.h +ffmpeg/libavcodec/rv34.c +ffmpeg/libavcodec/mdct.c +ffmpeg/libavcodec/imcdata.h +ffmpeg/libavcodec/dxa.c +ffmpeg/libavcodec/dvbsubdec.c +ffmpeg/libavcodec/kmvc.c +ffmpeg/libavcodec/smc.c +ffmpeg/libavcodec/mjpeg.c +ffmpeg/libavcodec/huffman.h +ffmpeg/libavcodec/error_resilience.c +ffmpeg/libavcodec/dvdsub_parser.c +ffmpeg/libavcodec/adxdec.c +ffmpeg/libavcodec/h261_parser.c +ffmpeg/libavcodec/sh4 +ffmpeg/libavcodec/sh4/dsputil_align.c +ffmpeg/libavcodec/sh4/idct_sh4.c +ffmpeg/libavcodec/sh4/qpel.c +ffmpeg/libavcodec/sh4/dsputil_sh4.c +ffmpeg/libavcodec/dvdsubdec.c +ffmpeg/libavcodec/pcx.c +ffmpeg/libavcodec/rv34.h ffmpeg/libavcodec/alpha ffmpeg/libavcodec/alpha/regdef.h ffmpeg/libavcodec/alpha/simple_idct_alpha.c @@ -61,528 +43,768 @@ ffmpeg/libavcodec/alpha/motion_est_alpha.c ffmpeg/libavcodec/alpha/dsputil_alpha.c ffmpeg/libavcodec/alpha/dsputil_alpha_asm.S ffmpeg/libavcodec/alpha/motion_est_mvi_asm.S +ffmpeg/libavcodec/h264.c +ffmpeg/libavcodec/nellymoserdec.c +ffmpeg/libavcodec/mpc7data.h +ffmpeg/libavcodec/intrax8huf.h +ffmpeg/libavcodec/ac3tab.h +ffmpeg/libavcodec/raw.c +ffmpeg/libavcodec/mjpeg.h +ffmpeg/libavcodec/indeo3.c +ffmpeg/libavcodec/png.c +ffmpeg/libavcodec/mpc.c +ffmpeg/libavcodec/vp3data.h +ffmpeg/libavcodec/w32thread.c +ffmpeg/libavcodec/flacenc.c +ffmpeg/libavcodec/nuv.c +ffmpeg/libavcodec/parser.c +ffmpeg/libavcodec/cavsdec.c +ffmpeg/libavcodec/golomb.h +ffmpeg/libavcodec/roqaudioenc.c +ffmpeg/libavcodec/flicvideo.c +ffmpeg/libavcodec/ratecontrol.c +ffmpeg/libavcodec/vcr1.c +ffmpeg/libavcodec/rv10.c +ffmpeg/libavcodec/interplayvideo.c +ffmpeg/libavcodec/libxvidff.c +ffmpeg/libavcodec/c93.c +ffmpeg/libavcodec/atrac3.c +ffmpeg/libavcodec/cavsdata.h +ffmpeg/libavcodec/utils.c +ffmpeg/libavcodec/mpc.h +ffmpeg/libavcodec/vqavideo.c +ffmpeg/libavcodec/h263.c +ffmpeg/libavcodec/apiexample.c +ffmpeg/libavcodec/indeo2.c +ffmpeg/libavcodec/remove_extradata_bsf.c +ffmpeg/libavcodec/dca.c +ffmpeg/libavcodec/libfaad.c +ffmpeg/libavcodec/tiff.h +ffmpeg/libavcodec/ac3dec.c +ffmpeg/libavcodec/h263.h +ffmpeg/libavcodec/h264.h +ffmpeg/libavcodec/smacker.c +ffmpeg/libavcodec/parser.h +ffmpeg/libavcodec/qtrle.c +ffmpeg/libavcodec/h263_parser.c +ffmpeg/libavcodec/aac_ac3_parser.c ffmpeg/libavcodec/sparc ffmpeg/libavcodec/sparc/dsputil_vis.c ffmpeg/libavcodec/sparc/vis.h +ffmpeg/libavcodec/sparc/simple_idct_vis.c +ffmpeg/libavcodec/faanidct.c +ffmpeg/libavcodec/vp56.c +ffmpeg/libavcodec/pnm.c +ffmpeg/libavcodec/wma.h +ffmpeg/libavcodec/asv1.c +ffmpeg/libavcodec/raw.h +ffmpeg/libavcodec/cookdata.h +ffmpeg/libavcodec/mpegaudio.c +ffmpeg/libavcodec/colorspace.h +ffmpeg/libavcodec/cljr.c +ffmpeg/libavcodec/bethsoftvideo.c +ffmpeg/libavcodec/png.h +ffmpeg/libavcodec/dca.h +ffmpeg/libavcodec/libvorbis.c +ffmpeg/libavcodec/wma.c +ffmpeg/libavcodec/mpegaudiodec.c +ffmpeg/libavcodec/h263_parser.h +ffmpeg/libavcodec/aac_ac3_parser.h +ffmpeg/libavcodec/os2thread.c +ffmpeg/libavcodec/dnxhdenc.c +ffmpeg/libavcodec/ratecontrol.h +ffmpeg/libavcodec/intrax8.c +ffmpeg/libavcodec/mpegaudiodata.h +ffmpeg/libavcodec/Makefile +ffmpeg/libavcodec/h264pred.c +ffmpeg/libavcodec/faanidct.h +ffmpeg/libavcodec/vp56.h +ffmpeg/libavcodec/pnm.h +ffmpeg/libavcodec/mjpeg_parser.c +ffmpeg/libavcodec/rl.h +ffmpeg/libavcodec/opt.c +ffmpeg/libavcodec/bmpenc.c +ffmpeg/libavcodec/intrax8.h +ffmpeg/libavcodec/snow.c +ffmpeg/libavcodec/fft-test.c +ffmpeg/libavcodec/adxenc.c +ffmpeg/libavcodec/rawdec.c +ffmpeg/libavcodec/unary.h +ffmpeg/libavcodec/bfin +ffmpeg/libavcodec/bfin/fdct_bfin.S +ffmpeg/libavcodec/bfin/mathops.h +ffmpeg/libavcodec/bfin/idct_bfin.S +ffmpeg/libavcodec/bfin/dsputil_bfin.c +ffmpeg/libavcodec/bfin/pixels_bfin.S +ffmpeg/libavcodec/bfin/vp3_bfin.c +ffmpeg/libavcodec/bfin/dsputil_bfin.h +ffmpeg/libavcodec/bfin/config_bfin.h +ffmpeg/libavcodec/bfin/vp3_idct_bfin.S +ffmpeg/libavcodec/bfin/mpegvideo_bfin.c +ffmpeg/libavcodec/qdm2data.h +ffmpeg/libavcodec/vc1_parser.c +ffmpeg/libavcodec/cavs_parser.c +ffmpeg/libavcodec/avs.c +ffmpeg/libavcodec/h264pred.h +ffmpeg/libavcodec/jfdctfst.c +ffmpeg/libavcodec/truespeech.c +ffmpeg/libavcodec/vp3.c +ffmpeg/libavcodec/svq1_vlc.h +ffmpeg/libavcodec/ulti_cb.h +ffmpeg/libavcodec/roqvideodec.c +ffmpeg/libavcodec/opt.h ffmpeg/libavcodec/i386 ffmpeg/libavcodec/i386/idct_mmx_xvid.c ffmpeg/libavcodec/i386/mpegvideo_mmx.c ffmpeg/libavcodec/i386/vp3dsp_mmx.c -ffmpeg/libavcodec/i386/motion_est_mmx.c ffmpeg/libavcodec/i386/fdct_mmx.c +ffmpeg/libavcodec/i386/motion_est_mmx.c ffmpeg/libavcodec/i386/dsputil_h264_template_mmx.c ffmpeg/libavcodec/i386/idct_mmx.c ffmpeg/libavcodec/i386/fft_3dn2.c ffmpeg/libavcodec/i386/dsputil_mmx.c +ffmpeg/libavcodec/i386/vp3dsp_mmx.h ffmpeg/libavcodec/i386/mmx.h ffmpeg/libavcodec/i386/dsputil_mmx_avg.h +ffmpeg/libavcodec/i386/dsputil_mmx.h ffmpeg/libavcodec/i386/h264dsp_mmx.c ffmpeg/libavcodec/i386/vp3dsp_sse2.c ffmpeg/libavcodec/i386/dsputil_mmx_rnd.h ffmpeg/libavcodec/i386/simple_idct_mmx.c ffmpeg/libavcodec/i386/snowdsp_mmx.c +ffmpeg/libavcodec/i386/mathops.h +ffmpeg/libavcodec/i386/vp3dsp_sse2.h +ffmpeg/libavcodec/i386/vc1dsp_mmx.c ffmpeg/libavcodec/i386/fft_3dn.c +ffmpeg/libavcodec/i386/cavsdsp_mmx.c ffmpeg/libavcodec/i386/cputest.c ffmpeg/libavcodec/i386/fft_sse.c +ffmpeg/libavcodec/i386/dsputilenc_mmx.c +ffmpeg/libavcodec/i386/dsputil_mmx_qns.h ffmpeg/libavcodec/i386/mpegvideo_mmx_template.c -ffmpeg/libavcodec/i386/mathops.h -ffmpeg/libavcodec/i386/cavsdsp_mmx.c +ffmpeg/libavcodec/i386/flacdsp_mmx.c +ffmpeg/libavcodec/mlp_parser.h +ffmpeg/libavcodec/msmpeg4.h +ffmpeg/libavcodec/ptx.c +ffmpeg/libavcodec/resample.c +ffmpeg/libavcodec/mpegaudio.h +ffmpeg/libavcodec/noise_bsf.c +ffmpeg/libavcodec/dv.c +ffmpeg/libavcodec/rle.h +ffmpeg/libavcodec/msmpeg4.c +ffmpeg/libavcodec/lzw.c +ffmpeg/libavcodec/pngenc.c +ffmpeg/libavcodec/bethsoftvideo.h +ffmpeg/libavcodec/jrevdct.c +ffmpeg/libavcodec/idcinvideo.c +ffmpeg/libavcodec/zmbvenc.c +ffmpeg/libavcodec/cavsdsp.c +ffmpeg/libavcodec/rawenc.c +ffmpeg/libavcodec/mpegvideo_common.h +ffmpeg/libavcodec/dnxhddec.c +ffmpeg/libavcodec/vp6data.h +ffmpeg/libavcodec/8bps.c +ffmpeg/libavcodec/lzw.h +ffmpeg/libavcodec/h263data.h +ffmpeg/libavcodec/h264dspenc.c +ffmpeg/libavcodec/golomb.c +ffmpeg/libavcodec/xl.c +ffmpeg/libavcodec/motion-test.c +ffmpeg/libavcodec/snow.h +ffmpeg/libavcodec/mpegvideo_enc.c +ffmpeg/libavcodec/huffman.c +ffmpeg/libavcodec/rv40vlc2.h +ffmpeg/libavcodec/qpeg.c +ffmpeg/libavcodec/ac3tab.c +ffmpeg/libavcodec/mdec.c +ffmpeg/libavcodec/pngdec.c +ffmpeg/libavcodec/motion_est.c +ffmpeg/libavcodec/tiertexseqv.c ffmpeg/libavcodec/ppc ffmpeg/libavcodec/ppc/gcc_fixes.h ffmpeg/libavcodec/ppc/dsputil_altivec.h -ffmpeg/libavcodec/ppc/mpegvideo_ppc.c -ffmpeg/libavcodec/ppc/dsputil_ppc.c -ffmpeg/libavcodec/ppc/fft_altivec.c -ffmpeg/libavcodec/ppc/mpegvideo_altivec.c -ffmpeg/libavcodec/ppc/fdct_altivec.c -ffmpeg/libavcodec/ppc/idct_altivec.c -ffmpeg/libavcodec/ppc/dsputil_altivec.c -ffmpeg/libavcodec/ppc/dsputil_ppc.h -ffmpeg/libavcodec/ppc/gmc_altivec.c +ffmpeg/libavcodec/ppc/int_altivec.c ffmpeg/libavcodec/ppc/vc1dsp_altivec.c +ffmpeg/libavcodec/ppc/imgresample_altivec.c ffmpeg/libavcodec/ppc/float_altivec.c +ffmpeg/libavcodec/ppc/gmc_altivec.c ffmpeg/libavcodec/ppc/mathops.h +ffmpeg/libavcodec/ppc/types_altivec.h +ffmpeg/libavcodec/ppc/imgresample_altivec.h +ffmpeg/libavcodec/ppc/check_altivec.c ffmpeg/libavcodec/ppc/h264_template_altivec.c +ffmpeg/libavcodec/ppc/fft_altivec.c +ffmpeg/libavcodec/ppc/dsputil_ppc.c +ffmpeg/libavcodec/ppc/mpegvideo_altivec.c +ffmpeg/libavcodec/ppc/fdct_altivec.c +ffmpeg/libavcodec/ppc/util_altivec.h +ffmpeg/libavcodec/ppc/idct_altivec.c ffmpeg/libavcodec/ppc/h264_altivec.c +ffmpeg/libavcodec/ppc/dsputil_ppc.h +ffmpeg/libavcodec/ppc/dsputil_altivec.c ffmpeg/libavcodec/ppc/snow_altivec.c -ffmpeg/libavcodec/ppc/types_altivec.h -ffmpeg/libavcodec/ps2 -ffmpeg/libavcodec/ps2/mpegvideo_mmi.c -ffmpeg/libavcodec/ps2/idct_mmi.c -ffmpeg/libavcodec/ps2/dsputil_mmi.c -ffmpeg/libavcodec/ps2/mmi.h -ffmpeg/libavcodec/dcadata.h +ffmpeg/libavcodec/mpegaudioenc.c +ffmpeg/libavcodec/flac.c +ffmpeg/libavcodec/vmnc.c +ffmpeg/libavcodec/rle.c +ffmpeg/libavcodec/xvmc_render.h +ffmpeg/libavcodec/mpc7.c +ffmpeg/libavcodec/mpegaudiodata.c +ffmpeg/libavcodec/mpegaudiotab.h +ffmpeg/libavcodec/mlp_parser.c +ffmpeg/libavcodec/roqvideoenc.c +ffmpeg/libavcodec/xvmcvideo.c ffmpeg/libavcodec/mlib ffmpeg/libavcodec/mlib/dsputil_mlib.c -ffmpeg/libavcodec/sh4 -ffmpeg/libavcodec/sh4/dsputil_align.c -ffmpeg/libavcodec/sh4/idct_sh4.c -ffmpeg/libavcodec/sh4/qpel.c -ffmpeg/libavcodec/sh4/dsputil_sh4.c +ffmpeg/libavcodec/tiff.c +ffmpeg/libavcodec/mathops.h +ffmpeg/libavcodec/ac3.h +ffmpeg/libavcodec/dump_extradata_bsf.c +ffmpeg/libavcodec/pnm_parser.c +ffmpeg/libavcodec/svq1dec.c +ffmpeg/libavcodec/allcodecs.c +ffmpeg/libavcodec/libxvid_internal.h +ffmpeg/libavcodec/dsputil.h +ffmpeg/libavcodec/audioconvert.c +ffmpeg/libavcodec/dvdata.h +ffmpeg/libavcodec/sgienc.c +ffmpeg/libavcodec/apedec.c +ffmpeg/libavcodec/rtjpeg.c +ffmpeg/libavcodec/cinepak.c +ffmpeg/libavcodec/cavs.h +ffmpeg/libavcodec/elbg.c +ffmpeg/libavcodec/msrle.c +ffmpeg/libavcodec/simple_idct.c +ffmpeg/libavcodec/rangecoder.c +ffmpeg/libavcodec/dpcm.c ffmpeg/libavcodec/armv4l ffmpeg/libavcodec/armv4l/mpegvideo_arm.c +ffmpeg/libavcodec/armv4l/simple_idct_armv5te.S ffmpeg/libavcodec/armv4l/jrevdct_arm.S +ffmpeg/libavcodec/armv4l/mathops.h ffmpeg/libavcodec/armv4l/dsputil_iwmmxt_rnd.h +ffmpeg/libavcodec/armv4l/mpegvideo_armv5te.c ffmpeg/libavcodec/armv4l/dsputil_arm.c ffmpeg/libavcodec/armv4l/mpegvideo_iwmmxt.c ffmpeg/libavcodec/armv4l/dsputil_arm_s.S +ffmpeg/libavcodec/armv4l/simple_idct_armv6.S ffmpeg/libavcodec/armv4l/dsputil_iwmmxt.c ffmpeg/libavcodec/armv4l/simple_idct_arm.S -ffmpeg/libavcodec/armv4l/simple_idct_armv5te.S -ffmpeg/libavcodec/armv4l/mathops.h -ffmpeg/libavcodec/armv4l/mpegvideo_armv5te.c -ffmpeg/libavcodec/armv4l/simple_idct_armv6.S +ffmpeg/libavcodec/imx_dump_header_bsf.c +ffmpeg/libavcodec/wmv2.c +ffmpeg/libavcodec/mjpegenc.c +ffmpeg/libavcodec/vc1acdata.h +ffmpeg/libavcodec/rv30data.h +ffmpeg/libavcodec/svq1.h +ffmpeg/libavcodec/vp5data.h +ffmpeg/libavcodec/ra144.c +ffmpeg/libavcodec/rpza.c +ffmpeg/libavcodec/xsubdec.c +ffmpeg/libavcodec/ws-snd1.c +ffmpeg/libavcodec/dnxhddata.c +ffmpeg/libavcodec/mjpegenc.h +ffmpeg/libavcodec/dcadata.h +ffmpeg/libavcodec/bmp.c +ffmpeg/libavcodec/xiph.h +ffmpeg/libavcodec/vorbis_data.c +ffmpeg/libavcodec/elbg.h +ffmpeg/libavcodec/sgidec.c ffmpeg/libavcodec/mmvideo.c -ffmpeg/libavcodec/dvbsubdec.c -ffmpeg/libavcodec/msmpeg4.c -ffmpeg/libavcodec/mjpeg.c -ffmpeg/libavcodec/8bps.c -ffmpeg/libavcodec/ffv1.c -ffmpeg/libavcodec/adx.c -ffmpeg/libavcodec/flashsv.c ffmpeg/libavcodec/rangecoder.h -ffmpeg/libavcodec/vp3data.h -ffmpeg/libavcodec/golomb.c -ffmpeg/libavcodec/nuv.c -ffmpeg/libavcodec/h264.c -ffmpeg/libavcodec/vcr1.c -ffmpeg/libavcodec/kmvc.c -ffmpeg/libavcodec/vqavideo.c -ffmpeg/libavcodec/golomb.h -ffmpeg/libavcodec/zmbv.c -ffmpeg/libavcodec/png.c -ffmpeg/libavcodec/indeo2.c +ffmpeg/libavcodec/ra144.h +ffmpeg/libavcodec/mpc8data.h +ffmpeg/libavcodec/ac3_parser.c +ffmpeg/libavcodec/mace.c ffmpeg/libavcodec/simple_idct.h -ffmpeg/libavcodec/mpegaudiodectab.h -ffmpeg/libavcodec/apiexample.c -ffmpeg/libavcodec/wma.c +ffmpeg/libavcodec/adx.h +ffmpeg/libavcodec/aasc.c +ffmpeg/libavcodec/mpeg12.h +ffmpeg/libavcodec/s3tc.h +ffmpeg/libavcodec/lcl.h +ffmpeg/libavcodec/mpeg4data.h +ffmpeg/libavcodec/msmpeg4data.c +ffmpeg/libavcodec/mpeg12data.c +ffmpeg/libavcodec/ulti.c +ffmpeg/libavcodec/atrac3data.h +ffmpeg/libavcodec/libmp3lame.c +ffmpeg/libavcodec/vmdav.c +ffmpeg/libavcodec/truemotion1.c +ffmpeg/libavcodec/mpeg12enc.c +ffmpeg/libavcodec/vc1.c +ffmpeg/libavcodec/mjpegdec.c +ffmpeg/libavcodec/cabac.c +ffmpeg/libavcodec/bmp.h +ffmpeg/libavcodec/lcldec.c +ffmpeg/libavcodec/indeo2data.h +ffmpeg/libavcodec/mpeg4video_parser.c +ffmpeg/libavcodec/ac3_parser.h +ffmpeg/libavcodec/vp3dsp.c +ffmpeg/libavcodec/mjpega_dump_header_bsf.c ffmpeg/libavcodec/roqvideo.c -ffmpeg/libavcodec/jpeg_ls.c +ffmpeg/libavcodec/mjpegbdec.c +ffmpeg/libavcodec/libx264.c +ffmpeg/libavcodec/eval.h +ffmpeg/libavcodec/vc1.h +ffmpeg/libavcodec/h264data.h +ffmpeg/libavcodec/rv30dsp.c +ffmpeg/libavcodec/mjpegdec.h ffmpeg/libavcodec/mpeg12data.h +ffmpeg/libavcodec/rv30.c +ffmpeg/libavcodec/svq1enc.c +ffmpeg/libavcodec/mpeg4video_parser.h +ffmpeg/libavcodec/vp56data.c +ffmpeg/libavcodec/mpegvideo_parser.c +ffmpeg/libavcodec/mpeg12.c +ffmpeg/libavcodec/jpegls.c +ffmpeg/libavcodec/fft.c +ffmpeg/libavcodec/dvbsub_parser.c +ffmpeg/libavcodec/rectangle.h +ffmpeg/libavcodec/roqvideo.h +ffmpeg/libavcodec/ffv1.c +ffmpeg/libavcodec/txd.c +ffmpeg/libavcodec/flashsv.c +ffmpeg/libavcodec/vp56data.h +ffmpeg/libavcodec/mpc8.c +ffmpeg/libavcodec/cabac.h +ffmpeg/libavcodec/dsputil.c +ffmpeg/libavcodec/gif.c +ffmpeg/libavcodec/jpeglsenc.c +ffmpeg/libavcodec/msmpeg4data.h +ffmpeg/libavcodec/faandct.c +ffmpeg/libavcodec/zmbv.c +ffmpeg/libavcodec/targaenc.c +ffmpeg/libavcodec/fraps.c +ffmpeg/libavcodec/alac.c +ffmpeg/libavcodec/mpegaudiodectab.h +ffmpeg/libavcodec/rv40.c +ffmpeg/libavcodec/lclenc.c +ffmpeg/libavcodec/vc1data.c +ffmpeg/libavcodec/dct-test.c +ffmpeg/libavcodec/rtjpeg.h ffmpeg/libavcodec/wmadata.h -ffmpeg/libavcodec/os2thread.c -ffmpeg/libavcodec/smacker.c -ffmpeg/libavcodec/w32thread.c +ffmpeg/libavcodec/wmv2.h +ffmpeg/libavcodec/bytestream.h +ffmpeg/libavcodec/mpegvideo.h +ffmpeg/libavcodec/sp5xdec.c +ffmpeg/libavcodec/dca_parser.c ffmpeg/libavcodec/truemotion1data.h -ffmpeg/libavcodec/Makefile +ffmpeg/libavcodec/tta.c +ffmpeg/libavcodec/g726.c +ffmpeg/libavcodec/vb.c ffmpeg/libavcodec/vc1data.h -ffmpeg/libavcodec/fft-test.c -ffmpeg/libavcodec/avs.c -ffmpeg/libavcodec/alac.c -ffmpeg/libavcodec/cljr.c -ffmpeg/libavcodec/ac3tab.h -ffmpeg/libavcodec/cookdata.h -ffmpeg/libavcodec/faandct.c -ffmpeg/libavcodec/pnm.c -ffmpeg/libavcodec/simple_idct.c -ffmpeg/libavcodec/fft.c +ffmpeg/libavcodec/xan.c +ffmpeg/libavcodec/faandct.h ffmpeg/libavcodec/bitstream_filter.c -ffmpeg/libavcodec/oggvorbis.c -ffmpeg/libavcodec/opt.c -ffmpeg/libavcodec/flicvideo.c -ffmpeg/libavcodec/qdm2data.h -ffmpeg/libavcodec/mpegaudio.c -ffmpeg/libavcodec/svq1_vlc.h -ffmpeg/libavcodec/jrevdct.c -ffmpeg/libavcodec/wma.h -ffmpeg/libavcodec/cavsdsp.c -ffmpeg/libavcodec/opt.h -ffmpeg/libavcodec/allcodecs.c -ffmpeg/libavcodec/resample.c -ffmpeg/libavcodec/x264.c -ffmpeg/libavcodec/vp3.c ffmpeg/libavcodec/sp5x.h -ffmpeg/libavcodec/bmp.h -ffmpeg/libavcodec/faandct.h -ffmpeg/libavcodec/dv.c -ffmpeg/libavcodec/mdec.c +ffmpeg/libavcodec/sunrast.c +ffmpeg/libavcodec/h263dec.c +ffmpeg/libavcodec/eval.c +ffmpeg/libavcodec/vp6.c +ffmpeg/libavcodec/jpeglsdec.c +ffmpeg/libavcodec/ps2 +ffmpeg/libavcodec/ps2/mpegvideo_mmi.c +ffmpeg/libavcodec/ps2/idct_mmi.c +ffmpeg/libavcodec/ps2/dsputil_mmi.c +ffmpeg/libavcodec/ps2/mmi.h +ffmpeg/libavcodec/avcodec.h +ffmpeg/libavcodec/imc.c +ffmpeg/libavcodec/jpeglsdec.h +ffmpeg/libavcodec/svq1.c +ffmpeg/libavcodec/dnxhddata.h +ffmpeg/libavcodec/libamr.c +ffmpeg/libavcodec/ac3.c +ffmpeg/libavcodec/rv34vlc.h +ffmpeg/libavcodec/cscd.c +ffmpeg/libavcodec/imgconvert.c ffmpeg/libavcodec/sonic.c -ffmpeg/libavcodec/4xm.c +ffmpeg/libavcodec/truemotion2.c +ffmpeg/libavcodec/pcm.c +ffmpeg/libavcodec/mp3_header_compress_bsf.c +ffmpeg/libavcodec/cavs.c +ffmpeg/libavcodec/truespeech_data.h ffmpeg/libavcodec/libgsm.c -ffmpeg/libavcodec/dsputil.h -ffmpeg/libavcodec/idcinvideo.c -ffmpeg/libavcodec/avcodec.h +ffmpeg/libavcodec/s3tc.c +ffmpeg/libavcodec/4xm.c ffmpeg/libavcodec/qdrw.c -ffmpeg/libavcodec/error_resilience.c +ffmpeg/libavcodec/imgresample.c +ffmpeg/libavcodec/qtrleenc.c +ffmpeg/libavcodec/vp5.c +ffmpeg/libavcodec/mpcdata.h +ffmpeg/libavcodec/aac_parser.c +ffmpeg/libavcodec/jpegls.h +ffmpeg/libavcodec/sgi.h ffmpeg/libavcodec/mpegvideo.c -ffmpeg/libavcodec/faad.c -ffmpeg/libavcodec/h263data.h -ffmpeg/libavcodec/lcl.c -ffmpeg/libavcodec/shorten.c -ffmpeg/libavcodec/ac3.h -ffmpeg/libavcodec/xl.c -ffmpeg/libavcodec/rtjpeg.c -ffmpeg/libavcodec/mpegvideo.h -ffmpeg/libavcodec/wmv2.c -ffmpeg/libavcodec/truemotion1.c -ffmpeg/libavcodec/imgconvert.c -ffmpeg/libavcodec/mdct.c -ffmpeg/libavcodec/h261data.h -ffmpeg/libavcodec/dvdsubdec.c ffmpeg/libavcodec/indeo3data.h -ffmpeg/libavcodec/rv10.c -ffmpeg/libavcodec/bytestream.h -ffmpeg/libavcodec/cabac.c -ffmpeg/libavcodec/smc.c -ffmpeg/libavcodec/faac.c -ffmpeg/libavcodec/xvidff.c -ffmpeg/libavcodec/mpeg12.c -ffmpeg/libavcodec/vc1acdata.h -ffmpeg/libavcodec/cavsdata.h -ffmpeg/libavcodec/raw.c -ffmpeg/libavcodec/qpeg.c -ffmpeg/libavcodec/vc1.c -ffmpeg/libavcodec/h263dec.c +ffmpeg/libavcodec/shorten.c +ffmpeg/libavcodec/flashsvenc.c +ffmpeg/libavcodec/xiph.c +ffmpeg/libavcodec/motion_est_template.c +ffmpeg/libavcodec/imgconvert_template.h +ffmpeg/libavcodec/liba52.c +ffmpeg/libavcodec/wmv2enc.c +ffmpeg/libavcodec/imgconvert.h +ffmpeg/libavcodec/ljpegenc.c +ffmpeg/libavcodec/vorbis_enc.c +ffmpeg/libavcodec/mp3_header_decompress_bsf.c ffmpeg/libavcodec/bitstream.c -ffmpeg/libavcodec/cabac.h -ffmpeg/libavcodec/interplayvideo.c -ffmpeg/libavcodec/xvmcvideo.c -ffmpeg/libavcodec/rtjpeg.h -ffmpeg/libavcodec/jfdctfst.c +ffmpeg/libavcodec/rv40data.h ffmpeg/libavcodec/cook.c -ffmpeg/libavcodec/rpza.c -ffmpeg/libavcodec/utils.c -ffmpeg/libavcodec/motion_est.c -ffmpeg/libavcodec/flacenc.c -ffmpeg/libavcodec/indeo3.c ffmpeg/libavcodec/wnv1.c -ffmpeg/libavcodec/h263.c -ffmpeg/libavcodec/imgresample.c -ffmpeg/libavcodec/mpegaudiodec.c -ffmpeg/libavcodec/parser.c -ffmpeg/libavcodec/snow.c -ffmpeg/libavcodec/truespeech_data.h -ffmpeg/libavcodec/dct-test.c -ffmpeg/libavcodec/ratecontrol.c -ffmpeg/libavcodec/tta.c -ffmpeg/libavcodec/xvid_rc.c -ffmpeg/libavcodec/svq1.c +ffmpeg/libavcodec/gifdec.c +ffmpeg/libavcodec/mpegaudiodecheader.c +ffmpeg/libavcodec/libtheoraenc.c +ffmpeg/libavcodec/dvbsub.c ffmpeg/libavcodec/bitstream.h -ffmpeg/libavcodec/snow.h -ffmpeg/libavcodec/a52dec.c -ffmpeg/libavcodec/cavs.c -ffmpeg/libavcodec/asv1.c -ffmpeg/libavcodec/truespeech.c -ffmpeg/libavcodec/msmpeg4data.h +ffmpeg/libavcodec/dsicinav.c +ffmpeg/libavcodec/lzwenc.c ffmpeg/libavcodec/qdm2.c -ffmpeg/libavcodec/fraps.c ffmpeg/libavcodec/svq1_cb.h -ffmpeg/libavcodec/cscd.c +ffmpeg/libavcodec/mpegaudiodecheader.h +ffmpeg/libavcodec/intrax8dsp.c ffmpeg/libavcodec/vorbis.c -ffmpeg/libavcodec/bmp.c -ffmpeg/libavcodec/dvdata.h -ffmpeg/libavcodec/mpegaudio.h -ffmpeg/libavcodec/flac.c -ffmpeg/libavcodec/amr.c -ffmpeg/libavcodec/dtsdec.c -ffmpeg/libavcodec/dsputil.c -ffmpeg/libavcodec/lzw.c -ffmpeg/libavcodec/g726.c -ffmpeg/libavcodec/bfin -ffmpeg/libavcodec/bfin/dsputil_bfin.c -ffmpeg/libavcodec/bfin/fdct_bfin.S -ffmpeg/libavcodec/bfin/idct_bfin.S -ffmpeg/libavcodec/bfin/pixels_bfin.S -ffmpeg/libavcodec/bfin/config_bfin.h -ffmpeg/libavcodec/ulti_cb.h -ffmpeg/libavcodec/cinepak.c -ffmpeg/libavcodec/xan.c +ffmpeg/libavcodec/movsub_bsf.c +ffmpeg/libavcodec/dcahuff.h +ffmpeg/libavcodec/wmv2dec.c +ffmpeg/libavcodec/h264enc.c +ffmpeg/libavcodec/vorbis.h +ffmpeg/libavcodec/wmaenc.c ffmpeg/libavcodec/fdctref.c -ffmpeg/libavcodec/eval.c -ffmpeg/libavcodec/vmnc.c -ffmpeg/libavcodec/qtrle.c -ffmpeg/libavcodec/rangecoder.c -ffmpeg/libavcodec/truemotion2.c -ffmpeg/libavcodec/indeo2data.h -ffmpeg/libavcodec/pcm.c -ffmpeg/libavcodec/motion_est_template.c -ffmpeg/libavcodec/imgconvert_template.h -ffmpeg/libavcodec/mpegaudiotab.h -ffmpeg/libavcodec/mp3lameaudio.c +ffmpeg/libavcodec/tiffenc.c +ffmpeg/libavcodec/libxvid_rc.c +ffmpeg/libavcodec/vorbis_dec.c ffmpeg/libavcodec/h261.c -ffmpeg/libavcodec/msrle.c -ffmpeg/libavcodec/dpcm.c +ffmpeg/libavcodec/libfaac.c +ffmpeg/libavcodec/h261.h +ffmpeg/libavcodec/adpcm.c +ffmpeg/libavcodec/mpegaudio_parser.c ffmpeg/libavcodec/cyuv.c ffmpeg/libavcodec/pthread.c -ffmpeg/libavcodec/ra144.c +ffmpeg/libavcodec/msvideo1.c +ffmpeg/libavcodec/svq1enc_cb.h ffmpeg/libavcodec/loco.c ffmpeg/libavcodec/huffyuv.c ffmpeg/libavcodec/svq3.c ffmpeg/libavcodec/tscc.c -ffmpeg/libavcodec/ws-snd1.c -ffmpeg/libavcodec/ra144.h +ffmpeg/libavcodec/rv34data.h +ffmpeg/libavcodec/targa.c +ffmpeg/libavcodec/h264idct.c +ffmpeg/libavcodec/h264_parser.c +ffmpeg/libavcodec/vc1dsp.c ffmpeg/libavcodec/wmadec.c -ffmpeg/libavcodec/motion_test.c +ffmpeg/libavcodec/vorbis_enc_data.h +ffmpeg/libavcodec/h264_parser.h ffmpeg/libavcodec/ra288.c -ffmpeg/libavcodec/mace.c +ffmpeg/libavcodec/ac3enc.c ffmpeg/libavcodec/jfdctint.c -ffmpeg/libavcodec/aasc.c +ffmpeg/libavcodec/resample2.c +ffmpeg/libavcodec/mpeg12decdata.h +ffmpeg/libavcodec/h261enc.c ffmpeg/libavcodec/ra288.h -ffmpeg/libavcodec/mpeg4data.h +ffmpeg/libavcodec/h264_mp4toannexb_bsf.c ffmpeg/libavcodec/dvdsubenc.c -ffmpeg/libavcodec/ulti.c -ffmpeg/libavcodec/vmdav.c -ffmpeg/libavcodec/vp3dsp.c +ffmpeg/libavcodec/h261dec.c ffmpeg/libavcodec/beosthread.c -ffmpeg/libavcodec/h264data.h -ffmpeg/libavcodec/adpcm.c -ffmpeg/libavcodec/dvbsub.c -ffmpeg/libavcodec/msvideo1.c -ffmpeg/libavcodec/h264idct.c -ffmpeg/libavcodec/resample2.c -ffmpeg/libavcodec/ac3enc.c -ffmpeg/libavcodec/vp6data.h -ffmpeg/libavcodec/mathops.h -ffmpeg/libavcodec/eval.h -ffmpeg/libavcodec/vp5data.h -ffmpeg/libavcodec/vp56data.c -ffmpeg/libavcodec/vp56data.h -ffmpeg/libavcodec/vp5.c -ffmpeg/libavcodec/vorbis_enc.c -ffmpeg/libavcodec/vp56.c -ffmpeg/libavcodec/ratecontrol.h -ffmpeg/libavcodec/audioconvert.c -ffmpeg/libavcodec/vp56.h -ffmpeg/libavcodec/vorbis.h -ffmpeg/libavcodec/vorbis_data.c -ffmpeg/libavcodec/vc1dsp.c -ffmpeg/libavcodec/vp6.c -ffmpeg/libavcodec/vorbis_enc_data.h +ffmpeg/libavcodec/pnmenc.c +ffmpeg/libavcodec/mpc8huff.h ffmpeg/libavcodec/wavpack.c -ffmpeg/libavcodec/targa.c -ffmpeg/libavcodec/lzw.h -ffmpeg/libavcodec/xvid_internal.h -ffmpeg/libavcodec/imcdata.h -ffmpeg/libavcodec/tiertexseqv.c -ffmpeg/libavcodec/imc.c -ffmpeg/libavcodec/tiff.c -ffmpeg/libavcodec/dsicinav.c -ffmpeg/libavcodec/parser.h -ffmpeg/libavcodec/gif.c -ffmpeg/libavcodec/gifdec.c -ffmpeg/libavcodec/mpcdata.h -ffmpeg/libavcodec/zmbvenc.c -ffmpeg/libavcodec/h264dsp.c -ffmpeg/libavcodec/h264enc.c -ffmpeg/libavcodec/mpc.c -ffmpeg/libavcodec/flashsvenc.c -ffmpeg/libavcodec/xvmc_render.h -ffmpeg/libavcodec/libtheoraenc.c -ffmpeg/libavcodec/dca.c -ffmpeg/libavcodec/bmpenc.c -ffmpeg/libavcodec/dcahuff.h -ffmpeg/libavcodec/wmaenc.c -ffmpeg/libavcodec/targaenc.c -ffmpeg/libavcodec/ac3.c -ffmpeg/libavcodec/dxa.c -ffmpeg/libavcodec/rl.h -ffmpeg/libavcodec/dnxhddec.c -ffmpeg/libavcodec/dnxhddata.h -ffmpeg/libavcodec/xiph.c -ffmpeg/libavcodec/xiph.h +ffmpeg/libavutil +ffmpeg/libavutil/mathematics.c +ffmpeg/libavutil/adler32.h +ffmpeg/libavutil/sha1.h +ffmpeg/libavutil/x86_cpu.h +ffmpeg/libavutil/integer.h +ffmpeg/libavutil/avstring.h +ffmpeg/libavutil/mathematics.h +ffmpeg/libavutil/crc_data.h +ffmpeg/libavutil/string.c +ffmpeg/libavutil/crc.c +ffmpeg/libavutil/avutil.h +ffmpeg/libavutil/crc.h +ffmpeg/libavutil/md5.c +ffmpeg/libavutil/intfloat_readwrite.c +ffmpeg/libavutil/lls.c +ffmpeg/libavutil/md5.h +ffmpeg/libavutil/intfloat_readwrite.h +ffmpeg/libavutil/Makefile +ffmpeg/libavutil/lls.h +ffmpeg/libavutil/tree.c +ffmpeg/libavutil/softfloat.c +ffmpeg/libavutil/lzo.c +ffmpeg/libavutil/tree.h +ffmpeg/libavutil/intreadwrite.h +ffmpeg/libavutil/softfloat.h +ffmpeg/libavutil/aes.c +ffmpeg/libavutil/lzo.h +ffmpeg/libavutil/rational.c +ffmpeg/libavutil/des.c +ffmpeg/libavutil/aes.h +ffmpeg/libavutil/mem.c +ffmpeg/libavutil/rational.h +ffmpeg/libavutil/des.h +ffmpeg/libavutil/random.c +ffmpeg/libavutil/log.c +ffmpeg/libavutil/internal.h +ffmpeg/libavutil/bswap.h +ffmpeg/libavutil/fifo.c +ffmpeg/libavutil/mem.h +ffmpeg/libavutil/base64.c +ffmpeg/libavutil/random.h +ffmpeg/libavutil/log.h +ffmpeg/libavutil/fifo.h +ffmpeg/libavutil/rc4.c +ffmpeg/libavutil/base64.h +ffmpeg/libavutil/adler32.c +ffmpeg/libavutil/sha1.c +ffmpeg/libavutil/integer.c +ffmpeg/libavutil/common.h +ffmpeg/libavutil/rc4.h +ffmpeg/output_example.c +ffmpeg/README +ffmpeg/CREDITS +ffmpeg/version.sh +ffmpeg/common.mak ffmpeg/libpostproc ffmpeg/libpostproc/postprocess_template.c ffmpeg/libpostproc/postprocess.c ffmpeg/libpostproc/postprocess_internal.h ffmpeg/libpostproc/postprocess_altivec_template.c -ffmpeg/libpostproc/mangle.h ffmpeg/libpostproc/postprocess.h ffmpeg/libpostproc/Makefile +ffmpeg/tools +ffmpeg/tools/cws2fws.c +ffmpeg/tools/unwrap-diff +ffmpeg/tools/build_avopt +ffmpeg/tools/clean-diff +ffmpeg/tools/trasher.c +ffmpeg/tools/pktdumper.c +ffmpeg/tools/qt-faststart.c +ffmpeg/ffplay.c ffmpeg/tests +ffmpeg/tests/seek_test.sh +ffmpeg/tests/seek.regression.ref ffmpeg/tests/videogen.c ffmpeg/tests/rotozoom.regression.ref ffmpeg/tests/test.conf ffmpeg/tests/tiny_psnr.c -ffmpeg/tests/dsptest.c ffmpeg/tests/libav.regression.ref +ffmpeg/tests/seek_test.c ffmpeg/tests/lena.pnm ffmpeg/tests/regression.sh ffmpeg/tests/rotozoom.c ffmpeg/tests/audiogen.c ffmpeg/tests/ffserver.regression.ref -ffmpeg/tests/Makefile ffmpeg/tests/server-regression.sh ffmpeg/tests/ffmpeg.regression.ref -ffmpeg/tests/seek_test.sh -ffmpeg/tests/seek_test.c +ffmpeg/ffserver.c +ffmpeg/libavfilter +ffmpeg/libavfilter/allfilters.c +ffmpeg/libavfilter/avfilter.h +ffmpeg/libavfilter/defaults.c +ffmpeg/libavfilter/formats.c +ffmpeg/libavfilter/Makefile +ffmpeg/libavfilter/avfilter.c ffmpeg/doc ffmpeg/doc/faq.texi ffmpeg/doc/ffmpeg-doc.texi +ffmpeg/doc/issue_tracker.txt +ffmpeg/doc/avutil.txt +ffmpeg/doc/soc.txt ffmpeg/doc/optimization.txt +ffmpeg/doc/snow.txt ffmpeg/doc/TODO +ffmpeg/doc/general.texi ffmpeg/doc/ffserver.conf ffmpeg/doc/texi2pod.pl ffmpeg/doc/ffmpeg_powerpc_performance_evaluation_howto.txt ffmpeg/doc/hooks.texi ffmpeg/doc/ffplay-doc.texi -ffmpeg/doc/Makefile ffmpeg/doc/ffserver-doc.texi -ffmpeg/doc/soc.txt -ffmpeg/doc/snow.txt -ffmpeg/doc/avutil.txt +ffmpeg/cmdutils.c +ffmpeg/COPYING.LGPL +ffmpeg/INSTALL ffmpeg/libavformat -ffmpeg/libavformat/riff.h +ffmpeg/libavformat/matroska.h +ffmpeg/libavformat/allformats.c ffmpeg/libavformat/img2.c -ffmpeg/libavformat/voc.h -ffmpeg/libavformat/dv1394.h -ffmpeg/libavformat/rtsp.h -ffmpeg/libavformat/utils.c -ffmpeg/libavformat/wav.c -ffmpeg/libavformat/cutils.c -ffmpeg/libavformat/dvenc.c -ffmpeg/libavformat/nut.c -ffmpeg/libavformat/avisynth.c -ffmpeg/libavformat/crc.c -ffmpeg/libavformat/wv.c -ffmpeg/libavformat/ipmovie.c -ffmpeg/libavformat/nut.h -ffmpeg/libavformat/ffm.c -ffmpeg/libavformat/mtv.c +ffmpeg/libavformat/gif.c +ffmpeg/libavformat/oggenc.c +ffmpeg/libavformat/framecrcenc.c +ffmpeg/libavformat/mpc8.c +ffmpeg/libavformat/file.c +ffmpeg/libavformat/isom.c +ffmpeg/libavformat/mpeg.h +ffmpeg/libavformat/matroskaenc.c +ffmpeg/libavformat/udp.c +ffmpeg/libavformat/sol.c ffmpeg/libavformat/nuv.c -ffmpeg/libavformat/framehook.c -ffmpeg/libavformat/os_support.c -ffmpeg/libavformat/vocenc.c -ffmpeg/libavformat/idroq.c -ffmpeg/libavformat/libnut.c -ffmpeg/libavformat/http.c -ffmpeg/libavformat/westwood.c -ffmpeg/libavformat/matroska.c -ffmpeg/libavformat/vocdec.c +ffmpeg/libavformat/vc1test.c +ffmpeg/libavformat/gifdec.c +ffmpeg/libavformat/ffm.c +ffmpeg/libavformat/oggparsespeex.c +ffmpeg/libavformat/nutdec.c +ffmpeg/libavformat/ipmovie.c +ffmpeg/libavformat/mxf.c +ffmpeg/libavformat/c93.c +ffmpeg/libavformat/avc.c +ffmpeg/libavformat/rmdec.c +ffmpeg/libavformat/voc.c +ffmpeg/libavformat/isom.h +ffmpeg/libavformat/idcin.c +ffmpeg/libavformat/avc.h +ffmpeg/libavformat/rtspcodes.h +ffmpeg/libavformat/apc.c ffmpeg/libavformat/adtsenc.c -ffmpeg/libavformat/flic.c +ffmpeg/libavformat/aviobuf.c +ffmpeg/libavformat/thp.c +ffmpeg/libavformat/avio.c ffmpeg/libavformat/electronicarts.c -ffmpeg/libavformat/rtp_h264.c +ffmpeg/libavformat/cutils.c +ffmpeg/libavformat/psxstr.c ffmpeg/libavformat/mpjpeg.c -ffmpeg/libavformat/flvenc.c -ffmpeg/libavformat/os_support.h -ffmpeg/libavformat/rtp_h264.h -ffmpeg/libavformat/tiertexseq.c -ffmpeg/libavformat/gxf.c -ffmpeg/libavformat/nutdec.c -ffmpeg/libavformat/avi.h -ffmpeg/libavformat/network.h +ffmpeg/libavformat/mmf.c +ffmpeg/libavformat/yuv4mpeg.c ffmpeg/libavformat/smacker.c +ffmpeg/libavformat/pva.c +ffmpeg/libavformat/voc.h +ffmpeg/libavformat/siff.c +ffmpeg/libavformat/rmenc.c +ffmpeg/libavformat/avio.h +ffmpeg/libavformat/oggdec.c +ffmpeg/libavformat/tta.c ffmpeg/libavformat/flv.h -ffmpeg/libavformat/udp.c -ffmpeg/libavformat/x11grab.c -ffmpeg/libavformat/gxf.h -ffmpeg/libavformat/mpc.c -ffmpeg/libavformat/avs.c -ffmpeg/libavformat/daud.c +ffmpeg/libavformat/rtp_h264.c ffmpeg/libavformat/rtpproto.c +ffmpeg/libavformat/txd.c +ffmpeg/libavformat/vocdec.c +ffmpeg/libavformat/avs.c +ffmpeg/libavformat/dsicin.c +ffmpeg/libavformat/aiff.c +ffmpeg/libavformat/rtpenc.c +ffmpeg/libavformat/au.c +ffmpeg/libavformat/asfcrypt.c +ffmpeg/libavformat/bethsoftvid.c ffmpeg/libavformat/Makefile -ffmpeg/libavformat/framehook.h +ffmpeg/libavformat/wav.c ffmpeg/libavformat/oggparsevorbis.c -ffmpeg/libavformat/rtspcodes.h +ffmpeg/libavformat/avidec.c +ffmpeg/libavformat/nsvdec.c ffmpeg/libavformat/oggparseflac.c +ffmpeg/libavformat/nut.h +ffmpeg/libavformat/tcp.c +ffmpeg/libavformat/oggdec.h +ffmpeg/libavformat/rtp_internal.h +ffmpeg/libavformat/dxa.c +ffmpeg/libavformat/matroskadec.c +ffmpeg/libavformat/network.h +ffmpeg/libavformat/gxf.c +ffmpeg/libavformat/movenc.c ffmpeg/libavformat/mpegts.c -ffmpeg/libavformat/mp3.c +ffmpeg/libavformat/framehook.c +ffmpeg/libavformat/asfcrypt.h +ffmpeg/libavformat/os_support.c +ffmpeg/libavformat/westwood.c ffmpeg/libavformat/mpegts.h +ffmpeg/libavformat/dvenc.c ffmpeg/libavformat/rtp.c -ffmpeg/libavformat/dc1394.c -ffmpeg/libavformat/4xm.c -ffmpeg/libavformat/ogg.c -ffmpeg/libavformat/qtpalette.h -ffmpeg/libavformat/asf.c +ffmpeg/libavformat/rtp_h264.h +ffmpeg/libavformat/avisynth.c +ffmpeg/libavformat/mtv.c +ffmpeg/libavformat/mp3.c +ffmpeg/libavformat/mpc.c ffmpeg/libavformat/dv.c -ffmpeg/libavformat/gxfenc.c -ffmpeg/libavformat/mmf.c -ffmpeg/libavformat/beosaudio.cpp +ffmpeg/libavformat/rtp_aac.c ffmpeg/libavformat/rtp.h -ffmpeg/libavformat/grab.c -ffmpeg/libavformat/asf-enc.c -ffmpeg/libavformat/asf.h +ffmpeg/libavformat/gxfenc.c +ffmpeg/libavformat/4xm.c +ffmpeg/libavformat/daud.c ffmpeg/libavformat/dv.h -ffmpeg/libavformat/rm.c -ffmpeg/libavformat/file.c -ffmpeg/libavformat/yuv4mpeg.c -ffmpeg/libavformat/nsvdec.c -ffmpeg/libavformat/tcp.c -ffmpeg/libavformat/movenc.c -ffmpeg/libavformat/mpeg.c -ffmpeg/libavformat/raw.c -ffmpeg/libavformat/amr.c -ffmpeg/libavformat/sierravmd.c -ffmpeg/libavformat/gifdec.c -ffmpeg/libavformat/wc3movie.c -ffmpeg/libavformat/grab_bktr.c -ffmpeg/libavformat/sol.c -ffmpeg/libavformat/avio.c -ffmpeg/libavformat/ogg2.c +ffmpeg/libavformat/idroq.c +ffmpeg/libavformat/flic.c +ffmpeg/libavformat/rtpdec.c +ffmpeg/libavformat/qtpalette.h +ffmpeg/libavformat/rm.h +ffmpeg/libavformat/lmlm4.c +ffmpeg/libavformat/http.c +ffmpeg/libavformat/mpegenc.c +ffmpeg/libavformat/rtp_mpv.c +ffmpeg/libavformat/rtp_mpv.h +ffmpeg/libavformat/matroska.c +ffmpeg/libavformat/tiertexseq.c +ffmpeg/libavformat/crcenc.c +ffmpeg/libavformat/libnut.c ffmpeg/libavformat/swf.c +ffmpeg/libavformat/asf-enc.c ffmpeg/libavformat/mov.c -ffmpeg/libavformat/avio.h -ffmpeg/libavformat/ogg2.h -ffmpeg/libavformat/psxstr.c +ffmpeg/libavformat/os_support.h +ffmpeg/libavformat/framehook.h ffmpeg/libavformat/avienc.c -ffmpeg/libavformat/au.c -ffmpeg/libavformat/aiff.c -ffmpeg/libavformat/isom.c -ffmpeg/libavformat/mxf.c +ffmpeg/libavformat/ape.c +ffmpeg/libavformat/asf.c +ffmpeg/libavformat/mpegtsenc.c ffmpeg/libavformat/mm.c -ffmpeg/libavformat/avformat.h -ffmpeg/libavformat/oggparseogm.c -ffmpeg/libavformat/idcin.c +ffmpeg/libavformat/wv.c +ffmpeg/libavformat/avi.h +ffmpeg/libavformat/mpeg.c ffmpeg/libavformat/oggparsetheora.c -ffmpeg/libavformat/mpegtsenc.c -ffmpeg/libavformat/riff.c -ffmpeg/libavformat/segafilm.c -ffmpeg/libavformat/v4l2.c -ffmpeg/libavformat/tta.c -ffmpeg/libavformat/avidec.c -ffmpeg/libavformat/audio.c ffmpeg/libavformat/flvdec.c -ffmpeg/libavformat/voc.c -ffmpeg/libavformat/allformats.c -ffmpeg/libavformat/gif.c +ffmpeg/libavformat/raw.c +ffmpeg/libavformat/oggparseogm.c +ffmpeg/libavformat/sdp.c +ffmpeg/libavformat/sierravmd.c +ffmpeg/libavformat/flvenc.c +ffmpeg/libavformat/amr.c +ffmpeg/libavformat/nut.c +ffmpeg/libavformat/vocenc.c +ffmpeg/libavformat/avformat.h +ffmpeg/libavformat/riff.c +ffmpeg/libavformat/rtp_aac.h ffmpeg/libavformat/rtsp.c -ffmpeg/libavformat/dsicin.c -ffmpeg/libavformat/dv1394.c -ffmpeg/libavformat/allformats.h -ffmpeg/libavformat/aviobuf.c -ffmpeg/libavformat/isom.h -ffmpeg/libavformat/rtp_internal.h -ffmpeg/libavformat/dxa.c -ffmpeg/libavformat/thp.c -ffmpeg/configure -ffmpeg/Doxyfile -ffmpeg/ffmpeg.c -ffmpeg/Changelog -ffmpeg/clean-diff -ffmpeg/pktdumper.c -ffmpeg/output_example.c -ffmpeg/CREDITS -ffmpeg/version.sh -ffmpeg/cmdutils.c -ffmpeg/INSTALL -ffmpeg/COPYING -ffmpeg/build_avopt +ffmpeg/libavformat/riff.h +ffmpeg/libavformat/raw.h +ffmpeg/libavformat/segafilm.c +ffmpeg/libavformat/rtsp.h +ffmpeg/libavformat/nutenc.c +ffmpeg/libavformat/rtpenc_h264.c +ffmpeg/libavformat/asf.h +ffmpeg/libavformat/eacdata.c +ffmpeg/libavformat/utils.c +ffmpeg/libavformat/gxf.h +ffmpeg/libavformat/wc3movie.c +ffmpeg/ffserver.h ffmpeg/ffinstall.nsi ffmpeg/cmdutils.h -ffmpeg/Makefile -ffmpeg/qt-faststart.c -ffmpeg/cws2fws.c -ffmpeg/unwrap-diff -ffmpeg/README -ffmpeg/common.mak -ffmpeg/ffplay.c -ffmpeg/ffserver.c -ffmpeg/ffserver.h ffmpeg/MAINTAINERS +ffmpeg/Makefile +ffmpeg/libavdevice +ffmpeg/libavdevice/libdc1394.c +ffmpeg/libavdevice/dv1394.h +ffmpeg/libavdevice/audio.c +ffmpeg/libavdevice/bktr.c +ffmpeg/libavdevice/v4l.c +ffmpeg/libavdevice/x11grab.c +ffmpeg/libavdevice/v4l2.c +ffmpeg/libavdevice/beosaudio.cpp +ffmpeg/libavdevice/dv1394.c +ffmpeg/libavdevice/alldevices.c +ffmpeg/libavdevice/avdevice.h +ffmpeg/libavdevice/Makefile ffmpeg/libswscale +ffmpeg/libswscale/yuv2rgb_bfin.c +ffmpeg/libswscale/swscale_bfin.c ffmpeg/libswscale/yuv2rgb.c ffmpeg/libswscale/swscale.c -ffmpeg/libswscale/rgb2rgb_template.c ffmpeg/libswscale/swscale_internal.h ffmpeg/libswscale/swscale_altivec_template.c ffmpeg/libswscale/yuv2rgb_mlib.c ffmpeg/libswscale/cs_test.c ffmpeg/libswscale/swscale.h -ffmpeg/libswscale/rgb2rgb.c ffmpeg/libswscale/yuv2rgb_altivec.c +ffmpeg/libswscale/yuv2rgb_vis.c +ffmpeg/libswscale/rgb2rgb_template.c +ffmpeg/libswscale/rgb2rgb.c ffmpeg/libswscale/swscale-example.c +ffmpeg/libswscale/internal_bfin.S ffmpeg/libswscale/yuv2rgb_template.c -ffmpeg/libswscale/Makefile -ffmpeg/libswscale/rgb2rgb.h ffmpeg/libswscale/swscale_template.c -ffmpeg/libswscale/yuv2rgb_init.c +ffmpeg/libswscale/rgb2rgb.h +ffmpeg/libswscale/Makefile diff --git a/contrib/ffmpeg/COPYING b/contrib/ffmpeg/COPYING deleted file mode 100644 index 1e0991447..000000000 --- a/contrib/ffmpeg/COPYING +++ /dev/null @@ -1,504 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - <one line to give the library's name and a brief idea of what it does.> - Copyright (C) <year> <name of author> - - This library 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 of the License, or (at your option) any later version. - - This library 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 this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - <signature of Ty Coon>, 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - - diff --git a/contrib/ffmpeg/COPYING.GPL b/contrib/ffmpeg/COPYING.GPL new file mode 100644 index 000000000..d159169d1 --- /dev/null +++ b/contrib/ffmpeg/COPYING.GPL @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/contrib/ffmpeg/COPYING.LGPL b/contrib/ffmpeg/COPYING.LGPL new file mode 100644 index 000000000..00b4fedfe --- /dev/null +++ b/contrib/ffmpeg/COPYING.LGPL @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + <one line to give the library's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This library 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. + + This library 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 this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + <signature of Ty Coon>, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/contrib/ffmpeg/CREDITS b/contrib/ffmpeg/CREDITS index f7f086a3c..dd328c65c 100644 --- a/contrib/ffmpeg/CREDITS +++ b/contrib/ffmpeg/CREDITS @@ -1,6 +1,7 @@ This file contains the name of the people who have contributed to FFmpeg. The names are sorted alphabetically by last name. +Dénes Balatoni Michel Bardiaux Fabrice Bellard Patrice Bensoussan @@ -18,6 +19,7 @@ Vladimir Gneushev Roine Gustafsson David Hammerton Wolfgang Hesseler +Marc Hoffman Falk Hueffner Steven Johnson Zdenek Kabelac diff --git a/contrib/ffmpeg/Changelog b/contrib/ffmpeg/Changelog index 0b96efe85..3249c60c5 100644 --- a/contrib/ffmpeg/Changelog +++ b/contrib/ffmpeg/Changelog @@ -1,4 +1,5 @@ version <next> +- The "device" muxers and demuxers are now in a new libavdevice library - DV50 AKA DVCPRO50 encoder, decoder, muxer and demuxer - TechSmith Camtasia (TSCC) video decoder - IBM Ultimotion (ULTI) video decoder @@ -63,7 +64,7 @@ version <next> - Delphine Software .cin demuxer/audio and video decoder - Tiertex .seq demuxer/video decoder - MTV demuxer -- TIFF picture decoder +- TIFF picture encoder and decoder - GIF picture decoder - Intel Music decoder - Musepack decoder @@ -77,6 +78,38 @@ version <next> - DNxHD decoder - Gamecube movie (.THP) playback system - Blackfin optimizations +- Interplay C93 demuxer and video decoder +- Bethsoft VID demuxer and video decoder +- CRYO APC demuxer +- Atrac3 decoder +- V.Flash PTX decoder +- RoQ muxer, audio encoder +- Renderware TXD demuxer and decoder +- extern C declarations for C++ removed from headers +- sws_flags command line option +- codebook generator +- RoQ video encoder +- QTRLE encoder +- OS/2 support removed and restored again +- AC-3 decoder +- NUT muxer (since r10052) +- Matroska muxer +- Slice-based parallel H.264 decoding +- Monkey's Audio demuxer and decoder +- additional SPARC (VIS) optimizations +- AMV audio and video decoder +- DNxHD encoder +- H.264 PAFF decoding +- Nellymoser ASAO decoder +- Beam Software SIFF demuxer and decoder +- libvorbis Vorbis decoding removed in favor of native decoder +- IntraX8 (J-Frame) subdecoder for WMV2 and VC-1 +- Ogg muxer +- PC Paintbrush PCX decoder +- Sun Rasterfile decoder +- TechnoTrend PVA demuxer +- Linux Media Labs MPEG-4 (LMLM4) demuxer +- AVM2 (Flash 9) SWF muxer version 0.4.9-pre1: @@ -145,7 +178,7 @@ version 0.4.9-pre1: - SGI image format, encoding and decoding - H.264 loop filter support - H.264 CABAC support -- nicer looking arrows for the motion vector vissualization +- nicer looking arrows for the motion vector visualization - improved VCD support - audio timestamp drift compensation - MPEG-2 YUV 422/444 support @@ -248,8 +281,8 @@ version 0.4.6: version 0.4.5: -- some header fixes (Zdenek Kabelac <kabi@informatics.muni.cz>) -- many MMX optimizations (Nick Kurshev <nickols_k@mail.ru>) +- some header fixes (Zdenek Kabelac <kabi at informatics.muni.cz>) +- many MMX optimizations (Nick Kurshev <nickols_k at mail.ru>) - added configure system (actually a small shell script) - added MPEG audio layer 1/2/3 decoding using LGPL'ed mpglib by Michael Hipp (temporary solution - waiting for integer only @@ -266,12 +299,12 @@ version 0.4.5: - added MJPEG decoder - added mmx/mmxext IDCT from libmpeg2 - added pgmyuvpipe, ppm, and ppm_pipe formats (original patch by Celer - <celer@shell.scrypt.net>) + <celer at shell.scrypt.net>) - added pixel format conversion layer (e.g. for MJPEG or PPM) - added deinterlacing option - MPEG-1/2 fixes -- MPEG-4 vol header fixes (Jonathan Marsden <snmjbm@pacbell.net>) -- ARM optimizations (Lionel Ulmer <lionel.ulmer@free.fr>). +- MPEG-4 vol header fixes (Jonathan Marsden <snmjbm at pacbell.net>) +- ARM optimizations (Lionel Ulmer <lionel.ulmer at free.fr>). - Windows porting of file converter - added MJPEG raw format (input/ouput) - added JPEG image format support (input/output) @@ -279,7 +312,7 @@ version 0.4.5: version 0.4.4: - fixed some std header definitions (Bjorn Lindgren - <bjorn.e.lindgren@telia.com>). + <bjorn.e.lindgren at telia.com>). - added MPEG demuxer (MPEG-1 and 2 compatible). - added ASF demuxer - added prototype RM demuxer @@ -302,7 +335,7 @@ version 0.4.4: version 0.4.3: -- BGR24 patch (initial patch by Jeroen Vreeken <pe1rxq@amsat.org>) +- BGR24 patch (initial patch by Jeroen Vreeken <pe1rxq at amsat.org>) - fixed raw yuv output - added motion rounding support in MPEG-4 - fixed motion bug rounding in MSMPEG4 @@ -317,7 +350,7 @@ version 0.4.3: - suppressed 'img:' protocol. Simply use: /tmp/test%d.[pgm|Y] as input or output. - added pgmpipe I/O format (original patch from Martin Aumueller - <lists@reserv.at>, but changed completely since we use a format + <lists at reserv.at>, but changed completely since we use a format instead of a protocol) version 0.4.2: @@ -355,7 +388,7 @@ version 0.4.0: - added timeshifting support for live feeds (option ?date=xxx in the URL) - added high quality image resize code with polyphase filter (need - mmx/see optimisation). Enable multiple image size support in ffserver. + mmx/see optimization). Enable multiple image size support in ffserver. - added multi live feed support in ffserver - suppressed master feature from ffserver (it should be done with an external program which opens the .ffm url and writes it to another @@ -369,7 +402,7 @@ version 0.4.0: - added WAV format support - added "tty user interface" to ffmpeg to stop grabbing gracefully - added MMX/SSE optimizations to SAD (Sums of Absolutes Differences) - (Juan J. Sierralta P. a.k.a. "Juanjo" <juanjo@atmlab.utfsm.cl>) + (Juan J. Sierralta P. a.k.a. "Juanjo" <juanjo at atmlab.utfsm.cl>) - added MMX DCT from mpeg2_movie 1.5 (Juanjo) - added new motion estimation algorithms, log and phods (Juanjo) - changed directories: libav for format handling, libavcodec for diff --git a/contrib/ffmpeg/Doxyfile b/contrib/ffmpeg/Doxyfile index 9e4fdcdd0..31daf5d86 100644 --- a/contrib/ffmpeg/Doxyfile +++ b/contrib/ffmpeg/Doxyfile @@ -654,7 +654,7 @@ LATEX_BATCHMODE = NO #--------------------------------------------------------------------------- # If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output -# The RTF output is optimised for Word 97 and may not look very pretty with +# The RTF output is optimized for Word 97 and may not look very pretty with # other RTF readers or editors. GENERATE_RTF = NO diff --git a/contrib/ffmpeg/MAINTAINERS b/contrib/ffmpeg/MAINTAINERS index beff7bb76..3a2dd36b2 100644 --- a/contrib/ffmpeg/MAINTAINERS +++ b/contrib/ffmpeg/MAINTAINERS @@ -80,7 +80,7 @@ Generic Parts: eval.c Michael Niedermayer audio and video frame extraction: parser.c - bitsream reading: + bitstream reading: bitstream.c, bitstream.h Michael Niedermayer CABAC: cabac.h, cabac.c Michael Niedermayer @@ -97,7 +97,7 @@ Generic Parts: motion* Michael Niedermayer rate control: ratecontrol.c - xvid_rc.c Michael Niedermayer + libxvid_rc.c Michael Niedermayer simple IDCT: simple_idct.c, simple_idct.h Michael Niedermayer postprocessing: @@ -108,14 +108,17 @@ Codecs: 8bps.c Roberto Togni aasc.c Kostya Shishkov ac3* Justin Ruggles + apedec.c Kostya Shishkov asv* Michael Niedermayer + atrac3* Benjamin Larsson bmp.c Mans Rullgard cavs* Stefan Gehrer cinepak.c Roberto Togni cljr Alex Beregszaszi cook.c, cookdata.h Benjamin Larsson cscd.c Reimar Doeffinger - dnxhddec.c Baptiste Coudurier + dca.c Kostya Shishkov, Benjamin Larsson + dnxhd* Baptiste Coudurier dpcm.c Mike Melanson dxa.c Kostya Shishkov dv.c Roman Shaposhnik @@ -136,8 +139,9 @@ Codecs: interplayvideo.c Mike Melanson jpeg_ls.c Kostya Shishkov kmvc.c Kostya Shishkov - lcl.c Roberto Togni + lcl*.c Roberto Togni libgsm.c Michel Bardiaux + libx264.c Mans Rullgard loco.c Kostya Shishkov lzo.h, lzo.c Reimar Doeffinger mdec.c Michael Niedermayer @@ -148,8 +152,10 @@ Codecs: msmpeg4.c, msmpeg4data.h Michael Niedermayer msrle.c Mike Melanson msvideo1.c Mike Melanson + nellymoserdec.c Benjamin Larsson nuv.c Reimar Doeffinger - oggtheora.c Mans Rullgard + pcx.c Ivo van Poorten + ptx.c Ivo van Poorten qdm2.c, qdm2data.h Roberto Togni qdrw.c Kostya Shishkov qpeg.c Kostya Shishkov @@ -159,9 +165,13 @@ Codecs: rpza.c Roberto Togni rtjpeg.c, rtjpeg.h Reimar Doeffinger rv10.c Michael Niedermayer + rv3* Kostya Shishkov + rv4* Kostya Shishkov + s3tc* Ivo van Poorten smc.c Mike Melanson snow.c Michael Niedermayer, Loren Merritt sonic.c Alex Beregszaszi + sunrast.c Ivo van Poorten svq3.c Michael Niedermayer targa.c Kostya Shishkov tiff.c Kostya Shishkov @@ -169,11 +179,15 @@ Codecs: truemotion2* Kostya Shishkov truespeech.c Kostya Shishkov tscc.c Kostya Shishkov + tta.c Alex Beregszaszi + txd.c Ivo van Poorten ulti* Kostya Shishkov + vb.c Kostya Shishkov vc1* Kostya Shishkov vcr1.c Michael Niedermayer vmnc.c Kostya Shishkov vorbis_enc.c Oded Shimon + vorbis_dec.c Denes Balatoni vp3* Mike Melanson vp5 Aurelien Jacobs vp6 Aurelien Jacobs @@ -181,7 +195,6 @@ Codecs: wavpack.c Kostya Shishkov wmv2.c Michael Niedermayer wnv1.c Kostya Shishkov - x264.c Mans Rullgard xan.c Mike Melanson xl.c Kostya Shishkov xvmcvideo.c Ivan Kalvachev @@ -202,6 +215,7 @@ Muxers/Demuxers: 4xm.c Mike Melanson adtsenc.c Mans Rullgard aiff.c Baptiste Coudurier + ape.c Kostya Shishkov avi* Michael Niedermayer crc.c Michael Niedermayer daud.c Reimar Doeffinger @@ -216,7 +230,9 @@ Muxers/Demuxers: ipmovie.c Mike Melanson img2.c Michael Niedermayer libnut.c Oded Shimon + lmlm4.c Ivo van Poorten matroska.c Aurelien Jacobs + matroskaenc.c David Conrad mov.c Michael Niedermayer, Baptiste Coudurier movenc.c Michael Niedermayer, Baptiste Coudurier mpc.c Kostya Shishkov @@ -226,14 +242,23 @@ Muxers/Demuxers: nsvdec.c Francois Revol nut.c Michael Niedermayer nuv.c Reimar Doeffinger - ogg2.c, ogg2.h Mans Rullgard + oggdec.c, oggdec.h Mans Rullgard + oggenc.c Baptiste Coudurier oggparsevorbis.c Mans Rullgard oggparseogm.c Mans Rullgard psxstr.c Mike Melanson + pva.c Ivo van Poorten raw.c Michael Niedermayer rm.c Roberto Togni + rtp.c, rtpenc.c Luca Abeni + rtp_mpv.*, rtp_aac.* Luca Abeni + rtsp.c Luca Barbato + sdp.c Luca Abeni segafilm.c Mike Melanson + siff.c Kostya Shishkov swf.c Baptiste Coudurier + tta.c Alex Beregszaszi + txd.c Ivo van Poorten v4l2.c Luca Abeni voc.c Aurelien Jacobs wav.c Michael Niedermayer @@ -248,7 +273,9 @@ Operating systems / CPU architectures Alpha Mans Rullgard, Falk Hueffner BeOS Francois Revol i386 Michael Niedermayer -Mac OS X / PowerPC Romain Dolbeau +Mac OS X / PowerPC Romain Dolbeau, Guillaume Poirier Amiga / PowerPC Colin Ward Linux / PowerPC Luca Barbato -Windows MinGW Alex Beregszaszi +Windows MinGW Alex Beregszaszi, Ramiro Polla +Windows Cygwin Victor Paesa +ADI/Blackfin DSP Marc Hoffman diff --git a/contrib/ffmpeg/Makefile b/contrib/ffmpeg/Makefile index d49bb1c76..8191165ac 100644 --- a/contrib/ffmpeg/Makefile +++ b/contrib/ffmpeg/Makefile @@ -8,65 +8,91 @@ VPATH=$(SRC_PATH_BARE) CFLAGS=$(OPTFLAGS) -I$(BUILD_ROOT) -I$(SRC_PATH) -I$(SRC_PATH)/libavutil \ -I$(SRC_PATH)/libavcodec -I$(SRC_PATH)/libavformat -I$(SRC_PATH)/libswscale \ - -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_ISOC9X_SOURCE + -I$(SRC_PATH)/libavdevice -I$(SRC_PATH)/libavfilter \ + -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_ISOC9X_SOURCE -DHAVE_AV_CONFIG_H LDFLAGS+= -g PROGS-$(CONFIG_FFMPEG) += ffmpeg PROGS-$(CONFIG_FFPLAY) += ffplay PROGS-$(CONFIG_FFSERVER) += ffserver -PROGS = $(addsuffix $(EXESUF), $(PROGS-yes)) -PROGS_G = $(addsuffix _g$(EXESUF), $(PROGS-yes)) -MANPAGES = $(addprefix doc/, $(addsuffix .1, $(PROGS-yes))) +PROGS = $(addsuffix $(EXESUF), $(PROGS-yes)) +PROGS_G = $(addsuffix _g$(EXESUF), $(PROGS-yes)) +MANPAGES = $(addprefix doc/, $(addsuffix .1, $(PROGS-yes))) -BASENAMES=ffmpeg ffplay ffserver -ALLPROGS=$(addsuffix $(EXESUF), $(BASENAMES)) -ALLPROGS_G=$(addsuffix _g$(EXESUF), $(BASENAMES)) -ALLMANPAGES=$(addsuffix .1, $(BASENAMES)) +BASENAMES = ffmpeg ffplay ffserver +ALLPROGS = $(addsuffix $(EXESUF), $(BASENAMES)) +ALLPROGS_G = $(addsuffix _g$(EXESUF), $(BASENAMES)) +ALLMANPAGES = $(addsuffix .1, $(BASENAMES)) ifeq ($(BUILD_SHARED),yes) -DEP_LIBS=libavcodec/$(SLIBPREF)avcodec$(SLIBSUF) libavformat/$(SLIBPREF)avformat$(SLIBSUF) +DEP_LIBS=libavcodec/$(SLIBPREF)avcodec$(SLIBSUF) libavformat/$(SLIBPREF)avformat$(SLIBSUF) libavdevice/$(SLIBPREF)avdevice$(SLIBSUF) else -DEP_LIBS=libavcodec/$(LIBPREF)avcodec$(LIBSUF) libavformat/$(LIBPREF)avformat$(LIBSUF) +DEP_LIBS=libavcodec/$(LIBPREF)avcodec$(LIBSUF) libavformat/$(LIBPREF)avformat$(LIBSUF) libavdevice/$(LIBPREF)avdevice$(LIBSUF) endif -ifeq ($(CONFIG_VHOOK),yes) -all: videohook -install: install-vhook -endif +ALL_TARGETS-$(CONFIG_VHOOK) += videohook +ALL_TARGETS-$(BUILD_DOC) += documentation -ifeq ($(BUILD_DOC),yes) -all: documentation -install: install-man +INSTALL_TARGETS-$(CONFIG_VHOOK) += install-vhook +ifneq ($(PROGS),) +INSTALL_TARGETS-yes += install-progs +INSTALL_TARGETS-$(BUILD_DOC) += install-man endif +VHOOKCFLAGS += $(filter-out -mdynamic-no-pic,$(CFLAGS)) + +BASEHOOKS = fish null watermark +ALLHOOKS = $(BASEHOOKS) drawtext imlib2 ppm +ALLHOOKS_SRCS = $(addprefix vhook/, $(addsuffix .c, $(ALLHOOKS))) + +HOOKS-$(HAVE_FORK) += ppm +HOOKS-$(HAVE_IMLIB2) += imlib2 +HOOKS-$(HAVE_FREETYPE2) += drawtext + +HOOKS = $(addprefix vhook/, $(addsuffix $(SLIBSUF), $(BASEHOOKS) $(HOOKS-yes))) + +VHOOKCFLAGS-$(HAVE_IMLIB2) += `imlib2-config --cflags` +LIBS_imlib2$(SLIBSUF) = `imlib2-config --libs` + +VHOOKCFLAGS-$(HAVE_FREETYPE2) += `freetype-config --cflags` +LIBS_drawtext$(SLIBSUF) = `freetype-config --libs` + +VHOOKCFLAGS += $(VHOOKCFLAGS-yes) + SRCS = $(addsuffix .c, $(PROGS-yes)) cmdutils.c -LDFLAGS := -L$(BUILD_ROOT)/libavformat -L$(BUILD_ROOT)/libavcodec -L$(BUILD_ROOT)/libavutil $(LDFLAGS) -EXTRALIBS := -lavformat$(BUILDSUF) -lavcodec$(BUILDSUF) -lavutil$(BUILDSUF) $(EXTRALIBS) +LDFLAGS := -L$(BUILD_ROOT)/libavdevice -L$(BUILD_ROOT)/libavformat -L$(BUILD_ROOT)/libavcodec -L$(BUILD_ROOT)/libavutil $(LDFLAGS) +EXTRALIBS := -lavdevice$(BUILDSUF) -lavformat$(BUILDSUF) -lavcodec$(BUILDSUF) -lavutil$(BUILDSUF) $(EXTRALIBS) ifeq ($(CONFIG_SWSCALER),yes) -LDFLAGS+=-L./libswscale +LDFLAGS+=-L$(BUILD_ROOT)/libswscale EXTRALIBS+=-lswscale$(BUILDSUF) endif -all: lib $(PROGS) +ifeq ($(CONFIG_AVFILTER),yes) +LDFLAGS+=-L$(BUILD_ROOT)/libavfilter +EXTRALIBS := -lavfilter$(BUILDSUF) $(EXTRALIBS) +endif + +MAKE-yes = $(MAKE) +MAKE- = : $(MAKE) + +all: lib $(PROGS) $(ALL_TARGETS-yes) lib: - $(MAKE) -C libavutil all - $(MAKE) -C libavcodec all - $(MAKE) -C libavformat all -ifeq ($(CONFIG_PP),yes) - $(MAKE) -C libpostproc all -endif -ifeq ($(CONFIG_SWSCALER),yes) - $(MAKE) -C libswscale all -endif + $(MAKE) -C libavutil all + $(MAKE) -C libavcodec all + $(MAKE) -C libavformat all + $(MAKE) -C libavdevice all + $(MAKE-$(CONFIG_PP)) -C libpostproc all + $(MAKE-$(CONFIG_SWSCALER)) -C libswscale all + $(MAKE-$(CONFIG_AVFILTER)) -C libavfilter all ffmpeg_g$(EXESUF): ffmpeg.o cmdutils.o .libs $(CC) $(LDFLAGS) -o $@ ffmpeg.o cmdutils.o $(EXTRALIBS) -ffserver$(EXESUF): ffserver.o .libs - $(CC) $(LDFLAGS) $(FFSERVERLDFLAGS) -o $@ ffserver.o $(EXTRALIBS) +ffserver$(EXESUF): ffserver.o cmdutils.o .libs + $(CC) $(LDFLAGS) $(FFSERVERLDFLAGS) -o $@ ffserver.o cmdutils.o $(EXTRALIBS) ffplay_g$(EXESUF): ffplay.o cmdutils.o .libs $(CC) $(LDFLAGS) -o $@ ffplay.o cmdutils.o $(EXTRALIBS) $(SDL_LIBS) @@ -84,115 +110,125 @@ version.h: $(SRC_PATH)/version.sh $(SRC_PATH) output_example$(EXESUF): output_example.o .libs - $(CC) $(LDFLAGS) -o $@ output_example.o $(EXTRALIBS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(EXTRALIBS) -qt-faststart$(EXESUF): qt-faststart.c - $(CC) $(CFLAGS) $< -o $@ +tools/%$(EXESUF): tools/%.c + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(EXTRALIBS) -cws2fws$(EXESUF): cws2fws.c - $(CC) $< -o $@ -lz - -ffplay.o: ffplay.c - $(CC) $(CFLAGS) $(SDL_CFLAGS) -c -o $@ $< +ffplay.o: CFLAGS += $(SDL_CFLAGS) ffmpeg.o ffplay.o ffserver.o: version.h +videohook: .libs $(HOOKS) + +vhook/%$(SLIBSUF): vhook/%.o + $(CC) $(LDFLAGS) -o $@ $(VHOOKSHFLAGS) $< $(VHOOKLIBS) $(LIBS_$(@F)) + +vhook/%.o: vhook/%.c + $(CC) $(VHOOKCFLAGS) -c -o $@ $< + %.o: %.c $(CC) $(CFLAGS) -c -o $@ $< -videohook: .libs - $(MAKE) -C vhook all +documentation: $(addprefix doc/, ffmpeg-doc.html faq.html ffserver-doc.html \ + ffplay-doc.html general.html hooks.html \ + $(ALLMANPAGES)) + +doc/%.html: doc/%.texi + texi2html -monolithic -number $< + mv $(@F) $@ + +doc/%.pod: doc/%-doc.texi + doc/texi2pod.pl $< $@ -documentation: - $(MAKE) -C doc all +doc/%.1: doc/%.pod + pod2man --section=1 --center=" " --release=" " $< > $@ -install: install-progs install-libs install-headers +install: install-libs install-headers $(INSTALL_TARGETS-yes) ifeq ($(BUILD_SHARED),yes) -install-progs: $(PROGS) install-libs -else -install-progs: $(PROGS) +install-progs: install-libs endif - install -d "$(bindir)" - install -c -m 755 $(PROGS) "$(bindir)" +install-progs: $(PROGS) + install -d "$(BINDIR)" + install -c -m 755 $(PROGS) "$(BINDIR)" # Create the Windows installer. wininstaller: all install makensis ffinstall.nsi install-man: - install -d "$(mandir)/man1" - install -m 644 $(MANPAGES) "$(mandir)/man1" + install -d "$(MANDIR)/man1" + install -m 644 $(MANPAGES) "$(MANDIR)/man1" -install-vhook: - $(MAKE) -C vhook install +install-vhook: videohook + install -d "$(SHLIBDIR)/vhook" + install -m 755 $(HOOKS) "$(SHLIBDIR)/vhook" install-libs: - $(MAKE) -C libavutil install-libs - $(MAKE) -C libavcodec install-libs - $(MAKE) -C libavformat install-libs -ifeq ($(CONFIG_PP),yes) - $(MAKE) -C libpostproc install-libs -endif -ifeq ($(CONFIG_SWSCALER),yes) - $(MAKE) -C libswscale install-libs -endif - -ifeq ($(BUILD_SHARED),yes) - -$(LDCONFIG) -endif + $(MAKE) -C libavutil install-libs + $(MAKE) -C libavcodec install-libs + $(MAKE) -C libavformat install-libs + $(MAKE) -C libavdevice install-libs + $(MAKE-$(CONFIG_PP)) -C libpostproc install-libs + $(MAKE-$(CONFIG_SWSCALER)) -C libswscale install-libs install-headers: - $(MAKE) -C libavutil install-headers - $(MAKE) -C libavcodec install-headers - $(MAKE) -C libavformat install-headers -ifeq ($(CONFIG_PP),yes) - $(MAKE) -C libpostproc install-headers -endif - $(MAKE) -C libswscale install-headers + $(MAKE) -C libavutil install-headers + $(MAKE) -C libavcodec install-headers + $(MAKE) -C libavformat install-headers + $(MAKE) -C libavdevice install-headers + $(MAKE-$(CONFIG_PP)) -C libpostproc install-headers + $(MAKE) -C libswscale install-headers + $(MAKE-$(CONFIG_AVFILTER)) -C libavfilter install-headers uninstall: uninstall-progs uninstall-libs uninstall-headers uninstall-man uninstall-vhook uninstall-progs: - rm -f $(addprefix $(bindir)/, $(ALLPROGS)) + rm -f $(addprefix "$(BINDIR)/", $(ALLPROGS)) uninstall-man: - rm -f $(addprefix $(mandir)/man1/,$(ALLMANPAGES)) + rm -f $(addprefix "$(MANDIR)/man1/",$(ALLMANPAGES)) uninstall-vhook: - $(MAKE) -C vhook uninstall + rm -f $(addprefix "$(SHLIBDIR)/",$(ALLHOOKS_SRCS:.c=$(SLIBSUF))) + -rmdir "$(SHLIBDIR)/vhook/" uninstall-libs: $(MAKE) -C libavutil uninstall-libs $(MAKE) -C libavcodec uninstall-libs $(MAKE) -C libavformat uninstall-libs + $(MAKE) -C libavdevice uninstall-libs $(MAKE) -C libpostproc uninstall-libs + $(MAKE) -C libswscale uninstall-libs + $(MAKE) -C libavfilter uninstall-libs uninstall-headers: $(MAKE) -C libavutil uninstall-headers $(MAKE) -C libavcodec uninstall-headers $(MAKE) -C libavformat uninstall-headers + $(MAKE) -C libavdevice uninstall-headers $(MAKE) -C libpostproc uninstall-headers - -rmdir "$(incdir)" - -rmdir "$(prefix)/include/postproc" - -depend dep: .depend - $(MAKE) -C libavutil depend - $(MAKE) -C libavcodec depend - $(MAKE) -C libavformat depend -ifeq ($(CONFIG_PP),yes) - $(MAKE) -C libpostproc depend -endif -ifeq ($(CONFIG_SWSCALER),yes) - $(MAKE) -C libswscale depend -endif -ifeq ($(CONFIG_VHOOK),yes) - $(MAKE) -C vhook depend -endif + $(MAKE) -C libswscale uninstall-headers + $(MAKE) -C libavfilter uninstall-headers + -rmdir "$(INCDIR)" + +depend dep: .depend .vhookdep + $(MAKE) -C libavutil depend + $(MAKE) -C libavcodec depend + $(MAKE) -C libavformat depend + $(MAKE) -C libavdevice depend + $(MAKE-$(CONFIG_PP)) -C libpostproc depend + $(MAKE-$(CONFIG_SWSCALER)) -C libswscale depend + $(MAKE-$(CONFIG_AVFILTER)) -C libavfilter depend .depend: $(SRCS) version.h $(CC) -MM $(CFLAGS) $(SDL_CFLAGS) $(filter-out %.h,$^) 1>.depend +# gcc stupidly only outputs the basename of targets with -MM +.vhookdep: $(ALLHOOKS_SRCS) version.h + $(CC) $(VHOOKCFLAGS) -MM $^ | sed 's,^\([a-z]\),vhook/\1,' > $@ + $(DEP_LIBS): lib .libs: $(DEP_LIBS) @@ -202,34 +238,205 @@ clean: $(MAKE) -C libavutil clean $(MAKE) -C libavcodec clean $(MAKE) -C libavformat clean + $(MAKE) -C libavdevice clean $(MAKE) -C libpostproc clean $(MAKE) -C libswscale clean - $(MAKE) -C tests clean - $(MAKE) -C vhook clean - $(MAKE) -C doc clean - rm -f *.o *.d *~ .libs gmon.out TAGS $(ALLPROGS) $(ALLPROGS_G) \ - output_example$(EXESUF) qt-faststart$(EXESUF) cws2fws$(EXESUF) + $(MAKE) -C libavfilter clean + rm -f *.o *~ .libs gmon.out TAGS $(ALLPROGS) $(ALLPROGS_G) \ + output_example$(EXESUF) + rm -f doc/*.html doc/*.pod doc/*.1 + rm -rf tests/vsynth1 tests/vsynth2 tests/data tests/asynth1.sw tests/*~ + rm -f $(addprefix tests/,$(addsuffix $(EXESUF),audiogen videogen rotozoom seek_test tiny_psnr)) + rm -f $(addprefix tools/,$(addsuffix $(EXESUF),cws2fws pktdumper qt-faststart trasher)) + rm -f vhook/*.o vhook/*~ vhook/*.so vhook/*.dylib vhook/*.dll distclean: clean $(MAKE) -C libavutil distclean $(MAKE) -C libavcodec distclean $(MAKE) -C libavformat distclean + $(MAKE) -C libavdevice distclean $(MAKE) -C libpostproc distclean $(MAKE) -C libswscale distclean - $(MAKE) -C tests distclean - $(MAKE) -C vhook distclean - rm -f .depend version.h config.* *.pc + $(MAKE) -C libavfilter distclean + rm -f .depend .vhookdep version.h config.* *.pc TAGS: etags *.[ch] libavformat/*.[ch] libavcodec/*.[ch] # regression tests -codectest libavtest test-server fulltest test mpeg4 mpeg: $(PROGS) - $(MAKE) -C tests $@ +fulltest test: codectest libavtest seektest + +FFMPEG_REFFILE = $(SRC_PATH)/tests/ffmpeg.regression.ref +FFSERVER_REFFILE = $(SRC_PATH)/tests/ffserver.regression.ref +LIBAV_REFFILE = $(SRC_PATH)/tests/libav.regression.ref +ROTOZOOM_REFFILE = $(SRC_PATH)/tests/rotozoom.regression.ref +SEEK_REFFILE = $(SRC_PATH)/tests/seek.regression.ref + +CODEC_TESTS = $(addprefix regtest-, \ + mpeg \ + mpeg2 \ + mpeg2thread \ + msmpeg4v2 \ + msmpeg4 \ + wmv1 \ + wmv2 \ + h261 \ + h263 \ + h263p \ + mpeg4 \ + huffyuv \ + rc \ + mpeg4adv \ + mpeg4thread \ + mp4psp \ + error \ + mpeg4nr \ + mpeg1b \ + mjpeg \ + ljpeg \ + jpegls \ + rv10 \ + rv20 \ + asv1 \ + asv2 \ + flv \ + ffv1 \ + snow \ + snowll \ + dv \ + dv50 \ + svq1 \ + flashsv \ + mp2 \ + ac3 \ + g726 \ + adpcm_ima_wav \ + adpcm_ms \ + adpcm_yam \ + adpcm_swf \ + flac \ + wma \ + ) + +LAVF_TESTS = $(addprefix regtest-, \ + avi \ + asf \ + rm \ + mpg \ + ts \ + swf \ + ffm \ + flv_fmt \ + mov \ + dv_fmt \ + gxf \ + nut \ + mkv \ + pbmpipe \ + pgmpipe \ + ppmpipe \ + gif \ + yuv4mpeg \ + pgm \ + ppm \ + bmp \ + tga \ + tiff \ + sgi \ + jpg \ + wav \ + alaw \ + mulaw \ + au \ + mmf \ + aiff \ + voc \ + ogg \ + pixfmt \ + ) + +REGFILES = $(addprefix tests/data/,$(addsuffix .$(1),$(2:regtest-%=%))) + +CODEC_ROTOZOOM = $(call REGFILES,rotozoom.regression,$(CODEC_TESTS)) +CODEC_VSYNTH = $(call REGFILES,vsynth.regression,$(CODEC_TESTS)) + +LAVF_REGFILES = $(call REGFILES,lavf.regression,$(LAVF_TESTS)) + +LAVF_REG = tests/data/lavf.regression +ROTOZOOM_REG = tests/data/rotozoom.regression +VSYNTH_REG = tests/data/vsynth.regression + +codectest: $(VSYNTH_REG) $(ROTOZOOM_REG) + diff -u -w $(FFMPEG_REFFILE) $(VSYNTH_REG) + diff -u -w $(ROTOZOOM_REFFILE) $(ROTOZOOM_REG) + +libavtest: $(LAVF_REG) + diff -u -w $(LIBAV_REFFILE) $(LAVF_REG) + +$(VSYNTH_REG) $(ROTOZOOM_REG) $(LAVF_REG): + cat $^ > $@ + +$(LAVF_REG): $(LAVF_REGFILES) +$(ROTOZOOM_REG): $(CODEC_ROTOZOOM) +$(VSYNTH_REG): $(CODEC_VSYNTH) + +$(CODEC_VSYNTH) $(CODEC_ROTOZOOM): $(CODEC_TESTS) + +$(LAVF_REGFILES): $(LAVF_TESTS) + +$(CODEC_TESTS) $(LAVF_TESTS): regtest-ref + +regtest-ref: ffmpeg$(EXESUF) tests/vsynth1/00.pgm tests/vsynth2/00.pgm tests/asynth1.sw + +$(CODEC_TESTS) regtest-ref: tests/tiny_psnr$(EXESUF) + $(SRC_PATH)/tests/regression.sh $@ vsynth tests/vsynth1 a + $(SRC_PATH)/tests/regression.sh $@ rotozoom tests/vsynth2 a + +$(LAVF_TESTS): + $(SRC_PATH)/tests/regression.sh $@ lavf tests/vsynth1 b + +seektest: codectest libavtest tests/seek_test$(EXESUF) + $(SRC_PATH)/tests/seek_test.sh $(SEEK_REFFILE) + +test-server: ffserver$(EXESUF) tests/vsynth1/00.pgm tests/asynth1.sw + @echo + @echo "Unfortunately ffserver is broken and therefore its regression" + @echo "test fails randomly. Treat the results accordingly." + @echo + $(SRC_PATH)/tests/server-regression.sh $(FFSERVER_REFFILE) $(SRC_PATH)/tests/test.conf + +ifeq ($(CONFIG_SWSCALER),yes) +test-server codectest $(CODEC_TESTS) libavtest: swscale_error +swscale_error: + @echo + @echo "This regression test is incompatible with --enable-swscaler." + @echo + @exit 1 +endif + +tests/vsynth1/00.pgm: tests/videogen$(EXESUF) + mkdir -p tests/vsynth1 + $(BUILD_ROOT)/$< 'tests/vsynth1/' + +tests/vsynth2/00.pgm: tests/rotozoom$(EXESUF) + mkdir -p tests/vsynth2 + $(BUILD_ROOT)/$< 'tests/vsynth2/' $(SRC_PATH)/tests/lena.pnm + +tests/asynth1.sw: tests/audiogen$(EXESUF) + $(BUILD_ROOT)/$< $@ + +%$(EXESUF): %.c + $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $< + +tests/seek_test$(EXESUF): tests/seek_test.c .libs + $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $< $(EXTRALIBS) + .PHONY: all lib videohook documentation install* wininstaller uninstall* .PHONY: dep depend clean distclean TAGS -.PHONY: codectest libavtest test-server fulltest test mpeg4 mpeg +.PHONY: codectest libavtest seektest test-server fulltest test +.PHONY: $(CODEC_TESTS) $(LAVF_TESTS) regtest-ref swscale-error -include .depend +-include .vhookdep diff --git a/contrib/ffmpeg/README b/contrib/ffmpeg/README index 9f905357e..b99967dc9 100644 --- a/contrib/ffmpeg/README +++ b/contrib/ffmpeg/README @@ -9,11 +9,20 @@ FFmpeg README 2) Licensing ------------ -* Read the file COPYING. ffmpeg and the associated libraries EXCEPT - libpostproc and libswscale are licensed under the GNU Lesser General +* Read the file COPYING.LGPL. FFmpeg and the associated libraries EXCEPT + for libpostproc and libswscale are licensed under the GNU Lesser General Public License. * libpostproc and libswscale are distributed under the GNU General Public - License and their compilation and use is optional in ffmpeg. + License, see the file COPYING.GPL for details. Their compilation and use + in FFmpeg is optional. -Fabrice Bellard. +* The file libavcodec/i386/idct_mmx.c is distributed under the GNU General + Public License. It is strictly an optimization and its use is optional. + +* The files libavcodec/jfdctfst.c, libavcodec/jfdctint.c, libavcodec/jrevdct.c + are taken from libjpeg, see the top of the files for licensing details. + +* The file libavcodec/fdctref.c is copyrighted by the MPEG Software Simulation + Group with all rights reserved. It is only used to create a DCT test program + and not compiled into libavcodec. diff --git a/contrib/ffmpeg/build_avopt b/contrib/ffmpeg/build_avopt deleted file mode 100755 index fcf165765..000000000 --- a/contrib/ffmpeg/build_avopt +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -sed 's/unsigned//g' |\ - sed 's/enum//g' |\ - egrep '^ *(int|float|double|AVRational|char *\*) *[a-zA-Z_0-9]* *;' |\ - sed 's/^ *\([^ ]*\)[ *]*\([^;]*\);.*$/{"\2", NULL, OFFSET(\2), FF_OPT_TYPE_\U\1, DEFAULT, \1_MIN, \1_MAX},/' |\ - sed 's/AVRATIONAL_M/INT_M/g'|\ - sed 's/TYPE_AVRATIONAL/TYPE_RATIONAL/g'|\ - sed 's/FLOAT_M/FLT_M/g'|\ - sed 's/FF_OPT_TYPE_CHAR/FF_OPT_TYPE_STRING/g' diff --git a/contrib/ffmpeg/clean-diff b/contrib/ffmpeg/clean-diff deleted file mode 100755 index 98e26a79f..000000000 --- a/contrib/ffmpeg/clean-diff +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -sed '/^+[^+]/!s/ /TaBBaT/g' |\ - expand -t `seq -s , 9 8 200` |\ - sed 's/TaBBaT/ /g' |\ - sed '/^+[^+]/s/ * $//' |\ - tr -d '\015' |\ - tr '\n' '°' |\ - sed 's/\(@@[^@]*@@°[^@]*\)/\n\1/g' |\ - egrep -v '@@[^@]*@@°(( [^°]*°)|([+-][[:space:]]*°)|(-[[:space:]]*([^°]*)°\+[[:space:]]*\5°))*$' |\ - tr -d '\n' |\ - tr '°' '\n' diff --git a/contrib/ffmpeg/cmdutils.c b/contrib/ffmpeg/cmdutils.c index d5095cec8..7acd61b14 100644 --- a/contrib/ffmpeg/cmdutils.c +++ b/contrib/ffmpeg/cmdutils.c @@ -18,14 +18,40 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#define HAVE_AV_CONFIG_H -#include "avformat.h" -#include "common.h" +#include <string.h> +#include <stdlib.h> +#include <errno.h> +#include <math.h> + +#include "avformat.h" +#include "avfilter.h" +#include "avdevice.h" #include "cmdutils.h" +#include "avstring.h" +#include "version.h" +#include "config.h" #undef exit + +double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max) +{ + char *tail; + const char *error; + double d = strtod(numstr, &tail); + if (*tail) + error= "Expected number for %s but found: %s\n"; + else if (d < min || d > max) + error= "The value for %s was %s which is not within %f - %f\n"; + else if(type == OPT_INT64 && (int64_t)d != d) + error= "Expected int64 for %s but found %s\n"; + else + return d; + fprintf(stderr, error, context, numstr, min, max); + exit(1); +} + void show_help_options(const OptionDef *options, const char *msg, int mask, int value) { const OptionDef *po; @@ -39,10 +65,10 @@ void show_help_options(const OptionDef *options, const char *msg, int mask, int printf("%s", msg); first = 0; } - pstrcpy(buf, sizeof(buf), po->name); + av_strlcpy(buf, po->name, sizeof(buf)); if (po->flags & HAS_ARG) { - pstrcat(buf, sizeof(buf), " "); - pstrcat(buf, sizeof(buf), po->argname); + av_strlcat(buf, " ", sizeof(buf)); + av_strlcat(buf, po->argname, sizeof(buf)); } printf("-%-17s %s\n", buf, po->help); } @@ -58,7 +84,8 @@ static const OptionDef* find_option(const OptionDef *po, const char *name){ return po; } -void parse_options(int argc, char **argv, const OptionDef *options) +void parse_options(int argc, char **argv, const OptionDef *options, + void (* parse_arg_function)(const char*)) { const char *opt, *arg; int optindex, handleoptions=1; @@ -97,11 +124,11 @@ unknown_opt: } else if (po->flags & OPT_BOOL) { *po->u.int_arg = 1; } else if (po->flags & OPT_INT) { - *po->u.int_arg = atoi(arg); + *po->u.int_arg = parse_number_or_die(opt+1, arg, OPT_INT64, INT_MIN, INT_MAX); } else if (po->flags & OPT_INT64) { - *po->u.int64_arg = atoll(arg); + *po->u.int64_arg = parse_number_or_die(opt+1, arg, OPT_INT64, INT64_MIN, INT64_MAX); } else if (po->flags & OPT_FLOAT) { - *po->u.float_arg = atof(arg); + *po->u.float_arg = parse_number_or_die(opt+1, arg, OPT_FLOAT, -INFINITY, INFINITY); } else if (po->flags & OPT_FUNC2) { if(po->u.func2_arg(opt+1, arg)<0) goto unknown_opt; @@ -109,7 +136,8 @@ unknown_opt: po->u.func_arg(arg); } } else { - parse_arg_file(opt); + if (parse_arg_function) + parse_arg_function(opt); } } } @@ -130,16 +158,91 @@ void print_error(const char *filename, int err) case AVERROR_NOFMT: fprintf(stderr, "%s: Unknown format\n", filename); break; - case AVERROR_IO: + case AVERROR(EIO): fprintf(stderr, "%s: I/O error occured\n" "Usually that means that input file is truncated and/or corrupted.\n", filename); break; - case AVERROR_NOMEM: + case AVERROR(ENOMEM): fprintf(stderr, "%s: memory allocation error occured\n", filename); break; + case AVERROR(ENOENT): + fprintf(stderr, "%s: no such file or directory\n", filename); + break; default: fprintf(stderr, "%s: Error while opening file\n", filename); break; } } + +void show_banner(const char *program_name, int program_birth_year) +{ + fprintf(stderr, "%s version " FFMPEG_VERSION ", Copyright (c) %d-2008 Fabrice Bellard, et al.\n", + program_name, program_birth_year); + fprintf(stderr, " configuration: " FFMPEG_CONFIGURATION "\n"); + fprintf(stderr, " libavutil version: " AV_STRINGIFY(LIBAVUTIL_VERSION) "\n"); + fprintf(stderr, " libavcodec version: " AV_STRINGIFY(LIBAVCODEC_VERSION) "\n"); + fprintf(stderr, " libavformat version: " AV_STRINGIFY(LIBAVFORMAT_VERSION) "\n"); + fprintf(stderr, " libavdevice version: " AV_STRINGIFY(LIBAVDEVICE_VERSION) "\n"); +#if ENABLE_AVFILTER + fprintf(stderr, " libavfilter version: " AV_STRINGIFY(LIBAVFILTER_VERSION) "\n"); +#endif + fprintf(stderr, " built on " __DATE__ " " __TIME__); +#ifdef __GNUC__ + fprintf(stderr, ", gcc: " __VERSION__ "\n"); +#else + fprintf(stderr, ", using a non-gcc compiler\n"); +#endif +} + +void show_version(const char *program_name) { + /* TODO: add function interface to avutil and avformat avdevice*/ + printf("%s " FFMPEG_VERSION "\n", program_name); + printf("libavutil %d\n" + "libavcodec %d\n" + "libavformat %d\n" + "libavdevice %d\n", + LIBAVUTIL_BUILD, avcodec_build(), LIBAVFORMAT_BUILD, LIBAVDEVICE_BUILD); +} + +void show_license(void) +{ +#ifdef CONFIG_NONFREE + printf( + "This version of FFmpeg has nonfree parts compiled in.\n" + "Therefore it is not legally redistributable.\n" + ); +#elif CONFIG_GPL + printf( + "FFmpeg is free software; you can redistribute it and/or modify\n" + "it under the terms of the GNU General Public License as published by\n" + "the Free Software Foundation; either version 2 of the License, or\n" + "(at your option) any later version.\n" + "\n" + "FFmpeg is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details.\n" + "\n" + "You should have received a copy of the GNU General Public License\n" + "along with FFmpeg; if not, write to the Free Software\n" + "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n" + ); +#else + printf( + "FFmpeg is free software; you can redistribute it and/or\n" + "modify it under the terms of the GNU Lesser General Public\n" + "License as published by the Free Software Foundation; either\n" + "version 2.1 of the License, or (at your option) any later version.\n" + "\n" + "FFmpeg is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" + "Lesser General Public License for more details.\n" + "\n" + "You should have received a copy of the GNU Lesser General Public\n" + "License along with FFmpeg; if not, write to the Free Software\n" + "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n" + ); +#endif +} diff --git a/contrib/ffmpeg/cmdutils.h b/contrib/ffmpeg/cmdutils.h index 13a61c09d..d06a1f8e8 100644 --- a/contrib/ffmpeg/cmdutils.h +++ b/contrib/ffmpeg/cmdutils.h @@ -19,8 +19,25 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _CMD_UTILS_H -#define _CMD_UTILS_H +#ifndef FFMPEG_CMDUTILS_H +#define FFMPEG_CMDUTILS_H + +#include <inttypes.h> + +/** + * Parses a string and returns its corresponding value as a double. + * Exits from the application if the string cannot be correctly + * parsed or the corresponding value is invalid. + * + * @param context the context of the value to be set (e.g. the + * corresponding commandline option name) + * @param numstr the string to be parsed + * @param type the type (OPT_INT64 or OPT_FLOAT) as which the + * string should be parsed + * @param min the minimum valid accepted value + * @param max the maximum valid accepted value + */ +double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max); typedef struct { const char *name; @@ -50,8 +67,41 @@ typedef struct { } OptionDef; void show_help_options(const OptionDef *options, const char *msg, int mask, int value); -void parse_options(int argc, char **argv, const OptionDef *options); -void parse_arg_file(const char *filename); + +/** + * Parses the command line arguments. + * @param options Array with the definitions required to interpret every + * option of the form: -<option_name> [<argument>] + * @param parse_arg_function Name of the function called to process every + * argument without a leading option name flag. NULL if such arguments do + * not have to be processed. + */ +void parse_options(int argc, char **argv, const OptionDef *options, + void (* parse_arg_function)(const char*)); + void print_error(const char *filename, int err); -#endif /* _CMD_UTILS_H */ +/** + * Prints the program banner to stderr. The banner contents depend on the + * current version of the repository and of the libav* libraries used by + * the program. + * @param program_name name of the program + * @param program_birth_year year of birth of the program + */ +void show_banner(const char *program_name, int program_birth_year); + +/** + * Prints the version of the program to stdout. The version message + * depends on the current versions of the repository and of the libav* + * libraries. + * @param program_name name of the program + */ +void show_version(const char *program_name); + +/** + * Prints the license of the program to stdout. The license depends on + * the license of the libraries compiled into the program. + */ +void show_license(void); + +#endif /* FFMPEG_CMDUTILS_H */ diff --git a/contrib/ffmpeg/common.mak b/contrib/ffmpeg/common.mak index 7989b9021..2ba85157b 100644 --- a/contrib/ffmpeg/common.mak +++ b/contrib/ffmpeg/common.mak @@ -8,26 +8,27 @@ SRC_DIR = "$(VPATH)" CFLAGS += $(CFLAGS-yes) OBJS += $(OBJS-yes) ASM_OBJS += $(ASM_OBJS-yes) +CPP_OBJS += $(CPP_OBJS-yes) CFLAGS += -DHAVE_AV_CONFIG_H -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \ -D_ISOC9X_SOURCE -I$(BUILD_ROOT) -I$(SRC_PATH) \ -I$(SRC_PATH)/libavutil $(OPTFLAGS) + SRCS := $(OBJS:.o=.c) $(ASM_OBJS:.o=.S) $(CPPOBJS:.o=.cpp) OBJS := $(OBJS) $(ASM_OBJS) $(CPPOBJS) -STATIC_OBJS := $(OBJS) $(STATIC_OBJS) -SHARED_OBJS := $(OBJS) $(SHARED_OBJS) -all: $(EXTRADEPS) $(LIB) $(SLIBNAME) +all: $(LIBNAME) $(SLIBNAME) -$(LIB): $(STATIC_OBJS) +$(LIBNAME): $(OBJS) rm -f $@ $(AR) rc $@ $^ $(EXTRAOBJS) $(RANLIB) $@ $(SLIBNAME): $(SLIBNAME_WITH_MAJOR) - ln -sf $^ $@ + $(LN_S) $^ $@ -$(SLIBNAME_WITH_MAJOR): $(SHARED_OBJS) +$(SLIBNAME_WITH_MAJOR): $(OBJS) + $(SLIB_CREATE_DEF_CMD) $(CC) $(SHFLAGS) $(LDFLAGS) -o $@ $^ $(EXTRALIBS) $(EXTRAOBJS) $(SLIB_EXTRA_CMD) @@ -37,63 +38,73 @@ $(SLIBNAME_WITH_MAJOR): $(SHARED_OBJS) %.o: %.S $(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $< -%: %.o $(LIB) +%: %.o $(LIBNAME) $(CC) $(LDFLAGS) -o $@ $^ $(EXTRALIBS) +%.ho: %.h + $(CC) $(CFLAGS) $(LIBOBJFLAGS) -Wno-unused -c -o $@ -x c $< + +ALLHEADERS = $(subst $(VPATH)/,,$(wildcard $(VPATH)/*.h)) +checkheaders: $(filter-out %_template.ho,$(ALLHEADERS:.h=.ho)) + depend dep: $(SRCS) $(CC) -MM $(CFLAGS) $^ 1>.depend clean:: - rm -f *.o *.d *~ *.a *.lib *.so *.so.* *.dylib *.dll \ - *.def *.dll.a *.exp + rm -f *.o *~ *.a *.lib *.so *.so.* *.dylib *.dll \ + *.def *.dll.a *.exp *.ho *.map $(TESTS) distclean: clean rm -f .depend -ifeq ($(BUILD_SHARED),yes) -INSTLIBTARGETS += install-lib-shared -endif -ifeq ($(BUILD_STATIC),yes) -INSTLIBTARGETS += install-lib-static -endif +INSTALL_TARGETS-$(BUILD_SHARED) += install-lib-shared +INSTALL_TARGETS-$(BUILD_STATIC) += install-lib-static install: install-libs install-headers -install-libs: $(INSTLIBTARGETS) +install-libs: $(INSTALL_TARGETS-yes) install-lib-shared: $(SLIBNAME) - install -d "$(shlibdir)" - install -m 755 $(SLIBNAME) "$(shlibdir)/$(SLIBNAME_WITH_VERSION)" - $(STRIP) "$(shlibdir)/$(SLIBNAME_WITH_VERSION)" - cd "$(shlibdir)" && \ - ln -sf $(SLIBNAME_WITH_VERSION) $(SLIBNAME_WITH_MAJOR) - cd "$(shlibdir)" && \ - ln -sf $(SLIBNAME_WITH_VERSION) $(SLIBNAME) + install -d "$(SHLIBDIR)" + install -m 755 $(SLIBNAME) "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)" + $(STRIP) "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)" + cd "$(SHLIBDIR)" && \ + $(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME_WITH_MAJOR) + cd "$(SHLIBDIR)" && \ + $(LN_S) $(SLIBNAME_WITH_VERSION) $(SLIBNAME) $(SLIB_INSTALL_EXTRA_CMD) -install-lib-static: $(LIB) - install -d "$(libdir)" - install -m 644 $(LIB) "$(libdir)" +install-lib-static: $(LIBNAME) + install -d "$(LIBDIR)" + install -m 644 $(LIBNAME) "$(LIBDIR)" $(LIB_INSTALL_EXTRA_CMD) +INCINSTDIR = $(INCDIR)/lib$(NAME) + install-headers: - install -d "$(incdir)" - install -d "$(libdir)/pkgconfig" - install -m 644 $(addprefix $(SRC_DIR)/,$(HEADERS)) "$(incdir)" - install -m 644 $(BUILD_ROOT)/lib$(NAME).pc "$(libdir)/pkgconfig" + install -d "$(INCINSTDIR)" + install -d "$(LIBDIR)/pkgconfig" + install -m 644 $(addprefix $(SRC_DIR)/,$(HEADERS)) "$(INCINSTDIR)" + install -m 644 $(BUILD_ROOT)/lib$(NAME).pc "$(LIBDIR)/pkgconfig" uninstall: uninstall-libs uninstall-headers uninstall-libs: - -rm -f "$(shlibdir)/$(SLIBNAME_WITH_MAJOR)" \ - "$(shlibdir)/$(SLIBNAME)" \ - "$(shlibdir)/$(SLIBNAME_WITH_VERSION)" - -rm -f "$(libdir)/$(LIB)" + -rm -f "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR)" \ + "$(SHLIBDIR)/$(SLIBNAME)" \ + "$(SHLIBDIR)/$(SLIBNAME_WITH_VERSION)" + -$(SLIB_UNINSTALL_EXTRA_CMD) + -rm -f "$(LIBDIR)/$(LIBNAME)" + +uninstall-headers:: + rm -f $(addprefix "$(INCINSTDIR)/",$(HEADERS)) + rm -f "$(LIBDIR)/pkgconfig/lib$(NAME).pc" + +tests: $(TESTS) -uninstall-headers: - rm -f $(addprefix "$(incdir)/",$(HEADERS)) - rm -f "$(libdir)/pkgconfig/lib$(NAME).pc" +%-test$(EXESUF): %.c $(LIBNAME) + $(CC) $(CFLAGS) $(LDFLAGS) -DTEST -o $@ $^ $(EXTRALIBS) -.PHONY: all depend dep clean distclean install* uninstall* +.PHONY: all depend dep clean distclean install* uninstall* tests -include .depend diff --git a/contrib/ffmpeg/configure b/contrib/ffmpeg/configure index 12f2877d2..74876f064 100755 --- a/contrib/ffmpeg/configure +++ b/contrib/ffmpeg/configure @@ -61,16 +61,19 @@ show_help(){ echo " --libdir=DIR install libs in DIR [PREFIX/lib]" echo " --shlibdir=DIR install shared libs in DIR [PREFIX/lib]" echo " --incdir=DIR install includes in DIR [PREFIX/include/ffmpeg]" - echo " --mandir=DIR install man page in DIR [PREFIX/man]" - echo " --enable-mingwce enable MinGW native/cross WinCE compile" + echo " --mandir=DIR install man page in DIR [PREFIX/share/man]" echo " --enable-static build static libraries [default=yes]" echo " --disable-static do not build static libraries [default=no]" echo " --enable-shared build shared libraries [default=no]" echo " --disable-shared do not build shared libraries [default=yes]" echo " --enable-gpl allow use of GPL code, the resulting libav*" echo " and ffmpeg will be under GPL [default=no]" + echo " --enable-nonfree allow use of nonfree code, the resulting libav*" + echo " and ffmpeg will be unredistributable [default=no]" echo " --enable-pp enable GPLed postprocessing support [default=no]" echo " --enable-swscaler software scaler support [default=no]" + echo " --enable-avfilter video filter support (replaces vhook) [default=no]" + echo " --enable-avfilter-lavf video filters dependant on avformat [default=no]" echo " --enable-beosthreads use BeOS threads [default=no]" echo " --enable-os2threads use OS/2 threads [default=no]" echo " --enable-pthreads use pthreads [default=no]" @@ -79,30 +82,26 @@ show_help(){ echo echo "External library support:" echo " --enable-sunmlib use Sun medialib [default=no]" - echo " --enable-dc1394 enable IIDC-1394 grabbing using libdc1394" - echo " and libraw1394 [default=no]" echo " --enable-liba52 enable GPLed liba52 support [default=no]" echo " --enable-liba52bin open liba52.so.0 at runtime [default=no]" echo " --enable-avisynth allow reading AVISynth script files [default=no]" - echo " --enable-libdts enable GPLed libdts support [default=no]" + echo " --enable-libamr-nb enable libamr-nb floating point audio codec" + echo " --enable-libamr-wb enable libamr-wb floating point audio codec" + echo " --enable-libdc1394 enable IIDC-1394 grabbing using libdc1394" + echo " and libraw1394 [default=no]" echo " --enable-libfaac enable FAAC support via libfaac [default=no]" echo " --enable-libfaad enable FAAD support via libfaad [default=no]" - echo " --enable-libfaadbin build FAAD support with runtime linking [default=no]" + echo " --enable-libfaadbin open libfaad.so.0 at runtime [default=no]" echo " --enable-libgsm enable GSM support via libgsm [default=no]" echo " --enable-libmp3lame enable MP3 encoding via libmp3lame [default=no]" echo " --enable-libnut enable NUT (de)muxing via libnut," echo " native demuxer exists [default=no]" - echo " --enable-libogg enable Ogg muxing via libogg [default=no]" echo " --enable-libtheora enable Theora encoding via libtheora [default=no]" - echo " --enable-libvorbis enable Vorbis en/decoding via libvorbis," - echo " native implementations exist [default=no]" - echo " --enable-x264 enable H.264 encoding via x264 [default=no]" - echo " --enable-xvid enable Xvid encoding via xvidcore," + echo " --enable-libvorbis enable Vorbis encoding via libvorbis," + echo " native implementation exists [default=no]" + echo " --enable-libx264 enable H.264 encoding via x264 [default=no]" + echo " --enable-libxvid enable Xvid encoding via xvidcore," echo " native MPEG-4/Xvid encoder exists [default=no]" - echo " --enable-amr-nb enable amr-nb floating point audio codec" - echo " --enable-amr-nb-fixed enable amr-nb fixed-point codec" - echo " --enable-amr-wb enable amr-wb floating point audio codec" - echo " --enable-amr-if2 enable amr-wb IF2 audio codec" echo "" echo "Advanced options (experts only):" echo " --source-path=PATH path to source code [$source_path]" @@ -125,12 +124,6 @@ show_help(){ echo " --disable-armv6 disable armv6 usage" echo " --disable-iwmmxt disable iwmmxt usage" echo " --disable-altivec disable AltiVec usage" - echo " --disable-audio-oss disable OSS audio support [default=no]" - echo " --disable-audio-beos disable BeOS audio support [default=no]" - echo " --disable-v4l disable video4linux grabbing [default=no]" - echo " --disable-v4l2 disable video4linux2 grabbing [default=no]" - echo " --disable-bktr disable bktr video grabbing [default=no]" - echo " --disable-dv1394 disable DV1394 grabbing [default=no]" echo " --disable-network disable network support [default=no]" echo " --disable-ipv6 disable ipv6 support [default=no]" echo " --disable-zlib disable zlib [default=no]" @@ -138,11 +131,12 @@ show_help(){ echo " --disable-debug disable debugging symbols" echo " --disable-mpegaudio-hp faster (but less accurate)" echo " MPEG audio decoding [default=no]" - echo " --disable-protocols disable I/O protocols support [default=no]" + echo " --enable-gray enable full grayscale support (slower color)" echo " --disable-ffmpeg disable ffmpeg build" echo " --disable-ffserver disable ffserver build" echo " --disable-ffplay disable ffplay build" echo " --enable-small optimize for size instead of speed" + echo " --enable-hardcoded-tables use hardcoded tables instead of runtime generation" echo " --enable-memalign-hack emulate memalign, interferes with memory debuggers" echo " --disable-encoder=NAME disables encoder NAME" echo " --enable-encoder=NAME enables encoder NAME" @@ -159,10 +153,26 @@ show_help(){ echo " --enable-parser=NAME enables parser NAME" echo " --disable-parser=NAME disables parser NAME" echo " --disable-parsers disables all parsers" + echo " --enable-bsf=NAME enables bitstream filter NAME" + echo " --disable-bsf=NAME disables bitstream filter NAME" + echo " --disable-bsfs disables all bitstream filters" + echo " --enable-protocol=NAME enables protocol NAME" + echo " --disable-protocol=NAME disables protocol NAME" + echo " --disable-protocols disables all protocols" + echo " --disable-devices disables all devices" + echo " --list-decoders show all available decoders" + echo " --list-encoders show all available encoders" + echo " --list-muxers show all available muxers" + echo " --list-demuxers show all available demuxers" + echo " --list-parsers show all available parsers" + echo " --list-protocols show all available protocols" + echo " --list-bsfs show all available bitstream filters" + echo " --list-indevs show all available input devices" + echo " --list-outdevs show all available output devices" echo echo "Developer options (useful when working on FFmpeg itself):" echo " --enable-gprof enable profiling with gprof [$gprof]" - echo " --disable-opts disable compiler optimizations" + echo " --disable-optimizations disable compiler optimizations" echo " --enable-extra-warnings enable more compiler warnings" echo " --disable-strip disable stripping of executables and shared libraries" echo "" @@ -176,7 +186,7 @@ log(){ log_file(){ log BEGIN $1 - cat -n $1 >>$logfile + pr -n -t $1 >>$logfile log END $1 } @@ -190,7 +200,7 @@ die(){ cat <<EOF If you think configure made a mistake, make sure you are using the latest version from SVN. If the latest version fails, report the problem to the -ffmpeg-devel@mplayerhq.hu mailing list or IRC #ffmpeg on irc.freenode.net. +ffmpeg-user@mplayerhq.hu mailing list or IRC #ffmpeg on irc.freenode.net. EOF if enabled logging; then cat <<EOF @@ -207,13 +217,13 @@ EOF exit 1 } -# "tr '[a-z]' '[A-Z]'" is a workaround for Solaris tr not grokking "tr a-z A-Z" +# Avoid locale weirdness, besides we really just want to translate ASCII. toupper(){ - echo "$@" | tr '[a-z]' '[A-Z]' + echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ } tolower(){ - echo "$@" | tr '[A-Z]' '[a-z]' + echo "$@" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz } set_all(){ @@ -283,6 +293,15 @@ disabled_any(){ done } +is_in(){ + value=$1 + shift + for var in $*; do + [ $var = $value ] && return 0 + done + return 1 +} + check_deps(){ for cfg; do enabled ${cfg}_checking && die "Circular dependency for $cfg." @@ -299,6 +318,11 @@ check_deps(){ enabled_all $dep_all || disable $cfg enabled_any $dep_any || disable $cfg + if enabled $cfg; then + eval dep_extralibs="\$${cfg}_extralibs" + test -n "$dep_extralibs" && add_extralibs $dep_extralibs + fi + disable ${cfg}_checking done } @@ -309,10 +333,13 @@ print_config(){ makefile=$3 shift 3 for cfg; do + ucname="`toupper $cfg`" if enabled $cfg; then - ucname="${pfx}`toupper $cfg`" - echo "#define ${ucname} 1" >> $header - echo "${ucname}=yes" >> $makefile + echo "#define ${pfx}${ucname} 1" >> $header + echo "#define ENABLE_${ucname} 1" >> $header + echo "${pfx}${ucname}=yes" >> $makefile + else + echo "#define ENABLE_${ucname} 0" >> $header fi done } @@ -391,10 +418,27 @@ check_cpp(){ check_cmd $cc $CFLAGS "$@" -E -o $TMPO $TMPC } +check_asm(){ + log check_asm "$@" + name="$1" + asm="$2" + shift 2 + check_cc "$@" <<EOF && enable $name || disable $name +int foo(void){ + asm volatile($asm); +} +EOF +} + check_ld(){ log check_ld "$@" check_cc || return - check_cmd $cc $LDFLAGS "$@" -o $TMPE $TMPO $extralibs + flags='' + libs='' + for f; do + test "${f}" = "${f#-l}" && flags="$flags $f" || libs="$libs $f" + done + check_cmd $cc $LDFLAGS $flags -o $TMPE $TMPO $extralibs $libs } check_cflags(){ @@ -407,7 +451,7 @@ EOF check_ldflags(){ log check_ldflags "$@" check_ld "$@" <<EOF && add_ldflags "$@" -int main(){ +int main(void){ return 0; } EOF @@ -432,7 +476,7 @@ check_func(){ disable $func check_ld "$@" <<EOF && enable $func extern int $func(); -int main(){ +int main(void){ $func(); } EOF @@ -451,7 +495,7 @@ check_func2(){ done check_ld "$@" <<EOF && enable $func $incs -int main(){ +int main(int argc, char **argv){ (void) $func; return 0; } @@ -486,6 +530,49 @@ check_exec(){ check_ld "$@" && { enabled cross_compile || $TMPE >>$logfile 2>&1; } } +check_exec_crash(){ + code=`cat` + + # exit() is not async signal safe. _Exit (C99) and _exit (POSIX) + # are safe but may not be available everywhere. Thus we use + # raise(SIGTERM) instead. The check is run in a subshell so we + # can redirect the "Terminated" message from the shell. SIGBUS + # is not defined by standard C so it is used conditionally. + + (check_exec "$@") >>$logfile 2>&1 <<EOF +#include <signal.h> +static void sighandler(int sig){ + raise(SIGTERM); +} +int main(void){ + signal(SIGILL, sighandler); + signal(SIGFPE, sighandler); + signal(SIGSEGV, sighandler); +#ifdef SIGBUS + signal(SIGBUS, sighandler); +#endif + { $code } +} +EOF +} + +check_type(){ + log check_type "$@" + headers=$1 + type=$2 + shift 2 + disable $type + incs="" + for hdr in $headers; do + incs="$incs +#include <$hdr>" + done + check_cc "$@" <<EOF && enable $type +$incs +$type v; +EOF +} + require(){ name="$1" header="$2" @@ -525,59 +612,60 @@ apply(){ "$@" < "$file" > "$file.tmp" && mv "$file.tmp" "$file" || rm "$file.tmp" } -CONFIG_LIST=' - encoders +COMPONENT_LIST=" + bsfs decoders - parsers - muxers demuxers - amr - amr_nb - amr_nb_fixed - amr_wb - audio_beos - audio_oss + encoders + filters + indevs + muxers + outdevs + parsers + protocols +" + +CONFIG_LIST=" + $COMPONENT_LIST + avfilter + avfilter_lavf avisynth beos_netserver - bktr - dc1394 - dv1394 - ebp_available - ebx_available ffmpeg ffplay ffserver gpl gprof + gray + hardcoded_tables ipv6 liba52 liba52bin - libdts + libamr_nb + libamr_wb + libdc1394 libfaac libfaad libfaadbin libgsm libmp3lame libnut - libogg libtheora libvorbis + libx264 + libxvid memalign_hack mpegaudio_hp network + nonfree powerpc_perf pp - protocols + small swscaler vhook - v4l - v4l2 - wince x11grab - x264 - xvid zlib -' +" THREADS_LIST=' beosthreads @@ -586,15 +674,44 @@ THREADS_LIST=' w32threads ' -HAVE_LIST=" - $THREADS_LIST +ARCH_LIST=' + alpha + armv4l + bfin + ia64 + m68k + mips + parisc + powerpc + s390 + sh4 + sparc + sparc64 + x86 + x86_32 + x86_64 +' + +ARCH_EXT_LIST=' altivec - altivec_h armv5te armv6 + iwmmxt + mmi + mmx + ssse3 + vis +' + +HAVE_LIST=" + $ARCH_EXT_LIST + $THREADS_LIST + altivec_h arpa_inet_h byteswap_h + closesocket cmov + conio_h dcbzl dev_bktr_ioctl_bt848_h dev_bktr_ioctl_meteor_h @@ -603,98 +720,152 @@ HAVE_LIST=" dev_video_bktr_ioctl_bt848_h dlfcn_h dlopen + ebp_available + ebx_available fast_64bit fast_cmov + fast_unaligned + fork freetype2 + gethrtime + GetProcessTimes + getrusage imlib2 inet_aton - iwmmxt - localtime_r + inline_asm + libdc1394_1 + libdc1394_2 + llrint + lrint lrintf machine_ioctl_bt848_h machine_ioctl_meteor_h malloc_h memalign + mkstemp mlib - mmi - mmx - os2 + ppc64 + round + roundf sdl sdl_video_size + socklen_t soundcard_h - sys_poll_h + poll_h + sys_select_h sys_soundcard_h + termios_h threads + winsock2_h " -TARGET_LIST=' - altivec - armv5te - armv6 - iwmmxt - mmi - mmx -' - CMDLINE_SELECT=" + $ARCH_EXT_LIST $CONFIG_LIST - $TARGET_LIST $THREADS_LIST - amr_if2 debug extra_warnings + optimizations shared static " +# code dependency declarations + +# architecture extensions +altivec_deps="powerpc" +armv5te_deps="armv4l" +armv6_deps="armv4l" +iwmmxt_deps="armv4l" +mmi_deps="mips" +mmx_deps="x86" +ssse3_deps="x86" +vis_deps="sparc" + +# decoders / encoders +ac3_decoder_deps="gpl" dxa_decoder_deps="zlib" flashsv_decoder_deps="zlib" flashsv_encoder_deps="zlib" +flv_decoder_deps="h263_decoder" +h263_decoder_deps="h263_parser mpeg4video_parser" +h263i_decoder_deps="h263_decoder" +h264_decoder_deps="h264_parser" mpeg_xvmc_decoder_deps="xvmc" +mpeg4_decoder_deps="h263_decoder" +msmpeg4v1_decoder_deps="h263_decoder" +msmpeg4v2_decoder_deps="h263_decoder" +msmpeg4v3_decoder_deps="h263_decoder" png_decoder_deps="zlib" png_encoder_deps="zlib" -x264_encoder_deps="x264" -xvid_encoder_deps="xvid" +svq3_decoder_deps="h264_parser" +vc1_decoder_deps="h263_decoder" +wmv1_decoder_deps="h263_decoder" +wmv2_decoder_deps="h263_decoder" +wmv3_decoder_deps="h263_decoder" zmbv_decoder_deps="zlib" zmbv_encoder_deps="zlib" -aac_decoder_deps="libfaad" -mpeg4aac_decoder_deps="libfaad" -amr_nb_decoder_deps_any="amr_nb amr_nb_fixed" -amr_nb_encoder_deps_any="amr_nb amr_nb_fixed" -amr_wb_decoder_deps="amr_wb" -amr_wb_encoder_deps="amr_wb" -dts_decoder_deps="libdts" -faac_encoder_deps="libfaac" +# external libraries liba52_decoder_deps="liba52" +liba52bin_decoder_extralibs='$ldl' +libamr_nb_decoder_deps="libamr_nb" +libamr_nb_encoder_deps="libamr_nb" +libamr_wb_decoder_deps="libamr_wb" +libamr_wb_encoder_deps="libamr_wb" +libfaac_encoder_deps="libfaac" +libfaad_decoder_deps="libfaad" +libfaadbin_decoder_extralibs='$ldl' libgsm_decoder_deps="libgsm" libgsm_encoder_deps="libgsm" libgsm_ms_decoder_deps="libgsm" libgsm_ms_encoder_deps="libgsm" +libmp3lame_encoder_deps="libmp3lame" libtheora_encoder_deps="libtheora" -mp3lame_encoder_deps="libmp3lame" -oggvorbis_decoder_deps="libvorbis" -oggvorbis_encoder_deps="libvorbis" - -audio_demuxer_deps_any="audio_oss audio_beos" -audio_muxer_deps_any="audio_oss audio_beos" -dc1394_demuxer_deps="dc1394" -dv1394_demuxer_deps="dv1394" -gxf_muxer_deps="gpl" +libvorbis_encoder_deps="libvorbis" +libx264_encoder_deps="libx264" +libxvid_encoder_deps="libxvid" +mpeg4aac_decoder_deps="libfaad" + +# demuxers / muxers +ac3_demuxer_deps="ac3_parser" +audio_beos_demuxer_deps="audio_beos" +audio_beos_demuxer_extralibs="-lmedia -lbe" +audio_beos_muxer_deps="audio_beos" +audio_beos_muxer_extralibs="-lmedia -lbe" +avisynth_demuxer_deps="avisynth" +bktr_demuxer_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h" +dv1394_demuxer_deps="dv1394 dv_demuxer" +libdc1394_demuxer_deps="libdc1394" libnut_demuxer_deps="libnut" libnut_muxer_deps="libnut" -ogg_muxer_deps="libogg" +mp3_demuxer_deps="mpegaudio_parser" +oss_demuxer_deps_any="soundcard_h sys_soundcard_h" +oss_muxer_deps_any="soundcard_h sys_soundcard_h" redir_demuxer_deps="network" -rtp_muxer_deps="network" -rtsp_demuxer_deps="network" -sdp_demuxer_deps="network" -v4l2_demuxer_deps="v4l2" -video_grab_device_demuxer_deps_any="v4l bktr" -x11_grab_device_demuxer_deps="x11grab" - +rtp_muxer_deps="network rtp_protocol" +rtsp_demuxer_deps="sdp_demuxer" +sdp_demuxer_deps="rtp_protocol mpegts_demuxer" +v4l2_demuxer_deps="linux_videodev2_h" +v4l_demuxer_deps="linux_videodev_h" +x11_grab_device_demuxer_deps="x11grab XShmCreateImage" +x11_grab_device_demuxer_extralibs="-lX11 -lXext" + +# protocols +http_protocol_deps="network" +rtp_protocol_deps="udp_protocol" +tcp_protocol_deps="network" +udp_protocol_deps="network" + +# filters +vsrc_movie_deps="avfilter_lavf" + +# programs ffplay_deps="sdl" -ffserver_deps="network protocols muxers" -network_deps="protocols" +ffserver_deps="ffm_muxer rtp_protocol rtsp_demuxer" +ffserver_extralibs='$ldl' +vhook_extralibs='$ldl' + # set temporary file name if test ! -z "$TMPDIR" ; then @@ -713,157 +884,111 @@ TMPH="${TMPDIR1}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.h" # default parameters -logging="yes" +enable logging logfile="config.err" # installation paths PREFIX="/usr/local" -libdir='${PREFIX}/lib' +libdir='$(PREFIX)/lib' shlibdir="$libdir" -incdir='${PREFIX}/include/ffmpeg' -mandir='${PREFIX}/man' -bindir='${PREFIX}/bin' +incdir='$(PREFIX)/include' +mandir='$(PREFIX)/share/man' +bindir='$(PREFIX)/bin' # toolchain -cross_prefix="" -cross_compile="no" cc="gcc" ar="ar" ranlib="ranlib" make="make" strip="strip" asmalign_pot="unknown" +ln_s="ln -sf" # machine arch=`uname -m` cpu="generic" -powerpc_perf="no" -mmx="default" -cmov="no" -fast_cmov="no" -armv5te="default" -armv6="default" -iwmmxt="default" -altivec="default" -dcbzl="no" -mmi="default" -bigendian="no" # OS targetos=$(tolower $(uname -s)) -beos_netserver="no" -os2="no" -wince="no" - -# non-library system interfaces -audio_beos="default" -audio_oss="yes" -bktr="yes" -dv1394="yes" -v4l2="yes" -v4l="yes" # libraries -amr_if2="no" -amr_nb="no" -amr_nb_fixed="no" -amr_wb="no" -avisynth="no" -dc1394="no" -dlfcn_h="no" -dlopen="no" -liba52="no" -liba52bin="no" -libdts="no" -libfaac="no" -libfaad2="no" -libfaad="no" -libfaadbin="no" -libgsm="no" -libmp3lame="no" -libnut="no" -libogg="no" -libtheora="no" -libvorbis="no" -mlib="no" -x11grab="no" -x264="no" -xvid="no" -zlib="yes" +enable zlib # configurable options -debug="yes" -dostrip="yes" -extra_warnings="no" -ffmpeg="yes" -ffplay="yes" -ffserver="yes" -gpl="no" -gprof="no" -ipv6="yes" -shared="no" -static="yes" -memalign_hack="no" -mpegaudio_hp="yes" -network="yes" -optimize="yes" -pp="no" -protocols="yes" -swscaler="no" +enable debug +enable dostrip +enable ffmpeg +enable ffplay +enable ffserver +enable ipv6 +enable static +enable mpegaudio_hp +enable network +enable optimizations +enable protocols vhook="default" -# threading -beosthreads="no" -os2threads="no" -pthreads="no" -w32threads="no" -thread_type="no" - # build settings SHFLAGS='-shared -Wl,-soname,$@' VHOOKSHFLAGS='$(SHFLAGS)' -LIBOBJFLAGS="" -FFLDFLAGS=-Wl,--warn-common LDLATEFLAGS='-Wl,-rpath-link,\$(BUILD_ROOT)/libavcodec -Wl,-rpath-link,\$(BUILD_ROOT)/libavformat -Wl,-rpath-link,\$(BUILD_ROOT)/libavutil' FFSERVERLDFLAGS=-Wl,-E -LDCONFIG="ldconfig" LIBPREF="lib" LIBSUF=".a" -LIB='$(LIBPREF)$(NAME)$(LIBSUF)' +FULLNAME='$(NAME)$(BUILDSUF)' +LIBNAME='$(LIBPREF)$(FULLNAME)$(LIBSUF)' SLIBPREF="lib" SLIBSUF=".so" -SLIBNAME='$(SLIBPREF)$(NAME)$(SLIBSUF)' +SLIBNAME='$(SLIBPREF)$(FULLNAME)$(SLIBSUF)' SLIBNAME_WITH_VERSION='$(SLIBNAME).$(LIBVERSION)' SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)' -EXESUF="" -BUILDSUF="" -LIB_INSTALL_EXTRA_CMD='$(RANLIB) "$(libdir)/$(LIB)"' +LIB_INSTALL_EXTRA_CMD='$(RANLIB) "$(LIBDIR)/$(LIBNAME)"' # find source path source_path="`dirname \"$0\"`" -source_path_used="yes" +enable source_path_used if test -z "$source_path" -o "$source_path" = "." ; then source_path="`pwd`" - source_path_used="no" + disable source_path_used else source_path="`cd \"$source_path\"; pwd`" echo "$source_path" | grep -q '[[:blank:]]' && - die "Out of tree builds are impossible with whitespace in source path." -fi - -if test x"$1" = x"-h" -o x"$1" = x"--help" ; then - show_help + die "Out of tree builds are impossible with whitespace in source path." fi FFMPEG_CONFIGURATION="$@" -ENCODER_LIST=`sed -n 's/^[^#]*ENC.*, *\(.*\)).*/\1_encoder/p' "$source_path/libavcodec/allcodecs.c"` -DECODER_LIST=`sed -n 's/^[^#]*DEC.*, *\(.*\)).*/\1_decoder/p' "$source_path/libavcodec/allcodecs.c"` -PARSER_LIST=`sed -n 's/^[^#]*PARSER.*, *\(.*\)).*/\1_parser/p' "$source_path/libavcodec/allcodecs.c"` -MUXER_LIST=`sed -n 's/^[^#]*_MUX.*, *\(.*\)).*/\1_muxer/p' "$source_path/libavformat/allformats.c"` -DEMUXER_LIST=`sed -n 's/^[^#]*DEMUX.*, *\(.*\)).*/\1_demuxer/p' "$source_path/libavformat/allformats.c"` - -enable $ENCODER_LIST $DECODER_LIST $PARSER_LIST $MUXER_LIST $DEMUXER_LIST +find_things(){ + thing=$1 + pattern=$2 + file=$source_path/$3 + sed -n "s/^[^#]*$pattern.*(.*, *\\(.*\\)).*/\\1_$thing/p" "$file" +} + +ENCODER_LIST=$(find_things encoder ENC libavcodec/allcodecs.c) +DECODER_LIST=$(find_things decoder DEC libavcodec/allcodecs.c) +PARSER_LIST=$(find_things parser PARSER libavcodec/allcodecs.c) +BSF_LIST=$(find_things bsf BSF libavcodec/allcodecs.c) +MUXER_LIST=$(find_things muxer _MUX libavformat/allformats.c) +DEMUXER_LIST=$(find_things demuxer DEMUX libavformat/allformats.c) +OUTDEV_LIST=$(find_things muxer _MUX libavdevice/alldevices.c) +INDEV_LIST=$(find_things demuxer DEMUX libavdevice/alldevices.c) +PROTOCOL_LIST=$(find_things protocol PROTOCOL libavformat/allformats.c) +VIDEO_FILTER_LIST=$(find_things vf_ VF_ libavfilter/allfilters.c) +SRC_FILTER_LIST=$(find_things vsrc_ VSRC_ libavfilter/allfilters.c) +FILTER_LIST="$SRC_FILTER_LIST $VIDEO_FILTER_LIST" + +enable $ARCH_EXT_LIST \ + $DECODER_LIST \ + $ENCODER_LIST \ + $PARSER_LIST \ + $BSF_LIST \ + $DEMUXER_LIST \ + $MUXER_LIST \ + $FILTER_LIST \ + $PROTOCOL_LIST \ + $INDEV_LIST \ + $OUTDEV_LIST \ die_unknown(){ echo "Unknown option \"$1\"." @@ -871,309 +996,328 @@ die_unknown(){ exit 1 } +show_list() { + suffix=_$1 + shift + echo $* | sed s/$suffix//g | tr ' ' '\n' | sort + exit 0 +} + for opt do - optval="${opt#*=}" - case "$opt" in - --log) - ;; - --log=*) logging="$optval" - ;; - --prefix=*) PREFIX="$optval" - ;; - --libdir=*) libdir="$optval" - ;; - --shlibdir=*) shlibdir="$optval" - ;; - --incdir=*) incdir="$optval" - ;; - --mandir=*) mandir="$optval" - ;; - --source-path=*) source_path="$optval" - ;; - --cross-prefix=*) cross_prefix="$optval" - ;; - --cross-compile) cross_compile="yes" - ;; - --target-os=*) targetos="$optval" - ;; - --cc=*) cc="$optval" - ;; - --make=*) make="$optval" - ;; - --extra-cflags=*) add_cflags "$optval" - ;; - --extra-ldflags=*) add_ldflags "$optval" - ;; - --extra-libs=*) add_extralibs "$optval" - ;; - --build-suffix=*) BUILDSUF="$optval" - ;; - --arch=*) arch="$optval" - ;; - --cpu=*) cpu="$optval" - ;; - --enable-mingwce) wince="yes" - ;; - --disable-opts) optimize="no" - ;; - --enable-small) optimize="small" - ;; - --enable-sunmlib) mlib="yes" - ;; - --disable-strip) dostrip="no" - ;; - --disable-encoders) disable $ENCODER_LIST - ;; - --disable-decoders) disable $DECODER_LIST - ;; - --disable-muxers) disable $MUXER_LIST - ;; - --disable-demuxers) disable $DEMUXER_LIST - ;; - --disable-parsers) disable $PARSER_LIST - ;; - --enable-*=*|--disable-*=*) - eval `echo "$opt" | sed 's/=/-/;s/--/action=/;s/-/ thing=/;s/-/ name=/'` - case "$thing" in - encoder|decoder|muxer|demuxer|parser) $action ${optval}_${thing} ;; - *) die_unknown "$opt" ;; - esac - ;; - --enable-?*|--disable-?*) - eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'` - echo "$CMDLINE_SELECT" | grep -q "^ *$option\$" || die_unknown $opt - $action $option - ;; - --help) show_help - ;; - *) - die_unknown $opt - ;; - esac + optval="${opt#*=}" + case "$opt" in + --log) + ;; + --log=*) logging="$optval" + ;; + --prefix=*) PREFIX="$optval" + ;; + --libdir=*) libdir="$optval" + ;; + --shlibdir=*) shlibdir="$optval" + ;; + --incdir=*) incdir="$optval" + ;; + --mandir=*) mandir="$optval" + ;; + --source-path=*) source_path="$optval" + ;; + --cross-prefix=*) cross_prefix="$optval" + ;; + --cross-compile) enable cross_compile + ;; + --target-os=*) targetos="$optval" + ;; + --cc=*) cc="$optval" + ;; + --make=*) make="$optval" + ;; + --extra-cflags=*) add_cflags "$optval" + ;; + --extra-ldflags=*) add_ldflags "$optval" + ;; + --extra-libs=*) add_extralibs "$optval" + ;; + --build-suffix=*) BUILDSUF="$optval" + ;; + --arch=*) arch="$optval" + ;; + --cpu=*) cpu="$optval" + ;; + --enable-sunmlib) enable mlib + ;; + --disable-strip) disable dostrip + ;; + --disable-encoders) disable $ENCODER_LIST + ;; + --disable-decoders) disable $DECODER_LIST + ;; + --disable-muxers) disable $MUXER_LIST + ;; + --disable-filters) disable $FILTER_LIST + ;; + --disable-demuxers) disable $DEMUXER_LIST + ;; + --disable-parsers) disable $PARSER_LIST + ;; + --disable-bsfs) disable $BSF_LIST + ;; + --disable-protocols) disable $PROTOCOL_LIST + ;; + --disable-devices) disable $INDEV_LIST $OUTDEV_LIST + ;; + --enable-*=*|--disable-*=*) + eval `echo "$opt" | sed 's/=/-/;s/--/action=/;s/-/ thing=/;s/-/ name=/'` + case "$thing" in + encoder|decoder|muxer|demuxer|parser|bsf|protocol) $action ${optval}_${thing} ;; + filter) $action ${optval} ;; + *) die_unknown "$opt" ;; + esac + ;; + --enable-?*|--disable-?*) + eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'` + echo "$CMDLINE_SELECT" | grep -q "^ *$option\$" || die_unknown $opt + $action $option + ;; + --list-*) + NAME="${opt#--list-}" + is_in $NAME $COMPONENT_LIST || die_unknown $opt + NAME=${NAME%s} + eval show_list $NAME \$$(toupper $NAME)_LIST + ;; + --help|-h) show_help + ;; + *) + die_unknown $opt + ;; + esac done case "$arch" in - i386|i486|i586|i686|i86pc|BePC) - arch="x86_32" - ;; - x86_64|amd64) - arch="x86_32" - canon_arch="`$cc -dumpmachine | sed -e 's,\([^-]*\)-.*,\1,'`" - if [ x"$canon_arch" = x"x86_64" -o x"$canon_arch" = x"amd64" ]; then - if [ -z "`echo $CFLAGS | grep -- -m32`" ]; then - arch="x86_64" + i386|i486|i586|i686|i86pc|BePC) + arch="x86_32" + enable fast_unaligned + ;; + x86_64|amd64) + arch="x86_32" + enable fast_unaligned + canon_arch="`$cc -dumpmachine | sed -e 's,\([^-]*\)-.*,\1,'`" + if [ x"$canon_arch" = x"x86_64" -o x"$canon_arch" = x"amd64" ]; then + if [ -z "`echo $CFLAGS | grep -- -m32`" ]; then + arch="x86_64" + enable fast_64bit + fi + fi + ;; + # armv4l is a subset of armv[567]*l + arm|armv[4567]*l) + arch="armv4l" + ;; + alpha) + arch="alpha" enable fast_64bit - fi - fi - ;; - # armv4l is a subset of armv[567]*l - arm|armv[4567]*l) - arch="armv4l" - ;; - alpha) - arch="alpha" - enable fast_64bit - ;; - "Power Macintosh"|ppc|powerpc) - arch="powerpc" - ;; - ppc64) - arch="powerpc" - enable fast_64bit - ;; - mips|mipsel|IP*) - arch="mips" - ;; - sun4u|sparc64) - arch="sparc64" - enable fast_64bit - ;; - sparc) - arch="sparc" - ;; - sh4) - arch="sh4" - ;; - parisc) - arch="parisc" - ;; - parisc64) - arch="parisc" - enable fast_64bit - ;; - s390|s390x) - arch="s390" - ;; - m68k) - arch="m68k" - ;; - ia64) - arch="ia64" - enable fast_64bit - ;; - bfin) - arch="bfin" - ;; - *) - arch="unknown" - ;; -esac - -# OS specific -osextralibs="-lm" -case $targetos in - beos|haiku|zeta) - PREFIX="$HOME/config" - # helps building libavcodec - add_cflags "-DPIC -fomit-frame-pointer" - # 3 gcc releases known for BeOS, each with ugly bugs - gcc_version="`$cc -v 2>&1 | grep version | cut -d ' ' -f3-`" - case "$gcc_version" in - 2.9-beos-991026*|2.9-beos-000224*) echo "R5/GG gcc" - mmx="no" - ;; - *20010315*) echo "BeBits gcc" - add_cflags "-fno-expensive-optimizations" - ;; - esac - LDCONFIG="echo ignoring ldconfig" - SHFLAGS=-nostart - # disable Linux things - dv1394="no" - # enable BeOS things - disabled audio_beos || enable_audio_beos - # no need for libm, but the inet stuff - # Check for BONE - # XXX: actually should check for NOT net_server - if (echo $BEINCLUDES|grep 'headers/be/bone' >/dev/null); then - osextralibs="-lbind -lsocket" - else - beos_netserver="yes" - osextralibs="-lnet" - fi ;; - sunos) - dv1394="no" - FFLDFLAGS="" - FFSERVERLDFLAGS="" - SHFLAGS="-shared -Wl,-h,\$@" - add_extralibs "-lsocket -lnsl" ;; - netbsd) - dv1394="no" - add_extralibs "-lossaudio" + "Power Macintosh"|ppc|powerpc) + arch="powerpc" ;; - openbsd) - dv1394="no" - need_memalign="no" - LIBOBJFLAGS="\$(PIC)" - LDCONFIG="ldconfig -m \$(shlibdir)" - SHFLAGS='-shared' - SLIBNAME='$(SLIBPREF)$(NAME)$(SLIBSUF).$(LIBVERSION)' - SLIBNAME_WITH_VERSION='$(SLIBNAME)' - SLIBNAME_WITH_MAJOR='$(SLIBNAME)' - add_extralibs "-lossaudio" + ppc64) + arch="powerpc" + enable fast_64bit ;; - freebsd) - dv1394="no" - need_memalign="no" - add_cflags "-pthread" + mips|mipsel|IP*) + arch="mips" ;; - gnu/kfreebsd) - dv1394="no" - add_cflags "-pthread" + sun4u|sparc64) + arch="sparc64" + enable fast_64bit ;; - bsd/os) - dv1394="no" - osextralibs="-lpoll -lgnugetopt -lm" - strip="strip -d" + sparc) + arch="sparc" ;; - darwin) - dv1394="no" - need_memalign="no" - SHFLAGS="-dynamiclib -Wl,-single_module -Wl,-install_name,\$(shlibdir)/\$(SLIBNAME),-current_version,\$(SPPVERSION),-compatibility_version,\$(SPPVERSION) -Wl,-read_only_relocs,suppress" - VHOOKSHFLAGS='-dynamiclib -Wl,-single_module -flat_namespace -undefined suppress -Wl,-install_name,$(shlibdir)/vhook/$@' - osextralibs="" - strip="strip -x" - FFLDFLAGS="-Wl,-dynamic,-search_paths_first" - SLIBSUF=".dylib" - SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME).$(LIBVERSION)$(SLIBSUF)' - SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME).$(LIBMAJOR)$(SLIBSUF)' - FFSERVERLDFLAGS=-Wl,-bind_at_load + sh4) + arch="sh4" ;; - mingw32*) - targetos=mingw32 - if enabled_all shared static; then - cat <<EOF -You can only build one library type at once on MinGW. -Specify --disable-static --enable-shared to only build -the shared libraries. To build only the static libraries -you do not need to pass additional options. -EOF - exit 1 - fi - dv1394="no" - ffserver="no" - network="no" - if enabled wince; then - protocols="no" - fi - SLIBPREF="" - SLIBSUF=".dll" - EXESUF=".exe" - SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)' - SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME)-$(LIBMAJOR)$(SLIBSUF)' - SLIB_EXTRA_CMD="-lib /machine:i386 /def:\$(@:${SLIBSUF}=.def)" - SLIB_INSTALL_EXTRA_CMD="-install -m 644 \$(SLIBNAME_WITH_MAJOR:\$(SLIBSUF)=.lib) \"\$(shlibdir)/\$(SLIBNAME_WITH_MAJOR:\$(SLIBSUF)=.lib)\"" - SHFLAGS="-shared -Wl,--output-def,\$(@:${SLIBSUF}=.def),--out-implib,lib\$(SLIBNAME:\$(SLIBSUF)=.dll.a) -Wl,--enable-runtime-pseudo-reloc" - add_extralibs -lws2_32 + parisc) + arch="parisc" ;; - cygwin*) - targetos=cygwin - shlibdir="$bindir" - dv1394="no" - VHOOKSHFLAGS='-shared -L$(BUILD_ROOT)/libavformat -L$(BUILD_ROOT)/libavcodec -L$(BUILD_ROOT)/libswscale -L$(BUILD_ROOT)/libavutil' - VHOOKLIBS='-lavformat$(BUILDSUF) -lavcodec$(BUILDSUF) -lswscale$(BUILDSUF) -lavutil$(BUILDSUF) $(EXTRALIBS)' - osextralibs="" - EXESUF=".exe" - SLIBPREF="cyg" - SLIBSUF=".dll" - SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)' - SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME)-$(LIBMAJOR)$(SLIBSUF)' - SHFLAGS='-shared -Wl,--out-implib=lib$(NAME).dll.a' + parisc64) + arch="parisc" + enable fast_64bit ;; - linux) - LDLATEFLAGS="-Wl,--as-needed $LDLATEFLAGS" + s390|s390x) + arch="s390" ;; - irix*) - targetos=irix - ranlib="echo ignoring ranlib" + m68k) + arch="m68k" ;; - os/2) - TMPE=$TMPE".exe" - ar="emxomfar -p128" - ranlib="echo ignoring ranlib" - strip="echo ignoring strip" - add_cflags "-Zomf" - FFLDFLAGS="-Zomf -Zstack 16384 -s" - SHFLAGS="-Zdll -Zomf" - FFSERVERLDFLAGS="" - LIBPREF="" - LIBSUF=".lib" - SLIBPREF="" - SLIBSUF=".dll" - EXESUF=".exe" - osextralibs="" - pkg_requires="" - dv1394="no" - ffserver="no" - vhook="no" - os2="yes" + ia64) + arch="ia64" + enable fast_64bit ;; - *) - targetos="${targetos}-UNKNOWN" + bfin) + arch="bfin" + ;; + *) + arch="unknown" ;; esac +enable $arch +enabled_any x86_32 x86_64 && enable x86 +enabled sparc64 && enable sparc + +# OS specific +case $targetos in + beos|haiku|zeta) + PREFIX="$HOME/config" + # helps building libavcodec + add_cflags "-DPIC -fomit-frame-pointer" + # 3 gcc releases known for BeOS, each with ugly bugs + gcc_version="`$cc -v 2>&1 | grep version | cut -d ' ' -f3-`" + case "$gcc_version" in + 2.9-beos-991026*|2.9-beos-000224*) echo "R5/GG gcc" + disable mmx + ;; + *20010315*) echo "BeBits gcc" + add_cflags "-fno-expensive-optimizations" + ;; + esac + SHFLAGS=-nostart + # enable BeOS things + enable audio_beos + # no need for libm, but the inet stuff + # Check for BONE + # XXX: actually should check for NOT net_server + if (echo $BEINCLUDES|grep 'headers/be/bone' >/dev/null); then + network_extralibs="-lbind -lsocket" + else + enable beos_netserver + network_extralibs="-lnet" + fi ;; + sunos) + FFSERVERLDFLAGS="" + SHFLAGS='-shared -Wl,-h,$@' + network_extralibs="-lsocket -lnsl" + ;; + netbsd) + oss_demuxer_extralibs="-lossaudio" + oss_muxer_extralibs="-lossaudio" + ;; + openbsd) + disable need_memalign + LIBOBJFLAGS='$(PIC)' + SHFLAGS='-shared' + SLIBNAME='$(SLIBPREF)$(FULLNAME)$(SLIBSUF).$(LIBVERSION)' + SLIBNAME_WITH_VERSION='$(SLIBNAME)' + SLIBNAME_WITH_MAJOR='$(SLIBNAME)' + oss_demuxer_extralibs="-lossaudio" + oss_muxer_extralibs="-lossaudio" + ;; + freebsd) + disable need_memalign + ;; + bsd/os) + osextralibs="-lpoll -lgnugetopt" + strip="strip -d" + ;; + darwin) + disable need_memalign + SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(SLIBNAME),-current_version,$(SPPVERSION),-compatibility_version,$(SPPVERSION) -Wl,-read_only_relocs,suppress' + VHOOKSHFLAGS='-dynamiclib -Wl,-single_module -flat_namespace -undefined suppress -Wl,-install_name,$(SHLIBDIR)/vhook/$@' + strip="strip -x" + FFLDFLAGS="-Wl,-dynamic,-search_paths_first" + SLIBSUF=".dylib" + SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME).$(LIBVERSION)$(SLIBSUF)' + SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME).$(LIBMAJOR)$(SLIBSUF)' + FFSERVERLDFLAGS=-Wl,-bind_at_load + ;; + mingw32*) + targetos=mingw32 + shlibdir="$bindir" + VHOOKSHFLAGS='-shared -L$(BUILD_ROOT)/libavformat -L$(BUILD_ROOT)/libavcodec -L$(BUILD_ROOT)/libavutil' + VHOOKLIBS='-lavformat$(BUILDSUF) -lavcodec$(BUILDSUF) -lavutil$(BUILDSUF) $(EXTRALIBS)' + if enabled swscaler; then + VHOOKSHFLAGS="$VHOOKSHFLAGS -L\$(BUILD_ROOT)/libswscale" + VHOOKLIBS="$VHOOKLIBS -lswscale\$(BUILDSUF)" + fi + disable ffserver + SLIBPREF="" + SLIBSUF=".dll" + EXESUF=".exe" + SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)' + SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)' + SLIB_EXTRA_CMD='-lib /machine:i386 /def:$(@:$(SLIBSUF)=.def)' + SLIB_INSTALL_EXTRA_CMD='-install -m 644 $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib) "$(SHLIBDIR)/$(SLIBNAME:$(SLIBSUF)=.lib)"' + SLIB_UNINSTALL_EXTRA_CMD='rm -f "$(SHLIBDIR)/$(SLIBNAME:$(SLIBSUF)=.lib)"' + SHFLAGS='-shared -Wl,--output-def,$(@:$(SLIBSUF)=.def) -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base' + ;; + cygwin*) + targetos=cygwin + shlibdir="$bindir" + VHOOKSHFLAGS='-shared -L$(BUILD_ROOT)/libavformat -L$(BUILD_ROOT)/libavcodec -L$(BUILD_ROOT)/libavutil' + VHOOKLIBS='-lavformat$(BUILDSUF) -lavcodec$(BUILDSUF) -lavutil$(BUILDSUF) $(EXTRALIBS)' + if enabled swscaler; then + VHOOKSHFLAGS="$VHOOKSHFLAGS -L\$(BUILD_ROOT)/libswscale" + VHOOKLIBS="$VHOOKLIBS -lswscale\$(BUILDSUF)" + fi + EXESUF=".exe" + SLIBPREF="cyg" + SLIBSUF=".dll" + SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)' + SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)' + SHFLAGS='-shared -Wl,--enable-auto-image-base' + ;; + *-dos|freedos|opendos) + enable memalign_hack + disable ffplay ffserver vhook + disable $INDEV_LIST $OUTDEV_LIST + network_extralibs="-lsocket" + EXESUF=".exe" + ;; + linux) + LDLATEFLAGS="-Wl,--as-needed $LDLATEFLAGS" + enable dv1394 + ;; + irix*) + targetos=irix + ranlib="echo ignoring ranlib" + ;; + os/2*) + ar="emxomfar -p256" + ranlib="echo ignoring ranlib" + strip="lxlite" + ln_s="cp -f" + add_cflags "-Zomf" + EXESUF=".exe" + FFLDFLAGS="-Zomf -Zbin-files -Zargs-wild -Zmap" + SHFLAGS='$(NAME).def -Zdll -Zomf' + FFSERVERLDFLAGS="" + LIBSUF="_s.lib" + SLIBPREF="" + SLIBSUF=".dll" + SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME)-$(LIBVERSION)$(SLIBSUF)' + SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(shell echo $(NAME) | cut -c1-6)$(LIBMAJOR)$(SLIBSUF)' + SLIB_CREATE_DEF_CMD='echo LIBRARY $(SLIBNAME_WITH_MAJOR) INITINSTANCE TERMINSTANCE > $(NAME).def; \ + echo PROTMODE >> $(NAME).def; \ + echo CODE PRELOAD MOVEABLE DISCARDABLE >> $(NAME).def; \ + echo DATA PRELOAD MOVEABLE MULTIPLE NONSHARED >> $(NAME).def; \ + echo EXPORTS >> $(NAME).def; \ + emxexp -o $(OBJS) >> $(NAME).def' + SLIB_EXTRA_CMD='emximp -o $(LIBPREF)$(NAME)_dll.a $(NAME).def; \ + emximp -o $(LIBPREF)$(NAME)_dll.lib $(NAME).def;' + SLIB_INSTALL_EXTRA_CMD='install -m 644 $(LIBPREF)$(NAME)_dll.a $(LIBPREF)$(NAME)_dll.lib "$(LIBDIR)"' + SLIB_UNINSTALL_EXTRA_CMD='rm -f "$(LIBDIR)"/$(LIBPREF)$(NAME)_dll.a "$(LIBDIR)"/$(LIBPREF)$(NAME)_dll.lib' + vhook="no" + ;; + interix) + disable vhook + ;; + + *) + targetos="${targetos}-UNKNOWN" + ;; +esac + add_extralibs $osextralibs if ! disabled logging ; then @@ -1187,18 +1331,14 @@ fi # Combine FFLDFLAGS and the LDFLAGS environment variable. LDFLAGS="$FFLDFLAGS $LDFLAGS" -test -n "$cross_prefix" && cross_compile=yes +test -n "$cross_prefix" && enable cross_compile cc="${cross_prefix}${cc}" ar="${cross_prefix}${ar}" ranlib="${cross_prefix}${ranlib}" strip="${cross_prefix}${strip}" -# Disable core dumps so that intentional execution of broken apps doesn't -# pollute the current directory. -ulimit -c 0 - # we need to build at least one lib type -if disabled_all static shared; then +if ! enabled_any static shared; then cat <<EOF At least one library type must be built. Specify --enable-static to build the static libraries or --enable-shared to @@ -1208,10 +1348,7 @@ EOF exit 1; fi -if disabled libogg; then - enabled libtheora && die "libogg must be enabled to enable libtheora." - enabled libvorbis && die "libogg must be enabled to enable libvorbis." -fi +disabled static && LIBNAME="" if enabled_any libfaad libfaadbin ; then if check_header faad.h; then @@ -1220,7 +1357,7 @@ if enabled_any libfaad libfaadbin ; then #ifndef FAAD2_VERSION ok faad1 #endif -int main( void ) { return 0; } +int main(void) { return 0; } EOF test $? = 0 && enable libfaad2 else @@ -1229,7 +1366,7 @@ EOF fi -if disabled gpl ; then +if ! enabled gpl; then die_gpl_disabled(){ name=$1 shift @@ -1237,65 +1374,36 @@ if disabled gpl ; then } die_gpl_disabled "The Postprocessing code" pp die_gpl_disabled "liba52" liba52 - die_gpl_disabled "libxvidcore" xvid - die_gpl_disabled "x264" x264 - die_gpl_disabled "libdts" libdts + die_gpl_disabled "libx264" libx264 + die_gpl_disabled "libxvidcore" libxvid die_gpl_disabled "FAAD2" libfaad2 die_gpl_disabled "The X11 grabber" x11grab die_gpl_disabled "The software scaler" swscaler fi -# compute MMX state -if test $mmx = "default"; then - if test $arch = "x86_32" -o $arch = "x86_64"; then - mmx="yes" - else - mmx="no" - fi +if ! enabled nonfree && enabled_any libamr_nb libamr_wb; then + die "libamr is nonfree and --enable-nonfree is not specified." fi +check_deps $ARCH_EXT_LIST + test -z "$need_memalign" && need_memalign="$mmx" #Darwin CC versions -needmdynamicnopic="no" if test $targetos = darwin; then if test -n "`$cc -v 2>&1 | grep xlc`"; then add_cflags "-qpdf2 -qlanglvl=extc99 -qmaxmem=-1 -qarch=auto -qtune=auto" else - gcc_version="`$cc -v 2>&1 | grep version | cut -d ' ' -f3-`" - case "$gcc_version" in - *2.95*) - add_cflags "-no-cpp-precomp -pipe" - ;; - *[34].*) - add_cflags "-no-cpp-precomp -pipe -force_cpusubtype_ALL -Wno-sign-compare" - if disabled shared; then - needmdynamicnopic="yes" - fi - ;; - *) - add_cflags "-no-cpp-precomp -pipe" - if disabled shared; then - needmdynamicnopic="yes" - fi - ;; - esac + add_cflags "-no-cpp-precomp -pipe" + check_cflags "-force_cpusubtype_ALL" + check_cflags "-Wno-sign-compare" + disabled shared && add_cflags -mdynamic-no-pic fi fi -disabled optimize || add_cflags -fomit-frame-pointer - -# Can only do AltiVec on PowerPC -if test $altivec = "default"; then - if test $arch = "powerpc"; then - altivec="yes" - else - altivec="no" - fi -fi +disabled optimizations || add_cflags -fomit-frame-pointer # Add processor-specific flags -POWERPCMODE="32bits" if test $cpu != "generic"; then warn_altivec(){ $1 altivec && echo "WARNING: Tuning for $2 but AltiVec $1."; @@ -1328,34 +1436,38 @@ if test $cpu != "generic"; then G5|g5|970|ppc970|PowerPC970|power4*|Power4*) add_cflags "-mcpu=970 -mpowerpc-gfxopt -mpowerpc64" warn_altivec disabled PPC970 - POWERPCMODE="64bits" + enable ppc64 + ;; + Cell|CELL|cell) + add_cflags "-mcpu=cell" + warn_altivec disabled Cell + enable ppc64 ;; # targets that do NOT support conditional mov (cmov) i[345]86|pentium|pentium-mmx|k6|k6-[23]|winchip-c6|winchip2|c3) add_cflags "-march=$cpu" - cmov="no" + disable cmov ;; # targets that do support conditional mov (cmov) i686|pentiumpro|pentium[23]|pentium-m|athlon|athlon-tbird|athlon-4|athlon-[mx]p|athlon64|k8|opteron|athlon-fx|core2) add_cflags "-march=$cpu" - cmov="yes" - fast_cmov="yes" + enable cmov + enable fast_cmov ;; # targets that do support conditional mov but on which it's slow - pentium4|prescott|nocona) + pentium4|pentium4m|prescott|nocona) add_cflags "-march=$cpu" - cmov="yes" - fast_cmov="no" + enable cmov + disable fast_cmov ;; sparc64) add_cflags "-mcpu=v9" ;; - bf*) #bf531 bf532 bf533 bf561 bf5xx all get this config - add_cflags "-mfdpic" - add_ldflags "-mfdpic" + arm*) + add_cflags "-mcpu=$cpu" ;; *) - echo "WARNING: Unknown CPU \"$cpu\", ignored." + echo "WARNING: Unknown CPU \"$cpu\", ignored." ;; esac fi @@ -1385,54 +1497,45 @@ rm $TMPE # compiler sanity check check_exec <<EOF -int main(){ +int main(void){ return 0; } EOF if test "$?" != 0; then echo "$cc is unable to create an executable file." - if test -z "$cross_prefix" && disabled cross_compile ; then + if test -z "$cross_prefix" && ! enabled cross_compile ; then echo "If $cc is a cross-compiler, use the --cross-compile option." echo "Only do this if you know what cross compiling means." fi die "C compiler test failed." fi -if test $arch = "x86_32" -o $arch = "x86_64"; then - if test "$targetos" = mingw32 -o "$targetos" = cygwin; then - cat <<EOF -WARNING: The following test might cause a testapp to crash (intentionally) -resulting in the appearance of a dialog box. Please click "Don't send" and -ignore it. -EOF - fi +check_asm inline_asm '""' +if enabled x86; then # check whether EBP is available on x86 # As 'i' is stored on the stack, this program will crash # if the base pointer is used to access it because the # base pointer is cleared in the inline assembly code. - (check_exec) <<EOF >>$logfile 2>&1 && enable ebp_available -int main(){ + check_exec_crash <<EOF && enable ebp_available volatile int i=0; asm volatile ( "xorl %%ebp, %%ebp" ::: "%ebp"); return i; -} EOF # check wether EBX is available on x86 - check_cc <<EOF && enable ebx_available -int main(){ - asm volatile ("":::"%ebx"); -} -EOF + check_asm ebx_available '"":::"%ebx"' + + # check whether binutils is new enough to compile SSSE3 + enabled ssse3 && check_asm ssse3 '"pabsw %xmm0, %xmm0"' fi # check for assembler specific support if test $arch = "powerpc"; then -check_cc <<EOF && dcbzl=yes +check_cc <<EOF && enable dcbzl int main(void) { register long zero = 0; char data[1024]; @@ -1445,26 +1548,18 @@ fi # check for SIMD availability # AltiVec flags: The FSF version of GCC differs from the Apple version -if test $arch = "powerpc"; then - if enabled altivec; then - if test -n "`$cc -v 2>&1 | grep version | grep Apple`"; then - add_cflags "-faltivec" - else - add_cflags "-maltivec -mabi=altivec" - fi - fi -fi +if enabled altivec; then + test -n "`$cc -v 2>&1 | grep version | grep Apple`" && + add_cflags "-faltivec" || + add_cflags "-maltivec -mabi=altivec" -check_header altivec.h + check_header altivec.h -# check if our compiler supports Motorola AltiVec C API -if enabled altivec; then - if enabled altivec_h; then - inc_altivec_h="#include <altivec.h>" - else + # check if our compiler supports Motorola AltiVec C API + enabled altivec_h && + inc_altivec_h="#include <altivec.h>" || inc_altivec_h= - fi - check_cc <<EOF || altivec=no + check_cc <<EOF || disable altivec $inc_altivec_h int main(void) { vector signed int v1, v2, v3; @@ -1474,90 +1569,55 @@ int main(void) { EOF fi -# check armv5te instructions support -if test $armv5te = "default" -a $arch = "armv4l"; then - armv5te=no - check_cc <<EOF && armv5te=yes - int main(void) { - __asm__ __volatile__ ("qadd r0, r0, r0"); - } -EOF -fi +enabled armv5te && check_asm armv5te '"qadd r0, r0, r0"' +enabled armv6 && check_asm armv6 '"sadd16 r0, r0, r0"' +enabled iwmmxt && check_asm iwmmxt '"wunpckelub wr6, wr4"' +enabled mmi && check_asm mmi '"lq $2, 0($2)"' +enabled vis && check_asm vis '"pdist %f0, %f0, %f0"' -mcpu=ultrasparc -if test $armv6 = "default" -a $arch = "armv4l"; then - check_cc <<EOF && armv6=yes || armv6=no -int main(void) { - __asm__ __volatile__ ("sadd16 r0, r0, r0"); -} -EOF -fi - -# check iwmmxt support -if test $iwmmxt = "default" -a $arch = "armv4l"; then - iwmmxt=no - check_cc <<EOF && iwmmxt=yes - int main(void) { - __asm__ __volatile__ ("wunpckelub wr6, wr4"); - } -EOF -fi - -# mmi only available on mips -if test $mmi = "default"; then - if test $arch = "mips"; then - mmi="yes" - else - mmi="no" - fi -fi - -# check if our compiler supports mmi -enabled mmi && check_cc <<EOF || mmi="no" -int main(void) { - __asm__ ("lq \$2, 0(\$2)"); - return 0; -} -EOF +enabled vis && add_cflags "-mcpu=ultrasparc -mtune=ultrasparc" # --- # big/little-endian test -if disabled cross_compile; then - check_ld <<EOF || die "endian test failed" && $TMPE && bigendian="yes" -#include <inttypes.h> -int main(int argc, char ** argv){ - volatile uint32_t i=0x01234567; - return (*((uint8_t*)(&i))) == 0x67; -} +check_cc <<EOF || die "endian test failed" +unsigned int endian = 'B' << 24 | 'I' << 16 | 'G' << 8 | 'E'; EOF -else - # programs cannot be launched if cross compiling, so make a static guess - if test "$arch" = "powerpc" -o "$arch" = "mips" ; then - bigendian="yes" - fi -fi +grep -q BIGE $TMPO && enable bigendian # --- # check availability of some header files -check_header malloc.h -check_func memalign - -if disabled_all memalign memalign_hack && enabled need_memalign ; then - die "Error, no memalign() but SSE enabled, disable it or use --enable-memalign-hack." +if check_func dlopen; then + ldl= +elif check_func dlopen -ldl; then + ldl=-ldl fi +check_func fork +check_func gethrtime +check_func getrusage +check_func inet_aton $network_extralibs +check_func memalign +check_func mkstemp +check_func2 windows.h GetProcessTimes + check_header byteswap.h +check_header conio.h +check_header dlfcn.h +check_header malloc.h +check_header termios.h -check_header arpa/inet.h +if ! enabled_any memalign memalign_hack && enabled need_memalign ; then + die "Error, no memalign() but SSE enabled, disable it or use --enable-memalign-hack." +fi -check_func inet_aton -check_func localtime_r -enabled zlib && check_lib zlib.h zlibVersion -lz || zlib="no" +enabled zlib && check_lib zlib.h zlibVersion -lz || disable zlib # ffserver uses poll(), # if it's not found we can emulate it using select(). if enabled ffserver; then - check_header sys/poll.h + check_header poll.h + check_header sys/select.h fi # check for some common methods of building with pthread support @@ -1567,10 +1627,10 @@ if enabled pthreads; then : elif check_func pthread_create -pthread; then add_cflags -pthread - add_ldflags -pthread + add_extralibs -pthread elif check_func pthread_create -pthreads; then add_cflags -pthreads - add_ldflags -pthreads + add_extralibs -pthreads elif ! check_lib pthread.h pthread_create -lpthread; then die "ERROR: can't find pthreads library" fi @@ -1578,41 +1638,51 @@ fi for thread in $THREADS_LIST; do if enabled $thread; then - if ! disabled thread_type ; then - die "ERROR: Only one thread type must be selected." - else + test -n "$thread_type" && + die "ERROR: Only one thread type must be selected." || thread_type="$thread" - fi fi done -enabled_any amr_nb amr_nb_fixed amr_wb amr_if2 && enable amr -enabled_all amr_nb amr_nb_fixed && - die "Only one of amr_nb and amr_nb_fixed may be enabled." +check_lib math.h sin -lm + +# test for C99 functions in math.h +for func in llrint lrint lrintf round roundf; do + check_exec <<EOF && enable $func || disable $func +#define _ISOC9X_SOURCE 1 +#include <math.h> +int main(void) { return ($func(3.999f) > 0)?0:1; } +EOF +done # these are off by default, so fail if requested and not available -enabled liba52 && require liba52 a52dec/a52.h a52_init -la52 -enabled libdts && require libdts dts.h dts_init -ldts -lm -enabled libgsm && require libgsm gsm.h gsm_create -lgsm -enabled libmp3lame && require LAME lame/lame.h lame_init -lmp3lame -lm -enabled libtheora && require libtheora theora/theora.h theora_info_init -ltheora -logg -enabled libvorbis && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbis -lvorbisenc -logg -enabled libogg && require libogg ogg/ogg.h ogg_sync_init -logg -enabled libnut && require libnut libnut.h nut_demuxer_init -lnut -enabled xvid && require XviD xvid.h xvid_global -lxvidcore -enabled x264 && require x264 x264.h x264_encoder_open -lx264 -enabled dc1394 && require libdc1394 libdc1394/dc1394_control.h dc1394_create_handle -ldc1394_control -lraw1394 -enabled mlib && require mediaLib mlib_types.h mlib_VectorSub_S16_U8_Mod -lmlib +enabled avisynth && require2 vfw32 "windows.h vfw.h" AVIFileInit -lvfw32 +enabled liba52 && require liba52 a52dec/a52.h a52_init -la52 +enabled libamr_nb && require libamrnb amrnb/interf_dec.h Speech_Decode_Frame_init -lamrnb -lm +enabled libamr_wb && require libamrwb amrwb/dec_if.h D_IF_init -lamrwb -lm enabled libfaac && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac enabled libfaad && require2 libfaad faad.h faacDecOpen -lfaad -enabled avisynth && require2 vfw32 "windows.h vfw.h" AVIFileInit -lvfw32 +enabled libgsm && require libgsm gsm.h gsm_create -lgsm +enabled libmp3lame && require LAME lame/lame.h lame_init -lmp3lame -lm +enabled libnut && require libnut libnut.h nut_demuxer_init -lnut +enabled libtheora && require libtheora theora/theora.h theora_info_init -ltheora -logg +enabled libvorbis && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg +enabled libx264 && require x264 x264.h x264_encoder_open -lx264 -lm +enabled libxvid && require Xvid xvid.h xvid_global -lxvidcore +enabled mlib && require mediaLib mlib_types.h mlib_VectorSub_S16_U8_Mod -lmlib + +# disable the native AC-3 decoder if liba52 is enabled +enabled liba52 && disable ac3_decoder + +# libdc1394 check +if enabled libdc1394; then + { check_lib dc1394/dc1394.h dc1394_new -ldc1394 -lraw1394 && + enable libdc1394_2; } || + { check_lib libdc1394/dc1394_control.h dc1394_create_handle -ldc1394_control -lraw1394 && + enable libdc1394_1; } || + die "ERROR: No version of libdc1394 found " +fi -# test for lrintf in math.h -check_exec <<EOF && lrintf=yes || lrintf=no -#define _ISOC9X_SOURCE 1 -#include <math.h> -int main( void ) { return (lrintf(3.999f) > 0)?0:1; } -EOF _restrict= for restrict_keyword in restrict __restrict__ __restrict; do @@ -1621,24 +1691,12 @@ void foo(char * $restrict_keyword p); EOF done -# dlopen/dlfcn.h probing - -check_header dlfcn.h - -if check_func dlopen; then - ldl= -elif check_func dlopen -ldl; then - ldl=-ldl -fi - test "$vhook" = "default" && vhook="$dlopen" -enabled_any vhook liba52bin libfaadbin ffserver && add_extralibs $ldl - -if test "$targetos" = cygwin && enabled static ; then - vhook="no" +if test "$targetos" = cygwin -o "$targetos" = mingw32 && enabled_all static vhook ; then + disable vhook echo - echo "At the moment vhooks don't work on Cygwin static builds." + echo "At the moment vhooks don't work on Cygwin or MinGW static builds." echo "Patches welcome." echo fi @@ -1648,30 +1706,28 @@ if enabled vhook; then check_ldflags -export-dynamic fi -enabled audio_beos && add_extralibs "-lmedia -lbe" - check_foo_config imlib2 imlib2 Imlib2.h imlib_load_font check_foo_config freetype2 freetype ft2build.h FT_Init_FreeType ########################################## # SDL check -sdl_too_old=no -sdl=no +disable sdl_too_old +disable sdl SDL_CONFIG="${cross_prefix}sdl-config" if "${SDL_CONFIG}" --version >/dev/null 2>&1; then sdl_cflags=`"${SDL_CONFIG}" --cflags` temp_cflags $sdl_cflags temp_extralibs `"${SDL_CONFIG}" --libs` - if check_lib SDL.h SDL_Init; then + if check_lib2 SDL.h SDL_Init; then _sdlversion=`"${SDL_CONFIG}" --version | sed 's/[^0-9]//g'` if test "$_sdlversion" -lt 121 ; then - sdl_too_old=yes + enable sdl_too_old else - sdl=yes + enable sdl check_cc $sdl_cflags <<EOF && enable sdl_video_size #include <SDL.h> -int main(void){ +int main(int argc, char **argv){ const SDL_VideoInfo *vi = SDL_GetVideoInfo(); int w = vi->current_w; return 0; @@ -1684,53 +1740,60 @@ fi texi2html -version >/dev/null 2>&1 && enable texi2html || disable texi2html +check_type sys/socket.h socklen_t + +########################################## +# Network check + +if enabled network; then + # Prefer arpa/inet.h over winsock2 + if check_header arpa/inet.h ; then + check_func closesocket + elif check_header winsock2.h ; then + network_extralibs="-lws2_32" + check_type ws2tcpip.h socklen_t + check_func2 winsock2.h closesocket + fi +fi + ########################################## # IPv6 check -enabled network && enabled ipv6 && check_ld <<EOF && ipv6=yes || ipv6=no +enabled network && enabled ipv6 && check_ld <<EOF && enable ipv6 || disable ipv6 #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> -int main( void ) { - struct sockaddr_storage saddr; - struct ipv6_mreq mreq6; - getaddrinfo(0,0,0,0); - getnameinfo(0,0,0,0,0,0,0); - IN6_IS_ADDR_MULTICAST((const struct in6_addr *)0); +int main(void) { + struct sockaddr_storage saddr; + struct ipv6_mreq mreq6; + getaddrinfo(0,0,0,0); + getnameinfo(0,0,0,0,0,0,0); + IN6_IS_ADDR_MULTICAST((const struct in6_addr *)0); } EOF -enabled v4l && check_header linux/videodev.h || disable v4l -enabled v4l2 && check_header linux/videodev2.h || disable v4l2 +check_header linux/videodev.h +check_header linux/videodev2.h # check for ioctl_meteor.h, ioctl_bt848.h and alternatives -if enabled bktr; then - { check_header dev/bktr/ioctl_meteor.h && - check_header dev/bktr/ioctl_bt848.h; } || - { check_header machine/ioctl_meteor.h && - check_header machine/ioctl_bt848.h; } || - { check_header dev/video/meteor/ioctl_meteor.h && - check_header dev/video/bktr/ioctl_bt848.h; } || - check_header dev/ic/bt8xx.h || - disable bktr -fi - -enabled audio_oss && - check_header sys/soundcard.h || - check_header soundcard.h || - disable audio_oss - -# Deal with the x11 frame grabber +{ check_header dev/bktr/ioctl_meteor.h && + check_header dev/bktr/ioctl_bt848.h; } || +{ check_header machine/ioctl_meteor.h && + check_header machine/ioctl_bt848.h; } || +{ check_header dev/video/meteor/ioctl_meteor.h && + check_header dev/video/bktr/ioctl_bt848.h; } || +check_header dev/ic/bt8xx.h + +check_header sys/soundcard.h +check_header soundcard.h + +# deal with the X11 frame grabber enabled x11grab && -enabled gpl && -enabled x11_grab_device_demuxer && check_header X11/Xlib.h && check_header X11/extensions/XShm.h && check_func XOpenDisplay -lX11 && -check_func XShmCreateImage -lX11 -lXext && -add_extralibs -lX11 -lXext || -disable x11_grab_device_demuxer +check_func XShmCreateImage -lX11 -lXext enabled debug && add_cflags -g @@ -1742,15 +1805,20 @@ check_cflags -Wdisabled-optimization check_cflags -Wpointer-arith check_cflags -Wredundant-decls check_cflags -Wno-pointer-sign +check_cflags -Wcast-qual +check_cflags -Wwrite-strings +check_cflags -Wtype-limits enabled extra_warnings && check_cflags -Winline # add some linker flags +check_ldflags -Wl,--warn-common check_ldflags $LDLATEFLAGS +check_ldflags -Wl,-Bsymbolic -# not all compilers support -Os -test "$optimize" = "small" && check_cflags -Os - -if enabled optimize; then +if enabled small; then + check_cflags -Os # not all compilers support -Os + optimizations="small" +elif enabled optimizations; then if test -n "`$cc -v 2>&1 | grep xlc`"; then add_cflags "-O5" add_ldflags "-O5" @@ -1758,13 +1826,15 @@ if enabled optimize; then add_cflags "-O3" fi fi +check_cflags -fno-math-errno +check_cflags -fno-signed-zeros # PIC flags for shared library objects where they are needed if enabled shared; then # LIBOBJFLAGS may have already been set in the OS configuration if test -z "$LIBOBJFLAGS" ; then case "$arch" in - x86_64|ia64|alpha|sparc*|power*) LIBOBJFLAGS="\$(PIC)" ;; + x86_64|ia64|alpha|sparc*|power*) LIBOBJFLAGS='$(PIC)' ;; esac fi fi @@ -1774,29 +1844,42 @@ if enabled gprof; then add_ldflags "-p" fi -VHOOKCFLAGS="-fPIC $CFLAGS" -enabled needmdynamicnopic && add_cflags -mdynamic-no-pic +VHOOKCFLAGS="-fPIC" -# find if .align arg is power-of-two or not +# Find out if the .align argument is a power of two or not. if test $asmalign_pot = "unknown"; then - asmalign_pot="no" - echo 'asm (".align 3");' | check_cc && asmalign_pot="yes" + disable asmalign_pot + echo 'asm (".align 3");' | check_cc && enable asmalign_pot fi -enabled_any $ENCODER_LIST && enable encoders -enabled_any $DECODER_LIST && enable decoders -enabled_any $MUXER_LIST && enable muxers -enabled_any $DEMUXER_LIST && enable demuxers - -enabled_any $THREADS_LIST && enable threads - -check_deps $CONFIG_LIST $HAVE_LIST $DECODER_LIST $ENCODER_LIST $PARSER_LIST \ - $DEMUXER_LIST $MUXER_LIST - -enabled libogg && append pkg_requires "ogg >= 1.1" +enabled_any $DECODER_LIST && enable decoders +enabled_any $ENCODER_LIST && enable encoders +enabled_any $BSF_LIST && enable bsfs +enabled_any $DEMUXER_LIST && enable demuxers +enabled_any $MUXER_LIST && enable muxers +enabled_any $FILTER_LIST && enable filters +enabled_any $INDEV_LIST && enable demuxers +enabled_any $OUTDEV_LIST && enable muxers +enabled_any $PROTOCOL_LIST && enable protocols + +enabled_any $THREADS_LIST && enable threads + +check_deps $CONFIG_LIST \ + $HAVE_LIST \ + $DECODER_LIST \ + $ENCODER_LIST \ + $PARSER_LIST \ + $BSF_LIST \ + $DEMUXER_LIST \ + $MUXER_LIST \ + $FILTER_LIST \ + $INDEV_LIST \ + $OUTDEV_LIST \ + $PROTOCOL_LIST \ + +enabled libdc1394 && append pkg_requires "libraw1394" enabled libtheora && append pkg_requires "theora" -enabled libvorbis && append pkg_requires "vorbis vorbisenc" -enabled dc1394 && append pkg_requires "libraw1394" +enabled libvorbis && append pkg_requires "vorbisenc" echo "install prefix $PREFIX" echo "source path $source_path" @@ -1807,100 +1890,112 @@ echo "ARCH $arch ($cpu)" if test "$BUILDSUF" != ""; then echo "build suffix $BUILDSUF" fi -echo "big-endian $bigendian" +echo "big-endian ${bigendian-no}" if test $arch = "x86_32" -o $arch = "x86_64"; then - echo "MMX enabled $mmx" - echo "CMOV enabled $cmov" - echo "CMOV is fast $fast_cmov" + echo "MMX enabled ${mmx-no}" + echo "CMOV enabled ${cmov-no}" + echo "CMOV is fast ${fast_cmov-no}" + echo "EBX available ${ebx_available-no}" + echo "EBP available ${ebp_available-no}" fi if test $arch = "armv4l"; then - echo "ARMv5TE enabled $armv5te" - echo "ARMv6 enabled $armv6" - echo "IWMMXT enabled $iwmmxt" + echo "ARMv5TE enabled ${armv5te-no}" + echo "ARMv6 enabled ${armv6-no}" + echo "IWMMXT enabled ${iwmmxt-no}" fi if test $arch = "mips"; then - echo "MMI enabled $mmi" + echo "MMI enabled ${mmi-no}" fi if test $arch = "powerpc"; then - echo "AltiVec enabled $altivec" - echo "dcbzl available $dcbzl" + echo "AltiVec enabled ${altivec-no}" + echo "dcbzl available ${dcbzl-no}" fi -echo "gprof enabled $gprof" -echo "debug symbols $debug" -echo "strip symbols $dostrip" -echo "optimize $optimize" -echo "static $static" -echo "shared $shared" -echo "postprocessing support $pp" -echo "software scaler enabled $swscaler" -echo "video hooking $vhook" +echo "gprof enabled ${gprof-no}" +echo "debug symbols ${debug-no}" +echo "strip symbols ${dostrip-no}" +echo "optimizations ${optimizations-no}" +echo "static ${static-no}" +echo "shared ${shared-no}" +echo "postprocessing support ${pp-no}" +echo "software scaler enabled ${swscaler-no}" +echo "new filter support ${avfilter-no}" +echo "filters using lavformat ${avfilter-lavf-no}" +echo "video hooking ${vhook-no}" if enabled vhook; then - echo "Imlib2 support $imlib2" - echo "FreeType support $freetype2" + echo "Imlib2 support ${imlib2-no}" + echo "FreeType support ${freetype2-no}" fi -echo "network support $network" +echo "network support ${network-no}" if enabled network; then - echo "IPv6 support $ipv6" + echo "IPv6 support ${ipv6-no}" fi -echo "threading support $thread_type" -echo "SDL support $sdl" +echo "threading support ${thread_type-no}" +echo "SDL support ${sdl-no}" if enabled sdl_too_old; then echo "-> Your SDL version is too old - please upgrade to have FFplay/SDL support." fi -echo "Sun medialib support $mlib" -echo "AVISynth enabled $avisynth" -echo "liba52 support $liba52" -echo "liba52 dlopened $liba52bin" -echo "libdts support $libdts" -echo "libfaac enabled $libfaac" -echo "libfaad enabled $libfaad" -echo "faadbin enabled $libfaadbin" -echo "libgsm enabled $libgsm" -echo "libmp3lame enabled $libmp3lame" -echo "libnut enabled $libnut" -echo "libogg enabled $libogg" -echo "libtheora enabled $libtheora" -echo "libvorbis enabled $libvorbis" -echo "x264 enabled $x264" -echo "XviD enabled $xvid" -echo "zlib enabled $zlib" -echo "AMR-NB float support $amr_nb" -echo "AMR-NB fixed support $amr_nb_fixed" -echo "AMR-WB float support $amr_wb" -echo "AMR-WB IF2 support $amr_if2" -if disabled gpl; then - echo "License: LGPL" -else - echo "License: GPL" -fi +echo "Sun medialib support ${mlib-no}" +echo "AVISynth enabled ${avisynth-no}" +echo "liba52 support ${liba52-no}" +echo "liba52 dlopened ${liba52bin-no}" +echo "libamr-nb support ${libamr_nb-no}" +echo "libamr-wb support ${libamr_wb-no}" +echo "libdc1394 support ${libdc1394-no}" +echo "libfaac enabled ${libfaac-no}" +echo "libfaad enabled ${libfaad-no}" +echo "libfaad dlopened ${libfaadbin-no}" +echo "libgsm enabled ${libgsm-no}" +echo "libmp3lame enabled ${libmp3lame-no}" +echo "libnut enabled ${libnut-no}" +echo "libtheora enabled ${libtheora-no}" +echo "libvorbis enabled ${libvorbis-no}" +echo "x264 enabled ${libx264-no}" +echo "XviD enabled ${libxvid-no}" +echo "zlib enabled ${zlib-no}" +echo + +for type in decoder encoder parser demuxer muxer protocol filter bsf indev outdev; do + echo "Enabled ${type}s:" + eval list=\$$(toupper $type)_LIST + for part in $list; do + enabled $part && echo ${part%_*} + done | sort | pr -3 -t + echo +done + +enabled nonfree && + echo "License: unredistributable" || + (enabled gpl && + echo "License: GPL" || + echo "License: LGPL") echo "Creating config.mak and config.h..." echo "# Automatically generated by configure - do not modify!" > config.mak echo "/* Automatically generated by configure - do not modify! */" > $TMPH +echo "#ifndef FFMPEG_CONFIG_H" >> $TMPH +echo "#define FFMPEG_CONFIG_H" >> $TMPH echo "#define FFMPEG_CONFIGURATION \"$FFMPEG_CONFIGURATION\"" >> $TMPH echo "PREFIX=$PREFIX" >> config.mak -echo "prefix=\$(DESTDIR)\${PREFIX}" >> config.mak -echo "libdir=\$(DESTDIR)$libdir" >> config.mak -echo "shlibdir=\$(DESTDIR)$shlibdir" >> config.mak -echo "incdir=\$(DESTDIR)$incdir" >> config.mak -echo "bindir=\$(DESTDIR)$bindir" >> config.mak -echo "mandir=\$(DESTDIR)$mandir" >> config.mak +echo "prefix=\$(DESTDIR)\$(PREFIX)" >> config.mak +echo "LIBDIR=\$(DESTDIR)$libdir" >> config.mak +echo "SHLIBDIR=\$(DESTDIR)$shlibdir" >> config.mak +echo "INCDIR=\$(DESTDIR)$incdir" >> config.mak +echo "BINDIR=\$(DESTDIR)$bindir" >> config.mak +echo "MANDIR=\$(DESTDIR)$mandir" >> config.mak echo "MAKE=$make" >> config.mak echo "CC=$cc" >> config.mak echo "AR=$ar" >> config.mak echo "RANLIB=$ranlib" >> config.mak -if enabled dostrip; then - echo "STRIP=$strip" >> config.mak -else +echo "LN_S=$ln_s" >> config.mak +enabled dostrip && + echo "STRIP=$strip" >> config.mak || echo "STRIP=echo ignoring strip" >> config.mak -fi echo "OPTFLAGS=$CFLAGS" >> config.mak echo "VHOOKCFLAGS=$VHOOKCFLAGS">>config.mak echo "LDFLAGS=$LDFLAGS" >> config.mak -echo "LDCONFIG=$LDCONFIG" >> config.mak echo "FFSERVERLDFLAGS=$FFSERVERLDFLAGS" >> config.mak echo "SHFLAGS=$SHFLAGS" >> config.mak echo "VHOOKSHFLAGS=$VHOOKSHFLAGS" >> config.mak @@ -1908,177 +2003,152 @@ echo "VHOOKLIBS=$VHOOKLIBS" >> config.mak echo "LIBOBJFLAGS=$LIBOBJFLAGS" >> config.mak echo "BUILD_STATIC=$static" >> config.mak echo "BUILDSUF=$BUILDSUF" >> config.mak +echo "FULLNAME=$FULLNAME" >> config.mak echo "LIBPREF=$LIBPREF" >> config.mak -echo "LIBSUF=\${BUILDSUF}$LIBSUF" >> config.mak -if enabled static; then - echo "LIB=$LIB" >> config.mak -else # Some Make complain if this variable does not exist. - echo "LIB=" >> config.mak -fi +echo "LIBSUF=$LIBSUF" >> config.mak +echo "LIBNAME=$LIBNAME" >> config.mak echo "SLIBPREF=$SLIBPREF" >> config.mak -echo "SLIBSUF=\${BUILDSUF}$SLIBSUF" >> config.mak -echo "EXESUF=\${BUILDSUF}$EXESUF" >> config.mak - -ucarch=`toupper $arch` -echo "TARGET_ARCH_${ucarch}=yes" >> config.mak -echo "#define ARCH_${ucarch} 1" >> $TMPH - -# special cases -case "$arch" in - x86_32|x86_64) - echo "TARGET_ARCH_X86=yes" >> config.mak - echo "#define ARCH_X86 1" >> $TMPH - ;; - powerpc) - if test "$POWERPCMODE" = "64bits"; then - echo "#define POWERPC_MODE_64BITS 1" >> $TMPH - fi - ;; - sparc64) - echo "TARGET_ARCH_SPARC=yes" >> config.mak - echo "#define ARCH_SPARC 1" >> $TMPH - ;; -esac +echo "SLIBSUF=$SLIBSUF" >> config.mak +echo "EXESUF=$EXESUF" >> config.mak if enabled bigendian; then - echo "WORDS_BIGENDIAN=yes" >> config.mak - echo "#define WORDS_BIGENDIAN 1" >> $TMPH + echo "WORDS_BIGENDIAN=yes" >> config.mak + echo "#define WORDS_BIGENDIAN 1" >> $TMPH fi if enabled mmx; then - echo "#define __CPU__ 586" >> $TMPH + echo "#define __CPU__ 586" >> $TMPH fi if enabled sdl; then - echo "SDL_LIBS=`"${SDL_CONFIG}" --libs`" >> config.mak - echo "SDL_CFLAGS=`"${SDL_CONFIG}" --cflags`" >> config.mak + echo "SDL_LIBS=`"${SDL_CONFIG}" --libs`" >> config.mak + echo "SDL_CFLAGS=`"${SDL_CONFIG}" --cflags`" >> config.mak fi if enabled texi2html; then - echo "BUILD_DOC=yes" >> config.mak + echo "BUILD_DOC=yes" >> config.mak fi -sws_version=`grep '#define LIBSWSCALE_VERSION ' "$source_path/libswscale/swscale.h" | sed 's/[^0-9\.]//g'` -pp_version=`grep '#define LIBPOSTPROC_VERSION ' "$source_path/libpostproc/postprocess.h" | sed 's/[^0-9\.]//g'` -lavc_version=`grep '#define LIBAVCODEC_VERSION ' "$source_path/libavcodec/avcodec.h" | sed 's/[^0-9\.]//g'` -lavf_version=`grep '#define LIBAVFORMAT_VERSION ' "$source_path/libavformat/avformat.h" | sed 's/[^0-9\.]//g'` -lavu_version=`grep '#define LIBAVUTIL_VERSION ' "$source_path/libavutil/avutil.h" | sed 's/[^0-9\.]//g'` - +get_version(){ + name=$1 + file=$source_path/$2 + eval $(grep "#define ${name}_VERSION_M" "$file" | awk '{ print $2"="$3 }') + eval ${name}_VERSION=\$${name}_VERSION_MAJOR.\$${name}_VERSION_MINOR.\$${name}_VERSION_MICRO +} +get_version LIBSWSCALE libswscale/swscale.h +get_version LIBPOSTPROC libpostproc/postprocess.h +get_version LIBAVCODEC libavcodec/avcodec.h +get_version LIBAVDEVICE libavdevice/avdevice.h +get_version LIBAVFORMAT libavformat/avformat.h +get_version LIBAVUTIL libavutil/avutil.h +get_version LIBAVFILTER libavfilter/avfilter.h if enabled shared; then - echo "BUILD_SHARED=yes" >> config.mak - echo "PIC=-fPIC -DPIC" >> config.mak - echo "SPPMAJOR=${pp_version%%.*}" >> config.mak - echo "SPPVERSION=$pp_version" >> config.mak - echo "LAVCMAJOR=${lavc_version%%.*}" >> config.mak - echo "LAVCVERSION=$lavc_version" >> config.mak - echo "LAVFMAJOR=${lavf_version%%.*}" >> config.mak - echo "LAVFVERSION=$lavf_version" >> config.mak - echo "LAVUMAJOR=${lavu_version%%.*}" >> config.mak - echo "LAVUVERSION=$lavu_version" >> config.mak - echo "SWSMAJOR=${sws_version%%.*}" >> config.mak - echo "SWSVERSION=$sws_version" >> config.mak - echo "SLIBNAME=${SLIBNAME}" >> config.mak - echo "SLIBNAME_WITH_VERSION=${SLIBNAME_WITH_VERSION}" >> config.mak - echo "SLIBNAME_WITH_MAJOR=${SLIBNAME_WITH_MAJOR}" >> config.mak - echo "SLIB_EXTRA_CMD=${SLIB_EXTRA_CMD}" >> config.mak - echo "SLIB_INSTALL_EXTRA_CMD=${SLIB_INSTALL_EXTRA_CMD}" >> config.mak + echo "BUILD_SHARED=yes" >> config.mak + echo "PIC=-fPIC -DPIC" >> config.mak + echo "SPPMAJOR=$LIBPOSTPROC_VERSION_MAJOR" >> config.mak + echo "SPPVERSION=$LIBPOSTPROC_VERSION" >> config.mak + echo "LAVCMAJOR=$LIBAVCODEC_VERSION_MAJOR" >> config.mak + echo "LAVCVERSION=$LIBAVCODEC_VERSION" >> config.mak + echo "LAVDMAJOR=$LIBAVDEVICE_VERSION_MAJOR" >> config.mak + echo "LAVDVERSION=$LIBAVDEVICE_VERSION" >> config.mak + echo "LAVFMAJOR=$LIBAVFORMAT_VERSION_MAJOR" >> config.mak + echo "LAVFVERSION=$LIBAVFORMAT_VERSION" >> config.mak + echo "LAVUMAJOR=$LIBAVUTIL_VERSION_MAJOR" >> config.mak + echo "LAVUVERSION=$LIBAVUTIL_VERSION" >> config.mak + echo "LAVFIMAJOR=$LIBAVFILTER_VERSION_MAJOR" >> config.mak + echo "LAVFIVERSION=$LIBAVFILTER_VERSION" >> config.mak + echo "SWSMAJOR=$LIBSWSCALE_VERSION_MAJOR" >> config.mak + echo "SWSVERSION=$LIBSWSCALE_VERSION" >> config.mak + echo "SLIBNAME=${SLIBNAME}" >> config.mak + echo "SLIBNAME_WITH_VERSION=${SLIBNAME_WITH_VERSION}" >> config.mak + echo "SLIBNAME_WITH_MAJOR=${SLIBNAME_WITH_MAJOR}" >> config.mak + echo "SLIB_CREATE_DEF_CMD=${SLIB_CREATE_DEF_CMD}" >> config.mak + echo "SLIB_EXTRA_CMD=${SLIB_EXTRA_CMD}" >> config.mak + echo "SLIB_INSTALL_EXTRA_CMD=${SLIB_INSTALL_EXTRA_CMD}" >> config.mak + echo "SLIB_UNINSTALL_EXTRA_CMD=${SLIB_UNINSTALL_EXTRA_CMD}" >> config.mak fi echo "LIB_INSTALL_EXTRA_CMD=${LIB_INSTALL_EXTRA_CMD}" >> config.mak echo "EXTRALIBS=$extralibs" >> config.mak +print_config ARCH_ $TMPH config.mak $ARCH_LIST print_config HAVE_ $TMPH config.mak $HAVE_LIST -print_config CONFIG_ $TMPH config.mak $CONFIG_LIST -print_config TARGET_ $TMPH config.mak $TARGET_LIST - -if test "$targetos" = darwin; then - echo "#define CONFIG_DARWIN 1" >> $TMPH -fi +print_config CONFIG_ $TMPH config.mak $CONFIG_LIST \ + $DECODER_LIST \ + $ENCODER_LIST \ + $PARSER_LIST \ + $BSF_LIST \ + $DEMUXER_LIST \ + $MUXER_LIST \ + $FILTER_LIST \ + $PROTOCOL_LIST \ + $INDEV_LIST \ + $OUTDEV_LIST \ echo "#define restrict $_restrict" >> $TMPH -if test "$optimize" = "small"; then - echo "#define always_inline" >> $TMPH - echo "#define CONFIG_SMALL 1" >> $TMPH +if enabled small; then + echo "#define av_always_inline" >> $TMPH fi echo "SRC_PATH=\"$source_path\"" >> config.mak echo "SRC_PATH_BARE=$source_path" >> config.mak echo "BUILD_ROOT=\"$PWD\"" >> config.mak -if enabled amr_if2; then - echo "AMR_CFLAGS=-DIF2=1" >> config.mak -fi - # Apparently it's not possible to portably echo a backslash. -if enabled asmalign_pot; then - printf '#define ASMALIGN(ZEROBITS) ".align " #ZEROBITS "\\n\\t"\n' >> $TMPH -else - printf '#define ASMALIGN(ZEROBITS) ".align 1<<" #ZEROBITS "\\n\\t"\n' >> $TMPH -fi +enabled asmalign_pot && + printf '#define ASMALIGN(ZEROBITS) ".align " #ZEROBITS "\\n\\t"\n' >> $TMPH || + printf '#define ASMALIGN(ZEROBITS) ".align 1<<" #ZEROBITS "\\n\\t"\n' >> $TMPH -for codec in $DECODER_LIST $ENCODER_LIST $PARSER_LIST $DEMUXER_LIST $MUXER_LIST; do - ucname="`toupper $codec`" - config_name="CONFIG_$ucname" - enabled_name="ENABLE_$ucname" - if enabled $codec; then - echo "#define $config_name 1" >> $TMPH - echo "#define $enabled_name 1" >> $TMPH - echo "$config_name=yes" >> config.mak - else - echo "#define $enabled_name 0" >> $TMPH - fi -done +echo "#endif /* FFMPEG_CONFIG_H */" >> $TMPH # Do not overwrite config.h if unchanged to avoid superfluous rebuilds. -if ! cmp -s $TMPH config.h; then - mv -f $TMPH config.h -else - echo "config.h is unchanged" -fi +cmp -s $TMPH config.h && + echo "config.h is unchanged" || + mv -f $TMPH config.h rm -f $TMPO $TMPC $TMPE $TMPS $TMPH # build tree in object directory if source path is different from current one if enabled source_path_used; then DIRS="\ - doc \ - libavformat \ - libavcodec \ - libavcodec/alpha \ - libavcodec/armv4l \ - libavcodec/bfin \ - libavcodec/i386 \ - libavcodec/sparc \ - libavcodec/mlib \ - libavcodec/ppc \ - libavcodec/amr \ - libavcodec/amr_float \ - libavcodec/amrwb_float \ - libpostproc \ - libavutil \ - libswscale \ - tests \ - vhook \ - " + doc \ + libavcodec \ + libavcodec/alpha \ + libavcodec/armv4l \ + libavcodec/bfin \ + libavcodec/i386 \ + libavcodec/mlib \ + libavcodec/ppc \ + libavcodec/sh4 \ + libavcodec/sparc \ + libavdevice \ + libavfilter \ + libavformat \ + libavutil \ + libpostproc \ + libswscale \ + tests \ + tools \ + vhook \ + " FILES="\ - Makefile \ - common.mak \ - libavformat/Makefile \ - libavcodec/Makefile \ - libpostproc/Makefile \ - libavutil/Makefile \ - libswscale/Makefile \ - tests/Makefile \ - vhook/Makefile \ - doc/Makefile \ - doc/texi2pod.pl \ - " + Makefile \ + common.mak \ + doc/texi2pod.pl \ + libavcodec/Makefile \ + libavdevice/Makefile \ + libavfilter/Makefile \ + libavformat/Makefile \ + libavutil/Makefile \ + libpostproc/Makefile \ + libswscale/Makefile \ + " for dir in $DIRS ; do - mkdir -p $dir + mkdir -p $dir done for f in $FILES ; do - ln -sf "$source_path/$f" $f + $ln_s "$source_path/$f" $f done fi @@ -2092,7 +2162,6 @@ comment=$2 version=$3 libs=$4 requires=$5 -include=$6 cat <<EOF >$name.pc prefix=$PREFIX exec_prefix=\${prefix} @@ -2105,7 +2174,7 @@ Version: $version Requires: $requires Conflicts: Libs: -L\${libdir} $libs -Cflags: -I\${includedir} -I\${includedir}/$include +Cflags: -I\${includedir} EOF } @@ -2120,7 +2189,7 @@ cat <<EOF >$name-uninstalled.pc prefix= exec_prefix= libdir=\${pcfiledir}/$name -includedir=\${pcfiledir}/$name +includedir=\${pcfiledir} Name: $name Description: $comment @@ -2132,26 +2201,33 @@ Cflags: -I\${includedir} EOF } -pkgconfig_generate libavutil "FFmpeg utility library" "$lavu_version" -lavutil "" ffmpeg -pkgconfig_generate_uninstalled libavutil "FFmpeg utility library" "$lavu_version" +pkgconfig_generate libavutil "FFmpeg utility library" "$LIBAVUTIL_VERSION" -lavutil "" +pkgconfig_generate_uninstalled libavutil "FFmpeg utility library" "$LIBAVUTIL_VERSION" -pkgconfig_generate libavcodec "FFmpeg codec library" "$lavc_version" "-lavcodec $extralibs" "$pkg_requires libavutil = $lavu_version" ffmpeg -pkgconfig_generate_uninstalled libavcodec "FFmpeg codec library" "$lavc_version" "$extralibs" "$pkg_requires libavutil = $lavu_version" +pkgconfig_generate libavcodec "FFmpeg codec library" "$LIBAVCODEC_VERSION" "-lavcodec $extralibs" "$pkg_requires libavutil = $LIBAVUTIL_VERSION" +pkgconfig_generate_uninstalled libavcodec "FFmpeg codec library" "$LIBAVCODEC_VERSION" "$extralibs" "$pkg_requires libavutil = $LIBAVUTIL_VERSION" -pkgconfig_generate libavformat "FFmpeg container format library" "$lavf_version" "-lavformat $extralibs" "$pkg_requires libavcodec = $lavc_version" ffmpeg -pkgconfig_generate_uninstalled libavformat "FFmpeg container format library" "$lavf_version" "$extralibs" "$pkg_requires libavcodec = $lavc_version" +pkgconfig_generate libavformat "FFmpeg container format library" "$LIBAVFORMAT_VERSION" "-lavformat $extralibs" "$pkg_requires libavcodec = $LIBAVCODEC_VERSION" +pkgconfig_generate_uninstalled libavformat "FFmpeg container format library" "$LIBAVFORMAT_VERSION" "$extralibs" "$pkg_requires libavcodec = $LIBAVCODEC_VERSION" +pkgconfig_generate libavdevice "FFmpeg device handling library" "$LIBAVDEVICE_VERSION" "-lavdevice $extralibs" "$pkg_requires libavformat = $LIBAVFORMAT_VERSION" +pkgconfig_generate_uninstalled libavdevice "FFmpeg device handling library" "$LIBAVDEVICE_VERSION" "$extralibs" "$pkg_requires libavformat = $LIBAVFORMAT_VERSION" if enabled pp; then - pkgconfig_generate libpostproc "FFmpeg post processing library" "$pp_version" -lpostproc "" postproc - pkgconfig_generate_uninstalled libpostproc "FFmpeg post processing library" "$pp_version" + pkgconfig_generate libpostproc "FFmpeg post processing library" "$LIBPOSTPROC_VERSION" -lpostproc "" + pkgconfig_generate_uninstalled libpostproc "FFmpeg post processing library" "$LIBPOSTPROC_VERSION" fi if enabled swscaler; then - pkgconfig_generate libswscale "FFmpeg image rescaling library" "$sws_version" -lswscale "libavutil = $lavu_version" ffmpeg - pkgconfig_generate_uninstalled libswscale "FFmpeg image rescaling library" "$sws_version" "" "libavutil = $lavu_version" + pkgconfig_generate libswscale "FFmpeg image rescaling library" "$LIBSWSCALE_VERSION" -lswscale "libavutil = $LIBAVUTIL_VERSION" + pkgconfig_generate_uninstalled libswscale "FFmpeg image rescaling library" "$LIBSWSCALE_VERSION" "" "libavutil = $LIBAVUTIL_VERSION" else - pkgconfig_generate libswscale "FFmpeg image rescaling library" "$sws_version" "" "$pkg_requires libavcodec = $lavc_version" ffmpeg - pkgconfig_generate_uninstalled libswscale "FFmpeg image rescaling library" "$sws_version" "" "$pkg_requires libavcodec = $lavc_version" - apply libswscale.pc sed s/^Libs:.*$/Libs:/ - apply libswscale-uninstalled.pc sed s/^Libs:.*$/Libs:/ + pkgconfig_generate libswscale "FFmpeg image rescaling library" "$LIBSWSCALE_VERSION" "" "$pkg_requires libavcodec = $LIBAVCODEC_VERSION" + pkgconfig_generate_uninstalled libswscale "FFmpeg image rescaling library" "$LIBSWSCALE_VERSION" "" "$pkg_requires libavcodec = $LIBAVCODEC_VERSION" + apply libswscale.pc sed s/^Libs:.*$/Libs:/ + apply libswscale-uninstalled.pc sed s/^Libs:.*$/Libs:/ +fi + +if enabled avfilter; then + pkgconfig_generate libavfilter "FFmpeg video filtering library" "$LIBAVFILTER_VERSION" "-lavfilter $extralibs" "$pkg_requires libavutil = $LIBAVUTIL_VERSION" ffmpeg + pkgconfig_generate_uninstalled libavfilter "FFmpeg video filtering library" "$LIBAVFILTER_VERSION" "$extralibs" "$pkg_requires libavutil = $LIBAVUTIL_VERSION" fi diff --git a/contrib/ffmpeg/cws2fws.c b/contrib/ffmpeg/cws2fws.c deleted file mode 100644 index 2e70c6618..000000000 --- a/contrib/ffmpeg/cws2fws.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * cws2fws by Alex Beregszaszi <alex@fsn.hu> - * Public domain. - * - * This utility converts compressed Macromedia Flash files to uncompressed ones. - * - */ - -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> -#include <zlib.h> - -#ifdef DEBUG -#define dbgprintf printf -#else -#define dbgprintf -#endif - -main(int argc, char *argv[]) -{ - int fd_in, fd_out, comp_len, uncomp_len, tag, i, last_out; - char buf_in[1024], buf_out[65536]; - z_stream zstream; - struct stat statbuf; - - if (argc < 3) - { - printf("Usage: %s <infile.swf> <outfile.swf>\n", argv[0]); - exit(1); - } - - fd_in = open(argv[1], O_RDONLY); - if (fd_in < 0) - { - perror("Error while opening: "); - exit(1); - } - - fd_out = open(argv[2], O_WRONLY|O_CREAT, 00644); - if (fd_out < 0) - { - perror("Error while opening: "); - close(fd_in); - exit(1); - } - - if (read(fd_in, &buf_in, 8) != 8) - { - printf("Header error\n"); - close(fd_in); - close(fd_out); - exit(1); - } - - if (buf_in[0] != 'C' || buf_in[1] != 'W' || buf_in[2] != 'S') - { - printf("Not a compressed flash file\n"); - exit(1); - } - - fstat(fd_in, &statbuf); - comp_len = statbuf.st_size; - uncomp_len = buf_in[4] | (buf_in[5] << 8) | (buf_in[6] << 16) | (buf_in[7] << 24); - - printf("Compressed size: %d Uncompressed size: %d\n", comp_len-4, uncomp_len-4); - - // write out modified header - buf_in[0] = 'F'; - write(fd_out, &buf_in, 8); - - zstream.zalloc = NULL; - zstream.zfree = NULL; - zstream.opaque = NULL; - inflateInit(&zstream); - - for (i = 0; i < comp_len-8;) - { - int ret, len = read(fd_in, &buf_in, 1024); - - dbgprintf("read %d bytes\n", len); - - last_out = zstream.total_out; - - zstream.next_in = &buf_in[0]; - zstream.avail_in = len; - zstream.next_out = &buf_out[0]; - zstream.avail_out = 65536; - - ret = inflate(&zstream, Z_SYNC_FLUSH); - if (ret != Z_STREAM_END && ret != Z_OK) - { - printf("Error while decompressing: %d\n", ret); - inflateEnd(&zstream); - exit(1); - } - - dbgprintf("a_in: %d t_in: %d a_out: %d t_out: %d -- %d out\n", - zstream.avail_in, zstream.total_in, zstream.avail_out, zstream.total_out, - zstream.total_out-last_out); - - write(fd_out, &buf_out, zstream.total_out-last_out); - - i += len; - - if (ret == Z_STREAM_END || ret == Z_BUF_ERROR) - break; - } - - if (zstream.total_out != uncomp_len-8) - { - printf("Size mismatch (%d != %d), updating header...\n", - zstream.total_out, uncomp_len-8); - - buf_in[0] = (zstream.total_out+8) & 0xff; - buf_in[1] = (zstream.total_out+8 >> 8) & 0xff; - buf_in[2] = (zstream.total_out+8 >> 16) & 0xff; - buf_in[3] = (zstream.total_out+8 >> 24) & 0xff; - - lseek(fd_out, 4, SEEK_SET); - write(fd_out, &buf_in, 4); - } - - inflateEnd(&zstream); - close(fd_in); - close(fd_out); -} diff --git a/contrib/ffmpeg/doc/Makefile b/contrib/ffmpeg/doc/Makefile deleted file mode 100644 index 4fc9dfb8f..000000000 --- a/contrib/ffmpeg/doc/Makefile +++ /dev/null @@ -1,20 +0,0 @@ --include ../config.mak - -VPATH=$(SRC_PATH_BARE)/doc - -all: ffmpeg-doc.html faq.html ffserver-doc.html ffplay-doc.html hooks.html \ - ffmpeg.1 ffserver.1 ffplay.1 - -%.html: %.texi Makefile - texi2html -monolithic -number $< - -%.pod: %-doc.texi - ./texi2pod.pl $< $@ - -%.1: %.pod - pod2man --section=1 --center=" " --release=" " $< > $@ - -clean: - rm -f *.html *.pod *.1 - -.PHONY: all clean diff --git a/contrib/ffmpeg/doc/TODO b/contrib/ffmpeg/doc/TODO index 996ce3177..a8567a5ec 100644 --- a/contrib/ffmpeg/doc/TODO +++ b/contrib/ffmpeg/doc/TODO @@ -68,24 +68,23 @@ unassigned TODO: (unordered) - SNOW: 4x4 block support - SNOW: 1/8 pel motion compensation support - SNOW: iterative motion estimation based on subsampled images +- SNOW: try B frames and MCTF and see how their PSNR/bitrate/complexity behaves +- SNOW: try to use the wavelet transformed MC-ed reference frame as context for the entropy coder +- SNOW: think about/analyize how to make snow use multiple cpus/threads +- SNOW: finish spec - FLAC: lossy encoding (viterbi and naive scalar quantization) - libavfilter - JPEG2000 decoder & encoder - MPEG4 GMC encoding support - macroblock based pixel format (better cache locality, somewhat complex, one paper claimed it faster for high res) -- NUT muxer -- seeking regression test -- regression tests for codecs which dont have an encoder (I+P frame bitstream in svn) +- regression tests for codecs which do not have an encoder (I+P-frame bitstream in svn) - add support for using mplayers video filters to ffmpeg -- reverse engeneer RV30/RV40 -- finish implementation of WMV2 j-picture - H264 encoder - per MB ratecontrol (so VCD and such do work better) - replace/rewrite libavcodec/fdctref.c - write a script which iteratively changes all functions between always_inline and noinline and benchmarks the result to find the best set of inlined functions -- set up roundup bugtracker somewhere with (newBug, reproduced, analyzed, fixed, worksForMe, duplicate, wontFix, invalid, needMoreInfo, newPatch, ok, applied, rejected, needChanges, newRequest, implemented, wontImplement, invalidReq) states and a checked integer - convert all the non SIMD asm into small asm vs. C testcases and submit them to the gcc devels so they can improve gcc - generic audio mixing API - extract PES packetizer from PS muxer and use it for new TS muxer - implement automatic AVBistreamFilter activation -- port libavformat/sgi.c (now removed) to new image format API +- make cabac encoder use bytestream (see http://trac.videolan.org/x264/changeset/?format=diff&new=651) diff --git a/contrib/ffmpeg/doc/avutil.txt b/contrib/ffmpeg/doc/avutil.txt index a81e74118..210bd0726 100644 --- a/contrib/ffmpeg/doc/avutil.txt +++ b/contrib/ffmpeg/doc/avutil.txt @@ -34,4 +34,4 @@ Goals: * Modular (few interdependencies and the possibility of disabling individual parts during ./configure) * Small (source and object) * Efficient (low CPU and memory usage) -* Useful (avoid useless features almost noone needs) +* Useful (avoid useless features almost no one needs) diff --git a/contrib/ffmpeg/doc/faq.texi b/contrib/ffmpeg/doc/faq.texi index 9c41679ae..85a0915b9 100644 --- a/contrib/ffmpeg/doc/faq.texi +++ b/contrib/ffmpeg/doc/faq.texi @@ -8,29 +8,123 @@ @end titlepage -@chapter General Problems +@chapter General Questions + +@section When will the next FFmpeg version be released? / Why are FFmpeg releases so few and far between? + +Like most open source projects FFmpeg suffers from a certain lack of +manpower. For this reason the developers have to prioritize the work +they do and putting out releases is not at the top of the list, fixing +bugs and reviewing patches takes precedence. Please don't complain or +request more timely and/or frequent releases unless you are willing to +help out creating them. + +@section I have a problem with an old version of FFmpeg; where should I report it? +Nowhere. Upgrade to the latest release or if there is no recent release upgrade +to Subversion HEAD. You could also try to report it. Maybe you will get lucky and +become the first person in history to get an answer different from "upgrade +to Subversion HEAD". + +@section Why doesn't FFmpeg support feature [xyz]? + +Because no one has taken on that task yet. FFmpeg development is +driven by the tasks that are important to the individual developers. +If there is a feature that is important to you, the best way to get +it implemented is to undertake the task yourself or sponsor a developer. + +@section FFmpeg does not support codec XXX. Can you include a Windows DLL loader to support it? + +No. Windows DLLs are not portable, bloated and often slow. +Moreover FFmpeg strives to support all codecs natively. +A DLL loader is not conducive to that goal. + +@section My bugreport/mail to ffmpeg-devel/user has not received any replies. + +Likely reasons +@itemize +@item We are busy and haven't had time yet to read your report or +investigate the issue. +@item You didn't follow bugreports.html. +@item You didn't use Subversion HEAD. +@item You reported a segmentation fault without gdb output. +@item You describe a problem but not how to reproduce it. +@item It's unclear if you use ffmpeg as command line tool or use +libav* from another application. +@item You speak about a video having problems on playback but +not what you use to play it. +@item We have no faint clue what you are talking about besides +that it is related to FFmpeg. +@end itemize + +@section Is there a forum for FFmpeg? I do not like mailing lists. + +Yes, (@url{http://dir.gmane.org/gmane.comp.video.ffmpeg.user}). @section I cannot read this file although this format seems to be supported by ffmpeg. -Even if ffmpeg can read the file format, it may not support all its +Even if ffmpeg can read the container format, it may not support all its codecs. Please consult the supported codec list in the ffmpeg documentation. -@section How do I encode JPEGs to another format ? +@section Which codecs are supported by Windows? + +Windows does not support standard formats like MPEG very well, unless you +install some additional codecs + +The following list of video codecs should work on most Windows systems: +@table @option +@item msmpeg4v2 +.avi/.asf +@item msmpeg4 +.asf only +@item wmv1 +.asf only +@item wmv2 +.asf only +@item mpeg4 +only if you have some MPEG-4 codec installed like ffdshow or XviD +@item mpeg1 +.mpg only +@end table +Note, ASF files often have .wmv or .wma extensions in Windows. It should also +be mentioned that Microsoft claims a patent on the ASF format, and may sue +or threaten users who create ASF files with non-Microsoft software. It is +strongly advised to avoid ASF where possible. -If the JPEGs are named img1.jpg, img2.jpg, img3.jpg,..., use: +The following list of audio codecs should work on most Windows systems: +@table @option +@item adpcm_ima_wav +@item adpcm_ms +@item pcm +@item mp3 +if some MP3 codec like LAME is installed +@end table + + +@chapter Usage + +@section ffmpeg does not work; What is wrong? + +Try a @code{make distclean} in the ffmpeg source directory before the build. If this does not help see +(@url{http://ffmpeg.org/bugreports.html}). + +@section How do I encode single pictures to movies? + +First, rename your pictures to follow a numerical sequence. +For example, img1.jpg, img2.jpg, img3.jpg,... +Then you may run: @example ffmpeg -f image2 -i img%d.jpg /tmp/a.mpg @end example -@samp{%d} is replaced by the image number. +Notice that @samp{%d} is replaced by the image number. -@file{img%03d.jpg} generates @file{img001.jpg}, @file{img002.jpg}, etc... +@file{img%03d.jpg} means the sequence @file{img001.jpg}, @file{img002.jpg}, etc... -The same system is used for the other image formats. +The same logic is used for any image format that ffmpeg reads. -@section How do I encode movie to single pictures ? +@section How do I encode movie to single pictures? Use: @@ -56,68 +150,28 @@ Applying that to the previous example: Beware that there is no "jpeg" codec. Use "mjpeg" instead. -@section FFmpeg does not support codec XXX. Can you include a Windows DLL loader to support it ? - -No. FFmpeg only supports open source codecs. Windows DLLs are not -portable, bloated and often slow. - -@section I get "Unsupported codec (id=86043) for input stream #0.1". What is the problem ? +@section I get "Unsupported codec (id=86043) for input stream #0.1". What is the problem? This is the Qcelp codec, FFmpeg has no support for that codec currently. Try mencoder/mplayer it might work. -@section Why do I see a slight quality degradation with multithreaded MPEG* encoding ? +@section Why do I see a slight quality degradation with multithreaded MPEG* encoding? For multithreaded MPEG* encoding, the encoded slices must be independent, otherwise thread n would practically have to wait for n-1 to finish, so it's quite logical that there is a small reduction of quality. This is not a bug. -@section How can I read from the standard input or write to the standard output ? +@section How can I read from the standard input or write to the standard output? Use @file{-} as filename. -@section Why does ffmpeg not decode audio in VOB files ? +@section Why does FFmpeg not decode audio in VOB files? -The audio is AC3 (a.k.a. A/52). AC3 decoding is an optional component in ffmpeg -as the component that handles AC3 decoding (liba52) is currently released under -the GPL. If you have liba52 installed on your system, enable AC3 decoding -with @code{./configure --enable-liba52 --enable-gpl}. Take care: by -enabling AC3, you automatically change the license of libavcodec from +The audio is AC-3 (a.k.a. A/52). AC-3 decoding is an optional component in FFmpeg +as the component that handles AC-3 decoding is currently released under the GPL. +Enable AC-3 decoding with @code{./configure --enable-gpl}. Take care: By +enabling AC-3, you automatically change the license of libavcodec from LGPL to GPL. -@section Which codecs are supported by Windows ? - -Windows does not support standard formats like MPEG very well, unless you -install some additional codecs - -The following list of video codecs should work on most Windows systems: -@table @option -@item msmpeg4v2 -.avi/.asf -@item msmpeg4 -.asf only -@item wmv1 -.asf only -@item wmv2 -.asf only -@item mpeg4 -only if you have some MPEG-4 codec installed like ffdshow or XviD -@item mpeg1 -.mpg only -@end table -Note, ASF files often have .wmv or .wma extensions in Windows. It should also -be mentioned that Microsoft claims a patent on the ASF format, and may sue -or threaten users who create ASF files with non-Microsoft software. It is -strongly advised to avoid ASF where possible. - -The following list of audio codecs should work on most Windows systems: -@table @option -@item adpcm_ima_wav -@item adpcm_ms -@item pcm -@item mp3 -if some MP3 codec like LAME is installed -@end table - @section Why does the chrominance data seem to be sampled at a different time from the luminance data on bt8x8 captures on Linux? This is a well-known bug in the bt8x8 driver. For 2.4.26 there is a patch at @@ -131,12 +185,6 @@ will cause somewhat too strong filtering. A fix is to apply (@url{http://svn.mpl or (@url{http://svn.mplayerhq.hu/michael/trunk/patches/bttv-comb-2.6.6.patch?view=co}) and pass 'combfilter=2'. -@section I have a problem with an old version of ffmpeg; where should I report it? -Nowhere. Upgrade to the latest release or if there is no recent release upgrade -to Subversion HEAD. You could also try to report it. Maybe you will get lucky and -become the first person in history to get an answer different from "upgrade -to Subversion HEAD". - @section -f jpeg doesn't work. Try '-f image2 test%d.jpg'. @@ -146,11 +194,6 @@ Try '-f image2 test%d.jpg'. Some codecs, like MPEG-1/2, only allow a small number of fixed framerates. Choose a different codec with the -vcodec command line option. -@section ffmpeg does not work; What is wrong? - -Try a 'make distclean' in the ffmpeg source directory before the build. If this does not help see -(@url{http://ffmpeg.org/bugreports.php}). - @section How do I encode XviD or DivX video with ffmpeg? Both XviD and DivX (version 4+) are implementations of the ISO MPEG-4 @@ -165,34 +208,34 @@ default. @table @option @item needed stuff --acodec aac -vcodec mpeg4 width<=320 height<=240 +-acodec libfaac -vcodec mpeg4 width<=320 height<=240 @item working stuff 4mv, title @item non-working stuff B-frames @item example command line -ffmpeg -i input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title X output.mp4 +ffmpeg -i input -acodec libfaac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title X output.mp4 @end table @section How do I encode videos which play on the PSP? @table @option @item needed stuff --acodec aac -vcodec mpeg4 width*height<=76800 width%16=0 height%16=0 -ar 24000 -r 30000/1001 or 15000/1001 -f psp +-acodec libfaac -vcodec mpeg4 width*height<=76800 width%16=0 height%16=0 -ar 24000 -r 30000/1001 or 15000/1001 -f psp @item working stuff 4mv, title @item non-working stuff B-frames @item example command line -ffmpeg -i input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -ar 24000 -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 368x192 -r 30000/1001 -title X -f psp output.mp4 +ffmpeg -i input -acodec libfaac -ab 128kb -vcodec mpeg4 -b 1200kb -ar 24000 -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 368x192 -r 30000/1001 -title X -f psp output.mp4 @item needed stuff for H.264 --acodec aac -vcodec h264 width*height<=76800 width%16=0? height%16=0? -ar 48000 -coder 1 -r 30000/1001 or 15000/1001 -f psp +-acodec libfaac -vcodec h264 width*height<=76800 width%16=0? height%16=0? -ar 48000 -coder 1 -r 30000/1001 or 15000/1001 -f psp @item working stuff for H.264 title, loop filter @item non-working stuff for H.264 CAVLC @item example command line -ffmpeg -i input -acodec aac -ab 128kb -vcodec h264 -b 1200kb -ar 48000 -mbd 2 -coder 1 -cmp 2 -subcmp 2 -s 368x192 -r 30000/1001 -title X -f psp -flags loop -trellis 2 -partitions parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 output.mp4 +ffmpeg -i input -acodec libfaac -ab 128kb -vcodec h264 -b 1200kb -ar 48000 -mbd 2 -coder 1 -cmp 2 -subcmp 2 -s 368x192 -r 30000/1001 -title X -f psp -flags loop -trellis 2 -partitions parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 output.mp4 @end table @section Which are good parameters for encoding high quality MPEG-4? @@ -230,99 +273,141 @@ Just create an "input.avs" text file with this single line ... For ANY other help on Avisynth, please visit @url{http://www.avisynth.org/}. -@section My bugreport/mail to ffmpeg-devel/user has not received any replies. +@section How can I join video files? -Likely reasons -@itemize -@item We are busy and haven't had time yet to read your report or -investigate the issue. -@item You didn't follow bugreports.html. -@item You didn't use Subversion HEAD. -@item You reported a segmentation fault without gdb output. -@item You describe a problem but not how to reproduce it. -@item It's unclear if you use ffmpeg as command line tool or use -libav* from another application. -@item You speak about a video having problems on playback but -not what you use to play it. -@item We have no faint clue what you are talking about besides -that it is related to FFmpeg. -@end itemize +A few multimedia containers (MPEG-1, MPEG-2 PS, DV) allow to join video files by +merely concatenating them. -@chapter Development +Hence you may concatenate your multimedia files by first transcoding them to +these privileged formats, then using the humble @code{cat} command (or the +equally humble @code{copy} under Windows), and finally transcoding back to your +format of choice. -@section When will the next FFmpeg version be released? / Why are FFmpeg releases so few and far between? +@example +ffmpeg -i input1.avi -sameq intermediate1.mpg +ffmpeg -i input2.avi -sameq intermediate2.mpg +cat intermediate1.mpg intermediate2.mpg > intermediate_all.mpg +ffmpeg -i intermediate_all.mpg -sameq output.avi +@end example -Like most open source projects FFmpeg suffers from a certain lack of -manpower. For this reason the developers have to prioritize the work -they do and putting out releases is not at the top of the list, fixing -bugs and reviewing patches takes precedence. Please don't complain or -request more timely and/or frequent releases unless you are willing to -help out creating them. +Notice that you should either use @code{-sameq} or set a reasonably high +bitrate for your intermediate and output files, if you want to preserve +video quality. -@section Why doesn't FFmpeg support feature [xyz]? +Also notice that you may avoid the huge intermediate files by taking advantage +of named pipes, should your platform support it: -Because no one has taken on that task yet. FFmpeg development is -driven by the tasks that are important to the individual developers. -If there is a feature that is important to you, the best way to get -it implemented is to undertake the task yourself. +@example +mkfifo intermediate1.mpg +mkfifo intermediate2.mpg +ffmpeg -i input1.avi -sameq -y intermediate1.mpg < /dev/null & +ffmpeg -i input2.avi -sameq -y intermediate2.mpg < /dev/null & +cat intermediate1.mpg intermediate2.mpg |\ +ffmpeg -f mpeg -i - -sameq -vcodec mpeg4 -acodec libmp3lame output.avi +@end example + +Similarly, the yuv4mpegpipe format, and the raw video, raw audio codecs also +allow concatenation, and the transcoding step is almost lossless. + +For example, let's say we want to join two FLV files into an output.flv file: +@example +mkfifo temp1.a +mkfifo temp1.v +mkfifo temp2.a +mkfifo temp2.v +mkfifo all.a +mkfifo all.v +ffmpeg -i input1.flv -vn -f u16le -acodec pcm_s16le -ac 2 -ar 44100 - > temp1.a < /dev/null & +ffmpeg -i input2.flv -vn -f u16le -acodec pcm_s16le -ac 2 -ar 44100 - > temp2.a < /dev/null & +ffmpeg -i input1.flv -an -f yuv4mpegpipe - > temp1.v < /dev/null & +ffmpeg -i input2.flv -an -f yuv4mpegpipe - > temp2.v < /dev/null & +cat temp1.a temp2.a > all.a & +cat temp1.v temp2.v > all.v & +ffmpeg -f u16le -acodec pcm_s16le -ac 2 -ar 44100 -i all.a \ + -f yuv4mpegpipe -i all.v \ + -sameq -y output.flv +rm temp[12].[av] all.[av] +@end example + +@section FFmpeg does not adhere to the -maxrate setting, some frames are bigger than maxrate/fps. + +Read the MPEG spec about video buffer verifier. + +@section I want CBR, but no matter what I do frame sizes differ. + +You do not understand what CBR is, please read the MPEG spec. +Read about video buffer verifier and constant bitrate. +The one sentence summary is that there is a buffer and the input rate is +constant, the output can vary as needed. + +@section How do I check if a stream is CBR? + +To quote the MPEG-2 spec: +"There is no way to tell that a bitstream is constant bitrate without +examining all of the vbv_delay values and making complicated computations." + + +@chapter Development -@section Are there examples illustrating how to use the FFmpeg libraries, particularly libavcodec and libavformat ? +@section Are there examples illustrating how to use the FFmpeg libraries, particularly libavcodec and libavformat? Yes. Read the Developers Guide of the FFmpeg documentation. Alternatively, examine the source code for one of the many open source projects that -already incorporate ffmpeg at (@url{projects.php}). +already incorporate ffmpeg at (@url{projects.html}). -@section Can you support my C compiler XXX ? +@section Can you support my C compiler XXX? It depends. If your compiler is C99-compliant, then patches to support it are likely to be welcome if they do not pollute the source code with @code{#ifdef}s related to the compiler. -@section Visual C++ produces many errors. +@section Is Microsoft Visual C++ supported? -Visual C++ is not compliant to the C standard and does not support -the inline assembly used in FFmpeg. -If you wish - for whatever weird reason - to use Visual C++ for your -project then you can link the Visual C++ code with libav* as long as +No. Microsoft Visual C++ is not compliant to the C99 standard and does +not - among other things - support the inline assembly used in FFmpeg. +If you wish to use MSVC++ for your +project then you can link the MSVC++ code with libav* as long as you compile the latter with a working C compiler. For more information, see -the @emph{Visual C++ compatibility} section in the FFmpeg documentation. +the @emph{Microsoft Visual C++ compatibility} section in the FFmpeg +documentation. -There have been efforts to make FFmpeg compatible with Visual C++ in the +There have been efforts to make FFmpeg compatible with MSVC++ in the past. However, they have all been rejected as too intrusive, especially -since MinGW does the job perfectly adequately. None of the core developers -work with Visual C++ and thus this item is low priority. Should you find +since MinGW does the job adequately. None of the core developers +work with MSVC++ and thus this item is low priority. Should you find the silver bullet that solves this problem, feel free to shoot it at us. -@section Can I use FFmpeg or libavcodec under Windows ? +We strongly recommend you to move over from MSVC++ to MinGW tools. + +@section Can I use FFmpeg or libavcodec under Windows? -Yes, but the MinGW tools @emph{must} be used to compile FFmpeg. You -can link the resulting DLLs with any other Windows program. Read the -@emph{Native Windows Compilation} and @emph{Visual C++ compatibility} -sections in the FFmpeg documentation to find more information. +Yes, but the Cygwin or MinGW tools @emph{must} be used to compile FFmpeg. +Read the @emph{Windows} section in the FFmpeg documentation to find more +information. -To get help and instructions for using FFmpeg under Windows, check out +To get help and instructions for building FFmpeg under Windows, check out the FFmpeg Windows Help Forum at @url{http://arrozcru.no-ip.org/ffmpeg/}. -@section Can you add automake, libtool or autoconf support ? +@section Can you add automake, libtool or autoconf support? No. These tools are too bloated and they complicate the build. -@section Why not rewrite ffmpeg in object-oriented C++ ? +@section Why not rewrite ffmpeg in object-oriented C++? ffmpeg is already organized in a highly modular manner and does not need to be rewritten in a formal object language. Further, many of the developers favor straight C; it works for them. For more arguments on this matter, read "Programming Religion" at (@url{http://www.tux.org/lkml/#s15}). -@section Why are the ffmpeg programs devoid of debugging symbols ? +@section Why are the ffmpeg programs devoid of debugging symbols? The build process creates ffmpeg_g, ffplay_g, etc. which contain full debug information. Those binaries are strip'd to create ffmpeg, ffplay, etc. If you need the debug information, used the *_g versions. -@section I do not like the LGPL, can I contribute code under the GPL instead ? +@section I do not like the LGPL, can I contribute code under the GPL instead? Yes, as long as the code is optional and can easily and cleanly be placed under #ifdef CONFIG_GPL without breaking anything. So for example a new codec @@ -336,7 +421,15 @@ the whole libav*. If you wish, disable some parts with configure switches. You can also try to hack it and remove more, but if you had problems fixing the compilation failure then you are probably not qualified for this. -@section I have a file in memory / a API different from *open/*read/ libc how do i use it with libavformat ? +@section I'm using libavcodec from within my C++ application but the linker complains about missing symbols which seem to be available. + +FFmpeg is a pure C project, so to use the libraries within your C++ application +you need to explicitly state that you are using a C library. You can do this by +encompassing your FFmpeg includes using @code{extern "C"}. + +See @url{http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html#faq-32.3} + +@section I have a file in memory / a API different from *open/*read/ libc how do i use it with libavformat? You have to implement a URLProtocol, see libavformat/file.c in FFmpeg and libmpdemux/demux_lavf.c in MPlayer sources. @@ -345,19 +438,35 @@ and libmpdemux/demux_lavf.c in MPlayer sources. The standard MSys bash (2.04) is broken. You need to install 2.05 or later. +@section I get "./configure: line <xxx>: pr: command not found" in MSys. + +The standard MSys install doesn't come with pr. You need to get it from the coreutils package. + @section I tried to pass RTP packets into a decoder, but it doesn't work. -Of course not, you MUST strip ALL RTP headers and assemble valid packets -first, an MP3 decoder decodes MP3 packets not bastardized MP3 packets -encapsulated in RTP. The same applies to all decoders, this is not specific -to ffmpeg or libavcodec. +RTP is a container format like any other, you must first depacketize the +codec frames/samples stored in RTP and then feed to the decoder. -@section where can i find libav* headers for pascal/delphi +@section Where can I find libav* headers for Pascal/Delphi? see @url{http://www.iversenit.dk/dev/ffmpeg-headers/} -@section where are the docs about ffv1, msmpeg4, asv1, 4xm? +@section Where is the documentation about ffv1, msmpeg4, asv1, 4xm? see @url{http://svn.mplayerhq.hu/michael/trunk/docs/} +@section How do I feed H.263-RTP (and other codecs in RTP) to libavcodec? + +Even if peculiar since it is network oriented, RTP is a container like any +other. You have to @emph{demux} RTP before feeding the payload to libavcodec. +In this specific case please look at RFC 4629 to see how it should be done. + +@section AVStream.r_frame_rate is wrong, it is much larger than the framerate. + +r_frame_rate is NOT the average framerate, it is the smallest framerate +that can accurately represent all timestamps. So no, it is not +wrong if it is larger than the average! +For example, if you have mixed 25 and 30 fps content, then r_frame_rate +will be 150. + @bye diff --git a/contrib/ffmpeg/doc/ffmpeg-doc.texi b/contrib/ffmpeg/doc/ffmpeg-doc.texi index e4e6430fd..baa257726 100644 --- a/contrib/ffmpeg/doc/ffmpeg-doc.texi +++ b/contrib/ffmpeg/doc/ffmpeg-doc.texi @@ -30,7 +30,7 @@ FFmpeg can grab video and audio from devices given that you specify the input format and device. @example -ffmpeg -f audio_device -i /dev/dsp -f video4linux2 -i /dev/video0 /tmp/out.mpg +ffmpeg -f oss -i /dev/dsp -f video4linux2 -i /dev/video0 /tmp/out.mpg @end example Note that you must activate the right video source and channel before @@ -44,14 +44,14 @@ standard mixer. FFmpeg can grab the X11 display. @example -ffmpeg -f x11grab -i :0.0 /tmp/out.mpg +ffmpeg -f x11grab -s cif -i :0.0 /tmp/out.mpg @end example 0.0 is display.screen number of your X11 server, same as the DISPLAY environment variable. @example -ffmpeg -f x11grab -i :0.0+10,20 /tmp/out.mpg +ffmpeg -f x11grab -s cif -i :0.0+10,20 /tmp/out.mpg @end example 0.0 is display.screen number of your X11 server, same as the DISPLAY environment @@ -127,7 +127,7 @@ stream, in the order of the definition of output streams. * You can transcode decrypted VOBs @example -ffmpeg -i snatch_1.vob -f avi -vcodec mpeg4 -b 800k -g 300 -bf 2 -acodec mp3 -ab 128k snatch.avi +ffmpeg -i snatch_1.vob -f avi -vcodec mpeg4 -b 800k -g 300 -bf 2 -acodec libmp3lame -ab 128k snatch.avi @end example This is a typical DVD ripping example; the input is a VOB file, the @@ -135,7 +135,7 @@ output an AVI file with MPEG-4 video and MP3 audio. Note that in this command we use B-frames so the MPEG-4 stream is DivX5 compatible, and GOP size is 300 which means one intra frame every 10 seconds for 29.97fps input video. Furthermore, the audio stream is MP3-encoded so you need -to enable LAME support by passing @code{--enable-mp3lame} to configure. +to enable LAME support by passing @code{--enable-libmp3lame} to configure. The mapping is particularly useful for DVD transcoding to get the desired audio language. @@ -212,7 +212,8 @@ input filename Overwrite output files. @item -t duration -Set the recording time in seconds. +Restrict the transcoded/captured video sequence +to the duration specified in seconds. @code{hh:mm:ss[.xxx]} syntax is also supported. @item -fs limit_size @@ -254,8 +255,8 @@ Set the track. @item -year number Set the year. -@item -v verbose -Control amount of logging. +@item -v number +Set the logging verbosity level. @item -target type Specify target file type ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd", @@ -308,6 +309,54 @@ The following abbreviations are recognized: 352x288 @item 4cif 704x576 +@item qqvga +160x120 +@item qvga +320x240 +@item vga +640x480 +@item svga +800x600 +@item xga +1024x768 +@item uxga +1600x1200 +@item qxga +2048x1536 +@item sxga +1280x1024 +@item qsxga +2560x2048 +@item hsxga +5120x4096 +@item wvga +852x480 +@item wxga +1366x768 +@item wsxga +1600x1024 +@item wuxga +1920x1200 +@item woxga +2560x1600 +@item wqsxga +3200x2048 +@item wquxga +3840x2400 +@item whsxga +6400x4096 +@item whuxga +7680x4800 +@item cga +320x200 +@item ega +640x350 +@item hd480 +852x480 +@item hd720 +1280x720 +@item hd1080 +1920x1080 @end table @item -aspect aspect @@ -338,11 +387,11 @@ Disable video recording. @item -bt tolerance Set video bitrate tolerance (in bit/s). @item -maxrate bitrate -Set max video bitrate tolerance (in bit/s). +Set max video bitrate (in bit/s). @item -minrate bitrate -Set min video bitrate tolerance (in bit/s). +Set min video bitrate (in bit/s). @item -bufsize size -Set rate control buffer size (in bits). +Set video buffer verifier buffer size (in bits). @item -vcodec codec Force video codec to @var{codec}. Use the @code{copy} special value to tell that the raw codec data must be copied as is. @@ -367,7 +416,10 @@ Add a new video stream to the current output stream. @table @option @item -pix_fmt format -Set pixel format. +Set pixel format. Use 'list' as parameter to show all the supported +pixel formats. +@item -sws_flags flags +Set SwScaler flags (only available when compiled with SwScaler support). @item -g gop_size Set the group of pictures size. @item -intra @@ -417,7 +469,7 @@ Set rate control equation (@pxref{FFmpeg formula evaluator}) (default = @code{tex^qComp}). @item -rc_override override rate control override for specific intervals -@item -me method +@item -me_method method Set motion estimation method to @var{method}. Available methods are (from lowest to best quality): @table @samp @@ -426,6 +478,8 @@ Try just the (0, 0) vector. @item phods @item log @item x1 +@item hex +@item umh @item epzs (default method) @item full @@ -537,6 +591,8 @@ The alternative is to deinterlace the input stream with Calculate PSNR of compressed frames. @item -vstats Dump video coding statistics to @file{vstats_HHMMSS.log}. +@item -vstats_file file +Dump video coding statistics to @var{file}. @item -vhook module Insert video processing @var{module}. @var{module} contains the module name and its parameters separated by spaces. @@ -656,6 +712,16 @@ Audio sync method. "Stretches/squeezes" the audio stream to match the timestamps the parameter is the maximum samples per second by which the audio is changed. -async 1 is a special case where only the start of the audio stream is corrected without any later correction. +@item -copyts +Copy timestamps from input to output. +@item -shortest +Finish encoding when the shortest input stream ends. +@item -dts_delta_threshold +Timestamp discontinuity delta threshold. +@item -muxdelay seconds +Set the maximum demux-decode delay. +@item -muxpreload seconds +Set the initial demux-decode delay. @end table @node FFmpeg formula evaluator @@ -784,873 +850,4 @@ It allows almost lossless encoding. @end itemize - -@chapter external libraries - -FFmpeg can be hooked up with a number of external libraries to add support -for more formats. - -@section AMR - -AMR comes in two different flavors, WB and NB. FFmpeg can make use of the -AMR WB (floating-point mode) and the AMR NB (both floating-point and -fixed-point mode) reference decoders and encoders. - -@itemize - -@item For AMR WB floating-point download TS26.204 V5.1.0 from -@url{http://www.3gpp.org/ftp/Specs/archive/26_series/26.204/26204-510.zip} -and extract the source to @file{libavcodec/amrwb_float/}. - -@item For AMR NB floating-point download TS26.104 REL-5 V5.1.0 from -@url{http://www.3gpp.org/ftp/Specs/archive/26_series/26.104/26104-510.zip} -and extract the source to @file{libavcodec/amr_float/}. -If you try this on Alpha, you may need to change @code{Word32} to -@code{int} in @file{amr/typedef.h}. - -@item For AMR NB fixed-point download TS26.073 REL-5 V5.1.0 from -@url{http://www.3gpp.org/ftp/Specs/archive/26_series/26.073/26073-510.zip} -and extract the source to @file{libavcodec/amr}. -You must also add @code{-DMMS_IO} and remove @code{-pedantic-errors} -to/from @code{CFLAGS} in @file{libavcodec/amr/makefile}, i.e. -``@code{CFLAGS = -Wall -I. \$(CFLAGS_\$(MODE)) -D\$(VAD) -DMMS_IO}''. - -@end itemize - - -@chapter Supported File Formats and Codecs - -You can use the @code{-formats} option to have an exhaustive list. - -@section File Formats - -FFmpeg supports the following file formats through the @code{libavformat} -library: - -@multitable @columnfractions .4 .1 .1 .4 -@item Supported File Format @tab Encoding @tab Decoding @tab Comments -@item MPEG audio @tab X @tab X -@item MPEG-1 systems @tab X @tab X -@tab muxed audio and video -@item MPEG-2 PS @tab X @tab X -@tab also known as @code{VOB} file -@item MPEG-2 TS @tab @tab X -@tab also known as DVB Transport Stream -@item ASF@tab X @tab X -@item AVI@tab X @tab X -@item WAV@tab X @tab X -@item Macromedia Flash@tab X @tab X -@tab Only embedded audio is decoded. -@item FLV @tab X @tab X -@tab Macromedia Flash video files -@item Real Audio and Video @tab X @tab X -@item Raw AC3 @tab X @tab X -@item Raw MJPEG @tab X @tab X -@item Raw MPEG video @tab X @tab X -@item Raw PCM8/16 bits, mulaw/Alaw@tab X @tab X -@item Raw CRI ADX audio @tab X @tab X -@item Raw Shorten audio @tab @tab X -@item SUN AU format @tab X @tab X -@item NUT @tab X @tab X @tab NUT Open Container Format -@item QuickTime @tab X @tab X -@item MPEG-4 @tab X @tab X -@tab MPEG-4 is a variant of QuickTime. -@item Raw MPEG4 video @tab X @tab X -@item DV @tab X @tab X -@item 4xm @tab @tab X -@tab 4X Technologies format, used in some games. -@item Playstation STR @tab @tab X -@item Id RoQ @tab @tab X -@tab Used in Quake III, Jedi Knight 2, other computer games. -@item Interplay MVE @tab @tab X -@tab Format used in various Interplay computer games. -@item WC3 Movie @tab @tab X -@tab Multimedia format used in Origin's Wing Commander III computer game. -@item Sega FILM/CPK @tab @tab X -@tab Used in many Sega Saturn console games. -@item Westwood Studios VQA/AUD @tab @tab X -@tab Multimedia formats used in Westwood Studios games. -@item Id Cinematic (.cin) @tab @tab X -@tab Used in Quake II. -@item FLIC format @tab @tab X -@tab .fli/.flc files -@item Sierra VMD @tab @tab X -@tab Used in Sierra CD-ROM games. -@item Sierra Online @tab @tab X -@tab .sol files used in Sierra Online games. -@item Matroska @tab @tab X -@item Electronic Arts Multimedia @tab @tab X -@tab Used in various EA games; files have extensions like WVE and UV2. -@item Nullsoft Video (NSV) format @tab @tab X -@item ADTS AAC audio @tab X @tab X -@item Creative VOC @tab X @tab X @tab Created for the Sound Blaster Pro. -@item American Laser Games MM @tab @tab X -@tab Multimedia format used in games like Mad Dog McCree -@item AVS @tab @tab X -@tab Multimedia format used by the Creature Shock game. -@item Smacker @tab @tab X -@tab Multimedia format used by many games. -@item GXF @tab X @tab X -@tab General eXchange Format SMPTE 360M, used by Thomson Grass Valley playout servers. -@item CIN @tab @tab X -@tab Multimedia format used by Delphine Software games. -@item MXF @tab @tab X -@tab Material eXchange Format SMPTE 377M, used by D-Cinema, broadcast industry. -@item SEQ @tab @tab X -@tab Tiertex .seq files used in the DOS CDROM version of the game Flashback. -@item DXA @tab @tab X -@tab This format is used in non-Windows version of Feeble Files game and -different game cutscenes repacked for use with ScummVM. -@item THP @tab @tab X -@tab Used on the Nintendo GameCube (video only) -@end multitable - -@code{X} means that encoding (resp. decoding) is supported. - -@section Image Formats - -FFmpeg can read and write images for each frame of a video sequence. The -following image formats are supported: - -@multitable @columnfractions .4 .1 .1 .4 -@item Supported Image Format @tab Encoding @tab Decoding @tab Comments -@item PGM, PPM @tab X @tab X -@item PAM @tab X @tab X @tab PAM is a PNM extension with alpha support. -@item PGMYUV @tab X @tab X @tab PGM with U and V components in YUV 4:2:0 -@item JPEG @tab X @tab X @tab Progressive JPEG is not supported. -@item .Y.U.V @tab X @tab X @tab one raw file per component -@item animated GIF @tab X @tab X @tab Only uncompressed GIFs are generated. -@item PNG @tab X @tab X @tab 2 bit and 4 bit/pixel not supported yet. -@item Targa @tab @tab X @tab Targa (.TGA) image format. -@item TIFF @tab @tab X @tab Only 24 bit/pixel images are supported. -@item SGI @tab X @tab X @tab SGI RGB image format -@end multitable - -@code{X} means that encoding (resp. decoding) is supported. - -@section Video Codecs - -@multitable @columnfractions .4 .1 .1 .4 -@item Supported Codec @tab Encoding @tab Decoding @tab Comments -@item MPEG-1 video @tab X @tab X -@item MPEG-2 video @tab X @tab X -@item MPEG-4 @tab X @tab X -@item MSMPEG4 V1 @tab X @tab X -@item MSMPEG4 V2 @tab X @tab X -@item MSMPEG4 V3 @tab X @tab X -@item WMV7 @tab X @tab X -@item WMV8 @tab X @tab X @tab not completely working -@item WMV9 @tab @tab X @tab not completely working -@item VC1 @tab @tab X -@item H.261 @tab X @tab X -@item H.263(+) @tab X @tab X @tab also known as RealVideo 1.0 -@item H.264 @tab @tab X -@item RealVideo 1.0 @tab X @tab X -@item RealVideo 2.0 @tab X @tab X -@item MJPEG @tab X @tab X -@item lossless MJPEG @tab X @tab X -@item JPEG-LS @tab X @tab X @tab fourcc: MJLS, lossless and near-lossless is supported -@item Apple MJPEG-B @tab @tab X -@item Sunplus MJPEG @tab @tab X @tab fourcc: SP5X -@item DV @tab X @tab X -@item HuffYUV @tab X @tab X -@item FFmpeg Video 1 @tab X @tab X @tab experimental lossless codec (fourcc: FFV1) -@item FFmpeg Snow @tab X @tab X @tab experimental wavelet codec (fourcc: SNOW) -@item Asus v1 @tab X @tab X @tab fourcc: ASV1 -@item Asus v2 @tab X @tab X @tab fourcc: ASV2 -@item Creative YUV @tab @tab X @tab fourcc: CYUV -@item Sorenson Video 1 @tab X @tab X @tab fourcc: SVQ1 -@item Sorenson Video 3 @tab @tab X @tab fourcc: SVQ3 -@item On2 VP3 @tab @tab X @tab still experimental -@item On2 VP5 @tab @tab X @tab fourcc: VP50 -@item On2 VP6 @tab @tab X @tab fourcc: VP60,VP61,VP62 -@item Theora @tab X @tab X @tab still experimental -@item Intel Indeo 3 @tab @tab X -@item FLV @tab X @tab X @tab Sorenson H.263 used in Flash -@item Flash Screen Video @tab X @tab X @tab fourcc: FSV1 -@item ATI VCR1 @tab @tab X @tab fourcc: VCR1 -@item ATI VCR2 @tab @tab X @tab fourcc: VCR2 -@item Cirrus Logic AccuPak @tab @tab X @tab fourcc: CLJR -@item 4X Video @tab @tab X @tab Used in certain computer games. -@item Sony Playstation MDEC @tab @tab X -@item Id RoQ @tab @tab X @tab Used in Quake III, Jedi Knight 2, other computer games. -@item Xan/WC3 @tab @tab X @tab Used in Wing Commander III .MVE files. -@item Interplay Video @tab @tab X @tab Used in Interplay .MVE files. -@item Apple Animation @tab @tab X @tab fourcc: 'rle ' -@item Apple Graphics @tab @tab X @tab fourcc: 'smc ' -@item Apple Video @tab @tab X @tab fourcc: rpza -@item Apple QuickDraw @tab @tab X @tab fourcc: qdrw -@item Cinepak @tab @tab X -@item Microsoft RLE @tab @tab X -@item Microsoft Video-1 @tab @tab X -@item Westwood VQA @tab @tab X -@item Id Cinematic Video @tab @tab X @tab Used in Quake II. -@item Planar RGB @tab @tab X @tab fourcc: 8BPS -@item FLIC video @tab @tab X -@item Duck TrueMotion v1 @tab @tab X @tab fourcc: DUCK -@item Duck TrueMotion v2 @tab @tab X @tab fourcc: TM20 -@item VMD Video @tab @tab X @tab Used in Sierra VMD files. -@item MSZH @tab @tab X @tab Part of LCL -@item ZLIB @tab X @tab X @tab Part of LCL, encoder experimental -@item TechSmith Camtasia @tab @tab X @tab fourcc: TSCC -@item IBM Ultimotion @tab @tab X @tab fourcc: ULTI -@item Miro VideoXL @tab @tab X @tab fourcc: VIXL -@item QPEG @tab @tab X @tab fourccs: QPEG, Q1.0, Q1.1 -@item LOCO @tab @tab X @tab -@item Winnov WNV1 @tab @tab X @tab -@item Autodesk Animator Studio Codec @tab @tab X @tab fourcc: AASC -@item Fraps FPS1 @tab @tab X @tab -@item CamStudio @tab @tab X @tab fourcc: CSCD -@item American Laser Games Video @tab @tab X @tab Used in games like Mad Dog McCree -@item ZMBV @tab X @tab X @tab Encoder works only on PAL8 -@item AVS Video @tab @tab X @tab Video encoding used by the Creature Shock game. -@item Smacker Video @tab @tab X @tab Video encoding used in Smacker. -@item RTjpeg @tab @tab X @tab Video encoding used in NuppelVideo files. -@item KMVC @tab @tab X @tab Codec used in Worms games. -@item VMware Video @tab @tab X @tab Codec used in videos captured by VMware. -@item Cin Video @tab @tab X @tab Codec used in Delphine Software games. -@item Tiertex Seq Video @tab @tab X @tab Codec used in DOS CDROM FlashBack game. -@item DXA Video @tab @tab X @tab Codec originally used in Feeble Files game. -@item AVID DNxHD @tab @tab X @tab aka SMPTE VC3 -@end multitable - -@code{X} means that encoding (resp. decoding) is supported. - -@section Audio Codecs - -@multitable @columnfractions .4 .1 .1 .1 .7 -@item Supported Codec @tab Encoding @tab Decoding @tab Comments -@item MPEG audio layer 2 @tab IX @tab IX -@item MPEG audio layer 1/3 @tab IX @tab IX -@tab MP3 encoding is supported through the external library LAME. -@item AC3 @tab IX @tab IX -@tab liba52 is used internally for decoding. -@item Vorbis @tab X @tab X -@item WMA V1/V2 @tab X @tab X -@item AAC @tab X @tab X -@tab Supported through the external library libfaac/libfaad. -@item Microsoft ADPCM @tab X @tab X -@item MS IMA ADPCM @tab X @tab X -@item QT IMA ADPCM @tab @tab X -@item 4X IMA ADPCM @tab @tab X -@item G.726 ADPCM @tab X @tab X -@item Duck DK3 IMA ADPCM @tab @tab X -@tab Used in some Sega Saturn console games. -@item Duck DK4 IMA ADPCM @tab @tab X -@tab Used in some Sega Saturn console games. -@item Westwood Studios IMA ADPCM @tab @tab X -@tab Used in Westwood Studios games like Command and Conquer. -@item SMJPEG IMA ADPCM @tab @tab X -@tab Used in certain Loki game ports. -@item CD-ROM XA ADPCM @tab @tab X -@item CRI ADX ADPCM @tab X @tab X -@tab Used in Sega Dreamcast games. -@item Electronic Arts ADPCM @tab @tab X -@tab Used in various EA titles. -@item Creative ADPCM @tab @tab X -@tab 16 -> 4, 8 -> 4, 8 -> 3, 8 -> 2 -@item RA144 @tab @tab X -@tab Real 14400 bit/s codec -@item RA288 @tab @tab X -@tab Real 28800 bit/s codec -@item RADnet @tab X @tab IX -@tab Real low bitrate AC3 codec, liba52 is used for decoding. -@item AMR-NB @tab X @tab X -@tab Supported through an external library. -@item AMR-WB @tab X @tab X -@tab Supported through an external library. -@item DV audio @tab @tab X -@item Id RoQ DPCM @tab @tab X -@tab Used in Quake III, Jedi Knight 2, other computer games. -@item Interplay MVE DPCM @tab @tab X -@tab Used in various Interplay computer games. -@item Xan DPCM @tab @tab X -@tab Used in Origin's Wing Commander IV AVI files. -@item Sierra Online DPCM @tab @tab X -@tab Used in Sierra Online game audio files. -@item Apple MACE 3 @tab @tab X -@item Apple MACE 6 @tab @tab X -@item FLAC lossless audio @tab @tab X -@item Shorten lossless audio @tab @tab X -@item Apple lossless audio @tab @tab X -@tab QuickTime fourcc 'alac' -@item FFmpeg Sonic @tab X @tab X -@tab experimental lossy/lossless codec -@item Qdesign QDM2 @tab @tab X -@tab there are still some distortions -@item Real COOK @tab @tab X -@tab All versions except 5.1 are supported -@item DSP Group TrueSpeech @tab @tab X -@item True Audio (TTA) @tab @tab X -@item Smacker Audio @tab @tab X -@item WavPack Audio @tab @tab X -@item Cin Audio @tab @tab X -@tab Codec used in Delphine Software games. -@item Intel Music Coder @tab @tab X -@item Musepack @tab @tab X -@tab Only SV7 is supported -@item DT$ Coherent Audio @tab @tab X -@end multitable - -@code{X} means that encoding (resp. decoding) is supported. - -@code{I} means that an integer-only version is available, too (ensures high -performance on systems without hardware floating point support). - -@chapter Platform Specific information - -@section BSD - -BSD make will not build FFmpeg, you need to install and use GNU Make -(@file{gmake}). - -@section Windows - -To get help and instructions for using FFmpeg under Windows, check out -the FFmpeg Windows Help Forum at -@url{http://arrozcru.no-ip.org/ffmpeg/}. - -@subsection Native Windows compilation - -@itemize -@item Install the current versions of MSYS and MinGW from -@url{http://www.mingw.org/}. You can find detailed installation -instructions in the download section and the FAQ. - -NOTE: Use at least bash 3.1. Older versions are known to be failing on the -configure script. - -@item If you want to test the FFplay, also download -the MinGW development library of SDL 1.2.x -(@file{SDL-devel-1.2.x-mingw32.tar.gz}) from -@url{http://www.libsdl.org}. Unpack it in a temporary directory, and -unpack the archive @file{i386-mingw32msvc.tar.gz} in the MinGW tool -directory. Edit the @file{sdl-config} script so that it gives the -correct SDL directory when invoked. - -@item Extract the current version of FFmpeg. - -@item Start the MSYS shell (file @file{msys.bat}). - -@item Change to the FFmpeg directory and follow - the instructions of how to compile FFmpeg (file -@file{INSTALL}). Usually, launching @file{./configure} and @file{make} -suffices. If you have problems using SDL, verify that -@file{sdl-config} can be launched from the MSYS command line. - -@item You can install FFmpeg in @file{Program Files/FFmpeg} by typing -@file{make install}. Do not forget to copy @file{SDL.dll} to the place -you launch @file{ffplay} from. - -@end itemize - -Notes: -@itemize - -@item The target @file{make wininstaller} can be used to create a -Nullsoft based Windows installer for FFmpeg and FFplay. @file{SDL.dll} -must be copied to the FFmpeg directory in order to build the -installer. - -@item By using @code{./configure --enable-shared} when configuring FFmpeg, -you can build @file{avcodec.dll} and @file{avformat.dll}. With -@code{make install} you install the FFmpeg DLLs and the associated -headers in @file{Program Files/FFmpeg}. - -@item Visual C++ compatibility: If you used @code{./configure --enable-shared} -when configuring FFmpeg, FFmpeg tries to use the Microsoft Visual -C++ @code{lib} tool to build @code{avcodec.lib} and -@code{avformat.lib}. With these libraries you can link your Visual C++ -code directly with the FFmpeg DLLs (see below). - -@end itemize - -@subsection Visual C++ compatibility - -FFmpeg will not compile under Visual C++ -- and it has too many -dependencies on the GCC compiler to make a port viable. However, -if you want to use the FFmpeg libraries in your own applications, -you can still compile those applications using Visual C++. An -important restriction to this is that you have to use the -dynamically linked versions of the FFmpeg libraries (i.e. the -DLLs), and you have to make sure that Visual-C++-compatible -import libraries are created during the FFmpeg build process. - -This description of how to use the FFmpeg libraries with Visual C++ is -based on Visual C++ 2005 Express Edition Beta 2. If you have a different -version, you might have to modify the procedures slightly. - -Here are the step-by-step instructions for building the FFmpeg libraries -so they can be used with Visual C++: - -@enumerate - -@item Install Visual C++ (if you have not done so already). - -@item Install MinGW and MSYS as described above. - -@item Add a call to @file{vcvars32.bat} (which sets up the environment -variables for the Visual C++ tools) as the first line of -@file{msys.bat}. The standard location for @file{vcvars32.bat} is -@file{C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat}, -and the standard location for @file{msys.bat} is -@file{C:\msys\1.0\msys.bat}. If this corresponds to your setup, add the -following line as the first line of @file{msys.bat}: - -@code{call "C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat"} - -@item Start the MSYS shell (file @file{msys.bat}) and type @code{link.exe}. -If you get a help message with the command line options of @code{link.exe}, -this means your environment variables are set up correctly, the -Microsoft linker is on the path and will be used by FFmpeg to -create Visual-C++-compatible import libraries. - -@item Extract the current version of FFmpeg and change to the FFmpeg directory. - -@item Type the command -@code{./configure --enable-shared --disable-static --enable-memalign-hack} -to configure and, if that did not produce any errors, -type @code{make} to build FFmpeg. - -@item The subdirectories @file{libavformat}, @file{libavcodec}, and -@file{libavutil} should now contain the files @file{avformat.dll}, -@file{avformat.lib}, @file{avcodec.dll}, @file{avcodec.lib}, -@file{avutil.dll}, and @file{avutil.lib}, respectively. Copy the three -DLLs to your System32 directory (typically @file{C:\Windows\System32}). - -@end enumerate - -And here is how to use these libraries with Visual C++: - -@enumerate - -@item Create a new console application ("File / New / Project") and then -select "Win32 Console Application". On the appropriate page of the -Application Wizard, uncheck the "Precompiled headers" option. - -@item Write the source code for your application, or, for testing, just -copy the code from an existing sample application into the source file -that Visual C++ has already created for you. (Note that your source -filehas to have a @code{.cpp} extension; otherwise, Visual C++ will not -compile the FFmpeg headers correctly because in C mode, it does not -recognize the @code{inline} keyword.) For example, you can copy -@file{output_example.c} from the FFmpeg distribution (but you will -have to make minor modifications so the code will compile under -C++, see below). - -@item Open the "Project / Properties" dialog box. In the "Configuration" -combo box, select "All Configurations" so that the changes you make will -affect both debug and release builds. In the tree view on the left hand -side, select "C/C++ / General", then edit the "Additional Include -Directories" setting to contain the complete paths to the -@file{libavformat}, @file{libavcodec}, and @file{libavutil} -subdirectories of your FFmpeg directory. Note that the directories have -to be separated using semicolons. Now select "Linker / General" from the -tree view and edit the "Additional Library Directories" setting to -contain the same three directories. - -@item Still in the "Project / Properties" dialog box, select "Linker / Input" -from the tree view, then add the files @file{avformat.lib}, -@file{avcodec.lib}, and @file{avutil.lib} to the end of the "Additional -Dependencies". Note that the names of the libraries have to be separated -using spaces. - -@item Now, select "C/C++ / Code Generation" from the tree view. Select -"Debug" in the "Configuration" combo box. Make sure that "Runtime -Library" is set to "Multi-threaded Debug DLL". Then, select "Release" in -the "Configuration" combo box and make sure that "Runtime Library" is -set to "Multi-threaded DLL". - -@item Click "OK" to close the "Project / Properties" dialog box and build -the application. Hopefully, it should compile and run cleanly. If you -used @file{output_example.c} as your sample application, you will get a -few compiler errors, but they are easy to fix. The first type of error -occurs because Visual C++ does not allow an @code{int} to be converted to -an @code{enum} without a cast. To solve the problem, insert the required -casts (this error occurs once for a @code{CodecID} and once for a -@code{CodecType}). The second type of error occurs because C++ requires -the return value of @code{malloc} to be cast to the exact type of the -pointer it is being assigned to. Visual C++ will complain that, for -example, @code{(void *)} is being assigned to @code{(uint8_t *)} without -an explicit cast. So insert an explicit cast in these places to silence -the compiler. The third type of error occurs because the @code{snprintf} -library function is called @code{_snprintf} under Visual C++. So just -add an underscore to fix the problem. With these changes, -@file{output_example.c} should compile under Visual C++, and the -resulting executable should produce valid video files. - -@end enumerate - -@subsection Cross compilation for Windows with Linux - -You must use the MinGW cross compilation tools available at -@url{http://www.mingw.org/}. - -Then configure FFmpeg with the following options: -@example -./configure --target-os=mingw32 --cross-prefix=i386-mingw32msvc- -@end example -(you can change the cross-prefix according to the prefix chosen for the -MinGW tools). - -Then you can easily test FFmpeg with Wine -(@url{http://www.winehq.com/}). - -@subsection Compilation under Cygwin - -Cygwin works very much like Unix. - -Just install your Cygwin with all the "Base" packages, plus the -following "Devel" ones: -@example -binutils, gcc-core, make, subversion -@end example - -Do not install binutils-20060709-1 (they are buggy on shared builds); -use binutils-20050610-1 instead. - -Then run - -@example -./configure --enable-static --disable-shared -@end example - -to make a static build or - -@example -./configure --enable-shared --disable-static -@end example - -to build shared libraries. - -If you want to build FFmpeg with additional libraries, download Cygwin -"Devel" packages for Ogg and Vorbis from any Cygwin packages repository -and/or SDL, xvid, faac, faad2 packages from Cygwin Ports, -(@url{http://cygwinports.dotsrc.org/}). - -@subsection Crosscompilation for Windows under Cygwin - -With Cygwin you can create Windows binaries that do not need the cygwin1.dll. - -Just install your Cygwin as explained before, plus these additional -"Devel" packages: -@example -gcc-mingw-core, mingw-runtime, mingw-zlib -@end example - -and add some special flags to your configure invocation. - -For a static build run -@example -./configure --target-os=mingw32 --enable-memalign-hack --enable-static --disable-shared --extra-cflags=-mno-cygwin --extra-libs=-mno-cygwin -@end example - -and for a build with shared libraries -@example -./configure --target-os=mingw32 --enable-memalign-hack --enable-shared --disable-static --extra-cflags=-mno-cygwin --extra-libs=-mno-cygwin -@end example - -@section BeOS - -The configure script should guess the configuration itself. -Networking support is currently not finished. -errno issues fixed by Andrew Bachmann. - -Old stuff: - -François Revol - revol at free dot fr - April 2002 - -The configure script should guess the configuration itself, -however I still did not test building on the net_server version of BeOS. - -FFserver is broken (needs poll() implementation). - -There are still issues with errno codes, which are negative in BeOS, and -that FFmpeg negates when returning. This ends up turning errors into -valid results, then crashes. -(To be fixed) - -@chapter Developers Guide - -@section API -@itemize @bullet -@item libavcodec is the library containing the codecs (both encoding and -decoding). Look at @file{libavcodec/apiexample.c} to see how to use it. - -@item libavformat is the library containing the file format handling (mux and -demux code for several formats). Look at @file{ffplay.c} to use it in a -player. See @file{output_example.c} to use it to generate audio or video -streams. - -@end itemize - -@section Integrating libavcodec or libavformat in your program - -You can integrate all the source code of the libraries to link them -statically to avoid any version problem. All you need is to provide a -'config.mak' and a 'config.h' in the parent directory. See the defines -generated by ./configure to understand what is needed. - -You can use libavcodec or libavformat in your commercial program, but -@emph{any patch you make must be published}. The best way to proceed is -to send your patches to the FFmpeg mailing list. - -@node Coding Rules -@section Coding Rules - -FFmpeg is programmed in the ISO C90 language with a few additional -features from ISO C99, namely: -@itemize @bullet -@item -the @samp{inline} keyword; -@item -@samp{//} comments; -@item -designated struct initializers (@samp{struct s x = @{ .i = 17 @};}) -@item -compound literals (@samp{x = (struct s) @{ 17, 23 @};}) -@end itemize - -These features are supported by all compilers we care about, so we will not -accept patches to remove their use unless they absolutely do not impair -clarity and performance. - -All code must compile with GCC 2.95 and GCC 3.3. Currently, FFmpeg also -compiles with several other compilers, such as the Compaq ccc compiler -or Sun Studio 9, and we would like to keep it that way unless it would -be exceedingly involved. To ensure compatibility, please do not use any -additional C99 features or GCC extensions. Especially watch out for: -@itemize @bullet -@item -mixing statements and declarations; -@item -@samp{long long} (use @samp{int64_t} instead); -@item -@samp{__attribute__} not protected by @samp{#ifdef __GNUC__} or similar; -@item -GCC statement expressions (@samp{(x = (@{ int y = 4; y; @})}). -@end itemize - -Indent size is 4. -The presentation is the one specified by 'indent -i4 -kr -nut'. -The TAB character is forbidden outside of Makefiles as is any -form of trailing whitespace. Commits containing either will be -rejected by the Subversion repository. - -Main priority in FFmpeg is simplicity and small code size (=less -bugs). - -Comments: Use the JavaDoc/Doxygen -format (see examples below) so that code documentation -can be generated automatically. All nontrivial functions should have a comment -above them explaining what the function does, even if it is just one sentence. -All structures and their member variables should be documented, too. -@example -/** - * @@file mpeg.c - * MPEG codec. - * @@author ... - */ - -/** - * Summary sentence. - * more text ... - * ... - */ -typedef struct Foobar@{ - int var1; /**< var1 description */ - int var2; ///< var2 description - /** var3 description */ - int var3; -@} Foobar; - -/** - * Summary sentence. - * more text ... - * ... - * @@param my_parameter description of my_parameter - * @@return return value description - */ -int myfunc(int my_parameter) -... -@end example - -fprintf and printf are forbidden in libavformat and libavcodec, -please use av_log() instead. - -@section Development Policy - -@enumerate -@item - You must not commit code which breaks FFmpeg! (Meaning unfinished but - enabled code which breaks compilation or compiles but does not work or - breaks the regression tests) - You can commit unfinished stuff (for testing etc), but it must be disabled - (#ifdef etc) by default so it does not interfere with other developers' - work. -@item - You do not have to over-test things. If it works for you, and you think it - should work for others, then commit. If your code has problems - (portability, triggers compiler bugs, unusual environment etc) they will be - reported and eventually fixed. -@item - Do not commit unrelated changes together, split them into self-contained - pieces. Also do not forget that if part B depends on part A, but A does not - depend on B, then A can and should be committed first and separate from B. - Keeping changes well split into self-contained parts makes reviewing and - understanding them on the commit log mailing list easier. This also helps - in case of debugging later on. - Also if you have doubts about splitting or not splitting, do not hesitate to - ask/disscuss it on the developer mailing list. -@item - Do not change behavior of the program (renaming options etc) without - first discussing it on the ffmpeg-devel mailing list. Do not remove - functionality from the code. Just improve! - - Note: Redundant code can be removed. -@item - Do not commit changes to the build system (Makefiles, configure script) - which change behavior, defaults etc, without asking first. The same - applies to compiler warning fixes, trivial looking fixes and to code - maintained by other developers. We usually have a reason for doing things - the way we do. Send your changes as patches to the ffmpeg-devel mailing - list, and if the code maintainers say OK, you may commit. This does not - apply to files you wrote and/or maintain. -@item - We refuse source indentation and other cosmetic changes if they are mixed - with functional changes, such commits will be rejected and removed. Every - developer has his own indentation style, you should not change it. Of course - if you (re)write something, you can use your own style, even though we would - prefer if the indentation throughout FFmpeg was consistent (Many projects - force a given indentation style - we do not.). If you really need to make - indentation changes (try to avoid this), separate them strictly from real - changes. - - NOTE: If you had to put if()@{ .. @} over a large (> 5 lines) chunk of code, - then either do NOT change the indentation of the inner part within (do not - move it to the right)! or do so in a separate commit -@item - Always fill out the commit log message. Describe in a few lines what you - changed and why. You can refer to mailing list postings if you fix a - particular bug. Comments such as "fixed!" or "Changed it." are unacceptable. -@item - If you apply a patch by someone else, include the name and email address in - the log message. Since the ffmpeg-cvslog mailing list is publicly - archived you should add some SPAM protection to the email address. Send an - answer to ffmpeg-devel (or wherever you got the patch from) saying that - you applied the patch. -@item - Do NOT commit to code actively maintained by others without permission. - Send a patch to ffmpeg-devel instead. If noone answers within a reasonable - timeframe (12h for build failures and security fixes, 3 days small changes, - 1 week for big patches) then commit your patch if you think it is OK. - Also note, the maintainer can simply ask for more time to review! -@item - Subscribe to the ffmpeg-cvslog mailing list. The diffs of all commits - are sent there and reviewed by all the other developers. Bugs and possible - improvements or general questions regarding commits are discussed there. We - expect you to react if problems with your code are uncovered. -@item - Update the documentation if you change behavior or add features. If you are - unsure how best to do this, send a patch to ffmpeg-devel, the documentation - maintainer(s) will review and commit your stuff. -@item - Try to keep important discussions and requests (also) on the public - developer mailing list, so that all developers can benefit from them. -@item - Never write to unallocated memory, never write over the end of arrays, - always check values read from some untrusted source before using them - as array index or other risky things. -@item - Remember to check if you need to bump versions for the specific libav - parts (libavutil, libavcodec, libavformat) you are changing. You need - to change the version integer and the version string. - Incrementing the first component means no backward compatibility to - previous versions (e.g. removal of a function from the public API). - Incrementing the second component means backward compatible change - (e.g. addition of a function to the public API). - Incrementing the third component means a noteworthy binary compatible - change (e.g. encoder bug fix that matters for the decoder). -@item - If you add a new codec, remember to update the changelog, add it to - the supported codecs table in the documentation and bump the second - component of the @file{libavcodec} version number appropriately. If - it has a fourcc, add it to @file{libavformat/avienc.c}, even if it - is only a decoder. -@item - Do not change code to hide warnings without ensuring that the underlying - logic is correct and thus the warning was inappropriate. -@end enumerate - -We think our rules are not too hard. If you have comments, contact us. - -Note, these rules are mostly borrowed from the MPlayer project. - -@section Submitting patches - -First, (@pxref{Coding Rules}) above if you did not yet. - -When you submit your patch, try to send a unified diff (diff '-up' -option). I cannot read other diffs :-) - -Also please do not submit patches which contain several unrelated changes. -Split them into individual self-contained patches; this makes reviewing -them much easier. - -Run the regression tests before submitting a patch so that you can -verify that there are no big problems. - -Patches should be posted as base64 encoded attachments (or any other -encoding which ensures that the patch will not be trashed during -transmission) to the ffmpeg-devel mailing list, see -@url{http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel} - -It also helps quite a bit if you tell us what the patch does (for example -'replaces lrint by lrintf'), and why (for example '*BSD isn't C99 compliant -and has no lrint()') - -@section Patch review process - -All patches posted to ffmpeg-devel will be reviewed, unless they contain a -clear note that the patch is not for SVN. -Reviews and comments will be posted as replies to the patch on the -mailing list. The patch submitter then has to take care of every comment, -that can be by resubmitting a changed patch or by disscussion. Resubmitted -patches will themselves be reviewed like any other patch. If at some point -a patch passes review with no comments then it is approved, that can for -simple and small patches happen immediately while large patches will generally -have to be changed and reviewed many times before they are approved. -After a patch is approved it will be committed to the repository. - -We will review all submitted patches, but sometimes we are quite busy so -especially for large patches this can take several weeks. - -When resubmitting patches, please do not make any significant changes -not related to the comments received during review. Such patches will -be rejected. Instead, submit significant changes or new features as -separate patches. - -@section Regression tests - -Before submitting a patch (or committing to the repository), you should at least -test that you did not break anything. - -The regression tests build a synthetic video stream and a synthetic -audio stream. These are then encoded and decoded with all codecs or -formats. The CRC (or MD5) of each generated file is recorded in a -result file. A 'diff' is launched to compare the reference results and -the result file. - -The regression tests then go on to test the FFserver code with a -limited set of streams. It is important that this step runs correctly -as well. - -Run 'make test' to test all the codecs and formats. - -Run 'make fulltest' to test all the codecs, formats and FFserver. - -[Of course, some patches may change the results of the regression tests. In -this case, the reference results of the regression tests shall be modified -accordingly]. - @bye diff --git a/contrib/ffmpeg/doc/ffserver-doc.texi b/contrib/ffmpeg/doc/ffserver-doc.texi index ed67bb6c0..9b0373360 100644 --- a/contrib/ffmpeg/doc/ffserver-doc.texi +++ b/contrib/ffmpeg/doc/ffserver-doc.texi @@ -49,8 +49,8 @@ I understand that FreeBSD systems work just fine as well. @section How do I make it work? First, build the kit. It *really* helps to have installed LAME first. Then when -you run the ffserver ./configure, make sure that you have the --enable-mp3lame -flag turned on. +you run the ffserver ./configure, make sure that you have the +@code{--enable-libmp3lame} flag turned on. LAME is important as it allows for streaming audio to Windows Media Player. Don't ask why the other audio types do not work. diff --git a/contrib/ffmpeg/doc/ffserver.conf b/contrib/ffmpeg/doc/ffserver.conf index a3b3ff412..f7db66ed2 100644 --- a/contrib/ffmpeg/doc/ffserver.conf +++ b/contrib/ffmpeg/doc/ffserver.conf @@ -109,7 +109,10 @@ VideoBufferSize 40 VideoFrameRate 3 # Size of the video frame: WxH (default: 160x128) -# The following abbreviations are defined: sqcif, qcif, cif, 4cif +# The following abbreviations are defined: sqcif, qcif, cif, 4cif, qqvga, +# qvga, vga, svga, xga, uxga, qxga, sxga, qsxga, hsxga, wvga, wxga, wsxga, +# wuxga, woxga, wqsxga, wquxga, whsxga, whuxga, cga, ega, hd480, hd720, +# hd1080 VideoSize 160x128 # Transmit only intra frames (useful for low bitrates, but kills frame rate). diff --git a/contrib/ffmpeg/doc/general.texi b/contrib/ffmpeg/doc/general.texi new file mode 100644 index 000000000..8fc27d603 --- /dev/null +++ b/contrib/ffmpeg/doc/general.texi @@ -0,0 +1,985 @@ +\input texinfo @c -*- texinfo -*- + +@settitle General Documentation +@titlepage +@sp 7 +@center @titlefont{General Documentation} +@sp 3 +@end titlepage + + +@chapter external libraries + +FFmpeg can be hooked up with a number of external libraries to add support +for more formats. None of them are used by default, their use has to be +explicitly requested by passing the appropriate flags to @file{./configure}. + +@section AMR + +AMR comes in two different flavors, wideband and narrowband. FFmpeg can make +use of the AMR wideband (floating-point mode) and the AMR narrowband +(floating-point mode) reference decoders and encoders. + +Go to @url{http://www.penguin.cz/~utx/amr} and follow the instructions for +installing the libraries. Then pass @code{--enable-libamr-nb} and/or +@code{--enable-libamr-wb} to configure to enable the libraries. + +Note that libamr is copyrighted without any sort of license grant. This means +that you can use it if you legally obtained it but you are not allowed to +redistribute it in any way. @strong{Any FFmpeg binaries with libamr support +you create are non-free and unredistributable!} + + +@chapter Supported File Formats and Codecs + +You can use the @code{-formats} option to have an exhaustive list. + +@section File Formats + +FFmpeg supports the following file formats through the @code{libavformat} +library: + +@multitable @columnfractions .4 .1 .1 .4 +@item Supported File Format @tab Encoding @tab Decoding @tab Comments +@item MPEG audio @tab X @tab X +@item MPEG-1 systems @tab X @tab X +@tab muxed audio and video +@item MPEG-2 PS @tab X @tab X +@tab also known as @code{VOB} file +@item MPEG-2 TS @tab @tab X +@tab also known as DVB Transport Stream +@item ASF@tab X @tab X +@item AVI@tab X @tab X +@item WAV@tab X @tab X +@item Macromedia Flash@tab X @tab X +@item AVM2 (Flash 9) @tab X @tab X +@tab Only embedded audio is decoded. +@item FLV @tab X @tab X +@tab Macromedia Flash video files +@item Real Audio and Video @tab X @tab X +@item Raw AC3 @tab X @tab X +@item Raw MJPEG @tab X @tab X +@item Raw MPEG video @tab X @tab X +@item Raw PCM8/16 bits, mulaw/Alaw@tab X @tab X +@item Raw CRI ADX audio @tab X @tab X +@item Raw Shorten audio @tab @tab X +@item SUN AU format @tab X @tab X +@item NUT @tab X @tab X @tab NUT Open Container Format +@item QuickTime @tab X @tab X +@item MPEG-4 @tab X @tab X +@tab MPEG-4 is a variant of QuickTime. +@item Raw MPEG4 video @tab X @tab X +@item DV @tab X @tab X +@item 4xm @tab @tab X +@tab 4X Technologies format, used in some games. +@item Playstation STR @tab @tab X +@item Id RoQ @tab X @tab X +@tab Used in Quake III, Jedi Knight 2, other computer games. +@item Interplay MVE @tab @tab X +@tab Format used in various Interplay computer games. +@item WC3 Movie @tab @tab X +@tab Multimedia format used in Origin's Wing Commander III computer game. +@item Sega FILM/CPK @tab @tab X +@tab Used in many Sega Saturn console games. +@item Westwood Studios VQA/AUD @tab @tab X +@tab Multimedia formats used in Westwood Studios games. +@item Id Cinematic (.cin) @tab @tab X +@tab Used in Quake II. +@item FLIC format @tab @tab X +@tab .fli/.flc files +@item Sierra VMD @tab @tab X +@tab Used in Sierra CD-ROM games. +@item Sierra Online @tab @tab X +@tab .sol files used in Sierra Online games. +@item Matroska @tab X @tab X +@item Electronic Arts Multimedia @tab @tab X +@tab Used in various EA games; files have extensions like WVE and UV2. +@item Nullsoft Video (NSV) format @tab @tab X +@item ADTS AAC audio @tab X @tab X +@item Creative VOC @tab X @tab X @tab Created for the Sound Blaster Pro. +@item American Laser Games MM @tab @tab X +@tab Multimedia format used in games like Mad Dog McCree +@item AVS @tab @tab X +@tab Multimedia format used by the Creature Shock game. +@item Smacker @tab @tab X +@tab Multimedia format used by many games. +@item GXF @tab X @tab X +@tab General eXchange Format SMPTE 360M, used by Thomson Grass Valley playout servers. +@item CIN @tab @tab X +@tab Multimedia format used by Delphine Software games. +@item MXF @tab @tab X +@tab Material eXchange Format SMPTE 377M, used by D-Cinema, broadcast industry. +@item SEQ @tab @tab X +@tab Tiertex .seq files used in the DOS CDROM version of the game Flashback. +@item DXA @tab @tab X +@tab This format is used in non-Windows version of Feeble Files game and +different game cutscenes repacked for use with ScummVM. +@item THP @tab @tab X +@tab Used on the Nintendo GameCube. +@item C93 @tab @tab X +@tab Used in the game Cyberia from Interplay. +@item Bethsoft VID @tab @tab X +@tab Used in some games from Bethesda Softworks. +@item CRYO APC @tab @tab X +@tab Audio format used in some games by CRYO Interactive Entertainment. +@item Monkey's Audio @tab @tab X +@item SIFF @tab @tab X +@tab Audio and video format used in some games by Beam Software +@end multitable + +@code{X} means that encoding (resp. decoding) is supported. + +@section Image Formats + +FFmpeg can read and write images for each frame of a video sequence. The +following image formats are supported: + +@multitable @columnfractions .4 .1 .1 .4 +@item Supported Image Format @tab Encoding @tab Decoding @tab Comments +@item PGM, PPM @tab X @tab X +@item PAM @tab X @tab X @tab PAM is a PNM extension with alpha support. +@item PGMYUV @tab X @tab X @tab PGM with U and V components in YUV 4:2:0 +@item JPEG @tab X @tab X @tab Progressive JPEG is not supported. +@item .Y.U.V @tab X @tab X @tab one raw file per component +@item animated GIF @tab X @tab X @tab Only uncompressed GIFs are generated. +@item PNG @tab X @tab X @tab 2 bit and 4 bit/pixel not supported yet. +@item Targa @tab @tab X @tab Targa (.TGA) image format. +@item TIFF @tab X @tab X @tab YUV, JPEG and some extension is not supported yet. +@item SGI @tab X @tab X @tab SGI RGB image format +@item PTX @tab @tab X @tab V.Flash PTX format +@end multitable + +@code{X} means that encoding (resp. decoding) is supported. + +@section Video Codecs + +@multitable @columnfractions .4 .1 .1 .4 +@item Supported Codec @tab Encoding @tab Decoding @tab Comments +@item MPEG-1 video @tab X @tab X +@item MPEG-2 video @tab X @tab X +@item MPEG-4 @tab X @tab X +@item MSMPEG4 V1 @tab X @tab X +@item MSMPEG4 V2 @tab X @tab X +@item MSMPEG4 V3 @tab X @tab X +@item WMV7 @tab X @tab X +@item WMV8 @tab X @tab X @tab not completely working +@item WMV9 @tab @tab X @tab not completely working +@item VC1 @tab @tab X +@item H.261 @tab X @tab X +@item H.263(+) @tab X @tab X @tab also known as RealVideo 1.0 +@item H.264 @tab @tab X +@item RealVideo 1.0 @tab X @tab X +@item RealVideo 2.0 @tab X @tab X +@item MJPEG @tab X @tab X +@item lossless MJPEG @tab X @tab X +@item JPEG-LS @tab X @tab X @tab fourcc: MJLS, lossless and near-lossless is supported +@item Apple MJPEG-B @tab @tab X +@item Sunplus MJPEG @tab @tab X @tab fourcc: SP5X +@item DV @tab X @tab X +@item HuffYUV @tab X @tab X +@item FFmpeg Video 1 @tab X @tab X @tab experimental lossless codec (fourcc: FFV1) +@item FFmpeg Snow @tab X @tab X @tab experimental wavelet codec (fourcc: SNOW) +@item Asus v1 @tab X @tab X @tab fourcc: ASV1 +@item Asus v2 @tab X @tab X @tab fourcc: ASV2 +@item Creative YUV @tab @tab X @tab fourcc: CYUV +@item Sorenson Video 1 @tab X @tab X @tab fourcc: SVQ1 +@item Sorenson Video 3 @tab @tab X @tab fourcc: SVQ3 +@item On2 VP3 @tab @tab X @tab still experimental +@item On2 VP5 @tab @tab X @tab fourcc: VP50 +@item On2 VP6 @tab @tab X @tab fourcc: VP60,VP61,VP62 +@item Theora @tab X @tab X @tab still experimental +@item Intel Indeo 3 @tab @tab X +@item FLV @tab X @tab X @tab Sorenson H.263 used in Flash +@item Flash Screen Video @tab X @tab X @tab fourcc: FSV1 +@item ATI VCR1 @tab @tab X @tab fourcc: VCR1 +@item ATI VCR2 @tab @tab X @tab fourcc: VCR2 +@item Cirrus Logic AccuPak @tab @tab X @tab fourcc: CLJR +@item 4X Video @tab @tab X @tab Used in certain computer games. +@item Sony Playstation MDEC @tab @tab X +@item Id RoQ @tab X @tab X @tab Used in Quake III, Jedi Knight 2, other computer games. +@item Xan/WC3 @tab @tab X @tab Used in Wing Commander III .MVE files. +@item Interplay Video @tab @tab X @tab Used in Interplay .MVE files. +@item Apple Animation @tab X @tab X @tab fourcc: 'rle ' +@item Apple Graphics @tab @tab X @tab fourcc: 'smc ' +@item Apple Video @tab @tab X @tab fourcc: rpza +@item Apple QuickDraw @tab @tab X @tab fourcc: qdrw +@item Cinepak @tab @tab X +@item Microsoft RLE @tab @tab X +@item Microsoft Video-1 @tab @tab X +@item Westwood VQA @tab @tab X +@item Id Cinematic Video @tab @tab X @tab Used in Quake II. +@item Planar RGB @tab @tab X @tab fourcc: 8BPS +@item FLIC video @tab @tab X +@item Duck TrueMotion v1 @tab @tab X @tab fourcc: DUCK +@item Duck TrueMotion v2 @tab @tab X @tab fourcc: TM20 +@item VMD Video @tab @tab X @tab Used in Sierra VMD files. +@item MSZH @tab @tab X @tab Part of LCL +@item ZLIB @tab X @tab X @tab Part of LCL, encoder experimental +@item TechSmith Camtasia @tab @tab X @tab fourcc: TSCC +@item IBM Ultimotion @tab @tab X @tab fourcc: ULTI +@item Miro VideoXL @tab @tab X @tab fourcc: VIXL +@item QPEG @tab @tab X @tab fourccs: QPEG, Q1.0, Q1.1 +@item LOCO @tab @tab X @tab +@item Winnov WNV1 @tab @tab X @tab +@item Autodesk Animator Studio Codec @tab @tab X @tab fourcc: AASC +@item Fraps FPS1 @tab @tab X @tab +@item CamStudio @tab @tab X @tab fourcc: CSCD +@item American Laser Games Video @tab @tab X @tab Used in games like Mad Dog McCree +@item ZMBV @tab X @tab X @tab Encoder works only on PAL8 +@item AVS Video @tab @tab X @tab Video encoding used by the Creature Shock game. +@item Smacker Video @tab @tab X @tab Video encoding used in Smacker. +@item RTjpeg @tab @tab X @tab Video encoding used in NuppelVideo files. +@item KMVC @tab @tab X @tab Codec used in Worms games. +@item VMware Video @tab @tab X @tab Codec used in videos captured by VMware. +@item Cin Video @tab @tab X @tab Codec used in Delphine Software games. +@item Tiertex Seq Video @tab @tab X @tab Codec used in DOS CDROM FlashBack game. +@item DXA Video @tab @tab X @tab Codec originally used in Feeble Files game. +@item AVID DNxHD @tab X @tab X @tab aka SMPTE VC3 +@item C93 Video @tab @tab X @tab Codec used in Cyberia game. +@item THP @tab @tab X @tab Used on the Nintendo GameCube. +@item Bethsoft VID @tab @tab X @tab Used in some games from Bethesda Softworks. +@item Renderware TXD @tab @tab X @tab Texture dictionaries used by the Renderware Engine. +@item AMV @tab @tab X @tab Used in Chinese MP3 players. +@end multitable + +@code{X} means that encoding (resp. decoding) is supported. + +@section Audio Codecs + +@multitable @columnfractions .4 .1 .1 .1 .7 +@item Supported Codec @tab Encoding @tab Decoding @tab Comments +@item MPEG audio layer 2 @tab IX @tab IX +@item MPEG audio layer 1/3 @tab X @tab IX +@tab MP3 encoding is supported through the external library LAME. +@item AC3 @tab IX @tab IX +@tab liba52 is used internally for decoding. +@item Vorbis @tab X @tab X +@item WMA V1/V2 @tab X @tab X +@item AAC @tab X @tab X +@tab Supported through the external library libfaac/libfaad. +@item Microsoft ADPCM @tab X @tab X +@item AMV IMA ADPCM @tab @tab X +@tab Used in AMV files +@item MS IMA ADPCM @tab X @tab X +@item QT IMA ADPCM @tab @tab X +@item 4X IMA ADPCM @tab @tab X +@item G.726 ADPCM @tab X @tab X +@item Duck DK3 IMA ADPCM @tab @tab X +@tab Used in some Sega Saturn console games. +@item Duck DK4 IMA ADPCM @tab @tab X +@tab Used in some Sega Saturn console games. +@item Westwood Studios IMA ADPCM @tab @tab X +@tab Used in Westwood Studios games like Command and Conquer. +@item SMJPEG IMA ADPCM @tab @tab X +@tab Used in certain Loki game ports. +@item CD-ROM XA ADPCM @tab @tab X +@item CRI ADX ADPCM @tab X @tab X +@tab Used in Sega Dreamcast games. +@item Electronic Arts ADPCM @tab @tab X +@tab Used in various EA titles. +@item Creative ADPCM @tab @tab X +@tab 16 -> 4, 8 -> 4, 8 -> 3, 8 -> 2 +@item THP ADPCM @tab @tab X +@tab Used on the Nintendo GameCube. +@item RA144 @tab @tab X +@tab Real 14400 bit/s codec +@item RA288 @tab @tab X +@tab Real 28800 bit/s codec +@item RADnet @tab X @tab IX +@tab Real low bitrate AC3 codec, liba52 is used for decoding. +@item AMR-NB @tab X @tab X +@tab Supported through an external library. +@item AMR-WB @tab X @tab X +@tab Supported through an external library. +@item DV audio @tab @tab X +@item Id RoQ DPCM @tab X @tab X +@tab Used in Quake III, Jedi Knight 2, other computer games. +@item Interplay MVE DPCM @tab @tab X +@tab Used in various Interplay computer games. +@item Xan DPCM @tab @tab X +@tab Used in Origin's Wing Commander IV AVI files. +@item Sierra Online DPCM @tab @tab X +@tab Used in Sierra Online game audio files. +@item Apple MACE 3 @tab @tab X +@item Apple MACE 6 @tab @tab X +@item FLAC lossless audio @tab X @tab X +@item Shorten lossless audio @tab @tab X +@item Apple lossless audio @tab @tab X +@tab QuickTime fourcc 'alac' +@item FFmpeg Sonic @tab X @tab X +@tab experimental lossy/lossless codec +@item Qdesign QDM2 @tab @tab X +@tab there are still some distortions +@item Real COOK @tab @tab X +@tab All versions except 5.1 are supported +@item DSP Group TrueSpeech @tab @tab X +@item True Audio (TTA) @tab @tab X +@item Smacker Audio @tab @tab X +@item WavPack Audio @tab @tab X +@item Cin Audio @tab @tab X +@tab Codec used in Delphine Software games. +@item Intel Music Coder @tab @tab X +@item Musepack @tab @tab X +@tab SV7 and SV8 are supported +@item DT$ Coherent Audio @tab @tab X +@item ATRAC 3 @tab @tab X +@item Monkey's Audio @tab @tab X @tab Only versions 3.97-3.99 are supported +@item Nellymoser ASAO @tab @tab X +@end multitable + +@code{X} means that encoding (resp. decoding) is supported. + +@code{I} means that an integer-only version is available, too (ensures high +performance on systems without hardware floating point support). + +@chapter Platform Specific information + +@section BSD + +BSD make will not build FFmpeg, you need to install and use GNU Make +(@file{gmake}). + +@section Windows + +To get help and instructions for building FFmpeg under Windows, check out +the FFmpeg Windows Help Forum at +@url{http://arrozcru.no-ip.org/ffmpeg/}. + +@subsection Native Windows compilation + +FFmpeg can be built to run natively on Windows using the MinGW tools. Install +the current versions of MSYS and MinGW from @url{http://www.mingw.org/}. Also +install the coreutils package. You can find detailed installation +instructions in the download section and the FAQ. + +Within the MSYS shell, configure and make with: + +@example +./configure --enable-memalign-hack +make +make install +@end example + +This will install @file{ffmpeg.exe} along with many other development files +to @file{/usr/local}. You may specify another install path using the +@code{--prefix} option in @file{configure}. + +Notes: + +@itemize + +@item Use at least bash 3.1. Older versions are known to fail on the +configure script. + +@item In order to compile vhooks, you must have a POSIX-compliant libdl in +your MinGW system. Get dlfcn-win32 from +@url{http://code.google.com/p/dlfcn-win32}. + +@item In order to compile FFplay, you must have the MinGW development library +of SDL. Get it from @url{http://www.libsdl.org}. +Edit the @file{bin/sdl-config} script so that it points to the correct prefix +where SDL was installed. Verify that @file{sdl-config} can be launched from +the MSYS command line. + +@item The target @code{make wininstaller} can be used to create a +Nullsoft-based Windows installer for FFmpeg and FFplay. @file{SDL.dll} +must be copied to the FFmpeg directory in order to build the +installer. + +@item By using @code{./configure --enable-shared} when configuring FFmpeg, +you can build libavutil, libavcodec and libavformat as DLLs. + +@end itemize + +@subsection Microsoft Visual C++ compatibility + +As stated in the FAQ, FFmpeg will not compile under MSVC++. However, if you +want to use the libav* libraries in your own applications, you can still +compile those applications using MSVC++. But the libav* libraries you link +to @emph{must} be built with MinGW. However, you will not be able to debug +inside the libav* libraries, since MSVC++ does not recognize the debug +symbols generated by GCC. +We strongly recommend you to move over from MSVC++ to MinGW tools. + +This description of how to use the FFmpeg libraries with MSVC++ is based on +Microsoft Visual C++ 2005 Express Edition. If you have a different version, +you might have to modify the procedures slightly. + +@subsubsection Using static libraries + +Assuming you have just built and installed FFmpeg in @file{/usr/local}. + +@enumerate + +@item Create a new console application ("File / New / Project") and then +select "Win32 Console Application". On the appropriate page of the +Application Wizard, uncheck the "Precompiled headers" option. + +@item Write the source code for your application, or, for testing, just +copy the code from an existing sample application into the source file +that MSVC++ has already created for you. For example, you can copy +@file{output_example.c} from the FFmpeg distribution. + +@item Open the "Project / Properties" dialog box. In the "Configuration" +combo box, select "All Configurations" so that the changes you make will +affect both debug and release builds. In the tree view on the left hand +side, select "C/C++ / General", then edit the "Additional Include +Directories" setting to contain the path where the FFmpeg includes were +installed (i.e. @file{c:\msys\1.0\local\include}). + +@item Still in the "Project / Properties" dialog box, select +"Linker / General" from the tree view and edit the +"Additional Library Directories" setting to contain the @file{lib} +directory where FFmpeg was installed (i.e. @file{c:\msys\1.0\local\lib}), +the directory where MinGW libs are installed (i.e. @file{c:\mingw\lib}), +and the directory where MinGW's GCC libs are installed +(i.e. @file{C:\mingw\lib\gcc\mingw32\4.2.1-sjlj}). Then select +"Linker / Input" from the tree view, and add the files @file{libavformat.a}, +@file{libavcodec.a}, @file{libavutil.a}, @file{libmingwex.a}, +@file{libgcc.a}, and any other libraries you used (i.e. @file{libz.a}) +to the end of "Additional Dependencies". + +@item Now, select "C/C++ / Code Generation" from the tree view. Select +"Debug" in the "Configuration" combo box. Make sure that "Runtime +Library" is set to "Multi-threaded Debug DLL". Then, select "Release" in +the "Configuration" combo box and make sure that "Runtime Library" is +set to "Multi-threaded DLL". + +@item Click "OK" to close the "Project / Properties" dialog box. + +@item MSVC++ lacks some C99 header files that are fundamental for FFmpeg. +Get msinttypes from @url{http://code.google.com/p/msinttypes/downloads/list} +and install it in MSVC++'s include directory +(i.e. @file{C:\Program Files\Microsoft Visual Studio 8\VC\include}). + +@item MSVC++ also does not understand the @code{inline} keyword used by +FFmpeg, so you must add this line before @code{#include}ing libav*: +@example +#define inline _inline +@end example + +@item If you used @file{output_example.c} as your sample application, +you will have to edit the @code{#include}s to point to the files which +are under the @file{ffmpeg} directory (i.e. @code{<ffmpeg/avformat.h>}). + +@item Build your application, everything should work. + +@end enumerate + +@subsubsection Using shared libraries + +This is how to create DLL and LIB files that are compatible with MSVC++: + +@enumerate + +@item Add a call to @file{vcvars32.bat} (which sets up the environment +variables for the Visual C++ tools) as the first line of @file{msys.bat}. +The standard location for @file{vcvars32.bat} is +@file{C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat}, +and the standard location for @file{msys.bat} is @file{C:\msys\1.0\msys.bat}. +If this corresponds to your setup, add the following line as the first line +of @file{msys.bat}: + +@example +call "C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat" +@end example + +Alternatively, you may start the @file{Visual Studio 2005 Command Prompt}, +and run @file{c:\msys\1.0\msys.bat} from there. + +@item Within the MSYS shell, run @code{lib.exe}. If you get a help message +from @file{Microsoft (R) Library Manager}, this means your environment +variables are set up correctly, the @file{Microsoft (R) Library Manager} +is on the path and will be used by FFmpeg to create +MSVC++-compatible import libraries. + +@item Build FFmpeg with + +@example +./configure --enable-shared --enable-memalign-hack +make +make install +@end example + +Your install path (@file{/usr/local/} by default) should now have the +necessary DLL and LIB files under the @file{bin} directory. + +@end enumerate + +To use those files with MSVC++, do the same as you would do with +the static libraries, as described above. But in Step 4, +you should only need to add the directory where the LIB files are installed +(i.e. @file{c:\msys\usr\local\bin}). This is not a typo, the LIB files are +installed in the @file{bin} directory. And instead of adding @file{libxx.a} +files, you should add @file{avcodec.lib}, @file{avformat.lib}, and +@file{avutil.lib}. There should be no need for @file{libmingwex.a}, +@file{libgcc.a}, and @file{wsock32.lib}, nor any other external library +statically linked into the DLLs. The @file{bin} directory contains a bunch +of DLL files, but the ones that are actually used to run your application +are the ones with a major version number in their filenames +(i.e. @file{avcodec-51.dll}). + +@subsection Cross compilation for Windows with Linux + +You must use the MinGW cross compilation tools available at +@url{http://www.mingw.org/}. + +Then configure FFmpeg with the following options: +@example +./configure --target-os=mingw32 --cross-prefix=i386-mingw32msvc- +@end example +(you can change the cross-prefix according to the prefix chosen for the +MinGW tools). + +Then you can easily test FFmpeg with Wine +(@url{http://www.winehq.com/}). + +@subsection Compilation under Cygwin + +The main issue with Cygwin is that newlib, its C library, does not +contain llrint(). However, it is possible to leverage the +implementation in MinGW. + +Just install your Cygwin with all the "Base" packages, plus the +following "Devel" ones: +@example +binutils, gcc-core, make, subversion, mingw-runtime +@end example + +Do not install binutils-20060709-1 (they are buggy on shared builds); +use binutils-20050610-1 instead. + +Then create a small library that just contains llrint(): + +@example +ar x /usr/lib/mingw/libmingwex.a llrint.o +ar cq /usr/local/lib/libllrint.a llrint.o +@end example + +Then run + +@example +./configure --enable-static --disable-shared --extra-ldflags='-L /usr/local/lib' --extra-libs='-l llrint' +@end example + +to make a static build or + +@example +./configure --enable-shared --disable-static --extra-ldflags='-L /usr/local/lib' --extra-libs='-l llrint' +@end example + +to build shared libraries. + +If you want to build FFmpeg with additional libraries, download Cygwin +"Devel" packages for Ogg and Vorbis from any Cygwin packages repository +and/or SDL, xvid, faac, faad2 packages from Cygwin Ports, +(@url{http://cygwinports.dotsrc.org/}). + +@subsection Crosscompilation for Windows under Cygwin + +With Cygwin you can create Windows binaries that do not need the cygwin1.dll. + +Just install your Cygwin as explained before, plus these additional +"Devel" packages: +@example +gcc-mingw-core, mingw-runtime, mingw-zlib +@end example + +and add some special flags to your configure invocation. + +For a static build run +@example +./configure --target-os=mingw32 --enable-memalign-hack --enable-static --disable-shared --extra-cflags=-mno-cygwin --extra-libs=-mno-cygwin +@end example + +and for a build with shared libraries +@example +./configure --target-os=mingw32 --enable-memalign-hack --enable-shared --disable-static --extra-cflags=-mno-cygwin --extra-libs=-mno-cygwin +@end example + +@section BeOS + +BeOS support is broken in mysterious ways. + +@section OS/2 + +For information about compiling FFmpeg on OS/2 see +@url{http://www.edm2.com/index.php/FFmpeg}. + +@chapter Developers Guide + +@section API +@itemize @bullet +@item libavcodec is the library containing the codecs (both encoding and +decoding). Look at @file{libavcodec/apiexample.c} to see how to use it. + +@item libavformat is the library containing the file format handling (mux and +demux code for several formats). Look at @file{ffplay.c} to use it in a +player. See @file{output_example.c} to use it to generate audio or video +streams. + +@end itemize + +@section Integrating libavcodec or libavformat in your program + +You can integrate all the source code of the libraries to link them +statically to avoid any version problem. All you need is to provide a +'config.mak' and a 'config.h' in the parent directory. See the defines +generated by ./configure to understand what is needed. + +You can use libavcodec or libavformat in your commercial program, but +@emph{any patch you make must be published}. The best way to proceed is +to send your patches to the FFmpeg mailing list. + +@node Coding Rules +@section Coding Rules + +FFmpeg is programmed in the ISO C90 language with a few additional +features from ISO C99, namely: +@itemize @bullet +@item +the @samp{inline} keyword; +@item +@samp{//} comments; +@item +designated struct initializers (@samp{struct s x = @{ .i = 17 @};}) +@item +compound literals (@samp{x = (struct s) @{ 17, 23 @};}) +@end itemize + +These features are supported by all compilers we care about, so we will not +accept patches to remove their use unless they absolutely do not impair +clarity and performance. + +All code must compile with GCC 2.95 and GCC 3.3. Currently, FFmpeg also +compiles with several other compilers, such as the Compaq ccc compiler +or Sun Studio 9, and we would like to keep it that way unless it would +be exceedingly involved. To ensure compatibility, please do not use any +additional C99 features or GCC extensions. Especially watch out for: +@itemize @bullet +@item +mixing statements and declarations; +@item +@samp{long long} (use @samp{int64_t} instead); +@item +@samp{__attribute__} not protected by @samp{#ifdef __GNUC__} or similar; +@item +GCC statement expressions (@samp{(x = (@{ int y = 4; y; @})}). +@end itemize + +Indent size is 4. +The presentation is the one specified by 'indent -i4 -kr -nut'. +The TAB character is forbidden outside of Makefiles as is any +form of trailing whitespace. Commits containing either will be +rejected by the Subversion repository. + +The main priority in FFmpeg is simplicity and small code size in order to +minimize the bug count. + +Comments: Use the JavaDoc/Doxygen +format (see examples below) so that code documentation +can be generated automatically. All nontrivial functions should have a comment +above them explaining what the function does, even if it is just one sentence. +All structures and their member variables should be documented, too. +@example +/** + * @@file mpeg.c + * MPEG codec. + * @@author ... + */ + +/** + * Summary sentence. + * more text ... + * ... + */ +typedef struct Foobar@{ + int var1; /**< var1 description */ + int var2; ///< var2 description + /** var3 description */ + int var3; +@} Foobar; + +/** + * Summary sentence. + * more text ... + * ... + * @@param my_parameter description of my_parameter + * @@return return value description + */ +int myfunc(int my_parameter) +... +@end example + +fprintf and printf are forbidden in libavformat and libavcodec, +please use av_log() instead. + +Casts should be used only when necessary. Unneeded parentheses +should also be avoided if they don't make the code easier to understand. + +@section Development Policy + +@enumerate +@item + Contributions should be licensed under the LGPL 2.1, including an + "or any later version" clause, or the MIT license. GPL 2 including + an "or any later version" clause is also acceptable, but LGPL is + preferred. +@item + You must not commit code which breaks FFmpeg! (Meaning unfinished but + enabled code which breaks compilation or compiles but does not work or + breaks the regression tests) + You can commit unfinished stuff (for testing etc), but it must be disabled + (#ifdef etc) by default so it does not interfere with other developers' + work. +@item + You do not have to over-test things. If it works for you, and you think it + should work for others, then commit. If your code has problems + (portability, triggers compiler bugs, unusual environment etc) they will be + reported and eventually fixed. +@item + Do not commit unrelated changes together, split them into self-contained + pieces. Also do not forget that if part B depends on part A, but A does not + depend on B, then A can and should be committed first and separate from B. + Keeping changes well split into self-contained parts makes reviewing and + understanding them on the commit log mailing list easier. This also helps + in case of debugging later on. + Also if you have doubts about splitting or not splitting, do not hesitate to + ask/discuss it on the developer mailing list. +@item + Do not change behavior of the program (renaming options etc) without + first discussing it on the ffmpeg-devel mailing list. Do not remove + functionality from the code. Just improve! + + Note: Redundant code can be removed. +@item + Do not commit changes to the build system (Makefiles, configure script) + which change behavior, defaults etc, without asking first. The same + applies to compiler warning fixes, trivial looking fixes and to code + maintained by other developers. We usually have a reason for doing things + the way we do. Send your changes as patches to the ffmpeg-devel mailing + list, and if the code maintainers say OK, you may commit. This does not + apply to files you wrote and/or maintain. +@item + We refuse source indentation and other cosmetic changes if they are mixed + with functional changes, such commits will be rejected and removed. Every + developer has his own indentation style, you should not change it. Of course + if you (re)write something, you can use your own style, even though we would + prefer if the indentation throughout FFmpeg was consistent (Many projects + force a given indentation style - we do not.). If you really need to make + indentation changes (try to avoid this), separate them strictly from real + changes. + + NOTE: If you had to put if()@{ .. @} over a large (> 5 lines) chunk of code, + then either do NOT change the indentation of the inner part within (do not + move it to the right)! or do so in a separate commit +@item + Always fill out the commit log message. Describe in a few lines what you + changed and why. You can refer to mailing list postings if you fix a + particular bug. Comments such as "fixed!" or "Changed it." are unacceptable. +@item + If you apply a patch by someone else, include the name and email address in + the log message. Since the ffmpeg-cvslog mailing list is publicly + archived you should add some SPAM protection to the email address. Send an + answer to ffmpeg-devel (or wherever you got the patch from) saying that + you applied the patch. +@item + When applying patches that have been discussed (at length) on the mailing + list, reference the thread in the log message. +@item + Do NOT commit to code actively maintained by others without permission. + Send a patch to ffmpeg-devel instead. If no one answers within a reasonable + timeframe (12h for build failures and security fixes, 3 days small changes, + 1 week for big patches) then commit your patch if you think it is OK. + Also note, the maintainer can simply ask for more time to review! +@item + Subscribe to the ffmpeg-cvslog mailing list. The diffs of all commits + are sent there and reviewed by all the other developers. Bugs and possible + improvements or general questions regarding commits are discussed there. We + expect you to react if problems with your code are uncovered. +@item + Update the documentation if you change behavior or add features. If you are + unsure how best to do this, send a patch to ffmpeg-devel, the documentation + maintainer(s) will review and commit your stuff. +@item + Try to keep important discussions and requests (also) on the public + developer mailing list, so that all developers can benefit from them. +@item + Never write to unallocated memory, never write over the end of arrays, + always check values read from some untrusted source before using them + as array index or other risky things. +@item + Remember to check if you need to bump versions for the specific libav + parts (libavutil, libavcodec, libavformat) you are changing. You need + to change the version integer and the version string. + Incrementing the first component means no backward compatibility to + previous versions (e.g. removal of a function from the public API). + Incrementing the second component means backward compatible change + (e.g. addition of a function to the public API). + Incrementing the third component means a noteworthy binary compatible + change (e.g. encoder bug fix that matters for the decoder). +@item + If you add a new codec, remember to update the changelog, add it to + the supported codecs table in the documentation and bump the second + component of the @file{libavcodec} version number appropriately. If + it has a fourcc, add it to @file{libavformat/avienc.c}, even if it + is only a decoder. +@item + Compiler warnings indicate potential bugs or code with bad style. If a type of + warning always points to correct and clean code, that warning should + be disabled, not the code changed. + Thus the remaining warnings can either be bugs or correct code. + If it is a bug, the bug has to be fixed. If it is not, the code should + be changed to not generate a warning unless that causes a slowdown + or obfuscates the code. +@item + If you add a new file, give it a proper license header. Do not copy and + paste it from a random place, use an existing file as template. +@end enumerate + +We think our rules are not too hard. If you have comments, contact us. + +Note, these rules are mostly borrowed from the MPlayer project. + +@section Submitting patches + +First, (@pxref{Coding Rules}) above if you did not yet. + +When you submit your patch, try to send a unified diff (diff '-up' +option). We cannot read other diffs :-) + +Also please do not submit a patch which contains several unrelated changes. +Split it into separate, self-contained pieces. This does not mean splitting +file by file. Instead, make the patch as small as possible while still +keeping it as a logical unit that contains an individual change, even +if it spans multiple files. This makes reviewing your patches much easier +for us and greatly increases your chances of getting your patch applied. + +Run the regression tests before submitting a patch so that you can +verify that there are no big problems. + +Patches should be posted as base64 encoded attachments (or any other +encoding which ensures that the patch will not be trashed during +transmission) to the ffmpeg-devel mailing list, see +@url{http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel} + +It also helps quite a bit if you tell us what the patch does (for example +'replaces lrint by lrintf'), and why (for example '*BSD isn't C99 compliant +and has no lrint()') + +Also please if you send several patches, send each patch as a separate mail, +do not attach several unrelated patches to the same mail. + +@section patch submission checklist + +@enumerate +@item + Do the regression tests pass with the patch applied? +@item + Is the patch a unified diff? +@item + Is the patch against latest FFmpeg SVN? +@item + Are you subscribed to ffmpeg-dev? + (the list is subscribers only due to spam) +@item + Have you checked that the changes are minimal, so that the same cannot be + achieved with a smaller patch and/or simpler final code? +@item + If the change is to speed critical code, did you benchmark it? +@item + If you did any benchmarks, did you provide them in the mail? +@item + Have you checked that the patch does not introduce buffer overflows or + other security issues? +@item + Is the patch created from the root of the source tree, so it can be + applied with @code{patch -p0}? +@item + Does the patch not mix functional and cosmetic changes? +@item + Did you add tabs or trailing whitespace to the code? Both are forbidden. +@item + Is the patch attached to the email you send? +@item + Is the mime type of the patch correct? It should be text/x-diff or + text/x-patch or at least text/plain and not application/octet-stream. +@item + If the patch fixes a bug, did you provide a verbose analysis of the bug? +@item + If the patch fixes a bug, did you provide enough information, including + a sample, so the bug can be reproduced and the fix can be verified? + Note please do not attach samples >100k to mails but rather provide a + URL, you can upload to ftp://upload.mplayerhq.hu +@item + Did you provide a verbose summary about what the patch does change? +@item + Did you provide a verbose explanation why it changes things like it does? +@item + Did you provide a verbose summary of the user visible advantages and + disadvantages if the patch is applied? +@item + Did you provide an example so we can verify the new feature added by the + patch easily? +@item + If you added a new file, did you insert a license header? It should be + taken from FFmpeg, not randomly copied and pasted from somewhere else. +@item + You should maintain alphabetical order in alphabetically ordered lists as + long as doing so does not break API/ABI compatibility. +@item + Lines with similar content should be aligned vertically when doing so + improves readability. +@item + Did you provide a suggestion for a clear commit log message? +@item + Did you test your decoder or demuxer against damaged data? If no, see + tools/trasher and the noise bitstream filter. Your decoder or demuxer + should not crash or end in a (near) infinite loop when fed damaged data. +@end enumerate + +@section Patch review process + +All patches posted to ffmpeg-devel will be reviewed, unless they contain a +clear note that the patch is not for SVN. +Reviews and comments will be posted as replies to the patch on the +mailing list. The patch submitter then has to take care of every comment, +that can be by resubmitting a changed patch or by discussion. Resubmitted +patches will themselves be reviewed like any other patch. If at some point +a patch passes review with no comments then it is approved, that can for +simple and small patches happen immediately while large patches will generally +have to be changed and reviewed many times before they are approved. +After a patch is approved it will be committed to the repository. + +We will review all submitted patches, but sometimes we are quite busy so +especially for large patches this can take several weeks. + +When resubmitting patches, please do not make any significant changes +not related to the comments received during review. Such patches will +be rejected. Instead, submit significant changes or new features as +separate patches. + +@section Regression tests + +Before submitting a patch (or committing to the repository), you should at least +test that you did not break anything. + +The regression tests build a synthetic video stream and a synthetic +audio stream. These are then encoded and decoded with all codecs or +formats. The CRC (or MD5) of each generated file is recorded in a +result file. A 'diff' is launched to compare the reference results and +the result file. + +The regression tests then go on to test the FFserver code with a +limited set of streams. It is important that this step runs correctly +as well. + +Run 'make test' to test all the codecs and formats. + +Run 'make fulltest' to test all the codecs, formats and FFserver. + +[Of course, some patches may change the results of the regression tests. In +this case, the reference results of the regression tests shall be modified +accordingly]. + +@bye diff --git a/contrib/ffmpeg/doc/hooks.texi b/contrib/ffmpeg/doc/hooks.texi index 49504509f..c410f1cb0 100644 --- a/contrib/ffmpeg/doc/hooks.texi +++ b/contrib/ffmpeg/doc/hooks.texi @@ -10,6 +10,12 @@ @chapter Introduction +@var{Please be aware that vhook is deprecated, and hence its development is +frozen (bug fixes are still accepted). +The substitute will be 'libavfilter', the result of our 'Video Filter API' +Google Summer of Code project. You may monitor its progress by subscribing to +the ffmpeg-soc mailing list at +@url{http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc}.} The video hook functionality is designed (mostly) for live video. It allows the video to be modified or examined between the decoder and the encoder. @@ -67,18 +73,27 @@ with the full path to the font file, as in: @end example where 20 is the point size. +You can specify the filename to read RGB color names from. If it is not +specified, these defaults are used: @file{/usr/share/X11/rgb.txt} and +@file{/usr/lib/X11/rgb.txt} + Options: @multitable @columnfractions .2 .8 +@item @option{-C <rgb.txt>} @tab The filename to read RGB color names from @item @option{-c <color>} @tab The color of the text @item @option{-F <fontname>} @tab The font face and size @item @option{-t <text>} @tab The text @item @option{-f <filename>} @tab The filename to read text from -@item @option{-x <expresion>} @tab x coordinate of text or image -@item @option{-y <expresion>} @tab y coordinate of text or image +@item @option{-x <expression>}@tab x coordinate of text or image +@item @option{-y <expression>}@tab y coordinate of text or image @item @option{-i <filename>} @tab The filename to read a image from +@item @option{-R <expression>}@tab Value for R color +@item @option{-G <expression>}@tab Value for G color +@item @option{-B <expression>}@tab Value for B color +@item @option{-A <expression>}@tab Value for Alpha channel @end multitable -Expresions are functions of these variables: +Expressions are functions of these variables: @multitable @columnfractions .2 .8 @item @var{N} @tab frame number (starting at zero) @item @var{H} @tab frame height @@ -137,6 +152,30 @@ Usage examples: a newline are treated as end-of-file. To create blank lines, use lines that consist of space characters only. + # Scrolling credits with custom color from a text file + ffmpeg -i input.avi -vhook \ + 'vhook/imlib2.so -C rgb.txt -c CustomColor1 -F VeraBd.ttf/16 -x 100 -y -1.0*N -f credits.txt' \ + -sameq output.avi + + This example does the same as the one above, but specifies an rgb.txt file + to be used, which has a custom-made color in it. + + # Variable colors + ffmpeg -i input.avi -vhook \ + 'vhook/imlib2.so -t Hello -R abs(255*sin(N/47*PI)) -G abs(255*sin(N/47*PI)) -B abs(255*sin(N/47*PI))' \ + -sameq output.avi + + In this example, the color for the text goes up and down from black to + white. + + # Text fade-out + ffmpeg -i input.avi -vhook \ + 'vhook/imlib2.so -t Hello -A max(0,255-exp(N/47))' \ + -sameq output.avi + + In this example, the text fades out in about 10 seconds for a 25 fps input + video file. + # scrolling credits from a graphics file ffmpeg -sameq -i input.avi \ -vhook 'vhook/imlib2.so -x 0 -y -1.0*N -i credits.png' output.avi diff --git a/contrib/ffmpeg/doc/issue_tracker.txt b/contrib/ffmpeg/doc/issue_tracker.txt new file mode 100644 index 000000000..4b6a8a134 --- /dev/null +++ b/contrib/ffmpeg/doc/issue_tracker.txt @@ -0,0 +1,222 @@ +FFmpeg's bug/patch/feature request tracker manual +================================================= + +NOTE: This is a draft. + +Overview: +--------- +FFmpeg uses Roundup for tracking issues, new issues and changes to +existing issues can be done through a web interface and through email. +It is possible to subscribe to individual issues by adding yourself to the +nosy list or to subscribe to the ffmpeg-issues mailing list which receives +a mail for every change to every issue. Replies to such mails will also +be properly added to the respective issue. +(the above does all work already after light testing) +The subscription URL for the ffmpeg-issues list is: +http://live.polito/mailman/listinfo/ffmpeg-issues +The URL of the webinterface of the tracker is: +http(s)://roundup.mplayerhq/roundup/ffmpeg/ +Note the URLs in this document are obfuscated, you must append the top level +domain of Hungary to the tracker, and of Italy to the mailing list. + +Email Interface: +---------------- +There is a mailing list to which all new issues and changes to existing issues +are sent. You can subscribe through +http://live.polito/mailman/listinfo/ffmpeg-issues +Replies to messages there will have their text added to the specific issues. +Attachments will be added as if they had been uploaded via the web interface. +You can change the status, substatus, topic, ... by changing the subject in +your reply like: +Re: [issue94] register_avcodec and allcodecs.h [type=patch;status=open;substatus=approved] +Roundup will then change things as you requested and remove the [...] from +the subject before forwarding the mail to the mailing list. + + +NOTE: issue = (bug report || patch || feature request) + +Type: +----- +bug + An error, flaw, mistake, failure, or fault in FFmpeg or libav* that + prevents it from behaving as intended. + +feature request + Request of support for encoding or decoding of a new codec, container + or variant. + Request of support for more, less or plain different output or behavior + where the current implementation cannot be considered wrong. + +patch + A patch as generated by diff which conforms to the patch submission and + development policy. + + +Priority: +--------- +critical + Bugs and patches which deal with data loss and security issues. + No feature request can be critical. + +important + Bugs which make FFmpeg unusable for a significant number of users, and + patches fixing them. + Examples here might be completely broken MPEG-4 decoding or a build issue + on Linux. + While broken 4xm decoding or a broken OS/2 build would not be important, + the separation to normal is somewhat fuzzy. + For feature requests this priority would be used for things many people + want. + +normal + + +minor + Bugs and patches about things like spelling errors, "mp2" instead of + "mp3" being shown and such. + Feature requests about things few people want or which do not make a big + difference. + +wish + Something that is desirable to have but that there is no urgency at + all to implement, e.g. something completely cosmetic like a website + restyle or a personalized doxy template or the FFmpeg logo. + This priority is not valid for bugs. + + +Status: +------- +new + initial state + +open + intermediate states + +closed + final state + + +Type/Status/Substatus: +---------- +*/new/new + Initial state of new bugs, patches and feature requests submitted by + users. + +*/open/open + Issues which have been briefly looked at and which did not look outright + invalid. + This implicates that no real more detailed state applies yet. Conversely, + the more detailed states below implicate that the issue has been briefly + looked at. + +*/closed/duplicate + Bugs, patches or feature requests which are duplicates. + Note that patches dealing with the same thing in a different way are not + duplicates. + Note, if you mark something as duplicate, do not forget setting the + superseder so bug reports are properly linked. + +*/closed/invalid + Bugs caused by user errors, random ineligible or otherwise nonsense stuff. + +*/closed/needs_more_info + Issues for which some information has been requested by the developers, + but which has not been provided by anyone within reasonable time. + +bug/open/reproduced + Bugs which have been reproduced. + +bug/open/analyzed + Bugs which have been analyzed and where it is understood what causes them + and which exact chain of events triggers them. This analysis should be + available as a message in the bug report. + Note, do not change the status to analyzed without also providing a clear + and understandable analysis. + This state implicates that the bug either has been reproduced or that + reproduction is not needed as the bug is already understood. + +bug/open/needs_more_info + Bug reports which are incomplete and or where more information is needed + from the submitter or another person who can provide it. + This state implicates that the bug has not been analyzed or reproduced. + Note, the idea behind needs_more_info is to offload work from the + developers to the users whenever possible. + +bug/closed/fixed + Bugs which have to the best of our knowledge been fixed. + +bug/closed/wont_fix + Bugs which we will not fix, the reasons here could be legal, philosophical + or others. + +bug/closed/works_for_me + Bugs for which sufficient information was provided to reproduce but + reproduction failed - that is the code seems to work correctly to the + best of our knowledge. + +patch/open/approved + Patches which have been reviewed and approved by a developer. + Such patches can be applied anytime by any other developer after some + reasonable testing (compile + regression tests + does the patch do + what the author claimed). + +patch/open/needs_changes + Patches which have been reviewed and need changes to be accepted. + +patch/closed/applied + Patches which have been applied. + +patch/closed/rejected + Patches which have been rejected. + +feature_request/open/needs_more_info + Feature requests where it is not clear what exactly is wanted + (these also could be closed as invalid ...). + +feature_request/closed/implemented + Feature requests which have been implemented. + +feature_request/closed/wont_implement + Feature requests which will not be implemented. The reasons here could + be legal, philosophical or others. + +Note, please do not use type-status-substatus combinations other than the +above without asking on ffmpeg-dev first! + +Note2, if you provide the requested info do not forget to remove the +needs_more_info substate. + +Topic: +------ +A topic is a tag you should add to your issue in order to make grouping them +easier. + +avcodec + issues in libavcodec/* + +avformat + issues in libavformat/* + +avutil + issues in libavutil/* + +regression test + issues in tests/* + +ffmpeg + issues in or related to ffmpeg.c + +ffplay + issues in or related to ffplay.c + +ffserver + issues in or related to ffserver.c + +build system + issues in or related to configure/Makefile + +regression + bugs which were working in a past revision + +roundup + issues related to our issue tracker diff --git a/contrib/ffmpeg/doc/optimization.txt b/contrib/ffmpeg/doc/optimization.txt index f66c69bcf..4c0934b4b 100644 --- a/contrib/ffmpeg/doc/optimization.txt +++ b/contrib/ffmpeg/doc/optimization.txt @@ -1,6 +1,8 @@ optimization Tips (for libavcodec): +=================================== What to optimize: +----------------- If you plan to do non-x86 architecture specific optimizations (SIMD normally), then take a look in the i386/ directory, as most important functions are already optimized for MMX. @@ -9,10 +11,12 @@ If you want to do x86 optimizations then you can either try to finetune the stuff in the i386 directory or find some other functions in the C source to optimize, but there aren't many left. + Understanding these overoptimized functions: +-------------------------------------------- As many functions tend to be a bit difficult to understand because of optimizations, it can be hard to optimize them further, or write -architecture-specific versions. It is recommened to look at older +architecture-specific versions. It is recommended to look at older revisions of the interesting files (for a web frontend try ViewVC at http://svn.mplayerhq.hu/ffmpeg/trunk/). Alternatively, look into the other architecture-specific versions in @@ -24,10 +28,23 @@ NOTE: If you still don't understand some function, ask at our mailing list!!! (http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel) +When is an optimization justified? +---------------------------------- +Normally, clean and simple optimizations for widely used codecs are +justified even if they only achieve an overall speedup of 0.1%. These +speedups accumulate and can make a big difference after awhile. Also, if +none of the following factors get worse due to an optimization -- speed, +binary code size, source size, source readability -- and at least one +factor improves, then an optimization is always a good idea even if the +overall gain is less than 0.1%. For obscure codecs that are not often +used, the goal is more toward keeping the code clean, small, and +readable instead of making it 1% faster. + WTF is that function good for ....: -The primary purpose of that list is to avoid wasting time to optimize functions -which are rarely used +----------------------------------- +The primary purpose of this list is to avoid wasting time optimizing functions +which are rarely used. put(_no_rnd)_pixels{,_x2,_y2,_xy2} Used in motion compensation (en/decoding). @@ -77,7 +94,7 @@ clear_blocks gmc Used for MPEG-4 gmc. Optimizing this should have a significant effect on the gmc decoding - speed but it's very likely impossible to write in SIMD. + speed. gmc1 Used for chroma blocks in MPEG-4 gmc with 1 warp point @@ -134,11 +151,29 @@ The minimum guaranteed alignment is written in the .h files, for example: void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, UINT8 *pixels/*align 8*/, int line_size); +General Tips: +------------- +Use asm loops like: +asm( + "1: .... + ... + "jump_instruciton .... +Do not use C loops: +do{ + asm( + ... +}while() + +Use asm() instead of intrinsics. The latter requires a good optimizing compiler +which gcc is not. + Links: +====== http://www.aggregate.org/MAGIC/ x86-specific: +------------- http://developer.intel.com/design/pentium4/manuals/248966.htm The IA-32 Intel Architecture Software Developer's Manual, Volume 2: @@ -152,14 +187,45 @@ http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/22007.pd ARM-specific: -ARM Architecture Reference Manual: -http://www.arm.com/community/academy/resources.html +------------- +ARM Architecture Reference Manual (up to ARMv5TE): +http://www.arm.com/community/university/eulaarmarm.html + +Procedure Call Standard for the ARM Architecture: +http://www.arm.com/pdfs/aapcs.pdf + +Optimization guide for ARM9E (used in Nokia 770 Internet Tablet): +http://infocenter.arm.com/help/topic/com.arm.doc.ddi0240b/DDI0240A.pdf +Optimization guide for ARM11 (used in Nokia N800 Internet Tablet): +http://infocenter.arm.com/help/topic/com.arm.doc.ddi0211j/DDI0211J_arm1136_r1p5_trm.pdf +Optimization guide for Intel XScale (used in Sharp Zaurus PDA): +http://download.intel.com/design/intelxscale/27347302.pdf + +PowerPC-specific: +----------------- +PowerPC32/AltiVec PIM: +www.freescale.com/files/32bit/doc/ref_manual/ALTIVECPEM.pdf + +PowerPC32/AltiVec PEM: +www.freescale.com/files/32bit/doc/ref_manual/ALTIVECPIM.pdf + +CELL/SPU: +http://www-01.ibm.com/chips/techlib/techlib.nsf/techdocs/30B3520C93F437AB87257060006FFE5E/$file/Language_Extensions_for_CBEA_2.4.pdf +http://www-01.ibm.com/chips/techlib/techlib.nsf/techdocs/9F820A5FFA3ECE8C8725716A0062585F/$file/CBE_Handbook_v1.1_24APR2007_pub.pdf + +SPARC-specific: +--------------- +SPARC Joint Programming Specification (JPS1): Commonality +http://www.fujitsu.com/downloads/PRMPWR/JPS1-R1.0.4-Common-pub.pdf -Instructions timings and optimization guide for ARM9E: -http://www.arm.com/pdfs/DDI0222B_9EJS_r1p2.pdf +UltraSPARC III Processor User's Manual (contains instruction timings) +http://www.sun.com/processors/manuals/USIIIv2.pdf +VIS Whitepaper (contains optimization guidelines) +http://www.sun.com/processors/vis/download/vis/vis_whitepaper.pdf GCC asm links: +-------------- official doc but quite ugly http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html diff --git a/contrib/ffmpeg/doc/snow.txt b/contrib/ffmpeg/doc/snow.txt index 4b8fab75a..f99133971 100644 --- a/contrib/ffmpeg/doc/snow.txt +++ b/contrib/ffmpeg/doc/snow.txt @@ -1,7 +1,18 @@ ============================================= -SNOW Video Codec Specification Draft 20070103 +Snow Video Codec Specification Draft 20080110 ============================================= +Introduction: +============= +This specification describes the Snow bitstream syntax and semantics as +well as the formal Snow decoding process. + +The decoding process is described precisely and any compliant decoder +MUST produce the exact same output for a spec-conformant Snow stream. +For encoding, though, any process which generates a stream compliant to +the syntactical and semantic requirements and which is decodable by +the process described in this spec shall be considered a conformant +Snow encoder. Definitions: ============ @@ -45,6 +56,22 @@ header: max_ref_frames-1 u header_state qlogs } + if(!keyframe){ + update_mc b header_state + if(update_mc){ + for(plane=0; plane<2; plane++){ + diag_mc b header_state + htaps/2-1 u header_state + for(i= p->htaps/2; i; i--) + |hcoeff[i]| u header_state + } + } + update_qlogs b header_state + if(update_qlogs){ + spatial_decomposition_count u header_state + qlogs + } + } spatial_decomposition_type s header_state qlog s header_state @@ -70,9 +97,9 @@ prediction: block(0) block(level): + mvx_diff=mvy_diff=y_diff=cb_diff=cr_diff=0 if(keyframe){ intra=1 - y_diff=cb_diff=cr_diff=0 }else{ if(level!=max_block_depth){ s_context= 2*left->level + 2*top->level + topleft->level + topright->level @@ -103,6 +130,20 @@ block(level): residual: + residual2(luma) + residual2(chroma_cr) + residual2(chroma_cb) + +residual2: + for(level=0; level<spatial_decomposition_count; level++){ + if(level==0) + subband(LL, 0) + subband(HL, level) + subband(LH, level) + subband(HH, level) + } + +subband: FIXME @@ -145,6 +186,35 @@ max_ref_frames maximum number of reference frames this MUST NOT change within a bitstream +update_mc + indicates that motion compensation filter parameters are stored in the + header + +diag_mc + flag to enable faster diagonal interpolation + this SHOULD be 1 unless it turns out to be covered by a valid patent + +htaps + number of half pel interpolation filter taps, MUST be even, >0 and <10 + +hcoeff + half pel interpolation filter coefficients, hcoeff[0] are the 2 middle + coefficients [1] are the next outer ones and so on, resulting in a filter + like: ...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... + the sign of the coefficients is not explicitly stored but alternates + after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... + hcoeff[0] is not explicitly stored but found by subtracting the sum + of all stored coefficients with signs from 32 + hcoeff[0]= 32 - hcoeff[1] - hcoeff[2] - ... + a good choice for hcoeff and htaps is + htaps= 6 + hcoeff={40,-10,2} + an alternative which requires more computations at both encoder and + decoder side and may or may not be better is + htaps= 8 + hcoeff={42,-14,6,-2} + + ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1 @@ -175,19 +245,121 @@ block_max_depth quant_table quantiztation table + +Highlevel bitstream structure: +============================= + -------------------------------------------- +| Header | + -------------------------------------------- +| ------------------------------------ | +| | Block0 | | +| | split? | | +| | yes no | | +| | ......... intra? | | +| | : Block01 : yes no | | +| | : Block02 : ....... .......... | | +| | : Block03 : : y DC : : ref index: | | +| | : Block04 : : cb DC : : motion x : | | +| | ......... : cr DC : : motion y : | | +| | ....... .......... | | +| ------------------------------------ | +| ------------------------------------ | +| | Block1 | | +| ... | + -------------------------------------------- +| ------------ ------------ ------------ | +|| Y subbands | | Cb subbands| | Cr subbands|| +|| --- --- | | --- --- | | --- --- || +|| |LL0||HL0| | | |LL0||HL0| | | |LL0||HL0| || +|| --- --- | | --- --- | | --- --- || +|| --- --- | | --- --- | | --- --- || +|| |LH0||HH0| | | |LH0||HH0| | | |LH0||HH0| || +|| --- --- | | --- --- | | --- --- || +|| --- --- | | --- --- | | --- --- || +|| |HL1||LH1| | | |HL1||LH1| | | |HL1||LH1| || +|| --- --- | | --- --- | | --- --- || +|| --- --- | | --- --- | | --- --- || +|| |HH1||HL2| | | |HH1||HL2| | | |HH1||HL2| || +|| ... | | ... | | ... || +| ------------ ------------ ------------ | + -------------------------------------------- + +Decoding process: +================= + + ------------ + | | + | Subbands | + ------------ | | + | | ------------ + | Intra DC | | + | | LL0 subband prediction + ------------ | + \ Dequantizaton + ------------------- \ | +| Reference frames | \ IDWT +| ------- ------- | Motion \ | +||Frame 0| |Frame 1|| Compensation . OBMC v ------- +| ------- ------- | --------------. \------> + --->|Frame n|-->output +| ------- ------- | ------- +||Frame 2| |Frame 3||<----------------------------------/ +| ... | + ------------------- + + Range Coder: ============ + +Binary Range Coder: +------------------- +The implemented range coder is an adapted version based upon "Range encoding: +an algorithm for removing redundancy from a digitised message." by G. N. N. +Martin. +The symbols encoded by the Snow range coder are bits (0|1). The +associated probabilities are not fix but change depending on the symbol mix +seen so far. + + +bit seen | new state +---------+----------------------------------------------- + 0 | 256 - state_transition_table[256 - old_state]; + 1 | state_transition_table[ old_state]; + +state_transition_table = { + 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, + 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, + 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, + 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, +104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, +119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, +134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, +150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, +165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, +180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, +195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, +210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, +226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, +241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0}; + FIXME + +Range Coding of integers: +------------------------- +FIXME + + Neighboring Blocks: =================== left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block -top-left is set to the top left block unless its outside of the image in +top-left is set to the top left block unless it is outside of the image in which case it is set to the left block -if this block has no larger parent block or its at the left side of its +if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used @@ -215,15 +387,129 @@ Intra DC Predicton: the luma and chroma values of the left block are used as predictors the used luma and chroma is the sum of the predictor and y_diff, cb_diff, cr_diff +to reverse this in the decoder apply the following: +block[y][x].dc[0] = block[y][x-1].dc[0] + y_diff; +block[y][x].dc[1] = block[y][x-1].dc[1] + cb_diff; +block[y][x].dc[2] = block[y][x-1].dc[2] + cr_diff; +block[*][-1].dc[*]= 128; Motion Compensation: ==================== + +Halfpel interpolation: +---------------------- +halfpel interpolation is done by convolution with the halfpel filter stored +in the header: + +horizontal halfpel samples are found by +H1[y][x] = hcoeff[0]*(F[y][x ] + F[y][x+1]) + + hcoeff[1]*(F[y][x-1] + F[y][x+2]) + + hcoeff[2]*(F[y][x-2] + F[y][x+3]) + + ... +h1[y][x] = (H1[y][x] + 32)>>6; + +vertical halfpel samples are found by +H2[y][x] = hcoeff[0]*(F[y ][x] + F[y+1][x]) + + hcoeff[1]*(F[y-1][x] + F[y+2][x]) + + ... +h2[y][x] = (H2[y][x] + 32)>>6; + +vertical+horizontal halfpel samples are found by +H3[y][x] = hcoeff[0]*(H2[y][x ] + H2[y][x+1]) + + hcoeff[1]*(H2[y][x-1] + H2[y][x+2]) + + ... +H3[y][x] = hcoeff[0]*(H1[y ][x] + H1[y+1][x]) + + hcoeff[1]*(H1[y+1][x] + H1[y+2][x]) + + ... +h3[y][x] = (H3[y][x] + 2048)>>12; + + + F H1 F + | | | + | | | + | | | + F H1 F + | | | + | | | + | | | + F-------F-------F-> H1<-F-------F-------F + v v v + H2 H3 H2 + ^ ^ ^ + F-------F-------F-> H1<-F-------F-------F + | | | + | | | + | | | + F H1 F + | | | + | | | + | | | + F H1 F + + +unavailable fullpel samples (outside the picture for example) shall be equal +to the closest available fullpel sample + + +Smaller pel interpolation: +-------------------------- +if diag_mc is set then points which lie on a line between 2 vertically, +horiziontally or diagonally adjacent halfpel points shall be interpolated +linearls with rounding to nearest and halfway values rounded up. +points which lie on 2 diagonals at the same time should only use the one +diagonal not containing the fullpel point + + + + F-->O---q---O<--h1->O---q---O<--F + v \ / v \ / v + O O O O O O O + | / | \ | + q q q q q + | / | \ | + O O O O O O O + ^ / \ ^ / \ ^ + h2-->O---q---O<--h3->O---q---O<--h2 + v \ / v \ / v + O O O O O O O + | \ | / | + q q q q q + | \ | / | + O O O O O O O + ^ / \ ^ / \ ^ + F-->O---q---O<--h1->O---q---O<--F + + + +the remaining points shall be bilinearly interpolated from the +up to 4 surrounding halfpel and fullpel points, again rounding should be to +nearest and halfway values rounded up + +compliant Snow decoders MUST support 1-1/8 pel luma and 1/2-1/16 pel chroma +interpolation at least + + +Overlapped block motion compensation: +------------------------------------- FIXME LL band prediction: =================== -FIXME +Each sample in the LL0 subband is predicted by the median of the left, top and +left+top-topleft samples, samples outside the subband shall be considered to +be 0. To reverse this prediction in the decoder apply the following. +for(y=0; y<height; y++){ + for(x=0; x<width; x++){ + sample[y][x] += median(sample[y-1][x], + sample[y][x-1], + sample[y-1][x]+sample[y][x-1]-sample[y-1][x-1]); + } +} +sample[-1][*]=sample[*][-1]= 0; +width,height here are the width and height of the LL0 subband not of the final +video + Dequantizaton: ============== @@ -231,20 +517,105 @@ FIXME Wavelet Transform: ================== -FIXME + +Snow supports 2 wavelet transforms, the symmetric biorthogonal 5/3 integer +transform and a integer approximation of the symmetric biorthogonal 9/7 +daubechies wavelet. + +2D IDWT (inverse discrete wavelet transform) +-------------------------------------------- +The 2D IDWT applies a 2D filter recursively, each time combining the +4 lowest frequency subbands into a single subband until only 1 subband +remains. +The 2D filter is done by first applying a 1D filter in the vertical direction +and then applying it in the horizontal one. + --------------- --------------- --------------- --------------- +|LL0|HL0| | | | | | | | | | | | +|---+---| HL1 | | L0|H0 | HL1 | | LL1 | HL1 | | | | +|LH0|HH0| | | | | | | | | | | | +|-------+-------|->|-------+-------|->|-------+-------|->| L1 | H1 |->... +| | | | | | | | | | | | +| LH1 | HH1 | | LH1 | HH1 | | LH1 | HH1 | | | | +| | | | | | | | | | | | + --------------- --------------- --------------- --------------- + + +1D Filter: +---------- +1. interleave the samples of the low and high frequency subbands like +s={L0, H0, L1, H1, L2, H2, L3, H3, ... } +note, this can end with a L or a H, the number of elements shall be w +s[-1] shall be considered equivalent to s[1 ] +s[w ] shall be considered equivalent to s[w-2] + +2. perform the lifting steps in order as described below + +5/3 Integer filter: +1. s[i] -= (s[i-1] + s[i+1] + 2)>>2; for all even i < w +2. s[i] += (s[i-1] + s[i+1] )>>1; for all odd i < w + +\ | /|\ | /|\ | /|\ | /|\ + \|/ | \|/ | \|/ | \|/ | + + | + | + | + | -1/4 + /|\ | /|\ | /|\ | /|\ | +/ | \|/ | \|/ | \|/ | \|/ + | + | + | + | + +1/2 + + +Snow's 9/7 Integer filter: +1. s[i] -= (3*(s[i-1] + s[i+1]) + 4)>>3; for all even i < w +2. s[i] -= s[i-1] + s[i+1] ; for all odd i < w +3. s[i] += ( s[i-1] + s[i+1] + 4*s[i] + 8)>>4; for all even i < w +4. s[i] += (3*(s[i-1] + s[i+1]) )>>1; for all odd i < w + +\ | /|\ | /|\ | /|\ | /|\ + \|/ | \|/ | \|/ | \|/ | + + | + | + | + | -3/8 + /|\ | /|\ | /|\ | /|\ | +/ | \|/ | \|/ | \|/ | \|/ + (| + (| + (| + (| + -1 +\ + /|\ + /|\ + /|\ + /|\ +1/4 + \|/ | \|/ | \|/ | \|/ | + + | + | + | + | +1/16 + /|\ | /|\ | /|\ | /|\ | +/ | \|/ | \|/ | \|/ | \|/ + | + | + | + | + +3/2 + +optimization tips: +following are exactly identical +(3a)>>1 == a + (a>>1) +(a + 4b + 8)>>4 == ((a>>2) + b + 2)>>2 + +16bit implementation note: +The IDWT can be implemented with 16bits, but this requires some care to +prevent overflows, the following list, lists the minimum number of bits needed +for some terms +1. lifting step +A= s[i-1] + s[i+1] 16bit +3*A + 4 18bit +A + (A>>1) + 2 17bit + +3. lifting step +s[i-1] + s[i+1] 17bit + +4. lifiting step +3*(s[i-1] + s[i+1]) 17bit + TODO: ===== Important: finetune initial contexts -spatial_decomposition_count per frame? flip wavelet? try to use the wavelet transformed predicted image (motion compensated image) as context for coding the residual coefficients try the MV length as context for coding the residual coefficients use extradata for stuff which is in the keyframes now? the MV median predictor is patented IIRC +implement per picture halfpel interpolation +try different range coder state transition tables for different contexts Not Important: +compare the 6 tap and 8 tap hpel filters (psnr/bitrate and subjective quality) spatial_scalability b vs u (!= 0 breaks syntax anyway so we can add a u later) diff --git a/contrib/ffmpeg/ffinstall.nsi b/contrib/ffmpeg/ffinstall.nsi index f483b0174..d3198a04e 100644 --- a/contrib/ffmpeg/ffinstall.nsi +++ b/contrib/ffmpeg/ffinstall.nsi @@ -32,7 +32,7 @@ Section "Install" File ".\ffplay.exe" File ".\COPYING" File ".\CREDITS" - + ; documentation SetOutPath $INSTDIR\doc File ".\doc\faq.html" @@ -58,7 +58,7 @@ Section Uninstall Delete "$INSTDIR\ffplay.exe" Delete "$INSTDIR\COPYING" Delete "$INSTDIR\CREDITS" - + ; delete documentation Delete "$INSTDIR\doc\faq.html" Delete "$INSTDIR\ffmpeg-doc.html" diff --git a/contrib/ffmpeg/ffmpeg.c b/contrib/ffmpeg/ffmpeg.c index c9bac5de6..3fe9992c6 100644 --- a/contrib/ffmpeg/ffmpeg.c +++ b/contrib/ffmpeg/ffmpeg.c @@ -18,29 +18,37 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#define HAVE_AV_CONFIG_H + +#include "config.h" +#include <ctype.h> +#include <string.h> +#include <math.h> +#include <stdlib.h> +#include <errno.h> #include <signal.h> #include <limits.h> #include "avformat.h" +#include "avdevice.h" #include "swscale.h" #include "framehook.h" #include "opt.h" #include "fifo.h" +#include "avstring.h" +#include "os_support.h" -#ifdef __MINGW32__ -#include <conio.h> -#else +#if !defined(HAVE_GETRUSAGE) && defined(HAVE_GETPROCESSTIMES) +#include <windows.h> +#endif + +#if defined(HAVE_TERMIOS_H) #include <unistd.h> #include <fcntl.h> #include <sys/ioctl.h> #include <sys/time.h> #include <termios.h> #include <sys/resource.h> -#endif -#ifdef CONFIG_OS2 -#include <sys/types.h> -#include <sys/select.h> -#include <stdlib.h> +#elif defined(HAVE_CONIO_H) +#include <conio.h> #endif #undef time //needed because HAVE_AV_CONFIG_H is defined on top #include <time.h> @@ -57,6 +65,9 @@ #undef exit +static const char program_name[] = "FFmpeg"; +static const int program_birth_year = 2000; + /* select an input stream for an output stream */ typedef struct AVStreamMap { int file_index; @@ -73,10 +84,6 @@ typedef struct AVMetaDataMap { extern const OptionDef options[]; -static void show_help(void); -static void show_license(void); -static int opt_default(const char *opt, const char *arg); - #define MAX_FILES 20 static AVFormatContext *input_files[MAX_FILES]; @@ -108,8 +115,7 @@ static int frame_bottomBand = 0; static int frame_leftBand = 0; static int frame_rightBand = 0; static int max_frames[4] = {INT_MAX, INT_MAX, INT_MAX, INT_MAX}; -static int frame_rate = 25; -static int frame_rate_base = 1; +static AVRational frame_rate = (AVRational) {0,0}; static float video_qscale = 0; static int video_qdiff = 3; static uint16_t *intra_matrix = NULL; @@ -119,12 +125,10 @@ static float video_rc_qsquish=1.0; static float video_rc_qmod_amp=0; static int video_rc_qmod_freq=0; #endif -static char *video_rc_override_string=NULL; -static char *video_rc_eq="tex^qComp"; -static int me_method = ME_EPZS; +static const char *video_rc_override_string=NULL; static int video_disable = 0; static int video_discard = 0; -static int video_codec_id = CODEC_ID_NONE; +static char *video_codec_name = NULL; static int video_codec_tag = 0; static int same_quality = 0; static int do_deinterlace = 0; @@ -142,11 +146,12 @@ static int audio_sample_rate = 44100; static float audio_qscale = QSCALE_NONE; static int audio_disable = 0; static int audio_channels = 1; -static int audio_codec_id = CODEC_ID_NONE; +static char *audio_codec_name = NULL; static int audio_codec_tag = 0; static char *audio_language = NULL; -static int subtitle_codec_id = CODEC_ID_NONE; +static int subtitle_disable = 0; +static char *subtitle_codec_name = NULL; static char *subtitle_language = NULL; static float mux_preload= 0.5; @@ -161,12 +166,12 @@ static char *str_title = NULL; static char *str_author = NULL; static char *str_copyright = NULL; static char *str_comment = NULL; +static char *str_genre = NULL; static char *str_album = NULL; static int do_benchmark = 0; static int do_hex_dump = 0; static int do_pkt_dump = 0; static int do_psnr = 0; -static int do_vstats = 0; static int do_pass = 0; static char *pass_logfilename = NULL; static int audio_stream_copy = 0; @@ -174,14 +179,18 @@ static int video_stream_copy = 0; static int subtitle_stream_copy = 0; static int video_sync_method= 1; static int audio_sync_method= 0; +static float audio_drift_threshold= 0.1; static int copy_ts= 0; static int opt_shortest = 0; // static int video_global_header = 0; +static char *vstats_filename; +static FILE *vstats_file; +static int opt_programid = 0; static int rate_emu = 0; static int video_channel = 0; -static char *video_standard = "ntsc"; +static char *video_standard; static int audio_volume = 256; @@ -199,18 +208,20 @@ static int input_sync; static uint64_t limit_filesize = 0; // static int pgmyuv_compatibility_hack=0; -static int dts_delta_threshold = 10; +static float dts_delta_threshold = 10; static int sws_flags = SWS_BICUBIC; -const char **opt_names=NULL; -int opt_name_count=0; -AVCodecContext *avctx_opts[CODEC_TYPE_NB]; -AVFormatContext *avformat_opts; -static int64_t timer_start = 0; +static const char **opt_names; +static int opt_name_count; +static AVCodecContext *avctx_opts[CODEC_TYPE_NB]; +static AVFormatContext *avformat_opts; +static struct SwsContext *sws_opts; +static int64_t timer_start; static AVBitStreamFilterContext *video_bitstream_filters=NULL; static AVBitStreamFilterContext *audio_bitstream_filters=NULL; +static AVBitStreamFilterContext *subtitle_bitstream_filters=NULL; static AVBitStreamFilterContext *bitstream_filters[MAX_FILES][MAX_STREAMS]; #define DEFAULT_PASS_LOGFILENAME "ffmpeg2pass" @@ -275,7 +286,7 @@ typedef struct AVInputFile { int nb_streams; /* nb streams we are aware of */ } AVInputFile; -#ifndef __MINGW32__ +#ifdef HAVE_TERMIOS_H /* init terminal so that we can grab keys */ static struct termios oldtty; @@ -283,7 +294,7 @@ static struct termios oldtty; static void term_exit(void) { -#ifndef __MINGW32__ +#ifdef HAVE_TERMIOS_H tcsetattr (0, TCSANOW, &oldtty); #endif } @@ -299,7 +310,7 @@ sigterm_handler(int sig) static void term_init(void) { -#ifndef __MINGW32__ +#ifdef HAVE_TERMIOS_H struct termios tty; tcgetattr (0, &tty); @@ -332,10 +343,7 @@ static void term_init(void) /* read a key without blocking */ static int read_key(void) { -#ifdef __MINGW32__ - if(kbhit()) - return(getch()); -#else +#if defined(HAVE_TERMIOS_H) int n = 1; unsigned char ch; #ifndef CONFIG_BEOS_NETSERVER @@ -355,6 +363,9 @@ static int read_key(void) return n; } +#elif defined(HAVE_CONIO_H) + if(kbhit()) + return(getch()); #endif return -1; } @@ -393,26 +404,37 @@ static double get_sync_ipts(const AVOutputStream *ost) { const AVInputStream *ist = ost->sync_ist; - return (double)(ist->pts + input_files_ts_offset[ist->file_index] - start_time)/AV_TIME_BASE; + return (double)(ist->pts - start_time)/AV_TIME_BASE; } static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx, AVBitStreamFilterContext *bsfc){ + int ret; + while(bsfc){ AVPacket new_pkt= *pkt; int a= av_bitstream_filter_filter(bsfc, avctx, NULL, &new_pkt.data, &new_pkt.size, pkt->data, pkt->size, pkt->flags & PKT_FLAG_KEY); - if(a){ + if(a>0){ av_free_packet(pkt); new_pkt.destruct= av_destruct_packet; + } else if(a<0){ + fprintf(stderr, "%s failed for stream %d, codec %s", + bsfc->filter->name, pkt->stream_index, + avctx->codec ? avctx->codec->name : "copy"); + print_error("", a); } *pkt= new_pkt; bsfc= bsfc->next; } - av_interleaved_write_frame(s, pkt); + ret= av_interleaved_write_frame(s, pkt); + if(ret < 0){ + print_error("av_interleaved_write_frame()", ret); + exit(1); + } } #define MAX_AUDIO_PACKET_SIZE (128 * 1024) @@ -429,6 +451,7 @@ static void do_audio_out(AVFormatContext *s, int size_out, frame_bytes, ret; AVCodecContext *enc= ost->st->codec; + AVCodecContext *dec= ist->st->codec; /* SC: dynamic allocation of buffers */ if (!audio_buf) @@ -438,6 +461,20 @@ static void do_audio_out(AVFormatContext *s, if (!audio_buf || !audio_out) return; /* Should signal an error ! */ + if (enc->channels != dec->channels) + ost->audio_resample = 1; + + if (ost->audio_resample && !ost->resample) { + ost->resample = audio_resample_init(enc->channels, dec->channels, + enc->sample_rate, dec->sample_rate); + if (!ost->resample) { + fprintf(stderr, "Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n", + dec->channels, dec->sample_rate, + enc->channels, enc->sample_rate); + exit(1); + } + } + if(audio_sync_method){ double delta = get_sync_ipts(ost) * enc->sample_rate - ost->sync_opts - av_fifo_size(&ost->fifo)/(ost->st->codec->channels * 2); @@ -446,7 +483,7 @@ static void do_audio_out(AVFormatContext *s, //FIXME resample delay if(fabs(delta) > 50){ - if(ist->is_start){ + if(ist->is_start || fabs(delta) > audio_drift_threshold*enc->sample_rate){ if(byte_delta < 0){ byte_delta= FFMAX(byte_delta, -size); size += byte_delta; @@ -499,6 +536,7 @@ static void do_audio_out(AVFormatContext *s, /* now encode as many frames as possible */ if (enc->frame_size > 1) { /* output resampled raw samples */ + av_fifo_realloc(&ost->fifo, av_fifo_size(&ost->fifo) + size_out + 1); av_fifo_write(&ost->fifo, buftmp, size_out); frame_bytes = enc->frame_size * 2 * enc->channels; @@ -507,6 +545,8 @@ static void do_audio_out(AVFormatContext *s, AVPacket pkt; av_init_packet(&pkt); + //FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio() + ret = avcodec_encode_audio(enc, audio_out, audio_out_size, (short *)audio_buf); audio_size += ret; @@ -551,6 +591,7 @@ static void do_audio_out(AVFormatContext *s, size_out = size_out >> 1; break; } + //FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio() ret = avcodec_encode_audio(enc, audio_out, size_out, (short *)buftmp); audio_size += ret; @@ -601,8 +642,9 @@ static void pre_process_video_frame(AVInputStream *ist, AVPicture *picture, void picture2 = picture; } - frame_hook_process(picture2, dec->pix_fmt, dec->width, dec->height, - 1000000 * ist->pts / AV_TIME_BASE); + if (ENABLE_VHOOK) + frame_hook_process(picture2, dec->pix_fmt, dec->width, dec->height, + 1000000 * ist->pts / AV_TIME_BASE); if (picture != picture2) *picture = *picture2; @@ -651,7 +693,7 @@ static void do_subtitle_out(AVFormatContext *s, pkt.stream_index = ost->index; pkt.data = subtitle_out; pkt.size = subtitle_out_size; - pkt.pts = av_rescale_q(av_rescale_q(pts, ist->st->time_base, AV_TIME_BASE_Q) + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ost->st->time_base); + pkt.pts = av_rescale_q(pts, ist->st->time_base, ost->st->time_base); if (enc->codec_id == CODEC_ID_DVB_SUBTITLE) { /* XXX: the pts correction is handled here. Maybe handling it in the codec would be better */ @@ -695,6 +737,8 @@ static void do_video_out(AVFormatContext *s, //FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c if (vdelta < -1.1) nb_frames = 0; + else if (video_sync_method == 2) + ost->sync_opts= lrintf(get_sync_ipts(ost) / av_q2d(enc->time_base)); else if (vdelta > 1.1) nb_frames = lrintf(vdelta); //fprintf(stderr, "vdelta:%f, ost->sync_opts:%"PRId64", ost->sync_ipts:%f nb_frames:%d\n", vdelta, ost->sync_opts, ost->sync_ipts, nb_frames); @@ -765,10 +809,8 @@ static void do_video_out(AVFormatContext *s, enc->coded_frame = dec->coded_frame; //FIXME/XXX remove this hack pkt.data= (uint8_t *)final_picture; pkt.size= sizeof(AVPicture); - if(dec->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE) - pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base); - if(dec->coded_frame && dec->coded_frame->key_frame) - pkt.flags |= PKT_FLAG_KEY; + pkt.pts= av_rescale_q(ost->sync_opts, enc->time_base, ost->st->time_base); + pkt.flags |= PKT_FLAG_KEY; write_frame(s, &pkt, ost->st->codec, bitstream_filters[ost->file_index][pkt.stream_index]); enc->coded_frame = old_frame; @@ -841,37 +883,27 @@ static double psnr(double d){ static void do_video_stats(AVFormatContext *os, AVOutputStream *ost, int frame_size) { - static FILE *fvstats=NULL; - char filename[40]; - time_t today2; - struct tm *today; AVCodecContext *enc; int frame_number; - int64_t ti; double ti1, bitrate, avg_bitrate; - if (!fvstats) { - today2 = time(NULL); - today = localtime(&today2); - snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, - today->tm_min, - today->tm_sec); - fvstats = fopen(filename,"w"); - if (!fvstats) { + /* this is executed just the first time do_video_stats is called */ + if (!vstats_file) { + vstats_file = fopen(vstats_filename, "w"); + if (!vstats_file) { perror("fopen"); exit(1); } } - ti = INT64_MAX; enc = ost->st->codec; if (enc->codec_type == CODEC_TYPE_VIDEO) { frame_number = ost->frame_number; - fprintf(fvstats, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality/(float)FF_QP2LAMBDA); + fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality/(float)FF_QP2LAMBDA); if (enc->flags&CODEC_FLAG_PSNR) - fprintf(fvstats, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0]/(enc->width*enc->height*255.0*255.0))); + fprintf(vstats_file, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0]/(enc->width*enc->height*255.0*255.0))); - fprintf(fvstats,"f_size= %6d ", frame_size); + fprintf(vstats_file,"f_size= %6d ", frame_size); /* compute pts value */ ti1 = ost->sync_opts * av_q2d(enc->time_base); if (ti1 < 0.01) @@ -879,9 +911,9 @@ static void do_video_stats(AVFormatContext *os, AVOutputStream *ost, bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0; avg_bitrate = (double)(video_size * 8) / ti1 / 1000.0; - fprintf(fvstats, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", + fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", (double)video_size / 1024, ti1, bitrate, avg_bitrate); - fprintf(fvstats,"type= %c\n", av_get_pict_type_char(enc->coded_frame->pict_type)); + fprintf(vstats_file,"type= %c\n", av_get_pict_type_char(enc->coded_frame->pict_type)); } } @@ -915,7 +947,9 @@ static void print_report(AVFormatContext **output_files, oc = output_files[0]; - total_size = url_ftell(&oc->pb); + total_size = url_fsize(oc->pb); + if(total_size<0) // FIXME improve url_fsize() so it works with non seekable output too + total_size= url_ftell(oc->pb); buf[0] = '\0'; ti1 = 1e10; @@ -926,7 +960,8 @@ static void print_report(AVFormatContext **output_files, enc = ost->st->codec; if (vid && enc->codec_type == CODEC_TYPE_VIDEO) { snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "q=%2.1f ", - enc->coded_frame->quality/(float)FF_QP2LAMBDA); + enc->coded_frame && !ost->st->stream_copy ? + enc->coded_frame->quality/(float)FF_QP2LAMBDA : -1); } if (!vid && enc->codec_type == CODEC_TYPE_VIDEO) { float t = (av_gettime()-timer_start) / 1000000.0; @@ -934,7 +969,8 @@ static void print_report(AVFormatContext **output_files, frame_number = ost->frame_number; snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "frame=%5d fps=%3d q=%3.1f ", frame_number, (t>1)?(int)(frame_number/t+0.5) : 0, - enc->coded_frame ? enc->coded_frame->quality/(float)FF_QP2LAMBDA : -1); + enc->coded_frame && !ost->st->stream_copy ? + enc->coded_frame->quality/(float)FF_QP2LAMBDA : -1); if(is_last_report) snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "L"); if(qp_hist && enc->coded_frame){ @@ -969,7 +1005,7 @@ static void print_report(AVFormatContext **output_files, vid = 1; } /* compute min output value */ - pts = (double)ost->st->pts.val * ost->st->time_base.num / ost->st->time_base.den; + pts = (double)ost->st->pts.val * av_q2d(ost->st->time_base); if ((pts < ti1) && (pts > 0)) ti1 = pts; } @@ -1023,13 +1059,8 @@ static int output_packet(AVInputStream *ist, int ist_index, AVSubtitle subtitle, *subtitle_to_free; int got_subtitle; - if(!pkt){ - ist->pts= ist->next_pts; // needed for last packet if vsync=0 - } else if (pkt->dts != AV_NOPTS_VALUE) { //FIXME seems redundant, as libavformat does this too - ist->next_pts = ist->pts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q); - } else { -// assert(ist->pts == ist->next_pts); - } + if(ist->next_pts == AV_NOPTS_VALUE) + ist->next_pts= ist->pts; if (pkt == NULL) { /* EOF handling */ @@ -1038,10 +1069,18 @@ static int output_packet(AVInputStream *ist, int ist_index, goto handle_eof; } + if(pkt->dts != AV_NOPTS_VALUE) + ist->next_pts = ist->pts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q); + len = pkt->size; ptr = pkt->data; while (len > 0) { handle_eof: + ist->pts= ist->next_pts; + + if(len && len != pkt->size && verbose>0) + fprintf(stderr, "Multiple frames in a packet from stream %d\n", pkt->stream_index); + /* decode the packet if needed */ data_buf = NULL; /* fail safe */ data_size = 0; @@ -1109,7 +1148,7 @@ static int output_packet(AVInputStream *ist, int ist_index, switch(ist->st->codec->codec_type) { case CODEC_TYPE_AUDIO: ist->next_pts += ((int64_t)AV_TIME_BASE * ist->st->codec->frame_size) / - (ist->st->codec->sample_rate * ist->st->codec->channels); + ist->st->codec->sample_rate; break; case CODEC_TYPE_VIDEO: if (ist->st->codec->time_base.num != 0) { @@ -1195,7 +1234,7 @@ static int output_packet(AVInputStream *ist, int ist_index, case CODEC_TYPE_VIDEO: do_video_out(os, ost, ist, &picture, &frame_size); video_size += frame_size; - if (do_vstats && frame_size) + if (vstats_filename && frame_size) do_video_stats(os, ost, frame_size); break; case CODEC_TYPE_SUBTITLE: @@ -1203,13 +1242,16 @@ static int output_packet(AVInputStream *ist, int ist_index, pkt->pts); break; default: - av_abort(); + abort(); } } else { AVFrame avframe; //FIXME/XXX remove this AVPacket opkt; av_init_packet(&opkt); + if (!ost->frame_number && !(pkt->flags & PKT_FLAG_KEY)) + continue; + /* no reencoding needed : output the packet directly */ /* force the input stream PTS */ @@ -1226,25 +1268,23 @@ static int output_packet(AVInputStream *ist, int ist_index, opkt.stream_index= ost->index; if(pkt->pts != AV_NOPTS_VALUE) - opkt.pts= av_rescale_q(av_rescale_q(pkt->pts, ist->st->time_base, AV_TIME_BASE_Q) + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ost->st->time_base); + opkt.pts= av_rescale_q(pkt->pts, ist->st->time_base, ost->st->time_base); else opkt.pts= AV_NOPTS_VALUE; - { - int64_t dts; if (pkt->dts == AV_NOPTS_VALUE) - dts = ist->next_pts; + opkt.dts = av_rescale_q(ist->next_pts, AV_TIME_BASE_Q, ost->st->time_base); else - dts= av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q); - opkt.dts= av_rescale_q(dts + input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ost->st->time_base); - } + opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->st->time_base); + + opkt.duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->st->time_base); opkt.flags= pkt->flags; //FIXME remove the following 2 lines they shall be replaced by the bitstream filters if(av_parser_change(ist->st->parser, ost->st->codec, &opkt.data, &opkt.size, data_buf, data_size, pkt->flags & PKT_FLAG_KEY)) opkt.destruct= av_destruct_packet; - write_frame(os, &opkt, ost->st->codec, bitstream_filters[ost->file_index][pkt->stream_index]); + write_frame(os, &opkt, ost->st->codec, bitstream_filters[ost->file_index][opkt.stream_index]); ost->st->codec->frame_number++; ost->frame_number++; av_free_packet(&opkt); @@ -1337,6 +1377,39 @@ static int output_packet(AVInputStream *ist, int ist_index, return -1; } +static void print_sdp(AVFormatContext **avc, int n) +{ + char sdp[2048]; + + avf_sdp_create(avc, n, sdp, sizeof(sdp)); + printf("SDP:\n%s\n", sdp); +} + +static int stream_index_from_inputs(AVFormatContext **input_files, + int nb_input_files, + AVInputFile *file_table, + AVInputStream **ist_table, + enum CodecType type, + int programid) +{ + int p, q, z; + for(z=0; z<nb_input_files; z++) { + AVFormatContext *ic = input_files[z]; + for(p=0; p<ic->nb_programs; p++) { + AVProgram *program = ic->programs[p]; + if(program->id != programid) + continue; + for(q=0; q<program->nb_stream_indexes; q++) { + int sidx = program->stream_index[q]; + int ris = file_table[z].ist_index + sidx; + if(ist_table[ris]->discard && ic->streams[sidx]->codec->codec_type == type) + return ris; + } + } + } + + return -1; +} /* * The following code is the main loop of the file converter @@ -1354,8 +1427,9 @@ static int av_encode(AVFormatContext **output_files, AVInputStream *ist, **ist_table = NULL; AVInputFile *file_table; int key; + int want_sdp = 1; - file_table= (AVInputFile*) av_mallocz(nb_input_files * sizeof(AVInputFile)); + file_table= av_mallocz(nb_input_files * sizeof(AVInputFile)); if (!file_table) goto fail; @@ -1463,25 +1537,36 @@ static int av_encode(AVFormatContext **output_files, } } else { - /* get corresponding input stream index : we select the first one with the right type */ - found = 0; - for(j=0;j<nb_istreams;j++) { - ist = ist_table[j]; - if (ist->discard && - ist->st->codec->codec_type == ost->st->codec->codec_type) { + if(opt_programid) { + found = 0; + j = stream_index_from_inputs(input_files, nb_input_files, file_table, ist_table, ost->st->codec->codec_type, opt_programid); + if(j != -1) { ost->source_index = j; found = 1; - break; } - } - - if (!found) { - /* try again and reuse existing stream */ + } else { + /* get corresponding input stream index : we select the first one with the right type */ + found = 0; for(j=0;j<nb_istreams;j++) { ist = ist_table[j]; - if (ist->st->codec->codec_type == ost->st->codec->codec_type) { + if (ist->discard && + ist->st->codec->codec_type == ost->st->codec->codec_type) { ost->source_index = j; found = 1; + break; + } + } + } + + if (!found) { + if(! opt_programid) { + /* try again and reuse existing stream */ + for(j=0;j<nb_istreams;j++) { + ist = ist_table[j]; + if (ist->st->codec->codec_type == ost->st->codec->codec_type) { + ost->source_index = j; + found = 1; + } } } if (!found) { @@ -1502,16 +1587,28 @@ static int av_encode(AVFormatContext **output_files, /* for each output stream, we compute the right encoding parameters */ for(i=0;i<nb_ostreams;i++) { ost = ost_table[i]; + os = output_files[ost->file_index]; ist = ist_table[ost->source_index]; codec = ost->st->codec; icodec = ist->st->codec; + if (!ost->st->language[0]) + av_strlcpy(ost->st->language, ist->st->language, + sizeof(ost->st->language)); + if (ost->st->stream_copy) { /* if stream_copy is selected, no need to decode or encode */ codec->codec_id = icodec->codec_id; codec->codec_type = icodec->codec_type; - if(!codec->codec_tag) codec->codec_tag = icodec->codec_tag; + + if(!codec->codec_tag){ + if( !os->oformat->codec_tag + || av_codec_get_id (os->oformat->codec_tag, icodec->codec_tag) > 0 + || av_codec_get_tag(os->oformat->codec_tag, icodec->codec_id) <= 0) + codec->codec_tag = icodec->codec_tag; + } + codec->bit_rate = icodec->bit_rate; codec->extradata= icodec->extradata; codec->extradata_size= icodec->extradata_size; @@ -1525,6 +1622,8 @@ static int av_encode(AVFormatContext **output_files, codec->channels = icodec->channels; codec->frame_size = icodec->frame_size; codec->block_align= icodec->block_align; + if(codec->block_align == 1 && codec->codec_id == CODEC_ID_MP3) + codec->block_align= 0; break; case CODEC_TYPE_VIDEO: if(using_vhook) { @@ -1539,45 +1638,15 @@ static int av_encode(AVFormatContext **output_files, case CODEC_TYPE_SUBTITLE: break; default: - av_abort(); + abort(); } } else { switch(codec->codec_type) { case CODEC_TYPE_AUDIO: - if (av_fifo_init(&ost->fifo, 2 * MAX_AUDIO_PACKET_SIZE)) + if (av_fifo_init(&ost->fifo, 1024)) goto fail; - - if (codec->channels == icodec->channels && - codec->sample_rate == icodec->sample_rate) { - ost->audio_resample = 0; - } else { - if (codec->channels != icodec->channels && - (icodec->codec_id == CODEC_ID_AC3 || - icodec->codec_id == CODEC_ID_DTS)) { - /* Special case for 5:1 AC3 and DTS input */ - /* and mono or stereo output */ - /* Request specific number of channels */ - icodec->channels = codec->channels; - if (codec->sample_rate == icodec->sample_rate) - ost->audio_resample = 0; - else { - ost->audio_resample = 1; - } - } else { - ost->audio_resample = 1; - } - } - if(audio_sync_method>1) - ost->audio_resample = 1; - - if(ost->audio_resample){ - ost->resample = audio_resample_init(codec->channels, icodec->channels, - codec->sample_rate, icodec->sample_rate); - if(!ost->resample){ - printf("Can't resample. Aborting.\n"); - av_abort(); - } - } + ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1; + icodec->request_channels = codec->channels; ist->decoding_needed = 1; ost->encoding_needed = 1; break; @@ -1614,6 +1683,7 @@ static int av_encode(AVFormatContext **output_files, fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n"); exit(1); } + sws_flags = av_get_int(sws_opts, "sws_flags", NULL); ost->img_resample_ctx = sws_getContext( icodec->width - (frame_leftBand + frame_rightBand), icodec->height - (frame_topBand + frame_bottomBand), @@ -1636,7 +1706,7 @@ static int av_encode(AVFormatContext **output_files, ist->decoding_needed = 1; break; default: - av_abort(); + abort(); break; } /* two pass mode */ @@ -1760,11 +1830,7 @@ static int av_encode(AVFormatContext **output_files, ist = ist_table[i]; is = input_files[ist->file_index]; ist->pts = 0; - ist->next_pts = av_rescale_q(ist->st->start_time, ist->st->time_base, AV_TIME_BASE_Q); - if(ist->st->start_time == AV_NOPTS_VALUE) - ist->next_pts=0; - if(input_files_ts_offset[ist->file_index]) - ist->next_pts= AV_NOPTS_VALUE; + ist->next_pts = AV_NOPTS_VALUE; ist->is_start = 1; } @@ -1807,6 +1873,12 @@ static int av_encode(AVFormatContext **output_files, ret = AVERROR(EINVAL); goto fail; } + if (strcmp(output_files[i]->oformat->name, "rtp")) { + want_sdp = 0; + } + } + if (want_sdp) { + print_sdp(output_files, nb_output_files); } if ( !using_stdin && verbose >= 0) { @@ -1875,14 +1947,17 @@ static int av_encode(AVFormatContext **output_files, break; /* finish if limit size exhausted */ - if (limit_filesize != 0 && limit_filesize < url_ftell(&output_files[0]->pb)) + if (limit_filesize != 0 && limit_filesize < url_ftell(output_files[0]->pb)) break; /* read a frame from it and output it in the fifo */ is = input_files[file_index]; if (av_read_frame(is, &pkt) < 0) { file_table[file_index].eof_reached = 1; - if (opt_shortest) break; else continue; // + if (opt_shortest) + break; + else + continue; } if (do_pkt_dump) { @@ -1897,18 +1972,22 @@ static int av_encode(AVFormatContext **output_files, if (ist->discard) goto discard_packet; + if (pkt.dts != AV_NOPTS_VALUE) + pkt.dts += av_rescale_q(input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ist->st->time_base); + if (pkt.pts != AV_NOPTS_VALUE) + pkt.pts += av_rescale_q(input_files_ts_offset[ist->file_index], AV_TIME_BASE_Q, ist->st->time_base); + // fprintf(stderr, "next:%"PRId64" dts:%"PRId64" off:%"PRId64" %d\n", ist->next_pts, pkt.dts, input_files_ts_offset[ist->file_index], ist->st->codec->codec_type); if (pkt.dts != AV_NOPTS_VALUE && ist->next_pts != AV_NOPTS_VALUE) { - int64_t delta= av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q) - ist->next_pts; - if(FFABS(delta) > 1LL*dts_delta_threshold*AV_TIME_BASE && !copy_ts){ + int64_t pkt_dts= av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q); + int64_t delta= pkt_dts - ist->next_pts; + if((FFABS(delta) > 1LL*dts_delta_threshold*AV_TIME_BASE || pkt_dts+1<ist->pts)&& !copy_ts){ input_files_ts_offset[ist->file_index]-= delta; if (verbose > 2) fprintf(stderr, "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n", delta, input_files_ts_offset[ist->file_index]); - for(i=0; i<file_table[file_index].nb_streams; i++){ - int index= file_table[file_index].ist_index + i; - ist_table[index]->next_pts += delta; - ist_table[index]->is_start=1; - } + pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); + if(pkt.pts != AV_NOPTS_VALUE) + pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); } } @@ -1993,7 +2072,7 @@ static int av_encode(AVFormatContext **output_files, av_free(ost->pict_tmp.data[0]); if (ost->video_resample) sws_freeContext(ost->img_resample_ctx); - if (ost->audio_resample) + if (ost->resample) audio_resample_close(ost->resample); av_free(ost); } @@ -2046,12 +2125,51 @@ static void opt_format(const char *arg) } } -static void opt_video_rc_eq(char *arg) -{ - video_rc_eq = arg; +extern int ffm_nopts; + +static int opt_default(const char *opt, const char *arg){ + int type; + const AVOption *o= NULL; + int opt_types[]={AV_OPT_FLAG_VIDEO_PARAM, AV_OPT_FLAG_AUDIO_PARAM, 0, AV_OPT_FLAG_SUBTITLE_PARAM, 0}; + + for(type=0; type<CODEC_TYPE_NB; type++){ + const AVOption *o2 = av_find_opt(avctx_opts[0], opt, NULL, opt_types[type], opt_types[type]); + if(o2) + o = av_set_string(avctx_opts[type], opt, arg); + } + if(!o) + o = av_set_string(avformat_opts, opt, arg); + if(!o) + o = av_set_string(sws_opts, opt, arg); + if(!o){ + if(opt[0] == 'a') + o = av_set_string(avctx_opts[CODEC_TYPE_AUDIO], opt+1, arg); + else if(opt[0] == 'v') + o = av_set_string(avctx_opts[CODEC_TYPE_VIDEO], opt+1, arg); + else if(opt[0] == 's') + o = av_set_string(avctx_opts[CODEC_TYPE_SUBTITLE], opt+1, arg); + } + if(!o) + return -1; + +// av_log(NULL, AV_LOG_ERROR, "%s:%s: %f 0x%0X\n", opt, arg, av_get_double(avctx_opts, opt, NULL), (int)av_get_int(avctx_opts, opt, NULL)); + + //FIXME we should always use avctx_opts, ... for storing options so there wont be any need to keep track of whats set over this + opt_names= av_realloc(opt_names, sizeof(void*)*(opt_name_count+1)); + opt_names[opt_name_count++]= o->name; + +#if defined(CONFIG_FFM_DEMUXER) || defined(CONFIG_FFM_MUXER) + /* disable generate of real time pts in ffm (need to be supressed anyway) */ + if(avctx_opts[0]->flags & CODEC_FLAG_BITEXACT) + ffm_nopts = 1; +#endif + + if(avctx_opts[0]->debug) + av_log_set_level(AV_LOG_DEBUG); + return 0; } -static void opt_video_rc_override_string(char *arg) +static void opt_video_rc_override_string(const char *arg) { video_rc_override_string = arg; } @@ -2064,17 +2182,29 @@ static void opt_me_threshold(const char *arg) static void opt_verbose(const char *arg) { verbose = atoi(arg); - av_log_level = atoi(arg); + av_log_set_level(verbose); } static void opt_frame_rate(const char *arg) { - if (parse_frame_rate(&frame_rate, &frame_rate_base, arg) < 0) { + if (av_parse_video_frame_rate(&frame_rate, arg) < 0) { fprintf(stderr, "Incorrect frame rate\n"); exit(1); } } +static int opt_bitrate(const char *opt, const char *arg) +{ + int codec_type = opt[0]=='a' ? CODEC_TYPE_AUDIO : CODEC_TYPE_VIDEO; + + opt_default(opt, arg); + + if (av_get_int(avctx_opts[codec_type], "b", NULL) < 1000) + fprintf(stderr, "WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s\n"); + + return 0; +} + static void opt_frame_crop_top(const char *arg) { frame_topBand = atoi(arg); @@ -2149,7 +2279,7 @@ static void opt_frame_crop_right(const char *arg) static void opt_frame_size(const char *arg) { - if (parse_image_size(&frame_width, &frame_height, arg) < 0) { + if (av_parse_video_frame_size(&frame_width, &frame_height, arg) < 0) { fprintf(stderr, "Incorrect frame size\n"); exit(1); } @@ -2245,10 +2375,24 @@ static void opt_frame_pad_right(const char *arg) } } +void list_pix_fmts(void) +{ + int i; + char pix_fmt_str[128]; + for (i=-1; i < PIX_FMT_NB; i++) { + avcodec_pix_fmt_string (pix_fmt_str, sizeof(pix_fmt_str), i); + fprintf(stdout, "%s\n", pix_fmt_str); + } +} static void opt_frame_pix_fmt(const char *arg) { - frame_pix_fmt = avcodec_get_pix_fmt(arg); + if (strcmp(arg, "list")) + frame_pix_fmt = avcodec_get_pix_fmt(arg); + else { + list_pix_fmts(); + exit(0); + } } static void opt_frame_aspect_ratio(const char *arg) @@ -2256,16 +2400,17 @@ static void opt_frame_aspect_ratio(const char *arg) int x = 0, y = 0; double ar = 0; const char *p; + char *end; p = strchr(arg, ':'); if (p) { - x = strtol(arg, (char **)&arg, 10); - if (arg == p) - y = strtol(arg+1, (char **)&arg, 10); + x = strtol(arg, &end, 10); + if (end == p) + y = strtol(end+1, &end, 10); if (x > 0 && y > 0) ar = (double)x / (double)y; } else - ar = strtod(arg, (char **)&arg); + ar = strtod(arg, NULL); if (!ar) { fprintf(stderr, "Incorrect aspect ratio specification.\n"); @@ -2333,32 +2478,20 @@ static void opt_video_standard(const char *arg) video_standard = av_strdup(arg); } -static void opt_codec(int *pstream_copy, int *pcodec_id, +static void opt_codec(int *pstream_copy, char **pcodec_name, int codec_type, const char *arg) { - AVCodec *p; - + av_freep(pcodec_name); if (!strcmp(arg, "copy")) { *pstream_copy = 1; } else { - p = first_avcodec; - while (p) { - if (!strcmp(p->name, arg) && p->type == codec_type) - break; - p = p->next; - } - if (p == NULL) { - fprintf(stderr, "Unknown codec '%s'\n", arg); - exit(1); - } else { - *pcodec_id = p->id; - } + *pcodec_name = av_strdup(arg); } } static void opt_audio_codec(const char *arg) { - opt_codec(&audio_stream_copy, &audio_codec_id, CODEC_TYPE_AUDIO, arg); + opt_codec(&audio_stream_copy, &audio_codec_name, CODEC_TYPE_AUDIO, arg); } static void opt_audio_tag(const char *arg) @@ -2379,6 +2512,7 @@ static void opt_video_tag(const char *arg) video_codec_tag= arg[0] + (arg[1]<<8) + (arg[2]<<16) + (arg[3]<<24); } +#ifdef CONFIG_VHOOK static void add_frame_hooker(const char *arg) { int argc = 0; @@ -2399,65 +2533,36 @@ static void add_frame_hooker(const char *arg) exit(1); } } - -const char *motion_str[] = { - "zero", - "full", - "log", - "phods", - "epzs", - "x1", - "hex", - "umh", - "iter", - NULL, -}; - -static void opt_motion_estimation(const char *arg) -{ - const char **p; - p = motion_str; - for(;;) { - if (!*p) { - fprintf(stderr, "Unknown motion estimation method '%s'\n", arg); - exit(1); - } - if (!strcmp(*p, arg)) - break; - p++; - } - me_method = (p - motion_str) + 1; -} +#endif static void opt_video_codec(const char *arg) { - opt_codec(&video_stream_copy, &video_codec_id, CODEC_TYPE_VIDEO, arg); + opt_codec(&video_stream_copy, &video_codec_name, CODEC_TYPE_VIDEO, arg); } static void opt_subtitle_codec(const char *arg) { - opt_codec(&subtitle_stream_copy, &subtitle_codec_id, CODEC_TYPE_SUBTITLE, arg); + opt_codec(&subtitle_stream_copy, &subtitle_codec_name, CODEC_TYPE_SUBTITLE, arg); } static void opt_map(const char *arg) { AVStreamMap *m; - const char *p; + char *p; - p = arg; m = &stream_maps[nb_stream_maps++]; - m->file_index = strtol(arg, (char **)&p, 0); + m->file_index = strtol(arg, &p, 0); if (*p) p++; - m->stream_index = strtol(p, (char **)&p, 0); + m->stream_index = strtol(p, &p, 0); if (*p) { p++; - m->sync_file_index = strtol(p, (char **)&p, 0); + m->sync_file_index = strtol(p, &p, 0); if (*p) p++; - m->sync_stream_index = strtol(p, (char **)&p, 0); + m->sync_stream_index = strtol(p, &p, 0); } else { m->sync_file_index = m->file_index; m->sync_stream_index = m->stream_index; @@ -2467,36 +2572,67 @@ static void opt_map(const char *arg) static void opt_map_meta_data(const char *arg) { AVMetaDataMap *m; - const char *p; + char *p; - p = arg; m = &meta_data_maps[nb_meta_data_maps++]; - m->out_file = strtol(arg, (char **)&p, 0); + m->out_file = strtol(arg, &p, 0); if (*p) p++; - m->in_file = strtol(p, (char **)&p, 0); + m->in_file = strtol(p, &p, 0); +} + +static int64_t parse_time_or_die(const char *timestr, int is_duration) +{ + int64_t us = parse_date(timestr, is_duration); + if (us == INT64_MIN) { + fprintf(stderr, "Invalid %s specification: %s\n", + is_duration ? "duration" : "date", timestr); + exit(1); + } + return us; } static void opt_recording_time(const char *arg) { - recording_time = parse_date(arg, 1); + recording_time = parse_time_or_die(arg, 1); } static void opt_start_time(const char *arg) { - start_time = parse_date(arg, 1); + start_time = parse_time_or_die(arg, 1); } static void opt_rec_timestamp(const char *arg) { - rec_timestamp = parse_date(arg, 0) / 1000000; + rec_timestamp = parse_time_or_die(arg, 0) / 1000000; } static void opt_input_ts_offset(const char *arg) { - input_ts_offset = parse_date(arg, 1); + input_ts_offset = parse_time_or_die(arg, 1); +} + +static enum CodecID find_codec_or_die(const char *name, int type, int encoder) +{ + const char *codec_string = encoder ? "encoder" : "decoder"; + AVCodec *codec; + + if(!name) + return CODEC_ID_NONE; + codec = encoder ? + avcodec_find_encoder_by_name(name) : + avcodec_find_decoder_by_name(name); + if(!codec) { + av_log(NULL, AV_LOG_ERROR, "Unknown %s '%s'\n", codec_string, name); + exit(1); + } + if(codec->type != type) { + av_log(NULL, AV_LOG_ERROR, "Invalid %s type '%s'\n", codec_string, name); + exit(1); + } + return codec->id; } static void opt_input_file(const char *filename) @@ -2519,30 +2655,42 @@ static void opt_input_file(const char *filename) ap->prealloced_context = 1; ap->sample_rate = audio_sample_rate; ap->channels = audio_channels; - ap->time_base.den = frame_rate; - ap->time_base.num = frame_rate_base; + ap->time_base.den = frame_rate.num; + ap->time_base.num = frame_rate.den; ap->width = frame_width + frame_padleft + frame_padright; ap->height = frame_height + frame_padtop + frame_padbottom; ap->pix_fmt = frame_pix_fmt; ap->channel = video_channel; ap->standard = video_standard; - ap->video_codec_id = video_codec_id; - ap->audio_codec_id = audio_codec_id; + ap->video_codec_id = find_codec_or_die(video_codec_name, CODEC_TYPE_VIDEO, 0); + ap->audio_codec_id = find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 0); if(pgmyuv_compatibility_hack) ap->video_codec_id= CODEC_ID_PGMYUV; for(i=0; i<opt_name_count; i++){ + char buf[256]; const AVOption *opt; - double d= av_get_double(avformat_opts, opt_names[i], &opt); - if(d==d && (opt->flags&AV_OPT_FLAG_DECODING_PARAM)) - av_set_double(ic, opt_names[i], d); + const char *str= av_get_string(avformat_opts, opt_names[i], &opt, buf, sizeof(buf)); + if(str && (opt->flags & AV_OPT_FLAG_DECODING_PARAM)) + av_set_string(ic, opt_names[i], str); } + + ic->video_codec_id = find_codec_or_die(video_codec_name , CODEC_TYPE_VIDEO , 0); + ic->audio_codec_id = find_codec_or_die(audio_codec_name , CODEC_TYPE_AUDIO , 0); + ic->subtitle_codec_id= find_codec_or_die(subtitle_codec_name, CODEC_TYPE_SUBTITLE, 0); + /* open the input file with generic libav function */ err = av_open_input_file(&ic, filename, file_iformat, 0, ap); if (err < 0) { print_error(filename, err); exit(1); } + if(opt_programid) { + int i; + for(i=0; i<ic->nb_programs; i++) + if(ic->programs[i]->id != opt_programid) + ic->programs[i]->discard = AVDISCARD_ALL; + } ic->loop_input = loop_input; @@ -2580,10 +2728,11 @@ static void opt_input_file(const char *filename) switch(enc->codec_type) { case CODEC_TYPE_AUDIO: for(j=0; j<opt_name_count; j++){ + char buf[256]; const AVOption *opt; - double d= av_get_double(avctx_opts[CODEC_TYPE_AUDIO], opt_names[j], &opt); - if(d==d && (opt->flags&AV_OPT_FLAG_AUDIO_PARAM) && (opt->flags&AV_OPT_FLAG_DECODING_PARAM)) - av_set_double(enc, opt_names[j], d); + const char *str= av_get_string(avctx_opts[CODEC_TYPE_AUDIO], opt_names[j], &opt, buf, sizeof(buf)); + if(str && (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) && (opt->flags & AV_OPT_FLAG_DECODING_PARAM)) + av_set_string(enc, opt_names[j], str); } //fprintf(stderr, "\nInput Audio channels: %d", enc->channels); audio_channels = enc->channels; @@ -2593,10 +2742,11 @@ static void opt_input_file(const char *filename) break; case CODEC_TYPE_VIDEO: for(j=0; j<opt_name_count; j++){ + char buf[256]; const AVOption *opt; - double d= av_get_double(avctx_opts[CODEC_TYPE_VIDEO], opt_names[j], &opt); - if(d==d && (opt->flags&AV_OPT_FLAG_VIDEO_PARAM) && (opt->flags&AV_OPT_FLAG_DECODING_PARAM)) - av_set_double(enc, opt_names[j], d); + const char *str= av_get_string(avctx_opts[CODEC_TYPE_VIDEO], opt_names[j], &opt, buf, sizeof(buf)); + if(str && (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) && (opt->flags & AV_OPT_FLAG_DECODING_PARAM)) + av_set_string(enc, opt_names[j], str); } frame_height = enc->height; frame_width = enc->width; @@ -2617,8 +2767,8 @@ static void opt_input_file(const char *filename) (float)rfps / rfps_base, rfps, rfps_base); } /* update the current frame rate to match the stream frame rate */ - frame_rate = rfps; - frame_rate_base = rfps_base; + frame_rate.num = rfps; + frame_rate.den = rfps_base; enc->rate_emu = rate_emu; if(video_disable) @@ -2629,11 +2779,14 @@ static void opt_input_file(const char *filename) case CODEC_TYPE_DATA: break; case CODEC_TYPE_SUBTITLE: + if(subtitle_disable) + ic->streams[i]->discard = AVDISCARD_ALL; break; + case CODEC_TYPE_ATTACHMENT: case CODEC_TYPE_UNKNOWN: break; default: - av_abort(); + abort(); } } @@ -2650,15 +2803,20 @@ static void opt_input_file(const char *filename) video_channel = 0; rate_emu = 0; + av_freep(&video_codec_name); + av_freep(&audio_codec_name); + av_freep(&subtitle_codec_name); } -static void check_audio_video_inputs(int *has_video_ptr, int *has_audio_ptr) +static void check_audio_video_sub_inputs(int *has_video_ptr, int *has_audio_ptr, + int *has_subtitle_ptr) { - int has_video, has_audio, i, j; + int has_video, has_audio, has_subtitle, i, j; AVFormatContext *ic; has_video = 0; has_audio = 0; + has_subtitle = 0; for(j=0;j<nb_input_files;j++) { ic = input_files[j]; for(i=0;i<ic->nb_streams;i++) { @@ -2670,17 +2828,21 @@ static void check_audio_video_inputs(int *has_video_ptr, int *has_audio_ptr) case CODEC_TYPE_VIDEO: has_video = 1; break; + case CODEC_TYPE_SUBTITLE: + has_subtitle = 1; + break; case CODEC_TYPE_DATA: + case CODEC_TYPE_ATTACHMENT: case CODEC_TYPE_UNKNOWN: - case CODEC_TYPE_SUBTITLE: break; default: - av_abort(); + abort(); } } } *has_video_ptr = has_video; *has_audio_ptr = has_audio; + *has_subtitle_ptr = has_subtitle; } static void new_video_stream(AVFormatContext *oc) @@ -2720,33 +2882,34 @@ static void new_video_stream(AVFormatContext *oc) st->stream_copy = 1; video_enc->codec_type = CODEC_TYPE_VIDEO; } else { - char *p; + const char *p; int i; AVCodec *codec; + AVRational fps= frame_rate.num ? frame_rate : (AVRational){25,1}; codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_VIDEO); - if (video_codec_id != CODEC_ID_NONE) - codec_id = video_codec_id; + if (video_codec_name) + codec_id = find_codec_or_die(video_codec_name, CODEC_TYPE_VIDEO, 1); video_enc->codec_id = codec_id; codec = avcodec_find_encoder(codec_id); for(i=0; i<opt_name_count; i++){ - const AVOption *opt; - double d= av_get_double(avctx_opts[CODEC_TYPE_VIDEO], opt_names[i], &opt); - if(d==d && (opt->flags&AV_OPT_FLAG_VIDEO_PARAM) && (opt->flags&AV_OPT_FLAG_ENCODING_PARAM)) - av_set_double(video_enc, opt_names[i], d); + char buf[256]; + const AVOption *opt; + const char *str= av_get_string(avctx_opts[CODEC_TYPE_VIDEO], opt_names[i], &opt, buf, sizeof(buf)); + if(str && (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) && (opt->flags & AV_OPT_FLAG_ENCODING_PARAM)) + av_set_string(video_enc, opt_names[i], str); } - video_enc->time_base.den = frame_rate; - video_enc->time_base.num = frame_rate_base; + video_enc->time_base.den = fps.num; + video_enc->time_base.num = fps.den; if(codec && codec->supported_framerates){ const AVRational *p= codec->supported_framerates; - AVRational req= (AVRational){frame_rate, frame_rate_base}; const AVRational *best=NULL; AVRational best_error= (AVRational){INT_MAX, 1}; for(; p->den!=0; p++){ - AVRational error= av_sub_q(req, *p); + AVRational error= av_sub_q(fps, *p); if(error.num <0) error.num *= -1; if(av_cmp_q(error, best_error) < 0){ best_error= error; @@ -2786,7 +2949,6 @@ static void new_video_stream(AVFormatContext *oc) video_enc->inter_matrix = inter_matrix; video_enc->max_qdiff = video_qdiff; - video_enc->rc_eq = video_rc_eq; video_enc->thread_count = thread_count; p= video_rc_override_string; for(i=0; p; i++){ @@ -2822,8 +2984,6 @@ static void new_video_stream(AVFormatContext *oc) if (do_psnr) video_enc->flags|= CODEC_FLAG_PSNR; - video_enc->me_method = me_method; - /* two pass mode */ if (do_pass) { if (do_pass == 1) { @@ -2836,7 +2996,7 @@ static void new_video_stream(AVFormatContext *oc) /* reset some key parameters */ video_disable = 0; - video_codec_id = CODEC_ID_NONE; + av_freep(&video_codec_name); video_stream_copy = 0; } @@ -2877,14 +3037,15 @@ static void new_audio_stream(AVFormatContext *oc) codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_AUDIO); for(i=0; i<opt_name_count; i++){ + char buf[256]; const AVOption *opt; - double d= av_get_double(avctx_opts[CODEC_TYPE_AUDIO], opt_names[i], &opt); - if(d==d && (opt->flags&AV_OPT_FLAG_AUDIO_PARAM) && (opt->flags&AV_OPT_FLAG_ENCODING_PARAM)) - av_set_double(audio_enc, opt_names[i], d); + const char *str= av_get_string(avctx_opts[CODEC_TYPE_AUDIO], opt_names[i], &opt, buf, sizeof(buf)); + if(str && (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) && (opt->flags & AV_OPT_FLAG_ENCODING_PARAM)) + av_set_string(audio_enc, opt_names[i], str); } - if (audio_codec_id != CODEC_ID_NONE) - codec_id = audio_codec_id; + if (audio_codec_name) + codec_id = find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 1); audio_enc->codec_id = codec_id; if (audio_qscale > QSCALE_NONE) { @@ -2897,30 +3058,23 @@ static void new_audio_stream(AVFormatContext *oc) audio_enc->sample_rate = audio_sample_rate; audio_enc->time_base= (AVRational){1, audio_sample_rate}; if (audio_language) { - pstrcpy(st->language, sizeof(st->language), audio_language); + av_strlcpy(st->language, audio_language, sizeof(st->language)); av_free(audio_language); audio_language = NULL; } /* reset some key parameters */ audio_disable = 0; - audio_codec_id = CODEC_ID_NONE; + av_freep(&audio_codec_name); audio_stream_copy = 0; } -static void opt_new_subtitle_stream(void) +static void new_subtitle_stream(AVFormatContext *oc) { - AVFormatContext *oc; AVStream *st; AVCodecContext *subtitle_enc; int i; - if (nb_output_files <= 0) { - fprintf(stderr, "At least one output file must be specified\n"); - exit(1); - } - oc = output_files[nb_output_files - 1]; - st = av_new_stream(oc, oc->nb_streams); if (!st) { fprintf(stderr, "Could not alloc stream\n"); @@ -2928,27 +3082,32 @@ static void opt_new_subtitle_stream(void) } avcodec_get_context_defaults2(st->codec, CODEC_TYPE_SUBTITLE); + bitstream_filters[nb_output_files][oc->nb_streams - 1]= subtitle_bitstream_filters; + subtitle_bitstream_filters= NULL; + subtitle_enc = st->codec; subtitle_enc->codec_type = CODEC_TYPE_SUBTITLE; if (subtitle_stream_copy) { st->stream_copy = 1; } else { for(i=0; i<opt_name_count; i++){ - const AVOption *opt; - double d= av_get_double(avctx_opts[CODEC_TYPE_SUBTITLE], opt_names[i], &opt); - if(d==d && (opt->flags&AV_OPT_FLAG_SUBTITLE_PARAM) && (opt->flags&AV_OPT_FLAG_ENCODING_PARAM)) - av_set_double(subtitle_enc, opt_names[i], d); + char buf[256]; + const AVOption *opt; + const char *str= av_get_string(avctx_opts[CODEC_TYPE_SUBTITLE], opt_names[i], &opt, buf, sizeof(buf)); + if(str && (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) && (opt->flags & AV_OPT_FLAG_ENCODING_PARAM)) + av_set_string(subtitle_enc, opt_names[i], str); } - subtitle_enc->codec_id = subtitle_codec_id; + subtitle_enc->codec_id = find_codec_or_die(subtitle_codec_name, CODEC_TYPE_SUBTITLE, 1); } if (subtitle_language) { - pstrcpy(st->language, sizeof(st->language), subtitle_language); + av_strlcpy(st->language, subtitle_language, sizeof(st->language)); av_free(subtitle_language); subtitle_language = NULL; } - subtitle_codec_id = CODEC_ID_NONE; + subtitle_disable = 0; + av_freep(&subtitle_codec_name); subtitle_stream_copy = 0; } @@ -2974,10 +3133,22 @@ static void opt_new_video_stream(void) new_video_stream(oc); } +static void opt_new_subtitle_stream(void) +{ + AVFormatContext *oc; + if (nb_output_files <= 0) { + fprintf(stderr, "At least one output file must be specified\n"); + exit(1); + } + oc = output_files[nb_output_files - 1]; + new_subtitle_stream(oc); +} + static void opt_output_file(const char *filename) { AVFormatContext *oc; - int use_video, use_audio, input_has_video, input_has_audio, i; + int use_video, use_audio, use_subtitle; + int input_has_video, input_has_audio, input_has_subtitle, i; AVFormatParameters params, *ap = ¶ms; if (!strcmp(filename, "-")) @@ -2988,17 +3159,17 @@ static void opt_output_file(const char *filename) if (!file_oformat) { file_oformat = guess_format(NULL, filename, NULL); if (!file_oformat) { - fprintf(stderr, "Unable for find a suitable output format for '%s'\n", + fprintf(stderr, "Unable to find a suitable output format for '%s'\n", filename); exit(1); } } oc->oformat = file_oformat; - pstrcpy(oc->filename, sizeof(oc->filename), filename); + av_strlcpy(oc->filename, filename, sizeof(oc->filename)); if (!strcmp(file_oformat->name, "ffm") && - strstart(filename, "http:", NULL)) { + av_strstart(filename, "http:", NULL)) { /* special case for files sent to ffserver: we get the stream parameters from ffserver */ if (read_ffserver_streams(oc, filename) < 0) { @@ -3006,17 +3177,21 @@ static void opt_output_file(const char *filename) exit(1); } } else { - use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_id != CODEC_ID_NONE; - use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_id != CODEC_ID_NONE; + use_video = file_oformat->video_codec != CODEC_ID_NONE || video_stream_copy || video_codec_name; + use_audio = file_oformat->audio_codec != CODEC_ID_NONE || audio_stream_copy || audio_codec_name; + use_subtitle = file_oformat->subtitle_codec != CODEC_ID_NONE || subtitle_stream_copy || subtitle_codec_name; /* disable if no corresponding type found and at least one input file */ if (nb_input_files > 0) { - check_audio_video_inputs(&input_has_video, &input_has_audio); + check_audio_video_sub_inputs(&input_has_video, &input_has_audio, + &input_has_subtitle); if (!input_has_video) use_video = 0; if (!input_has_audio) use_audio = 0; + if (!input_has_subtitle) + use_subtitle = 0; } /* manual disable */ @@ -3026,6 +3201,9 @@ static void opt_output_file(const char *filename) if (video_disable) { use_video = 0; } + if (subtitle_disable) { + use_subtitle = 0; + } if (use_video) { new_video_stream(oc); @@ -3035,18 +3213,24 @@ static void opt_output_file(const char *filename) new_audio_stream(oc); } + if (use_subtitle) { + new_subtitle_stream(oc); + } + oc->timestamp = rec_timestamp; if (str_title) - pstrcpy(oc->title, sizeof(oc->title), str_title); + av_strlcpy(oc->title, str_title, sizeof(oc->title)); if (str_author) - pstrcpy(oc->author, sizeof(oc->author), str_author); + av_strlcpy(oc->author, str_author, sizeof(oc->author)); if (str_copyright) - pstrcpy(oc->copyright, sizeof(oc->copyright), str_copyright); + av_strlcpy(oc->copyright, str_copyright, sizeof(oc->copyright)); if (str_comment) - pstrcpy(oc->comment, sizeof(oc->comment), str_comment); + av_strlcpy(oc->comment, str_comment, sizeof(oc->comment)); if (str_album) - pstrcpy(oc->album, sizeof(oc->album), str_album); + av_strlcpy(oc->album, str_album, sizeof(oc->album)); + if (str_genre) + av_strlcpy(oc->genre, str_genre, sizeof(oc->genre)); } output_files[nb_output_files++] = oc; @@ -3063,7 +3247,8 @@ static void opt_output_file(const char *filename) /* test if it already exists to avoid loosing precious files */ if (!file_overwrite && (strchr(filename, ':') == NULL || - strstart(filename, "file:", NULL))) { + filename[1] == ':' || + av_strstart(filename, "file:", NULL))) { if (url_exist(filename)) { int c; @@ -3102,10 +3287,11 @@ static void opt_output_file(const char *filename) oc->loop_output = loop_output; for(i=0; i<opt_name_count; i++){ + char buf[256]; const AVOption *opt; - double d = av_get_double(avformat_opts, opt_names[i], &opt); - if(d==d && (opt->flags&AV_OPT_FLAG_ENCODING_PARAM)) - av_set_double(oc, opt_names[i], d); + const char *str= av_get_string(avformat_opts, opt_names[i], &opt, buf, sizeof(buf)); + if(str && (opt->flags & AV_OPT_FLAG_ENCODING_PARAM)) + av_set_string(oc, opt_names[i], str); } /* reset some options */ @@ -3125,32 +3311,32 @@ static void opt_pass(const char *pass_str) do_pass = pass; } -#if defined(__MINGW32__) || defined(CONFIG_OS2) -static int64_t getutime(void) -{ - return av_gettime(); -} -#else static int64_t getutime(void) { +#ifdef HAVE_GETRUSAGE struct rusage rusage; getrusage(RUSAGE_SELF, &rusage); return (rusage.ru_utime.tv_sec * 1000000LL) + rusage.ru_utime.tv_usec; -} -#endif - -#if defined(CONFIG_FFM_DEMUXER) || defined(CONFIG_FFM_MUXER) -extern int ffm_nopts; +#elif defined(HAVE_GETPROCESSTIMES) + HANDLE proc; + FILETIME c, e, k, u; + proc = GetCurrentProcess(); + GetProcessTimes(proc, &c, &e, &k, &u); + return ((int64_t) u.dwHighDateTime << 32 | u.dwLowDateTime) / 10; +#else + return av_gettime(); #endif +} -static void show_formats(void) +static void opt_show_formats(void) { - AVInputFormat *ifmt; - AVOutputFormat *ofmt; - URLProtocol *up; - AVCodec *p, *p2; - const char **pp, *last_name; + AVInputFormat *ifmt=NULL; + AVOutputFormat *ofmt=NULL; + URLProtocol *up=NULL; + AVCodec *p=NULL, *p2; + AVBitStreamFilter *bsf=NULL; + const char *last_name; printf("File formats:\n"); last_name= "000"; @@ -3160,7 +3346,7 @@ static void show_formats(void) const char *name=NULL; const char *long_name=NULL; - for(ofmt = first_oformat; ofmt != NULL; ofmt = ofmt->next) { + while((ofmt= av_oformat_next(ofmt))) { if((name == NULL || strcmp(ofmt->name, name)<0) && strcmp(ofmt->name, last_name)>0){ name= ofmt->name; @@ -3168,7 +3354,7 @@ static void show_formats(void) encode=1; } } - for(ifmt = first_iformat; ifmt != NULL; ifmt = ifmt->next) { + while((ifmt= av_iformat_next(ifmt))) { if((name == NULL || strcmp(ifmt->name, name)<0) && strcmp(ifmt->name, last_name)>0){ name= ifmt->name; @@ -3200,7 +3386,7 @@ static void show_formats(void) const char *type_str; p2=NULL; - for(p = first_avcodec; p != NULL; p = p->next) { + while((p= av_codec_next(p))) { if((p2==NULL || strcmp(p->name, p2->name)<0) && strcmp(p->name, last_name)>0){ p2= p; @@ -3245,32 +3431,25 @@ static void show_formats(void) } printf("\n"); + printf("Bitstream filters:\n"); + while((bsf = av_bitstream_filter_next(bsf))) + printf(" %s", bsf->name); + printf("\n"); + printf("Supported file protocols:\n"); - for(up = first_protocol; up != NULL; up = up->next) + while((up = av_protocol_next(up))) printf(" %s:", up->name); printf("\n"); printf("Frame size, frame rate abbreviations:\n ntsc pal qntsc qpal sntsc spal film ntsc-film sqcif qcif cif 4cif\n"); - printf("Motion estimation methods:\n"); - pp = motion_str; - while (*pp) { - printf(" %s", *pp); - if ((pp - motion_str + 1) == ME_ZERO) - printf("(fastest)"); - else if ((pp - motion_str + 1) == ME_FULL) - printf("(slowest)"); - else if ((pp - motion_str + 1) == ME_EPZS) - printf("(default)"); - pp++; - } - printf("\n\n"); + printf("\n"); printf( -"Note, the names of encoders and decoders dont always match, so there are\n" +"Note, the names of encoders and decoders do not always match, so there are\n" "several cases where the above table shows encoder only or decoder only entries\n" -"even though both encoding and decoding are supported for example, the h263\n" -"decoder corresponds to the h263 and h263p encoders, for file formats its even\n" -"worse\n"); - exit(1); +"even though both encoding and decoding are supported. For example, the h263\n" +"decoder corresponds to the h263 and h263p encoders, for file formats it is even\n" +"worse.\n"); + exit(0); } static void parse_matrix_coeffs(uint16_t *dest, const char *str) @@ -3302,6 +3481,55 @@ static void opt_intra_matrix(const char *arg) parse_matrix_coeffs(intra_matrix, arg); } +/** + * Trivial log callback. + * Only suitable for show_help and similar since it lacks prefix handling. + */ +static void log_callback_help(void* ptr, int level, const char* fmt, va_list vl) +{ + vfprintf(stdout, fmt, vl); +} + +static void show_help(void) +{ + av_log_set_callback(log_callback_help); + printf("usage: ffmpeg [[infile options] -i infile]... {[outfile options] outfile}...\n" + "Hyper fast Audio and Video encoder\n"); + printf("\n"); + show_help_options(options, "Main options:\n", + OPT_EXPERT | OPT_AUDIO | OPT_VIDEO, 0); + show_help_options(options, "\nVideo options:\n", + OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, + OPT_VIDEO); + show_help_options(options, "\nAdvanced Video options:\n", + OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, + OPT_VIDEO | OPT_EXPERT); + show_help_options(options, "\nAudio options:\n", + OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, + OPT_AUDIO); + show_help_options(options, "\nAdvanced Audio options:\n", + OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, + OPT_AUDIO | OPT_EXPERT); + show_help_options(options, "\nSubtitle options:\n", + OPT_SUBTITLE | OPT_GRAB, + OPT_SUBTITLE); + show_help_options(options, "\nAudio/Video grab options:\n", + OPT_GRAB, + OPT_GRAB); + show_help_options(options, "\nAdvanced options:\n", + OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, + OPT_EXPERT); + av_opt_show(avctx_opts[0], NULL); + av_opt_show(avformat_opts, NULL); + av_opt_show(sws_opts, NULL); +} + +static void opt_show_help(void) +{ + show_help(); + exit(0); +} + static void opt_target(const char *arg) { int norm = -1; @@ -3319,7 +3547,7 @@ static void opt_target(const char *arg) } else { int fr; /* Calculate FR via float to avoid int overflow */ - fr = (int)(frame_rate * 1000.0 / frame_rate_base); + fr = (int)(frame_rate.num * 1000.0 / frame_rate.den); if(fr == 25000) { norm = 0; } else if((fr == 29970) || (fr == 23976)) { @@ -3447,25 +3675,24 @@ static void opt_target(const char *arg) } } -static void opt_video_bsf(const char *arg) +static void opt_vstats_file (const char *arg) { - AVBitStreamFilterContext *bsfc= av_bitstream_filter_init(arg); //FIXME split name and args for filter at '=' - AVBitStreamFilterContext **bsfp; - - if(!bsfc){ - fprintf(stderr, "Unknown bitstream filter %s\n", arg); - exit(1); - } + av_free (vstats_filename); + vstats_filename=av_strdup (arg); +} - bsfp= &video_bitstream_filters; - while(*bsfp) - bsfp= &(*bsfp)->next; +static void opt_vstats (void) +{ + char filename[40]; + time_t today2 = time(NULL); + struct tm *today = localtime(&today2); - *bsfp= bsfc; + snprintf(filename, sizeof(filename), "vstats_%02d%02d%02d.log", today->tm_hour, today->tm_min, + today->tm_sec); + opt_vstats_file(filename); } -//FIXME avoid audio - video code duplication -static void opt_audio_bsf(const char *arg) +static int opt_bsf(const char *opt, const char *arg) { AVBitStreamFilterContext *bsfc= av_bitstream_filter_init(arg); //FIXME split name and args for filter at '=' AVBitStreamFilterContext **bsfp; @@ -3475,76 +3702,41 @@ static void opt_audio_bsf(const char *arg) exit(1); } - bsfp= &audio_bitstream_filters; + bsfp= *opt == 'v' ? &video_bitstream_filters : + *opt == 'a' ? &audio_bitstream_filters : + &subtitle_bitstream_filters; while(*bsfp) bsfp= &(*bsfp)->next; *bsfp= bsfc; + + return 0; } -static void show_version(void) +static void opt_show_license(void) { - /* TODO: add function interface to avutil and avformat */ - fprintf(stderr, "ffmpeg " FFMPEG_VERSION "\n" - "libavutil %d\n" - "libavcodec %d\n" - "libavformat %d\n", - LIBAVUTIL_BUILD, avcodec_build(), LIBAVFORMAT_BUILD); - exit(1); + show_license(); + exit(0); } -static int opt_default(const char *opt, const char *arg){ - int type; - const AVOption *o= NULL; - int opt_types[]={AV_OPT_FLAG_VIDEO_PARAM, AV_OPT_FLAG_AUDIO_PARAM, 0, AV_OPT_FLAG_SUBTITLE_PARAM, 0}; - - for(type=0; type<CODEC_TYPE_NB; type++){ - const AVOption *o2 = av_find_opt(avctx_opts[0], opt, NULL, opt_types[type], opt_types[type]); - if(o2) - o = av_set_string(avctx_opts[type], opt, arg); - } - if(!o) - o = av_set_string(avformat_opts, opt, arg); - if(!o){ - if(opt[0] == 'a') - o = av_set_string(avctx_opts[CODEC_TYPE_AUDIO], opt+1, arg); - else if(opt[0] == 'v') - o = av_set_string(avctx_opts[CODEC_TYPE_VIDEO], opt+1, arg); - else if(opt[0] == 's') - o = av_set_string(avctx_opts[CODEC_TYPE_SUBTITLE], opt+1, arg); - } - if(!o) - return -1; - -// av_log(NULL, AV_LOG_ERROR, "%s:%s: %f 0x%0X\n", opt, arg, av_get_double(avctx_opts, opt, NULL), (int)av_get_int(avctx_opts, opt, NULL)); - - //FIXME we should always use avctx_opts, ... for storing options so there wont be any need to keep track of whats set over this - opt_names= av_realloc(opt_names, sizeof(void*)*(opt_name_count+1)); - opt_names[opt_name_count++]= o->name; - -#if defined(CONFIG_FFM_DEMUXER) || defined(CONFIG_FFM_MUXER) - /* disable generate of real time pts in ffm (need to be supressed anyway) */ - if(avctx_opts[0]->flags & CODEC_FLAG_BITEXACT) - ffm_nopts = 1; -#endif - - if(avctx_opts[0]->debug) - av_log_level = AV_LOG_DEBUG; - return 0; +static void opt_show_version(void) +{ + show_version(program_name); + exit(0); } const OptionDef options[] = { /* main options */ - { "L", 0, {(void*)show_license}, "show license" }, - { "h", 0, {(void*)show_help}, "show help" }, - { "version", 0, {(void*)show_version}, "show version" }, - { "formats", 0, {(void*)show_formats}, "show available formats, codecs, protocols, ..." }, + { "L", 0, {(void*)opt_show_license}, "show license" }, + { "h", 0, {(void*)opt_show_help}, "show help" }, + { "version", 0, {(void*)opt_show_version}, "show version" }, + { "formats", 0, {(void*)opt_show_formats}, "show available formats, codecs, protocols, ..." }, { "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" }, { "i", HAS_ARG, {(void*)opt_input_file}, "input file name", "filename" }, { "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" }, { "map", HAS_ARG | OPT_EXPERT, {(void*)opt_map}, "set input stream mapping", "file:stream[:syncfile:syncstream]" }, { "map_meta_data", HAS_ARG | OPT_EXPERT, {(void*)opt_map_meta_data}, "set meta data information of outfile from infile", "outfile:infile" }, - { "t", HAS_ARG, {(void*)opt_recording_time}, "set the recording time", "duration" }, + { "t", HAS_ARG, {(void*)opt_recording_time}, "record or transcode \"duration\" seconds of audio/video", "duration" }, { "fs", HAS_ARG | OPT_INT64, {(void*)&limit_filesize}, "set the limit file size in bytes", "limit_size" }, // { "ss", HAS_ARG, {(void*)opt_start_time}, "set the start time offset", "time_off" }, { "itsoffset", HAS_ARG, {(void*)opt_input_ts_offset}, "set the input ts offset", "time_off" }, @@ -3553,6 +3745,7 @@ const OptionDef options[] = { { "author", HAS_ARG | OPT_STRING, {(void*)&str_author}, "set the author", "string" }, { "copyright", HAS_ARG | OPT_STRING, {(void*)&str_copyright}, "set the copyright", "string" }, { "comment", HAS_ARG | OPT_STRING, {(void*)&str_comment}, "set the comment", "string" }, + { "genre", HAS_ARG | OPT_STRING, {(void*)&str_genre}, "set the genre", "string" }, { "album", HAS_ARG | OPT_STRING, {(void*)&str_album}, "set the album", "string" }, { "benchmark", OPT_BOOL | OPT_EXPERT, {(void*)&do_benchmark}, "add timings for benchmarking" }, @@ -3563,23 +3756,27 @@ const OptionDef options[] = { { "re", OPT_BOOL | OPT_EXPERT, {(void*)&rate_emu}, "read input at native frame rate", "" }, { "loop_input", OPT_BOOL | OPT_EXPERT, {(void*)&loop_input}, "loop (current only works with images)" }, { "loop_output", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&loop_output}, "number of times to loop output in formats that support looping (0 loops forever)", "" }, - { "v", HAS_ARG, {(void*)opt_verbose}, "control amount of logging", "verbose" }, + { "v", HAS_ARG, {(void*)opt_verbose}, "set the logging verbosity level", "number" }, { "target", HAS_ARG, {(void*)opt_target}, "specify target file type (\"vcd\", \"svcd\", \"dvd\", \"dv\", \"dv50\", \"pal-vcd\", \"ntsc-svcd\", ...)", "type" }, { "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" }, { "vsync", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_sync_method}, "video sync method", "" }, { "async", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&audio_sync_method}, "audio sync method", "" }, + { "adrift_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&audio_drift_threshold}, "audio drift threshold", "" }, { "vglobal", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&video_global_header}, "video global header storage type", "" }, { "copyts", OPT_BOOL | OPT_EXPERT, {(void*)©_ts}, "copy timestamps" }, { "shortest", OPT_BOOL | OPT_EXPERT, {(void*)&opt_shortest}, "finish encoding within shortest input" }, // - { "dts_delta_threshold", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&dts_delta_threshold}, "timestamp discontinuity delta threshold", "" }, + { "dts_delta_threshold", HAS_ARG | OPT_FLOAT | OPT_EXPERT, {(void*)&dts_delta_threshold}, "timestamp discontinuity delta threshold", "" }, + { "programid", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&opt_programid}, "desired program number", "" }, /* video options */ + { "b", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "" }, + { "vb", OPT_FUNC2 | HAS_ARG | OPT_VIDEO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "" }, { "vframes", OPT_INT | HAS_ARG | OPT_VIDEO, {(void*)&max_frames[CODEC_TYPE_VIDEO]}, "set the number of video frames to record", "number" }, { "dframes", OPT_INT | HAS_ARG, {(void*)&max_frames[CODEC_TYPE_DATA]}, "set the number of data frames to record", "number" }, { "r", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_rate}, "set frame rate (Hz value, fraction or abbreviation)", "rate" }, { "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" }, { "aspect", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_aspect_ratio}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" }, - { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format", "format" }, + { "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format, 'list' as argument shows all the pixel formats supported", "format" }, { "croptop", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_top}, "set top crop band size (in pixels)", "size" }, { "cropbottom", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_bottom}, "set bottom crop band size (in pixels)", "size" }, { "cropleft", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_left}, "set left crop band size (in pixels)", "size" }, @@ -3594,11 +3791,8 @@ const OptionDef options[] = { { "vdt", OPT_INT | HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)&video_discard}, "discard threshold", "n" }, { "qscale", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qscale}, "use fixed video quantizer scale (VBR)", "q" }, { "qdiff", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_qdiff}, "max difference between the quantizer scale (VBR)", "q" }, - { "rc_eq", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_eq}, "set rate control equation", "equation" }, { "rc_override", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_video_rc_override_string}, "rate control override for specific intervals", "override" }, { "vcodec", HAS_ARG | OPT_VIDEO, {(void*)opt_video_codec}, "force video codec ('copy' to copy stream)", "codec" }, - { "me", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_motion_estimation}, "set motion estimation method", - "method" }, { "me_threshold", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_me_threshold}, "motion estimaton threshold", "" }, { "strict", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_strict}, "how strictly to follow the standards", "strictness" }, { "sameq", OPT_BOOL | OPT_VIDEO, {(void*)&same_quality}, @@ -3608,8 +3802,11 @@ const OptionDef options[] = { { "deinterlace", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_deinterlace}, "deinterlace pictures" }, { "psnr", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_psnr}, "calculate PSNR of compressed frames" }, - { "vstats", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, {(void*)&do_vstats}, "dump video coding statistics to file" }, + { "vstats", OPT_EXPERT | OPT_VIDEO, {(void*)&opt_vstats}, "dump video coding statistics to file" }, + { "vstats_file", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_vstats_file}, "dump video coding statistics to file", "file" }, +#ifdef CONFIG_VHOOK { "vhook", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)add_frame_hooker}, "insert video processing module", "module" }, +#endif { "intra_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_intra_matrix}, "specify intra matrix coeffs", "matrix" }, { "inter_matrix", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_inter_matrix}, "specify inter matrix coeffs", "matrix" }, { "top", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_top_field_first}, "top=1/bottom=0/auto=-1 field first", "" }, @@ -3619,6 +3816,7 @@ const OptionDef options[] = { { "qphist", OPT_BOOL | OPT_EXPERT | OPT_VIDEO, { (void *)&qp_hist }, "show QP histogram" }, /* audio options */ + { "ab", OPT_FUNC2 | HAS_ARG | OPT_AUDIO, {(void*)opt_bitrate}, "set bitrate (in bits/s)", "" }, { "aframes", OPT_INT | HAS_ARG | OPT_AUDIO, {(void*)&max_frames[CODEC_TYPE_AUDIO]}, "set the number of audio frames to record", "number" }, { "aq", OPT_FLOAT | HAS_ARG | OPT_AUDIO, {(void*)&audio_qscale}, "set audio quality (codec-specific)", "quality", }, { "ar", HAS_ARG | OPT_AUDIO, {(void*)opt_audio_rate}, "set audio sampling rate (in Hz)", "rate" }, @@ -3631,6 +3829,7 @@ const OptionDef options[] = { { "alang", HAS_ARG | OPT_STRING | OPT_AUDIO, {(void *)&audio_language}, "set the ISO 639 language code (3 letters) of the current audio stream" , "code" }, /* subtitle options */ + { "sn", OPT_BOOL | OPT_SUBTITLE, {(void*)&subtitle_disable}, "disable subtitle" }, { "scodec", HAS_ARG | OPT_SUBTITLE, {(void*)opt_subtitle_codec}, "force subtitle codec ('copy' to copy stream)", "codec" }, { "newsubtitle", OPT_SUBTITLE, {(void*)opt_new_subtitle_stream}, "add a new subtitle stream to the current output stream" }, { "slang", HAS_ARG | OPT_STRING | OPT_SUBTITLE, {(void *)&subtitle_language}, "set the ISO 639 language code (3 letters) of the current subtitle stream" , "code" }, @@ -3644,105 +3843,65 @@ const OptionDef options[] = { { "muxdelay", OPT_FLOAT | HAS_ARG | OPT_EXPERT, {(void*)&mux_max_delay}, "set the maximum demux-decode delay", "seconds" }, { "muxpreload", OPT_FLOAT | HAS_ARG | OPT_EXPERT, {(void*)&mux_preload}, "set the initial demux-decode delay", "seconds" }, - { "absf", HAS_ARG | OPT_AUDIO | OPT_EXPERT, {(void*)opt_audio_bsf}, "", "bitstream filter" }, - { "vbsf", HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_video_bsf}, "", "bitstream filter" }, + { "absf", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream filter" }, + { "vbsf", OPT_FUNC2 | HAS_ARG | OPT_VIDEO | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream filter" }, + { "sbsf", OPT_FUNC2 | HAS_ARG | OPT_SUBTITLE | OPT_EXPERT, {(void*)opt_bsf}, "", "bitstream filter" }, { "default", OPT_FUNC2 | HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" }, { NULL, }, }; -static void show_banner(void) +static int av_exit() { - fprintf(stderr, "FFmpeg version " FFMPEG_VERSION ", Copyright (c) 2000-2007 Fabrice Bellard, et al.\n"); - fprintf(stderr, " configuration: " FFMPEG_CONFIGURATION "\n"); - fprintf(stderr, " libavutil version: " AV_STRINGIFY(LIBAVUTIL_VERSION) "\n"); - fprintf(stderr, " libavcodec version: " AV_STRINGIFY(LIBAVCODEC_VERSION) "\n"); - fprintf(stderr, " libavformat version: " AV_STRINGIFY(LIBAVFORMAT_VERSION) "\n"); - fprintf(stderr, " built on " __DATE__ " " __TIME__); -#ifdef __GNUC__ - fprintf(stderr, ", gcc: " __VERSION__ "\n"); -#else - fprintf(stderr, ", using a non-gcc compiler\n"); -#endif -} + int i; -static void show_license(void) -{ - show_banner(); -#ifdef CONFIG_GPL - printf( - "FFmpeg is free software; you can redistribute it and/or modify\n" - "it under the terms of the GNU General Public License as published by\n" - "the Free Software Foundation; either version 2 of the License, or\n" - "(at your option) any later version.\n" - "\n" - "FFmpeg is distributed in the hope that it will be useful,\n" - "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" - "GNU General Public License for more details.\n" - "\n" - "You should have received a copy of the GNU General Public License\n" - "along with FFmpeg; if not, write to the Free Software\n" - "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n" - ); -#else - printf( - "FFmpeg is free software; you can redistribute it and/or\n" - "modify it under the terms of the GNU Lesser General Public\n" - "License as published by the Free Software Foundation; either\n" - "version 2.1 of the License, or (at your option) any later version.\n" - "\n" - "FFmpeg is distributed in the hope that it will be useful,\n" - "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" - "Lesser General Public License for more details.\n" - "\n" - "You should have received a copy of the GNU Lesser General Public\n" - "License along with FFmpeg; if not, write to the Free Software\n" - "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n" - ); -#endif - exit(1); -} + /* close files */ + for(i=0;i<nb_output_files;i++) { + /* maybe av_close_output_file ??? */ + AVFormatContext *s = output_files[i]; + int j; + if (!(s->oformat->flags & AVFMT_NOFILE)) + url_fclose(s->pb); + for(j=0;j<s->nb_streams;j++) { + av_free(s->streams[j]->codec); + av_free(s->streams[j]); + } + av_free(s); + } + for(i=0;i<nb_input_files;i++) + av_close_input_file(input_files[i]); -static void show_help(void) -{ - show_banner(); - printf("usage: ffmpeg [[infile options] -i infile]... {[outfile options] outfile}...\n" - "Hyper fast Audio and Video encoder\n"); - printf("\n"); - show_help_options(options, "Main options:\n", - OPT_EXPERT | OPT_AUDIO | OPT_VIDEO, 0); - show_help_options(options, "\nVideo options:\n", - OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, - OPT_VIDEO); - show_help_options(options, "\nAdvanced Video options:\n", - OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, - OPT_VIDEO | OPT_EXPERT); - show_help_options(options, "\nAudio options:\n", - OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, - OPT_AUDIO); - show_help_options(options, "\nAdvanced Audio options:\n", - OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, - OPT_AUDIO | OPT_EXPERT); - show_help_options(options, "\nSubtitle options:\n", - OPT_SUBTITLE | OPT_GRAB, - OPT_SUBTITLE); - show_help_options(options, "\nAudio/Video grab options:\n", - OPT_GRAB, - OPT_GRAB); - show_help_options(options, "\nAdvanced options:\n", - OPT_EXPERT | OPT_AUDIO | OPT_VIDEO | OPT_GRAB, - OPT_EXPERT); - av_opt_show(avctx_opts[0], NULL); - av_opt_show(avformat_opts, NULL); + av_free_static(); - exit(1); -} + av_free(intra_matrix); + av_free(inter_matrix); -void parse_arg_file(const char *filename) -{ - opt_output_file(filename); + if (vstats_file) + fclose(vstats_file); + av_free(vstats_filename); + + av_free(opt_names); + + av_free(video_codec_name); + av_free(audio_codec_name); + av_free(subtitle_codec_name); + + av_free(video_standard); + +#ifdef CONFIG_POWERPC_PERF + extern void powerpc_display_perf_report(void); + powerpc_display_perf_report(); +#endif /* CONFIG_POWERPC_PERF */ + + if (received_sigterm) { + fprintf(stderr, + "Received signal %d: terminating.\n", + (int) received_sigterm); + exit (255); + } + + exit(0); /* not all OS-es handle main() return value */ + return 0; } int main(int argc, char **argv) @@ -3750,20 +3909,24 @@ int main(int argc, char **argv) int i; int64_t ti; + avcodec_register_all(); + avdevice_register_all(); av_register_all(); for(i=0; i<CODEC_TYPE_NB; i++){ avctx_opts[i]= avcodec_alloc_context2(i); } avformat_opts = av_alloc_format_context(); + sws_opts = sws_getContext(16,16,0, 16,16,0, sws_flags, NULL,NULL,NULL); - if (argc <= 1) + show_banner(program_name, program_birth_year); + if (argc <= 1) { show_help(); - else - show_banner(); + exit(1); + } /* parse options */ - parse_options(argc, argv, options); + parse_options(argc, argv, options, opt_output_file); /* file converter / grab */ if (nb_output_files <= 0) { @@ -3784,40 +3947,5 @@ int main(int argc, char **argv) printf("bench: utime=%0.3fs\n", ti / 1000000.0); } - /* close files */ - for(i=0;i<nb_output_files;i++) { - /* maybe av_close_output_file ??? */ - AVFormatContext *s = output_files[i]; - int j; - if (!(s->oformat->flags & AVFMT_NOFILE)) - url_fclose(&s->pb); - for(j=0;j<s->nb_streams;j++) { - av_free(s->streams[j]->codec); - av_free(s->streams[j]); - } - av_free(s); - } - for(i=0;i<nb_input_files;i++) - av_close_input_file(input_files[i]); - - av_free_static(); - - av_free(intra_matrix); - av_free(inter_matrix); - av_free(opt_names); - -#ifdef CONFIG_POWERPC_PERF - extern void powerpc_display_perf_report(void); - powerpc_display_perf_report(); -#endif /* CONFIG_POWERPC_PERF */ - - if (received_sigterm) { - fprintf(stderr, - "Received signal %d: terminating.\n", - (int) received_sigterm); - exit (255); - } - - exit(0); /* not all OS-es handle main() return value */ - return 0; + return av_exit(); } diff --git a/contrib/ffmpeg/ffplay.c b/contrib/ffmpeg/ffplay.c index ebe31cd9b..915c25710 100644 --- a/contrib/ffmpeg/ffplay.c +++ b/contrib/ffmpeg/ffplay.c @@ -18,9 +18,14 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#define HAVE_AV_CONFIG_H + +#include <math.h> +#include <limits.h> #include "avformat.h" +#include "avdevice.h" +#include "rtsp.h" #include "swscale.h" +#include "avstring.h" #include "version.h" #include "cmdutils.h" @@ -32,25 +37,11 @@ #undef main /* We don't want SDL to override our main() */ #endif -#ifdef CONFIG_OS2 -#define INCL_DOS - #include <os2.h> - #include <stdio.h> - - void MorphToPM() - { - PPIB pib; - PTIB tib; - - DosGetInfoBlocks(&tib, &pib); - - // Change flag from VIO to PM: - if (pib->pib_ultype==2) pib->pib_ultype = 3; - } -#endif - #undef exit +static const char program_name[] = "FFplay"; +static const int program_birth_year = 2003; + //#define DEBUG_SYNC #define MAX_VIDEOQ_SIZE (5 * 256 * 1024) @@ -194,6 +185,7 @@ static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE; static int audio_disable; static int video_disable; static int wanted_audio_stream= 0; +static int wanted_video_stream= 0; static int seek_by_bytes; static int display_disable; static int show_status; @@ -420,7 +412,7 @@ void fill_border(VideoState *s, int x, int y, int w, int h, int color) #define YUVA_IN(y, u, v, a, s, pal)\ {\ - unsigned int val = ((const uint32_t *)(pal))[*(const uint8_t*)s];\ + unsigned int val = ((const uint32_t *)(pal))[*(const uint8_t*)(s)];\ a = (val >> 24) & 0xff;\ y = (val >> 16) & 0xff;\ u = (val >> 8) & 0xff;\ @@ -435,31 +427,36 @@ void fill_border(VideoState *s, int x, int y, int w, int h, int color) #define BPP 1 -static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect) +static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect, int imgw, int imgh) { int wrap, wrap3, width2, skip2; int y, u, v, a, u1, v1, a1, w, h; uint8_t *lum, *cb, *cr; const uint8_t *p; const uint32_t *pal; - - lum = dst->data[0] + rect->y * dst->linesize[0]; - cb = dst->data[1] + (rect->y >> 1) * dst->linesize[1]; - cr = dst->data[2] + (rect->y >> 1) * dst->linesize[2]; - - width2 = (rect->w + 1) >> 1; - skip2 = rect->x >> 1; + int dstx, dsty, dstw, dsth; + + dstx = FFMIN(FFMAX(rect->x, 0), imgw); + dstw = FFMIN(FFMAX(rect->w, 0), imgw - dstx); + dsty = FFMIN(FFMAX(rect->y, 0), imgh); + dsth = FFMIN(FFMAX(rect->h, 0), imgh - dsty); + lum = dst->data[0] + dsty * dst->linesize[0]; + cb = dst->data[1] + (dsty >> 1) * dst->linesize[1]; + cr = dst->data[2] + (dsty >> 1) * dst->linesize[2]; + + width2 = (dstw + 1) >> 1; + skip2 = dstx >> 1; wrap = dst->linesize[0]; wrap3 = rect->linesize; p = rect->bitmap; pal = rect->rgba_palette; /* Now in YCrCb! */ - if (rect->y & 1) { - lum += rect->x; + if (dsty & 1) { + lum += dstx; cb += skip2; cr += skip2; - if (rect->x & 1) { + if (dstx & 1) { YUVA_IN(y, u, v, a, p, pal); lum[0] = ALPHA_BLEND(a, lum[0], y, 0); cb[0] = ALPHA_BLEND(a >> 2, cb[0], u, 0); @@ -469,7 +466,7 @@ static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect) lum++; p += BPP; } - for(w = rect->w - (rect->x & 1); w >= 2; w -= 2) { + for(w = dstw - (dstx & 1); w >= 2; w -= 2) { YUVA_IN(y, u, v, a, p, pal); u1 = u; v1 = v; @@ -494,17 +491,17 @@ static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect) cb[0] = ALPHA_BLEND(a >> 2, cb[0], u, 0); cr[0] = ALPHA_BLEND(a >> 2, cr[0], v, 0); } - p += wrap3 + (wrap3 - rect->w * BPP); - lum += wrap + (wrap - rect->w - rect->x); + p += wrap3 + (wrap3 - dstw * BPP); + lum += wrap + (wrap - dstw - dstx); cb += dst->linesize[1] - width2 - skip2; cr += dst->linesize[2] - width2 - skip2; } - for(h = rect->h - (rect->y & 1); h >= 2; h -= 2) { - lum += rect->x; + for(h = dsth - (dsty & 1); h >= 2; h -= 2) { + lum += dstx; cb += skip2; cr += skip2; - if (rect->x & 1) { + if (dstx & 1) { YUVA_IN(y, u, v, a, p, pal); u1 = u; v1 = v; @@ -524,7 +521,7 @@ static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect) p += -wrap3 + BPP; lum += -wrap + 1; } - for(w = rect->w - (rect->x & 1); w >= 2; w -= 2) { + for(w = dstw - (dstx & 1); w >= 2; w -= 2) { YUVA_IN(y, u, v, a, p, pal); u1 = u; v1 = v; @@ -579,18 +576,18 @@ static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect) p += -wrap3 + BPP; lum += -wrap + 1; } - p += wrap3 + (wrap3 - rect->w * BPP); - lum += wrap + (wrap - rect->w - rect->x); + p += wrap3 + (wrap3 - dstw * BPP); + lum += wrap + (wrap - dstw - dstx); cb += dst->linesize[1] - width2 - skip2; cr += dst->linesize[2] - width2 - skip2; } /* handle odd height */ if (h) { - lum += rect->x; + lum += dstx; cb += skip2; cr += skip2; - if (rect->x & 1) { + if (dstx & 1) { YUVA_IN(y, u, v, a, p, pal); lum[0] = ALPHA_BLEND(a, lum[0], y, 0); cb[0] = ALPHA_BLEND(a >> 2, cb[0], u, 0); @@ -600,7 +597,7 @@ static void blend_subrect(AVPicture *dst, const AVSubtitleRect *rect) lum++; p += BPP; } - for(w = rect->w - (rect->x & 1); w >= 2; w -= 2) { + for(w = dstw - (dstx & 1); w >= 2; w -= 2) { YUVA_IN(y, u, v, a, p, pal); u1 = u; v1 = v; @@ -660,7 +657,7 @@ static void video_image_display(VideoState *is) aspect_ratio = 0; else aspect_ratio = av_q2d(is->video_st->codec->sample_aspect_ratio) - * is->video_st->codec->width / is->video_st->codec->height;; + * is->video_st->codec->width / is->video_st->codec->height; if (aspect_ratio <= 0.0) aspect_ratio = (float)is->video_st->codec->width / (float)is->video_st->codec->height; @@ -718,7 +715,8 @@ static void video_image_display(VideoState *is) pict.linesize[2] = vp->bmp->pitches[1]; for (i = 0; i < sp->sub.num_rects; i++) - blend_subrect(&pict, &sp->sub.rects[i]); + blend_subrect(&pict, &sp->sub.rects[i], + vp->bmp->w, vp->bmp->h); SDL_UnlockYUVOverlay (vp->bmp); } @@ -872,7 +870,7 @@ static int video_open(VideoState *is){ w = 640; h = 480; } -#ifndef CONFIG_DARWIN +#ifndef __APPLE__ screen = SDL_SetVideoMode(w, h, 0, flags); #else /* setting bits_per_pixel = 0 or 32 causes blank video on OS X */ @@ -1019,7 +1017,7 @@ static void video_refresh_timer(void *opaque) /* compute nominal delay */ delay = vp->pts - is->frame_last_pts; - if (delay <= 0 || delay >= 1.0) { + if (delay <= 0 || delay >= 2.0) { /* if incorrect delay, use previous one */ delay = is->frame_last_delay; } @@ -1265,15 +1263,14 @@ static int queue_picture(VideoState *is, AVFrame *src_frame, double pts) pict.linesize[0] = vp->bmp->pitches[0]; pict.linesize[1] = vp->bmp->pitches[2]; pict.linesize[2] = vp->bmp->pitches[1]; + img_convert_ctx = sws_getCachedContext(img_convert_ctx, + is->video_st->codec->width, is->video_st->codec->height, + is->video_st->codec->pix_fmt, + is->video_st->codec->width, is->video_st->codec->height, + dst_pix_fmt, sws_flags, NULL, NULL, NULL); if (img_convert_ctx == NULL) { - img_convert_ctx = sws_getContext(is->video_st->codec->width, - is->video_st->codec->height, is->video_st->codec->pix_fmt, - is->video_st->codec->width, is->video_st->codec->height, - dst_pix_fmt, sws_flags, NULL, NULL, NULL); - if (img_convert_ctx == NULL) { - fprintf(stderr, "Cannot initialize the conversion context\n"); - exit(1); - } + fprintf(stderr, "Cannot initialize the conversion context\n"); + exit(1); } sws_scale(img_convert_ctx, src_frame->data, src_frame->linesize, 0, is->video_st->codec->height, pict.data, pict.linesize); @@ -1696,21 +1693,11 @@ static int stream_component_open(VideoState *is, int stream_index) /* prepare audio output */ if (enc->codec_type == CODEC_TYPE_AUDIO) { - wanted_spec.freq = enc->sample_rate; - wanted_spec.format = AUDIO_S16SYS; - /* hack for AC3. XXX: suppress that */ - if (enc->channels > 2) - enc->channels = 2; - wanted_spec.channels = enc->channels; - wanted_spec.silence = 0; - wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE; - wanted_spec.callback = sdl_audio_callback; - wanted_spec.userdata = is; - if (SDL_OpenAudio(&wanted_spec, &spec) < 0) { - fprintf(stderr, "SDL_OpenAudio: %s\n", SDL_GetError()); - return -1; + if (enc->channels > 0) { + enc->request_channels = FFMIN(2, enc->channels); + } else { + enc->request_channels = 2; } - is->audio_hw_buf_size = spec.size; } codec = avcodec_find_decoder(enc->codec_id); @@ -1729,6 +1716,23 @@ static int stream_component_open(VideoState *is, int stream_index) if (!codec || avcodec_open(enc, codec) < 0) return -1; + + /* prepare audio output */ + if (enc->codec_type == CODEC_TYPE_AUDIO) { + wanted_spec.freq = enc->sample_rate; + wanted_spec.format = AUDIO_S16SYS; + wanted_spec.channels = enc->channels; + wanted_spec.silence = 0; + wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE; + wanted_spec.callback = sdl_audio_callback; + wanted_spec.userdata = is; + if (SDL_OpenAudio(&wanted_spec, &spec) < 0) { + fprintf(stderr, "SDL_OpenAudio: %s\n", SDL_GetError()); + return -1; + } + is->audio_hw_buf_size = spec.size; + } + if(thread_count>1) avcodec_thread_init(enc, thread_count); enc->thread_count= thread_count; @@ -1879,7 +1883,7 @@ static int decode_thread(void *arg) { VideoState *is = arg; AVFormatContext *ic; - int err, i, ret, video_index, audio_index, use_play; + int err, i, ret, video_index, audio_index; AVPacket pkt1, *pkt = &pkt1; AVFormatParameters params, *ap = ¶ms; @@ -1893,8 +1897,6 @@ static int decode_thread(void *arg) url_set_interrupt_cb(decode_interrupt_cb); memset(ap, 0, sizeof(*ap)); - ap->initial_pause = 1; /* we force a pause when starting an RTSP - stream */ ap->width = frame_width; ap->height= frame_height; @@ -1908,24 +1910,18 @@ static int decode_thread(void *arg) goto fail; } is->ic = ic; -#ifdef CONFIG_NETWORK - use_play = (ic->iformat == &rtsp_demuxer); -#else - use_play = 0; -#endif if(genpts) ic->flags |= AVFMT_FLAG_GENPTS; - if (!use_play) { - err = av_find_stream_info(ic); - if (err < 0) { - fprintf(stderr, "%s: could not find codec parameters\n", is->filename); - ret = -1; - goto fail; - } - ic->pb.eof_reached= 0; //FIXME hack, ffplay maybe shouldnt use url_feof() to test for the end + err = av_find_stream_info(ic); + if (err < 0) { + fprintf(stderr, "%s: could not find codec parameters\n", is->filename); + ret = -1; + goto fail; } + if(ic->pb) + ic->pb->eof_reached= 0; //FIXME hack, ffplay maybe should not use url_feof() to test for the end /* if seeking requested, we execute it */ if (start_time != AV_NOPTS_VALUE) { @@ -1942,18 +1938,6 @@ static int decode_thread(void *arg) } } - /* now we can begin to play (RTSP stream only) */ - av_read_play(ic); - - if (use_play) { - err = av_find_stream_info(ic); - if (err < 0) { - fprintf(stderr, "%s: could not find codec parameters\n", is->filename); - ret = -1; - goto fail; - } - } - for(i = 0; i < ic->nb_streams; i++) { AVCodecContext *enc = ic->streams[i]->codec; switch(enc->codec_type) { @@ -1962,7 +1946,7 @@ static int decode_thread(void *arg) audio_index = i; break; case CODEC_TYPE_VIDEO: - if (video_index < 0 && !video_disable) + if ((video_index < 0 || wanted_video_stream-- > 0) && !video_disable) video_index = i; break; default: @@ -1995,7 +1979,6 @@ static int decode_thread(void *arg) for(;;) { if (is->abort_request) break; -#ifdef CONFIG_NETWORK if (is->paused != is->last_paused) { is->last_paused = is->paused; if (is->paused) @@ -2003,7 +1986,10 @@ static int decode_thread(void *arg) else av_read_play(ic); } - if (is->paused && ic->iformat == &rtsp_demuxer) { +#if defined(CONFIG_RTSP_DEMUXER) || defined(CONFIG_MMSH_PROTOCOL) + if (is->paused && + (!strcmp(ic->iformat->name, "rtsp") || + (ic->pb && !strcmp(url_fileno(ic->pb)->prot->name, "mmsh")))) { /* wait 10 ms to avoid trying to get another packet */ /* XXX: horrible */ SDL_Delay(10); @@ -2046,14 +2032,14 @@ static int decode_thread(void *arg) if (is->audioq.size > MAX_AUDIOQ_SIZE || is->videoq.size > MAX_VIDEOQ_SIZE || is->subtitleq.size > MAX_SUBTITLEQ_SIZE || - url_feof(&ic->pb)) { + url_feof(ic->pb)) { /* wait 10 ms */ SDL_Delay(10); continue; } ret = av_read_frame(ic, pkt); if (ret < 0) { - if (url_ferror(&ic->pb) == 0) { + if (url_ferror(ic->pb) == 0) { SDL_Delay(100); /* wait for user event */ continue; } else @@ -2109,7 +2095,7 @@ static VideoState *stream_open(const char *filename, AVInputFormat *iformat) is = av_mallocz(sizeof(VideoState)); if (!is) return NULL; - pstrcpy(is->filename, sizeof(is->filename), filename); + av_strlcpy(is->filename, filename, sizeof(is->filename)); is->iformat = iformat; is->ytop = 0; is->xleft = 0; @@ -2225,9 +2211,9 @@ static void toggle_pause(void) static void step_to_next_frame(void) { if (cur_stream) { + /* if the stream is paused unpause it, then step */ if (cur_stream->paused) - cur_stream->paused=0; - cur_stream->video_current_pts = get_video_clock(cur_stream); + stream_pause(cur_stream); } step = 1; } @@ -2305,7 +2291,7 @@ static void event_loop(void) do_seek: if (cur_stream) { if (seek_by_bytes) { - pos = url_ftell(&cur_stream->ic->pb); + pos = url_ftell(cur_stream->ic->pb); if (cur_stream->ic->bit_rate) incr *= cur_stream->ic->bit_rate / 60.0; else @@ -2368,7 +2354,7 @@ static void event_loop(void) static void opt_frame_size(const char *arg) { - if (parse_image_size(&frame_width, &frame_height, arg) < 0) { + if (av_parse_video_frame_size(&frame_width, &frame_height, arg) < 0) { fprintf(stderr, "Incorrect frame size\n"); exit(1); } @@ -2378,7 +2364,7 @@ static void opt_frame_size(const char *arg) } } -void opt_width(const char *arg) +static void opt_width(const char *arg) { screen_width = atoi(arg); if(screen_width<=0){ @@ -2387,7 +2373,7 @@ void opt_width(const char *arg) } } -void opt_height(const char *arg) +static void opt_height(const char *arg) { screen_height = atoi(arg); if(screen_height<=0){ @@ -2410,15 +2396,7 @@ static void opt_frame_pix_fmt(const char *arg) frame_pix_fmt = avcodec_get_pix_fmt(arg); } -#ifdef CONFIG_NETWORK -void opt_rtp_tcp(void) -{ - /* only tcp protocol */ - rtsp_default_protocols = (1 << RTSP_PROTOCOL_RTP_TCP); -} -#endif - -void opt_sync(const char *arg) +static void opt_sync(const char *arg) { if (!strcmp(arg, "audio")) av_sync_type = AV_SYNC_AUDIO_MASTER; @@ -2426,18 +2404,24 @@ void opt_sync(const char *arg) av_sync_type = AV_SYNC_VIDEO_MASTER; else if (!strcmp(arg, "ext")) av_sync_type = AV_SYNC_EXTERNAL_CLOCK; - else + else { show_help(); + exit(1); + } } -void opt_seek(const char *arg) +static void opt_seek(const char *arg) { start_time = parse_date(arg, 1); + if (start_time == INT64_MIN) { + fprintf(stderr, "Invalid duration specification: %s\n", arg); + exit(1); + } } static void opt_debug(const char *arg) { - av_log_level = 99; + av_log_set_level(99); debug = atoi(arg); } @@ -2454,8 +2438,14 @@ static void opt_thread_count(const char *arg) #endif } +static void opt_show_help(void) +{ + show_help(); + exit(0); +} + const OptionDef options[] = { - { "h", 0, {(void*)show_help}, "show help" }, + { "h", 0, {(void*)opt_show_help}, "show help" }, { "x", HAS_ARG, {(void*)opt_width}, "force displayed width", "width" }, { "y", HAS_ARG, {(void*)opt_height}, "force displayed height", "height" }, { "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" }, @@ -2463,6 +2453,7 @@ const OptionDef options[] = { { "an", OPT_BOOL, {(void*)&audio_disable}, "disable audio" }, { "vn", OPT_BOOL, {(void*)&video_disable}, "disable video" }, { "ast", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&wanted_audio_stream}, "", "" }, + { "vst", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&wanted_video_stream}, "", "" }, { "ss", HAS_ARG, {(void*)&opt_seek}, "seek to a given position in seconds", "pos" }, { "bytes", OPT_BOOL, {(void*)&seek_by_bytes}, "seek by bytes" }, { "nodisp", OPT_BOOL, {(void*)&display_disable}, "disable graphical display" }, @@ -2482,9 +2473,6 @@ const OptionDef options[] = { { "idct", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&idct}, "set idct algo", "algo" }, { "er", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&error_resilience}, "set error detection threshold (0-4)", "threshold" }, { "ec", OPT_INT | HAS_ARG | OPT_EXPERT, {(void*)&error_concealment}, "set error concealment options", "bit_mask" }, -#ifdef CONFIG_NETWORK - { "rtp_tcp", OPT_EXPERT, {(void*)&opt_rtp_tcp}, "force RTP/TCP protocol usage", "" }, -#endif { "sync", HAS_ARG | OPT_EXPERT, {(void*)opt_sync}, "set audio-video sync. type (type=audio/video/ext)", "type" }, { "threads", HAS_ARG | OPT_EXPERT, {(void*)opt_thread_count}, "thread count", "count" }, { NULL, }, @@ -2492,8 +2480,7 @@ const OptionDef options[] = { void show_help(void) { - printf("ffplay version " FFMPEG_VERSION ", Copyright (c) 2003-2006 Fabrice Bellard, et al.\n" - "usage: ffplay [options] input_file\n" + printf("usage: ffplay [options] input_file\n" "Simple media player\n"); printf("\n"); show_help_options(options, "Main options:\n", @@ -2512,13 +2499,12 @@ void show_help(void) "down/up seek backward/forward 1 minute\n" "mouse click seek to percentage in file corresponding to fraction of width\n" ); - exit(1); } -void parse_arg_file(const char *filename) +void opt_input_file(const char *filename) { if (!strcmp(filename, "-")) - filename = "pipe:"; + filename = "pipe:"; input_filename = filename; } @@ -2528,27 +2514,25 @@ int main(int argc, char **argv) int flags; /* register all codecs, demux and protocols */ + avcodec_register_all(); + avdevice_register_all(); av_register_all(); - #ifdef CONFIG_OS2 - MorphToPM(); // Morph the VIO application to a PM one to be able to use Win* functions - - // Make stdout and stderr unbuffered - setbuf( stdout, NULL ); - setbuf( stderr, NULL ); - #endif + show_banner(program_name, program_birth_year); - parse_options(argc, argv, options); + parse_options(argc, argv, options, opt_input_file); - if (!input_filename) + if (!input_filename) { show_help(); + exit(1); + } if (display_disable) { video_disable = 1; } flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER; -#if !defined(__MINGW32__) && !defined(CONFIG_DARWIN) - flags |= SDL_INIT_EVENTTHREAD; /* Not supported on win32 or darwin */ +#if !defined(__MINGW32__) && !defined(__APPLE__) + flags |= SDL_INIT_EVENTTHREAD; /* Not supported on Windows or Mac OS X */ #endif if (SDL_Init (flags)) { fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); diff --git a/contrib/ffmpeg/ffserver.c b/contrib/ffmpeg/ffserver.c index 063ac5a02..6742e5835 100644 --- a/contrib/ffmpeg/ffserver.c +++ b/contrib/ffmpeg/ffserver.c @@ -18,37 +18,47 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#define HAVE_AV_CONFIG_H + +#include "config.h" +#ifndef HAVE_CLOSESOCKET +#define closesocket close +#endif +#include <string.h> +#include <stdlib.h> #include "avformat.h" +#include "rtsp.h" +#include "rtp.h" +#include "os_support.h" #include <stdarg.h> #include <unistd.h> #include <fcntl.h> #include <sys/ioctl.h> -#ifdef HAVE_SYS_POLL_H -#include <sys/poll.h> +#ifdef HAVE_POLL_H +#include <poll.h> #endif #include <errno.h> #include <sys/time.h> #undef time //needed because HAVE_AV_CONFIG_H is defined on top #include <time.h> -#include <sys/types.h> -#include <sys/socket.h> #include <sys/wait.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> #include <signal.h> #ifdef HAVE_DLFCN_H #include <dlfcn.h> #endif +#include "network.h" #include "version.h" #include "ffserver.h" #include "random.h" +#include "avstring.h" +#include "cmdutils.h" #undef exit +static const char program_name[] = "FFserver"; +static const int program_birth_year = 2000; + /* maximum number of simultaneous HTTP connections */ #define HTTP_MAX_CONNECTIONS 2000 @@ -224,18 +234,18 @@ typedef struct FFStream { int conns_served; int64_t bytes_served; int64_t feed_max_size; /* maximum storage size, zero means unlimited */ - int64_t feed_write_index; /* current write position in feed (it wraps round) */ + int64_t feed_write_index; /* current write position in feed (it wraps around) */ int64_t feed_size; /* current size of feed */ struct FFStream *next_feed; } FFStream; typedef struct FeedData { long long data_count; - float avg_frame_size; /* frame size averraged over last frames with exponential mean */ + float avg_frame_size; /* frame size averaged over last frames with exponential mean */ } FeedData; -struct sockaddr_in my_http_addr; -struct sockaddr_in my_rtsp_addr; +static struct sockaddr_in my_http_addr; +static struct sockaddr_in my_rtsp_addr; static char logfilename[1024]; static HTTPContext *first_http_ctx; @@ -339,13 +349,11 @@ static void update_datarate(DataRateData *drd, int64_t count) if (!drd->time1 && !drd->count1) { drd->time1 = drd->time2 = cur_time; drd->count1 = drd->count2 = count; - } else { - if (cur_time - drd->time2 > 5000) { - drd->time1 = drd->time2; - drd->count1 = drd->count2; - drd->time2 = cur_time; - drd->count2 = count; - } + } else if (cur_time - drd->time2 > 5000) { + drd->time1 = drd->time2; + drd->count1 = drd->count2; + drd->time2 = cur_time; + drd->count2 = count; } } @@ -380,9 +388,8 @@ static void start_children(FFStream *feed) char *slash; int i; - for (i = 3; i < 256; i++) { + for (i = 3; i < 256; i++) close(i); - } if (!ffserver_debug) { i = open("/dev/null", O_RDWR); @@ -394,14 +401,13 @@ static void start_children(FFStream *feed) close(i); } - pstrcpy(pathname, sizeof(pathname), my_program_name); + av_strlcpy(pathname, my_program_name, sizeof(pathname)); slash = strrchr(pathname, '/'); - if (!slash) { + if (!slash) slash = pathname; - } else { + else slash++; - } strcpy(slash, "ffmpeg"); /* This is needed to make relative pathnames work */ @@ -444,7 +450,7 @@ static int socket_open_listen(struct sockaddr_in *my_addr) closesocket(server_fd); return -1; } - fcntl(server_fd, F_SETFL, O_NONBLOCK); + ff_socket_nonblock(server_fd, 1); return server_fd; } @@ -477,9 +483,9 @@ static void start_multicast(void) rtp_c = rtp_new_connection(&dest_addr, stream, session_id, RTSP_PROTOCOL_RTP_UDP_MULTICAST); - if (!rtp_c) { + if (!rtp_c) continue; - } + if (open_input_stream(rtp_c, "") < 0) { fprintf(stderr, "Could not open input stream for stream '%s'\n", stream->filename); @@ -592,9 +598,10 @@ static int http_server(void) second to handle timeouts */ do { ret = poll(poll_table, poll_entry - poll_table, delay); - if (ret < 0 && errno != EAGAIN && errno != EINTR) + if (ret < 0 && ff_neterrno() != FF_NETERROR(EAGAIN) && + ff_neterrno() != FF_NETERROR(EINTR)) return -1; - } while (ret <= 0); + } while (ret < 0); cur_time = av_gettime() / 1000; @@ -615,14 +622,12 @@ static int http_server(void) poll_entry = poll_table; /* new HTTP connection request ? */ - if (poll_entry->revents & POLLIN) { + if (poll_entry->revents & POLLIN) new_connection(server_fd, 0); - } poll_entry++; /* new RTSP connection request ? */ - if (poll_entry->revents & POLLIN) { + if (poll_entry->revents & POLLIN) new_connection(rtsp_server_fd, 1); - } } } @@ -652,7 +657,7 @@ static void new_connection(int server_fd, int is_rtsp) &len); if (fd < 0) return; - fcntl(fd, F_SETFL, O_NONBLOCK); + ff_socket_nonblock(fd, 1); /* XXX: should output a warning page when coming close to the connection limit */ @@ -700,11 +705,10 @@ static void close_connection(HTTPContext *c) cp = &first_http_ctx; while ((*cp) != NULL) { c1 = *cp; - if (c1 == c) { + if (c1 == c) *cp = c->next; - } else { + else cp = &c1->next; - } } /* remove references, if any (XXX: do it faster) */ @@ -720,9 +724,8 @@ static void close_connection(HTTPContext *c) /* close each frame parser */ for(i=0;i<c->fmt_in->nb_streams;i++) { st = c->fmt_in->streams[i]; - if (st->codec->codec) { + if (st->codec->codec) avcodec_close(st->codec); - } } av_close_input_file(c->fmt_in); } @@ -739,9 +742,8 @@ static void close_connection(HTTPContext *c) av_free(ctx); } h = c->rtp_handles[i]; - if (h) { + if (h) url_close(h); - } } ctx = &c->fmt_ctx; @@ -751,13 +753,13 @@ static void close_connection(HTTPContext *c) /* prepare header */ if (url_open_dyn_buf(&ctx->pb) >= 0) { av_write_trailer(ctx); - url_close_dyn_buf(&ctx->pb, &c->pb_buffer); + url_close_dyn_buf(ctx->pb, &c->pb_buffer); } } } for(i=0; i<ctx->nb_streams; i++) - av_free(ctx->streams[i]) ; + av_free(ctx->streams[i]); if (c->stream && !c->post && c->stream->stream_type == STREAM_TYPE_LIVE) current_bandwidth -= c->stream->bandwidth; @@ -795,7 +797,8 @@ static int handle_connection(HTTPContext *c) read_loop: len = recv(c->fd, c->buffer_ptr, 1, 0); if (len < 0) { - if (errno != EAGAIN && errno != EINTR) + if (ff_neterrno() != FF_NETERROR(EAGAIN) && + ff_neterrno() != FF_NETERROR(EINTR)) return -1; } else if (len == 0) { return -1; @@ -830,7 +833,8 @@ static int handle_connection(HTTPContext *c) return 0; len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0); if (len < 0) { - if (errno != EAGAIN && errno != EINTR) { + if (ff_neterrno() != FF_NETERROR(EAGAIN) && + ff_neterrno() != FF_NETERROR(EINTR)) { /* error : close connection */ av_freep(&c->pb_buffer); return -1; @@ -843,9 +847,8 @@ static int handle_connection(HTTPContext *c) if (c->buffer_ptr >= c->buffer_end) { av_freep(&c->pb_buffer); /* if error, exit */ - if (c->http_error) { + if (c->http_error) return -1; - } /* all the buffer was sent : synchronize to the incoming stream */ c->state = HTTPSTATE_SEND_DATA_HEADER; c->buffer_ptr = c->buffer_end = c->buffer; @@ -900,7 +903,8 @@ static int handle_connection(HTTPContext *c) return 0; len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0); if (len < 0) { - if (errno != EAGAIN && errno != EINTR) { + if (ff_neterrno() != FF_NETERROR(EAGAIN) && + ff_neterrno() != FF_NETERROR(EINTR)) { /* error : close connection */ av_freep(&c->pb_buffer); return -1; @@ -926,7 +930,8 @@ static int handle_connection(HTTPContext *c) len = send(c->fd, c->packet_buffer_ptr, c->packet_buffer_end - c->packet_buffer_ptr, 0); if (len < 0) { - if (errno != EAGAIN && errno != EINTR) { + if (ff_neterrno() != FF_NETERROR(EAGAIN) && + ff_neterrno() != FF_NETERROR(EINTR)) { /* error : close connection */ av_freep(&c->packet_buffer); return -1; @@ -972,13 +977,12 @@ static int extract_rates(char *rates, int ratelen, const char *request) while (*q && *q != '\n' && *q != ':') q++; - if (sscanf(q, ":%d:%d", &stream_no, &rate_no) != 2) { + if (sscanf(q, ":%d:%d", &stream_no, &rate_no) != 2) break; - } + stream_no--; - if (stream_no < ratelen && stream_no >= 0) { + if (stream_no < ratelen && stream_no >= 0) rates[stream_no] = rate_no; - } while (*q && *q != '\n' && !isspace(*q)) q++; @@ -1009,9 +1013,8 @@ static int find_stream_in_feed(FFStream *feed, AVCodecContext *codec, int bit_ra if (feed_codec->codec_id != codec->codec_id || feed_codec->sample_rate != codec->sample_rate || feed_codec->width != codec->width || - feed_codec->height != codec->height) { + feed_codec->height != codec->height) continue; - } /* Potential stream */ @@ -1120,12 +1123,11 @@ static int validate_acl(FFStream *stream, HTTPContext *c) enum IPAddressAction last_action = IP_DENY; IPAddressACL *acl; struct in_addr *src = &c->from_addr.sin_addr; - unsigned long src_addr = ntohl(src->s_addr); + unsigned long src_addr = src->s_addr; for (acl = stream->acl; acl; acl = acl->next) { - if (src_addr >= acl->first.s_addr && src_addr <= acl->last.s_addr) { + if (src_addr >= acl->first.s_addr && src_addr <= acl->last.s_addr) return (acl->action == IP_ALLOW) ? 1 : 0; - } last_action = acl->action; } @@ -1143,17 +1145,17 @@ static void compute_real_filename(char *filename, int max_size) FFStream *stream; /* compute filename by matching without the file extensions */ - pstrcpy(file1, sizeof(file1), filename); + av_strlcpy(file1, filename, sizeof(file1)); p = strrchr(file1, '.'); if (p) *p = '\0'; for(stream = first_stream; stream != NULL; stream = stream->next) { - pstrcpy(file2, sizeof(file2), stream->filename); + av_strlcpy(file2, stream->filename, sizeof(file2)); p = strrchr(file2, '.'); if (p) *p = '\0'; if (!strcmp(file1, file2)) { - pstrcpy(filename, max_size, stream->filename); + av_strlcpy(filename, stream->filename, max_size); break; } } @@ -1186,7 +1188,7 @@ static int http_parse_request(HTTPContext *c) p = c->buffer; get_word(cmd, sizeof(cmd), (const char **)&p); - pstrcpy(c->method, sizeof(c->method), cmd); + av_strlcpy(c->method, cmd, sizeof(c->method)); if (!strcmp(cmd, "GET")) c->post = 0; @@ -1196,13 +1198,13 @@ static int http_parse_request(HTTPContext *c) return -1; get_word(url, sizeof(url), (const char **)&p); - pstrcpy(c->url, sizeof(c->url), url); + av_strlcpy(c->url, url, sizeof(c->url)); get_word(protocol, sizeof(protocol), (const char **)&p); if (strcmp(protocol, "HTTP/1.0") && strcmp(protocol, "HTTP/1.1")) return -1; - pstrcpy(c->protocol, sizeof(c->protocol), protocol); + av_strlcpy(c->protocol, protocol, sizeof(c->protocol)); if (ffserver_debug) http_log("New connection: %s %s\n", cmd, url); @@ -1210,13 +1212,12 @@ static int http_parse_request(HTTPContext *c) /* find the filename and the optional info string in the request */ p = strchr(url, '?'); if (p) { - pstrcpy(info, sizeof(info), p); + av_strlcpy(info, p, sizeof(info)); *p = '\0'; - } else { + } else info[0] = '\0'; - } - pstrcpy(filename, sizeof(filename)-1, url + ((*url == '/') ? 1 : 0)); + av_strlcpy(filename, url + ((*url == '/') ? 1 : 0), sizeof(filename)-1); for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) { if (strncasecmp(p, "User-Agent:", 11) == 0) { @@ -1253,7 +1254,7 @@ static int http_parse_request(HTTPContext *c) // "redirect" / request to index.html if (!strlen(filename)) - pstrcpy(filename, sizeof(filename) - 1, "index.html"); + av_strlcpy(filename, "index.html", sizeof(filename) - 1); stream = first_stream; while (stream != NULL) { @@ -1298,15 +1299,14 @@ static int http_parse_request(HTTPContext *c) } } - /* If already streaming this feed, dont let start an another feeder */ + /* If already streaming this feed, do not let start another feeder. */ if (stream->feed_opened) { snprintf(msg, sizeof(msg), "This feed is already being received."); goto send_error; } - if (c->post == 0 && stream->stream_type == STREAM_TYPE_LIVE) { + if (c->post == 0 && stream->stream_type == STREAM_TYPE_LIVE) current_bandwidth += stream->bandwidth; - } if (c->post == 0 && max_bandwidth < current_bandwidth) { c->http_error = 200; @@ -1391,7 +1391,7 @@ static int http_parse_request(HTTPContext *c) { char hostname[256], *p; /* extract only hostname */ - pstrcpy(hostname, sizeof(hostname), hostbuf); + av_strlcpy(hostname, hostbuf, sizeof(hostname)); p = strrchr(hostname, ':'); if (p) *p = '\0'; @@ -1430,7 +1430,7 @@ static int http_parse_request(HTTPContext *c) } break; default: - av_abort(); + abort(); break; } @@ -1465,9 +1465,8 @@ static int http_parse_request(HTTPContext *c) logline = p; break; } - if (strncasecmp(p, "Pragma: client-id=", 18) == 0) { + if (strncasecmp(p, "Pragma: client-id=", 18) == 0) client_id = strtol(p + 18, 0, 10); - } p = strchr(p, '\n'); if (!p) break; @@ -1501,11 +1500,8 @@ static int http_parse_request(HTTPContext *c) break; } - if (wmpc) { - if (modify_current_stream(wmpc, ratebuf)) { - wmpc->switch_pending = 1; - } - } + if (wmpc && modify_current_stream(wmpc, ratebuf)) + wmpc->switch_pending = 1; } snprintf(msg, sizeof(msg), "POST command not handled"); @@ -1522,9 +1518,8 @@ static int http_parse_request(HTTPContext *c) } #ifdef DEBUG_WMP - if (strcmp(stream->filename + strlen(stream->filename) - 4, ".asf") == 0) { + if (strcmp(stream->filename + strlen(stream->filename) - 4, ".asf") == 0) http_log("\nGot request:\n%s\n", c->buffer); - } #endif if (c->stream->stream_type == STREAM_TYPE_STATUS) @@ -1590,8 +1585,7 @@ static void fmt_bytecount(ByteIOContext *pb, int64_t count) static const char *suffix = " kMGTP"; const char *s; - for (s = suffix; count >= 100000 && s[1]; count /= 1000, s++) { - } + for (s = suffix; count >= 100000 && s[1]; count /= 1000, s++); url_fprintf(pb, "%"PRId64"%c", count, *s); } @@ -1603,9 +1597,9 @@ static void compute_stats(HTTPContext *c) char *p; time_t ti; int i, len; - ByteIOContext pb1, *pb = &pb1; + ByteIOContext *pb; - if (url_open_dyn_buf(pb) < 0) { + if (url_open_dyn_buf(&pb) < 0) { /* XXX: return an error ? */ c->buffer_ptr = c->buffer; c->buffer_end = c->buffer; @@ -1618,9 +1612,8 @@ static void compute_stats(HTTPContext *c) url_fprintf(pb, "\r\n"); url_fprintf(pb, "<HEAD><TITLE>FFServer Status\n"); - if (c->stream->feed_filename) { + if (c->stream->feed_filename) url_fprintf(pb, "\n", c->stream->feed_filename); - } url_fprintf(pb, "\n"); url_fprintf(pb, "

FFServer Status

\n"); /* format status */ @@ -1633,14 +1626,14 @@ static void compute_stats(HTTPContext *c) char *eosf; if (stream->feed != stream) { - pstrcpy(sfilename, sizeof(sfilename) - 10, stream->filename); + av_strlcpy(sfilename, stream->filename, sizeof(sfilename) - 10); eosf = sfilename + strlen(sfilename); if (eosf - sfilename >= 4) { - if (strcmp(eosf - 4, ".asf") == 0) { + if (strcmp(eosf - 4, ".asf") == 0) strcpy(eosf - 4, ".asx"); - } else if (strcmp(eosf - 3, ".rm") == 0) { + else if (strcmp(eosf - 3, ".rm") == 0) strcpy(eosf - 3, ".ram"); - } else if (stream->fmt == &rtp_muxer) { + else if (stream->fmt && !strcmp(stream->fmt->name, "rtp")) { /* generate a sample RTSP director if unicast. Generate an SDP redirector if multicast */ @@ -1693,7 +1686,7 @@ static void compute_stats(HTTPContext *c) video_bit_rate += st->codec->bit_rate; break; default: - av_abort(); + abort(); } } url_fprintf(pb, " %s %d %d %s %s %d %s %s", @@ -1701,11 +1694,10 @@ static void compute_stats(HTTPContext *c) stream->bandwidth, video_bit_rate / 1000, video_codec_name, video_codec_name_extra, audio_bit_rate / 1000, audio_codec_name, audio_codec_name_extra); - if (stream->feed) { + if (stream->feed) url_fprintf(pb, "%s", stream->feed->filename); - } else { + else url_fprintf(pb, "%s", stream->feed_filename); - } url_fprintf(pb, "\n"); } break; @@ -1773,7 +1765,7 @@ static void compute_stats(HTTPContext *c) st->codec->qmin, st->codec->qmax, st->codec->time_base.den / st->codec->time_base.num); break; default: - av_abort(); + abort(); } url_fprintf(pb, "%d%s%d%s%s\n", i, type, st->codec->bit_rate/1000, codec ? codec->name : "", parameters); @@ -1834,13 +1826,10 @@ static void compute_stats(HTTPContext *c) bitrate = 0; if (c1->stream) { for (j = 0; j < c1->stream->nb_streams; j++) { - if (!c1->stream->feed) { + if (!c1->stream->feed) bitrate += c1->stream->streams[j]->codec->bit_rate; - } else { - if (c1->feed_streams[j] >= 0) { - bitrate += c1->stream->feed->streams[c1->feed_streams[j]]->codec->bit_rate; - } - } + else if (c1->feed_streams[j] >= 0) + bitrate += c1->stream->feed->streams[c1->feed_streams[j]]->codec->bit_rate; } } @@ -1884,9 +1873,8 @@ static void open_parser(AVFormatContext *s, int i) codec = avcodec_find_decoder(st->codec->codec_id); if (codec && (codec->capabilities & CODEC_CAP_PARSE_ONLY)) { st->codec->parse_only = 1; - if (avcodec_open(st->codec, codec) < 0) { + if (avcodec_open(st->codec, codec) < 0) st->codec->parse_only = 0; - } } } } @@ -1904,23 +1892,29 @@ static int open_input_stream(HTTPContext *c, const char *info) strcpy(input_filename, c->stream->feed->feed_filename); buf_size = FFM_PACKET_SIZE; /* compute position (absolute time) */ - if (find_info_tag(buf, sizeof(buf), "date", info)) { + if (find_info_tag(buf, sizeof(buf), "date", info)) + { stream_pos = parse_date(buf, 0); - } else if (find_info_tag(buf, sizeof(buf), "buffer", info)) { + if (stream_pos == INT64_MIN) + return -1; + } + else if (find_info_tag(buf, sizeof(buf), "buffer", info)) { int prebuffer = strtol(buf, 0, 10); stream_pos = av_gettime() - prebuffer * (int64_t)1000000; - } else { + } else stream_pos = av_gettime() - c->stream->prebuffer * (int64_t)1000; - } } else { strcpy(input_filename, c->stream->feed_filename); buf_size = 0; /* compute position (relative time) */ - if (find_info_tag(buf, sizeof(buf), "date", info)) { + if (find_info_tag(buf, sizeof(buf), "date", info)) + { stream_pos = parse_date(buf, 1); - } else { - stream_pos = 0; + if (stream_pos == INT64_MIN) + return -1; } + else + stream_pos = 0; } if (input_filename[0] == '\0') return -1; @@ -1937,7 +1931,9 @@ static int open_input_stream(HTTPContext *c, const char *info) http_log("%s not found", input_filename); return -1; } + s->flags |= AVFMT_FLAG_GENPTS; c->fmt_in = s; + av_find_stream_info(c->fmt_in); /* open each parser */ for(i=0;inb_streams;i++) @@ -1954,9 +1950,8 @@ static int open_input_stream(HTTPContext *c, const char *info) } #if 1 - if (c->fmt_in->iformat->read_seek) { + if (c->fmt_in->iformat->read_seek) c->fmt_in->iformat->read_seek(c->fmt_in, 0, stream_pos, 0); - } #endif /* set the start time (needed for maxtime and RTP packet timing) */ c->start_time = cur_time; @@ -1978,9 +1973,9 @@ static int64_t get_packet_send_clock(HTTPContext *c) int bytes_left, bytes_sent, frame_bytes; frame_bytes = c->cur_frame_bytes; - if (frame_bytes <= 0) { + if (frame_bytes <= 0) return c->cur_pts; - } else { + else { bytes_left = c->buffer_end - c->buffer_ptr; bytes_sent = frame_bytes - bytes_left; return c->cur_pts + (c->cur_frame_duration * bytes_sent) / frame_bytes; @@ -1997,14 +1992,14 @@ static int http_prepare_data(HTTPContext *c) switch(c->state) { case HTTPSTATE_SEND_DATA_HEADER: memset(&c->fmt_ctx, 0, sizeof(c->fmt_ctx)); - pstrcpy(c->fmt_ctx.author, sizeof(c->fmt_ctx.author), - c->stream->author); - pstrcpy(c->fmt_ctx.comment, sizeof(c->fmt_ctx.comment), - c->stream->comment); - pstrcpy(c->fmt_ctx.copyright, sizeof(c->fmt_ctx.copyright), - c->stream->copyright); - pstrcpy(c->fmt_ctx.title, sizeof(c->fmt_ctx.title), - c->stream->title); + av_strlcpy(c->fmt_ctx.author, c->stream->author, + sizeof(c->fmt_ctx.author)); + av_strlcpy(c->fmt_ctx.comment, c->stream->comment, + sizeof(c->fmt_ctx.comment)); + av_strlcpy(c->fmt_ctx.copyright, c->stream->copyright, + sizeof(c->fmt_ctx.copyright)); + av_strlcpy(c->fmt_ctx.title, c->stream->title, + sizeof(c->fmt_ctx.title)); /* open output stream by using specified codecs */ c->fmt_ctx.oformat = c->stream->fmt; @@ -2038,13 +2033,13 @@ static int http_prepare_data(HTTPContext *c) /* XXX: potential leak */ return -1; } - c->fmt_ctx.pb.is_streamed = 1; + c->fmt_ctx.pb->is_streamed = 1; av_set_parameters(&c->fmt_ctx, NULL); if (av_write_header(&c->fmt_ctx) < 0) return -1; - len = url_close_dyn_buf(&c->fmt_ctx.pb, &c->pb_buffer); + len = url_close_dyn_buf(c->fmt_ctx.pb, &c->pb_buffer); c->buffer_ptr = c->pb_buffer; c->buffer_end = c->pb_buffer + len; @@ -2057,17 +2052,16 @@ static int http_prepare_data(HTTPContext *c) AVPacket pkt; /* read a packet from the input stream */ - if (c->stream->feed) { + if (c->stream->feed) ffm_set_write_index(c->fmt_in, c->stream->feed->feed_write_index, c->stream->feed->feed_size); - } if (c->stream->max_time && - c->stream->max_time + c->start_time - cur_time < 0) { + c->stream->max_time + c->start_time - cur_time < 0) /* We have timed out */ c->state = HTTPSTATE_SEND_DATA_TRAILER; - } else { + else { redo: if (av_read_frame(c->fmt_in, &pkt) < 0) { if (c->stream->feed && c->stream->feed->feed_opened) { @@ -2100,22 +2094,18 @@ static int http_prepare_data(HTTPContext *c) if (c->switch_pending) { c->switch_pending = 0; for(i=0;istream->nb_streams;i++) { - if (c->switch_feed_streams[i] == pkt.stream_index) { - if (pkt.flags & PKT_FLAG_KEY) { + if (c->switch_feed_streams[i] == pkt.stream_index) + if (pkt.flags & PKT_FLAG_KEY) do_switch_stream(c, i); - } - } - if (c->switch_feed_streams[i] >= 0) { + if (c->switch_feed_streams[i] >= 0) c->switch_pending = 1; - } } } for(i=0;istream->nb_streams;i++) { if (c->feed_streams[i] == pkt.stream_index) { pkt.stream_index = i; - if (pkt.flags & PKT_FLAG_KEY) { + if (pkt.flags & PKT_FLAG_KEY) c->got_key_frame |= 1 << i; - } /* See if we have all the key frames, then * we start to send. This logic is not quite * right, but it works for the case of a @@ -2124,9 +2114,8 @@ static int http_prepare_data(HTTPContext *c) * typically a key frame). */ if (!c->stream->send_on_key || - ((c->got_key_frame + 1) >> c->stream->nb_streams)) { + ((c->got_key_frame + 1) >> c->stream->nb_streams)) goto send_it; - } } } } else { @@ -2191,11 +2180,10 @@ static int http_prepare_data(HTTPContext *c) pkt.pts = av_rescale_q(pkt.pts, c->fmt_in->streams[pkt.stream_index]->time_base, ctx->streams[pkt.stream_index]->time_base); - if (av_write_frame(ctx, &pkt)) { + if (av_write_frame(ctx, &pkt)) c->state = HTTPSTATE_SEND_DATA_TRAILER; - } - len = url_close_dyn_buf(&ctx->pb, &c->pb_buffer); + len = url_close_dyn_buf(ctx->pb, &c->pb_buffer); c->cur_frame_bytes = len; c->buffer_ptr = c->pb_buffer; c->buffer_end = c->pb_buffer + len; @@ -2221,7 +2209,7 @@ static int http_prepare_data(HTTPContext *c) return -1; } av_write_trailer(ctx); - len = url_close_dyn_buf(&ctx->pb, &c->pb_buffer); + len = url_close_dyn_buf(ctx->pb, &c->pb_buffer); c->buffer_ptr = c->pb_buffer; c->buffer_end = c->pb_buffer + len; @@ -2243,10 +2231,9 @@ static int http_send_data(HTTPContext *c) ret = http_prepare_data(c); if (ret < 0) return -1; - else if (ret != 0) { + else if (ret != 0) /* state change requested */ break; - } } else { if (c->is_packetized) { /* RTP data output */ @@ -2275,7 +2262,7 @@ static int http_send_data(HTTPContext *c) if (c->rtp_protocol == RTSP_PROTOCOL_RTP_TCP) { /* RTP packets are sent inside the RTSP TCP connection */ - ByteIOContext pb1, *pb = &pb1; + ByteIOContext *pb; int interleaved_index, size; uint8_t header[4]; HTTPContext *rtsp_c; @@ -2285,10 +2272,9 @@ static int http_send_data(HTTPContext *c) if (!rtsp_c) return -1; /* if already sending something, then wait. */ - if (rtsp_c->state != RTSPSTATE_WAIT_REQUEST) { + if (rtsp_c->state != RTSPSTATE_WAIT_REQUEST) break; - } - if (url_open_dyn_buf(pb) < 0) + if (url_open_dyn_buf(&pb) < 0) goto fail1; interleaved_index = c->packet_stream_index * 2; /* RTCP packets are sent at odd indexes */ @@ -2312,19 +2298,17 @@ static int http_send_data(HTTPContext *c) /* send everything we can NOW */ len = send(rtsp_c->fd, rtsp_c->packet_buffer_ptr, rtsp_c->packet_buffer_end - rtsp_c->packet_buffer_ptr, 0); - if (len > 0) { + if (len > 0) rtsp_c->packet_buffer_ptr += len; - } if (rtsp_c->packet_buffer_ptr < rtsp_c->packet_buffer_end) { /* if we could not send all the data, we will send it later, so a new state is needed to "lock" the RTSP TCP connection */ rtsp_c->state = RTSPSTATE_SEND_PACKET; break; - } else { + } else /* all data has been sent */ av_freep(&c->packet_buffer); - } } else { /* send RTP packet directly in UDP */ c->buffer_ptr += 4; @@ -2337,15 +2321,15 @@ static int http_send_data(HTTPContext *c) /* TCP data output */ len = send(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0); if (len < 0) { - if (errno != EAGAIN && errno != EINTR) { + if (ff_neterrno() != FF_NETERROR(EAGAIN) && + ff_neterrno() != FF_NETERROR(EINTR)) /* error : close connection */ return -1; - } else { + else return 0; - } - } else { + } else c->buffer_ptr += len; - } + c->data_count += len; update_datarate(&c->datarate, c->data_count); if (c->stream) @@ -2394,14 +2378,14 @@ static int http_receive_data(HTTPContext *c) len = recv(c->fd, c->buffer_ptr, c->buffer_end - c->buffer_ptr, 0); if (len < 0) { - if (errno != EAGAIN && errno != EINTR) { + if (ff_neterrno() != FF_NETERROR(EAGAIN) && + ff_neterrno() != FF_NETERROR(EINTR)) /* error : close connection */ goto fail; - } - } else if (len == 0) { + } else if (len == 0) /* end of connection : close it */ goto fail; - } else { + else { c->buffer_ptr += len; c->data_count += len; update_datarate(&c->datarate, c->data_count); @@ -2442,22 +2426,19 @@ static int http_receive_data(HTTPContext *c) /* wake up any waiting connections */ for(c1 = first_http_ctx; c1 != NULL; c1 = c1->next) { if (c1->state == HTTPSTATE_WAIT_FEED && - c1->stream->feed == c->stream->feed) { + c1->stream->feed == c->stream->feed) c1->state = HTTPSTATE_SEND_DATA; - } } } else { /* We have a header in our hands that contains useful data */ AVFormatContext s; AVInputFormat *fmt_in; - ByteIOContext *pb = &s.pb; int i; memset(&s, 0, sizeof(s)); - url_open_buf(pb, c->buffer, c->buffer_end - c->buffer, URL_RDONLY); - pb->buf_end = c->buffer_end; /* ?? */ - pb->is_streamed = 1; + url_open_buf(&s.pb, c->buffer, c->buffer_end - c->buffer, URL_RDONLY); + s.pb->is_streamed = 1; /* use feed output format name to find corresponding input format */ fmt_in = av_find_input_format(feed->fmt->name); @@ -2481,10 +2462,9 @@ static int http_receive_data(HTTPContext *c) av_freep(&s.priv_data); goto fail; } - for (i = 0; i < s.nb_streams; i++) { + for (i = 0; i < s.nb_streams; i++) memcpy(feed->streams[i]->codec, s.streams[i]->codec, sizeof(AVCodecContext)); - } av_freep(&s.priv_data); } c->buffer_ptr = c->buffer; @@ -2508,9 +2488,39 @@ static void rtsp_reply_header(HTTPContext *c, enum RTSPStatusCode error_number) char buf2[32]; switch(error_number) { -#define DEF(n, c, s) case c: str = s; break; -#include "rtspcodes.h" -#undef DEF + case RTSP_STATUS_OK: + str = "OK"; + break; + case RTSP_STATUS_METHOD: + str = "Method Not Allowed"; + break; + case RTSP_STATUS_BANDWIDTH: + str = "Not Enough Bandwidth"; + break; + case RTSP_STATUS_SESSION: + str = "Session Not Found"; + break; + case RTSP_STATUS_STATE: + str = "Method Not Valid in This State"; + break; + case RTSP_STATUS_AGGREGATE: + str = "Aggregate operation not allowed"; + break; + case RTSP_STATUS_ONLY_AGGREGATE: + str = "Only aggregate operation allowed"; + break; + case RTSP_STATUS_TRANSPORT: + str = "Unsupported transport"; + break; + case RTSP_STATUS_INTERNAL: + str = "Internal Server Error"; + break; + case RTSP_STATUS_SERVICE: + str = "Service Unavailable"; + break; + case RTSP_STATUS_VERSION: + str = "RTSP Version not supported"; + break; default: str = "Unknown Error"; break; @@ -2542,7 +2552,6 @@ static int rtsp_parse_request(HTTPContext *c) char url[1024]; char protocol[32]; char line[1024]; - ByteIOContext pb1; int len; RTSPHeader header1, *header = &header1; @@ -2553,12 +2562,11 @@ static int rtsp_parse_request(HTTPContext *c) get_word(url, sizeof(url), &p); get_word(protocol, sizeof(protocol), &p); - pstrcpy(c->method, sizeof(c->method), cmd); - pstrcpy(c->url, sizeof(c->url), url); - pstrcpy(c->protocol, sizeof(c->protocol), protocol); + av_strlcpy(c->method, cmd, sizeof(c->method)); + av_strlcpy(c->url, url, sizeof(c->url)); + av_strlcpy(c->protocol, protocol, sizeof(c->protocol)); - c->pb = &pb1; - if (url_open_dyn_buf(c->pb) < 0) { + if (url_open_dyn_buf(&c->pb) < 0) { /* XXX: cannot do more */ c->pb = NULL; /* safety */ return -1; @@ -2599,21 +2607,21 @@ static int rtsp_parse_request(HTTPContext *c) /* handle sequence number */ c->seq = header->seq; - if (!strcmp(cmd, "DESCRIBE")) { + if (!strcmp(cmd, "DESCRIBE")) rtsp_cmd_describe(c, url); - } else if (!strcmp(cmd, "OPTIONS")) { + else if (!strcmp(cmd, "OPTIONS")) rtsp_cmd_options(c, url); - } else if (!strcmp(cmd, "SETUP")) { + else if (!strcmp(cmd, "SETUP")) rtsp_cmd_setup(c, url, header); - } else if (!strcmp(cmd, "PLAY")) { + else if (!strcmp(cmd, "PLAY")) rtsp_cmd_play(c, url, header); - } else if (!strcmp(cmd, "PAUSE")) { + else if (!strcmp(cmd, "PAUSE")) rtsp_cmd_pause(c, url, header); - } else if (!strcmp(cmd, "TEARDOWN")) { + else if (!strcmp(cmd, "TEARDOWN")) rtsp_cmd_teardown(c, url, header); - } else { + else rtsp_reply_error(c, RTSP_STATUS_METHOD); - } + the_end: len = url_close_dyn_buf(c->pb, &c->pb_buffer); c->pb = NULL; /* safety */ @@ -2627,95 +2635,38 @@ static int rtsp_parse_request(HTTPContext *c) return 0; } -/* XXX: move that to rtsp.c, but would need to replace FFStream by - AVFormatContext */ static int prepare_sdp_description(FFStream *stream, uint8_t **pbuffer, struct in_addr my_ip) { - ByteIOContext pb1, *pb = &pb1; - int i, payload_type, port, private_payload_type, j; - const char *ipstr, *title, *mediatype; - AVStream *st; + AVFormatContext *avc; + AVStream avs[MAX_STREAMS]; + int i; - if (url_open_dyn_buf(pb) < 0) + avc = av_alloc_format_context(); + if (avc == NULL) { return -1; - - /* general media info */ - - url_fprintf(pb, "v=0\n"); - ipstr = inet_ntoa(my_ip); - url_fprintf(pb, "o=- 0 0 IN IP4 %s\n", ipstr); - title = stream->title; - if (title[0] == '\0') - title = "No Title"; - url_fprintf(pb, "s=%s\n", title); - if (stream->comment[0] != '\0') - url_fprintf(pb, "i=%s\n", stream->comment); + } + if (stream->title[0] != 0) { + av_strlcpy(avc->title, stream->title, sizeof(avc->title)); + } else { + av_strlcpy(avc->title, "No Title", sizeof(avc->title)); + } + avc->nb_streams = stream->nb_streams; if (stream->is_multicast) { - url_fprintf(pb, "c=IN IP4 %s\n", inet_ntoa(stream->multicast_ip)); + snprintf(avc->filename, 1024, "rtp://%s:%d?multicast=1?ttl=%d", + inet_ntoa(stream->multicast_ip), + stream->multicast_port, stream->multicast_ttl); } - /* for each stream, we output the necessary info */ - private_payload_type = RTP_PT_PRIVATE; + for(i = 0; i < stream->nb_streams; i++) { - st = stream->streams[i]; - if (st->codec->codec_id == CODEC_ID_MPEG2TS) { - mediatype = "video"; - } else { - switch(st->codec->codec_type) { - case CODEC_TYPE_AUDIO: - mediatype = "audio"; - break; - case CODEC_TYPE_VIDEO: - mediatype = "video"; - break; - default: - mediatype = "application"; - break; - } - } - /* NOTE: the port indication is not correct in case of - unicast. It is not an issue because RTSP gives it */ - payload_type = rtp_get_payload_type(st->codec); - if (payload_type < 0) - payload_type = private_payload_type++; - if (stream->is_multicast) { - port = stream->multicast_port + 2 * i; - } else { - port = 0; - } - url_fprintf(pb, "m=%s %d RTP/AVP %d\n", - mediatype, port, payload_type); - if (payload_type >= RTP_PT_PRIVATE) { - /* for private payload type, we need to give more info */ - switch(st->codec->codec_id) { - case CODEC_ID_MPEG4: - { - uint8_t *data; - url_fprintf(pb, "a=rtpmap:%d MP4V-ES/%d\n", - payload_type, 90000); - /* we must also add the mpeg4 header */ - data = st->codec->extradata; - if (data) { - url_fprintf(pb, "a=fmtp:%d config=", payload_type); - for(j=0;jcodec->extradata_size;j++) { - url_fprintf(pb, "%02x", data[j]); - } - url_fprintf(pb, "\n"); - } - } - break; - default: - /* XXX: add other codecs ? */ - goto fail; - } - } - url_fprintf(pb, "a=control:streamid=%d\n", i); + avc->streams[i] = &avs[i]; + avc->streams[i]->codec = stream->streams[i]->codec; } - return url_close_dyn_buf(pb, pbuffer); - fail: - url_close_dyn_buf(pb, pbuffer); - av_free(*pbuffer); - return -1; + *pbuffer = av_mallocz(2048); + avf_sdp_create(&avc, 1, *pbuffer, 2048); + av_free(avc); + + return strlen(*pbuffer); } static void rtsp_cmd_options(HTTPContext *c, const char *url) @@ -2743,7 +2694,8 @@ static void rtsp_cmd_describe(HTTPContext *c, const char *url) path++; for(stream = first_stream; stream != NULL; stream = stream->next) { - if (!stream->is_feed && stream->fmt == &rtp_muxer && + if (!stream->is_feed && + stream->fmt && !strcmp(stream->fmt->name, "rtp") && !strcmp(path, stream->filename)) { goto found; } @@ -2818,7 +2770,8 @@ static void rtsp_cmd_setup(HTTPContext *c, const char *url, /* now check each stream */ for(stream = first_stream; stream != NULL; stream = stream->next) { - if (!stream->is_feed && stream->fmt == &rtp_muxer) { + if (!stream->is_feed && + stream->fmt && !strcmp(stream->fmt->name, "rtp")) { /* accept aggregate filenames only if single stream */ if (!strcmp(path, stream->filename)) { if (stream->nb_streams != 1) { @@ -2844,10 +2797,9 @@ static void rtsp_cmd_setup(HTTPContext *c, const char *url, found: /* generate session id if needed */ - if (h->session_id[0] == '\0') { + if (h->session_id[0] == '\0') snprintf(h->session_id, sizeof(h->session_id), "%08x%08x", av_random(&random_state), av_random(&random_state)); - } /* find rtp session, and create it if none found */ rtp_c = find_rtp_session(h->session_id); @@ -2902,18 +2854,6 @@ static void rtsp_cmd_setup(HTTPContext *c, const char *url, dest_addr = rtp_c->from_addr; dest_addr.sin_port = htons(th->client_port_min); - /* add transport option if needed */ - if (ff_rtsp_callback) { - setup.ipaddr = ntohl(dest_addr.sin_addr.s_addr); - if (ff_rtsp_callback(RTSP_ACTION_SERVER_SETUP, rtp_c->session_id, - (char *)&setup, sizeof(setup), - stream->rtsp_option) < 0) { - rtsp_reply_error(c, RTSP_STATUS_TRANSPORT); - return; - } - dest_addr.sin_addr.s_addr = htonl(setup.ipaddr); - } - /* setup stream */ if (rtp_new_av_stream(rtp_c, stream_index, &dest_addr, c) < 0) { rtsp_reply_error(c, RTSP_STATUS_TRANSPORT); @@ -2940,9 +2880,8 @@ static void rtsp_cmd_setup(HTTPContext *c, const char *url, default: break; } - if (setup.transport_option[0] != '\0') { + if (setup.transport_option[0] != '\0') url_fprintf(c->pb, ";%s", setup.transport_option); - } url_fprintf(c->pb, "\r\n"); @@ -3044,6 +2983,7 @@ static void rtsp_cmd_pause(HTTPContext *c, const char *url, RTSPHeader *h) static void rtsp_cmd_teardown(HTTPContext *c, const char *url, RTSPHeader *h) { HTTPContext *rtp_c; + char session_id[32]; rtp_c = find_rtp_session_with_url(url, h->session_id); if (!rtp_c) { @@ -3051,19 +2991,15 @@ static void rtsp_cmd_teardown(HTTPContext *c, const char *url, RTSPHeader *h) return; } + av_strlcpy(session_id, rtp_c->session_id, sizeof(session_id)); + /* abort the session */ close_connection(rtp_c); - if (ff_rtsp_callback) { - ff_rtsp_callback(RTSP_ACTION_SERVER_TEARDOWN, rtp_c->session_id, - NULL, 0, - rtp_c->stream->rtsp_option); - } - /* now everything is OK, so we can send the connection parameters */ rtsp_reply_header(c, RTSP_STATUS_OK); /* session ID */ - url_fprintf(c->pb, "Session: %s\r\n", rtp_c->session_id); + url_fprintf(c->pb, "Session: %s\r\n", session_id); url_fprintf(c->pb, "\r\n"); } @@ -3097,7 +3033,7 @@ static HTTPContext *rtp_new_connection(struct sockaddr_in *from_addr, goto fail; nb_connections++; c->stream = stream; - pstrcpy(c->session_id, sizeof(c->session_id), session_id); + av_strlcpy(c->session_id, session_id, sizeof(c->session_id)); c->state = HTTPSTATE_READY; c->is_packetized = 1; c->rtp_protocol = rtp_protocol; @@ -3117,8 +3053,8 @@ static HTTPContext *rtp_new_connection(struct sockaddr_in *from_addr, proto_str = "???"; break; } - pstrcpy(c->protocol, sizeof(c->protocol), "RTP/"); - pstrcat(c->protocol, sizeof(c->protocol), proto_str); + av_strlcpy(c->protocol, "RTP/", sizeof(c->protocol)); + av_strlcat(c->protocol, proto_str, sizeof(c->protocol)); current_bandwidth += stream->bandwidth; @@ -3153,7 +3089,7 @@ static int rtp_new_av_stream(HTTPContext *c, ctx = av_alloc_format_context(); if (!ctx) return -1; - ctx->oformat = &rtp_muxer; + ctx->oformat = guess_format("rtp", NULL, NULL); st = av_mallocz(sizeof(AVStream)); if (!st) @@ -3163,13 +3099,13 @@ static int rtp_new_av_stream(HTTPContext *c, ctx->streams[0] = st; if (!c->stream->feed || - c->stream->feed == c->stream) { + c->stream->feed == c->stream) memcpy(st, c->stream->streams[stream_index], sizeof(AVStream)); - } else { + else memcpy(st, c->stream->feed->streams[c->stream->feed_streams[stream_index]], sizeof(AVStream)); - } + st->priv_data = NULL; /* build destination RTP address */ ipaddr = inet_ntoa(dest_addr->sin_addr); @@ -3225,7 +3161,7 @@ static int rtp_new_av_stream(HTTPContext *c, av_free(ctx); return -1; } - url_close_dyn_buf(&ctx->pb, &dummy_buf); + url_close_dyn_buf(ctx->pb, &dummy_buf); av_free(dummy_buf); c->rtp_ctx[stream_index] = ctx; @@ -3282,7 +3218,7 @@ static int add_av_stream(FFStream *feed, AVStream *st) goto found; break; default: - av_abort(); + abort(); } } } @@ -3300,11 +3236,10 @@ static void remove_stream(FFStream *stream) FFStream **ps; ps = &first_stream; while (*ps != NULL) { - if (*ps == stream) { + if (*ps == stream) *ps = (*ps)->next; - } else { + else ps = &(*ps)->next; - } } } @@ -3373,7 +3308,7 @@ static void build_file_streams(void) /* try to open the file */ /* open stream */ stream->ap_in = av_mallocz(sizeof(AVFormatParameters)); - if (stream->fmt == &rtp_muxer) { + if (stream->fmt && !strcmp(stream->fmt->name, "rtp")) { /* specific case : if transport stream output to RTP, we use a raw transport stream reader */ stream->ap_in->mpeg2ts_raw = 1; @@ -3397,9 +3332,9 @@ static void build_file_streams(void) } extract_mpeg4_header(infile); - for(i=0;inb_streams;i++) { + for(i=0;inb_streams;i++) add_av_stream1(stream, infile->streams[i]->codec); - } + av_close_input_file(infile); } } @@ -3418,9 +3353,8 @@ static void build_feed_streams(void) if (feed) { if (!stream->is_feed) { /* we handle a stream coming from a feed */ - for(i=0;inb_streams;i++) { + for(i=0;inb_streams;i++) stream->feed_streams[i] = add_av_stream(feed, stream->streams[i]); - } } } } @@ -3430,9 +3364,8 @@ static void build_feed_streams(void) feed = stream->feed; if (feed) { if (stream->is_feed) { - for(i=0;inb_streams;i++) { + for(i=0;inb_streams;i++) stream->feed_streams[i] = i; - } } } } @@ -3493,20 +3426,18 @@ static void build_feed_streams(void) matches = 0; } } - if (!matches) { + if (!matches) break; - } } - } else { + } else printf("Deleting feed file '%s' as stream counts differ (%d != %d)\n", feed->feed_filename, s->nb_streams, feed->nb_streams); - } av_close_input_file(s); - } else { + } else printf("Deleting feed file '%s' as it appears to be corrupt\n", feed->feed_filename); - } + if (!matches) { if (feed->readonly) { printf("Unable to delete feed file '%s' as it is marked readonly\n", @@ -3545,7 +3476,7 @@ static void build_feed_streams(void) } /* XXX: need better api */ av_freep(&s->priv_data); - url_fclose(&s->pb); + url_fclose(s->pb); } /* get feed size and write index */ fd = open(feed->feed_filename, O_RDONLY); @@ -3683,7 +3614,7 @@ static void add_codec(FFStream *stream, AVCodecContext *av) break; default: - av_abort(); + abort(); } st = av_mallocz(sizeof(AVStream)); @@ -3696,34 +3627,20 @@ static void add_codec(FFStream *stream, AVCodecContext *av) static int opt_audio_codec(const char *arg) { - AVCodec *p; + AVCodec *p= avcodec_find_encoder_by_name(arg); - p = first_avcodec; - while (p) { - if (!strcmp(p->name, arg) && p->type == CODEC_TYPE_AUDIO) - break; - p = p->next; - } - if (p == NULL) { + if (p == NULL || p->type != CODEC_TYPE_AUDIO) return CODEC_ID_NONE; - } return p->id; } static int opt_video_codec(const char *arg) { - AVCodec *p; + AVCodec *p= avcodec_find_encoder_by_name(arg); - p = first_avcodec; - while (p) { - if (!strcmp(p->name, arg) && p->type == CODEC_TYPE_VIDEO) - break; - p = p->next; - } - if (p == NULL) { + if (p == NULL || p->type != CODEC_TYPE_VIDEO) return CODEC_ID_NONE; - } return p->id; } @@ -3798,11 +3715,17 @@ static int parse_ffconfig(const char *filename) if (!strcasecmp(cmd, "Port")) { get_arg(arg, sizeof(arg), &p); - my_http_addr.sin_port = htons (atoi(arg)); + val = atoi(arg); + if (val < 1 || val > 65536) { + fprintf(stderr, "%s:%d: Invalid port: %s\n", + filename, line_num, arg); + errors++; + } + my_http_addr.sin_port = htons(val); } else if (!strcasecmp(cmd, "BindAddress")) { get_arg(arg, sizeof(arg), &p); - if (!inet_aton(arg, &my_http_addr.sin_addr)) { - fprintf(stderr, "%s:%d: Invalid IP address: %s\n", + if (resolve_host(&my_http_addr.sin_addr, arg) != 0) { + fprintf(stderr, "%s:%d: Invalid host/IP address: %s\n", filename, line_num, arg); errors++; } @@ -3810,11 +3733,17 @@ static int parse_ffconfig(const char *filename) ffserver_daemon = 0; } else if (!strcasecmp(cmd, "RTSPPort")) { get_arg(arg, sizeof(arg), &p); - my_rtsp_addr.sin_port = htons (atoi(arg)); + val = atoi(arg); + if (val < 1 || val > 65536) { + fprintf(stderr, "%s:%d: Invalid port: %s\n", + filename, line_num, arg); + errors++; + } + my_rtsp_addr.sin_port = htons(atoi(arg)); } else if (!strcasecmp(cmd, "RTSPBindAddress")) { get_arg(arg, sizeof(arg), &p); - if (!inet_aton(arg, &my_rtsp_addr.sin_addr)) { - fprintf(stderr, "%s:%d: Invalid IP address: %s\n", + if (resolve_host(&my_rtsp_addr.sin_addr, arg) != 0) { + fprintf(stderr, "%s:%d: Invalid host/IP address: %s\n", filename, line_num, arg); errors++; } @@ -3835,9 +3764,8 @@ static int parse_ffconfig(const char *filename) fprintf(stderr, "%s:%d: Invalid MaxBandwidth: %s\n", filename, line_num, arg); errors++; - } else { + } else max_bandwidth = val; - } } else if (!strcasecmp(cmd, "CustomLog")) { get_arg(logfilename, sizeof(logfilename), &p); } else if (!strcasecmp(cmd, "child_argv = (char **) av_mallocz(64 * sizeof(char *)); + feed->child_argv = av_mallocz(64 * sizeof(char *)); for (i = 0; i < 62; i++) { - char argbuf[256]; - - get_arg(argbuf, sizeof(argbuf), &p); - if (!argbuf[0]) + get_arg(arg, sizeof(arg), &p); + if (!arg[0]) break; - feed->child_argv[i] = av_malloc(strlen(argbuf) + 1); - strcpy(feed->child_argv[i], argbuf); + feed->child_argv[i] = av_strdup(arg); } feed->child_argv[i] = av_malloc(30 + strlen(feed->filename)); @@ -3912,17 +3837,16 @@ static int parse_ffconfig(const char *filename) } else if (!strcasecmp(cmd, "File")) { if (feed) { get_arg(feed->feed_filename, sizeof(feed->feed_filename), &p); - } else if (stream) { + } else if (stream) get_arg(stream->feed_filename, sizeof(stream->feed_filename), &p); - } } else if (!strcasecmp(cmd, "FileMaxSize")) { if (feed) { - const char *p1; + char *p1; double fsize; get_arg(arg, sizeof(arg), &p); p1 = arg; - fsize = strtod(p1, (char **)&p1); + fsize = strtod(p1, &p1); switch(toupper(*p1)) { case 'K': fsize *= 1024; @@ -3941,16 +3865,6 @@ static int parse_ffconfig(const char *filename) fprintf(stderr, "%s:%d: No corresponding for \n", filename, line_num); errors++; -#if 0 - } else { - /* Make sure that we start out clean */ - if (unlink(feed->feed_filename) < 0 - && errno != ENOENT) { - fprintf(stderr, "%s:%d: Unable to clean old feed file '%s': %s\n", - filename, line_num, feed->feed_filename, strerror(errno)); - errors++; - } -#endif } feed = NULL; } else if (!strcasecmp(cmd, "next_feed; } - if (!sfeed) { + if (!sfeed) fprintf(stderr, "%s:%d: feed '%s' not defined\n", filename, line_num, arg); - } else { + else stream->feed = sfeed; - } } } else if (!strcasecmp(cmd, "Format")) { get_arg(arg, sizeof(arg), &p); @@ -4019,6 +3932,7 @@ static int parse_ffconfig(const char *filename) video_id = stream->fmt->video_codec; } } else if (!strcasecmp(cmd, "InputFormat")) { + get_arg(arg, sizeof(arg), &p); stream->ifmt = av_find_input_format(arg); if (!stream->ifmt) { fprintf(stderr, "%s:%d: Unknown input format: %s\n", @@ -4033,30 +3947,24 @@ static int parse_ffconfig(const char *filename) errors++; } } else if (!strcasecmp(cmd, "Author")) { - if (stream) { + if (stream) get_arg(stream->author, sizeof(stream->author), &p); - } } else if (!strcasecmp(cmd, "Comment")) { - if (stream) { + if (stream) get_arg(stream->comment, sizeof(stream->comment), &p); - } } else if (!strcasecmp(cmd, "Copyright")) { - if (stream) { + if (stream) get_arg(stream->copyright, sizeof(stream->copyright), &p); - } } else if (!strcasecmp(cmd, "Title")) { - if (stream) { + if (stream) get_arg(stream->title, sizeof(stream->title), &p); - } } else if (!strcasecmp(cmd, "Preroll")) { get_arg(arg, sizeof(arg), &p); - if (stream) { + if (stream) stream->prebuffer = atof(arg) * 1000; - } } else if (!strcasecmp(cmd, "StartSendOnKey")) { - if (stream) { + if (stream) stream->send_on_key = 1; - } } else if (!strcasecmp(cmd, "AudioCodec")) { get_arg(arg, sizeof(arg), &p); audio_id = opt_audio_codec(arg); @@ -4075,24 +3983,20 @@ static int parse_ffconfig(const char *filename) } } else if (!strcasecmp(cmd, "MaxTime")) { get_arg(arg, sizeof(arg), &p); - if (stream) { + if (stream) stream->max_time = atof(arg) * 1000; - } } else if (!strcasecmp(cmd, "AudioBitRate")) { get_arg(arg, sizeof(arg), &p); - if (stream) { + if (stream) audio_enc.bit_rate = atoi(arg) * 1000; - } } else if (!strcasecmp(cmd, "AudioChannels")) { get_arg(arg, sizeof(arg), &p); - if (stream) { + if (stream) audio_enc.channels = atoi(arg); - } } else if (!strcasecmp(cmd, "AudioSampleRate")) { get_arg(arg, sizeof(arg), &p); - if (stream) { + if (stream) audio_enc.sample_rate = atoi(arg); - } } else if (!strcasecmp(cmd, "AudioQuality")) { get_arg(arg, sizeof(arg), &p); if (stream) { @@ -4141,7 +4045,7 @@ static int parse_ffconfig(const char *filename) } else if (!strcasecmp(cmd, "VideoSize")) { get_arg(arg, sizeof(arg), &p); if (stream) { - parse_image_size(&video_enc.width, &video_enc.height, arg); + av_parse_video_frame_size(&video_enc.width, &video_enc.height, arg); if ((video_enc.width % 16) != 0 || (video_enc.height % 16) != 0) { fprintf(stderr, "%s:%d: Image size must be a multiple of 16\n", @@ -4157,17 +4061,14 @@ static int parse_ffconfig(const char *filename) } } else if (!strcasecmp(cmd, "VideoGopSize")) { get_arg(arg, sizeof(arg), &p); - if (stream) { + if (stream) video_enc.gop_size = atoi(arg); - } } else if (!strcasecmp(cmd, "VideoIntraOnly")) { - if (stream) { + if (stream) video_enc.gop_size = 1; - } } else if (!strcasecmp(cmd, "VideoHighQuality")) { - if (stream) { + if (stream) video_enc.mb_decision = FF_MB_DECISION_BITS; - } } else if (!strcasecmp(cmd, "Video4MotionVector")) { if (stream) { video_enc.mb_decision = FF_MB_DECISION_BITS; //FIXME remove @@ -4175,21 +4076,17 @@ static int parse_ffconfig(const char *filename) } } else if (!strcasecmp(cmd, "VideoTag")) { get_arg(arg, sizeof(arg), &p); - if ((strlen(arg) == 4) && stream) { + if ((strlen(arg) == 4) && stream) video_enc.codec_tag = ff_get_fourcc(arg); - } } else if (!strcasecmp(cmd, "BitExact")) { - if (stream) { + if (stream) video_enc.flags |= CODEC_FLAG_BITEXACT; - } } else if (!strcasecmp(cmd, "DctFastint")) { - if (stream) { + if (stream) video_enc.dct_algo = FF_DCT_FASTINT; - } } else if (!strcasecmp(cmd, "IdctSimple")) { - if (stream) { + if (stream) video_enc.idct_algo = FF_IDCT_SIMPLE; - } } else if (!strcasecmp(cmd, "Qscale")) { get_arg(arg, sizeof(arg), &p); if (stream) { @@ -4228,38 +4125,33 @@ static int parse_ffconfig(const char *filename) } } else if (!strcasecmp(cmd, "LumaElim")) { get_arg(arg, sizeof(arg), &p); - if (stream) { + if (stream) video_enc.luma_elim_threshold = atoi(arg); - } } else if (!strcasecmp(cmd, "ChromaElim")) { get_arg(arg, sizeof(arg), &p); - if (stream) { + if (stream) video_enc.chroma_elim_threshold = atoi(arg); - } } else if (!strcasecmp(cmd, "LumiMask")) { get_arg(arg, sizeof(arg), &p); - if (stream) { + if (stream) video_enc.lumi_masking = atof(arg); - } } else if (!strcasecmp(cmd, "DarkMask")) { get_arg(arg, sizeof(arg), &p); - if (stream) { + if (stream) video_enc.dark_masking = atof(arg); - } } else if (!strcasecmp(cmd, "NoVideo")) { video_id = CODEC_ID_NONE; } else if (!strcasecmp(cmd, "NoAudio")) { audio_id = CODEC_ID_NONE; } else if (!strcasecmp(cmd, "ACL")) { IPAddressACL acl; - struct hostent *he; get_arg(arg, sizeof(arg), &p); - if (strcasecmp(arg, "allow") == 0) { + if (strcasecmp(arg, "allow") == 0) acl.action = IP_ALLOW; - } else if (strcasecmp(arg, "deny") == 0) { + else if (strcasecmp(arg, "deny") == 0) acl.action = IP_DENY; - } else { + else { fprintf(stderr, "%s:%d: ACL action '%s' is not ALLOW or DENY\n", filename, line_num, arg); errors++; @@ -4267,43 +4159,35 @@ static int parse_ffconfig(const char *filename) get_arg(arg, sizeof(arg), &p); - he = gethostbyname(arg); - if (!he) { + if (resolve_host(&acl.first, arg) != 0) { fprintf(stderr, "%s:%d: ACL refers to invalid host or ip address '%s'\n", filename, line_num, arg); errors++; - } else { - /* Only take the first */ - acl.first.s_addr = ntohl(((struct in_addr *) he->h_addr_list[0])->s_addr); + } else acl.last = acl.first; - } get_arg(arg, sizeof(arg), &p); if (arg[0]) { - he = gethostbyname(arg); - if (!he) { + if (resolve_host(&acl.last, arg) != 0) { fprintf(stderr, "%s:%d: ACL refers to invalid host or ip address '%s'\n", filename, line_num, arg); errors++; - } else { - /* Only take the first */ - acl.last.s_addr = ntohl(((struct in_addr *) he->h_addr_list[0])->s_addr); } } if (!errors) { - IPAddressACL *nacl = (IPAddressACL *) av_mallocz(sizeof(*nacl)); + IPAddressACL *nacl = av_mallocz(sizeof(*nacl)); IPAddressACL **naclp = 0; acl.next = 0; *nacl = acl; - if (stream) { + if (stream) naclp = &stream->acl; - } else if (feed) { + else if (feed) naclp = &feed->acl; - } else { + else { fprintf(stderr, "%s:%d: ACL found not in or \n", filename, line_num); errors++; @@ -4325,8 +4209,8 @@ static int parse_ffconfig(const char *filename) } else if (!strcasecmp(cmd, "MulticastAddress")) { get_arg(arg, sizeof(arg), &p); if (stream) { - if (!inet_aton(arg, &stream->multicast_ip)) { - fprintf(stderr, "%s:%d: Invalid IP address: %s\n", + if (resolve_host(&stream->multicast_ip, arg) != 0) { + fprintf(stderr, "%s:%d: Invalid host/IP address: %s\n", filename, line_num, arg); errors++; } @@ -4335,18 +4219,15 @@ static int parse_ffconfig(const char *filename) } } else if (!strcasecmp(cmd, "MulticastPort")) { get_arg(arg, sizeof(arg), &p); - if (stream) { + if (stream) stream->multicast_port = atoi(arg); - } } else if (!strcasecmp(cmd, "MulticastTTL")) { get_arg(arg, sizeof(arg), &p); - if (stream) { + if (stream) stream->multicast_ttl = atoi(arg); - } } else if (!strcasecmp(cmd, "NoLoop")) { - if (stream) { + if (stream) stream->loop = 0; - } } else if (!strcasecmp(cmd, "")) { if (!stream) { fprintf(stderr, "%s:%d: No corresponding for \n", @@ -4385,9 +4266,8 @@ static int parse_ffconfig(const char *filename) redirect->stream_type = STREAM_TYPE_REDIRECT; } } else if (!strcasecmp(cmd, "URL")) { - if (redirect) { + if (redirect) get_arg(redirect->feed_filename, sizeof(redirect->feed_filename), &p); - } } else if (!strcasecmp(cmd, "")) { if (!redirect) { fprintf(stderr, "%s:%d: No corresponding for \n", @@ -4423,14 +4303,8 @@ static int parse_ffconfig(const char *filename) return 0; } -static void show_banner(void) -{ - printf("ffserver version " FFMPEG_VERSION ", Copyright (c) 2000-2006 Fabrice Bellard, et al.\n"); -} - static void show_help(void) { - show_banner(); printf("usage: ffserver [-L] [-h] [-f configfile]\n" "Hyper fast multi format Audio/Video streaming server\n" "\n" @@ -4440,26 +4314,6 @@ static void show_help(void) ); } -static void show_license(void) -{ - show_banner(); - printf( - "FFmpeg is free software; you can redistribute it and/or\n" - "modify it under the terms of the GNU Lesser General Public\n" - "License as published by the Free Software Foundation; either\n" - "version 2.1 of the License, or (at your option) any later version.\n" - "\n" - "FFmpeg is distributed in the hope that it will be useful,\n" - "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n" - "Lesser General Public License for more details.\n" - "\n" - "You should have received a copy of the GNU Lesser General Public\n" - "License along with FFmpeg; if not, write to the Free Software\n" - "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n" - ); -} - static void handle_child_exit(int sig) { pid_t pid; @@ -4475,10 +4329,9 @@ static void handle_child_exit(int sig) feed->pid = 0; fprintf(stderr, "%s: Pid %d exited with status %d after %d seconds\n", feed->filename, pid, status, uptime); - if (uptime < 30) { + if (uptime < 30) /* Turn off any more restarts */ feed->child_argv = 0; - } } } } @@ -4494,6 +4347,8 @@ int main(int argc, char **argv) av_register_all(); + show_banner(program_name, program_birth_year); + config_filename = "/etc/ffserver.conf"; my_program_name = argv[0]; @@ -4507,11 +4362,11 @@ int main(int argc, char **argv) switch(c) { case 'L': show_license(); - exit(1); + exit(0); case '?': case 'h': show_help(); - exit(1); + exit(0); case 'n': no_launch = 1; break; diff --git a/contrib/ffmpeg/ffserver.h b/contrib/ffmpeg/ffserver.h index a1b95e84a..c76752fa4 100644 --- a/contrib/ffmpeg/ffserver.h +++ b/contrib/ffmpeg/ffserver.h @@ -18,11 +18,11 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef FFSERVER_H -#define FFSERVER_H +#ifndef FFMPEG_FFSERVER_H +#define FFMPEG_FFSERVER_H /* interface between ffserver and modules */ void ffserver_module_init(void); -#endif +#endif /* FFMPEG_FFSERVER_H */ diff --git a/contrib/ffmpeg/libavcodec/4xm.c b/contrib/ffmpeg/libavcodec/4xm.c index 6889dbc4b..d833a3b18 100644 --- a/contrib/ffmpeg/libavcodec/4xm.c +++ b/contrib/ffmpeg/libavcodec/4xm.c @@ -27,6 +27,7 @@ #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" +#include "bytestream.h" //#undef NDEBUG //#include @@ -36,7 +37,8 @@ #define CFRAME_BUFFER_COUNT 100 -static const uint8_t block_type_tab[4][8][2]={ +static const uint8_t block_type_tab[2][4][8][2]={ + { { //{8,4,2}x{8,4,2} { 0,1}, { 2,2}, { 6,3}, {14,4}, {30,5}, {31,5}, { 0,0} },{ //{8,4}x1 @@ -46,6 +48,17 @@ static const uint8_t block_type_tab[4][8][2]={ },{ //1x2, 2x1 { 0,1}, { 0,0}, { 0,0}, { 2,2}, { 6,3}, {14,4}, {15,4} } + },{ + { //{8,4,2}x{8,4,2} + { 1,2}, { 4,3}, { 5,3}, {0,2}, {6,3}, {7,3}, {0,0} + },{//{8,4}x1 + { 1,2}, { 0,0}, { 2,2}, {0,2}, {6,3}, {7,3}, {0,0} + },{//1x{8,4} + { 1,2}, { 2,2}, { 0,0}, {0,2}, {6,3}, {7,3}, {0,0} + },{//1x2, 2x1 + { 1,2}, { 0,0}, { 0,0}, {0,2}, {2,2}, {6,3}, {7,3} + } + } }; static const uint8_t size2index[4][4]={ @@ -102,7 +115,7 @@ static const uint8_t dequant_table[64]={ 20, 35, 34, 32, 31, 22, 15, 8, }; -static VLC block_type_vlc[4]; +static VLC block_type_vlc[2][4]; typedef struct CFrameBuffer{ @@ -118,14 +131,15 @@ typedef struct FourXContext{ AVFrame current_picture, last_picture; GetBitContext pre_gb; ///< ac/dc prefix GetBitContext gb; - uint8_t *bytestream; - uint16_t *wordstream; + const uint8_t *bytestream; + const uint16_t *wordstream; int mv[256]; VLC pre_vlc; int last_dc; DECLARE_ALIGNED_8(DCTELEM, block[6][64]); uint8_t *bitstream_buffer; unsigned int bitstream_buffer_size; + int version; CFrameBuffer cfrm[CFRAME_BUFFER_COUNT]; } FourXContext; @@ -224,10 +238,10 @@ static void idct(DCTELEM block[64]){ static void init_vlcs(FourXContext *f){ int i; - for(i=0; i<4; i++){ - init_vlc(&block_type_vlc[i], BLOCK_TYPE_VLC_BITS, 7, - &block_type_tab[i][0][1], 2, 1, - &block_type_tab[i][0][0], 2, 1, 1); + for(i=0; i<8; i++){ + init_vlc(&block_type_vlc[0][i], BLOCK_TYPE_VLC_BITS, 7, + &block_type_tab[0][i][0][1], 2, 1, + &block_type_tab[0][i][0][0], 2, 1, 1); } } @@ -235,7 +249,10 @@ static void init_mv(FourXContext *f){ int i; for(i=0; i<256; i++){ - f->mv[i] = mv[i][0] + mv[i][1]*f->current_picture.linesize[0]/2; + if(f->version>1) + f->mv[i] = mv[i][0] + mv[i][1] *f->current_picture.linesize[0]/2; + else + f->mv[i] = (i&15) - 8 + ((i>>4)-8)*f->current_picture.linesize[0]/2; } } @@ -283,12 +300,18 @@ static inline void mcdc(uint16_t *dst, uint16_t *src, int log2w, int h, int stri static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src, int log2w, int log2h, int stride){ const int index= size2index[log2h][log2w]; const int h= 1<gb, block_type_vlc[index].table, BLOCK_TYPE_VLC_BITS, 1); + int code= get_vlc2(&f->gb, block_type_vlc[1-(f->version>1)][index].table, BLOCK_TYPE_VLC_BITS, 1); + uint16_t *start= (uint16_t*)f->last_picture.data[0]; + uint16_t *end= start + stride*(f->avctx->height-h+1) - (1<=0 && code<=6); if(code == 0){ src += f->mv[ *f->bytestream++ ]; + if(start > src || src > end){ + av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n"); + return; + } mcdc(dst, src, log2w, h, stride, 1, 0); }else if(code == 1){ log2h--; @@ -298,8 +321,14 @@ static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src, int lo log2w--; decode_p_block(f, dst , src , log2w, log2h, stride); decode_p_block(f, dst + (1<version<2){ + mcdc(dst, src, log2w, h, stride, 1, 0); }else if(code == 4){ src += f->mv[ *f->bytestream++ ]; + if(start > src || src > end){ + av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n"); + return; + } mcdc(dst, src, log2w, h, stride, 1, le2me_16(*f->wordstream++)); }else if(code == 5){ mcdc(dst, src, log2w, h, stride, 0, le2me_16(*f->wordstream++)); @@ -314,22 +343,28 @@ static void decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src, int lo } } -static int get32(void *p){ - return le2me_32(*(uint32_t*)p); -} - -static int decode_p_frame(FourXContext *f, uint8_t *buf, int length){ +static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length){ int x, y; const int width= f->avctx->width; const int height= f->avctx->height; uint16_t *src= (uint16_t*)f->last_picture.data[0]; uint16_t *dst= (uint16_t*)f->current_picture.data[0]; const int stride= f->current_picture.linesize[0]>>1; - const unsigned int bitstream_size= get32(buf+8); - const unsigned int bytestream_size= get32(buf+16); - const unsigned int wordstream_size= get32(buf+12); + unsigned int bitstream_size, bytestream_size, wordstream_size, extra; - if(bitstream_size+ bytestream_size+ wordstream_size + 20 != length + if(f->version>1){ + extra=20; + bitstream_size= AV_RL32(buf+8); + wordstream_size= AV_RL32(buf+12); + bytestream_size= AV_RL32(buf+16); + }else{ + extra=0; + bitstream_size = AV_RL16(buf-4); + wordstream_size= AV_RL16(buf-2); + bytestream_size= FFMAX(length - bitstream_size - wordstream_size, 0); + } + + if(bitstream_size+ bytestream_size+ wordstream_size + extra != length || bitstream_size > (1<<26) || bytestream_size > (1<<26) || wordstream_size > (1<<26) @@ -340,11 +375,11 @@ static int decode_p_frame(FourXContext *f, uint8_t *buf, int length){ } f->bitstream_buffer= av_fast_realloc(f->bitstream_buffer, &f->bitstream_buffer_size, bitstream_size + FF_INPUT_BUFFER_PADDING_SIZE); - f->dsp.bswap_buf((uint32_t*)f->bitstream_buffer, (uint32_t*)(buf + 20), bitstream_size/4); + f->dsp.bswap_buf((uint32_t*)f->bitstream_buffer, (const uint32_t*)(buf + extra), bitstream_size/4); init_get_bits(&f->gb, f->bitstream_buffer, 8*bitstream_size); - f->wordstream= (uint16_t*)(buf + 20 + bitstream_size); - f->bytestream= buf + 20 + bitstream_size + wordstream_size; + f->wordstream= (const uint16_t*)(buf + extra + bitstream_size); + f->bytestream= buf + extra + bitstream_size + wordstream_size; init_mv(f); @@ -356,11 +391,13 @@ static int decode_p_frame(FourXContext *f, uint8_t *buf, int length){ dst += 8*stride; } - if(bitstream_size != (get_bits_count(&f->gb)+31)/32*4) + if( bitstream_size != (get_bits_count(&f->gb)+31)/32*4 + || (((const char*)f->wordstream - (const char*)buf + 2)&~2) != extra + bitstream_size + wordstream_size + || (((const char*)f->bytestream - (const char*)buf + 3)&~3) != extra + bitstream_size + wordstream_size + bytestream_size) av_log(f->avctx, AV_LOG_ERROR, " %d %td %td bytes left\n", bitstream_size - (get_bits_count(&f->gb)+31)/32*4, - bytestream_size - (f->bytestream - (buf + 20 + bitstream_size + wordstream_size)), - wordstream_size - (((uint8_t*)f->wordstream) - (buf + 20 + bitstream_size)) + -(((const char*)f->bytestream - (const char*)buf + 3)&~3) + (extra + bitstream_size + wordstream_size + bytestream_size), + -(((const char*)f->wordstream - (const char*)buf + 2)&~2) + (extra + bitstream_size + wordstream_size) ); return 0; @@ -471,14 +508,14 @@ static int decode_i_mb(FourXContext *f){ return 0; } -static uint8_t *read_huffman_tables(FourXContext *f, uint8_t * const buf){ +static const uint8_t *read_huffman_tables(FourXContext *f, const uint8_t * const buf){ int frequency[512]; uint8_t flag[512]; int up[512]; uint8_t len_tab[257]; int bits_tab[257]; int start, end; - uint8_t *ptr= buf; + const uint8_t *ptr= buf; int j; memset(frequency, 0, sizeof(frequency)); @@ -548,16 +585,59 @@ static uint8_t *read_huffman_tables(FourXContext *f, uint8_t * const buf){ return ptr; } -static int decode_i_frame(FourXContext *f, uint8_t *buf, int length){ +static int mix(int c0, int c1){ + int blue = 2*(c0&0x001F) + (c1&0x001F); + int green= (2*(c0&0x03E0) + (c1&0x03E0))>>5; + int red = 2*(c0>>10) + (c1>>10); + return red/3*1024 + green/3*32 + blue/3; +} + +static int decode_i2_frame(FourXContext *f, const uint8_t *buf, int length){ + int x, y, x2, y2; + const int width= f->avctx->width; + const int height= f->avctx->height; + uint16_t *dst= (uint16_t*)f->current_picture.data[0]; + const int stride= f->current_picture.linesize[0]>>1; + + for(y=0; y>2) + 8*(y2>>2); + dst[y2*stride+x2]= color[(bits>>index)&3]; + } + } + dst+=16; + } + dst += 16*stride - width; + } + + return 0; +} + +static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length){ int x, y; const int width= f->avctx->width; const int height= f->avctx->height; uint16_t *dst= (uint16_t*)f->current_picture.data[0]; const int stride= f->current_picture.linesize[0]>>1; - const unsigned int bitstream_size= get32(buf); - const int token_count __attribute__((unused)) = get32(buf + bitstream_size + 8); - unsigned int prestream_size= 4*get32(buf + bitstream_size + 4); - uint8_t *prestream= buf + bitstream_size + 12; + const unsigned int bitstream_size= AV_RL32(buf); + const int token_count av_unused = AV_RL32(buf + bitstream_size + 8); + unsigned int prestream_size= 4*AV_RL32(buf + bitstream_size + 4); + const uint8_t *prestream= buf + bitstream_size + 12; if(prestream_size + bitstream_size + 12 != length || bitstream_size > (1<<26) @@ -573,7 +653,7 @@ static int decode_i_frame(FourXContext *f, uint8_t *buf, int length){ prestream_size= length + buf - prestream; f->bitstream_buffer= av_fast_realloc(f->bitstream_buffer, &f->bitstream_buffer_size, prestream_size + FF_INPUT_BUFFER_PADDING_SIZE); - f->dsp.bswap_buf((uint32_t*)f->bitstream_buffer, (uint32_t*)prestream, prestream_size/4); + f->dsp.bswap_buf((uint32_t*)f->bitstream_buffer, (const uint32_t*)prestream, prestream_size/4); init_get_bits(&f->pre_gb, f->bitstream_buffer, 8*prestream_size); f->last_dc= 0*128*8*8; @@ -596,23 +676,23 @@ static int decode_i_frame(FourXContext *f, uint8_t *buf, int length){ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { FourXContext * const f = avctx->priv_data; AVFrame *picture = data; AVFrame *p, temp; int i, frame_4cc, frame_size; - frame_4cc= get32(buf); - if(buf_size != get32(buf+4)+8 || buf_size < 20){ - av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d\n", buf_size, get32(buf+4)); + frame_4cc= AV_RL32(buf); + if(buf_size != AV_RL32(buf+4)+8 || buf_size < 20){ + av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d\n", buf_size, AV_RL32(buf+4)); } if(frame_4cc == ff_get_fourcc("cfrm")){ int free_index=-1; const int data_size= buf_size - 20; - const int id= get32(buf+12); - const int whole_size= get32(buf+16); + const int id= AV_RL32(buf+12); + const int whole_size= AV_RL32(buf+16); CFrameBuffer *cfrm; for(i=0; ipict_type= I_TYPE; + if(decode_i2_frame(f, buf-4, frame_size) < 0) + return -1; + }else if(frame_4cc == ff_get_fourcc("ifrm")){ p->pict_type= I_TYPE; if(decode_i_frame(f, buf, frame_size) < 0) return -1; - }else if(frame_4cc == ff_get_fourcc("pfrm")){ + }else if(frame_4cc == ff_get_fourcc("pfrm") || frame_4cc == ff_get_fourcc("pfr2")){ p->pict_type= P_TYPE; if(decode_p_frame(f, buf, frame_size) < 0) return -1; @@ -711,10 +795,17 @@ static void common_init(AVCodecContext *avctx){ static int decode_init(AVCodecContext *avctx){ FourXContext * const f = avctx->priv_data; + if(avctx->extradata_size != 4 || !avctx->extradata) { + av_log(avctx, AV_LOG_ERROR, "extradata wrong or missing\n"); + return 1; + } + + f->version= AV_RL32(avctx->extradata)>>16; common_init(avctx); init_vlcs(f); - avctx->pix_fmt= PIX_FMT_RGB565; + if(f->version>2) avctx->pix_fmt= PIX_FMT_RGB565; + else avctx->pix_fmt= PIX_FMT_RGB555; return 0; } diff --git a/contrib/ffmpeg/libavcodec/8bps.c b/contrib/ffmpeg/libavcodec/8bps.c index 3d4eb05b3..23883457d 100644 --- a/contrib/ffmpeg/libavcodec/8bps.c +++ b/contrib/ffmpeg/libavcodec/8bps.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -35,7 +34,6 @@ #include #include -#include "common.h" #include "avcodec.h" @@ -59,14 +57,14 @@ typedef struct EightBpsContext { * Decode a frame * */ -static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size) { - EightBpsContext * const c = (EightBpsContext *)avctx->priv_data; - unsigned char *encoded = (unsigned char *)buf; + EightBpsContext * const c = avctx->priv_data; + const unsigned char *encoded = buf; unsigned char *pixptr, *pixptr_end; unsigned int height = avctx->height; // Real image height unsigned int dlen, p, row; - unsigned char *lp, *dp; + const unsigned char *lp, *dp; unsigned char count; unsigned int px_inc; unsigned int planes = c->planes; @@ -99,7 +97,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 for(row = 0; row < height; row++) { pixptr = c->pic.data[0] + row * c->pic.linesize[0] + planemap[p]; pixptr_end = pixptr + c->pic.linesize[0]; - dlen = be2me_16(*(unsigned short *)(lp+row*2)); + dlen = be2me_16(*(const unsigned short *)(lp+row*2)); /* Decode a row of this plane */ while(dlen > 0) { if(dp + 1 >= buf+buf_size) return -1; @@ -152,10 +150,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 */ static int decode_init(AVCodecContext *avctx) { - EightBpsContext * const c = (EightBpsContext *)avctx->priv_data; + EightBpsContext * const c = avctx->priv_data; c->avctx = avctx; - avctx->has_b_frames = 0; c->pic.data[0] = NULL; @@ -213,7 +210,7 @@ static int decode_init(AVCodecContext *avctx) */ static int decode_end(AVCodecContext *avctx) { - EightBpsContext * const c = (EightBpsContext *)avctx->priv_data; + EightBpsContext * const c = avctx->priv_data; if (c->pic.data[0]) avctx->release_buffer(avctx, &c->pic); diff --git a/contrib/ffmpeg/libavcodec/Makefile b/contrib/ffmpeg/libavcodec/Makefile index 9ec6b96f1..3ae5f3ac9 100644 --- a/contrib/ffmpeg/libavcodec/Makefile +++ b/contrib/ffmpeg/libavcodec/Makefile @@ -4,69 +4,62 @@ # include ../config.mak -CFLAGS+=-I$(SRC_PATH)/libswscale $(AMR_CFLAGS) - -OBJS= bitstream.o \ - utils.o \ - allcodecs.o \ - mpegvideo.o \ - jrevdct.o \ - jfdctfst.o \ - jfdctint.o\ - mjpeg.o \ - resample.o \ - resample2.o \ - dsputil.o \ - motion_est.o \ - imgconvert.o \ - mpeg12.o \ - mpegaudiodec.o \ - simple_idct.o \ - ratecontrol.o \ - eval.o \ - error_resilience.o \ - fft.o \ - mdct.o \ - raw.o \ - golomb.o \ - cabac.o\ - faandct.o \ - parser.o \ - vp3dsp.o \ - h264idct.o \ - rangecoder.o \ - pnm.o \ - h263.o \ - msmpeg4.o \ - h263dec.o \ - opt.o \ - bitstream_filter.o \ - audioconvert.o \ +CFLAGS += -I$(SRC_PATH)/libswscale -I$(SRC_PATH)/libavcodec + +OBJS = allcodecs.o \ + audioconvert.o \ + bitstream.o \ + bitstream_filter.o \ + dsputil.o \ + error_resilience.o \ + eval.o \ + faanidct.o \ + imgconvert.o \ + jrevdct.o \ + mpeg12.o \ + mpeg12data.o \ + mpegvideo.o \ + opt.o \ + parser.o \ + raw.o \ + resample.o \ + resample2.o \ + simple_idct.o \ + utils.o \ HEADERS = avcodec.h opt.h +OBJS-$(CONFIG_ENCODERS) += faandct.o jfdctfst.o jfdctint.o + OBJS-$(CONFIG_AASC_DECODER) += aasc.o -OBJS-$(CONFIG_AC3_ENCODER) += ac3enc.o ac3.o +OBJS-$(CONFIG_AC3_DECODER) += ac3dec.o ac3tab.o ac3.o mdct.o fft.o +OBJS-$(CONFIG_AC3_ENCODER) += ac3enc.o ac3tab.o ac3.o OBJS-$(CONFIG_ALAC_DECODER) += alac.o +OBJS-$(CONFIG_AMV_DECODER) += sp5xdec.o mjpegdec.o mjpeg.o +OBJS-$(CONFIG_APE_DECODER) += apedec.o OBJS-$(CONFIG_ASV1_DECODER) += asv1.o OBJS-$(CONFIG_ASV1_ENCODER) += asv1.o OBJS-$(CONFIG_ASV2_DECODER) += asv1.o OBJS-$(CONFIG_ASV2_ENCODER) += asv1.o +OBJS-$(CONFIG_ATRAC3_DECODER) += atrac3.o mdct.o fft.o OBJS-$(CONFIG_AVS_DECODER) += avs.o +OBJS-$(CONFIG_BETHSOFTVID_DECODER) += bethsoftvideo.o OBJS-$(CONFIG_BMP_DECODER) += bmp.o OBJS-$(CONFIG_BMP_ENCODER) += bmpenc.o -OBJS-$(CONFIG_CAVS_DECODER) += cavs.o cavsdsp.o +OBJS-$(CONFIG_C93_DECODER) += c93.o +OBJS-$(CONFIG_CAVS_DECODER) += cavs.o cavsdec.o cavsdsp.o golomb.o OBJS-$(CONFIG_CINEPAK_DECODER) += cinepak.o OBJS-$(CONFIG_CLJR_DECODER) += cljr.o OBJS-$(CONFIG_CLJR_ENCODER) += cljr.o -OBJS-$(CONFIG_COOK_DECODER) += cook.o +OBJS-$(CONFIG_COOK_DECODER) += cook.o mdct.o fft.o OBJS-$(CONFIG_CSCD_DECODER) += cscd.o OBJS-$(CONFIG_CYUV_DECODER) += cyuv.o OBJS-$(CONFIG_DCA_DECODER) += dca.o -OBJS-$(CONFIG_DNXHD_DECODER) += dnxhddec.o -OBJS-$(CONFIG_DSICINVIDEO_DECODER) += dsicinav.o +OBJS-$(CONFIG_DNXHD_DECODER) += dnxhddec.o dnxhddata.o +OBJS-$(CONFIG_DNXHD_ENCODER) += dnxhdenc.o dnxhddata.o mpegvideo_enc.o motion_est.o ratecontrol.o OBJS-$(CONFIG_DSICINAUDIO_DECODER) += dsicinav.o +OBJS-$(CONFIG_DSICINVIDEO_DECODER) += dsicinav.o OBJS-$(CONFIG_DVBSUB_DECODER) += dvbsubdec.o OBJS-$(CONFIG_DVBSUB_ENCODER) += dvbsub.o OBJS-$(CONFIG_DVDSUB_DECODER) += dvdsubdec.o @@ -75,130 +68,186 @@ OBJS-$(CONFIG_DVVIDEO_DECODER) += dv.o OBJS-$(CONFIG_DVVIDEO_ENCODER) += dv.o OBJS-$(CONFIG_DXA_DECODER) += dxa.o OBJS-$(CONFIG_EIGHTBPS_DECODER) += 8bps.o -OBJS-$(CONFIG_FFV1_DECODER) += ffv1.o -OBJS-$(CONFIG_FFV1_ENCODER) += ffv1.o +OBJS-$(CONFIG_FFV1_DECODER) += ffv1.o rangecoder.o golomb.o +OBJS-$(CONFIG_FFV1_ENCODER) += ffv1.o rangecoder.o OBJS-$(CONFIG_FFVHUFF_DECODER) += huffyuv.o OBJS-$(CONFIG_FFVHUFF_ENCODER) += huffyuv.o -OBJS-$(CONFIG_FLAC_DECODER) += flac.o -OBJS-$(CONFIG_FLAC_ENCODER) += flacenc.o +OBJS-$(CONFIG_FLAC_DECODER) += flac.o golomb.o +OBJS-$(CONFIG_FLAC_ENCODER) += flacenc.o golomb.o OBJS-$(CONFIG_FLASHSV_DECODER) += flashsv.o OBJS-$(CONFIG_FLASHSV_ENCODER) += flashsvenc.o OBJS-$(CONFIG_FLIC_DECODER) += flicvideo.o +OBJS-$(CONFIG_FLV_DECODER) += h263dec.o h263.o +OBJS-$(CONFIG_FLV_ENCODER) += mpegvideo_enc.o motion_est.o ratecontrol.o h263.o OBJS-$(CONFIG_FOURXM_DECODER) += 4xm.o -OBJS-$(CONFIG_FRAPS_DECODER) += fraps.o +OBJS-$(CONFIG_FRAPS_DECODER) += fraps.o huffman.o OBJS-$(CONFIG_GIF_DECODER) += gifdec.o lzw.o OBJS-$(CONFIG_GIF_ENCODER) += gif.o -OBJS-$(CONFIG_H261_DECODER) += h261.o -OBJS-$(CONFIG_H261_ENCODER) += h261.o -OBJS-$(CONFIG_H264_DECODER) += h264.o -OBJS-$(CONFIG_H264_ENCODER) += h264enc.o h264dsp.o +OBJS-$(CONFIG_H261_DECODER) += h261dec.o h261.o +OBJS-$(CONFIG_H261_ENCODER) += h261enc.o h261.o mpegvideo_enc.o motion_est.o ratecontrol.o +OBJS-$(CONFIG_H263_DECODER) += h263dec.o h263.o +OBJS-$(CONFIG_H263I_DECODER) += h263dec.o h263.o +OBJS-$(CONFIG_H263_ENCODER) += mpegvideo_enc.o motion_est.o ratecontrol.o h263.o +OBJS-$(CONFIG_H263P_ENCODER) += mpegvideo_enc.o motion_est.o ratecontrol.o h263.o +OBJS-$(CONFIG_H264_DECODER) += h264.o h264idct.o h264pred.o cabac.o golomb.o +OBJS-$(CONFIG_H264_ENCODER) += h264enc.o h264dspenc.o OBJS-$(CONFIG_HUFFYUV_DECODER) += huffyuv.o OBJS-$(CONFIG_HUFFYUV_ENCODER) += huffyuv.o OBJS-$(CONFIG_IDCIN_DECODER) += idcinvideo.o -OBJS-$(CONFIG_IMC_DECODER) += imc.o +OBJS-$(CONFIG_IMC_DECODER) += imc.o mdct.o fft.o OBJS-$(CONFIG_INDEO2_DECODER) += indeo2.o OBJS-$(CONFIG_INDEO3_DECODER) += indeo3.o -OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER) += dpcm.o +OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o +OBJS-$(CONFIG_JPEGLS_DECODER) += jpeglsdec.o jpegls.o mjpegdec.o mjpeg.o golomb.o +OBJS-$(CONFIG_JPEGLS_ENCODER) += jpeglsenc.o jpegls.o golomb.o OBJS-$(CONFIG_KMVC_DECODER) += kmvc.o -OBJS-$(CONFIG_LOCO_DECODER) += loco.o +OBJS-$(CONFIG_LJPEG_ENCODER) += ljpegenc.o mjpegenc.o mjpeg.o mpegvideo_enc.o motion_est.o ratecontrol.o +OBJS-$(CONFIG_LOCO_DECODER) += loco.o golomb.o OBJS-$(CONFIG_MACE3_DECODER) += mace.o OBJS-$(CONFIG_MACE6_DECODER) += mace.o +OBJS-$(CONFIG_MJPEG_DECODER) += mjpegdec.o mjpeg.o +OBJS-$(CONFIG_MJPEG_ENCODER) += mjpegenc.o mjpeg.o mpegvideo_enc.o motion_est.o ratecontrol.o +OBJS-$(CONFIG_MJPEGB_DECODER) += mjpegbdec.o mjpegdec.o mjpeg.o OBJS-$(CONFIG_MMVIDEO_DECODER) += mmvideo.o -OBJS-$(CONFIG_MP2_ENCODER) += mpegaudio.o -OBJS-$(CONFIG_MPC7_DECODER) += mpc.o +OBJS-$(CONFIG_MP2_DECODER) += mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o +OBJS-$(CONFIG_MP2_ENCODER) += mpegaudioenc.o mpegaudio.o mpegaudiodata.o +OBJS-$(CONFIG_MP3_DECODER) += mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o +OBJS-$(CONFIG_MP3ADU_DECODER) += mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o +OBJS-$(CONFIG_MP3ON4_DECODER) += mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o +OBJS-$(CONFIG_MPC7_DECODER) += mpc7.o mpc.o mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o +OBJS-$(CONFIG_MPC8_DECODER) += mpc8.o mpc.o mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o +OBJS-$(CONFIG_MPEG1VIDEO_ENCODER) += mpeg12enc.o mpeg12data.o mpegvideo_enc.o motion_est.o ratecontrol.o +OBJS-$(CONFIG_MPEG2VIDEO_ENCODER) += mpeg12enc.o mpeg12data.o mpegvideo_enc.o motion_est.o ratecontrol.o +OBJS-$(CONFIG_MPEG4_DECODER) += h263dec.o h263.o +OBJS-$(CONFIG_MPEG4_ENCODER) += mpegvideo_enc.o motion_est.o ratecontrol.o h263.o +OBJS-$(CONFIG_MSMPEG4V1_DECODER) += msmpeg4.o msmpeg4data.o h263dec.o h263.o +OBJS-$(CONFIG_MSMPEG4V1_ENCODER) += msmpeg4.o msmpeg4data.o mpegvideo_enc.o motion_est.o ratecontrol.o h263.o +OBJS-$(CONFIG_MSMPEG4V2_DECODER) += msmpeg4.o msmpeg4data.o h263dec.o h263.o +OBJS-$(CONFIG_MSMPEG4V2_ENCODER) += msmpeg4.o msmpeg4data.o mpegvideo_enc.o motion_est.o ratecontrol.o h263.o +OBJS-$(CONFIG_MSMPEG4V3_DECODER) += msmpeg4.o msmpeg4data.o h263dec.o h263.o +OBJS-$(CONFIG_MSMPEG4V3_ENCODER) += msmpeg4.o msmpeg4data.o mpegvideo_enc.o motion_est.o ratecontrol.o h263.o OBJS-$(CONFIG_MSRLE_DECODER) += msrle.o OBJS-$(CONFIG_MSVIDEO1_DECODER) += msvideo1.o -OBJS-$(CONFIG_MSZH_DECODER) += lcl.o +OBJS-$(CONFIG_MSZH_DECODER) += lcldec.o +OBJS-$(CONFIG_NELLYMOSER_DECODER) += nellymoserdec.o mdct.o fft.o OBJS-$(CONFIG_NUV_DECODER) += nuv.o rtjpeg.o -OBJS-$(CONFIG_PNG_DECODER) += png.o -OBJS-$(CONFIG_PNG_ENCODER) += png.o -OBJS-$(CONFIG_QDM2_DECODER) += qdm2.o +OBJS-$(CONFIG_PAM_ENCODER) += pnmenc.o pnm.o +OBJS-$(CONFIG_PBM_ENCODER) += pnmenc.o pnm.o +OBJS-$(CONFIG_PCX_DECODER) += pcx.o +OBJS-$(CONFIG_PGM_ENCODER) += pnmenc.o pnm.o +OBJS-$(CONFIG_PGMYUV_ENCODER) += pnmenc.o pnm.o +OBJS-$(CONFIG_PNG_DECODER) += png.o pngdec.o +OBJS-$(CONFIG_PNG_ENCODER) += png.o pngenc.o +OBJS-$(CONFIG_PPM_ENCODER) += pnmenc.o pnm.o +OBJS-$(CONFIG_PTX_DECODER) += ptx.o +OBJS-$(CONFIG_QDM2_DECODER) += qdm2.o mdct.o fft.o mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o OBJS-$(CONFIG_QDRAW_DECODER) += qdrw.o OBJS-$(CONFIG_QPEG_DECODER) += qpeg.o OBJS-$(CONFIG_QTRLE_DECODER) += qtrle.o +OBJS-$(CONFIG_QTRLE_ENCODER) += qtrleenc.o OBJS-$(CONFIG_RA_144_DECODER) += ra144.o OBJS-$(CONFIG_RA_288_DECODER) += ra288.o -OBJS-$(CONFIG_ROQ_DECODER) += roqvideo.o +OBJS-$(CONFIG_RAWVIDEO_DECODER) += rawdec.o +OBJS-$(CONFIG_RAWVIDEO_ENCODER) += rawenc.o +OBJS-$(CONFIG_ROQ_DECODER) += roqvideodec.o roqvideo.o +OBJS-$(CONFIG_ROQ_ENCODER) += roqvideoenc.o roqvideo.o elbg.o OBJS-$(CONFIG_ROQ_DPCM_DECODER) += dpcm.o +OBJS-$(CONFIG_ROQ_DPCM_ENCODER) += roqaudioenc.o OBJS-$(CONFIG_RPZA_DECODER) += rpza.o -OBJS-$(CONFIG_RV10_DECODER) += rv10.o -OBJS-$(CONFIG_RV10_ENCODER) += rv10.o -OBJS-$(CONFIG_RV20_DECODER) += rv10.o -OBJS-$(CONFIG_RV20_ENCODER) += rv10.o -OBJS-$(CONFIG_SHORTEN_DECODER) += shorten.o +OBJS-$(CONFIG_RV10_DECODER) += rv10.o h263.o +OBJS-$(CONFIG_RV10_ENCODER) += rv10.o mpegvideo_enc.o motion_est.o ratecontrol.o h263.o +OBJS-$(CONFIG_RV20_DECODER) += rv10.o h263.o +OBJS-$(CONFIG_RV20_ENCODER) += rv10.o mpegvideo_enc.o motion_est.o ratecontrol.o h263.o +OBJS-$(CONFIG_SGI_DECODER) += sgidec.o +OBJS-$(CONFIG_SGI_ENCODER) += sgienc.o rle.o +OBJS-$(CONFIG_SHORTEN_DECODER) += shorten.o golomb.o OBJS-$(CONFIG_SMACKAUD_DECODER) += smacker.o OBJS-$(CONFIG_SMACKER_DECODER) += smacker.o OBJS-$(CONFIG_SMC_DECODER) += smc.o -OBJS-$(CONFIG_SNOW_DECODER) += snow.o -OBJS-$(CONFIG_SNOW_ENCODER) += snow.o +OBJS-$(CONFIG_SNOW_DECODER) += snow.o rangecoder.o +OBJS-$(CONFIG_SNOW_ENCODER) += snow.o rangecoder.o motion_est.o ratecontrol.o h263.o OBJS-$(CONFIG_SOL_DPCM_DECODER) += dpcm.o -OBJS-$(CONFIG_SONIC_DECODER) += sonic.o -OBJS-$(CONFIG_SONIC_ENCODER) += sonic.o -OBJS-$(CONFIG_SONIC_LS_DECODER) += sonic.o -OBJS-$(CONFIG_SVQ1_DECODER) += svq1.o -OBJS-$(CONFIG_SVQ1_ENCODER) += svq1.o -OBJS-$(CONFIG_SVQ3_DECODER) += h264.o +OBJS-$(CONFIG_SONIC_DECODER) += sonic.o golomb.o +OBJS-$(CONFIG_SONIC_ENCODER) += sonic.o golomb.o +OBJS-$(CONFIG_SONIC_LS_ENCODER) += sonic.o golomb.o +OBJS-$(CONFIG_SP5X_DECODER) += sp5xdec.o mjpegdec.o mjpeg.o +OBJS-$(CONFIG_SUNRAST_DECODER) += sunrast.o +OBJS-$(CONFIG_SVQ1_DECODER) += svq1dec.o svq1.o h263.o +OBJS-$(CONFIG_SVQ1_ENCODER) += svq1enc.o svq1.o motion_est.o h263.o +OBJS-$(CONFIG_SVQ3_DECODER) += h264.o h264idct.o h264pred.o cabac.o golomb.o OBJS-$(CONFIG_TARGA_DECODER) += targa.o -OBJS-$(CONFIG_TARGA_ENCODER) += targaenc.o -OBJS-$(CONFIG_THEORA_DECODER) += vp3.o xiph.o +OBJS-$(CONFIG_TARGA_ENCODER) += targaenc.o rle.o +OBJS-$(CONFIG_THEORA_DECODER) += vp3.o xiph.o vp3dsp.o +OBJS-$(CONFIG_THP_DECODER) += mjpegdec.o mjpeg.o OBJS-$(CONFIG_TIERTEXSEQVIDEO_DECODER) += tiertexseqv.o OBJS-$(CONFIG_TIFF_DECODER) += tiff.o lzw.o +OBJS-$(CONFIG_TIFF_ENCODER) += tiffenc.o rle.o lzwenc.o OBJS-$(CONFIG_TRUEMOTION1_DECODER) += truemotion1.o OBJS-$(CONFIG_TRUEMOTION2_DECODER) += truemotion2.o OBJS-$(CONFIG_TRUESPEECH_DECODER) += truespeech.o OBJS-$(CONFIG_TSCC_DECODER) += tscc.o OBJS-$(CONFIG_TTA_DECODER) += tta.o +OBJS-$(CONFIG_TXD_DECODER) += txd.o s3tc.o OBJS-$(CONFIG_ULTI_DECODER) += ulti.o -OBJS-$(CONFIG_VC1_DECODER) += vc1.o vc1dsp.o +OBJS-$(CONFIG_VB_DECODER) += vb.o +OBJS-$(CONFIG_VC1_DECODER) += vc1.o vc1data.o vc1dsp.o msmpeg4data.o intrax8.o intrax8dsp.o OBJS-$(CONFIG_VCR1_DECODER) += vcr1.o OBJS-$(CONFIG_VCR1_ENCODER) += vcr1.o OBJS-$(CONFIG_VMDAUDIO_DECODER) += vmdav.o OBJS-$(CONFIG_VMDVIDEO_DECODER) += vmdav.o OBJS-$(CONFIG_VMNC_DECODER) += vmnc.o -OBJS-$(CONFIG_VORBIS_DECODER) += vorbis.o vorbis_data.o xiph.o -OBJS-$(CONFIG_VORBIS_ENCODER) += vorbis_enc.o vorbis.o vorbis_data.o -OBJS-$(CONFIG_VP3_DECODER) += vp3.o -OBJS-$(CONFIG_VP5_DECODER) += vp5.o vp56.o vp56data.o -OBJS-$(CONFIG_VP6_DECODER) += vp6.o vp56.o vp56data.o +OBJS-$(CONFIG_VORBIS_DECODER) += vorbis_dec.o vorbis.o vorbis_data.o xiph.o mdct.o fft.o +OBJS-$(CONFIG_VORBIS_ENCODER) += vorbis_enc.o vorbis.o vorbis_data.o mdct.o fft.o +OBJS-$(CONFIG_VP3_DECODER) += vp3.o vp3dsp.o +OBJS-$(CONFIG_VP5_DECODER) += vp5.o vp56.o vp56data.o vp3dsp.o +OBJS-$(CONFIG_VP6_DECODER) += vp6.o vp56.o vp56data.o vp3dsp.o huffman.o +OBJS-$(CONFIG_VP6A_DECODER) += vp6.o vp56.o vp56data.o vp3dsp.o huffman.o +OBJS-$(CONFIG_VP6F_DECODER) += vp6.o vp56.o vp56data.o vp3dsp.o huffman.o OBJS-$(CONFIG_VQA_DECODER) += vqavideo.o OBJS-$(CONFIG_WAVPACK_DECODER) += wavpack.o -OBJS-$(CONFIG_WMAV1_DECODER) += wmadec.o wma.o -OBJS-$(CONFIG_WMAV2_DECODER) += wmadec.o wma.o -OBJS-$(CONFIG_WMAV1_ENCODER) += wmaenc.o wma.o -OBJS-$(CONFIG_WMAV2_ENCODER) += wmaenc.o wma.o -OBJS-$(CONFIG_WMV3_DECODER) += vc1.o vc1dsp.o +OBJS-$(CONFIG_WMAV1_DECODER) += wmadec.o wma.o mdct.o fft.o +OBJS-$(CONFIG_WMAV1_ENCODER) += wmaenc.o wma.o mdct.o fft.o +OBJS-$(CONFIG_WMAV2_DECODER) += wmadec.o wma.o mdct.o fft.o +OBJS-$(CONFIG_WMAV2_ENCODER) += wmaenc.o wma.o mdct.o fft.o +OBJS-$(CONFIG_WMV1_DECODER) += h263dec.o h263.o +OBJS-$(CONFIG_WMV1_ENCODER) += mpegvideo_enc.o motion_est.o ratecontrol.o h263.o +OBJS-$(CONFIG_WMV2_DECODER) += wmv2dec.o wmv2.o msmpeg4.o msmpeg4data.o h263dec.o h263.o intrax8.o intrax8dsp.o +OBJS-$(CONFIG_WMV2_ENCODER) += wmv2enc.o wmv2.o msmpeg4.o msmpeg4data.o mpegvideo_enc.o motion_est.o ratecontrol.o h263.o +OBJS-$(CONFIG_WMV3_DECODER) += vc1.o vc1data.o vc1dsp.o OBJS-$(CONFIG_WNV1_DECODER) += wnv1.o OBJS-$(CONFIG_WS_SND1_DECODER) += ws-snd1.o OBJS-$(CONFIG_XAN_DPCM_DECODER) += dpcm.o OBJS-$(CONFIG_XAN_WC3_DECODER) += xan.o OBJS-$(CONFIG_XAN_WC4_DECODER) += xan.o OBJS-$(CONFIG_XL_DECODER) += xl.o -OBJS-$(CONFIG_ZLIB_DECODER) += lcl.o -OBJS-$(CONFIG_ZLIB_ENCODER) += lcl.o +OBJS-$(CONFIG_XSUB_DECODER) += xsubdec.o +OBJS-$(CONFIG_ZLIB_DECODER) += lcldec.o +OBJS-$(CONFIG_ZLIB_ENCODER) += lclenc.o OBJS-$(CONFIG_ZMBV_DECODER) += zmbv.o OBJS-$(CONFIG_ZMBV_ENCODER) += zmbvenc.o -OBJS-$(CONFIG_PCM_S32LE_DECODER) += pcm.o -OBJS-$(CONFIG_PCM_S32LE_ENCODER) += pcm.o OBJS-$(CONFIG_PCM_S32BE_DECODER) += pcm.o OBJS-$(CONFIG_PCM_S32BE_ENCODER) += pcm.o -OBJS-$(CONFIG_PCM_U32LE_DECODER) += pcm.o -OBJS-$(CONFIG_PCM_U32LE_ENCODER) += pcm.o +OBJS-$(CONFIG_PCM_S32LE_DECODER) += pcm.o +OBJS-$(CONFIG_PCM_S32LE_ENCODER) += pcm.o OBJS-$(CONFIG_PCM_U32BE_DECODER) += pcm.o OBJS-$(CONFIG_PCM_U32BE_ENCODER) += pcm.o -OBJS-$(CONFIG_PCM_S24LE_DECODER) += pcm.o -OBJS-$(CONFIG_PCM_S24LE_ENCODER) += pcm.o +OBJS-$(CONFIG_PCM_U32LE_DECODER) += pcm.o +OBJS-$(CONFIG_PCM_U32LE_ENCODER) += pcm.o OBJS-$(CONFIG_PCM_S24BE_DECODER) += pcm.o OBJS-$(CONFIG_PCM_S24BE_ENCODER) += pcm.o -OBJS-$(CONFIG_PCM_U24LE_DECODER) += pcm.o -OBJS-$(CONFIG_PCM_U24LE_ENCODER) += pcm.o +OBJS-$(CONFIG_PCM_S24LE_DECODER) += pcm.o +OBJS-$(CONFIG_PCM_S24LE_ENCODER) += pcm.o OBJS-$(CONFIG_PCM_U24BE_DECODER) += pcm.o OBJS-$(CONFIG_PCM_U24BE_ENCODER) += pcm.o +OBJS-$(CONFIG_PCM_U24LE_DECODER) += pcm.o +OBJS-$(CONFIG_PCM_U24LE_ENCODER) += pcm.o OBJS-$(CONFIG_PCM_S24DAUD_DECODER) += pcm.o OBJS-$(CONFIG_PCM_S24DAUD_ENCODER) += pcm.o OBJS-$(CONFIG_PCM_S16LE_DECODER) += pcm.o OBJS-$(CONFIG_PCM_S16LE_ENCODER) += pcm.o +OBJS-$(CONFIG_PCM_S16LE_PLANAR_DECODER)+= pcm.o OBJS-$(CONFIG_PCM_S16BE_DECODER) += pcm.o OBJS-$(CONFIG_PCM_S16BE_ENCODER) += pcm.o OBJS-$(CONFIG_PCM_U16LE_DECODER) += pcm.o @@ -213,103 +262,92 @@ OBJS-$(CONFIG_PCM_ALAW_DECODER) += pcm.o OBJS-$(CONFIG_PCM_ALAW_ENCODER) += pcm.o OBJS-$(CONFIG_PCM_MULAW_DECODER) += pcm.o OBJS-$(CONFIG_PCM_MULAW_ENCODER) += pcm.o +OBJS-$(CONFIG_PCM_ZORK_DECODER) += pcm.o +OBJS-$(CONFIG_PCM_ZORK_ENCODER) += pcm.o OBJS-$(CONFIG_ADPCM_4XM_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_4XM_ENCODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_ADX_DECODER) += adx.o -OBJS-$(CONFIG_ADPCM_ADX_ENCODER) += adx.o +OBJS-$(CONFIG_ADPCM_ADX_DECODER) += adxdec.o +OBJS-$(CONFIG_ADPCM_ADX_ENCODER) += adxenc.o OBJS-$(CONFIG_ADPCM_CT_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_CT_ENCODER) += adpcm.o OBJS-$(CONFIG_ADPCM_EA_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_EA_ENCODER) += adpcm.o +OBJS-$(CONFIG_ADPCM_EA_R1_DECODER) += adpcm.o +OBJS-$(CONFIG_ADPCM_EA_R2_DECODER) += adpcm.o +OBJS-$(CONFIG_ADPCM_EA_R3_DECODER) += adpcm.o +OBJS-$(CONFIG_ADPCM_EA_XAS_DECODER) += adpcm.o OBJS-$(CONFIG_ADPCM_G726_DECODER) += g726.o OBJS-$(CONFIG_ADPCM_G726_ENCODER) += g726.o +OBJS-$(CONFIG_ADPCM_IMA_AMV_DECODER) += adpcm.o OBJS-$(CONFIG_ADPCM_IMA_DK3_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_IMA_DK3_ENCODER) += adpcm.o OBJS-$(CONFIG_ADPCM_IMA_DK4_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_IMA_DK4_ENCODER) += adpcm.o +OBJS-$(CONFIG_ADPCM_IMA_EA_EACS_DECODER) += adpcm.o +OBJS-$(CONFIG_ADPCM_IMA_EA_SEAD_DECODER) += adpcm.o OBJS-$(CONFIG_ADPCM_IMA_QT_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_IMA_QT_ENCODER) += adpcm.o OBJS-$(CONFIG_ADPCM_IMA_SMJPEG_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_IMA_SMJPEG_ENCODER) += adpcm.o OBJS-$(CONFIG_ADPCM_IMA_WAV_DECODER) += adpcm.o OBJS-$(CONFIG_ADPCM_IMA_WAV_ENCODER) += adpcm.o OBJS-$(CONFIG_ADPCM_IMA_WS_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_IMA_WS_ENCODER) += adpcm.o OBJS-$(CONFIG_ADPCM_MS_DECODER) += adpcm.o OBJS-$(CONFIG_ADPCM_MS_ENCODER) += adpcm.o OBJS-$(CONFIG_ADPCM_SBPRO_2_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_SBPRO_2_ENCODER) += adpcm.o OBJS-$(CONFIG_ADPCM_SBPRO_3_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_SBPRO_3_ENCODER) += adpcm.o OBJS-$(CONFIG_ADPCM_SBPRO_4_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_SBPRO_4_ENCODER) += adpcm.o OBJS-$(CONFIG_ADPCM_SWF_DECODER) += adpcm.o OBJS-$(CONFIG_ADPCM_SWF_ENCODER) += adpcm.o +OBJS-$(CONFIG_ADPCM_THP_DECODER) += adpcm.o OBJS-$(CONFIG_ADPCM_XA_DECODER) += adpcm.o -OBJS-$(CONFIG_ADPCM_XA_ENCODER) += adpcm.o OBJS-$(CONFIG_ADPCM_YAMAHA_DECODER) += adpcm.o OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER) += adpcm.o +# libavformat dependencies +OBJS-$(CONFIG_MATROSKA_MUXER) += xiph.o +OBJS-$(CONFIG_OGG_MUXER) += xiph.o + # external codec libraries -OBJS-$(CONFIG_LIBA52) += a52dec.o -OBJS-$(CONFIG_LIBDTS) += dtsdec.o -OBJS-$(CONFIG_LIBFAAC) += faac.o -OBJS-$(CONFIG_LIBFAAD) += faad.o +OBJS-$(CONFIG_LIBA52) += liba52.o +OBJS-$(CONFIG_LIBAMR_NB) += libamr.o +OBJS-$(CONFIG_LIBAMR_WB) += libamr.o +OBJS-$(CONFIG_LIBFAAC) += libfaac.o +OBJS-$(CONFIG_LIBFAAD) += libfaad.o OBJS-$(CONFIG_LIBGSM) += libgsm.o -OBJS-$(CONFIG_LIBMP3LAME) += mp3lameaudio.o +OBJS-$(CONFIG_LIBMP3LAME) += libmp3lame.o OBJS-$(CONFIG_LIBTHEORA) += libtheoraenc.o -OBJS-$(CONFIG_LIBVORBIS) += oggvorbis.o -OBJS-$(CONFIG_X264) += x264.o -OBJS-$(CONFIG_XVID) += xvidff.o xvid_rc.o - -OBJS-$(CONFIG_AMR) += amr.o -OBJS-$(CONFIG_AMR_NB) += amr_float/sp_dec.o \ - amr_float/sp_enc.o \ - amr_float/interf_dec.o \ - amr_float/interf_enc.o - -ifeq ($(CONFIG_AMR_NB_FIXED),yes) -EXTRAOBJS += amr/*.o -EXTRADEPS=amrlibs -endif - -OBJS-$(CONFIG_AMR_WB) += amrwb_float/dec_acelp.o \ - amrwb_float/dec_dtx.o \ - amrwb_float/dec_gain.o \ - amrwb_float/dec_if.o \ - amrwb_float/dec_lpc.o \ - amrwb_float/dec_main.o \ - amrwb_float/dec_rom.o \ - amrwb_float/dec_util.o \ - amrwb_float/enc_acelp.o \ - amrwb_float/enc_dtx.o \ - amrwb_float/enc_gain.o \ - amrwb_float/enc_if.o \ - amrwb_float/enc_lpc.o \ - amrwb_float/enc_main.o \ - amrwb_float/enc_rom.o \ - amrwb_float/enc_util.o \ - amrwb_float/if_rom.o - -OBJS-$(CONFIG_AAC_PARSER) += parser.o -OBJS-$(CONFIG_AC3_PARSER) += parser.o ac3.o -OBJS-$(CONFIG_CAVSVIDEO_PARSER) += cavs.o parser.o -OBJS-$(CONFIG_DVBSUB_PARSER) += dvbsubdec.o -OBJS-$(CONFIG_DVDSUB_PARSER) += dvdsubdec.o -OBJS-$(CONFIG_H261_PARSER) += h261.o -OBJS-$(CONFIG_H263_PARSER) += h263dec.o -OBJS-$(CONFIG_H264_PARSER) += h264.o -OBJS-$(CONFIG_MJPEG_PARSER) += mjpeg.o -OBJS-$(CONFIG_MPEG4VIDEO_PARSER) += parser.o -OBJS-$(CONFIG_MPEGAUDIO_PARSER) += parser.o -OBJS-$(CONFIG_MPEGVIDEO_PARSER) += parser.o -OBJS-$(CONFIG_PNM_PARSER) += pnm.o +OBJS-$(CONFIG_LIBVORBIS) += libvorbis.o +OBJS-$(CONFIG_LIBX264) += libx264.o +OBJS-$(CONFIG_LIBXVID) += libxvidff.o libxvid_rc.o + + +OBJS-$(CONFIG_AAC_PARSER) += aac_parser.o aac_ac3_parser.o +OBJS-$(CONFIG_AC3_PARSER) += ac3_parser.o ac3tab.o aac_ac3_parser.o +OBJS-$(CONFIG_CAVSVIDEO_PARSER) += cavs_parser.o +OBJS-$(CONFIG_DCA_PARSER) += dca_parser.o +OBJS-$(CONFIG_DVBSUB_PARSER) += dvbsub_parser.o +OBJS-$(CONFIG_DVDSUB_PARSER) += dvdsub_parser.o +OBJS-$(CONFIG_H261_PARSER) += h261_parser.o +OBJS-$(CONFIG_H263_PARSER) += h263_parser.o +OBJS-$(CONFIG_H264_PARSER) += h264_parser.o +OBJS-$(CONFIG_MJPEG_PARSER) += mjpeg_parser.o +OBJS-$(CONFIG_MLP_PARSER) += mlp_parser.o +OBJS-$(CONFIG_MPEG4VIDEO_PARSER) += mpeg4video_parser.o h263.o +OBJS-$(CONFIG_MPEGAUDIO_PARSER) += mpegaudio_parser.o mpegaudiodecheader.o mpegaudiodata.o +OBJS-$(CONFIG_MPEGVIDEO_PARSER) += mpegvideo_parser.o +OBJS-$(CONFIG_PNM_PARSER) += pnm_parser.o pnm.o +OBJS-$(CONFIG_VC1_PARSER) += vc1_parser.o + +OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += dump_extradata_bsf.o +OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF) += h264_mp4toannexb_bsf.o +OBJS-$(CONFIG_IMX_DUMP_HEADER_BSF) += imx_dump_header_bsf.o +OBJS-$(CONFIG_MJPEGA_DUMP_HEADER_BSF) += mjpega_dump_header_bsf.o +OBJS-$(CONFIG_MOV2TEXTSUB_BSF) += movsub_bsf.o +OBJS-$(CONFIG_MP3_HEADER_COMPRESS_BSF) += mp3_header_compress_bsf.o +OBJS-$(CONFIG_MP3_HEADER_DECOMPRESS_BSF) += mp3_header_decompress_bsf.o mpegaudiodata.o +OBJS-$(CONFIG_NOISE_BSF) += noise_bsf.o +OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += remove_extradata_bsf.o +OBJS-$(CONFIG_TEXT2MOVSUB_BSF) += movsub_bsf.o +OBJS-$(HAVE_BEOSTHREADS) += beosthread.o +OBJS-$(HAVE_OS2THREADS) += os2thread.o OBJS-$(HAVE_PTHREADS) += pthread.o OBJS-$(HAVE_W32THREADS) += w32thread.o -OBJS-$(HAVE_OS2THREADS) += os2thread.o -OBJS-$(HAVE_BEOSTHREADS) += beosthread.o OBJS-$(HAVE_XVMC_ACCEL) += xvmcvideo.o @@ -318,7 +356,7 @@ OBJS += imgresample.o endif # processor-specific code -ifeq ($(TARGET_MMX),yes) +ifeq ($(HAVE_MMX),yes) OBJS += i386/fdct_mmx.o \ i386/cputest.o \ i386/dsputil_mmx.o \ @@ -327,76 +365,92 @@ OBJS += i386/fdct_mmx.o \ i386/simple_idct_mmx.o \ i386/idct_mmx_xvid.o \ i386/fft_sse.o \ - i386/vp3dsp_mmx.o \ - i386/vp3dsp_sse2.o \ i386/fft_3dn.o \ i386/fft_3dn2.o \ OBJS-$(CONFIG_GPL) += i386/idct_mmx.o + +OBJS-$(CONFIG_ENCODERS) += i386/dsputilenc_mmx.o + OBJS-$(CONFIG_CAVS_DECODER) += i386/cavsdsp_mmx.o +OBJS-$(CONFIG_FLAC_ENCODER) += i386/flacdsp_mmx.o OBJS-$(CONFIG_SNOW_DECODER) += i386/snowdsp_mmx.o +OBJS-$(CONFIG_VC1_DECODER) += i386/vc1dsp_mmx.o +OBJS-$(CONFIG_VP3_DECODER) += i386/vp3dsp_mmx.o i386/vp3dsp_sse2.o +OBJS-$(CONFIG_VP5_DECODER) += i386/vp3dsp_mmx.o i386/vp3dsp_sse2.o +OBJS-$(CONFIG_VP6_DECODER) += i386/vp3dsp_mmx.o i386/vp3dsp_sse2.o +OBJS-$(CONFIG_VP6A_DECODER) += i386/vp3dsp_mmx.o i386/vp3dsp_sse2.o +OBJS-$(CONFIG_VP6F_DECODER) += i386/vp3dsp_mmx.o i386/vp3dsp_sse2.o +OBJS-$(CONFIG_WMV3_DECODER) += i386/vc1dsp_mmx.o endif -ASM_OBJS-$(TARGET_ARCH_ARMV4L) += armv4l/jrevdct_arm.o \ +ASM_OBJS-$(ARCH_ARMV4L) += armv4l/jrevdct_arm.o \ armv4l/simple_idct_arm.o \ armv4l/dsputil_arm_s.o \ -OBJS-$(TARGET_ARCH_ARMV4L) += armv4l/dsputil_arm.o \ +OBJS-$(ARCH_ARMV4L) += armv4l/dsputil_arm.o \ armv4l/mpegvideo_arm.o \ -OBJS-$(TARGET_IWMMXT) += armv4l/dsputil_iwmmxt.o \ +OBJS-$(HAVE_IWMMXT) += armv4l/dsputil_iwmmxt.o \ armv4l/mpegvideo_iwmmxt.o \ -ASM_OBJS-$(TARGET_ARMV5TE) += armv4l/simple_idct_armv5te.o \ +ASM_OBJS-$(HAVE_ARMV5TE) += armv4l/simple_idct_armv5te.o \ armv4l/mpegvideo_armv5te.o \ -ASM_OBJS-$(HAVE_ARMV6) += armv4l/simple_idct_armv6.o +ASM_OBJS-$(HAVE_ARMV6) += armv4l/simple_idct_armv6.o \ -OBJS-$(TARGET_ARCH_SPARC) += sparc/dsputil_vis.o \ - -sparc/dsputil_vis.o: CFLAGS += -mcpu=ultrasparc -mtune=ultrasparc +OBJS-$(HAVE_VIS) += sparc/dsputil_vis.o \ + sparc/simple_idct_vis.o \ OBJS-$(HAVE_MLIB) += mlib/dsputil_mlib.o \ -OBJS-$(TARGET_ARCH_ALPHA) += alpha/dsputil_alpha.o \ +OBJS-$(ARCH_ALPHA) += alpha/dsputil_alpha.o \ + alpha/motion_est_alpha.o \ alpha/mpegvideo_alpha.o \ alpha/simple_idct_alpha.o \ - alpha/motion_est_alpha.o \ -ASM_OBJS-$(TARGET_ARCH_ALPHA) += alpha/dsputil_alpha_asm.o \ +ASM_OBJS-$(ARCH_ALPHA) += alpha/dsputil_alpha_asm.o \ alpha/motion_est_mvi_asm.o \ -OBJS-$(TARGET_ARCH_POWERPC) += ppc/dsputil_ppc.o \ - ppc/mpegvideo_ppc.o \ +OBJS-$(ARCH_POWERPC) += ppc/dsputil_ppc.o \ -OBJS-$(TARGET_MMI) += ps2/dsputil_mmi.o \ +OBJS-$(HAVE_MMI) += ps2/dsputil_mmi.o \ ps2/idct_mmi.o \ ps2/mpegvideo_mmi.o \ -OBJS-$(TARGET_ARCH_SH4) += sh4/idct_sh4.o \ - sh4/dsputil_sh4.o \ +OBJS-$(ARCH_SH4) += sh4/idct_sh4.o \ sh4/dsputil_align.o \ + sh4/dsputil_sh4.o \ -OBJS-$(TARGET_ALTIVEC) += ppc/dsputil_altivec.o \ - ppc/mpegvideo_altivec.o \ - ppc/idct_altivec.o \ - ppc/fft_altivec.o \ - ppc/gmc_altivec.o \ +ALTIVEC-OBJS-yes += ppc/dsputil_altivec.o \ ppc/fdct_altivec.o \ + ppc/fft_altivec.o \ ppc/float_altivec.o \ + ppc/gmc_altivec.o \ + ppc/idct_altivec.o \ + ppc/int_altivec.o \ + ppc/mpegvideo_altivec.o \ -ifeq ($(TARGET_ALTIVEC),yes) -OBJS-$(CONFIG_H264_DECODER) += ppc/h264_altivec.o -OBJS-$(CONFIG_SNOW_DECODER) += ppc/snow_altivec.o -OBJS-$(CONFIG_VC1_DECODER) += ppc/vc1dsp_altivec.o -OBJS-$(CONFIG_WMV3_DECODER) += ppc/vc1dsp_altivec.o -endif +ALTIVEC-OBJS-$(CONFIG_H264_DECODER) += ppc/h264_altivec.o +ALTIVEC-OBJS-$(CONFIG_SNOW_DECODER) += ppc/snow_altivec.o +ALTIVEC-OBJS-$(CONFIG_VC1_DECODER) += ppc/vc1dsp_altivec.o +ALTIVEC-OBJS-$(CONFIG_WMV3_DECODER) += ppc/vc1dsp_altivec.o -OBJS-$(TARGET_ARCH_BFIN) += bfin/dsputil_bfin.o \ +# -maltivec is needed in order to build AltiVec code. +$(ALTIVEC-OBJS-yes): CFLAGS += -maltivec -mabi=altivec -ASM_OBJS-$(TARGET_ARCH_BFIN) += bfin/pixels_bfin.o \ - bfin/idct_bfin.o \ +# check_altivec must be built without -maltivec +OBJS-$(HAVE_ALTIVEC) += $(ALTIVEC-OBJS-yes) \ + ppc/check_altivec.o + +OBJS-$(ARCH_BFIN) += bfin/dsputil_bfin.o \ + bfin/mpegvideo_bfin.o \ + bfin/vp3_bfin.o \ + +ASM_OBJS-$(ARCH_BFIN) += bfin/pixels_bfin.o \ bfin/fdct_bfin.o \ + bfin/idct_bfin.o \ + bfin/vp3_idct_bfin.o \ EXTRALIBS := -L$(BUILD_ROOT)/libavutil -lavutil$(BUILDSUF) $(EXTRALIBS) @@ -404,45 +458,28 @@ NAME=avcodec LIBVERSION=$(LAVCVERSION) LIBMAJOR=$(LAVCMAJOR) -TESTS= imgresample-test fft-test dct-test -ifeq ($(TARGET_ARCH_X86),yes) -TESTS+= cpuid_test motion-test +TESTS = $(addsuffix -test$(EXESUF), cabac dct eval fft h264 imgresample rangecoder snow) +ifeq ($(ARCH_X86),yes) +TESTS += cpuid-test$(EXESUF) motion-test$(EXESUF) endif include ../common.mak -amrlibs: - $(MAKE) -C amr spclib fipoplib - -tests: apiexample $(TESTS) - clean:: rm -f \ - i386/*.o i386/*~ \ + alpha/*.o alpha/*~ \ armv4l/*.o armv4l/*~ \ + bfin/*.o bfin/*~ \ + i386/*.o i386/*~ \ mlib/*.o mlib/*~ \ - alpha/*.o alpha/*~ \ ppc/*.o ppc/*~ \ ps2/*.o ps2/*~ \ sh4/*.o sh4/*~ \ sparc/*.o sparc/*~ \ - amr_float/*.o \ - apiexample $(TESTS) - -$(MAKE) -C amr clean - -$(MAKE) -C amrwb_float -f makefile.gcc clean - -apiexample: apiexample.o $(LIB) - -cpuid_test: i386/cputest.c - $(CC) $(CFLAGS) -D__TEST__ -o $@ $< - -imgresample-test: imgresample.c $(LIB) - $(CC) $(CFLAGS) -DTEST -o $@ $^ $(EXTRALIBS) - -dct-test: dct-test.o fdctref.o $(LIB) - -motion-test: motion_test.o $(LIB) - -fft-test: fft-test.o $(LIB) + apiexample$(EXESUF) -.PHONY: amrlibs tests +cpuid-test$(EXESUF): i386/cputest.c +apiexample$(EXESUF): apiexample.o $(LIBNAME) +dct-test$(EXESUF): dct-test.o fdctref.o $(LIBNAME) +fft-test$(EXESUF): fft-test.o $(LIBNAME) +motion-test$(EXESUF): motion-test.o $(LIBNAME) diff --git a/contrib/ffmpeg/libavcodec/a52dec.c b/contrib/ffmpeg/libavcodec/a52dec.c deleted file mode 100644 index c2da2283d..000000000 --- a/contrib/ffmpeg/libavcodec/a52dec.c +++ /dev/null @@ -1,259 +0,0 @@ -/* - * A52 decoder using liba52 - * Copyright (c) 2001 Fabrice Bellard. - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file a52dec.c - * A52 decoder using liba52 - */ - -#include "avcodec.h" -#include - -#ifdef CONFIG_LIBA52BIN -#include -static const char* liba52name = "liba52.so.0"; -#endif - -/** - * liba52 - Copyright (C) Aaron Holtzman - * released under the GPL license. - */ -typedef struct AC3DecodeState { - uint8_t inbuf[4096]; /* input buffer */ - uint8_t *inbuf_ptr; - int frame_size; - int flags; - int channels; - a52_state_t* state; - sample_t* samples; - - /* - * virtual method table - * - * using this function table so the liba52 doesn't - * have to be really linked together with ffmpeg - * and might be linked in runtime - this allows binary - * distribution of ffmpeg library which doens't depend - * on liba52 library - but if user has it installed - * it will be used - user might install such library - * separately - */ - void* handle; - a52_state_t* (*a52_init)(uint32_t mm_accel); - sample_t* (*a52_samples)(a52_state_t * state); - int (*a52_syncinfo)(uint8_t * buf, int * flags, - int * sample_rate, int * bit_rate); - int (*a52_frame)(a52_state_t * state, uint8_t * buf, int * flags, - sample_t * level, sample_t bias); - void (*a52_dynrng)(a52_state_t * state, - sample_t (* call) (sample_t, void *), void * data); - int (*a52_block)(a52_state_t * state); - void (*a52_free)(a52_state_t * state); - -} AC3DecodeState; - -#ifdef CONFIG_LIBA52BIN -static void* dlsymm(void* handle, const char* symbol) -{ - void* f = dlsym(handle, symbol); - if (!f) - av_log( NULL, AV_LOG_ERROR, "A52 Decoder - function '%s' can't be resolved\n", symbol); - return f; -} -#endif - -static int a52_decode_init(AVCodecContext *avctx) -{ - AC3DecodeState *s = avctx->priv_data; - -#ifdef CONFIG_LIBA52BIN - s->handle = dlopen(liba52name, RTLD_LAZY); - if (!s->handle) - { - av_log( avctx, AV_LOG_ERROR, "A52 library %s could not be opened! \n%s\n", liba52name, dlerror()); - return -1; - } - s->a52_init = (a52_state_t* (*)(uint32_t)) dlsymm(s->handle, "a52_init"); - s->a52_samples = (sample_t* (*)(a52_state_t*)) dlsymm(s->handle, "a52_samples"); - s->a52_syncinfo = (int (*)(uint8_t*, int*, int*, int*)) dlsymm(s->handle, "a52_syncinfo"); - s->a52_frame = (int (*)(a52_state_t*, uint8_t*, int*, sample_t*, sample_t)) dlsymm(s->handle, "a52_frame"); - s->a52_block = (int (*)(a52_state_t*)) dlsymm(s->handle, "a52_block"); - s->a52_free = (void (*)(a52_state_t*)) dlsymm(s->handle, "a52_free"); - if (!s->a52_init || !s->a52_samples || !s->a52_syncinfo - || !s->a52_frame || !s->a52_block || !s->a52_free) - { - dlclose(s->handle); - return -1; - } -#else - s->handle = 0; - s->a52_init = a52_init; - s->a52_samples = a52_samples; - s->a52_syncinfo = a52_syncinfo; - s->a52_frame = a52_frame; - s->a52_block = a52_block; - s->a52_free = a52_free; -#endif - s->state = s->a52_init(0); /* later use CPU flags */ - s->samples = s->a52_samples(s->state); - s->inbuf_ptr = s->inbuf; - s->frame_size = 0; - - return 0; -} - -/**** the following two functions comes from a52dec */ -static inline int blah (int32_t i) -{ - if (i > 0x43c07fff) - return 32767; - else if (i < 0x43bf8000) - return -32768; - return i - 0x43c00000; -} - -static inline void float_to_int (float * _f, int16_t * s16, int nchannels) -{ - int i, j, c; - int32_t * f = (int32_t *) _f; // XXX assumes IEEE float format - - j = 0; - nchannels *= 256; - for (i = 0; i < 256; i++) { - for (c = 0; c < nchannels; c += 256) - s16[j++] = blah (f[i + c]); - } -} - -/**** end */ - -#define HEADER_SIZE 7 - -static int a52_decode_frame(AVCodecContext *avctx, - void *data, int *data_size, - uint8_t *buf, int buf_size) -{ - AC3DecodeState *s = avctx->priv_data; - uint8_t *buf_ptr; - int flags, i, len; - int sample_rate, bit_rate; - short *out_samples = data; - float level; - static const int ac3_channels[8] = { - 2, 1, 2, 3, 3, 4, 4, 5 - }; - - *data_size= 0; - - buf_ptr = buf; - while (buf_size > 0) { - len = s->inbuf_ptr - s->inbuf; - if (s->frame_size == 0) { - /* no header seen : find one. We need at least 7 bytes to parse it */ - len = HEADER_SIZE - len; - if (len > buf_size) - len = buf_size; - memcpy(s->inbuf_ptr, buf_ptr, len); - buf_ptr += len; - s->inbuf_ptr += len; - buf_size -= len; - if ((s->inbuf_ptr - s->inbuf) == HEADER_SIZE) { - len = s->a52_syncinfo(s->inbuf, &s->flags, &sample_rate, &bit_rate); - if (len == 0) { - /* no sync found : move by one byte (inefficient, but simple!) */ - memcpy(s->inbuf, s->inbuf + 1, HEADER_SIZE - 1); - s->inbuf_ptr--; - } else { - s->frame_size = len; - /* update codec info */ - avctx->sample_rate = sample_rate; - s->channels = ac3_channels[s->flags & 7]; - if (s->flags & A52_LFE) - s->channels++; - if (avctx->channels == 0) - /* No specific number of channel requested */ - avctx->channels = s->channels; - else if (s->channels < avctx->channels) { - av_log(avctx, AV_LOG_ERROR, "ac3dec: AC3 Source channels are less than specified: output to %d channels.. (frmsize: %d)\n", s->channels, len); - avctx->channels = s->channels; - } - avctx->bit_rate = bit_rate; - } - } - } else if (len < s->frame_size) { - len = s->frame_size - len; - if (len > buf_size) - len = buf_size; - - memcpy(s->inbuf_ptr, buf_ptr, len); - buf_ptr += len; - s->inbuf_ptr += len; - buf_size -= len; - } else { - flags = s->flags; - if (avctx->channels == 1) - flags = A52_MONO; - else if (avctx->channels == 2) - flags = A52_STEREO; - else - flags |= A52_ADJUST_LEVEL; - level = 1; - if (s->a52_frame(s->state, s->inbuf, &flags, &level, 384)) { - fail: - av_log(avctx, AV_LOG_ERROR, "Error decoding frame\n"); - s->inbuf_ptr = s->inbuf; - s->frame_size = 0; - continue; - } - for (i = 0; i < 6; i++) { - if (s->a52_block(s->state)) - goto fail; - float_to_int(s->samples, out_samples + i * 256 * avctx->channels, avctx->channels); - } - s->inbuf_ptr = s->inbuf; - s->frame_size = 0; - *data_size = 6 * avctx->channels * 256 * sizeof(int16_t); - break; - } - } - return buf_ptr - buf; -} - -static int a52_decode_end(AVCodecContext *avctx) -{ - AC3DecodeState *s = avctx->priv_data; - s->a52_free(s->state); -#ifdef CONFIG_LIBA52BIN - dlclose(s->handle); -#endif - return 0; -} - -AVCodec liba52_decoder = { - "ac3", - CODEC_TYPE_AUDIO, - CODEC_ID_AC3, - sizeof(AC3DecodeState), - a52_decode_init, - NULL, - a52_decode_end, - a52_decode_frame, -}; diff --git a/contrib/ffmpeg/libavcodec/aac_ac3_parser.c b/contrib/ffmpeg/libavcodec/aac_ac3_parser.c new file mode 100644 index 000000000..999a18915 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/aac_ac3_parser.c @@ -0,0 +1,88 @@ +/* + * Common AAC and AC3 parser + * Copyright (c) 2003 Fabrice Bellard. + * Copyright (c) 2003 Michael Niedermayer. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "parser.h" +#include "aac_ac3_parser.h" + +int ff_aac_ac3_parse(AVCodecParserContext *s1, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + AACAC3ParseContext *s = s1->priv_data; + const uint8_t *buf_ptr; + int len, sample_rate, bit_rate, channels, samples; + + *poutbuf = NULL; + *poutbuf_size = 0; + + buf_ptr = buf; + while (buf_size > 0) { + int size_needed= s->frame_size ? s->frame_size : s->header_size; + len = s->inbuf_ptr - s->inbuf; + + if(leninbuf_ptr, buf_ptr, len); + buf_ptr += len; + s->inbuf_ptr += len; + buf_size -= len; + } + + if (s->frame_size == 0) { + if ((s->inbuf_ptr - s->inbuf) == s->header_size) { + len = s->sync(s->inbuf, &channels, &sample_rate, &bit_rate, + &samples); + if (len == 0) { + /* no sync found : move by one byte (inefficient, but simple!) */ + memmove(s->inbuf, s->inbuf + 1, s->header_size - 1); + s->inbuf_ptr--; + } else { + s->frame_size = len; + /* update codec info */ + avctx->sample_rate = sample_rate; + /* allow downmixing to stereo (or mono for AC3) */ + if(avctx->request_channels > 0 && + avctx->request_channels < channels && + (avctx->request_channels <= 2 || + (avctx->request_channels == 1 && + avctx->codec_id == CODEC_ID_AC3))) { + avctx->channels = avctx->request_channels; + } else { + avctx->channels = channels; + } + avctx->bit_rate = bit_rate; + avctx->frame_size = samples; + } + } + } else { + if(s->inbuf_ptr - s->inbuf == s->frame_size){ + *poutbuf = s->inbuf; + *poutbuf_size = s->frame_size; + s->inbuf_ptr = s->inbuf; + s->frame_size = 0; + break; + } + } + } + return buf_ptr - buf; +} diff --git a/contrib/ffmpeg/libavcodec/aac_ac3_parser.h b/contrib/ffmpeg/libavcodec/aac_ac3_parser.h new file mode 100644 index 000000000..e927de02d --- /dev/null +++ b/contrib/ffmpeg/libavcodec/aac_ac3_parser.h @@ -0,0 +1,43 @@ +/* + * Common AAC and AC3 parser prototypes + * Copyright (c) 2003 Fabrice Bellard. + * Copyright (c) 2003 Michael Niedermayer. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_AAC_AC3_PARSER_H +#define FFMPEG_AAC_AC3_PARSER_H + +#include +#include "avcodec.h" + +typedef struct AACAC3ParseContext { + uint8_t *inbuf_ptr; + int frame_size; + int header_size; + int (*sync)(const uint8_t *buf, int *channels, int *sample_rate, + int *bit_rate, int *samples); + uint8_t inbuf[8192]; /* input buffer */ +} AACAC3ParseContext; + +int ff_aac_ac3_parse(AVCodecParserContext *s1, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size); + +#endif /* FFMPEG_AAC_AC3_PARSER_H */ diff --git a/contrib/ffmpeg/libavcodec/aac_parser.c b/contrib/ffmpeg/libavcodec/aac_parser.c new file mode 100644 index 000000000..ac806931e --- /dev/null +++ b/contrib/ffmpeg/libavcodec/aac_parser.c @@ -0,0 +1,100 @@ +/* + * Audio and Video frame extraction + * Copyright (c) 2003 Fabrice Bellard. + * Copyright (c) 2003 Michael Niedermayer. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "parser.h" +#include "aac_ac3_parser.h" +#include "bitstream.h" + + +#define AAC_HEADER_SIZE 7 + + +static const int aac_sample_rates[16] = { + 96000, 88200, 64000, 48000, 44100, 32000, + 24000, 22050, 16000, 12000, 11025, 8000, 7350 +}; + +static const int aac_channels[8] = { + 0, 1, 2, 3, 4, 5, 6, 8 +}; + + +static int aac_sync(const uint8_t *buf, int *channels, int *sample_rate, + int *bit_rate, int *samples) +{ + GetBitContext bits; + int size, rdb, ch, sr; + + init_get_bits(&bits, buf, AAC_HEADER_SIZE * 8); + + if(get_bits(&bits, 12) != 0xfff) + return 0; + + skip_bits1(&bits); /* id */ + skip_bits(&bits, 2); /* layer */ + skip_bits1(&bits); /* protection_absent */ + skip_bits(&bits, 2); /* profile_objecttype */ + sr = get_bits(&bits, 4); /* sample_frequency_index */ + if(!aac_sample_rates[sr]) + return 0; + skip_bits1(&bits); /* private_bit */ + ch = get_bits(&bits, 3); /* channel_configuration */ + if(!aac_channels[ch]) + return 0; + skip_bits1(&bits); /* original/copy */ + skip_bits1(&bits); /* home */ + + /* adts_variable_header */ + skip_bits1(&bits); /* copyright_identification_bit */ + skip_bits1(&bits); /* copyright_identification_start */ + size = get_bits(&bits, 13); /* aac_frame_length */ + if(size < AAC_HEADER_SIZE) + return 0; + + skip_bits(&bits, 11); /* adts_buffer_fullness */ + rdb = get_bits(&bits, 2); /* number_of_raw_data_blocks_in_frame */ + + *channels = aac_channels[ch]; + *sample_rate = aac_sample_rates[sr]; + *samples = (rdb + 1) * 1024; + *bit_rate = size * 8 * *sample_rate / *samples; + + return size; +} + +static int aac_parse_init(AVCodecParserContext *s1) +{ + AACAC3ParseContext *s = s1->priv_data; + s->inbuf_ptr = s->inbuf; + s->header_size = AAC_HEADER_SIZE; + s->sync = aac_sync; + return 0; +} + + +AVCodecParser aac_parser = { + { CODEC_ID_AAC }, + sizeof(AACAC3ParseContext), + aac_parse_init, + ff_aac_ac3_parse, + NULL, +}; diff --git a/contrib/ffmpeg/libavcodec/aasc.c b/contrib/ffmpeg/libavcodec/aasc.c index 8f26fae87..62912a81a 100644 --- a/contrib/ffmpeg/libavcodec/aasc.c +++ b/contrib/ffmpeg/libavcodec/aasc.c @@ -28,7 +28,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include "dsputil.h" @@ -47,7 +46,7 @@ typedef struct AascContext { static int aasc_decode_init(AVCodecContext *avctx) { - AascContext *s = (AascContext *)avctx->priv_data; + AascContext *s = avctx->priv_data; s->avctx = avctx; @@ -59,9 +58,9 @@ static int aasc_decode_init(AVCodecContext *avctx) static int aasc_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { - AascContext *s = (AascContext *)avctx->priv_data; + AascContext *s = avctx->priv_data; int stream_ptr = 4; unsigned char rle_code; unsigned char stream_byte; @@ -153,7 +152,7 @@ static int aasc_decode_frame(AVCodecContext *avctx, static int aasc_decode_end(AVCodecContext *avctx) { - AascContext *s = (AascContext *)avctx->priv_data; + AascContext *s = avctx->priv_data; /* release the last frame */ if (s->frame.data[0]) diff --git a/contrib/ffmpeg/libavcodec/ac3.c b/contrib/ffmpeg/libavcodec/ac3.c index 3749d02f0..cc80277bc 100644 --- a/contrib/ffmpeg/libavcodec/ac3.c +++ b/contrib/ffmpeg/libavcodec/ac3.c @@ -26,9 +26,11 @@ #include "avcodec.h" #include "ac3.h" -#include "ac3tab.h" #include "bitstream.h" +static uint8_t band_start_tab[51]; +static uint8_t bin_to_band_tab[253]; + static inline int calc_lowcomp1(int a, int b0, int b1, int c) { if ((b0 + 256) == b1) { @@ -51,7 +53,7 @@ static inline int calc_lowcomp(int a, int b0, int b1, int bin) } void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, - int16_t *bndpsd) + int16_t *band_psd) { int bin, i, j, k, end1, v; @@ -62,26 +64,26 @@ void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, /* PSD integration */ j=start; - k=masktab[start]; + k=bin_to_band_tab[start]; do { v=psd[j]; j++; - end1 = FFMIN(bndtab[k+1], end); + end1 = FFMIN(band_start_tab[k+1], end); for(i=j;i> 1, 255); - v = FFMAX(v, psd[j]) + latab[adr]; + v = FFMAX(v, psd[j]) + ff_ac3_log_add_tab[adr]; j++; } - bndpsd[k]=v; + band_psd[k]=v; k++; - } while (end > bndtab[k]); + } while (end > band_start_tab[k]); } -void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd, - int start, int end, int fgain, int is_lfe, - int deltbae, int deltnseg, uint8_t *deltoffst, - uint8_t *deltlen, uint8_t *deltba, +void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, + int start, int end, int fast_gain, int is_lfe, + int dba_mode, int dba_nsegs, uint8_t *dba_offsets, + uint8_t *dba_lengths, uint8_t *dba_values, int16_t *mask) { int16_t excite[50]; /* excitation */ @@ -90,24 +92,24 @@ void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd, int lowcomp, fastleak, slowleak; /* excitation function */ - bndstrt = masktab[start]; - bndend = masktab[end-1] + 1; + bndstrt = bin_to_band_tab[start]; + bndend = bin_to_band_tab[end-1] + 1; if (bndstrt == 0) { lowcomp = 0; - lowcomp = calc_lowcomp1(lowcomp, bndpsd[0], bndpsd[1], 384); - excite[0] = bndpsd[0] - fgain - lowcomp; - lowcomp = calc_lowcomp1(lowcomp, bndpsd[1], bndpsd[2], 384); - excite[1] = bndpsd[1] - fgain - lowcomp; + lowcomp = calc_lowcomp1(lowcomp, band_psd[0], band_psd[1], 384); + excite[0] = band_psd[0] - fast_gain - lowcomp; + lowcomp = calc_lowcomp1(lowcomp, band_psd[1], band_psd[2], 384); + excite[1] = band_psd[1] - fast_gain - lowcomp; begin = 7; for (bin = 2; bin < 7; bin++) { if (!(is_lfe && bin == 6)) - lowcomp = calc_lowcomp1(lowcomp, bndpsd[bin], bndpsd[bin+1], 384); - fastleak = bndpsd[bin] - fgain; - slowleak = bndpsd[bin] - s->sgain; + lowcomp = calc_lowcomp1(lowcomp, band_psd[bin], band_psd[bin+1], 384); + fastleak = band_psd[bin] - fast_gain; + slowleak = band_psd[bin] - s->slow_gain; excite[bin] = fastleak - lowcomp; if (!(is_lfe && bin == 6)) { - if (bndpsd[bin] <= bndpsd[bin+1]) { + if (band_psd[bin] <= band_psd[bin+1]) { begin = bin + 1; break; } @@ -119,10 +121,10 @@ void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd, for (bin = begin; bin < end1; bin++) { if (!(is_lfe && bin == 6)) - lowcomp = calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin+1], bin); + lowcomp = calc_lowcomp(lowcomp, band_psd[bin], band_psd[bin+1], bin); - fastleak = FFMAX(fastleak - s->fdecay, bndpsd[bin] - fgain); - slowleak = FFMAX(slowleak - s->sdecay, bndpsd[bin] - s->sgain); + fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain); + slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain); excite[bin] = FFMAX(fastleak - lowcomp, slowleak); } begin = 22; @@ -130,39 +132,39 @@ void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd, /* coupling channel */ begin = bndstrt; - fastleak = (s->cplfleak << 8) + 768; - slowleak = (s->cplsleak << 8) + 768; + fastleak = (s->cpl_fast_leak << 8) + 768; + slowleak = (s->cpl_slow_leak << 8) + 768; } for (bin = begin; bin < bndend; bin++) { - fastleak = FFMAX(fastleak - s->fdecay, bndpsd[bin] - fgain); - slowleak = FFMAX(slowleak - s->sdecay, bndpsd[bin] - s->sgain); + fastleak = FFMAX(fastleak - s->fast_decay, band_psd[bin] - fast_gain); + slowleak = FFMAX(slowleak - s->slow_decay, band_psd[bin] - s->slow_gain); excite[bin] = FFMAX(fastleak, slowleak); } /* compute masking curve */ for (bin = bndstrt; bin < bndend; bin++) { - tmp = s->dbknee - bndpsd[bin]; + tmp = s->db_per_bit - band_psd[bin]; if (tmp > 0) { excite[bin] += tmp >> 2; } - mask[bin] = FFMAX(hth[bin >> s->halfratecod][s->fscod], excite[bin]); + mask[bin] = FFMAX(ff_ac3_hearing_threshold_tab[bin >> s->sr_shift][s->sr_code], excite[bin]); } /* delta bit allocation */ - if (deltbae == 0 || deltbae == 1) { + if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) { int band, seg, delta; band = 0; - for (seg = 0; seg < deltnseg; seg++) { - band += deltoffst[seg]; - if (deltba[seg] >= 4) { - delta = (deltba[seg] - 3) << 7; + for (seg = 0; seg < dba_nsegs; seg++) { + band += dba_offsets[seg]; + if (dba_values[seg] >= 4) { + delta = (dba_values[seg] - 3) << 7; } else { - delta = (deltba[seg] - 4) << 7; + delta = (dba_values[seg] - 4) << 7; } - for (k = 0; k < deltlen[seg]; k++) { + for (k = 0; k < dba_lengths[seg]; k++) { mask[band] += delta; band++; } @@ -171,49 +173,49 @@ void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd, } void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end, - int snroffset, int floor, uint8_t *bap) + int snr_offset, int floor, uint8_t *bap) { int i, j, k, end1, v, address; - /* special case, if snroffset is -960, set all bap's to zero */ - if(snroffset == -960) { + /* special case, if snr offset is -960, set all bap's to zero */ + if(snr_offset == -960) { memset(bap, 0, 256); return; } i = start; - j = masktab[start]; + j = bin_to_band_tab[start]; do { - v = (FFMAX(mask[j] - snroffset - floor, 0) & 0x1FE0) + floor; - end1 = FFMIN(bndtab[j] + bndsz[j], end); + v = (FFMAX(mask[j] - snr_offset - floor, 0) & 0x1FE0) + floor; + end1 = FFMIN(band_start_tab[j] + ff_ac3_critical_band_size_tab[j], end); for (k = i; k < end1; k++) { address = av_clip((psd[i] - v) >> 5, 0, 63); - bap[i] = baptab[address]; + bap[i] = ff_ac3_bap_tab[address]; i++; } - } while (end > bndtab[j++]); + } while (end > band_start_tab[j++]); } /* AC3 bit allocation. The algorithm is the one described in the AC3 spec. */ void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap, int8_t *exp, int start, int end, - int snroffset, int fgain, int is_lfe, - int deltbae,int deltnseg, - uint8_t *deltoffst, uint8_t *deltlen, - uint8_t *deltba) + int snr_offset, int fast_gain, int is_lfe, + int dba_mode, int dba_nsegs, + uint8_t *dba_offsets, uint8_t *dba_lengths, + uint8_t *dba_values) { int16_t psd[256]; /* scaled exponents */ - int16_t bndpsd[50]; /* interpolated exponents */ + int16_t band_psd[50]; /* interpolated exponents */ int16_t mask[50]; /* masking value */ - ff_ac3_bit_alloc_calc_psd(exp, start, end, psd, bndpsd); + ff_ac3_bit_alloc_calc_psd(exp, start, end, psd, band_psd); - ff_ac3_bit_alloc_calc_mask(s, bndpsd, start, end, fgain, is_lfe, - deltbae, deltnseg, deltoffst, deltlen, deltba, + ff_ac3_bit_alloc_calc_mask(s, band_psd, start, end, fast_gain, is_lfe, + dba_mode, dba_nsegs, dba_offsets, dba_lengths, dba_values, mask); - ff_ac3_bit_alloc_calc_bap(mask, psd, start, end, snroffset, s->floor, bap); + ff_ac3_bit_alloc_calc_bap(mask, psd, start, end, snr_offset, s->floor, bap); } /** @@ -228,60 +230,10 @@ void ac3_common_init(void) k = 0; l = 0; for(i=0;i<50;i++) { - bndtab[i] = l; - v = bndsz[i]; - for(j=0;jsync_word = get_bits(&gbc, 16); - if(hdr->sync_word != 0x0B77) - return -1; - - /* read ahead to bsid to make sure this is AC-3, not E-AC-3 */ - hdr->bsid = show_bits_long(&gbc, 29) & 0x1F; - if(hdr->bsid > 10) - return -2; - - hdr->crc1 = get_bits(&gbc, 16); - hdr->fscod = get_bits(&gbc, 2); - if(hdr->fscod == 3) - return -3; - - hdr->frmsizecod = get_bits(&gbc, 6); - if(hdr->frmsizecod > 37) - return -4; - - skip_bits(&gbc, 5); // skip bsid, already got it - - hdr->bsmod = get_bits(&gbc, 3); - hdr->acmod = get_bits(&gbc, 3); - if((hdr->acmod & 1) && hdr->acmod != 1) { - hdr->cmixlev = get_bits(&gbc, 2); - } - if(hdr->acmod & 4) { - hdr->surmixlev = get_bits(&gbc, 2); - } - if(hdr->acmod == 2) { - hdr->dsurmod = get_bits(&gbc, 2); - } - hdr->lfeon = get_bits1(&gbc); - - hdr->halfratecod = FFMAX(hdr->bsid, 8) - 8; - hdr->sample_rate = ff_ac3_freqs[hdr->fscod] >> hdr->halfratecod; - hdr->bit_rate = (ff_ac3_bitratetab[hdr->frmsizecod>>1] * 1000) >> hdr->halfratecod; - hdr->channels = ff_ac3_channels[hdr->acmod] + hdr->lfeon; - hdr->frame_size = ff_ac3_frame_sizes[hdr->frmsizecod][hdr->fscod] * 2; - - return 0; + band_start_tab[50] = l; } diff --git a/contrib/ffmpeg/libavcodec/ac3.h b/contrib/ffmpeg/libavcodec/ac3.h index ae53a80c3..b5fa789c4 100644 --- a/contrib/ffmpeg/libavcodec/ac3.h +++ b/contrib/ffmpeg/libavcodec/ac3.h @@ -24,6 +24,11 @@ * Common code between AC3 encoder and decoder. */ +#ifndef FFMPEG_AC3_H +#define FFMPEG_AC3_H + +#include "ac3tab.h" + #define AC3_MAX_CODED_FRAME_SIZE 3840 /* in bytes */ #define AC3_MAX_CHANNELS 6 /* including LFE channel */ @@ -38,11 +43,31 @@ #define EXP_D25 2 #define EXP_D45 3 +/** Delta bit allocation strategy */ +typedef enum { + DBA_REUSE = 0, + DBA_NEW, + DBA_NONE, + DBA_RESERVED +} AC3DeltaStrategy; + +/** Channel mode (audio coding mode) */ +typedef enum { + AC3_CHMODE_DUALMONO = 0, + AC3_CHMODE_MONO, + AC3_CHMODE_STEREO, + AC3_CHMODE_3F, + AC3_CHMODE_2F1R, + AC3_CHMODE_3F1R, + AC3_CHMODE_2F2R, + AC3_CHMODE_3F2R +} AC3ChannelMode; + typedef struct AC3BitAllocParameters { - int fscod; /* frequency */ - int halfratecod; - int sgain, sdecay, fdecay, dbknee, floor; - int cplfleak, cplsleak; + int sr_code; + int sr_shift; + int slow_gain, slow_decay, fast_decay, db_per_bit, floor; + int cpl_fast_leak, cpl_slow_leak; } AC3BitAllocParameters; /** @@ -55,21 +80,16 @@ typedef struct { */ uint16_t sync_word; uint16_t crc1; - uint8_t fscod; - uint8_t frmsizecod; - uint8_t bsid; - uint8_t bsmod; - uint8_t acmod; - uint8_t cmixlev; - uint8_t surmixlev; - uint8_t dsurmod; - uint8_t lfeon; + uint8_t sr_code; + uint8_t bitstream_id; + uint8_t channel_mode; + uint8_t lfe_on; /** @} */ /** @defgroup derived Derived values * @{ */ - uint8_t halfratecod; + uint8_t sr_shift; uint16_t sample_rate; uint32_t bit_rate; uint8_t channels; @@ -77,29 +97,6 @@ typedef struct { /** @} */ } AC3HeaderInfo; -/** - * Parses AC-3 frame header. - * Parses the header up to the lfeon element, which is the first 52 or 54 bits - * depending on the audio coding mode. - * @param buf[in] Array containing the first 7 bytes of the frame. - * @param hdr[out] Pointer to struct where header info is written. - * @return Returns 0 on success, -1 if there is a sync word mismatch, - * -2 if the bsid (version) element is invalid, -3 if the fscod (sample rate) - * element is invalid, or -4 if the frmsizecod (bit rate) element is invalid. - */ -int ff_ac3_parse_header(const uint8_t buf[7], AC3HeaderInfo *hdr); - -extern const uint16_t ff_ac3_frame_sizes[38][3]; -extern const uint8_t ff_ac3_channels[8]; -extern const uint16_t ff_ac3_freqs[3]; -extern const uint16_t ff_ac3_bitratetab[19]; -extern const int16_t ff_ac3_window[256]; -extern const uint8_t ff_sdecaytab[4]; -extern const uint8_t ff_fdecaytab[4]; -extern const uint16_t ff_sgaintab[4]; -extern const uint16_t ff_dbkneetab[4]; -extern const int16_t ff_floortab[8]; -extern const uint16_t ff_fgaintab[8]; void ac3_common_init(void); @@ -115,10 +112,10 @@ void ac3_common_init(void); * @param[in] start starting bin location * @param[in] end ending bin location * @param[out] psd signal power for each frequency bin - * @param[out] bndpsd signal power for each critical band + * @param[out] band_psd signal power for each critical band */ void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, - int16_t *bndpsd); + int16_t *band_psd); /** * Calculates the masking curve. @@ -128,23 +125,23 @@ void ff_ac3_bit_alloc_calc_psd(int8_t *exp, int start, int end, int16_t *psd, * allocation information is provided, it is used for adjusting the masking * curve, usually to give a closer match to a better psychoacoustic model. * - * @param[in] s adjustable bit allocation parameters - * @param[in] bndpsd signal power for each critical band - * @param[in] start starting bin location - * @param[in] end ending bin location - * @param[in] fgain fast gain (estimated signal-to-mask ratio) - * @param[in] is_lfe whether or not the channel being processed is the LFE - * @param[in] deltbae delta bit allocation exists (none, reuse, or new) - * @param[in] deltnseg number of delta segments - * @param[in] deltoffst location offsets for each segment - * @param[in] deltlen length of each segment - * @param[in] deltba delta bit allocation for each segment - * @param[out] mask calculated masking curve + * @param[in] s adjustable bit allocation parameters + * @param[in] band_psd signal power for each critical band + * @param[in] start starting bin location + * @param[in] end ending bin location + * @param[in] fast_gain fast gain (estimated signal-to-mask ratio) + * @param[in] is_lfe whether or not the channel being processed is the LFE + * @param[in] dba_mode delta bit allocation mode (none, reuse, or new) + * @param[in] dba_nsegs number of delta segments + * @param[in] dba_offsets location offsets for each segment + * @param[in] dba_lengths length of each segment + * @param[in] dba_values delta bit allocation for each segment + * @param[out] mask calculated masking curve */ -void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd, - int start, int end, int fgain, int is_lfe, - int deltbae, int deltnseg, uint8_t *deltoffst, - uint8_t *deltlen, uint8_t *deltba, +void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, + int start, int end, int fast_gain, int is_lfe, + int dba_mode, int dba_nsegs, uint8_t *dba_offsets, + uint8_t *dba_lengths, uint8_t *dba_values, int16_t *mask); /** @@ -157,15 +154,18 @@ void ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *bndpsd, * @param[in] psd signal power for each frequency bin * @param[in] start starting bin location * @param[in] end ending bin location - * @param[in] snroffset SNR adjustment + * @param[in] snr_offset SNR adjustment * @param[in] floor noise floor * @param[out] bap bit allocation pointers */ void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end, - int snroffset, int floor, uint8_t *bap); + int snr_offset, int floor, uint8_t *bap); void ac3_parametric_bit_allocation(AC3BitAllocParameters *s, uint8_t *bap, int8_t *exp, int start, int end, - int snroffset, int fgain, int is_lfe, - int deltbae,int deltnseg, - uint8_t *deltoffst, uint8_t *deltlen, uint8_t *deltba); + int snr_offset, int fast_gain, int is_lfe, + int dba_mode, int dba_nsegs, + uint8_t *dba_offsets, uint8_t *dba_lengths, + uint8_t *dba_values); + +#endif /* FFMPEG_AC3_H */ diff --git a/contrib/ffmpeg/libavcodec/ac3_parser.c b/contrib/ffmpeg/libavcodec/ac3_parser.c new file mode 100644 index 000000000..9bda20380 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/ac3_parser.c @@ -0,0 +1,156 @@ +/* + * AC3 parser + * Copyright (c) 2003 Fabrice Bellard. + * Copyright (c) 2003 Michael Niedermayer. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "parser.h" +#include "ac3_parser.h" +#include "aac_ac3_parser.h" +#include "bitstream.h" + + +#define AC3_HEADER_SIZE 7 + + +static const uint8_t eac3_blocks[4] = { + 1, 2, 3, 6 +}; + + +int ff_ac3_parse_header(const uint8_t buf[7], AC3HeaderInfo *hdr) +{ + GetBitContext gbc; + int frame_size_code; + int num_blocks; + + memset(hdr, 0, sizeof(*hdr)); + + init_get_bits(&gbc, buf, 54); + + hdr->sync_word = get_bits(&gbc, 16); + if(hdr->sync_word != 0x0B77) + return AC3_PARSE_ERROR_SYNC; + + /* read ahead to bsid to distinguish between AC-3 and E-AC-3 */ + hdr->bitstream_id = show_bits_long(&gbc, 29) & 0x1F; + if(hdr->bitstream_id > 16) + return AC3_PARSE_ERROR_BSID; + + if(hdr->bitstream_id <= 10) { + /* Normal AC-3 */ + hdr->crc1 = get_bits(&gbc, 16); + hdr->sr_code = get_bits(&gbc, 2); + if(hdr->sr_code == 3) + return AC3_PARSE_ERROR_SAMPLE_RATE; + + frame_size_code = get_bits(&gbc, 6); + if(frame_size_code > 37) + return AC3_PARSE_ERROR_FRAME_SIZE; + + skip_bits(&gbc, 5); // skip bsid, already got it + + skip_bits(&gbc, 3); // skip bitstream mode + hdr->channel_mode = get_bits(&gbc, 3); + if((hdr->channel_mode & 1) && hdr->channel_mode != AC3_CHMODE_MONO) { + skip_bits(&gbc, 2); // skip center mix level + } + if(hdr->channel_mode & 4) { + skip_bits(&gbc, 2); // skip surround mix level + } + if(hdr->channel_mode == AC3_CHMODE_STEREO) { + skip_bits(&gbc, 2); // skip dolby surround mode + } + hdr->lfe_on = get_bits1(&gbc); + + hdr->sr_shift = FFMAX(hdr->bitstream_id, 8) - 8; + hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code] >> hdr->sr_shift; + hdr->bit_rate = (ff_ac3_bitrate_tab[frame_size_code>>1] * 1000) >> hdr->sr_shift; + hdr->channels = ff_ac3_channels_tab[hdr->channel_mode] + hdr->lfe_on; + hdr->frame_size = ff_ac3_frame_size_tab[frame_size_code][hdr->sr_code] * 2; + } else { + /* Enhanced AC-3 */ + hdr->crc1 = 0; + skip_bits(&gbc, 2); // skip stream type + skip_bits(&gbc, 3); // skip substream id + + hdr->frame_size = (get_bits(&gbc, 11) + 1) << 1; + if(hdr->frame_size < AC3_HEADER_SIZE) + return AC3_PARSE_ERROR_FRAME_SIZE; + + hdr->sr_code = get_bits(&gbc, 2); + if (hdr->sr_code == 3) { + int sr_code2 = get_bits(&gbc, 2); + if(sr_code2 == 3) + return AC3_PARSE_ERROR_SAMPLE_RATE; + hdr->sample_rate = ff_ac3_sample_rate_tab[sr_code2] / 2; + hdr->sr_shift = 1; + num_blocks = 6; + } else { + num_blocks = eac3_blocks[get_bits(&gbc, 2)]; + hdr->sample_rate = ff_ac3_sample_rate_tab[hdr->sr_code]; + hdr->sr_shift = 0; + } + + hdr->channel_mode = get_bits(&gbc, 3); + hdr->lfe_on = get_bits1(&gbc); + + hdr->bit_rate = (uint32_t)(8.0 * hdr->frame_size * hdr->sample_rate / + (num_blocks * 256.0)); + hdr->channels = ff_ac3_channels_tab[hdr->channel_mode] + hdr->lfe_on; + } + + return 0; +} + +static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate, + int *bit_rate, int *samples) +{ + int err; + AC3HeaderInfo hdr; + + err = ff_ac3_parse_header(buf, &hdr); + + if(err < 0) + return 0; + + *sample_rate = hdr.sample_rate; + *bit_rate = hdr.bit_rate; + *channels = hdr.channels; + *samples = AC3_FRAME_SIZE; + return hdr.frame_size; +} + +static int ac3_parse_init(AVCodecParserContext *s1) +{ + AACAC3ParseContext *s = s1->priv_data; + s->inbuf_ptr = s->inbuf; + s->header_size = AC3_HEADER_SIZE; + s->sync = ac3_sync; + return 0; +} + + +AVCodecParser ac3_parser = { + { CODEC_ID_AC3 }, + sizeof(AACAC3ParseContext), + ac3_parse_init, + ff_aac_ac3_parse, + NULL, +}; diff --git a/contrib/ffmpeg/libavcodec/ac3_parser.h b/contrib/ffmpeg/libavcodec/ac3_parser.h new file mode 100644 index 000000000..ffac6190f --- /dev/null +++ b/contrib/ffmpeg/libavcodec/ac3_parser.h @@ -0,0 +1,47 @@ +/* + * AC3 parser prototypes + * Copyright (c) 2003 Fabrice Bellard. + * Copyright (c) 2003 Michael Niedermayer. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_AC3_PARSER_H +#define FFMPEG_AC3_PARSER_H + +#include "ac3.h" + +typedef enum { + AC3_PARSE_ERROR_SYNC = -1, + AC3_PARSE_ERROR_BSID = -2, + AC3_PARSE_ERROR_SAMPLE_RATE = -3, + AC3_PARSE_ERROR_FRAME_SIZE = -4, +} AC3ParseError; + +/** + * Parses AC-3 frame header. + * Parses the header up to the lfeon element, which is the first 52 or 54 bits + * depending on the audio coding mode. + * @param buf[in] Array containing the first 7 bytes of the frame. + * @param hdr[out] Pointer to struct where header info is written. + * @return Returns 0 on success, -1 if there is a sync word mismatch, + * -2 if the bsid (version) element is invalid, -3 if the fscod (sample rate) + * element is invalid, or -4 if the frmsizecod (bit rate) element is invalid. + */ +int ff_ac3_parse_header(const uint8_t buf[7], AC3HeaderInfo *hdr); + +#endif /* FFMPEG_AC3_PARSER_H */ diff --git a/contrib/ffmpeg/libavcodec/ac3dec.c b/contrib/ffmpeg/libavcodec/ac3dec.c new file mode 100644 index 000000000..0ce75e769 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/ac3dec.c @@ -0,0 +1,1173 @@ +/* + * AC-3 Audio Decoder + * This code is developed as part of Google Summer of Code 2006 Program. + * + * Copyright (c) 2006 Kartikey Mahendra BHATT (bhattkm at gmail dot com). + * Copyright (c) 2007 Justin Ruggles + * + * Portions of this code are derived from liba52 + * http://liba52.sourceforge.net + * Copyright (C) 2000-2003 Michel Lespinasse + * Copyright (C) 1999-2000 Aaron Holtzman + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * FFmpeg 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include + +#include "avcodec.h" +#include "ac3_parser.h" +#include "bitstream.h" +#include "crc.h" +#include "dsputil.h" +#include "random.h" + +/** + * Table of bin locations for rematrixing bands + * reference: Section 7.5.2 Rematrixing : Frequency Band Definitions + */ +static const uint8_t rematrix_band_tab[5] = { 13, 25, 37, 61, 253 }; + +/** + * table for exponent to scale_factor mapping + * scale_factors[i] = 2 ^ -i + */ +static float scale_factors[25]; + +/** table for grouping exponents */ +static uint8_t exp_ungroup_tab[128][3]; + + +/** tables for ungrouping mantissas */ +static float b1_mantissas[32][3]; +static float b2_mantissas[128][3]; +static float b3_mantissas[8]; +static float b4_mantissas[128][2]; +static float b5_mantissas[16]; + +/** + * Quantization table: levels for symmetric. bits for asymmetric. + * reference: Table 7.18 Mapping of bap to Quantizer + */ +static const uint8_t quantization_tab[16] = { + 0, 3, 5, 7, 11, 15, + 5, 6, 7, 8, 9, 10, 11, 12, 14, 16 +}; + +/** dynamic range table. converts codes to scale factors. */ +static float dynamic_range_tab[256]; + +/** Adjustments in dB gain */ +#define LEVEL_MINUS_3DB 0.7071067811865476 +#define LEVEL_MINUS_4POINT5DB 0.5946035575013605 +#define LEVEL_MINUS_6DB 0.5000000000000000 +#define LEVEL_MINUS_9DB 0.3535533905932738 +#define LEVEL_ZERO 0.0000000000000000 +#define LEVEL_ONE 1.0000000000000000 + +static const float gain_levels[6] = { + LEVEL_ZERO, + LEVEL_ONE, + LEVEL_MINUS_3DB, + LEVEL_MINUS_4POINT5DB, + LEVEL_MINUS_6DB, + LEVEL_MINUS_9DB +}; + +/** + * Table for center mix levels + * reference: Section 5.4.2.4 cmixlev + */ +static const uint8_t center_levels[4] = { 2, 3, 4, 3 }; + +/** + * Table for surround mix levels + * reference: Section 5.4.2.5 surmixlev + */ +static const uint8_t surround_levels[4] = { 2, 4, 0, 4 }; + +/** + * Table for default stereo downmixing coefficients + * reference: Section 7.8.2 Downmixing Into Two Channels + */ +static const uint8_t ac3_default_coeffs[8][5][2] = { + { { 1, 0 }, { 0, 1 }, }, + { { 2, 2 }, }, + { { 1, 0 }, { 0, 1 }, }, + { { 1, 0 }, { 3, 3 }, { 0, 1 }, }, + { { 1, 0 }, { 0, 1 }, { 4, 4 }, }, + { { 1, 0 }, { 3, 3 }, { 0, 1 }, { 5, 5 }, }, + { { 1, 0 }, { 0, 1 }, { 4, 0 }, { 0, 4 }, }, + { { 1, 0 }, { 3, 3 }, { 0, 1 }, { 4, 0 }, { 0, 4 }, }, +}; + +/* override ac3.h to include coupling channel */ +#undef AC3_MAX_CHANNELS +#define AC3_MAX_CHANNELS 7 +#define CPL_CH 0 + +#define AC3_OUTPUT_LFEON 8 + +typedef struct { + int channel_mode; ///< channel mode (acmod) + int block_switch[AC3_MAX_CHANNELS]; ///< block switch flags + int dither_flag[AC3_MAX_CHANNELS]; ///< dither flags + int dither_all; ///< true if all channels are dithered + int cpl_in_use; ///< coupling in use + int channel_in_cpl[AC3_MAX_CHANNELS]; ///< channel in coupling + int phase_flags_in_use; ///< phase flags in use + int phase_flags[18]; ///< phase flags + int cpl_band_struct[18]; ///< coupling band structure + int num_rematrixing_bands; ///< number of rematrixing bands + int rematrixing_flags[4]; ///< rematrixing flags + int exp_strategy[AC3_MAX_CHANNELS]; ///< exponent strategies + int snr_offset[AC3_MAX_CHANNELS]; ///< signal-to-noise ratio offsets + int fast_gain[AC3_MAX_CHANNELS]; ///< fast gain values (signal-to-mask ratio) + int dba_mode[AC3_MAX_CHANNELS]; ///< delta bit allocation mode + int dba_nsegs[AC3_MAX_CHANNELS]; ///< number of delta segments + uint8_t dba_offsets[AC3_MAX_CHANNELS][8]; ///< delta segment offsets + uint8_t dba_lengths[AC3_MAX_CHANNELS][8]; ///< delta segment lengths + uint8_t dba_values[AC3_MAX_CHANNELS][8]; ///< delta values for each segment + + int sample_rate; ///< sample frequency, in Hz + int bit_rate; ///< stream bit rate, in bits-per-second + int frame_size; ///< current frame size, in bytes + + int channels; ///< number of total channels + int fbw_channels; ///< number of full-bandwidth channels + int lfe_on; ///< lfe channel in use + int lfe_ch; ///< index of LFE channel + int output_mode; ///< output channel configuration + int out_channels; ///< number of output channels + + int center_mix_level; ///< Center mix level index + int surround_mix_level; ///< Surround mix level index + float downmix_coeffs[AC3_MAX_CHANNELS][2]; ///< stereo downmix coefficients + float dynamic_range[2]; ///< dynamic range + float cpl_coords[AC3_MAX_CHANNELS][18]; ///< coupling coordinates + int num_cpl_bands; ///< number of coupling bands + int num_cpl_subbands; ///< number of coupling sub bands + int start_freq[AC3_MAX_CHANNELS]; ///< start frequency bin + int end_freq[AC3_MAX_CHANNELS]; ///< end frequency bin + AC3BitAllocParameters bit_alloc_params; ///< bit allocation parameters + + int8_t dexps[AC3_MAX_CHANNELS][256]; ///< decoded exponents + uint8_t bap[AC3_MAX_CHANNELS][256]; ///< bit allocation pointers + int16_t psd[AC3_MAX_CHANNELS][256]; ///< scaled exponents + int16_t band_psd[AC3_MAX_CHANNELS][50]; ///< interpolated exponents + int16_t mask[AC3_MAX_CHANNELS][50]; ///< masking curve values + + DECLARE_ALIGNED_16(float, transform_coeffs[AC3_MAX_CHANNELS][256]); ///< transform coefficients + + /* For IMDCT. */ + MDCTContext imdct_512; ///< for 512 sample IMDCT + MDCTContext imdct_256; ///< for 256 sample IMDCT + DSPContext dsp; ///< for optimization + float add_bias; ///< offset for float_to_int16 conversion + float mul_bias; ///< scaling for float_to_int16 conversion + + DECLARE_ALIGNED_16(float, output[AC3_MAX_CHANNELS-1][256]); ///< output after imdct transform and windowing + DECLARE_ALIGNED_16(short, int_output[AC3_MAX_CHANNELS-1][256]); ///< final 16-bit integer output + DECLARE_ALIGNED_16(float, delay[AC3_MAX_CHANNELS-1][256]); ///< delay - added to the next block + DECLARE_ALIGNED_16(float, tmp_imdct[256]); ///< temporary storage for imdct transform + DECLARE_ALIGNED_16(float, tmp_output[512]); ///< temporary storage for output before windowing + DECLARE_ALIGNED_16(float, window[256]); ///< window coefficients + + /* Miscellaneous. */ + GetBitContext gbc; ///< bitstream reader + AVRandomState dith_state; ///< for dither generation + AVCodecContext *avctx; ///< parent context +} AC3DecodeContext; + +/** + * Symmetrical Dequantization + * reference: Section 7.3.3 Expansion of Mantissas for Symmetrical Quantization + * Tables 7.19 to 7.23 + */ +static inline float +symmetric_dequant(int code, int levels) +{ + return (code - (levels >> 1)) * (2.0f / levels); +} + +/* + * Initialize tables at runtime. + */ +static void ac3_tables_init(void) +{ + int i; + + /* generate grouped mantissa tables + reference: Section 7.3.5 Ungrouping of Mantissas */ + for(i=0; i<32; i++) { + /* bap=1 mantissas */ + b1_mantissas[i][0] = symmetric_dequant( i / 9 , 3); + b1_mantissas[i][1] = symmetric_dequant((i % 9) / 3, 3); + b1_mantissas[i][2] = symmetric_dequant((i % 9) % 3, 3); + } + for(i=0; i<128; i++) { + /* bap=2 mantissas */ + b2_mantissas[i][0] = symmetric_dequant( i / 25 , 5); + b2_mantissas[i][1] = symmetric_dequant((i % 25) / 5, 5); + b2_mantissas[i][2] = symmetric_dequant((i % 25) % 5, 5); + + /* bap=4 mantissas */ + b4_mantissas[i][0] = symmetric_dequant(i / 11, 11); + b4_mantissas[i][1] = symmetric_dequant(i % 11, 11); + } + /* generate ungrouped mantissa tables + reference: Tables 7.21 and 7.23 */ + for(i=0; i<7; i++) { + /* bap=3 mantissas */ + b3_mantissas[i] = symmetric_dequant(i, 7); + } + for(i=0; i<15; i++) { + /* bap=5 mantissas */ + b5_mantissas[i] = symmetric_dequant(i, 15); + } + + /* generate dynamic range table + reference: Section 7.7.1 Dynamic Range Control */ + for(i=0; i<256; i++) { + int v = (i >> 5) - ((i >> 7) << 3) - 5; + dynamic_range_tab[i] = powf(2.0f, v) * ((i & 0x1F) | 0x20); + } + + /* generate scale factors for exponents and asymmetrical dequantization + reference: Section 7.3.2 Expansion of Mantissas for Asymmetric Quantization */ + for (i = 0; i < 25; i++) + scale_factors[i] = pow(2.0, -i); + + /* generate exponent tables + reference: Section 7.1.3 Exponent Decoding */ + for(i=0; i<128; i++) { + exp_ungroup_tab[i][0] = i / 25; + exp_ungroup_tab[i][1] = (i % 25) / 5; + exp_ungroup_tab[i][2] = (i % 25) % 5; + } +} + + +/** + * AVCodec initialization + */ +static int ac3_decode_init(AVCodecContext *avctx) +{ + AC3DecodeContext *s = avctx->priv_data; + s->avctx = avctx; + + ac3_common_init(); + ac3_tables_init(); + ff_mdct_init(&s->imdct_256, 8, 1); + ff_mdct_init(&s->imdct_512, 9, 1); + ff_kbd_window_init(s->window, 5.0, 256); + dsputil_init(&s->dsp, avctx); + av_init_random(0, &s->dith_state); + + /* set bias values for float to int16 conversion */ + if(s->dsp.float_to_int16 == ff_float_to_int16_c) { + s->add_bias = 385.0f; + s->mul_bias = 1.0f; + } else { + s->add_bias = 0.0f; + s->mul_bias = 32767.0f; + } + + /* allow downmixing to stereo or mono */ + if (avctx->channels > 0 && avctx->request_channels > 0 && + avctx->request_channels < avctx->channels && + avctx->request_channels <= 2) { + avctx->channels = avctx->request_channels; + } + + return 0; +} + +/** + * Parse the 'sync info' and 'bit stream info' from the AC-3 bitstream. + * GetBitContext within AC3DecodeContext must point to + * start of the synchronized ac3 bitstream. + */ +static int ac3_parse_header(AC3DecodeContext *s) +{ + AC3HeaderInfo hdr; + GetBitContext *gbc = &s->gbc; + int err, i; + + err = ff_ac3_parse_header(gbc->buffer, &hdr); + if(err) + return err; + + if(hdr.bitstream_id > 10) + return AC3_PARSE_ERROR_BSID; + + /* get decoding parameters from header info */ + s->bit_alloc_params.sr_code = hdr.sr_code; + s->channel_mode = hdr.channel_mode; + s->lfe_on = hdr.lfe_on; + s->bit_alloc_params.sr_shift = hdr.sr_shift; + s->sample_rate = hdr.sample_rate; + s->bit_rate = hdr.bit_rate; + s->channels = hdr.channels; + s->fbw_channels = s->channels - s->lfe_on; + s->lfe_ch = s->fbw_channels + 1; + s->frame_size = hdr.frame_size; + + /* set default output to all source channels */ + s->out_channels = s->channels; + s->output_mode = s->channel_mode; + if(s->lfe_on) + s->output_mode |= AC3_OUTPUT_LFEON; + + /* set default mix levels */ + s->center_mix_level = 3; // -4.5dB + s->surround_mix_level = 4; // -6.0dB + + /* skip over portion of header which has already been read */ + skip_bits(gbc, 16); // skip the sync_word + skip_bits(gbc, 16); // skip crc1 + skip_bits(gbc, 8); // skip fscod and frmsizecod + skip_bits(gbc, 11); // skip bsid, bsmod, and acmod + if(s->channel_mode == AC3_CHMODE_STEREO) { + skip_bits(gbc, 2); // skip dsurmod + } else { + if((s->channel_mode & 1) && s->channel_mode != AC3_CHMODE_MONO) + s->center_mix_level = center_levels[get_bits(gbc, 2)]; + if(s->channel_mode & 4) + s->surround_mix_level = surround_levels[get_bits(gbc, 2)]; + } + skip_bits1(gbc); // skip lfeon + + /* read the rest of the bsi. read twice for dual mono mode. */ + i = !(s->channel_mode); + do { + skip_bits(gbc, 5); // skip dialog normalization + if (get_bits1(gbc)) + skip_bits(gbc, 8); //skip compression + if (get_bits1(gbc)) + skip_bits(gbc, 8); //skip language code + if (get_bits1(gbc)) + skip_bits(gbc, 7); //skip audio production information + } while (i--); + + skip_bits(gbc, 2); //skip copyright bit and original bitstream bit + + /* skip the timecodes (or extra bitstream information for Alternate Syntax) + TODO: read & use the xbsi1 downmix levels */ + if (get_bits1(gbc)) + skip_bits(gbc, 14); //skip timecode1 / xbsi1 + if (get_bits1(gbc)) + skip_bits(gbc, 14); //skip timecode2 / xbsi2 + + /* skip additional bitstream info */ + if (get_bits1(gbc)) { + i = get_bits(gbc, 6); + do { + skip_bits(gbc, 8); + } while(i--); + } + + return 0; +} + +/** + * Set stereo downmixing coefficients based on frame header info. + * reference: Section 7.8.2 Downmixing Into Two Channels + */ +static void set_downmix_coeffs(AC3DecodeContext *s) +{ + int i; + float cmix = gain_levels[s->center_mix_level]; + float smix = gain_levels[s->surround_mix_level]; + + for(i=0; ifbw_channels; i++) { + s->downmix_coeffs[i][0] = gain_levels[ac3_default_coeffs[s->channel_mode][i][0]]; + s->downmix_coeffs[i][1] = gain_levels[ac3_default_coeffs[s->channel_mode][i][1]]; + } + if(s->channel_mode > 1 && s->channel_mode & 1) { + s->downmix_coeffs[1][0] = s->downmix_coeffs[1][1] = cmix; + } + if(s->channel_mode == AC3_CHMODE_2F1R || s->channel_mode == AC3_CHMODE_3F1R) { + int nf = s->channel_mode - 2; + s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf][1] = smix * LEVEL_MINUS_3DB; + } + if(s->channel_mode == AC3_CHMODE_2F2R || s->channel_mode == AC3_CHMODE_3F2R) { + int nf = s->channel_mode - 4; + s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf+1][1] = smix; + } +} + +/** + * Decode the grouped exponents according to exponent strategy. + * reference: Section 7.1.3 Exponent Decoding + */ +static void decode_exponents(GetBitContext *gbc, int exp_strategy, int ngrps, + uint8_t absexp, int8_t *dexps) +{ + int i, j, grp, group_size; + int dexp[256]; + int expacc, prevexp; + + /* unpack groups */ + group_size = exp_strategy + (exp_strategy == EXP_D45); + for(grp=0,i=0; grpstart_freq[CPL_CH]; + for(bnd=0; bndnum_cpl_bands; bnd++) { + do { + subbnd++; + for(j=0; j<12; j++) { + for(ch=1; ch<=s->fbw_channels; ch++) { + if(s->channel_in_cpl[ch]) { + s->transform_coeffs[ch][i] = s->transform_coeffs[CPL_CH][i] * s->cpl_coords[ch][bnd] * 8.0f; + if (ch == 2 && s->phase_flags[bnd]) + s->transform_coeffs[ch][i] = -s->transform_coeffs[ch][i]; + } + } + i++; + } + } while(s->cpl_band_struct[subbnd]); + } +} + +/** + * Grouped mantissas for 3-level 5-level and 11-level quantization + */ +typedef struct { + float b1_mant[3]; + float b2_mant[3]; + float b4_mant[2]; + int b1ptr; + int b2ptr; + int b4ptr; +} mant_groups; + +/** + * Get the transform coefficients for a particular channel + * reference: Section 7.3 Quantization and Decoding of Mantissas + */ +static int get_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, mant_groups *m) +{ + GetBitContext *gbc = &s->gbc; + int i, gcode, tbap, start, end; + uint8_t *exps; + uint8_t *bap; + float *coeffs; + + exps = s->dexps[ch_index]; + bap = s->bap[ch_index]; + coeffs = s->transform_coeffs[ch_index]; + start = s->start_freq[ch_index]; + end = s->end_freq[ch_index]; + + for (i = start; i < end; i++) { + tbap = bap[i]; + switch (tbap) { + case 0: + coeffs[i] = ((av_random(&s->dith_state) & 0xFFFF) / 65535.0f) - 0.5f; + break; + + case 1: + if(m->b1ptr > 2) { + gcode = get_bits(gbc, 5); + m->b1_mant[0] = b1_mantissas[gcode][0]; + m->b1_mant[1] = b1_mantissas[gcode][1]; + m->b1_mant[2] = b1_mantissas[gcode][2]; + m->b1ptr = 0; + } + coeffs[i] = m->b1_mant[m->b1ptr++]; + break; + + case 2: + if(m->b2ptr > 2) { + gcode = get_bits(gbc, 7); + m->b2_mant[0] = b2_mantissas[gcode][0]; + m->b2_mant[1] = b2_mantissas[gcode][1]; + m->b2_mant[2] = b2_mantissas[gcode][2]; + m->b2ptr = 0; + } + coeffs[i] = m->b2_mant[m->b2ptr++]; + break; + + case 3: + coeffs[i] = b3_mantissas[get_bits(gbc, 3)]; + break; + + case 4: + if(m->b4ptr > 1) { + gcode = get_bits(gbc, 7); + m->b4_mant[0] = b4_mantissas[gcode][0]; + m->b4_mant[1] = b4_mantissas[gcode][1]; + m->b4ptr = 0; + } + coeffs[i] = m->b4_mant[m->b4ptr++]; + break; + + case 5: + coeffs[i] = b5_mantissas[get_bits(gbc, 4)]; + break; + + default: + /* asymmetric dequantization */ + coeffs[i] = get_sbits(gbc, quantization_tab[tbap]) * scale_factors[quantization_tab[tbap]-1]; + break; + } + coeffs[i] *= scale_factors[exps[i]]; + } + + return 0; +} + +/** + * Remove random dithering from coefficients with zero-bit mantissas + * reference: Section 7.3.4 Dither for Zero Bit Mantissas (bap=0) + */ +static void remove_dithering(AC3DecodeContext *s) { + int ch, i; + int end=0; + float *coeffs; + uint8_t *bap; + + for(ch=1; ch<=s->fbw_channels; ch++) { + if(!s->dither_flag[ch]) { + coeffs = s->transform_coeffs[ch]; + bap = s->bap[ch]; + if(s->channel_in_cpl[ch]) + end = s->start_freq[CPL_CH]; + else + end = s->end_freq[ch]; + for(i=0; ichannel_in_cpl[ch]) { + bap = s->bap[CPL_CH]; + for(; iend_freq[CPL_CH]; i++) { + if(!bap[i]) + coeffs[i] = 0.0f; + } + } + } + } +} + +/** + * Get the transform coefficients. + */ +static int get_transform_coeffs(AC3DecodeContext *s) +{ + int ch, end; + int got_cplchan = 0; + mant_groups m; + + m.b1ptr = m.b2ptr = m.b4ptr = 3; + + for (ch = 1; ch <= s->channels; ch++) { + /* transform coefficients for full-bandwidth channel */ + if (get_transform_coeffs_ch(s, ch, &m)) + return -1; + /* tranform coefficients for coupling channel come right after the + coefficients for the first coupled channel*/ + if (s->channel_in_cpl[ch]) { + if (!got_cplchan) { + if (get_transform_coeffs_ch(s, CPL_CH, &m)) { + av_log(s->avctx, AV_LOG_ERROR, "error in decoupling channels\n"); + return -1; + } + uncouple_channels(s); + got_cplchan = 1; + } + end = s->end_freq[CPL_CH]; + } else { + end = s->end_freq[ch]; + } + do + s->transform_coeffs[ch][end] = 0; + while(++end < 256); + } + + /* if any channel doesn't use dithering, zero appropriate coefficients */ + if(!s->dither_all) + remove_dithering(s); + + return 0; +} + +/** + * Stereo rematrixing. + * reference: Section 7.5.4 Rematrixing : Decoding Technique + */ +static void do_rematrixing(AC3DecodeContext *s) +{ + int bnd, i; + int end, bndend; + float tmp0, tmp1; + + end = FFMIN(s->end_freq[1], s->end_freq[2]); + + for(bnd=0; bndnum_rematrixing_bands; bnd++) { + if(s->rematrixing_flags[bnd]) { + bndend = FFMIN(end, rematrix_band_tab[bnd+1]); + for(i=rematrix_band_tab[bnd]; itransform_coeffs[1][i]; + tmp1 = s->transform_coeffs[2][i]; + s->transform_coeffs[1][i] = tmp0 + tmp1; + s->transform_coeffs[2][i] = tmp0 - tmp1; + } + } + } +} + +/** + * Perform the 256-point IMDCT + */ +static void do_imdct_256(AC3DecodeContext *s, int chindex) +{ + int i, k; + DECLARE_ALIGNED_16(float, x[128]); + FFTComplex z[2][64]; + float *o_ptr = s->tmp_output; + + for(i=0; i<2; i++) { + /* de-interleave coefficients */ + for(k=0; k<128; k++) { + x[k] = s->transform_coeffs[chindex][2*k+i]; + } + + /* run standard IMDCT */ + s->imdct_256.fft.imdct_calc(&s->imdct_256, o_ptr, x, s->tmp_imdct); + + /* reverse the post-rotation & reordering from standard IMDCT */ + for(k=0; k<32; k++) { + z[i][32+k].re = -o_ptr[128+2*k]; + z[i][32+k].im = -o_ptr[2*k]; + z[i][31-k].re = o_ptr[2*k+1]; + z[i][31-k].im = o_ptr[128+2*k+1]; + } + } + + /* apply AC-3 post-rotation & reordering */ + for(k=0; k<64; k++) { + o_ptr[ 2*k ] = -z[0][ k].im; + o_ptr[ 2*k+1] = z[0][63-k].re; + o_ptr[128+2*k ] = -z[0][ k].re; + o_ptr[128+2*k+1] = z[0][63-k].im; + o_ptr[256+2*k ] = -z[1][ k].re; + o_ptr[256+2*k+1] = z[1][63-k].im; + o_ptr[384+2*k ] = z[1][ k].im; + o_ptr[384+2*k+1] = -z[1][63-k].re; + } +} + +/** + * Inverse MDCT Transform. + * Convert frequency domain coefficients to time-domain audio samples. + * reference: Section 7.9.4 Transformation Equations + */ +static inline void do_imdct(AC3DecodeContext *s) +{ + int ch; + int channels; + + /* Don't perform the IMDCT on the LFE channel unless it's used in the output */ + channels = s->fbw_channels; + if(s->output_mode & AC3_OUTPUT_LFEON) + channels++; + + for (ch=1; ch<=channels; ch++) { + if (s->block_switch[ch]) { + do_imdct_256(s, ch); + } else { + s->imdct_512.fft.imdct_calc(&s->imdct_512, s->tmp_output, + s->transform_coeffs[ch], s->tmp_imdct); + } + /* For the first half of the block, apply the window, add the delay + from the previous block, and send to output */ + s->dsp.vector_fmul_add_add(s->output[ch-1], s->tmp_output, + s->window, s->delay[ch-1], 0, 256, 1); + /* For the second half of the block, apply the window and store the + samples to delay, to be combined with the next block */ + s->dsp.vector_fmul_reverse(s->delay[ch-1], s->tmp_output+256, + s->window, 256); + } +} + +/** + * Downmix the output to mono or stereo. + */ +static void ac3_downmix(AC3DecodeContext *s) +{ + int i, j; + float v0, v1, s0, s1; + + for(i=0; i<256; i++) { + v0 = v1 = s0 = s1 = 0.0f; + for(j=0; jfbw_channels; j++) { + v0 += s->output[j][i] * s->downmix_coeffs[j][0]; + v1 += s->output[j][i] * s->downmix_coeffs[j][1]; + s0 += s->downmix_coeffs[j][0]; + s1 += s->downmix_coeffs[j][1]; + } + v0 /= s0; + v1 /= s1; + if(s->output_mode == AC3_CHMODE_MONO) { + s->output[0][i] = (v0 + v1) * LEVEL_MINUS_3DB; + } else if(s->output_mode == AC3_CHMODE_STEREO) { + s->output[0][i] = v0; + s->output[1][i] = v1; + } + } +} + +/** + * Parse an audio block from AC-3 bitstream. + */ +static int ac3_parse_audio_block(AC3DecodeContext *s, int blk) +{ + int fbw_channels = s->fbw_channels; + int channel_mode = s->channel_mode; + int i, bnd, seg, ch; + GetBitContext *gbc = &s->gbc; + uint8_t bit_alloc_stages[AC3_MAX_CHANNELS]; + + memset(bit_alloc_stages, 0, AC3_MAX_CHANNELS); + + /* block switch flags */ + for (ch = 1; ch <= fbw_channels; ch++) + s->block_switch[ch] = get_bits1(gbc); + + /* dithering flags */ + s->dither_all = 1; + for (ch = 1; ch <= fbw_channels; ch++) { + s->dither_flag[ch] = get_bits1(gbc); + if(!s->dither_flag[ch]) + s->dither_all = 0; + } + + /* dynamic range */ + i = !(s->channel_mode); + do { + if(get_bits1(gbc)) { + s->dynamic_range[i] = ((dynamic_range_tab[get_bits(gbc, 8)]-1.0) * + s->avctx->drc_scale)+1.0; + } else if(blk == 0) { + s->dynamic_range[i] = 1.0f; + } + } while(i--); + + /* coupling strategy */ + if (get_bits1(gbc)) { + memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); + s->cpl_in_use = get_bits1(gbc); + if (s->cpl_in_use) { + /* coupling in use */ + int cpl_begin_freq, cpl_end_freq; + + /* determine which channels are coupled */ + for (ch = 1; ch <= fbw_channels; ch++) + s->channel_in_cpl[ch] = get_bits1(gbc); + + /* phase flags in use */ + if (channel_mode == AC3_CHMODE_STEREO) + s->phase_flags_in_use = get_bits1(gbc); + + /* coupling frequency range and band structure */ + cpl_begin_freq = get_bits(gbc, 4); + cpl_end_freq = get_bits(gbc, 4); + if (3 + cpl_end_freq - cpl_begin_freq < 0) { + av_log(s->avctx, AV_LOG_ERROR, "3+cplendf = %d < cplbegf = %d\n", 3+cpl_end_freq, cpl_begin_freq); + return -1; + } + s->num_cpl_bands = s->num_cpl_subbands = 3 + cpl_end_freq - cpl_begin_freq; + s->start_freq[CPL_CH] = cpl_begin_freq * 12 + 37; + s->end_freq[CPL_CH] = cpl_end_freq * 12 + 73; + for (bnd = 0; bnd < s->num_cpl_subbands - 1; bnd++) { + if (get_bits1(gbc)) { + s->cpl_band_struct[bnd] = 1; + s->num_cpl_bands--; + } + } + s->cpl_band_struct[s->num_cpl_subbands-1] = 0; + } else { + /* coupling not in use */ + for (ch = 1; ch <= fbw_channels; ch++) + s->channel_in_cpl[ch] = 0; + } + } + + /* coupling coordinates */ + if (s->cpl_in_use) { + int cpl_coords_exist = 0; + + for (ch = 1; ch <= fbw_channels; ch++) { + if (s->channel_in_cpl[ch]) { + if (get_bits1(gbc)) { + int master_cpl_coord, cpl_coord_exp, cpl_coord_mant; + cpl_coords_exist = 1; + master_cpl_coord = 3 * get_bits(gbc, 2); + for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { + cpl_coord_exp = get_bits(gbc, 4); + cpl_coord_mant = get_bits(gbc, 4); + if (cpl_coord_exp == 15) + s->cpl_coords[ch][bnd] = cpl_coord_mant / 16.0f; + else + s->cpl_coords[ch][bnd] = (cpl_coord_mant + 16.0f) / 32.0f; + s->cpl_coords[ch][bnd] *= scale_factors[cpl_coord_exp + master_cpl_coord]; + } + } + } + } + /* phase flags */ + if (channel_mode == AC3_CHMODE_STEREO && cpl_coords_exist) { + for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { + s->phase_flags[bnd] = s->phase_flags_in_use? get_bits1(gbc) : 0; + } + } + } + + /* stereo rematrixing strategy and band structure */ + if (channel_mode == AC3_CHMODE_STEREO) { + if (get_bits1(gbc)) { + s->num_rematrixing_bands = 4; + if(s->cpl_in_use && s->start_freq[CPL_CH] <= 61) + s->num_rematrixing_bands -= 1 + (s->start_freq[CPL_CH] == 37); + for(bnd=0; bndnum_rematrixing_bands; bnd++) + s->rematrixing_flags[bnd] = get_bits1(gbc); + } + } + + /* exponent strategies for each channel */ + s->exp_strategy[CPL_CH] = EXP_REUSE; + s->exp_strategy[s->lfe_ch] = EXP_REUSE; + for (ch = !s->cpl_in_use; ch <= s->channels; ch++) { + if(ch == s->lfe_ch) + s->exp_strategy[ch] = get_bits(gbc, 1); + else + s->exp_strategy[ch] = get_bits(gbc, 2); + if(s->exp_strategy[ch] != EXP_REUSE) + bit_alloc_stages[ch] = 3; + } + + /* channel bandwidth */ + for (ch = 1; ch <= fbw_channels; ch++) { + s->start_freq[ch] = 0; + if (s->exp_strategy[ch] != EXP_REUSE) { + int prev = s->end_freq[ch]; + if (s->channel_in_cpl[ch]) + s->end_freq[ch] = s->start_freq[CPL_CH]; + else { + int bandwidth_code = get_bits(gbc, 6); + if (bandwidth_code > 60) { + av_log(s->avctx, AV_LOG_ERROR, "bandwidth code = %d > 60", bandwidth_code); + return -1; + } + s->end_freq[ch] = bandwidth_code * 3 + 73; + } + if(blk > 0 && s->end_freq[ch] != prev) + memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); + } + } + s->start_freq[s->lfe_ch] = 0; + s->end_freq[s->lfe_ch] = 7; + + /* decode exponents for each channel */ + for (ch = !s->cpl_in_use; ch <= s->channels; ch++) { + if (s->exp_strategy[ch] != EXP_REUSE) { + int group_size, num_groups; + group_size = 3 << (s->exp_strategy[ch] - 1); + if(ch == CPL_CH) + num_groups = (s->end_freq[ch] - s->start_freq[ch]) / group_size; + else if(ch == s->lfe_ch) + num_groups = 2; + else + num_groups = (s->end_freq[ch] + group_size - 4) / group_size; + s->dexps[ch][0] = get_bits(gbc, 4) << !ch; + decode_exponents(gbc, s->exp_strategy[ch], num_groups, s->dexps[ch][0], + &s->dexps[ch][s->start_freq[ch]+!!ch]); + if(ch != CPL_CH && ch != s->lfe_ch) + skip_bits(gbc, 2); /* skip gainrng */ + } + } + + /* bit allocation information */ + if (get_bits1(gbc)) { + s->bit_alloc_params.slow_decay = ff_ac3_slow_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift; + s->bit_alloc_params.fast_decay = ff_ac3_fast_decay_tab[get_bits(gbc, 2)] >> s->bit_alloc_params.sr_shift; + s->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab[get_bits(gbc, 2)]; + s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[get_bits(gbc, 2)]; + s->bit_alloc_params.floor = ff_ac3_floor_tab[get_bits(gbc, 3)]; + for(ch=!s->cpl_in_use; ch<=s->channels; ch++) { + bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); + } + } + + /* signal-to-noise ratio offsets and fast gains (signal-to-mask ratios) */ + if (get_bits1(gbc)) { + int csnr; + csnr = (get_bits(gbc, 6) - 15) << 4; + for (ch = !s->cpl_in_use; ch <= s->channels; ch++) { /* snr offset and fast gain */ + s->snr_offset[ch] = (csnr + get_bits(gbc, 4)) << 2; + s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)]; + } + memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); + } + + /* coupling leak information */ + if (s->cpl_in_use && get_bits1(gbc)) { + s->bit_alloc_params.cpl_fast_leak = get_bits(gbc, 3); + s->bit_alloc_params.cpl_slow_leak = get_bits(gbc, 3); + bit_alloc_stages[CPL_CH] = FFMAX(bit_alloc_stages[CPL_CH], 2); + } + + /* delta bit allocation information */ + if (get_bits1(gbc)) { + /* delta bit allocation exists (strategy) */ + for (ch = !s->cpl_in_use; ch <= fbw_channels; ch++) { + s->dba_mode[ch] = get_bits(gbc, 2); + if (s->dba_mode[ch] == DBA_RESERVED) { + av_log(s->avctx, AV_LOG_ERROR, "delta bit allocation strategy reserved\n"); + return -1; + } + bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); + } + /* channel delta offset, len and bit allocation */ + for (ch = !s->cpl_in_use; ch <= fbw_channels; ch++) { + if (s->dba_mode[ch] == DBA_NEW) { + s->dba_nsegs[ch] = get_bits(gbc, 3); + for (seg = 0; seg <= s->dba_nsegs[ch]; seg++) { + s->dba_offsets[ch][seg] = get_bits(gbc, 5); + s->dba_lengths[ch][seg] = get_bits(gbc, 4); + s->dba_values[ch][seg] = get_bits(gbc, 3); + } + } + } + } else if(blk == 0) { + for(ch=0; ch<=s->channels; ch++) { + s->dba_mode[ch] = DBA_NONE; + } + } + + /* Bit allocation */ + for(ch=!s->cpl_in_use; ch<=s->channels; ch++) { + if(bit_alloc_stages[ch] > 2) { + /* Exponent mapping into PSD and PSD integration */ + ff_ac3_bit_alloc_calc_psd(s->dexps[ch], + s->start_freq[ch], s->end_freq[ch], + s->psd[ch], s->band_psd[ch]); + } + if(bit_alloc_stages[ch] > 1) { + /* Compute excitation function, Compute masking curve, and + Apply delta bit allocation */ + ff_ac3_bit_alloc_calc_mask(&s->bit_alloc_params, s->band_psd[ch], + s->start_freq[ch], s->end_freq[ch], + s->fast_gain[ch], (ch == s->lfe_ch), + s->dba_mode[ch], s->dba_nsegs[ch], + s->dba_offsets[ch], s->dba_lengths[ch], + s->dba_values[ch], s->mask[ch]); + } + if(bit_alloc_stages[ch] > 0) { + /* Compute bit allocation */ + ff_ac3_bit_alloc_calc_bap(s->mask[ch], s->psd[ch], + s->start_freq[ch], s->end_freq[ch], + s->snr_offset[ch], + s->bit_alloc_params.floor, + s->bap[ch]); + } + } + + /* unused dummy data */ + if (get_bits1(gbc)) { + int skipl = get_bits(gbc, 9); + while(skipl--) + skip_bits(gbc, 8); + } + + /* unpack the transform coefficients + this also uncouples channels if coupling is in use. */ + if (get_transform_coeffs(s)) { + av_log(s->avctx, AV_LOG_ERROR, "Error in routine get_transform_coeffs\n"); + return -1; + } + + /* recover coefficients if rematrixing is in use */ + if(s->channel_mode == AC3_CHMODE_STEREO) + do_rematrixing(s); + + /* apply scaling to coefficients (headroom, dynrng) */ + for(ch=1; ch<=s->channels; ch++) { + float gain = 2.0f * s->mul_bias; + if(s->channel_mode == AC3_CHMODE_DUALMONO) { + gain *= s->dynamic_range[ch-1]; + } else { + gain *= s->dynamic_range[0]; + } + for(i=0; iend_freq[ch]; i++) { + s->transform_coeffs[ch][i] *= gain; + } + } + + do_imdct(s); + + /* downmix output if needed */ + if(s->channels != s->out_channels && !((s->output_mode & AC3_OUTPUT_LFEON) && + s->fbw_channels == s->out_channels)) { + ac3_downmix(s); + } + + /* convert float to 16-bit integer */ + for(ch=0; chout_channels; ch++) { + for(i=0; i<256; i++) { + s->output[ch][i] += s->add_bias; + } + s->dsp.float_to_int16(s->int_output[ch], s->output[ch], 256); + } + + return 0; +} + +/** + * Decode a single AC-3 frame. + */ +static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t *buf, int buf_size) +{ + AC3DecodeContext *s = avctx->priv_data; + int16_t *out_samples = (int16_t *)data; + int i, blk, ch, err; + + /* initialize the GetBitContext with the start of valid AC-3 Frame */ + init_get_bits(&s->gbc, buf, buf_size * 8); + + /* parse the syncinfo */ + err = ac3_parse_header(s); + if(err) { + switch(err) { + case AC3_PARSE_ERROR_SYNC: + av_log(avctx, AV_LOG_ERROR, "frame sync error\n"); + break; + case AC3_PARSE_ERROR_BSID: + av_log(avctx, AV_LOG_ERROR, "invalid bitstream id\n"); + break; + case AC3_PARSE_ERROR_SAMPLE_RATE: + av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n"); + break; + case AC3_PARSE_ERROR_FRAME_SIZE: + av_log(avctx, AV_LOG_ERROR, "invalid frame size\n"); + break; + default: + av_log(avctx, AV_LOG_ERROR, "invalid header\n"); + break; + } + return -1; + } + + /* check that reported frame size fits in input buffer */ + if(s->frame_size > buf_size) { + av_log(avctx, AV_LOG_ERROR, "incomplete frame\n"); + return -1; + } + + /* check for crc mismatch */ + if(avctx->error_resilience >= FF_ER_CAREFUL) { + if(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, &buf[2], s->frame_size-2)) { + av_log(avctx, AV_LOG_ERROR, "frame CRC mismatch\n"); + return -1; + } + /* TODO: error concealment */ + } + + avctx->sample_rate = s->sample_rate; + avctx->bit_rate = s->bit_rate; + + /* channel config */ + s->out_channels = s->channels; + if (avctx->request_channels > 0 && avctx->request_channels <= 2 && + avctx->request_channels < s->channels) { + s->out_channels = avctx->request_channels; + s->output_mode = avctx->request_channels == 1 ? AC3_CHMODE_MONO : AC3_CHMODE_STEREO; + } + avctx->channels = s->out_channels; + + /* set downmixing coefficients if needed */ + if(s->channels != s->out_channels && !((s->output_mode & AC3_OUTPUT_LFEON) && + s->fbw_channels == s->out_channels)) { + set_downmix_coeffs(s); + } + + /* parse the audio blocks */ + for (blk = 0; blk < NB_BLOCKS; blk++) { + if (ac3_parse_audio_block(s, blk)) { + av_log(avctx, AV_LOG_ERROR, "error parsing the audio block\n"); + *data_size = 0; + return s->frame_size; + } + for (i = 0; i < 256; i++) + for (ch = 0; ch < s->out_channels; ch++) + *(out_samples++) = s->int_output[ch][i]; + } + *data_size = NB_BLOCKS * 256 * avctx->channels * sizeof (int16_t); + return s->frame_size; +} + +/** + * Uninitialize the AC-3 decoder. + */ +static int ac3_decode_end(AVCodecContext *avctx) +{ + AC3DecodeContext *s = avctx->priv_data; + ff_mdct_end(&s->imdct_512); + ff_mdct_end(&s->imdct_256); + + return 0; +} + +AVCodec ac3_decoder = { + .name = "ac3", + .type = CODEC_TYPE_AUDIO, + .id = CODEC_ID_AC3, + .priv_data_size = sizeof (AC3DecodeContext), + .init = ac3_decode_init, + .close = ac3_decode_end, + .decode = ac3_decode_frame, +}; diff --git a/contrib/ffmpeg/libavcodec/ac3enc.c b/contrib/ffmpeg/libavcodec/ac3enc.c index 5161b61e4..1b95e8060 100644 --- a/contrib/ffmpeg/libavcodec/ac3enc.c +++ b/contrib/ffmpeg/libavcodec/ac3enc.c @@ -37,34 +37,33 @@ typedef struct AC3EncodeContext { int lfe_channel; int bit_rate; unsigned int sample_rate; - unsigned int bsid; + unsigned int bitstream_id; unsigned int frame_size_min; /* minimum frame size in case rounding is necessary */ unsigned int frame_size; /* current frame size in words */ unsigned int bits_written; unsigned int samples_written; - int halfratecod; - unsigned int frmsizecod; - unsigned int fscod; /* frequency */ - unsigned int acmod; + int sr_shift; + unsigned int frame_size_code; + unsigned int sr_code; /* frequency */ + unsigned int channel_mode; int lfe; - unsigned int bsmod; + unsigned int bitstream_mode; short last_samples[AC3_MAX_CHANNELS][256]; unsigned int chbwcod[AC3_MAX_CHANNELS]; int nb_coefs[AC3_MAX_CHANNELS]; /* bitrate allocation control */ - int sgaincod, sdecaycod, fdecaycod, dbkneecod, floorcod; + int slow_gain_code, slow_decay_code, fast_decay_code, db_per_bit_code, floor_code; AC3BitAllocParameters bit_alloc; - int csnroffst; - int fgaincod[AC3_MAX_CHANNELS]; - int fsnroffst[AC3_MAX_CHANNELS]; + int coarse_snr_offset; + int fast_gain_code[AC3_MAX_CHANNELS]; + int fine_snr_offset[AC3_MAX_CHANNELS]; /* mantissa encoding */ int mant1_cnt, mant2_cnt, mant4_cnt; } AC3EncodeContext; static int16_t costab[64]; static int16_t sintab[64]; -static int16_t fft_rev[512]; static int16_t xcos1[128]; static int16_t xsin1[128]; @@ -74,8 +73,6 @@ static int16_t xsin1[128]; /* new exponents are sent if their Norm 1 exceed this number */ #define EXP_DIFF_THRESHOLD 1000 -static void fft_init(int ln); - static inline int16_t fix15(float a) { int v; @@ -93,7 +90,7 @@ typedef struct IComplex { static void fft_init(int ln) { - int i, j, m, n; + int i, n; float alpha; n = 1 << ln; @@ -103,14 +100,6 @@ static void fft_init(int ln) costab[i] = fix15(cos(alpha)); sintab[i] = fix15(sin(alpha)); } - - for(i=0;i> j) & 1) << (ln-j-1); - } - fft_rev[i]=m; - } } /* butter fly op */ @@ -148,14 +137,9 @@ static void fft(IComplex *z, int ln) /* reverse */ for(j=0;j> (8 - ln); + if (k < j) + FFSWAP(IComplex, z[k], z[j]); } /* pass 0 */ @@ -438,7 +422,7 @@ static void bit_alloc_masking(AC3EncodeContext *s, int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50]) { int blk, ch; - int16_t bndpsd[NB_BLOCKS][AC3_MAX_CHANNELS][50]; + int16_t band_psd[NB_BLOCKS][AC3_MAX_CHANNELS][50]; for(blk=0; blknb_all_channels;ch++) { @@ -448,12 +432,12 @@ static void bit_alloc_masking(AC3EncodeContext *s, } else { ff_ac3_bit_alloc_calc_psd(encoded_exp[blk][ch], 0, s->nb_coefs[ch], - psd[blk][ch], bndpsd[blk][ch]); - ff_ac3_bit_alloc_calc_mask(&s->bit_alloc, bndpsd[blk][ch], + psd[blk][ch], band_psd[blk][ch]); + ff_ac3_bit_alloc_calc_mask(&s->bit_alloc, band_psd[blk][ch], 0, s->nb_coefs[ch], - ff_fgaintab[s->fgaincod[ch]], + ff_ac3_fast_gain_tab[s->fast_gain_code[ch]], ch == s->lfe_channel, - 2, 0, NULL, NULL, NULL, + DBA_NONE, 0, NULL, NULL, NULL, mask[blk][ch]); } } @@ -464,12 +448,12 @@ static int bit_alloc(AC3EncodeContext *s, int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50], int16_t psd[NB_BLOCKS][AC3_MAX_CHANNELS][N/2], uint8_t bap[NB_BLOCKS][AC3_MAX_CHANNELS][N/2], - int frame_bits, int csnroffst, int fsnroffst) + int frame_bits, int coarse_snr_offset, int fine_snr_offset) { int i, ch; - int snroffset; + int snr_offset; - snroffset = (((csnroffst - 15) << 4) + fsnroffst) << 2; + snr_offset = (((coarse_snr_offset - 15) << 4) + fine_snr_offset) << 2; /* compute size */ for(i=0;imant4_cnt = 0; for(ch=0;chnb_all_channels;ch++) { ff_ac3_bit_alloc_calc_bap(mask[i][ch], psd[i][ch], 0, - s->nb_coefs[ch], snroffset, + s->nb_coefs[ch], snr_offset, s->bit_alloc.floor, bap[i][ch]); frame_bits += compute_mantissa_size(s, bap[i][ch], s->nb_coefs[ch]); @@ -486,7 +470,7 @@ static int bit_alloc(AC3EncodeContext *s, } #if 0 printf("csnr=%d fsnr=%d frame_bits=%d diff=%d\n", - csnroffst, fsnroffst, frame_bits, + coarse_snr_offset, fine_snr_offset, frame_bits, 16 * s->frame_size - ((frame_bits + 7) & ~7)); #endif return 16 * s->frame_size - frame_bits; @@ -501,40 +485,40 @@ static int compute_bit_allocation(AC3EncodeContext *s, int frame_bits) { int i, ch; - int csnroffst, fsnroffst; + int coarse_snr_offset, fine_snr_offset; uint8_t bap1[NB_BLOCKS][AC3_MAX_CHANNELS][N/2]; int16_t psd[NB_BLOCKS][AC3_MAX_CHANNELS][N/2]; int16_t mask[NB_BLOCKS][AC3_MAX_CHANNELS][50]; static int frame_bits_inc[8] = { 0, 0, 2, 2, 2, 4, 2, 4 }; /* init default parameters */ - s->sdecaycod = 2; - s->fdecaycod = 1; - s->sgaincod = 1; - s->dbkneecod = 2; - s->floorcod = 4; + s->slow_decay_code = 2; + s->fast_decay_code = 1; + s->slow_gain_code = 1; + s->db_per_bit_code = 2; + s->floor_code = 4; for(ch=0;chnb_all_channels;ch++) - s->fgaincod[ch] = 4; + s->fast_gain_code[ch] = 4; /* compute real values */ - s->bit_alloc.fscod = s->fscod; - s->bit_alloc.halfratecod = s->halfratecod; - s->bit_alloc.sdecay = ff_sdecaytab[s->sdecaycod] >> s->halfratecod; - s->bit_alloc.fdecay = ff_fdecaytab[s->fdecaycod] >> s->halfratecod; - s->bit_alloc.sgain = ff_sgaintab[s->sgaincod]; - s->bit_alloc.dbknee = ff_dbkneetab[s->dbkneecod]; - s->bit_alloc.floor = ff_floortab[s->floorcod]; + s->bit_alloc.sr_code = s->sr_code; + s->bit_alloc.sr_shift = s->sr_shift; + s->bit_alloc.slow_decay = ff_ac3_slow_decay_tab[s->slow_decay_code] >> s->sr_shift; + s->bit_alloc.fast_decay = ff_ac3_fast_decay_tab[s->fast_decay_code] >> s->sr_shift; + s->bit_alloc.slow_gain = ff_ac3_slow_gain_tab[s->slow_gain_code]; + s->bit_alloc.db_per_bit = ff_ac3_db_per_bit_tab[s->db_per_bit_code]; + s->bit_alloc.floor = ff_ac3_floor_tab[s->floor_code]; /* header size */ frame_bits += 65; - // if (s->acmod == 2) + // if (s->channel_mode == 2) // frame_bits += 2; - frame_bits += frame_bits_inc[s->acmod]; + frame_bits += frame_bits_inc[s->channel_mode]; /* audio blocks */ for(i=0;inb_channels * 2 + 2; /* blksw * c, dithflag * c, dynrnge, cplstre */ - if (s->acmod == 2) { + if (s->channel_mode == AC3_CHMODE_STEREO) { frame_bits++; /* rematstr */ if(i==0) frame_bits += 4; } @@ -568,43 +552,43 @@ static int compute_bit_allocation(AC3EncodeContext *s, /* now the big work begins : do the bit allocation. Modify the snr offset until we can pack everything in the requested frame size */ - csnroffst = s->csnroffst; - while (csnroffst >= 0 && - bit_alloc(s, mask, psd, bap, frame_bits, csnroffst, 0) < 0) - csnroffst -= SNR_INC1; - if (csnroffst < 0) { - av_log(NULL, AV_LOG_ERROR, "Bit allocation failed, try increasing the bitrate, -ab 384 for example!\n"); + coarse_snr_offset = s->coarse_snr_offset; + while (coarse_snr_offset >= 0 && + bit_alloc(s, mask, psd, bap, frame_bits, coarse_snr_offset, 0) < 0) + coarse_snr_offset -= SNR_INC1; + if (coarse_snr_offset < 0) { + av_log(NULL, AV_LOG_ERROR, "Bit allocation failed. Try increasing the bitrate.\n"); return -1; } - while ((csnroffst + SNR_INC1) <= 63 && + while ((coarse_snr_offset + SNR_INC1) <= 63 && bit_alloc(s, mask, psd, bap1, frame_bits, - csnroffst + SNR_INC1, 0) >= 0) { - csnroffst += SNR_INC1; + coarse_snr_offset + SNR_INC1, 0) >= 0) { + coarse_snr_offset += SNR_INC1; memcpy(bap, bap1, sizeof(bap1)); } - while ((csnroffst + 1) <= 63 && - bit_alloc(s, mask, psd, bap1, frame_bits, csnroffst + 1, 0) >= 0) { - csnroffst++; + while ((coarse_snr_offset + 1) <= 63 && + bit_alloc(s, mask, psd, bap1, frame_bits, coarse_snr_offset + 1, 0) >= 0) { + coarse_snr_offset++; memcpy(bap, bap1, sizeof(bap1)); } - fsnroffst = 0; - while ((fsnroffst + SNR_INC1) <= 15 && + fine_snr_offset = 0; + while ((fine_snr_offset + SNR_INC1) <= 15 && bit_alloc(s, mask, psd, bap1, frame_bits, - csnroffst, fsnroffst + SNR_INC1) >= 0) { - fsnroffst += SNR_INC1; + coarse_snr_offset, fine_snr_offset + SNR_INC1) >= 0) { + fine_snr_offset += SNR_INC1; memcpy(bap, bap1, sizeof(bap1)); } - while ((fsnroffst + 1) <= 15 && + while ((fine_snr_offset + 1) <= 15 && bit_alloc(s, mask, psd, bap1, frame_bits, - csnroffst, fsnroffst + 1) >= 0) { - fsnroffst++; + coarse_snr_offset, fine_snr_offset + 1) >= 0) { + fine_snr_offset++; memcpy(bap, bap1, sizeof(bap1)); } - s->csnroffst = csnroffst; + s->coarse_snr_offset = coarse_snr_offset; for(ch=0;chnb_all_channels;ch++) - s->fsnroffst[ch] = fsnroffst; + s->fine_snr_offset[ch] = fine_snr_offset; #if defined(DEBUG_BITALLOC) { int j; @@ -632,7 +616,8 @@ static int AC3_encode_init(AVCodecContext *avctx) AC3EncodeContext *s = avctx->priv_data; int i, j, ch; float alpha; - static const uint8_t acmod_defs[6] = { + int bw_code; + static const uint8_t channel_mode_defs[6] = { 0x01, /* C */ 0x02, /* L R */ 0x03, /* L C R */ @@ -648,7 +633,7 @@ static int AC3_encode_init(AVCodecContext *avctx) /* number of channels */ if (channels < 1 || channels > 6) return -1; - s->acmod = acmod_defs[channels - 1]; + s->channel_mode = channel_mode_defs[channels - 1]; s->lfe = (channels == 6) ? 1 : 0; s->nb_all_channels = channels; s->nb_channels = channels > 5 ? 5 : channels; @@ -657,45 +642,53 @@ static int AC3_encode_init(AVCodecContext *avctx) /* frequency */ for(i=0;i<3;i++) { for(j=0;j<3;j++) - if ((ff_ac3_freqs[j] >> i) == freq) + if ((ff_ac3_sample_rate_tab[j] >> i) == freq) goto found; } return -1; found: s->sample_rate = freq; - s->halfratecod = i; - s->fscod = j; - s->bsid = 8 + s->halfratecod; - s->bsmod = 0; /* complete main audio service */ + s->sr_shift = i; + s->sr_code = j; + s->bitstream_id = 8 + s->sr_shift; + s->bitstream_mode = 0; /* complete main audio service */ /* bitrate & frame size */ - bitrate /= 1000; for(i=0;i<19;i++) { - if ((ff_ac3_bitratetab[i] >> s->halfratecod) == bitrate) + if ((ff_ac3_bitrate_tab[i] >> s->sr_shift)*1000 == bitrate) break; } if (i == 19) return -1; s->bit_rate = bitrate; - s->frmsizecod = i << 1; - s->frame_size_min = ff_ac3_frame_sizes[s->frmsizecod][s->fscod]; + s->frame_size_code = i << 1; + s->frame_size_min = ff_ac3_frame_size_tab[s->frame_size_code][s->sr_code]; s->bits_written = 0; s->samples_written = 0; s->frame_size = s->frame_size_min; /* bit allocation init */ - for(ch=0;chnb_channels;ch++) { - /* bandwidth for each channel */ + if(avctx->cutoff) { + /* calculate bandwidth based on user-specified cutoff frequency */ + int cutoff = av_clip(avctx->cutoff, 1, s->sample_rate >> 1); + int fbw_coeffs = cutoff * 512 / s->sample_rate; + bw_code = av_clip((fbw_coeffs - 73) / 3, 0, 60); + } else { + /* use default bandwidth setting */ /* XXX: should compute the bandwidth according to the frame size, so that we avoid anoying high freq artefacts */ - s->chbwcod[ch] = 50; /* sample bandwidth as mpeg audio layer 2 table 0 */ - s->nb_coefs[ch] = ((s->chbwcod[ch] + 12) * 3) + 37; + bw_code = 50; + } + for(ch=0;chnb_channels;ch++) { + /* bandwidth for each channel */ + s->chbwcod[ch] = bw_code; + s->nb_coefs[ch] = bw_code * 3 + 73; } if (s->lfe) { s->nb_coefs[s->lfe_channel] = 7; /* fixed */ } /* initial snr offset */ - s->csnroffst = 40; + s->coarse_snr_offset = 40; /* mdct init */ fft_init(MDCT_NBITS - 2); @@ -718,16 +711,16 @@ static void output_frame_header(AC3EncodeContext *s, unsigned char *frame) put_bits(&s->pb, 16, 0x0b77); /* frame header */ put_bits(&s->pb, 16, 0); /* crc1: will be filled later */ - put_bits(&s->pb, 2, s->fscod); - put_bits(&s->pb, 6, s->frmsizecod + (s->frame_size - s->frame_size_min)); - put_bits(&s->pb, 5, s->bsid); - put_bits(&s->pb, 3, s->bsmod); - put_bits(&s->pb, 3, s->acmod); - if ((s->acmod & 0x01) && s->acmod != 0x01) + put_bits(&s->pb, 2, s->sr_code); + put_bits(&s->pb, 6, s->frame_size_code + (s->frame_size - s->frame_size_min)); + put_bits(&s->pb, 5, s->bitstream_id); + put_bits(&s->pb, 3, s->bitstream_mode); + put_bits(&s->pb, 3, s->channel_mode); + if ((s->channel_mode & 0x01) && s->channel_mode != AC3_CHMODE_MONO) put_bits(&s->pb, 2, 1); /* XXX -4.5 dB */ - if (s->acmod & 0x04) + if (s->channel_mode & 0x04) put_bits(&s->pb, 2, 1); /* XXX -6 dB */ - if (s->acmod == 0x02) + if (s->channel_mode == AC3_CHMODE_STEREO) put_bits(&s->pb, 2, 0); /* surround not indicated */ put_bits(&s->pb, 1, s->lfe); /* LFE */ put_bits(&s->pb, 5, 31); /* dialog norm: -31 db */ @@ -738,7 +731,7 @@ static void output_frame_header(AC3EncodeContext *s, unsigned char *frame) put_bits(&s->pb, 1, 1); /* original bitstream */ put_bits(&s->pb, 1, 0); /* no time code 1 */ put_bits(&s->pb, 1, 0); /* no time code 2 */ - put_bits(&s->pb, 1, 0); /* no addtional bit stream info */ + put_bits(&s->pb, 1, 0); /* no additional bit stream info */ } /* symetric quantization on 'levels' levels */ @@ -810,7 +803,7 @@ static void output_audio_block(AC3EncodeContext *s, put_bits(&s->pb, 1, 0); /* no new coupling strategy */ } - if (s->acmod == 2) + if (s->channel_mode == AC3_CHMODE_STEREO) { if(block_num==0) { @@ -900,20 +893,20 @@ static void output_audio_block(AC3EncodeContext *s, baie = (block_num == 0); put_bits(&s->pb, 1, baie); if (baie) { - put_bits(&s->pb, 2, s->sdecaycod); - put_bits(&s->pb, 2, s->fdecaycod); - put_bits(&s->pb, 2, s->sgaincod); - put_bits(&s->pb, 2, s->dbkneecod); - put_bits(&s->pb, 3, s->floorcod); + put_bits(&s->pb, 2, s->slow_decay_code); + put_bits(&s->pb, 2, s->fast_decay_code); + put_bits(&s->pb, 2, s->slow_gain_code); + put_bits(&s->pb, 2, s->db_per_bit_code); + put_bits(&s->pb, 3, s->floor_code); } /* snr offset */ put_bits(&s->pb, 1, baie); /* always present with bai */ if (baie) { - put_bits(&s->pb, 6, s->csnroffst); + put_bits(&s->pb, 6, s->coarse_snr_offset); for(ch=0;chnb_all_channels;ch++) { - put_bits(&s->pb, 4, s->fsnroffst[ch]); - put_bits(&s->pb, 3, s->fgaincod[ch]); + put_bits(&s->pb, 4, s->fine_snr_offset[ch]); + put_bits(&s->pb, 3, s->fast_gain_code[ch]); } } @@ -1132,16 +1125,17 @@ static int output_frame_end(AC3EncodeContext *s) /* Now we must compute both crcs : this is not so easy for crc1 because it is at the beginning of the data... */ frame_size_58 = (frame_size >> 1) + (frame_size >> 3); - crc1 = bswap_16(av_crc(av_crc8005, 0, frame + 4, 2 * frame_size_58 - 4)); + crc1 = bswap_16(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, + frame + 4, 2 * frame_size_58 - 4)); /* XXX: could precompute crc_inv */ crc_inv = pow_poly((CRC16_POLY >> 1), (16 * frame_size_58) - 16, CRC16_POLY); crc1 = mul_poly(crc_inv, crc1, CRC16_POLY); - frame[2] = crc1 >> 8; - frame[3] = crc1; + AV_WB16(frame+2,crc1); - crc2 = bswap_16(av_crc(av_crc8005, 0, frame + 2 * frame_size_58, (frame_size - frame_size_58) * 2 - 2)); - frame[2*frame_size - 2] = crc2 >> 8; - frame[2*frame_size - 1] = crc2; + crc2 = bswap_16(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, + frame + 2 * frame_size_58, + (frame_size - frame_size_58) * 2 - 2)); + AV_WB16(frame+2*frame_size-2,crc2); // printf("n=%d frame_size=%d\n", n, frame_size); return frame_size * 2; @@ -1242,11 +1236,11 @@ static int AC3_encode_frame(AVCodecContext *avctx, } /* adjust for fractional frame sizes */ - while(s->bits_written >= s->bit_rate*1000 && s->samples_written >= s->sample_rate) { - s->bits_written -= s->bit_rate*1000; + while(s->bits_written >= s->bit_rate && s->samples_written >= s->sample_rate) { + s->bits_written -= s->bit_rate; s->samples_written -= s->sample_rate; } - s->frame_size = s->frame_size_min + (s->bits_written * s->sample_rate < s->samples_written * s->bit_rate*1000); + s->frame_size = s->frame_size_min + (s->bits_written * s->sample_rate < s->samples_written * s->bit_rate); s->bits_written += s->frame_size * 16; s->samples_written += AC3_FRAME_SIZE; @@ -1271,6 +1265,7 @@ static int AC3_encode_close(AVCodecContext *avctx) /*************************************************************************/ /* TEST */ +#undef random #define FN (N/4) void fft_test(void) diff --git a/contrib/ffmpeg/libavcodec/ac3tab.c b/contrib/ffmpeg/libavcodec/ac3tab.c new file mode 100644 index 000000000..c87200b1d --- /dev/null +++ b/contrib/ffmpeg/libavcodec/ac3tab.c @@ -0,0 +1,249 @@ +/* + * AC3 tables + * copyright (c) 2001 Fabrice Bellard + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file ac3tab.c + * tables taken directly from AC3 spec. + */ + +#include "ac3tab.h" + +/** + * Possible frame sizes. + * from ATSC A/52 Table 5.18 Frame Size Code Table. + */ +const uint16_t ff_ac3_frame_size_tab[38][3] = { + { 64, 69, 96 }, + { 64, 70, 96 }, + { 80, 87, 120 }, + { 80, 88, 120 }, + { 96, 104, 144 }, + { 96, 105, 144 }, + { 112, 121, 168 }, + { 112, 122, 168 }, + { 128, 139, 192 }, + { 128, 140, 192 }, + { 160, 174, 240 }, + { 160, 175, 240 }, + { 192, 208, 288 }, + { 192, 209, 288 }, + { 224, 243, 336 }, + { 224, 244, 336 }, + { 256, 278, 384 }, + { 256, 279, 384 }, + { 320, 348, 480 }, + { 320, 349, 480 }, + { 384, 417, 576 }, + { 384, 418, 576 }, + { 448, 487, 672 }, + { 448, 488, 672 }, + { 512, 557, 768 }, + { 512, 558, 768 }, + { 640, 696, 960 }, + { 640, 697, 960 }, + { 768, 835, 1152 }, + { 768, 836, 1152 }, + { 896, 975, 1344 }, + { 896, 976, 1344 }, + { 1024, 1114, 1536 }, + { 1024, 1115, 1536 }, + { 1152, 1253, 1728 }, + { 1152, 1254, 1728 }, + { 1280, 1393, 1920 }, + { 1280, 1394, 1920 }, +}; + +/** + * Maps audio coding mode (acmod) to number of full-bandwidth channels. + * from ATSC A/52 Table 5.8 Audio Coding Mode + */ +const uint8_t ff_ac3_channels_tab[8] = { + 2, 1, 2, 3, 3, 4, 4, 5 +}; + +/* possible frequencies */ +const uint16_t ff_ac3_sample_rate_tab[3] = { 48000, 44100, 32000 }; + +/* possible bitrates */ +const uint16_t ff_ac3_bitrate_tab[19] = { + 32, 40, 48, 56, 64, 80, 96, 112, 128, + 160, 192, 224, 256, 320, 384, 448, 512, 576, 640 +}; + +/* AC3 MDCT window */ + +/* MDCT window */ +const int16_t ff_ac3_window[256] = { + 4, 7, 12, 16, 21, 28, 34, 42, + 51, 61, 72, 84, 97, 111, 127, 145, + 164, 184, 207, 231, 257, 285, 315, 347, + 382, 419, 458, 500, 544, 591, 641, 694, + 750, 810, 872, 937, 1007, 1079, 1155, 1235, + 1318, 1406, 1497, 1593, 1692, 1796, 1903, 2016, + 2132, 2253, 2379, 2509, 2644, 2783, 2927, 3076, + 3230, 3389, 3552, 3721, 3894, 4072, 4255, 4444, + 4637, 4835, 5038, 5246, 5459, 5677, 5899, 6127, + 6359, 6596, 6837, 7083, 7334, 7589, 7848, 8112, + 8380, 8652, 8927, 9207, 9491, 9778,10069,10363, +10660,10960,11264,11570,11879,12190,12504,12820, +13138,13458,13780,14103,14427,14753,15079,15407, +15735,16063,16392,16720,17049,17377,17705,18032, +18358,18683,19007,19330,19651,19970,20287,20602, +20914,21225,21532,21837,22139,22438,22733,23025, +23314,23599,23880,24157,24430,24699,24964,25225, +25481,25732,25979,26221,26459,26691,26919,27142, +27359,27572,27780,27983,28180,28373,28560,28742, +28919,29091,29258,29420,29577,29729,29876,30018, +30155,30288,30415,30538,30657,30771,30880,30985, +31086,31182,31274,31363,31447,31528,31605,31678, +31747,31814,31877,31936,31993,32046,32097,32145, +32190,32232,32272,32310,32345,32378,32409,32438, +32465,32490,32513,32535,32556,32574,32592,32608, +32623,32636,32649,32661,32671,32681,32690,32698, +32705,32712,32718,32724,32729,32733,32737,32741, +32744,32747,32750,32752,32754,32756,32757,32759, +32760,32761,32762,32763,32764,32764,32765,32765, +32766,32766,32766,32766,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767, +32767,32767,32767,32767,32767,32767,32767,32767, +}; + +const uint8_t ff_ac3_log_add_tab[260]= { +0x40,0x3f,0x3e,0x3d,0x3c,0x3b,0x3a,0x39,0x38,0x37, +0x36,0x35,0x34,0x34,0x33,0x32,0x31,0x30,0x2f,0x2f, +0x2e,0x2d,0x2c,0x2c,0x2b,0x2a,0x29,0x29,0x28,0x27, +0x26,0x26,0x25,0x24,0x24,0x23,0x23,0x22,0x21,0x21, +0x20,0x20,0x1f,0x1e,0x1e,0x1d,0x1d,0x1c,0x1c,0x1b, +0x1b,0x1a,0x1a,0x19,0x19,0x18,0x18,0x17,0x17,0x16, +0x16,0x15,0x15,0x15,0x14,0x14,0x13,0x13,0x13,0x12, +0x12,0x12,0x11,0x11,0x11,0x10,0x10,0x10,0x0f,0x0f, +0x0f,0x0e,0x0e,0x0e,0x0d,0x0d,0x0d,0x0d,0x0c,0x0c, +0x0c,0x0c,0x0b,0x0b,0x0b,0x0b,0x0a,0x0a,0x0a,0x0a, +0x0a,0x09,0x09,0x09,0x09,0x09,0x08,0x08,0x08,0x08, +0x08,0x08,0x07,0x07,0x07,0x07,0x07,0x07,0x06,0x06, +0x06,0x06,0x06,0x06,0x06,0x06,0x05,0x05,0x05,0x05, +0x05,0x05,0x05,0x05,0x04,0x04,0x04,0x04,0x04,0x04, +0x04,0x04,0x04,0x04,0x04,0x03,0x03,0x03,0x03,0x03, +0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x02, +0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, +0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x01,0x01, +0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, +0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, +0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; + +const uint16_t ff_ac3_hearing_threshold_tab[50][3]= { +{ 0x04d0,0x04f0,0x0580 }, +{ 0x04d0,0x04f0,0x0580 }, +{ 0x0440,0x0460,0x04b0 }, +{ 0x0400,0x0410,0x0450 }, +{ 0x03e0,0x03e0,0x0420 }, +{ 0x03c0,0x03d0,0x03f0 }, +{ 0x03b0,0x03c0,0x03e0 }, +{ 0x03b0,0x03b0,0x03d0 }, +{ 0x03a0,0x03b0,0x03c0 }, +{ 0x03a0,0x03a0,0x03b0 }, +{ 0x03a0,0x03a0,0x03b0 }, +{ 0x03a0,0x03a0,0x03b0 }, +{ 0x03a0,0x03a0,0x03a0 }, +{ 0x0390,0x03a0,0x03a0 }, +{ 0x0390,0x0390,0x03a0 }, +{ 0x0390,0x0390,0x03a0 }, +{ 0x0380,0x0390,0x03a0 }, +{ 0x0380,0x0380,0x03a0 }, +{ 0x0370,0x0380,0x03a0 }, +{ 0x0370,0x0380,0x03a0 }, +{ 0x0360,0x0370,0x0390 }, +{ 0x0360,0x0370,0x0390 }, +{ 0x0350,0x0360,0x0390 }, +{ 0x0350,0x0360,0x0390 }, +{ 0x0340,0x0350,0x0380 }, +{ 0x0340,0x0350,0x0380 }, +{ 0x0330,0x0340,0x0380 }, +{ 0x0320,0x0340,0x0370 }, +{ 0x0310,0x0320,0x0360 }, +{ 0x0300,0x0310,0x0350 }, +{ 0x02f0,0x0300,0x0340 }, +{ 0x02f0,0x02f0,0x0330 }, +{ 0x02f0,0x02f0,0x0320 }, +{ 0x02f0,0x02f0,0x0310 }, +{ 0x0300,0x02f0,0x0300 }, +{ 0x0310,0x0300,0x02f0 }, +{ 0x0340,0x0320,0x02f0 }, +{ 0x0390,0x0350,0x02f0 }, +{ 0x03e0,0x0390,0x0300 }, +{ 0x0420,0x03e0,0x0310 }, +{ 0x0460,0x0420,0x0330 }, +{ 0x0490,0x0450,0x0350 }, +{ 0x04a0,0x04a0,0x03c0 }, +{ 0x0460,0x0490,0x0410 }, +{ 0x0440,0x0460,0x0470 }, +{ 0x0440,0x0440,0x04a0 }, +{ 0x0520,0x0480,0x0460 }, +{ 0x0800,0x0630,0x0440 }, +{ 0x0840,0x0840,0x0450 }, +{ 0x0840,0x0840,0x04e0 }, +}; + +const uint8_t ff_ac3_bap_tab[64]= { + 0, 1, 1, 1, 1, 1, 2, 2, 3, 3, + 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, + 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, + 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, + 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, + 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, + 15, 15, 15, 15, +}; + +const uint8_t ff_ac3_slow_decay_tab[4]={ + 0x0f, 0x11, 0x13, 0x15, +}; + +const uint8_t ff_ac3_fast_decay_tab[4]={ + 0x3f, 0x53, 0x67, 0x7b, +}; + +const uint16_t ff_ac3_slow_gain_tab[4]= { + 0x540, 0x4d8, 0x478, 0x410, +}; + +const uint16_t ff_ac3_db_per_bit_tab[4]= { + 0x000, 0x700, 0x900, 0xb00, +}; + +const int16_t ff_ac3_floor_tab[8]= { + 0x2f0, 0x2b0, 0x270, 0x230, 0x1f0, 0x170, 0x0f0, 0xf800, +}; + +const uint16_t ff_ac3_fast_gain_tab[8]= { + 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400, +}; + +const uint8_t ff_ac3_critical_band_size_tab[50]={ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, + 3, 6, 6, 6, 6, 6, 6, 12, 12, 12, 12, 24, 24, 24, 24, 24 +}; diff --git a/contrib/ffmpeg/libavcodec/ac3tab.h b/contrib/ffmpeg/libavcodec/ac3tab.h index b549c5ba9..deb32b420 100644 --- a/contrib/ffmpeg/libavcodec/ac3tab.h +++ b/contrib/ffmpeg/libavcodec/ac3tab.h @@ -1,6 +1,6 @@ /* * AC3 tables - * copyright (c) 2001 Fabrice Bellard + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard. * * This file is part of FFmpeg. * @@ -19,233 +19,25 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/** - * @file ac3tab.h - * tables taken directly from AC3 spec. - */ - -/** - * Possible frame sizes. - * from ATSC A/52 Table 5.18 Frame Size Code Table. - */ -const uint16_t ff_ac3_frame_sizes[38][3] = { - { 64, 69, 96 }, - { 64, 70, 96 }, - { 80, 87, 120 }, - { 80, 88, 120 }, - { 96, 104, 144 }, - { 96, 105, 144 }, - { 112, 121, 168 }, - { 112, 122, 168 }, - { 128, 139, 192 }, - { 128, 140, 192 }, - { 160, 174, 240 }, - { 160, 175, 240 }, - { 192, 208, 288 }, - { 192, 209, 288 }, - { 224, 243, 336 }, - { 224, 244, 336 }, - { 256, 278, 384 }, - { 256, 279, 384 }, - { 320, 348, 480 }, - { 320, 349, 480 }, - { 384, 417, 576 }, - { 384, 418, 576 }, - { 448, 487, 672 }, - { 448, 488, 672 }, - { 512, 557, 768 }, - { 512, 558, 768 }, - { 640, 696, 960 }, - { 640, 697, 960 }, - { 768, 835, 1152 }, - { 768, 836, 1152 }, - { 896, 975, 1344 }, - { 896, 976, 1344 }, - { 1024, 1114, 1536 }, - { 1024, 1115, 1536 }, - { 1152, 1253, 1728 }, - { 1152, 1254, 1728 }, - { 1280, 1393, 1920 }, - { 1280, 1394, 1920 }, -}; - -/** - * Maps audio coding mode (acmod) to number of full-bandwidth channels. - * from ATSC A/52 Table 5.8 Audio Coding Mode - */ -const uint8_t ff_ac3_channels[8] = { - 2, 1, 2, 3, 3, 4, 4, 5 -}; - -/* possible frequencies */ -const uint16_t ff_ac3_freqs[3] = { 48000, 44100, 32000 }; - -/* possible bitrates */ -const uint16_t ff_ac3_bitratetab[19] = { - 32, 40, 48, 56, 64, 80, 96, 112, 128, - 160, 192, 224, 256, 320, 384, 448, 512, 576, 640 -}; - -/* AC3 MDCT window */ - -/* MDCT window */ -const int16_t ff_ac3_window[256] = { - 4, 7, 12, 16, 21, 28, 34, 42, - 51, 61, 72, 84, 97, 111, 127, 145, - 164, 184, 207, 231, 257, 285, 315, 347, - 382, 419, 458, 500, 544, 591, 641, 694, - 750, 810, 872, 937, 1007, 1079, 1155, 1235, - 1318, 1406, 1497, 1593, 1692, 1796, 1903, 2016, - 2132, 2253, 2379, 2509, 2644, 2783, 2927, 3076, - 3230, 3389, 3552, 3721, 3894, 4072, 4255, 4444, - 4637, 4835, 5038, 5246, 5459, 5677, 5899, 6127, - 6359, 6596, 6837, 7083, 7334, 7589, 7848, 8112, - 8380, 8652, 8927, 9207, 9491, 9778,10069,10363, -10660,10960,11264,11570,11879,12190,12504,12820, -13138,13458,13780,14103,14427,14753,15079,15407, -15735,16063,16392,16720,17049,17377,17705,18032, -18358,18683,19007,19330,19651,19970,20287,20602, -20914,21225,21532,21837,22139,22438,22733,23025, -23314,23599,23880,24157,24430,24699,24964,25225, -25481,25732,25979,26221,26459,26691,26919,27142, -27359,27572,27780,27983,28180,28373,28560,28742, -28919,29091,29258,29420,29577,29729,29876,30018, -30155,30288,30415,30538,30657,30771,30880,30985, -31086,31182,31274,31363,31447,31528,31605,31678, -31747,31814,31877,31936,31993,32046,32097,32145, -32190,32232,32272,32310,32345,32378,32409,32438, -32465,32490,32513,32535,32556,32574,32592,32608, -32623,32636,32649,32661,32671,32681,32690,32698, -32705,32712,32718,32724,32729,32733,32737,32741, -32744,32747,32750,32752,32754,32756,32757,32759, -32760,32761,32762,32763,32764,32764,32765,32765, -32766,32766,32766,32766,32767,32767,32767,32767, -32767,32767,32767,32767,32767,32767,32767,32767, -32767,32767,32767,32767,32767,32767,32767,32767, -}; - -static uint8_t masktab[253]; - -static const uint8_t latab[260]= { -0x0040,0x003f,0x003e,0x003d,0x003c,0x003b,0x003a,0x0039,0x0038,0x0037, -0x0036,0x0035,0x0034,0x0034,0x0033,0x0032,0x0031,0x0030,0x002f,0x002f, -0x002e,0x002d,0x002c,0x002c,0x002b,0x002a,0x0029,0x0029,0x0028,0x0027, -0x0026,0x0026,0x0025,0x0024,0x0024,0x0023,0x0023,0x0022,0x0021,0x0021, -0x0020,0x0020,0x001f,0x001e,0x001e,0x001d,0x001d,0x001c,0x001c,0x001b, -0x001b,0x001a,0x001a,0x0019,0x0019,0x0018,0x0018,0x0017,0x0017,0x0016, -0x0016,0x0015,0x0015,0x0015,0x0014,0x0014,0x0013,0x0013,0x0013,0x0012, -0x0012,0x0012,0x0011,0x0011,0x0011,0x0010,0x0010,0x0010,0x000f,0x000f, -0x000f,0x000e,0x000e,0x000e,0x000d,0x000d,0x000d,0x000d,0x000c,0x000c, -0x000c,0x000c,0x000b,0x000b,0x000b,0x000b,0x000a,0x000a,0x000a,0x000a, -0x000a,0x0009,0x0009,0x0009,0x0009,0x0009,0x0008,0x0008,0x0008,0x0008, -0x0008,0x0008,0x0007,0x0007,0x0007,0x0007,0x0007,0x0007,0x0006,0x0006, -0x0006,0x0006,0x0006,0x0006,0x0006,0x0006,0x0005,0x0005,0x0005,0x0005, -0x0005,0x0005,0x0005,0x0005,0x0004,0x0004,0x0004,0x0004,0x0004,0x0004, -0x0004,0x0004,0x0004,0x0004,0x0004,0x0003,0x0003,0x0003,0x0003,0x0003, -0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0003,0x0002, -0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002, -0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0002,0x0001,0x0001, -0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001, -0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001, -0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001,0x0001, -0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, -0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, -0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, -0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, -0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, -}; - -static const uint16_t hth[50][3]= { -{ 0x04d0,0x04f0,0x0580 }, -{ 0x04d0,0x04f0,0x0580 }, -{ 0x0440,0x0460,0x04b0 }, -{ 0x0400,0x0410,0x0450 }, -{ 0x03e0,0x03e0,0x0420 }, -{ 0x03c0,0x03d0,0x03f0 }, -{ 0x03b0,0x03c0,0x03e0 }, -{ 0x03b0,0x03b0,0x03d0 }, -{ 0x03a0,0x03b0,0x03c0 }, -{ 0x03a0,0x03a0,0x03b0 }, -{ 0x03a0,0x03a0,0x03b0 }, -{ 0x03a0,0x03a0,0x03b0 }, -{ 0x03a0,0x03a0,0x03a0 }, -{ 0x0390,0x03a0,0x03a0 }, -{ 0x0390,0x0390,0x03a0 }, -{ 0x0390,0x0390,0x03a0 }, -{ 0x0380,0x0390,0x03a0 }, -{ 0x0380,0x0380,0x03a0 }, -{ 0x0370,0x0380,0x03a0 }, -{ 0x0370,0x0380,0x03a0 }, -{ 0x0360,0x0370,0x0390 }, -{ 0x0360,0x0370,0x0390 }, -{ 0x0350,0x0360,0x0390 }, -{ 0x0350,0x0360,0x0390 }, -{ 0x0340,0x0350,0x0380 }, -{ 0x0340,0x0350,0x0380 }, -{ 0x0330,0x0340,0x0380 }, -{ 0x0320,0x0340,0x0370 }, -{ 0x0310,0x0320,0x0360 }, -{ 0x0300,0x0310,0x0350 }, -{ 0x02f0,0x0300,0x0340 }, -{ 0x02f0,0x02f0,0x0330 }, -{ 0x02f0,0x02f0,0x0320 }, -{ 0x02f0,0x02f0,0x0310 }, -{ 0x0300,0x02f0,0x0300 }, -{ 0x0310,0x0300,0x02f0 }, -{ 0x0340,0x0320,0x02f0 }, -{ 0x0390,0x0350,0x02f0 }, -{ 0x03e0,0x0390,0x0300 }, -{ 0x0420,0x03e0,0x0310 }, -{ 0x0460,0x0420,0x0330 }, -{ 0x0490,0x0450,0x0350 }, -{ 0x04a0,0x04a0,0x03c0 }, -{ 0x0460,0x0490,0x0410 }, -{ 0x0440,0x0460,0x0470 }, -{ 0x0440,0x0440,0x04a0 }, -{ 0x0520,0x0480,0x0460 }, -{ 0x0800,0x0630,0x0440 }, -{ 0x0840,0x0840,0x0450 }, -{ 0x0840,0x0840,0x04e0 }, -}; - -static const uint8_t baptab[64]= { - 0, 1, 1, 1, 1, 1, 2, 2, 3, 3, - 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, - 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, - 9, 10, 10, 10, 10, 11, 11, 11, 11, 12, - 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, - 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, - 15, 15, 15, 15, -}; - -const uint8_t ff_sdecaytab[4]={ - 0x0f, 0x11, 0x13, 0x15, -}; - -const uint8_t ff_fdecaytab[4]={ - 0x3f, 0x53, 0x67, 0x7b, -}; - -const uint16_t ff_sgaintab[4]= { - 0x540, 0x4d8, 0x478, 0x410, -}; - -const uint16_t ff_dbkneetab[4]= { - 0x000, 0x700, 0x900, 0xb00, -}; - -const int16_t ff_floortab[8]= { - 0x2f0, 0x2b0, 0x270, 0x230, 0x1f0, 0x170, 0x0f0, 0xf800, -}; - -const uint16_t ff_fgaintab[8]= { - 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400, -}; - -static const uint8_t bndsz[50]={ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, - 3, 6, 6, 6, 6, 6, 6, 12, 12, 12, 12, 24, 24, 24, 24, 24 -}; - -static uint8_t bndtab[51]; +#ifndef FFMPEG_AC3TAB_H +#define FFMPEG_AC3TAB_H + +#include "common.h" + +extern const uint16_t ff_ac3_frame_size_tab[38][3]; +extern const uint8_t ff_ac3_channels_tab[8]; +extern const uint16_t ff_ac3_sample_rate_tab[3]; +extern const uint16_t ff_ac3_bitrate_tab[19]; +extern const int16_t ff_ac3_window[256]; +extern const uint8_t ff_ac3_log_add_tab[260]; +extern const uint16_t ff_ac3_hearing_threshold_tab[50][3]; +extern const uint8_t ff_ac3_bap_tab[64]; +extern const uint8_t ff_ac3_slow_decay_tab[4]; +extern const uint8_t ff_ac3_fast_decay_tab[4]; +extern const uint16_t ff_ac3_slow_gain_tab[4]; +extern const uint16_t ff_ac3_db_per_bit_tab[4]; +extern const int16_t ff_ac3_floor_tab[8]; +extern const uint16_t ff_ac3_fast_gain_tab[8]; +extern const uint8_t ff_ac3_critical_band_size_tab[50]; + +#endif /* FFMPEG_AC3TAB_H */ diff --git a/contrib/ffmpeg/libavcodec/adpcm.c b/contrib/ffmpeg/libavcodec/adpcm.c index 8800c3a20..eadcfaedd 100644 --- a/contrib/ffmpeg/libavcodec/adpcm.c +++ b/contrib/ffmpeg/libavcodec/adpcm.c @@ -20,6 +20,7 @@ */ #include "avcodec.h" #include "bitstream.h" +#include "bytestream.h" /** * @file adpcm.c @@ -29,6 +30,11 @@ * by Mike Melanson (melanson@pcisys.net) * CD-ROM XA ADPCM codec by BERO * EA ADPCM decoder by Robin Kay (komadori@myrealbox.com) + * EA ADPCM R1/R2/R3 decoder by Peter Ross (pross@xvid.org) + * EA IMA EACS decoder by Peter Ross (pross@xvid.org) + * EA IMA SEAD decoder by Peter Ross (pross@xvid.org) + * EA ADPCM XAS decoder by Peter Ross (pross@xvid.org) + * THP ADPCM decoder by Marco Gerards (mgerards@xs4all.nl) * * Features and limitations: * @@ -48,12 +54,6 @@ #define BLKSIZE 1024 -#define CLAMP_TO_SHORT(value) \ -if (value > 32767) \ - value = 32767; \ -else if (value < -32768) \ - value = -32768; \ - /* step_table[] and index_table[] are from the ADPCM reference source */ /* This is the index table: */ static const int index_table[16] = { @@ -148,8 +148,7 @@ typedef struct ADPCMChannelStatus { typedef struct ADPCMContext { int channel; /* for stereo MOVs, decode left, then decode right, then tell it's decoded */ - ADPCMChannelStatus status[2]; - short sample_buffer[32]; /* hold left samples while waiting for right samples */ + ADPCMChannelStatus status[6]; } ADPCMContext; /* XXX: implement encoding */ @@ -160,11 +159,6 @@ static int adpcm_encode_init(AVCodecContext *avctx) if (avctx->channels > 2) return -1; /* only stereo or mono =) */ switch(avctx->codec->id) { - case CODEC_ID_ADPCM_IMA_QT: - av_log(avctx, AV_LOG_ERROR, "ADPCM: codec adpcm_ima_qt unsupported for encoding !\n"); - avctx->frame_size = 64; /* XXX: can multiple of avctx->channels * 64 (left and right blocks are interleaved) */ - return -1; - break; case CODEC_ID_ADPCM_IMA_WAV: avctx->frame_size = (BLKSIZE - 4 * avctx->channels) * 8 / (4 * avctx->channels) + 1; /* each 16 bits sample gives one nibble */ /* and we have 4 bytes per channel overhead */ @@ -180,6 +174,15 @@ static int adpcm_encode_init(AVCodecContext *avctx) avctx->frame_size = BLKSIZE * avctx->channels; avctx->block_align = BLKSIZE; break; + case CODEC_ID_ADPCM_SWF: + if (avctx->sample_rate != 11025 && + avctx->sample_rate != 22050 && + avctx->sample_rate != 44100) { + av_log(avctx, AV_LOG_ERROR, "Sample rate must be 11025, 22050 or 44100\n"); + return -1; + } + avctx->frame_size = 512 * (avctx->sample_rate / 11025); + break; default: return -1; break; @@ -203,8 +206,8 @@ static inline unsigned char adpcm_ima_compress_sample(ADPCMChannelStatus *c, sho { int delta = sample - c->prev_sample; int nibble = FFMIN(7, abs(delta)*4/step_table[c->step_index]) + (delta<0)*8; - c->prev_sample = c->prev_sample + ((step_table[c->step_index] * yamaha_difflookup[nibble]) / 8); - CLAMP_TO_SHORT(c->prev_sample); + c->prev_sample += ((step_table[c->step_index] * yamaha_difflookup[nibble]) / 8); + c->prev_sample = av_clip_int16(c->prev_sample); c->step_index = av_clip(c->step_index + index_table[nibble], 0, 88); return nibble; } @@ -223,10 +226,9 @@ static inline unsigned char adpcm_ms_compress_sample(ADPCMChannelStatus *c, shor nibble= av_clip(nibble, -8, 7)&0x0F; predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta; - CLAMP_TO_SHORT(predictor); c->sample2 = c->sample1; - c->sample1 = predictor; + c->sample1 = av_clip_int16(predictor); c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8; if (c->idelta < 16) c->idelta = 16; @@ -247,8 +249,8 @@ static inline unsigned char adpcm_yamaha_compress_sample(ADPCMChannelStatus *c, nibble = FFMIN(7, abs(delta)*4/c->step) + (delta<0)*8; - c->predictor = c->predictor + ((c->step * yamaha_difflookup[nibble]) / 8); - CLAMP_TO_SHORT(c->predictor); + c->predictor += ((c->step * yamaha_difflookup[nibble]) / 8); + c->predictor = av_clip_int16(c->predictor); c->step = (c->step * yamaha_indexscale[nibble]) >> 8; c->step = av_clip(c->step, 127, 24567); @@ -293,7 +295,7 @@ static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples, nodes[0]->step = c->step_index; nodes[0]->sample1 = c->sample1; nodes[0]->sample2 = c->sample2; - if(version == CODEC_ID_ADPCM_IMA_WAV) + if((version == CODEC_ID_ADPCM_IMA_WAV) || (version == CODEC_ID_ADPCM_SWF)) nodes[0]->sample1 = c->prev_sample; if(version == CODEC_ID_ADPCM_MS) nodes[0]->step = c->idelta; @@ -328,7 +330,7 @@ static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples, #define STORE_NODE(NAME, STEP_INDEX)\ int d;\ uint32_t ssd;\ - CLAMP_TO_SHORT(dec_sample);\ + dec_sample = av_clip_int16(dec_sample);\ d = sample - dec_sample;\ ssd = nodes[j]->ssd + d*d;\ if(nodes_next[frontier-1] && ssd >= nodes_next[frontier-1]->ssd)\ @@ -364,7 +366,7 @@ static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples, next_##NAME:; STORE_NODE(ms, FFMAX(16, (AdaptationTable[nibble] * step) >> 8)); } - } else if(version == CODEC_ID_ADPCM_IMA_WAV) { + } else if((version == CODEC_ID_ADPCM_IMA_WAV)|| (version == CODEC_ID_ADPCM_SWF)) { #define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)\ const int predictor = nodes[j]->sample1;\ const int div = (sample - predictor) * 4 / STEP_TABLE;\ @@ -440,22 +442,18 @@ static int adpcm_encode_frame(AVCodecContext *avctx, /* n = (BLKSIZE - 4 * avctx->channels) / (2 * 8 * avctx->channels); */ switch(avctx->codec->id) { - case CODEC_ID_ADPCM_IMA_QT: /* XXX: can't test until we get .mov writer */ - break; case CODEC_ID_ADPCM_IMA_WAV: n = avctx->frame_size / 8; c->status[0].prev_sample = (signed short)samples[0]; /* XXX */ /* c->status[0].step_index = 0; *//* XXX: not sure how to init the state machine */ - *dst++ = (c->status[0].prev_sample) & 0xFF; /* little endian */ - *dst++ = (c->status[0].prev_sample >> 8) & 0xFF; + bytestream_put_le16(&dst, c->status[0].prev_sample); *dst++ = (unsigned char)c->status[0].step_index; *dst++ = 0; /* unknown */ samples++; if (avctx->channels == 2) { - c->status[1].prev_sample = (signed short)samples[1]; + c->status[1].prev_sample = (signed short)samples[0]; /* c->status[1].step_index = 0; */ - *dst++ = (c->status[1].prev_sample) & 0xFF; - *dst++ = (c->status[1].prev_sample >> 8) & 0xFF; + bytestream_put_le16(&dst, c->status[1].prev_sample); *dst++ = (unsigned char)c->status[1].step_index; *dst++ = 0; samples++; @@ -481,17 +479,17 @@ static int adpcm_encode_frame(AVCodecContext *avctx, } } else for (; n>0; n--) { - *dst = adpcm_ima_compress_sample(&c->status[0], samples[0]) & 0x0F; - *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels]) << 4) & 0xF0; + *dst = adpcm_ima_compress_sample(&c->status[0], samples[0]); + *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels]) << 4; dst++; - *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 2]) & 0x0F; - *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 3]) << 4) & 0xF0; + *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 2]); + *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 3]) << 4; dst++; - *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 4]) & 0x0F; - *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 5]) << 4) & 0xF0; + *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 4]); + *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 5]) << 4; dst++; - *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 6]) & 0x0F; - *dst |= (adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 7]) << 4) & 0xF0; + *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 6]); + *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 7]) << 4; dst++; /* right channel */ if (avctx->channels == 2) { @@ -511,6 +509,46 @@ static int adpcm_encode_frame(AVCodecContext *avctx, samples += 8 * avctx->channels; } break; + case CODEC_ID_ADPCM_SWF: + { + int i; + PutBitContext pb; + init_put_bits(&pb, dst, buf_size*8); + + n = avctx->frame_size-1; + + //Store AdpcmCodeSize + put_bits(&pb, 2, 2); //Set 4bits flash adpcm format + + //Init the encoder state + for(i=0; ichannels; i++){ + c->status[i].step_index = av_clip(c->status[i].step_index, 0, 63); // clip step so it fits 6 bits + put_bits(&pb, 16, samples[i] & 0xFFFF); + put_bits(&pb, 6, c->status[i].step_index); + c->status[i].prev_sample = (signed short)samples[i]; + } + + if(avctx->trellis > 0) { + uint8_t buf[2][n]; + adpcm_compress_trellis(avctx, samples+2, buf[0], &c->status[0], n); + if (avctx->channels == 2) + adpcm_compress_trellis(avctx, samples+3, buf[1], &c->status[1], n); + for(i=0; ichannels == 2) + put_bits(&pb, 4, buf[1][i]); + } + } else { + for (i=1; iframe_size; i++) { + put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels*i])); + if (avctx->channels == 2) + put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[1], samples[2*i+1])); + } + } + flush_put_bits(&pb); + dst += put_bits_count(&pb)>>3; + break; + } case CODEC_ID_ADPCM_MS: for(i=0; ichannels; i++){ int predictor=0; @@ -523,20 +561,17 @@ static int adpcm_encode_frame(AVCodecContext *avctx, if (c->status[i].idelta < 16) c->status[i].idelta = 16; - *dst++ = c->status[i].idelta & 0xFF; - *dst++ = c->status[i].idelta >> 8; + bytestream_put_le16(&dst, c->status[i].idelta); } for(i=0; ichannels; i++){ c->status[i].sample1= *samples++; - *dst++ = c->status[i].sample1 & 0xFF; - *dst++ = c->status[i].sample1 >> 8; + bytestream_put_le16(&dst, c->status[i].sample1); } for(i=0; ichannels; i++){ c->status[i].sample2= *samples++; - *dst++ = c->status[i].sample2 & 0xFF; - *dst++ = c->status[i].sample2 >> 8; + bytestream_put_le16(&dst, c->status[i].sample2); } if(avctx->trellis > 0) { @@ -597,20 +632,29 @@ static int adpcm_encode_frame(AVCodecContext *avctx, static int adpcm_decode_init(AVCodecContext * avctx) { ADPCMContext *c = avctx->priv_data; + unsigned int max_channels = 2; - if(avctx->channels > 2U){ + switch(avctx->codec->id) { + case CODEC_ID_ADPCM_EA_R1: + case CODEC_ID_ADPCM_EA_R2: + case CODEC_ID_ADPCM_EA_R3: + max_channels = 6; + break; + } + if(avctx->channels > max_channels){ return -1; } - c->channel = 0; - c->status[0].predictor = c->status[1].predictor = 0; - c->status[0].step_index = c->status[1].step_index = 0; - c->status[0].step = c->status[1].step = 0; - switch(avctx->codec->id) { case CODEC_ID_ADPCM_CT: c->status[0].step = c->status[1].step = 511; break; + case CODEC_ID_ADPCM_IMA_WS: + if (avctx->extradata && avctx->extradata_size == 2 * 4) { + c->status[0].predictor = AV_RL32(avctx->extradata); + c->status[1].predictor = AV_RL32(avctx->extradata + 4); + } + break; default: break; } @@ -638,11 +682,10 @@ static inline short adpcm_ima_expand_nibble(ADPCMChannelStatus *c, char nibble, if (sign) predictor -= diff; else predictor += diff; - CLAMP_TO_SHORT(predictor); - c->predictor = predictor; + c->predictor = av_clip_int16(predictor); c->step_index = step_index; - return (short)predictor; + return (short)c->predictor; } static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, char nibble) @@ -651,19 +694,17 @@ static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, char nibble) predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 256; predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta; - CLAMP_TO_SHORT(predictor); c->sample2 = c->sample1; - c->sample1 = predictor; + c->sample1 = av_clip_int16(predictor); c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8; if (c->idelta < 16) c->idelta = 16; - return (short)predictor; + return c->sample1; } static inline short adpcm_ct_expand_nibble(ADPCMChannelStatus *c, char nibble) { - int predictor; int sign, delta, diff; int new_step; @@ -673,23 +714,14 @@ static inline short adpcm_ct_expand_nibble(ADPCMChannelStatus *c, char nibble) * the reference ADPCM implementation since modern CPUs can do the mults * quickly enough */ diff = ((2 * delta + 1) * c->step) >> 3; - predictor = c->predictor; /* predictor update is not so trivial: predictor is multiplied on 254/256 before updating */ - if(sign) - predictor = ((predictor * 254) >> 8) - diff; - else - predictor = ((predictor * 254) >> 8) + diff; + c->predictor = ((c->predictor * 254) >> 8) + (sign ? -diff : diff); + c->predictor = av_clip_int16(c->predictor); /* calculate new step and clamp it to range 511..32767 */ new_step = (ct_adpcm_table[nibble & 7] * c->step) >> 8; - c->step = new_step; - if(c->step < 511) - c->step = 511; - if(c->step > 32767) - c->step = 32767; - - CLAMP_TO_SHORT(predictor); - c->predictor = predictor; - return (short)predictor; + c->step = av_clip(new_step, 511, 32767); + + return (short)c->predictor; } static inline short adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, char nibble, int size, int shift) @@ -700,16 +732,8 @@ static inline short adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, char nibble delta = nibble & ((1<<(size-1))-1); diff = delta << (7 + c->step + shift); - if (sign) - c->predictor -= diff; - else - c->predictor += diff; - /* clamp result */ - if (c->predictor > 16256) - c->predictor = 16256; - else if (c->predictor < -16384) - c->predictor = -16384; + c->predictor = av_clip(c->predictor + (sign ? -diff : diff), -16384,16256); /* calculate new step */ if (delta >= (2*size - 3) && c->step < 3) @@ -728,7 +752,7 @@ static inline short adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, unsigned c } c->predictor += (c->step * yamaha_difflookup[nibble]) / 8; - CLAMP_TO_SHORT(c->predictor); + c->predictor = av_clip_int16(c->predictor); c->step = (c->step * yamaha_indexscale[nibble]) >> 8; c->step = av_clip(c->step, 127, 24567); return c->predictor; @@ -757,11 +781,10 @@ static void xa_decode(short *out, const unsigned char *in, t = (signed char)(d<<4)>>4; s = ( t<>6); - CLAMP_TO_SHORT(s); - *out = s; - out += inc; s_2 = s_1; - s_1 = s; + s_1 = av_clip_int16(s); + *out = s_1; + out += inc; } if (inc==2) { /* stereo */ @@ -783,11 +806,10 @@ static void xa_decode(short *out, const unsigned char *in, t = (signed char)d >> 4; s = ( t<>6); - CLAMP_TO_SHORT(s); - *out = s; - out += inc; s_2 = s_1; - s_1 = s; + s_1 = av_clip_int16(s); + *out = s_1; + out += inc; } if (inc==2) { /* stereo */ @@ -819,7 +841,7 @@ static void xa_decode(short *out, const unsigned char *in, static int adpcm_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { ADPCMContext *c = avctx->priv_data; ADPCMChannelStatus *cs; @@ -827,7 +849,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, int block_predictor[2]; short *samples; short *samples_end; - uint8_t *src; + const uint8_t *src; int st; /* stereo */ /* DK3 ADPCM accounting variables */ @@ -877,7 +899,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, if(cs->predictor & 0x8000) cs->predictor -= 0x10000; - CLAMP_TO_SHORT(cs->predictor); + cs->predictor = av_clip_int16(cs->predictor); cs->step_index = (*src++) & 0x7F; @@ -914,11 +936,9 @@ static int adpcm_decode_frame(AVCodecContext *avctx, for(i=0; ichannels; i++){ cs = &(c->status[i]); - cs->predictor = (int16_t)(src[0] + (src[1]<<8)); + cs->predictor = *samples++ = (int16_t)(src[0] + (src[1]<<8)); src+=2; - // XXX: is this correct ??: *samples++ = cs->predictor; - cs->step_index = *src++; if (cs->step_index > 88){ av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index); @@ -1101,8 +1121,6 @@ static int adpcm_decode_frame(AVCodecContext *avctx, } break; case CODEC_ID_ADPCM_XA: - c->status[0].sample1 = c->status[0].sample2 = - c->status[1].sample1 = c->status[1].sample2 = 0; while (buf_size >= 128) { xa_decode(samples, src, &c->status[0], &c->status[1], avctx->channels); @@ -1111,6 +1129,30 @@ static int adpcm_decode_frame(AVCodecContext *avctx, buf_size -= 128; } break; + case CODEC_ID_ADPCM_IMA_EA_EACS: + samples_in_chunk = bytestream_get_le32(&src) >> (1-st); + + if (samples_in_chunk > buf_size-4-(8<status[i].step_index = bytestream_get_le32(&src); + for (i=0; i<=st; i++) + c->status[i].predictor = bytestream_get_le32(&src); + + for (; samples_in_chunk; samples_in_chunk--, src++) { + *samples++ = adpcm_ima_expand_nibble(&c->status[0], *src>>4, 3); + *samples++ = adpcm_ima_expand_nibble(&c->status[st], *src&0x0F, 3); + } + break; + case CODEC_ID_ADPCM_IMA_EA_SEAD: + for (; src < buf+buf_size; src++) { + *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] >> 4, 6); + *samples++ = adpcm_ima_expand_nibble(&c->status[st],src[0]&0x0F, 6); + } + break; case CODEC_ID_ADPCM_EA: samples_in_chunk = AV_RL32(src); if (samples_in_chunk >= ((buf_size - 12) * 2)) { @@ -1149,28 +1191,147 @@ static int adpcm_decode_frame(AVCodecContext *avctx, next_right_sample = (next_right_sample + (current_right_sample * coeff1r) + (previous_right_sample * coeff2r) + 0x80) >> 8; - CLAMP_TO_SHORT(next_left_sample); - CLAMP_TO_SHORT(next_right_sample); previous_left_sample = current_left_sample; - current_left_sample = next_left_sample; + current_left_sample = av_clip_int16(next_left_sample); previous_right_sample = current_right_sample; - current_right_sample = next_right_sample; + current_right_sample = av_clip_int16(next_right_sample); *samples++ = (unsigned short)current_left_sample; *samples++ = (unsigned short)current_right_sample; } } break; + case CODEC_ID_ADPCM_EA_R1: + case CODEC_ID_ADPCM_EA_R2: + case CODEC_ID_ADPCM_EA_R3: { + /* channel numbering + 2chan: 0=fl, 1=fr + 4chan: 0=fl, 1=rl, 2=fr, 3=rr + 6chan: 0=fl, 1=c, 2=fr, 3=rl, 4=rr, 5=sub */ + const int big_endian = avctx->codec->id == CODEC_ID_ADPCM_EA_R3; + int32_t previous_sample, current_sample, next_sample; + int32_t coeff1, coeff2; + uint8_t shift; + unsigned int channel; + uint16_t *samplesC; + const uint8_t *srcC; + + samples_in_chunk = (big_endian ? bytestream_get_be32(&src) + : bytestream_get_le32(&src)) / 28; + if (samples_in_chunk > UINT32_MAX/(28*avctx->channels) || + 28*samples_in_chunk*avctx->channels > samples_end-samples) { + src += buf_size - 4; + break; + } + + for (channel=0; channelchannels; channel++) { + srcC = src + (big_endian ? bytestream_get_be32(&src) + : bytestream_get_le32(&src)) + + (avctx->channels-channel-1) * 4; + samplesC = samples + channel; + + if (avctx->codec->id == CODEC_ID_ADPCM_EA_R1) { + current_sample = (int16_t)bytestream_get_le16(&srcC); + previous_sample = (int16_t)bytestream_get_le16(&srcC); + } else { + current_sample = c->status[channel].predictor; + previous_sample = c->status[channel].prev_sample; + } + + for (count1=0; count1channels; + } + } else { + coeff1 = ea_adpcm_table[ (*srcC>>4) & 0x0F ]; + coeff2 = ea_adpcm_table[((*srcC>>4) & 0x0F) + 4]; + shift = (*srcC++ & 0x0F) + 8; + + for (count2=0; count2<28; count2++) { + if (count2 & 1) + next_sample = ((*srcC++ & 0x0F) << 28) >> shift; + else + next_sample = ((*srcC & 0xF0) << 24) >> shift; + + next_sample += (current_sample * coeff1) + + (previous_sample * coeff2); + next_sample = av_clip_int16(next_sample >> 8); + + previous_sample = current_sample; + current_sample = next_sample; + *samplesC = current_sample; + samplesC += avctx->channels; + } + } + } + + if (avctx->codec->id != CODEC_ID_ADPCM_EA_R1) { + c->status[channel].predictor = current_sample; + c->status[channel].prev_sample = previous_sample; + } + } + + src = src + buf_size - (4 + 4*avctx->channels); + samples += 28 * samples_in_chunk * avctx->channels; + break; + } + case CODEC_ID_ADPCM_EA_XAS: + if (samples_end-samples < 32*4*avctx->channels + || buf_size < (4+15)*4*avctx->channels) { + src += buf_size; + break; + } + for (channel=0; channelchannels; channel++) { + int coeff[2][4], shift[4]; + short *s2, *s = &samples[channel]; + for (n=0; n<4; n++, s+=32*avctx->channels) { + for (i=0; i<2; i++) + coeff[i][n] = ea_adpcm_table[(src[0]&0x0F)+4*i]; + shift[n] = (src[2]&0x0F) + 8; + for (s2=s, i=0; i<2; i++, src+=2, s2+=avctx->channels) + s2[0] = (src[0]&0xF0) + (src[1]<<8); + } + + for (m=2; m<32; m+=2) { + s = &samples[m*avctx->channels + channel]; + for (n=0; n<4; n++, src++, s+=32*avctx->channels) { + for (s2=s, i=0; i<8; i+=4, s2+=avctx->channels) { + int level = ((*src & (0xF0>>i)) << (24+i)) >> shift[n]; + int pred = s2[-1*avctx->channels] * coeff[0][n] + + s2[-2*avctx->channels] * coeff[1][n]; + s2[0] = av_clip_int16((level + pred + 0x80) >> 8); + } + } + } + } + samples += 32*4*avctx->channels; + break; + case CODEC_ID_ADPCM_IMA_AMV: case CODEC_ID_ADPCM_IMA_SMJPEG: - c->status[0].predictor = *src; - src += 2; - c->status[0].step_index = *src++; - src++; /* skip another byte before getting to the meat */ + c->status[0].predictor = (int16_t)bytestream_get_le16(&src); + c->status[0].step_index = bytestream_get_le16(&src); + + if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV) + src+=4; + while (src < buf + buf_size) { + char hi, lo; + lo = *src & 0x0F; + hi = (*src >> 4) & 0x0F; + + if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV) + FFSWAP(char, hi, lo); + *samples++ = adpcm_ima_expand_nibble(&c->status[0], - *src & 0x0F, 3); + lo, 3); *samples++ = adpcm_ima_expand_nibble(&c->status[0], - (*src >> 4) & 0x0F, 3); + hi, 3); src++; } break; @@ -1236,56 +1397,57 @@ static int adpcm_decode_frame(AVCodecContext *avctx, { GetBitContext gb; const int *table; - int k0, signmask, nb_bits; + int k0, signmask, nb_bits, count; int size = buf_size*8; init_get_bits(&gb, buf, size); - //read bits & inital values + //read bits & initial values nb_bits = get_bits(&gb, 2)+2; //av_log(NULL,AV_LOG_INFO,"nb_bits: %d\n", nb_bits); table = swf_index_tables[nb_bits-2]; k0 = 1 << (nb_bits-2); signmask = 1 << (nb_bits-1); - for (i = 0; i < avctx->channels; i++) { - *samples++ = c->status[i].predictor = get_sbits(&gb, 16); - c->status[i].step_index = get_bits(&gb, 6); - } - - while (get_bits_count(&gb) < size) - { - int i; - + while (get_bits_count(&gb) <= size - 22*avctx->channels) { for (i = 0; i < avctx->channels; i++) { - // similar to IMA adpcm - int delta = get_bits(&gb, nb_bits); - int step = step_table[c->status[i].step_index]; - long vpdiff = 0; // vpdiff = (delta+0.5)*step/4 - int k = k0; - - do { - if (delta & k) - vpdiff += step; - step >>= 1; - k >>= 1; - } while(k); - vpdiff += step; - - if (delta & signmask) - c->status[i].predictor -= vpdiff; - else - c->status[i].predictor += vpdiff; - - c->status[i].step_index += table[delta & (~signmask)]; - - c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88); - c->status[i].predictor = av_clip(c->status[i].predictor, -32768, 32767); - - *samples++ = c->status[i].predictor; - if (samples >= samples_end) { - av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n"); - return -1; + *samples++ = c->status[i].predictor = get_sbits(&gb, 16); + c->status[i].step_index = get_bits(&gb, 6); + } + + for (count = 0; get_bits_count(&gb) <= size - nb_bits*avctx->channels && count < 4095; count++) { + int i; + + for (i = 0; i < avctx->channels; i++) { + // similar to IMA adpcm + int delta = get_bits(&gb, nb_bits); + int step = step_table[c->status[i].step_index]; + long vpdiff = 0; // vpdiff = (delta+0.5)*step/4 + int k = k0; + + do { + if (delta & k) + vpdiff += step; + step >>= 1; + k >>= 1; + } while(k); + vpdiff += step; + + if (delta & signmask) + c->status[i].predictor -= vpdiff; + else + c->status[i].predictor += vpdiff; + + c->status[i].step_index += table[delta & (~signmask)]; + + c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88); + c->status[i].predictor = av_clip_int16(c->status[i].predictor); + + *samples++ = c->status[i].predictor; + if (samples >= samples_end) { + av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n"); + return -1; + } } } } @@ -1308,6 +1470,68 @@ static int adpcm_decode_frame(AVCodecContext *avctx, src++; } break; + case CODEC_ID_ADPCM_THP: + { + int table[2][16]; + unsigned int samplecnt; + int prev[2][2]; + int ch; + + if (buf_size < 80) { + av_log(avctx, AV_LOG_ERROR, "frame too small\n"); + return -1; + } + + src+=4; + samplecnt = bytestream_get_be32(&src); + + for (i = 0; i < 32; i++) + table[0][i] = (int16_t)bytestream_get_be16(&src); + + /* Initialize the previous sample. */ + for (i = 0; i < 4; i++) + prev[0][i] = (int16_t)bytestream_get_be16(&src); + + if (samplecnt >= (samples_end - samples) / (st + 1)) { + av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n"); + return -1; + } + + for (ch = 0; ch <= st; ch++) { + samples = (unsigned short *) data + ch; + + /* Read in every sample for this channel. */ + for (i = 0; i < samplecnt / 14; i++) { + int index = (*src >> 4) & 7; + unsigned int exp = 28 - (*src++ & 15); + int factor1 = table[ch][index * 2]; + int factor2 = table[ch][index * 2 + 1]; + + /* Decode 14 samples. */ + for (n = 0; n < 14; n++) { + int32_t sampledat; + if(n&1) sampledat= *src++ <<28; + else sampledat= (*src&0xF0)<<24; + + sampledat = ((prev[ch][0]*factor1 + + prev[ch][1]*factor2) >> 11) + (sampledat>>exp); + *samples = av_clip_int16(sampledat); + prev[ch][1] = prev[ch][0]; + prev[ch][0] = *samples++; + + /* In case of stereo, skip one sample, this sample + is for the other channel. */ + samples += st; + } + } + } + + /* In the previous loop, in case stereo is used, samples is + increased exactly one time too often. */ + samples -= st; + break; + } + default: return -1; } @@ -1352,21 +1576,27 @@ AVCodec name ## _decoder = { \ #define ADPCM_CODEC(id, name) \ ADPCM_ENCODER(id,name) ADPCM_DECODER(id,name) -ADPCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt); -ADPCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav); -ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3); -ADPCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4); -ADPCM_CODEC(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws); -ADPCM_CODEC(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg); -ADPCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms); -ADPCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm); -ADPCM_CODEC(CODEC_ID_ADPCM_XA, adpcm_xa); -ADPCM_CODEC(CODEC_ID_ADPCM_EA, adpcm_ea); -ADPCM_CODEC(CODEC_ID_ADPCM_CT, adpcm_ct); -ADPCM_CODEC(CODEC_ID_ADPCM_SWF, adpcm_swf); -ADPCM_CODEC(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha); -ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4); -ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3); -ADPCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2); - -#undef ADPCM_CODEC +ADPCM_DECODER(CODEC_ID_ADPCM_4XM, adpcm_4xm); +ADPCM_DECODER(CODEC_ID_ADPCM_CT, adpcm_ct); +ADPCM_DECODER(CODEC_ID_ADPCM_EA, adpcm_ea); +ADPCM_DECODER(CODEC_ID_ADPCM_EA_R1, adpcm_ea_r1); +ADPCM_DECODER(CODEC_ID_ADPCM_EA_R2, adpcm_ea_r2); +ADPCM_DECODER(CODEC_ID_ADPCM_EA_R3, adpcm_ea_r3); +ADPCM_DECODER(CODEC_ID_ADPCM_EA_XAS, adpcm_ea_xas); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_AMV, adpcm_ima_amv); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg); +ADPCM_CODEC (CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav); +ADPCM_DECODER(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws); +ADPCM_CODEC (CODEC_ID_ADPCM_MS, adpcm_ms); +ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4); +ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3); +ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2); +ADPCM_CODEC (CODEC_ID_ADPCM_SWF, adpcm_swf); +ADPCM_DECODER(CODEC_ID_ADPCM_THP, adpcm_thp); +ADPCM_DECODER(CODEC_ID_ADPCM_XA, adpcm_xa); +ADPCM_CODEC (CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha); diff --git a/contrib/ffmpeg/libavcodec/adx.c b/contrib/ffmpeg/libavcodec/adx.c deleted file mode 100644 index b449c9124..000000000 --- a/contrib/ffmpeg/libavcodec/adx.c +++ /dev/null @@ -1,412 +0,0 @@ -/* - * ADX ADPCM codecs - * Copyright (c) 2001,2003 BERO - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include "avcodec.h" - -/** - * @file adx.c - * SEGA CRI adx codecs. - * - * Reference documents: - * http://ku-www.ss.titech.ac.jp/~yatsushi/adx.html - * adx2wav & wav2adx http://www.geocities.co.jp/Playtown/2004/ - */ - -typedef struct { - int s1,s2; -} PREV; - -typedef struct { - PREV prev[2]; - int header_parsed; - unsigned char dec_temp[18*2]; - unsigned short enc_temp[32*2]; - int in_temp; -} ADXContext; - -//#define BASEVOL 0x11e0 -#define BASEVOL 0x4000 -#define SCALE1 0x7298 -#define SCALE2 0x3350 - -#define CLIP(s) if (s>32767) s=32767; else if (s<-32768) s=-32768 - -/* 18 bytes <-> 32 samples */ - -#ifdef CONFIG_ENCODERS -static void adx_encode(unsigned char *adx,const short *wav,PREV *prev) -{ - int scale; - int i; - int s0,s1,s2,d; - int max=0; - int min=0; - int data[32]; - - s1 = prev->s1; - s2 = prev->s2; - for(i=0;i<32;i++) { - s0 = wav[i]; - d = ((s0<<14) - SCALE1*s1 + SCALE2*s2)/BASEVOL; - data[i]=d; - if (maxd) min=d; - s2 = s1; - s1 = s0; - } - prev->s1 = s1; - prev->s2 = s2; - - /* -8..+7 */ - - if (max==0 && min==0) { - memset(adx,0,18); - return; - } - - if (max/7>-min/8) scale = max/7; - else scale = -min/8; - - if (scale==0) scale=1; - - adx[0] = scale>>8; - adx[1] = scale; - - for(i=0;i<16;i++) { - adx[i+2] = ((data[i*2]/scale)<<4) | ((data[i*2+1]/scale)&0xf); - } -} -#endif //CONFIG_ENCODERS - -static void adx_decode(short *out,const unsigned char *in,PREV *prev) -{ - int scale = ((in[0]<<8)|(in[1])); - int i; - int s0,s1,s2,d; - -// printf("%x ",scale); - - in+=2; - s1 = prev->s1; - s2 = prev->s2; - for(i=0;i<16;i++) { - d = in[i]; - // d>>=4; if (d&8) d-=16; - d = ((signed char)d >> 4); - s0 = (BASEVOL*d*scale + SCALE1*s1 - SCALE2*s2)>>14; - CLIP(s0); - *out++=s0; - s2 = s1; - s1 = s0; - - d = in[i]; - //d&=15; if (d&8) d-=16; - d = ((signed char)(d<<4) >> 4); - s0 = (BASEVOL*d*scale + SCALE1*s1 - SCALE2*s2)>>14; - CLIP(s0); - *out++=s0; - s2 = s1; - s1 = s0; - } - prev->s1 = s1; - prev->s2 = s2; - -} - -static void adx_decode_stereo(short *out,const unsigned char *in,PREV *prev) -{ - short tmp[32*2]; - int i; - - adx_decode(tmp ,in ,prev); - adx_decode(tmp+32,in+18,prev+1); - for(i=0;i<32;i++) { - out[i*2] = tmp[i]; - out[i*2+1] = tmp[i+32]; - } -} - -#ifdef CONFIG_ENCODERS - -static void write_long(unsigned char *p,uint32_t v) -{ - p[0] = v>>24; - p[1] = v>>16; - p[2] = v>>8; - p[3] = v; -} - -static int adx_encode_header(AVCodecContext *avctx,unsigned char *buf,size_t bufsize) -{ -#if 0 - struct { - uint32_t offset; /* 0x80000000 + sample start - 4 */ - unsigned char unknown1[3]; /* 03 12 04 */ - unsigned char channel; /* 1 or 2 */ - uint32_t freq; - uint32_t size; - uint32_t unknown2; /* 01 f4 03 00 */ - uint32_t unknown3; /* 00 00 00 00 */ - uint32_t unknown4; /* 00 00 00 00 */ - - /* if loop - unknown3 00 15 00 01 - unknown4 00 00 00 01 - long loop_start_sample; - long loop_start_byte; - long loop_end_sample; - long loop_end_byte; - long - */ - } adxhdr; /* big endian */ - /* offset-6 "(c)CRI" */ -#endif - write_long(buf+0x00,0x80000000|0x20); - write_long(buf+0x04,0x03120400|avctx->channels); - write_long(buf+0x08,avctx->sample_rate); - write_long(buf+0x0c,0); /* FIXME: set after */ - write_long(buf+0x10,0x01040300); - write_long(buf+0x14,0x00000000); - write_long(buf+0x18,0x00000000); - memcpy(buf+0x1c,"\0\0(c)CRI",8); - return 0x20+4; -} - -static int adx_decode_init(AVCodecContext *avctx); -static int adx_encode_init(AVCodecContext *avctx) -{ - if (avctx->channels > 2) - return -1; /* only stereo or mono =) */ - avctx->frame_size = 32; - - avctx->coded_frame= avcodec_alloc_frame(); - avctx->coded_frame->key_frame= 1; - -// avctx->bit_rate = avctx->sample_rate*avctx->channels*18*8/32; - - av_log(avctx, AV_LOG_DEBUG, "adx encode init\n"); - adx_decode_init(avctx); - - return 0; -} - -static int adx_encode_close(AVCodecContext *avctx) -{ - av_freep(&avctx->coded_frame); - - return 0; -} - -static int adx_encode_frame(AVCodecContext *avctx, - uint8_t *frame, int buf_size, void *data) -{ - ADXContext *c = avctx->priv_data; - const short *samples = data; - unsigned char *dst = frame; - int rest = avctx->frame_size; - -/* - input data size = - ffmpeg.c: do_audio_out() - frame_bytes = enc->frame_size * 2 * enc->channels; -*/ - -// printf("sz=%d ",buf_size); fflush(stdout); - if (!c->header_parsed) { - int hdrsize = adx_encode_header(avctx,dst,buf_size); - dst+=hdrsize; - c->header_parsed = 1; - } - - if (avctx->channels==1) { - while(rest>=32) { - adx_encode(dst,samples,c->prev); - dst+=18; - samples+=32; - rest-=32; - } - } else { - while(rest>=32*2) { - short tmpbuf[32*2]; - int i; - - for(i=0;i<32;i++) { - tmpbuf[i] = samples[i*2]; - tmpbuf[i+32] = samples[i*2+1]; - } - - adx_encode(dst,tmpbuf,c->prev); - adx_encode(dst+18,tmpbuf+32,c->prev+1); - dst+=18*2; - samples+=32*2; - rest-=32*2; - } - } - return dst-frame; -} - -#endif //CONFIG_ENCODERS - -static uint32_t read_long(const unsigned char *p) -{ - return (p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3]; -} - -static int is_adx(const unsigned char *buf,size_t bufsize) -{ - int offset; - - if (buf[0]!=0x80) return 0; - offset = (read_long(buf)^0x80000000)+4; - if (bufsizesample_rate = freq; - avctx->channels = channels; - avctx->bit_rate = freq*channels*18*8/32; -// avctx->frame_size = 18*channels; - - return offset; -} - -static int adx_decode_init(AVCodecContext * avctx) -{ - ADXContext *c = avctx->priv_data; - -// printf("adx_decode_init\n"); fflush(stdout); - c->prev[0].s1 = 0; - c->prev[0].s2 = 0; - c->prev[1].s1 = 0; - c->prev[1].s2 = 0; - c->header_parsed = 0; - c->in_temp = 0; - return 0; -} - -#if 0 -static void dump(unsigned char *buf,size_t len) -{ - int i; - for(i=0;ipriv_data; - short *samples = data; - const uint8_t *buf = buf0; - int rest = buf_size; - - if (!c->header_parsed) { - int hdrsize = adx_decode_header(avctx,buf,rest); - if (hdrsize==0) return -1; - c->header_parsed = 1; - buf += hdrsize; - rest -= hdrsize; - } - - if (c->in_temp) { - int copysize = 18*avctx->channels - c->in_temp; - memcpy(c->dec_temp+c->in_temp,buf,copysize); - rest -= copysize; - buf += copysize; - if (avctx->channels==1) { - adx_decode(samples,c->dec_temp,c->prev); - samples += 32; - } else { - adx_decode_stereo(samples,c->dec_temp,c->prev); - samples += 32*2; - } - } - // - if (avctx->channels==1) { - while(rest>=18) { - adx_decode(samples,buf,c->prev); - rest-=18; - buf+=18; - samples+=32; - } - } else { - while(rest>=18*2) { - adx_decode_stereo(samples,buf,c->prev); - rest-=18*2; - buf+=18*2; - samples+=32*2; - } - } - // - c->in_temp = rest; - if (rest) { - memcpy(c->dec_temp,buf,rest); - buf+=rest; - } - *data_size = (uint8_t*)samples - (uint8_t*)data; -// printf("%d:%d ",buf-buf0,*data_size); fflush(stdout); - return buf-buf0; -} - -#ifdef CONFIG_ENCODERS -AVCodec adpcm_adx_encoder = { - "adpcm_adx", - CODEC_TYPE_AUDIO, - CODEC_ID_ADPCM_ADX, - sizeof(ADXContext), - adx_encode_init, - adx_encode_frame, - adx_encode_close, - NULL, -}; -#endif //CONFIG_ENCODERS - -AVCodec adpcm_adx_decoder = { - "adpcm_adx", - CODEC_TYPE_AUDIO, - CODEC_ID_ADPCM_ADX, - sizeof(ADXContext), - adx_decode_init, - NULL, - NULL, - adx_decode_frame, -}; - diff --git a/contrib/ffmpeg/libavcodec/adx.h b/contrib/ffmpeg/libavcodec/adx.h new file mode 100644 index 000000000..16180372a --- /dev/null +++ b/contrib/ffmpeg/libavcodec/adx.h @@ -0,0 +1,49 @@ +/* + * ADX ADPCM codecs + * Copyright (c) 2001,2003 BERO + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file adx.h + * SEGA CRI adx codecs. + * + * Reference documents: + * http://ku-www.ss.titech.ac.jp/~yatsushi/adx.html + * adx2wav & wav2adx http://www.geocities.co.jp/Playtown/2004/ + */ + +#ifndef FFMPEG_ADX_H +#define FFMPEG_ADX_H + +typedef struct { + int s1,s2; +} PREV; + +typedef struct { + PREV prev[2]; + int header_parsed; + unsigned char dec_temp[18*2]; + int in_temp; +} ADXContext; + +#define BASEVOL 0x4000 +#define SCALE1 0x7298 +#define SCALE2 0x3350 + +#endif /* FFMPEG_ADX_H */ diff --git a/contrib/ffmpeg/libavcodec/adxdec.c b/contrib/ffmpeg/libavcodec/adxdec.c new file mode 100644 index 000000000..851badbee --- /dev/null +++ b/contrib/ffmpeg/libavcodec/adxdec.c @@ -0,0 +1,169 @@ +/* + * ADX ADPCM codecs + * Copyright (c) 2001,2003 BERO + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avcodec.h" +#include "adx.h" + +/** + * @file adx.c + * SEGA CRI adx codecs. + * + * Reference documents: + * http://ku-www.ss.titech.ac.jp/~yatsushi/adx.html + * adx2wav & wav2adx http://www.geocities.co.jp/Playtown/2004/ + */ + +/* 18 bytes <-> 32 samples */ + +static void adx_decode(short *out,const unsigned char *in,PREV *prev) +{ + int scale = AV_RB16(in); + int i; + int s0,s1,s2,d; + +// printf("%x ",scale); + + in+=2; + s1 = prev->s1; + s2 = prev->s2; + for(i=0;i<16;i++) { + d = in[i]; + // d>>=4; if (d&8) d-=16; + d = ((signed char)d >> 4); + s0 = (BASEVOL*d*scale + SCALE1*s1 - SCALE2*s2)>>14; + s2 = s1; + s1 = av_clip_int16(s0); + *out++=s1; + + d = in[i]; + //d&=15; if (d&8) d-=16; + d = ((signed char)(d<<4) >> 4); + s0 = (BASEVOL*d*scale + SCALE1*s1 - SCALE2*s2)>>14; + s2 = s1; + s1 = av_clip_int16(s0); + *out++=s1; + } + prev->s1 = s1; + prev->s2 = s2; + +} + +static void adx_decode_stereo(short *out,const unsigned char *in,PREV *prev) +{ + short tmp[32*2]; + int i; + + adx_decode(tmp ,in ,prev); + adx_decode(tmp+32,in+18,prev+1); + for(i=0;i<32;i++) { + out[i*2] = tmp[i]; + out[i*2+1] = tmp[i+32]; + } +} + +/* return data offset or 0 */ +static int adx_decode_header(AVCodecContext *avctx,const unsigned char *buf,size_t bufsize) +{ + int offset; + + if (buf[0]!=0x80) return 0; + offset = (AV_RB32(buf)^0x80000000)+4; + if (bufsizechannels = buf[7]; + avctx->sample_rate = AV_RB32(buf+8); + avctx->bit_rate = avctx->sample_rate*avctx->channels*18*8/32; + + return offset; +} + +static int adx_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf0, int buf_size) +{ + ADXContext *c = avctx->priv_data; + short *samples = data; + const uint8_t *buf = buf0; + int rest = buf_size; + + if (!c->header_parsed) { + int hdrsize = adx_decode_header(avctx,buf,rest); + if (hdrsize==0) return -1; + c->header_parsed = 1; + buf += hdrsize; + rest -= hdrsize; + } + + /* 18 bytes of data are expanded into 32*2 bytes of audio, + so guard against buffer overflows */ + if(rest/18 > *data_size/64) + rest = (*data_size/64) * 18; + + if (c->in_temp) { + int copysize = 18*avctx->channels - c->in_temp; + memcpy(c->dec_temp+c->in_temp,buf,copysize); + rest -= copysize; + buf += copysize; + if (avctx->channels==1) { + adx_decode(samples,c->dec_temp,c->prev); + samples += 32; + } else { + adx_decode_stereo(samples,c->dec_temp,c->prev); + samples += 32*2; + } + } + // + if (avctx->channels==1) { + while(rest>=18) { + adx_decode(samples,buf,c->prev); + rest-=18; + buf+=18; + samples+=32; + } + } else { + while(rest>=18*2) { + adx_decode_stereo(samples,buf,c->prev); + rest-=18*2; + buf+=18*2; + samples+=32*2; + } + } + // + c->in_temp = rest; + if (rest) { + memcpy(c->dec_temp,buf,rest); + buf+=rest; + } + *data_size = (uint8_t*)samples - (uint8_t*)data; +// printf("%d:%d ",buf-buf0,*data_size); fflush(stdout); + return buf-buf0; +} + +AVCodec adpcm_adx_decoder = { + "adpcm_adx", + CODEC_TYPE_AUDIO, + CODEC_ID_ADPCM_ADX, + sizeof(ADXContext), + NULL, + NULL, + NULL, + adx_decode_frame, +}; + diff --git a/contrib/ffmpeg/libavcodec/adxenc.c b/contrib/ffmpeg/libavcodec/adxenc.c new file mode 100644 index 000000000..4c3d74e3b --- /dev/null +++ b/contrib/ffmpeg/libavcodec/adxenc.c @@ -0,0 +1,193 @@ +/* + * ADX ADPCM codecs + * Copyright (c) 2001,2003 BERO + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avcodec.h" +#include "adx.h" + +/** + * @file adx.c + * SEGA CRI adx codecs. + * + * Reference documents: + * http://ku-www.ss.titech.ac.jp/~yatsushi/adx.html + * adx2wav & wav2adx http://www.geocities.co.jp/Playtown/2004/ + */ + +/* 18 bytes <-> 32 samples */ + +static void adx_encode(unsigned char *adx,const short *wav,PREV *prev) +{ + int scale; + int i; + int s0,s1,s2,d; + int max=0; + int min=0; + int data[32]; + + s1 = prev->s1; + s2 = prev->s2; + for(i=0;i<32;i++) { + s0 = wav[i]; + d = ((s0<<14) - SCALE1*s1 + SCALE2*s2)/BASEVOL; + data[i]=d; + if (maxd) min=d; + s2 = s1; + s1 = s0; + } + prev->s1 = s1; + prev->s2 = s2; + + /* -8..+7 */ + + if (max==0 && min==0) { + memset(adx,0,18); + return; + } + + if (max/7>-min/8) scale = max/7; + else scale = -min/8; + + if (scale==0) scale=1; + + AV_WB16(adx, scale); + + for(i=0;i<16;i++) { + adx[i+2] = ((data[i*2]/scale)<<4) | ((data[i*2+1]/scale)&0xf); + } +} + +static int adx_encode_header(AVCodecContext *avctx,unsigned char *buf,size_t bufsize) +{ +#if 0 + struct { + uint32_t offset; /* 0x80000000 + sample start - 4 */ + unsigned char unknown1[3]; /* 03 12 04 */ + unsigned char channel; /* 1 or 2 */ + uint32_t freq; + uint32_t size; + uint32_t unknown2; /* 01 f4 03 00 */ + uint32_t unknown3; /* 00 00 00 00 */ + uint32_t unknown4; /* 00 00 00 00 */ + + /* if loop + unknown3 00 15 00 01 + unknown4 00 00 00 01 + long loop_start_sample; + long loop_start_byte; + long loop_end_sample; + long loop_end_byte; + long + */ + } adxhdr; /* big endian */ + /* offset-6 "(c)CRI" */ +#endif + AV_WB32(buf+0x00,0x80000000|0x20); + AV_WB32(buf+0x04,0x03120400|avctx->channels); + AV_WB32(buf+0x08,avctx->sample_rate); + AV_WB32(buf+0x0c,0); /* FIXME: set after */ + AV_WB32(buf+0x10,0x01040300); + AV_WB32(buf+0x14,0x00000000); + AV_WB32(buf+0x18,0x00000000); + memcpy(buf+0x1c,"\0\0(c)CRI",8); + return 0x20+4; +} + +static int adx_encode_init(AVCodecContext *avctx) +{ + if (avctx->channels > 2) + return -1; /* only stereo or mono =) */ + avctx->frame_size = 32; + + avctx->coded_frame= avcodec_alloc_frame(); + avctx->coded_frame->key_frame= 1; + +// avctx->bit_rate = avctx->sample_rate*avctx->channels*18*8/32; + + av_log(avctx, AV_LOG_DEBUG, "adx encode init\n"); + + return 0; +} + +static int adx_encode_close(AVCodecContext *avctx) +{ + av_freep(&avctx->coded_frame); + + return 0; +} + +static int adx_encode_frame(AVCodecContext *avctx, + uint8_t *frame, int buf_size, void *data) +{ + ADXContext *c = avctx->priv_data; + const short *samples = data; + unsigned char *dst = frame; + int rest = avctx->frame_size; + +/* + input data size = + ffmpeg.c: do_audio_out() + frame_bytes = enc->frame_size * 2 * enc->channels; +*/ + +// printf("sz=%d ",buf_size); fflush(stdout); + if (!c->header_parsed) { + int hdrsize = adx_encode_header(avctx,dst,buf_size); + dst+=hdrsize; + c->header_parsed = 1; + } + + if (avctx->channels==1) { + while(rest>=32) { + adx_encode(dst,samples,c->prev); + dst+=18; + samples+=32; + rest-=32; + } + } else { + while(rest>=32*2) { + short tmpbuf[32*2]; + int i; + + for(i=0;i<32;i++) { + tmpbuf[i] = samples[i*2]; + tmpbuf[i+32] = samples[i*2+1]; + } + + adx_encode(dst,tmpbuf,c->prev); + adx_encode(dst+18,tmpbuf+32,c->prev+1); + dst+=18*2; + samples+=32*2; + rest-=32*2; + } + } + return dst-frame; +} + +AVCodec adpcm_adx_encoder = { + "adpcm_adx", + CODEC_TYPE_AUDIO, + CODEC_ID_ADPCM_ADX, + sizeof(ADXContext), + adx_encode_init, + adx_encode_frame, + adx_encode_close, + NULL, +}; diff --git a/contrib/ffmpeg/libavcodec/alac.c b/contrib/ffmpeg/libavcodec/alac.c index cc87c81e5..0689a46ef 100644 --- a/contrib/ffmpeg/libavcodec/alac.c +++ b/contrib/ffmpeg/libavcodec/alac.c @@ -1,7 +1,6 @@ /* * ALAC (Apple Lossless Audio Codec) decoder * Copyright (c) 2005 David Hammerton - * All rights reserved. * * This file is part of FFmpeg. * @@ -55,8 +54,11 @@ #include "avcodec.h" #include "bitstream.h" +#include "bytestream.h" +#include "unary.h" #define ALAC_EXTRADATA_SIZE 36 +#define MAX_CHANNELS 2 typedef struct { @@ -71,11 +73,9 @@ typedef struct { int bytespersample; /* buffers */ - int32_t *predicterror_buffer_a; - int32_t *predicterror_buffer_b; + int32_t *predicterror_buffer[MAX_CHANNELS]; - int32_t *outputsamples_buffer_a; - int32_t *outputsamples_buffer_b; + int32_t *outputsamples_buffer[MAX_CHANNELS]; /* stuff from setinfo */ uint32_t setinfo_max_samples_per_frame; /* 0x1000 = 4096 */ /* max samples per frame? */ @@ -86,8 +86,8 @@ typedef struct { uint8_t setinfo_rice_kmodifier; /* 0x0e */ uint8_t setinfo_7f; /* 0x02 */ uint16_t setinfo_80; /* 0x00ff */ - uint32_t setinfo_82; /* 0x000020e7 */ - uint32_t setinfo_86; /* 0x00069fe4 */ + uint32_t setinfo_82; /* 0x000020e7 */ /* max sample size?? */ + uint32_t setinfo_86; /* 0x00069fe4 */ /* bit rate (average)?? */ uint32_t setinfo_8a_rate; /* 0x0000ac44 */ /* end setinfo stuff */ @@ -95,16 +95,19 @@ typedef struct { static void allocate_buffers(ALACContext *alac) { - alac->predicterror_buffer_a = av_malloc(alac->setinfo_max_samples_per_frame * 4); - alac->predicterror_buffer_b = av_malloc(alac->setinfo_max_samples_per_frame * 4); + int chan; + for (chan = 0; chan < MAX_CHANNELS; chan++) { + alac->predicterror_buffer[chan] = + av_malloc(alac->setinfo_max_samples_per_frame * 4); - alac->outputsamples_buffer_a = av_malloc(alac->setinfo_max_samples_per_frame * 4); - alac->outputsamples_buffer_b = av_malloc(alac->setinfo_max_samples_per_frame * 4); + alac->outputsamples_buffer[chan] = + av_malloc(alac->setinfo_max_samples_per_frame * 4); + } } static int alac_set_info(ALACContext *alac) { - unsigned char *ptr = alac->avctx->extradata; + const unsigned char *ptr = alac->avctx->extradata; ptr += 4; /* size */ ptr += 4; /* alac */ @@ -114,39 +117,32 @@ static int alac_set_info(ALACContext *alac) av_log(alac->avctx, AV_LOG_ERROR, "setinfo_max_samples_per_frame too large\n"); return -1; } - alac->setinfo_max_samples_per_frame = AV_RB32(ptr); /* buffer size / 2 ? */ - ptr += 4; - alac->setinfo_7a = *ptr++; - alac->setinfo_sample_size = *ptr++; - alac->setinfo_rice_historymult = *ptr++; - alac->setinfo_rice_initialhistory = *ptr++; - alac->setinfo_rice_kmodifier = *ptr++; - alac->setinfo_7f = *ptr++; // channels? - alac->setinfo_80 = AV_RB16(ptr); - ptr += 2; - alac->setinfo_82 = AV_RB32(ptr); // max coded frame size - ptr += 4; - alac->setinfo_86 = AV_RB32(ptr); // bitrate ? - ptr += 4; - alac->setinfo_8a_rate = AV_RB32(ptr); // samplerate - ptr += 4; + + /* buffer size / 2 ? */ + alac->setinfo_max_samples_per_frame = bytestream_get_be32(&ptr); + alac->setinfo_7a = *ptr++; + alac->setinfo_sample_size = *ptr++; + alac->setinfo_rice_historymult = *ptr++; + alac->setinfo_rice_initialhistory = *ptr++; + alac->setinfo_rice_kmodifier = *ptr++; + /* channels? */ + alac->setinfo_7f = *ptr++; + alac->setinfo_80 = bytestream_get_be16(&ptr); + /* max coded frame size */ + alac->setinfo_82 = bytestream_get_be32(&ptr); + /* bitrate ? */ + alac->setinfo_86 = bytestream_get_be32(&ptr); + /* samplerate */ + alac->setinfo_8a_rate = bytestream_get_be32(&ptr); allocate_buffers(alac); return 0; } -/* hideously inefficient. could use a bitmask search, - * alternatively bsr on x86, - */ -static int count_leading_zeros(int32_t input) +static inline int count_leading_zeros(int32_t input) { - int i = 0; - while (!(0x80000000 & input) && i < 32) { - i++; - input = input << 1; - } - return i; + return 31-av_log2(input); } static void bastardized_rice_decompress(ALACContext *alac, @@ -164,18 +160,15 @@ static void bastardized_rice_decompress(ALACContext *alac, int sign_modifier = 0; for (output_count = 0; output_count < output_size; output_count++) { - int32_t x = 0; + int32_t x; int32_t x_modified; int32_t final_val; /* read x - number of 1s before 0 represent the rice */ - while (x <= 8 && get_bits1(&alac->gb)) { - x++; - } - + x = get_unary_0_9(&alac->gb); if (x > 8) { /* RICE THRESHOLD */ - /* use alternative encoding */ + /* use alternative encoding */ int32_t value; value = get_bits(&alac->gb, readsamplesize); @@ -186,7 +179,7 @@ static void bastardized_rice_decompress(ALACContext *alac, x = value; } else { - /* standard rice encoding */ + /* standard rice encoding */ int extrabits; int k; /* size of extra bits */ @@ -206,10 +199,9 @@ static void bastardized_rice_decompress(ALACContext *alac, if (extrabits > 1) { x += extrabits - 1; - get_bits(&alac->gb, k); - } else { - get_bits(&alac->gb, k - 1); - } + skip_bits(&alac->gb, k); + } else + skip_bits(&alac->gb, k - 1); } } @@ -222,8 +214,8 @@ static void bastardized_rice_decompress(ALACContext *alac, sign_modifier = 0; /* now update the history */ - history += (x_modified * rice_historymult) - - ((history * rice_historymult) >> 9); + history += x_modified * rice_historymult + - ((history * rice_historymult) >> 9); if (x_modified > 0xffff) history = 0xffff; @@ -234,10 +226,7 @@ static void bastardized_rice_decompress(ALACContext *alac, sign_modifier = 1; - x = 0; - while (x <= 8 && get_bits1(&alac->gb)) { - x++; - } + x = get_unary_0_9(&alac->gb); if (x > 8) { block_size = get_bits(&alac->gb, 16); @@ -256,16 +245,15 @@ static void bastardized_rice_decompress(ALACContext *alac, if (extrabits < 2) { x = 1 - extrabits; block_size += x; - get_bits(&alac->gb, k - 1); + skip_bits(&alac->gb, k - 1); } else { - get_bits(&alac->gb, k); + skip_bits(&alac->gb, k); } } if (block_size > 0) { memset(&output_buffer[output_count+1], 0, block_size * 4); output_count += block_size; - } if (block_size > 0xffff) @@ -276,12 +264,15 @@ static void bastardized_rice_decompress(ALACContext *alac, } } -#define SIGN_EXTENDED32(val, bits) ((val << (32 - bits)) >> (32 - bits)) +static inline int32_t extend_sign32(int32_t val, int bits) +{ + return (val << (32 - bits)) >> (32 - bits); +} -#define SIGN_ONLY(v) \ - ((v < 0) ? (-1) : \ - ((v > 0) ? (1) : \ - (0))) +static inline int sign_only(int v) +{ + return v ? FFSIGN(v) : 0; +} static void predictor_decompress_fir_adapt(int32_t *error_buffer, int32_t *buffer_out, @@ -297,7 +288,9 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer, *buffer_out = *error_buffer; if (!predictor_coef_num) { - if (output_size <= 1) return; + if (output_size <= 1) + return; + memcpy(buffer_out+1, error_buffer+1, (output_size-1) * 4); return; } @@ -306,53 +299,48 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer, /* second-best case scenario for fir decompression, * error describes a small difference from the previous sample only */ - if (output_size <= 1) return; + if (output_size <= 1) + return; for (i = 0; i < output_size - 1; i++) { int32_t prev_value; int32_t error_value; prev_value = buffer_out[i]; error_value = error_buffer[i+1]; - buffer_out[i+1] = SIGN_EXTENDED32((prev_value + error_value), readsamplesize); + buffer_out[i+1] = + extend_sign32((prev_value + error_value), readsamplesize); } return; } /* read warm-up samples */ - if (predictor_coef_num > 0) { - int i; + if (predictor_coef_num > 0) for (i = 0; i < predictor_coef_num; i++) { int32_t val; val = buffer_out[i] + error_buffer[i+1]; - - val = SIGN_EXTENDED32(val, readsamplesize); - + val = extend_sign32(val, readsamplesize); buffer_out[i+1] = val; } - } #if 0 /* 4 and 8 are very common cases (the only ones i've seen). these - * should be unrolled and optimised + * should be unrolled and optimized */ if (predictor_coef_num == 4) { - /* FIXME: optimised general case */ + /* FIXME: optimized general case */ return; } if (predictor_coef_table == 8) { - /* FIXME: optimised general case */ + /* FIXME: optimized general case */ return; } #endif - /* general case */ if (predictor_coef_num > 0) { - for (i = predictor_coef_num + 1; - i < output_size; - i++) { + for (i = predictor_coef_num + 1; i < output_size; i++) { int j; int sum = 0; int outval; @@ -366,7 +354,7 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer, outval = (1 << (predictor_quantitization-1)) + sum; outval = outval >> predictor_quantitization; outval = outval + buffer_out[0] + error_val; - outval = SIGN_EXTENDED32(outval, readsamplesize); + outval = extend_sign32(outval, readsamplesize); buffer_out[predictor_coef_num+1] = outval; @@ -375,7 +363,7 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer, while (predictor_num >= 0 && error_val > 0) { int val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num]; - int sign = SIGN_ONLY(val); + int sign = sign_only(val); predictor_coef_table[predictor_num] -= sign; @@ -391,7 +379,7 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer, while (predictor_num >= 0 && error_val < 0) { int val = buffer_out[0] - buffer_out[predictor_coef_num - predictor_num]; - int sign = - SIGN_ONLY(val); + int sign = - sign_only(val); predictor_coef_table[predictor_num] -= sign; @@ -409,32 +397,29 @@ static void predictor_decompress_fir_adapt(int32_t *error_buffer, } } -static void deinterlace_16(int32_t *buffer_a, int32_t *buffer_b, - int16_t *buffer_out, - int numchannels, int numsamples, - uint8_t interlacing_shift, - uint8_t interlacing_leftweight) +static void reconstruct_stereo_16(int32_t *buffer[MAX_CHANNELS], + int16_t *buffer_out, + int numchannels, int numsamples, + uint8_t interlacing_shift, + uint8_t interlacing_leftweight) { int i; - if (numsamples <= 0) return; + if (numsamples <= 0) + return; /* weighted interlacing */ if (interlacing_leftweight) { for (i = 0; i < numsamples; i++) { - int32_t difference, midright; - int16_t left; - int16_t right; - - midright = buffer_a[i]; - difference = buffer_b[i]; + int32_t a, b; + a = buffer[0][i]; + b = buffer[1][i]; - right = midright - ((difference * interlacing_leftweight) >> interlacing_shift); - left = (midright - ((difference * interlacing_leftweight) >> interlacing_shift)) - + difference; + a -= (b * interlacing_leftweight) >> interlacing_shift; + b += a; - buffer_out[i*numchannels] = left; - buffer_out[i*numchannels + 1] = right; + buffer_out[i*numchannels] = b; + buffer_out[i*numchannels + 1] = a; } return; @@ -444,8 +429,8 @@ static void deinterlace_16(int32_t *buffer_a, int32_t *buffer_b, for (i = 0; i < numsamples; i++) { int16_t left, right; - left = buffer_a[i]; - right = buffer_b[i]; + left = buffer[0][i]; + right = buffer[1][i]; buffer_out[i*numchannels] = left; buffer_out[i*numchannels + 1] = right; @@ -454,12 +439,18 @@ static void deinterlace_16(int32_t *buffer_a, int32_t *buffer_b, static int alac_decode_frame(AVCodecContext *avctx, void *outbuffer, int *outputsize, - uint8_t *inbuffer, int input_buffer_size) + const uint8_t *inbuffer, int input_buffer_size) { ALACContext *alac = avctx->priv_data; int channels; int32_t outputsamples; + int hassize; + int readsamplesize; + int wasted_bytes; + int isnotcompressed; + uint8_t interlacing_shift; + uint8_t interlacing_leftweight; /* short-circuit null buffers */ if (!inbuffer || !input_buffer_size) @@ -479,118 +470,111 @@ static int alac_decode_frame(AVCodecContext *avctx, alac->context_initialized = 1; } - outputsamples = alac->setinfo_max_samples_per_frame; - init_get_bits(&alac->gb, inbuffer, input_buffer_size * 8); - channels = get_bits(&alac->gb, 3); - - *outputsize = outputsamples * alac->bytespersample; - - switch(channels) { - case 0: { /* 1 channel */ - int hassize; - int isnotcompressed; - int readsamplesize; - - int wasted_bytes; - int ricemodifier; - + channels = get_bits(&alac->gb, 3) + 1; + if (channels > MAX_CHANNELS) { + av_log(avctx, AV_LOG_ERROR, "channels > %d not supported\n", + MAX_CHANNELS); + return input_buffer_size; + } - /* 2^result = something to do with output waiting. - * perhaps matters if we read > 1 frame in a pass? - */ - get_bits(&alac->gb, 4); + /* 2^result = something to do with output waiting. + * perhaps matters if we read > 1 frame in a pass? + */ + skip_bits(&alac->gb, 4); - get_bits(&alac->gb, 12); /* unknown, skip 12 bits */ + skip_bits(&alac->gb, 12); /* unknown, skip 12 bits */ - hassize = get_bits(&alac->gb, 1); /* the output sample size is stored soon */ + /* the output sample size is stored soon */ + hassize = get_bits1(&alac->gb); - wasted_bytes = get_bits(&alac->gb, 2); /* unknown ? */ + wasted_bytes = get_bits(&alac->gb, 2); /* unknown ? */ - isnotcompressed = get_bits(&alac->gb, 1); /* whether the frame is compressed */ + /* whether the frame is compressed */ + isnotcompressed = get_bits1(&alac->gb); - if (hassize) { - /* now read the number of samples, - * as a 32bit integer */ - outputsamples = get_bits(&alac->gb, 32); - *outputsize = outputsamples * alac->bytespersample; - } + if (hassize) { + /* now read the number of samples as a 32bit integer */ + outputsamples = get_bits(&alac->gb, 32); + } else + outputsamples = alac->setinfo_max_samples_per_frame; - readsamplesize = alac->setinfo_sample_size - (wasted_bytes * 8); + *outputsize = outputsamples * alac->bytespersample; + readsamplesize = alac->setinfo_sample_size - (wasted_bytes * 8) + channels - 1; - if (!isnotcompressed) { - /* so it is compressed */ - int16_t predictor_coef_table[32]; - int predictor_coef_num; - int prediction_type; - int prediction_quantitization; - int i; + if (!isnotcompressed) { + /* so it is compressed */ + int16_t predictor_coef_table[channels][32]; + int predictor_coef_num[channels]; + int prediction_type[channels]; + int prediction_quantitization[channels]; + int ricemodifier[channels]; + int i, chan; - /* FIXME: skip 16 bits, not sure what they are. seem to be used in - * two channel case */ - get_bits(&alac->gb, 8); - get_bits(&alac->gb, 8); + interlacing_shift = get_bits(&alac->gb, 8); + interlacing_leftweight = get_bits(&alac->gb, 8); - prediction_type = get_bits(&alac->gb, 4); - prediction_quantitization = get_bits(&alac->gb, 4); + for (chan = 0; chan < channels; chan++) { + prediction_type[chan] = get_bits(&alac->gb, 4); + prediction_quantitization[chan] = get_bits(&alac->gb, 4); - ricemodifier = get_bits(&alac->gb, 3); - predictor_coef_num = get_bits(&alac->gb, 5); + ricemodifier[chan] = get_bits(&alac->gb, 3); + predictor_coef_num[chan] = get_bits(&alac->gb, 5); /* read the predictor table */ - for (i = 0; i < predictor_coef_num; i++) { - predictor_coef_table[i] = (int16_t)get_bits(&alac->gb, 16); - } + for (i = 0; i < predictor_coef_num[chan]; i++) + predictor_coef_table[chan][i] = (int16_t)get_bits(&alac->gb, 16); + } - if (wasted_bytes) { - /* these bytes seem to have something to do with - * > 2 channel files. - */ - av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented, unhandling of wasted_bytes\n"); - } + if (wasted_bytes) + av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented, unhandling of wasted_bytes\n"); + for (chan = 0; chan < channels; chan++) { bastardized_rice_decompress(alac, - alac->predicterror_buffer_a, + alac->predicterror_buffer[chan], outputsamples, readsamplesize, alac->setinfo_rice_initialhistory, alac->setinfo_rice_kmodifier, - ricemodifier * alac->setinfo_rice_historymult / 4, + ricemodifier[chan] * alac->setinfo_rice_historymult / 4, (1 << alac->setinfo_rice_kmodifier) - 1); - if (prediction_type == 0) { - /* adaptive fir */ - predictor_decompress_fir_adapt(alac->predicterror_buffer_a, - alac->outputsamples_buffer_a, + if (prediction_type[chan] == 0) { + /* adaptive fir */ + predictor_decompress_fir_adapt(alac->predicterror_buffer[chan], + alac->outputsamples_buffer[chan], outputsamples, readsamplesize, - predictor_coef_table, - predictor_coef_num, - prediction_quantitization); + predictor_coef_table[chan], + predictor_coef_num[chan], + prediction_quantitization[chan]); } else { - av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type); - /* i think the only other prediction type (or perhaps this is just a - * boolean?) runs adaptive fir twice.. like: + av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type[chan]); + /* I think the only other prediction type (or perhaps this is + * just a boolean?) runs adaptive fir twice.. like: * predictor_decompress_fir_adapt(predictor_error, tempout, ...) * predictor_decompress_fir_adapt(predictor_error, outputsamples ...) * little strange.. */ } - - } else { - /* not compressed, easy case */ - if (readsamplesize <= 16) { - int i; + } + } else { + /* not compressed, easy case */ + if (alac->setinfo_sample_size <= 16) { + int i, chan; + for (chan = 0; chan < channels; chan++) for (i = 0; i < outputsamples; i++) { - int32_t audiobits = get_bits(&alac->gb, readsamplesize); + int32_t audiobits; - audiobits = SIGN_EXTENDED32(audiobits, readsamplesize); + audiobits = get_bits(&alac->gb, alac->setinfo_sample_size); + audiobits = extend_sign32(audiobits, readsamplesize); - alac->outputsamples_buffer_a[i] = audiobits; + alac->outputsamples_buffer[chan][i] = audiobits; } - } else { - int i; + } else { + int i, chan; + for (chan = 0; chan < channels; chan++) for (i = 0; i < outputsamples; i++) { int32_t audiobits; @@ -598,224 +582,43 @@ static int alac_decode_frame(AVCodecContext *avctx, /* special case of sign extension.. * as we'll be ORing the low 16bits into this */ audiobits = audiobits << 16; - audiobits = audiobits >> (32 - readsamplesize); - - audiobits |= get_bits(&alac->gb, readsamplesize - 16); + audiobits = audiobits >> (32 - alac->setinfo_sample_size); + audiobits |= get_bits(&alac->gb, alac->setinfo_sample_size - 16); - alac->outputsamples_buffer_a[i] = audiobits; + alac->outputsamples_buffer[chan][i] = audiobits; } - } - /* wasted_bytes = 0; // unused */ } + /* wasted_bytes = 0; */ + interlacing_shift = 0; + interlacing_leftweight = 0; + } - switch(alac->setinfo_sample_size) { - case 16: { + switch(alac->setinfo_sample_size) { + case 16: + if (channels == 2) { + reconstruct_stereo_16(alac->outputsamples_buffer, + (int16_t*)outbuffer, + alac->numchannels, + outputsamples, + interlacing_shift, + interlacing_leftweight); + } else { int i; for (i = 0; i < outputsamples; i++) { - int16_t sample = alac->outputsamples_buffer_a[i]; + int16_t sample = alac->outputsamples_buffer[0][i]; ((int16_t*)outbuffer)[i * alac->numchannels] = sample; } - break; - } - case 20: - case 24: - case 32: - av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented sample size %i\n", alac->setinfo_sample_size); - break; - default: - break; } break; - } - case 1: { /* 2 channels */ - int hassize; - int isnotcompressed; - int readsamplesize; - - int wasted_bytes; - - uint8_t interlacing_shift; - uint8_t interlacing_leftweight; - - /* 2^result = something to do with output waiting. - * perhaps matters if we read > 1 frame in a pass? - */ - get_bits(&alac->gb, 4); - - get_bits(&alac->gb, 12); /* unknown, skip 12 bits */ - - hassize = get_bits(&alac->gb, 1); /* the output sample size is stored soon */ - - wasted_bytes = get_bits(&alac->gb, 2); /* unknown ? */ - - isnotcompressed = get_bits(&alac->gb, 1); /* whether the frame is compressed */ - - if (hassize) { - /* now read the number of samples, - * as a 32bit integer */ - outputsamples = get_bits(&alac->gb, 32); - *outputsize = outputsamples * alac->bytespersample; - } - - readsamplesize = alac->setinfo_sample_size - (wasted_bytes * 8) + 1; - - if (!isnotcompressed) { - /* compressed */ - int16_t predictor_coef_table_a[32]; - int predictor_coef_num_a; - int prediction_type_a; - int prediction_quantitization_a; - int ricemodifier_a; - - int16_t predictor_coef_table_b[32]; - int predictor_coef_num_b; - int prediction_type_b; - int prediction_quantitization_b; - int ricemodifier_b; - - int i; - - interlacing_shift = get_bits(&alac->gb, 8); - interlacing_leftweight = get_bits(&alac->gb, 8); - - /******** channel 1 ***********/ - prediction_type_a = get_bits(&alac->gb, 4); - prediction_quantitization_a = get_bits(&alac->gb, 4); - - ricemodifier_a = get_bits(&alac->gb, 3); - predictor_coef_num_a = get_bits(&alac->gb, 5); - - /* read the predictor table */ - for (i = 0; i < predictor_coef_num_a; i++) { - predictor_coef_table_a[i] = (int16_t)get_bits(&alac->gb, 16); - } - - /******** channel 2 *********/ - prediction_type_b = get_bits(&alac->gb, 4); - prediction_quantitization_b = get_bits(&alac->gb, 4); - - ricemodifier_b = get_bits(&alac->gb, 3); - predictor_coef_num_b = get_bits(&alac->gb, 5); - - /* read the predictor table */ - for (i = 0; i < predictor_coef_num_b; i++) { - predictor_coef_table_b[i] = (int16_t)get_bits(&alac->gb, 16); - } - - /*********************/ - if (wasted_bytes) { - /* see mono case */ - av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented, unhandling of wasted_bytes\n"); - } - - /* channel 1 */ - bastardized_rice_decompress(alac, - alac->predicterror_buffer_a, - outputsamples, - readsamplesize, - alac->setinfo_rice_initialhistory, - alac->setinfo_rice_kmodifier, - ricemodifier_a * alac->setinfo_rice_historymult / 4, - (1 << alac->setinfo_rice_kmodifier) - 1); - - if (prediction_type_a == 0) { - /* adaptive fir */ - predictor_decompress_fir_adapt(alac->predicterror_buffer_a, - alac->outputsamples_buffer_a, - outputsamples, - readsamplesize, - predictor_coef_table_a, - predictor_coef_num_a, - prediction_quantitization_a); - } else { - /* see mono case */ - av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type_a); - } - - /* channel 2 */ - bastardized_rice_decompress(alac, - alac->predicterror_buffer_b, - outputsamples, - readsamplesize, - alac->setinfo_rice_initialhistory, - alac->setinfo_rice_kmodifier, - ricemodifier_b * alac->setinfo_rice_historymult / 4, - (1 << alac->setinfo_rice_kmodifier) - 1); - - if (prediction_type_b == 0) { - /* adaptive fir */ - predictor_decompress_fir_adapt(alac->predicterror_buffer_b, - alac->outputsamples_buffer_b, - outputsamples, - readsamplesize, - predictor_coef_table_b, - predictor_coef_num_b, - prediction_quantitization_b); - } else { - av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type_b); - } - } else { - /* not compressed, easy case */ - if (alac->setinfo_sample_size <= 16) { - int i; - for (i = 0; i < outputsamples; i++) { - int32_t audiobits_a, audiobits_b; - - audiobits_a = get_bits(&alac->gb, alac->setinfo_sample_size); - audiobits_b = get_bits(&alac->gb, alac->setinfo_sample_size); - - audiobits_a = SIGN_EXTENDED32(audiobits_a, alac->setinfo_sample_size); - audiobits_b = SIGN_EXTENDED32(audiobits_b, alac->setinfo_sample_size); - - alac->outputsamples_buffer_a[i] = audiobits_a; - alac->outputsamples_buffer_b[i] = audiobits_b; - } - } else { - int i; - for (i = 0; i < outputsamples; i++) { - int32_t audiobits_a, audiobits_b; - - audiobits_a = get_bits(&alac->gb, 16); - audiobits_a = audiobits_a << 16; - audiobits_a = audiobits_a >> (32 - alac->setinfo_sample_size); - audiobits_a |= get_bits(&alac->gb, alac->setinfo_sample_size - 16); - - audiobits_b = get_bits(&alac->gb, 16); - audiobits_b = audiobits_b << 16; - audiobits_b = audiobits_b >> (32 - alac->setinfo_sample_size); - audiobits_b |= get_bits(&alac->gb, alac->setinfo_sample_size - 16); - - alac->outputsamples_buffer_a[i] = audiobits_a; - alac->outputsamples_buffer_b[i] = audiobits_b; - } - } - /* wasted_bytes = 0; */ - interlacing_shift = 0; - interlacing_leftweight = 0; - } - - switch(alac->setinfo_sample_size) { - case 16: { - deinterlace_16(alac->outputsamples_buffer_a, - alac->outputsamples_buffer_b, - (int16_t*)outbuffer, - alac->numchannels, - outputsamples, - interlacing_shift, - interlacing_leftweight); - break; - } - case 20: - case 24: - case 32: - av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented sample size %i\n", alac->setinfo_sample_size); - break; - default: - break; - } - + case 20: + case 24: + // It is not clear if there exist any encoder that creates 24 bit ALAC + // files. iTunes convert 24 bit raw files to 16 bit before encoding. + case 32: + av_log(avctx, AV_LOG_ERROR, "FIXME: unimplemented sample size %i\n", alac->setinfo_sample_size); + break; + default: break; - } } return input_buffer_size; @@ -838,11 +641,11 @@ static int alac_decode_close(AVCodecContext *avctx) { ALACContext *alac = avctx->priv_data; - av_free(alac->predicterror_buffer_a); - av_free(alac->predicterror_buffer_b); - - av_free(alac->outputsamples_buffer_a); - av_free(alac->outputsamples_buffer_b); + int chan; + for (chan = 0; chan < MAX_CHANNELS; chan++) { + av_free(alac->predicterror_buffer[chan]); + av_free(alac->outputsamples_buffer[chan]); + } return 0; } diff --git a/contrib/ffmpeg/libavcodec/allcodecs.c b/contrib/ffmpeg/libavcodec/allcodecs.c index b247cbe34..9bb35fa97 100644 --- a/contrib/ffmpeg/libavcodec/allcodecs.c +++ b/contrib/ffmpeg/libavcodec/allcodecs.c @@ -26,14 +26,20 @@ #include "avcodec.h" -#define REGISTER_ENCODER(X,x) \ - if(ENABLE_##X##_ENCODER) register_avcodec(&x##_encoder) -#define REGISTER_DECODER(X,x) \ - if(ENABLE_##X##_DECODER) register_avcodec(&x##_decoder) +#define REGISTER_ENCODER(X,x) { \ + extern AVCodec x##_encoder; \ + if(ENABLE_##X##_ENCODER) register_avcodec(&x##_encoder); } +#define REGISTER_DECODER(X,x) { \ + extern AVCodec x##_decoder; \ + if(ENABLE_##X##_DECODER) register_avcodec(&x##_decoder); } #define REGISTER_ENCDEC(X,x) REGISTER_ENCODER(X,x); REGISTER_DECODER(X,x) -#define REGISTER_PARSER(X,x) \ - if(ENABLE_##X##_PARSER) av_register_codec_parser(&x##_parser) +#define REGISTER_PARSER(X,x) { \ + extern AVCodecParser x##_parser; \ + if(ENABLE_##X##_PARSER) av_register_codec_parser(&x##_parser); } +#define REGISTER_BSF(X,x) { \ + extern AVBitStreamFilter x##_bsf; \ + if(ENABLE_##X##_BSF) av_register_bitstream_filter(&x##_bsf); } /** * Register all the codecs, parsers and bitstream filters which were enabled at @@ -47,231 +53,261 @@ */ void avcodec_register_all(void) { - static int inited = 0; + static int initialized; - if (inited != 0) + if (initialized) return; - inited = 1; + initialized = 1; /* video codecs */ - REGISTER_DECODER(AASC, aasc); - REGISTER_ENCDEC (ASV1, asv1); - REGISTER_ENCDEC (ASV2, asv2); - REGISTER_DECODER(AVS, avs); - REGISTER_ENCDEC (BMP, bmp); - REGISTER_DECODER(CAVS, cavs); - REGISTER_DECODER(CINEPAK, cinepak); - REGISTER_DECODER(CLJR, cljr); - REGISTER_DECODER(CSCD, cscd); - REGISTER_DECODER(CYUV, cyuv); - REGISTER_DECODER(DCA, dca); - REGISTER_DECODER(DNXHD, dnxhd); - REGISTER_DECODER(DSICINVIDEO, dsicinvideo); - REGISTER_ENCDEC (DVVIDEO, dvvideo); - REGISTER_DECODER(DXA, dxa); - REGISTER_DECODER(EIGHTBPS, eightbps); - REGISTER_ENCDEC (FFV1, ffv1); - REGISTER_ENCDEC (FFVHUFF, ffvhuff); - REGISTER_ENCDEC (FLASHSV, flashsv); - REGISTER_DECODER(FLIC, flic); - REGISTER_ENCDEC (FLV, flv); - REGISTER_DECODER(FOURXM, fourxm); - REGISTER_DECODER(FRAPS, fraps); - REGISTER_ENCDEC (GIF, gif); - REGISTER_ENCDEC (H261, h261); - REGISTER_ENCDEC (H263, h263); - REGISTER_DECODER(H263I, h263i); - REGISTER_ENCODER(H263P, h263p); - REGISTER_DECODER(H264, h264); - REGISTER_ENCDEC (HUFFYUV, huffyuv); - REGISTER_DECODER(IDCIN, idcin); - REGISTER_DECODER(INDEO2, indeo2); - REGISTER_DECODER(INDEO3, indeo3); - REGISTER_DECODER(INTERPLAY_VIDEO, interplay_video); - REGISTER_ENCODER(JPEGLS, jpegls); - REGISTER_DECODER(KMVC, kmvc); - REGISTER_ENCODER(LJPEG, ljpeg); - REGISTER_DECODER(LOCO, loco); - REGISTER_DECODER(MDEC, mdec); - REGISTER_ENCDEC (MJPEG, mjpeg); - REGISTER_DECODER(MJPEGB, mjpegb); - REGISTER_DECODER(MMVIDEO, mmvideo); - REGISTER_DECODER(MPEG_XVMC, mpeg_xvmc); - REGISTER_ENCDEC (MPEG1VIDEO, mpeg1video); - REGISTER_ENCDEC (MPEG2VIDEO, mpeg2video); - REGISTER_ENCDEC (MPEG4, mpeg4); - REGISTER_DECODER(MPEGVIDEO, mpegvideo); - REGISTER_ENCDEC (MSMPEG4V1, msmpeg4v1); - REGISTER_ENCDEC (MSMPEG4V2, msmpeg4v2); - REGISTER_ENCDEC (MSMPEG4V3, msmpeg4v3); - REGISTER_DECODER(MSRLE, msrle); - REGISTER_DECODER(MSVIDEO1, msvideo1); - REGISTER_DECODER(MSZH, mszh); - REGISTER_DECODER(NUV, nuv); - REGISTER_ENCODER(PAM, pam); - REGISTER_ENCODER(PBM, pbm); - REGISTER_ENCODER(PGM, pgm); - REGISTER_ENCODER(PGMYUV, pgmyuv); - REGISTER_ENCDEC (PNG, png); - REGISTER_ENCODER(PPM, ppm); - REGISTER_DECODER(QDRAW, qdraw); - REGISTER_DECODER(QPEG, qpeg); - REGISTER_DECODER(QTRLE, qtrle); - REGISTER_ENCDEC (RAWVIDEO, rawvideo); - REGISTER_DECODER(ROQ, roq); - REGISTER_DECODER(RPZA, rpza); - REGISTER_ENCDEC (RV10, rv10); - REGISTER_ENCDEC (RV20, rv20); - REGISTER_DECODER(SMACKER, smacker); - REGISTER_DECODER(SMC, smc); - REGISTER_ENCDEC (SNOW, snow); - REGISTER_DECODER(SP5X, sp5x); - REGISTER_ENCDEC (SVQ1, svq1); - REGISTER_DECODER(SVQ3, svq3); - REGISTER_ENCDEC (TARGA, targa); - REGISTER_DECODER(THEORA, theora); - REGISTER_DECODER(THP, thp); - REGISTER_DECODER(TIERTEXSEQVIDEO, tiertexseqvideo); - REGISTER_DECODER(TIFF, tiff); - REGISTER_DECODER(TRUEMOTION1, truemotion1); - REGISTER_DECODER(TRUEMOTION2, truemotion2); - REGISTER_DECODER(TSCC, tscc); - REGISTER_DECODER(ULTI, ulti); - REGISTER_DECODER(VC1, vc1); - REGISTER_DECODER(VCR1, vcr1); - REGISTER_DECODER(VMDVIDEO, vmdvideo); - REGISTER_DECODER(VMNC, vmnc); - REGISTER_DECODER(VP3, vp3); - REGISTER_DECODER(VP5, vp5); - REGISTER_DECODER(VP6, vp6); - REGISTER_DECODER(VP6F, vp6f); - REGISTER_DECODER(VQA, vqa); - REGISTER_ENCDEC (WMV1, wmv1); - REGISTER_ENCDEC (WMV2, wmv2); - REGISTER_DECODER(WMV3, wmv3); - REGISTER_DECODER(WNV1, wnv1); - REGISTER_ENCODER(X264, x264); - REGISTER_DECODER(XAN_WC3, xan_wc3); - REGISTER_DECODER(XL, xl); - REGISTER_ENCODER(XVID, xvid); - REGISTER_ENCDEC (ZLIB, zlib); - REGISTER_ENCDEC (ZMBV, zmbv); + REGISTER_DECODER (AASC, aasc); + REGISTER_DECODER (AMV, amv); + REGISTER_ENCDEC (ASV1, asv1); + REGISTER_ENCDEC (ASV2, asv2); + REGISTER_DECODER (AVS, avs); + REGISTER_DECODER (BETHSOFTVID, bethsoftvid); + REGISTER_ENCDEC (BMP, bmp); + REGISTER_DECODER (C93, c93); + REGISTER_DECODER (CAVS, cavs); + REGISTER_DECODER (CINEPAK, cinepak); + REGISTER_DECODER (CLJR, cljr); + REGISTER_DECODER (CSCD, cscd); + REGISTER_DECODER (CYUV, cyuv); + REGISTER_ENCDEC (DNXHD, dnxhd); + REGISTER_DECODER (DSICINVIDEO, dsicinvideo); + REGISTER_ENCDEC (DVVIDEO, dvvideo); + REGISTER_DECODER (DXA, dxa); + REGISTER_DECODER (EIGHTBPS, eightbps); + REGISTER_ENCDEC (FFV1, ffv1); + REGISTER_ENCDEC (FFVHUFF, ffvhuff); + REGISTER_ENCDEC (FLASHSV, flashsv); + REGISTER_DECODER (FLIC, flic); + REGISTER_ENCDEC (FLV, flv); + REGISTER_DECODER (FOURXM, fourxm); + REGISTER_DECODER (FRAPS, fraps); + REGISTER_ENCDEC (GIF, gif); + REGISTER_ENCDEC (H261, h261); + REGISTER_ENCDEC (H263, h263); + REGISTER_DECODER (H263I, h263i); + REGISTER_ENCODER (H263P, h263p); + REGISTER_DECODER (H264, h264); + REGISTER_ENCDEC (HUFFYUV, huffyuv); + REGISTER_DECODER (IDCIN, idcin); + REGISTER_DECODER (INDEO2, indeo2); + REGISTER_DECODER (INDEO3, indeo3); + REGISTER_DECODER (INTERPLAY_VIDEO, interplay_video); + REGISTER_ENCDEC (JPEGLS, jpegls); + REGISTER_DECODER (KMVC, kmvc); + REGISTER_ENCODER (LJPEG, ljpeg); + REGISTER_DECODER (LOCO, loco); + REGISTER_DECODER (MDEC, mdec); + REGISTER_ENCDEC (MJPEG, mjpeg); + REGISTER_DECODER (MJPEGB, mjpegb); + REGISTER_DECODER (MMVIDEO, mmvideo); + REGISTER_DECODER (MPEG_XVMC, mpeg_xvmc); + REGISTER_ENCDEC (MPEG1VIDEO, mpeg1video); + REGISTER_ENCDEC (MPEG2VIDEO, mpeg2video); + REGISTER_ENCDEC (MPEG4, mpeg4); + REGISTER_DECODER (MPEGVIDEO, mpegvideo); + REGISTER_ENCDEC (MSMPEG4V1, msmpeg4v1); + REGISTER_ENCDEC (MSMPEG4V2, msmpeg4v2); + REGISTER_ENCDEC (MSMPEG4V3, msmpeg4v3); + REGISTER_DECODER (MSRLE, msrle); + REGISTER_DECODER (MSVIDEO1, msvideo1); + REGISTER_DECODER (MSZH, mszh); + REGISTER_DECODER (NUV, nuv); + REGISTER_ENCODER (PAM, pam); + REGISTER_ENCODER (PBM, pbm); + REGISTER_DECODER (PCX, pcx); + REGISTER_ENCODER (PGM, pgm); + REGISTER_ENCODER (PGMYUV, pgmyuv); + REGISTER_ENCDEC (PNG, png); + REGISTER_ENCODER (PPM, ppm); + REGISTER_DECODER (PTX, ptx); + REGISTER_DECODER (QDRAW, qdraw); + REGISTER_DECODER (QPEG, qpeg); + REGISTER_ENCDEC (QTRLE, qtrle); + REGISTER_ENCDEC (RAWVIDEO, rawvideo); + REGISTER_ENCDEC (ROQ, roq); + REGISTER_DECODER (RPZA, rpza); + REGISTER_ENCDEC (RV10, rv10); + REGISTER_ENCDEC (RV20, rv20); + REGISTER_ENCDEC (SGI, sgi); + REGISTER_DECODER (SMACKER, smacker); + REGISTER_DECODER (SMC, smc); + REGISTER_ENCDEC (SNOW, snow); + REGISTER_DECODER (SP5X, sp5x); + REGISTER_DECODER (SUNRAST, sunrast); + REGISTER_ENCDEC (SVQ1, svq1); + REGISTER_DECODER (SVQ3, svq3); + REGISTER_ENCDEC (TARGA, targa); + REGISTER_DECODER (THEORA, theora); + REGISTER_DECODER (THP, thp); + REGISTER_DECODER (TIERTEXSEQVIDEO, tiertexseqvideo); + REGISTER_ENCDEC (TIFF, tiff); + REGISTER_DECODER (TRUEMOTION1, truemotion1); + REGISTER_DECODER (TRUEMOTION2, truemotion2); + REGISTER_DECODER (TSCC, tscc); + REGISTER_DECODER (TXD, txd); + REGISTER_DECODER (ULTI, ulti); + REGISTER_DECODER (VB, vb); + REGISTER_DECODER (VC1, vc1); + REGISTER_DECODER (VCR1, vcr1); + REGISTER_DECODER (VMDVIDEO, vmdvideo); + REGISTER_DECODER (VMNC, vmnc); + REGISTER_DECODER (VP3, vp3); + REGISTER_DECODER (VP5, vp5); + REGISTER_DECODER (VP6, vp6); + REGISTER_DECODER (VP6A, vp6a); + REGISTER_DECODER (VP6F, vp6f); + REGISTER_DECODER (VQA, vqa); + REGISTER_ENCDEC (WMV1, wmv1); + REGISTER_ENCDEC (WMV2, wmv2); + REGISTER_DECODER (WMV3, wmv3); + REGISTER_DECODER (WNV1, wnv1); + REGISTER_DECODER (XAN_WC3, xan_wc3); + REGISTER_DECODER (XL, xl); + REGISTER_DECODER (XSUB, xsub); + REGISTER_ENCDEC (ZLIB, zlib); + REGISTER_ENCDEC (ZMBV, zmbv); /* audio codecs */ - REGISTER_DECODER(AAC, aac); - REGISTER_DECODER(MPEG4AAC, mpeg4aac); - REGISTER_ENCODER(AC3, ac3); - REGISTER_DECODER(ALAC, alac); - REGISTER_ENCDEC (AMR_NB, amr_nb); - REGISTER_ENCDEC (AMR_WB, amr_wb); - REGISTER_DECODER(COOK, cook); - REGISTER_DECODER(DSICINAUDIO, dsicinaudio); - REGISTER_DECODER(DTS, dts); - REGISTER_ENCODER(FAAC, faac); - REGISTER_ENCDEC (FLAC, flac); - REGISTER_DECODER(IMC, imc); - REGISTER_DECODER(LIBA52, liba52); - REGISTER_ENCDEC (LIBGSM, libgsm); - REGISTER_ENCDEC (LIBGSM_MS, libgsm_ms); - REGISTER_ENCODER(LIBTHEORA, libtheora); - REGISTER_DECODER(MACE3, mace3); - REGISTER_DECODER(MACE6, mace6); - REGISTER_ENCDEC (MP2, mp2); - REGISTER_DECODER(MP3, mp3); - REGISTER_DECODER(MP3ADU, mp3adu); - REGISTER_ENCODER(MP3LAME, mp3lame); - REGISTER_DECODER(MP3ON4, mp3on4); - REGISTER_DECODER(MPC7, mpc7); - if (!ENABLE_VORBIS_ENCODER) REGISTER_ENCODER(OGGVORBIS, oggvorbis); - if (!ENABLE_VORBIS_DECODER) REGISTER_DECODER(OGGVORBIS, oggvorbis); - REGISTER_DECODER(QDM2, qdm2); - REGISTER_DECODER(RA_144, ra_144); - REGISTER_DECODER(RA_288, ra_288); - REGISTER_DECODER(SHORTEN, shorten); - REGISTER_DECODER(SMACKAUD, smackaud); - REGISTER_ENCDEC (SONIC, sonic); - REGISTER_ENCODER(SONIC_LS, sonic_ls); - REGISTER_DECODER(TRUESPEECH, truespeech); - REGISTER_DECODER(TTA, tta); - REGISTER_DECODER(VMDAUDIO, vmdaudio); - REGISTER_ENCDEC (VORBIS, vorbis); - REGISTER_DECODER(WAVPACK, wavpack); - REGISTER_ENCDEC(WMAV1, wmav1); - REGISTER_ENCDEC(WMAV2, wmav2); - REGISTER_DECODER(WS_SND1, ws_snd1); + REGISTER_DECODER (MPEG4AAC, mpeg4aac); + REGISTER_ENCDEC (AC3, ac3); + REGISTER_DECODER (ALAC, alac); + REGISTER_DECODER (APE, ape); + REGISTER_DECODER (ATRAC3, atrac3); + REGISTER_DECODER (COOK, cook); + REGISTER_DECODER (DCA, dca); + REGISTER_DECODER (DSICINAUDIO, dsicinaudio); + REGISTER_ENCDEC (FLAC, flac); + REGISTER_DECODER (IMC, imc); + REGISTER_DECODER (MACE3, mace3); + REGISTER_DECODER (MACE6, mace6); + REGISTER_ENCDEC (MP2, mp2); + REGISTER_DECODER (MP3, mp3); + REGISTER_DECODER (MP3ADU, mp3adu); + REGISTER_DECODER (MP3ON4, mp3on4); + REGISTER_DECODER (MPC7, mpc7); + REGISTER_DECODER (MPC8, mpc8); + REGISTER_DECODER (NELLYMOSER, nellymoser); + REGISTER_DECODER (QDM2, qdm2); + REGISTER_DECODER (RA_144, ra_144); + REGISTER_DECODER (RA_288, ra_288); + REGISTER_DECODER (SHORTEN, shorten); + REGISTER_DECODER (SMACKAUD, smackaud); + REGISTER_ENCDEC (SONIC, sonic); + REGISTER_ENCODER (SONIC_LS, sonic_ls); + REGISTER_DECODER (TRUESPEECH, truespeech); + REGISTER_DECODER (TTA, tta); + REGISTER_DECODER (VMDAUDIO, vmdaudio); + REGISTER_ENCDEC (VORBIS, vorbis); + REGISTER_DECODER (WAVPACK, wavpack); + REGISTER_ENCDEC (WMAV1, wmav1); + REGISTER_ENCDEC (WMAV2, wmav2); + REGISTER_DECODER (WS_SND1, ws_snd1); /* pcm codecs */ - REGISTER_ENCDEC (PCM_ALAW, pcm_alaw); - REGISTER_ENCDEC (PCM_MULAW, pcm_mulaw); - REGISTER_ENCDEC (PCM_S8, pcm_s8); - REGISTER_ENCDEC (PCM_S16BE, pcm_s16be); - REGISTER_ENCDEC (PCM_S16LE, pcm_s16le); - REGISTER_ENCDEC (PCM_S24BE, pcm_s24be); - REGISTER_ENCDEC (PCM_S24DAUD, pcm_s24daud); - REGISTER_ENCDEC (PCM_S24LE, pcm_s24le); - REGISTER_ENCDEC (PCM_S32BE, pcm_s32be); - REGISTER_ENCDEC (PCM_S32LE, pcm_s32le); - REGISTER_ENCDEC (PCM_U8, pcm_u8); - REGISTER_ENCDEC (PCM_U16BE, pcm_u16be); - REGISTER_ENCDEC (PCM_U16LE, pcm_u16le); - REGISTER_ENCDEC (PCM_U24BE, pcm_u24be); - REGISTER_ENCDEC (PCM_U24LE, pcm_u24le); - REGISTER_ENCDEC (PCM_U32BE, pcm_u32be); - REGISTER_ENCDEC (PCM_U32LE, pcm_u32le); + REGISTER_ENCDEC (PCM_ALAW, pcm_alaw); + REGISTER_ENCDEC (PCM_MULAW, pcm_mulaw); + REGISTER_ENCDEC (PCM_S8, pcm_s8); + REGISTER_ENCDEC (PCM_S16BE, pcm_s16be); + REGISTER_ENCDEC (PCM_S16LE, pcm_s16le); + REGISTER_DECODER (PCM_S16LE_PLANAR, pcm_s16le_planar); + REGISTER_ENCDEC (PCM_S24BE, pcm_s24be); + REGISTER_ENCDEC (PCM_S24DAUD, pcm_s24daud); + REGISTER_ENCDEC (PCM_S24LE, pcm_s24le); + REGISTER_ENCDEC (PCM_S32BE, pcm_s32be); + REGISTER_ENCDEC (PCM_S32LE, pcm_s32le); + REGISTER_ENCDEC (PCM_U8, pcm_u8); + REGISTER_ENCDEC (PCM_U16BE, pcm_u16be); + REGISTER_ENCDEC (PCM_U16LE, pcm_u16le); + REGISTER_ENCDEC (PCM_U24BE, pcm_u24be); + REGISTER_ENCDEC (PCM_U24LE, pcm_u24le); + REGISTER_ENCDEC (PCM_U32BE, pcm_u32be); + REGISTER_ENCDEC (PCM_U32LE, pcm_u32le); + REGISTER_ENCDEC (PCM_ZORK , pcm_zork); /* dpcm codecs */ - REGISTER_DECODER(INTERPLAY_DPCM, interplay_dpcm); - REGISTER_DECODER(ROQ_DPCM, roq_dpcm); - REGISTER_DECODER(SOL_DPCM, sol_dpcm); - REGISTER_DECODER(XAN_DPCM, xan_dpcm); + REGISTER_DECODER (INTERPLAY_DPCM, interplay_dpcm); + REGISTER_ENCDEC (ROQ_DPCM, roq_dpcm); + REGISTER_DECODER (SOL_DPCM, sol_dpcm); + REGISTER_DECODER (XAN_DPCM, xan_dpcm); /* adpcm codecs */ - REGISTER_ENCDEC (ADPCM_4XM, adpcm_4xm); - REGISTER_ENCDEC (ADPCM_ADX, adpcm_adx); - REGISTER_ENCDEC (ADPCM_CT, adpcm_ct); - REGISTER_ENCDEC (ADPCM_EA, adpcm_ea); - REGISTER_ENCDEC (ADPCM_G726, adpcm_g726); - REGISTER_ENCDEC (ADPCM_IMA_DK3, adpcm_ima_dk3); - REGISTER_ENCDEC (ADPCM_IMA_DK4, adpcm_ima_dk4); - REGISTER_ENCDEC (ADPCM_IMA_QT, adpcm_ima_qt); - REGISTER_ENCDEC (ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg); - REGISTER_ENCDEC (ADPCM_IMA_WAV, adpcm_ima_wav); - REGISTER_ENCDEC (ADPCM_IMA_WS, adpcm_ima_ws); - REGISTER_ENCDEC (ADPCM_MS, adpcm_ms); - REGISTER_ENCDEC (ADPCM_SBPRO_2, adpcm_sbpro_2); - REGISTER_ENCDEC (ADPCM_SBPRO_3, adpcm_sbpro_3); - REGISTER_ENCDEC (ADPCM_SBPRO_4, adpcm_sbpro_4); - REGISTER_ENCDEC (ADPCM_SWF, adpcm_swf); - REGISTER_ENCDEC (ADPCM_XA, adpcm_xa); - REGISTER_ENCDEC (ADPCM_YAMAHA, adpcm_yamaha); + REGISTER_DECODER (ADPCM_4XM, adpcm_4xm); + REGISTER_ENCDEC (ADPCM_ADX, adpcm_adx); + REGISTER_DECODER (ADPCM_CT, adpcm_ct); + REGISTER_DECODER (ADPCM_EA, adpcm_ea); + REGISTER_DECODER (ADPCM_EA_R1, adpcm_ea_r1); + REGISTER_DECODER (ADPCM_EA_R2, adpcm_ea_r2); + REGISTER_DECODER (ADPCM_EA_R3, adpcm_ea_r3); + REGISTER_DECODER (ADPCM_EA_XAS, adpcm_ea_xas); + REGISTER_ENCDEC (ADPCM_G726, adpcm_g726); + REGISTER_DECODER (ADPCM_IMA_AMV, adpcm_ima_amv); + REGISTER_DECODER (ADPCM_IMA_DK3, adpcm_ima_dk3); + REGISTER_DECODER (ADPCM_IMA_DK4, adpcm_ima_dk4); + REGISTER_DECODER (ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs); + REGISTER_DECODER (ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead); + REGISTER_DECODER (ADPCM_IMA_QT, adpcm_ima_qt); + REGISTER_DECODER (ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg); + REGISTER_ENCDEC (ADPCM_IMA_WAV, adpcm_ima_wav); + REGISTER_DECODER (ADPCM_IMA_WS, adpcm_ima_ws); + REGISTER_ENCDEC (ADPCM_MS, adpcm_ms); + REGISTER_DECODER (ADPCM_SBPRO_2, adpcm_sbpro_2); + REGISTER_DECODER (ADPCM_SBPRO_3, adpcm_sbpro_3); + REGISTER_DECODER (ADPCM_SBPRO_4, adpcm_sbpro_4); + REGISTER_ENCDEC (ADPCM_SWF, adpcm_swf); + REGISTER_DECODER (ADPCM_THP, adpcm_thp); + REGISTER_DECODER (ADPCM_XA, adpcm_xa); + REGISTER_ENCDEC (ADPCM_YAMAHA, adpcm_yamaha); /* subtitles */ - REGISTER_ENCDEC (DVBSUB, dvbsub); - REGISTER_ENCDEC (DVDSUB, dvdsub); + REGISTER_ENCDEC (DVBSUB, dvbsub); + REGISTER_ENCDEC (DVDSUB, dvdsub); + + /* external libraries */ + REGISTER_DECODER (LIBA52, liba52); + REGISTER_ENCDEC (LIBAMR_NB, libamr_nb); + REGISTER_ENCDEC (LIBAMR_WB, libamr_wb); + REGISTER_ENCODER (LIBFAAC, libfaac); + REGISTER_DECODER (LIBFAAD, libfaad); + REGISTER_ENCDEC (LIBGSM, libgsm); + REGISTER_ENCDEC (LIBGSM_MS, libgsm_ms); + REGISTER_ENCODER (LIBMP3LAME, libmp3lame); + REGISTER_ENCODER (LIBTHEORA, libtheora); + REGISTER_ENCODER (LIBVORBIS, libvorbis); + REGISTER_ENCODER (LIBX264, libx264); + REGISTER_ENCODER (LIBXVID, libxvid); /* parsers */ - REGISTER_PARSER (AAC, aac); - REGISTER_PARSER (AC3, ac3); - REGISTER_PARSER (CAVSVIDEO, cavsvideo); - REGISTER_PARSER (DCA, dca); - REGISTER_PARSER (DVBSUB, dvbsub); - REGISTER_PARSER (DVDSUB, dvdsub); - REGISTER_PARSER (H261, h261); - REGISTER_PARSER (H263, h263); - REGISTER_PARSER (H264, h264); - REGISTER_PARSER (MJPEG, mjpeg); - REGISTER_PARSER (MPEG4VIDEO, mpeg4video); - REGISTER_PARSER (MPEGAUDIO, mpegaudio); - REGISTER_PARSER (MPEGVIDEO, mpegvideo); - REGISTER_PARSER (PNM, pnm); - REGISTER_PARSER (VC1, vc1); + REGISTER_PARSER (AAC, aac); + REGISTER_PARSER (AC3, ac3); + REGISTER_PARSER (CAVSVIDEO, cavsvideo); + REGISTER_PARSER (DCA, dca); + REGISTER_PARSER (DVBSUB, dvbsub); + REGISTER_PARSER (DVDSUB, dvdsub); + REGISTER_PARSER (H261, h261); + REGISTER_PARSER (H263, h263); + REGISTER_PARSER (H264, h264); + REGISTER_PARSER (MJPEG, mjpeg); + REGISTER_PARSER (MLP, mlp); + REGISTER_PARSER (MPEG4VIDEO, mpeg4video); + REGISTER_PARSER (MPEGAUDIO, mpegaudio); + REGISTER_PARSER (MPEGVIDEO, mpegvideo); + REGISTER_PARSER (PNM, pnm); + REGISTER_PARSER (VC1, vc1); - av_register_bitstream_filter(&dump_extradata_bsf); - av_register_bitstream_filter(&remove_extradata_bsf); - av_register_bitstream_filter(&noise_bsf); - av_register_bitstream_filter(&mp3_header_compress_bsf); - av_register_bitstream_filter(&mp3_header_decompress_bsf); - av_register_bitstream_filter(&mjpega_dump_header_bsf); - av_register_bitstream_filter(&imx_dump_header_bsf); + /* bitstream filters */ + REGISTER_BSF (DUMP_EXTRADATA, dump_extradata); + REGISTER_BSF (H264_MP4TOANNEXB, h264_mp4toannexb); + REGISTER_BSF (IMX_DUMP_HEADER, imx_dump_header); + REGISTER_BSF (MJPEGA_DUMP_HEADER, mjpega_dump_header); + REGISTER_BSF (MP3_HEADER_COMPRESS, mp3_header_compress); + REGISTER_BSF (MP3_HEADER_DECOMPRESS, mp3_header_decompress); + REGISTER_BSF (MOV2TEXTSUB, mov2textsub); + REGISTER_BSF (NOISE, noise); + REGISTER_BSF (REMOVE_EXTRADATA, remove_extradata); + REGISTER_BSF (TEXT2MOVSUB, text2movsub); } diff --git a/contrib/ffmpeg/libavcodec/alpha/asm.h b/contrib/ffmpeg/libavcodec/alpha/asm.h index c0ddde528..1d0fa6f6a 100644 --- a/contrib/ffmpeg/libavcodec/alpha/asm.h +++ b/contrib/ffmpeg/libavcodec/alpha/asm.h @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef LIBAVCODEC_ALPHA_ASM_H -#define LIBAVCODEC_ALPHA_ASM_H +#ifndef FFMPEG_ASM_H +#define FFMPEG_ASM_H #include @@ -188,4 +188,4 @@ struct unaligned_long { uint64_t l; } __attribute__((packed)); #error "Unknown compiler!" #endif -#endif /* LIBAVCODEC_ALPHA_ASM_H */ +#endif /* FFMPEG_ASM_H */ diff --git a/contrib/ffmpeg/libavcodec/alpha/dsputil_alpha.c b/contrib/ffmpeg/libavcodec/alpha/dsputil_alpha.c index c98d6f7ff..36357356e 100644 --- a/contrib/ffmpeg/libavcodec/alpha/dsputil_alpha.c +++ b/contrib/ffmpeg/libavcodec/alpha/dsputil_alpha.c @@ -20,7 +20,7 @@ */ #include "asm.h" -#include "../dsputil.h" +#include "dsputil.h" extern void simple_idct_axp(DCTELEM *block); extern void simple_idct_put_axp(uint8_t *dest, int line_size, DCTELEM *block); diff --git a/contrib/ffmpeg/libavcodec/alpha/motion_est_alpha.c b/contrib/ffmpeg/libavcodec/alpha/motion_est_alpha.c index 337ffb38e..b23338c09 100644 --- a/contrib/ffmpeg/libavcodec/alpha/motion_est_alpha.c +++ b/contrib/ffmpeg/libavcodec/alpha/motion_est_alpha.c @@ -20,7 +20,7 @@ */ #include "asm.h" -#include "../dsputil.h" +#include "dsputil.h" void get_pixels_mvi(DCTELEM *restrict block, const uint8_t *restrict pixels, int line_size) diff --git a/contrib/ffmpeg/libavcodec/alpha/mpegvideo_alpha.c b/contrib/ffmpeg/libavcodec/alpha/mpegvideo_alpha.c index 8ad264b06..9aa20f420 100644 --- a/contrib/ffmpeg/libavcodec/alpha/mpegvideo_alpha.c +++ b/contrib/ffmpeg/libavcodec/alpha/mpegvideo_alpha.c @@ -20,8 +20,8 @@ */ #include "asm.h" -#include "../dsputil.h" -#include "../mpegvideo.h" +#include "dsputil.h" +#include "mpegvideo.h" static void dct_unquantize_h263_intra_axp(MpegEncContext *s, DCTELEM *block, int n, int qscale) diff --git a/contrib/ffmpeg/libavcodec/alpha/regdef.h b/contrib/ffmpeg/libavcodec/alpha/regdef.h index 01e263bac..aaa15e994 100644 --- a/contrib/ffmpeg/libavcodec/alpha/regdef.h +++ b/contrib/ffmpeg/libavcodec/alpha/regdef.h @@ -20,8 +20,8 @@ */ /* Some BSDs don't seem to have regdef.h... sigh */ -#ifndef alpha_regdef_h -#define alpha_regdef_h +#ifndef FFMPEG_REGDEF_H +#define FFMPEG_REGDEF_H #define v0 $0 /* function return value */ @@ -63,4 +63,4 @@ #define sp $30 /* stack pointer */ #define zero $31 /* reads as zero, writes are noops */ -#endif /* alpha_regdef_h */ +#endif /* FFMPEG_REGDEF_H */ diff --git a/contrib/ffmpeg/libavcodec/alpha/simple_idct_alpha.c b/contrib/ffmpeg/libavcodec/alpha/simple_idct_alpha.c index adadd3ab0..f664801f9 100644 --- a/contrib/ffmpeg/libavcodec/alpha/simple_idct_alpha.c +++ b/contrib/ffmpeg/libavcodec/alpha/simple_idct_alpha.c @@ -3,6 +3,12 @@ * * Copyright (c) 2001 Michael Niedermayer * + * based upon some outcommented C code from mpeg2dec (idct_mmx.c + * written by Aaron Holtzman ) + * + * Alpha optimizations by MÃ¥ns RullgÃ¥rd + * and Falk Hueffner + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -18,16 +24,10 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * based upon some outcommented c code from mpeg2dec (idct_mmx.c - * written by Aaron Holtzman ) - * - * Alpha optimiziations by Måns Rullgård - * and Falk Hueffner */ #include "asm.h" -#include "../dsputil.h" +#include "dsputil.h" extern void (*put_pixels_clamped_axp_p)(const DCTELEM *block, uint8_t *pixels, int line_size); diff --git a/contrib/ffmpeg/libavcodec/amr.c b/contrib/ffmpeg/libavcodec/amr.c deleted file mode 100644 index 6a8193f0b..000000000 --- a/contrib/ffmpeg/libavcodec/amr.c +++ /dev/null @@ -1,715 +0,0 @@ -/* - * AMR Audio decoder stub - * Copyright (c) 2003 the ffmpeg project - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - - /** @file - * Adaptive Multi-Rate (AMR) Audio decoder stub. - * - * This code implements both an AMR-NarrowBand (AMR-NB) and an AMR-WideBand - * (AMR-WB) audio encoder/decoder through external reference code from - * http://www.3gpp.org/. The license of the code from 3gpp is unclear so you - * have to download the code separately. Two versions exists: One fixed-point - * and one with floats. For some reason the float-encoder is significant faster - * at least on a P4 1.5GHz (0.9s instead of 9.9s on a 30s audio clip at MR102). - * Both float and fixed point are supported for AMR-NB, but only float for - * AMR-WB. - * - * \section AMR-NB - * - * \subsection Float - * The float version (default) can be downloaded from: - * http://www.3gpp.org/ftp/Specs/archive/26_series/26.104/26104-610.zip - * Extract the source into \c "ffmpeg/libavcodec/amr_float". - * - * \subsection Fixed-point - * The fixed-point (TS26.073) can be downloaded from: - * http://www.3gpp.org/ftp/Specs/archive/26_series/26.073/26073-510.zip. - * Extract the source into \c "ffmpeg/libavcodec/amr". - * To use the fixed version run \c "./configure" with \c "--enable-amr_nb-fixed". - * - * \subsection Specification - * The specification for AMR-NB can be found in TS 26.071 - * (http://www.3gpp.org/ftp/Specs/html-info/26071.htm) and some other - * info at http://www.3gpp.org/ftp/Specs/html-info/26-series.htm. - * - * \section AMR-WB - * \subsection Float - * The reference code can be downloaded from: - * http://www.3gpp.org/ftp/Specs/archive/26_series/26.204/26204-600.zip - * It should be extracted to \c "ffmpeg/libavcodec/amrwb_float". Enable it with - * \c "--enable-amr_wb". - * - * \subsection Fixed-point - * If someone wants to use the fixed point version it can be downloaded from: - * http://www.3gpp.org/ftp/Specs/archive/26_series/26.173/26173-571.zip. - * - * \subsection Specification - * The specification for AMR-WB can be found in TS 26.171 - * (http://www.3gpp.org/ftp/Specs/html-info/26171.htm) and some other - * info at http://www.3gpp.org/ftp/Specs/html-info/26-series.htm. - * - */ - -#include "avcodec.h" - -#ifdef CONFIG_AMR_NB_FIXED - -#define MMS_IO - -#include "amr/sp_dec.h" -#include "amr/d_homing.h" -#include "amr/typedef.h" -#include "amr/sp_enc.h" -#include "amr/sid_sync.h" -#include "amr/e_homing.h" - -#else -#include "amr_float/interf_dec.h" -#include "amr_float/interf_enc.h" -#endif - -/* Common code for fixed and float version*/ -typedef struct AMR_bitrates -{ - int rate; - enum Mode mode; -} AMR_bitrates; - -/* Match desired bitrate */ -static int getBitrateMode(int bitrate) -{ - /* make the correspondance between bitrate and mode */ - AMR_bitrates rates[]={ {4750,MR475}, - {5150,MR515}, - {5900,MR59}, - {6700,MR67}, - {7400,MR74}, - {7950,MR795}, - {10200,MR102}, - {12200,MR122}, - }; - int i; - - for(i=0;i<8;i++) - { - if(rates[i].rate==bitrate) - { - return(rates[i].mode); - } - } - /* no bitrate matching, return an error */ - return -1; -} - -static void amr_decode_fix_avctx(AVCodecContext * avctx) -{ - const int is_amr_wb = 1 + (avctx->codec_id == CODEC_ID_AMR_WB); - - if(avctx->sample_rate == 0) - { - avctx->sample_rate = 8000 * is_amr_wb; - } - - if(avctx->channels == 0) - { - avctx->channels = 1; - } - - avctx->frame_size = 160 * is_amr_wb; -} - -#ifdef CONFIG_AMR_NB_FIXED -/* fixed point version*/ -/* frame size in serial bitstream file (frame type + serial stream + flags) */ -#define SERIAL_FRAMESIZE (1+MAX_SERIAL_SIZE+5) - -typedef struct AMRContext { - int frameCount; - Speech_Decode_FrameState *speech_decoder_state; - enum RXFrameType rx_type; - enum Mode mode; - Word16 reset_flag; - Word16 reset_flag_old; - - int enc_bitrate; - Speech_Encode_FrameState *enstate; - sid_syncState *sidstate; - enum TXFrameType tx_frametype; -} AMRContext; - -static int amr_nb_decode_init(AVCodecContext * avctx) -{ - AMRContext *s = avctx->priv_data; - - s->frameCount=0; - s->speech_decoder_state=NULL; - s->rx_type = (enum RXFrameType)0; - s->mode= (enum Mode)0; - s->reset_flag=0; - s->reset_flag_old=1; - - if(Speech_Decode_Frame_init(&s->speech_decoder_state, "Decoder")) - { - av_log(avctx, AV_LOG_ERROR, "Speech_Decode_Frame_init error\n"); - return -1; - } - - amr_decode_fix_avctx(avctx); - - if(avctx->channels > 1) - { - av_log(avctx, AV_LOG_ERROR, "amr_nb: multichannel decoding not supported\n"); - return -1; - } - - return 0; -} - -static int amr_nb_encode_init(AVCodecContext * avctx) -{ - AMRContext *s = avctx->priv_data; - - s->frameCount=0; - s->speech_decoder_state=NULL; - s->rx_type = (enum RXFrameType)0; - s->mode= (enum Mode)0; - s->reset_flag=0; - s->reset_flag_old=1; - - if(avctx->sample_rate!=8000) - { - av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n"); - return -1; - } - - if(avctx->channels!=1) - { - av_log(avctx, AV_LOG_ERROR, "Only mono supported\n"); - return -1; - } - - avctx->frame_size=160; - avctx->coded_frame= avcodec_alloc_frame(); - - if(Speech_Encode_Frame_init(&s->enstate, 0, "encoder") || sid_sync_init (&s->sidstate)) - { - av_log(avctx, AV_LOG_ERROR, "Speech_Encode_Frame_init error\n"); - return -1; - } - - if((s->enc_bitrate=getBitrateMode(avctx->bit_rate))<0) - { - av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n"); - return -1; - } - - return 0; -} - -static int amr_nb_encode_close(AVCodecContext * avctx) -{ - AMRContext *s = avctx->priv_data; - - Speech_Encode_Frame_exit(&s->enstate); - sid_sync_exit (&s->sidstate); - av_freep(&avctx->coded_frame); - return 0; -} - -static int amr_nb_decode_close(AVCodecContext * avctx) -{ - AMRContext *s = avctx->priv_data; - - Speech_Decode_Frame_exit(&s->speech_decoder_state); - return 0; -} - -static int amr_nb_decode_frame(AVCodecContext * avctx, - void *data, int *data_size, - uint8_t * buf, int buf_size) -{ - AMRContext *s = avctx->priv_data; - uint8_t*amrData=buf; - int offset=0; - UWord8 toc, q, ft; - Word16 serial[SERIAL_FRAMESIZE]; /* coded bits */ - Word16 *synth; - UWord8 *packed_bits; - static Word16 packed_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0}; - int i; - - //printf("amr_decode_frame data_size=%i buf=0x%X buf_size=%d frameCount=%d!!\n",*data_size,buf,buf_size,s->frameCount); - - synth=data; - -// while(offset> 2) & 0x01; - ft = (toc >> 3) & 0x0F; - - //printf("offset=%d, packet_size=%d amrData= 0x%X %X %X %X\n",offset,packed_size[ft],amrData[offset],amrData[offset+1],amrData[offset+2],amrData[offset+3]); - - offset++; - - packed_bits=amrData+offset; - - offset+=packed_size[ft]; - - //Unsort and unpack bits - s->rx_type = UnpackBits(q, ft, packed_bits, &s->mode, &serial[1]); - - //We have a new frame - s->frameCount++; - - if (s->rx_type == RX_NO_DATA) - { - s->mode = s->speech_decoder_state->prev_mode; - } - else { - s->speech_decoder_state->prev_mode = s->mode; - } - - /* if homed: check if this frame is another homing frame */ - if (s->reset_flag_old == 1) - { - /* only check until end of first subframe */ - s->reset_flag = decoder_homing_frame_test_first(&serial[1], s->mode); - } - /* produce encoder homing frame if homed & input=decoder homing frame */ - if ((s->reset_flag != 0) && (s->reset_flag_old != 0)) - { - for (i = 0; i < L_FRAME; i++) - { - synth[i] = EHF_MASK; - } - } - else - { - /* decode frame */ - Speech_Decode_Frame(s->speech_decoder_state, s->mode, &serial[1], s->rx_type, synth); - } - - //Each AMR-frame results in 160 16-bit samples - *data_size+=160*2; - synth+=160; - - /* if not homed: check whether current frame is a homing frame */ - if (s->reset_flag_old == 0) - { - /* check whole frame */ - s->reset_flag = decoder_homing_frame_test(&serial[1], s->mode); - } - /* reset decoder if current frame is a homing frame */ - if (s->reset_flag != 0) - { - Speech_Decode_Frame_reset(s->speech_decoder_state); - } - s->reset_flag_old = s->reset_flag; - - } - return offset; -} - - -static int amr_nb_encode_frame(AVCodecContext *avctx, - unsigned char *frame/*out*/, int buf_size, void *data/*in*/) -{ - short serial_data[250] = {0}; - AMRContext *s = avctx->priv_data; - int written; - - s->reset_flag = encoder_homing_frame_test(data); - - Speech_Encode_Frame(s->enstate, s->enc_bitrate, data, &serial_data[1], &s->mode); - - /* add frame type and mode */ - sid_sync (s->sidstate, s->mode, &s->tx_frametype); - - written = PackBits(s->mode, s->enc_bitrate, s->tx_frametype, &serial_data[1], frame); - - if (s->reset_flag != 0) - { - Speech_Encode_Frame_reset(s->enstate); - sid_sync_reset(s->sidstate); - } - return written; -} - - -#elif defined(CONFIG_AMR_NB) /* Float point version*/ - -typedef struct AMRContext { - int frameCount; - void * decState; - int *enstate; - int enc_bitrate; -} AMRContext; - -static int amr_nb_decode_init(AVCodecContext * avctx) -{ - AMRContext *s = avctx->priv_data; - - s->frameCount=0; - s->decState=Decoder_Interface_init(); - if(!s->decState) - { - av_log(avctx, AV_LOG_ERROR, "Decoder_Interface_init error\r\n"); - return -1; - } - - amr_decode_fix_avctx(avctx); - - if(avctx->channels > 1) - { - av_log(avctx, AV_LOG_ERROR, "amr_nb: multichannel decoding not supported\n"); - return -1; - } - - return 0; -} - -static int amr_nb_encode_init(AVCodecContext * avctx) -{ - AMRContext *s = avctx->priv_data; - - s->frameCount=0; - - if(avctx->sample_rate!=8000) - { - av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n"); - return -1; - } - - if(avctx->channels!=1) - { - av_log(avctx, AV_LOG_ERROR, "Only mono supported\n"); - return -1; - } - - avctx->frame_size=160; - avctx->coded_frame= avcodec_alloc_frame(); - - s->enstate=Encoder_Interface_init(0); - if(!s->enstate) - { - av_log(avctx, AV_LOG_ERROR, "Encoder_Interface_init error\n"); - return -1; - } - - if((s->enc_bitrate=getBitrateMode(avctx->bit_rate))<0) - { - av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n"); - return -1; - } - - return 0; -} - -static int amr_nb_decode_close(AVCodecContext * avctx) -{ - AMRContext *s = avctx->priv_data; - - Decoder_Interface_exit(s->decState); - return 0; -} - -static int amr_nb_encode_close(AVCodecContext * avctx) -{ - AMRContext *s = avctx->priv_data; - - Encoder_Interface_exit(s->enstate); - av_freep(&avctx->coded_frame); - return 0; -} - -static int amr_nb_decode_frame(AVCodecContext * avctx, - void *data, int *data_size, - uint8_t * buf, int buf_size) -{ - AMRContext *s = avctx->priv_data; - uint8_t*amrData=buf; - static short block_size[16]={ 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 }; - enum Mode dec_mode; - int packet_size; - - /* av_log(NULL,AV_LOG_DEBUG,"amr_decode_frame buf=%p buf_size=%d frameCount=%d!!\n",buf,buf_size,s->frameCount); */ - - dec_mode = (buf[0] >> 3) & 0x000F; - packet_size = block_size[dec_mode]+1; - - if(packet_size > buf_size) { - av_log(avctx, AV_LOG_ERROR, "amr frame too short (%u, should be %u)\n", buf_size, packet_size); - return -1; - } - - s->frameCount++; - /* av_log(NULL,AV_LOG_DEBUG,"packet_size=%d amrData= 0x%X %X %X %X\n",packet_size,amrData[0],amrData[1],amrData[2],amrData[3]); */ - /* call decoder */ - Decoder_Interface_Decode(s->decState, amrData, data, 0); - *data_size=160*2; - - return packet_size; -} - -static int amr_nb_encode_frame(AVCodecContext *avctx, - unsigned char *frame/*out*/, int buf_size, void *data/*in*/) -{ - AMRContext *s = avctx->priv_data; - int written; - - if((s->enc_bitrate=getBitrateMode(avctx->bit_rate))<0) - { - av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n"); - return -1; - } - - written = Encoder_Interface_Encode(s->enstate, - s->enc_bitrate, - data, - frame, - 0); - /* av_log(NULL,AV_LOG_DEBUG,"amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n",written, s->enc_bitrate, frame[0] ); */ - - return written; -} - -#endif - -#if defined(CONFIG_AMR_NB) || defined(CONFIG_AMR_NB_FIXED) - -AVCodec amr_nb_decoder = -{ - "amr_nb", - CODEC_TYPE_AUDIO, - CODEC_ID_AMR_NB, - sizeof(AMRContext), - amr_nb_decode_init, - NULL, - amr_nb_decode_close, - amr_nb_decode_frame, -}; - -AVCodec amr_nb_encoder = -{ - "amr_nb", - CODEC_TYPE_AUDIO, - CODEC_ID_AMR_NB, - sizeof(AMRContext), - amr_nb_encode_init, - amr_nb_encode_frame, - amr_nb_encode_close, - NULL, -}; - -#endif - -/* -----------AMR wideband ------------*/ -#ifdef CONFIG_AMR_WB - -#ifdef _TYPEDEF_H -//To avoid duplicate typedefs from typdef in amr-nb -#define typedef_h -#endif - -#include "amrwb_float/enc_if.h" -#include "amrwb_float/dec_if.h" - -/* Common code for fixed and float version*/ -typedef struct AMRWB_bitrates -{ - int rate; - int mode; -} AMRWB_bitrates; - -static int getWBBitrateMode(int bitrate) -{ - /* make the correspondance between bitrate and mode */ - AMRWB_bitrates rates[]={ {6600,0}, - {8850,1}, - {12650,2}, - {14250,3}, - {15850,4}, - {18250,5}, - {19850,6}, - {23050,7}, - {23850,8}, - }; - int i; - - for(i=0;i<9;i++) - { - if(rates[i].rate==bitrate) - { - return(rates[i].mode); - } - } - /* no bitrate matching, return an error */ - return -1; -} - - -typedef struct AMRWBContext { - int frameCount; - void *state; - int mode; - Word16 allow_dtx; -} AMRWBContext; - -static int amr_wb_encode_init(AVCodecContext * avctx) -{ - AMRWBContext *s = avctx->priv_data; - - s->frameCount=0; - - if(avctx->sample_rate!=16000) - { - av_log(avctx, AV_LOG_ERROR, "Only 16000Hz sample rate supported\n"); - return -1; - } - - if(avctx->channels!=1) - { - av_log(avctx, AV_LOG_ERROR, "Only mono supported\n"); - return -1; - } - - if((s->mode=getWBBitrateMode(avctx->bit_rate))<0) - { - av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n"); - return -1; - } - - avctx->frame_size=320; - avctx->coded_frame= avcodec_alloc_frame(); - - s->state = E_IF_init(); - s->allow_dtx=0; - - return 0; -} - -static int amr_wb_encode_close(AVCodecContext * avctx) -{ - AMRWBContext *s = avctx->priv_data; - - E_IF_exit(s->state); - av_freep(&avctx->coded_frame); - s->frameCount++; - return 0; -} - -static int amr_wb_encode_frame(AVCodecContext *avctx, - unsigned char *frame/*out*/, int buf_size, void *data/*in*/) -{ - AMRWBContext *s = avctx->priv_data; - int size; - - if((s->mode=getWBBitrateMode(avctx->bit_rate))<0) - { - av_log(avctx, AV_LOG_ERROR, "bitrate not supported\n"); - return -1; - } - size = E_IF_encode(s->state, s->mode, data, frame, s->allow_dtx); - return size; -} - -static int amr_wb_decode_init(AVCodecContext * avctx) -{ - AMRWBContext *s = avctx->priv_data; - - s->frameCount=0; - s->state = D_IF_init(); - - amr_decode_fix_avctx(avctx); - - if(avctx->channels > 1) - { - av_log(avctx, AV_LOG_ERROR, "amr_wb: multichannel decoding not supported\n"); - return -1; - } - - return 0; -} - -extern const UWord8 block_size[]; - -static int amr_wb_decode_frame(AVCodecContext * avctx, - void *data, int *data_size, - uint8_t * buf, int buf_size) -{ - AMRWBContext *s = avctx->priv_data; - uint8_t*amrData=buf; - int mode; - int packet_size; - - if(buf_size==0) { - /* nothing to do */ - return 0; - } - - mode = (amrData[0] >> 3) & 0x000F; - packet_size = block_size[mode]; - - if(packet_size > buf_size) { - av_log(avctx, AV_LOG_ERROR, "amr frame too short (%u, should be %u)\n", buf_size, packet_size+1); - return -1; - } - - s->frameCount++; - D_IF_decode( s->state, amrData, data, _good_frame); - *data_size=320*2; - return packet_size; -} - -static int amr_wb_decode_close(AVCodecContext * avctx) -{ - AMRWBContext *s = avctx->priv_data; - - D_IF_exit(s->state); - return 0; -} - -AVCodec amr_wb_decoder = -{ - "amr_wb", - CODEC_TYPE_AUDIO, - CODEC_ID_AMR_WB, - sizeof(AMRWBContext), - amr_wb_decode_init, - NULL, - amr_wb_decode_close, - amr_wb_decode_frame, -}; - -AVCodec amr_wb_encoder = -{ - "amr_wb", - CODEC_TYPE_AUDIO, - CODEC_ID_AMR_WB, - sizeof(AMRWBContext), - amr_wb_encode_init, - amr_wb_encode_frame, - amr_wb_encode_close, - NULL, -}; - -#endif //CONFIG_AMR_WB diff --git a/contrib/ffmpeg/libavcodec/apedec.c b/contrib/ffmpeg/libavcodec/apedec.c new file mode 100644 index 000000000..032bc7397 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/apedec.c @@ -0,0 +1,922 @@ +/* + * Monkey's Audio lossless audio decoder + * Copyright (c) 2007 Benjamin Zores + * based upon libdemac from Dave Chapman. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#define ALT_BITSTREAM_READER_LE +#include "avcodec.h" +#include "dsputil.h" +#include "bitstream.h" +#include "bytestream.h" + +/** + * @file apedec.c + * Monkey's Audio lossless audio decoder + */ + +#define BLOCKS_PER_LOOP 4608 +#define MAX_CHANNELS 2 +#define MAX_BYTESPERSAMPLE 3 + +#define APE_FRAMECODE_MONO_SILENCE 1 +#define APE_FRAMECODE_STEREO_SILENCE 3 +#define APE_FRAMECODE_PSEUDO_STEREO 4 + +#define HISTORY_SIZE 512 +#define PREDICTOR_ORDER 8 +/** Total size of all predictor histories */ +#define PREDICTOR_SIZE 50 + +#define YDELAYA (18 + PREDICTOR_ORDER*4) +#define YDELAYB (18 + PREDICTOR_ORDER*3) +#define XDELAYA (18 + PREDICTOR_ORDER*2) +#define XDELAYB (18 + PREDICTOR_ORDER) + +#define YADAPTCOEFFSA 18 +#define XADAPTCOEFFSA 14 +#define YADAPTCOEFFSB 10 +#define XADAPTCOEFFSB 5 + +/** + * Possible compression levels + * @{ + */ +enum APECompressionLevel { + COMPRESSION_LEVEL_FAST = 1000, + COMPRESSION_LEVEL_NORMAL = 2000, + COMPRESSION_LEVEL_HIGH = 3000, + COMPRESSION_LEVEL_EXTRA_HIGH = 4000, + COMPRESSION_LEVEL_INSANE = 5000 +}; +/** @} */ + +#define APE_FILTER_LEVELS 3 + +/** Filter orders depending on compression level */ +static const uint16_t ape_filter_orders[5][APE_FILTER_LEVELS] = { + { 0, 0, 0 }, + { 16, 0, 0 }, + { 64, 0, 0 }, + { 32, 256, 0 }, + { 16, 256, 1280 } +}; + +/** Filter fraction bits depending on compression level */ +static const uint16_t ape_filter_fracbits[5][APE_FILTER_LEVELS] = { + { 0, 0, 0 }, + { 11, 0, 0 }, + { 11, 0, 0 }, + { 10, 13, 0 }, + { 11, 13, 15 } +}; + + +/** Filters applied to the decoded data */ +typedef struct APEFilter { + int16_t *coeffs; ///< actual coefficients used in filtering + int16_t *adaptcoeffs; ///< adaptive filter coefficients used for correcting of actual filter coefficients + int16_t *historybuffer; ///< filter memory + int16_t *delay; ///< filtered values + + int avg; +} APEFilter; + +typedef struct APERice { + uint32_t k; + uint32_t ksum; +} APERice; + +typedef struct APERangecoder { + uint32_t low; ///< low end of interval + uint32_t range; ///< length of interval + uint32_t help; ///< bytes_to_follow resp. intermediate value + unsigned int buffer; ///< buffer for input/output +} APERangecoder; + +/** Filter histories */ +typedef struct APEPredictor { + int32_t *buf; + + int32_t lastA[2]; + + int32_t filterA[2]; + int32_t filterB[2]; + + int32_t coeffsA[2][4]; ///< adaption coefficients + int32_t coeffsB[2][5]; ///< adaption coefficients + int32_t historybuffer[HISTORY_SIZE + PREDICTOR_SIZE]; +} APEPredictor; + +/** Decoder context */ +typedef struct APEContext { + AVCodecContext *avctx; + DSPContext dsp; + int channels; + int samples; ///< samples left to decode in current frame + + int fileversion; ///< codec version, very important in decoding process + int compression_level; ///< compression levels + int fset; ///< which filter set to use (calculated from compression level) + int flags; ///< global decoder flags + + uint32_t CRC; ///< frame CRC + int frameflags; ///< frame flags + int currentframeblocks; ///< samples (per channel) in current frame + int blocksdecoded; ///< count of decoded samples in current frame + APEPredictor predictor; ///< predictor used for final reconstruction + + int32_t decoded0[BLOCKS_PER_LOOP]; ///< decoded data for the first channel + int32_t decoded1[BLOCKS_PER_LOOP]; ///< decoded data for the second channel + + int16_t* filterbuf[APE_FILTER_LEVELS]; ///< filter memory + + APERangecoder rc; ///< rangecoder used to decode actual values + APERice riceX; ///< rice code parameters for the second channel + APERice riceY; ///< rice code parameters for the first channel + APEFilter filters[APE_FILTER_LEVELS][2]; ///< filters used for reconstruction + + uint8_t *data; ///< current frame data + uint8_t *data_end; ///< frame data end + const uint8_t *ptr; ///< current position in frame data + const uint8_t *last_ptr; ///< position where last 4608-sample block ended +} APEContext; + +// TODO: dsputilize +static inline void vector_add(int16_t * v1, int16_t * v2, int order) +{ + while (order--) + *v1++ += *v2++; +} + +// TODO: dsputilize +static inline void vector_sub(int16_t * v1, int16_t * v2, int order) +{ + while (order--) + *v1++ -= *v2++; +} + +// TODO: dsputilize +static inline int32_t scalarproduct(int16_t * v1, int16_t * v2, int order) +{ + int res = 0; + + while (order--) + res += *v1++ * *v2++; + + return res; +} + +static int ape_decode_init(AVCodecContext * avctx) +{ + APEContext *s = avctx->priv_data; + int i; + + if (avctx->extradata_size != 6) { + av_log(avctx, AV_LOG_ERROR, "Incorrect extradata\n"); + return -1; + } + if (avctx->bits_per_sample != 16) { + av_log(avctx, AV_LOG_ERROR, "Only 16-bit samples are supported\n"); + return -1; + } + if (avctx->channels > 2) { + av_log(avctx, AV_LOG_ERROR, "Only mono and stereo is supported\n"); + return -1; + } + s->avctx = avctx; + s->channels = avctx->channels; + s->fileversion = AV_RL16(avctx->extradata); + s->compression_level = AV_RL16(avctx->extradata + 2); + s->flags = AV_RL16(avctx->extradata + 4); + + av_log(avctx, AV_LOG_DEBUG, "Compression Level: %d - Flags: %d\n", s->compression_level, s->flags); + if (s->compression_level % 1000 || s->compression_level > COMPRESSION_LEVEL_INSANE) { + av_log(avctx, AV_LOG_ERROR, "Incorrect compression level %d\n", s->compression_level); + return -1; + } + s->fset = s->compression_level / 1000 - 1; + for (i = 0; i < APE_FILTER_LEVELS; i++) { + if (!ape_filter_orders[s->fset][i]) + break; + s->filterbuf[i] = av_malloc((ape_filter_orders[s->fset][i] * 3 + HISTORY_SIZE) * 4); + } + + dsputil_init(&s->dsp, avctx); + return 0; +} + +static int ape_decode_close(AVCodecContext * avctx) +{ + APEContext *s = avctx->priv_data; + int i; + + for (i = 0; i < APE_FILTER_LEVELS; i++) + av_freep(&s->filterbuf[i]); + + return 0; +} + +/** + * @defgroup rangecoder APE range decoder + * @{ + */ + +#define CODE_BITS 32 +#define TOP_VALUE ((unsigned int)1 << (CODE_BITS-1)) +#define SHIFT_BITS (CODE_BITS - 9) +#define EXTRA_BITS ((CODE_BITS-2) % 8 + 1) +#define BOTTOM_VALUE (TOP_VALUE >> 8) + +/** Start the decoder */ +static inline void range_start_decoding(APEContext * ctx) +{ + ctx->rc.buffer = bytestream_get_byte(&ctx->ptr); + ctx->rc.low = ctx->rc.buffer >> (8 - EXTRA_BITS); + ctx->rc.range = (uint32_t) 1 << EXTRA_BITS; +} + +/** Perform normalization */ +static inline void range_dec_normalize(APEContext * ctx) +{ + while (ctx->rc.range <= BOTTOM_VALUE) { + ctx->rc.buffer = (ctx->rc.buffer << 8) | bytestream_get_byte(&ctx->ptr); + ctx->rc.low = (ctx->rc.low << 8) | ((ctx->rc.buffer >> 1) & 0xFF); + ctx->rc.range <<= 8; + } +} + +/** + * Calculate culmulative frequency for next symbol. Does NO update! + * @param tot_f is the total frequency or (code_value)1<rc.help = ctx->rc.range / tot_f; + return ctx->rc.low / ctx->rc.help; +} + +/** + * Decode value with given size in bits + * @param shift number of bits to decode + */ +static inline int range_decode_culshift(APEContext * ctx, int shift) +{ + range_dec_normalize(ctx); + ctx->rc.help = ctx->rc.range >> shift; + return ctx->rc.low / ctx->rc.help; +} + + +/** + * Update decoding state + * @param sy_f the interval length (frequency of the symbol) + * @param lt_f the lower end (frequency sum of < symbols) + */ +static inline void range_decode_update(APEContext * ctx, int sy_f, int lt_f) +{ + ctx->rc.low -= ctx->rc.help * lt_f; + ctx->rc.range = ctx->rc.help * sy_f; +} + +/** Decode n bits (n <= 16) without modelling */ +static inline int range_decode_bits(APEContext * ctx, int n) +{ + int sym = range_decode_culshift(ctx, n); + range_decode_update(ctx, 1, sym); + return sym; +} + + +#define MODEL_ELEMENTS 64 + +/** + * Fixed probabilities for symbols in Monkey Audio version 3.97 + */ +static const uint32_t counts_3970[65] = { + 0, 14824, 28224, 39348, 47855, 53994, 58171, 60926, + 62682, 63786, 64463, 64878, 65126, 65276, 65365, 65419, + 65450, 65469, 65480, 65487, 65491, 65493, 65494, 65495, + 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, + 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, + 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, + 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, + 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535, + 65536 +}; + +/** + * Probability ranges for symbols in Monkey Audio version 3.97 + */ +static const uint16_t counts_diff_3970[64] = { + 14824, 13400, 11124, 8507, 6139, 4177, 2755, 1756, + 1104, 677, 415, 248, 150, 89, 54, 31, + 19, 11, 7, 4, 2, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1 +}; + +/** + * Fixed probabilities for symbols in Monkey Audio version 3.98 + */ +static const uint32_t counts_3980[65] = { + 0, 19578, 36160, 48417, 56323, 60899, 63265, 64435, + 64971, 65232, 65351, 65416, 65447, 65466, 65476, 65482, + 65485, 65488, 65490, 65491, 65492, 65493, 65494, 65495, + 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, + 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, + 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, + 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, + 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535, + 65536 +}; + +/** + * Probability ranges for symbols in Monkey Audio version 3.98 + */ +static const uint16_t counts_diff_3980[64] = { + 19578, 16582, 12257, 7906, 4576, 2366, 1170, 536, + 261, 119, 65, 31, 19, 10, 6, 3, + 3, 2, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1 +}; + +/** + * Decode symbol + * @param counts probability range start position + * @param count_diffs probability range widths + */ +static inline int range_get_symbol(APEContext * ctx, + const uint32_t counts[], + const uint16_t counts_diff[]) +{ + int symbol, cf; + + cf = range_decode_culshift(ctx, 16); + + /* figure out the symbol inefficiently; a binary search would be much better */ + for (symbol = 0; counts[symbol + 1] <= cf; symbol++); + + range_decode_update(ctx, counts_diff[symbol], counts[symbol]); + + return symbol; +} +/** @} */ // group rangecoder + +static inline void update_rice(APERice *rice, int x) +{ + rice->ksum += ((x + 1) / 2) - ((rice->ksum + 16) >> 5); + + if (rice->k == 0) + rice->k = 1; + else if (rice->ksum < (1 << (rice->k + 4))) + rice->k--; + else if (rice->ksum >= (1 << (rice->k + 5))) + rice->k++; +} + +static inline int ape_decode_value(APEContext * ctx, APERice *rice) +{ + int x, overflow; + + if (ctx->fileversion < 3980) { + int tmpk; + + overflow = range_get_symbol(ctx, counts_3970, counts_diff_3970); + + if (overflow == (MODEL_ELEMENTS - 1)) { + tmpk = range_decode_bits(ctx, 5); + overflow = 0; + } else + tmpk = (rice->k < 1) ? 0 : rice->k - 1; + + if (tmpk <= 16) + x = range_decode_bits(ctx, tmpk); + else { + x = range_decode_bits(ctx, 16); + x |= (range_decode_bits(ctx, tmpk - 16) << 16); + } + x += overflow << tmpk; + } else { + int base, pivot; + + pivot = rice->ksum >> 5; + if (pivot == 0) + pivot = 1; + + overflow = range_get_symbol(ctx, counts_3980, counts_diff_3980); + + if (overflow == (MODEL_ELEMENTS - 1)) { + overflow = range_decode_bits(ctx, 16) << 16; + overflow |= range_decode_bits(ctx, 16); + } + + base = range_decode_culfreq(ctx, pivot); + range_decode_update(ctx, 1, base); + + x = base + overflow * pivot; + } + + update_rice(rice, x); + + /* Convert to signed */ + if (x & 1) + return (x >> 1) + 1; + else + return -(x >> 1); +} + +static void entropy_decode(APEContext * ctx, int blockstodecode, int stereo) +{ + int32_t *decoded0 = ctx->decoded0; + int32_t *decoded1 = ctx->decoded1; + + ctx->blocksdecoded = blockstodecode; + + if (ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) { + /* We are pure silence, just memset the output buffer. */ + memset(decoded0, 0, blockstodecode * sizeof(int32_t)); + memset(decoded1, 0, blockstodecode * sizeof(int32_t)); + } else { + while (blockstodecode--) { + *decoded0++ = ape_decode_value(ctx, &ctx->riceY); + if (stereo) + *decoded1++ = ape_decode_value(ctx, &ctx->riceX); + } + } + + if (ctx->blocksdecoded == ctx->currentframeblocks) + range_dec_normalize(ctx); /* normalize to use up all bytes */ +} + +static void init_entropy_decoder(APEContext * ctx) +{ + /* Read the CRC */ + ctx->CRC = bytestream_get_be32(&ctx->ptr); + + /* Read the frame flags if they exist */ + ctx->frameflags = 0; + if ((ctx->fileversion > 3820) && (ctx->CRC & 0x80000000)) { + ctx->CRC &= ~0x80000000; + + ctx->frameflags = bytestream_get_be32(&ctx->ptr); + } + + /* Keep a count of the blocks decoded in this frame */ + ctx->blocksdecoded = 0; + + /* Initialize the rice structs */ + ctx->riceX.k = 10; + ctx->riceX.ksum = (1 << ctx->riceX.k) * 16; + ctx->riceY.k = 10; + ctx->riceY.ksum = (1 << ctx->riceY.k) * 16; + + /* The first 8 bits of input are ignored. */ + ctx->ptr++; + + range_start_decoding(ctx); +} + +static const int32_t initial_coeffs[4] = { + 360, 317, -109, 98 +}; + +static void init_predictor_decoder(APEContext * ctx) +{ + APEPredictor *p = &ctx->predictor; + + /* Zero the history buffers */ + memset(p->historybuffer, 0, PREDICTOR_SIZE * sizeof(int32_t)); + p->buf = p->historybuffer; + + /* Initialize and zero the coefficients */ + memcpy(p->coeffsA[0], initial_coeffs, sizeof(initial_coeffs)); + memcpy(p->coeffsA[1], initial_coeffs, sizeof(initial_coeffs)); + memset(p->coeffsB, 0, sizeof(p->coeffsB)); + + p->filterA[0] = p->filterA[1] = 0; + p->filterB[0] = p->filterB[1] = 0; + p->lastA[0] = p->lastA[1] = 0; +} + +/** Get inverse sign of integer (-1 for positive, 1 for negative and 0 for zero) */ +static inline int APESIGN(int32_t x) { + return (x < 0) - (x > 0); +} + +static int predictor_update_filter(APEPredictor *p, const int decoded, const int filter, const int delayA, const int delayB, const int adaptA, const int adaptB) +{ + int32_t predictionA, predictionB; + + p->buf[delayA] = p->lastA[filter]; + p->buf[adaptA] = APESIGN(p->buf[delayA]); + p->buf[delayA - 1] = p->buf[delayA] - p->buf[delayA - 1]; + p->buf[adaptA - 1] = APESIGN(p->buf[delayA - 1]); + + predictionA = p->buf[delayA ] * p->coeffsA[filter][0] + + p->buf[delayA - 1] * p->coeffsA[filter][1] + + p->buf[delayA - 2] * p->coeffsA[filter][2] + + p->buf[delayA - 3] * p->coeffsA[filter][3]; + + /* Apply a scaled first-order filter compression */ + p->buf[delayB] = p->filterA[filter ^ 1] - ((p->filterB[filter] * 31) >> 5); + p->buf[adaptB] = APESIGN(p->buf[delayB]); + p->buf[delayB - 1] = p->buf[delayB] - p->buf[delayB - 1]; + p->buf[adaptB - 1] = APESIGN(p->buf[delayB - 1]); + p->filterB[filter] = p->filterA[filter ^ 1]; + + predictionB = p->buf[delayB ] * p->coeffsB[filter][0] + + p->buf[delayB - 1] * p->coeffsB[filter][1] + + p->buf[delayB - 2] * p->coeffsB[filter][2] + + p->buf[delayB - 3] * p->coeffsB[filter][3] + + p->buf[delayB - 4] * p->coeffsB[filter][4]; + + p->lastA[filter] = decoded + ((predictionA + (predictionB >> 1)) >> 10); + p->filterA[filter] = p->lastA[filter] + ((p->filterA[filter] * 31) >> 5); + + if (!decoded) // no need updating filter coefficients + return p->filterA[filter]; + + if (decoded > 0) { + p->coeffsA[filter][0] -= p->buf[adaptA ]; + p->coeffsA[filter][1] -= p->buf[adaptA - 1]; + p->coeffsA[filter][2] -= p->buf[adaptA - 2]; + p->coeffsA[filter][3] -= p->buf[adaptA - 3]; + + p->coeffsB[filter][0] -= p->buf[adaptB ]; + p->coeffsB[filter][1] -= p->buf[adaptB - 1]; + p->coeffsB[filter][2] -= p->buf[adaptB - 2]; + p->coeffsB[filter][3] -= p->buf[adaptB - 3]; + p->coeffsB[filter][4] -= p->buf[adaptB - 4]; + } else { + p->coeffsA[filter][0] += p->buf[adaptA ]; + p->coeffsA[filter][1] += p->buf[adaptA - 1]; + p->coeffsA[filter][2] += p->buf[adaptA - 2]; + p->coeffsA[filter][3] += p->buf[adaptA - 3]; + + p->coeffsB[filter][0] += p->buf[adaptB ]; + p->coeffsB[filter][1] += p->buf[adaptB - 1]; + p->coeffsB[filter][2] += p->buf[adaptB - 2]; + p->coeffsB[filter][3] += p->buf[adaptB - 3]; + p->coeffsB[filter][4] += p->buf[adaptB - 4]; + } + return p->filterA[filter]; +} + +static void predictor_decode_stereo(APEContext * ctx, int count) +{ + int32_t predictionA, predictionB; + APEPredictor *p = &ctx->predictor; + int32_t *decoded0 = ctx->decoded0; + int32_t *decoded1 = ctx->decoded1; + + while (count--) { + /* Predictor Y */ + predictionA = predictor_update_filter(p, *decoded0, 0, YDELAYA, YDELAYB, YADAPTCOEFFSA, YADAPTCOEFFSB); + predictionB = predictor_update_filter(p, *decoded1, 1, XDELAYA, XDELAYB, XADAPTCOEFFSA, XADAPTCOEFFSB); + *(decoded0++) = predictionA; + *(decoded1++) = predictionB; + + /* Combined */ + p->buf++; + + /* Have we filled the history buffer? */ + if (p->buf == p->historybuffer + HISTORY_SIZE) { + memmove(p->historybuffer, p->buf, PREDICTOR_SIZE * sizeof(int32_t)); + p->buf = p->historybuffer; + } + } +} + +static void predictor_decode_mono(APEContext * ctx, int count) +{ + APEPredictor *p = &ctx->predictor; + int32_t *decoded0 = ctx->decoded0; + int32_t predictionA, currentA, A; + + currentA = p->lastA[0]; + + while (count--) { + A = *decoded0; + + p->buf[YDELAYA] = currentA; + p->buf[YDELAYA - 1] = p->buf[YDELAYA] - p->buf[YDELAYA - 1]; + + predictionA = p->buf[YDELAYA ] * p->coeffsA[0][0] + + p->buf[YDELAYA - 1] * p->coeffsA[0][1] + + p->buf[YDELAYA - 2] * p->coeffsA[0][2] + + p->buf[YDELAYA - 3] * p->coeffsA[0][3]; + + currentA = A + (predictionA >> 10); + + p->buf[YADAPTCOEFFSA] = APESIGN(p->buf[YDELAYA ]); + p->buf[YADAPTCOEFFSA - 1] = APESIGN(p->buf[YDELAYA - 1]); + + if (A > 0) { + p->coeffsA[0][0] -= p->buf[YADAPTCOEFFSA ]; + p->coeffsA[0][1] -= p->buf[YADAPTCOEFFSA - 1]; + p->coeffsA[0][2] -= p->buf[YADAPTCOEFFSA - 2]; + p->coeffsA[0][3] -= p->buf[YADAPTCOEFFSA - 3]; + } else if (A < 0) { + p->coeffsA[0][0] += p->buf[YADAPTCOEFFSA ]; + p->coeffsA[0][1] += p->buf[YADAPTCOEFFSA - 1]; + p->coeffsA[0][2] += p->buf[YADAPTCOEFFSA - 2]; + p->coeffsA[0][3] += p->buf[YADAPTCOEFFSA - 3]; + } + + p->buf++; + + /* Have we filled the history buffer? */ + if (p->buf == p->historybuffer + HISTORY_SIZE) { + memmove(p->historybuffer, p->buf, PREDICTOR_SIZE * sizeof(int32_t)); + p->buf = p->historybuffer; + } + + p->filterA[0] = currentA + ((p->filterA[0] * 31) >> 5); + *(decoded0++) = p->filterA[0]; + } + + p->lastA[0] = currentA; +} + +static void do_init_filter(APEFilter *f, int16_t * buf, int order) +{ + f->coeffs = buf; + f->historybuffer = buf + order; + f->delay = f->historybuffer + order * 2; + f->adaptcoeffs = f->historybuffer + order; + + memset(f->historybuffer, 0, (order * 2) * sizeof(int16_t)); + memset(f->coeffs, 0, order * sizeof(int16_t)); + f->avg = 0; +} + +static void init_filter(APEContext * ctx, APEFilter *f, int16_t * buf, int order) +{ + do_init_filter(&f[0], buf, order); + do_init_filter(&f[1], buf + order * 3 + HISTORY_SIZE, order); +} + +static inline void do_apply_filter(int version, APEFilter *f, int32_t *data, int count, int order, int fracbits) +{ + int res; + int absres; + + while (count--) { + /* round fixedpoint scalar product */ + res = (scalarproduct(f->delay - order, f->coeffs, order) + (1 << (fracbits - 1))) >> fracbits; + + if (*data < 0) + vector_add(f->coeffs, f->adaptcoeffs - order, order); + else if (*data > 0) + vector_sub(f->coeffs, f->adaptcoeffs - order, order); + + res += *data; + + *data++ = res; + + /* Update the output history */ + *f->delay++ = av_clip_int16(res); + + if (version < 3980) { + /* Version ??? to < 3.98 files (untested) */ + f->adaptcoeffs[0] = (res == 0) ? 0 : ((res >> 28) & 8) - 4; + f->adaptcoeffs[-4] >>= 1; + f->adaptcoeffs[-8] >>= 1; + } else { + /* Version 3.98 and later files */ + + /* Update the adaption coefficients */ + absres = (res < 0 ? -res : res); + + if (absres > (f->avg * 3)) + *f->adaptcoeffs = ((res >> 25) & 64) - 32; + else if (absres > (f->avg * 4) / 3) + *f->adaptcoeffs = ((res >> 26) & 32) - 16; + else if (absres > 0) + *f->adaptcoeffs = ((res >> 27) & 16) - 8; + else + *f->adaptcoeffs = 0; + + f->avg += (absres - f->avg) / 16; + + f->adaptcoeffs[-1] >>= 1; + f->adaptcoeffs[-2] >>= 1; + f->adaptcoeffs[-8] >>= 1; + } + + f->adaptcoeffs++; + + /* Have we filled the history buffer? */ + if (f->delay == f->historybuffer + HISTORY_SIZE + (order * 2)) { + memmove(f->historybuffer, f->delay - (order * 2), + (order * 2) * sizeof(int16_t)); + f->delay = f->historybuffer + order * 2; + f->adaptcoeffs = f->historybuffer + order; + } + } +} + +static void apply_filter(APEContext * ctx, APEFilter *f, + int32_t * data0, int32_t * data1, + int count, int order, int fracbits) +{ + do_apply_filter(ctx->fileversion, &f[0], data0, count, order, fracbits); + if (data1) + do_apply_filter(ctx->fileversion, &f[1], data1, count, order, fracbits); +} + +static void ape_apply_filters(APEContext * ctx, int32_t * decoded0, + int32_t * decoded1, int count) +{ + int i; + + for (i = 0; i < APE_FILTER_LEVELS; i++) { + if (!ape_filter_orders[ctx->fset][i]) + break; + apply_filter(ctx, ctx->filters[i], decoded0, decoded1, count, ape_filter_orders[ctx->fset][i], ape_filter_fracbits[ctx->fset][i]); + } +} + +static void init_frame_decoder(APEContext * ctx) +{ + int i; + init_entropy_decoder(ctx); + init_predictor_decoder(ctx); + + for (i = 0; i < APE_FILTER_LEVELS; i++) { + if (!ape_filter_orders[ctx->fset][i]) + break; + init_filter(ctx, ctx->filters[i], ctx->filterbuf[i], ape_filter_orders[ctx->fset][i]); + } +} + +static void ape_unpack_mono(APEContext * ctx, int count) +{ + int32_t left; + int32_t *decoded0 = ctx->decoded0; + int32_t *decoded1 = ctx->decoded1; + + if (ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) { + entropy_decode(ctx, count, 0); + /* We are pure silence, so we're done. */ + av_log(ctx->avctx, AV_LOG_DEBUG, "pure silence mono\n"); + return; + } + + entropy_decode(ctx, count, 0); + ape_apply_filters(ctx, decoded0, NULL, count); + + /* Now apply the predictor decoding */ + predictor_decode_mono(ctx, count); + + /* Pseudo-stereo - just copy left channel to right channel */ + if (ctx->channels == 2) { + while (count--) { + left = *decoded0; + *(decoded1++) = *(decoded0++) = left; + } + } +} + +static void ape_unpack_stereo(APEContext * ctx, int count) +{ + int32_t left, right; + int32_t *decoded0 = ctx->decoded0; + int32_t *decoded1 = ctx->decoded1; + + if (ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) { + /* We are pure silence, so we're done. */ + av_log(ctx->avctx, AV_LOG_DEBUG, "pure silence stereo\n"); + return; + } + + entropy_decode(ctx, count, 1); + ape_apply_filters(ctx, decoded0, decoded1, count); + + /* Now apply the predictor decoding */ + predictor_decode_stereo(ctx, count); + + /* Decorrelate and scale to output depth */ + while (count--) { + left = *decoded1 - (*decoded0 / 2); + right = left + *decoded0; + + *(decoded0++) = left; + *(decoded1++) = right; + } +} + +static int ape_decode_frame(AVCodecContext * avctx, + void *data, int *data_size, + const uint8_t * buf, int buf_size) +{ + APEContext *s = avctx->priv_data; + int16_t *samples = data; + int nblocks; + int i, n; + int blockstodecode; + int bytes_used; + + if (buf_size == 0 && !s->samples) { + *data_size = 0; + return 0; + } + + /* should not happen but who knows */ + if (BLOCKS_PER_LOOP * 2 * avctx->channels > *data_size) { + av_log (avctx, AV_LOG_ERROR, "Packet size is too big to be handled in lavc! (max is %d where you have %d)\n", *data_size, s->samples * 2 * avctx->channels); + return -1; + } + + if(!s->samples){ + s->data = av_realloc(s->data, (buf_size + 3) & ~3); + s->dsp.bswap_buf((uint32_t*)s->data, (const uint32_t*)buf, buf_size >> 2); + s->ptr = s->last_ptr = s->data; + s->data_end = s->data + buf_size; + + nblocks = s->samples = bytestream_get_be32(&s->ptr); + n = bytestream_get_be32(&s->ptr); + if(n < 0 || n > 3){ + av_log(avctx, AV_LOG_ERROR, "Incorrect offset passed\n"); + s->data = NULL; + return -1; + } + s->ptr += n; + + s->currentframeblocks = nblocks; + buf += 4; + if (s->samples <= 0) { + *data_size = 0; + return buf_size; + } + + memset(s->decoded0, 0, sizeof(s->decoded0)); + memset(s->decoded1, 0, sizeof(s->decoded1)); + + /* Initialize the frame decoder */ + init_frame_decoder(s); + } + + if (!s->data) { + *data_size = 0; + return buf_size; + } + + nblocks = s->samples; + blockstodecode = FFMIN(BLOCKS_PER_LOOP, nblocks); + + if ((s->channels == 1) || (s->frameflags & APE_FRAMECODE_PSEUDO_STEREO)) + ape_unpack_mono(s, blockstodecode); + else + ape_unpack_stereo(s, blockstodecode); + + for (i = 0; i < blockstodecode; i++) { + *samples++ = s->decoded0[i]; + if(s->channels == 2) + *samples++ = s->decoded1[i]; + } + + s->samples -= blockstodecode; + + *data_size = blockstodecode * 2 * s->channels; + bytes_used = s->samples ? s->ptr - s->last_ptr : buf_size; + s->last_ptr = s->ptr; + return bytes_used; +} + +AVCodec ape_decoder = { + "ape", + CODEC_TYPE_AUDIO, + CODEC_ID_APE, + sizeof(APEContext), + ape_decode_init, + NULL, + ape_decode_close, + ape_decode_frame, +}; diff --git a/contrib/ffmpeg/libavcodec/apiexample.c b/contrib/ffmpeg/libavcodec/apiexample.c index 151637bd2..793cfaa04 100644 --- a/contrib/ffmpeg/libavcodec/apiexample.c +++ b/contrib/ffmpeg/libavcodec/apiexample.c @@ -336,11 +336,11 @@ void video_decode_example(const char *outfilename, const char *filename) picture= avcodec_alloc_frame(); if(codec->capabilities&CODEC_CAP_TRUNCATED) - c->flags|= CODEC_FLAG_TRUNCATED; /* we dont send complete frames */ + c->flags|= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */ - /* for some codecs, such as msmpeg4 and mpeg4, width and height - MUST be initialized there because these info are not available - in the bitstream */ + /* For some codecs, such as msmpeg4 and mpeg4, width and height + MUST be initialized there because this information is not + available in the bitstream. */ /* open it */ if (avcodec_open(c, codec) < 0) { @@ -433,8 +433,7 @@ int main(int argc, char **argv) /* must be called before using avcodec lib */ avcodec_init(); - /* register all the codecs (you can also register only the codec - you wish to have smaller code */ + /* register all the codecs */ avcodec_register_all(); if (argc <= 1) { diff --git a/contrib/ffmpeg/libavcodec/armv4l/dsputil_arm.c b/contrib/ffmpeg/libavcodec/armv4l/dsputil_arm.c index 61b5fdacc..47daec7a6 100644 --- a/contrib/ffmpeg/libavcodec/armv4l/dsputil_arm.c +++ b/contrib/ffmpeg/libavcodec/armv4l/dsputil_arm.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../dsputil.h" +#include "dsputil.h" #ifdef HAVE_IPP #include "ipp.h" #endif @@ -209,67 +209,69 @@ void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx) ff_put_pixels_clamped = c->put_pixels_clamped; ff_add_pixels_clamped = c->add_pixels_clamped; - if(idct_algo == FF_IDCT_AUTO){ + if (avctx->lowres == 0) { + if(idct_algo == FF_IDCT_AUTO){ #if defined(HAVE_IPP) - idct_algo = FF_IDCT_IPP; + idct_algo = FF_IDCT_IPP; #elif defined(HAVE_ARMV6) - idct_algo = FF_IDCT_SIMPLEARMV6; + idct_algo = FF_IDCT_SIMPLEARMV6; #elif defined(HAVE_ARMV5TE) - idct_algo = FF_IDCT_SIMPLEARMV5TE; + idct_algo = FF_IDCT_SIMPLEARMV5TE; #else - idct_algo = FF_IDCT_ARM; + idct_algo = FF_IDCT_ARM; #endif - } + } - if(idct_algo==FF_IDCT_ARM){ - c->idct_put= j_rev_dct_ARM_put; - c->idct_add= j_rev_dct_ARM_add; - c->idct = j_rev_dct_ARM; - c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;/* FF_NO_IDCT_PERM */ - } else if (idct_algo==FF_IDCT_SIMPLEARM){ - c->idct_put= simple_idct_ARM_put; - c->idct_add= simple_idct_ARM_add; - c->idct = simple_idct_ARM; - c->idct_permutation_type= FF_NO_IDCT_PERM; + if(idct_algo==FF_IDCT_ARM){ + c->idct_put= j_rev_dct_ARM_put; + c->idct_add= j_rev_dct_ARM_add; + c->idct = j_rev_dct_ARM; + c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM;/* FF_NO_IDCT_PERM */ + } else if (idct_algo==FF_IDCT_SIMPLEARM){ + c->idct_put= simple_idct_ARM_put; + c->idct_add= simple_idct_ARM_add; + c->idct = simple_idct_ARM; + c->idct_permutation_type= FF_NO_IDCT_PERM; #ifdef HAVE_ARMV6 - } else if (idct_algo==FF_IDCT_SIMPLEARMV6){ - c->idct_put= ff_simple_idct_put_armv6; - c->idct_add= ff_simple_idct_add_armv6; - c->idct = ff_simple_idct_armv6; - c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM; + } else if (idct_algo==FF_IDCT_SIMPLEARMV6){ + c->idct_put= ff_simple_idct_put_armv6; + c->idct_add= ff_simple_idct_add_armv6; + c->idct = ff_simple_idct_armv6; + c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM; #endif #ifdef HAVE_ARMV5TE - } else if (idct_algo==FF_IDCT_SIMPLEARMV5TE){ - c->idct_put= simple_idct_put_armv5te; - c->idct_add= simple_idct_add_armv5te; - c->idct = simple_idct_armv5te; - c->idct_permutation_type = FF_NO_IDCT_PERM; + } else if (idct_algo==FF_IDCT_SIMPLEARMV5TE){ + c->idct_put= simple_idct_put_armv5te; + c->idct_add= simple_idct_add_armv5te; + c->idct = simple_idct_armv5te; + c->idct_permutation_type = FF_NO_IDCT_PERM; #endif #ifdef HAVE_IPP - } else if (idct_algo==FF_IDCT_IPP){ - c->idct_put= simple_idct_ipp_put; - c->idct_add= simple_idct_ipp_add; - c->idct = simple_idct_ipp; - c->idct_permutation_type= FF_NO_IDCT_PERM; + } else if (idct_algo==FF_IDCT_IPP){ + c->idct_put= simple_idct_ipp_put; + c->idct_add= simple_idct_ipp_add; + c->idct = simple_idct_ipp; + c->idct_permutation_type= FF_NO_IDCT_PERM; #endif + } } -/* c->put_pixels_tab[0][0] = put_pixels16_arm; */ // NG! + c->put_pixels_tab[0][0] = put_pixels16_arm; c->put_pixels_tab[0][1] = put_pixels16_x2_arm; //OK! c->put_pixels_tab[0][2] = put_pixels16_y2_arm; //OK! -/* c->put_pixels_tab[0][3] = put_pixels16_xy2_arm; /\* NG *\/ */ -/* c->put_no_rnd_pixels_tab[0][0] = put_pixels16_arm; */ + c->put_pixels_tab[0][3] = put_pixels16_xy2_arm; + c->put_no_rnd_pixels_tab[0][0] = put_pixels16_arm; c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_arm; // OK c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_arm; //OK -/* c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_arm; //NG */ + c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_arm; c->put_pixels_tab[1][0] = put_pixels8_arm; //OK c->put_pixels_tab[1][1] = put_pixels8_x2_arm; //OK -/* c->put_pixels_tab[1][2] = put_pixels8_y2_arm; //NG */ -/* c->put_pixels_tab[1][3] = put_pixels8_xy2_arm; //NG */ + c->put_pixels_tab[1][2] = put_pixels8_y2_arm; + c->put_pixels_tab[1][3] = put_pixels8_xy2_arm; c->put_no_rnd_pixels_tab[1][0] = put_pixels8_arm;//OK c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_arm; //OK c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_arm; //OK -/* c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_arm;//NG */ + c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_arm; #ifdef HAVE_IWMMXT dsputil_init_iwmmxt(c, avctx); diff --git a/contrib/ffmpeg/libavcodec/armv4l/dsputil_arm_s.S b/contrib/ffmpeg/libavcodec/armv4l/dsputil_arm_s.S index 2a3ee9c50..56ffc04e7 100644 --- a/contrib/ffmpeg/libavcodec/armv4l/dsputil_arm_s.S +++ b/contrib/ffmpeg/libavcodec/armv4l/dsputil_arm_s.S @@ -553,7 +553,7 @@ put_no_rnd_pixels8_y2_arm: .word 4b @ ---------------------------------------------------------------- -.macro RND_XY2_IT align, rnd +.macro RND_XY2_IT align @ l1= (a & 0x03030303) + (b & 0x03030303) ?(+ 0x02020202) @ h1= ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2) .if \align == 0 @@ -582,11 +582,7 @@ put_no_rnd_pixels8_y2_arm: and r9, r5, r14 and r10, r6, r14 and r11, r7, r14 -.if \rnd == 1 - ldreq r14, [r12, #16] @ 0x02020202 -.else - ldreq r14, [r12, #28] @ 0x01010101 -.endif + ldreq r14, [r12, #16] @ 0x02020202/0x01010101 add r8, r8, r10 add r9, r9, r11 addeq r8, r8, r14 @@ -598,12 +594,13 @@ put_no_rnd_pixels8_y2_arm: and r7, r14, r7, lsr #2 add r10, r4, r6 add r11, r5, r7 + subs r3, r3, #1 .endm -.macro RND_XY2_EXPAND align, rnd - RND_XY2_IT \align, \rnd +.macro RND_XY2_EXPAND align + RND_XY2_IT \align 6: stmfd sp!, {r8-r11} - RND_XY2_IT \align, \rnd + RND_XY2_IT \align ldmfd sp!, {r4-r7} add r4, r4, r8 add r5, r5, r9 @@ -614,10 +611,9 @@ put_no_rnd_pixels8_y2_arm: and r5, r14, r5, lsr #2 add r4, r4, r6 add r5, r5, r7 - subs r3, r3, #1 stmia r0, {r4-r5} add r0, r0, r2 - bne 6b + bge 6b ldmfd sp!, {r4-r11,pc} .endm @@ -634,19 +630,19 @@ put_pixels8_xy2_arm: bic r1, r1, #3 ldrne pc, [r5] 1: - RND_XY2_EXPAND 0, 1 + RND_XY2_EXPAND 0 .align 8 2: - RND_XY2_EXPAND 1, 1 + RND_XY2_EXPAND 1 .align 8 3: - RND_XY2_EXPAND 2, 1 + RND_XY2_EXPAND 2 .align 8 4: - RND_XY2_EXPAND 3, 1 + RND_XY2_EXPAND 3 5: .word 0x03030303 @@ -656,7 +652,6 @@ put_pixels8_xy2_arm: .word 0x02020202 .word 0xFCFCFCFC >> 2 .word 0x0F0F0F0F - .word 0x01010101 .align 8 .global put_no_rnd_pixels8_xy2_arm @@ -671,26 +666,25 @@ put_no_rnd_pixels8_xy2_arm: bic r1, r1, #3 ldrne pc, [r5] 1: - RND_XY2_EXPAND 0, 0 + RND_XY2_EXPAND 0 .align 8 2: - RND_XY2_EXPAND 1, 0 + RND_XY2_EXPAND 1 .align 8 3: - RND_XY2_EXPAND 2, 0 + RND_XY2_EXPAND 2 .align 8 4: - RND_XY2_EXPAND 3, 0 + RND_XY2_EXPAND 3 5: .word 0x03030303 .word 2b .word 3b .word 4b - .word 0x02020202 + .word 0x01010101 .word 0xFCFCFCFC >> 2 .word 0x0F0F0F0F - .word 0x01010101 diff --git a/contrib/ffmpeg/libavcodec/armv4l/dsputil_iwmmxt.c b/contrib/ffmpeg/libavcodec/armv4l/dsputil_iwmmxt.c index 7536100ee..18329ddf6 100644 --- a/contrib/ffmpeg/libavcodec/armv4l/dsputil_iwmmxt.c +++ b/contrib/ffmpeg/libavcodec/armv4l/dsputil_iwmmxt.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../dsputil.h" +#include "dsputil.h" #define DEF(x, y) x ## _no_rnd_ ## y ##_iwmmxt #define SET_RND(regd) __asm__ __volatile__ ("mov r12, #1 \n\t tbcsth " #regd ", r12":::"r12"); @@ -123,6 +123,25 @@ void add_pixels_clamped_iwmmxt(const DCTELEM *block, uint8_t *pixels, int line_s : "cc", "memory", "r12"); } +static void clear_blocks_iwmmxt(DCTELEM *blocks) +{ + asm volatile( + "wzero wr0 \n\t" + "mov r1, #(128 * 6 / 32) \n\t" + "1: \n\t" + "wstrd wr0, [%0] \n\t" + "wstrd wr0, [%0, #8] \n\t" + "wstrd wr0, [%0, #16] \n\t" + "wstrd wr0, [%0, #24] \n\t" + "subs r1, r1, #1 \n\t" + "add %0, %0, #32 \n\t" + "bne 1b \n\t" + : "+r"(blocks) + : + : "r1" + ); +} + static void nop(uint8_t *block, const uint8_t *pixels, int line_size, int h) { return; @@ -146,6 +165,8 @@ void dsputil_init_iwmmxt(DSPContext* c, AVCodecContext *avctx) c->add_pixels_clamped = add_pixels_clamped_iwmmxt; + c->clear_blocks = clear_blocks_iwmmxt; + c->put_pixels_tab[0][0] = put_pixels16_iwmmxt; c->put_pixels_tab[0][1] = put_pixels16_x2_iwmmxt; c->put_pixels_tab[0][2] = put_pixels16_y2_iwmmxt; diff --git a/contrib/ffmpeg/libavcodec/armv4l/dsputil_iwmmxt_rnd.h b/contrib/ffmpeg/libavcodec/armv4l/dsputil_iwmmxt_rnd.h index 51ba61c47..f7151c7c6 100644 --- a/contrib/ffmpeg/libavcodec/armv4l/dsputil_iwmmxt_rnd.h +++ b/contrib/ffmpeg/libavcodec/armv4l/dsputil_iwmmxt_rnd.h @@ -19,6 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +/* This header intentionally has no multiple inclusion guards. It is meant to + * be included multiple times and generates different code depending on the + * value of certain #defines. */ + void DEF(put, pixels8)(uint8_t *block, const uint8_t *pixels, const int line_size, int h) { int stride = line_size; diff --git a/contrib/ffmpeg/libavcodec/armv4l/mathops.h b/contrib/ffmpeg/libavcodec/armv4l/mathops.h index 7ddd0ec6e..cc097c3ff 100644 --- a/contrib/ffmpeg/libavcodec/armv4l/mathops.h +++ b/contrib/ffmpeg/libavcodec/armv4l/mathops.h @@ -19,6 +19,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef FFMPEG_ARMV4L_MATHOPS_H +#define FFMPEG_ARMV4L_MATHOPS_H + #ifdef FRAC_BITS # define MULL(a, b) \ ({ int lo, hi;\ @@ -47,3 +50,5 @@ __rt; }) #endif + +#endif /* FFMPEG_ARMV4L_MATHOPS_H */ diff --git a/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_arm.c b/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_arm.c index 22d40d8bc..0aca43557 100644 --- a/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_arm.c +++ b/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_arm.c @@ -16,12 +16,11 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ -#include "../dsputil.h" -#include "../mpegvideo.h" -#include "../avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" +#include "avcodec.h" extern void MPV_common_init_iwmmxt(MpegEncContext *s); extern void MPV_common_init_armv5te(MpegEncContext *s); @@ -29,7 +28,7 @@ extern void MPV_common_init_armv5te(MpegEncContext *s); void MPV_common_init_armv4l(MpegEncContext *s) { /* IWMMXT support is a superset of armv5te, so - * allow optimised functions for armv5te unless + * allow optimized functions for armv5te unless * a better iwmmxt function exists */ #ifdef HAVE_ARMV5TE diff --git a/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_armv5te.c b/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_armv5te.c index 5e83c8a43..4322b19f2 100644 --- a/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_armv5te.c +++ b/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_armv5te.c @@ -19,15 +19,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* - * Some useful links for those who may be interested in optimizing code for ARM. - * ARM Architecture Reference Manual: http://www.arm.com/community/academy/resources.html - * Instructions timings and optimization guide for ARM9E: http://www.arm.com/pdfs/DDI0222B_9EJS_r1p2.pdf - */ - -#include "../dsputil.h" -#include "../mpegvideo.h" -#include "../avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" +#include "avcodec.h" #ifdef ENABLE_ARM_TESTS @@ -158,7 +152,7 @@ __asm__ __volatile__( \ static void dct_unquantize_h263_intra_armv5te(MpegEncContext *s, DCTELEM *block, int n, int qscale) { - int i, level, qmul, qadd; + int level, qmul, qadd; int nCoeffs; assert(s->block_last_index[n]>=0); @@ -187,7 +181,7 @@ static void dct_unquantize_h263_intra_armv5te(MpegEncContext *s, static void dct_unquantize_h263_inter_armv5te(MpegEncContext *s, DCTELEM *block, int n, int qscale) { - int i, level, qmul, qadd; + int qmul, qadd; int nCoeffs; assert(s->block_last_index[n]>=0); diff --git a/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_iwmmxt.c b/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_iwmmxt.c index 1336ac5f8..9e1121391 100644 --- a/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_iwmmxt.c +++ b/contrib/ffmpeg/libavcodec/armv4l/mpegvideo_iwmmxt.c @@ -18,9 +18,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../dsputil.h" -#include "../mpegvideo.h" -#include "../avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" +#include "avcodec.h" static void dct_unquantize_h263_intra_iwmmxt(MpegEncContext *s, DCTELEM *block, int n, int qscale) diff --git a/contrib/ffmpeg/libavcodec/armv4l/simple_idct_arm.S b/contrib/ffmpeg/libavcodec/armv4l/simple_idct_arm.S index b5a20f6da..98e900970 100644 --- a/contrib/ffmpeg/libavcodec/armv4l/simple_idct_arm.S +++ b/contrib/ffmpeg/libavcodec/armv4l/simple_idct_arm.S @@ -1,10 +1,12 @@ /* * simple_idct_arm.S * Copyright (C) 2002 Frederic 'dilb' Boulay. - * All Rights Reserved. * * Author: Frederic Boulay * + * The function defined in this file is derived from the simple_idct function + * from the libavcodec library part of the FFmpeg project. + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -20,9 +22,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * The function defined in this file, is derived from the simple_idct function - * from the libavcodec library part of the ffmpeg project. */ /* useful constants for the algorithm, they are save in __constant_ptr__ at */ @@ -80,7 +79,7 @@ simple_idct_ARM: __row_loop: - @@ read the row and check if it is null, almost null, or not, according to strongarm specs, it is not necessary to optimise ldr accesses (i.e. split 32bits in 2 16bits words), at least it gives more usable registers :) + @@ read the row and check if it is null, almost null, or not, according to strongarm specs, it is not necessary to optimize ldr accesses (i.e. split 32bits in 2 16bits words), at least it gives more usable registers :) ldr r1, [r14, #0] @ R1=(int32)(R12)[0]=ROWr32[0] (relative row cast to a 32b pointer) ldr r2, [r14, #4] @ R2=(int32)(R12)[1]=ROWr32[1] ldr r3, [r14, #8] @ R3=ROWr32[2] @@ -422,7 +421,7 @@ __end_a_evaluation2: @@ col[40] = ((a2 - b2) >> COL_SHIFT); @@ col[48] = ((a1 - b1) >> COL_SHIFT); @@ col[56] = ((a0 - b0) >> COL_SHIFT); - @@@@@ no optimisation here @@@@@ + @@@@@ no optimization here @@@@@ add r8, r6, r0 @ R8=a0+b0 add r9, r2, r1 @ R9=a1+b1 mov r8, r8, asr #COL_SHIFT diff --git a/contrib/ffmpeg/libavcodec/armv4l/simple_idct_armv5te.S b/contrib/ffmpeg/libavcodec/armv4l/simple_idct_armv5te.S index 28bee0643..8add33127 100644 --- a/contrib/ffmpeg/libavcodec/armv4l/simple_idct_armv5te.S +++ b/contrib/ffmpeg/libavcodec/armv4l/simple_idct_armv5te.S @@ -2,7 +2,7 @@ * Simple IDCT * * Copyright (c) 2001 Michael Niedermayer - * Copyright (c) 2006 Mans Rullgard + * Copyright (c) 2006 Mans Rullgard * * This file is part of FFmpeg. * @@ -42,6 +42,7 @@ w26: .long W26 w57: .long W57 .align + .type idct_row_armv5te, %function .func idct_row_armv5te idct_row_armv5te: str lr, [sp, #-4]! @@ -262,6 +263,7 @@ row_dc_only: .endm .align + .type idct_col_armv5te, %function .func idct_col_armv5te idct_col_armv5te: str lr, [sp, #-4]! @@ -336,6 +338,7 @@ idct_col_armv5te: .endfunc .align + .type idct_col_put_armv5te, %function .func idct_col_put_armv5te idct_col_put_armv5te: str lr, [sp, #-4]! @@ -455,6 +458,7 @@ idct_col_put_armv5te: .endfunc .align + .type idct_col_add_armv5te, %function .func idct_col_add_armv5te idct_col_add_armv5te: str lr, [sp, #-4]! @@ -608,6 +612,7 @@ idct_col_add_armv5te: .align .global simple_idct_armv5te + .type simple_idct_armv5te, %function .func simple_idct_armv5te simple_idct_armv5te: stmfd sp!, {v1, v2, v3, v4, v5, v6, v7, fp, lr} @@ -643,6 +648,7 @@ simple_idct_armv5te: .align .global simple_idct_add_armv5te + .type simple_idct_add_armv5te, %function .func simple_idct_add_armv5te simple_idct_add_armv5te: stmfd sp!, {a1, a2, v1, v2, v3, v4, v5, v6, v7, fp, lr} @@ -681,6 +687,7 @@ simple_idct_add_armv5te: .align .global simple_idct_put_armv5te + .type simple_idct_put_armv5te, %function .func simple_idct_put_armv5te simple_idct_put_armv5te: stmfd sp!, {a1, a2, v1, v2, v3, v4, v5, v6, v7, fp, lr} diff --git a/contrib/ffmpeg/libavcodec/armv4l/simple_idct_armv6.S b/contrib/ffmpeg/libavcodec/armv4l/simple_idct_armv6.S index 401e1910d..ab18c9f87 100644 --- a/contrib/ffmpeg/libavcodec/armv4l/simple_idct_armv6.S +++ b/contrib/ffmpeg/libavcodec/armv4l/simple_idct_armv6.S @@ -2,7 +2,7 @@ * Simple IDCT * * Copyright (c) 2001 Michael Niedermayer - * Copyright (c) 2007 Mans Rullgard + * Copyright (c) 2007 Mans Rullgard * * This file is part of FFmpeg. * @@ -191,6 +191,7 @@ w57: .long W57 a2 = dest */ .align + .type idct_row_armv6, %function .func idct_row_armv6 idct_row_armv6: str lr, [sp, #-4]! @@ -245,6 +246,7 @@ idct_row_armv6: a2 = dest */ .align + .type idct_col_armv6, %function .func idct_col_armv6 idct_col_armv6: stmfd sp!, {a2, lr} @@ -275,6 +277,7 @@ idct_col_armv6: a3 = line size */ .align + .type idct_col_put_armv6, %function .func idct_col_put_armv6 idct_col_put_armv6: stmfd sp!, {a2, a3, lr} @@ -307,6 +310,7 @@ idct_col_put_armv6: a3 = line size */ .align + .type idct_col_add_armv6, %function .func idct_col_add_armv6 idct_col_add_armv6: stmfd sp!, {a2, a3, lr} @@ -391,6 +395,7 @@ idct_col_add_armv6: .align .global ff_simple_idct_armv6 + .type ff_simple_idct_armv6, %function .func ff_simple_idct_armv6 /* void ff_simple_idct_armv6(DCTELEM *data); */ ff_simple_idct_armv6: @@ -409,6 +414,7 @@ ff_simple_idct_armv6: .align .global ff_simple_idct_add_armv6 + .type ff_simple_idct_add_armv6, %function .func ff_simple_idct_add_armv6 /* ff_simple_idct_add_armv6(uint8_t *dest, int line_size, DCTELEM *data); */ ff_simple_idct_add_armv6: @@ -429,6 +435,7 @@ ff_simple_idct_add_armv6: .align .global ff_simple_idct_put_armv6 + .type ff_simple_idct_put_armv6, %function .func ff_simple_idct_put_armv6 /* ff_simple_idct_put_armv6(uint8_t *dest, int line_size, DCTELEM *data); */ ff_simple_idct_put_armv6: diff --git a/contrib/ffmpeg/libavcodec/asv1.c b/contrib/ffmpeg/libavcodec/asv1.c index ec6bbb9ba..a0589cdd6 100644 --- a/contrib/ffmpeg/libavcodec/asv1.c +++ b/contrib/ffmpeg/libavcodec/asv1.c @@ -25,6 +25,7 @@ */ #include "avcodec.h" +#include "bitstream.h" #include "dsputil.h" #include "mpegvideo.h" @@ -386,7 +387,7 @@ static inline void dct_get(ASV1Context *a, int mb_x, int mb_y){ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { ASV1Context * const a = avctx->priv_data; AVFrame *picture = data; @@ -407,7 +408,7 @@ static int decode_frame(AVCodecContext *avctx, a->bitstream_buffer= av_fast_realloc(a->bitstream_buffer, &a->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); if(avctx->codec_id == CODEC_ID_ASV1) - a->dsp.bswap_buf((uint32_t*)a->bitstream_buffer, (uint32_t*)buf, buf_size/4); + a->dsp.bswap_buf((uint32_t*)a->bitstream_buffer, (const uint32_t*)buf, buf_size/4); else{ int i; for(i=0; i +#include +#include + +#include "avcodec.h" +#include "bitstream.h" +#include "dsputil.h" +#include "bytestream.h" + +#include "atrac3data.h" + +#define JOINT_STEREO 0x12 +#define STEREO 0x2 + + +/* These structures are needed to store the parsed gain control data. */ +typedef struct { + int num_gain_data; + int levcode[8]; + int loccode[8]; +} gain_info; + +typedef struct { + gain_info gBlock[4]; +} gain_block; + +typedef struct { + int pos; + int numCoefs; + float coef[8]; +} tonal_component; + +typedef struct { + int bandsCoded; + int numComponents; + tonal_component components[64]; + float prevFrame[1024]; + int gcBlkSwitch; + gain_block gainBlock[2]; + + DECLARE_ALIGNED_16(float, spectrum[1024]); + DECLARE_ALIGNED_16(float, IMDCT_buf[1024]); + + float delayBuf1[46]; ///> (off*8)) | (0x537F6103 << (32-(off*8)))); + bytes += 3 + off; + for (i = 0; i < bytes/4; i++) + obuf[i] = c ^ buf[i]; + + if (off) + av_log(NULL,AV_LOG_DEBUG,"Offset of %d not handled, post sample on ffmpeg-dev.\n",off); + + return off; +} + + +static void init_atrac3_transforms(ATRAC3Context *q) { + float enc_window[256]; + float s; + int i; + + /* Generate the mdct window, for details see + * http://wiki.multimedia.cx/index.php?title=RealAudio_atrc#Windows */ + for (i=0 ; i<256; i++) + enc_window[i] = (sin(((i + 0.5) / 256.0 - 0.5) * M_PI) + 1.0) * 0.5; + + if (!mdct_window[0]) + for (i=0 ; i<256; i++) { + mdct_window[i] = enc_window[i]/(enc_window[i]*enc_window[i] + enc_window[255-i]*enc_window[255-i]); + mdct_window[511-i] = mdct_window[i]; + } + + /* Generate the QMF window. */ + for (i=0 ; i<24; i++) { + s = qmf_48tap_half[i] * 2.0; + qmf_window[i] = s; + qmf_window[47 - i] = s; + } + + /* Initialize the MDCT transform. */ + ff_mdct_init(&mdct_ctx, 9, 1); +} + +/** + * Atrac3 uninit, free all allocated memory + */ + +static int atrac3_decode_close(AVCodecContext *avctx) +{ + ATRAC3Context *q = avctx->priv_data; + + av_free(q->pUnits); + av_free(q->decoded_bytes_buffer); + + return 0; +} + +/** +/ * Mantissa decoding + * + * @param gb the GetBit context + * @param selector what table is the output values coded with + * @param codingFlag constant length coding or variable length coding + * @param mantissas mantissa output table + * @param numCodes amount of values to get + */ + +static void readQuantSpectralCoeffs (GetBitContext *gb, int selector, int codingFlag, int* mantissas, int numCodes) +{ + int numBits, cnt, code, huffSymb; + + if (selector == 1) + numCodes /= 2; + + if (codingFlag != 0) { + /* constant length coding (CLC) */ + //FIXME we don't have any samples coded in CLC mode + numBits = CLCLengthTab[selector]; + + if (selector > 1) { + for (cnt = 0; cnt < numCodes; cnt++) { + if (numBits) + code = get_sbits(gb, numBits); + else + code = 0; + mantissas[cnt] = code; + } + } else { + for (cnt = 0; cnt < numCodes; cnt++) { + if (numBits) + code = get_bits(gb, numBits); //numBits is always 4 in this case + else + code = 0; + mantissas[cnt*2] = seTab_0[code >> 2]; + mantissas[cnt*2+1] = seTab_0[code & 3]; + } + } + } else { + /* variable length coding (VLC) */ + if (selector != 1) { + for (cnt = 0; cnt < numCodes; cnt++) { + huffSymb = get_vlc2(gb, spectral_coeff_tab[selector-1].table, spectral_coeff_tab[selector-1].bits, 3); + huffSymb += 1; + code = huffSymb >> 1; + if (huffSymb & 1) + code = -code; + mantissas[cnt] = code; + } + } else { + for (cnt = 0; cnt < numCodes; cnt++) { + huffSymb = get_vlc2(gb, spectral_coeff_tab[selector-1].table, spectral_coeff_tab[selector-1].bits, 3); + mantissas[cnt*2] = decTable1[huffSymb*2]; + mantissas[cnt*2+1] = decTable1[huffSymb*2+1]; + } + } + } +} + +/** + * Restore the quantized band spectrum coefficients + * + * @param gb the GetBit context + * @param pOut decoded band spectrum + * @return outSubbands subband counter, fix for broken specification/files + */ + +static int decodeSpectrum (GetBitContext *gb, float *pOut) +{ + int numSubbands, codingMode, cnt, first, last, subbWidth, *pIn; + int subband_vlc_index[32], SF_idxs[32]; + int mantissas[128]; + float SF; + + numSubbands = get_bits(gb, 5); // number of coded subbands + codingMode = get_bits1(gb); // coding Mode: 0 - VLC/ 1-CLC + + /* Get the VLC selector table for the subbands, 0 means not coded. */ + for (cnt = 0; cnt <= numSubbands; cnt++) + subband_vlc_index[cnt] = get_bits(gb, 3); + + /* Read the scale factor indexes from the stream. */ + for (cnt = 0; cnt <= numSubbands; cnt++) { + if (subband_vlc_index[cnt] != 0) + SF_idxs[cnt] = get_bits(gb, 6); + } + + for (cnt = 0; cnt <= numSubbands; cnt++) { + first = subbandTab[cnt]; + last = subbandTab[cnt+1]; + + subbWidth = last - first; + + if (subband_vlc_index[cnt] != 0) { + /* Decode spectral coefficients for this subband. */ + /* TODO: This can be done faster is several blocks share the + * same VLC selector (subband_vlc_index) */ + readQuantSpectralCoeffs (gb, subband_vlc_index[cnt], codingMode, mantissas, subbWidth); + + /* Decode the scale factor for this subband. */ + SF = SFTable[SF_idxs[cnt]] * iMaxQuant[subband_vlc_index[cnt]]; + + /* Inverse quantize the coefficients. */ + for (pIn=mantissas ; first> 2] == 0) + continue; + + coded_components = get_bits(gb,3); + + for (k=0; kgBlock; + + for (i=0 ; i<=numBands; i++) + { + numData = get_bits(gb,3); + pGain[i].num_gain_data = numData; + pLevel = pGain[i].levcode; + pLoc = pGain[i].loccode; + + for (cf = 0; cf < numData; cf++){ + pLevel[cf]= get_bits(gb,4); + pLoc [cf]= get_bits(gb,5); + if(cf && pLoc[cf] <= pLoc[cf-1]) + return -1; + } + } + + /* Clear the unused blocks. */ + for (; i<4 ; i++) + pGain[i].num_gain_data = 0; + + return 0; +} + +/** + * Apply gain parameters and perform the MDCT overlapping part + * + * @param pIn input float buffer + * @param pPrev previous float buffer to perform overlap against + * @param pOut output float buffer + * @param pGain1 current band gain info + * @param pGain2 next band gain info + */ + +static void gainCompensateAndOverlap (float *pIn, float *pPrev, float *pOut, gain_info *pGain1, gain_info *pGain2) +{ + /* gain compensation function */ + float gain1, gain2, gain_inc; + int cnt, numdata, nsample, startLoc, endLoc; + + + if (pGain2->num_gain_data == 0) + gain1 = 1.0; + else + gain1 = gain_tab1[pGain2->levcode[0]]; + + if (pGain1->num_gain_data == 0) { + for (cnt = 0; cnt < 256; cnt++) + pOut[cnt] = pIn[cnt] * gain1 + pPrev[cnt]; + } else { + numdata = pGain1->num_gain_data; + pGain1->loccode[numdata] = 32; + pGain1->levcode[numdata] = 4; + + nsample = 0; // current sample = 0 + + for (cnt = 0; cnt < numdata; cnt++) { + startLoc = pGain1->loccode[cnt] * 8; + endLoc = startLoc + 8; + + gain2 = gain_tab1[pGain1->levcode[cnt]]; + gain_inc = gain_tab2[(pGain1->levcode[cnt+1] - pGain1->levcode[cnt])+15]; + + /* interpolate */ + for (; nsample < startLoc; nsample++) + pOut[nsample] = (pIn[nsample] * gain1 + pPrev[nsample]) * gain2; + + /* interpolation is done over eight samples */ + for (; nsample < endLoc; nsample++) { + pOut[nsample] = (pIn[nsample] * gain1 + pPrev[nsample]) * gain2; + gain2 *= gain_inc; + } + } + + for (; nsample < 256; nsample++) + pOut[nsample] = (pIn[nsample] * gain1) + pPrev[nsample]; + } + + /* Delay for the overlapping part. */ + memcpy(pPrev, &pIn[256], 256*sizeof(float)); +} + +/** + * Combine the tonal band spectrum and regular band spectrum + * + * @param pSpectrum output spectrum buffer + * @param numComponents amount of tonal components + * @param pComponent tonal components for this band + */ + +static void addTonalComponents (float *pSpectrum, int numComponents, tonal_component *pComponent) +{ + int cnt, i; + float *pIn, *pOut; + + for (cnt = 0; cnt < numComponents; cnt++){ + pIn = pComponent[cnt].coef; + pOut = &(pSpectrum[pComponent[cnt].pos]); + + for (i=0 ; ibandsCoded = get_bits(gb,2); + + result = decodeGainControl (gb, &(pSnd->gainBlock[pSnd->gcBlkSwitch]), pSnd->bandsCoded); + if (result) return result; + + pSnd->numComponents = decodeTonalComponents (gb, pSnd->components, pSnd->bandsCoded); + if (pSnd->numComponents == -1) return -1; + + numSubbands = decodeSpectrum (gb, pSnd->spectrum); + + /* Merge the decoded spectrum and tonal components. */ + addTonalComponents (pSnd->spectrum, pSnd->numComponents, pSnd->components); + + + /* Convert number of subbands into number of MLT/QMF bands */ + numBands = (subbandTab[numSubbands] - 1) >> 8; + + + /* Reconstruct time domain samples. */ + for (band=0; band<4; band++) { + /* Perform the IMDCT step without overlapping. */ + if (band <= numBands) { + IMLT(&(pSnd->spectrum[band*256]), pSnd->IMDCT_buf, band&1,q->mdct_tmp); + } else + memset(pSnd->IMDCT_buf, 0, 512 * sizeof(float)); + + /* gain compensation and overlapping */ + gainCompensateAndOverlap (pSnd->IMDCT_buf, &(pSnd->prevFrame[band*256]), &(pOut[band*256]), + &((pSnd->gainBlock[1 - (pSnd->gcBlkSwitch)]).gBlock[band]), + &((pSnd->gainBlock[pSnd->gcBlkSwitch]).gBlock[band])); + } + + /* Swap the gain control buffers for the next frame. */ + pSnd->gcBlkSwitch ^= 1; + + return 0; +} + +/** + * Frame handling + * + * @param q Atrac3 private context + * @param databuf the input data + */ + +static int decodeFrame(ATRAC3Context *q, uint8_t* databuf) +{ + int result, i; + float *p1, *p2, *p3, *p4; + uint8_t *ptr1, *ptr2; + + if (q->codingMode == JOINT_STEREO) { + + /* channel coupling mode */ + /* decode Sound Unit 1 */ + init_get_bits(&q->gb,databuf,q->bits_per_frame); + + result = decodeChannelSoundUnit(q,&q->gb, q->pUnits, q->outSamples, 0, JOINT_STEREO); + if (result != 0) + return (result); + + /* Framedata of the su2 in the joint-stereo mode is encoded in + * reverse byte order so we need to swap it first. */ + ptr1 = databuf; + ptr2 = databuf+q->bytes_per_frame-1; + for (i = 0; i < (q->bytes_per_frame/2); i++, ptr1++, ptr2--) { + FFSWAP(uint8_t,*ptr1,*ptr2); + } + + /* Skip the sync codes (0xF8). */ + ptr1 = databuf; + for (i = 4; *ptr1 == 0xF8; i++, ptr1++) { + if (i >= q->bytes_per_frame) + return -1; + } + + + /* set the bitstream reader at the start of the second Sound Unit*/ + init_get_bits(&q->gb,ptr1,q->bits_per_frame); + + /* Fill the Weighting coeffs delay buffer */ + memmove(q->weighting_delay,&(q->weighting_delay[2]),4*sizeof(int)); + q->weighting_delay[4] = get_bits1(&q->gb); + q->weighting_delay[5] = get_bits(&q->gb,3); + + for (i = 0; i < 4; i++) { + q->matrix_coeff_index_prev[i] = q->matrix_coeff_index_now[i]; + q->matrix_coeff_index_now[i] = q->matrix_coeff_index_next[i]; + q->matrix_coeff_index_next[i] = get_bits(&q->gb,2); + } + + /* Decode Sound Unit 2. */ + result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[1], &q->outSamples[1024], 1, JOINT_STEREO); + if (result != 0) + return (result); + + /* Reconstruct the channel coefficients. */ + reverseMatrixing(q->outSamples, &q->outSamples[1024], q->matrix_coeff_index_prev, q->matrix_coeff_index_now); + + channelWeighting(q->outSamples, &q->outSamples[1024], q->weighting_delay); + + } else { + /* normal stereo mode or mono */ + /* Decode the channel sound units. */ + for (i=0 ; ichannels ; i++) { + + /* Set the bitstream reader at the start of a channel sound unit. */ + init_get_bits(&q->gb, databuf+((i*q->bytes_per_frame)/q->channels), (q->bits_per_frame)/q->channels); + + result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[i], &q->outSamples[i*1024], i, q->codingMode); + if (result != 0) + return (result); + } + } + + /* Apply the iQMF synthesis filter. */ + p1= q->outSamples; + for (i=0 ; ichannels ; i++) { + p2= p1+256; + p3= p2+256; + p4= p3+256; + iqmf (p1, p2, 256, p1, q->pUnits[i].delayBuf1, q->tempBuf); + iqmf (p4, p3, 256, p3, q->pUnits[i].delayBuf2, q->tempBuf); + iqmf (p1, p3, 512, p1, q->pUnits[i].delayBuf3, q->tempBuf); + p1 +=1024; + } + + return 0; +} + + +/** + * Atrac frame decoding + * + * @param avctx pointer to the AVCodecContext + */ + +static int atrac3_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size) { + ATRAC3Context *q = avctx->priv_data; + int result = 0, i; + uint8_t* databuf; + int16_t* samples = data; + + if (buf_size < avctx->block_align) + return buf_size; + + /* Check if we need to descramble and what buffer to pass on. */ + if (q->scrambled_stream) { + decode_bytes(buf, q->decoded_bytes_buffer, avctx->block_align); + databuf = q->decoded_bytes_buffer; + } else { + databuf = buf; + } + + result = decodeFrame(q, databuf); + + if (result != 0) { + av_log(NULL,AV_LOG_ERROR,"Frame decoding error!\n"); + return -1; + } + + if (q->channels == 1) { + /* mono */ + for (i = 0; i<1024; i++) + samples[i] = av_clip_int16(round(q->outSamples[i])); + *data_size = 1024 * sizeof(int16_t); + } else { + /* stereo */ + for (i = 0; i < 1024; i++) { + samples[i*2] = av_clip_int16(round(q->outSamples[i])); + samples[i*2+1] = av_clip_int16(round(q->outSamples[1024+i])); + } + *data_size = 2048 * sizeof(int16_t); + } + + return avctx->block_align; +} + + +/** + * Atrac3 initialization + * + * @param avctx pointer to the AVCodecContext + */ + +static int atrac3_decode_init(AVCodecContext *avctx) +{ + int i; + const uint8_t *edata_ptr = avctx->extradata; + ATRAC3Context *q = avctx->priv_data; + + /* Take data from the AVCodecContext (RM container). */ + q->sample_rate = avctx->sample_rate; + q->channels = avctx->channels; + q->bit_rate = avctx->bit_rate; + q->bits_per_frame = avctx->block_align * 8; + q->bytes_per_frame = avctx->block_align; + + /* Take care of the codec-specific extradata. */ + if (avctx->extradata_size == 14) { + /* Parse the extradata, WAV format */ + av_log(avctx,AV_LOG_DEBUG,"[0-1] %d\n",bytestream_get_le16(&edata_ptr)); //Unknown value always 1 + q->samples_per_channel = bytestream_get_le32(&edata_ptr); + q->codingMode = bytestream_get_le16(&edata_ptr); + av_log(avctx,AV_LOG_DEBUG,"[8-9] %d\n",bytestream_get_le16(&edata_ptr)); //Dupe of coding mode + q->frame_factor = bytestream_get_le16(&edata_ptr); //Unknown always 1 + av_log(avctx,AV_LOG_DEBUG,"[12-13] %d\n",bytestream_get_le16(&edata_ptr)); //Unknown always 0 + + /* setup */ + q->samples_per_frame = 1024 * q->channels; + q->atrac3version = 4; + q->delay = 0x88E; + if (q->codingMode) + q->codingMode = JOINT_STEREO; + else + q->codingMode = STEREO; + + q->scrambled_stream = 0; + + if ((q->bytes_per_frame == 96*q->channels*q->frame_factor) || (q->bytes_per_frame == 152*q->channels*q->frame_factor) || (q->bytes_per_frame == 192*q->channels*q->frame_factor)) { + } else { + av_log(avctx,AV_LOG_ERROR,"Unknown frame/channel/frame_factor configuration %d/%d/%d\n", q->bytes_per_frame, q->channels, q->frame_factor); + return -1; + } + + } else if (avctx->extradata_size == 10) { + /* Parse the extradata, RM format. */ + q->atrac3version = bytestream_get_be32(&edata_ptr); + q->samples_per_frame = bytestream_get_be16(&edata_ptr); + q->delay = bytestream_get_be16(&edata_ptr); + q->codingMode = bytestream_get_be16(&edata_ptr); + + q->samples_per_channel = q->samples_per_frame / q->channels; + q->scrambled_stream = 1; + + } else { + av_log(NULL,AV_LOG_ERROR,"Unknown extradata size %d.\n",avctx->extradata_size); + } + /* Check the extradata. */ + + if (q->atrac3version != 4) { + av_log(avctx,AV_LOG_ERROR,"Version %d != 4.\n",q->atrac3version); + return -1; + } + + if (q->samples_per_frame != 1024 && q->samples_per_frame != 2048) { + av_log(avctx,AV_LOG_ERROR,"Unknown amount of samples per frame %d.\n",q->samples_per_frame); + return -1; + } + + if (q->delay != 0x88E) { + av_log(avctx,AV_LOG_ERROR,"Unknown amount of delay %x != 0x88E.\n",q->delay); + return -1; + } + + if (q->codingMode == STEREO) { + av_log(avctx,AV_LOG_DEBUG,"Normal stereo detected.\n"); + } else if (q->codingMode == JOINT_STEREO) { + av_log(avctx,AV_LOG_DEBUG,"Joint stereo detected.\n"); + } else { + av_log(avctx,AV_LOG_ERROR,"Unknown channel coding mode %x!\n",q->codingMode); + return -1; + } + + if (avctx->channels <= 0 || avctx->channels > 2 /*|| ((avctx->channels * 1024) != q->samples_per_frame)*/) { + av_log(avctx,AV_LOG_ERROR,"Channel configuration error!\n"); + return -1; + } + + + if(avctx->block_align >= UINT_MAX/2) + return -1; + + /* Pad the data buffer with FF_INPUT_BUFFER_PADDING_SIZE, + * this is for the bitstream reader. */ + if ((q->decoded_bytes_buffer = av_mallocz((avctx->block_align+(4-avctx->block_align%4) + FF_INPUT_BUFFER_PADDING_SIZE))) == NULL) + return AVERROR(ENOMEM); + + + /* Initialize the VLC tables. */ + for (i=0 ; i<7 ; i++) { + init_vlc (&spectral_coeff_tab[i], 9, huff_tab_sizes[i], + huff_bits[i], 1, 1, + huff_codes[i], 1, 1, INIT_VLC_USE_STATIC); + } + + init_atrac3_transforms(q); + + /* Generate the scale factors. */ + for (i=0 ; i<64 ; i++) + SFTable[i] = pow(2.0, (i - 15) / 3.0); + + /* Generate gain tables. */ + for (i=0 ; i<16 ; i++) + gain_tab1[i] = powf (2.0, (4 - i)); + + for (i=-15 ; i<16 ; i++) + gain_tab2[i+15] = powf (2.0, i * -0.125); + + /* init the joint-stereo decoding data */ + q->weighting_delay[0] = 0; + q->weighting_delay[1] = 7; + q->weighting_delay[2] = 0; + q->weighting_delay[3] = 7; + q->weighting_delay[4] = 0; + q->weighting_delay[5] = 7; + + for (i=0; i<4; i++) { + q->matrix_coeff_index_prev[i] = 3; + q->matrix_coeff_index_now[i] = 3; + q->matrix_coeff_index_next[i] = 3; + } + + dsputil_init(&dsp, avctx); + + q->pUnits = av_mallocz(sizeof(channel_unit)*q->channels); + if (!q->pUnits) { + av_free(q->decoded_bytes_buffer); + return AVERROR(ENOMEM); + } + + return 0; +} + + +AVCodec atrac3_decoder = +{ + .name = "atrac 3", + .type = CODEC_TYPE_AUDIO, + .id = CODEC_ID_ATRAC3, + .priv_data_size = sizeof(ATRAC3Context), + .init = atrac3_decode_init, + .close = atrac3_decode_close, + .decode = atrac3_decode_frame, +}; diff --git a/contrib/ffmpeg/libavcodec/atrac3data.h b/contrib/ffmpeg/libavcodec/atrac3data.h new file mode 100644 index 000000000..786629d03 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/atrac3data.h @@ -0,0 +1,140 @@ +/* + * Atrac 3 compatible decoder data + * Copyright (c) 2006-2007 Maxim Poliakovski + * Copyright (c) 2006-2007 Benjamin Larsson + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file atrac3data.h + * Atrac 3 AKA RealAudio 8 compatible decoder data + */ + +#ifndef FFMPEG_ATRAC3DATA_H +#define FFMPEG_ATRAC3DATA_H + +#include + +/* VLC tables */ + +static const uint8_t huffcode1[9] = { + 0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F, +}; + +static const uint8_t huffbits1[9] = { + 1,3,3,4,4,5,5,5,5, +}; + +static const uint8_t huffcode2[5] = { + 0x0,0x4,0x5,0x6,0x7, +}; + +static const uint8_t huffbits2[5] = { + 1,3,3,3,3, +}; + +static const uint8_t huffcode3[7] = { +0x0,0x4,0x5,0xC,0xD,0xE,0xF, +}; + +static const uint8_t huffbits3[7] = { + 1,3,3,4,4,4,4, +}; + +static const uint8_t huffcode4[9] = { + 0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F, +}; + +static const uint8_t huffbits4[9] = { + 1,3,3,4,4,5,5,5,5, +}; + +static const uint8_t huffcode5[15] = { + 0x0,0x2,0x3,0x8,0x9,0xA,0xB,0x1C,0x1D,0x3C,0x3D,0x3E,0x3F,0xC,0xD, +}; + +static const uint8_t huffbits5[15] = { + 2,3,3,4,4,4,4,5,5,6,6,6,6,4,4 +}; + +static const uint8_t huffcode6[31] = { + 0x0,0x2,0x3,0x4,0x5,0x6,0x7,0x14,0x15,0x16,0x17,0x18,0x19,0x34,0x35, + 0x36,0x37,0x38,0x39,0x3A,0x3B,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,0x8,0x9, +}; + +static const uint8_t huffbits6[31] = { + 3,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,4,4 +}; + +static const uint8_t huffcode7[63] = { + 0x0,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF,0x10,0x11,0x24,0x25,0x26,0x27,0x28, + 0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x68,0x69,0x6A,0x6B,0x6C, + 0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2, + 0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,0x2,0x3, +}; + +static const uint8_t huffbits7[63] = { + 3,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,4,4 +}; + +static const uint8_t huff_tab_sizes[7] = { + 9, 5, 7, 9, 15, 31, 63, +}; + +static const uint8_t* huff_codes[7] = { + huffcode1,huffcode2,huffcode3,huffcode4,huffcode5,huffcode6,huffcode7, +}; + +static const uint8_t* huff_bits[7] = { + huffbits1,huffbits2,huffbits3,huffbits4,huffbits5,huffbits6,huffbits7, +}; + +/* selector tables */ + +static const uint8_t CLCLengthTab[8] = {0, 4, 3, 3, 4, 4, 5, 6}; +static const int8_t seTab_0[4] = {0, 1, -2, -1}; +static const int8_t decTable1[18] = {0,0, 0,1, 0,-1, 1,0, -1,0, 1,1, 1,-1, -1,1, -1,-1}; + + +/* tables for the scalefactor decoding */ + +static const float iMaxQuant[8] = { + 0.0, 1.0/1.5, 1.0/2.5, 1.0/3.5, 1.0/4.5, 1.0/7.5, 1.0/15.5, 1.0/31.5 +}; + +static const uint16_t subbandTab[33] = { + 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, + 256, 288, 320, 352, 384, 416, 448, 480, 512, 576, 640, 704, 768, 896, 1024 +}; + +/* transform data */ + +static const float qmf_48tap_half[24] = { + -0.00001461907, -0.00009205479, -0.000056157569, 0.00030117269, + 0.0002422519,-0.00085293897, -0.0005205574, 0.0020340169, + 0.00078333891, -0.0042153862, -0.00075614988, 0.0078402944, + -0.000061169922, -0.01344162, 0.0024626821, 0.021736089, + -0.007801671, -0.034090221, 0.01880949, 0.054326009, + -0.043596379, -0.099384367, 0.13207909, 0.46424159 +}; + +/* joint stereo related tables */ +static const float matrixCoeffs[8] = {0.0, 2.0, 2.0, 2.0, 0.0, 0.0, 1.0, 1.0}; + +#endif /* FFMPEG_ATRAC3DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/audioconvert.c b/contrib/ffmpeg/libavcodec/audioconvert.c index e6291ac6d..4c021219f 100644 --- a/contrib/ffmpeg/libavcodec/audioconvert.c +++ b/contrib/ffmpeg/libavcodec/audioconvert.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -54,8 +53,8 @@ if(fmt_pair == ofmt + 5*ifmt){\ }while(po < end);\ } -//FIXME put things below under ifdefs so we dont waste space for cases no codec will need -//FIXME rounding and cliping ? +//FIXME put things below under ifdefs so we do not waste space for cases no codec will need +//FIXME rounding and clipping ? CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_U8 , *(uint8_t*)pi) else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_U8 , (*(uint8_t*)pi - 0x80)<<8) diff --git a/contrib/ffmpeg/libavcodec/avcodec.h b/contrib/ffmpeg/libavcodec/avcodec.h index 1d8427a9d..32dd4da28 100644 --- a/contrib/ffmpeg/libavcodec/avcodec.h +++ b/contrib/ffmpeg/libavcodec/avcodec.h @@ -15,30 +15,31 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVCODEC_H -#define AVCODEC_H +#ifndef FFMPEG_AVCODEC_H +#define FFMPEG_AVCODEC_H /** * @file avcodec.h - * external api header. + * external API header */ -#ifdef __cplusplus -extern "C" { -#endif - -#include "avutil.h" +#include "libavutil/avutil.h" #include /* size_t */ -#define AV_STRINGIFY(s) AV_TOSTRING(s) -#define AV_TOSTRING(s) #s +#define LIBAVCODEC_VERSION_MAJOR 51 +#define LIBAVCODEC_VERSION_MINOR 50 +#define LIBAVCODEC_VERSION_MICRO 1 -#define LIBAVCODEC_VERSION_INT ((51<<16)+(40<<8)+2) -#define LIBAVCODEC_VERSION 51.40.2 +#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ + LIBAVCODEC_VERSION_MINOR, \ + LIBAVCODEC_VERSION_MICRO) +#define LIBAVCODEC_VERSION AV_VERSION(LIBAVCODEC_VERSION_MAJOR, \ + LIBAVCODEC_VERSION_MINOR, \ + LIBAVCODEC_VERSION_MICRO) #define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT #define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION) @@ -48,15 +49,21 @@ extern "C" { #define AV_TIME_BASE_Q (AVRational){1, AV_TIME_BASE} /** + * Identifies the syntax and semantics of the bitstream. + * The principle is roughly: + * Two decoders with the same ID can decode the same streams. + * Two encoders with the same ID can encode compatible streams. + * There may be slight deviations from the principle due to implementation + * details. * - * if you add a codec id to this list add it so that - * 1. no value of a existing codec id changes (that would break ABI) - * 2. closest to similar codecs + * If you add a codec ID to this list, add it so that + * 1. no value of a existing codec ID changes (that would break ABI), + * 2. it is as close as possible to similar codecs. */ enum CodecID { CODEC_ID_NONE, CODEC_ID_MPEG1VIDEO, - CODEC_ID_MPEG2VIDEO, /* prefered ID for MPEG Video 1 or 2 decoding */ + CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding CODEC_ID_MPEG2VIDEO_XVMC, CODEC_ID_H261, CODEC_ID_H263, @@ -159,8 +166,20 @@ enum CodecID { CODEC_ID_DXA, CODEC_ID_DNXHD, CODEC_ID_THP, - - /* various pcm "codecs" */ + CODEC_ID_SGI, + CODEC_ID_C93, + CODEC_ID_BETHSOFTVID, + CODEC_ID_PTX, + CODEC_ID_TXD, + CODEC_ID_VP6A, + CODEC_ID_AMV, + CODEC_ID_VB, + CODEC_ID_PCX, + CODEC_ID_SUNRAST, + CODEC_ID_INDEO4, + CODEC_ID_INDEO5, + + /* various PCM "codecs" */ CODEC_ID_PCM_S16LE= 0x10000, CODEC_ID_PCM_S16BE, CODEC_ID_PCM_U16LE, @@ -178,8 +197,10 @@ enum CodecID { CODEC_ID_PCM_U24LE, CODEC_ID_PCM_U24BE, CODEC_ID_PCM_S24DAUD, + CODEC_ID_PCM_ZORK, + CODEC_ID_PCM_S16LE_PLANAR, - /* various adpcm codecs */ + /* various ADPCM codecs */ CODEC_ID_ADPCM_IMA_QT= 0x11000, CODEC_ID_ADPCM_IMA_WAV, CODEC_ID_ADPCM_IMA_DK3, @@ -198,6 +219,14 @@ enum CodecID { CODEC_ID_ADPCM_SBPRO_4, CODEC_ID_ADPCM_SBPRO_3, CODEC_ID_ADPCM_SBPRO_2, + CODEC_ID_ADPCM_THP, + CODEC_ID_ADPCM_IMA_AMV, + CODEC_ID_ADPCM_EA_R1, + CODEC_ID_ADPCM_EA_R3, + CODEC_ID_ADPCM_EA_R2, + CODEC_ID_ADPCM_IMA_EA_SEAD, + CODEC_ID_ADPCM_IMA_EA_EACS, + CODEC_ID_ADPCM_EA_XAS, /* AMR */ CODEC_ID_AMR_NB= 0x12000, @@ -214,7 +243,7 @@ enum CodecID { CODEC_ID_SOL_DPCM, CODEC_ID_MP2= 0x15000, - CODEC_ID_MP3, /* prefered ID for MPEG Audio layer 1, 2 or3 decoding */ + CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3 CODEC_ID_AAC, #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) CODEC_ID_MPEG4AAC, @@ -236,7 +265,7 @@ enum CodecID { CODEC_ID_SHORTEN, CODEC_ID_ALAC, CODEC_ID_WESTWOOD_SND1, - CODEC_ID_GSM, /* As in Berlin toast format */ + CODEC_ID_GSM, ///< as in Berlin toast format CODEC_ID_QDM2, CODEC_ID_COOK, CODEC_ID_TRUESPEECH, @@ -248,18 +277,34 @@ enum CodecID { CODEC_ID_IMC, CODEC_ID_MUSEPACK7, CODEC_ID_MLP, - CODEC_ID_GSM_MS, /* As found in WAV */ + CODEC_ID_GSM_MS, /* as found in WAV */ + CODEC_ID_ATRAC3, + CODEC_ID_VOXWARE, + CODEC_ID_APE, + CODEC_ID_NELLYMOSER, + CODEC_ID_MUSEPACK8, + CODEC_ID_SPEEX, + CODEC_ID_WMAVOICE, + CODEC_ID_WMAPRO, + CODEC_ID_WMALOSSLESS, /* subtitle codecs */ CODEC_ID_DVD_SUBTITLE= 0x17000, CODEC_ID_DVB_SUBTITLE, + CODEC_ID_TEXT, ///< raw UTF-8 text + CODEC_ID_XSUB, + CODEC_ID_SSA, + CODEC_ID_MOV_TEXT, - CODEC_ID_MPEG2TS= 0x20000, /* _FAKE_ codec to indicate a raw MPEG2 transport - stream (only used by libavformat) */ + /* other specific kind of codecs (generaly used for attachments) */ + CODEC_ID_TTF= 0x18000, + + CODEC_ID_MPEG2TS= 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS + * stream (only used by libavformat) */ }; #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) -/* CODEC_ID_MP3LAME is absolete */ +/* CODEC_ID_MP3LAME is obsolete */ #define CODEC_ID_MP3LAME CODEC_ID_MP3 #define CODEC_ID_MPEG4AAC CODEC_ID_AAC #endif @@ -270,11 +315,14 @@ enum CodecType { CODEC_TYPE_AUDIO, CODEC_TYPE_DATA, CODEC_TYPE_SUBTITLE, + CODEC_TYPE_ATTACHMENT, CODEC_TYPE_NB }; -/* currently unused, may be used if 24/32 bits samples ever supported */ -/* all in native endian */ +/** + * Currently unused, may be used if 24/32 bits samples are ever supported. + * all in native-endian format + */ enum SampleFormat { SAMPLE_FMT_NONE = -1, SAMPLE_FMT_U8, ///< unsigned 8 bits @@ -289,34 +337,37 @@ enum SampleFormat { /** * Required number of additionally allocated bytes at the end of the input bitstream for decoding. - * this is mainly needed because some optimized bitstream readers read - * 32 or 64 bit at once and could read over the end
- * Note, if the first 23 bits of the additional bytes are not 0 then damaged - * MPEG bitstreams could cause overread and segfault + * This is mainly needed because some optimized bitstream readers read + * 32 or 64 bit at once and could read over the end.
+ * Note: If the first 23 bits of the additional bytes are not 0, then damaged + * MPEG bitstreams could cause overread and segfault. */ #define FF_INPUT_BUFFER_PADDING_SIZE 8 /** - * minimum encoding buffer size. - * used to avoid some checks during header writing + * minimum encoding buffer size + * Used to avoid some checks during header writing. */ #define FF_MIN_BUFFER_SIZE 16384 -/* motion estimation type, EPZS by default */ +/** + * motion estimation type. + */ enum Motion_Est_ID { - ME_ZERO = 1, + ME_ZERO = 1, ///< no search, that is use 0,0 vector whenever one is needed ME_FULL, ME_LOG, ME_PHODS, - ME_EPZS, - ME_X1, - ME_HEX, - ME_UMH, - ME_ITER, + ME_EPZS, ///< enhanced predictive zonal search + ME_X1, ///< reserved for experiments + ME_HEX, ///< hexagon based search + ME_UMH, ///< uneven multi-hexagon search + ME_ITER, ///< iterative search }; enum AVDiscard{ -//we leave some space between them for extensions (drop some keyframes for intra only or drop just some bidir frames) + /* We leave some space between them for extensions (drop some + * keyframes for intra-only or drop just some bidir frames). */ AVDISCARD_NONE =-16, ///< discard nothing AVDISCARD_DEFAULT= 0, ///< discard useless packets like 0 size packets in avi AVDISCARD_NONREF = 8, ///< discard all non reference @@ -328,73 +379,77 @@ enum AVDiscard{ typedef struct RcOverride{ int start_frame; int end_frame; - int qscale; // if this is 0 then quality_factor will be used instead + int qscale; // If this is 0 then quality_factor will be used instead. float quality_factor; } RcOverride; #define FF_MAX_B_FRAMES 16 /* encoding support - these flags can be passed in AVCodecContext.flags before initing - Note: not everything is supported yet. + These flags can be passed in AVCodecContext.flags before initialization. + Note: Not everything is supported yet. */ -#define CODEC_FLAG_QSCALE 0x0002 ///< use fixed qscale -#define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed / Advanced prediction for H263 -#define CODEC_FLAG_QPEL 0x0010 ///< use qpel MC -#define CODEC_FLAG_GMC 0x0020 ///< use GMC -#define CODEC_FLAG_MV0 0x0040 ///< always try a MB with MV=<0,0> -#define CODEC_FLAG_PART 0x0080 ///< use data partitioning -/* parent program guarantees that the input for b-frame containing streams is not written to - for at least s->max_b_frames+1 frames, if this is not set than the input will be copied */ +#define CODEC_FLAG_QSCALE 0x0002 ///< Use fixed qscale. +#define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed / advanced prediction for H.263. +#define CODEC_FLAG_QPEL 0x0010 ///< Use qpel MC. +#define CODEC_FLAG_GMC 0x0020 ///< Use GMC. +#define CODEC_FLAG_MV0 0x0040 ///< Always try a MB with MV=<0,0>. +#define CODEC_FLAG_PART 0x0080 ///< Use data partitioning. +/** + * The parent program guarantees that the input for B-frames containing + * streams is not written to for at least s->max_b_frames+1 frames, if + * this is not set the input will be copied. + */ #define CODEC_FLAG_INPUT_PRESERVED 0x0100 -#define CODEC_FLAG_PASS1 0x0200 ///< use internal 2pass ratecontrol in first pass mode -#define CODEC_FLAG_PASS2 0x0400 ///< use internal 2pass ratecontrol in second pass mode -#define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< use external huffman table (for mjpeg) -#define CODEC_FLAG_GRAY 0x2000 ///< only decode/encode grayscale -#define CODEC_FLAG_EMU_EDGE 0x4000///< don't draw edges -#define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding -#define CODEC_FLAG_TRUNCATED 0x00010000 /** input bitstream might be truncated at a random location instead - of only at frame boundaries */ -#define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< normalize adaptive quantization -#define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< use interlaced dct -#define CODEC_FLAG_LOW_DELAY 0x00080000 ///< force low delay -#define CODEC_FLAG_ALT_SCAN 0x00100000 ///< use alternate scan -#define CODEC_FLAG_TRELLIS_QUANT 0x00200000 ///< use trellis quantization -#define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< place global headers in extradata instead of every keyframe -#define CODEC_FLAG_BITEXACT 0x00800000 ///< use only bitexact stuff (except (i)dct) +#define CODEC_FLAG_PASS1 0x0200 ///< Use internal 2pass ratecontrol in first pass mode. +#define CODEC_FLAG_PASS2 0x0400 ///< Use internal 2pass ratecontrol in second pass mode. +#define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< Use external Huffman table (for MJPEG). +#define CODEC_FLAG_GRAY 0x2000 ///< Only decode/encode grayscale. +#define CODEC_FLAG_EMU_EDGE 0x4000 ///< Don't draw edges. +#define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding. +#define CODEC_FLAG_TRUNCATED 0x00010000 /** Input bitstream might be truncated at a random + location instead of only at frame boundaries. */ +#define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< Normalize adaptive quantization. +#define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< Use interlaced DCT. +#define CODEC_FLAG_LOW_DELAY 0x00080000 ///< Force low delay. +#define CODEC_FLAG_ALT_SCAN 0x00100000 ///< Use alternate scan. +#define CODEC_FLAG_TRELLIS_QUANT 0x00200000 ///< Use trellis quantization. +#define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< Place global headers in extradata instead of every keyframe. +#define CODEC_FLAG_BITEXACT 0x00800000 ///< Use only bitexact stuff (except (I)DCT). /* Fx : Flag for h263+ extra options */ #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) -#define CODEC_FLAG_H263P_AIC 0x01000000 ///< H263 Advanced intra coding / MPEG4 AC prediction (remove this) +#define CODEC_FLAG_H263P_AIC 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction (remove this) #endif -#define CODEC_FLAG_AC_PRED 0x01000000 ///< H263 Advanced intra coding / MPEG4 AC prediction -#define CODEC_FLAG_H263P_UMV 0x02000000 ///< Unlimited motion vector -#define CODEC_FLAG_CBP_RD 0x04000000 ///< use rate distortion optimization for cbp -#define CODEC_FLAG_QP_RD 0x08000000 ///< use rate distortion optimization for qp selectioon -#define CODEC_FLAG_H263P_AIV 0x00000008 ///< H263 Alternative inter vlc +#define CODEC_FLAG_AC_PRED 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction +#define CODEC_FLAG_H263P_UMV 0x02000000 ///< unlimited motion vector +#define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp. +#define CODEC_FLAG_QP_RD 0x08000000 ///< Use rate distortion optimization for qp selectioon. +#define CODEC_FLAG_H263P_AIV 0x00000008 ///< H.263 alternative inter VLC #define CODEC_FLAG_OBMC 0x00000001 ///< OBMC #define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter #define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000 #define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation -#define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< will reserve space for SVCD scan offset user data +#define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< Will reserve space for SVCD scan offset user data. #define CODEC_FLAG_CLOSED_GOP ((int)0x80000000) -#define CODEC_FLAG2_FAST 0x00000001 ///< allow non spec compliant speedup tricks -#define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< strictly enforce GOP size -#define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< skip bitstream encoding -#define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< place global headers at every keyframe instead of in extradata -#define CODEC_FLAG2_BPYRAMID 0x00000010 ///< H.264 allow b-frames to be used as references -#define CODEC_FLAG2_WPRED 0x00000020 ///< H.264 weighted biprediction for b-frames +#define CODEC_FLAG2_FAST 0x00000001 ///< Allow non spec compliant speedup tricks. +#define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< Strictly enforce GOP size. +#define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding. +#define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata. +#define CODEC_FLAG2_BPYRAMID 0x00000010 ///< H.264 allow B-frames to be used as references. +#define CODEC_FLAG2_WPRED 0x00000020 ///< H.264 weighted biprediction for B-frames #define CODEC_FLAG2_MIXED_REFS 0x00000040 ///< H.264 one reference per partition, as opposed to one reference per macroblock #define CODEC_FLAG2_8X8DCT 0x00000080 ///< H.264 high profile 8x8 transform #define CODEC_FLAG2_FASTPSKIP 0x00000100 ///< H.264 fast pskip #define CODEC_FLAG2_AUD 0x00000200 ///< H.264 access unit delimiters -#define CODEC_FLAG2_BRDO 0x00000400 ///< b-frame rate-distortion optimization -#define CODEC_FLAG2_INTRA_VLC 0x00000800 ///< use MPEG-2 intra VLC table -#define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< only do ME/MC (I frames -> ref, P frame -> ME+MC) -#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format -#define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skiping -#define CODEC_FLAG2_CHUNKS 0x00008000 ///< input bitstream might be truncated at a packet boundaries instead of only at frame boundaries -#define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< use MPEG-2 non linear quantizer +#define CODEC_FLAG2_BRDO 0x00000400 ///< B-frame rate-distortion optimization +#define CODEC_FLAG2_INTRA_VLC 0x00000800 ///< Use MPEG-2 intra VLC table. +#define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< Only do ME/MC (I frames -> ref, P frame -> ME+MC). +#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format. +#define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skipping +#define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries. +#define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< Use MPEG-2 nonlinear quantizer. +#define CODEC_FLAG2_BIT_RESERVOIR 0x00020000 ///< Use a bit reservoir when encoding if possible /* Unsupported options : * Syntax Arithmetic coding (SAC) @@ -403,21 +458,20 @@ typedef struct RcOverride{ /* /Fx */ /* codec capabilities */ -#define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< decoder can use draw_horiz_band callback +#define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< Decoder can use draw_horiz_band callback. /** * Codec uses get_buffer() for allocating buffers. * direct rendering method 1 */ #define CODEC_CAP_DR1 0x0002 -/* if 'parse_only' field is true, then avcodec_parse_frame() can be - used */ +/* If 'parse_only' field is true, then avcodec_parse_frame() can be used. */ #define CODEC_CAP_PARSE_ONLY 0x0004 #define CODEC_CAP_TRUNCATED 0x0008 -/* codec can export data for HW decoding (XvMC) */ +/* Codec can export data for HW decoding (XvMC). */ #define CODEC_CAP_HWACCEL 0x0010 /** - * codec has a non zero delay and needs to be feeded with NULL at the end to get the delayed data. - * if this is not set, the codec is guaranteed to never be feeded with NULL data + * Codec has a nonzero delay and needs to be fed with NULL at the end to get the delayed data. + * If this is not set, the codec is guaranteed to never be fed with NULL data. */ #define CODEC_CAP_DELAY 0x0020 /** @@ -426,16 +480,16 @@ typedef struct RcOverride{ */ #define CODEC_CAP_SMALL_LAST_FRAME 0x0040 -//the following defines may change, don't expect compatibility if you use them +//The following defines may change, don't expect compatibility if you use them. #define MB_TYPE_INTRA4x4 0x0001 -#define MB_TYPE_INTRA16x16 0x0002 //FIXME h264 specific -#define MB_TYPE_INTRA_PCM 0x0004 //FIXME h264 specific +#define MB_TYPE_INTRA16x16 0x0002 //FIXME H.264-specific +#define MB_TYPE_INTRA_PCM 0x0004 //FIXME H.264-specific #define MB_TYPE_16x16 0x0008 #define MB_TYPE_16x8 0x0010 #define MB_TYPE_8x16 0x0020 #define MB_TYPE_8x8 0x0040 #define MB_TYPE_INTERLACED 0x0080 -#define MB_TYPE_DIRECT2 0x0100 //FIXME +#define MB_TYPE_DIRECT2 0x0100 //FIXME #define MB_TYPE_ACPRED 0x0200 #define MB_TYPE_GMC 0x0400 #define MB_TYPE_SKIP 0x0800 @@ -452,28 +506,29 @@ typedef struct RcOverride{ /** * Pan Scan area. - * this specifies the area which should be displayed. Note there may be multiple such areas for one frame + * This specifies the area which should be displayed. + * Note there may be multiple such areas for one frame. */ typedef struct AVPanScan{ /** - * id. - * - encoding: set by user. - * - decoding: set by lavc + * id + * - encoding: Set by user. + * - decoding: Set by libavcodec. */ int id; /** * width and height in 1/16 pel - * - encoding: set by user. - * - decoding: set by lavc + * - encoding: Set by user. + * - decoding: Set by libavcodec. */ int width; int height; /** - * position of the top left corner in 1/16 pel for up to 3 fields/frames. - * - encoding: set by user. - * - decoding: set by lavc + * position of the top left corner in 1/16 pel for up to 3 fields/frames + * - encoding: Set by user. + * - decoding: Set by libavcodec. */ int16_t position[3][2]; }AVPanScan; @@ -481,99 +536,99 @@ typedef struct AVPanScan{ #define FF_COMMON_FRAME \ /**\ * pointer to the picture planes.\ - * this might be different from the first allocated byte\ + * This might be different from the first allocated byte\ * - encoding: \ * - decoding: \ */\ uint8_t *data[4];\ int linesize[4];\ /**\ - * pointer to the first allocated byte of the picture. can be used in get_buffer/release_buffer\ - * this isn't used by lavc unless the default get/release_buffer() is used\ + * pointer to the first allocated byte of the picture. Can be used in get_buffer/release_buffer.\ + * This isn't used by libavcodec unless the default get/release_buffer() is used.\ * - encoding: \ * - decoding: \ */\ uint8_t *base[4];\ /**\ * 1 -> keyframe, 0-> not\ - * - encoding: set by lavc\ - * - decoding: set by lavc\ + * - encoding: Set by libavcodec.\ + * - decoding: Set by libavcodec.\ */\ int key_frame;\ \ /**\ - * picture type of the frame, see ?_TYPE below.\ - * - encoding: set by lavc for coded_picture (and set by user for input)\ - * - decoding: set by lavc\ + * Picture type of the frame, see ?_TYPE below.\ + * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\ + * - decoding: Set by libavcodec.\ */\ int pict_type;\ \ /**\ * presentation timestamp in time_base units (time when frame should be shown to user)\ - * if AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed\ - * - encoding: MUST be set by user\ - * - decoding: set by lavc\ + * If AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed.\ + * - encoding: MUST be set by user.\ + * - decoding: Set by libavcodec.\ */\ int64_t pts;\ \ /**\ - * picture number in bitstream order.\ + * picture number in bitstream order\ * - encoding: set by\ - * - decoding: set by lavc\ + * - decoding: Set by libavcodec.\ */\ int coded_picture_number;\ /**\ - * picture number in display order.\ + * picture number in display order\ * - encoding: set by\ - * - decoding: set by lavc\ + * - decoding: Set by libavcodec.\ */\ int display_picture_number;\ \ /**\ * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) \ - * - encoding: set by lavc for coded_picture (and set by user for input)\ - * - decoding: set by lavc\ + * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\ + * - decoding: Set by libavcodec.\ */\ int quality; \ \ /**\ * buffer age (1->was last buffer and dint change, 2->..., ...).\ - * set to INT_MAX if the buffer has not been used yet \ + * Set to INT_MAX if the buffer has not been used yet.\ * - encoding: unused\ - * - decoding: MUST be set by get_buffer()\ + * - decoding: MUST be set by get_buffer().\ */\ int age;\ \ /**\ * is this picture used as reference\ * - encoding: unused\ - * - decoding: set by lavc (before get_buffer() call))\ + * - decoding: Set by libavcodec. (before get_buffer() call)).\ */\ int reference;\ \ /**\ * QP table\ * - encoding: unused\ - * - decoding: set by lavc\ + * - decoding: Set by libavcodec.\ */\ int8_t *qscale_table;\ /**\ * QP store stride\ * - encoding: unused\ - * - decoding: set by lavc\ + * - decoding: Set by libavcodec.\ */\ int qstride;\ \ /**\ - * mbskip_table[mb]>=1 if MB didnt change\ + * mbskip_table[mb]>=1 if MB didn't change\ * stride= mb_width = (width+15)>>4\ * - encoding: unused\ - * - decoding: set by lavc\ + * - decoding: Set by libavcodec.\ */\ uint8_t *mbskip_table;\ \ /**\ - * Motion vector table.\ + * motion vector table\ * @code\ * example:\ * int mv_sample_log2= 4 - motion_subsample_log2;\ @@ -581,16 +636,16 @@ typedef struct AVPanScan{ * int mv_stride= (mb_width << mv_sample_log2) + 1;\ * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];\ * @endcode\ - * - encoding: set by user\ - * - decoding: set by lavc\ + * - encoding: Set by user.\ + * - decoding: Set by libavcodec.\ */\ int16_t (*motion_val[2])[2];\ \ /**\ - * Macroblock type table\ + * macroblock type table\ * mb_type_base + mb_width + 2\ - * - encoding: set by user\ - * - decoding: set by lavc\ + * - encoding: Set by user.\ + * - decoding: Set by libavcodec.\ */\ uint32_t *mb_type;\ \ @@ -598,37 +653,37 @@ typedef struct AVPanScan{ * log2 of the size of the block which a single vector in motion_val represents: \ * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)\ * - encoding: unused\ - * - decoding: set by lavc\ + * - decoding: Set by libavcodec.\ */\ uint8_t motion_subsample_log2;\ \ /**\ * for some private data of the user\ * - encoding: unused\ - * - decoding: set by user\ + * - decoding: Set by user.\ */\ void *opaque;\ \ /**\ * error\ - * - encoding: set by lavc if flags&CODEC_FLAG_PSNR\ + * - encoding: Set by libavcodec. if flags&CODEC_FLAG_PSNR.\ * - decoding: unused\ */\ uint64_t error[4];\ \ /**\ - * type of the buffer (to keep track of who has to dealloc data[*])\ - * - encoding: set by the one who allocs it\ - * - decoding: set by the one who allocs it\ - * Note: user allocated (direct rendering) & internal buffers can not coexist currently\ + * type of the buffer (to keep track of who has to deallocate data[*])\ + * - encoding: Set by the one who allocates it.\ + * - decoding: Set by the one who allocates it.\ + * Note: User allocated (direct rendering) & internal buffers cannot coexist currently.\ */\ int type;\ \ /**\ - * when decoding, this signal how much the picture must be delayed.\ + * When decoding, this signals how much the picture must be delayed.\ * extra_delay = repeat_pict / (2*fps)\ * - encoding: unused\ - * - decoding: set by lavc\ + * - decoding: Set by libavcodec.\ */\ int repeat_pict;\ \ @@ -639,50 +694,50 @@ typedef struct AVPanScan{ \ /**\ * The content of the picture is interlaced.\ - * - encoding: set by user\ - * - decoding: set by lavc (default 0)\ + * - encoding: Set by user.\ + * - decoding: Set by libavcodec. (default 0)\ */\ int interlaced_frame;\ \ /**\ - * if the content is interlaced, is top field displayed first.\ - * - encoding: set by user\ - * - decoding: set by lavc\ + * If the content is interlaced, is top field displayed first.\ + * - encoding: Set by user.\ + * - decoding: Set by libavcodec.\ */\ int top_field_first;\ \ /**\ * Pan scan.\ - * - encoding: set by user\ - * - decoding: set by lavc\ + * - encoding: Set by user.\ + * - decoding: Set by libavcodec.\ */\ AVPanScan *pan_scan;\ \ /**\ - * tell user application that palette has changed from previous frame.\ + * Tell user application that palette has changed from previous frame.\ * - encoding: ??? (no palette-enabled encoder yet)\ - * - decoding: set by lavc (default 0)\ + * - decoding: Set by libavcodec. (default 0).\ */\ int palette_has_changed;\ \ /**\ - * Codec suggestion on buffer type if != 0\ + * codec suggestion on buffer type if != 0\ * - encoding: unused\ - * - decoding: set by lavc (before get_buffer() call))\ + * - decoding: Set by libavcodec. (before get_buffer() call)).\ */\ int buffer_hints;\ \ /**\ - * DCT coeffitients\ + * DCT coefficients\ * - encoding: unused\ - * - decoding: set by lavc\ + * - decoding: Set by libavcodec.\ */\ short *dct_coeff;\ \ /**\ - * Motion referece frame index\ - * - encoding: set by user\ - * - decoding: set by lavc\ + * motion referece frame index\ + * - encoding: Set by user.\ + * - decoding: Set by libavcodec.\ */\ int8_t *ref_index[2]; @@ -691,25 +746,31 @@ typedef struct AVPanScan{ #define FF_QSCALE_TYPE_H264 2 #define FF_BUFFER_TYPE_INTERNAL 1 -#define FF_BUFFER_TYPE_USER 2 ///< Direct rendering buffers (image is (de)allocated by user) -#define FF_BUFFER_TYPE_SHARED 4 ///< buffer from somewhere else, don't dealloc image (data/base), all other tables are not shared -#define FF_BUFFER_TYPE_COPY 8 ///< just a (modified) copy of some other buffer, don't dealloc anything +#define FF_BUFFER_TYPE_USER 2 ///< direct rendering buffers (image is (de)allocated by user) +#define FF_BUFFER_TYPE_SHARED 4 ///< Buffer from somewhere else; don't deallocate image (data/base), all other tables are not shared. +#define FF_BUFFER_TYPE_COPY 8 ///< Just a (modified) copy of some other buffer, don't deallocate anything. -#define FF_I_TYPE 1 // Intra -#define FF_P_TYPE 2 // Predicted -#define FF_B_TYPE 3 // Bi-dir predicted -#define FF_S_TYPE 4 // S(GMC)-VOP MPEG4 +#define FF_I_TYPE 1 // Intra +#define FF_P_TYPE 2 // Predicted +#define FF_B_TYPE 3 // Bi-dir predicted +#define FF_S_TYPE 4 // S(GMC)-VOP MPEG4 #define FF_SI_TYPE 5 #define FF_SP_TYPE 6 -#define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore) -#define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer -#define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content -#define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update) +#define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore). +#define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer. +#define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content. +#define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update). /** * Audio Video Frame. + * New fields can be added to the end of FF_COMMON_FRAME with minor version + * bumps. + * Removal, reordering and changes to existing fields require a major + * version bump. No fields should be added into AVFrame before or after + * FF_COMMON_FRAME! + * sizeof(AVFrame) must not be used outside libav*. */ typedef struct AVFrame { FF_COMMON_FRAME @@ -718,48 +779,52 @@ typedef struct AVFrame { #define DEFAULT_FRAME_RATE_BASE 1001000 /** - * main external api structure. + * main external API structure. + * New fields can be added to the end with minor version bumps. + * Removal, reordering and changes to existing fields require a major + * version bump. + * sizeof(AVCodecContext) must not be used outside libav*. */ typedef struct AVCodecContext { /** - * Info on struct for av_log + * information on struct for av_log * - set by avcodec_alloc_context */ AVClass *av_class; /** - * the average bitrate. - * - encoding: set by user. unused for constant quantizer encoding - * - decoding: set by lavc. 0 or some bitrate if this info is available in the stream + * the average bitrate + * - encoding: Set by user; unused for constant quantizer encoding. + * - decoding: Set by libavcodec. 0 or some bitrate if this info is available in the stream. */ int bit_rate; /** * number of bits the bitstream is allowed to diverge from the reference. * the reference can be CBR (for CBR pass1) or VBR (for pass2) - * - encoding: set by user. unused for constant quantizer encoding + * - encoding: Set by user; unused for constant quantizer encoding. * - decoding: unused */ int bit_rate_tolerance; /** * CODEC_FLAG_*. - * - encoding: set by user. - * - decoding: set by user. + * - encoding: Set by user. + * - decoding: Set by user. */ int flags; /** - * some codecs needs additionnal format info. It is stored here - * if any muxer uses this then ALL demuxers/parsers AND encoders for the specific codec MUST set it correctly - * too otherwise stream copy breaks - * in general use of this field by muxers is not recommanded - * - encoding: set by lavc. - * - decoding: set by lavc. (FIXME is this ok?) + * Some codecs need additional format info. It is stored here. + * If any muxer uses this then ALL demuxers/parsers AND encoders for the + * specific codec MUST set it correctly otherwise stream copy breaks. + * In general use of this field by muxers is not recommanded. + * - encoding: Set by libavcodec. + * - decoding: Set by libavcodec. (FIXME: Is this OK?) */ int sub_id; /** - * motion estimation algorithm used for video coding. + * Motion estimation algorithm used for video coding. * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex), * 8 (umh), 9 (iter) [7, 8 are x264 specific, 9 is snow specific] * - encoding: MUST be set by user. @@ -768,26 +833,26 @@ typedef struct AVCodecContext { int me_method; /** - * some codecs need / can use extra-data like huffman tables. - * mjpeg: huffman tables + * some codecs need / can use extradata like Huffman tables. + * mjpeg: Huffman tables * rv10: additional flags * mpeg4: global headers (they can be in the bitstream or here) - * the allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger - * then extradata_size to avoid prolems if its read with the bitstream reader - * the bytewise contents of extradata must not depend on the architecture or cpu endianness - * - encoding: set/allocated/freed by lavc. - * - decoding: set/allocated/freed by user. + * The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger + * than extradata_size to avoid prolems if it is read with the bitstream reader. + * The bytewise contents of extradata must not depend on the architecture or CPU endianness. + * - encoding: Set/allocated/freed by libavcodec. + * - decoding: Set/allocated/freed by user. */ uint8_t *extradata; int extradata_size; /** - * this is the fundamental unit of time (in seconds) in terms - * of which frame timestamps are represented. for fixed-fps content, + * This is the fundamental unit of time (in seconds) in terms + * of which frame timestamps are represented. For fixed-fps content, * timebase should be 1/framerate and timestamp increments should be * identically 1. - * - encoding: MUST be set by user - * - decoding: set by lavc. + * - encoding: MUST be set by user. + * - decoding: Set by libavcodec. */ AVRational time_base; @@ -795,43 +860,43 @@ typedef struct AVCodecContext { /** * picture width / height. * - encoding: MUST be set by user. - * - decoding: set by lavc. - * Note, for compatibility its possible to set this instead of - * coded_width/height before decoding + * - decoding: Set by libavcodec. + * Note: For compatibility it is possible to set this instead of + * coded_width/height before decoding. */ int width, height; #define FF_ASPECT_EXTENDED 15 /** - * the number of pictures in a group of pitures, or 0 for intra_only. - * - encoding: set by user. + * the number of pictures in a group of pictures, or 0 for intra_only + * - encoding: Set by user. * - decoding: unused */ int gop_size; /** - * pixel format, see PIX_FMT_xxx. - * - encoding: set by user. - * - decoding: set by lavc. + * Pixel format, see PIX_FMT_xxx. + * - encoding: Set by user. + * - decoding: Set by libavcodec. */ enum PixelFormat pix_fmt; /** - * Frame rate emulation. If not zero lower layer (i.e. format handler) + * Frame rate emulation. If not zero, the lower layer (i.e. format handler) * has to read frames at native frame rate. - * - encoding: set by user. - * - decoding: unused. + * - encoding: Set by user. + * - decoding: unused */ int rate_emu; /** - * if non NULL, 'draw_horiz_band' is called by the libavcodec - * decoder to draw an horizontal band. It improve cache usage. Not + * If non NULL, 'draw_horiz_band' is called by the libavcodec + * decoder to draw a horizontal band. It improves cache usage. Not * all codecs can do that. You must check the codec capabilities - * before + * beforehand. * - encoding: unused - * - decoding: set by user. + * - decoding: Set by user. * @param height the height of the slice * @param y the y position of the slice * @param type 1->top field, 2->bottom field, 3->frame @@ -842,28 +907,28 @@ typedef struct AVCodecContext { int y, int type, int height); /* audio only */ - int sample_rate; ///< samples per sec + int sample_rate; ///< samples per second int channels; /** - * audio sample format. - * - encoding: set by user. - * - decoding: set by lavc. + * audio sample format + * - encoding: Set by user. + * - decoding: Set by libavcodec. */ - enum SampleFormat sample_fmt; ///< sample format, currenly unused + enum SampleFormat sample_fmt; ///< sample format, currently unused - /* the following data should not be initialized */ + /* The following data should not be initialized. */ /** - * samples per packet. initialized when calling 'init' + * Samples per packet, initialized when calling 'init'. */ int frame_size; int frame_number; ///< audio or video frame number - int real_pict_num; ///< returns the real picture number of previous encoded frame + int real_pict_num; ///< Returns the real picture number of previous encoded frame. /** - * number of frames the decoded output will be delayed relative to + * Number of frames the decoded output will be delayed relative to * the encoded input. - * - encoding: set by lavc. + * - encoding: Set by libavcodec. * - decoding: unused */ int delay; @@ -873,37 +938,37 @@ typedef struct AVCodecContext { float qblur; ///< amount of qscale smoothing over time (0.0-1.0) /** - * minimum quantizer. - * - encoding: set by user. + * minimum quantizer + * - encoding: Set by user. * - decoding: unused */ int qmin; /** - * maximum quantizer. - * - encoding: set by user. + * maximum quantizer + * - encoding: Set by user. * - decoding: unused */ int qmax; /** - * maximum quantizer difference between frames. - * - encoding: set by user. + * maximum quantizer difference between frames + * - encoding: Set by user. * - decoding: unused */ int max_qdiff; /** - * maximum number of b frames between non b frames. - * note: the output will be delayed by max_b_frames+1 relative to the input - * - encoding: set by user. + * maximum number of B-frames between non-B-frames + * Note: The output will be delayed by max_b_frames+1 relative to the input. + * - encoding: Set by user. * - decoding: unused */ int max_b_frames; /** - * qscale factor between ip and b frames. - * - encoding: set by user. + * qscale factor between IP and B-frames + * - encoding: Set by user. * - decoding: unused */ float b_quant_factor; @@ -915,9 +980,9 @@ typedef struct AVCodecContext { int b_frame_strategy; /** - * hurry up amount. + * hurry up amount * - encoding: unused - * - decoding: set by user. 1-> skip b frames, 2-> skip idct/dequant too, 5-> skip everything except header + * - decoding: Set by user. 1-> Skip B-frames, 2-> Skip IDCT/dequant too, 5-> Skip everything except header * @deprecated Deprecated in favor of skip_idct and skip_frame. */ int hurry_up; @@ -932,19 +997,19 @@ typedef struct AVCodecContext { #endif int rtp_payload_size; /* The size of the RTP payload: the coder will */ - /* do it's best to deliver a chunk with size */ + /* do its best to deliver a chunk with size */ /* below rtp_payload_size, the chunk will start */ - /* with a start code on some codecs like H.263 */ + /* with a start code on some codecs like H.263. */ /* This doesn't take account of any particular */ - /* headers inside the transmited RTP payload */ + /* headers inside the transmitted RTP payload. */ - /* The RTP callback: This function is called */ - /* every time the encoder has a packet to send */ - /* Depends on the encoder if the data starts */ - /* with a Start Code (it should) H.263 does. */ - /* mb_nb contains the number of macroblocks */ - /* encoded in the RTP payload */ + /* The RTP callback: This function is called */ + /* every time the encoder has a packet to send. */ + /* It depends on the encoder if the data starts */ + /* with a Start Code (it should). H.263 does. */ + /* mb_nb contains the number of macroblocks */ + /* encoded in the RTP payload. */ void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb); /* statistics, used for 2-pass encoding */ @@ -958,16 +1023,16 @@ typedef struct AVCodecContext { int misc_bits; /** - * number of bits used for the previously encoded frame. - * - encoding: set by lavc + * number of bits used for the previously encoded frame + * - encoding: Set by libavcodec. * - decoding: unused */ int frame_bits; /** - * private data of the user, can be used to carry app specific stuff. - * - encoding: set by user - * - decoding: set by user + * Private data of the user, can be used to carry app specific stuff. + * - encoding: Set by user. + * - decoding: Set by user. */ void *opaque; @@ -977,23 +1042,23 @@ typedef struct AVCodecContext { /** * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A'). - * this is used to workaround some encoder bugs - * a demuxer should set this to what is stored in the field used to identify the codec - * if there are mutiple such fields in a container then the demuxer should choose the one - * which maximizes the information about the used codec - * if the codec tag field in a container is larger then 32bit then the demxuer should - * remap the longer id to 32bit with a table or other structure alternatively a new + * This is used to work around some encoder bugs. + * A demuxer should set this to what is stored in the field used to identify the codec. + * If there are multiple such fields in a container then the demuxer should choose the one + * which maximizes the information about the used codec. + * If the codec tag field in a container is larger then 32 bits then the demuxer should + * remap the longer ID to 32 bits with a table or other structure. Alternatively a new * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated - * first - * - encoding: set by user, if not then the default based on codec_id will be used - * - decoding: set by user, will be converted to upper case by lavc during init + * first. + * - encoding: Set by user, if not then the default based on codec_id will be used. + * - decoding: Set by user, will be converted to uppercase by libavcodec during init. */ unsigned int codec_tag; /** - * workaround bugs in encoders which sometimes cannot be detected automatically. - * - encoding: set by user - * - decoding: set by user + * Work around bugs in encoders which sometimes cannot be detected automatically. + * - encoding: Set by user + * - decoding: Set by user */ int workaround_bugs; #define FF_BUG_AUTODETECT 1 ///< autodetection @@ -1002,7 +1067,7 @@ typedef struct AVCodecContext { #define FF_BUG_UMP4 8 #define FF_BUG_NO_PADDING 16 #define FF_BUG_AMV 32 -#define FF_BUG_AC_VLC 0 ///< will be removed, libavcodec can now handle these non compliant files by default +#define FF_BUG_AC_VLC 0 ///< Will be removed, libavcodec can now handle these non-compliant files by default. #define FF_BUG_QPEL_CHROMA 64 #define FF_BUG_STD_QPEL 128 #define FF_BUG_QPEL_CHROMA2 256 @@ -1010,49 +1075,49 @@ typedef struct AVCodecContext { #define FF_BUG_EDGE 1024 #define FF_BUG_HPEL_CHROMA 2048 #define FF_BUG_DC_CLIP 4096 -#define FF_BUG_MS 8192 ///< workaround various bugs in microsofts broken decoders -//#define FF_BUG_FAKE_SCALABILITY 16 //autodetection should work 100% +#define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders. +//#define FF_BUG_FAKE_SCALABILITY 16 //Autodetection should work 100%. /** - * luma single coeff elimination threshold. - * - encoding: set by user + * luma single coefficient elimination threshold + * - encoding: Set by user. * - decoding: unused */ int luma_elim_threshold; /** - * chroma single coeff elimination threshold. - * - encoding: set by user + * chroma single coeff elimination threshold + * - encoding: Set by user. * - decoding: unused */ int chroma_elim_threshold; /** - * strictly follow the std (MPEG4, ...). - * - encoding: set by user + * strictly follow the standard (MPEG4, ...). + * - encoding: Set by user. * - decoding: unused */ int strict_std_compliance; -#define FF_COMPLIANCE_VERY_STRICT 2 ///< strictly conform to a older more strict version of the spec or reference software -#define FF_COMPLIANCE_STRICT 1 ///< strictly conform to all the things in the spec no matter what consequences +#define FF_COMPLIANCE_VERY_STRICT 2 ///< Strictly conform to a older more strict version of the spec or reference software. +#define FF_COMPLIANCE_STRICT 1 ///< Strictly conform to all the things in the spec no matter what consequences. #define FF_COMPLIANCE_NORMAL 0 -#define FF_COMPLIANCE_INOFFICIAL -1 ///< allow inofficial extensions -#define FF_COMPLIANCE_EXPERIMENTAL -2 ///< allow non standarized experimental things +#define FF_COMPLIANCE_INOFFICIAL -1 ///< Allow inofficial extensions. +#define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things. /** - * qscale offset between ip and b frames. - * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset) - * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset) - * - encoding: set by user. + * qscale offset between IP and B-frames + * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset). + * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset). + * - encoding: Set by user. * - decoding: unused */ float b_quant_offset; /** - * error resilience higher values will detect more errors but may missdetect - * some more or less valid parts as errors. + * Error resilience; higher values will detect more errors but may + * misdetect some more or less valid parts as errors. * - encoding: unused - * - decoding: set by user + * - decoding: Set by user. */ int error_resilience; #define FF_ER_CAREFUL 1 @@ -1061,67 +1126,67 @@ typedef struct AVCodecContext { #define FF_ER_VERY_AGGRESSIVE 4 /** - * called at the beginning of each frame to get a buffer for it. - * if pic.reference is set then the frame will be read later by lavc + * Called at the beginning of each frame to get a buffer for it. + * If pic.reference is set then the frame will be read later by libavcodec. * avcodec_align_dimensions() should be used to find the required width and - * height, as they normally need to be rounded up to the next multiple of 16 + * height, as they normally need to be rounded up to the next multiple of 16. * - encoding: unused - * - decoding: set by lavc, user can override + * - decoding: Set by libavcodec., user can override. */ int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic); /** - * called to release buffers which where allocated with get_buffer. - * a released buffer can be reused in get_buffer() - * pic.data[*] must be set to NULL + * Called to release buffers which where allocated with get_buffer. + * A released buffer can be reused in get_buffer(). + * pic.data[*] must be set to NULL. * - encoding: unused - * - decoding: set by lavc, user can override + * - decoding: Set by libavcodec., user can override. */ void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic); /** - * if 1 the stream has a 1 frame delay during decoding. - * - encoding: set by lavc - * - decoding: set by lavc + * If 1 the stream has a 1 frame delay during decoding. + * - encoding: Set by libavcodec. + * - decoding: Set by libavcodec. */ int has_b_frames; /** * number of bytes per packet if constant and known or 0 - * used by some WAV based audio codecs + * Used by some WAV based audio codecs. */ int block_align; - int parse_only; /* - decoding only: if true, only parsing is done + int parse_only; /* - decoding only: If true, only parsing is done (function avcodec_parse_frame()). The frame data is returned. Only MPEG codecs support this now. */ /** - * 0-> h263 quant 1-> mpeg quant. - * - encoding: set by user. + * 0-> h263 quant 1-> mpeg quant + * - encoding: Set by user. * - decoding: unused */ int mpeg_quant; /** - * pass1 encoding statistics output buffer. - * - encoding: set by lavc + * pass1 encoding statistics output buffer + * - encoding: Set by libavcodec. * - decoding: unused */ char *stats_out; /** - * pass2 encoding statistics input buffer. - * concatenated stuff from stats_out of pass1 should be placed here - * - encoding: allocated/set/freed by user + * pass2 encoding statistics input buffer + * Concatenated stuff from stats_out of pass1 should be placed here. + * - encoding: Allocated/set/freed by user. * - decoding: unused */ char *stats_in; /** - * ratecontrol qmin qmax limiting method. - * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax - * - encoding: set by user. + * ratecontrol qmin qmax limiting method + * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax. + * - encoding: Set by user. * - decoding: unused */ float rc_qsquish; @@ -1130,68 +1195,68 @@ typedef struct AVCodecContext { int rc_qmod_freq; /** - * ratecontrol override, see RcOverride. - * - encoding: allocated/set/freed by user. + * ratecontrol override, see RcOverride + * - encoding: Allocated/set/freed by user. * - decoding: unused */ RcOverride *rc_override; int rc_override_count; /** - * rate control equation. - * - encoding: set by user + * rate control equation + * - encoding: Set by user * - decoding: unused */ - char *rc_eq; + const char *rc_eq; /** - * maximum bitrate. - * - encoding: set by user. + * maximum bitrate + * - encoding: Set by user. * - decoding: unused */ int rc_max_rate; /** - * minimum bitrate. - * - encoding: set by user. + * minimum bitrate + * - encoding: Set by user. * - decoding: unused */ int rc_min_rate; /** - * decoder bitstream buffer size. - * - encoding: set by user. + * decoder bitstream buffer size + * - encoding: Set by user. * - decoding: unused */ int rc_buffer_size; float rc_buffer_aggressivity; /** - * qscale factor between p and i frames. - * if > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset) - * if < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset) - * - encoding: set by user. + * qscale factor between P and I-frames + * If > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset). + * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset). + * - encoding: Set by user. * - decoding: unused */ float i_quant_factor; /** - * qscale offset between p and i frames. - * - encoding: set by user. + * qscale offset between P and I-frames + * - encoding: Set by user. * - decoding: unused */ float i_quant_offset; /** - * initial complexity for pass1 ratecontrol. - * - encoding: set by user. + * initial complexity for pass1 ratecontrol + * - encoding: Set by user. * - decoding: unused */ float rc_initial_cplx; /** - * dct algorithm, see FF_DCT_* below. - * - encoding: set by user + * DCT algorithm, see FF_DCT_* below + * - encoding: Set by user. * - decoding: unused */ int dct_algo; @@ -1204,86 +1269,91 @@ typedef struct AVCodecContext { #define FF_DCT_FAAN 6 /** - * luminance masking (0-> disabled). - * - encoding: set by user + * luminance masking (0-> disabled) + * - encoding: Set by user. * - decoding: unused */ float lumi_masking; /** - * temporary complexity masking (0-> disabled). - * - encoding: set by user + * temporary complexity masking (0-> disabled) + * - encoding: Set by user. * - decoding: unused */ float temporal_cplx_masking; /** - * spatial complexity masking (0-> disabled). - * - encoding: set by user + * spatial complexity masking (0-> disabled) + * - encoding: Set by user. * - decoding: unused */ float spatial_cplx_masking; /** - * p block masking (0-> disabled). - * - encoding: set by user + * p block masking (0-> disabled) + * - encoding: Set by user. * - decoding: unused */ float p_masking; /** - * darkness masking (0-> disabled). - * - encoding: set by user + * darkness masking (0-> disabled) + * - encoding: Set by user. * - decoding: unused */ float dark_masking; +#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) /* for binary compatibility */ int unused; +#endif /** - * idct algorithm, see FF_IDCT_* below. - * - encoding: set by user - * - decoding: set by user + * IDCT algorithm, see FF_IDCT_* below. + * - encoding: Set by user. + * - decoding: Set by user. */ int idct_algo; -#define FF_IDCT_AUTO 0 -#define FF_IDCT_INT 1 -#define FF_IDCT_SIMPLE 2 -#define FF_IDCT_SIMPLEMMX 3 -#define FF_IDCT_LIBMPEG2MMX 4 -#define FF_IDCT_PS2 5 -#define FF_IDCT_MLIB 6 -#define FF_IDCT_ARM 7 -#define FF_IDCT_ALTIVEC 8 -#define FF_IDCT_SH4 9 -#define FF_IDCT_SIMPLEARM 10 -#define FF_IDCT_H264 11 -#define FF_IDCT_VP3 12 -#define FF_IDCT_IPP 13 -#define FF_IDCT_XVIDMMX 14 -#define FF_IDCT_CAVS 15 +#define FF_IDCT_AUTO 0 +#define FF_IDCT_INT 1 +#define FF_IDCT_SIMPLE 2 +#define FF_IDCT_SIMPLEMMX 3 +#define FF_IDCT_LIBMPEG2MMX 4 +#define FF_IDCT_PS2 5 +#define FF_IDCT_MLIB 6 +#define FF_IDCT_ARM 7 +#define FF_IDCT_ALTIVEC 8 +#define FF_IDCT_SH4 9 +#define FF_IDCT_SIMPLEARM 10 +#define FF_IDCT_H264 11 +#define FF_IDCT_VP3 12 +#define FF_IDCT_IPP 13 +#define FF_IDCT_XVIDMMX 14 +#define FF_IDCT_CAVS 15 #define FF_IDCT_SIMPLEARMV5TE 16 -#define FF_IDCT_SIMPLEARMV6 17 +#define FF_IDCT_SIMPLEARMV6 17 +#define FF_IDCT_SIMPLEVIS 18 +#define FF_IDCT_WMV2 19 +#define FF_IDCT_FAAN 20 /** - * slice count. - * - encoding: set by lavc - * - decoding: set by user (or 0) + * slice count + * - encoding: Set by libavcodec. + * - decoding: Set by user (or 0). */ int slice_count; /** - * slice offsets in the frame in bytes. - * - encoding: set/allocated by lavc - * - decoding: set/allocated by user (or NULL) + * slice offsets in the frame in bytes + * - encoding: Set/allocated by libavcodec. + * - decoding: Set/allocated by user (or NULL). */ int *slice_offset; /** - * error concealment flags. + * error concealment flags * - encoding: unused - * - decoding: set by user + * - decoding: Set by user. */ int error_concealment; #define FF_EC_GUESS_MVS 1 @@ -1293,35 +1363,33 @@ typedef struct AVCodecContext { * dsp_mask could be add used to disable unwanted CPU features * CPU features (i.e. MMX, SSE. ...) * - * with FORCE flag you may instead enable given CPU features - * (Dangerous: usable in case of misdetection, improper usage however will - * result into program crash) + * With the FORCE flag you may instead enable given CPU features. + * (Dangerous: Usable in case of misdetection, improper usage however will + * result into program crash.) */ unsigned dsp_mask; -#define FF_MM_FORCE 0x80000000 /* force usage of selected flags (OR) */ +#define FF_MM_FORCE 0x80000000 /* Force usage of selected flags (OR) */ /* lower 16 bits - CPU features */ -#ifdef HAVE_MMX -#define FF_MM_MMX 0x0001 /* standard MMX */ -#define FF_MM_3DNOW 0x0004 /* AMD 3DNOW */ -#define FF_MM_MMXEXT 0x0002 /* SSE integer functions or AMD MMX ext */ -#define FF_MM_SSE 0x0008 /* SSE functions */ -#define FF_MM_SSE2 0x0010 /* PIV SSE2 functions */ -#define FF_MM_3DNOWEXT 0x0020 /* AMD 3DNowExt */ -#endif /* HAVE_MMX */ -#ifdef HAVE_IWMMXT -#define FF_MM_IWMMXT 0x0100 /* XScale IWMMXT */ -#endif /* HAVE_IWMMXT */ +#define FF_MM_MMX 0x0001 ///< standard MMX +#define FF_MM_3DNOW 0x0004 ///< AMD 3DNOW +#define FF_MM_MMXEXT 0x0002 ///< SSE integer functions or AMD MMX ext +#define FF_MM_SSE 0x0008 ///< SSE functions +#define FF_MM_SSE2 0x0010 ///< PIV SSE2 functions +#define FF_MM_3DNOWEXT 0x0020 ///< AMD 3DNowExt +#define FF_MM_SSE3 0x0040 ///< Prescott SSE3 functions +#define FF_MM_SSSE3 0x0080 ///< Conroe SSSE3 functions +#define FF_MM_IWMMXT 0x0100 ///< XScale IWMMXT /** * bits per sample/pixel from the demuxer (needed for huffyuv). - * - encoding: set by lavc - * - decoding: set by user + * - encoding: Set by libavcodec. + * - decoding: Set by user. */ int bits_per_sample; /** - * prediction method (needed for huffyuv). - * - encoding: set by user + * prediction method (needed for huffyuv) + * - encoding: Set by user. * - decoding: unused */ int prediction_method; @@ -1330,46 +1398,46 @@ typedef struct AVCodecContext { #define FF_PRED_MEDIAN 2 /** - * sample aspect ratio (0 if unknown). - * numerator and denominator must be relative prime and smaller then 256 for some video standards - * - encoding: set by user. - * - decoding: set by lavc. + * sample aspect ratio (0 if unknown) + * Numerator and denominator must be relatively prime and smaller than 256 for some video standards. + * - encoding: Set by user. + * - decoding: Set by libavcodec. */ AVRational sample_aspect_ratio; /** - * the picture in the bitstream. - * - encoding: set by lavc - * - decoding: set by lavc + * the picture in the bitstream + * - encoding: Set by libavcodec. + * - decoding: Set by libavcodec. */ AVFrame *coded_frame; /** - * debug. - * - encoding: set by user. - * - decoding: set by user. + * debug + * - encoding: Set by user. + * - decoding: Set by user. */ int debug; -#define FF_DEBUG_PICT_INFO 1 -#define FF_DEBUG_RC 2 -#define FF_DEBUG_BITSTREAM 4 -#define FF_DEBUG_MB_TYPE 8 -#define FF_DEBUG_QP 16 -#define FF_DEBUG_MV 32 -#define FF_DEBUG_DCT_COEFF 0x00000040 -#define FF_DEBUG_SKIP 0x00000080 -#define FF_DEBUG_STARTCODE 0x00000100 -#define FF_DEBUG_PTS 0x00000200 -#define FF_DEBUG_ER 0x00000400 -#define FF_DEBUG_MMCO 0x00000800 -#define FF_DEBUG_BUGS 0x00001000 -#define FF_DEBUG_VIS_QP 0x00002000 +#define FF_DEBUG_PICT_INFO 1 +#define FF_DEBUG_RC 2 +#define FF_DEBUG_BITSTREAM 4 +#define FF_DEBUG_MB_TYPE 8 +#define FF_DEBUG_QP 16 +#define FF_DEBUG_MV 32 +#define FF_DEBUG_DCT_COEFF 0x00000040 +#define FF_DEBUG_SKIP 0x00000080 +#define FF_DEBUG_STARTCODE 0x00000100 +#define FF_DEBUG_PTS 0x00000200 +#define FF_DEBUG_ER 0x00000400 +#define FF_DEBUG_MMCO 0x00000800 +#define FF_DEBUG_BUGS 0x00001000 +#define FF_DEBUG_VIS_QP 0x00002000 #define FF_DEBUG_VIS_MB_TYPE 0x00004000 /** - * debug. - * - encoding: set by user. - * - decoding: set by user. + * debug + * - encoding: Set by user. + * - decoding: Set by user. */ int debug_mv; #define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames @@ -1377,127 +1445,127 @@ typedef struct AVCodecContext { #define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames /** - * error. - * - encoding: set by lavc if flags&CODEC_FLAG_PSNR + * error + * - encoding: Set by libavcodec if flags&CODEC_FLAG_PSNR. * - decoding: unused */ uint64_t error[4]; /** - * minimum MB quantizer. + * minimum MB quantizer * - encoding: unused * - decoding: unused */ int mb_qmin; /** - * maximum MB quantizer. + * maximum MB quantizer * - encoding: unused * - decoding: unused */ int mb_qmax; /** - * motion estimation compare function. - * - encoding: set by user. + * motion estimation comparison function + * - encoding: Set by user. * - decoding: unused */ int me_cmp; /** - * subpixel motion estimation compare function. - * - encoding: set by user. + * subpixel motion estimation comparison function + * - encoding: Set by user. * - decoding: unused */ int me_sub_cmp; /** - * macroblock compare function (not supported yet). - * - encoding: set by user. + * macroblock comparison function (not supported yet) + * - encoding: Set by user. * - decoding: unused */ int mb_cmp; /** - * interlaced dct compare function - * - encoding: set by user. + * interlaced DCT comparison function + * - encoding: Set by user. * - decoding: unused */ int ildct_cmp; -#define FF_CMP_SAD 0 -#define FF_CMP_SSE 1 -#define FF_CMP_SATD 2 -#define FF_CMP_DCT 3 -#define FF_CMP_PSNR 4 -#define FF_CMP_BIT 5 -#define FF_CMP_RD 6 -#define FF_CMP_ZERO 7 -#define FF_CMP_VSAD 8 -#define FF_CMP_VSSE 9 -#define FF_CMP_NSSE 10 -#define FF_CMP_W53 11 -#define FF_CMP_W97 12 +#define FF_CMP_SAD 0 +#define FF_CMP_SSE 1 +#define FF_CMP_SATD 2 +#define FF_CMP_DCT 3 +#define FF_CMP_PSNR 4 +#define FF_CMP_BIT 5 +#define FF_CMP_RD 6 +#define FF_CMP_ZERO 7 +#define FF_CMP_VSAD 8 +#define FF_CMP_VSSE 9 +#define FF_CMP_NSSE 10 +#define FF_CMP_W53 11 +#define FF_CMP_W97 12 #define FF_CMP_DCTMAX 13 #define FF_CMP_DCT264 14 #define FF_CMP_CHROMA 256 /** - * ME diamond size & shape. - * - encoding: set by user. + * ME diamond size & shape + * - encoding: Set by user. * - decoding: unused */ int dia_size; /** - * amount of previous MV predictors (2a+1 x 2a+1 square). - * - encoding: set by user. + * amount of previous MV predictors (2a+1 x 2a+1 square) + * - encoding: Set by user. * - decoding: unused */ int last_predictor_count; /** - * pre pass for motion estimation. - * - encoding: set by user. + * prepass for motion estimation + * - encoding: Set by user. * - decoding: unused */ int pre_me; /** - * motion estimation pre pass compare function. - * - encoding: set by user. + * motion estimation prepass comparison function + * - encoding: Set by user. * - decoding: unused */ int me_pre_cmp; /** - * ME pre pass diamond size & shape. - * - encoding: set by user. + * ME prepass diamond size & shape + * - encoding: Set by user. * - decoding: unused */ int pre_dia_size; /** - * subpel ME quality. - * - encoding: set by user. + * subpel ME quality + * - encoding: Set by user. * - decoding: unused */ int me_subpel_quality; /** - * callback to negotiate the pixelFormat. + * callback to negotiate the pixelFormat * @param fmt is the list of formats which are supported by the codec, - * its terminated by -1 as 0 is a valid format, the formats are ordered by quality - * the first is allways the native one - * @return the choosen format + * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality. + * The first is always the native one. + * @return the chosen format * - encoding: unused - * - decoding: set by user, if not set then the native format will always be choosen + * - decoding: Set by user, if not set the native format will be chosen. */ enum PixelFormat (*get_format)(struct AVCodecContext *s, const enum PixelFormat * fmt); /** - * DTG active format information (additionnal aspect ratio - * information only used in DVB MPEG2 transport streams). 0 if - * not set. + * DTG active format information (additional aspect ratio + * information only used in DVB MPEG-2 transport streams) + * 0 if not set. * - * - encoding: unused. - * - decoding: set by decoder + * - encoding: unused + * - decoding: Set by decoder. */ int dtg_active_format; #define FF_DTG_AFD_SAME 8 @@ -1509,46 +1577,46 @@ typedef struct AVCodecContext { #define FF_DTG_AFD_SP_4_3 15 /** - * Maximum motion estimation search range in subpel units. - * if 0 then no limit + * maximum motion estimation search range in subpel units + * If 0 then no limit. * - * - encoding: set by user. - * - decoding: unused. + * - encoding: Set by user. + * - decoding: unused */ int me_range; /** - * intra quantizer bias. - * - encoding: set by user. + * intra quantizer bias + * - encoding: Set by user. * - decoding: unused */ int intra_quant_bias; #define FF_DEFAULT_QUANT_BIAS 999999 /** - * inter quantizer bias. - * - encoding: set by user. + * inter quantizer bias + * - encoding: Set by user. * - decoding: unused */ int inter_quant_bias; /** - * color table ID. - * - encoding: unused. - * - decoding: which clrtable should be used for 8bit RGB images - * table have to be stored somewhere FIXME + * color table ID + * - encoding: unused + * - decoding: Which clrtable should be used for 8bit RGB images. + * Tables have to be stored somewhere. FIXME */ int color_table_id; /** - * internal_buffer count. - * Don't touch, used by lavc default_get_buffer() + * internal_buffer count + * Don't touch, used by libavcodec default_get_buffer(). */ int internal_buffer_count; /** - * internal_buffers. - * Don't touch, used by lavc default_get_buffer() + * internal_buffers + * Don't touch, used by libavcodec default_get_buffer(). */ void *internal_buffer; @@ -1559,25 +1627,28 @@ typedef struct AVCodecContext { #define FF_QUALITY_SCALE FF_LAMBDA_SCALE //FIXME maybe remove /** - * global quality for codecs which cannot change it per frame. - * this should be proportional to MPEG1/2/4 qscale. - * - encoding: set by user. + * Global quality for codecs which cannot change it per frame. + * This should be proportional to MPEG-1/2/4 qscale. + * - encoding: Set by user. * - decoding: unused */ int global_quality; -#define FF_CODER_TYPE_VLC 0 -#define FF_CODER_TYPE_AC 1 +#define FF_CODER_TYPE_VLC 0 +#define FF_CODER_TYPE_AC 1 +#define FF_CODER_TYPE_RAW 2 +#define FF_CODER_TYPE_RLE 3 +#define FF_CODER_TYPE_DEFLATE 4 /** * coder type - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int coder_type; /** * context model - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int context_model; @@ -1585,7 +1656,7 @@ typedef struct AVCodecContext { /** * * - encoding: unused - * - decoding: set by user. + * - decoding: Set by user. */ uint8_t * (*realloc)(struct AVCodecContext *s, uint8_t *buf, int buf_size); #endif @@ -1593,7 +1664,7 @@ typedef struct AVCodecContext { /** * slice flags * - encoding: unused - * - decoding: set by user. + * - decoding: Set by user. */ int slice_flags; #define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display @@ -1609,7 +1680,7 @@ typedef struct AVCodecContext { /** * macroblock decision mode - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int mb_decision; @@ -1619,105 +1690,105 @@ typedef struct AVCodecContext { /** * custom intra quantization matrix - * - encoding: set by user, can be NULL - * - decoding: set by lavc + * - encoding: Set by user, can be NULL. + * - decoding: Set by libavcodec. */ uint16_t *intra_matrix; /** * custom inter quantization matrix - * - encoding: set by user, can be NULL - * - decoding: set by lavc + * - encoding: Set by user, can be NULL. + * - decoding: Set by libavcodec. */ uint16_t *inter_matrix; /** * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A'). - * this is used to workaround some encoder bugs + * This is used to work around some encoder bugs. * - encoding: unused - * - decoding: set by user, will be converted to upper case by lavc during init + * - decoding: Set by user, will be converted to uppercase by libavcodec during init. */ unsigned int stream_codec_tag; /** - * scene change detection threshold. - * 0 is default, larger means fewer detected scene changes - * - encoding: set by user. + * scene change detection threshold + * 0 is default, larger means fewer detected scene changes. + * - encoding: Set by user. * - decoding: unused */ int scenechange_threshold; /** - * minimum lagrange multipler - * - encoding: set by user. + * minimum Lagrange multipler + * - encoding: Set by user. * - decoding: unused */ int lmin; /** - * maximum lagrange multipler - * - encoding: set by user. + * maximum Lagrange multipler + * - encoding: Set by user. * - decoding: unused */ int lmax; /** - * Palette control structure + * palette control structure * - encoding: ??? (no palette-enabled encoder yet) - * - decoding: set by user. + * - decoding: Set by user. */ struct AVPaletteControl *palctrl; /** * noise reduction strength - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int noise_reduction; /** - * called at the beginning of a frame to get cr buffer for it. - * buffer type (size, hints) must be the same. lavc won't check it. - * lavc will pass previous buffer in pic, function should return + * Called at the beginning of a frame to get cr buffer for it. + * Buffer type (size, hints) must be the same. libavcodec won't check it. + * libavcodec will pass previous buffer in pic, function should return * same buffer or new buffer with old frame "painted" into it. - * if pic.data[0] == NULL must behave like get_buffer(). + * If pic.data[0] == NULL must behave like get_buffer(). * - encoding: unused - * - decoding: set by lavc, user can override + * - decoding: Set by libavcodec., user can override */ int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic); /** - * number of bits which should be loaded into the rc buffer before decoding starts - * - encoding: set by user. + * Number of bits which should be loaded into the rc buffer before decoding starts. + * - encoding: Set by user. * - decoding: unused */ int rc_initial_buffer_occupancy; /** * - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int inter_threshold; /** - * CODEC_FLAG2_*. - * - encoding: set by user. - * - decoding: set by user. + * CODEC_FLAG2_* + * - encoding: Set by user. + * - decoding: Set by user. */ int flags2; /** - * simulates errors in the bitstream to test error concealment. - * - encoding: set by user. - * - decoding: unused. + * Simulates errors in the bitstream to test error concealment. + * - encoding: Set by user. + * - decoding: unused */ int error_rate; /** * MP3 antialias algorithm, see FF_AA_* below. * - encoding: unused - * - decoding: set by user + * - decoding: Set by user. */ int antialias_algo; #define FF_AA_AUTO 0 @@ -1725,166 +1796,171 @@ typedef struct AVCodecContext { #define FF_AA_INT 2 #define FF_AA_FLOAT 3 /** - * Quantizer noise shaping. - * - encoding: set by user + * quantizer noise shaping + * - encoding: Set by user. * - decoding: unused */ int quantizer_noise_shaping; /** - * Thread count. + * thread count * is used to decide how many independent tasks should be passed to execute() - * - encoding: set by user - * - decoding: set by user + * - encoding: Set by user. + * - decoding: Set by user. */ int thread_count; /** - * the codec may call this to execute several independent things. it will return only after - * finishing all tasks, the user may replace this with some multithreaded implementation, the - * default implementation will execute the parts serially + * The codec may call this to execute several independent things. + * It will return only after finishing all tasks. + * The user may replace this with some multithreaded implementation, + * the default implementation will execute the parts serially. * @param count the number of things to execute - * - encoding: set by lavc, user can override - * - decoding: set by lavc, user can override + * - encoding: Set by libavcodec, user can override. + * - decoding: Set by libavcodec, user can override. */ int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void **arg2, int *ret, int count); /** - * Thread opaque. - * can be used by execute() to store some per AVCodecContext stuff. + * thread opaque + * Can be used by execute() to store some per AVCodecContext stuff. * - encoding: set by execute() * - decoding: set by execute() */ void *thread_opaque; /** - * Motion estimation threshold. under which no motion estimation is - * performed, but instead the user specified motion vectors are used + * Motion estimation threshold below which no motion estimation is + * performed, but instead the user specified motion vectors are used. * - * - encoding: set by user + * - encoding: Set by user. * - decoding: unused */ int me_threshold; /** - * Macroblock threshold. under which the user specified macroblock types will be used - * - encoding: set by user + * Macroblock threshold below which the user specified macroblock types will be used. + * - encoding: Set by user. * - decoding: unused */ int mb_threshold; /** - * precision of the intra dc coefficient - 8. - * - encoding: set by user + * precision of the intra DC coefficient - 8 + * - encoding: Set by user. * - decoding: unused */ int intra_dc_precision; /** - * noise vs. sse weight for the nsse comparsion function. - * - encoding: set by user + * noise vs. sse weight for the nsse comparsion function + * - encoding: Set by user. * - decoding: unused */ int nsse_weight; /** - * number of macroblock rows at the top which are skipped. + * Number of macroblock rows at the top which are skipped. * - encoding: unused - * - decoding: set by user + * - decoding: Set by user. */ int skip_top; /** - * number of macroblock rows at the bottom which are skipped. + * Number of macroblock rows at the bottom which are skipped. * - encoding: unused - * - decoding: set by user + * - decoding: Set by user. */ int skip_bottom; /** * profile - * - encoding: set by user - * - decoding: set by lavc + * - encoding: Set by user. + * - decoding: Set by libavcodec. */ int profile; #define FF_PROFILE_UNKNOWN -99 +#define FF_PROFILE_AAC_MAIN 0 +#define FF_PROFILE_AAC_LOW 1 +#define FF_PROFILE_AAC_SSR 2 +#define FF_PROFILE_AAC_LTP 3 /** * level - * - encoding: set by user - * - decoding: set by lavc + * - encoding: Set by user. + * - decoding: Set by libavcodec. */ int level; #define FF_LEVEL_UNKNOWN -99 /** - * low resolution decoding. 1-> 1/2 size, 2->1/4 size + * low resolution decoding, 1-> 1/2 size, 2->1/4 size * - encoding: unused - * - decoding: set by user + * - decoding: Set by user. */ int lowres; /** - * bitsream width / height. may be different from width/height if lowres - * or other things are used + * Bitstream width / height, may be different from width/height if lowres + * or other things are used. * - encoding: unused - * - decoding: set by user before init if known, codec should override / dynamically change if needed + * - decoding: Set by user before init if known. Codec should override / dynamically change if needed. */ int coded_width, coded_height; /** * frame skip threshold - * - encoding: set by user + * - encoding: Set by user. * - decoding: unused */ int frame_skip_threshold; /** * frame skip factor - * - encoding: set by user + * - encoding: Set by user. * - decoding: unused */ int frame_skip_factor; /** * frame skip exponent - * - encoding: set by user + * - encoding: Set by user. * - decoding: unused */ int frame_skip_exp; /** - * frame skip comparission function - * - encoding: set by user. + * frame skip comparison function + * - encoding: Set by user. * - decoding: unused */ int frame_skip_cmp; /** - * border processing masking. raises the quantizer for mbs on the borders + * Border processing masking, raises the quantizer for mbs on the borders * of the picture. - * - encoding: set by user + * - encoding: Set by user. * - decoding: unused */ float border_masking; /** - * minimum MB lagrange multipler. - * - encoding: set by user. + * minimum MB lagrange multipler + * - encoding: Set by user. * - decoding: unused */ int mb_lmin; /** - * maximum MB lagrange multipler. - * - encoding: set by user. + * maximum MB lagrange multipler + * - encoding: Set by user. * - decoding: unused */ int mb_lmax; /** * - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int me_penalty_compensation; @@ -1892,90 +1968,90 @@ typedef struct AVCodecContext { /** * * - encoding: unused - * - decoding: set by user. + * - decoding: Set by user. */ enum AVDiscard skip_loop_filter; /** * * - encoding: unused - * - decoding: set by user. + * - decoding: Set by user. */ enum AVDiscard skip_idct; /** * * - encoding: unused - * - decoding: set by user. + * - decoding: Set by user. */ enum AVDiscard skip_frame; /** * - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int bidir_refine; /** * - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int brd_scale; /** * constant rate factor - quality-based VBR - values ~correspond to qps - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ float crf; /** * constant quantization parameter rate control method - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int cqp; /** - * minimum gop size - * - encoding: set by user. + * minimum GOP size + * - encoding: Set by user. * - decoding: unused */ int keyint_min; /** * number of reference frames - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int refs; /** * chroma qp offset from luma - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int chromaoffset; /** - * influences how often b-frames are used - * - encoding: set by user. + * Influences how often B-frames are used. + * - encoding: Set by user. * - decoding: unused */ int bframebias; /** * trellis RD quantization - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int trellis; /** - * reduce fluctuations in qp (before curve compression) - * - encoding: set by user. + * Reduce fluctuations in qp (before curve compression). + * - encoding: Set by user. * - decoding: unused */ float complexityblur; @@ -1983,7 +2059,7 @@ typedef struct AVCodecContext { /** * in-loop deblocking filter alphac0 parameter * alpha is in the range -6...6 - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int deblockalpha; @@ -1991,123 +2067,144 @@ typedef struct AVCodecContext { /** * in-loop deblocking filter beta parameter * beta is in the range -6...6 - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int deblockbeta; /** * macroblock subpartition sizes to consider - p8x8, p4x4, b8x8, i8x8, i4x4 - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int partitions; -#define X264_PART_I4X4 0x001 /* Analyse i4x4 */ -#define X264_PART_I8X8 0x002 /* Analyse i8x8 (requires 8x8 transform) */ -#define X264_PART_P8X8 0x010 /* Analyse p16x8, p8x16 and p8x8 */ -#define X264_PART_P4X4 0x020 /* Analyse p8x4, p4x8, p4x4 */ -#define X264_PART_B8X8 0x100 /* Analyse b16x8, b8x16 and b8x8 */ +#define X264_PART_I4X4 0x001 /* Analyze i4x4 */ +#define X264_PART_I8X8 0x002 /* Analyze i8x8 (requires 8x8 transform) */ +#define X264_PART_P8X8 0x010 /* Analyze p16x8, p8x16 and p8x8 */ +#define X264_PART_P4X4 0x020 /* Analyze p8x4, p4x8, p4x4 */ +#define X264_PART_B8X8 0x100 /* Analyze b16x8, b8x16 and b8x8 */ /** - * direct mv prediction mode - 0 (none), 1 (spatial), 2 (temporal) - * - encoding: set by user. + * direct MV prediction mode - 0 (none), 1 (spatial), 2 (temporal) + * - encoding: Set by user. * - decoding: unused */ int directpred; /** - * audio cutoff bandwidth (0 means "automatic") . Currently used only by FAAC - * - encoding: set by user. + * Audio cutoff bandwidth (0 means "automatic") + * - encoding: Set by user. * - decoding: unused */ int cutoff; /** - * multiplied by qscale for each frame and added to scene_change_score - * - encoding: set by user. + * Multiplied by qscale for each frame and added to scene_change_score. + * - encoding: Set by user. * - decoding: unused */ int scenechange_factor; /** * - * note: value depends upon the compare functin used for fullpel ME - * - encoding: set by user. + * Note: Value depends upon the compare function used for fullpel ME. + * - encoding: Set by user. * - decoding: unused */ int mv0_threshold; /** - * adjusts sensitivity of b_frame_strategy 1 - * - encoding: set by user. + * Adjusts sensitivity of b_frame_strategy 1. + * - encoding: Set by user. * - decoding: unused */ int b_sensitivity; /** - * - encoding: set by user. + * - encoding: Set by user. * - decoding: unused */ int compression_level; #define FF_COMPRESSION_DEFAULT -1 /** - * sets whether to use LPC mode - used by FLAC encoder - * - encoding: set by user. - * - decoding: unused. + * Sets whether to use LPC mode - used by FLAC encoder. + * - encoding: Set by user. + * - decoding: unused */ int use_lpc; /** * LPC coefficient precision - used by FLAC encoder - * - encoding: set by user. - * - decoding: unused. + * - encoding: Set by user. + * - decoding: unused */ int lpc_coeff_precision; /** - * - encoding: set by user. - * - decoding: unused. + * - encoding: Set by user. + * - decoding: unused */ int min_prediction_order; /** - * - encoding: set by user. - * - decoding: unused. + * - encoding: Set by user. + * - decoding: unused */ int max_prediction_order; /** * search method for selecting prediction order - * - encoding: set by user. - * - decoding: unused. + * - encoding: Set by user. + * - decoding: unused */ int prediction_order_method; /** - * - encoding: set by user. - * - decoding: unused. + * - encoding: Set by user. + * - decoding: unused */ int min_partition_order; /** - * - encoding: set by user. - * - decoding: unused. + * - encoding: Set by user. + * - decoding: unused */ int max_partition_order; /** * GOP timecode frame start number, in non drop frame format - * - encoding: set by user. - * - decoding: unused. + * - encoding: Set by user. + * - decoding: unused */ int64_t timecode_frame_start; + + /** + * Decoder should decode to this many channels if it can (0 for default) + * - encoding: unused + * - decoding: Set by user. + */ + int request_channels; + + /** + * Percentage of dynamic range compression to be applied by the decoder. + * The default value is 1.0, corresponding to full compression. + * - encoding: unused + * - decoding: Set by user. + */ + float drc_scale; } AVCodecContext; /** * AVCodec. */ typedef struct AVCodec { + /** + * Name of the codec implementation. + * The name is globally unique among encoders and among decoders (but an + * encoder and a decoder can share the same name). + * This is the primary way to find a codec from the user perspective. + */ const char *name; enum CodecType type; enum CodecID id; @@ -2116,7 +2213,7 @@ typedef struct AVCodec { int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data); int (*close)(AVCodecContext *); int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, - uint8_t *buf, int buf_size); + const uint8_t *buf, int buf_size); int capabilities; struct AVCodec *next; void (*flush)(AVCodecContext *); @@ -2137,20 +2234,22 @@ typedef struct AVPicture { * AVPaletteControl * This structure defines a method for communicating palette changes * between and demuxer and a decoder. - * this is totally broken, palette changes should be sent as AVPackets + * + * @deprecated Use AVPacket to send palette changes instead. + * This is totally broken. */ #define AVPALETTE_SIZE 1024 #define AVPALETTE_COUNT 256 typedef struct AVPaletteControl { - /* demuxer sets this to 1 to indicate the palette has changed; - * decoder resets to 0 */ + /* Demuxer sets this to 1 to indicate the palette has changed; + * decoder resets to 0. */ int palette_changed; /* 4-byte ARGB palette entries, stored in native byte order; note that * the individual palette components should be on a 8-bit scale; if - * the palette data comes from a IBM VGA native format, the component - * data is probably 6 bits in size and needs to be scaled */ + * the palette data comes from an IBM VGA native format, the component + * data is probably 6 bits in size and needs to be scaled. */ unsigned int palette[AVPALETTE_COUNT]; } AVPaletteControl attribute_deprecated; @@ -2174,255 +2273,6 @@ typedef struct AVSubtitle { AVSubtitleRect *rects; } AVSubtitle; -extern AVCodec ac3_encoder; -extern AVCodec amr_nb_encoder; -extern AVCodec amr_wb_encoder; -extern AVCodec asv1_encoder; -extern AVCodec asv2_encoder; -extern AVCodec bmp_encoder; -extern AVCodec dvvideo_encoder; -extern AVCodec faac_encoder; -extern AVCodec ffv1_encoder; -extern AVCodec ffvhuff_encoder; -extern AVCodec flac_encoder; -extern AVCodec flashsv_encoder; -extern AVCodec flv_encoder; -extern AVCodec gif_encoder; -extern AVCodec h261_encoder; -extern AVCodec h263_encoder; -extern AVCodec h263p_encoder; -extern AVCodec h264_encoder; -extern AVCodec huffyuv_encoder; -extern AVCodec jpegls_encoder; -extern AVCodec libgsm_encoder; -extern AVCodec libgsm_ms_encoder; -extern AVCodec libtheora_encoder; -extern AVCodec ljpeg_encoder; -extern AVCodec mdec_encoder; -extern AVCodec mjpeg_encoder; -extern AVCodec mp2_encoder; -extern AVCodec mp3lame_encoder; -extern AVCodec mpeg1video_encoder; -extern AVCodec mpeg2video_encoder; -extern AVCodec mpeg4_encoder; -extern AVCodec msmpeg4v1_encoder; -extern AVCodec msmpeg4v2_encoder; -extern AVCodec msmpeg4v3_encoder; -extern AVCodec oggvorbis_encoder; -extern AVCodec pam_encoder; -extern AVCodec pbm_encoder; -extern AVCodec pgm_encoder; -extern AVCodec pgmyuv_encoder; -extern AVCodec png_encoder; -extern AVCodec ppm_encoder; -extern AVCodec rv10_encoder; -extern AVCodec rv20_encoder; -extern AVCodec snow_encoder; -extern AVCodec sonic_encoder; -extern AVCodec sonic_ls_encoder; -extern AVCodec svq1_encoder; -extern AVCodec targa_encoder; -extern AVCodec vcr1_encoder; -extern AVCodec vorbis_encoder; -extern AVCodec wmav1_encoder; -extern AVCodec wmav2_encoder; -extern AVCodec wmv1_encoder; -extern AVCodec wmv2_encoder; -extern AVCodec x264_encoder; -extern AVCodec xvid_encoder; -extern AVCodec zlib_encoder; -extern AVCodec zmbv_encoder; - -extern AVCodec aac_decoder; -extern AVCodec aasc_decoder; -extern AVCodec alac_decoder; -extern AVCodec amr_nb_decoder; -extern AVCodec amr_wb_decoder; -extern AVCodec asv1_decoder; -extern AVCodec asv2_decoder; -extern AVCodec avs_decoder; -extern AVCodec bmp_decoder; -extern AVCodec cavs_decoder; -extern AVCodec cinepak_decoder; -extern AVCodec cljr_decoder; -extern AVCodec cook_decoder; -extern AVCodec cscd_decoder; -extern AVCodec cyuv_decoder; -extern AVCodec dca_decoder; -extern AVCodec dnxhd_decoder; -extern AVCodec dsicinaudio_decoder; -extern AVCodec dsicinvideo_decoder; -extern AVCodec dvvideo_decoder; -extern AVCodec dxa_decoder; -extern AVCodec eightbps_decoder; -extern AVCodec ffv1_decoder; -extern AVCodec ffvhuff_decoder; -extern AVCodec flac_decoder; -extern AVCodec flashsv_decoder; -extern AVCodec flic_decoder; -extern AVCodec flv_decoder; -extern AVCodec fourxm_decoder; -extern AVCodec fraps_decoder; -extern AVCodec gif_decoder; -extern AVCodec h261_decoder; -extern AVCodec h263_decoder; -extern AVCodec h263i_decoder; -extern AVCodec h264_decoder; -extern AVCodec huffyuv_decoder; -extern AVCodec idcin_decoder; -extern AVCodec imc_decoder; -extern AVCodec indeo2_decoder; -extern AVCodec indeo3_decoder; -extern AVCodec interplay_dpcm_decoder; -extern AVCodec interplay_video_decoder; -extern AVCodec kmvc_decoder; -extern AVCodec libgsm_decoder; -extern AVCodec libgsm_ms_decoder; -extern AVCodec loco_decoder; -extern AVCodec mace3_decoder; -extern AVCodec mace6_decoder; -extern AVCodec mdec_decoder; -extern AVCodec mjpeg_decoder; -extern AVCodec mjpegb_decoder; -extern AVCodec mmvideo_decoder; -extern AVCodec mp2_decoder; -extern AVCodec mp3_decoder; -extern AVCodec mp3adu_decoder; -extern AVCodec mp3on4_decoder; -extern AVCodec mpc7_decoder; -extern AVCodec mpeg1video_decoder; -extern AVCodec mpeg2video_decoder; -extern AVCodec mpeg4_decoder; -extern AVCodec mpeg4aac_decoder; -extern AVCodec mpeg_xvmc_decoder; -extern AVCodec mpegvideo_decoder; -extern AVCodec msmpeg4v1_decoder; -extern AVCodec msmpeg4v2_decoder; -extern AVCodec msmpeg4v3_decoder; -extern AVCodec msrle_decoder; -extern AVCodec msvideo1_decoder; -extern AVCodec mszh_decoder; -extern AVCodec nuv_decoder; -extern AVCodec oggvorbis_decoder; -extern AVCodec png_decoder; -extern AVCodec qdm2_decoder; -extern AVCodec qdraw_decoder; -extern AVCodec qpeg_decoder; -extern AVCodec qtrle_decoder; -extern AVCodec ra_144_decoder; -extern AVCodec ra_288_decoder; -extern AVCodec roq_decoder; -extern AVCodec roq_dpcm_decoder; -extern AVCodec rpza_decoder; -extern AVCodec rv10_decoder; -extern AVCodec rv20_decoder; -extern AVCodec rv30_decoder; -extern AVCodec rv40_decoder; -extern AVCodec shorten_decoder; -extern AVCodec smackaud_decoder; -extern AVCodec smacker_decoder; -extern AVCodec smc_decoder; -extern AVCodec snow_decoder; -extern AVCodec sol_dpcm_decoder; -extern AVCodec sonic_decoder; -extern AVCodec sp5x_decoder; -extern AVCodec svq1_decoder; -extern AVCodec svq3_decoder; -extern AVCodec targa_decoder; -extern AVCodec theora_decoder; -extern AVCodec thp_decoder; -extern AVCodec tiertexseqvideo_decoder; -extern AVCodec tiff_decoder; -extern AVCodec truemotion1_decoder; -extern AVCodec truemotion2_decoder; -extern AVCodec truespeech_decoder; -extern AVCodec tscc_decoder; -extern AVCodec tta_decoder; -extern AVCodec ulti_decoder; -extern AVCodec vc1_decoder; -extern AVCodec vcr1_decoder; -extern AVCodec vmdaudio_decoder; -extern AVCodec vmdvideo_decoder; -extern AVCodec vmnc_decoder; -extern AVCodec vorbis_decoder; -extern AVCodec vp3_decoder; -extern AVCodec vp5_decoder; -extern AVCodec vp6_decoder; -extern AVCodec vp6f_decoder; -extern AVCodec vqa_decoder; -extern AVCodec wavpack_decoder; -extern AVCodec wmav1_decoder; -extern AVCodec wmav2_decoder; -extern AVCodec wmv1_decoder; -extern AVCodec wmv2_decoder; -extern AVCodec wmv3_decoder; -extern AVCodec wnv1_decoder; -extern AVCodec ws_snd1_decoder; -extern AVCodec xan_dpcm_decoder; -extern AVCodec xan_wc3_decoder; -extern AVCodec xl_decoder; -extern AVCodec zlib_decoder; -extern AVCodec zmbv_decoder; - -/* pcm codecs */ -#define PCM_CODEC(id, name) \ -extern AVCodec name ## _decoder; \ -extern AVCodec name ## _encoder - -PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw); -PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw); -PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8); -PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be); -PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le); -PCM_CODEC(CODEC_ID_PCM_S24BE, pcm_s24be); -PCM_CODEC(CODEC_ID_PCM_S24DAUD, pcm_s24daud); -PCM_CODEC(CODEC_ID_PCM_S24LE, pcm_s24le); -PCM_CODEC(CODEC_ID_PCM_S32BE, pcm_s32be); -PCM_CODEC(CODEC_ID_PCM_S32LE, pcm_s32le); -PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8); -PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be); -PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le); -PCM_CODEC(CODEC_ID_PCM_U24BE, pcm_u24be); -PCM_CODEC(CODEC_ID_PCM_U24LE, pcm_u24le); -PCM_CODEC(CODEC_ID_PCM_U32BE, pcm_u32be); -PCM_CODEC(CODEC_ID_PCM_U32LE, pcm_u32le); - -/* adpcm codecs */ - -PCM_CODEC(CODEC_ID_ADPCM_4XM, adpcm_4xm); -PCM_CODEC(CODEC_ID_ADPCM_ADX, adpcm_adx); -PCM_CODEC(CODEC_ID_ADPCM_CT, adpcm_ct); -PCM_CODEC(CODEC_ID_ADPCM_EA, adpcm_ea); -PCM_CODEC(CODEC_ID_ADPCM_G726, adpcm_g726); -PCM_CODEC(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3); -PCM_CODEC(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4); -PCM_CODEC(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt); -PCM_CODEC(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav); -PCM_CODEC(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws); -PCM_CODEC(CODEC_ID_ADPCM_MS, adpcm_ms); -PCM_CODEC(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2); -PCM_CODEC(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3); -PCM_CODEC(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4); -PCM_CODEC(CODEC_ID_ADPCM_SMJPEG, adpcm_ima_smjpeg); -PCM_CODEC(CODEC_ID_ADPCM_SWF, adpcm_swf); -PCM_CODEC(CODEC_ID_ADPCM_XA, adpcm_xa); -PCM_CODEC(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha); - -#undef PCM_CODEC - -/* dummy raw video codec */ -extern AVCodec rawvideo_decoder; -extern AVCodec rawvideo_encoder; - -/* the following codecs use external GPL libs */ -extern AVCodec dts_decoder; -extern AVCodec liba52_decoder; - -/* subtitles */ -extern AVCodec dvbsub_decoder; -extern AVCodec dvbsub_encoder; -extern AVCodec dvdsub_decoder; -extern AVCodec dvdsub_encoder; /* resample.c */ @@ -2444,13 +2294,20 @@ void av_resample_close(struct AVResampleContext *c); #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) /* YUV420 format is assumed ! */ -struct ImgReSampleContext attribute_deprecated; - +/** + * @deprecated Use the software scaler (swscale) instead. + */ typedef struct ImgReSampleContext ImgReSampleContext attribute_deprecated; +/** + * @deprecated Use the software scaler (swscale) instead. + */ attribute_deprecated ImgReSampleContext *img_resample_init(int output_width, int output_height, int input_width, int input_height); +/** + * @deprecated Use the software scaler (swscale) instead. + */ attribute_deprecated ImgReSampleContext *img_resample_full_init(int owidth, int oheight, int iwidth, int iheight, int topBand, int bottomBand, @@ -2458,34 +2315,39 @@ attribute_deprecated ImgReSampleContext *img_resample_full_init(int owidth, int int padtop, int padbottom, int padleft, int padright); - -attribute_deprecated void img_resample(ImgReSampleContext *s, +/** + * @deprecated Use the software scaler (swscale) instead. + */ +attribute_deprecated void img_resample(struct ImgReSampleContext *s, AVPicture *output, const AVPicture *input); -attribute_deprecated void img_resample_close(ImgReSampleContext *s); +/** + * @deprecated Use the software scaler (swscale) instead. + */ +attribute_deprecated void img_resample_close(struct ImgReSampleContext *s); #endif /** * Allocate memory for a picture. Call avpicture_free to free it. * - * @param picture the picture to be filled in. - * @param pix_fmt the format of the picture. - * @param width the width of the picture. - * @param height the height of the picture. - * @return Zero if successful, a negative value if not. + * @param picture the picture to be filled in + * @param pix_fmt the format of the picture + * @param width the width of the picture + * @param height the height of the picture + * @return zero if successful, a negative value if not */ int avpicture_alloc(AVPicture *picture, int pix_fmt, int width, int height); /** * Free a picture previously allocated by avpicture_alloc(). * - * @param picture The AVPicture to be freed. + * @param picture the AVPicture to be freed */ void avpicture_free(AVPicture *picture); /** - * Fill in AVPicture's fields. + * Fill in the AVPicture fields. * The fields of the given AVPicture are filled in by using the 'ptr' address * which points to the image data buffer. Depending on the specified picture * format, one or multiple image data pointers and line sizes will be set. @@ -2493,12 +2355,12 @@ void avpicture_free(AVPicture *picture); * the different picture planes and the line sizes of the different planes * will be stored in the lines_sizes array. * - * @param picture AVPicture who's fields are to be filled in + * @param picture AVPicture whose fields are to be filled in * @param ptr Buffer which will contain or contains the actual image data - * @param pix_fmt The format in which the picture data is stored - * @param width The width of the image in pixels - * @param height The height of the image in pixels - * @return Size of the image data in bytes. + * @param pix_fmt The format in which the picture data is stored. + * @param width the width of the image in pixels + * @param height the height of the image in pixels + * @return size of the image data in bytes */ int avpicture_fill(AVPicture *picture, uint8_t *ptr, int pix_fmt, int width, int height); @@ -2509,9 +2371,9 @@ int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height, * Calculate the size in bytes that a picture of the given width and height * would occupy if stored in the given picture format. * - * @param pix_fmt The given picture format - * @param width The width of the image - * @param height The height of the image + * @param pix_fmt the given picture format + * @param width the width of the image + * @param height the height of the image * @return Image data size in bytes */ int avpicture_get_size(int pix_fmt, int width, int height); @@ -2537,11 +2399,11 @@ unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat p); * other formats. These losses can involve loss of chroma, but also loss of * resolution, loss of color depth, loss due to the color space conversion, loss * of the alpha bits or loss due to color quantization. - * avcodec_get_fix_fmt_loss() informs you on the various types of losses which - * will occur when converting from one pixel format to another. + * avcodec_get_fix_fmt_loss() informs you about the various types of losses + * which will occur when converting from one pixel format to another. * - * @param[in] dst_pix_fmt Destination pixel format. - * @param[in] src_pix_fmt Source pixel format. + * @param[in] dst_pix_fmt destination pixel format + * @param[in] src_pix_fmt source pixel format * @param[in] has_alpha Whether the source pixel format alpha channel is used. * @return Combination of flags informing you what kind of losses will occur. */ @@ -2554,8 +2416,8 @@ int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt, * may occur. For example, when converting from RGB24 to GRAY, the color * information will be lost. Similarly, other losses occur when converting from * some formats to other formats. avcodec_find_best_pix_fmt() searches which of - * the given pixel formats should be used to undergo the least amount of losses. - * The pixel formats from which it choses one, are determined by the + * the given pixel formats should be used to suffer the least amount of loss. + * The pixel formats from which it chooses one, are determined by the * \p pix_fmt_mask parameter. * * @code @@ -2564,8 +2426,8 @@ int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt, * dst_pix_fmt = avcodec_find_best_pix_fmt(pix_fmt_mask, src_pix_fmt, alpha, &loss); * @endcode * - * @param[in] pix_fmt_mask Bitmask determining which pixel format to choose from. - * @param[in] src_pix_fmt Source pixel format. + * @param[in] pix_fmt_mask bitmask determining which pixel format to choose from + * @param[in] src_pix_fmt source pixel format * @param[in] has_alpha Whether the source pixel format alpha channel is used. * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur. * @return The best pixel format to convert to or -1 if none was found. @@ -2573,6 +2435,19 @@ int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt, int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt, int has_alpha, int *loss_ptr); + +/** + * Print in buf the string corresponding to the pixel format with + * number pix_fmt, or an header if pix_fmt is negative. + * + * @param[in] buf the buffer where to write the string + * @param[in] buf_size the size of buf + * @param[in] pix_fmt the number of the pixel format to print the corresponding info string, or + * a negative value to print the corresponding header. + * Meaningful values for obtaining a pixel format info vary from 0 to PIX_FMT_NB -1. + */ +void avcodec_pix_fmt_string (char *buf, int buf_size, int pix_fmt); + #define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */ #define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */ @@ -2584,7 +2459,10 @@ int img_get_alpha_info(const AVPicture *src, int pix_fmt, int width, int height); #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) -/* convert among pixel formats */ +/** + * convert among pixel formats + * @deprecated Use the software scaler (swscale) instead. + */ attribute_deprecated int img_convert(AVPicture *dst, int dst_pix_fmt, const AVPicture *src, int pix_fmt, int width, int height); @@ -2597,7 +2475,10 @@ int avpicture_deinterlace(AVPicture *dst, const AVPicture *src, /* external high level API */ +#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) extern AVCodec *first_avcodec; +#endif +AVCodec *av_codec_next(AVCodec *c); /* returns LIBAVCODEC_VERSION_INT constant */ unsigned avcodec_version(void); @@ -2615,33 +2496,33 @@ void avcodec_init(void); void register_avcodec(AVCodec *format); /** - * Finds an encoder with a matching codec ID. + * Finds a registered encoder with a matching codec ID. * - * @param id CodecID of the requested encoder. + * @param id CodecID of the requested encoder * @return An encoder if one was found, NULL otherwise. */ AVCodec *avcodec_find_encoder(enum CodecID id); /** - * Finds an encoder with the specified name. + * Finds a registered encoder with the specified name. * - * @param name Name of the requested encoder. + * @param name name of the requested encoder * @return An encoder if one was found, NULL otherwise. */ AVCodec *avcodec_find_encoder_by_name(const char *name); /** - * Finds a decoder with a matching codec ID. + * Finds a registered decoder with a matching codec ID. * - * @param id CodecID of the requested decoder. + * @param id CodecID of the requested decoder * @return A decoder if one was found, NULL otherwise. */ AVCodec *avcodec_find_decoder(enum CodecID id); /** - * Finds an decoder with the specified name. + * Finds a registered decoder with the specified name. * - * @param name Name of the requested decoder. + * @param name name of the requested decoder * @return A decoder if one was found, NULL otherwise. */ AVCodec *avcodec_find_decoder_by_name(const char *name); @@ -2717,9 +2598,10 @@ int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, v * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for * retrieving a codec. * - * @warning This function is not thread save! + * @warning This function is not thread safe! * * @code + * avcodec_register_all(); * codec = avcodec_find_decoder(CODEC_ID_H264); * if (!codec) * exit(1); @@ -2730,9 +2612,9 @@ int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, v * exit(1); * @endcode * - * @param avctx The context which will be setup to use the given codec. + * @param avctx The context which will be set up to use the given codec. * @param codec The codec to use within the context. - * @return Zero on success, a negative value on error. + * @return zero on success, a negative value on error * @see avcodec_alloc_context, avcodec_find_decoder, avcodec_find_encoder */ int avcodec_open(AVCodecContext *avctx, AVCodec *codec); @@ -2742,13 +2624,13 @@ int avcodec_open(AVCodecContext *avctx, AVCodec *codec); */ attribute_deprecated int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, - uint8_t *buf, int buf_size); + const uint8_t *buf, int buf_size); /** * Decodes an audio frame from \p buf into \p samples. - * The avcodec_decode_audio2() function decodes a frame of audio from the input + * The avcodec_decode_audio2() function decodes an audio frame from the input * buffer \p buf of size \p buf_size. To decode it, it makes use of the - * audiocodec which was coupled with \p avctx using avcodec_open(). The + * audio codec which was coupled with \p avctx using avcodec_open(). The * resulting decoded frame is stored in output buffer \p samples. If no frame * could be decompressed, \p frame_size_ptr is zero. Otherwise, it is the * decompressed frame size in \e bytes. @@ -2764,7 +2646,7 @@ attribute_deprecated int avcodec_decode_audio(AVCodecContext *avctx, int16_t *sa * no overreading happens for damaged MPEG streams. * * @note You might have to align the input buffer \p buf and output buffer \p - * samples. The alignment requirements depend on the CPU: on some CPUs it isn't + * samples. The alignment requirements depend on the CPU: On some CPUs it isn't * necessary at all, on others it won't work at all if not aligned and on others * it will work but it will have an impact on performance. In practice, the * bitstream should have 4 byte alignment at minimum and all sample data should @@ -2772,23 +2654,23 @@ attribute_deprecated int avcodec_decode_audio(AVCodecContext *avctx, int16_t *sa * the linesize is not a multiple of 16 then there's no sense in aligning the * start of the buffer to 16. * - * @param avctx The codec context. - * @param[out] samples The output buffer. - * @param[in,out] frame_size_ptr The output buffer size in bytes. - * @param[in] buf The input buffer. - * @param[in] buf_size The input buffer size in bytes. + * @param avctx the codec context + * @param[out] samples the output buffer + * @param[in,out] frame_size_ptr the output buffer size in bytes + * @param[in] buf the input buffer + * @param[in] buf_size the input buffer size in bytes * @return On error a negative value is returned, otherwise the number of bytes * used or zero if no frame could be decompressed. */ int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, - uint8_t *buf, int buf_size); + const uint8_t *buf, int buf_size); /** * Decodes a video frame from \p buf into \p picture. - * The avcodec_decode_video() function decodes a frame of video from the input + * The avcodec_decode_video() function decodes a video frame from the input * buffer \p buf of size \p buf_size. To decode it, it makes use of the - * videocodec which was coupled with \p avctx using avcodec_open(). The + * video codec which was coupled with \p avctx using avcodec_open(). The * resulting decoded frame is stored in \p picture. * * @warning The input buffer must be \c FF_INPUT_BUFFER_PADDING_SIZE larger than @@ -2807,21 +2689,21 @@ int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples, * the linesize is not a multiple of 16 then there's no sense in aligning the * start of the buffer to 16. * - * @param avctx The codec context. + * @param avctx the codec context * @param[out] picture The AVFrame in which the decoded video frame will be stored. - * @param[in] buf The input buffer. - * @param[in] buf_size The size of the input buffer in bytes. - * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is non zero. + * @param[in] buf the input buffer + * @param[in] buf_size the size of the input buffer in bytes + * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero. * @return On error a negative value is returned, otherwise the number of bytes * used or zero if no frame could be decompressed. */ int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, - uint8_t *buf, int buf_size); + const uint8_t *buf, int buf_size); -/* decode a subtitle message. return -1 if error, otherwise return the - *number of bytes used. If no subtitle could be decompressed, - *got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */ +/* Decode a subtitle message. Return -1 if error, otherwise return the + * number of bytes used. If no subtitle could be decompressed, + * got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */ int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, const uint8_t *buf, int buf_size); @@ -2831,35 +2713,37 @@ int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata, /** * Encodes an audio frame from \p samples into \p buf. - * The avcodec_encode_audio() function encodes a frame of audio from the input - * buffer \p samples. To encode it, it makes use of the audiocodec which was + * The avcodec_encode_audio() function encodes an audio frame from the input + * buffer \p samples. To encode it, it makes use of the audio codec which was * coupled with \p avctx using avcodec_open(). The resulting encoded frame is * stored in output buffer \p buf. * * @note The output buffer should be at least \c FF_MIN_BUFFER_SIZE bytes large. * - * @param avctx The codec context. - * @param[out] buf The output buffer. - * @param[in] buf_size The output buffer size. - * @param[in] samples The input buffer containing the samples. - * @return On error a negative value is returned, on succes zero or the number - * of bytes used from the input buffer. + * @param avctx the codec context + * @param[out] buf the output buffer + * @param[in] buf_size the output buffer size + * @param[in] samples the input buffer containing the samples + * The number of samples read from this buffer is frame_size*channels, + * both of which are defined in \p avctx. + * @return On error a negative value is returned, on success zero or the number + * of bytes used to encode the data read from the input buffer. */ int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, const short *samples); /** * Encodes a video frame from \p pict into \p buf. - * The avcodec_encode_video() function encodes a frame of video from the input - * \p pict. To encode it, it makes use of the videocodec which was coupled with + * The avcodec_encode_video() function encodes a video frame from the input + * \p pict. To encode it, it makes use of the video codec which was coupled with * \p avctx using avcodec_open(). The resulting encoded bytes representing the * frame are stored in the output buffer \p buf. The input picture should be * stored using a specific format, namely \c avctx.pix_fmt. * - * @param avctx The codec context. - * @param[out] buf The output buffer for the bitstream of encoded frame. - * @param[in] buf_size The size of the outputbuffer in bytes. - * @param[in] pict The input picture to encode. + * @param avctx the codec context + * @param[out] buf the output buffer for the bitstream of encoded frame + * @param[in] buf_size the size of the output buffer in bytes + * @param[in] pict the input picture to encode * @return On error a negative value is returned, on success zero or the number * of bytes used from the input buffer. */ @@ -2884,7 +2768,7 @@ void avcodec_default_free_buffers(AVCodecContext *s); /** * Returns a single letter to describe the given picture type \p pict_type. * - * @param[in] pict_type The picture type. + * @param[in] pict_type the picture type * @return A single character representing the picture type. */ char av_get_pict_type_char(int pict_type); @@ -2892,11 +2776,19 @@ char av_get_pict_type_char(int pict_type); /** * Returns codec bits per sample. * - * @param[in] codec_id The codec. + * @param[in] codec_id the codec * @return Number of bits per sample or zero if unknown for the given codec. */ int av_get_bits_per_sample(enum CodecID codec_id); +/** + * Returns sample format bits per sample. + * + * @param[in] sample_fmt the sample format + * @return Number of bits per sample or zero if unknown for the given sample format. + */ +int av_get_bits_per_sample_format(enum SampleFormat sample_fmt); + /* frame parsing */ typedef struct AVCodecParserContext { void *priv_data; @@ -2906,8 +2798,8 @@ typedef struct AVCodecParserContext { (incremented by each av_parser_parse()) */ int64_t last_frame_offset; /* offset of the last frame */ /* video info */ - int pict_type; /* XXX: put it back in AVCodecContext */ - int repeat_pict; /* XXX: put it back in AVCodecContext */ + int pict_type; /* XXX: Put it back in AVCodecContext. */ + int repeat_pict; /* XXX: Put it back in AVCodecContext. */ int64_t pts; /* pts of the current frame */ int64_t dts; /* dts of the current frame */ @@ -2924,6 +2816,9 @@ typedef struct AVCodecParserContext { int flags; #define PARSER_FLAG_COMPLETE_FRAMES 0x0001 + + int64_t offset; ///< byte offset from starting packet start + int64_t last_offset; } AVCodecParserContext; typedef struct AVCodecParser { @@ -2932,14 +2827,17 @@ typedef struct AVCodecParser { int (*parser_init)(AVCodecParserContext *s); int (*parser_parse)(AVCodecParserContext *s, AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, + const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size); void (*parser_close)(AVCodecParserContext *s); int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size); struct AVCodecParser *next; } AVCodecParser; +#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) extern AVCodecParser *av_first_parser; +#endif +AVCodecParser *av_parser_next(AVCodecParser *c); void av_register_codec_parser(AVCodecParser *parser); AVCodecParserContext *av_parser_init(int codec_id); @@ -2954,22 +2852,6 @@ int av_parser_change(AVCodecParserContext *s, const uint8_t *buf, int buf_size, int keyframe); void av_parser_close(AVCodecParserContext *s); -extern AVCodecParser aac_parser; -extern AVCodecParser ac3_parser; -extern AVCodecParser cavsvideo_parser; -extern AVCodecParser dca_parser; -extern AVCodecParser dvbsub_parser; -extern AVCodecParser dvdsub_parser; -extern AVCodecParser h261_parser; -extern AVCodecParser h263_parser; -extern AVCodecParser h264_parser; -extern AVCodecParser mjpeg_parser; -extern AVCodecParser mpeg4video_parser; -extern AVCodecParser mpegaudio_parser; -extern AVCodecParser mpegvideo_parser; -extern AVCodecParser pnm_parser; -extern AVCodecParser vc1_parser; - typedef struct AVBitStreamFilterContext { void *priv_data; @@ -2986,11 +2868,10 @@ typedef struct AVBitStreamFilter { AVCodecContext *avctx, const char *args, uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size, int keyframe); + void (*close)(AVBitStreamFilterContext *bsfc); struct AVBitStreamFilter *next; } AVBitStreamFilter; -extern AVBitStreamFilter *av_first_bitstream_filter; - void av_register_bitstream_filter(AVBitStreamFilter *bsf); AVBitStreamFilterContext *av_bitstream_filter_init(const char *name); int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc, @@ -2999,14 +2880,7 @@ int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc, const uint8_t *buf, int buf_size, int keyframe); void av_bitstream_filter_close(AVBitStreamFilterContext *bsf); -extern AVBitStreamFilter dump_extradata_bsf; -extern AVBitStreamFilter remove_extradata_bsf; -extern AVBitStreamFilter noise_bsf; -extern AVBitStreamFilter mp3_header_compress_bsf; -extern AVBitStreamFilter mp3_header_decompress_bsf; -extern AVBitStreamFilter mjpega_dump_header_bsf; -extern AVBitStreamFilter imx_dump_header_bsf; - +AVBitStreamFilter *av_bitstream_filter_next(AVBitStreamFilter *f); /* memory */ @@ -3021,8 +2895,12 @@ void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size); /* for static data only */ /** - * Frees all static arrays and reset their pointers to 0. + * Frees all static arrays and resets their pointers to 0. * Call this function to release all statically allocated tables. + * + * @deprecated. Code which uses av_free_static is broken/misdesigned + * and should correctly use static arrays + * */ attribute_deprecated void av_free_static(void); @@ -3032,7 +2910,9 @@ attribute_deprecated void av_free_static(void); * @warning Do not use for normal allocation. * * @param[in] size The amount of memory you need in bytes. - * @return Block of memory of the requested size. + * @return block of memory of the requested size + * @deprecated. Code which uses av_mallocz_static is broken/misdesigned + * and should correctly use static arrays */ attribute_deprecated void *av_mallocz_static(unsigned int size); @@ -3043,49 +2923,80 @@ void av_picture_copy(AVPicture *dst, const AVPicture *src, int pix_fmt, int width, int height); /** - * Crop image top and left side + * Crop image top and left side. */ int av_picture_crop(AVPicture *dst, const AVPicture *src, int pix_fmt, int top_band, int left_band); /** - * Pad image + * Pad image. */ int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, int pix_fmt, int padtop, int padbottom, int padleft, int padright, int *color); #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) +/** + * @deprecated Use the software scaler (swscale) instead. + */ attribute_deprecated void img_copy(AVPicture *dst, const AVPicture *src, int pix_fmt, int width, int height); +/** + * @deprecated Use the software scaler (swscale) instead. + */ attribute_deprecated int img_crop(AVPicture *dst, const AVPicture *src, int pix_fmt, int top_band, int left_band); +/** + * @deprecated Use the software scaler (swscale) instead. + */ attribute_deprecated int img_pad(AVPicture *dst, const AVPicture *src, int height, int width, int pix_fmt, int padtop, int padbottom, int padleft, int padright, int *color); #endif extern unsigned int av_xiphlacing(unsigned char *s, unsigned int v); +/** + * Parses \p str and put in \p width_ptr and \p height_ptr the detected values. + * + * @return 0 in case of a successful parsing, a negative value otherwise + * @param[in] str the string to parse: it has to be a string in the format + * x or a valid video frame size abbreviation. + * @param[in,out] width_ptr pointer to the variable which will contain the detected + * frame width value + * @param[in,out] height_ptr pointer to the variable which will contain the detected + * frame height value + */ +int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str); + +/** + * Parses \p str and put in \p frame_rate the detected values. + * + * @return 0 in case of a successful parsing, a negative value otherwise + * @param[in] str the string to parse: it has to be a string in the format + * /, a float number or a valid video rate abbreviation + * @param[in,out] frame_rate pointer to the AVRational which will contain the detected + * frame rate + */ +int av_parse_video_frame_rate(AVRational *frame_rate, const char *str); + /* error handling */ #if EINVAL > 0 -#define AVERROR(e) (-(e)) /**< returns a negative error code from a POSIX error code, to return from library functions. */ -#define AVUNERROR(e) (-(e)) /**< returns a POSIX error code from a library function error return value. */ +#define AVERROR(e) (-(e)) /**< Returns a negative error code from a POSIX error code, to return from library functions. */ +#define AVUNERROR(e) (-(e)) /**< Returns a POSIX error code from a library function error return value. */ #else -/* some platforms have E* and errno already negated. */ +/* Some platforms have E* and errno already negated. */ #define AVERROR(e) (e) #define AVUNERROR(e) (e) #endif #define AVERROR_UNKNOWN AVERROR(EINVAL) /**< unknown error */ -#define AVERROR_IO AVERROR(EIO) /**< i/o error */ -#define AVERROR_NUMEXPECTED AVERROR(EDOM) /**< number syntax expected in filename */ +#define AVERROR_IO AVERROR(EIO) /**< I/O error */ +#define AVERROR_NUMEXPECTED AVERROR(EDOM) /**< Number syntax expected in filename. */ #define AVERROR_INVALIDDATA AVERROR(EINVAL) /**< invalid data found */ #define AVERROR_NOMEM AVERROR(ENOMEM) /**< not enough memory */ #define AVERROR_NOFMT AVERROR(EILSEQ) /**< unknown format */ -#define AVERROR_NOTSUPP AVERROR(ENOSYS) /**< operation not supported */ - -#ifdef __cplusplus -} -#endif +#define AVERROR_NOTSUPP AVERROR(ENOSYS) /**< Operation not supported. */ +#define AVERROR_NOENT AVERROR(ENOENT) /**< No such file or directory. */ +#define AVERROR_PATCHWELCOME -MKTAG('P','A','W','E') /**< Not yet implemented in FFmpeg. Patches welcome. */ -#endif /* AVCODEC_H */ +#endif /* FFMPEG_AVCODEC_H */ diff --git a/contrib/ffmpeg/libavcodec/avs.c b/contrib/ffmpeg/libavcodec/avs.c index ebfa8adb7..7d4f3e45e 100644 --- a/contrib/ffmpeg/libavcodec/avs.c +++ b/contrib/ffmpeg/libavcodec/avs.c @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avcodec.h" @@ -44,12 +44,13 @@ typedef enum { static int avs_decode_frame(AVCodecContext * avctx, - void *data, int *data_size, uint8_t * buf, int buf_size) + void *data, int *data_size, const uint8_t * buf, int buf_size) { avs_context_t *const avs = avctx->priv_data; AVFrame *picture = data; AVFrame *const p = (AVFrame *) & avs->picture; - uint8_t *table, *vect, *out; + const uint8_t *table, *vect; + uint8_t *out; int i, j, x, y, stride, vect_w = 3, vect_h = 3; int sub_type; avs_block_type_t type; diff --git a/contrib/ffmpeg/libavcodec/beosthread.c b/contrib/ffmpeg/libavcodec/beosthread.c index 3d059912b..4c99bc0ff 100644 --- a/contrib/ffmpeg/libavcodec/beosthread.c +++ b/contrib/ffmpeg/libavcodec/beosthread.c @@ -16,12 +16,10 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ //#define DEBUG #include "avcodec.h" -#include "common.h" #include @@ -74,8 +72,8 @@ static int32 ff_thread_func(void *v){ } /** - * free what has been allocated by avcodec_thread_init(). - * must be called after decoding has finished, especially dont call while avcodec_thread_execute() is running + * Free what has been allocated by avcodec_thread_init(). + * Must be called after decoding has finished, especially do not call while avcodec_thread_execute() is running. */ void avcodec_thread_free(AVCodecContext *s){ ThreadContext *c= s->thread_opaque; diff --git a/contrib/ffmpeg/libavcodec/bethsoftvideo.c b/contrib/ffmpeg/libavcodec/bethsoftvideo.c new file mode 100644 index 000000000..9d1f6124a --- /dev/null +++ b/contrib/ffmpeg/libavcodec/bethsoftvideo.c @@ -0,0 +1,139 @@ +/* + * Bethesda VID video decoder + * Copyright (C) 2007 Nicholas Tung + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file bethsoftvideo.c + * @brief Bethesda Softworks VID Video Decoder + * @author Nicholas Tung [ntung (at. ntung com] (2007-03) + * @sa http://wiki.multimedia.cx/index.php?title=Bethsoft_VID + * @sa http://www.svatopluk.com/andux/docs/dfvid.html + */ + +#include "common.h" +#include "dsputil.h" +#include "bethsoftvideo.h" +#include "bytestream.h" + +typedef struct BethsoftvidContext { + AVFrame frame; +} BethsoftvidContext; + +static int bethsoftvid_decode_init(AVCodecContext *avctx) +{ + BethsoftvidContext *vid = avctx->priv_data; + vid->frame.reference = 1; + vid->frame.buffer_hints = FF_BUFFER_HINTS_VALID | + FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + avctx->pix_fmt = PIX_FMT_PAL8; + return 0; +} + +static void set_palette(AVFrame * frame, const uint8_t * palette_buffer) +{ + uint32_t * palette = (uint32_t *)frame->data[1]; + int a; + for(a = 0; a < 256; a++){ + palette[a] = AV_RB24(&palette_buffer[a * 3]) * 4; + } + frame->palette_has_changed = 1; +} + +static int bethsoftvid_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size) +{ + BethsoftvidContext * vid = avctx->priv_data; + char block_type; + uint8_t * dst; + uint8_t * frame_end; + int remaining = avctx->width; // number of bytes remaining on a line + const int wrap_to_next_line = vid->frame.linesize[0] - avctx->width; + int code; + int yoffset; + + if (avctx->reget_buffer(avctx, &vid->frame)) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return -1; + } + dst = vid->frame.data[0]; + frame_end = vid->frame.data[0] + vid->frame.linesize[0] * avctx->height; + + switch(block_type = *buf++){ + case PALETTE_BLOCK: + set_palette(&vid->frame, buf); + return 0; + case VIDEO_YOFF_P_FRAME: + yoffset = bytestream_get_le16(&buf); + if(yoffset >= avctx->height) + return -1; + dst += vid->frame.linesize[0] * yoffset; + } + + // main code + while((code = *buf++)){ + int length = code & 0x7f; + + // copy any bytes starting at the current position, and ending at the frame width + while(length > remaining){ + if(code < 0x80) + bytestream_get_buffer(&buf, dst, remaining); + else if(block_type == VIDEO_I_FRAME) + memset(dst, buf[0], remaining); + length -= remaining; // decrement the number of bytes to be copied + dst += remaining + wrap_to_next_line; // skip over extra bytes at end of frame + remaining = avctx->width; + if(dst == frame_end) + goto end; + } + + // copy any remaining bytes after / if line overflows + if(code < 0x80) + bytestream_get_buffer(&buf, dst, length); + else if(block_type == VIDEO_I_FRAME) + memset(dst, *buf++, length); + remaining -= length; + dst += length; + } + end: + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = vid->frame; + + return buf_size; +} + +static int bethsoftvid_decode_end(AVCodecContext *avctx) +{ + BethsoftvidContext * vid = avctx->priv_data; + if(vid->frame.data[0]) + avctx->release_buffer(avctx, &vid->frame); + return 0; +} + +AVCodec bethsoftvid_decoder = { + .name = "bethsoftvid", + .type = CODEC_TYPE_VIDEO, + .id = CODEC_ID_BETHSOFTVID, + .priv_data_size = sizeof(BethsoftvidContext), + .init = bethsoftvid_decode_init, + .close = bethsoftvid_decode_end, + .decode = bethsoftvid_decode_frame, +}; diff --git a/contrib/ffmpeg/libavcodec/bethsoftvideo.h b/contrib/ffmpeg/libavcodec/bethsoftvideo.h new file mode 100644 index 000000000..96629cd05 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/bethsoftvideo.h @@ -0,0 +1,36 @@ +/* + * Bethesda VID video decoder + * Copyright (C) 2007 Nicholas Tung + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_BETHSOFTVIDEO_H +#define FFMPEG_BETHSOFTVIDEO_H + +enum BethsoftVidBlockType +{ + PALETTE_BLOCK = 0x02, + FIRST_AUDIO_BLOCK = 0x7c, + AUDIO_BLOCK = 0x7d, + VIDEO_I_FRAME = 0x03, + VIDEO_P_FRAME = 0x01, + VIDEO_YOFF_P_FRAME = 0x04, + EOF_BLOCK = 0x14, +}; + +#endif /* FFMPEG_BETHSOFTVIDEO_H */ diff --git a/contrib/ffmpeg/libavcodec/bfin/config_bfin.h b/contrib/ffmpeg/libavcodec/bfin/config_bfin.h index 1f5080900..0f0eab6be 100644 --- a/contrib/ffmpeg/libavcodec/bfin/config_bfin.h +++ b/contrib/ffmpeg/libavcodec/bfin/config_bfin.h @@ -29,18 +29,37 @@ DEFUN(put_pixels_clamped,mL1, rts; */ + +#ifndef FFMPEG_CONFIG_BFIN_H +#define FFMPEG_CONFIG_BFIN_H + #ifndef DEFUN +#define mL3 .text #ifndef mL1 +#ifdef __FDPIC__ #define mL1 .l1.text +#else +#define mL1 mL3 +#endif #endif -#define mL3 .text #define DEFUN(fname,where,interface) \ .section where; \ .global _ff_bfin_ ## fname ; \ + .type _ff_bfin_ ## fname, STT_FUNC; \ .align 8; \ _ff_bfin_ ## fname +#define DEFUN_END(fname) \ + .size _ff_bfin_ ## fname, . - _ff_bfin_ ## fname + +#ifdef __FDPIC__ +#define RELOC(reg,got,obj) reg = [got + obj@GOT17M4] +#else +#define RELOC(reg,got,obj) reg.L = obj; reg.H = obj +#endif + #endif +#endif /* FFMPEG_CONFIG_BFIN_H */ diff --git a/contrib/ffmpeg/libavcodec/bfin/dsputil_bfin.c b/contrib/ffmpeg/libavcodec/bfin/dsputil_bfin.c index b4d549fb7..a72459948 100644 --- a/contrib/ffmpeg/libavcodec/bfin/dsputil_bfin.c +++ b/contrib/ffmpeg/libavcodec/bfin/dsputil_bfin.c @@ -22,62 +22,43 @@ */ #include -#include -#include "../avcodec.h" -#include "../dsputil.h" +#include "avcodec.h" +#include "dsputil.h" +#include "dsputil_bfin.h" -#define USE_L1CODE - -#ifdef USE_L1CODE -#define L1CODE __attribute__ ((l1_text)) -#else -#define L1CODE -#endif int off; -extern void ff_bfin_idct (DCTELEM *block) L1CODE; -extern void ff_bfin_fdct (DCTELEM *block) L1CODE; -extern void ff_bfin_add_pixels_clamped (DCTELEM *block, uint8_t *dest, int line_size) L1CODE; -extern void ff_bfin_put_pixels_clamped (DCTELEM *block, uint8_t *dest, int line_size) L1CODE; -extern void ff_bfin_diff_pixels (DCTELEM *block, uint8_t *s1, uint8_t *s2, int stride) L1CODE; -extern void ff_bfin_get_pixels (DCTELEM *restrict block, const uint8_t *pixels, int line_size) L1CODE; -extern int ff_bfin_pix_norm1 (uint8_t * pix, int line_size) L1CODE; -extern int ff_bfin_z_sad8x8 (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h) L1CODE; -extern int ff_bfin_z_sad16x16 (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h) L1CODE; - -extern void ff_bfin_z_put_pixels16_xy2 (uint8_t *block, const uint8_t *s0, int dest_size, int line_size, int h) L1CODE; -extern void ff_bfin_z_put_pixels8_xy2 (uint8_t *block, const uint8_t *s0, int dest_size, int line_size, int h) L1CODE; -extern void ff_bfin_put_pixels16_xy2_nornd (uint8_t *block, const uint8_t *s0, int line_size, int h) L1CODE; -extern void ff_bfin_put_pixels8_xy2_nornd (uint8_t *block, const uint8_t *s0, int line_size, int h) L1CODE; +extern void ff_bfin_idct (DCTELEM *block) attribute_l1_text; +extern void ff_bfin_fdct (DCTELEM *block) attribute_l1_text; +extern void ff_bfin_vp3_idct (DCTELEM *block); +extern void ff_bfin_vp3_idct_put (uint8_t *dest, int line_size, DCTELEM *block); +extern void ff_bfin_vp3_idct_add (uint8_t *dest, int line_size, DCTELEM *block); +extern void ff_bfin_add_pixels_clamped (DCTELEM *block, uint8_t *dest, int line_size) attribute_l1_text; +extern void ff_bfin_put_pixels_clamped (DCTELEM *block, uint8_t *dest, int line_size) attribute_l1_text; +extern void ff_bfin_diff_pixels (DCTELEM *block, uint8_t *s1, uint8_t *s2, int stride) attribute_l1_text; +extern void ff_bfin_get_pixels (DCTELEM *restrict block, const uint8_t *pixels, int line_size) attribute_l1_text; +extern int ff_bfin_pix_norm1 (uint8_t * pix, int line_size) attribute_l1_text; +extern int ff_bfin_z_sad8x8 (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h) attribute_l1_text; +extern int ff_bfin_z_sad16x16 (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h) attribute_l1_text; +extern void ff_bfin_z_put_pixels16_xy2 (uint8_t *block, const uint8_t *s0, int dest_size, int line_size, int h) attribute_l1_text; +extern void ff_bfin_z_put_pixels8_xy2 (uint8_t *block, const uint8_t *s0, int dest_size, int line_size, int h) attribute_l1_text; +extern void ff_bfin_put_pixels16_xy2_nornd (uint8_t *block, const uint8_t *s0, int line_size, int h) attribute_l1_text; +extern void ff_bfin_put_pixels8_xy2_nornd (uint8_t *block, const uint8_t *s0, int line_size, int h) attribute_l1_text; -extern int ff_bfin_pix_sum (uint8_t *p, int stride) L1CODE; -extern void ff_bfin_put_pixels8uc (uint8_t *block, const uint8_t *s0, const uint8_t *s1, int dest_size, int line_size, int h) L1CODE; -extern void ff_bfin_put_pixels16uc (uint8_t *block, const uint8_t *s0, const uint8_t *s1, int dest_size, int line_size, int h) L1CODE; -extern void ff_bfin_put_pixels8uc_nornd (uint8_t *block, const uint8_t *s0, const uint8_t *s1, int line_size, int h) L1CODE; -extern void ff_bfin_put_pixels16uc_nornd (uint8_t *block, const uint8_t *s0, const uint8_t *s1, int line_size, int h) L1CODE; +extern int ff_bfin_pix_sum (uint8_t *p, int stride) attribute_l1_text; -extern int ff_bfin_sse4 (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) L1CODE; -extern int ff_bfin_sse8 (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) L1CODE; -extern int ff_bfin_sse16 (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) L1CODE; +extern void ff_bfin_put_pixels8uc (uint8_t *block, const uint8_t *s0, const uint8_t *s1, int dest_size, int line_size, int h) attribute_l1_text; +extern void ff_bfin_put_pixels16uc (uint8_t *block, const uint8_t *s0, const uint8_t *s1, int dest_size, int line_size, int h) attribute_l1_text; +extern void ff_bfin_put_pixels8uc_nornd (uint8_t *block, const uint8_t *s0, const uint8_t *s1, int line_size, int h) attribute_l1_text; +extern void ff_bfin_put_pixels16uc_nornd (uint8_t *block, const uint8_t *s0, const uint8_t *s1, int line_size, int h) attribute_l1_text; +extern int ff_bfin_sse4 (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) attribute_l1_text; +extern int ff_bfin_sse8 (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) attribute_l1_text; +extern int ff_bfin_sse16 (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) attribute_l1_text; -#if 0 -void pblk (uint8_t *p, int w, int h, int s) -{ - int i,j; - av_log (0,0,"0x%08x:\n", p); - for (i = 0;isad[0] = bfin_pix_abs16; c->sad[1] = bfin_pix_abs8; + c->vsad[0] = bfin_vsad; + c->vsad[4] = bfin_vsad_intra16; + /* TODO [0] 16 [1] 8 */ c->pix_abs[0][0] = bfin_pix_abs16; c->pix_abs[0][1] = bfin_pix_abs16_x2; @@ -300,10 +293,17 @@ void dsputil_init_bfin( DSPContext* c, AVCodecContext *avctx ) c->put_no_rnd_pixels_tab[0][2] = bfin_put_pixels16_y2_nornd; c->put_no_rnd_pixels_tab[0][3] = ff_bfin_put_pixels16_xy2_nornd; - c->fdct = ff_bfin_fdct; - c->idct = ff_bfin_idct; - c->idct_add = bfin_idct_add; - c->idct_put = bfin_idct_put; + c->idct_permutation_type = FF_NO_IDCT_PERM; + c->fdct = ff_bfin_fdct; + if (avctx->idct_algo==FF_IDCT_VP3) { + c->idct = ff_bfin_vp3_idct; + c->idct_add = ff_bfin_vp3_idct_add; + c->idct_put = ff_bfin_vp3_idct_put; + } else { + c->idct = ff_bfin_idct; + c->idct_add = bfin_idct_add; + c->idct_put = bfin_idct_put; + } } diff --git a/contrib/ffmpeg/libavcodec/bfin/dsputil_bfin.h b/contrib/ffmpeg/libavcodec/bfin/dsputil_bfin.h new file mode 100644 index 000000000..411c8ea73 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/bfin/dsputil_bfin.h @@ -0,0 +1,74 @@ +/* + * BlackFin DSPUTILS COMMON OPTIMIZATIONS HEADER + * + * Copyright (C) 2007 Marc Hoffman + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +#ifndef FFMPEG_DSPUTIL_BFIN_H +#define FFMPEG_DSPUTIL_BFIN_H + +#ifdef __FDPIC__ +#define attribute_l1_text __attribute__ ((l1_text)) +#define attribute_l1_data_b __attribute__((l1_data_B)) +#else +#define attribute_l1_text +#define attribute_l1_data_b +#endif + +#ifdef BFIN_PROFILE + +static double Telem[16]; +static char *TelemNames[16]; +static int TelemCnt; + +#define PROF(lab,e) { int xx_e = e; char*xx_lab = lab; uint64_t xx_t0 = read_time(); +#define EPROF() xx_t0 = read_time()-xx_t0; Telem[xx_e] = Telem[xx_e] + xx_t0; TelemNames[xx_e] = xx_lab; } + +static void prof_report (void) +{ + int i; + double s = 0; + for (i=0;i<16;i++) { + double v; + if (TelemNames[i]) { + v = Telem[i]/TelemCnt; + av_log (NULL,AV_LOG_DEBUG,"%-20s: %12.4f\t%12.4f\n", TelemNames[i],v,v/64); + s = s + Telem[i]; + } + } + av_log (NULL,AV_LOG_DEBUG,"%-20s: %12.4f\t%12.4f\n%20.4f\t%d\n", + "total",s/TelemCnt,s/TelemCnt/64,s,TelemCnt); +} + +static void bfprof (void) +{ + static int init; + if (!init) atexit (prof_report); + init=1; + TelemCnt++; +} + +#else +#define PROF(a,b) +#define EPROF() +#define bfprof() +#endif + +#endif /* FFMPEG_DSPUTIL_BFIN_H */ diff --git a/contrib/ffmpeg/libavcodec/bfin/fdct_bfin.S b/contrib/ffmpeg/libavcodec/bfin/fdct_bfin.S index 8230673e8..03f2709e3 100644 --- a/contrib/ffmpeg/libavcodec/bfin/fdct_bfin.S +++ b/contrib/ffmpeg/libavcodec/bfin/fdct_bfin.S @@ -129,23 +129,30 @@ root:/u/ffmpeg/bhead/libavcodec> #include "config_bfin.h" +#ifdef __FDPIC__ .section .l1.data.B,"aw",@progbits +#else +.data +#endif .align 4; dct_coeff: .short 0x5a82, 0x2d41, 0x187e, 0x3b21, 0x0c7c, 0x3ec5, 0x238e, 0x3537; +#ifdef __FDPIC__ .section .l1.data.A,"aw",@progbits +#endif .align 4 vtmp: .space 128 +.text DEFUN(fdct,mL1, (DCTELEM *block)): [--SP] = (R7:4, P5:3); // Push the registers onto the stack. b0 = r0; - r0 = [P3+dct_coeff@GOT17M4]; + RELOC(r0, P3, dct_coeff); b3 = r0; - r0 = [P3+vtmp@GOT17M4]; + RELOC(r0, P3, vtmp); b2 = r0; L3 = 16; // L3 is set to 16 to make the coefficient @@ -321,4 +328,5 @@ DEFUN(fdct,mL1, L3=0; (r7:4,p5:3) = [sp++]; RTS; +DEFUN_END(fdct) diff --git a/contrib/ffmpeg/libavcodec/bfin/idct_bfin.S b/contrib/ffmpeg/libavcodec/bfin/idct_bfin.S index f6904c189..7bb104038 100644 --- a/contrib/ffmpeg/libavcodec/bfin/idct_bfin.S +++ b/contrib/ffmpeg/libavcodec/bfin/idct_bfin.S @@ -57,7 +57,11 @@ IDCT BFINidct: 88.3 kdct/s #include "config_bfin.h" +#ifdef __FDPIC__ .section .l1.data.B,"aw",@progbits +#else +.data +#endif .align 4; coefs: @@ -72,7 +76,9 @@ coefs: .short 0x18F9; //cos(7pi/16) .short 0x7D8A; //cos(pi/16) -.section .l1.data.A +#ifdef __FDPIC__ +.section .l1.data.A,"aw",@progbits +#endif vtmp: .space 256 @@ -81,6 +87,7 @@ vtmp: .space 256 #define TMP2 FP-16 +.text DEFUN(idct,mL1, (DCTELEM *block)): @@ -88,8 +95,8 @@ DEFUN(idct,mL1, link 16; [--SP] = (R7:4, P5:3); // Push the registers onto the stack. B0 = R0; // Pointer to Input matrix - R1 = [P3+coefs@GOT17M4]; // Pointer to Coefficients - R2 = [P3+vtmp@GOT17M4]; // Pointer to Temporary matrix + RELOC(R1, P3, coefs); // Pointer to Coefficients + RELOC(R2, P3, vtmp); // Pointer to Temporary matrix B3 = R1; B2 = R2; L3 = 20; // L3 is used for making the coefficient array @@ -293,5 +300,6 @@ DEFUN(idct,mL1, (R7:4,P5:3)=[SP++]; unlink; RTS; +DEFUN_END(idct) diff --git a/contrib/ffmpeg/libavcodec/bfin/mathops.h b/contrib/ffmpeg/libavcodec/bfin/mathops.h new file mode 100644 index 000000000..ec40f4e68 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/bfin/mathops.h @@ -0,0 +1,52 @@ +/* + * mathops.h + * + * Copyright (C) 2007 Marc Hoffman + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef FFMPEG_BFIN_MATHOPS_H +#define FFMPEG_BFIN_MATHOPS_H + +#ifdef CONFIG_MPEGAUDIO_HP +#define MULH(X,Y) ({ int xxo; \ + asm ( \ + "a1 = %2.L * %1.L (FU);\n\t" \ + "a1 = a1 >> 16;\n\t" \ + "a1 += %2.H * %1.L (IS,M);\n\t" \ + "a0 = %1.H * %2.H, a1+= %1.H * %2.L (IS,M);\n\t"\ + "a1 = a1 >>> 16;\n\t" \ + "%0 = (a0 += a1);\n\t" \ + : "=d" (xxo) : "d" (X), "d" (Y) : "A0","A1"); xxo; }) +#else +#define MULH(X,Y) ({ int xxo; \ + asm ( \ + "a1 = %2.H * %1.L (IS,M);\n\t" \ + "a0 = %1.H * %2.H, a1+= %1.H * %2.L (IS,M);\n\t"\ + "a1 = a1 >>> 16;\n\t" \ + "%0 = (a0 += a1);\n\t" \ + : "=d" (xxo) : "d" (X), "d" (Y) : "A0","A1"); xxo; }) +#endif + +/* signed 16x16 -> 32 multiply */ +#define MUL16(a, b) ({ int xxo; \ + asm ( \ + "%0 = %1.l*%2.l (is);\n\t" \ + : "=W" (xxo) : "d" (a), "d" (b) : "A1"); \ + xxo; }) + +#endif /* FFMPEG_BFIN_MATHOPS_H */ diff --git a/contrib/ffmpeg/libavcodec/bfin/mpegvideo_bfin.c b/contrib/ffmpeg/libavcodec/bfin/mpegvideo_bfin.c new file mode 100644 index 000000000..9dd121baf --- /dev/null +++ b/contrib/ffmpeg/libavcodec/bfin/mpegvideo_bfin.c @@ -0,0 +1,152 @@ +/* + * BlackFin MPEGVIDEO OPTIMIZATIONS + * + * Copyright (C) 2007 Marc Hoffman + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "dsputil.h" +#include "mpegvideo.h" +#include "avcodec.h" +#include "dsputil_bfin.h" + + +extern void ff_bfin_fdct (DCTELEM *block) attribute_l1_text; + + +static int dct_quantize_bfin (MpegEncContext *s, + DCTELEM *block, int n, + int qscale, int *overflow) +{ + int last_non_zero, q, start_i; + const short *qmat; + short *bias; + const uint8_t *scantable= s->intra_scantable.scantable; + short dc; + int max=0; + + PROF("fdct",0); + ff_bfin_fdct (block); + EPROF(); + + PROF("denoise",1); + if(s->dct_error_sum) + s->denoise_dct(s, block); + EPROF(); + + PROF("quant-init",2); + if (s->mb_intra) { + if (!s->h263_aic) { + if (n < 4) + q = s->y_dc_scale; + else + q = s->c_dc_scale; + q = q << 3; + } else + /* For AIC we skip quant/dequant of INTRADC */ + q = 1 << 3; + + /* note: block[0] is assumed to be positive */ + dc = block[0] = (block[0] + (q >> 1)) / q; + start_i = 1; + last_non_zero = 0; + bias = s->q_intra_matrix16[qscale][1]; + qmat = s->q_intra_matrix16[qscale][0]; + + } else { + start_i = 0; + last_non_zero = -1; + bias = s->q_inter_matrix16[qscale][1]; + qmat = s->q_inter_matrix16[qscale][0]; + + } + EPROF(); + + PROF("quantize",4); + + /* for(i=start_i; i<64; i++) { */ + /* sign = (block[i]>>15)|1; */ + /* level = ((abs(block[i])+bias[0])*qmat[i])>>16; */ + /* if (level < 0) level = 0; */ + /* max |= level; */ + /* level = level * sign; */ + /* block[i] = level; */ + /* } */ + + asm volatile + ("i2=%1;\n\t" + "r1=[%1++]; \n\t" + "r0=r1>>>15 (v); \n\t" + "lsetup (0f,1f) lc0=%3; \n\t" + "0: r0=r0|%4; \n\t" + " r1=abs r1 (v) || r2=[%2++];\n\t" + " r1=r1+|+%5; \n\t" + " r1=max(r1,%6) (v); \n\t" + " r1.h=(a1 =r1.h*r2.h), r1.l=(a0 =r1.l*r2.l) (tfu); \n\t" + " %0=%0|r1; \n\t" + " r0.h=(a1 =r1.h*r0.h), r0.l=(a0 =r1.l*r0.l) (is) || r1=[%1++];\n\t" + "1: r0=r1>>>15 (v) || [i2++]=r0;\n\t" + "r1=%0>>16; \n\t" + "%0=%0|r1; \n\t" + "%0.h=0; \n\t" + : "=&d" (max) + : "b" (block), "b" (qmat), "a" (32), "d" (0x00010001), "d" (bias[0]*0x10001), "d" (0) + : "R0","R1","R2", "I2"); + if (start_i == 1) block[0] = dc; + + EPROF(); + + + PROF("zzscan",5); + + asm volatile + ("r0=b[%1--] (x); \n\t" + "lsetup (0f,1f) lc0=%3; \n\t" /* for(i=63; i>=start_i; i--) { */ + "0: p0=r0; \n\t" /* j = scantable[i]; */ + " p0=%2+(p0<<1); \n\t" /* if (block[j]) { */ + " r0=w[p0]; \n\t" /* last_non_zero = i; */ + " cc=r0==0; \n\t" /* break; */ + " if !cc jump 2f; \n\t" /* } */ + "1: r0=b[%1--] (x); \n\t" /* } */ + " %0=%4; \n\t" + " jump 3f; \n\t" + "2: %0=lc0; \n\t" + "3:\n\t" + + : "=d" (last_non_zero) + : "a" (scantable+63), "a" (block), "a" (63), "d" (last_non_zero) + : "P0","R0"); + + EPROF(); + + *overflow= s->max_qcoeff < max; //overflow might have happened + + bfprof(); + + /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */ + if (s->dsp.idct_permutation_type != FF_NO_IDCT_PERM) + ff_block_permute(block, s->dsp.idct_permutation, scantable, last_non_zero); + + return last_non_zero; +} + +void MPV_common_init_bfin (MpegEncContext *s) +{ + s->dct_quantize= dct_quantize_bfin; +} + diff --git a/contrib/ffmpeg/libavcodec/bfin/pixels_bfin.S b/contrib/ffmpeg/libavcodec/bfin/pixels_bfin.S index 2968fcff6..69b493b64 100644 --- a/contrib/ffmpeg/libavcodec/bfin/pixels_bfin.S +++ b/contrib/ffmpeg/libavcodec/bfin/pixels_bfin.S @@ -48,6 +48,7 @@ ppc$1: R2 = Max(R0, R4) (V) || [I1++M1] = R6; (R7:4) = [SP++]; RTS; +DEFUN_END(put_pixels_clamped) DEFUN(add_pixels_clamped,mL1, (DCTELEM *block, uint8_t *dest, int line_size)): @@ -80,6 +81,7 @@ apc$3: R6 = BYTEOP3P(R1:0, R3:2) (LO) || [I2++M0] = R6 || R2 = [I1]; (R7:4) = [SP++]; RTS; +DEFUN_END(add_pixels_clamped) /* @@ -121,6 +123,7 @@ pp8$1: DISALGNEXCPT || R2 = [I1++] || [I3++M3] = R7; (r7:6) = [sp++]; RTS; +DEFUN_END(put_pixels8uc) DEFUN(put_pixels16uc,mL1, (uint8_t *block, const uint8_t *s0, const uint8_t *s1, @@ -155,6 +158,7 @@ pp16$1: DISALGNEXCPT || R2 = [I1++] || [I3++M3] = R7; (r7:6) = [sp++]; unlink; RTS; +DEFUN_END(put_pixels16uc) @@ -184,6 +188,7 @@ pp8$3: DISALGNEXCPT || R2 = [I1++] || [I3++M3] = R7; (r7:6) = [sp++]; RTS; +DEFUN_END(put_pixels8uc_nornd) DEFUN(put_pixels16uc_nornd,mL1, (uint8_t *block, const uint8_t *s0, const uint8_t *s1, @@ -217,6 +222,7 @@ pp16$3: DISALGNEXCPT || R2 = [I1++] || [I3++M3] = R7; (r7:6) = [sp++]; RTS; +DEFUN_END(put_pixels16uc_nornd) DEFUN(z_put_pixels16_xy2,mL1, (uint8_t *block, const uint8_t *s0, @@ -275,6 +281,7 @@ LE$16O: DISALGNEXCPT || R2 = [I1++] || [I3++M2] = R5; (r7:4) = [sp++]; unlink; rts; +DEFUN_END(z_put_pixels16_xy2) DEFUN(put_pixels16_xy2_nornd,mL1, (uint8_t *block, const uint8_t *s0, @@ -332,6 +339,7 @@ LE$16OT:DISALGNEXCPT || R2 = [I1++] || [I3++M2] = R5; (r7:4) = [sp++]; unlink; rts; +DEFUN_END(put_pixels16_xy2_nornd) DEFUN(z_put_pixels8_xy2,mL1, (uint8_t *block, const uint8_t *s0, @@ -381,6 +389,7 @@ LE$8O: DISALGNEXCPT || R2 =[I1++] || [I3++M2] = R5; (r7:4) = [sp++]; unlink; rts; +DEFUN_END(z_put_pixels8_xy2) DEFUN(put_pixels8_xy2_nornd,mL1, (uint8_t *block, const uint8_t *s0, int line_size, int h)): @@ -458,6 +467,7 @@ DEFUN(diff_pixels,mL1, (r7:4) = [sp++]; unlink; rts; +DEFUN_END(put_pixels8_xy2_nornd) /* for (i = 0; i < 16; i++) { @@ -504,6 +514,7 @@ LE$PS: r6=r6+|+r4; (r7:4) = [sp++]; unlink; rts; +DEFUN_END(pix_sum) DEFUN(get_pixels,mL1, @@ -528,6 +539,7 @@ gp8$1: [I3++]=R5 (r7:4) = [sp++]; RTS; +DEFUN_END(get_pixels) /* sad = sad16x16 (ubyte *mb, ubyte *refwin, srcwidth, refwinwidth, h) */ @@ -559,6 +571,7 @@ e$16: SAA (R1:0,R3:2) (R) || R0 = [I0++] || R2 = [I1++]; R0 = R2 + R3 ; unlink; RTS; +DEFUN_END(z_sad16x16) /* sad = sad8x8 (ubyte *mb, ubyte *refwin, int srcwidth, int refwinwidth, int h) */ /* 36 cycles */ @@ -586,6 +599,7 @@ e$8: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++]; R3=A1.L+A1.H, R2=A0.L+A0.H ; R0 = R2 + R3 ; RTS; +DEFUN_END(z_sad8x8) DEFUN(pix_norm1,mL1, (uint8_t * pix, int line_size)): @@ -629,6 +643,7 @@ _pix_norm1_blkfn_loopEnd: (R7:4,P5:3)=[SP++]; RTS; +DEFUN_END(pix_norm1) DEFUN(sse4,mL1, (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)): @@ -655,6 +670,7 @@ DEFUN(sse4,mL1, (r7:6) = [sp++]; unlink; rts; +DEFUN_END(sse4) DEFUN(sse8,mL1, (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)): @@ -684,6 +700,7 @@ DEFUN(sse8,mL1, (r7:6) = [sp++]; unlink; rts; +DEFUN_END(sse8) DEFUN(sse16,mL1, (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)): @@ -719,5 +736,6 @@ DEFUN(sse16,mL1, (r7:6) = [sp++]; unlink; rts; +DEFUN_END(sse16) diff --git a/contrib/ffmpeg/libavcodec/bfin/vp3_bfin.c b/contrib/ffmpeg/libavcodec/bfin/vp3_bfin.c new file mode 100644 index 000000000..fce5668d0 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/bfin/vp3_bfin.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2007 Marc Hoffman + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "dsputil.h" +#include "dsputil_bfin.h" + +extern void ff_bfin_vp3_idct (DCTELEM *block) attribute_l1_text; +extern void ff_bfin_idct (DCTELEM *block) attribute_l1_text; +extern void ff_bfin_add_pixels_clamped (DCTELEM *block, uint8_t *dest, int line_size) attribute_l1_text; +extern void ff_bfin_put_pixels_clamped (DCTELEM *block, uint8_t *dest, int line_size) attribute_l1_text; + +/* Intra iDCT offset 128 */ +void ff_bfin_vp3_idct_put (uint8_t *dest, int line_size, DCTELEM *block) +{ + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + int i,j; + + ff_bfin_vp3_idct (block); + + for (i=0;i<8;i++) + for (j=0;j<8;j++) + dest[line_size*i+j]=cm[128+block[i*8+j]]; +} + +/* Inter iDCT */ +void ff_bfin_vp3_idct_add (uint8_t *dest, int line_size, DCTELEM *block) +{ + ff_bfin_vp3_idct (block); + ff_bfin_add_pixels_clamped (block, dest, line_size); +} + + diff --git a/contrib/ffmpeg/libavcodec/bfin/vp3_idct_bfin.S b/contrib/ffmpeg/libavcodec/bfin/vp3_idct_bfin.S new file mode 100644 index 000000000..ec8c1bee7 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/bfin/vp3_idct_bfin.S @@ -0,0 +1,281 @@ +/* + * vp3_idct BlackFin + * + * Copyright (C) 2007 Marc Hoffman + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +/* + This blackfin DSP code implements an 8x8 inverse type II DCT. + +Prototype : void ff_bfin_vp3_idct(DCTELEM *in) + +Registers Used : A0, A1, R0-R7, I0-I3, B0, B2, B3, M0-M2, L0-L3, P0-P5, LC0. + +*/ + +#include "config_bfin.h" + +#ifdef __FDPIC__ +.section .l1.data.B,"aw",@progbits +#else +.data +#endif + +.align 4; +coefs: +.short 0x5a82; // C4 +.short 0x5a82; // C4 +.short 0x30FC; //cos(3pi/8) C6 +.short 0x7642; //cos(pi/8) C2 +.short 0x18F9; //cos(7pi/16) +.short 0x7D8A; //cos(pi/16) +.short 0x471D; //cos(5pi/16) +.short 0x6A6E; //cos(3pi/16) +.short 0x18F9; //cos(7pi/16) +.short 0x7D8A; //cos(pi/16) + +#ifdef __FDPIC__ +.section .l1.data.A +#endif + +vtmp: .space 256 + +#define TMP0 FP-8 +#define TMP1 FP-12 +#define TMP2 FP-16 + + +.text +DEFUN(vp3_idct,mL1, + (DCTELEM *block)): + +/********************** Function Prologue *********************************/ + link 16; + [--SP] = (R7:4, P5:3); // Push the registers onto the stack. + B0 = R0; // Pointer to Input matrix + RELOC(R1, P3, coefs); // Pointer to Coefficients + RELOC(R2, P3, vtmp); // Pointer to Temporary matrix + B3 = R1; + B2 = R2; + L3 = 20; // L3 is used for making the coefficient array + // circular. + // MUST BE RESTORED TO ZERO at function exit. + M1 = 16 (X); // All these registers are initialized for + M3 = 8(X); // modifying address offsets. + + I0 = B0; // I0 points to Input Element (0, 0). + I2 = B0; // I2 points to Input Element (0, 0). + I2 += M3 || R0.H = W[I0]; + // Element 0 is read into R0.H + I1 = I2; // I1 points to input Element (0, 6). + I1 += 4 || R0.L = W[I2++]; + // I2 points to input Element (0, 4). + // Element 4 is read into R0.L. + P2 = 8 (X); + P3 = 32 (X); + P4 = -32 (X); + P5 = 98 (X); + R7 = 0x8000(Z); + I3 = B3; // I3 points to Coefficients + P0 = B2; // P0 points to array Element (0, 0) of temp + P1 = B2; + R7 = [I3++] || [TMP2]=R7; // Coefficient C4 is read into R7.H and R7.L. + MNOP; + NOP; + + /* + * A1 = Y0 * cos(pi/4) + * A0 = Y0 * cos(pi/4) + * A1 = A1 + Y4 * cos(pi/4) + * A0 = A0 - Y4 * cos(pi/4) + * load: + * R1=(Y2,Y6) + * R7=(C2,C6) + * res: + * R3=Y0, R2=Y4 + */ + A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || I0+= 4 || R1.L=W[I1++]; + R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || R1.H=W[I0--] || R7=[I3++]; + + LSETUP (.0, .1) LC0 = P2; // perform 8 1d idcts + + P2 = 112 (X); + P1 = P1 + P2; // P1 points to element (7, 0) of temp buffer. + P2 = -94(X); + +.0: + /* + * A1 = Y2 * cos(3pi/8) + * A0 = Y2 * cos(pi/8) + * A1 = A1 - Y6 * cos(pi/8) + * A0 = A0 + Y6 * cos(3pi/8) + * R5 = (Y1,Y7) + * R7 = (C1,C7) + * res: + * R1=Y2, R0=Y6 + */ + A1=R7.L*R1.H, A0=R7.H*R1.H (IS) || I0+=4 || R5.H=W[I0]; + R1=(A1-=R7.H*R1.L), R0=(A0+=R7.L*R1.L) (IS) || R5.L=W[I1--] || R7=[I3++]; + /* + * Y0 = Y0 + Y6. + * Y4 = Y4 + Y2. + * Y2 = Y4 - Y2. + * Y6 = Y0 - Y6. + * R3 is saved + * R6.l=Y3 + * note: R3: Y0, R2: Y4, R1: Y2, R0: Y6 + */ + R3=R3+R0, R0=R3-R0; + R2=R2+R1, R1=R2-R1 || [TMP0]=R3 || R6.L=W[I0--]; + /* + * Compute the odd portion (1,3,5,7) even is done. + * + * Y1 = C7 * Y1 - C1 * Y7 + C3 * Y5 - C5 * Y3. + * Y7 = C1 * Y1 + C7 * Y7 + C5 * Y5 + C3 * Y3. + * Y5 = C5 * Y1 + C3 * Y7 + C7 * Y5 - C1 * Y3. + * Y3 = C3 * Y1 - C5 * Y7 - C1 * Y5 - C7 * Y3. + */ + // R5=(Y1,Y7) R6=(Y5,Y3) // R7=(C1,C7) + A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || [TMP1]=R2 || R6.H=W[I2--]; + A1-=R7.H*R5.L, A0+=R7.L*R5.L (IS) || I0-=4 || R7=[I3++]; + A1+=R7.H*R6.H, A0+=R7.L*R6.H (IS) || I0+=M1; // R7=(C3,C5) + R3 =(A1-=R7.L*R6.L), R2 =(A0+=R7.H*R6.L) (IS); + A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || R4=[TMP0]; + A1+=R7.H*R5.L, A0-=R7.L*R5.L (IS) || I1+=M1 || R7=[I3++]; // R7=(C1,C7) + A1+=R7.L*R6.H, A0-=R7.H*R6.H (IS); + R7 =(A1-=R7.H*R6.L), R6 =(A0-=R7.L*R6.L) (IS) || I2+=M1; + // R3=Y1, R2=Y7, R7=Y5, R6=Y3 + + /* Transpose write column. */ + R5.H=R4+R2 (RND12); // Y0=Y0+Y7 + R5.L=R4-R2 (RND12) || R4 = [TMP1]; // Y7=Y7-Y0 + R2.H=R1+R7 (RND12) || W[P0++P3]=R5.H; // Y2=Y2+Y5 st Y0 + R2.L=R1-R7 (RND12) || W[P1++P4]=R5.L || R7=[I3++]; // Y5=Y2-Y5 st Y7 + R5.H=R0-R3 (RND12) || W[P0++P3]=R2.H || R1.L=W[I1++]; // Y1=Y6-Y1 st Y2 + R5.L=R0+R3 (RND12) || W[P1++P4]=R2.L || R0.H=W[I0++]; // Y6=Y6+Y1 st Y5 + R3.H=R4-R6 (RND12) || W[P0++P3]=R5.H || R0.L=W[I2++]; // Y3=Y3-Y4 st Y1 + R3.L=R4+R6 (RND12) || W[P1++P4]=R5.L || R1.H=W[I0++]; // Y4=Y3+Y4 st Y6 + + /* pipeline loop start, + drain Y3, Y4 */ + A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || W[P0++P2]= R3.H || R1.H = W[I0--]; +.1: R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || W[P1++P5]= R3.L || R7 = [I3++]; + + + + I0 = B2; // I0 points to Input Element (0, 0) + I2 = B2; // I2 points to Input Element (0, 0) + I2 += M3 || R0.H = W[I0]; + // Y0 is read in R0.H + I1 = I2; // I1 points to input Element (0, 6) + I1 += 4 || R0.L = W[I2++]; + // I2 points to input Element (0, 4) + // Y4 is read in R0.L + P2 = 8 (X); + I3 = B3; // I3 points to Coefficients + P0 = B0; // P0 points to array Element (0, 0) for writing + // output + P1 = B0; + R7 = [I3++]; // R7.H = C4 and R7.L = C4 + NOP; + + /* + * A1 = Y0 * cos(pi/4) + * A0 = Y0 * cos(pi/4) + * A1 = A1 + Y4 * cos(pi/4) + * A0 = A0 - Y4 * cos(pi/4) + * load: + * R1=(Y2,Y6) + * R7=(C2,C6) + * res: + * R3=Y0, R2=Y4 + */ + A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || I0+=4 || R1.L=W[I1++]; + R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || R1.H=W[I0--] || R7=[I3++]; + + LSETUP (.2, .3) LC0 = P2; // peform 8 1d idcts + P2 = 112 (X); + P1 = P1 + P2; + P2 = -94(X); + +.2: + /* + * A1 = Y2 * cos(3pi/8) + * A0 = Y2 * cos(pi/8) + * A1 = A1 - Y6 * cos(pi/8) + * A0 = A0 + Y6 * cos(3pi/8) + * R5 = (Y1,Y7) + * R7 = (C1,C7) + * res: + * R1=Y2, R0=Y6 + */ + A1=R7.L*R1.H, A0=R7.H*R1.H (IS) || I0+=4 || R5.H=W[I0]; + R1=(A1-=R7.H*R1.L), R0=(A0+=R7.L*R1.L) (IS) || R5.L=W[I1--] || R7=[I3++]; + /* + * Y0 = Y0 + Y6. + * Y4 = Y4 + Y2. + * Y2 = Y4 - Y2. + * Y6 = Y0 - Y6. + * R3 is saved + * R6.l=Y3 + * note: R3: Y0, R2: Y4, R1: Y2, R0: Y6 + */ + R3=R3+R0, R0=R3-R0; + R2=R2+R1, R1=R2-R1 || [TMP0]=R3 || R6.L=W[I0--]; + /* + * Compute the odd portion (1,3,5,7) even is done. + * + * Y1 = C7 * Y1 - C1 * Y7 + C3 * Y5 - C5 * Y3. + * Y7 = C1 * Y1 + C7 * Y7 + C5 * Y5 + C3 * Y3. + * Y5 = C5 * Y1 + C3 * Y7 + C7 * Y5 - C1 * Y3. + * Y3 = C3 * Y1 - C5 * Y7 - C1 * Y5 - C7 * Y3. + */ + // R5=(Y1,Y7) R6=(Y5,Y3) // R7=(C1,C7) + A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || [TMP1]=R2 || R6.H=W[I2--]; + A1-=R7.H*R5.L, A0+=R7.L*R5.L (IS) || I0-=4 || R7=[I3++]; + A1+=R7.H*R6.H, A0+=R7.L*R6.H (IS) || I0+=M1; // R7=(C3,C5) + R3 =(A1-=R7.L*R6.L), R2 =(A0+=R7.H*R6.L) (IS); + A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || R4=[TMP0]; + A1+=R7.H*R5.L, A0-=R7.L*R5.L (IS) || I1+=M1 || R7=[I3++]; // R7=(C1,C7) + A1+=R7.L*R6.H, A0-=R7.H*R6.H (IS); + R7 =(A1-=R7.H*R6.L), R6 =(A0-=R7.L*R6.L) (IS) || I2+=M1; + // R3=Y1, R2=Y7, R7=Y5, R6=Y3 + + /* Transpose write column. */ + R5.H=R4+R2 (RND20); // Y0=Y0+Y7 + R5.L=R4-R2 (RND20) || R4 = [TMP1]; // Y7=Y7-Y0 + R5=R5>>>2(v); + R2.H=R1+R7 (RND20) || W[P0++P3]=R5.H; // Y2=Y2+Y5 st Y0 + R2.L=R1-R7 (RND20) || W[P1++P4]=R5.L || R7=[I3++]; // Y5=Y2-Y5 st Y7 + R2=R2>>>2(v); + R5.H=R0-R3 (RND20) || W[P0++P3]=R2.H || R1.L=W[I1++]; // Y1=Y6-Y1 st Y2 + R5.L=R0+R3 (RND20) || W[P1++P4]=R2.L || R0.H=W[I0++]; // Y6=Y6+Y1 st Y5 + R5=R5>>>2(v); + R3.H=R4-R6 (RND20) || W[P0++P3]=R5.H || R0.L=W[I2++]; // Y3=Y3-Y4 st Y1 + R3.L=R4+R6 (RND20) || W[P1++P4]=R5.L || R1.H=W[I0++]; // Y4=Y3+Y4 st Y6 + R3=R3>>>2(v); + /* pipeline loop start, + drain Y3, Y4 */ + A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || W[P0++P2]= R3.H || R1.H = W[I0--]; +.3: R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || W[P1++P5]= R3.L || R7 = [I3++]; + + L3 = 0; + (R7:4,P5:3)=[SP++]; + unlink; + RTS; +DEFUN_END(vp3_idct) + + diff --git a/contrib/ffmpeg/libavcodec/bitstream.c b/contrib/ffmpeg/libavcodec/bitstream.c index a0c239798..b74775e9c 100644 --- a/contrib/ffmpeg/libavcodec/bitstream.c +++ b/contrib/ffmpeg/libavcodec/bitstream.c @@ -3,6 +3,8 @@ * Copyright (c) 2000, 2001 Fabrice Bellard. * Copyright (c) 2002-2004 Michael Niedermayer * + * alternative bitstream reader & writer by Michael Niedermayer + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -18,8 +20,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * alternative bitstream reader & writer by Michael Niedermayer */ /** @@ -36,6 +36,8 @@ * @param[in] ptr The block of memory to reallocate. * @param[in] size The requested size. * @return Block of memory of requested size. + * @deprecated. Code which uses ff_realloc_static is broken/misdesigned + * and should correctly use static arrays */ attribute_deprecated void *ff_realloc_static(void *ptr, unsigned int size); @@ -48,7 +50,7 @@ void align_put_bits(PutBitContext *s) #endif } -void ff_put_string(PutBitContext * pbc, char *s, int put_zero) +void ff_put_string(PutBitContext * pbc, const char *s, int put_zero) { while(*s){ put_bits(pbc, 8, *s); @@ -58,6 +60,28 @@ void ff_put_string(PutBitContext * pbc, char *s, int put_zero) put_bits(pbc, 8, 0); } +void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length) +{ + const uint16_t *srcw= (const uint16_t*)src; + int words= length>>4; + int bits= length&15; + int i; + + if(length==0) return; + + if(ENABLE_SMALL || words < 16 || put_bits_count(pb)&7){ + for(i=0; i>(16-bits)); +} + /* VLC decoding */ //#define DEBUG_VLC @@ -102,16 +126,17 @@ static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, + const void *symbols, int symbols_wrap, int symbols_size, uint32_t code_prefix, int n_prefix, int flags) { - int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2; + int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2, symbol; uint32_t code; VLC_TYPE (*table)[2]; table_size = 1 << table_nb_bits; table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_STATIC); #ifdef DEBUG_VLC - printf("new table index=%d size=%d code_prefix=%x n=%d\n", + av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d code_prefix=%x n=%d\n", table_index, table_size, code_prefix, n_prefix); #endif if (table_index < 0) @@ -130,8 +155,12 @@ static int build_table(VLC *vlc, int table_nb_bits, /* we accept tables with holes */ if (n <= 0) continue; + if (!symbols) + symbol = i; + else + GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size); #if defined(DEBUG_VLC) && 0 - printf("i=%d n=%d code=0x%x\n", i, n, code); + av_log(NULL,AV_LOG_DEBUG,"i=%d n=%d code=0x%x\n", i, n, code); #endif /* if code matches the prefix, it is in the table */ n -= n_prefix; @@ -156,14 +185,14 @@ static int build_table(VLC *vlc, int table_nb_bits, return -1; } table[j][1] = n; //bits - table[j][0] = i; //code + table[j][0] = symbol; j++; } } else { n -= table_nb_bits; j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1); #ifdef DEBUG_VLC - printf("%4x: n=%d (subtable)\n", + av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n", j, n); #endif /* compute table size */ @@ -187,6 +216,7 @@ static int build_table(VLC *vlc, int table_nb_bits, index = build_table(vlc, n, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, + symbols, symbols_wrap, symbols_size, (flags & INIT_VLC_LE) ? (code_prefix | (i << n_prefix)) : ((code_prefix << table_nb_bits) | i), n_prefix + table_nb_bits, flags); if (index < 0) @@ -212,6 +242,8 @@ static int build_table(VLC *vlc, int table_nb_bits, 'codes' : table which gives the bit pattern of of each vlc code. + 'symbols' : table which gives the values to be returned from get_vlc(). + 'xxx_wrap' : give the number of bytes between each entry of the 'bits' or 'codes' tables. @@ -219,14 +251,15 @@ static int build_table(VLC *vlc, int table_nb_bits, or 'codes' tables. 'wrap' and 'size' allows to use any memory configuration and types - (byte/word/long) to store the 'bits' and 'codes' tables. + (byte/word/long) to store the 'bits', 'codes', and 'symbols' tables. 'use_static' should be set to 1 for tables, which should be freed with av_free_static(), 0 if free_vlc() will be used. */ -int init_vlc(VLC *vlc, int nb_bits, int nb_codes, +int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, + const void *symbols, int symbols_wrap, int symbols_size, int flags) { vlc->bits = nb_bits; @@ -242,14 +275,15 @@ int init_vlc(VLC *vlc, int nb_bits, int nb_codes, } #ifdef DEBUG_VLC - printf("build table nb_codes=%d\n", nb_codes); + av_log(NULL,AV_LOG_DEBUG,"build table nb_codes=%d\n", nb_codes); #endif if (build_table(vlc, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, + symbols, symbols_wrap, symbols_size, 0, 0, flags) < 0) { - av_free(vlc->table); + av_freep(&vlc->table); return -1; } return 0; @@ -258,6 +292,6 @@ int init_vlc(VLC *vlc, int nb_bits, int nb_codes, void free_vlc(VLC *vlc) { - av_free(vlc->table); + av_freep(&vlc->table); } diff --git a/contrib/ffmpeg/libavcodec/bitstream.h b/contrib/ffmpeg/libavcodec/bitstream.h index 18842702c..0a6f7de53 100644 --- a/contrib/ffmpeg/libavcodec/bitstream.h +++ b/contrib/ffmpeg/libavcodec/bitstream.h @@ -23,13 +23,19 @@ * bitstream api header. */ -#ifndef BITSTREAM_H -#define BITSTREAM_H - +#ifndef FFMPEG_BITSTREAM_H +#define FFMPEG_BITSTREAM_H + +#include +#include +#include +#include "common.h" +#include "bswap.h" +#include "intreadwrite.h" #include "log.h" #if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER) -#define ALT_BITSTREAM_READER +# define ALT_BITSTREAM_READER #endif //#define ALT_BITSTREAM_WRITER @@ -38,7 +44,7 @@ # ifdef ARCH_ARMV4L # define A32_BITSTREAM_READER # else -#define ALT_BITSTREAM_READER +# define ALT_BITSTREAM_READER //#define LIBMPEG2_BITSTREAM_READER //#define A32_BITSTREAM_READER # endif @@ -131,7 +137,8 @@ static inline void flush_put_bits(PutBitContext *s) } void align_put_bits(PutBitContext *s); -void ff_put_string(PutBitContext * pbc, char *s, int put_zero); +void ff_put_string(PutBitContext * pbc, const char *s, int put_zero); +void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length); /* bit input */ /* buffer, buffer_end and size_in_bits must be present and used by every reader */ @@ -166,11 +173,11 @@ typedef struct RL_VLC_ELEM { uint8_t run; } RL_VLC_ELEM; -#if defined(ARCH_SPARC) || defined(ARCH_ARMV4L) || defined(ARCH_MIPS) +#if defined(ARCH_SPARC) || defined(ARCH_ARMV4L) || defined(ARCH_MIPS) || defined(ARCH_BFIN) #define UNALIGNED_STORES_ARE_BAD #endif -/* used to avoid missaligned exceptions on some archs (alpha, ...) */ +/* used to avoid misaligned exceptions on some archs (alpha, ...) */ #if defined(ARCH_X86) # define unaligned16(a) (*(const uint16_t*)(a)) # define unaligned32(a) (*(const uint32_t*)(a)) @@ -335,8 +342,8 @@ static inline void skip_put_bytes(PutBitContext *s, int n){ } /** - * skips the given number of bits. - * must only be used if the actual values in the bitstream dont matter + * Skips the given number of bits. + * Must only be used if the actual values in the bitstream do not matter. */ static inline void skip_put_bits(PutBitContext *s, int n){ #ifdef ALT_BITSTREAM_WRITER @@ -400,26 +407,6 @@ LAST_SKIP_BITS(name, gb, num) for examples see get_bits, show_bits, skip_bits, get_vlc */ -static inline int unaligned32_be(const void *v) -{ -#ifdef CONFIG_ALIGN - const uint8_t *p=v; - return (((p[0]<<8) | p[1])<<16) | (p[2]<<8) | (p[3]); -#else - return be2me_32( unaligned32(v)); //original -#endif -} - -static inline int unaligned32_le(const void *v) -{ -#ifdef CONFIG_ALIGN - const uint8_t *p=v; - return (((p[3]<<8) | p[2])<<16) | (p[1]<<8) | (p[0]); -#else - return le2me_32( unaligned32(v)); //original -#endif -} - #ifdef ALT_BITSTREAM_READER # define MIN_CACHE_BITS 25 @@ -432,13 +419,13 @@ static inline int unaligned32_le(const void *v) # ifdef ALT_BITSTREAM_READER_LE # define UPDATE_CACHE(name, gb)\ - name##_cache= unaligned32_le( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\ + name##_cache= AV_RL32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\ # define SKIP_CACHE(name, gb, num)\ name##_cache >>= (num); # else # define UPDATE_CACHE(name, gb)\ - name##_cache= unaligned32_be( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\ + name##_cache= AV_RB32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\ # define SKIP_CACHE(name, gb, num)\ name##_cache <<= (num); @@ -799,9 +786,19 @@ static inline void align_get_bits(GetBitContext *s) if(n) skip_bits(s, n); } -int init_vlc(VLC *vlc, int nb_bits, int nb_codes, +#define init_vlc(vlc, nb_bits, nb_codes,\ + bits, bits_wrap, bits_size,\ + codes, codes_wrap, codes_size,\ + flags)\ + init_vlc_sparse(vlc, nb_bits, nb_codes,\ + bits, bits_wrap, bits_size,\ + codes, codes_wrap, codes_size,\ + NULL, 0, 0, flags) + +int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, + const void *symbols, int symbols_wrap, int symbols_size, int flags); #define INIT_VLC_USE_STATIC 1 #define INIT_VLC_LE 2 @@ -873,7 +870,7 @@ void free_vlc(VLC *vlc); * parses a vlc code, faster then get_vlc() * @param bits is the number of bits which will be read at once, must be * identical to nb_bits in init_vlc() - * @param max_depth is the number of times bits bits must be readed to completly + * @param max_depth is the number of times bits bits must be read to completely * read the longest vlc code * = (max_vlc_length + bits - 1) / bits */ @@ -953,4 +950,11 @@ static inline int decode012(GetBitContext *gb){ return get_bits1(gb) + 1; } -#endif /* BITSTREAM_H */ +static inline int decode210(GetBitContext *gb){ + if (get_bits1(gb)) + return 0; + else + return 2 - get_bits1(gb); +} + +#endif /* FFMPEG_BITSTREAM_H */ diff --git a/contrib/ffmpeg/libavcodec/bitstream_filter.c b/contrib/ffmpeg/libavcodec/bitstream_filter.c index 89fc4e175..aeafd7db4 100644 --- a/contrib/ffmpeg/libavcodec/bitstream_filter.c +++ b/contrib/ffmpeg/libavcodec/bitstream_filter.c @@ -19,10 +19,14 @@ */ #include "avcodec.h" -#include "mpegaudio.h" AVBitStreamFilter *first_bitstream_filter= NULL; +AVBitStreamFilter *av_bitstream_filter_next(AVBitStreamFilter *f){ + if(f) return f->next; + else return first_bitstream_filter; +} + void av_register_bitstream_filter(AVBitStreamFilter *bsf){ bsf->next = first_bitstream_filter; first_bitstream_filter= bsf; @@ -44,6 +48,8 @@ AVBitStreamFilterContext *av_bitstream_filter_init(const char *name){ } void av_bitstream_filter_close(AVBitStreamFilterContext *bsfc){ + if(bsfc->filter->close) + bsfc->filter->close(bsfc); av_freep(&bsfc->priv_data); av_parser_close(bsfc->parser); av_free(bsfc); @@ -57,228 +63,3 @@ int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc, *poutbuf_size= buf_size; return bsfc->filter->filter(bsfc, avctx, args, poutbuf, poutbuf_size, buf, buf_size, keyframe); } - -static int dump_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size, int keyframe){ - int cmd= args ? *args : 0; - /* cast to avoid warning about discarding qualifiers */ - if(avctx->extradata){ - if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER) && cmd=='a') - ||(keyframe && (cmd=='k' || !cmd)) - ||(cmd=='e') - /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/){ - int size= buf_size + avctx->extradata_size; - *poutbuf_size= size; - *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); - - memcpy(*poutbuf, avctx->extradata, avctx->extradata_size); - memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); - return 1; - } - } - return 0; -} - -static int remove_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size, int keyframe){ - int cmd= args ? *args : 0; - AVCodecParserContext *s; - - if(!bsfc->parser){ - bsfc->parser= av_parser_init(avctx->codec_id); - } - s= bsfc->parser; - - if(s && s->parser->split){ - if( (((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) || (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)) && cmd=='a') - ||(!keyframe && cmd=='k') - ||(cmd=='e' || !cmd) - ){ - int i= s->parser->split(avctx, buf, buf_size); - buf += i; - buf_size -= i; - } - } - *poutbuf= (uint8_t *) buf; - *poutbuf_size= buf_size; - - return 0; -} - -static int noise(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size, int keyframe){ - int amount= args ? atoi(args) : 10000; - unsigned int *state= bsfc->priv_data; - int i; - - *poutbuf= av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); - - memcpy(*poutbuf, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); - for(i=0; istrict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ - av_log(avctx, AV_LOG_ERROR, "not standards compliant\n"); - return -1; - } - - header = AV_RB32(buf); - mode_extension= (header>>4)&3; - - if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){ -output_unchanged: - *poutbuf= (uint8_t *) buf; - *poutbuf_size= buf_size; - - av_log(avctx, AV_LOG_INFO, "cannot compress %08X\n", header); - return 0; - } - - if(avctx->extradata_size == 0){ - avctx->extradata_size=15; - avctx->extradata= av_malloc(avctx->extradata_size); - strcpy(avctx->extradata, "FFCMP3 0.0"); - memcpy(avctx->extradata+11, buf, 4); - } - if(avctx->extradata_size != 15){ - av_log(avctx, AV_LOG_ERROR, "Extradata invalid\n"); - return -1; - } - extraheader = AV_RB32(avctx->extradata+11); - if((extraheader&MP3_MASK) != (header&MP3_MASK)) - goto output_unchanged; - - header_size= (header&0x10000) ? 4 : 6; - - *poutbuf_size= buf_size - header_size; - *poutbuf= av_malloc(buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE); - - if(avctx->channels==2){ - if((header & (3<<19)) != 3<<19){ - (*poutbuf)[1] &= 0x3F; - (*poutbuf)[1] |= mode_extension<<6; - FFSWAP(int, (*poutbuf)[1], (*poutbuf)[2]); - }else{ - (*poutbuf)[1] &= 0x8F; - (*poutbuf)[1] |= mode_extension<<4; - } - } - - return 1; -} - -static int mp3_header_decompress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size, int keyframe){ - uint32_t header; - int sample_rate= avctx->sample_rate; - int sample_rate_index=0; - int lsf, mpeg25, bitrate_index, frame_size; - - header = AV_RB32(buf); - if(ff_mpa_check_header(header) >= 0){ - *poutbuf= (uint8_t *) buf; - *poutbuf_size= buf_size; - - return 0; - } - - if(avctx->extradata_size != 15 || strcmp(avctx->extradata, "FFCMP3 0.0")){ - av_log(avctx, AV_LOG_ERROR, "Extradata invalid %d\n", avctx->extradata_size); - return -1; - } - - header= AV_RB32(avctx->extradata+11) & MP3_MASK; - - lsf = sample_rate < (24000+32000)/2; - mpeg25 = sample_rate < (12000+16000)/2; - sample_rate_index= (header>>10)&3; - sample_rate= mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); //in case sample rate is a little off - - for(bitrate_index=2; bitrate_index<30; bitrate_index++){ - frame_size = mpa_bitrate_tab[lsf][2][bitrate_index>>1]; - frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1); - if(frame_size == buf_size + 4) - break; - if(frame_size == buf_size + 6) - break; - } - if(bitrate_index == 30){ - av_log(avctx, AV_LOG_ERROR, "couldnt find bitrate_index\n"); - return -1; - } - - header |= (bitrate_index&1)<<9; - header |= (bitrate_index>>1)<<12; - header |= (frame_size == buf_size + 4)<<16; //FIXME actually set a correct crc instead of 0 - - *poutbuf_size= frame_size; - *poutbuf= av_malloc(frame_size + FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(*poutbuf + frame_size - buf_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); - - if(avctx->channels==2){ - uint8_t *p= *poutbuf + frame_size - buf_size; - if(lsf){ - FFSWAP(int, p[1], p[2]); - header |= (p[1] & 0xC0)>>2; - p[1] &= 0x3F; - }else{ - header |= p[1] & 0x30; - p[1] &= 0xCF; - } - } - - (*poutbuf)[0]= header>>24; - (*poutbuf)[1]= header>>16; - (*poutbuf)[2]= header>> 8; - (*poutbuf)[3]= header ; - - return 1; -} - -AVBitStreamFilter dump_extradata_bsf={ - "dump_extra", - 0, - dump_extradata, -}; - -AVBitStreamFilter remove_extradata_bsf={ - "remove_extra", - 0, - remove_extradata, -}; - -AVBitStreamFilter noise_bsf={ - "noise", - sizeof(int), - noise, -}; - -AVBitStreamFilter mp3_header_compress_bsf={ - "mp3comp", - 0, - mp3_header_compress, -}; - -AVBitStreamFilter mp3_header_decompress_bsf={ - "mp3decomp", - 0, - mp3_header_decompress, -}; diff --git a/contrib/ffmpeg/libavcodec/bmp.c b/contrib/ffmpeg/libavcodec/bmp.c index d1cfdce6d..35d20e6cc 100644 --- a/contrib/ffmpeg/libavcodec/bmp.c +++ b/contrib/ffmpeg/libavcodec/bmp.c @@ -34,7 +34,7 @@ static int bmp_decode_init(AVCodecContext *avctx){ static int bmp_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { BMPContext *s = avctx->priv_data; AVFrame *picture = data; @@ -48,7 +48,7 @@ static int bmp_decode_frame(AVCodecContext *avctx, uint32_t rgb[3]; uint8_t *ptr; int dsize; - uint8_t *buf0 = buf; + const uint8_t *buf0 = buf; if(buf_size < 14){ av_log(avctx, AV_LOG_ERROR, "buf size too small (%d)\n", buf_size); @@ -111,7 +111,6 @@ static int bmp_decode_frame(AVCodecContext *avctx, rgb[2] = bytestream_get_le32(&buf); } - avctx->codec_id = CODEC_ID_BMP; avctx->width = width; avctx->height = height > 0? height: -height; @@ -194,7 +193,7 @@ static int bmp_decode_frame(AVCodecContext *avctx, break; case 16: for(i = 0; i < avctx->height; i++){ - uint16_t *src = (uint16_t *) buf; + const uint16_t *src = (const uint16_t *) buf; uint16_t *dst = (uint16_t *) ptr; for(j = 0; j < avctx->width; j++) @@ -206,7 +205,7 @@ static int bmp_decode_frame(AVCodecContext *avctx, break; case 32: for(i = 0; i < avctx->height; i++){ - uint8_t *src = buf; + const uint8_t *src = buf; uint8_t *dst = ptr; for(j = 0; j < avctx->width; j++){ diff --git a/contrib/ffmpeg/libavcodec/bmp.h b/contrib/ffmpeg/libavcodec/bmp.h index cf6ace845..cbbd21ce9 100644 --- a/contrib/ffmpeg/libavcodec/bmp.h +++ b/contrib/ffmpeg/libavcodec/bmp.h @@ -19,6 +19,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef FFMPEG_BMP_H +#define FFMPEG_BMP_H + +#include "avcodec.h" + typedef struct BMPContext { AVFrame picture; } BMPContext; @@ -29,3 +34,5 @@ typedef enum { BMP_RLE4 =2, BMP_BITFIELDS =3, } BiCompression; + +#endif /* FFMPEG_BMP_H */ diff --git a/contrib/ffmpeg/libavcodec/bytestream.h b/contrib/ffmpeg/libavcodec/bytestream.h index d1e9f82ed..3a94e719c 100644 --- a/contrib/ffmpeg/libavcodec/bytestream.h +++ b/contrib/ffmpeg/libavcodec/bytestream.h @@ -22,27 +22,38 @@ #ifndef FFMPEG_BYTESTREAM_H #define FFMPEG_BYTESTREAM_H -#define DEF(name, bytes, read, write)\ -static av_always_inline unsigned int bytestream_get_ ## name(uint8_t **b){\ +#include "common.h" + +#define DEF_T(type, name, bytes, read, write) \ +static av_always_inline type bytestream_get_ ## name(const uint8_t **b){\ (*b) += bytes;\ return read(*b - bytes);\ }\ -static av_always_inline void bytestream_put_ ##name(uint8_t **b, const unsigned int value){\ +static av_always_inline void bytestream_put_ ##name(uint8_t **b, const type value){\ write(*b, value);\ (*b) += bytes;\ -}; +} + +#define DEF(name, bytes, read, write) \ + DEF_T(unsigned int, name, bytes, read, write) +#define DEF64(name, bytes, read, write) \ + DEF_T(uint64_t, name, bytes, read, write) -DEF(le32, 4, AV_RL32, AV_WL32) -DEF(le24, 3, AV_RL24, AV_WL24) -DEF(le16, 2, AV_RL16, AV_WL16) -DEF(be32, 4, AV_RB32, AV_WB32) -DEF(be24, 3, AV_RB24, AV_WB24) -DEF(be16, 2, AV_RB16, AV_WB16) -DEF(byte, 1, AV_RB8 , AV_WB8 ) +DEF64(le64, 8, AV_RL64, AV_WL64) +DEF (le32, 4, AV_RL32, AV_WL32) +DEF (le24, 3, AV_RL24, AV_WL24) +DEF (le16, 2, AV_RL16, AV_WL16) +DEF64(be64, 8, AV_RB64, AV_WB64) +DEF (be32, 4, AV_RB32, AV_WB32) +DEF (be24, 3, AV_RB24, AV_WB24) +DEF (be16, 2, AV_RB16, AV_WB16) +DEF (byte, 1, AV_RB8 , AV_WB8 ) #undef DEF +#undef DEF64 +#undef DEF_T -static av_always_inline unsigned int bytestream_get_buffer(uint8_t **b, uint8_t *dst, unsigned int size) +static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size) { memcpy(dst, *b, size); (*b) += size; diff --git a/contrib/ffmpeg/libavcodec/c93.c b/contrib/ffmpeg/libavcodec/c93.c new file mode 100644 index 000000000..2b5d3900c --- /dev/null +++ b/contrib/ffmpeg/libavcodec/c93.c @@ -0,0 +1,253 @@ +/* + * Interplay C93 video decoder + * Copyright (c) 2007 Anssi Hannula + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "bytestream.h" + +typedef struct { + AVFrame pictures[2]; + int currentpic; +} C93DecoderContext; + +typedef enum { + C93_8X8_FROM_PREV = 0x02, + C93_4X4_FROM_PREV = 0x06, + C93_4X4_FROM_CURR = 0x07, + C93_8X8_2COLOR = 0x08, + C93_4X4_2COLOR = 0x0A, + C93_4X4_4COLOR_GRP = 0x0B, + C93_4X4_4COLOR = 0x0D, + C93_NOOP = 0x0E, + C93_8X8_INTRA = 0x0F, +} C93BlockType; + +#define WIDTH 320 +#define HEIGHT 192 + +#define C93_HAS_PALETTE 0x01 +#define C93_FIRST_FRAME 0x02 + +static int decode_init(AVCodecContext *avctx) +{ + avctx->pix_fmt = PIX_FMT_PAL8; + return 0; +} + +static int decode_end(AVCodecContext *avctx) +{ + C93DecoderContext * const c93 = avctx->priv_data; + + if (c93->pictures[0].data[0]) + avctx->release_buffer(avctx, &c93->pictures[0]); + if (c93->pictures[1].data[0]) + avctx->release_buffer(avctx, &c93->pictures[1]); + return 0; +} + +static inline int copy_block(AVCodecContext *avctx, uint8_t *to, + uint8_t *from, int offset, int height, int stride) +{ + int i; + int width = height; + int from_x = offset % WIDTH; + int from_y = offset / WIDTH; + int overflow = from_x + width - WIDTH; + + if (!from) { + /* silently ignoring predictive blocks in first frame */ + return 0; + } + + if (from_y + height > HEIGHT) { + av_log(avctx, AV_LOG_ERROR, "invalid offset %d during C93 decoding\n", + offset); + return -1; + } + + if (overflow > 0) { + width -= overflow; + for (i = 0; i < height; i++) { + memcpy(&to[i*stride+width], &from[(from_y+i)*stride], overflow); + } + } + + for (i = 0; i < height; i++) { + memcpy(&to[i*stride], &from[(from_y+i)*stride+from_x], width); + } + + return 0; +} + +static inline void draw_n_color(uint8_t *out, int stride, int width, + int height, int bpp, uint8_t cols[4], uint8_t grps[4], uint32_t col) +{ + int x, y; + for (y = 0; y < height; y++) { + if (grps) + cols[0] = grps[3 * (y >> 1)]; + for (x = 0; x < width; x++) { + if (grps) + cols[1]= grps[(x >> 1) + 1]; + out[x + y*stride] = cols[col & ((1 << bpp) - 1)]; + col >>= bpp; + } + } +} + +static int decode_frame(AVCodecContext *avctx, void *data, + int *data_size, const uint8_t * buf, int buf_size) +{ + C93DecoderContext * const c93 = avctx->priv_data; + AVFrame * const newpic = &c93->pictures[c93->currentpic]; + AVFrame * const oldpic = &c93->pictures[c93->currentpic^1]; + AVFrame *picture = data; + uint8_t *out; + int stride, i, x, y, bt = 0; + + c93->currentpic ^= 1; + + newpic->reference = 1; + newpic->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | + FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE; + if (avctx->reget_buffer(avctx, newpic)) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return -1; + } + + stride = newpic->linesize[0]; + + if (buf[0] & C93_FIRST_FRAME) { + newpic->pict_type = FF_I_TYPE; + newpic->key_frame = 1; + } else { + newpic->pict_type = FF_P_TYPE; + newpic->key_frame = 0; + } + + if (*buf++ & C93_HAS_PALETTE) { + uint32_t *palette = (uint32_t *) newpic->data[1]; + const uint8_t *palbuf = buf + buf_size - 768 - 1; + for (i = 0; i < 256; i++) { + palette[i] = bytestream_get_be24(&palbuf); + } + } else { + if (oldpic->data[1]) + memcpy(newpic->data[1], oldpic->data[1], 256 * 4); + } + + for (y = 0; y < HEIGHT; y += 8) { + out = newpic->data[0] + y * stride; + for (x = 0; x < WIDTH; x += 8) { + uint8_t *copy_from = oldpic->data[0]; + unsigned int offset, j; + uint8_t cols[4], grps[4]; + C93BlockType block_type; + + if (!bt) + bt = *buf++; + + block_type= bt & 0x0F; + switch (block_type) { + case C93_8X8_FROM_PREV: + offset = bytestream_get_le16(&buf); + if (copy_block(avctx, out, copy_from, offset, 8, stride)) + return -1; + break; + + case C93_4X4_FROM_CURR: + copy_from = newpic->data[0]; + case C93_4X4_FROM_PREV: + for (j = 0; j < 8; j += 4) { + for (i = 0; i < 8; i += 4) { + offset = bytestream_get_le16(&buf); + if (copy_block(avctx, &out[j*stride+i], + copy_from, offset, 4, stride)) + return -1; + } + } + break; + + case C93_8X8_2COLOR: + bytestream_get_buffer(&buf, cols, 2); + for (i = 0; i < 8; i++) { + draw_n_color(out + i*stride, stride, 8, 1, 1, cols, + NULL, *buf++); + } + + break; + + case C93_4X4_2COLOR: + case C93_4X4_4COLOR: + case C93_4X4_4COLOR_GRP: + for (j = 0; j < 8; j += 4) { + for (i = 0; i < 8; i += 4) { + if (block_type == C93_4X4_2COLOR) { + bytestream_get_buffer(&buf, cols, 2); + draw_n_color(out + i + j*stride, stride, 4, 4, + 1, cols, NULL, bytestream_get_le16(&buf)); + } else if (block_type == C93_4X4_4COLOR) { + bytestream_get_buffer(&buf, cols, 4); + draw_n_color(out + i + j*stride, stride, 4, 4, + 2, cols, NULL, bytestream_get_le32(&buf)); + } else { + bytestream_get_buffer(&buf, grps, 4); + draw_n_color(out + i + j*stride, stride, 4, 4, + 1, cols, grps, bytestream_get_le16(&buf)); + } + } + } + break; + + case C93_NOOP: + break; + + case C93_8X8_INTRA: + for (j = 0; j < 8; j++) + bytestream_get_buffer(&buf, out + j*stride, 8); + break; + + default: + av_log(avctx, AV_LOG_ERROR, "unexpected type %x at %dx%d\n", + block_type, x, y); + return -1; + } + bt >>= 4; + out += 8; + } + } + + *picture = *newpic; + *data_size = sizeof(AVFrame); + + return buf_size; +} + +AVCodec c93_decoder = { + "c93", + CODEC_TYPE_VIDEO, + CODEC_ID_C93, + sizeof(C93DecoderContext), + decode_init, + NULL, + decode_end, + decode_frame, + CODEC_CAP_DR1, +}; diff --git a/contrib/ffmpeg/libavcodec/cabac.c b/contrib/ffmpeg/libavcodec/cabac.c index c6da6292a..fc17bb6ac 100644 --- a/contrib/ffmpeg/libavcodec/cabac.c +++ b/contrib/ffmpeg/libavcodec/cabac.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -179,12 +178,14 @@ void ff_init_cabac_states(CABACContext *c){ } } -#if 0 //selftest +#ifdef TEST +#undef random #define SIZE 10240 #include "avcodec.h" +#include "cabac.h" -int main(){ +int main(void){ CABACContext c; uint8_t b[9*SIZE]; uint8_t r[9*SIZE]; @@ -192,7 +193,7 @@ int main(){ uint8_t state[10]= {0}; ff_init_cabac_encoder(&c, b, SIZE); - ff_init_cabac_states(&c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64); + ff_init_cabac_states(&c); for(i=0; i @@ -87,6 +90,7 @@ static inline void renorm_cabac_encoder(CABACContext *c){ } } +#ifdef TEST static void put_cabac(CABACContext *c, uint8_t * const state, int bit){ int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + *state]; @@ -256,6 +260,7 @@ static void put_cabac_ueg(CABACContext *c, uint8_t * state, int v, int max, int put_cabac_bypass(c, sign); } } +#endif /* TEST */ static void refill(CABACContext *c){ #if CABAC_BITS == 16 @@ -267,6 +272,7 @@ static void refill(CABACContext *c){ c->bytestream+= CABAC_BITS/8; } +#if ! ( defined(ARCH_X86) && defined(HAVE_7REGS) && defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS) ) static void refill2(CABACContext *c){ int i, x; @@ -284,6 +290,7 @@ static void refill2(CABACContext *c){ c->low += x<bytestream+= CABAC_BITS/8; } +#endif static inline void renorm_cabac_decoder(CABACContext *c){ while(c->range < 0x100){ @@ -320,7 +327,7 @@ static inline void renorm_cabac_decoder_once(CABACContext *c){ //P3:665 athlon:517 asm( "lea -0x100(%0), %%eax \n\t" - "cdq \n\t" + "cltd \n\t" "mov %0, %%eax \n\t" "and %%edx, %0 \n\t" "and %1, %%edx \n\t" @@ -363,7 +370,7 @@ static inline void renorm_cabac_decoder_once(CABACContext *c){ refill(c); } -static int av_always_inline get_cabac_inline(CABACContext *c, uint8_t * const state){ +static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const state){ //FIXME gcc generates duplicate load/stores for c->low and c->range #define LOW "0" #define RANGE "4" @@ -376,7 +383,7 @@ static int av_always_inline get_cabac_inline(CABACContext *c, uint8_t * const st #define BYTE "16" #define BYTEEND "20" #endif -#if defined(ARCH_X86) && defined(CONFIG_7REGS) && defined(CONFIG_EBX_AVAILABLE) && !( defined(ARCH_X86_64) && defined(PIC) ) +#if defined(ARCH_X86) && defined(HAVE_7REGS) && defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS) int bit; #ifndef BRANCHLESS_CABAC_DECODER @@ -454,7 +461,7 @@ static int av_always_inline get_cabac_inline(CABACContext *c, uint8_t * const st "2: \n\t" "movl %%edx, "RANGE "(%2) \n\t" "movl %%ebx, "LOW "(%2) \n\t" - :"=&a"(bit) //FIXME this is fragile gcc either runs out of registers or misscompiles it (for example if "+a"(bit) or "+m"(*state) is used + :"=&a"(bit) //FIXME this is fragile gcc either runs out of registers or miscompiles it (for example if "+a"(bit) or "+m"(*state) is used :"r"(state), "r"(c) : "%"REG_c, "%ebx", "%edx", "%"REG_S, "memory" ); @@ -532,10 +539,10 @@ static int av_always_inline get_cabac_inline(CABACContext *c, uint8_t * const st ); bit&=1; #endif /* BRANCHLESS_CABAC_DECODER */ -#else /* defined(ARCH_X86) && !(defined(PIC) && defined(__GNUC__)) */ +#else /* defined(ARCH_X86) && defined(HAVE_7REGS) && defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS) */ int s = *state; int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + s]; - int bit, lps_mask attribute_unused; + int bit, lps_mask av_unused; c->range -= RangeLPS; #ifndef BRANCHLESS_CABAC_DECODER @@ -571,7 +578,7 @@ static int av_always_inline get_cabac_inline(CABACContext *c, uint8_t * const st if(!(c->low & CABAC_MASK)) refill2(c); #endif /* BRANCHLESS_CABAC_DECODER */ -#endif /* defined(ARCH_X86) && !(defined(PIC) && defined(__GNUC__)) */ +#endif /* defined(ARCH_X86) && defined(HAVE_7REGS) && defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS) */ return bit; } @@ -592,7 +599,7 @@ static int get_cabac_bypass(CABACContext *c){ "shl $17, %%ebx \n\t" "add %%eax, %%eax \n\t" "sub %%ebx, %%eax \n\t" - "cdq \n\t" + "cltd \n\t" "and %%edx, %%ebx \n\t" "add %%ebx, %%eax \n\t" "test %%ax, %%ax \n\t" @@ -639,7 +646,7 @@ static av_always_inline int get_cabac_bypass_sign(CABACContext *c, int val){ "shl $17, %%ebx \n\t" "add %%eax, %%eax \n\t" "sub %%ebx, %%eax \n\t" - "cdq \n\t" + "cltd \n\t" "and %%edx, %%ebx \n\t" "add %%ebx, %%eax \n\t" "xor %%edx, %%ecx \n\t" @@ -679,8 +686,8 @@ static av_always_inline int get_cabac_bypass_sign(CABACContext *c, int val){ } //FIXME the x86 code from this file should be moved into i386/h264 or cabac something.c/h (note ill kill you if you move my code away from under my fingers before iam finished with it!) -//FIXME use some macros to avoid duplicatin get_cabac (cant be done yet as that would make optimization work hard) -#if defined(ARCH_X86) && defined(CONFIG_7REGS) && defined(CONFIG_EBX_AVAILABLE) && !( defined(ARCH_X86_64) && defined(PIC) ) +//FIXME use some macros to avoid duplicatin get_cabac (cannot be done yet as that would make optimization work hard) +#if defined(ARCH_X86) && defined(HAVE_7REGS) && defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS) static int decode_significance_x86(CABACContext *c, int max_coeff, uint8_t *significant_coeff_ctx_base, int *index){ void *end= significant_coeff_ctx_base + max_coeff - 1; int minusstart= -(int)significant_coeff_ctx_base; @@ -731,7 +738,7 @@ static int decode_significance_x86(CABACContext *c, int max_coeff, uint8_t *sign return coeff_count; } -static int decode_significance_8x8_x86(CABACContext *c, uint8_t *significant_coeff_ctx_base, int *index, uint8_t *sig_off){ +static int decode_significance_8x8_x86(CABACContext *c, uint8_t *significant_coeff_ctx_base, int *index, const uint8_t *sig_off){ int minusindex= 4-(int)index; int coeff_count; long last=0; @@ -786,7 +793,7 @@ static int decode_significance_8x8_x86(CABACContext *c, uint8_t *significant_coe ); return coeff_count; } -#endif /* defined(ARCH_X86) && !(defined(PIC) && defined(__GNUC__)) */ +#endif /* defined(ARCH_X86) && && defined(HAVE_7REGS) && defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS) */ /** * @@ -802,8 +809,9 @@ static int get_cabac_terminate(CABACContext *c){ } } +#if 0 /** - * get (truncated) unnary binarization. + * Get (truncated) unary binarization. */ static int get_cabac_u(CABACContext *c, uint8_t * state, int max, int max_index, int truncated){ int i; @@ -857,3 +865,6 @@ static int get_cabac_ueg(CABACContext *c, uint8_t * state, int max, int is_signe }else return i; } +#endif /* 0 */ + +#endif /* FFMPEG_CABAC_H */ diff --git a/contrib/ffmpeg/libavcodec/cavs.c b/contrib/ffmpeg/libavcodec/cavs.c index 4672635d7..2867c0679 100644 --- a/contrib/ffmpeg/libavcodec/cavs.c +++ b/contrib/ffmpeg/libavcodec/cavs.c @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** @@ -28,82 +28,9 @@ #include "avcodec.h" #include "bitstream.h" #include "golomb.h" -#include "mpegvideo.h" +#include "cavs.h" #include "cavsdata.h" -#ifdef CONFIG_CAVS_DECODER -typedef struct { - MpegEncContext s; - Picture picture; ///< currently decoded frame - Picture DPB[2]; ///< reference frames - int dist[2]; ///< temporal distances from current frame to ref frames - int profile, level; - int aspect_ratio; - int mb_width, mb_height; - int pic_type; - int progressive; - int pic_structure; - int skip_mode_flag; ///< select between skip_count or one skip_flag per MB - int loop_filter_disable; - int alpha_offset, beta_offset; - int ref_flag; - int mbx, mby; ///< macroblock coordinates - int flags; ///< availability flags of neighbouring macroblocks - int stc; ///< last start code - uint8_t *cy, *cu, *cv; ///< current MB sample pointers - int left_qp; - uint8_t *top_qp; - - /** mv motion vector cache - 0: D3 B2 B3 C2 - 4: A1 X0 X1 - - 8: A3 X2 X3 - - - X are the vectors in the current macroblock (5,6,9,10) - A is the macroblock to the left (4,8) - B is the macroblock to the top (1,2) - C is the macroblock to the top-right (3) - D is the macroblock to the top-left (0) - - the same is repeated for backward motion vectors */ - vector_t mv[2*4*3]; - vector_t *top_mv[2]; - vector_t *col_mv; - - /** luma pred mode cache - 0: -- B2 B3 - 3: A1 X0 X1 - 6: A3 X2 X3 */ - int pred_mode_Y[3*3]; - int *top_pred_Y; - int l_stride, c_stride; - int luma_scan[4]; - int qp; - int qp_fixed; - int cbp; - ScanTable scantable; - - /** intra prediction is done with un-deblocked samples - they are saved here before deblocking the MB */ - uint8_t *top_border_y, *top_border_u, *top_border_v; - uint8_t left_border_y[26], left_border_u[10], left_border_v[10]; - uint8_t intern_border_y[26]; - uint8_t topleft_border_y, topleft_border_u, topleft_border_v; - - void (*intra_pred_l[8])(uint8_t *d,uint8_t *top,uint8_t *left,int stride); - void (*intra_pred_c[7])(uint8_t *d,uint8_t *top,uint8_t *left,int stride); - uint8_t *col_type_base; - uint8_t *col_type; - - /* scaling factors for MV prediction */ - int sym_factor; ///< for scaling in symmetrical B block - int direct_den[2]; ///< for scaling in direct B block - int scale_den[2]; ///< for scaling neighbouring MVs - - int got_keyframe; - DCTELEM *block; -} AVSContext; - /***************************************************************************** * * in-loop deblocking filter @@ -144,7 +71,7 @@ static inline int get_bs(vector_t *mvP, vector_t *mvQ, int b) { * --------- * */ -static void filter_mb(AVSContext *h, enum mb_t mb_type) { +void ff_cavs_filter(AVSContext *h, enum mb_t mb_type) { DECLARE_ALIGNED_8(uint8_t, bs[8]); int qp_avg, alpha, beta, tc; int i; @@ -168,11 +95,11 @@ static void filter_mb(AVSContext *h, enum mb_t mb_type) { *((uint64_t *)bs) = 0x0202020202020202ULL; else{ *((uint64_t *)bs) = 0; - if(partition_flags[mb_type] & SPLITV){ + if(ff_cavs_partition_flags[mb_type] & SPLITV){ bs[2] = get_bs(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X1], mb_type > P_8X8); bs[3] = get_bs(&h->mv[MV_FWD_X2], &h->mv[MV_FWD_X3], mb_type > P_8X8); } - if(partition_flags[mb_type] & SPLITH){ + if(ff_cavs_partition_flags[mb_type] & SPLITH){ bs[6] = get_bs(&h->mv[MV_FWD_X0], &h->mv[MV_FWD_X2], mb_type > P_8X8); bs[7] = get_bs(&h->mv[MV_FWD_X1], &h->mv[MV_FWD_X3], mb_type > P_8X8); } @@ -216,7 +143,7 @@ static void filter_mb(AVSContext *h, enum mb_t mb_type) { * ****************************************************************************/ -static inline void load_intra_pred_luma(AVSContext *h, uint8_t *top, +void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top, uint8_t **left, int block) { int i; @@ -266,9 +193,26 @@ static inline void load_intra_pred_luma(AVSContext *h, uint8_t *top, } } +void ff_cavs_load_intra_pred_chroma(AVSContext *h) { + /* extend borders by one pixel */ + h->left_border_u[9] = h->left_border_u[8]; + h->left_border_v[9] = h->left_border_v[8]; + h->top_border_u[h->mbx*10+9] = h->top_border_u[h->mbx*10+8]; + h->top_border_v[h->mbx*10+9] = h->top_border_v[h->mbx*10+8]; + if(h->mbx && h->mby) { + h->top_border_u[h->mbx*10] = h->left_border_u[0] = h->topleft_border_u; + h->top_border_v[h->mbx*10] = h->left_border_v[0] = h->topleft_border_v; + } else { + h->left_border_u[0] = h->left_border_u[1]; + h->left_border_v[0] = h->left_border_v[1]; + h->top_border_u[h->mbx*10] = h->top_border_u[h->mbx*10+1]; + h->top_border_v[h->mbx*10] = h->top_border_v[h->mbx*10+1]; + } +} + static void intra_pred_vert(uint8_t *d,uint8_t *top,uint8_t *left,int stride) { int y; - uint64_t a = unaligned64(&top[1]); + uint64_t a = AV_RN64(&top[1]); for(y=0;y<8;y++) { *((uint64_t *)(d+y*stride)) = a; } @@ -353,11 +297,23 @@ static void intra_pred_lp_top(uint8_t *d,uint8_t *top,uint8_t *left,int stride) #undef LOWPASS -static inline void modify_pred(const int_fast8_t *mod_table, int *mode) { - *mode = mod_table[*mode]; - if(*mode < 0) { - av_log(NULL, AV_LOG_ERROR, "Illegal intra prediction mode\n"); - *mode = 0; +void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv) { + /* save pred modes before they get modified */ + h->pred_mode_Y[3] = h->pred_mode_Y[5]; + h->pred_mode_Y[6] = h->pred_mode_Y[8]; + h->top_pred_Y[h->mbx*2+0] = h->pred_mode_Y[7]; + h->top_pred_Y[h->mbx*2+1] = h->pred_mode_Y[8]; + + /* modify pred modes according to availability of neighbour samples */ + if(!(h->flags & A_AVAIL)) { + modify_pred(ff_left_modifier_l, &h->pred_mode_Y[4] ); + modify_pred(ff_left_modifier_l, &h->pred_mode_Y[7] ); + modify_pred(ff_left_modifier_c, pred_mode_uv ); + } + if(!(h->flags & B_AVAIL)) { + modify_pred(ff_top_modifier_l, &h->pred_mode_Y[4] ); + modify_pred(ff_top_modifier_l, &h->pred_mode_Y[5] ); + modify_pred(ff_top_modifier_c, pred_mode_uv ); } } @@ -454,8 +410,8 @@ static inline void mc_part_std(AVSContext *h,int square,int chroma_height,int de } } -static void inter_pred(AVSContext *h, enum mb_t mb_type) { - if(partition_flags[mb_type] == 0){ // 16x16 +void ff_cavs_inter(AVSContext *h, enum mb_t mb_type) { + if(ff_cavs_partition_flags[mb_type] == 0){ // 16x16 mc_part_std(h, 1, 8, 0, h->cy, h->cu, h->cv, 0, 0, h->s.dsp.put_cavs_qpel_pixels_tab[0], h->s.dsp.put_h264_chroma_pixels_tab[0], @@ -483,9 +439,6 @@ static void inter_pred(AVSContext *h, enum mb_t mb_type) { h->s.dsp.avg_cavs_qpel_pixels_tab[1], h->s.dsp.avg_h264_chroma_pixels_tab[1],&h->mv[MV_FWD_X3]); } - /* set intra prediction modes to default values */ - h->pred_mode_Y[3] = h->pred_mode_Y[6] = INTRA_L_LP; - h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = INTRA_L_LP; } /***************************************************************************** @@ -494,27 +447,6 @@ static void inter_pred(AVSContext *h, enum mb_t mb_type) { * ****************************************************************************/ -static inline void set_mvs(vector_t *mv, enum block_t size) { - switch(size) { - case BLK_16X16: - mv[MV_STRIDE ] = mv[0]; - mv[MV_STRIDE+1] = mv[0]; - case BLK_16X8: - mv[1] = mv[0]; - break; - case BLK_8X16: - mv[MV_STRIDE] = mv[0]; - break; - } -} - -static inline void store_mvs(AVSContext *h) { - h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 0] = h->mv[MV_FWD_X0]; - h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 1] = h->mv[MV_FWD_X1]; - h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 2] = h->mv[MV_FWD_X2]; - h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 3] = h->mv[MV_FWD_X3]; -} - static inline void scale_mv(AVSContext *h, int *d_x, int *d_y, vector_t *src, int distp) { int den = h->scale_den[src->ref]; @@ -547,37 +479,8 @@ static inline void mv_pred_median(AVSContext *h, vector_t *mvP, vector_t *mvA, v } } -static inline void mv_pred_direct(AVSContext *h, vector_t *pmv_fw, - vector_t *col_mv) { - vector_t *pmv_bw = pmv_fw + MV_BWD_OFFS; - int den = h->direct_den[col_mv->ref]; - int m = col_mv->x >> 31; - - pmv_fw->dist = h->dist[1]; - pmv_bw->dist = h->dist[0]; - pmv_fw->ref = 1; - pmv_bw->ref = 0; - /* scale the co-located motion vector according to its temporal span */ - pmv_fw->x = (((den+(den*col_mv->x*pmv_fw->dist^m)-m-1)>>14)^m)-m; - pmv_bw->x = m-(((den+(den*col_mv->x*pmv_bw->dist^m)-m-1)>>14)^m); - m = col_mv->y >> 31; - pmv_fw->y = (((den+(den*col_mv->y*pmv_fw->dist^m)-m-1)>>14)^m)-m; - pmv_bw->y = m-(((den+(den*col_mv->y*pmv_bw->dist^m)-m-1)>>14)^m); -} - -static inline void mv_pred_sym(AVSContext *h, vector_t *src, enum block_t size) { - vector_t *dst = src + MV_BWD_OFFS; - - /* backward mv is the scaled and negated forward mv */ - dst->x = -((src->x * h->sym_factor + 256) >> 9); - dst->y = -((src->y * h->sym_factor + 256) >> 9); - dst->ref = 0; - dst->dist = h->dist[0]; - set_mvs(dst, size); -} - -static void mv_pred(AVSContext *h, enum mv_loc_t nP, enum mv_loc_t nC, - enum mv_pred_t mode, enum block_t size, int ref) { +void ff_cavs_mv(AVSContext *h, enum mv_loc_t nP, enum mv_loc_t nC, + enum mv_pred_t mode, enum block_t size, int ref) { vector_t *mvP = &h->mv[nP]; vector_t *mvA = &h->mv[nP-1]; vector_t *mvB = &h->mv[nP-4]; @@ -592,7 +495,7 @@ static void mv_pred(AVSContext *h, enum mv_loc_t nP, enum mv_loc_t nC, ((mvA->ref == NOT_AVAIL) || (mvB->ref == NOT_AVAIL) || ((mvA->x | mvA->y | mvA->ref) == 0) || ((mvB->x | mvB->y | mvB->ref) == 0) )) { - mvP2 = &un_mv; + mvP2 = &ff_cavs_un_mv; /* if there is only one suitable candidate, take it */ } else if((mvA->ref >= 0) && (mvB->ref < 0) && (mvC->ref < 0)) { mvP2= mvA; @@ -620,111 +523,6 @@ static void mv_pred(AVSContext *h, enum mv_loc_t nP, enum mv_loc_t nC, set_mvs(mvP,size); } -/***************************************************************************** - * - * residual data decoding - * - ****************************************************************************/ - -/** kth-order exponential golomb code */ -static inline int get_ue_code(GetBitContext *gb, int order) { - if(order) { - int ret = get_ue_golomb(gb) << order; - return ret + get_bits(gb,order); - } - return get_ue_golomb(gb); -} - -/** - * decode coefficients from one 8x8 block, dequantize, inverse transform - * and add them to sample block - * @param r pointer to 2D VLC table - * @param esc_golomb_order escape codes are k-golomb with this order k - * @param qp quantizer - * @param dst location of sample block - * @param stride line stride in frame buffer - */ -static int decode_residual_block(AVSContext *h, GetBitContext *gb, - const residual_vlc_t *r, int esc_golomb_order, - int qp, uint8_t *dst, int stride) { - int i,pos = -1; - int level_code, esc_code, level, run, mask; - int level_buf[64]; - int run_buf[64]; - int dqm = dequant_mul[qp]; - int dqs = dequant_shift[qp]; - int dqa = 1 << (dqs - 1); - const uint8_t *scantab = h->scantable.permutated; - DCTELEM *block = h->block; - - for(i=0;i<65;i++) { - level_code = get_ue_code(gb,r->golomb_order); - if(level_code >= ESCAPE_CODE) { - run = ((level_code - ESCAPE_CODE) >> 1) + 1; - esc_code = get_ue_code(gb,esc_golomb_order); - level = esc_code + (run > r->max_run ? 1 : r->level_add[run]); - while(level > r->inc_limit) - r++; - mask = -(level_code & 1); - level = (level^mask) - mask; - } else { - level = r->rltab[level_code][0]; - if(!level) //end of block signal - break; - run = r->rltab[level_code][1]; - r += r->rltab[level_code][2]; - } - level_buf[i] = level; - run_buf[i] = run; - } - /* inverse scan and dequantization */ - while(--i >= 0){ - pos += run_buf[i]; - if(pos > 63) { - av_log(h->s.avctx, AV_LOG_ERROR, - "position out of block bounds at pic %d MB(%d,%d)\n", - h->picture.poc, h->mbx, h->mby); - return -1; - } - block[scantab[pos]] = (level_buf[i]*dqm + dqa) >> dqs; - } - h->s.dsp.cavs_idct8_add(dst,block,stride); - return 0; -} - - -static inline void decode_residual_chroma(AVSContext *h) { - if(h->cbp & (1<<4)) - decode_residual_block(h,&h->s.gb,chroma_2dvlc,0, chroma_qp[h->qp], - h->cu,h->c_stride); - if(h->cbp & (1<<5)) - decode_residual_block(h,&h->s.gb,chroma_2dvlc,0, chroma_qp[h->qp], - h->cv,h->c_stride); -} - -static inline int decode_residual_inter(AVSContext *h) { - int block; - - /* get coded block pattern */ - int cbp= get_ue_golomb(&h->s.gb); - if(cbp > 63){ - av_log(h->s.avctx, AV_LOG_ERROR, "illegal inter cbp\n"); - return -1; - } - h->cbp = cbp_tab[cbp][1]; - - /* get quantizer */ - if(h->cbp && !h->qp_fixed) - h->qp = (h->qp + get_se_golomb(&h->s.gb)) & 63; - for(block=0;block<4;block++) - if(h->cbp & (1<s.gb,inter_2dvlc,0,h->qp, - h->cy + h->luma_scan[block], h->l_stride); - decode_residual_chroma(h); - - return 0; -} - /***************************************************************************** * * macroblock level @@ -734,7 +532,7 @@ static inline int decode_residual_inter(AVSContext *h) { /** * initialise predictors for motion vectors and intra prediction */ -static inline void init_mb(AVSContext *h) { +void ff_cavs_init_mb(AVSContext *h) { int i; /* copy predictors from top line (MB B and C) into cache */ @@ -746,10 +544,10 @@ static inline void init_mb(AVSContext *h) { h->pred_mode_Y[2] = h->top_pred_Y[h->mbx*2+1]; /* clear top predictors if MB B is not available */ if(!(h->flags & B_AVAIL)) { - h->mv[MV_FWD_B2] = un_mv; - h->mv[MV_FWD_B3] = un_mv; - h->mv[MV_BWD_B2] = un_mv; - h->mv[MV_BWD_B3] = un_mv; + h->mv[MV_FWD_B2] = ff_cavs_un_mv; + h->mv[MV_FWD_B3] = ff_cavs_un_mv; + h->mv[MV_BWD_B2] = ff_cavs_un_mv; + h->mv[MV_BWD_B3] = ff_cavs_un_mv; h->pred_mode_Y[1] = h->pred_mode_Y[2] = NOT_AVAIL; h->flags &= ~(C_AVAIL|D_AVAIL); } else if(h->mbx) { @@ -759,26 +557,24 @@ static inline void init_mb(AVSContext *h) { h->flags &= ~C_AVAIL; /* clear top-right predictors if MB C is not available */ if(!(h->flags & C_AVAIL)) { - h->mv[MV_FWD_C2] = un_mv; - h->mv[MV_BWD_C2] = un_mv; + h->mv[MV_FWD_C2] = ff_cavs_un_mv; + h->mv[MV_BWD_C2] = ff_cavs_un_mv; } /* clear top-left predictors if MB D is not available */ if(!(h->flags & D_AVAIL)) { - h->mv[MV_FWD_D3] = un_mv; - h->mv[MV_BWD_D3] = un_mv; + h->mv[MV_FWD_D3] = ff_cavs_un_mv; + h->mv[MV_BWD_D3] = ff_cavs_un_mv; } /* set pointer for co-located macroblock type */ h->col_type = &h->col_type_base[h->mby*h->mb_width + h->mbx]; } -static inline void check_for_slice(AVSContext *h); - /** * save predictors for later macroblocks and increase * macroblock address * @returns 0 if end of frame is reached, 1 otherwise */ -static inline int next_mb(AVSContext *h) { +int ff_cavs_next_mb(AVSContext *h) { int i; h->flags |= A_AVAIL; @@ -801,7 +597,7 @@ static inline int next_mb(AVSContext *h) { h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL; /* clear left mv predictors */ for(i=0;i<=20;i+=4) - h->mv[i] = un_mv; + h->mv[i] = ff_cavs_un_mv; h->mbx = 0; h->mby++; /* re-calculate sample pointers */ @@ -817,309 +613,21 @@ static inline int next_mb(AVSContext *h) { return 1; } -static int decode_mb_i(AVSContext *h, int cbp_code) { - GetBitContext *gb = &h->s.gb; - int block, pred_mode_uv; - uint8_t top[18]; - uint8_t *left = NULL; - uint8_t *d; - - init_mb(h); - - /* get intra prediction modes from stream */ - for(block=0;block<4;block++) { - int nA,nB,predpred; - int pos = scan3x3[block]; - - nA = h->pred_mode_Y[pos-1]; - nB = h->pred_mode_Y[pos-3]; - predpred = FFMIN(nA,nB); - if(predpred == NOT_AVAIL) // if either is not available - predpred = INTRA_L_LP; - if(!get_bits1(gb)){ - int rem_mode= get_bits(gb, 2); - predpred = rem_mode + (rem_mode >= predpred); - } - h->pred_mode_Y[pos] = predpred; - } - pred_mode_uv = get_ue_golomb(gb); - if(pred_mode_uv > 6) { - av_log(h->s.avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n"); - return -1; - } - - /* save pred modes before they get modified */ - h->pred_mode_Y[3] = h->pred_mode_Y[5]; - h->pred_mode_Y[6] = h->pred_mode_Y[8]; - h->top_pred_Y[h->mbx*2+0] = h->pred_mode_Y[7]; - h->top_pred_Y[h->mbx*2+1] = h->pred_mode_Y[8]; - - /* modify pred modes according to availability of neighbour samples */ - if(!(h->flags & A_AVAIL)) { - modify_pred(left_modifier_l, &h->pred_mode_Y[4] ); - modify_pred(left_modifier_l, &h->pred_mode_Y[7] ); - modify_pred(left_modifier_c, &pred_mode_uv ); - } - if(!(h->flags & B_AVAIL)) { - modify_pred(top_modifier_l, &h->pred_mode_Y[4] ); - modify_pred(top_modifier_l, &h->pred_mode_Y[5] ); - modify_pred(top_modifier_c, &pred_mode_uv ); - } - - /* get coded block pattern */ - if(h->pic_type == FF_I_TYPE) - cbp_code = get_ue_golomb(gb); - if(cbp_code > 63){ - av_log(h->s.avctx, AV_LOG_ERROR, "illegal intra cbp\n"); - return -1; - } - h->cbp = cbp_tab[cbp_code][0]; - if(h->cbp && !h->qp_fixed) - h->qp = (h->qp + get_se_golomb(gb)) & 63; //qp_delta - - /* luma intra prediction interleaved with residual decode/transform/add */ - for(block=0;block<4;block++) { - d = h->cy + h->luma_scan[block]; - load_intra_pred_luma(h, top, &left, block); - h->intra_pred_l[h->pred_mode_Y[scan3x3[block]]] - (d, top, left, h->l_stride); - if(h->cbp & (1<qp,d,h->l_stride); - } - - /* chroma intra prediction */ - /* extend borders by one pixel */ - h->left_border_u[9] = h->left_border_u[8]; - h->left_border_v[9] = h->left_border_v[8]; - h->top_border_u[h->mbx*10+9] = h->top_border_u[h->mbx*10+8]; - h->top_border_v[h->mbx*10+9] = h->top_border_v[h->mbx*10+8]; - if(h->mbx && h->mby) { - h->top_border_u[h->mbx*10] = h->left_border_u[0] = h->topleft_border_u; - h->top_border_v[h->mbx*10] = h->left_border_v[0] = h->topleft_border_v; - } else { - h->left_border_u[0] = h->left_border_u[1]; - h->left_border_v[0] = h->left_border_v[1]; - h->top_border_u[h->mbx*10] = h->top_border_u[h->mbx*10+1]; - h->top_border_v[h->mbx*10] = h->top_border_v[h->mbx*10+1]; - } - h->intra_pred_c[pred_mode_uv](h->cu, &h->top_border_u[h->mbx*10], - h->left_border_u, h->c_stride); - h->intra_pred_c[pred_mode_uv](h->cv, &h->top_border_v[h->mbx*10], - h->left_border_v, h->c_stride); - - decode_residual_chroma(h); - filter_mb(h,I_8X8); - - /* mark motion vectors as intra */ - h->mv[MV_FWD_X0] = intra_mv; - set_mvs(&h->mv[MV_FWD_X0], BLK_16X16); - h->mv[MV_BWD_X0] = intra_mv; - set_mvs(&h->mv[MV_BWD_X0], BLK_16X16); - if(h->pic_type != FF_B_TYPE) - *h->col_type = I_8X8; - - return 0; -} - -static void decode_mb_p(AVSContext *h, enum mb_t mb_type) { - GetBitContext *gb = &h->s.gb; - int ref[4]; - - init_mb(h); - switch(mb_type) { - case P_SKIP: - mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_PSKIP, BLK_16X16, 0); - break; - case P_16X16: - ref[0] = h->ref_flag ? 0 : get_bits1(gb); - mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16,ref[0]); - break; - case P_16X8: - ref[0] = h->ref_flag ? 0 : get_bits1(gb); - ref[2] = h->ref_flag ? 0 : get_bits1(gb); - mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, ref[0]); - mv_pred(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, ref[2]); - break; - case P_8X16: - ref[0] = h->ref_flag ? 0 : get_bits1(gb); - ref[1] = h->ref_flag ? 0 : get_bits1(gb); - mv_pred(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, ref[0]); - mv_pred(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_TOPRIGHT, BLK_8X16, ref[1]); - break; - case P_8X8: - ref[0] = h->ref_flag ? 0 : get_bits1(gb); - ref[1] = h->ref_flag ? 0 : get_bits1(gb); - ref[2] = h->ref_flag ? 0 : get_bits1(gb); - ref[3] = h->ref_flag ? 0 : get_bits1(gb); - mv_pred(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_MEDIAN, BLK_8X8, ref[0]); - mv_pred(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_MEDIAN, BLK_8X8, ref[1]); - mv_pred(h, MV_FWD_X2, MV_FWD_X1, MV_PRED_MEDIAN, BLK_8X8, ref[2]); - mv_pred(h, MV_FWD_X3, MV_FWD_X0, MV_PRED_MEDIAN, BLK_8X8, ref[3]); - } - inter_pred(h, mb_type); - store_mvs(h); - if(mb_type != P_SKIP) - decode_residual_inter(h); - filter_mb(h,mb_type); - *h->col_type = mb_type; -} - -static void decode_mb_b(AVSContext *h, enum mb_t mb_type) { - int block; - enum sub_mb_t sub_type[4]; - int flags; - - init_mb(h); - - /* reset all MVs */ - h->mv[MV_FWD_X0] = dir_mv; - set_mvs(&h->mv[MV_FWD_X0], BLK_16X16); - h->mv[MV_BWD_X0] = dir_mv; - set_mvs(&h->mv[MV_BWD_X0], BLK_16X16); - switch(mb_type) { - case B_SKIP: - case B_DIRECT: - if(!(*h->col_type)) { - /* intra MB at co-location, do in-plane prediction */ - mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_BSKIP, BLK_16X16, 1); - mv_pred(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_BSKIP, BLK_16X16, 0); - } else - /* direct prediction from co-located P MB, block-wise */ - for(block=0;block<4;block++) - mv_pred_direct(h,&h->mv[mv_scan[block]], - &h->col_mv[(h->mby*h->mb_width+h->mbx)*4 + block]); - break; - case B_FWD_16X16: - mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1); - break; - case B_SYM_16X16: - mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1); - mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X16); - break; - case B_BWD_16X16: - mv_pred(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_MEDIAN, BLK_16X16, 0); - break; - case B_8X8: - for(block=0;block<4;block++) - sub_type[block] = get_bits(&h->s.gb,2); - for(block=0;block<4;block++) { - switch(sub_type[block]) { - case B_SUB_DIRECT: - if(!(*h->col_type)) { - /* intra MB at co-location, do in-plane prediction */ - mv_pred(h, mv_scan[block], mv_scan[block]-3, - MV_PRED_BSKIP, BLK_8X8, 1); - mv_pred(h, mv_scan[block]+MV_BWD_OFFS, - mv_scan[block]-3+MV_BWD_OFFS, - MV_PRED_BSKIP, BLK_8X8, 0); - } else - mv_pred_direct(h,&h->mv[mv_scan[block]], - &h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + block]); - break; - case B_SUB_FWD: - mv_pred(h, mv_scan[block], mv_scan[block]-3, - MV_PRED_MEDIAN, BLK_8X8, 1); - break; - case B_SUB_SYM: - mv_pred(h, mv_scan[block], mv_scan[block]-3, - MV_PRED_MEDIAN, BLK_8X8, 1); - mv_pred_sym(h, &h->mv[mv_scan[block]], BLK_8X8); - break; - } - } - for(block=0;block<4;block++) { - if(sub_type[block] == B_SUB_BWD) - mv_pred(h, mv_scan[block]+MV_BWD_OFFS, - mv_scan[block]+MV_BWD_OFFS-3, - MV_PRED_MEDIAN, BLK_8X8, 0); - } - break; - default: - assert((mb_type > B_SYM_16X16) && (mb_type < B_8X8)); - flags = partition_flags[mb_type]; - if(mb_type & 1) { /* 16x8 macroblock types */ - if(flags & FWD0) - mv_pred(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, 1); - if(flags & SYM0) - mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X8); - if(flags & FWD1) - mv_pred(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, 1); - if(flags & SYM1) - mv_pred_sym(h, &h->mv[MV_FWD_X2], BLK_16X8); - if(flags & BWD0) - mv_pred(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_TOP, BLK_16X8, 0); - if(flags & BWD1) - mv_pred(h, MV_BWD_X2, MV_BWD_A1, MV_PRED_LEFT, BLK_16X8, 0); - } else { /* 8x16 macroblock types */ - if(flags & FWD0) - mv_pred(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, 1); - if(flags & SYM0) - mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_8X16); - if(flags & FWD1) - mv_pred(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_TOPRIGHT,BLK_8X16, 1); - if(flags & SYM1) - mv_pred_sym(h, &h->mv[MV_FWD_X1], BLK_8X16); - if(flags & BWD0) - mv_pred(h, MV_BWD_X0, MV_BWD_B3, MV_PRED_LEFT, BLK_8X16, 0); - if(flags & BWD1) - mv_pred(h, MV_BWD_X1, MV_BWD_C2, MV_PRED_TOPRIGHT,BLK_8X16, 0); - } - } - inter_pred(h, mb_type); - if(mb_type != B_SKIP) - decode_residual_inter(h); - filter_mb(h,mb_type); -} - -/***************************************************************************** - * - * slice level - * - ****************************************************************************/ - -static inline int decode_slice_header(AVSContext *h, GetBitContext *gb) { - if(h->stc > 0xAF) - av_log(h->s.avctx, AV_LOG_ERROR, "unexpected start code 0x%02x\n", h->stc); - h->mby = h->stc; - if((h->mby == 0) && (!h->qp_fixed)){ - h->qp_fixed = get_bits1(gb); - h->qp = get_bits(gb,6); - } - /* inter frame or second slice can have weighting params */ - if((h->pic_type != FF_I_TYPE) || (!h->pic_structure && h->mby >= h->mb_width/2)) - if(get_bits1(gb)) { //slice_weighting_flag - av_log(h->s.avctx, AV_LOG_ERROR, - "weighted prediction not yet supported\n"); - } - return 0; -} - -static inline void check_for_slice(AVSContext *h) { - GetBitContext *gb = &h->s.gb; - int align; - align = (-get_bits_count(gb)) & 7; - if((show_bits_long(gb,24+align) & 0xFFFFFF) == 0x000001) { - get_bits_long(gb,24+align); - h->stc = get_bits(gb,8); - decode_slice_header(h,gb); - } -} - /***************************************************************************** * * frame level * ****************************************************************************/ -static void init_pic(AVSContext *h) { +void ff_cavs_init_pic(AVSContext *h) { int i; /* clear some predictors */ for(i=0;i<=20;i+=4) - h->mv[i] = un_mv; - h->mv[MV_BWD_X0] = dir_mv; + h->mv[i] = ff_cavs_un_mv; + h->mv[MV_BWD_X0] = ff_cavs_dir_mv; set_mvs(&h->mv[MV_BWD_X0], BLK_16X16); - h->mv[MV_FWD_X0] = dir_mv; + h->mv[MV_FWD_X0] = ff_cavs_dir_mv; set_mvs(&h->mv[MV_FWD_X0], BLK_16X16); h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL; h->cy = h->picture.data[0]; @@ -1133,136 +641,6 @@ static void init_pic(AVSContext *h) { h->flags = 0; } -static int decode_pic(AVSContext *h) { - MpegEncContext *s = &h->s; - int skip_count; - enum mb_t mb_type; - - if (!s->context_initialized) { - s->avctx->idct_algo = FF_IDCT_CAVS; - if (MPV_common_init(s) < 0) - return -1; - ff_init_scantable(s->dsp.idct_permutation,&h->scantable,ff_zigzag_direct); - } - get_bits(&s->gb,16);//bbv_dwlay - if(h->stc == PIC_PB_START_CODE) { - h->pic_type = get_bits(&s->gb,2) + FF_I_TYPE; - if(h->pic_type > FF_B_TYPE) { - av_log(s->avctx, AV_LOG_ERROR, "illegal picture type\n"); - return -1; - } - /* make sure we have the reference frames we need */ - if(!h->DPB[0].data[0] || - (!h->DPB[1].data[0] && h->pic_type == FF_B_TYPE)) - return -1; - } else { - h->pic_type = FF_I_TYPE; - if(get_bits1(&s->gb)) - get_bits(&s->gb,16);//time_code - } - /* release last B frame */ - if(h->picture.data[0]) - s->avctx->release_buffer(s->avctx, (AVFrame *)&h->picture); - - s->avctx->get_buffer(s->avctx, (AVFrame *)&h->picture); - init_pic(h); - h->picture.poc = get_bits(&s->gb,8)*2; - - /* get temporal distances and MV scaling factors */ - if(h->pic_type != FF_B_TYPE) { - h->dist[0] = (h->picture.poc - h->DPB[0].poc + 512) % 512; - } else { - h->dist[0] = (h->DPB[0].poc - h->picture.poc + 512) % 512; - } - h->dist[1] = (h->picture.poc - h->DPB[1].poc + 512) % 512; - h->scale_den[0] = h->dist[0] ? 512/h->dist[0] : 0; - h->scale_den[1] = h->dist[1] ? 512/h->dist[1] : 0; - if(h->pic_type == FF_B_TYPE) { - h->sym_factor = h->dist[0]*h->scale_den[1]; - } else { - h->direct_den[0] = h->dist[0] ? 16384/h->dist[0] : 0; - h->direct_den[1] = h->dist[1] ? 16384/h->dist[1] : 0; - } - - if(s->low_delay) - get_ue_golomb(&s->gb); //bbv_check_times - h->progressive = get_bits1(&s->gb); - if(h->progressive) - h->pic_structure = 1; - else if(!(h->pic_structure = get_bits1(&s->gb) && (h->stc == PIC_PB_START_CODE)) ) - get_bits1(&s->gb); //advanced_pred_mode_disable - skip_bits1(&s->gb); //top_field_first - skip_bits1(&s->gb); //repeat_first_field - h->qp_fixed = get_bits1(&s->gb); - h->qp = get_bits(&s->gb,6); - if(h->pic_type == FF_I_TYPE) { - if(!h->progressive && !h->pic_structure) - skip_bits1(&s->gb);//what is this? - skip_bits(&s->gb,4); //reserved bits - } else { - if(!(h->pic_type == FF_B_TYPE && h->pic_structure == 1)) - h->ref_flag = get_bits1(&s->gb); - skip_bits(&s->gb,4); //reserved bits - h->skip_mode_flag = get_bits1(&s->gb); - } - h->loop_filter_disable = get_bits1(&s->gb); - if(!h->loop_filter_disable && get_bits1(&s->gb)) { - h->alpha_offset = get_se_golomb(&s->gb); - h->beta_offset = get_se_golomb(&s->gb); - } else { - h->alpha_offset = h->beta_offset = 0; - } - check_for_slice(h); - if(h->pic_type == FF_I_TYPE) { - do { - decode_mb_i(h, 0); - } while(next_mb(h)); - } else if(h->pic_type == FF_P_TYPE) { - do { - if(h->skip_mode_flag) { - skip_count = get_ue_golomb(&s->gb); - while(skip_count--) { - decode_mb_p(h,P_SKIP); - if(!next_mb(h)) - goto done; - } - mb_type = get_ue_golomb(&s->gb) + P_16X16; - } else - mb_type = get_ue_golomb(&s->gb) + P_SKIP; - if(mb_type > P_8X8) { - decode_mb_i(h, mb_type - P_8X8 - 1); - } else - decode_mb_p(h,mb_type); - } while(next_mb(h)); - } else { /* FF_B_TYPE */ - do { - if(h->skip_mode_flag) { - skip_count = get_ue_golomb(&s->gb); - while(skip_count--) { - decode_mb_b(h,B_SKIP); - if(!next_mb(h)) - goto done; - } - mb_type = get_ue_golomb(&s->gb) + B_DIRECT; - } else - mb_type = get_ue_golomb(&s->gb) + B_SKIP; - if(mb_type > B_8X8) { - decode_mb_i(h, mb_type - B_8X8 - 1); - } else - decode_mb_b(h,mb_type); - } while(next_mb(h)); - } - done: - if(h->pic_type != FF_B_TYPE) { - if(h->DPB[1].data[0]) - s->avctx->release_buffer(s->avctx, (AVFrame *)&h->DPB[1]); - memcpy(&h->DPB[1], &h->DPB[0], sizeof(Picture)); - memcpy(&h->DPB[0], &h->picture, sizeof(Picture)); - memset(&h->picture,0,sizeof(Picture)); - } - return 0; -} - /***************************************************************************** * * headers and interface @@ -1274,7 +652,7 @@ static int decode_pic(AVSContext *h) { * this data has to be stored for one complete row of macroblocks * and this storage space is allocated here */ -static void init_top_lines(AVSContext *h) { +void ff_cavs_init_top_lines(AVSContext *h) { /* alloc top line of predictors */ h->top_qp = av_malloc( h->mb_width); h->top_mv[0] = av_malloc((h->mb_width*2+1)*sizeof(vector_t)); @@ -1290,116 +668,7 @@ static void init_top_lines(AVSContext *h) { h->block = av_mallocz(64*sizeof(DCTELEM)); } -static int decode_seq_header(AVSContext *h) { - MpegEncContext *s = &h->s; - extern const AVRational ff_frame_rate_tab[]; - int frame_rate_code; - - h->profile = get_bits(&s->gb,8); - h->level = get_bits(&s->gb,8); - skip_bits1(&s->gb); //progressive sequence - s->width = get_bits(&s->gb,14); - s->height = get_bits(&s->gb,14); - skip_bits(&s->gb,2); //chroma format - skip_bits(&s->gb,3); //sample_precision - h->aspect_ratio = get_bits(&s->gb,4); - frame_rate_code = get_bits(&s->gb,4); - skip_bits(&s->gb,18);//bit_rate_lower - skip_bits1(&s->gb); //marker_bit - skip_bits(&s->gb,12);//bit_rate_upper - s->low_delay = get_bits1(&s->gb); - h->mb_width = (s->width + 15) >> 4; - h->mb_height = (s->height + 15) >> 4; - h->s.avctx->time_base.den = ff_frame_rate_tab[frame_rate_code].num; - h->s.avctx->time_base.num = ff_frame_rate_tab[frame_rate_code].den; - h->s.avctx->width = s->width; - h->s.avctx->height = s->height; - if(!h->top_qp) - init_top_lines(h); - return 0; -} - -static void cavs_flush(AVCodecContext * avctx) { - AVSContext *h = avctx->priv_data; - h->got_keyframe = 0; -} - -static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size, - uint8_t * buf, int buf_size) { - AVSContext *h = avctx->priv_data; - MpegEncContext *s = &h->s; - int input_size; - const uint8_t *buf_end; - const uint8_t *buf_ptr; - AVFrame *picture = data; - uint32_t stc; - - s->avctx = avctx; - - if (buf_size == 0) { - if(!s->low_delay && h->DPB[0].data[0]) { - *data_size = sizeof(AVPicture); - *picture = *(AVFrame *) &h->DPB[0]; - } - return 0; - } - - buf_ptr = buf; - buf_end = buf + buf_size; - for(;;) { - buf_ptr = ff_find_start_code(buf_ptr,buf_end, &stc); - if(stc & 0xFFFFFE00) - return FFMAX(0, buf_ptr - buf - s->parse_context.last_index); - input_size = (buf_end - buf_ptr)*8; - switch(stc) { - case SEQ_START_CODE: - init_get_bits(&s->gb, buf_ptr, input_size); - decode_seq_header(h); - break; - case PIC_I_START_CODE: - if(!h->got_keyframe) { - if(h->DPB[0].data[0]) - avctx->release_buffer(avctx, (AVFrame *)&h->DPB[0]); - if(h->DPB[1].data[0]) - avctx->release_buffer(avctx, (AVFrame *)&h->DPB[1]); - h->got_keyframe = 1; - } - case PIC_PB_START_CODE: - *data_size = 0; - if(!h->got_keyframe) - break; - init_get_bits(&s->gb, buf_ptr, input_size); - h->stc = stc; - if(decode_pic(h)) - break; - *data_size = sizeof(AVPicture); - if(h->pic_type != FF_B_TYPE) { - if(h->DPB[1].data[0]) { - *picture = *(AVFrame *) &h->DPB[1]; - } else { - *data_size = 0; - } - } else - *picture = *(AVFrame *) &h->picture; - break; - case EXT_START_CODE: - //mpeg_decode_extension(avctx,buf_ptr, input_size); - break; - case USER_START_CODE: - //mpeg_decode_user_data(avctx,buf_ptr, input_size); - break; - default: - if (stc >= SLICE_MIN_START_CODE && - stc <= SLICE_MAX_START_CODE) { - init_get_bits(&s->gb, buf_ptr, input_size); - decode_slice_header(h, &s->gb); - } - break; - } - } -} - -static int cavs_decode_init(AVCodecContext * avctx) { +int ff_cavs_init(AVCodecContext *avctx) { AVSContext *h = avctx->priv_data; MpegEncContext * const s = &h->s; @@ -1425,12 +694,12 @@ static int cavs_decode_init(AVCodecContext * avctx) { h->intra_pred_c[ INTRA_C_LP_LEFT] = intra_pred_lp_left; h->intra_pred_c[ INTRA_C_LP_TOP] = intra_pred_lp_top; h->intra_pred_c[ INTRA_C_DC_128] = intra_pred_dc_128; - h->mv[ 7] = un_mv; - h->mv[19] = un_mv; + h->mv[ 7] = ff_cavs_un_mv; + h->mv[19] = ff_cavs_un_mv; return 0; } -static int cavs_decode_end(AVCodecContext * avctx) { +int ff_cavs_end(AVCodecContext *avctx) { AVSContext *h = avctx->priv_data; av_free(h->top_qp); @@ -1445,96 +714,3 @@ static int cavs_decode_end(AVCodecContext * avctx) { av_free(h->block); return 0; } - -AVCodec cavs_decoder = { - "cavs", - CODEC_TYPE_VIDEO, - CODEC_ID_CAVS, - sizeof(AVSContext), - cavs_decode_init, - NULL, - cavs_decode_end, - cavs_decode_frame, - CODEC_CAP_DR1 | CODEC_CAP_DELAY, - .flush= cavs_flush, -}; -#endif /* CONFIG_CAVS_DECODER */ - -#ifdef CONFIG_CAVSVIDEO_PARSER -/** - * finds the end of the current frame in the bitstream. - * @return the position of the first byte of the next frame, or -1 - */ -static int cavs_find_frame_end(ParseContext *pc, const uint8_t *buf, - int buf_size) { - int pic_found, i; - uint32_t state; - - pic_found= pc->frame_start_found; - state= pc->state; - - i=0; - if(!pic_found){ - for(i=0; i SLICE_MAX_START_CODE){ - pc->frame_start_found=0; - pc->state=-1; - return i-3; - } - } - } - } - pc->frame_start_found= pic_found; - pc->state= state; - return END_NOT_FOUND; -} - -static int cavsvideo_parse(AVCodecParserContext *s, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - ParseContext *pc = s->priv_data; - int next; - - if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ - next= buf_size; - }else{ - next= cavs_find_frame_end(pc, buf, buf_size); - - if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { - *poutbuf = NULL; - *poutbuf_size = 0; - return buf_size; - } - } - *poutbuf = (uint8_t *)buf; - *poutbuf_size = buf_size; - return next; -} - -AVCodecParser cavsvideo_parser = { - { CODEC_ID_CAVS }, - sizeof(ParseContext1), - NULL, - cavsvideo_parse, - ff_parse1_close, - ff_mpeg4video_split, -}; -#endif /* CONFIG_CAVSVIDEO_PARSER */ diff --git a/contrib/ffmpeg/libavcodec/cavs.h b/contrib/ffmpeg/libavcodec/cavs.h new file mode 100644 index 000000000..9afa96e42 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/cavs.h @@ -0,0 +1,314 @@ +/* + * Chinese AVS video (AVS1-P2, JiZhun profile) decoder. + * Copyright (c) 2006 Stefan Gehrer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_CAVS_H +#define FFMPEG_CAVS_H + +#include "dsputil.h" +#include "mpegvideo.h" + +#define SLICE_MIN_START_CODE 0x00000101 +#define SLICE_MAX_START_CODE 0x000001af +#define EXT_START_CODE 0x000001b5 +#define USER_START_CODE 0x000001b2 +#define CAVS_START_CODE 0x000001b0 +#define PIC_I_START_CODE 0x000001b3 +#define PIC_PB_START_CODE 0x000001b6 + +#define A_AVAIL 1 +#define B_AVAIL 2 +#define C_AVAIL 4 +#define D_AVAIL 8 +#define NOT_AVAIL -1 +#define REF_INTRA -2 +#define REF_DIR -3 + +#define ESCAPE_CODE 59 + +#define FWD0 0x01 +#define FWD1 0x02 +#define BWD0 0x04 +#define BWD1 0x08 +#define SYM0 0x10 +#define SYM1 0x20 +#define SPLITH 0x40 +#define SPLITV 0x80 + +#define MV_BWD_OFFS 12 +#define MV_STRIDE 4 + +enum mb_t { + I_8X8 = 0, + P_SKIP, + P_16X16, + P_16X8, + P_8X16, + P_8X8, + B_SKIP, + B_DIRECT, + B_FWD_16X16, + B_BWD_16X16, + B_SYM_16X16, + B_8X8 = 29 +}; + +enum sub_mb_t { + B_SUB_DIRECT, + B_SUB_FWD, + B_SUB_BWD, + B_SUB_SYM +}; + +enum intra_luma_t { + INTRA_L_VERT, + INTRA_L_HORIZ, + INTRA_L_LP, + INTRA_L_DOWN_LEFT, + INTRA_L_DOWN_RIGHT, + INTRA_L_LP_LEFT, + INTRA_L_LP_TOP, + INTRA_L_DC_128 +}; + +enum intra_chroma_t { + INTRA_C_LP, + INTRA_C_HORIZ, + INTRA_C_VERT, + INTRA_C_PLANE, + INTRA_C_LP_LEFT, + INTRA_C_LP_TOP, + INTRA_C_DC_128, +}; + +enum mv_pred_t { + MV_PRED_MEDIAN, + MV_PRED_LEFT, + MV_PRED_TOP, + MV_PRED_TOPRIGHT, + MV_PRED_PSKIP, + MV_PRED_BSKIP +}; + +enum block_t { + BLK_16X16, + BLK_16X8, + BLK_8X16, + BLK_8X8 +}; + +enum mv_loc_t { + MV_FWD_D3 = 0, + MV_FWD_B2, + MV_FWD_B3, + MV_FWD_C2, + MV_FWD_A1, + MV_FWD_X0, + MV_FWD_X1, + MV_FWD_A3 = 8, + MV_FWD_X2, + MV_FWD_X3, + MV_BWD_D3 = MV_BWD_OFFS, + MV_BWD_B2, + MV_BWD_B3, + MV_BWD_C2, + MV_BWD_A1, + MV_BWD_X0, + MV_BWD_X1, + MV_BWD_A3 = MV_BWD_OFFS+8, + MV_BWD_X2, + MV_BWD_X3 +}; + +DECLARE_ALIGNED_8(typedef, struct) { + int16_t x; + int16_t y; + int16_t dist; + int16_t ref; +} vector_t; + +typedef struct dec_2dvlc_t { + int8_t rltab[59][3]; + int8_t level_add[27]; + int8_t golomb_order; + int inc_limit; + int8_t max_run; +} dec_2dvlc_t; + +typedef struct { + MpegEncContext s; + Picture picture; ///< currently decoded frame + Picture DPB[2]; ///< reference frames + int dist[2]; ///< temporal distances from current frame to ref frames + int profile, level; + int aspect_ratio; + int mb_width, mb_height; + int pic_type; + int progressive; + int pic_structure; + int skip_mode_flag; ///< select between skip_count or one skip_flag per MB + int loop_filter_disable; + int alpha_offset, beta_offset; + int ref_flag; + int mbx, mby; ///< macroblock coordinates + int flags; ///< availability flags of neighbouring macroblocks + int stc; ///< last start code + uint8_t *cy, *cu, *cv; ///< current MB sample pointers + int left_qp; + uint8_t *top_qp; + + /** mv motion vector cache + 0: D3 B2 B3 C2 + 4: A1 X0 X1 - + 8: A3 X2 X3 - + + X are the vectors in the current macroblock (5,6,9,10) + A is the macroblock to the left (4,8) + B is the macroblock to the top (1,2) + C is the macroblock to the top-right (3) + D is the macroblock to the top-left (0) + + the same is repeated for backward motion vectors */ + vector_t mv[2*4*3]; + vector_t *top_mv[2]; + vector_t *col_mv; + + /** luma pred mode cache + 0: -- B2 B3 + 3: A1 X0 X1 + 6: A3 X2 X3 */ + int pred_mode_Y[3*3]; + int *top_pred_Y; + int l_stride, c_stride; + int luma_scan[4]; + int qp; + int qp_fixed; + int cbp; + ScanTable scantable; + + /** intra prediction is done with un-deblocked samples + they are saved here before deblocking the MB */ + uint8_t *top_border_y, *top_border_u, *top_border_v; + uint8_t left_border_y[26], left_border_u[10], left_border_v[10]; + uint8_t intern_border_y[26]; + uint8_t topleft_border_y, topleft_border_u, topleft_border_v; + + void (*intra_pred_l[8])(uint8_t *d,uint8_t *top,uint8_t *left,int stride); + void (*intra_pred_c[7])(uint8_t *d,uint8_t *top,uint8_t *left,int stride); + uint8_t *col_type_base; + uint8_t *col_type; + + /* scaling factors for MV prediction */ + int sym_factor; ///< for scaling in symmetrical B block + int direct_den[2]; ///< for scaling in direct B block + int scale_den[2]; ///< for scaling neighbouring MVs + + int got_keyframe; + DCTELEM *block; +} AVSContext; + +extern const uint8_t ff_cavs_dequant_shift[64]; +extern const uint16_t ff_cavs_dequant_mul[64]; +extern const dec_2dvlc_t ff_cavs_intra_dec[7]; +extern const dec_2dvlc_t ff_cavs_inter_dec[7]; +extern const dec_2dvlc_t ff_cavs_chroma_dec[5]; +extern const uint8_t ff_cavs_chroma_qp[64]; +extern const uint8_t ff_cavs_scan3x3[4]; +extern const uint8_t ff_cavs_partition_flags[30]; +extern const int_fast8_t ff_left_modifier_l[8]; +extern const int_fast8_t ff_top_modifier_l[8]; +extern const int_fast8_t ff_left_modifier_c[7]; +extern const int_fast8_t ff_top_modifier_c[7]; +extern const vector_t ff_cavs_intra_mv; +extern const vector_t ff_cavs_un_mv; +extern const vector_t ff_cavs_dir_mv; + +static inline void modify_pred(const int_fast8_t *mod_table, int *mode) { + *mode = mod_table[*mode]; + if(*mode < 0) { + av_log(NULL, AV_LOG_ERROR, "Illegal intra prediction mode\n"); + *mode = 0; + } +} + +static inline void set_intra_mode_default(AVSContext *h) { + h->pred_mode_Y[3] = h->pred_mode_Y[6] = INTRA_L_LP; + h->top_pred_Y[h->mbx*2+0] = h->top_pred_Y[h->mbx*2+1] = INTRA_L_LP; +} + +static inline void set_mvs(vector_t *mv, enum block_t size) { + switch(size) { + case BLK_16X16: + mv[MV_STRIDE ] = mv[0]; + mv[MV_STRIDE+1] = mv[0]; + case BLK_16X8: + mv[1] = mv[0]; + break; + case BLK_8X16: + mv[MV_STRIDE] = mv[0]; + break; + } +} + +static inline void set_mv_intra(AVSContext *h) { + h->mv[MV_FWD_X0] = ff_cavs_intra_mv; + set_mvs(&h->mv[MV_FWD_X0], BLK_16X16); + h->mv[MV_BWD_X0] = ff_cavs_intra_mv; + set_mvs(&h->mv[MV_BWD_X0], BLK_16X16); + if(h->pic_type != FF_B_TYPE) + *h->col_type = I_8X8; +} + +static inline int dequant(AVSContext *h, DCTELEM *level_buf, uint8_t *run_buf, + DCTELEM *dst, int mul, int shift, int coeff_num) { + int round = 1 << (shift - 1); + int pos = -1; + const uint8_t *scantab = h->scantable.permutated; + + /* inverse scan and dequantization */ + while(--coeff_num >= 0){ + pos += run_buf[coeff_num]; + if(pos > 63) { + av_log(h->s.avctx, AV_LOG_ERROR, + "position out of block bounds at pic %d MB(%d,%d)\n", + h->picture.poc, h->mbx, h->mby); + return -1; + } + dst[scantab[pos]] = (level_buf[coeff_num]*mul + round) >> shift; + } + return 0; +} + +void ff_cavs_filter(AVSContext *h, enum mb_t mb_type); +void ff_cavs_load_intra_pred_luma(AVSContext *h, uint8_t *top, uint8_t **left, + int block); +void ff_cavs_load_intra_pred_chroma(AVSContext *h); +void ff_cavs_modify_mb_i(AVSContext *h, int *pred_mode_uv); +void ff_cavs_inter(AVSContext *h, enum mb_t mb_type); +void ff_cavs_mv(AVSContext *h, enum mv_loc_t nP, enum mv_loc_t nC, + enum mv_pred_t mode, enum block_t size, int ref); +void ff_cavs_init_mb(AVSContext *h); +int ff_cavs_next_mb(AVSContext *h); +void ff_cavs_init_pic(AVSContext *h); +void ff_cavs_init_top_lines(AVSContext *h); +int ff_cavs_init(AVCodecContext *avctx); +int ff_cavs_end (AVCodecContext *avctx); + +#endif /* FFMPEG_CAVS_H */ diff --git a/contrib/ffmpeg/libavcodec/cavs_parser.c b/contrib/ffmpeg/libavcodec/cavs_parser.c new file mode 100644 index 000000000..33f7fff71 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/cavs_parser.c @@ -0,0 +1,107 @@ +/* + * Chinese AVS video (AVS1-P2, JiZhun profile) parser. + * Copyright (c) 2006 Stefan Gehrer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file cavs_parser.c + * Chinese AVS video (AVS1-P2, JiZhun profile) parser + * @author Stefan Gehrer + */ + +#include "parser.h" +#include "cavs.h" + + +/** + * finds the end of the current frame in the bitstream. + * @return the position of the first byte of the next frame, or -1 + */ +static int cavs_find_frame_end(ParseContext *pc, const uint8_t *buf, + int buf_size) { + int pic_found, i; + uint32_t state; + + pic_found= pc->frame_start_found; + state= pc->state; + + i=0; + if(!pic_found){ + for(i=0; i SLICE_MAX_START_CODE){ + pc->frame_start_found=0; + pc->state=-1; + return i-3; + } + } + } + } + pc->frame_start_found= pic_found; + pc->state= state; + return END_NOT_FOUND; +} + +static int cavsvideo_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + ParseContext *pc = s->priv_data; + int next; + + if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ + next= buf_size; + }else{ + next= cavs_find_frame_end(pc, buf, buf_size); + + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + } + *poutbuf = buf; + *poutbuf_size = buf_size; + return next; +} + +AVCodecParser cavsvideo_parser = { + { CODEC_ID_CAVS }, + sizeof(ParseContext1), + NULL, + cavsvideo_parse, + ff_parse1_close, + ff_mpeg4video_split, +}; diff --git a/contrib/ffmpeg/libavcodec/cavsdata.h b/contrib/ffmpeg/libavcodec/cavsdata.h index d76985136..a24fb5ddb 100644 --- a/contrib/ffmpeg/libavcodec/cavsdata.h +++ b/contrib/ffmpeg/libavcodec/cavsdata.h @@ -16,123 +16,15 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#define SLICE_MIN_START_CODE 0x00000101 -#define SLICE_MAX_START_CODE 0x000001af -#define EXT_START_CODE 0x000001b5 -#define USER_START_CODE 0x000001b2 -#define SEQ_START_CODE 0x000001b0 -#define PIC_I_START_CODE 0x000001b3 -#define PIC_PB_START_CODE 0x000001b6 +#ifndef FFMPEG_CAVSDATA_H +#define FFMPEG_CAVSDATA_H -#define A_AVAIL 1 -#define B_AVAIL 2 -#define C_AVAIL 4 -#define D_AVAIL 8 -#define NOT_AVAIL -1 -#define REF_INTRA -2 -#define REF_DIR -3 +#include "cavs.h" -#define ESCAPE_CODE 59 - -#define FWD0 0x01 -#define FWD1 0x02 -#define BWD0 0x04 -#define BWD1 0x08 -#define SYM0 0x10 -#define SYM1 0x20 -#define SPLITH 0x40 -#define SPLITV 0x80 - -#define MV_BWD_OFFS 12 -#define MV_STRIDE 4 - -enum mb_t { - I_8X8 = 0, - P_SKIP, - P_16X16, - P_16X8, - P_8X16, - P_8X8, - B_SKIP, - B_DIRECT, - B_FWD_16X16, - B_BWD_16X16, - B_SYM_16X16, - B_8X8 = 29 -}; - -enum sub_mb_t { - B_SUB_DIRECT, - B_SUB_FWD, - B_SUB_BWD, - B_SUB_SYM -}; - -enum intra_luma_t { - INTRA_L_VERT, - INTRA_L_HORIZ, - INTRA_L_LP, - INTRA_L_DOWN_LEFT, - INTRA_L_DOWN_RIGHT, - INTRA_L_LP_LEFT, - INTRA_L_LP_TOP, - INTRA_L_DC_128 -}; - -enum intra_chroma_t { - INTRA_C_LP, - INTRA_C_HORIZ, - INTRA_C_VERT, - INTRA_C_PLANE, - INTRA_C_LP_LEFT, - INTRA_C_LP_TOP, - INTRA_C_DC_128, -}; - -enum mv_pred_t { - MV_PRED_MEDIAN, - MV_PRED_LEFT, - MV_PRED_TOP, - MV_PRED_TOPRIGHT, - MV_PRED_PSKIP, - MV_PRED_BSKIP -}; - -enum block_t { - BLK_16X16, - BLK_16X8, - BLK_8X16, - BLK_8X8 -}; - -enum mv_loc_t { - MV_FWD_D3 = 0, - MV_FWD_B2, - MV_FWD_B3, - MV_FWD_C2, - MV_FWD_A1, - MV_FWD_X0, - MV_FWD_X1, - MV_FWD_A3 = 8, - MV_FWD_X2, - MV_FWD_X3, - MV_BWD_D3 = MV_BWD_OFFS, - MV_BWD_B2, - MV_BWD_B3, - MV_BWD_C2, - MV_BWD_A1, - MV_BWD_X0, - MV_BWD_X1, - MV_BWD_A3 = MV_BWD_OFFS+8, - MV_BWD_X2, - MV_BWD_X3 -}; - -#ifdef CONFIG_CAVS_DECODER -static const uint8_t partition_flags[30] = { +const uint8_t ff_cavs_partition_flags[30] = { 0, //I_8X8 0, //P_SKIP 0, //P_16X16 @@ -165,32 +57,16 @@ static const uint8_t partition_flags[30] = { SPLITH|SPLITV, //B_8X8 = 29 }; -static const uint8_t scan3x3[4] = {4,5,7,8}; - -static const uint8_t mv_scan[4] = { - MV_FWD_X0,MV_FWD_X1, - MV_FWD_X2,MV_FWD_X3 -}; - -static const uint8_t cbp_tab[64][2] = { - {63, 0},{15,15},{31,63},{47,31},{ 0,16},{14,32},{13,47},{11,13}, - { 7,14},{ 5,11},{10,12},{ 8, 5},{12,10},{61, 7},{ 4,48},{55, 3}, - { 1, 2},{ 2, 8},{59, 4},{ 3, 1},{62,61},{ 9,55},{ 6,59},{29,62}, - {45,29},{51,27},{23,23},{39,19},{27,30},{46,28},{53, 9},{30, 6}, - {43,60},{37,21},{60,44},{16,26},{21,51},{28,35},{19,18},{35,20}, - {42,24},{26,53},{44,17},{32,37},{58,39},{24,45},{20,58},{17,43}, - {18,42},{48,46},{22,36},{33,33},{25,34},{49,40},{40,52},{36,49}, - {34,50},{50,56},{52,25},{54,22},{41,54},{56,57},{38,41},{57,38} -}; +const uint8_t ff_cavs_scan3x3[4] = {4,5,7,8}; -static const uint8_t chroma_qp[64] = { +const uint8_t ff_cavs_chroma_qp[64] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15, 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, 32,33,34,35,36,37,38,39,40,41,42,42,43,43,44,44, 45,45,46,46,47,47,48,48,48,49,49,49,50,50,50,51 }; -static const uint8_t dequant_shift[64] = { +const uint8_t ff_cavs_dequant_shift[64] = { 14,14,14,14,14,14,14,14, 13,13,13,13,13,13,13,13, 13,12,12,12,12,12,12,12, @@ -201,7 +77,7 @@ static const uint8_t dequant_shift[64] = { 7, 7, 7, 7, 7, 7, 7, 7 }; -static const uint16_t dequant_mul[64] = { +const uint16_t ff_cavs_dequant_mul[64] = { 32768,36061,38968,42495,46341,50535,55437,60424, 32932,35734,38968,42495,46177,50535,55109,59933, 65535,35734,38968,42577,46341,50617,55027,60097, @@ -212,35 +88,20 @@ static const uint16_t dequant_mul[64] = { 32771,35734,38965,42497,46341,50535,55109,60099 }; -DECLARE_ALIGNED_8(typedef, struct) { - int16_t x; - int16_t y; - int16_t dist; - int16_t ref; -} vector_t; - /** marks block as unavailable, i.e. out of picture or not yet decoded */ -static const vector_t un_mv = {0,0,1,NOT_AVAIL}; +const vector_t ff_cavs_un_mv = {0,0,1,NOT_AVAIL}; /** marks block as "no prediction from this direction" e.g. forward motion vector in BWD partition */ -static const vector_t dir_mv = {0,0,1,REF_DIR}; +const vector_t ff_cavs_dir_mv = {0,0,1,REF_DIR}; /** marks block as using intra prediction */ -static const vector_t intra_mv = {0,0,1,REF_INTRA}; - -typedef struct residual_vlc_t { - int8_t rltab[59][3]; - int8_t level_add[27]; - int8_t golomb_order; - int inc_limit; - int8_t max_run; -} residual_vlc_t; +const vector_t ff_cavs_intra_mv = {0,0,1,REF_INTRA}; #define EOB 0,0,0 -static const residual_vlc_t intra_2dvlc[7] = { +const dec_2dvlc_t ff_cavs_intra_dec[7] = { { { //level / run / table_inc { 1, 1, 1},{ -1, 1, 1},{ 1, 2, 1},{ -1, 2, 1},{ 1, 3, 1},{ -1, 3, 1}, @@ -377,7 +238,7 @@ static const residual_vlc_t intra_2dvlc[7] = { } }; -static const residual_vlc_t inter_2dvlc[7] = { +const dec_2dvlc_t ff_cavs_inter_dec[7] = { { { //level / run { 1, 1, 1},{ -1, 1, 1},{ 1, 2, 1},{ -1, 2, 1},{ 1, 3, 1},{ -1, 3, 1}, @@ -514,7 +375,7 @@ static const residual_vlc_t inter_2dvlc[7] = { } }; -static const residual_vlc_t chroma_2dvlc[5] = { +const dec_2dvlc_t ff_cavs_chroma_dec[5] = { { { //level / run { 1, 1, 1},{ -1, 1, 1},{ 1, 2, 1},{ -1, 2, 1},{ 1, 3, 1},{ -1, 3, 1}, @@ -636,8 +497,9 @@ static const uint8_t tc_tab[64] = { 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9 }; -static const int_fast8_t left_modifier_l[8] = { 0,-1, 6,-1,-1, 7, 6, 7}; -static const int_fast8_t top_modifier_l[8] = {-1, 1, 5,-1,-1, 5, 7, 7}; -static const int_fast8_t left_modifier_c[7] = { 5,-1, 2,-1, 6, 5, 6}; -static const int_fast8_t top_modifier_c[7] = { 4, 1,-1,-1, 4, 6, 6}; -#endif /* CONFIG_CAVS_DECODER */ +const int_fast8_t ff_left_modifier_l[8] = { 0,-1, 6,-1,-1, 7, 6, 7}; +const int_fast8_t ff_top_modifier_l[8] = {-1, 1, 5,-1,-1, 5, 7, 7}; +const int_fast8_t ff_left_modifier_c[7] = { 5,-1, 2,-1, 6, 5, 6}; +const int_fast8_t ff_top_modifier_c[7] = { 4, 1,-1,-1, 4, 6, 6}; + +#endif /* FFMPEG_CAVSDATA_H */ diff --git a/contrib/ffmpeg/libavcodec/cavsdec.c b/contrib/ffmpeg/libavcodec/cavsdec.c new file mode 100644 index 000000000..b3849a434 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/cavsdec.c @@ -0,0 +1,702 @@ +/* + * Chinese AVS video (AVS1-P2, JiZhun profile) decoder. + * Copyright (c) 2006 Stefan Gehrer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file cavs.c + * Chinese AVS video (AVS1-P2, JiZhun profile) decoder + * @author Stefan Gehrer + */ + +#include "avcodec.h" +#include "bitstream.h" +#include "golomb.h" +#include "cavs.h" + +static const uint8_t mv_scan[4] = { + MV_FWD_X0,MV_FWD_X1, + MV_FWD_X2,MV_FWD_X3 +}; + +static const uint8_t cbp_tab[64][2] = { + {63, 0},{15,15},{31,63},{47,31},{ 0,16},{14,32},{13,47},{11,13}, + { 7,14},{ 5,11},{10,12},{ 8, 5},{12,10},{61, 7},{ 4,48},{55, 3}, + { 1, 2},{ 2, 8},{59, 4},{ 3, 1},{62,61},{ 9,55},{ 6,59},{29,62}, + {45,29},{51,27},{23,23},{39,19},{27,30},{46,28},{53, 9},{30, 6}, + {43,60},{37,21},{60,44},{16,26},{21,51},{28,35},{19,18},{35,20}, + {42,24},{26,53},{44,17},{32,37},{58,39},{24,45},{20,58},{17,43}, + {18,42},{48,46},{22,36},{33,33},{25,34},{49,40},{40,52},{36,49}, + {34,50},{50,56},{52,25},{54,22},{41,54},{56,57},{38,41},{57,38} +}; + +/***************************************************************************** + * + * motion vector prediction + * + ****************************************************************************/ + +static inline void store_mvs(AVSContext *h) { + h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 0] = h->mv[MV_FWD_X0]; + h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 1] = h->mv[MV_FWD_X1]; + h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 2] = h->mv[MV_FWD_X2]; + h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + 3] = h->mv[MV_FWD_X3]; +} + +static inline void mv_pred_direct(AVSContext *h, vector_t *pmv_fw, + vector_t *col_mv) { + vector_t *pmv_bw = pmv_fw + MV_BWD_OFFS; + int den = h->direct_den[col_mv->ref]; + int m = col_mv->x >> 31; + + pmv_fw->dist = h->dist[1]; + pmv_bw->dist = h->dist[0]; + pmv_fw->ref = 1; + pmv_bw->ref = 0; + /* scale the co-located motion vector according to its temporal span */ + pmv_fw->x = (((den+(den*col_mv->x*pmv_fw->dist^m)-m-1)>>14)^m)-m; + pmv_bw->x = m-(((den+(den*col_mv->x*pmv_bw->dist^m)-m-1)>>14)^m); + m = col_mv->y >> 31; + pmv_fw->y = (((den+(den*col_mv->y*pmv_fw->dist^m)-m-1)>>14)^m)-m; + pmv_bw->y = m-(((den+(den*col_mv->y*pmv_bw->dist^m)-m-1)>>14)^m); +} + +static inline void mv_pred_sym(AVSContext *h, vector_t *src, enum block_t size) { + vector_t *dst = src + MV_BWD_OFFS; + + /* backward mv is the scaled and negated forward mv */ + dst->x = -((src->x * h->sym_factor + 256) >> 9); + dst->y = -((src->y * h->sym_factor + 256) >> 9); + dst->ref = 0; + dst->dist = h->dist[0]; + set_mvs(dst, size); +} + +/***************************************************************************** + * + * residual data decoding + * + ****************************************************************************/ + +/** kth-order exponential golomb code */ +static inline int get_ue_code(GetBitContext *gb, int order) { + if(order) { + int ret = get_ue_golomb(gb) << order; + return ret + get_bits(gb,order); + } + return get_ue_golomb(gb); +} + +/** + * decode coefficients from one 8x8 block, dequantize, inverse transform + * and add them to sample block + * @param r pointer to 2D VLC table + * @param esc_golomb_order escape codes are k-golomb with this order k + * @param qp quantizer + * @param dst location of sample block + * @param stride line stride in frame buffer + */ +static int decode_residual_block(AVSContext *h, GetBitContext *gb, + const dec_2dvlc_t *r, int esc_golomb_order, + int qp, uint8_t *dst, int stride) { + int i, level_code, esc_code, level, run, mask; + DCTELEM level_buf[64]; + uint8_t run_buf[64]; + DCTELEM *block = h->block; + + for(i=0;i<65;i++) { + level_code = get_ue_code(gb,r->golomb_order); + if(level_code >= ESCAPE_CODE) { + run = ((level_code - ESCAPE_CODE) >> 1) + 1; + esc_code = get_ue_code(gb,esc_golomb_order); + level = esc_code + (run > r->max_run ? 1 : r->level_add[run]); + while(level > r->inc_limit) + r++; + mask = -(level_code & 1); + level = (level^mask) - mask; + } else { + level = r->rltab[level_code][0]; + if(!level) //end of block signal + break; + run = r->rltab[level_code][1]; + r += r->rltab[level_code][2]; + } + level_buf[i] = level; + run_buf[i] = run; + } + if(dequant(h,level_buf, run_buf, block, ff_cavs_dequant_mul[qp], + ff_cavs_dequant_shift[qp], i)) + return -1; + h->s.dsp.cavs_idct8_add(dst,block,stride); + return 0; +} + + +static inline void decode_residual_chroma(AVSContext *h) { + if(h->cbp & (1<<4)) + decode_residual_block(h,&h->s.gb,ff_cavs_chroma_dec,0, + ff_cavs_chroma_qp[h->qp],h->cu,h->c_stride); + if(h->cbp & (1<<5)) + decode_residual_block(h,&h->s.gb,ff_cavs_chroma_dec,0, + ff_cavs_chroma_qp[h->qp],h->cv,h->c_stride); +} + +static inline int decode_residual_inter(AVSContext *h) { + int block; + + /* get coded block pattern */ + int cbp= get_ue_golomb(&h->s.gb); + if(cbp > 63){ + av_log(h->s.avctx, AV_LOG_ERROR, "illegal inter cbp\n"); + return -1; + } + h->cbp = cbp_tab[cbp][1]; + + /* get quantizer */ + if(h->cbp && !h->qp_fixed) + h->qp = (h->qp + get_se_golomb(&h->s.gb)) & 63; + for(block=0;block<4;block++) + if(h->cbp & (1<s.gb,ff_cavs_inter_dec,0,h->qp, + h->cy + h->luma_scan[block], h->l_stride); + decode_residual_chroma(h); + + return 0; +} + +/***************************************************************************** + * + * macroblock level + * + ****************************************************************************/ + +static int decode_mb_i(AVSContext *h, int cbp_code) { + GetBitContext *gb = &h->s.gb; + int block, pred_mode_uv; + uint8_t top[18]; + uint8_t *left = NULL; + uint8_t *d; + + ff_cavs_init_mb(h); + + /* get intra prediction modes from stream */ + for(block=0;block<4;block++) { + int nA,nB,predpred; + int pos = ff_cavs_scan3x3[block]; + + nA = h->pred_mode_Y[pos-1]; + nB = h->pred_mode_Y[pos-3]; + predpred = FFMIN(nA,nB); + if(predpred == NOT_AVAIL) // if either is not available + predpred = INTRA_L_LP; + if(!get_bits1(gb)){ + int rem_mode= get_bits(gb, 2); + predpred = rem_mode + (rem_mode >= predpred); + } + h->pred_mode_Y[pos] = predpred; + } + pred_mode_uv = get_ue_golomb(gb); + if(pred_mode_uv > 6) { + av_log(h->s.avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n"); + return -1; + } + ff_cavs_modify_mb_i(h, &pred_mode_uv); + + /* get coded block pattern */ + if(h->pic_type == FF_I_TYPE) + cbp_code = get_ue_golomb(gb); + if(cbp_code > 63){ + av_log(h->s.avctx, AV_LOG_ERROR, "illegal intra cbp\n"); + return -1; + } + h->cbp = cbp_tab[cbp_code][0]; + if(h->cbp && !h->qp_fixed) + h->qp = (h->qp + get_se_golomb(gb)) & 63; //qp_delta + + /* luma intra prediction interleaved with residual decode/transform/add */ + for(block=0;block<4;block++) { + d = h->cy + h->luma_scan[block]; + ff_cavs_load_intra_pred_luma(h, top, &left, block); + h->intra_pred_l[h->pred_mode_Y[ff_cavs_scan3x3[block]]] + (d, top, left, h->l_stride); + if(h->cbp & (1<qp,d,h->l_stride); + } + + /* chroma intra prediction */ + ff_cavs_load_intra_pred_chroma(h); + h->intra_pred_c[pred_mode_uv](h->cu, &h->top_border_u[h->mbx*10], + h->left_border_u, h->c_stride); + h->intra_pred_c[pred_mode_uv](h->cv, &h->top_border_v[h->mbx*10], + h->left_border_v, h->c_stride); + + decode_residual_chroma(h); + ff_cavs_filter(h,I_8X8); + set_mv_intra(h); + return 0; +} + +static void decode_mb_p(AVSContext *h, enum mb_t mb_type) { + GetBitContext *gb = &h->s.gb; + int ref[4]; + + ff_cavs_init_mb(h); + switch(mb_type) { + case P_SKIP: + ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_PSKIP, BLK_16X16, 0); + break; + case P_16X16: + ref[0] = h->ref_flag ? 0 : get_bits1(gb); + ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16,ref[0]); + break; + case P_16X8: + ref[0] = h->ref_flag ? 0 : get_bits1(gb); + ref[2] = h->ref_flag ? 0 : get_bits1(gb); + ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, ref[0]); + ff_cavs_mv(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, ref[2]); + break; + case P_8X16: + ref[0] = h->ref_flag ? 0 : get_bits1(gb); + ref[1] = h->ref_flag ? 0 : get_bits1(gb); + ff_cavs_mv(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, ref[0]); + ff_cavs_mv(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_TOPRIGHT,BLK_8X16, ref[1]); + break; + case P_8X8: + ref[0] = h->ref_flag ? 0 : get_bits1(gb); + ref[1] = h->ref_flag ? 0 : get_bits1(gb); + ref[2] = h->ref_flag ? 0 : get_bits1(gb); + ref[3] = h->ref_flag ? 0 : get_bits1(gb); + ff_cavs_mv(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_MEDIAN, BLK_8X8, ref[0]); + ff_cavs_mv(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_MEDIAN, BLK_8X8, ref[1]); + ff_cavs_mv(h, MV_FWD_X2, MV_FWD_X1, MV_PRED_MEDIAN, BLK_8X8, ref[2]); + ff_cavs_mv(h, MV_FWD_X3, MV_FWD_X0, MV_PRED_MEDIAN, BLK_8X8, ref[3]); + } + ff_cavs_inter(h, mb_type); + set_intra_mode_default(h); + store_mvs(h); + if(mb_type != P_SKIP) + decode_residual_inter(h); + ff_cavs_filter(h,mb_type); + *h->col_type = mb_type; +} + +static void decode_mb_b(AVSContext *h, enum mb_t mb_type) { + int block; + enum sub_mb_t sub_type[4]; + int flags; + + ff_cavs_init_mb(h); + + /* reset all MVs */ + h->mv[MV_FWD_X0] = ff_cavs_dir_mv; + set_mvs(&h->mv[MV_FWD_X0], BLK_16X16); + h->mv[MV_BWD_X0] = ff_cavs_dir_mv; + set_mvs(&h->mv[MV_BWD_X0], BLK_16X16); + switch(mb_type) { + case B_SKIP: + case B_DIRECT: + if(!(*h->col_type)) { + /* intra MB at co-location, do in-plane prediction */ + ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_BSKIP, BLK_16X16, 1); + ff_cavs_mv(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_BSKIP, BLK_16X16, 0); + } else + /* direct prediction from co-located P MB, block-wise */ + for(block=0;block<4;block++) + mv_pred_direct(h,&h->mv[mv_scan[block]], + &h->col_mv[(h->mby*h->mb_width+h->mbx)*4 + block]); + break; + case B_FWD_16X16: + ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1); + break; + case B_SYM_16X16: + ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1); + mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X16); + break; + case B_BWD_16X16: + ff_cavs_mv(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_MEDIAN, BLK_16X16, 0); + break; + case B_8X8: + for(block=0;block<4;block++) + sub_type[block] = get_bits(&h->s.gb,2); + for(block=0;block<4;block++) { + switch(sub_type[block]) { + case B_SUB_DIRECT: + if(!(*h->col_type)) { + /* intra MB at co-location, do in-plane prediction */ + ff_cavs_mv(h, mv_scan[block], mv_scan[block]-3, + MV_PRED_BSKIP, BLK_8X8, 1); + ff_cavs_mv(h, mv_scan[block]+MV_BWD_OFFS, + mv_scan[block]-3+MV_BWD_OFFS, + MV_PRED_BSKIP, BLK_8X8, 0); + } else + mv_pred_direct(h,&h->mv[mv_scan[block]], + &h->col_mv[(h->mby*h->mb_width + h->mbx)*4 + block]); + break; + case B_SUB_FWD: + ff_cavs_mv(h, mv_scan[block], mv_scan[block]-3, + MV_PRED_MEDIAN, BLK_8X8, 1); + break; + case B_SUB_SYM: + ff_cavs_mv(h, mv_scan[block], mv_scan[block]-3, + MV_PRED_MEDIAN, BLK_8X8, 1); + mv_pred_sym(h, &h->mv[mv_scan[block]], BLK_8X8); + break; + } + } + for(block=0;block<4;block++) { + if(sub_type[block] == B_SUB_BWD) + ff_cavs_mv(h, mv_scan[block]+MV_BWD_OFFS, + mv_scan[block]+MV_BWD_OFFS-3, + MV_PRED_MEDIAN, BLK_8X8, 0); + } + break; + default: + assert((mb_type > B_SYM_16X16) && (mb_type < B_8X8)); + flags = ff_cavs_partition_flags[mb_type]; + if(mb_type & 1) { /* 16x8 macroblock types */ + if(flags & FWD0) + ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, 1); + if(flags & SYM0) + mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X8); + if(flags & FWD1) + ff_cavs_mv(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, 1); + if(flags & SYM1) + mv_pred_sym(h, &h->mv[MV_FWD_X2], BLK_16X8); + if(flags & BWD0) + ff_cavs_mv(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_TOP, BLK_16X8, 0); + if(flags & BWD1) + ff_cavs_mv(h, MV_BWD_X2, MV_BWD_A1, MV_PRED_LEFT, BLK_16X8, 0); + } else { /* 8x16 macroblock types */ + if(flags & FWD0) + ff_cavs_mv(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, 1); + if(flags & SYM0) + mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_8X16); + if(flags & FWD1) + ff_cavs_mv(h,MV_FWD_X1,MV_FWD_C2,MV_PRED_TOPRIGHT,BLK_8X16,1); + if(flags & SYM1) + mv_pred_sym(h, &h->mv[MV_FWD_X1], BLK_8X16); + if(flags & BWD0) + ff_cavs_mv(h, MV_BWD_X0, MV_BWD_B3, MV_PRED_LEFT, BLK_8X16, 0); + if(flags & BWD1) + ff_cavs_mv(h,MV_BWD_X1,MV_BWD_C2,MV_PRED_TOPRIGHT,BLK_8X16,0); + } + } + ff_cavs_inter(h, mb_type); + set_intra_mode_default(h); + if(mb_type != B_SKIP) + decode_residual_inter(h); + ff_cavs_filter(h,mb_type); +} + +/***************************************************************************** + * + * slice level + * + ****************************************************************************/ + +static inline int decode_slice_header(AVSContext *h, GetBitContext *gb) { + if(h->stc > 0xAF) + av_log(h->s.avctx, AV_LOG_ERROR, "unexpected start code 0x%02x\n", h->stc); + h->mby = h->stc; + if((h->mby == 0) && (!h->qp_fixed)){ + h->qp_fixed = get_bits1(gb); + h->qp = get_bits(gb,6); + } + /* inter frame or second slice can have weighting params */ + if((h->pic_type != FF_I_TYPE) || (!h->pic_structure && h->mby >= h->mb_width/2)) + if(get_bits1(gb)) { //slice_weighting_flag + av_log(h->s.avctx, AV_LOG_ERROR, + "weighted prediction not yet supported\n"); + } + return 0; +} + +static inline void check_for_slice(AVSContext *h) { + GetBitContext *gb = &h->s.gb; + int align; + align = (-get_bits_count(gb)) & 7; + if((show_bits_long(gb,24+align) & 0xFFFFFF) == 0x000001) { + skip_bits_long(gb,24+align); + h->stc = get_bits(gb,8); + decode_slice_header(h,gb); + } +} + +/***************************************************************************** + * + * frame level + * + ****************************************************************************/ + +static int decode_pic(AVSContext *h) { + MpegEncContext *s = &h->s; + int skip_count; + enum mb_t mb_type; + + if (!s->context_initialized) { + s->avctx->idct_algo = FF_IDCT_CAVS; + if (MPV_common_init(s) < 0) + return -1; + ff_init_scantable(s->dsp.idct_permutation,&h->scantable,ff_zigzag_direct); + } + skip_bits(&s->gb,16);//bbv_dwlay + if(h->stc == PIC_PB_START_CODE) { + h->pic_type = get_bits(&s->gb,2) + FF_I_TYPE; + if(h->pic_type > FF_B_TYPE) { + av_log(s->avctx, AV_LOG_ERROR, "illegal picture type\n"); + return -1; + } + /* make sure we have the reference frames we need */ + if(!h->DPB[0].data[0] || + (!h->DPB[1].data[0] && h->pic_type == FF_B_TYPE)) + return -1; + } else { + h->pic_type = FF_I_TYPE; + if(get_bits1(&s->gb)) + skip_bits(&s->gb,16);//time_code + } + /* release last B frame */ + if(h->picture.data[0]) + s->avctx->release_buffer(s->avctx, (AVFrame *)&h->picture); + + s->avctx->get_buffer(s->avctx, (AVFrame *)&h->picture); + ff_cavs_init_pic(h); + h->picture.poc = get_bits(&s->gb,8)*2; + + /* get temporal distances and MV scaling factors */ + if(h->pic_type != FF_B_TYPE) { + h->dist[0] = (h->picture.poc - h->DPB[0].poc + 512) % 512; + } else { + h->dist[0] = (h->DPB[0].poc - h->picture.poc + 512) % 512; + } + h->dist[1] = (h->picture.poc - h->DPB[1].poc + 512) % 512; + h->scale_den[0] = h->dist[0] ? 512/h->dist[0] : 0; + h->scale_den[1] = h->dist[1] ? 512/h->dist[1] : 0; + if(h->pic_type == FF_B_TYPE) { + h->sym_factor = h->dist[0]*h->scale_den[1]; + } else { + h->direct_den[0] = h->dist[0] ? 16384/h->dist[0] : 0; + h->direct_den[1] = h->dist[1] ? 16384/h->dist[1] : 0; + } + + if(s->low_delay) + get_ue_golomb(&s->gb); //bbv_check_times + h->progressive = get_bits1(&s->gb); + if(h->progressive) + h->pic_structure = 1; + else if(!(h->pic_structure = get_bits1(&s->gb) && (h->stc == PIC_PB_START_CODE)) ) + skip_bits1(&s->gb); //advanced_pred_mode_disable + skip_bits1(&s->gb); //top_field_first + skip_bits1(&s->gb); //repeat_first_field + h->qp_fixed = get_bits1(&s->gb); + h->qp = get_bits(&s->gb,6); + if(h->pic_type == FF_I_TYPE) { + if(!h->progressive && !h->pic_structure) + skip_bits1(&s->gb);//what is this? + skip_bits(&s->gb,4); //reserved bits + } else { + if(!(h->pic_type == FF_B_TYPE && h->pic_structure == 1)) + h->ref_flag = get_bits1(&s->gb); + skip_bits(&s->gb,4); //reserved bits + h->skip_mode_flag = get_bits1(&s->gb); + } + h->loop_filter_disable = get_bits1(&s->gb); + if(!h->loop_filter_disable && get_bits1(&s->gb)) { + h->alpha_offset = get_se_golomb(&s->gb); + h->beta_offset = get_se_golomb(&s->gb); + } else { + h->alpha_offset = h->beta_offset = 0; + } + check_for_slice(h); + if(h->pic_type == FF_I_TYPE) { + do { + decode_mb_i(h, 0); + } while(ff_cavs_next_mb(h)); + } else if(h->pic_type == FF_P_TYPE) { + do { + if(h->skip_mode_flag) { + skip_count = get_ue_golomb(&s->gb); + while(skip_count--) { + decode_mb_p(h,P_SKIP); + if(!ff_cavs_next_mb(h)) + goto done; + } + mb_type = get_ue_golomb(&s->gb) + P_16X16; + } else + mb_type = get_ue_golomb(&s->gb) + P_SKIP; + if(mb_type > P_8X8) { + decode_mb_i(h, mb_type - P_8X8 - 1); + } else + decode_mb_p(h,mb_type); + } while(ff_cavs_next_mb(h)); + } else { /* FF_B_TYPE */ + do { + if(h->skip_mode_flag) { + skip_count = get_ue_golomb(&s->gb); + while(skip_count--) { + decode_mb_b(h,B_SKIP); + if(!ff_cavs_next_mb(h)) + goto done; + } + mb_type = get_ue_golomb(&s->gb) + B_DIRECT; + } else + mb_type = get_ue_golomb(&s->gb) + B_SKIP; + if(mb_type > B_8X8) { + decode_mb_i(h, mb_type - B_8X8 - 1); + } else + decode_mb_b(h,mb_type); + } while(ff_cavs_next_mb(h)); + } + done: + if(h->pic_type != FF_B_TYPE) { + if(h->DPB[1].data[0]) + s->avctx->release_buffer(s->avctx, (AVFrame *)&h->DPB[1]); + memcpy(&h->DPB[1], &h->DPB[0], sizeof(Picture)); + memcpy(&h->DPB[0], &h->picture, sizeof(Picture)); + memset(&h->picture,0,sizeof(Picture)); + } + return 0; +} + +/***************************************************************************** + * + * headers and interface + * + ****************************************************************************/ + +static int decode_seq_header(AVSContext *h) { + MpegEncContext *s = &h->s; + int frame_rate_code; + + h->profile = get_bits(&s->gb,8); + h->level = get_bits(&s->gb,8); + skip_bits1(&s->gb); //progressive sequence + s->width = get_bits(&s->gb,14); + s->height = get_bits(&s->gb,14); + skip_bits(&s->gb,2); //chroma format + skip_bits(&s->gb,3); //sample_precision + h->aspect_ratio = get_bits(&s->gb,4); + frame_rate_code = get_bits(&s->gb,4); + skip_bits(&s->gb,18);//bit_rate_lower + skip_bits1(&s->gb); //marker_bit + skip_bits(&s->gb,12);//bit_rate_upper + s->low_delay = get_bits1(&s->gb); + h->mb_width = (s->width + 15) >> 4; + h->mb_height = (s->height + 15) >> 4; + h->s.avctx->time_base.den = ff_frame_rate_tab[frame_rate_code].num; + h->s.avctx->time_base.num = ff_frame_rate_tab[frame_rate_code].den; + h->s.avctx->width = s->width; + h->s.avctx->height = s->height; + if(!h->top_qp) + ff_cavs_init_top_lines(h); + return 0; +} + +static void cavs_flush(AVCodecContext * avctx) { + AVSContext *h = avctx->priv_data; + h->got_keyframe = 0; +} + +static int cavs_decode_frame(AVCodecContext * avctx,void *data, int *data_size, + const uint8_t * buf, int buf_size) { + AVSContext *h = avctx->priv_data; + MpegEncContext *s = &h->s; + int input_size; + const uint8_t *buf_end; + const uint8_t *buf_ptr; + AVFrame *picture = data; + uint32_t stc = -1; + + s->avctx = avctx; + + if (buf_size == 0) { + if(!s->low_delay && h->DPB[0].data[0]) { + *data_size = sizeof(AVPicture); + *picture = *(AVFrame *) &h->DPB[0]; + } + return 0; + } + + buf_ptr = buf; + buf_end = buf + buf_size; + for(;;) { + buf_ptr = ff_find_start_code(buf_ptr,buf_end, &stc); + if(stc & 0xFFFFFE00) + return FFMAX(0, buf_ptr - buf - s->parse_context.last_index); + input_size = (buf_end - buf_ptr)*8; + switch(stc) { + case CAVS_START_CODE: + init_get_bits(&s->gb, buf_ptr, input_size); + decode_seq_header(h); + break; + case PIC_I_START_CODE: + if(!h->got_keyframe) { + if(h->DPB[0].data[0]) + avctx->release_buffer(avctx, (AVFrame *)&h->DPB[0]); + if(h->DPB[1].data[0]) + avctx->release_buffer(avctx, (AVFrame *)&h->DPB[1]); + h->got_keyframe = 1; + } + case PIC_PB_START_CODE: + *data_size = 0; + if(!h->got_keyframe) + break; + init_get_bits(&s->gb, buf_ptr, input_size); + h->stc = stc; + if(decode_pic(h)) + break; + *data_size = sizeof(AVPicture); + if(h->pic_type != FF_B_TYPE) { + if(h->DPB[1].data[0]) { + *picture = *(AVFrame *) &h->DPB[1]; + } else { + *data_size = 0; + } + } else + *picture = *(AVFrame *) &h->picture; + break; + case EXT_START_CODE: + //mpeg_decode_extension(avctx,buf_ptr, input_size); + break; + case USER_START_CODE: + //mpeg_decode_user_data(avctx,buf_ptr, input_size); + break; + default: + if (stc >= SLICE_MIN_START_CODE && + stc <= SLICE_MAX_START_CODE) { + init_get_bits(&s->gb, buf_ptr, input_size); + decode_slice_header(h, &s->gb); + } + break; + } + } +} + +AVCodec cavs_decoder = { + "cavs", + CODEC_TYPE_VIDEO, + CODEC_ID_CAVS, + sizeof(AVSContext), + ff_cavs_init, + NULL, + ff_cavs_end, + cavs_decode_frame, + CODEC_CAP_DR1 | CODEC_CAP_DELAY, + .flush= cavs_flush, +}; diff --git a/contrib/ffmpeg/libavcodec/cavsdsp.c b/contrib/ffmpeg/libavcodec/cavsdsp.c index 55ecaae0a..fd744cc80 100644 --- a/contrib/ffmpeg/libavcodec/cavsdsp.c +++ b/contrib/ffmpeg/libavcodec/cavsdsp.c @@ -19,7 +19,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include diff --git a/contrib/ffmpeg/libavcodec/cinepak.c b/contrib/ffmpeg/libavcodec/cinepak.c index db0519b5d..66ecd3fc5 100644 --- a/contrib/ffmpeg/libavcodec/cinepak.c +++ b/contrib/ffmpeg/libavcodec/cinepak.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -35,7 +34,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include "dsputil.h" @@ -61,7 +59,7 @@ typedef struct CinepakContext { DSPContext dsp; AVFrame frame; - unsigned char *data; + const unsigned char *data; int size; int width, height; @@ -74,9 +72,9 @@ typedef struct CinepakContext { } CinepakContext; static void cinepak_decode_codebook (cvid_codebook_t *codebook, - int chunk_id, int size, uint8_t *data) + int chunk_id, int size, const uint8_t *data) { - uint8_t *eod = (data + size); + const uint8_t *eod = (data + size); uint32_t flag, mask; int i, n; @@ -123,9 +121,9 @@ static void cinepak_decode_codebook (cvid_codebook_t *codebook, } static int cinepak_decode_vectors (CinepakContext *s, cvid_strip_t *strip, - int chunk_id, int size, uint8_t *data) + int chunk_id, int size, const uint8_t *data) { - uint8_t *eod = (data + size); + const uint8_t *eod = (data + size); uint32_t flag, mask; cvid_codebook_t *codebook; unsigned int x, y; @@ -266,9 +264,9 @@ static int cinepak_decode_vectors (CinepakContext *s, cvid_strip_t *strip, } static int cinepak_decode_strip (CinepakContext *s, - cvid_strip_t *strip, uint8_t *data, int size) + cvid_strip_t *strip, const uint8_t *data, int size) { - uint8_t *eod = (data + size); + const uint8_t *eod = (data + size); int chunk_id, chunk_size; /* coordinate sanity checks */ @@ -319,7 +317,7 @@ static int cinepak_decode_strip (CinepakContext *s, static int cinepak_decode (CinepakContext *s) { - uint8_t *eod = (s->data + s->size); + const uint8_t *eod = (s->data + s->size); int i, result, strip_size, frame_flags, num_strips; int y0 = 0; int encoded_buf_size; @@ -391,7 +389,7 @@ static int cinepak_decode (CinepakContext *s) static int cinepak_decode_init(AVCodecContext *avctx) { - CinepakContext *s = (CinepakContext *)avctx->priv_data; + CinepakContext *s = avctx->priv_data; s->avctx = avctx; s->width = (avctx->width + 3) & ~3; @@ -407,7 +405,6 @@ static int cinepak_decode_init(AVCodecContext *avctx) avctx->pix_fmt = PIX_FMT_PAL8; } - avctx->has_b_frames = 0; dsputil_init(&s->dsp, avctx); s->frame.data[0] = NULL; @@ -417,9 +414,9 @@ static int cinepak_decode_init(AVCodecContext *avctx) static int cinepak_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { - CinepakContext *s = (CinepakContext *)avctx->priv_data; + CinepakContext *s = avctx->priv_data; s->data = buf; s->size = buf_size; @@ -452,7 +449,7 @@ static int cinepak_decode_frame(AVCodecContext *avctx, static int cinepak_decode_end(AVCodecContext *avctx) { - CinepakContext *s = (CinepakContext *)avctx->priv_data; + CinepakContext *s = avctx->priv_data; if (s->frame.data[0]) avctx->release_buffer(avctx, &s->frame); diff --git a/contrib/ffmpeg/libavcodec/cljr.c b/contrib/ffmpeg/libavcodec/cljr.c index 44810f5cf..6b76411ac 100644 --- a/contrib/ffmpeg/libavcodec/cljr.c +++ b/contrib/ffmpeg/libavcodec/cljr.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -38,7 +37,7 @@ typedef struct CLJRContext{ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { CLJRContext * const a = avctx->priv_data; AVFrame *picture = data; diff --git a/contrib/ffmpeg/libavcodec/colorspace.h b/contrib/ffmpeg/libavcodec/colorspace.h new file mode 100644 index 000000000..9d89d6daa --- /dev/null +++ b/contrib/ffmpeg/libavcodec/colorspace.h @@ -0,0 +1,111 @@ +/* + * Colorspace conversion defines + * Copyright (c) 2001, 2002, 2003 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file colorspace.h + * Various defines for YUV<->RGB conversion + */ + +#ifndef FFMPEG_COLORSPACE_H +#define FFMPEG_COLORSPACE_H + +#define SCALEBITS 10 +#define ONE_HALF (1 << (SCALEBITS - 1)) +#define FIX(x) ((int) ((x) * (1<> SCALEBITS];\ + g = cm[(y + g_add) >> SCALEBITS];\ + b = cm[(y + b_add) >> SCALEBITS];\ +} + +#define YUV_TO_RGB1(cb1, cr1)\ +{\ + cb = (cb1) - 128;\ + cr = (cr1) - 128;\ + r_add = FIX(1.40200) * cr + ONE_HALF;\ + g_add = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;\ + b_add = FIX(1.77200) * cb + ONE_HALF;\ +} + +#define YUV_TO_RGB2(r, g, b, y1)\ +{\ + y = (y1) << SCALEBITS;\ + r = cm[(y + r_add) >> SCALEBITS];\ + g = cm[(y + g_add) >> SCALEBITS];\ + b = cm[(y + b_add) >> SCALEBITS];\ +} + +#define Y_CCIR_TO_JPEG(y)\ + cm[((y) * FIX(255.0/219.0) + (ONE_HALF - 16 * FIX(255.0/219.0))) >> SCALEBITS] + +#define Y_JPEG_TO_CCIR(y)\ + (((y) * FIX(219.0/255.0) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS) + +#define C_CCIR_TO_JPEG(y)\ + cm[(((y) - 128) * FIX(127.0/112.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS] + +/* NOTE: the clamp is really necessary! */ +static inline int C_JPEG_TO_CCIR(int y) { + y = (((y - 128) * FIX(112.0/127.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS); + if (y < 16) + y = 16; + return y; +} + + +#define RGB_TO_Y(r, g, b) \ +((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \ + FIX(0.11400) * (b) + ONE_HALF) >> SCALEBITS) + +#define RGB_TO_U(r1, g1, b1, shift)\ +(((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \ + FIX(0.50000) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) + +#define RGB_TO_V(r1, g1, b1, shift)\ +(((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \ + FIX(0.08131) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) + +#define RGB_TO_Y_CCIR(r, g, b) \ +((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \ + FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS) + +#define RGB_TO_U_CCIR(r1, g1, b1, shift)\ +(((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \ + FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) + +#define RGB_TO_V_CCIR(r1, g1, b1, shift)\ +(((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \ + FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) + +#endif /* FFMPEG_COLORSPACE_H */ diff --git a/contrib/ffmpeg/libavcodec/cook.c b/contrib/ffmpeg/libavcodec/cook.c index 32b1081cc..8fa14e31c 100644 --- a/contrib/ffmpeg/libavcodec/cook.c +++ b/contrib/ffmpeg/libavcodec/cook.c @@ -18,12 +18,11 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** * @file cook.c - * Cook compatible decoder. + * Cook compatible decoder. Bastardization of the G.722.1 standard. * This decoder handles RealNetworks, RealAudio G2 data. * Cook is identified by the codec name cook in RM files. * @@ -50,7 +49,6 @@ #include "avcodec.h" #include "bitstream.h" #include "dsputil.h" -#include "common.h" #include "bytestream.h" #include "random.h" @@ -70,7 +68,29 @@ typedef struct { int *previous; } cook_gains; -typedef struct { +typedef struct cook { + /* + * The following 5 functions provide the lowlevel arithmetic on + * the internal audio buffers. + */ + void (* scalar_dequant)(struct cook *q, int index, int quant_index, + int* subband_coef_index, int* subband_coef_sign, + float* mlt_p); + + void (* decouple) (struct cook *q, + int subband, + float f1, float f2, + float *decode_buffer, + float *mlt_buffer1, float *mlt_buffer2); + + void (* imlt_window) (struct cook *q, float *buffer1, + cook_gains *gains_ptr, float *previous_buffer); + + void (* interpolate) (struct cook *q, float* buffer, + int gain_index, int gain_index_next); + + void (* saturate_output) (struct cook *q, int chan, int16_t *out); + GetBitContext gb; /* stream data */ int nb_channels; @@ -123,6 +143,9 @@ typedef struct { float mono_previous_buffer2[1024]; float decode_buffer_1[1024]; float decode_buffer_2[1024]; + float decode_buffer_0[1060]; /* static allocation for joint decode */ + + const float *cplscales[5]; } COOKContext; /* debug functions */ @@ -195,19 +218,19 @@ static int init_cook_vlc_tables(COOKContext *q) { result = 0; for (i=0 ; i<13 ; i++) { - result &= init_vlc (&q->envelope_quant_index[i], 9, 24, + result |= init_vlc (&q->envelope_quant_index[i], 9, 24, envelope_quant_index_huffbits[i], 1, 1, envelope_quant_index_huffcodes[i], 2, 2, 0); } av_log(NULL,AV_LOG_DEBUG,"sqvh VLC init\n"); for (i=0 ; i<7 ; i++) { - result &= init_vlc (&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i], + result |= init_vlc (&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i], cvh_huffbits[i], 1, 1, cvh_huffcodes[i], 2, 2, 0); } if (q->nb_channels==2 && q->joint_stereo==1){ - result &= init_vlc (&q->ccpl, 6, (1<js_vlc_bits)-1, + result |= init_vlc (&q->ccpl, 6, (1<js_vlc_bits)-1, ccpl_huffbits[q->js_vlc_bits-2], 1, 1, ccpl_huffcodes[q->js_vlc_bits-2], 2, 2, 0); av_log(NULL,AV_LOG_DEBUG,"Joint-stereo VLC used.\n"); @@ -241,6 +264,18 @@ static int init_cook_mlt(COOKContext *q) { return 0; } +static const float *maybe_reformat_buffer32 (COOKContext *q, const float *ptr, int n) +{ + if (1) + return ptr; +} + +static void init_cplscales_table (COOKContext *q) { + int i; + for (i=0;i<5;i++) + q->cplscales[i] = maybe_reformat_buffer32 (q, cplscales[i], (1<<(i+2))-1); +} + /*************** init functions end ***********/ /** @@ -248,7 +283,7 @@ static int init_cook_mlt(COOKContext *q) { * Why? No idea, some checksum/error detection method maybe. * * Out buffer size: extra bytes are needed to cope with - * padding/missalignment. + * padding/misalignment. * Subpackets passed to the decoder can contain two, consecutive * half-subpackets, of identical but arbitrary size. * 1234 1234 1234 1234 extraA extraB @@ -266,10 +301,10 @@ static int init_cook_mlt(COOKContext *q) { #define DECODE_BYTES_PAD1(bytes) (3 - ((bytes)+3) % 4) #define DECODE_BYTES_PAD2(bytes) ((bytes) % 4 + DECODE_BYTES_PAD1(2 * (bytes))) -static inline int decode_bytes(uint8_t* inbuffer, uint8_t* out, int bytes){ +static inline int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes){ int i, off; uint32_t c; - uint32_t* buf; + const uint32_t* buf; uint32_t* obuf = (uint32_t*) out; /* FIXME: 64 bit platforms would be able to do 64 bits at a time. * I'm too lazy though, should be something like @@ -278,7 +313,7 @@ static inline int decode_bytes(uint8_t* inbuffer, uint8_t* out, int bytes){ * Buffer alignment needs to be checked. */ off = (int)((long)inbuffer & 3); - buf = (uint32_t*) (inbuffer - off); + buf = (const uint32_t*) (inbuffer - off); c = be2me_32((0x37c511f2 >> (off*8)) | (0x37c511f2 << (32-(off*8)))); bytes += 3 + off; for (i = 0; i < bytes/4; i++) @@ -353,9 +388,7 @@ static void decode_gain_info(GetBitContext *gb, int *gaininfo) static void decode_envelope(COOKContext *q, int* quant_index_table) { int i,j, vlc_index; - int bitbias; - bitbias = get_bits_count(&q->gb); quant_index_table[0]= get_bits(&q->gb,6) - 6; //This is used later in categorize for (i=1 ; i < q->total_subbands ; i++){ @@ -385,15 +418,13 @@ static void decode_envelope(COOKContext *q, int* quant_index_table) { static void categorize(COOKContext *q, int* quant_index_table, int* category, int* category_index){ - int exp_idx, bias, tmpbias, bits_left, num_bits, index, v, i, j; + int exp_idx, bias, tmpbias1, tmpbias2, bits_left, num_bits, index, v, i, j; int exp_index2[102]; int exp_index1[102]; - int tmp_categorize_array1[128]; - int tmp_categorize_array1_idx=0; - int tmp_categorize_array2[128]; - int tmp_categorize_array2_idx=0; - int category_index_size=0; + int tmp_categorize_array[128*2]; + int tmp_categorize_array1_idx=q->numvector_size; + int tmp_categorize_array2_idx=q->numvector_size; bits_left = q->bits_per_subpacket - get_bits_count(&q->gb); @@ -405,8 +436,7 @@ static void categorize(COOKContext *q, int* quant_index_table, memset(&exp_index1,0,102*sizeof(int)); memset(&exp_index2,0,102*sizeof(int)); - memset(&tmp_categorize_array1,0,128*sizeof(int)); - memset(&tmp_categorize_array2,0,128*sizeof(int)); + memset(&tmp_categorize_array,0,128*2*sizeof(int)); bias=-32; @@ -415,12 +445,7 @@ static void categorize(COOKContext *q, int* quant_index_table, num_bits = 0; index = 0; for (j=q->total_subbands ; j>0 ; j--){ - exp_idx = (i - quant_index_table[index] + bias) / 2; - if (exp_idx<0){ - exp_idx=0; - } else if(exp_idx >7) { - exp_idx=7; - } + exp_idx = av_clip((i - quant_index_table[index] + bias) / 2, 0, 7); index++; num_bits+=expbits_tab[exp_idx]; } @@ -432,25 +457,20 @@ static void categorize(COOKContext *q, int* quant_index_table, /* Calculate total number of bits. */ num_bits=0; for (i=0 ; itotal_subbands ; i++) { - exp_idx = (bias - quant_index_table[i]) / 2; - if (exp_idx<0) { - exp_idx=0; - } else if(exp_idx >7) { - exp_idx=7; - } + exp_idx = av_clip((bias - quant_index_table[i]) / 2, 0, 7); num_bits += expbits_tab[exp_idx]; exp_index1[i] = exp_idx; exp_index2[i] = exp_idx; } - tmpbias = bias = num_bits; + tmpbias1 = tmpbias2 = num_bits; for (j = 1 ; j < q->numvector_size ; j++) { - if (tmpbias + bias > 2*bits_left) { /* ---> */ + if (tmpbias1 + tmpbias2 > 2*bits_left) { /* ---> */ int max = -999999; index=-1; for (i=0 ; itotal_subbands ; i++){ if (exp_index1[i] < 7) { - v = (-2*exp_index1[i]) - quant_index_table[i] - 32; + v = (-2*exp_index1[i]) - quant_index_table[i] + bias; if ( v >= max) { max = v; index = i; @@ -458,16 +478,16 @@ static void categorize(COOKContext *q, int* quant_index_table, } } if(index==-1)break; - tmp_categorize_array1[tmp_categorize_array1_idx++] = index; - tmpbias -= expbits_tab[exp_index1[index]] - - expbits_tab[exp_index1[index]+1]; + tmp_categorize_array[tmp_categorize_array1_idx++] = index; + tmpbias1 -= expbits_tab[exp_index1[index]] - + expbits_tab[exp_index1[index]+1]; ++exp_index1[index]; } else { /* <--- */ int min = 999999; index=-1; for (i=0 ; itotal_subbands ; i++){ if(exp_index2[i] > 0){ - v = (-2*exp_index2[i])-quant_index_table[i]; + v = (-2*exp_index2[i])-quant_index_table[i]+bias; if ( v < min) { min = v; index = i; @@ -475,9 +495,9 @@ static void categorize(COOKContext *q, int* quant_index_table, } } if(index == -1)break; - tmp_categorize_array2[tmp_categorize_array2_idx++] = index; - tmpbias -= expbits_tab[exp_index2[index]] - - expbits_tab[exp_index2[index]-1]; + tmp_categorize_array[--tmp_categorize_array2_idx] = index; + tmpbias2 -= expbits_tab[exp_index2[index]] - + expbits_tab[exp_index2[index]-1]; --exp_index2[index]; } } @@ -485,17 +505,8 @@ static void categorize(COOKContext *q, int* quant_index_table, for(i=0 ; itotal_subbands ; i++) category[i] = exp_index2[i]; - /* Concatenate the two arrays. */ - for(i=tmp_categorize_array2_idx-1 ; i >= 0; i--) - category_index[category_index_size++] = tmp_categorize_array2[i]; - - for(i=0;inumvector_size;i++) - category_index[i]=0; + for(i=0 ; inumvector_size-1 ; i++) + category_index[i] = tmp_categorize_array[tmp_categorize_array2_idx++]; } @@ -508,7 +519,7 @@ static void categorize(COOKContext *q, int* quant_index_table, * @param category_index pointer to the category_index array */ -static void inline expand_category(COOKContext *q, int* category, +static inline void expand_category(COOKContext *q, int* category, int* category_index){ int i; for(i=0 ; inum_vectors ; i++){ @@ -527,7 +538,7 @@ static void inline expand_category(COOKContext *q, int* category, * @param mlt_p pointer into the mlt buffer */ -static void scalar_dequant(COOKContext *q, int index, int quant_index, +static void scalar_dequant_float(COOKContext *q, int index, int quant_index, int* subband_coef_index, int* subband_coef_sign, float* mlt_p){ int i; @@ -558,15 +569,11 @@ static int unpack_SQVH(COOKContext *q, int category, int* subband_coef_index, int* subband_coef_sign) { int i,j; int vlc, vd ,tmp, result; - int ub; - int cb; vd = vd_tab[category]; result = 0; for(i=0 ; igb); vlc = get_vlc2(&q->gb, q->sqvh[category].table, q->sqvh[category].bits, 3); - cb = get_bits_count(&q->gb); if (q->bits_per_subpacket < get_bits_count(&q->gb)){ vlc = 0; result = 1; @@ -626,9 +633,9 @@ static void decode_vectors(COOKContext* q, int* category, memset(subband_coef_index, 0, sizeof(subband_coef_index)); memset(subband_coef_sign, 0, sizeof(subband_coef_sign)); } - scalar_dequant(q, index, quant_index_table[band], - subband_coef_index, subband_coef_sign, - &mlt_buffer[band * 20]); + q->scalar_dequant(q, index, quant_index_table[band], + subband_coef_index, subband_coef_sign, + &mlt_buffer[band * SUBBAND_SIZE]); } if(q->total_subbands*SUBBAND_SIZE >= q->samples_per_channel){ @@ -641,8 +648,7 @@ static void decode_vectors(COOKContext* q, int* category, * function for decoding mono data * * @param q pointer to the COOKContext - * @param mlt_buffer1 pointer to left channel mlt coefficients - * @param mlt_buffer2 pointer to right channel mlt coefficients + * @param mlt_buffer pointer to mlt coefficients */ static void mono_decode(COOKContext *q, float* mlt_buffer) { @@ -671,7 +677,7 @@ static void mono_decode(COOKContext *q, float* mlt_buffer) { * @param gain_index_next index for the next block multiplier */ -static void interpolate(COOKContext *q, float* buffer, +static void interpolate_float(COOKContext *q, float* buffer, int gain_index, int gain_index_next){ int i; float fc1, fc2; @@ -692,6 +698,32 @@ static void interpolate(COOKContext *q, float* buffer, } } +/** + * Apply transform window, overlap buffers. + * + * @param q pointer to the COOKContext + * @param inbuffer pointer to the mltcoefficients + * @param gains_ptr current and previous gains + * @param previous_buffer pointer to the previous buffer to be used for overlapping + */ + +static void imlt_window_float (COOKContext *q, float *buffer1, + cook_gains *gains_ptr, float *previous_buffer) +{ + const float fc = q->pow2tab[gains_ptr->previous[0] + 63]; + int i; + /* The weird thing here, is that the two halves of the time domain + * buffer are swapped. Also, the newest data, that we save away for + * next frame, has the wrong sign. Hence the subtraction below. + * Almost sounds like a complex conjugate/reverse data/FFT effect. + */ + + /* Apply window and overlap */ + for(i = 0; i < q->samples_per_channel; i++){ + buffer1[i] = buffer1[i] * fc * q->mlt_window[i] - + previous_buffer[i] * q->mlt_window[q->samples_per_channel - 1 - i]; + } +} /** * The modulated lapped transform, this takes transform coefficients @@ -708,7 +740,6 @@ static void interpolate(COOKContext *q, float* buffer, static void imlt_gain(COOKContext *q, float *inbuffer, cook_gains *gains_ptr, float* previous_buffer) { - const float fc = q->pow2tab[gains_ptr->previous[0] + 63]; float *buffer0 = q->mono_mdct_output; float *buffer1 = q->mono_mdct_output + q->samples_per_channel; int i; @@ -717,23 +748,13 @@ static void imlt_gain(COOKContext *q, float *inbuffer, q->mdct_ctx.fft.imdct_calc(&q->mdct_ctx, q->mono_mdct_output, inbuffer, q->mdct_tmp); - /* The weird thing here, is that the two halves of the time domain - * buffer are swapped. Also, the newest data, that we save away for - * next frame, has the wrong sign. Hence the subtraction below. - * Almost sounds like a complex conjugate/reverse data/FFT effect. - */ - - /* Apply window and overlap */ - for(i = 0; i < q->samples_per_channel; i++){ - buffer1[i] = buffer1[i] * fc * q->mlt_window[i] - - previous_buffer[i] * q->mlt_window[q->samples_per_channel - 1 - i]; - } + q->imlt_window (q, buffer1, gains_ptr, previous_buffer); /* Apply gain profile */ for (i = 0; i < 8; i++) { if (gains_ptr->now[i] || gains_ptr->now[i + 1]) - interpolate(q, &buffer1[q->gain_size_factor * i], - gains_ptr->now[i], gains_ptr->now[i + 1]); + q->interpolate(q, &buffer1[q->gain_size_factor * i], + gains_ptr->now[i], gains_ptr->now[i + 1]); } /* Save away the current to be previous block. */ @@ -771,6 +792,30 @@ static void decouple_info(COOKContext *q, int* decouple_tab){ return; } +/* + * function decouples a pair of signals from a single signal via multiplication. + * + * @param q pointer to the COOKContext + * @param subband index of the current subband + * @param f1 multiplier for channel 1 extraction + * @param f2 multiplier for channel 2 extraction + * @param decode_buffer input buffer + * @param mlt_buffer1 pointer to left channel mlt coefficients + * @param mlt_buffer2 pointer to right channel mlt coefficients + */ +static void decouple_float (COOKContext *q, + int subband, + float f1, float f2, + float *decode_buffer, + float *mlt_buffer1, float *mlt_buffer2) +{ + int j, tmp_idx; + for (j=0 ; jjs_subband_start + subband)*SUBBAND_SIZE)+j; + mlt_buffer1[SUBBAND_SIZE*subband + j] = f1 * decode_buffer[tmp_idx]; + mlt_buffer2[SUBBAND_SIZE*subband + j] = f2 * decode_buffer[tmp_idx]; + } +} /** * function for decoding joint stereo data @@ -784,10 +829,10 @@ static void joint_decode(COOKContext *q, float* mlt_buffer1, float* mlt_buffer2) { int i,j; int decouple_tab[SUBBAND_SIZE]; - float decode_buffer[1060]; - int idx, cpl_tmp,tmp_idx; + float *decode_buffer = q->decode_buffer_0; + int idx, cpl_tmp; float f1,f2; - float* cplscale; + const float* cplscale; memset(decouple_tab, 0, sizeof(decouple_tab)); memset(decode_buffer, 0, sizeof(decode_buffer)); @@ -812,14 +857,10 @@ static void joint_decode(COOKContext *q, float* mlt_buffer1, for (i=q->js_subband_start ; isubbands ; i++) { cpl_tmp = cplband[i]; idx -=decouple_tab[cpl_tmp]; - cplscale = (float*)cplscales[q->js_vlc_bits-2]; //choose decoupler table + cplscale = q->cplscales[q->js_vlc_bits-2]; //choose decoupler table f1 = cplscale[decouple_tab[cpl_tmp]]; f2 = cplscale[idx-1]; - for (j=0 ; jjs_subband_start + i)*20)+j; - mlt_buffer1[20*i + j] = f1 * decode_buffer[tmp_idx]; - mlt_buffer2[20*i + j] = f2 * decode_buffer[tmp_idx]; - } + q->decouple (q, i, f1, f2, decode_buffer, mlt_buffer1, mlt_buffer2); idx = (1 << q->js_vlc_bits) - 1; } } @@ -834,7 +875,7 @@ static void joint_decode(COOKContext *q, float* mlt_buffer1, */ static inline void -decode_bytes_and_gain(COOKContext *q, uint8_t *inbuffer, +decode_bytes_and_gain(COOKContext *q, const uint8_t *inbuffer, cook_gains *gains_ptr) { int offset; @@ -849,6 +890,26 @@ decode_bytes_and_gain(COOKContext *q, uint8_t *inbuffer, FFSWAP(int *, gains_ptr->now, gains_ptr->previous); } + /** + * Saturate the output signal to signed 16bit integers. + * + * @param q pointer to the COOKContext + * @param chan channel to saturate + * @param out pointer to the output vector + */ +static void +saturate_output_float (COOKContext *q, int chan, int16_t *out) +{ + int j; + float *output = q->mono_mdct_output + q->samples_per_channel; + /* Clip and convert floats to 16 bits. + */ + for (j = 0; j < q->samples_per_channel; j++) { + out[chan + q->nb_channels * j] = + av_clip_int16(lrintf(output[j])); + } +} + /** * Final part of subpacket decoding: * Apply modulated lapped transform, gain compensation, @@ -867,17 +928,8 @@ mlt_compensate_output(COOKContext *q, float *decode_buffer, cook_gains *gains, float *previous_buffer, int16_t *out, int chan) { - float *output = q->mono_mdct_output + q->samples_per_channel; - int j; - imlt_gain(q, decode_buffer, gains, previous_buffer); - - /* Clip and convert floats to 16 bits. - */ - for (j = 0; j < q->samples_per_channel; j++) { - out[chan + q->nb_channels * j] = - av_clip(lrintf(output[j]), -32768, 32767); - } + q->saturate_output (q, chan, out); } @@ -892,7 +944,7 @@ mlt_compensate_output(COOKContext *q, float *decode_buffer, */ -static int decode_subpacket(COOKContext *q, uint8_t *inbuffer, +static int decode_subpacket(COOKContext *q, const uint8_t *inbuffer, int sub_packet_size, int16_t *outbuffer) { /* packet dump */ // for (i=0 ; ipriv_data; if (buf_size < avctx->block_align) @@ -986,7 +1038,7 @@ static void dump_cook_context(COOKContext *q) static int cook_decode_init(AVCodecContext *avctx) { COOKContext *q = avctx->priv_data; - uint8_t *edata_ptr = avctx->extradata; + const uint8_t *edata_ptr = avctx->extradata; /* Take care of the codec specific extradata. */ if (avctx->extradata_size <= 0) { @@ -1075,6 +1127,7 @@ static int cook_decode_init(AVCodecContext *avctx) init_rootpow2table(q); init_pow2table(q); init_gain_table(q); + init_cplscales_table(q); if (init_cook_vlc_tables(q) != 0) return -1; @@ -1109,6 +1162,15 @@ static int cook_decode_init(AVCodecContext *avctx) if ( init_cook_mlt(q) != 0 ) return -1; + /* Initialize COOK signal arithmetic handling */ + if (1) { + q->scalar_dequant = scalar_dequant_float; + q->decouple = decouple_float; + q->imlt_window = imlt_window_float; + q->interpolate = interpolate_float; + q->saturate_output = saturate_output_float; + } + /* Try to catch some obviously faulty streams, othervise it might be exploitable */ if (q->total_subbands > 53) { av_log(avctx,AV_LOG_ERROR,"total_subbands > 53, report sample!\n"); diff --git a/contrib/ffmpeg/libavcodec/cookdata.h b/contrib/ffmpeg/libavcodec/cookdata.h index 395c9a7dd..38beef41c 100644 --- a/contrib/ffmpeg/libavcodec/cookdata.h +++ b/contrib/ffmpeg/libavcodec/cookdata.h @@ -18,7 +18,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -26,6 +25,11 @@ * Cook AKA RealAudio G2 compatible decoderdata */ +#ifndef FFMPEG_COOKDATA_H +#define FFMPEG_COOKDATA_H + +#include + /* various data tables */ static const int expbits_tab[8] = { @@ -557,3 +561,5 @@ static const float cplscale6[63] = { static const float* cplscales[5] = { cplscale2, cplscale3, cplscale4, cplscale5, cplscale6, }; + +#endif /* FFMPEG_COOKDATA_H */ diff --git a/contrib/ffmpeg/libavcodec/cscd.c b/contrib/ffmpeg/libavcodec/cscd.c index 2e7d05c40..26e662d54 100644 --- a/contrib/ffmpeg/libavcodec/cscd.c +++ b/contrib/ffmpeg/libavcodec/cscd.c @@ -21,7 +21,6 @@ #include #include -#include "common.h" #include "avcodec.h" #ifdef CONFIG_ZLIB @@ -36,7 +35,7 @@ typedef struct { unsigned char* decomp_buf; } CamStudioContext; -static void copy_frame_default(AVFrame *f, uint8_t *src, +static void copy_frame_default(AVFrame *f, const uint8_t *src, int linelen, int height) { int i; uint8_t *dst = f->data[0]; @@ -48,7 +47,7 @@ static void copy_frame_default(AVFrame *f, uint8_t *src, } } -static void add_frame_default(AVFrame *f, uint8_t *src, +static void add_frame_default(AVFrame *f, const uint8_t *src, int linelen, int height) { int i, j; uint8_t *dst = f->data[0]; @@ -66,7 +65,7 @@ static void add_frame_default(AVFrame *f, uint8_t *src, #define add_frame_16 add_frame_default #define add_frame_32 add_frame_default #else -static void copy_frame_16(AVFrame *f, uint8_t *src, +static void copy_frame_16(AVFrame *f, const uint8_t *src, int linelen, int height) { int i, j; uint8_t *dst = f->data[0]; @@ -82,7 +81,7 @@ static void copy_frame_16(AVFrame *f, uint8_t *src, } } -static void copy_frame_32(AVFrame *f, uint8_t *src, +static void copy_frame_32(AVFrame *f, const uint8_t *src, int linelen, int height) { int i, j; uint8_t *dst = f->data[0]; @@ -100,7 +99,7 @@ static void copy_frame_32(AVFrame *f, uint8_t *src, } } -static void add_frame_16(AVFrame *f, uint8_t *src, +static void add_frame_16(AVFrame *f, const uint8_t *src, int linelen, int height) { int i, j; uint8_t *dst = f->data[0]; @@ -116,7 +115,7 @@ static void add_frame_16(AVFrame *f, uint8_t *src, } } -static void add_frame_32(AVFrame *f, uint8_t *src, +static void add_frame_32(AVFrame *f, const uint8_t *src, int linelen, int height) { int i, j; uint8_t *dst = f->data[0]; @@ -136,8 +135,8 @@ static void add_frame_32(AVFrame *f, uint8_t *src, #endif static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) { - CamStudioContext *c = (CamStudioContext *)avctx->priv_data; + const uint8_t *buf, int buf_size) { + CamStudioContext *c = avctx->priv_data; AVFrame *picture = data; if (buf_size < 2) { @@ -214,11 +213,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, } static int decode_init(AVCodecContext *avctx) { - CamStudioContext *c = (CamStudioContext *)avctx->priv_data; + CamStudioContext *c = avctx->priv_data; if (avcodec_check_dimensions(avctx, avctx->height, avctx->width) < 0) { return 1; } - avctx->has_b_frames = 0; switch (avctx->bits_per_sample) { case 16: avctx->pix_fmt = PIX_FMT_RGB555; break; case 24: avctx->pix_fmt = PIX_FMT_BGR24; break; @@ -243,7 +241,7 @@ static int decode_init(AVCodecContext *avctx) { } static int decode_end(AVCodecContext *avctx) { - CamStudioContext *c = (CamStudioContext *)avctx->priv_data; + CamStudioContext *c = avctx->priv_data; av_freep(&c->decomp_buf); if (c->pic.data[0]) avctx->release_buffer(avctx, &c->pic); diff --git a/contrib/ffmpeg/libavcodec/cyuv.c b/contrib/ffmpeg/libavcodec/cyuv.c index 101f2bd85..c36495ec6 100644 --- a/contrib/ffmpeg/libavcodec/cyuv.c +++ b/contrib/ffmpeg/libavcodec/cyuv.c @@ -1,4 +1,8 @@ /* + * Creative YUV (CYUV) Video Decoder + * by Mike Melanson (melanson@pcisys.net) + * based on "Creative YUV (CYUV) stream format for AVI": + * http://www.csse.monash.edu.au/~timf/videocodec/cyuv.txt * * Copyright (C) 2003 the ffmpeg project * @@ -17,12 +21,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Creative YUV (CYUV) Video Decoder - * by Mike Melanson (melanson@pcisys.net) - * based on "Creative YUV (CYUV) stream format for AVI": - * http://www.csse.monash.edu.au/~timf/videocodec/cyuv.txt - * */ /** @@ -35,7 +33,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" @@ -58,14 +55,13 @@ static int cyuv_decode_init(AVCodecContext *avctx) return -1; s->height = avctx->height; avctx->pix_fmt = PIX_FMT_YUV411P; - avctx->has_b_frames = 0; return 0; } static int cyuv_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { CyuvDecodeContext *s=avctx->priv_data; @@ -77,9 +73,9 @@ static int cyuv_decode_frame(AVCodecContext *avctx, int v_ptr; /* prediction error tables (make it clear that they are signed values) */ - signed char *y_table = (signed char*)buf + 0; - signed char *u_table = (signed char*)buf + 16; - signed char *v_table = (signed char*)buf + 32; + const signed char *y_table = (const signed char*)buf + 0; + const signed char *u_table = (const signed char*)buf + 16; + const signed char *v_table = (const signed char*)buf + 32; unsigned char y_pred, u_pred, v_pred; int stream_ptr; diff --git a/contrib/ffmpeg/libavcodec/dca.c b/contrib/ffmpeg/libavcodec/dca.c index a57dcdc44..2a449a203 100644 --- a/contrib/ffmpeg/libavcodec/dca.c +++ b/contrib/ffmpeg/libavcodec/dca.c @@ -35,15 +35,7 @@ #include "bitstream.h" #include "dcadata.h" #include "dcahuff.h" -#include "parser.h" - -/** DCA syncwords, also used for bitstream type detection */ -//@{ -#define DCA_MARKER_RAW_BE 0x7FFE8001 -#define DCA_MARKER_RAW_LE 0xFE7F0180 -#define DCA_MARKER_14B_BE 0x1FFFE800 -#define DCA_MARKER_14B_LE 0xFF1F00E8 -//@} +#include "dca.h" //#define TRACE @@ -95,7 +87,7 @@ static BitAlloc dca_smpl_bitalloc[11]; ///< samples VLCs /** Pre-calculated cosine modulation coefs for the QMF */ static float cos_mod[544]; -static int av_always_inline get_bitalloc(GetBitContext *gb, BitAlloc *ba, int idx) +static av_always_inline int get_bitalloc(GetBitContext *gb, BitAlloc *ba, int idx) { return get_vlc2(gb, ba->vlc[idx].table, ba->vlc[idx].bits, ba->wrap) + ba->offset; } @@ -185,16 +177,16 @@ typedef struct { DSPContext dsp; } DCAContext; -static void dca_init_vlcs() +static void dca_init_vlcs(void) { - static int vlcs_inited = 0; + static int vlcs_initialized = 0; int i, j; - if (vlcs_inited) + if (vlcs_initialized) return; dca_bitalloc_index.offset = 1; - dca_bitalloc_index.wrap = 1; + dca_bitalloc_index.wrap = 2; for (i = 0; i < 5; i++) init_vlc(&dca_bitalloc_index.vlc[i], bitalloc_12_vlc_bits[i], 12, bitalloc_12_bits[i], 1, 1, @@ -222,7 +214,7 @@ static void dca_init_vlcs() bitalloc_bits[i][j], 1, 1, bitalloc_codes[i][j], 2, 2, 1); } - vlcs_inited = 1; + vlcs_initialized = 1; } static inline void get_array(GetBitContext *gb, int *dst, int len, int bits) @@ -285,7 +277,8 @@ static int dca_parse_frame_header(DCAContext * s) s->dialog_norm = get_bits(&s->gb, 4); /* FIXME: channels mixing levels */ - s->output = DCA_STEREO; + s->output = s->amode; + if(s->lfe) s->output |= DCA_LFE; #ifdef TRACE av_log(s->avctx, AV_LOG_DEBUG, "frame type: %i\n", s->frame_type); @@ -395,11 +388,11 @@ static int dca_parse_frame_header(DCAContext * s) } -static inline int get_scale(GetBitContext *gb, int level, int index, int value) +static inline int get_scale(GetBitContext *gb, int level, int value) { if (level < 5) { /* huffman encoded */ - value += get_bitalloc(gb, &dca_scalefactor, index); + value += get_bitalloc(gb, &dca_scalefactor, level); } else if(level < 8) value = get_bits(gb, level + 1); return value; @@ -436,7 +429,7 @@ static int dca_subframe_header(DCAContext * s) s->bitalloc[j][k] = get_bits(&s->gb, 4); else { s->bitalloc[j][k] = - get_bitalloc(&s->gb, &dca_bitalloc_index, j); + get_bitalloc(&s->gb, &dca_bitalloc_index, s->bitalloc_huffman[j]); } if (s->bitalloc[j][k] > 26) { @@ -460,28 +453,28 @@ static int dca_subframe_header(DCAContext * s) } for (j = 0; j < s->prim_channels; j++) { - uint32_t *scale_table; + const uint32_t *scale_table; int scale_sum; memset(s->scale_factor[j], 0, s->subband_activity[j] * sizeof(s->scale_factor[0][0][0]) * 2); if (s->scalefactor_huffman[j] == 6) - scale_table = (uint32_t *) scale_factor_quant7; + scale_table = scale_factor_quant7; else - scale_table = (uint32_t *) scale_factor_quant6; + scale_table = scale_factor_quant6; /* When huffman coded, only the difference is encoded */ scale_sum = 0; for (k = 0; k < s->subband_activity[j]; k++) { if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) { - scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], j, scale_sum); + scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum); s->scale_factor[j][k][0] = scale_table[scale_sum]; } if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) { /* Get second scale factor */ - scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], j, scale_sum); + scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum); s->scale_factor[j][k][1] = scale_table[scale_sum]; } } @@ -507,7 +500,7 @@ static int dca_subframe_header(DCAContext * s) * (is this valid as well for joint scales ???) */ for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) { - scale = get_scale(&s->gb, s->joint_huff[j], j, 0); + scale = get_scale(&s->gb, s->joint_huff[j], 0); scale += 64; /* bias */ s->joint_scale_factor[j][k] = scale; /*joint_scale_table[scale]; */ } @@ -521,10 +514,18 @@ static int dca_subframe_header(DCAContext * s) } /* Stereo downmix coefficients */ - if (s->prim_channels > 2 && s->downmix) { - for (j = 0; j < s->prim_channels; j++) { - s->downmix_coef[j][0] = get_bits(&s->gb, 7); - s->downmix_coef[j][1] = get_bits(&s->gb, 7); + if (s->prim_channels > 2) { + if(s->downmix) { + for (j = 0; j < s->prim_channels; j++) { + s->downmix_coef[j][0] = get_bits(&s->gb, 7); + s->downmix_coef[j][1] = get_bits(&s->gb, 7); + } + } else { + int am = s->amode & DCA_CHANNEL_MASK; + for (j = 0; j < s->prim_channels; j++) { + s->downmix_coef[j][0] = dca_default_coeffs[am][j][0]; + s->downmix_coef[j][1] = dca_default_coeffs[am][j][1]; + } } } @@ -611,6 +612,7 @@ static int dca_subframe_header(DCAContext * s) } for (j = 0; j < s->prim_channels; j++) { if (s->joint_intensity[j] > 0) { + int source_channel = s->joint_intensity[j] - 1; av_log(s->avctx, AV_LOG_DEBUG, "Joint scale factor index:\n"); for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) av_log(s->avctx, AV_LOG_DEBUG, " %i", s->joint_scale_factor[j][k]); @@ -629,6 +631,7 @@ static int dca_subframe_header(DCAContext * s) for (k = s->vq_start_subband[j]; k < s->subband_activity[j]; k++) av_log(s->avctx, AV_LOG_DEBUG, "VQ index: %i\n", s->high_freq_vq[j][k]); if(s->lfe){ + int lfe_samples = 2 * s->lfe * s->subsubframes; av_log(s->avctx, AV_LOG_DEBUG, "LFE samples:\n"); for (j = lfe_samples; j < lfe_samples * 2; j++) av_log(s->avctx, AV_LOG_DEBUG, " %f", s->lfe_data[j]); @@ -643,7 +646,7 @@ static void qmf_32_subbands(DCAContext * s, int chans, float samples_in[32][8], float *samples_out, float scale, float bias) { - float *prCoeff; + const float *prCoeff; int i, j, k; float praXin[33], *raXin = &praXin[1]; @@ -656,9 +659,9 @@ static void qmf_32_subbands(DCAContext * s, int chans, /* Select filter */ if (!s->multirate_inter) /* Non-perfect reconstruction */ - prCoeff = (float *) fir_32bands_nonperfect; + prCoeff = fir_32bands_nonperfect; else /* Perfect reconstruction */ - prCoeff = (float *) fir_32bands_perfect; + prCoeff = fir_32bands_perfect; /* Reconstructed channel sample index */ for (subindex = 0; subindex < 8; subindex++) { @@ -749,18 +752,18 @@ static void lfe_interpolation_fir(int decimation_select, } /* downmixing routines */ -#define MIX_REAR1(samples, si1) \ - samples[i] += samples[si1]; \ - samples[i+256] += samples[si1]; +#define MIX_REAR1(samples, si1, rs, coef) \ + samples[i] += samples[si1] * coef[rs][0]; \ + samples[i+256] += samples[si1] * coef[rs][1]; -#define MIX_REAR2(samples, si1, si2) \ - samples[i] += samples[si1]; \ - samples[i+256] += samples[si2]; +#define MIX_REAR2(samples, si1, si2, rs, coef) \ + samples[i] += samples[si1] * coef[rs][0] + samples[si2] * coef[rs+1][0]; \ + samples[i+256] += samples[si1] * coef[rs][1] + samples[si2] * coef[rs+1][1]; -#define MIX_FRONT3(samples) \ +#define MIX_FRONT3(samples, coef) \ t = samples[i]; \ - samples[i] += samples[i+256]; \ - samples[i+256] = samples[i+512] + t; + samples[i] = t * coef[0][0] + samples[i+256] * coef[1][0] + samples[i+512] * coef[2][0]; \ + samples[i+256] = t * coef[0][1] + samples[i+256] * coef[1][1] + samples[i+512] * coef[2][1]; #define DOWNMIX_TO_STEREO(op1, op2) \ for(i = 0; i < 256; i++){ \ @@ -768,10 +771,17 @@ static void lfe_interpolation_fir(int decimation_select, op2 \ } -static void dca_downmix(float *samples, int srcfmt) +static void dca_downmix(float *samples, int srcfmt, + int downmix_coef[DCA_PRIM_CHANNELS_MAX][2]) { int i; float t; + float coef[DCA_PRIM_CHANNELS_MAX][2]; + + for(i=0; icurrent_subsubframe; - float *quant_step_table; + const float *quant_step_table; /* FIXME */ float subband_samples[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][8]; @@ -843,9 +853,9 @@ static int dca_subsubframe(DCAContext * s) /* Select quantization step size table */ if (s->bit_rate == 0x1f) - quant_step_table = (float *) lossless_quant_d; + quant_step_table = lossless_quant_d; else - quant_step_table = (float *) lossy_quant_d; + quant_step_table = lossy_quant_d; for (k = 0; k < s->prim_channels; k++) { for (l = 0; l < s->vq_start_subband[k]; l++) { @@ -979,7 +989,7 @@ static int dca_subsubframe(DCAContext * s) /* Down mixing */ if (s->prim_channels > dca_channels[s->output & DCA_CHANNEL_MASK]) { - dca_downmix(s->samples, s->amode); + dca_downmix(s->samples, s->amode, s->downmix_coef); } /* Generate LFE samples for this subsubframe FIXME!!! */ @@ -991,7 +1001,7 @@ static int dca_subsubframe(DCAContext * s) s->lfe_data + lfe_samples + 2 * s->lfe * subsubframe, &s->samples[256 * i_channels], - 8388608.0, s->bias); + 256.0, 0 /* s->bias */); /* Outputs 20bits pcm samples */ } @@ -1081,14 +1091,20 @@ static int dca_decode_block(DCAContext * s) /** * Convert bitstream to one representation based on sync marker */ -static int dca_convert_bitstream(uint8_t * src, int src_size, uint8_t * dst, +static int dca_convert_bitstream(const uint8_t * src, int src_size, uint8_t * dst, int max_size) { uint32_t mrk; int i, tmp; - uint16_t *ssrc = (uint16_t *) src, *sdst = (uint16_t *) dst; + const uint16_t *ssrc = (const uint16_t *) src; + uint16_t *sdst = (uint16_t *) dst; PutBitContext pb; + if((unsigned)src_size > (unsigned)max_size) { + av_log(NULL, AV_LOG_ERROR, "Input frame size larger then DCA_MAX_FRAME_SIZE!\n"); + return -1; + } + mrk = AV_RB32(src); switch (mrk) { case DCA_MARKER_RAW_BE: @@ -1118,7 +1134,7 @@ static int dca_convert_bitstream(uint8_t * src, int src_size, uint8_t * dst, */ static int dca_decode_frame(AVCodecContext * avctx, void *data, int *data_size, - uint8_t * buf, int buf_size) + const uint8_t * buf, int buf_size) { int i, j, k; @@ -1129,21 +1145,27 @@ static int dca_decode_frame(AVCodecContext * avctx, s->dca_buffer_size = dca_convert_bitstream(buf, buf_size, s->dca_buffer, DCA_MAX_FRAME_SIZE); if (s->dca_buffer_size == -1) { - av_log(avctx, AV_LOG_ERROR, "Not a DCA frame\n"); + av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n"); return -1; } init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8); if (dca_parse_frame_header(s) < 0) { //seems like the frame is corrupt, try with the next one + *data_size=0; return buf_size; } //set AVCodec values with parsed data avctx->sample_rate = s->sample_rate; - avctx->channels = 2; //FIXME avctx->bit_rate = s->bit_rate; - channels = dca_channels[s->output]; + channels = s->prim_channels + !!s->lfe; + if(avctx->request_channels == 2 && s->prim_channels > 2) { + channels = 2; + s->output = DCA_STEREO; + } + + avctx->channels = channels; if(*data_size < (s->sample_blocks / 8) * 256 * sizeof(int16_t) * channels) return -1; *data_size = 0; @@ -1173,9 +1195,9 @@ static int dca_decode_frame(AVCodecContext * avctx, static void pre_calc_cosmod(DCAContext * s) { int i, j, k; - static int cosmod_inited = 0; + static int cosmod_initialized = 0; - if(cosmod_inited) return; + if(cosmod_initialized) return; for (j = 0, k = 0; k < 16; k++) for (i = 0; i < 16; i++) cos_mod[j++] = cos((2 * i + 1) * (2 * k + 1) * M_PI / 64); @@ -1190,7 +1212,7 @@ static void pre_calc_cosmod(DCAContext * s) for (k = 0; k < 16; k++) cos_mod[j++] = -0.25 / (2.0 * sin((2 * k + 1) * M_PI / 128)); - cosmod_inited = 1; + cosmod_initialized = 1; } @@ -1209,6 +1231,13 @@ static int dca_decode_init(AVCodecContext * avctx) pre_calc_cosmod(s); dsputil_init(&s->dsp, avctx); + + /* allow downmixing to stereo */ + if (avctx->channels > 0 && avctx->request_channels < avctx->channels && + avctx->request_channels == 2) { + avctx->channels = avctx->request_channels; + } + return 0; } @@ -1221,102 +1250,3 @@ AVCodec dca_decoder = { .init = dca_decode_init, .decode = dca_decode_frame, }; - -#ifdef CONFIG_DCA_PARSER - -typedef struct DCAParseContext { - ParseContext pc; - uint32_t lastmarker; -} DCAParseContext; - -#define IS_MARKER(state, i, buf, buf_size) \ - ((state == DCA_MARKER_14B_LE && (i < buf_size-2) && (buf[i+1] & 0xF0) == 0xF0 && buf[i+2] == 0x07) \ - || (state == DCA_MARKER_14B_BE && (i < buf_size-2) && buf[i+1] == 0x07 && (buf[i+2] & 0xF0) == 0xF0) \ - || state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE) - -/** - * finds the end of the current frame in the bitstream. - * @return the position of the first byte of the next frame, or -1 - */ -static int dca_find_frame_end(DCAParseContext * pc1, const uint8_t * buf, - int buf_size) -{ - int start_found, i; - uint32_t state; - ParseContext *pc = &pc1->pc; - - start_found = pc->frame_start_found; - state = pc->state; - - i = 0; - if (!start_found) { - for (i = 0; i < buf_size; i++) { - state = (state << 8) | buf[i]; - if (IS_MARKER(state, i, buf, buf_size)) { - if (pc1->lastmarker && state == pc1->lastmarker) { - start_found = 1; - break; - } else if (!pc1->lastmarker) { - start_found = 1; - pc1->lastmarker = state; - break; - } - } - } - } - if (start_found) { - for (; i < buf_size; i++) { - state = (state << 8) | buf[i]; - if (state == pc1->lastmarker && IS_MARKER(state, i, buf, buf_size)) { - pc->frame_start_found = 0; - pc->state = -1; - return i - 3; - } - } - } - pc->frame_start_found = start_found; - pc->state = state; - return END_NOT_FOUND; -} - -static int dca_parse_init(AVCodecParserContext * s) -{ - DCAParseContext *pc1 = s->priv_data; - - pc1->lastmarker = 0; - return 0; -} - -static int dca_parse(AVCodecParserContext * s, - AVCodecContext * avctx, - uint8_t ** poutbuf, int *poutbuf_size, - const uint8_t * buf, int buf_size) -{ - DCAParseContext *pc1 = s->priv_data; - ParseContext *pc = &pc1->pc; - int next; - - if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { - next = buf_size; - } else { - next = dca_find_frame_end(pc1, buf, buf_size); - - if (ff_combine_frame(pc, next, (uint8_t **) & buf, &buf_size) < 0) { - *poutbuf = NULL; - *poutbuf_size = 0; - return buf_size; - } - } - *poutbuf = (uint8_t *) buf; - *poutbuf_size = buf_size; - return next; -} - -AVCodecParser dca_parser = { - {CODEC_ID_DTS}, - sizeof(DCAParseContext), - dca_parse_init, - dca_parse, - ff_parse_close, -}; -#endif /* CONFIG_DCA_PARSER */ diff --git a/contrib/ffmpeg/libavcodec/dca.h b/contrib/ffmpeg/libavcodec/dca.h new file mode 100644 index 000000000..e2197a440 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/dca.h @@ -0,0 +1,34 @@ +/* + * DCA compatible decoder + * Copyright (C) 2004 Gildas Bazin + * Copyright (C) 2004 Benjamin Zores + * Copyright (C) 2006 Benjamin Larsson + * Copyright (C) 2007 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_DCA_H +#define FFMPEG_DCA_H + +/** DCA syncwords, also used for bitstream type detection */ +#define DCA_MARKER_RAW_BE 0x7FFE8001 +#define DCA_MARKER_RAW_LE 0xFE7F0180 +#define DCA_MARKER_14B_BE 0x1FFFE800 +#define DCA_MARKER_14B_LE 0xFF1F00E8 + +#endif /* FFMPEG_DCA_H */ diff --git a/contrib/ffmpeg/libavcodec/dca_parser.c b/contrib/ffmpeg/libavcodec/dca_parser.c new file mode 100644 index 000000000..6618b3156 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/dca_parser.c @@ -0,0 +1,126 @@ +/* + * DCA parser + * Copyright (C) 2004 Gildas Bazin + * Copyright (C) 2004 Benjamin Zores + * Copyright (C) 2006 Benjamin Larsson + * Copyright (C) 2007 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file dca_parser.c + */ + +#include "parser.h" +#include "dca.h" + +typedef struct DCAParseContext { + ParseContext pc; + uint32_t lastmarker; +} DCAParseContext; + +#define IS_MARKER(state, i, buf, buf_size) \ + ((state == DCA_MARKER_14B_LE && (i < buf_size-2) && (buf[i+1] & 0xF0) == 0xF0 && buf[i+2] == 0x07) \ + || (state == DCA_MARKER_14B_BE && (i < buf_size-2) && buf[i+1] == 0x07 && (buf[i+2] & 0xF0) == 0xF0) \ + || state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE) + +/** + * finds the end of the current frame in the bitstream. + * @return the position of the first byte of the next frame, or -1 + */ +static int dca_find_frame_end(DCAParseContext * pc1, const uint8_t * buf, + int buf_size) +{ + int start_found, i; + uint32_t state; + ParseContext *pc = &pc1->pc; + + start_found = pc->frame_start_found; + state = pc->state; + + i = 0; + if (!start_found) { + for (i = 0; i < buf_size; i++) { + state = (state << 8) | buf[i]; + if (IS_MARKER(state, i, buf, buf_size)) { + if (pc1->lastmarker && state == pc1->lastmarker) { + start_found = 1; + break; + } else if (!pc1->lastmarker) { + start_found = 1; + pc1->lastmarker = state; + break; + } + } + } + } + if (start_found) { + for (; i < buf_size; i++) { + state = (state << 8) | buf[i]; + if (state == pc1->lastmarker && IS_MARKER(state, i, buf, buf_size)) { + pc->frame_start_found = 0; + pc->state = -1; + return i - 3; + } + } + } + pc->frame_start_found = start_found; + pc->state = state; + return END_NOT_FOUND; +} + +static int dca_parse_init(AVCodecParserContext * s) +{ + DCAParseContext *pc1 = s->priv_data; + + pc1->lastmarker = 0; + return 0; +} + +static int dca_parse(AVCodecParserContext * s, + AVCodecContext * avctx, + const uint8_t ** poutbuf, int *poutbuf_size, + const uint8_t * buf, int buf_size) +{ + DCAParseContext *pc1 = s->priv_data; + ParseContext *pc = &pc1->pc; + int next; + + if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { + next = buf_size; + } else { + next = dca_find_frame_end(pc1, buf, buf_size); + + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + } + *poutbuf = buf; + *poutbuf_size = buf_size; + return next; +} + +AVCodecParser dca_parser = { + {CODEC_ID_DTS}, + sizeof(DCAParseContext), + dca_parse_init, + dca_parse, + ff_parse_close, +}; diff --git a/contrib/ffmpeg/libavcodec/dcadata.h b/contrib/ffmpeg/libavcodec/dcadata.h index c9f2ca747..40e78360d 100644 --- a/contrib/ffmpeg/libavcodec/dcadata.h +++ b/contrib/ffmpeg/libavcodec/dcadata.h @@ -24,6 +24,11 @@ * @file dcadata.c */ +#ifndef FFMPEG_DCADATA_H +#define FFMPEG_DCADATA_H + +#include + /* Generic tables */ static const uint32_t dca_sample_rates[16] = @@ -7309,7 +7314,7 @@ static const float fir_32bands_nonperfect[] = +1.390191784E-007 }; -//FIXME the coeffs are symetric +//FIXME the coeffs are symmetric static const float lfe_fir_64[] = { 2.6584343868307770E-004, @@ -7826,7 +7831,7 @@ static const float lfe_fir_64[] = 2.6584343868307770E-004 }; -//FIXME the coeffs are symetric +//FIXME the coeffs are symmetric static const float lfe_fir_128[] = { @@ -8344,7 +8349,7 @@ static const float lfe_fir_128[] = 0.00053168571 }; -/* 10^-(dB/20), with dB beeing a list of dB values rangeing from 0 to -72 */ +/* 10^-(dB/20), with dB being a list of dB values ranging from 0 to -72 */ /* do a 20*log10(dca_downmix_coeffs) to reconvert the values */ static const float dca_downmix_coeffs[65] = { @@ -8361,6 +8366,19 @@ static const float dca_downmix_coeffs[65] = { 0.001412537544623, 0.001000000000000, 0.000501187233627, 0.000251188643151, 0.000000000000000, }; +static const uint8_t dca_default_coeffs[16][5][2] = { + { { 13, 13 }, }, + { { 0, 64 }, { 64, 0 }, }, + { { 0, 64 }, { 64, 0 }, }, + { { 0, 64 }, { 64, 0 }, }, + { { 0, 64 }, { 64, 0 }, }, + { { 6, 6 }, { 0, 25 }, { 25, 0 }, }, + { { 0, 25 }, { 25, 0 }, { 13, 13 }, }, + { { 6, 6 }, { 0, 25 }, { 25, 0 }, { 13, 13 }, }, + { { 0, 25 }, { 25, 0 }, { 0, 13 }, { 13, 0 }, }, + { { 6, 6 }, { 0, 25 }, { 25, 0 }, { 0, 13 }, { 13, 0 }, }, +}; + /* downmix coeffs TABLE 9 @@ -8452,3 +8470,5 @@ where Ch(n) represents the subband samples in the (n)th audio channel. */ + +#endif /* FFMPEG_DCADATA_H */ diff --git a/contrib/ffmpeg/libavcodec/dcahuff.h b/contrib/ffmpeg/libavcodec/dcahuff.h index 8a78aee7e..a140f3b8b 100644 --- a/contrib/ffmpeg/libavcodec/dcahuff.h +++ b/contrib/ffmpeg/libavcodec/dcahuff.h @@ -20,6 +20,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef FFMPEG_DCAHUFF_H +#define FFMPEG_DCAHUFF_H + +#include +#include + #define TMODE_COUNT 4 static const uint8_t tmode_vlc_bits[TMODE_COUNT] = { 3, 3, 3, 2 }; static const uint16_t tmode_codes[TMODE_COUNT][4] = { @@ -1066,3 +1072,5 @@ static const uint8_t* bitalloc_bits[10][8] = { { bitalloc_129_bits_a, bitalloc_129_bits_b, bitalloc_129_bits_c, bitalloc_129_bits_d, bitalloc_129_bits_e, bitalloc_129_bits_f, bitalloc_129_bits_g, NULL } }; + +#endif /* FFMPEG_DCAHUFF_H */ diff --git a/contrib/ffmpeg/libavcodec/dct-test.c b/contrib/ffmpeg/libavcodec/dct-test.c index 7cd866832..c3ef297c4 100644 --- a/contrib/ffmpeg/libavcodec/dct-test.c +++ b/contrib/ffmpeg/libavcodec/dct-test.c @@ -30,17 +30,20 @@ #include #include #include +#include #include "dsputil.h" #include "simple_idct.h" #include "faandct.h" +#include "faanidct.h" #ifndef MAX #define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif #undef printf +#undef random void *fast_memcpy(void *a, const void *b, size_t c){return memcpy(a,b,c);}; @@ -51,7 +54,6 @@ extern void ff_idct_xvid_mmx(DCTELEM *block); extern void ff_idct_xvid_mmx2(DCTELEM *block); extern void init_fdct(); -extern void j_rev_dct(DCTELEM *data); extern void ff_mmx_idct(DCTELEM *data); extern void ff_mmxext_idct(DCTELEM *data); @@ -85,19 +87,24 @@ struct algo { struct algo algos[] = { DCT_ERROR( "REF-DBL", 0, fdct, fdct, NO_PERM), + DCT_ERROR("FAAN", 0, ff_faandct, fdct, FAAN_SCALE), + DCT_ERROR("FAANI", 1, ff_faanidct, idct, NO_PERM), DCT_ERROR("IJG-AAN-INT", 0, fdct_ifast, fdct, SCALE_PERM), DCT_ERROR("IJG-LLM-INT", 0, ff_jpeg_fdct_islow, fdct, NO_PERM), DCT_ERROR("REF-DBL", 1, idct, idct, NO_PERM), DCT_ERROR("INT", 1, j_rev_dct, idct, MMX_PERM), - DCT_ERROR("SIMPLE-C", 1, simple_idct, idct, NO_PERM), + DCT_ERROR("SIMPLE-C", 1, ff_simple_idct, idct, NO_PERM), -#ifdef ARCH_X86 +#ifdef HAVE_MMX DCT_ERROR("MMX", 0, ff_fdct_mmx, fdct, NO_PERM), +#ifdef HAVE_MMX2 DCT_ERROR("MMX2", 0, ff_fdct_mmx2, fdct, NO_PERM), - DCT_ERROR("FAAN", 0, ff_faandct, fdct, FAAN_SCALE), +#endif +#ifdef CONFIG_GPL DCT_ERROR("LIBMPEG2-MMX", 1, ff_mmx_idct, idct, MMX_PERM), DCT_ERROR("LIBMPEG2-MMXEXT", 1, ff_mmxext_idct, idct, MMX_PERM), +#endif DCT_ERROR("SIMPLE-MMX", 1, ff_simple_idct_mmx, idct, MMX_SIMPLE_PERM), DCT_ERROR("XVID-MMX", 1, ff_idct_xvid_mmx, idct, NO_PERM), DCT_ERROR("XVID-MMX2", 1, ff_idct_xvid_mmx2, idct, NO_PERM), @@ -333,7 +340,7 @@ void dct_error(const char *name, int is_idct, for(i=0; i<64; i++) block[i]= block1[i]; // memcpy(block, block1, sizeof(DCTELEM) * 64); -// dont memcpy especially not fastmemcpy because it does movntq !!! +// do not memcpy especially not fastmemcpy because it does movntq !!! fdct_func(block); } it1 += NB_ITS_SPEED; @@ -493,7 +500,7 @@ void idct248_error(const char *name, for(i=0; i<64; i++) block[i]= block1[i]; // memcpy(block, block1, sizeof(DCTELEM) * 64); -// dont memcpy especially not fastmemcpy because it does movntq !!! +// do not memcpy especially not fastmemcpy because it does movntq !!! idct248_put(img_dest, 8, block); } it1 += NB_ITS_SPEED; @@ -554,7 +561,7 @@ int main(int argc, char **argv) printf("ffmpeg DCT/IDCT test\n"); if (test_248_dct) { - idct248_error("SIMPLE-C", simple_idct248_put); + idct248_error("SIMPLE-C", ff_simple_idct248_put); } else { for (i=0;algos[i].name;i++) if (algos[i].is_idct == test_idct) { diff --git a/contrib/ffmpeg/libavcodec/dnxhddata.c b/contrib/ffmpeg/libavcodec/dnxhddata.c new file mode 100644 index 000000000..fa6d13fa4 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/dnxhddata.c @@ -0,0 +1,443 @@ +/* + * VC3/DNxHD data. + * Copyright (c) 2007 SmartJog S.A., Baptiste Coudurier . + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "dnxhddata.h" + +static const uint8_t dnxhd_1237_luma_weight[] = { + 0, 32, 33, 34, 34, 36, 37, 36, + 36, 37, 38, 38, 38, 39, 41, 44, + 43, 41, 40, 41, 46, 49, 47, 46, + 47, 49, 51, 54, 60, 62, 59, 55, + 54, 56, 58, 61, 65, 66, 64, 63, + 66, 73, 78, 79, 80, 79, 78, 78, + 82, 87, 89, 90, 93, 95, 96, 97, + 97, 100, 104, 102, 98, 98, 99, 99, +}; + +static const uint8_t dnxhd_1237_chroma_weight[] = { + 0, 32, 36, 39, 39, 38, 39, 41, + 45, 51, 57, 58, 53, 48, 47, 51, + 55, 58, 66, 75, 81, 83, 82, 78, + 73, 72, 74, 77, 83, 85, 83, 82, + 89, 99, 96, 90, 94, 97, 99, 105, + 109, 105, 95, 89, 92, 95, 94, 93, + 92, 88, 89, 90, 93, 95, 96, 97, + 97, 100, 104, 102, 98, 98, 99, 99, +}; + +static const uint8_t dnxhd_1238_luma_weight[] = { + 0, 32, 32, 33, 34, 33, 33, 33, + 33, 33, 33, 33, 33, 35, 37, 37, + 36, 36, 35, 36, 38, 38, 36, 35, + 36, 37, 38, 41, 42, 41, 39, 38, + 38, 38, 39, 41, 42, 41, 39, 39, + 40, 41, 43, 44, 44, 44, 44, 44, + 45, 47, 47, 47, 49, 50, 51, 51, + 51, 53, 55, 57, 58, 59, 57, 57, +}; + +static const uint8_t dnxhd_1238_chroma_weight[] = { + 0, 32, 35, 35, 35, 34, 34, 35, + 39, 43, 45, 45, 41, 39, 40, 41, + 42, 44, 48, 55, 59, 63, 65, 59, + 53, 52, 52, 55, 61, 62, 58, 58, + 63, 66, 66, 65, 70, 74, 70, 66, + 65, 68, 75, 77, 74, 74, 77, 76, + 73, 73, 73, 73, 76, 80, 89, 90, + 82, 77, 80, 86, 84, 82, 82, 82, +}; + +static const uint8_t dnxhd_1241_luma_weight[] = { + 0, 32, 33, 34, 34, 35, 36, 37, + 36, 37, 38, 38, 38, 39, 39, 40, + 40, 38, 38, 39, 38, 37, 39, 41, + 41, 42, 43, 45, 45, 46, 47, 46, + 45, 43, 39, 37, 37, 40, 44, 45, + 45, 46, 46, 46, 47, 47, 46, 44, + 42, 43, 45, 47, 48, 49, 50, 49, + 48, 46, 47, 48, 48, 49, 49, 49, +}; + +static const uint8_t dnxhd_1241_chroma_weight[] = { + 0, 32, 36, 38, 37, 37, 40, 41, + 40, 40, 42, 42, 41, 41, 41, 41, + 42, 43, 44, 44, 45, 46, 46, 45, + 44, 45, 45, 45, 45, 46, 47, 46, + 45, 44, 42, 41, 43, 45, 45, 47, + 48, 48, 48, 46, 47, 47, 46, 47, + 46, 45, 45, 47, 48, 49, 50, 49, + 48, 46, 48, 49, 48, 49, 49, 49, +}; + +static const uint8_t dnxhd_1242_luma_weight[] = { + 0, 32, 33, 33, 34, 35, 36, 35, + 33, 33, 35, 36, 37, 37, 38, 37, + 37, 37, 36, 37, 37, 37, 38, 39, + 37, 36, 37, 40, 42, 45, 46, 44, + 41, 42, 44, 45, 47, 49, 50, 48, + 46, 48, 49, 50, 52, 52, 50, 49, + 47, 48, 50, 50, 51, 51, 50, 49, + 49, 51, 52, 51, 49, 47, 47, 47, +}; + +static const uint8_t dnxhd_1242_chroma_weight[] = { + 0, 32, 37, 42, 45, 45, 45, 44, + 38, 37, 40, 42, 44, 49, 51, 47, + 41, 40, 43, 44, 46, 48, 51, 54, + 51, 47, 47, 45, 47, 50, 51, 49, + 46, 47, 49, 47, 50, 55, 55, 51, + 48, 49, 51, 51, 52, 52, 54, 54, + 49, 49, 52, 53, 54, 54, 53, 53, + 55, 59, 63, 62, 60, 60, 60, 60, + }; + +static const uint8_t dnxhd_1243_luma_weight[] = { + 0, 32, 32, 33, 33, 35, 35, 35, + 35, 35, 35, 35, 34, 35, 38, 40, + 39, 37, 37, 37, 36, 35, 36, 38, + 40, 41, 42, 44, 45, 44, 42, 41, + 40, 38, 36, 36, 37, 38, 40, 43, + 44, 45, 45, 45, 45, 45, 45, 41, + 39, 41, 45, 47, 47, 48, 48, 48, + 46, 44, 45, 47, 47, 48, 47, 47, +}; + +static const uint8_t dnxhd_1243_chroma_weight[] = { + 0, 32, 36, 37, 36, 37, 39, 39, + 41, 43, 43, 42, 41, 41, 41, 42, + 43, 43, 43, 44, 44, 44, 46, 47, + 46, 45, 45, 45, 45, 46, 44, 44, + 45, 44, 42, 41, 43, 46, 45, 44, + 45, 45, 45, 46, 46, 46, 45, 44, + 45, 44, 45, 47, 47, 48, 49, 48, + 46, 45, 46, 47, 47, 48, 47, 47, +}; + +static const uint8_t dnxhd_1251_luma_weight[] = { + 0, 32, 32, 34, 34, 34, 34, 35, + 35, 35, 36, 37, 36, 36, 35, 36, + 38, 38, 38, 38, 38, 38, 38, 38, + 38, 38, 39, 41, 44, 43, 41, 40, + 40, 40, 40, 39, 40, 41, 40, 39, + 40, 43, 46, 46, 44, 44, 44, 42, + 41, 43, 46, 48, 50, 55, 58, 53, + 48, 50, 55, 58, 61, 62, 62, 62, +}; + +static const uint8_t dnxhd_1251_chroma_weight[] = { + 0, 32, 35, 36, 36, 35, 36, 39, + 41, 43, 45, 44, 41, 39, 40, 42, + 43, 43, 45, 48, 48, 48, 50, 50, + 50, 51, 51, 51, 51, 52, 53, 54, + 51, 49, 51, 52, 52, 56, 57, 55, + 54, 54, 55, 56, 55, 58, 58, 58, + 60, 61, 62, 62, 59, 57, 58, 58, + 61, 59, 59, 59, 61, 62, 62, 62, +}; + +static const uint8_t dnxhd_1252_luma_weight[] = { + 0, 32, 34, 35, 36, 36, 36, 37, + 36, 37, 39, 40, 41, 40, 40, 40, + 41, 41, 42, 41, 41, 43, 44, 44, + 45, 46, 48, 55, 60, 57, 52, 50, + 49, 49, 52, 52, 53, 55, 58, 62, + 65, 73, 82, 82, 80, 78, 73, 68, + 71, 82, 90, 90, 88, 87, 90, 95, + 100, 107, 103, 97, 95, 93, 99, 99, +}; +static const uint8_t dnxhd_1252_chroma_weight[] = { + 0, 32, 35, 36, 37, 37, 38, 40, + 42, 46, 49, 50, 50, 49, 49, 53, + 56, 56, 57, 58, 60, 62, 64, 65, + 63, 64, 64, 65, 66, 65, 67, 71, + 72, 74, 74, 74, 74, 77, 81, 78, + 72, 73, 82, 85, 89, 88, 84, 80, + 90, 100, 90, 90, 88, 87, 90, 95, + 114, 128, 125, 129, 134, 125, 116, 116, +}; + +static const uint8_t dnxhd_1237_dc_codes[12] = { + 0, 12, 13, 1, 2, 3, 4, 5, 14, 30, 62, 63, +}; + +static const uint8_t dnxhd_1237_dc_bits[12] = { + 3, 4, 4, 3, 3, 3, 3, 3, 4, 5, 6, 6, +}; + +static const uint16_t dnxhd_1237_ac_codes[257] = { + 0, 1, 4, 5, 12, 26, 27, 56, 57, 58, 59, 120, 121, 244, 245, 246, 247, 248, 498, 499, 500, 501, 502, 1006, 1007, 1008, 1009, 1010, 1011, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031, 4064, 4065, 4066, 4067, 4068, 4069, 4070, 4071, 4072, 4073, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 8157, 8158, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 32668, 32669, 32670, 32671, 32672, 32673, 32674, 32675, 32676, 32677, 32678, 32679, 32680, 32681, 32682, 32683, 32684, 65370, 65371, 65372, 65373, 65374, 65375, 65376, 65377, 65378, 65379, 65380, 65381, 65382, 65383, 65384, 65385, 65386, 65387, 65388, 65389, 65390, 65391, 65392, 65393, 65394, 65395, 65396, 65397, 65398, 65399, 65400, 65401, 65402, 65403, 65404, 65405, 65406, 65407, 65408, 65409, 65410, 65411, 65412, 65413, 65414, 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535, +}; + +static const uint8_t dnxhd_1237_ac_bits[257] = { + 2, 2, 3, 3, 4, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, +}; + +static const uint8_t dnxhd_1237_ac_level[257] = { + 1, 1, 2, 0, 3, 4, 2, 5, 6, 7, 3, 8, 9, 10, 11, 12, 4, 5, 13, 14, 15, 16, 6, 17, 18, 19, 20, 21, 7, 22, 23, 24, 25, 26, 27, 8, 9, 28, 29, 30, 31, 32, 33, 34, 10, 11, 12, 35, 36, 37, 38, 39, 40, 41, 13, 14, 15, 16, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 17, 18, 19, 20, 21, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 1, 22, 23, 24, 25, 26, 27, 62, 63, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, +}; + +static const uint8_t dnxhd_1237_ac_run_flag[257] = { + 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; + +static const uint8_t dnxhd_1237_ac_index_flag[257] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; + +static const uint16_t dnxhd_1237_run_codes[62] = { + 0, 4, 10, 11, 24, 25, 26, 54, 55, 56, 57, 58, 118, 119, 240, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, +}; + +static const uint8_t dnxhd_1237_run_bits[62] = { + 1, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, +}; + +static const uint8_t dnxhd_1237_run[62] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 53, 57, 58, 59, 60, 61, 62, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, +}; + +static const uint8_t dnxhd_1238_dc_codes[12] = { + 0, 12, 13, 1, 2, 3, 4, 5, 14, 30, 62, 63, +}; + +static const uint8_t dnxhd_1238_dc_bits[12] = { + 3, 4, 4, 3, 3, 3, 3, 3, 4, 5, 6, 6, +}; + +static const uint16_t dnxhd_1238_ac_codes[257] = { + 0, 1, 4, 10, 11, 24, 25, 26, 54, 55, 56, 57, 116, 117, 118, 119, 240, 241, 242, 243, 244, 245, 492, 493, 494, 495, 496, 497, 498, 499, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 4056, 4057, 4058, 4059, 4060, 4061, 4062, 4063, 4064, 4065, 4066, 4067, 4068, 4069, 8140, 8141, 8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 16314, 16315, 16316, 16317, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, 16336, 16337, 16338, 32678, 32679, 32680, 32681, 32682, 32683, 32684, 32685, 32686, 32687, 32688, 32689, 32690, 32691, 32692, 32693, 32694, 32695, 32696, 32697, 32698, 32699, 32700, 32701, 32702, 32703, 32704, 32705, 65412, 65413, 65414, 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535, +}; + +static const uint8_t dnxhd_1238_ac_bits[257] = { + 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, +}; + +static const uint8_t dnxhd_1238_ac_level[257] = { + 1, 1, 2, 3, 0, 4, 5, 2, 6, 7, 8, 3, 9, 10, 11, 4, 12, 13, 14, 15, 16, 5, 17, 18, 19, 20, 21, 22, 6, 7, 23, 24, 25, 26, 27, 28, 29, 8, 9, 30, 31, 32, 33, 34, 35, 36, 37, 10, 11, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 12, 13, 14, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 15, 16, 17, 18, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 40, 25, 26, 27, 28, 29, 30, 38, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, +}; /* 0 is EOB */ + +static const uint8_t dnxhd_1238_ac_run_flag[257] = { + 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; + +static const uint8_t dnxhd_1238_ac_index_flag[257] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; + +static const uint16_t dnxhd_1238_run_codes[62] = { + 0, 4, 10, 11, 24, 25, 26, 27, 56, 57, 58, 59, 120, 242, 486, 487, 488, 489, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, +}; + +static const uint8_t dnxhd_1238_run_bits[62] = { + 1, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, +}; + +static const uint8_t dnxhd_1238_run[62] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 21, 17, 18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, +}; + +static const uint8_t dnxhd_1241_dc_codes[14] = { + 10, 62, 11, 12, 13, 0, 1, 2, 3, 4, 14, 30, 126, 127, +}; + +static const uint8_t dnxhd_1241_dc_bits[14] = { + 4, 6, 4, 4, 4, 3, 3, 3, 3, 3, 4, 5, 7, 7, +}; +static const uint16_t dnxhd_1241_ac_codes[257] = { + 0, 1, 4, 10, 11, 24, 25, 26, 54, 55, 56, 57, 116, 117, 118, 119, 240, 241, 242, 243, 244, 245, 492, 493, 494, 495, 496, 497, 498, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 4054, 4055, 4056, 4057, 4058, 4059, 4060, 4061, 4062, 4063, 4064, 4065, 4066, 4067, 4068, 4069, 8140, 8141, 8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 8157, 16316, 16317, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, 16336, 16337, 32676, 32677, 32678, 32679, 32680, 32681, 32682, 32683, 32684, 32685, 32686, 32687, 32688, 32689, 32690, 32691, 32692, 32693, 32694, 32695, 32696, 32697, 32698, 32699, 32700, 32701, 32702, 32703, 32704, 32705, 32706, 32707, 32708, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535, +}; + +static const uint8_t dnxhd_1241_ac_bits[257] = { + 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, +}; + +static const uint8_t dnxhd_1241_ac_level[257] = { + 1, 1, 2, 3, 0, 4, 5, 2, 6, 7, 8, 3, 9, 10, 11, 4, 12, 13, 14, 15, 16, 5, 17, 18, 19, 20, 21, 6, 7, 22, 23, 24, 25, 26, 27, 28, 29, 8, 9, 30, 31, 32, 33, 34, 35, 36, 37, 38, 10, 11, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 12, 13, 14, 15, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 1, 16, 17, 18, 19, 64, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, 22, 23, 24, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 25, 26, 27, 28, 29, 30, 31, 32, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, +}; + +static const uint8_t dnxhd_1241_ac_run_flag[257] = { + 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; + +static const uint8_t dnxhd_1241_ac_index_flag[257] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; + +static const uint16_t dnxhd_1241_run_codes[62] = { + 0, 4, 10, 11, 24, 25, 26, 27, 56, 57, 58, 59, 120, 242, 486, 487, 488, 489, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, +}; + +static const uint8_t dnxhd_1241_run_bits[62] = { + 1, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, +}; + +static const uint8_t dnxhd_1241_run[62] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 17, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, +}; + +static const uint8_t dnxhd_1251_dc_codes[12] = { + 0, 12, 13, 1, 2, 3, 4, 5, 14, 30, 62, 63, +}; +static const uint8_t dnxhd_1251_dc_bits[12] = { + 3, 4, 4, 3, 3, 3, 3, 3, 4, 5, 6, 6, +}; +static const uint16_t dnxhd_1251_ac_codes[257] = { + 0, 1, 4, 10, 11, 24, 25, 26, 54, 55, 56, 57, 116, 117, 118, 119, 240, 241, 242, 243, 244, 245, 492, 493, 494, 495, 496, 497, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 4052, 4053, 4054, 4055, 4056, 4057, 4058, 4059, 4060, 4061, 4062, 4063, 4064, 4065, 4066, 8134, 8135, 8136, 8137, 8138, 8139, 8140, 8141, 8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 16314, 16315, 16316, 16317, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, 16336, 16337, 16338, 16339, 32680, 32681, 32682, 32683, 32684, 32685, 32686, 32687, 32688, 32689, 32690, 32691, 32692, 32693, 32694, 32695, 32696, 32697, 32698, 32699, 32700, 32701, 32702, 32703, 32704, 32705, 32706, 32707, 32708, 32709, 32710, 32711, 32712, 32713, 32714, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535, +}; +static const uint8_t dnxhd_1251_ac_bits[257] = { + 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, +}; +static const uint8_t dnxhd_1251_ac_level[257] = { + 1, 1, 2, 3, 0, 4, 5, 2, 6, 7, 8, 3, 9, 10, 11, 4, 12, 13, 14, 15, 16, 5, 17, 18, 19, 20, 21, 6, 22, 23, 24, 25, 26, 27, 28, 29, 7, 8, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 9, 10, 11, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 12, 13, 14, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 15, 16, 17, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 18, 19, 20, 21, 22, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 23, 24, 25, 26, 27, 28, 59, 60, 61, 62, 63, 64, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, +}; +static const uint8_t dnxhd_1251_ac_run_flag[257] = { + 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; +static const uint8_t dnxhd_1251_ac_index_flag[257] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; +static const uint16_t dnxhd_1251_run_codes[62] = { + 0, 4, 5, 12, 26, 27, 28, 58, 118, 119, 120, 242, 486, 487, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, +}; +static const uint8_t dnxhd_1251_run_bits[62] = { + 1, 3, 3, 4, 5, 5, 5, 6, 7, 7, 7, 8, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, +}; +static const uint8_t dnxhd_1251_run[62] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, +}; + +static const uint8_t dnxhd_1252_dc_codes[12] = { + 0, 12, 13, 1, 2, 3, 4, 5, 14, 30, 62, 63, +}; +static const uint8_t dnxhd_1252_dc_bits[12] = { + 3, 4, 4, 3, 3, 3, 3, 3, 4, 5, 6, 6, +}; +static const uint16_t dnxhd_1252_ac_codes[257] = { + 0, 1, 4, 10, 11, 12, 26, 27, 56, 57, 58, 118, 119, 120, 242, 243, 244, 245, 246, 247, 496, 497, 498, 499, 500, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 4060, 4061, 4062, 4063, 4064, 4065, 4066, 4067, 4068, 4069, 4070, 4071, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 8157, 8158, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, 32672, 32673, 32674, 32675, 32676, 32677, 32678, 32679, 32680, 32681, 32682, 32683, 32684, 32685, 32686, 32687, 32688, 32689, 32690, 32691, 32692, 32693, 32694, 65390, 65391, 65392, 65393, 65394, 65395, 65396, 65397, 65398, 65399, 65400, 65401, 65402, 65403, 65404, 65405, 65406, 65407, 65408, 65409, 65410, 65411, 65412, 65413, 65414, 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535, +}; +static const uint8_t dnxhd_1252_ac_bits[257] = { + 2, 2, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, +}; +static const uint8_t dnxhd_1252_ac_level[257] = { + 1, 1, 2, 3, 2, 0, 4, 5, 6, 7, 3, 8, 9, 10, 11, 12, 13, 14, 4, 5, 15, 16, 17, 18, 6, 19, 20, 21, 22, 23, 24, 7, 8, 25, 26, 27, 28, 29, 30, 31, 32, 9, 10, 33, 34, 35, 36, 37, 38, 39, 40, 41, 11, 12, 13, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 14, 15, 16, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 17, 18, 19, 20, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 21, 22, 23, 24, 25, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, +}; +static const uint8_t dnxhd_1252_ac_run_flag[257] = { + 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; +static const uint8_t dnxhd_1252_ac_index_flag[257] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; +static const uint16_t dnxhd_1252_run_codes[62] = { + 0, 4, 5, 12, 26, 27, 28, 58, 118, 119, 120, 242, 486, 487, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, +}; +static const uint8_t dnxhd_1252_run_bits[62] = { + 1, 3, 3, 4, 5, 5, 5, 6, 7, 7, 7, 8, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, +}; +static const uint8_t dnxhd_1252_run[62] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, +}; + +const CIDEntry ff_dnxhd_cid_table[] = { + { 1237, 1920, 1080, 0, 606208, 606208, 4, 8, + dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight, + dnxhd_1237_dc_codes, dnxhd_1237_dc_bits, + dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_level, + dnxhd_1237_ac_run_flag, dnxhd_1237_ac_index_flag, + dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run, + { 115, 120, 145, 240, 290 } }, + { 1238, 1920, 1080, 0, 917504, 917504, 4, 8, + dnxhd_1238_luma_weight, dnxhd_1238_chroma_weight, + dnxhd_1238_dc_codes, dnxhd_1238_dc_bits, + dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level, + dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag, + dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run, + { 175, 185, 220, 365, 440 } }, + { 1241, 1920, 1080, 1, 917504, 458752, 6, 10, + dnxhd_1241_luma_weight, dnxhd_1241_chroma_weight, + dnxhd_1241_dc_codes, dnxhd_1241_dc_bits, + dnxhd_1241_ac_codes, dnxhd_1241_ac_bits, dnxhd_1241_ac_level, + dnxhd_1241_ac_run_flag, dnxhd_1241_ac_index_flag, + dnxhd_1241_run_codes, dnxhd_1241_run_bits, dnxhd_1241_run, + { 185, 220 } }, + { 1242, 1920, 1080, 1, 606208, 303104, 4, 8, + dnxhd_1242_luma_weight, dnxhd_1242_chroma_weight, + dnxhd_1237_dc_codes, dnxhd_1237_dc_bits, + dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_level, + dnxhd_1237_ac_run_flag, dnxhd_1237_ac_index_flag, + dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run, + { 120, 145 } }, + { 1243, 1920, 1080, 1, 917504, 458752, 4, 8, + dnxhd_1243_luma_weight, dnxhd_1243_chroma_weight, + dnxhd_1238_dc_codes, dnxhd_1238_dc_bits, + dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level, + dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag, + dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run, + { 185, 220 } }, + { 1251, 1280, 720, 0, 458752, 458752, 4, 8, + dnxhd_1251_luma_weight, dnxhd_1251_chroma_weight, + dnxhd_1251_dc_codes, dnxhd_1251_dc_bits, + dnxhd_1251_ac_codes, dnxhd_1251_ac_bits, dnxhd_1251_ac_level, + dnxhd_1251_ac_run_flag, dnxhd_1251_ac_index_flag, + dnxhd_1251_run_codes, dnxhd_1251_run_bits, dnxhd_1251_run, + { 90, 110, 175, 220 } }, + { 1252, 1280, 720, 0, 303104, 303104, 4, 8, + dnxhd_1252_luma_weight, dnxhd_1252_chroma_weight, + dnxhd_1252_dc_codes, dnxhd_1252_dc_bits, + dnxhd_1252_ac_codes, dnxhd_1252_ac_bits, dnxhd_1252_ac_level, + dnxhd_1252_ac_run_flag, dnxhd_1252_ac_index_flag, + dnxhd_1252_run_codes, dnxhd_1252_run_bits, dnxhd_1252_run, + { 60, 75, 115, 145 } }, + { 1253, 1920, 1080, 0, 188416, 188416, 4, 8, + dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight, + dnxhd_1237_dc_codes, dnxhd_1237_dc_bits, + dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_level, + dnxhd_1237_ac_run_flag, dnxhd_1237_ac_index_flag, + dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run, + { 36, 45, 75, 90 } }, +}; + +int ff_dnxhd_get_cid_table(int cid) +{ + int i; + for (i = 0; i < sizeof(ff_dnxhd_cid_table)/sizeof(CIDEntry); i++) + if (ff_dnxhd_cid_table[i].cid == cid) + return i; + return -1; +} + +int ff_dnxhd_find_cid(AVCodecContext *avctx) +{ + int i, j; + int mbs = avctx->bit_rate/1000000; + for (i = 0; i < sizeof(ff_dnxhd_cid_table)/sizeof(CIDEntry); i++) { + const CIDEntry *cid = &ff_dnxhd_cid_table[i]; + if (cid->width == avctx->width && cid->height == avctx->height && + cid->interlaced == !!(avctx->flags & CODEC_FLAG_INTERLACED_DCT) && + cid->bit_depth == 8) { // until 10 bit is supported + for (j = 0; j < sizeof(cid->bit_rates); j++) { + if (cid->bit_rates[j] == mbs) + return cid->cid; + } + } + } + return 0; +} diff --git a/contrib/ffmpeg/libavcodec/dnxhddata.h b/contrib/ffmpeg/libavcodec/dnxhddata.h index 5d5aa528b..1bd028e08 100644 --- a/contrib/ffmpeg/libavcodec/dnxhddata.h +++ b/contrib/ffmpeg/libavcodec/dnxhddata.h @@ -19,88 +19,33 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -static const uint8_t dnxhd_1238_luma_weigth[] = { - 0, 32, 32, 33, 34, 33, 33, 33, - 33, 33, 33, 33, 33, 35, 37, 37, - 36, 36, 35, 36, 38, 38, 36, 35, - 36, 37, 38, 41, 42, 41, 39, 38, - 38, 38, 39, 41, 42, 41, 39, 39, - 40, 41, 43, 44, 44, 44, 44, 44, - 45, 47, 47, 47, 49, 50, 51, 51, - 51, 53, 55, 57, 58, 59, 57, 57, -}; - -static const uint8_t dnxhd_1238_chroma_weigth[] = { - 0, 32, 35, 35, 35, 34, 34, 35, - 39, 43, 45, 45, 41, 39, 40, 41, - 42, 44, 48, 55, 59, 63, 65, 59, - 53, 52, 52, 55, 61, 62, 58, 58, - 63, 66, 66, 65, 70, 74, 70, 66, - 65, 68, 75, 77, 74, 74, 77, 76, - 73, 73, 73, 73, 76, 80, 89, 90, - 82, 77, 80, 86, 84, 82, 82, 82, -}; - -/* FIXME permute */ -static const uint8_t dnxhd_1243_luma_weigth[] = { - 0,32,35,35,38,40,44,45, - 32,33,35,35,39,42,44,45, - 33,35,34,37,41,42,45,45, - 35,35,37,40,41,44,45,48, - 35,37,38,40,43,45,47,48, - 36,36,38,40,45,47,48,47, - 35,36,38,41,45,46,47,48, - 36,37,39,41,44,45,47,47, -}; - -/* FIXME permute */ -static const uint8_t dnxhd_1243_chroma_weigth[] = { - 0,32,37,39,41,42,45,45, - 36,36,39,41,43,45,46,45, - 37,41,41,43,45,44,45,46, - 43,42,43,46,44,45,46,48, - 43,44,47,45,44,46,47,49, - 44,46,44,45,45,47,48,47, - 44,42,46,44,45,46,47,48, - 41,43,45,44,45,46,47,47, -}; - -static const uint8_t dnxhd_1238_dc_codes[12] = { - 0, 12, 13, 1, 2, 3, 4, 5, 14, 30, 62, 63, -}; - -static const uint8_t dnxhd_1238_dc_bits[12] = { - 3, 4, 4, 3, 3, 3, 3, 3, 4, 5, 6, 6, -}; - -static const uint16_t dnxhd_1238_ac_codes[257] = { - 0, 1, 4, 10, 11, 24, 25, 26, 54, 55, 56, 57, 116, 117, 118, 119, 240, 241, 242, 243, 244, 245, 492, 493, 494, 495, 496, 497, 498, 499, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 4056, 4057, 4058, 4059, 4060, 4061, 4062, 4063, 4064, 4065, 4066, 4067, 4068, 4069, 8140, 8141, 8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 16314, 16315, 16316, 16317, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, 16336, 16337, 16338, 32678, 32679, 32680, 32681, 32682, 32683, 32684, 32685, 32686, 32687, 32688, 32689, 32690, 32691, 32692, 32693, 32694, 32695, 32696, 32697, 32698, 32699, 32700, 32701, 32702, 32703, 32704, 32705, 65412, 65413, 65414, 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535, -}; - -static const uint8_t dnxhd_1238_ac_bits[257] = { - 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, -}; - -static const uint8_t dnxhd_1238_ac_level[257] = { - 1, 1, 2, 3, 0, 4, 5, 2, 6, 7, 8, 3, 9, 10, 11, 4, 12, 13, 14, 15, 16, 5, 17, 18, 19, 20, 21, 22, 6, 7, 23, 24, 25, 26, 27, 28, 29, 8, 9, 30, 31, 32, 33, 34, 35, 36, 37, 10, 11, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 12, 13, 14, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 15, 16, 17, 18, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 40, 25, 26, 27, 28, 29, 30, 38, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, -}; /* 0 is EOB */ - -static const uint8_t dnxhd_1238_ac_run_flag[257] = { - 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -}; - -static const uint8_t dnxhd_1238_ac_index_flag[257] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -}; - -static const uint16_t dnxhd_1238_run_codes[62] = { - 0, 4, 10, 11, 24, 25, 26, 27, 56, 57, 58, 59, 120, 242, 486, 487, 488, 489, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, -}; - -static const uint8_t dnxhd_1238_run_bits[62] = { - 1, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, -}; - -static const uint8_t dnxhd_1238_run[62] = { - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 21, 17, 18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -}; +#ifndef FFMPEG_DNXHDDATA_H +#define FFMPEG_DNXHDDATA_H + +#include +#include "avcodec.h" + +typedef struct { + int cid; + unsigned int width, height; + int interlaced; + unsigned int frame_size; + unsigned int coding_unit_size; + int index_bits; + int bit_depth; + const uint8_t *luma_weight, *chroma_weight; + const uint8_t *dc_codes, *dc_bits; + const uint16_t *ac_codes; + const uint8_t *ac_bits, *ac_level; + const uint8_t *ac_run_flag, *ac_index_flag; + const uint16_t *run_codes; + const uint8_t *run_bits, *run; + int bit_rates[5]; ///< Helpher to choose variants, rounded to nearest 5Mb/s +} CIDEntry; + +extern const CIDEntry ff_dnxhd_cid_table[]; + +int ff_dnxhd_get_cid_table(int cid); +int ff_dnxhd_find_cid(AVCodecContext *avctx); + +#endif /* FFMPEG_DNXHDDATA_H */ diff --git a/contrib/ffmpeg/libavcodec/dnxhddec.c b/contrib/ffmpeg/libavcodec/dnxhddec.c index 224439c47..8d3977ed5 100644 --- a/contrib/ffmpeg/libavcodec/dnxhddec.c +++ b/contrib/ffmpeg/libavcodec/dnxhddec.c @@ -28,22 +28,6 @@ #include "dsputil.h" #include "mpegvideo.h" -typedef struct { - int cid; - unsigned int width, height; - int interlaced; - unsigned int frame_size; - int index_bits; - int bit_depth; - const uint8_t *luma_weigth, *chroma_weigth; - const uint8_t *dc_codes, *dc_bits; - const uint16_t *ac_codes; - const uint8_t *ac_bits, *ac_level; - const uint8_t *ac_run_flag, *ac_index_flag; - const uint16_t *run_codes; - const uint8_t *run_bits, *run; -} CIDEntry; - typedef struct { AVCodecContext *avctx; AVFrame picture; @@ -53,11 +37,7 @@ typedef struct { unsigned int mb_width, mb_height; uint32_t mb_scan_index[68]; /* max for 1080p */ int cur_field; ///< current interlaced field - int index_bits; ///< length of index value VLC ac_vlc, dc_vlc, run_vlc; - const uint8_t *ac_level, *run; - const uint8_t *ac_run_flag, *ac_index_flag; - const uint8_t *luma_weigth, *chroma_weigth; int last_dc[3]; DSPContext dsp; DECLARE_ALIGNED_16(DCTELEM, blocks[8][64]); @@ -65,32 +45,8 @@ typedef struct { const CIDEntry *cid_table; } DNXHDContext; -static const CIDEntry cid_table[] = { - { 1238, 1920, 1080, 0, 917504, 4, 8, - dnxhd_1238_luma_weigth, dnxhd_1238_chroma_weigth, - dnxhd_1238_dc_codes, dnxhd_1238_dc_bits, - dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level, - dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag, - dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run }, -/* { 1243, 1920, 1080, 1, 917504, 4, 8, */ -/* dnxhd_1243_luma_weigth, dnxhd_1243_chroma_weigth, */ -/* dnxhd_1238_dc_codes, dnxhd_1238_dc_bits, */ -/* dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level, */ -/* dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag, */ -/* dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run }, */ -}; - -static int dnxhd_get_cid_table(int cid) -{ - int i; - for (i = 0; i < sizeof(cid_table)/sizeof(CIDEntry); i++) - if (cid_table[i].cid == cid) - return i; - return -1; -} - #define DNXHD_VLC_BITS 9 -#define DNXHD_DC_VLC_BITS 6 +#define DNXHD_DC_VLC_BITS 7 static int dnxhd_decode_init(AVCodecContext *avctx) { @@ -108,36 +64,27 @@ static int dnxhd_init_vlc(DNXHDContext *ctx, int cid) if (!ctx->cid_table) { int index; - if ((index = dnxhd_get_cid_table(cid)) < 0) { + if ((index = ff_dnxhd_get_cid_table(cid)) < 0) { av_log(ctx->avctx, AV_LOG_ERROR, "unsupported cid %d\n", cid); return -1; } - ctx->cid_table = &cid_table[index]; + ctx->cid_table = &ff_dnxhd_cid_table[index]; init_vlc(&ctx->ac_vlc, DNXHD_VLC_BITS, 257, - cid_table->ac_bits, 1, 1, - cid_table->ac_codes, 2, 2, 0); - init_vlc(&ctx->dc_vlc, DNXHD_DC_VLC_BITS, 12, - cid_table->dc_bits, 1, 1, - cid_table->dc_codes, 1, 1, 0); + ctx->cid_table->ac_bits, 1, 1, + ctx->cid_table->ac_codes, 2, 2, 0); + init_vlc(&ctx->dc_vlc, DNXHD_DC_VLC_BITS, ctx->cid_table->bit_depth+4, + ctx->cid_table->dc_bits, 1, 1, + ctx->cid_table->dc_codes, 1, 1, 0); init_vlc(&ctx->run_vlc, DNXHD_VLC_BITS, 62, - cid_table->run_bits, 1, 1, - cid_table->run_codes, 2, 2, 0); - - ctx->run = cid_table->run; - ctx->ac_level = cid_table->ac_level; - ctx->ac_run_flag = cid_table->ac_run_flag; - ctx->ac_index_flag = cid_table->ac_index_flag; - ctx->luma_weigth = cid_table->luma_weigth; - ctx->chroma_weigth = cid_table->chroma_weigth; - - ctx->index_bits = cid_table->index_bits; + ctx->cid_table->run_bits, 1, 1, + ctx->cid_table->run_codes, 2, 2, 0); ff_init_scantable(ctx->dsp.idct_permutation, &ctx->scantable, ff_zigzag_direct); } return 0; } -static int dnxhd_decode_header(DNXHDContext *ctx, uint8_t *buf, int buf_size) +static int dnxhd_decode_header(DNXHDContext *ctx, const uint8_t *buf, int buf_size, int first_field) { static const uint8_t header_prefix[] = { 0x00, 0x00, 0x02, 0x80, 0x01 }; int i; @@ -149,9 +96,11 @@ static int dnxhd_decode_header(DNXHDContext *ctx, uint8_t *buf, int buf_size) av_log(ctx->avctx, AV_LOG_ERROR, "error in header\n"); return -1; } - if (buf[5] & 2) {/* interlaced FIXME top or bottom */ + if (buf[5] & 2) { /* interlaced */ + ctx->cur_field = buf[5] & 1; ctx->picture.interlaced_frame = 1; - av_log(ctx->avctx, AV_LOG_DEBUG, "interlaced %d\n", buf[5] & 3); + ctx->picture.top_field_first = first_field ^ ctx->cur_field; + av_log(ctx->avctx, AV_LOG_DEBUG, "interlaced %d, cur field %d\n", buf[5] & 3, ctx->cur_field); } ctx->height = AV_RB16(buf + 0x18); @@ -159,7 +108,7 @@ static int dnxhd_decode_header(DNXHDContext *ctx, uint8_t *buf, int buf_size) dprintf(ctx->avctx, "width %d, heigth %d\n", ctx->width, ctx->height); - if (buf[0x21] & 0x80) { + if (buf[0x21] & 0x40) { av_log(ctx->avctx, AV_LOG_ERROR, "10 bit per component\n"); return -1; } @@ -170,7 +119,7 @@ static int dnxhd_decode_header(DNXHDContext *ctx, uint8_t *buf, int buf_size) if (dnxhd_init_vlc(ctx, ctx->cid) < 0) return -1; - if (buf_size < ctx->cid_table->frame_size) { + if (buf_size < ctx->cid_table->coding_unit_size) { av_log(ctx->avctx, AV_LOG_ERROR, "incorrect frame size\n"); return -1; } @@ -212,10 +161,10 @@ static void dnxhd_decode_dct_block(DNXHDContext *ctx, DCTELEM *block, int n, int if (n&2) { component = 1 + (n&1); - weigth_matrix = ctx->chroma_weigth; + weigth_matrix = ctx->cid_table->chroma_weight; } else { component = 0; - weigth_matrix = ctx->luma_weigth; + weigth_matrix = ctx->cid_table->luma_weight; } ctx->last_dc[component] += dnxhd_decode_dc(ctx); @@ -224,38 +173,42 @@ static void dnxhd_decode_dct_block(DNXHDContext *ctx, DCTELEM *block, int n, int for (i = 1; ; i++) { index = get_vlc2(&ctx->gb, ctx->ac_vlc.table, DNXHD_VLC_BITS, 2); //av_log(ctx->avctx, AV_LOG_DEBUG, "index %d\n", index); - level = ctx->ac_level[index]; + level = ctx->cid_table->ac_level[index]; if (!level) { /* EOB */ //av_log(ctx->avctx, AV_LOG_DEBUG, "EOB\n"); return; } sign = get_sbits(&ctx->gb, 1); - if (ctx->ac_index_flag[index]) { - level += get_bits(&ctx->gb, ctx->index_bits)<<6; + if (ctx->cid_table->ac_index_flag[index]) { + level += get_bits(&ctx->gb, ctx->cid_table->index_bits)<<6; } - if (ctx->ac_run_flag[index]) { + if (ctx->cid_table->ac_run_flag[index]) { index2 = get_vlc2(&ctx->gb, ctx->run_vlc.table, DNXHD_VLC_BITS, 2); - i += ctx->run[index2]; + i += ctx->cid_table->run[index2]; } - j = ctx->scantable.permutated[i]; - //av_log(ctx->avctx, AV_LOG_DEBUG, "j %d\n", j); - //av_log(ctx->avctx, AV_LOG_DEBUG, "level %d, weigth %d\n", level, weigth_matrix[i]); - level = (2*level+1) * qscale * weigth_matrix[i]; - if (weigth_matrix[i] != 32) // FIXME 10bit - level += 32; - level >>= 6; - level = (level^sign) - sign; - if (i > 63) { av_log(ctx->avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\n", n, i); return; } + j = ctx->scantable.permutated[i]; + //av_log(ctx->avctx, AV_LOG_DEBUG, "j %d\n", j); + //av_log(ctx->avctx, AV_LOG_DEBUG, "level %d, weigth %d\n", level, weigth_matrix[i]); + level = (2*level+1) * qscale * weigth_matrix[i]; + if (ctx->cid_table->bit_depth == 10) { + if (weigth_matrix[i] != 8) + level += 8; + level >>= 4; + } else { + if (weigth_matrix[i] != 32) + level += 32; + level >>= 6; + } //av_log(NULL, AV_LOG_DEBUG, "i %d, j %d, end level %d\n", i, j, level); - block[j] = level; + block[j] = (level^sign) - sign; } } @@ -277,10 +230,22 @@ static int dnxhd_decode_macroblock(DNXHDContext *ctx, int x, int y) for (i = 0; i < 8; i++) { dnxhd_decode_dct_block(ctx, ctx->blocks[i], i, qscale); } + + if (ctx->picture.interlaced_frame) { + dct_linesize_luma <<= 1; + dct_linesize_chroma <<= 1; + } + dest_y = ctx->picture.data[0] + ((y * dct_linesize_luma) << 4) + (x << 4); dest_u = ctx->picture.data[1] + ((y * dct_linesize_chroma) << 4) + (x << 3); dest_v = ctx->picture.data[2] + ((y * dct_linesize_chroma) << 4) + (x << 3); + if (ctx->cur_field) { + dest_y += ctx->picture.linesize[0]; + dest_u += ctx->picture.linesize[1]; + dest_v += ctx->picture.linesize[2]; + } + dct_offset = dct_linesize_luma << 3; ctx->dsp.idct_put(dest_y, dct_linesize_luma, ctx->blocks[0]); ctx->dsp.idct_put(dest_y + 8, dct_linesize_luma, ctx->blocks[1]); @@ -298,11 +263,13 @@ static int dnxhd_decode_macroblock(DNXHDContext *ctx, int x, int y) return 0; } -static int dnxhd_decode_macroblocks(DNXHDContext *ctx, uint8_t *buf, int buf_size) +static int dnxhd_decode_macroblocks(DNXHDContext *ctx, const uint8_t *buf, int buf_size) { int x, y; for (y = 0; y < ctx->mb_height; y++) { - memset(ctx->last_dc, 4, sizeof(ctx->last_dc)); // 4 for levels +128 + ctx->last_dc[0] = + ctx->last_dc[1] = + ctx->last_dc[2] = 1<<(ctx->cid_table->bit_depth+2); // for levels +2^(bitdepth-1) init_get_bits(&ctx->gb, buf + ctx->mb_scan_index[y], (buf_size - ctx->mb_scan_index[y]) << 3); for (x = 0; x < ctx->mb_width; x++) { //START_TIMER; @@ -314,14 +281,16 @@ static int dnxhd_decode_macroblocks(DNXHDContext *ctx, uint8_t *buf, int buf_siz } static int dnxhd_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { DNXHDContext *ctx = avctx->priv_data; AVFrame *picture = data; + int first_field = 1; dprintf(avctx, "frame size %d\n", buf_size); - if (dnxhd_decode_header(ctx, buf, buf_size) < 0) + decode_coding_unit: + if (dnxhd_decode_header(ctx, buf, buf_size, first_field) < 0) return -1; avctx->pix_fmt = PIX_FMT_YUV422P; @@ -329,15 +298,24 @@ static int dnxhd_decode_frame(AVCodecContext *avctx, void *data, int *data_size, return -1; avcodec_set_dimensions(avctx, ctx->width, ctx->height); - if (ctx->picture.data[0]) - avctx->release_buffer(avctx, &ctx->picture); - if (avctx->get_buffer(avctx, &ctx->picture) < 0) { - av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + if (first_field) { + if (ctx->picture.data[0]) + avctx->release_buffer(avctx, &ctx->picture); + if (avctx->get_buffer(avctx, &ctx->picture) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } } dnxhd_decode_macroblocks(ctx, buf + 0x280, buf_size - 0x280); + if (first_field && ctx->picture.interlaced_frame) { + buf += ctx->cid_table->coding_unit_size; + buf_size -= ctx->cid_table->coding_unit_size; + first_field = 0; + goto decode_coding_unit; + } + *picture = ctx->picture; *data_size = sizeof(AVPicture); return buf_size; @@ -347,7 +325,7 @@ static int dnxhd_decode_close(AVCodecContext *avctx) { DNXHDContext *ctx = avctx->priv_data; - if(ctx->picture.data[0]) + if (ctx->picture.data[0]) avctx->release_buffer(avctx, &ctx->picture); free_vlc(&ctx->ac_vlc); free_vlc(&ctx->dc_vlc); diff --git a/contrib/ffmpeg/libavcodec/dnxhdenc.c b/contrib/ffmpeg/libavcodec/dnxhdenc.c new file mode 100644 index 000000000..3da6a1a67 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/dnxhdenc.c @@ -0,0 +1,847 @@ +/* + * VC3/DNxHD encoder + * Copyright (c) 2007 Baptiste Coudurier + * + * VC-3 encoder funded by the British Broadcasting Corporation + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +//#define DEBUG +#define RC_VARIANCE 1 // use variance or ssd for fast rc + +#include "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" +#include "dnxhddata.h" + +typedef struct { + uint16_t mb; + int value; +} RCCMPEntry; + +typedef struct { + int ssd; + int bits; +} RCEntry; + +int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); + +typedef struct DNXHDEncContext { + MpegEncContext m; ///< Used for quantization dsp functions + + AVFrame frame; + int cid; + const CIDEntry *cid_table; + uint8_t *msip; ///< Macroblock Scan Indices Payload + uint32_t *slice_size; + + struct DNXHDEncContext *thread[MAX_THREADS]; + + unsigned dct_y_offset; + unsigned dct_uv_offset; + int interlaced; + int cur_field; + + DECLARE_ALIGNED_16(DCTELEM, blocks[8][64]); + + int (*qmatrix_c) [64]; + int (*qmatrix_l) [64]; + uint16_t (*qmatrix_l16)[2][64]; + uint16_t (*qmatrix_c16)[2][64]; + + unsigned frame_bits; + uint8_t *src[3]; + + uint16_t *table_vlc_codes; + uint8_t *table_vlc_bits; + uint16_t *table_run_codes; + uint8_t *table_run_bits; + + /** Rate control */ + unsigned slice_bits; + unsigned qscale; + unsigned lambda; + + unsigned thread_size; + + uint16_t *mb_bits; + uint8_t *mb_qscale; + + RCCMPEntry *mb_cmp; + RCEntry (*mb_rc)[8160]; +} DNXHDEncContext; + +#define LAMBDA_FRAC_BITS 10 + +static int dnxhd_init_vlc(DNXHDEncContext *ctx) +{ + int i; + + CHECKED_ALLOCZ(ctx->table_vlc_codes, 449*2); + CHECKED_ALLOCZ(ctx->table_vlc_bits, 449); + CHECKED_ALLOCZ(ctx->table_run_codes, 63*2); + CHECKED_ALLOCZ(ctx->table_run_bits, 63); + + for (i = 0; i < 257; i++) { + int level = ctx->cid_table->ac_level[i] + + (ctx->cid_table->ac_run_flag[i] << 7) + (ctx->cid_table->ac_index_flag[i] << 8); + assert(level < 449); + if (ctx->cid_table->ac_level[i] == 64 && ctx->cid_table->ac_index_flag[i]) + level -= 64; // use 0+(1<<8) level + ctx->table_vlc_codes[level] = ctx->cid_table->ac_codes[i]; + ctx->table_vlc_bits [level] = ctx->cid_table->ac_bits[i]; + } + for (i = 0; i < 62; i++) { + int run = ctx->cid_table->run[i]; + assert(run < 63); + ctx->table_run_codes[run] = ctx->cid_table->run_codes[i]; + ctx->table_run_bits [run] = ctx->cid_table->run_bits[i]; + } + return 0; + fail: + return -1; +} + +static int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias) +{ + // init first elem to 1 to avoid div by 0 in convert_matrix + uint16_t weight_matrix[64] = {1,}; // convert_matrix needs uint16_t* + int qscale, i; + + CHECKED_ALLOCZ(ctx->qmatrix_l, (ctx->m.avctx->qmax+1) * 64 * sizeof(int)); + CHECKED_ALLOCZ(ctx->qmatrix_c, (ctx->m.avctx->qmax+1) * 64 * sizeof(int)); + CHECKED_ALLOCZ(ctx->qmatrix_l16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t)); + CHECKED_ALLOCZ(ctx->qmatrix_c16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t)); + + for (i = 1; i < 64; i++) { + int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]]; + weight_matrix[j] = ctx->cid_table->luma_weight[i]; + } + ff_convert_matrix(&ctx->m.dsp, ctx->qmatrix_l, ctx->qmatrix_l16, weight_matrix, + ctx->m.intra_quant_bias, 1, ctx->m.avctx->qmax, 1); + for (i = 1; i < 64; i++) { + int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]]; + weight_matrix[j] = ctx->cid_table->chroma_weight[i]; + } + ff_convert_matrix(&ctx->m.dsp, ctx->qmatrix_c, ctx->qmatrix_c16, weight_matrix, + ctx->m.intra_quant_bias, 1, ctx->m.avctx->qmax, 1); + for (qscale = 1; qscale <= ctx->m.avctx->qmax; qscale++) { + for (i = 0; i < 64; i++) { + ctx->qmatrix_l [qscale] [i] <<= 2; ctx->qmatrix_c [qscale] [i] <<= 2; + ctx->qmatrix_l16[qscale][0][i] <<= 2; ctx->qmatrix_l16[qscale][1][i] <<= 2; + ctx->qmatrix_c16[qscale][0][i] <<= 2; ctx->qmatrix_c16[qscale][1][i] <<= 2; + } + } + return 0; + fail: + return -1; +} + +static int dnxhd_init_rc(DNXHDEncContext *ctx) +{ + CHECKED_ALLOCZ(ctx->mb_rc, 8160*ctx->m.avctx->qmax*sizeof(RCEntry)); + if (ctx->m.avctx->mb_decision != FF_MB_DECISION_RD) + CHECKED_ALLOCZ(ctx->mb_cmp, ctx->m.mb_num*sizeof(RCCMPEntry)); + + ctx->frame_bits = (ctx->cid_table->coding_unit_size - 640 - 4) * 8; + ctx->qscale = 1; + ctx->lambda = 2<priv_data; + int i, index; + + ctx->cid = ff_dnxhd_find_cid(avctx); + if (!ctx->cid || avctx->pix_fmt != PIX_FMT_YUV422P) { + av_log(avctx, AV_LOG_ERROR, "video parameters incompatible with DNxHD\n"); + return -1; + } + av_log(avctx, AV_LOG_DEBUG, "cid %d\n", ctx->cid); + + index = ff_dnxhd_get_cid_table(ctx->cid); + ctx->cid_table = &ff_dnxhd_cid_table[index]; + + ctx->m.avctx = avctx; + ctx->m.mb_intra = 1; + ctx->m.h263_aic = 1; + + dsputil_init(&ctx->m.dsp, avctx); + ff_dct_common_init(&ctx->m); + if (!ctx->m.dct_quantize) + ctx->m.dct_quantize = dct_quantize_c; + + ctx->m.mb_height = (avctx->height + 15) / 16; + ctx->m.mb_width = (avctx->width + 15) / 16; + + if (avctx->flags & CODEC_FLAG_INTERLACED_DCT) { + ctx->interlaced = 1; + ctx->m.mb_height /= 2; + } + + ctx->m.mb_num = ctx->m.mb_height * ctx->m.mb_width; + + if (avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS) + ctx->m.intra_quant_bias = avctx->intra_quant_bias; + if (dnxhd_init_qmat(ctx, ctx->m.intra_quant_bias, 0) < 0) // XXX tune lbias/cbias + return -1; + + if (dnxhd_init_vlc(ctx) < 0) + return -1; + if (dnxhd_init_rc(ctx) < 0) + return -1; + + CHECKED_ALLOCZ(ctx->slice_size, ctx->m.mb_height*sizeof(uint32_t)); + CHECKED_ALLOCZ(ctx->mb_bits, ctx->m.mb_num *sizeof(uint16_t)); + CHECKED_ALLOCZ(ctx->mb_qscale, ctx->m.mb_num *sizeof(uint8_t)); + + ctx->frame.key_frame = 1; + ctx->frame.pict_type = FF_I_TYPE; + ctx->m.avctx->coded_frame = &ctx->frame; + + if (avctx->thread_count > MAX_THREADS || (avctx->thread_count > ctx->m.mb_height)) { + av_log(avctx, AV_LOG_ERROR, "too many threads\n"); + return -1; + } + + ctx->thread[0] = ctx; + for (i = 1; i < avctx->thread_count; i++) { + ctx->thread[i] = av_malloc(sizeof(DNXHDEncContext)); + memcpy(ctx->thread[i], ctx, sizeof(DNXHDEncContext)); + } + + for (i = 0; i < avctx->thread_count; i++) { + ctx->thread[i]->m.start_mb_y = (ctx->m.mb_height*(i ) + avctx->thread_count/2) / avctx->thread_count; + ctx->thread[i]->m.end_mb_y = (ctx->m.mb_height*(i+1) + avctx->thread_count/2) / avctx->thread_count; + } + + return 0; + fail: //for CHECKED_ALLOCZ + return -1; +} + +static int dnxhd_write_header(AVCodecContext *avctx, uint8_t *buf) +{ + DNXHDEncContext *ctx = avctx->priv_data; + const uint8_t header_prefix[5] = { 0x00,0x00,0x02,0x80,0x01 }; + + memcpy(buf, header_prefix, 5); + buf[5] = ctx->interlaced ? ctx->cur_field+2 : 0x01; + buf[6] = 0x80; // crc flag off + buf[7] = 0xa0; // reserved + AV_WB16(buf + 0x18, avctx->height); // ALPF + AV_WB16(buf + 0x1a, avctx->width); // SPL + AV_WB16(buf + 0x1d, avctx->height); // NAL + + buf[0x21] = 0x38; // FIXME 8 bit per comp + buf[0x22] = 0x88 + (ctx->frame.interlaced_frame<<2); + AV_WB32(buf + 0x28, ctx->cid); // CID + buf[0x2c] = ctx->interlaced ? 0 : 0x80; + + buf[0x5f] = 0x01; // UDL + + buf[0x167] = 0x02; // reserved + AV_WB16(buf + 0x16a, ctx->m.mb_height * 4 + 4); // MSIPS + buf[0x16d] = ctx->m.mb_height; // Ns + buf[0x16f] = 0x10; // reserved + + ctx->msip = buf + 0x170; + return 0; +} + +static av_always_inline void dnxhd_encode_dc(DNXHDEncContext *ctx, int diff) +{ + int nbits; + if (diff < 0) { + nbits = av_log2_16bit(-2*diff); + diff--; + } else { + nbits = av_log2_16bit(2*diff); + } + put_bits(&ctx->m.pb, ctx->cid_table->dc_bits[nbits] + nbits, + (ctx->cid_table->dc_codes[nbits]<m.last_dc[n]); + ctx->m.last_dc[n] = block[0]; + + for (i = 1; i <= last_index; i++) { + j = ctx->m.intra_scantable.permutated[i]; + slevel = block[j]; + if (slevel) { + int run_level = i - last_non_zero - 1; + int sign; + MASK_ABS(sign, slevel); + if (slevel > 64) { + offset = (slevel-1) >> 6; + slevel = 256 | (slevel & 63); // level 64 is treated as 0 + } + if (run_level) + slevel |= 128; + put_bits(&ctx->m.pb, ctx->table_vlc_bits[slevel]+1, (ctx->table_vlc_codes[slevel]<<1)|(sign&1)); + if (offset) { + put_bits(&ctx->m.pb, 4, offset); + offset = 0; + } + if (run_level) + put_bits(&ctx->m.pb, ctx->table_run_bits[run_level], ctx->table_run_codes[run_level]); + last_non_zero = i; + } + } + put_bits(&ctx->m.pb, ctx->table_vlc_bits[0], ctx->table_vlc_codes[0]); // EOB +} + +static av_always_inline void dnxhd_unquantize_c(DNXHDEncContext *ctx, DCTELEM *block, int n, int qscale, int last_index) +{ + const uint8_t *weight_matrix; + int level; + int i; + + weight_matrix = (n&2) ? ctx->cid_table->chroma_weight : ctx->cid_table->luma_weight; + + for (i = 1; i <= last_index; i++) { + int j = ctx->m.intra_scantable.permutated[i]; + level = block[j]; + if (level) { + if (level < 0) { + level = (1-2*level) * qscale * weight_matrix[i]; + if (weight_matrix[i] != 32) + level += 32; + level >>= 6; + level = -level; + } else { + level = (2*level+1) * qscale * weight_matrix[i]; + if (weight_matrix[i] != 32) + level += 32; + level >>= 6; + } + block[j] = level; + } + } +} + +static av_always_inline int dnxhd_ssd_block(DCTELEM *qblock, DCTELEM *block) +{ + int score = 0; + int i; + for (i = 0; i < 64; i++) + score += (block[i]-qblock[i])*(block[i]-qblock[i]); + return score; +} + +static av_always_inline int dnxhd_calc_ac_bits(DNXHDEncContext *ctx, DCTELEM *block, int last_index) +{ + int last_non_zero = 0; + int bits = 0; + int i, j, level; + for (i = 1; i <= last_index; i++) { + j = ctx->m.intra_scantable.permutated[i]; + level = block[j]; + if (level) { + int run_level = i - last_non_zero - 1; + level = FFABS(level); + if (level > 64) { + level = 256 | (level & 63); // level 64 is treated as 0 + bits += 4; + } + level |= (!!run_level)<<7; + bits += ctx->table_vlc_bits[level]+1 + ctx->table_run_bits[run_level]; + last_non_zero = i; + } + } + return bits; +} + +static av_always_inline void dnxhd_get_pixels_4x8(DCTELEM *restrict block, const uint8_t *pixels, int line_size) +{ + int i; + for (i = 0; i < 4; i++) { + block[0] = pixels[0]; + block[1] = pixels[1]; + block[2] = pixels[2]; + block[3] = pixels[3]; + block[4] = pixels[4]; + block[5] = pixels[5]; + block[6] = pixels[6]; + block[7] = pixels[7]; + pixels += line_size; + block += 8; + } + memcpy(block , block- 8, sizeof(*block)*8); + memcpy(block+ 8, block-16, sizeof(*block)*8); + memcpy(block+16, block-24, sizeof(*block)*8); + memcpy(block+24, block-32, sizeof(*block)*8); +} + +static av_always_inline void dnxhd_get_blocks(DNXHDEncContext *ctx, int mb_x, int mb_y) +{ + const uint8_t *ptr_y = ctx->thread[0]->src[0] + ((mb_y << 4) * ctx->m.linesize) + (mb_x << 4); + const uint8_t *ptr_u = ctx->thread[0]->src[1] + ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << 3); + const uint8_t *ptr_v = ctx->thread[0]->src[2] + ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << 3); + DSPContext *dsp = &ctx->m.dsp; + + dsp->get_pixels(ctx->blocks[0], ptr_y , ctx->m.linesize); + dsp->get_pixels(ctx->blocks[1], ptr_y + 8, ctx->m.linesize); + dsp->get_pixels(ctx->blocks[2], ptr_u , ctx->m.uvlinesize); + dsp->get_pixels(ctx->blocks[3], ptr_v , ctx->m.uvlinesize); + + if (mb_y+1 == ctx->m.mb_height && ctx->m.avctx->height == 1080) { + if (ctx->interlaced) { + dnxhd_get_pixels_4x8(ctx->blocks[4], ptr_y + ctx->dct_y_offset , ctx->m.linesize); + dnxhd_get_pixels_4x8(ctx->blocks[5], ptr_y + ctx->dct_y_offset + 8, ctx->m.linesize); + dnxhd_get_pixels_4x8(ctx->blocks[6], ptr_u + ctx->dct_uv_offset , ctx->m.uvlinesize); + dnxhd_get_pixels_4x8(ctx->blocks[7], ptr_v + ctx->dct_uv_offset , ctx->m.uvlinesize); + } else + memset(ctx->blocks[4], 0, 4*64*sizeof(DCTELEM)); + } else { + dsp->get_pixels(ctx->blocks[4], ptr_y + ctx->dct_y_offset , ctx->m.linesize); + dsp->get_pixels(ctx->blocks[5], ptr_y + ctx->dct_y_offset + 8, ctx->m.linesize); + dsp->get_pixels(ctx->blocks[6], ptr_u + ctx->dct_uv_offset , ctx->m.uvlinesize); + dsp->get_pixels(ctx->blocks[7], ptr_v + ctx->dct_uv_offset , ctx->m.uvlinesize); + } +} + +static av_always_inline int dnxhd_switch_matrix(DNXHDEncContext *ctx, int i) +{ + if (i&2) { + ctx->m.q_intra_matrix16 = ctx->qmatrix_c16; + ctx->m.q_intra_matrix = ctx->qmatrix_c; + return 1 + (i&1); + } else { + ctx->m.q_intra_matrix16 = ctx->qmatrix_l16; + ctx->m.q_intra_matrix = ctx->qmatrix_l; + return 0; + } +} + +static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg) +{ + DNXHDEncContext *ctx = arg; + int mb_y, mb_x; + int qscale = ctx->thread[0]->qscale; + + for (mb_y = ctx->m.start_mb_y; mb_y < ctx->m.end_mb_y; mb_y++) { + ctx->m.last_dc[0] = + ctx->m.last_dc[1] = + ctx->m.last_dc[2] = 1024; + + for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) { + unsigned mb = mb_y * ctx->m.mb_width + mb_x; + int ssd = 0; + int ac_bits = 0; + int dc_bits = 0; + int i; + + dnxhd_get_blocks(ctx, mb_x, mb_y); + + for (i = 0; i < 8; i++) { + DECLARE_ALIGNED_16(DCTELEM, block[64]); + DCTELEM *src_block = ctx->blocks[i]; + int overflow, nbits, diff, last_index; + int n = dnxhd_switch_matrix(ctx, i); + + memcpy(block, src_block, sizeof(block)); + last_index = ctx->m.dct_quantize((MpegEncContext*)ctx, block, i, qscale, &overflow); + ac_bits += dnxhd_calc_ac_bits(ctx, block, last_index); + + diff = block[0] - ctx->m.last_dc[n]; + if (diff < 0) nbits = av_log2_16bit(-2*diff); + else nbits = av_log2_16bit( 2*diff); + dc_bits += ctx->cid_table->dc_bits[nbits] + nbits; + + ctx->m.last_dc[n] = block[0]; + + if (avctx->mb_decision == FF_MB_DECISION_RD || !RC_VARIANCE) { + dnxhd_unquantize_c(ctx, block, i, qscale, last_index); + ctx->m.dsp.idct(block); + ssd += dnxhd_ssd_block(block, src_block); + } + } + ctx->mb_rc[qscale][mb].ssd = ssd; + ctx->mb_rc[qscale][mb].bits = ac_bits+dc_bits+12+8*ctx->table_vlc_bits[0]; + } + } + return 0; +} + +static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg) +{ + DNXHDEncContext *ctx = arg; + int mb_y, mb_x; + + for (mb_y = ctx->m.start_mb_y; mb_y < ctx->m.end_mb_y; mb_y++) { + ctx->m.last_dc[0] = + ctx->m.last_dc[1] = + ctx->m.last_dc[2] = 1024; + for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) { + unsigned mb = mb_y * ctx->m.mb_width + mb_x; + int qscale = ctx->mb_qscale[mb]; + int i; + + put_bits(&ctx->m.pb, 12, qscale<<1); + + dnxhd_get_blocks(ctx, mb_x, mb_y); + + for (i = 0; i < 8; i++) { + DCTELEM *block = ctx->blocks[i]; + int last_index, overflow; + int n = dnxhd_switch_matrix(ctx, i); + last_index = ctx->m.dct_quantize((MpegEncContext*)ctx, block, i, qscale, &overflow); + dnxhd_encode_block(ctx, block, last_index, n); + } + } + if (put_bits_count(&ctx->m.pb)&31) + put_bits(&ctx->m.pb, 32-(put_bits_count(&ctx->m.pb)&31), 0); + } + flush_put_bits(&ctx->m.pb); + return 0; +} + +static void dnxhd_setup_threads_slices(DNXHDEncContext *ctx, uint8_t *buf) +{ + int mb_y, mb_x; + int i, offset = 0; + for (i = 0; i < ctx->m.avctx->thread_count; i++) { + int thread_size = 0; + for (mb_y = ctx->thread[i]->m.start_mb_y; mb_y < ctx->thread[i]->m.end_mb_y; mb_y++) { + ctx->slice_size[mb_y] = 0; + for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) { + unsigned mb = mb_y * ctx->m.mb_width + mb_x; + ctx->slice_size[mb_y] += ctx->mb_bits[mb]; + } + ctx->slice_size[mb_y] = (ctx->slice_size[mb_y]+31)&~31; + ctx->slice_size[mb_y] >>= 3; + thread_size += ctx->slice_size[mb_y]; + } + init_put_bits(&ctx->thread[i]->m.pb, buf + 640 + offset, thread_size); + offset += thread_size; + } +} + +static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg) +{ + DNXHDEncContext *ctx = arg; + int mb_y, mb_x; + for (mb_y = ctx->m.start_mb_y; mb_y < ctx->m.end_mb_y; mb_y++) { + for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) { + unsigned mb = mb_y * ctx->m.mb_width + mb_x; + uint8_t *pix = ctx->thread[0]->src[0] + ((mb_y<<4) * ctx->m.linesize) + (mb_x<<4); + int sum = ctx->m.dsp.pix_sum(pix, ctx->m.linesize); + int varc = (ctx->m.dsp.pix_norm1(pix, ctx->m.linesize) - (((unsigned)(sum*sum))>>8)+128)>>8; + ctx->mb_cmp[mb].value = varc; + ctx->mb_cmp[mb].mb = mb; + } + } + return 0; +} + +static int dnxhd_encode_rdo(AVCodecContext *avctx, DNXHDEncContext *ctx) +{ + int lambda, up_step, down_step; + int last_lower = INT_MAX, last_higher = 0; + int x, y, q; + + for (q = 1; q < avctx->qmax; q++) { + ctx->qscale = q; + avctx->execute(avctx, dnxhd_calc_bits_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count); + } + up_step = down_step = 2<lambda; + + for (;;) { + int bits = 0; + int end = 0; + if (lambda == last_higher) { + lambda++; + end = 1; // need to set final qscales/bits + } + for (y = 0; y < ctx->m.mb_height; y++) { + for (x = 0; x < ctx->m.mb_width; x++) { + unsigned min = UINT_MAX; + int qscale = 1; + int mb = y*ctx->m.mb_width+x; + for (q = 1; q < avctx->qmax; q++) { + unsigned score = ctx->mb_rc[q][mb].bits*lambda+(ctx->mb_rc[q][mb].ssd<mb_rc[qscale][mb].bits; + ctx->mb_qscale[mb] = qscale; + ctx->mb_bits[mb] = ctx->mb_rc[qscale][mb].bits; + } + bits = (bits+31)&~31; // padding + if (bits > ctx->frame_bits) + break; + } + //dprintf(ctx->m.avctx, "lambda %d, up %u, down %u, bits %d, frame %d\n", + // lambda, last_higher, last_lower, bits, ctx->frame_bits); + if (end) { + if (bits > ctx->frame_bits) + return -1; + break; + } + if (bits < ctx->frame_bits) { + last_lower = FFMIN(lambda, last_lower); + if (last_higher != 0) + lambda = (lambda+last_higher)>>1; + else + lambda -= down_step; + down_step *= 5; // XXX tune ? + up_step = 1<>1; + else + lambda += up_step; + up_step *= 5; + down_step = 1<m.avctx, "out lambda %d\n", lambda); + ctx->lambda = lambda; + return 0; +} + +static int dnxhd_find_qscale(DNXHDEncContext *ctx) +{ + int bits = 0; + int up_step = 1; + int down_step = 1; + int last_higher = 0; + int last_lower = INT_MAX; + int qscale; + int x, y; + + qscale = ctx->qscale; + for (;;) { + bits = 0; + ctx->qscale = qscale; + // XXX avoid recalculating bits + ctx->m.avctx->execute(ctx->m.avctx, dnxhd_calc_bits_thread, (void**)&ctx->thread[0], NULL, ctx->m.avctx->thread_count); + for (y = 0; y < ctx->m.mb_height; y++) { + for (x = 0; x < ctx->m.mb_width; x++) + bits += ctx->mb_rc[qscale][y*ctx->m.mb_width+x].bits; + bits = (bits+31)&~31; // padding + if (bits > ctx->frame_bits) + break; + } + //dprintf(ctx->m.avctx, "%d, qscale %d, bits %d, frame %d, higher %d, lower %d\n", + // ctx->m.avctx->frame_number, qscale, bits, ctx->frame_bits, last_higher, last_lower); + if (bits < ctx->frame_bits) { + if (qscale == 1) + return 1; + if (last_higher == qscale - 1) { + qscale = last_higher; + break; + } + last_lower = FFMIN(qscale, last_lower); + if (last_higher != 0) + qscale = (qscale+last_higher)>>1; + else + qscale -= down_step++; + if (qscale < 1) + qscale = 1; + up_step = 1; + } else { + if (last_lower == qscale + 1) + break; + last_higher = FFMAX(qscale, last_higher); + if (last_lower != INT_MAX) + qscale = (qscale+last_lower)>>1; + else + qscale += up_step++; + down_step = 1; + if (qscale >= ctx->m.avctx->qmax) + return -1; + } + } + //dprintf(ctx->m.avctx, "out qscale %d\n", qscale); + ctx->qscale = qscale; + return 0; +} + +static int dnxhd_rc_cmp(const void *a, const void *b) +{ + return ((const RCCMPEntry *)b)->value - ((const RCCMPEntry *)a)->value; +} + +static int dnxhd_encode_fast(AVCodecContext *avctx, DNXHDEncContext *ctx) +{ + int max_bits = 0; + int ret, x, y; + if ((ret = dnxhd_find_qscale(ctx)) < 0) + return -1; + for (y = 0; y < ctx->m.mb_height; y++) { + for (x = 0; x < ctx->m.mb_width; x++) { + int mb = y*ctx->m.mb_width+x; + int delta_bits; + ctx->mb_qscale[mb] = ctx->qscale; + ctx->mb_bits[mb] = ctx->mb_rc[ctx->qscale][mb].bits; + max_bits += ctx->mb_rc[ctx->qscale][mb].bits; + if (!RC_VARIANCE) { + delta_bits = ctx->mb_rc[ctx->qscale][mb].bits-ctx->mb_rc[ctx->qscale+1][mb].bits; + ctx->mb_cmp[mb].mb = mb; + ctx->mb_cmp[mb].value = delta_bits ? + ((ctx->mb_rc[ctx->qscale][mb].ssd-ctx->mb_rc[ctx->qscale+1][mb].ssd)*100)/delta_bits + : INT_MIN; //avoid increasing qscale + } + } + max_bits += 31; //worst padding + } + if (!ret) { + if (RC_VARIANCE) + avctx->execute(avctx, dnxhd_mb_var_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count); + qsort(ctx->mb_cmp, ctx->m.mb_num, sizeof(RCEntry), dnxhd_rc_cmp); + for (x = 0; x < ctx->m.mb_num && max_bits > ctx->frame_bits; x++) { + int mb = ctx->mb_cmp[x].mb; + max_bits -= ctx->mb_rc[ctx->qscale][mb].bits - ctx->mb_rc[ctx->qscale+1][mb].bits; + ctx->mb_qscale[mb] = ctx->qscale+1; + ctx->mb_bits[mb] = ctx->mb_rc[ctx->qscale+1][mb].bits; + } + } + return 0; +} + +static void dnxhd_load_picture(DNXHDEncContext *ctx, const AVFrame *frame) +{ + int i; + + for (i = 0; i < 3; i++) { + ctx->frame.data[i] = frame->data[i]; + ctx->frame.linesize[i] = frame->linesize[i]; + } + + for (i = 0; i < ctx->m.avctx->thread_count; i++) { + ctx->thread[i]->m.linesize = ctx->frame.linesize[0]<interlaced; + ctx->thread[i]->m.uvlinesize = ctx->frame.linesize[1]<interlaced; + ctx->thread[i]->dct_y_offset = ctx->m.linesize *8; + ctx->thread[i]->dct_uv_offset = ctx->m.uvlinesize*8; + } + + ctx->frame.interlaced_frame = frame->interlaced_frame; + ctx->cur_field = frame->interlaced_frame && !frame->top_field_first; +} + +static int dnxhd_encode_picture(AVCodecContext *avctx, unsigned char *buf, int buf_size, const void *data) +{ + DNXHDEncContext *ctx = avctx->priv_data; + int first_field = 1; + int offset, i, ret; + + if (buf_size < ctx->cid_table->frame_size) { + av_log(avctx, AV_LOG_ERROR, "output buffer is too small to compress picture\n"); + return -1; + } + + dnxhd_load_picture(ctx, data); + + encode_coding_unit: + for (i = 0; i < 3; i++) { + ctx->src[i] = ctx->frame.data[i]; + if (ctx->interlaced && ctx->cur_field) + ctx->src[i] += ctx->frame.linesize[i]; + } + + dnxhd_write_header(avctx, buf); + + if (avctx->mb_decision == FF_MB_DECISION_RD) + ret = dnxhd_encode_rdo(avctx, ctx); + else + ret = dnxhd_encode_fast(avctx, ctx); + if (ret < 0) { + av_log(avctx, AV_LOG_ERROR, "picture could not fit ratecontrol constraints\n"); + return -1; + } + + dnxhd_setup_threads_slices(ctx, buf); + + offset = 0; + for (i = 0; i < ctx->m.mb_height; i++) { + AV_WB32(ctx->msip + i * 4, offset); + offset += ctx->slice_size[i]; + assert(!(ctx->slice_size[i] & 3)); + } + + avctx->execute(avctx, dnxhd_encode_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count); + + AV_WB32(buf + ctx->cid_table->coding_unit_size - 4, 0x600DC0DE); // EOF + + if (ctx->interlaced && first_field) { + first_field = 0; + ctx->cur_field ^= 1; + buf += ctx->cid_table->coding_unit_size; + buf_size -= ctx->cid_table->coding_unit_size; + goto encode_coding_unit; + } + + return ctx->cid_table->frame_size; +} + +static int dnxhd_encode_end(AVCodecContext *avctx) +{ + DNXHDEncContext *ctx = avctx->priv_data; + int i; + + av_freep(&ctx->table_vlc_codes); + av_freep(&ctx->table_vlc_bits); + av_freep(&ctx->table_run_codes); + av_freep(&ctx->table_run_bits); + + av_freep(&ctx->mb_bits); + av_freep(&ctx->mb_qscale); + av_freep(&ctx->mb_rc); + av_freep(&ctx->mb_cmp); + av_freep(&ctx->slice_size); + + av_freep(&ctx->qmatrix_c); + av_freep(&ctx->qmatrix_l); + av_freep(&ctx->qmatrix_c16); + av_freep(&ctx->qmatrix_l16); + + for (i = 1; i < avctx->thread_count; i++) + av_freep(&ctx->thread[i]); + + return 0; +} + +AVCodec dnxhd_encoder = { + "dnxhd", + CODEC_TYPE_VIDEO, + CODEC_ID_DNXHD, + sizeof(DNXHDEncContext), + dnxhd_encode_init, + dnxhd_encode_picture, + dnxhd_encode_end, + .pix_fmts = (enum PixelFormat[]){PIX_FMT_YUV422P, -1}, +}; diff --git a/contrib/ffmpeg/libavcodec/dpcm.c b/contrib/ffmpeg/libavcodec/dpcm.c index 6243881de..01dd5cce0 100644 --- a/contrib/ffmpeg/libavcodec/dpcm.c +++ b/contrib/ffmpeg/libavcodec/dpcm.c @@ -46,8 +46,6 @@ typedef struct DPCMContext { const int *sol_table;//for SOL_DPCM } DPCMContext; -#define SATURATE_S16(x) if (x < -32768) x = -32768; \ - else if (x > 32767) x = 32767; #define SE_16BIT(x) if (x & 0x8000) x -= 0x10000; static int interplay_delta_table[] = { @@ -161,7 +159,7 @@ static int dpcm_decode_init(AVCodecContext *avctx) static int dpcm_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { DPCMContext *s = avctx->priv_data; int in, out = 0; @@ -175,6 +173,10 @@ static int dpcm_decode_frame(AVCodecContext *avctx, if (!buf_size) return 0; + // almost every DPCM variant expands one byte of data into two + if(*data_size/2 < buf_size) + return -1; + switch(avctx->codec->id) { case CODEC_ID_ROQ_DPCM: @@ -190,7 +192,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, /* decode the samples */ for (in = 8, out = 0; in < buf_size; in++, out++) { predictor[channel_number] += s->roq_square_array[buf[in]]; - SATURATE_S16(predictor[channel_number]); + predictor[channel_number] = av_clip_int16(predictor[channel_number]); output_samples[out] = predictor[channel_number]; /* toggle channel */ @@ -213,7 +215,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, while (in < buf_size) { predictor[channel_number] += interplay_delta_table[buf[in++]]; - SATURATE_S16(predictor[channel_number]); + predictor[channel_number] = av_clip_int16(predictor[channel_number]); output_samples[out++] = predictor[channel_number]; /* toggle channel */ @@ -248,7 +250,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, diff >>= shift[channel_number]; predictor[channel_number] += diff; - SATURATE_S16(predictor[channel_number]); + predictor[channel_number] = av_clip_int16(predictor[channel_number]); output_samples[out++] = predictor[channel_number]; /* toggle channel */ @@ -258,6 +260,8 @@ static int dpcm_decode_frame(AVCodecContext *avctx, case CODEC_ID_SOL_DPCM: in = 0; if (avctx->codec_tag != 3) { + if(*data_size/4 < buf_size) + return -1; while (in < buf_size) { int n1, n2; n1 = (buf[in] >> 4) & 0xF; @@ -277,7 +281,7 @@ static int dpcm_decode_frame(AVCodecContext *avctx, n = buf[in++]; if (n & 0x80) s->sample[channel_number] -= s->sol_table[n & 0x7F]; else s->sample[channel_number] += s->sol_table[n & 0x7F]; - SATURATE_S16(s->sample[channel_number]); + s->sample[channel_number] = av_clip_int16(s->sample[channel_number]); output_samples[out++] = s->sample[channel_number]; /* toggle channel */ channel_number ^= s->channels - 1; @@ -290,46 +294,19 @@ static int dpcm_decode_frame(AVCodecContext *avctx, return buf_size; } -AVCodec roq_dpcm_decoder = { - "roq_dpcm", - CODEC_TYPE_AUDIO, - CODEC_ID_ROQ_DPCM, - sizeof(DPCMContext), - dpcm_decode_init, - NULL, - NULL, - dpcm_decode_frame, -}; - -AVCodec interplay_dpcm_decoder = { - "interplay_dpcm", - CODEC_TYPE_AUDIO, - CODEC_ID_INTERPLAY_DPCM, - sizeof(DPCMContext), - dpcm_decode_init, - NULL, - NULL, - dpcm_decode_frame, +#define DPCM_DECODER(id, name) \ +AVCodec name ## _decoder = { \ + #name, \ + CODEC_TYPE_AUDIO, \ + id, \ + sizeof(DPCMContext), \ + dpcm_decode_init, \ + NULL, \ + NULL, \ + dpcm_decode_frame, \ }; -AVCodec xan_dpcm_decoder = { - "xan_dpcm", - CODEC_TYPE_AUDIO, - CODEC_ID_XAN_DPCM, - sizeof(DPCMContext), - dpcm_decode_init, - NULL, - NULL, - dpcm_decode_frame, -}; - -AVCodec sol_dpcm_decoder = { - "sol_dpcm", - CODEC_TYPE_AUDIO, - CODEC_ID_SOL_DPCM, - sizeof(DPCMContext), - dpcm_decode_init, - NULL, - NULL, - dpcm_decode_frame, -}; +DPCM_DECODER(CODEC_ID_INTERPLAY_DPCM, interplay_dpcm); +DPCM_DECODER(CODEC_ID_ROQ_DPCM, roq_dpcm); +DPCM_DECODER(CODEC_ID_SOL_DPCM, sol_dpcm); +DPCM_DECODER(CODEC_ID_XAN_DPCM, xan_dpcm); diff --git a/contrib/ffmpeg/libavcodec/dsicinav.c b/contrib/ffmpeg/libavcodec/dsicinav.c index c7c3f5627..e549487c7 100644 --- a/contrib/ffmpeg/libavcodec/dsicinav.c +++ b/contrib/ffmpeg/libavcodec/dsicinav.c @@ -25,7 +25,7 @@ */ #include "avcodec.h" -#include "common.h" +#include "bytestream.h" typedef enum CinVideoBitmapIndex { @@ -88,12 +88,11 @@ static const int16_t cinaudio_delta16_table[256] = { static int cinvideo_decode_init(AVCodecContext *avctx) { - CinVideoContext *cin = (CinVideoContext *)avctx->priv_data; + CinVideoContext *cin = avctx->priv_data; unsigned int i; cin->avctx = avctx; avctx->pix_fmt = PIX_FMT_PAL8; - avctx->has_b_frames = 0; cin->frame.data[0] = NULL; @@ -196,9 +195,9 @@ static void cin_decode_rle(const unsigned char *src, int src_size, unsigned char static int cinvideo_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { - CinVideoContext *cin = (CinVideoContext *)avctx->priv_data; + CinVideoContext *cin = avctx->priv_data; int i, y, palette_type, palette_colors_count, bitmap_frame_type, bitmap_frame_size; cin->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; @@ -208,7 +207,7 @@ static int cinvideo_decode_frame(AVCodecContext *avctx, } palette_type = buf[0]; - palette_colors_count = buf[1] | (buf[2] << 8); + palette_colors_count = AV_RL16(buf+1); bitmap_frame_type = buf[3]; buf += 4; @@ -217,13 +216,12 @@ static int cinvideo_decode_frame(AVCodecContext *avctx, /* handle palette */ if (palette_type == 0) { for (i = 0; i < palette_colors_count; ++i) { - cin->palette[i] = (buf[2] << 16) | (buf[1] << 8) | buf[0]; - buf += 3; + cin->palette[i] = bytestream_get_le24(&buf); bitmap_frame_size -= 3; } } else { for (i = 0; i < palette_colors_count; ++i) { - cin->palette[buf[0]] = (buf[3] << 16) | (buf[2] << 8) | buf[1]; + cin->palette[buf[0]] = AV_RL24(buf+1); buf += 4; bitmap_frame_size -= 4; } @@ -288,7 +286,7 @@ static int cinvideo_decode_frame(AVCodecContext *avctx, static int cinvideo_decode_end(AVCodecContext *avctx) { - CinVideoContext *cin = (CinVideoContext *)avctx->priv_data; + CinVideoContext *cin = avctx->priv_data; int i; if (cin->frame.data[0]) @@ -302,7 +300,7 @@ static int cinvideo_decode_end(AVCodecContext *avctx) static int cinaudio_decode_init(AVCodecContext *avctx) { - CinAudioContext *cin = (CinAudioContext *)avctx->priv_data; + CinAudioContext *cin = avctx->priv_data; cin->avctx = avctx; cin->initial_decode_frame = 1; @@ -313,12 +311,14 @@ static int cinaudio_decode_init(AVCodecContext *avctx) static int cinaudio_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { - CinAudioContext *cin = (CinAudioContext *)avctx->priv_data; - uint8_t *src = buf; + CinAudioContext *cin = avctx->priv_data; + const uint8_t *src = buf; int16_t *samples = (int16_t *)data; + buf_size = FFMIN(buf_size, *data_size/2); + if (cin->initial_decode_frame) { cin->initial_decode_frame = 0; cin->delta = (int16_t)AV_RL16(src); src += 2; @@ -327,7 +327,7 @@ static int cinaudio_decode_frame(AVCodecContext *avctx, } while (buf_size > 0) { cin->delta += cinaudio_delta16_table[*src++]; - cin->delta = av_clip(cin->delta, -32768, 32767); + cin->delta = av_clip_int16(cin->delta); *samples++ = cin->delta; --buf_size; } diff --git a/contrib/ffmpeg/libavcodec/dsputil.c b/contrib/ffmpeg/libavcodec/dsputil.c index 3f5e845e7..055486d49 100644 --- a/contrib/ffmpeg/libavcodec/dsputil.c +++ b/contrib/ffmpeg/libavcodec/dsputil.c @@ -3,6 +3,8 @@ * Copyright (c) 2000, 2001 Fabrice Bellard. * Copyright (c) 2002-2004 Michael Niedermayer * + * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -18,8 +20,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer */ /** @@ -32,6 +32,8 @@ #include "mpegvideo.h" #include "simple_idct.h" #include "faandct.h" +#include "faanidct.h" +#include "h263.h" #include "snow.h" /* snow.c */ @@ -40,9 +42,19 @@ void ff_spatial_dwt(int *buffer, int width, int height, int stride, int type, in /* vorbis.c */ void vorbis_inverse_coupling(float *mag, float *ang, int blocksize); +/* flacenc.c */ +void ff_flac_compute_autocorr(const int32_t *data, int len, int lag, double *autoc); + +/* pngdec.c */ +void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp); + uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP] = {0, }; uint32_t ff_squareTbl[512] = {0, }; +// 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size +#define pb_7f (~0UL/255 * 0x7f) +#define pb_80 (~0UL/255 * 0x80) + const uint8_t ff_zigzag_direct[64] = { 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, @@ -210,7 +222,7 @@ static int pix_norm1_c(uint8_t * pix, int line_size) return s; } -static void bswap_buf(uint32_t *dst, uint32_t *src, int w){ +static void bswap_buf(uint32_t *dst, const uint32_t *src, int w){ int i; for(i=0; i+8<=w; i+=8){ @@ -592,6 +604,14 @@ static void add_pixels4_c(uint8_t *restrict pixels, DCTELEM *block, int line_siz } } +static int sum_abs_dctelem_c(DCTELEM *block) +{ + int sum=0, i; + for(i=0; i<64; i++) + sum+= FFABS(block[i]); + return sum; +} + #if 0 #define PIXOP2(OPNAME, OP) \ @@ -599,7 +619,7 @@ static void OPNAME ## _pixels(uint8_t *block, const uint8_t *pixels, int line_si {\ int i;\ for(i=0; i>1));\ pixels+=line_size;\ block +=line_size;\ @@ -621,8 +641,8 @@ static void OPNAME ## _pixels_x2_c(uint8_t *block, const uint8_t *pixels, int li {\ int i;\ for(i=0; i>1));\ pixels+=line_size;\ block +=line_size;\ @@ -633,8 +653,8 @@ static void OPNAME ## _no_rnd_pixels_y2_c(uint8_t *block, const uint8_t *pixels, {\ int i;\ for(i=0; i>1));\ pixels+=line_size;\ block +=line_size;\ @@ -645,8 +665,8 @@ static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int li {\ int i;\ for(i=0; i>1));\ pixels+=line_size;\ block +=line_size;\ @@ -656,8 +676,8 @@ static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int li static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ {\ int i;\ - const uint64_t a= LD64(pixels );\ - const uint64_t b= LD64(pixels+1);\ + const uint64_t a= AV_RN64(pixels );\ + const uint64_t b= AV_RN64(pixels+1);\ uint64_t l0= (a&0x0303030303030303ULL)\ + (b&0x0303030303030303ULL)\ + 0x0202020202020202ULL;\ @@ -667,8 +687,8 @@ static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int l \ pixels+=line_size;\ for(i=0; i>2)\ @@ -676,8 +696,8 @@ static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int l OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\ pixels+=line_size;\ block +=line_size;\ - a= LD64(pixels );\ - b= LD64(pixels+1);\ + a= AV_RN64(pixels );\ + b= AV_RN64(pixels+1);\ l0= (a&0x0303030303030303ULL)\ + (b&0x0303030303030303ULL)\ + 0x0202020202020202ULL;\ @@ -692,8 +712,8 @@ static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int l static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ {\ int i;\ - const uint64_t a= LD64(pixels );\ - const uint64_t b= LD64(pixels+1);\ + const uint64_t a= AV_RN64(pixels );\ + const uint64_t b= AV_RN64(pixels+1);\ uint64_t l0= (a&0x0303030303030303ULL)\ + (b&0x0303030303030303ULL)\ + 0x0101010101010101ULL;\ @@ -703,8 +723,8 @@ static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels \ pixels+=line_size;\ for(i=0; i>2)\ @@ -712,8 +732,8 @@ static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\ pixels+=line_size;\ block +=line_size;\ - a= LD64(pixels );\ - b= LD64(pixels+1);\ + a= AV_RN64(pixels );\ + b= AV_RN64(pixels+1);\ l0= (a&0x0303030303030303ULL)\ + (b&0x0303030303030303ULL)\ + 0x0101010101010101ULL;\ @@ -740,7 +760,7 @@ CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels_xy2_c, static void OPNAME ## _pixels2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ int i;\ for(i=0; i>2)\ + ((d&0xFCFCFCFCUL)>>2);\ OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ - a= LD32(&src1[i*src_stride1+4]);\ - b= LD32(&src2[i*src_stride2+4]);\ - c= LD32(&src3[i*src_stride3+4]);\ - d= LD32(&src4[i*src_stride4+4]);\ + a= AV_RN32(&src1[i*src_stride1+4]);\ + b= AV_RN32(&src2[i*src_stride2+4]);\ + c= AV_RN32(&src3[i*src_stride3+4]);\ + d= AV_RN32(&src4[i*src_stride4+4]);\ l0= (a&0x03030303UL)\ + (b&0x03030303UL)\ + 0x02020202UL;\ @@ -901,10 +921,10 @@ static inline void OPNAME ## _no_rnd_pixels8_l4(uint8_t *dst, const uint8_t *src int i;\ for(i=0; i>2)\ + ((d&0xFCFCFCFCUL)>>2);\ OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ - a= LD32(&src1[i*src_stride1+4]);\ - b= LD32(&src2[i*src_stride2+4]);\ - c= LD32(&src3[i*src_stride3+4]);\ - d= LD32(&src4[i*src_stride4+4]);\ + a= AV_RN32(&src1[i*src_stride1+4]);\ + b= AV_RN32(&src2[i*src_stride2+4]);\ + c= AV_RN32(&src3[i*src_stride3+4]);\ + d= AV_RN32(&src4[i*src_stride4+4]);\ l0= (a&0x03030303UL)\ + (b&0x03030303UL)\ + 0x01010101UL;\ @@ -978,8 +998,8 @@ static inline void OPNAME ## _pixels2_xy2_c(uint8_t *block, const uint8_t *pixel static inline void OPNAME ## _pixels4_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ {\ int i;\ - const uint32_t a= LD32(pixels );\ - const uint32_t b= LD32(pixels+1);\ + const uint32_t a= AV_RN32(pixels );\ + const uint32_t b= AV_RN32(pixels+1);\ uint32_t l0= (a&0x03030303UL)\ + (b&0x03030303UL)\ + 0x02020202UL;\ @@ -989,8 +1009,8 @@ static inline void OPNAME ## _pixels4_xy2_c(uint8_t *block, const uint8_t *pixel \ pixels+=line_size;\ for(i=0; i>2)\ @@ -998,8 +1018,8 @@ static inline void OPNAME ## _pixels4_xy2_c(uint8_t *block, const uint8_t *pixel OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ pixels+=line_size;\ block +=line_size;\ - a= LD32(pixels );\ - b= LD32(pixels+1);\ + a= AV_RN32(pixels );\ + b= AV_RN32(pixels+1);\ l0= (a&0x03030303UL)\ + (b&0x03030303UL)\ + 0x02020202UL;\ @@ -1016,8 +1036,8 @@ static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixel int j;\ for(j=0; j<2; j++){\ int i;\ - const uint32_t a= LD32(pixels );\ - const uint32_t b= LD32(pixels+1);\ + const uint32_t a= AV_RN32(pixels );\ + const uint32_t b= AV_RN32(pixels+1);\ uint32_t l0= (a&0x03030303UL)\ + (b&0x03030303UL)\ + 0x02020202UL;\ @@ -1027,8 +1047,8 @@ static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixel \ pixels+=line_size;\ for(i=0; i>2)\ @@ -1036,8 +1056,8 @@ static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixel OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ pixels+=line_size;\ block +=line_size;\ - a= LD32(pixels );\ - b= LD32(pixels+1);\ + a= AV_RN32(pixels );\ + b= AV_RN32(pixels+1);\ l0= (a&0x03030303UL)\ + (b&0x03030303UL)\ + 0x02020202UL;\ @@ -1057,8 +1077,8 @@ static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t int j;\ for(j=0; j<2; j++){\ int i;\ - const uint32_t a= LD32(pixels );\ - const uint32_t b= LD32(pixels+1);\ + const uint32_t a= AV_RN32(pixels );\ + const uint32_t b= AV_RN32(pixels+1);\ uint32_t l0= (a&0x03030303UL)\ + (b&0x03030303UL)\ + 0x01010101UL;\ @@ -1068,8 +1088,8 @@ static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t \ pixels+=line_size;\ for(i=0; i>2)\ @@ -1077,8 +1097,8 @@ static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ pixels+=line_size;\ block +=line_size;\ - a= LD32(pixels );\ - b= LD32(pixels+1);\ + a= AV_RN32(pixels );\ + b= AV_RN32(pixels+1);\ l0= (a&0x03030303UL)\ + (b&0x03030303UL)\ + 0x01010101UL;\ @@ -1428,12 +1448,22 @@ static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*a \ assert(x<8 && y<8 && x>=0 && y>=0);\ \ - for(i=0; i=0 && y>=0);\ \ - for(i=0; i=0 && y>=0);\ \ - for(i=0; idsp.diff_pixels(temp, src1, src2, stride); s->dsp.fdct(temp); - - for(i=0; i<64; i++) - sum+= FFABS(temp[i]); - - return sum; + return s->dsp.sum_abs_dctelem(temp); } #ifdef CONFIG_GPL @@ -3430,11 +3502,11 @@ static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2 static int dct264_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ MpegEncContext * const s= (MpegEncContext *)c; - int16_t dct[8][8]; + DCTELEM dct[8][8]; int i; int sum=0; - s->dsp.diff_pixels(dct, src1, src2, stride); + s->dsp.diff_pixels(dct[0], src1, src2, stride); #define SRC(x) dct[i][x] #define DST(x,v) dct[i][x]= v @@ -3486,7 +3558,7 @@ static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *s s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i); s->dct_unquantize_inter(s, temp, 0, s->qscale); - simple_idct(temp); //FIXME + ff_simple_idct(temp); //FIXME for(i=0; i<64; i++) sum+= (temp[i]-bak[i])*(temp[i]-bak[i]); @@ -3694,7 +3766,8 @@ static int vsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int st return score; } -static int ssd_int8_vs_int16_c(int8_t *pix1, int16_t *pix2, int size){ +static int ssd_int8_vs_int16_c(const int8_t *pix1, const int16_t *pix2, + int size){ int score=0; int i; for(i=0; i>31; // is this faster on some gcc/cpu combinations? @@ -3746,8 +3819,90 @@ void ff_float_to_int16_c(int16_t *dst, const float *src, int len){ } } +#define W0 2048 +#define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */ +#define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */ +#define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */ +#define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */ +#define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */ +#define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */ +#define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */ + +static void wmv2_idct_row(short * b) +{ + int s1,s2; + int a0,a1,a2,a3,a4,a5,a6,a7; + /*step 1*/ + a1 = W1*b[1]+W7*b[7]; + a7 = W7*b[1]-W1*b[7]; + a5 = W5*b[5]+W3*b[3]; + a3 = W3*b[5]-W5*b[3]; + a2 = W2*b[2]+W6*b[6]; + a6 = W6*b[2]-W2*b[6]; + a0 = W0*b[0]+W0*b[4]; + a4 = W0*b[0]-W0*b[4]; + /*step 2*/ + s1 = (181*(a1-a5+a7-a3)+128)>>8;//1,3,5,7, + s2 = (181*(a1-a5-a7+a3)+128)>>8; + /*step 3*/ + b[0] = (a0+a2+a1+a5 + (1<<7))>>8; + b[1] = (a4+a6 +s1 + (1<<7))>>8; + b[2] = (a4-a6 +s2 + (1<<7))>>8; + b[3] = (a0-a2+a7+a3 + (1<<7))>>8; + b[4] = (a0-a2-a7-a3 + (1<<7))>>8; + b[5] = (a4-a6 -s2 + (1<<7))>>8; + b[6] = (a4+a6 -s1 + (1<<7))>>8; + b[7] = (a0+a2-a1-a5 + (1<<7))>>8; +} +static void wmv2_idct_col(short * b) +{ + int s1,s2; + int a0,a1,a2,a3,a4,a5,a6,a7; + /*step 1, with extended precision*/ + a1 = (W1*b[8*1]+W7*b[8*7] + 4)>>3; + a7 = (W7*b[8*1]-W1*b[8*7] + 4)>>3; + a5 = (W5*b[8*5]+W3*b[8*3] + 4)>>3; + a3 = (W3*b[8*5]-W5*b[8*3] + 4)>>3; + a2 = (W2*b[8*2]+W6*b[8*6] + 4)>>3; + a6 = (W6*b[8*2]-W2*b[8*6] + 4)>>3; + a0 = (W0*b[8*0]+W0*b[8*4] )>>3; + a4 = (W0*b[8*0]-W0*b[8*4] )>>3; + /*step 2*/ + s1 = (181*(a1-a5+a7-a3)+128)>>8; + s2 = (181*(a1-a5-a7+a3)+128)>>8; + /*step 3*/ + b[8*0] = (a0+a2+a1+a5 + (1<<13))>>14; + b[8*1] = (a4+a6 +s1 + (1<<13))>>14; + b[8*2] = (a4-a6 +s2 + (1<<13))>>14; + b[8*3] = (a0-a2+a7+a3 + (1<<13))>>14; + + b[8*4] = (a0-a2-a7-a3 + (1<<13))>>14; + b[8*5] = (a4-a6 -s2 + (1<<13))>>14; + b[8*6] = (a4+a6 -s1 + (1<<13))>>14; + b[8*7] = (a0+a2-a1-a5 + (1<<13))>>14; +} +void ff_wmv2_idct_c(short * block){ + int i; + + for(i=0;i<64;i+=8){ + wmv2_idct_row(block+i); + } + for(i=0;i<8;i++){ + wmv2_idct_col(block+i); + } +} /* XXX: those functions should be suppressed ASAP when all IDCTs are converted */ +static void ff_wmv2_idct_put_c(uint8_t *dest, int line_size, DCTELEM *block) +{ + ff_wmv2_idct_c(block); + put_pixels_clamped_c(block, dest, line_size); +} +static void ff_wmv2_idct_add_c(uint8_t *dest, int line_size, DCTELEM *block) +{ + ff_wmv2_idct_c(block); + add_pixels_clamped_c(block, dest, line_size); +} static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block) { j_rev_dct (block); @@ -3794,7 +3949,7 @@ static void ff_jref_idct1_add(uint8_t *dest, int line_size, DCTELEM *block) dest[0] = cm[dest[0] + ((block[0] + 4)>>3)]; } -static void just_return() { return; } +static void just_return(void *mem av_unused, int stride av_unused, int h av_unused) { return; } /* init static data */ void dsputil_static_init(void) @@ -3818,13 +3973,14 @@ int ff_check_alignment(void){ static int did_fail=0; DECLARE_ALIGNED_16(int, aligned); - if((int)&aligned & 15){ + if((long)&aligned & 15){ if(!did_fail){ #if defined(HAVE_MMX) || defined(HAVE_ALTIVEC) av_log(NULL, AV_LOG_ERROR, "Compiler did not align stack variables. Libavcodec has been miscompiled\n" "and may be very slow or crash. This is not a bug in libavcodec,\n" - "but in the compiler. Do not report crashes to FFmpeg developers.\n"); + "but in the compiler. You may try recompiling using gcc >= 4.2.\n" + "Do not report crashes to FFmpeg developers.\n"); #endif did_fail=1; } @@ -3855,7 +4011,7 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx) #endif //CONFIG_ENCODERS if(avctx->lowres==1){ - if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO){ + if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO || !ENABLE_H264_DECODER){ c->idct_put= ff_jref_idct4_put; c->idct_add= ff_jref_idct4_add; }else{ @@ -3880,23 +4036,36 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx) c->idct_add= ff_jref_idct_add; c->idct = j_rev_dct; c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM; - }else if(avctx->idct_algo==FF_IDCT_VP3){ + }else if((ENABLE_VP3_DECODER || ENABLE_VP5_DECODER || ENABLE_VP6_DECODER || ENABLE_THEORA_DECODER ) && + avctx->idct_algo==FF_IDCT_VP3){ c->idct_put= ff_vp3_idct_put_c; c->idct_add= ff_vp3_idct_add_c; c->idct = ff_vp3_idct_c; c->idct_permutation_type= FF_NO_IDCT_PERM; + }else if(avctx->idct_algo==FF_IDCT_WMV2){ + c->idct_put= ff_wmv2_idct_put_c; + c->idct_add= ff_wmv2_idct_add_c; + c->idct = ff_wmv2_idct_c; + c->idct_permutation_type= FF_NO_IDCT_PERM; + }else if(avctx->idct_algo==FF_IDCT_FAAN){ + c->idct_put= ff_faanidct_put; + c->idct_add= ff_faanidct_add; + c->idct = ff_faanidct; + c->idct_permutation_type= FF_NO_IDCT_PERM; }else{ //accurate/default - c->idct_put= simple_idct_put; - c->idct_add= simple_idct_add; - c->idct = simple_idct; + c->idct_put= ff_simple_idct_put; + c->idct_add= ff_simple_idct_add; + c->idct = ff_simple_idct; c->idct_permutation_type= FF_NO_IDCT_PERM; } } - c->h264_idct_add= ff_h264_idct_add_c; - c->h264_idct8_add= ff_h264_idct8_add_c; - c->h264_idct_dc_add= ff_h264_idct_dc_add_c; - c->h264_idct8_dc_add= ff_h264_idct8_dc_add_c; + if (ENABLE_H264_DECODER) { + c->h264_idct_add= ff_h264_idct_add_c; + c->h264_idct8_add= ff_h264_idct8_add_c; + c->h264_idct_dc_add= ff_h264_idct_dc_add_c; + c->h264_idct8_dc_add= ff_h264_idct8_dc_add_c; + } c->get_pixels = get_pixels_c; c->diff_pixels = diff_pixels_c; @@ -3905,6 +4074,7 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx) c->add_pixels_clamped = add_pixels_clamped_c; c->add_pixels8 = add_pixels8_c; c->add_pixels4 = add_pixels4_c; + c->sum_abs_dctelem = sum_abs_dctelem_c; c->gmc1 = gmc1_c; c->gmc = ff_gmc_c; c->clear_blocks = clear_blocks_c; @@ -4039,8 +4209,11 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx) #if defined(CONFIG_VC1_DECODER) || defined(CONFIG_WMV3_DECODER) ff_vc1dsp_init(c,avctx); #endif +#if defined(CONFIG_WMV2_DECODER) || defined(CONFIG_VC1_DECODER) || defined(CONFIG_WMV3_DECODER) + ff_intrax8dsp_init(c,avctx); +#endif #if defined(CONFIG_H264_ENCODER) - ff_h264dsp_init(c,avctx); + ff_h264dspenc_init(c,avctx); #endif c->put_mspel_pixels_tab[0]= put_mspel8_mc00_c; @@ -4087,9 +4260,13 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx) c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c; c->add_bytes= add_bytes_c; + c->add_bytes_l2= add_bytes_l2_c; c->diff_bytes= diff_bytes_c; c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c; c->bswap_buf= bswap_buf; +#ifdef CONFIG_PNG_DECODER + c->add_png_paeth_prediction= ff_add_png_paeth_prediction; +#endif c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_c; c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_c; @@ -4099,8 +4276,10 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx) c->h264_h_loop_filter_chroma_intra= h264_h_loop_filter_chroma_intra_c; c->h264_loop_filter_strength= NULL; - c->h263_h_loop_filter= h263_h_loop_filter_c; - c->h263_v_loop_filter= h263_v_loop_filter_c; + if (ENABLE_ANY_H263) { + c->h263_h_loop_filter= h263_h_loop_filter_c; + c->h263_v_loop_filter= h263_v_loop_filter_c; + } c->h261_loop_filter= h261_loop_filter_c; @@ -4115,6 +4294,9 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx) #ifdef CONFIG_VORBIS_DECODER c->vorbis_inverse_coupling = vorbis_inverse_coupling; +#endif +#ifdef CONFIG_FLAC_ENCODER + c->flac_compute_autocorr = ff_flac_compute_autocorr; #endif c->vector_fmul = vector_fmul_c; c->vector_fmul_reverse = vector_fmul_reverse_c; @@ -4131,33 +4313,15 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx) memset(c->put_2tap_qpel_pixels_tab, 0, sizeof(c->put_2tap_qpel_pixels_tab)); memset(c->avg_2tap_qpel_pixels_tab, 0, sizeof(c->avg_2tap_qpel_pixels_tab)); -#ifdef HAVE_MMX - dsputil_init_mmx(c, avctx); -#endif -#ifdef ARCH_ARMV4L - dsputil_init_armv4l(c, avctx); -#endif -#ifdef HAVE_MLIB - dsputil_init_mlib(c, avctx); -#endif -#ifdef ARCH_SPARC - dsputil_init_vis(c,avctx); -#endif -#ifdef ARCH_ALPHA - dsputil_init_alpha(c, avctx); -#endif -#ifdef ARCH_POWERPC - dsputil_init_ppc(c, avctx); -#endif -#ifdef HAVE_MMI - dsputil_init_mmi(c, avctx); -#endif -#ifdef ARCH_SH4 - dsputil_init_sh4(c,avctx); -#endif -#ifdef ARCH_BFIN - dsputil_init_bfin(c,avctx); -#endif + if (ENABLE_MMX) dsputil_init_mmx (c, avctx); + if (ENABLE_ARMV4L) dsputil_init_armv4l(c, avctx); + if (ENABLE_MLIB) dsputil_init_mlib (c, avctx); + if (ENABLE_VIS) dsputil_init_vis (c, avctx); + if (ENABLE_ALPHA) dsputil_init_alpha (c, avctx); + if (ENABLE_POWERPC) dsputil_init_ppc (c, avctx); + if (ENABLE_MMI) dsputil_init_mmi (c, avctx); + if (ENABLE_SH4) dsputil_init_sh4 (c, avctx); + if (ENABLE_BFIN) dsputil_init_bfin (c, avctx); for(i=0; i<64; i++){ if(!c->put_2tap_qpel_pixels_tab[0][i]) diff --git a/contrib/ffmpeg/libavcodec/dsputil.h b/contrib/ffmpeg/libavcodec/dsputil.h index 800669ea7..5fe169ecc 100644 --- a/contrib/ffmpeg/libavcodec/dsputil.h +++ b/contrib/ffmpeg/libavcodec/dsputil.h @@ -27,10 +27,9 @@ * absolutely necessary to call emms_c() between dsp & float/double code */ -#ifndef DSPUTIL_H -#define DSPUTIL_H +#ifndef FFMPEG_DSPUTIL_H +#define FFMPEG_DSPUTIL_H -#include "common.h" #include "avcodec.h" @@ -38,6 +37,7 @@ /* dct code */ typedef short DCTELEM; typedef int DWTELEM; +typedef short IDWTELEM; void fdct_ifast (DCTELEM *data); void fdct_ifast248 (DCTELEM *data); @@ -48,6 +48,7 @@ void j_rev_dct (DCTELEM *data); void j_rev_dct4 (DCTELEM *data); void j_rev_dct2 (DCTELEM *data); void j_rev_dct1 (DCTELEM *data); +void ff_wmv2_idct_c(DCTELEM *data); void ff_fdct_mmx(DCTELEM *block); void ff_fdct_mmx2(DCTELEM *block); @@ -145,7 +146,7 @@ static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ /* motion estimation */ // h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller then 2 -// allthough currently h<4 is not used as functions with width <8 are not used and neither implemented +// although currently h<4 is not used as functions with width <8 are neither used nor implemented typedef int (*me_cmp_func)(void /*MpegEncContext*/ *s, uint8_t *blk1/*align width (8 or 16)*/, uint8_t *blk2/*align 1*/, int line_size, int h)/* __attribute__ ((const))*/; @@ -164,6 +165,7 @@ typedef struct DSPContext { void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); void (*add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size); void (*add_pixels4)(uint8_t *pixels, DCTELEM *block, int line_size); + int (*sum_abs_dctelem)(DCTELEM *block/*align 16*/); /** * translational global motion compensation. */ @@ -200,7 +202,8 @@ typedef struct DSPContext { me_cmp_func ildct_cmp[5]; //only width 16 used me_cmp_func frame_skip_cmp[5]; //only width 8 used - int (*ssd_int8_vs_int16)(int8_t *pix1, int16_t *pix2, int size); + int (*ssd_int8_vs_int16)(const int8_t *pix1, const int16_t *pix2, + int size); /** * Halfpel motion compensation with rounding (a+b+1)>>1. @@ -301,13 +304,16 @@ typedef struct DSPContext { /* huffyuv specific */ void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w); + void (*add_bytes_l2)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 16*/, int w); void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w); /** * subtract huffyuv's variant of median prediction * note, this might read from src1[-1], src2[-1] */ void (*sub_hfyu_median_prediction)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top); - void (*bswap_buf)(uint32_t *dst, uint32_t *src, int w); + /* this might write to dst[w] */ + void (*add_png_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp); + void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w); void (*h264_v_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0); void (*h264_h_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0); @@ -324,8 +330,13 @@ typedef struct DSPContext { void (*h261_loop_filter)(uint8_t *src, int stride); + void (*x8_v_loop_filter)(uint8_t *src, int stride, int qscale); + void (*x8_h_loop_filter)(uint8_t *src, int stride, int qscale); + /* assume len is a multiple of 4, and arrays are 16-byte aligned */ void (*vorbis_inverse_coupling)(float *mag, float *ang, int blocksize); + /* no alignment needed */ + void (*flac_compute_autocorr)(const int32_t *data, int len, int lag, double *autoc); /* assume len is a multiple of 8, and arrays are 16-byte aligned */ void (*vector_fmul)(float *dst, const float *src, int len); void (*vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len); @@ -346,13 +357,13 @@ typedef struct DSPContext { /** * block -> idct -> clip to unsigned 8 bit -> dest. * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...) - * @param line_size size in bytes of a horizotal line of dest + * @param line_size size in bytes of a horizontal line of dest */ void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); /** * block -> idct -> add dest -> clip to unsigned 8 bit -> dest. - * @param line_size size in bytes of a horizotal line of dest + * @param line_size size in bytes of a horizontal line of dest */ void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); @@ -389,8 +400,8 @@ typedef struct DSPContext { void (*h264_dct)(DCTELEM block[4][4]); /* snow wavelet */ - void (*vertical_compose97i)(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width); - void (*horizontal_compose97i)(DWTELEM *b, int width); + void (*vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width); + void (*horizontal_compose97i)(IDWTELEM *b, int width); void (*inner_add_yblock)(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8); void (*prefetch)(void *mem, int stride, int h); @@ -399,15 +410,21 @@ typedef struct DSPContext { /* vc1 functions */ void (*vc1_inv_trans_8x8)(DCTELEM *b); - void (*vc1_inv_trans_8x4)(DCTELEM *b, int n); - void (*vc1_inv_trans_4x8)(DCTELEM *b, int n); - void (*vc1_inv_trans_4x4)(DCTELEM *b, int n); + void (*vc1_inv_trans_8x4)(uint8_t *dest, int line_size, DCTELEM *block); + void (*vc1_inv_trans_4x8)(uint8_t *dest, int line_size, DCTELEM *block); + void (*vc1_inv_trans_4x4)(uint8_t *dest, int line_size, DCTELEM *block); void (*vc1_v_overlap)(uint8_t* src, int stride); void (*vc1_h_overlap)(uint8_t* src, int stride); /* put 8x8 block with bicubic interpolation and quarterpel precision * last argument is actually round value instead of height */ op_pixels_func put_vc1_mspel_pixels_tab[16]; + + /* intrax8 functions */ + void (*x8_spatial_compensation[12])(uint8_t *src , uint8_t *dst, int linesize); + void (*x8_setup_spatial_compensation)(uint8_t *src, uint8_t *dst, int linesize, + int * range, int * sum, int edges); + } DSPContext; void dsputil_static_init(void); @@ -470,11 +487,17 @@ static inline int get_penalty_factor(int lambda, int lambda2, int type){ one or more MultiMedia extension */ int mm_support(void); -#ifdef __GNUC__ - #define DECLARE_ALIGNED_16(t,v) t v __attribute__ ((aligned (16))) -#else - #define DECLARE_ALIGNED_16(t,v) __declspec(align(16)) t v -#endif +void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx); +void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx); +void dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx); +void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx); +void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx); +void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx); +void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx); +void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx); +void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx); + +#define DECLARE_ALIGNED_16(t, v) DECLARE_ALIGNED(16, t, v) #if defined(HAVE_MMX) @@ -497,7 +520,7 @@ void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int li static inline void emms(void) { - __asm __volatile ("emms;":::"memory"); + asm volatile ("emms;":::"memory"); } @@ -507,95 +530,36 @@ static inline void emms(void) emms();\ } -#ifdef __GNUC__ - #define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8))) -#else - #define DECLARE_ALIGNED_8(t,v) __declspec(align(8)) t v -#endif - -#define STRIDE_ALIGN 8 - -void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx); void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx); #elif defined(ARCH_ARMV4L) -/* This is to use 4 bytes read to the IDCT pointers for some 'zero' - line optimizations */ -#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (4))) -#define STRIDE_ALIGN 4 - #define MM_IWMMXT 0x0100 /* XScale IWMMXT */ extern int mm_flags; -void dsputil_init_armv4l(DSPContext* c, AVCodecContext *avctx); - -#elif defined(HAVE_MLIB) - -/* SPARC/VIS IDCT needs 8-byte aligned DCT blocks */ -#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8))) -#define STRIDE_ALIGN 8 - -void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx); - -#elif defined(ARCH_SPARC) - -/* SPARC/VIS IDCT needs 8-byte aligned DCT blocks */ -#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8))) -#define STRIDE_ALIGN 8 -void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx); - -#elif defined(ARCH_ALPHA) - -#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8))) -#define STRIDE_ALIGN 8 - -void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx); - #elif defined(ARCH_POWERPC) #define MM_ALTIVEC 0x0001 /* standard AltiVec */ extern int mm_flags; -#if defined(HAVE_ALTIVEC) && !defined(CONFIG_DARWIN) -#define pixel altivec_pixel -#include -#undef pixel -#endif - -#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (16))) +#define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v) #define STRIDE_ALIGN 16 -void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx); - #elif defined(HAVE_MMI) -#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (16))) +#define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v) #define STRIDE_ALIGN 16 -void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx); - -#elif defined(ARCH_SH4) - -#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8))) -#define STRIDE_ALIGN 8 - -void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx); - -#elif defined(ARCH_BFIN) - -#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8))) -#define STRIDE_ALIGN 8 - -void dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx); - -#else +#endif -#define DECLARE_ALIGNED_8(t,v) t v __attribute__ ((aligned (8))) -#define STRIDE_ALIGN 8 +#ifndef DECLARE_ALIGNED_8 +# define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(8, t, v) +#endif +#ifndef STRIDE_ALIGN +# define STRIDE_ALIGN 8 #endif /* PSNR */ @@ -651,6 +615,14 @@ typedef struct MDCTContext { FFTContext fft; } MDCTContext; +/** + * Generate a Kaiser-Bessel Derived Window. + * @param window pointer to half window + * @param alpha determines window shape + * @param n size of half window + */ +void ff_kbd_window_init(float *window, float alpha, int n); + int ff_mdct_init(MDCTContext *s, int nbits, int inverse); void ff_imdct_calc(MDCTContext *s, FFTSample *output, const FFTSample *input, FFTSample *tmp); @@ -662,13 +634,13 @@ void ff_mdct_calc(MDCTContext *s, FFTSample *out, const FFTSample *input, FFTSample *tmp); void ff_mdct_end(MDCTContext *s); -#define WARPER8_16(name8, name16)\ +#define WRAPPER8_16(name8, name16)\ static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\ return name8(s, dst , src , stride, h)\ +name8(s, dst+8 , src+8 , stride, h);\ } -#define WARPER8_16_SQ(name8, name16)\ +#define WRAPPER8_16_SQ(name8, name16)\ static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\ int score=0;\ score +=name8(s, dst , src , stride, 8);\ @@ -688,7 +660,7 @@ static inline void copy_block2(uint8_t *dst, uint8_t *src, int dstStride, int sr int i; for(i=0; i - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * FFmpeg 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "avcodec.h" -#include - -#include -#include - -#define BUFFER_SIZE 18726 -#define HEADER_SIZE 14 - -#define CONVERT_LEVEL 1 -#define CONVERT_BIAS 0 - -typedef struct DTSContext { - dts_state_t *state; - uint8_t buf[BUFFER_SIZE]; - uint8_t *bufptr; - uint8_t *bufpos; -} DTSContext; - -static inline int16_t -convert(sample_t s) -{ - return s * 0x7fff; -} - -static void -convert2s16_multi(sample_t *f, int16_t *s16, int flags) -{ - int i; - - switch(flags & (DTS_CHANNEL_MASK | DTS_LFE)){ - case DTS_MONO: - for(i = 0; i < 256; i++){ - s16[5*i] = s16[5*i+1] = s16[5*i+2] = s16[5*i+3] = 0; - s16[5*i+4] = convert(f[i]); - } - case DTS_CHANNEL: - case DTS_STEREO: - case DTS_DOLBY: - for(i = 0; i < 256; i++){ - s16[2*i] = convert(f[i]); - s16[2*i+1] = convert(f[i+256]); - } - case DTS_3F: - for(i = 0; i < 256; i++){ - s16[5*i] = convert(f[i+256]); - s16[5*i+1] = convert(f[i+512]); - s16[5*i+2] = s16[5*i+3] = 0; - s16[5*i+4] = convert(f[i]); - } - case DTS_2F2R: - for(i = 0; i < 256; i++){ - s16[4*i] = convert(f[i]); - s16[4*i+1] = convert(f[i+256]); - s16[4*i+2] = convert(f[i+512]); - s16[4*i+3] = convert(f[i+768]); - } - case DTS_3F2R: - for(i = 0; i < 256; i++){ - s16[5*i] = convert(f[i+256]); - s16[5*i+1] = convert(f[i+512]); - s16[5*i+2] = convert(f[i+768]); - s16[5*i+3] = convert(f[i+1024]); - s16[5*i+4] = convert(f[i]); - } - case DTS_MONO | DTS_LFE: - for(i = 0; i < 256; i++){ - s16[6*i] = s16[6*i+1] = s16[6*i+2] = s16[6*i+3] = 0; - s16[6*i+4] = convert(f[i]); - s16[6*i+5] = convert(f[i+256]); - } - case DTS_CHANNEL | DTS_LFE: - case DTS_STEREO | DTS_LFE: - case DTS_DOLBY | DTS_LFE: - for(i = 0; i < 256; i++){ - s16[6*i] = convert(f[i]); - s16[6*i+1] = convert(f[i+256]); - s16[6*i+2] = s16[6*i+3] = s16[6*i+4] = 0; - s16[6*i+5] = convert(f[i+512]); - } - case DTS_3F | DTS_LFE: - for(i = 0; i < 256; i++){ - s16[6*i] = convert(f[i+256]); - s16[6*i+1] = convert(f[i+512]); - s16[6*i+2] = s16[6*i+3] = 0; - s16[6*i+4] = convert(f[i]); - s16[6*i+5] = convert(f[i+768]); - } - case DTS_2F2R | DTS_LFE: - for(i = 0; i < 256; i++){ - s16[6*i] = convert(f[i]); - s16[6*i+1] = convert(f[i+256]); - s16[6*i+2] = convert(f[i+512]); - s16[6*i+3] = convert(f[i+768]); - s16[6*i+4] = 0; - s16[6*i+5] = convert(f[i+1024]); - } - case DTS_3F2R | DTS_LFE: - for(i = 0; i < 256; i++){ - s16[6*i] = convert(f[i+256]); - s16[6*i+1] = convert(f[i+512]); - s16[6*i+2] = convert(f[i+768]); - s16[6*i+3] = convert(f[i+1024]); - s16[6*i+4] = convert(f[i]); - s16[6*i+5] = convert(f[i+1280]); - } - } -} - -static int -channels_multi(int flags) -{ - switch(flags & (DTS_CHANNEL_MASK | DTS_LFE)){ - case DTS_CHANNEL: - case DTS_STEREO: - case DTS_DOLBY: - return 2; - case DTS_2F2R: - return 4; - case DTS_MONO: - case DTS_3F: - case DTS_3F2R: - return 5; - case DTS_MONO | DTS_LFE: - case DTS_CHANNEL | DTS_LFE: - case DTS_STEREO | DTS_LFE: - case DTS_DOLBY | DTS_LFE: - case DTS_3F | DTS_LFE: - case DTS_2F2R | DTS_LFE: - case DTS_3F2R | DTS_LFE: - return 6; - } - - return -1; -} - -static int -dts_decode_frame(AVCodecContext * avctx, void *data, int *data_size, - uint8_t * buff, int buff_size) -{ - DTSContext *s = avctx->priv_data; - uint8_t *start = buff; - uint8_t *end = buff + buff_size; - int16_t *out_samples = data; - int sample_rate; - int frame_length; - int flags; - int bit_rate; - int len; - level_t level; - sample_t bias; - int nblocks; - int i; - - *data_size = 0; - - while(1) { - int length; - - len = end - start; - if(!len) - break; - if(len > s->bufpos - s->bufptr) - len = s->bufpos - s->bufptr; - memcpy(s->bufptr, start, len); - s->bufptr += len; - start += len; - if(s->bufptr != s->bufpos) - return start - buff; - if(s->bufpos != s->buf + HEADER_SIZE) - break; - - length = dts_syncinfo(s->state, s->buf, &flags, &sample_rate, - &bit_rate, &frame_length); - if(!length) { - av_log(NULL, AV_LOG_INFO, "skip\n"); - for(s->bufptr = s->buf; s->bufptr < s->buf + HEADER_SIZE - 1; s->bufptr++) - s->bufptr[0] = s->bufptr[1]; - continue; - } - s->bufpos = s->buf + length; - } - - level = CONVERT_LEVEL; - bias = CONVERT_BIAS; - - flags |= DTS_ADJUST_LEVEL; - if(dts_frame(s->state, s->buf, &flags, &level, bias)) { - av_log(avctx, AV_LOG_ERROR, "dts_frame() failed\n"); - goto end; - } - - avctx->sample_rate = sample_rate; - avctx->channels = channels_multi(flags); - avctx->bit_rate = bit_rate; - - nblocks = dts_blocks_num(s->state); - - for(i = 0; i < nblocks; i++) { - if(dts_block(s->state)) { - av_log(avctx, AV_LOG_ERROR, "dts_block() failed\n"); - goto end; - } - - convert2s16_multi(dts_samples(s->state), out_samples, flags); - - out_samples += 256 * avctx->channels; - *data_size += 256 * sizeof(int16_t) * avctx->channels; - } - -end: - s->bufptr = s->buf; - s->bufpos = s->buf + HEADER_SIZE; - return start - buff; -} - -static int -dts_decode_init(AVCodecContext * avctx) -{ - DTSContext *s = avctx->priv_data; - s->bufptr = s->buf; - s->bufpos = s->buf + HEADER_SIZE; - s->state = dts_init(0); - if(s->state == NULL) - return -1; - - return 0; -} - -static int -dts_decode_end(AVCodecContext * avctx) -{ - DTSContext *s = avctx->priv_data; - dts_free(s->state); - return 0; -} - -AVCodec dts_decoder = { - "dts", - CODEC_TYPE_AUDIO, - CODEC_ID_DTS, - sizeof(DTSContext), - dts_decode_init, - NULL, - dts_decode_end, - dts_decode_frame, -}; diff --git a/contrib/ffmpeg/libavcodec/dump_extradata_bsf.c b/contrib/ffmpeg/libavcodec/dump_extradata_bsf.c new file mode 100644 index 000000000..db263490a --- /dev/null +++ b/contrib/ffmpeg/libavcodec/dump_extradata_bsf.c @@ -0,0 +1,50 @@ +/* + * copyright (c) 2006 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" + + +static int dump_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, + uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size, int keyframe){ + int cmd= args ? *args : 0; + /* cast to avoid warning about discarding qualifiers */ + if(avctx->extradata){ + if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER) && cmd=='a') + ||(keyframe && (cmd=='k' || !cmd)) + ||(cmd=='e') + /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/){ + int size= buf_size + avctx->extradata_size; + *poutbuf_size= size; + *poutbuf= av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); + + memcpy(*poutbuf, avctx->extradata, avctx->extradata_size); + memcpy((*poutbuf) + avctx->extradata_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); + return 1; + } + } + return 0; +} + +AVBitStreamFilter dump_extradata_bsf={ + "dump_extra", + 0, + dump_extradata, +}; diff --git a/contrib/ffmpeg/libavcodec/dv.c b/contrib/ffmpeg/libavcodec/dv.c index 19615b431..66c6d3c11 100644 --- a/contrib/ffmpeg/libavcodec/dv.c +++ b/contrib/ffmpeg/libavcodec/dv.c @@ -225,7 +225,7 @@ static int dvvideo_init(AVCodecContext *avctx) /* 248DCT setup */ s->fdct[1] = dsp.fdct248; - s->idct_put[1] = simple_idct248_put; // FIXME: need to add it to DSP + s->idct_put[1] = ff_simple_idct248_put; // FIXME: need to add it to DSP if(avctx->lowres){ for (i=0; i<64; i++){ int j= ff_zigzag248_direct[i]; @@ -363,7 +363,7 @@ static inline void bit_copy(PutBitContext *pb, GetBitContext *gb) /* mb_x and mb_y are in units of 8 pixels */ static inline void dv_decode_video_segment(DVVideoContext *s, - uint8_t *buf_ptr1, + const uint8_t *buf_ptr1, const uint16_t *mb_pos_ptr) { int quant, dc, dct_mode, class1, j; @@ -372,7 +372,7 @@ static inline void dv_decode_video_segment(DVVideoContext *s, int c_offset; uint8_t *y_ptr; void (*idct_put)(uint8_t *dest, int line_size, DCTELEM *block); - uint8_t *buf_ptr; + const uint8_t *buf_ptr; PutBitContext pb, vs_pb; GetBitContext gb; BlockInfo mb_data[5 * 6], *mb, *mb1; @@ -1031,7 +1031,7 @@ static int dv_encode_mt(AVCodecContext *avctx, void* sl) 144000 bytes for PAL - or twice those for 50Mbps) */ static int dvvideo_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { DVVideoContext *s = avctx->priv_data; diff --git a/contrib/ffmpeg/libavcodec/dvbsub.c b/contrib/ffmpeg/libavcodec/dvbsub.c index 44ba19d86..a1594edd0 100644 --- a/contrib/ffmpeg/libavcodec/dvbsub.c +++ b/contrib/ffmpeg/libavcodec/dvbsub.c @@ -19,6 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avcodec.h" +#include "bytestream.h" +#include "colorspace.h" typedef struct DVBSubtitleContext { int hide_state; @@ -192,31 +194,6 @@ static void dvb_encode_rle4(uint8_t **pq, *pq = q; } -#define SCALEBITS 10 -#define ONE_HALF (1 << (SCALEBITS - 1)) -#define FIX(x) ((int) ((x) * (1<> SCALEBITS) - -#define RGB_TO_U_CCIR(r1, g1, b1, shift)\ -(((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \ - FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) - -#define RGB_TO_V_CCIR(r1, g1, b1, shift)\ -(((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \ - FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) - -static inline void putbe16(uint8_t **pq, uint16_t v) -{ - uint8_t *q; - q = *pq; - *q++ = v >> 8; - *q++ = v; - *pq = q; -} - static int encode_dvb_subtitles(DVBSubtitleContext *s, uint8_t *outbuf, AVSubtitle *h) { @@ -237,7 +214,7 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, *q++ = 0x0f; /* sync_byte */ *q++ = 0x10; /* segment_type */ - putbe16(&q, page_id); + bytestream_put_be16(&q, page_id); pseg_len = q; q += 2; /* segment length */ *q++ = 30; /* page_timeout (seconds) */ @@ -251,11 +228,11 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, for (region_id = 0; region_id < h->num_rects; region_id++) { *q++ = region_id; *q++ = 0xff; /* reserved */ - putbe16(&q, h->rects[region_id].x); /* left pos */ - putbe16(&q, h->rects[region_id].y); /* top pos */ + bytestream_put_be16(&q, h->rects[region_id].x); /* left pos */ + bytestream_put_be16(&q, h->rects[region_id].y); /* top pos */ } - putbe16(&pseg_len, q - pseg_len - 2); + bytestream_put_be16(&pseg_len, q - pseg_len - 2); if (!s->hide_state) { for (clut_id = 0; clut_id < h->num_rects; clut_id++) { @@ -274,7 +251,7 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, *q++ = 0x0f; /* sync byte */ *q++ = 0x12; /* CLUT definition segment */ - putbe16(&q, page_id); + bytestream_put_be16(&q, page_id); pseg_len = q; q += 2; /* segment length */ *q++ = clut_id; @@ -297,7 +274,7 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, } } - putbe16(&pseg_len, q - pseg_len - 2); + bytestream_put_be16(&pseg_len, q - pseg_len - 2); } } @@ -317,27 +294,27 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, *q++ = 0x0f; /* sync_byte */ *q++ = 0x11; /* segment_type */ - putbe16(&q, page_id); + bytestream_put_be16(&q, page_id); pseg_len = q; q += 2; /* segment length */ *q++ = region_id; *q++ = (s->object_version << 4) | (0 << 3) | 0x07; /* version , no fill */ - putbe16(&q, h->rects[region_id].w); /* region width */ - putbe16(&q, h->rects[region_id].h); /* region height */ + bytestream_put_be16(&q, h->rects[region_id].w); /* region width */ + bytestream_put_be16(&q, h->rects[region_id].h); /* region height */ *q++ = ((1 + bpp_index) << 5) | ((1 + bpp_index) << 2) | 0x03; *q++ = region_id; /* clut_id == region_id */ *q++ = 0; /* 8 bit fill colors */ *q++ = 0x03; /* 4 bit and 2 bit fill colors */ if (!s->hide_state) { - putbe16(&q, region_id); /* object_id == region_id */ + bytestream_put_be16(&q, region_id); /* object_id == region_id */ *q++ = (0 << 6) | (0 << 4); *q++ = 0; *q++ = 0xf0; *q++ = 0; } - putbe16(&pseg_len, q - pseg_len - 2); + bytestream_put_be16(&pseg_len, q - pseg_len - 2); } if (!s->hide_state) { @@ -357,11 +334,11 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, *q++ = 0x0f; /* sync byte */ *q++ = 0x13; - putbe16(&q, page_id); + bytestream_put_be16(&q, page_id); pseg_len = q; q += 2; /* segment length */ - putbe16(&q, object_id); + bytestream_put_be16(&q, object_id); *q++ = (s->object_version << 4) | (0 << 2) | (0 << 1) | 1; /* version = 0, onject_coding_method, non_modifying_color_flag */ @@ -388,11 +365,11 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, h->rects[object_id].w * 2, h->rects[object_id].w, h->rects[object_id].h >> 1); - putbe16(&ptop_field_len, bottom_ptr - top_ptr); - putbe16(&pbottom_field_len, q - bottom_ptr); + bytestream_put_be16(&ptop_field_len, bottom_ptr - top_ptr); + bytestream_put_be16(&pbottom_field_len, q - bottom_ptr); } - putbe16(&pseg_len, q - pseg_len - 2); + bytestream_put_be16(&pseg_len, q - pseg_len - 2); } } @@ -400,11 +377,11 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, *q++ = 0x0f; /* sync_byte */ *q++ = 0x80; /* segment_type */ - putbe16(&q, page_id); + bytestream_put_be16(&q, page_id); pseg_len = q; q += 2; /* segment length */ - putbe16(&pseg_len, q - pseg_len - 2); + bytestream_put_be16(&pseg_len, q - pseg_len - 2); *q++ = 0xff; /* end of PES data */ @@ -413,16 +390,6 @@ static int encode_dvb_subtitles(DVBSubtitleContext *s, return q - outbuf; } -static int dvbsub_init_decoder(AVCodecContext *avctx) -{ - return 0; -} - -static int dvbsub_close_decoder(AVCodecContext *avctx) -{ - return 0; -} - static int dvbsub_encode(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data) { @@ -439,7 +406,6 @@ AVCodec dvbsub_encoder = { CODEC_TYPE_SUBTITLE, CODEC_ID_DVB_SUBTITLE, sizeof(DVBSubtitleContext), - dvbsub_init_decoder, + NULL, dvbsub_encode, - dvbsub_close_decoder, }; diff --git a/contrib/ffmpeg/libavcodec/dvbsub_parser.c b/contrib/ffmpeg/libavcodec/dvbsub_parser.c new file mode 100644 index 000000000..312c243bf --- /dev/null +++ b/contrib/ffmpeg/libavcodec/dvbsub_parser.c @@ -0,0 +1,196 @@ +/* + * DVB subtitle parser for FFmpeg + * Copyright (c) 2005 Ian Caulfield. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avcodec.h" +#include "dsputil.h" +#include "bitstream.h" + +//#define DEBUG +//#define DEBUG_PACKET_CONTENTS + +/* Parser (mostly) copied from dvdsub.c */ + +#define PARSE_BUF_SIZE (65536) + + +/* parser definition */ +typedef struct DVBSubParseContext { + uint8_t *packet_buf; + int packet_start; + int packet_index; + int in_packet; +} DVBSubParseContext; + +static int dvbsub_parse_init(AVCodecParserContext *s) +{ + DVBSubParseContext *pc = s->priv_data; + pc->packet_buf = av_malloc(PARSE_BUF_SIZE); + + return 0; +} + +static int dvbsub_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + DVBSubParseContext *pc = s->priv_data; + uint8_t *p, *p_end; + int len, buf_pos = 0; + +#ifdef DEBUG + av_log(avctx, AV_LOG_INFO, "DVB parse packet pts=%"PRIx64", lpts=%"PRIx64", cpts=%"PRIx64":\n", + s->pts, s->last_pts, s->cur_frame_pts[s->cur_frame_start_index]); +#endif + +#ifdef DEBUG_PACKET_CONTENTS + int i; + + for (i=0; i < buf_size; i++) + { + av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); + if (i % 16 == 15) + av_log(avctx, AV_LOG_INFO, "\n"); + } + + if (i % 16 != 0) + av_log(avctx, AV_LOG_INFO, "\n"); + +#endif + + *poutbuf = NULL; + *poutbuf_size = 0; + + s->fetch_timestamp = 1; + + if (s->last_pts != s->pts && s->last_pts != AV_NOPTS_VALUE) /* Start of a new packet */ + { + if (pc->packet_index != pc->packet_start) + { +#ifdef DEBUG + av_log(avctx, AV_LOG_INFO, "Discarding %d bytes\n", + pc->packet_index - pc->packet_start); +#endif + } + + pc->packet_start = 0; + pc->packet_index = 0; + + if (buf_size < 2 || buf[0] != 0x20 || buf[1] != 0x00) { +#ifdef DEBUG + av_log(avctx, AV_LOG_INFO, "Bad packet header\n"); +#endif + return -1; + } + + buf_pos = 2; + + pc->in_packet = 1; + } else { + if (pc->packet_start != 0) + { + if (pc->packet_index != pc->packet_start) + { + memmove(pc->packet_buf, pc->packet_buf + pc->packet_start, + pc->packet_index - pc->packet_start); + + pc->packet_index -= pc->packet_start; + pc->packet_start = 0; + } else { + pc->packet_start = 0; + pc->packet_index = 0; + } + } + } + + if (buf_size - buf_pos + pc->packet_index > PARSE_BUF_SIZE) + return -1; + +/* if not currently in a packet, discard data */ + if (pc->in_packet == 0) + return buf_size; + + memcpy(pc->packet_buf + pc->packet_index, buf + buf_pos, buf_size - buf_pos); + pc->packet_index += buf_size - buf_pos; + + p = pc->packet_buf; + p_end = pc->packet_buf + pc->packet_index; + + while (p < p_end) + { + if (*p == 0x0f) + { + if (p + 6 <= p_end) + { + len = AV_RB16(p + 4); + + if (p + len + 6 <= p_end) + { + *poutbuf_size += len + 6; + + p += len + 6; + } else + break; + } else + break; + } else if (*p == 0xff) { + if (p + 1 < p_end) + { +#ifdef DEBUG + av_log(avctx, AV_LOG_INFO, "Junk at end of packet\n"); +#endif + } + pc->packet_index = p - pc->packet_buf; + pc->in_packet = 0; + break; + } else { + av_log(avctx, AV_LOG_ERROR, "Junk in packet\n"); + + pc->packet_index = p - pc->packet_buf; + pc->in_packet = 0; + break; + } + } + + if (*poutbuf_size > 0) + { + *poutbuf = pc->packet_buf; + pc->packet_start = *poutbuf_size; + } + + if (s->last_pts == AV_NOPTS_VALUE) + s->last_pts = s->pts; + + return buf_size; +} + +static void dvbsub_parse_close(AVCodecParserContext *s) +{ + DVBSubParseContext *pc = s->priv_data; + av_freep(&pc->packet_buf); +} + +AVCodecParser dvbsub_parser = { + { CODEC_ID_DVB_SUBTITLE }, + sizeof(DVBSubParseContext), + dvbsub_parse_init, + dvbsub_parse, + dvbsub_parse_close, +}; diff --git a/contrib/ffmpeg/libavcodec/dvbsubdec.c b/contrib/ffmpeg/libavcodec/dvbsubdec.c index 08ef6213e..5822564e7 100644 --- a/contrib/ffmpeg/libavcodec/dvbsubdec.c +++ b/contrib/ffmpeg/libavcodec/dvbsubdec.c @@ -21,6 +21,7 @@ #include "avcodec.h" #include "dsputil.h" #include "bitstream.h" +#include "colorspace.h" //#define DEBUG //#define DEBUG_PACKET_CONTENTS @@ -101,7 +102,7 @@ static void png_save2(const char *filename, uint32_t *bitmap, int w, int h) char fname[40], fname2[40]; char command[1024]; - snprintf(fname, 40, "%s.ppm", filename); + snprintf(fname, sizeof(fname), "%s.ppm", filename); f = fopen(fname, "w"); if (!f) { @@ -123,7 +124,7 @@ static void png_save2(const char *filename, uint32_t *bitmap, int w, int h) fclose(f); - snprintf(fname2, 40, "%s-a.pgm", filename); + snprintf(fname2, sizeof(fname2), "%s-a.pgm", filename); f = fopen(fname2, "w"); if (!f) { @@ -142,10 +143,10 @@ static void png_save2(const char *filename, uint32_t *bitmap, int w, int h) } fclose(f); - snprintf(command, 1024, "pnmtopng -alpha %s %s > %s.png 2> /dev/null", fname2, fname, filename); + snprintf(command, sizeof(command), "pnmtopng -alpha %s %s > %s.png 2> /dev/null", fname2, fname, filename); system(command); - snprintf(command, 1024, "rm %s %s", fname, fname2); + snprintf(command, sizeof(command), "rm %s %s", fname, fname2); system(command); } #endif @@ -171,8 +172,8 @@ typedef struct DVBSubObjectDisplay { int x_pos; int y_pos; - int fgcolour; - int bgcolour; + int fgcolor; + int bgcolor; struct DVBSubObjectDisplay *region_list_next; struct DVBSubObjectDisplay *object_list_next; @@ -205,7 +206,7 @@ typedef struct DVBSubRegion { int depth; int clut; - int bgcolour; + int bgcolor; uint8_t *pbuf; int buf_size; @@ -233,7 +234,7 @@ static DVBSubObject* get_object(DVBSubContext *ctx, int object_id) { DVBSubObject *ptr = ctx->object_list; - while (ptr != NULL && ptr->id != object_id) { + while (ptr && ptr->id != object_id) { ptr = ptr->next; } @@ -244,7 +245,7 @@ static DVBSubCLUT* get_clut(DVBSubContext *ctx, int clut_id) { DVBSubCLUT *ptr = ctx->clut_list; - while (ptr != NULL && ptr->id != clut_id) { + while (ptr && ptr->id != clut_id) { ptr = ptr->next; } @@ -255,7 +256,7 @@ static DVBSubRegion* get_region(DVBSubContext *ctx, int region_id) { DVBSubRegion *ptr = ctx->region_list; - while (ptr != NULL && ptr->id != region_id) { + while (ptr && ptr->id != region_id) { ptr = ptr->next; } @@ -267,16 +268,16 @@ static void delete_region_display_list(DVBSubContext *ctx, DVBSubRegion *region) DVBSubObject *object, *obj2, **obj2_ptr; DVBSubObjectDisplay *display, *obj_disp, **obj_disp_ptr; - while (region->display_list != NULL) { + while (region->display_list) { display = region->display_list; object = get_object(ctx, display->object_id); - if (object != NULL) { + if (object) { obj_disp = object->display_list; obj_disp_ptr = &object->display_list; - while (obj_disp != NULL && obj_disp != display) { + while (obj_disp && obj_disp != display) { obj_disp_ptr = &obj_disp->object_list_next; obj_disp = obj_disp->object_list_next; } @@ -284,11 +285,11 @@ static void delete_region_display_list(DVBSubContext *ctx, DVBSubRegion *region) if (obj_disp) { *obj_disp_ptr = obj_disp->object_list_next; - if (object->display_list == NULL) { + if (!object->display_list) { obj2 = ctx->object_list; obj2_ptr = &ctx->object_list; - while (obj2 != NULL && obj2 != object) { + while (obj2 && obj2 != object) { obj2_ptr = &obj2->next; obj2 = obj2->next; } @@ -312,21 +313,19 @@ static void delete_state(DVBSubContext *ctx) DVBSubRegion *region; DVBSubCLUT *clut; - while (ctx->region_list != NULL) - { + while (ctx->region_list) { region = ctx->region_list; ctx->region_list = region->next; delete_region_display_list(ctx, region); - if (region->pbuf != NULL) + if (region->pbuf) av_free(region->pbuf); av_free(region); } - while (ctx->clut_list != NULL) - { + while (ctx->clut_list) { clut = ctx->clut_list; ctx->clut_list = clut->next; @@ -335,7 +334,7 @@ static void delete_state(DVBSubContext *ctx) } /* Should already be null */ - if (ctx->object_list != NULL) + if (ctx->object_list) av_log(0, AV_LOG_ERROR, "Memory deallocation error!\n"); } @@ -419,8 +418,7 @@ static int dvbsub_close_decoder(AVCodecContext *avctx) delete_state(ctx); - while (ctx->display_list != NULL) - { + while (ctx->display_list) { display = ctx->display_list; ctx->display_list = display->next; @@ -431,7 +429,7 @@ static int dvbsub_close_decoder(AVCodecContext *avctx) } static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, - uint8_t **srcbuf, int buf_size, + const uint8_t **srcbuf, int buf_size, int non_mod, uint8_t *map_table) { GetBitContext gb; @@ -445,16 +443,16 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, while (get_bits_count(&gb) < (buf_size << 8) && pixels_read < dbuf_len) { bits = get_bits(&gb, 2); - if (bits != 0) { + if (bits) { if (non_mod != 1 || bits != 1) { - if (map_table != NULL) + if (map_table) *destbuf++ = map_table[bits]; else *destbuf++ = bits; } pixels_read++; } else { - bits = get_bits(&gb, 1); + bits = get_bits1(&gb); if (bits == 1) { run_length = get_bits(&gb, 3) + 3; bits = get_bits(&gb, 2); @@ -462,7 +460,7 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, if (non_mod == 1 && bits == 1) pixels_read += run_length; else { - if (map_table != NULL) + if (map_table) bits = map_table[bits]; while (run_length-- > 0 && pixels_read < dbuf_len) { *destbuf++ = bits; @@ -470,7 +468,7 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, } } } else { - bits = get_bits(&gb, 1); + bits = get_bits1(&gb); if (bits == 0) { bits = get_bits(&gb, 2); if (bits == 2) { @@ -480,7 +478,7 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, if (non_mod == 1 && bits == 1) pixels_read += run_length; else { - if (map_table != NULL) + if (map_table) bits = map_table[bits]; while (run_length-- > 0 && pixels_read < dbuf_len) { *destbuf++ = bits; @@ -494,7 +492,7 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, if (non_mod == 1 && bits == 1) pixels_read += run_length; else { - if (map_table != NULL) + if (map_table) bits = map_table[bits]; while (run_length-- > 0 && pixels_read < dbuf_len) { *destbuf++ = bits; @@ -503,7 +501,7 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, } } else if (bits == 1) { pixels_read += 2; - if (map_table != NULL) + if (map_table) bits = map_table[0]; else bits = 0; @@ -516,7 +514,7 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, return pixels_read; } } else { - if (map_table != NULL) + if (map_table) bits = map_table[0]; else bits = 0; @@ -527,7 +525,7 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, } } - if (get_bits(&gb, 6) != 0) + if (get_bits(&gb, 6)) av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n"); (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; @@ -536,7 +534,7 @@ static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, } static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, - uint8_t **srcbuf, int buf_size, + const uint8_t **srcbuf, int buf_size, int non_mod, uint8_t *map_table) { GetBitContext gb; @@ -550,16 +548,16 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, while (get_bits_count(&gb) < (buf_size << 8) && pixels_read < dbuf_len) { bits = get_bits(&gb, 4); - if (bits != 0) { + if (bits) { if (non_mod != 1 || bits != 1) { - if (map_table != NULL) + if (map_table) *destbuf++ = map_table[bits]; else *destbuf++ = bits; } pixels_read++; } else { - bits = get_bits(&gb, 1); + bits = get_bits1(&gb); if (bits == 0) { run_length = get_bits(&gb, 3); @@ -570,7 +568,7 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, run_length += 2; - if (map_table != NULL) + if (map_table) bits = map_table[0]; else bits = 0; @@ -580,7 +578,7 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, pixels_read++; } } else { - bits = get_bits(&gb, 1); + bits = get_bits1(&gb); if (bits == 0) { run_length = get_bits(&gb, 2) + 4; bits = get_bits(&gb, 4); @@ -588,7 +586,7 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, if (non_mod == 1 && bits == 1) pixels_read += run_length; else { - if (map_table != NULL) + if (map_table) bits = map_table[bits]; while (run_length-- > 0 && pixels_read < dbuf_len) { *destbuf++ = bits; @@ -604,7 +602,7 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, if (non_mod == 1 && bits == 1) pixels_read += run_length; else { - if (map_table != NULL) + if (map_table) bits = map_table[bits]; while (run_length-- > 0 && pixels_read < dbuf_len) { *destbuf++ = bits; @@ -618,7 +616,7 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, if (non_mod == 1 && bits == 1) pixels_read += run_length; else { - if (map_table != NULL) + if (map_table) bits = map_table[bits]; while (run_length-- > 0 && pixels_read < dbuf_len) { *destbuf++ = bits; @@ -627,7 +625,7 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, } } else if (bits == 1) { pixels_read += 2; - if (map_table != NULL) + if (map_table) bits = map_table[0]; else bits = 0; @@ -636,7 +634,7 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, *destbuf++ = bits; } } else { - if (map_table != NULL) + if (map_table) bits = map_table[0]; else bits = 0; @@ -648,7 +646,7 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, } } - if (get_bits(&gb, 8) != 0) + if (get_bits(&gb, 8)) av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n"); (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; @@ -657,10 +655,10 @@ static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, } static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len, - uint8_t **srcbuf, int buf_size, + const uint8_t **srcbuf, int buf_size, int non_mod, uint8_t *map_table) { - uint8_t *sbuf_end = (*srcbuf) + buf_size; + const uint8_t *sbuf_end = (*srcbuf) + buf_size; int bits; int run_length; int pixels_read = 0; @@ -668,9 +666,9 @@ static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len, while (*srcbuf < sbuf_end && pixels_read < dbuf_len) { bits = *(*srcbuf)++; - if (bits != 0) { + if (bits) { if (non_mod != 1 || bits != 1) { - if (map_table != NULL) + if (map_table) *destbuf++ = map_table[bits]; else *destbuf++ = bits; @@ -684,7 +682,7 @@ static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len, return pixels_read; } - if (map_table != NULL) + if (map_table) bits = map_table[0]; else bits = 0; @@ -697,7 +695,7 @@ static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len, if (non_mod == 1 && bits == 1) pixels_read += run_length; - if (map_table != NULL) + if (map_table) bits = map_table[bits]; else while (run_length-- > 0 && pixels_read < dbuf_len) { *destbuf++ = bits; @@ -707,7 +705,7 @@ static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len, } } - if (*(*srcbuf)++ != 0) + if (*(*srcbuf)++) av_log(0, AV_LOG_ERROR, "DVBSub error: line overflow\n"); return pixels_read; @@ -716,12 +714,12 @@ static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len, static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDisplay *display, - uint8_t *buf, int buf_size, int top_bottom, int non_mod) + const uint8_t *buf, int buf_size, int top_bottom, int non_mod) { DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; DVBSubRegion *region = get_region(ctx, display->region_id); - uint8_t *buf_end = buf + buf_size; + const uint8_t *buf_end = buf + buf_size; uint8_t *pbuf; int x_pos, y_pos; int i; @@ -738,8 +736,7 @@ static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDis #endif #ifdef DEBUG_PACKET_CONTENTS - for (i = 0; i < buf_size; i++) - { + for (i = 0; i < buf_size; i++) { if (i % 16 == 0) av_log(avctx, AV_LOG_INFO, "0x%08p: ", buf+i); @@ -748,7 +745,7 @@ static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDis av_log(avctx, AV_LOG_INFO, "\n"); } - if (i % 16 != 0) + if (i % 16) av_log(avctx, AV_LOG_INFO, "\n"); #endif @@ -836,18 +833,18 @@ static void dvbsub_parse_pixel_data_block(AVCodecContext *avctx, DVBSubObjectDis } static void dvbsub_parse_object_segment(AVCodecContext *avctx, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; - uint8_t *buf_end = buf + buf_size; - uint8_t *block; + const uint8_t *buf_end = buf + buf_size; + const uint8_t *block; int object_id; DVBSubObject *object; DVBSubObjectDisplay *display; int top_field_len, bottom_field_len; - int coding_method, non_modifying_colour; + int coding_method, non_modifying_color; object_id = AV_RB16(buf); buf += 2; @@ -858,7 +855,7 @@ static void dvbsub_parse_object_segment(AVCodecContext *avctx, return; coding_method = ((*buf) >> 2) & 3; - non_modifying_colour = ((*buf++) >> 1) & 1; + non_modifying_color = ((*buf++) >> 1) & 1; if (coding_method == 0) { top_field_len = AV_RB16(buf); @@ -871,11 +868,11 @@ static void dvbsub_parse_object_segment(AVCodecContext *avctx, return; } - for (display = object->display_list; display != 0; display = display->object_list_next) { + for (display = object->display_list; display; display = display->object_list_next) { block = buf; dvbsub_parse_pixel_data_block(avctx, display, block, top_field_len, 0, - non_modifying_colour); + non_modifying_color); if (bottom_field_len > 0) block = buf + top_field_len; @@ -883,7 +880,7 @@ static void dvbsub_parse_object_segment(AVCodecContext *avctx, bottom_field_len = top_field_len; dvbsub_parse_pixel_data_block(avctx, display, block, bottom_field_len, 1, - non_modifying_colour); + non_modifying_color); } /* } else if (coding_method == 1) {*/ @@ -894,35 +891,12 @@ static void dvbsub_parse_object_segment(AVCodecContext *avctx, } -#define SCALEBITS 10 -#define ONE_HALF (1 << (SCALEBITS - 1)) -#define FIX(x) ((int) ((x) * (1<> SCALEBITS];\ - g = cm[(y + g_add) >> SCALEBITS];\ - b = cm[(y + b_add) >> SCALEBITS];\ -} - - static void dvbsub_parse_clut_segment(AVCodecContext *avctx, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; - uint8_t *buf_end = buf + buf_size; + const uint8_t *buf_end = buf + buf_size; int clut_id; DVBSubCLUT *clut; int entry_id, depth , full_range; @@ -934,14 +908,13 @@ static void dvbsub_parse_clut_segment(AVCodecContext *avctx, av_log(avctx, AV_LOG_INFO, "DVB clut packet:\n"); - for (i=0; i < buf_size; i++) - { + for (i=0; i < buf_size; i++) { av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); if (i % 16 == 15) av_log(avctx, AV_LOG_INFO, "\n"); } - if (i % 16 != 0) + if (i % 16) av_log(avctx, AV_LOG_INFO, "\n"); #endif @@ -951,7 +924,7 @@ static void dvbsub_parse_clut_segment(AVCodecContext *avctx, clut = get_clut(ctx, clut_id); - if (clut == NULL) { + if (!clut) { clut = av_malloc(sizeof(DVBSubCLUT)); memcpy(clut, &default_clut, sizeof(DVBSubCLUT)); @@ -962,8 +935,7 @@ static void dvbsub_parse_clut_segment(AVCodecContext *avctx, ctx->clut_list = clut; } - while (buf + 4 < buf_end) - { + while (buf + 4 < buf_end) { entry_id = *buf++; depth = (*buf) & 0xe0; @@ -1010,11 +982,11 @@ static void dvbsub_parse_clut_segment(AVCodecContext *avctx, static void dvbsub_parse_region_segment(AVCodecContext *avctx, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; - uint8_t *buf_end = buf + buf_size; + const uint8_t *buf_end = buf + buf_size; int region_id, object_id; DVBSubRegion *region; DVBSubObject *object; @@ -1028,8 +1000,7 @@ static void dvbsub_parse_region_segment(AVCodecContext *avctx, region = get_region(ctx, region_id); - if (region == NULL) - { + if (!region) { region = av_mallocz(sizeof(DVBSubRegion)); region->id = region_id; @@ -1046,7 +1017,7 @@ static void dvbsub_parse_region_segment(AVCodecContext *avctx, buf += 2; if (region->width * region->height != region->buf_size) { - if (region->pbuf != 0) + if (region->pbuf) av_free(region->pbuf); region->buf_size = region->width * region->height; @@ -1057,17 +1028,21 @@ static void dvbsub_parse_region_segment(AVCodecContext *avctx, } region->depth = 1 << (((*buf++) >> 2) & 7); + if(region->depth<2 || region->depth>8){ + av_log(avctx, AV_LOG_ERROR, "region depth %d is invalid\n", region->depth); + region->depth= 4; + } region->clut = *buf++; if (region->depth == 8) - region->bgcolour = *buf++; + region->bgcolor = *buf++; else { buf += 1; if (region->depth == 4) - region->bgcolour = (((*buf++) >> 4) & 15); + region->bgcolor = (((*buf++) >> 4) & 15); else - region->bgcolour = (((*buf++) >> 2) & 3); + region->bgcolor = (((*buf++) >> 2) & 3); } #ifdef DEBUG @@ -1075,9 +1050,9 @@ static void dvbsub_parse_region_segment(AVCodecContext *avctx, #endif if (fill) { - memset(region->pbuf, region->bgcolour, region->buf_size); + memset(region->pbuf, region->bgcolor, region->buf_size); #ifdef DEBUG - av_log(avctx, AV_LOG_INFO, "Fill region (%d)\n", region->bgcolour); + av_log(avctx, AV_LOG_INFO, "Fill region (%d)\n", region->bgcolor); #endif } @@ -1089,7 +1064,7 @@ static void dvbsub_parse_region_segment(AVCodecContext *avctx, object = get_object(ctx, object_id); - if (object == NULL) { + if (!object) { object = av_mallocz(sizeof(DVBSubObject)); object->id = object_id; @@ -1110,8 +1085,8 @@ static void dvbsub_parse_region_segment(AVCodecContext *avctx, buf += 2; if ((object->type == 1 || object->type == 2) && buf+1 < buf_end) { - display->fgcolour = *buf++; - display->bgcolour = *buf++; + display->fgcolor = *buf++; + display->bgcolor = *buf++; } display->region_list_next = region->display_list; @@ -1123,13 +1098,13 @@ static void dvbsub_parse_region_segment(AVCodecContext *avctx, } static void dvbsub_parse_page_segment(AVCodecContext *avctx, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; DVBSubRegionDisplay *display; DVBSubRegionDisplay *tmp_display_list, **tmp_ptr; - uint8_t *buf_end = buf + buf_size; + const uint8_t *buf_end = buf + buf_size; int region_id; int page_state; @@ -1143,8 +1118,7 @@ static void dvbsub_parse_page_segment(AVCodecContext *avctx, av_log(avctx, AV_LOG_INFO, "Page time out %ds, state %d\n", ctx->time_out, page_state); #endif - if (page_state == 2) - { + if (page_state == 2) { delete_state(ctx); } @@ -1159,12 +1133,12 @@ static void dvbsub_parse_page_segment(AVCodecContext *avctx, display = tmp_display_list; tmp_ptr = &tmp_display_list; - while (display != NULL && display->region_id != region_id) { + while (display && display->region_id != region_id) { tmp_ptr = &display->next; display = display->next; } - if (display == NULL) + if (!display) display = av_mallocz(sizeof(DVBSubRegionDisplay)); display->region_id = region_id; @@ -1185,7 +1159,7 @@ static void dvbsub_parse_page_segment(AVCodecContext *avctx, #endif } - while (tmp_display_list != 0) { + while (tmp_display_list) { display = tmp_display_list; tmp_display_list = display->next; @@ -1214,7 +1188,7 @@ static void save_display_set(DVBSubContext *ctx) width = 0; height = 0; - for (display = ctx->display_list; display != NULL; display = display->next) { + for (display = ctx->display_list; display; display = display->next) { region = get_region(ctx, display->region_id); if (x_pos == -1) { @@ -1247,7 +1221,7 @@ static void save_display_set(DVBSubContext *ctx) pbuf = av_malloc(width * height * 4); - for (display = ctx->display_list; display != NULL; display = display->next) { + for (display = ctx->display_list; display; display = display->next) { region = get_region(ctx, display->region_id); x_off = display->x_pos - x_pos; @@ -1280,7 +1254,7 @@ static void save_display_set(DVBSubContext *ctx) } - snprintf(filename, 32, "dvbs.%d", fileno_index); + snprintf(filename, sizeof(filename), "dvbs.%d", fileno_index); png_save2(filename, pbuf, width, height); @@ -1291,7 +1265,7 @@ static void save_display_set(DVBSubContext *ctx) } #endif -static int dvbsub_display_end_segment(AVCodecContext *avctx, uint8_t *buf, +static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf, int buf_size, AVSubtitle *sub) { DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; @@ -1315,11 +1289,11 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, uint8_t *buf, i = 0; - for (display = ctx->display_list; display != NULL; display = display->next) { + for (display = ctx->display_list; display; display = display->next) { region = get_region(ctx, display->region_id); rect = &sub->rects[i]; - if (region == NULL) + if (!region) continue; rect->x = display->x_pos; @@ -1331,7 +1305,7 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, uint8_t *buf, clut = get_clut(ctx, region->clut); - if (clut == NULL) + if (!clut) clut = &default_clut; switch (region->depth) { @@ -1367,11 +1341,11 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, uint8_t *buf, static int dvbsub_decode(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { DVBSubContext *ctx = (DVBSubContext*) avctx->priv_data; AVSubtitle *sub = (AVSubtitle*) data; - uint8_t *p, *p_end; + const uint8_t *p, *p_end; int segment_type; int page_id; int segment_length; @@ -1381,14 +1355,13 @@ static int dvbsub_decode(AVCodecContext *avctx, av_log(avctx, AV_LOG_INFO, "DVB sub packet:\n"); - for (i=0; i < buf_size; i++) - { + for (i=0; i < buf_size; i++) { av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); if (i % 16 == 15) av_log(avctx, AV_LOG_INFO, "\n"); } - if (i % 16 != 0) + if (i % 16) av_log(avctx, AV_LOG_INFO, "\n"); #endif @@ -1399,8 +1372,7 @@ static int dvbsub_decode(AVCodecContext *avctx, p = buf; p_end = buf + buf_size; - while (p < p_end && *p == 0x0f) - { + while (p < p_end && *p == 0x0f) { p += 1; segment_type = *p++; page_id = AV_RB16(p); @@ -1437,8 +1409,7 @@ static int dvbsub_decode(AVCodecContext *avctx, p += segment_length; } - if (p != p_end) - { + if (p != p_end) { #ifdef DEBUG av_log(avctx, AV_LOG_INFO, "Junk at end of packet\n"); #endif @@ -1459,173 +1430,3 @@ AVCodec dvbsub_decoder = { dvbsub_close_decoder, dvbsub_decode, }; - -/* Parser (mostly) copied from dvdsub.c */ - -#define PARSE_BUF_SIZE (65536) - - -/* parser definition */ -typedef struct DVBSubParseContext { - uint8_t *packet_buf; - int packet_start; - int packet_index; - int in_packet; -} DVBSubParseContext; - -static int dvbsub_parse_init(AVCodecParserContext *s) -{ - DVBSubParseContext *pc = s->priv_data; - pc->packet_buf = av_malloc(PARSE_BUF_SIZE); - - return 0; -} - -static int dvbsub_parse(AVCodecParserContext *s, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - DVBSubParseContext *pc = s->priv_data; - uint8_t *p, *p_end; - int len, buf_pos = 0; - -#ifdef DEBUG - av_log(avctx, AV_LOG_INFO, "DVB parse packet pts=%"PRIx64", lpts=%"PRIx64", cpts=%"PRIx64":\n", - s->pts, s->last_pts, s->cur_frame_pts[s->cur_frame_start_index]); -#endif - -#ifdef DEBUG_PACKET_CONTENTS - int i; - - for (i=0; i < buf_size; i++) - { - av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); - if (i % 16 == 15) - av_log(avctx, AV_LOG_INFO, "\n"); - } - - if (i % 16 != 0) - av_log(avctx, AV_LOG_INFO, "\n"); - -#endif - - *poutbuf = NULL; - *poutbuf_size = 0; - - s->fetch_timestamp = 1; - - if (s->last_pts != s->pts && s->last_pts != AV_NOPTS_VALUE) /* Start of a new packet */ - { - if (pc->packet_index != pc->packet_start) - { -#ifdef DEBUG - av_log(avctx, AV_LOG_INFO, "Discarding %d bytes\n", - pc->packet_index - pc->packet_start); -#endif - } - - pc->packet_start = 0; - pc->packet_index = 0; - - if (buf_size < 2 || buf[0] != 0x20 || buf[1] != 0x00) { -#ifdef DEBUG - av_log(avctx, AV_LOG_INFO, "Bad packet header\n"); -#endif - return -1; - } - - buf_pos = 2; - - pc->in_packet = 1; - } else { - if (pc->packet_start != 0) - { - if (pc->packet_index != pc->packet_start) - { - memmove(pc->packet_buf, pc->packet_buf + pc->packet_start, - pc->packet_index - pc->packet_start); - - pc->packet_index -= pc->packet_start; - pc->packet_start = 0; - } else { - pc->packet_start = 0; - pc->packet_index = 0; - } - } - } - - if (buf_size - buf_pos + pc->packet_index > PARSE_BUF_SIZE) - return -1; - -/* if not currently in a packet, discard data */ - if (pc->in_packet == 0) - return buf_size; - - memcpy(pc->packet_buf + pc->packet_index, buf + buf_pos, buf_size - buf_pos); - pc->packet_index += buf_size - buf_pos; - - p = pc->packet_buf; - p_end = pc->packet_buf + pc->packet_index; - - while (p < p_end) - { - if (*p == 0x0f) - { - if (p + 6 <= p_end) - { - len = AV_RB16(p + 4); - - if (p + len + 6 <= p_end) - { - *poutbuf_size += len + 6; - - p += len + 6; - } else - break; - } else - break; - } else if (*p == 0xff) { - if (p + 1 < p_end) - { -#ifdef DEBUG - av_log(avctx, AV_LOG_INFO, "Junk at end of packet\n"); -#endif - } - pc->packet_index = p - pc->packet_buf; - pc->in_packet = 0; - break; - } else { - av_log(avctx, AV_LOG_ERROR, "Junk in packet\n"); - - pc->packet_index = p - pc->packet_buf; - pc->in_packet = 0; - break; - } - } - - if (*poutbuf_size > 0) - { - *poutbuf = pc->packet_buf; - pc->packet_start = *poutbuf_size; - } - - if (s->last_pts == AV_NOPTS_VALUE) - s->last_pts = s->pts; - - return buf_size; -} - -static void dvbsub_parse_close(AVCodecParserContext *s) -{ - DVBSubParseContext *pc = s->priv_data; - av_freep(&pc->packet_buf); -} - -AVCodecParser dvbsub_parser = { - { CODEC_ID_DVB_SUBTITLE }, - sizeof(DVBSubParseContext), - dvbsub_parse_init, - dvbsub_parse, - dvbsub_parse_close, -}; diff --git a/contrib/ffmpeg/libavcodec/dvdata.h b/contrib/ffmpeg/libavcodec/dvdata.h index e688ffbb0..50ea537ef 100644 --- a/contrib/ffmpeg/libavcodec/dvdata.h +++ b/contrib/ffmpeg/libavcodec/dvdata.h @@ -24,6 +24,12 @@ * Constants for DV codec. */ +#ifndef FFMPEG_DVDATA_H +#define FFMPEG_DVDATA_H + +#include "avcodec.h" +#include "rational.h" + /* * DVprofile is used to express the differences between various * DV flavors. For now it's primarily used for differentiating @@ -329,7 +335,7 @@ static const uint8_t dv_quant_shifts[22][4] = { static const uint8_t dv_quant_offset[4] = { 6, 3, 0, 1 }; -/* NOTE: I prefer hardcoding the positionning of dv blocks, it is +/* NOTE: I prefer hardcoding the positioning of dv blocks, it is simpler :-) */ static const uint16_t dv_place_420[1620] = { @@ -2534,7 +2540,7 @@ static const uint8_t dv_audio_shuffle625[12][9] = { { 31, 67, 103, 21, 57, 93, 11, 47, 83}, }; -static const __attribute__((unused)) int dv_audio_frequency[3] = { +static const av_unused int dv_audio_frequency[3] = { 48000, 44100, 32000, }; @@ -2655,18 +2661,18 @@ enum dv_pack_type { /* largest possible DV frame, in bytes (PAL 50Mbps) */ #define DV_MAX_FRAME_SIZE 288000 -static inline const DVprofile* dv_frame_profile(uint8_t* frame) +static inline const DVprofile* dv_frame_profile(const uint8_t* frame) { if ((frame[3] & 0x80) == 0) { /* DSF flag */ /* it's an NTSC format */ - if ((frame[80*5 + 48 + 3] & 0x4)) { /* 4:2:2 sampling */ + if ((frame[80*5 + 48 + 3] & 0x4) && (frame[80*5 + 48] == dv_video_source)) { /* 4:2:2 sampling */ return &dv_profiles[3]; /* NTSC 50Mbps */ } else { /* 4:1:1 sampling */ return &dv_profiles[0]; /* NTSC 25Mbps */ } } else { /* it's a PAL format */ - if ((frame[80*5 + 48 + 3] & 0x4)) { /* 4:2:2 sampling */ + if ((frame[80*5 + 48 + 3] & 0x4) && (frame[80*5 + 48] == dv_video_source)) { /* 4:2:2 sampling */ return &dv_profiles[4]; /* PAL 50Mbps */ } else if ((frame[5] & 0x07) == 0) { /* APT flag */ return &dv_profiles[1]; /* PAL 25Mbps 4:2:0 */ @@ -2722,3 +2728,5 @@ static inline int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t* buf) buf[2] = 0xff; /* reserved -- always 1 */ return 3; } + +#endif /* FFMPEG_DVDATA_H */ diff --git a/contrib/ffmpeg/libavcodec/dvdsub_parser.c b/contrib/ffmpeg/libavcodec/dvdsub_parser.c new file mode 100644 index 000000000..0893daca6 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/dvdsub_parser.c @@ -0,0 +1,83 @@ +/* + * DVD subtitle decoding for ffmpeg + * Copyright (c) 2005 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avcodec.h" + +/* parser definition */ +typedef struct DVDSubParseContext { + uint8_t *packet; + int packet_len; + int packet_index; +} DVDSubParseContext; + +static int dvdsub_parse_init(AVCodecParserContext *s) +{ + return 0; +} + +static int dvdsub_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + DVDSubParseContext *pc = s->priv_data; + + if (pc->packet_index == 0) { + if (buf_size < 2) + return 0; + pc->packet_len = AV_RB16(buf); + if (pc->packet_len == 0) /* HD-DVD subpicture packet */ + pc->packet_len = AV_RB32(buf+2); + av_freep(&pc->packet); + pc->packet = av_malloc(pc->packet_len); + } + if (pc->packet) { + if (pc->packet_index + buf_size <= pc->packet_len) { + memcpy(pc->packet + pc->packet_index, buf, buf_size); + pc->packet_index += buf_size; + if (pc->packet_index >= pc->packet_len) { + *poutbuf = pc->packet; + *poutbuf_size = pc->packet_len; + pc->packet_index = 0; + return buf_size; + } + } else { + /* erroneous size */ + pc->packet_index = 0; + } + } + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; +} + +static void dvdsub_parse_close(AVCodecParserContext *s) +{ + DVDSubParseContext *pc = s->priv_data; + av_freep(&pc->packet); +} + +AVCodecParser dvdsub_parser = { + { CODEC_ID_DVD_SUBTITLE }, + sizeof(DVDSubParseContext), + dvdsub_parse_init, + dvdsub_parse, + dvdsub_parse_close, +}; diff --git a/contrib/ffmpeg/libavcodec/dvdsubdec.c b/contrib/ffmpeg/libavcodec/dvdsubdec.c index 3a93a6076..0927b7a17 100644 --- a/contrib/ffmpeg/libavcodec/dvdsubdec.c +++ b/contrib/ffmpeg/libavcodec/dvdsubdec.c @@ -19,50 +19,87 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avcodec.h" +#include "bitstream.h" +#include "colorspace.h" +#include "dsputil.h" //#define DEBUG -static int dvdsub_init_decoder(AVCodecContext *avctx) +static void yuv_a_to_rgba(const uint8_t *ycbcr, const uint8_t *alpha, uint32_t *rgba, int num_values) { - return 0; + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + uint8_t r, g, b; + int i, y, cb, cr; + int r_add, g_add, b_add; + + for (i = num_values; i > 0; i--) { + y = *ycbcr++; + cb = *ycbcr++; + cr = *ycbcr++; + YUV_TO_RGB1_CCIR(cb, cr); + YUV_TO_RGB2_CCIR(r, g, b, y); + *rgba++ = (*alpha++ << 24) | (r << 16) | (g << 8) | b; + } +} + +static int decode_run_2bit(GetBitContext *gb, int *color) +{ + unsigned int v, t; + + v = 0; + for (t = 1; v < t && t <= 0x40; t <<= 2) + v = (v << 4) | get_bits(gb, 4); + *color = v & 3; + if (v < 4) { /* Code for fill rest of line */ + return INT_MAX; + } + return v >> 2; } -static int get_nibble(const uint8_t *buf, int nibble_offset) +static int decode_run_8bit(GetBitContext *gb, int *color) { - return (buf[nibble_offset >> 1] >> ((1 - (nibble_offset & 1)) << 2)) & 0xf; + int len; + int has_run = get_bits1(gb); + if (get_bits1(gb)) + *color = get_bits(gb, 8); + else + *color = get_bits(gb, 2); + if (has_run) { + if (get_bits1(gb)) { + len = get_bits(gb, 7); + if (len == 0) + len = INT_MAX; + else + len += 9; + } else + len = get_bits(gb, 3) + 2; + } else + len = 1; + return len; } static int decode_rle(uint8_t *bitmap, int linesize, int w, int h, - const uint8_t *buf, int nibble_offset, int buf_size) + const uint8_t *buf, int start, int buf_size, int is_8bit) { - unsigned int v; - int x, y, len, color, nibble_end; + GetBitContext gb; + int bit_len; + int x, y, len, color; uint8_t *d; - nibble_end = buf_size * 2; + bit_len = (buf_size - start) * 8; + init_get_bits(&gb, buf + start, bit_len); + x = 0; y = 0; d = bitmap; for(;;) { - if (nibble_offset >= nibble_end) + if (get_bits_count(&gb) > bit_len) return -1; - v = get_nibble(buf, nibble_offset++); - if (v < 0x4) { - v = (v << 4) | get_nibble(buf, nibble_offset++); - if (v < 0x10) { - v = (v << 4) | get_nibble(buf, nibble_offset++); - if (v < 0x040) { - v = (v << 4) | get_nibble(buf, nibble_offset++); - if (v < 4) { - v |= (w - x) << 2; - } - } - } - } - len = v >> 2; - if (len > (w - x)) - len = (w - x); - color = v & 0x03; + if (is_8bit) + len = decode_run_8bit(&gb, &color); + else + len = decode_run_2bit(&gb, &color); + len = FFMIN(len, w - x); memset(d + x, color, len); x += len; if (x >= w) { @@ -72,14 +109,14 @@ static int decode_rle(uint8_t *bitmap, int linesize, int w, int h, d += linesize; x = 0; /* byte align */ - nibble_offset += (nibble_offset & 1); + align_get_bits(&gb); } } return 0; } static void guess_palette(uint32_t *rgba_palette, - uint8_t *palette, + uint8_t *colormap, uint8_t *alpha, uint32_t subtitle_color) { @@ -92,8 +129,8 @@ static void guess_palette(uint32_t *rgba_palette, memset(color_used, 0, 16); nb_opaque_colors = 0; for(i = 0; i < 4; i++) { - if (alpha[i] != 0 && !color_used[palette[i]]) { - color_used[palette[i]] = 1; + if (alpha[i] != 0 && !color_used[colormap[i]]) { + color_used[colormap[i]] = 1; nb_opaque_colors++; } } @@ -105,47 +142,62 @@ static void guess_palette(uint32_t *rgba_palette, memset(color_used, 0, 16); for(i = 0; i < 4; i++) { if (alpha[i] != 0) { - if (!color_used[palette[i]]) { + if (!color_used[colormap[i]]) { level = (0xff * j) / nb_opaque_colors; r = (((subtitle_color >> 16) & 0xff) * level) >> 8; g = (((subtitle_color >> 8) & 0xff) * level) >> 8; b = (((subtitle_color >> 0) & 0xff) * level) >> 8; rgba_palette[i] = b | (g << 8) | (r << 16) | ((alpha[i] * 17) << 24); - color_used[palette[i]] = (i + 1); + color_used[colormap[i]] = (i + 1); j--; } else { - rgba_palette[i] = (rgba_palette[color_used[palette[i]] - 1] & 0x00ffffff) | + rgba_palette[i] = (rgba_palette[color_used[colormap[i]] - 1] & 0x00ffffff) | ((alpha[i] * 17) << 24); } } } } +#define READ_OFFSET(a) (big_offsets ? AV_RB32(a) : AV_RB16(a)) + static int decode_dvd_subtitles(AVSubtitle *sub_header, const uint8_t *buf, int buf_size) { int cmd_pos, pos, cmd, x1, y1, x2, y2, offset1, offset2, next_cmd_pos; - uint8_t palette[4], alpha[4]; + int big_offsets, offset_size, is_8bit = 0; + const uint8_t *yuv_palette = 0; + uint8_t colormap[4], alpha[256]; int date; int i; int is_menu = 0; - if (buf_size < 4) + if (buf_size < 10) return -1; sub_header->rects = NULL; sub_header->num_rects = 0; sub_header->start_display_time = 0; sub_header->end_display_time = 0; - cmd_pos = AV_RB16(buf + 2); - while ((cmd_pos + 4) < buf_size) { + if (AV_RB16(buf) == 0) { /* HD subpicture with 4-byte offsets */ + big_offsets = 1; + offset_size = 4; + cmd_pos = 6; + } else { + big_offsets = 0; + offset_size = 2; + cmd_pos = 2; + } + + cmd_pos = READ_OFFSET(buf + cmd_pos); + + while ((cmd_pos + 2 + offset_size) < buf_size) { date = AV_RB16(buf + cmd_pos); - next_cmd_pos = AV_RB16(buf + cmd_pos + 2); + next_cmd_pos = READ_OFFSET(buf + cmd_pos + 2); #ifdef DEBUG av_log(NULL, AV_LOG_INFO, "cmd_pos=0x%04x next=0x%04x date=%d\n", cmd_pos, next_cmd_pos, date); #endif - pos = cmd_pos + 4; + pos = cmd_pos + 2 + offset_size; offset1 = -1; offset2 = -1; x1 = y1 = x2 = y2 = 0; @@ -168,13 +220,13 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header, sub_header->end_display_time = (date << 10) / 90; break; case 0x03: - /* set palette */ + /* set colormap */ if ((buf_size - pos) < 2) goto fail; - palette[3] = buf[pos] >> 4; - palette[2] = buf[pos] & 0x0f; - palette[1] = buf[pos + 1] >> 4; - palette[0] = buf[pos + 1] & 0x0f; + colormap[3] = buf[pos] >> 4; + colormap[2] = buf[pos] & 0x0f; + colormap[1] = buf[pos + 1] >> 4; + colormap[0] = buf[pos + 1] & 0x0f; pos += 2; break; case 0x04: @@ -191,12 +243,15 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header, #endif break; case 0x05: + case 0x85: if ((buf_size - pos) < 6) goto fail; x1 = (buf[pos] << 4) | (buf[pos + 1] >> 4); x2 = ((buf[pos + 1] & 0x0f) << 8) | buf[pos + 2]; y1 = (buf[pos + 3] << 4) | (buf[pos + 4] >> 4); y2 = ((buf[pos + 4] & 0x0f) << 8) | buf[pos + 5]; + if (cmd & 0x80) + is_8bit = 1; #ifdef DEBUG av_log(NULL, AV_LOG_INFO, "x1=%d x2=%d y1=%d y2=%d\n", x1, x2, y1, y2); @@ -213,8 +268,39 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header, #endif pos += 4; break; + case 0x86: + if ((buf_size - pos) < 8) + goto fail; + offset1 = AV_RB32(buf + pos); + offset2 = AV_RB32(buf + pos + 4); +#ifdef DEBUG + av_log(NULL, AV_LOG_INFO, "offset1=0x%04x offset2=0x%04x\n", offset1, offset2); +#endif + pos += 8; + break; + + case 0x83: + /* HD set palette */ + if ((buf_size - pos) < 768) + goto fail; + yuv_palette = buf + pos; + pos += 768; + break; + case 0x84: + /* HD set contrast (alpha) */ + if ((buf_size - pos) < 256) + goto fail; + for (i = 0; i < 256; i++) + alpha[i] = 0xFF - buf[pos+i]; + pos += 256; + break; + case 0xff: + goto the_end; default: +#ifdef DEBUG + av_log(NULL, AV_LOG_INFO, "unrecognised subpicture command 0x%x\n", cmd); +#endif goto the_end; } } @@ -243,20 +329,28 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header, bitmap = av_malloc(w * h); sub_header->rects = av_mallocz(sizeof(AVSubtitleRect)); sub_header->num_rects = 1; - sub_header->rects[0].rgba_palette = av_malloc(4 * 4); + sub_header->rects[0].bitmap = bitmap; decode_rle(bitmap, w * 2, w, (h + 1) / 2, - buf, offset1 * 2, buf_size); + buf, offset1, buf_size, is_8bit); decode_rle(bitmap + w, w * 2, w, h / 2, - buf, offset2 * 2, buf_size); - guess_palette(sub_header->rects[0].rgba_palette, - palette, alpha, 0xffff00); + buf, offset2, buf_size, is_8bit); + if (is_8bit) { + if (yuv_palette == 0) + goto fail; + sub_header->rects[0].rgba_palette = av_malloc(256 * 4); + sub_header->rects[0].nb_colors = 256; + yuv_a_to_rgba(yuv_palette, alpha, sub_header->rects[0].rgba_palette, 256); + } else { + sub_header->rects[0].rgba_palette = av_malloc(4 * 4); + sub_header->rects[0].nb_colors = 4; + guess_palette(sub_header->rects[0].rgba_palette, + colormap, alpha, 0xffff00); + } sub_header->rects[0].x = x1; sub_header->rects[0].y = y1; sub_header->rects[0].w = w; sub_header->rects[0].h = h; - sub_header->rects[0].nb_colors = 4; sub_header->rects[0].linesize = w; - sub_header->rects[0].bitmap = bitmap; } } if (next_cmd_pos == cmd_pos) @@ -266,6 +360,14 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header, if (sub_header->num_rects > 0) return is_menu; fail: + if (sub_header->rects != NULL) { + for (i = 0; i < sub_header->num_rects; i++) { + av_free(sub_header->rects[i].bitmap); + av_free(sub_header->rects[i].rgba_palette); + } + av_freep(&sub_header->rects); + sub_header->num_rects = 0; + } return -1; } @@ -336,11 +438,6 @@ static int find_smallest_bounding_rectangle(AVSubtitle *s) return 1; } -static int dvdsub_close_decoder(AVCodecContext *avctx) -{ - return 0; -} - #ifdef DEBUG #undef fprintf static void ppm_save(const char *filename, uint8_t *bitmap, int w, int h, @@ -372,7 +469,7 @@ static void ppm_save(const char *filename, uint8_t *bitmap, int w, int h, static int dvdsub_decode(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { AVSubtitle *sub = (void *)data; int is_menu; @@ -405,68 +502,8 @@ AVCodec dvdsub_decoder = { CODEC_TYPE_SUBTITLE, CODEC_ID_DVD_SUBTITLE, 0, - dvdsub_init_decoder, NULL, - dvdsub_close_decoder, + NULL, + NULL, dvdsub_decode, }; - -/* parser definition */ -typedef struct DVDSubParseContext { - uint8_t *packet; - int packet_len; - int packet_index; -} DVDSubParseContext; - -static int dvdsub_parse_init(AVCodecParserContext *s) -{ - return 0; -} - -static int dvdsub_parse(AVCodecParserContext *s, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - DVDSubParseContext *pc = s->priv_data; - - if (pc->packet_index == 0) { - if (buf_size < 2) - return 0; - pc->packet_len = AV_RB16(buf); - av_freep(&pc->packet); - pc->packet = av_malloc(pc->packet_len); - } - if (pc->packet) { - if (pc->packet_index + buf_size <= pc->packet_len) { - memcpy(pc->packet + pc->packet_index, buf, buf_size); - pc->packet_index += buf_size; - if (pc->packet_index >= pc->packet_len) { - *poutbuf = pc->packet; - *poutbuf_size = pc->packet_len; - pc->packet_index = 0; - return buf_size; - } - } else { - /* erroneous size */ - pc->packet_index = 0; - } - } - *poutbuf = NULL; - *poutbuf_size = 0; - return buf_size; -} - -static void dvdsub_parse_close(AVCodecParserContext *s) -{ - DVDSubParseContext *pc = s->priv_data; - av_freep(&pc->packet); -} - -AVCodecParser dvdsub_parser = { - { CODEC_ID_DVD_SUBTITLE }, - sizeof(DVDSubParseContext), - dvdsub_parse_init, - dvdsub_parse, - dvdsub_parse_close, -}; diff --git a/contrib/ffmpeg/libavcodec/dvdsubenc.c b/contrib/ffmpeg/libavcodec/dvdsubenc.c index fac29acc2..77ea88c96 100644 --- a/contrib/ffmpeg/libavcodec/dvdsubenc.c +++ b/contrib/ffmpeg/libavcodec/dvdsubenc.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avcodec.h" +#include "bytestream.h" #undef NDEBUG #include @@ -85,14 +86,6 @@ static void dvd_encode_rle(uint8_t **pq, *pq = q; } -static inline void putbe16(uint8_t **pq, uint16_t v) -{ - uint8_t *q = *pq; - *q++ = v >> 8; - *q++ = v; - *pq = q; -} - static int encode_dvd_subtitles(uint8_t *outbuf, int outbuf_size, const AVSubtitle *h) { @@ -163,11 +156,11 @@ static int encode_dvd_subtitles(uint8_t *outbuf, int outbuf_size, // set data packet size qq = outbuf + 2; - putbe16(&qq, q - outbuf); + bytestream_put_be16(&qq, q - outbuf); // send start display command - putbe16(&q, (h->start_display_time*90) >> 10); - putbe16(&q, (q - outbuf) /*- 2 */ + 8 + 12*rects + 2); + bytestream_put_be16(&q, (h->start_display_time*90) >> 10); + bytestream_put_be16(&q, (q - outbuf) /*- 2 */ + 8 + 12*rects + 2); *q++ = 0x03; // palette - 4 nibbles *q++ = 0x03; *q++ = 0x7f; *q++ = 0x04; // alpha - 4 nibbles @@ -192,35 +185,25 @@ static int encode_dvd_subtitles(uint8_t *outbuf, int outbuf_size, *q++ = 0x06; // offset1, offset2 - putbe16(&q, offset1[object_id]); - putbe16(&q, offset2[object_id]); + bytestream_put_be16(&q, offset1[object_id]); + bytestream_put_be16(&q, offset2[object_id]); } *q++ = 0x01; // start command *q++ = 0xff; // terminating command // send stop display command last - putbe16(&q, (h->end_display_time*90) >> 10); - putbe16(&q, (q - outbuf) - 2 /*+ 4*/); + bytestream_put_be16(&q, (h->end_display_time*90) >> 10); + bytestream_put_be16(&q, (q - outbuf) - 2 /*+ 4*/); *q++ = 0x02; // set end *q++ = 0xff; // terminating command qq = outbuf; - putbe16(&qq, q - outbuf); + bytestream_put_be16(&qq, q - outbuf); av_log(NULL, AV_LOG_DEBUG, "subtitle_packet size=%td\n", q - outbuf); return q - outbuf; } -static int dvdsub_init_encoder(AVCodecContext *avctx) -{ - return 0; -} - -static int dvdsub_close_encoder(AVCodecContext *avctx) -{ - return 0; -} - static int dvdsub_encode(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data) { @@ -237,11 +220,6 @@ AVCodec dvdsub_encoder = { CODEC_TYPE_SUBTITLE, CODEC_ID_DVD_SUBTITLE, 0, - dvdsub_init_encoder, + NULL, dvdsub_encode, - dvdsub_close_encoder, }; - -/* Local Variables: */ -/* c-basic-offset:4 */ -/* End: */ diff --git a/contrib/ffmpeg/libavcodec/dxa.c b/contrib/ffmpeg/libavcodec/dxa.c index fc201ccb4..46b01cd81 100644 --- a/contrib/ffmpeg/libavcodec/dxa.c +++ b/contrib/ffmpeg/libavcodec/dxa.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -28,7 +27,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include @@ -189,9 +187,9 @@ static int decode_13(AVCodecContext *avctx, DxaDecContext *c, uint8_t* dst, uint return 0; } -static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size) { - DxaDecContext * const c = (DxaDecContext *)avctx->priv_data; + DxaDecContext * const c = avctx->priv_data; uint8_t *outptr, *srcptr, *tmpptr; unsigned long dsize; int i, j, compr; @@ -289,7 +287,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 static int decode_init(AVCodecContext *avctx) { - DxaDecContext * const c = (DxaDecContext *)avctx->priv_data; + DxaDecContext * const c = avctx->priv_data; c->avctx = avctx; avctx->pix_fmt = PIX_FMT_PAL8; @@ -309,7 +307,7 @@ static int decode_init(AVCodecContext *avctx) static int decode_end(AVCodecContext *avctx) { - DxaDecContext * const c = (DxaDecContext *)avctx->priv_data; + DxaDecContext * const c = avctx->priv_data; av_freep(&c->decomp_buf); if(c->prev.data[0]) diff --git a/contrib/ffmpeg/libavcodec/elbg.c b/contrib/ffmpeg/libavcodec/elbg.c new file mode 100644 index 000000000..cd5b5ed4f --- /dev/null +++ b/contrib/ffmpeg/libavcodec/elbg.c @@ -0,0 +1,417 @@ +/* + * Copyright (C) 2007 Vitor Sessak + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file cbook_gen.c + * Codebook Generator using the ELBG algorithm + */ + +#include + +#include "elbg.h" +#include "avcodec.h" +#include "random.h" + +#define DELTA_ERR_MAX 0.1 ///< Precision of the ELBG algorithm (as percentual error) + +/** + * In the ELBG jargon, a cell is the set of points that are closest to a + * codebook entry. Not to be confused with a RoQ Video cell. */ +typedef struct cell_s { + int index; + struct cell_s *next; +} cell; + +/** + * ELBG internal data + */ +typedef struct{ + int error; + int dim; + int numCB; + int *codebook; + cell **cells; + int *utility; + int *utility_inc; + int *nearest_cb; + int *points; + AVRandomState *rand_state; +} elbg_data; + +static inline int distance_limited(int *a, int *b, int dim, int limit) +{ + int i, dist=0; + for (i=0; i limit) + return INT_MAX; + } + + return dist; +} + +static inline void vect_division(int *res, int *vect, int div, int dim) +{ + int i; + if (div > 1) + for (i=0; inext) + error += distance_limited(centroid, elbg->points + cells->index*elbg->dim, elbg->dim, INT_MAX); + + return error; +} + +static int get_closest_codebook(elbg_data *elbg, int index) +{ + int i, pick=0, diff, diff_min = INT_MAX; + for (i=0; inumCB; i++) + if (i != index) { + diff = distance_limited(elbg->codebook + i*elbg->dim, elbg->codebook + index*elbg->dim, elbg->dim, diff_min); + if (diff < diff_min) { + pick = i; + diff_min = diff; + } + } + return pick; +} + +static int get_high_utility_cell(elbg_data *elbg) +{ + int i=0; + /* Using linear search, do binary if it ever turns to be speed critical */ + int r = av_random(elbg->rand_state)%elbg->utility_inc[elbg->numCB-1]; + while (elbg->utility_inc[i] < r) + i++; + return i; +} + +/** + * Implementation of the simple LBG algorithm for just two codebooks + */ +static int simple_lbg(int dim, + int *centroid[3], + int newutility[3], + int *points, + cell *cells) +{ + int i, idx; + int numpoints[2] = {0,0}; + int newcentroid[2][dim]; + cell *tempcell; + + memset(newcentroid, 0, sizeof(newcentroid)); + + newutility[0] = + newutility[1] = 0; + + for (tempcell = cells; tempcell; tempcell=tempcell->next) { + idx = distance_limited(centroid[0], points + tempcell->index*dim, dim, INT_MAX)>= + distance_limited(centroid[1], points + tempcell->index*dim, dim, INT_MAX); + numpoints[idx]++; + for (i=0; iindex*dim + i]; + } + + vect_division(centroid[0], newcentroid[0], numpoints[0], dim); + vect_division(centroid[1], newcentroid[1], numpoints[1], dim); + + for (tempcell = cells; tempcell; tempcell=tempcell->next) { + int dist[2] = {distance_limited(centroid[0], points + tempcell->index*dim, dim, INT_MAX), + distance_limited(centroid[1], points + tempcell->index*dim, dim, INT_MAX)}; + int idx = dist[0] > dist[1]; + newutility[idx] += dist[idx]; + } + + return newutility[0] + newutility[1]; +} + +static void get_new_centroids(elbg_data *elbg, int huc, int *newcentroid_i, + int *newcentroid_p) +{ + cell *tempcell; + int min[elbg->dim]; + int max[elbg->dim]; + int i; + + for (i=0; i< elbg->dim; i++) { + min[i]=INT_MAX; + max[i]=0; + } + + for (tempcell = elbg->cells[huc]; tempcell; tempcell = tempcell->next) + for(i=0; idim; i++) { + min[i]=FFMIN(min[i], elbg->points[tempcell->index*elbg->dim + i]); + max[i]=FFMAX(max[i], elbg->points[tempcell->index*elbg->dim + i]); + } + + for (i=0; idim; i++) { + newcentroid_i[i] = min[i] + (max[i] - min[i])/3; + newcentroid_p[i] = min[i] + (2*(max[i] - min[i]))/3; + } +} + +/** + * Add the points in the low utility cell to its closest cell. Split the high + * utility cell, putting the separed points in the (now empty) low utility + * cell. + * + * @param elbg Internal elbg data + * @param indexes {luc, huc, cluc} + * @param newcentroid A vector with the position of the new centroids + */ +static void shift_codebook(elbg_data *elbg, int *indexes, + int *newcentroid[3]) +{ + cell *tempdata; + cell **pp = &elbg->cells[indexes[2]]; + + while(*pp) + pp= &(*pp)->next; + + *pp = elbg->cells[indexes[0]]; + + elbg->cells[indexes[0]] = NULL; + tempdata = elbg->cells[indexes[1]]; + elbg->cells[indexes[1]] = NULL; + + while(tempdata) { + cell *tempcell2 = tempdata->next; + int idx = distance_limited(elbg->points + tempdata->index*elbg->dim, + newcentroid[0], elbg->dim, INT_MAX) > + distance_limited(elbg->points + tempdata->index*elbg->dim, + newcentroid[1], elbg->dim, INT_MAX); + + tempdata->next = elbg->cells[indexes[idx]]; + elbg->cells[indexes[idx]] = tempdata; + tempdata = tempcell2; + } +} + +static void evaluate_utility_inc(elbg_data *elbg) +{ + int i, inc=0; + + for (i=0; i < elbg->numCB; i++) { + if (elbg->numCB*elbg->utility[i] > elbg->error) + inc += elbg->utility[i]; + elbg->utility_inc[i] = inc; + } +} + + +static void update_utility_and_n_cb(elbg_data *elbg, int idx, int newutility) +{ + cell *tempcell; + + elbg->utility[idx] = newutility; + for (tempcell=elbg->cells[idx]; tempcell; tempcell=tempcell->next) + elbg->nearest_cb[tempcell->index] = idx; +} + +/** + * Evaluate if a shift lower the error. If it does, call shift_codebooks + * and update elbg->error, elbg->utility and elbg->nearest_cb. + * + * @param elbg Internal elbg data + * @param indexes {luc (low utility cell, huc (high utility cell), cluc (closest cell to low utility cell)} + */ +static void try_shift_candidate(elbg_data *elbg, int idx[3]) +{ + int j, k, olderror=0, newerror, cont=0; + int newutility[3]; + int newcentroid[3][elbg->dim]; + int *newcentroid_ptrs[3] = { newcentroid[0], newcentroid[1], newcentroid[2] }; + cell *tempcell; + + for (j=0; j<3; j++) + olderror += elbg->utility[idx[j]]; + + memset(newcentroid[2], 0, elbg->dim*sizeof(int)); + + for (k=0; k<2; k++) + for (tempcell=elbg->cells[idx[2*k]]; tempcell; tempcell=tempcell->next) { + cont++; + for (j=0; jdim; j++) + newcentroid[2][j] += elbg->points[tempcell->index*elbg->dim + j]; + } + + vect_division(newcentroid[2], newcentroid[2], cont, elbg->dim); + + get_new_centroids(elbg, idx[1], newcentroid[0], newcentroid[1]); + + newutility[2] = eval_error_cell(elbg, newcentroid[2], elbg->cells[idx[0]]); + newutility[2] += eval_error_cell(elbg, newcentroid[2], elbg->cells[idx[2]]); + + newerror = newutility[2]; + + newerror += simple_lbg(elbg->dim, newcentroid_ptrs, newutility, elbg->points, + elbg->cells[idx[1]]); + + if (olderror > newerror) { + shift_codebook(elbg, idx, newcentroid_ptrs); + + elbg->error += newerror - olderror; + + for (j=0; j<3; j++) + update_utility_and_n_cb(elbg, idx[j], newutility[j]); + + evaluate_utility_inc(elbg); + } + } + +/** + * Implementation of the ELBG block + */ +static void do_shiftings(elbg_data *elbg) +{ + int idx[3]; + + evaluate_utility_inc(elbg); + + for (idx[0]=0; idx[0] < elbg->numCB; idx[0]++) + if (elbg->numCB*elbg->utility[idx[0]] < elbg->error) { + if (elbg->utility_inc[elbg->numCB-1] == 0) + return; + + idx[1] = get_high_utility_cell(elbg); + idx[2] = get_closest_codebook(elbg, idx[0]); + + try_shift_candidate(elbg, idx); + } +} + +#define BIG_PRIME 433494437LL + +void ff_init_elbg(int *points, int dim, int numpoints, int *codebook, + int numCB, int max_steps, int *closest_cb, + AVRandomState *rand_state) +{ + int i, k; + + if (numpoints > 24*numCB) { + /* ELBG is very costly for a big number of points. So if we have a lot + of them, get a good initial codebook to save on iterations */ + int *temp_points = av_malloc(dim*(numpoints/8)*sizeof(int)); + for (i=0; ierror = INT_MAX; + elbg->dim = dim; + elbg->numCB = numCB; + elbg->codebook = codebook; + elbg->cells = av_malloc(numCB*sizeof(cell *)); + elbg->utility = av_malloc(numCB*sizeof(int)); + elbg->nearest_cb = closest_cb; + elbg->points = points; + elbg->utility_inc = av_malloc(numCB*sizeof(int)); + + elbg->rand_state = rand_state; + + do { + free_cells = list_buffer; + last_error = elbg->error; + steps++; + memset(elbg->utility, 0, numCB*sizeof(int)); + memset(elbg->cells, 0, numCB*sizeof(cell *)); + + elbg->error = 0; + + /* This loop evaluate the actual Voronoi partition. It is the most + costly part of the algorithm. */ + for (i=0; i < numpoints; i++) { + dist_cb[i] = INT_MAX; + for (k=0; k < elbg->numCB; k++) { + dist = distance_limited(elbg->points + i*elbg->dim, elbg->codebook + k*elbg->dim, dim, dist_cb[i]); + if (dist < dist_cb[i]) { + dist_cb[i] = dist; + elbg->nearest_cb[i] = k; + } + } + elbg->error += dist_cb[i]; + elbg->utility[elbg->nearest_cb[i]] += dist_cb[i]; + free_cells->index = i; + free_cells->next = elbg->cells[elbg->nearest_cb[i]]; + elbg->cells[elbg->nearest_cb[i]] = free_cells; + free_cells++; + } + + do_shiftings(elbg); + + memset(size_part, 0, numCB*sizeof(int)); + + memset(elbg->codebook, 0, elbg->numCB*dim*sizeof(int)); + + for (i=0; i < numpoints; i++) { + size_part[elbg->nearest_cb[i]]++; + for (j=0; j < elbg->dim; j++) + elbg->codebook[elbg->nearest_cb[i]*elbg->dim + j] += + elbg->points[i*elbg->dim + j]; + } + + for (i=0; i < elbg->numCB; i++) + vect_division(elbg->codebook + i*elbg->dim, + elbg->codebook + i*elbg->dim, size_part[i], elbg->dim); + + } while(((last_error - elbg->error) > DELTA_ERR_MAX*elbg->error) && + (steps < max_steps)); + + av_free(dist_cb); + av_free(size_part); + av_free(elbg->utility); + av_free(list_buffer); + av_free(elbg->cells); + av_free(elbg->utility_inc); +} diff --git a/contrib/ffmpeg/libavcodec/elbg.h b/contrib/ffmpeg/libavcodec/elbg.h new file mode 100644 index 000000000..1b2e45c4e --- /dev/null +++ b/contrib/ffmpeg/libavcodec/elbg.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2007 Vitor Sessak + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_ELBG_H +#define FFMPEG_ELBG_H + +#include "random.h" + +/** + * Implementation of the Enhanced LBG Algorithm + * Based on the paper "Neural Networks 14:1219-1237" that can be found in + * http://citeseer.ist.psu.edu/patan01enhanced.html . + * + * @param points Input points. + * @param dim Dimension of the points. + * @param numpoints Num of points in **points. + * @param codebook Pointer to the output codebook. Must be allocated. + * @param numCB Number of points in the codebook. + * @param num_steps The maximum number of steps. One step is already a good compromise between time and quality. + * @param closest_cb Return the closest codebook to each point. Must be allocated. + * @param rand_state A random number generator state. Should be already initialised by av_init_random. + */ +void ff_do_elbg(int *points, int dim, int numpoints, int *codebook, + int numCB, int num_steps, int *closest_cb, + AVRandomState *rand_state); + +/** + * Initialize the **codebook vector for the elbg algorithm. If you have already + * a codebook and you want to refine it, you shouldn't call this function. + * If numpoints < 8*numCB this function fills **codebook with random numbers. + * If not, it calls ff_do_elbg for a (smaller) random sample of the points in + * **points. Get the same parameters as ff_do_elbg. + */ +void ff_init_elbg(int *points, int dim, int numpoints, int *codebook, + int numCB, int num_steps, int *closest_cb, + AVRandomState *rand_state); + +#endif /* FFMPEG_ELBG_H */ diff --git a/contrib/ffmpeg/libavcodec/error_resilience.c b/contrib/ffmpeg/libavcodec/error_resilience.c index 175ccf73a..17f04d5ab 100644 --- a/contrib/ffmpeg/libavcodec/error_resilience.c +++ b/contrib/ffmpeg/libavcodec/error_resilience.c @@ -30,7 +30,6 @@ #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" -#include "common.h" static void decode_mb(MpegEncContext *s){ s->dest[0] = s->current_picture.data[0] + (s->mb_y * 16* s->linesize ) + s->mb_x * 16; @@ -109,7 +108,7 @@ static void filter181(int16_t *data, int width, int height, int stride){ } /** - * guess the dc of blocks which dont have a undamaged dc + * guess the dc of blocks which do not have an undamaged dc * @param w width in 8 pixel blocks * @param h height in 8 pixel blocks */ @@ -564,6 +563,11 @@ static int is_intra_more_likely(MpegEncContext *s){ if(undamaged_count < 5) return 0; //allmost all MBs damaged -> use temporal prediction +#ifdef HAVE_XVMC + //prevent dsp.sad() check, that requires access to the image + if(s->avctx->xvmc_acceleration && s->pict_type==I_TYPE) return 1; +#endif + skip_amount= FFMAX(undamaged_count/50, 1); //check only upto 50 MBs is_intra_likely=0; @@ -765,7 +769,7 @@ void ff_er_frame_end(MpegEncContext *s){ if( error2==(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END) && error1!=(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END) - && ((error1&AC_END) || (error1&DC_END) || (error1&MV_END))){ //end & uninited + && ((error1&AC_END) || (error1&DC_END) || (error1&MV_END))){ //end & uninit end_ok=0; } diff --git a/contrib/ffmpeg/libavcodec/eval.c b/contrib/ffmpeg/libavcodec/eval.c index 877de3552..dc0012bf6 100644 --- a/contrib/ffmpeg/libavcodec/eval.c +++ b/contrib/ffmpeg/libavcodec/eval.c @@ -19,7 +19,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -56,7 +55,7 @@ typedef struct Parser{ double (**func2)(void *, double a, double b); // NULL terminated char **func2_name; // NULL terminated void *opaque; - char **error; + const char **error; #define VARS 10 double var[VARS]; } Parser; @@ -377,10 +376,10 @@ static int verify_expr(AVEvalExpr * e) { } } -AVEvalExpr * ff_parse(char *s, const char **const_name, +AVEvalExpr * ff_parse(const char *s, const char **const_name, double (**func1)(void *, double), const char **func1_name, double (**func2)(void *, double, double), char **func2_name, - char **error){ + const char **error){ Parser p; AVEvalExpr * e; char w[strlen(s) + 1], * wp = w; @@ -414,10 +413,10 @@ double ff_parse_eval(AVEvalExpr * e, double *const_value, void *opaque) { return eval_expr(&p, e); } -double ff_eval2(char *s, double *const_value, const char **const_name, +double ff_eval2(const char *s, double *const_value, const char **const_name, double (**func1)(void *, double), const char **func1_name, double (**func2)(void *, double, double), char **func2_name, - void *opaque, char **error){ + void *opaque, const char **error){ AVEvalExpr * e = ff_parse(s, const_name, func1, func1_name, func2, func2_name, error); double d; if (!e) return NAN; @@ -431,7 +430,7 @@ attribute_deprecated double ff_eval(char *s, double *const_value, const char **c double (**func1)(void *, double), const char **func1_name, double (**func2)(void *, double, double), char **func2_name, void *opaque){ - char *error=NULL; + const char *error=NULL; double ret; ret = ff_eval2(s, const_value, const_name, func1, func1_name, func2, func2_name, opaque, &error); if (error) @@ -452,7 +451,7 @@ static const char *const_names[]={ "E", 0 }; -main(){ +int main(void){ int i; printf("%f == 12.7\n", ff_eval("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL)); printf("%f == 0.931322575\n", ff_eval("80G/80Gi", const_values, const_names, NULL, NULL, NULL, NULL, NULL)); @@ -462,5 +461,6 @@ main(){ ff_eval("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL); STOP_TIMER("ff_eval") } + return 0; } #endif diff --git a/contrib/ffmpeg/libavcodec/eval.h b/contrib/ffmpeg/libavcodec/eval.h index b52199cf4..786e950c0 100644 --- a/contrib/ffmpeg/libavcodec/eval.h +++ b/contrib/ffmpeg/libavcodec/eval.h @@ -25,10 +25,13 @@ * eval header. */ -#ifndef AVCODEC_EVAL_H -#define AVCODEC_EVAL_H +#ifndef FFMPEG_EVAL_H +#define FFMPEG_EVAL_H #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) +/** + * @deprecated Use ff_eval2 instead + */ double ff_eval(char *s, double *const_value, const char **const_name, double (**func1)(void *, double), const char **func1_name, double (**func2)(void *, double, double), char **func2_name, @@ -49,10 +52,10 @@ double ff_eval(char *s, double *const_value, const char **const_name, * @param opaque a pointer which will be passed to all functions from func1 and func2 * @return the value of the expression */ -double ff_eval2(char *s, double *const_value, const char **const_name, +double ff_eval2(const char *s, double *const_value, const char **const_name, double (**func1)(void *, double), const char **func1_name, double (**func2)(void *, double, double), char **func2_name, - void *opaque, char **error); + void *opaque, const char **error); typedef struct ff_expr_s AVEvalExpr; @@ -65,13 +68,13 @@ typedef struct ff_expr_s AVEvalExpr; * @param func1_name NULL terminated array of zero terminated strings of func1 identifers * @param func2_name NULL terminated array of zero terminated strings of func2 identifers * @param error pointer to a char* which is set to an error message if something goes wrong - * @return AVEvalExpr which must be freed with ff_eval_free by the user when its not needed anymore + * @return AVEvalExpr which must be freed with ff_eval_free by the user when it is not needed anymore * NULL if anything went wrong */ -AVEvalExpr * ff_parse(char *s, const char **const_name, +AVEvalExpr * ff_parse(const char *s, const char **const_name, double (**func1)(void *, double), const char **func1_name, double (**func2)(void *, double, double), char **func2_name, - char **error); + const char **error); /** * Evaluates a previously parsed expression. * @param const_value a zero terminated array of values for the identifers from ff_parse const_name @@ -81,4 +84,4 @@ AVEvalExpr * ff_parse(char *s, const char **const_name, double ff_parse_eval(AVEvalExpr * e, double *const_value, void *opaque); void ff_eval_free(AVEvalExpr * e); -#endif /* AVCODEC_EVAL_H */ +#endif /* FFMPEG_EVAL_H */ diff --git a/contrib/ffmpeg/libavcodec/faac.c b/contrib/ffmpeg/libavcodec/faac.c deleted file mode 100644 index 9ff9f5ed0..000000000 --- a/contrib/ffmpeg/libavcodec/faac.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Interface to libfaac for aac encoding - * Copyright (c) 2002 Gildas Bazin - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file faacaudio.c - * Interface to libfaac for aac encoding. - */ - -#include "avcodec.h" -#include - -typedef struct FaacAudioContext { - faacEncHandle faac_handle; -} FaacAudioContext; - -static int Faac_encode_init(AVCodecContext *avctx) -{ - FaacAudioContext *s = avctx->priv_data; - faacEncConfigurationPtr faac_cfg; - unsigned long samples_input, max_bytes_output; - - /* number of channels */ - if (avctx->channels < 1 || avctx->channels > 6) - return -1; - - s->faac_handle = faacEncOpen(avctx->sample_rate, - avctx->channels, - &samples_input, &max_bytes_output); - - /* check faac version */ - faac_cfg = faacEncGetCurrentConfiguration(s->faac_handle); - if (faac_cfg->version != FAAC_CFG_VERSION) { - av_log(avctx, AV_LOG_ERROR, "wrong libfaac version (compiled for: %d, using %d)\n", FAAC_CFG_VERSION, faac_cfg->version); - faacEncClose(s->faac_handle); - return -1; - } - - /* put the options in the configuration struct */ - faac_cfg->aacObjectType = LOW; - faac_cfg->mpegVersion = MPEG4; - faac_cfg->useTns = 0; - faac_cfg->allowMidside = 1; - faac_cfg->bitRate = avctx->bit_rate / avctx->channels; - faac_cfg->bandWidth = avctx->cutoff; - if(avctx->flags & CODEC_FLAG_QSCALE) { - faac_cfg->bitRate = 0; - faac_cfg->quantqual = avctx->global_quality / FF_QP2LAMBDA; - } - faac_cfg->outputFormat = 1; - faac_cfg->inputFormat = FAAC_INPUT_16BIT; - - avctx->frame_size = samples_input / avctx->channels; - - avctx->coded_frame= avcodec_alloc_frame(); - avctx->coded_frame->key_frame= 1; - - /* Set decoder specific info */ - avctx->extradata_size = 0; - if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) { - - unsigned char *buffer = NULL; - unsigned long decoder_specific_info_size; - - if (!faacEncGetDecoderSpecificInfo(s->faac_handle, &buffer, - &decoder_specific_info_size)) { - avctx->extradata = av_malloc(decoder_specific_info_size + FF_INPUT_BUFFER_PADDING_SIZE); - avctx->extradata_size = decoder_specific_info_size; - memcpy(avctx->extradata, buffer, avctx->extradata_size); - faac_cfg->outputFormat = 0; - } -#undef free - free(buffer); -#define free please_use_av_free - } - - if (!faacEncSetConfiguration(s->faac_handle, faac_cfg)) { - av_log(avctx, AV_LOG_ERROR, "libfaac doesn't support this output format!\n"); - return -1; - } - - return 0; -} - -static int Faac_encode_frame(AVCodecContext *avctx, - unsigned char *frame, int buf_size, void *data) -{ - FaacAudioContext *s = avctx->priv_data; - int bytes_written; - - bytes_written = faacEncEncode(s->faac_handle, - data, - avctx->frame_size * avctx->channels, - frame, - buf_size); - - return bytes_written; -} - -static int Faac_encode_close(AVCodecContext *avctx) -{ - FaacAudioContext *s = avctx->priv_data; - - av_freep(&avctx->coded_frame); - av_freep(&avctx->extradata); - - faacEncClose(s->faac_handle); - return 0; -} - -AVCodec faac_encoder = { - "aac", - CODEC_TYPE_AUDIO, - CODEC_ID_AAC, - sizeof(FaacAudioContext), - Faac_encode_init, - Faac_encode_frame, - Faac_encode_close -}; diff --git a/contrib/ffmpeg/libavcodec/faad.c b/contrib/ffmpeg/libavcodec/faad.c deleted file mode 100644 index 01cbd40e7..000000000 --- a/contrib/ffmpeg/libavcodec/faad.c +++ /dev/null @@ -1,333 +0,0 @@ -/* - * Faad decoder - * Copyright (c) 2003 Zdenek Kabelac. - * Copyright (c) 2004 Thomas Raivio. - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file faad.c - * AAC decoder. - * - * still a bit unfinished - but it plays something - */ - -#include "avcodec.h" -#include "faad.h" - -#ifndef FAADAPI -#define FAADAPI -#endif - -/* - * when CONFIG_LIBFAADBIN is defined the libfaad will be opened at runtime - */ -//#undef CONFIG_LIBFAADBIN -//#define CONFIG_LIBFAADBIN - -#ifdef CONFIG_LIBFAADBIN -#include -static const char* libfaadname = "libfaad.so.0"; -#else -#define dlopen(a) -#define dlclose(a) -#endif - -typedef struct { - void* handle; /* dlopen handle */ - void* faac_handle; /* FAAD library handle */ - int sample_size; - int init; - - /* faad calls */ - faacDecHandle FAADAPI (*faacDecOpen)(void); - faacDecConfigurationPtr FAADAPI (*faacDecGetCurrentConfiguration)(faacDecHandle hDecoder); -#ifndef FAAD2_VERSION - int FAADAPI (*faacDecSetConfiguration)(faacDecHandle hDecoder, - faacDecConfigurationPtr config); - int FAADAPI (*faacDecInit)(faacDecHandle hDecoder, - unsigned char *buffer, - unsigned long *samplerate, - unsigned long *channels); - int FAADAPI (*faacDecInit2)(faacDecHandle hDecoder, unsigned char *pBuffer, - unsigned long SizeOfDecoderSpecificInfo, - unsigned long *samplerate, unsigned long *channels); - int FAADAPI (*faacDecDecode)(faacDecHandle hDecoder, - unsigned char *buffer, - unsigned long *bytesconsumed, - short *sample_buffer, - unsigned long *samples); -#else - unsigned char FAADAPI (*faacDecSetConfiguration)(faacDecHandle hDecoder, - faacDecConfigurationPtr config); - long FAADAPI (*faacDecInit)(faacDecHandle hDecoder, - unsigned char *buffer, - unsigned long buffer_size, - unsigned long *samplerate, - unsigned char *channels); - char FAADAPI (*faacDecInit2)(faacDecHandle hDecoder, unsigned char *pBuffer, - unsigned long SizeOfDecoderSpecificInfo, - unsigned long *samplerate, unsigned char *channels); - void *FAADAPI (*faacDecDecode)(faacDecHandle hDecoder, - faacDecFrameInfo *hInfo, - unsigned char *buffer, - unsigned long buffer_size); - char* FAADAPI (*faacDecGetErrorMessage)(unsigned char errcode); -#endif - - void FAADAPI (*faacDecClose)(faacDecHandle hDecoder); - - -} FAACContext; - -static const unsigned long faac_srates[] = -{ - 96000, 88200, 64000, 48000, 44100, 32000, - 24000, 22050, 16000, 12000, 11025, 8000 -}; - -static int faac_init_mp4(AVCodecContext *avctx) -{ - FAACContext *s = (FAACContext *) avctx->priv_data; - unsigned long samplerate; -#ifndef FAAD2_VERSION - unsigned long channels; -#else - unsigned char channels; -#endif - int r = 0; - - if (avctx->extradata){ - r = s->faacDecInit2(s->faac_handle, (uint8_t*) avctx->extradata, - avctx->extradata_size, - &samplerate, &channels); - if (r < 0){ - av_log(avctx, AV_LOG_ERROR, - "faacDecInit2 failed r:%d sr:%ld ch:%ld s:%d\n", - r, samplerate, (long)channels, avctx->extradata_size); - } else { - avctx->sample_rate = samplerate; - avctx->channels = channels; - s->init = 1; - } - } - - return r; -} - -static int faac_decode_frame(AVCodecContext *avctx, - void *data, int *data_size, - uint8_t *buf, int buf_size) -{ - FAACContext *s = (FAACContext *) avctx->priv_data; -#ifndef FAAD2_VERSION - unsigned long bytesconsumed; - short *sample_buffer = NULL; - unsigned long samples; - int out; -#else - faacDecFrameInfo frame_info; - void *out; -#endif - if(buf_size == 0) - return 0; -#ifndef FAAD2_VERSION - out = s->faacDecDecode(s->faac_handle, - (unsigned char*)buf, - &bytesconsumed, - data, - &samples); - samples *= s->sample_size; - if (data_size) - *data_size = samples; - return (buf_size < (int)bytesconsumed) - ? buf_size : (int)bytesconsumed; -#else - - if(!s->init){ - unsigned long srate; - unsigned char channels; - int r = s->faacDecInit(s->faac_handle, buf, buf_size, &srate, &channels); - if(r < 0){ - av_log(avctx, AV_LOG_ERROR, "faac: codec init failed: %s\n", - s->faacDecGetErrorMessage(frame_info.error)); - return -1; - } - avctx->sample_rate = srate; - avctx->channels = channels; - s->init = 1; - } - - out = s->faacDecDecode(s->faac_handle, &frame_info, (unsigned char*)buf, (unsigned long)buf_size); - - if (frame_info.error > 0) { - av_log(avctx, AV_LOG_ERROR, "faac: frame decoding failed: %s\n", - s->faacDecGetErrorMessage(frame_info.error)); - return -1; - } - - frame_info.samples *= s->sample_size; - memcpy(data, out, frame_info.samples); // CHECKME - can we cheat this one - - if (data_size) - *data_size = frame_info.samples; - - return (buf_size < (int)frame_info.bytesconsumed) - ? buf_size : (int)frame_info.bytesconsumed; -#endif -} - -static int faac_decode_end(AVCodecContext *avctx) -{ - FAACContext *s = (FAACContext *) avctx->priv_data; - - s->faacDecClose(s->faac_handle); - - dlclose(s->handle); - return 0; -} - -static int faac_decode_init(AVCodecContext *avctx) -{ - FAACContext *s = (FAACContext *) avctx->priv_data; - faacDecConfigurationPtr faac_cfg; - -#ifdef CONFIG_LIBFAADBIN - const char* err = 0; - - s->handle = dlopen(libfaadname, RTLD_LAZY); - if (!s->handle) - { - av_log(avctx, AV_LOG_ERROR, "FAAD library: %s could not be opened! \n%s\n", - libfaadname, dlerror()); - return -1; - } -#define dfaac(a, b) \ - do { static const char* n = "faacDec" #a; \ - if ((s->faacDec ## a = b dlsym( s->handle, n )) == NULL) { err = n; break; } } while(0) - for(;;) { -#else /* !CONFIG_LIBFAADBIN */ -#define dfaac(a, b) s->faacDec ## a = faacDec ## a -#endif /* CONFIG_LIBFAADBIN */ - - // resolve all needed function calls - dfaac(Open, (faacDecHandle FAADAPI (*)(void))); - dfaac(Close, (void FAADAPI (*)(faacDecHandle hDecoder))); - dfaac(GetCurrentConfiguration, (faacDecConfigurationPtr - FAADAPI (*)(faacDecHandle))); -#ifndef FAAD2_VERSION - dfaac(SetConfiguration, (int FAADAPI (*)(faacDecHandle, - faacDecConfigurationPtr))); - - dfaac(Init, (int FAADAPI (*)(faacDecHandle, unsigned char*, - unsigned long*, unsigned long*))); - dfaac(Init2, (int FAADAPI (*)(faacDecHandle, unsigned char*, - unsigned long, unsigned long*, - unsigned long*))); - dfaac(Decode, (int FAADAPI (*)(faacDecHandle, unsigned char*, - unsigned long*, short*, unsigned long*))); -#else - dfaac(SetConfiguration, (unsigned char FAADAPI (*)(faacDecHandle, - faacDecConfigurationPtr))); - dfaac(Init, (long FAADAPI (*)(faacDecHandle, unsigned char*, - unsigned long, unsigned long*, unsigned char*))); - dfaac(Init2, (char FAADAPI (*)(faacDecHandle, unsigned char*, - unsigned long, unsigned long*, - unsigned char*))); - dfaac(Decode, (void *FAADAPI (*)(faacDecHandle, faacDecFrameInfo*, - unsigned char*, unsigned long))); - dfaac(GetErrorMessage, (char* FAADAPI (*)(unsigned char))); -#endif -#undef dfacc - -#ifdef CONFIG_LIBFAADBIN - break; - } - if (err) { - dlclose(s->handle); - av_log(avctx, AV_LOG_ERROR, "FAAD library: cannot resolve %s in %s!\n", - err, libfaadname); - return -1; - } -#endif - - s->faac_handle = s->faacDecOpen(); - if (!s->faac_handle) { - av_log(avctx, AV_LOG_ERROR, "FAAD library: cannot create handler!\n"); - faac_decode_end(avctx); - return -1; - } - - - faac_cfg = s->faacDecGetCurrentConfiguration(s->faac_handle); - - if (faac_cfg) { - switch (avctx->bits_per_sample) { - case 8: av_log(avctx, AV_LOG_ERROR, "FAADlib unsupported bps %d\n", avctx->bits_per_sample); break; - default: - case 16: -#ifdef FAAD2_VERSION - faac_cfg->outputFormat = FAAD_FMT_16BIT; -#endif - s->sample_size = 2; - break; - case 24: -#ifdef FAAD2_VERSION - faac_cfg->outputFormat = FAAD_FMT_24BIT; -#endif - s->sample_size = 3; - break; - case 32: -#ifdef FAAD2_VERSION - faac_cfg->outputFormat = FAAD_FMT_32BIT; -#endif - s->sample_size = 4; - break; - } - - faac_cfg->defSampleRate = (!avctx->sample_rate) ? 44100 : avctx->sample_rate; - faac_cfg->defObjectType = LC; - } - - s->faacDecSetConfiguration(s->faac_handle, faac_cfg); - - faac_init_mp4(avctx); - - return 0; -} - -#define AAC_CODEC(id, name) \ -AVCodec name ## _decoder = { \ - #name, \ - CODEC_TYPE_AUDIO, \ - id, \ - sizeof(FAACContext), \ - faac_decode_init, \ - NULL, \ - faac_decode_end, \ - faac_decode_frame, \ -} - -// FIXME - raw AAC files - maybe just one entry will be enough -AAC_CODEC(CODEC_ID_AAC, aac); -#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) -// If it's mp4 file - usually embeded into Qt Mov -AAC_CODEC(CODEC_ID_MPEG4AAC, mpeg4aac); -#endif - -#undef AAC_CODEC diff --git a/contrib/ffmpeg/libavcodec/faandct.c b/contrib/ffmpeg/libavcodec/faandct.c index 6f73ee5e9..014c2d751 100644 --- a/contrib/ffmpeg/libavcodec/faandct.c +++ b/contrib/ffmpeg/libavcodec/faandct.c @@ -2,6 +2,8 @@ * Floating point AAN DCT * Copyright (c) 2003 Michael Niedermayer * + * this implementation is based upon the IJG integer AAN DCT (see jfdctfst.c) + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -18,7 +20,8 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * this implementation is based upon the IJG integer AAN DCT (see jfdctfst.c) + * The AAN DCT in this file except ff_faandct248() can also be used under the + * new (3 clause) BSD license. */ /** @@ -74,7 +77,7 @@ static av_always_inline void row_fdct(FLOAT temp[64], DCTELEM * data) { FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; FLOAT tmp10, tmp11, tmp12, tmp13; - FLOAT z1, z2, z3, z4, z5, z11, z13; + FLOAT z2, z4, z5, z11, z13; int i; for (i=0; i<8*8; i+=8) { @@ -95,21 +98,27 @@ static av_always_inline void row_fdct(FLOAT temp[64], DCTELEM * data) temp[0 + i]= tmp10 + tmp11; temp[4 + i]= tmp10 - tmp11; - z1= (tmp12 + tmp13)*A1; - temp[2 + i]= tmp13 + z1; - temp[6 + i]= tmp13 - z1; + tmp12 += tmp13; + tmp12 *= A1; + temp[2 + i]= tmp13 + tmp12; + temp[6 + i]= tmp13 - tmp12; - tmp10= tmp4 + tmp5; - tmp11= tmp5 + tmp6; - tmp12= tmp6 + tmp7; + tmp4 += tmp5; + tmp5 += tmp6; + tmp6 += tmp7; - z5= (tmp10 - tmp12) * A5; - z2= tmp10*A2 + z5; - z4= tmp12*A4 + z5; - z3= tmp11*A1; +#if 0 + z5= (tmp4 - tmp6) * A5; + z2= tmp4*A2 + z5; + z4= tmp6*A4 + z5; +#else + z2= tmp4*(A2+A5) - tmp6*A5; + z4= tmp6*(A4-A5) + tmp4*A5; +#endif + tmp5*=A1; - z11= tmp7 + z3; - z13= tmp7 - z3; + z11= tmp7 + tmp5; + z13= tmp7 - tmp5; temp[5 + i]= z13 + z2; temp[3 + i]= z13 - z2; @@ -122,7 +131,7 @@ void ff_faandct(DCTELEM * data) { FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; FLOAT tmp10, tmp11, tmp12, tmp13; - FLOAT z1, z2, z3, z4, z5, z11, z13; + FLOAT z2, z4, z5, z11, z13; FLOAT temp[64]; int i; @@ -148,21 +157,27 @@ void ff_faandct(DCTELEM * data) data[8*0 + i]= lrintf(SCALE(8*0 + i) * (tmp10 + tmp11)); data[8*4 + i]= lrintf(SCALE(8*4 + i) * (tmp10 - tmp11)); - z1= (tmp12 + tmp13)* A1; - data[8*2 + i]= lrintf(SCALE(8*2 + i) * (tmp13 + z1)); - data[8*6 + i]= lrintf(SCALE(8*6 + i) * (tmp13 - z1)); + tmp12 += tmp13; + tmp12 *= A1; + data[8*2 + i]= lrintf(SCALE(8*2 + i) * (tmp13 + tmp12)); + data[8*6 + i]= lrintf(SCALE(8*6 + i) * (tmp13 - tmp12)); - tmp10= tmp4 + tmp5; - tmp11= tmp5 + tmp6; - tmp12= tmp6 + tmp7; + tmp4 += tmp5; + tmp5 += tmp6; + tmp6 += tmp7; - z5= (tmp10 - tmp12) * A5; - z2= tmp10*A2 + z5; - z4= tmp12*A4 + z5; - z3= tmp11*A1; +#if 0 + z5= (tmp4 - tmp6) * A5; + z2= tmp4*A2 + z5; + z4= tmp6*A4 + z5; +#else + z2= tmp4*(A2+A5) - tmp6*A5; + z4= tmp6*(A4-A5) + tmp4*A5; +#endif + tmp5*=A1; - z11= tmp7 + z3; - z13= tmp7 - z3; + z11= tmp7 + tmp5; + z13= tmp7 - tmp5; data[8*5 + i]= lrintf(SCALE(8*5 + i) * (z13 + z2)); data[8*3 + i]= lrintf(SCALE(8*3 + i) * (z13 - z2)); @@ -175,7 +190,6 @@ void ff_faandct248(DCTELEM * data) { FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; FLOAT tmp10, tmp11, tmp12, tmp13; - FLOAT z1; FLOAT temp[64]; int i; @@ -201,9 +215,10 @@ void ff_faandct248(DCTELEM * data) data[8*0 + i] = lrintf(SCALE(8*0 + i) * (tmp10 + tmp11)); data[8*4 + i] = lrintf(SCALE(8*4 + i) * (tmp10 - tmp11)); - z1 = (tmp12 + tmp13)* A1; - data[8*2 + i] = lrintf(SCALE(8*2 + i) * (tmp13 + z1)); - data[8*6 + i] = lrintf(SCALE(8*6 + i) * (tmp13 - z1)); + tmp12 += tmp13; + tmp12 *= A1; + data[8*2 + i] = lrintf(SCALE(8*2 + i) * (tmp13 + tmp12)); + data[8*6 + i] = lrintf(SCALE(8*6 + i) * (tmp13 - tmp12)); tmp10 = tmp4 + tmp7; tmp11 = tmp5 + tmp6; @@ -213,8 +228,9 @@ void ff_faandct248(DCTELEM * data) data[8*1 + i] = lrintf(SCALE(8*0 + i) * (tmp10 + tmp11)); data[8*5 + i] = lrintf(SCALE(8*4 + i) * (tmp10 - tmp11)); - z1 = (tmp12 + tmp13)* A1; - data[8*3 + i] = lrintf(SCALE(8*2 + i) * (tmp13 + z1)); - data[8*7 + i] = lrintf(SCALE(8*6 + i) * (tmp13 - z1)); + tmp12 += tmp13; + tmp12 *= A1; + data[8*3 + i] = lrintf(SCALE(8*2 + i) * (tmp13 + tmp12)); + data[8*7 + i] = lrintf(SCALE(8*6 + i) * (tmp13 - tmp12)); } } diff --git a/contrib/ffmpeg/libavcodec/faandct.h b/contrib/ffmpeg/libavcodec/faandct.h index 77dd41dae..b9a4eeb3e 100644 --- a/contrib/ffmpeg/libavcodec/faandct.h +++ b/contrib/ffmpeg/libavcodec/faandct.h @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -27,7 +26,14 @@ * @author Michael Niedermayer */ +#ifndef FFMPEG_FAANDCT_H +#define FFMPEG_FAANDCT_H + +#include "dsputil.h" + #define FAAN_POSTSCALE void ff_faandct(DCTELEM * data); void ff_faandct248(DCTELEM * data); + +#endif /* FFMPEG_FAANDCT_H */ diff --git a/contrib/ffmpeg/libavcodec/faanidct.c b/contrib/ffmpeg/libavcodec/faanidct.c new file mode 100644 index 000000000..add40349a --- /dev/null +++ b/contrib/ffmpeg/libavcodec/faanidct.c @@ -0,0 +1,168 @@ +/* + * Floating point AAN IDCT + * Copyright (c) 2008 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "faanidct.h" + +/* To allow switching to double. */ +#define FLOAT float + +#define B0 1.0000000000000000000000 +#define B1 1.3870398453221474618216 // cos(pi*1/16)sqrt(2) +#define B2 1.3065629648763765278566 // cos(pi*2/16)sqrt(2) +#define B3 1.1758756024193587169745 // cos(pi*3/16)sqrt(2) +#define B4 1.0000000000000000000000 // cos(pi*4/16)sqrt(2) +#define B5 0.7856949583871021812779 // cos(pi*5/16)sqrt(2) +#define B6 0.5411961001461969843997 // cos(pi*6/16)sqrt(2) +#define B7 0.2758993792829430123360 // cos(pi*7/16)sqrt(2) + +#define A4 0.70710678118654752438 // cos(pi*4/16) +#define A2 0.92387953251128675613 // cos(pi*2/16) + +static const FLOAT prescale[64]={ +B0*B0/8, B0*B1/8, B0*B2/8, B0*B3/8, B0*B4/8, B0*B5/8, B0*B6/8, B0*B7/8, +B1*B0/8, B1*B1/8, B1*B2/8, B1*B3/8, B1*B4/8, B1*B5/8, B1*B6/8, B1*B7/8, +B2*B0/8, B2*B1/8, B2*B2/8, B2*B3/8, B2*B4/8, B2*B5/8, B2*B6/8, B2*B7/8, +B3*B0/8, B3*B1/8, B3*B2/8, B3*B3/8, B3*B4/8, B3*B5/8, B3*B6/8, B3*B7/8, +B4*B0/8, B4*B1/8, B4*B2/8, B4*B3/8, B4*B4/8, B4*B5/8, B4*B6/8, B4*B7/8, +B5*B0/8, B5*B1/8, B5*B2/8, B5*B3/8, B5*B4/8, B5*B5/8, B5*B6/8, B5*B7/8, +B6*B0/8, B6*B1/8, B6*B2/8, B6*B3/8, B6*B4/8, B6*B5/8, B6*B6/8, B6*B7/8, +B7*B0/8, B7*B1/8, B7*B2/8, B7*B3/8, B7*B4/8, B7*B5/8, B7*B6/8, B7*B7/8, +}; + +static inline void p8idct(DCTELEM data[64], FLOAT temp[64], uint8_t *dest, int stride, int x, int y, int type){ + int i; + FLOAT tmp0; + FLOAT s04, d04, s17, d17, s26, d26, s53, d53; + FLOAT os07, os16, os25, os34; + FLOAT od07, od16, od25, od34; + + for(i=0; i + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_FAANIDCT_H +#define FFMPEG_FAANIDCT_H + +#include +#include "dsputil.h" + +void ff_faanidct(DCTELEM block[64]); +void ff_faanidct_add(uint8_t *dest, int line_size, DCTELEM block[64]); +void ff_faanidct_put(uint8_t *dest, int line_size, DCTELEM block[64]); + +#endif /* FFMPEG_FAANIDCT_H */ diff --git a/contrib/ffmpeg/libavcodec/fdctref.c b/contrib/ffmpeg/libavcodec/fdctref.c index 5eff36849..c6a057b84 100644 --- a/contrib/ffmpeg/libavcodec/fdctref.c +++ b/contrib/ffmpeg/libavcodec/fdctref.c @@ -27,7 +27,6 @@ * are subject to royalty fees to patent holders. Many of these patents are * general enough such that they are unavoidable regardless of implementation * design. - * */ #include diff --git a/contrib/ffmpeg/libavcodec/fft-test.c b/contrib/ffmpeg/libavcodec/fft-test.c index d2497383d..8ac04611a 100644 --- a/contrib/ffmpeg/libavcodec/fft-test.c +++ b/contrib/ffmpeg/libavcodec/fft-test.c @@ -27,8 +27,11 @@ #include #include #include +#include +#include #undef exit +#undef random int mm_flags; @@ -47,7 +50,7 @@ FFTComplex *exptab; void fft_ref_init(int nbits, int inverse) { int n, i; - float c1, s1, alpha; + double c1, s1, alpha; n = 1 << nbits; exptab = av_malloc((n / 2) * sizeof(FFTComplex)); @@ -66,7 +69,7 @@ void fft_ref_init(int nbits, int inverse) void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits) { int n, i, j, k, n2; - float tmp_re, tmp_im, s, c; + double tmp_re, tmp_im, s, c; FFTComplex *q; n = 1 << nbits; @@ -92,10 +95,11 @@ void fft_ref(FFTComplex *tabr, FFTComplex *tab, int nbits) } } -void imdct_ref(float *out, float *in, int n) +void imdct_ref(float *out, float *in, int nbits) { + int n = 1<= 1e-3) { + double e= fabsf(tab1[i] - tab2[i]); + if (e >= 1e-3) { av_log(NULL, AV_LOG_ERROR, "ERROR %d: %f %f\n", i, tab1[i], tab2[i]); } + error+= e*e; + if(e>max) max= e; } + av_log(NULL, AV_LOG_INFO, "max:%f e:%g\n", max, sqrt(error)/n); } @@ -237,11 +248,11 @@ int main(int argc, char **argv) if (do_mdct) { if (do_inverse) { - imdct_ref((float *)tab_ref, (float *)tab1, fft_size); + imdct_ref((float *)tab_ref, (float *)tab1, fft_nbits); ff_imdct_calc(m, tab2, (float *)tab1, tabtmp); check_diff((float *)tab_ref, tab2, fft_size); } else { - mdct_ref((float *)tab_ref, (float *)tab1, fft_size); + mdct_ref((float *)tab_ref, (float *)tab1, fft_nbits); ff_mdct_calc(m, tab2, (float *)tab1, tabtmp); diff --git a/contrib/ffmpeg/libavcodec/ffv1.c b/contrib/ffmpeg/libavcodec/ffv1.c index 45f408c87..d0f2efbfe 100644 --- a/contrib/ffmpeg/libavcodec/ffv1.c +++ b/contrib/ffmpeg/libavcodec/ffv1.c @@ -18,7 +18,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -26,9 +25,8 @@ * FF Video Codec 1 (an experimental lossless codec) */ -#include "common.h" -#include "bitstream.h" #include "avcodec.h" +#include "bitstream.h" #include "dsputil.h" #include "rangecoder.h" #include "golomb.h" @@ -704,6 +702,7 @@ static int common_end(AVCodecContext *avctx){ PlaneContext *p= &s->plane[i]; av_freep(&p->state); + av_freep(&p->vlc_state); } return 0; @@ -937,7 +936,7 @@ static int decode_init(AVCodecContext *avctx) return 0; } -static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){ +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size){ FFV1Context *f = avctx->priv_data; RangeCoder * const c= &f->c; const int width= f->width; diff --git a/contrib/ffmpeg/libavcodec/flac.c b/contrib/ffmpeg/libavcodec/flac.c index 1016ed47f..81ed55e35 100644 --- a/contrib/ffmpeg/libavcodec/flac.c +++ b/contrib/ffmpeg/libavcodec/flac.c @@ -183,7 +183,7 @@ static int metadata_parse(FLACContext *s) av_log(s->avctx, AV_LOG_DEBUG, "STREAM HEADER\n"); do { - metadata_last = get_bits(&s->gb, 1); + metadata_last = get_bits1(&s->gb); metadata_type = get_bits(&s->gb, 7); metadata_size = get_bits_long(&s->gb, 24); @@ -217,7 +217,7 @@ static int decode_residuals(FLACContext *s, int channel, int pred_order) int sample = 0, samples; method_type = get_bits(&s->gb, 2); - if (method_type != 0){ + if (method_type > 1){ av_log(s->avctx, AV_LOG_DEBUG, "illegal residual coding method %d\n", method_type); return -1; } @@ -234,8 +234,8 @@ static int decode_residuals(FLACContext *s, int channel, int pred_order) i= pred_order; for (partition = 0; partition < (1 << rice_order); partition++) { - tmp = get_bits(&s->gb, 4); - if (tmp == 15) + tmp = get_bits(&s->gb, method_type == 0 ? 4 : 5); + if (tmp == (method_type == 0 ? 15 : 31)) { av_log(s->avctx, AV_LOG_DEBUG, "fixed len partition\n"); tmp = get_bits(&s->gb, 5); @@ -259,7 +259,9 @@ static int decode_residuals(FLACContext *s, int channel, int pred_order) static int decode_subframe_fixed(FLACContext *s, int channel, int pred_order) { - int i; + const int blocksize = s->blocksize; + int32_t *decoded = s->decoded[channel]; + int a, b, c, d, i; // av_log(s->avctx, AV_LOG_DEBUG, " SUBFRAME FIXED\n"); @@ -268,38 +270,37 @@ static int decode_subframe_fixed(FLACContext *s, int channel, int pred_order) for (i = 0; i < pred_order; i++) { - s->decoded[channel][i] = get_sbits(&s->gb, s->curr_bps); + decoded[i] = get_sbits(&s->gb, s->curr_bps); // av_log(s->avctx, AV_LOG_DEBUG, " %d: %d\n", i, s->decoded[channel][i]); } if (decode_residuals(s, channel, pred_order) < 0) return -1; + a = decoded[pred_order-1]; + b = a - decoded[pred_order-2]; + c = b - decoded[pred_order-2] + decoded[pred_order-3]; + d = c - decoded[pred_order-2] + 2*decoded[pred_order-3] - decoded[pred_order-4]; + switch(pred_order) { case 0: break; case 1: - for (i = pred_order; i < s->blocksize; i++) - s->decoded[channel][i] += s->decoded[channel][i-1]; + for (i = pred_order; i < blocksize; i++) + decoded[i] = a += decoded[i]; break; case 2: - for (i = pred_order; i < s->blocksize; i++) - s->decoded[channel][i] += 2*s->decoded[channel][i-1] - - s->decoded[channel][i-2]; + for (i = pred_order; i < blocksize; i++) + decoded[i] = a += b += decoded[i]; break; case 3: - for (i = pred_order; i < s->blocksize; i++) - s->decoded[channel][i] += 3*s->decoded[channel][i-1] - - 3*s->decoded[channel][i-2] - + s->decoded[channel][i-3]; + for (i = pred_order; i < blocksize; i++) + decoded[i] = a += b += c += decoded[i]; break; case 4: - for (i = pred_order; i < s->blocksize; i++) - s->decoded[channel][i] += 4*s->decoded[channel][i-1] - - 6*s->decoded[channel][i-2] - + 4*s->decoded[channel][i-3] - - s->decoded[channel][i-4]; + for (i = pred_order; i < blocksize; i++) + decoded[i] = a += b += c += d += decoded[i]; break; default: av_log(s->avctx, AV_LOG_ERROR, "illegal pred order %d\n", pred_order); @@ -314,6 +315,7 @@ static int decode_subframe_lpc(FLACContext *s, int channel, int pred_order) int i, j; int coeff_prec, qlevel; int coeffs[pred_order]; + int32_t *decoded = s->decoded[channel]; // av_log(s->avctx, AV_LOG_DEBUG, " SUBFRAME LPC\n"); @@ -322,8 +324,8 @@ static int decode_subframe_lpc(FLACContext *s, int channel, int pred_order) for (i = 0; i < pred_order; i++) { - s->decoded[channel][i] = get_sbits(&s->gb, s->curr_bps); -// av_log(s->avctx, AV_LOG_DEBUG, " %d: %d\n", i, s->decoded[channel][i]); + decoded[i] = get_sbits(&s->gb, s->curr_bps); +// av_log(s->avctx, AV_LOG_DEBUG, " %d: %d\n", i, decoded[i]); } coeff_prec = get_bits(&s->gb, 4) + 1; @@ -355,17 +357,34 @@ static int decode_subframe_lpc(FLACContext *s, int channel, int pred_order) { sum = 0; for (j = 0; j < pred_order; j++) - sum += (int64_t)coeffs[j] * s->decoded[channel][i-j-1]; - s->decoded[channel][i] += sum >> qlevel; + sum += (int64_t)coeffs[j] * decoded[i-j-1]; + decoded[i] += sum >> qlevel; } } else { - int sum; - for (i = pred_order; i < s->blocksize; i++) + for (i = pred_order; i < s->blocksize-1; i += 2) { - sum = 0; + int c; + int d = decoded[i-pred_order]; + int s0 = 0, s1 = 0; + for (j = pred_order-1; j > 0; j--) + { + c = coeffs[j]; + s0 += c*d; + d = decoded[i-j]; + s1 += c*d; + } + c = coeffs[0]; + s0 += c*d; + d = decoded[i] += s0 >> qlevel; + s1 += c*d; + decoded[i+1] += s1 >> qlevel; + } + if (i < s->blocksize) + { + int sum = 0; for (j = 0; j < pred_order; j++) - sum += coeffs[j] * s->decoded[channel][i-j-1]; - s->decoded[channel][i] += sum >> qlevel; + sum += coeffs[j] * decoded[i-j-1]; + decoded[i] += sum >> qlevel; } } @@ -539,7 +558,8 @@ static int decode_frame(FLACContext *s, int alloc_data_size) } skip_bits(&s->gb, 8); - crc8= av_crc(av_crc07, 0, s->gb.buffer, get_bits_count(&s->gb)/8); + crc8 = av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, + s->gb.buffer, get_bits_count(&s->gb)/8); if(crc8){ av_log(s->avctx, AV_LOG_ERROR, "header crc mismatch crc=%2X\n", crc8); return -1; @@ -568,20 +588,9 @@ static int decode_frame(FLACContext *s, int alloc_data_size) return 0; } -static inline int16_t shift_to_16_bits(int32_t data, int bps) -{ - if (bps == 24) { - return (data >> 8); - } else if (bps == 20) { - return (data >> 4); - } else { - return data; - } -} - static int flac_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { FLACContext *s = avctx->priv_data; int tmp = 0, i, j = 0, input_buf_size = 0; @@ -620,9 +629,9 @@ static int flac_decode_frame(AVCodecContext *avctx, if (!metadata_parse(s)) { tmp = show_bits(&s->gb, 16); - if(tmp != 0xFFF8){ + if((tmp & 0xFFFE) != 0xFFF8){ av_log(s->avctx, AV_LOG_ERROR, "FRAME HEADER not here\n"); - while(get_bits_count(&s->gb)/8+2 < buf_size && show_bits(&s->gb, 16) != 0xFFF8) + while(get_bits_count(&s->gb)/8+2 < buf_size && (show_bits(&s->gb, 16) & 0xFFFE) != 0xFFF8) skip_bits(&s->gb, 8); goto end; // we may not have enough bits left to decode a frame, so try next time } @@ -684,8 +693,8 @@ static int flac_decode_frame(AVCodecContext *avctx, {\ int a= s->decoded[0][i];\ int b= s->decoded[1][i];\ - *(samples++) = (left ) >> (16 - s->bps);\ - *(samples++) = (right) >> (16 - s->bps);\ + *samples++ = ((left) << (24 - s->bps)) >> 8;\ + *samples++ = ((right) << (24 - s->bps)) >> 8;\ }\ break; @@ -695,7 +704,7 @@ static int flac_decode_frame(AVCodecContext *avctx, for (j = 0; j < s->blocksize; j++) { for (i = 0; i < s->channels; i++) - *(samples++) = shift_to_16_bits(s->decoded[i][j], s->bps); + *samples++ = (s->decoded[i][j] << (24 - s->bps)) >> 8; } break; case LEFT_SIDE: @@ -712,7 +721,7 @@ static int flac_decode_frame(AVCodecContext *avctx, // s->last_blocksize = s->blocksize; end: - i= (get_bits_count(&s->gb)+7)/8;; + i= (get_bits_count(&s->gb)+7)/8; if(i > buf_size){ av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size); s->bitstream_size=0; diff --git a/contrib/ffmpeg/libavcodec/flacenc.c b/contrib/ffmpeg/libavcodec/flacenc.c index 9dd6c7eb8..469b46115 100644 --- a/contrib/ffmpeg/libavcodec/flacenc.c +++ b/contrib/ffmpeg/libavcodec/flacenc.c @@ -22,6 +22,7 @@ #include "avcodec.h" #include "bitstream.h" #include "crc.h" +#include "dsputil.h" #include "golomb.h" #include "lls.h" @@ -84,7 +85,7 @@ typedef struct FlacSubframe { int shift; RiceContext rc; int32_t samples[FLAC_MAX_BLOCKSIZE]; - int32_t residual[FLAC_MAX_BLOCKSIZE]; + int32_t residual[FLAC_MAX_BLOCKSIZE+1]; } FlacSubframe; typedef struct FlacFrame { @@ -107,6 +108,7 @@ typedef struct FlacEncodeContext { FlacFrame frame; CompressionOptions options; AVCodecContext *avctx; + DSPContext dsp; } FlacEncodeContext; static const int flac_samplerates[16] = { @@ -177,6 +179,8 @@ static int flac_encode_init(AVCodecContext *avctx) s->avctx = avctx; + dsputil_init(&s->dsp, avctx); + if(avctx->sample_fmt != SAMPLE_FMT_S16) { return -1; } @@ -447,20 +451,19 @@ static void copy_samples(FlacEncodeContext *s, int16_t *samples) #define rice_encode_count(sum, n, k) (((n)*((k)+1))+((sum-(n>>1))>>(k))) +/** + * Solve for d/dk(rice_encode_count) = n-((sum-(n>>1))>>(k+1)) = 0 + */ static int find_optimal_param(uint32_t sum, int n) { - int k, k_opt; - uint32_t nbits[MAX_RICE_PARAM+1]; - - k_opt = 0; - nbits[0] = UINT32_MAX; - for(k=0; k<=MAX_RICE_PARAM; k++) { - nbits[k] = rice_encode_count(sum, n, k); - if(nbits[k] < nbits[k_opt]) { - k_opt = k; - } - } - return k_opt; + int k; + uint32_t sum2; + + if(sum <= n>>1) + return 0; + sum2 = sum-(n>>1); + k = av_log2(n<256 ? FASTDIV(sum2,n) : sum2/n); + return FFMIN(k, MAX_RICE_PARAM); } static uint32_t calc_optimal_rice_params(RiceContext *rc, int porder, @@ -471,16 +474,15 @@ static uint32_t calc_optimal_rice_params(RiceContext *rc, int porder, uint32_t all_bits; part = (1 << porder); - all_bits = 0; + all_bits = 4 * part; cnt = (n >> porder) - pred_order; for(i=0; i> porder); k = find_optimal_param(sums[i], cnt); rc->params[i] = k; all_bits += rice_encode_count(sums[i], cnt, k); + cnt = n >> porder; } - all_bits += (4 * part); rc->porder = porder; @@ -499,10 +501,11 @@ static void calc_sums(int pmin, int pmax, uint32_t *data, int n, int pred_order, res = &data[pred_order]; res_end = &data[n >> pmax]; for(i=0; i> pmax; } /* sums for lower levels */ @@ -590,13 +593,19 @@ static void apply_welch_window(const int32_t *data, int len, double *w_data) double w; double c; + assert(!(len&1)); //the optimization in r11881 does not support odd len + //if someone wants odd len extend the change in r11881 + n2 = (len >> 1); c = 2.0 / (len - 1.0); + + w_data+=n2; + data+=n2; for(i=0; i= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER); if(use_lpc == 1){ - compute_autocorr(samples, blocksize, max_order+1, autoc); + s->dsp.flac_compute_autocorr(samples, blocksize, max_order, autoc); compute_lpc_coefs(autoc, max_order, lpc, ref); }else{ LLSModel m[2]; - double var[MAX_LPC_ORDER+1], eval, weight; + double var[MAX_LPC_ORDER+1], weight; for(pass=0; pass>pass) + fabs(eval - var[0]); + inv = 1/eval; + rinv = sqrt(inv); for(j=0; j<=max_order; j++) - var[j]/= sqrt(eval); - weight += 1/eval; + var[j] *= rinv; + weight += inv; }else weight++; @@ -823,33 +848,142 @@ static void encode_residual_fixed(int32_t *res, const int32_t *smp, int n, for(i=order; i> shift); + res[i+1] = smp[i+1] - (p1 >> shift); } } static void encode_residual_lpc(int32_t *res, const int32_t *smp, int n, int order, const int32_t *coefs, int shift) { - int i, j; - int32_t pred; - + int i; for(i=0; i> shift); - } + res[i ] = smp[i ] - (p0 >> shift); + res[i+1] = smp[i+1] - (p1 >> shift); + } +#else + switch(order) { + case 1: encode_residual_lpc_unrolled(res, smp, n, 1, coefs, shift, 0); break; + case 2: encode_residual_lpc_unrolled(res, smp, n, 2, coefs, shift, 0); break; + case 3: encode_residual_lpc_unrolled(res, smp, n, 3, coefs, shift, 0); break; + case 4: encode_residual_lpc_unrolled(res, smp, n, 4, coefs, shift, 0); break; + case 5: encode_residual_lpc_unrolled(res, smp, n, 5, coefs, shift, 0); break; + case 6: encode_residual_lpc_unrolled(res, smp, n, 6, coefs, shift, 0); break; + case 7: encode_residual_lpc_unrolled(res, smp, n, 7, coefs, shift, 0); break; + case 8: encode_residual_lpc_unrolled(res, smp, n, 8, coefs, shift, 0); break; + default: encode_residual_lpc_unrolled(res, smp, n, order, coefs, shift, 1); break; + } +#endif } static int encode_residual(FlacEncodeContext *ctx, int ch) @@ -919,7 +1053,7 @@ static int encode_residual(FlacEncodeContext *ctx, int ch) } /* LPC */ - opt_order = lpc_calc_coefs(smp, n, max_order, precision, coefs, shift, ctx->options.use_lpc, omethod); + opt_order = lpc_calc_coefs(ctx, smp, n, max_order, precision, coefs, shift, ctx->options.use_lpc, omethod); if(omethod == ORDER_METHOD_2LEVEL || omethod == ORDER_METHOD_4LEVEL || @@ -1155,7 +1289,8 @@ static void output_frame_header(FlacEncodeContext *s) put_bits(&s->pb, 16, s->sr_code[1]); } flush_put_bits(&s->pb); - crc = av_crc(av_crc07, 0, s->pb.buf, put_bits_count(&s->pb)>>3); + crc = av_crc(av_crc_get_table(AV_CRC_8_ATM), 0, + s->pb.buf, put_bits_count(&s->pb)>>3); put_bits(&s->pb, 8, crc); } @@ -1297,7 +1432,8 @@ static void output_frame_footer(FlacEncodeContext *s) { int crc; flush_put_bits(&s->pb); - crc = bswap_16(av_crc(av_crc8005, 0, s->pb.buf, put_bits_count(&s->pb)>>3)); + crc = bswap_16(av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, + s->pb.buf, put_bits_count(&s->pb)>>3)); put_bits(&s->pb, 16, crc); flush_put_bits(&s->pb); } diff --git a/contrib/ffmpeg/libavcodec/flashsv.c b/contrib/ffmpeg/libavcodec/flashsv.c index 9e4aa951a..842a7ccaf 100644 --- a/contrib/ffmpeg/libavcodec/flashsv.c +++ b/contrib/ffmpeg/libavcodec/flashsv.c @@ -50,7 +50,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include "bitstream.h" @@ -82,7 +81,7 @@ static void copy_region(uint8_t *sptr, uint8_t *dptr, static int flashsv_decode_init(AVCodecContext *avctx) { - FlashSVContext *s = (FlashSVContext *)avctx->priv_data; + FlashSVContext *s = avctx->priv_data; int zret; // Zlib return code s->avctx = avctx; @@ -95,7 +94,6 @@ static int flashsv_decode_init(AVCodecContext *avctx) return 1; } avctx->pix_fmt = PIX_FMT_BGR24; - avctx->has_b_frames = 0; s->frame.data[0] = NULL; return 0; @@ -104,9 +102,9 @@ static int flashsv_decode_init(AVCodecContext *avctx) static int flashsv_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { - FlashSVContext *s = (FlashSVContext *)avctx->priv_data; + FlashSVContext *s = avctx->priv_data; int h_blocks, v_blocks, h_part, v_part, i, j; GetBitContext gb; @@ -232,7 +230,7 @@ static int flashsv_decode_frame(AVCodecContext *avctx, static int flashsv_decode_end(AVCodecContext *avctx) { - FlashSVContext *s = (FlashSVContext *)avctx->priv_data; + FlashSVContext *s = avctx->priv_data; inflateEnd(&(s->zstream)); /* release the frame if needed */ if (s->frame.data[0]) diff --git a/contrib/ffmpeg/libavcodec/flashsvenc.c b/contrib/ffmpeg/libavcodec/flashsvenc.c index cbf488328..2b791c294 100644 --- a/contrib/ffmpeg/libavcodec/flashsvenc.c +++ b/contrib/ffmpeg/libavcodec/flashsvenc.c @@ -58,7 +58,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include "bitstream.h" #include "bytestream.h" @@ -100,7 +99,7 @@ static int copy_region_enc(uint8_t *sptr, uint8_t *dptr, static int flashsv_encode_init(AVCodecContext *avctx) { - FlashSVContext *s = (FlashSVContext *)avctx->priv_data; + FlashSVContext *s = avctx->priv_data; s->avctx = avctx; @@ -115,16 +114,6 @@ static int flashsv_encode_init(AVCodecContext *avctx) // Needed if zlib unused or init aborted before deflateInit memset(&(s->zstream), 0, sizeof(z_stream)); -/* - s->zstream.zalloc = NULL; //av_malloc; - s->zstream.zfree = NULL; //av_free; - s->zstream.opaque = NULL; - zret = deflateInit(&(s->zstream), 9); - if (zret != Z_OK) { - av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); - return -1; - } -*/ s->last_key_frame=0; @@ -194,22 +183,7 @@ static int encode_bitstream(FlashSVContext *s, AVFrame *p, uint8_t *buf, int buf //ret = deflateReset(&(s->zstream)); if (ret != Z_OK) av_log(s->avctx, AV_LOG_ERROR, "error while compressing block %dx%d\n", i, j); - /* - s->zstream.next_in = s->tmpblock; - s->zstream.avail_in = 3*ws*hs; - s->zstream.total_in = 0; - s->zstream.next_out = ptr+2; - s->zstream.avail_out = buf_size-buf_pos-2; - s->zstream.total_out = 0; - - ret = deflate(&(s->zstream), Z_FINISH); - if ((ret != Z_OK) && (ret != Z_STREAM_END)) - av_log(s->avctx, AV_LOG_ERROR, "error while compressing block %dx%d\n", i, j); - - size = s->zstream.total_out; - //av_log(avctx, AV_LOG_INFO, "compressed blocks: %d\n", size); - */ bytestream_put_be16(&ptr,(unsigned int)zsize); buf_pos += zsize+2; //av_log(avctx, AV_LOG_ERROR, "buf_pos = %d\n", buf_pos); @@ -232,9 +206,10 @@ static int encode_bitstream(FlashSVContext *s, AVFrame *p, uint8_t *buf, int buf static int flashsv_encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void *data) { - FlashSVContext * const s = (FlashSVContext *)avctx->priv_data; + FlashSVContext * const s = avctx->priv_data; AVFrame *pict = data; AVFrame * const p = &s->frame; + uint8_t *pfptr; int res; int I_frame = 0; int opt_w, opt_h; @@ -243,7 +218,7 @@ static int flashsv_encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_siz /* First frame needs to be a keyframe */ if (avctx->frame_number == 0) { - s->previous_frame = av_mallocz(p->linesize[0]*s->image_height); + s->previous_frame = av_mallocz(FFABS(p->linesize[0])*s->image_height); if (!s->previous_frame) { av_log(avctx, AV_LOG_ERROR, "Memory allocation failed.\n"); return -1; @@ -251,6 +226,11 @@ static int flashsv_encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_siz I_frame = 1; } + if (p->linesize[0] < 0) + pfptr = s->previous_frame - ((s->image_height-1) * p->linesize[0]); + else + pfptr = s->previous_frame; + /* Check the placement of keyframes */ if (avctx->gop_size > 0) { if (avctx->frame_number >= s->last_key_frame + avctx->gop_size) { @@ -258,40 +238,8 @@ static int flashsv_encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_siz } } -#if 0 - int w, h; - int optim_sizes[16][16]; - int smallest_size; - //Try all possible combinations and store the encoded frame sizes - for (w=1 ; w<17 ; w++) { - for (h=1 ; h<17 ; h++) { - optim_sizes[w-1][h-1] = encode_bitstream(s, p, s->encbuffer, s->image_width*s->image_height*4, w*16, h*16, s->previous_frame); - //av_log(avctx, AV_LOG_ERROR, "[%d][%d]size = %d\n",w,h,optim_sizes[w-1][h-1]); - } - } - - //Search for the smallest framesize and encode the frame with those parameters - smallest_size=optim_sizes[0][0]; - opt_w = 0; - opt_h = 0; - for (w=0 ; w<16 ; w++) { - for (h=0 ; h<16 ; h++) { - if (optim_sizes[w][h] < smallest_size) { - smallest_size = optim_sizes[w][h]; - opt_w = w; - opt_h = h; - } - } - } - res = encode_bitstream(s, p, buf, buf_size, (opt_w+1)*16, (opt_h+1)*16, s->previous_frame); - av_log(avctx, AV_LOG_ERROR, "[%d][%d]optimal size = %d, res = %d|\n", opt_w, opt_h, smallest_size, res); - - if (buf_size < res) - av_log(avctx, AV_LOG_ERROR, "buf_size %d < res %d\n", buf_size, res); - -#else - opt_w=1; - opt_h=1; + opt_w=4; + opt_h=4; if (buf_size < s->image_width*s->image_height*3) { //Conservative upper bound check for compressed data @@ -299,10 +247,13 @@ static int flashsv_encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_siz return -1; } - res = encode_bitstream(s, p, buf, buf_size, opt_w*16, opt_h*16, s->previous_frame, &I_frame); -#endif + res = encode_bitstream(s, p, buf, buf_size, opt_w*16, opt_h*16, pfptr, &I_frame); + //save the current frame - memcpy(s->previous_frame, p->data[0], s->image_height*p->linesize[0]); + if(p->linesize[0] > 0) + memcpy(s->previous_frame, p->data[0], s->image_height*p->linesize[0]); + else + memcpy(s->previous_frame, p->data[0] + p->linesize[0] * (s->image_height-1), s->image_height*FFABS(p->linesize[0])); //mark the frame type so the muxer can mux it correctly if (I_frame) { @@ -322,7 +273,7 @@ static int flashsv_encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_siz static int flashsv_encode_end(AVCodecContext *avctx) { - FlashSVContext *s = (FlashSVContext *)avctx->priv_data; + FlashSVContext *s = avctx->priv_data; deflateEnd(&(s->zstream)); diff --git a/contrib/ffmpeg/libavcodec/flicvideo.c b/contrib/ffmpeg/libavcodec/flicvideo.c index b60e0b1c2..29116a232 100644 --- a/contrib/ffmpeg/libavcodec/flicvideo.c +++ b/contrib/ffmpeg/libavcodec/flicvideo.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -41,7 +40,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include "bswap.h" @@ -80,26 +78,28 @@ typedef struct FlicDecodeContext { static int flic_decode_init(AVCodecContext *avctx) { - FlicDecodeContext *s = (FlicDecodeContext *)avctx->priv_data; + FlicDecodeContext *s = avctx->priv_data; unsigned char *fli_header = (unsigned char *)avctx->extradata; int depth; s->avctx = avctx; - avctx->has_b_frames = 0; s->fli_type = AV_RL16(&fli_header[4]); /* Might be overridden if a Magic Carpet FLC */ - depth = AV_RL16(&fli_header[12]); - - if (depth == 0) { - depth = 8; /* Some FLC generators set depth to zero, when they mean 8Bpp. Fix up here */ - } + depth = 0; if (s->avctx->extradata_size == 12) { /* special case for magic carpet FLIs */ s->fli_type = FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE; + depth = 8; } else if (s->avctx->extradata_size != 128) { av_log(avctx, AV_LOG_ERROR, "Expected extradata of 12 or 128 bytes\n"); return -1; + } else { + depth = AV_RL16(&fli_header[12]); + } + + if (depth == 0) { + depth = 8; /* Some FLC generators set depth to zero, when they mean 8Bpp. Fix up here */ } if ((s->fli_type == FLC_FLX_TYPE_CODE) && (depth == 16)) { @@ -127,9 +127,9 @@ static int flic_decode_init(AVCodecContext *avctx) static int flic_decode_frame_8BPP(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { - FlicDecodeContext *s = (FlicDecodeContext *)avctx->priv_data; + FlicDecodeContext *s = avctx->priv_data; int stream_ptr = 0; int stream_ptr_after_color_chunk; @@ -427,11 +427,11 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx, static int flic_decode_frame_15_16BPP(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { /* Note, the only difference between the 15Bpp and 16Bpp */ /* Format is the pixel format, the packets are processed the same. */ - FlicDecodeContext *s = (FlicDecodeContext *)avctx->priv_data; + FlicDecodeContext *s = avctx->priv_data; int stream_ptr = 0; int pixel_ptr; @@ -581,20 +581,18 @@ static int flic_decode_frame_15_16BPP(AVCodecContext *avctx, } /* Now FLX is strange, in that it is "byte" as opposed to "pixel" run length compressed. - * This doesnt give us any good oportunity to perform word endian conversion - * during decompression. So if its requried (ie, this isnt a LE target, we do + * This does not give us any good oportunity to perform word endian conversion + * during decompression. So if it is required (i.e., this is not a LE target, we do * a second pass over the line here, swapping the bytes. */ - pixel = 0xFF00; - if (0xFF00 != AV_RL16(&pixel)) /* Check if its not an LE Target */ - { - pixel_ptr = y_ptr; - pixel_countdown = s->avctx->width; - while (pixel_countdown > 0) { +#ifdef WORDS_BIGENDIAN + pixel_ptr = y_ptr; + pixel_countdown = s->avctx->width; + while (pixel_countdown > 0) { *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[pixel_ptr]); pixel_ptr += 2; - } } +#endif y_ptr += s->frame.linesize[0]; } break; @@ -694,7 +692,7 @@ static int flic_decode_frame_15_16BPP(AVCodecContext *avctx, static int flic_decode_frame_24BPP(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { av_log(avctx, AV_LOG_ERROR, "24Bpp FLC Unsupported due to lack of test files.\n"); return -1; @@ -702,7 +700,7 @@ static int flic_decode_frame_24BPP(AVCodecContext *avctx, static int flic_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { if (avctx->pix_fmt == PIX_FMT_PAL8) { return flic_decode_frame_8BPP(avctx, data, data_size, @@ -718,11 +716,11 @@ static int flic_decode_frame(AVCodecContext *avctx, buf, buf_size); } - /* Shouldnt get here, ever as the pix_fmt is processed */ + /* Should not get here, ever as the pix_fmt is processed */ /* in flic_decode_init and the above if should deal with */ /* the finite set of possibilites allowable by here. */ - /* but in case we do, just error out. */ - av_log(avctx, AV_LOG_ERROR, "Unknown Format of FLC. My Science cant explain how this happened\n"); + /* But in case we do, just error out. */ + av_log(avctx, AV_LOG_ERROR, "Unknown FLC format, my science cannot explain how this happened.\n"); return -1; } diff --git a/contrib/ffmpeg/libavcodec/fraps.c b/contrib/ffmpeg/libavcodec/fraps.c index 0a4567d05..b7db219c9 100644 --- a/contrib/ffmpeg/libavcodec/fraps.c +++ b/contrib/ffmpeg/libavcodec/fraps.c @@ -18,7 +18,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -34,30 +33,18 @@ #include "avcodec.h" #include "bitstream.h" +#include "huffman.h" +#include "bytestream.h" #include "dsputil.h" #define FPS_TAG MKTAG('F', 'P', 'S', 'x') -/* symbol for Huffman tree node */ -#define HNODE -1 - -/** - * Huffman node - * FIXME one day this should belong to one general framework - */ -typedef struct Node{ - int16_t sym; - int16_t n0; - int count; -}Node; - /** * local variable storage */ typedef struct FrapsContext{ AVCodecContext *avctx; AVFrame frame; - Node nodes[512]; uint8_t *tmpbuf; DSPContext dsp; } FrapsContext; @@ -73,7 +60,6 @@ static int decode_init(AVCodecContext *avctx) FrapsContext * const s = avctx->priv_data; avctx->coded_frame = (AVFrame*)&s->frame; - avctx->has_b_frames = 0; avctx->pix_fmt= PIX_FMT_NONE; /* set in decode_frame */ s->avctx = avctx; @@ -89,95 +75,36 @@ static int decode_init(AVCodecContext *avctx) * Comparator - our nodes should ascend by count * but with preserved symbol order */ -static int huff_cmp(const Node *a, const Node *b){ +static int huff_cmp(const void *va, const void *vb){ + const Node *a = va, *b = vb; return (a->count - b->count)*256 + a->sym - b->sym; } -static void get_tree_codes(uint32_t *bits, int16_t *lens, uint8_t *xlat, Node *nodes, int node, uint32_t pfx, int pl, int *pos) -{ - int s; - - s = nodes[node].sym; - if(s != HNODE || !nodes[node].count){ - bits[*pos] = pfx; - lens[*pos] = pl; - xlat[*pos] = s; - (*pos)++; - }else{ - pfx <<= 1; - pl++; - get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0, pfx, pl, pos); - pfx |= 1; - get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0+1, pfx, pl, pos); - } -} - -static int build_huff_tree(VLC *vlc, Node *nodes, uint8_t *xlat) -{ - uint32_t bits[256]; - int16_t lens[256]; - int pos = 0; - - get_tree_codes(bits, lens, xlat, nodes, 510, 0, 0, &pos); - return init_vlc(vlc, 9, pos, lens, 2, 2, bits, 4, 4, 0); -} - - /** * decode Fraps v2 packed plane */ static int fraps2_decode_plane(FrapsContext *s, uint8_t *dst, int stride, int w, - int h, uint8_t *src, int size, int Uoff) + int h, const uint8_t *src, int size, int Uoff) { int i, j; - int cur_node; GetBitContext gb; VLC vlc; - int64_t sum = 0; - uint8_t recode[256]; - - for(i = 0; i < 256; i++){ - s->nodes[i].sym = i; - s->nodes[i].count = AV_RL32(src); - s->nodes[i].n0 = -2; - if(s->nodes[i].count < 0) { - av_log(s->avctx, AV_LOG_ERROR, "Symbol count < 0\n"); - return -1; - } - src += 4; - sum += s->nodes[i].count; - } - size -= 1024; + Node nodes[512]; - if(sum >> 31) { - av_log(s->avctx, AV_LOG_ERROR, "Too high symbol frequencies. Tree construction is not possible\n"); - return -1; - } - qsort(s->nodes, 256, sizeof(Node), huff_cmp); - cur_node = 256; - for(i = 0; i < 511; i += 2){ - s->nodes[cur_node].sym = HNODE; - s->nodes[cur_node].count = s->nodes[i].count + s->nodes[i+1].count; - s->nodes[cur_node].n0 = i; - for(j = cur_node; j > 0; j--){ - if(s->nodes[j].count >= s->nodes[j - 1].count) break; - FFSWAP(Node, s->nodes[j], s->nodes[j - 1]); - } - cur_node++; - } - if(build_huff_tree(&vlc, s->nodes, recode) < 0){ - av_log(s->avctx, AV_LOG_ERROR, "Error building tree\n"); + for(i = 0; i < 256; i++) + nodes[i].count = bytestream_get_le32(&src); + size -= 1024; + if (ff_huff_build_tree(s->avctx, &vlc, 256, nodes, huff_cmp, 0) < 0) return -1; - } /* we have built Huffman table and are ready to decode plane */ /* convert bits so they may be used by standard bitreader */ - s->dsp.bswap_buf(s->tmpbuf, src, size >> 2); + s->dsp.bswap_buf((uint32_t *)s->tmpbuf, (const uint32_t *)src, size >> 2); init_get_bits(&gb, s->tmpbuf, size * 8); for(j = 0; j < h; j++){ for(i = 0; i < w; i++){ - dst[i] = recode[get_vlc2(&gb, vlc.table, 9, 3)]; + dst[i] = get_vlc2(&gb, vlc.table, 9, 3); /* lines are stored as deltas between previous lines * and we need to add 0x80 to the first lines of chroma planes */ @@ -201,7 +128,7 @@ static int fraps2_decode_plane(FrapsContext *s, uint8_t *dst, int stride, int w, */ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { FrapsContext * const s = avctx->priv_data; AVFrame *frame = data; @@ -209,7 +136,7 @@ static int decode_frame(AVCodecContext *avctx, uint32_t header; unsigned int version,header_size; unsigned int x, y; - uint32_t *buf32; + const uint32_t *buf32; uint32_t *luma1,*luma2,*cb,*cr; uint32_t offs[4]; int i, is_chroma, planes; @@ -263,7 +190,7 @@ static int decode_frame(AVCodecContext *avctx, f->key_frame = f->pict_type == FF_I_TYPE; if (f->pict_type == FF_I_TYPE) { - buf32=(uint32_t*)buf; + buf32=(const uint32_t*)buf; for(y=0; yheight/2; y++){ luma1=(uint32_t*)&f->data[0][ y*2*f->linesize[0] ]; luma2=(uint32_t*)&f->data[0][ (y*2+1)*f->linesize[0] ]; diff --git a/contrib/ffmpeg/libavcodec/g726.c b/contrib/ffmpeg/libavcodec/g726.c index 07af33122..d0073c1b4 100644 --- a/contrib/ffmpeg/libavcodec/g726.c +++ b/contrib/ffmpeg/libavcodec/g726.c @@ -23,7 +23,6 @@ */ #include #include "avcodec.h" -#include "common.h" #include "bitstream.h" /** @@ -65,14 +64,14 @@ static inline int sgn(int value) typedef struct G726Tables { int bits; /**< bits per sample */ - int* quant; /**< quantization table */ - int* iquant; /**< inverse quantization table */ - int* W; /**< special table #1 ;-) */ - int* F; /**< special table #2 */ + const int* quant; /**< quantization table */ + const int* iquant; /**< inverse quantization table */ + const int* W; /**< special table #1 ;-) */ + const int* F; /**< special table #2 */ } G726Tables; typedef struct G726Context { - G726Tables* tbls; /**< static tables needed for computation */ + const G726Tables* tbls; /**< static tables needed for computation */ Float11 sr[2]; /**< prev. reconstructed samples */ Float11 dq[6]; /**< prev. difference */ @@ -92,53 +91,53 @@ typedef struct G726Context { int y; /**< quantizer scaling factor for the next iteration */ } G726Context; -static int quant_tbl16[] = /**< 16kbit/s 2bits per sample */ +static const int quant_tbl16[] = /**< 16kbit/s 2bits per sample */ { 260, INT_MAX }; -static int iquant_tbl16[] = +static const int iquant_tbl16[] = { 116, 365, 365, 116 }; -static int W_tbl16[] = +static const int W_tbl16[] = { -22, 439, 439, -22 }; -static int F_tbl16[] = +static const int F_tbl16[] = { 0, 7, 7, 0 }; -static int quant_tbl24[] = /**< 24kbit/s 3bits per sample */ +static const int quant_tbl24[] = /**< 24kbit/s 3bits per sample */ { 7, 217, 330, INT_MAX }; -static int iquant_tbl24[] = +static const int iquant_tbl24[] = { INT_MIN, 135, 273, 373, 373, 273, 135, INT_MIN }; -static int W_tbl24[] = +static const int W_tbl24[] = { -4, 30, 137, 582, 582, 137, 30, -4 }; -static int F_tbl24[] = +static const int F_tbl24[] = { 0, 1, 2, 7, 7, 2, 1, 0 }; -static int quant_tbl32[] = /**< 32kbit/s 4bits per sample */ +static const int quant_tbl32[] = /**< 32kbit/s 4bits per sample */ { -125, 79, 177, 245, 299, 348, 399, INT_MAX }; -static int iquant_tbl32[] = +static const int iquant_tbl32[] = { INT_MIN, 4, 135, 213, 273, 323, 373, 425, 425, 373, 323, 273, 213, 135, 4, INT_MIN }; -static int W_tbl32[] = +static const int W_tbl32[] = { -12, 18, 41, 64, 112, 198, 355, 1122, 1122, 355, 198, 112, 64, 41, 18, -12}; -static int F_tbl32[] = +static const int F_tbl32[] = { 0, 0, 0, 1, 1, 1, 3, 7, 7, 3, 1, 1, 1, 0, 0, 0 }; -static int quant_tbl40[] = /**< 40kbit/s 5bits per sample */ +static const int quant_tbl40[] = /**< 40kbit/s 5bits per sample */ { -122, -16, 67, 138, 197, 249, 297, 338, 377, 412, 444, 474, 501, 527, 552, INT_MAX }; -static int iquant_tbl40[] = +static const int iquant_tbl40[] = { INT_MIN, -66, 28, 104, 169, 224, 274, 318, 358, 395, 429, 459, 488, 514, 539, 566, 566, 539, 514, 488, 459, 429, 395, 358, 318, 274, 224, 169, 104, 28, -66, INT_MIN }; -static int W_tbl40[] = +static const int W_tbl40[] = { 14, 14, 24, 39, 40, 41, 58, 100, 141, 179, 219, 280, 358, 440, 529, 696, 696, 529, 440, 358, 280, 219, 179, 141, 100, 58, 41, 40, 39, 24, 14, 14 }; -static int F_tbl40[] = +static const int F_tbl40[] = { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 6, 6, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; -static G726Tables G726Tables_pool[] = +static const G726Tables G726Tables_pool[] = {{ 2, quant_tbl16, iquant_tbl16, W_tbl16, F_tbl16 }, { 3, quant_tbl24, iquant_tbl24, W_tbl24, F_tbl24 }, { 4, quant_tbl32, iquant_tbl32, W_tbl32, F_tbl32 }, @@ -374,7 +373,7 @@ static int g726_encode_frame(AVCodecContext *avctx, static int g726_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { AVG726Context *c = avctx->priv_data; short *samples = data; @@ -388,7 +387,7 @@ static int g726_decode_frame(AVCodecContext *avctx, mask = (1<code_size) - 1; init_get_bits(&gb, buf, buf_size * 8); if (c->bits_left) { - int s = c->code_size - c->bits_left;; + int s = c->code_size - c->bits_left; code = (c->bit_buffer << s) | get_bits(&gb, s); *samples++ = g726_decode(&c->c, code & mask); } diff --git a/contrib/ffmpeg/libavcodec/gif.c b/contrib/ffmpeg/libavcodec/gif.c index f67ab52c2..ee3a13929 100644 --- a/contrib/ffmpeg/libavcodec/gif.c +++ b/contrib/ffmpeg/libavcodec/gif.c @@ -132,15 +132,11 @@ static void gif_put_bits_rev(PutBitContext *s, int n, unsigned int value) } else { bit_buf |= value << (bit_cnt); - *s->buf_ptr = bit_buf & 0xff; - s->buf_ptr[1] = (bit_buf >> 8) & 0xff; - s->buf_ptr[2] = (bit_buf >> 16) & 0xff; - s->buf_ptr[3] = (bit_buf >> 24) & 0xff; + bytestream_put_le32(&s->buf_ptr, bit_buf); //printf("bitbuf = %08x\n", bit_buf); - s->buf_ptr+=4; if (s->buf_ptr >= s->buf_end) - puts("bit buffer overflow !!"); // should never happen ! who got rid of the callback ??? + abort(); // flush_buffer_rev(s); bit_cnt=bit_cnt + n - 32; if (bit_cnt == 0) { @@ -195,9 +191,7 @@ static int gif_image_write_header(uint8_t **bytestream, } else { for(i=0;i<256;i++) { v = palette[i]; - bytestream_put_byte(bytestream, (v >> 16) & 0xff); - bytestream_put_byte(bytestream, (v >> 8) & 0xff); - bytestream_put_byte(bytestream, (v) & 0xff); + bytestream_put_be24(bytestream, v); } } diff --git a/contrib/ffmpeg/libavcodec/gifdec.c b/contrib/ffmpeg/libavcodec/gifdec.c index 3e8a3e6bc..8f0252694 100644 --- a/contrib/ffmpeg/libavcodec/gifdec.c +++ b/contrib/ffmpeg/libavcodec/gifdec.c @@ -47,8 +47,8 @@ typedef struct GifState { int gce_delay; /* LZW compatible decoder */ - uint8_t *bytestream; - uint8_t *bytestream_end; + const uint8_t *bytestream; + const uint8_t *bytestream_end; LZWState *lzw; /* aux buffers */ @@ -96,8 +96,7 @@ static int gif_read_image(GifState *s) n = (1 << bits_per_pixel); spal = palette; for(i = 0; i < n; i++) { - s->image_palette[i] = (0xff << 24) | - (spal[0] << 16) | (spal[1] << 8) | (spal[2]); + s->image_palette[i] = (0xff << 24) | AV_RB24(spal); spal += 3; } for(; i < 256; i++) @@ -258,18 +257,15 @@ static int gif_parse_next_image(GifState *s) #endif switch (code) { case ',': - if (gif_read_image(s) < 0) - return -1; - return 0; - case ';': - /* end of image */ - return -1; + return gif_read_image(s); case '!': if (gif_read_extension(s) < 0) return -1; break; + case ';': + /* end of image */ default: - /* error or errneous EOF */ + /* error or erroneous EOF */ return -1; } } @@ -289,7 +285,7 @@ static int gif_decode_init(AVCodecContext *avctx) return 0; } -static int gif_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) +static int gif_decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size) { GifState *s = avctx->priv_data; AVFrame *picture = data; diff --git a/contrib/ffmpeg/libavcodec/golomb.c b/contrib/ffmpeg/libavcodec/golomb.c index 50df4fc40..0ac7c9514 100644 --- a/contrib/ffmpeg/libavcodec/golomb.c +++ b/contrib/ffmpeg/libavcodec/golomb.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -154,3 +153,21 @@ const int8_t ff_interleaved_se_golomb_vlc_code[256]={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; + +const uint8_t ff_interleaved_dirac_golomb_vlc_code[256]={ +0, 1, 0, 0, 2, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, +4, 5, 2, 2, 6, 7, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +8, 9, 4, 4, 10,11,5, 5, 2, 2, 2, 2, 2, 2, 2, 2, +12,13,6, 6, 14,15,7, 7, 3, 3, 3, 3, 3, 3, 3, 3, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}; diff --git a/contrib/ffmpeg/libavcodec/golomb.h b/contrib/ffmpeg/libavcodec/golomb.h index 9bf7aec46..f2bc7fda6 100644 --- a/contrib/ffmpeg/libavcodec/golomb.h +++ b/contrib/ffmpeg/libavcodec/golomb.h @@ -18,7 +18,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -28,6 +27,12 @@ * @author Michael Niedermayer and Alex Beregszaszi */ +#ifndef FFMPEG_GOLOMB_H +#define FFMPEG_GOLOMB_H + +#include +#include "bitstream.h" + #define INVALID_VLC 0x80000000 extern const uint8_t ff_golomb_vlc_len[512]; @@ -38,6 +43,7 @@ extern const uint8_t ff_ue_golomb_len[256]; extern const uint8_t ff_interleaved_golomb_vlc_len[256]; extern const uint8_t ff_interleaved_ue_golomb_vlc_code[256]; extern const int8_t ff_interleaved_se_golomb_vlc_code[256]; +extern const uint8_t ff_interleaved_dirac_golomb_vlc_code[256]; /** @@ -70,7 +76,6 @@ static inline int get_ue_golomb(GetBitContext *gb){ static inline int svq3_get_ue_golomb(GetBitContext *gb){ uint32_t buf; - int log; OPEN_READER(re, gb); UPDATE_CACHE(re, gb); @@ -83,21 +88,24 @@ static inline int svq3_get_ue_golomb(GetBitContext *gb){ return ff_interleaved_ue_golomb_vlc_code[buf]; }else{ - LAST_SKIP_BITS(re, gb, 8); - UPDATE_CACHE(re, gb); - buf |= 1 | (GET_CACHE(re, gb) >> 8); + int ret = 1; - if((buf & 0xAAAAAAAA) == 0) - return INVALID_VLC; + while (1) { + buf >>= 32 - 8; + LAST_SKIP_BITS(re, gb, FFMIN(ff_interleaved_golomb_vlc_len[buf], 8)); - for(log=31; (buf & 0x80000000) == 0; log--){ - buf = (buf << 2) - ((buf << log) >> (log - 1)) + (buf >> 30); + if (ff_interleaved_golomb_vlc_len[buf] != 9){ + ret <<= (ff_interleaved_golomb_vlc_len[buf] - 1) >> 1; + ret |= ff_interleaved_dirac_golomb_vlc_code[buf]; + break; + } + ret = (ret << 4) | ff_interleaved_dirac_golomb_vlc_code[buf]; + UPDATE_CACHE(re, gb); + buf = GET_CACHE(re, gb); } - LAST_SKIP_BITS(re, gb, 63 - 2*log - 8); CLOSE_READER(re, gb); - - return ((buf << log) >> log) - 1; + return ret - 1; } } @@ -187,6 +195,24 @@ static inline int svq3_get_se_golomb(GetBitContext *gb){ } } +static inline int dirac_get_se_golomb(GetBitContext *gb){ + uint32_t buf; + uint32_t ret; + + ret = svq3_get_ue_golomb(gb); + + if (ret) { + OPEN_READER(re, gb); + UPDATE_CACHE(re, gb); + buf = SHOW_SBITS(re, gb, 1); + LAST_SKIP_BITS(re, gb, 1); + ret = (ret ^ buf) - buf; + CLOSE_READER(re, gb); + } + + return ret; +} + /** * read unsigned golomb rice code (ffv1). */ @@ -477,3 +503,5 @@ static inline void set_sr_golomb_flac(PutBitContext *pb, int i, int k, int limit set_ur_golomb_jpegls(pb, v, k, limit, esc_len); } + +#endif /* FFMPEG_GOLOMB_H */ diff --git a/contrib/ffmpeg/libavcodec/h261.c b/contrib/ffmpeg/libavcodec/h261.c index 83f3136e3..b4658c58c 100644 --- a/contrib/ffmpeg/libavcodec/h261.c +++ b/contrib/ffmpeg/libavcodec/h261.c @@ -1,5 +1,5 @@ /* - * H261 decoder + * H261 common code * Copyright (c) 2002-2004 Michael Niedermayer * Copyright (c) 2004 Maarten Daniels * @@ -25,40 +25,13 @@ * h261codec. */ -#include "common.h" #include "dsputil.h" #include "avcodec.h" -#include "mpegvideo.h" -#include "h261data.h" +#include "h261.h" - -#define H261_MBA_VLC_BITS 9 -#define H261_MTYPE_VLC_BITS 6 -#define H261_MV_VLC_BITS 7 -#define H261_CBP_VLC_BITS 9 -#define TCOEFF_VLC_BITS 9 - -#define MBA_STUFFING 33 -#define MBA_STARTCODE 34 #define IS_FIL(a) ((a)&MB_TYPE_H261_FIL) -/** - * H261Context - */ -typedef struct H261Context{ - MpegEncContext s; - - int current_mba; - int previous_mba; - int mba_diff; - int mtype; - int current_mv_x; - int current_mv_y; - int gob_number; - int gob_start_code_skipped; // 1 if gob start code is already read before gob header is read -}H261Context; - -static uint8_t static_rl_table_store[2][2*MAX_RUN + MAX_LEVEL + 3]; +uint8_t ff_h261_rl_table_store[2][2*MAX_RUN + MAX_LEVEL + 3]; void ff_h261_loop_filter(MpegEncContext *s){ H261Context * h= (H261Context*)s; @@ -79,979 +52,3 @@ void ff_h261_loop_filter(MpegEncContext *s){ s->dsp.h261_loop_filter(dest_cr, uvlinesize); } -int ff_h261_get_picture_format(int width, int height){ - // QCIF - if (width == 176 && height == 144) - return 0; - // CIF - else if (width == 352 && height == 288) - return 1; - // ERROR - else - return -1; -} - -static void h261_encode_block(H261Context * h, DCTELEM * block, - int n); -static int h261_decode_block(H261Context *h, DCTELEM *block, - int n, int coded); - -void ff_h261_encode_picture_header(MpegEncContext * s, int picture_number){ - H261Context * h = (H261Context *) s; - int format, temp_ref; - - align_put_bits(&s->pb); - - /* Update the pointer to last GOB */ - s->ptr_lastgob = pbBufPtr(&s->pb); - - put_bits(&s->pb, 20, 0x10); /* PSC */ - - temp_ref= s->picture_number * (int64_t)30000 * s->avctx->time_base.num / - (1001 * (int64_t)s->avctx->time_base.den); //FIXME maybe this should use a timestamp - put_bits(&s->pb, 5, temp_ref & 0x1f); /* TemporalReference */ - - put_bits(&s->pb, 1, 0); /* split screen off */ - put_bits(&s->pb, 1, 0); /* camera off */ - put_bits(&s->pb, 1, 0); /* freeze picture release off */ - - format = ff_h261_get_picture_format(s->width, s->height); - - put_bits(&s->pb, 1, format); /* 0 == QCIF, 1 == CIF */ - - put_bits(&s->pb, 1, 0); /* still image mode */ - put_bits(&s->pb, 1, 0); /* reserved */ - - put_bits(&s->pb, 1, 0); /* no PEI */ - if(format == 0) - h->gob_number = -1; - else - h->gob_number = 0; - h->current_mba = 0; -} - -/** - * Encodes a group of blocks header. - */ -static void h261_encode_gob_header(MpegEncContext * s, int mb_line){ - H261Context * h = (H261Context *)s; - if(ff_h261_get_picture_format(s->width, s->height) == 0){ - h->gob_number+=2; // QCIF - } - else{ - h->gob_number++; // CIF - } - put_bits(&s->pb, 16, 1); /* GBSC */ - put_bits(&s->pb, 4, h->gob_number); /* GN */ - put_bits(&s->pb, 5, s->qscale); /* GQUANT */ - put_bits(&s->pb, 1, 0); /* no GEI */ - h->current_mba = 0; - h->previous_mba = 0; - h->current_mv_x=0; - h->current_mv_y=0; -} - -void ff_h261_reorder_mb_index(MpegEncContext* s){ - int index= s->mb_x + s->mb_y*s->mb_width; - - if(index % 33 == 0) - h261_encode_gob_header(s,0); - - /* for CIF the GOB's are fragmented in the middle of a scanline - that's why we need to adjust the x and y index of the macroblocks */ - if(ff_h261_get_picture_format(s->width,s->height) == 1){ // CIF - s->mb_x = index % 11 ; index /= 11; - s->mb_y = index % 3 ; index /= 3; - s->mb_x+= 11*(index % 2); index /= 2; - s->mb_y+= 3*index; - - ff_init_block_index(s); - ff_update_block_index(s); - } -} - -static void h261_encode_motion(H261Context * h, int val){ - MpegEncContext * const s = &h->s; - int sign, code; - if(val==0){ - code = 0; - put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]); - } - else{ - if(val > 15) - val -=32; - if(val < -16) - val+=32; - sign = val < 0; - code = sign ? -val : val; - put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]); - put_bits(&s->pb,1,sign); - } -} - -static inline int get_cbp(MpegEncContext * s, - DCTELEM block[6][64]) -{ - int i, cbp; - cbp= 0; - for (i = 0; i < 6; i++) { - if (s->block_last_index[i] >= 0) - cbp |= 1 << (5 - i); - } - return cbp; -} -void ff_h261_encode_mb(MpegEncContext * s, - DCTELEM block[6][64], - int motion_x, int motion_y) -{ - H261Context * h = (H261Context *)s; - int mvd, mv_diff_x, mv_diff_y, i, cbp; - cbp = 63; // avoid warning - mvd = 0; - - h->current_mba++; - h->mtype = 0; - - if (!s->mb_intra){ - /* compute cbp */ - cbp= get_cbp(s, block); - - /* mvd indicates if this block is motion compensated */ - mvd = motion_x | motion_y; - - if((cbp | mvd | s->dquant ) == 0) { - /* skip macroblock */ - s->skip_count++; - h->current_mv_x=0; - h->current_mv_y=0; - return; - } - } - - /* MB is not skipped, encode MBA */ - put_bits(&s->pb, h261_mba_bits[(h->current_mba-h->previous_mba)-1], h261_mba_code[(h->current_mba-h->previous_mba)-1]); - - /* calculate MTYPE */ - if(!s->mb_intra){ - h->mtype++; - - if(mvd || s->loop_filter) - h->mtype+=3; - if(s->loop_filter) - h->mtype+=3; - if(cbp || s->dquant) - h->mtype++; - assert(h->mtype > 1); - } - - if(s->dquant) - h->mtype++; - - put_bits(&s->pb, h261_mtype_bits[h->mtype], h261_mtype_code[h->mtype]); - - h->mtype = h261_mtype_map[h->mtype]; - - if(IS_QUANT(h->mtype)){ - ff_set_qscale(s,s->qscale+s->dquant); - put_bits(&s->pb, 5, s->qscale); - } - - if(IS_16X16(h->mtype)){ - mv_diff_x = (motion_x >> 1) - h->current_mv_x; - mv_diff_y = (motion_y >> 1) - h->current_mv_y; - h->current_mv_x = (motion_x >> 1); - h->current_mv_y = (motion_y >> 1); - h261_encode_motion(h,mv_diff_x); - h261_encode_motion(h,mv_diff_y); - } - - h->previous_mba = h->current_mba; - - if(HAS_CBP(h->mtype)){ - assert(cbp>0); - put_bits(&s->pb,h261_cbp_tab[cbp-1][1],h261_cbp_tab[cbp-1][0]); - } - for(i=0; i<6; i++) { - /* encode each block */ - h261_encode_block(h, block[i], i); - } - - if ( ( h->current_mba == 11 ) || ( h->current_mba == 22 ) || ( h->current_mba == 33 ) || ( !IS_16X16 ( h->mtype ) )){ - h->current_mv_x=0; - h->current_mv_y=0; - } -} - -void ff_h261_encode_init(MpegEncContext *s){ - static int done = 0; - - if (!done) { - done = 1; - init_rl(&h261_rl_tcoeff, static_rl_table_store); - } - - s->min_qcoeff= -127; - s->max_qcoeff= 127; - s->y_dc_scale_table= - s->c_dc_scale_table= ff_mpeg1_dc_scale_table; -} - - -/** - * encodes a 8x8 block. - * @param block the 8x8 block - * @param n block index (0-3 are luma, 4-5 are chroma) - */ -static void h261_encode_block(H261Context * h, DCTELEM * block, int n){ - MpegEncContext * const s = &h->s; - int level, run, last, i, j, last_index, last_non_zero, sign, slevel, code; - RLTable *rl; - - rl = &h261_rl_tcoeff; - if (s->mb_intra) { - /* DC coef */ - level = block[0]; - /* 255 cannot be represented, so we clamp */ - if (level > 254) { - level = 254; - block[0] = 254; - } - /* 0 cannot be represented also */ - else if (level < 1) { - level = 1; - block[0] = 1; - } - if (level == 128) - put_bits(&s->pb, 8, 0xff); - else - put_bits(&s->pb, 8, level); - i = 1; - } else if((block[0]==1 || block[0] == -1) && (s->block_last_index[n] > -1)){ - //special case - put_bits(&s->pb,2,block[0]>0 ? 2 : 3 ); - i = 1; - } else { - i = 0; - } - - /* AC coefs */ - last_index = s->block_last_index[n]; - last_non_zero = i - 1; - for (; i <= last_index; i++) { - j = s->intra_scantable.permutated[i]; - level = block[j]; - if (level) { - run = i - last_non_zero - 1; - last = (i == last_index); - sign = 0; - slevel = level; - if (level < 0) { - sign = 1; - level = -level; - } - code = get_rl_index(rl, 0 /*no last in H.261, EOB is used*/, run, level); - if(run==0 && level < 16) - code+=1; - put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); - if (code == rl->n) { - put_bits(&s->pb, 6, run); - assert(slevel != 0); - assert(level <= 127); - put_bits(&s->pb, 8, slevel & 0xff); - } else { - put_bits(&s->pb, 1, sign); - } - last_non_zero = i; - } - } - if(last_index > -1){ - put_bits(&s->pb, rl->table_vlc[0][1], rl->table_vlc[0][0]);// END OF BLOCK - } -} - -/***********************************************/ -/* decoding */ - -static VLC h261_mba_vlc; -static VLC h261_mtype_vlc; -static VLC h261_mv_vlc; -static VLC h261_cbp_vlc; - -static void h261_decode_init_vlc(H261Context *h){ - static int done = 0; - - if(!done){ - done = 1; - init_vlc(&h261_mba_vlc, H261_MBA_VLC_BITS, 35, - h261_mba_bits, 1, 1, - h261_mba_code, 1, 1, 1); - init_vlc(&h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10, - h261_mtype_bits, 1, 1, - h261_mtype_code, 1, 1, 1); - init_vlc(&h261_mv_vlc, H261_MV_VLC_BITS, 17, - &h261_mv_tab[0][1], 2, 1, - &h261_mv_tab[0][0], 2, 1, 1); - init_vlc(&h261_cbp_vlc, H261_CBP_VLC_BITS, 63, - &h261_cbp_tab[0][1], 2, 1, - &h261_cbp_tab[0][0], 2, 1, 1); - init_rl(&h261_rl_tcoeff, static_rl_table_store); - init_vlc_rl(&h261_rl_tcoeff, 1); - } -} - -static int h261_decode_init(AVCodecContext *avctx){ - H261Context *h= avctx->priv_data; - MpegEncContext * const s = &h->s; - - // set defaults - MPV_decode_defaults(s); - s->avctx = avctx; - - s->width = s->avctx->coded_width; - s->height = s->avctx->coded_height; - s->codec_id = s->avctx->codec->id; - - s->out_format = FMT_H261; - s->low_delay= 1; - avctx->pix_fmt= PIX_FMT_YUV420P; - - s->codec_id= avctx->codec->id; - - h261_decode_init_vlc(h); - - h->gob_start_code_skipped = 0; - - return 0; -} - -/** - * decodes the group of blocks header or slice header. - * @return <0 if an error occured - */ -static int h261_decode_gob_header(H261Context *h){ - unsigned int val; - MpegEncContext * const s = &h->s; - - if ( !h->gob_start_code_skipped ){ - /* Check for GOB Start Code */ - val = show_bits(&s->gb, 15); - if(val) - return -1; - - /* We have a GBSC */ - skip_bits(&s->gb, 16); - } - - h->gob_start_code_skipped = 0; - - h->gob_number = get_bits(&s->gb, 4); /* GN */ - s->qscale = get_bits(&s->gb, 5); /* GQUANT */ - - /* Check if gob_number is valid */ - if (s->mb_height==18){ //cif - if ((h->gob_number<=0) || (h->gob_number>12)) - return -1; - } - else{ //qcif - if ((h->gob_number!=1) && (h->gob_number!=3) && (h->gob_number!=5)) - return -1; - } - - /* GEI */ - while (get_bits1(&s->gb) != 0) { - skip_bits(&s->gb, 8); - } - - if(s->qscale==0) - return -1; - - // For the first transmitted macroblock in a GOB, MBA is the absolute address. For - // subsequent macroblocks, MBA is the difference between the absolute addresses of - // the macroblock and the last transmitted macroblock. - h->current_mba = 0; - h->mba_diff = 0; - - return 0; -} - -/** - * decodes the group of blocks / video packet header. - * @return <0 if no resync found - */ -static int ff_h261_resync(H261Context *h){ - MpegEncContext * const s = &h->s; - int left, ret; - - if ( h->gob_start_code_skipped ){ - ret= h261_decode_gob_header(h); - if(ret>=0) - return 0; - } - else{ - if(show_bits(&s->gb, 15)==0){ - ret= h261_decode_gob_header(h); - if(ret>=0) - return 0; - } - //ok, its not where its supposed to be ... - s->gb= s->last_resync_gb; - align_get_bits(&s->gb); - left= s->gb.size_in_bits - get_bits_count(&s->gb); - - for(;left>15+1+4+5; left-=8){ - if(show_bits(&s->gb, 15)==0){ - GetBitContext bak= s->gb; - - ret= h261_decode_gob_header(h); - if(ret>=0) - return 0; - - s->gb= bak; - } - skip_bits(&s->gb, 8); - } - } - - return -1; -} - -/** - * decodes skipped macroblocks - * @return 0 - */ -static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2 ) -{ - MpegEncContext * const s = &h->s; - int i; - - s->mb_intra = 0; - - for(i=mba1; imb_x= ((h->gob_number-1) % 2) * 11 + i % 11; - s->mb_y= ((h->gob_number-1) / 2) * 3 + i / 11; - xy = s->mb_x + s->mb_y * s->mb_stride; - ff_init_block_index(s); - ff_update_block_index(s); - - for(j=0;j<6;j++) - s->block_last_index[j] = -1; - - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_16X16; - s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; - s->mv[0][0][0] = 0; - s->mv[0][0][1] = 0; - s->mb_skipped = 1; - h->mtype &= ~MB_TYPE_H261_FIL; - - MPV_decode_mb(s, s->block); - } - - return 0; -} - -static int decode_mv_component(GetBitContext *gb, int v){ - int mv_diff = get_vlc2(gb, h261_mv_vlc.table, H261_MV_VLC_BITS, 2); - - /* check if mv_diff is valid */ - if ( mv_diff < 0 ) - return v; - - mv_diff = mvmap[mv_diff]; - - if(mv_diff && !get_bits1(gb)) - mv_diff= -mv_diff; - - v += mv_diff; - if (v <=-16) v+= 32; - else if(v >= 16) v-= 32; - - return v; -} - -static int h261_decode_mb(H261Context *h){ - MpegEncContext * const s = &h->s; - int i, cbp, xy; - - cbp = 63; - // Read mba - do{ - h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc.table, H261_MBA_VLC_BITS, 2); - - /* Check for slice end */ - /* NOTE: GOB can be empty (no MB data) or exist only of MBA_stuffing */ - if (h->mba_diff == MBA_STARTCODE){ // start code - h->gob_start_code_skipped = 1; - return SLICE_END; - } - } - while( h->mba_diff == MBA_STUFFING ); // stuffing - - if ( h->mba_diff < 0 ){ - if ( get_bits_count(&s->gb) + 7 >= s->gb.size_in_bits ) - return SLICE_END; - - av_log(s->avctx, AV_LOG_ERROR, "illegal mba at %d %d\n", s->mb_x, s->mb_y); - return SLICE_ERROR; - } - - h->mba_diff += 1; - h->current_mba += h->mba_diff; - - if ( h->current_mba > MBA_STUFFING ) - return SLICE_ERROR; - - s->mb_x= ((h->gob_number-1) % 2) * 11 + ((h->current_mba-1) % 11); - s->mb_y= ((h->gob_number-1) / 2) * 3 + ((h->current_mba-1) / 11); - xy = s->mb_x + s->mb_y * s->mb_stride; - ff_init_block_index(s); - ff_update_block_index(s); - - // Read mtype - h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2); - h->mtype = h261_mtype_map[h->mtype]; - - // Read mquant - if ( IS_QUANT ( h->mtype ) ){ - ff_set_qscale(s, get_bits(&s->gb, 5)); - } - - s->mb_intra = IS_INTRA4x4(h->mtype); - - // Read mv - if ( IS_16X16 ( h->mtype ) ){ - // Motion vector data is included for all MC macroblocks. MVD is obtained from the macroblock vector by subtracting the - // vector of the preceding macroblock. For this calculation the vector of the preceding macroblock is regarded as zero in the - // following three situations: - // 1) evaluating MVD for macroblocks 1, 12 and 23; - // 2) evaluating MVD for macroblocks in which MBA does not represent a difference of 1; - // 3) MTYPE of the previous macroblock was not MC. - if ( ( h->current_mba == 1 ) || ( h->current_mba == 12 ) || ( h->current_mba == 23 ) || - ( h->mba_diff != 1)) - { - h->current_mv_x = 0; - h->current_mv_y = 0; - } - - h->current_mv_x= decode_mv_component(&s->gb, h->current_mv_x); - h->current_mv_y= decode_mv_component(&s->gb, h->current_mv_y); - }else{ - h->current_mv_x = 0; - h->current_mv_y = 0; - } - - // Read cbp - if ( HAS_CBP( h->mtype ) ){ - cbp = get_vlc2(&s->gb, h261_cbp_vlc.table, H261_CBP_VLC_BITS, 2) + 1; - } - - if(s->mb_intra){ - s->current_picture.mb_type[xy]= MB_TYPE_INTRA; - goto intra; - } - - //set motion vectors - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_16X16; - s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; - s->mv[0][0][0] = h->current_mv_x * 2;//gets divided by 2 in motion compensation - s->mv[0][0][1] = h->current_mv_y * 2; - -intra: - /* decode each block */ - if(s->mb_intra || HAS_CBP(h->mtype)){ - s->dsp.clear_blocks(s->block[0]); - for (i = 0; i < 6; i++) { - if (h261_decode_block(h, s->block[i], i, cbp&32) < 0){ - return SLICE_ERROR; - } - cbp+=cbp; - } - }else{ - for (i = 0; i < 6; i++) - s->block_last_index[i]= -1; - } - - MPV_decode_mb(s, s->block); - - return SLICE_OK; -} - -/** - * decodes a macroblock - * @return <0 if an error occured - */ -static int h261_decode_block(H261Context * h, DCTELEM * block, - int n, int coded) -{ - MpegEncContext * const s = &h->s; - int code, level, i, j, run; - RLTable *rl = &h261_rl_tcoeff; - const uint8_t *scan_table; - - // For the variable length encoding there are two code tables, one being used for - // the first transmitted LEVEL in INTER, INTER+MC and INTER+MC+FIL blocks, the second - // for all other LEVELs except the first one in INTRA blocks which is fixed length - // coded with 8 bits. - // NOTE: the two code tables only differ in one VLC so we handle that manually. - scan_table = s->intra_scantable.permutated; - if (s->mb_intra){ - /* DC coef */ - level = get_bits(&s->gb, 8); - // 0 (00000000b) and -128 (10000000b) are FORBIDDEN - if((level&0x7F) == 0){ - av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y); - return -1; - } - // The code 1000 0000 is not used, the reconstruction level of 1024 being coded as 1111 1111. - if (level == 255) - level = 128; - block[0] = level; - i = 1; - }else if(coded){ - // Run Level Code - // EOB Not possible for first level when cbp is available (that's why the table is different) - // 0 1 1s - // * * 0* - int check = show_bits(&s->gb, 2); - i = 0; - if ( check & 0x2 ){ - skip_bits(&s->gb, 2); - block[0] = ( check & 0x1 ) ? -1 : 1; - i = 1; - } - }else{ - i = 0; - } - if(!coded){ - s->block_last_index[n] = i - 1; - return 0; - } - for(;;){ - code = get_vlc2(&s->gb, rl->vlc.table, TCOEFF_VLC_BITS, 2); - if (code < 0){ - av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y); - return -1; - } - if (code == rl->n) { - /* escape */ - // The remaining combinations of (run, level) are encoded with a 20-bit word consisting of 6 bits escape, 6 bits run and 8 bits level. - run = get_bits(&s->gb, 6); - level = get_sbits(&s->gb, 8); - }else if(code == 0){ - break; - }else{ - run = rl->table_run[code]; - level = rl->table_level[code]; - if (get_bits1(&s->gb)) - level = -level; - } - i += run; - if (i >= 64){ - av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n", s->mb_x, s->mb_y); - return -1; - } - j = scan_table[i]; - block[j] = level; - i++; - } - s->block_last_index[n] = i-1; - return 0; -} - -/** - * decodes the H261 picture header. - * @return <0 if no startcode found - */ -static int h261_decode_picture_header(H261Context *h){ - MpegEncContext * const s = &h->s; - int format, i; - uint32_t startcode= 0; - - for(i= s->gb.size_in_bits - get_bits_count(&s->gb); i>24; i-=1){ - startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF; - - if(startcode == 0x10) - break; - } - - if (startcode != 0x10){ - av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); - return -1; - } - - /* temporal reference */ - i= get_bits(&s->gb, 5); /* picture timestamp */ - if(i < (s->picture_number&31)) - i += 32; - s->picture_number = (s->picture_number&~31) + i; - - s->avctx->time_base= (AVRational){1001, 30000}; - s->current_picture.pts= s->picture_number; - - - /* PTYPE starts here */ - skip_bits1(&s->gb); /* split screen off */ - skip_bits1(&s->gb); /* camera off */ - skip_bits1(&s->gb); /* freeze picture release off */ - - format = get_bits1(&s->gb); - - //only 2 formats possible - if (format == 0){//QCIF - s->width = 176; - s->height = 144; - s->mb_width = 11; - s->mb_height = 9; - }else{//CIF - s->width = 352; - s->height = 288; - s->mb_width = 22; - s->mb_height = 18; - } - - s->mb_num = s->mb_width * s->mb_height; - - skip_bits1(&s->gb); /* still image mode off */ - skip_bits1(&s->gb); /* Reserved */ - - /* PEI */ - while (get_bits1(&s->gb) != 0){ - skip_bits(&s->gb, 8); - } - - // h261 has no I-FRAMES, but if we pass I_TYPE for the first frame, the codec crashes if it does - // not contain all I-blocks (e.g. when a packet is lost) - s->pict_type = P_TYPE; - - h->gob_number = 0; - return 0; -} - -static int h261_decode_gob(H261Context *h){ - MpegEncContext * const s = &h->s; - - ff_set_qscale(s, s->qscale); - - /* decode mb's */ - while(h->current_mba <= MBA_STUFFING) - { - int ret; - /* DCT & quantize */ - ret= h261_decode_mb(h); - if(ret<0){ - if(ret==SLICE_END){ - h261_decode_mb_skipped(h, h->current_mba, 33); - return 0; - } - av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", s->mb_x + s->mb_y*s->mb_stride); - return -1; - } - - h261_decode_mb_skipped(h, h->current_mba-h->mba_diff, h->current_mba-1); - } - - return -1; -} - -#ifdef CONFIG_H261_PARSER -static int h261_find_frame_end(ParseContext *pc, AVCodecContext* avctx, const uint8_t *buf, int buf_size){ - int vop_found, i, j; - uint32_t state; - - vop_found= pc->frame_start_found; - state= pc->state; - - for(i=0; i>j)&0xFFFFF) == 0x00010){ - vop_found=1; - break; - } - } - } - if(vop_found){ - for(; i>j)&0xFFFFF) == 0x00010){ - pc->frame_start_found=0; - pc->state= state>>(2*8); - return i-1; - } - } - } - } - - pc->frame_start_found= vop_found; - pc->state= state; - return END_NOT_FOUND; -} - -static int h261_parse(AVCodecParserContext *s, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - ParseContext *pc = s->priv_data; - int next; - - next= h261_find_frame_end(pc,avctx, buf, buf_size); - if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { - *poutbuf = NULL; - *poutbuf_size = 0; - return buf_size; - } - *poutbuf = (uint8_t *)buf; - *poutbuf_size = buf_size; - return next; -} -#endif - -/** - * returns the number of bytes consumed for building the current frame - */ -static int get_consumed_bytes(MpegEncContext *s, int buf_size){ - int pos= get_bits_count(&s->gb)>>3; - if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...) - if(pos+10>buf_size) pos=buf_size; // oops ;) - - return pos; -} - -static int h261_decode_frame(AVCodecContext *avctx, - void *data, int *data_size, - uint8_t *buf, int buf_size) -{ - H261Context *h= avctx->priv_data; - MpegEncContext *s = &h->s; - int ret; - AVFrame *pict = data; - -#ifdef DEBUG - av_log(avctx, AV_LOG_DEBUG, "*****frame %d size=%d\n", avctx->frame_number, buf_size); - av_log(avctx, AV_LOG_DEBUG, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]); -#endif - s->flags= avctx->flags; - s->flags2= avctx->flags2; - - h->gob_start_code_skipped=0; - -retry: - - init_get_bits(&s->gb, buf, buf_size*8); - - if(!s->context_initialized){ - if (MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix - return -1; - } - - //we need to set current_picture_ptr before reading the header, otherwise we cant store anyting im there - if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){ - int i= ff_find_unused_picture(s, 0); - s->current_picture_ptr= &s->picture[i]; - } - - ret = h261_decode_picture_header(h); - - /* skip if the header was thrashed */ - if (ret < 0){ - av_log(s->avctx, AV_LOG_ERROR, "header damaged\n"); - return -1; - } - - if (s->width != avctx->coded_width || s->height != avctx->coded_height){ - ParseContext pc= s->parse_context; //FIXME move these demuxng hack to avformat - s->parse_context.buffer=0; - MPV_common_end(s); - s->parse_context= pc; - } - if (!s->context_initialized) { - avcodec_set_dimensions(avctx, s->width, s->height); - - goto retry; - } - - // for hurry_up==5 - s->current_picture.pict_type= s->pict_type; - s->current_picture.key_frame= s->pict_type == I_TYPE; - - /* skip everything if we are in a hurry>=5 */ - if(avctx->hurry_up>=5) return get_consumed_bytes(s, buf_size); - if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE) - ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE) - || avctx->skip_frame >= AVDISCARD_ALL) - return get_consumed_bytes(s, buf_size); - - if(MPV_frame_start(s, avctx) < 0) - return -1; - - ff_er_frame_start(s); - - /* decode each macroblock */ - s->mb_x=0; - s->mb_y=0; - - while(h->gob_number < (s->mb_height==18 ? 12 : 5)){ - if(ff_h261_resync(h)<0) - break; - h261_decode_gob(h); - } - MPV_frame_end(s); - -assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type); -assert(s->current_picture.pict_type == s->pict_type); - *pict= *(AVFrame*)s->current_picture_ptr; - ff_print_debug_info(s, pict); - - *data_size = sizeof(AVFrame); - - return get_consumed_bytes(s, buf_size); -} - -static int h261_decode_end(AVCodecContext *avctx) -{ - H261Context *h= avctx->priv_data; - MpegEncContext *s = &h->s; - - MPV_common_end(s); - return 0; -} - -#ifdef CONFIG_ENCODERS -AVCodec h261_encoder = { - "h261", - CODEC_TYPE_VIDEO, - CODEC_ID_H261, - sizeof(H261Context), - MPV_encode_init, - MPV_encode_picture, - MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, -}; -#endif - -AVCodec h261_decoder = { - "h261", - CODEC_TYPE_VIDEO, - CODEC_ID_H261, - sizeof(H261Context), - h261_decode_init, - NULL, - h261_decode_end, - h261_decode_frame, - CODEC_CAP_DR1, -}; - -#ifdef CONFIG_H261_PARSER -AVCodecParser h261_parser = { - { CODEC_ID_H261 }, - sizeof(ParseContext), - NULL, - h261_parse, - ff_parse_close, -}; -#endif diff --git a/contrib/ffmpeg/libavcodec/h261.h b/contrib/ffmpeg/libavcodec/h261.h new file mode 100644 index 000000000..f0ce7c366 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/h261.h @@ -0,0 +1,51 @@ +/* + * H261 decoder + * Copyright (c) 2002-2004 Michael Niedermayer + * Copyright (c) 2004 Maarten Daniels + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file h261.c + * h261codec. + */ + +#ifndef FFMPEG_H261_H +#define FFMPEG_H261_H + +#include "mpegvideo.h" + +/** + * H261Context + */ +typedef struct H261Context{ + MpegEncContext s; + + int current_mba; + int previous_mba; + int mba_diff; + int mtype; + int current_mv_x; + int current_mv_y; + int gob_number; + int gob_start_code_skipped; // 1 if gob start code is already read before gob header is read +}H261Context; + +#define MB_TYPE_H261_FIL 0x800000 + +#endif /* FFMPEG_H261_H */ diff --git a/contrib/ffmpeg/libavcodec/h261_parser.c b/contrib/ffmpeg/libavcodec/h261_parser.c new file mode 100644 index 000000000..3f3aac6e4 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/h261_parser.c @@ -0,0 +1,90 @@ +/* + * H261 parser + * Copyright (c) 2002-2004 Michael Niedermayer + * Copyright (c) 2004 Maarten Daniels + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file h261_parser.c + * h261codec. + */ + +#include "parser.h" + + +static int h261_find_frame_end(ParseContext *pc, AVCodecContext* avctx, const uint8_t *buf, int buf_size){ + int vop_found, i, j; + uint32_t state; + + vop_found= pc->frame_start_found; + state= pc->state; + + for(i=0; i>j)&0xFFFFF0) == 0x000100){ + vop_found=1; + break; + } + } + } + if(vop_found){ + for(; i>j)&0xFFFFF0) == 0x000100){ + pc->frame_start_found=0; + pc->state= (state>>(3*8))+0xFF00; + return i-2; + } + } + } + } + + pc->frame_start_found= vop_found; + pc->state= state; + return END_NOT_FOUND; +} + +static int h261_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + ParseContext *pc = s->priv_data; + int next; + + next= h261_find_frame_end(pc,avctx, buf, buf_size); + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + *poutbuf = buf; + *poutbuf_size = buf_size; + return next; +} + +AVCodecParser h261_parser = { + { CODEC_ID_H261 }, + sizeof(ParseContext), + NULL, + h261_parse, + ff_parse_close, +}; diff --git a/contrib/ffmpeg/libavcodec/h261data.h b/contrib/ffmpeg/libavcodec/h261data.h index 2a93b73e3..a86b6df98 100644 --- a/contrib/ffmpeg/libavcodec/h261data.h +++ b/contrib/ffmpeg/libavcodec/h261data.h @@ -23,7 +23,12 @@ * @file h261data.h * H.261 tables. */ -#define MB_TYPE_H261_FIL 0x800000 + +#ifndef FFMPEG_H261DATA_H +#define FFMPEG_H261DATA_H + +#include +#include "h261.h" // H.261 VLC table for macroblock addressing static const uint8_t h261_mba_code[35] = { @@ -155,3 +160,5 @@ static RLTable h261_rl_tcoeff = { h261_tcoeff_run, h261_tcoeff_level, }; + +#endif /* FFMPEG_H261DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/h261dec.c b/contrib/ffmpeg/libavcodec/h261dec.c new file mode 100644 index 000000000..264a7d3f5 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/h261dec.c @@ -0,0 +1,650 @@ +/* + * H261 decoder + * Copyright (c) 2002-2004 Michael Niedermayer + * Copyright (c) 2004 Maarten Daniels + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file h261dec.c + * H.261 decoder. + */ + +#include "dsputil.h" +#include "avcodec.h" +#include "mpegvideo.h" +#include "h261.h" +#include "h261data.h" + +#define H261_MBA_VLC_BITS 9 +#define H261_MTYPE_VLC_BITS 6 +#define H261_MV_VLC_BITS 7 +#define H261_CBP_VLC_BITS 9 +#define TCOEFF_VLC_BITS 9 +#define MBA_STUFFING 33 +#define MBA_STARTCODE 34 + +extern uint8_t ff_h261_rl_table_store[2][2*MAX_RUN + MAX_LEVEL + 3]; + +static VLC h261_mba_vlc; +static VLC h261_mtype_vlc; +static VLC h261_mv_vlc; +static VLC h261_cbp_vlc; + +static int h261_decode_block(H261Context * h, DCTELEM * block, int n, int coded); + +static void h261_decode_init_vlc(H261Context *h){ + static int done = 0; + + if(!done){ + done = 1; + init_vlc(&h261_mba_vlc, H261_MBA_VLC_BITS, 35, + h261_mba_bits, 1, 1, + h261_mba_code, 1, 1, 1); + init_vlc(&h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10, + h261_mtype_bits, 1, 1, + h261_mtype_code, 1, 1, 1); + init_vlc(&h261_mv_vlc, H261_MV_VLC_BITS, 17, + &h261_mv_tab[0][1], 2, 1, + &h261_mv_tab[0][0], 2, 1, 1); + init_vlc(&h261_cbp_vlc, H261_CBP_VLC_BITS, 63, + &h261_cbp_tab[0][1], 2, 1, + &h261_cbp_tab[0][0], 2, 1, 1); + init_rl(&h261_rl_tcoeff, ff_h261_rl_table_store); + init_vlc_rl(&h261_rl_tcoeff, 1); + } +} + +static int h261_decode_init(AVCodecContext *avctx){ + H261Context *h= avctx->priv_data; + MpegEncContext * const s = &h->s; + + // set defaults + MPV_decode_defaults(s); + s->avctx = avctx; + + s->width = s->avctx->coded_width; + s->height = s->avctx->coded_height; + s->codec_id = s->avctx->codec->id; + + s->out_format = FMT_H261; + s->low_delay= 1; + avctx->pix_fmt= PIX_FMT_YUV420P; + + s->codec_id= avctx->codec->id; + + h261_decode_init_vlc(h); + + h->gob_start_code_skipped = 0; + + return 0; +} + +/** + * decodes the group of blocks header or slice header. + * @return <0 if an error occured + */ +static int h261_decode_gob_header(H261Context *h){ + unsigned int val; + MpegEncContext * const s = &h->s; + + if ( !h->gob_start_code_skipped ){ + /* Check for GOB Start Code */ + val = show_bits(&s->gb, 15); + if(val) + return -1; + + /* We have a GBSC */ + skip_bits(&s->gb, 16); + } + + h->gob_start_code_skipped = 0; + + h->gob_number = get_bits(&s->gb, 4); /* GN */ + s->qscale = get_bits(&s->gb, 5); /* GQUANT */ + + /* Check if gob_number is valid */ + if (s->mb_height==18){ //cif + if ((h->gob_number<=0) || (h->gob_number>12)) + return -1; + } + else{ //qcif + if ((h->gob_number!=1) && (h->gob_number!=3) && (h->gob_number!=5)) + return -1; + } + + /* GEI */ + while (get_bits1(&s->gb) != 0) { + skip_bits(&s->gb, 8); + } + + if(s->qscale==0) + return -1; + + // For the first transmitted macroblock in a GOB, MBA is the absolute address. For + // subsequent macroblocks, MBA is the difference between the absolute addresses of + // the macroblock and the last transmitted macroblock. + h->current_mba = 0; + h->mba_diff = 0; + + return 0; +} + +/** + * decodes the group of blocks / video packet header. + * @return <0 if no resync found + */ +static int ff_h261_resync(H261Context *h){ + MpegEncContext * const s = &h->s; + int left, ret; + + if ( h->gob_start_code_skipped ){ + ret= h261_decode_gob_header(h); + if(ret>=0) + return 0; + } + else{ + if(show_bits(&s->gb, 15)==0){ + ret= h261_decode_gob_header(h); + if(ret>=0) + return 0; + } + //OK, it is not where it is supposed to be ... + s->gb= s->last_resync_gb; + align_get_bits(&s->gb); + left= s->gb.size_in_bits - get_bits_count(&s->gb); + + for(;left>15+1+4+5; left-=8){ + if(show_bits(&s->gb, 15)==0){ + GetBitContext bak= s->gb; + + ret= h261_decode_gob_header(h); + if(ret>=0) + return 0; + + s->gb= bak; + } + skip_bits(&s->gb, 8); + } + } + + return -1; +} + +/** + * decodes skipped macroblocks + * @return 0 + */ +static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2 ) +{ + MpegEncContext * const s = &h->s; + int i; + + s->mb_intra = 0; + + for(i=mba1; imb_x= ((h->gob_number-1) % 2) * 11 + i % 11; + s->mb_y= ((h->gob_number-1) / 2) * 3 + i / 11; + xy = s->mb_x + s->mb_y * s->mb_stride; + ff_init_block_index(s); + ff_update_block_index(s); + + for(j=0;j<6;j++) + s->block_last_index[j] = -1; + + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; + s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; + s->mv[0][0][0] = 0; + s->mv[0][0][1] = 0; + s->mb_skipped = 1; + h->mtype &= ~MB_TYPE_H261_FIL; + + MPV_decode_mb(s, s->block); + } + + return 0; +} + +static int decode_mv_component(GetBitContext *gb, int v){ + int mv_diff = get_vlc2(gb, h261_mv_vlc.table, H261_MV_VLC_BITS, 2); + + /* check if mv_diff is valid */ + if ( mv_diff < 0 ) + return v; + + mv_diff = mvmap[mv_diff]; + + if(mv_diff && !get_bits1(gb)) + mv_diff= -mv_diff; + + v += mv_diff; + if (v <=-16) v+= 32; + else if(v >= 16) v-= 32; + + return v; +} + +static int h261_decode_mb(H261Context *h){ + MpegEncContext * const s = &h->s; + int i, cbp, xy; + + cbp = 63; + // Read mba + do{ + h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc.table, H261_MBA_VLC_BITS, 2); + + /* Check for slice end */ + /* NOTE: GOB can be empty (no MB data) or exist only of MBA_stuffing */ + if (h->mba_diff == MBA_STARTCODE){ // start code + h->gob_start_code_skipped = 1; + return SLICE_END; + } + } + while( h->mba_diff == MBA_STUFFING ); // stuffing + + if ( h->mba_diff < 0 ){ + if ( get_bits_count(&s->gb) + 7 >= s->gb.size_in_bits ) + return SLICE_END; + + av_log(s->avctx, AV_LOG_ERROR, "illegal mba at %d %d\n", s->mb_x, s->mb_y); + return SLICE_ERROR; + } + + h->mba_diff += 1; + h->current_mba += h->mba_diff; + + if ( h->current_mba > MBA_STUFFING ) + return SLICE_ERROR; + + s->mb_x= ((h->gob_number-1) % 2) * 11 + ((h->current_mba-1) % 11); + s->mb_y= ((h->gob_number-1) / 2) * 3 + ((h->current_mba-1) / 11); + xy = s->mb_x + s->mb_y * s->mb_stride; + ff_init_block_index(s); + ff_update_block_index(s); + + // Read mtype + h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2); + h->mtype = h261_mtype_map[h->mtype]; + + // Read mquant + if ( IS_QUANT ( h->mtype ) ){ + ff_set_qscale(s, get_bits(&s->gb, 5)); + } + + s->mb_intra = IS_INTRA4x4(h->mtype); + + // Read mv + if ( IS_16X16 ( h->mtype ) ){ + // Motion vector data is included for all MC macroblocks. MVD is obtained from the macroblock vector by subtracting the + // vector of the preceding macroblock. For this calculation the vector of the preceding macroblock is regarded as zero in the + // following three situations: + // 1) evaluating MVD for macroblocks 1, 12 and 23; + // 2) evaluating MVD for macroblocks in which MBA does not represent a difference of 1; + // 3) MTYPE of the previous macroblock was not MC. + if ( ( h->current_mba == 1 ) || ( h->current_mba == 12 ) || ( h->current_mba == 23 ) || + ( h->mba_diff != 1)) + { + h->current_mv_x = 0; + h->current_mv_y = 0; + } + + h->current_mv_x= decode_mv_component(&s->gb, h->current_mv_x); + h->current_mv_y= decode_mv_component(&s->gb, h->current_mv_y); + }else{ + h->current_mv_x = 0; + h->current_mv_y = 0; + } + + // Read cbp + if ( HAS_CBP( h->mtype ) ){ + cbp = get_vlc2(&s->gb, h261_cbp_vlc.table, H261_CBP_VLC_BITS, 2) + 1; + } + + if(s->mb_intra){ + s->current_picture.mb_type[xy]= MB_TYPE_INTRA; + goto intra; + } + + //set motion vectors + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; + s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; + s->mv[0][0][0] = h->current_mv_x * 2;//gets divided by 2 in motion compensation + s->mv[0][0][1] = h->current_mv_y * 2; + +intra: + /* decode each block */ + if(s->mb_intra || HAS_CBP(h->mtype)){ + s->dsp.clear_blocks(s->block[0]); + for (i = 0; i < 6; i++) { + if (h261_decode_block(h, s->block[i], i, cbp&32) < 0){ + return SLICE_ERROR; + } + cbp+=cbp; + } + }else{ + for (i = 0; i < 6; i++) + s->block_last_index[i]= -1; + } + + MPV_decode_mb(s, s->block); + + return SLICE_OK; +} + +/** + * decodes a macroblock + * @return <0 if an error occured + */ +static int h261_decode_block(H261Context * h, DCTELEM * block, + int n, int coded) +{ + MpegEncContext * const s = &h->s; + int code, level, i, j, run; + RLTable *rl = &h261_rl_tcoeff; + const uint8_t *scan_table; + + // For the variable length encoding there are two code tables, one being used for + // the first transmitted LEVEL in INTER, INTER+MC and INTER+MC+FIL blocks, the second + // for all other LEVELs except the first one in INTRA blocks which is fixed length + // coded with 8 bits. + // NOTE: the two code tables only differ in one VLC so we handle that manually. + scan_table = s->intra_scantable.permutated; + if (s->mb_intra){ + /* DC coef */ + level = get_bits(&s->gb, 8); + // 0 (00000000b) and -128 (10000000b) are FORBIDDEN + if((level&0x7F) == 0){ + av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y); + return -1; + } + // The code 1000 0000 is not used, the reconstruction level of 1024 being coded as 1111 1111. + if (level == 255) + level = 128; + block[0] = level; + i = 1; + }else if(coded){ + // Run Level Code + // EOB Not possible for first level when cbp is available (that's why the table is different) + // 0 1 1s + // * * 0* + int check = show_bits(&s->gb, 2); + i = 0; + if ( check & 0x2 ){ + skip_bits(&s->gb, 2); + block[0] = ( check & 0x1 ) ? -1 : 1; + i = 1; + } + }else{ + i = 0; + } + if(!coded){ + s->block_last_index[n] = i - 1; + return 0; + } + for(;;){ + code = get_vlc2(&s->gb, rl->vlc.table, TCOEFF_VLC_BITS, 2); + if (code < 0){ + av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y); + return -1; + } + if (code == rl->n) { + /* escape */ + // The remaining combinations of (run, level) are encoded with a 20-bit word consisting of 6 bits escape, 6 bits run and 8 bits level. + run = get_bits(&s->gb, 6); + level = get_sbits(&s->gb, 8); + }else if(code == 0){ + break; + }else{ + run = rl->table_run[code]; + level = rl->table_level[code]; + if (get_bits1(&s->gb)) + level = -level; + } + i += run; + if (i >= 64){ + av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n", s->mb_x, s->mb_y); + return -1; + } + j = scan_table[i]; + block[j] = level; + i++; + } + s->block_last_index[n] = i-1; + return 0; +} + +/** + * decodes the H261 picture header. + * @return <0 if no startcode found + */ +static int h261_decode_picture_header(H261Context *h){ + MpegEncContext * const s = &h->s; + int format, i; + uint32_t startcode= 0; + + for(i= s->gb.size_in_bits - get_bits_count(&s->gb); i>24; i-=1){ + startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF; + + if(startcode == 0x10) + break; + } + + if (startcode != 0x10){ + av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); + return -1; + } + + /* temporal reference */ + i= get_bits(&s->gb, 5); /* picture timestamp */ + if(i < (s->picture_number&31)) + i += 32; + s->picture_number = (s->picture_number&~31) + i; + + s->avctx->time_base= (AVRational){1001, 30000}; + s->current_picture.pts= s->picture_number; + + + /* PTYPE starts here */ + skip_bits1(&s->gb); /* split screen off */ + skip_bits1(&s->gb); /* camera off */ + skip_bits1(&s->gb); /* freeze picture release off */ + + format = get_bits1(&s->gb); + + //only 2 formats possible + if (format == 0){//QCIF + s->width = 176; + s->height = 144; + s->mb_width = 11; + s->mb_height = 9; + }else{//CIF + s->width = 352; + s->height = 288; + s->mb_width = 22; + s->mb_height = 18; + } + + s->mb_num = s->mb_width * s->mb_height; + + skip_bits1(&s->gb); /* still image mode off */ + skip_bits1(&s->gb); /* Reserved */ + + /* PEI */ + while (get_bits1(&s->gb) != 0){ + skip_bits(&s->gb, 8); + } + + // h261 has no I-FRAMES, but if we pass I_TYPE for the first frame, the codec crashes if it does + // not contain all I-blocks (e.g. when a packet is lost) + s->pict_type = P_TYPE; + + h->gob_number = 0; + return 0; +} + +static int h261_decode_gob(H261Context *h){ + MpegEncContext * const s = &h->s; + + ff_set_qscale(s, s->qscale); + + /* decode mb's */ + while(h->current_mba <= MBA_STUFFING) + { + int ret; + /* DCT & quantize */ + ret= h261_decode_mb(h); + if(ret<0){ + if(ret==SLICE_END){ + h261_decode_mb_skipped(h, h->current_mba, 33); + return 0; + } + av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", s->mb_x + s->mb_y*s->mb_stride); + return -1; + } + + h261_decode_mb_skipped(h, h->current_mba-h->mba_diff, h->current_mba-1); + } + + return -1; +} + +/** + * returns the number of bytes consumed for building the current frame + */ +static int get_consumed_bytes(MpegEncContext *s, int buf_size){ + int pos= get_bits_count(&s->gb)>>3; + if(pos==0) pos=1; //avoid infinite loops (i doubt that is needed but ...) + if(pos+10>buf_size) pos=buf_size; // oops ;) + + return pos; +} + +static int h261_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size) +{ + H261Context *h= avctx->priv_data; + MpegEncContext *s = &h->s; + int ret; + AVFrame *pict = data; + +#ifdef DEBUG + av_log(avctx, AV_LOG_DEBUG, "*****frame %d size=%d\n", avctx->frame_number, buf_size); + av_log(avctx, AV_LOG_DEBUG, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]); +#endif + s->flags= avctx->flags; + s->flags2= avctx->flags2; + + h->gob_start_code_skipped=0; + +retry: + + init_get_bits(&s->gb, buf, buf_size*8); + + if(!s->context_initialized){ + if (MPV_common_init(s) < 0) //we need the idct permutaton for reading a custom matrix + return -1; + } + + //we need to set current_picture_ptr before reading the header, otherwise we cannot store anyting im there + if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){ + int i= ff_find_unused_picture(s, 0); + s->current_picture_ptr= &s->picture[i]; + } + + ret = h261_decode_picture_header(h); + + /* skip if the header was thrashed */ + if (ret < 0){ + av_log(s->avctx, AV_LOG_ERROR, "header damaged\n"); + return -1; + } + + if (s->width != avctx->coded_width || s->height != avctx->coded_height){ + ParseContext pc= s->parse_context; //FIXME move this demuxing hack to libavformat + s->parse_context.buffer=0; + MPV_common_end(s); + s->parse_context= pc; + } + if (!s->context_initialized) { + avcodec_set_dimensions(avctx, s->width, s->height); + + goto retry; + } + + // for hurry_up==5 + s->current_picture.pict_type= s->pict_type; + s->current_picture.key_frame= s->pict_type == I_TYPE; + + /* skip everything if we are in a hurry>=5 */ + if(avctx->hurry_up>=5) return get_consumed_bytes(s, buf_size); + if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE) + ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE) + || avctx->skip_frame >= AVDISCARD_ALL) + return get_consumed_bytes(s, buf_size); + + if(MPV_frame_start(s, avctx) < 0) + return -1; + + ff_er_frame_start(s); + + /* decode each macroblock */ + s->mb_x=0; + s->mb_y=0; + + while(h->gob_number < (s->mb_height==18 ? 12 : 5)){ + if(ff_h261_resync(h)<0) + break; + h261_decode_gob(h); + } + MPV_frame_end(s); + +assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type); +assert(s->current_picture.pict_type == s->pict_type); + *pict= *(AVFrame*)s->current_picture_ptr; + ff_print_debug_info(s, pict); + + *data_size = sizeof(AVFrame); + + return get_consumed_bytes(s, buf_size); +} + +static int h261_decode_end(AVCodecContext *avctx) +{ + H261Context *h= avctx->priv_data; + MpegEncContext *s = &h->s; + + MPV_common_end(s); + return 0; +} + +AVCodec h261_decoder = { + "h261", + CODEC_TYPE_VIDEO, + CODEC_ID_H261, + sizeof(H261Context), + h261_decode_init, + NULL, + h261_decode_end, + h261_decode_frame, + CODEC_CAP_DR1, +}; diff --git a/contrib/ffmpeg/libavcodec/h261enc.c b/contrib/ffmpeg/libavcodec/h261enc.c new file mode 100644 index 000000000..aea2549c7 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/h261enc.c @@ -0,0 +1,334 @@ +/* + * H261 encoder + * Copyright (c) 2002-2004 Michael Niedermayer + * Copyright (c) 2004 Maarten Daniels + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file h261enc.c + * H.261 encoder. + */ + +#include "dsputil.h" +#include "avcodec.h" +#include "mpegvideo.h" +#include "h261.h" +#include "h261data.h" + +extern uint8_t ff_h261_rl_table_store[2][2*MAX_RUN + MAX_LEVEL + 3]; + +static void h261_encode_block(H261Context * h, DCTELEM * block, + int n); + +int ff_h261_get_picture_format(int width, int height){ + // QCIF + if (width == 176 && height == 144) + return 0; + // CIF + else if (width == 352 && height == 288) + return 1; + // ERROR + else + return -1; +} + +void ff_h261_encode_picture_header(MpegEncContext * s, int picture_number){ + H261Context * h = (H261Context *) s; + int format, temp_ref; + + align_put_bits(&s->pb); + + /* Update the pointer to last GOB */ + s->ptr_lastgob = pbBufPtr(&s->pb); + + put_bits(&s->pb, 20, 0x10); /* PSC */ + + temp_ref= s->picture_number * (int64_t)30000 * s->avctx->time_base.num / + (1001 * (int64_t)s->avctx->time_base.den); //FIXME maybe this should use a timestamp + put_bits(&s->pb, 5, temp_ref & 0x1f); /* TemporalReference */ + + put_bits(&s->pb, 1, 0); /* split screen off */ + put_bits(&s->pb, 1, 0); /* camera off */ + put_bits(&s->pb, 1, 0); /* freeze picture release off */ + + format = ff_h261_get_picture_format(s->width, s->height); + + put_bits(&s->pb, 1, format); /* 0 == QCIF, 1 == CIF */ + + put_bits(&s->pb, 1, 0); /* still image mode */ + put_bits(&s->pb, 1, 0); /* reserved */ + + put_bits(&s->pb, 1, 0); /* no PEI */ + if(format == 0) + h->gob_number = -1; + else + h->gob_number = 0; + h->current_mba = 0; +} + +/** + * Encodes a group of blocks header. + */ +static void h261_encode_gob_header(MpegEncContext * s, int mb_line){ + H261Context * h = (H261Context *)s; + if(ff_h261_get_picture_format(s->width, s->height) == 0){ + h->gob_number+=2; // QCIF + } + else{ + h->gob_number++; // CIF + } + put_bits(&s->pb, 16, 1); /* GBSC */ + put_bits(&s->pb, 4, h->gob_number); /* GN */ + put_bits(&s->pb, 5, s->qscale); /* GQUANT */ + put_bits(&s->pb, 1, 0); /* no GEI */ + h->current_mba = 0; + h->previous_mba = 0; + h->current_mv_x=0; + h->current_mv_y=0; +} + +void ff_h261_reorder_mb_index(MpegEncContext* s){ + int index= s->mb_x + s->mb_y*s->mb_width; + + if(index % 33 == 0) + h261_encode_gob_header(s,0); + + /* for CIF the GOB's are fragmented in the middle of a scanline + that's why we need to adjust the x and y index of the macroblocks */ + if(ff_h261_get_picture_format(s->width,s->height) == 1){ // CIF + s->mb_x = index % 11 ; index /= 11; + s->mb_y = index % 3 ; index /= 3; + s->mb_x+= 11*(index % 2); index /= 2; + s->mb_y+= 3*index; + + ff_init_block_index(s); + ff_update_block_index(s); + } +} + +static void h261_encode_motion(H261Context * h, int val){ + MpegEncContext * const s = &h->s; + int sign, code; + if(val==0){ + code = 0; + put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]); + } + else{ + if(val > 15) + val -=32; + if(val < -16) + val+=32; + sign = val < 0; + code = sign ? -val : val; + put_bits(&s->pb,h261_mv_tab[code][1],h261_mv_tab[code][0]); + put_bits(&s->pb,1,sign); + } +} + +static inline int get_cbp(MpegEncContext * s, + DCTELEM block[6][64]) +{ + int i, cbp; + cbp= 0; + for (i = 0; i < 6; i++) { + if (s->block_last_index[i] >= 0) + cbp |= 1 << (5 - i); + } + return cbp; +} +void ff_h261_encode_mb(MpegEncContext * s, + DCTELEM block[6][64], + int motion_x, int motion_y) +{ + H261Context * h = (H261Context *)s; + int mvd, mv_diff_x, mv_diff_y, i, cbp; + cbp = 63; // avoid warning + mvd = 0; + + h->current_mba++; + h->mtype = 0; + + if (!s->mb_intra){ + /* compute cbp */ + cbp= get_cbp(s, block); + + /* mvd indicates if this block is motion compensated */ + mvd = motion_x | motion_y; + + if((cbp | mvd | s->dquant ) == 0) { + /* skip macroblock */ + s->skip_count++; + h->current_mv_x=0; + h->current_mv_y=0; + return; + } + } + + /* MB is not skipped, encode MBA */ + put_bits(&s->pb, h261_mba_bits[(h->current_mba-h->previous_mba)-1], h261_mba_code[(h->current_mba-h->previous_mba)-1]); + + /* calculate MTYPE */ + if(!s->mb_intra){ + h->mtype++; + + if(mvd || s->loop_filter) + h->mtype+=3; + if(s->loop_filter) + h->mtype+=3; + if(cbp || s->dquant) + h->mtype++; + assert(h->mtype > 1); + } + + if(s->dquant) + h->mtype++; + + put_bits(&s->pb, h261_mtype_bits[h->mtype], h261_mtype_code[h->mtype]); + + h->mtype = h261_mtype_map[h->mtype]; + + if(IS_QUANT(h->mtype)){ + ff_set_qscale(s,s->qscale+s->dquant); + put_bits(&s->pb, 5, s->qscale); + } + + if(IS_16X16(h->mtype)){ + mv_diff_x = (motion_x >> 1) - h->current_mv_x; + mv_diff_y = (motion_y >> 1) - h->current_mv_y; + h->current_mv_x = (motion_x >> 1); + h->current_mv_y = (motion_y >> 1); + h261_encode_motion(h,mv_diff_x); + h261_encode_motion(h,mv_diff_y); + } + + h->previous_mba = h->current_mba; + + if(HAS_CBP(h->mtype)){ + assert(cbp>0); + put_bits(&s->pb,h261_cbp_tab[cbp-1][1],h261_cbp_tab[cbp-1][0]); + } + for(i=0; i<6; i++) { + /* encode each block */ + h261_encode_block(h, block[i], i); + } + + if ( ( h->current_mba == 11 ) || ( h->current_mba == 22 ) || ( h->current_mba == 33 ) || ( !IS_16X16 ( h->mtype ) )){ + h->current_mv_x=0; + h->current_mv_y=0; + } +} + +void ff_h261_encode_init(MpegEncContext *s){ + static int done = 0; + + if (!done) { + done = 1; + init_rl(&h261_rl_tcoeff, ff_h261_rl_table_store); + } + + s->min_qcoeff= -127; + s->max_qcoeff= 127; + s->y_dc_scale_table= + s->c_dc_scale_table= ff_mpeg1_dc_scale_table; +} + + +/** + * encodes a 8x8 block. + * @param block the 8x8 block + * @param n block index (0-3 are luma, 4-5 are chroma) + */ +static void h261_encode_block(H261Context * h, DCTELEM * block, int n){ + MpegEncContext * const s = &h->s; + int level, run, last, i, j, last_index, last_non_zero, sign, slevel, code; + RLTable *rl; + + rl = &h261_rl_tcoeff; + if (s->mb_intra) { + /* DC coef */ + level = block[0]; + /* 255 cannot be represented, so we clamp */ + if (level > 254) { + level = 254; + block[0] = 254; + } + /* 0 cannot be represented also */ + else if (level < 1) { + level = 1; + block[0] = 1; + } + if (level == 128) + put_bits(&s->pb, 8, 0xff); + else + put_bits(&s->pb, 8, level); + i = 1; + } else if((block[0]==1 || block[0] == -1) && (s->block_last_index[n] > -1)){ + //special case + put_bits(&s->pb,2,block[0]>0 ? 2 : 3 ); + i = 1; + } else { + i = 0; + } + + /* AC coefs */ + last_index = s->block_last_index[n]; + last_non_zero = i - 1; + for (; i <= last_index; i++) { + j = s->intra_scantable.permutated[i]; + level = block[j]; + if (level) { + run = i - last_non_zero - 1; + last = (i == last_index); + sign = 0; + slevel = level; + if (level < 0) { + sign = 1; + level = -level; + } + code = get_rl_index(rl, 0 /*no last in H.261, EOB is used*/, run, level); + if(run==0 && level < 16) + code+=1; + put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); + if (code == rl->n) { + put_bits(&s->pb, 6, run); + assert(slevel != 0); + assert(level <= 127); + put_bits(&s->pb, 8, slevel & 0xff); + } else { + put_bits(&s->pb, 1, sign); + } + last_non_zero = i; + } + } + if(last_index > -1){ + put_bits(&s->pb, rl->table_vlc[0][1], rl->table_vlc[0][0]);// END OF BLOCK + } +} + +AVCodec h261_encoder = { + "h261", + CODEC_TYPE_VIDEO, + CODEC_ID_H261, + sizeof(H261Context), + MPV_encode_init, + MPV_encode_picture, + MPV_encode_end, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, +}; + diff --git a/contrib/ffmpeg/libavcodec/h263.c b/contrib/ffmpeg/libavcodec/h263.c index 4db89e970..6262c94da 100644 --- a/contrib/ffmpeg/libavcodec/h263.c +++ b/contrib/ffmpeg/libavcodec/h263.c @@ -5,6 +5,10 @@ * Copyright (c) 2001 Juan J. Sierralta P. * Copyright (c) 2002-2004 Michael Niedermayer * + * ac prediction encoding, B-frame support, error resilience, optimizations, + * qpel decoding, gmc decoding, interlaced decoding + * by Michael Niedermayer + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -20,10 +24,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * ac prediction encoding, b-frame support, error resilience, optimizations, - * qpel decoding, gmc decoding, interlaced decoding, - * by Michael Niedermayer */ /** @@ -34,7 +34,6 @@ //#define DEBUG #include -#include "common.h" #include "dsputil.h" #include "avcodec.h" #include "mpegvideo.h" @@ -139,6 +138,23 @@ int h263_get_picture_format(int width, int height) return format; } +static void show_pict_info(MpegEncContext *s){ + av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n", + s->qscale, av_get_pict_type_char(s->pict_type), + s->gb.size_in_bits, 1-s->no_rounding, + s->obmc ? " AP" : "", + s->umvplus ? " UMV" : "", + s->h263_long_vectors ? " LONG" : "", + s->h263_plus ? " +" : "", + s->h263_aic ? " AIC" : "", + s->alt_inter_vlc ? " AIV" : "", + s->modified_quant ? " MQ" : "", + s->loop_filter ? " LOOP" : "", + s->h263_slice_structured ? " SS" : "", + s->avctx->time_base.den, s->avctx->time_base.num + ); +} + #ifdef CONFIG_ENCODERS static void aspect_to_info(MpegEncContext * s, AVRational aspect){ @@ -213,7 +229,7 @@ void h263_encode_picture_header(MpegEncContext * s, int picture_number) for(i=0; i<2; i++){ int div, error; div= (s->avctx->time_base.num*1800000LL + 500LL*s->avctx->time_base.den) / ((1000LL+i)*s->avctx->time_base.den); - div= av_clip(1, div, 127); + div= av_clip(div, 1, 127); error= FFABS(s->avctx->time_base.num*1800000LL - (1000LL+i)*s->avctx->time_base.den*div); if(error < best_error){ best_error= error; @@ -894,7 +910,7 @@ void mpeg4_encode_mb(MpegEncContext * s, int i, cbp; if(s->pict_type==B_TYPE){ - static const int mb_type_table[8]= {-1, 2, 3, 1,-1,-1,-1, 0}; /* convert from mv_dir to type */ + static const int mb_type_table[8]= {-1, 3, 2, 1,-1,-1,-1, 0}; /* convert from mv_dir to type */ int mb_type= mb_type_table[s->mv_dir]; if(s->mb_x==0){ @@ -1836,9 +1852,6 @@ static void init_mv_penalty_and_fcode(MpegEncContext *s) umv_fcode_tab[mv]= 1; } } -#endif - -#ifdef CONFIG_ENCODERS static void init_uni_dc_tab(void) { @@ -1892,9 +1905,6 @@ static void init_uni_dc_tab(void) } } -#endif //CONFIG_ENCODERS - -#ifdef CONFIG_ENCODERS static void init_uni_mpeg4_rl_tab(RLTable *rl, uint32_t *bits_tab, uint8_t *len_tab){ int slevel, run, last; @@ -2243,9 +2253,6 @@ static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n) } } } -#endif - -#ifdef CONFIG_ENCODERS /***************************************************/ /** @@ -2260,25 +2267,12 @@ void ff_mpeg4_stuffing(PutBitContext * pbc) } /* must be called before writing the header */ -void ff_set_mpeg4_time(MpegEncContext * s, int picture_number){ - int time_div, time_mod; - - assert(s->current_picture_ptr->pts != AV_NOPTS_VALUE); - s->time= s->current_picture_ptr->pts*s->avctx->time_base.num; - - time_div= s->time/s->avctx->time_base.den; - time_mod= s->time%s->avctx->time_base.den; - +void ff_set_mpeg4_time(MpegEncContext * s){ if(s->pict_type==B_TYPE){ - s->pb_time= s->pp_time - (s->last_non_b_time - s->time); - assert(s->pb_time > 0 && s->pb_time < s->pp_time); ff_mpeg4_init_direct_mv(s); }else{ s->last_time_base= s->time_base; - s->time_base= time_div; - s->pp_time= s->time - s->last_non_b_time; - s->last_non_b_time= s->time; - assert(picture_number==0 || s->pp_time > 0); + s->time_base= s->time/s->avctx->time_base.den; } } @@ -2361,6 +2355,8 @@ static void mpeg4_encode_vol_header(MpegEncContext * s, int vo_number, int vol_n { int vo_ver_id; + if (!ENABLE_MPEG4_ENCODER) return; + if(s->max_b_frames || s->quarter_sample){ vo_ver_id= 5; s->vo_type= ADV_SIMPLE_VO_TYPE; @@ -2517,23 +2513,6 @@ void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number) #endif //CONFIG_ENCODERS -/** - * set qscale and update qscale dependent variables. - */ -void ff_set_qscale(MpegEncContext * s, int qscale) -{ - if (qscale < 1) - qscale = 1; - else if (qscale > 31) - qscale = 31; - - s->qscale = qscale; - s->chroma_qscale= s->chroma_qscale_table[qscale]; - - s->y_dc_scale= s->y_dc_scale_table[ qscale ]; - s->c_dc_scale= s->c_dc_scale_table[ s->chroma_qscale ]; -} - /** * predicts the dc. * encoding quantized level -> quantized diff @@ -2918,59 +2897,6 @@ static VLC mb_type_b_vlc; static VLC h263_mbtype_b_vlc; static VLC cbpc_b_vlc; -void init_vlc_rl(RLTable *rl, int use_static) -{ - int i, q; - - /* Return if static table is already initialized */ - if(use_static && rl->rl_vlc[0]) - return; - - init_vlc(&rl->vlc, 9, rl->n + 1, - &rl->table_vlc[0][1], 4, 2, - &rl->table_vlc[0][0], 4, 2, use_static); - - - for(q=0; q<32; q++){ - int qmul= q*2; - int qadd= (q-1)|1; - - if(q==0){ - qmul=1; - qadd=0; - } - if(use_static) - rl->rl_vlc[q]= av_mallocz_static(rl->vlc.table_size*sizeof(RL_VLC_ELEM)); - else - rl->rl_vlc[q]= av_malloc(rl->vlc.table_size*sizeof(RL_VLC_ELEM)); - for(i=0; ivlc.table_size; i++){ - int code= rl->vlc.table[i][0]; - int len = rl->vlc.table[i][1]; - int level, run; - - if(len==0){ // illegal code - run= 66; - level= MAX_LEVEL; - }else if(len<0){ //more bits needed - run= 0; - level= code; - }else{ - if(code==rl->n){ //esc - run= 66; - level= 0; - }else{ - run= rl->table_run [code] + 1; - level= rl->table_level[code] * qmul + qadd; - if(code >= rl->last) run+=192; - } - } - rl->rl_vlc[q][i].len= len; - rl->rl_vlc[q][i].level= level; - rl->rl_vlc[q][i].run= run; - } - } -} - /* init vlcs */ /* XXX: find a better solution to handle static init */ @@ -3387,7 +3313,7 @@ int ff_h263_resync(MpegEncContext *s){ if(ret>=0) return 0; } - //ok, it's not where its supposed to be ... + //OK, it's not where it is supposed to be ... s->gb= s->last_resync_gb; align_get_bits(&s->gb); left= s->gb.size_in_bits - get_bits_count(&s->gb); @@ -4721,7 +4647,7 @@ retry: i += run; if (i >= 64){ if(s->alt_inter_vlc && rl == &rl_inter && !s->mb_intra){ - //looks like a hack but no, it's the way its supposed to work ... + //Looks like a hack but no, it's the way it is supposed to work ... rl = &rl_intra_aic; i = 0; s->gb= gb; @@ -4828,26 +4754,26 @@ static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, i = -1; ff_mpeg4_pred_dc(s, n, 0, &dc_pred_dir, 0); } - if (!coded) - goto not_coded; + if (!coded) + goto not_coded; - if(rvlc){ - rl = &rvlc_rl_intra; - rl_vlc = rvlc_rl_intra.rl_vlc[0]; - }else{ - rl = &rl_intra; - rl_vlc = rl_intra.rl_vlc[0]; - } - if (s->ac_pred) { - if (dc_pred_dir == 0) - scan_table = s->intra_v_scantable.permutated; /* left */ - else - scan_table = s->intra_h_scantable.permutated; /* top */ - } else { + if(rvlc){ + rl = &rvlc_rl_intra; + rl_vlc = rvlc_rl_intra.rl_vlc[0]; + }else{ + rl = &rl_intra; + rl_vlc = rl_intra.rl_vlc[0]; + } + if (s->ac_pred) { + if (dc_pred_dir == 0) + scan_table = s->intra_v_scantable.permutated; /* left */ + else + scan_table = s->intra_h_scantable.permutated; /* top */ + } else { scan_table = s->intra_scantable.permutated; - } - qmul=1; - qadd=0; + } + qmul=1; + qadd=0; } else { i = -1; if (!coded) { @@ -5142,7 +5068,7 @@ int h263_decode_picture_header(MpegEncContext *s) format = get_bits(&s->gb, 3); dprintf(s->avctx, "ufep=1, format: %d\n", format); s->custom_pcf= get_bits1(&s->gb); - s->umvplus = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */ + s->umvplus = get_bits1(&s->gb); /* Unrestricted Motion Vector */ if (get_bits1(&s->gb) != 0) { av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n"); } @@ -5294,20 +5220,7 @@ int h263_decode_picture_header(MpegEncContext *s) } if(s->avctx->debug&FF_DEBUG_PICT_INFO){ - av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n", - s->qscale, av_get_pict_type_char(s->pict_type), - s->gb.size_in_bits, 1-s->no_rounding, - s->obmc ? " AP" : "", - s->umvplus ? " UMV" : "", - s->h263_long_vectors ? " LONG" : "", - s->h263_plus ? " +" : "", - s->h263_aic ? " AIC" : "", - s->alt_inter_vlc ? " AIV" : "", - s->modified_quant ? " MQ" : "", - s->loop_filter ? " LOOP" : "", - s->h263_slice_structured ? " SS" : "", - s->avctx->time_base.den, s->avctx->time_base.num - ); + show_pict_info(s); } #if 1 if (s->pict_type == I_TYPE && s->codec_tag == ff_get_fourcc("ZYGO")){ @@ -5665,6 +5578,11 @@ static int decode_vol_header(MpegEncContext *s, GetBitContext *gb){ skip_bits1(gb); /* marker */ } s->num_sprite_warping_points= get_bits(gb, 6); + if(s->num_sprite_warping_points > 3){ + av_log(s->avctx, AV_LOG_ERROR, "%d sprite_warping_points\n", s->num_sprite_warping_points); + s->num_sprite_warping_points= 0; + return -1; + } s->sprite_warping_accuracy = get_bits(gb, 2); s->sprite_brightness_change= get_bits1(gb); if(s->vol_sprite_usage==STATIC_SPRITE) @@ -6197,11 +6115,7 @@ int intel_h263_decode_picture_header(MpegEncContext *s) av_log(s->avctx, AV_LOG_ERROR, "SAC not supported\n"); return -1; /* SAC: off */ } - if (get_bits1(&s->gb) != 0) { - s->obmc= 1; - av_log(s->avctx, AV_LOG_ERROR, "Advanced Prediction Mode not supported\n"); -// return -1; /* advanced prediction mode: off */ - } + s->obmc= get_bits1(&s->gb); if (get_bits1(&s->gb) != 0) { av_log(s->avctx, AV_LOG_ERROR, "PB frame mode no supported\n"); return -1; /* PB frame mode */ @@ -6222,6 +6136,9 @@ int intel_h263_decode_picture_header(MpegEncContext *s) s->y_dc_scale_table= s->c_dc_scale_table= ff_mpeg1_dc_scale_table; + if(s->avctx->debug&FF_DEBUG_PICT_INFO) + show_pict_info(s); + return 0; } diff --git a/contrib/ffmpeg/libavcodec/h263.h b/contrib/ffmpeg/libavcodec/h263.h new file mode 100644 index 000000000..47b168b54 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/h263.h @@ -0,0 +1,46 @@ +/* + * H263/MPEG4 backend for ffmpeg encoder and decoder + * copyright (c) 2007 Aurelien Jacobs + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_H263_H +#define FFMPEG_H263_H + +#include "config.h" +#include "msmpeg4.h" + +#define ENABLE_ANY_H263_DECODER (ENABLE_H263_DECODER || \ + ENABLE_H263I_DECODER || \ + ENABLE_FLV_DECODER || \ + ENABLE_RV10_DECODER || \ + ENABLE_RV20_DECODER || \ + ENABLE_MPEG4_DECODER || \ + ENABLE_MSMPEG4_DECODER || \ + ENABLE_WMV_DECODER) +#define ENABLE_ANY_H263_ENCODER (ENABLE_H263_ENCODER || \ + ENABLE_H263P_ENCODER || \ + ENABLE_FLV_ENCODER || \ + ENABLE_RV10_ENCODER || \ + ENABLE_RV20_ENCODER || \ + ENABLE_MPEG4_ENCODER || \ + ENABLE_MSMPEG4_ENCODER || \ + ENABLE_WMV_ENCODER) +#define ENABLE_ANY_H263 (ENABLE_ANY_H263_DECODER || ENABLE_ANY_H263_ENCODER) + +#endif /* FFMPEG_H263_H */ diff --git a/contrib/ffmpeg/libavcodec/h263_parser.c b/contrib/ffmpeg/libavcodec/h263_parser.c new file mode 100644 index 000000000..bfef3b5bb --- /dev/null +++ b/contrib/ffmpeg/libavcodec/h263_parser.c @@ -0,0 +1,91 @@ +/* + * H.263 parser + * Copyright (c) 2002-2004 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file h263_parser.c + * H.263 parser + */ + +#include "parser.h" + +int ff_h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){ + int vop_found, i; + uint32_t state; + + vop_found= pc->frame_start_found; + state= pc->state; + + i=0; + if(!vop_found){ + for(i=0; i>(32-22) == 0x20){ + i++; + vop_found=1; + break; + } + } + } + + if(vop_found){ + for(; i>(32-22) == 0x20){ + pc->frame_start_found=0; + pc->state=-1; + return i-3; + } + } + } + pc->frame_start_found= vop_found; + pc->state= state; + + return END_NOT_FOUND; +} + +static int h263_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + ParseContext *pc = s->priv_data; + int next; + + next= ff_h263_find_frame_end(pc, buf, buf_size); + + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + + *poutbuf = buf; + *poutbuf_size = buf_size; + return next; +} + +AVCodecParser h263_parser = { + { CODEC_ID_H263 }, + sizeof(ParseContext), + NULL, + h263_parse, + ff_parse_close, +}; diff --git a/contrib/ffmpeg/libavcodec/h263_parser.h b/contrib/ffmpeg/libavcodec/h263_parser.h new file mode 100644 index 000000000..dc5077451 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/h263_parser.h @@ -0,0 +1,29 @@ +/* + * H.263 parser + * Copyright (c) 2002-2004 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_H263_PARSER_H +#define FFMPEG_H263_PARSER_H + +#include "parser.h" + +int ff_h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size); + +#endif /* FFMPEG_H263_PARSER_H */ diff --git a/contrib/ffmpeg/libavcodec/h263data.h b/contrib/ffmpeg/libavcodec/h263data.h index 5eddc3b54..b6c1c163c 100644 --- a/contrib/ffmpeg/libavcodec/h263data.h +++ b/contrib/ffmpeg/libavcodec/h263data.h @@ -26,6 +26,11 @@ * H.263 tables. */ +#ifndef FFMPEG_H263DATA_H +#define FFMPEG_H263DATA_H + +#include +#include "mpegvideo.h" /* intra MCBPC, mb_type = (intra), then (intraq) */ const uint8_t intra_MCBPC_code[9] = { 1, 1, 2, 3, 1, 1, 2, 3, 1 }; @@ -306,3 +311,4 @@ const uint8_t ff_h263_loop_filter_strength[32]={ 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,11,12,12,12 }; +#endif /* FFMPEG_H263DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/h263dec.c b/contrib/ffmpeg/libavcodec/h263dec.c index b385f84cd..eddaadc83 100644 --- a/contrib/ffmpeg/libavcodec/h263dec.c +++ b/contrib/ffmpeg/libavcodec/h263dec.c @@ -28,6 +28,9 @@ #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" +#include "h263_parser.h" +#include "mpeg4video_parser.h" +#include "msmpeg4.h" //#define DEBUG //#define PRINT_FRAME_TIME @@ -108,7 +111,7 @@ int ff_h263_decode_init(AVCodecContext *avctx) if (MPV_common_init(s) < 0) return -1; - if (s->h263_msmpeg4) + if (ENABLE_MSMPEG4_DECODER && s->h263_msmpeg4) ff_msmpeg4_decode_init(s); else h263_decode_init_vlc(s); @@ -138,7 +141,7 @@ static int get_consumed_bytes(MpegEncContext *s, int buf_size){ if(pos<0) pos=0; // padding is not really read so this might be -1 return pos; }else{ - if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...) + if(pos==0) pos=1; //avoid infinite loops (i doubt that is needed but ...) if(pos+10>buf_size) pos=buf_size; // oops ;) return pos; @@ -317,108 +320,9 @@ static int decode_slice(MpegEncContext *s){ return -1; } -/** - * finds the end of the current frame in the bitstream. - * @return the position of the first byte of the next frame, or -1 - */ -int ff_mpeg4_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){ - int vop_found, i; - uint32_t state; - - vop_found= pc->frame_start_found; - state= pc->state; - - i=0; - if(!vop_found){ - for(i=0; iframe_start_found=0; - pc->state=-1; - return i-3; - } - } - } - pc->frame_start_found= vop_found; - pc->state= state; - return END_NOT_FOUND; -} - -static int h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){ - int vop_found, i; - uint32_t state; - - vop_found= pc->frame_start_found; - state= pc->state; - - i=0; - if(!vop_found){ - for(i=0; i>(32-22) == 0x20){ - i++; - vop_found=1; - break; - } - } - } - - if(vop_found){ - for(; i>(32-22) == 0x20){ - pc->frame_start_found=0; - pc->state=-1; - return i-3; - } - } - } - pc->frame_start_found= vop_found; - pc->state= state; - - return END_NOT_FOUND; -} - -#ifdef CONFIG_H263_PARSER -static int h263_parse(AVCodecParserContext *s, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - ParseContext *pc = s->priv_data; - int next; - - next= h263_find_frame_end(pc, buf, buf_size); - - if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { - *poutbuf = NULL; - *poutbuf_size = 0; - return buf_size; - } - - *poutbuf = (uint8_t *)buf; - *poutbuf_size = buf_size; - return next; -} -#endif - int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { MpegEncContext *s = avctx->priv_data; int ret; @@ -454,13 +358,13 @@ uint64_t time= rdtsc(); if(s->codec_id==CODEC_ID_MPEG4){ next= ff_mpeg4_find_frame_end(&s->parse_context, buf, buf_size); }else if(s->codec_id==CODEC_ID_H263){ - next= h263_find_frame_end(&s->parse_context, buf, buf_size); + next= ff_h263_find_frame_end(&s->parse_context, buf, buf_size); }else{ av_log(s->avctx, AV_LOG_ERROR, "this codec does not support truncated bitstreams\n"); return -1; } - if( ff_combine_frame(&s->parse_context, next, &buf, &buf_size) < 0 ) + if( ff_combine_frame(&s->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 ) return buf_size; } @@ -478,16 +382,17 @@ retry: return -1; } - //we need to set current_picture_ptr before reading the header, otherwise we cant store anyting im there + /* We need to set current_picture_ptr before reading the header, + * otherwise we cannot store anyting in there */ if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){ int i= ff_find_unused_picture(s, 0); s->current_picture_ptr= &s->picture[i]; } /* let's go :-) */ - if (s->msmpeg4_version==5) { + if (ENABLE_WMV2_DECODER && s->msmpeg4_version==5) { ret= ff_wmv2_decode_picture_header(s); - } else if (s->msmpeg4_version) { + } else if (ENABLE_MSMPEG4_DECODER && s->msmpeg4_version) { ret = msmpeg4_decode_picture_header(s); } else if (s->h263_pred) { if(s->avctx->extradata_size && s->picture_number==0){ @@ -548,11 +453,11 @@ retry: s->workaround_bugs|= FF_BUG_UMP4; } - if(s->divx_version>=500){ + if(s->divx_version>=500 && s->divx_build<1814){ s->workaround_bugs|= FF_BUG_QPEL_CHROMA; } - if(s->divx_version>502){ + if(s->divx_version>502 && s->divx_build<1814){ s->workaround_bugs|= FF_BUG_QPEL_CHROMA2; } @@ -717,10 +622,11 @@ retry: ff_er_frame_start(s); //the second part of the wmv2 header contains the MB skip bits which are stored in current_picture->mb_type - //which isnt available before MPV_frame_start() - if (s->msmpeg4_version==5){ - if(ff_wmv2_decode_secondary_picture_header(s) < 0) - return -1; + //which is not available before MPV_frame_start() + if (ENABLE_WMV2_DECODER && s->msmpeg4_version==5){ + ret = ff_wmv2_decode_secondary_picture_header(s); + if(ret<0) return ret; + if(ret==1) goto intrax8_decoded; } /* decode each macroblock */ @@ -744,7 +650,7 @@ retry: } if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==I_TYPE) - if(msmpeg4_decode_ext_header(s, buf_size) < 0){ + if(!ENABLE_MSMPEG4_DECODER || msmpeg4_decode_ext_header(s, buf_size) < 0){ s->error_status_table[s->mb_num-1]= AC_ERROR|DC_ERROR|MV_ERROR; } @@ -777,6 +683,7 @@ retry: } } +intrax8_decoded: ff_er_frame_end(s); MPV_frame_end(s); @@ -795,7 +702,7 @@ assert(s->current_picture.pict_type == s->pict_type); } /* Return the Picture timestamp as the frame number */ - /* we substract 1 because it is added on utils.c */ + /* we subtract 1 because it is added on utils.c */ avctx->frame_number = s->picture_number - 1; #ifdef PRINT_FRAME_TIME @@ -902,13 +809,3 @@ AVCodec flv_decoder = { ff_h263_decode_frame, CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 }; - -#ifdef CONFIG_H263_PARSER -AVCodecParser h263_parser = { - { CODEC_ID_H263 }, - sizeof(ParseContext), - NULL, - h263_parse, - ff_parse_close, -}; -#endif diff --git a/contrib/ffmpeg/libavcodec/h264.c b/contrib/ffmpeg/libavcodec/h264.c index 4d72dc2ff..cd6facb9b 100644 --- a/contrib/ffmpeg/libavcodec/h264.c +++ b/contrib/ffmpeg/libavcodec/h264.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -26,367 +25,25 @@ * @author Michael Niedermayer */ -#include "common.h" #include "dsputil.h" #include "avcodec.h" #include "mpegvideo.h" +#include "h264.h" #include "h264data.h" +#include "h264_parser.h" #include "golomb.h" +#include "rectangle.h" #include "cabac.h" //#undef NDEBUG #include -#define interlaced_dct interlaced_dct_is_a_bad_name -#define mb_intra mb_intra_isnt_initalized_see_mb_type - -#define LUMA_DC_BLOCK_INDEX 25 -#define CHROMA_DC_BLOCK_INDEX 26 - -#define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8 -#define COEFF_TOKEN_VLC_BITS 8 -#define TOTAL_ZEROS_VLC_BITS 9 -#define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3 -#define RUN_VLC_BITS 3 -#define RUN7_VLC_BITS 6 - -#define MAX_SPS_COUNT 32 -#define MAX_PPS_COUNT 256 - -#define MAX_MMCO_COUNT 66 - -/* Compiling in interlaced support reduces the speed - * of progressive decoding by about 2%. */ -#define ALLOW_INTERLACE - -#ifdef ALLOW_INTERLACE -#define MB_MBAFF h->mb_mbaff -#define MB_FIELD h->mb_field_decoding_flag -#define FRAME_MBAFF h->mb_aff_frame -#else -#define MB_MBAFF 0 -#define MB_FIELD 0 -#define FRAME_MBAFF 0 -#undef IS_INTERLACED -#define IS_INTERLACED(mb_type) 0 -#endif - /** - * Sequence parameter set + * Value of Picture.reference when Picture is not a reference picture, but + * is held for delayed output. */ -typedef struct SPS{ - - int profile_idc; - int level_idc; - int transform_bypass; ///< qpprime_y_zero_transform_bypass_flag - int log2_max_frame_num; ///< log2_max_frame_num_minus4 + 4 - int poc_type; ///< pic_order_cnt_type - int log2_max_poc_lsb; ///< log2_max_pic_order_cnt_lsb_minus4 - int delta_pic_order_always_zero_flag; - int offset_for_non_ref_pic; - int offset_for_top_to_bottom_field; - int poc_cycle_length; ///< num_ref_frames_in_pic_order_cnt_cycle - int ref_frame_count; ///< num_ref_frames - int gaps_in_frame_num_allowed_flag; - int mb_width; ///< frame_width_in_mbs_minus1 + 1 - int mb_height; ///< frame_height_in_mbs_minus1 + 1 - int frame_mbs_only_flag; - int mb_aff; ///b4_stride - int b8_stride; - - int mb_linesize; ///< may be equal to s->linesize or s->linesize*2, for mbaff - int mb_uvlinesize; - - int emu_edge_width; - int emu_edge_height; - - int halfpel_flag; - int thirdpel_flag; - - int unknown_svq3_flag; - int next_slice_index; - - SPS sps_buffer[MAX_SPS_COUNT]; - SPS sps; ///< current sps - - PPS pps_buffer[MAX_PPS_COUNT]; - /** - * current pps - */ - PPS pps; //FIXME move to Picture perhaps? (->no) do we need that? - - uint32_t dequant4_buffer[6][52][16]; - uint32_t dequant8_buffer[2][52][64]; - uint32_t (*dequant4_coeff[6])[16]; - uint32_t (*dequant8_coeff[2])[64]; - int dequant_coeff_pps; ///< reinit tables when pps changes - - int slice_num; - uint8_t *slice_table_base; - uint8_t *slice_table; ///< slice_table_base + 2*mb_stride + 1 - int slice_type; - int slice_type_fixed; - - //interlacing specific flags - int mb_aff_frame; - int mb_field_decoding_flag; - int mb_mbaff; ///< mb_aff_frame && mb_field_decoding_flag - - unsigned int sub_mb_type[4]; - - //POC stuff - int poc_lsb; - int poc_msb; - int delta_poc_bottom; - int delta_poc[2]; - int frame_num; - int prev_poc_msb; ///< poc_msb of the last reference pic for POC type 0 - int prev_poc_lsb; ///< poc_lsb of the last reference pic for POC type 0 - int frame_num_offset; ///< for POC type 2 - int prev_frame_num_offset; ///< for POC type 2 - int prev_frame_num; ///< frame_num of the last pic for POC type 1/2 - - /** - * frame_num for frames or 2*frame_num for field pics. - */ - int curr_pic_num; - - /** - * max_frame_num or 2*max_frame_num for field pics. - */ - int max_pic_num; - - //Weighted pred stuff - int use_weight; - int use_weight_chroma; - int luma_log2_weight_denom; - int chroma_log2_weight_denom; - int luma_weight[2][48]; - int luma_offset[2][48]; - int chroma_weight[2][48][2]; - int chroma_offset[2][48][2]; - int implicit_weight[48][48]; - - //deblock - int deblocking_filter; ///< disable_deblocking_filter_idc with 1<->0 - int slice_alpha_c0_offset; - int slice_beta_offset; - - int redundant_pic_count; - - int direct_spatial_mv_pred; - int dist_scale_factor[16]; - int dist_scale_factor_field[32]; - int map_col_to_list0[2][16]; - int map_col_to_list0_field[2][32]; - - /** - * num_ref_idx_l0/1_active_minus1 + 1 - */ - unsigned int ref_count[2]; ///< counts frames or fields, depending on current mb mode - unsigned int list_count; - Picture *short_ref[32]; - Picture *long_ref[32]; - Picture default_ref_list[2][32]; - Picture ref_list[2][48]; ///< 0..15: frame refs, 16..47: mbaff field refs - Picture *delayed_pic[18]; //FIXME size? - Picture *delayed_output_pic; - - /** - * memory management control operations buffer. - */ - MMCO mmco[MAX_MMCO_COUNT]; - int mmco_index; - - int long_ref_count; ///< number of actual long term references - int short_ref_count; ///< number of actual short term references - - //data partitioning - GetBitContext intra_gb; - GetBitContext inter_gb; - GetBitContext *intra_gb_ptr; - GetBitContext *inter_gb_ptr; - - DECLARE_ALIGNED_8(DCTELEM, mb[16*24]); - DCTELEM mb_padding[256]; ///< as mb is addressed by scantable[i] and scantable is uint8_t we can either check that i is not to large or ensure that there is some unused stuff after mb - - /** - * Cabac - */ - CABACContext cabac; - uint8_t cabac_state[460]; - int cabac_init_idc; - - /* 0x100 -> non null luma_dc, 0x80/0x40 -> non null chroma_dc (cb/cr), 0x?0 -> chroma_cbp(0,1,2), 0x0? luma_cbp */ - uint16_t *cbp_table; - int cbp; - int top_cbp; - int left_cbp; - /* chroma_pred_mode for i4x4 or i16x16, else 0 */ - uint8_t *chroma_pred_mode_table; - int last_qscale_diff; - int16_t (*mvd_table[2])[2]; - DECLARE_ALIGNED_8(int16_t, mvd_cache[2][5*8][2]); - uint8_t *direct_table; - uint8_t direct_cache[5*8]; - - uint8_t zigzag_scan[16]; - uint8_t zigzag_scan8x8[64]; - uint8_t zigzag_scan8x8_cavlc[64]; - uint8_t field_scan[16]; - uint8_t field_scan8x8[64]; - uint8_t field_scan8x8_cavlc[64]; - const uint8_t *zigzag_scan_q0; - const uint8_t *zigzag_scan8x8_q0; - const uint8_t *zigzag_scan8x8_cavlc_q0; - const uint8_t *field_scan_q0; - const uint8_t *field_scan8x8_q0; - const uint8_t *field_scan8x8_cavlc_q0; - - int x264_build; -}H264Context; +#define DELAYED_PIC_REF 4 static VLC coeff_token_vlc[4]; static VLC chroma_dc_coeff_token_vlc; @@ -419,109 +76,23 @@ const uint8_t ff_div6[52]={ }; -/** - * fill a rectangle. - * @param h height of the rectangle, should be a constant - * @param w width of the rectangle, should be a constant - * @param size the size of val (1 or 4), should be a constant - */ -static av_always_inline void fill_rectangle(void *vp, int w, int h, int stride, uint32_t val, int size){ - uint8_t *p= (uint8_t*)vp; - assert(size==1 || size==4); - assert(w<=4); - - w *= size; - stride *= size; - - assert((((long)vp)&(FFMIN(w, STRIDE_ALIGN)-1)) == 0); - assert((stride&(w-1))==0); - if(w==2){ - const uint16_t v= size==4 ? val : val*0x0101; - *(uint16_t*)(p + 0*stride)= v; - if(h==1) return; - *(uint16_t*)(p + 1*stride)= v; - if(h==2) return; - *(uint16_t*)(p + 2*stride)= - *(uint16_t*)(p + 3*stride)= v; - }else if(w==4){ - const uint32_t v= size==4 ? val : val*0x01010101; - *(uint32_t*)(p + 0*stride)= v; - if(h==1) return; - *(uint32_t*)(p + 1*stride)= v; - if(h==2) return; - *(uint32_t*)(p + 2*stride)= - *(uint32_t*)(p + 3*stride)= v; - }else if(w==8){ - //gcc can't optimize 64bit math on x86_32 -#if defined(ARCH_X86_64) || (defined(MP_WORDSIZE) && MP_WORDSIZE >= 64) - const uint64_t v= val*0x0100000001ULL; - *(uint64_t*)(p + 0*stride)= v; - if(h==1) return; - *(uint64_t*)(p + 1*stride)= v; - if(h==2) return; - *(uint64_t*)(p + 2*stride)= - *(uint64_t*)(p + 3*stride)= v; - }else if(w==16){ - const uint64_t v= val*0x0100000001ULL; - *(uint64_t*)(p + 0+0*stride)= - *(uint64_t*)(p + 8+0*stride)= - *(uint64_t*)(p + 0+1*stride)= - *(uint64_t*)(p + 8+1*stride)= v; - if(h==2) return; - *(uint64_t*)(p + 0+2*stride)= - *(uint64_t*)(p + 8+2*stride)= - *(uint64_t*)(p + 0+3*stride)= - *(uint64_t*)(p + 8+3*stride)= v; -#else - *(uint32_t*)(p + 0+0*stride)= - *(uint32_t*)(p + 4+0*stride)= val; - if(h==1) return; - *(uint32_t*)(p + 0+1*stride)= - *(uint32_t*)(p + 4+1*stride)= val; - if(h==2) return; - *(uint32_t*)(p + 0+2*stride)= - *(uint32_t*)(p + 4+2*stride)= - *(uint32_t*)(p + 0+3*stride)= - *(uint32_t*)(p + 4+3*stride)= val; - }else if(w==16){ - *(uint32_t*)(p + 0+0*stride)= - *(uint32_t*)(p + 4+0*stride)= - *(uint32_t*)(p + 8+0*stride)= - *(uint32_t*)(p +12+0*stride)= - *(uint32_t*)(p + 0+1*stride)= - *(uint32_t*)(p + 4+1*stride)= - *(uint32_t*)(p + 8+1*stride)= - *(uint32_t*)(p +12+1*stride)= val; - if(h==2) return; - *(uint32_t*)(p + 0+2*stride)= - *(uint32_t*)(p + 4+2*stride)= - *(uint32_t*)(p + 8+2*stride)= - *(uint32_t*)(p +12+2*stride)= - *(uint32_t*)(p + 0+3*stride)= - *(uint32_t*)(p + 4+3*stride)= - *(uint32_t*)(p + 8+3*stride)= - *(uint32_t*)(p +12+3*stride)= val; -#endif - }else - assert(0); - assert(h==4); -} - static void fill_caches(H264Context *h, int mb_type, int for_deblock){ MpegEncContext * const s = &h->s; const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; int topleft_xy, top_xy, topright_xy, left_xy[2]; int topleft_type, top_type, topright_type, left_type[2]; int left_block[8]; + int topleft_partition= -1; int i; + top_xy = mb_xy - (s->mb_stride << FIELD_PICTURE); + //FIXME deblocking could skip the intra and nnz parts. - if(for_deblock && (h->slice_num == 1 || h->slice_table[mb_xy] == h->slice_table[mb_xy-s->mb_stride]) && !FRAME_MBAFF) + if(for_deblock && (h->slice_num == 1 || h->slice_table[mb_xy] == h->slice_table[top_xy]) && !FRAME_MBAFF) return; //wow what a mess, why didn't they simplify the interlacing&intra stuff, i can't imagine that these complex rules are worth it - top_xy = mb_xy - s->mb_stride; topleft_xy = top_xy - 1; topright_xy= top_xy + 1; left_xy[1] = left_xy[0] = mb_xy-1; @@ -556,6 +127,10 @@ static void fill_caches(H264Context *h, int mb_type, int for_deblock){ : (!curr_mb_frame_flag && !topleft_mb_frame_flag) // top macroblock ) { topleft_xy -= s->mb_stride; + } else if(bottom && curr_mb_frame_flag && !left_mb_frame_flag) { + topleft_xy += s->mb_stride; + // take topleft mv from the middle of the mb, as opposed to all other modes which use the bottom-right partition + topleft_partition = 0; } if (bottom ? !curr_mb_frame_flag // bottom macroblock @@ -833,8 +408,8 @@ static void fill_caches(H264Context *h, int mb_type, int for_deblock){ continue; if(USES_LIST(topleft_type, list)){ - const int b_xy = h->mb2b_xy[topleft_xy] + 3 + 3*h->b_stride; - const int b8_xy= h->mb2b8_xy[topleft_xy] + 1 + h->b8_stride; + const int b_xy = h->mb2b_xy[topleft_xy] + 3 + h->b_stride + (topleft_partition & 2*h->b_stride); + const int b8_xy= h->mb2b8_xy[topleft_xy] + 1 + (topleft_partition & h->b8_stride); *(uint32_t*)h->mv_cache[list][scan8[0] - 1 - 1*8]= *(uint32_t*)s->current_picture.motion_val[list][b_xy]; h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy]; }else{ @@ -1131,7 +706,7 @@ static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, in #define SET_DIAG_MV(MV_OP, REF_OP, X4, Y4)\ const int x4 = X4, y4 = Y4;\ const int mb_type = mb_types[(x4>>2)+(y4>>2)*s->mb_stride];\ - if(!USES_LIST(mb_type,list) && !IS_8X8(mb_type))\ + if(!USES_LIST(mb_type,list))\ return LIST_NOT_USED;\ mv = s->current_picture_ptr->motion_val[list][x4 + y4*h->b_stride];\ h->mv_cache[list][scan8[0]-2][0] = mv[0];\ @@ -1152,7 +727,7 @@ static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, in && !IS_INTERLACED(mb_types[h->left_mb_xy[0]]) && i >= scan8[0]+8){ // leftshift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's ok. - SET_DIAG_MV(>>1, <<1, s->mb_x*4-1, (s->mb_y&~1)*4 - 1 + ((i-scan8[0])>>3)*2); + SET_DIAG_MV(/2, <<1, s->mb_x*4-1, (s->mb_y&~1)*4 - 1 + ((i-scan8[0])>>3)*2); } } #undef SET_DIAG_MV @@ -1447,14 +1022,76 @@ static inline void pred_direct_motion(H264Context * const h, int *mb_type){ } if(ref[1] < 0){ - *mb_type &= ~MB_TYPE_P0L1; - sub_mb_type &= ~MB_TYPE_P0L1; + if(!is_b8x8) + *mb_type &= ~MB_TYPE_L1; + sub_mb_type &= ~MB_TYPE_L1; }else if(ref[0] < 0){ - *mb_type &= ~MB_TYPE_P0L0; - sub_mb_type &= ~MB_TYPE_P0L0; + if(!is_b8x8) + *mb_type &= ~MB_TYPE_L0; + sub_mb_type &= ~MB_TYPE_L0; } - if(IS_16X16(*mb_type)){ + if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col)){ + int pair_xy = s->mb_x + (s->mb_y&~1)*s->mb_stride; + int mb_types_col[2]; + int b8_stride = h->b8_stride; + int b4_stride = h->b_stride; + + *mb_type = (*mb_type & ~MB_TYPE_16x16) | MB_TYPE_8x8; + + if(IS_INTERLACED(*mb_type)){ + mb_types_col[0] = h->ref_list[1][0].mb_type[pair_xy]; + mb_types_col[1] = h->ref_list[1][0].mb_type[pair_xy+s->mb_stride]; + if(s->mb_y&1){ + l1ref0 -= 2*b8_stride; + l1ref1 -= 2*b8_stride; + l1mv0 -= 4*b4_stride; + l1mv1 -= 4*b4_stride; + } + b8_stride *= 3; + b4_stride *= 6; + }else{ + int cur_poc = s->current_picture_ptr->poc; + int *col_poc = h->ref_list[1]->field_poc; + int col_parity = FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc); + int dy = 2*col_parity - (s->mb_y&1); + mb_types_col[0] = + mb_types_col[1] = h->ref_list[1][0].mb_type[pair_xy + col_parity*s->mb_stride]; + l1ref0 += dy*b8_stride; + l1ref1 += dy*b8_stride; + l1mv0 += 2*dy*b4_stride; + l1mv1 += 2*dy*b4_stride; + b8_stride = 0; + } + + for(i8=0; i8<4; i8++){ + int x8 = i8&1; + int y8 = i8>>1; + int xy8 = x8+y8*b8_stride; + int xy4 = 3*x8+y8*b4_stride; + int a=0, b=0; + + if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8])) + continue; + h->sub_mb_type[i8] = sub_mb_type; + + fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1); + fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1); + if(!IS_INTRA(mb_types_col[y8]) + && ( (l1ref0[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1) + || (l1ref0[xy8] < 0 && l1ref1[xy8] == 0 && FFABS(l1mv1[xy4][0]) <= 1 && FFABS(l1mv1[xy4][1]) <= 1))){ + if(ref[0] > 0) + a= pack16to32(mv[0][0],mv[0][1]); + if(ref[1] > 0) + b= pack16to32(mv[1][0],mv[1][1]); + }else{ + a= pack16to32(mv[0][0],mv[0][1]); + b= pack16to32(mv[1][0],mv[1][1]); + } + fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, a, 4); + fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, b, 4); + } + }else if(IS_16X16(*mb_type)){ int a=0, b=0; fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1); @@ -1738,9 +1375,10 @@ static inline void write_back_motion(H264Context *h, int mb_type){ * @param dst_length is the number of decoded bytes FIXME here or a decode rbsp tailing? * @returns decoded bytes, might be src+1 if no escapes */ -static uint8_t *decode_nal(H264Context *h, uint8_t *src, int *dst_length, int *consumed, int length){ +static const uint8_t *decode_nal(H264Context *h, const uint8_t *src, int *dst_length, int *consumed, int length){ int i, si, di; uint8_t *dst; + int bufidx; // src[0]&0x80; //forbidden bit h->nal_ref_idc= src[0]>>5; @@ -1769,8 +1407,9 @@ static uint8_t *decode_nal(H264Context *h, uint8_t *src, int *dst_length, int *c return src; } - h->rbsp_buffer= av_fast_realloc(h->rbsp_buffer, &h->rbsp_buffer_size, length); - dst= h->rbsp_buffer; + bufidx = h->nal_unit_type == NAL_DPC ? 1 : 0; // use second escape buffer for inter data + h->rbsp_buffer[bufidx]= av_fast_realloc(h->rbsp_buffer[bufidx], &h->rbsp_buffer_size[bufidx], length); + dst= h->rbsp_buffer[bufidx]; if (dst == NULL){ return NULL; @@ -1795,7 +1434,7 @@ static uint8_t *decode_nal(H264Context *h, uint8_t *src, int *dst_length, int *c *dst_length= di; *consumed= si + 1;//+1 for the header -//FIXME store exact number of bits in the getbitcontext (its needed for decoding) +//FIXME store exact number of bits in the getbitcontext (it is needed for decoding) return dst; } @@ -1803,7 +1442,7 @@ static uint8_t *decode_nal(H264Context *h, uint8_t *src, int *dst_length, int *c * identifies the exact end of the bitstream * @return the length of the trailing, or 0 if damaged */ -static int decode_rbsp_trailing(H264Context *h, uint8_t *src){ +static int decode_rbsp_trailing(H264Context *h, const uint8_t *src){ int v= *src; int r; @@ -1946,12 +1585,11 @@ static void chroma_dc_dct_c(DCTELEM *block){ /** * gets the chroma qp. */ -static inline int get_chroma_qp(int chroma_qp_index_offset, int qscale){ - - return chroma_qp[av_clip(qscale + chroma_qp_index_offset, 0, 51)]; +static inline int get_chroma_qp(H264Context *h, int t, int qscale){ + return h->pps.chroma_qp_table[t][qscale & 0xff]; } -//FIXME need to check that this doesnt overflow signed 32 bit for low qp, i am not sure, it's very close +//FIXME need to check that this does not overflow signed 32 bit for low qp, i am not sure, it's very close //FIXME check that gcc inlines this (and optimizes intra & separate_dc stuff away) static inline int quantize_c(DCTELEM *block, uint8_t *scantable, int qscale, int intra, int separate_dc){ int i; @@ -2030,722 +1668,6 @@ static inline int quantize_c(DCTELEM *block, uint8_t *scantable, int qscale, int return last_non_zero; } -static void pred4x4_vertical_c(uint8_t *src, uint8_t *topright, int stride){ - const uint32_t a= ((uint32_t*)(src-stride))[0]; - ((uint32_t*)(src+0*stride))[0]= a; - ((uint32_t*)(src+1*stride))[0]= a; - ((uint32_t*)(src+2*stride))[0]= a; - ((uint32_t*)(src+3*stride))[0]= a; -} - -static void pred4x4_horizontal_c(uint8_t *src, uint8_t *topright, int stride){ - ((uint32_t*)(src+0*stride))[0]= src[-1+0*stride]*0x01010101; - ((uint32_t*)(src+1*stride))[0]= src[-1+1*stride]*0x01010101; - ((uint32_t*)(src+2*stride))[0]= src[-1+2*stride]*0x01010101; - ((uint32_t*)(src+3*stride))[0]= src[-1+3*stride]*0x01010101; -} - -static void pred4x4_dc_c(uint8_t *src, uint8_t *topright, int stride){ - const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] - + src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 4) >>3; - - ((uint32_t*)(src+0*stride))[0]= - ((uint32_t*)(src+1*stride))[0]= - ((uint32_t*)(src+2*stride))[0]= - ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; -} - -static void pred4x4_left_dc_c(uint8_t *src, uint8_t *topright, int stride){ - const int dc= ( src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 2) >>2; - - ((uint32_t*)(src+0*stride))[0]= - ((uint32_t*)(src+1*stride))[0]= - ((uint32_t*)(src+2*stride))[0]= - ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; -} - -static void pred4x4_top_dc_c(uint8_t *src, uint8_t *topright, int stride){ - const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + 2) >>2; - - ((uint32_t*)(src+0*stride))[0]= - ((uint32_t*)(src+1*stride))[0]= - ((uint32_t*)(src+2*stride))[0]= - ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; -} - -static void pred4x4_128_dc_c(uint8_t *src, uint8_t *topright, int stride){ - ((uint32_t*)(src+0*stride))[0]= - ((uint32_t*)(src+1*stride))[0]= - ((uint32_t*)(src+2*stride))[0]= - ((uint32_t*)(src+3*stride))[0]= 128U*0x01010101U; -} - - -#define LOAD_TOP_RIGHT_EDGE\ - const int t4= topright[0];\ - const int t5= topright[1];\ - const int t6= topright[2];\ - const int t7= topright[3];\ - -#define LOAD_LEFT_EDGE\ - const int l0= src[-1+0*stride];\ - const int l1= src[-1+1*stride];\ - const int l2= src[-1+2*stride];\ - const int l3= src[-1+3*stride];\ - -#define LOAD_TOP_EDGE\ - const int t0= src[ 0-1*stride];\ - const int t1= src[ 1-1*stride];\ - const int t2= src[ 2-1*stride];\ - const int t3= src[ 3-1*stride];\ - -static void pred4x4_down_right_c(uint8_t *src, uint8_t *topright, int stride){ - const int lt= src[-1-1*stride]; - LOAD_TOP_EDGE - LOAD_LEFT_EDGE - - src[0+3*stride]=(l3 + 2*l2 + l1 + 2)>>2; - src[0+2*stride]= - src[1+3*stride]=(l2 + 2*l1 + l0 + 2)>>2; - src[0+1*stride]= - src[1+2*stride]= - src[2+3*stride]=(l1 + 2*l0 + lt + 2)>>2; - src[0+0*stride]= - src[1+1*stride]= - src[2+2*stride]= - src[3+3*stride]=(l0 + 2*lt + t0 + 2)>>2; - src[1+0*stride]= - src[2+1*stride]= - src[3+2*stride]=(lt + 2*t0 + t1 + 2)>>2; - src[2+0*stride]= - src[3+1*stride]=(t0 + 2*t1 + t2 + 2)>>2; - src[3+0*stride]=(t1 + 2*t2 + t3 + 2)>>2; -} - -static void pred4x4_down_left_c(uint8_t *src, uint8_t *topright, int stride){ - LOAD_TOP_EDGE - LOAD_TOP_RIGHT_EDGE -// LOAD_LEFT_EDGE - - src[0+0*stride]=(t0 + t2 + 2*t1 + 2)>>2; - src[1+0*stride]= - src[0+1*stride]=(t1 + t3 + 2*t2 + 2)>>2; - src[2+0*stride]= - src[1+1*stride]= - src[0+2*stride]=(t2 + t4 + 2*t3 + 2)>>2; - src[3+0*stride]= - src[2+1*stride]= - src[1+2*stride]= - src[0+3*stride]=(t3 + t5 + 2*t4 + 2)>>2; - src[3+1*stride]= - src[2+2*stride]= - src[1+3*stride]=(t4 + t6 + 2*t5 + 2)>>2; - src[3+2*stride]= - src[2+3*stride]=(t5 + t7 + 2*t6 + 2)>>2; - src[3+3*stride]=(t6 + 3*t7 + 2)>>2; -} - -static void pred4x4_vertical_right_c(uint8_t *src, uint8_t *topright, int stride){ - const int lt= src[-1-1*stride]; - LOAD_TOP_EDGE - LOAD_LEFT_EDGE - const __attribute__((unused)) int unu= l3; - - src[0+0*stride]= - src[1+2*stride]=(lt + t0 + 1)>>1; - src[1+0*stride]= - src[2+2*stride]=(t0 + t1 + 1)>>1; - src[2+0*stride]= - src[3+2*stride]=(t1 + t2 + 1)>>1; - src[3+0*stride]=(t2 + t3 + 1)>>1; - src[0+1*stride]= - src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2; - src[1+1*stride]= - src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2; - src[2+1*stride]= - src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2; - src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2; - src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2; - src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2; -} - -static void pred4x4_vertical_left_c(uint8_t *src, uint8_t *topright, int stride){ - LOAD_TOP_EDGE - LOAD_TOP_RIGHT_EDGE - const __attribute__((unused)) int unu= t7; - - src[0+0*stride]=(t0 + t1 + 1)>>1; - src[1+0*stride]= - src[0+2*stride]=(t1 + t2 + 1)>>1; - src[2+0*stride]= - src[1+2*stride]=(t2 + t3 + 1)>>1; - src[3+0*stride]= - src[2+2*stride]=(t3 + t4+ 1)>>1; - src[3+2*stride]=(t4 + t5+ 1)>>1; - src[0+1*stride]=(t0 + 2*t1 + t2 + 2)>>2; - src[1+1*stride]= - src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2; - src[2+1*stride]= - src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2; - src[3+1*stride]= - src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2; - src[3+3*stride]=(t4 + 2*t5 + t6 + 2)>>2; -} - -static void pred4x4_horizontal_up_c(uint8_t *src, uint8_t *topright, int stride){ - LOAD_LEFT_EDGE - - src[0+0*stride]=(l0 + l1 + 1)>>1; - src[1+0*stride]=(l0 + 2*l1 + l2 + 2)>>2; - src[2+0*stride]= - src[0+1*stride]=(l1 + l2 + 1)>>1; - src[3+0*stride]= - src[1+1*stride]=(l1 + 2*l2 + l3 + 2)>>2; - src[2+1*stride]= - src[0+2*stride]=(l2 + l3 + 1)>>1; - src[3+1*stride]= - src[1+2*stride]=(l2 + 2*l3 + l3 + 2)>>2; - src[3+2*stride]= - src[1+3*stride]= - src[0+3*stride]= - src[2+2*stride]= - src[2+3*stride]= - src[3+3*stride]=l3; -} - -static void pred4x4_horizontal_down_c(uint8_t *src, uint8_t *topright, int stride){ - const int lt= src[-1-1*stride]; - LOAD_TOP_EDGE - LOAD_LEFT_EDGE - const __attribute__((unused)) int unu= t3; - - src[0+0*stride]= - src[2+1*stride]=(lt + l0 + 1)>>1; - src[1+0*stride]= - src[3+1*stride]=(l0 + 2*lt + t0 + 2)>>2; - src[2+0*stride]=(lt + 2*t0 + t1 + 2)>>2; - src[3+0*stride]=(t0 + 2*t1 + t2 + 2)>>2; - src[0+1*stride]= - src[2+2*stride]=(l0 + l1 + 1)>>1; - src[1+1*stride]= - src[3+2*stride]=(lt + 2*l0 + l1 + 2)>>2; - src[0+2*stride]= - src[2+3*stride]=(l1 + l2+ 1)>>1; - src[1+2*stride]= - src[3+3*stride]=(l0 + 2*l1 + l2 + 2)>>2; - src[0+3*stride]=(l2 + l3 + 1)>>1; - src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2; -} - -void ff_pred16x16_vertical_c(uint8_t *src, int stride){ - int i; - const uint32_t a= ((uint32_t*)(src-stride))[0]; - const uint32_t b= ((uint32_t*)(src-stride))[1]; - const uint32_t c= ((uint32_t*)(src-stride))[2]; - const uint32_t d= ((uint32_t*)(src-stride))[3]; - - for(i=0; i<16; i++){ - ((uint32_t*)(src+i*stride))[0]= a; - ((uint32_t*)(src+i*stride))[1]= b; - ((uint32_t*)(src+i*stride))[2]= c; - ((uint32_t*)(src+i*stride))[3]= d; - } -} - -void ff_pred16x16_horizontal_c(uint8_t *src, int stride){ - int i; - - for(i=0; i<16; i++){ - ((uint32_t*)(src+i*stride))[0]= - ((uint32_t*)(src+i*stride))[1]= - ((uint32_t*)(src+i*stride))[2]= - ((uint32_t*)(src+i*stride))[3]= src[-1+i*stride]*0x01010101; - } -} - -void ff_pred16x16_dc_c(uint8_t *src, int stride){ - int i, dc=0; - - for(i=0;i<16; i++){ - dc+= src[-1+i*stride]; - } - - for(i=0;i<16; i++){ - dc+= src[i-stride]; - } - - dc= 0x01010101*((dc + 16)>>5); - - for(i=0; i<16; i++){ - ((uint32_t*)(src+i*stride))[0]= - ((uint32_t*)(src+i*stride))[1]= - ((uint32_t*)(src+i*stride))[2]= - ((uint32_t*)(src+i*stride))[3]= dc; - } -} - -static void pred16x16_left_dc_c(uint8_t *src, int stride){ - int i, dc=0; - - for(i=0;i<16; i++){ - dc+= src[-1+i*stride]; - } - - dc= 0x01010101*((dc + 8)>>4); - - for(i=0; i<16; i++){ - ((uint32_t*)(src+i*stride))[0]= - ((uint32_t*)(src+i*stride))[1]= - ((uint32_t*)(src+i*stride))[2]= - ((uint32_t*)(src+i*stride))[3]= dc; - } -} - -static void pred16x16_top_dc_c(uint8_t *src, int stride){ - int i, dc=0; - - for(i=0;i<16; i++){ - dc+= src[i-stride]; - } - dc= 0x01010101*((dc + 8)>>4); - - for(i=0; i<16; i++){ - ((uint32_t*)(src+i*stride))[0]= - ((uint32_t*)(src+i*stride))[1]= - ((uint32_t*)(src+i*stride))[2]= - ((uint32_t*)(src+i*stride))[3]= dc; - } -} - -void ff_pred16x16_128_dc_c(uint8_t *src, int stride){ - int i; - - for(i=0; i<16; i++){ - ((uint32_t*)(src+i*stride))[0]= - ((uint32_t*)(src+i*stride))[1]= - ((uint32_t*)(src+i*stride))[2]= - ((uint32_t*)(src+i*stride))[3]= 0x01010101U*128U; - } -} - -static inline void pred16x16_plane_compat_c(uint8_t *src, int stride, const int svq3){ - int i, j, k; - int a; - uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; - const uint8_t * const src0 = src+7-stride; - const uint8_t *src1 = src+8*stride-1; - const uint8_t *src2 = src1-2*stride; // == src+6*stride-1; - int H = src0[1] - src0[-1]; - int V = src1[0] - src2[ 0]; - for(k=2; k<=8; ++k) { - src1 += stride; src2 -= stride; - H += k*(src0[k] - src0[-k]); - V += k*(src1[0] - src2[ 0]); - } - if(svq3){ - H = ( 5*(H/4) ) / 16; - V = ( 5*(V/4) ) / 16; - - /* required for 100% accuracy */ - i = H; H = V; V = i; - }else{ - H = ( 5*H+32 ) >> 6; - V = ( 5*V+32 ) >> 6; - } - - a = 16*(src1[0] + src2[16] + 1) - 7*(V+H); - for(j=16; j>0; --j) { - int b = a; - a += V; - for(i=-16; i<0; i+=4) { - src[16+i] = cm[ (b ) >> 5 ]; - src[17+i] = cm[ (b+ H) >> 5 ]; - src[18+i] = cm[ (b+2*H) >> 5 ]; - src[19+i] = cm[ (b+3*H) >> 5 ]; - b += 4*H; - } - src += stride; - } -} - -void ff_pred16x16_plane_c(uint8_t *src, int stride){ - pred16x16_plane_compat_c(src, stride, 0); -} - -void ff_pred8x8_vertical_c(uint8_t *src, int stride){ - int i; - const uint32_t a= ((uint32_t*)(src-stride))[0]; - const uint32_t b= ((uint32_t*)(src-stride))[1]; - - for(i=0; i<8; i++){ - ((uint32_t*)(src+i*stride))[0]= a; - ((uint32_t*)(src+i*stride))[1]= b; - } -} - -void ff_pred8x8_horizontal_c(uint8_t *src, int stride){ - int i; - - for(i=0; i<8; i++){ - ((uint32_t*)(src+i*stride))[0]= - ((uint32_t*)(src+i*stride))[1]= src[-1+i*stride]*0x01010101; - } -} - -void ff_pred8x8_128_dc_c(uint8_t *src, int stride){ - int i; - - for(i=0; i<8; i++){ - ((uint32_t*)(src+i*stride))[0]= - ((uint32_t*)(src+i*stride))[1]= 0x01010101U*128U; - } -} - -static void pred8x8_left_dc_c(uint8_t *src, int stride){ - int i; - int dc0, dc2; - - dc0=dc2=0; - for(i=0;i<4; i++){ - dc0+= src[-1+i*stride]; - dc2+= src[-1+(i+4)*stride]; - } - dc0= 0x01010101*((dc0 + 2)>>2); - dc2= 0x01010101*((dc2 + 2)>>2); - - for(i=0; i<4; i++){ - ((uint32_t*)(src+i*stride))[0]= - ((uint32_t*)(src+i*stride))[1]= dc0; - } - for(i=4; i<8; i++){ - ((uint32_t*)(src+i*stride))[0]= - ((uint32_t*)(src+i*stride))[1]= dc2; - } -} - -static void pred8x8_top_dc_c(uint8_t *src, int stride){ - int i; - int dc0, dc1; - - dc0=dc1=0; - for(i=0;i<4; i++){ - dc0+= src[i-stride]; - dc1+= src[4+i-stride]; - } - dc0= 0x01010101*((dc0 + 2)>>2); - dc1= 0x01010101*((dc1 + 2)>>2); - - for(i=0; i<4; i++){ - ((uint32_t*)(src+i*stride))[0]= dc0; - ((uint32_t*)(src+i*stride))[1]= dc1; - } - for(i=4; i<8; i++){ - ((uint32_t*)(src+i*stride))[0]= dc0; - ((uint32_t*)(src+i*stride))[1]= dc1; - } -} - - -void ff_pred8x8_dc_c(uint8_t *src, int stride){ - int i; - int dc0, dc1, dc2, dc3; - - dc0=dc1=dc2=0; - for(i=0;i<4; i++){ - dc0+= src[-1+i*stride] + src[i-stride]; - dc1+= src[4+i-stride]; - dc2+= src[-1+(i+4)*stride]; - } - dc3= 0x01010101*((dc1 + dc2 + 4)>>3); - dc0= 0x01010101*((dc0 + 4)>>3); - dc1= 0x01010101*((dc1 + 2)>>2); - dc2= 0x01010101*((dc2 + 2)>>2); - - for(i=0; i<4; i++){ - ((uint32_t*)(src+i*stride))[0]= dc0; - ((uint32_t*)(src+i*stride))[1]= dc1; - } - for(i=4; i<8; i++){ - ((uint32_t*)(src+i*stride))[0]= dc2; - ((uint32_t*)(src+i*stride))[1]= dc3; - } -} - -void ff_pred8x8_plane_c(uint8_t *src, int stride){ - int j, k; - int a; - uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; - const uint8_t * const src0 = src+3-stride; - const uint8_t *src1 = src+4*stride-1; - const uint8_t *src2 = src1-2*stride; // == src+2*stride-1; - int H = src0[1] - src0[-1]; - int V = src1[0] - src2[ 0]; - for(k=2; k<=4; ++k) { - src1 += stride; src2 -= stride; - H += k*(src0[k] - src0[-k]); - V += k*(src1[0] - src2[ 0]); - } - H = ( 17*H+16 ) >> 5; - V = ( 17*V+16 ) >> 5; - - a = 16*(src1[0] + src2[8]+1) - 3*(V+H); - for(j=8; j>0; --j) { - int b = a; - a += V; - src[0] = cm[ (b ) >> 5 ]; - src[1] = cm[ (b+ H) >> 5 ]; - src[2] = cm[ (b+2*H) >> 5 ]; - src[3] = cm[ (b+3*H) >> 5 ]; - src[4] = cm[ (b+4*H) >> 5 ]; - src[5] = cm[ (b+5*H) >> 5 ]; - src[6] = cm[ (b+6*H) >> 5 ]; - src[7] = cm[ (b+7*H) >> 5 ]; - src += stride; - } -} - -#define SRC(x,y) src[(x)+(y)*stride] -#define PL(y) \ - const int l##y = (SRC(-1,y-1) + 2*SRC(-1,y) + SRC(-1,y+1) + 2) >> 2; -#define PREDICT_8x8_LOAD_LEFT \ - const int l0 = ((has_topleft ? SRC(-1,-1) : SRC(-1,0)) \ - + 2*SRC(-1,0) + SRC(-1,1) + 2) >> 2; \ - PL(1) PL(2) PL(3) PL(4) PL(5) PL(6) \ - const int l7 attribute_unused = (SRC(-1,6) + 3*SRC(-1,7) + 2) >> 2 - -#define PT(x) \ - const int t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2; -#define PREDICT_8x8_LOAD_TOP \ - const int t0 = ((has_topleft ? SRC(-1,-1) : SRC(0,-1)) \ - + 2*SRC(0,-1) + SRC(1,-1) + 2) >> 2; \ - PT(1) PT(2) PT(3) PT(4) PT(5) PT(6) \ - const int t7 attribute_unused = ((has_topright ? SRC(8,-1) : SRC(7,-1)) \ - + 2*SRC(7,-1) + SRC(6,-1) + 2) >> 2 - -#define PTR(x) \ - t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2; -#define PREDICT_8x8_LOAD_TOPRIGHT \ - int t8, t9, t10, t11, t12, t13, t14, t15; \ - if(has_topright) { \ - PTR(8) PTR(9) PTR(10) PTR(11) PTR(12) PTR(13) PTR(14) \ - t15 = (SRC(14,-1) + 3*SRC(15,-1) + 2) >> 2; \ - } else t8=t9=t10=t11=t12=t13=t14=t15= SRC(7,-1); - -#define PREDICT_8x8_LOAD_TOPLEFT \ - const int lt = (SRC(-1,0) + 2*SRC(-1,-1) + SRC(0,-1) + 2) >> 2 - -#define PREDICT_8x8_DC(v) \ - int y; \ - for( y = 0; y < 8; y++ ) { \ - ((uint32_t*)src)[0] = \ - ((uint32_t*)src)[1] = v; \ - src += stride; \ - } - -static void pred8x8l_128_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride) -{ - PREDICT_8x8_DC(0x80808080); -} -static void pred8x8l_left_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride) -{ - PREDICT_8x8_LOAD_LEFT; - const uint32_t dc = ((l0+l1+l2+l3+l4+l5+l6+l7+4) >> 3) * 0x01010101; - PREDICT_8x8_DC(dc); -} -static void pred8x8l_top_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride) -{ - PREDICT_8x8_LOAD_TOP; - const uint32_t dc = ((t0+t1+t2+t3+t4+t5+t6+t7+4) >> 3) * 0x01010101; - PREDICT_8x8_DC(dc); -} -static void pred8x8l_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride) -{ - PREDICT_8x8_LOAD_LEFT; - PREDICT_8x8_LOAD_TOP; - const uint32_t dc = ((l0+l1+l2+l3+l4+l5+l6+l7 - +t0+t1+t2+t3+t4+t5+t6+t7+8) >> 4) * 0x01010101; - PREDICT_8x8_DC(dc); -} -static void pred8x8l_horizontal_c(uint8_t *src, int has_topleft, int has_topright, int stride) -{ - PREDICT_8x8_LOAD_LEFT; -#define ROW(y) ((uint32_t*)(src+y*stride))[0] =\ - ((uint32_t*)(src+y*stride))[1] = 0x01010101 * l##y - ROW(0); ROW(1); ROW(2); ROW(3); ROW(4); ROW(5); ROW(6); ROW(7); -#undef ROW -} -static void pred8x8l_vertical_c(uint8_t *src, int has_topleft, int has_topright, int stride) -{ - int y; - PREDICT_8x8_LOAD_TOP; - src[0] = t0; - src[1] = t1; - src[2] = t2; - src[3] = t3; - src[4] = t4; - src[5] = t5; - src[6] = t6; - src[7] = t7; - for( y = 1; y < 8; y++ ) - *(uint64_t*)(src+y*stride) = *(uint64_t*)src; -} -static void pred8x8l_down_left_c(uint8_t *src, int has_topleft, int has_topright, int stride) -{ - PREDICT_8x8_LOAD_TOP; - PREDICT_8x8_LOAD_TOPRIGHT; - SRC(0,0)= (t0 + 2*t1 + t2 + 2) >> 2; - SRC(0,1)=SRC(1,0)= (t1 + 2*t2 + t3 + 2) >> 2; - SRC(0,2)=SRC(1,1)=SRC(2,0)= (t2 + 2*t3 + t4 + 2) >> 2; - SRC(0,3)=SRC(1,2)=SRC(2,1)=SRC(3,0)= (t3 + 2*t4 + t5 + 2) >> 2; - SRC(0,4)=SRC(1,3)=SRC(2,2)=SRC(3,1)=SRC(4,0)= (t4 + 2*t5 + t6 + 2) >> 2; - SRC(0,5)=SRC(1,4)=SRC(2,3)=SRC(3,2)=SRC(4,1)=SRC(5,0)= (t5 + 2*t6 + t7 + 2) >> 2; - SRC(0,6)=SRC(1,5)=SRC(2,4)=SRC(3,3)=SRC(4,2)=SRC(5,1)=SRC(6,0)= (t6 + 2*t7 + t8 + 2) >> 2; - SRC(0,7)=SRC(1,6)=SRC(2,5)=SRC(3,4)=SRC(4,3)=SRC(5,2)=SRC(6,1)=SRC(7,0)= (t7 + 2*t8 + t9 + 2) >> 2; - SRC(1,7)=SRC(2,6)=SRC(3,5)=SRC(4,4)=SRC(5,3)=SRC(6,2)=SRC(7,1)= (t8 + 2*t9 + t10 + 2) >> 2; - SRC(2,7)=SRC(3,6)=SRC(4,5)=SRC(5,4)=SRC(6,3)=SRC(7,2)= (t9 + 2*t10 + t11 + 2) >> 2; - SRC(3,7)=SRC(4,6)=SRC(5,5)=SRC(6,4)=SRC(7,3)= (t10 + 2*t11 + t12 + 2) >> 2; - SRC(4,7)=SRC(5,6)=SRC(6,5)=SRC(7,4)= (t11 + 2*t12 + t13 + 2) >> 2; - SRC(5,7)=SRC(6,6)=SRC(7,5)= (t12 + 2*t13 + t14 + 2) >> 2; - SRC(6,7)=SRC(7,6)= (t13 + 2*t14 + t15 + 2) >> 2; - SRC(7,7)= (t14 + 3*t15 + 2) >> 2; -} -static void pred8x8l_down_right_c(uint8_t *src, int has_topleft, int has_topright, int stride) -{ - PREDICT_8x8_LOAD_TOP; - PREDICT_8x8_LOAD_LEFT; - PREDICT_8x8_LOAD_TOPLEFT; - SRC(0,7)= (l7 + 2*l6 + l5 + 2) >> 2; - SRC(0,6)=SRC(1,7)= (l6 + 2*l5 + l4 + 2) >> 2; - SRC(0,5)=SRC(1,6)=SRC(2,7)= (l5 + 2*l4 + l3 + 2) >> 2; - SRC(0,4)=SRC(1,5)=SRC(2,6)=SRC(3,7)= (l4 + 2*l3 + l2 + 2) >> 2; - SRC(0,3)=SRC(1,4)=SRC(2,5)=SRC(3,6)=SRC(4,7)= (l3 + 2*l2 + l1 + 2) >> 2; - SRC(0,2)=SRC(1,3)=SRC(2,4)=SRC(3,5)=SRC(4,6)=SRC(5,7)= (l2 + 2*l1 + l0 + 2) >> 2; - SRC(0,1)=SRC(1,2)=SRC(2,3)=SRC(3,4)=SRC(4,5)=SRC(5,6)=SRC(6,7)= (l1 + 2*l0 + lt + 2) >> 2; - SRC(0,0)=SRC(1,1)=SRC(2,2)=SRC(3,3)=SRC(4,4)=SRC(5,5)=SRC(6,6)=SRC(7,7)= (l0 + 2*lt + t0 + 2) >> 2; - SRC(1,0)=SRC(2,1)=SRC(3,2)=SRC(4,3)=SRC(5,4)=SRC(6,5)=SRC(7,6)= (lt + 2*t0 + t1 + 2) >> 2; - SRC(2,0)=SRC(3,1)=SRC(4,2)=SRC(5,3)=SRC(6,4)=SRC(7,5)= (t0 + 2*t1 + t2 + 2) >> 2; - SRC(3,0)=SRC(4,1)=SRC(5,2)=SRC(6,3)=SRC(7,4)= (t1 + 2*t2 + t3 + 2) >> 2; - SRC(4,0)=SRC(5,1)=SRC(6,2)=SRC(7,3)= (t2 + 2*t3 + t4 + 2) >> 2; - SRC(5,0)=SRC(6,1)=SRC(7,2)= (t3 + 2*t4 + t5 + 2) >> 2; - SRC(6,0)=SRC(7,1)= (t4 + 2*t5 + t6 + 2) >> 2; - SRC(7,0)= (t5 + 2*t6 + t7 + 2) >> 2; - -} -static void pred8x8l_vertical_right_c(uint8_t *src, int has_topleft, int has_topright, int stride) -{ - PREDICT_8x8_LOAD_TOP; - PREDICT_8x8_LOAD_LEFT; - PREDICT_8x8_LOAD_TOPLEFT; - SRC(0,6)= (l5 + 2*l4 + l3 + 2) >> 2; - SRC(0,7)= (l6 + 2*l5 + l4 + 2) >> 2; - SRC(0,4)=SRC(1,6)= (l3 + 2*l2 + l1 + 2) >> 2; - SRC(0,5)=SRC(1,7)= (l4 + 2*l3 + l2 + 2) >> 2; - SRC(0,2)=SRC(1,4)=SRC(2,6)= (l1 + 2*l0 + lt + 2) >> 2; - SRC(0,3)=SRC(1,5)=SRC(2,7)= (l2 + 2*l1 + l0 + 2) >> 2; - SRC(0,1)=SRC(1,3)=SRC(2,5)=SRC(3,7)= (l0 + 2*lt + t0 + 2) >> 2; - SRC(0,0)=SRC(1,2)=SRC(2,4)=SRC(3,6)= (lt + t0 + 1) >> 1; - SRC(1,1)=SRC(2,3)=SRC(3,5)=SRC(4,7)= (lt + 2*t0 + t1 + 2) >> 2; - SRC(1,0)=SRC(2,2)=SRC(3,4)=SRC(4,6)= (t0 + t1 + 1) >> 1; - SRC(2,1)=SRC(3,3)=SRC(4,5)=SRC(5,7)= (t0 + 2*t1 + t2 + 2) >> 2; - SRC(2,0)=SRC(3,2)=SRC(4,4)=SRC(5,6)= (t1 + t2 + 1) >> 1; - SRC(3,1)=SRC(4,3)=SRC(5,5)=SRC(6,7)= (t1 + 2*t2 + t3 + 2) >> 2; - SRC(3,0)=SRC(4,2)=SRC(5,4)=SRC(6,6)= (t2 + t3 + 1) >> 1; - SRC(4,1)=SRC(5,3)=SRC(6,5)=SRC(7,7)= (t2 + 2*t3 + t4 + 2) >> 2; - SRC(4,0)=SRC(5,2)=SRC(6,4)=SRC(7,6)= (t3 + t4 + 1) >> 1; - SRC(5,1)=SRC(6,3)=SRC(7,5)= (t3 + 2*t4 + t5 + 2) >> 2; - SRC(5,0)=SRC(6,2)=SRC(7,4)= (t4 + t5 + 1) >> 1; - SRC(6,1)=SRC(7,3)= (t4 + 2*t5 + t6 + 2) >> 2; - SRC(6,0)=SRC(7,2)= (t5 + t6 + 1) >> 1; - SRC(7,1)= (t5 + 2*t6 + t7 + 2) >> 2; - SRC(7,0)= (t6 + t7 + 1) >> 1; -} -static void pred8x8l_horizontal_down_c(uint8_t *src, int has_topleft, int has_topright, int stride) -{ - PREDICT_8x8_LOAD_TOP; - PREDICT_8x8_LOAD_LEFT; - PREDICT_8x8_LOAD_TOPLEFT; - SRC(0,7)= (l6 + l7 + 1) >> 1; - SRC(1,7)= (l5 + 2*l6 + l7 + 2) >> 2; - SRC(0,6)=SRC(2,7)= (l5 + l6 + 1) >> 1; - SRC(1,6)=SRC(3,7)= (l4 + 2*l5 + l6 + 2) >> 2; - SRC(0,5)=SRC(2,6)=SRC(4,7)= (l4 + l5 + 1) >> 1; - SRC(1,5)=SRC(3,6)=SRC(5,7)= (l3 + 2*l4 + l5 + 2) >> 2; - SRC(0,4)=SRC(2,5)=SRC(4,6)=SRC(6,7)= (l3 + l4 + 1) >> 1; - SRC(1,4)=SRC(3,5)=SRC(5,6)=SRC(7,7)= (l2 + 2*l3 + l4 + 2) >> 2; - SRC(0,3)=SRC(2,4)=SRC(4,5)=SRC(6,6)= (l2 + l3 + 1) >> 1; - SRC(1,3)=SRC(3,4)=SRC(5,5)=SRC(7,6)= (l1 + 2*l2 + l3 + 2) >> 2; - SRC(0,2)=SRC(2,3)=SRC(4,4)=SRC(6,5)= (l1 + l2 + 1) >> 1; - SRC(1,2)=SRC(3,3)=SRC(5,4)=SRC(7,5)= (l0 + 2*l1 + l2 + 2) >> 2; - SRC(0,1)=SRC(2,2)=SRC(4,3)=SRC(6,4)= (l0 + l1 + 1) >> 1; - SRC(1,1)=SRC(3,2)=SRC(5,3)=SRC(7,4)= (lt + 2*l0 + l1 + 2) >> 2; - SRC(0,0)=SRC(2,1)=SRC(4,2)=SRC(6,3)= (lt + l0 + 1) >> 1; - SRC(1,0)=SRC(3,1)=SRC(5,2)=SRC(7,3)= (l0 + 2*lt + t0 + 2) >> 2; - SRC(2,0)=SRC(4,1)=SRC(6,2)= (t1 + 2*t0 + lt + 2) >> 2; - SRC(3,0)=SRC(5,1)=SRC(7,2)= (t2 + 2*t1 + t0 + 2) >> 2; - SRC(4,0)=SRC(6,1)= (t3 + 2*t2 + t1 + 2) >> 2; - SRC(5,0)=SRC(7,1)= (t4 + 2*t3 + t2 + 2) >> 2; - SRC(6,0)= (t5 + 2*t4 + t3 + 2) >> 2; - SRC(7,0)= (t6 + 2*t5 + t4 + 2) >> 2; -} -static void pred8x8l_vertical_left_c(uint8_t *src, int has_topleft, int has_topright, int stride) -{ - PREDICT_8x8_LOAD_TOP; - PREDICT_8x8_LOAD_TOPRIGHT; - SRC(0,0)= (t0 + t1 + 1) >> 1; - SRC(0,1)= (t0 + 2*t1 + t2 + 2) >> 2; - SRC(0,2)=SRC(1,0)= (t1 + t2 + 1) >> 1; - SRC(0,3)=SRC(1,1)= (t1 + 2*t2 + t3 + 2) >> 2; - SRC(0,4)=SRC(1,2)=SRC(2,0)= (t2 + t3 + 1) >> 1; - SRC(0,5)=SRC(1,3)=SRC(2,1)= (t2 + 2*t3 + t4 + 2) >> 2; - SRC(0,6)=SRC(1,4)=SRC(2,2)=SRC(3,0)= (t3 + t4 + 1) >> 1; - SRC(0,7)=SRC(1,5)=SRC(2,3)=SRC(3,1)= (t3 + 2*t4 + t5 + 2) >> 2; - SRC(1,6)=SRC(2,4)=SRC(3,2)=SRC(4,0)= (t4 + t5 + 1) >> 1; - SRC(1,7)=SRC(2,5)=SRC(3,3)=SRC(4,1)= (t4 + 2*t5 + t6 + 2) >> 2; - SRC(2,6)=SRC(3,4)=SRC(4,2)=SRC(5,0)= (t5 + t6 + 1) >> 1; - SRC(2,7)=SRC(3,5)=SRC(4,3)=SRC(5,1)= (t5 + 2*t6 + t7 + 2) >> 2; - SRC(3,6)=SRC(4,4)=SRC(5,2)=SRC(6,0)= (t6 + t7 + 1) >> 1; - SRC(3,7)=SRC(4,5)=SRC(5,3)=SRC(6,1)= (t6 + 2*t7 + t8 + 2) >> 2; - SRC(4,6)=SRC(5,4)=SRC(6,2)=SRC(7,0)= (t7 + t8 + 1) >> 1; - SRC(4,7)=SRC(5,5)=SRC(6,3)=SRC(7,1)= (t7 + 2*t8 + t9 + 2) >> 2; - SRC(5,6)=SRC(6,4)=SRC(7,2)= (t8 + t9 + 1) >> 1; - SRC(5,7)=SRC(6,5)=SRC(7,3)= (t8 + 2*t9 + t10 + 2) >> 2; - SRC(6,6)=SRC(7,4)= (t9 + t10 + 1) >> 1; - SRC(6,7)=SRC(7,5)= (t9 + 2*t10 + t11 + 2) >> 2; - SRC(7,6)= (t10 + t11 + 1) >> 1; - SRC(7,7)= (t10 + 2*t11 + t12 + 2) >> 2; -} -static void pred8x8l_horizontal_up_c(uint8_t *src, int has_topleft, int has_topright, int stride) -{ - PREDICT_8x8_LOAD_LEFT; - SRC(0,0)= (l0 + l1 + 1) >> 1; - SRC(1,0)= (l0 + 2*l1 + l2 + 2) >> 2; - SRC(0,1)=SRC(2,0)= (l1 + l2 + 1) >> 1; - SRC(1,1)=SRC(3,0)= (l1 + 2*l2 + l3 + 2) >> 2; - SRC(0,2)=SRC(2,1)=SRC(4,0)= (l2 + l3 + 1) >> 1; - SRC(1,2)=SRC(3,1)=SRC(5,0)= (l2 + 2*l3 + l4 + 2) >> 2; - SRC(0,3)=SRC(2,2)=SRC(4,1)=SRC(6,0)= (l3 + l4 + 1) >> 1; - SRC(1,3)=SRC(3,2)=SRC(5,1)=SRC(7,0)= (l3 + 2*l4 + l5 + 2) >> 2; - SRC(0,4)=SRC(2,3)=SRC(4,2)=SRC(6,1)= (l4 + l5 + 1) >> 1; - SRC(1,4)=SRC(3,3)=SRC(5,2)=SRC(7,1)= (l4 + 2*l5 + l6 + 2) >> 2; - SRC(0,5)=SRC(2,4)=SRC(4,3)=SRC(6,2)= (l5 + l6 + 1) >> 1; - SRC(1,5)=SRC(3,4)=SRC(5,3)=SRC(7,2)= (l5 + 2*l6 + l7 + 2) >> 2; - SRC(0,6)=SRC(2,5)=SRC(4,4)=SRC(6,3)= (l6 + l7 + 1) >> 1; - SRC(1,6)=SRC(3,5)=SRC(5,4)=SRC(7,3)= (l6 + 3*l7 + 2) >> 2; - SRC(0,7)=SRC(1,7)=SRC(2,6)=SRC(2,7)=SRC(3,6)= - SRC(3,7)=SRC(4,5)=SRC(4,6)=SRC(4,7)=SRC(5,5)= - SRC(5,6)=SRC(5,7)=SRC(6,4)=SRC(6,5)=SRC(6,6)= - SRC(6,7)=SRC(7,4)=SRC(7,5)=SRC(7,6)=SRC(7,7)= l7; -} -#undef PREDICT_8x8_LOAD_LEFT -#undef PREDICT_8x8_LOAD_TOP -#undef PREDICT_8x8_LOAD_TOPLEFT -#undef PREDICT_8x8_LOAD_TOPRIGHT -#undef PREDICT_8x8_DC -#undef PTR -#undef PT -#undef PL -#undef SRC - static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square, int chroma_height, int delta, int list, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int src_x_offset, int src_y_offset, @@ -2762,7 +1684,7 @@ static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square, const int full_mx= mx>>2; const int full_my= my>>2; const int pic_width = 16*s->mb_width; - const int pic_height = 16*s->mb_height >> MB_MBAFF; + const int pic_height = 16*s->mb_height >> MB_FIELD; if(!pic->data[0]) //FIXME this is unacceptable, some senseable error concealment must be done for missing reference frames return; @@ -2784,11 +1706,11 @@ static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square, qpix_op[luma_xy](dest_y + delta, src_y + delta, h->mb_linesize); } - if(s->flags&CODEC_FLAG_GRAY) return; + if(ENABLE_GRAY && s->flags&CODEC_FLAG_GRAY) return; - if(MB_MBAFF){ + if(MB_FIELD){ // chroma offset when predicting from a field of opposite parity - my += 2 * ((s->mb_y & 1) - (h->ref_cache[list][scan8[n]] & 1)); + my += 2 * ((s->mb_y & 1) - (pic->reference - 1)); emu |= (my>>3) < 0 || (my>>3) + 8 >= (pic_height>>1); } src_cb= pic->data[1] + (mx>>3) + (my>>3)*h->mb_uvlinesize; @@ -2821,7 +1743,7 @@ static inline void mc_part_std(H264Context *h, int n, int square, int chroma_hei dest_cb += x_offset + y_offset*h->mb_uvlinesize; dest_cr += x_offset + y_offset*h->mb_uvlinesize; x_offset += 8*s->mb_x; - y_offset += 8*(s->mb_y >> MB_MBAFF); + y_offset += 8*(s->mb_y >> MB_FIELD); if(list0){ Picture *ref= &h->ref_list[0][ h->ref_cache[0][ scan8[n] ] ]; @@ -2854,7 +1776,7 @@ static inline void mc_part_weighted(H264Context *h, int n, int square, int chrom dest_cb += x_offset + y_offset*h->mb_uvlinesize; dest_cr += x_offset + y_offset*h->mb_uvlinesize; x_offset += 8*s->mb_x; - y_offset += 8*(s->mb_y >> MB_MBAFF); + y_offset += 8*(s->mb_y >> MB_FIELD); if(list0 && list1){ /* don't optimize for luma-only case, since B-frames usually @@ -3029,7 +1951,7 @@ static void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t prefetch_motion(h, 1); } -static void decode_init_vlc(){ +static void decode_init_vlc(void){ static int done = 0; if (!done) { @@ -3068,56 +1990,9 @@ static void decode_init_vlc(){ } } -/** - * Sets the intra prediction function pointers. - */ -static void init_pred_ptrs(H264Context *h){ -// MpegEncContext * const s = &h->s; - - h->pred4x4[VERT_PRED ]= pred4x4_vertical_c; - h->pred4x4[HOR_PRED ]= pred4x4_horizontal_c; - h->pred4x4[DC_PRED ]= pred4x4_dc_c; - h->pred4x4[DIAG_DOWN_LEFT_PRED ]= pred4x4_down_left_c; - h->pred4x4[DIAG_DOWN_RIGHT_PRED]= pred4x4_down_right_c; - h->pred4x4[VERT_RIGHT_PRED ]= pred4x4_vertical_right_c; - h->pred4x4[HOR_DOWN_PRED ]= pred4x4_horizontal_down_c; - h->pred4x4[VERT_LEFT_PRED ]= pred4x4_vertical_left_c; - h->pred4x4[HOR_UP_PRED ]= pred4x4_horizontal_up_c; - h->pred4x4[LEFT_DC_PRED ]= pred4x4_left_dc_c; - h->pred4x4[TOP_DC_PRED ]= pred4x4_top_dc_c; - h->pred4x4[DC_128_PRED ]= pred4x4_128_dc_c; - - h->pred8x8l[VERT_PRED ]= pred8x8l_vertical_c; - h->pred8x8l[HOR_PRED ]= pred8x8l_horizontal_c; - h->pred8x8l[DC_PRED ]= pred8x8l_dc_c; - h->pred8x8l[DIAG_DOWN_LEFT_PRED ]= pred8x8l_down_left_c; - h->pred8x8l[DIAG_DOWN_RIGHT_PRED]= pred8x8l_down_right_c; - h->pred8x8l[VERT_RIGHT_PRED ]= pred8x8l_vertical_right_c; - h->pred8x8l[HOR_DOWN_PRED ]= pred8x8l_horizontal_down_c; - h->pred8x8l[VERT_LEFT_PRED ]= pred8x8l_vertical_left_c; - h->pred8x8l[HOR_UP_PRED ]= pred8x8l_horizontal_up_c; - h->pred8x8l[LEFT_DC_PRED ]= pred8x8l_left_dc_c; - h->pred8x8l[TOP_DC_PRED ]= pred8x8l_top_dc_c; - h->pred8x8l[DC_128_PRED ]= pred8x8l_128_dc_c; - - h->pred8x8[DC_PRED8x8 ]= ff_pred8x8_dc_c; - h->pred8x8[VERT_PRED8x8 ]= ff_pred8x8_vertical_c; - h->pred8x8[HOR_PRED8x8 ]= ff_pred8x8_horizontal_c; - h->pred8x8[PLANE_PRED8x8 ]= ff_pred8x8_plane_c; - h->pred8x8[LEFT_DC_PRED8x8]= pred8x8_left_dc_c; - h->pred8x8[TOP_DC_PRED8x8 ]= pred8x8_top_dc_c; - h->pred8x8[DC_128_PRED8x8 ]= ff_pred8x8_128_dc_c; - - h->pred16x16[DC_PRED8x8 ]= ff_pred16x16_dc_c; - h->pred16x16[VERT_PRED8x8 ]= ff_pred16x16_vertical_c; - h->pred16x16[HOR_PRED8x8 ]= ff_pred16x16_horizontal_c; - h->pred16x16[PLANE_PRED8x8 ]= ff_pred16x16_plane_c; - h->pred16x16[LEFT_DC_PRED8x8]= pred16x16_left_dc_c; - h->pred16x16[TOP_DC_PRED8x8 ]= pred16x16_top_dc_c; - h->pred16x16[DC_128_PRED8x8 ]= ff_pred16x16_128_dc_c; -} - static void free_tables(H264Context *h){ + int i; + H264Context *hx; av_freep(&h->intra4x4_pred_mode); av_freep(&h->chroma_pred_mode_table); av_freep(&h->cbp_table); @@ -3126,14 +2001,24 @@ static void free_tables(H264Context *h){ av_freep(&h->direct_table); av_freep(&h->non_zero_count); av_freep(&h->slice_table_base); - av_freep(&h->top_borders[1]); - av_freep(&h->top_borders[0]); h->slice_table= NULL; av_freep(&h->mb2b_xy); av_freep(&h->mb2b8_xy); - av_freep(&h->s.obmc_scratchpad); + for(i = 0; i < MAX_SPS_COUNT; i++) + av_freep(h->sps_buffers + i); + + for(i = 0; i < MAX_PPS_COUNT; i++) + av_freep(h->pps_buffers + i); + + for(i = 0; i < h->s.avctx->thread_count; i++) { + hx = h->thread_context[i]; + if(!hx) continue; + av_freep(&hx->top_borders[1]); + av_freep(&hx->top_borders[0]); + av_freep(&hx->s.obmc_scratchpad); + } } static void init_dequant8_coeff_table(H264Context *h){ @@ -3214,16 +2099,12 @@ static int alloc_tables(H264Context *h){ CHECKED_ALLOCZ(h->non_zero_count , big_mb_num * 16 * sizeof(uint8_t)) CHECKED_ALLOCZ(h->slice_table_base , (big_mb_num+s->mb_stride) * sizeof(uint8_t)) - CHECKED_ALLOCZ(h->top_borders[0] , s->mb_width * (16+8+8) * sizeof(uint8_t)) - CHECKED_ALLOCZ(h->top_borders[1] , s->mb_width * (16+8+8) * sizeof(uint8_t)) CHECKED_ALLOCZ(h->cbp_table, big_mb_num * sizeof(uint16_t)) - if( h->pps.cabac ) { - CHECKED_ALLOCZ(h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t)) - CHECKED_ALLOCZ(h->mvd_table[0], 32*big_mb_num * sizeof(uint16_t)); - CHECKED_ALLOCZ(h->mvd_table[1], 32*big_mb_num * sizeof(uint16_t)); - CHECKED_ALLOCZ(h->direct_table, 32*big_mb_num * sizeof(uint8_t)); - } + CHECKED_ALLOCZ(h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t)) + CHECKED_ALLOCZ(h->mvd_table[0], 32*big_mb_num * sizeof(uint16_t)); + CHECKED_ALLOCZ(h->mvd_table[1], 32*big_mb_num * sizeof(uint16_t)); + CHECKED_ALLOCZ(h->direct_table, 32*big_mb_num * sizeof(uint8_t)); memset(h->slice_table_base, -1, (big_mb_num+s->mb_stride) * sizeof(uint8_t)); h->slice_table= h->slice_table_base + s->mb_stride*2 + 1; @@ -3252,6 +2133,38 @@ fail: return -1; } +/** + * Mimic alloc_tables(), but for every context thread. + */ +static void clone_tables(H264Context *dst, H264Context *src){ + dst->intra4x4_pred_mode = src->intra4x4_pred_mode; + dst->non_zero_count = src->non_zero_count; + dst->slice_table = src->slice_table; + dst->cbp_table = src->cbp_table; + dst->mb2b_xy = src->mb2b_xy; + dst->mb2b8_xy = src->mb2b8_xy; + dst->chroma_pred_mode_table = src->chroma_pred_mode_table; + dst->mvd_table[0] = src->mvd_table[0]; + dst->mvd_table[1] = src->mvd_table[1]; + dst->direct_table = src->direct_table; + + dst->s.obmc_scratchpad = NULL; + ff_h264_pred_init(&dst->hpc, src->s.codec_id); +} + +/** + * Init context + * Allocate buffers which are not shared amongst multiple threads. + */ +static int context_init(H264Context *h){ + CHECKED_ALLOCZ(h->top_borders[0], h->s.mb_width * (16+8+8) * sizeof(uint8_t)) + CHECKED_ALLOCZ(h->top_borders[1], h->s.mb_width * (16+8+8) * sizeof(uint8_t)) + + return 0; +fail: + return -1; // free_tables will clean up for us +} + static void common_init(H264Context *h){ MpegEncContext * const s = &h->s; @@ -3259,7 +2172,7 @@ static void common_init(H264Context *h){ s->height = s->avctx->height; s->codec_id= s->avctx->codec->id; - init_pred_ptrs(h); + ff_h264_pred_init(&h->hpc, s->codec_id); h->dequant_coeff_pps= -1; s->unrestricted_mv=1; @@ -3283,6 +2196,7 @@ static int decode_init(AVCodecContext *avctx){ // set defaults // s->decode_mb= ff_h263_decode_mb; + s->quarter_sample = 1; s->low_delay= 1; avctx->pix_fmt= PIX_FMT_YUV420P; @@ -3296,6 +2210,7 @@ static int decode_init(AVCodecContext *avctx){ h->is_avc = 0; } + h->thread_context[0] = h; return 0; } @@ -3306,6 +2221,13 @@ static int frame_start(H264Context *h){ if(MPV_frame_start(s, s->avctx) < 0) return -1; ff_er_frame_start(s); + /* + * MPV_frame_start uses pict_type to derive key_frame. + * This is incorrect for H.264; IDR markings must be used. + * Zero here; IDR markings per slice in frame or fields are OR'd in later. + * See decode_nal_units(). + */ + s->current_picture_ptr->key_frame= 0; assert(s->linesize && s->uvlinesize); @@ -3322,18 +2244,19 @@ static int frame_start(H264Context *h){ /* can't be in alloc_tables because linesize isn't known there. * FIXME: redo bipred weight to not require extra buffer? */ - if(!s->obmc_scratchpad) - s->obmc_scratchpad = av_malloc(16*2*s->linesize + 8*2*s->uvlinesize); + for(i = 0; i < s->avctx->thread_count; i++) + if(!h->thread_context[i]->s.obmc_scratchpad) + h->thread_context[i]->s.obmc_scratchpad = av_malloc(16*2*s->linesize + 8*2*s->uvlinesize); /* some macroblocks will be accessed before they're available */ - if(FRAME_MBAFF) + if(FRAME_MBAFF || s->avctx->thread_count > 1) memset(h->slice_table, -1, (s->mb_height*s->mb_stride-1) * sizeof(uint8_t)); // s->decode= (s->flags&CODEC_FLAG_PSNR) || !s->encoding || s->current_picture.reference /*|| h->contains_intra*/ || 1; return 0; } -static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize){ +static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize, int simple){ MpegEncContext * const s = &h->s; int i; @@ -3351,7 +2274,7 @@ static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src *(uint64_t*)(h->top_borders[0][s->mb_x]+0)= *(uint64_t*)(src_y + 16*linesize); *(uint64_t*)(h->top_borders[0][s->mb_x]+8)= *(uint64_t*)(src_y +8+16*linesize); - if(!(s->flags&CODEC_FLAG_GRAY)){ + if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ h->left_border[17 ]= h->top_borders[0][s->mb_x][16+7]; h->left_border[17+9]= h->top_borders[0][s->mb_x][24+7]; for(i=1; i<9; i++){ @@ -3363,12 +2286,22 @@ static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src } } -static inline void xchg_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize, int xchg){ +static inline void xchg_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize, int xchg, int simple){ MpegEncContext * const s = &h->s; int temp8, i; uint64_t temp64; - int deblock_left = (s->mb_x > 0); - int deblock_top = (s->mb_y > 0); + int deblock_left; + int deblock_top; + int mb_xy; + + if(h->deblocking_filter == 2) { + mb_xy = s->mb_x + s->mb_y*s->mb_stride; + deblock_left = h->slice_table[mb_xy] == h->slice_table[mb_xy - 1]; + deblock_top = h->slice_table[mb_xy] == h->slice_table[h->top_mb_xy]; + } else { + deblock_left = (s->mb_x > 0); + deblock_top = (s->mb_y > 0); + } src_y -= linesize + 1; src_cb -= uvlinesize + 1; @@ -3394,7 +2327,7 @@ b= t; } } - if(!(s->flags&CODEC_FLAG_GRAY)){ + if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ if(deblock_left){ for(i = !deblock_top; i<9; i++){ XCHG(h->left_border[i+17 ], src_cb[i*uvlinesize], temp8, xchg); @@ -3429,7 +2362,7 @@ static inline void backup_pair_border(H264Context *h, uint8_t *src_y, uint8_t *s *(uint64_t*)(h->top_borders[1][s->mb_x]+0)= *(uint64_t*)(src_y + 33*linesize); *(uint64_t*)(h->top_borders[1][s->mb_x]+8)= *(uint64_t*)(src_y +8+33*linesize); - if(!(s->flags&CODEC_FLAG_GRAY)){ + if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ h->left_border[34 ]= h->top_borders[0][s->mb_x][16+7]; h->left_border[34+ 1]= h->top_borders[1][s->mb_x][16+7]; h->left_border[34+18 ]= h->top_borders[0][s->mb_x][24+7]; @@ -3481,7 +2414,7 @@ b= t; } } - if(!(s->flags&CODEC_FLAG_GRAY)){ + if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ if(deblock_left){ for(i = (!deblock_top) << 1; i<18; i++){ XCHG(h->left_border[i+34 ], src_cb[i*uvlinesize], temp8, xchg); @@ -3497,7 +2430,7 @@ b= t; } } -static void av_always_inline hl_decode_mb_internal(H264Context *h, int simple){ +static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){ MpegEncContext * const s = &h->s; const int mb_x= s->mb_x; const int mb_y= s->mb_y; @@ -3535,13 +2468,13 @@ static void av_always_inline hl_decode_mb_internal(H264Context *h, int simple){ continue; if(IS_16X16(mb_type)){ int8_t *ref = &h->ref_cache[list][scan8[0]]; - fill_rectangle(ref, 4, 4, 8, 16+*ref^(s->mb_y&1), 1); + fill_rectangle(ref, 4, 4, 8, (16+*ref)^(s->mb_y&1), 1); }else{ for(i=0; i<16; i+=4){ //FIXME can refs be smaller than 8x8 when !direct_8x8_inference ? int ref = h->ref_cache[list][scan8[i]]; if(ref >= 0) - fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2, 8, 16+ref^(s->mb_y&1), 1); + fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2, 8, (16+ref)^(s->mb_y&1), 1); } } } @@ -3601,11 +2534,11 @@ static void av_always_inline hl_decode_mb_internal(H264Context *h, int simple){ } else { if(IS_INTRA(mb_type)){ if(h->deblocking_filter && (simple || !FRAME_MBAFF)) - xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 1); + xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 1, simple); - if(simple || !(s->flags&CODEC_FLAG_GRAY)){ - h->pred8x8[ h->chroma_pred_mode ](dest_cb, uvlinesize); - h->pred8x8[ h->chroma_pred_mode ](dest_cr, uvlinesize); + if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ + h->hpc.pred8x8[ h->chroma_pred_mode ](dest_cb, uvlinesize); + h->hpc.pred8x8[ h->chroma_pred_mode ](dest_cr, uvlinesize); } if(IS_INTRA4x4(mb_type)){ @@ -3615,7 +2548,7 @@ static void av_always_inline hl_decode_mb_internal(H264Context *h, int simple){ uint8_t * const ptr= dest_y + block_offset[i]; const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ]; const int nnz = h->non_zero_count_cache[ scan8[i] ]; - h->pred8x8l[ dir ](ptr, (h->topleft_samples_available<hpc.pred8x8l[ dir ](ptr, (h->topleft_samples_available<topright_samples_available<mb[i*16]) @@ -3642,7 +2575,7 @@ static void av_always_inline hl_decode_mb_internal(H264Context *h, int simple){ }else topright= NULL; - h->pred4x4[ dir ](ptr, topright, linesize); + h->hpc.pred4x4[ dir ](ptr, topright, linesize); nnz = h->non_zero_count_cache[ scan8[i] ]; if(nnz){ if(is_h264){ @@ -3656,15 +2589,15 @@ static void av_always_inline hl_decode_mb_internal(H264Context *h, int simple){ } } }else{ - h->pred16x16[ h->intra16x16_pred_mode ](dest_y , linesize); + h->hpc.pred16x16[ h->intra16x16_pred_mode ](dest_y , linesize); if(is_h264){ if(!transform_bypass) - h264_luma_dc_dequant_idct_c(h->mb, s->qscale, h->dequant4_coeff[IS_INTRA(mb_type) ? 0:3][s->qscale][0]); + h264_luma_dc_dequant_idct_c(h->mb, s->qscale, h->dequant4_coeff[0][s->qscale][0]); }else svq3_luma_dc_dequant_idct_c(h->mb, s->qscale); } if(h->deblocking_filter && (simple || !FRAME_MBAFF)) - xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0); + xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0, simple); }else if(is_h264){ hl_motion(h, dest_y, dest_cb, dest_cr, s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab, @@ -3704,15 +2637,15 @@ static void av_always_inline hl_decode_mb_internal(H264Context *h, int simple){ } } - if(simple || !(s->flags&CODEC_FLAG_GRAY)){ + if(simple || !ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ uint8_t *dest[2] = {dest_cb, dest_cr}; if(transform_bypass){ idct_add = idct_dc_add = s->dsp.add_pixels4; }else{ idct_add = s->dsp.h264_idct_add; idct_dc_add = s->dsp.h264_idct_dc_add; - chroma_dc_dequant_idct_c(h->mb + 16*16, h->chroma_qp, h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp][0]); - chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->chroma_qp, h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp][0]); + chroma_dc_dequant_idct_c(h->mb + 16*16, h->chroma_qp[0], h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp[0]][0]); + chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->chroma_qp[1], h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp[1]][0]); } if(is_h264){ for(i=16; i<16+8; i++){ @@ -3754,17 +2687,19 @@ static void av_always_inline hl_decode_mb_internal(H264Context *h, int simple){ s->mb_y--; tprintf(h->s.avctx, "call mbaff filter_mb mb_x:%d mb_y:%d pair_dest_y = %p, dest_y = %p\n", mb_x, mb_y, pair_dest_y, dest_y); fill_caches(h, mb_type_top, 1); //FIXME don't fill stuff which isn't used by filter_mb - h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mb_xy]); + h->chroma_qp[0] = get_chroma_qp(h, 0, s->current_picture.qscale_table[mb_xy]); + h->chroma_qp[1] = get_chroma_qp(h, 1, s->current_picture.qscale_table[mb_xy]); filter_mb(h, mb_x, mb_y, pair_dest_y, pair_dest_cb, pair_dest_cr, linesize, uvlinesize); // bottom s->mb_y++; tprintf(h->s.avctx, "call mbaff filter_mb\n"); fill_caches(h, mb_type_bottom, 1); //FIXME don't fill stuff which isn't used by filter_mb - h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mb_xy+s->mb_stride]); + h->chroma_qp[0] = get_chroma_qp(h, 0, s->current_picture.qscale_table[mb_xy+s->mb_stride]); + h->chroma_qp[1] = get_chroma_qp(h, 1, s->current_picture.qscale_table[mb_xy+s->mb_stride]); filter_mb(h, mb_x, mb_y+1, dest_y, dest_cb, dest_cr, linesize, uvlinesize); } else { tprintf(h->s.avctx, "call filter_mb\n"); - backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize); + backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, simple); fill_caches(h, mb_type, 1); //FIXME don't fill stuff which isn't used by filter_mb filter_mb_fast(h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize); } @@ -3791,7 +2726,7 @@ static void hl_decode_mb(H264Context *h){ const int mb_y= s->mb_y; const int mb_xy= mb_x + mb_y*s->mb_stride; const int mb_type= s->current_picture.mb_type[mb_xy]; - int is_complex = FRAME_MBAFF || MB_FIELD || IS_INTRA_PCM(mb_type) || s->codec_id != CODEC_ID_H264 || (s->flags&CODEC_FLAG_GRAY) || s->encoding; + int is_complex = FRAME_MBAFF || MB_FIELD || IS_INTRA_PCM(mb_type) || s->codec_id != CODEC_ID_H264 || (ENABLE_GRAY && (s->flags&CODEC_FLAG_GRAY)) || s->encoding; if(!s->decode) return; @@ -3801,6 +2736,105 @@ static void hl_decode_mb(H264Context *h){ else hl_decode_mb_simple(h); } +static void pic_as_field(Picture *pic, const int parity){ + int i; + for (i = 0; i < 4; ++i) { + if (parity == PICT_BOTTOM_FIELD) + pic->data[i] += pic->linesize[i]; + pic->reference = parity; + pic->linesize[i] *= 2; + } +} + +static int split_field_copy(Picture *dest, Picture *src, + int parity, int id_add){ + int match = !!(src->reference & parity); + + if (match) { + *dest = *src; + pic_as_field(dest, parity); + dest->pic_id *= 2; + dest->pic_id += id_add; + } + + return match; +} + +/** + * Split one reference list into field parts, interleaving by parity + * as per H.264 spec section 8.2.4.2.5. Output fields have their data pointers + * set to look at the actual start of data for that field. + * + * @param dest output list + * @param dest_len maximum number of fields to put in dest + * @param src the source reference list containing fields and/or field pairs + * (aka short_ref/long_ref, or + * refFrameListXShortTerm/refFrameListLongTerm in spec-speak) + * @param src_len number of Picture's in source (pairs and unmatched fields) + * @param parity the parity of the picture being decoded/needing + * these ref pics (PICT_{TOP,BOTTOM}_FIELD) + * @return number of fields placed in dest + */ +static int split_field_half_ref_list(Picture *dest, int dest_len, + Picture *src, int src_len, int parity){ + int same_parity = 1; + int same_i = 0; + int opp_i = 0; + int out_i; + int field_output; + + for (out_i = 0; out_i < dest_len; out_i += field_output) { + if (same_parity && same_i < src_len) { + field_output = split_field_copy(dest + out_i, src + same_i, + parity, 1); + same_parity = !field_output; + same_i++; + + } else if (opp_i < src_len) { + field_output = split_field_copy(dest + out_i, src + opp_i, + PICT_FRAME - parity, 0); + same_parity = field_output; + opp_i++; + + } else { + break; + } + } + + return out_i; +} + +/** + * Split the reference frame list into a reference field list. + * This implements H.264 spec 8.2.4.2.5 for a combined input list. + * The input list contains both reference field pairs and + * unmatched reference fields; it is ordered as spec describes + * RefPicListX for frames in 8.2.4.2.1 and 8.2.4.2.3, except that + * unmatched field pairs are also present. Conceptually this is equivalent + * to concatenation of refFrameListXShortTerm with refFrameListLongTerm. + * + * @param dest output reference list where ordered fields are to be placed + * @param dest_len max number of fields to place at dest + * @param src source reference list, as described above + * @param src_len number of pictures (pairs and unmatched fields) in src + * @param parity parity of field being currently decoded + * (one of PICT_{TOP,BOTTOM}_FIELD) + * @param long_i index into src array that holds first long reference picture, + * or src_len if no long refs present. + */ +static int split_field_ref_list(Picture *dest, int dest_len, + Picture *src, int src_len, + int parity, int long_i){ + + int i = split_field_half_ref_list(dest, dest_len, src, long_i, parity); + dest += i; + dest_len -= i; + + i += split_field_half_ref_list(dest, dest_len, src + long_i, + src_len - long_i, parity); + return i; +} + /** * fills the default_ref_list. */ @@ -3808,9 +2842,25 @@ static int fill_default_ref_list(H264Context *h){ MpegEncContext * const s = &h->s; int i; int smallest_poc_greater_than_current = -1; + int structure_sel; Picture sorted_short_ref[32]; + Picture field_entry_list[2][32]; + Picture *frame_list[2]; + + if (FIELD_PICTURE) { + structure_sel = PICT_FRAME; + frame_list[0] = field_entry_list[0]; + frame_list[1] = field_entry_list[1]; + } else { + structure_sel = 0; + frame_list[0] = h->default_ref_list[0]; + frame_list[1] = h->default_ref_list[1]; + } if(h->slice_type==B_TYPE){ + int list; + int len[2]; + int short_len[2]; int out_i; int limit= INT_MIN; @@ -3838,71 +2888,92 @@ static int fill_default_ref_list(H264Context *h){ } } } - } - if(s->picture_structure == PICT_FRAME){ - if(h->slice_type==B_TYPE){ - int list; - tprintf(h->s.avctx, "current poc: %d, smallest_poc_greater_than_current: %d\n", s->current_picture_ptr->poc, smallest_poc_greater_than_current); + tprintf(h->s.avctx, "current poc: %d, smallest_poc_greater_than_current: %d\n", s->current_picture_ptr->poc, smallest_poc_greater_than_current); - // find the largest poc - for(list=0; list<2; list++){ - int index = 0; - int j= -99; - int step= list ? -1 : 1; - - for(i=0; ishort_ref_count && index < h->ref_count[list]; i++, j+=step) { - while(j<0 || j>= h->short_ref_count){ - if(j != -99 && step == (list ? -1 : 1)) - return -1; - step = -step; - j= smallest_poc_greater_than_current + (step>>1); - } - if(sorted_short_ref[j].reference != 3) continue; - h->default_ref_list[list][index ]= sorted_short_ref[j]; - h->default_ref_list[list][index++].pic_id= sorted_short_ref[j].frame_num; + // find the largest poc + for(list=0; list<2; list++){ + int index = 0; + int j= -99; + int step= list ? -1 : 1; + + for(i=0; ishort_ref_count && index < h->ref_count[list]; i++, j+=step) { + int sel; + while(j<0 || j>= h->short_ref_count){ + if(j != -99 && step == (list ? -1 : 1)) + return -1; + step = -step; + j= smallest_poc_greater_than_current + (step>>1); } + sel = sorted_short_ref[j].reference | structure_sel; + if(sel != PICT_FRAME) continue; + frame_list[list][index ]= sorted_short_ref[j]; + frame_list[list][index++].pic_id= sorted_short_ref[j].frame_num; + } + short_len[list] = index; - for(i = 0; i < 16 && index < h->ref_count[ list ]; i++){ - if(h->long_ref[i] == NULL) continue; - if(h->long_ref[i]->reference != 3) continue; + for(i = 0; i < 16 && index < h->ref_count[ list ]; i++){ + int sel; + if(h->long_ref[i] == NULL) continue; + sel = h->long_ref[i]->reference | structure_sel; + if(sel != PICT_FRAME) continue; - h->default_ref_list[ list ][index ]= *h->long_ref[i]; - h->default_ref_list[ list ][index++].pic_id= i;; - } + frame_list[ list ][index ]= *h->long_ref[i]; + frame_list[ list ][index++].pic_id= i; + } + len[list] = index; + } - if(list && (smallest_poc_greater_than_current<=0 || smallest_poc_greater_than_current>=h->short_ref_count) && (1 < index)){ - // swap the two first elements of L1 when - // L0 and L1 are identical - Picture temp= h->default_ref_list[1][0]; - h->default_ref_list[1][0] = h->default_ref_list[1][1]; - h->default_ref_list[1][1] = temp; - } + for(list=0; list<2; list++){ + if (FIELD_PICTURE) + len[list] = split_field_ref_list(h->default_ref_list[list], + h->ref_count[list], + frame_list[list], + len[list], + s->picture_structure, + short_len[list]); + + // swap the two first elements of L1 when L0 and L1 are identical + if(list && len[0] > 1 && len[0] == len[1]) + for(i=0; h->default_ref_list[0][i].data[0] == h->default_ref_list[1][i].data[0]; i++) + if(i == len[0]){ + FFSWAP(Picture, h->default_ref_list[1][0], h->default_ref_list[1][1]); + break; + } - if(index < h->ref_count[ list ]) - memset(&h->default_ref_list[list][index], 0, sizeof(Picture)*(h->ref_count[ list ] - index)); - } - }else{ - int index=0; - for(i=0; ishort_ref_count; i++){ - if(h->short_ref[i]->reference != 3) continue; //FIXME refernce field shit - h->default_ref_list[0][index ]= *h->short_ref[i]; - h->default_ref_list[0][index++].pic_id= h->short_ref[i]->frame_num; - } - for(i = 0; i < 16; i++){ - if(h->long_ref[i] == NULL) continue; - if(h->long_ref[i]->reference != 3) continue; - h->default_ref_list[0][index ]= *h->long_ref[i]; - h->default_ref_list[0][index++].pic_id= i;; - } - if(index < h->ref_count[0]) - memset(&h->default_ref_list[0][index], 0, sizeof(Picture)*(h->ref_count[0] - index)); + if(len[list] < h->ref_count[ list ]) + memset(&h->default_ref_list[list][len[list]], 0, sizeof(Picture)*(h->ref_count[ list ] - len[list])); } - }else{ //FIELD - if(h->slice_type==B_TYPE){ - }else{ - //FIXME second field balh + + + }else{ + int index=0; + int short_len; + for(i=0; ishort_ref_count; i++){ + int sel; + sel = h->short_ref[i]->reference | structure_sel; + if(sel != PICT_FRAME) continue; + frame_list[0][index ]= *h->short_ref[i]; + frame_list[0][index++].pic_id= h->short_ref[i]->frame_num; + } + short_len = index; + for(i = 0; i < 16; i++){ + int sel; + if(h->long_ref[i] == NULL) continue; + sel = h->long_ref[i]->reference | structure_sel; + if(sel != PICT_FRAME) continue; + frame_list[0][index ]= *h->long_ref[i]; + frame_list[0][index++].pic_id= i; } + + if (FIELD_PICTURE) + index = split_field_ref_list(h->default_ref_list[0], + h->ref_count[0], frame_list[0], + index, s->picture_structure, + short_len); + + if(index < h->ref_count[0]) + memset(&h->default_ref_list[0][index], 0, sizeof(Picture)*(h->ref_count[0] - index)); } #ifdef TRACE for (i=0; iref_count[0]; i++) { @@ -3910,7 +2981,7 @@ static int fill_default_ref_list(H264Context *h){ } if(h->slice_type==B_TYPE){ for (i=0; iref_count[1]; i++) { - tprintf(h->s.avctx, "List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, h->default_ref_list[0][i].data[0]); + tprintf(h->s.avctx, "List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, h->default_ref_list[1][i].data[0]); } } #endif @@ -3920,9 +2991,33 @@ static int fill_default_ref_list(H264Context *h){ static void print_short_term(H264Context *h); static void print_long_term(H264Context *h); +/** + * Extract structure information about the picture described by pic_num in + * the current decoding context (frame or field). Note that pic_num is + * picture number without wrapping (so, 0<=pic_nums; + + *structure = s->picture_structure; + if(FIELD_PICTURE){ + if (!(pic_num & 1)) + /* opposite field */ + *structure ^= PICT_FRAME; + pic_num >>= 1; + } + + return pic_num; +} + static int decode_ref_pic_list_reordering(H264Context *h){ MpegEncContext * const s = &h->s; - int list, index; + int list, index, pic_structure; print_short_term(h); print_long_term(h); @@ -3951,8 +3046,9 @@ static int decode_ref_pic_list_reordering(H264Context *h){ if(reordering_of_pic_nums_idc<3){ if(reordering_of_pic_nums_idc<2){ const unsigned int abs_diff_pic_num= get_ue_golomb(&s->gb) + 1; + int frame_num; - if(abs_diff_pic_num >= h->max_pic_num){ + if(abs_diff_pic_num > h->max_pic_num){ av_log(h->s.avctx, AV_LOG_ERROR, "abs_diff_pic_num overflow\n"); return -1; } @@ -3961,25 +3057,34 @@ static int decode_ref_pic_list_reordering(H264Context *h){ else pred+= abs_diff_pic_num; pred &= h->max_pic_num - 1; + frame_num = pic_num_extract(h, pred, &pic_structure); + for(i= h->short_ref_count-1; i>=0; i--){ ref = h->short_ref[i]; - assert(ref->reference == 3); + assert(ref->reference); assert(!ref->long_ref); - if(ref->data[0] != NULL && ref->frame_num == pred && ref->long_ref == 0) // ignore non existing pictures by testing data[0] pointer + if(ref->data[0] != NULL && + ref->frame_num == frame_num && + (ref->reference & pic_structure) && + ref->long_ref == 0) // ignore non existing pictures by testing data[0] pointer break; } if(i>=0) - ref->pic_id= ref->frame_num; + ref->pic_id= pred; }else{ + int long_idx; pic_id= get_ue_golomb(&s->gb); //long_term_pic_idx - if(pic_id>31){ + + long_idx= pic_num_extract(h, pic_id, &pic_structure); + + if(long_idx>31){ av_log(h->s.avctx, AV_LOG_ERROR, "long_term_pic_idx overflow\n"); return -1; } - ref = h->long_ref[pic_id]; - if(ref){ + ref = h->long_ref[long_idx]; + assert(!(ref && !ref->reference)); + if(ref && (ref->reference & pic_structure)){ ref->pic_id= pic_id; - assert(ref->reference == 3); assert(ref->long_ref); i=0; }else{ @@ -3999,6 +3104,9 @@ static int decode_ref_pic_list_reordering(H264Context *h){ h->ref_list[list][i]= h->ref_list[list][i-1]; } h->ref_list[list][index]= *ref; + if (FIELD_PICTURE){ + pic_as_field(&h->ref_list[list][index], pic_structure); + } } }else{ av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n"); @@ -4029,9 +3137,11 @@ static void fill_mbaff_ref_list(H264Context *h){ field[0] = *frame; for(j=0; j<3; j++) field[0].linesize[j] <<= 1; + field[0].reference = PICT_TOP_FIELD; field[1] = field[0]; for(j=0; j<3; j++) field[1].data[j] += frame->linesize[j]; + field[1].reference = PICT_BOTTOM_FIELD; h->luma_weight[list][16+2*i] = h->luma_weight[list][16+2*i+1] = h->luma_weight[list][i]; h->luma_offset[list][16+2*i] = h->luma_offset[list][16+2*i+1] = h->luma_offset[list][i]; @@ -4137,17 +3247,32 @@ static void implicit_weight_table(H264Context *h){ } } -static inline void unreference_pic(H264Context *h, Picture *pic){ +/** + * Mark a picture as no longer needed for reference. The refmask + * argument allows unreferencing of individual fields or the whole frame. + * If the picture becomes entirely unreferenced, but is being held for + * display purposes, it is marked as such. + * @param refmask mask of fields to unreference; the mask is bitwise + * anded with the reference marking of pic + * @return non-zero if pic becomes entirely unreferenced (except possibly + * for display purposes) zero if one of the fields remains in + * reference + */ +static inline int unreference_pic(H264Context *h, Picture *pic, int refmask){ int i; - pic->reference=0; - if(pic == h->delayed_output_pic) - pic->reference=1; - else{ - for(i = 0; h->delayed_pic[i]; i++) - if(pic == h->delayed_pic[i]){ - pic->reference=1; - break; - } + if (pic->reference &= refmask) { + return 0; + } else { + if(pic == h->delayed_output_pic) + pic->reference=DELAYED_PIC_REF; + else{ + for(i = 0; h->delayed_pic[i]; i++) + if(pic == h->delayed_pic[i]){ + pic->reference=DELAYED_PIC_REF; + break; + } + } + return 1; } } @@ -4159,14 +3284,14 @@ static void idr(H264Context *h){ for(i=0; i<16; i++){ if (h->long_ref[i] != NULL) { - unreference_pic(h, h->long_ref[i]); + unreference_pic(h, h->long_ref[i], 0); h->long_ref[i]= NULL; } } h->long_ref_count=0; for(i=0; ishort_ref_count; i++){ - unreference_pic(h, h->short_ref[i]); + unreference_pic(h, h->short_ref[i], 0); h->short_ref[i]= NULL; } h->short_ref_count=0; @@ -4187,33 +3312,77 @@ static void flush_dpb(AVCodecContext *avctx){ idr(h); if(h->s.current_picture_ptr) h->s.current_picture_ptr->reference= 0; + h->s.first_field= 0; + ff_mpeg_flush(avctx); } /** - * - * @return the removed picture or NULL if an error occurs + * Find a Picture in the short term reference list by frame number. + * @param frame_num frame number to search for + * @param idx the index into h->short_ref where returned picture is found + * undefined if no picture found. + * @return pointer to the found picture, or NULL if no pic with the provided + * frame number is found */ -static Picture * remove_short(H264Context *h, int frame_num){ +static Picture * find_short(H264Context *h, int frame_num, int *idx){ MpegEncContext * const s = &h->s; int i; - if(s->avctx->debug&FF_DEBUG_MMCO) - av_log(h->s.avctx, AV_LOG_DEBUG, "remove short %d count %d\n", frame_num, h->short_ref_count); - for(i=0; ishort_ref_count; i++){ Picture *pic= h->short_ref[i]; if(s->avctx->debug&FF_DEBUG_MMCO) av_log(h->s.avctx, AV_LOG_DEBUG, "%d %d %p\n", i, pic->frame_num, pic); - if(pic->frame_num == frame_num){ - h->short_ref[i]= NULL; - memmove(&h->short_ref[i], &h->short_ref[i+1], (h->short_ref_count - i - 1)*sizeof(Picture*)); - h->short_ref_count--; + if(pic->frame_num == frame_num) { + *idx = i; return pic; } } return NULL; } +/** + * Remove a picture from the short term reference list by its index in + * that list. This does no checking on the provided index; it is assumed + * to be valid. Other list entries are shifted down. + * @param i index into h->short_ref of picture to remove. + */ +static void remove_short_at_index(H264Context *h, int i){ + assert(i > 0 && i < h->short_ref_count); + h->short_ref[i]= NULL; + if (--h->short_ref_count) + memmove(&h->short_ref[i], &h->short_ref[i+1], (h->short_ref_count - i)*sizeof(Picture*)); +} + +/** + * + * @return the removed picture or NULL if an error occurs + */ +static Picture * remove_short(H264Context *h, int frame_num){ + MpegEncContext * const s = &h->s; + Picture *pic; + int i; + + if(s->avctx->debug&FF_DEBUG_MMCO) + av_log(h->s.avctx, AV_LOG_DEBUG, "remove short %d count %d\n", frame_num, h->short_ref_count); + + pic = find_short(h, frame_num, &i); + if (pic) + remove_short_at_index(h, i); + + return pic; +} + +/** + * Remove a picture from the long term reference list by its index in + * that list. This does no checking on the provided index; it is assumed + * to be valid. The removed entry is set to NULL. Other entries are unaffected. + * @param i index into h->long_ref of picture to remove. + */ +static void remove_long_at_index(H264Context *h, int i){ + h->long_ref[i]= NULL; + h->long_ref_count--; +} + /** * * @return the removed picture or NULL if an error occurs @@ -4222,8 +3391,8 @@ static Picture * remove_long(H264Context *h, int i){ Picture *pic; pic= h->long_ref[i]; - h->long_ref[i]= NULL; - if(pic) h->long_ref_count--; + if (pic) + remove_long_at_index(h, i); return pic; } @@ -4264,77 +3433,143 @@ static void print_long_term(H264Context *h) { static int execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ MpegEncContext * const s = &h->s; int i, j; - int current_is_long=0; + int current_ref_assigned=0; Picture *pic; if((s->avctx->debug&FF_DEBUG_MMCO) && mmco_count==0) av_log(h->s.avctx, AV_LOG_DEBUG, "no mmco here\n"); for(i=0; iavctx->debug&FF_DEBUG_MMCO) - av_log(h->s.avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode, h->mmco[i].short_frame_num, h->mmco[i].long_index); + av_log(h->s.avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode, h->mmco[i].short_pic_num, h->mmco[i].long_arg); switch(mmco[i].opcode){ case MMCO_SHORT2UNUSED: - pic= remove_short(h, mmco[i].short_frame_num); - if(pic) - unreference_pic(h, pic); - else if(s->avctx->debug&FF_DEBUG_MMCO) - av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: remove_short() failure\n"); + if(s->avctx->debug&FF_DEBUG_MMCO) + av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: unref short %d count %d\n", h->mmco[i].short_pic_num, h->short_ref_count); + frame_num = pic_num_extract(h, mmco[i].short_pic_num, &structure); + pic = find_short(h, frame_num, &j); + if (pic) { + if (unreference_pic(h, pic, structure ^ PICT_FRAME)) + remove_short_at_index(h, j); + } else if(s->avctx->debug&FF_DEBUG_MMCO) + av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: unref short failure\n"); break; case MMCO_SHORT2LONG: - pic= remove_long(h, mmco[i].long_index); - if(pic) unreference_pic(h, pic); + if (FIELD_PICTURE && mmco[i].long_arg < h->long_ref_count && + h->long_ref[mmco[i].long_arg]->frame_num == + mmco[i].short_pic_num / 2) { + /* do nothing, we've already moved this field pair. */ + } else { + int frame_num = mmco[i].short_pic_num >> FIELD_PICTURE; - h->long_ref[ mmco[i].long_index ]= remove_short(h, mmco[i].short_frame_num); - if (h->long_ref[ mmco[i].long_index ]){ - h->long_ref[ mmco[i].long_index ]->long_ref=1; - h->long_ref_count++; + pic= remove_long(h, mmco[i].long_arg); + if(pic) unreference_pic(h, pic, 0); + + h->long_ref[ mmco[i].long_arg ]= remove_short(h, frame_num); + if (h->long_ref[ mmco[i].long_arg ]){ + h->long_ref[ mmco[i].long_arg ]->long_ref=1; + h->long_ref_count++; + } } break; case MMCO_LONG2UNUSED: - pic= remove_long(h, mmco[i].long_index); - if(pic) - unreference_pic(h, pic); - else if(s->avctx->debug&FF_DEBUG_MMCO) - av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: remove_long() failure\n"); + j = pic_num_extract(h, mmco[i].long_arg, &structure); + pic = h->long_ref[j]; + if (pic) { + if (unreference_pic(h, pic, structure ^ PICT_FRAME)) + remove_long_at_index(h, j); + } else if(s->avctx->debug&FF_DEBUG_MMCO) + av_log(h->s.avctx, AV_LOG_DEBUG, "mmco: unref long failure\n"); break; case MMCO_LONG: - pic= remove_long(h, mmco[i].long_index); - if(pic) unreference_pic(h, pic); + unref_pic = 1; + if (FIELD_PICTURE && !s->first_field) { + if (h->long_ref[mmco[i].long_arg] == s->current_picture_ptr) { + /* Just mark second field as referenced */ + unref_pic = 0; + } else if (s->current_picture_ptr->reference) { + /* First field in pair is in short term list or + * at a different long term index. + * This is not allowed; see 7.4.3, notes 2 and 3. + * Report the problem and keep the pair where it is, + * and mark this field valid. + */ + av_log(h->s.avctx, AV_LOG_ERROR, + "illegal long term reference assignment for second " + "field in complementary field pair (first field is " + "short term or has non-matching long index)\n"); + unref_pic = 0; + } + } - h->long_ref[ mmco[i].long_index ]= s->current_picture_ptr; - h->long_ref[ mmco[i].long_index ]->long_ref=1; - h->long_ref_count++; + if (unref_pic) { + pic= remove_long(h, mmco[i].long_arg); + if(pic) unreference_pic(h, pic, 0); - current_is_long=1; + h->long_ref[ mmco[i].long_arg ]= s->current_picture_ptr; + h->long_ref[ mmco[i].long_arg ]->long_ref=1; + h->long_ref_count++; + } + + s->current_picture_ptr->reference |= s->picture_structure; + current_ref_assigned=1; break; case MMCO_SET_MAX_LONG: - assert(mmco[i].long_index <= 16); + assert(mmco[i].long_arg <= 16); // just remove the long term which index is greater than new max - for(j = mmco[i].long_index; j<16; j++){ + for(j = mmco[i].long_arg; j<16; j++){ pic = remove_long(h, j); - if (pic) unreference_pic(h, pic); + if (pic) unreference_pic(h, pic, 0); } break; case MMCO_RESET: while(h->short_ref_count){ pic= remove_short(h, h->short_ref[0]->frame_num); - if(pic) unreference_pic(h, pic); + if(pic) unreference_pic(h, pic, 0); } for(j = 0; j < 16; j++) { pic= remove_long(h, j); - if(pic) unreference_pic(h, pic); + if(pic) unreference_pic(h, pic, 0); } break; default: assert(0); } } - if(!current_is_long){ + if (!current_ref_assigned && FIELD_PICTURE && + !s->first_field && s->current_picture_ptr->reference) { + + /* Second field of complementary field pair; the first field of + * which is already referenced. If short referenced, it + * should be first entry in short_ref. If not, it must exist + * in long_ref; trying to put it on the short list here is an + * error in the encoded bit stream (ref: 7.4.3, NOTE 2 and 3). + */ + if (h->short_ref_count && h->short_ref[0] == s->current_picture_ptr) { + /* Just mark the second field valid */ + s->current_picture_ptr->reference = PICT_FRAME; + } else if (s->current_picture_ptr->long_ref) { + av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term reference " + "assignment for second field " + "in complementary field pair " + "(first field is long term)\n"); + } else { + /* + * First field in reference, but not in any sensible place on our + * reference lists. This shouldn't happen unless reference + * handling somewhere else is wrong. + */ + assert(0); + } + current_ref_assigned = 1; + } + + if(!current_ref_assigned){ pic= remove_short(h, s->current_picture_ptr->frame_num); if(pic){ - unreference_pic(h, pic); + unreference_pic(h, pic, 0); av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n"); } @@ -4344,6 +3579,32 @@ static int execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ h->short_ref[0]= s->current_picture_ptr; h->short_ref[0]->long_ref=0; h->short_ref_count++; + s->current_picture_ptr->reference |= s->picture_structure; + } + + if (h->long_ref_count + h->short_ref_count > h->sps.ref_frame_count){ + + /* We have too many reference frames, probably due to corrupted + * stream. Need to discard one frame. Prevents overrun of the + * short_ref and long_ref buffers. + */ + av_log(h->s.avctx, AV_LOG_ERROR, + "number of reference frames exceeds max (probably " + "corrupt input), discarding one\n"); + + if (h->long_ref_count) { + for (i = 0; i < 16; ++i) + if (h->long_ref[i]) + break; + + assert(i < 16); + pic = h->long_ref[i]; + remove_long_at_index(h, i); + } else { + pic = h->short_ref[h->short_ref_count - 1]; + remove_short_at_index(h, h->short_ref_count - 1); + } + unreference_pic(h, pic, 0); } print_short_term(h); @@ -4351,39 +3612,39 @@ static int execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ return 0; } -static int decode_ref_pic_marking(H264Context *h){ +static int decode_ref_pic_marking(H264Context *h, GetBitContext *gb){ MpegEncContext * const s = &h->s; int i; if(h->nal_unit_type == NAL_IDR_SLICE){ //FIXME fields - s->broken_link= get_bits1(&s->gb) -1; - h->mmco[0].long_index= get_bits1(&s->gb) - 1; // current_long_term_idx - if(h->mmco[0].long_index == -1) + s->broken_link= get_bits1(gb) -1; + h->mmco[0].long_arg= get_bits1(gb) - 1; // current_long_term_idx + if(h->mmco[0].long_arg == -1) h->mmco_index= 0; else{ h->mmco[0].opcode= MMCO_LONG; h->mmco_index= 1; } }else{ - if(get_bits1(&s->gb)){ // adaptive_ref_pic_marking_mode_flag + if(get_bits1(gb)){ // adaptive_ref_pic_marking_mode_flag for(i= 0; igb);; + MMCOOpcode opcode= get_ue_golomb(gb); h->mmco[i].opcode= opcode; if(opcode==MMCO_SHORT2UNUSED || opcode==MMCO_SHORT2LONG){ - h->mmco[i].short_frame_num= (h->frame_num - get_ue_golomb(&s->gb) - 1) & ((1<sps.log2_max_frame_num)-1); //FIXME fields -/* if(h->mmco[i].short_frame_num >= h->short_ref_count || h->short_ref[ h->mmco[i].short_frame_num ] == NULL){ + h->mmco[i].short_pic_num= (h->curr_pic_num - get_ue_golomb(gb) - 1) & (h->max_pic_num - 1); +/* if(h->mmco[i].short_pic_num >= h->short_ref_count || h->short_ref[ h->mmco[i].short_pic_num ] == NULL){ av_log(s->avctx, AV_LOG_ERROR, "illegal short ref in memory management control operation %d\n", mmco); return -1; }*/ } if(opcode==MMCO_SHORT2LONG || opcode==MMCO_LONG2UNUSED || opcode==MMCO_LONG || opcode==MMCO_SET_MAX_LONG){ - unsigned int long_index= get_ue_golomb(&s->gb); - if(/*h->mmco[i].long_index >= h->long_ref_count || h->long_ref[ h->mmco[i].long_index ] == NULL*/ long_index >= 16){ + unsigned int long_arg= get_ue_golomb(gb); + if(long_arg >= 32 || (long_arg >= 16 && !(opcode == MMCO_LONG2UNUSED && FIELD_PICTURE))){ av_log(h->s.avctx, AV_LOG_ERROR, "illegal long ref in memory management control operation %d\n", opcode); return -1; } - h->mmco[i].long_index= long_index; + h->mmco[i].long_arg= long_arg; } if(opcode > (unsigned)MMCO_LONG){ @@ -4397,10 +3658,17 @@ static int decode_ref_pic_marking(H264Context *h){ }else{ assert(h->long_ref_count + h->short_ref_count <= h->sps.ref_frame_count); - if(h->long_ref_count + h->short_ref_count == h->sps.ref_frame_count){ //FIXME fields + if(h->short_ref_count && h->long_ref_count + h->short_ref_count == h->sps.ref_frame_count && + !(FIELD_PICTURE && !s->first_field && s->current_picture_ptr->reference)) { h->mmco[0].opcode= MMCO_SHORT2UNUSED; - h->mmco[0].short_frame_num= h->short_ref[ h->short_ref_count - 1 ]->frame_num; + h->mmco[0].short_pic_num= h->short_ref[ h->short_ref_count - 1 ]->frame_num; h->mmco_index= 1; + if (FIELD_PICTURE) { + h->mmco[0].short_pic_num *= 2; + h->mmco[1].opcode= MMCO_SHORT2UNUSED; + h->mmco[1].short_pic_num= h->mmco[0].short_pic_num + 1; + h->mmco_index= 2; + } }else h->mmco_index= 0; } @@ -4477,48 +3745,146 @@ static int init_poc(H264Context *h){ if(s->picture_structure == PICT_FRAME) field_poc[1] += h->delta_poc[1]; }else{ - int poc; - if(h->nal_unit_type == NAL_IDR_SLICE){ - poc= 0; - }else{ - if(h->nal_ref_idc) poc= 2*(h->frame_num_offset + h->frame_num); - else poc= 2*(h->frame_num_offset + h->frame_num) - 1; + int poc; + if(h->nal_unit_type == NAL_IDR_SLICE){ + poc= 0; + }else{ + if(h->nal_ref_idc) poc= 2*(h->frame_num_offset + h->frame_num); + else poc= 2*(h->frame_num_offset + h->frame_num) - 1; + } + field_poc[0]= poc; + field_poc[1]= poc; + } + + if(s->picture_structure != PICT_BOTTOM_FIELD) { + s->current_picture_ptr->field_poc[0]= field_poc[0]; + s->current_picture_ptr->poc = field_poc[0]; + } + if(s->picture_structure != PICT_TOP_FIELD) { + s->current_picture_ptr->field_poc[1]= field_poc[1]; + s->current_picture_ptr->poc = field_poc[1]; + } + if(!FIELD_PICTURE || !s->first_field) { + Picture *cur = s->current_picture_ptr; + cur->poc= FFMIN(cur->field_poc[0], cur->field_poc[1]); + } + + return 0; +} + + +/** + * initialize scan tables + */ +static void init_scan_tables(H264Context *h){ + MpegEncContext * const s = &h->s; + int i; + if(s->dsp.h264_idct_add == ff_h264_idct_add_c){ //FIXME little ugly + memcpy(h->zigzag_scan, zigzag_scan, 16*sizeof(uint8_t)); + memcpy(h-> field_scan, field_scan, 16*sizeof(uint8_t)); + }else{ + for(i=0; i<16; i++){ +#define T(x) (x>>2) | ((x<<2) & 0xF) + h->zigzag_scan[i] = T(zigzag_scan[i]); + h-> field_scan[i] = T( field_scan[i]); +#undef T } - field_poc[0]= poc; - field_poc[1]= poc; } + if(s->dsp.h264_idct8_add == ff_h264_idct8_add_c){ + memcpy(h->zigzag_scan8x8, zigzag_scan8x8, 64*sizeof(uint8_t)); + memcpy(h->zigzag_scan8x8_cavlc, zigzag_scan8x8_cavlc, 64*sizeof(uint8_t)); + memcpy(h->field_scan8x8, field_scan8x8, 64*sizeof(uint8_t)); + memcpy(h->field_scan8x8_cavlc, field_scan8x8_cavlc, 64*sizeof(uint8_t)); + }else{ + for(i=0; i<64; i++){ +#define T(x) (x>>3) | ((x&7)<<3) + h->zigzag_scan8x8[i] = T(zigzag_scan8x8[i]); + h->zigzag_scan8x8_cavlc[i] = T(zigzag_scan8x8_cavlc[i]); + h->field_scan8x8[i] = T(field_scan8x8[i]); + h->field_scan8x8_cavlc[i] = T(field_scan8x8_cavlc[i]); +#undef T + } + } + if(h->sps.transform_bypass){ //FIXME same ugly + h->zigzag_scan_q0 = zigzag_scan; + h->zigzag_scan8x8_q0 = zigzag_scan8x8; + h->zigzag_scan8x8_cavlc_q0 = zigzag_scan8x8_cavlc; + h->field_scan_q0 = field_scan; + h->field_scan8x8_q0 = field_scan8x8; + h->field_scan8x8_cavlc_q0 = field_scan8x8_cavlc; + }else{ + h->zigzag_scan_q0 = h->zigzag_scan; + h->zigzag_scan8x8_q0 = h->zigzag_scan8x8; + h->zigzag_scan8x8_cavlc_q0 = h->zigzag_scan8x8_cavlc; + h->field_scan_q0 = h->field_scan; + h->field_scan8x8_q0 = h->field_scan8x8; + h->field_scan8x8_cavlc_q0 = h->field_scan8x8_cavlc; + } +} - if(s->picture_structure != PICT_BOTTOM_FIELD) - s->current_picture_ptr->field_poc[0]= field_poc[0]; - if(s->picture_structure != PICT_TOP_FIELD) - s->current_picture_ptr->field_poc[1]= field_poc[1]; - if(s->picture_structure == PICT_FRAME) // FIXME field pix? - s->current_picture_ptr->poc= FFMIN(field_poc[0], field_poc[1]); +/** + * Replicates H264 "master" context to thread contexts. + */ +static void clone_slice(H264Context *dst, H264Context *src) +{ + memcpy(dst->block_offset, src->block_offset, sizeof(dst->block_offset)); + dst->s.current_picture_ptr = src->s.current_picture_ptr; + dst->s.current_picture = src->s.current_picture; + dst->s.linesize = src->s.linesize; + dst->s.uvlinesize = src->s.uvlinesize; + dst->s.first_field = src->s.first_field; - return 0; + dst->prev_poc_msb = src->prev_poc_msb; + dst->prev_poc_lsb = src->prev_poc_lsb; + dst->prev_frame_num_offset = src->prev_frame_num_offset; + dst->prev_frame_num = src->prev_frame_num; + dst->short_ref_count = src->short_ref_count; + + memcpy(dst->short_ref, src->short_ref, sizeof(dst->short_ref)); + memcpy(dst->long_ref, src->long_ref, sizeof(dst->long_ref)); + memcpy(dst->default_ref_list, src->default_ref_list, sizeof(dst->default_ref_list)); + memcpy(dst->ref_list, src->ref_list, sizeof(dst->ref_list)); + + memcpy(dst->dequant4_coeff, src->dequant4_coeff, sizeof(src->dequant4_coeff)); + memcpy(dst->dequant8_coeff, src->dequant8_coeff, sizeof(src->dequant8_coeff)); } /** * decodes a slice header. * this will allso call MPV_common_init() and frame_start() as needed + * + * @param h h264context + * @param h0 h264 master context (differs from 'h' when doing sliced based parallel decoding) + * + * @return 0 if okay, <0 if an error occured, 1 if decoding must not be multithreaded */ -static int decode_slice_header(H264Context *h){ +static int decode_slice_header(H264Context *h, H264Context *h0){ MpegEncContext * const s = &h->s; + MpegEncContext * const s0 = &h0->s; unsigned int first_mb_in_slice; unsigned int pps_id; int num_ref_idx_active_override_flag; static const uint8_t slice_type_map[5]= {P_TYPE, B_TYPE, I_TYPE, SP_TYPE, SI_TYPE}; - unsigned int slice_type, tmp; + unsigned int slice_type, tmp, i; int default_ref_list_done = 0; + int last_pic_structure; - s->current_picture.reference= h->nal_ref_idc != 0; s->dropable= h->nal_ref_idc == 0; + if((s->avctx->flags2 & CODEC_FLAG2_FAST) && !h->nal_ref_idc){ + s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab; + s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab; + }else{ + s->me.qpel_put= s->dsp.put_h264_qpel_pixels_tab; + s->me.qpel_avg= s->dsp.avg_h264_qpel_pixels_tab; + } + first_mb_in_slice= get_ue_golomb(&s->gb); if((s->flags2 & CODEC_FLAG2_CHUNKS) && first_mb_in_slice == 0){ - h->slice_num = 0; - s->current_picture_ptr= NULL; + h0->current_slice = 0; + if (!s0->first_field) + s->current_picture_ptr= NULL; } slice_type= get_ue_golomb(&s->gb); @@ -4534,31 +3900,36 @@ static int decode_slice_header(H264Context *h){ slice_type= slice_type_map[ slice_type ]; if (slice_type == I_TYPE - || (h->slice_num != 0 && slice_type == h->slice_type) ) { + || (h0->current_slice != 0 && slice_type == h0->last_slice_type) ) { default_ref_list_done = 1; } h->slice_type= slice_type; s->pict_type= h->slice_type; // to make a few old func happy, it's wrong though + if (s->pict_type == B_TYPE && s0->last_picture_ptr == NULL) { + av_log(h->s.avctx, AV_LOG_ERROR, + "B picture before any references, skipping\n"); + return -1; + } pps_id= get_ue_golomb(&s->gb); if(pps_id>=MAX_PPS_COUNT){ av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n"); return -1; } - h->pps= h->pps_buffer[pps_id]; - if(h->pps.slice_group_count == 0){ + if(!h0->pps_buffers[pps_id]) { av_log(h->s.avctx, AV_LOG_ERROR, "non existing PPS referenced\n"); return -1; } + h->pps= *h0->pps_buffers[pps_id]; - h->sps= h->sps_buffer[ h->pps.sps_id ]; - if(h->sps.log2_max_frame_num == 0){ + if(!h0->sps_buffers[h->pps.sps_id]) { av_log(h->s.avctx, AV_LOG_ERROR, "non existing SPS referenced\n"); return -1; } + h->sps = *h0->sps_buffers[h->pps.sps_id]; - if(h->dequant_coeff_pps != pps_id){ + if(h == h0 && h->dequant_coeff_pps != pps_id){ h->dequant_coeff_pps = pps_id; init_dequant_tables(h); } @@ -4577,58 +3948,35 @@ static int decode_slice_header(H264Context *h){ if (s->context_initialized && ( s->width != s->avctx->width || s->height != s->avctx->height)) { + if(h != h0) + return -1; // width / height changed during parallelized decoding free_tables(h); MPV_common_end(s); } if (!s->context_initialized) { + if(h != h0) + return -1; // we cant (re-)initialize context during parallel decoding if (MPV_common_init(s) < 0) return -1; + s->first_field = 0; - if(s->dsp.h264_idct_add == ff_h264_idct_add_c){ //FIXME little ugly - memcpy(h->zigzag_scan, zigzag_scan, 16*sizeof(uint8_t)); - memcpy(h-> field_scan, field_scan, 16*sizeof(uint8_t)); - }else{ - int i; - for(i=0; i<16; i++){ -#define T(x) (x>>2) | ((x<<2) & 0xF) - h->zigzag_scan[i] = T(zigzag_scan[i]); - h-> field_scan[i] = T( field_scan[i]); -#undef T - } - } - if(s->dsp.h264_idct8_add == ff_h264_idct8_add_c){ - memcpy(h->zigzag_scan8x8, zigzag_scan8x8, 64*sizeof(uint8_t)); - memcpy(h->zigzag_scan8x8_cavlc, zigzag_scan8x8_cavlc, 64*sizeof(uint8_t)); - memcpy(h->field_scan8x8, field_scan8x8, 64*sizeof(uint8_t)); - memcpy(h->field_scan8x8_cavlc, field_scan8x8_cavlc, 64*sizeof(uint8_t)); - }else{ - int i; - for(i=0; i<64; i++){ -#define T(x) (x>>3) | ((x&7)<<3) - h->zigzag_scan8x8[i] = T(zigzag_scan8x8[i]); - h->zigzag_scan8x8_cavlc[i] = T(zigzag_scan8x8_cavlc[i]); - h->field_scan8x8[i] = T(field_scan8x8[i]); - h->field_scan8x8_cavlc[i] = T(field_scan8x8_cavlc[i]); -#undef T - } - } - if(h->sps.transform_bypass){ //FIXME same ugly - h->zigzag_scan_q0 = zigzag_scan; - h->zigzag_scan8x8_q0 = zigzag_scan8x8; - h->zigzag_scan8x8_cavlc_q0 = zigzag_scan8x8_cavlc; - h->field_scan_q0 = field_scan; - h->field_scan8x8_q0 = field_scan8x8; - h->field_scan8x8_cavlc_q0 = field_scan8x8_cavlc; - }else{ - h->zigzag_scan_q0 = h->zigzag_scan; - h->zigzag_scan8x8_q0 = h->zigzag_scan8x8; - h->zigzag_scan8x8_cavlc_q0 = h->zigzag_scan8x8_cavlc; - h->field_scan_q0 = h->field_scan; - h->field_scan8x8_q0 = h->field_scan8x8; - h->field_scan8x8_cavlc_q0 = h->field_scan8x8_cavlc; + init_scan_tables(h); + alloc_tables(h); + + for(i = 1; i < s->avctx->thread_count; i++) { + H264Context *c; + c = h->thread_context[i] = av_malloc(sizeof(H264Context)); + memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext)); + memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext)); + c->sps = h->sps; + c->pps = h->pps; + init_scan_tables(c); + clone_tables(c, h); } - alloc_tables(h); + for(i = 0; i < s->avctx->thread_count; i++) + if(context_init(h->thread_context[i]) < 0) + return -1; s->avctx->width = s->width; s->avctx->height = s->height; @@ -4645,42 +3993,90 @@ static int decode_slice_header(H264Context *h){ } } - if(h->slice_num == 0){ - if(frame_start(h) < 0) - return -1; - } - - s->current_picture_ptr->frame_num= //FIXME frame_num cleanup h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num); h->mb_mbaff = 0; h->mb_aff_frame = 0; + last_pic_structure = s0->picture_structure; if(h->sps.frame_mbs_only_flag){ s->picture_structure= PICT_FRAME; }else{ if(get_bits1(&s->gb)) { //field_pic_flag s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb); //bottom_field_flag - av_log(h->s.avctx, AV_LOG_ERROR, "PAFF interlacing is not implemented\n"); } else { s->picture_structure= PICT_FRAME; h->mb_aff_frame = h->sps.mb_aff; } } + + if(h0->current_slice == 0){ + /* See if we have a decoded first field looking for a pair... */ + if (s0->first_field) { + assert(s0->current_picture_ptr); + assert(s0->current_picture_ptr->data[0]); + assert(s0->current_picture_ptr->reference != DELAYED_PIC_REF); + + /* figure out if we have a complementary field pair */ + if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) { + /* + * Previous field is unmatched. Don't display it, but let it + * remain for reference if marked as such. + */ + s0->current_picture_ptr = NULL; + s0->first_field = FIELD_PICTURE; + + } else { + if (h->nal_ref_idc && + s0->current_picture_ptr->reference && + s0->current_picture_ptr->frame_num != h->frame_num) { + /* + * This and previous field were reference, but had + * different frame_nums. Consider this field first in + * pair. Throw away previous field except for reference + * purposes. + */ + s0->first_field = 1; + s0->current_picture_ptr = NULL; + + } else { + /* Second field in complementary pair */ + s0->first_field = 0; + } + } + + } else { + /* Frame or first field in a potentially complementary pair */ + assert(!s0->current_picture_ptr); + s0->first_field = FIELD_PICTURE; + } + + if((!FIELD_PICTURE || s0->first_field) && frame_start(h) < 0) { + s0->first_field = 0; + return -1; + } + } + if(h != h0) + clone_slice(h, h0); + + s->current_picture_ptr->frame_num= h->frame_num; //FIXME frame_num cleanup + assert(s->mb_num == s->mb_width * s->mb_height); - if(first_mb_in_slice << h->mb_aff_frame >= s->mb_num || + if(first_mb_in_slice << FIELD_OR_MBAFF_PICTURE >= s->mb_num || first_mb_in_slice >= s->mb_num){ av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n"); return -1; } s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width; - s->resync_mb_y = s->mb_y = (first_mb_in_slice / s->mb_width) << h->mb_aff_frame; + s->resync_mb_y = s->mb_y = (first_mb_in_slice / s->mb_width) << FIELD_OR_MBAFF_PICTURE; + if (s->picture_structure == PICT_BOTTOM_FIELD) + s->resync_mb_y = s->mb_y = s->mb_y + 1; assert(s->mb_y < s->mb_height); if(s->picture_structure==PICT_FRAME){ h->curr_pic_num= h->frame_num; h->max_pic_num= 1<< h->sps.log2_max_frame_num; }else{ - h->curr_pic_num= 2*h->frame_num; + h->curr_pic_num= 2*h->frame_num + 1; h->max_pic_num= 1<<(h->sps.log2_max_frame_num + 1); } @@ -4716,8 +4112,6 @@ static int decode_slice_header(H264Context *h){ if(h->slice_type == P_TYPE || h->slice_type == SP_TYPE || h->slice_type == B_TYPE){ if(h->slice_type == B_TYPE){ h->direct_spatial_mv_pred= get_bits1(&s->gb); - if(h->sps.mb_aff && h->direct_spatial_mv_pred) - av_log(h->s.avctx, AV_LOG_ERROR, "MBAFF + spatial direct mode is not implemented\n"); } num_ref_idx_active_override_flag= get_bits1(&s->gb); @@ -4754,8 +4148,8 @@ static int decode_slice_header(H264Context *h){ else h->use_weight = 0; - if(s->current_picture.reference) - decode_ref_pic_marking(h); + if(h->nal_ref_idc) + decode_ref_pic_marking(h0, &s->gb); if(FRAME_MBAFF) fill_mbaff_ref_list(h); @@ -4776,7 +4170,8 @@ static int decode_slice_header(H264Context *h){ return -1; } s->qscale= tmp; - h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->qscale); + h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale); + h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale); //FIXME qscale / qp ... stuff if(h->slice_type == SP_TYPE){ get_bits1(&s->gb); /* sp_for_switch_flag */ @@ -4803,21 +4198,39 @@ static int decode_slice_header(H264Context *h){ h->slice_beta_offset = get_se_golomb(&s->gb) << 1; } } + if( s->avctx->skip_loop_filter >= AVDISCARD_ALL ||(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->slice_type != I_TYPE) ||(s->avctx->skip_loop_filter >= AVDISCARD_BIDIR && h->slice_type == B_TYPE) ||(s->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0)) h->deblocking_filter= 0; + if(h->deblocking_filter == 1 && h0->max_contexts > 1) { + if(s->avctx->flags2 & CODEC_FLAG2_FAST) { + /* Cheat slightly for speed: + Do not bother to deblock across slices. */ + h->deblocking_filter = 2; + } else { + h0->max_contexts = 1; + if(!h0->single_decode_warning) { + av_log(s->avctx, AV_LOG_INFO, "Cannot parallelize deblocking type 1, decoding such frames in sequential order\n"); + h0->single_decode_warning = 1; + } + if(h != h0) + return 1; // deblocking switched inside frame + } + } + #if 0 //FMO if( h->pps.num_slice_groups > 1 && h->pps.mb_slice_group_map_type >= 3 && h->pps.mb_slice_group_map_type <= 5) slice_group_change_cycle= get_bits(&s->gb, ?); #endif - h->slice_num++; + h0->last_slice_type = slice_type; + h->slice_num = ++h0->current_slice; h->emu_edge_width= (s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16; - h->emu_edge_height= FRAME_MBAFF ? 0 : h->emu_edge_width; + h->emu_edge_height= (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width; if(s->avctx->debug&FF_DEBUG_PICT_INFO){ av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s\n", @@ -4835,14 +4248,6 @@ static int decode_slice_header(H264Context *h){ ); } - if((s->avctx->flags2 & CODEC_FLAG2_FAST) && !s->current_picture.reference){ - s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab; - s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab; - }else{ - s->me.qpel_put= s->dsp.put_h264_qpel_pixels_tab; - s->me.qpel_avg= s->dsp.avg_h264_qpel_pixels_tab; - } - return 0; } @@ -5161,7 +4566,7 @@ decode_intra_mb: if(IS_INTRA_PCM(mb_type)){ unsigned int x, y; - // we assume these blocks are very rare so we dont optimize it + // We assume these blocks are very rare so we do not optimize it. align_get_bits(&s->gb); // The pixels are stored in the same order as levels in h->mb array. @@ -5189,7 +4594,8 @@ decode_intra_mb: // In deblocking, the quantizer is 0 s->current_picture.qscale_table[mb_xy]= 0; - h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, 0); + h->chroma_qp[0] = get_chroma_qp(h, 0, 0); + h->chroma_qp[1] = get_chroma_qp(h, 1, 0); // All coeffs are present memset(h->non_zero_count[mb_xy], 16, 16); @@ -5299,8 +4705,6 @@ decode_intra_mb: dct8x8_allowed = get_dct8x8_allowed(h); for(list=0; listlist_count; list++){ - const int ref_count= IS_REF0(mb_type) ? 1 : h->ref_count[list]; - for(i=0; i<4; i++){ if(IS_DIRECT(h->sub_mb_type[i])) { h->ref_cache[list][ scan8[4*i] ] = h->ref_cache[list][ scan8[4*i]+1 ]; @@ -5465,7 +4869,7 @@ decode_intra_mb: if(cbp || IS_INTRA16x16(mb_type)){ int i8x8, i4x4, chroma_idx; - int chroma_qp, dquant; + int dquant; GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr; const uint8_t *scan, *scan8x8, *dc_scan; @@ -5494,7 +4898,8 @@ decode_intra_mb: else s->qscale-= 52; } - h->chroma_qp= chroma_qp= get_chroma_qp(h->pps.chroma_qp_index_offset, s->qscale); + h->chroma_qp[0]= get_chroma_qp(h, 0, s->qscale); + h->chroma_qp[1]= get_chroma_qp(h, 1, s->qscale); if(IS_INTRA16x16(mb_type)){ if( decode_residual(h, h->intra_gb_ptr, h->mb, LUMA_DC_BLOCK_INDEX, dc_scan, h->dequant4_coeff[0][s->qscale], 16) < 0){ return -1; //FIXME continue if partitioned and other return -1 too @@ -5552,9 +4957,10 @@ decode_intra_mb: if(cbp&0x20){ for(chroma_idx=0; chroma_idx<2; chroma_idx++){ + const uint32_t *qmul = h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[chroma_idx]]; for(i4x4=0; i4x4<4; i4x4++){ const int index= 16 + 4*chroma_idx + i4x4; - if( decode_residual(h, gb, h->mb + 16*index, index, scan + 1, h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][chroma_qp], 15) < 0){ + if( decode_residual(h, gb, h->mb + 16*index, index, scan + 1, qmul, 15) < 0){ return -1; } } @@ -5713,7 +5119,7 @@ static int decode_cabac_mb_skip( H264Context *h, int mb_x, int mb_y ) { }else{ int mb_xy = mb_x + mb_y*s->mb_stride; mba_xy = mb_xy - 1; - mbb_xy = mb_xy - s->mb_stride; + mbb_xy = mb_xy - (s->mb_stride << FIELD_PICTURE); } if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mba_xy] )) @@ -5766,65 +5172,20 @@ static int decode_cabac_mb_chroma_pre_mode( H264Context *h) { return 3; } -static const uint8_t block_idx_x[16] = { - 0, 1, 0, 1, 2, 3, 2, 3, 0, 1, 0, 1, 2, 3, 2, 3 -}; -static const uint8_t block_idx_y[16] = { - 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3 -}; -static const uint8_t block_idx_xy[4][4] = { - { 0, 2, 8, 10}, - { 1, 3, 9, 11}, - { 4, 6, 12, 14}, - { 5, 7, 13, 15} -}; - static int decode_cabac_mb_cbp_luma( H264Context *h) { - int cbp = 0; - int cbp_b = -1; - int i8x8; - - if( h->slice_table[h->top_mb_xy] == h->slice_num ) { - cbp_b = h->top_cbp; - tprintf(h->s.avctx, "cbp_b = top_cbp = %x\n", cbp_b); - } - - for( i8x8 = 0; i8x8 < 4; i8x8++ ) { - int cbp_a = -1; - int x, y; - int ctx = 0; - - x = block_idx_x[4*i8x8]; - y = block_idx_y[4*i8x8]; - - if( x > 0 ) - cbp_a = cbp; - else if( h->slice_table[h->left_mb_xy[0]] == h->slice_num ) { - cbp_a = h->left_cbp; - tprintf(h->s.avctx, "cbp_a = left_cbp = %x\n", cbp_a); - } - - if( y > 0 ) - cbp_b = cbp; - - /* No need to test for skip as we put 0 for skip block */ - /* No need to test for IPCM as we put 1 for IPCM block */ - if( cbp_a >= 0 ) { - int i8x8a = block_idx_xy[(x-1)&0x03][y]/4; - if( ((cbp_a >> i8x8a)&0x01) == 0 ) - ctx++; - } - - if( cbp_b >= 0 ) { - int i8x8b = block_idx_xy[x][(y-1)&0x03]/4; - if( ((cbp_b >> i8x8b)&0x01) == 0 ) - ctx += 2; - } - - if( get_cabac( &h->cabac, &h->cabac_state[73 + ctx] ) ) { - cbp |= 1 << i8x8; - } - } + int cbp_b, cbp_a, ctx, cbp = 0; + + cbp_a = h->slice_table[h->left_mb_xy[0]] == h->slice_num ? h->left_cbp : -1; + cbp_b = h->slice_table[h->top_mb_xy] == h->slice_num ? h->top_cbp : -1; + + ctx = !(cbp_a & 0x02) + 2 * !(cbp_b & 0x04); + cbp |= get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]); + ctx = !(cbp & 0x01) + 2 * !(cbp_b & 0x08); + cbp |= get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 1; + ctx = !(cbp_a & 0x08) + 2 * !(cbp & 0x01); + cbp |= get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 2; + ctx = !(cbp & 0x04) + 2 * !(cbp & 0x02); + cbp |= get_cabac_noinline(&h->cabac, &h->cabac_state[73 + ctx]) << 3; return cbp; } static int decode_cabac_mb_cbp_chroma( H264Context *h) { @@ -5846,16 +5207,9 @@ static int decode_cabac_mb_cbp_chroma( H264Context *h) { return 1 + get_cabac_noinline( &h->cabac, &h->cabac_state[77 + ctx] ); } static int decode_cabac_mb_dqp( H264Context *h) { - MpegEncContext * const s = &h->s; - int mbn_xy; int ctx = 0; int val = 0; - if( s->mb_x > 0 ) - mbn_xy = s->mb_x + s->mb_y*s->mb_stride - 1; - else - mbn_xy = s->mb_width - 1 + (s->mb_y-1)*s->mb_stride; - if( h->last_qscale_diff != 0 ) ctx++; @@ -5978,7 +5332,7 @@ static int decode_cabac_mb_mvd( H264Context *h, int list, int n, int l ) { return get_cabac_bypass_sign( &h->cabac, -mvd ); } -static int inline get_cabac_cbf_ctx( H264Context *h, int cat, int idx ) { +static inline int get_cabac_cbf_ctx( H264Context *h, int cat, int idx ) { int nza, nzb; int ctx = 0; @@ -6006,14 +5360,14 @@ static int inline get_cabac_cbf_ctx( H264Context *h, int cat, int idx ) { return ctx + 4 * cat; } -static const __attribute((used)) uint8_t last_coeff_flag_offset_8x8[63] = { +DECLARE_ASM_CONST(1, const uint8_t, last_coeff_flag_offset_8x8[63]) = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8 }; -static int decode_cabac_residual( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff) { +static void decode_cabac_residual( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff) { const int mb_xy = h->s.mb_x + h->s.mb_y*h->s.mb_stride; static const int significant_coeff_flag_offset[2][6] = { { 105+0, 105+15, 105+29, 105+44, 105+47, 402 }, @@ -6039,7 +5393,7 @@ static int decode_cabac_residual( H264Context *h, DCTELEM *block, int cat, int n int index[64]; - int last; + int av_unused last; int coeff_count = 0; int abslevel1 = 1; @@ -6083,7 +5437,7 @@ static int decode_cabac_residual( H264Context *h, DCTELEM *block, int cat, int n h->cabac.low = cc.low ; h->cabac.bytestream= cc.bytestream; #endif - return 0; + return; } } @@ -6111,7 +5465,7 @@ static int decode_cabac_residual( H264Context *h, DCTELEM *block, int cat, int n index[coeff_count++] = last;\ } const uint8_t *sig_off = significant_coeff_flag_offset_8x8[MB_FIELD]; -#if defined(ARCH_X86) && defined(CONFIG_7REGS) && defined(CONFIG_EBX_AVAILABLE) && !( defined(ARCH_X86_64) && defined(PIC) ) +#if defined(ARCH_X86) && defined(HAVE_7REGS) && defined(HAVE_EBX_AVAILABLE) && !defined(BROKEN_RELOCATIONS) coeff_count= decode_significance_8x8_x86(CC, significant_coeff_ctx_base, index, sig_off); } else { coeff_count= decode_significance_x86(CC, max_coeff, significant_coeff_ctx_base, index); @@ -6144,7 +5498,7 @@ static int decode_cabac_residual( H264Context *h, DCTELEM *block, int cat, int n if( !qmul ) { block[j] = get_cabac_bypass_sign( CC, -1); }else{ - block[j] = (get_cabac_bypass_sign( CC, -qmul[j]) + 32) >> 6;; + block[j] = (get_cabac_bypass_sign( CC, -qmul[j]) + 32) >> 6; } abslevel1++; @@ -6184,10 +5538,10 @@ static int decode_cabac_residual( H264Context *h, DCTELEM *block, int cat, int n h->cabac.low = cc.low ; h->cabac.bytestream= cc.bytestream; #endif - return 0; + } -static void inline compute_mb_neighbors(H264Context *h) +static inline void compute_mb_neighbors(H264Context *h) { MpegEncContext * const s = &h->s; const int mb_xy = s->mb_x + s->mb_y*s->mb_stride; @@ -6209,6 +5563,8 @@ static void inline compute_mb_neighbors(H264Context *h) if (left_mb_frame_flag != curr_mb_frame_flag) { h->left_mb_xy[0] = pair_xy - 1; } + } else if (FIELD_PICTURE) { + h->top_mb_xy -= s->mb_stride; } return; } @@ -6304,7 +5660,7 @@ decode_intra_mb: const uint8_t *ptr; unsigned int x, y; - // We assume these blocks are very rare so we dont optimize it. + // We assume these blocks are very rare so we do not optimize it. // FIXME The two following lines get the bitstream position in the cabac // decode, I think it should be done by a function in cabac.h (or cabac.c). ptr= h->cabac.bytestream; @@ -6343,7 +5699,8 @@ decode_intra_mb: h->chroma_pred_mode_table[mb_xy] = 0; // In deblocking, the quantizer is 0 s->current_picture.qscale_table[mb_xy]= 0; - h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, 0); + h->chroma_qp[0] = get_chroma_qp(h, 0, 0); + h->chroma_qp[1] = get_chroma_qp(h, 1, 0); // All coeffs are present memset(h->non_zero_count[mb_xy], 16, 16); s->current_picture.mb_type[mb_xy]= mb_type; @@ -6399,6 +5756,10 @@ decode_intra_mb: if( IS_DIRECT(h->sub_mb_type[0] | h->sub_mb_type[1] | h->sub_mb_type[2] | h->sub_mb_type[3]) ) { pred_direct_motion(h, &mb_type); + h->ref_cache[0][scan8[4]] = + h->ref_cache[1][scan8[4]] = + h->ref_cache[0][scan8[12]] = + h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE; if( h->ref_count[0] > 1 || h->ref_count[1] > 1 ) { for( i = 0; i < 4; i++ ) if( IS_DIRECT(h->sub_mb_type[i]) ) @@ -6434,11 +5795,11 @@ decode_intra_mb: for(list=0; listlist_count; list++){ for(i=0; i<4; i++){ + h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]; if(IS_DIRECT(h->sub_mb_type[i])){ fill_rectangle(h->mvd_cache[list][scan8[4*i]], 2, 2, 8, 0, 4); continue; } - h->ref_cache[list][ scan8[4*i] ]=h->ref_cache[list][ scan8[4*i]+1 ]; if(IS_DIR(h->sub_mb_type[i], 0, list) && !IS_DIRECT(h->sub_mb_type[i])){ const int sub_mb_type= h->sub_mb_type[i]; @@ -6597,6 +5958,7 @@ decode_intra_mb: if( cbp || IS_INTRA16x16( mb_type ) ) { const uint8_t *scan, *scan8x8, *dc_scan; + const uint32_t *qmul; int dqp; if(IS_INTERLACED(mb_type)){ @@ -6619,18 +5981,19 @@ decode_intra_mb: if(s->qscale<0) s->qscale+= 52; else s->qscale-= 52; } - h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, s->qscale); + h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale); + h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale); if( IS_INTRA16x16( mb_type ) ) { int i; //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 DC\n" ); - if( decode_cabac_residual( h, h->mb, 0, 0, dc_scan, NULL, 16) < 0) - return -1; + decode_cabac_residual( h, h->mb, 0, 0, dc_scan, NULL, 16); + if( cbp&15 ) { + qmul = h->dequant4_coeff[0][s->qscale]; for( i = 0; i < 16; i++ ) { //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 AC:%d\n", i ); - if( decode_cabac_residual(h, h->mb + 16*i, 1, i, scan + 1, h->dequant4_coeff[0][s->qscale], 15) < 0 ) - return -1; + decode_cabac_residual(h, h->mb + 16*i, 1, i, scan + 1, qmul, 15); } } else { fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1); @@ -6640,17 +6003,17 @@ decode_intra_mb: for( i8x8 = 0; i8x8 < 4; i8x8++ ) { if( cbp & (1<mb + 64*i8x8, 5, 4*i8x8, - scan8x8, h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 64) < 0 ) - return -1; - } else - for( i4x4 = 0; i4x4 < 4; i4x4++ ) { - const int index = 4*i8x8 + i4x4; - //av_log( s->avctx, AV_LOG_ERROR, "Luma4x4: %d\n", index ); + decode_cabac_residual(h, h->mb + 64*i8x8, 5, 4*i8x8, + scan8x8, h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 64); + } else { + qmul = h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale]; + for( i4x4 = 0; i4x4 < 4; i4x4++ ) { + const int index = 4*i8x8 + i4x4; + //av_log( s->avctx, AV_LOG_ERROR, "Luma4x4: %d\n", index ); //START_TIMER - if( decode_cabac_residual(h, h->mb + 16*index, 2, index, scan, h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale], 16) < 0 ) - return -1; + decode_cabac_residual(h, h->mb + 16*index, 2, index, scan, qmul, 16); //STOP_TIMER("decode_residual") + } } } else { uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ]; @@ -6663,19 +6026,18 @@ decode_intra_mb: int c; for( c = 0; c < 2; c++ ) { //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-DC\n",c ); - if( decode_cabac_residual(h, h->mb + 256 + 16*4*c, 3, c, chroma_dc_scan, NULL, 4) < 0) - return -1; + decode_cabac_residual(h, h->mb + 256 + 16*4*c, 3, c, chroma_dc_scan, NULL, 4); } } if( cbp&0x20 ) { int c, i; for( c = 0; c < 2; c++ ) { + qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]]; for( i = 0; i < 4; i++ ) { const int index = 16 + 4 * c + i; //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-AC %d\n",c, index - 16 ); - if( decode_cabac_residual(h, h->mb + 16*index, 4, index - 16, scan + 1, h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp], 15) < 0) - return -1; + decode_cabac_residual(h, h->mb + 16*index, 4, index - 16, scan + 1, qmul, 15); } } } else { @@ -7009,23 +6371,27 @@ static void filter_mb_edgech( H264Context *h, uint8_t *pix, int stride, int16_t static void filter_mb_fast( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize) { MpegEncContext * const s = &h->s; + int mb_y_firstrow = s->picture_structure == PICT_BOTTOM_FIELD; int mb_xy, mb_type; int qp, qp0, qp1, qpc, qpc0, qpc1, qp_thresh; - if(mb_x==0 || mb_y==0 || !s->dsp.h264_loop_filter_strength) { + mb_xy = mb_x + mb_y*s->mb_stride; + + if(mb_x==0 || mb_y==mb_y_firstrow || !s->dsp.h264_loop_filter_strength || h->pps.chroma_qp_diff || + (h->deblocking_filter == 2 && (h->slice_table[mb_xy] != h->slice_table[h->top_mb_xy] || + h->slice_table[mb_xy] != h->slice_table[mb_xy - 1]))) { filter_mb(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize); return; } assert(!FRAME_MBAFF); - mb_xy = mb_x + mb_y*s->mb_stride; mb_type = s->current_picture.mb_type[mb_xy]; qp = s->current_picture.qscale_table[mb_xy]; qp0 = s->current_picture.qscale_table[mb_xy-1]; qp1 = s->current_picture.qscale_table[h->top_mb_xy]; - qpc = get_chroma_qp( h->pps.chroma_qp_index_offset, qp ); - qpc0 = get_chroma_qp( h->pps.chroma_qp_index_offset, qp0 ); - qpc1 = get_chroma_qp( h->pps.chroma_qp_index_offset, qp1 ); + qpc = get_chroma_qp( h, 0, qp ); + qpc0 = get_chroma_qp( h, 0, qp0 ); + qpc1 = get_chroma_qp( h, 0, qp1 ); qp0 = (qp + qp0 + 1) >> 1; qp1 = (qp + qp1 + 1) >> 1; qpc0 = (qpc + qpc0 + 1) >> 1; @@ -7038,17 +6404,18 @@ static void filter_mb_fast( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, if( IS_INTRA(mb_type) ) { int16_t bS4[4] = {4,4,4,4}; int16_t bS3[4] = {3,3,3,3}; + int16_t *bSH = FIELD_PICTURE ? bS3 : bS4; if( IS_8x8DCT(mb_type) ) { filter_mb_edgev( h, &img_y[4*0], linesize, bS4, qp0 ); filter_mb_edgev( h, &img_y[4*2], linesize, bS3, qp ); - filter_mb_edgeh( h, &img_y[4*0*linesize], linesize, bS4, qp1 ); + filter_mb_edgeh( h, &img_y[4*0*linesize], linesize, bSH, qp1 ); filter_mb_edgeh( h, &img_y[4*2*linesize], linesize, bS3, qp ); } else { filter_mb_edgev( h, &img_y[4*0], linesize, bS4, qp0 ); filter_mb_edgev( h, &img_y[4*1], linesize, bS3, qp ); filter_mb_edgev( h, &img_y[4*2], linesize, bS3, qp ); filter_mb_edgev( h, &img_y[4*3], linesize, bS3, qp ); - filter_mb_edgeh( h, &img_y[4*0*linesize], linesize, bS4, qp1 ); + filter_mb_edgeh( h, &img_y[4*0*linesize], linesize, bSH, qp1 ); filter_mb_edgeh( h, &img_y[4*1*linesize], linesize, bS3, qp ); filter_mb_edgeh( h, &img_y[4*2*linesize], linesize, bS3, qp ); filter_mb_edgeh( h, &img_y[4*3*linesize], linesize, bS3, qp ); @@ -7057,9 +6424,9 @@ static void filter_mb_fast( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, filter_mb_edgecv( h, &img_cb[2*2], uvlinesize, bS3, qpc ); filter_mb_edgecv( h, &img_cr[2*0], uvlinesize, bS4, qpc0 ); filter_mb_edgecv( h, &img_cr[2*2], uvlinesize, bS3, qpc ); - filter_mb_edgech( h, &img_cb[2*0*uvlinesize], uvlinesize, bS4, qpc1 ); + filter_mb_edgech( h, &img_cb[2*0*uvlinesize], uvlinesize, bSH, qpc1 ); filter_mb_edgech( h, &img_cb[2*2*uvlinesize], uvlinesize, bS3, qpc ); - filter_mb_edgech( h, &img_cr[2*0*uvlinesize], uvlinesize, bS4, qpc1 ); + filter_mb_edgech( h, &img_cr[2*0*uvlinesize], uvlinesize, bSH, qpc1 ); filter_mb_edgech( h, &img_cr[2*2*uvlinesize], uvlinesize, bS3, qpc ); return; } else { @@ -7083,7 +6450,7 @@ static void filter_mb_fast( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, if( IS_INTRA(s->current_picture.mb_type[mb_xy-1]) ) bSv[0][0] = 0x0004000400040004ULL; if( IS_INTRA(s->current_picture.mb_type[h->top_mb_xy]) ) - bSv[1][0] = 0x0004000400040004ULL; + bSv[1][0] = FIELD_PICTURE ? 0x0003000300030003ULL : 0x0004000400040004ULL; #define FILTER(hv,dir,edge)\ if(bSv[dir][edge]) {\ @@ -7131,7 +6498,7 @@ static void filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8 //for sufficiently low qp, filtering wouldn't do anything //this is a conservative estimate: could also check beta_offset and more accurate chroma_qp if(!FRAME_MBAFF){ - int qp_thresh = 15 - h->slice_alpha_c0_offset - FFMAX(0, h->pps.chroma_qp_index_offset); + int qp_thresh = 15 - h->slice_alpha_c0_offset - FFMAX(0, FFMAX(h->pps.chroma_qp_index_offset[0], h->pps.chroma_qp_index_offset[1])); int qp = s->current_picture.qscale_table[mb_xy]; if(qp <= qp_thresh && (mb_x == 0 || ((qp + s->current_picture.qscale_table[mb_xy-1] + 1)>>1) <= qp_thresh) @@ -7154,7 +6521,8 @@ static void filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8 const int left_mb_xy[2] = { pair_xy-1, pair_xy-1+s->mb_stride }; int16_t bS[8]; int qp[2]; - int chroma_qp[2]; + int bqp[2]; + int rqp[2]; int mb_qp, mbn0_qp, mbn1_qp; int i; first_vertical_edge_done = 1; @@ -7180,18 +6548,22 @@ static void filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8 mbn0_qp = s->current_picture.qscale_table[left_mb_xy[0]]; mbn1_qp = s->current_picture.qscale_table[left_mb_xy[1]]; qp[0] = ( mb_qp + mbn0_qp + 1 ) >> 1; - chroma_qp[0] = ( get_chroma_qp( h->pps.chroma_qp_index_offset, mb_qp ) + - get_chroma_qp( h->pps.chroma_qp_index_offset, mbn0_qp ) + 1 ) >> 1; + bqp[0] = ( get_chroma_qp( h, 0, mb_qp ) + + get_chroma_qp( h, 0, mbn0_qp ) + 1 ) >> 1; + rqp[0] = ( get_chroma_qp( h, 1, mb_qp ) + + get_chroma_qp( h, 1, mbn0_qp ) + 1 ) >> 1; qp[1] = ( mb_qp + mbn1_qp + 1 ) >> 1; - chroma_qp[1] = ( get_chroma_qp( h->pps.chroma_qp_index_offset, mb_qp ) + - get_chroma_qp( h->pps.chroma_qp_index_offset, mbn1_qp ) + 1 ) >> 1; + bqp[1] = ( get_chroma_qp( h, 0, mb_qp ) + + get_chroma_qp( h, 0, mbn1_qp ) + 1 ) >> 1; + rqp[1] = ( get_chroma_qp( h, 1, mb_qp ) + + get_chroma_qp( h, 1, mbn1_qp ) + 1 ) >> 1; /* Filter edge */ - tprintf(s->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPc:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], chroma_qp[0], chroma_qp[1], linesize, uvlinesize); + tprintf(s->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPb:%d/%d QPr:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], bqp[0], bqp[1], rqp[0], rqp[1], linesize, uvlinesize); { int i; for (i = 0; i < 8; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } filter_mb_mbaff_edgev ( h, &img_y [0], linesize, bS, qp ); - filter_mb_mbaff_edgecv( h, &img_cb[0], uvlinesize, bS, chroma_qp ); - filter_mb_mbaff_edgecv( h, &img_cr[0], uvlinesize, bS, chroma_qp ); + filter_mb_mbaff_edgecv( h, &img_cb[0], uvlinesize, bS, bqp ); + filter_mb_mbaff_edgecv( h, &img_cr[0], uvlinesize, bS, rqp ); } /* dir : 0 -> vertical edge, 1 -> horizontal edge */ for( dir = 0; dir < 2; dir++ ) @@ -7229,7 +6601,7 @@ static void filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8 unsigned int tmp_linesize = 2 * linesize; unsigned int tmp_uvlinesize = 2 * uvlinesize; int mbn_xy = mb_xy - 2 * s->mb_stride; - int qp, chroma_qp; + int qp; int i, j; int16_t bS[4]; @@ -7253,10 +6625,10 @@ static void filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8 tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize); { int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } filter_mb_edgeh( h, &img_y[j*linesize], tmp_linesize, bS, qp ); - chroma_qp = ( h->chroma_qp + - get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1; - filter_mb_edgech( h, &img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp ); - filter_mb_edgech( h, &img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp ); + filter_mb_edgech( h, &img_cb[j*uvlinesize], tmp_uvlinesize, bS, + ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); + filter_mb_edgech( h, &img_cr[j*uvlinesize], tmp_uvlinesize, bS, + ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); } start = 1; @@ -7353,25 +6725,25 @@ static void filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8 if( dir == 0 ) { filter_mb_edgev( h, &img_y[4*edge], linesize, bS, qp ); if( (edge&1) == 0 ) { - int chroma_qp = ( h->chroma_qp + - get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1; - filter_mb_edgecv( h, &img_cb[2*edge], uvlinesize, bS, chroma_qp ); - filter_mb_edgecv( h, &img_cr[2*edge], uvlinesize, bS, chroma_qp ); + filter_mb_edgecv( h, &img_cb[2*edge], uvlinesize, bS, + ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); + filter_mb_edgecv( h, &img_cr[2*edge], uvlinesize, bS, + ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); } } else { filter_mb_edgeh( h, &img_y[4*edge*linesize], linesize, bS, qp ); if( (edge&1) == 0 ) { - int chroma_qp = ( h->chroma_qp + - get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1; - filter_mb_edgech( h, &img_cb[2*edge*uvlinesize], uvlinesize, bS, chroma_qp ); - filter_mb_edgech( h, &img_cr[2*edge*uvlinesize], uvlinesize, bS, chroma_qp ); + filter_mb_edgech( h, &img_cb[2*edge*uvlinesize], uvlinesize, bS, + ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); + filter_mb_edgech( h, &img_cr[2*edge*uvlinesize], uvlinesize, bS, + ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1); } } } } } -static int decode_slice(H264Context *h){ +static int decode_slice(struct AVCodecContext *avctx, H264Context *h){ MpegEncContext * const s = &h->s; const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F; @@ -7421,7 +6793,7 @@ static int decode_slice(H264Context *h){ eos = get_cabac_terminate( &h->cabac ); if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 2) { - av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%d)\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytestream); + av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%td)\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytestream); ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); return -1; } @@ -7430,7 +6802,7 @@ static int decode_slice(H264Context *h){ s->mb_x = 0; ff_draw_horiz_band(s, 16*s->mb_y, 16); ++s->mb_y; - if(FRAME_MBAFF) { + if(FIELD_OR_MBAFF_PICTURE) { ++s->mb_y; } } @@ -7467,7 +6839,7 @@ static int decode_slice(H264Context *h){ s->mb_x=0; ff_draw_horiz_band(s, 16*s->mb_y, 16); ++s->mb_y; - if(FRAME_MBAFF) { + if(FIELD_OR_MBAFF_PICTURE) { ++s->mb_y; } if(s->mb_y >= s->mb_height){ @@ -7636,7 +7008,7 @@ static inline int decode_vui_parameters(H264Context *h, SPS *sps){ if( aspect_ratio_idc == EXTENDED_SAR ) { sps->sar.num= get_bits(&s->gb, 16); sps->sar.den= get_bits(&s->gb, 16); - }else if(aspect_ratio_idc < 14){ + }else if(aspect_ratio_idc < sizeof(pixel_aspect)/sizeof(*pixel_aspect)){ sps->sar= pixel_aspect[aspect_ratio_idc]; }else{ av_log(h->s.avctx, AV_LOG_ERROR, "illegal aspect ratio\n"); @@ -7753,6 +7125,26 @@ static void decode_scaling_matrices(H264Context *h, SPS *sps, PPS *pps, int is_s } } +/** + * Returns and optionally allocates SPS / PPS structures in the supplied array 'vec' + */ +static void * +alloc_parameter_set(H264Context *h, void **vec, const unsigned int id, const unsigned int max, + const size_t size, const char *name) +{ + if(id>=max) { + av_log(h->s.avctx, AV_LOG_ERROR, "%s_id (%d) out of range\n", name, id); + return NULL; + } + + if(!vec[id]) { + vec[id] = av_mallocz(size); + if(vec[id] == NULL) + av_log(h->s.avctx, AV_LOG_ERROR, "cannot allocate memory for %s\n", name); + } + return vec[id]; +} + static inline int decode_seq_parameter_set(H264Context *h){ MpegEncContext * const s = &h->s; int profile_idc, level_idc; @@ -7769,13 +7161,10 @@ static inline int decode_seq_parameter_set(H264Context *h){ level_idc= get_bits(&s->gb, 8); sps_id= get_ue_golomb(&s->gb); - if (sps_id >= MAX_SPS_COUNT){ - // ok it has gone out of hand, someone is sending us bad stuff. - av_log(h->s.avctx, AV_LOG_ERROR, "illegal sps_id (%d)\n", sps_id); + sps = alloc_parameter_set(h, (void **)h->sps_buffers, sps_id, MAX_SPS_COUNT, sizeof(SPS), "sps"); + if(sps == NULL) return -1; - } - sps= &h->sps_buffer[ sps_id ]; sps->profile_idc= profile_idc; sps->level_idc= level_idc; @@ -7814,8 +7203,9 @@ static inline int decode_seq_parameter_set(H264Context *h){ } tmp= get_ue_golomb(&s->gb); - if(tmp > MAX_PICTURE_COUNT-2){ + if(tmp > MAX_PICTURE_COUNT-2 || tmp >= 32){ av_log(h->s.avctx, AV_LOG_ERROR, "too many reference frames\n"); + return -1; } sps->ref_frame_count= tmp; sps->gaps_in_frame_num_allowed_flag= get_bits1(&s->gb); @@ -7880,19 +7270,25 @@ static inline int decode_seq_parameter_set(H264Context *h){ return 0; } +static void +build_qp_table(PPS *pps, int t, int index) +{ + int i; + for(i = 0; i < 255; i++) + pps->chroma_qp_table[t][i & 0xff] = chroma_qp[av_clip(i + index, 0, 51)]; +} + static inline int decode_picture_parameter_set(H264Context *h, int bit_length){ MpegEncContext * const s = &h->s; unsigned int tmp, pps_id= get_ue_golomb(&s->gb); PPS *pps; - if(pps_id>=MAX_PPS_COUNT){ - av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n"); + pps = alloc_parameter_set(h, (void **)h->pps_buffers, pps_id, MAX_PPS_COUNT, sizeof(PPS), "pps"); + if(pps == NULL) return -1; - } - pps = &h->pps_buffer[pps_id]; tmp= get_ue_golomb(&s->gb); - if(tmp>=MAX_SPS_COUNT){ + if(tmp>=MAX_SPS_COUNT || h->sps_buffers[tmp] == NULL){ av_log(h->s.avctx, AV_LOG_ERROR, "sps_id out of range\n"); return -1; } @@ -7950,7 +7346,7 @@ static inline int decode_picture_parameter_set(H264Context *h, int bit_length){ pps->weighted_bipred_idc= get_bits(&s->gb, 2); pps->init_qp= get_se_golomb(&s->gb) + 26; pps->init_qs= get_se_golomb(&s->gb) + 26; - pps->chroma_qp_index_offset= get_se_golomb(&s->gb); + pps->chroma_qp_index_offset[0]= get_se_golomb(&s->gb); pps->deblocking_filter_parameters_present= get_bits1(&s->gb); pps->constrained_intra_pred= get_bits1(&s->gb); pps->redundant_pic_cnt_present = get_bits1(&s->gb); @@ -7962,18 +7358,27 @@ static inline int decode_picture_parameter_set(H264Context *h, int bit_length){ if(get_bits_count(&s->gb) < bit_length){ pps->transform_8x8_mode= get_bits1(&s->gb); - decode_scaling_matrices(h, &h->sps_buffer[pps->sps_id], pps, 0, pps->scaling_matrix4, pps->scaling_matrix8); - get_se_golomb(&s->gb); //second_chroma_qp_index_offset + decode_scaling_matrices(h, h->sps_buffers[pps->sps_id], pps, 0, pps->scaling_matrix4, pps->scaling_matrix8); + pps->chroma_qp_index_offset[1]= get_se_golomb(&s->gb); //second_chroma_qp_index_offset + } else { + pps->chroma_qp_index_offset[1]= pps->chroma_qp_index_offset[0]; } + build_qp_table(pps, 0, pps->chroma_qp_index_offset[0]); + if(pps->chroma_qp_index_offset[0] != pps->chroma_qp_index_offset[1]) { + build_qp_table(pps, 1, pps->chroma_qp_index_offset[1]); + h->pps.chroma_qp_diff= 1; + } else + memcpy(pps->chroma_qp_table[1], pps->chroma_qp_table[0], 256); + if(s->avctx->debug&FF_DEBUG_PICT_INFO){ - av_log(h->s.avctx, AV_LOG_DEBUG, "pps:%u sps:%u %s slice_groups:%d ref:%d/%d %s qp:%d/%d/%d %s %s %s %s\n", + av_log(h->s.avctx, AV_LOG_DEBUG, "pps:%u sps:%u %s slice_groups:%d ref:%d/%d %s qp:%d/%d/%d/%d %s %s %s %s\n", pps_id, pps->sps_id, pps->cabac ? "CABAC" : "CAVLC", pps->slice_group_count, pps->ref_count[0], pps->ref_count[1], pps->weighted_pred ? "weighted" : "", - pps->init_qp, pps->init_qs, pps->chroma_qp_index_offset, + pps->init_qp, pps->init_qs, pps->chroma_qp_index_offset[0], pps->chroma_qp_index_offset[1], pps->deblocking_filter_parameters_present ? "LPAR" : "", pps->constrained_intra_pred ? "CONSTR" : "", pps->redundant_pic_cnt_present ? "REDU" : "", @@ -7985,119 +7390,49 @@ static inline int decode_picture_parameter_set(H264Context *h, int bit_length){ } /** - * finds the end of the current frame in the bitstream. - * @return the position of the first byte of the next frame, or -1 + * Call decode_slice() for each context. + * + * @param h h264 master context + * @param context_count number of contexts to execute */ -static int find_frame_end(H264Context *h, const uint8_t *buf, int buf_size){ +static void execute_decode_slices(H264Context *h, int context_count){ + MpegEncContext * const s = &h->s; + AVCodecContext * const avctx= s->avctx; + H264Context *hx; int i; - uint32_t state; - ParseContext *pc = &(h->s.parse_context); -//printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]); -// mb_addr= pc->mb_addr - 1; - state= pc->state; - if(state>13) - state= 7; - - for(i=0; i7, 1->4, 0->5 - else if(buf[i]) state = 7; - else state>>=1; //2->1, 1->0, 0->0 - }else if(state<=5){ - int v= buf[i] & 0x1F; - if(v==7 || v==8 || v==9){ - if(pc->frame_start_found){ - i++; -found: - pc->state=7; - pc->frame_start_found= 0; - return i-(state&5); - } - }else if(v==1 || v==2 || v==5){ - if(pc->frame_start_found){ - state+=8; - continue; - }else - pc->frame_start_found = 1; - } - state= 7; - }else{ - if(buf[i] & 0x80) - goto found; - state= 7; - } - } - pc->state= state; - return END_NOT_FOUND; -} - -#ifdef CONFIG_H264_PARSER -static int h264_parse(AVCodecParserContext *s, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - H264Context *h = s->priv_data; - ParseContext *pc = &h->s.parse_context; - int next; - - if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ - next= buf_size; - }else{ - next= find_frame_end(h, buf, buf_size); - - if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { - *poutbuf = NULL; - *poutbuf_size = 0; - return buf_size; - } - if(next<0){ - find_frame_end(h, &pc->buffer[pc->last_index + next], -next); //update state + if(context_count == 1) { + decode_slice(avctx, h); + } else { + for(i = 1; i < context_count; i++) { + hx = h->thread_context[i]; + hx->s.error_resilience = avctx->error_resilience; + hx->s.error_count = 0; } - } - *poutbuf = (uint8_t *)buf; - *poutbuf_size = buf_size; - return next; -} - -static int h264_split(AVCodecContext *avctx, - const uint8_t *buf, int buf_size) -{ - int i; - uint32_t state = -1; - int has_sps= 0; + avctx->execute(avctx, (void *)decode_slice, + (void **)h->thread_context, NULL, context_count); - for(i=0; i<=buf_size; i++){ - if((state&0xFFFFFF1F) == 0x107) - has_sps=1; -/* if((state&0xFFFFFF1F) == 0x101 || (state&0xFFFFFF1F) == 0x102 || (state&0xFFFFFF1F) == 0x105){ - }*/ - if((state&0xFFFFFF00) == 0x100 && (state&0xFFFFFF1F) != 0x107 && (state&0xFFFFFF1F) != 0x108 && (state&0xFFFFFF1F) != 0x109){ - if(has_sps){ - while(i>4 && buf[i-5]==0) i--; - return i-4; - } - } - if (ithread_context[context_count - 1]; + s->mb_x = hx->s.mb_x; + s->mb_y = hx->s.mb_y; + s->dropable = hx->s.dropable; + s->picture_structure = hx->s.picture_structure; + for(i = 1; i < context_count; i++) + h->s.error_count += h->thread_context[i]->s.error_count; } - return 0; } -#endif /* CONFIG_H264_PARSER */ -static int decode_nal_units(H264Context *h, uint8_t *buf, int buf_size){ + +static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){ MpegEncContext * const s = &h->s; AVCodecContext * const avctx= s->avctx; int buf_index=0; + H264Context *hx; ///< thread context + int context_count = 0; + + h->max_contexts = avctx->thread_count; #if 0 int i; for(i=0; i<50; i++){ @@ -8105,54 +7440,58 @@ static int decode_nal_units(H264Context *h, uint8_t *buf, int buf_size){ } #endif if(!(s->flags2 & CODEC_FLAG2_CHUNKS)){ - h->slice_num = 0; - s->current_picture_ptr= NULL; + h->current_slice = 0; + if (!s->first_field) + s->current_picture_ptr= NULL; } for(;;){ int consumed; int dst_length; int bit_length; - uint8_t *ptr; + const uint8_t *ptr; int i, nalsize = 0; - - if(h->is_avc) { - if(buf_index >= buf_size) break; - nalsize = 0; - for(i = 0; i < h->nal_length_size; i++) - nalsize = (nalsize << 8) | buf[buf_index++]; - if(nalsize <= 1 || nalsize > buf_size){ - if(nalsize == 1){ - buf_index++; - continue; - }else{ - av_log(h->s.avctx, AV_LOG_ERROR, "AVC: nal size %d\n", nalsize); - break; + int err; + + if(h->is_avc) { + if(buf_index >= buf_size) break; + nalsize = 0; + for(i = 0; i < h->nal_length_size; i++) + nalsize = (nalsize << 8) | buf[buf_index++]; + if(nalsize <= 1 || (nalsize+buf_index > buf_size)){ + if(nalsize == 1){ + buf_index++; + continue; + }else{ + av_log(h->s.avctx, AV_LOG_ERROR, "AVC: nal size %d\n", nalsize); + break; + } + } + } else { + // start code prefix search + for(; buf_index + 3 < buf_size; buf_index++){ + // This should always succeed in the first iteration. + if(buf[buf_index] == 0 && buf[buf_index+1] == 0 && buf[buf_index+2] == 1) + break; } - } - } else { - // start code prefix search - for(; buf_index + 3 < buf_size; buf_index++){ - // this should allways succeed in the first iteration - if(buf[buf_index] == 0 && buf[buf_index+1] == 0 && buf[buf_index+2] == 1) - break; - } - if(buf_index+3 >= buf_size) break; + if(buf_index+3 >= buf_size) break; - buf_index+=3; - } + buf_index+=3; + } + + hx = h->thread_context[context_count]; - ptr= decode_nal(h, buf + buf_index, &dst_length, &consumed, h->is_avc ? nalsize : buf_size - buf_index); - if (ptr==NULL || dst_length <= 0){ + ptr= decode_nal(hx, buf + buf_index, &dst_length, &consumed, h->is_avc ? nalsize : buf_size - buf_index); + if (ptr==NULL || dst_length < 0){ return -1; } - while(ptr[dst_length - 1] == 0 && dst_length > 1) + while(ptr[dst_length - 1] == 0 && dst_length > 0) dst_length--; - bit_length= 8*dst_length - decode_rbsp_trailing(h, ptr + dst_length - 1); + bit_length= !dst_length ? 0 : (8*dst_length - decode_rbsp_trailing(h, ptr + dst_length - 1)); if(s->avctx->debug&FF_DEBUG_STARTCODE){ - av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d/%d length %d\n", h->nal_unit_type, buf_index, buf_size, dst_length); + av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d/%d length %d\n", hx->nal_unit_type, buf_index, buf_size, dst_length); } if (h->is_avc && (nalsize != consumed)) @@ -8160,57 +7499,60 @@ static int decode_nal_units(H264Context *h, uint8_t *buf, int buf_size){ buf_index += consumed; - if( (s->hurry_up == 1 && h->nal_ref_idc == 0) //FIXME dont discard SEI id + if( (s->hurry_up == 1 && h->nal_ref_idc == 0) //FIXME do not discard SEI id ||(avctx->skip_frame >= AVDISCARD_NONREF && h->nal_ref_idc == 0)) continue; - switch(h->nal_unit_type){ + again: + err = 0; + switch(hx->nal_unit_type){ case NAL_IDR_SLICE: + if (h->nal_unit_type != NAL_IDR_SLICE) { + av_log(h->s.avctx, AV_LOG_ERROR, "Invalid mix of idr and non-idr slices"); + return -1; + } idr(h); //FIXME ensure we don't loose some frames if there is reordering case NAL_SLICE: - init_get_bits(&s->gb, ptr, bit_length); - h->intra_gb_ptr= - h->inter_gb_ptr= &s->gb; - s->data_partitioning = 0; - - if(decode_slice_header(h) < 0){ - av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header error\n"); - break; - } - s->current_picture_ptr->key_frame= (h->nal_unit_type == NAL_IDR_SLICE); - if(h->redundant_pic_count==0 && s->hurry_up < 5 - && (avctx->skip_frame < AVDISCARD_NONREF || h->nal_ref_idc) - && (avctx->skip_frame < AVDISCARD_BIDIR || h->slice_type!=B_TYPE) - && (avctx->skip_frame < AVDISCARD_NONKEY || h->slice_type==I_TYPE) + init_get_bits(&hx->s.gb, ptr, bit_length); + hx->intra_gb_ptr= + hx->inter_gb_ptr= &hx->s.gb; + hx->s.data_partitioning = 0; + + if((err = decode_slice_header(hx, h))) + break; + + s->current_picture_ptr->key_frame|= (hx->nal_unit_type == NAL_IDR_SLICE); + if(hx->redundant_pic_count==0 && hx->s.hurry_up < 5 + && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) + && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type!=B_TYPE) + && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type==I_TYPE) && avctx->skip_frame < AVDISCARD_ALL) - decode_slice(h); + context_count++; break; case NAL_DPA: - init_get_bits(&s->gb, ptr, bit_length); - h->intra_gb_ptr= - h->inter_gb_ptr= NULL; - s->data_partitioning = 1; + init_get_bits(&hx->s.gb, ptr, bit_length); + hx->intra_gb_ptr= + hx->inter_gb_ptr= NULL; + hx->s.data_partitioning = 1; - if(decode_slice_header(h) < 0){ - av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header error\n"); - } + err = decode_slice_header(hx, h); break; case NAL_DPB: - init_get_bits(&h->intra_gb, ptr, bit_length); - h->intra_gb_ptr= &h->intra_gb; + init_get_bits(&hx->intra_gb, ptr, bit_length); + hx->intra_gb_ptr= &hx->intra_gb; break; case NAL_DPC: - init_get_bits(&h->inter_gb, ptr, bit_length); - h->inter_gb_ptr= &h->inter_gb; + init_get_bits(&hx->inter_gb, ptr, bit_length); + hx->inter_gb_ptr= &hx->inter_gb; - if(h->redundant_pic_count==0 && h->intra_gb_ptr && s->data_partitioning + if(hx->redundant_pic_count==0 && hx->intra_gb_ptr && hx->s.data_partitioning && s->context_initialized && s->hurry_up < 5 - && (avctx->skip_frame < AVDISCARD_NONREF || h->nal_ref_idc) - && (avctx->skip_frame < AVDISCARD_BIDIR || h->slice_type!=B_TYPE) - && (avctx->skip_frame < AVDISCARD_NONKEY || h->slice_type==I_TYPE) + && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) + && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type!=B_TYPE) + && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type==I_TYPE) && avctx->skip_frame < AVDISCARD_ALL) - decode_slice(h); + context_count++; break; case NAL_SEI: init_get_bits(&s->gb, ptr, bit_length); @@ -8240,10 +7582,29 @@ static int decode_nal_units(H264Context *h, uint8_t *buf, int buf_size){ case NAL_AUXILIARY_SLICE: break; default: - av_log(avctx, AV_LOG_ERROR, "Unknown NAL code: %d\n", h->nal_unit_type); + av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\n", h->nal_unit_type, bit_length); + } + + if(context_count == h->max_contexts) { + execute_decode_slices(h, context_count); + context_count = 0; } - } + if (err < 0) + av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header error\n"); + else if(err == 1) { + /* Slice could not be decoded in parallel mode, copy down + * NAL unit stuff to context 0 and restart. Note that + * rbsp_buffer is not transfered, but since we no longer + * run in parallel mode this should not be an issue. */ + h->nal_unit_type = hx->nal_unit_type; + h->nal_ref_idc = hx->nal_ref_idc; + hx = h; + goto again; + } + } + if(context_count) + execute_decode_slices(h, context_count); return buf_index; } @@ -8257,7 +7618,7 @@ static int get_consumed_bytes(MpegEncContext *s, int pos, int buf_size){ return pos; }else{ - if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...) + if(pos==0) pos=1; //avoid infinite loops (i doubt that is needed but ...) if(pos+10>buf_size) pos=buf_size; // oops ;) return pos; @@ -8266,7 +7627,7 @@ static int get_consumed_bytes(MpegEncContext *s, int pos, int buf_size){ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { H264Context *h = avctx->priv_data; MpegEncContext *s = &h->s; @@ -8302,9 +7663,9 @@ static int decode_frame(AVCodecContext *avctx, } if(s->flags&CODEC_FLAG_TRUNCATED){ - int next= find_frame_end(h, buf, buf_size); + int next= ff_h264_find_frame_end(h, buf, buf_size); - if( ff_combine_frame(&s->parse_context, next, &buf, &buf_size) < 0 ) + if( ff_combine_frame(&s->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 ) return buf_size; //printf("next:%d buf_size:%d last_index:%d\n", next, buf_size, s->parse_context.last_index); } @@ -8360,6 +7721,7 @@ static int decode_frame(AVCodecContext *avctx, return -1; if(!(s->flags2 & CODEC_FLAG2_CHUNKS) && !s->current_picture_ptr){ + if (avctx->skip_frame >= AVDISCARD_NONREF || s->hurry_up) return 0; av_log(avctx, AV_LOG_ERROR, "no frame!\n"); return -1; } @@ -8377,87 +7739,109 @@ static int decode_frame(AVCodecContext *avctx, h->prev_frame_num_offset= h->frame_num_offset; h->prev_frame_num= h->frame_num; - if(s->current_picture_ptr->reference){ + if(!s->dropable) { h->prev_poc_msb= h->poc_msb; h->prev_poc_lsb= h->poc_lsb; - } - if(s->current_picture_ptr->reference) execute_ref_pic_marking(h, h->mmco, h->mmco_index); + } - ff_er_frame_end(s); + /* + * FIXME: Error handling code does not seem to support interlaced + * when slices span multiple rows + * The ff_er_add_slice calls don't work right for bottom + * fields; they cause massive erroneous error concealing + * Error marking covers both fields (top and bottom). + * This causes a mismatched s->error_count + * and a bad error table. Further, the error count goes to + * INT_MAX when called for bottom field, because mb_y is + * past end by one (callers fault) and resync_mb_y != 0 + * causes problems for the first MB line, too. + */ + if (!FIELD_PICTURE) + ff_er_frame_end(s); MPV_frame_end(s); - //FIXME do something with unavailable reference frames + if (s->first_field) { + /* Wait for second field. */ + *data_size = 0; -#if 0 //decode order - *data_size = sizeof(AVFrame); -#else - /* Sort B-frames into display order */ + } else { + cur->interlaced_frame = FIELD_OR_MBAFF_PICTURE; + /* Derive top_field_first from field pocs. */ + cur->top_field_first = cur->field_poc[0] < cur->field_poc[1]; - if(h->sps.bitstream_restriction_flag - && s->avctx->has_b_frames < h->sps.num_reorder_frames){ - s->avctx->has_b_frames = h->sps.num_reorder_frames; - s->low_delay = 0; - } + //FIXME do something with unavailable reference frames - pics = 0; - while(h->delayed_pic[pics]) pics++; +#if 0 //decode order + *data_size = sizeof(AVFrame); +#else + /* Sort B-frames into display order */ - assert(pics+1 < sizeof(h->delayed_pic) / sizeof(h->delayed_pic[0])); + if(h->sps.bitstream_restriction_flag + && s->avctx->has_b_frames < h->sps.num_reorder_frames){ + s->avctx->has_b_frames = h->sps.num_reorder_frames; + s->low_delay = 0; + } - h->delayed_pic[pics++] = cur; - if(cur->reference == 0) - cur->reference = 1; + pics = 0; + while(h->delayed_pic[pics]) pics++; - cross_idr = 0; - for(i=0; h->delayed_pic[i]; i++) - if(h->delayed_pic[i]->key_frame || h->delayed_pic[i]->poc==0) - cross_idr = 1; + assert(pics+1 < sizeof(h->delayed_pic) / sizeof(h->delayed_pic[0])); - out = h->delayed_pic[0]; - out_idx = 0; - for(i=1; h->delayed_pic[i] && !h->delayed_pic[i]->key_frame; i++) - if(h->delayed_pic[i]->poc < out->poc){ - out = h->delayed_pic[i]; - out_idx = i; - } + h->delayed_pic[pics++] = cur; + if(cur->reference == 0) + cur->reference = DELAYED_PIC_REF; - out_of_order = !cross_idr && prev && out->poc < prev->poc; - if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames >= h->sps.num_reorder_frames) - { } - else if(prev && pics <= s->avctx->has_b_frames) - out = prev; - else if((out_of_order && pics-1 == s->avctx->has_b_frames && pics < 15) - || (s->low_delay && - ((!cross_idr && prev && out->poc > prev->poc + 2) - || cur->pict_type == B_TYPE))) - { - s->low_delay = 0; - s->avctx->has_b_frames++; - out = prev; - } - else if(out_of_order) - out = prev; + cross_idr = 0; + for(i=0; h->delayed_pic[i]; i++) + if(h->delayed_pic[i]->key_frame || h->delayed_pic[i]->poc==0) + cross_idr = 1; - if(out_of_order || pics > s->avctx->has_b_frames){ - for(i=out_idx; h->delayed_pic[i]; i++) - h->delayed_pic[i] = h->delayed_pic[i+1]; - } + out = h->delayed_pic[0]; + out_idx = 0; + for(i=1; h->delayed_pic[i] && !h->delayed_pic[i]->key_frame; i++) + if(h->delayed_pic[i]->poc < out->poc){ + out = h->delayed_pic[i]; + out_idx = i; + } - if(prev == out) - *data_size = 0; - else - *data_size = sizeof(AVFrame); - if(prev && prev != out && prev->reference == 1) - prev->reference = 0; - h->delayed_output_pic = out; + out_of_order = !cross_idr && prev && out->poc < prev->poc; + if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames >= h->sps.num_reorder_frames) + { } + else if(prev && pics <= s->avctx->has_b_frames) + out = prev; + else if((out_of_order && pics-1 == s->avctx->has_b_frames && pics < 15) + || (s->low_delay && + ((!cross_idr && prev && out->poc > prev->poc + 2) + || cur->pict_type == B_TYPE))) + { + s->low_delay = 0; + s->avctx->has_b_frames++; + out = prev; + } + else if(out_of_order) + out = prev; + + if(out_of_order || pics > s->avctx->has_b_frames){ + for(i=out_idx; h->delayed_pic[i]; i++) + h->delayed_pic[i] = h->delayed_pic[i+1]; + } + + if(prev == out) + *data_size = 0; + else + *data_size = sizeof(AVFrame); + if(prev && prev != out && prev->reference == DELAYED_PIC_REF) + prev->reference = 0; + h->delayed_output_pic = out; #endif - if(out) - *pict= *(AVFrame*)out; - else - av_log(avctx, AV_LOG_DEBUG, "no picture\n"); + if(out) + *pict= *(AVFrame*)out; + else + av_log(avctx, AV_LOG_DEBUG, "no picture\n"); + } } assert(pict->data[0] || !*data_size); @@ -8466,7 +7850,7 @@ static int decode_frame(AVCodecContext *avctx, #if 0 //? /* Return the Picture timestamp as the frame number */ - /* we substract 1 because it is added on utils.c */ + /* we subtract 1 because it is added on utils.c */ avctx->frame_number = s->picture_number - 1; #endif return get_consumed_bytes(s, buf_index, buf_size); @@ -8491,10 +7875,12 @@ static inline void fill_mb_avail(H264Context *h){ } #endif -#if 0 //selftest +#ifdef TEST +#undef printf +#undef random #define COUNT 8000 #define SIZE (COUNT*40) -int main(){ +int main(void){ int i; uint8_t temp[SIZE]; PutBitContext pb; @@ -8523,7 +7909,7 @@ int main(){ START_TIMER j= get_ue_golomb(&gb); if(j != i){ - printf("missmatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s); + printf("mismatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s); // return -1; } STOP_TIMER("get_ue_golomb"); @@ -8548,12 +7934,13 @@ int main(){ START_TIMER j= get_se_golomb(&gb); if(j != i - COUNT/2){ - printf("missmatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s); + printf("mismatch! at %d (%d should be %d) bits:%6X\n", i, j, i, s); // return -1; } STOP_TIMER("get_se_golomb"); } +#if 0 printf("testing 4x4 (I)DCT\n"); DCTELEM block[16]; @@ -8593,14 +7980,12 @@ int main(){ } } printf("error=%f max_error=%d\n", ((float)error)/COUNT/16, (int)max_error ); -#if 0 printf("testing quantizer\n"); for(qp=0; qp<52; qp++){ for(i=0; i<16; i++) src1_block[i]= src2_block[i]= random()%255; } -#endif printf("Testing NAL layer\n"); uint8_t bitstream[COUNT]; @@ -8652,17 +8037,18 @@ int main(){ } if(memcmp(bitstream, out, COUNT)){ - printf("missmatch\n"); + printf("mismatch\n"); return -1; } } +#endif printf("Testing RBSP\n"); return 0; } -#endif +#endif /* TEST */ static int decode_end(AVCodecContext *avctx) @@ -8670,7 +8056,8 @@ static int decode_end(AVCodecContext *avctx) H264Context *h = avctx->priv_data; MpegEncContext *s = &h->s; - av_freep(&h->rbsp_buffer); + av_freep(&h->rbsp_buffer[0]); + av_freep(&h->rbsp_buffer[1]); free_tables(h); //FIXME cleanup init stuff perhaps MPV_common_end(s); @@ -8693,15 +8080,4 @@ AVCodec h264_decoder = { .flush= flush_dpb, }; -#ifdef CONFIG_H264_PARSER -AVCodecParser h264_parser = { - { CODEC_ID_H264 }, - sizeof(H264Context), - NULL, - h264_parse, - ff_parse_close, - h264_split, -}; -#endif - #include "svq3.c" diff --git a/contrib/ffmpeg/libavcodec/h264.h b/contrib/ffmpeg/libavcodec/h264.h new file mode 100644 index 000000000..f45b3a6a4 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/h264.h @@ -0,0 +1,419 @@ +/* + * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder + * Copyright (c) 2003 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file h264.h + * H.264 / AVC / MPEG4 part10 codec. + * @author Michael Niedermayer + */ + +#ifndef FFMPEG_H264_H +#define FFMPEG_H264_H + +#include "dsputil.h" +#include "cabac.h" +#include "mpegvideo.h" +#include "h264pred.h" + +#define interlaced_dct interlaced_dct_is_a_bad_name +#define mb_intra mb_intra_is_not_initialized_see_mb_type + +#define LUMA_DC_BLOCK_INDEX 25 +#define CHROMA_DC_BLOCK_INDEX 26 + +#define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8 +#define COEFF_TOKEN_VLC_BITS 8 +#define TOTAL_ZEROS_VLC_BITS 9 +#define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3 +#define RUN_VLC_BITS 3 +#define RUN7_VLC_BITS 6 + +#define MAX_SPS_COUNT 32 +#define MAX_PPS_COUNT 256 + +#define MAX_MMCO_COUNT 66 + +/* Compiling in interlaced support reduces the speed + * of progressive decoding by about 2%. */ +#define ALLOW_INTERLACE + +#ifdef ALLOW_INTERLACE +#define MB_MBAFF h->mb_mbaff +#define MB_FIELD h->mb_field_decoding_flag +#define FRAME_MBAFF h->mb_aff_frame +#define FIELD_PICTURE (s->picture_structure != PICT_FRAME) +#else +#define MB_MBAFF 0 +#define MB_FIELD 0 +#define FRAME_MBAFF 0 +#define FIELD_PICTURE 0 +#undef IS_INTERLACED +#define IS_INTERLACED(mb_type) 0 +#endif +#define FIELD_OR_MBAFF_PICTURE (FRAME_MBAFF || FIELD_PICTURE) + +/** + * Sequence parameter set + */ +typedef struct SPS{ + + int profile_idc; + int level_idc; + int transform_bypass; ///< qpprime_y_zero_transform_bypass_flag + int log2_max_frame_num; ///< log2_max_frame_num_minus4 + 4 + int poc_type; ///< pic_order_cnt_type + int log2_max_poc_lsb; ///< log2_max_pic_order_cnt_lsb_minus4 + int delta_pic_order_always_zero_flag; + int offset_for_non_ref_pic; + int offset_for_top_to_bottom_field; + int poc_cycle_length; ///< num_ref_frames_in_pic_order_cnt_cycle + int ref_frame_count; ///< num_ref_frames + int gaps_in_frame_num_allowed_flag; + int mb_width; ///< pic_width_in_mbs_minus1 + 1 + int mb_height; ///< pic_height_in_map_units_minus1 + 1 + int frame_mbs_only_flag; + int mb_aff; ///b4_stride + int b8_stride; + + int mb_linesize; ///< may be equal to s->linesize or s->linesize*2, for mbaff + int mb_uvlinesize; + + int emu_edge_width; + int emu_edge_height; + + int halfpel_flag; + int thirdpel_flag; + + int unknown_svq3_flag; + int next_slice_index; + + SPS *sps_buffers[MAX_SPS_COUNT]; + SPS sps; ///< current sps + + PPS *pps_buffers[MAX_PPS_COUNT]; + /** + * current pps + */ + PPS pps; //FIXME move to Picture perhaps? (->no) do we need that? + + uint32_t dequant4_buffer[6][52][16]; + uint32_t dequant8_buffer[2][52][64]; + uint32_t (*dequant4_coeff[6])[16]; + uint32_t (*dequant8_coeff[2])[64]; + int dequant_coeff_pps; ///< reinit tables when pps changes + + int slice_num; + uint8_t *slice_table_base; + uint8_t *slice_table; ///< slice_table_base + 2*mb_stride + 1 + int slice_type; + int slice_type_fixed; + + //interlacing specific flags + int mb_aff_frame; + int mb_field_decoding_flag; + int mb_mbaff; ///< mb_aff_frame && mb_field_decoding_flag + + unsigned int sub_mb_type[4]; + + //POC stuff + int poc_lsb; + int poc_msb; + int delta_poc_bottom; + int delta_poc[2]; + int frame_num; + int prev_poc_msb; ///< poc_msb of the last reference pic for POC type 0 + int prev_poc_lsb; ///< poc_lsb of the last reference pic for POC type 0 + int frame_num_offset; ///< for POC type 2 + int prev_frame_num_offset; ///< for POC type 2 + int prev_frame_num; ///< frame_num of the last pic for POC type 1/2 + + /** + * frame_num for frames or 2*frame_num+1 for field pics. + */ + int curr_pic_num; + + /** + * max_frame_num or 2*max_frame_num for field pics. + */ + int max_pic_num; + + //Weighted pred stuff + int use_weight; + int use_weight_chroma; + int luma_log2_weight_denom; + int chroma_log2_weight_denom; + int luma_weight[2][48]; + int luma_offset[2][48]; + int chroma_weight[2][48][2]; + int chroma_offset[2][48][2]; + int implicit_weight[48][48]; + + //deblock + int deblocking_filter; ///< disable_deblocking_filter_idc with 1<->0 + int slice_alpha_c0_offset; + int slice_beta_offset; + + int redundant_pic_count; + + int direct_spatial_mv_pred; + int dist_scale_factor[16]; + int dist_scale_factor_field[32]; + int map_col_to_list0[2][16]; + int map_col_to_list0_field[2][32]; + + /** + * num_ref_idx_l0/1_active_minus1 + 1 + */ + unsigned int ref_count[2]; ///< counts frames or fields, depending on current mb mode + unsigned int list_count; + Picture *short_ref[32]; + Picture *long_ref[32]; + Picture default_ref_list[2][32]; ///< base reference list for all slices of a coded picture + Picture ref_list[2][48]; /**< 0..15: frame refs, 16..47: mbaff field refs. + Reordered version of default_ref_list + according to picture reordering in slice header */ + Picture *delayed_pic[18]; //FIXME size? + Picture *delayed_output_pic; + + /** + * memory management control operations buffer. + */ + MMCO mmco[MAX_MMCO_COUNT]; + int mmco_index; + + int long_ref_count; ///< number of actual long term references + int short_ref_count; ///< number of actual short term references + + //data partitioning + GetBitContext intra_gb; + GetBitContext inter_gb; + GetBitContext *intra_gb_ptr; + GetBitContext *inter_gb_ptr; + + DECLARE_ALIGNED_16(DCTELEM, mb[16*24]); + DCTELEM mb_padding[256]; ///< as mb is addressed by scantable[i] and scantable is uint8_t we can either check that i is not to large or ensure that there is some unused stuff after mb + + /** + * Cabac + */ + CABACContext cabac; + uint8_t cabac_state[460]; + int cabac_init_idc; + + /* 0x100 -> non null luma_dc, 0x80/0x40 -> non null chroma_dc (cb/cr), 0x?0 -> chroma_cbp(0,1,2), 0x0? luma_cbp */ + uint16_t *cbp_table; + int cbp; + int top_cbp; + int left_cbp; + /* chroma_pred_mode for i4x4 or i16x16, else 0 */ + uint8_t *chroma_pred_mode_table; + int last_qscale_diff; + int16_t (*mvd_table[2])[2]; + DECLARE_ALIGNED_8(int16_t, mvd_cache[2][5*8][2]); + uint8_t *direct_table; + uint8_t direct_cache[5*8]; + + uint8_t zigzag_scan[16]; + uint8_t zigzag_scan8x8[64]; + uint8_t zigzag_scan8x8_cavlc[64]; + uint8_t field_scan[16]; + uint8_t field_scan8x8[64]; + uint8_t field_scan8x8_cavlc[64]; + const uint8_t *zigzag_scan_q0; + const uint8_t *zigzag_scan8x8_q0; + const uint8_t *zigzag_scan8x8_cavlc_q0; + const uint8_t *field_scan_q0; + const uint8_t *field_scan8x8_q0; + const uint8_t *field_scan8x8_cavlc_q0; + + int x264_build; + + /** + * @defgroup multithreading Members for slice based multithreading + * @{ + */ + struct H264Context *thread_context[MAX_THREADS]; + + /** + * current slice number, used to initalize slice_num of each thread/context + */ + int current_slice; + + /** + * Max number of threads / contexts. + * This is equal to AVCodecContext.thread_count unless + * multithreaded decoding is impossible, in which case it is + * reduced to 1. + */ + int max_contexts; + + /** + * 1 if the single thread fallback warning has already been + * displayed, 0 otherwise. + */ + int single_decode_warning; + + int last_slice_type; + /** @} */ + +}H264Context; + +#endif /* FFMPEG_H264_H */ diff --git a/contrib/ffmpeg/libavcodec/h264_mp4toannexb_bsf.c b/contrib/ffmpeg/libavcodec/h264_mp4toannexb_bsf.c new file mode 100644 index 000000000..03eb956ca --- /dev/null +++ b/contrib/ffmpeg/libavcodec/h264_mp4toannexb_bsf.c @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2007 Benoit Fouet + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" + +typedef struct H264BSFContext { + uint8_t length_size; + uint8_t first_idr; + uint8_t *sps_pps_data; + uint32_t size; +} H264BSFContext; + +static void alloc_and_copy(uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *sps_pps, uint32_t sps_pps_size, + const uint8_t *in, uint32_t in_size) { + uint32_t offset = *poutbuf_size; + uint8_t nal_header_size = offset ? 3 : 4; + + *poutbuf_size += sps_pps_size+in_size+nal_header_size; + *poutbuf = av_realloc(*poutbuf, *poutbuf_size); + if (sps_pps) + memcpy(*poutbuf+offset, sps_pps, sps_pps_size); + memcpy(*poutbuf+sps_pps_size+nal_header_size+offset, in, in_size); + if (!offset) + AV_WB32(*poutbuf+sps_pps_size, 1); + else { + (*poutbuf+offset+sps_pps_size)[0] = (*poutbuf+offset+sps_pps_size)[1] = 0; + (*poutbuf+offset+sps_pps_size)[2] = 1; + } +} + +static int h264_mp4toannexb_filter(AVBitStreamFilterContext *bsfc, + AVCodecContext *avctx, const char *args, + uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size, + int keyframe) { + H264BSFContext *ctx = bsfc->priv_data; + uint8_t unit_type; + uint32_t nal_size, cumul_size = 0; + + /* nothing to filter */ + if (!avctx->extradata || avctx->extradata_size < 6) { + *poutbuf = (uint8_t*) buf; + *poutbuf_size = buf_size; + return 0; + } + + /* retrieve sps and pps NAL units from extradata */ + if (!ctx->sps_pps_data) { + uint16_t unit_size; + uint32_t total_size = 0; + uint8_t *out = NULL, unit_nb, sps_done = 0; + const uint8_t *extradata = avctx->extradata+4; + static const uint8_t nalu_header[4] = {0, 0, 0, 1}; + + /* retrieve length coded size */ + ctx->length_size = (*extradata++ & 0x3) + 1; + if (ctx->length_size == 3) + return AVERROR(EINVAL); + + /* retrieve sps and pps unit(s) */ + unit_nb = *extradata++ & 0x1f; /* number of sps unit(s) */ + if (!unit_nb) { + unit_nb = *extradata++; /* number of pps unit(s) */ + sps_done++; + } + while (unit_nb--) { + unit_size = AV_RB16(extradata); + total_size += unit_size+4; + if (extradata+2+unit_size > avctx->extradata+avctx->extradata_size) { + av_free(out); + return AVERROR(EINVAL); + } + out = av_realloc(out, total_size); + if (!out) + return AVERROR(ENOMEM); + memcpy(out+total_size-unit_size-4, nalu_header, 4); + memcpy(out+total_size-unit_size, extradata+2, unit_size); + extradata += 2+unit_size; + + if (!unit_nb && !sps_done++) + unit_nb = *extradata++; /* number of pps unit(s) */ + } + + ctx->sps_pps_data = out; + ctx->size = total_size; + ctx->first_idr = 1; + } + + *poutbuf_size = 0; + *poutbuf = NULL; + do { + if (ctx->length_size == 1) + nal_size = buf[0]; + else if (ctx->length_size == 2) + nal_size = AV_RB16(buf); + else + nal_size = AV_RB32(buf); + + buf += ctx->length_size; + unit_type = *buf & 0x1f; + + /* prepend only to the first type 5 NAL unit of an IDR picture */ + if (ctx->first_idr && unit_type == 5) { + alloc_and_copy(poutbuf, poutbuf_size, + ctx->sps_pps_data, ctx->size, + buf, nal_size); + ctx->first_idr = 0; + } + else { + alloc_and_copy(poutbuf, poutbuf_size, + NULL, 0, + buf, nal_size); + if (!ctx->first_idr && unit_type == 1) + ctx->first_idr = 1; + } + + buf += nal_size; + cumul_size += nal_size + ctx->length_size; + } while (cumul_size < buf_size); + + return 1; +} + +static void h264_mp4toannexb_close(AVBitStreamFilterContext *bsfc) +{ + H264BSFContext *ctx = bsfc->priv_data; + av_freep(&ctx->sps_pps_data); +} + +AVBitStreamFilter h264_mp4toannexb_bsf = { + "h264_mp4toannexb", + sizeof(H264BSFContext), + h264_mp4toannexb_filter, + h264_mp4toannexb_close, +}; + diff --git a/contrib/ffmpeg/libavcodec/h264_parser.c b/contrib/ffmpeg/libavcodec/h264_parser.c new file mode 100644 index 000000000..7a85d770c --- /dev/null +++ b/contrib/ffmpeg/libavcodec/h264_parser.c @@ -0,0 +1,148 @@ +/* + * H.26L/H.264/AVC/JVT/14496-10/... parser + * Copyright (c) 2003 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file h264_parser.c + * H.264 / AVC / MPEG4 part10 parser. + * @author Michael Niedermayer + */ + +#include "parser.h" +#include "h264_parser.h" + +#include + + +int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_size) +{ + int i; + uint32_t state; + ParseContext *pc = &(h->s.parse_context); +//printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]); +// mb_addr= pc->mb_addr - 1; + state= pc->state; + if(state>13) + state= 7; + + for(i=0; i7, 1->4, 0->5 + else if(buf[i]) state = 7; + else state>>=1; //2->1, 1->0, 0->0 + }else if(state<=5){ + int v= buf[i] & 0x1F; + if(v==7 || v==8 || v==9){ + if(pc->frame_start_found){ + i++; +found: + pc->state=7; + pc->frame_start_found= 0; + return i-(state&5); + } + }else if(v==1 || v==2 || v==5){ + if(pc->frame_start_found){ + state+=8; + continue; + }else + pc->frame_start_found = 1; + } + state= 7; + }else{ + if(buf[i] & 0x80) + goto found; + state= 7; + } + } + pc->state= state; + return END_NOT_FOUND; +} + +static int h264_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + H264Context *h = s->priv_data; + ParseContext *pc = &h->s.parse_context; + int next; + + if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ + next= buf_size; + }else{ + next= ff_h264_find_frame_end(h, buf, buf_size); + + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + + if(next<0 && next != END_NOT_FOUND){ + assert(pc->last_index + next >= 0 ); + ff_h264_find_frame_end(h, &pc->buffer[pc->last_index + next], -next); //update state + } + } + + *poutbuf = buf; + *poutbuf_size = buf_size; + return next; +} + +static int h264_split(AVCodecContext *avctx, + const uint8_t *buf, int buf_size) +{ + int i; + uint32_t state = -1; + int has_sps= 0; + + for(i=0; i<=buf_size; i++){ + if((state&0xFFFFFF1F) == 0x107) + has_sps=1; +/* if((state&0xFFFFFF1F) == 0x101 || (state&0xFFFFFF1F) == 0x102 || (state&0xFFFFFF1F) == 0x105){ + }*/ + if((state&0xFFFFFF00) == 0x100 && (state&0xFFFFFF1F) != 0x107 && (state&0xFFFFFF1F) != 0x108 && (state&0xFFFFFF1F) != 0x109){ + if(has_sps){ + while(i>4 && buf[i-5]==0) i--; + return i-4; + } + } + if (i + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file h264_parser.h + * H.264 / AVC / MPEG4 part10 parser. + * @author Michael Niedermayer + */ + +#ifndef FFMPEG_H264_PARSER_H +#define FFMPEG_H264_PARSER_H + +#include "h264.h" + +/** + * finds the end of the current frame in the bitstream. + * @return the position of the first byte of the next frame, or -1 + */ +int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_size); + +#endif /* FFMPEG_H264_PARSER_H */ diff --git a/contrib/ffmpeg/libavcodec/h264data.h b/contrib/ffmpeg/libavcodec/h264data.h index 74e720421..dce1666fc 100644 --- a/contrib/ffmpeg/libavcodec/h264data.h +++ b/contrib/ffmpeg/libavcodec/h264data.h @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -27,29 +26,13 @@ * @author Michael Niedermayer */ -#define VERT_PRED 0 -#define HOR_PRED 1 -#define DC_PRED 2 -#define DIAG_DOWN_LEFT_PRED 3 -#define DIAG_DOWN_RIGHT_PRED 4 -#define VERT_RIGHT_PRED 5 -#define HOR_DOWN_PRED 6 -#define VERT_LEFT_PRED 7 -#define HOR_UP_PRED 8 - -#define LEFT_DC_PRED 9 -#define TOP_DC_PRED 10 -#define DC_128_PRED 11 +#ifndef FFMPEG_H264DATA_H +#define FFMPEG_H264DATA_H +#include +#include "mpegvideo.h" +#include "rational.h" -#define DC_PRED8x8 0 -#define HOR_PRED8x8 1 -#define VERT_PRED8x8 2 -#define PLANE_PRED8x8 3 - -#define LEFT_DC_PRED8x8 4 -#define TOP_DC_PRED8x8 5 -#define DC_128_PRED8x8 6 #define EXTENDED_SAR 255 @@ -71,7 +54,7 @@ NAL_SPS_EXT, NAL_AUXILIARY_SLICE=19 }; -static const AVRational pixel_aspect[14]={ +static const AVRational pixel_aspect[17]={ {0, 1}, {1, 1}, {12, 11}, @@ -86,6 +69,9 @@ static const AVRational pixel_aspect[14]={ {15, 11}, {64, 33}, {160,99}, + {4, 3}, + {3, 2}, + {2, 1}, }; static const uint8_t golomb_to_pict_type[5]= @@ -538,7 +524,7 @@ static const uint8_t default_scaling8[2][64]={ 24,25,27,28,30,32,33,35 }}; -static const int dequant4_coeff_init[6][3]={ +static const uint8_t dequant4_coeff_init[6][3]={ {10,13,16}, {11,14,18}, {13,16,20}, @@ -547,10 +533,10 @@ static const int dequant4_coeff_init[6][3]={ {18,23,29}, }; -static const int dequant8_coeff_init_scan[16] = { +static const uint8_t dequant8_coeff_init_scan[16] = { 0,3,4,3, 3,1,5,1, 4,5,2,5, 3,1,5,1 }; -static const int dequant8_coeff_init[6][6]={ +static const uint8_t dequant8_coeff_init[6][6]={ {20,18,32,19,25,24}, {22,19,35,21,28,26}, {26,23,42,24,33,31}, @@ -618,7 +604,7 @@ static const int quant_coeff[52][16]={ /* Deblocking filter (p153) */ -static const int alpha_table[52*3] = { +static const uint8_t alpha_table[52*3] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -634,7 +620,7 @@ static const int alpha_table[52*3] = { 255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255, }; -static const int beta_table[52*3] = { +static const uint8_t beta_table[52*3] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -650,7 +636,7 @@ static const int beta_table[52*3] = { 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, }; -static const int tc0_table[52*3][3] = { +static const uint8_t tc0_table[52*3][3] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, @@ -682,7 +668,7 @@ static const int tc0_table[52*3][3] = { /* Cabac pre state table */ -static const int cabac_context_init_I[460][2] = +static const int8_t cabac_context_init_I[460][2] = { /* 0 - 10 */ { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 }, @@ -851,7 +837,7 @@ static const int cabac_context_init_I[460][2] = { 29, 9 }, { 35, 20 }, { 29, 36 }, { 14, 67 } }; -static const int cabac_context_init_PB[3][460][2] = +static const int8_t cabac_context_init_PB[3][460][2] = { /* i_cabac_init_idc == 0 */ { @@ -1321,3 +1307,5 @@ static const int cabac_context_init_PB[3][460][2] = { 31, 12 }, { 37, 23 }, { 31, 38 }, { 20, 64 }, } }; + +#endif /* FFMPEG_H264DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/h264dsp.c b/contrib/ffmpeg/libavcodec/h264dsp.c deleted file mode 100644 index 4f18afac4..000000000 --- a/contrib/ffmpeg/libavcodec/h264dsp.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * H.264/MPEG-4 Part 10 (Base profile) encoder. - * - * DSP functions - * - * Copyright (c) 2006 Expertisecentrum Digitale Media, UHasselt - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file h264dsp.c - * H.264 encoder related DSP utils - * - */ - -#include "dsputil.h" - -extern const uint8_t ff_div6[52]; -extern const uint8_t ff_rem6[52]; - -#define H264_DCT_PART1(X) \ - a = block[0][X]+block[3][X]; \ - c = block[0][X]-block[3][X]; \ - b = block[1][X]+block[2][X]; \ - d = block[1][X]-block[2][X]; \ - pieces[0][X] = a+b; \ - pieces[2][X] = a-b; \ - pieces[1][X] = (c<<1)+d; \ - pieces[3][X] = c-(d<<1); - -#define H264_DCT_PART2(X) \ - a = pieces[X][0]+pieces[X][3]; \ - c = pieces[X][0]-pieces[X][3]; \ - b = pieces[X][1]+pieces[X][2]; \ - d = pieces[X][1]-pieces[X][2]; \ - block[0][X] = a+b; \ - block[2][X] = a-b; \ - block[1][X] = (c<<1)+d; \ - block[3][X] = c-(d<<1); - -/** - * Transform the provided matrix using the H.264 modified DCT. - * @note - * we'll always work with transposed input blocks, to avoid having to make a - * distinction between C and mmx implementations. - * - * @param block transposed input block - */ -static void h264_dct_c(DCTELEM block[4][4]) -{ - DCTELEM pieces[4][4]; - DCTELEM a, b, c, d; - - H264_DCT_PART1(0); - H264_DCT_PART1(1); - H264_DCT_PART1(2); - H264_DCT_PART1(3); - H264_DCT_PART2(0); - H264_DCT_PART2(1); - H264_DCT_PART2(2); - H264_DCT_PART2(3); -} - -void ff_h264dsp_init(DSPContext* c, AVCodecContext *avctx) -{ - c->h264_dct = h264_dct_c; -} - diff --git a/contrib/ffmpeg/libavcodec/h264dspenc.c b/contrib/ffmpeg/libavcodec/h264dspenc.c new file mode 100644 index 000000000..061de5e10 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/h264dspenc.c @@ -0,0 +1,81 @@ +/* + * H.264/MPEG-4 Part 10 (Base profile) encoder. + * + * DSP functions + * + * Copyright (c) 2006 Expertisecentrum Digitale Media, UHasselt + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file h264dspenc.c + * H.264 encoder related DSP utils + * + */ + +#include "dsputil.h" + +extern const uint8_t ff_div6[52]; +extern const uint8_t ff_rem6[52]; + +#define H264_DCT_PART1(X) \ + a = block[0][X]+block[3][X]; \ + c = block[0][X]-block[3][X]; \ + b = block[1][X]+block[2][X]; \ + d = block[1][X]-block[2][X]; \ + pieces[0][X] = a+b; \ + pieces[2][X] = a-b; \ + pieces[1][X] = (c<<1)+d; \ + pieces[3][X] = c-(d<<1); + +#define H264_DCT_PART2(X) \ + a = pieces[X][0]+pieces[X][3]; \ + c = pieces[X][0]-pieces[X][3]; \ + b = pieces[X][1]+pieces[X][2]; \ + d = pieces[X][1]-pieces[X][2]; \ + block[0][X] = a+b; \ + block[2][X] = a-b; \ + block[1][X] = (c<<1)+d; \ + block[3][X] = c-(d<<1); + +/** + * Transform the provided matrix using the H.264 modified DCT. + * @note + * we'll always work with transposed input blocks, to avoid having to make a + * distinction between C and mmx implementations. + * + * @param block transposed input block + */ +static void h264_dct_c(DCTELEM block[4][4]) +{ + DCTELEM pieces[4][4]; + DCTELEM a, b, c, d; + + H264_DCT_PART1(0); + H264_DCT_PART1(1); + H264_DCT_PART1(2); + H264_DCT_PART1(3); + H264_DCT_PART2(0); + H264_DCT_PART2(1); + H264_DCT_PART2(2); + H264_DCT_PART2(3); +} + +void ff_h264dspenc_init(DSPContext* c, AVCodecContext *avctx) +{ + c->h264_dct = h264_dct_c; +} + diff --git a/contrib/ffmpeg/libavcodec/h264idct.c b/contrib/ffmpeg/libavcodec/h264idct.c index a6a56d33a..571e2e91d 100644 --- a/contrib/ffmpeg/libavcodec/h264idct.c +++ b/contrib/ffmpeg/libavcodec/h264idct.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** diff --git a/contrib/ffmpeg/libavcodec/h264pred.c b/contrib/ffmpeg/libavcodec/h264pred.c new file mode 100644 index 000000000..b3e84b72a --- /dev/null +++ b/contrib/ffmpeg/libavcodec/h264pred.c @@ -0,0 +1,1073 @@ +/* + * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder + * Copyright (c) 2003 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file h264pred.c + * H.264 / AVC / MPEG4 part10 prediction functions. + * @author Michael Niedermayer + */ + +#include "avcodec.h" +#include "mpegvideo.h" +#include "h264pred.h" + +static void pred4x4_vertical_c(uint8_t *src, uint8_t *topright, int stride){ + const uint32_t a= ((uint32_t*)(src-stride))[0]; + ((uint32_t*)(src+0*stride))[0]= a; + ((uint32_t*)(src+1*stride))[0]= a; + ((uint32_t*)(src+2*stride))[0]= a; + ((uint32_t*)(src+3*stride))[0]= a; +} + +static void pred4x4_horizontal_c(uint8_t *src, uint8_t *topright, int stride){ + ((uint32_t*)(src+0*stride))[0]= src[-1+0*stride]*0x01010101; + ((uint32_t*)(src+1*stride))[0]= src[-1+1*stride]*0x01010101; + ((uint32_t*)(src+2*stride))[0]= src[-1+2*stride]*0x01010101; + ((uint32_t*)(src+3*stride))[0]= src[-1+3*stride]*0x01010101; +} + +static void pred4x4_dc_c(uint8_t *src, uint8_t *topright, int stride){ + const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + + src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 4) >>3; + + ((uint32_t*)(src+0*stride))[0]= + ((uint32_t*)(src+1*stride))[0]= + ((uint32_t*)(src+2*stride))[0]= + ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; +} + +static void pred4x4_left_dc_c(uint8_t *src, uint8_t *topright, int stride){ + const int dc= ( src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 2) >>2; + + ((uint32_t*)(src+0*stride))[0]= + ((uint32_t*)(src+1*stride))[0]= + ((uint32_t*)(src+2*stride))[0]= + ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; +} + +static void pred4x4_top_dc_c(uint8_t *src, uint8_t *topright, int stride){ + const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + 2) >>2; + + ((uint32_t*)(src+0*stride))[0]= + ((uint32_t*)(src+1*stride))[0]= + ((uint32_t*)(src+2*stride))[0]= + ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; +} + +static void pred4x4_128_dc_c(uint8_t *src, uint8_t *topright, int stride){ + ((uint32_t*)(src+0*stride))[0]= + ((uint32_t*)(src+1*stride))[0]= + ((uint32_t*)(src+2*stride))[0]= + ((uint32_t*)(src+3*stride))[0]= 128U*0x01010101U; +} + + +#define LOAD_TOP_RIGHT_EDGE\ + const int av_unused t4= topright[0];\ + const int av_unused t5= topright[1];\ + const int av_unused t6= topright[2];\ + const int av_unused t7= topright[3];\ + +#define LOAD_DOWN_LEFT_EDGE\ + const int av_unused l4= src[-1+4*stride];\ + const int av_unused l5= src[-1+5*stride];\ + const int av_unused l6= src[-1+6*stride];\ + const int av_unused l7= src[-1+7*stride];\ + +#define LOAD_LEFT_EDGE\ + const int av_unused l0= src[-1+0*stride];\ + const int av_unused l1= src[-1+1*stride];\ + const int av_unused l2= src[-1+2*stride];\ + const int av_unused l3= src[-1+3*stride];\ + +#define LOAD_TOP_EDGE\ + const int av_unused t0= src[ 0-1*stride];\ + const int av_unused t1= src[ 1-1*stride];\ + const int av_unused t2= src[ 2-1*stride];\ + const int av_unused t3= src[ 3-1*stride];\ + +static void pred4x4_down_right_c(uint8_t *src, uint8_t *topright, int stride){ + const int lt= src[-1-1*stride]; + LOAD_TOP_EDGE + LOAD_LEFT_EDGE + + src[0+3*stride]=(l3 + 2*l2 + l1 + 2)>>2; + src[0+2*stride]= + src[1+3*stride]=(l2 + 2*l1 + l0 + 2)>>2; + src[0+1*stride]= + src[1+2*stride]= + src[2+3*stride]=(l1 + 2*l0 + lt + 2)>>2; + src[0+0*stride]= + src[1+1*stride]= + src[2+2*stride]= + src[3+3*stride]=(l0 + 2*lt + t0 + 2)>>2; + src[1+0*stride]= + src[2+1*stride]= + src[3+2*stride]=(lt + 2*t0 + t1 + 2)>>2; + src[2+0*stride]= + src[3+1*stride]=(t0 + 2*t1 + t2 + 2)>>2; + src[3+0*stride]=(t1 + 2*t2 + t3 + 2)>>2; +} + +static void pred4x4_down_left_c(uint8_t *src, uint8_t *topright, int stride){ + LOAD_TOP_EDGE + LOAD_TOP_RIGHT_EDGE +// LOAD_LEFT_EDGE + + src[0+0*stride]=(t0 + t2 + 2*t1 + 2)>>2; + src[1+0*stride]= + src[0+1*stride]=(t1 + t3 + 2*t2 + 2)>>2; + src[2+0*stride]= + src[1+1*stride]= + src[0+2*stride]=(t2 + t4 + 2*t3 + 2)>>2; + src[3+0*stride]= + src[2+1*stride]= + src[1+2*stride]= + src[0+3*stride]=(t3 + t5 + 2*t4 + 2)>>2; + src[3+1*stride]= + src[2+2*stride]= + src[1+3*stride]=(t4 + t6 + 2*t5 + 2)>>2; + src[3+2*stride]= + src[2+3*stride]=(t5 + t7 + 2*t6 + 2)>>2; + src[3+3*stride]=(t6 + 3*t7 + 2)>>2; +} + +static void pred4x4_down_left_svq3_c(uint8_t *src, uint8_t *topright, int stride){ + LOAD_TOP_EDGE + LOAD_LEFT_EDGE + const av_unused int unu0= t0; + const av_unused int unu1= l0; + + src[0+0*stride]=(l1 + t1)>>1; + src[1+0*stride]= + src[0+1*stride]=(l2 + t2)>>1; + src[2+0*stride]= + src[1+1*stride]= + src[0+2*stride]= + src[3+0*stride]= + src[2+1*stride]= + src[1+2*stride]= + src[0+3*stride]= + src[3+1*stride]= + src[2+2*stride]= + src[1+3*stride]= + src[3+2*stride]= + src[2+3*stride]= + src[3+3*stride]=(l3 + t3)>>1; +} + +static void pred4x4_down_left_rv40_c(uint8_t *src, uint8_t *topright, int stride){ + LOAD_TOP_EDGE + LOAD_TOP_RIGHT_EDGE + LOAD_LEFT_EDGE + LOAD_DOWN_LEFT_EDGE + + src[0+0*stride]=(t0 + t2 + 2*t1 + 2 + l0 + l2 + 2*l1 + 2)>>3; + src[1+0*stride]= + src[0+1*stride]=(t1 + t3 + 2*t2 + 2 + l1 + l3 + 2*l2 + 2)>>3; + src[2+0*stride]= + src[1+1*stride]= + src[0+2*stride]=(t2 + t4 + 2*t3 + 2 + l2 + l4 + 2*l3 + 2)>>3; + src[3+0*stride]= + src[2+1*stride]= + src[1+2*stride]= + src[0+3*stride]=(t3 + t5 + 2*t4 + 2 + l3 + l5 + 2*l4 + 2)>>3; + src[3+1*stride]= + src[2+2*stride]= + src[1+3*stride]=(t4 + t6 + 2*t5 + 2 + l4 + l6 + 2*l5 + 2)>>3; + src[3+2*stride]= + src[2+3*stride]=(t5 + t7 + 2*t6 + 2 + l5 + l7 + 2*l6 + 2)>>3; + src[3+3*stride]=(t6 + t7 + 1 + l6 + l7 + 1)>>2; +} + +static void pred4x4_down_left_rv40_notop_c(uint8_t *src, uint8_t *topright, int stride){ + LOAD_LEFT_EDGE + LOAD_DOWN_LEFT_EDGE + + src[0+0*stride]=(l0 + l2 + 2*l1 + 2)>>2; + src[1+0*stride]= + src[0+1*stride]=(l1 + l3 + 2*l2 + 2)>>2; + src[2+0*stride]= + src[1+1*stride]= + src[0+2*stride]=(l2 + l4 + 2*l3 + 2)>>2; + src[3+0*stride]= + src[2+1*stride]= + src[1+2*stride]= + src[0+3*stride]=(l3 + l5 + 2*l4 + 2)>>2; + src[3+1*stride]= + src[2+2*stride]= + src[1+3*stride]=(l4 + l6 + 2*l5 + 2)>>2; + src[3+2*stride]= + src[2+3*stride]=(l5 + l7 + 2*l6 + 2)>>2; + src[3+3*stride]=(l6 + l7 + 1)>>1; +} + +static void pred4x4_down_left_rv40_nodown_c(uint8_t *src, uint8_t *topright, int stride){ + LOAD_TOP_EDGE + LOAD_TOP_RIGHT_EDGE + LOAD_LEFT_EDGE + + src[0+0*stride]=(t0 + t2 + 2*t1 + 2 + l0 + l2 + 2*l1 + 2)>>3; + src[1+0*stride]= + src[0+1*stride]=(t1 + t3 + 2*t2 + 2 + l1 + l3 + 2*l2 + 2)>>3; + src[2+0*stride]= + src[1+1*stride]= + src[0+2*stride]=(t2 + t4 + 2*t3 + 2 + l2 + 3*l3 + 2)>>3; + src[3+0*stride]= + src[2+1*stride]= + src[1+2*stride]= + src[0+3*stride]=(t3 + t5 + 2*t4 + 2 + l3*4 + 2)>>3; + src[3+1*stride]= + src[2+2*stride]= + src[1+3*stride]=(t4 + t6 + 2*t5 + 2 + l3*4 + 2)>>3; + src[3+2*stride]= + src[2+3*stride]=(t5 + t7 + 2*t6 + 2 + l3*4 + 2)>>3; + src[3+3*stride]=(t6 + t7 + 1 + 2*l3 + 1)>>2; +} + +static void pred4x4_vertical_right_c(uint8_t *src, uint8_t *topright, int stride){ + const int lt= src[-1-1*stride]; + LOAD_TOP_EDGE + LOAD_LEFT_EDGE + + src[0+0*stride]= + src[1+2*stride]=(lt + t0 + 1)>>1; + src[1+0*stride]= + src[2+2*stride]=(t0 + t1 + 1)>>1; + src[2+0*stride]= + src[3+2*stride]=(t1 + t2 + 1)>>1; + src[3+0*stride]=(t2 + t3 + 1)>>1; + src[0+1*stride]= + src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2; + src[1+1*stride]= + src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2; + src[2+1*stride]= + src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2; + src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2; + src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2; + src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2; +} + +static void pred4x4_vertical_left_c(uint8_t *src, uint8_t *topright, int stride){ + LOAD_TOP_EDGE + LOAD_TOP_RIGHT_EDGE + + src[0+0*stride]=(t0 + t1 + 1)>>1; + src[1+0*stride]= + src[0+2*stride]=(t1 + t2 + 1)>>1; + src[2+0*stride]= + src[1+2*stride]=(t2 + t3 + 1)>>1; + src[3+0*stride]= + src[2+2*stride]=(t3 + t4+ 1)>>1; + src[3+2*stride]=(t4 + t5+ 1)>>1; + src[0+1*stride]=(t0 + 2*t1 + t2 + 2)>>2; + src[1+1*stride]= + src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2; + src[2+1*stride]= + src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2; + src[3+1*stride]= + src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2; + src[3+3*stride]=(t4 + 2*t5 + t6 + 2)>>2; +} + +static void pred4x4_vertical_left_rv40(uint8_t *src, uint8_t *topright, int stride, + const int l0, const int l1, const int l2, const int l3, const int l4){ + LOAD_TOP_EDGE + LOAD_TOP_RIGHT_EDGE + + src[0+0*stride]=(2*t0 + 2*t1 + l1 + 2*l2 + l3 + 4)>>3; + src[1+0*stride]= + src[0+2*stride]=(t1 + t2 + 1)>>1; + src[2+0*stride]= + src[1+2*stride]=(t2 + t3 + 1)>>1; + src[3+0*stride]= + src[2+2*stride]=(t3 + t4+ 1)>>1; + src[3+2*stride]=(t4 + t5+ 1)>>1; + src[0+1*stride]=(t0 + 2*t1 + t2 + l2 + 2*l3 + l4 + 4)>>3; + src[1+1*stride]= + src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2; + src[2+1*stride]= + src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2; + src[3+1*stride]= + src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2; + src[3+3*stride]=(t4 + 2*t5 + t6 + 2)>>2; +} + +static void pred4x4_vertical_left_rv40_c(uint8_t *src, uint8_t *topright, int stride){ + LOAD_LEFT_EDGE + LOAD_DOWN_LEFT_EDGE + + pred4x4_vertical_left_rv40(src, topright, stride, l0, l1, l2, l3, l4); +} + +static void pred4x4_vertical_left_rv40_nodown_c(uint8_t *src, uint8_t *topright, int stride){ + LOAD_LEFT_EDGE + + pred4x4_vertical_left_rv40(src, topright, stride, l0, l1, l2, l3, l3); +} + +static void pred4x4_horizontal_up_c(uint8_t *src, uint8_t *topright, int stride){ + LOAD_LEFT_EDGE + + src[0+0*stride]=(l0 + l1 + 1)>>1; + src[1+0*stride]=(l0 + 2*l1 + l2 + 2)>>2; + src[2+0*stride]= + src[0+1*stride]=(l1 + l2 + 1)>>1; + src[3+0*stride]= + src[1+1*stride]=(l1 + 2*l2 + l3 + 2)>>2; + src[2+1*stride]= + src[0+2*stride]=(l2 + l3 + 1)>>1; + src[3+1*stride]= + src[1+2*stride]=(l2 + 2*l3 + l3 + 2)>>2; + src[3+2*stride]= + src[1+3*stride]= + src[0+3*stride]= + src[2+2*stride]= + src[2+3*stride]= + src[3+3*stride]=l3; +} + +static void pred4x4_horizontal_up_rv40_c(uint8_t *src, uint8_t *topright, int stride){ + LOAD_LEFT_EDGE + LOAD_DOWN_LEFT_EDGE + LOAD_TOP_EDGE + LOAD_TOP_RIGHT_EDGE + + src[0+0*stride]=(t1 + 2*t2 + t3 + 2*l0 + 2*l1 + 4)>>3; + src[1+0*stride]=(t2 + 2*t3 + t4 + l0 + 2*l1 + l2 + 4)>>3; + src[2+0*stride]= + src[0+1*stride]=(t3 + 2*t4 + t5 + 2*l1 + 2*l2 + 4)>>3; + src[3+0*stride]= + src[1+1*stride]=(t4 + 2*t5 + t6 + l1 + 2*l2 + l3 + 4)>>3; + src[2+1*stride]= + src[0+2*stride]=(t5 + 2*t6 + t7 + 2*l2 + 2*l3 + 4)>>3; + src[3+1*stride]= + src[1+2*stride]=(t6 + 3*t7 + l2 + 3*l3 + 4)>>3; + src[3+2*stride]= + src[1+3*stride]=(l3 + 2*l4 + l5 + 2)>>2; + src[0+3*stride]= + src[2+2*stride]=(t6 + t7 + l3 + l4 + 2)>>2; + src[2+3*stride]=(l4 + l5 + 1)>>1; + src[3+3*stride]=(l4 + 2*l5 + l6 + 2)>>2; +} + +static void pred4x4_horizontal_up_rv40_nodown_c(uint8_t *src, uint8_t *topright, int stride){ + LOAD_LEFT_EDGE + LOAD_TOP_EDGE + LOAD_TOP_RIGHT_EDGE + + src[0+0*stride]=(t1 + 2*t2 + t3 + 2*l0 + 2*l1 + 4)>>3; + src[1+0*stride]=(t2 + 2*t3 + t4 + l0 + 2*l1 + l2 + 4)>>3; + src[2+0*stride]= + src[0+1*stride]=(t3 + 2*t4 + t5 + 2*l1 + 2*l2 + 4)>>3; + src[3+0*stride]= + src[1+1*stride]=(t4 + 2*t5 + t6 + l1 + 2*l2 + l3 + 4)>>3; + src[2+1*stride]= + src[0+2*stride]=(t5 + 2*t6 + t7 + 2*l2 + 2*l3 + 4)>>3; + src[3+1*stride]= + src[1+2*stride]=(t6 + 3*t7 + l2 + 3*l3 + 4)>>3; + src[3+2*stride]= + src[1+3*stride]=l3; + src[0+3*stride]= + src[2+2*stride]=(t6 + t7 + 2*l3 + 2)>>2; + src[2+3*stride]= + src[3+3*stride]=l3; +} + +static void pred4x4_horizontal_down_c(uint8_t *src, uint8_t *topright, int stride){ + const int lt= src[-1-1*stride]; + LOAD_TOP_EDGE + LOAD_LEFT_EDGE + + src[0+0*stride]= + src[2+1*stride]=(lt + l0 + 1)>>1; + src[1+0*stride]= + src[3+1*stride]=(l0 + 2*lt + t0 + 2)>>2; + src[2+0*stride]=(lt + 2*t0 + t1 + 2)>>2; + src[3+0*stride]=(t0 + 2*t1 + t2 + 2)>>2; + src[0+1*stride]= + src[2+2*stride]=(l0 + l1 + 1)>>1; + src[1+1*stride]= + src[3+2*stride]=(lt + 2*l0 + l1 + 2)>>2; + src[0+2*stride]= + src[2+3*stride]=(l1 + l2+ 1)>>1; + src[1+2*stride]= + src[3+3*stride]=(l0 + 2*l1 + l2 + 2)>>2; + src[0+3*stride]=(l2 + l3 + 1)>>1; + src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2; +} + +static void pred16x16_vertical_c(uint8_t *src, int stride){ + int i; + const uint32_t a= ((uint32_t*)(src-stride))[0]; + const uint32_t b= ((uint32_t*)(src-stride))[1]; + const uint32_t c= ((uint32_t*)(src-stride))[2]; + const uint32_t d= ((uint32_t*)(src-stride))[3]; + + for(i=0; i<16; i++){ + ((uint32_t*)(src+i*stride))[0]= a; + ((uint32_t*)(src+i*stride))[1]= b; + ((uint32_t*)(src+i*stride))[2]= c; + ((uint32_t*)(src+i*stride))[3]= d; + } +} + +static void pred16x16_horizontal_c(uint8_t *src, int stride){ + int i; + + for(i=0; i<16; i++){ + ((uint32_t*)(src+i*stride))[0]= + ((uint32_t*)(src+i*stride))[1]= + ((uint32_t*)(src+i*stride))[2]= + ((uint32_t*)(src+i*stride))[3]= src[-1+i*stride]*0x01010101; + } +} + +static void pred16x16_dc_c(uint8_t *src, int stride){ + int i, dc=0; + + for(i=0;i<16; i++){ + dc+= src[-1+i*stride]; + } + + for(i=0;i<16; i++){ + dc+= src[i-stride]; + } + + dc= 0x01010101*((dc + 16)>>5); + + for(i=0; i<16; i++){ + ((uint32_t*)(src+i*stride))[0]= + ((uint32_t*)(src+i*stride))[1]= + ((uint32_t*)(src+i*stride))[2]= + ((uint32_t*)(src+i*stride))[3]= dc; + } +} + +static void pred16x16_left_dc_c(uint8_t *src, int stride){ + int i, dc=0; + + for(i=0;i<16; i++){ + dc+= src[-1+i*stride]; + } + + dc= 0x01010101*((dc + 8)>>4); + + for(i=0; i<16; i++){ + ((uint32_t*)(src+i*stride))[0]= + ((uint32_t*)(src+i*stride))[1]= + ((uint32_t*)(src+i*stride))[2]= + ((uint32_t*)(src+i*stride))[3]= dc; + } +} + +static void pred16x16_top_dc_c(uint8_t *src, int stride){ + int i, dc=0; + + for(i=0;i<16; i++){ + dc+= src[i-stride]; + } + dc= 0x01010101*((dc + 8)>>4); + + for(i=0; i<16; i++){ + ((uint32_t*)(src+i*stride))[0]= + ((uint32_t*)(src+i*stride))[1]= + ((uint32_t*)(src+i*stride))[2]= + ((uint32_t*)(src+i*stride))[3]= dc; + } +} + +static void pred16x16_128_dc_c(uint8_t *src, int stride){ + int i; + + for(i=0; i<16; i++){ + ((uint32_t*)(src+i*stride))[0]= + ((uint32_t*)(src+i*stride))[1]= + ((uint32_t*)(src+i*stride))[2]= + ((uint32_t*)(src+i*stride))[3]= 0x01010101U*128U; + } +} + +static inline void pred16x16_plane_compat_c(uint8_t *src, int stride, const int svq3, const int rv40){ + int i, j, k; + int a; + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + const uint8_t * const src0 = src+7-stride; + const uint8_t *src1 = src+8*stride-1; + const uint8_t *src2 = src1-2*stride; // == src+6*stride-1; + int H = src0[1] - src0[-1]; + int V = src1[0] - src2[ 0]; + for(k=2; k<=8; ++k) { + src1 += stride; src2 -= stride; + H += k*(src0[k] - src0[-k]); + V += k*(src1[0] - src2[ 0]); + } + if(svq3){ + H = ( 5*(H/4) ) / 16; + V = ( 5*(V/4) ) / 16; + + /* required for 100% accuracy */ + i = H; H = V; V = i; + }else if(rv40){ + H = ( H + (H>>2) ) >> 4; + V = ( V + (V>>2) ) >> 4; + }else{ + H = ( 5*H+32 ) >> 6; + V = ( 5*V+32 ) >> 6; + } + + a = 16*(src1[0] + src2[16] + 1) - 7*(V+H); + for(j=16; j>0; --j) { + int b = a; + a += V; + for(i=-16; i<0; i+=4) { + src[16+i] = cm[ (b ) >> 5 ]; + src[17+i] = cm[ (b+ H) >> 5 ]; + src[18+i] = cm[ (b+2*H) >> 5 ]; + src[19+i] = cm[ (b+3*H) >> 5 ]; + b += 4*H; + } + src += stride; + } +} + +static void pred16x16_plane_c(uint8_t *src, int stride){ + pred16x16_plane_compat_c(src, stride, 0, 0); +} + +static void pred16x16_plane_svq3_c(uint8_t *src, int stride){ + pred16x16_plane_compat_c(src, stride, 1, 0); +} + +static void pred16x16_plane_rv40_c(uint8_t *src, int stride){ + pred16x16_plane_compat_c(src, stride, 0, 1); +} + +static void pred8x8_vertical_c(uint8_t *src, int stride){ + int i; + const uint32_t a= ((uint32_t*)(src-stride))[0]; + const uint32_t b= ((uint32_t*)(src-stride))[1]; + + for(i=0; i<8; i++){ + ((uint32_t*)(src+i*stride))[0]= a; + ((uint32_t*)(src+i*stride))[1]= b; + } +} + +static void pred8x8_horizontal_c(uint8_t *src, int stride){ + int i; + + for(i=0; i<8; i++){ + ((uint32_t*)(src+i*stride))[0]= + ((uint32_t*)(src+i*stride))[1]= src[-1+i*stride]*0x01010101; + } +} + +static void pred8x8_128_dc_c(uint8_t *src, int stride){ + int i; + + for(i=0; i<8; i++){ + ((uint32_t*)(src+i*stride))[0]= + ((uint32_t*)(src+i*stride))[1]= 0x01010101U*128U; + } +} + +static void pred8x8_left_dc_c(uint8_t *src, int stride){ + int i; + int dc0, dc2; + + dc0=dc2=0; + for(i=0;i<4; i++){ + dc0+= src[-1+i*stride]; + dc2+= src[-1+(i+4)*stride]; + } + dc0= 0x01010101*((dc0 + 2)>>2); + dc2= 0x01010101*((dc2 + 2)>>2); + + for(i=0; i<4; i++){ + ((uint32_t*)(src+i*stride))[0]= + ((uint32_t*)(src+i*stride))[1]= dc0; + } + for(i=4; i<8; i++){ + ((uint32_t*)(src+i*stride))[0]= + ((uint32_t*)(src+i*stride))[1]= dc2; + } +} + +static void pred8x8_left_dc_rv40_c(uint8_t *src, int stride){ + int i; + int dc0; + + dc0=0; + for(i=0;i<8; i++) + dc0+= src[-1+i*stride]; + dc0= 0x01010101*((dc0 + 4)>>3); + + for(i=0; i<8; i++){ + ((uint32_t*)(src+i*stride))[0]= + ((uint32_t*)(src+i*stride))[1]= dc0; + } +} + +static void pred8x8_top_dc_c(uint8_t *src, int stride){ + int i; + int dc0, dc1; + + dc0=dc1=0; + for(i=0;i<4; i++){ + dc0+= src[i-stride]; + dc1+= src[4+i-stride]; + } + dc0= 0x01010101*((dc0 + 2)>>2); + dc1= 0x01010101*((dc1 + 2)>>2); + + for(i=0; i<4; i++){ + ((uint32_t*)(src+i*stride))[0]= dc0; + ((uint32_t*)(src+i*stride))[1]= dc1; + } + for(i=4; i<8; i++){ + ((uint32_t*)(src+i*stride))[0]= dc0; + ((uint32_t*)(src+i*stride))[1]= dc1; + } +} + +static void pred8x8_top_dc_rv40_c(uint8_t *src, int stride){ + int i; + int dc0; + + dc0=0; + for(i=0;i<8; i++) + dc0+= src[i-stride]; + dc0= 0x01010101*((dc0 + 4)>>3); + + for(i=0; i<8; i++){ + ((uint32_t*)(src+i*stride))[0]= + ((uint32_t*)(src+i*stride))[1]= dc0; + } +} + + +static void pred8x8_dc_c(uint8_t *src, int stride){ + int i; + int dc0, dc1, dc2, dc3; + + dc0=dc1=dc2=0; + for(i=0;i<4; i++){ + dc0+= src[-1+i*stride] + src[i-stride]; + dc1+= src[4+i-stride]; + dc2+= src[-1+(i+4)*stride]; + } + dc3= 0x01010101*((dc1 + dc2 + 4)>>3); + dc0= 0x01010101*((dc0 + 4)>>3); + dc1= 0x01010101*((dc1 + 2)>>2); + dc2= 0x01010101*((dc2 + 2)>>2); + + for(i=0; i<4; i++){ + ((uint32_t*)(src+i*stride))[0]= dc0; + ((uint32_t*)(src+i*stride))[1]= dc1; + } + for(i=4; i<8; i++){ + ((uint32_t*)(src+i*stride))[0]= dc2; + ((uint32_t*)(src+i*stride))[1]= dc3; + } +} + +static void pred8x8_dc_rv40_c(uint8_t *src, int stride){ + int i; + int dc0=0; + + for(i=0;i<4; i++){ + dc0+= src[-1+i*stride] + src[i-stride]; + dc0+= src[4+i-stride]; + dc0+= src[-1+(i+4)*stride]; + } + dc0= 0x01010101*((dc0 + 8)>>4); + + for(i=0; i<4; i++){ + ((uint32_t*)(src+i*stride))[0]= dc0; + ((uint32_t*)(src+i*stride))[1]= dc0; + } + for(i=4; i<8; i++){ + ((uint32_t*)(src+i*stride))[0]= dc0; + ((uint32_t*)(src+i*stride))[1]= dc0; + } +} + +static void pred8x8_plane_c(uint8_t *src, int stride){ + int j, k; + int a; + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + const uint8_t * const src0 = src+3-stride; + const uint8_t *src1 = src+4*stride-1; + const uint8_t *src2 = src1-2*stride; // == src+2*stride-1; + int H = src0[1] - src0[-1]; + int V = src1[0] - src2[ 0]; + for(k=2; k<=4; ++k) { + src1 += stride; src2 -= stride; + H += k*(src0[k] - src0[-k]); + V += k*(src1[0] - src2[ 0]); + } + H = ( 17*H+16 ) >> 5; + V = ( 17*V+16 ) >> 5; + + a = 16*(src1[0] + src2[8]+1) - 3*(V+H); + for(j=8; j>0; --j) { + int b = a; + a += V; + src[0] = cm[ (b ) >> 5 ]; + src[1] = cm[ (b+ H) >> 5 ]; + src[2] = cm[ (b+2*H) >> 5 ]; + src[3] = cm[ (b+3*H) >> 5 ]; + src[4] = cm[ (b+4*H) >> 5 ]; + src[5] = cm[ (b+5*H) >> 5 ]; + src[6] = cm[ (b+6*H) >> 5 ]; + src[7] = cm[ (b+7*H) >> 5 ]; + src += stride; + } +} + +#define SRC(x,y) src[(x)+(y)*stride] +#define PL(y) \ + const int l##y = (SRC(-1,y-1) + 2*SRC(-1,y) + SRC(-1,y+1) + 2) >> 2; +#define PREDICT_8x8_LOAD_LEFT \ + const int l0 = ((has_topleft ? SRC(-1,-1) : SRC(-1,0)) \ + + 2*SRC(-1,0) + SRC(-1,1) + 2) >> 2; \ + PL(1) PL(2) PL(3) PL(4) PL(5) PL(6) \ + const int l7 av_unused = (SRC(-1,6) + 3*SRC(-1,7) + 2) >> 2 + +#define PT(x) \ + const int t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2; +#define PREDICT_8x8_LOAD_TOP \ + const int t0 = ((has_topleft ? SRC(-1,-1) : SRC(0,-1)) \ + + 2*SRC(0,-1) + SRC(1,-1) + 2) >> 2; \ + PT(1) PT(2) PT(3) PT(4) PT(5) PT(6) \ + const int t7 av_unused = ((has_topright ? SRC(8,-1) : SRC(7,-1)) \ + + 2*SRC(7,-1) + SRC(6,-1) + 2) >> 2 + +#define PTR(x) \ + t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2; +#define PREDICT_8x8_LOAD_TOPRIGHT \ + int t8, t9, t10, t11, t12, t13, t14, t15; \ + if(has_topright) { \ + PTR(8) PTR(9) PTR(10) PTR(11) PTR(12) PTR(13) PTR(14) \ + t15 = (SRC(14,-1) + 3*SRC(15,-1) + 2) >> 2; \ + } else t8=t9=t10=t11=t12=t13=t14=t15= SRC(7,-1); + +#define PREDICT_8x8_LOAD_TOPLEFT \ + const int lt = (SRC(-1,0) + 2*SRC(-1,-1) + SRC(0,-1) + 2) >> 2 + +#define PREDICT_8x8_DC(v) \ + int y; \ + for( y = 0; y < 8; y++ ) { \ + ((uint32_t*)src)[0] = \ + ((uint32_t*)src)[1] = v; \ + src += stride; \ + } + +static void pred8x8l_128_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride) +{ + PREDICT_8x8_DC(0x80808080); +} +static void pred8x8l_left_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride) +{ + PREDICT_8x8_LOAD_LEFT; + const uint32_t dc = ((l0+l1+l2+l3+l4+l5+l6+l7+4) >> 3) * 0x01010101; + PREDICT_8x8_DC(dc); +} +static void pred8x8l_top_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride) +{ + PREDICT_8x8_LOAD_TOP; + const uint32_t dc = ((t0+t1+t2+t3+t4+t5+t6+t7+4) >> 3) * 0x01010101; + PREDICT_8x8_DC(dc); +} +static void pred8x8l_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride) +{ + PREDICT_8x8_LOAD_LEFT; + PREDICT_8x8_LOAD_TOP; + const uint32_t dc = ((l0+l1+l2+l3+l4+l5+l6+l7 + +t0+t1+t2+t3+t4+t5+t6+t7+8) >> 4) * 0x01010101; + PREDICT_8x8_DC(dc); +} +static void pred8x8l_horizontal_c(uint8_t *src, int has_topleft, int has_topright, int stride) +{ + PREDICT_8x8_LOAD_LEFT; +#define ROW(y) ((uint32_t*)(src+y*stride))[0] =\ + ((uint32_t*)(src+y*stride))[1] = 0x01010101 * l##y + ROW(0); ROW(1); ROW(2); ROW(3); ROW(4); ROW(5); ROW(6); ROW(7); +#undef ROW +} +static void pred8x8l_vertical_c(uint8_t *src, int has_topleft, int has_topright, int stride) +{ + int y; + PREDICT_8x8_LOAD_TOP; + src[0] = t0; + src[1] = t1; + src[2] = t2; + src[3] = t3; + src[4] = t4; + src[5] = t5; + src[6] = t6; + src[7] = t7; + for( y = 1; y < 8; y++ ) + *(uint64_t*)(src+y*stride) = *(uint64_t*)src; +} +static void pred8x8l_down_left_c(uint8_t *src, int has_topleft, int has_topright, int stride) +{ + PREDICT_8x8_LOAD_TOP; + PREDICT_8x8_LOAD_TOPRIGHT; + SRC(0,0)= (t0 + 2*t1 + t2 + 2) >> 2; + SRC(0,1)=SRC(1,0)= (t1 + 2*t2 + t3 + 2) >> 2; + SRC(0,2)=SRC(1,1)=SRC(2,0)= (t2 + 2*t3 + t4 + 2) >> 2; + SRC(0,3)=SRC(1,2)=SRC(2,1)=SRC(3,0)= (t3 + 2*t4 + t5 + 2) >> 2; + SRC(0,4)=SRC(1,3)=SRC(2,2)=SRC(3,1)=SRC(4,0)= (t4 + 2*t5 + t6 + 2) >> 2; + SRC(0,5)=SRC(1,4)=SRC(2,3)=SRC(3,2)=SRC(4,1)=SRC(5,0)= (t5 + 2*t6 + t7 + 2) >> 2; + SRC(0,6)=SRC(1,5)=SRC(2,4)=SRC(3,3)=SRC(4,2)=SRC(5,1)=SRC(6,0)= (t6 + 2*t7 + t8 + 2) >> 2; + SRC(0,7)=SRC(1,6)=SRC(2,5)=SRC(3,4)=SRC(4,3)=SRC(5,2)=SRC(6,1)=SRC(7,0)= (t7 + 2*t8 + t9 + 2) >> 2; + SRC(1,7)=SRC(2,6)=SRC(3,5)=SRC(4,4)=SRC(5,3)=SRC(6,2)=SRC(7,1)= (t8 + 2*t9 + t10 + 2) >> 2; + SRC(2,7)=SRC(3,6)=SRC(4,5)=SRC(5,4)=SRC(6,3)=SRC(7,2)= (t9 + 2*t10 + t11 + 2) >> 2; + SRC(3,7)=SRC(4,6)=SRC(5,5)=SRC(6,4)=SRC(7,3)= (t10 + 2*t11 + t12 + 2) >> 2; + SRC(4,7)=SRC(5,6)=SRC(6,5)=SRC(7,4)= (t11 + 2*t12 + t13 + 2) >> 2; + SRC(5,7)=SRC(6,6)=SRC(7,5)= (t12 + 2*t13 + t14 + 2) >> 2; + SRC(6,7)=SRC(7,6)= (t13 + 2*t14 + t15 + 2) >> 2; + SRC(7,7)= (t14 + 3*t15 + 2) >> 2; +} +static void pred8x8l_down_right_c(uint8_t *src, int has_topleft, int has_topright, int stride) +{ + PREDICT_8x8_LOAD_TOP; + PREDICT_8x8_LOAD_LEFT; + PREDICT_8x8_LOAD_TOPLEFT; + SRC(0,7)= (l7 + 2*l6 + l5 + 2) >> 2; + SRC(0,6)=SRC(1,7)= (l6 + 2*l5 + l4 + 2) >> 2; + SRC(0,5)=SRC(1,6)=SRC(2,7)= (l5 + 2*l4 + l3 + 2) >> 2; + SRC(0,4)=SRC(1,5)=SRC(2,6)=SRC(3,7)= (l4 + 2*l3 + l2 + 2) >> 2; + SRC(0,3)=SRC(1,4)=SRC(2,5)=SRC(3,6)=SRC(4,7)= (l3 + 2*l2 + l1 + 2) >> 2; + SRC(0,2)=SRC(1,3)=SRC(2,4)=SRC(3,5)=SRC(4,6)=SRC(5,7)= (l2 + 2*l1 + l0 + 2) >> 2; + SRC(0,1)=SRC(1,2)=SRC(2,3)=SRC(3,4)=SRC(4,5)=SRC(5,6)=SRC(6,7)= (l1 + 2*l0 + lt + 2) >> 2; + SRC(0,0)=SRC(1,1)=SRC(2,2)=SRC(3,3)=SRC(4,4)=SRC(5,5)=SRC(6,6)=SRC(7,7)= (l0 + 2*lt + t0 + 2) >> 2; + SRC(1,0)=SRC(2,1)=SRC(3,2)=SRC(4,3)=SRC(5,4)=SRC(6,5)=SRC(7,6)= (lt + 2*t0 + t1 + 2) >> 2; + SRC(2,0)=SRC(3,1)=SRC(4,2)=SRC(5,3)=SRC(6,4)=SRC(7,5)= (t0 + 2*t1 + t2 + 2) >> 2; + SRC(3,0)=SRC(4,1)=SRC(5,2)=SRC(6,3)=SRC(7,4)= (t1 + 2*t2 + t3 + 2) >> 2; + SRC(4,0)=SRC(5,1)=SRC(6,2)=SRC(7,3)= (t2 + 2*t3 + t4 + 2) >> 2; + SRC(5,0)=SRC(6,1)=SRC(7,2)= (t3 + 2*t4 + t5 + 2) >> 2; + SRC(6,0)=SRC(7,1)= (t4 + 2*t5 + t6 + 2) >> 2; + SRC(7,0)= (t5 + 2*t6 + t7 + 2) >> 2; + +} +static void pred8x8l_vertical_right_c(uint8_t *src, int has_topleft, int has_topright, int stride) +{ + PREDICT_8x8_LOAD_TOP; + PREDICT_8x8_LOAD_LEFT; + PREDICT_8x8_LOAD_TOPLEFT; + SRC(0,6)= (l5 + 2*l4 + l3 + 2) >> 2; + SRC(0,7)= (l6 + 2*l5 + l4 + 2) >> 2; + SRC(0,4)=SRC(1,6)= (l3 + 2*l2 + l1 + 2) >> 2; + SRC(0,5)=SRC(1,7)= (l4 + 2*l3 + l2 + 2) >> 2; + SRC(0,2)=SRC(1,4)=SRC(2,6)= (l1 + 2*l0 + lt + 2) >> 2; + SRC(0,3)=SRC(1,5)=SRC(2,7)= (l2 + 2*l1 + l0 + 2) >> 2; + SRC(0,1)=SRC(1,3)=SRC(2,5)=SRC(3,7)= (l0 + 2*lt + t0 + 2) >> 2; + SRC(0,0)=SRC(1,2)=SRC(2,4)=SRC(3,6)= (lt + t0 + 1) >> 1; + SRC(1,1)=SRC(2,3)=SRC(3,5)=SRC(4,7)= (lt + 2*t0 + t1 + 2) >> 2; + SRC(1,0)=SRC(2,2)=SRC(3,4)=SRC(4,6)= (t0 + t1 + 1) >> 1; + SRC(2,1)=SRC(3,3)=SRC(4,5)=SRC(5,7)= (t0 + 2*t1 + t2 + 2) >> 2; + SRC(2,0)=SRC(3,2)=SRC(4,4)=SRC(5,6)= (t1 + t2 + 1) >> 1; + SRC(3,1)=SRC(4,3)=SRC(5,5)=SRC(6,7)= (t1 + 2*t2 + t3 + 2) >> 2; + SRC(3,0)=SRC(4,2)=SRC(5,4)=SRC(6,6)= (t2 + t3 + 1) >> 1; + SRC(4,1)=SRC(5,3)=SRC(6,5)=SRC(7,7)= (t2 + 2*t3 + t4 + 2) >> 2; + SRC(4,0)=SRC(5,2)=SRC(6,4)=SRC(7,6)= (t3 + t4 + 1) >> 1; + SRC(5,1)=SRC(6,3)=SRC(7,5)= (t3 + 2*t4 + t5 + 2) >> 2; + SRC(5,0)=SRC(6,2)=SRC(7,4)= (t4 + t5 + 1) >> 1; + SRC(6,1)=SRC(7,3)= (t4 + 2*t5 + t6 + 2) >> 2; + SRC(6,0)=SRC(7,2)= (t5 + t6 + 1) >> 1; + SRC(7,1)= (t5 + 2*t6 + t7 + 2) >> 2; + SRC(7,0)= (t6 + t7 + 1) >> 1; +} +static void pred8x8l_horizontal_down_c(uint8_t *src, int has_topleft, int has_topright, int stride) +{ + PREDICT_8x8_LOAD_TOP; + PREDICT_8x8_LOAD_LEFT; + PREDICT_8x8_LOAD_TOPLEFT; + SRC(0,7)= (l6 + l7 + 1) >> 1; + SRC(1,7)= (l5 + 2*l6 + l7 + 2) >> 2; + SRC(0,6)=SRC(2,7)= (l5 + l6 + 1) >> 1; + SRC(1,6)=SRC(3,7)= (l4 + 2*l5 + l6 + 2) >> 2; + SRC(0,5)=SRC(2,6)=SRC(4,7)= (l4 + l5 + 1) >> 1; + SRC(1,5)=SRC(3,6)=SRC(5,7)= (l3 + 2*l4 + l5 + 2) >> 2; + SRC(0,4)=SRC(2,5)=SRC(4,6)=SRC(6,7)= (l3 + l4 + 1) >> 1; + SRC(1,4)=SRC(3,5)=SRC(5,6)=SRC(7,7)= (l2 + 2*l3 + l4 + 2) >> 2; + SRC(0,3)=SRC(2,4)=SRC(4,5)=SRC(6,6)= (l2 + l3 + 1) >> 1; + SRC(1,3)=SRC(3,4)=SRC(5,5)=SRC(7,6)= (l1 + 2*l2 + l3 + 2) >> 2; + SRC(0,2)=SRC(2,3)=SRC(4,4)=SRC(6,5)= (l1 + l2 + 1) >> 1; + SRC(1,2)=SRC(3,3)=SRC(5,4)=SRC(7,5)= (l0 + 2*l1 + l2 + 2) >> 2; + SRC(0,1)=SRC(2,2)=SRC(4,3)=SRC(6,4)= (l0 + l1 + 1) >> 1; + SRC(1,1)=SRC(3,2)=SRC(5,3)=SRC(7,4)= (lt + 2*l0 + l1 + 2) >> 2; + SRC(0,0)=SRC(2,1)=SRC(4,2)=SRC(6,3)= (lt + l0 + 1) >> 1; + SRC(1,0)=SRC(3,1)=SRC(5,2)=SRC(7,3)= (l0 + 2*lt + t0 + 2) >> 2; + SRC(2,0)=SRC(4,1)=SRC(6,2)= (t1 + 2*t0 + lt + 2) >> 2; + SRC(3,0)=SRC(5,1)=SRC(7,2)= (t2 + 2*t1 + t0 + 2) >> 2; + SRC(4,0)=SRC(6,1)= (t3 + 2*t2 + t1 + 2) >> 2; + SRC(5,0)=SRC(7,1)= (t4 + 2*t3 + t2 + 2) >> 2; + SRC(6,0)= (t5 + 2*t4 + t3 + 2) >> 2; + SRC(7,0)= (t6 + 2*t5 + t4 + 2) >> 2; +} +static void pred8x8l_vertical_left_c(uint8_t *src, int has_topleft, int has_topright, int stride) +{ + PREDICT_8x8_LOAD_TOP; + PREDICT_8x8_LOAD_TOPRIGHT; + SRC(0,0)= (t0 + t1 + 1) >> 1; + SRC(0,1)= (t0 + 2*t1 + t2 + 2) >> 2; + SRC(0,2)=SRC(1,0)= (t1 + t2 + 1) >> 1; + SRC(0,3)=SRC(1,1)= (t1 + 2*t2 + t3 + 2) >> 2; + SRC(0,4)=SRC(1,2)=SRC(2,0)= (t2 + t3 + 1) >> 1; + SRC(0,5)=SRC(1,3)=SRC(2,1)= (t2 + 2*t3 + t4 + 2) >> 2; + SRC(0,6)=SRC(1,4)=SRC(2,2)=SRC(3,0)= (t3 + t4 + 1) >> 1; + SRC(0,7)=SRC(1,5)=SRC(2,3)=SRC(3,1)= (t3 + 2*t4 + t5 + 2) >> 2; + SRC(1,6)=SRC(2,4)=SRC(3,2)=SRC(4,0)= (t4 + t5 + 1) >> 1; + SRC(1,7)=SRC(2,5)=SRC(3,3)=SRC(4,1)= (t4 + 2*t5 + t6 + 2) >> 2; + SRC(2,6)=SRC(3,4)=SRC(4,2)=SRC(5,0)= (t5 + t6 + 1) >> 1; + SRC(2,7)=SRC(3,5)=SRC(4,3)=SRC(5,1)= (t5 + 2*t6 + t7 + 2) >> 2; + SRC(3,6)=SRC(4,4)=SRC(5,2)=SRC(6,0)= (t6 + t7 + 1) >> 1; + SRC(3,7)=SRC(4,5)=SRC(5,3)=SRC(6,1)= (t6 + 2*t7 + t8 + 2) >> 2; + SRC(4,6)=SRC(5,4)=SRC(6,2)=SRC(7,0)= (t7 + t8 + 1) >> 1; + SRC(4,7)=SRC(5,5)=SRC(6,3)=SRC(7,1)= (t7 + 2*t8 + t9 + 2) >> 2; + SRC(5,6)=SRC(6,4)=SRC(7,2)= (t8 + t9 + 1) >> 1; + SRC(5,7)=SRC(6,5)=SRC(7,3)= (t8 + 2*t9 + t10 + 2) >> 2; + SRC(6,6)=SRC(7,4)= (t9 + t10 + 1) >> 1; + SRC(6,7)=SRC(7,5)= (t9 + 2*t10 + t11 + 2) >> 2; + SRC(7,6)= (t10 + t11 + 1) >> 1; + SRC(7,7)= (t10 + 2*t11 + t12 + 2) >> 2; +} +static void pred8x8l_horizontal_up_c(uint8_t *src, int has_topleft, int has_topright, int stride) +{ + PREDICT_8x8_LOAD_LEFT; + SRC(0,0)= (l0 + l1 + 1) >> 1; + SRC(1,0)= (l0 + 2*l1 + l2 + 2) >> 2; + SRC(0,1)=SRC(2,0)= (l1 + l2 + 1) >> 1; + SRC(1,1)=SRC(3,0)= (l1 + 2*l2 + l3 + 2) >> 2; + SRC(0,2)=SRC(2,1)=SRC(4,0)= (l2 + l3 + 1) >> 1; + SRC(1,2)=SRC(3,1)=SRC(5,0)= (l2 + 2*l3 + l4 + 2) >> 2; + SRC(0,3)=SRC(2,2)=SRC(4,1)=SRC(6,0)= (l3 + l4 + 1) >> 1; + SRC(1,3)=SRC(3,2)=SRC(5,1)=SRC(7,0)= (l3 + 2*l4 + l5 + 2) >> 2; + SRC(0,4)=SRC(2,3)=SRC(4,2)=SRC(6,1)= (l4 + l5 + 1) >> 1; + SRC(1,4)=SRC(3,3)=SRC(5,2)=SRC(7,1)= (l4 + 2*l5 + l6 + 2) >> 2; + SRC(0,5)=SRC(2,4)=SRC(4,3)=SRC(6,2)= (l5 + l6 + 1) >> 1; + SRC(1,5)=SRC(3,4)=SRC(5,3)=SRC(7,2)= (l5 + 2*l6 + l7 + 2) >> 2; + SRC(0,6)=SRC(2,5)=SRC(4,4)=SRC(6,3)= (l6 + l7 + 1) >> 1; + SRC(1,6)=SRC(3,5)=SRC(5,4)=SRC(7,3)= (l6 + 3*l7 + 2) >> 2; + SRC(0,7)=SRC(1,7)=SRC(2,6)=SRC(2,7)=SRC(3,6)= + SRC(3,7)=SRC(4,5)=SRC(4,6)=SRC(4,7)=SRC(5,5)= + SRC(5,6)=SRC(5,7)=SRC(6,4)=SRC(6,5)=SRC(6,6)= + SRC(6,7)=SRC(7,4)=SRC(7,5)=SRC(7,6)=SRC(7,7)= l7; +} +#undef PREDICT_8x8_LOAD_LEFT +#undef PREDICT_8x8_LOAD_TOP +#undef PREDICT_8x8_LOAD_TOPLEFT +#undef PREDICT_8x8_LOAD_TOPRIGHT +#undef PREDICT_8x8_DC +#undef PTR +#undef PT +#undef PL +#undef SRC + +/** + * Sets the intra prediction function pointers. + */ +void ff_h264_pred_init(H264PredContext *h, int codec_id){ +// MpegEncContext * const s = &h->s; + + if(codec_id != CODEC_ID_RV40){ + h->pred4x4[VERT_PRED ]= pred4x4_vertical_c; + h->pred4x4[HOR_PRED ]= pred4x4_horizontal_c; + h->pred4x4[DC_PRED ]= pred4x4_dc_c; + if(codec_id == CODEC_ID_SVQ3) + h->pred4x4[DIAG_DOWN_LEFT_PRED ]= pred4x4_down_left_svq3_c; + else + h->pred4x4[DIAG_DOWN_LEFT_PRED ]= pred4x4_down_left_c; + h->pred4x4[DIAG_DOWN_RIGHT_PRED]= pred4x4_down_right_c; + h->pred4x4[VERT_RIGHT_PRED ]= pred4x4_vertical_right_c; + h->pred4x4[HOR_DOWN_PRED ]= pred4x4_horizontal_down_c; + h->pred4x4[VERT_LEFT_PRED ]= pred4x4_vertical_left_c; + h->pred4x4[HOR_UP_PRED ]= pred4x4_horizontal_up_c; + h->pred4x4[LEFT_DC_PRED ]= pred4x4_left_dc_c; + h->pred4x4[TOP_DC_PRED ]= pred4x4_top_dc_c; + h->pred4x4[DC_128_PRED ]= pred4x4_128_dc_c; + }else{ + h->pred4x4[VERT_PRED ]= pred4x4_vertical_c; + h->pred4x4[HOR_PRED ]= pred4x4_horizontal_c; + h->pred4x4[DC_PRED ]= pred4x4_dc_c; + h->pred4x4[DIAG_DOWN_LEFT_PRED ]= pred4x4_down_left_rv40_c; + h->pred4x4[DIAG_DOWN_RIGHT_PRED]= pred4x4_down_right_c; + h->pred4x4[VERT_RIGHT_PRED ]= pred4x4_vertical_right_c; + h->pred4x4[HOR_DOWN_PRED ]= pred4x4_horizontal_down_c; + h->pred4x4[VERT_LEFT_PRED ]= pred4x4_vertical_left_rv40_c; + h->pred4x4[HOR_UP_PRED ]= pred4x4_horizontal_up_rv40_c; + h->pred4x4[LEFT_DC_PRED ]= pred4x4_left_dc_c; + h->pred4x4[TOP_DC_PRED ]= pred4x4_top_dc_c; + h->pred4x4[DC_128_PRED ]= pred4x4_128_dc_c; + h->pred4x4[DIAG_DOWN_LEFT_PRED_RV40_NODOWN]= pred4x4_down_left_rv40_nodown_c; + h->pred4x4[HOR_UP_PRED_RV40_NODOWN]= pred4x4_horizontal_up_rv40_nodown_c; + h->pred4x4[VERT_LEFT_PRED_RV40_NODOWN]= pred4x4_vertical_left_rv40_nodown_c; + } + + h->pred8x8l[VERT_PRED ]= pred8x8l_vertical_c; + h->pred8x8l[HOR_PRED ]= pred8x8l_horizontal_c; + h->pred8x8l[DC_PRED ]= pred8x8l_dc_c; + h->pred8x8l[DIAG_DOWN_LEFT_PRED ]= pred8x8l_down_left_c; + h->pred8x8l[DIAG_DOWN_RIGHT_PRED]= pred8x8l_down_right_c; + h->pred8x8l[VERT_RIGHT_PRED ]= pred8x8l_vertical_right_c; + h->pred8x8l[HOR_DOWN_PRED ]= pred8x8l_horizontal_down_c; + h->pred8x8l[VERT_LEFT_PRED ]= pred8x8l_vertical_left_c; + h->pred8x8l[HOR_UP_PRED ]= pred8x8l_horizontal_up_c; + h->pred8x8l[LEFT_DC_PRED ]= pred8x8l_left_dc_c; + h->pred8x8l[TOP_DC_PRED ]= pred8x8l_top_dc_c; + h->pred8x8l[DC_128_PRED ]= pred8x8l_128_dc_c; + + h->pred8x8[VERT_PRED8x8 ]= pred8x8_vertical_c; + h->pred8x8[HOR_PRED8x8 ]= pred8x8_horizontal_c; + h->pred8x8[PLANE_PRED8x8 ]= pred8x8_plane_c; + if(codec_id != CODEC_ID_RV40){ + h->pred8x8[DC_PRED8x8 ]= pred8x8_dc_c; + h->pred8x8[LEFT_DC_PRED8x8]= pred8x8_left_dc_c; + h->pred8x8[TOP_DC_PRED8x8 ]= pred8x8_top_dc_c; + }else{ + h->pred8x8[DC_PRED8x8 ]= pred8x8_dc_rv40_c; + h->pred8x8[LEFT_DC_PRED8x8]= pred8x8_left_dc_rv40_c; + h->pred8x8[TOP_DC_PRED8x8 ]= pred8x8_top_dc_rv40_c; + } + h->pred8x8[DC_128_PRED8x8 ]= pred8x8_128_dc_c; + + h->pred16x16[DC_PRED8x8 ]= pred16x16_dc_c; + h->pred16x16[VERT_PRED8x8 ]= pred16x16_vertical_c; + h->pred16x16[HOR_PRED8x8 ]= pred16x16_horizontal_c; + h->pred16x16[PLANE_PRED8x8 ]= pred16x16_plane_c; + switch(codec_id){ + case CODEC_ID_SVQ3: + h->pred16x16[PLANE_PRED8x8 ]= pred16x16_plane_svq3_c; + break; + case CODEC_ID_RV40: + h->pred16x16[PLANE_PRED8x8 ]= pred16x16_plane_rv40_c; + break; + default: + h->pred16x16[PLANE_PRED8x8 ]= pred16x16_plane_c; + } + h->pred16x16[LEFT_DC_PRED8x8]= pred16x16_left_dc_c; + h->pred16x16[TOP_DC_PRED8x8 ]= pred16x16_top_dc_c; + h->pred16x16[DC_128_PRED8x8 ]= pred16x16_128_dc_c; +} diff --git a/contrib/ffmpeg/libavcodec/h264pred.h b/contrib/ffmpeg/libavcodec/h264pred.h new file mode 100644 index 000000000..111e5b369 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/h264pred.h @@ -0,0 +1,77 @@ +/* + * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder + * Copyright (c) 2003 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file h264pred.h + * H.264 / AVC / MPEG4 prediction functions. + * @author Michael Niedermayer + */ + +#ifndef FFMPEG_H264PRED_H +#define FFMPEG_H264PRED_H + +#include "common.h" + +/** + * Prediction types + */ +//@{ +#define VERT_PRED 0 +#define HOR_PRED 1 +#define DC_PRED 2 +#define DIAG_DOWN_LEFT_PRED 3 +#define DIAG_DOWN_RIGHT_PRED 4 +#define VERT_RIGHT_PRED 5 +#define HOR_DOWN_PRED 6 +#define VERT_LEFT_PRED 7 +#define HOR_UP_PRED 8 + +#define LEFT_DC_PRED 9 +#define TOP_DC_PRED 10 +#define DC_128_PRED 11 + +#define DIAG_DOWN_LEFT_PRED_RV40_NODOWN 12 +#define HOR_UP_PRED_RV40_NODOWN 13 +#define VERT_LEFT_PRED_RV40_NODOWN 14 + +#define DC_PRED8x8 0 +#define HOR_PRED8x8 1 +#define VERT_PRED8x8 2 +#define PLANE_PRED8x8 3 + +#define LEFT_DC_PRED8x8 4 +#define TOP_DC_PRED8x8 5 +#define DC_128_PRED8x8 6 +//@} + +/** + * Context for storing H.264 prediction functions + */ +typedef struct H264PredContext{ + void (*pred4x4 [9+3+3])(uint8_t *src, uint8_t *topright, int stride);//FIXME move to dsp? + void (*pred8x8l [9+3])(uint8_t *src, int topleft, int topright, int stride); + void (*pred8x8 [4+3])(uint8_t *src, int stride); + void (*pred16x16[4+3])(uint8_t *src, int stride); +}H264PredContext; + +void ff_h264_pred_init(H264PredContext *h, int codec_id); + +#endif /* FFMPEG_H264PRED_H */ diff --git a/contrib/ffmpeg/libavcodec/huffman.c b/contrib/ffmpeg/libavcodec/huffman.c new file mode 100644 index 000000000..43a78558e --- /dev/null +++ b/contrib/ffmpeg/libavcodec/huffman.c @@ -0,0 +1,105 @@ +/** + * @file huffman.c + * huffman tree builder and VLC generator + * Copyright (c) 2006 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "bitstream.h" +#include "huffman.h" + +/* symbol for Huffman tree node */ +#define HNODE -1 + + +static void get_tree_codes(uint32_t *bits, int16_t *lens, uint8_t *xlat, Node *nodes, int node, uint32_t pfx, int pl, int *pos) +{ + int s; + + s = nodes[node].sym; + if(s != HNODE || !nodes[node].count){ + bits[*pos] = pfx; + lens[*pos] = pl; + xlat[*pos] = s; + (*pos)++; + }else{ + pfx <<= 1; + pl++; + get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0, pfx, pl, pos); + pfx |= 1; + get_tree_codes(bits, lens, xlat, nodes, nodes[node].n0+1, pfx, pl, pos); + } +} + +static int build_huff_tree(VLC *vlc, Node *nodes, int head) +{ + uint32_t bits[256]; + int16_t lens[256]; + uint8_t xlat[256]; + int pos = 0; + + get_tree_codes(bits, lens, xlat, nodes, head, 0, 0, &pos); + return init_vlc_sparse(vlc, 9, pos, lens, 2, 2, bits, 4, 4, xlat, 1, 1, 0); +} + + +/** + * nodes size must be 2*nb_codes + * first nb_codes nodes.count must be set + */ +int ff_huff_build_tree(AVCodecContext *avctx, VLC *vlc, int nb_codes, + Node *nodes, huff_cmp_t cmp, int hnode_first) +{ + int i, j; + int cur_node; + int64_t sum = 0; + + for(i = 0; i < nb_codes; i++){ + nodes[i].sym = i; + nodes[i].n0 = -2; + sum += nodes[i].count; + } + + if(sum >> 31) { + av_log(avctx, AV_LOG_ERROR, "Too high symbol frequencies. Tree construction is not possible\n"); + return -1; + } + qsort(nodes, nb_codes, sizeof(Node), cmp); + cur_node = nb_codes; + nodes[nb_codes*2-1].count = 0; + for(i = 0; i < nb_codes*2-1; i += 2){ + nodes[cur_node].sym = HNODE; + nodes[cur_node].count = nodes[i].count + nodes[i+1].count; + nodes[cur_node].n0 = i; + for(j = cur_node; j > 0; j--){ + if(nodes[j].count > nodes[j-1].count || + (nodes[j].count == nodes[j-1].count && + (!hnode_first || nodes[j].n0==j-1 || nodes[j].n0==j-2 || + (nodes[j].sym!=HNODE && nodes[j-1].sym!=HNODE)))) + break; + FFSWAP(Node, nodes[j], nodes[j-1]); + } + cur_node++; + } + if(build_huff_tree(vlc, nodes, nb_codes*2-2) < 0){ + av_log(avctx, AV_LOG_ERROR, "Error building tree\n"); + return -1; + } + return 0; +} diff --git a/contrib/ffmpeg/libavcodec/huffman.h b/contrib/ffmpeg/libavcodec/huffman.h new file mode 100644 index 000000000..57fbefa1e --- /dev/null +++ b/contrib/ffmpeg/libavcodec/huffman.h @@ -0,0 +1,39 @@ +/** + * @file huffman.h + * huffman tree builder and VLC generator + * Copyright (C) 2007 Aurelien Jacobs + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_HUFFMAN_H +#define FFMPEG_HUFFMAN_H + +#include "avcodec.h" +#include "bitstream.h" + +typedef struct { + int16_t sym; + int16_t n0; + uint32_t count; +} Node; + +typedef int (*huff_cmp_t)(const void *va, const void *vb); +int ff_huff_build_tree(AVCodecContext *avctx, VLC *vlc, int nb_codes, + Node *nodes, huff_cmp_t cmp, int hnode_first); + +#endif /* FFMPEG_HUFFMAN_H */ diff --git a/contrib/ffmpeg/libavcodec/huffyuv.c b/contrib/ffmpeg/libavcodec/huffyuv.c index f68d8e7ef..dddcdf1db 100644 --- a/contrib/ffmpeg/libavcodec/huffyuv.c +++ b/contrib/ffmpeg/libavcodec/huffyuv.c @@ -3,6 +3,9 @@ * * Copyright (c) 2002-2003 Michael Niedermayer * + * see http://www.pcisys.net/~melanson/codecs/huffyuv.txt for a description of + * the algorithm used + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -18,9 +21,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * see http://www.pcisys.net/~melanson/codecs/huffyuv.txt for a description of - * the algorithm used */ /** @@ -28,9 +28,8 @@ * huffyuv codec for libavcodec. */ -#include "common.h" -#include "bitstream.h" #include "avcodec.h" +#include "bitstream.h" #include "dsputil.h" #define VLC_BITS 11 @@ -71,7 +70,8 @@ typedef struct HYuvContext{ uint64_t stats[3][256]; uint8_t len[3][256]; uint32_t bits[3][256]; - VLC vlc[3]; + uint32_t pix_bgr_map[1< h[child+1].val) + child++; + if(h[root].val > h[child].val) { + FFSWAP(heap_elem_t, h[root], h[child]); + root = child; + } else + break; + } +} + static void generate_len_table(uint8_t *dst, uint64_t *stats, int size){ - uint64_t counts[2*size]; + heap_elem_t h[size]; int up[2*size]; + int len[2*size]; int offset, i, next; for(offset=1; ; offset<<=1){ for(i=0; i=0; i--) + heap_sift(h, i, size); + + for(next=size; next=size; i--) + len[i] = len[up[i]] + 1; + for(i=0; i= 32) break; + } + if(i==size) break; + } +} +#endif /* CONFIG_ENCODERS */ - for(i=0; i counts[i]){ - if(min1 > counts[i]){ - min2= min1; - min2_i= min1_i; - min1= counts[i]; - min1_i= i; +static void generate_joint_tables(HYuvContext *s){ + uint16_t symbols[1<bitstream_bpp < 24){ + int p, i, y, u; + for(p=0; p<3; p++){ + for(i=y=0; y<256; y++){ + int len0 = s->len[0][y]; + int limit = VLC_BITS - len0; + if(limit <= 0) + continue; + for(u=0; u<256; u++){ + int len1 = s->len[p][u]; + if(len1 > limit) + continue; + len[i] = len0 + len1; + bits[i] = (s->bits[0][y] << len1) + s->bits[p][u]; + symbols[i] = (y<<8) + u; + if(symbols[i] != 0xffff) // reserved to mean "invalid" + i++; + } + } + free_vlc(&s->vlc[3+p]); + init_vlc_sparse(&s->vlc[3+p], VLC_BITS, i, len, 1, 1, bits, 2, 2, symbols, 2, 2, 0); + } + }else{ + uint8_t (*map)[4] = (uint8_t(*)[4])s->pix_bgr_map; + int i, b, g, r, code; + int p0 = s->decorrelate; + int p1 = !s->decorrelate; + // restrict the range to +/-16 becaues that's pretty much guaranteed to + // cover all the combinations that fit in 11 bits total, and it doesn't + // matter if we miss a few rare codes. + for(i=0, g=-16; g<16; g++){ + int len0 = s->len[p0][g&255]; + int limit0 = VLC_BITS - len0; + if(limit0 < 2) + continue; + for(b=-16; b<16; b++){ + int len1 = s->len[p1][b&255]; + int limit1 = limit0 - len1; + if(limit1 < 1) + continue; + code = (s->bits[p0][g&255] << len1) + s->bits[p1][b&255]; + for(r=-16; r<16; r++){ + int len2 = s->len[2][r&255]; + if(len2 > limit1) + continue; + len[i] = len0 + len1 + len2; + bits[i] = (code << len2) + s->bits[2][r&255]; + if(s->decorrelate){ + map[i][G] = g; + map[i][B] = g+b; + map[i][R] = g+r; }else{ - min2= counts[i]; - min2_i= i; + map[i][B] = g; + map[i][G] = b; + map[i][R] = r; } + i++; } } - - if(min2==INT64_MAX) break; - - counts[next]= min1 + min2; - counts[min1_i]= - counts[min2_i]= INT64_MAX; - up[min1_i]= - up[min2_i]= next; - up[next]= -1; - } - - for(i=0; i= 32) break; - - dst[i]= len; } - if(i==size) break; + free_vlc(&s->vlc[3]); + init_vlc(&s->vlc[3], VLC_BITS, i, len, 1, 1, bits, 2, 2, 0); } } -#endif /* CONFIG_ENCODERS */ static int read_huffman_tables(HYuvContext *s, uint8_t *src, int length){ GetBitContext gb; @@ -340,6 +409,8 @@ printf("%6X, %2d, %3d\n", s->bits[i][j], s->len[i][j], j); init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4, 0); } + generate_joint_tables(s); + return (get_bits_count(&gb)+7)/8; } @@ -368,6 +439,8 @@ static int read_old_huffman_tables(HYuvContext *s){ init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4, 0); } + generate_joint_tables(s); + return 0; #else av_log(s->avctx, AV_LOG_DEBUG, "v1 huffyuv is not supported \n"); @@ -654,16 +727,27 @@ static int encode_init(AVCodecContext *avctx) } #endif /* CONFIG_ENCODERS */ +/* TODO instead of restarting the read when the code isn't in the first level + * of the joint table, jump into the 2nd level of the individual table. */ +#define READ_2PIX(dst0, dst1, plane1){\ + uint16_t code = get_vlc2(&s->gb, s->vlc[3+plane1].table, VLC_BITS, 1);\ + if(code != 0xffff){\ + dst0 = code>>8;\ + dst1 = code;\ + }else{\ + dst0 = get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3);\ + dst1 = get_vlc2(&s->gb, s->vlc[plane1].table, VLC_BITS, 3);\ + }\ +} + static void decode_422_bitstream(HYuvContext *s, int count){ int i; count/=2; for(i=0; itemp[0][2*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); - s->temp[1][ i ]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); - s->temp[0][2*i+1]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); - s->temp[2][ i ]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); + READ_2PIX(s->temp[0][2*i ], s->temp[1][i], 1); + READ_2PIX(s->temp[0][2*i+1], s->temp[2][i], 2); } } @@ -673,8 +757,7 @@ static void decode_gray_bitstream(HYuvContext *s, int count){ count/=2; for(i=0; itemp[0][2*i ]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); - s->temp[0][2*i+1]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); + READ_2PIX(s->temp[0][2*i ], s->temp[0][2*i+1], 0); } } @@ -687,34 +770,43 @@ static int encode_422_bitstream(HYuvContext *s, int count){ return -1; } +#define LOAD4\ + int y0 = s->temp[0][2*i];\ + int y1 = s->temp[0][2*i+1];\ + int u0 = s->temp[1][i];\ + int v0 = s->temp[2][i]; + count/=2; if(s->flags&CODEC_FLAG_PASS1){ for(i=0; istats[0][ s->temp[0][2*i ] ]++; - s->stats[1][ s->temp[1][ i ] ]++; - s->stats[0][ s->temp[0][2*i+1] ]++; - s->stats[2][ s->temp[2][ i ] ]++; + LOAD4; + s->stats[0][y0]++; + s->stats[1][u0]++; + s->stats[0][y1]++; + s->stats[2][v0]++; } } if(s->avctx->flags2&CODEC_FLAG2_NO_OUTPUT) return 0; if(s->context){ for(i=0; istats[0][ s->temp[0][2*i ] ]++; - put_bits(&s->pb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]); - s->stats[1][ s->temp[1][ i ] ]++; - put_bits(&s->pb, s->len[1][ s->temp[1][ i ] ], s->bits[1][ s->temp[1][ i ] ]); - s->stats[0][ s->temp[0][2*i+1] ]++; - put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]); - s->stats[2][ s->temp[2][ i ] ]++; - put_bits(&s->pb, s->len[2][ s->temp[2][ i ] ], s->bits[2][ s->temp[2][ i ] ]); + LOAD4; + s->stats[0][y0]++; + put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]); + s->stats[1][u0]++; + put_bits(&s->pb, s->len[1][u0], s->bits[1][u0]); + s->stats[0][y1]++; + put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]); + s->stats[2][v0]++; + put_bits(&s->pb, s->len[2][v0], s->bits[2][v0]); } }else{ for(i=0; ipb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]); - put_bits(&s->pb, s->len[1][ s->temp[1][ i ] ], s->bits[1][ s->temp[1][ i ] ]); - put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]); - put_bits(&s->pb, s->len[2][ s->temp[2][ i ] ], s->bits[2][ s->temp[2][ i ] ]); + LOAD4; + put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]); + put_bits(&s->pb, s->len[1][u0], s->bits[1][u0]); + put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]); + put_bits(&s->pb, s->len[2][v0], s->bits[2][v0]); } } return 0; @@ -728,11 +820,21 @@ static int encode_gray_bitstream(HYuvContext *s, int count){ return -1; } +#define LOAD2\ + int y0 = s->temp[0][2*i];\ + int y1 = s->temp[0][2*i+1]; +#define STAT2\ + s->stats[0][y0]++;\ + s->stats[0][y1]++; +#define WRITE2\ + put_bits(&s->pb, s->len[0][y0], s->bits[0][y0]);\ + put_bits(&s->pb, s->len[0][y1], s->bits[0][y1]); + count/=2; if(s->flags&CODEC_FLAG_PASS1){ for(i=0; istats[0][ s->temp[0][2*i ] ]++; - s->stats[0][ s->temp[0][2*i+1] ]++; + LOAD2; + STAT2; } } if(s->avctx->flags2&CODEC_FLAG2_NO_OUTPUT) @@ -740,54 +842,51 @@ static int encode_gray_bitstream(HYuvContext *s, int count){ if(s->context){ for(i=0; istats[0][ s->temp[0][2*i ] ]++; - put_bits(&s->pb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]); - s->stats[0][ s->temp[0][2*i+1] ]++; - put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]); + LOAD2; + STAT2; + WRITE2; } }else{ for(i=0; ipb, s->len[0][ s->temp[0][2*i ] ], s->bits[0][ s->temp[0][2*i ] ]); - put_bits(&s->pb, s->len[0][ s->temp[0][2*i+1] ], s->bits[0][ s->temp[0][2*i+1] ]); + LOAD2; + WRITE2; } } return 0; } #endif /* CONFIG_ENCODERS */ -static void decode_bgr_bitstream(HYuvContext *s, int count){ +static av_always_inline void decode_bgr_1(HYuvContext *s, int count, int decorrelate, int alpha){ int i; - - if(s->decorrelate){ - if(s->bitstream_bpp==24){ - for(i=0; itemp[0][4*i+G]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); - s->temp[0][4*i+B]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3) + s->temp[0][4*i+G]; - s->temp[0][4*i+R]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3) + s->temp[0][4*i+G]; - } + for(i=0; igb, s->vlc[3].table, VLC_BITS, 1); + if(code != -1){ + *(uint32_t*)&s->temp[0][4*i] = s->pix_bgr_map[code]; + }else if(decorrelate){ + s->temp[0][4*i+G] = get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); + s->temp[0][4*i+B] = get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3) + s->temp[0][4*i+G]; + s->temp[0][4*i+R] = get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3) + s->temp[0][4*i+G]; }else{ - for(i=0; itemp[0][4*i+G]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); - s->temp[0][4*i+B]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3) + s->temp[0][4*i+G]; - s->temp[0][4*i+R]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3) + s->temp[0][4*i+G]; - get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?! - } + s->temp[0][4*i+B] = get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); + s->temp[0][4*i+G] = get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); + s->temp[0][4*i+R] = get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); } + if(alpha) + get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?! + } +} + +static void decode_bgr_bitstream(HYuvContext *s, int count){ + if(s->decorrelate){ + if(s->bitstream_bpp==24) + decode_bgr_1(s, count, 1, 0); + else + decode_bgr_1(s, count, 1, 1); }else{ - if(s->bitstream_bpp==24){ - for(i=0; itemp[0][4*i+B]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); - s->temp[0][4*i+G]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); - s->temp[0][4*i+R]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); - } - }else{ - for(i=0; itemp[0][4*i+B]= get_vlc2(&s->gb, s->vlc[0].table, VLC_BITS, 3); - s->temp[0][4*i+G]= get_vlc2(&s->gb, s->vlc[1].table, VLC_BITS, 3); - s->temp[0][4*i+R]= get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); - get_vlc2(&s->gb, s->vlc[2].table, VLC_BITS, 3); //?! - } - } + if(s->bitstream_bpp==24) + decode_bgr_1(s, count, 0, 0); + else + decode_bgr_1(s, count, 0, 1); } } @@ -799,35 +898,34 @@ static int encode_bgr_bitstream(HYuvContext *s, int count){ return -1; } - if((s->flags&CODEC_FLAG_PASS1) && (s->avctx->flags2&CODEC_FLAG2_NO_OUTPUT)){ - for(i=0; itemp[0][4*i+G]; - int b= (s->temp[0][4*i+B] - g) & 0xff; +#define LOAD3\ + int g= s->temp[0][4*i+G];\ + int b= (s->temp[0][4*i+B] - g) & 0xff;\ int r= (s->temp[0][4*i+R] - g) & 0xff; - s->stats[0][b]++; - s->stats[1][g]++; +#define STAT3\ + s->stats[0][b]++;\ + s->stats[1][g]++;\ s->stats[2][r]++; +#define WRITE3\ + put_bits(&s->pb, s->len[1][g], s->bits[1][g]);\ + put_bits(&s->pb, s->len[0][b], s->bits[0][b]);\ + put_bits(&s->pb, s->len[2][r], s->bits[2][r]); + + if((s->flags&CODEC_FLAG_PASS1) && (s->avctx->flags2&CODEC_FLAG2_NO_OUTPUT)){ + for(i=0; icontext || (s->flags&CODEC_FLAG_PASS1)){ for(i=0; itemp[0][4*i+G]; - int b= (s->temp[0][4*i+B] - g) & 0xff; - int r= (s->temp[0][4*i+R] - g) & 0xff; - s->stats[0][b]++; - s->stats[1][g]++; - s->stats[2][r]++; - put_bits(&s->pb, s->len[1][g], s->bits[1][g]); - put_bits(&s->pb, s->len[0][b], s->bits[0][b]); - put_bits(&s->pb, s->len[2][r], s->bits[2][r]); + LOAD3; + STAT3; + WRITE3; } }else{ for(i=0; itemp[0][4*i+G]; - int b= (s->temp[0][4*i+B] - g) & 0xff; - int r= (s->temp[0][4*i+R] - g) & 0xff; - put_bits(&s->pb, s->len[1][g], s->bits[1][g]); - put_bits(&s->pb, s->len[0][b], s->bits[0][b]); - put_bits(&s->pb, s->len[2][r], s->bits[2][r]); + LOAD3; + WRITE3; } } return 0; @@ -861,7 +959,7 @@ static void draw_slice(HYuvContext *s, int y){ s->last_slice_end= y + h; } -static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){ +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size){ HYuvContext *s = avctx->priv_data; const int width= s->width; const int width2= s->width>>1; @@ -874,7 +972,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 s->bitstream_buffer= av_fast_realloc(s->bitstream_buffer, &s->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); - s->dsp.bswap_buf((uint32_t*)s->bitstream_buffer, (uint32_t*)buf, buf_size/4); + s->dsp.bswap_buf((uint32_t*)s->bitstream_buffer, (const uint32_t*)buf, buf_size/4); if(p->data[0]) avctx->release_buffer(avctx, p); @@ -1071,7 +1169,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 decode_bgr_bitstream(s, width-1); add_left_prediction_bgr32(p->data[0] + last_line+4, s->temp[0], width-1, &leftr, &leftg, &leftb); - for(y=s->height-2; y>=0; y--){ //yes its stored upside down + for(y=s->height-2; y>=0; y--){ //Yes it is stored upside down. decode_bgr_bitstream(s, width); add_left_prediction_bgr32(p->data[0] + p->linesize[0]*y, s->temp[0], width, &leftr, &leftg, &leftb); @@ -1120,7 +1218,7 @@ static int decode_end(AVCodecContext *avctx) common_end(s); av_freep(&s->bitstream_buffer); - for(i=0; i<3; i++){ + for(i=0; i<6; i++){ free_vlc(&s->vlc[i]); } @@ -1310,11 +1408,11 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, snprintf(p, end-p, "\n"); p++; } - } + } else + avctx->stats_out[0] = '\0'; if(!(s->avctx->flags2 & CODEC_FLAG2_NO_OUTPUT)){ flush_put_bits(&s->pb); s->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, size); - avctx->stats_out[0] = '\0'; } s->picture_number++; diff --git a/contrib/ffmpeg/libavcodec/i386/cavsdsp_mmx.c b/contrib/ffmpeg/libavcodec/i386/cavsdsp_mmx.c index 51d519a5c..141382fb0 100644 --- a/contrib/ffmpeg/libavcodec/i386/cavsdsp_mmx.c +++ b/contrib/ffmpeg/libavcodec/i386/cavsdsp_mmx.c @@ -2,7 +2,7 @@ * Chinese AVS video (AVS1-P2, JiZhun profile) decoder. * Copyright (c) 2006 Stefan Gehrer * - * MMX optimised DSP functions, based on H.264 optimisations by + * MMX-optimized DSP functions, based on H.264 optimizations by * Michael Niedermayer and Loren Merritt * * This file is part of FFmpeg. @@ -19,41 +19,19 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../dsputil.h" +#include "dsputil.h" +#include "dsputil_mmx.h" #include "common.h" -DECLARE_ALIGNED_8(static const uint64_t,ff_pw_4 ) = 0x0004000400040004ULL; -DECLARE_ALIGNED_8(static const uint64_t,ff_pw_5 ) = 0x0005000500050005ULL; -DECLARE_ALIGNED_8(static const uint64_t,ff_pw_7 ) = 0x0007000700070007ULL; -DECLARE_ALIGNED_8(static const uint64_t,ff_pw_42) = 0x002A002A002A002AULL; -DECLARE_ALIGNED_8(static const uint64_t,ff_pw_64) = 0x0040004000400040ULL; -DECLARE_ALIGNED_8(static const uint64_t,ff_pw_96) = 0x0060006000600060ULL; - /***************************************************************************** * * inverse transform * ****************************************************************************/ -#define SUMSUB_BA( a, b ) \ - "paddw "#b", "#a" \n\t"\ - "paddw "#b", "#b" \n\t"\ - "psubw "#a", "#b" \n\t" - -#define SBUTTERFLY(a,b,t,n)\ - "movq " #a ", " #t " \n\t" /* abcd */\ - "punpckl" #n " " #b ", " #a " \n\t" /* aebf */\ - "punpckh" #n " " #b ", " #t " \n\t" /* cgdh */ - -#define TRANSPOSE4(a,b,c,d,t)\ - SBUTTERFLY(a,b,t,wd) /* a=aebf t=cgdh */\ - SBUTTERFLY(c,d,b,wd) /* c=imjn b=kolp */\ - SBUTTERFLY(a,c,d,dq) /* a=aeim d=bfjn */\ - SBUTTERFLY(t,b,c,dq) /* t=cgko c=dhlp */ - static inline void cavs_idct8_1d(int16_t *block, uint64_t bias) { asm volatile( diff --git a/contrib/ffmpeg/libavcodec/i386/cputest.c b/contrib/ffmpeg/libavcodec/i386/cputest.c index 0705ab3e5..57b85ff9c 100644 --- a/contrib/ffmpeg/libavcodec/i386/cputest.c +++ b/contrib/ffmpeg/libavcodec/i386/cputest.c @@ -21,7 +21,7 @@ */ #include -#include "../dsputil.h" +#include "dsputil.h" #undef printf @@ -35,7 +35,7 @@ /* ebx saving is necessary for PIC. gcc seems unable to see it alone */ #define cpuid(index,eax,ebx,ecx,edx)\ - __asm __volatile\ + asm volatile\ ("mov %%"REG_b", %%"REG_S"\n\t"\ "cpuid\n\t"\ "xchg %%"REG_b", %%"REG_S\ @@ -80,15 +80,19 @@ int mm_support(void) if(max_std_level >= 1){ cpuid(1, eax, ebx, ecx, std_caps); if (std_caps & (1<<23)) - rval |= MM_MMX; + rval |= FF_MM_MMX; if (std_caps & (1<<25)) - rval |= MM_MMXEXT | MM_SSE; + rval |= FF_MM_MMXEXT +#if !defined(__GNUC__) || __GNUC__ > 2 + | FF_MM_SSE; if (std_caps & (1<<26)) - rval |= MM_SSE2; + rval |= FF_MM_SSE2; if (ecx & 1) - rval |= MM_SSE3; + rval |= FF_MM_SSE3; if (ecx & 0x00000200 ) - rval |= MM_SSSE3; + rval |= FF_MM_SSSE3 +#endif + ; } cpuid(0x80000000, max_ext_level, ebx, ecx, edx); @@ -96,30 +100,30 @@ int mm_support(void) if(max_ext_level >= 0x80000001){ cpuid(0x80000001, eax, ebx, ecx, ext_caps); if (ext_caps & (1<<31)) - rval |= MM_3DNOW; + rval |= FF_MM_3DNOW; if (ext_caps & (1<<30)) - rval |= MM_3DNOWEXT; + rval |= FF_MM_3DNOWEXT; if (ext_caps & (1<<23)) - rval |= MM_MMX; + rval |= FF_MM_MMX; if (ext_caps & (1<<22)) - rval |= MM_MMXEXT; + rval |= FF_MM_MMXEXT; } #if 0 av_log(NULL, AV_LOG_DEBUG, "%s%s%s%s%s%s%s%s\n", - (rval&MM_MMX) ? "MMX ":"", - (rval&MM_MMXEXT) ? "MMX2 ":"", - (rval&MM_SSE) ? "SSE ":"", - (rval&MM_SSE2) ? "SSE2 ":"", - (rval&MM_SSE3) ? "SSE3 ":"", - (rval&MM_SSSE3) ? "SSSE3 ":"", - (rval&MM_3DNOW) ? "3DNow ":"", - (rval&MM_3DNOWEXT) ? "3DNowExt ":""); + (rval&FF_MM_MMX) ? "MMX ":"", + (rval&FF_MM_MMXEXT) ? "MMX2 ":"", + (rval&FF_MM_SSE) ? "SSE ":"", + (rval&FF_MM_SSE2) ? "SSE2 ":"", + (rval&FF_MM_SSE3) ? "SSE3 ":"", + (rval&FF_MM_SSSE3) ? "SSSE3 ":"", + (rval&FF_MM_3DNOW) ? "3DNow ":"", + (rval&FF_MM_3DNOWEXT) ? "3DNowExt ":""); #endif return rval; } -#ifdef __TEST__ +#ifdef TEST int main ( void ) { int mm_flags; diff --git a/contrib/ffmpeg/libavcodec/i386/dsputil_h264_template_mmx.c b/contrib/ffmpeg/libavcodec/i386/dsputil_h264_template_mmx.c index a943a0371..e36c44075 100644 --- a/contrib/ffmpeg/libavcodec/i386/dsputil_h264_template_mmx.c +++ b/contrib/ffmpeg/libavcodec/i386/dsputil_h264_template_mmx.c @@ -25,8 +25,10 @@ * H264_CHROMA_OP must be defined to empty for put and pavgb/pavgusb for avg * H264_CHROMA_MC8_MV0 must be defined to a (put|avg)_pixels8 function */ -static void H264_CHROMA_MC8_TMPL(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y) +static void H264_CHROMA_MC8_TMPL(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y, int rnd) { + DECLARE_ALIGNED_8(static const uint64_t, ff_pw_28) = 0x001C001C001C001CULL; + const uint64_t *rnd_reg; DECLARE_ALIGNED_8(uint64_t, AA); DECLARE_ALIGNED_8(uint64_t, DD); int i; @@ -44,16 +46,17 @@ static void H264_CHROMA_MC8_TMPL(uint8_t *dst/*align 8*/, uint8_t *src/*align 1* /* 1 dimensional filter only */ const int dxy = x ? 1 : stride; + rnd_reg = rnd ? &ff_pw_4 : &ff_pw_3; + asm volatile( "movd %0, %%mm5\n\t" "movq %1, %%mm4\n\t" + "movq %2, %%mm6\n\t" /* mm6 = rnd */ "punpcklwd %%mm5, %%mm5\n\t" "punpckldq %%mm5, %%mm5\n\t" /* mm5 = B = x */ - "movq %%mm4, %%mm6\n\t" "pxor %%mm7, %%mm7\n\t" "psubw %%mm5, %%mm4\n\t" /* mm4 = A = 8-x */ - "psrlw $1, %%mm6\n\t" /* mm6 = 4 */ - :: "rm"(x+y), "m"(ff_pw_8)); + :: "rm"(x+y), "m"(ff_pw_8), "m"(*rnd_reg)); for(i=0; i */ -#include "../dsputil.h" -#include "../simple_idct.h" -#include "../mpegvideo.h" +#include "dsputil.h" +#include "dsputil_mmx.h" +#include "simple_idct.h" +#include "mpegvideo.h" #include "x86_cpu.h" #include "mmx.h" +#include "vp3dsp_mmx.h" +#include "vp3dsp_sse2.h" +#include "h263.h" //#undef NDEBUG //#include @@ -37,58 +41,58 @@ extern void ff_idct_xvid_mmx2(short *block); int mm_flags; /* multimedia extension flags */ /* pixel operations */ -static const uint64_t mm_bone attribute_used __attribute__ ((aligned(8))) = 0x0101010101010101ULL; -static const uint64_t mm_wone attribute_used __attribute__ ((aligned(8))) = 0x0001000100010001ULL; -static const uint64_t mm_wtwo attribute_used __attribute__ ((aligned(8))) = 0x0002000200020002ULL; +DECLARE_ALIGNED_8 (const uint64_t, ff_bone) = 0x0101010101010101ULL; +DECLARE_ALIGNED_8 (const uint64_t, ff_wtwo) = 0x0002000200020002ULL; -static const uint64_t ff_pdw_80000000[2] attribute_used __attribute__ ((aligned(16))) = +DECLARE_ALIGNED_16(const uint64_t, ff_pdw_80000000[2]) = {0x8000000080000000ULL, 0x8000000080000000ULL}; -static const uint64_t ff_pw_20 attribute_used __attribute__ ((aligned(8))) = 0x0014001400140014ULL; -static const uint64_t ff_pw_3 attribute_used __attribute__ ((aligned(8))) = 0x0003000300030003ULL; -static const uint64_t ff_pw_4 attribute_used __attribute__ ((aligned(8))) = 0x0004000400040004ULL; -static const uint64_t ff_pw_5 attribute_used __attribute__ ((aligned(8))) = 0x0005000500050005ULL; -static const uint64_t ff_pw_8 attribute_used __attribute__ ((aligned(8))) = 0x0008000800080008ULL; -static const uint64_t ff_pw_16 attribute_used __attribute__ ((aligned(8))) = 0x0010001000100010ULL; -static const uint64_t ff_pw_32 attribute_used __attribute__ ((aligned(8))) = 0x0020002000200020ULL; -static const uint64_t ff_pw_64 attribute_used __attribute__ ((aligned(8))) = 0x0040004000400040ULL; -static const uint64_t ff_pw_15 attribute_used __attribute__ ((aligned(8))) = 0x000F000F000F000FULL; - -static const uint64_t ff_pb_1 attribute_used __attribute__ ((aligned(8))) = 0x0101010101010101ULL; -static const uint64_t ff_pb_3 attribute_used __attribute__ ((aligned(8))) = 0x0303030303030303ULL; -static const uint64_t ff_pb_7 attribute_used __attribute__ ((aligned(8))) = 0x0707070707070707ULL; -static const uint64_t ff_pb_3F attribute_used __attribute__ ((aligned(8))) = 0x3F3F3F3F3F3F3F3FULL; -static const uint64_t ff_pb_A1 attribute_used __attribute__ ((aligned(8))) = 0xA1A1A1A1A1A1A1A1ULL; -static const uint64_t ff_pb_5F attribute_used __attribute__ ((aligned(8))) = 0x5F5F5F5F5F5F5F5FULL; -static const uint64_t ff_pb_FC attribute_used __attribute__ ((aligned(8))) = 0xFCFCFCFCFCFCFCFCULL; - -#define JUMPALIGN() __asm __volatile (ASMALIGN(3)::) -#define MOVQ_ZERO(regd) __asm __volatile ("pxor %%" #regd ", %%" #regd ::) - -#define MOVQ_WONE(regd) \ - __asm __volatile ( \ - "pcmpeqd %%" #regd ", %%" #regd " \n\t" \ - "psrlw $15, %%" #regd ::) +DECLARE_ALIGNED_8 (const uint64_t, ff_pw_3 ) = 0x0003000300030003ULL; +DECLARE_ALIGNED_8 (const uint64_t, ff_pw_4 ) = 0x0004000400040004ULL; +DECLARE_ALIGNED_16(const xmm_t, ff_pw_5 ) = {0x0005000500050005ULL, 0x0005000500050005ULL}; +DECLARE_ALIGNED_8 (const uint64_t, ff_pw_8 ) = 0x0008000800080008ULL; +DECLARE_ALIGNED_8 (const uint64_t, ff_pw_15 ) = 0x000F000F000F000FULL; +DECLARE_ALIGNED_16(const xmm_t, ff_pw_16 ) = {0x0010001000100010ULL, 0x0010001000100010ULL}; +DECLARE_ALIGNED_8 (const uint64_t, ff_pw_20 ) = 0x0014001400140014ULL; +DECLARE_ALIGNED_16(const xmm_t, ff_pw_32 ) = {0x0020002000200020ULL, 0x0020002000200020ULL}; +DECLARE_ALIGNED_8 (const uint64_t, ff_pw_42 ) = 0x002A002A002A002AULL; +DECLARE_ALIGNED_8 (const uint64_t, ff_pw_64 ) = 0x0040004000400040ULL; +DECLARE_ALIGNED_8 (const uint64_t, ff_pw_96 ) = 0x0060006000600060ULL; +DECLARE_ALIGNED_8 (const uint64_t, ff_pw_128) = 0x0080008000800080ULL; +DECLARE_ALIGNED_8 (const uint64_t, ff_pw_255) = 0x00ff00ff00ff00ffULL; + +DECLARE_ALIGNED_8 (const uint64_t, ff_pb_1 ) = 0x0101010101010101ULL; +DECLARE_ALIGNED_8 (const uint64_t, ff_pb_3 ) = 0x0303030303030303ULL; +DECLARE_ALIGNED_8 (const uint64_t, ff_pb_7 ) = 0x0707070707070707ULL; +DECLARE_ALIGNED_8 (const uint64_t, ff_pb_3F ) = 0x3F3F3F3F3F3F3F3FULL; +DECLARE_ALIGNED_8 (const uint64_t, ff_pb_A1 ) = 0xA1A1A1A1A1A1A1A1ULL; +DECLARE_ALIGNED_8 (const uint64_t, ff_pb_FC ) = 0xFCFCFCFCFCFCFCFCULL; + +DECLARE_ALIGNED_16(const double, ff_pd_1[2]) = { 1.0, 1.0 }; +DECLARE_ALIGNED_16(const double, ff_pd_2[2]) = { 2.0, 2.0 }; + +#define JUMPALIGN() asm volatile (ASMALIGN(3)::) +#define MOVQ_ZERO(regd) asm volatile ("pxor %%" #regd ", %%" #regd ::) #define MOVQ_BFE(regd) \ - __asm __volatile ( \ + asm volatile ( \ "pcmpeqd %%" #regd ", %%" #regd " \n\t"\ "paddb %%" #regd ", %%" #regd " \n\t" ::) #ifndef PIC -#define MOVQ_BONE(regd) __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_bone)) -#define MOVQ_WTWO(regd) __asm __volatile ("movq %0, %%" #regd " \n\t" ::"m"(mm_wtwo)) +#define MOVQ_BONE(regd) asm volatile ("movq %0, %%" #regd " \n\t" ::"m"(ff_bone)) +#define MOVQ_WTWO(regd) asm volatile ("movq %0, %%" #regd " \n\t" ::"m"(ff_wtwo)) #else // for shared library it's better to use this way for accessing constants // pcmpeqd -> -1 #define MOVQ_BONE(regd) \ - __asm __volatile ( \ + asm volatile ( \ "pcmpeqd %%" #regd ", %%" #regd " \n\t" \ "psrlw $15, %%" #regd " \n\t" \ "packuswb %%" #regd ", %%" #regd " \n\t" ::) #define MOVQ_WTWO(regd) \ - __asm __volatile ( \ + asm volatile ( \ "pcmpeqd %%" #regd ", %%" #regd " \n\t" \ "psrlw $15, %%" #regd " \n\t" \ "psllw $1, %%" #regd " \n\t"::) @@ -175,7 +179,6 @@ static const uint64_t ff_pb_FC attribute_used __attribute__ ((aligned(8))) = 0xF /* 3Dnow specific */ #define DEF(x) x ## _3dnow -/* for Athlons PAVGUSB is prefered */ #define PAVGB "pavgusb" #include "dsputil_mmx_avg.h" @@ -196,73 +199,22 @@ static const uint64_t ff_pb_FC attribute_used __attribute__ ((aligned(8))) = 0xF #undef DEF #undef PAVGB -#define SBUTTERFLY(a,b,t,n)\ - "movq " #a ", " #t " \n\t" /* abcd */\ - "punpckl" #n " " #b ", " #a " \n\t" /* aebf */\ - "punpckh" #n " " #b ", " #t " \n\t" /* cgdh */\ +#define put_no_rnd_pixels16_mmx put_pixels16_mmx +#define put_no_rnd_pixels8_mmx put_pixels8_mmx +#define put_pixels16_mmx2 put_pixels16_mmx +#define put_pixels8_mmx2 put_pixels8_mmx +#define put_pixels4_mmx2 put_pixels4_mmx +#define put_no_rnd_pixels16_mmx2 put_no_rnd_pixels16_mmx +#define put_no_rnd_pixels8_mmx2 put_no_rnd_pixels8_mmx +#define put_pixels16_3dnow put_pixels16_mmx +#define put_pixels8_3dnow put_pixels8_mmx +#define put_pixels4_3dnow put_pixels4_mmx +#define put_no_rnd_pixels16_3dnow put_no_rnd_pixels16_mmx +#define put_no_rnd_pixels8_3dnow put_no_rnd_pixels8_mmx /***********************************/ /* standard MMX */ -#ifdef CONFIG_ENCODERS -static void get_pixels_mmx(DCTELEM *block, const uint8_t *pixels, int line_size) -{ - asm volatile( - "mov $-128, %%"REG_a" \n\t" - "pxor %%mm7, %%mm7 \n\t" - ASMALIGN(4) - "1: \n\t" - "movq (%0), %%mm0 \n\t" - "movq (%0, %2), %%mm2 \n\t" - "movq %%mm0, %%mm1 \n\t" - "movq %%mm2, %%mm3 \n\t" - "punpcklbw %%mm7, %%mm0 \n\t" - "punpckhbw %%mm7, %%mm1 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" - "punpckhbw %%mm7, %%mm3 \n\t" - "movq %%mm0, (%1, %%"REG_a") \n\t" - "movq %%mm1, 8(%1, %%"REG_a") \n\t" - "movq %%mm2, 16(%1, %%"REG_a") \n\t" - "movq %%mm3, 24(%1, %%"REG_a") \n\t" - "add %3, %0 \n\t" - "add $32, %%"REG_a" \n\t" - "js 1b \n\t" - : "+r" (pixels) - : "r" (block+64), "r" ((long)line_size), "r" ((long)line_size*2) - : "%"REG_a - ); -} - -static inline void diff_pixels_mmx(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride) -{ - asm volatile( - "pxor %%mm7, %%mm7 \n\t" - "mov $-128, %%"REG_a" \n\t" - ASMALIGN(4) - "1: \n\t" - "movq (%0), %%mm0 \n\t" - "movq (%1), %%mm2 \n\t" - "movq %%mm0, %%mm1 \n\t" - "movq %%mm2, %%mm3 \n\t" - "punpcklbw %%mm7, %%mm0 \n\t" - "punpckhbw %%mm7, %%mm1 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" - "punpckhbw %%mm7, %%mm3 \n\t" - "psubw %%mm2, %%mm0 \n\t" - "psubw %%mm3, %%mm1 \n\t" - "movq %%mm0, (%2, %%"REG_a") \n\t" - "movq %%mm1, 8(%2, %%"REG_a") \n\t" - "add %3, %0 \n\t" - "add %3, %1 \n\t" - "add $16, %%"REG_a" \n\t" - "jnz 1b \n\t" - : "+r" (s1), "+r" (s2) - : "r" (block+64), "r" ((long)stride) - : "%"REG_a - ); -} -#endif //CONFIG_ENCODERS - void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size) { const DCTELEM *p; @@ -272,7 +224,7 @@ void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size p = block; pix = pixels; /* unrolled loop */ - __asm __volatile( + asm volatile( "movq %3, %%mm0 \n\t" "movq 8%3, %%mm1 \n\t" "movq 16%3, %%mm2 \n\t" @@ -297,7 +249,7 @@ void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size // if here would be an exact copy of the code above // compiler would generate some very strange code // thus using "r" - __asm __volatile( + asm volatile( "movq (%3), %%mm0 \n\t" "movq 8(%3), %%mm1 \n\t" "movq 16(%3), %%mm2 \n\t" @@ -348,7 +300,7 @@ void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size MOVQ_ZERO(mm7); i = 4; do { - __asm __volatile( + asm volatile( "movq (%2), %%mm0 \n\t" "movq 8(%2), %%mm1 \n\t" "movq 16(%2), %%mm2 \n\t" @@ -379,7 +331,7 @@ void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size static void put_pixels4_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h) { - __asm __volatile( + asm volatile( "lea (%3, %3), %%"REG_a" \n\t" ASMALIGN(3) "1: \n\t" @@ -405,7 +357,7 @@ static void put_pixels4_mmx(uint8_t *block, const uint8_t *pixels, int line_size static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h) { - __asm __volatile( + asm volatile( "lea (%3, %3), %%"REG_a" \n\t" ASMALIGN(3) "1: \n\t" @@ -431,7 +383,7 @@ static void put_pixels8_mmx(uint8_t *block, const uint8_t *pixels, int line_size static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels, int line_size, int h) { - __asm __volatile( + asm volatile( "lea (%3, %3), %%"REG_a" \n\t" ASMALIGN(3) "1: \n\t" @@ -463,9 +415,57 @@ static void put_pixels16_mmx(uint8_t *block, const uint8_t *pixels, int line_siz ); } +static void put_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_size, int h) +{ + asm volatile( + "1: \n\t" + "movdqu (%1), %%xmm0 \n\t" + "movdqu (%1,%3), %%xmm1 \n\t" + "movdqu (%1,%3,2), %%xmm2 \n\t" + "movdqu (%1,%4), %%xmm3 \n\t" + "movdqa %%xmm0, (%2) \n\t" + "movdqa %%xmm1, (%2,%3) \n\t" + "movdqa %%xmm2, (%2,%3,2) \n\t" + "movdqa %%xmm3, (%2,%4) \n\t" + "subl $4, %0 \n\t" + "lea (%1,%3,4), %1 \n\t" + "lea (%2,%3,4), %2 \n\t" + "jnz 1b \n\t" + : "+g"(h), "+r" (pixels), "+r" (block) + : "r"((long)line_size), "r"(3L*line_size) + : "memory" + ); +} + +static void avg_pixels16_sse2(uint8_t *block, const uint8_t *pixels, int line_size, int h) +{ + asm volatile( + "1: \n\t" + "movdqu (%1), %%xmm0 \n\t" + "movdqu (%1,%3), %%xmm1 \n\t" + "movdqu (%1,%3,2), %%xmm2 \n\t" + "movdqu (%1,%4), %%xmm3 \n\t" + "pavgb (%2), %%xmm0 \n\t" + "pavgb (%2,%3), %%xmm1 \n\t" + "pavgb (%2,%3,2), %%xmm2 \n\t" + "pavgb (%2,%4), %%xmm3 \n\t" + "movdqa %%xmm0, (%2) \n\t" + "movdqa %%xmm1, (%2,%3) \n\t" + "movdqa %%xmm2, (%2,%3,2) \n\t" + "movdqa %%xmm3, (%2,%4) \n\t" + "subl $4, %0 \n\t" + "lea (%1,%3,4), %1 \n\t" + "lea (%2,%3,4), %2 \n\t" + "jnz 1b \n\t" + : "+g"(h), "+r" (pixels), "+r" (block) + : "r"((long)line_size), "r"(3L*line_size) + : "memory" + ); +} + static void clear_blocks_mmx(DCTELEM *blocks) { - __asm __volatile( + asm volatile( "pxor %%mm7, %%mm7 \n\t" "mov $-128*6, %%"REG_a" \n\t" "1: \n\t" @@ -480,46 +480,6 @@ static void clear_blocks_mmx(DCTELEM *blocks) ); } -#ifdef CONFIG_ENCODERS -static int pix_sum16_mmx(uint8_t * pix, int line_size){ - const int h=16; - int sum; - long index= -line_size*h; - - __asm __volatile( - "pxor %%mm7, %%mm7 \n\t" - "pxor %%mm6, %%mm6 \n\t" - "1: \n\t" - "movq (%2, %1), %%mm0 \n\t" - "movq (%2, %1), %%mm1 \n\t" - "movq 8(%2, %1), %%mm2 \n\t" - "movq 8(%2, %1), %%mm3 \n\t" - "punpcklbw %%mm7, %%mm0 \n\t" - "punpckhbw %%mm7, %%mm1 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" - "punpckhbw %%mm7, %%mm3 \n\t" - "paddw %%mm0, %%mm1 \n\t" - "paddw %%mm2, %%mm3 \n\t" - "paddw %%mm1, %%mm3 \n\t" - "paddw %%mm3, %%mm6 \n\t" - "add %3, %1 \n\t" - " js 1b \n\t" - "movq %%mm6, %%mm5 \n\t" - "psrlq $32, %%mm6 \n\t" - "paddw %%mm5, %%mm6 \n\t" - "movq %%mm6, %%mm5 \n\t" - "psrlq $16, %%mm6 \n\t" - "paddw %%mm5, %%mm6 \n\t" - "movd %%mm6, %0 \n\t" - "andl $0xFFFF, %0 \n\t" - : "=&r" (sum), "+r" (index) - : "r" (pix - index), "r" ((long)line_size) - ); - - return sum; -} -#endif //CONFIG_ENCODERS - static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){ long i=0; asm volatile( @@ -542,6 +502,26 @@ static void add_bytes_mmx(uint8_t *dst, uint8_t *src, int w){ dst[i+0] += src[i+0]; } +static void add_bytes_l2_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){ + long i=0; + asm volatile( + "1: \n\t" + "movq (%2, %0), %%mm0 \n\t" + "movq 8(%2, %0), %%mm1 \n\t" + "paddb (%3, %0), %%mm0 \n\t" + "paddb 8(%3, %0), %%mm1 \n\t" + "movq %%mm0, (%1, %0) \n\t" + "movq %%mm1, 8(%1, %0) \n\t" + "add $16, %0 \n\t" + "cmp %4, %0 \n\t" + " jb 1b \n\t" + : "+r" (i) + : "r"(dst), "r"(src1), "r"(src2), "r"((long)w-15) + ); + for(; idsp.sse[0](c, pix1, pix2, line_size, h); - else score1 = sse16_mmx(c, pix1, pix2, line_size, h); - score2= hf_noise16_mmx(pix1, line_size, h) - hf_noise16_mmx(pix2, line_size, h); - - if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight; - else return score1 + FFABS(score2)*8; -} - -static int nsse8_mmx(void *p, uint8_t * pix1, uint8_t * pix2, int line_size, int h) { - MpegEncContext *c = p; - int score1= sse8_mmx(c, pix1, pix2, line_size, h); - int score2= hf_noise8_mmx(pix1, line_size, h) - hf_noise8_mmx(pix2, line_size, h); - - if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight; - else return score1 + FFABS(score2)*8; -} - -static int vsad_intra16_mmx(void *v, uint8_t * pix, uint8_t * dummy, int line_size, int h) { - int tmp; - - assert( (((int)pix) & 7) == 0); - assert((line_size &7) ==0); - -#define SUM(in0, in1, out0, out1) \ - "movq (%0), %%mm2\n"\ - "movq 8(%0), %%mm3\n"\ - "add %2,%0\n"\ - "movq %%mm2, " #out0 "\n"\ - "movq %%mm3, " #out1 "\n"\ - "psubusb " #in0 ", %%mm2\n"\ - "psubusb " #in1 ", %%mm3\n"\ - "psubusb " #out0 ", " #in0 "\n"\ - "psubusb " #out1 ", " #in1 "\n"\ - "por %%mm2, " #in0 "\n"\ - "por %%mm3, " #in1 "\n"\ - "movq " #in0 ", %%mm2\n"\ - "movq " #in1 ", %%mm3\n"\ - "punpcklbw %%mm7, " #in0 "\n"\ - "punpcklbw %%mm7, " #in1 "\n"\ - "punpckhbw %%mm7, %%mm2\n"\ - "punpckhbw %%mm7, %%mm3\n"\ - "paddw " #in1 ", " #in0 "\n"\ - "paddw %%mm3, %%mm2\n"\ - "paddw %%mm2, " #in0 "\n"\ - "paddw " #in0 ", %%mm6\n" - - - asm volatile ( - "movl %3,%%ecx\n" - "pxor %%mm6,%%mm6\n" - "pxor %%mm7,%%mm7\n" - "movq (%0),%%mm0\n" - "movq 8(%0),%%mm1\n" - "add %2,%0\n" - "subl $2, %%ecx\n" - SUM(%%mm0, %%mm1, %%mm4, %%mm5) - "1:\n" - - SUM(%%mm4, %%mm5, %%mm0, %%mm1) - - SUM(%%mm0, %%mm1, %%mm4, %%mm5) - - "subl $2, %%ecx\n" - "jnz 1b\n" - - "movq %%mm6,%%mm0\n" - "psrlq $32, %%mm6\n" - "paddw %%mm6,%%mm0\n" - "movq %%mm0,%%mm6\n" - "psrlq $16, %%mm0\n" - "paddw %%mm6,%%mm0\n" - "movd %%mm0,%1\n" - : "+r" (pix), "=r"(tmp) - : "r" ((long)line_size) , "m" (h) - : "%ecx"); - return tmp & 0xFFFF; -} -#undef SUM - -static int vsad_intra16_mmx2(void *v, uint8_t * pix, uint8_t * dummy, int line_size, int h) { - int tmp; - - assert( (((int)pix) & 7) == 0); - assert((line_size &7) ==0); - -#define SUM(in0, in1, out0, out1) \ - "movq (%0), " #out0 "\n"\ - "movq 8(%0), " #out1 "\n"\ - "add %2,%0\n"\ - "psadbw " #out0 ", " #in0 "\n"\ - "psadbw " #out1 ", " #in1 "\n"\ - "paddw " #in1 ", " #in0 "\n"\ - "paddw " #in0 ", %%mm6\n" - - asm volatile ( - "movl %3,%%ecx\n" - "pxor %%mm6,%%mm6\n" - "pxor %%mm7,%%mm7\n" - "movq (%0),%%mm0\n" - "movq 8(%0),%%mm1\n" - "add %2,%0\n" - "subl $2, %%ecx\n" - SUM(%%mm0, %%mm1, %%mm4, %%mm5) - "1:\n" - - SUM(%%mm4, %%mm5, %%mm0, %%mm1) - - SUM(%%mm0, %%mm1, %%mm4, %%mm5) - - "subl $2, %%ecx\n" - "jnz 1b\n" - - "movd %%mm6,%1\n" - : "+r" (pix), "=r"(tmp) - : "r" ((long)line_size) , "m" (h) - : "%ecx"); - return tmp; -} -#undef SUM - -static int vsad16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) { - int tmp; - - assert( (((int)pix1) & 7) == 0); - assert( (((int)pix2) & 7) == 0); - assert((line_size &7) ==0); - -#define SUM(in0, in1, out0, out1) \ - "movq (%0),%%mm2\n"\ - "movq (%1)," #out0 "\n"\ - "movq 8(%0),%%mm3\n"\ - "movq 8(%1)," #out1 "\n"\ - "add %3,%0\n"\ - "add %3,%1\n"\ - "psubb " #out0 ", %%mm2\n"\ - "psubb " #out1 ", %%mm3\n"\ - "pxor %%mm7, %%mm2\n"\ - "pxor %%mm7, %%mm3\n"\ - "movq %%mm2, " #out0 "\n"\ - "movq %%mm3, " #out1 "\n"\ - "psubusb " #in0 ", %%mm2\n"\ - "psubusb " #in1 ", %%mm3\n"\ - "psubusb " #out0 ", " #in0 "\n"\ - "psubusb " #out1 ", " #in1 "\n"\ - "por %%mm2, " #in0 "\n"\ - "por %%mm3, " #in1 "\n"\ - "movq " #in0 ", %%mm2\n"\ - "movq " #in1 ", %%mm3\n"\ - "punpcklbw %%mm7, " #in0 "\n"\ - "punpcklbw %%mm7, " #in1 "\n"\ - "punpckhbw %%mm7, %%mm2\n"\ - "punpckhbw %%mm7, %%mm3\n"\ - "paddw " #in1 ", " #in0 "\n"\ - "paddw %%mm3, %%mm2\n"\ - "paddw %%mm2, " #in0 "\n"\ - "paddw " #in0 ", %%mm6\n" - - - asm volatile ( - "movl %4,%%ecx\n" - "pxor %%mm6,%%mm6\n" - "pcmpeqw %%mm7,%%mm7\n" - "psllw $15, %%mm7\n" - "packsswb %%mm7, %%mm7\n" - "movq (%0),%%mm0\n" - "movq (%1),%%mm2\n" - "movq 8(%0),%%mm1\n" - "movq 8(%1),%%mm3\n" - "add %3,%0\n" - "add %3,%1\n" - "subl $2, %%ecx\n" - "psubb %%mm2, %%mm0\n" - "psubb %%mm3, %%mm1\n" - "pxor %%mm7, %%mm0\n" - "pxor %%mm7, %%mm1\n" - SUM(%%mm0, %%mm1, %%mm4, %%mm5) - "1:\n" - - SUM(%%mm4, %%mm5, %%mm0, %%mm1) - - SUM(%%mm0, %%mm1, %%mm4, %%mm5) - - "subl $2, %%ecx\n" - "jnz 1b\n" - - "movq %%mm6,%%mm0\n" - "psrlq $32, %%mm6\n" - "paddw %%mm6,%%mm0\n" - "movq %%mm0,%%mm6\n" - "psrlq $16, %%mm0\n" - "paddw %%mm6,%%mm0\n" - "movd %%mm0,%2\n" - : "+r" (pix1), "+r" (pix2), "=r"(tmp) - : "r" ((long)line_size) , "m" (h) - : "%ecx"); - return tmp & 0x7FFF; -} -#undef SUM - -static int vsad16_mmx2(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) { - int tmp; - - assert( (((int)pix1) & 7) == 0); - assert( (((int)pix2) & 7) == 0); - assert((line_size &7) ==0); - -#define SUM(in0, in1, out0, out1) \ - "movq (%0)," #out0 "\n"\ - "movq (%1),%%mm2\n"\ - "movq 8(%0)," #out1 "\n"\ - "movq 8(%1),%%mm3\n"\ - "add %3,%0\n"\ - "add %3,%1\n"\ - "psubb %%mm2, " #out0 "\n"\ - "psubb %%mm3, " #out1 "\n"\ - "pxor %%mm7, " #out0 "\n"\ - "pxor %%mm7, " #out1 "\n"\ - "psadbw " #out0 ", " #in0 "\n"\ - "psadbw " #out1 ", " #in1 "\n"\ - "paddw " #in1 ", " #in0 "\n"\ - "paddw " #in0 ", %%mm6\n" - - asm volatile ( - "movl %4,%%ecx\n" - "pxor %%mm6,%%mm6\n" - "pcmpeqw %%mm7,%%mm7\n" - "psllw $15, %%mm7\n" - "packsswb %%mm7, %%mm7\n" - "movq (%0),%%mm0\n" - "movq (%1),%%mm2\n" - "movq 8(%0),%%mm1\n" - "movq 8(%1),%%mm3\n" - "add %3,%0\n" - "add %3,%1\n" - "subl $2, %%ecx\n" - "psubb %%mm2, %%mm0\n" - "psubb %%mm3, %%mm1\n" - "pxor %%mm7, %%mm0\n" - "pxor %%mm7, %%mm1\n" - SUM(%%mm0, %%mm1, %%mm4, %%mm5) - "1:\n" - - SUM(%%mm4, %%mm5, %%mm0, %%mm1) - - SUM(%%mm0, %%mm1, %%mm4, %%mm5) - - "subl $2, %%ecx\n" - "jnz 1b\n" - - "movd %%mm6,%2\n" - : "+r" (pix1), "+r" (pix2), "=r"(tmp) - : "r" ((long)line_size) , "m" (h) - : "%ecx"); - return tmp; -} -#undef SUM - -static void diff_bytes_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){ - long i=0; - asm volatile( - "1: \n\t" - "movq (%2, %0), %%mm0 \n\t" - "movq (%1, %0), %%mm1 \n\t" - "psubb %%mm0, %%mm1 \n\t" - "movq %%mm1, (%3, %0) \n\t" - "movq 8(%2, %0), %%mm0 \n\t" - "movq 8(%1, %0), %%mm1 \n\t" - "psubb %%mm0, %%mm1 \n\t" - "movq %%mm1, 8(%3, %0) \n\t" - "add $16, %0 \n\t" - "cmp %4, %0 \n\t" - " jb 1b \n\t" - : "+r" (i) - : "r"(src1), "r"(src2), "r"(dst), "r"((long)w-15) - ); - for(; iput_ ## postfix1 = put_ ## postfix2;\ - c->put_no_rnd_ ## postfix1 = put_no_rnd_ ## postfix2;\ - c->avg_ ## postfix1 = avg_ ## postfix2; - static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy, int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height){ const int w = 8; @@ -2515,8 +1513,8 @@ static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int o const int dxh = dxy*(h-1); const int dyw = dyx*(w-1); if( // non-constant fullpel offset (3% of blocks) - (ox^(ox+dxw) | ox^(ox+dxh) | ox^(ox+dxw+dxh) | - oy^(oy+dyw) | oy^(oy+dyh) | oy^(oy+dyw+dyh)) >> (16+shift) + ((ox^(ox+dxw)) | (ox^(ox+dxh)) | (ox^(ox+dxw+dxh)) | + (oy^(oy+dyw)) | (oy^(oy+dyh)) | (oy^(oy+dyw+dyh))) >> (16+shift) // uses more than 16 bits of subpel mv (only at huge resolution) || (dxx|dxy|dyx|dyy)&15 ) { @@ -2610,94 +1608,6 @@ static void gmc_mmx(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int o } } -#ifdef CONFIG_ENCODERS -static int try_8x8basis_mmx(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){ - long i=0; - - assert(FFABS(scale) < 256); - scale<<= 16 + 1 - BASIS_SHIFT + RECON_SHIFT; - - asm volatile( - "pcmpeqw %%mm6, %%mm6 \n\t" // -1w - "psrlw $15, %%mm6 \n\t" // 1w - "pxor %%mm7, %%mm7 \n\t" - "movd %4, %%mm5 \n\t" - "punpcklwd %%mm5, %%mm5 \n\t" - "punpcklwd %%mm5, %%mm5 \n\t" - "1: \n\t" - "movq (%1, %0), %%mm0 \n\t" - "movq 8(%1, %0), %%mm1 \n\t" - "pmulhw %%mm5, %%mm0 \n\t" - "pmulhw %%mm5, %%mm1 \n\t" - "paddw %%mm6, %%mm0 \n\t" - "paddw %%mm6, %%mm1 \n\t" - "psraw $1, %%mm0 \n\t" - "psraw $1, %%mm1 \n\t" - "paddw (%2, %0), %%mm0 \n\t" - "paddw 8(%2, %0), %%mm1 \n\t" - "psraw $6, %%mm0 \n\t" - "psraw $6, %%mm1 \n\t" - "pmullw (%3, %0), %%mm0 \n\t" - "pmullw 8(%3, %0), %%mm1 \n\t" - "pmaddwd %%mm0, %%mm0 \n\t" - "pmaddwd %%mm1, %%mm1 \n\t" - "paddd %%mm1, %%mm0 \n\t" - "psrld $4, %%mm0 \n\t" - "paddd %%mm0, %%mm7 \n\t" - "add $16, %0 \n\t" - "cmp $128, %0 \n\t" //FIXME optimize & bench - " jb 1b \n\t" - "movq %%mm7, %%mm6 \n\t" - "psrlq $32, %%mm7 \n\t" - "paddd %%mm6, %%mm7 \n\t" - "psrld $2, %%mm7 \n\t" - "movd %%mm7, %0 \n\t" - - : "+r" (i) - : "r"(basis), "r"(rem), "r"(weight), "g"(scale) - ); - return i; -} - -static void add_8x8basis_mmx(int16_t rem[64], int16_t basis[64], int scale){ - long i=0; - - if(FFABS(scale) < 256){ - scale<<= 16 + 1 - BASIS_SHIFT + RECON_SHIFT; - asm volatile( - "pcmpeqw %%mm6, %%mm6 \n\t" // -1w - "psrlw $15, %%mm6 \n\t" // 1w - "movd %3, %%mm5 \n\t" - "punpcklwd %%mm5, %%mm5 \n\t" - "punpcklwd %%mm5, %%mm5 \n\t" - "1: \n\t" - "movq (%1, %0), %%mm0 \n\t" - "movq 8(%1, %0), %%mm1 \n\t" - "pmulhw %%mm5, %%mm0 \n\t" - "pmulhw %%mm5, %%mm1 \n\t" - "paddw %%mm6, %%mm0 \n\t" - "paddw %%mm6, %%mm1 \n\t" - "psraw $1, %%mm0 \n\t" - "psraw $1, %%mm1 \n\t" - "paddw (%2, %0), %%mm0 \n\t" - "paddw 8(%2, %0), %%mm1 \n\t" - "movq %%mm0, (%2, %0) \n\t" - "movq %%mm1, 8(%2, %0) \n\t" - "add $16, %0 \n\t" - "cmp $128, %0 \n\t" //FIXME optimize & bench - " jb 1b \n\t" - - : "+r" (i) - : "r"(basis), "r"(rem), "g"(scale) - ); - }else{ - for(i=0; i<8*8; i++){ - rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT); - } - } -} -#endif /* CONFIG_ENCODERS */ - #define PREFETCH(name, op) \ static void name(void *mem, int stride, int h){\ const uint8_t *p= mem;\ @@ -2712,7 +1622,7 @@ PREFETCH(prefetch_3dnow, prefetch) #include "h264dsp_mmx.c" -/* AVS specific */ +/* CAVS specific */ void ff_cavsdsp_init_mmx2(DSPContext* c, AVCodecContext *avctx); void ff_put_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) { @@ -2728,14 +1638,17 @@ void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride) { avg_pixels16_mmx(dst, src, stride, 16); } +/* VC1 specific */ +void ff_vc1dsp_init_mmx(DSPContext* dsp, AVCodecContext *avctx); + +void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd) { + put_pixels8_mmx(dst, src, stride, 8); +} + /* external functions, from idct_mmx.c */ void ff_mmx_idct(DCTELEM *block); void ff_mmxext_idct(DCTELEM *block); -void ff_vp3_idct_sse2(int16_t *input_data); -void ff_vp3_idct_mmx(int16_t *data); -void ff_vp3_dsp_init_mmx(void); - /* XXX: those functions should be suppressed ASAP when all IDCTs are converted */ #ifdef CONFIG_GPL @@ -2760,26 +1673,6 @@ static void ff_libmpeg2mmx2_idct_add(uint8_t *dest, int line_size, DCTELEM *bloc add_pixels_clamped_mmx(block, dest, line_size); } #endif -static void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, DCTELEM *block) -{ - ff_vp3_idct_sse2(block); - put_signed_pixels_clamped_mmx(block, dest, line_size); -} -static void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, DCTELEM *block) -{ - ff_vp3_idct_sse2(block); - add_pixels_clamped_mmx(block, dest, line_size); -} -static void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, DCTELEM *block) -{ - ff_vp3_idct_mmx(block); - put_signed_pixels_clamped_mmx(block, dest, line_size); -} -static void ff_vp3_idct_add_mmx(uint8_t *dest, int line_size, DCTELEM *block) -{ - ff_vp3_idct_mmx(block); - add_pixels_clamped_mmx(block, dest, line_size); -} static void ff_idct_xvid_mmx_put(uint8_t *dest, int line_size, DCTELEM *block) { ff_idct_xvid_mmx (block); @@ -3069,16 +1962,14 @@ static void float_to_int16_sse(int16_t *dst, const float *src, int len){ asm volatile("emms"); } -#ifdef CONFIG_SNOW_DECODER -extern void ff_snow_horizontal_compose97i_sse2(DWTELEM *b, int width); -extern void ff_snow_horizontal_compose97i_mmx(DWTELEM *b, int width); -extern void ff_snow_vertical_compose97i_sse2(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width); -extern void ff_snow_vertical_compose97i_mmx(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width); +extern void ff_snow_horizontal_compose97i_sse2(IDWTELEM *b, int width); +extern void ff_snow_horizontal_compose97i_mmx(IDWTELEM *b, int width); +extern void ff_snow_vertical_compose97i_sse2(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width); +extern void ff_snow_vertical_compose97i_mmx(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width); extern void ff_snow_inner_add_yblock_sse2(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8); extern void ff_snow_inner_add_yblock_mmx(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8); -#endif void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) { @@ -3109,18 +2000,6 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) if (mm_flags & MM_MMX) { const int idct_algo= avctx->idct_algo; -#ifdef CONFIG_ENCODERS - const int dct_algo = avctx->dct_algo; - if(dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX){ - if(mm_flags & MM_SSE2){ - c->fdct = ff_fdct_sse2; - }else if(mm_flags & MM_MMXEXT){ - c->fdct = ff_fdct_mmx2; - }else{ - c->fdct = ff_fdct_mmx; - } - } -#endif //CONFIG_ENCODERS if(avctx->lowres==0){ if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SIMPLEMMX){ c->idct_put= ff_simple_idct_put_mmx; @@ -3140,7 +2019,8 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) } c->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM; #endif - }else if(idct_algo==FF_IDCT_VP3 && + }else if((ENABLE_VP3_DECODER || ENABLE_VP5_DECODER || ENABLE_VP6_DECODER) && + idct_algo==FF_IDCT_VP3 && avctx->codec->id!=CODEC_ID_THEORA && !(avctx->flags & CODEC_FLAG_BITEXACT)){ if(mm_flags & MM_SSE2){ @@ -3170,96 +2050,45 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) } } -#ifdef CONFIG_ENCODERS - c->get_pixels = get_pixels_mmx; - c->diff_pixels = diff_pixels_mmx; -#endif //CONFIG_ENCODERS c->put_pixels_clamped = put_pixels_clamped_mmx; c->put_signed_pixels_clamped = put_signed_pixels_clamped_mmx; c->add_pixels_clamped = add_pixels_clamped_mmx; c->clear_blocks = clear_blocks_mmx; -#ifdef CONFIG_ENCODERS - c->pix_sum = pix_sum16_mmx; -#endif //CONFIG_ENCODERS - - c->put_pixels_tab[0][0] = put_pixels16_mmx; - c->put_pixels_tab[0][1] = put_pixels16_x2_mmx; - c->put_pixels_tab[0][2] = put_pixels16_y2_mmx; - c->put_pixels_tab[0][3] = put_pixels16_xy2_mmx; - - c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mmx; - c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx; - c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx; - c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_mmx; - - c->avg_pixels_tab[0][0] = avg_pixels16_mmx; - c->avg_pixels_tab[0][1] = avg_pixels16_x2_mmx; - c->avg_pixels_tab[0][2] = avg_pixels16_y2_mmx; - c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx; - - c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_mmx; - c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x2_mmx; - c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y2_mmx; - c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy2_mmx; - - c->put_pixels_tab[1][0] = put_pixels8_mmx; - c->put_pixels_tab[1][1] = put_pixels8_x2_mmx; - c->put_pixels_tab[1][2] = put_pixels8_y2_mmx; - c->put_pixels_tab[1][3] = put_pixels8_xy2_mmx; - - c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mmx; - c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx; - c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx; - c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_mmx; - - c->avg_pixels_tab[1][0] = avg_pixels8_mmx; - c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx; - c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx; - c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx; - - c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels8_mmx; - c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x2_mmx; - c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y2_mmx; - c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy2_mmx; + +#define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \ + c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## SIZE ## _ ## CPU; \ + c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## SIZE ## _x2_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU + + SET_HPEL_FUNCS(put, 0, 16, mmx); + SET_HPEL_FUNCS(put_no_rnd, 0, 16, mmx); + SET_HPEL_FUNCS(avg, 0, 16, mmx); + SET_HPEL_FUNCS(avg_no_rnd, 0, 16, mmx); + SET_HPEL_FUNCS(put, 1, 8, mmx); + SET_HPEL_FUNCS(put_no_rnd, 1, 8, mmx); + SET_HPEL_FUNCS(avg, 1, 8, mmx); + SET_HPEL_FUNCS(avg_no_rnd, 1, 8, mmx); c->gmc= gmc_mmx; c->add_bytes= add_bytes_mmx; -#ifdef CONFIG_ENCODERS - c->diff_bytes= diff_bytes_mmx; - - c->hadamard8_diff[0]= hadamard8_diff16_mmx; - c->hadamard8_diff[1]= hadamard8_diff_mmx; + c->add_bytes_l2= add_bytes_l2_mmx; - c->pix_norm1 = pix_norm1_mmx; - c->sse[0] = (mm_flags & MM_SSE2) ? sse16_sse2 : sse16_mmx; - c->sse[1] = sse8_mmx; - c->vsad[4]= vsad_intra16_mmx; - - c->nsse[0] = nsse16_mmx; - c->nsse[1] = nsse8_mmx; - if(!(avctx->flags & CODEC_FLAG_BITEXACT)){ - c->vsad[0] = vsad16_mmx; + if (ENABLE_ANY_H263) { + c->h263_v_loop_filter= h263_v_loop_filter_mmx; + c->h263_h_loop_filter= h263_h_loop_filter_mmx; } - - if(!(avctx->flags & CODEC_FLAG_BITEXACT)){ - c->try_8x8basis= try_8x8basis_mmx; - } - c->add_8x8basis= add_8x8basis_mmx; - - c->ssd_int8_vs_int16 = ssd_int8_vs_int16_mmx; - -#endif //CONFIG_ENCODERS - - c->h263_v_loop_filter= h263_v_loop_filter_mmx; - c->h263_h_loop_filter= h263_h_loop_filter_mmx; - c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_mmx; + c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_mmx_rnd; c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_mmx; + c->put_no_rnd_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_mmx_nornd; c->h264_idct_dc_add= c->h264_idct_add= ff_h264_idct_add_mmx; c->h264_idct8_dc_add= c->h264_idct8_add= ff_h264_idct8_add_mmx; + if (mm_flags & MM_SSE2) + c->h264_idct8_add= ff_h264_idct8_add_sse2; if (mm_flags & MM_MMXEXT) { c->prefetch = prefetch_mmx2; @@ -3278,12 +2107,6 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2; c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2; -#ifdef CONFIG_ENCODERS - c->hadamard8_diff[0]= hadamard8_diff16_mmx2; - c->hadamard8_diff[1]= hadamard8_diff_mmx2; - c->vsad[4]= vsad_intra16_mmx2; -#endif //CONFIG_ENCODERS - c->h264_idct_dc_add= ff_h264_idct_dc_add_mmx2; c->h264_idct8_dc_add= ff_h264_idct8_dc_add_mmx2; @@ -3294,79 +2117,46 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx2; c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2; c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2; -#ifdef CONFIG_ENCODERS - c->vsad[0] = vsad16_mmx2; -#endif //CONFIG_ENCODERS } -#if 1 - SET_QPEL_FUNC(qpel_pixels_tab[0][ 0], qpel16_mc00_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 1], qpel16_mc10_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 2], qpel16_mc20_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 3], qpel16_mc30_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 4], qpel16_mc01_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 6], qpel16_mc21_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 8], qpel16_mc02_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[0][10], qpel16_mc22_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[0][12], qpel16_mc03_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[0][14], qpel16_mc23_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 0], qpel8_mc00_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 1], qpel8_mc10_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 2], qpel8_mc20_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 3], qpel8_mc30_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 4], qpel8_mc01_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 6], qpel8_mc21_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 8], qpel8_mc02_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[1][10], qpel8_mc22_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[1][12], qpel8_mc03_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[1][14], qpel8_mc23_mmx2) - SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_mmx2) -#endif - -//FIXME 3dnow too -#define dspfunc(PFX, IDX, NUM) \ - c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_mmx2; \ - c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_mmx2; \ - c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_mmx2; \ - c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_mmx2; \ - c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_mmx2; \ - c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_mmx2; \ - c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_mmx2; \ - c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_mmx2; \ - c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_mmx2; \ - c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_mmx2; \ - c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_mmx2; \ - c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_mmx2; \ - c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_mmx2; \ - c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_mmx2; \ - c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_mmx2; \ - c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_mmx2 - - dspfunc(put_h264_qpel, 0, 16); - dspfunc(put_h264_qpel, 1, 8); - dspfunc(put_h264_qpel, 2, 4); - dspfunc(avg_h264_qpel, 0, 16); - dspfunc(avg_h264_qpel, 1, 8); - dspfunc(avg_h264_qpel, 2, 4); - - dspfunc(put_2tap_qpel, 0, 16); - dspfunc(put_2tap_qpel, 1, 8); - dspfunc(avg_2tap_qpel, 0, 16); - dspfunc(avg_2tap_qpel, 1, 8); -#undef dspfunc - - c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_mmx2; +#define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU) \ + c->PFX ## _pixels_tab[IDX][ 0] = PFX ## SIZE ## _mc00_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][ 1] = PFX ## SIZE ## _mc10_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][ 2] = PFX ## SIZE ## _mc20_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][ 3] = PFX ## SIZE ## _mc30_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][ 4] = PFX ## SIZE ## _mc01_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][ 5] = PFX ## SIZE ## _mc11_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][ 6] = PFX ## SIZE ## _mc21_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][ 7] = PFX ## SIZE ## _mc31_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][ 8] = PFX ## SIZE ## _mc02_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][ 9] = PFX ## SIZE ## _mc12_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][10] = PFX ## SIZE ## _mc22_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][11] = PFX ## SIZE ## _mc32_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][12] = PFX ## SIZE ## _mc03_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][13] = PFX ## SIZE ## _mc13_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][14] = PFX ## SIZE ## _mc23_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][15] = PFX ## SIZE ## _mc33_ ## CPU + + SET_QPEL_FUNCS(put_qpel, 0, 16, mmx2); + SET_QPEL_FUNCS(put_qpel, 1, 8, mmx2); + SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmx2); + SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmx2); + SET_QPEL_FUNCS(avg_qpel, 0, 16, mmx2); + SET_QPEL_FUNCS(avg_qpel, 1, 8, mmx2); + + SET_QPEL_FUNCS(put_h264_qpel, 0, 16, mmx2); + SET_QPEL_FUNCS(put_h264_qpel, 1, 8, mmx2); + SET_QPEL_FUNCS(put_h264_qpel, 2, 4, mmx2); + SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, mmx2); + SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, mmx2); + SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, mmx2); + + SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, mmx2); + SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, mmx2); + SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, mmx2); + SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, mmx2); + + c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_mmx2_rnd; c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_mmx2; c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_mmx2; c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_mmx2; @@ -3396,13 +2186,13 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) c->biweight_h264_pixels_tab[6]= ff_h264_biweight_4x4_mmx2; c->biweight_h264_pixels_tab[7]= ff_h264_biweight_4x2_mmx2; -#ifdef CONFIG_CAVS_DECODER - ff_cavsdsp_init_mmx2(c, avctx); -#endif + if (ENABLE_CAVS_DECODER) + ff_cavsdsp_init_mmx2(c, avctx); + + if (ENABLE_VC1_DECODER || ENABLE_WMV3_DECODER) + ff_vc1dsp_init_mmx(c, avctx); -#ifdef CONFIG_ENCODERS - c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_mmx2; -#endif //CONFIG_ENCODERS + c->add_png_paeth_prediction= add_png_paeth_prediction_mmx2; } else if (mm_flags & MM_3DNOW) { c->prefetch = prefetch_3dnow; @@ -3429,82 +2219,90 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow; } - SET_QPEL_FUNC(qpel_pixels_tab[0][ 0], qpel16_mc00_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 1], qpel16_mc10_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 2], qpel16_mc20_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 3], qpel16_mc30_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 4], qpel16_mc01_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 5], qpel16_mc11_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 6], qpel16_mc21_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 7], qpel16_mc31_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 8], qpel16_mc02_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[0][ 9], qpel16_mc12_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[0][10], qpel16_mc22_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[0][12], qpel16_mc03_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[0][14], qpel16_mc23_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 0], qpel8_mc00_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 1], qpel8_mc10_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 2], qpel8_mc20_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 3], qpel8_mc30_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 4], qpel8_mc01_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 5], qpel8_mc11_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 6], qpel8_mc21_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 7], qpel8_mc31_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 8], qpel8_mc02_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[1][ 9], qpel8_mc12_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[1][10], qpel8_mc22_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[1][12], qpel8_mc03_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[1][14], qpel8_mc23_3dnow) - SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_3dnow) - -#define dspfunc(PFX, IDX, NUM) \ - c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_3dnow; \ - c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_3dnow; \ - c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_3dnow; \ - c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_3dnow; \ - c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_3dnow; \ - c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_3dnow; \ - c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_3dnow; \ - c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_3dnow; \ - c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_3dnow; \ - c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_3dnow; \ - c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_3dnow; \ - c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_3dnow; \ - c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_3dnow; \ - c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_3dnow; \ - c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_3dnow; \ - c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_3dnow - - dspfunc(put_h264_qpel, 0, 16); - dspfunc(put_h264_qpel, 1, 8); - dspfunc(put_h264_qpel, 2, 4); - dspfunc(avg_h264_qpel, 0, 16); - dspfunc(avg_h264_qpel, 1, 8); - dspfunc(avg_h264_qpel, 2, 4); - - dspfunc(put_2tap_qpel, 0, 16); - dspfunc(put_2tap_qpel, 1, 8); - dspfunc(avg_2tap_qpel, 0, 16); - dspfunc(avg_2tap_qpel, 1, 8); - - c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_3dnow; + SET_QPEL_FUNCS(put_qpel, 0, 16, 3dnow); + SET_QPEL_FUNCS(put_qpel, 1, 8, 3dnow); + SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, 3dnow); + SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, 3dnow); + SET_QPEL_FUNCS(avg_qpel, 0, 16, 3dnow); + SET_QPEL_FUNCS(avg_qpel, 1, 8, 3dnow); + + SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 3dnow); + SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 3dnow); + SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 3dnow); + SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 3dnow); + SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 3dnow); + SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 3dnow); + + SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, 3dnow); + SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, 3dnow); + SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, 3dnow); + SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, 3dnow); + + c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_3dnow_rnd; c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_3dnow; } -#ifdef CONFIG_SNOW_DECODER + +#define H264_QPEL_FUNCS(x, y, CPU)\ + c->put_h264_qpel_pixels_tab[0][x+y*4] = put_h264_qpel16_mc##x##y##_##CPU;\ + c->put_h264_qpel_pixels_tab[1][x+y*4] = put_h264_qpel8_mc##x##y##_##CPU;\ + c->avg_h264_qpel_pixels_tab[0][x+y*4] = avg_h264_qpel16_mc##x##y##_##CPU;\ + c->avg_h264_qpel_pixels_tab[1][x+y*4] = avg_h264_qpel8_mc##x##y##_##CPU; + if((mm_flags & MM_SSE2) && !(mm_flags & MM_3DNOW)){ + // these functions are slower than mmx on AMD, but faster on Intel +/* FIXME works in most codecs, but crashes svq1 due to unaligned chroma + c->put_pixels_tab[0][0] = put_pixels16_sse2; + c->avg_pixels_tab[0][0] = avg_pixels16_sse2; +*/ + H264_QPEL_FUNCS(0, 0, sse2); + } if(mm_flags & MM_SSE2){ + H264_QPEL_FUNCS(0, 1, sse2); + H264_QPEL_FUNCS(0, 2, sse2); + H264_QPEL_FUNCS(0, 3, sse2); + H264_QPEL_FUNCS(1, 1, sse2); + H264_QPEL_FUNCS(1, 2, sse2); + H264_QPEL_FUNCS(1, 3, sse2); + H264_QPEL_FUNCS(2, 1, sse2); + H264_QPEL_FUNCS(2, 2, sse2); + H264_QPEL_FUNCS(2, 3, sse2); + H264_QPEL_FUNCS(3, 1, sse2); + H264_QPEL_FUNCS(3, 2, sse2); + H264_QPEL_FUNCS(3, 3, sse2); + } +#ifdef HAVE_SSSE3 + if(mm_flags & MM_SSSE3){ + H264_QPEL_FUNCS(1, 0, ssse3); + H264_QPEL_FUNCS(1, 1, ssse3); + H264_QPEL_FUNCS(1, 2, ssse3); + H264_QPEL_FUNCS(1, 3, ssse3); + H264_QPEL_FUNCS(2, 0, ssse3); + H264_QPEL_FUNCS(2, 1, ssse3); + H264_QPEL_FUNCS(2, 2, ssse3); + H264_QPEL_FUNCS(2, 3, ssse3); + H264_QPEL_FUNCS(3, 0, ssse3); + H264_QPEL_FUNCS(3, 1, ssse3); + H264_QPEL_FUNCS(3, 2, ssse3); + H264_QPEL_FUNCS(3, 3, ssse3); + c->add_png_paeth_prediction= add_png_paeth_prediction_ssse3; + } +#endif + +#ifdef CONFIG_SNOW_DECODER + if(mm_flags & MM_SSE2 & 0){ c->horizontal_compose97i = ff_snow_horizontal_compose97i_sse2; +#ifdef HAVE_7REGS c->vertical_compose97i = ff_snow_vertical_compose97i_sse2; +#endif c->inner_add_yblock = ff_snow_inner_add_yblock_sse2; } else{ + if(mm_flags & MM_MMXEXT){ c->horizontal_compose97i = ff_snow_horizontal_compose97i_mmx; +#ifdef HAVE_7REGS c->vertical_compose97i = ff_snow_vertical_compose97i_mmx; +#endif + } c->inner_add_yblock = ff_snow_inner_add_yblock_mmx; } #endif @@ -3528,9 +2326,9 @@ void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx) c->vector_fmul_add_add = vector_fmul_add_add_3dnow; // faster than sse } -#ifdef CONFIG_ENCODERS - dsputil_init_pix_mmx(c, avctx); -#endif //CONFIG_ENCODERS + if (ENABLE_ENCODERS) + dsputilenc_init_mmx(c, avctx); + #if 0 // for speed testing get_pixels = just_return; diff --git a/contrib/ffmpeg/libavcodec/i386/dsputil_mmx.h b/contrib/ffmpeg/libavcodec/i386/dsputil_mmx.h new file mode 100644 index 000000000..6f0d5ef19 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/i386/dsputil_mmx.h @@ -0,0 +1,123 @@ +/* + * MMX optimized DSP utils + * Copyright (c) 2007 Aurelien Jacobs + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_DSPUTIL_MMX_H +#define FFMPEG_DSPUTIL_MMX_H + +#include +#include "dsputil.h" + +typedef struct { uint64_t a, b; } xmm_t; + +extern const uint64_t ff_bone; +extern const uint64_t ff_wtwo; + +extern const uint64_t ff_pdw_80000000[2]; + +extern const uint64_t ff_pw_3; +extern const uint64_t ff_pw_4; +extern const xmm_t ff_pw_5; +extern const uint64_t ff_pw_8; +extern const uint64_t ff_pw_15; +extern const xmm_t ff_pw_16; +extern const uint64_t ff_pw_20; +extern const xmm_t ff_pw_32; +extern const uint64_t ff_pw_42; +extern const uint64_t ff_pw_64; +extern const uint64_t ff_pw_96; +extern const uint64_t ff_pw_128; +extern const uint64_t ff_pw_255; + +extern const uint64_t ff_pb_1; +extern const uint64_t ff_pb_3; +extern const uint64_t ff_pb_7; +extern const uint64_t ff_pb_3F; +extern const uint64_t ff_pb_A1; +extern const uint64_t ff_pb_FC; + +extern const double ff_pd_1[2]; +extern const double ff_pd_2[2]; + +/* in/out: mma=mma+mmb, mmb=mmb-mma */ +#define SUMSUB_BA( a, b ) \ + "paddw "#b", "#a" \n\t"\ + "paddw "#b", "#b" \n\t"\ + "psubw "#a", "#b" \n\t" + +#define SBUTTERFLY(a,b,t,n,m)\ + "mov" #m " " #a ", " #t " \n\t" /* abcd */\ + "punpckl" #n " " #b ", " #a " \n\t" /* aebf */\ + "punpckh" #n " " #b ", " #t " \n\t" /* cgdh */\ + +#define TRANSPOSE4(a,b,c,d,t)\ + SBUTTERFLY(a,b,t,wd,q) /* a=aebf t=cgdh */\ + SBUTTERFLY(c,d,b,wd,q) /* c=imjn b=kolp */\ + SBUTTERFLY(a,c,d,dq,q) /* a=aeim d=bfjn */\ + SBUTTERFLY(t,b,c,dq,q) /* t=cgko c=dhlp */ + +#ifdef ARCH_X86_64 +// permutes 01234567 -> 05736421 +#define TRANSPOSE8(a,b,c,d,e,f,g,h,t)\ + SBUTTERFLY(a,b,%%xmm8,wd,dqa)\ + SBUTTERFLY(c,d,b,wd,dqa)\ + SBUTTERFLY(e,f,d,wd,dqa)\ + SBUTTERFLY(g,h,f,wd,dqa)\ + SBUTTERFLY(a,c,h,dq,dqa)\ + SBUTTERFLY(%%xmm8,b,c,dq,dqa)\ + SBUTTERFLY(e,g,b,dq,dqa)\ + SBUTTERFLY(d,f,g,dq,dqa)\ + SBUTTERFLY(a,e,f,qdq,dqa)\ + SBUTTERFLY(%%xmm8,d,e,qdq,dqa)\ + SBUTTERFLY(h,b,d,qdq,dqa)\ + SBUTTERFLY(c,g,b,qdq,dqa)\ + "movdqa %%xmm8, "#g" \n\t" +#else +#define TRANSPOSE8(a,b,c,d,e,f,g,h,t)\ + "movdqa "#h", "#t" \n\t"\ + SBUTTERFLY(a,b,h,wd,dqa)\ + "movdqa "#h", 16"#t" \n\t"\ + "movdqa "#t", "#h" \n\t"\ + SBUTTERFLY(c,d,b,wd,dqa)\ + SBUTTERFLY(e,f,d,wd,dqa)\ + SBUTTERFLY(g,h,f,wd,dqa)\ + SBUTTERFLY(a,c,h,dq,dqa)\ + "movdqa "#h", "#t" \n\t"\ + "movdqa 16"#t", "#h" \n\t"\ + SBUTTERFLY(h,b,c,dq,dqa)\ + SBUTTERFLY(e,g,b,dq,dqa)\ + SBUTTERFLY(d,f,g,dq,dqa)\ + SBUTTERFLY(a,e,f,qdq,dqa)\ + SBUTTERFLY(h,d,e,qdq,dqa)\ + "movdqa "#h", 16"#t" \n\t"\ + "movdqa "#t", "#h" \n\t"\ + SBUTTERFLY(h,b,d,qdq,dqa)\ + SBUTTERFLY(c,g,b,qdq,dqa)\ + "movdqa 16"#t", "#g" \n\t" +#endif + +#define MOVQ_WONE(regd) \ + asm volatile ( \ + "pcmpeqd %%" #regd ", %%" #regd " \n\t" \ + "psrlw $15, %%" #regd ::) + +void dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx); + +#endif /* FFMPEG_DSPUTIL_MMX_H */ diff --git a/contrib/ffmpeg/libavcodec/i386/dsputil_mmx_avg.h b/contrib/ffmpeg/libavcodec/i386/dsputil_mmx_avg.h index b365cea57..c6c7aaa62 100644 --- a/contrib/ffmpeg/libavcodec/i386/dsputil_mmx_avg.h +++ b/contrib/ffmpeg/libavcodec/i386/dsputil_mmx_avg.h @@ -3,6 +3,10 @@ * Copyright (c) 2000, 2001 Fabrice Bellard. * Copyright (c) 2002-2004 Michael Niedermayer * + * MMX optimization by Nick Kurshev + * mostly rewritten by Michael Niedermayer + * and improved by Zdenek Kabelac + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -18,18 +22,18 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * MMX optimization by Nick Kurshev - * mostly rewritten by Michael Niedermayer - * and improved by Zdenek Kabelac */ +/* This header intentionally has no multiple inclusion guards. It is meant to + * be included multiple times and generates different code depending on the + * value of certain #defines. */ + /* XXX: we use explicit registers to avoid a gcc 2.95.2 register asm clobber bug - now it will work with 2.95.2 and also with -fPIC */ static void DEF(put_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h) { - __asm __volatile( + asm volatile( "lea (%3, %3), %%"REG_a" \n\t" "1: \n\t" "movq (%1), %%mm0 \n\t" @@ -57,7 +61,7 @@ static void DEF(put_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_ static void DEF(put_pixels4_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h) { - __asm __volatile( + asm volatile( "testl $1, %0 \n\t" " jz 1f \n\t" "movd (%1), %%mm0 \n\t" @@ -96,7 +100,7 @@ static void DEF(put_pixels4_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int "add $16, %2 \n\t" "subl $4, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used +#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -108,7 +112,7 @@ static void DEF(put_pixels4_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int static void DEF(put_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h) { - __asm __volatile( + asm volatile( "testl $1, %0 \n\t" " jz 1f \n\t" "movq (%1), %%mm0 \n\t" @@ -143,7 +147,7 @@ static void DEF(put_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int "add $32, %2 \n\t" "subl $4, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used +#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -158,7 +162,7 @@ static void DEF(put_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int static void DEF(put_no_rnd_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h) { - __asm __volatile( + asm volatile( "pcmpeqb %%mm6, %%mm6 \n\t" "testl $1, %0 \n\t" " jz 1f \n\t" @@ -213,7 +217,7 @@ static void DEF(put_no_rnd_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src "add $32, %2 \n\t" "subl $4, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used +#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -228,7 +232,7 @@ static void DEF(put_no_rnd_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src static void DEF(avg_pixels4_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h) { - __asm __volatile( + asm volatile( "testl $1, %0 \n\t" " jz 1f \n\t" "movd (%1), %%mm0 \n\t" @@ -268,7 +272,7 @@ static void DEF(avg_pixels4_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int "add $16, %2 \n\t" "subl $4, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used +#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -280,7 +284,7 @@ static void DEF(avg_pixels4_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int static void DEF(avg_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h) { - __asm __volatile( + asm volatile( "testl $1, %0 \n\t" " jz 1f \n\t" "movq (%1), %%mm0 \n\t" @@ -320,7 +324,7 @@ static void DEF(avg_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int "add $32, %2 \n\t" "subl $4, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used +#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -335,7 +339,7 @@ static void DEF(avg_pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int static void DEF(put_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h) { - __asm __volatile( + asm volatile( "lea (%3, %3), %%"REG_a" \n\t" "1: \n\t" "movq (%1), %%mm0 \n\t" @@ -375,7 +379,7 @@ static void DEF(put_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line static void DEF(put_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h) { - __asm __volatile( + asm volatile( "testl $1, %0 \n\t" " jz 1f \n\t" "movq (%1), %%mm0 \n\t" @@ -408,7 +412,7 @@ static void DEF(put_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int "add $32, %2 \n\t" "subl $2, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used +#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -423,7 +427,7 @@ static void DEF(put_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int static void DEF(avg_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h) { - __asm __volatile( + asm volatile( "testl $1, %0 \n\t" " jz 1f \n\t" "movq (%1), %%mm0 \n\t" @@ -462,7 +466,7 @@ static void DEF(avg_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int "add $32, %2 \n\t" "subl $2, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used +#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -477,7 +481,7 @@ static void DEF(avg_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int static void DEF(put_no_rnd_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h) { - __asm __volatile( + asm volatile( "pcmpeqb %%mm6, %%mm6 \n\t" "testl $1, %0 \n\t" " jz 1f \n\t" @@ -535,7 +539,7 @@ static void DEF(put_no_rnd_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *sr "add $32, %2 \n\t" "subl $2, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used +#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -552,7 +556,7 @@ static void DEF(put_no_rnd_pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *sr static void DEF(put_no_rnd_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h) { MOVQ_BONE(mm6); - __asm __volatile( + asm volatile( "lea (%3, %3), %%"REG_a" \n\t" "1: \n\t" "movq (%1), %%mm0 \n\t" @@ -588,7 +592,7 @@ static void DEF(put_no_rnd_pixels8_x2)(uint8_t *block, const uint8_t *pixels, in static void DEF(put_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h) { - __asm __volatile( + asm volatile( "lea (%3, %3), %%"REG_a" \n\t" "movq (%1), %%mm0 \n\t" "sub %3, %2 \n\t" @@ -620,7 +624,7 @@ static void DEF(put_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_ static void DEF(put_no_rnd_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h) { MOVQ_BONE(mm6); - __asm __volatile( + asm volatile( "lea (%3, %3), %%"REG_a" \n\t" "movq (%1), %%mm0 \n\t" "sub %3, %2 \n\t" @@ -652,7 +656,7 @@ static void DEF(put_no_rnd_pixels8_y2)(uint8_t *block, const uint8_t *pixels, in static void DEF(avg_pixels8)(uint8_t *block, const uint8_t *pixels, int line_size, int h) { - __asm __volatile( + asm volatile( "lea (%3, %3), %%"REG_a" \n\t" "1: \n\t" "movq (%2), %%mm0 \n\t" @@ -680,7 +684,7 @@ static void DEF(avg_pixels8)(uint8_t *block, const uint8_t *pixels, int line_siz static void DEF(avg_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h) { - __asm __volatile( + asm volatile( "lea (%3, %3), %%"REG_a" \n\t" "1: \n\t" "movq (%1), %%mm0 \n\t" @@ -712,7 +716,7 @@ static void DEF(avg_pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_ static void DEF(avg_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h) { - __asm __volatile( + asm volatile( "lea (%3, %3), %%"REG_a" \n\t" "movq (%1), %%mm0 \n\t" "sub %3, %2 \n\t" @@ -748,11 +752,12 @@ static void DEF(avg_pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_ :"%"REG_a, "memory"); } -// Note this is not correctly rounded, but this function is only used for b frames so it doesnt matter +/* Note this is not correctly rounded, but this function is only + * used for B-frames so it does not matter. */ static void DEF(avg_pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h) { MOVQ_BONE(mm6); - __asm __volatile( + asm volatile( "lea (%3, %3), %%"REG_a" \n\t" "movq (%1), %%mm0 \n\t" PAVGB" 1(%1), %%mm0 \n\t" @@ -790,6 +795,31 @@ static void DEF(avg_pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line :"%"REG_a, "memory"); } +static void DEF(avg_pixels4)(uint8_t *block, const uint8_t *pixels, int line_size, int h) +{ + do { + asm volatile( + "movd (%1), %%mm0 \n\t" + "movd (%1, %2), %%mm1 \n\t" + "movd (%1, %2, 2), %%mm2 \n\t" + "movd (%1, %3), %%mm3 \n\t" + PAVGB" (%0), %%mm0 \n\t" + PAVGB" (%0, %2), %%mm1 \n\t" + PAVGB" (%0, %2, 2), %%mm2 \n\t" + PAVGB" (%0, %3), %%mm3 \n\t" + "movd %%mm0, (%1) \n\t" + "movd %%mm1, (%1, %2) \n\t" + "movd %%mm2, (%1, %2, 2) \n\t" + "movd %%mm3, (%1, %3) \n\t" + ::"S"(pixels), "D"(block), + "r" ((long)line_size), "r"(3L*line_size) + :"memory"); + block += 4*line_size; + pixels += 4*line_size; + h -= 4; + } while(h > 0); +} + //FIXME the following could be optimized too ... static void DEF(put_no_rnd_pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){ DEF(put_no_rnd_pixels8_x2)(block , pixels , line_size, h); diff --git a/contrib/ffmpeg/libavcodec/i386/dsputil_mmx_qns.h b/contrib/ffmpeg/libavcodec/i386/dsputil_mmx_qns.h new file mode 100644 index 000000000..f01f0b08b --- /dev/null +++ b/contrib/ffmpeg/libavcodec/i386/dsputil_mmx_qns.h @@ -0,0 +1,105 @@ +/* + * DSP utils : QNS functions are compiled 3 times for mmx/3dnow/ssse3 + * Copyright (c) 2004 Michael Niedermayer + * + * MMX optimization by Michael Niedermayer + * 3DNow! and SSSE3 optimization by Zuxy Meng + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* This header intentionally has no multiple inclusion guards. It is meant to + * be included multiple times and generates different code depending on the + * value of certain #defines. */ + +#define MAX_ABS (512 >> (SCALE_OFFSET>0 ? SCALE_OFFSET : 0)) + +static int DEF(try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale) +{ + long i=0; + + assert(FFABS(scale) < MAX_ABS); + scale<<= 16 + SCALE_OFFSET - BASIS_SHIFT + RECON_SHIFT; + + SET_RND(mm6); + asm volatile( + "pxor %%mm7, %%mm7 \n\t" + "movd %4, %%mm5 \n\t" + "punpcklwd %%mm5, %%mm5 \n\t" + "punpcklwd %%mm5, %%mm5 \n\t" + ASMALIGN(4) + "1: \n\t" + "movq (%1, %0), %%mm0 \n\t" + "movq 8(%1, %0), %%mm1 \n\t" + PMULHRW(%%mm0, %%mm1, %%mm5, %%mm6) + "paddw (%2, %0), %%mm0 \n\t" + "paddw 8(%2, %0), %%mm1 \n\t" + "psraw $6, %%mm0 \n\t" + "psraw $6, %%mm1 \n\t" + "pmullw (%3, %0), %%mm0 \n\t" + "pmullw 8(%3, %0), %%mm1 \n\t" + "pmaddwd %%mm0, %%mm0 \n\t" + "pmaddwd %%mm1, %%mm1 \n\t" + "paddd %%mm1, %%mm0 \n\t" + "psrld $4, %%mm0 \n\t" + "paddd %%mm0, %%mm7 \n\t" + "add $16, %0 \n\t" + "cmp $128, %0 \n\t" //FIXME optimize & bench + " jb 1b \n\t" + PHADDD(%%mm7, %%mm6) + "psrld $2, %%mm7 \n\t" + "movd %%mm7, %0 \n\t" + + : "+r" (i) + : "r"(basis), "r"(rem), "r"(weight), "g"(scale) + ); + return i; +} + +static void DEF(add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale) +{ + long i=0; + + if(FFABS(scale) < MAX_ABS){ + scale<<= 16 + SCALE_OFFSET - BASIS_SHIFT + RECON_SHIFT; + SET_RND(mm6); + asm volatile( + "movd %3, %%mm5 \n\t" + "punpcklwd %%mm5, %%mm5 \n\t" + "punpcklwd %%mm5, %%mm5 \n\t" + ASMALIGN(4) + "1: \n\t" + "movq (%1, %0), %%mm0 \n\t" + "movq 8(%1, %0), %%mm1 \n\t" + PMULHRW(%%mm0, %%mm1, %%mm5, %%mm6) + "paddw (%2, %0), %%mm0 \n\t" + "paddw 8(%2, %0), %%mm1 \n\t" + "movq %%mm0, (%2, %0) \n\t" + "movq %%mm1, 8(%2, %0) \n\t" + "add $16, %0 \n\t" + "cmp $128, %0 \n\t" // FIXME optimize & bench + " jb 1b \n\t" + + : "+r" (i) + : "r"(basis), "r"(rem), "g"(scale) + ); + }else{ + for(i=0; i<8*8; i++){ + rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT); + } + } +} diff --git a/contrib/ffmpeg/libavcodec/i386/dsputil_mmx_rnd.h b/contrib/ffmpeg/libavcodec/i386/dsputil_mmx_rnd.h index f53b34662..33c8a2692 100644 --- a/contrib/ffmpeg/libavcodec/i386/dsputil_mmx_rnd.h +++ b/contrib/ffmpeg/libavcodec/i386/dsputil_mmx_rnd.h @@ -3,6 +3,10 @@ * Copyright (c) 2000, 2001 Fabrice Bellard. * Copyright (c) 2003-2004 Michael Niedermayer * + * MMX optimization by Nick Kurshev + * mostly rewritten by Michael Niedermayer + * and improved by Zdenek Kabelac + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -18,17 +22,17 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * MMX optimization by Nick Kurshev - * mostly rewritten by Michael Niedermayer - * and improved by Zdenek Kabelac */ +/* This header intentionally has no multiple inclusion guards. It is meant to + * be included multiple times and generates different code depending on the + * value of certain #defines. */ + // put_pixels static void DEF(put, pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h) { MOVQ_BFE(mm6); - __asm __volatile( + asm volatile( "lea (%3, %3), %%"REG_a" \n\t" ASMALIGN(3) "1: \n\t" @@ -57,10 +61,10 @@ static void DEF(put, pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line :REG_a, "memory"); } -static void attribute_unused DEF(put, pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h) +static void av_unused DEF(put, pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h) { MOVQ_BFE(mm6); - __asm __volatile( + asm volatile( "testl $1, %0 \n\t" " jz 1f \n\t" "movq (%1), %%mm0 \n\t" @@ -98,7 +102,7 @@ static void attribute_unused DEF(put, pixels8_l2)(uint8_t *dst, uint8_t *src1, u "add %5, %3 \n\t" "subl $4, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used +#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -110,7 +114,7 @@ static void attribute_unused DEF(put, pixels8_l2)(uint8_t *dst, uint8_t *src1, u static void DEF(put, pixels16_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h) { MOVQ_BFE(mm6); - __asm __volatile( + asm volatile( "lea (%3, %3), %%"REG_a" \n\t" ASMALIGN(3) "1: \n\t" @@ -153,10 +157,10 @@ static void DEF(put, pixels16_x2)(uint8_t *block, const uint8_t *pixels, int lin :REG_a, "memory"); } -static void attribute_unused DEF(put, pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h) +static void av_unused DEF(put, pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h) { MOVQ_BFE(mm6); - __asm __volatile( + asm volatile( "testl $1, %0 \n\t" " jz 1f \n\t" "movq (%1), %%mm0 \n\t" @@ -193,7 +197,7 @@ static void attribute_unused DEF(put, pixels16_l2)(uint8_t *dst, uint8_t *src1, "add $32, %2 \n\t" "subl $2, %0 \n\t" "jnz 1b \n\t" -#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cant be used +#ifdef PIC //Note "+bm" and "+mb" are buggy too (with gcc 3.2.2 at least) and cannot be used :"+m"(h), "+a"(src1), "+c"(src2), "+d"(dst) #else :"+b"(h), "+a"(src1), "+c"(src2), "+d"(dst) @@ -205,7 +209,7 @@ static void attribute_unused DEF(put, pixels16_l2)(uint8_t *dst, uint8_t *src1, static void DEF(put, pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h) { MOVQ_BFE(mm6); - __asm __volatile( + asm volatile( "lea (%3, %3), %%"REG_a" \n\t" "movq (%1), %%mm0 \n\t" ASMALIGN(3) @@ -235,7 +239,7 @@ static void DEF(put, pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int lin { MOVQ_ZERO(mm7); SET_RND(mm6); // =2 for rnd and =1 for no_rnd version - __asm __volatile( + asm volatile( "movq (%1), %%mm0 \n\t" "movq 1(%1), %%mm4 \n\t" "movq %%mm0, %%mm1 \n\t" @@ -298,12 +302,12 @@ static void DEF(put, pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int lin } // avg_pixels -static void attribute_unused DEF(avg, pixels4)(uint8_t *block, const uint8_t *pixels, int line_size, int h) +static void av_unused DEF(avg, pixels4)(uint8_t *block, const uint8_t *pixels, int line_size, int h) { MOVQ_BFE(mm6); JUMPALIGN(); do { - __asm __volatile( + asm volatile( "movd %0, %%mm0 \n\t" "movd %1, %%mm1 \n\t" PAVGB(%%mm0, %%mm1, %%mm2, %%mm6) @@ -323,7 +327,7 @@ static void DEF(avg, pixels8)(uint8_t *block, const uint8_t *pixels, int line_si MOVQ_BFE(mm6); JUMPALIGN(); do { - __asm __volatile( + asm volatile( "movq %0, %%mm0 \n\t" "movq %1, %%mm1 \n\t" PAVGB(%%mm0, %%mm1, %%mm2, %%mm6) @@ -342,7 +346,7 @@ static void DEF(avg, pixels16)(uint8_t *block, const uint8_t *pixels, int line_s MOVQ_BFE(mm6); JUMPALIGN(); do { - __asm __volatile( + asm volatile( "movq %0, %%mm0 \n\t" "movq %1, %%mm1 \n\t" PAVGB(%%mm0, %%mm1, %%mm2, %%mm6) @@ -365,7 +369,7 @@ static void DEF(avg, pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line MOVQ_BFE(mm6); JUMPALIGN(); do { - __asm __volatile( + asm volatile( "movq %1, %%mm0 \n\t" "movq 1%1, %%mm1 \n\t" "movq %0, %%mm3 \n\t" @@ -380,12 +384,12 @@ static void DEF(avg, pixels8_x2)(uint8_t *block, const uint8_t *pixels, int line } while (--h); } -static __attribute__((unused)) void DEF(avg, pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h) +static av_unused void DEF(avg, pixels8_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h) { MOVQ_BFE(mm6); JUMPALIGN(); do { - __asm __volatile( + asm volatile( "movq %1, %%mm0 \n\t" "movq %2, %%mm1 \n\t" "movq %0, %%mm3 \n\t" @@ -406,7 +410,7 @@ static void DEF(avg, pixels16_x2)(uint8_t *block, const uint8_t *pixels, int lin MOVQ_BFE(mm6); JUMPALIGN(); do { - __asm __volatile( + asm volatile( "movq %1, %%mm0 \n\t" "movq 1%1, %%mm1 \n\t" "movq %0, %%mm3 \n\t" @@ -427,12 +431,12 @@ static void DEF(avg, pixels16_x2)(uint8_t *block, const uint8_t *pixels, int lin } while (--h); } -static __attribute__((unused)) void DEF(avg, pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h) +static av_unused void DEF(avg, pixels16_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int dstStride, int src1Stride, int h) { MOVQ_BFE(mm6); JUMPALIGN(); do { - __asm __volatile( + asm volatile( "movq %1, %%mm0 \n\t" "movq %2, %%mm1 \n\t" "movq %0, %%mm3 \n\t" @@ -457,7 +461,7 @@ static __attribute__((unused)) void DEF(avg, pixels16_l2)(uint8_t *dst, uint8_t static void DEF(avg, pixels8_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h) { MOVQ_BFE(mm6); - __asm __volatile( + asm volatile( "lea (%3, %3), %%"REG_a" \n\t" "movq (%1), %%mm0 \n\t" ASMALIGN(3) @@ -498,7 +502,7 @@ static void DEF(avg, pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int lin { MOVQ_ZERO(mm7); SET_RND(mm6); // =2 for rnd and =1 for no_rnd version - __asm __volatile( + asm volatile( "movq (%1), %%mm0 \n\t" "movq 1(%1), %%mm4 \n\t" "movq %%mm0, %%mm1 \n\t" @@ -588,5 +592,3 @@ static void DEF(avg, pixels16_xy2)(uint8_t *block, const uint8_t *pixels, int li DEF(avg, pixels8_xy2)(block , pixels , line_size, h); DEF(avg, pixels8_xy2)(block+8, pixels+8, line_size, h); } - - diff --git a/contrib/ffmpeg/libavcodec/i386/dsputilenc_mmx.c b/contrib/ffmpeg/libavcodec/i386/dsputilenc_mmx.c new file mode 100644 index 000000000..c9fb67045 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/i386/dsputilenc_mmx.c @@ -0,0 +1,1422 @@ +/* + * MMX optimized DSP utils + * Copyright (c) 2000, 2001 Fabrice Bellard. + * Copyright (c) 2002-2004 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * MMX optimization by Nick Kurshev + */ + +#include "dsputil.h" +#include "dsputil_mmx.h" +#include "mpegvideo.h" +#include "x86_cpu.h" + + +static void get_pixels_mmx(DCTELEM *block, const uint8_t *pixels, int line_size) +{ + asm volatile( + "mov $-128, %%"REG_a" \n\t" + "pxor %%mm7, %%mm7 \n\t" + ASMALIGN(4) + "1: \n\t" + "movq (%0), %%mm0 \n\t" + "movq (%0, %2), %%mm2 \n\t" + "movq %%mm0, %%mm1 \n\t" + "movq %%mm2, %%mm3 \n\t" + "punpcklbw %%mm7, %%mm0 \n\t" + "punpckhbw %%mm7, %%mm1 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" + "punpckhbw %%mm7, %%mm3 \n\t" + "movq %%mm0, (%1, %%"REG_a") \n\t" + "movq %%mm1, 8(%1, %%"REG_a") \n\t" + "movq %%mm2, 16(%1, %%"REG_a") \n\t" + "movq %%mm3, 24(%1, %%"REG_a") \n\t" + "add %3, %0 \n\t" + "add $32, %%"REG_a" \n\t" + "js 1b \n\t" + : "+r" (pixels) + : "r" (block+64), "r" ((long)line_size), "r" ((long)line_size*2) + : "%"REG_a + ); +} + +static inline void diff_pixels_mmx(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride) +{ + asm volatile( + "pxor %%mm7, %%mm7 \n\t" + "mov $-128, %%"REG_a" \n\t" + ASMALIGN(4) + "1: \n\t" + "movq (%0), %%mm0 \n\t" + "movq (%1), %%mm2 \n\t" + "movq %%mm0, %%mm1 \n\t" + "movq %%mm2, %%mm3 \n\t" + "punpcklbw %%mm7, %%mm0 \n\t" + "punpckhbw %%mm7, %%mm1 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" + "punpckhbw %%mm7, %%mm3 \n\t" + "psubw %%mm2, %%mm0 \n\t" + "psubw %%mm3, %%mm1 \n\t" + "movq %%mm0, (%2, %%"REG_a") \n\t" + "movq %%mm1, 8(%2, %%"REG_a") \n\t" + "add %3, %0 \n\t" + "add %3, %1 \n\t" + "add $16, %%"REG_a" \n\t" + "jnz 1b \n\t" + : "+r" (s1), "+r" (s2) + : "r" (block+64), "r" ((long)stride) + : "%"REG_a + ); +} + +static int pix_sum16_mmx(uint8_t * pix, int line_size){ + const int h=16; + int sum; + long index= -line_size*h; + + asm volatile( + "pxor %%mm7, %%mm7 \n\t" + "pxor %%mm6, %%mm6 \n\t" + "1: \n\t" + "movq (%2, %1), %%mm0 \n\t" + "movq (%2, %1), %%mm1 \n\t" + "movq 8(%2, %1), %%mm2 \n\t" + "movq 8(%2, %1), %%mm3 \n\t" + "punpcklbw %%mm7, %%mm0 \n\t" + "punpckhbw %%mm7, %%mm1 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" + "punpckhbw %%mm7, %%mm3 \n\t" + "paddw %%mm0, %%mm1 \n\t" + "paddw %%mm2, %%mm3 \n\t" + "paddw %%mm1, %%mm3 \n\t" + "paddw %%mm3, %%mm6 \n\t" + "add %3, %1 \n\t" + " js 1b \n\t" + "movq %%mm6, %%mm5 \n\t" + "psrlq $32, %%mm6 \n\t" + "paddw %%mm5, %%mm6 \n\t" + "movq %%mm6, %%mm5 \n\t" + "psrlq $16, %%mm6 \n\t" + "paddw %%mm5, %%mm6 \n\t" + "movd %%mm6, %0 \n\t" + "andl $0xFFFF, %0 \n\t" + : "=&r" (sum), "+r" (index) + : "r" (pix - index), "r" ((long)line_size) + ); + + return sum; +} + +static int pix_norm1_mmx(uint8_t *pix, int line_size) { + int tmp; + asm volatile ( + "movl $16,%%ecx\n" + "pxor %%mm0,%%mm0\n" + "pxor %%mm7,%%mm7\n" + "1:\n" + "movq (%0),%%mm2\n" /* mm2 = pix[0-7] */ + "movq 8(%0),%%mm3\n" /* mm3 = pix[8-15] */ + + "movq %%mm2,%%mm1\n" /* mm1 = mm2 = pix[0-7] */ + + "punpckhbw %%mm0,%%mm1\n" /* mm1 = [pix4-7] */ + "punpcklbw %%mm0,%%mm2\n" /* mm2 = [pix0-3] */ + + "movq %%mm3,%%mm4\n" /* mm4 = mm3 = pix[8-15] */ + "punpckhbw %%mm0,%%mm3\n" /* mm3 = [pix12-15] */ + "punpcklbw %%mm0,%%mm4\n" /* mm4 = [pix8-11] */ + + "pmaddwd %%mm1,%%mm1\n" /* mm1 = (pix0^2+pix1^2,pix2^2+pix3^2) */ + "pmaddwd %%mm2,%%mm2\n" /* mm2 = (pix4^2+pix5^2,pix6^2+pix7^2) */ + + "pmaddwd %%mm3,%%mm3\n" + "pmaddwd %%mm4,%%mm4\n" + + "paddd %%mm1,%%mm2\n" /* mm2 = (pix0^2+pix1^2+pix4^2+pix5^2, + pix2^2+pix3^2+pix6^2+pix7^2) */ + "paddd %%mm3,%%mm4\n" + "paddd %%mm2,%%mm7\n" + + "add %2, %0\n" + "paddd %%mm4,%%mm7\n" + "dec %%ecx\n" + "jnz 1b\n" + + "movq %%mm7,%%mm1\n" + "psrlq $32, %%mm7\n" /* shift hi dword to lo */ + "paddd %%mm7,%%mm1\n" + "movd %%mm1,%1\n" + : "+r" (pix), "=r"(tmp) : "r" ((long)line_size) : "%ecx" ); + return tmp; +} + +static int sse8_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) { + int tmp; + asm volatile ( + "movl %4,%%ecx\n" + "shr $1,%%ecx\n" + "pxor %%mm0,%%mm0\n" /* mm0 = 0 */ + "pxor %%mm7,%%mm7\n" /* mm7 holds the sum */ + "1:\n" + "movq (%0),%%mm1\n" /* mm1 = pix1[0][0-7] */ + "movq (%1),%%mm2\n" /* mm2 = pix2[0][0-7] */ + "movq (%0,%3),%%mm3\n" /* mm3 = pix1[1][0-7] */ + "movq (%1,%3),%%mm4\n" /* mm4 = pix2[1][0-7] */ + + /* todo: mm1-mm2, mm3-mm4 */ + /* algo: subtract mm1 from mm2 with saturation and vice versa */ + /* OR the results to get absolute difference */ + "movq %%mm1,%%mm5\n" + "movq %%mm3,%%mm6\n" + "psubusb %%mm2,%%mm1\n" + "psubusb %%mm4,%%mm3\n" + "psubusb %%mm5,%%mm2\n" + "psubusb %%mm6,%%mm4\n" + + "por %%mm1,%%mm2\n" + "por %%mm3,%%mm4\n" + + /* now convert to 16-bit vectors so we can square them */ + "movq %%mm2,%%mm1\n" + "movq %%mm4,%%mm3\n" + + "punpckhbw %%mm0,%%mm2\n" + "punpckhbw %%mm0,%%mm4\n" + "punpcklbw %%mm0,%%mm1\n" /* mm1 now spread over (mm1,mm2) */ + "punpcklbw %%mm0,%%mm3\n" /* mm4 now spread over (mm3,mm4) */ + + "pmaddwd %%mm2,%%mm2\n" + "pmaddwd %%mm4,%%mm4\n" + "pmaddwd %%mm1,%%mm1\n" + "pmaddwd %%mm3,%%mm3\n" + + "lea (%0,%3,2), %0\n" /* pix1 += 2*line_size */ + "lea (%1,%3,2), %1\n" /* pix2 += 2*line_size */ + + "paddd %%mm2,%%mm1\n" + "paddd %%mm4,%%mm3\n" + "paddd %%mm1,%%mm7\n" + "paddd %%mm3,%%mm7\n" + + "decl %%ecx\n" + "jnz 1b\n" + + "movq %%mm7,%%mm1\n" + "psrlq $32, %%mm7\n" /* shift hi dword to lo */ + "paddd %%mm7,%%mm1\n" + "movd %%mm1,%2\n" + : "+r" (pix1), "+r" (pix2), "=r"(tmp) + : "r" ((long)line_size) , "m" (h) + : "%ecx"); + return tmp; +} + +static int sse16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) { + int tmp; + asm volatile ( + "movl %4,%%ecx\n" + "pxor %%mm0,%%mm0\n" /* mm0 = 0 */ + "pxor %%mm7,%%mm7\n" /* mm7 holds the sum */ + "1:\n" + "movq (%0),%%mm1\n" /* mm1 = pix1[0-7] */ + "movq (%1),%%mm2\n" /* mm2 = pix2[0-7] */ + "movq 8(%0),%%mm3\n" /* mm3 = pix1[8-15] */ + "movq 8(%1),%%mm4\n" /* mm4 = pix2[8-15] */ + + /* todo: mm1-mm2, mm3-mm4 */ + /* algo: subtract mm1 from mm2 with saturation and vice versa */ + /* OR the results to get absolute difference */ + "movq %%mm1,%%mm5\n" + "movq %%mm3,%%mm6\n" + "psubusb %%mm2,%%mm1\n" + "psubusb %%mm4,%%mm3\n" + "psubusb %%mm5,%%mm2\n" + "psubusb %%mm6,%%mm4\n" + + "por %%mm1,%%mm2\n" + "por %%mm3,%%mm4\n" + + /* now convert to 16-bit vectors so we can square them */ + "movq %%mm2,%%mm1\n" + "movq %%mm4,%%mm3\n" + + "punpckhbw %%mm0,%%mm2\n" + "punpckhbw %%mm0,%%mm4\n" + "punpcklbw %%mm0,%%mm1\n" /* mm1 now spread over (mm1,mm2) */ + "punpcklbw %%mm0,%%mm3\n" /* mm4 now spread over (mm3,mm4) */ + + "pmaddwd %%mm2,%%mm2\n" + "pmaddwd %%mm4,%%mm4\n" + "pmaddwd %%mm1,%%mm1\n" + "pmaddwd %%mm3,%%mm3\n" + + "add %3,%0\n" + "add %3,%1\n" + + "paddd %%mm2,%%mm1\n" + "paddd %%mm4,%%mm3\n" + "paddd %%mm1,%%mm7\n" + "paddd %%mm3,%%mm7\n" + + "decl %%ecx\n" + "jnz 1b\n" + + "movq %%mm7,%%mm1\n" + "psrlq $32, %%mm7\n" /* shift hi dword to lo */ + "paddd %%mm7,%%mm1\n" + "movd %%mm1,%2\n" + : "+r" (pix1), "+r" (pix2), "=r"(tmp) + : "r" ((long)line_size) , "m" (h) + : "%ecx"); + return tmp; +} + +static int sse16_sse2(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) { + int tmp; + asm volatile ( + "shr $1,%2\n" + "pxor %%xmm0,%%xmm0\n" /* mm0 = 0 */ + "pxor %%xmm7,%%xmm7\n" /* mm7 holds the sum */ + "1:\n" + "movdqu (%0),%%xmm1\n" /* mm1 = pix1[0][0-15] */ + "movdqu (%1),%%xmm2\n" /* mm2 = pix2[0][0-15] */ + "movdqu (%0,%4),%%xmm3\n" /* mm3 = pix1[1][0-15] */ + "movdqu (%1,%4),%%xmm4\n" /* mm4 = pix2[1][0-15] */ + + /* todo: mm1-mm2, mm3-mm4 */ + /* algo: subtract mm1 from mm2 with saturation and vice versa */ + /* OR the results to get absolute difference */ + "movdqa %%xmm1,%%xmm5\n" + "movdqa %%xmm3,%%xmm6\n" + "psubusb %%xmm2,%%xmm1\n" + "psubusb %%xmm4,%%xmm3\n" + "psubusb %%xmm5,%%xmm2\n" + "psubusb %%xmm6,%%xmm4\n" + + "por %%xmm1,%%xmm2\n" + "por %%xmm3,%%xmm4\n" + + /* now convert to 16-bit vectors so we can square them */ + "movdqa %%xmm2,%%xmm1\n" + "movdqa %%xmm4,%%xmm3\n" + + "punpckhbw %%xmm0,%%xmm2\n" + "punpckhbw %%xmm0,%%xmm4\n" + "punpcklbw %%xmm0,%%xmm1\n" /* mm1 now spread over (mm1,mm2) */ + "punpcklbw %%xmm0,%%xmm3\n" /* mm4 now spread over (mm3,mm4) */ + + "pmaddwd %%xmm2,%%xmm2\n" + "pmaddwd %%xmm4,%%xmm4\n" + "pmaddwd %%xmm1,%%xmm1\n" + "pmaddwd %%xmm3,%%xmm3\n" + + "lea (%0,%4,2), %0\n" /* pix1 += 2*line_size */ + "lea (%1,%4,2), %1\n" /* pix2 += 2*line_size */ + + "paddd %%xmm2,%%xmm1\n" + "paddd %%xmm4,%%xmm3\n" + "paddd %%xmm1,%%xmm7\n" + "paddd %%xmm3,%%xmm7\n" + + "decl %2\n" + "jnz 1b\n" + + "movdqa %%xmm7,%%xmm1\n" + "psrldq $8, %%xmm7\n" /* shift hi qword to lo */ + "paddd %%xmm1,%%xmm7\n" + "movdqa %%xmm7,%%xmm1\n" + "psrldq $4, %%xmm7\n" /* shift hi dword to lo */ + "paddd %%xmm1,%%xmm7\n" + "movd %%xmm7,%3\n" + : "+r" (pix1), "+r" (pix2), "+r"(h), "=r"(tmp) + : "r" ((long)line_size)); + return tmp; +} + +static int hf_noise8_mmx(uint8_t * pix1, int line_size, int h) { + int tmp; + asm volatile ( + "movl %3,%%ecx\n" + "pxor %%mm7,%%mm7\n" + "pxor %%mm6,%%mm6\n" + + "movq (%0),%%mm0\n" + "movq %%mm0, %%mm1\n" + "psllq $8, %%mm0\n" + "psrlq $8, %%mm1\n" + "psrlq $8, %%mm0\n" + "movq %%mm0, %%mm2\n" + "movq %%mm1, %%mm3\n" + "punpcklbw %%mm7,%%mm0\n" + "punpcklbw %%mm7,%%mm1\n" + "punpckhbw %%mm7,%%mm2\n" + "punpckhbw %%mm7,%%mm3\n" + "psubw %%mm1, %%mm0\n" + "psubw %%mm3, %%mm2\n" + + "add %2,%0\n" + + "movq (%0),%%mm4\n" + "movq %%mm4, %%mm1\n" + "psllq $8, %%mm4\n" + "psrlq $8, %%mm1\n" + "psrlq $8, %%mm4\n" + "movq %%mm4, %%mm5\n" + "movq %%mm1, %%mm3\n" + "punpcklbw %%mm7,%%mm4\n" + "punpcklbw %%mm7,%%mm1\n" + "punpckhbw %%mm7,%%mm5\n" + "punpckhbw %%mm7,%%mm3\n" + "psubw %%mm1, %%mm4\n" + "psubw %%mm3, %%mm5\n" + "psubw %%mm4, %%mm0\n" + "psubw %%mm5, %%mm2\n" + "pxor %%mm3, %%mm3\n" + "pxor %%mm1, %%mm1\n" + "pcmpgtw %%mm0, %%mm3\n\t" + "pcmpgtw %%mm2, %%mm1\n\t" + "pxor %%mm3, %%mm0\n" + "pxor %%mm1, %%mm2\n" + "psubw %%mm3, %%mm0\n" + "psubw %%mm1, %%mm2\n" + "paddw %%mm0, %%mm2\n" + "paddw %%mm2, %%mm6\n" + + "add %2,%0\n" + "1:\n" + + "movq (%0),%%mm0\n" + "movq %%mm0, %%mm1\n" + "psllq $8, %%mm0\n" + "psrlq $8, %%mm1\n" + "psrlq $8, %%mm0\n" + "movq %%mm0, %%mm2\n" + "movq %%mm1, %%mm3\n" + "punpcklbw %%mm7,%%mm0\n" + "punpcklbw %%mm7,%%mm1\n" + "punpckhbw %%mm7,%%mm2\n" + "punpckhbw %%mm7,%%mm3\n" + "psubw %%mm1, %%mm0\n" + "psubw %%mm3, %%mm2\n" + "psubw %%mm0, %%mm4\n" + "psubw %%mm2, %%mm5\n" + "pxor %%mm3, %%mm3\n" + "pxor %%mm1, %%mm1\n" + "pcmpgtw %%mm4, %%mm3\n\t" + "pcmpgtw %%mm5, %%mm1\n\t" + "pxor %%mm3, %%mm4\n" + "pxor %%mm1, %%mm5\n" + "psubw %%mm3, %%mm4\n" + "psubw %%mm1, %%mm5\n" + "paddw %%mm4, %%mm5\n" + "paddw %%mm5, %%mm6\n" + + "add %2,%0\n" + + "movq (%0),%%mm4\n" + "movq %%mm4, %%mm1\n" + "psllq $8, %%mm4\n" + "psrlq $8, %%mm1\n" + "psrlq $8, %%mm4\n" + "movq %%mm4, %%mm5\n" + "movq %%mm1, %%mm3\n" + "punpcklbw %%mm7,%%mm4\n" + "punpcklbw %%mm7,%%mm1\n" + "punpckhbw %%mm7,%%mm5\n" + "punpckhbw %%mm7,%%mm3\n" + "psubw %%mm1, %%mm4\n" + "psubw %%mm3, %%mm5\n" + "psubw %%mm4, %%mm0\n" + "psubw %%mm5, %%mm2\n" + "pxor %%mm3, %%mm3\n" + "pxor %%mm1, %%mm1\n" + "pcmpgtw %%mm0, %%mm3\n\t" + "pcmpgtw %%mm2, %%mm1\n\t" + "pxor %%mm3, %%mm0\n" + "pxor %%mm1, %%mm2\n" + "psubw %%mm3, %%mm0\n" + "psubw %%mm1, %%mm2\n" + "paddw %%mm0, %%mm2\n" + "paddw %%mm2, %%mm6\n" + + "add %2,%0\n" + "subl $2, %%ecx\n" + " jnz 1b\n" + + "movq %%mm6, %%mm0\n" + "punpcklwd %%mm7,%%mm0\n" + "punpckhwd %%mm7,%%mm6\n" + "paddd %%mm0, %%mm6\n" + + "movq %%mm6,%%mm0\n" + "psrlq $32, %%mm6\n" + "paddd %%mm6,%%mm0\n" + "movd %%mm0,%1\n" + : "+r" (pix1), "=r"(tmp) + : "r" ((long)line_size) , "g" (h-2) + : "%ecx"); + return tmp; +} + +static int hf_noise16_mmx(uint8_t * pix1, int line_size, int h) { + int tmp; + uint8_t * pix= pix1; + asm volatile ( + "movl %3,%%ecx\n" + "pxor %%mm7,%%mm7\n" + "pxor %%mm6,%%mm6\n" + + "movq (%0),%%mm0\n" + "movq 1(%0),%%mm1\n" + "movq %%mm0, %%mm2\n" + "movq %%mm1, %%mm3\n" + "punpcklbw %%mm7,%%mm0\n" + "punpcklbw %%mm7,%%mm1\n" + "punpckhbw %%mm7,%%mm2\n" + "punpckhbw %%mm7,%%mm3\n" + "psubw %%mm1, %%mm0\n" + "psubw %%mm3, %%mm2\n" + + "add %2,%0\n" + + "movq (%0),%%mm4\n" + "movq 1(%0),%%mm1\n" + "movq %%mm4, %%mm5\n" + "movq %%mm1, %%mm3\n" + "punpcklbw %%mm7,%%mm4\n" + "punpcklbw %%mm7,%%mm1\n" + "punpckhbw %%mm7,%%mm5\n" + "punpckhbw %%mm7,%%mm3\n" + "psubw %%mm1, %%mm4\n" + "psubw %%mm3, %%mm5\n" + "psubw %%mm4, %%mm0\n" + "psubw %%mm5, %%mm2\n" + "pxor %%mm3, %%mm3\n" + "pxor %%mm1, %%mm1\n" + "pcmpgtw %%mm0, %%mm3\n\t" + "pcmpgtw %%mm2, %%mm1\n\t" + "pxor %%mm3, %%mm0\n" + "pxor %%mm1, %%mm2\n" + "psubw %%mm3, %%mm0\n" + "psubw %%mm1, %%mm2\n" + "paddw %%mm0, %%mm2\n" + "paddw %%mm2, %%mm6\n" + + "add %2,%0\n" + "1:\n" + + "movq (%0),%%mm0\n" + "movq 1(%0),%%mm1\n" + "movq %%mm0, %%mm2\n" + "movq %%mm1, %%mm3\n" + "punpcklbw %%mm7,%%mm0\n" + "punpcklbw %%mm7,%%mm1\n" + "punpckhbw %%mm7,%%mm2\n" + "punpckhbw %%mm7,%%mm3\n" + "psubw %%mm1, %%mm0\n" + "psubw %%mm3, %%mm2\n" + "psubw %%mm0, %%mm4\n" + "psubw %%mm2, %%mm5\n" + "pxor %%mm3, %%mm3\n" + "pxor %%mm1, %%mm1\n" + "pcmpgtw %%mm4, %%mm3\n\t" + "pcmpgtw %%mm5, %%mm1\n\t" + "pxor %%mm3, %%mm4\n" + "pxor %%mm1, %%mm5\n" + "psubw %%mm3, %%mm4\n" + "psubw %%mm1, %%mm5\n" + "paddw %%mm4, %%mm5\n" + "paddw %%mm5, %%mm6\n" + + "add %2,%0\n" + + "movq (%0),%%mm4\n" + "movq 1(%0),%%mm1\n" + "movq %%mm4, %%mm5\n" + "movq %%mm1, %%mm3\n" + "punpcklbw %%mm7,%%mm4\n" + "punpcklbw %%mm7,%%mm1\n" + "punpckhbw %%mm7,%%mm5\n" + "punpckhbw %%mm7,%%mm3\n" + "psubw %%mm1, %%mm4\n" + "psubw %%mm3, %%mm5\n" + "psubw %%mm4, %%mm0\n" + "psubw %%mm5, %%mm2\n" + "pxor %%mm3, %%mm3\n" + "pxor %%mm1, %%mm1\n" + "pcmpgtw %%mm0, %%mm3\n\t" + "pcmpgtw %%mm2, %%mm1\n\t" + "pxor %%mm3, %%mm0\n" + "pxor %%mm1, %%mm2\n" + "psubw %%mm3, %%mm0\n" + "psubw %%mm1, %%mm2\n" + "paddw %%mm0, %%mm2\n" + "paddw %%mm2, %%mm6\n" + + "add %2,%0\n" + "subl $2, %%ecx\n" + " jnz 1b\n" + + "movq %%mm6, %%mm0\n" + "punpcklwd %%mm7,%%mm0\n" + "punpckhwd %%mm7,%%mm6\n" + "paddd %%mm0, %%mm6\n" + + "movq %%mm6,%%mm0\n" + "psrlq $32, %%mm6\n" + "paddd %%mm6,%%mm0\n" + "movd %%mm0,%1\n" + : "+r" (pix1), "=r"(tmp) + : "r" ((long)line_size) , "g" (h-2) + : "%ecx"); + return tmp + hf_noise8_mmx(pix+8, line_size, h); +} + +static int nsse16_mmx(void *p, uint8_t * pix1, uint8_t * pix2, int line_size, int h) { + MpegEncContext *c = p; + int score1, score2; + + if(c) score1 = c->dsp.sse[0](c, pix1, pix2, line_size, h); + else score1 = sse16_mmx(c, pix1, pix2, line_size, h); + score2= hf_noise16_mmx(pix1, line_size, h) - hf_noise16_mmx(pix2, line_size, h); + + if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight; + else return score1 + FFABS(score2)*8; +} + +static int nsse8_mmx(void *p, uint8_t * pix1, uint8_t * pix2, int line_size, int h) { + MpegEncContext *c = p; + int score1= sse8_mmx(c, pix1, pix2, line_size, h); + int score2= hf_noise8_mmx(pix1, line_size, h) - hf_noise8_mmx(pix2, line_size, h); + + if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight; + else return score1 + FFABS(score2)*8; +} + +static int vsad_intra16_mmx(void *v, uint8_t * pix, uint8_t * dummy, int line_size, int h) { + int tmp; + + assert( (((int)pix) & 7) == 0); + assert((line_size &7) ==0); + +#define SUM(in0, in1, out0, out1) \ + "movq (%0), %%mm2\n"\ + "movq 8(%0), %%mm3\n"\ + "add %2,%0\n"\ + "movq %%mm2, " #out0 "\n"\ + "movq %%mm3, " #out1 "\n"\ + "psubusb " #in0 ", %%mm2\n"\ + "psubusb " #in1 ", %%mm3\n"\ + "psubusb " #out0 ", " #in0 "\n"\ + "psubusb " #out1 ", " #in1 "\n"\ + "por %%mm2, " #in0 "\n"\ + "por %%mm3, " #in1 "\n"\ + "movq " #in0 ", %%mm2\n"\ + "movq " #in1 ", %%mm3\n"\ + "punpcklbw %%mm7, " #in0 "\n"\ + "punpcklbw %%mm7, " #in1 "\n"\ + "punpckhbw %%mm7, %%mm2\n"\ + "punpckhbw %%mm7, %%mm3\n"\ + "paddw " #in1 ", " #in0 "\n"\ + "paddw %%mm3, %%mm2\n"\ + "paddw %%mm2, " #in0 "\n"\ + "paddw " #in0 ", %%mm6\n" + + + asm volatile ( + "movl %3,%%ecx\n" + "pxor %%mm6,%%mm6\n" + "pxor %%mm7,%%mm7\n" + "movq (%0),%%mm0\n" + "movq 8(%0),%%mm1\n" + "add %2,%0\n" + "subl $2, %%ecx\n" + SUM(%%mm0, %%mm1, %%mm4, %%mm5) + "1:\n" + + SUM(%%mm4, %%mm5, %%mm0, %%mm1) + + SUM(%%mm0, %%mm1, %%mm4, %%mm5) + + "subl $2, %%ecx\n" + "jnz 1b\n" + + "movq %%mm6,%%mm0\n" + "psrlq $32, %%mm6\n" + "paddw %%mm6,%%mm0\n" + "movq %%mm0,%%mm6\n" + "psrlq $16, %%mm0\n" + "paddw %%mm6,%%mm0\n" + "movd %%mm0,%1\n" + : "+r" (pix), "=r"(tmp) + : "r" ((long)line_size) , "m" (h) + : "%ecx"); + return tmp & 0xFFFF; +} +#undef SUM + +static int vsad_intra16_mmx2(void *v, uint8_t * pix, uint8_t * dummy, int line_size, int h) { + int tmp; + + assert( (((int)pix) & 7) == 0); + assert((line_size &7) ==0); + +#define SUM(in0, in1, out0, out1) \ + "movq (%0), " #out0 "\n"\ + "movq 8(%0), " #out1 "\n"\ + "add %2,%0\n"\ + "psadbw " #out0 ", " #in0 "\n"\ + "psadbw " #out1 ", " #in1 "\n"\ + "paddw " #in1 ", " #in0 "\n"\ + "paddw " #in0 ", %%mm6\n" + + asm volatile ( + "movl %3,%%ecx\n" + "pxor %%mm6,%%mm6\n" + "pxor %%mm7,%%mm7\n" + "movq (%0),%%mm0\n" + "movq 8(%0),%%mm1\n" + "add %2,%0\n" + "subl $2, %%ecx\n" + SUM(%%mm0, %%mm1, %%mm4, %%mm5) + "1:\n" + + SUM(%%mm4, %%mm5, %%mm0, %%mm1) + + SUM(%%mm0, %%mm1, %%mm4, %%mm5) + + "subl $2, %%ecx\n" + "jnz 1b\n" + + "movd %%mm6,%1\n" + : "+r" (pix), "=r"(tmp) + : "r" ((long)line_size) , "m" (h) + : "%ecx"); + return tmp; +} +#undef SUM + +static int vsad16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) { + int tmp; + + assert( (((int)pix1) & 7) == 0); + assert( (((int)pix2) & 7) == 0); + assert((line_size &7) ==0); + +#define SUM(in0, in1, out0, out1) \ + "movq (%0),%%mm2\n"\ + "movq (%1)," #out0 "\n"\ + "movq 8(%0),%%mm3\n"\ + "movq 8(%1)," #out1 "\n"\ + "add %3,%0\n"\ + "add %3,%1\n"\ + "psubb " #out0 ", %%mm2\n"\ + "psubb " #out1 ", %%mm3\n"\ + "pxor %%mm7, %%mm2\n"\ + "pxor %%mm7, %%mm3\n"\ + "movq %%mm2, " #out0 "\n"\ + "movq %%mm3, " #out1 "\n"\ + "psubusb " #in0 ", %%mm2\n"\ + "psubusb " #in1 ", %%mm3\n"\ + "psubusb " #out0 ", " #in0 "\n"\ + "psubusb " #out1 ", " #in1 "\n"\ + "por %%mm2, " #in0 "\n"\ + "por %%mm3, " #in1 "\n"\ + "movq " #in0 ", %%mm2\n"\ + "movq " #in1 ", %%mm3\n"\ + "punpcklbw %%mm7, " #in0 "\n"\ + "punpcklbw %%mm7, " #in1 "\n"\ + "punpckhbw %%mm7, %%mm2\n"\ + "punpckhbw %%mm7, %%mm3\n"\ + "paddw " #in1 ", " #in0 "\n"\ + "paddw %%mm3, %%mm2\n"\ + "paddw %%mm2, " #in0 "\n"\ + "paddw " #in0 ", %%mm6\n" + + + asm volatile ( + "movl %4,%%ecx\n" + "pxor %%mm6,%%mm6\n" + "pcmpeqw %%mm7,%%mm7\n" + "psllw $15, %%mm7\n" + "packsswb %%mm7, %%mm7\n" + "movq (%0),%%mm0\n" + "movq (%1),%%mm2\n" + "movq 8(%0),%%mm1\n" + "movq 8(%1),%%mm3\n" + "add %3,%0\n" + "add %3,%1\n" + "subl $2, %%ecx\n" + "psubb %%mm2, %%mm0\n" + "psubb %%mm3, %%mm1\n" + "pxor %%mm7, %%mm0\n" + "pxor %%mm7, %%mm1\n" + SUM(%%mm0, %%mm1, %%mm4, %%mm5) + "1:\n" + + SUM(%%mm4, %%mm5, %%mm0, %%mm1) + + SUM(%%mm0, %%mm1, %%mm4, %%mm5) + + "subl $2, %%ecx\n" + "jnz 1b\n" + + "movq %%mm6,%%mm0\n" + "psrlq $32, %%mm6\n" + "paddw %%mm6,%%mm0\n" + "movq %%mm0,%%mm6\n" + "psrlq $16, %%mm0\n" + "paddw %%mm6,%%mm0\n" + "movd %%mm0,%2\n" + : "+r" (pix1), "+r" (pix2), "=r"(tmp) + : "r" ((long)line_size) , "m" (h) + : "%ecx"); + return tmp & 0x7FFF; +} +#undef SUM + +static int vsad16_mmx2(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) { + int tmp; + + assert( (((int)pix1) & 7) == 0); + assert( (((int)pix2) & 7) == 0); + assert((line_size &7) ==0); + +#define SUM(in0, in1, out0, out1) \ + "movq (%0)," #out0 "\n"\ + "movq (%1),%%mm2\n"\ + "movq 8(%0)," #out1 "\n"\ + "movq 8(%1),%%mm3\n"\ + "add %3,%0\n"\ + "add %3,%1\n"\ + "psubb %%mm2, " #out0 "\n"\ + "psubb %%mm3, " #out1 "\n"\ + "pxor %%mm7, " #out0 "\n"\ + "pxor %%mm7, " #out1 "\n"\ + "psadbw " #out0 ", " #in0 "\n"\ + "psadbw " #out1 ", " #in1 "\n"\ + "paddw " #in1 ", " #in0 "\n"\ + "paddw " #in0 ", %%mm6\n" + + asm volatile ( + "movl %4,%%ecx\n" + "pxor %%mm6,%%mm6\n" + "pcmpeqw %%mm7,%%mm7\n" + "psllw $15, %%mm7\n" + "packsswb %%mm7, %%mm7\n" + "movq (%0),%%mm0\n" + "movq (%1),%%mm2\n" + "movq 8(%0),%%mm1\n" + "movq 8(%1),%%mm3\n" + "add %3,%0\n" + "add %3,%1\n" + "subl $2, %%ecx\n" + "psubb %%mm2, %%mm0\n" + "psubb %%mm3, %%mm1\n" + "pxor %%mm7, %%mm0\n" + "pxor %%mm7, %%mm1\n" + SUM(%%mm0, %%mm1, %%mm4, %%mm5) + "1:\n" + + SUM(%%mm4, %%mm5, %%mm0, %%mm1) + + SUM(%%mm0, %%mm1, %%mm4, %%mm5) + + "subl $2, %%ecx\n" + "jnz 1b\n" + + "movd %%mm6,%2\n" + : "+r" (pix1), "+r" (pix2), "=r"(tmp) + : "r" ((long)line_size) , "m" (h) + : "%ecx"); + return tmp; +} +#undef SUM + +static void diff_bytes_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){ + long i=0; + asm volatile( + "1: \n\t" + "movq (%2, %0), %%mm0 \n\t" + "movq (%1, %0), %%mm1 \n\t" + "psubb %%mm0, %%mm1 \n\t" + "movq %%mm1, (%3, %0) \n\t" + "movq 8(%2, %0), %%mm0 \n\t" + "movq 8(%1, %0), %%mm1 \n\t" + "psubb %%mm0, %%mm1 \n\t" + "movq %%mm1, 8(%3, %0) \n\t" + "add $16, %0 \n\t" + "cmp %4, %0 \n\t" + " jb 1b \n\t" + : "+r" (i) + : "r"(src1), "r"(src2), "r"(dst), "r"((long)w-15) + ); + for(; idct_algo; + if(dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX){ + if(mm_flags & MM_SSE2){ + c->fdct = ff_fdct_sse2; + }else if(mm_flags & MM_MMXEXT){ + c->fdct = ff_fdct_mmx2; + }else{ + c->fdct = ff_fdct_mmx; + } + } + + c->get_pixels = get_pixels_mmx; + c->diff_pixels = diff_pixels_mmx; + c->pix_sum = pix_sum16_mmx; + + c->diff_bytes= diff_bytes_mmx; + c->sum_abs_dctelem= sum_abs_dctelem_mmx; + + c->hadamard8_diff[0]= hadamard8_diff16_mmx; + c->hadamard8_diff[1]= hadamard8_diff_mmx; + + c->pix_norm1 = pix_norm1_mmx; + c->sse[0] = (mm_flags & MM_SSE2) ? sse16_sse2 : sse16_mmx; + c->sse[1] = sse8_mmx; + c->vsad[4]= vsad_intra16_mmx; + + c->nsse[0] = nsse16_mmx; + c->nsse[1] = nsse8_mmx; + if(!(avctx->flags & CODEC_FLAG_BITEXACT)){ + c->vsad[0] = vsad16_mmx; + } + + if(!(avctx->flags & CODEC_FLAG_BITEXACT)){ + c->try_8x8basis= try_8x8basis_mmx; + } + c->add_8x8basis= add_8x8basis_mmx; + + c->ssd_int8_vs_int16 = ssd_int8_vs_int16_mmx; + + + if (mm_flags & MM_MMXEXT) { + c->sum_abs_dctelem= sum_abs_dctelem_mmx2; + c->hadamard8_diff[0]= hadamard8_diff16_mmx2; + c->hadamard8_diff[1]= hadamard8_diff_mmx2; + c->vsad[4]= vsad_intra16_mmx2; + + if(!(avctx->flags & CODEC_FLAG_BITEXACT)){ + c->vsad[0] = vsad16_mmx2; + } + + c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_mmx2; + } + + if(mm_flags & MM_SSE2){ + c->sum_abs_dctelem= sum_abs_dctelem_sse2; + c->hadamard8_diff[0]= hadamard8_diff16_sse2; + c->hadamard8_diff[1]= hadamard8_diff_sse2; + if (ENABLE_FLAC_ENCODER) + c->flac_compute_autocorr = ff_flac_compute_autocorr_sse2; + } + +#ifdef HAVE_SSSE3 + if(mm_flags & MM_SSSE3){ + if(!(avctx->flags & CODEC_FLAG_BITEXACT)){ + c->try_8x8basis= try_8x8basis_ssse3; + } + c->add_8x8basis= add_8x8basis_ssse3; + c->sum_abs_dctelem= sum_abs_dctelem_ssse3; + c->hadamard8_diff[0]= hadamard8_diff16_ssse3; + c->hadamard8_diff[1]= hadamard8_diff_ssse3; + } +#endif + + if(mm_flags & MM_3DNOW){ + if(!(avctx->flags & CODEC_FLAG_BITEXACT)){ + c->try_8x8basis= try_8x8basis_3dnow; + } + c->add_8x8basis= add_8x8basis_3dnow; + } + } + + dsputil_init_pix_mmx(c, avctx); +} diff --git a/contrib/ffmpeg/libavcodec/i386/fdct_mmx.c b/contrib/ffmpeg/libavcodec/i386/fdct_mmx.c index 7e2682a4a..f93c3c937 100644 --- a/contrib/ffmpeg/libavcodec/i386/fdct_mmx.c +++ b/contrib/ffmpeg/libavcodec/i386/fdct_mmx.c @@ -30,7 +30,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "common.h" -#include "../dsputil.h" +#include "dsputil.h" #include "mmx.h" #define ATTR_ALIGN(align) __attribute__ ((__aligned__ (align))) @@ -52,18 +52,20 @@ #define RND_FRW_ROW (1 << (SHIFT_FRW_ROW-1)) //#define RND_FRW_COL (1 << (SHIFT_FRW_COL-1)) +#define X8(x) x,x,x,x,x,x,x,x + //concatenated table, for forward DCT transformation -static const int16_t fdct_tg_all_16[] ATTR_ALIGN(8) = { - 13036, 13036, 13036, 13036, // tg * (2<<16) + 0.5 - 27146, 27146, 27146, 27146, // tg * (2<<16) + 0.5 - -21746, -21746, -21746, -21746, // tg * (2<<16) + 0.5 +static const int16_t fdct_tg_all_16[24] ATTR_ALIGN(16) = { + X8(13036), // tg * (2<<16) + 0.5 + X8(27146), // tg * (2<<16) + 0.5 + X8(-21746) // tg * (2<<16) + 0.5 }; -static const int16_t ocos_4_16[4] ATTR_ALIGN(8) = { - 23170, 23170, 23170, 23170, //cos * (2<<15) + 0.5 +static const int16_t ocos_4_16[8] ATTR_ALIGN(16) = { + X8(23170) //cos * (2<<15) + 0.5 }; -static const int64_t fdct_one_corr ATTR_ALIGN(8) = 0x0001000100010001LL; +static const int16_t fdct_one_corr[8] ATTR_ALIGN(16) = { X8(1) }; static const int32_t fdct_r_row[2] ATTR_ALIGN(8) = {RND_FRW_ROW, RND_FRW_ROW }; @@ -283,86 +285,88 @@ TABLE_SSE2 TABLE_SSE2 }}; - -static av_always_inline void fdct_col(const int16_t *in, int16_t *out, int offset) -{ - movq_m2r(*(in + offset + 1 * 8), mm0); - movq_m2r(*(in + offset + 6 * 8), mm1); - movq_r2r(mm0, mm2); - movq_m2r(*(in + offset + 2 * 8), mm3); - paddsw_r2r(mm1, mm0); - movq_m2r(*(in + offset + 5 * 8), mm4); - psllw_i2r(SHIFT_FRW_COL, mm0); - movq_m2r(*(in + offset + 0 * 8), mm5); - paddsw_r2r(mm3, mm4); - paddsw_m2r(*(in + offset + 7 * 8), mm5); - psllw_i2r(SHIFT_FRW_COL, mm4); - movq_r2r(mm0, mm6); - psubsw_r2r(mm1, mm2); - movq_m2r(*(fdct_tg_all_16 + 4), mm1); - psubsw_r2r(mm4, mm0); - movq_m2r(*(in + offset + 3 * 8), mm7); - pmulhw_r2r(mm0, mm1); - paddsw_m2r(*(in + offset + 4 * 8), mm7); - psllw_i2r(SHIFT_FRW_COL, mm5); - paddsw_r2r(mm4, mm6); - psllw_i2r(SHIFT_FRW_COL, mm7); - movq_r2r(mm5, mm4); - psubsw_r2r(mm7, mm5); - paddsw_r2r(mm5, mm1); - paddsw_r2r(mm7, mm4); - por_m2r(fdct_one_corr, mm1); - psllw_i2r(SHIFT_FRW_COL + 1, mm2); - pmulhw_m2r(*(fdct_tg_all_16 + 4), mm5); - movq_r2r(mm4, mm7); - psubsw_m2r(*(in + offset + 5 * 8), mm3); - psubsw_r2r(mm6, mm4); - movq_r2m(mm1, *(out + offset + 2 * 8)); - paddsw_r2r(mm6, mm7); - movq_m2r(*(in + offset + 3 * 8), mm1); - psllw_i2r(SHIFT_FRW_COL + 1, mm3); - psubsw_m2r(*(in + offset + 4 * 8), mm1); - movq_r2r(mm2, mm6); - movq_r2m(mm4, *(out + offset + 4 * 8)); - paddsw_r2r(mm3, mm2); - pmulhw_m2r(*ocos_4_16, mm2); - psubsw_r2r(mm3, mm6); - pmulhw_m2r(*ocos_4_16, mm6); - psubsw_r2r(mm0, mm5); - por_m2r(fdct_one_corr, mm5); - psllw_i2r(SHIFT_FRW_COL, mm1); - por_m2r(fdct_one_corr, mm2); - movq_r2r(mm1, mm4); - movq_m2r(*(in + offset + 0 * 8), mm3); - paddsw_r2r(mm6, mm1); - psubsw_m2r(*(in + offset + 7 * 8), mm3); - psubsw_r2r(mm6, mm4); - movq_m2r(*(fdct_tg_all_16 + 0), mm0); - psllw_i2r(SHIFT_FRW_COL, mm3); - movq_m2r(*(fdct_tg_all_16 + 8), mm6); - pmulhw_r2r(mm1, mm0); - movq_r2m(mm7, *(out + offset + 0 * 8)); - pmulhw_r2r(mm4, mm6); - movq_r2m(mm5, *(out + offset + 6 * 8)); - movq_r2r(mm3, mm7); - movq_m2r(*(fdct_tg_all_16 + 8), mm5); - psubsw_r2r(mm2, mm7); - paddsw_r2r(mm2, mm3); - pmulhw_r2r(mm7, mm5); - paddsw_r2r(mm3, mm0); - paddsw_r2r(mm4, mm6); - pmulhw_m2r(*(fdct_tg_all_16 + 0), mm3); - por_m2r(fdct_one_corr, mm0); - paddsw_r2r(mm7, mm5); - psubsw_r2r(mm6, mm7); - movq_r2m(mm0, *(out + offset + 1 * 8)); - paddsw_r2r(mm4, mm5); - movq_r2m(mm7, *(out + offset + 3 * 8)); - psubsw_r2r(mm1, mm3); - movq_r2m(mm5, *(out + offset + 5 * 8)); - movq_r2m(mm3, *(out + offset + 7 * 8)); +#define FDCT_COL(cpu, mm, mov)\ +static av_always_inline void fdct_col_##cpu(const int16_t *in, int16_t *out, int offset)\ +{\ + mov##_m2r(*(in + offset + 1 * 8), mm##0);\ + mov##_m2r(*(in + offset + 6 * 8), mm##1);\ + mov##_r2r(mm##0, mm##2);\ + mov##_m2r(*(in + offset + 2 * 8), mm##3);\ + paddsw_r2r(mm##1, mm##0);\ + mov##_m2r(*(in + offset + 5 * 8), mm##4);\ + psllw_i2r(SHIFT_FRW_COL, mm##0);\ + mov##_m2r(*(in + offset + 0 * 8), mm##5);\ + paddsw_r2r(mm##3, mm##4);\ + paddsw_m2r(*(in + offset + 7 * 8), mm##5);\ + psllw_i2r(SHIFT_FRW_COL, mm##4);\ + mov##_r2r(mm##0, mm##6);\ + psubsw_r2r(mm##1, mm##2);\ + mov##_m2r(*(fdct_tg_all_16 + 8), mm##1);\ + psubsw_r2r(mm##4, mm##0);\ + mov##_m2r(*(in + offset + 3 * 8), mm##7);\ + pmulhw_r2r(mm##0, mm##1);\ + paddsw_m2r(*(in + offset + 4 * 8), mm##7);\ + psllw_i2r(SHIFT_FRW_COL, mm##5);\ + paddsw_r2r(mm##4, mm##6);\ + psllw_i2r(SHIFT_FRW_COL, mm##7);\ + mov##_r2r(mm##5, mm##4);\ + psubsw_r2r(mm##7, mm##5);\ + paddsw_r2r(mm##5, mm##1);\ + paddsw_r2r(mm##7, mm##4);\ + por_m2r(*fdct_one_corr, mm##1);\ + psllw_i2r(SHIFT_FRW_COL + 1, mm##2);\ + pmulhw_m2r(*(fdct_tg_all_16 + 8), mm##5);\ + mov##_r2r(mm##4, mm##7);\ + psubsw_m2r(*(in + offset + 5 * 8), mm##3);\ + psubsw_r2r(mm##6, mm##4);\ + mov##_r2m(mm##1, *(out + offset + 2 * 8));\ + paddsw_r2r(mm##6, mm##7);\ + mov##_m2r(*(in + offset + 3 * 8), mm##1);\ + psllw_i2r(SHIFT_FRW_COL + 1, mm##3);\ + psubsw_m2r(*(in + offset + 4 * 8), mm##1);\ + mov##_r2r(mm##2, mm##6);\ + mov##_r2m(mm##4, *(out + offset + 4 * 8));\ + paddsw_r2r(mm##3, mm##2);\ + pmulhw_m2r(*ocos_4_16, mm##2);\ + psubsw_r2r(mm##3, mm##6);\ + pmulhw_m2r(*ocos_4_16, mm##6);\ + psubsw_r2r(mm##0, mm##5);\ + por_m2r(*fdct_one_corr, mm##5);\ + psllw_i2r(SHIFT_FRW_COL, mm##1);\ + por_m2r(*fdct_one_corr, mm##2);\ + mov##_r2r(mm##1, mm##4);\ + mov##_m2r(*(in + offset + 0 * 8), mm##3);\ + paddsw_r2r(mm##6, mm##1);\ + psubsw_m2r(*(in + offset + 7 * 8), mm##3);\ + psubsw_r2r(mm##6, mm##4);\ + mov##_m2r(*(fdct_tg_all_16 + 0), mm##0);\ + psllw_i2r(SHIFT_FRW_COL, mm##3);\ + mov##_m2r(*(fdct_tg_all_16 + 16), mm##6);\ + pmulhw_r2r(mm##1, mm##0);\ + mov##_r2m(mm##7, *(out + offset + 0 * 8));\ + pmulhw_r2r(mm##4, mm##6);\ + mov##_r2m(mm##5, *(out + offset + 6 * 8));\ + mov##_r2r(mm##3, mm##7);\ + mov##_m2r(*(fdct_tg_all_16 + 16), mm##5);\ + psubsw_r2r(mm##2, mm##7);\ + paddsw_r2r(mm##2, mm##3);\ + pmulhw_r2r(mm##7, mm##5);\ + paddsw_r2r(mm##3, mm##0);\ + paddsw_r2r(mm##4, mm##6);\ + pmulhw_m2r(*(fdct_tg_all_16 + 0), mm##3);\ + por_m2r(*fdct_one_corr, mm##0);\ + paddsw_r2r(mm##7, mm##5);\ + psubsw_r2r(mm##6, mm##7);\ + mov##_r2m(mm##0, *(out + offset + 1 * 8));\ + paddsw_r2r(mm##4, mm##5);\ + mov##_r2m(mm##7, *(out + offset + 3 * 8));\ + psubsw_r2r(mm##1, mm##3);\ + mov##_r2m(mm##5, *(out + offset + 5 * 8));\ + mov##_r2m(mm##3, *(out + offset + 7 * 8));\ } +FDCT_COL(mmx, mm, movq) +FDCT_COL(sse2, xmm, movdqa) static av_always_inline void fdct_row_sse2(const int16_t *in, int16_t *out) { @@ -471,7 +475,7 @@ static av_always_inline void fdct_row_mmx2(const int16_t *in, int16_t *out, cons static av_always_inline void fdct_row_mmx(const int16_t *in, int16_t *out, const int16_t *table) { -//FIXME reorder (i dont have a old mmx only cpu here to benchmark ...) +//FIXME reorder (I do not have an old MMX-only CPU here to benchmark ...) movd_m2r(*(in + 6), mm1); punpcklwd_m2r(*(in + 4), mm1); movq_r2r(mm1, mm2); @@ -524,8 +528,8 @@ void ff_fdct_mmx(int16_t *block) const int16_t *table= tab_frw_01234567; int i; - fdct_col(block, block1, 0); - fdct_col(block, block1, 4); + fdct_col_mmx(block, block1, 0); + fdct_col_mmx(block, block1, 4); for(i=8;i>0;i--) { fdct_row_mmx(block1, block, table); @@ -542,8 +546,8 @@ void ff_fdct_mmx2(int16_t *block) const int16_t *table= tab_frw_01234567; int i; - fdct_col(block, block1, 0); - fdct_col(block, block1, 4); + fdct_col_mmx(block, block1, 0); + fdct_col_mmx(block, block1, 4); for(i=8;i>0;i--) { fdct_row_mmx2(block1, block, table); @@ -558,9 +562,7 @@ void ff_fdct_sse2(int16_t *block) int64_t align_tmp[16] ATTR_ALIGN(16); int16_t * const block1= (int16_t*)align_tmp; - fdct_col(block, block1, 0); - fdct_col(block, block1, 4); - + fdct_col_sse2(block, block1, 0); fdct_row_sse2(block1, block); } diff --git a/contrib/ffmpeg/libavcodec/i386/fft_3dn.c b/contrib/ffmpeg/libavcodec/i386/fft_3dn.c index 8087f1932..4231d855a 100644 --- a/contrib/ffmpeg/libavcodec/i386/fft_3dn.c +++ b/contrib/ffmpeg/libavcodec/i386/fft_3dn.c @@ -19,7 +19,7 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../dsputil.h" +#include "dsputil.h" static const int p1m1[2] __attribute__((aligned(8))) = { 0, 1 << 31 }; diff --git a/contrib/ffmpeg/libavcodec/i386/fft_3dn2.c b/contrib/ffmpeg/libavcodec/i386/fft_3dn2.c index a4fe5f0b6..6d063321d 100644 --- a/contrib/ffmpeg/libavcodec/i386/fft_3dn2.c +++ b/contrib/ffmpeg/libavcodec/i386/fft_3dn2.c @@ -19,7 +19,7 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../dsputil.h" +#include "dsputil.h" static const int p1m1[2] __attribute__((aligned(8))) = { 0, 1 << 31 }; diff --git a/contrib/ffmpeg/libavcodec/i386/fft_sse.c b/contrib/ffmpeg/libavcodec/i386/fft_sse.c index 0dc0c61c1..39e64c700 100644 --- a/contrib/ffmpeg/libavcodec/i386/fft_sse.c +++ b/contrib/ffmpeg/libavcodec/i386/fft_sse.c @@ -18,7 +18,7 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../dsputil.h" +#include "dsputil.h" static const int p1p1p1m1[4] __attribute__((aligned(16))) = { 0, 0, 0, 1 << 31 }; @@ -100,20 +100,33 @@ void ff_fft_calc_sse(FFTContext *s, FFTComplex *z) i = nloops*8; asm volatile( "1: \n\t" - "sub $16, %0 \n\t" + "sub $32, %0 \n\t" "movaps (%2,%0), %%xmm1 \n\t" "movaps (%1,%0), %%xmm0 \n\t" + "movaps 16(%2,%0), %%xmm5 \n\t" + "movaps 16(%1,%0), %%xmm4 \n\t" "movaps %%xmm1, %%xmm2 \n\t" + "movaps %%xmm5, %%xmm6 \n\t" "shufps $0xA0, %%xmm1, %%xmm1 \n\t" "shufps $0xF5, %%xmm2, %%xmm2 \n\t" + "shufps $0xA0, %%xmm5, %%xmm5 \n\t" + "shufps $0xF5, %%xmm6, %%xmm6 \n\t" "mulps (%3,%0,2), %%xmm1 \n\t" // cre*re cim*re "mulps 16(%3,%0,2), %%xmm2 \n\t" // -cim*im cre*im + "mulps 32(%3,%0,2), %%xmm5 \n\t" // cre*re cim*re + "mulps 48(%3,%0,2), %%xmm6 \n\t" // -cim*im cre*im "addps %%xmm2, %%xmm1 \n\t" + "addps %%xmm6, %%xmm5 \n\t" "movaps %%xmm0, %%xmm3 \n\t" + "movaps %%xmm4, %%xmm7 \n\t" "addps %%xmm1, %%xmm0 \n\t" "subps %%xmm1, %%xmm3 \n\t" + "addps %%xmm5, %%xmm4 \n\t" + "subps %%xmm5, %%xmm7 \n\t" "movaps %%xmm0, (%1,%0) \n\t" "movaps %%xmm3, (%2,%0) \n\t" + "movaps %%xmm4, 16(%1,%0) \n\t" + "movaps %%xmm7, 16(%2,%0) \n\t" "jg 1b \n\t" :"+r"(i) :"r"(p), "r"(p + nloops), "r"(cptr) @@ -141,67 +154,106 @@ void ff_imdct_calc_sse(MDCTContext *s, FFTSample *output, n4 = n >> 2; n8 = n >> 3; - asm volatile ("movaps %0, %%xmm7\n\t"::"m"(*p1m1p1m1)); +#ifdef ARCH_X86_64 + asm volatile ("movaps %0, %%xmm8\n\t"::"m"(*p1m1p1m1)); +#define P1M1P1M1 "%%xmm8" +#else +#define P1M1P1M1 "%4" +#endif /* pre rotation */ in1 = input; in2 = input + n2 - 4; - /* Complex multiplication - Two complex products per iteration, we could have 4 with 8 xmm - registers, 8 with 16 xmm registers. - Maybe we should unroll more. - */ - for (k = 0; k < n4; k += 2) { + /* Complex multiplication */ + for (k = 0; k < n4; k += 4) { asm volatile ( "movaps %0, %%xmm0 \n\t" // xmm0 = r0 X r1 X : in2 "movaps %1, %%xmm3 \n\t" // xmm3 = X i1 X i0: in1 + "movaps -16+1*%0, %%xmm4 \n\t" // xmm4 = r0 X r1 X : in2 + "movaps 16+1*%1, %%xmm7 \n\t" // xmm7 = X i1 X i0: in1 "movlps %2, %%xmm1 \n\t" // xmm1 = X X R1 R0: tcos "movlps %3, %%xmm2 \n\t" // xmm2 = X X I1 I0: tsin + "movlps 8+1*%2, %%xmm5 \n\t" // xmm5 = X X R1 R0: tcos + "movlps 8+1*%3, %%xmm6 \n\t" // xmm6 = X X I1 I0: tsin "shufps $95, %%xmm0, %%xmm0 \n\t" // xmm0 = r1 r1 r0 r0 "shufps $160,%%xmm3, %%xmm3 \n\t" // xmm3 = i1 i1 i0 i0 + "shufps $95, %%xmm4, %%xmm4 \n\t" // xmm4 = r1 r1 r0 r0 + "shufps $160,%%xmm7, %%xmm7 \n\t" // xmm7 = i1 i1 i0 i0 "unpcklps %%xmm2, %%xmm1 \n\t" // xmm1 = I1 R1 I0 R0 + "unpcklps %%xmm6, %%xmm5 \n\t" // xmm5 = I1 R1 I0 R0 "movaps %%xmm1, %%xmm2 \n\t" // xmm2 = I1 R1 I0 R0 - "xorps %%xmm7, %%xmm2 \n\t" // xmm2 = -I1 R1 -I0 R0 + "movaps %%xmm5, %%xmm6 \n\t" // xmm6 = I1 R1 I0 R0 + "xorps "P1M1P1M1", %%xmm2 \n\t" // xmm2 = -I1 R1 -I0 R0 + "xorps "P1M1P1M1", %%xmm6 \n\t" // xmm6 = -I1 R1 -I0 R0 "mulps %%xmm1, %%xmm0 \n\t" // xmm0 = rI rR rI rR + "mulps %%xmm5, %%xmm4 \n\t" // xmm4 = rI rR rI rR "shufps $177,%%xmm2, %%xmm2 \n\t" // xmm2 = R1 -I1 R0 -I0 + "shufps $177,%%xmm6, %%xmm6 \n\t" // xmm6 = R1 -I1 R0 -I0 "mulps %%xmm2, %%xmm3 \n\t" // xmm3 = Ri -Ii Ri -Ii + "mulps %%xmm6, %%xmm7 \n\t" // xmm7 = Ri -Ii Ri -Ii "addps %%xmm3, %%xmm0 \n\t" // xmm0 = result + "addps %%xmm7, %%xmm4 \n\t" // xmm4 = result ::"m"(in2[-2*k]), "m"(in1[2*k]), "m"(tcos[k]), "m"(tsin[k]) +#ifndef ARCH_X86_64 + ,"m"(*p1m1p1m1) +#endif ); /* Should be in the same block, hack for gcc2.95 & gcc3 */ asm ( "movlps %%xmm0, %0 \n\t" "movhps %%xmm0, %1 \n\t" - :"=m"(z[revtab[k]]), "=m"(z[revtab[k + 1]]) + "movlps %%xmm4, %2 \n\t" + "movhps %%xmm4, %3 \n\t" + :"=m"(z[revtab[k]]), "=m"(z[revtab[k + 1]]), + "=m"(z[revtab[k + 2]]), "=m"(z[revtab[k + 3]]) ); } ff_fft_calc_sse(&s->fft, z); - /* Not currently needed, added for safety */ - asm volatile ("movaps %0, %%xmm7\n\t"::"m"(*p1m1p1m1)); +#ifndef ARCH_X86_64 +#undef P1M1P1M1 +#define P1M1P1M1 "%3" +#endif /* post rotation + reordering */ - for (k = 0; k < n4; k += 2) { + for (k = 0; k < n4; k += 4) { asm ( "movaps %0, %%xmm0 \n\t" // xmm0 = i1 r1 i0 r0: z + "movaps 16+1*%0, %%xmm4 \n\t" // xmm4 = i1 r1 i0 r0: z "movlps %1, %%xmm1 \n\t" // xmm1 = X X R1 R0: tcos + "movlps 8+1*%1, %%xmm5 \n\t" // xmm5 = X X R1 R0: tcos "movaps %%xmm0, %%xmm3 \n\t" // xmm3 = i1 r1 i0 r0 + "movaps %%xmm4, %%xmm7 \n\t" // xmm7 = i1 r1 i0 r0 "movlps %2, %%xmm2 \n\t" // xmm2 = X X I1 I0: tsin + "movlps 8+1*%2, %%xmm6 \n\t" // xmm6 = X X I1 I0: tsin "shufps $160,%%xmm0, %%xmm0 \n\t" // xmm0 = r1 r1 r0 r0 "shufps $245,%%xmm3, %%xmm3 \n\t" // xmm3 = i1 i1 i0 i0 + "shufps $160,%%xmm4, %%xmm4 \n\t" // xmm4 = r1 r1 r0 r0 + "shufps $245,%%xmm7, %%xmm7 \n\t" // xmm7 = i1 i1 i0 i0 "unpcklps %%xmm2, %%xmm1 \n\t" // xmm1 = I1 R1 I0 R0 + "unpcklps %%xmm6, %%xmm5 \n\t" // xmm5 = I1 R1 I0 R0 "movaps %%xmm1, %%xmm2 \n\t" // xmm2 = I1 R1 I0 R0 - "xorps %%xmm7, %%xmm2 \n\t" // xmm2 = -I1 R1 -I0 R0 + "movaps %%xmm5, %%xmm6 \n\t" // xmm6 = I1 R1 I0 R0 + "xorps "P1M1P1M1", %%xmm2 \n\t" // xmm2 = -I1 R1 -I0 R0 "mulps %%xmm1, %%xmm0 \n\t" // xmm0 = rI rR rI rR + "xorps "P1M1P1M1", %%xmm6 \n\t" // xmm6 = -I1 R1 -I0 R0 + "mulps %%xmm5, %%xmm4 \n\t" // xmm4 = rI rR rI rR "shufps $177,%%xmm2, %%xmm2 \n\t" // xmm2 = R1 -I1 R0 -I0 + "shufps $177,%%xmm6, %%xmm6 \n\t" // xmm6 = R1 -I1 R0 -I0 "mulps %%xmm2, %%xmm3 \n\t" // xmm3 = Ri -Ii Ri -Ii + "mulps %%xmm6, %%xmm7 \n\t" // xmm7 = Ri -Ii Ri -Ii "addps %%xmm3, %%xmm0 \n\t" // xmm0 = result + "addps %%xmm7, %%xmm4 \n\t" // xmm4 = result "movaps %%xmm0, %0 \n\t" + "movaps %%xmm4, 16+1*%0\n\t" :"+m"(z[k]) :"m"(tcos[k]), "m"(tsin[k]) +#ifndef ARCH_X86_64 + ,"m"(*p1m1p1m1) +#endif ); } diff --git a/contrib/ffmpeg/libavcodec/i386/flacdsp_mmx.c b/contrib/ffmpeg/libavcodec/i386/flacdsp_mmx.c new file mode 100644 index 000000000..e799ce421 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/i386/flacdsp_mmx.c @@ -0,0 +1,138 @@ +/* + * MMX optimized FLAC DSP utils + * Copyright (c) 2007 Loren Merritt + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "dsputil_mmx.h" + +static void apply_welch_window_sse2(const int32_t *data, int len, double *w_data) +{ + double c = 2.0 / (len-1.0); + int n2 = len>>1; + long i = -n2*sizeof(int32_t); + long j = n2*sizeof(int32_t); + asm volatile( + "movsd %0, %%xmm7 \n\t" + "movapd %1, %%xmm6 \n\t" + "movapd %2, %%xmm5 \n\t" + "movlhps %%xmm7, %%xmm7 \n\t" + "subpd %%xmm5, %%xmm7 \n\t" + "addsd %%xmm6, %%xmm7 \n\t" + ::"m"(c), "m"(*ff_pd_1), "m"(*ff_pd_2) + ); +#define WELCH(MOVPD, offset)\ + asm volatile(\ + "1: \n\t"\ + "movapd %%xmm7, %%xmm1 \n\t"\ + "mulpd %%xmm1, %%xmm1 \n\t"\ + "movapd %%xmm6, %%xmm0 \n\t"\ + "subpd %%xmm1, %%xmm0 \n\t"\ + "pshufd $0x4e, %%xmm0, %%xmm1 \n\t"\ + "cvtpi2pd (%3,%0), %%xmm2 \n\t"\ + "cvtpi2pd "#offset"*4(%3,%1), %%xmm3 \n\t"\ + "mulpd %%xmm0, %%xmm2 \n\t"\ + "mulpd %%xmm1, %%xmm3 \n\t"\ + "movapd %%xmm2, (%2,%0,2) \n\t"\ + MOVPD" %%xmm3, "#offset"*8(%2,%1,2) \n\t"\ + "subpd %%xmm5, %%xmm7 \n\t"\ + "sub $8, %1 \n\t"\ + "add $8, %0 \n\t"\ + "jl 1b \n\t"\ + :"+&r"(i), "+&r"(j)\ + :"r"(w_data+n2), "r"(data+n2)\ + ); + if(len&1) + WELCH("movupd", -1) + else + WELCH("movapd", -2) +#undef WELCH +} + +void ff_flac_compute_autocorr_sse2(const int32_t *data, int len, int lag, + double *autoc) +{ + double tmp[len + lag + 2]; + double *data1 = tmp + lag; + int j; + + if((long)data1 & 15) + data1++; + + apply_welch_window_sse2(data, len, data1); + + for(j=0; j> 6; @@ -369,8 +439,8 @@ static void ff_h264_idct8_dc_add_mmx2(uint8_t *dst, int16_t *block, int stride) "paddusb %%mm3 , %%mm1 \n\t"\ "paddusb %%mm6 , %%mm2 \n\t" -// in: mm0=p1 mm1=p0 mm2=q0 mm3=q1 mm7=(tc&mask) %8=mm_bone -// out: (q1addr) = clip( (q2+((p0+q0+1)>>1))>>1, q1-tc0, q1+tc0 ) +// in: mm0=p1 mm1=p0 mm2=q0 mm3=q1 mm7=(tc&mask) %8=ff_bone +// out: (q1addr) = av_clip( (q2+((p0+q0+1)>>1))>>1, q1-tc0, q1+tc0 ) // clobbers: q2, tmp, tc0 #define H264_DEBLOCK_Q1(p1, q2, q2addr, q1addr, tc0, tmp)\ "movq %%mm1, "#tmp" \n\t"\ @@ -435,7 +505,7 @@ static inline void h264_loop_filter_luma_mmx2(uint8_t *pix, int stride, int alph : "=m"(*tmp0) : "r"(pix-3*stride), "r"(pix), "r"((long)stride), "m"(*tmp0/*unused*/), "m"(*(uint32_t*)tc0), "m"(alpha1), "m"(beta1), - "m"(mm_bone) + "m"(ff_bone) ); } @@ -482,7 +552,7 @@ static inline void h264_loop_filter_chroma_mmx2(uint8_t *pix, int stride, int al :: "r"(pix-2*stride), "r"(pix), "r"((long)stride), "r"(*(uint32_t*)tc0), - "m"(alpha1), "m"(beta1), "m"(mm_bone), "m"(ff_pb_3F) + "m"(alpha1), "m"(beta1), "m"(ff_bone), "m"(ff_pb_3F) ); } @@ -532,7 +602,7 @@ static inline void h264_loop_filter_chroma_intra_mmx2(uint8_t *pix, int stride, "movq %%mm1, (%0,%2) \n\t" "movq %%mm2, (%1) \n\t" :: "r"(pix-2*stride), "r"(pix), "r"((long)stride), - "m"(alpha1), "m"(beta1), "m"(mm_bone) + "m"(alpha1), "m"(beta1), "m"(ff_bone) ); } @@ -651,37 +721,44 @@ static void h264_loop_filter_strength_mmx2( int16_t bS[2][4][4], uint8_t nnz[40] /***********************************/ /* motion compensation */ -#define QPEL_H264V(A,B,C,D,E,F,OP)\ - "movd (%0), "#F" \n\t"\ - "movq "#C", %%mm6 \n\t"\ - "paddw "#D", %%mm6 \n\t"\ - "psllw $2, %%mm6 \n\t"\ - "psubw "#B", %%mm6 \n\t"\ - "psubw "#E", %%mm6 \n\t"\ - "pmullw %4, %%mm6 \n\t"\ - "add %2, %0 \n\t"\ - "punpcklbw %%mm7, "#F" \n\t"\ +#define QPEL_H264V_MM(A,B,C,D,E,F,OP,T,Z,d,q)\ + "mov"#q" "#C", "#T" \n\t"\ + "mov"#d" (%0), "#F" \n\t"\ + "paddw "#D", "#T" \n\t"\ + "psllw $2, "#T" \n\t"\ + "psubw "#B", "#T" \n\t"\ + "psubw "#E", "#T" \n\t"\ + "punpcklbw "#Z", "#F" \n\t"\ + "pmullw %4, "#T" \n\t"\ "paddw %5, "#A" \n\t"\ + "add %2, %0 \n\t"\ "paddw "#F", "#A" \n\t"\ - "paddw "#A", %%mm6 \n\t"\ - "psraw $5, %%mm6 \n\t"\ - "packuswb %%mm6, %%mm6 \n\t"\ - OP(%%mm6, (%1), A, d)\ + "paddw "#A", "#T" \n\t"\ + "psraw $5, "#T" \n\t"\ + "packuswb "#T", "#T" \n\t"\ + OP(T, (%1), A, d)\ "add %3, %1 \n\t" -#define QPEL_H264HV(A,B,C,D,E,F,OF)\ - "movd (%0), "#F" \n\t"\ - "movq "#C", %%mm6 \n\t"\ - "paddw "#D", %%mm6 \n\t"\ - "psllw $2, %%mm6 \n\t"\ - "psubw "#B", %%mm6 \n\t"\ - "psubw "#E", %%mm6 \n\t"\ - "pmullw %3, %%mm6 \n\t"\ - "add %2, %0 \n\t"\ - "punpcklbw %%mm7, "#F" \n\t"\ +#define QPEL_H264HV_MM(A,B,C,D,E,F,OF,T,Z,d,q)\ + "mov"#q" "#C", "#T" \n\t"\ + "mov"#d" (%0), "#F" \n\t"\ + "paddw "#D", "#T" \n\t"\ + "psllw $2, "#T" \n\t"\ + "paddw %4, "#A" \n\t"\ + "psubw "#B", "#T" \n\t"\ + "psubw "#E", "#T" \n\t"\ + "punpcklbw "#Z", "#F" \n\t"\ + "pmullw %3, "#T" \n\t"\ "paddw "#F", "#A" \n\t"\ - "paddw "#A", %%mm6 \n\t"\ - "movq %%mm6, "#OF"(%1) \n\t" + "add %2, %0 \n\t"\ + "paddw "#A", "#T" \n\t"\ + "mov"#q" "#T", "#OF"(%1) \n\t" + +#define QPEL_H264V(A,B,C,D,E,F,OP) QPEL_H264V_MM(A,B,C,D,E,F,OP,%%mm6,%%mm7,d,q) +#define QPEL_H264HV(A,B,C,D,E,F,OF) QPEL_H264HV_MM(A,B,C,D,E,F,OF,%%mm6,%%mm7,d,q) +#define QPEL_H264V_XMM(A,B,C,D,E,F,OP) QPEL_H264V_MM(A,B,C,D,E,F,OP,%%xmm6,%%xmm7,q,dqa) +#define QPEL_H264HV_XMM(A,B,C,D,E,F,OF) QPEL_H264HV_MM(A,B,C,D,E,F,OF,%%xmm6,%%xmm7,q,dqa) + #define QPEL_H264(OPNAME, OP, MMX)\ static av_noinline void OPNAME ## h264_qpel4_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ @@ -719,7 +796,7 @@ static av_noinline void OPNAME ## h264_qpel4_h_lowpass_ ## MMX(uint8_t *dst, uin "add %4, %1 \n\t"\ "decl %2 \n\t"\ " jnz 1b \n\t"\ - : "+a"(src), "+c"(dst), "+m"(h)\ + : "+a"(src), "+c"(dst), "+g"(h)\ : "d"((long)srcStride), "S"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\ : "memory"\ );\ @@ -825,7 +902,7 @@ static av_noinline void OPNAME ## h264_qpel4_hv_lowpass_ ## MMX(uint8_t *dst, in QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 3*8*3)\ \ : "+a"(src)\ - : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5)\ + : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5), "m"(ff_pw_16)\ : "memory"\ );\ tmp += 4;\ @@ -833,7 +910,6 @@ static av_noinline void OPNAME ## h264_qpel4_hv_lowpass_ ## MMX(uint8_t *dst, in }\ tmp -= 3*4;\ asm volatile(\ - "movq %4, %%mm6 \n\t"\ "1: \n\t"\ "movq (%0), %%mm0 \n\t"\ "paddw 10(%0), %%mm0 \n\t"\ @@ -846,8 +922,7 @@ static av_noinline void OPNAME ## h264_qpel4_hv_lowpass_ ## MMX(uint8_t *dst, in "psubw %%mm1, %%mm0 \n\t"/*(a-b)/4-b */\ "paddsw %%mm2, %%mm0 \n\t"\ "psraw $2, %%mm0 \n\t"/*((a-b)/4-b+c)/4 */\ - "paddw %%mm6, %%mm2 \n\t"\ - "paddw %%mm2, %%mm0 \n\t"/*(a-5*b+20*c)/16 +32 */\ + "paddw %%mm2, %%mm0 \n\t"/*(a-5*b+20*c)/16 */\ "psraw $6, %%mm0 \n\t"\ "packuswb %%mm0, %%mm0 \n\t"\ OP(%%mm0, (%1),%%mm7, d)\ @@ -855,8 +930,8 @@ static av_noinline void OPNAME ## h264_qpel4_hv_lowpass_ ## MMX(uint8_t *dst, in "add %3, %1 \n\t"\ "decl %2 \n\t"\ " jnz 1b \n\t"\ - : "+a"(tmp), "+c"(dst), "+m"(h)\ - : "S"((long)dstStride), "m"(ff_pw_32)\ + : "+a"(tmp), "+c"(dst), "+g"(h)\ + : "S"((long)dstStride)\ : "memory"\ );\ }\ @@ -912,7 +987,7 @@ static av_noinline void OPNAME ## h264_qpel8_h_lowpass_ ## MMX(uint8_t *dst, uin "add %4, %1 \n\t"\ "decl %2 \n\t"\ " jnz 1b \n\t"\ - : "+a"(src), "+c"(dst), "+m"(h)\ + : "+a"(src), "+c"(dst), "+g"(h)\ : "d"((long)srcStride), "S"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\ : "memory"\ );\ @@ -1036,8 +1111,7 @@ static av_noinline void OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(uint8_t *dst, dst += 4-h*dstStride;\ }\ }\ -static av_noinline void OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride, int size){\ - int h = size;\ +static av_always_inline void OPNAME ## h264_qpel8or16_hv1_lowpass_ ## MMX(int16_t *tmp, uint8_t *src, int tmpStride, int srcStride, int size){\ int w = (size+8)>>2;\ src -= 2*srcStride+2;\ while(w--){\ @@ -1067,7 +1141,7 @@ static av_noinline void OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst QPEL_H264HV(%%mm0, %%mm1, %%mm2, %%mm3, %%mm4, %%mm5, 6*48)\ QPEL_H264HV(%%mm1, %%mm2, %%mm3, %%mm4, %%mm5, %%mm0, 7*48)\ : "+a"(src)\ - : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5)\ + : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5), "m"(ff_pw_16)\ : "memory"\ );\ if(size==16){\ @@ -1081,19 +1155,19 @@ static av_noinline void OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst QPEL_H264HV(%%mm2, %%mm3, %%mm4, %%mm5, %%mm0, %%mm1, 14*48)\ QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 15*48)\ : "+a"(src)\ - : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5)\ + : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5), "m"(ff_pw_16)\ : "memory"\ );\ }\ tmp += 4;\ src += 4 - (size+5)*srcStride;\ }\ - tmp -= size+8;\ - w = size>>4;\ +}\ +static av_always_inline void OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, int dstStride, int tmpStride, int size){\ + int w = size>>4;\ do{\ - h = size;\ + int h = size;\ asm volatile(\ - "movq %4, %%mm6 \n\t"\ "1: \n\t"\ "movq (%0), %%mm0 \n\t"\ "movq 8(%0), %%mm3 \n\t"\ @@ -1117,8 +1191,6 @@ static av_noinline void OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst "paddsw %%mm5, %%mm3 \n\t"\ "psraw $2, %%mm0 \n\t"\ "psraw $2, %%mm3 \n\t"\ - "paddw %%mm6, %%mm2 \n\t"\ - "paddw %%mm6, %%mm5 \n\t"\ "paddw %%mm2, %%mm0 \n\t"\ "paddw %%mm5, %%mm3 \n\t"\ "psraw $6, %%mm0 \n\t"\ @@ -1129,8 +1201,8 @@ static av_noinline void OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst "add %3, %1 \n\t"\ "decl %2 \n\t"\ " jnz 1b \n\t"\ - : "+a"(tmp), "+c"(dst), "+m"(h)\ - : "S"((long)dstStride), "m"(ff_pw_32)\ + : "+a"(tmp), "+c"(dst), "+g"(h)\ + : "S"((long)dstStride)\ : "memory"\ );\ tmp += 8 - size*24;\ @@ -1146,7 +1218,7 @@ static av_noinline void OPNAME ## h264_qpel16_v_lowpass_ ## MMX(uint8_t *dst, ui OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\ }\ \ -static av_noinline void OPNAME ## h264_qpel16_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ +static void OPNAME ## h264_qpel16_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\ OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\ src += 8*srcStride;\ @@ -1165,6 +1237,10 @@ static av_noinline void OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\ }\ \ +static av_noinline void OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride, int size){\ + put_h264_qpel8or16_hv1_lowpass_ ## MMX(tmp, src, tmpStride, srcStride, size);\ + OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(dst, tmp, dstStride, tmpStride, size);\ +}\ static void OPNAME ## h264_qpel8_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\ OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst , tmp , src , dstStride, tmpStride, srcStride, 8);\ }\ @@ -1176,11 +1252,8 @@ static void OPNAME ## h264_qpel16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, static av_noinline void OPNAME ## pixels4_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\ {\ asm volatile(\ - "movq %5, %%mm6 \n\t"\ "movq (%1), %%mm0 \n\t"\ "movq 24(%1), %%mm1 \n\t"\ - "paddw %%mm6, %%mm0 \n\t"\ - "paddw %%mm6, %%mm1 \n\t"\ "psraw $5, %%mm0 \n\t"\ "psraw $5, %%mm1 \n\t"\ "packuswb %%mm0, %%mm0 \n\t"\ @@ -1193,8 +1266,6 @@ static av_noinline void OPNAME ## pixels4_l2_shift5_ ## MMX(uint8_t *dst, int16_ "lea (%2,%4,2), %2 \n\t"\ "movq 48(%1), %%mm0 \n\t"\ "movq 72(%1), %%mm1 \n\t"\ - "paddw %%mm6, %%mm0 \n\t"\ - "paddw %%mm6, %%mm1 \n\t"\ "psraw $5, %%mm0 \n\t"\ "psraw $5, %%mm1 \n\t"\ "packuswb %%mm0, %%mm0 \n\t"\ @@ -1204,32 +1275,34 @@ static av_noinline void OPNAME ## pixels4_l2_shift5_ ## MMX(uint8_t *dst, int16_ OP(%%mm0, (%2), %%mm4, d)\ OP(%%mm1, (%2,%4), %%mm5, d)\ :"+a"(src8), "+c"(src16), "+d"(dst)\ - :"S"((long)src8Stride), "D"((long)dstStride), "m"(ff_pw_16)\ + :"S"((long)src8Stride), "D"((long)dstStride)\ :"memory");\ }\ static av_noinline void OPNAME ## pixels8_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\ {\ - asm volatile(\ - "movq %0, %%mm6 \n\t"\ - ::"m"(ff_pw_16)\ - );\ - while(h--){\ + do{\ asm volatile(\ "movq (%1), %%mm0 \n\t"\ "movq 8(%1), %%mm1 \n\t"\ - "paddw %%mm6, %%mm0 \n\t"\ - "paddw %%mm6, %%mm1 \n\t"\ + "movq 48(%1), %%mm2 \n\t"\ + "movq 8+48(%1), %%mm3 \n\t"\ "psraw $5, %%mm0 \n\t"\ "psraw $5, %%mm1 \n\t"\ + "psraw $5, %%mm2 \n\t"\ + "psraw $5, %%mm3 \n\t"\ "packuswb %%mm1, %%mm0 \n\t"\ + "packuswb %%mm3, %%mm2 \n\t"\ PAVGB" (%0), %%mm0 \n\t"\ + PAVGB" (%0,%3), %%mm2 \n\t"\ OP(%%mm0, (%2), %%mm5, q)\ - ::"a"(src8), "c"(src16), "d"(dst)\ + OP(%%mm2, (%2,%4), %%mm5, q)\ + ::"a"(src8), "c"(src16), "d"(dst),\ + "r"((long)src8Stride), "r"((long)dstStride)\ :"memory");\ - src8 += src8Stride;\ - src16 += 24;\ - dst += dstStride;\ - }\ + src8 += 2L*src8Stride;\ + src16 += 48;\ + dst += 2L*dstStride;\ + }while(h-=2);\ }\ static void OPNAME ## pixels16_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, uint8_t *src8, int dstStride, int src8Stride, int h)\ {\ @@ -1238,11 +1311,453 @@ static void OPNAME ## pixels16_l2_shift5_ ## MMX(uint8_t *dst, int16_t *src16, u }\ -#define H264_MC(OPNAME, SIZE, MMX) \ -static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\ - OPNAME ## pixels ## SIZE ## _mmx(dst, src, stride, SIZE);\ +#ifdef ARCH_X86_64 +#define QPEL_H264_H16_XMM(OPNAME, OP, MMX)\ +static av_noinline void OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\ + int h=16;\ + asm volatile(\ + "pxor %%xmm15, %%xmm15 \n\t"\ + "movdqa %6, %%xmm14 \n\t"\ + "movdqa %7, %%xmm13 \n\t"\ + "1: \n\t"\ + "lddqu 3(%0), %%xmm1 \n\t"\ + "lddqu -5(%0), %%xmm7 \n\t"\ + "movdqa %%xmm1, %%xmm0 \n\t"\ + "punpckhbw %%xmm15, %%xmm1 \n\t"\ + "punpcklbw %%xmm15, %%xmm0 \n\t"\ + "punpcklbw %%xmm15, %%xmm7 \n\t"\ + "movdqa %%xmm1, %%xmm2 \n\t"\ + "movdqa %%xmm0, %%xmm6 \n\t"\ + "movdqa %%xmm1, %%xmm3 \n\t"\ + "movdqa %%xmm0, %%xmm8 \n\t"\ + "movdqa %%xmm1, %%xmm4 \n\t"\ + "movdqa %%xmm0, %%xmm9 \n\t"\ + "movdqa %%xmm1, %%xmm5 \n\t"\ + "movdqa %%xmm0, %%xmm10 \n\t"\ + "palignr $6, %%xmm0, %%xmm5 \n\t"\ + "palignr $6, %%xmm7, %%xmm10\n\t"\ + "palignr $8, %%xmm0, %%xmm4 \n\t"\ + "palignr $8, %%xmm7, %%xmm9 \n\t"\ + "palignr $10,%%xmm0, %%xmm3 \n\t"\ + "palignr $10,%%xmm7, %%xmm8 \n\t"\ + "paddw %%xmm1, %%xmm5 \n\t"\ + "paddw %%xmm0, %%xmm10 \n\t"\ + "palignr $12,%%xmm0, %%xmm2 \n\t"\ + "palignr $12,%%xmm7, %%xmm6 \n\t"\ + "palignr $14,%%xmm0, %%xmm1 \n\t"\ + "palignr $14,%%xmm7, %%xmm0 \n\t"\ + "paddw %%xmm3, %%xmm2 \n\t"\ + "paddw %%xmm8, %%xmm6 \n\t"\ + "paddw %%xmm4, %%xmm1 \n\t"\ + "paddw %%xmm9, %%xmm0 \n\t"\ + "psllw $2, %%xmm2 \n\t"\ + "psllw $2, %%xmm6 \n\t"\ + "psubw %%xmm1, %%xmm2 \n\t"\ + "psubw %%xmm0, %%xmm6 \n\t"\ + "paddw %%xmm13,%%xmm5 \n\t"\ + "paddw %%xmm13,%%xmm10 \n\t"\ + "pmullw %%xmm14,%%xmm2 \n\t"\ + "pmullw %%xmm14,%%xmm6 \n\t"\ + "lddqu (%2), %%xmm3 \n\t"\ + "paddw %%xmm5, %%xmm2 \n\t"\ + "paddw %%xmm10,%%xmm6 \n\t"\ + "psraw $5, %%xmm2 \n\t"\ + "psraw $5, %%xmm6 \n\t"\ + "packuswb %%xmm2,%%xmm6 \n\t"\ + "pavgb %%xmm3, %%xmm6 \n\t"\ + OP(%%xmm6, (%1), %%xmm4, dqa)\ + "add %5, %0 \n\t"\ + "add %5, %1 \n\t"\ + "add %4, %2 \n\t"\ + "decl %3 \n\t"\ + "jg 1b \n\t"\ + : "+a"(src), "+c"(dst), "+d"(src2), "+g"(h)\ + : "D"((long)src2Stride), "S"((long)dstStride),\ + "m"(ff_pw_5), "m"(ff_pw_16)\ + : "memory"\ + );\ +} +#else // ARCH_X86_64 +#define QPEL_H264_H16_XMM(OPNAME, OP, MMX)\ +static av_noinline void OPNAME ## h264_qpel16_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\ + OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\ + OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\ + src += 8*dstStride;\ + dst += 8*dstStride;\ + src2 += 8*src2Stride;\ + OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst , src , src2 , dstStride, src2Stride);\ + OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(dst+8, src+8, src2+8, dstStride, src2Stride);\ +} +#endif // ARCH_X86_64 + +#define QPEL_H264_H_XMM(OPNAME, OP, MMX)\ +static av_noinline void OPNAME ## h264_qpel8_h_lowpass_l2_ ## MMX(uint8_t *dst, uint8_t *src, uint8_t *src2, int dstStride, int src2Stride){\ + int h=8;\ + asm volatile(\ + "pxor %%xmm7, %%xmm7 \n\t"\ + "movdqa %0, %%xmm6 \n\t"\ + :: "m"(ff_pw_5)\ + );\ + do{\ + asm volatile(\ + "lddqu -5(%0), %%xmm1 \n\t"\ + "movdqa %%xmm1, %%xmm0 \n\t"\ + "punpckhbw %%xmm7, %%xmm1 \n\t"\ + "punpcklbw %%xmm7, %%xmm0 \n\t"\ + "movdqa %%xmm1, %%xmm2 \n\t"\ + "movdqa %%xmm1, %%xmm3 \n\t"\ + "movdqa %%xmm1, %%xmm4 \n\t"\ + "movdqa %%xmm1, %%xmm5 \n\t"\ + "palignr $6, %%xmm0, %%xmm5 \n\t"\ + "palignr $8, %%xmm0, %%xmm4 \n\t"\ + "palignr $10,%%xmm0, %%xmm3 \n\t"\ + "paddw %%xmm1, %%xmm5 \n\t"\ + "palignr $12,%%xmm0, %%xmm2 \n\t"\ + "palignr $14,%%xmm0, %%xmm1 \n\t"\ + "paddw %%xmm3, %%xmm2 \n\t"\ + "paddw %%xmm4, %%xmm1 \n\t"\ + "psllw $2, %%xmm2 \n\t"\ + "movq (%2), %%xmm3 \n\t"\ + "psubw %%xmm1, %%xmm2 \n\t"\ + "paddw %5, %%xmm5 \n\t"\ + "pmullw %%xmm6, %%xmm2 \n\t"\ + "paddw %%xmm5, %%xmm2 \n\t"\ + "psraw $5, %%xmm2 \n\t"\ + "packuswb %%xmm2, %%xmm2 \n\t"\ + "pavgb %%xmm3, %%xmm2 \n\t"\ + OP(%%xmm2, (%1), %%xmm4, q)\ + "add %4, %0 \n\t"\ + "add %4, %1 \n\t"\ + "add %3, %2 \n\t"\ + : "+a"(src), "+c"(dst), "+d"(src2)\ + : "D"((long)src2Stride), "S"((long)dstStride),\ + "m"(ff_pw_16)\ + : "memory"\ + );\ + }while(--h);\ }\ +QPEL_H264_H16_XMM(OPNAME, OP, MMX)\ \ +static av_noinline void OPNAME ## h264_qpel8_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ + int h=8;\ + asm volatile(\ + "pxor %%xmm7, %%xmm7 \n\t"\ + "movdqa %5, %%xmm6 \n\t"\ + "1: \n\t"\ + "lddqu -5(%0), %%xmm1 \n\t"\ + "movdqa %%xmm1, %%xmm0 \n\t"\ + "punpckhbw %%xmm7, %%xmm1 \n\t"\ + "punpcklbw %%xmm7, %%xmm0 \n\t"\ + "movdqa %%xmm1, %%xmm2 \n\t"\ + "movdqa %%xmm1, %%xmm3 \n\t"\ + "movdqa %%xmm1, %%xmm4 \n\t"\ + "movdqa %%xmm1, %%xmm5 \n\t"\ + "palignr $6, %%xmm0, %%xmm5 \n\t"\ + "palignr $8, %%xmm0, %%xmm4 \n\t"\ + "palignr $10,%%xmm0, %%xmm3 \n\t"\ + "paddw %%xmm1, %%xmm5 \n\t"\ + "palignr $12,%%xmm0, %%xmm2 \n\t"\ + "palignr $14,%%xmm0, %%xmm1 \n\t"\ + "paddw %%xmm3, %%xmm2 \n\t"\ + "paddw %%xmm4, %%xmm1 \n\t"\ + "psllw $2, %%xmm2 \n\t"\ + "psubw %%xmm1, %%xmm2 \n\t"\ + "paddw %6, %%xmm5 \n\t"\ + "pmullw %%xmm6, %%xmm2 \n\t"\ + "paddw %%xmm5, %%xmm2 \n\t"\ + "psraw $5, %%xmm2 \n\t"\ + "packuswb %%xmm2, %%xmm2 \n\t"\ + OP(%%xmm2, (%1), %%xmm4, q)\ + "add %3, %0 \n\t"\ + "add %4, %1 \n\t"\ + "decl %2 \n\t"\ + " jnz 1b \n\t"\ + : "+a"(src), "+c"(dst), "+g"(h)\ + : "D"((long)srcStride), "S"((long)dstStride),\ + "m"(ff_pw_5), "m"(ff_pw_16)\ + : "memory"\ + );\ +}\ +static void OPNAME ## h264_qpel16_h_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ + OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\ + OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\ + src += 8*srcStride;\ + dst += 8*dstStride;\ + OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst , src , dstStride, srcStride);\ + OPNAME ## h264_qpel8_h_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride);\ +}\ + +#define QPEL_H264_V_XMM(OPNAME, OP, MMX)\ +static av_noinline void OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\ + src -= 2*srcStride;\ + \ + asm volatile(\ + "pxor %%xmm7, %%xmm7 \n\t"\ + "movq (%0), %%xmm0 \n\t"\ + "add %2, %0 \n\t"\ + "movq (%0), %%xmm1 \n\t"\ + "add %2, %0 \n\t"\ + "movq (%0), %%xmm2 \n\t"\ + "add %2, %0 \n\t"\ + "movq (%0), %%xmm3 \n\t"\ + "add %2, %0 \n\t"\ + "movq (%0), %%xmm4 \n\t"\ + "add %2, %0 \n\t"\ + "punpcklbw %%xmm7, %%xmm0 \n\t"\ + "punpcklbw %%xmm7, %%xmm1 \n\t"\ + "punpcklbw %%xmm7, %%xmm2 \n\t"\ + "punpcklbw %%xmm7, %%xmm3 \n\t"\ + "punpcklbw %%xmm7, %%xmm4 \n\t"\ + QPEL_H264V_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, OP)\ + QPEL_H264V_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, OP)\ + QPEL_H264V_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, OP)\ + QPEL_H264V_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, OP)\ + QPEL_H264V_XMM(%%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, OP)\ + QPEL_H264V_XMM(%%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, OP)\ + QPEL_H264V_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, OP)\ + QPEL_H264V_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, OP)\ + \ + : "+a"(src), "+c"(dst)\ + : "S"((long)srcStride), "D"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\ + : "memory"\ + );\ + if(h==16){\ + asm volatile(\ + QPEL_H264V_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, OP)\ + QPEL_H264V_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, OP)\ + QPEL_H264V_XMM(%%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, OP)\ + QPEL_H264V_XMM(%%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, OP)\ + QPEL_H264V_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, OP)\ + QPEL_H264V_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, OP)\ + QPEL_H264V_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, OP)\ + QPEL_H264V_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, OP)\ + \ + : "+a"(src), "+c"(dst)\ + : "S"((long)srcStride), "D"((long)dstStride), "m"(ff_pw_5), "m"(ff_pw_16)\ + : "memory"\ + );\ + }\ +}\ +static void OPNAME ## h264_qpel8_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ + OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 8);\ +}\ +static av_noinline void OPNAME ## h264_qpel16_v_lowpass_ ## MMX(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ + OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst , src , dstStride, srcStride, 16);\ + OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(dst+8, src+8, dstStride, srcStride, 16);\ +} + +static av_always_inline void put_h264_qpel8or16_hv1_lowpass_sse2(int16_t *tmp, uint8_t *src, int tmpStride, int srcStride, int size){ + int w = (size+8)>>3; + src -= 2*srcStride+2; + while(w--){ + asm volatile( + "pxor %%xmm7, %%xmm7 \n\t" + "movq (%0), %%xmm0 \n\t" + "add %2, %0 \n\t" + "movq (%0), %%xmm1 \n\t" + "add %2, %0 \n\t" + "movq (%0), %%xmm2 \n\t" + "add %2, %0 \n\t" + "movq (%0), %%xmm3 \n\t" + "add %2, %0 \n\t" + "movq (%0), %%xmm4 \n\t" + "add %2, %0 \n\t" + "punpcklbw %%xmm7, %%xmm0 \n\t" + "punpcklbw %%xmm7, %%xmm1 \n\t" + "punpcklbw %%xmm7, %%xmm2 \n\t" + "punpcklbw %%xmm7, %%xmm3 \n\t" + "punpcklbw %%xmm7, %%xmm4 \n\t" + QPEL_H264HV_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, 0*48) + QPEL_H264HV_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, 1*48) + QPEL_H264HV_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, 2*48) + QPEL_H264HV_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, 3*48) + QPEL_H264HV_XMM(%%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, 4*48) + QPEL_H264HV_XMM(%%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, 5*48) + QPEL_H264HV_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, 6*48) + QPEL_H264HV_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, 7*48) + : "+a"(src) + : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5), "m"(ff_pw_16) + : "memory" + ); + if(size==16){ + asm volatile( + QPEL_H264HV_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, 8*48) + QPEL_H264HV_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, 9*48) + QPEL_H264HV_XMM(%%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, 10*48) + QPEL_H264HV_XMM(%%xmm5, %%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, 11*48) + QPEL_H264HV_XMM(%%xmm0, %%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, 12*48) + QPEL_H264HV_XMM(%%xmm1, %%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, 13*48) + QPEL_H264HV_XMM(%%xmm2, %%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, 14*48) + QPEL_H264HV_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, 15*48) + : "+a"(src) + : "c"(tmp), "S"((long)srcStride), "m"(ff_pw_5), "m"(ff_pw_16) + : "memory" + ); + } + tmp += 8; + src += 8 - (size+5)*srcStride; + } +} + +#define QPEL_H264_HV2_XMM(OPNAME, OP, MMX)\ +static av_always_inline void OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, int dstStride, int tmpStride, int size){\ + int h = size;\ + if(size == 16){\ + asm volatile(\ + "1: \n\t"\ + "movdqa 32(%0), %%xmm4 \n\t"\ + "movdqa 16(%0), %%xmm5 \n\t"\ + "movdqa (%0), %%xmm7 \n\t"\ + "movdqa %%xmm4, %%xmm3 \n\t"\ + "movdqa %%xmm4, %%xmm2 \n\t"\ + "movdqa %%xmm4, %%xmm1 \n\t"\ + "movdqa %%xmm4, %%xmm0 \n\t"\ + "palignr $10, %%xmm5, %%xmm0 \n\t"\ + "palignr $8, %%xmm5, %%xmm1 \n\t"\ + "palignr $6, %%xmm5, %%xmm2 \n\t"\ + "palignr $4, %%xmm5, %%xmm3 \n\t"\ + "palignr $2, %%xmm5, %%xmm4 \n\t"\ + "paddw %%xmm5, %%xmm0 \n\t"\ + "paddw %%xmm4, %%xmm1 \n\t"\ + "paddw %%xmm3, %%xmm2 \n\t"\ + "movdqa %%xmm5, %%xmm6 \n\t"\ + "movdqa %%xmm5, %%xmm4 \n\t"\ + "movdqa %%xmm5, %%xmm3 \n\t"\ + "palignr $8, %%xmm7, %%xmm4 \n\t"\ + "palignr $2, %%xmm7, %%xmm6 \n\t"\ + "palignr $10, %%xmm7, %%xmm3 \n\t"\ + "paddw %%xmm6, %%xmm4 \n\t"\ + "movdqa %%xmm5, %%xmm6 \n\t"\ + "palignr $6, %%xmm7, %%xmm5 \n\t"\ + "palignr $4, %%xmm7, %%xmm6 \n\t"\ + "paddw %%xmm7, %%xmm3 \n\t"\ + "paddw %%xmm6, %%xmm5 \n\t"\ + \ + "psubw %%xmm1, %%xmm0 \n\t"\ + "psubw %%xmm4, %%xmm3 \n\t"\ + "psraw $2, %%xmm0 \n\t"\ + "psraw $2, %%xmm3 \n\t"\ + "psubw %%xmm1, %%xmm0 \n\t"\ + "psubw %%xmm4, %%xmm3 \n\t"\ + "paddw %%xmm2, %%xmm0 \n\t"\ + "paddw %%xmm5, %%xmm3 \n\t"\ + "psraw $2, %%xmm0 \n\t"\ + "psraw $2, %%xmm3 \n\t"\ + "paddw %%xmm2, %%xmm0 \n\t"\ + "paddw %%xmm5, %%xmm3 \n\t"\ + "psraw $6, %%xmm0 \n\t"\ + "psraw $6, %%xmm3 \n\t"\ + "packuswb %%xmm0, %%xmm3 \n\t"\ + OP(%%xmm3, (%1), %%xmm7, dqa)\ + "add $48, %0 \n\t"\ + "add %3, %1 \n\t"\ + "decl %2 \n\t"\ + " jnz 1b \n\t"\ + : "+a"(tmp), "+c"(dst), "+g"(h)\ + : "S"((long)dstStride)\ + : "memory"\ + );\ + }else{\ + asm volatile(\ + "1: \n\t"\ + "movdqa 16(%0), %%xmm1 \n\t"\ + "movdqa (%0), %%xmm0 \n\t"\ + "movdqa %%xmm1, %%xmm2 \n\t"\ + "movdqa %%xmm1, %%xmm3 \n\t"\ + "movdqa %%xmm1, %%xmm4 \n\t"\ + "movdqa %%xmm1, %%xmm5 \n\t"\ + "palignr $10, %%xmm0, %%xmm5 \n\t"\ + "palignr $8, %%xmm0, %%xmm4 \n\t"\ + "palignr $6, %%xmm0, %%xmm3 \n\t"\ + "palignr $4, %%xmm0, %%xmm2 \n\t"\ + "palignr $2, %%xmm0, %%xmm1 \n\t"\ + "paddw %%xmm5, %%xmm0 \n\t"\ + "paddw %%xmm4, %%xmm1 \n\t"\ + "paddw %%xmm3, %%xmm2 \n\t"\ + "psubw %%xmm1, %%xmm0 \n\t"\ + "psraw $2, %%xmm0 \n\t"\ + "psubw %%xmm1, %%xmm0 \n\t"\ + "paddw %%xmm2, %%xmm0 \n\t"\ + "psraw $2, %%xmm0 \n\t"\ + "paddw %%xmm2, %%xmm0 \n\t"\ + "psraw $6, %%xmm0 \n\t"\ + "packuswb %%xmm0, %%xmm0 \n\t"\ + OP(%%xmm0, (%1), %%xmm7, q)\ + "add $48, %0 \n\t"\ + "add %3, %1 \n\t"\ + "decl %2 \n\t"\ + " jnz 1b \n\t"\ + : "+a"(tmp), "+c"(dst), "+g"(h)\ + : "S"((long)dstStride)\ + : "memory"\ + );\ + }\ +} + +#define QPEL_H264_HV_XMM(OPNAME, OP, MMX)\ +static av_noinline void OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride, int size){\ + put_h264_qpel8or16_hv1_lowpass_sse2(tmp, src, tmpStride, srcStride, size);\ + OPNAME ## h264_qpel8or16_hv2_lowpass_ ## MMX(dst, tmp, dstStride, tmpStride, size);\ +}\ +static void OPNAME ## h264_qpel8_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\ + OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst, tmp, src, dstStride, tmpStride, srcStride, 8);\ +}\ +static void OPNAME ## h264_qpel16_hv_lowpass_ ## MMX(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\ + OPNAME ## h264_qpel8or16_hv_lowpass_ ## MMX(dst, tmp, src, dstStride, tmpStride, srcStride, 16);\ +}\ + +#define put_pixels8_l2_sse2 put_pixels8_l2_mmx2 +#define avg_pixels8_l2_sse2 avg_pixels8_l2_mmx2 +#define put_pixels16_l2_sse2 put_pixels16_l2_mmx2 +#define avg_pixels16_l2_sse2 avg_pixels16_l2_mmx2 +#define put_pixels8_l2_ssse3 put_pixels8_l2_mmx2 +#define avg_pixels8_l2_ssse3 avg_pixels8_l2_mmx2 +#define put_pixels16_l2_ssse3 put_pixels16_l2_mmx2 +#define avg_pixels16_l2_ssse3 avg_pixels16_l2_mmx2 + +#define put_pixels8_l2_shift5_sse2 put_pixels8_l2_shift5_mmx2 +#define avg_pixels8_l2_shift5_sse2 avg_pixels8_l2_shift5_mmx2 +#define put_pixels16_l2_shift5_sse2 put_pixels16_l2_shift5_mmx2 +#define avg_pixels16_l2_shift5_sse2 avg_pixels16_l2_shift5_mmx2 +#define put_pixels8_l2_shift5_ssse3 put_pixels8_l2_shift5_mmx2 +#define avg_pixels8_l2_shift5_ssse3 avg_pixels8_l2_shift5_mmx2 +#define put_pixels16_l2_shift5_ssse3 put_pixels16_l2_shift5_mmx2 +#define avg_pixels16_l2_shift5_ssse3 avg_pixels16_l2_shift5_mmx2 + +#define put_h264_qpel8_h_lowpass_l2_sse2 put_h264_qpel8_h_lowpass_l2_mmx2 +#define avg_h264_qpel8_h_lowpass_l2_sse2 avg_h264_qpel8_h_lowpass_l2_mmx2 +#define put_h264_qpel16_h_lowpass_l2_sse2 put_h264_qpel16_h_lowpass_l2_mmx2 +#define avg_h264_qpel16_h_lowpass_l2_sse2 avg_h264_qpel16_h_lowpass_l2_mmx2 + +#define put_h264_qpel8_v_lowpass_ssse3 put_h264_qpel8_v_lowpass_sse2 +#define avg_h264_qpel8_v_lowpass_ssse3 avg_h264_qpel8_v_lowpass_sse2 +#define put_h264_qpel16_v_lowpass_ssse3 put_h264_qpel16_v_lowpass_sse2 +#define avg_h264_qpel16_v_lowpass_ssse3 avg_h264_qpel16_v_lowpass_sse2 + +#define put_h264_qpel8or16_hv2_lowpass_sse2 put_h264_qpel8or16_hv2_lowpass_mmx2 +#define avg_h264_qpel8or16_hv2_lowpass_sse2 avg_h264_qpel8or16_hv2_lowpass_mmx2 + +#define H264_MC(OPNAME, SIZE, MMX, ALIGN) \ +H264_MC_C(OPNAME, SIZE, MMX, ALIGN)\ +H264_MC_V(OPNAME, SIZE, MMX, ALIGN)\ +H264_MC_H(OPNAME, SIZE, MMX, ALIGN)\ +H264_MC_HV(OPNAME, SIZE, MMX, ALIGN)\ + +static void put_h264_qpel16_mc00_sse2 (uint8_t *dst, uint8_t *src, int stride){ + put_pixels16_sse2(dst, src, stride, 16); +} +static void avg_h264_qpel16_mc00_sse2 (uint8_t *dst, uint8_t *src, int stride){ + avg_pixels16_sse2(dst, src, stride, 16); +} +#define put_h264_qpel8_mc00_sse2 put_h264_qpel8_mc00_mmx2 +#define avg_h264_qpel8_mc00_sse2 avg_h264_qpel8_mc00_mmx2 + +#define H264_MC_C(OPNAME, SIZE, MMX, ALIGN) \ +static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## MMX (uint8_t *dst, uint8_t *src, int stride){\ + OPNAME ## pixels ## SIZE ## _ ## MMX(dst, src, stride, SIZE);\ +}\ + +#define H264_MC_H(OPNAME, SIZE, MMX, ALIGN) \ static void OPNAME ## h264_qpel ## SIZE ## _mc10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src, stride, stride);\ }\ @@ -1254,12 +1769,12 @@ static void OPNAME ## h264_qpel ## SIZE ## _mc20_ ## MMX(uint8_t *dst, uint8_t * static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, src+1, stride, stride);\ }\ -\ + +#define H264_MC_V(OPNAME, SIZE, MMX, ALIGN) \ static void OPNAME ## h264_qpel ## SIZE ## _mc01_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - uint64_t temp[SIZE*SIZE/8];\ - uint8_t * const half= (uint8_t*)temp;\ - put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(half, src, SIZE, stride);\ - OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src, half, stride, stride, SIZE);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\ + put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\ + OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src, temp, stride, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ @@ -1267,82 +1782,91 @@ static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## MMX(uint8_t *dst, uint8_t * }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - uint64_t temp[SIZE*SIZE/8];\ - uint8_t * const half= (uint8_t*)temp;\ - put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(half, src, SIZE, stride);\ - OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src+stride, half, stride, stride, SIZE);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\ + put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\ + OPNAME ## pixels ## SIZE ## _l2_ ## MMX(dst, src+stride, temp, stride, stride, SIZE);\ }\ -\ + +#define H264_MC_HV(OPNAME, SIZE, MMX, ALIGN) \ static void OPNAME ## h264_qpel ## SIZE ## _mc11_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - uint64_t temp[SIZE*SIZE/8];\ - uint8_t * const halfV= (uint8_t*)temp;\ - put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src, SIZE, stride);\ - OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfV, stride, SIZE);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\ + put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\ + OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, temp, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc31_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - uint64_t temp[SIZE*SIZE/8];\ - uint8_t * const halfV= (uint8_t*)temp;\ - put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src+1, SIZE, stride);\ - OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfV, stride, SIZE);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\ + put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src+1, SIZE, stride);\ + OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, temp, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc13_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - uint64_t temp[SIZE*SIZE/8];\ - uint8_t * const halfV= (uint8_t*)temp;\ - put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src, SIZE, stride);\ - OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfV, stride, SIZE);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\ + put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src, SIZE, stride);\ + OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, temp, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc33_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - uint64_t temp[SIZE*SIZE/8];\ - uint8_t * const halfV= (uint8_t*)temp;\ - put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(halfV, src+1, SIZE, stride);\ - OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfV, stride, SIZE);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*SIZE]);\ + put_h264_qpel ## SIZE ## _v_lowpass_ ## MMX(temp, src+1, SIZE, stride);\ + OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, temp, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc22_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - uint64_t temp[SIZE*(SIZE<8?12:24)/4];\ - int16_t * const tmp= (int16_t*)temp;\ - OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(dst, tmp, src, stride, SIZE, stride);\ + DECLARE_ALIGNED(ALIGN, uint16_t, temp[SIZE*(SIZE<8?12:24)]);\ + OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(dst, temp, src, stride, SIZE, stride);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\ - uint8_t * const halfHV= (uint8_t*)temp;\ - int16_t * const tmp= ((int16_t*)temp) + SIZE*SIZE/2;\ - assert((int)temp & 7 == 0);\ - put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, tmp, src, SIZE, SIZE, stride);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE]);\ + uint8_t * const halfHV= temp;\ + int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\ + assert(((int)temp & 7) == 0);\ + put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src, halfHV, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\ - uint8_t * const halfHV= (uint8_t*)temp;\ - int16_t * const tmp= ((int16_t*)temp) + SIZE*SIZE/2;\ - assert((int)temp & 7 == 0);\ - put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, tmp, src, SIZE, SIZE, stride);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE]);\ + uint8_t * const halfHV= temp;\ + int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\ + assert(((int)temp & 7) == 0);\ + put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\ OPNAME ## h264_qpel ## SIZE ## _h_lowpass_l2_ ## MMX(dst, src+stride, halfHV, stride, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\ - int16_t * const halfV= ((int16_t*)temp) + SIZE*SIZE/2;\ - uint8_t * const halfHV= ((uint8_t*)temp);\ - assert((int)temp & 7 == 0);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE]);\ + uint8_t * const halfHV= temp;\ + int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\ + assert(((int)temp & 7) == 0);\ put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_shift5_ ## MMX(dst, halfV+2, halfHV, stride, SIZE, SIZE);\ }\ \ static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ - uint64_t temp[SIZE*(SIZE<8?12:24)/4 + SIZE*SIZE/8];\ - int16_t * const halfV= ((int16_t*)temp) + SIZE*SIZE/2;\ - uint8_t * const halfHV= ((uint8_t*)temp);\ - assert((int)temp & 7 == 0);\ + DECLARE_ALIGNED(ALIGN, uint8_t, temp[SIZE*(SIZE<8?12:24)*2 + SIZE*SIZE]);\ + uint8_t * const halfHV= temp;\ + int16_t * const halfV= (int16_t*)(temp + SIZE*SIZE);\ + assert(((int)temp & 7) == 0);\ put_h264_qpel ## SIZE ## _hv_lowpass_ ## MMX(halfHV, halfV, src, SIZE, SIZE, stride);\ OPNAME ## pixels ## SIZE ## _l2_shift5_ ## MMX(dst, halfV+3, halfHV, stride, SIZE, SIZE);\ }\ +#define H264_MC_4816(MMX)\ +H264_MC(put_, 4, MMX, 8)\ +H264_MC(put_, 8, MMX, 8)\ +H264_MC(put_, 16,MMX, 8)\ +H264_MC(avg_, 4, MMX, 8)\ +H264_MC(avg_, 8, MMX, 8)\ +H264_MC(avg_, 16,MMX, 8)\ + +#define H264_MC_816(QPEL, XMM)\ +QPEL(put_, 8, XMM, 16)\ +QPEL(put_, 16,XMM, 16)\ +QPEL(avg_, 8, XMM, 16)\ +QPEL(avg_, 16,XMM, 16)\ + #define AVG_3DNOW_OP(a,b,temp, size) \ "mov" #size " " #b ", " #temp " \n\t"\ @@ -1360,20 +1884,28 @@ QPEL_H264(avg_, AVG_3DNOW_OP, 3dnow) #define PAVGB "pavgb" QPEL_H264(put_, PUT_OP, mmx2) QPEL_H264(avg_, AVG_MMX2_OP, mmx2) +QPEL_H264_V_XMM(put_, PUT_OP, sse2) +QPEL_H264_V_XMM(avg_, AVG_MMX2_OP, sse2) +QPEL_H264_HV_XMM(put_, PUT_OP, sse2) +QPEL_H264_HV_XMM(avg_, AVG_MMX2_OP, sse2) +#ifdef HAVE_SSSE3 +QPEL_H264_H_XMM(put_, PUT_OP, ssse3) +QPEL_H264_H_XMM(avg_, AVG_MMX2_OP, ssse3) +QPEL_H264_HV2_XMM(put_, PUT_OP, ssse3) +QPEL_H264_HV2_XMM(avg_, AVG_MMX2_OP, ssse3) +QPEL_H264_HV_XMM(put_, PUT_OP, ssse3) +QPEL_H264_HV_XMM(avg_, AVG_MMX2_OP, ssse3) +#endif #undef PAVGB -H264_MC(put_, 4, 3dnow) -H264_MC(put_, 8, 3dnow) -H264_MC(put_, 16,3dnow) -H264_MC(avg_, 4, 3dnow) -H264_MC(avg_, 8, 3dnow) -H264_MC(avg_, 16,3dnow) -H264_MC(put_, 4, mmx2) -H264_MC(put_, 8, mmx2) -H264_MC(put_, 16,mmx2) -H264_MC(avg_, 4, mmx2) -H264_MC(avg_, 8, mmx2) -H264_MC(avg_, 16,mmx2) +H264_MC_4816(3dnow) +H264_MC_4816(mmx2) +H264_MC_816(H264_MC_V, sse2) +H264_MC_816(H264_MC_HV, sse2) +#ifdef HAVE_SSSE3 +H264_MC_816(H264_MC_H, ssse3) +H264_MC_816(H264_MC_HV, ssse3) +#endif #define H264_CHROMA_OP(S,D) @@ -1383,6 +1915,16 @@ H264_MC(avg_, 16,mmx2) #define H264_CHROMA_MC2_TMPL put_h264_chroma_mc2_mmx2 #define H264_CHROMA_MC8_MV0 put_pixels8_mmx #include "dsputil_h264_template_mmx.c" + +static void put_h264_chroma_mc8_mmx_rnd(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y) +{ + put_h264_chroma_mc8_mmx(dst, src, stride, h, x, y, 1); +} +static void put_h264_chroma_mc8_mmx_nornd(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y) +{ + put_h264_chroma_mc8_mmx(dst, src, stride, h, x, y, 0); +} + #undef H264_CHROMA_OP #undef H264_CHROMA_OP4 #undef H264_CHROMA_MC8_TMPL @@ -1398,6 +1940,10 @@ H264_MC(avg_, 16,mmx2) #define H264_CHROMA_MC2_TMPL avg_h264_chroma_mc2_mmx2 #define H264_CHROMA_MC8_MV0 avg_pixels8_mmx2 #include "dsputil_h264_template_mmx.c" +static void avg_h264_chroma_mc8_mmx2_rnd(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y) +{ + avg_h264_chroma_mc8_mmx2(dst, src, stride, h, x, y, 1); +} #undef H264_CHROMA_OP #undef H264_CHROMA_OP4 #undef H264_CHROMA_MC8_TMPL @@ -1412,6 +1958,10 @@ H264_MC(avg_, 16,mmx2) #define H264_CHROMA_MC4_TMPL avg_h264_chroma_mc4_3dnow #define H264_CHROMA_MC8_MV0 avg_pixels8_3dnow #include "dsputil_h264_template_mmx.c" +static void avg_h264_chroma_mc8_3dnow_rnd(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y) +{ + avg_h264_chroma_mc8_3dnow(dst, src, stride, h, x, y, 1); +} #undef H264_CHROMA_OP #undef H264_CHROMA_OP4 #undef H264_CHROMA_MC8_TMPL diff --git a/contrib/ffmpeg/libavcodec/i386/idct_mmx.c b/contrib/ffmpeg/libavcodec/i386/idct_mmx.c index 4c548fdce..005a42ded 100644 --- a/contrib/ffmpeg/libavcodec/i386/idct_mmx.c +++ b/contrib/ffmpeg/libavcodec/i386/idct_mmx.c @@ -20,7 +20,7 @@ */ #include "common.h" -#include "../dsputil.h" +#include "dsputil.h" #include "mmx.h" @@ -33,7 +33,7 @@ #define rounder(bias) {round (bias), round (bias)} #if 0 -/* C row IDCT - its just here to document the MMXEXT and MMX versions */ +/* C row IDCT - it is just here to document the MMXEXT and MMX versions */ static inline void idct_row (int16_t * row, int offset, int16_t * table, int32_t * rounder) { @@ -85,102 +85,102 @@ static inline void idct_row (int16_t * row, int offset, static inline void mmxext_row_head (int16_t * row, int offset, const int16_t * table) { - movq_m2r (*(row+offset), mm2); // mm2 = x6 x4 x2 x0 + movq_m2r (*(row+offset), mm2); /* mm2 = x6 x4 x2 x0 */ - movq_m2r (*(row+offset+4), mm5); // mm5 = x7 x5 x3 x1 - movq_r2r (mm2, mm0); // mm0 = x6 x4 x2 x0 + movq_m2r (*(row+offset+4), mm5); /* mm5 = x7 x5 x3 x1 */ + movq_r2r (mm2, mm0); /* mm0 = x6 x4 x2 x0 */ - movq_m2r (*table, mm3); // mm3 = -C2 -C4 C2 C4 - movq_r2r (mm5, mm6); // mm6 = x7 x5 x3 x1 + movq_m2r (*table, mm3); /* mm3 = -C2 -C4 C2 C4 */ + movq_r2r (mm5, mm6); /* mm6 = x7 x5 x3 x1 */ - movq_m2r (*(table+4), mm4); // mm4 = C6 C4 C6 C4 - pmaddwd_r2r (mm0, mm3); // mm3 = -C4*x4-C2*x6 C4*x0+C2*x2 + movq_m2r (*(table+4), mm4); /* mm4 = C6 C4 C6 C4 */ + pmaddwd_r2r (mm0, mm3); /* mm3 = -C4*x4-C2*x6 C4*x0+C2*x2 */ - pshufw_r2r (mm2, mm2, 0x4e); // mm2 = x2 x0 x6 x4 + pshufw_r2r (mm2, mm2, 0x4e); /* mm2 = x2 x0 x6 x4 */ } static inline void mmxext_row (const int16_t * table, const int32_t * rounder) { - movq_m2r (*(table+8), mm1); // mm1 = -C5 -C1 C3 C1 - pmaddwd_r2r (mm2, mm4); // mm4 = C4*x0+C6*x2 C4*x4+C6*x6 + movq_m2r (*(table+8), mm1); /* mm1 = -C5 -C1 C3 C1 */ + pmaddwd_r2r (mm2, mm4); /* mm4 = C4*x0+C6*x2 C4*x4+C6*x6 */ - pmaddwd_m2r (*(table+16), mm0); // mm0 = C4*x4-C6*x6 C4*x0-C6*x2 - pshufw_r2r (mm6, mm6, 0x4e); // mm6 = x3 x1 x7 x5 + pmaddwd_m2r (*(table+16), mm0); /* mm0 = C4*x4-C6*x6 C4*x0-C6*x2 */ + pshufw_r2r (mm6, mm6, 0x4e); /* mm6 = x3 x1 x7 x5 */ - movq_m2r (*(table+12), mm7); // mm7 = -C7 C3 C7 C5 - pmaddwd_r2r (mm5, mm1); // mm1 = -C1*x5-C5*x7 C1*x1+C3*x3 + movq_m2r (*(table+12), mm7); /* mm7 = -C7 C3 C7 C5 */ + pmaddwd_r2r (mm5, mm1); /* mm1 = -C1*x5-C5*x7 C1*x1+C3*x3 */ - paddd_m2r (*rounder, mm3); // mm3 += rounder - pmaddwd_r2r (mm6, mm7); // mm7 = C3*x1-C7*x3 C5*x5+C7*x7 + paddd_m2r (*rounder, mm3); /* mm3 += rounder */ + pmaddwd_r2r (mm6, mm7); /* mm7 = C3*x1-C7*x3 C5*x5+C7*x7 */ - pmaddwd_m2r (*(table+20), mm2); // mm2 = C4*x0-C2*x2 -C4*x4+C2*x6 - paddd_r2r (mm4, mm3); // mm3 = a1 a0 + rounder + pmaddwd_m2r (*(table+20), mm2); /* mm2 = C4*x0-C2*x2 -C4*x4+C2*x6 */ + paddd_r2r (mm4, mm3); /* mm3 = a1 a0 + rounder */ - pmaddwd_m2r (*(table+24), mm5); // mm5 = C3*x5-C1*x7 C5*x1-C1*x3 - movq_r2r (mm3, mm4); // mm4 = a1 a0 + rounder + pmaddwd_m2r (*(table+24), mm5); /* mm5 = C3*x5-C1*x7 C5*x1-C1*x3 */ + movq_r2r (mm3, mm4); /* mm4 = a1 a0 + rounder */ - pmaddwd_m2r (*(table+28), mm6); // mm6 = C7*x1-C5*x3 C7*x5+C3*x7 - paddd_r2r (mm7, mm1); // mm1 = b1 b0 + pmaddwd_m2r (*(table+28), mm6); /* mm6 = C7*x1-C5*x3 C7*x5+C3*x7 */ + paddd_r2r (mm7, mm1); /* mm1 = b1 b0 */ - paddd_m2r (*rounder, mm0); // mm0 += rounder - psubd_r2r (mm1, mm3); // mm3 = a1-b1 a0-b0 + rounder + paddd_m2r (*rounder, mm0); /* mm0 += rounder */ + psubd_r2r (mm1, mm3); /* mm3 = a1-b1 a0-b0 + rounder */ - psrad_i2r (ROW_SHIFT, mm3); // mm3 = y6 y7 - paddd_r2r (mm4, mm1); // mm1 = a1+b1 a0+b0 + rounder + psrad_i2r (ROW_SHIFT, mm3); /* mm3 = y6 y7 */ + paddd_r2r (mm4, mm1); /* mm1 = a1+b1 a0+b0 + rounder */ - paddd_r2r (mm2, mm0); // mm0 = a3 a2 + rounder - psrad_i2r (ROW_SHIFT, mm1); // mm1 = y1 y0 + paddd_r2r (mm2, mm0); /* mm0 = a3 a2 + rounder */ + psrad_i2r (ROW_SHIFT, mm1); /* mm1 = y1 y0 */ - paddd_r2r (mm6, mm5); // mm5 = b3 b2 - movq_r2r (mm0, mm4); // mm4 = a3 a2 + rounder + paddd_r2r (mm6, mm5); /* mm5 = b3 b2 */ + movq_r2r (mm0, mm4); /* mm4 = a3 a2 + rounder */ - paddd_r2r (mm5, mm0); // mm0 = a3+b3 a2+b2 + rounder - psubd_r2r (mm5, mm4); // mm4 = a3-b3 a2-b2 + rounder + paddd_r2r (mm5, mm0); /* mm0 = a3+b3 a2+b2 + rounder */ + psubd_r2r (mm5, mm4); /* mm4 = a3-b3 a2-b2 + rounder */ } static inline void mmxext_row_tail (int16_t * row, int store) { - psrad_i2r (ROW_SHIFT, mm0); // mm0 = y3 y2 + psrad_i2r (ROW_SHIFT, mm0); /* mm0 = y3 y2 */ - psrad_i2r (ROW_SHIFT, mm4); // mm4 = y4 y5 + psrad_i2r (ROW_SHIFT, mm4); /* mm4 = y4 y5 */ - packssdw_r2r (mm0, mm1); // mm1 = y3 y2 y1 y0 + packssdw_r2r (mm0, mm1); /* mm1 = y3 y2 y1 y0 */ - packssdw_r2r (mm3, mm4); // mm4 = y6 y7 y4 y5 + packssdw_r2r (mm3, mm4); /* mm4 = y6 y7 y4 y5 */ - movq_r2m (mm1, *(row+store)); // save y3 y2 y1 y0 - pshufw_r2r (mm4, mm4, 0xb1); // mm4 = y7 y6 y5 y4 + movq_r2m (mm1, *(row+store)); /* save y3 y2 y1 y0 */ + pshufw_r2r (mm4, mm4, 0xb1); /* mm4 = y7 y6 y5 y4 */ /* slot */ - movq_r2m (mm4, *(row+store+4)); // save y7 y6 y5 y4 + movq_r2m (mm4, *(row+store+4)); /* save y7 y6 y5 y4 */ } static inline void mmxext_row_mid (int16_t * row, int store, int offset, const int16_t * table) { - movq_m2r (*(row+offset), mm2); // mm2 = x6 x4 x2 x0 - psrad_i2r (ROW_SHIFT, mm0); // mm0 = y3 y2 + movq_m2r (*(row+offset), mm2); /* mm2 = x6 x4 x2 x0 */ + psrad_i2r (ROW_SHIFT, mm0); /* mm0 = y3 y2 */ - movq_m2r (*(row+offset+4), mm5); // mm5 = x7 x5 x3 x1 - psrad_i2r (ROW_SHIFT, mm4); // mm4 = y4 y5 + movq_m2r (*(row+offset+4), mm5); /* mm5 = x7 x5 x3 x1 */ + psrad_i2r (ROW_SHIFT, mm4); /* mm4 = y4 y5 */ - packssdw_r2r (mm0, mm1); // mm1 = y3 y2 y1 y0 - movq_r2r (mm5, mm6); // mm6 = x7 x5 x3 x1 + packssdw_r2r (mm0, mm1); /* mm1 = y3 y2 y1 y0 */ + movq_r2r (mm5, mm6); /* mm6 = x7 x5 x3 x1 */ - packssdw_r2r (mm3, mm4); // mm4 = y6 y7 y4 y5 - movq_r2r (mm2, mm0); // mm0 = x6 x4 x2 x0 + packssdw_r2r (mm3, mm4); /* mm4 = y6 y7 y4 y5 */ + movq_r2r (mm2, mm0); /* mm0 = x6 x4 x2 x0 */ - movq_r2m (mm1, *(row+store)); // save y3 y2 y1 y0 - pshufw_r2r (mm4, mm4, 0xb1); // mm4 = y7 y6 y5 y4 + movq_r2m (mm1, *(row+store)); /* save y3 y2 y1 y0 */ + pshufw_r2r (mm4, mm4, 0xb1); /* mm4 = y7 y6 y5 y4 */ - movq_m2r (*table, mm3); // mm3 = -C2 -C4 C2 C4 - movq_r2m (mm4, *(row+store+4)); // save y7 y6 y5 y4 + movq_m2r (*table, mm3); /* mm3 = -C2 -C4 C2 C4 */ + movq_r2m (mm4, *(row+store+4)); /* save y7 y6 y5 y4 */ - pmaddwd_r2r (mm0, mm3); // mm3 = -C4*x4-C2*x6 C4*x0+C2*x2 + pmaddwd_r2r (mm0, mm3); /* mm3 = -C4*x4-C2*x6 C4*x0+C2*x2 */ - movq_m2r (*(table+4), mm4); // mm4 = C6 C4 C6 C4 - pshufw_r2r (mm2, mm2, 0x4e); // mm2 = x2 x0 x6 x4 + movq_m2r (*(table+4), mm4); /* mm4 = C6 C4 C6 C4 */ + pshufw_r2r (mm2, mm2, 0x4e); /* mm2 = x2 x0 x6 x4 */ } @@ -197,123 +197,123 @@ static inline void mmxext_row_mid (int16_t * row, int store, static inline void mmx_row_head (int16_t * row, int offset, const int16_t * table) { - movq_m2r (*(row+offset), mm2); // mm2 = x6 x4 x2 x0 + movq_m2r (*(row+offset), mm2); /* mm2 = x6 x4 x2 x0 */ - movq_m2r (*(row+offset+4), mm5); // mm5 = x7 x5 x3 x1 - movq_r2r (mm2, mm0); // mm0 = x6 x4 x2 x0 + movq_m2r (*(row+offset+4), mm5); /* mm5 = x7 x5 x3 x1 */ + movq_r2r (mm2, mm0); /* mm0 = x6 x4 x2 x0 */ - movq_m2r (*table, mm3); // mm3 = C6 C4 C2 C4 - movq_r2r (mm5, mm6); // mm6 = x7 x5 x3 x1 + movq_m2r (*table, mm3); /* mm3 = C6 C4 C2 C4 */ + movq_r2r (mm5, mm6); /* mm6 = x7 x5 x3 x1 */ - punpckldq_r2r (mm0, mm0); // mm0 = x2 x0 x2 x0 + punpckldq_r2r (mm0, mm0); /* mm0 = x2 x0 x2 x0 */ - movq_m2r (*(table+4), mm4); // mm4 = -C2 -C4 C6 C4 - pmaddwd_r2r (mm0, mm3); // mm3 = C4*x0+C6*x2 C4*x0+C2*x2 + movq_m2r (*(table+4), mm4); /* mm4 = -C2 -C4 C6 C4 */ + pmaddwd_r2r (mm0, mm3); /* mm3 = C4*x0+C6*x2 C4*x0+C2*x2 */ - movq_m2r (*(table+8), mm1); // mm1 = -C7 C3 C3 C1 - punpckhdq_r2r (mm2, mm2); // mm2 = x6 x4 x6 x4 + movq_m2r (*(table+8), mm1); /* mm1 = -C7 C3 C3 C1 */ + punpckhdq_r2r (mm2, mm2); /* mm2 = x6 x4 x6 x4 */ } static inline void mmx_row (const int16_t * table, const int32_t * rounder) { - pmaddwd_r2r (mm2, mm4); // mm4 = -C4*x4-C2*x6 C4*x4+C6*x6 - punpckldq_r2r (mm5, mm5); // mm5 = x3 x1 x3 x1 + pmaddwd_r2r (mm2, mm4); /* mm4 = -C4*x4-C2*x6 C4*x4+C6*x6 */ + punpckldq_r2r (mm5, mm5); /* mm5 = x3 x1 x3 x1 */ - pmaddwd_m2r (*(table+16), mm0); // mm0 = C4*x0-C2*x2 C4*x0-C6*x2 - punpckhdq_r2r (mm6, mm6); // mm6 = x7 x5 x7 x5 + pmaddwd_m2r (*(table+16), mm0); /* mm0 = C4*x0-C2*x2 C4*x0-C6*x2 */ + punpckhdq_r2r (mm6, mm6); /* mm6 = x7 x5 x7 x5 */ - movq_m2r (*(table+12), mm7); // mm7 = -C5 -C1 C7 C5 - pmaddwd_r2r (mm5, mm1); // mm1 = C3*x1-C7*x3 C1*x1+C3*x3 + movq_m2r (*(table+12), mm7); /* mm7 = -C5 -C1 C7 C5 */ + pmaddwd_r2r (mm5, mm1); /* mm1 = C3*x1-C7*x3 C1*x1+C3*x3 */ - paddd_m2r (*rounder, mm3); // mm3 += rounder - pmaddwd_r2r (mm6, mm7); // mm7 = -C1*x5-C5*x7 C5*x5+C7*x7 + paddd_m2r (*rounder, mm3); /* mm3 += rounder */ + pmaddwd_r2r (mm6, mm7); /* mm7 = -C1*x5-C5*x7 C5*x5+C7*x7 */ - pmaddwd_m2r (*(table+20), mm2); // mm2 = C4*x4-C6*x6 -C4*x4+C2*x6 - paddd_r2r (mm4, mm3); // mm3 = a1 a0 + rounder + pmaddwd_m2r (*(table+20), mm2); /* mm2 = C4*x4-C6*x6 -C4*x4+C2*x6 */ + paddd_r2r (mm4, mm3); /* mm3 = a1 a0 + rounder */ - pmaddwd_m2r (*(table+24), mm5); // mm5 = C7*x1-C5*x3 C5*x1-C1*x3 - movq_r2r (mm3, mm4); // mm4 = a1 a0 + rounder + pmaddwd_m2r (*(table+24), mm5); /* mm5 = C7*x1-C5*x3 C5*x1-C1*x3 */ + movq_r2r (mm3, mm4); /* mm4 = a1 a0 + rounder */ - pmaddwd_m2r (*(table+28), mm6); // mm6 = C3*x5-C1*x7 C7*x5+C3*x7 - paddd_r2r (mm7, mm1); // mm1 = b1 b0 + pmaddwd_m2r (*(table+28), mm6); /* mm6 = C3*x5-C1*x7 C7*x5+C3*x7 */ + paddd_r2r (mm7, mm1); /* mm1 = b1 b0 */ - paddd_m2r (*rounder, mm0); // mm0 += rounder - psubd_r2r (mm1, mm3); // mm3 = a1-b1 a0-b0 + rounder + paddd_m2r (*rounder, mm0); /* mm0 += rounder */ + psubd_r2r (mm1, mm3); /* mm3 = a1-b1 a0-b0 + rounder */ - psrad_i2r (ROW_SHIFT, mm3); // mm3 = y6 y7 - paddd_r2r (mm4, mm1); // mm1 = a1+b1 a0+b0 + rounder + psrad_i2r (ROW_SHIFT, mm3); /* mm3 = y6 y7 */ + paddd_r2r (mm4, mm1); /* mm1 = a1+b1 a0+b0 + rounder */ - paddd_r2r (mm2, mm0); // mm0 = a3 a2 + rounder - psrad_i2r (ROW_SHIFT, mm1); // mm1 = y1 y0 + paddd_r2r (mm2, mm0); /* mm0 = a3 a2 + rounder */ + psrad_i2r (ROW_SHIFT, mm1); /* mm1 = y1 y0 */ - paddd_r2r (mm6, mm5); // mm5 = b3 b2 - movq_r2r (mm0, mm7); // mm7 = a3 a2 + rounder + paddd_r2r (mm6, mm5); /* mm5 = b3 b2 */ + movq_r2r (mm0, mm7); /* mm7 = a3 a2 + rounder */ - paddd_r2r (mm5, mm0); // mm0 = a3+b3 a2+b2 + rounder - psubd_r2r (mm5, mm7); // mm7 = a3-b3 a2-b2 + rounder + paddd_r2r (mm5, mm0); /* mm0 = a3+b3 a2+b2 + rounder */ + psubd_r2r (mm5, mm7); /* mm7 = a3-b3 a2-b2 + rounder */ } static inline void mmx_row_tail (int16_t * row, int store) { - psrad_i2r (ROW_SHIFT, mm0); // mm0 = y3 y2 + psrad_i2r (ROW_SHIFT, mm0); /* mm0 = y3 y2 */ - psrad_i2r (ROW_SHIFT, mm7); // mm7 = y4 y5 + psrad_i2r (ROW_SHIFT, mm7); /* mm7 = y4 y5 */ - packssdw_r2r (mm0, mm1); // mm1 = y3 y2 y1 y0 + packssdw_r2r (mm0, mm1); /* mm1 = y3 y2 y1 y0 */ - packssdw_r2r (mm3, mm7); // mm7 = y6 y7 y4 y5 + packssdw_r2r (mm3, mm7); /* mm7 = y6 y7 y4 y5 */ - movq_r2m (mm1, *(row+store)); // save y3 y2 y1 y0 - movq_r2r (mm7, mm4); // mm4 = y6 y7 y4 y5 + movq_r2m (mm1, *(row+store)); /* save y3 y2 y1 y0 */ + movq_r2r (mm7, mm4); /* mm4 = y6 y7 y4 y5 */ - pslld_i2r (16, mm7); // mm7 = y7 0 y5 0 + pslld_i2r (16, mm7); /* mm7 = y7 0 y5 0 */ - psrld_i2r (16, mm4); // mm4 = 0 y6 0 y4 + psrld_i2r (16, mm4); /* mm4 = 0 y6 0 y4 */ - por_r2r (mm4, mm7); // mm7 = y7 y6 y5 y4 + por_r2r (mm4, mm7); /* mm7 = y7 y6 y5 y4 */ /* slot */ - movq_r2m (mm7, *(row+store+4)); // save y7 y6 y5 y4 + movq_r2m (mm7, *(row+store+4)); /* save y7 y6 y5 y4 */ } static inline void mmx_row_mid (int16_t * row, int store, int offset, const int16_t * table) { - movq_m2r (*(row+offset), mm2); // mm2 = x6 x4 x2 x0 - psrad_i2r (ROW_SHIFT, mm0); // mm0 = y3 y2 + movq_m2r (*(row+offset), mm2); /* mm2 = x6 x4 x2 x0 */ + psrad_i2r (ROW_SHIFT, mm0); /* mm0 = y3 y2 */ - movq_m2r (*(row+offset+4), mm5); // mm5 = x7 x5 x3 x1 - psrad_i2r (ROW_SHIFT, mm7); // mm7 = y4 y5 + movq_m2r (*(row+offset+4), mm5); /* mm5 = x7 x5 x3 x1 */ + psrad_i2r (ROW_SHIFT, mm7); /* mm7 = y4 y5 */ - packssdw_r2r (mm0, mm1); // mm1 = y3 y2 y1 y0 - movq_r2r (mm5, mm6); // mm6 = x7 x5 x3 x1 + packssdw_r2r (mm0, mm1); /* mm1 = y3 y2 y1 y0 */ + movq_r2r (mm5, mm6); /* mm6 = x7 x5 x3 x1 */ - packssdw_r2r (mm3, mm7); // mm7 = y6 y7 y4 y5 - movq_r2r (mm2, mm0); // mm0 = x6 x4 x2 x0 + packssdw_r2r (mm3, mm7); /* mm7 = y6 y7 y4 y5 */ + movq_r2r (mm2, mm0); /* mm0 = x6 x4 x2 x0 */ - movq_r2m (mm1, *(row+store)); // save y3 y2 y1 y0 - movq_r2r (mm7, mm1); // mm1 = y6 y7 y4 y5 + movq_r2m (mm1, *(row+store)); /* save y3 y2 y1 y0 */ + movq_r2r (mm7, mm1); /* mm1 = y6 y7 y4 y5 */ - punpckldq_r2r (mm0, mm0); // mm0 = x2 x0 x2 x0 - psrld_i2r (16, mm7); // mm7 = 0 y6 0 y4 + punpckldq_r2r (mm0, mm0); /* mm0 = x2 x0 x2 x0 */ + psrld_i2r (16, mm7); /* mm7 = 0 y6 0 y4 */ - movq_m2r (*table, mm3); // mm3 = C6 C4 C2 C4 - pslld_i2r (16, mm1); // mm1 = y7 0 y5 0 + movq_m2r (*table, mm3); /* mm3 = C6 C4 C2 C4 */ + pslld_i2r (16, mm1); /* mm1 = y7 0 y5 0 */ - movq_m2r (*(table+4), mm4); // mm4 = -C2 -C4 C6 C4 - por_r2r (mm1, mm7); // mm7 = y7 y6 y5 y4 + movq_m2r (*(table+4), mm4); /* mm4 = -C2 -C4 C6 C4 */ + por_r2r (mm1, mm7); /* mm7 = y7 y6 y5 y4 */ - movq_m2r (*(table+8), mm1); // mm1 = -C7 C3 C3 C1 - punpckhdq_r2r (mm2, mm2); // mm2 = x6 x4 x6 x4 + movq_m2r (*(table+8), mm1); /* mm1 = -C7 C3 C3 C1 */ + punpckhdq_r2r (mm2, mm2); /* mm2 = x6 x4 x6 x4 */ - movq_r2m (mm7, *(row+store+4)); // save y7 y6 y5 y4 - pmaddwd_r2r (mm0, mm3); // mm3 = C4*x0+C6*x2 C4*x0+C2*x2 + movq_r2m (mm7, *(row+store+4)); /* save y7 y6 y5 y4 */ + pmaddwd_r2r (mm0, mm3); /* mm3 = C4*x0+C6*x2 C4*x0+C2*x2 */ } #if 0 -// C column IDCT - its just here to document the MMXEXT and MMX versions +/* C column IDCT - it is just here to document the MMXEXT and MMX versions */ static inline void idct_col (int16_t * col, int offset) { /* multiplication - as implemented on mmx */ @@ -384,7 +384,7 @@ static inline void idct_col (int16_t * col, int offset) #endif -// MMX column IDCT +/* MMX column IDCT */ static inline void idct_col (int16_t * col, int offset) { #define T1 13036 @@ -392,140 +392,140 @@ static inline void idct_col (int16_t * col, int offset) #define T3 43790 #define C4 23170 - static const short _T1[] ATTR_ALIGN(8) = {T1,T1,T1,T1}; - static const short _T2[] ATTR_ALIGN(8) = {T2,T2,T2,T2}; - static const short _T3[] ATTR_ALIGN(8) = {T3,T3,T3,T3}; - static const short _C4[] ATTR_ALIGN(8) = {C4,C4,C4,C4}; + static const short t1_vector[] ATTR_ALIGN(8) = {T1,T1,T1,T1}; + static const short t2_vector[] ATTR_ALIGN(8) = {T2,T2,T2,T2}; + static const short t3_vector[] ATTR_ALIGN(8) = {T3,T3,T3,T3}; + static const short c4_vector[] ATTR_ALIGN(8) = {C4,C4,C4,C4}; - /* column code adapted from peter gubanov */ + /* column code adapted from Peter Gubanov */ /* http://www.elecard.com/peter/idct.shtml */ - movq_m2r (*_T1, mm0); // mm0 = T1 + movq_m2r (*t1_vector, mm0); /* mm0 = T1 */ - movq_m2r (*(col+offset+1*8), mm1); // mm1 = x1 - movq_r2r (mm0, mm2); // mm2 = T1 + movq_m2r (*(col+offset+1*8), mm1); /* mm1 = x1 */ + movq_r2r (mm0, mm2); /* mm2 = T1 */ - movq_m2r (*(col+offset+7*8), mm4); // mm4 = x7 - pmulhw_r2r (mm1, mm0); // mm0 = T1*x1 + movq_m2r (*(col+offset+7*8), mm4); /* mm4 = x7 */ + pmulhw_r2r (mm1, mm0); /* mm0 = T1*x1 */ - movq_m2r (*_T3, mm5); // mm5 = T3 - pmulhw_r2r (mm4, mm2); // mm2 = T1*x7 + movq_m2r (*t3_vector, mm5); /* mm5 = T3 */ + pmulhw_r2r (mm4, mm2); /* mm2 = T1*x7 */ - movq_m2r (*(col+offset+5*8), mm6); // mm6 = x5 - movq_r2r (mm5, mm7); // mm7 = T3-1 + movq_m2r (*(col+offset+5*8), mm6); /* mm6 = x5 */ + movq_r2r (mm5, mm7); /* mm7 = T3-1 */ - movq_m2r (*(col+offset+3*8), mm3); // mm3 = x3 - psubsw_r2r (mm4, mm0); // mm0 = v17 + movq_m2r (*(col+offset+3*8), mm3); /* mm3 = x3 */ + psubsw_r2r (mm4, mm0); /* mm0 = v17 */ - movq_m2r (*_T2, mm4); // mm4 = T2 - pmulhw_r2r (mm3, mm5); // mm5 = (T3-1)*x3 + movq_m2r (*t2_vector, mm4); /* mm4 = T2 */ + pmulhw_r2r (mm3, mm5); /* mm5 = (T3-1)*x3 */ - paddsw_r2r (mm2, mm1); // mm1 = u17 - pmulhw_r2r (mm6, mm7); // mm7 = (T3-1)*x5 + paddsw_r2r (mm2, mm1); /* mm1 = u17 */ + pmulhw_r2r (mm6, mm7); /* mm7 = (T3-1)*x5 */ /* slot */ - movq_r2r (mm4, mm2); // mm2 = T2 - paddsw_r2r (mm3, mm5); // mm5 = T3*x3 + movq_r2r (mm4, mm2); /* mm2 = T2 */ + paddsw_r2r (mm3, mm5); /* mm5 = T3*x3 */ - pmulhw_m2r (*(col+offset+2*8), mm4);// mm4 = T2*x2 - paddsw_r2r (mm6, mm7); // mm7 = T3*x5 + pmulhw_m2r (*(col+offset+2*8), mm4);/* mm4 = T2*x2 */ + paddsw_r2r (mm6, mm7); /* mm7 = T3*x5 */ - psubsw_r2r (mm6, mm5); // mm5 = v35 - paddsw_r2r (mm3, mm7); // mm7 = u35 + psubsw_r2r (mm6, mm5); /* mm5 = v35 */ + paddsw_r2r (mm3, mm7); /* mm7 = u35 */ - movq_m2r (*(col+offset+6*8), mm3); // mm3 = x6 - movq_r2r (mm0, mm6); // mm6 = v17 + movq_m2r (*(col+offset+6*8), mm3); /* mm3 = x6 */ + movq_r2r (mm0, mm6); /* mm6 = v17 */ - pmulhw_r2r (mm3, mm2); // mm2 = T2*x6 - psubsw_r2r (mm5, mm0); // mm0 = b3 + pmulhw_r2r (mm3, mm2); /* mm2 = T2*x6 */ + psubsw_r2r (mm5, mm0); /* mm0 = b3 */ - psubsw_r2r (mm3, mm4); // mm4 = v26 - paddsw_r2r (mm6, mm5); // mm5 = v12 + psubsw_r2r (mm3, mm4); /* mm4 = v26 */ + paddsw_r2r (mm6, mm5); /* mm5 = v12 */ - movq_r2m (mm0, *(col+offset+3*8)); // save b3 in scratch0 - movq_r2r (mm1, mm6); // mm6 = u17 + movq_r2m (mm0, *(col+offset+3*8)); /* save b3 in scratch0 */ + movq_r2r (mm1, mm6); /* mm6 = u17 */ - paddsw_m2r (*(col+offset+2*8), mm2);// mm2 = u26 - paddsw_r2r (mm7, mm6); // mm6 = b0 + paddsw_m2r (*(col+offset+2*8), mm2);/* mm2 = u26 */ + paddsw_r2r (mm7, mm6); /* mm6 = b0 */ - psubsw_r2r (mm7, mm1); // mm1 = u12 - movq_r2r (mm1, mm7); // mm7 = u12 + psubsw_r2r (mm7, mm1); /* mm1 = u12 */ + movq_r2r (mm1, mm7); /* mm7 = u12 */ - movq_m2r (*(col+offset+0*8), mm3); // mm3 = x0 - paddsw_r2r (mm5, mm1); // mm1 = u12+v12 + movq_m2r (*(col+offset+0*8), mm3); /* mm3 = x0 */ + paddsw_r2r (mm5, mm1); /* mm1 = u12+v12 */ - movq_m2r (*_C4, mm0); // mm0 = C4/2 - psubsw_r2r (mm5, mm7); // mm7 = u12-v12 + movq_m2r (*c4_vector, mm0); /* mm0 = C4/2 */ + psubsw_r2r (mm5, mm7); /* mm7 = u12-v12 */ - movq_r2m (mm6, *(col+offset+5*8)); // save b0 in scratch1 - pmulhw_r2r (mm0, mm1); // mm1 = b1/2 + movq_r2m (mm6, *(col+offset+5*8)); /* save b0 in scratch1 */ + pmulhw_r2r (mm0, mm1); /* mm1 = b1/2 */ - movq_r2r (mm4, mm6); // mm6 = v26 - pmulhw_r2r (mm0, mm7); // mm7 = b2/2 + movq_r2r (mm4, mm6); /* mm6 = v26 */ + pmulhw_r2r (mm0, mm7); /* mm7 = b2/2 */ - movq_m2r (*(col+offset+4*8), mm5); // mm5 = x4 - movq_r2r (mm3, mm0); // mm0 = x0 + movq_m2r (*(col+offset+4*8), mm5); /* mm5 = x4 */ + movq_r2r (mm3, mm0); /* mm0 = x0 */ - psubsw_r2r (mm5, mm3); // mm3 = v04 - paddsw_r2r (mm5, mm0); // mm0 = u04 + psubsw_r2r (mm5, mm3); /* mm3 = v04 */ + paddsw_r2r (mm5, mm0); /* mm0 = u04 */ - paddsw_r2r (mm3, mm4); // mm4 = a1 - movq_r2r (mm0, mm5); // mm5 = u04 + paddsw_r2r (mm3, mm4); /* mm4 = a1 */ + movq_r2r (mm0, mm5); /* mm5 = u04 */ - psubsw_r2r (mm6, mm3); // mm3 = a2 - paddsw_r2r (mm2, mm5); // mm5 = a0 + psubsw_r2r (mm6, mm3); /* mm3 = a2 */ + paddsw_r2r (mm2, mm5); /* mm5 = a0 */ - paddsw_r2r (mm1, mm1); // mm1 = b1 - psubsw_r2r (mm2, mm0); // mm0 = a3 + paddsw_r2r (mm1, mm1); /* mm1 = b1 */ + psubsw_r2r (mm2, mm0); /* mm0 = a3 */ - paddsw_r2r (mm7, mm7); // mm7 = b2 - movq_r2r (mm3, mm2); // mm2 = a2 + paddsw_r2r (mm7, mm7); /* mm7 = b2 */ + movq_r2r (mm3, mm2); /* mm2 = a2 */ - movq_r2r (mm4, mm6); // mm6 = a1 - paddsw_r2r (mm7, mm3); // mm3 = a2+b2 + movq_r2r (mm4, mm6); /* mm6 = a1 */ + paddsw_r2r (mm7, mm3); /* mm3 = a2+b2 */ - psraw_i2r (COL_SHIFT, mm3); // mm3 = y2 - paddsw_r2r (mm1, mm4); // mm4 = a1+b1 + psraw_i2r (COL_SHIFT, mm3); /* mm3 = y2 */ + paddsw_r2r (mm1, mm4); /* mm4 = a1+b1 */ - psraw_i2r (COL_SHIFT, mm4); // mm4 = y1 - psubsw_r2r (mm1, mm6); // mm6 = a1-b1 + psraw_i2r (COL_SHIFT, mm4); /* mm4 = y1 */ + psubsw_r2r (mm1, mm6); /* mm6 = a1-b1 */ - movq_m2r (*(col+offset+5*8), mm1); // mm1 = b0 - psubsw_r2r (mm7, mm2); // mm2 = a2-b2 + movq_m2r (*(col+offset+5*8), mm1); /* mm1 = b0 */ + psubsw_r2r (mm7, mm2); /* mm2 = a2-b2 */ - psraw_i2r (COL_SHIFT, mm6); // mm6 = y6 - movq_r2r (mm5, mm7); // mm7 = a0 + psraw_i2r (COL_SHIFT, mm6); /* mm6 = y6 */ + movq_r2r (mm5, mm7); /* mm7 = a0 */ - movq_r2m (mm4, *(col+offset+1*8)); // save y1 - psraw_i2r (COL_SHIFT, mm2); // mm2 = y5 + movq_r2m (mm4, *(col+offset+1*8)); /* save y1 */ + psraw_i2r (COL_SHIFT, mm2); /* mm2 = y5 */ - movq_r2m (mm3, *(col+offset+2*8)); // save y2 - paddsw_r2r (mm1, mm5); // mm5 = a0+b0 + movq_r2m (mm3, *(col+offset+2*8)); /* save y2 */ + paddsw_r2r (mm1, mm5); /* mm5 = a0+b0 */ - movq_m2r (*(col+offset+3*8), mm4); // mm4 = b3 - psubsw_r2r (mm1, mm7); // mm7 = a0-b0 + movq_m2r (*(col+offset+3*8), mm4); /* mm4 = b3 */ + psubsw_r2r (mm1, mm7); /* mm7 = a0-b0 */ - psraw_i2r (COL_SHIFT, mm5); // mm5 = y0 - movq_r2r (mm0, mm3); // mm3 = a3 + psraw_i2r (COL_SHIFT, mm5); /* mm5 = y0 */ + movq_r2r (mm0, mm3); /* mm3 = a3 */ - movq_r2m (mm2, *(col+offset+5*8)); // save y5 - psubsw_r2r (mm4, mm3); // mm3 = a3-b3 + movq_r2m (mm2, *(col+offset+5*8)); /* save y5 */ + psubsw_r2r (mm4, mm3); /* mm3 = a3-b3 */ - psraw_i2r (COL_SHIFT, mm7); // mm7 = y7 - paddsw_r2r (mm0, mm4); // mm4 = a3+b3 + psraw_i2r (COL_SHIFT, mm7); /* mm7 = y7 */ + paddsw_r2r (mm0, mm4); /* mm4 = a3+b3 */ - movq_r2m (mm5, *(col+offset+0*8)); // save y0 - psraw_i2r (COL_SHIFT, mm3); // mm3 = y4 + movq_r2m (mm5, *(col+offset+0*8)); /* save y0 */ + psraw_i2r (COL_SHIFT, mm3); /* mm3 = y4 */ - movq_r2m (mm6, *(col+offset+6*8)); // save y6 - psraw_i2r (COL_SHIFT, mm4); // mm4 = y3 + movq_r2m (mm6, *(col+offset+6*8)); /* save y6 */ + psraw_i2r (COL_SHIFT, mm4); /* mm4 = y3 */ - movq_r2m (mm7, *(col+offset+7*8)); // save y7 + movq_r2m (mm7, *(col+offset+7*8)); /* save y7 */ - movq_r2m (mm3, *(col+offset+4*8)); // save y4 + movq_r2m (mm3, *(col+offset+4*8)); /* save y4 */ - movq_r2m (mm4, *(col+offset+3*8)); // save y3 + movq_r2m (mm4, *(col+offset+3*8)); /* save y3 */ #undef T1 #undef T2 diff --git a/contrib/ffmpeg/libavcodec/i386/idct_mmx_xvid.c b/contrib/ffmpeg/libavcodec/i386/idct_mmx_xvid.c index 85cfbc9cd..15e5290e7 100644 --- a/contrib/ffmpeg/libavcodec/i386/idct_mmx_xvid.c +++ b/contrib/ffmpeg/libavcodec/i386/idct_mmx_xvid.c @@ -1,56 +1,46 @@ -///**************************************************************************** -// * -// * XVID MPEG-4 VIDEO CODEC -// * - MMX and XMM forward discrete cosine transform - -// * -// * Copyright(C) 2001 Peter Ross -// * -// * This file is part of FFmpeg. -// * -// * FFmpeg 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. -// * -// * FFmpeg 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 FFmpeg; if not, write to the Free Software Foundation, -// * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -// * -// * $Id: idct_mmx_xvid.c 6577 2006-10-07 15:30:46Z diego $ -// * -// ***************************************************************************/ - -// **************************************************************************** -// -// Originally provided by Intel at AP-922 -// http://developer.intel.com/vtune/cbts/strmsimd/922down.htm -// (See more app notes at http://developer.intel.com/vtune/cbts/strmsimd/appnotes.htm) -// but in a limited edition. -// New macro implements a column part for precise iDCT -// The routine precision now satisfies IEEE standard 1180-1990. -// -// Copyright(C) 2000-2001 Peter Gubanov -// Rounding trick Copyright(C) 2000 Michel Lespinasse -// -// http://www.elecard.com/peter/idct.html -// http://www.linuxvideo.org/mpeg2dec/ -// -// ***************************************************************************/ -// -// These examples contain code fragments for first stage iDCT 8x8 -// (for rows) and first stage DCT 8x8 (for columns) -// - -// conversion to gcc syntax by michael niedermayer - +/* + * XVID MPEG-4 VIDEO CODEC + * - MMX and XMM forward discrete cosine transform - + * + * Copyright(C) 2001 Peter Ross + * + * Originally provided by Intel at AP-922 + * http://developer.intel.com/vtune/cbts/strmsimd/922down.htm + * (See more app notes at http://developer.intel.com/vtune/cbts/strmsimd/appnotes.htm) + * but in a limited edition. + * New macro implements a column part for precise iDCT + * The routine precision now satisfies IEEE standard 1180-1990. + * + * Copyright(C) 2000-2001 Peter Gubanov + * Rounding trick Copyright(C) 2000 Michel Lespinasse + * + * http://www.elecard.com/peter/idct.html + * http://www.linuxvideo.org/mpeg2dec/ + * + * These examples contain code fragments for first stage iDCT 8x8 + * (for rows) and first stage DCT 8x8 (for columns) + * + * conversion to gcc syntax by Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ #include -#include "../avcodec.h" +#include "avcodec.h" //============================================================================= // Macros and other preprocessor constants @@ -74,13 +64,13 @@ //----------------------------------------------------------------------------- -static const int16_t tg_1_16[4*4] attribute_used __attribute__ ((aligned(8))) = { +DECLARE_ALIGNED(8, static const int16_t, tg_1_16[4*4]) = { 13036,13036,13036,13036, // tg * (2<<16) + 0.5 27146,27146,27146,27146, // tg * (2<<16) + 0.5 -21746,-21746,-21746,-21746, // tg * (2<<16) + 0.5 23170,23170,23170,23170}; // cos * (2<<15) + 0.5 -static const int32_t rounder_0[2*8] attribute_used __attribute__ ((aligned(8))) = { +DECLARE_ALIGNED(8, static const int32_t, rounder_0[2*8]) = { 65536,65536, 3597,3597, 2260,2260, @@ -150,7 +140,7 @@ static const int32_t rounder_0[2*8] attribute_used __attribute__ ((aligned(8))) //----------------------------------------------------------------------------- // Table for rows 0,4 - constants are multiplied by cos_4_16 -static const int16_t tab_i_04_mmx[32*4] attribute_used __attribute__ ((aligned(8))) = { +DECLARE_ALIGNED(8, static const int16_t, tab_i_04_mmx[32*4]) = { 16384,16384,16384,-16384, // movq-> w06 w04 w02 w00 21407,8867,8867,-21407, // w07 w05 w03 w01 16384,-16384,16384,16384, // w14 w12 w10 w08 @@ -192,7 +182,7 @@ static const int16_t tab_i_04_mmx[32*4] attribute_used __attribute__ ((aligned(8 //----------------------------------------------------------------------------- // %3 for rows 0,4 - constants are multiplied by cos_4_16 -static const int16_t tab_i_04_xmm[32*4] attribute_used __attribute__ ((aligned(8))) = { +DECLARE_ALIGNED(8, static const int16_t, tab_i_04_xmm[32*4]) = { 16384,21407,16384,8867, // movq-> w05 w04 w01 w00 16384,8867,-16384,-21407, // w07 w06 w03 w02 16384,-8867,16384,-21407, // w13 w12 w09 w08 diff --git a/contrib/ffmpeg/libavcodec/i386/mathops.h b/contrib/ffmpeg/libavcodec/i386/mathops.h index 3553a4025..51d59396e 100644 --- a/contrib/ffmpeg/libavcodec/i386/mathops.h +++ b/contrib/ffmpeg/libavcodec/i386/mathops.h @@ -19,6 +19,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef FFMPEG_I386_MATHOPS_H +#define FFMPEG_I386_MATHOPS_H + #ifdef FRAC_BITS # define MULL(ra, rb) \ ({ int rt, dummy; asm (\ @@ -39,3 +42,4 @@ asm ("imull %2\n\t" : "=A"(rt) : "a" (ra), "g" (rb));\ rt; }) +#endif /* FFMPEG_I386_MATHOPS_H */ diff --git a/contrib/ffmpeg/libavcodec/i386/mmx.h b/contrib/ffmpeg/libavcodec/i386/mmx.h index 41aae6c21..2e029d1aa 100644 --- a/contrib/ffmpeg/libavcodec/i386/mmx.h +++ b/contrib/ffmpeg/libavcodec/i386/mmx.h @@ -18,8 +18,10 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVCODEC_I386MMX_H -#define AVCODEC_I386MMX_H +#ifndef FFMPEG_MMX_H +#define FFMPEG_MMX_H + +#warning Everything in this header is deprecated, use plain asm()! New code using this header will be rejected. /* * The type of an value that fits in an MMX register (note that long @@ -280,4 +282,4 @@ typedef union { #define punpckhqdq_r2r(regs,regd) mmx_r2r (punpckhqdq, regs, regd) -#endif /* AVCODEC_I386MMX_H */ +#endif /* FFMPEG_MMX_H */ diff --git a/contrib/ffmpeg/libavcodec/i386/motion_est_mmx.c b/contrib/ffmpeg/libavcodec/i386/motion_est_mmx.c index e33870e0f..888d891d9 100644 --- a/contrib/ffmpeg/libavcodec/i386/motion_est_mmx.c +++ b/contrib/ffmpeg/libavcodec/i386/motion_est_mmx.c @@ -3,6 +3,8 @@ * Copyright (c) 2001 Fabrice Bellard. * Copyright (c) 2002-2004 Michael Niedermayer * + * mostly by Michael Niedermayer + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -18,19 +20,17 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * mostly by Michael Niedermayer */ -#include "../dsputil.h" +#include "dsputil.h" #include "x86_cpu.h" -static const __attribute__ ((aligned(8))) uint64_t round_tab[3]={ +DECLARE_ASM_CONST(8, uint64_t, round_tab[3])={ 0x0000000000000000ULL, 0x0001000100010001ULL, 0x0002000200020002ULL, }; -static attribute_used __attribute__ ((aligned(8))) uint64_t bone= 0x0101010101010101LL; +DECLARE_ASM_CONST(8, uint64_t, bone)= 0x0101010101010101LL; static inline void sad8_1_mmx(uint8_t *blk1, uint8_t *blk2, int stride, int h) { @@ -70,86 +70,127 @@ static inline void sad8_1_mmx(uint8_t *blk1, uint8_t *blk2, int stride, int h) static inline void sad8_1_mmx2(uint8_t *blk1, uint8_t *blk2, int stride, int h) { - long len= -(stride*h); asm volatile( ASMALIGN(4) "1: \n\t" - "movq (%1, %%"REG_a"), %%mm0 \n\t" - "movq (%2, %%"REG_a"), %%mm2 \n\t" - "psadbw %%mm2, %%mm0 \n\t" - "add %3, %%"REG_a" \n\t" - "movq (%1, %%"REG_a"), %%mm1 \n\t" - "movq (%2, %%"REG_a"), %%mm3 \n\t" - "psadbw %%mm1, %%mm3 \n\t" - "paddw %%mm3, %%mm0 \n\t" + "movq (%1), %%mm0 \n\t" + "movq (%1, %3), %%mm1 \n\t" + "psadbw (%2), %%mm0 \n\t" + "psadbw (%2, %3), %%mm1 \n\t" "paddw %%mm0, %%mm6 \n\t" - "add %3, %%"REG_a" \n\t" - " js 1b \n\t" - : "+a" (len) - : "r" (blk1 - len), "r" (blk2 - len), "r" ((long)stride) + "paddw %%mm1, %%mm6 \n\t" + "lea (%1,%3,2), %1 \n\t" + "lea (%2,%3,2), %2 \n\t" + "sub $2, %0 \n\t" + " jg 1b \n\t" + : "+r" (h), "+r" (blk1), "+r" (blk2) + : "r" ((long)stride) ); } -static inline void sad8_2_mmx2(uint8_t *blk1a, uint8_t *blk1b, uint8_t *blk2, int stride, int h) +static int sad16_sse2(void *v, uint8_t *blk2, uint8_t *blk1, int stride, int h) { - long len= -(stride*h); + int ret; asm volatile( + "pxor %%xmm6, %%xmm6 \n\t" ASMALIGN(4) "1: \n\t" - "movq (%1, %%"REG_a"), %%mm0 \n\t" - "movq (%2, %%"REG_a"), %%mm2 \n\t" - "pavgb %%mm2, %%mm0 \n\t" - "movq (%3, %%"REG_a"), %%mm2 \n\t" - "psadbw %%mm2, %%mm0 \n\t" - "add %4, %%"REG_a" \n\t" - "movq (%1, %%"REG_a"), %%mm1 \n\t" - "movq (%2, %%"REG_a"), %%mm3 \n\t" - "pavgb %%mm1, %%mm3 \n\t" - "movq (%3, %%"REG_a"), %%mm1 \n\t" - "psadbw %%mm1, %%mm3 \n\t" - "paddw %%mm3, %%mm0 \n\t" + "movdqu (%1), %%xmm0 \n\t" + "movdqu (%1, %3), %%xmm1 \n\t" + "psadbw (%2), %%xmm0 \n\t" + "psadbw (%2, %3), %%xmm1 \n\t" + "paddw %%xmm0, %%xmm6 \n\t" + "paddw %%xmm1, %%xmm6 \n\t" + "lea (%1,%3,2), %1 \n\t" + "lea (%2,%3,2), %2 \n\t" + "sub $2, %0 \n\t" + " jg 1b \n\t" + : "+r" (h), "+r" (blk1), "+r" (blk2) + : "r" ((long)stride) + ); + asm volatile( + "movhlps %%xmm6, %%xmm0 \n\t" + "paddw %%xmm0, %%xmm6 \n\t" + "movd %%xmm6, %0 \n\t" + : "=r"(ret) + ); + return ret; +} + +static inline void sad8_x2a_mmx2(uint8_t *blk1, uint8_t *blk2, int stride, int h) +{ + asm volatile( + ASMALIGN(4) + "1: \n\t" + "movq (%1), %%mm0 \n\t" + "movq (%1, %3), %%mm1 \n\t" + "pavgb 1(%1), %%mm0 \n\t" + "pavgb 1(%1, %3), %%mm1 \n\t" + "psadbw (%2), %%mm0 \n\t" + "psadbw (%2, %3), %%mm1 \n\t" "paddw %%mm0, %%mm6 \n\t" - "add %4, %%"REG_a" \n\t" - " js 1b \n\t" - : "+a" (len) - : "r" (blk1a - len), "r" (blk1b -len), "r" (blk2 - len), "r" ((long)stride) + "paddw %%mm1, %%mm6 \n\t" + "lea (%1,%3,2), %1 \n\t" + "lea (%2,%3,2), %2 \n\t" + "sub $2, %0 \n\t" + " jg 1b \n\t" + : "+r" (h), "+r" (blk1), "+r" (blk2) + : "r" ((long)stride) ); } -static inline void sad8_4_mmx2(uint8_t *blk1, uint8_t *blk2, int stride, int h) -{ //FIXME reuse src - long len= -(stride*h); +static inline void sad8_y2a_mmx2(uint8_t *blk1, uint8_t *blk2, int stride, int h) +{ asm volatile( + "movq (%1), %%mm0 \n\t" + "add %3, %1 \n\t" ASMALIGN(4) + "1: \n\t" + "movq (%1), %%mm1 \n\t" + "movq (%1, %3), %%mm2 \n\t" + "pavgb %%mm1, %%mm0 \n\t" + "pavgb %%mm2, %%mm1 \n\t" + "psadbw (%2), %%mm0 \n\t" + "psadbw (%2, %3), %%mm1 \n\t" + "paddw %%mm0, %%mm6 \n\t" + "paddw %%mm1, %%mm6 \n\t" + "movq %%mm2, %%mm0 \n\t" + "lea (%1,%3,2), %1 \n\t" + "lea (%2,%3,2), %2 \n\t" + "sub $2, %0 \n\t" + " jg 1b \n\t" + : "+r" (h), "+r" (blk1), "+r" (blk2) + : "r" ((long)stride) + ); +} + +static inline void sad8_4_mmx2(uint8_t *blk1, uint8_t *blk2, int stride, int h) +{ + asm volatile( "movq "MANGLE(bone)", %%mm5 \n\t" + "movq (%1), %%mm0 \n\t" + "pavgb 1(%1), %%mm0 \n\t" + "add %3, %1 \n\t" + ASMALIGN(4) "1: \n\t" - "movq (%1, %%"REG_a"), %%mm0 \n\t" - "movq (%2, %%"REG_a"), %%mm2 \n\t" - "movq 1(%1, %%"REG_a"), %%mm1 \n\t" - "movq 1(%2, %%"REG_a"), %%mm3 \n\t" - "pavgb %%mm2, %%mm0 \n\t" - "pavgb %%mm1, %%mm3 \n\t" - "psubusb %%mm5, %%mm3 \n\t" - "pavgb %%mm3, %%mm0 \n\t" - "movq (%3, %%"REG_a"), %%mm2 \n\t" - "psadbw %%mm2, %%mm0 \n\t" - "add %4, %%"REG_a" \n\t" - "movq (%1, %%"REG_a"), %%mm1 \n\t" - "movq (%2, %%"REG_a"), %%mm3 \n\t" - "movq 1(%1, %%"REG_a"), %%mm2 \n\t" - "movq 1(%2, %%"REG_a"), %%mm4 \n\t" - "pavgb %%mm3, %%mm1 \n\t" - "pavgb %%mm4, %%mm2 \n\t" - "psubusb %%mm5, %%mm2 \n\t" - "pavgb %%mm1, %%mm2 \n\t" - "movq (%3, %%"REG_a"), %%mm1 \n\t" - "psadbw %%mm1, %%mm2 \n\t" - "paddw %%mm2, %%mm0 \n\t" + "movq (%1), %%mm1 \n\t" + "movq (%1,%3), %%mm2 \n\t" + "pavgb 1(%1), %%mm1 \n\t" + "pavgb 1(%1,%3), %%mm2 \n\t" + "psubusb %%mm5, %%mm1 \n\t" + "pavgb %%mm1, %%mm0 \n\t" + "pavgb %%mm2, %%mm1 \n\t" + "psadbw (%2), %%mm0 \n\t" + "psadbw (%2,%3), %%mm1 \n\t" "paddw %%mm0, %%mm6 \n\t" - "add %4, %%"REG_a" \n\t" - " js 1b \n\t" - : "+a" (len) - : "r" (blk1 - len), "r" (blk1 - len + stride), "r" (blk2 - len), "r" ((long)stride) + "paddw %%mm1, %%mm6 \n\t" + "movq %%mm2, %%mm0 \n\t" + "lea (%1,%3,2), %1 \n\t" + "lea (%2,%3,2), %2 \n\t" + "sub $2, %0 \n\t" + " jg 1b \n\t" + : "+r" (h), "+r" (blk1), "+r" (blk2) + : "r" ((long)stride) ); } @@ -195,45 +236,48 @@ static inline void sad8_4_mmx(uint8_t *blk1, uint8_t *blk2, int stride, int h) { long len= -(stride*h); asm volatile( - ASMALIGN(4) - "1: \n\t" "movq (%1, %%"REG_a"), %%mm0 \n\t" - "movq (%2, %%"REG_a"), %%mm1 \n\t" - "movq %%mm0, %%mm4 \n\t" - "movq %%mm1, %%mm2 \n\t" - "punpcklbw %%mm7, %%mm0 \n\t" - "punpcklbw %%mm7, %%mm1 \n\t" - "punpckhbw %%mm7, %%mm4 \n\t" - "punpckhbw %%mm7, %%mm2 \n\t" - "paddw %%mm1, %%mm0 \n\t" - "paddw %%mm2, %%mm4 \n\t" "movq 1(%1, %%"REG_a"), %%mm2 \n\t" - "movq 1(%2, %%"REG_a"), %%mm3 \n\t" - "movq %%mm2, %%mm1 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" + "movq %%mm0, %%mm1 \n\t" + "movq %%mm2, %%mm3 \n\t" + "punpcklbw %%mm7, %%mm0 \n\t" "punpckhbw %%mm7, %%mm1 \n\t" - "paddw %%mm0, %%mm2 \n\t" - "paddw %%mm4, %%mm1 \n\t" - "movq %%mm3, %%mm4 \n\t" - "punpcklbw %%mm7, %%mm3 \n\t" - "punpckhbw %%mm7, %%mm4 \n\t" - "paddw %%mm3, %%mm2 \n\t" - "paddw %%mm4, %%mm1 \n\t" - "movq (%3, %%"REG_a"), %%mm3 \n\t" - "movq (%3, %%"REG_a"), %%mm4 \n\t" - "paddw %%mm5, %%mm2 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" + "punpckhbw %%mm7, %%mm3 \n\t" + "paddw %%mm2, %%mm0 \n\t" + "paddw %%mm3, %%mm1 \n\t" + ASMALIGN(4) + "1: \n\t" + "movq (%2, %%"REG_a"), %%mm2 \n\t" + "movq 1(%2, %%"REG_a"), %%mm4 \n\t" + "movq %%mm2, %%mm3 \n\t" + "movq %%mm4, %%mm5 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" + "punpckhbw %%mm7, %%mm3 \n\t" + "punpcklbw %%mm7, %%mm4 \n\t" + "punpckhbw %%mm7, %%mm5 \n\t" + "paddw %%mm4, %%mm2 \n\t" + "paddw %%mm5, %%mm3 \n\t" + "movq 16+"MANGLE(round_tab)", %%mm5 \n\t" + "paddw %%mm2, %%mm0 \n\t" + "paddw %%mm3, %%mm1 \n\t" + "paddw %%mm5, %%mm0 \n\t" "paddw %%mm5, %%mm1 \n\t" - "psrlw $2, %%mm2 \n\t" + "movq (%3, %%"REG_a"), %%mm4 \n\t" + "movq (%3, %%"REG_a"), %%mm5 \n\t" + "psrlw $2, %%mm0 \n\t" "psrlw $2, %%mm1 \n\t" - "packuswb %%mm1, %%mm2 \n\t" - "psubusb %%mm2, %%mm3 \n\t" - "psubusb %%mm4, %%mm2 \n\t" - "por %%mm3, %%mm2 \n\t" - "movq %%mm2, %%mm0 \n\t" + "packuswb %%mm1, %%mm0 \n\t" + "psubusb %%mm0, %%mm4 \n\t" + "psubusb %%mm5, %%mm0 \n\t" + "por %%mm4, %%mm0 \n\t" + "movq %%mm0, %%mm4 \n\t" "punpcklbw %%mm7, %%mm0 \n\t" - "punpckhbw %%mm7, %%mm2 \n\t" - "paddw %%mm2, %%mm0 \n\t" + "punpckhbw %%mm7, %%mm4 \n\t" "paddw %%mm0, %%mm6 \n\t" + "paddw %%mm4, %%mm6 \n\t" + "movq %%mm2, %%mm0 \n\t" + "movq %%mm3, %%mm1 \n\t" "add %4, %%"REG_a" \n\t" " js 1b \n\t" : "+a" (len) @@ -267,6 +311,15 @@ static inline int sum_mmx2(void) return ret; } +static inline void sad8_x2a_mmx(uint8_t *blk1, uint8_t *blk2, int stride, int h) +{ + sad8_2_mmx(blk1, blk1+1, blk2, stride, h); +} +static inline void sad8_y2a_mmx(uint8_t *blk1, uint8_t *blk2, int stride, int h) +{ + sad8_2_mmx(blk1, blk1+stride, blk2, stride, h); +} + #define PIX_SAD(suf)\ static int sad8_ ## suf(void *v, uint8_t *blk2, uint8_t *blk1, int stride, int h)\ @@ -288,7 +341,7 @@ static int sad8_x2_ ## suf(void *v, uint8_t *blk2, uint8_t *blk1, int stride, in :: "m"(round_tab[1]) \ );\ \ - sad8_2_ ## suf(blk1, blk1+1, blk2, stride, 8);\ + sad8_x2a_ ## suf(blk1, blk2, stride, 8);\ \ return sum_ ## suf();\ }\ @@ -302,7 +355,7 @@ static int sad8_y2_ ## suf(void *v, uint8_t *blk2, uint8_t *blk1, int stride, in :: "m"(round_tab[1]) \ );\ \ - sad8_2_ ## suf(blk1, blk1+stride, blk2, stride, 8);\ + sad8_y2a_ ## suf(blk1, blk2, stride, 8);\ \ return sum_ ## suf();\ }\ @@ -312,9 +365,7 @@ static int sad8_xy2_ ## suf(void *v, uint8_t *blk2, uint8_t *blk1, int stride, i assert(h==8);\ asm volatile("pxor %%mm7, %%mm7 \n\t"\ "pxor %%mm6, %%mm6 \n\t"\ - "movq %0, %%mm5 \n\t"\ - :: "m"(round_tab[2]) \ - );\ + ::);\ \ sad8_4_ ## suf(blk1, blk2, stride, 8);\ \ @@ -339,8 +390,8 @@ static int sad16_x2_ ## suf(void *v, uint8_t *blk2, uint8_t *blk1, int stride, i :: "m"(round_tab[1]) \ );\ \ - sad8_2_ ## suf(blk1 , blk1+1, blk2 , stride, h);\ - sad8_2_ ## suf(blk1+8, blk1+9, blk2+8, stride, h);\ + sad8_x2a_ ## suf(blk1 , blk2 , stride, h);\ + sad8_x2a_ ## suf(blk1+8, blk2+8, stride, h);\ \ return sum_ ## suf();\ }\ @@ -352,8 +403,8 @@ static int sad16_y2_ ## suf(void *v, uint8_t *blk2, uint8_t *blk1, int stride, i :: "m"(round_tab[1]) \ );\ \ - sad8_2_ ## suf(blk1 , blk1+stride, blk2 , stride, h);\ - sad8_2_ ## suf(blk1+8, blk1+stride+8,blk2+8, stride, h);\ + sad8_y2a_ ## suf(blk1 , blk2 , stride, h);\ + sad8_y2a_ ## suf(blk1+8, blk2+8, stride, h);\ \ return sum_ ## suf();\ }\ @@ -361,9 +412,7 @@ static int sad16_xy2_ ## suf(void *v, uint8_t *blk2, uint8_t *blk1, int stride, {\ asm volatile("pxor %%mm7, %%mm7 \n\t"\ "pxor %%mm6, %%mm6 \n\t"\ - "movq %0, %%mm5 \n\t"\ - :: "m"(round_tab[2]) \ - );\ + ::);\ \ sad8_4_ ## suf(blk1 , blk2 , stride, h);\ sad8_4_ ## suf(blk1+8, blk2+8, stride, h);\ @@ -405,4 +454,7 @@ void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx) c->pix_abs[1][3] = sad8_xy2_mmx2; } } + if ((mm_flags & MM_SSE2) && !(mm_flags & MM_3DNOW)) { + c->sad[0]= sad16_sse2; + } } diff --git a/contrib/ffmpeg/libavcodec/i386/mpegvideo_mmx.c b/contrib/ffmpeg/libavcodec/i386/mpegvideo_mmx.c index 1b7b1c19f..90b553aa2 100644 --- a/contrib/ffmpeg/libavcodec/i386/mpegvideo_mmx.c +++ b/contrib/ffmpeg/libavcodec/i386/mpegvideo_mmx.c @@ -2,6 +2,9 @@ * The simplest mpeg encoder (well, it was the simplest!) * Copyright (c) 2000,2001 Fabrice Bellard. * + * Optimized for ia32 CPUs by Nick Kurshev + * h263, mpeg1, mpeg2 dequantizer & draw_edges by Michael Niedermayer + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -17,21 +20,16 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Optimized for ia32 cpus by Nick Kurshev - * h263, mpeg1, mpeg2 dequantizer & draw_edges by Michael Niedermayer */ -#include "../dsputil.h" -#include "../mpegvideo.h" -#include "../avcodec.h" +#include "dsputil.h" +#include "dsputil_mmx.h" +#include "mpegvideo.h" +#include "avcodec.h" #include "x86_cpu.h" extern uint16_t inv_zigzag_direct16[64]; -static const unsigned long long int mm_wabs __attribute__ ((aligned(8))) = 0xffffffffffffffffULL; -static const unsigned long long int mm_wone __attribute__ ((aligned(8))) = 0x0001000100010001ULL; - static void dct_unquantize_h263_intra_mmx(MpegEncContext *s, DCTELEM *block, int n, int qscale) @@ -179,7 +177,7 @@ asm volatile( if (level < -2048 || level > 2047) fprintf(stderr, "unquant error %d %d\n", i, level); #endif - We can suppose that result of two multiplications can't be greate of 0xFFFF + We can suppose that result of two multiplications can't be greater than 0xFFFF i.e. is 16-bit, so we use here only PMULLW instruction and can avoid a complex multiplication. ===================================================== @@ -397,7 +395,7 @@ asm volatile( : "%"REG_a, "memory" ); block[0]= block0; - //Note, we dont do mismatch control for intra as errors cannot accumulate + //Note, we do not do mismatch control for intra as errors cannot accumulate } static void dct_unquantize_mpeg2_inter_mmx(MpegEncContext *s, @@ -673,6 +671,12 @@ static void denoise_dct_sse2(MpegEncContext *s, DCTELEM *block){ ); } +#ifdef HAVE_SSSE3 +#define HAVE_SSSE3_BAK +#endif +#undef HAVE_SSSE3 + +#undef HAVE_SSE2 #undef HAVE_MMX2 #define RENAME(a) a ## _MMX #define RENAMEl(a) a ## _mmx @@ -685,12 +689,22 @@ static void denoise_dct_sse2(MpegEncContext *s, DCTELEM *block){ #define RENAMEl(a) a ## _mmx2 #include "mpegvideo_mmx_template.c" +#define HAVE_SSE2 #undef RENAME #undef RENAMEl #define RENAME(a) a ## _SSE2 #define RENAMEl(a) a ## _sse2 #include "mpegvideo_mmx_template.c" +#ifdef HAVE_SSSE3_BAK +#define HAVE_SSSE3 +#undef RENAME +#undef RENAMEl +#define RENAME(a) a ## _SSSE3 +#define RENAMEl(a) a ## _sse2 +#include "mpegvideo_mmx_template.c" +#endif + void MPV_common_init_mmx(MpegEncContext *s) { if (mm_flags & MM_MMX) { @@ -713,6 +727,11 @@ void MPV_common_init_mmx(MpegEncContext *s) } if(dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX){ +#ifdef HAVE_SSSE3 + if(mm_flags & MM_SSSE3){ + s->dct_quantize= dct_quantize_SSSE3; + } else +#endif if(mm_flags & MM_SSE2){ s->dct_quantize= dct_quantize_SSE2; } else if(mm_flags & MM_MMXEXT){ diff --git a/contrib/ffmpeg/libavcodec/i386/mpegvideo_mmx_template.c b/contrib/ffmpeg/libavcodec/i386/mpegvideo_mmx_template.c index d59b6efd9..9c9c763b2 100644 --- a/contrib/ffmpeg/libavcodec/i386/mpegvideo_mmx_template.c +++ b/contrib/ffmpeg/libavcodec/i386/mpegvideo_mmx_template.c @@ -19,47 +19,91 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#undef MMREG_WIDTH +#undef MM +#undef MOVQ #undef SPREADW #undef PMAXW #undef PMAX -#ifdef HAVE_MMX2 -#define SPREADW(a) "pshufw $0, " #a ", " #a " \n\t" -#define PMAXW(a,b) "pmaxsw " #a ", " #b " \n\t" +#undef SAVE_SIGN +#undef RESTORE_SIGN + +#if defined(HAVE_SSE2) +#define MMREG_WIDTH "16" +#define MM "%%xmm" +#define MOVQ "movdqa" +#define SPREADW(a) \ + "pshuflw $0, "a", "a" \n\t"\ + "punpcklwd "a", "a" \n\t" +#define PMAXW(a,b) "pmaxsw "a", "b" \n\t" #define PMAX(a,b) \ - "pshufw $0x0E," #a ", " #b " \n\t"\ + "movhlps "a", "b" \n\t"\ PMAXW(b, a)\ - "pshufw $0x01," #a ", " #b " \n\t"\ + "pshuflw $0x0E, "a", "b" \n\t"\ + PMAXW(b, a)\ + "pshuflw $0x01, "a", "b" \n\t"\ + PMAXW(b, a) +#else +#define MMREG_WIDTH "8" +#define MM "%%mm" +#define MOVQ "movq" +#if defined(HAVE_MMX2) +#define SPREADW(a) "pshufw $0, "a", "a" \n\t" +#define PMAXW(a,b) "pmaxsw "a", "b" \n\t" +#define PMAX(a,b) \ + "pshufw $0x0E, "a", "b" \n\t"\ + PMAXW(b, a)\ + "pshufw $0x01, "a", "b" \n\t"\ PMAXW(b, a) #else #define SPREADW(a) \ - "punpcklwd " #a ", " #a " \n\t"\ - "punpcklwd " #a ", " #a " \n\t" + "punpcklwd "a", "a" \n\t"\ + "punpcklwd "a", "a" \n\t" #define PMAXW(a,b) \ - "psubusw " #a ", " #b " \n\t"\ - "paddw " #a ", " #b " \n\t" + "psubusw "a", "b" \n\t"\ + "paddw "a", "b" \n\t" #define PMAX(a,b) \ - "movq " #a ", " #b " \n\t"\ - "psrlq $32, " #a " \n\t"\ + "movq "a", "b" \n\t"\ + "psrlq $32, "a" \n\t"\ PMAXW(b, a)\ - "movq " #a ", " #b " \n\t"\ - "psrlq $16, " #a " \n\t"\ + "movq "a", "b" \n\t"\ + "psrlq $16, "a" \n\t"\ PMAXW(b, a) #endif +#endif + +#ifdef HAVE_SSSE3 +#define SAVE_SIGN(a,b) \ + "movdqa "b", "a" \n\t"\ + "pabsw "b", "b" \n\t" +#define RESTORE_SIGN(a,b) \ + "psignw "a", "b" \n\t" +#else +#define SAVE_SIGN(a,b) \ + "pxor "a", "a" \n\t"\ + "pcmpgtw "b", "a" \n\t" /* block[i] <= 0 ? 0xFF : 0x00 */\ + "pxor "a", "b" \n\t"\ + "psubw "a", "b" \n\t" /* ABS(block[i]) */ +#define RESTORE_SIGN(a,b) \ + "pxor "a", "b" \n\t"\ + "psubw "a", "b" \n\t" // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i]) +#endif static int RENAME(dct_quantize)(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow) { long last_non_zero_p1; - int level=0, q; //=0 is cuz gcc says uninitalized ... + int level=0, q; //=0 is cuz gcc says uninitialized ... const uint16_t *qmat, *bias; - DECLARE_ALIGNED_8(int16_t, temp_block[64]); + DECLARE_ALIGNED_16(int16_t, temp_block[64]); assert((7&(int)(&temp_block[0])) == 0); //did gcc align it correctly? //s->fdct (block); - RENAMEl(ff_fdct) (block); //cant be anything else ... + RENAMEl(ff_fdct) (block); //cannot be anything else ... if(s->dct_error_sum) s->denoise_dct(s, block); @@ -106,98 +150,82 @@ static int RENAME(dct_quantize)(MpegEncContext *s, if((s->out_format == FMT_H263 || s->out_format == FMT_H261) && s->mpeg_quant==0){ asm volatile( - "movd %%"REG_a", %%mm3 \n\t" // last_non_zero_p1 - SPREADW(%%mm3) - "pxor %%mm7, %%mm7 \n\t" // 0 - "pxor %%mm4, %%mm4 \n\t" // 0 - "movq (%2), %%mm5 \n\t" // qmat[0] - "pxor %%mm6, %%mm6 \n\t" - "psubw (%3), %%mm6 \n\t" // -bias[0] + "movd %%"REG_a", "MM"3 \n\t" // last_non_zero_p1 + SPREADW(MM"3") + "pxor "MM"7, "MM"7 \n\t" // 0 + "pxor "MM"4, "MM"4 \n\t" // 0 + MOVQ" (%2), "MM"5 \n\t" // qmat[0] + "pxor "MM"6, "MM"6 \n\t" + "psubw (%3), "MM"6 \n\t" // -bias[0] "mov $-128, %%"REG_a" \n\t" ASMALIGN(4) "1: \n\t" - "pxor %%mm1, %%mm1 \n\t" // 0 - "movq (%1, %%"REG_a"), %%mm0 \n\t" // block[i] - "pcmpgtw %%mm0, %%mm1 \n\t" // block[i] <= 0 ? 0xFF : 0x00 - "pxor %%mm1, %%mm0 \n\t" - "psubw %%mm1, %%mm0 \n\t" // ABS(block[i]) - "psubusw %%mm6, %%mm0 \n\t" // ABS(block[i]) + bias[0] - "pmulhw %%mm5, %%mm0 \n\t" // (ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16 - "por %%mm0, %%mm4 \n\t" - "pxor %%mm1, %%mm0 \n\t" - "psubw %%mm1, %%mm0 \n\t" // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i]) - "movq %%mm0, (%5, %%"REG_a") \n\t" - "pcmpeqw %%mm7, %%mm0 \n\t" // out==0 ? 0xFF : 0x00 - "movq (%4, %%"REG_a"), %%mm1 \n\t" - "movq %%mm7, (%1, %%"REG_a") \n\t" // 0 - "pandn %%mm1, %%mm0 \n\t" - PMAXW(%%mm0, %%mm3) - "add $8, %%"REG_a" \n\t" + MOVQ" (%1, %%"REG_a"), "MM"0 \n\t" // block[i] + SAVE_SIGN(MM"1", MM"0") // ABS(block[i]) + "psubusw "MM"6, "MM"0 \n\t" // ABS(block[i]) + bias[0] + "pmulhw "MM"5, "MM"0 \n\t" // (ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16 + "por "MM"0, "MM"4 \n\t" + RESTORE_SIGN(MM"1", MM"0") // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i]) + MOVQ" "MM"0, (%5, %%"REG_a") \n\t" + "pcmpeqw "MM"7, "MM"0 \n\t" // out==0 ? 0xFF : 0x00 + MOVQ" (%4, %%"REG_a"), "MM"1 \n\t" + MOVQ" "MM"7, (%1, %%"REG_a") \n\t" // 0 + "pandn "MM"1, "MM"0 \n\t" + PMAXW(MM"0", MM"3") + "add $"MMREG_WIDTH", %%"REG_a" \n\t" " js 1b \n\t" - PMAX(%%mm3, %%mm0) - "movd %%mm3, %%"REG_a" \n\t" + PMAX(MM"3", MM"0") + "movd "MM"3, %%"REG_a" \n\t" "movzb %%al, %%"REG_a" \n\t" // last_non_zero_p1 : "+a" (last_non_zero_p1) : "r" (block+64), "r" (qmat), "r" (bias), "r" (inv_zigzag_direct16+64), "r" (temp_block+64) ); - // note the asm is split cuz gcc doesnt like that many operands ... - asm volatile( - "movd %1, %%mm1 \n\t" // max_qcoeff - SPREADW(%%mm1) - "psubusw %%mm1, %%mm4 \n\t" - "packuswb %%mm4, %%mm4 \n\t" - "movd %%mm4, %0 \n\t" // *overflow - : "=g" (*overflow) - : "g" (s->max_qcoeff) - ); }else{ // FMT_H263 asm volatile( - "movd %%"REG_a", %%mm3 \n\t" // last_non_zero_p1 - SPREADW(%%mm3) - "pxor %%mm7, %%mm7 \n\t" // 0 - "pxor %%mm4, %%mm4 \n\t" // 0 + "movd %%"REG_a", "MM"3 \n\t" // last_non_zero_p1 + SPREADW(MM"3") + "pxor "MM"7, "MM"7 \n\t" // 0 + "pxor "MM"4, "MM"4 \n\t" // 0 "mov $-128, %%"REG_a" \n\t" ASMALIGN(4) "1: \n\t" - "pxor %%mm1, %%mm1 \n\t" // 0 - "movq (%1, %%"REG_a"), %%mm0 \n\t" // block[i] - "pcmpgtw %%mm0, %%mm1 \n\t" // block[i] <= 0 ? 0xFF : 0x00 - "pxor %%mm1, %%mm0 \n\t" - "psubw %%mm1, %%mm0 \n\t" // ABS(block[i]) - "movq (%3, %%"REG_a"), %%mm6 \n\t" // bias[0] - "paddusw %%mm6, %%mm0 \n\t" // ABS(block[i]) + bias[0] - "movq (%2, %%"REG_a"), %%mm5 \n\t" // qmat[i] - "pmulhw %%mm5, %%mm0 \n\t" // (ABS(block[i])*qmat[0] + bias[0]*qmat[0])>>16 - "por %%mm0, %%mm4 \n\t" - "pxor %%mm1, %%mm0 \n\t" - "psubw %%mm1, %%mm0 \n\t" // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i]) - "movq %%mm0, (%5, %%"REG_a") \n\t" - "pcmpeqw %%mm7, %%mm0 \n\t" // out==0 ? 0xFF : 0x00 - "movq (%4, %%"REG_a"), %%mm1 \n\t" - "movq %%mm7, (%1, %%"REG_a") \n\t" // 0 - "pandn %%mm1, %%mm0 \n\t" - PMAXW(%%mm0, %%mm3) - "add $8, %%"REG_a" \n\t" + MOVQ" (%1, %%"REG_a"), "MM"0 \n\t" // block[i] + SAVE_SIGN(MM"1", MM"0") // ABS(block[i]) + MOVQ" (%3, %%"REG_a"), "MM"6 \n\t" // bias[0] + "paddusw "MM"6, "MM"0 \n\t" // ABS(block[i]) + bias[0] + MOVQ" (%2, %%"REG_a"), "MM"5 \n\t" // qmat[i] + "pmulhw "MM"5, "MM"0 \n\t" // (ABS(block[i])*qmat[0] + bias[0]*qmat[0])>>16 + "por "MM"0, "MM"4 \n\t" + RESTORE_SIGN(MM"1", MM"0") // out=((ABS(block[i])*qmat[0] - bias[0]*qmat[0])>>16)*sign(block[i]) + MOVQ" "MM"0, (%5, %%"REG_a") \n\t" + "pcmpeqw "MM"7, "MM"0 \n\t" // out==0 ? 0xFF : 0x00 + MOVQ" (%4, %%"REG_a"), "MM"1 \n\t" + MOVQ" "MM"7, (%1, %%"REG_a") \n\t" // 0 + "pandn "MM"1, "MM"0 \n\t" + PMAXW(MM"0", MM"3") + "add $"MMREG_WIDTH", %%"REG_a" \n\t" " js 1b \n\t" - PMAX(%%mm3, %%mm0) - "movd %%mm3, %%"REG_a" \n\t" + PMAX(MM"3", MM"0") + "movd "MM"3, %%"REG_a" \n\t" "movzb %%al, %%"REG_a" \n\t" // last_non_zero_p1 : "+a" (last_non_zero_p1) : "r" (block+64), "r" (qmat+64), "r" (bias+64), "r" (inv_zigzag_direct16+64), "r" (temp_block+64) ); - // note the asm is split cuz gcc doesnt like that many operands ... - asm volatile( - "movd %1, %%mm1 \n\t" // max_qcoeff - SPREADW(%%mm1) - "psubusw %%mm1, %%mm4 \n\t" - "packuswb %%mm4, %%mm4 \n\t" - "movd %%mm4, %0 \n\t" // *overflow + } + asm volatile( + "movd %1, "MM"1 \n\t" // max_qcoeff + SPREADW(MM"1") + "psubusw "MM"1, "MM"4 \n\t" + "packuswb "MM"4, "MM"4 \n\t" +#ifdef HAVE_SSE2 + "packuswb "MM"4, "MM"4 \n\t" +#endif + "movd "MM"4, %0 \n\t" // *overflow : "=g" (*overflow) : "g" (s->max_qcoeff) - ); - } + ); if(s->mb_intra) block[0]= level; else block[0]= temp_block[0]; diff --git a/contrib/ffmpeg/libavcodec/i386/simple_idct_mmx.c b/contrib/ffmpeg/libavcodec/i386/simple_idct_mmx.c index 525ef34f7..059f473a0 100644 --- a/contrib/ffmpeg/libavcodec/i386/simple_idct_mmx.c +++ b/contrib/ffmpeg/libavcodec/i386/simple_idct_mmx.c @@ -19,8 +19,8 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../dsputil.h" -#include "../simple_idct.h" +#include "dsputil.h" +#include "simple_idct.h" /* 23170.475006 @@ -48,10 +48,10 @@ #define ROW_SHIFT 11 #define COL_SHIFT 20 // 6 -static const uint64_t attribute_used __attribute__((aligned(8))) wm1010= 0xFFFF0000FFFF0000ULL; -static const uint64_t attribute_used __attribute__((aligned(8))) d40000= 0x0000000000040000ULL; +DECLARE_ASM_CONST(8, uint64_t, wm1010)= 0xFFFF0000FFFF0000ULL; +DECLARE_ASM_CONST(8, uint64_t, d40000)= 0x0000000000040000ULL; -static const int16_t __attribute__((aligned(8))) coeffs[]= { +DECLARE_ALIGNED(8, static const int16_t, coeffs[])= { 1<<(ROW_SHIFT-1), 0, 1<<(ROW_SHIFT-1), 0, // 1<<(COL_SHIFT-1), 0, 1<<(COL_SHIFT-1), 0, // 0, 1<<(COL_SHIFT-1-16), 0, 1<<(COL_SHIFT-1-16), @@ -209,7 +209,7 @@ row[7] = input[13]; static inline void idct(int16_t *block) { - int64_t __attribute__((aligned(8))) align_tmp[16]; + DECLARE_ALIGNED(8, int64_t, align_tmp[16]); int16_t * const temp= (int16_t*)align_tmp; asm volatile( diff --git a/contrib/ffmpeg/libavcodec/i386/snowdsp_mmx.c b/contrib/ffmpeg/libavcodec/i386/snowdsp_mmx.c index 8f182303d..e43f7e9de 100644 --- a/contrib/ffmpeg/libavcodec/i386/snowdsp_mmx.c +++ b/contrib/ffmpeg/libavcodec/i386/snowdsp_mmx.c @@ -19,22 +19,20 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../avcodec.h" -#include "../snow.h" +#include "avcodec.h" +#include "snow.h" #include "x86_cpu.h" -void ff_snow_horizontal_compose97i_sse2(DWTELEM *b, int width){ +void ff_snow_horizontal_compose97i_sse2(IDWTELEM *b, int width){ const int w2= (width+1)>>1; - // SSE2 code runs faster with pointers aligned on a 32-byte boundary. - DWTELEM temp_buf[(width>>1) + 4]; - DWTELEM * const temp = temp_buf + 4 - (((int)temp_buf & 0xF) >> 2); + DECLARE_ALIGNED_16(IDWTELEM, temp[width>>1]); const int w_l= (width>>1); const int w_r= w2 - 1; int i; { // Lift 0 - DWTELEM * const ref = b + w2 - 1; - DWTELEM b_0 = b[0]; //By allowing the first entry in b[0] to be calculated twice + IDWTELEM * const ref = b + w2 - 1; + IDWTELEM b_0 = b[0]; //By allowing the first entry in b[0] to be calculated twice // (the first time erroneously), we allow the SSE2 code to run an extra pass. // The savings in code and time are well worth having to store this value and // calculate b[0] correctly afterwards. @@ -42,33 +40,27 @@ void ff_snow_horizontal_compose97i_sse2(DWTELEM *b, int width){ i = 0; asm volatile( "pcmpeqd %%xmm7, %%xmm7 \n\t" - "pslld $31, %%xmm7 \n\t" - "psrld $29, %%xmm7 \n\t" + "pcmpeqd %%xmm3, %%xmm3 \n\t" + "psllw $1, %%xmm3 \n\t" + "paddw %%xmm7, %%xmm3 \n\t" + "psllw $13, %%xmm3 \n\t" ::); - for(; i> W_BS); + b[0] = b_0 + ((2 * ref[1] + W_BO-1 + 4 * b_0) >> W_BS); } { // Lift 3 - DWTELEM * const src = b+w2; + IDWTELEM * const src = b+w2; i = 0; - for(; (((long)&temp[i]) & 0xF) && i>W_AS); } for(; i>1]; b[i] = b[i>>1]; } - for (i-=30; i>=0; i-=32){ + for (i-=62; i>=0; i-=64){ asm volatile( "movdqa (%1), %%xmm0 \n\t" "movdqa 16(%1), %%xmm2 \n\t" @@ -198,18 +189,18 @@ void ff_snow_horizontal_compose97i_sse2(DWTELEM *b, int width){ "movdqa 16(%1), %%xmm3 \n\t" "movdqa 32(%1), %%xmm5 \n\t" "movdqa 48(%1), %%xmm7 \n\t" - "punpckldq (%2), %%xmm0 \n\t" - "punpckldq 16(%2), %%xmm2 \n\t" - "punpckldq 32(%2), %%xmm4 \n\t" - "punpckldq 48(%2), %%xmm6 \n\t" + "punpcklwd (%2), %%xmm0 \n\t" + "punpcklwd 16(%2), %%xmm2 \n\t" + "punpcklwd 32(%2), %%xmm4 \n\t" + "punpcklwd 48(%2), %%xmm6 \n\t" "movdqa %%xmm0, (%0) \n\t" "movdqa %%xmm2, 32(%0) \n\t" "movdqa %%xmm4, 64(%0) \n\t" "movdqa %%xmm6, 96(%0) \n\t" - "punpckhdq (%2), %%xmm1 \n\t" - "punpckhdq 16(%2), %%xmm3 \n\t" - "punpckhdq 32(%2), %%xmm5 \n\t" - "punpckhdq 48(%2), %%xmm7 \n\t" + "punpckhwd (%2), %%xmm1 \n\t" + "punpckhwd 16(%2), %%xmm3 \n\t" + "punpckhwd 32(%2), %%xmm5 \n\t" + "punpckhwd 48(%2), %%xmm7 \n\t" "movdqa %%xmm1, 16(%0) \n\t" "movdqa %%xmm3, 48(%0) \n\t" "movdqa %%xmm5, 80(%0) \n\t" @@ -221,45 +212,39 @@ void ff_snow_horizontal_compose97i_sse2(DWTELEM *b, int width){ } } -void ff_snow_horizontal_compose97i_mmx(DWTELEM *b, int width){ +void ff_snow_horizontal_compose97i_mmx(IDWTELEM *b, int width){ const int w2= (width+1)>>1; - DWTELEM temp[width >> 1]; + IDWTELEM temp[width >> 1]; const int w_l= (width>>1); const int w_r= w2 - 1; int i; { // Lift 0 - DWTELEM * const ref = b + w2 - 1; + IDWTELEM * const ref = b + w2 - 1; i = 1; b[0] = b[0] - ((W_DM * 2 * ref[1]+W_DO)>>W_DS); asm volatile( - "pcmpeqd %%mm7, %%mm7 \n\t" - "pslld $31, %%mm7 \n\t" - "psrld $29, %%mm7 \n\t" + "pcmpeqw %%mm7, %%mm7 \n\t" + "pcmpeqw %%mm3, %%mm3 \n\t" + "psllw $1, %%mm3 \n\t" + "paddw %%mm7, %%mm3 \n\t" + "psllw $13, %%mm3 \n\t" ::); - for(; i> W_BS); + b[0] = b[0] + (((2 * ref[1] + W_BO) + 4 * b[0]) >> W_BS); asm volatile( - "pslld $1, %%mm7 \n\t" /* xmm7 already holds a '4' from 2 lifts ago. */ + "psllw $15, %%mm7 \n\t" + "pcmpeqw %%mm6, %%mm6 \n\t" + "psrlw $13, %%mm6 \n\t" + "paddw %%mm7, %%mm6 \n\t" ::); - for(; i>1]; b[i] = b[i>>1]; } - for (i-=14; i>=0; i-=16){ + for (i-=30; i>=0; i-=32){ asm volatile( "movq (%1), %%mm0 \n\t" "movq 8(%1), %%mm2 \n\t" @@ -377,18 +363,18 @@ void ff_snow_horizontal_compose97i_mmx(DWTELEM *b, int width){ "movq 8(%1), %%mm3 \n\t" "movq 16(%1), %%mm5 \n\t" "movq 24(%1), %%mm7 \n\t" - "punpckldq (%2), %%mm0 \n\t" - "punpckldq 8(%2), %%mm2 \n\t" - "punpckldq 16(%2), %%mm4 \n\t" - "punpckldq 24(%2), %%mm6 \n\t" + "punpcklwd (%2), %%mm0 \n\t" + "punpcklwd 8(%2), %%mm2 \n\t" + "punpcklwd 16(%2), %%mm4 \n\t" + "punpcklwd 24(%2), %%mm6 \n\t" "movq %%mm0, (%0) \n\t" "movq %%mm2, 16(%0) \n\t" "movq %%mm4, 32(%0) \n\t" "movq %%mm6, 48(%0) \n\t" - "punpckhdq (%2), %%mm1 \n\t" - "punpckhdq 8(%2), %%mm3 \n\t" - "punpckhdq 16(%2), %%mm5 \n\t" - "punpckhdq 24(%2), %%mm7 \n\t" + "punpckhwd (%2), %%mm1 \n\t" + "punpckhwd 8(%2), %%mm3 \n\t" + "punpckhwd 16(%2), %%mm5 \n\t" + "punpckhwd 24(%2), %%mm7 \n\t" "movq %%mm1, 8(%0) \n\t" "movq %%mm3, 24(%0) \n\t" "movq %%mm5, 40(%0) \n\t" @@ -400,47 +386,48 @@ void ff_snow_horizontal_compose97i_mmx(DWTELEM *b, int width){ } } +#ifdef HAVE_7REGS #define snow_vertical_compose_sse2_load_add(op,r,t0,t1,t2,t3)\ - ""op" (%%"r",%%"REG_d",4), %%"t0" \n\t"\ - ""op" 16(%%"r",%%"REG_d",4), %%"t1" \n\t"\ - ""op" 32(%%"r",%%"REG_d",4), %%"t2" \n\t"\ - ""op" 48(%%"r",%%"REG_d",4), %%"t3" \n\t" + ""op" ("r",%%"REG_d"), %%"t0" \n\t"\ + ""op" 16("r",%%"REG_d"), %%"t1" \n\t"\ + ""op" 32("r",%%"REG_d"), %%"t2" \n\t"\ + ""op" 48("r",%%"REG_d"), %%"t3" \n\t" #define snow_vertical_compose_sse2_load(r,t0,t1,t2,t3)\ snow_vertical_compose_sse2_load_add("movdqa",r,t0,t1,t2,t3) #define snow_vertical_compose_sse2_add(r,t0,t1,t2,t3)\ - snow_vertical_compose_sse2_load_add("paddd",r,t0,t1,t2,t3) + snow_vertical_compose_sse2_load_add("paddw",r,t0,t1,t2,t3) -#define snow_vertical_compose_sse2_sub(s0,s1,s2,s3,t0,t1,t2,t3)\ - "psubd %%"s0", %%"t0" \n\t"\ - "psubd %%"s1", %%"t1" \n\t"\ - "psubd %%"s2", %%"t2" \n\t"\ - "psubd %%"s3", %%"t3" \n\t" +#define snow_vertical_compose_r2r_sub(s0,s1,s2,s3,t0,t1,t2,t3)\ + "psubw %%"s0", %%"t0" \n\t"\ + "psubw %%"s1", %%"t1" \n\t"\ + "psubw %%"s2", %%"t2" \n\t"\ + "psubw %%"s3", %%"t3" \n\t" #define snow_vertical_compose_sse2_store(w,s0,s1,s2,s3)\ - "movdqa %%"s0", (%%"w",%%"REG_d",4) \n\t"\ - "movdqa %%"s1", 16(%%"w",%%"REG_d",4) \n\t"\ - "movdqa %%"s2", 32(%%"w",%%"REG_d",4) \n\t"\ - "movdqa %%"s3", 48(%%"w",%%"REG_d",4) \n\t" - -#define snow_vertical_compose_sse2_sra(n,t0,t1,t2,t3)\ - "psrad $"n", %%"t0" \n\t"\ - "psrad $"n", %%"t1" \n\t"\ - "psrad $"n", %%"t2" \n\t"\ - "psrad $"n", %%"t3" \n\t" - -#define snow_vertical_compose_sse2_r2r_add(s0,s1,s2,s3,t0,t1,t2,t3)\ - "paddd %%"s0", %%"t0" \n\t"\ - "paddd %%"s1", %%"t1" \n\t"\ - "paddd %%"s2", %%"t2" \n\t"\ - "paddd %%"s3", %%"t3" \n\t" - -#define snow_vertical_compose_sse2_sll(n,t0,t1,t2,t3)\ - "pslld $"n", %%"t0" \n\t"\ - "pslld $"n", %%"t1" \n\t"\ - "pslld $"n", %%"t2" \n\t"\ - "pslld $"n", %%"t3" \n\t" + "movdqa %%"s0", ("w",%%"REG_d") \n\t"\ + "movdqa %%"s1", 16("w",%%"REG_d") \n\t"\ + "movdqa %%"s2", 32("w",%%"REG_d") \n\t"\ + "movdqa %%"s3", 48("w",%%"REG_d") \n\t" + +#define snow_vertical_compose_sra(n,t0,t1,t2,t3)\ + "psraw $"n", %%"t0" \n\t"\ + "psraw $"n", %%"t1" \n\t"\ + "psraw $"n", %%"t2" \n\t"\ + "psraw $"n", %%"t3" \n\t" + +#define snow_vertical_compose_r2r_add(s0,s1,s2,s3,t0,t1,t2,t3)\ + "paddw %%"s0", %%"t0" \n\t"\ + "paddw %%"s1", %%"t1" \n\t"\ + "paddw %%"s2", %%"t2" \n\t"\ + "paddw %%"s3", %%"t3" \n\t" + +#define snow_vertical_compose_r2r_pmulhw(s0,s1,s2,s3,t0,t1,t2,t3)\ + "pmulhw %%"s0", %%"t0" \n\t"\ + "pmulhw %%"s1", %%"t1" \n\t"\ + "pmulhw %%"s2", %%"t2" \n\t"\ + "pmulhw %%"s3", %%"t3" \n\t" #define snow_vertical_compose_sse2_move(s0,s1,s2,s3,t0,t1,t2,t3)\ "movdqa %%"s0", %%"t0" \n\t"\ @@ -448,10 +435,10 @@ void ff_snow_horizontal_compose97i_mmx(DWTELEM *b, int width){ "movdqa %%"s2", %%"t2" \n\t"\ "movdqa %%"s3", %%"t3" \n\t" -void ff_snow_vertical_compose97i_sse2(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width){ +void ff_snow_vertical_compose97i_sse2(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width){ long i = width; - while(i & 0xF) + while(i & 0x1F) { i--; b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS; @@ -459,96 +446,85 @@ void ff_snow_vertical_compose97i_sse2(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWT b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS; b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS; } + i+=i; asm volatile ( "jmp 2f \n\t" "1: \n\t" - - "mov %6, %%"REG_a" \n\t" - "mov %4, %%"REG_S" \n\t" - - snow_vertical_compose_sse2_load(REG_S,"xmm0","xmm2","xmm4","xmm6") - snow_vertical_compose_sse2_add(REG_a,"xmm0","xmm2","xmm4","xmm6") - snow_vertical_compose_sse2_move("xmm0","xmm2","xmm4","xmm6","xmm1","xmm3","xmm5","xmm7") - snow_vertical_compose_sse2_sll("1","xmm0","xmm2","xmm4","xmm6")\ - snow_vertical_compose_sse2_r2r_add("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6") - - "pcmpeqd %%xmm1, %%xmm1 \n\t" - "pslld $31, %%xmm1 \n\t" - "psrld $29, %%xmm1 \n\t" - "mov %5, %%"REG_a" \n\t" - - snow_vertical_compose_sse2_r2r_add("xmm1","xmm1","xmm1","xmm1","xmm0","xmm2","xmm4","xmm6") - snow_vertical_compose_sse2_sra("3","xmm0","xmm2","xmm4","xmm6") - snow_vertical_compose_sse2_load(REG_a,"xmm1","xmm3","xmm5","xmm7") - snow_vertical_compose_sse2_sub("xmm0","xmm2","xmm4","xmm6","xmm1","xmm3","xmm5","xmm7") - snow_vertical_compose_sse2_store(REG_a,"xmm1","xmm3","xmm5","xmm7") - "mov %3, %%"REG_c" \n\t" - snow_vertical_compose_sse2_load(REG_S,"xmm0","xmm2","xmm4","xmm6") - snow_vertical_compose_sse2_add(REG_c,"xmm1","xmm3","xmm5","xmm7") - snow_vertical_compose_sse2_sub("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6") - snow_vertical_compose_sse2_store(REG_S,"xmm0","xmm2","xmm4","xmm6") - "mov %2, %%"REG_a" \n\t" - snow_vertical_compose_sse2_load(REG_c,"xmm1","xmm3","xmm5","xmm7") - snow_vertical_compose_sse2_add(REG_a,"xmm0","xmm2","xmm4","xmm6") - snow_vertical_compose_sse2_sll("2","xmm1","xmm3","xmm5","xmm7")\ - snow_vertical_compose_sse2_r2r_add("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6") - - "pcmpeqd %%xmm1, %%xmm1 \n\t" - "pslld $31, %%xmm1 \n\t" - "psrld $28, %%xmm1 \n\t" - "mov %1, %%"REG_S" \n\t" - - snow_vertical_compose_sse2_r2r_add("xmm1","xmm1","xmm1","xmm1","xmm0","xmm2","xmm4","xmm6") - snow_vertical_compose_sse2_sra("4","xmm0","xmm2","xmm4","xmm6") - snow_vertical_compose_sse2_add(REG_c,"xmm0","xmm2","xmm4","xmm6") - snow_vertical_compose_sse2_store(REG_c,"xmm0","xmm2","xmm4","xmm6") - snow_vertical_compose_sse2_add(REG_S,"xmm0","xmm2","xmm4","xmm6") + snow_vertical_compose_sse2_load("%4","xmm0","xmm2","xmm4","xmm6") + snow_vertical_compose_sse2_add("%6","xmm0","xmm2","xmm4","xmm6") + + + "pcmpeqw %%xmm0, %%xmm0 \n\t" + "pcmpeqw %%xmm2, %%xmm2 \n\t" + "paddw %%xmm2, %%xmm2 \n\t" + "paddw %%xmm0, %%xmm2 \n\t" + "psllw $13, %%xmm2 \n\t" + snow_vertical_compose_r2r_add("xmm0","xmm0","xmm0","xmm0","xmm1","xmm3","xmm5","xmm7") + snow_vertical_compose_r2r_pmulhw("xmm2","xmm2","xmm2","xmm2","xmm1","xmm3","xmm5","xmm7") + snow_vertical_compose_sse2_add("%5","xmm1","xmm3","xmm5","xmm7") + snow_vertical_compose_sse2_store("%5","xmm1","xmm3","xmm5","xmm7") + snow_vertical_compose_sse2_load("%4","xmm0","xmm2","xmm4","xmm6") + snow_vertical_compose_sse2_add("%3","xmm1","xmm3","xmm5","xmm7") + snow_vertical_compose_r2r_sub("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6") + snow_vertical_compose_sse2_store("%4","xmm0","xmm2","xmm4","xmm6") + + "pcmpeqw %%xmm7, %%xmm7 \n\t" + "pcmpeqw %%xmm5, %%xmm5 \n\t" + "psllw $15, %%xmm7 \n\t" + "psrlw $13, %%xmm5 \n\t" + "paddw %%xmm7, %%xmm5 \n\t" + snow_vertical_compose_r2r_add("xmm5","xmm5","xmm5","xmm5","xmm0","xmm2","xmm4","xmm6") + "movq (%2,%%"REG_d"), %%xmm1 \n\t" + "movq 8(%2,%%"REG_d"), %%xmm3 \n\t" + "paddw %%xmm7, %%xmm1 \n\t" + "paddw %%xmm7, %%xmm3 \n\t" + "pavgw %%xmm1, %%xmm0 \n\t" + "pavgw %%xmm3, %%xmm2 \n\t" + "movq 16(%2,%%"REG_d"), %%xmm1 \n\t" + "movq 24(%2,%%"REG_d"), %%xmm3 \n\t" + "paddw %%xmm7, %%xmm1 \n\t" + "paddw %%xmm7, %%xmm3 \n\t" + "pavgw %%xmm1, %%xmm4 \n\t" + "pavgw %%xmm3, %%xmm6 \n\t" + snow_vertical_compose_r2r_sub("xmm7","xmm7","xmm7","xmm7","xmm0","xmm2","xmm4","xmm6") + snow_vertical_compose_sra("1","xmm0","xmm2","xmm4","xmm6") + snow_vertical_compose_sse2_add("%3","xmm0","xmm2","xmm4","xmm6") + + snow_vertical_compose_sra("2","xmm0","xmm2","xmm4","xmm6") + snow_vertical_compose_sse2_add("%3","xmm0","xmm2","xmm4","xmm6") + snow_vertical_compose_sse2_store("%3","xmm0","xmm2","xmm4","xmm6") + snow_vertical_compose_sse2_add("%1","xmm0","xmm2","xmm4","xmm6") snow_vertical_compose_sse2_move("xmm0","xmm2","xmm4","xmm6","xmm1","xmm3","xmm5","xmm7") - snow_vertical_compose_sse2_sll("1","xmm0","xmm2","xmm4","xmm6")\ - snow_vertical_compose_sse2_r2r_add("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6") - snow_vertical_compose_sse2_sra("1","xmm0","xmm2","xmm4","xmm6") - snow_vertical_compose_sse2_add(REG_a,"xmm0","xmm2","xmm4","xmm6") - snow_vertical_compose_sse2_store(REG_a,"xmm0","xmm2","xmm4","xmm6") + snow_vertical_compose_sra("1","xmm0","xmm2","xmm4","xmm6") + snow_vertical_compose_r2r_add("xmm1","xmm3","xmm5","xmm7","xmm0","xmm2","xmm4","xmm6") + snow_vertical_compose_sse2_add("%2","xmm0","xmm2","xmm4","xmm6") + snow_vertical_compose_sse2_store("%2","xmm0","xmm2","xmm4","xmm6") "2: \n\t" - "sub $16, %%"REG_d" \n\t" + "sub $64, %%"REG_d" \n\t" "jge 1b \n\t" :"+d"(i) - : - "m"(b0),"m"(b1),"m"(b2),"m"(b3),"m"(b4),"m"(b5): - "%"REG_a"","%"REG_S"","%"REG_c""); + :"r"(b0),"r"(b1),"r"(b2),"r"(b3),"r"(b4),"r"(b5)); } #define snow_vertical_compose_mmx_load_add(op,r,t0,t1,t2,t3)\ - ""op" (%%"r",%%"REG_d",4), %%"t0" \n\t"\ - ""op" 8(%%"r",%%"REG_d",4), %%"t1" \n\t"\ - ""op" 16(%%"r",%%"REG_d",4), %%"t2" \n\t"\ - ""op" 24(%%"r",%%"REG_d",4), %%"t3" \n\t" + ""op" ("r",%%"REG_d"), %%"t0" \n\t"\ + ""op" 8("r",%%"REG_d"), %%"t1" \n\t"\ + ""op" 16("r",%%"REG_d"), %%"t2" \n\t"\ + ""op" 24("r",%%"REG_d"), %%"t3" \n\t" #define snow_vertical_compose_mmx_load(r,t0,t1,t2,t3)\ snow_vertical_compose_mmx_load_add("movq",r,t0,t1,t2,t3) #define snow_vertical_compose_mmx_add(r,t0,t1,t2,t3)\ - snow_vertical_compose_mmx_load_add("paddd",r,t0,t1,t2,t3) - -#define snow_vertical_compose_mmx_sub(s0,s1,s2,s3,t0,t1,t2,t3)\ - snow_vertical_compose_sse2_sub(s0,s1,s2,s3,t0,t1,t2,t3) + snow_vertical_compose_mmx_load_add("paddw",r,t0,t1,t2,t3) #define snow_vertical_compose_mmx_store(w,s0,s1,s2,s3)\ - "movq %%"s0", (%%"w",%%"REG_d",4) \n\t"\ - "movq %%"s1", 8(%%"w",%%"REG_d",4) \n\t"\ - "movq %%"s2", 16(%%"w",%%"REG_d",4) \n\t"\ - "movq %%"s3", 24(%%"w",%%"REG_d",4) \n\t" - -#define snow_vertical_compose_mmx_sra(n,t0,t1,t2,t3)\ - snow_vertical_compose_sse2_sra(n,t0,t1,t2,t3) - -#define snow_vertical_compose_mmx_r2r_add(s0,s1,s2,s3,t0,t1,t2,t3)\ - snow_vertical_compose_sse2_r2r_add(s0,s1,s2,s3,t0,t1,t2,t3) - -#define snow_vertical_compose_mmx_sll(n,t0,t1,t2,t3)\ - snow_vertical_compose_sse2_sll(n,t0,t1,t2,t3) + "movq %%"s0", ("w",%%"REG_d") \n\t"\ + "movq %%"s1", 8("w",%%"REG_d") \n\t"\ + "movq %%"s2", 16("w",%%"REG_d") \n\t"\ + "movq %%"s3", 24("w",%%"REG_d") \n\t" #define snow_vertical_compose_mmx_move(s0,s1,s2,s3,t0,t1,t2,t3)\ "movq %%"s0", %%"t0" \n\t"\ @@ -556,9 +532,10 @@ void ff_snow_vertical_compose97i_sse2(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWT "movq %%"s2", %%"t2" \n\t"\ "movq %%"s3", %%"t3" \n\t" -void ff_snow_vertical_compose97i_mmx(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width){ + +void ff_snow_vertical_compose97i_mmx(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width){ long i = width; - while(i & 0x7) + while(i & 15) { i--; b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS; @@ -566,69 +543,68 @@ void ff_snow_vertical_compose97i_mmx(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTE b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS; b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS; } - + i+=i; asm volatile( "jmp 2f \n\t" "1: \n\t" - "mov %6, %%"REG_a" \n\t" - "mov %4, %%"REG_S" \n\t" - - snow_vertical_compose_mmx_load(REG_S,"mm0","mm2","mm4","mm6") - snow_vertical_compose_mmx_add(REG_a,"mm0","mm2","mm4","mm6") + snow_vertical_compose_mmx_load("%4","mm1","mm3","mm5","mm7") + snow_vertical_compose_mmx_add("%6","mm1","mm3","mm5","mm7") + "pcmpeqw %%mm0, %%mm0 \n\t" + "pcmpeqw %%mm2, %%mm2 \n\t" + "paddw %%mm2, %%mm2 \n\t" + "paddw %%mm0, %%mm2 \n\t" + "psllw $13, %%mm2 \n\t" + snow_vertical_compose_r2r_add("mm0","mm0","mm0","mm0","mm1","mm3","mm5","mm7") + snow_vertical_compose_r2r_pmulhw("mm2","mm2","mm2","mm2","mm1","mm3","mm5","mm7") + snow_vertical_compose_mmx_add("%5","mm1","mm3","mm5","mm7") + snow_vertical_compose_mmx_store("%5","mm1","mm3","mm5","mm7") + snow_vertical_compose_mmx_load("%4","mm0","mm2","mm4","mm6") + snow_vertical_compose_mmx_add("%3","mm1","mm3","mm5","mm7") + snow_vertical_compose_r2r_sub("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6") + snow_vertical_compose_mmx_store("%4","mm0","mm2","mm4","mm6") + "pcmpeqw %%mm7, %%mm7 \n\t" + "pcmpeqw %%mm5, %%mm5 \n\t" + "psllw $15, %%mm7 \n\t" + "psrlw $13, %%mm5 \n\t" + "paddw %%mm7, %%mm5 \n\t" + snow_vertical_compose_r2r_add("mm5","mm5","mm5","mm5","mm0","mm2","mm4","mm6") + "movq (%2,%%"REG_d"), %%mm1 \n\t" + "movq 8(%2,%%"REG_d"), %%mm3 \n\t" + "paddw %%mm7, %%mm1 \n\t" + "paddw %%mm7, %%mm3 \n\t" + "pavgw %%mm1, %%mm0 \n\t" + "pavgw %%mm3, %%mm2 \n\t" + "movq 16(%2,%%"REG_d"), %%mm1 \n\t" + "movq 24(%2,%%"REG_d"), %%mm3 \n\t" + "paddw %%mm7, %%mm1 \n\t" + "paddw %%mm7, %%mm3 \n\t" + "pavgw %%mm1, %%mm4 \n\t" + "pavgw %%mm3, %%mm6 \n\t" + snow_vertical_compose_r2r_sub("mm7","mm7","mm7","mm7","mm0","mm2","mm4","mm6") + snow_vertical_compose_sra("1","mm0","mm2","mm4","mm6") + snow_vertical_compose_mmx_add("%3","mm0","mm2","mm4","mm6") + + snow_vertical_compose_sra("2","mm0","mm2","mm4","mm6") + snow_vertical_compose_mmx_add("%3","mm0","mm2","mm4","mm6") + snow_vertical_compose_mmx_store("%3","mm0","mm2","mm4","mm6") + snow_vertical_compose_mmx_add("%1","mm0","mm2","mm4","mm6") snow_vertical_compose_mmx_move("mm0","mm2","mm4","mm6","mm1","mm3","mm5","mm7") - snow_vertical_compose_mmx_sll("1","mm0","mm2","mm4","mm6") - snow_vertical_compose_mmx_r2r_add("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6") - - "pcmpeqd %%mm1, %%mm1 \n\t" - "pslld $31, %%mm1 \n\t" - "psrld $29, %%mm1 \n\t" - "mov %5, %%"REG_a" \n\t" - - snow_vertical_compose_mmx_r2r_add("mm1","mm1","mm1","mm1","mm0","mm2","mm4","mm6") - snow_vertical_compose_mmx_sra("3","mm0","mm2","mm4","mm6") - snow_vertical_compose_mmx_load(REG_a,"mm1","mm3","mm5","mm7") - snow_vertical_compose_mmx_sub("mm0","mm2","mm4","mm6","mm1","mm3","mm5","mm7") - snow_vertical_compose_mmx_store(REG_a,"mm1","mm3","mm5","mm7") - "mov %3, %%"REG_c" \n\t" - snow_vertical_compose_mmx_load(REG_S,"mm0","mm2","mm4","mm6") - snow_vertical_compose_mmx_add(REG_c,"mm1","mm3","mm5","mm7") - snow_vertical_compose_mmx_sub("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6") - snow_vertical_compose_mmx_store(REG_S,"mm0","mm2","mm4","mm6") - "mov %2, %%"REG_a" \n\t" - snow_vertical_compose_mmx_load(REG_c,"mm1","mm3","mm5","mm7") - snow_vertical_compose_mmx_add(REG_a,"mm0","mm2","mm4","mm6") - snow_vertical_compose_mmx_sll("2","mm1","mm3","mm5","mm7") - snow_vertical_compose_mmx_r2r_add("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6") - - "pcmpeqd %%mm1, %%mm1 \n\t" - "pslld $31, %%mm1 \n\t" - "psrld $28, %%mm1 \n\t" - "mov %1, %%"REG_S" \n\t" - - snow_vertical_compose_mmx_r2r_add("mm1","mm1","mm1","mm1","mm0","mm2","mm4","mm6") - snow_vertical_compose_mmx_sra("4","mm0","mm2","mm4","mm6") - snow_vertical_compose_mmx_add(REG_c,"mm0","mm2","mm4","mm6") - snow_vertical_compose_mmx_store(REG_c,"mm0","mm2","mm4","mm6") - snow_vertical_compose_mmx_add(REG_S,"mm0","mm2","mm4","mm6") - snow_vertical_compose_mmx_move("mm0","mm2","mm4","mm6","mm1","mm3","mm5","mm7") - snow_vertical_compose_mmx_sll("1","mm0","mm2","mm4","mm6") - snow_vertical_compose_mmx_r2r_add("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6") - snow_vertical_compose_mmx_sra("1","mm0","mm2","mm4","mm6") - snow_vertical_compose_mmx_add(REG_a,"mm0","mm2","mm4","mm6") - snow_vertical_compose_mmx_store(REG_a,"mm0","mm2","mm4","mm6") + snow_vertical_compose_sra("1","mm0","mm2","mm4","mm6") + snow_vertical_compose_r2r_add("mm1","mm3","mm5","mm7","mm0","mm2","mm4","mm6") + snow_vertical_compose_mmx_add("%2","mm0","mm2","mm4","mm6") + snow_vertical_compose_mmx_store("%2","mm0","mm2","mm4","mm6") "2: \n\t" - "sub $8, %%"REG_d" \n\t" + "sub $32, %%"REG_d" \n\t" "jge 1b \n\t" :"+d"(i) - : - "m"(b0),"m"(b1),"m"(b2),"m"(b3),"m"(b4),"m"(b5): - "%"REG_a"","%"REG_S"","%"REG_c""); + :"r"(b0),"r"(b1),"r"(b2),"r"(b3),"r"(b4),"r"(b5)); } +#endif //HAVE_7REGS #define snow_inner_add_yblock_sse2_header \ - DWTELEM * * dst_array = sb->line + src_y;\ + IDWTELEM * * dst_array = sb->line + src_y;\ long tmp;\ asm volatile(\ "mov %7, %%"REG_c" \n\t"\ @@ -636,8 +612,8 @@ void ff_snow_vertical_compose97i_mmx(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTE "mov %4, %%"REG_S" \n\t"\ "pxor %%xmm7, %%xmm7 \n\t" /* 0 */\ "pcmpeqd %%xmm3, %%xmm3 \n\t"\ - "pslld $31, %%xmm3 \n\t"\ - "psrld $24, %%xmm3 \n\t" /* FRAC_BITS >> 1 */\ + "psllw $15, %%xmm3 \n\t"\ + "psrlw $12, %%xmm3 \n\t" /* FRAC_BITS >> 1 */\ "1: \n\t"\ "mov %1, %%"REG_D" \n\t"\ "mov (%%"REG_D"), %%"REG_D" \n\t"\ @@ -691,7 +667,7 @@ void ff_snow_vertical_compose97i_mmx(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTE "jnz 1b \n\t"\ :"+m"(dst8),"+m"(dst_array),"=&r"(tmp)\ :\ - "rm"((long)(src_x<<2)),"m"(obmc),"a"(block),"m"((long)b_h),"m"((long)src_stride):\ + "rm"((long)(src_x<<1)),"m"(obmc),"a"(block),"m"((long)b_h),"m"((long)src_stride):\ "%"REG_c"","%"REG_S"","%"REG_D"","%"REG_d""); #define snow_inner_add_yblock_sse2_end_8\ @@ -765,36 +741,23 @@ snow_inner_add_yblock_sse2_accum_16("1", "512") snow_inner_add_yblock_sse2_accum_16("0", "528") "mov %0, %%"REG_d" \n\t" - "movdqa %%xmm1, %%xmm0 \n\t" - "movdqa %%xmm5, %%xmm4 \n\t" - "punpcklwd %%xmm7, %%xmm0 \n\t" - "paddd (%%"REG_D"), %%xmm0 \n\t" - "punpckhwd %%xmm7, %%xmm1 \n\t" - "paddd 16(%%"REG_D"), %%xmm1 \n\t" - "punpcklwd %%xmm7, %%xmm4 \n\t" - "paddd 32(%%"REG_D"), %%xmm4 \n\t" - "punpckhwd %%xmm7, %%xmm5 \n\t" - "paddd 48(%%"REG_D"), %%xmm5 \n\t" - "paddd %%xmm3, %%xmm0 \n\t" - "paddd %%xmm3, %%xmm1 \n\t" - "paddd %%xmm3, %%xmm4 \n\t" - "paddd %%xmm3, %%xmm5 \n\t" - "psrad $8, %%xmm0 \n\t" /* FRAC_BITS. */ - "psrad $8, %%xmm1 \n\t" /* FRAC_BITS. */ - "psrad $8, %%xmm4 \n\t" /* FRAC_BITS. */ - "psrad $8, %%xmm5 \n\t" /* FRAC_BITS. */ - - "packssdw %%xmm1, %%xmm0 \n\t" - "packssdw %%xmm5, %%xmm4 \n\t" - "packuswb %%xmm4, %%xmm0 \n\t" - - "movdqu %%xmm0, (%%"REG_d") \n\t" + "psrlw $4, %%xmm1 \n\t" + "psrlw $4, %%xmm5 \n\t" + "paddw (%%"REG_D"), %%xmm1 \n\t" + "paddw 16(%%"REG_D"), %%xmm5 \n\t" + "paddw %%xmm3, %%xmm1 \n\t" + "paddw %%xmm3, %%xmm5 \n\t" + "psraw $4, %%xmm1 \n\t" /* FRAC_BITS. */ + "psraw $4, %%xmm5 \n\t" /* FRAC_BITS. */ + "packuswb %%xmm5, %%xmm1 \n\t" + + "movdqu %%xmm1, (%%"REG_d") \n\t" snow_inner_add_yblock_sse2_end_16 } #define snow_inner_add_yblock_mmx_header \ - DWTELEM * * dst_array = sb->line + src_y;\ + IDWTELEM * * dst_array = sb->line + src_y;\ long tmp;\ asm volatile(\ "mov %7, %%"REG_c" \n\t"\ @@ -802,8 +765,8 @@ snow_inner_add_yblock_sse2_end_16 "mov %4, %%"REG_S" \n\t"\ "pxor %%mm7, %%mm7 \n\t" /* 0 */\ "pcmpeqd %%mm3, %%mm3 \n\t"\ - "pslld $31, %%mm3 \n\t"\ - "psrld $24, %%mm3 \n\t" /* FRAC_BITS >> 1 */\ + "psllw $15, %%mm3 \n\t"\ + "psrlw $12, %%mm3 \n\t" /* FRAC_BITS >> 1 */\ "1: \n\t"\ "mov %1, %%"REG_D" \n\t"\ "mov (%%"REG_D"), %%"REG_D" \n\t"\ @@ -829,29 +792,16 @@ snow_inner_add_yblock_sse2_end_16 #define snow_inner_add_yblock_mmx_mix(read_offset, write_offset)\ "mov %0, %%"REG_d" \n\t"\ - "movq %%mm1, %%mm0 \n\t"\ - "movq %%mm5, %%mm4 \n\t"\ - "punpcklwd %%mm7, %%mm0 \n\t"\ - "paddd "read_offset"(%%"REG_D"), %%mm0 \n\t"\ - "punpckhwd %%mm7, %%mm1 \n\t"\ - "paddd "read_offset"+8(%%"REG_D"), %%mm1 \n\t"\ - "punpcklwd %%mm7, %%mm4 \n\t"\ - "paddd "read_offset"+16(%%"REG_D"), %%mm4 \n\t"\ - "punpckhwd %%mm7, %%mm5 \n\t"\ - "paddd "read_offset"+24(%%"REG_D"), %%mm5 \n\t"\ - "paddd %%mm3, %%mm0 \n\t"\ - "paddd %%mm3, %%mm1 \n\t"\ - "paddd %%mm3, %%mm4 \n\t"\ - "paddd %%mm3, %%mm5 \n\t"\ - "psrad $8, %%mm0 \n\t"\ - "psrad $8, %%mm1 \n\t"\ - "psrad $8, %%mm4 \n\t"\ - "psrad $8, %%mm5 \n\t"\ -\ - "packssdw %%mm1, %%mm0 \n\t"\ - "packssdw %%mm5, %%mm4 \n\t"\ - "packuswb %%mm4, %%mm0 \n\t"\ - "movq %%mm0, "write_offset"(%%"REG_d") \n\t" + "psrlw $4, %%mm1 \n\t"\ + "psrlw $4, %%mm5 \n\t"\ + "paddw "read_offset"(%%"REG_D"), %%mm1 \n\t"\ + "paddw "read_offset"+8(%%"REG_D"), %%mm5 \n\t"\ + "paddw %%mm3, %%mm1 \n\t"\ + "paddw %%mm3, %%mm5 \n\t"\ + "psraw $4, %%mm1 \n\t"\ + "psraw $4, %%mm5 \n\t"\ + "packuswb %%mm5, %%mm1 \n\t"\ + "movq %%mm1, "write_offset"(%%"REG_d") \n\t" #define snow_inner_add_yblock_mmx_end(s_step)\ "add $"s_step", %%"REG_S" \n\t"\ @@ -865,7 +815,7 @@ snow_inner_add_yblock_sse2_end_16 "jnz 1b \n\t"\ :"+m"(dst8),"+m"(dst_array),"=&r"(tmp)\ :\ - "rm"((long)(src_x<<2)),"m"(obmc),"a"(block),"m"((long)b_h),"m"((long)src_stride):\ + "rm"((long)(src_x<<1)),"m"(obmc),"a"(block),"m"((long)b_h),"m"((long)src_stride):\ "%"REG_c"","%"REG_S"","%"REG_D"","%"REG_d""); static void inner_add_yblock_bw_8_obmc_16_mmx(const uint8_t *obmc, const long obmc_stride, uint8_t * * block, int b_w, long b_h, @@ -892,7 +842,7 @@ snow_inner_add_yblock_mmx_start("mm1", "mm5", "3", "8", "8") snow_inner_add_yblock_mmx_accum("2", "24", "8") snow_inner_add_yblock_mmx_accum("1", "520", "8") snow_inner_add_yblock_mmx_accum("0", "536", "8") -snow_inner_add_yblock_mmx_mix("32", "8") +snow_inner_add_yblock_mmx_mix("16", "8") snow_inner_add_yblock_mmx_end("32") } diff --git a/contrib/ffmpeg/libavcodec/i386/vc1dsp_mmx.c b/contrib/ffmpeg/libavcodec/i386/vc1dsp_mmx.c new file mode 100644 index 000000000..16fabd3e2 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/i386/vc1dsp_mmx.c @@ -0,0 +1,490 @@ +/* + * VC-1 and WMV3 - DSP functions MMX-optimized + * Copyright (c) 2007 Christophe GISQUET + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "dsputil.h" +#include "dsputil_mmx.h" +#include "x86_cpu.h" + +/** Add rounder from mm7 to mm3 and pack result at destination */ +#define NORMALIZE_MMX(SHIFT) \ + "paddw %%mm7, %%mm3 \n\t" /* +bias-r */ \ + "paddw %%mm7, %%mm4 \n\t" /* +bias-r */ \ + "psraw "SHIFT", %%mm3 \n\t" \ + "psraw "SHIFT", %%mm4 \n\t" + +#define TRANSFER_DO_PACK \ + "packuswb %%mm4, %%mm3 \n\t" \ + "movq %%mm3, (%2) \n\t" + +#define TRANSFER_DONT_PACK \ + "movq %%mm3, 0(%2) \n\t" \ + "movq %%mm4, 8(%2) \n\t" + +/** @see MSPEL_FILTER13_CORE for use as UNPACK macro */ +#define DO_UNPACK(reg) "punpcklbw %%mm0, " reg "\n\t" +#define DONT_UNPACK(reg) + +/** Compute the rounder 32-r or 8-r and unpacks it to mm7 */ +#define LOAD_ROUNDER_MMX(ROUND) \ + "movd "ROUND", %%mm7 \n\t" \ + "punpcklwd %%mm7, %%mm7 \n\t" \ + "punpckldq %%mm7, %%mm7 \n\t" + +#define SHIFT2_LINE(OFF, R0,R1,R2,R3) \ + "paddw %%mm"#R2", %%mm"#R1" \n\t" \ + "movd (%0,%3), %%mm"#R0" \n\t" \ + "pmullw %%mm6, %%mm"#R1" \n\t" \ + "punpcklbw %%mm0, %%mm"#R0" \n\t" \ + "movd (%0,%2), %%mm"#R3" \n\t" \ + "psubw %%mm"#R0", %%mm"#R1" \n\t" \ + "punpcklbw %%mm0, %%mm"#R3" \n\t" \ + "paddw %%mm7, %%mm"#R1" \n\t" \ + "psubw %%mm"#R3", %%mm"#R1" \n\t" \ + "psraw %4, %%mm"#R1" \n\t" \ + "movq %%mm"#R1", "#OFF"(%1) \n\t" \ + "add %2, %0 \n\t" + +DECLARE_ALIGNED_16(const uint64_t, ff_pw_9) = 0x0009000900090009ULL; + +/** Sacrifying mm6 allows to pipeline loads from src */ +static void vc1_put_ver_16b_shift2_mmx(int16_t *dst, + const uint8_t *src, long int stride, + int rnd, int64_t shift) +{ + asm volatile( + "mov $3, %%"REG_c" \n\t" + LOAD_ROUNDER_MMX("%5") + "movq "MANGLE(ff_pw_9)", %%mm6 \n\t" + "1: \n\t" + "movd (%0), %%mm2 \n\t" + "add %2, %0 \n\t" + "movd (%0), %%mm3 \n\t" + "punpcklbw %%mm0, %%mm2 \n\t" + "punpcklbw %%mm0, %%mm3 \n\t" + SHIFT2_LINE( 0, 1, 2, 3, 4) + SHIFT2_LINE( 24, 2, 3, 4, 1) + SHIFT2_LINE( 48, 3, 4, 1, 2) + SHIFT2_LINE( 72, 4, 1, 2, 3) + SHIFT2_LINE( 96, 1, 2, 3, 4) + SHIFT2_LINE(120, 2, 3, 4, 1) + SHIFT2_LINE(144, 3, 4, 1, 2) + SHIFT2_LINE(168, 4, 1, 2, 3) + "sub %6, %0 \n\t" + "add $8, %1 \n\t" + "dec %%"REG_c" \n\t" + "jnz 1b \n\t" + : "+r"(src), "+r"(dst) + : "r"(stride), "r"(-2*stride), + "m"(shift), "m"(rnd), "r"(9*stride-4) + : "%"REG_c, "memory" + ); +} + +/** + * Data is already unpacked, so some operations can directly be made from + * memory. + */ +static void vc1_put_hor_16b_shift2_mmx(uint8_t *dst, long int stride, + const int16_t *src, int rnd) +{ + int h = 8; + + src -= 1; + rnd -= (-1+9+9-1)*1024; /* Add -1024 bias */ + asm volatile( + LOAD_ROUNDER_MMX("%4") + "movq "MANGLE(ff_pw_128)", %%mm6\n\t" + "movq "MANGLE(ff_pw_9)", %%mm5 \n\t" + "1: \n\t" + "movq 2*0+0(%1), %%mm1 \n\t" + "movq 2*0+8(%1), %%mm2 \n\t" + "movq 2*1+0(%1), %%mm3 \n\t" + "movq 2*1+8(%1), %%mm4 \n\t" + "paddw 2*3+0(%1), %%mm1 \n\t" + "paddw 2*3+8(%1), %%mm2 \n\t" + "paddw 2*2+0(%1), %%mm3 \n\t" + "paddw 2*2+8(%1), %%mm4 \n\t" + "pmullw %%mm5, %%mm3 \n\t" + "pmullw %%mm5, %%mm4 \n\t" + "psubw %%mm1, %%mm3 \n\t" + "psubw %%mm2, %%mm4 \n\t" + NORMALIZE_MMX("$7") + /* Remove bias */ + "paddw %%mm6, %%mm3 \n\t" + "paddw %%mm6, %%mm4 \n\t" + TRANSFER_DO_PACK + "add $24, %1 \n\t" + "add %3, %2 \n\t" + "decl %0 \n\t" + "jnz 1b \n\t" + : "+r"(h), "+r" (src), "+r" (dst) + : "r"(stride), "m"(rnd) + : "memory" + ); +} + + +/** + * Purely vertical or horizontal 1/2 shift interpolation. + * Sacrify mm6 for *9 factor. + */ +static void vc1_put_shift2_mmx(uint8_t *dst, const uint8_t *src, + long int stride, int rnd, long int offset) +{ + rnd = 8-rnd; + asm volatile( + "mov $8, %%"REG_c" \n\t" + LOAD_ROUNDER_MMX("%5") + "movq "MANGLE(ff_pw_9)", %%mm6\n\t" + "1: \n\t" + "movd 0(%0 ), %%mm3 \n\t" + "movd 4(%0 ), %%mm4 \n\t" + "movd 0(%0,%2), %%mm1 \n\t" + "movd 4(%0,%2), %%mm2 \n\t" + "add %2, %0 \n\t" + "punpcklbw %%mm0, %%mm3 \n\t" + "punpcklbw %%mm0, %%mm4 \n\t" + "punpcklbw %%mm0, %%mm1 \n\t" + "punpcklbw %%mm0, %%mm2 \n\t" + "paddw %%mm1, %%mm3 \n\t" + "paddw %%mm2, %%mm4 \n\t" + "movd 0(%0,%3), %%mm1 \n\t" + "movd 4(%0,%3), %%mm2 \n\t" + "pmullw %%mm6, %%mm3 \n\t" /* 0,9,9,0*/ + "pmullw %%mm6, %%mm4 \n\t" /* 0,9,9,0*/ + "punpcklbw %%mm0, %%mm1 \n\t" + "punpcklbw %%mm0, %%mm2 \n\t" + "psubw %%mm1, %%mm3 \n\t" /*-1,9,9,0*/ + "psubw %%mm2, %%mm4 \n\t" /*-1,9,9,0*/ + "movd 0(%0,%2), %%mm1 \n\t" + "movd 4(%0,%2), %%mm2 \n\t" + "punpcklbw %%mm0, %%mm1 \n\t" + "punpcklbw %%mm0, %%mm2 \n\t" + "psubw %%mm1, %%mm3 \n\t" /*-1,9,9,-1*/ + "psubw %%mm2, %%mm4 \n\t" /*-1,9,9,-1*/ + NORMALIZE_MMX("$4") + "packuswb %%mm4, %%mm3 \n\t" + "movq %%mm3, (%1) \n\t" + "add %6, %0 \n\t" + "add %4, %1 \n\t" + "dec %%"REG_c" \n\t" + "jnz 1b \n\t" + : "+r"(src), "+r"(dst) + : "r"(offset), "r"(-2*offset), "g"(stride), "m"(rnd), + "g"(stride-offset) + : "%"REG_c, "memory" + ); +} + +/** + * Filter coefficients made global to allow access by all 1 or 3 quarter shift + * interpolation functions. + */ +DECLARE_ALIGNED_16(const uint64_t, ff_pw_53) = 0x0035003500350035ULL; +DECLARE_ALIGNED_16(const uint64_t, ff_pw_18) = 0x0012001200120012ULL; + +/** + * Core of the 1/4 and 3/4 shift bicubic interpolation. + * + * @param UNPACK Macro unpacking arguments from 8 to 16bits (can be empty). + * @param MOVQ "movd 1" or "movq 2", if data read is already unpacked. + * @param A1 Address of 1st tap (beware of unpacked/packed). + * @param A2 Address of 2nd tap + * @param A3 Address of 3rd tap + * @param A4 Address of 4th tap + */ +#define MSPEL_FILTER13_CORE(UNPACK, MOVQ, A1, A2, A3, A4) \ + MOVQ "*0+"A1", %%mm1 \n\t" \ + MOVQ "*4+"A1", %%mm2 \n\t" \ + UNPACK("%%mm1") \ + UNPACK("%%mm2") \ + "pmullw "MANGLE(ff_pw_3)", %%mm1\n\t" \ + "pmullw "MANGLE(ff_pw_3)", %%mm2\n\t" \ + MOVQ "*0+"A2", %%mm3 \n\t" \ + MOVQ "*4+"A2", %%mm4 \n\t" \ + UNPACK("%%mm3") \ + UNPACK("%%mm4") \ + "pmullw %%mm6, %%mm3 \n\t" /* *18 */ \ + "pmullw %%mm6, %%mm4 \n\t" /* *18 */ \ + "psubw %%mm1, %%mm3 \n\t" /* 18,-3 */ \ + "psubw %%mm2, %%mm4 \n\t" /* 18,-3 */ \ + MOVQ "*0+"A4", %%mm1 \n\t" \ + MOVQ "*4+"A4", %%mm2 \n\t" \ + UNPACK("%%mm1") \ + UNPACK("%%mm2") \ + "psllw $2, %%mm1 \n\t" /* 4* */ \ + "psllw $2, %%mm2 \n\t" /* 4* */ \ + "psubw %%mm1, %%mm3 \n\t" /* -4,18,-3 */ \ + "psubw %%mm2, %%mm4 \n\t" /* -4,18,-3 */ \ + MOVQ "*0+"A3", %%mm1 \n\t" \ + MOVQ "*4+"A3", %%mm2 \n\t" \ + UNPACK("%%mm1") \ + UNPACK("%%mm2") \ + "pmullw %%mm5, %%mm1 \n\t" /* *53 */ \ + "pmullw %%mm5, %%mm2 \n\t" /* *53 */ \ + "paddw %%mm1, %%mm3 \n\t" /* 4,53,18,-3 */ \ + "paddw %%mm2, %%mm4 \n\t" /* 4,53,18,-3 */ + +/** + * Macro to build the vertical 16bits version of vc1_put_shift[13]. + * Here, offset=src_stride. Parameters passed A1 to A4 must use + * %3 (src_stride) and %4 (3*src_stride). + * + * @param NAME Either 1 or 3 + * @see MSPEL_FILTER13_CORE for information on A1->A4 + */ +#define MSPEL_FILTER13_VER_16B(NAME, A1, A2, A3, A4) \ +static void \ +vc1_put_ver_16b_ ## NAME ## _mmx(int16_t *dst, const uint8_t *src, \ + long int src_stride, \ + int rnd, int64_t shift) \ +{ \ + int h = 8; \ + src -= src_stride; \ + asm volatile( \ + LOAD_ROUNDER_MMX("%5") \ + "movq "MANGLE(ff_pw_53)", %%mm5\n\t" \ + "movq "MANGLE(ff_pw_18)", %%mm6\n\t" \ + ASMALIGN(3) \ + "1: \n\t" \ + MSPEL_FILTER13_CORE(DO_UNPACK, "movd 1", A1, A2, A3, A4) \ + NORMALIZE_MMX("%6") \ + TRANSFER_DONT_PACK \ + /* Last 3 (in fact 4) bytes on the line */ \ + "movd 8+"A1", %%mm1 \n\t" \ + DO_UNPACK("%%mm1") \ + "movq %%mm1, %%mm3 \n\t" \ + "paddw %%mm1, %%mm1 \n\t" \ + "paddw %%mm3, %%mm1 \n\t" /* 3* */ \ + "movd 8+"A2", %%mm3 \n\t" \ + DO_UNPACK("%%mm3") \ + "pmullw %%mm6, %%mm3 \n\t" /* *18 */ \ + "psubw %%mm1, %%mm3 \n\t" /*18,-3 */ \ + "movd 8+"A3", %%mm1 \n\t" \ + DO_UNPACK("%%mm1") \ + "pmullw %%mm5, %%mm1 \n\t" /* *53 */ \ + "paddw %%mm1, %%mm3 \n\t" /*53,18,-3 */ \ + "movd 8+"A4", %%mm1 \n\t" \ + DO_UNPACK("%%mm1") \ + "psllw $2, %%mm1 \n\t" /* 4* */ \ + "psubw %%mm1, %%mm3 \n\t" \ + "paddw %%mm7, %%mm3 \n\t" \ + "psraw %6, %%mm3 \n\t" \ + "movq %%mm3, 16(%2) \n\t" \ + "add %3, %1 \n\t" \ + "add $24, %2 \n\t" \ + "decl %0 \n\t" \ + "jnz 1b \n\t" \ + : "+r"(h), "+r" (src), "+r" (dst) \ + : "r"(src_stride), "r"(3*src_stride), \ + "m"(rnd), "m"(shift) \ + : "memory" \ + ); \ +} + +/** + * Macro to build the horizontal 16bits version of vc1_put_shift[13]. + * Here, offset=16bits, so parameters passed A1 to A4 should be simple. + * + * @param NAME Either 1 or 3 + * @see MSPEL_FILTER13_CORE for information on A1->A4 + */ +#define MSPEL_FILTER13_HOR_16B(NAME, A1, A2, A3, A4) \ +static void \ +vc1_put_hor_16b_ ## NAME ## _mmx(uint8_t *dst, long int stride, \ + const int16_t *src, int rnd) \ +{ \ + int h = 8; \ + src -= 1; \ + rnd -= (-4+58+13-3)*256; /* Add -256 bias */ \ + asm volatile( \ + LOAD_ROUNDER_MMX("%4") \ + "movq "MANGLE(ff_pw_18)", %%mm6 \n\t" \ + "movq "MANGLE(ff_pw_53)", %%mm5 \n\t" \ + ASMALIGN(3) \ + "1: \n\t" \ + MSPEL_FILTER13_CORE(DONT_UNPACK, "movq 2", A1, A2, A3, A4) \ + NORMALIZE_MMX("$7") \ + /* Remove bias */ \ + "paddw "MANGLE(ff_pw_128)", %%mm3 \n\t" \ + "paddw "MANGLE(ff_pw_128)", %%mm4 \n\t" \ + TRANSFER_DO_PACK \ + "add $24, %1 \n\t" \ + "add %3, %2 \n\t" \ + "decl %0 \n\t" \ + "jnz 1b \n\t" \ + : "+r"(h), "+r" (src), "+r" (dst) \ + : "r"(stride), "m"(rnd) \ + : "memory" \ + ); \ +} + +/** + * Macro to build the 8bits, any direction, version of vc1_put_shift[13]. + * Here, offset=src_stride. Parameters passed A1 to A4 must use + * %3 (offset) and %4 (3*offset). + * + * @param NAME Either 1 or 3 + * @see MSPEL_FILTER13_CORE for information on A1->A4 + */ +#define MSPEL_FILTER13_8B(NAME, A1, A2, A3, A4) \ +static void \ +vc1_put_## NAME ## _mmx(uint8_t *dst, const uint8_t *src, \ + long int stride, int rnd, long int offset) \ +{ \ + int h = 8; \ + src -= offset; \ + rnd = 32-rnd; \ + asm volatile ( \ + LOAD_ROUNDER_MMX("%6") \ + "movq "MANGLE(ff_pw_53)", %%mm5 \n\t" \ + "movq "MANGLE(ff_pw_18)", %%mm6 \n\t" \ + ASMALIGN(3) \ + "1: \n\t" \ + MSPEL_FILTER13_CORE(DO_UNPACK, "movd 1", A1, A2, A3, A4) \ + NORMALIZE_MMX("$6") \ + TRANSFER_DO_PACK \ + "add %5, %1 \n\t" \ + "add %5, %2 \n\t" \ + "decl %0 \n\t" \ + "jnz 1b \n\t" \ + : "+r"(h), "+r" (src), "+r" (dst) \ + : "r"(offset), "r"(3*offset), "g"(stride), "m"(rnd) \ + : "memory" \ + ); \ +} + +/** 1/4 shift bicubic interpolation */ +MSPEL_FILTER13_8B (shift1, "0(%1,%4 )", "0(%1,%3,2)", "0(%1,%3 )", "0(%1 )") +MSPEL_FILTER13_VER_16B(shift1, "0(%1,%4 )", "0(%1,%3,2)", "0(%1,%3 )", "0(%1 )") +MSPEL_FILTER13_HOR_16B(shift1, "2*3(%1)", "2*2(%1)", "2*1(%1)", "2*0(%1)") + +/** 3/4 shift bicubic interpolation */ +MSPEL_FILTER13_8B (shift3, "0(%1 )", "0(%1,%3 )", "0(%1,%3,2)", "0(%1,%4 )") +MSPEL_FILTER13_VER_16B(shift3, "0(%1 )", "0(%1,%3 )", "0(%1,%3,2)", "0(%1,%4 )") +MSPEL_FILTER13_HOR_16B(shift3, "2*0(%1)", "2*1(%1)", "2*2(%1)", "2*3(%1)") + +typedef void (*vc1_mspel_mc_filter_ver_16bits)(int16_t *dst, const uint8_t *src, long int src_stride, int rnd, int64_t shift); +typedef void (*vc1_mspel_mc_filter_hor_16bits)(uint8_t *dst, long int dst_stride, const int16_t *src, int rnd); +typedef void (*vc1_mspel_mc_filter_8bits)(uint8_t *dst, const uint8_t *src, long int stride, int rnd, long int offset); + +/** + * Interpolates fractional pel values by applying proper vertical then + * horizontal filter. + * + * @param dst Destination buffer for interpolated pels. + * @param src Source buffer. + * @param stride Stride for both src and dst buffers. + * @param hmode Horizontal filter (expressed in quarter pixels shift). + * @param hmode Vertical filter. + * @param rnd Rounding bias. + */ +static void vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride, + int hmode, int vmode, int rnd) +{ + static const vc1_mspel_mc_filter_ver_16bits vc1_put_shift_ver_16bits[] = + { NULL, vc1_put_ver_16b_shift1_mmx, vc1_put_ver_16b_shift2_mmx, vc1_put_ver_16b_shift3_mmx }; + static const vc1_mspel_mc_filter_hor_16bits vc1_put_shift_hor_16bits[] = + { NULL, vc1_put_hor_16b_shift1_mmx, vc1_put_hor_16b_shift2_mmx, vc1_put_hor_16b_shift3_mmx }; + static const vc1_mspel_mc_filter_8bits vc1_put_shift_8bits[] = + { NULL, vc1_put_shift1_mmx, vc1_put_shift2_mmx, vc1_put_shift3_mmx }; + + asm volatile( + "pxor %%mm0, %%mm0 \n\t" + ::: "memory" + ); + + if (vmode) { /* Vertical filter to apply */ + if (hmode) { /* Horizontal filter to apply, output to tmp */ + static const int shift_value[] = { 0, 5, 1, 5 }; + int shift = (shift_value[hmode]+shift_value[vmode])>>1; + int r; + DECLARE_ALIGNED_16(int16_t, tmp[12*8]); + + r = (1<<(shift-1)) + rnd-1; + vc1_put_shift_ver_16bits[vmode](tmp, src-1, stride, r, shift); + + vc1_put_shift_hor_16bits[hmode](dst, stride, tmp+1, 64-rnd); + return; + } + else { /* No horizontal filter, output 8 lines to dst */ + vc1_put_shift_8bits[vmode](dst, src, stride, 1-rnd, stride); + return; + } + } + + /* Horizontal mode with no vertical mode */ + vc1_put_shift_8bits[hmode](dst, src, stride, rnd, 1); +} + +void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd); + +/** Macro to ease bicubic filter interpolation functions declarations */ +#define DECLARE_FUNCTION(a, b) \ +static void put_vc1_mspel_mc ## a ## b ## _mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd) { \ + vc1_mspel_mc(dst, src, stride, a, b, rnd); \ +} + +DECLARE_FUNCTION(0, 1) +DECLARE_FUNCTION(0, 2) +DECLARE_FUNCTION(0, 3) + +DECLARE_FUNCTION(1, 0) +DECLARE_FUNCTION(1, 1) +DECLARE_FUNCTION(1, 2) +DECLARE_FUNCTION(1, 3) + +DECLARE_FUNCTION(2, 0) +DECLARE_FUNCTION(2, 1) +DECLARE_FUNCTION(2, 2) +DECLARE_FUNCTION(2, 3) + +DECLARE_FUNCTION(3, 0) +DECLARE_FUNCTION(3, 1) +DECLARE_FUNCTION(3, 2) +DECLARE_FUNCTION(3, 3) + +void ff_vc1dsp_init_mmx(DSPContext* dsp, AVCodecContext *avctx) { + dsp->put_vc1_mspel_pixels_tab[ 0] = ff_put_vc1_mspel_mc00_mmx; + dsp->put_vc1_mspel_pixels_tab[ 4] = put_vc1_mspel_mc01_mmx; + dsp->put_vc1_mspel_pixels_tab[ 8] = put_vc1_mspel_mc02_mmx; + dsp->put_vc1_mspel_pixels_tab[12] = put_vc1_mspel_mc03_mmx; + + dsp->put_vc1_mspel_pixels_tab[ 1] = put_vc1_mspel_mc10_mmx; + dsp->put_vc1_mspel_pixels_tab[ 5] = put_vc1_mspel_mc11_mmx; + dsp->put_vc1_mspel_pixels_tab[ 9] = put_vc1_mspel_mc12_mmx; + dsp->put_vc1_mspel_pixels_tab[13] = put_vc1_mspel_mc13_mmx; + + dsp->put_vc1_mspel_pixels_tab[ 2] = put_vc1_mspel_mc20_mmx; + dsp->put_vc1_mspel_pixels_tab[ 6] = put_vc1_mspel_mc21_mmx; + dsp->put_vc1_mspel_pixels_tab[10] = put_vc1_mspel_mc22_mmx; + dsp->put_vc1_mspel_pixels_tab[14] = put_vc1_mspel_mc23_mmx; + + dsp->put_vc1_mspel_pixels_tab[ 3] = put_vc1_mspel_mc30_mmx; + dsp->put_vc1_mspel_pixels_tab[ 7] = put_vc1_mspel_mc31_mmx; + dsp->put_vc1_mspel_pixels_tab[11] = put_vc1_mspel_mc32_mmx; + dsp->put_vc1_mspel_pixels_tab[15] = put_vc1_mspel_mc33_mmx; +} diff --git a/contrib/ffmpeg/libavcodec/i386/vp3dsp_mmx.c b/contrib/ffmpeg/libavcodec/i386/vp3dsp_mmx.c index f715dc803..d71a2b414 100644 --- a/contrib/ffmpeg/libavcodec/i386/vp3dsp_mmx.c +++ b/contrib/ffmpeg/libavcodec/i386/vp3dsp_mmx.c @@ -23,7 +23,7 @@ * MMX-optimized functions cribbed from the original VP3 source code. */ -#include "../dsputil.h" +#include "dsputil.h" #include "mmx.h" #define IdctAdjustBeforeShift 8 @@ -322,3 +322,15 @@ void ff_vp3_idct_mmx(int16_t *output_data) #undef J } + +void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, DCTELEM *block) +{ + ff_vp3_idct_mmx(block); + put_signed_pixels_clamped_mmx(block, dest, line_size); +} + +void ff_vp3_idct_add_mmx(uint8_t *dest, int line_size, DCTELEM *block) +{ + ff_vp3_idct_mmx(block); + add_pixels_clamped_mmx(block, dest, line_size); +} diff --git a/contrib/ffmpeg/libavcodec/i386/vp3dsp_mmx.h b/contrib/ffmpeg/libavcodec/i386/vp3dsp_mmx.h new file mode 100644 index 000000000..7c2bc601b --- /dev/null +++ b/contrib/ffmpeg/libavcodec/i386/vp3dsp_mmx.h @@ -0,0 +1,32 @@ +/* + * vp3dsp MMX function declarations + * Copyright (c) 2007 Aurelien Jacobs + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_VP3DSP_MMX_H +#define FFMPEG_VP3DSP_MMX_H + +#include "dsputil.h" + +void ff_vp3_idct_mmx(int16_t *data); +void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, DCTELEM *block); +void ff_vp3_idct_add_mmx(uint8_t *dest, int line_size, DCTELEM *block); +void ff_vp3_dsp_init_mmx(void); + +#endif /* FFMPEG_VP3DSP_MMX_H */ diff --git a/contrib/ffmpeg/libavcodec/i386/vp3dsp_sse2.c b/contrib/ffmpeg/libavcodec/i386/vp3dsp_sse2.c index bd2911d59..3105e7f5f 100644 --- a/contrib/ffmpeg/libavcodec/i386/vp3dsp_sse2.c +++ b/contrib/ffmpeg/libavcodec/i386/vp3dsp_sse2.c @@ -23,7 +23,7 @@ * SSE2-optimized functions cribbed from the original VP3 source code. */ -#include "../dsputil.h" +#include "dsputil.h" #include "mmx.h" static DECLARE_ALIGNED_16(const unsigned short, SSE2_dequant_const[]) = @@ -802,8 +802,8 @@ void ff_vp3_idct_sse2(int16_t *input_data) { unsigned char *input_bytes = (unsigned char *)input_data; unsigned char *output_data_bytes = (unsigned char *)input_data; - unsigned char *idct_data_bytes = (unsigned char *)SSE2_idct_data; - unsigned char *Eight = (unsigned char *)eight_data; + const unsigned char *idct_data_bytes = (const unsigned char *)SSE2_idct_data; + const unsigned char *Eight = (const unsigned char *)eight_data; #define eax input_bytes //#define ebx dequant_matrix_bytes @@ -825,3 +825,15 @@ void ff_vp3_idct_sse2(int16_t *input_data) SSE2_Column_IDCT(); } + +void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, DCTELEM *block) +{ + ff_vp3_idct_sse2(block); + put_signed_pixels_clamped_mmx(block, dest, line_size); +} + +void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, DCTELEM *block) +{ + ff_vp3_idct_sse2(block); + add_pixels_clamped_mmx(block, dest, line_size); +} diff --git a/contrib/ffmpeg/libavcodec/i386/vp3dsp_sse2.h b/contrib/ffmpeg/libavcodec/i386/vp3dsp_sse2.h new file mode 100644 index 000000000..d02918f45 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/i386/vp3dsp_sse2.h @@ -0,0 +1,31 @@ +/* + * vp3dsp SSE2 function declarations + * Copyright (c) 2007 Aurelien Jacobs + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_VP3DSP_SSE2_H +#define FFMPEG_VP3DSP_SSE2_H + +#include "dsputil.h" + +void ff_vp3_idct_sse2(int16_t *input_data); +void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, DCTELEM *block); +void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, DCTELEM *block); + +#endif /* FFMPEG_VP3DSP_SSE2_H */ diff --git a/contrib/ffmpeg/libavcodec/idcinvideo.c b/contrib/ffmpeg/libavcodec/idcinvideo.c index 112da7bc6..79ed6fb17 100644 --- a/contrib/ffmpeg/libavcodec/idcinvideo.c +++ b/contrib/ffmpeg/libavcodec/idcinvideo.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -50,7 +49,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include "dsputil.h" @@ -71,7 +69,7 @@ typedef struct IdcinContext { DSPContext dsp; AVFrame frame; - unsigned char *buf; + const unsigned char *buf; int size; hnode_t huff_nodes[256][HUF_TOKENS*2]; @@ -149,13 +147,12 @@ static void huff_build_tree(IdcinContext *s, int prev) { static int idcin_decode_init(AVCodecContext *avctx) { - IdcinContext *s = (IdcinContext *)avctx->priv_data; + IdcinContext *s = avctx->priv_data; int i, j, histogram_index = 0; unsigned char *histograms; s->avctx = avctx; avctx->pix_fmt = PIX_FMT_PAL8; - avctx->has_b_frames = 0; dsputil_init(&s->dsp, avctx); /* make sure the Huffman tables make it */ @@ -215,9 +212,9 @@ static void idcin_decode_vlcs(IdcinContext *s) static int idcin_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { - IdcinContext *s = (IdcinContext *)avctx->priv_data; + IdcinContext *s = avctx->priv_data; AVPaletteControl *palette_control = avctx->palctrl; s->buf = buf; @@ -250,7 +247,7 @@ static int idcin_decode_frame(AVCodecContext *avctx, static int idcin_decode_end(AVCodecContext *avctx) { - IdcinContext *s = (IdcinContext *)avctx->priv_data; + IdcinContext *s = avctx->priv_data; if (s->frame.data[0]) avctx->release_buffer(avctx, &s->frame); diff --git a/contrib/ffmpeg/libavcodec/imc.c b/contrib/ffmpeg/libavcodec/imc.c index 6140130b1..237ff6816 100644 --- a/contrib/ffmpeg/libavcodec/imc.c +++ b/contrib/ffmpeg/libavcodec/imc.c @@ -19,7 +19,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -42,6 +41,7 @@ #include "imcdata.h" +#define IMC_BLOCK_SIZE 64 #define IMC_FRAME_ID 0x21 #define BANDS 32 #define COEFFS 256 @@ -455,7 +455,7 @@ static void imc_get_skip_coeff(IMCContext* q) { q->skipFlagBits[i] = band_tab[i+1] - band_tab[i]; for(j = band_tab[i]; j < band_tab[i+1]; j++) { - if ((q->skipFlags[j] = get_bits(&q->gb,1))) + if ((q->skipFlags[j] = get_bits1(&q->gb))) q->skipFlagCount[i]++; } } else { @@ -486,7 +486,7 @@ static void imc_get_skip_coeff(IMCContext* q) { if (j < band_tab[i+1]) { q->skipFlagBits[i]++; - if ((q->skipFlags[j] = get_bits(&q->gb,1))) + if ((q->skipFlags[j] = get_bits1(&q->gb))) q->skipFlagCount[i]++; } } @@ -626,7 +626,7 @@ static int imc_get_coeffs (IMCContext* q) { static int imc_decode_frame(AVCodecContext * avctx, void *data, int *data_size, - uint8_t * buf, int buf_size) + const uint8_t * buf, int buf_size) { IMCContext *q = avctx->priv_data; @@ -636,13 +636,16 @@ static int imc_decode_frame(AVCodecContext * avctx, int flag; int bits, summer; int counter, bitscount; - uint16_t *buf16 = (uint16_t *) buf; + uint16_t buf16[IMC_BLOCK_SIZE / 2]; - /* FIXME: input should not be modified */ - for(i = 0; i < FFMIN(buf_size, avctx->block_align) / 2; i++) - buf16[i] = bswap_16(buf16[i]); + if (buf_size < IMC_BLOCK_SIZE) { + av_log(avctx, AV_LOG_ERROR, "imc frame too small!\n"); + return -1; + } + for(i = 0; i < IMC_BLOCK_SIZE / 2; i++) + buf16[i] = bswap_16(((const uint16_t*)buf)[i]); - init_get_bits(&q->gb, buf, 512); + init_get_bits(&q->gb, (const uint8_t*)buf16, IMC_BLOCK_SIZE * 8); /* Check the frame header */ imc_hdr = get_bits(&q->gb, 9); @@ -789,7 +792,7 @@ static int imc_decode_frame(AVCodecContext * avctx, *data_size = COEFFS * sizeof(int16_t); - return avctx->block_align; + return IMC_BLOCK_SIZE; } diff --git a/contrib/ffmpeg/libavcodec/imcdata.h b/contrib/ffmpeg/libavcodec/imcdata.h index 92ed275f1..75f4fd744 100644 --- a/contrib/ffmpeg/libavcodec/imcdata.h +++ b/contrib/ffmpeg/libavcodec/imcdata.h @@ -19,9 +19,13 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ +#ifndef FFMPEG_IMCDATA_H +#define FFMPEG_IMCDATA_H + +#include + static const uint16_t band_tab[33] = { 0, 3, 6, 9, 12, 16, 20, 24, 29, 34, 40, 46, 53, 60, 68, 76, 84, 93, 102, 111, 121, 131, @@ -162,3 +166,4 @@ static const uint16_t imc_huffman_bits[4][4][18] = { } }; +#endif /* FFMPEG_IMCDATA_H */ diff --git a/contrib/ffmpeg/libavcodec/imgconvert.c b/contrib/ffmpeg/libavcodec/imgconvert.c index 2971afaa8..468035f36 100644 --- a/contrib/ffmpeg/libavcodec/imgconvert.c +++ b/contrib/ffmpeg/libavcodec/imgconvert.c @@ -1,5 +1,5 @@ /* - * Misc image convertion routines + * Misc image conversion routines * Copyright (c) 2001, 2002, 2003 Fabrice Bellard. * * This file is part of FFmpeg. @@ -21,7 +21,7 @@ /** * @file imgconvert.c - * Misc image convertion routines. + * misc image conversion routines */ /* TODO: @@ -32,10 +32,7 @@ #include "avcodec.h" #include "dsputil.h" - -#ifdef USE_FASTMEMCPY -#include "libvo/fastmemcpy.h" -#endif +#include "colorspace.h" #ifdef HAVE_MMX #include "i386/mmx.h" @@ -123,6 +120,24 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = { .depth = 8, .x_chroma_shift = 2, .y_chroma_shift = 0, }, + [PIX_FMT_YUV440P] = { + .name = "yuv440p", + .nb_channels = 3, + .color_type = FF_COLOR_YUV, + .pixel_type = FF_PIXEL_PLANAR, + .depth = 8, + .x_chroma_shift = 0, .y_chroma_shift = 1, + }, + + /* YUV formats with alpha plane */ + [PIX_FMT_YUVA420P] = { + .name = "yuva420p", + .nb_channels = 4, + .color_type = FF_COLOR_YUV, + .pixel_type = FF_PIXEL_PLANAR, + .depth = 8, + .x_chroma_shift = 1, .y_chroma_shift = 1, + }, /* JPEG YUV */ [PIX_FMT_YUVJ420P] = { @@ -149,6 +164,14 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = { .depth = 8, .x_chroma_shift = 0, .y_chroma_shift = 0, }, + [PIX_FMT_YUVJ440P] = { + .name = "yuvj440p", + .nb_channels = 3, + .color_type = FF_COLOR_YUV_JPEG, + .pixel_type = FF_PIXEL_PLANAR, + .depth = 8, + .x_chroma_shift = 0, .y_chroma_shift = 1, + }, /* RGB formats */ [PIX_FMT_RGB24] = { @@ -382,64 +405,74 @@ enum PixelFormat avcodec_get_pix_fmt(const char* name) return i; } -int avpicture_fill(AVPicture *picture, uint8_t *ptr, - int pix_fmt, int width, int height) +void avcodec_pix_fmt_string (char *buf, int buf_size, int pix_fmt) +{ + PixFmtInfo info= pix_fmt_info[pix_fmt]; + + char is_alpha_char= info.is_alpha ? 'y' : 'n'; + + /* print header */ + if (pix_fmt < 0) + snprintf (buf, buf_size, + "name " " nb_channels" " depth" " is_alpha" + ); + else + snprintf (buf, buf_size, + "%-10s" " %1d " " %2d " " %c ", + info.name, + info.nb_channels, + info.depth, + is_alpha_char + ); +} + +int ff_fill_linesize(AVPicture *picture, int pix_fmt, int width) { - int size, w2, h2, size2; + int w2; const PixFmtInfo *pinfo; - if(avcodec_check_dimensions(NULL, width, height)) - goto fail; + memset(picture->linesize, 0, sizeof(picture->linesize)); pinfo = &pix_fmt_info[pix_fmt]; - size = width * height; switch(pix_fmt) { case PIX_FMT_YUV420P: case PIX_FMT_YUV422P: case PIX_FMT_YUV444P: case PIX_FMT_YUV410P: case PIX_FMT_YUV411P: + case PIX_FMT_YUV440P: case PIX_FMT_YUVJ420P: case PIX_FMT_YUVJ422P: case PIX_FMT_YUVJ444P: + case PIX_FMT_YUVJ440P: w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift; - h2 = (height + (1 << pinfo->y_chroma_shift) - 1) >> pinfo->y_chroma_shift; - size2 = w2 * h2; - picture->data[0] = ptr; - picture->data[1] = picture->data[0] + size; - picture->data[2] = picture->data[1] + size2; picture->linesize[0] = width; picture->linesize[1] = w2; picture->linesize[2] = w2; - return size + 2 * size2; + break; + case PIX_FMT_YUVA420P: + w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift; + picture->linesize[0] = width; + picture->linesize[1] = w2; + picture->linesize[2] = w2; + picture->linesize[3] = width; + break; case PIX_FMT_NV12: case PIX_FMT_NV21: w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift; - h2 = (height + (1 << pinfo->y_chroma_shift) - 1) >> pinfo->y_chroma_shift; - size2 = w2 * h2 * 2; - picture->data[0] = ptr; - picture->data[1] = picture->data[0] + size; - picture->data[2] = NULL; picture->linesize[0] = width; picture->linesize[1] = w2; - picture->linesize[2] = 0; - return size + 2 * size2; + break; case PIX_FMT_RGB24: case PIX_FMT_BGR24: - picture->data[0] = ptr; - picture->data[1] = NULL; - picture->data[2] = NULL; picture->linesize[0] = width * 3; - return size * 3; + break; case PIX_FMT_RGB32: case PIX_FMT_BGR32: case PIX_FMT_RGB32_1: case PIX_FMT_BGR32_1: - picture->data[0] = ptr; - picture->data[1] = NULL; - picture->data[2] = NULL; picture->linesize[0] = width * 4; - return size * 4; + break; case PIX_FMT_GRAY16BE: case PIX_FMT_GRAY16LE: case PIX_FMT_BGR555: @@ -447,57 +480,119 @@ int avpicture_fill(AVPicture *picture, uint8_t *ptr, case PIX_FMT_RGB555: case PIX_FMT_RGB565: case PIX_FMT_YUYV422: - picture->data[0] = ptr; - picture->data[1] = NULL; - picture->data[2] = NULL; picture->linesize[0] = width * 2; - return size * 2; + break; case PIX_FMT_UYVY422: - picture->data[0] = ptr; - picture->data[1] = NULL; - picture->data[2] = NULL; picture->linesize[0] = width * 2; - return size * 2; + break; case PIX_FMT_UYYVYY411: - picture->data[0] = ptr; - picture->data[1] = NULL; - picture->data[2] = NULL; picture->linesize[0] = width + width/2; - return size + size/2; + break; case PIX_FMT_RGB8: case PIX_FMT_BGR8: case PIX_FMT_RGB4_BYTE: case PIX_FMT_BGR4_BYTE: case PIX_FMT_GRAY8: - picture->data[0] = ptr; - picture->data[1] = NULL; - picture->data[2] = NULL; picture->linesize[0] = width; - return size; + break; case PIX_FMT_RGB4: case PIX_FMT_BGR4: + picture->linesize[0] = width / 2; + break; + case PIX_FMT_MONOWHITE: + case PIX_FMT_MONOBLACK: + picture->linesize[0] = (width + 7) >> 3; + break; + case PIX_FMT_PAL8: + picture->linesize[0] = width; + picture->linesize[1] = 4; + break; + default: + return -1; + } + return 0; +} + +int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, int pix_fmt, + int height) +{ + int size, h2, size2; + const PixFmtInfo *pinfo; + + pinfo = &pix_fmt_info[pix_fmt]; + size = picture->linesize[0] * height; + switch(pix_fmt) { + case PIX_FMT_YUV420P: + case PIX_FMT_YUV422P: + case PIX_FMT_YUV444P: + case PIX_FMT_YUV410P: + case PIX_FMT_YUV411P: + case PIX_FMT_YUV440P: + case PIX_FMT_YUVJ420P: + case PIX_FMT_YUVJ422P: + case PIX_FMT_YUVJ444P: + case PIX_FMT_YUVJ440P: + h2 = (height + (1 << pinfo->y_chroma_shift) - 1) >> pinfo->y_chroma_shift; + size2 = picture->linesize[1] * h2; picture->data[0] = ptr; - picture->data[1] = NULL; + picture->data[1] = picture->data[0] + size; + picture->data[2] = picture->data[1] + size2; + picture->data[3] = NULL; + return size + 2 * size2; + case PIX_FMT_YUVA420P: + h2 = (height + (1 << pinfo->y_chroma_shift) - 1) >> pinfo->y_chroma_shift; + size2 = picture->linesize[1] * h2; + picture->data[0] = ptr; + picture->data[1] = picture->data[0] + size; + picture->data[2] = picture->data[1] + size2; + picture->data[3] = picture->data[1] + size2 + size2; + return 2 * size + 2 * size2; + case PIX_FMT_NV12: + case PIX_FMT_NV21: + h2 = (height + (1 << pinfo->y_chroma_shift) - 1) >> pinfo->y_chroma_shift; + size2 = picture->linesize[1] * h2 * 2; + picture->data[0] = ptr; + picture->data[1] = picture->data[0] + size; picture->data[2] = NULL; - picture->linesize[0] = width / 2; - return size / 2; + picture->data[3] = NULL; + return size + 2 * size2; + case PIX_FMT_RGB24: + case PIX_FMT_BGR24: + case PIX_FMT_RGB32: + case PIX_FMT_BGR32: + case PIX_FMT_RGB32_1: + case PIX_FMT_BGR32_1: + case PIX_FMT_GRAY16BE: + case PIX_FMT_GRAY16LE: + case PIX_FMT_BGR555: + case PIX_FMT_BGR565: + case PIX_FMT_RGB555: + case PIX_FMT_RGB565: + case PIX_FMT_YUYV422: + case PIX_FMT_UYVY422: + case PIX_FMT_UYYVYY411: + case PIX_FMT_RGB8: + case PIX_FMT_BGR8: + case PIX_FMT_RGB4_BYTE: + case PIX_FMT_BGR4_BYTE: + case PIX_FMT_GRAY8: + case PIX_FMT_RGB4: + case PIX_FMT_BGR4: case PIX_FMT_MONOWHITE: case PIX_FMT_MONOBLACK: picture->data[0] = ptr; picture->data[1] = NULL; picture->data[2] = NULL; - picture->linesize[0] = (width + 7) >> 3; - return picture->linesize[0] * height; + picture->data[3] = NULL; + return size; case PIX_FMT_PAL8: size2 = (size + 3) & ~3; picture->data[0] = ptr; picture->data[1] = ptr + size2; /* palette is stored here as 256 32 bit words */ picture->data[2] = NULL; - picture->linesize[0] = width; - picture->linesize[1] = 4; + picture->data[3] = NULL; return size2 + 256 * 4; default: -fail: picture->data[0] = NULL; picture->data[1] = NULL; picture->data[2] = NULL; @@ -506,6 +601,19 @@ fail: } } +int avpicture_fill(AVPicture *picture, uint8_t *ptr, + int pix_fmt, int width, int height) +{ + + if(avcodec_check_dimensions(NULL, width, height)) + return -1; + + if (ff_fill_linesize(picture, pix_fmt, width)) + return -1; + + return ff_fill_pointer(picture, ptr, pix_fmt, height); +} + int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height, unsigned char *dest, int dest_size) { @@ -733,10 +841,9 @@ void ff_img_copy_plane(uint8_t *dst, int dst_wrap, } } -void av_picture_copy(AVPicture *dst, const AVPicture *src, - int pix_fmt, int width, int height) +int ff_get_plane_bytewidth(enum PixelFormat pix_fmt, int width, int plane) { - int bwidth, bits, i; + int bits; const PixFmtInfo *pf = &pix_fmt_info[pix_fmt]; pf = &pix_fmt_info[pix_fmt]; @@ -758,21 +865,42 @@ void av_picture_copy(AVPicture *dst, const AVPicture *src, bits = pf->depth * pf->nb_channels; break; } - bwidth = (width * bits + 7) >> 3; - ff_img_copy_plane(dst->data[0], dst->linesize[0], - src->data[0], src->linesize[0], - bwidth, height); + return (width * bits + 7) >> 3; break; + case FF_PIXEL_PLANAR: + if (plane == 1 || plane == 2) + width >>= pf->x_chroma_shift; + + return (width * pf->depth + 7) >> 3; + break; + case FF_PIXEL_PALETTE: + if (plane == 0) + return width; + break; + } + + return -1; +} + +void av_picture_copy(AVPicture *dst, const AVPicture *src, + int pix_fmt, int width, int height) +{ + int i; + const PixFmtInfo *pf = &pix_fmt_info[pix_fmt]; + + pf = &pix_fmt_info[pix_fmt]; + switch(pf->pixel_type) { + case FF_PIXEL_PACKED: case FF_PIXEL_PLANAR: for(i = 0; i < pf->nb_channels; i++) { int w, h; + int bwidth = ff_get_plane_bytewidth(pix_fmt, width, i); w = width; h = height; if (i == 1 || i == 2) { w >>= pf->x_chroma_shift; h >>= pf->y_chroma_shift; } - bwidth = (w * pf->depth + 7) >> 3; ff_img_copy_plane(dst->data[i], dst->linesize[i], src->data[i], src->linesize[i], bwidth, h); @@ -1141,87 +1269,6 @@ static void yuv420p_to_uyvy422(AVPicture *dst, const AVPicture *src, } } -#define SCALEBITS 10 -#define ONE_HALF (1 << (SCALEBITS - 1)) -#define FIX(x) ((int) ((x) * (1<> SCALEBITS];\ - g = cm[(y + g_add) >> SCALEBITS];\ - b = cm[(y + b_add) >> SCALEBITS];\ -} - -#define YUV_TO_RGB1(cb1, cr1)\ -{\ - cb = (cb1) - 128;\ - cr = (cr1) - 128;\ - r_add = FIX(1.40200) * cr + ONE_HALF;\ - g_add = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;\ - b_add = FIX(1.77200) * cb + ONE_HALF;\ -} - -#define YUV_TO_RGB2(r, g, b, y1)\ -{\ - y = (y1) << SCALEBITS;\ - r = cm[(y + r_add) >> SCALEBITS];\ - g = cm[(y + g_add) >> SCALEBITS];\ - b = cm[(y + b_add) >> SCALEBITS];\ -} - -#define Y_CCIR_TO_JPEG(y)\ - cm[((y) * FIX(255.0/219.0) + (ONE_HALF - 16 * FIX(255.0/219.0))) >> SCALEBITS] - -#define Y_JPEG_TO_CCIR(y)\ - (((y) * FIX(219.0/255.0) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS) - -#define C_CCIR_TO_JPEG(y)\ - cm[(((y) - 128) * FIX(127.0/112.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS] - -/* NOTE: the clamp is really necessary! */ -static inline int C_JPEG_TO_CCIR(int y) { - y = (((y - 128) * FIX(112.0/127.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS); - if (y < 16) - y = 16; - return y; -} - - -#define RGB_TO_Y(r, g, b) \ -((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \ - FIX(0.11400) * (b) + ONE_HALF) >> SCALEBITS) - -#define RGB_TO_U(r1, g1, b1, shift)\ -(((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \ - FIX(0.50000) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) - -#define RGB_TO_V(r1, g1, b1, shift)\ -(((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \ - FIX(0.08131) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) - -#define RGB_TO_Y_CCIR(r, g, b) \ -((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \ - FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS) - -#define RGB_TO_U_CCIR(r1, g1, b1, shift)\ -(((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \ - FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) - -#define RGB_TO_V_CCIR(r1, g1, b1, shift)\ -(((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \ - FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) - static uint8_t y_ccir_to_jpeg[256]; static uint8_t y_jpeg_to_ccir[256]; static uint8_t c_ccir_to_jpeg[256]; @@ -1501,6 +1548,20 @@ static void grow21(uint8_t *dst, int dst_wrap, } } +/* 1x1 -> 1x2 */ +static void grow12(uint8_t *dst, int dst_wrap, + const uint8_t *src, int src_wrap, + int width, int height) +{ + for(;height > 0; height-=2) { + memcpy(dst, src, width); + dst += dst_wrap; + memcpy(dst, src, width); + dst += dst_wrap; + src += src_wrap; + } +} + /* 1x1 -> 2x2 */ static void grow22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, @@ -1886,7 +1947,9 @@ static void gray16be_to_gray(AVPicture *dst, const AVPicture *src, static void gray16le_to_gray(AVPicture *dst, const AVPicture *src, int width, int height) { - gray16_to_gray(dst, src + 1, width, height); + AVPicture tmpsrc = *src; + tmpsrc.data[0]++; + gray16_to_gray(dst, &tmpsrc, width, height); } static void gray16_to_gray16(AVPicture *dst, const AVPicture *src, @@ -1894,9 +1957,9 @@ static void gray16_to_gray16(AVPicture *dst, const AVPicture *src, { int x, y, src_wrap, dst_wrap; uint16_t *s, *d; - s = src->data[0]; + s = (uint16_t*)src->data[0]; src_wrap = (src->linesize[0] - width * 2)/2; - d = dst->data[0]; + d = (uint16_t*)dst->data[0]; dst_wrap = (dst->linesize[0] - width * 2)/2; for(y=0; ydata[i], dst->linesize[i], @@ -2845,10 +2917,7 @@ int avpicture_deinterlace(AVPicture *dst, const AVPicture *src, width, height); } } -#ifdef HAVE_MMX - emms(); -#endif + emms_c(); return 0; } -#undef FIX diff --git a/contrib/ffmpeg/libavcodec/imgconvert.h b/contrib/ffmpeg/libavcodec/imgconvert.h new file mode 100644 index 000000000..2370aa6f7 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/imgconvert.h @@ -0,0 +1,33 @@ +/* + * Misc image conversion routines + * most functionality is exported to the public API, see avcodec.h + * + * Copyright (c) 2008 Vitor Sessak + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_IMGCONVERT_H +#define FFMPEG_IMGCONVERT_H + +int ff_fill_linesize(AVPicture *picture, int pix_fmt, int width); + +int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, int pix_fmt, int height); + +int ff_get_plane_bytewidth(enum PixelFormat pix_fmt, int width, int plane); + +#endif /* FFMPEG_IMGCONVERT_H */ diff --git a/contrib/ffmpeg/libavcodec/imgconvert_template.h b/contrib/ffmpeg/libavcodec/imgconvert_template.h index 70c090bad..2d23be87b 100644 --- a/contrib/ffmpeg/libavcodec/imgconvert_template.h +++ b/contrib/ffmpeg/libavcodec/imgconvert_template.h @@ -1,5 +1,5 @@ /* - * Templates for image convertion routines + * templates for image conversion routines * Copyright (c) 2001, 2002, 2003 Fabrice Bellard. * * This file is part of FFmpeg. @@ -19,6 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +/* This header intentionally has no multiple inclusion guards. It is meant to + * be included multiple times and generates different code depending on the + * value of certain #defines. */ + #ifndef RGB_OUT #define RGB_OUT(d, r, g, b) RGBA_OUT(d, r, g, b, 0xff) #endif @@ -410,7 +414,7 @@ static void glue(pal8_to_, RGB_NAME)(AVPicture *dst, const AVPicture *src, } } -// RGB24 has optimised routines +// RGB24 has optimized routines #if !defined(FMT_RGB32) && !defined(FMT_RGB24) /* alpha support */ diff --git a/contrib/ffmpeg/libavcodec/imgresample.c b/contrib/ffmpeg/libavcodec/imgresample.c index 2722d5acf..c481e9df3 100644 --- a/contrib/ffmpeg/libavcodec/imgresample.c +++ b/contrib/ffmpeg/libavcodec/imgresample.c @@ -28,8 +28,8 @@ #include "swscale.h" #include "dsputil.h" -#ifdef USE_FASTMEMCPY -#include "libvo/fastmemcpy.h" +#ifdef HAVE_ALTIVEC +#include "ppc/imgresample_altivec.h" #endif #define NB_COMPONENTS 3 @@ -48,6 +48,7 @@ #define LINE_BUF_HEIGHT (NB_TAPS * 4) struct SwsContext { + AVClass *av_class; struct ImgReSampleContext *resampling_ctx; enum PixelFormat src_pix_fmt, dst_pix_fmt; }; @@ -282,136 +283,9 @@ static void v_resample4_mmx(uint8_t *dst, int dst_width, const uint8_t *src, } emms(); } -#endif - -#ifdef HAVE_ALTIVEC -typedef union { - vector unsigned char v; - unsigned char c[16]; -} vec_uc_t; - -typedef union { - vector signed short v; - signed short s[8]; -} vec_ss_t; - -void v_resample16_altivec(uint8_t *dst, int dst_width, const uint8_t *src, - int wrap, int16_t *filter) -{ - int sum, i; - const uint8_t *s; - vector unsigned char *tv, tmp, dstv, zero; - vec_ss_t srchv[4], srclv[4], fv[4]; - vector signed short zeros, sumhv, sumlv; - s = src; - - for(i=0;i<4;i++) - { - /* - The vec_madds later on does an implicit >>15 on the result. - Since FILTER_BITS is 8, and we have 15 bits of magnitude in - a signed short, we have just enough bits to pre-shift our - filter constants <<7 to compensate for vec_madds. - */ - fv[i].s[0] = filter[i] << (15-FILTER_BITS); - fv[i].v = vec_splat(fv[i].v, 0); - } - - zero = vec_splat_u8(0); - zeros = vec_splat_s16(0); - +#endif /* HAVE_MMX */ - /* - When we're resampling, we'd ideally like both our input buffers, - and output buffers to be 16-byte aligned, so we can do both aligned - reads and writes. Sadly we can't always have this at the moment, so - we opt for aligned writes, as unaligned writes have a huge overhead. - To do this, do enough scalar resamples to get dst 16-byte aligned. - */ - i = (-(int)dst) & 0xf; - while(i>0) { - sum = s[0 * wrap] * filter[0] + - s[1 * wrap] * filter[1] + - s[2 * wrap] * filter[2] + - s[3 * wrap] * filter[3]; - sum = sum >> FILTER_BITS; - if (sum<0) sum = 0; else if (sum>255) sum=255; - dst[0] = sum; - dst++; - s++; - dst_width--; - i--; - } - - /* Do our altivec resampling on 16 pixels at once. */ - while(dst_width>=16) { - /* - Read 16 (potentially unaligned) bytes from each of - 4 lines into 4 vectors, and split them into shorts. - Interleave the multipy/accumulate for the resample - filter with the loads to hide the 3 cycle latency - the vec_madds have. - */ - tv = (vector unsigned char *) &s[0 * wrap]; - tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[i * wrap])); - srchv[0].v = (vector signed short) vec_mergeh(zero, tmp); - srclv[0].v = (vector signed short) vec_mergel(zero, tmp); - sumhv = vec_madds(srchv[0].v, fv[0].v, zeros); - sumlv = vec_madds(srclv[0].v, fv[0].v, zeros); - - tv = (vector unsigned char *) &s[1 * wrap]; - tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[1 * wrap])); - srchv[1].v = (vector signed short) vec_mergeh(zero, tmp); - srclv[1].v = (vector signed short) vec_mergel(zero, tmp); - sumhv = vec_madds(srchv[1].v, fv[1].v, sumhv); - sumlv = vec_madds(srclv[1].v, fv[1].v, sumlv); - - tv = (vector unsigned char *) &s[2 * wrap]; - tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[2 * wrap])); - srchv[2].v = (vector signed short) vec_mergeh(zero, tmp); - srclv[2].v = (vector signed short) vec_mergel(zero, tmp); - sumhv = vec_madds(srchv[2].v, fv[2].v, sumhv); - sumlv = vec_madds(srclv[2].v, fv[2].v, sumlv); - - tv = (vector unsigned char *) &s[3 * wrap]; - tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[3 * wrap])); - srchv[3].v = (vector signed short) vec_mergeh(zero, tmp); - srclv[3].v = (vector signed short) vec_mergel(zero, tmp); - sumhv = vec_madds(srchv[3].v, fv[3].v, sumhv); - sumlv = vec_madds(srclv[3].v, fv[3].v, sumlv); - - /* - Pack the results into our destination vector, - and do an aligned write of that back to memory. - */ - dstv = vec_packsu(sumhv, sumlv) ; - vec_st(dstv, 0, (vector unsigned char *) dst); - - dst+=16; - s+=16; - dst_width-=16; - } - - /* - If there are any leftover pixels, resample them - with the slow scalar method. - */ - while(dst_width>0) { - sum = s[0 * wrap] * filter[0] + - s[1 * wrap] * filter[1] + - s[2 * wrap] * filter[2] + - s[3 * wrap] * filter[3]; - sum = sum >> FILTER_BITS; - if (sum<0) sum = 0; else if (sum>255) sum=255; - dst[0] = sum; - dst++; - s++; - dst_width--; - } -} -#endif - -/* slow version to handle limit cases. Does not need optimisation */ +/* slow version to handle limit cases. Does not need optimization */ static void h_resample_slow(uint8_t *dst, int dst_width, const uint8_t *src, int src_width, int src_start, int src_incr, int16_t *filters) @@ -517,7 +391,7 @@ static void component_resample(ImgReSampleContext *s, h_resample(new_line, owidth, src_line, iwidth, - FCENTER * POS_FRAC, s->h_incr, &s->h_filters[0][0]); - /* handle ring buffer wraping */ + /* handle ring buffer wrapping */ if (ring_y >= LINE_BUF_HEIGHT) { memcpy(s->line_buf + (ring_y - LINE_BUF_HEIGHT) * owidth, new_line, owidth); @@ -646,7 +520,9 @@ struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, struct SwsContext *ctx; ctx = av_malloc(sizeof(struct SwsContext)); - if (ctx == NULL) { + if (ctx) + ctx->av_class = av_mallocz(sizeof(AVClass)); + if (!ctx || !ctx->av_class) { av_log(NULL, AV_LOG_ERROR, "Cannot allocate a resampling context!\n"); return NULL; @@ -680,6 +556,7 @@ void sws_freeContext(struct SwsContext *ctx) } else { av_free(ctx->resampling_ctx); } + av_free(ctx->av_class); av_free(ctx); } @@ -815,6 +692,7 @@ the_end: #ifdef TEST #include +#undef exit /* input */ #define XSIZE 256 @@ -942,8 +820,8 @@ int main(int argc, char **argv) exit(1); } av_log(NULL, AV_LOG_INFO, "MMX OK\n"); -#endif +#endif /* HAVE_MMX */ return 0; } -#endif +#endif /* TEST */ diff --git a/contrib/ffmpeg/libavcodec/imx_dump_header_bsf.c b/contrib/ffmpeg/libavcodec/imx_dump_header_bsf.c new file mode 100644 index 000000000..5a844407b --- /dev/null +++ b/contrib/ffmpeg/libavcodec/imx_dump_header_bsf.c @@ -0,0 +1,59 @@ +/* + * imx dump header bitstream filter + * Copyright (c) 2007 Baptiste Coudurier. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file imx_dump_header_bsf.c + * imx dump header bitstream filter + * modifies bitstream to fit in mov and be decoded by final cut pro decoder + */ + +#include "avcodec.h" +#include "bytestream.h" + + +static int imx_dump_header(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, + uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size, int keyframe) +{ + /* MXF essence element key */ + static const uint8_t imx_header[16] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x05,0x01,0x01,0x00 }; + uint8_t *poutbufp; + + if (avctx->codec_id != CODEC_ID_MPEG2VIDEO) { + av_log(avctx, AV_LOG_ERROR, "imx bitstream filter only applies to mpeg2video codec\n"); + return 0; + } + + *poutbuf = av_malloc(buf_size + 20 + FF_INPUT_BUFFER_PADDING_SIZE); + poutbufp = *poutbuf; + bytestream_put_buffer(&poutbufp, imx_header, 16); + bytestream_put_byte(&poutbufp, 0x83); /* KLV BER long form */ + bytestream_put_be24(&poutbufp, buf_size); + bytestream_put_buffer(&poutbufp, buf, buf_size); + *poutbuf_size = poutbufp - *poutbuf; + return 1; +} + +AVBitStreamFilter imx_dump_header_bsf = { + "imxdump", + 0, + imx_dump_header, +}; diff --git a/contrib/ffmpeg/libavcodec/indeo2.c b/contrib/ffmpeg/libavcodec/indeo2.c index 2b129d141..4a7e2d01f 100644 --- a/contrib/ffmpeg/libavcodec/indeo2.c +++ b/contrib/ffmpeg/libavcodec/indeo2.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -137,7 +136,7 @@ static int ir2_decode_plane_inter(Ir2Context *ctx, int width, int height, uint8_ static int ir2_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { Ir2Context * const s = avctx->priv_data; AVFrame *picture = data; @@ -197,11 +196,13 @@ static int ir2_decode_init(AVCodecContext *avctx){ avctx->pix_fmt= PIX_FMT_YUV410P; if (!ir2_vlc.table) +#ifdef ALT_BITSTREAM_READER_LE init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES, &ir2_codes[0][1], 4, 2, -#ifdef ALT_BITSTREAM_READER_LE &ir2_codes[0][0], 4, 2, INIT_VLC_USE_STATIC | INIT_VLC_LE); #else + init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES, + &ir2_codes[0][1], 4, 2, &ir2_codes[0][0], 4, 2, INIT_VLC_USE_STATIC); #endif diff --git a/contrib/ffmpeg/libavcodec/indeo2data.h b/contrib/ffmpeg/libavcodec/indeo2data.h index 71d250af7..2be32dfc9 100644 --- a/contrib/ffmpeg/libavcodec/indeo2data.h +++ b/contrib/ffmpeg/libavcodec/indeo2data.h @@ -19,6 +19,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef FFMPEG_INDEO2DATA_H +#define FFMPEG_INDEO2DATA_H + +#include + #define IR2_CODES 143 static const uint16_t ir2_codes[IR2_CODES][2] = { #ifdef ALT_BITSTREAM_READER_LE @@ -132,3 +137,5 @@ static const uint8_t ir2_luma_table[256] = { 0x28, 0x5C, 0x6C, 0xC1, 0x94, 0x3F, 0xC1, 0x6C, 0x3F, 0x94, 0xD9, 0xD9, 0x27, 0x27, 0x80, 0x80 }; + +#endif /* FFMPEG_INDEO2DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/indeo3.c b/contrib/ffmpeg/libavcodec/indeo3.c index 1b1914406..9237b5ec2 100644 --- a/contrib/ffmpeg/libavcodec/indeo3.c +++ b/contrib/ffmpeg/libavcodec/indeo3.c @@ -24,10 +24,10 @@ #include #include -#include "common.h" #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" +#include "bytestream.h" #include "indeo3data.h" @@ -55,13 +55,13 @@ typedef struct Indeo3DecodeContext { unsigned short *corrector_type; } Indeo3DecodeContext; -static int corrector_type_0[24] = { +static const int corrector_type_0[24] = { 195, 159, 133, 115, 101, 93, 87, 77, 195, 159, 133, 115, 101, 93, 87, 77, 128, 79, 79, 79, 79, 79, 79, 79 }; -static int corrector_type_2[8] = { 9, 7, 6, 8, 5, 4, 3, 2 }; +static const int corrector_type_2[8] = { 9, 7, 6, 8, 5, 4, 3, 2 }; static void build_modpred(Indeo3DecodeContext *s) { @@ -93,9 +93,9 @@ static void build_modpred(Indeo3DecodeContext *s) } static void iv_Decode_Chunk(Indeo3DecodeContext *s, unsigned char *cur, - unsigned char *ref, int width, int height, unsigned char *buf1, - long fflags2, unsigned char *hdr, - unsigned char *buf2, int min_width_160); + unsigned char *ref, int width, int height, const unsigned char *buf1, + long fflags2, const unsigned char *hdr, + const unsigned char *buf2, int min_width_160); /* ---------------------------------------------------------------------- */ static void iv_alloc_frames(Indeo3DecodeContext *s) @@ -177,38 +177,32 @@ static void iv_free_func(Indeo3DecodeContext *s) /* ---------------------------------------------------------------------- */ static unsigned long iv_decode_frame(Indeo3DecodeContext *s, - unsigned char *buf, int buf_size) + const unsigned char *buf, int buf_size) { unsigned int hdr_width, hdr_height, chroma_width, chroma_height; unsigned long fflags1, fflags2, fflags3, offs1, offs2, offs3, offs; - unsigned char *hdr_pos, *buf_pos; + const unsigned char *hdr_pos, *buf_pos; buf_pos = buf; buf_pos += 18; - fflags1 = le2me_16(*(uint16_t *)buf_pos); - buf_pos += 2; - fflags3 = le2me_32(*(uint32_t *)buf_pos); - buf_pos += 4; + fflags1 = bytestream_get_le16(&buf_pos); + fflags3 = bytestream_get_le32(&buf_pos); fflags2 = *buf_pos++; buf_pos += 3; - hdr_height = le2me_16(*(uint16_t *)buf_pos); - buf_pos += 2; - hdr_width = le2me_16(*(uint16_t *)buf_pos); + hdr_height = bytestream_get_le16(&buf_pos); + hdr_width = bytestream_get_le16(&buf_pos); if(avcodec_check_dimensions(NULL, hdr_width, hdr_height)) return -1; - buf_pos += 2; chroma_height = ((hdr_height >> 2) + 3) & 0x7ffc; chroma_width = ((hdr_width >> 2) + 3) & 0x7ffc; - offs1 = le2me_32(*(uint32_t *)buf_pos); - buf_pos += 4; - offs2 = le2me_32(*(uint32_t *)buf_pos); + offs1 = bytestream_get_le32(&buf_pos); + offs2 = bytestream_get_le32(&buf_pos); + offs3 = bytestream_get_le32(&buf_pos); buf_pos += 4; - offs3 = le2me_32(*(uint32_t *)buf_pos); - buf_pos += 8; hdr_pos = buf_pos; if(fflags3 == 0x80) return 4; @@ -221,8 +215,7 @@ static unsigned long iv_decode_frame(Indeo3DecodeContext *s, } buf_pos = buf + 16 + offs1; - offs = le2me_32(*(uint32_t *)buf_pos); - buf_pos += 4; + offs = bytestream_get_le32(&buf_pos); iv_Decode_Chunk(s, s->cur_frame->Ybuf, s->ref_frame->Ybuf, hdr_width, hdr_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos, @@ -232,16 +225,14 @@ static unsigned long iv_decode_frame(Indeo3DecodeContext *s, { buf_pos = buf + 16 + offs2; - offs = le2me_32(*(uint32_t *)buf_pos); - buf_pos += 4; + offs = bytestream_get_le32(&buf_pos); iv_Decode_Chunk(s, s->cur_frame->Vbuf, s->ref_frame->Vbuf, chroma_width, chroma_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos, FFMIN(chroma_width, 40)); buf_pos = buf + 16 + offs3; - offs = le2me_32(*(uint32_t *)buf_pos); - buf_pos += 4; + offs = bytestream_get_le32(&buf_pos); iv_Decode_Chunk(s, s->cur_frame->Ubuf, s->ref_frame->Ubuf, chroma_width, chroma_height, buf_pos + offs * 2, fflags2, hdr_pos, buf_pos, @@ -308,13 +299,13 @@ typedef struct { static void iv_Decode_Chunk(Indeo3DecodeContext *s, unsigned char *cur, unsigned char *ref, int width, int height, - unsigned char *buf1, long fflags2, unsigned char *hdr, - unsigned char *buf2, int min_width_160) + const unsigned char *buf1, long fflags2, const unsigned char *hdr, + const unsigned char *buf2, int min_width_160) { unsigned char bit_buf; unsigned long bit_pos, lv, lv1, lv2; long *width_tbl, width_tbl_arr[10]; - signed char *ref_vectors; + const signed char *ref_vectors; unsigned char *cur_frm_pos, *ref_frm_pos, *cp, *cp2; uint32_t *cur_lp, *ref_lp; const uint32_t *correction_lp[2], *correctionloworder_lp[2], *correctionhighorder_lp[2]; @@ -379,7 +370,7 @@ static void iv_Decode_Chunk(Indeo3DecodeContext *s, } else if(cmd == 3) { if(strip->usl7 == 0) { strip->usl7 = 1; - ref_vectors = (signed char*)buf2 + (*buf1 * 2); + ref_vectors = (const signed char*)buf2 + (*buf1 * 2); buf1++; continue; } @@ -1066,7 +1057,6 @@ static int indeo3_decode_init(AVCodecContext *avctx) s->width = avctx->width; s->height = avctx->height; avctx->pix_fmt = PIX_FMT_YUV410P; - avctx->has_b_frames = 0; build_modpred(s); iv_alloc_frames(s); @@ -1076,7 +1066,7 @@ static int indeo3_decode_init(AVCodecContext *avctx) static int indeo3_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - unsigned char *buf, int buf_size) + const unsigned char *buf, int buf_size) { Indeo3DecodeContext *s=avctx->priv_data; unsigned char *src, *dest; diff --git a/contrib/ffmpeg/libavcodec/indeo3data.h b/contrib/ffmpeg/libavcodec/indeo3data.h index e69a09f0e..eb9a8c19e 100644 --- a/contrib/ffmpeg/libavcodec/indeo3data.h +++ b/contrib/ffmpeg/libavcodec/indeo3data.h @@ -19,6 +19,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef FFMPEG_INDEO3DATA_H +#define FFMPEG_INDEO3DATA_H + +#include + static const uint32_t correction[] = { 0x00000000, 0x00000202, 0xfffffdfe, 0x000002ff, 0xfffffd01, 0xffffff03, 0x000000fd, 0x00000404, 0xfffffbfc, 0x00000501, 0xfffffaff, 0x00000105, 0xfffffefb, 0x000003fc, 0xfffffc04, 0x000005fe, @@ -2333,3 +2338,5 @@ static const uint32_t correctionhighorder[] = { 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }; + +#endif /* FFMPEG_INDEO3DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/interplayvideo.c b/contrib/ffmpeg/libavcodec/interplayvideo.c index 95059c365..3731fb275 100644 --- a/contrib/ffmpeg/libavcodec/interplayvideo.c +++ b/contrib/ffmpeg/libavcodec/interplayvideo.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -40,8 +39,8 @@ #include #include -#include "common.h" #include "avcodec.h" +#include "bytestream.h" #include "dsputil.h" #define PALETTE_COUNT 256 @@ -61,14 +60,14 @@ typedef struct IpvideoContext { AVFrame second_last_frame; AVFrame last_frame; AVFrame current_frame; - unsigned char *decoding_map; + const unsigned char *decoding_map; int decoding_map_size; - unsigned char *buf; + const unsigned char *buf; int size; - unsigned char *stream_ptr; - unsigned char *stream_end; + const unsigned char *stream_ptr; + const unsigned char *stream_end; unsigned char *pixel_ptr; int line_inc; int stride; @@ -298,10 +297,8 @@ static int ipvideo_decode_block_opcode_0x7(IpvideoContext *s) /* need 2 more bytes from the stream */ CHECK_STREAM_PTR(2); - B[0] = *s->stream_ptr++; - B[1] = *s->stream_ptr++; - flags = (B[1] << 8) | B[0]; + flags = bytestream_get_le16(&s->stream_ptr); bitmask = 0x0001; for (y = 0; y < 8; y += 2) { for (x = 0; x < 8; x += 2, bitmask <<= 1) { @@ -479,7 +476,6 @@ static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s) { int x, y; unsigned char P[4]; - unsigned char B[4]; unsigned int flags = 0; int shifter = 0; unsigned char pix; @@ -497,8 +493,7 @@ static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s) for (y = 0; y < 8; y++) { /* get the next set of 8 2-bit flags */ - flags = (s->stream_ptr[1] << 8) | s->stream_ptr[0]; - s->stream_ptr += 2; + flags = bytestream_get_le16(&s->stream_ptr); for (x = 0, shifter = 0; x < 8; x++, shifter += 2) { *s->pixel_ptr++ = P[(flags >> shifter) & 0x03]; } @@ -510,11 +505,7 @@ static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s) /* 1 of 4 colors for each 2x2 block, need 4 more bytes */ CHECK_STREAM_PTR(4); - B[0] = *s->stream_ptr++; - B[1] = *s->stream_ptr++; - B[2] = *s->stream_ptr++; - B[3] = *s->stream_ptr++; - flags = (B[3] << 24) | (B[2] << 16) | (B[1] << 8) | B[0]; + flags = bytestream_get_le32(&s->stream_ptr); shifter = 0; for (y = 0; y < 8; y += 2) { @@ -536,11 +527,7 @@ static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s) for (y = 0; y < 8; y++) { /* time to reload flags? */ if ((y == 0) || (y == 4)) { - B[0] = *s->stream_ptr++; - B[1] = *s->stream_ptr++; - B[2] = *s->stream_ptr++; - B[3] = *s->stream_ptr++; - flags = (B[3] << 24) | (B[2] << 16) | (B[1] << 8) | B[0]; + flags = bytestream_get_le32(&s->stream_ptr); shifter = 0; } for (x = 0; x < 8; x += 2, shifter += 2) { @@ -559,11 +546,7 @@ static int ipvideo_decode_block_opcode_0x9(IpvideoContext *s) for (y = 0; y < 8; y += 2) { /* time to reload flags? */ if ((y == 0) || (y == 4)) { - B[0] = *s->stream_ptr++; - B[1] = *s->stream_ptr++; - B[2] = *s->stream_ptr++; - B[3] = *s->stream_ptr++; - flags = (B[3] << 24) | (B[2] << 16) | (B[1] << 8) | B[0]; + flags = bytestream_get_le32(&s->stream_ptr); shifter = 0; } for (x = 0; x < 8; x++, shifter += 2) { @@ -865,7 +848,6 @@ static int ipvideo_decode_init(AVCodecContext *avctx) } avctx->pix_fmt = PIX_FMT_PAL8; - avctx->has_b_frames = 0; dsputil_init(&s->dsp, avctx); /* decoding map contains 4 bits of information per 8x8 block */ @@ -897,7 +879,7 @@ static int ipvideo_decode_init(AVCodecContext *avctx) static int ipvideo_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { IpvideoContext *s = avctx->priv_data; AVPaletteControl *palette_control = avctx->palctrl; diff --git a/contrib/ffmpeg/libavcodec/intrax8.c b/contrib/ffmpeg/libavcodec/intrax8.c new file mode 100644 index 000000000..0436deb4c --- /dev/null +++ b/contrib/ffmpeg/libavcodec/intrax8.c @@ -0,0 +1,764 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file intrax8.c + * @brief IntraX8 (J-Frame) subdecoder, used by WMV2 and VC-1 + */ + +#include "avcodec.h" +#include "bitstream.h" +#include "mpegvideo.h" +#include "msmpeg4data.h" +#include "intrax8huf.h" +#include "intrax8.h" + +#define MAX_TABLE_DEPTH(table_bits, max_bits) ((max_bits+table_bits-1)/table_bits) + +#define DC_VLC_BITS 9 +#define AC_VLC_BITS 9 +#define OR_VLC_BITS 7 + +#define DC_VLC_MTD MAX_TABLE_DEPTH(DC_VLC_BITS, MAX_DC_VLC_BITS) +#define AC_VLC_MTD MAX_TABLE_DEPTH(AC_VLC_BITS, MAX_AC_VLC_BITS) +#define OR_VLC_MTD MAX_TABLE_DEPTH(OR_VLC_BITS, MAX_OR_VLC_BITS) + +static VLC j_ac_vlc[2][2][8]; //[quant<13],[intra/inter],[select] +static VLC j_dc_vlc[2][8]; //[quant], [select] +static VLC j_orient_vlc[2][4]; //[quant], [select] + +static void x8_vlc_init(){ + int i; + +#define init_ac_vlc(dst,src) \ + init_vlc(&dst, \ + AC_VLC_BITS,77, \ + &src[1],4,2, \ + &src[0],4,2, \ + 1) +//set ac tables + for(i=0;i<8;i++){ + init_ac_vlc( j_ac_vlc[0][0][i], x8_ac0_highquant_table[i][0] ); + init_ac_vlc( j_ac_vlc[0][1][i], x8_ac1_highquant_table[i][0] ); + init_ac_vlc( j_ac_vlc[1][0][i], x8_ac0_lowquant_table [i][0] ); + init_ac_vlc( j_ac_vlc[1][1][i], x8_ac1_lowquant_table [i][0] ); + } +#undef init_ac_vlc + +//set dc tables +#define init_dc_vlc(dst,src) \ + init_vlc(&dst, \ + DC_VLC_BITS,34, \ + &src[1],4,2, \ + &src[0],4,2, \ + 1); + for(i=0;i<8;i++){ + init_dc_vlc( j_dc_vlc[0][i], x8_dc_highquant_table[i][0]); + init_dc_vlc( j_dc_vlc[1][i], x8_dc_lowquant_table [i][0]); + } +#undef init_dc_vlc + +//set orient tables +#define init_or_vlc(dst,src) \ + init_vlc(&dst, \ + OR_VLC_BITS,12, \ + &src[1],4,2, \ + &src[0],4,2, \ + 1); + for(i=0;i<2;i++){ + init_or_vlc( j_orient_vlc[0][i], x8_orient_highquant_table[i][0]); + } + for(i=0;i<4;i++){ + init_or_vlc( j_orient_vlc[1][i], x8_orient_lowquant_table [i][0]) + } +} +#undef init_or_vlc + +static void x8_reset_vlc_tables(IntraX8Context * w){ + memset(w->j_dc_vlc,0,sizeof(w->j_dc_vlc)); + memset(w->j_ac_vlc,0,sizeof(w->j_ac_vlc)); + w->j_orient_vlc=NULL; +} + +static inline void x8_select_ac_table(IntraX8Context * const w , int mode){ + MpegEncContext * const s= w->s; + int table_index; + + assert(mode<4); + + if( w->j_ac_vlc[mode] ) return; + + table_index = get_bits(&s->gb, 3); + w->j_ac_vlc[mode] = &j_ac_vlc[w->quant<13][mode>>1][table_index];//2 modes use same tables + assert(w->j_ac_vlc[mode]); +} + +static inline int x8_get_orient_vlc(IntraX8Context * w){ + MpegEncContext * const s= w->s; + int table_index; + + if(!w->j_orient_vlc ){ + table_index = get_bits(&s->gb, 1+(w->quant<13) ); + w->j_orient_vlc = &j_orient_vlc[w->quant<13][table_index]; + } + assert(w->j_orient_vlc); + assert(w->j_orient_vlc->table); + + return get_vlc2(&s->gb, w->j_orient_vlc->table, OR_VLC_BITS, OR_VLC_MTD); +} + +#define extra_bits(eb) (eb) +#define extra_run (0xFF<<8) +#define extra_level (0x00<<8) +#define run_offset(r) ((r)<<16) +#define level_offset(l) ((l)<<24) +static const uint32_t ac_decode_table[]={ + /*46*/ extra_bits(3) | extra_run | run_offset(16) | level_offset( 0), + /*47*/ extra_bits(3) | extra_run | run_offset(24) | level_offset( 0), + /*48*/ extra_bits(2) | extra_run | run_offset( 4) | level_offset( 1), + /*49*/ extra_bits(3) | extra_run | run_offset( 8) | level_offset( 1), + + /*50*/ extra_bits(5) | extra_run | run_offset(32) | level_offset( 0), + /*51*/ extra_bits(4) | extra_run | run_offset(16) | level_offset( 1), + + /*52*/ extra_bits(2) | extra_level | run_offset( 0) | level_offset( 4), + /*53*/ extra_bits(2) | extra_level | run_offset( 0) | level_offset( 8), + /*54*/ extra_bits(2) | extra_level | run_offset( 0) | level_offset(12), + /*55*/ extra_bits(3) | extra_level | run_offset( 0) | level_offset(16), + /*56*/ extra_bits(3) | extra_level | run_offset( 0) | level_offset(24), + + /*57*/ extra_bits(2) | extra_level | run_offset( 1) | level_offset( 3), + /*58*/ extra_bits(3) | extra_level | run_offset( 1) | level_offset( 7), + + /*59*/ extra_bits(2) | extra_run | run_offset(16) | level_offset( 0), + /*60*/ extra_bits(2) | extra_run | run_offset(20) | level_offset( 0), + /*61*/ extra_bits(2) | extra_run | run_offset(24) | level_offset( 0), + /*62*/ extra_bits(2) | extra_run | run_offset(28) | level_offset( 0), + /*63*/ extra_bits(4) | extra_run | run_offset(32) | level_offset( 0), + /*64*/ extra_bits(4) | extra_run | run_offset(48) | level_offset( 0), + + /*65*/ extra_bits(2) | extra_run | run_offset( 4) | level_offset( 1), + /*66*/ extra_bits(3) | extra_run | run_offset( 8) | level_offset( 1), + /*67*/ extra_bits(4) | extra_run | run_offset(16) | level_offset( 1), + + /*68*/ extra_bits(2) | extra_level | run_offset( 0) | level_offset( 4), + /*69*/ extra_bits(3) | extra_level | run_offset( 0) | level_offset( 8), + /*70*/ extra_bits(4) | extra_level | run_offset( 0) | level_offset(16), + + /*71*/ extra_bits(2) | extra_level | run_offset( 1) | level_offset( 3), + /*72*/ extra_bits(3) | extra_level | run_offset( 1) | level_offset( 7), +}; +//extra_bits = 3bits; extra_run/level = 1 bit; run_offset = 6bits; level_offset = 5 bits; +#undef extra_bits +#undef extra_run +#undef extra_level +#undef run_offset +#undef level_offset + +static void x8_get_ac_rlf(IntraX8Context * const w, const int mode, + int * const run, int * const level, int * const final){ + MpegEncContext * const s= w->s; + int i,e; + +// x8_select_ac_table(w,mode); + i = get_vlc2(&s->gb, w->j_ac_vlc[mode]->table, AC_VLC_BITS, AC_VLC_MTD); + + if(i<46){ //[0-45] + int t,l; + if(i<0){ + (*level)=(*final)=//prevent 'may be used unilitialized' + (*run)=64;//this would cause error exit in the ac loop + return; + } + + (*final) = t = (i>22); + i-=23*t; +/* + i== 0-15 r=0-15 l=0 ;r=i& %01111 + i==16-19 r=0-3 l=1 ;r=i& %00011 + i==20-21 r=0-1 l=2 ;r=i& %00001 + i==22 r=0 l=3 ;r=i& %00000 +l=lut_l[i/2]={0,0,0,0,0,0,0,0,1,1,2,3}[i>>1];// 11 10'01 01'00 00'00 00'00 00'00 00 => 0xE50000 +t=lut_mask[l]={0x0f,0x03,0x01,0x00}[l]; as i<256 the higher bits do not matter */ + l=(0xE50000>>(i&(0x1E)))&3;/*0x1E or (~1) or ((i>>1)<<1)*/ + t=(0x01030F>>(l<<3)); + + (*run) = i&t; + (*level) = l; + }else if(i<73){//[46-72] + uint32_t sm; + uint32_t mask; + + i-=46; + sm=ac_decode_table[i]; + + e=get_bits(&s->gb,sm&0xF);sm>>=8;//3bits + mask=sm&0xff;sm>>=8; //1bit + + (*run) =(sm&0xff) + (e&( mask));//6bits + (*level)=(sm>>8) + (e&(~mask));//5bits + (*final)=i>(58-46); + }else if(i<75){//[73-74] + static const uint8_t crazy_mix_runlevel[32]={ + 0x22,0x32,0x33,0x53,0x23,0x42,0x43,0x63, + 0x24,0x52,0x34,0x73,0x25,0x62,0x44,0x83, + 0x26,0x72,0x35,0x54,0x27,0x82,0x45,0x64, + 0x28,0x92,0x36,0x74,0x29,0xa2,0x46,0x84}; + + (*final)=!(i&1); + e=get_bits(&s->gb,5);//get the extra bits + (*run) =crazy_mix_runlevel[e]>>4; + (*level)=crazy_mix_runlevel[e]&0x0F; + }else{ + (*level)=get_bits( &s->gb, 7-3*(i&1)); + (*run) =get_bits( &s->gb, 6); + (*final)=get_bits1(&s->gb); + } + return; +} + +//static const uint8_t dc_extra_sbits[] ={0, 1,1, 1,1, 2,2, 3,3, 4,4, 5,5, 6,6, 7,7 }; +static const uint8_t dc_index_offset[] ={ 0, 1,2, 3,4, 5,7, 9,13, 17,25, 33,49, 65,97, 129,193}; + +static int x8_get_dc_rlf(IntraX8Context * const w,int const mode, int * const level, int * const final){ + MpegEncContext * const s= w->s; + int i,e,c; + + assert(mode<3); + if( !w->j_dc_vlc[mode] ) { + int table_index; + table_index = get_bits(&s->gb, 3); + //4 modes, same table + w->j_dc_vlc[mode]= &j_dc_vlc[w->quant<13][table_index]; + } + assert(w->j_dc_vlc); + assert(w->j_dc_vlc[mode]->table); + + i=get_vlc2(&s->gb, w->j_dc_vlc[mode]->table, DC_VLC_BITS, DC_VLC_MTD); + + /*(i>=17) {i-=17;final=1;}*/ + c= i>16; + (*final)=c; + i-=17*c; + + if(i<=0){ + (*level)=0; + return -i; + } + c=(i+1)>>1;//hackish way to calculate dc_extra_sbits[] + c-=c>1; + + e=get_bits(&s->gb,c);//get the extra bits + i=dc_index_offset[i]+(e>>1); + + e= -(e & 1);//0,0xffffff + (*level)= (i ^ e) - e;// (i^0)-0 , (i^0xff)-(-1) + return 0; +} +//end of huffman + +static int x8_setup_spatial_predictor(IntraX8Context * const w, const int chroma){ + MpegEncContext * const s= w->s; + int range; + int sum; + int quant; + + s->dsp.x8_setup_spatial_compensation(s->dest[chroma], s->edge_emu_buffer, + s->current_picture.linesize[chroma>0], + &range, &sum, w->edges); + if(chroma){ + w->orient=w->chroma_orient; + quant=w->quant_dc_chroma; + }else{ + quant=w->quant; + } + + w->flat_dc=0; + if(range < quant || range < 3){ + w->orient=0; + if(range < 3){//yep you read right, a +-1 idct error may break decoding! + w->flat_dc=1; + sum+=9; + w->predicted_dc = (sum*6899)>>17;//((1<<17)+9)/(8+8+1+2)=6899 + } + } + if(chroma) + return 0; + + assert(w->orient < 3); + if(range < 2*w->quant){ + if( (w->edges&3) == 0){ + if(w->orient==1) w->orient=11; + if(w->orient==2) w->orient=10; + }else{ + w->orient=0; + } + w->raw_orient=0; + }else{ + static const uint8_t prediction_table[3][12]={ + {0,8,4, 10,11, 2,6,9,1,3,5,7}, + {4,0,8, 11,10, 3,5,2,6,9,1,7}, + {8,0,4, 10,11, 1,7,2,6,9,3,5} + }; + w->raw_orient=x8_get_orient_vlc(w); + if(w->raw_orient<0) return -1; + assert(w->raw_orient < 12 ); + assert(w->orient<3); + w->orient=prediction_table[w->orient][w->raw_orient]; + } + return 0; +} + +static void x8_update_predictions(IntraX8Context * const w, const int orient, const int est_run ){ + MpegEncContext * const s= w->s; + + w->prediction_table[s->mb_x*2+(s->mb_y&1)] = (est_run<<2) + 1*(orient==4) + 2*(orient==8); +/* + y=2n+0 ->//0 2 4 + y=2n+1 ->//1 3 5 +*/ +} +static void x8_get_prediction_chroma(IntraX8Context * const w){ + MpegEncContext * const s= w->s; + + w->edges = 1*( !(s->mb_x>>1) ); + w->edges|= 2*( !(s->mb_y>>1) ); + w->edges|= 4*( s->mb_x >= (2*s->mb_width-1) );//mb_x for chroma would always be odd + + w->raw_orient=0; + if(w->edges&3){//lut_co[8]={inv,4,8,8, inv,4,8,8}<- =>{1,1,0,0;1,1,0,0} => 0xCC + w->chroma_orient=4<<((0xCC>>w->edges)&1); + return; + } + w->chroma_orient = (w->prediction_table[2*s->mb_x-2] & 0x03)<<2;//block[x-1][y|1-1)] +} + +static void x8_get_prediction(IntraX8Context * const w){ + MpegEncContext * const s= w->s; + int a,b,c,i; + + w->edges = 1*( !s->mb_x ); + w->edges|= 2*( !s->mb_y ); + w->edges|= 4*( s->mb_x >= (2*s->mb_width-1) ); + + switch(w->edges&3){ + case 0: + break; + case 1: + //take the one from the above block[0][y-1] + w->est_run = w->prediction_table[!(s->mb_y&1)]>>2; + w->orient = 1; + return; + case 2: + //take the one from the previous block[x-1][0] + w->est_run = w->prediction_table[2*s->mb_x-2]>>2; + w->orient = 2; + return; + case 3: + w->est_run = 16; + w->orient = 0; + return; + } + //no edge cases + b= w->prediction_table[2*s->mb_x + !(s->mb_y&1) ];//block[x ][y-1] + a= w->prediction_table[2*s->mb_x-2 + (s->mb_y&1) ];//block[x-1][y ] + c= w->prediction_table[2*s->mb_x-2 + !(s->mb_y&1) ];//block[x-1][y-1] + + w->est_run = FFMIN(b,a); + /* This condition has nothing to do with w->edges, even if it looks + similar it would trigger if e.g. x=3;y=2; + I guess somebody wrote something wrong and it became standard. */ + if( (s->mb_x & s->mb_y) != 0 ) w->est_run=FFMIN(c,w->est_run); + w->est_run>>=2; + + a&=3; + b&=3; + c&=3; + + i=( 0xFFEAF4C4>>(2*b+8*a) )&3; + if(i!=3) w->orient=i; + else w->orient=( 0xFFEAD8>>(2*c+8*(w->quant>12)) )&3; +/* +lut1[b][a]={ +->{0, 1, 0, pad}, + {0, 1, X, pad}, + {2, 2, 2, pad}} + pad 2 2 2; pad X 1 0; pad 0 1 0 <- +-> 11 10 '10 10 '11 11'01 00 '11 00'01 00=>0xEAF4C4 + +lut2[q>12][c]={ + ->{0,2,1,pad}, + {2,2,2,pad}} + pad 2 2 2; pad 1 2 0 <- +-> 11 10'10 10 '11 01'10 00=>0xEAD8 +*/ +} + + +static void x8_ac_compensation(IntraX8Context * const w, int const direction, int const dc_level){ + MpegEncContext * const s= w->s; + int t; +#define B(x,y) s->block[0][s->dsp.idct_permutation[(x)+(y)*8]] +#define T(x) ((x) * dc_level + 0x8000) >> 16; + switch(direction){ + case 0: + t = T(3811);//h + B(1,0) -= t; + B(0,1) -= t; + + t = T(487);//e + B(2,0) -= t; + B(0,2) -= t; + + t = T(506);//f + B(3,0) -= t; + B(0,3) -= t; + + t = T(135);//c + B(4,0) -= t; + B(0,4) -= t; + B(2,1) += t; + B(1,2) += t; + B(3,1) += t; + B(1,3) += t; + + t = T(173);//d + B(5,0) -= t; + B(0,5) -= t; + + t = T(61);//b + B(6,0) -= t; + B(0,6) -= t; + B(5,1) += t; + B(1,5) += t; + + t = T(42); //a + B(7,0) -= t; + B(0,7) -= t; + B(4,1) += t; + B(1,4) += t; + B(4,4) += t; + + t = T(1084);//g + B(1,1) += t; + + s->block_last_index[0] = FFMAX(s->block_last_index[0], 7*8); + break; + case 1: + B(0,1) -= T(6269); + B(0,3) -= T( 708); + B(0,5) -= T( 172); + B(0,7) -= T( 73); + + s->block_last_index[0] = FFMAX(s->block_last_index[0], 7*8); + break; + case 2: + B(1,0) -= T(6269); + B(3,0) -= T( 708); + B(5,0) -= T( 172); + B(7,0) -= T( 73); + + s->block_last_index[0] = FFMAX(s->block_last_index[0], 7); + break; + } +#undef B +#undef T +} + +static void dsp_x8_put_solidcolor(uint8_t const pix, uint8_t * dst, int const linesize){ + int k; + for(k=0;k<8;k++){ + memset(dst,pix,8); + dst+=linesize; + } +} + +static const int16_t quant_table[64] = { + 256, 256, 256, 256, 256, 256, 259, 262, + 265, 269, 272, 275, 278, 282, 285, 288, + 292, 295, 299, 303, 306, 310, 314, 317, + 321, 325, 329, 333, 337, 341, 345, 349, + 353, 358, 362, 366, 371, 375, 379, 384, + 389, 393, 398, 403, 408, 413, 417, 422, + 428, 433, 438, 443, 448, 454, 459, 465, + 470, 476, 482, 488, 493, 499, 505, 511 +}; + +static int x8_decode_intra_mb(IntraX8Context* const w, const int chroma){ + MpegEncContext * const s= w->s; + + uint8_t * scantable; + int final,run,level; + int ac_mode,dc_mode,est_run,dc_level; + int pos,n; + int zeros_only; + int use_quant_matrix; + int sign; + + assert(w->orient<12); + memset(s->block[0],0x00,64*sizeof(DCTELEM)); + + if(chroma){ + dc_mode=2; + }else{ + dc_mode=!!w->est_run;//0,1 + } + + if(x8_get_dc_rlf(w, dc_mode, &dc_level, &final)) return -1; + n=0; + zeros_only=0; + if(!final){//decode ac + use_quant_matrix=w->use_quant_matrix; + if(chroma){ + ac_mode = 1; + est_run = 64;//not used + }else{ + if (w->raw_orient < 3){ + use_quant_matrix = 0; + } + if(w->raw_orient > 4){ + ac_mode = 0; + est_run = 64; + }else{ + if(w->est_run > 1){ + ac_mode = 2; + est_run=w->est_run; + }else{ + ac_mode = 3; + est_run = 64; + } + } + } + x8_select_ac_table(w,ac_mode); + /*scantable_selector[12]={0,2,0,1,1,1,0,2,2,0,1,2};<- + -> 10'01' 00'10' 10'00' 01'01' 01'00' 10'00 =>0x928548 */ + scantable = w->scantable[ (0x928548>>(2*w->orient))&3 ].permutated; + pos=0; + do { + n++; + if( n >= est_run ){ + ac_mode=3; + x8_select_ac_table(w,3); + } + + x8_get_ac_rlf(w,ac_mode,&run,&level,&final); + + pos+=run+1; + if(pos>63){ + //this also handles vlc error in x8_get_ac_rlf + return -1; + } + level= (level+1) * w->dquant; + level+= w->qsum; + + sign = - get_bits1(&s->gb); + level = (level ^ sign) - sign; + + if(use_quant_matrix){ + level = (level*quant_table[pos])>>8; + } + s->block[0][ scantable[pos] ]=level; + }while(!final); + + s->block_last_index[0]=pos; + }else{//DC only + s->block_last_index[0]=0; + if(w->flat_dc && ((unsigned)(dc_level+1)) < 3){//[-1;1] + int32_t divide_quant= !chroma ? w->divide_quant_dc_luma: + w->divide_quant_dc_chroma; + int32_t dc_quant = !chroma ? w->quant: + w->quant_dc_chroma; + + //original intent dc_level+=predicted_dc/quant; but it got lost somewhere in the rounding + dc_level+= (w->predicted_dc*divide_quant + (1<<12) )>>13; + + dsp_x8_put_solidcolor( av_clip_uint8((dc_level*dc_quant+4)>>3), + s->dest[chroma], s->current_picture.linesize[!!chroma]); + + goto block_placed; + } + zeros_only = (dc_level == 0); + } + if(!chroma){ + s->block[0][0] = dc_level*w->quant; + }else{ + s->block[0][0] = dc_level*w->quant_dc_chroma; + } + + //there is !zero_only check in the original, but dc_level check is enough + if( (unsigned int)(dc_level+1) >= 3 && (w->edges&3) != 3 ){ + int direction; + /*ac_comp_direction[orient] = { 0, 3, 3, 1, 1, 0, 0, 0, 2, 2, 2, 1 };<- + -> 01'10' 10'10' 00'00' 00'01' 01'11' 11'00 =>0x6A017C */ + direction= (0x6A017C>>(w->orient*2))&3; + if (direction != 3){ + x8_ac_compensation(w, direction, s->block[0][0]);//modify block_last[] + } + } + + if(w->flat_dc){ + dsp_x8_put_solidcolor(w->predicted_dc, s->dest[chroma], s->current_picture.linesize[!!chroma]); + }else{ + s->dsp.x8_spatial_compensation[w->orient]( s->edge_emu_buffer, + s->dest[chroma], + s->current_picture.linesize[!!chroma] ); + } + if(!zeros_only) + s->dsp.idct_add ( s->dest[chroma], + s->current_picture.linesize[!!chroma], + s->block[0] ); + +block_placed: + + if(!chroma){ + x8_update_predictions(w,w->orient,n); + } + + if(s->loop_filter){ + uint8_t* ptr = s->dest[chroma]; + int linesize = s->current_picture.linesize[!!chroma]; + + if(!( (w->edges&2) || ( zeros_only && (w->orient|4)==4 ) )){ + s->dsp.x8_h_loop_filter(ptr, linesize, w->quant); + } + if(!( (w->edges&1) || ( zeros_only && (w->orient|8)==8 ) )){ + s->dsp.x8_v_loop_filter(ptr, linesize, w->quant); + } + } + return 0; +} + +static void x8_init_block_index(MpegEncContext *s){ //FIXME maybe merge with ff_* +//not s->linesize as this would be wrong for field pics +//not that IntraX8 has interlacing support ;) + const int linesize = s->current_picture.linesize[0]; + const int uvlinesize= s->current_picture.linesize[1]; + + s->dest[0] = s->current_picture.data[0]; + s->dest[1] = s->current_picture.data[1]; + s->dest[2] = s->current_picture.data[2]; + + s->dest[0] += s->mb_y * linesize << 3; + s->dest[1] += ( s->mb_y&(~1) ) * uvlinesize << 2;//chroma blocks are on add rows + s->dest[2] += ( s->mb_y&(~1) ) * uvlinesize << 2; +} + +/** + * Initialize IntraX8 frame decoder. + * Requires valid MpegEncContext with valid s->mb_width before calling. + * @param w pointer to IntraX8Context + * @param s pointer to MpegEncContext of the parent codec + */ +void ff_intrax8_common_init(IntraX8Context * w, MpegEncContext * const s){ + + w->s=s; + x8_vlc_init(); + assert(s->mb_width>0); + w->prediction_table=av_mallocz(s->mb_width*2*2);//two rows, 2 blocks per cannon mb + + ff_init_scantable(s->dsp.idct_permutation, &w->scantable[0], wmv1_scantable[0]); + ff_init_scantable(s->dsp.idct_permutation, &w->scantable[1], wmv1_scantable[2]); + ff_init_scantable(s->dsp.idct_permutation, &w->scantable[2], wmv1_scantable[3]); +} + +/** + * Destroy IntraX8 frame structure. + * @param w pointer to IntraX8Context + */ +void ff_intrax8_common_end(IntraX8Context * w) +{ + av_freep(&w->prediction_table); +} + +/** + * Decode single IntraX8 frame. + * The parent codec must fill s->loopfilter and s->gb (bitstream). + * The parent codec must call MPV_frame_start(), ff_er_frame_start() before calling this function. + * The parent codec must call ff_er_frame_end(), MPV_frame_end() after calling this function. + * This function does not use MPV_decode_mb(). + * lowres decoding is theoretically impossible. + * @param w pointer to IntraX8Context + * @param dquant doubled quantizer, it would be odd in case of VC-1 halfpq==1. + * @param quant_offset offset away from zero + */ +//FIXME extern uint8_t wmv3_dc_scale_table[32]; +int ff_intrax8_decode_picture(IntraX8Context * const w, int dquant, int quant_offset){ + MpegEncContext * const s= w->s; + int mb_xy; + assert(s); + w->use_quant_matrix = get_bits1(&s->gb); + + w->dquant = dquant; + w->quant = dquant >> 1; + w->qsum = quant_offset; + + w->divide_quant_dc_luma = ((1<<16) + (w->quant>>1)) / w->quant; + if(w->quant < 5){ + w->quant_dc_chroma = w->quant; + w->divide_quant_dc_chroma = w->divide_quant_dc_luma; + }else{ + w->quant_dc_chroma = w->quant+((w->quant+3)>>3); + w->divide_quant_dc_chroma = ((1<<16) + (w->quant_dc_chroma>>1)) / w->quant_dc_chroma; + } + x8_reset_vlc_tables(w); + + s->resync_mb_x=0; + s->resync_mb_y=0; + + for(s->mb_y=0; s->mb_y < s->mb_height*2; s->mb_y++){ + x8_init_block_index(s); + mb_xy=(s->mb_y>>1)*s->mb_stride; + + for(s->mb_x=0; s->mb_x < s->mb_width*2; s->mb_x++){ + x8_get_prediction(w); + if(x8_setup_spatial_predictor(w,0)) goto error; + if(x8_decode_intra_mb(w,0)) goto error; + + if( s->mb_x & s->mb_y & 1 ){ + x8_get_prediction_chroma(w); + + /*when setting up chroma, no vlc is read, + so no error condition can be reached*/ + x8_setup_spatial_predictor(w,1); + if(x8_decode_intra_mb(w,1)) goto error; + + x8_setup_spatial_predictor(w,2); + if(x8_decode_intra_mb(w,2)) goto error; + + s->dest[1]+= 8; + s->dest[2]+= 8; + + /*emulate MB info in the relevant tables*/ + s->mbskip_table [mb_xy]=0; + s->mbintra_table[mb_xy]=1; + s->current_picture.qscale_table[mb_xy]=w->quant; + mb_xy++; + } + s->dest[0]+= 8; + } + if(s->mb_y&1){ + ff_draw_horiz_band(s, (s->mb_y-1)*8, 16); + } + } + +error: + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, + (s->mb_x>>1)-1, (s->mb_y>>1)-1, + (AC_END|DC_END|MV_END) ); + return 0; +} diff --git a/contrib/ffmpeg/libavcodec/intrax8.h b/contrib/ffmpeg/libavcodec/intrax8.h new file mode 100644 index 000000000..3f6de67da --- /dev/null +++ b/contrib/ffmpeg/libavcodec/intrax8.h @@ -0,0 +1,57 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_INTRAX8_H +#define FFMPEG_INTRAX8_H + +#include "bitstream.h" +#include "mpegvideo.h" + +typedef struct{ + VLC * j_ac_vlc[4];//they point to the static j_mb_vlc + VLC * j_orient_vlc; + VLC * j_dc_vlc[3]; + + int use_quant_matrix; +//set by ff_intrax8_common_init + uint8_t * prediction_table;//2*(mb_w*2) + ScanTable scantable[3]; +//set by the caller codec + MpegEncContext * s; + int quant; + int dquant; + int qsum; +//calculated per frame + int quant_dc_chroma; + int divide_quant_dc_luma; + int divide_quant_dc_chroma; +//changed per block + int edges; + int flat_dc; + int predicted_dc; + int raw_orient; + int chroma_orient; + int orient; + int est_run; +} IntraX8Context; + +void ff_intrax8_common_init(IntraX8Context * w, MpegEncContext * const s); +void ff_intrax8_common_end(IntraX8Context * w); +int ff_intrax8_decode_picture(IntraX8Context * w, int quant, int halfpq); + +#endif /* FFMPEG_INTRAX8_H */ diff --git a/contrib/ffmpeg/libavcodec/intrax8dsp.c b/contrib/ffmpeg/libavcodec/intrax8dsp.c new file mode 100644 index 000000000..f90c0fdf0 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/intrax8dsp.c @@ -0,0 +1,432 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** +* @file intrax8dsp.c + *@brief IntraX8 frame subdecoder image manipulation routines + */ + +#include "dsputil.h" + +/* +area positions, #3 is 1 pixel only, other are 8 pixels + |66666666| + 3|44444444|55555555| +- -+--------+--------+ +1 2|XXXXXXXX| +1 2|XXXXXXXX| +1 2|XXXXXXXX| +1 2|XXXXXXXX| +1 2|XXXXXXXX| +1 2|XXXXXXXX| +1 2|XXXXXXXX| +1 2|XXXXXXXX| +^-start +*/ + +#define area1 (0) +#define area2 (8) +#define area3 (8+8) +#define area4 (8+8+1) +#define area5 (8+8+1+8) +#define area6 (8+8+1+16) + +/** + Collect statistics and prepare the edge pixels required by the other spatial compensation functions. + + * @param src pointer to the beginning of the processed block + * @param dst pointer to emu_edge, edge pixels are stored the way other compensation routines do. + * @param linesize byte offset between 2 vertical pixels in the source image + * @param range pointer to the variable where the edge pixel range is to be stored (max-min values) + * @param psum pointer to the variable where the edge pixel sum is to be stored + * @param edges Informs this routine that the block is on an image border, so it has to interpolate the missing edge pixels. + and some of the edge pixels should be interpolated, the flag has the following meaning: + 1 - mb_x==0 - first block in the row, interpolate area #1,#2,#3; + 2 - mb_y==0 - first row, interpolate area #3,#4,#5,#6; + note: 1|2 - mb_x==mb_y==0 - first block, use 0x80 value for all areas; + 4 - mb_x>= (mb_width-1) last block in the row, interpolate area #5; +*/ +static void x8_setup_spatial_compensation(uint8_t *src, uint8_t *dst, int linesize, + int * range, int * psum, int edges){ + uint8_t * ptr; + int sum; + int i; + int min_pix,max_pix; + uint8_t c; + + if((edges&3)==3){ + *psum=0x80*(8+1+8+2); + *range=0; + memset(dst,0x80,16+1+16+8); + //this triggers flat_dc for sure. + //flat_dc avoids all (other) prediction modes, but requires dc_level decoding. + return; + } + + min_pix=256; + max_pix=-1; + + sum=0; + + if(!(edges&1)){//(mb_x!=0)//there is previous block on this row + ptr=src-1;//left column, area 2 + for(i=7;i>=0;i--){ + c=*(ptr-1);//area1, same mb as area2, no need to check + dst[area1+i]=c; + c=*(ptr); + + sum+=c; + min_pix=FFMIN(min_pix,c); + max_pix=FFMAX(max_pix,c); + dst[area2+i]=c; + + ptr+=linesize; + } + } + + if(!(edges&2)){ //(mb_y!=0)//there is row above + ptr=src-linesize;//top line + for(i=0;i<8;i++){ + c=*(ptr+i); + sum+=c; + min_pix=FFMIN(min_pix, c); + max_pix=FFMAX(max_pix, c); + } + if(edges&4){//last block on the row? + memset(dst+area5,c,8);//set with last pixel fr + memcpy(dst+area4, ptr, 8); + }else{ + memcpy(dst+area4, ptr, 16);//both area4 and 5 + } + memcpy(dst+area6, ptr-linesize, 8);//area6 always present in the above block + } + //now calculate the stuff we need + if(edges&3){//mb_x==0 || mb_y==0){ + int avg=(sum+4)>>3; + if(edges&1){ //(mb_x==0) {//implies mb_y!=0 + memset(dst+area1,avg,8+8+1);//areas 1,2 and 3 are averaged + }else{//implies y==0 x!=0 + memset(dst+area3,avg, 1+16+8);//areas 3, 4,5,6 + } + sum+=avg*9; + }else{ + uint8_t c=*(src-1-linesize);//the edge pixel, in the top line and left column + dst[area3]=c; + sum+=c; + //edge pixel is not part of min/max + } + (*range) = max_pix - min_pix; + sum += *(dst+area5) + *(dst+area5+1); + *psum = sum; +} + + +static const uint16_t zero_prediction_weights[64*2] = { + 640, 640, 669, 480, 708, 354, 748, 257, 792, 198, 760, 143, 808, 101, 772, 72, + 480, 669, 537, 537, 598, 416, 661, 316, 719, 250, 707, 185, 768, 134, 745, 97, + 354, 708, 416, 598, 488, 488, 564, 388, 634, 317, 642, 241, 716, 179, 706, 132, + 257, 748, 316, 661, 388, 564, 469, 469, 543, 395, 571, 311, 655, 238, 660, 180, + 198, 792, 250, 719, 317, 634, 395, 543, 469, 469, 507, 380, 597, 299, 616, 231, + 161, 855, 206, 788, 266, 710, 340, 623, 411, 548, 455, 455, 548, 366, 576, 288, + 122, 972, 159, 914, 211, 842, 276, 758, 341, 682, 389, 584, 483, 483, 520, 390, + 110, 1172, 144, 1107, 193, 1028, 254, 932, 317, 846, 366, 731, 458, 611, 499, 499 +}; + +static void spatial_compensation_0(uint8_t *src , uint8_t *dst, int linesize){ + int i,j; + int x,y; + unsigned int p;//power divided by 2 + int a; + uint16_t left_sum[2][8]; + uint16_t top_sum[2][8]; + memset(left_sum,0,2*8*sizeof(uint16_t)); + memset( top_sum,0,2*8*sizeof(uint16_t)); + + for(i=0;i<8;i++){ + a=src[area2+7-i]<<4; + for(j=0;j<8;j++){ + p=abs(i-j); + left_sum[p&1][j]+= a>>(p>>1); + } + } + + for(i=0;i<8;i++){ + a=src[area4+i]<<4; + for(j=0;j<8;j++){ + p=abs(i-j); + top_sum[p&1][j]+= a>>(p>>1); + } + } + for(;i<10;i++){ + a=src[area4+i]<<4; + for(j=5;j<8;j++){ + p=abs(i-j); + top_sum[p&1][j]+= a>>(p>>1); + } + } + for(;i<12;i++){ + a=src[area4+i]<<4; + for(j=7;j<8;j++){ + p=abs(i-j); + top_sum[p&1][j]+= a>>(p>>1); + } + } + + for(i=0;i<8;i++){ + top_sum [0][i]+=(top_sum [1][i]*181 + 128 )>>8;//181 is sqrt(2)/2 + left_sum[0][i]+=(left_sum[1][i]*181 + 128 )>>8; + } + for(y=0;y<8;y++){ + for(x=0;x<8;x++){ + dst[x] = ( + (uint32_t)top_sum [0][x]*zero_prediction_weights[y*16+x*2+0] + + (uint32_t)left_sum[0][y]*zero_prediction_weights[y*16+x*2+1] + + 0x8000 + )>>16; + } + dst+=linesize; + } +} +static void spatial_compensation_1(uint8_t *src , uint8_t *dst, int linesize){ + int x,y; + + for(y=0;y<8;y++){ + for(x=0;x<8;x++){ + dst[x]=src[area4 + FFMIN(2*y+x+2, 15) ]; + } + dst+=linesize; + } +} +static void spatial_compensation_2(uint8_t *src , uint8_t *dst, int linesize){ + int x,y; + + for(y=0;y<8;y++){ + for(x=0;x<8;x++){ + dst[x]=src[area4 +1+y+x]; + } + dst+=linesize; + } +} +static void spatial_compensation_3(uint8_t *src , uint8_t *dst, int linesize){ + int x,y; + + for(y=0;y<8;y++){ + for(x=0;x<8;x++){ + dst[x]=src[area4 +((y+1)>>1)+x]; + } + dst+=linesize; + } +} +static void spatial_compensation_4(uint8_t *src , uint8_t *dst, int linesize){ + int x,y; + + for(y=0;y<8;y++){ + for(x=0;x<8;x++){ + dst[x]=( src[area4+x] + src[area6+x] + 1 )>>1; + } + dst+=linesize; + } +} +static void spatial_compensation_5(uint8_t *src , uint8_t *dst, int linesize){ + int x,y; + + for(y=0;y<8;y++){ + for(x=0;x<8;x++){ + if(2*x-y<0){ + dst[x]=src[area2+9+2*x-y]; + }else{ + dst[x]=src[area4 +x-((y+1)>>1)]; + } + } + dst+=linesize; + } +} +static void spatial_compensation_6(uint8_t *src , uint8_t *dst, int linesize){ + int x,y; + + for(y=0;y<8;y++){ + for(x=0;x<8;x++){ + dst[x]=src[area3+x-y]; + } + dst+=linesize; + } +} +static void spatial_compensation_7(uint8_t *src , uint8_t *dst, int linesize){ + int x,y; + + for(y=0;y<8;y++){ + for(x=0;x<8;x++){ + if(x-2*y>0){ + dst[x]=( src[area3-1+x-2*y] + src[area3+x-2*y] + 1)>>1; + }else{ + dst[x]=src[area2+8-y +(x>>1)]; + } + } + dst+=linesize; + } +} +static void spatial_compensation_8(uint8_t *src , uint8_t *dst, int linesize){ + int x,y; + + for(y=0;y<8;y++){ + for(x=0;x<8;x++){ + dst[x]=( src[area1+7-y] + src[area2+7-y] + 1 )>>1; + } + dst+=linesize; + } +} +static void spatial_compensation_9(uint8_t *src , uint8_t *dst, int linesize){ + int x,y; + + for(y=0;y<8;y++){ + for(x=0;x<8;x++){ + dst[x]=src[area2+6-FFMIN(x+y,6)]; + } + dst+=linesize; + } +} +static void spatial_compensation_10(uint8_t *src , uint8_t *dst, int linesize){ + int x,y; + + for(y=0;y<8;y++){ + for(x=0;x<8;x++){ + dst[x]=(src[area2+7-y]*(8-x)+src[area4+x]*x+4)>>3; + } + dst+=linesize; + } +} +static void spatial_compensation_11(uint8_t *src , uint8_t *dst, int linesize){ + int x,y; + + for(y=0;y<8;y++){ + for(x=0;x<8;x++){ + dst[x]=(src[area2+7-y]*y+src[area4+x]*(8-y)+4)>>3; + } + dst+=linesize; + } +} + +static void x8_loop_filter(uint8_t * ptr, const int a_stride, const int b_stride, int quant){ + int i,t; + int p0,p1,p2,p3,p4,p5,p6,p7,p8,p9; + int ql=(quant+10)>>3; + + for(i=0; i<8; i++,ptr+=b_stride){ + p0=ptr[-5*a_stride]; + p1=ptr[-4*a_stride]; + p2=ptr[-3*a_stride]; + p3=ptr[-2*a_stride]; + p4=ptr[-1*a_stride]; + p5=ptr[ 0 ]; + p6=ptr[ 1*a_stride]; + p7=ptr[ 2*a_stride]; + p8=ptr[ 3*a_stride]; + p9=ptr[ 4*a_stride]; + + t= + (FFABS(p1-p2) <= ql) + + (FFABS(p2-p3) <= ql) + + (FFABS(p3-p4) <= ql) + + (FFABS(p4-p5) <= ql); + if(t>0){//You need at least 1 to be able to reach a total score of 6. + t+= + (FFABS(p5-p6) <= ql) + + (FFABS(p6-p7) <= ql) + + (FFABS(p7-p8) <= ql) + + (FFABS(p8-p9) <= ql) + + (FFABS(p0-p1) <= ql); + if(t>=6){ + int min,max; + + min=max=p1; + min=FFMIN(min,p3); max=FFMAX(max,p3); + min=FFMIN(min,p5); max=FFMAX(max,p5); + min=FFMIN(min,p8); max=FFMAX(max,p8); + if(max-min<2*quant){//early stop + min=FFMIN(min,p2); max=FFMAX(max,p2); + min=FFMIN(min,p4); max=FFMAX(max,p4); + min=FFMIN(min,p6); max=FFMAX(max,p6); + min=FFMIN(min,p7); max=FFMAX(max,p7); + if(max-min<2*quant){ + ptr[-2*a_stride]=(4*p2 + 3*p3 + 1*p7 + 4)>>3; + ptr[-1*a_stride]=(3*p2 + 3*p4 + 2*p7 + 4)>>3; + ptr[ 0 ]=(2*p2 + 3*p5 + 3*p7 + 4)>>3; + ptr[ 1*a_stride]=(1*p2 + 3*p6 + 4*p7 + 4)>>3; + continue; + }; + } + } + } + { + int x,x0,x1,x2; + int m; + + x0 = (2*p3 - 5*p4 + 5*p5 - 2*p6 + 4)>>3; + if(FFABS(x0) < quant){ + x1=(2*p1 - 5*p2 + 5*p3 - 2*p4 + 4)>>3; + x2=(2*p5 - 5*p6 + 5*p7 - 2*p8 + 4)>>3; + + x=FFABS(x0) - FFMIN( FFABS(x1), FFABS(x2) ); + m=p4-p5; + + if( x > 0 && (m^x0) <0){ + int32_t sign; + + sign=m>>31; + m=(m^sign)-sign;//abs(m) + m>>=1; + + x=(5*x)>>3; + + if(x>m) x=m; + + x=(x^sign)-sign; + + ptr[-1*a_stride] -= x; + ptr[ 0] += x; + } + } + } + } +} + +static void x8_h_loop_filter(uint8_t *src, int stride, int qscale){ + x8_loop_filter(src, stride, 1, qscale); +} + +static void x8_v_loop_filter(uint8_t *src, int stride, int qscale){ + x8_loop_filter(src, 1, stride, qscale); +} + +void ff_intrax8dsp_init(DSPContext* dsp, AVCodecContext *avctx) { + dsp->x8_h_loop_filter=x8_h_loop_filter; + dsp->x8_v_loop_filter=x8_v_loop_filter; + dsp->x8_setup_spatial_compensation=x8_setup_spatial_compensation; + dsp->x8_spatial_compensation[0]=spatial_compensation_0; + dsp->x8_spatial_compensation[1]=spatial_compensation_1; + dsp->x8_spatial_compensation[2]=spatial_compensation_2; + dsp->x8_spatial_compensation[3]=spatial_compensation_3; + dsp->x8_spatial_compensation[4]=spatial_compensation_4; + dsp->x8_spatial_compensation[5]=spatial_compensation_5; + dsp->x8_spatial_compensation[6]=spatial_compensation_6; + dsp->x8_spatial_compensation[7]=spatial_compensation_7; + dsp->x8_spatial_compensation[8]=spatial_compensation_8; + dsp->x8_spatial_compensation[9]=spatial_compensation_9; + dsp->x8_spatial_compensation[10]=spatial_compensation_10; + dsp->x8_spatial_compensation[11]=spatial_compensation_11; +} diff --git a/contrib/ffmpeg/libavcodec/intrax8huf.h b/contrib/ffmpeg/libavcodec/intrax8huf.h new file mode 100644 index 000000000..f8c830d95 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/intrax8huf.h @@ -0,0 +1,918 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_INTRAX8HUF_H +#define FFMPEG_INTRAX8HUF_H + +#include + + +static const uint16_t x8_orient_lowquant_table[4][12][2]={ + {//0 + {0x0000, 1}, {0x0004, 3}, {0x0005, 3}, {0x000C, 4}, + {0x000D, 4}, {0x0038, 6}, {0x001D, 5}, {0x0039, 6}, + {0x003C, 6}, {0x003D, 6}, {0x003E, 6}, {0x003F, 6}, + },{//1 + {0x0000, 5}, {0x0001, 5}, {0x0002, 5}, {0x0001, 2}, + {0x0002, 2}, {0x0002, 4}, {0x0003, 5}, {0x0006, 3}, + {0x0003, 4}, {0x000E, 4}, {0x001E, 5}, {0x001F, 5}, + },{//2 + {0x0000, 2}, {0x0001, 2}, {0x0004, 3}, {0x0005, 3}, + {0x0006, 3}, {0x0038, 6}, {0x0039, 6}, {0x001D, 5}, + {0x003C, 6}, {0x003D, 6}, {0x003E, 6}, {0x003F, 6}, + },{//3 + {0x0000, 3}, {0x0002, 4}, {0x0003, 4}, {0x0001, 2}, + {0x0002, 2}, {0x0018, 5}, {0x0019, 5}, {0x000D, 4}, + {0x001C, 5}, {0x001D, 5}, {0x001E, 5}, {0x001F, 5}, + } +}; + +static const uint16_t x8_orient_highquant_table[2][12][2]={ + {//0 + {0x0000, 2}, {0x0001, 2}, {0x0004, 3}, {0x0005, 3}, + {0x0006, 3}, {0x0038, 6}, {0x001D, 5}, {0x0039, 6}, + {0x003C, 6}, {0x003D, 6}, {0x003E, 6}, {0x003F, 6}, + },{//1 + {0x0000, 1}, {0x0002, 2}, {0x0006, 3}, {0x001C, 5}, + {0x001D, 5}, {0x0078, 7}, {0x003D, 6}, {0x0079, 7}, + {0x007C, 7}, {0x007D, 7}, {0x007E, 7}, {0x007F, 7}, + } +}; +#define MAX_OR_VLC_BITS 7 + + +static const uint16_t x8_dc_lowquant_table[8][34][2]={ + {//0 + {0x0000, 5}, {0x0001, 4}, {0x0001, 5}, {0x0004, 5}, + {0x0005, 5}, {0x0006, 5}, {0x000E, 6}, {0x000F, 6}, + {0x0040, 8}, {0x0041, 8}, {0x0840, 13}, {0x0841, 13}, + {0x0842, 13}, {0x0843, 13}, {0x0844, 13}, {0x0845, 13}, + {0x0846, 13}, {0x0002, 2}, {0x0003, 2}, {0x0003, 3}, + {0x0005, 4}, {0x0009, 5}, {0x0011, 6}, {0x0043, 8}, + {0x0085, 9}, {0x0847, 13}, {0x0848, 13}, {0x0849, 13}, + {0x084A, 13}, {0x084B, 13}, {0x084C, 13}, {0x084D, 13}, + {0x084E, 13}, {0x084F, 13}, + },{//1 + {0x0000, 4}, {0x0001, 3}, {0x0002, 3}, {0x0001, 4}, + {0x0006, 4}, {0x0004, 3}, {0x0007, 4}, {0x0005, 3}, + {0x000C, 4}, {0x000D, 4}, {0x001C, 5}, {0x003A, 6}, + {0x01D8, 9}, {0x01D9, 9}, {0x1DA0, 13}, {0x1DA1, 13}, + {0x1DA2, 13}, {0x003C, 6}, {0x003D, 6}, {0x003E, 6}, + {0x0077, 7}, {0x01DB, 9}, {0x007E, 7}, {0x00FE, 8}, + {0x01FE, 9}, {0x1DA3, 13}, {0x1DA4, 13}, {0x1DA5, 13}, + {0x0ED3, 12}, {0x0ED4, 12}, {0x01FF, 9}, {0x0ED5, 12}, + {0x0ED6, 12}, {0x0ED7, 12}, + },{//2 + {0x0000, 4}, {0x0001, 3}, {0x0002, 3}, {0x0001, 4}, + {0x0006, 4}, {0x0007, 4}, {0x0008, 4}, {0x0009, 4}, + {0x0028, 6}, {0x0029, 6}, {0x0054, 7}, {0x0055, 7}, + {0x0AC0, 12}, {0x0AC1, 12}, {0x0AC2, 12}, {0x0AC3, 12}, + {0x0AC4, 12}, {0x000B, 4}, {0x0006, 3}, {0x000E, 4}, + {0x001E, 5}, {0x003E, 6}, {0x003F, 6}, {0x0057, 7}, + {0x00AD, 8}, {0x0AC5, 12}, {0x0AC6, 12}, {0x0AC7, 12}, + {0x0AC8, 12}, {0x0AC9, 12}, {0x0ACA, 12}, {0x0ACB, 12}, + {0x0566, 11}, {0x0567, 11}, + },{//3 + {0x0000, 4}, {0x0001, 2}, {0x0001, 3}, {0x0004, 3}, + {0x0005, 3}, {0x0006, 3}, {0x0001, 4}, {0x000E, 4}, + {0x003C, 6}, {0x003D, 6}, {0x007C, 7}, {0x00FA, 8}, + {0x3EC0, 14}, {0x3EC1, 14}, {0x3EC2, 14}, {0x3EC3, 14}, + {0x1F62, 13}, {0x01F7, 9}, {0x007E, 7}, {0x00FE, 8}, + {0x00FF, 8}, {0x1F63, 13}, {0x1F64, 13}, {0x1F65, 13}, + {0x1F66, 13}, {0x1F67, 13}, {0x1F68, 13}, {0x1F69, 13}, + {0x1F6A, 13}, {0x1F6B, 13}, {0x1F6C, 13}, {0x1F6D, 13}, + {0x1F6E, 13}, {0x1F6F, 13}, + },{//4 + {0x0000, 7}, {0x0001, 7}, {0x0002, 7}, {0x0003, 7}, + {0x0004, 7}, {0x0005, 7}, {0x0006, 7}, {0x0007, 7}, + {0x0008, 7}, {0x0009, 7}, {0x000A, 7}, {0x000B, 7}, + {0x000C, 7}, {0x000D, 7}, {0x000E, 7}, {0x000F, 7}, + {0x0010, 7}, {0x0001, 1}, {0x0001, 2}, {0x0011, 7}, + {0x0012, 7}, {0x0013, 7}, {0x0014, 7}, {0x0015, 7}, + {0x0016, 7}, {0x0017, 7}, {0x0018, 7}, {0x0019, 7}, + {0x001A, 7}, {0x001B, 7}, {0x001C, 7}, {0x001D, 7}, + {0x001E, 7}, {0x001F, 7}, + },{//5 + {0x0000, 5}, {0x0001, 4}, {0x0001, 5}, {0x0008, 6}, + {0x0009, 6}, {0x000A, 6}, {0x0016, 7}, {0x000C, 6}, + {0x0017, 7}, {0x000D, 6}, {0x0038, 8}, {0x001D, 7}, + {0x0039, 8}, {0x0780, 13}, {0x0781, 13}, {0x0782, 13}, + {0x0783, 13}, {0x0002, 3}, {0x0001, 1}, {0x0003, 3}, + {0x001F, 7}, {0x003D, 8}, {0x0079, 9}, {0x0784, 13}, + {0x0785, 13}, {0x0786, 13}, {0x0787, 13}, {0x0788, 13}, + {0x0789, 13}, {0x078A, 13}, {0x078B, 13}, {0x078C, 13}, + {0x078D, 13}, {0x03C7, 12}, + },{//6 + {0x0000, 4}, {0x0001, 2}, {0x0001, 3}, {0x0004, 3}, + {0x0001, 4}, {0x000A, 4}, {0x0016, 5}, {0x002E, 6}, + {0x005E, 7}, {0x005F, 7}, {0x00C0, 8}, {0x3040, 14}, + {0x3041, 14}, {0x0305, 10}, {0x0183, 9}, {0x3042, 14}, + {0x3043, 14}, {0x000D, 4}, {0x0007, 3}, {0x0019, 5}, + {0x0031, 6}, {0x00C2, 8}, {0x00C3, 8}, {0x3044, 14}, + {0x3045, 14}, {0x3046, 14}, {0x3047, 14}, {0x3048, 14}, + {0x3049, 14}, {0x304A, 14}, {0x304B, 14}, {0x304C, 14}, + {0x304D, 14}, {0x1827, 13}, + },{//7 + {0x0000, 6}, {0x0001, 6}, {0x0002, 6}, {0x0006, 7}, + {0x0007, 7}, {0x0004, 6}, {0x0005, 6}, {0x0006, 6}, + {0x000E, 7}, {0x001E, 8}, {0x001F, 8}, {0x0040, 9}, + {0x0082, 10}, {0x0830, 14}, {0x0831, 14}, {0x0832, 14}, + {0x0833, 14}, {0x0001, 1}, {0x0001, 2}, {0x0003, 4}, + {0x0005, 5}, {0x0009, 6}, {0x0011, 7}, {0x0021, 8}, + {0x0834, 14}, {0x0835, 14}, {0x0836, 14}, {0x0837, 14}, + {0x0838, 14}, {0x0839, 14}, {0x083A, 14}, {0x083B, 14}, + {0x041E, 13}, {0x041F, 13}, + } +}; + +static const uint16_t x8_dc_highquant_table[8][34][2]={ + {//0 + {0x0000, 5}, {0x0001, 4}, {0x0002, 4}, {0x0001, 5}, + {0x0006, 5}, {0x0004, 4}, {0x0007, 5}, {0x000A, 5}, + {0x002C, 7}, {0x002D, 7}, {0x05C0, 12}, {0x05C1, 12}, + {0x05C2, 12}, {0x05C3, 12}, {0x05C4, 12}, {0x05C5, 12}, + {0x05C6, 12}, {0x0003, 3}, {0x0002, 2}, {0x0006, 3}, + {0x000E, 4}, {0x001E, 5}, {0x001F, 5}, {0x002F, 7}, + {0x005D, 8}, {0x05C7, 12}, {0x05C8, 12}, {0x05C9, 12}, + {0x05CA, 12}, {0x05CB, 12}, {0x05CC, 12}, {0x05CD, 12}, + {0x05CE, 12}, {0x05CF, 12}, + },{//1 + {0x0000, 3}, {0x0001, 3}, {0x0002, 3}, {0x0006, 4}, + {0x0007, 4}, {0x0004, 3}, {0x000A, 4}, {0x000B, 4}, + {0x0030, 6}, {0x0062, 7}, {0x0063, 7}, {0x0640, 11}, + {0x0641, 11}, {0x0642, 11}, {0x0643, 11}, {0x0644, 11}, + {0x0645, 11}, {0x0033, 6}, {0x000D, 4}, {0x001C, 5}, + {0x001D, 5}, {0x003C, 6}, {0x001F, 5}, {0x0065, 7}, + {0x007A, 7}, {0x0646, 11}, {0x007B, 7}, {0x0647, 11}, + {0x0648, 11}, {0x0649, 11}, {0x064A, 11}, {0x064B, 11}, + {0x0326, 10}, {0x0327, 10}, + },{//2 + {0x0000, 7}, {0x0001, 7}, {0x0001, 6}, {0x0004, 7}, + {0x0003, 6}, {0x0005, 7}, {0x0010, 8}, {0x0011, 8}, + {0x0240, 13}, {0x0241, 13}, {0x0242, 13}, {0x0243, 13}, + {0x0244, 13}, {0x0245, 13}, {0x0246, 13}, {0x0247, 13}, + {0x0124, 12}, {0x0001, 1}, {0x0001, 2}, {0x0001, 3}, + {0x0003, 5}, {0x0005, 6}, {0x0013, 8}, {0x0125, 12}, + {0x0126, 12}, {0x0127, 12}, {0x0128, 12}, {0x0129, 12}, + {0x012A, 12}, {0x012B, 12}, {0x012C, 12}, {0x012D, 12}, + {0x012E, 12}, {0x012F, 12}, + },{//3 + {0x0000, 4}, {0x0001, 3}, {0x0002, 3}, {0x0001, 4}, + {0x0006, 4}, {0x0004, 3}, {0x0005, 3}, {0x0006, 3}, + {0x000E, 5}, {0x000F, 5}, {0x0070, 7}, {0x0710, 11}, + {0x0711, 11}, {0x0712, 11}, {0x0713, 11}, {0x0714, 11}, + {0x0715, 11}, {0x001D, 5}, {0x0072, 7}, {0x003C, 6}, + {0x003D, 6}, {0x0073, 7}, {0x007C, 7}, {0x007D, 7}, + {0x007E, 7}, {0x0716, 11}, {0x0717, 11}, {0x0718, 11}, + {0x007F, 7}, {0x0719, 11}, {0x071A, 11}, {0x071B, 11}, + {0x038E, 10}, {0x038F, 10}, + },{//4 + {0x0000, 8}, {0x0001, 7}, {0x0002, 7}, {0x0003, 7}, + {0x0002, 9}, {0x0008, 8}, {0x0003, 9}, {0x0240, 14}, + {0x0241, 14}, {0x0242, 14}, {0x0243, 14}, {0x0244, 14}, + {0x0245, 14}, {0x0246, 14}, {0x0247, 14}, {0x0124, 13}, + {0x0125, 13}, {0x0001, 2}, {0x0001, 1}, {0x0001, 3}, + {0x0001, 4}, {0x0003, 6}, {0x0005, 7}, {0x0013, 9}, + {0x0126, 13}, {0x0127, 13}, {0x0128, 13}, {0x0129, 13}, + {0x012A, 13}, {0x012B, 13}, {0x012C, 13}, {0x012D, 13}, + {0x012E, 13}, {0x012F, 13}, + },{//5 + {0x0000, 7}, {0x0001, 7}, {0x0001, 6}, {0x0002, 6}, + {0x0003, 6}, {0x0004, 6}, {0x0005, 6}, {0x0006, 6}, + {0x0007, 6}, {0x0008, 6}, {0x0009, 6}, {0x000A, 6}, + {0x000B, 6}, {0x000C, 6}, {0x000D, 6}, {0x000E, 6}, + {0x000F, 6}, {0x0010, 6}, {0x0011, 6}, {0x0012, 6}, + {0x0013, 6}, {0x0014, 6}, {0x0015, 6}, {0x0016, 6}, + {0x0017, 6}, {0x0018, 6}, {0x0019, 6}, {0x0001, 1}, + {0x001A, 6}, {0x001B, 6}, {0x001C, 6}, {0x001D, 6}, + {0x001E, 6}, {0x001F, 6}, + },{//6 + {0x0000, 5}, {0x0001, 4}, {0x0001, 5}, {0x0004, 5}, + {0x000A, 6}, {0x0006, 5}, {0x000B, 6}, {0x000E, 6}, + {0x003C, 8}, {0x003D, 8}, {0x07C0, 13}, {0x07C1, 13}, + {0x07C2, 13}, {0x07C3, 13}, {0x07C4, 13}, {0x07C5, 13}, + {0x07C6, 13}, {0x0001, 2}, {0x0002, 2}, {0x0006, 3}, + {0x000E, 4}, {0x001E, 5}, {0x001F, 5}, {0x003F, 8}, + {0x007D, 9}, {0x07C7, 13}, {0x07C8, 13}, {0x07C9, 13}, + {0x07CA, 13}, {0x07CB, 13}, {0x07CC, 13}, {0x07CD, 13}, + {0x07CE, 13}, {0x07CF, 13}, + },{//7 + {0x0000, 7}, {0x0001, 7}, {0x0002, 7}, {0x0003, 7}, + {0x0004, 7}, {0x0005, 7}, {0x0006, 7}, {0x0007, 7}, + {0x0008, 7}, {0x0009, 7}, {0x000A, 7}, {0x000B, 7}, + {0x000C, 7}, {0x000D, 7}, {0x000E, 7}, {0x000F, 7}, + {0x0010, 7}, {0x0001, 1}, {0x0001, 2}, {0x0011, 7}, + {0x0012, 7}, {0x0013, 7}, {0x0014, 7}, {0x0015, 7}, + {0x0016, 7}, {0x0017, 7}, {0x0018, 7}, {0x0019, 7}, + {0x001A, 7}, {0x001B, 7}, {0x001C, 7}, {0x001D, 7}, + {0x001E, 7}, {0x001F, 7}, + } +}; +#define MAX_DC_VLC_BITS 14 + + +static const uint16_t x8_ac0_lowquant_table[8][77][2]={ + {//0 + {0x0000, 2}, {0x0002, 3}, {0x0006, 4}, {0x000E, 5}, + {0x001E, 6}, {0x003E, 7}, {0x003F, 7}, {0x0040, 7}, + {0x0104, 9}, {0x0083, 8}, {0x0084, 8}, {0x0085, 8}, + {0x020A, 10}, {0x020B, 10}, {0x0218, 10}, {0x0219, 10}, + {0x0009, 4}, {0x0044, 7}, {0x010D, 9}, {0x021C, 10}, + {0x0023, 6}, {0x0045, 7}, {0x0050, 7}, {0x000B, 4}, + {0x000C, 4}, {0x0015, 5}, {0x001A, 5}, {0x001B, 5}, + {0x0029, 6}, {0x0038, 6}, {0x0039, 6}, {0x003A, 6}, + {0x0051, 7}, {0x0076, 7}, {0x0077, 7}, {0x0078, 7}, + {0x0079, 7}, {0x007A, 7}, {0x007B, 7}, {0x00F8, 8}, + {0x010F, 9}, {0x021D, 10}, {0x3E40, 14}, {0x3E41, 14}, + {0x3E42, 14}, {0x3E43, 14}, {0x03E5, 10}, {0x3E44, 14}, + {0x01F3, 9}, {0x3E45, 14}, {0x3E46, 14}, {0x3E47, 14}, + {0x00FA, 8}, {0x3E48, 14}, {0x3E49, 14}, {0x3E4A, 14}, + {0x3E4B, 14}, {0x03EC, 10}, {0x3E4C, 14}, {0x007E, 7}, + {0x00FE, 8}, {0x00FF, 8}, {0x01F7, 9}, {0x3E4D, 14}, + {0x3E4E, 14}, {0x3E4F, 14}, {0x3ED0, 14}, {0x3ED1, 14}, + {0x3ED2, 14}, {0x3ED3, 14}, {0x3ED4, 14}, {0x3ED5, 14}, + {0x1F6B, 13}, {0x1F6C, 13}, {0x1F6D, 13}, {0x1F6E, 13}, + {0x1F6F, 13}, + },{//1 + {0x0000, 3}, {0x0004, 5}, {0x0014, 7}, {0x000B, 6}, + {0x000C, 6}, {0x002A, 8}, {0x002B, 8}, {0x0034, 8}, + {0x0D40, 14}, {0x0D41, 14}, {0x001B, 7}, {0x0D42, 14}, + {0x0D43, 14}, {0x0D44, 14}, {0x0D45, 14}, {0x0D46, 14}, + {0x000E, 6}, {0x003C, 8}, {0x0D47, 14}, {0x003D, 8}, + {0x0D48, 14}, {0x0D49, 14}, {0x0D4A, 14}, {0x0001, 2}, + {0x0004, 3}, {0x0014, 5}, {0x000B, 4}, {0x000C, 4}, + {0x000D, 4}, {0x002A, 6}, {0x001F, 7}, {0x0056, 7}, + {0x0057, 7}, {0x0070, 7}, {0x00E2, 8}, {0x0072, 7}, + {0x003A, 6}, {0x003B, 6}, {0x003C, 6}, {0x003D, 6}, + {0x00E3, 8}, {0x0D4B, 14}, {0x00E6, 8}, {0x00E7, 8}, + {0x00F8, 8}, {0x0D4C, 14}, {0x0D4D, 14}, {0x0D4E, 14}, + {0x00F9, 8}, {0x0D4F, 14}, {0x0D50, 14}, {0x0D51, 14}, + {0x06A9, 13}, {0x06AA, 13}, {0x06AB, 13}, {0x06AC, 13}, + {0x06AD, 13}, {0x06AE, 13}, {0x06AF, 13}, {0x003F, 6}, + {0x06B0, 13}, {0x06B1, 13}, {0x06B2, 13}, {0x06B3, 13}, + {0x06B4, 13}, {0x007D, 7}, {0x06B5, 13}, {0x06B6, 13}, + {0x06B7, 13}, {0x06B8, 13}, {0x06B9, 13}, {0x06BA, 13}, + {0x06BB, 13}, {0x06BC, 13}, {0x06BD, 13}, {0x06BE, 13}, + {0x06BF, 13}, + },{//2 + {0x0000, 2}, {0x0002, 3}, {0x0003, 3}, {0x0008, 4}, + {0x0012, 5}, {0x0013, 5}, {0x0028, 6}, {0x0029, 6}, + {0x0054, 7}, {0x0055, 7}, {0x0056, 7}, {0x00AE, 8}, + {0x00AF, 8}, {0x00B0, 8}, {0x0162, 9}, {0x02C6, 10}, + {0x000C, 4}, {0x002D, 6}, {0x00B2, 8}, {0x0166, 9}, + {0x002E, 6}, {0x0167, 9}, {0x00BC, 8}, {0x001A, 5}, + {0x0036, 6}, {0x0037, 6}, {0x0038, 6}, {0x005F, 7}, + {0x0072, 7}, {0x0073, 7}, {0x0074, 7}, {0x0075, 7}, + {0x0076, 7}, {0x0077, 7}, {0x0078, 7}, {0x0079, 7}, + {0x007A, 7}, {0x007B, 7}, {0x00BD, 8}, {0xB1C0, 16}, + {0xB1C1, 16}, {0x58E1, 15}, {0x0B1D, 12}, {0x58E2, 15}, + {0x58E3, 15}, {0x58E4, 15}, {0x00F8, 8}, {0x03E4, 10}, + {0x01F3, 9}, {0x0B1E, 12}, {0x58E5, 15}, {0x58E6, 15}, + {0x00FA, 8}, {0x58E7, 15}, {0x58F8, 15}, {0x58F9, 15}, + {0x58FA, 15}, {0x01F6, 9}, {0x58FB, 15}, {0x007E, 7}, + {0x00FE, 8}, {0x00FF, 8}, {0x07CA, 11}, {0x0F96, 12}, + {0x58FC, 15}, {0x58FD, 15}, {0x58FE, 15}, {0x58FF, 15}, + {0x7CB8, 15}, {0x7CB9, 15}, {0x7CBA, 15}, {0x7CBB, 15}, + {0x7CBC, 15}, {0x01F7, 9}, {0x7CBD, 15}, {0x7CBE, 15}, + {0x7CBF, 15}, + },{//3 + {0x0000, 2}, {0x0002, 3}, {0x0006, 4}, {0x000E, 5}, + {0x000F, 5}, {0x0020, 6}, {0x0021, 6}, {0x0044, 7}, + {0x0045, 7}, {0x008C, 8}, {0x008D, 8}, {0x011C, 9}, + {0x011D, 9}, {0x011E, 9}, {0x023E, 10}, {0x023F, 10}, + {0x0005, 3}, {0x0012, 5}, {0x004C, 7}, {0x004D, 7}, + {0x000C, 4}, {0x004E, 7}, {0x001A, 5}, {0x0036, 6}, + {0x004F, 7}, {0x006E, 7}, {0x006F, 7}, {0x00E0, 8}, + {0x00E1, 8}, {0x00E2, 8}, {0x00E3, 8}, {0x00E4, 8}, + {0x00E5, 8}, {0x01CC, 9}, {0x00E7, 8}, {0x00E8, 8}, + {0x00E9, 8}, {0x01CD, 9}, {0x0750, 11}, {0x03A9, 10}, + {0x0751, 11}, {0x7540, 15}, {0x03AB, 10}, {0x7541, 15}, + {0x7542, 15}, {0x7543, 15}, {0x01D6, 9}, {0x0755, 11}, + {0x0076, 7}, {0x0EA9, 12}, {0x7544, 15}, {0x7545, 15}, + {0x001E, 5}, {0x0077, 7}, {0x00F8, 8}, {0x03AE, 10}, + {0x075E, 11}, {0x007D, 7}, {0x03E4, 10}, {0x00FC, 8}, + {0x00FD, 8}, {0x03E5, 10}, {0x03E6, 10}, {0x0EBE, 12}, + {0x7546, 15}, {0x07CE, 11}, {0x7547, 15}, {0x75F8, 15}, + {0x75F9, 15}, {0x75FA, 15}, {0x75FB, 15}, {0x75FC, 15}, + {0x75FD, 15}, {0x007F, 7}, {0x3AFF, 14}, {0x0F9E, 12}, + {0x0F9F, 12}, + },{//4 + {0x0000, 3}, {0x0002, 4}, {0x0003, 4}, {0x0008, 5}, + {0x0012, 6}, {0x0013, 6}, {0x0014, 6}, {0x002A, 7}, + {0x0016, 6}, {0x002B, 7}, {0x005C, 8}, {0x005D, 8}, + {0x005E, 8}, {0x00BE, 9}, {0x00BF, 9}, {0x0060, 8}, + {0x0007, 4}, {0x000D, 5}, {0x0019, 6}, {0x0020, 6}, + {0x0009, 4}, {0x0021, 6}, {0x0011, 5}, {0x0014, 5}, + {0x002A, 6}, {0x002B, 6}, {0x002C, 6}, {0x002D, 6}, + {0x002E, 6}, {0x002F, 6}, {0x0030, 6}, {0x0031, 7}, + {0x0062, 7}, {0x0063, 7}, {0x0064, 7}, {0x0065, 7}, + {0x0066, 7}, {0x0061, 8}, {0x0670, 11}, {0x0068, 7}, + {0x0069, 7}, {0x00CF, 8}, {0x019D, 9}, {0x01A8, 9}, + {0x01A9, 9}, {0x0339, 10}, {0x01AA, 9}, {0x0356, 10}, + {0x0036, 6}, {0x00D6, 8}, {0x6710, 15}, {0x6711, 15}, + {0x000E, 4}, {0x006E, 7}, {0x01AE, 9}, {0x6712, 15}, + {0x6713, 15}, {0x003C, 6}, {0x0357, 10}, {0x006F, 7}, + {0x00F4, 8}, {0x00F5, 8}, {0x035E, 10}, {0x01EC, 9}, + {0x6714, 15}, {0x01ED, 9}, {0x035F, 10}, {0x03DC, 10}, + {0x03DD, 10}, {0x6715, 15}, {0x338B, 14}, {0x338C, 14}, + {0x338D, 14}, {0x001F, 5}, {0x01EF, 9}, {0x338E, 14}, + {0x338F, 14}, + },{//5 + {0x0000, 2}, {0x0004, 4}, {0x000A, 5}, {0x000B, 5}, + {0x0018, 6}, {0x0019, 6}, {0x0034, 7}, {0x006A, 8}, + {0x006B, 8}, {0x006C, 8}, {0x00DA, 9}, {0x036C, 11}, + {0x006E, 8}, {0x01B7, 10}, {0x036D, 11}, {0x3780, 15}, + {0x0004, 3}, {0x000E, 5}, {0x001E, 6}, {0x003E, 7}, + {0x000A, 4}, {0x002C, 6}, {0x0017, 5}, {0x002D, 6}, + {0x003F, 7}, {0x00C0, 8}, {0x0061, 7}, {0x00C1, 8}, + {0x0062, 7}, {0x00C6, 8}, {0x0064, 7}, {0x00C7, 8}, + {0x00CA, 8}, {0x00DF, 9}, {0x0196, 9}, {0x0197, 9}, + {0x0198, 9}, {0x0199, 9}, {0x0379, 11}, {0x019A, 9}, + {0x01BD, 10}, {0x066C, 11}, {0x3781, 15}, {0x0337, 10}, + {0x066D, 11}, {0x0670, 11}, {0x0339, 10}, {0x0671, 11}, + {0x0034, 6}, {0x00CF, 8}, {0x3782, 15}, {0x3783, 15}, + {0x000E, 4}, {0x001B, 5}, {0x006A, 7}, {0x006B, 7}, + {0x019D, 9}, {0x003C, 6}, {0x00F4, 8}, {0x00F5, 8}, + {0x03D8, 10}, {0x07B2, 11}, {0x3784, 15}, {0x03DA, 10}, + {0x3785, 15}, {0x03DB, 10}, {0x03DC, 10}, {0x3786, 15}, + {0x3787, 15}, {0x1BC4, 14}, {0x1BC5, 14}, {0x1BC6, 14}, + {0x1BC7, 14}, {0x001F, 5}, {0x03DD, 10}, {0x07B3, 11}, + {0x01EF, 9}, + },{//6 + {0x0000, 2}, {0x0004, 4}, {0x000A, 5}, {0x0016, 6}, + {0x0017, 6}, {0x0060, 8}, {0x00C2, 9}, {0x0186, 10}, + {0x0187, 10}, {0x00C4, 9}, {0x3140, 15}, {0x3141, 15}, + {0x018B, 10}, {0x3142, 15}, {0x018C, 10}, {0x3143, 15}, + {0x0007, 4}, {0x000D, 5}, {0x0064, 8}, {0x0065, 8}, + {0x0010, 5}, {0x00C7, 9}, {0x0066, 8}, {0x0005, 3}, + {0x0006, 3}, {0x0009, 4}, {0x0011, 5}, {0x0038, 6}, + {0x0039, 6}, {0x0074, 7}, {0x0075, 7}, {0x0076, 7}, + {0x0067, 8}, {0x00EE, 8}, {0x01DE, 9}, {0x00F0, 8}, + {0x018D, 10}, {0x3144, 15}, {0x01DF, 9}, {0x003D, 6}, + {0x003E, 6}, {0x01E2, 9}, {0x03C6, 10}, {0x00F2, 8}, + {0x00F3, 8}, {0x03C7, 10}, {0x3145, 15}, {0x3146, 15}, + {0x01F8, 9}, {0x3147, 15}, {0x3148, 15}, {0x3149, 15}, + {0x00FD, 8}, {0x314A, 15}, {0x314B, 15}, {0x314C, 15}, + {0x314D, 15}, {0x01F9, 9}, {0x314E, 15}, {0x01FC, 9}, + {0x314F, 15}, {0x3150, 15}, {0x3151, 15}, {0x3152, 15}, + {0x3153, 15}, {0x03FA, 10}, {0x03FB, 10}, {0x3154, 15}, + {0x3155, 15}, {0x3156, 15}, {0x3157, 15}, {0x3158, 15}, + {0x3159, 15}, {0x00FF, 8}, {0x18AD, 14}, {0x18AE, 14}, + {0x18AF, 14}, + },{//7 + {0x0000, 4}, {0x0080, 11}, {0x0081, 11}, {0x0082, 11}, + {0x0083, 11}, {0x0084, 11}, {0x0085, 11}, {0x0086, 11}, + {0x0087, 11}, {0x0088, 11}, {0x0089, 11}, {0x008A, 11}, + {0x008B, 11}, {0x008C, 11}, {0x008D, 11}, {0x008E, 11}, + {0x008F, 11}, {0x0048, 10}, {0x0049, 10}, {0x004A, 10}, + {0x004B, 10}, {0x004C, 10}, {0x004D, 10}, {0x0001, 1}, + {0x0001, 2}, {0x004E, 10}, {0x0002, 4}, {0x0003, 4}, + {0x004F, 10}, {0x0050, 10}, {0x0051, 10}, {0x0052, 10}, + {0x0053, 10}, {0x0054, 10}, {0x0055, 10}, {0x0056, 10}, + {0x0057, 10}, {0x0058, 10}, {0x0059, 10}, {0x005A, 10}, + {0x005B, 10}, {0x005C, 10}, {0x005D, 10}, {0x005E, 10}, + {0x005F, 10}, {0x0060, 10}, {0x0061, 10}, {0x0062, 10}, + {0x0063, 10}, {0x0064, 10}, {0x0065, 10}, {0x0066, 10}, + {0x0067, 10}, {0x0068, 10}, {0x0069, 10}, {0x006A, 10}, + {0x006B, 10}, {0x006C, 10}, {0x006D, 10}, {0x006E, 10}, + {0x006F, 10}, {0x0070, 10}, {0x0071, 10}, {0x0072, 10}, + {0x0073, 10}, {0x0074, 10}, {0x0075, 10}, {0x0076, 10}, + {0x0077, 10}, {0x0078, 10}, {0x0079, 10}, {0x007A, 10}, + {0x007B, 10}, {0x007C, 10}, {0x007D, 10}, {0x007E, 10}, + {0x007F, 10}, + } +}; + +static const uint16_t x8_ac0_highquant_table[8][77][2]={ + {//0 + {0x0000, 3}, {0x0002, 4}, {0x000C, 6}, {0x000D, 6}, + {0x001C, 7}, {0x000F, 6}, {0x1D00, 15}, {0x003B, 8}, + {0x1D01, 15}, {0x0075, 9}, {0x1D02, 15}, {0x0080, 9}, + {0x1D03, 15}, {0x1D04, 15}, {0x1D05, 15}, {0x0E83, 14}, + {0x0009, 5}, {0x0011, 6}, {0x0081, 9}, {0x0082, 9}, + {0x0021, 7}, {0x0028, 7}, {0x0083, 9}, {0x0002, 2}, + {0x0003, 3}, {0x000C, 4}, {0x000D, 4}, {0x000B, 5}, + {0x0015, 6}, {0x0052, 8}, {0x0070, 7}, {0x0039, 6}, + {0x0071, 7}, {0x0053, 8}, {0x0E84, 14}, {0x0074, 7}, + {0x0075, 7}, {0x0076, 7}, {0x01DC, 9}, {0x001E, 5}, + {0x003E, 6}, {0x01DD, 9}, {0x00EF, 8}, {0x01F8, 9}, + {0x01F9, 9}, {0x0E85, 14}, {0x0E86, 14}, {0x0E87, 14}, + {0x00FD, 8}, {0x0E88, 14}, {0x0E89, 14}, {0x0E8A, 14}, + {0x0E8B, 14}, {0x0E8C, 14}, {0x0E8D, 14}, {0x0E8E, 14}, + {0x0E8F, 14}, {0x0E90, 14}, {0x0E91, 14}, {0x01FC, 9}, + {0x0E92, 14}, {0x0E93, 14}, {0x0E94, 14}, {0x0E95, 14}, + {0x0E96, 14}, {0x0E97, 14}, {0x01FD, 9}, {0x0E98, 14}, + {0x01FE, 9}, {0x0E99, 14}, {0x0E9A, 14}, {0x0E9B, 14}, + {0x0E9C, 14}, {0x01FF, 9}, {0x0E9D, 14}, {0x0E9E, 14}, + {0x0E9F, 14}, + },{//1 + {0x0000, 3}, {0x0002, 4}, {0x0003, 4}, {0x0008, 5}, + {0x0012, 6}, {0x0013, 6}, {0x0014, 6}, {0x0015, 6}, + {0x002C, 7}, {0x005A, 8}, {0x005B, 8}, {0x005C, 8}, + {0x005D, 8}, {0x1780, 14}, {0x0179, 10}, {0x017A, 10}, + {0x0006, 4}, {0x000E, 5}, {0x001E, 6}, {0x003E, 7}, + {0x0010, 5}, {0x0022, 6}, {0x0012, 5}, {0x000A, 4}, + {0x0013, 5}, {0x0016, 5}, {0x0023, 6}, {0x002E, 6}, + {0x002F, 6}, {0x0030, 6}, {0x0031, 6}, {0x003F, 7}, + {0x005F, 8}, {0x00C8, 8}, {0x0065, 7}, {0x0066, 7}, + {0x0067, 7}, {0x0068, 7}, {0x00C9, 8}, {0x0069, 7}, + {0x006A, 7}, {0x00D6, 8}, {0x00D7, 8}, {0x00D8, 8}, + {0x1781, 14}, {0x017B, 10}, {0x01B2, 9}, {0x1782, 14}, + {0x001C, 5}, {0x01B3, 9}, {0x1783, 14}, {0x1784, 14}, + {0x001D, 5}, {0x00DA, 8}, {0x1785, 14}, {0x1786, 14}, + {0x1787, 14}, {0x0037, 6}, {0x00DB, 8}, {0x0078, 7}, + {0x00F2, 8}, {0x01E6, 9}, {0x00F4, 8}, {0x1788, 14}, + {0x1789, 14}, {0x00F5, 8}, {0x01E7, 9}, {0x178A, 14}, + {0x178B, 14}, {0x178C, 14}, {0x178D, 14}, {0x01EC, 9}, + {0x178E, 14}, {0x001F, 5}, {0x00F7, 8}, {0x01ED, 9}, + {0x178F, 14}, + },{//2 + {0x0000, 4}, {0x0002, 5}, {0x0180, 12}, {0x0181, 12}, + {0x0182, 12}, {0x0183, 12}, {0x0184, 12}, {0x0185, 12}, + {0x0186, 12}, {0x0187, 12}, {0x0188, 12}, {0x0189, 12}, + {0x00C5, 11}, {0x00C6, 11}, {0x00C7, 11}, {0x00C8, 11}, + {0x00C9, 11}, {0x00CA, 11}, {0x00CB, 11}, {0x00CC, 11}, + {0x00CD, 11}, {0x00CE, 11}, {0x00CF, 11}, {0x0001, 1}, + {0x0001, 2}, {0x0004, 5}, {0x0005, 5}, {0x0006, 5}, + {0x00D0, 11}, {0x00D1, 11}, {0x00D2, 11}, {0x00D3, 11}, + {0x00D4, 11}, {0x00D5, 11}, {0x00D6, 11}, {0x00D7, 11}, + {0x00D8, 11}, {0x00D9, 11}, {0x00DA, 11}, {0x0007, 5}, + {0x00DB, 11}, {0x00DC, 11}, {0x00DD, 11}, {0x00DE, 11}, + {0x00DF, 11}, {0x00E0, 11}, {0x00E1, 11}, {0x00E2, 11}, + {0x00E3, 11}, {0x00E4, 11}, {0x00E5, 11}, {0x00E6, 11}, + {0x00E7, 11}, {0x00E8, 11}, {0x00E9, 11}, {0x00EA, 11}, + {0x00EB, 11}, {0x00EC, 11}, {0x00ED, 11}, {0x00EE, 11}, + {0x00EF, 11}, {0x00F0, 11}, {0x00F1, 11}, {0x00F2, 11}, + {0x00F3, 11}, {0x00F4, 11}, {0x00F5, 11}, {0x00F6, 11}, + {0x00F7, 11}, {0x00F8, 11}, {0x00F9, 11}, {0x00FA, 11}, + {0x00FB, 11}, {0x00FC, 11}, {0x00FD, 11}, {0x00FE, 11}, + {0x00FF, 11}, + },{//3 + {0x0000, 8}, {0x0001, 8}, {0x0002, 8}, {0x0003, 8}, + {0x0004, 8}, {0x0005, 8}, {0x0006, 8}, {0x0007, 8}, + {0x0008, 8}, {0x0009, 8}, {0x000A, 8}, {0x000B, 8}, + {0x000C, 8}, {0x000D, 8}, {0x000E, 8}, {0x000F, 8}, + {0x0010, 8}, {0x0011, 8}, {0x0012, 8}, {0x0013, 8}, + {0x0014, 8}, {0x0015, 8}, {0x0016, 8}, {0x0001, 1}, + {0x0017, 8}, {0x000C, 7}, {0x000D, 7}, {0x000E, 7}, + {0x000F, 7}, {0x0010, 7}, {0x0011, 7}, {0x0012, 7}, + {0x0013, 7}, {0x0014, 7}, {0x0015, 7}, {0x0016, 7}, + {0x0017, 7}, {0x0018, 7}, {0x0019, 7}, {0x001A, 7}, + {0x001B, 7}, {0x001C, 7}, {0x001D, 7}, {0x001E, 7}, + {0x001F, 7}, {0x0020, 7}, {0x0021, 7}, {0x0022, 7}, + {0x0023, 7}, {0x0024, 7}, {0x0025, 7}, {0x0026, 7}, + {0x0027, 7}, {0x0028, 7}, {0x0029, 7}, {0x002A, 7}, + {0x002B, 7}, {0x002C, 7}, {0x002D, 7}, {0x002E, 7}, + {0x002F, 7}, {0x0030, 7}, {0x0031, 7}, {0x0032, 7}, + {0x0033, 7}, {0x0034, 7}, {0x0035, 7}, {0x0036, 7}, + {0x0037, 7}, {0x0038, 7}, {0x0039, 7}, {0x003A, 7}, + {0x003B, 7}, {0x003C, 7}, {0x003D, 7}, {0x003E, 7}, + {0x003F, 7}, + },{//4 + {0x0000, 9}, {0x0001, 9}, {0x0002, 9}, {0x0003, 9}, + {0x0004, 9}, {0x0005, 9}, {0x0006, 9}, {0x0007, 9}, + {0x0008, 9}, {0x0009, 9}, {0x000A, 9}, {0x000B, 9}, + {0x000C, 9}, {0x000D, 9}, {0x000E, 9}, {0x000F, 9}, + {0x0010, 9}, {0x0011, 9}, {0x0012, 9}, {0x0013, 9}, + {0x0014, 9}, {0x0015, 9}, {0x000B, 8}, {0x0001, 2}, + {0x0001, 1}, {0x000C, 8}, {0x000D, 8}, {0x000E, 8}, + {0x000F, 8}, {0x0010, 8}, {0x0011, 8}, {0x0012, 8}, + {0x0013, 8}, {0x0014, 8}, {0x0015, 8}, {0x0016, 8}, + {0x0017, 8}, {0x0018, 8}, {0x0019, 8}, {0x001A, 8}, + {0x001B, 8}, {0x001C, 8}, {0x001D, 8}, {0x001E, 8}, + {0x001F, 8}, {0x0020, 8}, {0x0021, 8}, {0x0022, 8}, + {0x0023, 8}, {0x0024, 8}, {0x0025, 8}, {0x0026, 8}, + {0x0027, 8}, {0x0028, 8}, {0x0029, 8}, {0x002A, 8}, + {0x002B, 8}, {0x002C, 8}, {0x002D, 8}, {0x002E, 8}, + {0x002F, 8}, {0x0030, 8}, {0x0031, 8}, {0x0032, 8}, + {0x0033, 8}, {0x0034, 8}, {0x0035, 8}, {0x0036, 8}, + {0x0037, 8}, {0x0038, 8}, {0x0039, 8}, {0x003A, 8}, + {0x003B, 8}, {0x003C, 8}, {0x003D, 8}, {0x003E, 8}, + {0x003F, 8}, + },{//5 + {0x0000, 10}, {0x0001, 10}, {0x0002, 10}, {0x0003, 10}, + {0x0004, 10}, {0x0005, 10}, {0x0006, 10}, {0x0007, 10}, + {0x0008, 10}, {0x0009, 10}, {0x000A, 10}, {0x000B, 10}, + {0x000C, 10}, {0x000D, 10}, {0x000E, 10}, {0x000F, 10}, + {0x0010, 10}, {0x0011, 10}, {0x0012, 10}, {0x0013, 10}, + {0x000A, 9}, {0x000B, 9}, {0x000C, 9}, {0x0001, 1}, + {0x0001, 3}, {0x000D, 9}, {0x000E, 9}, {0x0001, 2}, + {0x000F, 9}, {0x0010, 9}, {0x0011, 9}, {0x0012, 9}, + {0x0013, 9}, {0x0014, 9}, {0x0015, 9}, {0x0016, 9}, + {0x0017, 9}, {0x0018, 9}, {0x0019, 9}, {0x001A, 9}, + {0x001B, 9}, {0x001C, 9}, {0x001D, 9}, {0x001E, 9}, + {0x001F, 9}, {0x0020, 9}, {0x0021, 9}, {0x0022, 9}, + {0x0023, 9}, {0x0024, 9}, {0x0025, 9}, {0x0026, 9}, + {0x0027, 9}, {0x0028, 9}, {0x0029, 9}, {0x002A, 9}, + {0x002B, 9}, {0x002C, 9}, {0x002D, 9}, {0x002E, 9}, + {0x002F, 9}, {0x0030, 9}, {0x0031, 9}, {0x0032, 9}, + {0x0033, 9}, {0x0034, 9}, {0x0035, 9}, {0x0036, 9}, + {0x0037, 9}, {0x0038, 9}, {0x0039, 9}, {0x003A, 9}, + {0x003B, 9}, {0x003C, 9}, {0x003D, 9}, {0x003E, 9}, + {0x003F, 9}, + },{//6 + {0x0000, 2}, {0x0004, 4}, {0x000A, 5}, {0x000B, 5}, + {0x0018, 6}, {0x0019, 6}, {0x0034, 7}, {0x006A, 8}, + {0x006B, 8}, {0x006C, 8}, {0x00DA, 9}, {0x00DB, 9}, + {0x01B8, 10}, {0x00DD, 9}, {0x01B9, 10}, {0x3780, 15}, + {0x0004, 3}, {0x000E, 5}, {0x001E, 6}, {0x001F, 6}, + {0x000A, 4}, {0x0058, 7}, {0x0017, 5}, {0x0018, 5}, + {0x0059, 7}, {0x005A, 7}, {0x005B, 7}, {0x00C8, 8}, + {0x0065, 7}, {0x0066, 7}, {0x00C9, 8}, {0x00CE, 8}, + {0x00CF, 8}, {0x00D0, 8}, {0x00D1, 8}, {0x00D2, 8}, + {0x00D3, 8}, {0x00DF, 9}, {0x00D4, 8}, {0x00D5, 8}, + {0x00D6, 8}, {0x01AE, 9}, {0x3781, 15}, {0x01BD, 10}, + {0x035E, 10}, {0x035F, 10}, {0x3782, 15}, {0x0360, 10}, + {0x0037, 6}, {0x01B1, 9}, {0x3783, 15}, {0x3784, 15}, + {0x000E, 4}, {0x003C, 6}, {0x0361, 10}, {0x3785, 15}, + {0x1BC3, 14}, {0x003D, 6}, {0x00D9, 8}, {0x1BC4, 14}, + {0x0368, 10}, {0x1BC5, 14}, {0x1BC6, 14}, {0x1BC7, 14}, + {0x1BC8, 14}, {0x00DB, 8}, {0x0369, 10}, {0x036A, 10}, + {0x1BC9, 14}, {0x1BCA, 14}, {0x1BCB, 14}, {0x1BCC, 14}, + {0x1BCD, 14}, {0x001F, 5}, {0x036B, 10}, {0x1BCE, 14}, + {0x1BCF, 14}, + },{//7 + {0x0000, 3}, {0x0002, 4}, {0x0006, 5}, {0x0007, 5}, + {0x0010, 6}, {0x0044, 8}, {0x0023, 7}, {0x0012, 6}, + {0x0026, 7}, {0x08A0, 13}, {0x004E, 8}, {0x004F, 8}, + {0x08A1, 13}, {0x08A2, 13}, {0x08A3, 13}, {0x0050, 8}, + {0x0006, 4}, {0x000B, 5}, {0x0029, 7}, {0x0015, 6}, + {0x001C, 6}, {0x003A, 7}, {0x001E, 6}, {0x0004, 3}, + {0x0014, 5}, {0x0015, 5}, {0x000B, 4}, {0x001F, 6}, + {0x0030, 6}, {0x0031, 6}, {0x0019, 5}, {0x0051, 8}, + {0x0034, 6}, {0x0035, 6}, {0x0036, 6}, {0x0037, 6}, + {0x0076, 8}, {0x0077, 8}, {0x0070, 7}, {0x001D, 5}, + {0x0071, 7}, {0x0072, 7}, {0x08A4, 13}, {0x0073, 7}, + {0x00F0, 8}, {0x08A5, 13}, {0x08A6, 13}, {0x08A7, 13}, + {0x0079, 7}, {0x007A, 7}, {0x08A8, 13}, {0x08A9, 13}, + {0x00F1, 8}, {0x08AA, 13}, {0x08AB, 13}, {0x08AC, 13}, + {0x08AD, 13}, {0x00F6, 8}, {0x08AE, 13}, {0x007C, 7}, + {0x00F7, 8}, {0x08AF, 13}, {0x08B0, 13}, {0x08B1, 13}, + {0x08B2, 13}, {0x00FA, 8}, {0x08B3, 13}, {0x08B4, 13}, + {0x08B5, 13}, {0x08B6, 13}, {0x08B7, 13}, {0x00FB, 8}, + {0x045C, 12}, {0x003F, 6}, {0x045D, 12}, {0x045E, 12}, + {0x045F, 12}, + } +}; + +static const uint16_t x8_ac1_lowquant_table[8][77][2]={ + {//0 + {0x0000, 3}, {0x0002, 4}, {0x0003, 4}, {0x0008, 5}, + {0x0012, 6}, {0x0026, 7}, {0x0014, 6}, {0x004E, 8}, + {0x004F, 8}, {0x00A8, 9}, {0x0152, 10}, {0x00AA, 9}, + {0x00AB, 9}, {0x00AC, 9}, {0x2A60, 15}, {0x02A7, 11}, + {0x0006, 4}, {0x000B, 5}, {0x001C, 6}, {0x003A, 7}, + {0x000F, 5}, {0x003B, 7}, {0x0010, 5}, {0x0005, 3}, + {0x0009, 4}, {0x0011, 5}, {0x0018, 5}, {0x0019, 5}, + {0x001A, 5}, {0x0036, 6}, {0x0037, 6}, {0x0070, 7}, + {0x0057, 8}, {0x00E2, 8}, {0x00E3, 8}, {0x00E4, 8}, + {0x00E5, 8}, {0x00AD, 9}, {0x0398, 10}, {0x003A, 6}, + {0x0076, 7}, {0x00E7, 8}, {0x00EE, 8}, {0x00EF, 8}, + {0x0732, 11}, {0x039A, 10}, {0x0733, 11}, {0x2A61, 15}, + {0x0078, 7}, {0x1531, 14}, {0x1532, 14}, {0x1533, 14}, + {0x003D, 6}, {0x039B, 10}, {0x1534, 14}, {0x1535, 14}, + {0x1536, 14}, {0x0079, 7}, {0x1537, 14}, {0x00F8, 8}, + {0x01F2, 9}, {0x07CC, 11}, {0x03E7, 10}, {0x07CD, 11}, + {0x3E80, 14}, {0x00FB, 8}, {0x03E9, 10}, {0x3E81, 14}, + {0x3E82, 14}, {0x3E83, 14}, {0x3E84, 14}, {0x3E85, 14}, + {0x3E86, 14}, {0x003F, 6}, {0x01F5, 9}, {0x07D1, 11}, + {0x3E87, 14}, + },{//1 + {0x0000, 2}, {0x0002, 3}, {0x0006, 4}, {0x000E, 5}, + {0x001E, 6}, {0x001F, 6}, {0x0040, 7}, {0x0082, 8}, + {0x0083, 8}, {0x0084, 8}, {0x010A, 9}, {0x010B, 9}, + {0x0430, 11}, {0x0431, 11}, {0x0432, 11}, {0x0433, 11}, + {0x0005, 3}, {0x0011, 5}, {0x0024, 6}, {0x004A, 7}, + {0x000C, 4}, {0x0026, 6}, {0x000D, 4}, {0x0087, 8}, + {0x010D, 9}, {0x0258, 10}, {0x012D, 9}, {0x0259, 10}, + {0x025C, 10}, {0x0974, 12}, {0x025E, 10}, {0x025F, 10}, + {0x0270, 10}, {0x0271, 10}, {0x04BB, 11}, {0x0975, 12}, + {0x0272, 10}, {0x09CC, 12}, {0x09CD, 12}, {0x4E70, 15}, + {0x4E71, 15}, {0x4E72, 15}, {0x4E73, 15}, {0x273A, 14}, + {0x273B, 14}, {0x273C, 14}, {0x04E8, 11}, {0x04E9, 11}, + {0x009E, 8}, {0x0275, 10}, {0x09D8, 12}, {0x273D, 14}, + {0x000E, 4}, {0x003C, 6}, {0x007A, 7}, {0x009F, 8}, + {0x0277, 10}, {0x003E, 6}, {0x00F6, 8}, {0x04ED, 11}, + {0x03DC, 10}, {0x273E, 14}, {0x07BA, 11}, {0x09D9, 12}, + {0x273F, 14}, {0x3DD8, 14}, {0x3DD9, 14}, {0x3DDA, 14}, + {0x3DDB, 14}, {0x3DDC, 14}, {0x3DDD, 14}, {0x3DDE, 14}, + {0x3DDF, 14}, {0x003F, 6}, {0x07BC, 11}, {0x07BD, 11}, + {0x03DF, 10}, + },{//2 + {0x0000, 3}, {0x0002, 4}, {0x0006, 5}, {0x000E, 6}, + {0x001E, 7}, {0x003E, 8}, {0x003F, 8}, {0x0040, 8}, + {0x0104, 10}, {0x0083, 9}, {0x0105, 10}, {0x0108, 10}, + {0x4240, 16}, {0x010A, 10}, {0x010B, 10}, {0x4241, 16}, + {0x0003, 3}, {0x0009, 5}, {0x0011, 6}, {0x0043, 8}, + {0x0004, 3}, {0x000A, 5}, {0x000A, 4}, {0x002C, 7}, + {0x00B4, 9}, {0x00B5, 9}, {0x00B6, 9}, {0x00B7, 9}, + {0x00B8, 9}, {0x0172, 10}, {0x0173, 10}, {0x0174, 10}, + {0x0175, 10}, {0x0176, 10}, {0x0177, 10}, {0x00BC, 9}, + {0x017A, 10}, {0x0213, 11}, {0x4242, 16}, {0x017B, 10}, + {0x02F8, 11}, {0x017D, 10}, {0x02F9, 11}, {0x017E, 10}, + {0x4243, 16}, {0x02FE, 11}, {0x2122, 15}, {0x2123, 15}, + {0x0058, 7}, {0x0164, 9}, {0x2124, 15}, {0x2125, 15}, + {0x0006, 3}, {0x000E, 4}, {0x002D, 6}, {0x002E, 6}, + {0x00B3, 8}, {0x001E, 5}, {0x005E, 7}, {0x2126, 15}, + {0x2127, 15}, {0x2128, 15}, {0x2129, 15}, {0x02FF, 11}, + {0x212A, 15}, {0x0594, 11}, {0x0595, 11}, {0x0596, 11}, + {0x212B, 15}, {0x212C, 15}, {0x212D, 15}, {0x212E, 15}, + {0x212F, 15}, {0x001F, 5}, {0x0597, 11}, {0x00BE, 8}, + {0x00BF, 8}, + },{//3 + {0x0000, 2}, {0x0002, 3}, {0x0006, 4}, {0x0007, 4}, + {0x0010, 5}, {0x0011, 5}, {0x0024, 6}, {0x0025, 6}, + {0x0026, 6}, {0x0027, 6}, {0x0050, 7}, {0x0051, 7}, + {0x00A4, 8}, {0x00A5, 8}, {0x00A6, 8}, {0x014E, 9}, + {0x000B, 4}, {0x002A, 6}, {0x0056, 7}, {0x014F, 9}, + {0x0030, 6}, {0x00AE, 8}, {0x0062, 7}, {0x0032, 6}, + {0x0033, 6}, {0x0034, 6}, {0x0035, 6}, {0x0036, 6}, + {0x0063, 7}, {0x006E, 7}, {0x006F, 7}, {0x0070, 7}, + {0x0071, 7}, {0x0072, 7}, {0x0073, 7}, {0x0074, 7}, + {0x00AF, 8}, {0x00EA, 8}, {0x01D6, 9}, {0x075C, 11}, + {0x03AF, 10}, {0x75D0, 15}, {0x75D1, 15}, {0x75D2, 15}, + {0x75D3, 15}, {0x75D4, 15}, {0x0076, 7}, {0x00EE, 8}, + {0x00EF, 8}, {0x0EBB, 12}, {0x01E0, 9}, {0x75D5, 15}, + {0x0079, 7}, {0x01E1, 9}, {0x75D6, 15}, {0x75D7, 15}, + {0x7880, 15}, {0x00F4, 8}, {0x0789, 11}, {0x003E, 6}, + {0x007B, 7}, {0x00F5, 8}, {0x00FC, 8}, {0x007F, 7}, + {0x01E3, 9}, {0x078A, 11}, {0x078B, 11}, {0x7881, 15}, + {0x7882, 15}, {0x7883, 15}, {0x3C42, 14}, {0x3C43, 14}, + {0x3C44, 14}, {0x00FD, 8}, {0x3C45, 14}, {0x3C46, 14}, + {0x3C47, 14}, + },{//4 + {0x0000, 2}, {0x0004, 4}, {0x000A, 5}, {0x0016, 6}, + {0x0017, 6}, {0x0030, 7}, {0x0031, 7}, {0x0064, 8}, + {0x0065, 8}, {0x0066, 8}, {0x00CE, 9}, {0x00CF, 9}, + {0x01A0, 10}, {0x01A1, 10}, {0x1A20, 14}, {0x0689, 12}, + {0x0004, 3}, {0x000E, 5}, {0x001B, 6}, {0x0035, 7}, + {0x000A, 4}, {0x001E, 6}, {0x0016, 5}, {0x0017, 5}, + {0x001F, 6}, {0x0030, 6}, {0x0031, 6}, {0x0064, 7}, + {0x0065, 7}, {0x0069, 8}, {0x0066, 7}, {0x00CE, 8}, + {0x00CF, 8}, {0x00D0, 8}, {0x00D1, 8}, {0x00D2, 8}, + {0x01A6, 9}, {0x01A3, 10}, {0x034E, 10}, {0x006A, 7}, + {0x00D6, 8}, {0x01AE, 9}, {0x01AF, 9}, {0x034F, 10}, + {0x0345, 11}, {0x01B0, 9}, {0x01B1, 9}, {0x0364, 10}, + {0x006D, 7}, {0x00DC, 8}, {0x0D94, 12}, {0x0D95, 12}, + {0x000E, 4}, {0x003C, 6}, {0x00DD, 8}, {0x00DE, 8}, + {0x01B3, 9}, {0x003D, 6}, {0x00DF, 8}, {0x01F0, 9}, + {0x03E2, 10}, {0x03E3, 10}, {0x06CB, 11}, {0x03E4, 10}, + {0x07CA, 11}, {0x01F3, 9}, {0x01F4, 9}, {0x07CB, 11}, + {0x07D4, 11}, {0x1A21, 14}, {0x1A22, 14}, {0x07D5, 11}, + {0x1A23, 14}, {0x003F, 6}, {0x01F6, 9}, {0x01F7, 9}, + {0x03EB, 10}, + },{//5 + {0x0000, 2}, {0x0002, 3}, {0x0006, 4}, {0x000E, 5}, + {0x000F, 5}, {0x0020, 6}, {0x0021, 6}, {0x0044, 7}, + {0x0045, 7}, {0x0046, 7}, {0x008E, 8}, {0x008F, 8}, + {0x0090, 8}, {0x0122, 9}, {0x0246, 10}, {0x0124, 9}, + {0x0005, 3}, {0x0013, 5}, {0x004A, 7}, {0x0093, 8}, + {0x0018, 5}, {0x004B, 7}, {0x0032, 6}, {0x001A, 5}, + {0x0033, 6}, {0x006C, 7}, {0x006D, 7}, {0x006E, 7}, + {0x00DE, 8}, {0x00DF, 8}, {0x0070, 7}, {0x00E2, 8}, + {0x00E3, 8}, {0x00E4, 8}, {0x00E5, 8}, {0x00E6, 8}, + {0x00E7, 8}, {0x0125, 9}, {0x01D0, 9}, {0x048E, 11}, + {0x091E, 12}, {0x091F, 12}, {0x7440, 15}, {0x1D11, 13}, + {0x7441, 15}, {0x7442, 15}, {0x00E9, 8}, {0x01D4, 9}, + {0x00EB, 8}, {0x03A3, 10}, {0x01D5, 9}, {0x1D12, 13}, + {0x001E, 5}, {0x0076, 7}, {0x01DC, 9}, {0x01DD, 9}, + {0x7443, 15}, {0x007C, 7}, {0x0745, 11}, {0x00EF, 8}, + {0x00FA, 8}, {0x00FB, 8}, {0x01F8, 9}, {0x00FD, 8}, + {0x07E4, 11}, {0x0FCA, 12}, {0x1D13, 13}, {0x7E58, 15}, + {0x7E59, 15}, {0x7E5A, 15}, {0x7E5B, 15}, {0x7E5C, 15}, + {0x7E5D, 15}, {0x007F, 7}, {0x3F2F, 14}, {0x07E6, 11}, + {0x07E7, 11}, + },{//6 + {0x0000, 3}, {0x0002, 4}, {0x0003, 4}, {0x0008, 5}, + {0x0009, 5}, {0x0014, 6}, {0x0015, 6}, {0x002C, 7}, + {0x005A, 8}, {0x005B, 8}, {0x005C, 8}, {0x00BA, 9}, + {0x00BB, 9}, {0x00BC, 9}, {0x02F4, 11}, {0x05EA, 12}, + {0x0003, 3}, {0x0010, 5}, {0x0022, 6}, {0x0046, 7}, + {0x0009, 4}, {0x0028, 6}, {0x0015, 5}, {0x000B, 4}, + {0x0018, 5}, {0x0029, 6}, {0x0032, 6}, {0x0047, 7}, + {0x0066, 7}, {0x0067, 7}, {0x0068, 7}, {0x0069, 7}, + {0x006A, 7}, {0x005F, 8}, {0x00D6, 8}, {0x00D7, 8}, + {0x01B0, 9}, {0x00D9, 8}, {0x017B, 10}, {0x006D, 7}, + {0x00DC, 8}, {0x01B1, 9}, {0x06E8, 11}, {0x01BB, 9}, + {0x0375, 10}, {0x05EB, 12}, {0x01BC, 9}, {0x6E90, 15}, + {0x0038, 6}, {0x0072, 7}, {0x6E91, 15}, {0x6E92, 15}, + {0x001D, 5}, {0x0073, 7}, {0x01BD, 9}, {0x06F8, 11}, + {0x6E93, 15}, {0x003C, 6}, {0x01BF, 9}, {0x00F4, 8}, + {0x01EA, 9}, {0x037D, 10}, {0x03D6, 10}, {0x06F9, 11}, + {0x6E94, 15}, {0x00F6, 8}, {0x01EE, 9}, {0x6E95, 15}, + {0x6E96, 15}, {0x6E97, 15}, {0x374C, 14}, {0x374D, 14}, + {0x374E, 14}, {0x001F, 5}, {0x03D7, 10}, {0x01EF, 9}, + {0x374F, 14}, + },{//7 + {0x0000, 2}, {0x0004, 4}, {0x000A, 5}, {0x0016, 6}, + {0x002E, 7}, {0x002F, 7}, {0x0060, 8}, {0x0061, 8}, + {0x00C4, 9}, {0x00C5, 9}, {0x00C6, 9}, {0x018E, 10}, + {0x31E0, 15}, {0x31E1, 15}, {0x31E2, 15}, {0x31E3, 15}, + {0x0004, 3}, {0x000D, 5}, {0x0019, 6}, {0x0038, 7}, + {0x000A, 4}, {0x001D, 6}, {0x000B, 4}, {0x0072, 8}, + {0x0073, 8}, {0x00F0, 9}, {0x01E2, 10}, {0x00F2, 9}, + {0x01E3, 10}, {0x00F3, 9}, {0x01E8, 10}, {0x01E9, 10}, + {0x31E4, 15}, {0x01EA, 10}, {0x031F, 11}, {0x03D6, 11}, + {0x31E5, 15}, {0x01EC, 10}, {0x31E6, 15}, {0x00F7, 9}, + {0x03D7, 11}, {0x31E7, 15}, {0x31E8, 15}, {0x03DA, 11}, + {0x03DB, 11}, {0x31E9, 15}, {0x03E0, 11}, {0x31EA, 15}, + {0x003F, 7}, {0x01F1, 10}, {0x31EB, 15}, {0x31EC, 15}, + {0x0006, 3}, {0x001C, 5}, {0x0074, 7}, {0x0075, 7}, + {0x00F9, 9}, {0x001E, 5}, {0x0076, 7}, {0x00FA, 9}, + {0x03E1, 11}, {0x31ED, 15}, {0x18F7, 14}, {0x1F60, 14}, + {0x1F61, 14}, {0x01DC, 9}, {0x01DD, 9}, {0x1F62, 14}, + {0x1F63, 14}, {0x1F64, 14}, {0x1F65, 14}, {0x1F66, 14}, + {0x1F67, 14}, {0x001F, 5}, {0x03ED, 11}, {0x00EF, 8}, + {0x01F7, 10}, + } +}; + +static const uint16_t x8_ac1_highquant_table[8][77][2]={ + {//0 + {0x0000, 3}, {0x0002, 4}, {0x0006, 5}, {0x0007, 5}, + {0x0008, 5}, {0x0009, 5}, {0x0014, 6}, {0x002A, 7}, + {0x0016, 6}, {0x002B, 7}, {0x005C, 8}, {0x002F, 7}, + {0x0030, 7}, {0x005D, 8}, {0x0062, 8}, {0x00C6, 9}, + {0x0007, 4}, {0x0019, 6}, {0x001A, 6}, {0x0036, 7}, + {0x0010, 5}, {0x006E, 8}, {0x0022, 6}, {0x0009, 4}, + {0x000A, 4}, {0x0016, 5}, {0x0023, 6}, {0x002E, 6}, + {0x002F, 6}, {0x0030, 6}, {0x0062, 7}, {0x0063, 7}, + {0x0064, 7}, {0x0065, 7}, {0x0066, 7}, {0x0067, 7}, + {0x0068, 7}, {0x0069, 7}, {0x006A, 7}, {0x006B, 7}, + {0x006C, 7}, {0x00C7, 9}, {0x00DE, 9}, {0x00DF, 9}, + {0x06D0, 11}, {0x01B5, 9}, {0x0037, 6}, {0x00DB, 8}, + {0x001C, 5}, {0x0074, 7}, {0x01D4, 9}, {0x01D5, 9}, + {0x0076, 7}, {0x0369, 10}, {0x3688, 14}, {0x3689, 14}, + {0x368A, 14}, {0x0077, 7}, {0x03AC, 10}, {0x0078, 7}, + {0x00F2, 8}, {0x01D7, 9}, {0x00F3, 8}, {0x007A, 7}, + {0x368B, 14}, {0x007B, 7}, {0x007C, 7}, {0x03AD, 10}, + {0x03E8, 10}, {0x368C, 14}, {0x368D, 14}, {0x03E9, 10}, + {0x368E, 14}, {0x003F, 6}, {0x01F5, 9}, {0x00FB, 8}, + {0x368F, 14}, + },{//1 + {0x0000, 2}, {0x0004, 4}, {0x000A, 5}, {0x000B, 5}, + {0x0018, 6}, {0x0032, 7}, {0x0033, 7}, {0x0034, 7}, + {0x006A, 8}, {0x00D6, 9}, {0x00D7, 9}, {0x00D8, 9}, + {0x00D9, 9}, {0x3680, 15}, {0x01B5, 10}, {0x0369, 11}, + {0x0004, 3}, {0x000E, 5}, {0x001E, 6}, {0x0037, 7}, + {0x000A, 4}, {0x0016, 5}, {0x000C, 4}, {0x001F, 6}, + {0x005C, 7}, {0x005D, 7}, {0x00BC, 8}, {0x00BD, 8}, + {0x005F, 7}, {0x00D0, 8}, {0x00DB, 9}, {0x00D1, 8}, + {0x01A4, 9}, {0x01A5, 9}, {0x01A6, 9}, {0x01A7, 9}, + {0x0350, 10}, {0x06A2, 11}, {0x06A3, 11}, {0x01A9, 9}, + {0x01AA, 9}, {0x06AC, 11}, {0x3681, 15}, {0x0357, 10}, + {0x3682, 15}, {0x3683, 15}, {0x3684, 15}, {0x3685, 15}, + {0x0036, 6}, {0x00D6, 8}, {0x3686, 15}, {0x3687, 15}, + {0x000E, 4}, {0x006E, 7}, {0x00D7, 8}, {0x06AD, 11}, + {0x3688, 15}, {0x001E, 5}, {0x00DE, 8}, {0x06F8, 11}, + {0x037D, 10}, {0x3689, 15}, {0x368A, 15}, {0x368B, 15}, + {0x368C, 15}, {0x01BF, 9}, {0x368D, 15}, {0x1B47, 14}, + {0x37C8, 14}, {0x37C9, 14}, {0x37CA, 14}, {0x37CB, 14}, + {0x37CC, 14}, {0x001F, 5}, {0x37CD, 14}, {0x37CE, 14}, + {0x37CF, 14}, + },{//2 + {0x0000, 3}, {0x0002, 4}, {0x0003, 4}, {0x0008, 5}, + {0x0012, 6}, {0x0026, 7}, {0x0014, 6}, {0x0027, 7}, + {0x00A8, 9}, {0x00A9, 9}, {0x0055, 8}, {0x2B00, 15}, + {0x00AD, 9}, {0x2B01, 15}, {0x2B02, 15}, {0x2B03, 15}, + {0x0003, 3}, {0x000B, 5}, {0x0040, 7}, {0x0041, 7}, + {0x0009, 4}, {0x0021, 6}, {0x0011, 5}, {0x000A, 4}, + {0x000B, 4}, {0x0018, 5}, {0x0032, 6}, {0x0033, 6}, + {0x0034, 6}, {0x0035, 6}, {0x006C, 7}, {0x0057, 8}, + {0x006D, 7}, {0x00DC, 8}, {0x0159, 10}, {0x00DD, 8}, + {0x01BC, 9}, {0x037A, 10}, {0x037B, 10}, {0x0038, 6}, + {0x0072, 7}, {0x01BE, 9}, {0x01BF, 9}, {0x00E6, 8}, + {0x039C, 10}, {0x01CF, 9}, {0x2B04, 15}, {0x2B05, 15}, + {0x0074, 7}, {0x01D4, 9}, {0x2B06, 15}, {0x2B07, 15}, + {0x001E, 5}, {0x00EB, 8}, {0x1584, 14}, {0x1585, 14}, + {0x1586, 14}, {0x003B, 6}, {0x01D5, 9}, {0x01F0, 9}, + {0x039D, 10}, {0x03E2, 10}, {0x1587, 14}, {0x1588, 14}, + {0x1589, 14}, {0x00F9, 8}, {0x158A, 14}, {0x158B, 14}, + {0x03E3, 10}, {0x158C, 14}, {0x158D, 14}, {0x01F4, 9}, + {0x158E, 14}, {0x003F, 6}, {0x00FB, 8}, {0x01F5, 9}, + {0x158F, 14}, + },{//3 + {0x0000, 3}, {0x0002, 4}, {0x0006, 5}, {0x0007, 5}, + {0x0010, 6}, {0x0011, 6}, {0x0024, 7}, {0x0025, 7}, + {0x0013, 6}, {0x0014, 6}, {0x002A, 7}, {0x002B, 7}, + {0x00B0, 9}, {0x00B1, 9}, {0x002D, 7}, {0x0059, 8}, + {0x000C, 5}, {0x0017, 6}, {0x00D0, 9}, {0x0035, 7}, + {0x001B, 6}, {0x0038, 7}, {0x0039, 7}, {0x0004, 3}, + {0x0005, 3}, {0x000F, 5}, {0x0018, 5}, {0x001D, 6}, + {0x0032, 6}, {0x0033, 6}, {0x0068, 7}, {0x0069, 7}, + {0x0069, 8}, {0x00D4, 8}, {0x00D5, 8}, {0x00D6, 8}, + {0x006C, 7}, {0x0037, 6}, {0x006D, 7}, {0x0070, 7}, + {0x0039, 6}, {0x00D7, 8}, {0x00D1, 9}, {0x3880, 14}, + {0x3881, 14}, {0x3882, 14}, {0x0074, 7}, {0x01C5, 9}, + {0x0075, 7}, {0x00E3, 8}, {0x3883, 14}, {0x3884, 14}, + {0x00EC, 8}, {0x3885, 14}, {0x1C43, 13}, {0x1C44, 13}, + {0x1C45, 13}, {0x00ED, 8}, {0x1C46, 13}, {0x003C, 6}, + {0x0077, 7}, {0x01E8, 9}, {0x003E, 6}, {0x007B, 7}, + {0x1C47, 13}, {0x007E, 7}, {0x007F, 7}, {0x1C48, 13}, + {0x1C49, 13}, {0x1C4A, 13}, {0x1C4B, 13}, {0x1C4C, 13}, + {0x1C4D, 13}, {0x00F5, 8}, {0x1C4E, 13}, {0x01E9, 9}, + {0x1C4F, 13}, + },{//4 + {0x0000, 2}, {0x0004, 4}, {0x000A, 5}, {0x000B, 5}, + {0x0018, 6}, {0x0019, 6}, {0x0034, 7}, {0x0035, 7}, + {0x0036, 7}, {0x006E, 8}, {0x00DE, 9}, {0x00DF, 9}, + {0x01C0, 10}, {0x01C1, 10}, {0x01C2, 10}, {0x3860, 15}, + {0x0004, 3}, {0x000F, 5}, {0x001D, 6}, {0x0039, 7}, + {0x000A, 4}, {0x002C, 6}, {0x002D, 6}, {0x000C, 4}, + {0x0017, 5}, {0x0034, 6}, {0x0035, 6}, {0x0036, 6}, + {0x006E, 7}, {0x006F, 7}, {0x0070, 7}, {0x0071, 7}, + {0x0071, 8}, {0x00E4, 8}, {0x00E5, 8}, {0x00E6, 8}, + {0x00E7, 8}, {0x00E8, 8}, {0x03A4, 10}, {0x0075, 7}, + {0x00EC, 8}, {0x01D3, 9}, {0x01DA, 9}, {0x03A5, 10}, + {0x03B6, 10}, {0x070D, 12}, {0x03B7, 10}, {0x070E, 12}, + {0x003C, 6}, {0x00EE, 8}, {0x3861, 15}, {0x3862, 15}, + {0x003D, 6}, {0x01DE, 9}, {0x3863, 15}, {0x3864, 15}, + {0x3865, 15}, {0x007C, 7}, {0x070F, 12}, {0x03BE, 10}, + {0x03BF, 10}, {0x3866, 15}, {0x0FA0, 12}, {0x07D1, 11}, + {0x3867, 15}, {0x00FB, 8}, {0x01F5, 9}, {0x7D08, 15}, + {0x0FA4, 12}, {0x7D09, 15}, {0x7D0A, 15}, {0x7D0B, 15}, + {0x3E86, 14}, {0x003F, 6}, {0x0FA5, 12}, {0x07D3, 11}, + {0x3E87, 14}, + },{//5 + {0x0000, 3}, {0x0002, 4}, {0x0003, 4}, {0x0008, 5}, + {0x0009, 5}, {0x0014, 6}, {0x002A, 7}, {0x0056, 8}, + {0x02B8, 11}, {0x00AF, 9}, {0x02B9, 11}, {0x015D, 10}, + {0x02C0, 11}, {0x2C10, 15}, {0x2C11, 15}, {0x2C12, 15}, + {0x0006, 4}, {0x000E, 5}, {0x0017, 6}, {0x002D, 7}, + {0x000F, 5}, {0x0040, 7}, {0x0021, 6}, {0x0005, 3}, + {0x0009, 4}, {0x0011, 5}, {0x0018, 5}, {0x0019, 5}, + {0x001A, 5}, {0x0036, 6}, {0x0037, 6}, {0x0041, 7}, + {0x0059, 8}, {0x00E0, 8}, {0x00E1, 8}, {0x0071, 7}, + {0x00E4, 8}, {0x00B1, 9}, {0x02C2, 11}, {0x001D, 5}, + {0x0073, 7}, {0x00E5, 8}, {0x00F0, 8}, {0x0079, 7}, + {0x03C4, 10}, {0x01E3, 9}, {0x01E8, 9}, {0x2C13, 15}, + {0x007B, 7}, {0x2C14, 15}, {0x2C15, 15}, {0x2C16, 15}, + {0x007C, 7}, {0x02C3, 11}, {0x2C17, 15}, {0x160C, 14}, + {0x160D, 14}, {0x007D, 7}, {0x160E, 14}, {0x01E9, 9}, + {0x03C5, 10}, {0x03D4, 10}, {0x01EB, 9}, {0x160F, 14}, + {0x3D50, 14}, {0x00FC, 8}, {0x07AB, 11}, {0x3D51, 14}, + {0x3D52, 14}, {0x3D53, 14}, {0x3D54, 14}, {0x01FA, 9}, + {0x3D55, 14}, {0x007F, 7}, {0x01FB, 9}, {0x3D56, 14}, + {0x3D57, 14}, + },{//6 + {0x0000, 3}, {0x0002, 4}, {0x0003, 4}, {0x0008, 5}, + {0x0009, 5}, {0x000A, 5}, {0x000B, 5}, {0x0018, 6}, + {0x0032, 7}, {0x000D, 5}, {0x0033, 7}, {0x0E00, 13}, + {0x0039, 7}, {0x0E01, 13}, {0x003A, 7}, {0x0E02, 13}, + {0x0008, 4}, {0x001E, 6}, {0x003B, 7}, {0x003E, 7}, + {0x0012, 5}, {0x003F, 7}, {0x0013, 5}, {0x0028, 6}, + {0x0029, 6}, {0x0054, 7}, {0x002B, 6}, {0x0055, 7}, + {0x0058, 7}, {0x0E03, 13}, {0x0059, 7}, {0x005A, 7}, + {0x0E04, 13}, {0x0E05, 13}, {0x0703, 12}, {0x005B, 7}, + {0x005C, 7}, {0x0704, 12}, {0x0705, 12}, {0x005D, 7}, + {0x0706, 12}, {0x0707, 12}, {0x0708, 12}, {0x0709, 12}, + {0x070A, 12}, {0x070B, 12}, {0x0018, 5}, {0x002F, 6}, + {0x000D, 4}, {0x0019, 5}, {0x070C, 12}, {0x0070, 7}, + {0x001D, 5}, {0x070D, 12}, {0x070E, 12}, {0x070F, 12}, + {0x0710, 12}, {0x0039, 6}, {0x0711, 12}, {0x003C, 6}, + {0x0712, 12}, {0x0713, 12}, {0x0714, 12}, {0x0715, 12}, + {0x0716, 12}, {0x003D, 6}, {0x0717, 12}, {0x0718, 12}, + {0x0719, 12}, {0x071A, 12}, {0x071B, 12}, {0x071C, 12}, + {0x071D, 12}, {0x001F, 5}, {0x071E, 12}, {0x0071, 7}, + {0x071F, 12}, + },{//7 + {0x0000, 3}, {0x0002, 4}, {0x0006, 5}, {0x000E, 6}, + {0x000F, 6}, {0x0040, 8}, {0x0041, 8}, {0x0042, 8}, + {0x0218, 11}, {0x2190, 15}, {0x2191, 15}, {0x2192, 15}, + {0x2193, 15}, {0x2194, 15}, {0x2195, 15}, {0x2196, 15}, + {0x0005, 4}, {0x0011, 6}, {0x0024, 7}, {0x0087, 9}, + {0x000C, 5}, {0x004A, 8}, {0x004B, 8}, {0x0002, 2}, + {0x0006, 3}, {0x000D, 5}, {0x000E, 5}, {0x000F, 5}, + {0x0013, 6}, {0x0038, 6}, {0x00E4, 8}, {0x00E5, 8}, + {0x01CC, 9}, {0x00E7, 8}, {0x0074, 7}, {0x00EA, 8}, + {0x01CD, 9}, {0x021A, 11}, {0x2197, 15}, {0x001E, 5}, + {0x0076, 7}, {0x00EB, 8}, {0x01DC, 9}, {0x00EF, 8}, + {0x01DD, 9}, {0x01F0, 9}, {0x2198, 15}, {0x2199, 15}, + {0x00F9, 8}, {0x03E2, 10}, {0x219A, 15}, {0x219B, 15}, + {0x00FA, 8}, {0x219C, 15}, {0x219D, 15}, {0x219E, 15}, + {0x219F, 15}, {0x01F6, 9}, {0x21B0, 15}, {0x00FC, 8}, + {0x01F7, 9}, {0x21B1, 15}, {0x21B2, 15}, {0x21B3, 15}, + {0x21B4, 15}, {0x01FA, 9}, {0x21B5, 15}, {0x21B6, 15}, + {0x21B7, 15}, {0x21B8, 15}, {0x21B9, 15}, {0x03E3, 10}, + {0x10DD, 14}, {0x007F, 7}, {0x01FB, 9}, {0x10DE, 14}, + {0x10DF, 14}, + } +}; +#define MAX_AC_VLC_BITS 16 + +#endif /* FFMPEG_INTRAX8HUF_H */ diff --git a/contrib/ffmpeg/libavcodec/jpeg_ls.c b/contrib/ffmpeg/libavcodec/jpeg_ls.c deleted file mode 100644 index 136e3fb80..000000000 --- a/contrib/ffmpeg/libavcodec/jpeg_ls.c +++ /dev/null @@ -1,860 +0,0 @@ -/* - * JPEG-LS encoder and decoder - * Copyright (c) 2003 Michael Niedermayer - * Copyright (c) 2006 Konstantin Shishkov - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "golomb.h" - -/** - * @file jpeg_ls.c - * JPEG-LS encoder and decoder. - */ - -typedef struct JpeglsContext{ - AVCodecContext *avctx; - AVFrame picture; -}JpeglsContext; - -typedef struct JLSState{ - int T1, T2, T3; - int A[367], B[367], C[365], N[367]; - int limit, reset, bpp, qbpp, maxval, range; - int near, twonear; - int run_index[3]; -}JLSState; - -static const uint8_t log2_run[32]={ - 0, 0, 0, 0, 1, 1, 1, 1, - 2, 2, 2, 2, 3, 3, 3, 3, - 4, 4, 5, 5, 6, 6, 7, 7, - 8, 9,10,11,12,13,14,15 -}; - -/* -* Uncomment this to significantly speed up decoding of broken JPEG-LS -* (or test broken JPEG-LS decoder) and slow down ordinary decoding a bit. -* -* There is no Golomb code with length >= 32 bits possible, so check and -* avoid situation of 32 zeros, FFmpeg Golomb decoder is painfully slow -* on this errors. -*/ -//#define JLS_BROKEN - -/********** Functions for both encoder and decoder **********/ - -/** - * Calculate initial JPEG-LS parameters - */ -static void ls_init_state(JLSState *state){ - int i; - - state->twonear = state->near * 2 + 1; - state->range = ((state->maxval + state->twonear - 1) / state->twonear) + 1; - - // QBPP = ceil(log2(RANGE)) - for(state->qbpp = 0; (1 << state->qbpp) < state->range; state->qbpp++); - - if(state->bpp < 8) - state->limit = 16 + 2 * state->bpp - state->qbpp; - else - state->limit = (4 * state->bpp) - state->qbpp; - - for(i = 0; i < 367; i++) { - state->A[i] = FFMAX((state->range + 32) >> 6, 2); - state->N[i] = 1; - } - -} - -/** - * Calculate quantized gradient value, used for context determination - */ -static inline int quantize(JLSState *s, int v){ //FIXME optimize - if(v==0) return 0; - if(v < 0){ - if(v <= -s->T3) return -4; - if(v <= -s->T2) return -3; - if(v <= -s->T1) return -2; - if(v < -s->near) return -1; - return 0; - }else{ - if(v <= s->near) return 0; - if(v < s->T1) return 1; - if(v < s->T2) return 2; - if(v < s->T3) return 3; - return 4; - } -} - -/** - * Custom value clipping function used in T1, T2, T3 calculation - */ -static inline int iso_clip(int v, int vmin, int vmax){ - if(v > vmax || v < vmin) return vmin; - else return v; -} - -/** - * Calculate JPEG-LS codec values - */ -static void reset_ls_coding_parameters(JLSState *s, int reset_all){ - const int basic_t1= 3; - const int basic_t2= 7; - const int basic_t3= 21; - int factor; - - if(s->maxval==0 || reset_all) s->maxval= (1 << s->bpp) - 1; - - if(s->maxval >=128){ - factor= (FFMIN(s->maxval, 4095) + 128)>>8; - - if(s->T1==0 || reset_all) - s->T1= iso_clip(factor*(basic_t1-2) + 2 + 3*s->near, s->near+1, s->maxval); - if(s->T2==0 || reset_all) - s->T2= iso_clip(factor*(basic_t2-3) + 3 + 5*s->near, s->T1, s->maxval); - if(s->T3==0 || reset_all) - s->T3= iso_clip(factor*(basic_t3-4) + 4 + 7*s->near, s->T2, s->maxval); - }else{ - factor= 256 / (s->maxval + 1); - - if(s->T1==0 || reset_all) - s->T1= iso_clip(FFMAX(2, basic_t1/factor + 3*s->near), s->near+1, s->maxval); - if(s->T2==0 || reset_all) - s->T2= iso_clip(FFMAX(3, basic_t2/factor + 5*s->near), s->T1, s->maxval); - if(s->T3==0 || reset_all) - s->T3= iso_clip(FFMAX(4, basic_t3/factor + 6*s->near), s->T2, s->maxval); - } - - if(s->reset==0 || reset_all) s->reset= 64; -// av_log(NULL, AV_LOG_DEBUG, "[JPEG-LS RESET] T=%i,%i,%i\n", s->T1, s->T2, s->T3); -} - - -/********** Decoder-specific functions **********/ - -/** - * Decode LSE block with initialization parameters - */ -static int decode_lse(MJpegDecodeContext *s) -{ - int len, id; - - /* XXX: verify len field validity */ - len = get_bits(&s->gb, 16); - id = get_bits(&s->gb, 8); - - switch(id){ - case 1: - s->maxval= get_bits(&s->gb, 16); - s->t1= get_bits(&s->gb, 16); - s->t2= get_bits(&s->gb, 16); - s->t3= get_bits(&s->gb, 16); - s->reset= get_bits(&s->gb, 16); - -// reset_ls_coding_parameters(s, 0); - //FIXME quant table? - break; - case 2: - case 3: - av_log(s->avctx, AV_LOG_ERROR, "palette not supported\n"); - return -1; - case 4: - av_log(s->avctx, AV_LOG_ERROR, "oversize image not supported\n"); - return -1; - default: - av_log(s->avctx, AV_LOG_ERROR, "invalid id %d\n", id); - return -1; - } -// av_log(s->avctx, AV_LOG_DEBUG, "ID=%i, T=%i,%i,%i\n", id, s->t1, s->t2, s->t3); - - return 0; -} - -static void inline downscale_state(JLSState *state, int Q){ - if(state->N[Q] == state->reset){ - state->A[Q] >>=1; - state->B[Q] >>=1; - state->N[Q] >>=1; - } - state->N[Q]++; -} - -static inline int update_state_regular(JLSState *state, int Q, int err){ - state->A[Q] += FFABS(err); - err *= state->twonear; - state->B[Q] += err; - - downscale_state(state, Q); - - if(state->B[Q] <= -state->N[Q]) { - state->B[Q]= FFMAX(state->B[Q] + state->N[Q], 1-state->N[Q]); - if(state->C[Q] > -128) - state->C[Q]--; - }else if(state->B[Q] > 0){ - state->B[Q]= FFMIN(state->B[Q] - state->N[Q], 0); - if(state->C[Q] < 127) - state->C[Q]++; - } - - return err; -} - -/** - * Get context-dependent Golomb code, decode it and update context - */ -static inline int ls_get_code_regular(GetBitContext *gb, JLSState *state, int Q){ - int k, ret; - - for(k = 0; (state->N[Q] << k) < state->A[Q]; k++); - -#ifdef JLS_BROKEN - if(!show_bits_long(gb, 32))return -1; -#endif - ret = get_ur_golomb_jpegls(gb, k, state->limit, state->qbpp); - - /* decode mapped error */ - if(ret & 1) - ret = -((ret + 1) >> 1); - else - ret >>= 1; - - /* for NEAR=0, k=0 and 2*B[Q] <= - N[Q] mapping is reversed */ - if(!state->near && !k && (2 * state->B[Q] <= -state->N[Q])) - ret = -(ret + 1); - - ret= update_state_regular(state, Q, ret); - - return ret; -} - -/** - * Get Golomb code, decode it and update state for run termination - */ -static inline int ls_get_code_runterm(GetBitContext *gb, JLSState *state, int RItype, int limit_add){ - int k, ret, temp, map; - int Q = 365 + RItype; - - temp= state->A[Q]; - if(RItype) - temp += state->N[Q] >> 1; - - for(k = 0; (state->N[Q] << k) < temp; k++); - -#ifdef JLS_BROKEN - if(!show_bits_long(gb, 32))return -1; -#endif - ret = get_ur_golomb_jpegls(gb, k, state->limit - limit_add - 1, state->qbpp); - - /* decode mapped error */ - map = 0; - if(!k && (RItype || ret) && (2 * state->B[Q] < state->N[Q])) - map = 1; - ret += RItype + map; - - if(ret & 1){ - ret = map - ((ret + 1) >> 1); - state->B[Q]++; - } else { - ret = ret >> 1; - } - - /* update state */ - state->A[Q] += FFABS(ret) - RItype; - ret *= state->twonear; - downscale_state(state, Q); - - return ret; -} - -#define R(a, i ) (bits == 8 ? ((uint8_t*)(a))[i] : ((uint16_t*)(a))[i] ) -#define W(a, i, v) (bits == 8 ? (((uint8_t*)(a))[i]=v) : (((uint16_t*)(a))[i]=v)) -/** - * Decode one line of image - */ -static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, void *last, void *dst, int last2, int w, int stride, int comp, int bits){ - int i, x = 0; - int Ra, Rb, Rc, Rd; - int D0, D1, D2; - - while(x < w) { - int err, pred; - - /* compute gradients */ - Ra = x ? R(dst, x - stride) : R(last, x); - Rb = R(last, x); - Rc = x ? R(last, x - stride) : last2; - Rd = (x >= w - stride) ? R(last, x) : R(last, x + stride); - D0 = Rd - Rb; - D1 = Rb - Rc; - D2 = Rc - Ra; - /* run mode */ - if((FFABS(D0) <= state->near) && (FFABS(D1) <= state->near) && (FFABS(D2) <= state->near)) { - int r; - int RItype; - - /* decode full runs while available */ - while(get_bits1(&s->gb)) { - int r; - r = 1 << log2_run[state->run_index[comp]]; - if(x + r * stride > w) { - r = (w - x) / stride; - } - for(i = 0; i < r; i++) { - W(dst, x, Ra); - x += stride; - } - /* if EOL reached, we stop decoding */ - if(r != (1 << log2_run[state->run_index[comp]])) - return; - if(state->run_index[comp] < 31) - state->run_index[comp]++; - if(x + stride > w) - return; - } - /* decode aborted run */ - r = log2_run[state->run_index[comp]]; - if(r) - r = get_bits_long(&s->gb, r); - for(i = 0; i < r; i++) { - W(dst, x, Ra); - x += stride; - } - - /* decode run termination value */ - Rb = R(last, x); - RItype = (FFABS(Ra - Rb) <= state->near) ? 1 : 0; - err = ls_get_code_runterm(&s->gb, state, RItype, log2_run[state->run_index[comp]]); - if(state->run_index[comp]) - state->run_index[comp]--; - - if(state->near && RItype){ - pred = Ra + err; - } else { - if(Rb < Ra) - pred = Rb - err; - else - pred = Rb + err; - } - } else { /* regular mode */ - int context, sign; - - context = quantize(state, D0) * 81 + quantize(state, D1) * 9 + quantize(state, D2); - pred = mid_pred(Ra, Ra + Rb - Rc, Rb); - - if(context < 0){ - context = -context; - sign = 1; - }else{ - sign = 0; - } - - if(sign){ - pred = av_clip(pred - state->C[context], 0, state->maxval); - err = -ls_get_code_regular(&s->gb, state, context); - } else { - pred = av_clip(pred + state->C[context], 0, state->maxval); - err = ls_get_code_regular(&s->gb, state, context); - } - - /* we have to do something more for near-lossless coding */ - pred += err; - } - if(state->near){ - if(pred < -state->near) - pred += state->range * state->twonear; - else if(pred > state->maxval + state->near) - pred -= state->range * state->twonear; - pred = av_clip(pred, 0, state->maxval); - } - - pred &= state->maxval; - W(dst, x, pred); - x += stride; - } -} - -static int ls_decode_picture(MJpegDecodeContext *s, int near, int point_transform, int ilv){ - int i, t = 0; - uint8_t *zero, *last, *cur; - JLSState *state; - int off = 0, stride = 1, width, shift; - - zero = av_mallocz(s->picture.linesize[0]); - last = zero; - cur = s->picture.data[0]; - - state = av_mallocz(sizeof(JLSState)); - /* initialize JPEG-LS state from JPEG parameters */ - state->near = near; - state->bpp = (s->bits < 2) ? 2 : s->bits; - state->maxval = s->maxval; - state->T1 = s->t1; - state->T2 = s->t2; - state->T3 = s->t3; - state->reset = s->reset; - reset_ls_coding_parameters(state, 0); - ls_init_state(state); - - if(s->bits <= 8) - shift = point_transform + (8 - s->bits); - else - shift = point_transform + (16 - s->bits); - -// av_log(s->avctx, AV_LOG_DEBUG, "JPEG-LS params: %ix%i NEAR=%i MV=%i T(%i,%i,%i) RESET=%i, LIMIT=%i, qbpp=%i, RANGE=%i\n",s->width,s->height,state->near,state->maxval,state->T1,state->T2,state->T3,state->reset,state->limit,state->qbpp, state->range); -// av_log(s->avctx, AV_LOG_DEBUG, "JPEG params: ILV=%i Pt=%i BPP=%i, scan = %i\n", ilv, point_transform, s->bits, s->cur_scan); - if(ilv == 0) { /* separate planes */ - off = s->cur_scan - 1; - stride = (s->nb_components > 1) ? 3 : 1; - width = s->width * stride; - cur += off; - for(i = 0; i < s->height; i++) { - if(s->bits <= 8){ - ls_decode_line(state, s, last, cur, t, width, stride, off, 8); - t = last[0]; - }else{ - ls_decode_line(state, s, last, cur, t, width, stride, off, 16); - t = *((uint16_t*)last); - } - last = cur; - cur += s->picture.linesize[0]; - - if (s->restart_interval && !--s->restart_count) { - align_get_bits(&s->gb); - skip_bits(&s->gb, 16); /* skip RSTn */ - } - } - } else if(ilv == 1) { /* line interleaving */ - int j; - int Rc[3] = {0, 0, 0}; - memset(cur, 0, s->picture.linesize[0]); - width = s->width * 3; - for(i = 0; i < s->height; i++) { - for(j = 0; j < 3; j++) { - ls_decode_line(state, s, last + j, cur + j, Rc[j], width, 3, j, 8); - Rc[j] = last[j]; - - if (s->restart_interval && !--s->restart_count) { - align_get_bits(&s->gb); - skip_bits(&s->gb, 16); /* skip RSTn */ - } - } - last = cur; - cur += s->picture.linesize[0]; - } - } else if(ilv == 2) { /* sample interleaving */ - av_log(s->avctx, AV_LOG_ERROR, "Sample interleaved images are not supported.\n"); - av_free(state); - av_free(zero); - return -1; - } - - if(shift){ /* we need to do point transform or normalize samples */ - int x, w; - - w = s->width * s->nb_components; - - if(s->bits <= 8){ - uint8_t *src = s->picture.data[0]; - - for(i = 0; i < s->height; i++){ - for(x = off; x < w; x+= stride){ - src[x] <<= shift; - } - src += s->picture.linesize[0]; - } - }else{ - uint16_t *src = (uint16_t*) s->picture.data[0]; - - for(i = 0; i < s->height; i++){ - for(x = 0; x < w; x++){ - src[x] <<= shift; - } - src += s->picture.linesize[0]/2; - } - } - } - av_free(state); - av_free(zero); - - return 0; -} - -#if defined(CONFIG_ENCODERS) && defined(CONFIG_JPEGLS_ENCODER) -/********** Encoder-specific functions **********/ - -/** - * Encode error from regular symbol - */ -static inline void ls_encode_regular(JLSState *state, PutBitContext *pb, int Q, int err){ - int k; - int val; - int map; - - for(k = 0; (state->N[Q] << k) < state->A[Q]; k++); - - map = !state->near && !k && (2 * state->B[Q] <= -state->N[Q]); - - if(err < 0) - err += state->range; - if(err >= ((state->range + 1) >> 1)) { - err -= state->range; - val = 2 * FFABS(err) - 1 - map; - } else - val = 2 * err + map; - - set_ur_golomb_jpegls(pb, val, k, state->limit, state->qbpp); - - update_state_regular(state, Q, err); -} - -/** - * Encode error from run termination - */ -static inline void ls_encode_runterm(JLSState *state, PutBitContext *pb, int RItype, int err, int limit_add){ - int k; - int val, map; - int Q = 365 + RItype; - int temp; - - temp = state->A[Q]; - if(RItype) - temp += state->N[Q] >> 1; - for(k = 0; (state->N[Q] << k) < temp; k++); - map = 0; - if(!k && err && (2 * state->B[Q] < state->N[Q])) - map = 1; - - if(err < 0) - val = - (2 * err) - 1 - RItype + map; - else - val = 2 * err - RItype - map; - set_ur_golomb_jpegls(pb, val, k, state->limit - limit_add - 1, state->qbpp); - - if(err < 0) - state->B[Q]++; - state->A[Q] += (val + 1 - RItype) >> 1; - - downscale_state(state, Q); -} - -/** - * Encode run value as specified by JPEG-LS standard - */ -static inline void ls_encode_run(JLSState *state, PutBitContext *pb, int run, int comp, int trail){ - while(run >= (1 << log2_run[state->run_index[comp]])){ - put_bits(pb, 1, 1); - run -= 1 << log2_run[state->run_index[comp]]; - if(state->run_index[comp] < 31) - state->run_index[comp]++; - } - /* if hit EOL, encode another full run, else encode aborted run */ - if(!trail && run) { - put_bits(pb, 1, 1); - }else if(trail){ - put_bits(pb, 1, 0); - if(log2_run[state->run_index[comp]]) - put_bits(pb, log2_run[state->run_index[comp]], run); - } -} - -/** - * Encode one line of image - */ -static inline void ls_encode_line(JLSState *state, PutBitContext *pb, void *last, void *cur, int last2, int w, int stride, int comp, int bits){ - int x = 0; - int Ra, Rb, Rc, Rd; - int D0, D1, D2; - - while(x < w) { - int err, pred, sign; - - /* compute gradients */ - Ra = x ? R(cur, x - stride) : R(last, x); - Rb = R(last, x); - Rc = x ? R(last, x - stride) : last2; - Rd = (x >= w - stride) ? R(last, x) : R(last, x + stride); - D0 = Rd - Rb; - D1 = Rb - Rc; - D2 = Rc - Ra; - - /* run mode */ - if((FFABS(D0) <= state->near) && (FFABS(D1) <= state->near) && (FFABS(D2) <= state->near)) { - int RUNval, RItype, run; - - run = 0; - RUNval = Ra; - while(x < w && (FFABS(R(cur, x) - RUNval) <= state->near)){ - run++; - W(cur, x, Ra); - x += stride; - } - ls_encode_run(state, pb, run, comp, x < w); - if(x >= w) - return; - Rb = R(last, x); - RItype = (FFABS(Ra - Rb) <= state->near); - pred = RItype ? Ra : Rb; - err = R(cur, x) - pred; - - if(!RItype && Ra > Rb) - err = -err; - - if(state->near){ - if(err > 0) - err = (state->near + err) / state->twonear; - else - err = -(state->near - err) / state->twonear; - - if(RItype || (Rb >= Ra)) - Ra = av_clip(pred + err * state->twonear, 0, state->maxval); - else - Ra = av_clip(pred - err * state->twonear, 0, state->maxval); - W(cur, x, Ra); - } - if(err < 0) - err += state->range; - if(err >= ((state->range + 1) >> 1)) - err -= state->range; - - ls_encode_runterm(state, pb, RItype, err, log2_run[state->run_index[comp]]); - - if(state->run_index[comp] > 0) - state->run_index[comp]--; - } else { /* regular mode */ - int context; - - context = quantize(state, D0) * 81 + quantize(state, D1) * 9 + quantize(state, D2); - pred = mid_pred(Ra, Ra + Rb - Rc, Rb); - - if(context < 0){ - context = -context; - sign = 1; - pred = av_clip(pred - state->C[context], 0, state->maxval); - err = pred - R(cur, x); - }else{ - sign = 0; - pred = av_clip(pred + state->C[context], 0, state->maxval); - err = R(cur, x) - pred; - } - - if(state->near){ - if(err > 0) - err = (state->near + err) / state->twonear; - else - err = -(state->near - err) / state->twonear; - if(!sign) - Ra = av_clip(pred + err * state->twonear, 0, state->maxval); - else - Ra = av_clip(pred - err * state->twonear, 0, state->maxval); - W(cur, x, Ra); - } - - ls_encode_regular(state, pb, context, err); - } - x += stride; - } -} - -static void ls_store_lse(JLSState *state, PutBitContext *pb){ - /* Test if we have default params and don't need to store LSE */ - JLSState state2; - memset(&state2, 0, sizeof(JLSState)); - state2.bpp = state->bpp; - state2.near = state->near; - reset_ls_coding_parameters(&state2, 1); - if(state->T1 == state2.T1 && state->T2 == state2.T2 && state->T3 == state2.T3 && state->reset == state2.reset) - return; - /* store LSE type 1 */ - put_marker(pb, LSE); - put_bits(pb, 16, 13); - put_bits(pb, 8, 1); - put_bits(pb, 16, state->maxval); - put_bits(pb, 16, state->T1); - put_bits(pb, 16, state->T2); - put_bits(pb, 16, state->T3); - put_bits(pb, 16, state->reset); -} - -static int encode_picture_ls(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ - JpeglsContext * const s = avctx->priv_data; - AVFrame *pict = data; - AVFrame * const p= (AVFrame*)&s->picture; - const int near = avctx->prediction_method; - PutBitContext pb, pb2; - GetBitContext gb; - uint8_t *buf2, *zero, *cur, *last; - JLSState *state; - int i, size; - int comps; - - buf2 = av_malloc(buf_size); - - init_put_bits(&pb, buf, buf_size); - init_put_bits(&pb2, buf2, buf_size); - - *p = *pict; - p->pict_type= FF_I_TYPE; - p->key_frame= 1; - - if(avctx->pix_fmt == PIX_FMT_GRAY8 || avctx->pix_fmt == PIX_FMT_GRAY16) - comps = 1; - else - comps = 3; - - /* write our own JPEG header, can't use mjpeg_picture_header */ - put_marker(&pb, SOI); - put_marker(&pb, SOF48); - put_bits(&pb, 16, 8 + comps * 3); // header size depends on components - put_bits(&pb, 8, (avctx->pix_fmt == PIX_FMT_GRAY16) ? 16 : 8); // bpp - put_bits(&pb, 16, avctx->height); - put_bits(&pb, 16, avctx->width); - put_bits(&pb, 8, comps); // components - for(i = 1; i <= comps; i++) { - put_bits(&pb, 8, i); // component ID - put_bits(&pb, 8, 0x11); // subsampling: none - put_bits(&pb, 8, 0); // Tiq, used by JPEG-LS ext - } - - put_marker(&pb, SOS); - put_bits(&pb, 16, 6 + comps * 2); - put_bits(&pb, 8, comps); - for(i = 1; i <= comps; i++) { - put_bits(&pb, 8, i); // component ID - put_bits(&pb, 8, 0); // mapping index: none - } - put_bits(&pb, 8, near); - put_bits(&pb, 8, (comps > 1) ? 1 : 0); // interleaving: 0 - plane, 1 - line - put_bits(&pb, 8, 0); // point transform: none - - state = av_mallocz(sizeof(JLSState)); - /* initialize JPEG-LS state from JPEG parameters */ - state->near = near; - state->bpp = (avctx->pix_fmt == PIX_FMT_GRAY16) ? 16 : 8; - reset_ls_coding_parameters(state, 0); - ls_init_state(state); - - ls_store_lse(state, &pb); - - zero = av_mallocz(p->linesize[0]); - last = zero; - cur = p->data[0]; - if(avctx->pix_fmt == PIX_FMT_GRAY8){ - int t = 0; - - for(i = 0; i < avctx->height; i++) { - ls_encode_line(state, &pb2, last, cur, t, avctx->width, 1, 0, 8); - t = last[0]; - last = cur; - cur += p->linesize[0]; - } - }else if(avctx->pix_fmt == PIX_FMT_GRAY16){ - int t = 0; - - for(i = 0; i < avctx->height; i++) { - ls_encode_line(state, &pb2, last, cur, t, avctx->width, 1, 0, 16); - t = *((uint16_t*)last); - last = cur; - cur += p->linesize[0]; - } - }else if(avctx->pix_fmt == PIX_FMT_RGB24){ - int j, width; - int Rc[3] = {0, 0, 0}; - - width = avctx->width * 3; - for(i = 0; i < avctx->height; i++) { - for(j = 0; j < 3; j++) { - ls_encode_line(state, &pb2, last + j, cur + j, Rc[j], width, 3, j, 8); - Rc[j] = last[j]; - } - last = cur; - cur += s->picture.linesize[0]; - } - }else if(avctx->pix_fmt == PIX_FMT_BGR24){ - int j, width; - int Rc[3] = {0, 0, 0}; - - width = avctx->width * 3; - for(i = 0; i < avctx->height; i++) { - for(j = 2; j >= 0; j--) { - ls_encode_line(state, &pb2, last + j, cur + j, Rc[j], width, 3, j, 8); - Rc[j] = last[j]; - } - last = cur; - cur += s->picture.linesize[0]; - } - } - - av_free(zero); - av_free(state); - - // the specification says that after doing 0xff escaping unused bits in the - // last byte must be set to 0, so just append 7 "optional" zero-bits to - // avoid special-casing. - put_bits(&pb2, 7, 0); - size = put_bits_count(&pb2); - flush_put_bits(&pb2); - /* do escape coding */ - init_get_bits(&gb, buf2, size); - size -= 7; - while(get_bits_count(&gb) < size){ - int v; - v = get_bits(&gb, 8); - put_bits(&pb, 8, v); - if(v == 0xFF){ - v = get_bits(&gb, 7); - put_bits(&pb, 8, v); - } - } - align_put_bits(&pb); - av_free(buf2); - - /* End of image */ - put_marker(&pb, EOI); - flush_put_bits(&pb); - - emms_c(); - - return put_bits_count(&pb) >> 3; -} - -static int encode_init_ls(AVCodecContext *ctx) { - JpeglsContext *c = (JpeglsContext*)ctx->priv_data; - - c->avctx = ctx; - ctx->coded_frame = &c->picture; - - if(ctx->pix_fmt != PIX_FMT_GRAY8 && ctx->pix_fmt != PIX_FMT_GRAY16 && ctx->pix_fmt != PIX_FMT_RGB24 && ctx->pix_fmt != PIX_FMT_BGR24){ - av_log(ctx, AV_LOG_ERROR, "Only grayscale and RGB24/BGR24 images are supported\n"); - return -1; - } - return 0; -} - -AVCodec jpegls_encoder = { //FIXME avoid MPV_* lossless jpeg shouldnt need them - "jpegls", - CODEC_TYPE_VIDEO, - CODEC_ID_JPEGLS, - sizeof(JpeglsContext), - encode_init_ls, - encode_picture_ls, - NULL, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_RGB24, PIX_FMT_GRAY8, PIX_FMT_GRAY16, -1}, -}; -#endif diff --git a/contrib/ffmpeg/libavcodec/jpegls.c b/contrib/ffmpeg/libavcodec/jpegls.c new file mode 100644 index 000000000..8a6f5065c --- /dev/null +++ b/contrib/ffmpeg/libavcodec/jpegls.c @@ -0,0 +1,96 @@ +/* + * JPEG-LS common code + * Copyright (c) 2003 Michael Niedermayer + * Copyright (c) 2006 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file jpegls.c + * JPEG-LS common code. + */ + +#include "jpegls.h" + +const uint8_t ff_log2_run[32]={ + 0, 0, 0, 0, 1, 1, 1, 1, + 2, 2, 2, 2, 3, 3, 3, 3, + 4, 4, 5, 5, 6, 6, 7, 7, + 8, 9,10,11,12,13,14,15 +}; + +void ff_jpegls_init_state(JLSState *state){ + int i; + + state->twonear = state->near * 2 + 1; + state->range = ((state->maxval + state->twonear - 1) / state->twonear) + 1; + + // QBPP = ceil(log2(RANGE)) + for(state->qbpp = 0; (1 << state->qbpp) < state->range; state->qbpp++); + + if(state->bpp < 8) + state->limit = 16 + 2 * state->bpp - state->qbpp; + else + state->limit = (4 * state->bpp) - state->qbpp; + + for(i = 0; i < 367; i++) { + state->A[i] = FFMAX((state->range + 32) >> 6, 2); + state->N[i] = 1; + } + +} + +/** + * Custom value clipping function used in T1, T2, T3 calculation + */ +static inline int iso_clip(int v, int vmin, int vmax){ + if(v > vmax || v < vmin) return vmin; + else return v; +} + +void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all){ + const int basic_t1= 3; + const int basic_t2= 7; + const int basic_t3= 21; + int factor; + + if(s->maxval==0 || reset_all) s->maxval= (1 << s->bpp) - 1; + + if(s->maxval >=128){ + factor= (FFMIN(s->maxval, 4095) + 128)>>8; + + if(s->T1==0 || reset_all) + s->T1= iso_clip(factor*(basic_t1-2) + 2 + 3*s->near, s->near+1, s->maxval); + if(s->T2==0 || reset_all) + s->T2= iso_clip(factor*(basic_t2-3) + 3 + 5*s->near, s->T1, s->maxval); + if(s->T3==0 || reset_all) + s->T3= iso_clip(factor*(basic_t3-4) + 4 + 7*s->near, s->T2, s->maxval); + }else{ + factor= 256 / (s->maxval + 1); + + if(s->T1==0 || reset_all) + s->T1= iso_clip(FFMAX(2, basic_t1/factor + 3*s->near), s->near+1, s->maxval); + if(s->T2==0 || reset_all) + s->T2= iso_clip(FFMAX(3, basic_t2/factor + 5*s->near), s->T1, s->maxval); + if(s->T3==0 || reset_all) + s->T3= iso_clip(FFMAX(4, basic_t3/factor + 6*s->near), s->T2, s->maxval); + } + + if(s->reset==0 || reset_all) s->reset= 64; +// av_log(NULL, AV_LOG_DEBUG, "[JPEG-LS RESET] T=%i,%i,%i\n", s->T1, s->T2, s->T3); +} diff --git a/contrib/ffmpeg/libavcodec/jpegls.h b/contrib/ffmpeg/libavcodec/jpegls.h new file mode 100644 index 000000000..792d2be3b --- /dev/null +++ b/contrib/ffmpeg/libavcodec/jpegls.h @@ -0,0 +1,111 @@ +/* + * JPEG-LS common code + * Copyright (c) 2003 Michael Niedermayer + * Copyright (c) 2006 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file jpegls.h + * JPEG-LS common code. + */ + +#ifndef FFMPEG_JPEGLS_H +#define FFMPEG_JPEGLS_H + +#include "avcodec.h" + +typedef struct JpeglsContext{ + AVCodecContext *avctx; + AVFrame picture; +}JpeglsContext; + +typedef struct JLSState{ + int T1, T2, T3; + int A[367], B[367], C[365], N[367]; + int limit, reset, bpp, qbpp, maxval, range; + int near, twonear; + int run_index[3]; +}JLSState; + +extern const uint8_t ff_log2_run[32]; + +/** + * Calculate initial JPEG-LS parameters + */ +void ff_jpegls_init_state(JLSState *state); + +/** + * Calculate quantized gradient value, used for context determination + */ +static inline int ff_jpegls_quantize(JLSState *s, int v){ //FIXME optimize + if(v==0) return 0; + if(v < 0){ + if(v <= -s->T3) return -4; + if(v <= -s->T2) return -3; + if(v <= -s->T1) return -2; + if(v < -s->near) return -1; + return 0; + }else{ + if(v <= s->near) return 0; + if(v < s->T1) return 1; + if(v < s->T2) return 2; + if(v < s->T3) return 3; + return 4; + } +} + +/** + * Calculate JPEG-LS codec values + */ +void ff_jpegls_reset_coding_parameters(JLSState *s, int reset_all); + + +static inline void ff_jpegls_downscale_state(JLSState *state, int Q){ + if(state->N[Q] == state->reset){ + state->A[Q] >>=1; + state->B[Q] >>=1; + state->N[Q] >>=1; + } + state->N[Q]++; +} + +static inline int ff_jpegls_update_state_regular(JLSState *state, int Q, int err){ + state->A[Q] += FFABS(err); + err *= state->twonear; + state->B[Q] += err; + + ff_jpegls_downscale_state(state, Q); + + if(state->B[Q] <= -state->N[Q]) { + state->B[Q]= FFMAX(state->B[Q] + state->N[Q], 1-state->N[Q]); + if(state->C[Q] > -128) + state->C[Q]--; + }else if(state->B[Q] > 0){ + state->B[Q]= FFMIN(state->B[Q] - state->N[Q], 0); + if(state->C[Q] < 127) + state->C[Q]++; + } + + return err; +} + +#define R(a, i ) (bits == 8 ? ((uint8_t*)(a))[i] : ((uint16_t*)(a))[i] ) +#define W(a, i, v) (bits == 8 ? (((uint8_t*)(a))[i]=v) : (((uint16_t*)(a))[i]=v)) + +#endif /* FFMPEG_JPEGLS_H */ diff --git a/contrib/ffmpeg/libavcodec/jpeglsdec.c b/contrib/ffmpeg/libavcodec/jpeglsdec.c new file mode 100644 index 000000000..ac40903da --- /dev/null +++ b/contrib/ffmpeg/libavcodec/jpeglsdec.c @@ -0,0 +1,375 @@ +/* + * JPEG-LS decoder + * Copyright (c) 2003 Michael Niedermayer + * Copyright (c) 2006 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file jpeglsdec.c + * JPEG-LS decoder. + */ + +#include "avcodec.h" +#include "bitstream.h" +#include "golomb.h" +#include "mjpeg.h" +#include "mjpegdec.h" +#include "jpegls.h" +#include "jpeglsdec.h" + + +/* +* Uncomment this to significantly speed up decoding of broken JPEG-LS +* (or test broken JPEG-LS decoder) and slow down ordinary decoding a bit. +* +* There is no Golomb code with length >= 32 bits possible, so check and +* avoid situation of 32 zeros, FFmpeg Golomb decoder is painfully slow +* on this errors. +*/ +//#define JLS_BROKEN + + +/** + * Decode LSE block with initialization parameters + */ +int ff_jpegls_decode_lse(MJpegDecodeContext *s) +{ + int len, id; + + /* XXX: verify len field validity */ + len = get_bits(&s->gb, 16); + id = get_bits(&s->gb, 8); + + switch(id){ + case 1: + s->maxval= get_bits(&s->gb, 16); + s->t1= get_bits(&s->gb, 16); + s->t2= get_bits(&s->gb, 16); + s->t3= get_bits(&s->gb, 16); + s->reset= get_bits(&s->gb, 16); + +// ff_jpegls_reset_coding_parameters(s, 0); + //FIXME quant table? + break; + case 2: + case 3: + av_log(s->avctx, AV_LOG_ERROR, "palette not supported\n"); + return -1; + case 4: + av_log(s->avctx, AV_LOG_ERROR, "oversize image not supported\n"); + return -1; + default: + av_log(s->avctx, AV_LOG_ERROR, "invalid id %d\n", id); + return -1; + } +// av_log(s->avctx, AV_LOG_DEBUG, "ID=%i, T=%i,%i,%i\n", id, s->t1, s->t2, s->t3); + + return 0; +} + +/** + * Get context-dependent Golomb code, decode it and update context + */ +static inline int ls_get_code_regular(GetBitContext *gb, JLSState *state, int Q){ + int k, ret; + + for(k = 0; (state->N[Q] << k) < state->A[Q]; k++); + +#ifdef JLS_BROKEN + if(!show_bits_long(gb, 32))return -1; +#endif + ret = get_ur_golomb_jpegls(gb, k, state->limit, state->qbpp); + + /* decode mapped error */ + if(ret & 1) + ret = -((ret + 1) >> 1); + else + ret >>= 1; + + /* for NEAR=0, k=0 and 2*B[Q] <= - N[Q] mapping is reversed */ + if(!state->near && !k && (2 * state->B[Q] <= -state->N[Q])) + ret = -(ret + 1); + + ret= ff_jpegls_update_state_regular(state, Q, ret); + + return ret; +} + +/** + * Get Golomb code, decode it and update state for run termination + */ +static inline int ls_get_code_runterm(GetBitContext *gb, JLSState *state, int RItype, int limit_add){ + int k, ret, temp, map; + int Q = 365 + RItype; + + temp= state->A[Q]; + if(RItype) + temp += state->N[Q] >> 1; + + for(k = 0; (state->N[Q] << k) < temp; k++); + +#ifdef JLS_BROKEN + if(!show_bits_long(gb, 32))return -1; +#endif + ret = get_ur_golomb_jpegls(gb, k, state->limit - limit_add - 1, state->qbpp); + + /* decode mapped error */ + map = 0; + if(!k && (RItype || ret) && (2 * state->B[Q] < state->N[Q])) + map = 1; + ret += RItype + map; + + if(ret & 1){ + ret = map - ((ret + 1) >> 1); + state->B[Q]++; + } else { + ret = ret >> 1; + } + + /* update state */ + state->A[Q] += FFABS(ret) - RItype; + ret *= state->twonear; + ff_jpegls_downscale_state(state, Q); + + return ret; +} + +/** + * Decode one line of image + */ +static inline void ls_decode_line(JLSState *state, MJpegDecodeContext *s, void *last, void *dst, int last2, int w, int stride, int comp, int bits){ + int i, x = 0; + int Ra, Rb, Rc, Rd; + int D0, D1, D2; + + while(x < w) { + int err, pred; + + /* compute gradients */ + Ra = x ? R(dst, x - stride) : R(last, x); + Rb = R(last, x); + Rc = x ? R(last, x - stride) : last2; + Rd = (x >= w - stride) ? R(last, x) : R(last, x + stride); + D0 = Rd - Rb; + D1 = Rb - Rc; + D2 = Rc - Ra; + /* run mode */ + if((FFABS(D0) <= state->near) && (FFABS(D1) <= state->near) && (FFABS(D2) <= state->near)) { + int r; + int RItype; + + /* decode full runs while available */ + while(get_bits1(&s->gb)) { + int r; + r = 1 << ff_log2_run[state->run_index[comp]]; + if(x + r * stride > w) { + r = (w - x) / stride; + } + for(i = 0; i < r; i++) { + W(dst, x, Ra); + x += stride; + } + /* if EOL reached, we stop decoding */ + if(r != (1 << ff_log2_run[state->run_index[comp]])) + return; + if(state->run_index[comp] < 31) + state->run_index[comp]++; + if(x + stride > w) + return; + } + /* decode aborted run */ + r = ff_log2_run[state->run_index[comp]]; + if(r) + r = get_bits_long(&s->gb, r); + for(i = 0; i < r; i++) { + W(dst, x, Ra); + x += stride; + } + + /* decode run termination value */ + Rb = R(last, x); + RItype = (FFABS(Ra - Rb) <= state->near) ? 1 : 0; + err = ls_get_code_runterm(&s->gb, state, RItype, ff_log2_run[state->run_index[comp]]); + if(state->run_index[comp]) + state->run_index[comp]--; + + if(state->near && RItype){ + pred = Ra + err; + } else { + if(Rb < Ra) + pred = Rb - err; + else + pred = Rb + err; + } + } else { /* regular mode */ + int context, sign; + + context = ff_jpegls_quantize(state, D0) * 81 + ff_jpegls_quantize(state, D1) * 9 + ff_jpegls_quantize(state, D2); + pred = mid_pred(Ra, Ra + Rb - Rc, Rb); + + if(context < 0){ + context = -context; + sign = 1; + }else{ + sign = 0; + } + + if(sign){ + pred = av_clip(pred - state->C[context], 0, state->maxval); + err = -ls_get_code_regular(&s->gb, state, context); + } else { + pred = av_clip(pred + state->C[context], 0, state->maxval); + err = ls_get_code_regular(&s->gb, state, context); + } + + /* we have to do something more for near-lossless coding */ + pred += err; + } + if(state->near){ + if(pred < -state->near) + pred += state->range * state->twonear; + else if(pred > state->maxval + state->near) + pred -= state->range * state->twonear; + pred = av_clip(pred, 0, state->maxval); + } + + pred &= state->maxval; + W(dst, x, pred); + x += stride; + } +} + +int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transform, int ilv){ + int i, t = 0; + uint8_t *zero, *last, *cur; + JLSState *state; + int off = 0, stride = 1, width, shift; + + zero = av_mallocz(s->picture.linesize[0]); + last = zero; + cur = s->picture.data[0]; + + state = av_mallocz(sizeof(JLSState)); + /* initialize JPEG-LS state from JPEG parameters */ + state->near = near; + state->bpp = (s->bits < 2) ? 2 : s->bits; + state->maxval = s->maxval; + state->T1 = s->t1; + state->T2 = s->t2; + state->T3 = s->t3; + state->reset = s->reset; + ff_jpegls_reset_coding_parameters(state, 0); + ff_jpegls_init_state(state); + + if(s->bits <= 8) + shift = point_transform + (8 - s->bits); + else + shift = point_transform + (16 - s->bits); + +// av_log(s->avctx, AV_LOG_DEBUG, "JPEG-LS params: %ix%i NEAR=%i MV=%i T(%i,%i,%i) RESET=%i, LIMIT=%i, qbpp=%i, RANGE=%i\n",s->width,s->height,state->near,state->maxval,state->T1,state->T2,state->T3,state->reset,state->limit,state->qbpp, state->range); +// av_log(s->avctx, AV_LOG_DEBUG, "JPEG params: ILV=%i Pt=%i BPP=%i, scan = %i\n", ilv, point_transform, s->bits, s->cur_scan); + if(ilv == 0) { /* separate planes */ + off = s->cur_scan - 1; + stride = (s->nb_components > 1) ? 3 : 1; + width = s->width * stride; + cur += off; + for(i = 0; i < s->height; i++) { + if(s->bits <= 8){ + ls_decode_line(state, s, last, cur, t, width, stride, off, 8); + t = last[0]; + }else{ + ls_decode_line(state, s, last, cur, t, width, stride, off, 16); + t = *((uint16_t*)last); + } + last = cur; + cur += s->picture.linesize[0]; + + if (s->restart_interval && !--s->restart_count) { + align_get_bits(&s->gb); + skip_bits(&s->gb, 16); /* skip RSTn */ + } + } + } else if(ilv == 1) { /* line interleaving */ + int j; + int Rc[3] = {0, 0, 0}; + memset(cur, 0, s->picture.linesize[0]); + width = s->width * 3; + for(i = 0; i < s->height; i++) { + for(j = 0; j < 3; j++) { + ls_decode_line(state, s, last + j, cur + j, Rc[j], width, 3, j, 8); + Rc[j] = last[j]; + + if (s->restart_interval && !--s->restart_count) { + align_get_bits(&s->gb); + skip_bits(&s->gb, 16); /* skip RSTn */ + } + } + last = cur; + cur += s->picture.linesize[0]; + } + } else if(ilv == 2) { /* sample interleaving */ + av_log(s->avctx, AV_LOG_ERROR, "Sample interleaved images are not supported.\n"); + av_free(state); + av_free(zero); + return -1; + } + + if(shift){ /* we need to do point transform or normalize samples */ + int x, w; + + w = s->width * s->nb_components; + + if(s->bits <= 8){ + uint8_t *src = s->picture.data[0]; + + for(i = 0; i < s->height; i++){ + for(x = off; x < w; x+= stride){ + src[x] <<= shift; + } + src += s->picture.linesize[0]; + } + }else{ + uint16_t *src = (uint16_t*) s->picture.data[0]; + + for(i = 0; i < s->height; i++){ + for(x = 0; x < w; x++){ + src[x] <<= shift; + } + src += s->picture.linesize[0]/2; + } + } + } + av_free(state); + av_free(zero); + + return 0; +} + + +AVCodec jpegls_decoder = { + "jpegls", + CODEC_TYPE_VIDEO, + CODEC_ID_JPEGLS, + sizeof(MJpegDecodeContext), + ff_mjpeg_decode_init, + NULL, + ff_mjpeg_decode_end, + ff_mjpeg_decode_frame, + CODEC_CAP_DR1, +}; diff --git a/contrib/ffmpeg/libavcodec/jpeglsdec.h b/contrib/ffmpeg/libavcodec/jpeglsdec.h new file mode 100644 index 000000000..362a0feb5 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/jpeglsdec.h @@ -0,0 +1,41 @@ +/* + * JPEG-LS decoder + * Copyright (c) 2003 Michael Niedermayer + * Copyright (c) 2006 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file jpeglsdec.h + * JPEG-LS decoder. + */ + +#ifndef FFMPEG_JPEGLSDEC_H +#define FFMPEG_JPEGLSDEC_H + +#include "mjpeg.h" +#include "mjpegdec.h" + +/** + * Decode LSE block with initialization parameters + */ +int ff_jpegls_decode_lse(MJpegDecodeContext *s); + +int ff_jpegls_decode_picture(MJpegDecodeContext *s, int near, int point_transform, int ilv); + +#endif /* FFMPEG_JPEGLSDEC_H */ diff --git a/contrib/ffmpeg/libavcodec/jpeglsenc.c b/contrib/ffmpeg/libavcodec/jpeglsenc.c new file mode 100644 index 000000000..a759a7048 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/jpeglsenc.c @@ -0,0 +1,393 @@ +/* + * JPEG-LS encoder + * Copyright (c) 2003 Michael Niedermayer + * Copyright (c) 2006 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file jpeglsenc.c + * JPEG-LS encoder. + */ + +#include "avcodec.h" +#include "bitstream.h" +#include "golomb.h" +#include "dsputil.h" +#include "mjpeg.h" +#include "jpegls.h" + + +/** + * Encode error from regular symbol + */ +static inline void ls_encode_regular(JLSState *state, PutBitContext *pb, int Q, int err){ + int k; + int val; + int map; + + for(k = 0; (state->N[Q] << k) < state->A[Q]; k++); + + map = !state->near && !k && (2 * state->B[Q] <= -state->N[Q]); + + if(err < 0) + err += state->range; + if(err >= ((state->range + 1) >> 1)) { + err -= state->range; + val = 2 * FFABS(err) - 1 - map; + } else + val = 2 * err + map; + + set_ur_golomb_jpegls(pb, val, k, state->limit, state->qbpp); + + ff_jpegls_update_state_regular(state, Q, err); +} + +/** + * Encode error from run termination + */ +static inline void ls_encode_runterm(JLSState *state, PutBitContext *pb, int RItype, int err, int limit_add){ + int k; + int val, map; + int Q = 365 + RItype; + int temp; + + temp = state->A[Q]; + if(RItype) + temp += state->N[Q] >> 1; + for(k = 0; (state->N[Q] << k) < temp; k++); + map = 0; + if(!k && err && (2 * state->B[Q] < state->N[Q])) + map = 1; + + if(err < 0) + val = - (2 * err) - 1 - RItype + map; + else + val = 2 * err - RItype - map; + set_ur_golomb_jpegls(pb, val, k, state->limit - limit_add - 1, state->qbpp); + + if(err < 0) + state->B[Q]++; + state->A[Q] += (val + 1 - RItype) >> 1; + + ff_jpegls_downscale_state(state, Q); +} + +/** + * Encode run value as specified by JPEG-LS standard + */ +static inline void ls_encode_run(JLSState *state, PutBitContext *pb, int run, int comp, int trail){ + while(run >= (1 << ff_log2_run[state->run_index[comp]])){ + put_bits(pb, 1, 1); + run -= 1 << ff_log2_run[state->run_index[comp]]; + if(state->run_index[comp] < 31) + state->run_index[comp]++; + } + /* if hit EOL, encode another full run, else encode aborted run */ + if(!trail && run) { + put_bits(pb, 1, 1); + }else if(trail){ + put_bits(pb, 1, 0); + if(ff_log2_run[state->run_index[comp]]) + put_bits(pb, ff_log2_run[state->run_index[comp]], run); + } +} + +/** + * Encode one line of image + */ +static inline void ls_encode_line(JLSState *state, PutBitContext *pb, void *last, void *cur, int last2, int w, int stride, int comp, int bits){ + int x = 0; + int Ra, Rb, Rc, Rd; + int D0, D1, D2; + + while(x < w) { + int err, pred, sign; + + /* compute gradients */ + Ra = x ? R(cur, x - stride) : R(last, x); + Rb = R(last, x); + Rc = x ? R(last, x - stride) : last2; + Rd = (x >= w - stride) ? R(last, x) : R(last, x + stride); + D0 = Rd - Rb; + D1 = Rb - Rc; + D2 = Rc - Ra; + + /* run mode */ + if((FFABS(D0) <= state->near) && (FFABS(D1) <= state->near) && (FFABS(D2) <= state->near)) { + int RUNval, RItype, run; + + run = 0; + RUNval = Ra; + while(x < w && (FFABS(R(cur, x) - RUNval) <= state->near)){ + run++; + W(cur, x, Ra); + x += stride; + } + ls_encode_run(state, pb, run, comp, x < w); + if(x >= w) + return; + Rb = R(last, x); + RItype = (FFABS(Ra - Rb) <= state->near); + pred = RItype ? Ra : Rb; + err = R(cur, x) - pred; + + if(!RItype && Ra > Rb) + err = -err; + + if(state->near){ + if(err > 0) + err = (state->near + err) / state->twonear; + else + err = -(state->near - err) / state->twonear; + + if(RItype || (Rb >= Ra)) + Ra = av_clip(pred + err * state->twonear, 0, state->maxval); + else + Ra = av_clip(pred - err * state->twonear, 0, state->maxval); + W(cur, x, Ra); + } + if(err < 0) + err += state->range; + if(err >= ((state->range + 1) >> 1)) + err -= state->range; + + ls_encode_runterm(state, pb, RItype, err, ff_log2_run[state->run_index[comp]]); + + if(state->run_index[comp] > 0) + state->run_index[comp]--; + } else { /* regular mode */ + int context; + + context = ff_jpegls_quantize(state, D0) * 81 + ff_jpegls_quantize(state, D1) * 9 + ff_jpegls_quantize(state, D2); + pred = mid_pred(Ra, Ra + Rb - Rc, Rb); + + if(context < 0){ + context = -context; + sign = 1; + pred = av_clip(pred - state->C[context], 0, state->maxval); + err = pred - R(cur, x); + }else{ + sign = 0; + pred = av_clip(pred + state->C[context], 0, state->maxval); + err = R(cur, x) - pred; + } + + if(state->near){ + if(err > 0) + err = (state->near + err) / state->twonear; + else + err = -(state->near - err) / state->twonear; + if(!sign) + Ra = av_clip(pred + err * state->twonear, 0, state->maxval); + else + Ra = av_clip(pred - err * state->twonear, 0, state->maxval); + W(cur, x, Ra); + } + + ls_encode_regular(state, pb, context, err); + } + x += stride; + } +} + +static void ls_store_lse(JLSState *state, PutBitContext *pb){ + /* Test if we have default params and don't need to store LSE */ + JLSState state2; + memset(&state2, 0, sizeof(JLSState)); + state2.bpp = state->bpp; + state2.near = state->near; + ff_jpegls_reset_coding_parameters(&state2, 1); + if(state->T1 == state2.T1 && state->T2 == state2.T2 && state->T3 == state2.T3 && state->reset == state2.reset) + return; + /* store LSE type 1 */ + put_marker(pb, LSE); + put_bits(pb, 16, 13); + put_bits(pb, 8, 1); + put_bits(pb, 16, state->maxval); + put_bits(pb, 16, state->T1); + put_bits(pb, 16, state->T2); + put_bits(pb, 16, state->T3); + put_bits(pb, 16, state->reset); +} + +static int encode_picture_ls(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ + JpeglsContext * const s = avctx->priv_data; + AVFrame *pict = data; + AVFrame * const p= (AVFrame*)&s->picture; + const int near = avctx->prediction_method; + PutBitContext pb, pb2; + GetBitContext gb; + uint8_t *buf2, *zero, *cur, *last; + JLSState *state; + int i, size; + int comps; + + buf2 = av_malloc(buf_size); + + init_put_bits(&pb, buf, buf_size); + init_put_bits(&pb2, buf2, buf_size); + + *p = *pict; + p->pict_type= FF_I_TYPE; + p->key_frame= 1; + + if(avctx->pix_fmt == PIX_FMT_GRAY8 || avctx->pix_fmt == PIX_FMT_GRAY16) + comps = 1; + else + comps = 3; + + /* write our own JPEG header, can't use mjpeg_picture_header */ + put_marker(&pb, SOI); + put_marker(&pb, SOF48); + put_bits(&pb, 16, 8 + comps * 3); // header size depends on components + put_bits(&pb, 8, (avctx->pix_fmt == PIX_FMT_GRAY16) ? 16 : 8); // bpp + put_bits(&pb, 16, avctx->height); + put_bits(&pb, 16, avctx->width); + put_bits(&pb, 8, comps); // components + for(i = 1; i <= comps; i++) { + put_bits(&pb, 8, i); // component ID + put_bits(&pb, 8, 0x11); // subsampling: none + put_bits(&pb, 8, 0); // Tiq, used by JPEG-LS ext + } + + put_marker(&pb, SOS); + put_bits(&pb, 16, 6 + comps * 2); + put_bits(&pb, 8, comps); + for(i = 1; i <= comps; i++) { + put_bits(&pb, 8, i); // component ID + put_bits(&pb, 8, 0); // mapping index: none + } + put_bits(&pb, 8, near); + put_bits(&pb, 8, (comps > 1) ? 1 : 0); // interleaving: 0 - plane, 1 - line + put_bits(&pb, 8, 0); // point transform: none + + state = av_mallocz(sizeof(JLSState)); + /* initialize JPEG-LS state from JPEG parameters */ + state->near = near; + state->bpp = (avctx->pix_fmt == PIX_FMT_GRAY16) ? 16 : 8; + ff_jpegls_reset_coding_parameters(state, 0); + ff_jpegls_init_state(state); + + ls_store_lse(state, &pb); + + zero = av_mallocz(p->linesize[0]); + last = zero; + cur = p->data[0]; + if(avctx->pix_fmt == PIX_FMT_GRAY8){ + int t = 0; + + for(i = 0; i < avctx->height; i++) { + ls_encode_line(state, &pb2, last, cur, t, avctx->width, 1, 0, 8); + t = last[0]; + last = cur; + cur += p->linesize[0]; + } + }else if(avctx->pix_fmt == PIX_FMT_GRAY16){ + int t = 0; + + for(i = 0; i < avctx->height; i++) { + ls_encode_line(state, &pb2, last, cur, t, avctx->width, 1, 0, 16); + t = *((uint16_t*)last); + last = cur; + cur += p->linesize[0]; + } + }else if(avctx->pix_fmt == PIX_FMT_RGB24){ + int j, width; + int Rc[3] = {0, 0, 0}; + + width = avctx->width * 3; + for(i = 0; i < avctx->height; i++) { + for(j = 0; j < 3; j++) { + ls_encode_line(state, &pb2, last + j, cur + j, Rc[j], width, 3, j, 8); + Rc[j] = last[j]; + } + last = cur; + cur += s->picture.linesize[0]; + } + }else if(avctx->pix_fmt == PIX_FMT_BGR24){ + int j, width; + int Rc[3] = {0, 0, 0}; + + width = avctx->width * 3; + for(i = 0; i < avctx->height; i++) { + for(j = 2; j >= 0; j--) { + ls_encode_line(state, &pb2, last + j, cur + j, Rc[j], width, 3, j, 8); + Rc[j] = last[j]; + } + last = cur; + cur += s->picture.linesize[0]; + } + } + + av_free(zero); + av_free(state); + + // the specification says that after doing 0xff escaping unused bits in the + // last byte must be set to 0, so just append 7 "optional" zero-bits to + // avoid special-casing. + put_bits(&pb2, 7, 0); + size = put_bits_count(&pb2); + flush_put_bits(&pb2); + /* do escape coding */ + init_get_bits(&gb, buf2, size); + size -= 7; + while(get_bits_count(&gb) < size){ + int v; + v = get_bits(&gb, 8); + put_bits(&pb, 8, v); + if(v == 0xFF){ + v = get_bits(&gb, 7); + put_bits(&pb, 8, v); + } + } + align_put_bits(&pb); + av_free(buf2); + + /* End of image */ + put_marker(&pb, EOI); + flush_put_bits(&pb); + + emms_c(); + + return put_bits_count(&pb) >> 3; +} + +static int encode_init_ls(AVCodecContext *ctx) { + JpeglsContext *c = (JpeglsContext*)ctx->priv_data; + + c->avctx = ctx; + ctx->coded_frame = &c->picture; + + if(ctx->pix_fmt != PIX_FMT_GRAY8 && ctx->pix_fmt != PIX_FMT_GRAY16 && ctx->pix_fmt != PIX_FMT_RGB24 && ctx->pix_fmt != PIX_FMT_BGR24){ + av_log(ctx, AV_LOG_ERROR, "Only grayscale and RGB24/BGR24 images are supported\n"); + return -1; + } + return 0; +} + +AVCodec jpegls_encoder = { //FIXME avoid MPV_* lossless JPEG should not need them + "jpegls", + CODEC_TYPE_VIDEO, + CODEC_ID_JPEGLS, + sizeof(JpeglsContext), + encode_init_ls, + encode_picture_ls, + NULL, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_RGB24, PIX_FMT_GRAY8, PIX_FMT_GRAY16, -1}, +}; diff --git a/contrib/ffmpeg/libavcodec/kmvc.c b/contrib/ffmpeg/libavcodec/kmvc.c index 08de05188..395ca2cb9 100644 --- a/contrib/ffmpeg/libavcodec/kmvc.c +++ b/contrib/ffmpeg/libavcodec/kmvc.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -28,8 +27,8 @@ #include #include -#include "common.h" #include "avcodec.h" +#include "bytestream.h" #define KMVC_KEYFRAME 0x80 #define KMVC_PALETTE 0x40 @@ -68,7 +67,7 @@ typedef struct BitBuf { } \ } -static void kmvc_decode_intra_8x8(KmvcContext * ctx, uint8_t * src, int w, int h) +static void kmvc_decode_intra_8x8(KmvcContext * ctx, const uint8_t * src, int w, int h) { BitBuf bb; int res, val; @@ -143,7 +142,7 @@ static void kmvc_decode_intra_8x8(KmvcContext * ctx, uint8_t * src, int w, int h } } -static void kmvc_decode_inter_8x8(KmvcContext * ctx, uint8_t * src, int w, int h) +static void kmvc_decode_inter_8x8(KmvcContext * ctx, const uint8_t * src, int w, int h) { BitBuf bb; int res, val; @@ -225,10 +224,10 @@ static void kmvc_decode_inter_8x8(KmvcContext * ctx, uint8_t * src, int w, int h } } -static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint8_t * buf, +static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, const uint8_t * buf, int buf_size) { - KmvcContext *const ctx = (KmvcContext *) avctx->priv_data; + KmvcContext *const ctx = avctx->priv_data; uint8_t *out, *src; int i; int header; @@ -250,7 +249,7 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint if (buf[0] == 127) { buf += 3; for (i = 0; i < 127; i++) { - ctx->pal[i + (header & 0x81)] = (buf[0] << 16) | (buf[1] << 8) | buf[2]; + ctx->pal[i + (header & 0x81)] = AV_RB24(buf); buf += 4; } buf -= 127 * 4 + 3; @@ -275,8 +274,7 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint ctx->pic.palette_has_changed = 1; // palette starts from index 1 and has 127 entries for (i = 1; i <= ctx->palsize; i++) { - ctx->pal[i] = (buf[0] << 16) | (buf[1] << 8) | buf[2]; - buf += 3; + ctx->pal[i] = bytestream_get_be24(&buf); } } @@ -342,7 +340,7 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, uint */ static int decode_init(AVCodecContext * avctx) { - KmvcContext *const c = (KmvcContext *) avctx->priv_data; + KmvcContext *const c = avctx->priv_data; int i; c->avctx = avctx; @@ -394,7 +392,7 @@ static int decode_init(AVCodecContext * avctx) */ static int decode_end(AVCodecContext * avctx) { - KmvcContext *const c = (KmvcContext *) avctx->priv_data; + KmvcContext *const c = avctx->priv_data; av_freep(&c->frm0); av_freep(&c->frm1); diff --git a/contrib/ffmpeg/libavcodec/lcl.c b/contrib/ffmpeg/libavcodec/lcl.c deleted file mode 100644 index b02ea1543..000000000 --- a/contrib/ffmpeg/libavcodec/lcl.c +++ /dev/null @@ -1,928 +0,0 @@ -/* - * LCL (LossLess Codec Library) Codec - * Copyright (c) 2002-2004 Roberto Togni - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -/** - * @file lcl.c - * LCL (LossLess Codec Library) Video Codec - * Decoder for MSZH and ZLIB codecs - * Experimental encoder for ZLIB RGB24 - * - * Fourcc: MSZH, ZLIB - * - * Original Win32 dll: - * Ver2.23 By Kenji Oshima 2000.09.20 - * avimszh.dll, avizlib.dll - * - * A description of the decoding algorithm can be found here: - * http://www.pcisys.net/~melanson/codecs - * - * Supports: BGR24 (RGB 24bpp) - * - */ - -#include -#include - -#include "common.h" -#include "bitstream.h" -#include "avcodec.h" - -#ifdef CONFIG_ZLIB -#include -#endif - - -#define BMPTYPE_YUV 1 -#define BMPTYPE_RGB 2 - -#define IMGTYPE_YUV111 0 -#define IMGTYPE_YUV422 1 -#define IMGTYPE_RGB24 2 -#define IMGTYPE_YUV411 3 -#define IMGTYPE_YUV211 4 -#define IMGTYPE_YUV420 5 - -#define COMP_MSZH 0 -#define COMP_MSZH_NOCOMP 1 -#define COMP_ZLIB_HISPEED 1 -#define COMP_ZLIB_HICOMP 9 -#define COMP_ZLIB_NORMAL -1 - -#define FLAG_MULTITHREAD 1 -#define FLAG_NULLFRAME 2 -#define FLAG_PNGFILTER 4 -#define FLAGMASK_UNUSED 0xf8 - -#define CODEC_MSZH 1 -#define CODEC_ZLIB 3 - -#define FOURCC_MSZH mmioFOURCC('M','S','Z','H') -#define FOURCC_ZLIB mmioFOURCC('Z','L','I','B') - -/* - * Decoder context - */ -typedef struct LclContext { - - AVCodecContext *avctx; - AVFrame pic; - PutBitContext pb; - - // Image type - int imgtype; - // Compression type - int compression; - // Flags - int flags; - // Decompressed data size - unsigned int decomp_size; - // Decompression buffer - unsigned char* decomp_buf; - // Maximum compressed data size - unsigned int max_comp_size; - // Compression buffer - unsigned char* comp_buf; -#ifdef CONFIG_ZLIB - z_stream zstream; -#endif -} LclContext; - - -/* - * - * Helper functions - * - */ -static inline unsigned char fix (int pix14) -{ - int tmp; - - tmp = (pix14 + 0x80000) >> 20; - if (tmp < 0) - return 0; - if (tmp > 255) - return 255; - return tmp; -} - - - -static inline unsigned char get_b (unsigned char yq, signed char bq) -{ - return fix((yq << 20) + bq * 1858076); -} - - - -static inline unsigned char get_g (unsigned char yq, signed char bq, signed char rq) -{ - return fix((yq << 20) - bq * 360857 - rq * 748830); -} - - - -static inline unsigned char get_r (unsigned char yq, signed char rq) -{ - return fix((yq << 20) + rq * 1470103); -} - - - -static unsigned int mszh_decomp(unsigned char * srcptr, int srclen, unsigned char * destptr, unsigned int destsize) -{ - unsigned char *destptr_bak = destptr; - unsigned char *destptr_end = destptr + destsize; - unsigned char mask = 0; - unsigned char maskbit = 0; - unsigned int ofs, cnt; - - while ((srclen > 0) && (destptr < destptr_end)) { - if (maskbit == 0) { - mask = *(srcptr++); - maskbit = 8; - srclen--; - continue; - } - if ((mask & (1 << (--maskbit))) == 0) { - if (destptr + 4 > destptr_end) - break; - *(int*)destptr = *(int*)srcptr; - srclen -= 4; - destptr += 4; - srcptr += 4; - } else { - ofs = *(srcptr++); - cnt = *(srcptr++); - ofs += cnt * 256;; - cnt = ((cnt >> 3) & 0x1f) + 1; - ofs &= 0x7ff; - srclen -= 2; - cnt *= 4; - if (destptr + cnt > destptr_end) { - cnt = destptr_end - destptr; - } - for (; cnt > 0; cnt--) { - *(destptr) = *(destptr - ofs); - destptr++; - } - } - } - - return (destptr - destptr_bak); -} - - - -#ifdef CONFIG_DECODERS -/* - * - * Decode a frame - * - */ -static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) -{ - LclContext * const c = (LclContext *)avctx->priv_data; - unsigned char *encoded = (unsigned char *)buf; - unsigned int pixel_ptr; - int row, col; - unsigned char *outptr; - unsigned int width = avctx->width; // Real image width - unsigned int height = avctx->height; // Real image height - unsigned int mszh_dlen; - unsigned char yq, y1q, uq, vq; - int uqvq; - unsigned int mthread_inlen, mthread_outlen; -#ifdef CONFIG_ZLIB - int zret; // Zlib return code -#endif - unsigned int len = buf_size; - - if(c->pic.data[0]) - avctx->release_buffer(avctx, &c->pic); - - c->pic.reference = 0; - c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; - if(avctx->get_buffer(avctx, &c->pic) < 0){ - av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; - } - - outptr = c->pic.data[0]; // Output image pointer - - /* Decompress frame */ - switch (avctx->codec_id) { - case CODEC_ID_MSZH: - switch (c->compression) { - case COMP_MSZH: - if (c->flags & FLAG_MULTITHREAD) { - mthread_inlen = *((unsigned int*)encoded); - mthread_outlen = *((unsigned int*)(encoded+4)); - if (mthread_outlen > c->decomp_size) // this should not happen - mthread_outlen = c->decomp_size; - mszh_dlen = mszh_decomp(encoded + 8, mthread_inlen, c->decomp_buf, c->decomp_size); - if (mthread_outlen != mszh_dlen) { - av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%d != %d)\n", - mthread_outlen, mszh_dlen); - return -1; - } - mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - mthread_inlen, - c->decomp_buf + mthread_outlen, c->decomp_size - mthread_outlen); - if (mthread_outlen != mszh_dlen) { - av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %d)\n", - mthread_outlen, mszh_dlen); - return -1; - } - encoded = c->decomp_buf; - len = c->decomp_size; - } else { - mszh_dlen = mszh_decomp(encoded, len, c->decomp_buf, c->decomp_size); - if (c->decomp_size != mszh_dlen) { - av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %d)\n", - c->decomp_size, mszh_dlen); - return -1; - } - encoded = c->decomp_buf; - len = mszh_dlen; - } - break; - case COMP_MSZH_NOCOMP: - break; - default: - av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n"); - return -1; - } - break; - case CODEC_ID_ZLIB: -#ifdef CONFIG_ZLIB - /* Using the original dll with normal compression (-1) and RGB format - * gives a file with ZLIB fourcc, but frame is really uncompressed. - * To be sure that's true check also frame size */ - if ((c->compression == COMP_ZLIB_NORMAL) && (c->imgtype == IMGTYPE_RGB24) && - (len == width * height * 3)) - break; - zret = inflateReset(&(c->zstream)); - if (zret != Z_OK) { - av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); - return -1; - } - if (c->flags & FLAG_MULTITHREAD) { - mthread_inlen = *((unsigned int*)encoded); - mthread_outlen = *((unsigned int*)(encoded+4)); - if (mthread_outlen > c->decomp_size) - mthread_outlen = c->decomp_size; - c->zstream.next_in = encoded + 8; - c->zstream.avail_in = mthread_inlen; - c->zstream.next_out = c->decomp_buf; - c->zstream.avail_out = c->decomp_size; - zret = inflate(&(c->zstream), Z_FINISH); - if ((zret != Z_OK) && (zret != Z_STREAM_END)) { - av_log(avctx, AV_LOG_ERROR, "Mthread1 inflate error: %d\n", zret); - return -1; - } - if (mthread_outlen != (unsigned int)(c->zstream.total_out)) { - av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%u != %lu)\n", - mthread_outlen, c->zstream.total_out); - return -1; - } - zret = inflateReset(&(c->zstream)); - if (zret != Z_OK) { - av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate reset error: %d\n", zret); - return -1; - } - c->zstream.next_in = encoded + 8 + mthread_inlen; - c->zstream.avail_in = len - mthread_inlen; - c->zstream.next_out = c->decomp_buf + mthread_outlen; - c->zstream.avail_out = c->decomp_size - mthread_outlen; - zret = inflate(&(c->zstream), Z_FINISH); - if ((zret != Z_OK) && (zret != Z_STREAM_END)) { - av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate error: %d\n", zret); - return -1; - } - if (mthread_outlen != (unsigned int)(c->zstream.total_out)) { - av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %lu)\n", - mthread_outlen, c->zstream.total_out); - return -1; - } - } else { - c->zstream.next_in = encoded; - c->zstream.avail_in = len; - c->zstream.next_out = c->decomp_buf; - c->zstream.avail_out = c->decomp_size; - zret = inflate(&(c->zstream), Z_FINISH); - if ((zret != Z_OK) && (zret != Z_STREAM_END)) { - av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret); - return -1; - } - if (c->decomp_size != (unsigned int)(c->zstream.total_out)) { - av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n", - c->decomp_size, c->zstream.total_out); - return -1; - } - } - encoded = c->decomp_buf; - len = c->decomp_size;; -#else - av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n"); - return -1; -#endif - break; - default: - av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n"); - return -1; - } - - - /* Apply PNG filter */ - if ((avctx->codec_id == CODEC_ID_ZLIB) && (c->flags & FLAG_PNGFILTER)) { - switch (c->imgtype) { - case IMGTYPE_YUV111: - case IMGTYPE_RGB24: - for (row = 0; row < height; row++) { - pixel_ptr = row * width * 3; - yq = encoded[pixel_ptr++]; - uqvq = encoded[pixel_ptr++]; - uqvq+=(encoded[pixel_ptr++] << 8); - for (col = 1; col < width; col++) { - encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; - uqvq -= (encoded[pixel_ptr+1] | (encoded[pixel_ptr+2]<<8)); - encoded[pixel_ptr+1] = (uqvq) & 0xff; - encoded[pixel_ptr+2] = ((uqvq)>>8) & 0xff; - pixel_ptr += 3; - } - } - break; - case IMGTYPE_YUV422: - for (row = 0; row < height; row++) { - pixel_ptr = row * width * 2; - yq = uq = vq =0; - for (col = 0; col < width/4; col++) { - encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; - encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; - encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; - encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; - encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; - encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5]; - encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6]; - encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7]; - pixel_ptr += 8; - } - } - break; - case IMGTYPE_YUV411: - for (row = 0; row < height; row++) { - pixel_ptr = row * width / 2 * 3; - yq = uq = vq =0; - for (col = 0; col < width/4; col++) { - encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; - encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; - encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; - encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; - encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; - encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; - pixel_ptr += 6; - } - } - break; - case IMGTYPE_YUV211: - for (row = 0; row < height; row++) { - pixel_ptr = row * width * 2; - yq = uq = vq =0; - for (col = 0; col < width/2; col++) { - encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; - encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; - encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2]; - encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3]; - pixel_ptr += 4; - } - } - break; - case IMGTYPE_YUV420: - for (row = 0; row < height/2; row++) { - pixel_ptr = row * width * 3; - yq = y1q = uq = vq =0; - for (col = 0; col < width/2; col++) { - encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; - encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; - encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2]; - encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3]; - encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; - encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; - pixel_ptr += 6; - } - } - break; - default: - av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n"); - return -1; - } - } - - /* Convert colorspace */ - switch (c->imgtype) { - case IMGTYPE_YUV111: - for (row = height - 1; row >= 0; row--) { - pixel_ptr = row * c->pic.linesize[0]; - for (col = 0; col < width; col++) { - outptr[pixel_ptr++] = get_b(encoded[0], encoded[1]); - outptr[pixel_ptr++] = get_g(encoded[0], encoded[1], encoded[2]); - outptr[pixel_ptr++] = get_r(encoded[0], encoded[2]); - encoded += 3; - } - } - break; - case IMGTYPE_YUV422: - for (row = height - 1; row >= 0; row--) { - pixel_ptr = row * c->pic.linesize[0]; - for (col = 0; col < width/4; col++) { - outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]); - outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[6]); - outptr[pixel_ptr++] = get_r(encoded[0], encoded[6]); - outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]); - outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[6]); - outptr[pixel_ptr++] = get_r(encoded[1], encoded[6]); - outptr[pixel_ptr++] = get_b(encoded[2], encoded[5]); - outptr[pixel_ptr++] = get_g(encoded[2], encoded[5], encoded[7]); - outptr[pixel_ptr++] = get_r(encoded[2], encoded[7]); - outptr[pixel_ptr++] = get_b(encoded[3], encoded[5]); - outptr[pixel_ptr++] = get_g(encoded[3], encoded[5], encoded[7]); - outptr[pixel_ptr++] = get_r(encoded[3], encoded[7]); - encoded += 8; - } - } - break; - case IMGTYPE_RGB24: - for (row = height - 1; row >= 0; row--) { - pixel_ptr = row * c->pic.linesize[0]; - for (col = 0; col < width; col++) { - outptr[pixel_ptr++] = encoded[0]; - outptr[pixel_ptr++] = encoded[1]; - outptr[pixel_ptr++] = encoded[2]; - encoded += 3; - } - } - break; - case IMGTYPE_YUV411: - for (row = height - 1; row >= 0; row--) { - pixel_ptr = row * c->pic.linesize[0]; - for (col = 0; col < width/4; col++) { - outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]); - outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[5]); - outptr[pixel_ptr++] = get_r(encoded[0], encoded[5]); - outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]); - outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[5]); - outptr[pixel_ptr++] = get_r(encoded[1], encoded[5]); - outptr[pixel_ptr++] = get_b(encoded[2], encoded[4]); - outptr[pixel_ptr++] = get_g(encoded[2], encoded[4], encoded[5]); - outptr[pixel_ptr++] = get_r(encoded[2], encoded[5]); - outptr[pixel_ptr++] = get_b(encoded[3], encoded[4]); - outptr[pixel_ptr++] = get_g(encoded[3], encoded[4], encoded[5]); - outptr[pixel_ptr++] = get_r(encoded[3], encoded[5]); - encoded += 6; - } - } - break; - case IMGTYPE_YUV211: - for (row = height - 1; row >= 0; row--) { - pixel_ptr = row * c->pic.linesize[0]; - for (col = 0; col < width/2; col++) { - outptr[pixel_ptr++] = get_b(encoded[0], encoded[2]); - outptr[pixel_ptr++] = get_g(encoded[0], encoded[2], encoded[3]); - outptr[pixel_ptr++] = get_r(encoded[0], encoded[3]); - outptr[pixel_ptr++] = get_b(encoded[1], encoded[2]); - outptr[pixel_ptr++] = get_g(encoded[1], encoded[2], encoded[3]); - outptr[pixel_ptr++] = get_r(encoded[1], encoded[3]); - encoded += 4; - } - } - break; - case IMGTYPE_YUV420: - for (row = height / 2 - 1; row >= 0; row--) { - pixel_ptr = 2 * row * c->pic.linesize[0]; - for (col = 0; col < width/2; col++) { - outptr[pixel_ptr] = get_b(encoded[0], encoded[4]); - outptr[pixel_ptr+1] = get_g(encoded[0], encoded[4], encoded[5]); - outptr[pixel_ptr+2] = get_r(encoded[0], encoded[5]); - outptr[pixel_ptr+3] = get_b(encoded[1], encoded[4]); - outptr[pixel_ptr+4] = get_g(encoded[1], encoded[4], encoded[5]); - outptr[pixel_ptr+5] = get_r(encoded[1], encoded[5]); - outptr[pixel_ptr-c->pic.linesize[0]] = get_b(encoded[2], encoded[4]); - outptr[pixel_ptr-c->pic.linesize[0]+1] = get_g(encoded[2], encoded[4], encoded[5]); - outptr[pixel_ptr-c->pic.linesize[0]+2] = get_r(encoded[2], encoded[5]); - outptr[pixel_ptr-c->pic.linesize[0]+3] = get_b(encoded[3], encoded[4]); - outptr[pixel_ptr-c->pic.linesize[0]+4] = get_g(encoded[3], encoded[4], encoded[5]); - outptr[pixel_ptr-c->pic.linesize[0]+5] = get_r(encoded[3], encoded[5]); - pixel_ptr += 6; - encoded += 6; - } - } - break; - default: - av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n"); - return -1; - } - - *data_size = sizeof(AVFrame); - *(AVFrame*)data = c->pic; - - /* always report that the buffer was completely consumed */ - return buf_size; -} -#endif - -#ifdef CONFIG_ENCODERS -/* - * - * Encode a frame - * - */ -static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ - LclContext *c = avctx->priv_data; - AVFrame *pict = data; - AVFrame * const p = &c->pic; - int i; - int zret; // Zlib return code - -#ifndef CONFIG_ZLIB - av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled in.\n"); - return -1; -#else - - init_put_bits(&c->pb, buf, buf_size); - - *p = *pict; - p->pict_type= FF_I_TYPE; - p->key_frame= 1; - - if(avctx->pix_fmt != PIX_FMT_BGR24){ - av_log(avctx, AV_LOG_ERROR, "Format not supported!\n"); - return -1; - } - - zret = deflateReset(&(c->zstream)); - if (zret != Z_OK) { - av_log(avctx, AV_LOG_ERROR, "Deflate reset error: %d\n", zret); - return -1; - } - c->zstream.next_out = c->comp_buf; - c->zstream.avail_out = c->max_comp_size; - - for(i = avctx->height - 1; i >= 0; i--) { - c->zstream.next_in = p->data[0]+p->linesize[0]*i; - c->zstream.avail_in = avctx->width*3; - zret = deflate(&(c->zstream), Z_NO_FLUSH); - if (zret != Z_OK) { - av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret); - return -1; - } - } - zret = deflate(&(c->zstream), Z_FINISH); - if (zret != Z_STREAM_END) { - av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret); - return -1; - } - - for (i = 0; i < c->zstream.total_out; i++) - put_bits(&c->pb, 8, c->comp_buf[i]); - flush_put_bits(&c->pb); - - return c->zstream.total_out; -#endif -} -#endif /* CONFIG_ENCODERS */ - -#ifdef CONFIG_DECODERS -/* - * - * Init lcl decoder - * - */ -static int decode_init(AVCodecContext *avctx) -{ - LclContext * const c = (LclContext *)avctx->priv_data; - unsigned int basesize = avctx->width * avctx->height; - unsigned int max_basesize = ((avctx->width + 3) & ~3) * ((avctx->height + 3) & ~3); - unsigned int max_decomp_size; - int zret; // Zlib return code - - c->avctx = avctx; - avctx->has_b_frames = 0; - - c->pic.data[0] = NULL; - -#ifdef CONFIG_ZLIB - // Needed if zlib unused or init aborted before inflateInit - memset(&(c->zstream), 0, sizeof(z_stream)); -#endif - - if (avctx->extradata_size < 8) { - av_log(avctx, AV_LOG_ERROR, "Extradata size too small.\n"); - return 1; - } - - if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { - return 1; - } - - /* Check codec type */ - if (((avctx->codec_id == CODEC_ID_MSZH) && (*((char *)avctx->extradata + 7) != CODEC_MSZH)) || - ((avctx->codec_id == CODEC_ID_ZLIB) && (*((char *)avctx->extradata + 7) != CODEC_ZLIB))) { - av_log(avctx, AV_LOG_ERROR, "Codec id and codec type mismatch. This should not happen.\n"); - } - - /* Detect image type */ - switch (c->imgtype = *((char *)avctx->extradata + 4)) { - case IMGTYPE_YUV111: - c->decomp_size = basesize * 3; - max_decomp_size = max_basesize * 3; - av_log(avctx, AV_LOG_INFO, "Image type is YUV 1:1:1.\n"); - break; - case IMGTYPE_YUV422: - c->decomp_size = basesize * 2; - max_decomp_size = max_basesize * 2; - av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:2:2.\n"); - break; - case IMGTYPE_RGB24: - c->decomp_size = basesize * 3; - max_decomp_size = max_basesize * 3; - av_log(avctx, AV_LOG_INFO, "Image type is RGB 24.\n"); - break; - case IMGTYPE_YUV411: - c->decomp_size = basesize / 2 * 3; - max_decomp_size = max_basesize / 2 * 3; - av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:1:1.\n"); - break; - case IMGTYPE_YUV211: - c->decomp_size = basesize * 2; - max_decomp_size = max_basesize * 2; - av_log(avctx, AV_LOG_INFO, "Image type is YUV 2:1:1.\n"); - break; - case IMGTYPE_YUV420: - c->decomp_size = basesize / 2 * 3; - max_decomp_size = max_basesize / 2 * 3; - av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:2:0.\n"); - break; - default: - av_log(avctx, AV_LOG_ERROR, "Unsupported image format %d.\n", c->imgtype); - return 1; - } - - /* Detect compression method */ - c->compression = *((char *)avctx->extradata + 5); - switch (avctx->codec_id) { - case CODEC_ID_MSZH: - switch (c->compression) { - case COMP_MSZH: - av_log(avctx, AV_LOG_INFO, "Compression enabled.\n"); - break; - case COMP_MSZH_NOCOMP: - c->decomp_size = 0; - av_log(avctx, AV_LOG_INFO, "No compression.\n"); - break; - default: - av_log(avctx, AV_LOG_ERROR, "Unsupported compression format for MSZH (%d).\n", c->compression); - return 1; - } - break; - case CODEC_ID_ZLIB: -#ifdef CONFIG_ZLIB - switch (c->compression) { - case COMP_ZLIB_HISPEED: - av_log(avctx, AV_LOG_INFO, "High speed compression.\n"); - break; - case COMP_ZLIB_HICOMP: - av_log(avctx, AV_LOG_INFO, "High compression.\n"); - break; - case COMP_ZLIB_NORMAL: - av_log(avctx, AV_LOG_INFO, "Normal compression.\n"); - break; - default: - if ((c->compression < Z_NO_COMPRESSION) || (c->compression > Z_BEST_COMPRESSION)) { - av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression); - return 1; - } - av_log(avctx, AV_LOG_INFO, "Compression level for ZLIB: (%d).\n", c->compression); - } -#else - av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n"); - return 1; -#endif - break; - default: - av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in compression switch.\n"); - return 1; - } - - /* Allocate decompression buffer */ - if (c->decomp_size) { - if ((c->decomp_buf = av_malloc(max_decomp_size)) == NULL) { - av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n"); - return 1; - } - } - - /* Detect flags */ - c->flags = *((char *)avctx->extradata + 6); - if (c->flags & FLAG_MULTITHREAD) - av_log(avctx, AV_LOG_INFO, "Multithread encoder flag set.\n"); - if (c->flags & FLAG_NULLFRAME) - av_log(avctx, AV_LOG_INFO, "Nullframe insertion flag set.\n"); - if ((avctx->codec_id == CODEC_ID_ZLIB) && (c->flags & FLAG_PNGFILTER)) - av_log(avctx, AV_LOG_INFO, "PNG filter flag set.\n"); - if (c->flags & FLAGMASK_UNUSED) - av_log(avctx, AV_LOG_ERROR, "Unknown flag set (%d).\n", c->flags); - - /* If needed init zlib */ - if (avctx->codec_id == CODEC_ID_ZLIB) { -#ifdef CONFIG_ZLIB - c->zstream.zalloc = Z_NULL; - c->zstream.zfree = Z_NULL; - c->zstream.opaque = Z_NULL; - zret = inflateInit(&(c->zstream)); - if (zret != Z_OK) { - av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); - return 1; - } -#else - av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n"); - return 1; -#endif - } - - avctx->pix_fmt = PIX_FMT_BGR24; - - return 0; -} -#endif /* CONFIG_DECODERS */ - -#ifdef CONFIG_ENCODERS -/* - * - * Init lcl encoder - * - */ -static int encode_init(AVCodecContext *avctx) -{ - LclContext *c = avctx->priv_data; - int zret; // Zlib return code - -#ifndef CONFIG_ZLIB - av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n"); - return 1; -#else - - c->avctx= avctx; - - assert(avctx->width && avctx->height); - - avctx->extradata= av_mallocz(8); - avctx->coded_frame= &c->pic; - - // Will be user settable someday - c->compression = 6; - c->flags = 0; - - switch(avctx->pix_fmt){ - case PIX_FMT_BGR24: - c->imgtype = IMGTYPE_RGB24; - c->decomp_size = avctx->width * avctx->height * 3; - avctx->bits_per_sample= 24; - break; - default: - av_log(avctx, AV_LOG_ERROR, "Format %d not supported\n", avctx->pix_fmt); - return -1; - } - - ((uint8_t*)avctx->extradata)[0]= 4; - ((uint8_t*)avctx->extradata)[1]= 0; - ((uint8_t*)avctx->extradata)[2]= 0; - ((uint8_t*)avctx->extradata)[3]= 0; - ((uint8_t*)avctx->extradata)[4]= c->imgtype; - ((uint8_t*)avctx->extradata)[5]= c->compression; - ((uint8_t*)avctx->extradata)[6]= c->flags; - ((uint8_t*)avctx->extradata)[7]= CODEC_ZLIB; - c->avctx->extradata_size= 8; - - c->zstream.zalloc = Z_NULL; - c->zstream.zfree = Z_NULL; - c->zstream.opaque = Z_NULL; - zret = deflateInit(&(c->zstream), c->compression); - if (zret != Z_OK) { - av_log(avctx, AV_LOG_ERROR, "Deflate init error: %d\n", zret); - return 1; - } - - /* Conservative upper bound taken from zlib v1.2.1 source */ - c->max_comp_size = c->decomp_size + ((c->decomp_size + 7) >> 3) + - ((c->decomp_size + 63) >> 6) + 11; - if ((c->comp_buf = av_malloc(c->max_comp_size)) == NULL) { - av_log(avctx, AV_LOG_ERROR, "Can't allocate compression buffer.\n"); - return 1; - } - - return 0; -#endif -} -#endif /* CONFIG_ENCODERS */ - - - -#ifdef CONFIG_DECODERS -/* - * - * Uninit lcl decoder - * - */ -static int decode_end(AVCodecContext *avctx) -{ - LclContext * const c = (LclContext *)avctx->priv_data; - - if (c->pic.data[0]) - avctx->release_buffer(avctx, &c->pic); -#ifdef CONFIG_ZLIB - inflateEnd(&(c->zstream)); -#endif - - return 0; -} -#endif - -#ifdef CONFIG_ENCODERS -/* - * - * Uninit lcl encoder - * - */ -static int encode_end(AVCodecContext *avctx) -{ - LclContext *c = avctx->priv_data; - - av_freep(&avctx->extradata); - av_freep(&c->comp_buf); -#ifdef CONFIG_ZLIB - deflateEnd(&(c->zstream)); -#endif - - return 0; -} -#endif - -#ifdef CONFIG_MSZH_DECODER -AVCodec mszh_decoder = { - "mszh", - CODEC_TYPE_VIDEO, - CODEC_ID_MSZH, - sizeof(LclContext), - decode_init, - NULL, - decode_end, - decode_frame, - CODEC_CAP_DR1, -}; -#endif - -#ifdef CONFIG_ZLIB_DECODER -AVCodec zlib_decoder = { - "zlib", - CODEC_TYPE_VIDEO, - CODEC_ID_ZLIB, - sizeof(LclContext), - decode_init, - NULL, - decode_end, - decode_frame, - CODEC_CAP_DR1, -}; -#endif - -#ifdef CONFIG_ENCODERS - -AVCodec zlib_encoder = { - "zlib", - CODEC_TYPE_VIDEO, - CODEC_ID_ZLIB, - sizeof(LclContext), - encode_init, - encode_frame, - encode_end, -}; - -#endif //CONFIG_ENCODERS diff --git a/contrib/ffmpeg/libavcodec/lcl.h b/contrib/ffmpeg/libavcodec/lcl.h new file mode 100644 index 000000000..7d5a76a78 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/lcl.h @@ -0,0 +1,49 @@ +/* + * LCL (LossLess Codec Library) Codec + * Copyright (c) 2002-2004 Roberto Togni + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_LCL_H +#define FFMPEG_LCL_H + +#define BMPTYPE_YUV 1 +#define BMPTYPE_RGB 2 + +#define IMGTYPE_YUV111 0 +#define IMGTYPE_YUV422 1 +#define IMGTYPE_RGB24 2 +#define IMGTYPE_YUV411 3 +#define IMGTYPE_YUV211 4 +#define IMGTYPE_YUV420 5 + +#define COMP_MSZH 0 +#define COMP_MSZH_NOCOMP 1 +#define COMP_ZLIB_HISPEED 1 +#define COMP_ZLIB_HICOMP 9 +#define COMP_ZLIB_NORMAL -1 + +#define FLAG_MULTITHREAD 1 +#define FLAG_NULLFRAME 2 +#define FLAG_PNGFILTER 4 +#define FLAGMASK_UNUSED 0xf8 + +#define CODEC_MSZH 1 +#define CODEC_ZLIB 3 + +#endif /* FFMPEG_LCL_H */ diff --git a/contrib/ffmpeg/libavcodec/lcldec.c b/contrib/ffmpeg/libavcodec/lcldec.c new file mode 100644 index 000000000..4abb0cd41 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/lcldec.c @@ -0,0 +1,715 @@ +/* + * LCL (LossLess Codec Library) Codec + * Copyright (c) 2002-2004 Roberto Togni + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file lcl.c + * LCL (LossLess Codec Library) Video Codec + * Decoder for MSZH and ZLIB codecs + * Experimental encoder for ZLIB RGB24 + * + * Fourcc: MSZH, ZLIB + * + * Original Win32 dll: + * Ver2.23 By Kenji Oshima 2000.09.20 + * avimszh.dll, avizlib.dll + * + * A description of the decoding algorithm can be found here: + * http://www.pcisys.net/~melanson/codecs + * + * Supports: BGR24 (RGB 24bpp) + * + */ + +#include +#include + +#include "avcodec.h" +#include "bitstream.h" +#include "lcl.h" + +#ifdef CONFIG_ZLIB +#include +#endif + +/* + * Decoder context + */ +typedef struct LclDecContext { + AVFrame pic; + + // Image type + int imgtype; + // Compression type + int compression; + // Flags + int flags; + // Decompressed data size + unsigned int decomp_size; + // Decompression buffer + unsigned char* decomp_buf; +#ifdef CONFIG_ZLIB + z_stream zstream; +#endif +} LclDecContext; + + +/* + * + * Helper functions + * + */ +static inline unsigned char fix (int pix14) +{ + int tmp; + + tmp = (pix14 + 0x80000) >> 20; + if (tmp < 0) + return 0; + if (tmp > 255) + return 255; + return tmp; +} + + + +static inline unsigned char get_b (unsigned char yq, signed char bq) +{ + return fix((yq << 20) + bq * 1858076); +} + + + +static inline unsigned char get_g (unsigned char yq, signed char bq, signed char rq) +{ + return fix((yq << 20) - bq * 360857 - rq * 748830); +} + + + +static inline unsigned char get_r (unsigned char yq, signed char rq) +{ + return fix((yq << 20) + rq * 1470103); +} + + + +static unsigned int mszh_decomp(unsigned char * srcptr, int srclen, unsigned char * destptr, unsigned int destsize) +{ + unsigned char *destptr_bak = destptr; + unsigned char *destptr_end = destptr + destsize; + unsigned char mask = 0; + unsigned char maskbit = 0; + unsigned int ofs, cnt; + + while ((srclen > 0) && (destptr < destptr_end)) { + if (maskbit == 0) { + mask = *(srcptr++); + maskbit = 8; + srclen--; + continue; + } + if ((mask & (1 << (--maskbit))) == 0) { + if (destptr + 4 > destptr_end) + break; + *(int*)destptr = *(int*)srcptr; + srclen -= 4; + destptr += 4; + srcptr += 4; + } else { + ofs = *(srcptr++); + cnt = *(srcptr++); + ofs += cnt * 256; + cnt = ((cnt >> 3) & 0x1f) + 1; + ofs &= 0x7ff; + srclen -= 2; + cnt *= 4; + if (destptr + cnt > destptr_end) { + cnt = destptr_end - destptr; + } + for (; cnt > 0; cnt--) { + *(destptr) = *(destptr - ofs); + destptr++; + } + } + } + + return (destptr - destptr_bak); +} + + + +/* + * + * Decode a frame + * + */ +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size) +{ + LclDecContext * const c = avctx->priv_data; + unsigned char *encoded = (unsigned char *)buf; + unsigned int pixel_ptr; + int row, col; + unsigned char *outptr; + unsigned int width = avctx->width; // Real image width + unsigned int height = avctx->height; // Real image height + unsigned int mszh_dlen; + unsigned char yq, y1q, uq, vq; + int uqvq; + unsigned int mthread_inlen, mthread_outlen; +#ifdef CONFIG_ZLIB + int zret; // Zlib return code +#endif + unsigned int len = buf_size; + + if(c->pic.data[0]) + avctx->release_buffer(avctx, &c->pic); + + c->pic.reference = 0; + c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; + if(avctx->get_buffer(avctx, &c->pic) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + + outptr = c->pic.data[0]; // Output image pointer + + /* Decompress frame */ + switch (avctx->codec_id) { + case CODEC_ID_MSZH: + switch (c->compression) { + case COMP_MSZH: + if (c->flags & FLAG_MULTITHREAD) { + mthread_inlen = *((unsigned int*)encoded); + mthread_outlen = *((unsigned int*)(encoded+4)); + if (mthread_outlen > c->decomp_size) // this should not happen + mthread_outlen = c->decomp_size; + mszh_dlen = mszh_decomp(encoded + 8, mthread_inlen, c->decomp_buf, c->decomp_size); + if (mthread_outlen != mszh_dlen) { + av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%d != %d)\n", + mthread_outlen, mszh_dlen); + return -1; + } + mszh_dlen = mszh_decomp(encoded + 8 + mthread_inlen, len - mthread_inlen, + c->decomp_buf + mthread_outlen, c->decomp_size - mthread_outlen); + if (mthread_outlen != mszh_dlen) { + av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %d)\n", + mthread_outlen, mszh_dlen); + return -1; + } + encoded = c->decomp_buf; + len = c->decomp_size; + } else { + mszh_dlen = mszh_decomp(encoded, len, c->decomp_buf, c->decomp_size); + if (c->decomp_size != mszh_dlen) { + av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %d)\n", + c->decomp_size, mszh_dlen); + return -1; + } + encoded = c->decomp_buf; + len = mszh_dlen; + } + break; + case COMP_MSZH_NOCOMP: + break; + default: + av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n"); + return -1; + } + break; + case CODEC_ID_ZLIB: +#ifdef CONFIG_ZLIB + /* Using the original dll with normal compression (-1) and RGB format + * gives a file with ZLIB fourcc, but frame is really uncompressed. + * To be sure that's true check also frame size */ + if ((c->compression == COMP_ZLIB_NORMAL) && (c->imgtype == IMGTYPE_RGB24) && + (len == width * height * 3)) + break; + zret = inflateReset(&(c->zstream)); + if (zret != Z_OK) { + av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); + return -1; + } + if (c->flags & FLAG_MULTITHREAD) { + mthread_inlen = *((unsigned int*)encoded); + mthread_outlen = *((unsigned int*)(encoded+4)); + if (mthread_outlen > c->decomp_size) + mthread_outlen = c->decomp_size; + c->zstream.next_in = encoded + 8; + c->zstream.avail_in = mthread_inlen; + c->zstream.next_out = c->decomp_buf; + c->zstream.avail_out = c->decomp_size; + zret = inflate(&(c->zstream), Z_FINISH); + if ((zret != Z_OK) && (zret != Z_STREAM_END)) { + av_log(avctx, AV_LOG_ERROR, "Mthread1 inflate error: %d\n", zret); + return -1; + } + if (mthread_outlen != (unsigned int)(c->zstream.total_out)) { + av_log(avctx, AV_LOG_ERROR, "Mthread1 decoded size differs (%u != %lu)\n", + mthread_outlen, c->zstream.total_out); + return -1; + } + zret = inflateReset(&(c->zstream)); + if (zret != Z_OK) { + av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate reset error: %d\n", zret); + return -1; + } + c->zstream.next_in = encoded + 8 + mthread_inlen; + c->zstream.avail_in = len - mthread_inlen; + c->zstream.next_out = c->decomp_buf + mthread_outlen; + c->zstream.avail_out = c->decomp_size - mthread_outlen; + zret = inflate(&(c->zstream), Z_FINISH); + if ((zret != Z_OK) && (zret != Z_STREAM_END)) { + av_log(avctx, AV_LOG_ERROR, "Mthread2 inflate error: %d\n", zret); + return -1; + } + if (mthread_outlen != (unsigned int)(c->zstream.total_out)) { + av_log(avctx, AV_LOG_ERROR, "Mthread2 decoded size differs (%d != %lu)\n", + mthread_outlen, c->zstream.total_out); + return -1; + } + } else { + c->zstream.next_in = encoded; + c->zstream.avail_in = len; + c->zstream.next_out = c->decomp_buf; + c->zstream.avail_out = c->decomp_size; + zret = inflate(&(c->zstream), Z_FINISH); + if ((zret != Z_OK) && (zret != Z_STREAM_END)) { + av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret); + return -1; + } + if (c->decomp_size != (unsigned int)(c->zstream.total_out)) { + av_log(avctx, AV_LOG_ERROR, "Decoded size differs (%d != %lu)\n", + c->decomp_size, c->zstream.total_out); + return -1; + } + } + encoded = c->decomp_buf; + len = c->decomp_size; +#else + av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n"); + return -1; +#endif + break; + default: + av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in frame decoder compression switch.\n"); + return -1; + } + + + /* Apply PNG filter */ + if ((avctx->codec_id == CODEC_ID_ZLIB) && (c->flags & FLAG_PNGFILTER)) { + switch (c->imgtype) { + case IMGTYPE_YUV111: + case IMGTYPE_RGB24: + for (row = 0; row < height; row++) { + pixel_ptr = row * width * 3; + yq = encoded[pixel_ptr++]; + uqvq = AV_RL16(encoded+pixel_ptr); + pixel_ptr += 2; + for (col = 1; col < width; col++) { + encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; + uqvq -= AV_RL16(encoded+pixel_ptr+1); + AV_WL16(encoded+pixel_ptr+1, uqvq); + pixel_ptr += 3; + } + } + break; + case IMGTYPE_YUV422: + for (row = 0; row < height; row++) { + pixel_ptr = row * width * 2; + yq = uq = vq =0; + for (col = 0; col < width/4; col++) { + encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; + encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; + encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; + encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; + encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; + encoded[pixel_ptr+5] = uq -= encoded[pixel_ptr+5]; + encoded[pixel_ptr+6] = vq -= encoded[pixel_ptr+6]; + encoded[pixel_ptr+7] = vq -= encoded[pixel_ptr+7]; + pixel_ptr += 8; + } + } + break; + case IMGTYPE_YUV411: + for (row = 0; row < height; row++) { + pixel_ptr = row * width / 2 * 3; + yq = uq = vq =0; + for (col = 0; col < width/4; col++) { + encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; + encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; + encoded[pixel_ptr+2] = yq -= encoded[pixel_ptr+2]; + encoded[pixel_ptr+3] = yq -= encoded[pixel_ptr+3]; + encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; + encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; + pixel_ptr += 6; + } + } + break; + case IMGTYPE_YUV211: + for (row = 0; row < height; row++) { + pixel_ptr = row * width * 2; + yq = uq = vq =0; + for (col = 0; col < width/2; col++) { + encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; + encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; + encoded[pixel_ptr+2] = uq -= encoded[pixel_ptr+2]; + encoded[pixel_ptr+3] = vq -= encoded[pixel_ptr+3]; + pixel_ptr += 4; + } + } + break; + case IMGTYPE_YUV420: + for (row = 0; row < height/2; row++) { + pixel_ptr = row * width * 3; + yq = y1q = uq = vq =0; + for (col = 0; col < width/2; col++) { + encoded[pixel_ptr] = yq -= encoded[pixel_ptr]; + encoded[pixel_ptr+1] = yq -= encoded[pixel_ptr+1]; + encoded[pixel_ptr+2] = y1q -= encoded[pixel_ptr+2]; + encoded[pixel_ptr+3] = y1q -= encoded[pixel_ptr+3]; + encoded[pixel_ptr+4] = uq -= encoded[pixel_ptr+4]; + encoded[pixel_ptr+5] = vq -= encoded[pixel_ptr+5]; + pixel_ptr += 6; + } + } + break; + default: + av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in pngfilter switch.\n"); + return -1; + } + } + + /* Convert colorspace */ + switch (c->imgtype) { + case IMGTYPE_YUV111: + for (row = height - 1; row >= 0; row--) { + pixel_ptr = row * c->pic.linesize[0]; + for (col = 0; col < width; col++) { + outptr[pixel_ptr++] = get_b(encoded[0], encoded[1]); + outptr[pixel_ptr++] = get_g(encoded[0], encoded[1], encoded[2]); + outptr[pixel_ptr++] = get_r(encoded[0], encoded[2]); + encoded += 3; + } + } + break; + case IMGTYPE_YUV422: + for (row = height - 1; row >= 0; row--) { + pixel_ptr = row * c->pic.linesize[0]; + for (col = 0; col < width/4; col++) { + outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]); + outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[6]); + outptr[pixel_ptr++] = get_r(encoded[0], encoded[6]); + outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]); + outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[6]); + outptr[pixel_ptr++] = get_r(encoded[1], encoded[6]); + outptr[pixel_ptr++] = get_b(encoded[2], encoded[5]); + outptr[pixel_ptr++] = get_g(encoded[2], encoded[5], encoded[7]); + outptr[pixel_ptr++] = get_r(encoded[2], encoded[7]); + outptr[pixel_ptr++] = get_b(encoded[3], encoded[5]); + outptr[pixel_ptr++] = get_g(encoded[3], encoded[5], encoded[7]); + outptr[pixel_ptr++] = get_r(encoded[3], encoded[7]); + encoded += 8; + } + } + break; + case IMGTYPE_RGB24: + for (row = height - 1; row >= 0; row--) { + pixel_ptr = row * c->pic.linesize[0]; + for (col = 0; col < width; col++) { + outptr[pixel_ptr++] = encoded[0]; + outptr[pixel_ptr++] = encoded[1]; + outptr[pixel_ptr++] = encoded[2]; + encoded += 3; + } + } + break; + case IMGTYPE_YUV411: + for (row = height - 1; row >= 0; row--) { + pixel_ptr = row * c->pic.linesize[0]; + for (col = 0; col < width/4; col++) { + outptr[pixel_ptr++] = get_b(encoded[0], encoded[4]); + outptr[pixel_ptr++] = get_g(encoded[0], encoded[4], encoded[5]); + outptr[pixel_ptr++] = get_r(encoded[0], encoded[5]); + outptr[pixel_ptr++] = get_b(encoded[1], encoded[4]); + outptr[pixel_ptr++] = get_g(encoded[1], encoded[4], encoded[5]); + outptr[pixel_ptr++] = get_r(encoded[1], encoded[5]); + outptr[pixel_ptr++] = get_b(encoded[2], encoded[4]); + outptr[pixel_ptr++] = get_g(encoded[2], encoded[4], encoded[5]); + outptr[pixel_ptr++] = get_r(encoded[2], encoded[5]); + outptr[pixel_ptr++] = get_b(encoded[3], encoded[4]); + outptr[pixel_ptr++] = get_g(encoded[3], encoded[4], encoded[5]); + outptr[pixel_ptr++] = get_r(encoded[3], encoded[5]); + encoded += 6; + } + } + break; + case IMGTYPE_YUV211: + for (row = height - 1; row >= 0; row--) { + pixel_ptr = row * c->pic.linesize[0]; + for (col = 0; col < width/2; col++) { + outptr[pixel_ptr++] = get_b(encoded[0], encoded[2]); + outptr[pixel_ptr++] = get_g(encoded[0], encoded[2], encoded[3]); + outptr[pixel_ptr++] = get_r(encoded[0], encoded[3]); + outptr[pixel_ptr++] = get_b(encoded[1], encoded[2]); + outptr[pixel_ptr++] = get_g(encoded[1], encoded[2], encoded[3]); + outptr[pixel_ptr++] = get_r(encoded[1], encoded[3]); + encoded += 4; + } + } + break; + case IMGTYPE_YUV420: + for (row = height / 2 - 1; row >= 0; row--) { + pixel_ptr = 2 * row * c->pic.linesize[0]; + for (col = 0; col < width/2; col++) { + outptr[pixel_ptr] = get_b(encoded[0], encoded[4]); + outptr[pixel_ptr+1] = get_g(encoded[0], encoded[4], encoded[5]); + outptr[pixel_ptr+2] = get_r(encoded[0], encoded[5]); + outptr[pixel_ptr+3] = get_b(encoded[1], encoded[4]); + outptr[pixel_ptr+4] = get_g(encoded[1], encoded[4], encoded[5]); + outptr[pixel_ptr+5] = get_r(encoded[1], encoded[5]); + outptr[pixel_ptr-c->pic.linesize[0]] = get_b(encoded[2], encoded[4]); + outptr[pixel_ptr-c->pic.linesize[0]+1] = get_g(encoded[2], encoded[4], encoded[5]); + outptr[pixel_ptr-c->pic.linesize[0]+2] = get_r(encoded[2], encoded[5]); + outptr[pixel_ptr-c->pic.linesize[0]+3] = get_b(encoded[3], encoded[4]); + outptr[pixel_ptr-c->pic.linesize[0]+4] = get_g(encoded[3], encoded[4], encoded[5]); + outptr[pixel_ptr-c->pic.linesize[0]+5] = get_r(encoded[3], encoded[5]); + pixel_ptr += 6; + encoded += 6; + } + } + break; + default: + av_log(avctx, AV_LOG_ERROR, "BUG! Unknown imagetype in image decoder.\n"); + return -1; + } + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = c->pic; + + /* always report that the buffer was completely consumed */ + return buf_size; +} + +/* + * + * Init lcl decoder + * + */ +static int decode_init(AVCodecContext *avctx) +{ + LclDecContext * const c = avctx->priv_data; + unsigned int basesize = avctx->width * avctx->height; + unsigned int max_basesize = ((avctx->width + 3) & ~3) * ((avctx->height + 3) & ~3); + unsigned int max_decomp_size; + int zret; // Zlib return code + + c->pic.data[0] = NULL; + +#ifdef CONFIG_ZLIB + // Needed if zlib unused or init aborted before inflateInit + memset(&(c->zstream), 0, sizeof(z_stream)); +#endif + + if (avctx->extradata_size < 8) { + av_log(avctx, AV_LOG_ERROR, "Extradata size too small.\n"); + return 1; + } + + if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { + return 1; + } + + /* Check codec type */ + if (((avctx->codec_id == CODEC_ID_MSZH) && (*((char *)avctx->extradata + 7) != CODEC_MSZH)) || + ((avctx->codec_id == CODEC_ID_ZLIB) && (*((char *)avctx->extradata + 7) != CODEC_ZLIB))) { + av_log(avctx, AV_LOG_ERROR, "Codec id and codec type mismatch. This should not happen.\n"); + } + + /* Detect image type */ + switch (c->imgtype = *((char *)avctx->extradata + 4)) { + case IMGTYPE_YUV111: + c->decomp_size = basesize * 3; + max_decomp_size = max_basesize * 3; + av_log(avctx, AV_LOG_INFO, "Image type is YUV 1:1:1.\n"); + break; + case IMGTYPE_YUV422: + c->decomp_size = basesize * 2; + max_decomp_size = max_basesize * 2; + av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:2:2.\n"); + break; + case IMGTYPE_RGB24: + c->decomp_size = basesize * 3; + max_decomp_size = max_basesize * 3; + av_log(avctx, AV_LOG_INFO, "Image type is RGB 24.\n"); + break; + case IMGTYPE_YUV411: + c->decomp_size = basesize / 2 * 3; + max_decomp_size = max_basesize / 2 * 3; + av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:1:1.\n"); + break; + case IMGTYPE_YUV211: + c->decomp_size = basesize * 2; + max_decomp_size = max_basesize * 2; + av_log(avctx, AV_LOG_INFO, "Image type is YUV 2:1:1.\n"); + break; + case IMGTYPE_YUV420: + c->decomp_size = basesize / 2 * 3; + max_decomp_size = max_basesize / 2 * 3; + av_log(avctx, AV_LOG_INFO, "Image type is YUV 4:2:0.\n"); + break; + default: + av_log(avctx, AV_LOG_ERROR, "Unsupported image format %d.\n", c->imgtype); + return 1; + } + + /* Detect compression method */ + c->compression = *((char *)avctx->extradata + 5); + switch (avctx->codec_id) { + case CODEC_ID_MSZH: + switch (c->compression) { + case COMP_MSZH: + av_log(avctx, AV_LOG_INFO, "Compression enabled.\n"); + break; + case COMP_MSZH_NOCOMP: + c->decomp_size = 0; + av_log(avctx, AV_LOG_INFO, "No compression.\n"); + break; + default: + av_log(avctx, AV_LOG_ERROR, "Unsupported compression format for MSZH (%d).\n", c->compression); + return 1; + } + break; + case CODEC_ID_ZLIB: +#ifdef CONFIG_ZLIB + switch (c->compression) { + case COMP_ZLIB_HISPEED: + av_log(avctx, AV_LOG_INFO, "High speed compression.\n"); + break; + case COMP_ZLIB_HICOMP: + av_log(avctx, AV_LOG_INFO, "High compression.\n"); + break; + case COMP_ZLIB_NORMAL: + av_log(avctx, AV_LOG_INFO, "Normal compression.\n"); + break; + default: + if ((c->compression < Z_NO_COMPRESSION) || (c->compression > Z_BEST_COMPRESSION)) { + av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression); + return 1; + } + av_log(avctx, AV_LOG_INFO, "Compression level for ZLIB: (%d).\n", c->compression); + } +#else + av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n"); + return 1; +#endif + break; + default: + av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in compression switch.\n"); + return 1; + } + + /* Allocate decompression buffer */ + if (c->decomp_size) { + if ((c->decomp_buf = av_malloc(max_decomp_size)) == NULL) { + av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n"); + return 1; + } + } + + /* Detect flags */ + c->flags = *((char *)avctx->extradata + 6); + if (c->flags & FLAG_MULTITHREAD) + av_log(avctx, AV_LOG_INFO, "Multithread encoder flag set.\n"); + if (c->flags & FLAG_NULLFRAME) + av_log(avctx, AV_LOG_INFO, "Nullframe insertion flag set.\n"); + if ((avctx->codec_id == CODEC_ID_ZLIB) && (c->flags & FLAG_PNGFILTER)) + av_log(avctx, AV_LOG_INFO, "PNG filter flag set.\n"); + if (c->flags & FLAGMASK_UNUSED) + av_log(avctx, AV_LOG_ERROR, "Unknown flag set (%d).\n", c->flags); + + /* If needed init zlib */ + if (avctx->codec_id == CODEC_ID_ZLIB) { +#ifdef CONFIG_ZLIB + c->zstream.zalloc = Z_NULL; + c->zstream.zfree = Z_NULL; + c->zstream.opaque = Z_NULL; + zret = inflateInit(&(c->zstream)); + if (zret != Z_OK) { + av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); + return 1; + } +#else + av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n"); + return 1; +#endif + } + + avctx->pix_fmt = PIX_FMT_BGR24; + + return 0; +} + +/* + * + * Uninit lcl decoder + * + */ +static int decode_end(AVCodecContext *avctx) +{ + LclDecContext * const c = avctx->priv_data; + + if (c->pic.data[0]) + avctx->release_buffer(avctx, &c->pic); +#ifdef CONFIG_ZLIB + inflateEnd(&(c->zstream)); +#endif + + return 0; +} + +#ifdef CONFIG_MSZH_DECODER +AVCodec mszh_decoder = { + "mszh", + CODEC_TYPE_VIDEO, + CODEC_ID_MSZH, + sizeof(LclDecContext), + decode_init, + NULL, + decode_end, + decode_frame, + CODEC_CAP_DR1, +}; +#endif + +#ifdef CONFIG_ZLIB_DECODER +AVCodec zlib_decoder = { + "zlib", + CODEC_TYPE_VIDEO, + CODEC_ID_ZLIB, + sizeof(LclDecContext), + decode_init, + NULL, + decode_end, + decode_frame, + CODEC_CAP_DR1, +}; +#endif diff --git a/contrib/ffmpeg/libavcodec/lclenc.c b/contrib/ffmpeg/libavcodec/lclenc.c new file mode 100644 index 000000000..e8349052a --- /dev/null +++ b/contrib/ffmpeg/libavcodec/lclenc.c @@ -0,0 +1,231 @@ +/* + * LCL (LossLess Codec Library) Codec + * Copyright (c) 2002-2004 Roberto Togni + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file lcl.c + * LCL (LossLess Codec Library) Video Codec + * Decoder for MSZH and ZLIB codecs + * Experimental encoder for ZLIB RGB24 + * + * Fourcc: MSZH, ZLIB + * + * Original Win32 dll: + * Ver2.23 By Kenji Oshima 2000.09.20 + * avimszh.dll, avizlib.dll + * + * A description of the decoding algorithm can be found here: + * http://www.pcisys.net/~melanson/codecs + * + * Supports: BGR24 (RGB 24bpp) + * + */ + +#include +#include + +#include "avcodec.h" +#include "bitstream.h" +#include "lcl.h" + +#ifdef CONFIG_ZLIB +#include +#endif + +/* + * Decoder context + */ +typedef struct LclEncContext { + + AVCodecContext *avctx; + AVFrame pic; + PutBitContext pb; + + // Image type + int imgtype; + // Compression type + int compression; + // Flags + int flags; + // Decompressed data size + unsigned int decomp_size; + // Maximum compressed data size + unsigned int max_comp_size; + // Compression buffer + unsigned char* comp_buf; +#ifdef CONFIG_ZLIB + z_stream zstream; +#endif +} LclEncContext; + +/* + * + * Encode a frame + * + */ +static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ + LclEncContext *c = avctx->priv_data; + AVFrame *pict = data; + AVFrame * const p = &c->pic; + int i; + int zret; // Zlib return code + +#ifndef CONFIG_ZLIB + av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled in.\n"); + return -1; +#else + + init_put_bits(&c->pb, buf, buf_size); + + *p = *pict; + p->pict_type= FF_I_TYPE; + p->key_frame= 1; + + if(avctx->pix_fmt != PIX_FMT_BGR24){ + av_log(avctx, AV_LOG_ERROR, "Format not supported!\n"); + return -1; + } + + zret = deflateReset(&(c->zstream)); + if (zret != Z_OK) { + av_log(avctx, AV_LOG_ERROR, "Deflate reset error: %d\n", zret); + return -1; + } + c->zstream.next_out = c->comp_buf; + c->zstream.avail_out = c->max_comp_size; + + for(i = avctx->height - 1; i >= 0; i--) { + c->zstream.next_in = p->data[0]+p->linesize[0]*i; + c->zstream.avail_in = avctx->width*3; + zret = deflate(&(c->zstream), Z_NO_FLUSH); + if (zret != Z_OK) { + av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret); + return -1; + } + } + zret = deflate(&(c->zstream), Z_FINISH); + if (zret != Z_STREAM_END) { + av_log(avctx, AV_LOG_ERROR, "Deflate error: %d\n", zret); + return -1; + } + + for (i = 0; i < c->zstream.total_out; i++) + put_bits(&c->pb, 8, c->comp_buf[i]); + flush_put_bits(&c->pb); + + return c->zstream.total_out; +#endif +} + +/* + * + * Init lcl encoder + * + */ +static int encode_init(AVCodecContext *avctx) +{ + LclEncContext *c = avctx->priv_data; + int zret; // Zlib return code + +#ifndef CONFIG_ZLIB + av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n"); + return 1; +#else + + c->avctx= avctx; + + assert(avctx->width && avctx->height); + + avctx->extradata= av_mallocz(8); + avctx->coded_frame= &c->pic; + + // Will be user settable someday + c->compression = 6; + c->flags = 0; + + switch(avctx->pix_fmt){ + case PIX_FMT_BGR24: + c->imgtype = IMGTYPE_RGB24; + c->decomp_size = avctx->width * avctx->height * 3; + avctx->bits_per_sample= 24; + break; + default: + av_log(avctx, AV_LOG_ERROR, "Format %d not supported\n", avctx->pix_fmt); + return -1; + } + + ((uint8_t*)avctx->extradata)[0]= 4; + ((uint8_t*)avctx->extradata)[1]= 0; + ((uint8_t*)avctx->extradata)[2]= 0; + ((uint8_t*)avctx->extradata)[3]= 0; + ((uint8_t*)avctx->extradata)[4]= c->imgtype; + ((uint8_t*)avctx->extradata)[5]= c->compression; + ((uint8_t*)avctx->extradata)[6]= c->flags; + ((uint8_t*)avctx->extradata)[7]= CODEC_ZLIB; + c->avctx->extradata_size= 8; + + c->zstream.zalloc = Z_NULL; + c->zstream.zfree = Z_NULL; + c->zstream.opaque = Z_NULL; + zret = deflateInit(&(c->zstream), c->compression); + if (zret != Z_OK) { + av_log(avctx, AV_LOG_ERROR, "Deflate init error: %d\n", zret); + return 1; + } + + /* Conservative upper bound taken from zlib v1.2.1 source */ + c->max_comp_size = c->decomp_size + ((c->decomp_size + 7) >> 3) + + ((c->decomp_size + 63) >> 6) + 11; + if ((c->comp_buf = av_malloc(c->max_comp_size)) == NULL) { + av_log(avctx, AV_LOG_ERROR, "Can't allocate compression buffer.\n"); + return 1; + } + + return 0; +#endif +} + +/* + * + * Uninit lcl encoder + * + */ +static int encode_end(AVCodecContext *avctx) +{ + LclEncContext *c = avctx->priv_data; + + av_freep(&avctx->extradata); + av_freep(&c->comp_buf); +#ifdef CONFIG_ZLIB + deflateEnd(&(c->zstream)); +#endif + + return 0; +} + +AVCodec zlib_encoder = { + "zlib", + CODEC_TYPE_VIDEO, + CODEC_ID_ZLIB, + sizeof(LclEncContext), + encode_init, + encode_frame, + encode_end, +}; diff --git a/contrib/ffmpeg/libavcodec/liba52.c b/contrib/ffmpeg/libavcodec/liba52.c new file mode 100644 index 000000000..86b013602 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/liba52.c @@ -0,0 +1,225 @@ +/* + * A52 decoder using liba52 + * Copyright (c) 2001 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file a52dec.c + * A52 decoder using liba52 + */ + +#include "avcodec.h" +#include + +#ifdef CONFIG_LIBA52BIN +#include +static const char* liba52name = "liba52.so.0"; +#endif + +/** + * liba52 - Copyright (C) Aaron Holtzman + * released under the GPL license. + */ +typedef struct AC3DecodeState { + int flags; + int channels; + a52_state_t* state; + sample_t* samples; + + /* + * virtual method table + * + * using this function table so the liba52 doesn't + * have to be really linked together with ffmpeg + * and might be linked in runtime - this allows binary + * distribution of ffmpeg library which doens't depend + * on liba52 library - but if user has it installed + * it will be used - user might install such library + * separately + */ + void* handle; + a52_state_t* (*a52_init)(uint32_t mm_accel); + sample_t* (*a52_samples)(a52_state_t * state); + int (*a52_syncinfo)(uint8_t * buf, int * flags, + int * sample_rate, int * bit_rate); + int (*a52_frame)(a52_state_t * state, uint8_t * buf, int * flags, + sample_t * level, sample_t bias); + void (*a52_dynrng)(a52_state_t * state, + sample_t (* call) (sample_t, void *), void * data); + int (*a52_block)(a52_state_t * state); + void (*a52_free)(a52_state_t * state); + +} AC3DecodeState; + +#ifdef CONFIG_LIBA52BIN +static void* dlsymm(void* handle, const char* symbol) +{ + void* f = dlsym(handle, symbol); + if (!f) + av_log( NULL, AV_LOG_ERROR, "A52 Decoder - function '%s' can't be resolved\n", symbol); + return f; +} +#endif + +static int a52_decode_init(AVCodecContext *avctx) +{ + AC3DecodeState *s = avctx->priv_data; + +#ifdef CONFIG_LIBA52BIN + s->handle = dlopen(liba52name, RTLD_LAZY); + if (!s->handle) + { + av_log( avctx, AV_LOG_ERROR, "A52 library %s could not be opened! \n%s\n", liba52name, dlerror()); + return -1; + } + s->a52_init = (a52_state_t* (*)(uint32_t)) dlsymm(s->handle, "a52_init"); + s->a52_samples = (sample_t* (*)(a52_state_t*)) dlsymm(s->handle, "a52_samples"); + s->a52_syncinfo = (int (*)(uint8_t*, int*, int*, int*)) dlsymm(s->handle, "a52_syncinfo"); + s->a52_frame = (int (*)(a52_state_t*, uint8_t*, int*, sample_t*, sample_t)) dlsymm(s->handle, "a52_frame"); + s->a52_block = (int (*)(a52_state_t*)) dlsymm(s->handle, "a52_block"); + s->a52_free = (void (*)(a52_state_t*)) dlsymm(s->handle, "a52_free"); + if (!s->a52_init || !s->a52_samples || !s->a52_syncinfo + || !s->a52_frame || !s->a52_block || !s->a52_free) + { + dlclose(s->handle); + return -1; + } +#else + s->handle = 0; + s->a52_init = a52_init; + s->a52_samples = a52_samples; + s->a52_syncinfo = a52_syncinfo; + s->a52_frame = a52_frame; + s->a52_block = a52_block; + s->a52_free = a52_free; +#endif + s->state = s->a52_init(0); /* later use CPU flags */ + s->samples = s->a52_samples(s->state); + + /* allow downmixing to stereo or mono */ + if (avctx->channels > 0 && avctx->request_channels > 0 && + avctx->request_channels < avctx->channels && + avctx->request_channels <= 2) { + avctx->channels = avctx->request_channels; + } + + return 0; +} + +/**** the following function comes from a52dec */ +static inline void float_to_int (float * _f, int16_t * s16, int nchannels) +{ + int i, j, c; + int32_t * f = (int32_t *) _f; // XXX assumes IEEE float format + + j = 0; + nchannels *= 256; + for (i = 0; i < 256; i++) { + for (c = 0; c < nchannels; c += 256) + s16[j++] = av_clip_int16(f[i + c] - 0x43c00000); + } +} + +/**** end */ + +#define HEADER_SIZE 7 + +static int a52_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + uint8_t *buf, int buf_size) +{ + AC3DecodeState *s = avctx->priv_data; + int flags, i, len; + int sample_rate, bit_rate; + short *out_samples = data; + float level; + static const int ac3_channels[8] = { + 2, 1, 2, 3, 3, 4, 4, 5 + }; + + *data_size= 0; + + if (buf_size < HEADER_SIZE) { + av_log(avctx, AV_LOG_ERROR, "Error decoding frame, not enough bytes for header\n"); + return -1; + } + len = s->a52_syncinfo(buf, &s->flags, &sample_rate, &bit_rate); + if (len == 0) { + av_log(avctx, AV_LOG_ERROR, "Error decoding frame, no sync byte at begin\n"); + return -1; + } + if (buf_size < len) { + av_log(avctx, AV_LOG_ERROR, "Error decoding frame, not enough bytes\n"); + return -1; + } + /* update codec info */ + avctx->sample_rate = sample_rate; + s->channels = ac3_channels[s->flags & 7]; + if (s->flags & A52_LFE) + s->channels++; + if (avctx->request_channels > 0 && + avctx->request_channels <= 2 && + avctx->request_channels < s->channels) { + avctx->channels = avctx->request_channels; + } else { + avctx->channels = s->channels; + } + avctx->bit_rate = bit_rate; + flags = s->flags; + if (avctx->channels == 1) + flags = A52_MONO; + else if (avctx->channels == 2) + flags = A52_STEREO; + else + flags |= A52_ADJUST_LEVEL; + level = 1; + if (s->a52_frame(s->state, buf, &flags, &level, 384)) { + fail: + av_log(avctx, AV_LOG_ERROR, "Error decoding frame\n"); + return -1; + } + for (i = 0; i < 6; i++) { + if (s->a52_block(s->state)) + goto fail; + float_to_int(s->samples, out_samples + i * 256 * avctx->channels, avctx->channels); + } + *data_size = 6 * avctx->channels * 256 * sizeof(int16_t); + return len; +} + +static int a52_decode_end(AVCodecContext *avctx) +{ + AC3DecodeState *s = avctx->priv_data; + s->a52_free(s->state); +#ifdef CONFIG_LIBA52BIN + dlclose(s->handle); +#endif + return 0; +} + +AVCodec liba52_decoder = { + "liba52", + CODEC_TYPE_AUDIO, + CODEC_ID_AC3, + sizeof(AC3DecodeState), + a52_decode_init, + NULL, + a52_decode_end, + a52_decode_frame, +}; diff --git a/contrib/ffmpeg/libavcodec/libamr.c b/contrib/ffmpeg/libavcodec/libamr.c new file mode 100644 index 000000000..5a5145060 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/libamr.c @@ -0,0 +1,712 @@ +/* + * AMR Audio decoder stub + * Copyright (c) 2003 the ffmpeg project + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + /** @file + * Adaptive Multi-Rate (AMR) Audio decoder stub. + * + * This code implements both an AMR-NarrowBand (AMR-NB) and an AMR-WideBand + * (AMR-WB) audio encoder/decoder through external reference code from + * http://www.3gpp.org/. The license of the code from 3gpp is unclear so you + * have to download the code separately. Two versions exists: One fixed-point + * and one floating-point. For some reason the float encoder is significantly + * faster at least on a P4 1.5GHz (0.9s instead of 9.9s on a 30s audio clip + * at MR102). Both float and fixed point are supported for AMR-NB, but only + * float for AMR-WB. + * + * \section AMR-NB + * + * \subsection Float + * The float version (default) can be downloaded from: + * http://www.3gpp.org/ftp/Specs/archive/26_series/26.104/26104-610.zip + * + * \subsection Fixed-point + * The fixed-point (TS26.073) can be downloaded from: + * http://www.3gpp.org/ftp/Specs/archive/26_series/26.073/26073-600.zip + * + * \subsection Specification + * The specification for AMR-NB can be found in TS 26.071 + * (http://www.3gpp.org/ftp/Specs/html-info/26071.htm) and some other + * info at http://www.3gpp.org/ftp/Specs/html-info/26-series.htm. + * + * \section AMR-WB + * + * \subsection Float + * The reference code can be downloaded from: + * http://www.3gpp.org/ftp/Specs/archive/26_series/26.204/26204-600.zip + * + * \subsection Fixed-point + * If someone wants to use the fixed point version it can be downloaded from: + * http://www.3gpp.org/ftp/Specs/archive/26_series/26.173/26173-571.zip. + * + * \subsection Specification + * The specification for AMR-WB can be found in TS 26.171 + * (http://www.3gpp.org/ftp/Specs/html-info/26171.htm) and some other + * info at http://www.3gpp.org/ftp/Specs/html-info/26-series.htm. + * + */ + +#include "avcodec.h" + +#ifdef CONFIG_LIBAMR_NB_FIXED + +#define MMS_IO + +#include "amr/sp_dec.h" +#include "amr/d_homing.h" +#include "amr/typedef.h" +#include "amr/sp_enc.h" +#include "amr/sid_sync.h" +#include "amr/e_homing.h" + +#else +#include +#include +#endif + +static const char *nb_bitrate_unsupported = + "bitrate not supported: use one of 4.75k, 5.15k, 5.9k, 6.7k, 7.4k, 7.95k, 10.2k or 12.2k\n"; +static const char *wb_bitrate_unsupported = + "bitrate not supported: use one of 6.6k, 8.85k, 12.65k, 14.25k, 15.85k, 18.25k, 19.85k, 23.05k, or 23.85k\n"; + +/* Common code for fixed and float version*/ +typedef struct AMR_bitrates +{ + int rate; + enum Mode mode; +} AMR_bitrates; + +/* Match desired bitrate */ +static int getBitrateMode(int bitrate) +{ + /* make the correspondance between bitrate and mode */ + AMR_bitrates rates[]={ {4750,MR475}, + {5150,MR515}, + {5900,MR59}, + {6700,MR67}, + {7400,MR74}, + {7950,MR795}, + {10200,MR102}, + {12200,MR122}, + }; + int i; + + for(i=0;i<8;i++) + { + if(rates[i].rate==bitrate) + { + return(rates[i].mode); + } + } + /* no bitrate matching, return an error */ + return -1; +} + +static void amr_decode_fix_avctx(AVCodecContext * avctx) +{ + const int is_amr_wb = 1 + (avctx->codec_id == CODEC_ID_AMR_WB); + + if(avctx->sample_rate == 0) + { + avctx->sample_rate = 8000 * is_amr_wb; + } + + if(avctx->channels == 0) + { + avctx->channels = 1; + } + + avctx->frame_size = 160 * is_amr_wb; +} + +#ifdef CONFIG_LIBAMR_NB_FIXED +/* fixed point version*/ +/* frame size in serial bitstream file (frame type + serial stream + flags) */ +#define SERIAL_FRAMESIZE (1+MAX_SERIAL_SIZE+5) + +typedef struct AMRContext { + int frameCount; + Speech_Decode_FrameState *speech_decoder_state; + enum RXFrameType rx_type; + enum Mode mode; + Word16 reset_flag; + Word16 reset_flag_old; + + int enc_bitrate; + Speech_Encode_FrameState *enstate; + sid_syncState *sidstate; + enum TXFrameType tx_frametype; +} AMRContext; + +static int amr_nb_decode_init(AVCodecContext * avctx) +{ + AMRContext *s = avctx->priv_data; + + s->frameCount=0; + s->speech_decoder_state=NULL; + s->rx_type = (enum RXFrameType)0; + s->mode= (enum Mode)0; + s->reset_flag=0; + s->reset_flag_old=1; + + if(Speech_Decode_Frame_init(&s->speech_decoder_state, "Decoder")) + { + av_log(avctx, AV_LOG_ERROR, "Speech_Decode_Frame_init error\n"); + return -1; + } + + amr_decode_fix_avctx(avctx); + + if(avctx->channels > 1) + { + av_log(avctx, AV_LOG_ERROR, "amr_nb: multichannel decoding not supported\n"); + return -1; + } + + return 0; +} + +static int amr_nb_encode_init(AVCodecContext * avctx) +{ + AMRContext *s = avctx->priv_data; + + s->frameCount=0; + s->speech_decoder_state=NULL; + s->rx_type = (enum RXFrameType)0; + s->mode= (enum Mode)0; + s->reset_flag=0; + s->reset_flag_old=1; + + if(avctx->sample_rate!=8000) + { + av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n"); + return -1; + } + + if(avctx->channels!=1) + { + av_log(avctx, AV_LOG_ERROR, "Only mono supported\n"); + return -1; + } + + avctx->frame_size=160; + avctx->coded_frame= avcodec_alloc_frame(); + + if(Speech_Encode_Frame_init(&s->enstate, 0, "encoder") || sid_sync_init (&s->sidstate)) + { + av_log(avctx, AV_LOG_ERROR, "Speech_Encode_Frame_init error\n"); + return -1; + } + + if((s->enc_bitrate=getBitrateMode(avctx->bit_rate))<0) + { + av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported); + return -1; + } + + return 0; +} + +static int amr_nb_encode_close(AVCodecContext * avctx) +{ + AMRContext *s = avctx->priv_data; + + Speech_Encode_Frame_exit(&s->enstate); + sid_sync_exit (&s->sidstate); + av_freep(&avctx->coded_frame); + return 0; +} + +static int amr_nb_decode_close(AVCodecContext * avctx) +{ + AMRContext *s = avctx->priv_data; + + Speech_Decode_Frame_exit(&s->speech_decoder_state); + return 0; +} + +static int amr_nb_decode_frame(AVCodecContext * avctx, + void *data, int *data_size, + uint8_t * buf, int buf_size) +{ + AMRContext *s = avctx->priv_data; + uint8_t*amrData=buf; + int offset=0; + UWord8 toc, q, ft; + Word16 serial[SERIAL_FRAMESIZE]; /* coded bits */ + Word16 *synth; + UWord8 *packed_bits; + static Word16 packed_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0}; + int i; + + //printf("amr_decode_frame data_size=%i buf=0x%X buf_size=%d frameCount=%d!!\n",*data_size,buf,buf_size,s->frameCount); + + synth=data; + + toc=amrData[offset]; + /* read rest of the frame based on ToC byte */ + q = (toc >> 2) & 0x01; + ft = (toc >> 3) & 0x0F; + + //printf("offset=%d, packet_size=%d amrData= 0x%X %X %X %X\n",offset,packed_size[ft],amrData[offset],amrData[offset+1],amrData[offset+2],amrData[offset+3]); + + offset++; + + packed_bits=amrData+offset; + + offset+=packed_size[ft]; + + //Unsort and unpack bits + s->rx_type = UnpackBits(q, ft, packed_bits, &s->mode, &serial[1]); + + //We have a new frame + s->frameCount++; + + if (s->rx_type == RX_NO_DATA) + { + s->mode = s->speech_decoder_state->prev_mode; + } + else { + s->speech_decoder_state->prev_mode = s->mode; + } + + /* if homed: check if this frame is another homing frame */ + if (s->reset_flag_old == 1) + { + /* only check until end of first subframe */ + s->reset_flag = decoder_homing_frame_test_first(&serial[1], s->mode); + } + /* produce encoder homing frame if homed & input=decoder homing frame */ + if ((s->reset_flag != 0) && (s->reset_flag_old != 0)) + { + for (i = 0; i < L_FRAME; i++) + { + synth[i] = EHF_MASK; + } + } + else + { + /* decode frame */ + Speech_Decode_Frame(s->speech_decoder_state, s->mode, &serial[1], s->rx_type, synth); + } + + //Each AMR-frame results in 160 16-bit samples + *data_size=160*2; + + /* if not homed: check whether current frame is a homing frame */ + if (s->reset_flag_old == 0) + { + /* check whole frame */ + s->reset_flag = decoder_homing_frame_test(&serial[1], s->mode); + } + /* reset decoder if current frame is a homing frame */ + if (s->reset_flag != 0) + { + Speech_Decode_Frame_reset(s->speech_decoder_state); + } + s->reset_flag_old = s->reset_flag; + + return offset; +} + + +static int amr_nb_encode_frame(AVCodecContext *avctx, + unsigned char *frame/*out*/, int buf_size, void *data/*in*/) +{ + short serial_data[250] = {0}; + AMRContext *s = avctx->priv_data; + int written; + + s->reset_flag = encoder_homing_frame_test(data); + + Speech_Encode_Frame(s->enstate, s->enc_bitrate, data, &serial_data[1], &s->mode); + + /* add frame type and mode */ + sid_sync (s->sidstate, s->mode, &s->tx_frametype); + + written = PackBits(s->mode, s->enc_bitrate, s->tx_frametype, &serial_data[1], frame); + + if (s->reset_flag != 0) + { + Speech_Encode_Frame_reset(s->enstate); + sid_sync_reset(s->sidstate); + } + return written; +} + + +#elif defined(CONFIG_LIBAMR_NB) /* Float point version*/ + +typedef struct AMRContext { + int frameCount; + void * decState; + int *enstate; + int enc_bitrate; +} AMRContext; + +static int amr_nb_decode_init(AVCodecContext * avctx) +{ + AMRContext *s = avctx->priv_data; + + s->frameCount=0; + s->decState=Decoder_Interface_init(); + if(!s->decState) + { + av_log(avctx, AV_LOG_ERROR, "Decoder_Interface_init error\r\n"); + return -1; + } + + amr_decode_fix_avctx(avctx); + + if(avctx->channels > 1) + { + av_log(avctx, AV_LOG_ERROR, "amr_nb: multichannel decoding not supported\n"); + return -1; + } + + return 0; +} + +static int amr_nb_encode_init(AVCodecContext * avctx) +{ + AMRContext *s = avctx->priv_data; + + s->frameCount=0; + + if(avctx->sample_rate!=8000) + { + av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n"); + return -1; + } + + if(avctx->channels!=1) + { + av_log(avctx, AV_LOG_ERROR, "Only mono supported\n"); + return -1; + } + + avctx->frame_size=160; + avctx->coded_frame= avcodec_alloc_frame(); + + s->enstate=Encoder_Interface_init(0); + if(!s->enstate) + { + av_log(avctx, AV_LOG_ERROR, "Encoder_Interface_init error\n"); + return -1; + } + + if((s->enc_bitrate=getBitrateMode(avctx->bit_rate))<0) + { + av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported); + return -1; + } + + return 0; +} + +static int amr_nb_decode_close(AVCodecContext * avctx) +{ + AMRContext *s = avctx->priv_data; + + Decoder_Interface_exit(s->decState); + return 0; +} + +static int amr_nb_encode_close(AVCodecContext * avctx) +{ + AMRContext *s = avctx->priv_data; + + Encoder_Interface_exit(s->enstate); + av_freep(&avctx->coded_frame); + return 0; +} + +static int amr_nb_decode_frame(AVCodecContext * avctx, + void *data, int *data_size, + uint8_t * buf, int buf_size) +{ + AMRContext *s = avctx->priv_data; + uint8_t*amrData=buf; + static const uint8_t block_size[16]={ 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 }; + enum Mode dec_mode; + int packet_size; + + /* av_log(NULL,AV_LOG_DEBUG,"amr_decode_frame buf=%p buf_size=%d frameCount=%d!!\n",buf,buf_size,s->frameCount); */ + + dec_mode = (buf[0] >> 3) & 0x000F; + packet_size = block_size[dec_mode]+1; + + if(packet_size > buf_size) { + av_log(avctx, AV_LOG_ERROR, "amr frame too short (%u, should be %u)\n", buf_size, packet_size); + return -1; + } + + s->frameCount++; + /* av_log(NULL,AV_LOG_DEBUG,"packet_size=%d amrData= 0x%X %X %X %X\n",packet_size,amrData[0],amrData[1],amrData[2],amrData[3]); */ + /* call decoder */ + Decoder_Interface_Decode(s->decState, amrData, data, 0); + *data_size=160*2; + + return packet_size; +} + +static int amr_nb_encode_frame(AVCodecContext *avctx, + unsigned char *frame/*out*/, int buf_size, void *data/*in*/) +{ + AMRContext *s = avctx->priv_data; + int written; + + if((s->enc_bitrate=getBitrateMode(avctx->bit_rate))<0) + { + av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported); + return -1; + } + + written = Encoder_Interface_Encode(s->enstate, + s->enc_bitrate, + data, + frame, + 0); + /* av_log(NULL,AV_LOG_DEBUG,"amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n",written, s->enc_bitrate, frame[0] ); */ + + return written; +} + +#endif + +#if defined(CONFIG_LIBAMR_NB) || defined(CONFIG_LIBAMR_NB_FIXED) + +AVCodec libamr_nb_decoder = +{ + "libamr_nb", + CODEC_TYPE_AUDIO, + CODEC_ID_AMR_NB, + sizeof(AMRContext), + amr_nb_decode_init, + NULL, + amr_nb_decode_close, + amr_nb_decode_frame, +}; + +AVCodec libamr_nb_encoder = +{ + "libamr_nb", + CODEC_TYPE_AUDIO, + CODEC_ID_AMR_NB, + sizeof(AMRContext), + amr_nb_encode_init, + amr_nb_encode_frame, + amr_nb_encode_close, + NULL, +}; + +#endif + +/* -----------AMR wideband ------------*/ +#ifdef CONFIG_LIBAMR_WB + +#ifdef _TYPEDEF_H +//To avoid duplicate typedefs from typedef in amr-nb +#define typedef_h +#endif + +#include +#include +#include + +/* Common code for fixed and float version*/ +typedef struct AMRWB_bitrates +{ + int rate; + int mode; +} AMRWB_bitrates; + +static int getWBBitrateMode(int bitrate) +{ + /* make the correspondance between bitrate and mode */ + AMRWB_bitrates rates[]={ {6600,0}, + {8850,1}, + {12650,2}, + {14250,3}, + {15850,4}, + {18250,5}, + {19850,6}, + {23050,7}, + {23850,8}, + }; + int i; + + for(i=0;i<9;i++) + { + if(rates[i].rate==bitrate) + { + return(rates[i].mode); + } + } + /* no bitrate matching, return an error */ + return -1; +} + + +typedef struct AMRWBContext { + int frameCount; + void *state; + int mode; + Word16 allow_dtx; +} AMRWBContext; + +static int amr_wb_encode_init(AVCodecContext * avctx) +{ + AMRWBContext *s = avctx->priv_data; + + s->frameCount=0; + + if(avctx->sample_rate!=16000) + { + av_log(avctx, AV_LOG_ERROR, "Only 16000Hz sample rate supported\n"); + return -1; + } + + if(avctx->channels!=1) + { + av_log(avctx, AV_LOG_ERROR, "Only mono supported\n"); + return -1; + } + + if((s->mode=getWBBitrateMode(avctx->bit_rate))<0) + { + av_log(avctx, AV_LOG_ERROR, wb_bitrate_unsupported); + return -1; + } + + avctx->frame_size=320; + avctx->coded_frame= avcodec_alloc_frame(); + + s->state = E_IF_init(); + s->allow_dtx=0; + + return 0; +} + +static int amr_wb_encode_close(AVCodecContext * avctx) +{ + AMRWBContext *s = avctx->priv_data; + + E_IF_exit(s->state); + av_freep(&avctx->coded_frame); + s->frameCount++; + return 0; +} + +static int amr_wb_encode_frame(AVCodecContext *avctx, + unsigned char *frame/*out*/, int buf_size, void *data/*in*/) +{ + AMRWBContext *s = avctx->priv_data; + int size; + + if((s->mode=getWBBitrateMode(avctx->bit_rate))<0) + { + av_log(avctx, AV_LOG_ERROR, wb_bitrate_unsupported); + return -1; + } + size = E_IF_encode(s->state, s->mode, data, frame, s->allow_dtx); + return size; +} + +static int amr_wb_decode_init(AVCodecContext * avctx) +{ + AMRWBContext *s = avctx->priv_data; + + s->frameCount=0; + s->state = D_IF_init(); + + amr_decode_fix_avctx(avctx); + + if(avctx->channels > 1) + { + av_log(avctx, AV_LOG_ERROR, "amr_wb: multichannel decoding not supported\n"); + return -1; + } + + return 0; +} + +static int amr_wb_decode_frame(AVCodecContext * avctx, + void *data, int *data_size, + uint8_t * buf, int buf_size) +{ + AMRWBContext *s = avctx->priv_data; + uint8_t*amrData=buf; + int mode; + int packet_size; + static const uint8_t block_size[16] = {18, 23, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1}; + + if(buf_size==0) { + /* nothing to do */ + return 0; + } + + mode = (amrData[0] >> 3) & 0x000F; + packet_size = block_size[mode]; + + if(packet_size > buf_size) { + av_log(avctx, AV_LOG_ERROR, "amr frame too short (%u, should be %u)\n", buf_size, packet_size+1); + return -1; + } + + s->frameCount++; + D_IF_decode( s->state, amrData, data, _good_frame); + *data_size=320*2; + return packet_size; +} + +static int amr_wb_decode_close(AVCodecContext * avctx) +{ + AMRWBContext *s = avctx->priv_data; + + D_IF_exit(s->state); + return 0; +} + +AVCodec libamr_wb_decoder = +{ + "libamr_wb", + CODEC_TYPE_AUDIO, + CODEC_ID_AMR_WB, + sizeof(AMRWBContext), + amr_wb_decode_init, + NULL, + amr_wb_decode_close, + amr_wb_decode_frame, +}; + +AVCodec libamr_wb_encoder = +{ + "libamr_wb", + CODEC_TYPE_AUDIO, + CODEC_ID_AMR_WB, + sizeof(AMRWBContext), + amr_wb_encode_init, + amr_wb_encode_frame, + amr_wb_encode_close, + NULL, +}; + +#endif //CONFIG_LIBAMR_WB diff --git a/contrib/ffmpeg/libavcodec/libfaac.c b/contrib/ffmpeg/libavcodec/libfaac.c new file mode 100644 index 000000000..e2802b398 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/libfaac.c @@ -0,0 +1,154 @@ +/* + * Interface to libfaac for aac encoding + * Copyright (c) 2002 Gildas Bazin + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file libfaac.c + * Interface to libfaac for aac encoding. + */ + +#include "avcodec.h" +#include + +typedef struct FaacAudioContext { + faacEncHandle faac_handle; +} FaacAudioContext; + +static int Faac_encode_init(AVCodecContext *avctx) +{ + FaacAudioContext *s = avctx->priv_data; + faacEncConfigurationPtr faac_cfg; + unsigned long samples_input, max_bytes_output; + + /* number of channels */ + if (avctx->channels < 1 || avctx->channels > 6) + return -1; + + s->faac_handle = faacEncOpen(avctx->sample_rate, + avctx->channels, + &samples_input, &max_bytes_output); + + /* check faac version */ + faac_cfg = faacEncGetCurrentConfiguration(s->faac_handle); + if (faac_cfg->version != FAAC_CFG_VERSION) { + av_log(avctx, AV_LOG_ERROR, "wrong libfaac version (compiled for: %d, using %d)\n", FAAC_CFG_VERSION, faac_cfg->version); + faacEncClose(s->faac_handle); + return -1; + } + + /* put the options in the configuration struct */ + switch(avctx->profile) { + case FF_PROFILE_AAC_MAIN: + faac_cfg->aacObjectType = MAIN; + break; + case FF_PROFILE_UNKNOWN: + case FF_PROFILE_AAC_LOW: + faac_cfg->aacObjectType = LOW; + break; + case FF_PROFILE_AAC_SSR: + faac_cfg->aacObjectType = SSR; + break; + case FF_PROFILE_AAC_LTP: + faac_cfg->aacObjectType = LTP; + break; + default: + av_log(avctx, AV_LOG_ERROR, "invalid AAC profile\n"); + faacEncClose(s->faac_handle); + return -1; + } + faac_cfg->mpegVersion = MPEG4; + faac_cfg->useTns = 0; + faac_cfg->allowMidside = 1; + faac_cfg->bitRate = avctx->bit_rate / avctx->channels; + faac_cfg->bandWidth = avctx->cutoff; + if(avctx->flags & CODEC_FLAG_QSCALE) { + faac_cfg->bitRate = 0; + faac_cfg->quantqual = avctx->global_quality / FF_QP2LAMBDA; + } + faac_cfg->outputFormat = 1; + faac_cfg->inputFormat = FAAC_INPUT_16BIT; + + avctx->frame_size = samples_input / avctx->channels; + + avctx->coded_frame= avcodec_alloc_frame(); + avctx->coded_frame->key_frame= 1; + + /* Set decoder specific info */ + avctx->extradata_size = 0; + if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) { + + unsigned char *buffer = NULL; + unsigned long decoder_specific_info_size; + + if (!faacEncGetDecoderSpecificInfo(s->faac_handle, &buffer, + &decoder_specific_info_size)) { + avctx->extradata = av_malloc(decoder_specific_info_size + FF_INPUT_BUFFER_PADDING_SIZE); + avctx->extradata_size = decoder_specific_info_size; + memcpy(avctx->extradata, buffer, avctx->extradata_size); + faac_cfg->outputFormat = 0; + } +#undef free + free(buffer); +#define free please_use_av_free + } + + if (!faacEncSetConfiguration(s->faac_handle, faac_cfg)) { + av_log(avctx, AV_LOG_ERROR, "libfaac doesn't support this output format!\n"); + return -1; + } + + return 0; +} + +static int Faac_encode_frame(AVCodecContext *avctx, + unsigned char *frame, int buf_size, void *data) +{ + FaacAudioContext *s = avctx->priv_data; + int bytes_written; + + bytes_written = faacEncEncode(s->faac_handle, + data, + avctx->frame_size * avctx->channels, + frame, + buf_size); + + return bytes_written; +} + +static int Faac_encode_close(AVCodecContext *avctx) +{ + FaacAudioContext *s = avctx->priv_data; + + av_freep(&avctx->coded_frame); + av_freep(&avctx->extradata); + + faacEncClose(s->faac_handle); + return 0; +} + +AVCodec libfaac_encoder = { + "libfaac", + CODEC_TYPE_AUDIO, + CODEC_ID_AAC, + sizeof(FaacAudioContext), + Faac_encode_init, + Faac_encode_frame, + Faac_encode_close +}; diff --git a/contrib/ffmpeg/libavcodec/libfaad.c b/contrib/ffmpeg/libavcodec/libfaad.c new file mode 100644 index 000000000..f8d7c6573 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/libfaad.c @@ -0,0 +1,338 @@ +/* + * Faad decoder + * Copyright (c) 2003 Zdenek Kabelac. + * Copyright (c) 2004 Thomas Raivio. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file faad.c + * AAC decoder. + * + * still a bit unfinished - but it plays something + */ + +#include "avcodec.h" +#include "faad.h" + +#ifndef FAADAPI +#define FAADAPI +#endif + +/* + * when CONFIG_LIBFAADBIN is defined the libfaad will be opened at runtime + */ +//#undef CONFIG_LIBFAADBIN +//#define CONFIG_LIBFAADBIN + +#ifdef CONFIG_LIBFAADBIN +#include +static const char* libfaadname = "libfaad.so"; +#else +#define dlopen(a) +#define dlclose(a) +#endif + +typedef struct { + void* handle; /* dlopen handle */ + void* faac_handle; /* FAAD library handle */ + int sample_size; + int init; + + /* faad calls */ + faacDecHandle FAADAPI (*faacDecOpen)(void); + faacDecConfigurationPtr FAADAPI (*faacDecGetCurrentConfiguration)(faacDecHandle hDecoder); +#ifndef FAAD2_VERSION + int FAADAPI (*faacDecSetConfiguration)(faacDecHandle hDecoder, + faacDecConfigurationPtr config); + int FAADAPI (*faacDecInit)(faacDecHandle hDecoder, + unsigned char *buffer, + unsigned long *samplerate, + unsigned long *channels); + int FAADAPI (*faacDecInit2)(faacDecHandle hDecoder, unsigned char *pBuffer, + unsigned long SizeOfDecoderSpecificInfo, + unsigned long *samplerate, unsigned long *channels); + int FAADAPI (*faacDecDecode)(faacDecHandle hDecoder, + unsigned char *buffer, + unsigned long *bytesconsumed, + short *sample_buffer, + unsigned long *samples); +#else + unsigned char FAADAPI (*faacDecSetConfiguration)(faacDecHandle hDecoder, + faacDecConfigurationPtr config); + long FAADAPI (*faacDecInit)(faacDecHandle hDecoder, + unsigned char *buffer, + unsigned long buffer_size, + unsigned long *samplerate, + unsigned char *channels); + char FAADAPI (*faacDecInit2)(faacDecHandle hDecoder, unsigned char *pBuffer, + unsigned long SizeOfDecoderSpecificInfo, + unsigned long *samplerate, unsigned char *channels); + void *FAADAPI (*faacDecDecode)(faacDecHandle hDecoder, + faacDecFrameInfo *hInfo, + unsigned char *buffer, + unsigned long buffer_size); + char* FAADAPI (*faacDecGetErrorMessage)(unsigned char errcode); +#endif + + void FAADAPI (*faacDecClose)(faacDecHandle hDecoder); + + +} FAACContext; + +static const unsigned long faac_srates[] = +{ + 96000, 88200, 64000, 48000, 44100, 32000, + 24000, 22050, 16000, 12000, 11025, 8000 +}; + +static void channel_setup(AVCodecContext *avctx) +{ +#ifdef FAAD2_VERSION + FAACContext *s = avctx->priv_data; + if (avctx->request_channels > 0 && avctx->request_channels == 2 && + avctx->request_channels < avctx->channels) { + faacDecConfigurationPtr faac_cfg; + avctx->channels = 2; + faac_cfg = s->faacDecGetCurrentConfiguration(s->faac_handle); + faac_cfg->downMatrix = 1; + s->faacDecSetConfiguration(s->faac_handle, faac_cfg); + } +#endif +} + +static int faac_init_mp4(AVCodecContext *avctx) +{ + FAACContext *s = avctx->priv_data; + unsigned long samplerate; +#ifndef FAAD2_VERSION + unsigned long channels; +#else + unsigned char channels; +#endif + int r = 0; + + if (avctx->extradata){ + r = s->faacDecInit2(s->faac_handle, (uint8_t*) avctx->extradata, + avctx->extradata_size, + &samplerate, &channels); + if (r < 0){ + av_log(avctx, AV_LOG_ERROR, + "faacDecInit2 failed r:%d sr:%ld ch:%ld s:%d\n", + r, samplerate, (long)channels, avctx->extradata_size); + } else { + avctx->sample_rate = samplerate; + avctx->channels = channels; + channel_setup(avctx); + s->init = 1; + } + } + + return r; +} + +static int faac_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + uint8_t *buf, int buf_size) +{ + FAACContext *s = avctx->priv_data; +#ifndef FAAD2_VERSION + unsigned long bytesconsumed; + short *sample_buffer = NULL; + unsigned long samples; + int out; +#else + faacDecFrameInfo frame_info; + void *out; +#endif + if(buf_size == 0) + return 0; +#ifndef FAAD2_VERSION + out = s->faacDecDecode(s->faac_handle, + (unsigned char*)buf, + &bytesconsumed, + data, + &samples); + samples *= s->sample_size; + if (data_size) + *data_size = samples; + return (buf_size < (int)bytesconsumed) + ? buf_size : (int)bytesconsumed; +#else + + if(!s->init){ + unsigned long srate; + unsigned char channels; + int r = s->faacDecInit(s->faac_handle, buf, buf_size, &srate, &channels); + if(r < 0){ + av_log(avctx, AV_LOG_ERROR, "faac: codec init failed: %s\n", + s->faacDecGetErrorMessage(frame_info.error)); + return -1; + } + avctx->sample_rate = srate; + avctx->channels = channels; + channel_setup(avctx); + s->init = 1; + } + + out = s->faacDecDecode(s->faac_handle, &frame_info, (unsigned char*)buf, (unsigned long)buf_size); + + if (frame_info.error > 0) { + av_log(avctx, AV_LOG_ERROR, "faac: frame decoding failed: %s\n", + s->faacDecGetErrorMessage(frame_info.error)); + return -1; + } + + frame_info.samples *= s->sample_size; + memcpy(data, out, frame_info.samples); // CHECKME - can we cheat this one + + if (data_size) + *data_size = frame_info.samples; + + return (buf_size < (int)frame_info.bytesconsumed) + ? buf_size : (int)frame_info.bytesconsumed; +#endif +} + +static int faac_decode_end(AVCodecContext *avctx) +{ + FAACContext *s = avctx->priv_data; + + s->faacDecClose(s->faac_handle); + + dlclose(s->handle); + return 0; +} + +static int faac_decode_init(AVCodecContext *avctx) +{ + FAACContext *s = avctx->priv_data; + faacDecConfigurationPtr faac_cfg; + +#ifdef CONFIG_LIBFAADBIN + const char* err = 0; + + s->handle = dlopen(libfaadname, RTLD_LAZY); + if (!s->handle) + { + av_log(avctx, AV_LOG_ERROR, "FAAD library: %s could not be opened! \n%s\n", + libfaadname, dlerror()); + return -1; + } + +#define dfaac(a) do { \ + const char* n = AV_STRINGIFY(faacDec ## a); \ + if (!err && !(s->faacDec ## a = dlsym(s->handle, n))) { \ + err = n; \ + } \ + } while(0) +#else /* !CONFIG_LIBFAADBIN */ +#define dfaac(a) s->faacDec ## a = faacDec ## a +#endif /* CONFIG_LIBFAADBIN */ + + // resolve all needed function calls + dfaac(Open); + dfaac(Close); + dfaac(GetCurrentConfiguration); + dfaac(SetConfiguration); + dfaac(Init); + dfaac(Init2); + dfaac(Decode); +#ifdef FAAD2_VERSION + dfaac(GetErrorMessage); +#endif + +#undef dfaac + +#ifdef CONFIG_LIBFAADBIN + if (err) { + dlclose(s->handle); + av_log(avctx, AV_LOG_ERROR, "FAAD library: cannot resolve %s in %s!\n", + err, libfaadname); + return -1; + } +#endif + + s->faac_handle = s->faacDecOpen(); + if (!s->faac_handle) { + av_log(avctx, AV_LOG_ERROR, "FAAD library: cannot create handler!\n"); + faac_decode_end(avctx); + return -1; + } + + + faac_cfg = s->faacDecGetCurrentConfiguration(s->faac_handle); + + if (faac_cfg) { + switch (avctx->bits_per_sample) { + case 8: av_log(avctx, AV_LOG_ERROR, "FAADlib unsupported bps %d\n", avctx->bits_per_sample); break; + default: + case 16: +#ifdef FAAD2_VERSION + faac_cfg->outputFormat = FAAD_FMT_16BIT; +#endif + s->sample_size = 2; + break; + case 24: +#ifdef FAAD2_VERSION + faac_cfg->outputFormat = FAAD_FMT_24BIT; +#endif + s->sample_size = 3; + break; + case 32: +#ifdef FAAD2_VERSION + faac_cfg->outputFormat = FAAD_FMT_32BIT; +#endif + s->sample_size = 4; + break; + } + + faac_cfg->defSampleRate = (!avctx->sample_rate) ? 44100 : avctx->sample_rate; + faac_cfg->defObjectType = LC; + } + + s->faacDecSetConfiguration(s->faac_handle, faac_cfg); + + faac_init_mp4(avctx); + + if(!s->init && avctx->channels > 0) + channel_setup(avctx); + + return 0; +} + +#define AAC_CODEC(id, name) \ +AVCodec name ## _decoder = { \ + #name, \ + CODEC_TYPE_AUDIO, \ + id, \ + sizeof(FAACContext), \ + faac_decode_init, \ + NULL, \ + faac_decode_end, \ + faac_decode_frame, \ +} + +// FIXME - raw AAC files - maybe just one entry will be enough +AAC_CODEC(CODEC_ID_AAC, libfaad); +#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) +// If it's mp4 file - usually embeded into Qt Mov +AAC_CODEC(CODEC_ID_MPEG4AAC, mpeg4aac); +#endif + +#undef AAC_CODEC diff --git a/contrib/ffmpeg/libavcodec/libgsm.c b/contrib/ffmpeg/libavcodec/libgsm.c index 86dfce575..4fe2b384b 100644 --- a/contrib/ffmpeg/libavcodec/libgsm.c +++ b/contrib/ffmpeg/libavcodec/libgsm.c @@ -30,7 +30,7 @@ #include "avcodec.h" #include -// gsm.h miss some essential constants +// gsm.h misses some essential constants #define GSM_BLOCK_SIZE 33 #define GSM_MS_BLOCK_SIZE 65 #define GSM_FRAME_SIZE 160 @@ -84,7 +84,7 @@ static int libgsm_encode_frame(AVCodecContext *avctx, AVCodec libgsm_encoder = { - "gsm", + "libgsm", CODEC_TYPE_AUDIO, CODEC_ID_GSM, 0, @@ -94,7 +94,7 @@ AVCodec libgsm_encoder = { }; AVCodec libgsm_ms_encoder = { - "gsm", + "libgsm_ms", CODEC_TYPE_AUDIO, CODEC_ID_GSM_MS, 0, @@ -123,7 +123,7 @@ static int libgsm_decode_frame(AVCodecContext *avctx, } AVCodec libgsm_decoder = { - "gsm", + "libgsm", CODEC_TYPE_AUDIO, CODEC_ID_GSM, 0, @@ -134,7 +134,7 @@ AVCodec libgsm_decoder = { }; AVCodec libgsm_ms_decoder = { - "gsm_ms", + "libgsm_ms", CODEC_TYPE_AUDIO, CODEC_ID_GSM_MS, 0, diff --git a/contrib/ffmpeg/libavcodec/libmp3lame.c b/contrib/ffmpeg/libavcodec/libmp3lame.c new file mode 100644 index 000000000..6fbf2e23d --- /dev/null +++ b/contrib/ffmpeg/libavcodec/libmp3lame.c @@ -0,0 +1,221 @@ +/* + * Interface to libmp3lame for mp3 encoding + * Copyright (c) 2002 Lennert Buytenhek + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mp3lameaudio.c + * Interface to libmp3lame for mp3 encoding. + */ + +#include "avcodec.h" +#include "mpegaudio.h" +#include + +#define BUFFER_SIZE (7200 + MPA_FRAME_SIZE + MPA_FRAME_SIZE/4) +typedef struct Mp3AudioContext { + lame_global_flags *gfp; + int stereo; + uint8_t buffer[BUFFER_SIZE]; + int buffer_index; +} Mp3AudioContext; + +static int MP3lame_encode_init(AVCodecContext *avctx) +{ + Mp3AudioContext *s = avctx->priv_data; + + if (avctx->channels > 2) + return -1; + + s->stereo = avctx->channels > 1 ? 1 : 0; + + if ((s->gfp = lame_init()) == NULL) + goto err; + lame_set_in_samplerate(s->gfp, avctx->sample_rate); + lame_set_out_samplerate(s->gfp, avctx->sample_rate); + lame_set_num_channels(s->gfp, avctx->channels); + /* lame 3.91 dies on quality != 5 */ + lame_set_quality(s->gfp, 5); + /* lame 3.91 doesn't work in mono */ + lame_set_mode(s->gfp, JOINT_STEREO); + lame_set_brate(s->gfp, avctx->bit_rate/1000); + if(avctx->flags & CODEC_FLAG_QSCALE) { + lame_set_brate(s->gfp, 0); + lame_set_VBR(s->gfp, vbr_default); + lame_set_VBR_q(s->gfp, avctx->global_quality / (float)FF_QP2LAMBDA); + } + lame_set_bWriteVbrTag(s->gfp,0); + lame_set_disable_reservoir(s->gfp, avctx->flags2 & CODEC_FLAG2_BIT_RESERVOIR ? 0 : 1); + if (lame_init_params(s->gfp) < 0) + goto err_close; + + avctx->frame_size = lame_get_framesize(s->gfp); + + avctx->coded_frame= avcodec_alloc_frame(); + avctx->coded_frame->key_frame= 1; + + return 0; + +err_close: + lame_close(s->gfp); +err: + return -1; +} + +static const int sSampleRates[3] = { + 44100, 48000, 32000 +}; + +static const int sBitRates[2][3][15] = { + { { 0, 32, 64, 96,128,160,192,224,256,288,320,352,384,416,448}, + { 0, 32, 48, 56, 64, 80, 96,112,128,160,192,224,256,320,384}, + { 0, 32, 40, 48, 56, 64, 80, 96,112,128,160,192,224,256,320} + }, + { { 0, 32, 48, 56, 64, 80, 96,112,128,144,160,176,192,224,256}, + { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160}, + { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160} + }, +}; + +static const int sSamplesPerFrame[2][3] = +{ + { 384, 1152, 1152 }, + { 384, 1152, 576 } +}; + +static const int sBitsPerSlot[3] = { + 32, + 8, + 8 +}; + +static int mp3len(void *data, int *samplesPerFrame, int *sampleRate) +{ + uint32_t header = AV_RB32(data); + int layerID = 3 - ((header >> 17) & 0x03); + int bitRateID = ((header >> 12) & 0x0f); + int sampleRateID = ((header >> 10) & 0x03); + int bitsPerSlot = sBitsPerSlot[layerID]; + int isPadded = ((header >> 9) & 0x01); + static int const mode_tab[4]= {2,3,1,0}; + int mode= mode_tab[(header >> 19) & 0x03]; + int mpeg_id= mode>0; + int temp0, temp1, bitRate; + + if ( (( header >> 21 ) & 0x7ff) != 0x7ff || mode == 3 || layerID==3 || sampleRateID==3) { + return -1; + } + + if(!samplesPerFrame) samplesPerFrame= &temp0; + if(!sampleRate ) sampleRate = &temp1; + +// *isMono = ((header >> 6) & 0x03) == 0x03; + + *sampleRate = sSampleRates[sampleRateID]>>mode; + bitRate = sBitRates[mpeg_id][layerID][bitRateID] * 1000; + *samplesPerFrame = sSamplesPerFrame[mpeg_id][layerID]; +//av_log(NULL, AV_LOG_DEBUG, "sr:%d br:%d spf:%d l:%d m:%d\n", *sampleRate, bitRate, *samplesPerFrame, layerID, mode); + + return *samplesPerFrame * bitRate / (bitsPerSlot * *sampleRate) + isPadded; +} + +static int MP3lame_encode_frame(AVCodecContext *avctx, + unsigned char *frame, int buf_size, void *data) +{ + Mp3AudioContext *s = avctx->priv_data; + int len; + int lame_result; + + /* lame 3.91 dies on '1-channel interleaved' data */ + + if(data){ + if (s->stereo) { + lame_result = lame_encode_buffer_interleaved( + s->gfp, + data, + avctx->frame_size, + s->buffer + s->buffer_index, + BUFFER_SIZE - s->buffer_index + ); + } else { + lame_result = lame_encode_buffer( + s->gfp, + data, + data, + avctx->frame_size, + s->buffer + s->buffer_index, + BUFFER_SIZE - s->buffer_index + ); + } + }else{ + lame_result= lame_encode_flush( + s->gfp, + s->buffer + s->buffer_index, + BUFFER_SIZE - s->buffer_index + ); + } + + if(lame_result==-1) { + /* output buffer too small */ + av_log(avctx, AV_LOG_ERROR, "lame: output buffer too small (buffer index: %d, free bytes: %d)\n", s->buffer_index, BUFFER_SIZE - s->buffer_index); + return 0; + } + + s->buffer_index += lame_result; + + if(s->buffer_index<4) + return 0; + + len= mp3len(s->buffer, NULL, NULL); +//av_log(avctx, AV_LOG_DEBUG, "in:%d packet-len:%d index:%d\n", avctx->frame_size, len, s->buffer_index); + if(len <= s->buffer_index){ + memcpy(frame, s->buffer, len); + s->buffer_index -= len; + + memmove(s->buffer, s->buffer+len, s->buffer_index); + //FIXME fix the audio codec API, so we do not need the memcpy() +/*for(i=0; ipriv_data; + + av_freep(&avctx->coded_frame); + + lame_close(s->gfp); + return 0; +} + + +AVCodec libmp3lame_encoder = { + "libmp3lame", + CODEC_TYPE_AUDIO, + CODEC_ID_MP3, + sizeof(Mp3AudioContext), + MP3lame_encode_init, + MP3lame_encode_frame, + MP3lame_encode_close, + .capabilities= CODEC_CAP_DELAY, +}; diff --git a/contrib/ffmpeg/libavcodec/libtheoraenc.c b/contrib/ffmpeg/libavcodec/libtheoraenc.c index 7f531dbee..c3d848f31 100644 --- a/contrib/ffmpeg/libavcodec/libtheoraenc.c +++ b/contrib/ffmpeg/libavcodec/libtheoraenc.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /*! @@ -69,8 +69,8 @@ static int concatenate_packet(unsigned int* offset, AVCodecContext* avc_context, avc_context->extradata = newdata; avc_context->extradata_size = newsize; - avc_context->extradata[ (*offset)++ ] = packet->bytes >> 8; - avc_context->extradata[ (*offset)++ ] = packet->bytes & 0xff; + AV_WB16(avc_context->extradata + (*offset), packet->bytes); + *offset += 2; memcpy( avc_context->extradata + (*offset), packet->packet, packet->bytes ); (*offset) += packet->bytes; return 0; diff --git a/contrib/ffmpeg/libavcodec/libvorbis.c b/contrib/ffmpeg/libavcodec/libvorbis.c new file mode 100644 index 000000000..3fb507dad --- /dev/null +++ b/contrib/ffmpeg/libavcodec/libvorbis.c @@ -0,0 +1,220 @@ +/* + * copyright (c) 2002 Mark Hills + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file oggvorbis.c + * Ogg Vorbis codec support via libvorbisenc. + * @author Mark Hills + */ + +#include + +#include "avcodec.h" +#include "bytestream.h" + +#undef NDEBUG +#include + +#define OGGVORBIS_FRAME_SIZE 64 + +#define BUFFER_SIZE (1024*64) + +typedef struct OggVorbisContext { + vorbis_info vi ; + vorbis_dsp_state vd ; + vorbis_block vb ; + uint8_t buffer[BUFFER_SIZE]; + int buffer_index; + + /* decoder */ + vorbis_comment vc ; + ogg_packet op; +} OggVorbisContext ; + + +static int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) { + double cfreq; + + if(avccontext->flags & CODEC_FLAG_QSCALE) { + /* variable bitrate */ + if(vorbis_encode_setup_vbr(vi, avccontext->channels, + avccontext->sample_rate, + avccontext->global_quality / (float)FF_QP2LAMBDA)) + return -1; + } else { + /* constant bitrate */ + if(vorbis_encode_setup_managed(vi, avccontext->channels, + avccontext->sample_rate, -1, avccontext->bit_rate, -1)) + return -1; + +#ifdef OGGVORBIS_VBR_BY_ESTIMATE + /* variable bitrate by estimate */ + if(vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE_AVG, NULL)) + return -1; +#endif + } + + /* cutoff frequency */ + if(avccontext->cutoff > 0) { + cfreq = avccontext->cutoff / 1000.0; + if(vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq)) + return -1; + } + + return vorbis_encode_setup_init(vi); +} + +static int oggvorbis_encode_init(AVCodecContext *avccontext) { + OggVorbisContext *context = avccontext->priv_data ; + ogg_packet header, header_comm, header_code; + uint8_t *p; + unsigned int offset, len; + + vorbis_info_init(&context->vi) ; + if(oggvorbis_init_encoder(&context->vi, avccontext) < 0) { + av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init: init_encoder failed") ; + return -1 ; + } + vorbis_analysis_init(&context->vd, &context->vi) ; + vorbis_block_init(&context->vd, &context->vb) ; + + vorbis_comment_init(&context->vc); + vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT) ; + + vorbis_analysis_headerout(&context->vd, &context->vc, &header, + &header_comm, &header_code); + + len = header.bytes + header_comm.bytes + header_code.bytes; + avccontext->extradata_size= 64 + len + len/255; + p = avccontext->extradata= av_mallocz(avccontext->extradata_size); + p[0] = 2; + offset = 1; + offset += av_xiphlacing(&p[offset], header.bytes); + offset += av_xiphlacing(&p[offset], header_comm.bytes); + memcpy(&p[offset], header.packet, header.bytes); + offset += header.bytes; + memcpy(&p[offset], header_comm.packet, header_comm.bytes); + offset += header_comm.bytes; + memcpy(&p[offset], header_code.packet, header_code.bytes); + offset += header_code.bytes; + avccontext->extradata_size = offset; + avccontext->extradata= av_realloc(avccontext->extradata, avccontext->extradata_size); + +/* vorbis_block_clear(&context->vb); + vorbis_dsp_clear(&context->vd); + vorbis_info_clear(&context->vi);*/ + vorbis_comment_clear(&context->vc); + + avccontext->frame_size = OGGVORBIS_FRAME_SIZE ; + + avccontext->coded_frame= avcodec_alloc_frame(); + avccontext->coded_frame->key_frame= 1; + + return 0 ; +} + + +static int oggvorbis_encode_frame(AVCodecContext *avccontext, + unsigned char *packets, + int buf_size, void *data) +{ + OggVorbisContext *context = avccontext->priv_data ; + float **buffer ; + ogg_packet op ; + signed short *audio = data ; + int l, samples = data ? OGGVORBIS_FRAME_SIZE : 0; + + buffer = vorbis_analysis_buffer(&context->vd, samples) ; + + if(context->vi.channels == 1) { + for(l = 0 ; l < samples ; l++) + buffer[0][l]=audio[l]/32768.f; + } else { + for(l = 0 ; l < samples ; l++){ + buffer[0][l]=audio[l*2]/32768.f; + buffer[1][l]=audio[l*2+1]/32768.f; + } + } + + vorbis_analysis_wrote(&context->vd, samples) ; + + while(vorbis_analysis_blockout(&context->vd, &context->vb) == 1) { + vorbis_analysis(&context->vb, NULL); + vorbis_bitrate_addblock(&context->vb) ; + + while(vorbis_bitrate_flushpacket(&context->vd, &op)) { + /* i'd love to say the following line is a hack, but sadly it's + * not, apparently the end of stream decision is in libogg. */ + if(op.bytes==1) + continue; + memcpy(context->buffer + context->buffer_index, &op, sizeof(ogg_packet)); + context->buffer_index += sizeof(ogg_packet); + memcpy(context->buffer + context->buffer_index, op.packet, op.bytes); + context->buffer_index += op.bytes; +// av_log(avccontext, AV_LOG_DEBUG, "e%d / %d\n", context->buffer_index, op.bytes); + } + } + + l=0; + if(context->buffer_index){ + ogg_packet *op2= (ogg_packet*)context->buffer; + op2->packet = context->buffer + sizeof(ogg_packet); + + l= op2->bytes; + avccontext->coded_frame->pts= av_rescale_q(op2->granulepos, (AVRational){1, avccontext->sample_rate}, avccontext->time_base); + //FIXME we should reorder the user supplied pts and not assume that they are spaced by 1/sample_rate + + memcpy(packets, op2->packet, l); + context->buffer_index -= l + sizeof(ogg_packet); + memcpy(context->buffer, context->buffer + l + sizeof(ogg_packet), context->buffer_index); +// av_log(avccontext, AV_LOG_DEBUG, "E%d\n", l); + } + + return l; +} + + +static int oggvorbis_encode_close(AVCodecContext *avccontext) { + OggVorbisContext *context = avccontext->priv_data ; +/* ogg_packet op ; */ + + vorbis_analysis_wrote(&context->vd, 0) ; /* notify vorbisenc this is EOF */ + + vorbis_block_clear(&context->vb); + vorbis_dsp_clear(&context->vd); + vorbis_info_clear(&context->vi); + + av_freep(&avccontext->coded_frame); + av_freep(&avccontext->extradata); + + return 0 ; +} + + +AVCodec libvorbis_encoder = { + "libvorbis", + CODEC_TYPE_AUDIO, + CODEC_ID_VORBIS, + sizeof(OggVorbisContext), + oggvorbis_encode_init, + oggvorbis_encode_frame, + oggvorbis_encode_close, + .capabilities= CODEC_CAP_DELAY, +} ; diff --git a/contrib/ffmpeg/libavcodec/libx264.c b/contrib/ffmpeg/libavcodec/libx264.c new file mode 100644 index 000000000..eb897eba2 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/libx264.c @@ -0,0 +1,300 @@ +/* + * H.264 encoding using the x264 library + * Copyright (C) 2005 Mans Rullgard + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include +#include +#include +#include +#include + +typedef struct X264Context { + x264_param_t params; + x264_t *enc; + x264_picture_t pic; + AVFrame out_pic; +} X264Context; + +static void +X264_log(void *p, int level, const char *fmt, va_list args) +{ + static const int level_map[] = { + [X264_LOG_ERROR] = AV_LOG_ERROR, + [X264_LOG_WARNING] = AV_LOG_WARNING, + [X264_LOG_INFO] = AV_LOG_INFO, + [X264_LOG_DEBUG] = AV_LOG_DEBUG + }; + + if(level < 0 || level > X264_LOG_DEBUG) + return; + + av_vlog(p, level_map[level], fmt, args); +} + + +static int +encode_nals(uint8_t *buf, int size, x264_nal_t *nals, int nnal) +{ + uint8_t *p = buf; + int i; + + for(i = 0; i < nnal; i++){ + int s = x264_nal_encode(p, &size, 1, nals + i); + if(s < 0) + return -1; + p += s; + } + + return p - buf; +} + +static int +X264_frame(AVCodecContext *ctx, uint8_t *buf, int bufsize, void *data) +{ + X264Context *x4 = ctx->priv_data; + AVFrame *frame = data; + x264_nal_t *nal; + int nnal, i; + x264_picture_t pic_out; + + x4->pic.img.i_csp = X264_CSP_I420; + x4->pic.img.i_plane = 3; + + if (frame) { + for(i = 0; i < 3; i++){ + x4->pic.img.plane[i] = frame->data[i]; + x4->pic.img.i_stride[i] = frame->linesize[i]; + } + + x4->pic.i_pts = frame->pts; + x4->pic.i_type = X264_TYPE_AUTO; + } + + if(x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, + &pic_out)) + return -1; + + bufsize = encode_nals(buf, bufsize, nal, nnal); + if(bufsize < 0) + return -1; + + /* FIXME: dts */ + x4->out_pic.pts = pic_out.i_pts; + + switch(pic_out.i_type){ + case X264_TYPE_IDR: + case X264_TYPE_I: + x4->out_pic.pict_type = FF_I_TYPE; + break; + case X264_TYPE_P: + x4->out_pic.pict_type = FF_P_TYPE; + break; + case X264_TYPE_B: + case X264_TYPE_BREF: + x4->out_pic.pict_type = FF_B_TYPE; + break; + } + + x4->out_pic.key_frame = pic_out.i_type == X264_TYPE_IDR; + x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; + + return bufsize; +} + +static int +X264_close(AVCodecContext *avctx) +{ + X264Context *x4 = avctx->priv_data; + + if(x4->enc) + x264_encoder_close(x4->enc); + + return 0; +} + +static int +X264_init(AVCodecContext *avctx) +{ + X264Context *x4 = avctx->priv_data; + + x264_param_default(&x4->params); + + x4->params.pf_log = X264_log; + x4->params.p_log_private = avctx; + + x4->params.i_keyint_max = avctx->gop_size; + x4->params.rc.i_bitrate = avctx->bit_rate / 1000; + x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000; + x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000; + x4->params.rc.b_stat_write = (avctx->flags & CODEC_FLAG_PASS1); + if(avctx->flags & CODEC_FLAG_PASS2) x4->params.rc.b_stat_read = 1; + else{ + if(avctx->crf){ + x4->params.rc.i_rc_method = X264_RC_CRF; + x4->params.rc.f_rf_constant = avctx->crf; + }else if(avctx->cqp > -1){ + x4->params.rc.i_rc_method = X264_RC_CQP; + x4->params.rc.i_qp_constant = avctx->cqp; + } + } + + // if neither crf nor cqp modes are selected we have to enable the RC + // we do it this way because we cannot check if the bitrate has been set + if(!(avctx->crf || (avctx->cqp > -1))) x4->params.rc.i_rc_method = X264_RC_ABR; + + x4->params.i_bframe = avctx->max_b_frames; + x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC; + x4->params.b_bframe_adaptive = avctx->b_frame_strategy; + x4->params.i_bframe_bias = avctx->bframebias; + x4->params.b_bframe_pyramid = (avctx->flags2 & CODEC_FLAG2_BPYRAMID); + avctx->has_b_frames= (avctx->flags2 & CODEC_FLAG2_BPYRAMID) ? 2 : !!avctx->max_b_frames; + + x4->params.i_keyint_min = avctx->keyint_min; + if(x4->params.i_keyint_min > x4->params.i_keyint_max) + x4->params.i_keyint_min = x4->params.i_keyint_max; + + x4->params.i_scenecut_threshold = avctx->scenechange_threshold; + + x4->params.b_deblocking_filter = (avctx->flags & CODEC_FLAG_LOOP_FILTER); + x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha; + x4->params.i_deblocking_filter_beta = avctx->deblockbeta; + + x4->params.rc.i_qp_min = avctx->qmin; + x4->params.rc.i_qp_max = avctx->qmax; + x4->params.rc.i_qp_step = avctx->max_qdiff; + + x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */ + x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */ + x4->params.rc.f_complexity_blur = avctx->complexityblur; + + x4->params.i_frame_reference = avctx->refs; + + x4->params.i_width = avctx->width; + x4->params.i_height = avctx->height; + x4->params.vui.i_sar_width = avctx->sample_aspect_ratio.num; + x4->params.vui.i_sar_height = avctx->sample_aspect_ratio.den; + x4->params.i_fps_num = avctx->time_base.den; + x4->params.i_fps_den = avctx->time_base.num; + + x4->params.analyse.inter = 0; + if(avctx->partitions){ + if(avctx->partitions & X264_PART_I4X4) + x4->params.analyse.inter |= X264_ANALYSE_I4x4; + if(avctx->partitions & X264_PART_I8X8) + x4->params.analyse.inter |= X264_ANALYSE_I8x8; + if(avctx->partitions & X264_PART_P8X8) + x4->params.analyse.inter |= X264_ANALYSE_PSUB16x16; + if(avctx->partitions & X264_PART_P4X4) + x4->params.analyse.inter |= X264_ANALYSE_PSUB8x8; + if(avctx->partitions & X264_PART_B8X8) + x4->params.analyse.inter |= X264_ANALYSE_BSUB16x16; + } + + x4->params.analyse.i_direct_mv_pred = avctx->directpred; + + x4->params.analyse.b_weighted_bipred = (avctx->flags2 & CODEC_FLAG2_WPRED); + + if(avctx->me_method == ME_EPZS) + x4->params.analyse.i_me_method = X264_ME_DIA; + else if(avctx->me_method == ME_HEX) + x4->params.analyse.i_me_method = X264_ME_HEX; + else if(avctx->me_method == ME_UMH) + x4->params.analyse.i_me_method = X264_ME_UMH; + else if(avctx->me_method == ME_FULL) + x4->params.analyse.i_me_method = X264_ME_ESA; + else x4->params.analyse.i_me_method = X264_ME_HEX; + + x4->params.analyse.i_me_range = avctx->me_range; + x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality; + + x4->params.analyse.b_bidir_me = (avctx->bidir_refine > 0); + x4->params.analyse.b_bframe_rdo = (avctx->flags2 & CODEC_FLAG2_BRDO); + x4->params.analyse.b_mixed_references = + (avctx->flags2 & CODEC_FLAG2_MIXED_REFS); + x4->params.analyse.b_chroma_me = (avctx->me_cmp & FF_CMP_CHROMA); + x4->params.analyse.b_transform_8x8 = (avctx->flags2 & CODEC_FLAG2_8X8DCT); + x4->params.analyse.b_fast_pskip = (avctx->flags2 & CODEC_FLAG2_FASTPSKIP); + + x4->params.analyse.i_trellis = avctx->trellis; + x4->params.analyse.i_noise_reduction = avctx->noise_reduction; + + if(avctx->level > 0) x4->params.i_level_idc = avctx->level; + + x4->params.rc.f_rate_tolerance = + (float)avctx->bit_rate_tolerance/avctx->bit_rate; + + if((avctx->rc_buffer_size != 0) && + (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)){ + x4->params.rc.f_vbv_buffer_init = + (float)avctx->rc_initial_buffer_occupancy/avctx->rc_buffer_size; + } + else x4->params.rc.f_vbv_buffer_init = 0.9; + + x4->params.rc.f_ip_factor = 1/fabs(avctx->i_quant_factor); + x4->params.rc.f_pb_factor = avctx->b_quant_factor; + x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset; + x4->params.rc.psz_rc_eq = avctx->rc_eq; + + x4->params.analyse.b_psnr = (avctx->flags & CODEC_FLAG_PSNR); + x4->params.i_log_level = X264_LOG_DEBUG; + + x4->params.b_aud = (avctx->flags2 & CODEC_FLAG2_AUD); + + x4->params.i_threads = avctx->thread_count; + + if(avctx->flags & CODEC_FLAG_GLOBAL_HEADER){ + x4->params.b_repeat_headers = 0; + } + + x4->enc = x264_encoder_open(&x4->params); + if(!x4->enc) + return -1; + + avctx->coded_frame = &x4->out_pic; + + if(avctx->flags & CODEC_FLAG_GLOBAL_HEADER){ + x264_nal_t *nal; + int nnal, i, s = 0; + + x264_encoder_headers(x4->enc, &nal, &nnal); + + /* 5 bytes NAL header + worst case escaping */ + for(i = 0; i < nnal; i++) + s += 5 + nal[i].i_payload * 4 / 3; + + avctx->extradata = av_malloc(s); + avctx->extradata_size = encode_nals(avctx->extradata, s, nal, nnal); + } + + return 0; +} + +AVCodec libx264_encoder = { + .name = "libx264", + .type = CODEC_TYPE_VIDEO, + .id = CODEC_ID_H264, + .priv_data_size = sizeof(X264Context), + .init = X264_init, + .encode = X264_frame, + .close = X264_close, + .capabilities = CODEC_CAP_DELAY, + .pix_fmts = (enum PixelFormat[]) { PIX_FMT_YUV420P, -1 } +}; diff --git a/contrib/ffmpeg/libavcodec/libxvid_internal.h b/contrib/ffmpeg/libavcodec/libxvid_internal.h new file mode 100644 index 000000000..a7d5a9646 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/libxvid_internal.h @@ -0,0 +1,32 @@ +/* + * copyright (C) 2006 Corey Hickey + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_LIBXVID_INTERNAL_H +#define FFMPEG_LIBXVID_INTERNAL_H + +/** + * @file libxvid_internal.h + * common functions for use with the XviD wrappers + */ + + +int av_tempfile(char *prefix, char **filename); + +#endif /* FFMPEG_LIBXVID_INTERNAL_H */ diff --git a/contrib/ffmpeg/libavcodec/libxvid_rc.c b/contrib/ffmpeg/libavcodec/libxvid_rc.c new file mode 100644 index 000000000..f06f5b960 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/libxvid_rc.c @@ -0,0 +1,148 @@ +/* + * xvid Rate control wrapper for lavc video encoders + * + * Copyright (c) 2006 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include "avcodec.h" +#include "libxvid_internal.h" +//#include "dsputil.h" +#include "mpegvideo.h" + +#undef NDEBUG +#include + +extern unsigned int xvid_debug; + +int ff_xvid_rate_control_init(MpegEncContext *s){ + char *tmp_name; + int fd, i; + xvid_plg_create_t xvid_plg_create; + xvid_plugin_2pass2_t xvid_2pass2; + +//xvid_debug=-1; + + fd=av_tempfile("xvidrc.", &tmp_name); + if (fd == -1) { + av_log(NULL, AV_LOG_ERROR, "Can't create temporary pass2 file.\n"); + return -1; + } + + for(i=0; irc_context.num_entries; i++){ + static const char *frame_types = " ipbs"; + char tmp[256]; + RateControlEntry *rce; + + rce= &s->rc_context.entry[i]; + + snprintf(tmp, sizeof(tmp), "%c %d %d %d %d %d %d\n", + frame_types[rce->pict_type], (int)lrintf(rce->qscale / FF_QP2LAMBDA), rce->i_count, s->mb_num - rce->i_count - rce->skip_count, + rce->skip_count, (rce->i_tex_bits + rce->p_tex_bits + rce->misc_bits+7)/8, (rce->header_bits+rce->mv_bits+7)/8); + +//av_log(NULL, AV_LOG_ERROR, "%s\n", tmp); + write(fd, tmp, strlen(tmp)); + } + + close(fd); + + memset(&xvid_2pass2, 0, sizeof(xvid_2pass2)); + xvid_2pass2.version= XVID_MAKE_VERSION(1,1,0); + xvid_2pass2.filename= tmp_name; + xvid_2pass2.bitrate= s->avctx->bit_rate; + xvid_2pass2.vbv_size= s->avctx->rc_buffer_size; + xvid_2pass2.vbv_maxrate= s->avctx->rc_max_rate; + xvid_2pass2.vbv_initial= s->avctx->rc_initial_buffer_occupancy; + + memset(&xvid_plg_create, 0, sizeof(xvid_plg_create)); + xvid_plg_create.version= XVID_MAKE_VERSION(1,1,0); + xvid_plg_create.fbase= s->avctx->time_base.den; + xvid_plg_create.fincr= s->avctx->time_base.num; + xvid_plg_create.param= &xvid_2pass2; + + if(xvid_plugin_2pass2(NULL, XVID_PLG_CREATE, &xvid_plg_create, &s->rc_context.non_lavc_opaque)<0){ + av_log(NULL, AV_LOG_ERROR, "xvid_plugin_2pass2 failed\n"); + return -1; + } + return 0; +} + +float ff_xvid_rate_estimate_qscale(MpegEncContext *s, int dry_run){ + xvid_plg_data_t xvid_plg_data; + + memset(&xvid_plg_data, 0, sizeof(xvid_plg_data)); + xvid_plg_data.version= XVID_MAKE_VERSION(1,1,0); + xvid_plg_data.width = s->width; + xvid_plg_data.height= s->height; + xvid_plg_data.mb_width = s->mb_width; + xvid_plg_data.mb_height= s->mb_height; + xvid_plg_data.fbase= s->avctx->time_base.den; + xvid_plg_data.fincr= s->avctx->time_base.num; + xvid_plg_data.min_quant[0]= s->avctx->qmin; + xvid_plg_data.min_quant[1]= s->avctx->qmin; + xvid_plg_data.min_quant[2]= s->avctx->qmin; //FIXME i/b factor & offset + xvid_plg_data.max_quant[0]= s->avctx->qmax; + xvid_plg_data.max_quant[1]= s->avctx->qmax; + xvid_plg_data.max_quant[2]= s->avctx->qmax; //FIXME i/b factor & offset + xvid_plg_data.bquant_offset = 0; // 100 * s->avctx->b_quant_offset; + xvid_plg_data.bquant_ratio = 100; // * s->avctx->b_quant_factor; + +#if 0 + xvid_plg_data.stats.hlength= X +#endif + + if(!s->rc_context.dry_run_qscale){ + if(s->picture_number){ + xvid_plg_data.length= + xvid_plg_data.stats.length= (s->frame_bits + 7)/8; + xvid_plg_data.frame_num= s->rc_context.last_picture_number; + xvid_plg_data.quant= s->qscale; + + xvid_plg_data.type= s->last_pict_type; + if(xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_AFTER, &xvid_plg_data, NULL)){ + av_log(s->avctx, AV_LOG_ERROR, "xvid_plugin_2pass2(handle, XVID_PLG_AFTER, ...) FAILED\n"); + return -1; + } + } + s->rc_context.last_picture_number= + xvid_plg_data.frame_num= s->picture_number; + xvid_plg_data.quant= 0; + if(xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_BEFORE, &xvid_plg_data, NULL)){ + av_log(s->avctx, AV_LOG_ERROR, "xvid_plugin_2pass2(handle, XVID_PLG_BEFORE, ...) FAILED\n"); + return -1; + } + s->rc_context.dry_run_qscale= xvid_plg_data.quant; + } + xvid_plg_data.quant= s->rc_context.dry_run_qscale; + if(!dry_run) + s->rc_context.dry_run_qscale= 0; + + if(s->pict_type == B_TYPE) //FIXME this is not exactly identical to xvid + return xvid_plg_data.quant * FF_QP2LAMBDA * s->avctx->b_quant_factor + s->avctx->b_quant_offset; + else + return xvid_plg_data.quant * FF_QP2LAMBDA; +} + +void ff_xvid_rate_control_uninit(MpegEncContext *s){ + xvid_plg_destroy_t xvid_plg_destroy; + + xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_DESTROY, &xvid_plg_destroy, NULL); +} + diff --git a/contrib/ffmpeg/libavcodec/libxvidff.c b/contrib/ffmpeg/libavcodec/libxvidff.c new file mode 100644 index 000000000..f3a1a5bb9 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/libxvidff.c @@ -0,0 +1,765 @@ +/* + * Interface to xvidcore for mpeg4 encoding + * Copyright (c) 2004 Adam Thayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file xvidmpeg4.c + * Interface to xvidcore for MPEG-4 compliant encoding. + * @author Adam Thayer (krevnik@comcast.net) + */ + +#include +#include +#include "avcodec.h" +#include "libxvid_internal.h" + +/** + * Buffer management macros. + */ +#define BUFFER_SIZE 1024 +#define BUFFER_REMAINING(x) (BUFFER_SIZE - strlen(x)) +#define BUFFER_CAT(x) (&((x)[strlen(x)])) + +/* For PPC Use */ +extern int has_altivec(void); + +/** + * Structure for the private XviD context. + * This stores all the private context for the codec. + */ +typedef struct xvid_context { + void *encoder_handle; /** Handle for XviD Encoder */ + int xsize, ysize; /** Frame size */ + int vop_flags; /** VOP flags for XviD Encoder */ + int vol_flags; /** VOL flags for XviD Encoder */ + int me_flags; /** Motion Estimation flags */ + int qscale; /** Do we use constant scale? */ + int quicktime_format; /** Are we in a QT-based format? */ + AVFrame encoded_picture; /** Encoded frame information */ + char *twopassbuffer; /** Character buffer for two-pass */ + char *old_twopassbuffer; /** Old character buffer (two-pass) */ + char *twopassfile; /** second pass temp file name */ + unsigned char *intra_matrix; /** P-Frame Quant Matrix */ + unsigned char *inter_matrix; /** I-Frame Quant Matrix */ +} xvid_context_t; + +/** + * Structure for the private first-pass plugin. + */ +typedef struct xvid_ff_pass1 { + int version; /** XviD version */ + xvid_context_t *context; /** Pointer to private context */ +} xvid_ff_pass1_t; + +/* Prototypes - See function implementation for details */ +int xvid_strip_vol_header(AVCodecContext *avctx, unsigned char *frame, unsigned int header_len, unsigned int frame_len); +int xvid_ff_2pass(void *ref, int opt, void *p1, void *p2); +void xvid_correct_framerate(AVCodecContext *avctx); + +/** + * Creates the private context for the encoder. + * All buffers are allocated, settings are loaded from the user, + * and the encoder context created. + * + * @param avctx AVCodecContext pointer to context + * @return Returns 0 on success, -1 on failure + */ +int ff_xvid_encode_init(AVCodecContext *avctx) { + int xerr, i; + int xvid_flags = avctx->flags; + xvid_context_t *x = avctx->priv_data; + uint16_t *intra, *inter; + int fd; + + xvid_plugin_single_t single; + xvid_ff_pass1_t rc2pass1; + xvid_plugin_2pass2_t rc2pass2; + xvid_gbl_init_t xvid_gbl_init; + xvid_enc_create_t xvid_enc_create; + xvid_enc_plugin_t plugins[7]; + + /* Bring in VOP flags from ffmpeg command-line */ + x->vop_flags = XVID_VOP_HALFPEL; /* Bare minimum quality */ + if( xvid_flags & CODEC_FLAG_4MV ) + x->vop_flags |= XVID_VOP_INTER4V; /* Level 3 */ + if( xvid_flags & CODEC_FLAG_TRELLIS_QUANT) + x->vop_flags |= XVID_VOP_TRELLISQUANT; /* Level 5 */ + if( xvid_flags & CODEC_FLAG_AC_PRED ) + x->vop_flags |= XVID_VOP_HQACPRED; /* Level 6 */ + if( xvid_flags & CODEC_FLAG_GRAY ) + x->vop_flags |= XVID_VOP_GREYSCALE; + + /* Decide which ME quality setting to use */ + x->me_flags = 0; + switch( avctx->me_method ) { + case ME_FULL: /* Quality 6 */ + x->me_flags |= XVID_ME_EXTSEARCH16 + | XVID_ME_EXTSEARCH8; + + case ME_EPZS: /* Quality 4 */ + x->me_flags |= XVID_ME_ADVANCEDDIAMOND8 + | XVID_ME_HALFPELREFINE8 + | XVID_ME_CHROMA_PVOP + | XVID_ME_CHROMA_BVOP; + + case ME_LOG: /* Quality 2 */ + case ME_PHODS: + case ME_X1: + x->me_flags |= XVID_ME_ADVANCEDDIAMOND16 + | XVID_ME_HALFPELREFINE16; + + case ME_ZERO: /* Quality 0 */ + default: + break; + } + + /* Decide how we should decide blocks */ + switch( avctx->mb_decision ) { + case 2: + x->vop_flags |= XVID_VOP_MODEDECISION_RD; + x->me_flags |= XVID_ME_HALFPELREFINE8_RD + | XVID_ME_QUARTERPELREFINE8_RD + | XVID_ME_EXTSEARCH_RD + | XVID_ME_CHECKPREDICTION_RD; + case 1: + if( !(x->vop_flags & XVID_VOP_MODEDECISION_RD) ) + x->vop_flags |= XVID_VOP_FAST_MODEDECISION_RD; + x->me_flags |= XVID_ME_HALFPELREFINE16_RD + | XVID_ME_QUARTERPELREFINE16_RD; + + default: + break; + } + + /* Bring in VOL flags from ffmpeg command-line */ + x->vol_flags = 0; + if( xvid_flags & CODEC_FLAG_GMC ) { + x->vol_flags |= XVID_VOL_GMC; + x->me_flags |= XVID_ME_GME_REFINE; + } + if( xvid_flags & CODEC_FLAG_QPEL ) { + x->vol_flags |= XVID_VOL_QUARTERPEL; + x->me_flags |= XVID_ME_QUARTERPELREFINE16; + if( x->vop_flags & XVID_VOP_INTER4V ) + x->me_flags |= XVID_ME_QUARTERPELREFINE8; + } + + memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init)); + xvid_gbl_init.version = XVID_VERSION; + xvid_gbl_init.debug = 0; + +#ifdef ARCH_POWERPC + /* XviD's PPC support is borked, use libavcodec to detect */ +#ifdef HAVE_ALTIVEC + if( has_altivec() ) { + xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ALTIVEC; + } else +#endif + xvid_gbl_init.cpu_flags = XVID_CPU_FORCE; +#else + /* XviD can detect on x86 */ + xvid_gbl_init.cpu_flags = 0; +#endif + + /* Initialize */ + xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL); + + /* Create the encoder reference */ + memset(&xvid_enc_create, 0, sizeof(xvid_enc_create)); + xvid_enc_create.version = XVID_VERSION; + + /* Store the desired frame size */ + xvid_enc_create.width = x->xsize = avctx->width; + xvid_enc_create.height = x->ysize = avctx->height; + + /* XviD can determine the proper profile to use */ + /* xvid_enc_create.profile = XVID_PROFILE_S_L3; */ + + /* We don't use zones or threads */ + xvid_enc_create.zones = NULL; + xvid_enc_create.num_zones = 0; + xvid_enc_create.num_threads = 0; + + xvid_enc_create.plugins = plugins; + xvid_enc_create.num_plugins = 0; + + /* Initialize Buffers */ + x->twopassbuffer = NULL; + x->old_twopassbuffer = NULL; + x->twopassfile = NULL; + + if( xvid_flags & CODEC_FLAG_PASS1 ) { + memset(&rc2pass1, 0, sizeof(xvid_ff_pass1_t)); + rc2pass1.version = XVID_VERSION; + rc2pass1.context = x; + x->twopassbuffer = av_malloc(BUFFER_SIZE); + x->old_twopassbuffer = av_malloc(BUFFER_SIZE); + if( x->twopassbuffer == NULL || x->old_twopassbuffer == NULL ) { + av_log(avctx, AV_LOG_ERROR, + "XviD: Cannot allocate 2-pass log buffers\n"); + return -1; + } + x->twopassbuffer[0] = x->old_twopassbuffer[0] = 0; + + plugins[xvid_enc_create.num_plugins].func = xvid_ff_2pass; + plugins[xvid_enc_create.num_plugins].param = &rc2pass1; + xvid_enc_create.num_plugins++; + } else if( xvid_flags & CODEC_FLAG_PASS2 ) { + memset(&rc2pass2, 0, sizeof(xvid_plugin_2pass2_t)); + rc2pass2.version = XVID_VERSION; + rc2pass2.bitrate = avctx->bit_rate; + + fd = av_tempfile("xvidff.", &(x->twopassfile)); + if( fd == -1 ) { + av_log(avctx, AV_LOG_ERROR, + "XviD: Cannot write 2-pass pipe\n"); + return -1; + } + + if( avctx->stats_in == NULL ) { + av_log(avctx, AV_LOG_ERROR, + "XviD: No 2-pass information loaded for second pass\n"); + return -1; + } + + if( strlen(avctx->stats_in) > + write(fd, avctx->stats_in, strlen(avctx->stats_in)) ) { + close(fd); + av_log(avctx, AV_LOG_ERROR, + "XviD: Cannot write to 2-pass pipe\n"); + return -1; + } + + close(fd); + rc2pass2.filename = x->twopassfile; + plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2; + plugins[xvid_enc_create.num_plugins].param = &rc2pass2; + xvid_enc_create.num_plugins++; + } else if( !(xvid_flags & CODEC_FLAG_QSCALE) ) { + /* Single Pass Bitrate Control! */ + memset(&single, 0, sizeof(xvid_plugin_single_t)); + single.version = XVID_VERSION; + single.bitrate = avctx->bit_rate; + + plugins[xvid_enc_create.num_plugins].func = xvid_plugin_single; + plugins[xvid_enc_create.num_plugins].param = &single; + xvid_enc_create.num_plugins++; + } + + /* Luminance Masking */ + if( 0.0 != avctx->lumi_masking ) { + plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking; + plugins[xvid_enc_create.num_plugins].param = NULL; + xvid_enc_create.num_plugins++; + } + + /* Frame Rate and Key Frames */ + xvid_correct_framerate(avctx); + xvid_enc_create.fincr = avctx->time_base.num; + xvid_enc_create.fbase = avctx->time_base.den; + if( avctx->gop_size > 0 ) + xvid_enc_create.max_key_interval = avctx->gop_size; + else + xvid_enc_create.max_key_interval = 240; /* XviD's best default */ + + /* Quants */ + if( xvid_flags & CODEC_FLAG_QSCALE ) x->qscale = 1; + else x->qscale = 0; + + xvid_enc_create.min_quant[0] = avctx->qmin; + xvid_enc_create.min_quant[1] = avctx->qmin; + xvid_enc_create.min_quant[2] = avctx->qmin; + xvid_enc_create.max_quant[0] = avctx->qmax; + xvid_enc_create.max_quant[1] = avctx->qmax; + xvid_enc_create.max_quant[2] = avctx->qmax; + + /* Quant Matrices */ + x->intra_matrix = x->inter_matrix = NULL; + if( avctx->mpeg_quant ) + x->vol_flags |= XVID_VOL_MPEGQUANT; + if( (avctx->intra_matrix || avctx->inter_matrix) ) { + x->vol_flags |= XVID_VOL_MPEGQUANT; + + if( avctx->intra_matrix ) { + intra = avctx->intra_matrix; + x->intra_matrix = av_malloc(sizeof(unsigned char) * 64); + } else + intra = NULL; + if( avctx->inter_matrix ) { + inter = avctx->inter_matrix; + x->inter_matrix = av_malloc(sizeof(unsigned char) * 64); + } else + inter = NULL; + + for( i = 0; i < 64; i++ ) { + if( intra ) + x->intra_matrix[i] = (unsigned char)intra[i]; + if( inter ) + x->inter_matrix[i] = (unsigned char)inter[i]; + } + } + + /* Misc Settings */ + xvid_enc_create.frame_drop_ratio = 0; + xvid_enc_create.global = 0; + if( xvid_flags & CODEC_FLAG_CLOSED_GOP ) + xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP; + + /* Determines which codec mode we are operating in */ + avctx->extradata = NULL; + avctx->extradata_size = 0; + if( xvid_flags & CODEC_FLAG_GLOBAL_HEADER ) { + /* In this case, we are claiming to be MPEG4 */ + x->quicktime_format = 1; + avctx->codec_id = CODEC_ID_MPEG4; + } else { + /* We are claiming to be XviD */ + x->quicktime_format = 0; + if(!avctx->codec_tag) + avctx->codec_tag = ff_get_fourcc("xvid"); + } + + /* Bframes */ + xvid_enc_create.max_bframes = avctx->max_b_frames; + xvid_enc_create.bquant_offset = 100 * avctx->b_quant_offset; + xvid_enc_create.bquant_ratio = 100 * avctx->b_quant_factor; + if( avctx->max_b_frames > 0 && !x->quicktime_format ) xvid_enc_create.global |= XVID_GLOBAL_PACKED; + + /* Create encoder context */ + xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); + if( xerr ) { + av_log(avctx, AV_LOG_ERROR, "XviD: Could not create encoder reference\n"); + return -1; + } + + x->encoder_handle = xvid_enc_create.handle; + avctx->coded_frame = &x->encoded_picture; + + return 0; +} + +/** + * Encodes a single frame. + * + * @param avctx AVCodecContext pointer to context + * @param frame Pointer to encoded frame buffer + * @param buf_size Size of encoded frame buffer + * @param data Pointer to AVFrame of unencoded frame + * @return Returns 0 on success, -1 on failure + */ +int ff_xvid_encode_frame(AVCodecContext *avctx, + unsigned char *frame, int buf_size, void *data) { + int xerr, i; + char *tmp; + xvid_context_t *x = avctx->priv_data; + AVFrame *picture = data; + AVFrame *p = &(x->encoded_picture); + + xvid_enc_frame_t xvid_enc_frame; + xvid_enc_stats_t xvid_enc_stats; + + /* Start setting up the frame */ + memset(&xvid_enc_frame, 0, sizeof(xvid_enc_frame)); + xvid_enc_frame.version = XVID_VERSION; + memset(&xvid_enc_stats, 0, sizeof(xvid_enc_stats)); + xvid_enc_stats.version = XVID_VERSION; + *p = *picture; + + /* Let XviD know where to put the frame. */ + xvid_enc_frame.bitstream = frame; + xvid_enc_frame.length = buf_size; + + /* Initialize input image fields */ + if( avctx->pix_fmt != PIX_FMT_YUV420P ) { + av_log(avctx, AV_LOG_ERROR, "XviD: Color spaces other than 420p not supported\n"); + return -1; + } + + xvid_enc_frame.input.csp = XVID_CSP_PLANAR; /* YUV420P */ + + for( i = 0; i < 4; i++ ) { + xvid_enc_frame.input.plane[i] = picture->data[i]; + xvid_enc_frame.input.stride[i] = picture->linesize[i]; + } + + /* Encoder Flags */ + xvid_enc_frame.vop_flags = x->vop_flags; + xvid_enc_frame.vol_flags = x->vol_flags; + xvid_enc_frame.motion = x->me_flags; + xvid_enc_frame.type = XVID_TYPE_AUTO; + + /* Quant Setting */ + if( x->qscale ) xvid_enc_frame.quant = picture->quality / FF_QP2LAMBDA; + else xvid_enc_frame.quant = 0; + + /* Matrices */ + xvid_enc_frame.quant_intra_matrix = x->intra_matrix; + xvid_enc_frame.quant_inter_matrix = x->inter_matrix; + + /* Encode */ + xerr = xvid_encore(x->encoder_handle, XVID_ENC_ENCODE, + &xvid_enc_frame, &xvid_enc_stats); + + /* Two-pass log buffer swapping */ + avctx->stats_out = NULL; + if( x->twopassbuffer ) { + tmp = x->old_twopassbuffer; + x->old_twopassbuffer = x->twopassbuffer; + x->twopassbuffer = tmp; + x->twopassbuffer[0] = 0; + if( x->old_twopassbuffer[0] != 0 ) { + avctx->stats_out = x->old_twopassbuffer; + } + } + + if( 0 <= xerr ) { + p->quality = xvid_enc_stats.quant * FF_QP2LAMBDA; + if( xvid_enc_stats.type == XVID_TYPE_PVOP ) + p->pict_type = FF_P_TYPE; + else if( xvid_enc_stats.type == XVID_TYPE_BVOP ) + p->pict_type = FF_B_TYPE; + else if( xvid_enc_stats.type == XVID_TYPE_SVOP ) + p->pict_type = FF_S_TYPE; + else + p->pict_type = FF_I_TYPE; + if( xvid_enc_frame.out_flags & XVID_KEYFRAME ) { + p->key_frame = 1; + if( x->quicktime_format ) + return xvid_strip_vol_header(avctx, frame, + xvid_enc_stats.hlength, xerr); + } else + p->key_frame = 0; + + return xerr; + } else { + av_log(avctx, AV_LOG_ERROR, "XviD: Encoding Error Occurred: %i\n", xerr); + return -1; + } +} + +/** + * Destroys the private context for the encoder. + * All buffers are freed, and the XviD encoder context is destroyed. + * + * @param avctx AVCodecContext pointer to context + * @return Returns 0, success guaranteed + */ +int ff_xvid_encode_close(AVCodecContext *avctx) { + xvid_context_t *x = avctx->priv_data; + + xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL); + + if( avctx->extradata != NULL ) + av_free(avctx->extradata); + if( x->twopassbuffer != NULL ) { + av_free(x->twopassbuffer); + av_free(x->old_twopassbuffer); + } + if( x->twopassfile != NULL ) + av_free(x->twopassfile); + if( x->intra_matrix != NULL ) + av_free(x->intra_matrix); + if( x->inter_matrix != NULL ) + av_free(x->inter_matrix); + + return 0; +} + +/** + * Routine to create a global VO/VOL header for MP4 container. + * What we do here is extract the header from the XviD bitstream + * as it is encoded. We also strip the repeated headers from the + * bitstream when a global header is requested for MPEG-4 ISO + * compliance. + * + * @param avctx AVCodecContext pointer to context + * @param frame Pointer to encoded frame data + * @param header_len Length of header to search + * @param frame_len Length of encoded frame data + * @return Returns new length of frame data + */ +int xvid_strip_vol_header(AVCodecContext *avctx, + unsigned char *frame, + unsigned int header_len, + unsigned int frame_len) { + int vo_len = 0, i; + + for( i = 0; i < header_len - 3; i++ ) { + if( frame[i] == 0x00 && + frame[i+1] == 0x00 && + frame[i+2] == 0x01 && + frame[i+3] == 0xB6 ) { + vo_len = i; + break; + } + } + + if( vo_len > 0 ) { + /* We need to store the header, so extract it */ + if( avctx->extradata == NULL ) { + avctx->extradata = av_malloc(vo_len); + memcpy(avctx->extradata, frame, vo_len); + avctx->extradata_size = vo_len; + } + /* Less dangerous now, memmove properly copies the two + chunks of overlapping data */ + memmove(frame, &(frame[vo_len]), frame_len - vo_len); + return frame_len - vo_len; + } else + return frame_len; +} + +/** + * Routine to correct a possibly erroneous framerate being fed to us. + * XviD currently chokes on framerates where the ticks per frame is + * extremely large. This function works to correct problems in this area + * by estimating a new framerate and taking the simpler fraction of + * the two presented. + * + * @param avctx Context that contains the framerate to correct. + */ +void xvid_correct_framerate(AVCodecContext *avctx) { + int frate, fbase; + int est_frate, est_fbase; + int gcd; + float est_fps, fps; + + frate = avctx->time_base.den; + fbase = avctx->time_base.num; + + gcd = ff_gcd(frate, fbase); + if( gcd > 1 ) { + frate /= gcd; + fbase /= gcd; + } + + if( frate <= 65000 && fbase <= 65000 ) { + avctx->time_base.den = frate; + avctx->time_base.num = fbase; + return; + } + + fps = (float)frate / (float)fbase; + est_fps = roundf(fps * 1000.0) / 1000.0; + + est_frate = (int)est_fps; + if( est_fps > (int)est_fps ) { + est_frate = (est_frate + 1) * 1000; + est_fbase = (int)roundf((float)est_frate / est_fps); + } else + est_fbase = 1; + + gcd = ff_gcd(est_frate, est_fbase); + if( gcd > 1 ) { + est_frate /= gcd; + est_fbase /= gcd; + } + + if( fbase > est_fbase ) { + avctx->time_base.den = est_frate; + avctx->time_base.num = est_fbase; + av_log(avctx, AV_LOG_DEBUG, + "XviD: framerate re-estimated: %.2f, %.3f%% correction\n", + est_fps, (((est_fps - fps)/fps) * 100.0)); + } else { + avctx->time_base.den = frate; + avctx->time_base.num = fbase; + } +} + +/* + * XviD 2-Pass Kludge Section + * + * XviD's default 2-pass doesn't allow us to create data as we need to, so + * this section spends time replacing the first pass plugin so we can write + * statistic information as libavcodec requests in. We have another kludge + * that allows us to pass data to the second pass in XviD without a custom + * rate-control plugin. + */ + +/** + * Initializes the two-pass plugin and context. + * + * @param param Input construction parameter structure + * @param handle Private context handle + * @return Returns XVID_ERR_xxxx on failure, or 0 on success. + */ +static int xvid_ff_2pass_create(xvid_plg_create_t * param, + void ** handle) { + xvid_ff_pass1_t *x = (xvid_ff_pass1_t *)param->param; + char *log = x->context->twopassbuffer; + + /* Do a quick bounds check */ + if( log == NULL ) + return XVID_ERR_FAIL; + + /* We use snprintf() */ + /* This is because we can safely prevent a buffer overflow */ + log[0] = 0; + snprintf(log, BUFFER_REMAINING(log), + "# ffmpeg 2-pass log file, using xvid codec\n"); + snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log), + "# Do not modify. libxvidcore version: %d.%d.%d\n\n", + XVID_VERSION_MAJOR(XVID_VERSION), + XVID_VERSION_MINOR(XVID_VERSION), + XVID_VERSION_PATCH(XVID_VERSION)); + + *handle = x->context; + return 0; +} + +/** + * Destroys the two-pass plugin context. + * + * @param ref Context pointer for the plugin + * @param param Destrooy context + * @return Returns 0, success guaranteed + */ +static int xvid_ff_2pass_destroy(xvid_context_t *ref, + xvid_plg_destroy_t *param) { + /* Currently cannot think of anything to do on destruction */ + /* Still, the framework should be here for reference/use */ + if( ref->twopassbuffer != NULL ) + ref->twopassbuffer[0] = 0; + return 0; +} + +/** + * Enables fast encode mode during the first pass. + * + * @param ref Context pointer for the plugin + * @param param Frame data + * @return Returns 0, success guaranteed + */ +static int xvid_ff_2pass_before(xvid_context_t *ref, + xvid_plg_data_t *param) { + int motion_remove; + int motion_replacements; + int vop_remove; + + /* Nothing to do here, result is changed too much */ + if( param->zone && param->zone->mode == XVID_ZONE_QUANT ) + return 0; + + /* We can implement a 'turbo' first pass mode here */ + param->quant = 2; + + /* Init values */ + motion_remove = ~XVID_ME_CHROMA_PVOP & + ~XVID_ME_CHROMA_BVOP & + ~XVID_ME_EXTSEARCH16 & + ~XVID_ME_ADVANCEDDIAMOND16; + motion_replacements = XVID_ME_FAST_MODEINTERPOLATE | + XVID_ME_SKIP_DELTASEARCH | + XVID_ME_FASTREFINE16 | + XVID_ME_BFRAME_EARLYSTOP; + vop_remove = ~XVID_VOP_MODEDECISION_RD & + ~XVID_VOP_FAST_MODEDECISION_RD & + ~XVID_VOP_TRELLISQUANT & + ~XVID_VOP_INTER4V & + ~XVID_VOP_HQACPRED; + + param->vol_flags &= ~XVID_VOL_GMC; + param->vop_flags &= vop_remove; + param->motion_flags &= motion_remove; + param->motion_flags |= motion_replacements; + + return 0; +} + +/** + * Captures statistic data and writes it during first pass. + * + * @param ref Context pointer for the plugin + * @param param Statistic data + * @return Returns XVID_ERR_xxxx on failure, or 0 on success + */ +static int xvid_ff_2pass_after(xvid_context_t *ref, + xvid_plg_data_t *param) { + char *log = ref->twopassbuffer; + char *frame_types = " ipbs"; + char frame_type; + + /* Quick bounds check */ + if( log == NULL ) + return XVID_ERR_FAIL; + + /* Convert the type given to us into a character */ + if( param->type < 5 && param->type > 0 ) { + frame_type = frame_types[param->type]; + } else { + return XVID_ERR_FAIL; + } + + snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log), + "%c %d %d %d %d %d %d\n", + frame_type, param->stats.quant, param->stats.kblks, param->stats.mblks, + param->stats.ublks, param->stats.length, param->stats.hlength); + + return 0; +} + +/** + * Dispatch function for our custom plugin. + * This handles the dispatch for the XviD plugin. It passes data + * on to other functions for actual processing. + * + * @param ref Context pointer for the plugin + * @param cmd The task given for us to complete + * @param p1 First parameter (varies) + * @param p2 Second parameter (varies) + * @return Returns XVID_ERR_xxxx on failure, or 0 on success + */ +int xvid_ff_2pass(void *ref, int cmd, void *p1, void *p2) { + switch( cmd ) { + case XVID_PLG_INFO: + case XVID_PLG_FRAME: + return 0; + + case XVID_PLG_BEFORE: + return xvid_ff_2pass_before(ref, p1); + + case XVID_PLG_CREATE: + return xvid_ff_2pass_create(p1, p2); + + case XVID_PLG_AFTER: + return xvid_ff_2pass_after(ref, p1); + + case XVID_PLG_DESTROY: + return xvid_ff_2pass_destroy(ref, p1); + + default: + return XVID_ERR_FAIL; + } +} + +/** + * XviD codec definition for libavcodec. + */ +AVCodec libxvid_encoder = { + "libxvid", + CODEC_TYPE_VIDEO, + CODEC_ID_XVID, + sizeof(xvid_context_t), + ff_xvid_encode_init, + ff_xvid_encode_frame, + ff_xvid_encode_close, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, +}; diff --git a/contrib/ffmpeg/libavcodec/ljpegenc.c b/contrib/ffmpeg/libavcodec/ljpegenc.c new file mode 100644 index 000000000..0e717397b --- /dev/null +++ b/contrib/ffmpeg/libavcodec/ljpegenc.c @@ -0,0 +1,197 @@ +/* + * lossless JPEG encoder + * Copyright (c) 2000, 2001 Fabrice Bellard. + * Copyright (c) 2003 Alex Beregszaszi + * Copyright (c) 2003-2004 Michael Niedermayer + * + * Support for external huffman table, various fixes (AVID workaround), + * aspecting, new decode_frame mechanism and apple mjpeg-b support + * by Alex Beregszaszi + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file ljpegenc.c + * lossless JPEG encoder. + */ + +#include "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" +#include "mjpeg.h" +#include "mjpegenc.h" + + +static int encode_picture_lossless(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ + MpegEncContext * const s = avctx->priv_data; + MJpegContext * const m = s->mjpeg_ctx; + AVFrame *pict = data; + const int width= s->width; + const int height= s->height; + AVFrame * const p= (AVFrame*)&s->current_picture; + const int predictor= avctx->prediction_method+1; + + init_put_bits(&s->pb, buf, buf_size); + + *p = *pict; + p->pict_type= FF_I_TYPE; + p->key_frame= 1; + + ff_mjpeg_encode_picture_header(s); + + s->header_bits= put_bits_count(&s->pb); + + if(avctx->pix_fmt == PIX_FMT_RGB32){ + int x, y, i; + const int linesize= p->linesize[0]; + uint16_t (*buffer)[4]= (void *) s->rd_scratchpad; + int left[3], top[3], topleft[3]; + + for(i=0; i<3; i++){ + buffer[0][i]= 1 << (9 - 1); + } + + for(y = 0; y < height; y++) { + const int modified_predictor= y ? predictor : 1; + uint8_t *ptr = p->data[0] + (linesize * y); + + if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < width*3*4){ + av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); + return -1; + } + + for(i=0; i<3; i++){ + top[i]= left[i]= topleft[i]= buffer[0][i]; + } + for(x = 0; x < width; x++) { + buffer[x][1] = ptr[4*x+0] - ptr[4*x+1] + 0x100; + buffer[x][2] = ptr[4*x+2] - ptr[4*x+1] + 0x100; + buffer[x][0] = (ptr[4*x+0] + 2*ptr[4*x+1] + ptr[4*x+2])>>2; + + for(i=0;i<3;i++) { + int pred, diff; + + PREDICT(pred, topleft[i], top[i], left[i], modified_predictor); + + topleft[i]= top[i]; + top[i]= buffer[x+1][i]; + + left[i]= buffer[x][i]; + + diff= ((left[i] - pred + 0x100)&0x1FF) - 0x100; + + if(i==0) + ff_mjpeg_encode_dc(s, diff, m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly + else + ff_mjpeg_encode_dc(s, diff, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance); + } + } + } + }else{ + int mb_x, mb_y, i; + const int mb_width = (width + s->mjpeg_hsample[0] - 1) / s->mjpeg_hsample[0]; + const int mb_height = (height + s->mjpeg_vsample[0] - 1) / s->mjpeg_vsample[0]; + + for(mb_y = 0; mb_y < mb_height; mb_y++) { + if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < mb_width * 4 * 3 * s->mjpeg_hsample[0] * s->mjpeg_vsample[0]){ + av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); + return -1; + } + for(mb_x = 0; mb_x < mb_width; mb_x++) { + if(mb_x==0 || mb_y==0){ + for(i=0;i<3;i++) { + uint8_t *ptr; + int x, y, h, v, linesize; + h = s->mjpeg_hsample[i]; + v = s->mjpeg_vsample[i]; + linesize= p->linesize[i]; + + for(y=0; ydata[i] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap + if(y==0 && mb_y==0){ + if(x==0 && mb_x==0){ + pred= 128; + }else{ + pred= ptr[-1]; + } + }else{ + if(x==0 && mb_x==0){ + pred= ptr[-linesize]; + }else{ + PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor); + } + } + + if(i==0) + ff_mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly + else + ff_mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_chrominance, m->huff_code_dc_chrominance); + } + } + } + }else{ + for(i=0;i<3;i++) { + uint8_t *ptr; + int x, y, h, v, linesize; + h = s->mjpeg_hsample[i]; + v = s->mjpeg_vsample[i]; + linesize= p->linesize[i]; + + for(y=0; ydata[i] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap +//printf("%d %d %d %d %8X\n", mb_x, mb_y, x, y, ptr); + PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor); + + if(i==0) + ff_mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly + else + ff_mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_chrominance, m->huff_code_dc_chrominance); + } + } + } + } + } + } + } + + emms_c(); + + ff_mjpeg_encode_picture_trailer(s); + s->picture_number++; + + flush_put_bits(&s->pb); + return pbBufPtr(&s->pb) - s->pb.buf; +// return (put_bits_count(&f->pb)+7)/8; +} + + +AVCodec ljpeg_encoder = { //FIXME avoid MPV_* lossless JPEG should not need them + "ljpeg", + CODEC_TYPE_VIDEO, + CODEC_ID_LJPEG, + sizeof(MpegEncContext), + MPV_encode_init, + encode_picture_lossless, + MPV_encode_end, +}; diff --git a/contrib/ffmpeg/libavcodec/loco.c b/contrib/ffmpeg/libavcodec/loco.c index 760699d45..14be6f019 100644 --- a/contrib/ffmpeg/libavcodec/loco.c +++ b/contrib/ffmpeg/libavcodec/loco.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -26,7 +25,6 @@ */ #include "avcodec.h" -#include "common.h" #include "bitstream.h" #include "golomb.h" @@ -118,7 +116,7 @@ static inline int loco_predict(uint8_t* data, int stride, int step) } static int loco_decode_plane(LOCOContext *l, uint8_t *data, int width, int height, - int stride, uint8_t *buf, int buf_size, int step) + int stride, const uint8_t *buf, int buf_size, int step) { RICEContext rc; int val; @@ -159,7 +157,7 @@ static int loco_decode_plane(LOCOContext *l, uint8_t *data, int width, int heigh static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { LOCOContext * const l = avctx->priv_data; AVFrame * const p= (AVFrame*)&l->pic; diff --git a/contrib/ffmpeg/libavcodec/lzw.c b/contrib/ffmpeg/libavcodec/lzw.c index 6bc0b9a48..833c9d0ab 100644 --- a/contrib/ffmpeg/libavcodec/lzw.c +++ b/contrib/ffmpeg/libavcodec/lzw.c @@ -42,7 +42,7 @@ static const uint16_t mask[17] = }; struct LZWState { - uint8_t *pbuf, *ebuf; + const uint8_t *pbuf, *ebuf; int bbits; unsigned int bbuf; @@ -91,7 +91,7 @@ static int lzw_get_code(struct LZWState * s) return c & s->curmask; } -uint8_t* ff_lzw_cur_ptr(LZWState *p) +const uint8_t* ff_lzw_cur_ptr(LZWState *p) { return ((struct LZWState*)p)->pbuf; } @@ -127,7 +127,7 @@ void ff_lzw_decode_close(LZWState **p) * @param buf_size input data size * @param mode decoder working mode - either GIF or TIFF */ -int ff_lzw_decode_init(LZWState *p, int csize, uint8_t *buf, int buf_size, int mode) +int ff_lzw_decode_init(LZWState *p, int csize, const uint8_t *buf, int buf_size, int mode) { struct LZWState *s = (struct LZWState *)p; diff --git a/contrib/ffmpeg/libavcodec/lzw.h b/contrib/ffmpeg/libavcodec/lzw.h index 60f115caf..161f0dce5 100644 --- a/contrib/ffmpeg/libavcodec/lzw.h +++ b/contrib/ffmpeg/libavcodec/lzw.h @@ -27,8 +27,10 @@ * Modified for use in TIFF by Konstantin Shishkov */ -#ifndef LZW_H -#define LZW_H +#ifndef FFMPEG_LZW_H +#define FFMPEG_LZW_H + +#include "bitstream.h" enum FF_LZW_MODES{ FF_LZW_GIF, @@ -41,9 +43,17 @@ typedef void LZWState; /* first two functions de/allocate memory for LZWState */ void ff_lzw_decode_open(LZWState **p); void ff_lzw_decode_close(LZWState **p); -int ff_lzw_decode_init(LZWState *s, int csize, uint8_t *buf, int buf_size, int mode); +int ff_lzw_decode_init(LZWState *s, int csize, const uint8_t *buf, int buf_size, int mode); int ff_lzw_decode(LZWState *s, uint8_t *buf, int len); -uint8_t* ff_lzw_cur_ptr(LZWState *lzw); +const uint8_t* ff_lzw_cur_ptr(LZWState *lzw); void ff_lzw_decode_tail(LZWState *lzw); -#endif +/** LZW encode state */ +struct LZWEncodeState; +extern const int ff_lzw_encode_state_size; + +void ff_lzw_encode_init(struct LZWEncodeState * s, uint8_t * outbuf, int outsize, int maxbits); +int ff_lzw_encode(struct LZWEncodeState * s, const uint8_t * inbuf, int insize); +int ff_lzw_encode_flush(struct LZWEncodeState * s); + +#endif /* FFMPEG_LZW_H */ diff --git a/contrib/ffmpeg/libavcodec/lzwenc.c b/contrib/ffmpeg/libavcodec/lzwenc.c new file mode 100644 index 000000000..3a24af347 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/lzwenc.c @@ -0,0 +1,262 @@ +/* + * LZW encoder + * Copyright (c) 2007 Bartlomiej Wolowiec + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * LZW encoder + * @file lzwenc.c + * @author Bartlomiej Wolowiec + */ + +#include "avcodec.h" +#include "bitstream.h" +#include "lzw.h" + +#define LZW_MAXBITS 12 +#define LZW_SIZTABLE (1<= LZW_HASH_SIZE) + head -= LZW_HASH_SIZE; + assert(head >= 0 && head < LZW_HASH_SIZE); + return head; +} + +/** + * Hash function calculates next hash value + * @param head Actual hash code + * @param offset Offset calculated by hashOffset + * @return New hash value + */ +static inline int hashNext(int head, const int offset) +{ + head -= offset; + if(head < 0) + head += LZW_HASH_SIZE; + return head; +} + +/** + * Hash function calculates hash offset + * @param head Actual hash code + * @return Hash offset + */ +static inline int hashOffset(const int head) +{ + return head ? LZW_HASH_SIZE - head : 1; +} + +/** + * Write one code to stream + * @param s LZW state + * @param c code to write + */ +static inline void writeCode(LZWEncodeState * s, int c) +{ + assert(0 <= c && c < 1 << s->bits); + put_bits(&s->pb, s->bits, c); +} + + +/** + * Find LZW code for block + * @param s LZW state + * @param c Last character in block + * @param hash_prefix LZW code for prefix + * @return LZW code for block or -1 if not found in table + */ +static inline int findCode(LZWEncodeState * s, uint8_t c, int hash_prefix) +{ + int h = hash(FFMAX(hash_prefix, 0), c); + int hash_offset = hashOffset(h); + + while (s->tab[h].hash_prefix != LZW_PREFIX_FREE) { + if ((s->tab[h].suffix == c) + && (s->tab[h].hash_prefix == hash_prefix)) + return h; + h = hashNext(h, hash_offset); + } + + return h; +} + +/** + * Add block to LZW code table + * @param s LZW state + * @param c Last character in block + * @param hash_prefix LZW code for prefix + * @param hash_code LZW code for bytes block + */ +static inline void addCode(LZWEncodeState * s, uint8_t c, int hash_prefix, int hash_code) +{ + s->tab[hash_code].code = s->tabsize; + s->tab[hash_code].suffix = c; + s->tab[hash_code].hash_prefix = hash_prefix; + + s->tabsize++; + + if (s->tabsize >= 1 << s->bits) + s->bits++; +} + +/** + * Clear LZW code table + * @param s LZW state + */ +static void clearTable(LZWEncodeState * s) +{ + int i, h; + + writeCode(s, s->clear_code); + s->bits = 9; + for (i = 0; i < LZW_HASH_SIZE; i++) { + s->tab[i].hash_prefix = LZW_PREFIX_FREE; + } + for (i = 0; i < 256; i++) { + h = hash(0, i); + s->tab[h].code = i; + s->tab[h].suffix = i; + s->tab[h].hash_prefix = LZW_PREFIX_EMPTY; + } + s->tabsize = 258; +} + +/** + * Calculate number of bytes written + * @param s LZW encode state + * @return Number of bytes written + */ +static int writtenBytes(LZWEncodeState *s){ + int ret = put_bits_count(&s->pb) >> 3; + ret -= s->output_bytes; + s->output_bytes += ret; + return ret; +} + +/** + * Initialize LZW encoder. Please set s->clear_code, s->end_code and s->maxbits before run. + * @param s LZW state + * @param outbuf Output buffer + * @param outsize Size of output buffer + * @param maxbits Maximum length of code + */ +void ff_lzw_encode_init(LZWEncodeState * s, uint8_t * outbuf, int outsize, int maxbits) +{ + s->clear_code = 256; + s->end_code = 257; + s->maxbits = maxbits; + init_put_bits(&s->pb, outbuf, outsize); + s->bufsize = outsize; + assert(9 <= s->maxbits && s->maxbits <= s->maxbits); + s->maxcode = 1 << s->maxbits; + s->output_bytes = 0; + s->last_code = LZW_PREFIX_EMPTY; + s->bits = 9; +} + +/** + * LZW main compress function + * @param s LZW state + * @param inbuf Input buffer + * @param insize Size of input buffer + * @return Number of bytes written or -1 on error + */ +int ff_lzw_encode(LZWEncodeState * s, const uint8_t * inbuf, int insize) +{ + int i; + + if(insize * 3 > (s->bufsize - s->output_bytes) * 2){ + return -1; + } + + if (s->last_code == LZW_PREFIX_EMPTY) + clearTable(s); + + for (i = 0; i < insize; i++) { + uint8_t c = *inbuf++; + int code = findCode(s, c, s->last_code); + if (s->tab[code].hash_prefix == LZW_PREFIX_FREE) { + writeCode(s, s->last_code); + addCode(s, c, s->last_code, code); + code= hash(0, c); + } + s->last_code = s->tab[code].code; + if (s->tabsize >= s->maxcode - 1) { + clearTable(s); + } + } + + return writtenBytes(s); +} + +/** + * Write end code and flush bitstream + * @param s LZW state + * @return Number of bytes written or -1 on error + */ +int ff_lzw_encode_flush(LZWEncodeState * s) +{ + if (s->last_code != -1) + writeCode(s, s->last_code); + writeCode(s, s->end_code); + flush_put_bits(&s->pb); + s->last_code = -1; + + return writtenBytes(s); +} diff --git a/contrib/ffmpeg/libavcodec/mace.c b/contrib/ffmpeg/libavcodec/mace.c index 95839379a..7256f7678 100644 --- a/contrib/ffmpeg/libavcodec/mace.c +++ b/contrib/ffmpeg/libavcodec/mace.c @@ -263,7 +263,7 @@ static void chomp3(MACEContext *ctx, /* /// "Exp1to3()" */ static void Exp1to3(MACEContext *ctx, - uint8_t *inBuffer, + const uint8_t *inBuffer, void *outBuffer, uint32_t cnt, uint32_t numChannels, @@ -347,7 +347,7 @@ static void chomp6(MACEContext *ctx, /* /// "Exp1to6()" */ static void Exp1to6(MACEContext *ctx, - uint8_t *inBuffer, + const uint8_t *inBuffer, void *outBuffer, uint32_t cnt, uint32_t numChannels, @@ -401,7 +401,7 @@ static int mace_decode_init(AVCodecContext * avctx) static int mace_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { short *samples; MACEContext *c = avctx->priv_data; @@ -409,18 +409,14 @@ static int mace_decode_frame(AVCodecContext *avctx, samples = (short *)data; switch (avctx->codec->id) { case CODEC_ID_MACE3: -#ifdef DEBUG -puts("mace_decode_frame[3]()"); -#endif + dprintf(avctx, "mace_decode_frame[3]()"); Exp1to3(c, buf, samples, buf_size / 2 / avctx->channels, avctx->channels, 1); if (avctx->channels == 2) Exp1to3(c, buf, samples+1, buf_size / 2 / 2, 2, 2); *data_size = 2 * 3 * buf_size; break; case CODEC_ID_MACE6: -#ifdef DEBUG -puts("mace_decode_frame[6]()"); -#endif + dprintf(avctx, "mace_decode_frame[6]()"); Exp1to6(c, buf, samples, buf_size / avctx->channels, avctx->channels, 1); if (avctx->channels == 2) Exp1to6(c, buf, samples+1, buf_size / 2, 2, 2); diff --git a/contrib/ffmpeg/libavcodec/mathops.h b/contrib/ffmpeg/libavcodec/mathops.h index c6ec70597..38b1f5c65 100644 --- a/contrib/ffmpeg/libavcodec/mathops.h +++ b/contrib/ffmpeg/libavcodec/mathops.h @@ -19,8 +19,10 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef MATHOPS_H -#define MATHOPS_H +#ifndef FFMPEG_MATHOPS_H +#define FFMPEG_MATHOPS_H + +#include "common.h" #ifdef ARCH_X86_32 @@ -34,6 +36,10 @@ #include "ppc/mathops.h" +#elif defined(ARCH_BFIN) + +#include "bfin/mathops.h" + #endif /* generic implementation */ @@ -65,5 +71,5 @@ static av_always_inline int MULH(int a, int b){ # define MUL16(ra, rb) ((ra) * (rb)) #endif -#endif //MATHOPS_H +#endif /* FFMPEG_MATHOPS_H */ diff --git a/contrib/ffmpeg/libavcodec/mdct.c b/contrib/ffmpeg/libavcodec/mdct.c index de3275289..e809fcdcb 100644 --- a/contrib/ffmpeg/libavcodec/mdct.c +++ b/contrib/ffmpeg/libavcodec/mdct.c @@ -25,6 +25,29 @@ * MDCT/IMDCT transforms. */ +// Generate a Kaiser-Bessel Derived Window. +#define BESSEL_I0_ITER 50 // default: 50 iterations of Bessel I0 approximation +void ff_kbd_window_init(float *window, float alpha, int n) +{ + int i, j; + double sum = 0.0, bessel, tmp; + double local_window[n]; + double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n); + + for (i = 0; i < n; i++) { + tmp = i * (n - i) * alpha2; + bessel = 1.0; + for (j = BESSEL_I0_ITER; j > 0; j--) + bessel = bessel * tmp / (j * j) + 1; + sum += bessel; + local_window[i] = sum; + } + + sum++; + for (i = 0; i < n; i++) + window[i] = sqrt(local_window[i] / sum); +} + /** * init MDCT or IMDCT computation. */ diff --git a/contrib/ffmpeg/libavcodec/mdec.c b/contrib/ffmpeg/libavcodec/mdec.c index ee43b2777..ed2476213 100644 --- a/contrib/ffmpeg/libavcodec/mdec.c +++ b/contrib/ffmpeg/libavcodec/mdec.c @@ -2,6 +2,8 @@ * PSX MDEC codec * Copyright (c) 2003 Michael Niedermayer * + * based upon code from Sebastian Jedruszkiewicz + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -17,8 +19,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * based upon code from Sebastian Jedruszkiewicz */ /** @@ -60,7 +60,7 @@ static inline int mdec_decode_block_intra(MDECContext *a, DCTELEM *block, int n) { int level, diff, i, j, run; int component; - RLTable *rl = &rl_mpeg1; + RLTable *rl = &ff_rl_mpeg1; uint8_t * const scantable= a->scantable.permutated; const uint16_t *quant_matrix= ff_mpeg1_default_intra_matrix; const int qscale= a->qscale; @@ -158,7 +158,7 @@ static inline void idct_put(MDECContext *a, int mb_x, int mb_y){ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { MDECContext * const a = avctx->priv_data; AVFrame *picture = data; @@ -175,9 +175,6 @@ static int decode_frame(AVCodecContext *avctx, } p->pict_type= I_TYPE; p->key_frame= 1; - a->last_dc[0]= - a->last_dc[1]= - a->last_dc[2]= 0; a->bitstream_buffer= av_fast_realloc(a->bitstream_buffer, &a->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); for(i=0; iqscale= get_bits(&a->gb, 16); a->version= get_bits(&a->gb, 16); + a->last_dc[0]= + a->last_dc[1]= + a->last_dc[2]= 128; + // printf("qscale:%d (0x%X), version:%d (0x%X)\n", a->qscale, a->qscale, a->version, a->version); for(a->mb_x=0; a->mb_xmb_width; a->mb_x++){ diff --git a/contrib/ffmpeg/libavcodec/mjpeg.c b/contrib/ffmpeg/libavcodec/mjpeg.c index e3583e54e..08ffb95a7 100644 --- a/contrib/ffmpeg/libavcodec/mjpeg.c +++ b/contrib/ffmpeg/libavcodec/mjpeg.c @@ -4,6 +4,10 @@ * Copyright (c) 2003 Alex Beregszaszi * Copyright (c) 2003-2004 Michael Niedermayer * + * Support for external huffman table, various fixes (AVID workaround), + * aspecting, new decode_frame mechanism and apple mjpeg-b support + * by Alex Beregszaszi + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -19,10 +23,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Support for external huffman table, various fixes (AVID workaround), - * aspecting, new decode_frame mechanism and apple mjpeg-b support - * by Alex Beregszaszi */ /** @@ -30,118 +30,15 @@ * MJPEG encoder and decoder. */ -//#define DEBUG -#include - -#include "avcodec.h" -#include "dsputil.h" -#include "mpegvideo.h" -#include "bytestream.h" - -/* use two quantizer tables (one for luminance and one for chrominance) */ -/* not yet working */ -#undef TWOMATRIXES - -typedef struct MJpegContext { - uint8_t huff_size_dc_luminance[12]; //FIXME use array [3] instead of lumi / chrom, for easier addressing - uint16_t huff_code_dc_luminance[12]; - uint8_t huff_size_dc_chrominance[12]; - uint16_t huff_code_dc_chrominance[12]; - - uint8_t huff_size_ac_luminance[256]; - uint16_t huff_code_ac_luminance[256]; - uint8_t huff_size_ac_chrominance[256]; - uint16_t huff_code_ac_chrominance[256]; -} MJpegContext; - -/* JPEG marker codes */ -typedef enum { - /* start of frame */ - SOF0 = 0xc0, /* baseline */ - SOF1 = 0xc1, /* extended sequential, huffman */ - SOF2 = 0xc2, /* progressive, huffman */ - SOF3 = 0xc3, /* lossless, huffman */ - - SOF5 = 0xc5, /* differential sequential, huffman */ - SOF6 = 0xc6, /* differential progressive, huffman */ - SOF7 = 0xc7, /* differential lossless, huffman */ - JPG = 0xc8, /* reserved for JPEG extension */ - SOF9 = 0xc9, /* extended sequential, arithmetic */ - SOF10 = 0xca, /* progressive, arithmetic */ - SOF11 = 0xcb, /* lossless, arithmetic */ - - SOF13 = 0xcd, /* differential sequential, arithmetic */ - SOF14 = 0xce, /* differential progressive, arithmetic */ - SOF15 = 0xcf, /* differential lossless, arithmetic */ - - DHT = 0xc4, /* define huffman tables */ - - DAC = 0xcc, /* define arithmetic-coding conditioning */ - - /* restart with modulo 8 count "m" */ - RST0 = 0xd0, - RST1 = 0xd1, - RST2 = 0xd2, - RST3 = 0xd3, - RST4 = 0xd4, - RST5 = 0xd5, - RST6 = 0xd6, - RST7 = 0xd7, +#include "mjpeg.h" - SOI = 0xd8, /* start of image */ - EOI = 0xd9, /* end of image */ - SOS = 0xda, /* start of scan */ - DQT = 0xdb, /* define quantization tables */ - DNL = 0xdc, /* define number of lines */ - DRI = 0xdd, /* define restart interval */ - DHP = 0xde, /* define hierarchical progression */ - EXP = 0xdf, /* expand reference components */ - - APP0 = 0xe0, - APP1 = 0xe1, - APP2 = 0xe2, - APP3 = 0xe3, - APP4 = 0xe4, - APP5 = 0xe5, - APP6 = 0xe6, - APP7 = 0xe7, - APP8 = 0xe8, - APP9 = 0xe9, - APP10 = 0xea, - APP11 = 0xeb, - APP12 = 0xec, - APP13 = 0xed, - APP14 = 0xee, - APP15 = 0xef, - - JPG0 = 0xf0, - JPG1 = 0xf1, - JPG2 = 0xf2, - JPG3 = 0xf3, - JPG4 = 0xf4, - JPG5 = 0xf5, - JPG6 = 0xf6, - SOF48 = 0xf7, ///< JPEG-LS - LSE = 0xf8, ///< JPEG-LS extension parameters - JPG9 = 0xf9, - JPG10 = 0xfa, - JPG11 = 0xfb, - JPG12 = 0xfc, - JPG13 = 0xfd, - - COM = 0xfe, /* comment */ - - TEM = 0x01, /* temporary private use for arithmetic coding */ - - /* 0x02 -> 0xbf reserved */ -} JPEG_MARKER; #if 0 /* These are the sample quantization tables given in JPEG spec section K.1. * The spec says that the values given produce "good" quality, and * when divided by 2, "very good" quality. */ -static const unsigned char std_luminance_quant_tbl[64] = { +const unsigned char std_luminance_quant_tbl[64] = { 16, 11, 10, 16, 24, 40, 51, 61, 12, 12, 14, 19, 26, 58, 60, 55, 14, 13, 16, 24, 40, 57, 69, 56, @@ -151,7 +48,7 @@ static const unsigned char std_luminance_quant_tbl[64] = { 49, 64, 78, 87, 103, 121, 120, 101, 72, 92, 95, 98, 112, 100, 103, 99 }; -static const unsigned char std_chrominance_quant_tbl[64] = { +const unsigned char std_chrominance_quant_tbl[64] = { 17, 18, 24, 47, 99, 99, 99, 99, 18, 21, 26, 66, 99, 99, 99, 99, 24, 26, 56, 99, 99, 99, 99, 99, @@ -165,19 +62,19 @@ static const unsigned char std_chrominance_quant_tbl[64] = { /* Set up the standard Huffman tables (cf. JPEG standard section K.3) */ /* IMPORTANT: these are only valid for 8-bit data precision! */ -static const uint8_t bits_dc_luminance[17] = +const uint8_t ff_mjpeg_bits_dc_luminance[17] = { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; -static const uint8_t val_dc_luminance[] = +const uint8_t ff_mjpeg_val_dc_luminance[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; -static const uint8_t bits_dc_chrominance[17] = +const uint8_t ff_mjpeg_bits_dc_chrominance[17] = { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }; -static const uint8_t val_dc_chrominance[] = +const uint8_t ff_mjpeg_val_dc_chrominance[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; -static const uint8_t bits_ac_luminance[17] = +const uint8_t ff_mjpeg_bits_ac_luminance[17] = { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d }; -static const uint8_t val_ac_luminance[] = +const uint8_t ff_mjpeg_val_ac_luminance[] = { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, @@ -201,10 +98,10 @@ static const uint8_t val_ac_luminance[] = 0xf9, 0xfa }; -static const uint8_t bits_ac_chrominance[17] = +const uint8_t ff_mjpeg_bits_ac_chrominance[17] = { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 }; -static const uint8_t val_ac_chrominance[] = +const uint8_t ff_mjpeg_val_ac_chrominance[] = { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, @@ -229,8 +126,9 @@ static const uint8_t val_ac_chrominance[] = }; /* isn't this function nicer than the one in the libjpeg ? */ -static void build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code, - const uint8_t *bits_table, const uint8_t *val_table) +void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code, + const uint8_t *bits_table, + const uint8_t *val_table) { int i, j, k,nb, code, sym; @@ -247,2405 +145,3 @@ static void build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code, code <<= 1; } } - -#ifdef CONFIG_ENCODERS -int mjpeg_init(MpegEncContext *s) -{ - MJpegContext *m; - - m = av_malloc(sizeof(MJpegContext)); - if (!m) - return -1; - - s->min_qcoeff=-1023; - s->max_qcoeff= 1023; - - /* build all the huffman tables */ - build_huffman_codes(m->huff_size_dc_luminance, - m->huff_code_dc_luminance, - bits_dc_luminance, - val_dc_luminance); - build_huffman_codes(m->huff_size_dc_chrominance, - m->huff_code_dc_chrominance, - bits_dc_chrominance, - val_dc_chrominance); - build_huffman_codes(m->huff_size_ac_luminance, - m->huff_code_ac_luminance, - bits_ac_luminance, - val_ac_luminance); - build_huffman_codes(m->huff_size_ac_chrominance, - m->huff_code_ac_chrominance, - bits_ac_chrominance, - val_ac_chrominance); - - s->mjpeg_ctx = m; - return 0; -} - -void mjpeg_close(MpegEncContext *s) -{ - av_free(s->mjpeg_ctx); -} -#endif //CONFIG_ENCODERS - -#define PREDICT(ret, topleft, top, left, predictor)\ - switch(predictor){\ - case 1: ret= left; break;\ - case 2: ret= top; break;\ - case 3: ret= topleft; break;\ - case 4: ret= left + top - topleft; break;\ - case 5: ret= left + ((top - topleft)>>1); break;\ - case 6: ret= top + ((left - topleft)>>1); break;\ - default:\ - case 7: ret= (left + top)>>1; break;\ - } - -#ifdef CONFIG_ENCODERS -static inline void put_marker(PutBitContext *p, int code) -{ - put_bits(p, 8, 0xff); - put_bits(p, 8, code); -} - -/* table_class: 0 = DC coef, 1 = AC coefs */ -static int put_huffman_table(MpegEncContext *s, int table_class, int table_id, - const uint8_t *bits_table, const uint8_t *value_table) -{ - PutBitContext *p = &s->pb; - int n, i; - - put_bits(p, 4, table_class); - put_bits(p, 4, table_id); - - n = 0; - for(i=1;i<=16;i++) { - n += bits_table[i]; - put_bits(p, 8, bits_table[i]); - } - - for(i=0;ipb; - int i, j, size; - uint8_t *ptr; - - /* quant matrixes */ - put_marker(p, DQT); -#ifdef TWOMATRIXES - put_bits(p, 16, 2 + 2 * (1 + 64)); -#else - put_bits(p, 16, 2 + 1 * (1 + 64)); -#endif - put_bits(p, 4, 0); /* 8 bit precision */ - put_bits(p, 4, 0); /* table 0 */ - for(i=0;i<64;i++) { - j = s->intra_scantable.permutated[i]; - put_bits(p, 8, s->intra_matrix[j]); - } -#ifdef TWOMATRIXES - put_bits(p, 4, 0); /* 8 bit precision */ - put_bits(p, 4, 1); /* table 1 */ - for(i=0;i<64;i++) { - j = s->intra_scantable.permutated[i]; - put_bits(p, 8, s->chroma_intra_matrix[j]); - } -#endif - - /* huffman table */ - put_marker(p, DHT); - flush_put_bits(p); - ptr = pbBufPtr(p); - put_bits(p, 16, 0); /* patched later */ - size = 2; - size += put_huffman_table(s, 0, 0, bits_dc_luminance, val_dc_luminance); - size += put_huffman_table(s, 0, 1, bits_dc_chrominance, val_dc_chrominance); - - size += put_huffman_table(s, 1, 0, bits_ac_luminance, val_ac_luminance); - size += put_huffman_table(s, 1, 1, bits_ac_chrominance, val_ac_chrominance); - ptr[0] = size >> 8; - ptr[1] = size; -} - -static void jpeg_put_comments(MpegEncContext *s) -{ - PutBitContext *p = &s->pb; - int size; - uint8_t *ptr; - - if (s->aspect_ratio_info /* && !lossless */) - { - /* JFIF header */ - put_marker(p, APP0); - put_bits(p, 16, 16); - ff_put_string(p, "JFIF", 1); /* this puts the trailing zero-byte too */ - put_bits(p, 16, 0x0201); /* v 1.02 */ - put_bits(p, 8, 0); /* units type: 0 - aspect ratio */ - put_bits(p, 16, s->avctx->sample_aspect_ratio.num); - put_bits(p, 16, s->avctx->sample_aspect_ratio.den); - put_bits(p, 8, 0); /* thumbnail width */ - put_bits(p, 8, 0); /* thumbnail height */ - } - - /* comment */ - if(!(s->flags & CODEC_FLAG_BITEXACT)){ - put_marker(p, COM); - flush_put_bits(p); - ptr = pbBufPtr(p); - put_bits(p, 16, 0); /* patched later */ - ff_put_string(p, LIBAVCODEC_IDENT, 1); - size = strlen(LIBAVCODEC_IDENT)+3; - ptr[0] = size >> 8; - ptr[1] = size; - } - - if( s->avctx->pix_fmt == PIX_FMT_YUV420P - ||s->avctx->pix_fmt == PIX_FMT_YUV422P - ||s->avctx->pix_fmt == PIX_FMT_YUV444P){ - put_marker(p, COM); - flush_put_bits(p); - ptr = pbBufPtr(p); - put_bits(p, 16, 0); /* patched later */ - ff_put_string(p, "CS=ITU601", 1); - size = strlen("CS=ITU601")+3; - ptr[0] = size >> 8; - ptr[1] = size; - } -} - -void mjpeg_picture_header(MpegEncContext *s) -{ - const int lossless= s->avctx->codec_id != CODEC_ID_MJPEG; - const int ls = s->avctx->codec_id == CODEC_ID_JPEGLS; - - assert(!(ls && s->mjpeg_write_tables)); - - put_marker(&s->pb, SOI); - - if (!s->mjpeg_data_only_frames) - { - jpeg_put_comments(s); - - if (s->mjpeg_write_tables) jpeg_table_header(s); - - switch(s->avctx->codec_id){ - case CODEC_ID_MJPEG: put_marker(&s->pb, SOF0 ); break; - case CODEC_ID_LJPEG: put_marker(&s->pb, SOF3 ); break; - case CODEC_ID_JPEGLS: put_marker(&s->pb, SOF48); break; - default: assert(0); - } - - put_bits(&s->pb, 16, 17); - if(lossless && s->avctx->pix_fmt == PIX_FMT_RGB32) - put_bits(&s->pb, 8, 9); /* 9 bits/component RCT */ - else - put_bits(&s->pb, 8, 8); /* 8 bits/component */ - put_bits(&s->pb, 16, s->height); - put_bits(&s->pb, 16, s->width); - put_bits(&s->pb, 8, 3); /* 3 components */ - - /* Y component */ - put_bits(&s->pb, 8, 1); /* component number */ - put_bits(&s->pb, 4, s->mjpeg_hsample[0]); /* H factor */ - put_bits(&s->pb, 4, s->mjpeg_vsample[0]); /* V factor */ - put_bits(&s->pb, 8, 0); /* select matrix */ - - /* Cb component */ - put_bits(&s->pb, 8, 2); /* component number */ - put_bits(&s->pb, 4, s->mjpeg_hsample[1]); /* H factor */ - put_bits(&s->pb, 4, s->mjpeg_vsample[1]); /* V factor */ -#ifdef TWOMATRIXES - put_bits(&s->pb, 8, lossless ? 0 : 1); /* select matrix */ -#else - put_bits(&s->pb, 8, 0); /* select matrix */ -#endif - - /* Cr component */ - put_bits(&s->pb, 8, 3); /* component number */ - put_bits(&s->pb, 4, s->mjpeg_hsample[2]); /* H factor */ - put_bits(&s->pb, 4, s->mjpeg_vsample[2]); /* V factor */ -#ifdef TWOMATRIXES - put_bits(&s->pb, 8, lossless ? 0 : 1); /* select matrix */ -#else - put_bits(&s->pb, 8, 0); /* select matrix */ -#endif - } - - /* scan header */ - put_marker(&s->pb, SOS); - put_bits(&s->pb, 16, 12); /* length */ - put_bits(&s->pb, 8, 3); /* 3 components */ - - /* Y component */ - put_bits(&s->pb, 8, 1); /* index */ - put_bits(&s->pb, 4, 0); /* DC huffman table index */ - put_bits(&s->pb, 4, 0); /* AC huffman table index */ - - /* Cb component */ - put_bits(&s->pb, 8, 2); /* index */ - put_bits(&s->pb, 4, 1); /* DC huffman table index */ - put_bits(&s->pb, 4, lossless ? 0 : 1); /* AC huffman table index */ - - /* Cr component */ - put_bits(&s->pb, 8, 3); /* index */ - put_bits(&s->pb, 4, 1); /* DC huffman table index */ - put_bits(&s->pb, 4, lossless ? 0 : 1); /* AC huffman table index */ - - put_bits(&s->pb, 8, (lossless && !ls) ? s->avctx->prediction_method+1 : 0); /* Ss (not used) */ - - switch(s->avctx->codec_id){ - case CODEC_ID_MJPEG: put_bits(&s->pb, 8, 63); break; /* Se (not used) */ - case CODEC_ID_LJPEG: put_bits(&s->pb, 8, 0); break; /* not used */ - case CODEC_ID_JPEGLS: put_bits(&s->pb, 8, 1); break; /* ILV = line interleaved */ - default: assert(0); - } - - put_bits(&s->pb, 8, 0); /* Ah/Al (not used) */ - - //FIXME DC/AC entropy table selectors stuff in jpegls -} - -static void escape_FF(MpegEncContext *s, int start) -{ - int size= put_bits_count(&s->pb) - start*8; - int i, ff_count; - uint8_t *buf= s->pb.buf + start; - int align= (-(size_t)(buf))&3; - - assert((size&7) == 0); - size >>= 3; - - ff_count=0; - for(i=0; i>4))&0x0F0F0F0F)+0x01010101)&0x10101010; - v= *(uint32_t*)(&buf[i+4]); - acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010; - v= *(uint32_t*)(&buf[i+8]); - acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010; - v= *(uint32_t*)(&buf[i+12]); - acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010; - - acc>>=4; - acc+= (acc>>16); - acc+= (acc>>8); - ff_count+= acc&0xFF; - } - for(; ipb, 32, 0); - put_bits(&s->pb, (ff_count-i)*8, 0); - flush_put_bits(&s->pb); - - for(i=size-1; ff_count; i--){ - int v= buf[i]; - - if(v==0xFF){ -//printf("%d %d\n", i, ff_count); - buf[i+ff_count]= 0; - ff_count--; - } - - buf[i+ff_count]= v; - } -} - -void ff_mjpeg_stuffing(PutBitContext * pbc) -{ - int length; - length= (-put_bits_count(pbc))&7; - if(length) put_bits(pbc, length, (1<pb); - flush_put_bits(&s->pb); - - assert((s->header_bits&7)==0); - - escape_FF(s, s->header_bits>>3); - - put_marker(&s->pb, EOI); -} - -static inline void mjpeg_encode_dc(MpegEncContext *s, int val, - uint8_t *huff_size, uint16_t *huff_code) -{ - int mant, nbits; - - if (val == 0) { - put_bits(&s->pb, huff_size[0], huff_code[0]); - } else { - mant = val; - if (val < 0) { - val = -val; - mant--; - } - - nbits= av_log2_16bit(val) + 1; - - put_bits(&s->pb, huff_size[nbits], huff_code[nbits]); - - put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); - } -} - -static void encode_block(MpegEncContext *s, DCTELEM *block, int n) -{ - int mant, nbits, code, i, j; - int component, dc, run, last_index, val; - MJpegContext *m = s->mjpeg_ctx; - uint8_t *huff_size_ac; - uint16_t *huff_code_ac; - - /* DC coef */ - component = (n <= 3 ? 0 : (n&1) + 1); - dc = block[0]; /* overflow is impossible */ - val = dc - s->last_dc[component]; - if (n < 4) { - mjpeg_encode_dc(s, val, m->huff_size_dc_luminance, m->huff_code_dc_luminance); - huff_size_ac = m->huff_size_ac_luminance; - huff_code_ac = m->huff_code_ac_luminance; - } else { - mjpeg_encode_dc(s, val, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance); - huff_size_ac = m->huff_size_ac_chrominance; - huff_code_ac = m->huff_code_ac_chrominance; - } - s->last_dc[component] = dc; - - /* AC coefs */ - - run = 0; - last_index = s->block_last_index[n]; - for(i=1;i<=last_index;i++) { - j = s->intra_scantable.permutated[i]; - val = block[j]; - if (val == 0) { - run++; - } else { - while (run >= 16) { - put_bits(&s->pb, huff_size_ac[0xf0], huff_code_ac[0xf0]); - run -= 16; - } - mant = val; - if (val < 0) { - val = -val; - mant--; - } - - nbits= av_log2(val) + 1; - code = (run << 4) | nbits; - - put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]); - - put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); - run = 0; - } - } - - /* output EOB only if not already 64 values */ - if (last_index < 63 || run != 0) - put_bits(&s->pb, huff_size_ac[0], huff_code_ac[0]); -} - -void mjpeg_encode_mb(MpegEncContext *s, - DCTELEM block[6][64]) -{ - int i; - for(i=0;i<5;i++) { - encode_block(s, block[i], i); - } - if (s->chroma_format == CHROMA_420) { - encode_block(s, block[5], 5); - } else { - encode_block(s, block[6], 6); - encode_block(s, block[5], 5); - encode_block(s, block[7], 7); - } -} - -static int encode_picture_lossless(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ - MpegEncContext * const s = avctx->priv_data; - MJpegContext * const m = s->mjpeg_ctx; - AVFrame *pict = data; - const int width= s->width; - const int height= s->height; - AVFrame * const p= (AVFrame*)&s->current_picture; - const int predictor= avctx->prediction_method+1; - - init_put_bits(&s->pb, buf, buf_size); - - *p = *pict; - p->pict_type= FF_I_TYPE; - p->key_frame= 1; - - mjpeg_picture_header(s); - - s->header_bits= put_bits_count(&s->pb); - - if(avctx->pix_fmt == PIX_FMT_RGB32){ - int x, y, i; - const int linesize= p->linesize[0]; - uint16_t (*buffer)[4]= (void *) s->rd_scratchpad; - int left[3], top[3], topleft[3]; - - for(i=0; i<3; i++){ - buffer[0][i]= 1 << (9 - 1); - } - - for(y = 0; y < height; y++) { - const int modified_predictor= y ? predictor : 1; - uint8_t *ptr = p->data[0] + (linesize * y); - - if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < width*3*4){ - av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); - return -1; - } - - for(i=0; i<3; i++){ - top[i]= left[i]= topleft[i]= buffer[0][i]; - } - for(x = 0; x < width; x++) { - buffer[x][1] = ptr[4*x+0] - ptr[4*x+1] + 0x100; - buffer[x][2] = ptr[4*x+2] - ptr[4*x+1] + 0x100; - buffer[x][0] = (ptr[4*x+0] + 2*ptr[4*x+1] + ptr[4*x+2])>>2; - - for(i=0;i<3;i++) { - int pred, diff; - - PREDICT(pred, topleft[i], top[i], left[i], modified_predictor); - - topleft[i]= top[i]; - top[i]= buffer[x+1][i]; - - left[i]= buffer[x][i]; - - diff= ((left[i] - pred + 0x100)&0x1FF) - 0x100; - - if(i==0) - mjpeg_encode_dc(s, diff, m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly - else - mjpeg_encode_dc(s, diff, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance); - } - } - } - }else{ - int mb_x, mb_y, i; - const int mb_width = (width + s->mjpeg_hsample[0] - 1) / s->mjpeg_hsample[0]; - const int mb_height = (height + s->mjpeg_vsample[0] - 1) / s->mjpeg_vsample[0]; - - for(mb_y = 0; mb_y < mb_height; mb_y++) { - if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < mb_width * 4 * 3 * s->mjpeg_hsample[0] * s->mjpeg_vsample[0]){ - av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); - return -1; - } - for(mb_x = 0; mb_x < mb_width; mb_x++) { - if(mb_x==0 || mb_y==0){ - for(i=0;i<3;i++) { - uint8_t *ptr; - int x, y, h, v, linesize; - h = s->mjpeg_hsample[i]; - v = s->mjpeg_vsample[i]; - linesize= p->linesize[i]; - - for(y=0; ydata[i] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap - if(y==0 && mb_y==0){ - if(x==0 && mb_x==0){ - pred= 128; - }else{ - pred= ptr[-1]; - } - }else{ - if(x==0 && mb_x==0){ - pred= ptr[-linesize]; - }else{ - PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor); - } - } - - if(i==0) - mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly - else - mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_chrominance, m->huff_code_dc_chrominance); - } - } - } - }else{ - for(i=0;i<3;i++) { - uint8_t *ptr; - int x, y, h, v, linesize; - h = s->mjpeg_hsample[i]; - v = s->mjpeg_vsample[i]; - linesize= p->linesize[i]; - - for(y=0; ydata[i] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap -//printf("%d %d %d %d %8X\n", mb_x, mb_y, x, y, ptr); - PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor); - - if(i==0) - mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_luminance, m->huff_code_dc_luminance); //FIXME ugly - else - mjpeg_encode_dc(s, (int8_t)(*ptr - pred), m->huff_size_dc_chrominance, m->huff_code_dc_chrominance); - } - } - } - } - } - } - } - - emms_c(); - - mjpeg_picture_trailer(s); - s->picture_number++; - - flush_put_bits(&s->pb); - return pbBufPtr(&s->pb) - s->pb.buf; -// return (put_bits_count(&f->pb)+7)/8; -} - -#endif //CONFIG_ENCODERS - -/******************************************/ -/* decoding */ - -#define MAX_COMPONENTS 4 - -typedef struct MJpegDecodeContext { - AVCodecContext *avctx; - GetBitContext gb; - int mpeg_enc_ctx_allocated; /* true if decoding context allocated */ - - int start_code; /* current start code */ - int buffer_size; - uint8_t *buffer; - - int16_t quant_matrixes[4][64]; - VLC vlcs[2][4]; - int qscale[4]; ///< quantizer scale calculated from quant_matrixes - - int org_height; /* size given at codec init */ - int first_picture; /* true if decoding first picture */ - int interlaced; /* true if interlaced */ - int bottom_field; /* true if bottom field */ - int lossless; - int ls; - int progressive; - int rgb; - int rct; /* standard rct */ - int pegasus_rct; /* pegasus reversible colorspace transform */ - int bits; /* bits per component */ - - int maxval; - int near; ///< near lossless bound (si 0 for lossless) - int t1,t2,t3; - int reset; ///< context halfing intervall ?rename - - int width, height; - int mb_width, mb_height; - int nb_components; - int component_id[MAX_COMPONENTS]; - int h_count[MAX_COMPONENTS]; /* horizontal and vertical count for each component */ - int v_count[MAX_COMPONENTS]; - int comp_index[MAX_COMPONENTS]; - int dc_index[MAX_COMPONENTS]; - int ac_index[MAX_COMPONENTS]; - int nb_blocks[MAX_COMPONENTS]; - int h_scount[MAX_COMPONENTS]; - int v_scount[MAX_COMPONENTS]; - int h_max, v_max; /* maximum h and v counts */ - int quant_index[4]; /* quant table index for each component */ - int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */ - AVFrame picture; /* picture structure */ - int linesize[MAX_COMPONENTS]; ///< linesize << interlaced - int8_t *qscale_table; - DECLARE_ALIGNED_8(DCTELEM, block[64]); - ScanTable scantable; - void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); - void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); - - int restart_interval; - int restart_count; - - int buggy_avid; - int cs_itu601; - int interlace_polarity; - - int mjpb_skiptosod; - - int cur_scan; /* current scan, used by JPEG-LS */ -} MJpegDecodeContext; - -#include "jpeg_ls.c" //FIXME make jpeg-ls more independent - -static int mjpeg_decode_dht(MJpegDecodeContext *s); - -static int build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table, - int nb_codes, int use_static, int is_ac) -{ - uint8_t huff_size[256+16]; - uint16_t huff_code[256+16]; - - assert(nb_codes <= 256); - - memset(huff_size, 0, sizeof(huff_size)); - build_huffman_codes(huff_size, huff_code, bits_table, val_table); - - if(is_ac){ - memmove(huff_size+16, huff_size, sizeof(uint8_t)*nb_codes); - memmove(huff_code+16, huff_code, sizeof(uint16_t)*nb_codes); - memset(huff_size, 0, sizeof(uint8_t)*16); - memset(huff_code, 0, sizeof(uint16_t)*16); - nb_codes += 16; - } - - return init_vlc(vlc, 9, nb_codes, huff_size, 1, 1, huff_code, 2, 2, use_static); -} - -static int mjpeg_decode_init(AVCodecContext *avctx) -{ - MJpegDecodeContext *s = avctx->priv_data; - MpegEncContext s2; - memset(s, 0, sizeof(MJpegDecodeContext)); - - s->avctx = avctx; - - /* ugly way to get the idct & scantable FIXME */ - memset(&s2, 0, sizeof(MpegEncContext)); - s2.avctx= avctx; -// s2->out_format = FMT_MJPEG; - dsputil_init(&s2.dsp, avctx); - DCT_common_init(&s2); - - s->scantable= s2.intra_scantable; - s->idct_put= s2.dsp.idct_put; - s->idct_add= s2.dsp.idct_add; - - s->mpeg_enc_ctx_allocated = 0; - s->buffer_size = 0; - s->buffer = NULL; - s->start_code = -1; - s->first_picture = 1; - s->org_height = avctx->coded_height; - - build_vlc(&s->vlcs[0][0], bits_dc_luminance, val_dc_luminance, 12, 0, 0); - build_vlc(&s->vlcs[0][1], bits_dc_chrominance, val_dc_chrominance, 12, 0, 0); - build_vlc(&s->vlcs[1][0], bits_ac_luminance, val_ac_luminance, 251, 0, 1); - build_vlc(&s->vlcs[1][1], bits_ac_chrominance, val_ac_chrominance, 251, 0, 1); - - if (avctx->flags & CODEC_FLAG_EXTERN_HUFF) - { - av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n"); - init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8); - mjpeg_decode_dht(s); - /* should check for error - but dunno */ - } - if (avctx->extradata_size > 9 && - AV_RL32(avctx->extradata + 4) == MKTAG('f','i','e','l')) { - if (avctx->extradata[9] == 6) { /* quicktime icefloe 019 */ - s->interlace_polarity = 1; /* bottom field first */ - av_log(avctx, AV_LOG_DEBUG, "mjpeg bottom field first\n"); - } - } - - return 0; -} - - -/** - * finds the end of the current frame in the bitstream. - * @return the position of the first byte of the next frame, or -1 - */ -static int find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){ - int vop_found, i; - uint16_t state; - - vop_found= pc->frame_start_found; - state= pc->state; - - i=0; - if(!vop_found){ - for(i=0; iframe_start_found=0; - pc->state=0; - return i-1; - } - } - } - pc->frame_start_found= vop_found; - pc->state= state; - return END_NOT_FOUND; -} - -static int jpeg_parse(AVCodecParserContext *s, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - ParseContext *pc = s->priv_data; - int next; - - next= find_frame_end(pc, buf, buf_size); - - if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { - *poutbuf = NULL; - *poutbuf_size = 0; - return buf_size; - } - - *poutbuf = (uint8_t *)buf; - *poutbuf_size = buf_size; - return next; -} - -/* quantize tables */ -static int mjpeg_decode_dqt(MJpegDecodeContext *s) -{ - int len, index, i, j; - - len = get_bits(&s->gb, 16) - 2; - - while (len >= 65) { - /* only 8 bit precision handled */ - if (get_bits(&s->gb, 4) != 0) - { - av_log(s->avctx, AV_LOG_ERROR, "dqt: 16bit precision\n"); - return -1; - } - index = get_bits(&s->gb, 4); - if (index >= 4) - return -1; - av_log(s->avctx, AV_LOG_DEBUG, "index=%d\n", index); - /* read quant table */ - for(i=0;i<64;i++) { - j = s->scantable.permutated[i]; - s->quant_matrixes[index][j] = get_bits(&s->gb, 8); - } - - //XXX FIXME finetune, and perhaps add dc too - s->qscale[index]= FFMAX( - s->quant_matrixes[index][s->scantable.permutated[1]], - s->quant_matrixes[index][s->scantable.permutated[8]]) >> 1; - av_log(s->avctx, AV_LOG_DEBUG, "qscale[%d]: %d\n", index, s->qscale[index]); - len -= 65; - } - - return 0; -} - -/* decode huffman tables and build VLC decoders */ -static int mjpeg_decode_dht(MJpegDecodeContext *s) -{ - int len, index, i, class, n, v, code_max; - uint8_t bits_table[17]; - uint8_t val_table[256]; - - len = get_bits(&s->gb, 16) - 2; - - while (len > 0) { - if (len < 17) - return -1; - class = get_bits(&s->gb, 4); - if (class >= 2) - return -1; - index = get_bits(&s->gb, 4); - if (index >= 4) - return -1; - n = 0; - for(i=1;i<=16;i++) { - bits_table[i] = get_bits(&s->gb, 8); - n += bits_table[i]; - } - len -= 17; - if (len < n || n > 256) - return -1; - - code_max = 0; - for(i=0;igb, 8); - if (v > code_max) - code_max = v; - val_table[i] = v; - } - len -= n; - - /* build VLC and flush previous vlc if present */ - free_vlc(&s->vlcs[class][index]); - av_log(s->avctx, AV_LOG_DEBUG, "class=%d index=%d nb_codes=%d\n", - class, index, code_max + 1); - if(build_vlc(&s->vlcs[class][index], bits_table, val_table, code_max + 1, 0, class > 0) < 0){ - return -1; - } - } - return 0; -} - -static int mjpeg_decode_sof(MJpegDecodeContext *s) -{ - int len, nb_components, i, width, height, pix_fmt_id; - - /* XXX: verify len field validity */ - len = get_bits(&s->gb, 16); - s->bits= get_bits(&s->gb, 8); - - if(s->pegasus_rct) s->bits=9; - if(s->bits==9 && !s->pegasus_rct) s->rct=1; //FIXME ugly - - if (s->bits != 8 && !s->lossless){ - av_log(s->avctx, AV_LOG_ERROR, "only 8 bits/component accepted\n"); - return -1; - } - - height = get_bits(&s->gb, 16); - width = get_bits(&s->gb, 16); - - av_log(s->avctx, AV_LOG_DEBUG, "sof0: picture: %dx%d\n", width, height); - if(avcodec_check_dimensions(s->avctx, width, height)) - return -1; - - nb_components = get_bits(&s->gb, 8); - if (nb_components <= 0 || - nb_components > MAX_COMPONENTS) - return -1; - if (s->ls && !(s->bits <= 8 || nb_components == 1)){ - av_log(s->avctx, AV_LOG_ERROR, "only <= 8 bits/component or 16-bit gray accepted for JPEG-LS\n"); - return -1; - } - s->nb_components = nb_components; - s->h_max = 1; - s->v_max = 1; - for(i=0;icomponent_id[i] = get_bits(&s->gb, 8) - 1; - s->h_count[i] = get_bits(&s->gb, 4); - s->v_count[i] = get_bits(&s->gb, 4); - /* compute hmax and vmax (only used in interleaved case) */ - if (s->h_count[i] > s->h_max) - s->h_max = s->h_count[i]; - if (s->v_count[i] > s->v_max) - s->v_max = s->v_count[i]; - s->quant_index[i] = get_bits(&s->gb, 8); - if (s->quant_index[i] >= 4) - return -1; - av_log(s->avctx, AV_LOG_DEBUG, "component %d %d:%d id: %d quant:%d\n", i, s->h_count[i], - s->v_count[i], s->component_id[i], s->quant_index[i]); - } - - if(s->ls && (s->h_max > 1 || s->v_max > 1)) { - av_log(s->avctx, AV_LOG_ERROR, "Subsampling in JPEG-LS is not supported.\n"); - return -1; - } - - if(s->v_max==1 && s->h_max==1 && s->lossless==1) s->rgb=1; - - /* if different size, realloc/alloc picture */ - /* XXX: also check h_count and v_count */ - if (width != s->width || height != s->height) { - av_freep(&s->qscale_table); - - s->width = width; - s->height = height; - - /* test interlaced mode */ - if (s->first_picture && - s->org_height != 0 && - s->height < ((s->org_height * 3) / 4)) { - s->interlaced = 1; - s->bottom_field = s->interlace_polarity; - s->picture.interlaced_frame = 1; - s->picture.top_field_first = !s->interlace_polarity; - height *= 2; - } - - avcodec_set_dimensions(s->avctx, width, height); - - s->qscale_table= av_mallocz((s->width+15)/16); - - s->first_picture = 0; - } - - if(s->interlaced && (s->bottom_field == !s->interlace_polarity)) - return 0; - - /* XXX: not complete test ! */ - pix_fmt_id = (s->h_count[0] << 20) | (s->v_count[0] << 16) | - (s->h_count[1] << 12) | (s->v_count[1] << 8) | - (s->h_count[2] << 4) | s->v_count[2]; - av_log(s->avctx, AV_LOG_DEBUG, "pix fmt id %x\n", pix_fmt_id); - switch(pix_fmt_id){ - case 0x222222: - case 0x111111: - if(s->rgb){ - s->avctx->pix_fmt = PIX_FMT_RGB32; - }else if(s->nb_components==3) - s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV444P : PIX_FMT_YUVJ444P; - else - s->avctx->pix_fmt = PIX_FMT_GRAY8; - break; - case 0x211111: - case 0x221212: - s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV422P : PIX_FMT_YUVJ422P; - break; - default: - case 0x221111: - s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV420P : PIX_FMT_YUVJ420P; - break; - } - if(s->ls){ - if(s->nb_components > 1) - s->avctx->pix_fmt = PIX_FMT_RGB24; - else if(s->bits <= 8) - s->avctx->pix_fmt = PIX_FMT_GRAY8; - else - s->avctx->pix_fmt = PIX_FMT_GRAY16; - } - - if(s->picture.data[0]) - s->avctx->release_buffer(s->avctx, &s->picture); - - s->picture.reference= 0; - if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){ - av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; - } - s->picture.pict_type= I_TYPE; - s->picture.key_frame= 1; - - for(i=0; i<3; i++){ - s->linesize[i]= s->picture.linesize[i] << s->interlaced; - } - -// printf("%d %d %d %d %d %d\n", s->width, s->height, s->linesize[0], s->linesize[1], s->interlaced, s->avctx->height); - - if (len != (8+(3*nb_components))) - { - av_log(s->avctx, AV_LOG_DEBUG, "decode_sof0: error, len(%d) mismatch\n", len); - } - - /* totally blank picture as progressive JPEG will only add details to it */ - if(s->progressive){ - memset(s->picture.data[0], 0, s->picture.linesize[0] * s->height); - memset(s->picture.data[1], 0, s->picture.linesize[1] * s->height >> (s->v_max - s->v_count[1])); - memset(s->picture.data[2], 0, s->picture.linesize[2] * s->height >> (s->v_max - s->v_count[2])); - } - return 0; -} - -static inline int mjpeg_decode_dc(MJpegDecodeContext *s, int dc_index) -{ - int code; - code = get_vlc2(&s->gb, s->vlcs[0][dc_index].table, 9, 2); - if (code < 0) - { - av_log(s->avctx, AV_LOG_WARNING, "mjpeg_decode_dc: bad vlc: %d:%d (%p)\n", 0, dc_index, - &s->vlcs[0][dc_index]); - return 0xffff; - } - - if(code) - return get_xbits(&s->gb, code); - else - return 0; -} - -/* decode block and dequantize */ -static int decode_block(MJpegDecodeContext *s, DCTELEM *block, - int component, int dc_index, int ac_index, int16_t *quant_matrix) -{ - int code, i, j, level, val; - - /* DC coef */ - val = mjpeg_decode_dc(s, dc_index); - if (val == 0xffff) { - av_log(s->avctx, AV_LOG_ERROR, "error dc\n"); - return -1; - } - val = val * quant_matrix[0] + s->last_dc[component]; - s->last_dc[component] = val; - block[0] = val; - /* AC coefs */ - i = 0; - {OPEN_READER(re, &s->gb) - for(;;) { - UPDATE_CACHE(re, &s->gb); - GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2) - - /* EOB */ - if (code == 0x10) - break; - i += ((unsigned)code) >> 4; - if(code != 0x100){ - code &= 0xf; - if(code > MIN_CACHE_BITS - 16){ - UPDATE_CACHE(re, &s->gb) - } - { - int cache=GET_CACHE(re,&s->gb); - int sign=(~cache)>>31; - level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign; - } - - LAST_SKIP_BITS(re, &s->gb, code) - - if (i >= 63) { - if(i == 63){ - j = s->scantable.permutated[63]; - block[j] = level * quant_matrix[j]; - break; - } - av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i); - return -1; - } - j = s->scantable.permutated[i]; - block[j] = level * quant_matrix[j]; - } - } - CLOSE_READER(re, &s->gb)} - - return 0; -} - -/* decode block and dequantize - progressive JPEG version */ -static int decode_block_progressive(MJpegDecodeContext *s, DCTELEM *block, - int component, int dc_index, int ac_index, int16_t *quant_matrix, - int ss, int se, int Ah, int Al, int *EOBRUN) -{ - int code, i, j, level, val, run; - - /* DC coef */ - if(!ss){ - val = mjpeg_decode_dc(s, dc_index); - if (val == 0xffff) { - av_log(s->avctx, AV_LOG_ERROR, "error dc\n"); - return -1; - } - val = (val * quant_matrix[0] << Al) + s->last_dc[component]; - }else - val = 0; - s->last_dc[component] = val; - block[0] = val; - if(!se) return 0; - /* AC coefs */ - if(*EOBRUN){ - (*EOBRUN)--; - return 0; - } - {OPEN_READER(re, &s->gb) - for(i=ss;;i++) { - UPDATE_CACHE(re, &s->gb); - GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2) - /* Progressive JPEG use AC coeffs from zero and this decoder sets offset 16 by default */ - code -= 16; - if(code & 0xF) { - i += ((unsigned) code) >> 4; - code &= 0xf; - if(code > MIN_CACHE_BITS - 16){ - UPDATE_CACHE(re, &s->gb) - } - { - int cache=GET_CACHE(re,&s->gb); - int sign=(~cache)>>31; - level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign; - } - - LAST_SKIP_BITS(re, &s->gb, code) - - if (i >= se) { - if(i == se){ - j = s->scantable.permutated[se]; - block[j] = level * quant_matrix[j] << Al; - break; - } - av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i); - return -1; - } - j = s->scantable.permutated[i]; - block[j] = level * quant_matrix[j] << Al; - }else{ - run = ((unsigned) code) >> 4; - if(run == 0xF){// ZRL - skip 15 coefficients - i += 15; - }else{ - val = run; - run = (1 << run); - UPDATE_CACHE(re, &s->gb); - run += (GET_CACHE(re, &s->gb) >> (32 - val)) & (run - 1); - if(val) - LAST_SKIP_BITS(re, &s->gb, val); - *EOBRUN = run - 1; - break; - } - } - } - CLOSE_READER(re, &s->gb)} - - return 0; -} - -static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int predictor, int point_transform){ - int i, mb_x, mb_y; - uint16_t buffer[32768][4]; - int left[3], top[3], topleft[3]; - const int linesize= s->linesize[0]; - const int mask= (1<bits)-1; - - if((unsigned)s->mb_width > 32768) //dynamic alloc - return -1; - - for(i=0; i<3; i++){ - buffer[0][i]= 1 << (s->bits + point_transform - 1); - } - for(mb_y = 0; mb_y < s->mb_height; mb_y++) { - const int modified_predictor= mb_y ? predictor : 1; - uint8_t *ptr = s->picture.data[0] + (linesize * mb_y); - - if (s->interlaced && s->bottom_field) - ptr += linesize >> 1; - - for(i=0; i<3; i++){ - top[i]= left[i]= topleft[i]= buffer[0][i]; - } - for(mb_x = 0; mb_x < s->mb_width; mb_x++) { - if (s->restart_interval && !s->restart_count) - s->restart_count = s->restart_interval; - - for(i=0;i<3;i++) { - int pred; - - topleft[i]= top[i]; - top[i]= buffer[mb_x][i]; - - PREDICT(pred, topleft[i], top[i], left[i], modified_predictor); - - left[i]= - buffer[mb_x][i]= mask & (pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform)); - } - - if (s->restart_interval && !--s->restart_count) { - align_get_bits(&s->gb); - skip_bits(&s->gb, 16); /* skip RSTn */ - } - } - - if(s->rct){ - for(mb_x = 0; mb_x < s->mb_width; mb_x++) { - ptr[4*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200)>>2); - ptr[4*mb_x+0] = buffer[mb_x][1] + ptr[4*mb_x+1]; - ptr[4*mb_x+2] = buffer[mb_x][2] + ptr[4*mb_x+1]; - } - }else if(s->pegasus_rct){ - for(mb_x = 0; mb_x < s->mb_width; mb_x++) { - ptr[4*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2])>>2); - ptr[4*mb_x+0] = buffer[mb_x][1] + ptr[4*mb_x+1]; - ptr[4*mb_x+2] = buffer[mb_x][2] + ptr[4*mb_x+1]; - } - }else{ - for(mb_x = 0; mb_x < s->mb_width; mb_x++) { - ptr[4*mb_x+0] = buffer[mb_x][0]; - ptr[4*mb_x+1] = buffer[mb_x][1]; - ptr[4*mb_x+2] = buffer[mb_x][2]; - } - } - } - return 0; -} - -static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor, int point_transform){ - int i, mb_x, mb_y; - const int nb_components=3; - - for(mb_y = 0; mb_y < s->mb_height; mb_y++) { - for(mb_x = 0; mb_x < s->mb_width; mb_x++) { - if (s->restart_interval && !s->restart_count) - s->restart_count = s->restart_interval; - - if(mb_x==0 || mb_y==0 || s->interlaced){ - for(i=0;inb_blocks[i]; - c = s->comp_index[i]; - h = s->h_scount[i]; - v = s->v_scount[i]; - x = 0; - y = 0; - linesize= s->linesize[c]; - - for(j=0; jpicture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap - if(y==0 && mb_y==0){ - if(x==0 && mb_x==0){ - pred= 128 << point_transform; - }else{ - pred= ptr[-1]; - } - }else{ - if(x==0 && mb_x==0){ - pred= ptr[-linesize]; - }else{ - PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor); - } - } - - if (s->interlaced && s->bottom_field) - ptr += linesize >> 1; - *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform); - - if (++x == h) { - x = 0; - y++; - } - } - } - }else{ - for(i=0;inb_blocks[i]; - c = s->comp_index[i]; - h = s->h_scount[i]; - v = s->v_scount[i]; - x = 0; - y = 0; - linesize= s->linesize[c]; - - for(j=0; jpicture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap - PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor); - *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform); - if (++x == h) { - x = 0; - y++; - } - } - } - } - if (s->restart_interval && !--s->restart_count) { - align_get_bits(&s->gb); - skip_bits(&s->gb, 16); /* skip RSTn */ - } - } - } - return 0; -} - -static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int ss, int se, int Ah, int Al){ - int i, mb_x, mb_y; - int EOBRUN = 0; - - if(Ah) return 0; /* TODO decode refinement planes too */ - for(mb_y = 0; mb_y < s->mb_height; mb_y++) { - for(mb_x = 0; mb_x < s->mb_width; mb_x++) { - if (s->restart_interval && !s->restart_count) - s->restart_count = s->restart_interval; - - for(i=0;inb_blocks[i]; - c = s->comp_index[i]; - h = s->h_scount[i]; - v = s->v_scount[i]; - x = 0; - y = 0; - for(j=0;jblock, 0, sizeof(s->block)); - if (!s->progressive && decode_block(s, s->block, i, - s->dc_index[i], s->ac_index[i], - s->quant_matrixes[ s->quant_index[c] ]) < 0) { - av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x); - return -1; - } - if (s->progressive && decode_block_progressive(s, s->block, i, - s->dc_index[i], s->ac_index[i], - s->quant_matrixes[ s->quant_index[c] ], ss, se, Ah, Al, &EOBRUN) < 0) { - av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x); - return -1; - } -// av_log(s->avctx, AV_LOG_DEBUG, "mb: %d %d processed\n", mb_y, mb_x); - ptr = s->picture.data[c] + - (((s->linesize[c] * (v * mb_y + y) * 8) + - (h * mb_x + x) * 8) >> s->avctx->lowres); - if (s->interlaced && s->bottom_field) - ptr += s->linesize[c] >> 1; -//av_log(NULL, AV_LOG_DEBUG, "%d %d %d %d %d %d %d %d \n", mb_x, mb_y, x, y, c, s->bottom_field, (v * mb_y + y) * 8, (h * mb_x + x) * 8); - if(!s->progressive) - s->idct_put(ptr, s->linesize[c], s->block); - else - s->idct_add(ptr, s->linesize[c], s->block); - if (++x == h) { - x = 0; - y++; - } - } - } - /* (< 1350) buggy workaround for Spectralfan.mov, should be fixed */ - if (s->restart_interval && (s->restart_interval < 1350) && - !--s->restart_count) { - align_get_bits(&s->gb); - skip_bits(&s->gb, 16); /* skip RSTn */ - for (i=0; ilast_dc[i] = 1024; - } - } - } - return 0; -} - -static int mjpeg_decode_sos(MJpegDecodeContext *s) -{ - int len, nb_components, i, h, v, predictor, point_transform; - int vmax, hmax, index, id; - const int block_size= s->lossless ? 1 : 8; - int ilv, prev_shift; - - /* XXX: verify len field validity */ - len = get_bits(&s->gb, 16); - nb_components = get_bits(&s->gb, 8); - if (len != 6+2*nb_components) - { - av_log(s->avctx, AV_LOG_ERROR, "decode_sos: invalid len (%d)\n", len); - return -1; - } - vmax = 0; - hmax = 0; - for(i=0;igb, 8) - 1; - av_log(s->avctx, AV_LOG_DEBUG, "component: %d\n", id); - /* find component index */ - for(index=0;indexnb_components;index++) - if (id == s->component_id[index]) - break; - if (index == s->nb_components) - { - av_log(s->avctx, AV_LOG_ERROR, "decode_sos: index(%d) out of components\n", index); - return -1; - } - - s->comp_index[i] = index; - - s->nb_blocks[i] = s->h_count[index] * s->v_count[index]; - s->h_scount[i] = s->h_count[index]; - s->v_scount[i] = s->v_count[index]; - - s->dc_index[i] = get_bits(&s->gb, 4); - s->ac_index[i] = get_bits(&s->gb, 4); - - if (s->dc_index[i] < 0 || s->ac_index[i] < 0 || - s->dc_index[i] >= 4 || s->ac_index[i] >= 4) - goto out_of_range; -#if 0 //buggy - switch(s->start_code) - { - case SOF0: - if (dc_index[i] > 1 || ac_index[i] > 1) - goto out_of_range; - break; - case SOF1: - case SOF2: - if (dc_index[i] > 3 || ac_index[i] > 3) - goto out_of_range; - break; - case SOF3: - if (dc_index[i] > 3 || ac_index[i] != 0) - goto out_of_range; - break; - } -#endif - } - - predictor= get_bits(&s->gb, 8); /* JPEG Ss / lossless JPEG predictor /JPEG-LS NEAR */ - ilv= get_bits(&s->gb, 8); /* JPEG Se / JPEG-LS ILV */ - prev_shift = get_bits(&s->gb, 4); /* Ah */ - point_transform= get_bits(&s->gb, 4); /* Al */ - - for(i=0;ilast_dc[i] = 1024; - - if (nb_components > 1) { - /* interleaved stream */ - s->mb_width = (s->width + s->h_max * block_size - 1) / (s->h_max * block_size); - s->mb_height = (s->height + s->v_max * block_size - 1) / (s->v_max * block_size); - } else if(!s->ls) { /* skip this for JPEG-LS */ - h = s->h_max / s->h_scount[0]; - v = s->v_max / s->v_scount[0]; - s->mb_width = (s->width + h * block_size - 1) / (h * block_size); - s->mb_height = (s->height + v * block_size - 1) / (v * block_size); - s->nb_blocks[0] = 1; - s->h_scount[0] = 1; - s->v_scount[0] = 1; - } - - if(s->avctx->debug & FF_DEBUG_PICT_INFO) - av_log(s->avctx, AV_LOG_DEBUG, "%s %s p:%d >>:%d ilv:%d bits:%d %s\n", s->lossless ? "lossless" : "sequencial DCT", s->rgb ? "RGB" : "", - predictor, point_transform, ilv, s->bits, - s->pegasus_rct ? "PRCT" : (s->rct ? "RCT" : "")); - - - /* mjpeg-b can have padding bytes between sos and image data, skip them */ - for (i = s->mjpb_skiptosod; i > 0; i--) - skip_bits(&s->gb, 8); - - if(s->lossless){ - if(s->ls){ -// for(){ -// reset_ls_coding_parameters(s, 0); - - ls_decode_picture(s, predictor, point_transform, ilv); - }else{ - if(s->rgb){ - if(ljpeg_decode_rgb_scan(s, predictor, point_transform) < 0) - return -1; - }else{ - if(ljpeg_decode_yuv_scan(s, predictor, point_transform) < 0) - return -1; - } - } - }else{ - if(mjpeg_decode_scan(s, nb_components, predictor, ilv, prev_shift, point_transform) < 0) - return -1; - } - emms_c(); - return 0; - out_of_range: - av_log(s->avctx, AV_LOG_ERROR, "decode_sos: ac/dc index out of range\n"); - return -1; -} - -static int mjpeg_decode_dri(MJpegDecodeContext *s) -{ - if (get_bits(&s->gb, 16) != 4) - return -1; - s->restart_interval = get_bits(&s->gb, 16); - s->restart_count = 0; - av_log(s->avctx, AV_LOG_DEBUG, "restart interval: %d\n", s->restart_interval); - - return 0; -} - -static int mjpeg_decode_app(MJpegDecodeContext *s) -{ - int len, id; - - len = get_bits(&s->gb, 16); - if (len < 5) - return -1; - if(8*len + get_bits_count(&s->gb) > s->gb.size_in_bits) - return -1; - - id = (get_bits(&s->gb, 16) << 16) | get_bits(&s->gb, 16); - id = be2me_32(id); - len -= 6; - - if(s->avctx->debug & FF_DEBUG_STARTCODE){ - av_log(s->avctx, AV_LOG_DEBUG, "APPx %8X\n", id); - } - - /* buggy AVID, it puts EOI only at every 10th frame */ - /* also this fourcc is used by non-avid files too, it holds some - informations, but it's always present in AVID creates files */ - if (id == ff_get_fourcc("AVI1")) - { - /* structure: - 4bytes AVI1 - 1bytes polarity - 1bytes always zero - 4bytes field_size - 4bytes field_size_less_padding - */ - s->buggy_avid = 1; -// if (s->first_picture) -// printf("mjpeg: workarounding buggy AVID\n"); - s->interlace_polarity = get_bits(&s->gb, 8); -#if 0 - skip_bits(&s->gb, 8); - skip_bits(&s->gb, 32); - skip_bits(&s->gb, 32); - len -= 10; -#endif -// if (s->interlace_polarity) -// printf("mjpeg: interlace polarity: %d\n", s->interlace_polarity); - goto out; - } - -// len -= 2; - - if (id == ff_get_fourcc("JFIF")) - { - int t_w, t_h, v1, v2; - skip_bits(&s->gb, 8); /* the trailing zero-byte */ - v1= get_bits(&s->gb, 8); - v2= get_bits(&s->gb, 8); - skip_bits(&s->gb, 8); - - s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 16); - s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 16); - - if (s->avctx->debug & FF_DEBUG_PICT_INFO) - av_log(s->avctx, AV_LOG_INFO, "mjpeg: JFIF header found (version: %x.%x) SAR=%d/%d\n", - v1, v2, - s->avctx->sample_aspect_ratio.num, - s->avctx->sample_aspect_ratio.den - ); - - t_w = get_bits(&s->gb, 8); - t_h = get_bits(&s->gb, 8); - if (t_w && t_h) - { - /* skip thumbnail */ - if (len-10-(t_w*t_h*3) > 0) - len -= t_w*t_h*3; - } - len -= 10; - goto out; - } - - if (id == ff_get_fourcc("Adob") && (get_bits(&s->gb, 8) == 'e')) - { - if (s->avctx->debug & FF_DEBUG_PICT_INFO) - av_log(s->avctx, AV_LOG_INFO, "mjpeg: Adobe header found\n"); - skip_bits(&s->gb, 16); /* version */ - skip_bits(&s->gb, 16); /* flags0 */ - skip_bits(&s->gb, 16); /* flags1 */ - skip_bits(&s->gb, 8); /* transform */ - len -= 7; - goto out; - } - - if (id == ff_get_fourcc("LJIF")){ - if (s->avctx->debug & FF_DEBUG_PICT_INFO) - av_log(s->avctx, AV_LOG_INFO, "Pegasus lossless jpeg header found\n"); - skip_bits(&s->gb, 16); /* version ? */ - skip_bits(&s->gb, 16); /* unknwon always 0? */ - skip_bits(&s->gb, 16); /* unknwon always 0? */ - skip_bits(&s->gb, 16); /* unknwon always 0? */ - switch( get_bits(&s->gb, 8)){ - case 1: - s->rgb= 1; - s->pegasus_rct=0; - break; - case 2: - s->rgb= 1; - s->pegasus_rct=1; - break; - default: - av_log(s->avctx, AV_LOG_ERROR, "unknown colorspace\n"); - } - len -= 9; - goto out; - } - - /* Apple MJPEG-A */ - if ((s->start_code == APP1) && (len > (0x28 - 8))) - { - id = (get_bits(&s->gb, 16) << 16) | get_bits(&s->gb, 16); - id = be2me_32(id); - len -= 4; - if (id == ff_get_fourcc("mjpg")) /* Apple MJPEG-A */ - { -#if 0 - skip_bits(&s->gb, 32); /* field size */ - skip_bits(&s->gb, 32); /* pad field size */ - skip_bits(&s->gb, 32); /* next off */ - skip_bits(&s->gb, 32); /* quant off */ - skip_bits(&s->gb, 32); /* huff off */ - skip_bits(&s->gb, 32); /* image off */ - skip_bits(&s->gb, 32); /* scan off */ - skip_bits(&s->gb, 32); /* data off */ -#endif - if (s->avctx->debug & FF_DEBUG_PICT_INFO) - av_log(s->avctx, AV_LOG_INFO, "mjpeg: Apple MJPEG-A header found\n"); - } - } - -out: - /* slow but needed for extreme adobe jpegs */ - if (len < 0) - av_log(s->avctx, AV_LOG_ERROR, "mjpeg: error, decode_app parser read over the end\n"); - while(--len > 0) - skip_bits(&s->gb, 8); - - return 0; -} - -static int mjpeg_decode_com(MJpegDecodeContext *s) -{ - int len = get_bits(&s->gb, 16); - if (len >= 2 && 8*len - 16 + get_bits_count(&s->gb) <= s->gb.size_in_bits) { - char *cbuf = av_malloc(len - 1); - if (cbuf) { - int i; - for (i = 0; i < len - 2; i++) - cbuf[i] = get_bits(&s->gb, 8); - if (i > 0 && cbuf[i-1] == '\n') - cbuf[i-1] = 0; - else - cbuf[i] = 0; - - if(s->avctx->debug & FF_DEBUG_PICT_INFO) - av_log(s->avctx, AV_LOG_INFO, "mjpeg comment: '%s'\n", cbuf); - - /* buggy avid, it puts EOI only at every 10th frame */ - if (!strcmp(cbuf, "AVID")) - { - s->buggy_avid = 1; - // if (s->first_picture) - // printf("mjpeg: workarounding buggy AVID\n"); - } - else if(!strcmp(cbuf, "CS=ITU601")){ - s->cs_itu601= 1; - } - - av_free(cbuf); - } - } - - return 0; -} - -#if 0 -static int valid_marker_list[] = -{ - /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f */ -/* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 1 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 2 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 3 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 4 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 5 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 6 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 7 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 8 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* 9 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* a */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* b */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/* c */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -/* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -/* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -/* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, -} -#endif - -/* return the 8 bit start code value and update the search - state. Return -1 if no start code found */ -static int find_marker(uint8_t **pbuf_ptr, uint8_t *buf_end) -{ - uint8_t *buf_ptr; - unsigned int v, v2; - int val; -#ifdef DEBUG - int skipped=0; -#endif - - buf_ptr = *pbuf_ptr; - while (buf_ptr < buf_end) { - v = *buf_ptr++; - v2 = *buf_ptr; - if ((v == 0xff) && (v2 >= 0xc0) && (v2 <= 0xfe) && buf_ptr < buf_end) { - val = *buf_ptr++; - goto found; - } -#ifdef DEBUG - skipped++; -#endif - } - val = -1; -found: -#ifdef DEBUG - av_log(NULL, AV_LOG_VERBOSE, "find_marker skipped %d bytes\n", skipped); -#endif - *pbuf_ptr = buf_ptr; - return val; -} - -static int mjpeg_decode_frame(AVCodecContext *avctx, - void *data, int *data_size, - uint8_t *buf, int buf_size) -{ - MJpegDecodeContext *s = avctx->priv_data; - uint8_t *buf_end, *buf_ptr; - int start_code; - AVFrame *picture = data; - - buf_ptr = buf; - buf_end = buf + buf_size; - while (buf_ptr < buf_end) { - /* find start next marker */ - start_code = find_marker(&buf_ptr, buf_end); - { - /* EOF */ - if (start_code < 0) { - goto the_end; - } else { - av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%d\n", start_code, buf_end - buf_ptr); - - if ((buf_end - buf_ptr) > s->buffer_size) - { - av_free(s->buffer); - s->buffer_size = buf_end-buf_ptr; - s->buffer = av_malloc(s->buffer_size + FF_INPUT_BUFFER_PADDING_SIZE); - av_log(avctx, AV_LOG_DEBUG, "buffer too small, expanding to %d bytes\n", - s->buffer_size); - } - - /* unescape buffer of SOS, use special treatment for JPEG-LS */ - if (start_code == SOS && !s->ls) - { - uint8_t *src = buf_ptr; - uint8_t *dst = s->buffer; - - while (srccodec_id != CODEC_ID_THP) - { - if (x == 0xff) { - while (src < buf_end && x == 0xff) - x = *(src++); - - if (x >= 0xd0 && x <= 0xd7) - *(dst++) = x; - else if (x) - break; - } - } - } - init_get_bits(&s->gb, s->buffer, (dst - s->buffer)*8); - - av_log(avctx, AV_LOG_DEBUG, "escaping removed %d bytes\n", - (buf_end - buf_ptr) - (dst - s->buffer)); - } - else if(start_code == SOS && s->ls){ - uint8_t *src = buf_ptr; - uint8_t *dst = s->buffer; - int bit_count = 0; - int t = 0, b = 0; - PutBitContext pb; - - s->cur_scan++; - - /* find marker */ - while (src + t < buf_end){ - uint8_t x = src[t++]; - if (x == 0xff){ - while((src + t < buf_end) && x == 0xff) - x = src[t++]; - if (x & 0x80) { - t -= 2; - break; - } - } - } - bit_count = t * 8; - - init_put_bits(&pb, dst, t); - - /* unescape bitstream */ - while(b < t){ - uint8_t x = src[b++]; - put_bits(&pb, 8, x); - if(x == 0xFF){ - x = src[b++]; - put_bits(&pb, 7, x); - bit_count--; - } - } - flush_put_bits(&pb); - - init_get_bits(&s->gb, dst, bit_count); - } - else - init_get_bits(&s->gb, buf_ptr, (buf_end - buf_ptr)*8); - - s->start_code = start_code; - if(s->avctx->debug & FF_DEBUG_STARTCODE){ - av_log(avctx, AV_LOG_DEBUG, "startcode: %X\n", start_code); - } - - /* process markers */ - if (start_code >= 0xd0 && start_code <= 0xd7) { - av_log(avctx, AV_LOG_DEBUG, "restart marker: %d\n", start_code&0x0f); - /* APP fields */ - } else if (start_code >= APP0 && start_code <= APP15) { - mjpeg_decode_app(s); - /* Comment */ - } else if (start_code == COM){ - mjpeg_decode_com(s); - } - - switch(start_code) { - case SOI: - s->restart_interval = 0; - - s->restart_count = 0; - /* nothing to do on SOI */ - break; - case DQT: - mjpeg_decode_dqt(s); - break; - case DHT: - if(mjpeg_decode_dht(s) < 0){ - av_log(avctx, AV_LOG_ERROR, "huffman table decode error\n"); - return -1; - } - break; - case SOF0: - s->lossless=0; - s->ls=0; - s->progressive=0; - if (mjpeg_decode_sof(s) < 0) - return -1; - break; - case SOF2: - s->lossless=0; - s->ls=0; - s->progressive=1; - if (mjpeg_decode_sof(s) < 0) - return -1; - break; - case SOF3: - s->lossless=1; - s->ls=0; - s->progressive=0; - if (mjpeg_decode_sof(s) < 0) - return -1; - break; - case SOF48: - s->lossless=1; - s->ls=1; - s->progressive=0; - if (mjpeg_decode_sof(s) < 0) - return -1; - break; - case LSE: - if (decode_lse(s) < 0) - return -1; - break; - case EOI: - s->cur_scan = 0; - if ((s->buggy_avid && !s->interlaced) || s->restart_interval) - break; -eoi_parser: - { - if (s->interlaced) { - s->bottom_field ^= 1; - /* if not bottom field, do not output image yet */ - if (s->bottom_field == !s->interlace_polarity) - goto not_the_end; - } - *picture = s->picture; - *data_size = sizeof(AVFrame); - - if(!s->lossless){ - picture->quality= FFMAX(FFMAX(s->qscale[0], s->qscale[1]), s->qscale[2]); - picture->qstride= 0; - picture->qscale_table= s->qscale_table; - memset(picture->qscale_table, picture->quality, (s->width+15)/16); - if(avctx->debug & FF_DEBUG_QP) - av_log(avctx, AV_LOG_DEBUG, "QP: %d\n", picture->quality); - picture->quality*= FF_QP2LAMBDA; - } - - goto the_end; - } - break; - case SOS: - mjpeg_decode_sos(s); - /* buggy avid puts EOI every 10-20th frame */ - /* if restart period is over process EOI */ - if ((s->buggy_avid && !s->interlaced) || s->restart_interval) - goto eoi_parser; - break; - case DRI: - mjpeg_decode_dri(s); - break; - case SOF1: - case SOF5: - case SOF6: - case SOF7: - case SOF9: - case SOF10: - case SOF11: - case SOF13: - case SOF14: - case SOF15: - case JPG: - av_log(avctx, AV_LOG_ERROR, "mjpeg: unsupported coding type (%x)\n", start_code); - break; -// default: -// printf("mjpeg: unsupported marker (%x)\n", start_code); -// break; - } - -not_the_end: - /* eof process start code */ - buf_ptr += (get_bits_count(&s->gb)+7)/8; - av_log(avctx, AV_LOG_DEBUG, "marker parser used %d bytes (%d bits)\n", - (get_bits_count(&s->gb)+7)/8, get_bits_count(&s->gb)); - } - } - } -the_end: - av_log(avctx, AV_LOG_DEBUG, "mjpeg decode frame unused %d bytes\n", buf_end - buf_ptr); -// return buf_end - buf_ptr; - return buf_ptr - buf; -} - -static int mjpegb_decode_frame(AVCodecContext *avctx, - void *data, int *data_size, - uint8_t *buf, int buf_size) -{ - MJpegDecodeContext *s = avctx->priv_data; - uint8_t *buf_end, *buf_ptr; - AVFrame *picture = data; - GetBitContext hgb; /* for the header */ - uint32_t dqt_offs, dht_offs, sof_offs, sos_offs, second_field_offs; - uint32_t field_size, sod_offs; - - buf_ptr = buf; - buf_end = buf + buf_size; - -read_header: - /* reset on every SOI */ - s->restart_interval = 0; - s->restart_count = 0; - s->mjpb_skiptosod = 0; - - init_get_bits(&hgb, buf_ptr, /*buf_size*/(buf_end - buf_ptr)*8); - - skip_bits(&hgb, 32); /* reserved zeros */ - - if (get_bits_long(&hgb, 32) != MKBETAG('m','j','p','g')) - { - av_log(avctx, AV_LOG_WARNING, "not mjpeg-b (bad fourcc)\n"); - return 0; - } - - field_size = get_bits_long(&hgb, 32); /* field size */ - av_log(avctx, AV_LOG_DEBUG, "field size: 0x%x\n", field_size); - skip_bits(&hgb, 32); /* padded field size */ - second_field_offs = get_bits_long(&hgb, 32); - av_log(avctx, AV_LOG_DEBUG, "second field offs: 0x%x\n", second_field_offs); - if (second_field_offs) - s->interlaced = 1; - - dqt_offs = get_bits_long(&hgb, 32); - av_log(avctx, AV_LOG_DEBUG, "dqt offs: 0x%x\n", dqt_offs); - if (dqt_offs) - { - init_get_bits(&s->gb, buf+dqt_offs, (buf_end - (buf+dqt_offs))*8); - s->start_code = DQT; - mjpeg_decode_dqt(s); - } - - dht_offs = get_bits_long(&hgb, 32); - av_log(avctx, AV_LOG_DEBUG, "dht offs: 0x%x\n", dht_offs); - if (dht_offs) - { - init_get_bits(&s->gb, buf+dht_offs, (buf_end - (buf+dht_offs))*8); - s->start_code = DHT; - mjpeg_decode_dht(s); - } - - sof_offs = get_bits_long(&hgb, 32); - av_log(avctx, AV_LOG_DEBUG, "sof offs: 0x%x\n", sof_offs); - if (sof_offs) - { - init_get_bits(&s->gb, buf+sof_offs, (buf_end - (buf+sof_offs))*8); - s->start_code = SOF0; - if (mjpeg_decode_sof(s) < 0) - return -1; - } - - sos_offs = get_bits_long(&hgb, 32); - av_log(avctx, AV_LOG_DEBUG, "sos offs: 0x%x\n", sos_offs); - sod_offs = get_bits_long(&hgb, 32); - av_log(avctx, AV_LOG_DEBUG, "sod offs: 0x%x\n", sod_offs); - if (sos_offs) - { -// init_get_bits(&s->gb, buf+sos_offs, (buf_end - (buf+sos_offs))*8); - init_get_bits(&s->gb, buf+sos_offs, field_size*8); - s->mjpb_skiptosod = (sod_offs - sos_offs - show_bits(&s->gb, 16)); - s->start_code = SOS; - mjpeg_decode_sos(s); - } - - if (s->interlaced) { - s->bottom_field ^= 1; - /* if not bottom field, do not output image yet */ - if (s->bottom_field && second_field_offs) - { - buf_ptr = buf + second_field_offs; - second_field_offs = 0; - goto read_header; - } - } - - //XXX FIXME factorize, this looks very similar to the EOI code - - *picture= s->picture; - *data_size = sizeof(AVFrame); - - if(!s->lossless){ - picture->quality= FFMAX(FFMAX(s->qscale[0], s->qscale[1]), s->qscale[2]); - picture->qstride= 0; - picture->qscale_table= s->qscale_table; - memset(picture->qscale_table, picture->quality, (s->width+15)/16); - if(avctx->debug & FF_DEBUG_QP) - av_log(avctx, AV_LOG_DEBUG, "QP: %d\n", picture->quality); - picture->quality*= FF_QP2LAMBDA; - } - - return buf_ptr - buf; -} - -#include "sp5x.h" - -static int sp5x_decode_frame(AVCodecContext *avctx, - void *data, int *data_size, - uint8_t *buf, int buf_size) -{ -#if 0 - MJpegDecodeContext *s = avctx->priv_data; -#endif - const int qscale = 5; - uint8_t *buf_ptr, *buf_end, *recoded; - int i = 0, j = 0; - - if (!avctx->width || !avctx->height) - return -1; - - buf_ptr = buf; - buf_end = buf + buf_size; - -#if 1 - recoded = av_mallocz(buf_size + 1024); - if (!recoded) - return -1; - - /* SOI */ - recoded[j++] = 0xFF; - recoded[j++] = 0xD8; - - memcpy(recoded+j, &sp5x_data_dqt[0], sizeof(sp5x_data_dqt)); - memcpy(recoded+j+5, &sp5x_quant_table[qscale * 2], 64); - memcpy(recoded+j+70, &sp5x_quant_table[(qscale * 2) + 1], 64); - j += sizeof(sp5x_data_dqt); - - memcpy(recoded+j, &sp5x_data_dht[0], sizeof(sp5x_data_dht)); - j += sizeof(sp5x_data_dht); - - memcpy(recoded+j, &sp5x_data_sof[0], sizeof(sp5x_data_sof)); - recoded[j+5] = (avctx->coded_height >> 8) & 0xFF; - recoded[j+6] = avctx->coded_height & 0xFF; - recoded[j+7] = (avctx->coded_width >> 8) & 0xFF; - recoded[j+8] = avctx->coded_width & 0xFF; - j += sizeof(sp5x_data_sof); - - memcpy(recoded+j, &sp5x_data_sos[0], sizeof(sp5x_data_sos)); - j += sizeof(sp5x_data_sos); - - for (i = 14; i < buf_size && j < buf_size+1024-2; i++) - { - recoded[j++] = buf[i]; - if (buf[i] == 0xff) - recoded[j++] = 0; - } - - /* EOI */ - recoded[j++] = 0xFF; - recoded[j++] = 0xD9; - - i = mjpeg_decode_frame(avctx, data, data_size, recoded, j); - - av_free(recoded); - -#else - /* SOF */ - s->bits = 8; - s->width = avctx->coded_width; - s->height = avctx->coded_height; - s->nb_components = 3; - s->component_id[0] = 0; - s->h_count[0] = 2; - s->v_count[0] = 2; - s->quant_index[0] = 0; - s->component_id[1] = 1; - s->h_count[1] = 1; - s->v_count[1] = 1; - s->quant_index[1] = 1; - s->component_id[2] = 2; - s->h_count[2] = 1; - s->v_count[2] = 1; - s->quant_index[2] = 1; - s->h_max = 2; - s->v_max = 2; - - s->qscale_table = av_mallocz((s->width+15)/16); - avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV420P : PIX_FMT_YUVJ420; - s->interlaced = 0; - - s->picture.reference = 0; - if (avctx->get_buffer(avctx, &s->picture) < 0) - { - av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; - } - - s->picture.pict_type = I_TYPE; - s->picture.key_frame = 1; - - for (i = 0; i < 3; i++) - s->linesize[i] = s->picture.linesize[i] << s->interlaced; - - /* DQT */ - for (i = 0; i < 64; i++) - { - j = s->scantable.permutated[i]; - s->quant_matrixes[0][j] = sp5x_quant_table[(qscale * 2) + i]; - } - s->qscale[0] = FFMAX( - s->quant_matrixes[0][s->scantable.permutated[1]], - s->quant_matrixes[0][s->scantable.permutated[8]]) >> 1; - - for (i = 0; i < 64; i++) - { - j = s->scantable.permutated[i]; - s->quant_matrixes[1][j] = sp5x_quant_table[(qscale * 2) + 1 + i]; - } - s->qscale[1] = FFMAX( - s->quant_matrixes[1][s->scantable.permutated[1]], - s->quant_matrixes[1][s->scantable.permutated[8]]) >> 1; - - /* DHT */ - - /* SOS */ - s->comp_index[0] = 0; - s->nb_blocks[0] = s->h_count[0] * s->v_count[0]; - s->h_scount[0] = s->h_count[0]; - s->v_scount[0] = s->v_count[0]; - s->dc_index[0] = 0; - s->ac_index[0] = 0; - - s->comp_index[1] = 1; - s->nb_blocks[1] = s->h_count[1] * s->v_count[1]; - s->h_scount[1] = s->h_count[1]; - s->v_scount[1] = s->v_count[1]; - s->dc_index[1] = 1; - s->ac_index[1] = 1; - - s->comp_index[2] = 2; - s->nb_blocks[2] = s->h_count[2] * s->v_count[2]; - s->h_scount[2] = s->h_count[2]; - s->v_scount[2] = s->v_count[2]; - s->dc_index[2] = 1; - s->ac_index[2] = 1; - - for (i = 0; i < 3; i++) - s->last_dc[i] = 1024; - - s->mb_width = (s->width * s->h_max * 8 -1) / (s->h_max * 8); - s->mb_height = (s->height * s->v_max * 8 -1) / (s->v_max * 8); - - init_get_bits(&s->gb, buf+14, (buf_size-14)*8); - - return mjpeg_decode_scan(s); -#endif - - return i; -} - -static int mjpeg_decode_end(AVCodecContext *avctx) -{ - MJpegDecodeContext *s = avctx->priv_data; - int i, j; - - av_free(s->buffer); - av_free(s->qscale_table); - - for(i=0;i<2;i++) { - for(j=0;j<4;j++) - free_vlc(&s->vlcs[i][j]); - } - return 0; -} - -static int mjpega_dump_header(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size, int keyframe) -{ - uint8_t *poutbufp; - int i; - - if (avctx->codec_id != CODEC_ID_MJPEG) { - av_log(avctx, AV_LOG_ERROR, "mjpega bitstream filter only applies to mjpeg codec\n"); - return 0; - } - - *poutbuf_size = 0; - *poutbuf = av_malloc(buf_size + 44 + FF_INPUT_BUFFER_PADDING_SIZE); - poutbufp = *poutbuf; - bytestream_put_byte(&poutbufp, 0xff); - bytestream_put_byte(&poutbufp, SOI); - bytestream_put_byte(&poutbufp, 0xff); - bytestream_put_byte(&poutbufp, APP1); - bytestream_put_be16(&poutbufp, 42); /* size */ - bytestream_put_be32(&poutbufp, 0); - bytestream_put_buffer(&poutbufp, "mjpg", 4); - bytestream_put_be32(&poutbufp, buf_size + 44); /* field size */ - bytestream_put_be32(&poutbufp, buf_size + 44); /* pad field size */ - bytestream_put_be32(&poutbufp, 0); /* next ptr */ - - for (i = 0; i < buf_size - 1; i++) { - if (buf[i] == 0xff) { - switch (buf[i + 1]) { - case DQT: /* quant off */ - case DHT: /* huff off */ - case SOF0: /* image off */ - bytestream_put_be32(&poutbufp, i + 46); - break; - case SOS: - bytestream_put_be32(&poutbufp, i + 46); /* scan off */ - bytestream_put_be32(&poutbufp, i + 46 + AV_RB16(buf + i + 2)); /* data off */ - bytestream_put_buffer(&poutbufp, buf + 2, buf_size - 2); /* skip already written SOI */ - *poutbuf_size = poutbufp - *poutbuf; - return 1; - case APP1: - if (i + 8 < buf_size && AV_RL32(buf + i + 8) == ff_get_fourcc("mjpg")) { - av_log(avctx, AV_LOG_ERROR, "bitstream already formatted\n"); - memcpy(*poutbuf, buf, buf_size); - *poutbuf_size = buf_size; - return 1; - } - } - } - } - av_freep(poutbuf); - av_log(avctx, AV_LOG_ERROR, "could not find SOS marker in bitstream\n"); - return 0; -} - -AVCodec mjpeg_decoder = { - "mjpeg", - CODEC_TYPE_VIDEO, - CODEC_ID_MJPEG, - sizeof(MJpegDecodeContext), - mjpeg_decode_init, - NULL, - mjpeg_decode_end, - mjpeg_decode_frame, - CODEC_CAP_DR1, - NULL -}; - -AVCodec thp_decoder = { - "thp", - CODEC_TYPE_VIDEO, - CODEC_ID_THP, - sizeof(MJpegDecodeContext), - mjpeg_decode_init, - NULL, - mjpeg_decode_end, - mjpeg_decode_frame, - CODEC_CAP_DR1, - NULL -}; - -AVCodec mjpegb_decoder = { - "mjpegb", - CODEC_TYPE_VIDEO, - CODEC_ID_MJPEGB, - sizeof(MJpegDecodeContext), - mjpeg_decode_init, - NULL, - mjpeg_decode_end, - mjpegb_decode_frame, - CODEC_CAP_DR1, - NULL -}; - -AVCodec sp5x_decoder = { - "sp5x", - CODEC_TYPE_VIDEO, - CODEC_ID_SP5X, - sizeof(MJpegDecodeContext), - mjpeg_decode_init, - NULL, - mjpeg_decode_end, - sp5x_decode_frame, - CODEC_CAP_DR1, - NULL -}; - -#ifdef CONFIG_ENCODERS -AVCodec ljpeg_encoder = { //FIXME avoid MPV_* lossless jpeg shouldnt need them - "ljpeg", - CODEC_TYPE_VIDEO, - CODEC_ID_LJPEG, - sizeof(MpegEncContext), - MPV_encode_init, - encode_picture_lossless, - MPV_encode_end, -}; -#endif - -AVCodecParser mjpeg_parser = { - { CODEC_ID_MJPEG }, - sizeof(ParseContext), - NULL, - jpeg_parse, - ff_parse_close, -}; - -AVBitStreamFilter mjpega_dump_header_bsf = { - "mjpegadump", - 0, - mjpega_dump_header, -}; diff --git a/contrib/ffmpeg/libavcodec/mjpeg.h b/contrib/ffmpeg/libavcodec/mjpeg.h new file mode 100644 index 000000000..1916fd0cf --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mjpeg.h @@ -0,0 +1,156 @@ +/* + * MJPEG encoder and decoder + * Copyright (c) 2000, 2001 Fabrice Bellard. + * Copyright (c) 2003 Alex Beregszaszi + * Copyright (c) 2003-2004 Michael Niedermayer + * + * Support for external huffman table, various fixes (AVID workaround), + * aspecting, new decode_frame mechanism and apple mjpeg-b support + * by Alex Beregszaszi + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mjpeg.h + * MJPEG encoder and decoder. + */ + +#ifndef FFMPEG_MJPEG_H +#define FFMPEG_MJPEG_H + +#include "avcodec.h" +#include "bitstream.h" + + +/* JPEG marker codes */ +typedef enum { + /* start of frame */ + SOF0 = 0xc0, /* baseline */ + SOF1 = 0xc1, /* extended sequential, huffman */ + SOF2 = 0xc2, /* progressive, huffman */ + SOF3 = 0xc3, /* lossless, huffman */ + + SOF5 = 0xc5, /* differential sequential, huffman */ + SOF6 = 0xc6, /* differential progressive, huffman */ + SOF7 = 0xc7, /* differential lossless, huffman */ + JPG = 0xc8, /* reserved for JPEG extension */ + SOF9 = 0xc9, /* extended sequential, arithmetic */ + SOF10 = 0xca, /* progressive, arithmetic */ + SOF11 = 0xcb, /* lossless, arithmetic */ + + SOF13 = 0xcd, /* differential sequential, arithmetic */ + SOF14 = 0xce, /* differential progressive, arithmetic */ + SOF15 = 0xcf, /* differential lossless, arithmetic */ + + DHT = 0xc4, /* define huffman tables */ + + DAC = 0xcc, /* define arithmetic-coding conditioning */ + + /* restart with modulo 8 count "m" */ + RST0 = 0xd0, + RST1 = 0xd1, + RST2 = 0xd2, + RST3 = 0xd3, + RST4 = 0xd4, + RST5 = 0xd5, + RST6 = 0xd6, + RST7 = 0xd7, + + SOI = 0xd8, /* start of image */ + EOI = 0xd9, /* end of image */ + SOS = 0xda, /* start of scan */ + DQT = 0xdb, /* define quantization tables */ + DNL = 0xdc, /* define number of lines */ + DRI = 0xdd, /* define restart interval */ + DHP = 0xde, /* define hierarchical progression */ + EXP = 0xdf, /* expand reference components */ + + APP0 = 0xe0, + APP1 = 0xe1, + APP2 = 0xe2, + APP3 = 0xe3, + APP4 = 0xe4, + APP5 = 0xe5, + APP6 = 0xe6, + APP7 = 0xe7, + APP8 = 0xe8, + APP9 = 0xe9, + APP10 = 0xea, + APP11 = 0xeb, + APP12 = 0xec, + APP13 = 0xed, + APP14 = 0xee, + APP15 = 0xef, + + JPG0 = 0xf0, + JPG1 = 0xf1, + JPG2 = 0xf2, + JPG3 = 0xf3, + JPG4 = 0xf4, + JPG5 = 0xf5, + JPG6 = 0xf6, + SOF48 = 0xf7, ///< JPEG-LS + LSE = 0xf8, ///< JPEG-LS extension parameters + JPG9 = 0xf9, + JPG10 = 0xfa, + JPG11 = 0xfb, + JPG12 = 0xfc, + JPG13 = 0xfd, + + COM = 0xfe, /* comment */ + + TEM = 0x01, /* temporary private use for arithmetic coding */ + + /* 0x02 -> 0xbf reserved */ +} JPEG_MARKER; + +static inline void put_marker(PutBitContext *p, int code) +{ + put_bits(p, 8, 0xff); + put_bits(p, 8, code); +} + +#define PREDICT(ret, topleft, top, left, predictor)\ + switch(predictor){\ + case 1: ret= left; break;\ + case 2: ret= top; break;\ + case 3: ret= topleft; break;\ + case 4: ret= left + top - topleft; break;\ + case 5: ret= left + ((top - topleft)>>1); break;\ + case 6: ret= top + ((left - topleft)>>1); break;\ + default:\ + case 7: ret= (left + top)>>1; break;\ + } + +extern const uint8_t ff_mjpeg_bits_dc_luminance[]; +extern const uint8_t ff_mjpeg_val_dc_luminance[]; + +extern const uint8_t ff_mjpeg_bits_dc_chrominance[]; +extern const uint8_t ff_mjpeg_val_dc_chrominance[]; + +extern const uint8_t ff_mjpeg_bits_ac_luminance[]; +extern const uint8_t ff_mjpeg_val_ac_luminance[]; + +extern const uint8_t ff_mjpeg_bits_ac_chrominance[]; +extern const uint8_t ff_mjpeg_val_ac_chrominance[]; + +void ff_mjpeg_build_huffman_codes(uint8_t *huff_size, uint16_t *huff_code, + const uint8_t *bits_table, + const uint8_t *val_table); + +#endif /* FFMPEG_MJPEG_H */ diff --git a/contrib/ffmpeg/libavcodec/mjpeg_parser.c b/contrib/ffmpeg/libavcodec/mjpeg_parser.c new file mode 100644 index 000000000..aad112eb9 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mjpeg_parser.c @@ -0,0 +1,101 @@ +/* + * MJPEG parser + * Copyright (c) 2000, 2001 Fabrice Bellard. + * Copyright (c) 2003 Alex Beregszaszi + * Copyright (c) 2003-2004 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mjpeg_parser.c + * MJPEG parser. + */ + +#include "parser.h" + + +/** + * finds the end of the current frame in the bitstream. + * @return the position of the first byte of the next frame, or -1 + */ +static int find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){ + int vop_found, i; + uint16_t state; + + vop_found= pc->frame_start_found; + state= pc->state; + + i=0; + if(!vop_found){ + for(i=0; iframe_start_found=0; + pc->state=0; + return i-1; + } + } + } + pc->frame_start_found= vop_found; + pc->state= state; + return END_NOT_FOUND; +} + +static int jpeg_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + ParseContext *pc = s->priv_data; + int next; + + next= find_frame_end(pc, buf, buf_size); + + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + + *poutbuf = buf; + *poutbuf_size = buf_size; + return next; +} + + +AVCodecParser mjpeg_parser = { + { CODEC_ID_MJPEG }, + sizeof(ParseContext), + NULL, + jpeg_parse, + ff_parse_close, +}; diff --git a/contrib/ffmpeg/libavcodec/mjpega_dump_header_bsf.c b/contrib/ffmpeg/libavcodec/mjpega_dump_header_bsf.c new file mode 100644 index 000000000..a3f013174 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mjpega_dump_header_bsf.c @@ -0,0 +1,92 @@ +/* + * MJPEG A dump header bitstream filter + * Copyright (c) 2006 Baptiste Coudurier. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mjpega_dump_header_bsf.c + * MJPEG A dump header bitstream filter + * modifies bitstream to be decoded by quicktime + */ + +#include "avcodec.h" +#include "bytestream.h" +#include "mjpeg.h" + + +static int mjpega_dump_header(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, + uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size, int keyframe) +{ + uint8_t *poutbufp; + int i; + + if (avctx->codec_id != CODEC_ID_MJPEG) { + av_log(avctx, AV_LOG_ERROR, "mjpega bitstream filter only applies to mjpeg codec\n"); + return 0; + } + + *poutbuf_size = 0; + *poutbuf = av_malloc(buf_size + 44 + FF_INPUT_BUFFER_PADDING_SIZE); + poutbufp = *poutbuf; + bytestream_put_byte(&poutbufp, 0xff); + bytestream_put_byte(&poutbufp, SOI); + bytestream_put_byte(&poutbufp, 0xff); + bytestream_put_byte(&poutbufp, APP1); + bytestream_put_be16(&poutbufp, 42); /* size */ + bytestream_put_be32(&poutbufp, 0); + bytestream_put_buffer(&poutbufp, "mjpg", 4); + bytestream_put_be32(&poutbufp, buf_size + 44); /* field size */ + bytestream_put_be32(&poutbufp, buf_size + 44); /* pad field size */ + bytestream_put_be32(&poutbufp, 0); /* next ptr */ + + for (i = 0; i < buf_size - 1; i++) { + if (buf[i] == 0xff) { + switch (buf[i + 1]) { + case DQT: /* quant off */ + case DHT: /* huff off */ + case SOF0: /* image off */ + bytestream_put_be32(&poutbufp, i + 46); + break; + case SOS: + bytestream_put_be32(&poutbufp, i + 46); /* scan off */ + bytestream_put_be32(&poutbufp, i + 46 + AV_RB16(buf + i + 2)); /* data off */ + bytestream_put_buffer(&poutbufp, buf + 2, buf_size - 2); /* skip already written SOI */ + *poutbuf_size = poutbufp - *poutbuf; + return 1; + case APP1: + if (i + 8 < buf_size && AV_RL32(buf + i + 8) == ff_get_fourcc("mjpg")) { + av_log(avctx, AV_LOG_ERROR, "bitstream already formatted\n"); + memcpy(*poutbuf, buf, buf_size); + *poutbuf_size = buf_size; + return 1; + } + } + } + } + av_freep(poutbuf); + av_log(avctx, AV_LOG_ERROR, "could not find SOS marker in bitstream\n"); + return 0; +} + +AVBitStreamFilter mjpega_dump_header_bsf = { + "mjpegadump", + 0, + mjpega_dump_header, +}; diff --git a/contrib/ffmpeg/libavcodec/mjpegbdec.c b/contrib/ffmpeg/libavcodec/mjpegbdec.c new file mode 100644 index 000000000..0f27379f3 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mjpegbdec.c @@ -0,0 +1,149 @@ +/* + * Apple MJPEG-B decoder + * Copyright (c) 2002 Alex Beregszaszi + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mjpegbdec.c + * Apple MJPEG-B decoder. + */ + +#include "avcodec.h" +#include "mjpeg.h" +#include "mjpegdec.h" + + +static int mjpegb_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size) +{ + MJpegDecodeContext *s = avctx->priv_data; + const uint8_t *buf_end, *buf_ptr; + AVFrame *picture = data; + GetBitContext hgb; /* for the header */ + uint32_t dqt_offs, dht_offs, sof_offs, sos_offs, second_field_offs; + uint32_t field_size, sod_offs; + + buf_ptr = buf; + buf_end = buf + buf_size; + +read_header: + /* reset on every SOI */ + s->restart_interval = 0; + s->restart_count = 0; + s->mjpb_skiptosod = 0; + + init_get_bits(&hgb, buf_ptr, /*buf_size*/(buf_end - buf_ptr)*8); + + skip_bits(&hgb, 32); /* reserved zeros */ + + if (get_bits_long(&hgb, 32) != MKBETAG('m','j','p','g')) + { + av_log(avctx, AV_LOG_WARNING, "not mjpeg-b (bad fourcc)\n"); + return 0; + } + + field_size = get_bits_long(&hgb, 32); /* field size */ + av_log(avctx, AV_LOG_DEBUG, "field size: 0x%x\n", field_size); + skip_bits(&hgb, 32); /* padded field size */ + second_field_offs = get_bits_long(&hgb, 32); + av_log(avctx, AV_LOG_DEBUG, "second field offs: 0x%x\n", second_field_offs); + + dqt_offs = get_bits_long(&hgb, 32); + av_log(avctx, AV_LOG_DEBUG, "dqt offs: 0x%x\n", dqt_offs); + if (dqt_offs) + { + init_get_bits(&s->gb, buf_ptr+dqt_offs, (buf_end - (buf_ptr+dqt_offs))*8); + s->start_code = DQT; + ff_mjpeg_decode_dqt(s); + } + + dht_offs = get_bits_long(&hgb, 32); + av_log(avctx, AV_LOG_DEBUG, "dht offs: 0x%x\n", dht_offs); + if (dht_offs) + { + init_get_bits(&s->gb, buf_ptr+dht_offs, (buf_end - (buf_ptr+dht_offs))*8); + s->start_code = DHT; + ff_mjpeg_decode_dht(s); + } + + sof_offs = get_bits_long(&hgb, 32); + av_log(avctx, AV_LOG_DEBUG, "sof offs: 0x%x\n", sof_offs); + if (sof_offs) + { + init_get_bits(&s->gb, buf_ptr+sof_offs, (buf_end - (buf_ptr+sof_offs))*8); + s->start_code = SOF0; + if (ff_mjpeg_decode_sof(s) < 0) + return -1; + } + + sos_offs = get_bits_long(&hgb, 32); + av_log(avctx, AV_LOG_DEBUG, "sos offs: 0x%x\n", sos_offs); + sod_offs = get_bits_long(&hgb, 32); + av_log(avctx, AV_LOG_DEBUG, "sod offs: 0x%x\n", sod_offs); + if (sos_offs) + { +// init_get_bits(&s->gb, buf+sos_offs, (buf_end - (buf+sos_offs))*8); + init_get_bits(&s->gb, buf_ptr+sos_offs, field_size*8); + s->mjpb_skiptosod = (sod_offs - sos_offs - show_bits(&s->gb, 16)); + s->start_code = SOS; + ff_mjpeg_decode_sos(s); + } + + if (s->interlaced) { + s->bottom_field ^= 1; + /* if not bottom field, do not output image yet */ + if (s->bottom_field != s->interlace_polarity && second_field_offs) + { + buf_ptr = buf + second_field_offs; + second_field_offs = 0; + goto read_header; + } + } + + //XXX FIXME factorize, this looks very similar to the EOI code + + *picture= s->picture; + *data_size = sizeof(AVFrame); + + if(!s->lossless){ + picture->quality= FFMAX(FFMAX(s->qscale[0], s->qscale[1]), s->qscale[2]); + picture->qstride= 0; + picture->qscale_table= s->qscale_table; + memset(picture->qscale_table, picture->quality, (s->width+15)/16); + if(avctx->debug & FF_DEBUG_QP) + av_log(avctx, AV_LOG_DEBUG, "QP: %d\n", picture->quality); + picture->quality*= FF_QP2LAMBDA; + } + + return buf_ptr - buf; +} + +AVCodec mjpegb_decoder = { + "mjpegb", + CODEC_TYPE_VIDEO, + CODEC_ID_MJPEGB, + sizeof(MJpegDecodeContext), + ff_mjpeg_decode_init, + NULL, + ff_mjpeg_decode_end, + mjpegb_decode_frame, + CODEC_CAP_DR1, + NULL +}; diff --git a/contrib/ffmpeg/libavcodec/mjpegdec.c b/contrib/ffmpeg/libavcodec/mjpegdec.c new file mode 100644 index 000000000..e4184d54b --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mjpegdec.c @@ -0,0 +1,1380 @@ +/* + * MJPEG decoder + * Copyright (c) 2000, 2001 Fabrice Bellard. + * Copyright (c) 2003 Alex Beregszaszi + * Copyright (c) 2003-2004 Michael Niedermayer + * + * Support for external huffman table, various fixes (AVID workaround), + * aspecting, new decode_frame mechanism and apple mjpeg-b support + * by Alex Beregszaszi + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mjpegdec.c + * MJPEG decoder. + */ + +//#define DEBUG +#include + +#include "avcodec.h" +#include "dsputil.h" +#include "mjpeg.h" +#include "mjpegdec.h" +#include "jpeglsdec.h" + + +static int build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table, + int nb_codes, int use_static, int is_ac) +{ + uint8_t huff_size[256+16]; + uint16_t huff_code[256+16]; + + assert(nb_codes <= 256); + + memset(huff_size, 0, sizeof(huff_size)); + ff_mjpeg_build_huffman_codes(huff_size, huff_code, bits_table, val_table); + + if(is_ac){ + memmove(huff_size+16, huff_size, sizeof(uint8_t)*nb_codes); + memmove(huff_code+16, huff_code, sizeof(uint16_t)*nb_codes); + memset(huff_size, 0, sizeof(uint8_t)*16); + memset(huff_code, 0, sizeof(uint16_t)*16); + nb_codes += 16; + } + + return init_vlc(vlc, 9, nb_codes, huff_size, 1, 1, huff_code, 2, 2, use_static); +} + +static void build_basic_mjpeg_vlc(MJpegDecodeContext * s) { + build_vlc(&s->vlcs[0][0], ff_mjpeg_bits_dc_luminance, + ff_mjpeg_val_dc_luminance, 12, 0, 0); + build_vlc(&s->vlcs[0][1], ff_mjpeg_bits_dc_chrominance, + ff_mjpeg_val_dc_chrominance, 12, 0, 0); + build_vlc(&s->vlcs[1][0], ff_mjpeg_bits_ac_luminance, + ff_mjpeg_val_ac_luminance, 251, 0, 1); + build_vlc(&s->vlcs[1][1], ff_mjpeg_bits_ac_chrominance, + ff_mjpeg_val_ac_chrominance, 251, 0, 1); +} + +int ff_mjpeg_decode_init(AVCodecContext *avctx) +{ + MJpegDecodeContext *s = avctx->priv_data; + + s->avctx = avctx; + dsputil_init(&s->dsp, avctx); + ff_init_scantable(s->dsp.idct_permutation, &s->scantable, ff_zigzag_direct); + s->buffer_size = 0; + s->buffer = NULL; + s->start_code = -1; + s->first_picture = 1; + s->org_height = avctx->coded_height; + + build_basic_mjpeg_vlc(s); + + if (avctx->flags & CODEC_FLAG_EXTERN_HUFF) + { + av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n"); + init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8); + if (ff_mjpeg_decode_dht(s)) { + av_log(avctx, AV_LOG_ERROR, "mjpeg: error using external huffman table, switching back to internal\n"); + build_basic_mjpeg_vlc(s); + } + } + if (avctx->extradata_size > 9 && + AV_RL32(avctx->extradata + 4) == MKTAG('f','i','e','l')) { + if (avctx->extradata[9] == 6) { /* quicktime icefloe 019 */ + s->interlace_polarity = 1; /* bottom field first */ + av_log(avctx, AV_LOG_DEBUG, "mjpeg bottom field first\n"); + } + } + + return 0; +} + + +/* quantize tables */ +int ff_mjpeg_decode_dqt(MJpegDecodeContext *s) +{ + int len, index, i, j; + + len = get_bits(&s->gb, 16) - 2; + + while (len >= 65) { + /* only 8 bit precision handled */ + if (get_bits(&s->gb, 4) != 0) + { + av_log(s->avctx, AV_LOG_ERROR, "dqt: 16bit precision\n"); + return -1; + } + index = get_bits(&s->gb, 4); + if (index >= 4) + return -1; + av_log(s->avctx, AV_LOG_DEBUG, "index=%d\n", index); + /* read quant table */ + for(i=0;i<64;i++) { + j = s->scantable.permutated[i]; + s->quant_matrixes[index][j] = get_bits(&s->gb, 8); + } + + //XXX FIXME finetune, and perhaps add dc too + s->qscale[index]= FFMAX( + s->quant_matrixes[index][s->scantable.permutated[1]], + s->quant_matrixes[index][s->scantable.permutated[8]]) >> 1; + av_log(s->avctx, AV_LOG_DEBUG, "qscale[%d]: %d\n", index, s->qscale[index]); + len -= 65; + } + + return 0; +} + +/* decode huffman tables and build VLC decoders */ +int ff_mjpeg_decode_dht(MJpegDecodeContext *s) +{ + int len, index, i, class, n, v, code_max; + uint8_t bits_table[17]; + uint8_t val_table[256]; + + len = get_bits(&s->gb, 16) - 2; + + while (len > 0) { + if (len < 17) + return -1; + class = get_bits(&s->gb, 4); + if (class >= 2) + return -1; + index = get_bits(&s->gb, 4); + if (index >= 4) + return -1; + n = 0; + for(i=1;i<=16;i++) { + bits_table[i] = get_bits(&s->gb, 8); + n += bits_table[i]; + } + len -= 17; + if (len < n || n > 256) + return -1; + + code_max = 0; + for(i=0;igb, 8); + if (v > code_max) + code_max = v; + val_table[i] = v; + } + len -= n; + + /* build VLC and flush previous vlc if present */ + free_vlc(&s->vlcs[class][index]); + av_log(s->avctx, AV_LOG_DEBUG, "class=%d index=%d nb_codes=%d\n", + class, index, code_max + 1); + if(build_vlc(&s->vlcs[class][index], bits_table, val_table, code_max + 1, 0, class > 0) < 0){ + return -1; + } + } + return 0; +} + +int ff_mjpeg_decode_sof(MJpegDecodeContext *s) +{ + int len, nb_components, i, width, height, pix_fmt_id; + + /* XXX: verify len field validity */ + len = get_bits(&s->gb, 16); + s->bits= get_bits(&s->gb, 8); + + if(s->pegasus_rct) s->bits=9; + if(s->bits==9 && !s->pegasus_rct) s->rct=1; //FIXME ugly + + if (s->bits != 8 && !s->lossless){ + av_log(s->avctx, AV_LOG_ERROR, "only 8 bits/component accepted\n"); + return -1; + } + + height = get_bits(&s->gb, 16); + width = get_bits(&s->gb, 16); + + //HACK for odd_height.mov + if(s->interlaced && s->width == width && s->height == height + 1) + height= s->height; + + av_log(s->avctx, AV_LOG_DEBUG, "sof0: picture: %dx%d\n", width, height); + if(avcodec_check_dimensions(s->avctx, width, height)) + return -1; + + nb_components = get_bits(&s->gb, 8); + if (nb_components <= 0 || + nb_components > MAX_COMPONENTS) + return -1; + if (s->ls && !(s->bits <= 8 || nb_components == 1)){ + av_log(s->avctx, AV_LOG_ERROR, "only <= 8 bits/component or 16-bit gray accepted for JPEG-LS\n"); + return -1; + } + s->nb_components = nb_components; + s->h_max = 1; + s->v_max = 1; + for(i=0;icomponent_id[i] = get_bits(&s->gb, 8) - 1; + s->h_count[i] = get_bits(&s->gb, 4); + s->v_count[i] = get_bits(&s->gb, 4); + /* compute hmax and vmax (only used in interleaved case) */ + if (s->h_count[i] > s->h_max) + s->h_max = s->h_count[i]; + if (s->v_count[i] > s->v_max) + s->v_max = s->v_count[i]; + s->quant_index[i] = get_bits(&s->gb, 8); + if (s->quant_index[i] >= 4) + return -1; + av_log(s->avctx, AV_LOG_DEBUG, "component %d %d:%d id: %d quant:%d\n", i, s->h_count[i], + s->v_count[i], s->component_id[i], s->quant_index[i]); + } + + if(s->ls && (s->h_max > 1 || s->v_max > 1)) { + av_log(s->avctx, AV_LOG_ERROR, "Subsampling in JPEG-LS is not supported.\n"); + return -1; + } + + if(s->v_max==1 && s->h_max==1 && s->lossless==1) s->rgb=1; + + /* if different size, realloc/alloc picture */ + /* XXX: also check h_count and v_count */ + if (width != s->width || height != s->height) { + av_freep(&s->qscale_table); + + s->width = width; + s->height = height; + s->interlaced = 0; + + /* test interlaced mode */ + if (s->first_picture && + s->org_height != 0 && + s->height < ((s->org_height * 3) / 4)) { + s->interlaced = 1; + s->bottom_field = s->interlace_polarity; + s->picture.interlaced_frame = 1; + s->picture.top_field_first = !s->interlace_polarity; + height *= 2; + } + + avcodec_set_dimensions(s->avctx, width, height); + + s->qscale_table= av_mallocz((s->width+15)/16); + + s->first_picture = 0; + } + + if(s->interlaced && (s->bottom_field == !s->interlace_polarity)) + return 0; + + /* XXX: not complete test ! */ + pix_fmt_id = (s->h_count[0] << 20) | (s->v_count[0] << 16) | + (s->h_count[1] << 12) | (s->v_count[1] << 8) | + (s->h_count[2] << 4) | s->v_count[2]; + av_log(s->avctx, AV_LOG_DEBUG, "pix fmt id %x\n", pix_fmt_id); + switch(pix_fmt_id){ + case 0x222222: + case 0x111111: + if(s->rgb){ + s->avctx->pix_fmt = PIX_FMT_RGB32; + }else if(s->nb_components==3) + s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV444P : PIX_FMT_YUVJ444P; + else + s->avctx->pix_fmt = PIX_FMT_GRAY8; + break; + case 0x110000: + s->avctx->pix_fmt = PIX_FMT_GRAY8; + break; + case 0x121111: + s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV440P : PIX_FMT_YUVJ440P; + break; + case 0x211111: + case 0x221212: + s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV422P : PIX_FMT_YUVJ422P; + break; + case 0x221111: + s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV420P : PIX_FMT_YUVJ420P; + break; + default: + av_log(s->avctx, AV_LOG_ERROR, "Unhandled pixel format 0x%x\n", pix_fmt_id); + return -1; + } + if(s->ls){ + if(s->nb_components > 1) + s->avctx->pix_fmt = PIX_FMT_RGB24; + else if(s->bits <= 8) + s->avctx->pix_fmt = PIX_FMT_GRAY8; + else + s->avctx->pix_fmt = PIX_FMT_GRAY16; + } + + if(s->picture.data[0]) + s->avctx->release_buffer(s->avctx, &s->picture); + + s->picture.reference= 0; + if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){ + av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + s->picture.pict_type= I_TYPE; + s->picture.key_frame= 1; + + for(i=0; i<3; i++){ + s->linesize[i]= s->picture.linesize[i] << s->interlaced; + } + +// printf("%d %d %d %d %d %d\n", s->width, s->height, s->linesize[0], s->linesize[1], s->interlaced, s->avctx->height); + + if (len != (8+(3*nb_components))) + { + av_log(s->avctx, AV_LOG_DEBUG, "decode_sof0: error, len(%d) mismatch\n", len); + } + + /* totally blank picture as progressive JPEG will only add details to it */ + if(s->progressive){ + memset(s->picture.data[0], 0, s->picture.linesize[0] * s->height); + memset(s->picture.data[1], 0, s->picture.linesize[1] * s->height >> (s->v_max - s->v_count[1])); + memset(s->picture.data[2], 0, s->picture.linesize[2] * s->height >> (s->v_max - s->v_count[2])); + } + return 0; +} + +static inline int mjpeg_decode_dc(MJpegDecodeContext *s, int dc_index) +{ + int code; + code = get_vlc2(&s->gb, s->vlcs[0][dc_index].table, 9, 2); + if (code < 0) + { + av_log(s->avctx, AV_LOG_WARNING, "mjpeg_decode_dc: bad vlc: %d:%d (%p)\n", 0, dc_index, + &s->vlcs[0][dc_index]); + return 0xffff; + } + + if(code) + return get_xbits(&s->gb, code); + else + return 0; +} + +/* decode block and dequantize */ +static int decode_block(MJpegDecodeContext *s, DCTELEM *block, + int component, int dc_index, int ac_index, int16_t *quant_matrix) +{ + int code, i, j, level, val; + + /* DC coef */ + val = mjpeg_decode_dc(s, dc_index); + if (val == 0xffff) { + av_log(s->avctx, AV_LOG_ERROR, "error dc\n"); + return -1; + } + val = val * quant_matrix[0] + s->last_dc[component]; + s->last_dc[component] = val; + block[0] = val; + /* AC coefs */ + i = 0; + {OPEN_READER(re, &s->gb) + for(;;) { + UPDATE_CACHE(re, &s->gb); + GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2) + + /* EOB */ + if (code == 0x10) + break; + i += ((unsigned)code) >> 4; + if(code != 0x100){ + code &= 0xf; + if(code > MIN_CACHE_BITS - 16){ + UPDATE_CACHE(re, &s->gb) + } + { + int cache=GET_CACHE(re,&s->gb); + int sign=(~cache)>>31; + level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign; + } + + LAST_SKIP_BITS(re, &s->gb, code) + + if (i >= 63) { + if(i == 63){ + j = s->scantable.permutated[63]; + block[j] = level * quant_matrix[j]; + break; + } + av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i); + return -1; + } + j = s->scantable.permutated[i]; + block[j] = level * quant_matrix[j]; + } + } + CLOSE_READER(re, &s->gb)} + + return 0; +} + +/* decode block and dequantize - progressive JPEG version */ +static int decode_block_progressive(MJpegDecodeContext *s, DCTELEM *block, + int component, int dc_index, int ac_index, int16_t *quant_matrix, + int ss, int se, int Ah, int Al, int *EOBRUN) +{ + int code, i, j, level, val, run; + + /* DC coef */ + if(!ss){ + val = mjpeg_decode_dc(s, dc_index); + if (val == 0xffff) { + av_log(s->avctx, AV_LOG_ERROR, "error dc\n"); + return -1; + } + val = (val * quant_matrix[0] << Al) + s->last_dc[component]; + }else + val = 0; + s->last_dc[component] = val; + block[0] = val; + if(!se) return 0; + /* AC coefs */ + if(*EOBRUN){ + (*EOBRUN)--; + return 0; + } + {OPEN_READER(re, &s->gb) + for(i=ss;;i++) { + UPDATE_CACHE(re, &s->gb); + GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2) + /* Progressive JPEG use AC coeffs from zero and this decoder sets offset 16 by default */ + code -= 16; + if(code & 0xF) { + i += ((unsigned) code) >> 4; + code &= 0xf; + if(code > MIN_CACHE_BITS - 16){ + UPDATE_CACHE(re, &s->gb) + } + { + int cache=GET_CACHE(re,&s->gb); + int sign=(~cache)>>31; + level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign; + } + + LAST_SKIP_BITS(re, &s->gb, code) + + if (i >= se) { + if(i == se){ + j = s->scantable.permutated[se]; + block[j] = level * quant_matrix[j] << Al; + break; + } + av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i); + return -1; + } + j = s->scantable.permutated[i]; + block[j] = level * quant_matrix[j] << Al; + }else{ + run = ((unsigned) code) >> 4; + if(run == 0xF){// ZRL - skip 15 coefficients + i += 15; + }else{ + val = run; + run = (1 << run); + UPDATE_CACHE(re, &s->gb); + run += (GET_CACHE(re, &s->gb) >> (32 - val)) & (run - 1); + if(val) + LAST_SKIP_BITS(re, &s->gb, val); + *EOBRUN = run - 1; + break; + } + } + } + CLOSE_READER(re, &s->gb)} + + return 0; +} + +static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int predictor, int point_transform){ + int i, mb_x, mb_y; + uint16_t buffer[32768][4]; + int left[3], top[3], topleft[3]; + const int linesize= s->linesize[0]; + const int mask= (1<bits)-1; + + if((unsigned)s->mb_width > 32768) //dynamic alloc + return -1; + + for(i=0; i<3; i++){ + buffer[0][i]= 1 << (s->bits + point_transform - 1); + } + for(mb_y = 0; mb_y < s->mb_height; mb_y++) { + const int modified_predictor= mb_y ? predictor : 1; + uint8_t *ptr = s->picture.data[0] + (linesize * mb_y); + + if (s->interlaced && s->bottom_field) + ptr += linesize >> 1; + + for(i=0; i<3; i++){ + top[i]= left[i]= topleft[i]= buffer[0][i]; + } + for(mb_x = 0; mb_x < s->mb_width; mb_x++) { + if (s->restart_interval && !s->restart_count) + s->restart_count = s->restart_interval; + + for(i=0;i<3;i++) { + int pred; + + topleft[i]= top[i]; + top[i]= buffer[mb_x][i]; + + PREDICT(pred, topleft[i], top[i], left[i], modified_predictor); + + left[i]= + buffer[mb_x][i]= mask & (pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform)); + } + + if (s->restart_interval && !--s->restart_count) { + align_get_bits(&s->gb); + skip_bits(&s->gb, 16); /* skip RSTn */ + } + } + + if(s->rct){ + for(mb_x = 0; mb_x < s->mb_width; mb_x++) { + ptr[4*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200)>>2); + ptr[4*mb_x+0] = buffer[mb_x][1] + ptr[4*mb_x+1]; + ptr[4*mb_x+2] = buffer[mb_x][2] + ptr[4*mb_x+1]; + } + }else if(s->pegasus_rct){ + for(mb_x = 0; mb_x < s->mb_width; mb_x++) { + ptr[4*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2])>>2); + ptr[4*mb_x+0] = buffer[mb_x][1] + ptr[4*mb_x+1]; + ptr[4*mb_x+2] = buffer[mb_x][2] + ptr[4*mb_x+1]; + } + }else{ + for(mb_x = 0; mb_x < s->mb_width; mb_x++) { + ptr[4*mb_x+0] = buffer[mb_x][0]; + ptr[4*mb_x+1] = buffer[mb_x][1]; + ptr[4*mb_x+2] = buffer[mb_x][2]; + } + } + } + return 0; +} + +static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor, int point_transform){ + int i, mb_x, mb_y; + const int nb_components=3; + + for(mb_y = 0; mb_y < s->mb_height; mb_y++) { + for(mb_x = 0; mb_x < s->mb_width; mb_x++) { + if (s->restart_interval && !s->restart_count) + s->restart_count = s->restart_interval; + + if(mb_x==0 || mb_y==0 || s->interlaced){ + for(i=0;inb_blocks[i]; + c = s->comp_index[i]; + h = s->h_scount[i]; + v = s->v_scount[i]; + x = 0; + y = 0; + linesize= s->linesize[c]; + + for(j=0; jpicture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap + if(y==0 && mb_y==0){ + if(x==0 && mb_x==0){ + pred= 128 << point_transform; + }else{ + pred= ptr[-1]; + } + }else{ + if(x==0 && mb_x==0){ + pred= ptr[-linesize]; + }else{ + PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor); + } + } + + if (s->interlaced && s->bottom_field) + ptr += linesize >> 1; + *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform); + + if (++x == h) { + x = 0; + y++; + } + } + } + }else{ + for(i=0;inb_blocks[i]; + c = s->comp_index[i]; + h = s->h_scount[i]; + v = s->v_scount[i]; + x = 0; + y = 0; + linesize= s->linesize[c]; + + for(j=0; jpicture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap + PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor); + *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform); + if (++x == h) { + x = 0; + y++; + } + } + } + } + if (s->restart_interval && !--s->restart_count) { + align_get_bits(&s->gb); + skip_bits(&s->gb, 16); /* skip RSTn */ + } + } + } + return 0; +} + +static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int ss, int se, int Ah, int Al){ + int i, mb_x, mb_y; + int EOBRUN = 0; + uint8_t* data[MAX_COMPONENTS]; + int linesize[MAX_COMPONENTS]; + + if(Ah) return 0; /* TODO decode refinement planes too */ + + for(i=0; i < nb_components; i++) { + int c = s->comp_index[i]; + data[c] = s->picture.data[c]; + linesize[c]=s->linesize[c]; + if(s->avctx->codec->id==CODEC_ID_AMV) { + //picture should be flipped upside-down for this codec + assert(!(s->avctx->flags & CODEC_FLAG_EMU_EDGE)); + data[c] += (linesize[c] * (s->v_scount[i] * (8 * s->mb_height -((s->height/s->v_max)&7)) - 1 )); + linesize[c] *= -1; + } + } + + for(mb_y = 0; mb_y < s->mb_height; mb_y++) { + for(mb_x = 0; mb_x < s->mb_width; mb_x++) { + if (s->restart_interval && !s->restart_count) + s->restart_count = s->restart_interval; + + for(i=0;inb_blocks[i]; + c = s->comp_index[i]; + h = s->h_scount[i]; + v = s->v_scount[i]; + x = 0; + y = 0; + for(j=0;jblock, 0, sizeof(s->block)); + if (!s->progressive && decode_block(s, s->block, i, + s->dc_index[i], s->ac_index[i], + s->quant_matrixes[ s->quant_index[c] ]) < 0) { + av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x); + return -1; + } + if (s->progressive && decode_block_progressive(s, s->block, i, + s->dc_index[i], s->ac_index[i], + s->quant_matrixes[ s->quant_index[c] ], ss, se, Ah, Al, &EOBRUN) < 0) { + av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x); + return -1; + } +// av_log(s->avctx, AV_LOG_DEBUG, "mb: %d %d processed\n", mb_y, mb_x); + ptr = data[c] + + (((linesize[c] * (v * mb_y + y) * 8) + + (h * mb_x + x) * 8) >> s->avctx->lowres); + if (s->interlaced && s->bottom_field) + ptr += linesize[c] >> 1; +//av_log(NULL, AV_LOG_DEBUG, "%d %d %d %d %d %d %d %d \n", mb_x, mb_y, x, y, c, s->bottom_field, (v * mb_y + y) * 8, (h * mb_x + x) * 8); + if(!s->progressive) + s->dsp.idct_put(ptr, linesize[c], s->block); + else + s->dsp.idct_add(ptr, linesize[c], s->block); + if (++x == h) { + x = 0; + y++; + } + } + } + /* (< 1350) buggy workaround for Spectralfan.mov, should be fixed */ + if (s->restart_interval && (s->restart_interval < 1350) && + !--s->restart_count) { + align_get_bits(&s->gb); + skip_bits(&s->gb, 16); /* skip RSTn */ + for (i=0; ilast_dc[i] = 1024; + } + } + } + return 0; +} + +int ff_mjpeg_decode_sos(MJpegDecodeContext *s) +{ + int len, nb_components, i, h, v, predictor, point_transform; + int vmax, hmax, index, id; + const int block_size= s->lossless ? 1 : 8; + int ilv, prev_shift; + + /* XXX: verify len field validity */ + len = get_bits(&s->gb, 16); + nb_components = get_bits(&s->gb, 8); + if (len != 6+2*nb_components) + { + av_log(s->avctx, AV_LOG_ERROR, "decode_sos: invalid len (%d)\n", len); + return -1; + } + vmax = 0; + hmax = 0; + for(i=0;igb, 8) - 1; + av_log(s->avctx, AV_LOG_DEBUG, "component: %d\n", id); + /* find component index */ + for(index=0;indexnb_components;index++) + if (id == s->component_id[index]) + break; + if (index == s->nb_components) + { + av_log(s->avctx, AV_LOG_ERROR, "decode_sos: index(%d) out of components\n", index); + return -1; + } + + s->comp_index[i] = index; + + s->nb_blocks[i] = s->h_count[index] * s->v_count[index]; + s->h_scount[i] = s->h_count[index]; + s->v_scount[i] = s->v_count[index]; + + s->dc_index[i] = get_bits(&s->gb, 4); + s->ac_index[i] = get_bits(&s->gb, 4); + + if (s->dc_index[i] < 0 || s->ac_index[i] < 0 || + s->dc_index[i] >= 4 || s->ac_index[i] >= 4) + goto out_of_range; +#if 0 //buggy + switch(s->start_code) + { + case SOF0: + if (dc_index[i] > 1 || ac_index[i] > 1) + goto out_of_range; + break; + case SOF1: + case SOF2: + if (dc_index[i] > 3 || ac_index[i] > 3) + goto out_of_range; + break; + case SOF3: + if (dc_index[i] > 3 || ac_index[i] != 0) + goto out_of_range; + break; + } +#endif + } + + predictor= get_bits(&s->gb, 8); /* JPEG Ss / lossless JPEG predictor /JPEG-LS NEAR */ + ilv= get_bits(&s->gb, 8); /* JPEG Se / JPEG-LS ILV */ + prev_shift = get_bits(&s->gb, 4); /* Ah */ + point_transform= get_bits(&s->gb, 4); /* Al */ + + for(i=0;ilast_dc[i] = 1024; + + if (nb_components > 1) { + /* interleaved stream */ + s->mb_width = (s->width + s->h_max * block_size - 1) / (s->h_max * block_size); + s->mb_height = (s->height + s->v_max * block_size - 1) / (s->v_max * block_size); + } else if(!s->ls) { /* skip this for JPEG-LS */ + h = s->h_max / s->h_scount[0]; + v = s->v_max / s->v_scount[0]; + s->mb_width = (s->width + h * block_size - 1) / (h * block_size); + s->mb_height = (s->height + v * block_size - 1) / (v * block_size); + s->nb_blocks[0] = 1; + s->h_scount[0] = 1; + s->v_scount[0] = 1; + } + + if(s->avctx->debug & FF_DEBUG_PICT_INFO) + av_log(s->avctx, AV_LOG_DEBUG, "%s %s p:%d >>:%d ilv:%d bits:%d %s\n", s->lossless ? "lossless" : "sequencial DCT", s->rgb ? "RGB" : "", + predictor, point_transform, ilv, s->bits, + s->pegasus_rct ? "PRCT" : (s->rct ? "RCT" : "")); + + + /* mjpeg-b can have padding bytes between sos and image data, skip them */ + for (i = s->mjpb_skiptosod; i > 0; i--) + skip_bits(&s->gb, 8); + + if(s->lossless){ + if(ENABLE_JPEGLS_DECODER && s->ls){ +// for(){ +// reset_ls_coding_parameters(s, 0); + + ff_jpegls_decode_picture(s, predictor, point_transform, ilv); + }else{ + if(s->rgb){ + if(ljpeg_decode_rgb_scan(s, predictor, point_transform) < 0) + return -1; + }else{ + if(ljpeg_decode_yuv_scan(s, predictor, point_transform) < 0) + return -1; + } + } + }else{ + if(mjpeg_decode_scan(s, nb_components, predictor, ilv, prev_shift, point_transform) < 0) + return -1; + } + emms_c(); + return 0; + out_of_range: + av_log(s->avctx, AV_LOG_ERROR, "decode_sos: ac/dc index out of range\n"); + return -1; +} + +static int mjpeg_decode_dri(MJpegDecodeContext *s) +{ + if (get_bits(&s->gb, 16) != 4) + return -1; + s->restart_interval = get_bits(&s->gb, 16); + s->restart_count = 0; + av_log(s->avctx, AV_LOG_DEBUG, "restart interval: %d\n", s->restart_interval); + + return 0; +} + +static int mjpeg_decode_app(MJpegDecodeContext *s) +{ + int len, id, i; + + len = get_bits(&s->gb, 16); + if (len < 5) + return -1; + if(8*len + get_bits_count(&s->gb) > s->gb.size_in_bits) + return -1; + + id = (get_bits(&s->gb, 16) << 16) | get_bits(&s->gb, 16); + id = be2me_32(id); + len -= 6; + + if(s->avctx->debug & FF_DEBUG_STARTCODE){ + av_log(s->avctx, AV_LOG_DEBUG, "APPx %8X\n", id); + } + + /* buggy AVID, it puts EOI only at every 10th frame */ + /* also this fourcc is used by non-avid files too, it holds some + informations, but it's always present in AVID creates files */ + if (id == ff_get_fourcc("AVI1")) + { + /* structure: + 4bytes AVI1 + 1bytes polarity + 1bytes always zero + 4bytes field_size + 4bytes field_size_less_padding + */ + s->buggy_avid = 1; +// if (s->first_picture) +// printf("mjpeg: workarounding buggy AVID\n"); + i = get_bits(&s->gb, 8); + if (i==2) s->bottom_field= 1; + else if(i==1) s->bottom_field= 0; +#if 0 + skip_bits(&s->gb, 8); + skip_bits(&s->gb, 32); + skip_bits(&s->gb, 32); + len -= 10; +#endif +// if (s->interlace_polarity) +// printf("mjpeg: interlace polarity: %d\n", s->interlace_polarity); + goto out; + } + +// len -= 2; + + if (id == ff_get_fourcc("JFIF")) + { + int t_w, t_h, v1, v2; + skip_bits(&s->gb, 8); /* the trailing zero-byte */ + v1= get_bits(&s->gb, 8); + v2= get_bits(&s->gb, 8); + skip_bits(&s->gb, 8); + + s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 16); + s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 16); + + if (s->avctx->debug & FF_DEBUG_PICT_INFO) + av_log(s->avctx, AV_LOG_INFO, "mjpeg: JFIF header found (version: %x.%x) SAR=%d/%d\n", + v1, v2, + s->avctx->sample_aspect_ratio.num, + s->avctx->sample_aspect_ratio.den + ); + + t_w = get_bits(&s->gb, 8); + t_h = get_bits(&s->gb, 8); + if (t_w && t_h) + { + /* skip thumbnail */ + if (len-10-(t_w*t_h*3) > 0) + len -= t_w*t_h*3; + } + len -= 10; + goto out; + } + + if (id == ff_get_fourcc("Adob") && (get_bits(&s->gb, 8) == 'e')) + { + if (s->avctx->debug & FF_DEBUG_PICT_INFO) + av_log(s->avctx, AV_LOG_INFO, "mjpeg: Adobe header found\n"); + skip_bits(&s->gb, 16); /* version */ + skip_bits(&s->gb, 16); /* flags0 */ + skip_bits(&s->gb, 16); /* flags1 */ + skip_bits(&s->gb, 8); /* transform */ + len -= 7; + goto out; + } + + if (id == ff_get_fourcc("LJIF")){ + if (s->avctx->debug & FF_DEBUG_PICT_INFO) + av_log(s->avctx, AV_LOG_INFO, "Pegasus lossless jpeg header found\n"); + skip_bits(&s->gb, 16); /* version ? */ + skip_bits(&s->gb, 16); /* unknwon always 0? */ + skip_bits(&s->gb, 16); /* unknwon always 0? */ + skip_bits(&s->gb, 16); /* unknwon always 0? */ + switch( get_bits(&s->gb, 8)){ + case 1: + s->rgb= 1; + s->pegasus_rct=0; + break; + case 2: + s->rgb= 1; + s->pegasus_rct=1; + break; + default: + av_log(s->avctx, AV_LOG_ERROR, "unknown colorspace\n"); + } + len -= 9; + goto out; + } + + /* Apple MJPEG-A */ + if ((s->start_code == APP1) && (len > (0x28 - 8))) + { + id = (get_bits(&s->gb, 16) << 16) | get_bits(&s->gb, 16); + id = be2me_32(id); + len -= 4; + if (id == ff_get_fourcc("mjpg")) /* Apple MJPEG-A */ + { +#if 0 + skip_bits(&s->gb, 32); /* field size */ + skip_bits(&s->gb, 32); /* pad field size */ + skip_bits(&s->gb, 32); /* next off */ + skip_bits(&s->gb, 32); /* quant off */ + skip_bits(&s->gb, 32); /* huff off */ + skip_bits(&s->gb, 32); /* image off */ + skip_bits(&s->gb, 32); /* scan off */ + skip_bits(&s->gb, 32); /* data off */ +#endif + if (s->avctx->debug & FF_DEBUG_PICT_INFO) + av_log(s->avctx, AV_LOG_INFO, "mjpeg: Apple MJPEG-A header found\n"); + } + } + +out: + /* slow but needed for extreme adobe jpegs */ + if (len < 0) + av_log(s->avctx, AV_LOG_ERROR, "mjpeg: error, decode_app parser read over the end\n"); + while(--len > 0) + skip_bits(&s->gb, 8); + + return 0; +} + +static int mjpeg_decode_com(MJpegDecodeContext *s) +{ + int len = get_bits(&s->gb, 16); + if (len >= 2 && 8*len - 16 + get_bits_count(&s->gb) <= s->gb.size_in_bits) { + char *cbuf = av_malloc(len - 1); + if (cbuf) { + int i; + for (i = 0; i < len - 2; i++) + cbuf[i] = get_bits(&s->gb, 8); + if (i > 0 && cbuf[i-1] == '\n') + cbuf[i-1] = 0; + else + cbuf[i] = 0; + + if(s->avctx->debug & FF_DEBUG_PICT_INFO) + av_log(s->avctx, AV_LOG_INFO, "mjpeg comment: '%s'\n", cbuf); + + /* buggy avid, it puts EOI only at every 10th frame */ + if (!strcmp(cbuf, "AVID")) + { + s->buggy_avid = 1; + // if (s->first_picture) + // printf("mjpeg: workarounding buggy AVID\n"); + } + else if(!strcmp(cbuf, "CS=ITU601")){ + s->cs_itu601= 1; + } + + av_free(cbuf); + } + } + + return 0; +} + +#if 0 +static int valid_marker_list[] = +{ + /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f */ +/* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 1 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 2 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 3 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 4 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 5 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 6 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 7 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 8 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 9 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* a */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* b */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* c */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +/* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +/* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +/* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, +} +#endif + +/* return the 8 bit start code value and update the search + state. Return -1 if no start code found */ +static int find_marker(const uint8_t **pbuf_ptr, const uint8_t *buf_end) +{ + const uint8_t *buf_ptr; + unsigned int v, v2; + int val; +#ifdef DEBUG + int skipped=0; +#endif + + buf_ptr = *pbuf_ptr; + while (buf_ptr < buf_end) { + v = *buf_ptr++; + v2 = *buf_ptr; + if ((v == 0xff) && (v2 >= 0xc0) && (v2 <= 0xfe) && buf_ptr < buf_end) { + val = *buf_ptr++; + goto found; + } +#ifdef DEBUG + skipped++; +#endif + } + val = -1; +found: +#ifdef DEBUG + av_log(NULL, AV_LOG_VERBOSE, "find_marker skipped %d bytes\n", skipped); +#endif + *pbuf_ptr = buf_ptr; + return val; +} + +int ff_mjpeg_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size) +{ + MJpegDecodeContext *s = avctx->priv_data; + const uint8_t *buf_end, *buf_ptr; + int start_code; + AVFrame *picture = data; + + buf_ptr = buf; + buf_end = buf + buf_size; + while (buf_ptr < buf_end) { + /* find start next marker */ + start_code = find_marker(&buf_ptr, buf_end); + { + /* EOF */ + if (start_code < 0) { + goto the_end; + } else { + av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%td\n", start_code, buf_end - buf_ptr); + + if ((buf_end - buf_ptr) > s->buffer_size) + { + av_free(s->buffer); + s->buffer_size = buf_end-buf_ptr; + s->buffer = av_malloc(s->buffer_size + FF_INPUT_BUFFER_PADDING_SIZE); + av_log(avctx, AV_LOG_DEBUG, "buffer too small, expanding to %d bytes\n", + s->buffer_size); + } + + /* unescape buffer of SOS, use special treatment for JPEG-LS */ + if (start_code == SOS && !s->ls) + { + const uint8_t *src = buf_ptr; + uint8_t *dst = s->buffer; + + while (srccodec_id != CODEC_ID_THP) + { + if (x == 0xff) { + while (src < buf_end && x == 0xff) + x = *(src++); + + if (x >= 0xd0 && x <= 0xd7) + *(dst++) = x; + else if (x) + break; + } + } + } + init_get_bits(&s->gb, s->buffer, (dst - s->buffer)*8); + + av_log(avctx, AV_LOG_DEBUG, "escaping removed %td bytes\n", + (buf_end - buf_ptr) - (dst - s->buffer)); + } + else if(start_code == SOS && s->ls){ + const uint8_t *src = buf_ptr; + uint8_t *dst = s->buffer; + int bit_count = 0; + int t = 0, b = 0; + PutBitContext pb; + + s->cur_scan++; + + /* find marker */ + while (src + t < buf_end){ + uint8_t x = src[t++]; + if (x == 0xff){ + while((src + t < buf_end) && x == 0xff) + x = src[t++]; + if (x & 0x80) { + t -= 2; + break; + } + } + } + bit_count = t * 8; + + init_put_bits(&pb, dst, t); + + /* unescape bitstream */ + while(b < t){ + uint8_t x = src[b++]; + put_bits(&pb, 8, x); + if(x == 0xFF){ + x = src[b++]; + put_bits(&pb, 7, x); + bit_count--; + } + } + flush_put_bits(&pb); + + init_get_bits(&s->gb, dst, bit_count); + } + else + init_get_bits(&s->gb, buf_ptr, (buf_end - buf_ptr)*8); + + s->start_code = start_code; + if(s->avctx->debug & FF_DEBUG_STARTCODE){ + av_log(avctx, AV_LOG_DEBUG, "startcode: %X\n", start_code); + } + + /* process markers */ + if (start_code >= 0xd0 && start_code <= 0xd7) { + av_log(avctx, AV_LOG_DEBUG, "restart marker: %d\n", start_code&0x0f); + /* APP fields */ + } else if (start_code >= APP0 && start_code <= APP15) { + mjpeg_decode_app(s); + /* Comment */ + } else if (start_code == COM){ + mjpeg_decode_com(s); + } + + switch(start_code) { + case SOI: + s->restart_interval = 0; + + s->restart_count = 0; + /* nothing to do on SOI */ + break; + case DQT: + ff_mjpeg_decode_dqt(s); + break; + case DHT: + if(ff_mjpeg_decode_dht(s) < 0){ + av_log(avctx, AV_LOG_ERROR, "huffman table decode error\n"); + return -1; + } + break; + case SOF0: + s->lossless=0; + s->ls=0; + s->progressive=0; + if (ff_mjpeg_decode_sof(s) < 0) + return -1; + break; + case SOF2: + s->lossless=0; + s->ls=0; + s->progressive=1; + if (ff_mjpeg_decode_sof(s) < 0) + return -1; + break; + case SOF3: + s->lossless=1; + s->ls=0; + s->progressive=0; + if (ff_mjpeg_decode_sof(s) < 0) + return -1; + break; + case SOF48: + s->lossless=1; + s->ls=1; + s->progressive=0; + if (ff_mjpeg_decode_sof(s) < 0) + return -1; + break; + case LSE: + if (!ENABLE_JPEGLS_DECODER || ff_jpegls_decode_lse(s) < 0) + return -1; + break; + case EOI: + s->cur_scan = 0; + if ((s->buggy_avid && !s->interlaced) || s->restart_interval) + break; +eoi_parser: + { + if (s->interlaced) { + s->bottom_field ^= 1; + /* if not bottom field, do not output image yet */ + if (s->bottom_field == !s->interlace_polarity) + goto not_the_end; + } + *picture = s->picture; + *data_size = sizeof(AVFrame); + + if(!s->lossless){ + picture->quality= FFMAX(FFMAX(s->qscale[0], s->qscale[1]), s->qscale[2]); + picture->qstride= 0; + picture->qscale_table= s->qscale_table; + memset(picture->qscale_table, picture->quality, (s->width+15)/16); + if(avctx->debug & FF_DEBUG_QP) + av_log(avctx, AV_LOG_DEBUG, "QP: %d\n", picture->quality); + picture->quality*= FF_QP2LAMBDA; + } + + goto the_end; + } + break; + case SOS: + ff_mjpeg_decode_sos(s); + /* buggy avid puts EOI every 10-20th frame */ + /* if restart period is over process EOI */ + if ((s->buggy_avid && !s->interlaced) || s->restart_interval) + goto eoi_parser; + break; + case DRI: + mjpeg_decode_dri(s); + break; + case SOF1: + case SOF5: + case SOF6: + case SOF7: + case SOF9: + case SOF10: + case SOF11: + case SOF13: + case SOF14: + case SOF15: + case JPG: + av_log(avctx, AV_LOG_ERROR, "mjpeg: unsupported coding type (%x)\n", start_code); + break; +// default: +// printf("mjpeg: unsupported marker (%x)\n", start_code); +// break; + } + +not_the_end: + /* eof process start code */ + buf_ptr += (get_bits_count(&s->gb)+7)/8; + av_log(avctx, AV_LOG_DEBUG, "marker parser used %d bytes (%d bits)\n", + (get_bits_count(&s->gb)+7)/8, get_bits_count(&s->gb)); + } + } + } +the_end: + av_log(avctx, AV_LOG_DEBUG, "mjpeg decode frame unused %td bytes\n", buf_end - buf_ptr); +// return buf_end - buf_ptr; + return buf_ptr - buf; +} + +int ff_mjpeg_decode_end(AVCodecContext *avctx) +{ + MJpegDecodeContext *s = avctx->priv_data; + int i, j; + + av_free(s->buffer); + av_free(s->qscale_table); + + for(i=0;i<2;i++) { + for(j=0;j<4;j++) + free_vlc(&s->vlcs[i][j]); + } + return 0; +} + +AVCodec mjpeg_decoder = { + "mjpeg", + CODEC_TYPE_VIDEO, + CODEC_ID_MJPEG, + sizeof(MJpegDecodeContext), + ff_mjpeg_decode_init, + NULL, + ff_mjpeg_decode_end, + ff_mjpeg_decode_frame, + CODEC_CAP_DR1, + NULL +}; + +AVCodec thp_decoder = { + "thp", + CODEC_TYPE_VIDEO, + CODEC_ID_THP, + sizeof(MJpegDecodeContext), + ff_mjpeg_decode_init, + NULL, + ff_mjpeg_decode_end, + ff_mjpeg_decode_frame, + CODEC_CAP_DR1, + NULL +}; diff --git a/contrib/ffmpeg/libavcodec/mjpegdec.h b/contrib/ffmpeg/libavcodec/mjpegdec.h new file mode 100644 index 000000000..d97b176a9 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mjpegdec.h @@ -0,0 +1,112 @@ +/* + * MJPEG decoder + * Copyright (c) 2000, 2001 Fabrice Bellard. + * Copyright (c) 2003 Alex Beregszaszi + * Copyright (c) 2003-2004 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mjpegdec.h + * MJPEG decoder. + */ + +#ifndef FFMPEG_MJPEGDEC_H +#define FFMPEG_MJPEGDEC_H + +#include "avcodec.h" +#include "bitstream.h" +#include "dsputil.h" +#include "mpegvideo.h" + +#define MAX_COMPONENTS 4 + +typedef struct MJpegDecodeContext { + AVCodecContext *avctx; + GetBitContext gb; + + int start_code; /* current start code */ + int buffer_size; + uint8_t *buffer; + + int16_t quant_matrixes[4][64]; + VLC vlcs[2][4]; + int qscale[4]; ///< quantizer scale calculated from quant_matrixes + + int org_height; /* size given at codec init */ + int first_picture; /* true if decoding first picture */ + int interlaced; /* true if interlaced */ + int bottom_field; /* true if bottom field */ + int lossless; + int ls; + int progressive; + int rgb; + int rct; /* standard rct */ + int pegasus_rct; /* pegasus reversible colorspace transform */ + int bits; /* bits per component */ + + int maxval; + int near; ///< near lossless bound (si 0 for lossless) + int t1,t2,t3; + int reset; ///< context halfing intervall ?rename + + int width, height; + int mb_width, mb_height; + int nb_components; + int component_id[MAX_COMPONENTS]; + int h_count[MAX_COMPONENTS]; /* horizontal and vertical count for each component */ + int v_count[MAX_COMPONENTS]; + int comp_index[MAX_COMPONENTS]; + int dc_index[MAX_COMPONENTS]; + int ac_index[MAX_COMPONENTS]; + int nb_blocks[MAX_COMPONENTS]; + int h_scount[MAX_COMPONENTS]; + int v_scount[MAX_COMPONENTS]; + int h_max, v_max; /* maximum h and v counts */ + int quant_index[4]; /* quant table index for each component */ + int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */ + AVFrame picture; /* picture structure */ + int linesize[MAX_COMPONENTS]; ///< linesize << interlaced + int8_t *qscale_table; + DECLARE_ALIGNED_8(DCTELEM, block[64]); + ScanTable scantable; + DSPContext dsp; + + int restart_interval; + int restart_count; + + int buggy_avid; + int cs_itu601; + int interlace_polarity; + + int mjpb_skiptosod; + + int cur_scan; /* current scan, used by JPEG-LS */ +} MJpegDecodeContext; + +int ff_mjpeg_decode_init(AVCodecContext *avctx); +int ff_mjpeg_decode_end(AVCodecContext *avctx); +int ff_mjpeg_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size); +int ff_mjpeg_decode_dqt(MJpegDecodeContext *s); +int ff_mjpeg_decode_dht(MJpegDecodeContext *s); +int ff_mjpeg_decode_sof(MJpegDecodeContext *s); +int ff_mjpeg_decode_sos(MJpegDecodeContext *s); + +#endif /* FFMPEG_MJPEGDEC_H */ diff --git a/contrib/ffmpeg/libavcodec/mjpegenc.c b/contrib/ffmpeg/libavcodec/mjpegenc.c new file mode 100644 index 000000000..b5e5a827d --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mjpegenc.c @@ -0,0 +1,458 @@ +/* + * MJPEG encoder + * Copyright (c) 2000, 2001 Fabrice Bellard. + * Copyright (c) 2003 Alex Beregszaszi + * Copyright (c) 2003-2004 Michael Niedermayer + * + * Support for external huffman table, various fixes (AVID workaround), + * aspecting, new decode_frame mechanism and apple mjpeg-b support + * by Alex Beregszaszi + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mjpegenc.c + * MJPEG encoder. + */ + +//#define DEBUG +#include + +#include "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" +#include "mjpeg.h" +#include "mjpegenc.h" + +/* use two quantizer tables (one for luminance and one for chrominance) */ +/* not yet working */ +#undef TWOMATRIXES + + +int ff_mjpeg_encode_init(MpegEncContext *s) +{ + MJpegContext *m; + + m = av_malloc(sizeof(MJpegContext)); + if (!m) + return -1; + + s->min_qcoeff=-1023; + s->max_qcoeff= 1023; + + /* build all the huffman tables */ + ff_mjpeg_build_huffman_codes(m->huff_size_dc_luminance, + m->huff_code_dc_luminance, + ff_mjpeg_bits_dc_luminance, + ff_mjpeg_val_dc_luminance); + ff_mjpeg_build_huffman_codes(m->huff_size_dc_chrominance, + m->huff_code_dc_chrominance, + ff_mjpeg_bits_dc_chrominance, + ff_mjpeg_val_dc_chrominance); + ff_mjpeg_build_huffman_codes(m->huff_size_ac_luminance, + m->huff_code_ac_luminance, + ff_mjpeg_bits_ac_luminance, + ff_mjpeg_val_ac_luminance); + ff_mjpeg_build_huffman_codes(m->huff_size_ac_chrominance, + m->huff_code_ac_chrominance, + ff_mjpeg_bits_ac_chrominance, + ff_mjpeg_val_ac_chrominance); + + s->mjpeg_ctx = m; + return 0; +} + +void ff_mjpeg_encode_close(MpegEncContext *s) +{ + av_free(s->mjpeg_ctx); +} + +/* table_class: 0 = DC coef, 1 = AC coefs */ +static int put_huffman_table(MpegEncContext *s, int table_class, int table_id, + const uint8_t *bits_table, const uint8_t *value_table) +{ + PutBitContext *p = &s->pb; + int n, i; + + put_bits(p, 4, table_class); + put_bits(p, 4, table_id); + + n = 0; + for(i=1;i<=16;i++) { + n += bits_table[i]; + put_bits(p, 8, bits_table[i]); + } + + for(i=0;ipb; + int i, j, size; + uint8_t *ptr; + + /* quant matrixes */ + put_marker(p, DQT); +#ifdef TWOMATRIXES + put_bits(p, 16, 2 + 2 * (1 + 64)); +#else + put_bits(p, 16, 2 + 1 * (1 + 64)); +#endif + put_bits(p, 4, 0); /* 8 bit precision */ + put_bits(p, 4, 0); /* table 0 */ + for(i=0;i<64;i++) { + j = s->intra_scantable.permutated[i]; + put_bits(p, 8, s->intra_matrix[j]); + } +#ifdef TWOMATRIXES + put_bits(p, 4, 0); /* 8 bit precision */ + put_bits(p, 4, 1); /* table 1 */ + for(i=0;i<64;i++) { + j = s->intra_scantable.permutated[i]; + put_bits(p, 8, s->chroma_intra_matrix[j]); + } +#endif + + /* huffman table */ + put_marker(p, DHT); + flush_put_bits(p); + ptr = pbBufPtr(p); + put_bits(p, 16, 0); /* patched later */ + size = 2; + size += put_huffman_table(s, 0, 0, ff_mjpeg_bits_dc_luminance, + ff_mjpeg_val_dc_luminance); + size += put_huffman_table(s, 0, 1, ff_mjpeg_bits_dc_chrominance, + ff_mjpeg_val_dc_chrominance); + + size += put_huffman_table(s, 1, 0, ff_mjpeg_bits_ac_luminance, + ff_mjpeg_val_ac_luminance); + size += put_huffman_table(s, 1, 1, ff_mjpeg_bits_ac_chrominance, + ff_mjpeg_val_ac_chrominance); + AV_WB16(ptr, size); +} + +static void jpeg_put_comments(MpegEncContext *s) +{ + PutBitContext *p = &s->pb; + int size; + uint8_t *ptr; + + if (s->aspect_ratio_info /* && !lossless */) + { + /* JFIF header */ + put_marker(p, APP0); + put_bits(p, 16, 16); + ff_put_string(p, "JFIF", 1); /* this puts the trailing zero-byte too */ + put_bits(p, 16, 0x0201); /* v 1.02 */ + put_bits(p, 8, 0); /* units type: 0 - aspect ratio */ + put_bits(p, 16, s->avctx->sample_aspect_ratio.num); + put_bits(p, 16, s->avctx->sample_aspect_ratio.den); + put_bits(p, 8, 0); /* thumbnail width */ + put_bits(p, 8, 0); /* thumbnail height */ + } + + /* comment */ + if(!(s->flags & CODEC_FLAG_BITEXACT)){ + put_marker(p, COM); + flush_put_bits(p); + ptr = pbBufPtr(p); + put_bits(p, 16, 0); /* patched later */ + ff_put_string(p, LIBAVCODEC_IDENT, 1); + size = strlen(LIBAVCODEC_IDENT)+3; + AV_WB16(ptr, size); + } + + if( s->avctx->pix_fmt == PIX_FMT_YUV420P + ||s->avctx->pix_fmt == PIX_FMT_YUV422P + ||s->avctx->pix_fmt == PIX_FMT_YUV444P){ + put_marker(p, COM); + flush_put_bits(p); + ptr = pbBufPtr(p); + put_bits(p, 16, 0); /* patched later */ + ff_put_string(p, "CS=ITU601", 1); + size = strlen("CS=ITU601")+3; + AV_WB16(ptr, size); + } +} + +void ff_mjpeg_encode_picture_header(MpegEncContext *s) +{ + const int lossless= s->avctx->codec_id != CODEC_ID_MJPEG; + + put_marker(&s->pb, SOI); + + jpeg_put_comments(s); + + jpeg_table_header(s); + + switch(s->avctx->codec_id){ + case CODEC_ID_MJPEG: put_marker(&s->pb, SOF0 ); break; + case CODEC_ID_LJPEG: put_marker(&s->pb, SOF3 ); break; + default: assert(0); + } + + put_bits(&s->pb, 16, 17); + if(lossless && s->avctx->pix_fmt == PIX_FMT_RGB32) + put_bits(&s->pb, 8, 9); /* 9 bits/component RCT */ + else + put_bits(&s->pb, 8, 8); /* 8 bits/component */ + put_bits(&s->pb, 16, s->height); + put_bits(&s->pb, 16, s->width); + put_bits(&s->pb, 8, 3); /* 3 components */ + + /* Y component */ + put_bits(&s->pb, 8, 1); /* component number */ + put_bits(&s->pb, 4, s->mjpeg_hsample[0]); /* H factor */ + put_bits(&s->pb, 4, s->mjpeg_vsample[0]); /* V factor */ + put_bits(&s->pb, 8, 0); /* select matrix */ + + /* Cb component */ + put_bits(&s->pb, 8, 2); /* component number */ + put_bits(&s->pb, 4, s->mjpeg_hsample[1]); /* H factor */ + put_bits(&s->pb, 4, s->mjpeg_vsample[1]); /* V factor */ +#ifdef TWOMATRIXES + put_bits(&s->pb, 8, lossless ? 0 : 1); /* select matrix */ +#else + put_bits(&s->pb, 8, 0); /* select matrix */ +#endif + + /* Cr component */ + put_bits(&s->pb, 8, 3); /* component number */ + put_bits(&s->pb, 4, s->mjpeg_hsample[2]); /* H factor */ + put_bits(&s->pb, 4, s->mjpeg_vsample[2]); /* V factor */ +#ifdef TWOMATRIXES + put_bits(&s->pb, 8, lossless ? 0 : 1); /* select matrix */ +#else + put_bits(&s->pb, 8, 0); /* select matrix */ +#endif + + /* scan header */ + put_marker(&s->pb, SOS); + put_bits(&s->pb, 16, 12); /* length */ + put_bits(&s->pb, 8, 3); /* 3 components */ + + /* Y component */ + put_bits(&s->pb, 8, 1); /* index */ + put_bits(&s->pb, 4, 0); /* DC huffman table index */ + put_bits(&s->pb, 4, 0); /* AC huffman table index */ + + /* Cb component */ + put_bits(&s->pb, 8, 2); /* index */ + put_bits(&s->pb, 4, 1); /* DC huffman table index */ + put_bits(&s->pb, 4, lossless ? 0 : 1); /* AC huffman table index */ + + /* Cr component */ + put_bits(&s->pb, 8, 3); /* index */ + put_bits(&s->pb, 4, 1); /* DC huffman table index */ + put_bits(&s->pb, 4, lossless ? 0 : 1); /* AC huffman table index */ + + put_bits(&s->pb, 8, lossless ? s->avctx->prediction_method+1 : 0); /* Ss (not used) */ + + switch(s->avctx->codec_id){ + case CODEC_ID_MJPEG: put_bits(&s->pb, 8, 63); break; /* Se (not used) */ + case CODEC_ID_LJPEG: put_bits(&s->pb, 8, 0); break; /* not used */ + default: assert(0); + } + + put_bits(&s->pb, 8, 0); /* Ah/Al (not used) */ +} + +static void escape_FF(MpegEncContext *s, int start) +{ + int size= put_bits_count(&s->pb) - start*8; + int i, ff_count; + uint8_t *buf= s->pb.buf + start; + int align= (-(size_t)(buf))&3; + + assert((size&7) == 0); + size >>= 3; + + ff_count=0; + for(i=0; i>4))&0x0F0F0F0F)+0x01010101)&0x10101010; + v= *(uint32_t*)(&buf[i+4]); + acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010; + v= *(uint32_t*)(&buf[i+8]); + acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010; + v= *(uint32_t*)(&buf[i+12]); + acc+=(((v & (v>>4))&0x0F0F0F0F)+0x01010101)&0x10101010; + + acc>>=4; + acc+= (acc>>16); + acc+= (acc>>8); + ff_count+= acc&0xFF; + } + for(; ipb, 32, 0); + put_bits(&s->pb, (ff_count-i)*8, 0); + flush_put_bits(&s->pb); + + for(i=size-1; ff_count; i--){ + int v= buf[i]; + + if(v==0xFF){ +//printf("%d %d\n", i, ff_count); + buf[i+ff_count]= 0; + ff_count--; + } + + buf[i+ff_count]= v; + } +} + +void ff_mjpeg_encode_stuffing(PutBitContext * pbc) +{ + int length; + length= (-put_bits_count(pbc))&7; + if(length) put_bits(pbc, length, (1<pb); + flush_put_bits(&s->pb); + + assert((s->header_bits&7)==0); + + escape_FF(s, s->header_bits>>3); + + put_marker(&s->pb, EOI); +} + +void ff_mjpeg_encode_dc(MpegEncContext *s, int val, + uint8_t *huff_size, uint16_t *huff_code) +{ + int mant, nbits; + + if (val == 0) { + put_bits(&s->pb, huff_size[0], huff_code[0]); + } else { + mant = val; + if (val < 0) { + val = -val; + mant--; + } + + nbits= av_log2_16bit(val) + 1; + + put_bits(&s->pb, huff_size[nbits], huff_code[nbits]); + + put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); + } +} + +static void encode_block(MpegEncContext *s, DCTELEM *block, int n) +{ + int mant, nbits, code, i, j; + int component, dc, run, last_index, val; + MJpegContext *m = s->mjpeg_ctx; + uint8_t *huff_size_ac; + uint16_t *huff_code_ac; + + /* DC coef */ + component = (n <= 3 ? 0 : (n&1) + 1); + dc = block[0]; /* overflow is impossible */ + val = dc - s->last_dc[component]; + if (n < 4) { + ff_mjpeg_encode_dc(s, val, m->huff_size_dc_luminance, m->huff_code_dc_luminance); + huff_size_ac = m->huff_size_ac_luminance; + huff_code_ac = m->huff_code_ac_luminance; + } else { + ff_mjpeg_encode_dc(s, val, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance); + huff_size_ac = m->huff_size_ac_chrominance; + huff_code_ac = m->huff_code_ac_chrominance; + } + s->last_dc[component] = dc; + + /* AC coefs */ + + run = 0; + last_index = s->block_last_index[n]; + for(i=1;i<=last_index;i++) { + j = s->intra_scantable.permutated[i]; + val = block[j]; + if (val == 0) { + run++; + } else { + while (run >= 16) { + put_bits(&s->pb, huff_size_ac[0xf0], huff_code_ac[0xf0]); + run -= 16; + } + mant = val; + if (val < 0) { + val = -val; + mant--; + } + + nbits= av_log2(val) + 1; + code = (run << 4) | nbits; + + put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]); + + put_bits(&s->pb, nbits, mant & ((1 << nbits) - 1)); + run = 0; + } + } + + /* output EOB only if not already 64 values */ + if (last_index < 63 || run != 0) + put_bits(&s->pb, huff_size_ac[0], huff_code_ac[0]); +} + +void ff_mjpeg_encode_mb(MpegEncContext *s, DCTELEM block[6][64]) +{ + int i; + for(i=0;i<5;i++) { + encode_block(s, block[i], i); + } + if (s->chroma_format == CHROMA_420) { + encode_block(s, block[5], 5); + } else { + encode_block(s, block[6], 6); + encode_block(s, block[5], 5); + encode_block(s, block[7], 7); + } +} + +AVCodec mjpeg_encoder = { + "mjpeg", + CODEC_TYPE_VIDEO, + CODEC_ID_MJPEG, + sizeof(MpegEncContext), + MPV_encode_init, + MPV_encode_picture, + MPV_encode_end, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, -1}, +}; diff --git a/contrib/ffmpeg/libavcodec/mjpegenc.h b/contrib/ffmpeg/libavcodec/mjpegenc.h new file mode 100644 index 000000000..02f8a714c --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mjpegenc.h @@ -0,0 +1,60 @@ +/* + * MJPEG encoder + * Copyright (c) 2000, 2001 Fabrice Bellard. + * Copyright (c) 2003 Alex Beregszaszi + * Copyright (c) 2003-2004 Michael Niedermayer + * + * Support for external huffman table, various fixes (AVID workaround), + * aspecting, new decode_frame mechanism and apple mjpeg-b support + * by Alex Beregszaszi + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mjpegenc.h + * MJPEG encoder. + */ + +#ifndef FFMPEG_MJPEGENC_H +#define FFMPEG_MJPEGENC_H + +#include "dsputil.h" +#include "mpegvideo.h" + +typedef struct MJpegContext { + uint8_t huff_size_dc_luminance[12]; //FIXME use array [3] instead of lumi / chrom, for easier addressing + uint16_t huff_code_dc_luminance[12]; + uint8_t huff_size_dc_chrominance[12]; + uint16_t huff_code_dc_chrominance[12]; + + uint8_t huff_size_ac_luminance[256]; + uint16_t huff_code_ac_luminance[256]; + uint8_t huff_size_ac_chrominance[256]; + uint16_t huff_code_ac_chrominance[256]; +} MJpegContext; + +int ff_mjpeg_encode_init(MpegEncContext *s); +void ff_mjpeg_encode_close(MpegEncContext *s); +void ff_mjpeg_encode_picture_header(MpegEncContext *s); +void ff_mjpeg_encode_picture_trailer(MpegEncContext *s); +void ff_mjpeg_encode_stuffing(PutBitContext *pbc); +void ff_mjpeg_encode_dc(MpegEncContext *s, int val, + uint8_t *huff_size, uint16_t *huff_code); +void ff_mjpeg_encode_mb(MpegEncContext *s, DCTELEM block[6][64]); + +#endif /* FFMPEG_MJPEGENC_H */ diff --git a/contrib/ffmpeg/libavcodec/mlib/dsputil_mlib.c b/contrib/ffmpeg/libavcodec/mlib/dsputil_mlib.c index b78a54e0e..203a8da53 100644 --- a/contrib/ffmpeg/libavcodec/mlib/dsputil_mlib.c +++ b/contrib/ffmpeg/libavcodec/mlib/dsputil_mlib.c @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../dsputil.h" -#include "../mpegvideo.h" +#include "dsputil.h" +#include "mpegvideo.h" #include #include @@ -374,7 +374,7 @@ static void avg_pixels8_xy2_mlib(uint8_t * dest, const uint8_t * ref, /* swap byte order of a buffer */ -static void bswap_buf_mlib(uint32_t *dst, uint32_t *src, int w) +static void bswap_buf_mlib(uint32_t *dst, const uint32_t *src, int w) { mlib_VectorReverseByteOrder_U32_U32(dst, src, w); } diff --git a/contrib/ffmpeg/libavcodec/mlp_parser.c b/contrib/ffmpeg/libavcodec/mlp_parser.c new file mode 100644 index 000000000..96dbc5943 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mlp_parser.c @@ -0,0 +1,307 @@ +/* + * MLP parser + * Copyright (c) 2007 Ian Caulfield + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mlp_parser.c + * MLP parser + */ + +#include "bitstream.h" +#include "parser.h" +#include "crc.h" +#include "mlp_parser.h" + +static const uint8_t mlp_quants[16] = { + 16, 20, 24, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, +}; + +static const uint8_t mlp_channels[32] = { + 1, 2, 3, 4, 3, 4, 5, 3, 4, 5, 4, 5, 6, 4, 5, 4, + 5, 6, 5, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; + +static const uint8_t thd_chancount[13] = { +// LR C LFE LRs LRvh LRc LRrs Cs Ts LRsd LRw Cvh LFE2 + 2, 1, 1, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1 +}; + +static int mlp_samplerate(int in) +{ + if (in == 0xF) + return 0; + + return (in & 8 ? 44100 : 48000) << (in & 7) ; +} + +static int truehd_channels(int chanmap) +{ + int channels = 0, i; + + for (i = 0; i < 13; i++) + channels += thd_chancount[i] * ((chanmap >> i) & 1); + + return channels; +} + +static int crc_init = 0; +static AVCRC crc_2D[1024]; + +/** MLP uses checksums that seem to be based on the standard CRC algorithm, + * but not (in implementation terms, the table lookup and XOR are reversed). + * We can implement this behavior using a standard av_crc on all but the + * last element, then XOR that with the last element. + */ + +static uint16_t mlp_checksum16(const uint8_t *buf, unsigned int buf_size) +{ + uint16_t crc; + + if (!crc_init) { + av_crc_init(crc_2D, 0, 16, 0x002D, sizeof(crc_2D)); + crc_init = 1; + } + + crc = av_crc(crc_2D, 0, buf, buf_size - 2); + crc ^= AV_RL16(buf + buf_size - 2); + return crc; +} + +/** Read a major sync info header - contains high level information about + * the stream - sample rate, channel arrangement etc. Most of this + * information is not actually necessary for decoding, only for playback. + */ + +int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, const uint8_t *buf, + unsigned int buf_size) +{ + GetBitContext gb; + int ratebits; + uint16_t checksum; + + if (buf_size < 28) { + av_log(log, AV_LOG_ERROR, "Packet too short, unable to read major sync\n"); + return -1; + } + + checksum = mlp_checksum16(buf, 26); + if (checksum != AV_RL16(buf+26)) { + av_log(log, AV_LOG_ERROR, "Major sync info header checksum error\n"); + return -1; + } + + init_get_bits(&gb, buf, buf_size * 8); + + if (get_bits_long(&gb, 24) != 0xf8726f) /* Sync words */ + return -1; + + mh->stream_type = get_bits(&gb, 8); + + if (mh->stream_type == 0xbb) { + mh->group1_bits = mlp_quants[get_bits(&gb, 4)]; + mh->group2_bits = mlp_quants[get_bits(&gb, 4)]; + + ratebits = get_bits(&gb, 4); + mh->group1_samplerate = mlp_samplerate(ratebits); + mh->group2_samplerate = mlp_samplerate(get_bits(&gb, 4)); + + skip_bits(&gb, 11); + + mh->channels_mlp = get_bits(&gb, 5); + } else if (mh->stream_type == 0xba) { + mh->group1_bits = 24; // TODO: Is this information actually conveyed anywhere? + mh->group2_bits = 0; + + ratebits = get_bits(&gb, 4); + mh->group1_samplerate = mlp_samplerate(ratebits); + mh->group2_samplerate = 0; + + skip_bits(&gb, 8); + + mh->channels_thd_stream1 = get_bits(&gb, 5); + + skip_bits(&gb, 2); + + mh->channels_thd_stream2 = get_bits(&gb, 13); + } else + return -1; + + mh->access_unit_size = 40 << (ratebits & 7); + mh->access_unit_size_pow2 = 64 << (ratebits & 7); + + skip_bits_long(&gb, 48); + + mh->is_vbr = get_bits1(&gb); + + mh->peak_bitrate = (get_bits(&gb, 15) * mh->group1_samplerate + 8) >> 4; + + mh->num_substreams = get_bits(&gb, 4); + + skip_bits_long(&gb, 4 + 11 * 8); + + return 0; +} + +typedef struct MLPParseContext +{ + ParseContext pc; + + int bytes_left; + + int in_sync; + + int num_substreams; +} MLPParseContext; + +static int mlp_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + MLPParseContext *mp = s->priv_data; + int sync_present; + uint8_t parity_bits; + int next; + int i, p = 0; + + *poutbuf_size = 0; + if (buf_size == 0) + return 0; + + if (!mp->in_sync) { + // Not in sync - find a major sync header + + for (i = 0; i < buf_size; i++) { + mp->pc.state = (mp->pc.state << 8) | buf[i]; + if ((mp->pc.state & 0xfffffffe) == 0xf8726fba) { + mp->in_sync = 1; + mp->bytes_left = 0; + break; + } + } + + if (!mp->in_sync) { + ff_combine_frame(&mp->pc, END_NOT_FOUND, &buf, &buf_size); + return buf_size; + } + + ff_combine_frame(&mp->pc, i - 7, &buf, &buf_size); + + return i - 7; + } + + if (mp->bytes_left == 0) { + // Find length of this packet + + /* Copy overread bytes from last frame into buffer. */ + for(; mp->pc.overread>0; mp->pc.overread--) { + mp->pc.buffer[mp->pc.index++]= mp->pc.buffer[mp->pc.overread_index++]; + } + + if (mp->pc.index + buf_size < 2) { + ff_combine_frame(&mp->pc, END_NOT_FOUND, &buf, &buf_size); + return buf_size; + } + + mp->bytes_left = ((mp->pc.index > 0 ? mp->pc.buffer[0] : buf[0]) << 8) + | (mp->pc.index > 1 ? mp->pc.buffer[1] : buf[1-mp->pc.index]); + mp->bytes_left = (mp->bytes_left & 0xfff) * 2; + mp->bytes_left -= mp->pc.index; + } + + next = (mp->bytes_left > buf_size) ? END_NOT_FOUND : mp->bytes_left; + + if (ff_combine_frame(&mp->pc, next, &buf, &buf_size) < 0) { + mp->bytes_left -= buf_size; + return buf_size; + } + + mp->bytes_left = 0; + + sync_present = (AV_RB32(buf + 4) & 0xfffffffe) == 0xf8726fba; + + if (!sync_present) { + // First nibble of a frame is a parity check of the first few nibbles. + // Only check when this isn't a sync frame - syncs have a checksum. + + parity_bits = 0; + for (i = 0; i <= mp->num_substreams; i++) { + parity_bits ^= buf[p++]; + parity_bits ^= buf[p++]; + + if (i == 0 || buf[p-2] & 0x80) { + parity_bits ^= buf[p++]; + parity_bits ^= buf[p++]; + } + } + + if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) { + av_log(avctx, AV_LOG_INFO, "mlpparse: Parity check failed.\n"); + goto lost_sync; + } + } else { + MLPHeaderInfo mh; + + if (ff_mlp_read_major_sync(avctx, &mh, buf + 4, buf_size - 4) < 0) + goto lost_sync; + +#ifdef CONFIG_AUDIO_NONSHORT + avctx->bits_per_sample = mh.group1_bits; + if (avctx->bits_per_sample > 16) + avctx->sample_fmt = SAMPLE_FMT_S32; +#endif + avctx->sample_rate = mh.group1_samplerate; + avctx->frame_size = mh.access_unit_size; + + if (mh.stream_type == 0xbb) { + /* MLP stream */ + avctx->channels = mlp_channels[mh.channels_mlp]; + } else { /* mh.stream_type == 0xba */ + /* TrueHD stream */ + if (mh.channels_thd_stream2) + avctx->channels = truehd_channels(mh.channels_thd_stream2); + else + avctx->channels = truehd_channels(mh.channels_thd_stream1); + } + + if (!mh.is_vbr) /* Stream is CBR */ + avctx->bit_rate = mh.peak_bitrate; + + mp->num_substreams = mh.num_substreams; + } + + *poutbuf = buf; + *poutbuf_size = buf_size; + + return next; + +lost_sync: + mp->in_sync = 0; + return -1; +} + +AVCodecParser mlp_parser = { + { CODEC_ID_MLP }, + sizeof(MLPParseContext), + NULL, + mlp_parse, + NULL, +}; diff --git a/contrib/ffmpeg/libavcodec/mlp_parser.h b/contrib/ffmpeg/libavcodec/mlp_parser.h new file mode 100644 index 000000000..d690b4f45 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mlp_parser.h @@ -0,0 +1,60 @@ +/* + * MLP parser prototypes + * Copyright (c) 2007 Ian Caulfield + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mlp_parser.h + * MLP parser prototypes + */ + +#ifndef FFMPEG_MLP_PARSER_H +#define FFMPEG_MLP_PARSER_H + +#include + +typedef struct MLPHeaderInfo +{ + int stream_type; ///< 0xBB for MLP, 0xBA for TrueHD + + int group1_bits; ///< The bit depth of the first substream + int group2_bits; ///< Bit depth of the second substream (MLP only) + + int group1_samplerate; ///< Sample rate of first substream + int group2_samplerate; ///< Sample rate of second substream (MLP only) + + int channels_mlp; ///< Channel arrangement for MLP streams + int channels_thd_stream1; ///< Channel arrangement for substream 1 of TrueHD streams (5.1) + int channels_thd_stream2; ///< Channel arrangement for substream 2 of TrueHD streams (7.1) + + int access_unit_size; ///< Number of samples per coded frame + int access_unit_size_pow2; ///< Next power of two above number of samples per frame + + int is_vbr; ///< Stream is VBR instead of CBR + int peak_bitrate; ///< Peak bitrate for VBR, actual bitrate (==peak) for CBR + + int num_substreams; ///< Number of substreams within stream +} MLPHeaderInfo; + + +int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, const uint8_t *buf, + unsigned int buf_size); + +#endif /* FFMPEG_MLP_PARSER_H */ + diff --git a/contrib/ffmpeg/libavcodec/mmvideo.c b/contrib/ffmpeg/libavcodec/mmvideo.c index 7ba1321cb..9c169a004 100644 --- a/contrib/ffmpeg/libavcodec/mmvideo.c +++ b/contrib/ffmpeg/libavcodec/mmvideo.c @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** @@ -59,7 +59,6 @@ static int mm_decode_init(AVCodecContext *avctx) } avctx->pix_fmt = PIX_FMT_PAL8; - avctx->has_b_frames = 0; if (avcodec_check_dimensions(avctx, avctx->width, avctx->height)) return -1; @@ -151,7 +150,7 @@ static void mm_decode_inter(MmContext * s, int half_horiz, int half_vert, const static int mm_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { MmContext *s = avctx->priv_data; AVPaletteControl *palette_control = avctx->palctrl; diff --git a/contrib/ffmpeg/libavcodec/motion-test.c b/contrib/ffmpeg/libavcodec/motion-test.c new file mode 100644 index 000000000..69791500b --- /dev/null +++ b/contrib/ffmpeg/libavcodec/motion-test.c @@ -0,0 +1,164 @@ +/* + * (c) 2001 Fabrice Bellard + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file motion_test.c + * motion test. + */ + +#include +#include +#include +#include +#include + +#include "dsputil.h" + +#include "i386/mmx.h" + +#undef exit +#undef printf +#undef random + +#define WIDTH 64 +#define HEIGHT 64 + +uint8_t img1[WIDTH * HEIGHT]; +uint8_t img2[WIDTH * HEIGHT]; + +void fill_random(uint8_t *tab, int size) +{ + int i; + for(i=0;idsp_mask = FF_MM_FORCE; + dsputil_init(&cctx, ctx); + for (c = 0; c < 2; c++) { + int x; + ctx->dsp_mask = FF_MM_FORCE | flags[c]; + dsputil_init(&mmxctx, ctx); + + for (x = 0; x < 2; x++) { + printf("%s for %dx%d pixels\n", c ? "mmx2" : "mmx", + x ? 8 : 16, x ? 8 : 16); + test_motion("mmx", mmxctx.pix_abs[x][0], cctx.pix_abs[x][0]); + test_motion("mmx_x2", mmxctx.pix_abs[x][1], cctx.pix_abs[x][1]); + test_motion("mmx_y2", mmxctx.pix_abs[x][2], cctx.pix_abs[x][2]); + test_motion("mmx_xy2", mmxctx.pix_abs[x][3], cctx.pix_abs[x][3]); + } + } + av_free(ctx); + + return 0; +} diff --git a/contrib/ffmpeg/libavcodec/motion_est.c b/contrib/ffmpeg/libavcodec/motion_est.c index a042f4916..16db0f87c 100644 --- a/contrib/ffmpeg/libavcodec/motion_est.c +++ b/contrib/ffmpeg/libavcodec/motion_est.c @@ -3,6 +3,7 @@ * Copyright (c) 2000,2001 Fabrice Bellard. * Copyright (c) 2002-2004 Michael Niedermayer * + * new motion estimation (X1/EPZS) by Michael Niedermayer * * This file is part of FFmpeg. * @@ -19,8 +20,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * new Motion Estimation (X1/EPZS) by Michael Niedermayer */ /** @@ -279,7 +278,9 @@ void ff_init_me(MpegEncContext *s){ c->uvstride= 8*s->mb_width + 16; } - // 8x8 fullpel search would need a 4x4 chroma compare, which we dont have yet, and even if we had the motion estimation code doesnt expect it + /* 8x8 fullpel search would need a 4x4 chroma compare, which we do + * not have yet, and even if we had, the motion estimation code + * does not expect it. */ if(s->codec_id != CODEC_ID_SNOW){ if((c->avctx->me_cmp&FF_CMP_CHROMA)/* && !s->dsp.me_cmp[2]*/){ s->dsp.me_cmp[2]= zero_cmp; @@ -1805,7 +1806,7 @@ static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y) P_LEFT[1] = av_clip(mv_table[mot_xy - 1][1], ymin<first_slice_line) { //FIXME maybe allow this over thread boundary as its clipped + if (!s->first_slice_line) { //FIXME maybe allow this over thread boundary as it is clipped P_TOP[0] = av_clip(mv_table[mot_xy - mot_stride ][0], xmin<256*256*16) type&= ~CANDIDATE_MB_TYPE_DIRECT; //dont try direct mode if its invalid for this MB + if(dmin>256*256*16) type&= ~CANDIDATE_MB_TYPE_DIRECT; //do not try direct mode if it is invalid for this MB if(s->codec_id == CODEC_ID_MPEG4 && type&CANDIDATE_MB_TYPE_DIRECT && s->flags&CODEC_FLAG_MV0 && *(uint32_t*)s->b_direct_mv_table[xy]) type |= CANDIDATE_MB_TYPE_DIRECT0; #if 0 diff --git a/contrib/ffmpeg/libavcodec/motion_est_template.c b/contrib/ffmpeg/libavcodec/motion_est_template.c index 37443b022..70b4f824a 100644 --- a/contrib/ffmpeg/libavcodec/motion_est_template.c +++ b/contrib/ffmpeg/libavcodec/motion_est_template.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -27,11 +26,11 @@ //lets hope gcc will remove the unused vars ...(gcc 3.2.2 seems to do it ...) #define LOAD_COMMON\ - uint32_t attribute_unused * const score_map= c->score_map;\ - const int attribute_unused xmin= c->xmin;\ - const int attribute_unused ymin= c->ymin;\ - const int attribute_unused xmax= c->xmax;\ - const int attribute_unused ymax= c->ymax;\ + uint32_t av_unused * const score_map= c->score_map;\ + const int av_unused xmin= c->xmin;\ + const int av_unused ymin= c->ymin;\ + const int av_unused xmax= c->xmax;\ + const int av_unused ymax= c->ymax;\ uint8_t *mv_penalty= c->current_mv_penalty;\ const int pred_x= c->pred_x;\ const int pred_y= c->pred_y;\ diff --git a/contrib/ffmpeg/libavcodec/motion_test.c b/contrib/ffmpeg/libavcodec/motion_test.c deleted file mode 100644 index ecdb62a4e..000000000 --- a/contrib/ffmpeg/libavcodec/motion_test.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * (c) 2001 Fabrice Bellard - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file motion_test.c - * motion test. - */ - -#include -#include -#include -#include -#include - -#include "dsputil.h" - -#include "i386/mmx.h" - -#undef exit -#undef printf - -int pix_abs16x16_mmx(uint8_t *blk1, uint8_t *blk2, int lx); -int pix_abs16x16_mmx1(uint8_t *blk1, uint8_t *blk2, int lx); -int pix_abs16x16_c(uint8_t *blk1, uint8_t *blk2, int lx); -int pix_abs16x16_x2_mmx(uint8_t *blk1, uint8_t *blk2, int lx); -int pix_abs16x16_x2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx); -int pix_abs16x16_x2_c(uint8_t *blk1, uint8_t *blk2, int lx); -int pix_abs16x16_y2_mmx(uint8_t *blk1, uint8_t *blk2, int lx); -int pix_abs16x16_y2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx); -int pix_abs16x16_y2_c(uint8_t *blk1, uint8_t *blk2, int lx); -int pix_abs16x16_xy2_mmx(uint8_t *blk1, uint8_t *blk2, int lx); -int pix_abs16x16_xy2_mmx1(uint8_t *blk1, uint8_t *blk2, int lx); -int pix_abs16x16_xy2_c(uint8_t *blk1, uint8_t *blk2, int lx); - -typedef int motion_func(uint8_t *blk1, uint8_t *blk2, int lx); - -#define WIDTH 64 -#define HEIGHT 64 - -uint8_t img1[WIDTH * HEIGHT]; -uint8_t img2[WIDTH * HEIGHT]; - -void fill_random(uint8_t *tab, int size) -{ - int i; - for(i=0;i 0xffff) return 0; + *poutbuf_size = buf_size + 2; + *poutbuf = av_malloc(*poutbuf_size + FF_INPUT_BUFFER_PADDING_SIZE); + AV_WB16(*poutbuf, buf_size); + memcpy(*poutbuf + 2, buf, buf_size); + return 1; +} + +AVBitStreamFilter text2movsub_bsf={ + "text2movsub", + 0, + text2movsub, +}; + +static int mov2textsub(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, + uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size, int keyframe){ + if (buf_size < 2) return 0; + *poutbuf_size = FFMIN(buf_size - 2, AV_RB16(buf)); + *poutbuf = av_malloc(*poutbuf_size + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(*poutbuf, buf + 2, *poutbuf_size); + return 1; +} + +AVBitStreamFilter mov2textsub_bsf={ + "mov2textsub", + 0, + mov2textsub, +}; diff --git a/contrib/ffmpeg/libavcodec/mp3_header_compress_bsf.c b/contrib/ffmpeg/libavcodec/mp3_header_compress_bsf.c new file mode 100644 index 000000000..f5c513834 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mp3_header_compress_bsf.c @@ -0,0 +1,86 @@ +/* + * copyright (c) 2006 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "mpegaudio.h" + + +static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, + uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size, int keyframe){ + uint32_t header, extraheader; + int mode_extension, header_size; + + if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ + av_log(avctx, AV_LOG_ERROR, "not standards compliant\n"); + return -1; + } + + header = AV_RB32(buf); + mode_extension= (header>>4)&3; + + if(ff_mpa_check_header(header) < 0 || (header&0x60000) != 0x20000){ +output_unchanged: + *poutbuf= (uint8_t *) buf; + *poutbuf_size= buf_size; + + av_log(avctx, AV_LOG_INFO, "cannot compress %08X\n", header); + return 0; + } + + if(avctx->extradata_size == 0){ + avctx->extradata_size=15; + avctx->extradata= av_malloc(avctx->extradata_size); + strcpy(avctx->extradata, "FFCMP3 0.0"); + memcpy(avctx->extradata+11, buf, 4); + } + if(avctx->extradata_size != 15){ + av_log(avctx, AV_LOG_ERROR, "Extradata invalid\n"); + return -1; + } + extraheader = AV_RB32(avctx->extradata+11); + if((extraheader&MP3_MASK) != (header&MP3_MASK)) + goto output_unchanged; + + header_size= (header&0x10000) ? 4 : 6; + + *poutbuf_size= buf_size - header_size; + *poutbuf= av_malloc(buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(*poutbuf, buf + header_size, buf_size - header_size + FF_INPUT_BUFFER_PADDING_SIZE); + + if(avctx->channels==2){ + if((header & (3<<19)) != 3<<19){ + (*poutbuf)[1] &= 0x3F; + (*poutbuf)[1] |= mode_extension<<6; + FFSWAP(int, (*poutbuf)[1], (*poutbuf)[2]); + }else{ + (*poutbuf)[1] &= 0x8F; + (*poutbuf)[1] |= mode_extension<<4; + } + } + + return 1; +} + +AVBitStreamFilter mp3_header_compress_bsf={ + "mp3comp", + 0, + mp3_header_compress, +}; diff --git a/contrib/ffmpeg/libavcodec/mp3_header_decompress_bsf.c b/contrib/ffmpeg/libavcodec/mp3_header_decompress_bsf.c new file mode 100644 index 000000000..d897ed985 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mp3_header_decompress_bsf.c @@ -0,0 +1,96 @@ +/* + * copyright (c) 2006 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "mpegaudio.h" +#include "mpegaudiodata.h" + + +static int mp3_header_decompress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, + uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size, int keyframe){ + uint32_t header; + int sample_rate= avctx->sample_rate; + int sample_rate_index=0; + int lsf, mpeg25, bitrate_index, frame_size; + + header = AV_RB32(buf); + if(ff_mpa_check_header(header) >= 0){ + *poutbuf= (uint8_t *) buf; + *poutbuf_size= buf_size; + + return 0; + } + + if(avctx->extradata_size != 15 || strcmp(avctx->extradata, "FFCMP3 0.0")){ + av_log(avctx, AV_LOG_ERROR, "Extradata invalid %d\n", avctx->extradata_size); + return -1; + } + + header= AV_RB32(avctx->extradata+11) & MP3_MASK; + + lsf = sample_rate < (24000+32000)/2; + mpeg25 = sample_rate < (12000+16000)/2; + sample_rate_index= (header>>10)&3; + sample_rate= ff_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); //in case sample rate is a little off + + for(bitrate_index=2; bitrate_index<30; bitrate_index++){ + frame_size = ff_mpa_bitrate_tab[lsf][2][bitrate_index>>1]; + frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1); + if(frame_size == buf_size + 4) + break; + if(frame_size == buf_size + 6) + break; + } + if(bitrate_index == 30){ + av_log(avctx, AV_LOG_ERROR, "Could not find bitrate_index.\n"); + return -1; + } + + header |= (bitrate_index&1)<<9; + header |= (bitrate_index>>1)<<12; + header |= (frame_size == buf_size + 4)<<16; //FIXME actually set a correct crc instead of 0 + + *poutbuf_size= frame_size; + *poutbuf= av_malloc(frame_size + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(*poutbuf + frame_size - buf_size, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); + + if(avctx->channels==2){ + uint8_t *p= *poutbuf + frame_size - buf_size; + if(lsf){ + FFSWAP(int, p[1], p[2]); + header |= (p[1] & 0xC0)>>2; + p[1] &= 0x3F; + }else{ + header |= p[1] & 0x30; + p[1] &= 0xCF; + } + } + + AV_WB32(*poutbuf, header); + + return 1; +} + +AVBitStreamFilter mp3_header_decompress_bsf={ + "mp3decomp", + 0, + mp3_header_decompress, +}; diff --git a/contrib/ffmpeg/libavcodec/mp3lameaudio.c b/contrib/ffmpeg/libavcodec/mp3lameaudio.c deleted file mode 100644 index d13350265..000000000 --- a/contrib/ffmpeg/libavcodec/mp3lameaudio.c +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Interface to libmp3lame for mp3 encoding - * Copyright (c) 2002 Lennert Buytenhek - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file mp3lameaudio.c - * Interface to libmp3lame for mp3 encoding. - */ - -#include "avcodec.h" -#include "mpegaudio.h" -#include - -#define BUFFER_SIZE (2*MPA_FRAME_SIZE) -typedef struct Mp3AudioContext { - lame_global_flags *gfp; - int stereo; - uint8_t buffer[BUFFER_SIZE]; - int buffer_index; -} Mp3AudioContext; - -static int MP3lame_encode_init(AVCodecContext *avctx) -{ - Mp3AudioContext *s = avctx->priv_data; - - if (avctx->channels > 2) - return -1; - - s->stereo = avctx->channels > 1 ? 1 : 0; - - if ((s->gfp = lame_init()) == NULL) - goto err; - lame_set_in_samplerate(s->gfp, avctx->sample_rate); - lame_set_out_samplerate(s->gfp, avctx->sample_rate); - lame_set_num_channels(s->gfp, avctx->channels); - /* lame 3.91 dies on quality != 5 */ - lame_set_quality(s->gfp, 5); - /* lame 3.91 doesn't work in mono */ - lame_set_mode(s->gfp, JOINT_STEREO); - lame_set_brate(s->gfp, avctx->bit_rate/1000); - if(avctx->flags & CODEC_FLAG_QSCALE) { - lame_set_brate(s->gfp, 0); - lame_set_VBR(s->gfp, vbr_default); - lame_set_VBR_q(s->gfp, avctx->global_quality / (float)FF_QP2LAMBDA); - } - lame_set_bWriteVbrTag(s->gfp,0); - if (lame_init_params(s->gfp) < 0) - goto err_close; - - avctx->frame_size = lame_get_framesize(s->gfp); - - avctx->coded_frame= avcodec_alloc_frame(); - avctx->coded_frame->key_frame= 1; - - return 0; - -err_close: - lame_close(s->gfp); -err: - return -1; -} - -static const int sSampleRates[3] = { - 44100, 48000, 32000 -}; - -static const int sBitRates[2][3][15] = { - { { 0, 32, 64, 96,128,160,192,224,256,288,320,352,384,416,448}, - { 0, 32, 48, 56, 64, 80, 96,112,128,160,192,224,256,320,384}, - { 0, 32, 40, 48, 56, 64, 80, 96,112,128,160,192,224,256,320} - }, - { { 0, 32, 48, 56, 64, 80, 96,112,128,144,160,176,192,224,256}, - { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160}, - { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160} - }, -}; - -static const int sSamplesPerFrame[2][3] = -{ - { 384, 1152, 1152 }, - { 384, 1152, 576 } -}; - -static const int sBitsPerSlot[3] = { - 32, - 8, - 8 -}; - -static int mp3len(void *data, int *samplesPerFrame, int *sampleRate) -{ - uint8_t *dataTmp = (uint8_t *)data; - uint32_t header = ( (uint32_t)dataTmp[0] << 24 ) | ( (uint32_t)dataTmp[1] << 16 ) | ( (uint32_t)dataTmp[2] << 8 ) | (uint32_t)dataTmp[3]; - int layerID = 3 - ((header >> 17) & 0x03); - int bitRateID = ((header >> 12) & 0x0f); - int sampleRateID = ((header >> 10) & 0x03); - int bitsPerSlot = sBitsPerSlot[layerID]; - int isPadded = ((header >> 9) & 0x01); - static int const mode_tab[4]= {2,3,1,0}; - int mode= mode_tab[(header >> 19) & 0x03]; - int mpeg_id= mode>0; - int temp0, temp1, bitRate; - - if ( (( header >> 21 ) & 0x7ff) != 0x7ff || mode == 3 || layerID==3 || sampleRateID==3) { - return -1; - } - - if(!samplesPerFrame) samplesPerFrame= &temp0; - if(!sampleRate ) sampleRate = &temp1; - -// *isMono = ((header >> 6) & 0x03) == 0x03; - - *sampleRate = sSampleRates[sampleRateID]>>mode; - bitRate = sBitRates[mpeg_id][layerID][bitRateID] * 1000; - *samplesPerFrame = sSamplesPerFrame[mpeg_id][layerID]; -//av_log(NULL, AV_LOG_DEBUG, "sr:%d br:%d spf:%d l:%d m:%d\n", *sampleRate, bitRate, *samplesPerFrame, layerID, mode); - - return *samplesPerFrame * bitRate / (bitsPerSlot * *sampleRate) + isPadded; -} - -static int MP3lame_encode_frame(AVCodecContext *avctx, - unsigned char *frame, int buf_size, void *data) -{ - Mp3AudioContext *s = avctx->priv_data; - int len; - int lame_result; - - /* lame 3.91 dies on '1-channel interleaved' data */ - - if(data){ - if (s->stereo) { - lame_result = lame_encode_buffer_interleaved( - s->gfp, - data, - avctx->frame_size, - s->buffer + s->buffer_index, - BUFFER_SIZE - s->buffer_index - ); - } else { - lame_result = lame_encode_buffer( - s->gfp, - data, - data, - avctx->frame_size, - s->buffer + s->buffer_index, - BUFFER_SIZE - s->buffer_index - ); - } - }else{ - lame_result= lame_encode_flush( - s->gfp, - s->buffer + s->buffer_index, - BUFFER_SIZE - s->buffer_index - ); - } - - if(lame_result==-1) { - /* output buffer too small */ - av_log(avctx, AV_LOG_ERROR, "lame: output buffer too small (buffer index: %d, free bytes: %d)\n", s->buffer_index, BUFFER_SIZE - s->buffer_index); - return 0; - } - - s->buffer_index += lame_result; - - if(s->buffer_index<4) - return 0; - - len= mp3len(s->buffer, NULL, NULL); -//av_log(avctx, AV_LOG_DEBUG, "in:%d packet-len:%d index:%d\n", avctx->frame_size, len, s->buffer_index); - if(len <= s->buffer_index){ - memcpy(frame, s->buffer, len); - s->buffer_index -= len; - - memmove(s->buffer, s->buffer+len, s->buffer_index); - //FIXME fix the audio codec API, so we dont need the memcpy() -/*for(i=0; ipriv_data; - - av_freep(&avctx->coded_frame); - - lame_close(s->gfp); - return 0; -} - - -AVCodec mp3lame_encoder = { - "mp3", - CODEC_TYPE_AUDIO, - CODEC_ID_MP3, - sizeof(Mp3AudioContext), - MP3lame_encode_init, - MP3lame_encode_frame, - MP3lame_encode_close, - .capabilities= CODEC_CAP_DELAY, -}; diff --git a/contrib/ffmpeg/libavcodec/mpc.c b/contrib/ffmpeg/libavcodec/mpc.c index f351c549f..96e1a20b0 100644 --- a/contrib/ffmpeg/libavcodec/mpc.c +++ b/contrib/ffmpeg/libavcodec/mpc.c @@ -1,5 +1,5 @@ /* - * Musepack decoder + * Musepack decoder core * Copyright (c) 2006 Konstantin Shishkov * * This file is part of FFmpeg. @@ -17,11 +17,10 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** - * @file mpc.c Musepack decoder + * @file mpc.c Musepack decoder core * MPEG Audio Layer 1/2 -like codec with frames of 1152 samples * divided into 32 subbands. */ @@ -36,109 +35,18 @@ #endif #include "mpegaudio.h" +#include "mpc.h" #include "mpcdata.h" -#define BANDS 32 -#define SAMPLES_PER_BAND 36 -#define MPC_FRAME_SIZE (BANDS * SAMPLES_PER_BAND) - -static VLC scfi_vlc, dscf_vlc, hdr_vlc, quant_vlc[MPC7_QUANT_VLC_TABLES][2]; - static DECLARE_ALIGNED_16(MPA_INT, mpa_window[512]); -typedef struct { - DSPContext dsp; - int IS, MSS, gapless; - int lastframelen, bands; - int oldDSCF[2][BANDS]; - AVRandomState rnd; - int frames_to_skip; - /* for synthesis */ - DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512*2]); - int synth_buf_offset[MPA_MAX_CHANNELS]; - DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]); -} MPCContext; - -/** Subband structure - hold all variables for each subband */ -typedef struct { - int msf; ///< mid-stereo flag - int res[2]; - int scfi[2]; - int scf_idx[2][3]; - int Q[2]; -}Band; - -static int mpc7_decode_init(AVCodecContext * avctx) +void ff_mpc_init() { - int i, j; - MPCContext *c = avctx->priv_data; - GetBitContext gb; - uint8_t buf[16]; - float f1=1.20050805774840750476 * 256; - static int vlc_inited = 0; - - if(avctx->extradata_size < 16){ - av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\n", avctx->extradata_size); - return -1; - } - memset(c->oldDSCF, 0, sizeof(c->oldDSCF)); - av_init_random(0xDEADBEEF, &c->rnd); - dsputil_init(&c->dsp, avctx); - c->dsp.bswap_buf(buf, avctx->extradata, 4); ff_mpa_synth_init(mpa_window); - init_get_bits(&gb, buf, 128); - - c->IS = get_bits1(&gb); - c->MSS = get_bits1(&gb); - c->bands = get_bits(&gb, 6); - if(c->bands >= BANDS){ - av_log(avctx, AV_LOG_ERROR, "Too many bands: %i\n", c->bands); - return -1; - } - skip_bits(&gb, 88); - c->gapless = get_bits1(&gb); - c->lastframelen = get_bits(&gb, 11); - av_log(avctx, AV_LOG_DEBUG, "IS: %d, MSS: %d, TG: %d, LFL: %d, bands: %d\n", - c->IS, c->MSS, c->gapless, c->lastframelen, c->bands); - c->frames_to_skip = 0; - - if(vlc_inited) return 0; - av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n"); - if(init_vlc(&scfi_vlc, MPC7_SCFI_BITS, MPC7_SCFI_SIZE, - &mpc7_scfi[1], 2, 1, - &mpc7_scfi[0], 2, 1, INIT_VLC_USE_STATIC)){ - av_log(avctx, AV_LOG_ERROR, "Cannot init SCFI VLC\n"); - return -1; - } - if(init_vlc(&dscf_vlc, MPC7_DSCF_BITS, MPC7_DSCF_SIZE, - &mpc7_dscf[1], 2, 1, - &mpc7_dscf[0], 2, 1, INIT_VLC_USE_STATIC)){ - av_log(avctx, AV_LOG_ERROR, "Cannot init DSCF VLC\n"); - return -1; - } - if(init_vlc(&hdr_vlc, MPC7_HDR_BITS, MPC7_HDR_SIZE, - &mpc7_hdr[1], 2, 1, - &mpc7_hdr[0], 2, 1, INIT_VLC_USE_STATIC)){ - av_log(avctx, AV_LOG_ERROR, "Cannot init HDR VLC\n"); - return -1; - } - for(i = 0; i < MPC7_QUANT_VLC_TABLES; i++){ - for(j = 0; j < 2; j++){ - if(init_vlc(&quant_vlc[i][j], 9, mpc7_quant_vlc_sizes[i], - &mpc7_quant_vlc[i][j][1], 4, 2, - &mpc7_quant_vlc[i][j][0], 4, 2, INIT_VLC_USE_STATIC)){ - av_log(avctx, AV_LOG_ERROR, "Cannot init QUANT VLC %i,%i\n",i,j); - return -1; - } - } - } - vlc_inited = 1; - return 0; } /** * Process decoded Musepack data and produce PCM - * @todo make it available for MPC8 and MPC6 */ static void mpc_synth(MPCContext *c, int16_t *out) { @@ -160,147 +68,29 @@ static void mpc_synth(MPCContext *c, int16_t *out) *out++=samples[i]; } -/** - * Fill samples for given subband - */ -static void inline idx_to_quant(MPCContext *c, GetBitContext *gb, int idx, int *dst) -{ - int i, i1, t; - switch(idx){ - case -1: - for(i = 0; i < SAMPLES_PER_BAND; i++){ - *dst++ = (av_random(&c->rnd) & 0x3FC) - 510; - } - break; - case 1: - i1 = get_bits1(gb); - for(i = 0; i < SAMPLES_PER_BAND/3; i++){ - t = get_vlc2(gb, quant_vlc[0][i1].table, 9, 2); - *dst++ = mpc_idx30[t]; - *dst++ = mpc_idx31[t]; - *dst++ = mpc_idx32[t]; - } - break; - case 2: - i1 = get_bits1(gb); - for(i = 0; i < SAMPLES_PER_BAND/2; i++){ - t = get_vlc2(gb, quant_vlc[1][i1].table, 9, 2); - *dst++ = mpc_idx50[t]; - *dst++ = mpc_idx51[t]; - } - break; - case 3: case 4: case 5: case 6: case 7: - i1 = get_bits1(gb); - for(i = 0; i < SAMPLES_PER_BAND; i++) - *dst++ = get_vlc2(gb, quant_vlc[idx-1][i1].table, 9, 2) - mpc7_quant_vlc_off[idx-1]; - break; - case 8: case 9: case 10: case 11: case 12: - case 13: case 14: case 15: case 16: case 17: - t = (1 << (idx - 2)) - 1; - for(i = 0; i < SAMPLES_PER_BAND; i++) - *dst++ = get_bits(gb, idx - 1) - t; - break; - default: // case 0 and -2..-17 - return; - } -} - -static int mpc7_decode_frame(AVCodecContext * avctx, - void *data, int *data_size, - uint8_t * buf, int buf_size) +void ff_mpc_dequantize_and_synth(MPCContext * c, int maxband, void *data) { - MPCContext *c = avctx->priv_data; - GetBitContext gb; - uint8_t *bits; - int i, j, ch, t; - int mb = -1; - Band bands[BANDS]; - int Q[2][MPC_FRAME_SIZE]; + int i, j, ch; + Band *bands = c->bands; int off; float mul; - int bits_used, bits_avail; - memset(bands, 0, sizeof(bands)); - if(buf_size <= 4){ - av_log(avctx, AV_LOG_ERROR, "Too small buffer passed (%i bytes)\n", buf_size); - } - - bits = av_malloc(((buf_size - 1) & ~3) + FF_INPUT_BUFFER_PADDING_SIZE); - c->dsp.bswap_buf(bits, buf + 4, (buf_size - 4) >> 2); - init_get_bits(&gb, bits, (buf_size - 4)* 8); - skip_bits(&gb, buf[0]); - - /* read subband indexes */ - for(i = 0; i <= c->bands; i++){ - for(ch = 0; ch < 2; ch++){ - if(i) t = get_vlc2(&gb, hdr_vlc.table, MPC7_HDR_BITS, 1) - 5; - if(!i || (t == 4)) bands[i].res[ch] = get_bits(&gb, 4); - else bands[i].res[ch] = bands[i-1].res[ch] + t; - } - - if(bands[i].res[0] || bands[i].res[1]){ - mb = i; - if(c->MSS) bands[i].msf = get_bits1(&gb); - } - } - /* get scale indexes coding method */ - for(i = 0; i <= mb; i++) - for(ch = 0; ch < 2; ch++) - if(bands[i].res[ch]) bands[i].scfi[ch] = get_vlc2(&gb, scfi_vlc.table, MPC7_SCFI_BITS, 1); - /* get scale indexes */ - for(i = 0; i <= mb; i++){ - for(ch = 0; ch < 2; ch++){ - if(bands[i].res[ch]){ - bands[i].scf_idx[ch][2] = c->oldDSCF[ch][i]; - t = get_vlc2(&gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; - bands[i].scf_idx[ch][0] = (t == 8) ? get_bits(&gb, 6) : (bands[i].scf_idx[ch][2] + t); - switch(bands[i].scfi[ch]){ - case 0: - t = get_vlc2(&gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; - bands[i].scf_idx[ch][1] = (t == 8) ? get_bits(&gb, 6) : (bands[i].scf_idx[ch][0] + t); - t = get_vlc2(&gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; - bands[i].scf_idx[ch][2] = (t == 8) ? get_bits(&gb, 6) : (bands[i].scf_idx[ch][1] + t); - break; - case 1: - t = get_vlc2(&gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; - bands[i].scf_idx[ch][1] = (t == 8) ? get_bits(&gb, 6) : (bands[i].scf_idx[ch][0] + t); - bands[i].scf_idx[ch][2] = bands[i].scf_idx[ch][1]; - break; - case 2: - bands[i].scf_idx[ch][1] = bands[i].scf_idx[ch][0]; - t = get_vlc2(&gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; - bands[i].scf_idx[ch][2] = (t == 8) ? get_bits(&gb, 6) : (bands[i].scf_idx[ch][1] + t); - break; - case 3: - bands[i].scf_idx[ch][2] = bands[i].scf_idx[ch][1] = bands[i].scf_idx[ch][0]; - break; - } - c->oldDSCF[ch][i] = bands[i].scf_idx[ch][2]; - } - } - } - /* get quantizers */ - memset(Q, 0, sizeof(Q)); - off = 0; - for(i = 0; i < BANDS; i++, off += SAMPLES_PER_BAND) - for(ch = 0; ch < 2; ch++) - idx_to_quant(c, &gb, bands[i].res[ch], Q[ch] + off); /* dequantize */ memset(c->sb_samples, 0, sizeof(c->sb_samples)); off = 0; - for(i = 0; i <= mb; i++, off += SAMPLES_PER_BAND){ + for(i = 0; i <= maxband; i++, off += SAMPLES_PER_BAND){ for(ch = 0; ch < 2; ch++){ if(bands[i].res[ch]){ j = 0; - mul = mpc_CC[bands[i].res[ch]] * mpc7_SCF[bands[i].scf_idx[ch][0]]; + mul = mpc_CC[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][0]]; for(; j < 12; j++) - c->sb_samples[ch][j][i] = mul * Q[ch][j + off]; - mul = mpc_CC[bands[i].res[ch]] * mpc7_SCF[bands[i].scf_idx[ch][1]]; + c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off]; + mul = mpc_CC[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][1]]; for(; j < 24; j++) - c->sb_samples[ch][j][i] = mul * Q[ch][j + off]; - mul = mpc_CC[bands[i].res[ch]] * mpc7_SCF[bands[i].scf_idx[ch][2]]; + c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off]; + mul = mpc_CC[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][2]]; for(; j < 36; j++) - c->sb_samples[ch][j][i] = mul * Q[ch][j + off]; + c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off]; } } if(bands[i].msf){ @@ -315,41 +105,4 @@ static int mpc7_decode_frame(AVCodecContext * avctx, } mpc_synth(c, data); - - av_free(bits); - - bits_used = get_bits_count(&gb); - bits_avail = (buf_size - 4) * 8; - if(!buf[1] && ((bits_avail < bits_used) || (bits_used + 32 <= bits_avail))){ - av_log(NULL,0, "Error decoding frame: used %i of %i bits\n", bits_used, bits_avail); - return -1; - } - if(c->frames_to_skip){ - c->frames_to_skip--; - *data_size = 0; - return buf_size; - } - *data_size = (buf[1] ? c->lastframelen : MPC_FRAME_SIZE) * 4; - - return buf_size; -} - -static void mpc7_decode_flush(AVCodecContext *avctx) -{ - MPCContext *c = avctx->priv_data; - - memset(c->oldDSCF, 0, sizeof(c->oldDSCF)); - c->frames_to_skip = 32; } - -AVCodec mpc7_decoder = { - "mpc sv7", - CODEC_TYPE_AUDIO, - CODEC_ID_MUSEPACK7, - sizeof(MPCContext), - mpc7_decode_init, - NULL, - NULL, - mpc7_decode_frame, - .flush = mpc7_decode_flush, -}; diff --git a/contrib/ffmpeg/libavcodec/mpc.h b/contrib/ffmpeg/libavcodec/mpc.h new file mode 100644 index 000000000..ce438e3af --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpc.h @@ -0,0 +1,80 @@ +/* + * Musepack decoder + * Copyright (c) 2006 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mpc.h Musepack decoder + * MPEG Audio Layer 1/2 -like codec with frames of 1152 samples + * divided into 32 subbands. + */ + +#ifndef FFMPEG_MPC_H +#define FFMPEG_MPC_H + +#include "avcodec.h" +#include "bitstream.h" +#include "dsputil.h" +#include "random.h" + +#ifdef CONFIG_MPEGAUDIO_HP +#define USE_HIGHPRECISION +#endif +#include "mpegaudio.h" + +#include "mpcdata.h" + +#define BANDS 32 +#define SAMPLES_PER_BAND 36 +#define MPC_FRAME_SIZE (BANDS * SAMPLES_PER_BAND) + +/** Subband structure - hold all variables for each subband */ +typedef struct { + int msf; ///< mid-stereo flag + int res[2]; + int scfi[2]; + int scf_idx[2][3]; + int Q[2]; +}Band; + +typedef struct { + DSPContext dsp; + GetBitContext gb; + int IS, MSS, gapless; + int lastframelen; + int maxbands, last_max_band; + int last_bits_used; + int oldDSCF[2][BANDS]; + Band bands[BANDS]; + int Q[2][MPC_FRAME_SIZE]; + int cur_frame, frames; + uint8_t *bits; + int buf_size; + AVRandomState rnd; + int frames_to_skip; + /* for synthesis */ + DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512*2]); + int synth_buf_offset[MPA_MAX_CHANNELS]; + DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]); +} MPCContext; + +extern void ff_mpc_init(); +extern void ff_mpc_dequantize_and_synth(MPCContext *c, int maxband, void *dst); + +#endif /* FFMPEG_MPC_H */ diff --git a/contrib/ffmpeg/libavcodec/mpc7.c b/contrib/ffmpeg/libavcodec/mpc7.c new file mode 100644 index 000000000..37bdb5f39 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpc7.c @@ -0,0 +1,276 @@ +/* + * Musepack SV7 decoder + * Copyright (c) 2006 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mpc7.c Musepack SV7 decoder + * MPEG Audio Layer 1/2 -like codec with frames of 1152 samples + * divided into 32 subbands. + */ + +#include "avcodec.h" +#include "bitstream.h" +#include "dsputil.h" +#include "random.h" + +#ifdef CONFIG_MPEGAUDIO_HP +#define USE_HIGHPRECISION +#endif +#include "mpegaudio.h" + +#include "mpc.h" +#include "mpc7data.h" + +#define BANDS 32 +#define SAMPLES_PER_BAND 36 +#define MPC_FRAME_SIZE (BANDS * SAMPLES_PER_BAND) + +static VLC scfi_vlc, dscf_vlc, hdr_vlc, quant_vlc[MPC7_QUANT_VLC_TABLES][2]; + +static int mpc7_decode_init(AVCodecContext * avctx) +{ + int i, j; + MPCContext *c = avctx->priv_data; + GetBitContext gb; + uint8_t buf[16]; + static int vlc_initialized = 0; + + if(avctx->extradata_size < 16){ + av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\n", avctx->extradata_size); + return -1; + } + memset(c->oldDSCF, 0, sizeof(c->oldDSCF)); + av_init_random(0xDEADBEEF, &c->rnd); + dsputil_init(&c->dsp, avctx); + c->dsp.bswap_buf((uint32_t*)buf, (const uint32_t*)avctx->extradata, 4); + ff_mpc_init(); + init_get_bits(&gb, buf, 128); + + c->IS = get_bits1(&gb); + c->MSS = get_bits1(&gb); + c->maxbands = get_bits(&gb, 6); + if(c->maxbands >= BANDS){ + av_log(avctx, AV_LOG_ERROR, "Too many bands: %i\n", c->maxbands); + return -1; + } + skip_bits(&gb, 88); + c->gapless = get_bits1(&gb); + c->lastframelen = get_bits(&gb, 11); + av_log(avctx, AV_LOG_DEBUG, "IS: %d, MSS: %d, TG: %d, LFL: %d, bands: %d\n", + c->IS, c->MSS, c->gapless, c->lastframelen, c->maxbands); + c->frames_to_skip = 0; + + if(vlc_initialized) return 0; + av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n"); + if(init_vlc(&scfi_vlc, MPC7_SCFI_BITS, MPC7_SCFI_SIZE, + &mpc7_scfi[1], 2, 1, + &mpc7_scfi[0], 2, 1, INIT_VLC_USE_STATIC)){ + av_log(avctx, AV_LOG_ERROR, "Cannot init SCFI VLC\n"); + return -1; + } + if(init_vlc(&dscf_vlc, MPC7_DSCF_BITS, MPC7_DSCF_SIZE, + &mpc7_dscf[1], 2, 1, + &mpc7_dscf[0], 2, 1, INIT_VLC_USE_STATIC)){ + av_log(avctx, AV_LOG_ERROR, "Cannot init DSCF VLC\n"); + return -1; + } + if(init_vlc(&hdr_vlc, MPC7_HDR_BITS, MPC7_HDR_SIZE, + &mpc7_hdr[1], 2, 1, + &mpc7_hdr[0], 2, 1, INIT_VLC_USE_STATIC)){ + av_log(avctx, AV_LOG_ERROR, "Cannot init HDR VLC\n"); + return -1; + } + for(i = 0; i < MPC7_QUANT_VLC_TABLES; i++){ + for(j = 0; j < 2; j++){ + if(init_vlc(&quant_vlc[i][j], 9, mpc7_quant_vlc_sizes[i], + &mpc7_quant_vlc[i][j][1], 4, 2, + &mpc7_quant_vlc[i][j][0], 4, 2, INIT_VLC_USE_STATIC)){ + av_log(avctx, AV_LOG_ERROR, "Cannot init QUANT VLC %i,%i\n",i,j); + return -1; + } + } + } + vlc_initialized = 1; + return 0; +} + +/** + * Fill samples for given subband + */ +static inline void idx_to_quant(MPCContext *c, GetBitContext *gb, int idx, int *dst) +{ + int i, i1, t; + switch(idx){ + case -1: + for(i = 0; i < SAMPLES_PER_BAND; i++){ + *dst++ = (av_random(&c->rnd) & 0x3FC) - 510; + } + break; + case 1: + i1 = get_bits1(gb); + for(i = 0; i < SAMPLES_PER_BAND/3; i++){ + t = get_vlc2(gb, quant_vlc[0][i1].table, 9, 2); + *dst++ = mpc7_idx30[t]; + *dst++ = mpc7_idx31[t]; + *dst++ = mpc7_idx32[t]; + } + break; + case 2: + i1 = get_bits1(gb); + for(i = 0; i < SAMPLES_PER_BAND/2; i++){ + t = get_vlc2(gb, quant_vlc[1][i1].table, 9, 2); + *dst++ = mpc7_idx50[t]; + *dst++ = mpc7_idx51[t]; + } + break; + case 3: case 4: case 5: case 6: case 7: + i1 = get_bits1(gb); + for(i = 0; i < SAMPLES_PER_BAND; i++) + *dst++ = get_vlc2(gb, quant_vlc[idx-1][i1].table, 9, 2) - mpc7_quant_vlc_off[idx-1]; + break; + case 8: case 9: case 10: case 11: case 12: + case 13: case 14: case 15: case 16: case 17: + t = (1 << (idx - 2)) - 1; + for(i = 0; i < SAMPLES_PER_BAND; i++) + *dst++ = get_bits(gb, idx - 1) - t; + break; + default: // case 0 and -2..-17 + return; + } +} + +static int mpc7_decode_frame(AVCodecContext * avctx, + void *data, int *data_size, + const uint8_t * buf, int buf_size) +{ + MPCContext *c = avctx->priv_data; + GetBitContext gb; + uint8_t *bits; + int i, ch, t; + int mb = -1; + Band *bands = c->bands; + int off; + int bits_used, bits_avail; + + memset(bands, 0, sizeof(bands)); + if(buf_size <= 4){ + av_log(avctx, AV_LOG_ERROR, "Too small buffer passed (%i bytes)\n", buf_size); + } + + bits = av_malloc(((buf_size - 1) & ~3) + FF_INPUT_BUFFER_PADDING_SIZE); + c->dsp.bswap_buf((uint32_t*)bits, (const uint32_t*)(buf + 4), (buf_size - 4) >> 2); + init_get_bits(&gb, bits, (buf_size - 4)* 8); + skip_bits(&gb, buf[0]); + + /* read subband indexes */ + for(i = 0; i <= c->maxbands; i++){ + for(ch = 0; ch < 2; ch++){ + if(i) t = get_vlc2(&gb, hdr_vlc.table, MPC7_HDR_BITS, 1) - 5; + if(!i || (t == 4)) bands[i].res[ch] = get_bits(&gb, 4); + else bands[i].res[ch] = bands[i-1].res[ch] + t; + } + + if(bands[i].res[0] || bands[i].res[1]){ + mb = i; + if(c->MSS) bands[i].msf = get_bits1(&gb); + } + } + /* get scale indexes coding method */ + for(i = 0; i <= mb; i++) + for(ch = 0; ch < 2; ch++) + if(bands[i].res[ch]) bands[i].scfi[ch] = get_vlc2(&gb, scfi_vlc.table, MPC7_SCFI_BITS, 1); + /* get scale indexes */ + for(i = 0; i <= mb; i++){ + for(ch = 0; ch < 2; ch++){ + if(bands[i].res[ch]){ + bands[i].scf_idx[ch][2] = c->oldDSCF[ch][i]; + t = get_vlc2(&gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; + bands[i].scf_idx[ch][0] = (t == 8) ? get_bits(&gb, 6) : (bands[i].scf_idx[ch][2] + t); + switch(bands[i].scfi[ch]){ + case 0: + t = get_vlc2(&gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; + bands[i].scf_idx[ch][1] = (t == 8) ? get_bits(&gb, 6) : (bands[i].scf_idx[ch][0] + t); + t = get_vlc2(&gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; + bands[i].scf_idx[ch][2] = (t == 8) ? get_bits(&gb, 6) : (bands[i].scf_idx[ch][1] + t); + break; + case 1: + t = get_vlc2(&gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; + bands[i].scf_idx[ch][1] = (t == 8) ? get_bits(&gb, 6) : (bands[i].scf_idx[ch][0] + t); + bands[i].scf_idx[ch][2] = bands[i].scf_idx[ch][1]; + break; + case 2: + bands[i].scf_idx[ch][1] = bands[i].scf_idx[ch][0]; + t = get_vlc2(&gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; + bands[i].scf_idx[ch][2] = (t == 8) ? get_bits(&gb, 6) : (bands[i].scf_idx[ch][1] + t); + break; + case 3: + bands[i].scf_idx[ch][2] = bands[i].scf_idx[ch][1] = bands[i].scf_idx[ch][0]; + break; + } + c->oldDSCF[ch][i] = bands[i].scf_idx[ch][2]; + } + } + } + /* get quantizers */ + memset(c->Q, 0, sizeof(c->Q)); + off = 0; + for(i = 0; i < BANDS; i++, off += SAMPLES_PER_BAND) + for(ch = 0; ch < 2; ch++) + idx_to_quant(c, &gb, bands[i].res[ch], c->Q[ch] + off); + + ff_mpc_dequantize_and_synth(c, mb, data); + + av_free(bits); + + bits_used = get_bits_count(&gb); + bits_avail = (buf_size - 4) * 8; + if(!buf[1] && ((bits_avail < bits_used) || (bits_used + 32 <= bits_avail))){ + av_log(NULL,0, "Error decoding frame: used %i of %i bits\n", bits_used, bits_avail); + return -1; + } + if(c->frames_to_skip){ + c->frames_to_skip--; + *data_size = 0; + return buf_size; + } + *data_size = (buf[1] ? c->lastframelen : MPC_FRAME_SIZE) * 4; + + return buf_size; +} + +static void mpc7_decode_flush(AVCodecContext *avctx) +{ + MPCContext *c = avctx->priv_data; + + memset(c->oldDSCF, 0, sizeof(c->oldDSCF)); + c->frames_to_skip = 32; +} + +AVCodec mpc7_decoder = { + "mpc sv7", + CODEC_TYPE_AUDIO, + CODEC_ID_MUSEPACK7, + sizeof(MPCContext), + mpc7_decode_init, + NULL, + NULL, + mpc7_decode_frame, + .flush = mpc7_decode_flush, +}; diff --git a/contrib/ffmpeg/libavcodec/mpc7data.h b/contrib/ffmpeg/libavcodec/mpc7data.h new file mode 100644 index 000000000..b9e64702e --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpc7data.h @@ -0,0 +1,171 @@ +/* + * Musepack decoder + * Copyright (c) 2006 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_MPC7DATA_H +#define FFMPEG_MPC7DATA_H + +#include + +static const int8_t mpc7_idx30[] = { -1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1}; +static const int8_t mpc7_idx31[] = { -1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1}; +static const int8_t mpc7_idx32[] = { -1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}; +static const int8_t mpc7_idx50[] = { -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2}; +static const int8_t mpc7_idx51[] = { -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2}; + +#define MPC7_SCFI_SIZE 4 +#define MPC7_SCFI_BITS 3 +static const uint8_t mpc7_scfi[MPC7_SCFI_SIZE * 2] = { + 0x2, 3, 0x1, 1, 0x3, 3, 0x0, 2 +}; + +#define MPC7_DSCF_SIZE 16 +#define MPC7_DSCF_BITS 6 +static const uint8_t mpc7_dscf[MPC7_DSCF_SIZE * 2] = { + 0x20, 6, 0x04, 5, 0x11, 5, 0x1E, 5, 0x0D, 4, 0x00, 3, 0x03, 3, 0x09, 4, + 0x05, 3, 0x02, 3, 0x0E, 4, 0x03, 4, 0x1F, 5, 0x05, 5, 0x21, 6, 0x0C, 4 +}; + +#define MPC7_HDR_SIZE 10 +#define MPC7_HDR_BITS 9 +static const uint8_t mpc7_hdr[MPC7_HDR_SIZE * 2] = { + 0x5C, 8, 0x2F, 7, 0x0A, 5, 0x04, 4, 0x00, 2, + 0x01, 1, 0x03, 3, 0x16, 6, 0xBB, 9, 0xBA, 9 +}; + +#define MPC7_QUANT_VLC_TABLES 7 +static const uint8_t mpc7_quant_vlc_sizes[MPC7_QUANT_VLC_TABLES * 2] = { + 27, 25, 7, 9, 15, 31, 63 +}; + +static const uint8_t mpc7_quant_vlc_off[MPC7_QUANT_VLC_TABLES] = { + 0, 0, 3, 4, 7, 15, 31 +}; + +static const uint16_t mpc7_quant_vlc[MPC7_QUANT_VLC_TABLES][2][64 * 2] = { +{ + { + 0x0036, 6, 0x0009, 5, 0x0020, 6, 0x0005, 5, 0x000A, 4, 0x0007, 5, + 0x0034, 6, 0x0000, 5, 0x0023, 6, 0x000A, 5, 0x0006, 4, 0x0004, 5, + 0x000B, 4, 0x0007, 3, 0x000C, 4, 0x0003, 5, 0x0007, 4, 0x000B, 5, + 0x0022, 6, 0x0001, 5, 0x0035, 6, 0x0006, 5, 0x0009, 4, 0x0002, 5, + 0x0021, 6, 0x0008, 5, 0x0037, 6 + }, + { + 0x0067, 8, 0x003E, 7, 0x00E1, 9, 0x0037, 7, 0x0003, 4, 0x0034, 7, + 0x0065, 8, 0x003C, 7, 0x00E3, 9, 0x0018, 6, 0x0000, 4, 0x003D, 7, + 0x0004, 4, 0x0001, 1, 0x0005, 4, 0x003F, 7, 0x0001, 4, 0x003B, 7, + 0x00E2, 9, 0x0039, 7, 0x0064, 8, 0x0035, 7, 0x0002, 4, 0x0036, 7, + 0x00E0, 9, 0x003A, 7, 0x0066, 8 + } +}, +{ + { + 0x0059, 7, 0x002F, 6, 0x000F, 5, 0x0000, 5, 0x005B, 7, 0x0004, 5, + 0x0006, 4, 0x000D, 4, 0x0004, 4, 0x0005, 5, 0x0014, 5, 0x000C, 4, + 0x0004, 3, 0x000F, 4, 0x000E, 5, 0x0003, 5, 0x0003, 4, 0x000E, 4, + 0x0005, 4, 0x0001, 5, 0x005A, 7, 0x0002, 5, 0x0015, 5, 0x002E, 6, + 0x0058, 7 + }, + { + 0x0399, 10, 0x0071, 7, 0x0033, 6, 0x00E7, 8, 0x039A, 10, 0x0068, 7, + 0x001E, 5, 0x0000, 3, 0x001D, 5, 0x0069, 7, 0x0032, 6, 0x0001, 3, + 0x0002, 2, 0x0003, 3, 0x0031, 6, 0x006B, 7, 0x001B, 5, 0x0002, 3, + 0x001F, 5, 0x0070, 7, 0x0398, 10, 0x006A, 7, 0x0030, 6, 0x0072, 7, + 0x039B, 10 + } +}, +{ + { + 0x000C, 4, 0x0004, 3, 0x0000, 2, 0x0001, 2, 0x0007, 3, 0x0005, 3, 0x000D, 4 + }, + { + 0x0004, 5, 0x0003, 4, 0x0002, 2, 0x0003, 2, 0x0001, 2, 0x0000, 3, 0x0005, 5 + } +}, +{ + { + 0x0005, 4, 0x0000, 3, 0x0004, 3, 0x0006, 3, 0x0007, 3, 0x0005, 3, 0x0003, 3, 0x0001, 3, 0x0004, 4 + }, + { + 0x0009, 5, 0x000C, 4, 0x0003, 3, 0x0000, 2, 0x0002, 2, 0x0007, 3, 0x000D, 4, 0x0005, 4, 0x0008, 5 + } +}, +{ + { + 0x0039, 6, 0x0017, 5, 0x0008, 4, 0x000A, 4, 0x000D, 4, 0x0000, 3, + 0x0002, 3, 0x0003, 3, 0x0001, 3, 0x000F, 4, 0x000C, 4, 0x0009, 4, + 0x001D, 5, 0x0016, 5, 0x0038, 6, + }, + { + 0x00E5, 8, 0x0038, 6, 0x0007, 5, 0x0002, 4, 0x0000, 3, 0x0003, 3, + 0x0005, 3, 0x0006, 3, 0x0004, 3, 0x0002, 3, 0x000F, 4, 0x001D, 5, + 0x0006, 5, 0x0073, 7, 0x00E4, 8, + }, +}, +{ + { + 0x0041, 7, 0x0006, 6, 0x002C, 6, 0x002D, 6, 0x003B, 6, 0x000D, 5, + 0x0011, 5, 0x0013, 5, 0x0017, 5, 0x0015, 5, 0x001A, 5, 0x001E, 5, + 0x0000, 4, 0x0002, 4, 0x0005, 4, 0x0007, 4, 0x0003, 4, 0x0004, 4, + 0x001F, 5, 0x001C, 5, 0x0019, 5, 0x001B, 5, 0x0018, 5, 0x0014, 5, + 0x0012, 5, 0x000C, 5, 0x0002, 5, 0x003A, 6, 0x0021, 6, 0x0007, 6, + 0x0040, 7 + }, + { + 0x1948, 13, 0x194A, 13, 0x0328, 10, 0x0195, 9, 0x00CB, 8, 0x0066, 7, + 0x0031, 6, 0x0009, 5, 0x000F, 5, 0x001F, 5, 0x0002, 4, 0x0006, 4, + 0x0008, 4, 0x000B, 4, 0x000D, 4, 0x0000, 3, 0x000E, 4, 0x000A, 4, + 0x0009, 4, 0x0005, 4, 0x0003, 4, 0x001E, 5, 0x000E, 5, 0x0008, 5, + 0x0030, 6, 0x0067, 7, 0x00C9, 8, 0x00C8, 8, 0x0653, 11, 0x1949, 13, + 0x194B, 13 + } +}, +{ + { + 0x0067, 8, 0x0099, 8, 0x00B5, 8, 0x00E9, 8, 0x0040, 7, 0x0041, 7, + 0x004D, 7, 0x0051, 7, 0x005B, 7, 0x0071, 7, 0x0070, 7, 0x0018, 6, + 0x001D, 6, 0x0023, 6, 0x0025, 6, 0x0029, 6, 0x002C, 6, 0x002E, 6, + 0x0033, 6, 0x0031, 6, 0x0036, 6, 0x0037, 6, 0x0039, 6, 0x003C, 6, + 0x0000, 5, 0x0002, 5, 0x000A, 5, 0x0005, 5, 0x0009, 5, 0x0006, 5, + 0x000D, 5, 0x0007, 5, 0x000B, 5, 0x000F, 5, 0x0008, 5, 0x0004, 5, + 0x0003, 5, 0x0001, 5, 0x003F, 6, 0x003E, 6, 0x003D, 6, 0x0035, 6, + 0x003B, 6, 0x0034, 6, 0x0030, 6, 0x002F, 6, 0x002B, 6, 0x002A, 6, + 0x0027, 6, 0x0024, 6, 0x0021, 6, 0x001C, 6, 0x0075, 7, 0x0065, 7, + 0x0064, 7, 0x0050, 7, 0x0045, 7, 0x0044, 7, 0x0032, 7, 0x00E8, 8, + 0x00B4, 8, 0x0098, 8, 0x0066, 8 + }, + { + 0x37A4, 14, 0x37AD, 14, 0x37A6, 14, 0x37AE, 14, 0x0DEA, 12, 0x02F0, 10, + 0x02F1, 10, 0x00A0, 9, 0x00A2, 9, 0x01BC, 9, 0x007A, 8, 0x00DF, 8, + 0x003C, 7, 0x0049, 7, 0x006E, 7, 0x000E, 6, 0x0018, 6, 0x0019, 6, + 0x0022, 6, 0x0025, 6, 0x0036, 6, 0x0003, 5, 0x0009, 5, 0x000B, 5, + 0x0010, 5, 0x0013, 5, 0x0015, 5, 0x0018, 5, 0x001A, 5, 0x001D, 5, + 0x001F, 5, 0x0002, 4, 0x0000, 4, 0x001E, 5, 0x001C, 5, 0x0019, 5, + 0x0016, 5, 0x0014, 5, 0x000E, 5, 0x000D, 5, 0x0008, 5, 0x0006, 5, + 0x0002, 5, 0x002E, 6, 0x0023, 6, 0x001F, 6, 0x0015, 6, 0x000F, 6, + 0x005F, 7, 0x0048, 7, 0x0029, 7, 0x00BD, 8, 0x007B, 8, 0x0179, 9, + 0x00A1, 9, 0x037B, 10, 0x0147, 10, 0x0146, 10, 0x0DE8, 12, 0x37AF, 14, + 0x37A7, 14, 0x37AC, 14, 0x37A5, 14 + } +} +}; + +#endif /* FFMPEG_MPC7DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/mpc8.c b/contrib/ffmpeg/libavcodec/mpc8.c new file mode 100644 index 000000000..3dfa5c9f3 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpc8.c @@ -0,0 +1,364 @@ +/* + * Musepack SV8 decoder + * Copyright (c) 2007 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mpc8.c Musepack SV8 decoder + * MPEG Audio Layer 1/2 -like codec with frames of 1152 samples + * divided into 32 subbands. + */ + +#include "avcodec.h" +#include "bitstream.h" +#include "dsputil.h" +#include "random.h" + +#ifdef CONFIG_MPEGAUDIO_HP +#define USE_HIGHPRECISION +#endif +#include "mpegaudio.h" + +#include "mpc.h" +#include "mpcdata.h" +#include "mpc8data.h" +#include "mpc8huff.h" + +static VLC band_vlc, scfi_vlc[2], dscf_vlc[2], res_vlc[2]; +static VLC q1_vlc, q2_vlc[2], q3_vlc[2], quant_vlc[4][2], q9up_vlc; + +static const int q3_offsets[2] = { MPC8_Q3_OFFSET, MPC8_Q4_OFFSET }; +static const int quant_offsets[6] = { MPC8_Q5_OFFSET, MPC8_Q6_OFFSET, MPC8_Q7_OFFSET, MPC8_Q8_OFFSET }; + +static inline int mpc8_dec_base(GetBitContext *gb, int k, int n) +{ + int code = get_bits(gb, mpc8_cnk_len[k-1][n-1] - 1); + + if (code >= mpc8_cnk_lost[k-1][n-1]) + code = ((code << 1) | get_bits1(gb)) - mpc8_cnk_lost[k-1][n-1]; + + return code; +} + +static inline int mpc8_dec_enum(GetBitContext *gb, int k, int n) +{ + int bits = 0; + const uint32_t * C = mpc8_cnk[k-1]; + int code = mpc8_dec_base(gb, k, n); + + do { + n--; + if (code >= C[n]) { + bits |= 1 << n; + code -= C[n]; + C -= 32; + k--; + } + } while(k > 0); + + return bits; +} + +static inline int mpc8_get_mod_golomb(GetBitContext *gb, int m) +{ + if(mpc8_cnk_len[0][m] < 1) return 0; + return mpc8_dec_base(gb, 1, m+1); +} + +static int mpc8_get_mask(GetBitContext *gb, int size, int t) +{ + int mask = 0; + + if(t && t != size) + mask = mpc8_dec_enum(gb, FFMIN(t, size - t), size); + if((t << 1) > size) mask = ~mask; + + return mask; +} + +static int mpc8_decode_init(AVCodecContext * avctx) +{ + int i; + MPCContext *c = avctx->priv_data; + GetBitContext gb; + static int vlc_initialized = 0; + + if(avctx->extradata_size < 2){ + av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\n", avctx->extradata_size); + return -1; + } + memset(c->oldDSCF, 0, sizeof(c->oldDSCF)); + av_init_random(0xDEADBEEF, &c->rnd); + dsputil_init(&c->dsp, avctx); + + ff_mpc_init(); + + init_get_bits(&gb, avctx->extradata, 16); + + skip_bits(&gb, 3);//sample rate + c->maxbands = get_bits(&gb, 5) + 1; + skip_bits(&gb, 4);//channels + c->MSS = get_bits1(&gb); + c->frames = 1 << (get_bits(&gb, 3) * 2); + + if(vlc_initialized) return 0; + av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n"); + + init_vlc(&band_vlc, MPC8_BANDS_BITS, MPC8_BANDS_SIZE, + mpc8_bands_bits, 1, 1, + mpc8_bands_codes, 1, 1, INIT_VLC_USE_STATIC); + + init_vlc(&q1_vlc, MPC8_Q1_BITS, MPC8_Q1_SIZE, + mpc8_q1_bits, 1, 1, + mpc8_q1_codes, 1, 1, INIT_VLC_USE_STATIC); + init_vlc(&q9up_vlc, MPC8_Q9UP_BITS, MPC8_Q9UP_SIZE, + mpc8_q9up_bits, 1, 1, + mpc8_q9up_codes, 1, 1, INIT_VLC_USE_STATIC); + + init_vlc(&scfi_vlc[0], MPC8_SCFI0_BITS, MPC8_SCFI0_SIZE, + mpc8_scfi0_bits, 1, 1, + mpc8_scfi0_codes, 1, 1, INIT_VLC_USE_STATIC); + init_vlc(&scfi_vlc[1], MPC8_SCFI1_BITS, MPC8_SCFI1_SIZE, + mpc8_scfi1_bits, 1, 1, + mpc8_scfi1_codes, 1, 1, INIT_VLC_USE_STATIC); + + init_vlc(&dscf_vlc[0], MPC8_DSCF0_BITS, MPC8_DSCF0_SIZE, + mpc8_dscf0_bits, 1, 1, + mpc8_dscf0_codes, 1, 1, INIT_VLC_USE_STATIC); + init_vlc(&dscf_vlc[1], MPC8_DSCF1_BITS, MPC8_DSCF1_SIZE, + mpc8_dscf1_bits, 1, 1, + mpc8_dscf1_codes, 1, 1, INIT_VLC_USE_STATIC); + + init_vlc_sparse(&q3_vlc[0], MPC8_Q3_BITS, MPC8_Q3_SIZE, + mpc8_q3_bits, 1, 1, + mpc8_q3_codes, 1, 1, + mpc8_q3_syms, 1, 1, INIT_VLC_USE_STATIC); + init_vlc_sparse(&q3_vlc[1], MPC8_Q4_BITS, MPC8_Q4_SIZE, + mpc8_q4_bits, 1, 1, + mpc8_q4_codes, 1, 1, + mpc8_q4_syms, 1, 1, INIT_VLC_USE_STATIC); + + for(i = 0; i < 2; i++){ + init_vlc(&res_vlc[i], MPC8_RES_BITS, MPC8_RES_SIZE, + &mpc8_res_bits[i], 1, 1, + &mpc8_res_codes[i], 1, 1, INIT_VLC_USE_STATIC); + + init_vlc(&q2_vlc[i], MPC8_Q2_BITS, MPC8_Q2_SIZE, + &mpc8_q2_bits[i], 1, 1, + &mpc8_q2_codes[i], 1, 1, INIT_VLC_USE_STATIC); + + init_vlc(&quant_vlc[0][i], MPC8_Q5_BITS, MPC8_Q5_SIZE, + &mpc8_q5_bits[i], 1, 1, + &mpc8_q5_codes[i], 1, 1, INIT_VLC_USE_STATIC); + init_vlc(&quant_vlc[1][i], MPC8_Q6_BITS, MPC8_Q6_SIZE, + &mpc8_q6_bits[i], 1, 1, + &mpc8_q6_codes[i], 1, 1, INIT_VLC_USE_STATIC); + init_vlc(&quant_vlc[2][i], MPC8_Q7_BITS, MPC8_Q7_SIZE, + &mpc8_q7_bits[i], 1, 1, + &mpc8_q7_codes[i], 1, 1, INIT_VLC_USE_STATIC); + init_vlc(&quant_vlc[3][i], MPC8_Q8_BITS, MPC8_Q8_SIZE, + &mpc8_q8_bits[i], 1, 1, + &mpc8_q8_codes[i], 1, 1, INIT_VLC_USE_STATIC); + } + vlc_initialized = 1; + return 0; +} + +static int mpc8_decode_frame(AVCodecContext * avctx, + void *data, int *data_size, + const uint8_t * buf, int buf_size) +{ + MPCContext *c = avctx->priv_data; + GetBitContext gb2, *gb = &gb2; + int i, j, k, ch, cnt, res, t; + Band *bands = c->bands; + int off; + int maxband, keyframe; + int last[2]; + + keyframe = c->cur_frame == 0; + + if(keyframe){ + memset(c->Q, 0, sizeof(c->Q)); + c->last_bits_used = 0; + } + init_get_bits(gb, buf, buf_size * 8); + skip_bits(gb, c->last_bits_used & 7); + + if(keyframe) + maxband = mpc8_get_mod_golomb(gb, c->maxbands + 1); + else{ + maxband = c->last_max_band + get_vlc2(gb, band_vlc.table, MPC8_BANDS_BITS, 2); + if(maxband > 32) maxband -= 33; + } + c->last_max_band = maxband; + + /* read subband indexes */ + if(maxband){ + last[0] = last[1] = 0; + for(i = maxband - 1; i >= 0; i--){ + for(ch = 0; ch < 2; ch++){ + last[ch] = get_vlc2(gb, res_vlc[last[ch] > 2].table, MPC8_RES_BITS, 2) + last[ch]; + if(last[ch] > 15) last[ch] -= 17; + bands[i].res[ch] = last[ch]; + } + } + if(c->MSS){ + int mask; + + cnt = 0; + for(i = 0; i < maxband; i++) + if(bands[i].res[0] || bands[i].res[1]) + cnt++; + t = mpc8_get_mod_golomb(gb, cnt); + mask = mpc8_get_mask(gb, cnt, t); + for(i = maxband - 1; i >= 0; i--) + if(bands[i].res[0] || bands[i].res[1]){ + bands[i].msf = mask & 1; + mask >>= 1; + } + } + } + for(i = maxband; i < c->maxbands; i++) + bands[i].res[0] = bands[i].res[1] = 0; + + if(keyframe){ + for(i = 0; i < 32; i++) + c->oldDSCF[0][i] = c->oldDSCF[1][i] = 1; + } + + for(i = 0; i < maxband; i++){ + if(bands[i].res[0] || bands[i].res[1]){ + cnt = !!bands[i].res[0] + !!bands[i].res[1] - 1; + if(cnt >= 0){ + t = get_vlc2(gb, scfi_vlc[cnt].table, scfi_vlc[cnt].bits, 1); + if(bands[i].res[0]) bands[i].scfi[0] = t >> (2 * cnt); + if(bands[i].res[1]) bands[i].scfi[1] = t & 3; + } + } + } + + for(i = 0; i < maxband; i++){ + for(ch = 0; ch < 2; ch++){ + if(!bands[i].res[ch]) continue; + + if(c->oldDSCF[ch][i]){ + bands[i].scf_idx[ch][0] = get_bits(gb, 7) - 6; + c->oldDSCF[ch][i] = 0; + }else{ + t = get_vlc2(gb, dscf_vlc[1].table, MPC8_DSCF1_BITS, 2); + if(t == 64) + t += get_bits(gb, 6); + bands[i].scf_idx[ch][0] = ((bands[i].scf_idx[ch][2] + t - 25) & 0x7F) - 6; + } + for(j = 0; j < 2; j++){ + if((bands[i].scfi[ch] << j) & 2) + bands[i].scf_idx[ch][j + 1] = bands[i].scf_idx[ch][j]; + else{ + t = get_vlc2(gb, dscf_vlc[0].table, MPC8_DSCF0_BITS, 2); + if(t == 31) + t = 64 + get_bits(gb, 6); + bands[i].scf_idx[ch][j + 1] = ((bands[i].scf_idx[ch][j] + t - 25) & 0x7F) - 6; + } + } + } + } + + for(i = 0, off = 0; i < maxband; i++, off += SAMPLES_PER_BAND){ + for(ch = 0; ch < 2; ch++){ + res = bands[i].res[ch]; + switch(res){ + case -1: + for(j = 0; j < SAMPLES_PER_BAND; j++) + c->Q[ch][off + j] = (av_random(&c->rnd) & 0x3FC) - 510; + break; + case 0: + break; + case 1: + for(j = 0; j < SAMPLES_PER_BAND; j += SAMPLES_PER_BAND / 2){ + cnt = get_vlc2(gb, q1_vlc.table, MPC8_Q1_BITS, 2); + t = mpc8_get_mask(gb, 18, cnt); + for(k = 0; k < SAMPLES_PER_BAND / 2; k++, t <<= 1) + c->Q[ch][off + j + k] = (t & 0x20000) ? (get_bits1(gb) << 1) - 1 : 0; + } + break; + case 2: + cnt = 6;//2*mpc8_thres[res] + for(j = 0; j < SAMPLES_PER_BAND; j += 3){ + t = get_vlc2(gb, q2_vlc[cnt > 3].table, MPC8_Q2_BITS, 2); + c->Q[ch][off + j + 0] = mpc8_idx50[t]; + c->Q[ch][off + j + 1] = mpc8_idx51[t]; + c->Q[ch][off + j + 2] = mpc8_idx52[t]; + cnt = (cnt >> 1) + mpc8_huffq2[t]; + } + break; + case 3: + case 4: + for(j = 0; j < SAMPLES_PER_BAND; j += 2){ + t = get_vlc2(gb, q3_vlc[res - 3].table, MPC8_Q3_BITS, 2) + q3_offsets[res - 3]; + c->Q[ch][off + j + 1] = t >> 4; + c->Q[ch][off + j + 0] = (t & 8) ? (t & 0xF) - 16 : (t & 0xF); + } + break; + case 5: + case 6: + case 7: + case 8: + cnt = 2 * mpc8_thres[res]; + for(j = 0; j < SAMPLES_PER_BAND; j++){ + t = get_vlc2(gb, quant_vlc[res - 5][cnt > mpc8_thres[res]].table, quant_vlc[res - 5][cnt > mpc8_thres[res]].bits, 2) + quant_offsets[res - 5]; + c->Q[ch][off + j] = t; + cnt = (cnt >> 1) + FFABS(c->Q[ch][off + j]); + } + break; + default: + for(j = 0; j < SAMPLES_PER_BAND; j++){ + c->Q[ch][off + j] = get_vlc2(gb, q9up_vlc.table, MPC8_Q9UP_BITS, 2); + if(res != 9){ + c->Q[ch][off + j] <<= res - 9; + c->Q[ch][off + j] |= get_bits(gb, res - 9); + } + c->Q[ch][off + j] -= (1 << (res - 2)) - 1; + } + } + } + } + + ff_mpc_dequantize_and_synth(c, maxband, data); + + c->cur_frame++; + + c->last_bits_used = get_bits_count(gb); + if(c->cur_frame >= c->frames) + c->cur_frame = 0; + *data_size = MPC_FRAME_SIZE * 4; + + return c->cur_frame ? c->last_bits_used >> 3 : buf_size; +} + +AVCodec mpc8_decoder = { + "mpc sv8", + CODEC_TYPE_AUDIO, + CODEC_ID_MUSEPACK8, + sizeof(MPCContext), + mpc8_decode_init, + NULL, + NULL, + mpc8_decode_frame, +}; diff --git a/contrib/ffmpeg/libavcodec/mpc8data.h b/contrib/ffmpeg/libavcodec/mpc8data.h new file mode 100644 index 000000000..280dd6ffd --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpc8data.h @@ -0,0 +1,121 @@ +/* + * Musepack SV8 decoder + * Copyright (c) 2007 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_MPC8DATA_H +#define FFMPEG_MPC8DATA_H + +#include + +static const int8_t mpc8_idx50[125] = { + -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, + -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, + -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, + -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, + -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2 +}; +static const int8_t mpc8_idx51[125] = { + -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, + -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, + -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, + -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, + -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2 +}; +static const int8_t mpc8_idx52[125] = { + -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 +}; + +static const unsigned int mpc8_thres[] = {0, 0, 3, 0, 0, 1, 3, 4, 8}; +static const int8_t mpc8_huffq2[5*5*5] = { + 6, 5, 4, 5, 6, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, 6, 5, 4, 5, + 6, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4, 5, 4, 3, + 4, 5, 4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1, 2, 3, 4, 3, + 2, 3, 4, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 3, 4, 5, + 4, 3, 4, 5, 6, 5, 4, 5, 6, 5, 4, 3, 4, 5, 4, 3, 2, 3, 4, 5, 4, 3, 4, 5, + 6, 5, 4, 5, 6 +}; + + +static const uint32_t mpc8_cnk[16][32] = +{ + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}, + {0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210, 231, 253, 276, 300, 325, 351, 378, 406, 435, 465}, + {0, 0, 0, 1, 4, 10, 20, 35, 56, 84, 120, 165, 220, 286, 364, 455, 560, 680, 816, 969, 1140, 1330, 1540, 1771, 2024, 2300, 2600, 2925, 3276, 3654, 4060, 4495}, + {0, 0, 0, 0, 1, 5, 15, 35, 70, 126, 210, 330, 495, 715, 1001, 1365, 1820, 2380, 3060, 3876, 4845, 5985, 7315, 8855, 10626, 12650, 14950, 17550, 20475, 23751, 27405, 31465}, + {0, 0, 0, 0, 0, 1, 6, 21, 56, 126, 252, 462, 792, 1287, 2002, 3003, 4368, 6188, 8568, 11628, 15504, 20349, 26334, 33649, 42504, 53130, 65780, 80730, 98280, 118755, 142506, 169911}, + {0, 0, 0, 0, 0, 0, 1, 7, 28, 84, 210, 462, 924, 1716, 3003, 5005, 8008, 12376, 18564, 27132, 38760, 54264, 74613, 100947, 134596, 177100, 230230, 296010, 376740, 475020, 593775, 736281}, + {0, 0, 0, 0, 0, 0, 0, 1, 8, 36, 120, 330, 792, 1716, 3432, 6435, 11440, 19448, 31824, 50388, 77520, 116280, 170544, 245157, 346104, 480700, 657800, 888030, 1184040, 1560780, 2035800, 2629575}, + {0, 0, 0, 0, 0, 0, 0, 0, 1, 9, 45, 165, 495, 1287, 3003, 6435, 12870, 24310, 43758, 75582, 125970, 203490, 319770, 490314, 735471, 1081575, 1562275, 2220075, 3108105, 4292145, 5852925, 7888725}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 10, 55, 220, 715, 2002, 5005, 11440, 24310, 48620, 92378, 167960, 293930, 497420, 817190, 1307504, 2042975, 3124550, 4686825, 6906900, 10015005, 14307150, 20160075}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 11, 66, 286, 1001, 3003, 8008, 19448, 43758, 92378, 184756, 352716, 646646, 1144066, 1961256, 3268760, 5311735, 8436285, 13123110, 20030010, 30045015, 44352165}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 12, 78, 364, 1365, 4368, 12376, 31824, 75582, 167960, 352716, 705432, 1352078, 2496144, 4457400, 7726160, 13037895, 21474180, 34597290, 54627300, 84672315}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 13, 91, 455, 1820, 6188, 18564, 50388, 125970, 293930, 646646, 1352078, 2704156, 5200300, 9657700, 17383860, 30421755, 51895935, 86493225, 141120525}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 14, 105, 560, 2380, 8568, 27132, 77520, 203490, 497420, 1144066, 2496144, 5200300, 10400600, 20058300, 37442160, 67863915, 119759850, 206253075}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 15, 120, 680, 3060, 11628, 38760, 116280, 319770, 817190, 1961256, 4457400, 9657700, 20058300, 40116600, 77558760, 145422675, 265182525}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 16, 136, 816, 3876, 15504, 54264, 170544, 490314, 1307504, 3268760, 7726160, 17383860, 37442160, 77558760, 155117520, 300540195}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 17, 153, 969, 4845, 20349, 74613, 245157, 735471, 2042975, 5311735, 13037895, 30421755, 67863915, 145422675, 300540195} +}; + +const static uint8_t mpc8_cnk_len[16][33] = +{ + {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6}, + {0, 0, 2, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 0}, + {0, 0, 0, 2, 4, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 13, 13, 0}, + {0, 0, 0, 0, 3, 4, 6, 7, 7, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 15, 16, 0}, + {0, 0, 0, 0, 0, 3, 5, 6, 7, 8, 9, 10, 11, 11, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 0}, + {0, 0, 0, 0, 0, 0, 3, 5, 7, 8, 9, 10, 11, 12, 13, 13, 14, 15, 15, 16, 16, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20, 0}, + {0, 0, 0, 0, 0, 0, 0, 3, 6, 7, 9, 10, 11, 12, 13, 14, 15, 15, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 21, 22, 22, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 8, 9, 11, 12, 13, 14, 15, 16, 17, 17, 18, 19, 19, 20, 21, 21, 22, 22, 23, 23, 23, 24, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 8, 10, 11, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 21, 22, 23, 23, 24, 24, 25, 25, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 9, 10, 12, 13, 15, 16, 17, 18, 19, 20, 21, 21, 22, 23, 24, 24, 25, 25, 26, 26, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 9, 11, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 23, 24, 25, 26, 26, 27, 27, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 9, 11, 13, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25, 25, 26, 27, 28, 28, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 10, 12, 14, 15, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 27, 28, 29, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 10, 12, 14, 16, 17, 19, 20, 21, 23, 24, 25, 26, 27, 28, 28, 29, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 8, 10, 12, 14, 16, 18, 19, 21, 22, 23, 25, 26, 27, 28, 29, 30, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 10, 13, 15, 17, 18, 20, 21, 23, 24, 25, 27, 28, 29, 30, 0} + +}; + +const static uint32_t mpc8_cnk_lost[16][33] = +{ + {0, 0, 1, 0, 3, 2, 1, 0, 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 31}, + {0, 0, 1, 2, 6, 1, 11, 4, 28, 19, 9, 62, 50, 37, 23, 8, 120, 103, 85, 66, 46, 25, 3, 236, 212, 187, 161, 134, 106, 77, 47, 16, 0}, + {0, 0, 0, 0, 6, 12, 29, 8, 44, 8, 91, 36, 226, 148, 57, 464, 344, 208, 55, 908, 718, 508, 277, 24, 1796, 1496, 1171, 820, 442, 36, 3697, 3232, 0}, + {0, 0, 0, 0, 3, 1, 29, 58, 2, 46, 182, 17, 309, 23, 683, 228, 1716, 1036, 220, 3347, 2207, 877, 7529, 5758, 3734, 1434, 15218, 12293, 9017, 5363, 1303, 29576, 0}, + {0, 0, 0, 0, 0, 2, 11, 8, 2, 4, 50, 232, 761, 46, 1093, 3824, 2004, 7816, 4756, 880, 12419, 6434, 31887, 23032, 12406, 65292, 50342, 32792, 12317, 119638, 92233, 60768, 0}, + {0, 0, 0, 0, 0, 0, 1, 4, 44, 46, 50, 100, 332, 1093, 3187, 184, 4008, 14204, 5636, 26776, 11272, 56459, 30125, 127548, 85044, 31914, 228278, 147548, 49268, 454801, 312295, 142384, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 28, 8, 182, 232, 332, 664, 1757, 4944, 13320, 944, 15148, 53552, 14792, 91600, 16987, 178184, 43588, 390776, 160546, 913112, 536372, 61352, 1564729, 828448, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 7, 19, 91, 17, 761, 1093, 1757, 3514, 8458, 21778, 55490, 5102, 58654, 204518, 33974, 313105, 1015577, 534877, 1974229, 1086199, 4096463, 2535683, 499883, 6258916, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 9, 36, 309, 46, 3187, 4944, 8458, 16916, 38694, 94184, 230358, 26868, 231386, 789648, 54177, 1069754, 3701783, 1481708, 6762211, 2470066, 13394357, 5505632, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 62, 226, 23, 1093, 184, 13320, 21778, 38694, 77388, 171572, 401930, 953086, 135896, 925544, 3076873, 8340931, 3654106, 13524422, 3509417, 22756699, 2596624, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 50, 148, 683, 3824, 4008, 944, 55490, 94184, 171572, 343144, 745074, 1698160, 3931208, 662448, 3739321, 12080252, 32511574, 12481564, 49545413, 5193248, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 37, 57, 228, 2004, 14204, 15148, 5102, 230358, 401930, 745074, 1490148, 3188308, 7119516, 16170572, 3132677, 15212929, 47724503, 127314931, 42642616, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 23, 464, 1716, 7816, 5636, 53552, 58654, 26868, 953086, 1698160, 3188308, 6376616, 13496132, 29666704, 66353813, 14457878, 62182381, 189497312, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 8, 344, 1036, 4756, 26776, 14792, 204518, 231386, 135896, 3931208, 7119516, 13496132, 26992264, 56658968, 123012781, 3252931, 65435312, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 208, 220, 880, 11272, 91600, 33974, 789648, 925544, 662448, 16170572, 29666704, 56658968, 113317936, 236330717, 508019104, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 103, 55, 3347, 12419, 56459, 16987, 313105, 54177, 3076873, 3739321, 3132677, 66353813, 123012781, 236330717, 0} +}; + +#endif /* FFMPEG_MPC8DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/mpc8huff.h b/contrib/ffmpeg/libavcodec/mpc8huff.h new file mode 100644 index 000000000..21e7730ce --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpc8huff.h @@ -0,0 +1,578 @@ +/* + * Musepack SV8 decoder + * Copyright (c) 2007 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_MPC8HUFF_H +#define FFMPEG_MPC8HUFF_H + +#include + +#define MPC8_BANDS_SIZE 33 +#define MPC8_BANDS_BITS 9 + +static const uint8_t mpc8_bands_codes[MPC8_BANDS_SIZE] = { + 0x01, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x04, + 0x05, 0x06, 0x01, 0x02, 0x03, 0x00, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x01, 0x09, 0x0A, 0x0B, 0x07, + 0x08, 0x09, 0x06, 0x07, 0x05, 0x05, 0x03, 0x03, + 0x01, +}; +static const int8_t mpc8_bands_bits[MPC8_BANDS_SIZE] = { + 1, 3, 5, 6, 7, 8, 8, 9, + 10, 11, 12, 12, 12, 13, 12, 12, + 12, 12, 12, 13, 12, 12, 12, 11, + 11, 11, 10, 10, 9, 8, 6, 5, + 2, +}; + +#define MPC8_SCFI0_SIZE 4 +#define MPC8_SCFI0_BITS 3 + +static const uint8_t mpc8_scfi0_codes[MPC8_SCFI0_SIZE] = { + 0x00, 0x01, 0x01, 0x01, +}; +static const int8_t mpc8_scfi0_bits[MPC8_SCFI0_SIZE] = { + 3, 3, 1, 2, +}; + +#define MPC8_SCFI1_SIZE 16 +#define MPC8_SCFI1_BITS 7 + +static const uint8_t mpc8_scfi1_codes[MPC8_SCFI1_SIZE] = { + 0x01, 0x00, 0x02, 0x03, 0x01, 0x03, 0x04, 0x05, + 0x04, 0x06, 0x02, 0x02, 0x05, 0x07, 0x03, 0x03, + +}; +static const int8_t mpc8_scfi1_bits[MPC8_SCFI1_SIZE] = { + 6, 7, 6, 6, 7, 5, 5, 5, + 6, 5, 2, 3, 6, 5, 3, 2, + +}; + +#define MPC8_DSCF0_SIZE 64 +#define MPC8_DSCF0_BITS 9 + +static const uint8_t mpc8_dscf0_codes[MPC8_DSCF0_SIZE] = { + 0x03, 0x04, 0x05, 0x04, 0x05, 0x06, 0x05, 0x06, + 0x07, 0x08, 0x09, 0x07, 0x08, 0x09, 0x0A, 0x07, + 0x08, 0x09, 0x0A, 0x07, 0x08, 0x09, 0x0A, 0x06, + 0x07, 0x05, 0x04, 0x05, 0x06, 0x06, 0x07, 0x0A, + 0x08, 0x05, 0x06, 0x07, 0x09, 0x07, 0x08, 0x09, + 0x0B, 0x0B, 0x0C, 0x0D, 0x0B, 0x0C, 0x0D, 0x0B, + 0x0C, 0x0D, 0x07, 0x08, 0x09, 0x06, 0x07, 0x03, + 0x04, 0x05, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, +}; +static const int8_t mpc8_dscf0_bits[MPC8_DSCF0_SIZE] = { + 12, 12, 12, 11, 11, 11, 10, 10, + 10, 10, 10, 9, 9, 9, 9, 8, + 8, 8, 8, 7, 7, 7, 7, 6, + 6, 5, 4, 4, 5, 4, 4, 10, + 4, 3, 3, 3, 4, 5, 6, 6, + 7, 8, 8, 8, 9, 9, 9, 10, + 10, 10, 11, 11, 11, 12, 12, 13, + 13, 13, 14, 14, 14, 14, 14, 14, + +}; + +#define MPC8_DSCF1_SIZE 65 +#define MPC8_DSCF1_BITS 9 + +static const uint8_t mpc8_dscf1_codes[MPC8_DSCF1_SIZE] = { + 0x00, 0x03, 0x04, 0x04, 0x05, 0x06, 0x05, 0x06, + 0x07, 0x08, 0x07, 0x08, 0x09, 0x0A, 0x07, 0x08, + 0x09, 0x0A, 0x07, 0x08, 0x09, 0x06, 0x07, 0x05, + 0x06, 0x04, 0x03, 0x03, 0x04, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x05, 0x04, 0x05, 0x05, 0x07, 0x08, + 0x09, 0x0A, 0x0B, 0x0B, 0x0C, 0x0D, 0x0B, 0x0C, + 0x0D, 0x09, 0x0A, 0x0B, 0x0C, 0x07, 0x08, 0x09, + 0x05, 0x06, 0x07, 0x01, 0x02, 0x03, 0x04, 0x05, + 0x0D, +}; +static const int8_t mpc8_dscf1_bits[MPC8_DSCF1_SIZE] = { + 15, 14, 14, 13, 13, 13, 12, 12, + 12, 12, 11, 11, 11, 11, 10, 10, + 10, 10, 9, 9, 9, 8, 8, 7, + 7, 6, 5, 4, 4, 3, 3, 3, + 3, 3, 4, 5, 5, 6, 7, 8, + 8, 9, 9, 10, 10, 10, 11, 11, + 11, 12, 12, 12, 12, 13, 13, 13, + 14, 14, 14, 15, 15, 15, 15, 15, + 12, +}; + +#define MPC8_RES_SIZE 17 +#define MPC8_RES_BITS 9 + +static const uint8_t mpc8_res_codes[2][MPC8_RES_SIZE] = { + { + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, + 0x01, + }, + { + 0x01, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x00, 0x01, 0x02, 0x03, 0x01, 0x01, 0x01, 0x01, + 0x03, + } +}; +static const int8_t mpc8_res_bits[2][MPC8_RES_SIZE] = { + { + 1, 2, 4, 5, 6, 7, 9, 10, + 11, 12, 13, 14, 15, 16, 16, 8, + 3, + }, + { + 2, 2, 3, 5, 7, 8, 10, 12, + 14, 14, 14, 14, 11, 9, 6, 4, + 2, + } +}; + +#define MPC8_Q1_SIZE 19 +#define MPC8_Q1_BITS 9 + +static const uint8_t mpc8_q1_codes[MPC8_Q1_SIZE] = { + 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x03, 0x04, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x00, 0x01, +}; +static const int8_t mpc8_q1_bits[MPC8_Q1_SIZE] = { + 6, 4, 4, 3, 3, 3, 3, 3, + 4, 4, 4, 5, 7, 8, 9, 10, + 11, 12, 12, +}; + +#define MPC8_Q9UP_SIZE 256 +#define MPC8_Q9UP_BITS 9 + +static const uint8_t mpc8_q9up_codes[MPC8_Q9UP_SIZE] = { + 0x01, 0x02, 0x03, 0x04, 0x05, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x26, 0x27, 0x13, 0x14, 0x15, + 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, + 0x28, 0x26, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, + 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, + 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, + 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, + 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, + 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, + 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, + 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, + 0x67, 0x68, 0x69, 0x6A, 0x56, 0x57, 0x58, 0x59, + 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, + 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x3E, + 0x3F, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x6B, 0x7B, 0x6C, 0x6D, 0x6E, + 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, + 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, + 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, + 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, + 0x8F, 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, + 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, + 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, + 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0x27, 0x28, 0x29, + 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, + 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, + 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, + 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, + 0x4A, 0x4B, 0x06, 0x07, 0x08, 0x09, 0x00, 0x01, +}; +static const int8_t mpc8_q9up_bits[MPC8_Q9UP_SIZE] = { + 10, 10, 10, 10, 10, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 8, 8, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, + 8, 9, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 6, + 6, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 8, 7, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 10, 10, 10, 10, 11, 11, +}; + +#define MPC8_Q2_SIZE 125 +#define MPC8_Q2_BITS 9 + +static const uint8_t mpc8_q2_codes[2][MPC8_Q2_SIZE] = { +{ + 0x02, 0x03, 0x0F, 0x04, 0x00, 0x05, 0x0C, 0x12, + 0x0D, 0x06, 0x07, 0x13, 0x15, 0x14, 0x08, 0x09, + 0x0E, 0x15, 0x0F, 0x0A, 0x03, 0x0B, 0x10, 0x0C, + 0x01, 0x0D, 0x10, 0x16, 0x11, 0x0E, 0x12, 0x0F, + 0x10, 0x16, 0x13, 0x17, 0x11, 0x08, 0x12, 0x18, + 0x14, 0x13, 0x14, 0x17, 0x15, 0x0F, 0x16, 0x19, + 0x17, 0x10, 0x11, 0x1A, 0x18, 0x1B, 0x12, 0x1C, + 0x15, 0x09, 0x16, 0x1D, 0x19, 0x0A, 0x07, 0x0B, + 0x1A, 0x1E, 0x17, 0x0C, 0x18, 0x1F, 0x13, 0x20, + 0x1B, 0x21, 0x14, 0x11, 0x18, 0x22, 0x19, 0x12, + 0x1A, 0x19, 0x1A, 0x1B, 0x1B, 0x23, 0x1C, 0x0D, + 0x1D, 0x24, 0x1C, 0x1C, 0x1E, 0x1F, 0x1D, 0x13, + 0x1E, 0x25, 0x1F, 0x14, 0x02, 0x15, 0x15, 0x16, + 0x04, 0x17, 0x20, 0x26, 0x21, 0x18, 0x16, 0x27, + 0x1D, 0x28, 0x19, 0x1A, 0x22, 0x29, 0x23, 0x1B, + 0x03, 0x1C, 0x17, 0x1D, 0x05, +}, +{ + 0x02, 0x03, 0x0F, 0x04, 0x00, 0x05, 0x0C, 0x0D, + 0x0E, 0x06, 0x07, 0x0F, 0x1E, 0x10, 0x10, 0x08, + 0x11, 0x12, 0x13, 0x09, 0x03, 0x0A, 0x11, 0x0B, + 0x01, 0x0C, 0x14, 0x15, 0x16, 0x0D, 0x17, 0x12, + 0x0E, 0x13, 0x18, 0x19, 0x14, 0x0F, 0x10, 0x1A, + 0x1B, 0x15, 0x11, 0x16, 0x1C, 0x0E, 0x1D, 0x1E, + 0x1F, 0x0F, 0x12, 0x20, 0x1F, 0x21, 0x13, 0x22, + 0x12, 0x13, 0x14, 0x23, 0x20, 0x15, 0x0F, 0x16, + 0x21, 0x24, 0x17, 0x18, 0x19, 0x25, 0x14, 0x26, + 0x22, 0x27, 0x15, 0x10, 0x28, 0x29, 0x2A, 0x11, + 0x2B, 0x17, 0x1A, 0x18, 0x2C, 0x2D, 0x1B, 0x1C, + 0x19, 0x2E, 0x2F, 0x1A, 0x1D, 0x1B, 0x30, 0x12, + 0x31, 0x32, 0x33, 0x13, 0x02, 0x14, 0x15, 0x16, + 0x04, 0x17, 0x34, 0x35, 0x36, 0x18, 0x16, 0x37, + 0x23, 0x38, 0x19, 0x1A, 0x39, 0x3A, 0x3B, 0x1B, + 0x03, 0x1C, 0x17, 0x1D, 0x05, +} +}; +static const int8_t mpc8_q2_bits[2][MPC8_Q2_SIZE] = { +{ + 12, 11, 10, 11, 13, 11, 9, 8, + 9, 11, 11, 8, 7, 8, 11, 11, + 9, 8, 9, 11, 12, 11, 10, 11, + 13, 11, 9, 8, 9, 11, 9, 6, + 6, 7, 9, 8, 6, 4, 6, 8, + 9, 6, 6, 7, 9, 11, 9, 8, + 9, 11, 10, 8, 7, 8, 10, 8, + 6, 4, 6, 8, 7, 4, 3, 4, + 7, 8, 6, 4, 6, 8, 10, 8, + 7, 8, 10, 11, 9, 8, 9, 11, + 9, 6, 6, 6, 9, 8, 6, 4, + 6, 8, 9, 7, 6, 6, 9, 11, + 9, 8, 9, 11, 13, 11, 10, 11, + 12, 11, 9, 8, 9, 11, 10, 8, + 7, 8, 11, 11, 9, 8, 9, 11, + 13, 11, 10, 11, 12, +}, +{ + 11, 10, 9, 10, 12, 10, 8, 8, + 8, 10, 10, 8, 7, 8, 9, 10, + 8, 8, 8, 10, 11, 10, 9, 10, + 12, 10, 8, 8, 8, 10, 8, 6, + 5, 6, 8, 8, 6, 5, 5, 8, + 8, 6, 5, 6, 8, 10, 8, 8, + 8, 10, 9, 8, 7, 8, 9, 8, + 5, 5, 5, 8, 7, 5, 4, 5, + 7, 8, 5, 5, 5, 8, 9, 8, + 7, 8, 9, 10, 8, 8, 8, 10, + 8, 6, 5, 6, 8, 8, 5, 5, + 6, 8, 8, 6, 5, 6, 8, 10, + 8, 8, 8, 10, 12, 10, 10, 10, + 11, 10, 8, 8, 8, 10, 9, 8, + 7, 8, 10, 10, 8, 8, 8, 10, + 12, 10, 9, 10, 11, +} +}; + +#define MPC8_Q3_SIZE 49 +#define MPC8_Q3_BITS 9 +#define MPC8_Q3_OFFSET -48 + +static const uint8_t mpc8_q3_codes[MPC8_Q3_SIZE] = { + 0x07, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x0F, + 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x13, 0x12, 0x11, + 0x10, 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, + 0x11, 0x10, 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, + 0x09, 0x08, 0x07, 0x06, 0x05, 0x09, 0x08, 0x07, + 0x06, 0x05, 0x04, 0x03, 0x02, 0x03, 0x02, 0x01, + 0x00, +}; +static const int8_t mpc8_q3_bits[MPC8_Q3_SIZE] = { + 3, 4, 4, 4, 4, 4, 4, 5, + 5, 5, 5, 5, 5, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 8, 8, 8, + 8, 8, 8, 8, 8, 9, 9, 9, + 9, +}; +static const int8_t mpc8_q3_syms[MPC8_Q3_SIZE] = { + 48, 65, 64, 49, 63, 32, 47, 80, + 79, 50, 62, 33, 16, 82, 81, 95, + 94, 66, 78, 34, 46, 17, 31, 30, + 97, 96, 111, 67, 77, 51, 61, 35, + 45, 18, 1, 0, 15, 98, 110, 83, + 93, 19, 29, 2, 14, 99, 109, 3, + 13, +}; + +#define MPC8_Q4_SIZE 81 +#define MPC8_Q4_BITS 9 +#define MPC8_Q4_OFFSET -64 + +static const uint8_t mpc8_q4_codes[MPC8_Q4_SIZE] = { + 0x0F, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, 0x18, 0x17, + 0x16, 0x15, 0x14, 0x13, 0x12, 0x23, 0x22, 0x21, + 0x20, 0x1F, 0x1E, 0x1D, 0x1C, 0x1B, 0x1A, 0x19, + 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, + 0x10, 0x0F, 0x0E, 0x0D, 0x19, 0x18, 0x17, 0x16, + 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0F, 0x0E, + 0x0D, 0x0C, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, + 0x11, 0x10, 0x0F, 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, + 0x09, 0x08, 0x07, 0x06, 0x05, 0x09, 0x08, 0x07, + 0x06, 0x05, 0x04, 0x03, 0x02, 0x03, 0x02, 0x01, + 0x00, +}; +static const int8_t mpc8_q4_bits[MPC8_Q4_SIZE] = { + 4, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 9, 9, 9, + 9, 9, 9, 9, 9, 10, 10, 10, + 10, +}; +static const int8_t mpc8_q4_syms[MPC8_Q4_SIZE] = { + 64, 96, 81, 80, 95, 66, 65, 79, + 78, 49, 48, 63, 32, 113, 112, 98, + 97, 111, 110, 83, 82, 94, 93, 67, + 77, 51, 50, 62, 61, 34, 33, 47, + 46, 17, 16, 31, 128, 114, 127, 126, + 99, 109, 68, 76, 35, 45, 18, 30, + 0, 15, 130, 129, 143, 142, 115, 125, + 100, 108, 84, 92, 52, 60, 36, 44, + 19, 29, 2, 1, 14, 131, 141, 116, + 124, 20, 28, 3, 13, 132, 140, 4, + 12, +}; + +#define MPC8_Q5_SIZE 15 +#define MPC8_Q5_BITS 7 +#define MPC8_Q5_OFFSET -7 + +static const uint8_t mpc8_q5_codes[2][MPC8_Q5_SIZE] = { +{ + 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, + 0x04, 0x05, 0x03, 0x03, 0x03, 0x02, 0x03, +}, +{ + 0x00, 0x01, 0x02, 0x02, 0x03, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x04, 0x05, 0x03, 0x02, 0x03, +} +}; +static const int8_t mpc8_q5_bits[2][MPC8_Q5_SIZE] = { +{ + 7, 7, 6, 5, 4, 3, 3, 2, + 3, 3, 4, 5, 6, 7, 7, +}, +{ + 6, 6, 5, 4, 4, 3, 3, 3, + 3, 3, 4, 4, 5, 6, 6, +} +}; + +#define MPC8_Q6_SIZE 31 +#define MPC8_Q6_BITS 9 +#define MPC8_Q6_OFFSET -15 + +static const uint8_t mpc8_q6_codes[2][MPC8_Q6_SIZE] = { +{ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x04, 0x03, + 0x04, 0x05, 0x05, 0x06, 0x04, 0x05, 0x04, 0x03, + 0x05, 0x06, 0x07, 0x07, 0x06, 0x07, 0x08, 0x09, + 0x05, 0x06, 0x07, 0x04, 0x05, 0x06, 0x07, +}, +{ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x04, 0x05, 0x04, + 0x05, 0x06, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, + 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x07, 0x08, 0x09, + 0x06, 0x07, 0x05, 0x06, 0x07, 0x02, 0x03, +} +}; +static const int8_t mpc8_q6_bits[2][MPC8_Q6_SIZE] = { +{ + 9, 9, 9, 9, 8, 8, 7, 6, + 6, 6, 5, 5, 4, 4, 3, 2, + 3, 4, 4, 5, 6, 6, 6, 6, + 7, 8, 8, 9, 9, 9, 9, +}, +{ + 8, 8, 7, 7, 7, 6, 6, 5, + 5, 5, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 5, 5, 5, + 6, 6, 7, 7, 7, 8, 8, +} +}; + +#define MPC8_Q7_SIZE 63 +#define MPC8_Q7_BITS 9 +#define MPC8_Q7_OFFSET -31 + +static const uint8_t mpc8_q7_codes[2][MPC8_Q7_SIZE] = { +{ + 0x00, 0x01, 0x02, 0x08, 0x09, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x0A, 0x0B, 0x0C, 0x0D, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, + 0x0A, 0x0B, 0x0C, 0x08, 0x09, 0x06, 0x04, 0x03, + 0x05, 0x07, 0x0A, 0x0B, 0x0D, 0x0E, 0x0F, 0x0F, + 0x10, 0x11, 0x12, 0x0F, 0x13, 0x10, 0x11, 0x12, + 0x13, 0x0E, 0x0F, 0x10, 0x11, 0x08, 0x09, 0x0A, + 0x0B, 0x0C, 0x12, 0x13, 0x0D, 0x0E, 0x0F, +}, +{ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x09, 0x0A, + 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x0C, 0x0D, + 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, + 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, + 0x1E, 0x1F, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, + 0x17, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x09, 0x0A, + 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x02, 0x03, +} +}; +static const int8_t mpc8_q7_bits[2][MPC8_Q7_SIZE] = { +{ + 10, 10, 10, 9, 9, 10, 10, 10, + 10, 10, 9, 9, 9, 9, 8, 8, + 8, 8, 8, 7, 7, 7, 7, 7, + 6, 6, 6, 5, 5, 4, 3, 2, + 3, 4, 5, 5, 6, 6, 6, 7, + 7, 7, 7, 8, 7, 8, 8, 8, + 8, 9, 9, 9, 9, 10, 10, 10, + 10, 10, 9, 9, 10, 10, 10, +}, +{ + 9, 9, 8, 8, 8, 8, 8, 8, + 8, 7, 7, 7, 7, 7, 6, 6, + 6, 6, 6, 6, 6, 6, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 6, 6, 6, 6, 6, 6, + 6, 7, 7, 7, 7, 7, 8, 8, + 8, 8, 8, 8, 8, 9, 9, +} +}; + +#define MPC8_Q8_SIZE 127 +#define MPC8_Q8_BITS 9 +#define MPC8_Q8_OFFSET -63 + +static const uint8_t mpc8_q8_codes[2][MPC8_Q8_SIZE] = { +{ + 0x03, 0x04, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x1A, + 0x0F, 0x1B, 0x10, 0x00, 0x01, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x11, 0x0C, 0x12, 0x13, + 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1C, 0x1A, + 0x1B, 0x1C, 0x1D, 0x1E, 0x1D, 0x1E, 0x1F, 0x20, + 0x21, 0x22, 0x23, 0x24, 0x19, 0x25, 0x1A, 0x1B, + 0x1C, 0x1D, 0x1E, 0x1F, 0x14, 0x15, 0x16, 0x17, + 0x0E, 0x0F, 0x10, 0x11, 0x0B, 0x07, 0x04, 0x03, + 0x05, 0x0C, 0x0D, 0x12, 0x13, 0x14, 0x15, 0x18, + 0x19, 0x1A, 0x1B, 0x20, 0x21, 0x22, 0x23, 0x24, + 0x25, 0x26, 0x27, 0x26, 0x27, 0x28, 0x29, 0x2A, + 0x2B, 0x2C, 0x2D, 0x2E, 0x1F, 0x20, 0x2F, 0x21, + 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, + 0x0D, 0x0E, 0x2A, 0x0F, 0x10, 0x11, 0x12, 0x02, + 0x13, 0x03, 0x04, 0x05, 0x2B, 0x2C, 0x30, 0x31, + 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, +}, +{ + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x15, 0x16, + 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, + 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, + 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, + 0x2F, 0x30, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, + 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, + 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, + 0x3C, 0x3D, 0x3E, 0x31, 0x3F, 0x32, 0x33, 0x34, + 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, + 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, + 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x16, + 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, + 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, + 0x27, 0x28, 0x29, 0x04, 0x05, 0x06, 0x07, +} +}; +static const int8_t mpc8_q8_bits[2][MPC8_Q8_SIZE] = { +{ + 11, 11, 10, 10, 10, 10, 10, 9, + 10, 9, 10, 12, 12, 11, 11, 11, + 11, 11, 11, 11, 10, 11, 10, 10, + 10, 10, 10, 10, 10, 10, 9, 10, + 10, 10, 10, 10, 9, 9, 9, 9, + 9, 9, 9, 9, 8, 9, 8, 8, + 8, 8, 8, 8, 7, 7, 7, 7, + 6, 6, 6, 6, 5, 4, 3, 2, + 3, 5, 5, 6, 6, 6, 6, 7, + 7, 7, 7, 8, 8, 8, 8, 8, + 8, 8, 8, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 10, 10, 9, 10, + 10, 10, 10, 10, 10, 10, 10, 10, + 11, 11, 10, 11, 11, 11, 11, 12, + 11, 12, 12, 12, 10, 10, 9, 9, + 10, 10, 10, 10, 10, 10, 10, +}, +{ + 9, 9, 9, 9, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 7, 6, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 9, 9, 9, 9, +} +}; + +#endif /* FFMPEG_MPC8HUFF_H */ diff --git a/contrib/ffmpeg/libavcodec/mpcdata.h b/contrib/ffmpeg/libavcodec/mpcdata.h index 2b74765ed..23ad06d9c 100644 --- a/contrib/ffmpeg/libavcodec/mpcdata.h +++ b/contrib/ffmpeg/libavcodec/mpcdata.h @@ -17,14 +17,12 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ -static const int8_t mpc_idx30[] = { -1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1}; -static const int8_t mpc_idx31[] = { -1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1}; -static const int8_t mpc_idx32[] = { -1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1}; -static const int8_t mpc_idx50[] = { -2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2,-2,-1, 0, 1, 2}; -static const int8_t mpc_idx51[] = { -2,-2,-2,-2,-2,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2}; +#ifndef FFMPEG_MPCDATA_H +#define FFMPEG_MPCDATA_H + +#include static const float mpc_CC[18] = { 65536.0000, 21845.3333, 13107.2000, 9362.2857, 7281.7778, 4369.0667, 2114.0645, @@ -32,145 +30,7 @@ static const float mpc_CC[18] = { 4.0002, 2.0001, 1.0000 }; -#define MPC7_SCFI_SIZE 4 -#define MPC7_SCFI_BITS 3 -static const uint8_t mpc7_scfi[MPC7_SCFI_SIZE * 2] = { - 0x2, 3, 0x1, 1, 0x3, 3, 0x0, 2 -}; - -#define MPC7_DSCF_SIZE 16 -#define MPC7_DSCF_BITS 6 -static const uint8_t mpc7_dscf[MPC7_DSCF_SIZE * 2] = { - 0x20, 6, 0x04, 5, 0x11, 5, 0x1E, 5, 0x0D, 4, 0x00, 3, 0x03, 3, 0x09, 4, - 0x05, 3, 0x02, 3, 0x0E, 4, 0x03, 4, 0x1F, 5, 0x05, 5, 0x21, 6, 0x0C, 4 -}; - -#define MPC7_HDR_SIZE 10 -#define MPC7_HDR_BITS 9 -static const uint8_t mpc7_hdr[MPC7_HDR_SIZE * 2] = { - 0x5C, 8, 0x2F, 7, 0x0A, 5, 0x04, 4, 0x00, 2, - 0x01, 1, 0x03, 3, 0x16, 6, 0xBB, 9, 0xBA, 9 -}; - -#define MPC7_QUANT_VLC_TABLES 7 -static const uint8_t mpc7_quant_vlc_sizes[MPC7_QUANT_VLC_TABLES * 2] = { - 27, 25, 7, 9, 15, 31, 63 -}; - -static const uint8_t mpc7_quant_vlc_off[MPC7_QUANT_VLC_TABLES] = { - 0, 0, 3, 4, 7, 15, 31 -}; - -static const uint16_t mpc7_quant_vlc[MPC7_QUANT_VLC_TABLES][2][64 * 2] = { -{ - { - 0x0036, 6, 0x0009, 5, 0x0020, 6, 0x0005, 5, 0x000A, 4, 0x0007, 5, - 0x0034, 6, 0x0000, 5, 0x0023, 6, 0x000A, 5, 0x0006, 4, 0x0004, 5, - 0x000B, 4, 0x0007, 3, 0x000C, 4, 0x0003, 5, 0x0007, 4, 0x000B, 5, - 0x0022, 6, 0x0001, 5, 0x0035, 6, 0x0006, 5, 0x0009, 4, 0x0002, 5, - 0x0021, 6, 0x0008, 5, 0x0037, 6 - }, - { - 0x0067, 8, 0x003E, 7, 0x00E1, 9, 0x0037, 7, 0x0003, 4, 0x0034, 7, - 0x0065, 8, 0x003C, 7, 0x00E3, 9, 0x0018, 6, 0x0000, 4, 0x003D, 7, - 0x0004, 4, 0x0001, 1, 0x0005, 4, 0x003F, 7, 0x0001, 4, 0x003B, 7, - 0x00E2, 9, 0x0039, 7, 0x0064, 8, 0x0035, 7, 0x0002, 4, 0x0036, 7, - 0x00E0, 9, 0x003A, 7, 0x0066, 8 - } -}, -{ - { - 0x0059, 7, 0x002F, 6, 0x000F, 5, 0x0000, 5, 0x005B, 7, 0x0004, 5, - 0x0006, 4, 0x000D, 4, 0x0004, 4, 0x0005, 5, 0x0014, 5, 0x000C, 4, - 0x0004, 3, 0x000F, 4, 0x000E, 5, 0x0003, 5, 0x0003, 4, 0x000E, 4, - 0x0005, 4, 0x0001, 5, 0x005A, 7, 0x0002, 5, 0x0015, 5, 0x002E, 6, - 0x0058, 7 - }, - { - 0x0399, 10, 0x0071, 7, 0x0033, 6, 0x00E7, 8, 0x039A, 10, 0x0068, 7, - 0x001E, 5, 0x0000, 3, 0x001D, 5, 0x0069, 7, 0x0032, 6, 0x0001, 3, - 0x0002, 2, 0x0003, 3, 0x0031, 6, 0x006B, 7, 0x001B, 5, 0x0002, 3, - 0x001F, 5, 0x0070, 7, 0x0398, 10, 0x006A, 7, 0x0030, 6, 0x0072, 7, - 0x039B, 10 - } -}, -{ - { - 0x000C, 4, 0x0004, 3, 0x0000, 2, 0x0001, 2, 0x0007, 3, 0x0005, 3, 0x000D, 4 - }, - { - 0x0004, 5, 0x0003, 4, 0x0002, 2, 0x0003, 2, 0x0001, 2, 0x0000, 3, 0x0005, 5 - } -}, -{ - { - 0x0005, 4, 0x0000, 3, 0x0004, 3, 0x0006, 3, 0x0007, 3, 0x0005, 3, 0x0003, 3, 0x0001, 3, 0x0004, 4 - }, - { - 0x0009, 5, 0x000C, 4, 0x0003, 3, 0x0000, 2, 0x0002, 2, 0x0007, 3, 0x000D, 4, 0x0005, 4, 0x0008, 5 - } -}, -{ - { - 0x0039, 6, 0x0017, 5, 0x0008, 4, 0x000A, 4, 0x000D, 4, 0x0000, 3, - 0x0002, 3, 0x0003, 3, 0x0001, 3, 0x000F, 4, 0x000C, 4, 0x0009, 4, - 0x001D, 5, 0x0016, 5, 0x0038, 6, - }, - { - 0x00E5, 8, 0x0038, 6, 0x0007, 5, 0x0002, 4, 0x0000, 3, 0x0003, 3, - 0x0005, 3, 0x0006, 3, 0x0004, 3, 0x0002, 3, 0x000F, 4, 0x001D, 5, - 0x0006, 5, 0x0073, 7, 0x00E4, 8, - }, -}, -{ - { - 0x0041, 7, 0x0006, 6, 0x002C, 6, 0x002D, 6, 0x003B, 6, 0x000D, 5, - 0x0011, 5, 0x0013, 5, 0x0017, 5, 0x0015, 5, 0x001A, 5, 0x001E, 5, - 0x0000, 4, 0x0002, 4, 0x0005, 4, 0x0007, 4, 0x0003, 4, 0x0004, 4, - 0x001F, 5, 0x001C, 5, 0x0019, 5, 0x001B, 5, 0x0018, 5, 0x0014, 5, - 0x0012, 5, 0x000C, 5, 0x0002, 5, 0x003A, 6, 0x0021, 6, 0x0007, 6, - 0x0040, 7 - }, - { - 0x1948, 13, 0x194A, 13, 0x0328, 10, 0x0195, 9, 0x00CB, 8, 0x0066, 7, - 0x0031, 6, 0x0009, 5, 0x000F, 5, 0x001F, 5, 0x0002, 4, 0x0006, 4, - 0x0008, 4, 0x000B, 4, 0x000D, 4, 0x0000, 3, 0x000E, 4, 0x000A, 4, - 0x0009, 4, 0x0005, 4, 0x0003, 4, 0x001E, 5, 0x000E, 5, 0x0008, 5, - 0x0030, 6, 0x0067, 7, 0x00C9, 8, 0x00C8, 8, 0x0653, 11, 0x1949, 13, - 0x194B, 13 - } -}, -{ - { - 0x0067, 8, 0x0099, 8, 0x00B5, 8, 0x00E9, 8, 0x0040, 7, 0x0041, 7, - 0x004D, 7, 0x0051, 7, 0x005B, 7, 0x0071, 7, 0x0070, 7, 0x0018, 6, - 0x001D, 6, 0x0023, 6, 0x0025, 6, 0x0029, 6, 0x002C, 6, 0x002E, 6, - 0x0033, 6, 0x0031, 6, 0x0036, 6, 0x0037, 6, 0x0039, 6, 0x003C, 6, - 0x0000, 5, 0x0002, 5, 0x000A, 5, 0x0005, 5, 0x0009, 5, 0x0006, 5, - 0x000D, 5, 0x0007, 5, 0x000B, 5, 0x000F, 5, 0x0008, 5, 0x0004, 5, - 0x0003, 5, 0x0001, 5, 0x003F, 6, 0x003E, 6, 0x003D, 6, 0x0035, 6, - 0x003B, 6, 0x0034, 6, 0x0030, 6, 0x002F, 6, 0x002B, 6, 0x002A, 6, - 0x0027, 6, 0x0024, 6, 0x0021, 6, 0x001C, 6, 0x0075, 7, 0x0065, 7, - 0x0064, 7, 0x0050, 7, 0x0045, 7, 0x0044, 7, 0x0032, 7, 0x00E8, 8, - 0x00B4, 8, 0x0098, 8, 0x0066, 8 - }, - { - 0x37A4, 14, 0x37AD, 14, 0x37A6, 14, 0x37AE, 14, 0x0DEA, 12, 0x02F0, 10, - 0x02F1, 10, 0x00A0, 9, 0x00A2, 9, 0x01BC, 9, 0x007A, 8, 0x00DF, 8, - 0x003C, 7, 0x0049, 7, 0x006E, 7, 0x000E, 6, 0x0018, 6, 0x0019, 6, - 0x0022, 6, 0x0025, 6, 0x0036, 6, 0x0003, 5, 0x0009, 5, 0x000B, 5, - 0x0010, 5, 0x0013, 5, 0x0015, 5, 0x0018, 5, 0x001A, 5, 0x001D, 5, - 0x001F, 5, 0x0002, 4, 0x0000, 4, 0x001E, 5, 0x001C, 5, 0x0019, 5, - 0x0016, 5, 0x0014, 5, 0x000E, 5, 0x000D, 5, 0x0008, 5, 0x0006, 5, - 0x0002, 5, 0x002E, 6, 0x0023, 6, 0x001F, 6, 0x0015, 6, 0x000F, 6, - 0x005F, 7, 0x0048, 7, 0x0029, 7, 0x00BD, 8, 0x007B, 8, 0x0179, 9, - 0x00A1, 9, 0x037B, 10, 0x0147, 10, 0x0146, 10, 0x0DE8, 12, 0x37AF, 14, - 0x37A7, 14, 0x37AC, 14, 0x37A5, 14 - } -} -}; - -static const float mpc7_SCF[128] = { +static const float mpc_SCF[128] = { 307.330047607421875000, 255.999984741210937500, 213.243041992187500000, 177.627334594726562500, 147.960128784179687500, 123.247924804687500000, 102.663139343261718750, 85.516410827636718750, 71.233520507812500000, 59.336143493652343750, 49.425861358642578125, 41.170787811279296875, @@ -204,3 +64,5 @@ static const float mpc7_SCF[128] = { 0.000000092001613439, 0.000000076635565449, 0.000000063835940978, 0.000000053174105119, 0.000000044293003043, 0.000000036895215771, 0.000000030733001921, 0.000000025599996789 }; + +#endif /* FFMPEG_MPCDATA_H */ diff --git a/contrib/ffmpeg/libavcodec/mpeg12.c b/contrib/ffmpeg/libavcodec/mpeg12.c index c0fa7e4bc..56b456a07 100644 --- a/contrib/ffmpeg/libavcodec/mpeg12.c +++ b/contrib/ffmpeg/libavcodec/mpeg12.c @@ -1,5 +1,5 @@ /* - * MPEG1 codec / MPEG2 decoder + * MPEG1/2 decoder * Copyright (c) 2000,2001 Fabrice Bellard. * Copyright (c) 2002-2004 Michael Niedermayer * @@ -22,7 +22,7 @@ /** * @file mpeg12.c - * MPEG1/2 codec + * MPEG1/2 decoder */ //#define DEBUG @@ -30,23 +30,15 @@ #include "dsputil.h" #include "mpegvideo.h" +#include "mpeg12.h" #include "mpeg12data.h" +#include "mpeg12decdata.h" #include "bytestream.h" //#undef NDEBUG //#include -/* Start codes. */ -#define SEQ_END_CODE 0x000001b7 -#define SEQ_START_CODE 0x000001b3 -#define GOP_START_CODE 0x000001b8 -#define PICTURE_START_CODE 0x00000100 -#define SLICE_MIN_START_CODE 0x00000101 -#define SLICE_MAX_START_CODE 0x000001af -#define EXT_START_CODE 0x000001b5 -#define USER_START_CODE 0x000001b2 - #define DC_VLC_BITS 9 #define MV_VLC_BITS 9 #define MBINCR_VLC_BITS 9 @@ -55,12 +47,6 @@ #define MB_BTYPE_VLC_BITS 6 #define TEX_VLC_BITS 9 -#ifdef CONFIG_ENCODERS -static void mpeg1_encode_block(MpegEncContext *s, - DCTELEM *block, - int component); -static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code); // RAL: f_code parameter added -#endif //CONFIG_ENCODERS static inline int mpeg1_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n); @@ -79,12 +65,10 @@ static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, DCTELEM *bloc static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred); static void exchange_uv(MpegEncContext *s); -#ifdef HAVE_XVMC extern int XVMC_field_start(MpegEncContext *s, AVCodecContext *avctx); extern int XVMC_field_end(MpegEncContext *s); extern void XVMC_pack_pblocks(MpegEncContext *s,int cbp); extern void XVMC_init_block(MpegEncContext *s);//set s->block -#endif static const enum PixelFormat pixfmt_yuv_420[]= {PIX_FMT_YUV420P,-1}; static const enum PixelFormat pixfmt_yuv_422[]= {PIX_FMT_YUV422P,-1}; @@ -93,22 +77,8 @@ static const enum PixelFormat pixfmt_xvmc_mpg2_420[] = { PIX_FMT_XVMC_MPEG2_IDCT, PIX_FMT_XVMC_MPEG2_MC, -1}; -#ifdef CONFIG_ENCODERS -static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; -static uint8_t fcode_tab[MAX_MV*2+1]; - -static uint8_t uni_mpeg1_ac_vlc_len [64*64*2]; -static uint8_t uni_mpeg2_ac_vlc_len [64*64*2]; -/* simple include everything table for dc, first byte is bits number next 3 are code*/ -static uint32_t mpeg1_lum_dc_uni[512]; -static uint32_t mpeg1_chr_dc_uni[512]; - -static uint8_t mpeg1_index_run[2][64]; -static int8_t mpeg1_max_level[2][64]; -#endif //CONFIG_ENCODERS - -static uint8_t static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3]; +uint8_t ff_mpeg12_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3]; static void init_2d_vlc_rl(RLTable *rl, int use_static) { @@ -152,260 +122,7 @@ static void init_2d_vlc_rl(RLTable *rl, int use_static) } } -#ifdef CONFIG_ENCODERS -static void init_uni_ac_vlc(RLTable *rl, uint8_t *uni_ac_vlc_len){ - int i; - - for(i=0; i<128; i++){ - int level= i-64; - int run; - for(run=0; run<64; run++){ - int len, bits, code; - - int alevel= FFABS(level); - int sign= (level>>31)&1; - - if (alevel > rl->max_level[0][run]) - code= 111; /*rl->n*/ - else - code= rl->index_run[0][run] + alevel - 1; - - if (code < 111 /* rl->n */) { - /* store the vlc & sign at once */ - len= rl->table_vlc[code][1]+1; - bits= (rl->table_vlc[code][0]<<1) + sign; - } else { - len= rl->table_vlc[111/*rl->n*/][1]+6; - bits= rl->table_vlc[111/*rl->n*/][0]<<6; - - bits|= run; - if (alevel < 128) { - bits<<=8; len+=8; - bits|= level & 0xff; - } else { - bits<<=16; len+=16; - bits|= level & 0xff; - if (level < 0) { - bits|= 0x8001 + level + 255; - } else { - bits|= level & 0xffff; - } - } - } - - uni_ac_vlc_len [UNI_AC_ENC_INDEX(run, i)]= len; - } - } -} - - -static int find_frame_rate_index(MpegEncContext *s){ - int i; - int64_t dmin= INT64_MAX; - int64_t d; - - for(i=1;i<14;i++) { - int64_t n0= 1001LL/ff_frame_rate_tab[i].den*ff_frame_rate_tab[i].num*s->avctx->time_base.num; - int64_t n1= 1001LL*s->avctx->time_base.den; - if(s->avctx->strict_std_compliance > FF_COMPLIANCE_INOFFICIAL && i>=9) break; - - d = FFABS(n0 - n1); - if(d < dmin){ - dmin=d; - s->frame_rate_index= i; - } - } - if(dmin) - return -1; - else - return 0; -} - -static int encode_init(AVCodecContext *avctx) -{ - MpegEncContext *s = avctx->priv_data; - - if(MPV_encode_init(avctx) < 0) - return -1; - - if(find_frame_rate_index(s) < 0){ - if(s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ - av_log(avctx, AV_LOG_ERROR, "MPEG1/2 does not support %d/%d fps\n", avctx->time_base.den, avctx->time_base.num); - return -1; - }else{ - av_log(avctx, AV_LOG_INFO, "MPEG1/2 does not support %d/%d fps, there may be AV sync issues\n", avctx->time_base.den, avctx->time_base.num); - } - } - - if(avctx->profile == FF_PROFILE_UNKNOWN){ - if(avctx->level != FF_LEVEL_UNKNOWN){ - av_log(avctx, AV_LOG_ERROR, "Set profile and level\n"); - return -1; - } - avctx->profile = s->chroma_format == CHROMA_420 ? 4 : 0; /* Main or 4:2:2 */ - } - - if(avctx->level == FF_LEVEL_UNKNOWN){ - if(avctx->profile == 0){ /* 4:2:2 */ - if(avctx->width <= 720 && avctx->height <= 608) avctx->level = 5; /* Main */ - else avctx->level = 2; /* High */ - }else{ - if(avctx->profile != 1 && s->chroma_format != CHROMA_420){ - av_log(avctx, AV_LOG_ERROR, "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n"); - return -1; - } - if(avctx->width <= 720 && avctx->height <= 576) avctx->level = 8; /* Main */ - else if(avctx->width <= 1440) avctx->level = 6; /* High 1440 */ - else avctx->level = 4; /* High */ - } - } - - if((avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) && s->frame_rate_index != 4){ - av_log(avctx, AV_LOG_ERROR, "Drop frame time code only allowed with 1001/30000 fps\n"); - return -1; - } - - return 0; -} - -static void put_header(MpegEncContext *s, int header) -{ - align_put_bits(&s->pb); - put_bits(&s->pb, 16, header>>16); - put_bits(&s->pb, 16, header&0xFFFF); -} - -/* put sequence header if needed */ -static void mpeg1_encode_sequence_header(MpegEncContext *s) -{ - unsigned int vbv_buffer_size; - unsigned int fps, v; - int i; - uint64_t time_code; - float best_aspect_error= 1E10; - float aspect_ratio= av_q2d(s->avctx->sample_aspect_ratio); - int constraint_parameter_flag; - - if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA) - - if (s->current_picture.key_frame) { - AVRational framerate= ff_frame_rate_tab[s->frame_rate_index]; - - /* mpeg1 header repeated every gop */ - put_header(s, SEQ_START_CODE); - - put_bits(&s->pb, 12, s->width); - put_bits(&s->pb, 12, s->height); - - for(i=1; i<15; i++){ - float error= aspect_ratio; - if(s->codec_id == CODEC_ID_MPEG1VIDEO || i <=1) - error-= 1.0/mpeg1_aspect[i]; - else - error-= av_q2d(mpeg2_aspect[i])*s->height/s->width; - - error= FFABS(error); - - if(error < best_aspect_error){ - best_aspect_error= error; - s->aspect_ratio_info= i; - } - } - - put_bits(&s->pb, 4, s->aspect_ratio_info); - put_bits(&s->pb, 4, s->frame_rate_index); - - if(s->avctx->rc_max_rate){ - v = (s->avctx->rc_max_rate + 399) / 400; - if (v > 0x3ffff && s->codec_id == CODEC_ID_MPEG1VIDEO) - v = 0x3ffff; - }else{ - v= 0x3FFFF; - } - - if(s->avctx->rc_buffer_size) - vbv_buffer_size = s->avctx->rc_buffer_size; - else - /* VBV calculation: Scaled so that a VCD has the proper VBV size of 40 kilobytes */ - vbv_buffer_size = (( 20 * s->bit_rate) / (1151929 / 2)) * 8 * 1024; - vbv_buffer_size= (vbv_buffer_size + 16383) / 16384; - - put_bits(&s->pb, 18, v & 0x3FFFF); - put_bits(&s->pb, 1, 1); /* marker */ - put_bits(&s->pb, 10, vbv_buffer_size & 0x3FF); - - constraint_parameter_flag= - s->width <= 768 && s->height <= 576 && - s->mb_width * s->mb_height <= 396 && - s->mb_width * s->mb_height * framerate.num <= framerate.den*396*25 && - framerate.num <= framerate.den*30 && - s->avctx->me_range && s->avctx->me_range < 128 && - vbv_buffer_size <= 20 && - v <= 1856000/400 && - s->codec_id == CODEC_ID_MPEG1VIDEO; - - put_bits(&s->pb, 1, constraint_parameter_flag); - - ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix); - ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix); - - if(s->codec_id == CODEC_ID_MPEG2VIDEO){ - put_header(s, EXT_START_CODE); - put_bits(&s->pb, 4, 1); //seq ext - - put_bits(&s->pb, 1, s->avctx->profile == 0); //escx 1 for 4:2:2 profile */ - - put_bits(&s->pb, 3, s->avctx->profile); //profile - put_bits(&s->pb, 4, s->avctx->level); //level - - put_bits(&s->pb, 1, s->progressive_sequence); - put_bits(&s->pb, 2, s->chroma_format); - put_bits(&s->pb, 2, 0); //horizontal size ext - put_bits(&s->pb, 2, 0); //vertical size ext - put_bits(&s->pb, 12, v>>18); //bitrate ext - put_bits(&s->pb, 1, 1); //marker - put_bits(&s->pb, 8, vbv_buffer_size >>10); //vbv buffer ext - put_bits(&s->pb, 1, s->low_delay); - put_bits(&s->pb, 2, 0); // frame_rate_ext_n - put_bits(&s->pb, 5, 0); // frame_rate_ext_d - } - - put_header(s, GOP_START_CODE); - put_bits(&s->pb, 1, !!(s->avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE)); /* drop frame flag */ - /* time code : we must convert from the real frame rate to a - fake mpeg frame rate in case of low frame rate */ - fps = (framerate.num + framerate.den/2)/ framerate.den; - time_code = s->current_picture_ptr->coded_picture_number + s->avctx->timecode_frame_start; - - s->gop_picture_number = s->current_picture_ptr->coded_picture_number; - if (s->avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) { - /* only works for NTSC 29.97 */ - int d = time_code / 17982; - int m = time_code % 17982; - //if (m < 2) m += 2; /* not needed since -2,-1 / 1798 in C returns 0 */ - time_code += 18 * d + 2 * ((m - 2) / 1798); - } - put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24)); - put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60)); - put_bits(&s->pb, 1, 1); - put_bits(&s->pb, 6, (uint32_t)((time_code / fps) % 60)); - put_bits(&s->pb, 6, (uint32_t)((time_code % fps))); - put_bits(&s->pb, 1, !!(s->flags & CODEC_FLAG_CLOSED_GOP)); - put_bits(&s->pb, 1, 0); /* broken link */ - } -} - -static inline void encode_mb_skip_run(MpegEncContext *s, int run){ - while (run >= 33) { - put_bits(&s->pb, 11, 0x008); - run -= 33; - } - put_bits(&s->pb, mbAddrIncrTable[run][1], - mbAddrIncrTable[run][0]); -} -#endif //CONFIG_ENCODERS - -static void common_init(MpegEncContext *s) +void ff_mpeg12_common_init(MpegEncContext *s) { s->y_dc_scale_table= @@ -420,621 +137,6 @@ void ff_mpeg1_clean_buffers(MpegEncContext *s){ memset(s->last_mv, 0, sizeof(s->last_mv)); } -#ifdef CONFIG_ENCODERS - -static av_always_inline void put_qscale(MpegEncContext *s) -{ - if(s->q_scale_type){ - assert(s->qscale>=1 && s->qscale <=12); - put_bits(&s->pb, 5, inv_non_linear_qscale[s->qscale]); - }else{ - put_bits(&s->pb, 5, s->qscale); - } -} - -void ff_mpeg1_encode_slice_header(MpegEncContext *s){ - put_header(s, SLICE_MIN_START_CODE + s->mb_y); - put_qscale(s); - put_bits(&s->pb, 1, 0); /* slice extra information */ -} - -void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number) -{ - mpeg1_encode_sequence_header(s); - - /* mpeg1 picture header */ - put_header(s, PICTURE_START_CODE); - /* temporal reference */ - - // RAL: s->picture_number instead of s->fake_picture_number - put_bits(&s->pb, 10, (s->picture_number - - s->gop_picture_number) & 0x3ff); - put_bits(&s->pb, 3, s->pict_type); - - s->vbv_delay_ptr= s->pb.buf + put_bits_count(&s->pb)/8; - put_bits(&s->pb, 16, 0xFFFF); /* vbv_delay */ - - // RAL: Forward f_code also needed for B frames - if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) { - put_bits(&s->pb, 1, 0); /* half pel coordinates */ - if(s->codec_id == CODEC_ID_MPEG1VIDEO) - put_bits(&s->pb, 3, s->f_code); /* forward_f_code */ - else - put_bits(&s->pb, 3, 7); /* forward_f_code */ - } - - // RAL: Backward f_code necessary for B frames - if (s->pict_type == B_TYPE) { - put_bits(&s->pb, 1, 0); /* half pel coordinates */ - if(s->codec_id == CODEC_ID_MPEG1VIDEO) - put_bits(&s->pb, 3, s->b_code); /* backward_f_code */ - else - put_bits(&s->pb, 3, 7); /* backward_f_code */ - } - - put_bits(&s->pb, 1, 0); /* extra bit picture */ - - s->frame_pred_frame_dct = 1; - if(s->codec_id == CODEC_ID_MPEG2VIDEO){ - put_header(s, EXT_START_CODE); - put_bits(&s->pb, 4, 8); //pic ext - if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) { - put_bits(&s->pb, 4, s->f_code); - put_bits(&s->pb, 4, s->f_code); - }else{ - put_bits(&s->pb, 8, 255); - } - if (s->pict_type == B_TYPE) { - put_bits(&s->pb, 4, s->b_code); - put_bits(&s->pb, 4, s->b_code); - }else{ - put_bits(&s->pb, 8, 255); - } - put_bits(&s->pb, 2, s->intra_dc_precision); - - assert(s->picture_structure == PICT_FRAME); - put_bits(&s->pb, 2, s->picture_structure); - if (s->progressive_sequence) { - put_bits(&s->pb, 1, 0); /* no repeat */ - } else { - put_bits(&s->pb, 1, s->current_picture_ptr->top_field_first); - } - /* XXX: optimize the generation of this flag with entropy - measures */ - s->frame_pred_frame_dct = s->progressive_sequence; - - put_bits(&s->pb, 1, s->frame_pred_frame_dct); - put_bits(&s->pb, 1, s->concealment_motion_vectors); - put_bits(&s->pb, 1, s->q_scale_type); - put_bits(&s->pb, 1, s->intra_vlc_format); - put_bits(&s->pb, 1, s->alternate_scan); - put_bits(&s->pb, 1, s->repeat_first_field); - s->progressive_frame = s->progressive_sequence; - put_bits(&s->pb, 1, s->chroma_format == CHROMA_420 ? s->progressive_frame : 0); /* chroma_420_type */ - put_bits(&s->pb, 1, s->progressive_frame); - put_bits(&s->pb, 1, 0); //composite_display_flag - } - if(s->flags & CODEC_FLAG_SVCD_SCAN_OFFSET){ - int i; - - put_header(s, USER_START_CODE); - for(i=0; ipb, 8, svcd_scan_offset_placeholder[i]); - } - } - - s->mb_y=0; - ff_mpeg1_encode_slice_header(s); -} - -static inline void put_mb_modes(MpegEncContext *s, int n, int bits, - int has_mv, int field_motion) -{ - put_bits(&s->pb, n, bits); - if (!s->frame_pred_frame_dct) { - if (has_mv) - put_bits(&s->pb, 2, 2 - field_motion); /* motion_type: frame/field */ - put_bits(&s->pb, 1, s->interlaced_dct); - } -} - -static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s, - DCTELEM block[6][64], - int motion_x, int motion_y, - int mb_block_count) -{ - int i, cbp; - const int mb_x = s->mb_x; - const int mb_y = s->mb_y; - const int first_mb= mb_x == s->resync_mb_x && mb_y == s->resync_mb_y; - - /* compute cbp */ - cbp = 0; - for(i=0;iblock_last_index[i] >= 0) - cbp |= 1 << (mb_block_count - 1 - i); - } - - if (cbp == 0 && !first_mb && s->mv_type == MV_TYPE_16X16 && - (mb_x != s->mb_width - 1 || (mb_y != s->mb_height - 1 && s->codec_id == CODEC_ID_MPEG1VIDEO)) && - ((s->pict_type == P_TYPE && (motion_x | motion_y) == 0) || - (s->pict_type == B_TYPE && s->mv_dir == s->last_mv_dir && (((s->mv_dir & MV_DIR_FORWARD) ? ((s->mv[0][0][0] - s->last_mv[0][0][0])|(s->mv[0][0][1] - s->last_mv[0][0][1])) : 0) | - ((s->mv_dir & MV_DIR_BACKWARD) ? ((s->mv[1][0][0] - s->last_mv[1][0][0])|(s->mv[1][0][1] - s->last_mv[1][0][1])) : 0)) == 0))) { - s->mb_skip_run++; - s->qscale -= s->dquant; - s->skip_count++; - s->misc_bits++; - s->last_bits++; - if(s->pict_type == P_TYPE){ - s->last_mv[0][1][0]= s->last_mv[0][0][0]= - s->last_mv[0][1][1]= s->last_mv[0][0][1]= 0; - } - } else { - if(first_mb){ - assert(s->mb_skip_run == 0); - encode_mb_skip_run(s, s->mb_x); - }else{ - encode_mb_skip_run(s, s->mb_skip_run); - } - - if (s->pict_type == I_TYPE) { - if(s->dquant && cbp){ - put_mb_modes(s, 2, 1, 0, 0); /* macroblock_type : macroblock_quant = 1 */ - put_qscale(s); - }else{ - put_mb_modes(s, 1, 1, 0, 0); /* macroblock_type : macroblock_quant = 0 */ - s->qscale -= s->dquant; - } - s->misc_bits+= get_bits_diff(s); - s->i_count++; - } else if (s->mb_intra) { - if(s->dquant && cbp){ - put_mb_modes(s, 6, 0x01, 0, 0); - put_qscale(s); - }else{ - put_mb_modes(s, 5, 0x03, 0, 0); - s->qscale -= s->dquant; - } - s->misc_bits+= get_bits_diff(s); - s->i_count++; - memset(s->last_mv, 0, sizeof(s->last_mv)); - } else if (s->pict_type == P_TYPE) { - if(s->mv_type == MV_TYPE_16X16){ - if (cbp != 0) { - if ((motion_x|motion_y) == 0) { - if(s->dquant){ - put_mb_modes(s, 5, 1, 0, 0); /* macroblock_pattern & quant */ - put_qscale(s); - }else{ - put_mb_modes(s, 2, 1, 0, 0); /* macroblock_pattern only */ - } - s->misc_bits+= get_bits_diff(s); - } else { - if(s->dquant){ - put_mb_modes(s, 5, 2, 1, 0); /* motion + cbp */ - put_qscale(s); - }else{ - put_mb_modes(s, 1, 1, 1, 0); /* motion + cbp */ - } - s->misc_bits+= get_bits_diff(s); - mpeg1_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code); // RAL: f_code parameter added - mpeg1_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code); // RAL: f_code parameter added - s->mv_bits+= get_bits_diff(s); - } - } else { - put_bits(&s->pb, 3, 1); /* motion only */ - if (!s->frame_pred_frame_dct) - put_bits(&s->pb, 2, 2); /* motion_type: frame */ - s->misc_bits+= get_bits_diff(s); - mpeg1_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code); // RAL: f_code parameter added - mpeg1_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code); // RAL: f_code parameter added - s->qscale -= s->dquant; - s->mv_bits+= get_bits_diff(s); - } - s->last_mv[0][1][0]= s->last_mv[0][0][0]= motion_x; - s->last_mv[0][1][1]= s->last_mv[0][0][1]= motion_y; - }else{ - assert(!s->frame_pred_frame_dct && s->mv_type == MV_TYPE_FIELD); - - if (cbp) { - if(s->dquant){ - put_mb_modes(s, 5, 2, 1, 1); /* motion + cbp */ - put_qscale(s); - }else{ - put_mb_modes(s, 1, 1, 1, 1); /* motion + cbp */ - } - } else { - put_bits(&s->pb, 3, 1); /* motion only */ - put_bits(&s->pb, 2, 1); /* motion_type: field */ - s->qscale -= s->dquant; - } - s->misc_bits+= get_bits_diff(s); - for(i=0; i<2; i++){ - put_bits(&s->pb, 1, s->field_select[0][i]); - mpeg1_encode_motion(s, s->mv[0][i][0] - s->last_mv[0][i][0] , s->f_code); - mpeg1_encode_motion(s, s->mv[0][i][1] - (s->last_mv[0][i][1]>>1), s->f_code); - s->last_mv[0][i][0]= s->mv[0][i][0]; - s->last_mv[0][i][1]= 2*s->mv[0][i][1]; - } - s->mv_bits+= get_bits_diff(s); - } - if(cbp) { - if (s->chroma_y_shift) { - put_bits(&s->pb, mbPatTable[cbp][1], mbPatTable[cbp][0]); - } else { - put_bits(&s->pb, mbPatTable[cbp>>2][1], mbPatTable[cbp>>2][0]); - put_bits(&s->pb, 2, cbp & 3); - } - } - s->f_count++; - } else{ - static const int mb_type_len[4]={0,3,4,2}; //bak,for,bi - - if(s->mv_type == MV_TYPE_16X16){ - if (cbp){ // With coded bloc pattern - if (s->dquant) { - if(s->mv_dir == MV_DIR_FORWARD) - put_mb_modes(s, 6, 3, 1, 0); - else - put_mb_modes(s, mb_type_len[s->mv_dir]+3, 2, 1, 0); - put_qscale(s); - } else { - put_mb_modes(s, mb_type_len[s->mv_dir], 3, 1, 0); - } - }else{ // No coded bloc pattern - put_bits(&s->pb, mb_type_len[s->mv_dir], 2); - if (!s->frame_pred_frame_dct) - put_bits(&s->pb, 2, 2); /* motion_type: frame */ - s->qscale -= s->dquant; - } - s->misc_bits += get_bits_diff(s); - if (s->mv_dir&MV_DIR_FORWARD){ - mpeg1_encode_motion(s, s->mv[0][0][0] - s->last_mv[0][0][0], s->f_code); - mpeg1_encode_motion(s, s->mv[0][0][1] - s->last_mv[0][0][1], s->f_code); - s->last_mv[0][0][0]=s->last_mv[0][1][0]= s->mv[0][0][0]; - s->last_mv[0][0][1]=s->last_mv[0][1][1]= s->mv[0][0][1]; - s->f_count++; - } - if (s->mv_dir&MV_DIR_BACKWARD){ - mpeg1_encode_motion(s, s->mv[1][0][0] - s->last_mv[1][0][0], s->b_code); - mpeg1_encode_motion(s, s->mv[1][0][1] - s->last_mv[1][0][1], s->b_code); - s->last_mv[1][0][0]=s->last_mv[1][1][0]= s->mv[1][0][0]; - s->last_mv[1][0][1]=s->last_mv[1][1][1]= s->mv[1][0][1]; - s->b_count++; - } - }else{ - assert(s->mv_type == MV_TYPE_FIELD); - assert(!s->frame_pred_frame_dct); - if (cbp){ // With coded bloc pattern - if (s->dquant) { - if(s->mv_dir == MV_DIR_FORWARD) - put_mb_modes(s, 6, 3, 1, 1); - else - put_mb_modes(s, mb_type_len[s->mv_dir]+3, 2, 1, 1); - put_qscale(s); - } else { - put_mb_modes(s, mb_type_len[s->mv_dir], 3, 1, 1); - } - }else{ // No coded bloc pattern - put_bits(&s->pb, mb_type_len[s->mv_dir], 2); - put_bits(&s->pb, 2, 1); /* motion_type: field */ - s->qscale -= s->dquant; - } - s->misc_bits += get_bits_diff(s); - if (s->mv_dir&MV_DIR_FORWARD){ - for(i=0; i<2; i++){ - put_bits(&s->pb, 1, s->field_select[0][i]); - mpeg1_encode_motion(s, s->mv[0][i][0] - s->last_mv[0][i][0] , s->f_code); - mpeg1_encode_motion(s, s->mv[0][i][1] - (s->last_mv[0][i][1]>>1), s->f_code); - s->last_mv[0][i][0]= s->mv[0][i][0]; - s->last_mv[0][i][1]= 2*s->mv[0][i][1]; - } - s->f_count++; - } - if (s->mv_dir&MV_DIR_BACKWARD){ - for(i=0; i<2; i++){ - put_bits(&s->pb, 1, s->field_select[1][i]); - mpeg1_encode_motion(s, s->mv[1][i][0] - s->last_mv[1][i][0] , s->b_code); - mpeg1_encode_motion(s, s->mv[1][i][1] - (s->last_mv[1][i][1]>>1), s->b_code); - s->last_mv[1][i][0]= s->mv[1][i][0]; - s->last_mv[1][i][1]= 2*s->mv[1][i][1]; - } - s->b_count++; - } - } - s->mv_bits += get_bits_diff(s); - if(cbp) { - if (s->chroma_y_shift) { - put_bits(&s->pb, mbPatTable[cbp][1], mbPatTable[cbp][0]); - } else { - put_bits(&s->pb, mbPatTable[cbp>>2][1], mbPatTable[cbp>>2][0]); - put_bits(&s->pb, 2, cbp & 3); - } - } - } - for(i=0;imb_skip_run = 0; - if(s->mb_intra) - s->i_tex_bits+= get_bits_diff(s); - else - s->p_tex_bits+= get_bits_diff(s); - } -} - -void mpeg1_encode_mb(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y) -{ - if (s->chroma_format == CHROMA_420) mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 6); - else mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 8); -} - -// RAL: Parameter added: f_or_b_code -static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code) -{ - int code, bit_size, l, bits, range, sign; - - if (val == 0) { - /* zero vector */ - code = 0; - put_bits(&s->pb, - mbMotionVectorTable[0][1], - mbMotionVectorTable[0][0]); - } else { - bit_size = f_or_b_code - 1; - range = 1 << bit_size; - /* modulo encoding */ - l= INT_BIT - 5 - bit_size; - val= (val<>l; - - if (val >= 0) { - val--; - code = (val >> bit_size) + 1; - bits = val & (range - 1); - sign = 0; - } else { - val = -val; - val--; - code = (val >> bit_size) + 1; - bits = val & (range - 1); - sign = 1; - } - - assert(code > 0 && code <= 16); - - put_bits(&s->pb, - mbMotionVectorTable[code][1], - mbMotionVectorTable[code][0]); - - put_bits(&s->pb, 1, sign); - if (bit_size > 0) { - put_bits(&s->pb, bit_size, bits); - } - } -} - -void ff_mpeg1_encode_init(MpegEncContext *s) -{ - static int done=0; - - common_init(s); - - if(!done){ - int f_code; - int mv; - int i; - - done=1; - init_rl(&rl_mpeg1, static_rl_table_store[0]); - init_rl(&rl_mpeg2, static_rl_table_store[1]); - - for(i=0; i<64; i++) - { - mpeg1_max_level[0][i]= rl_mpeg1.max_level[0][i]; - mpeg1_index_run[0][i]= rl_mpeg1.index_run[0][i]; - } - - init_uni_ac_vlc(&rl_mpeg1, uni_mpeg1_ac_vlc_len); - if(s->intra_vlc_format) - init_uni_ac_vlc(&rl_mpeg2, uni_mpeg2_ac_vlc_len); - - /* build unified dc encoding tables */ - for(i=-255; i<256; i++) - { - int adiff, index; - int bits, code; - int diff=i; - - adiff = FFABS(diff); - if(diff<0) diff--; - index = av_log2(2*adiff); - - bits= vlc_dc_lum_bits[index] + index; - code= (vlc_dc_lum_code[index]<> bit_size) + 1; - if(code<17){ - len= mbMotionVectorTable[code][1] + 1 + bit_size; - }else{ - len= mbMotionVectorTable[16][1] + 2 + bit_size; - } - } - - mv_penalty[f_code][mv+MAX_MV]= len; - } - } - - - for(f_code=MAX_FCODE; f_code>0; f_code--){ - for(mv=-(8<me.mv_penalty= mv_penalty; - s->fcode_tab= fcode_tab; - if(s->codec_id == CODEC_ID_MPEG1VIDEO){ - s->min_qcoeff=-255; - s->max_qcoeff= 255; - }else{ - s->min_qcoeff=-2047; - s->max_qcoeff= 2047; - } - if (s->intra_vlc_format) { - s->intra_ac_vlc_length= - s->intra_ac_vlc_last_length= uni_mpeg2_ac_vlc_len; - } else { - s->intra_ac_vlc_length= - s->intra_ac_vlc_last_length= uni_mpeg1_ac_vlc_len; - } - s->inter_ac_vlc_length= - s->inter_ac_vlc_last_length= uni_mpeg1_ac_vlc_len; -} - -static inline void encode_dc(MpegEncContext *s, int diff, int component) -{ - if(((unsigned) (diff+255)) >= 511){ - int index; - - if(diff<0){ - index= av_log2_16bit(-2*diff); - diff--; - }else{ - index= av_log2_16bit(2*diff); - } - if (component == 0) { - put_bits( - &s->pb, - vlc_dc_lum_bits[index] + index, - (vlc_dc_lum_code[index]<pb, - vlc_dc_chroma_bits[index] + index, - (vlc_dc_chroma_code[index]<pb, - mpeg1_lum_dc_uni[diff+255]&0xFF, - mpeg1_lum_dc_uni[diff+255]>>8); - } else { - put_bits( - &s->pb, - mpeg1_chr_dc_uni[diff+255]&0xFF, - mpeg1_chr_dc_uni[diff+255]>>8); - } - } -} - -static void mpeg1_encode_block(MpegEncContext *s, - DCTELEM *block, - int n) -{ - int alevel, level, last_non_zero, dc, diff, i, j, run, last_index, sign; - int code, component; - const uint16_t (*table_vlc)[2] = rl_mpeg1.table_vlc; - - last_index = s->block_last_index[n]; - - /* DC coef */ - if (s->mb_intra) { - component = (n <= 3 ? 0 : (n&1) + 1); - dc = block[0]; /* overflow is impossible */ - diff = dc - s->last_dc[component]; - encode_dc(s, diff, component); - s->last_dc[component] = dc; - i = 1; - if (s->intra_vlc_format) - table_vlc = rl_mpeg2.table_vlc; - } else { - /* encode the first coefficient : needs to be done here because - it is handled slightly differently */ - level = block[0]; - if (abs(level) == 1) { - code = ((uint32_t)level >> 31); /* the sign bit */ - put_bits(&s->pb, 2, code | 0x02); - i = 1; - } else { - i = 0; - last_non_zero = -1; - goto next_coef; - } - } - - /* now quantify & encode AC coefs */ - last_non_zero = i - 1; - - for(;i<=last_index;i++) { - j = s->intra_scantable.permutated[i]; - level = block[j]; - next_coef: -#if 0 - if (level != 0) - dprintf(s->avctx, "level[%d]=%d\n", i, level); -#endif - /* encode using VLC */ - if (level != 0) { - run = i - last_non_zero - 1; - - alevel= level; - MASK_ABS(sign, alevel) - sign&=1; - - if (alevel <= mpeg1_max_level[0][run]){ - code= mpeg1_index_run[0][run] + alevel - 1; - /* store the vlc & sign at once */ - put_bits(&s->pb, table_vlc[code][1]+1, (table_vlc[code][0]<<1) + sign); - } else { - /* escape seems to be pretty rare <5% so i dont optimize it */ - put_bits(&s->pb, table_vlc[111][1], table_vlc[111][0]); - /* escape: only clip in this case */ - put_bits(&s->pb, 6, run); - if(s->codec_id == CODEC_ID_MPEG1VIDEO){ - if (alevel < 128) { - put_bits(&s->pb, 8, level & 0xff); - } else { - if (level < 0) { - put_bits(&s->pb, 16, 0x8001 + level + 255); - } else { - put_bits(&s->pb, 16, level & 0xffff); - } - } - }else{ - put_bits(&s->pb, 12, level & 0xfff); - } - } - last_non_zero = i; - } - } - /* end of block */ - put_bits(&s->pb, table_vlc[112][1], table_vlc[112][0]); -} -#endif //CONFIG_ENCODERS /******************************************/ /* decoding */ @@ -1055,20 +157,20 @@ static void init_vlcs(void) done = 1; init_vlc(&dc_lum_vlc, DC_VLC_BITS, 12, - vlc_dc_lum_bits, 1, 1, - vlc_dc_lum_code, 2, 2, 1); + ff_mpeg12_vlc_dc_lum_bits, 1, 1, + ff_mpeg12_vlc_dc_lum_code, 2, 2, 1); init_vlc(&dc_chroma_vlc, DC_VLC_BITS, 12, - vlc_dc_chroma_bits, 1, 1, - vlc_dc_chroma_code, 2, 2, 1); + ff_mpeg12_vlc_dc_chroma_bits, 1, 1, + ff_mpeg12_vlc_dc_chroma_code, 2, 2, 1); init_vlc(&mv_vlc, MV_VLC_BITS, 17, - &mbMotionVectorTable[0][1], 2, 1, - &mbMotionVectorTable[0][0], 2, 1, 1); + &ff_mpeg12_mbMotionVectorTable[0][1], 2, 1, + &ff_mpeg12_mbMotionVectorTable[0][0], 2, 1, 1); init_vlc(&mbincr_vlc, MBINCR_VLC_BITS, 36, - &mbAddrIncrTable[0][1], 2, 1, - &mbAddrIncrTable[0][0], 2, 1, 1); + &ff_mpeg12_mbAddrIncrTable[0][1], 2, 1, + &ff_mpeg12_mbAddrIncrTable[0][0], 2, 1, 1); init_vlc(&mb_pat_vlc, MB_PAT_VLC_BITS, 64, - &mbPatTable[0][1], 2, 1, - &mbPatTable[0][0], 2, 1, 1); + &ff_mpeg12_mbPatTable[0][1], 2, 1, + &ff_mpeg12_mbPatTable[0][0], 2, 1, 1); init_vlc(&mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7, &table_mb_ptype[0][1], 2, 1, @@ -1076,11 +178,11 @@ static void init_vlcs(void) init_vlc(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 11, &table_mb_btype[0][1], 2, 1, &table_mb_btype[0][0], 2, 1, 1); - init_rl(&rl_mpeg1, static_rl_table_store[0]); - init_rl(&rl_mpeg2, static_rl_table_store[1]); + init_rl(&ff_rl_mpeg1, ff_mpeg12_static_rl_table_store[0]); + init_rl(&ff_rl_mpeg2, ff_mpeg12_static_rl_table_store[1]); - init_2d_vlc_rl(&rl_mpeg1, 1); - init_2d_vlc_rl(&rl_mpeg2, 1); + init_2d_vlc_rl(&ff_rl_mpeg1, 1); + init_2d_vlc_rl(&ff_rl_mpeg2, 1); } } @@ -1119,26 +221,7 @@ static int mpeg_decode_mb(MpegEncContext *s, assert(s->mb_skipped==0); if (s->mb_skip_run-- != 0) { - if(s->pict_type == I_TYPE){ - av_log(s->avctx, AV_LOG_ERROR, "skipped MB in I frame at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - - /* skip mb */ - s->mb_intra = 0; - for(i=0;i<12;i++) - s->block_last_index[i] = -1; - if(s->picture_structure == PICT_FRAME) - s->mv_type = MV_TYPE_16X16; - else - s->mv_type = MV_TYPE_FIELD; if (s->pict_type == P_TYPE) { - /* if P type, zero motion vector is implied */ - s->mv_dir = MV_DIR_FORWARD; - s->mv[0][0][0] = s->mv[0][0][1] = 0; - s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0; - s->last_mv[0][1][0] = s->last_mv[0][1][1] = 0; - s->field_select[0][0]= s->picture_structure - 1; s->mb_skipped = 1; s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16; } else { @@ -1151,12 +234,6 @@ static int mpeg_decode_mb(MpegEncContext *s, if(IS_INTRA(mb_type)) return -1; - /* if B type, reuse previous vectors and directions */ - s->mv[0][0][0] = s->last_mv[0][0][0]; - s->mv[0][0][1] = s->last_mv[0][0][1]; - s->mv[1][0][0] = s->last_mv[1][0][0]; - s->mv[1][0][1] = s->last_mv[1][0][1]; - s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= mb_type | MB_TYPE_SKIP; // assert(s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1]&(MB_TYPE_16x16|MB_TYPE_16x8)); @@ -1261,23 +338,20 @@ static int mpeg_decode_mb(MpegEncContext *s, if (mb_type & MB_TYPE_ZERO_MV){ assert(mb_type & MB_TYPE_CBP); - /* compute dct type */ - if (s->picture_structure == PICT_FRAME && //FIXME add a interlaced_dct coded var? - !s->frame_pred_frame_dct) { - s->interlaced_dct = get_bits1(&s->gb); - } - - if (IS_QUANT(mb_type)) - s->qscale = get_qscale(s); - s->mv_dir = MV_DIR_FORWARD; - if(s->picture_structure == PICT_FRAME) + if(s->picture_structure == PICT_FRAME){ + if(!s->frame_pred_frame_dct) + s->interlaced_dct = get_bits1(&s->gb); s->mv_type = MV_TYPE_16X16; - else{ + }else{ s->mv_type = MV_TYPE_FIELD; mb_type |= MB_TYPE_INTERLACED; s->field_select[0][0]= s->picture_structure - 1; } + + if (IS_QUANT(mb_type)) + s->qscale = get_qscale(s); + s->last_mv[0][0][0] = 0; s->last_mv[0][0][1] = 0; s->last_mv[0][1][0] = 0; @@ -1287,34 +361,29 @@ static int mpeg_decode_mb(MpegEncContext *s, }else{ assert(mb_type & MB_TYPE_L0L1); //FIXME decide if MBs in field pictures are MB_TYPE_INTERLACED - /* get additionnal motion vector type */ + /* get additional motion vector type */ if (s->frame_pred_frame_dct) motion_type = MT_FRAME; else{ motion_type = get_bits(&s->gb, 2); - } - - /* compute dct type */ - if (s->picture_structure == PICT_FRAME && //FIXME add a interlaced_dct coded var? - !s->frame_pred_frame_dct && HAS_CBP(mb_type)) { - s->interlaced_dct = get_bits1(&s->gb); + if (s->picture_structure == PICT_FRAME && HAS_CBP(mb_type)) + s->interlaced_dct = get_bits1(&s->gb); } if (IS_QUANT(mb_type)) s->qscale = get_qscale(s); /* motion vectors */ - s->mv_dir = 0; - for(i=0;i<2;i++) { - if (USES_LIST(mb_type, i)) { - s->mv_dir |= (MV_DIR_FORWARD >> i); - dprintf(s->avctx, "motion_type=%d\n", motion_type); - switch(motion_type) { - case MT_FRAME: /* or MT_16X8 */ - if (s->picture_structure == PICT_FRAME) { + s->mv_dir= (mb_type>>13)&3; + dprintf(s->avctx, "motion_type=%d\n", motion_type); + switch(motion_type) { + case MT_FRAME: /* or MT_16X8 */ + if (s->picture_structure == PICT_FRAME) { + mb_type |= MB_TYPE_16x16; + s->mv_type = MV_TYPE_16X16; + for(i=0;i<2;i++) { + if (USES_LIST(mb_type, i)) { /* MT_FRAME */ - mb_type |= MB_TYPE_16x16; - s->mv_type = MV_TYPE_16X16; s->mv[i][0][0]= s->last_mv[i][0][0]= s->last_mv[i][1][0] = mpeg_decode_motion(s, s->mpeg_f_code[i][0], s->last_mv[i][0][0]); s->mv[i][0][1]= s->last_mv[i][0][1]= s->last_mv[i][1][1] = @@ -1324,10 +393,14 @@ static int mpeg_decode_mb(MpegEncContext *s, s->mv[i][0][0] <<= 1; s->mv[i][0][1] <<= 1; } - } else { + } + } + } else { + mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED; + s->mv_type = MV_TYPE_16X8; + for(i=0;i<2;i++) { + if (USES_LIST(mb_type, i)) { /* MT_16X8 */ - mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED; - s->mv_type = MV_TYPE_16X8; for(j=0;j<2;j++) { s->field_select[i][j] = get_bits1(&s->gb); for(k=0;k<2;k++) { @@ -1338,11 +411,15 @@ static int mpeg_decode_mb(MpegEncContext *s, } } } - break; - case MT_FIELD: - s->mv_type = MV_TYPE_FIELD; - if (s->picture_structure == PICT_FRAME) { - mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED; + } + } + break; + case MT_FIELD: + s->mv_type = MV_TYPE_FIELD; + if (s->picture_structure == PICT_FRAME) { + mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED; + for(i=0;i<2;i++) { + if (USES_LIST(mb_type, i)) { for(j=0;j<2;j++) { s->field_select[i][j] = get_bits1(&s->gb); val = mpeg_decode_motion(s, s->mpeg_f_code[i][0], @@ -1356,8 +433,12 @@ static int mpeg_decode_mb(MpegEncContext *s, s->mv[i][j][1] = val; dprintf(s->avctx, "fmy=%d\n", val); } - } else { - mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED; + } + } + } else { + mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED; + for(i=0;i<2;i++) { + if (USES_LIST(mb_type, i)) { s->field_select[i][0] = get_bits1(&s->gb); for(k=0;k<2;k++) { val = mpeg_decode_motion(s, s->mpeg_f_code[i][k], @@ -1367,59 +448,60 @@ static int mpeg_decode_mb(MpegEncContext *s, s->mv[i][0][k] = val; } } - break; - case MT_DMV: - { - int dmx, dmy, mx, my, m; - - mx = mpeg_decode_motion(s, s->mpeg_f_code[i][0], - s->last_mv[i][0][0]); - s->last_mv[i][0][0] = mx; - s->last_mv[i][1][0] = mx; - dmx = get_dmv(s); - my = mpeg_decode_motion(s, s->mpeg_f_code[i][1], - s->last_mv[i][0][1] >> 1); - dmy = get_dmv(s); - s->mv_type = MV_TYPE_DMV; - - - s->last_mv[i][0][1] = my<<1; - s->last_mv[i][1][1] = my<<1; - - s->mv[i][0][0] = mx; - s->mv[i][0][1] = my; - s->mv[i][1][0] = mx;//not used - s->mv[i][1][1] = my;//not used - - if (s->picture_structure == PICT_FRAME) { - mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED; - - //m = 1 + 2 * s->top_field_first; - m = s->top_field_first ? 1 : 3; - - /* top -> top pred */ - s->mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx; - s->mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1; - m = 4 - m; - s->mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx; - s->mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1; - } else { - mb_type |= MB_TYPE_16x16; - - s->mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx; - s->mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy; - if(s->picture_structure == PICT_TOP_FIELD) - s->mv[i][2][1]--; - else - s->mv[i][2][1]++; - } + } + } + break; + case MT_DMV: + s->mv_type = MV_TYPE_DMV; + for(i=0;i<2;i++) { + if (USES_LIST(mb_type, i)) { + int dmx, dmy, mx, my, m; + mx = mpeg_decode_motion(s, s->mpeg_f_code[i][0], + s->last_mv[i][0][0]); + s->last_mv[i][0][0] = mx; + s->last_mv[i][1][0] = mx; + dmx = get_dmv(s); + my = mpeg_decode_motion(s, s->mpeg_f_code[i][1], + s->last_mv[i][0][1] >> 1); + dmy = get_dmv(s); + + + s->last_mv[i][0][1] = my<<1; + s->last_mv[i][1][1] = my<<1; + + s->mv[i][0][0] = mx; + s->mv[i][0][1] = my; + s->mv[i][1][0] = mx;//not used + s->mv[i][1][1] = my;//not used + + if (s->picture_structure == PICT_FRAME) { + mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED; + + //m = 1 + 2 * s->top_field_first; + m = s->top_field_first ? 1 : 3; + + /* top -> top pred */ + s->mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx; + s->mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1; + m = 4 - m; + s->mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx; + s->mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1; + } else { + mb_type |= MB_TYPE_16x16; + + s->mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx; + s->mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy; + if(s->picture_structure == PICT_TOP_FIELD) + s->mv[i][2][1]--; + else + s->mv[i][2][1]++; } - break; - default: - av_log(s->avctx, AV_LOG_ERROR, "00 motion_type at %d %d\n", s->mb_x, s->mb_y); - return -1; } } + break; + default: + av_log(s->avctx, AV_LOG_ERROR, "00 motion_type at %d %d\n", s->mb_x, s->mb_y); + return -1; } } @@ -1427,18 +509,15 @@ static int mpeg_decode_mb(MpegEncContext *s, if (HAS_CBP(mb_type)) { s->dsp.clear_blocks(s->block[0]); - if(!s->chroma_y_shift){ - s->dsp.clear_blocks(s->block[6]); - } - cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1); - if (cbp < 0 || ((cbp == 0) && (s->chroma_format < 2)) ){ - av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y); - return -1; - } if(mb_block_count > 6){ cbp<<= mb_block_count-6; cbp |= get_bits(&s->gb, mb_block_count-6); + s->dsp.clear_blocks(s->block[6]); + } + if (cbp <= 0){ + av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y); + return -1; } #ifdef HAVE_XVMC @@ -1565,7 +644,7 @@ static inline int mpeg1_decode_block_intra(MpegEncContext *s, { int level, dc, diff, i, j, run; int component; - RLTable *rl = &rl_mpeg1; + RLTable *rl = &ff_rl_mpeg1; uint8_t * const scantable= s->intra_scantable.permutated; const uint16_t *quant_matrix= s->intra_matrix; const int qscale= s->qscale; @@ -1637,7 +716,7 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s, int n) { int level, i, j, run; - RLTable *rl = &rl_mpeg1; + RLTable *rl = &ff_rl_mpeg1; uint8_t * const scantable= s->intra_scantable.permutated; const uint16_t *quant_matrix= s->inter_matrix; const int qscale= s->qscale; @@ -1658,7 +737,9 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s, if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) goto end; } - +#if MIN_CACHE_BITS < 19 + UPDATE_CACHE(re, &s->gb); +#endif /* now quantify & encode AC coefs */ for(;;) { GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); @@ -1698,9 +779,14 @@ static inline int mpeg1_decode_block_inter(MpegEncContext *s, } block[j] = level; +#if MIN_CACHE_BITS < 19 + UPDATE_CACHE(re, &s->gb); +#endif if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) break; +#if MIN_CACHE_BITS >= 19 UPDATE_CACHE(re, &s->gb); +#endif } end: LAST_SKIP_BITS(re, &s->gb, 2); @@ -1713,7 +799,7 @@ end: static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n) { int level, i, j, run; - RLTable *rl = &rl_mpeg1; + RLTable *rl = &ff_rl_mpeg1; uint8_t * const scantable= s->intra_scantable.permutated; const int qscale= s->qscale; @@ -1733,6 +819,9 @@ static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *bloc if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) goto end; } +#if MIN_CACHE_BITS < 19 + UPDATE_CACHE(re, &s->gb); +#endif /* now quantify & encode AC coefs */ for(;;) { @@ -1769,9 +858,14 @@ static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *bloc } block[j] = level; +#if MIN_CACHE_BITS < 19 + UPDATE_CACHE(re, &s->gb); +#endif if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) break; +#if MIN_CACHE_BITS >= 19 UPDATE_CACHE(re, &s->gb); +#endif } end: LAST_SKIP_BITS(re, &s->gb, 2); @@ -1787,7 +881,7 @@ static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, int n) { int level, i, j, run; - RLTable *rl = &rl_mpeg1; + RLTable *rl = &ff_rl_mpeg1; uint8_t * const scantable= s->intra_scantable.permutated; const uint16_t *quant_matrix; const int qscale= s->qscale; @@ -1816,6 +910,9 @@ static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) goto end; } +#if MIN_CACHE_BITS < 19 + UPDATE_CACHE(re, &s->gb); +#endif /* now quantify & encode AC coefs */ for(;;) { @@ -1849,9 +946,14 @@ static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, mismatch ^= level; block[j] = level; +#if MIN_CACHE_BITS < 19 + UPDATE_CACHE(re, &s->gb); +#endif if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) break; +#if MIN_CACHE_BITS >= 19 UPDATE_CACHE(re, &s->gb); +#endif } end: LAST_SKIP_BITS(re, &s->gb, 2); @@ -1868,7 +970,7 @@ static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, int n) { int level, i, j, run; - RLTable *rl = &rl_mpeg1; + RLTable *rl = &ff_rl_mpeg1; uint8_t * const scantable= s->intra_scantable.permutated; const int qscale= s->qscale; OPEN_READER(re, &s->gb); @@ -1886,6 +988,9 @@ static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) goto end; } +#if MIN_CACHE_BITS < 19 + UPDATE_CACHE(re, &s->gb); +#endif /* now quantify & encode AC coefs */ for(;;) { @@ -1914,9 +1019,14 @@ static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, } block[j] = level; +#if MIN_CACHE_BITS < 19 + UPDATE_CACHE(re, &s->gb); +#endif if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) break; +#if MIN_CACHE_BITS >=19 UPDATE_CACHE(re, &s->gb); +#endif } end: LAST_SKIP_BITS(re, &s->gb, 2); @@ -1957,9 +1067,9 @@ static inline int mpeg2_decode_block_intra(MpegEncContext *s, mismatch = block[0] ^ 1; i = 0; if (s->intra_vlc_format) - rl = &rl_mpeg2; + rl = &ff_rl_mpeg2; else - rl = &rl_mpeg1; + rl = &ff_rl_mpeg1; { OPEN_READER(re, &s->gb); @@ -2033,9 +1143,9 @@ static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, s->last_dc[component] = dc; block[0] = dc << (3 - s->intra_dc_precision); if (s->intra_vlc_format) - rl = &rl_mpeg2; + rl = &ff_rl_mpeg2; else - rl = &rl_mpeg1; + rl = &ff_rl_mpeg1; { OPEN_READER(re, &s->gb); @@ -2084,6 +1194,7 @@ typedef struct Mpeg1Context { int slice_count; int swap_uv;//indicate VCR2 int save_aspect_info; + int save_width, save_height; AVRational frame_rate_ext; ///< MPEG-2 specific framerate modificator } Mpeg1Context; @@ -2105,7 +1216,7 @@ static int mpeg_decode_init(AVCodecContext *avctx) s->mpeg_enc_ctx.avctx= avctx; s->mpeg_enc_ctx.flags= avctx->flags; s->mpeg_enc_ctx.flags2= avctx->flags2; - common_init(&s->mpeg_enc_ctx); + ff_mpeg12_common_init(&s->mpeg_enc_ctx); init_vlcs(); s->mpeg_enc_ctx_allocated = 0; @@ -2138,6 +1249,8 @@ static int mpeg_decode_postinit(AVCodecContext *avctx){ (s1->mpeg_enc_ctx_allocated == 0)|| avctx->coded_width != s->width || avctx->coded_height != s->height|| + s1->save_width != s->width || + s1->save_height != s->height || s1->save_aspect_info != s->aspect_ratio_info|| 0) { @@ -2155,6 +1268,8 @@ static int mpeg_decode_postinit(AVCodecContext *avctx){ avcodec_set_dimensions(avctx, s->width, s->height); avctx->bit_rate = s->bit_rate; s1->save_aspect_info = s->aspect_ratio_info; + s1->save_width = s->width; + s1->save_height = s->height; //low_delay may be forced, in this case we will have B frames //that behave like P frames @@ -2166,7 +1281,7 @@ static int mpeg_decode_postinit(AVCodecContext *avctx){ avctx->time_base.num= ff_frame_rate_tab[s->frame_rate_index].den; //mpeg1 aspect avctx->sample_aspect_ratio= av_d2q( - 1.0/mpeg1_aspect[s->aspect_ratio_info], 255); + 1.0/ff_mpeg1_aspect[s->aspect_ratio_info], 255); }else{//mpeg2 //mpeg2 fps @@ -2181,19 +1296,19 @@ static int mpeg_decode_postinit(AVCodecContext *avctx){ if( (s1->pan_scan.width == 0 )||(s1->pan_scan.height == 0) ){ s->avctx->sample_aspect_ratio= av_div_q( - mpeg2_aspect[s->aspect_ratio_info], + ff_mpeg2_aspect[s->aspect_ratio_info], (AVRational){s->width, s->height} ); }else{ s->avctx->sample_aspect_ratio= av_div_q( - mpeg2_aspect[s->aspect_ratio_info], + ff_mpeg2_aspect[s->aspect_ratio_info], (AVRational){s1->pan_scan.width, s1->pan_scan.height} ); } }else{ s->avctx->sample_aspect_ratio= - mpeg2_aspect[s->aspect_ratio_info]; + ff_mpeg2_aspect[s->aspect_ratio_info]; } }//mpeg2 @@ -2556,7 +1671,6 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, { MpegEncContext *s = &s1->mpeg_enc_ctx; AVCodecContext *avctx= s->avctx; - int ret; const int field_pic= s->picture_structure != PICT_FRAME; const int lowres= s->avctx->lowres; @@ -2631,11 +1745,7 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, XVMC_init_block(s);//set s->block #endif - ret = mpeg_decode_mb(s, s->block); - s->chroma_qscale= s->qscale; - - dprintf(s->avctx, "ret=%d\n", ret); - if (ret < 0) + if(mpeg_decode_mb(s, s->block) < 0) return -1; if(s->current_picture.motion_val[0] && !s->encoding){ //note motion_val is normally NULL unless we want to extract the MVs @@ -2670,8 +1780,8 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, } s->dest[0] += 16 >> lowres; - s->dest[1] += 16 >> (s->chroma_x_shift + lowres); - s->dest[2] += 16 >> (s->chroma_x_shift + lowres); + s->dest[1] +=(16 >> lowres) >> s->chroma_x_shift; + s->dest[2] +=(16 >> lowres) >> s->chroma_x_shift; MPV_decode_mb(s, s->block); @@ -2726,10 +1836,40 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, break; } } + if(s->mb_skip_run){ + int i; + if(s->pict_type == I_TYPE){ + av_log(s->avctx, AV_LOG_ERROR, "skipped MB in I frame at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + + /* skip mb */ + s->mb_intra = 0; + for(i=0;i<12;i++) + s->block_last_index[i] = -1; + if(s->picture_structure == PICT_FRAME) + s->mv_type = MV_TYPE_16X16; + else + s->mv_type = MV_TYPE_FIELD; + if (s->pict_type == P_TYPE) { + /* if P type, zero motion vector is implied */ + s->mv_dir = MV_DIR_FORWARD; + s->mv[0][0][0] = s->mv[0][0][1] = 0; + s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0; + s->last_mv[0][1][0] = s->last_mv[0][1][1] = 0; + s->field_select[0][0]= s->picture_structure - 1; + } else { + /* if B type, reuse previous vectors and directions */ + s->mv[0][0][0] = s->last_mv[0][0][0]; + s->mv[0][0][1] = s->last_mv[0][0][1]; + s->mv[1][0][0] = s->last_mv[1][0][0]; + s->mv[1][0][1] = s->last_mv[1][0][1]; + } + } } } eos: // end of slice - *buf += get_bits_count(&s->gb)/8 - 1; + *buf += (get_bits_count(&s->gb)-1)/8; //printf("y %d %d %d %d\n", s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y); return 0; } @@ -3037,30 +2177,48 @@ static void mpeg_decode_gop(AVCodecContext *avctx, * finds the end of the current frame in the bitstream. * @return the position of the first byte of the next frame, or -1 */ -static int mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) +int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size) { int i; uint32_t state= pc->state; - i=0; - if(!pc->frame_start_found){ - for(i=0; i 1/4 + 1 first_SEQEXT -> 0/2 + 2 first field start -> 3/0 + 3 second_SEQEXT -> 2/0 + 4 searching end +*/ + + for(i=0; iframe_start_found>=0 && pc->frame_start_found<=4); + if(pc->frame_start_found&1){ + if(state == EXT_START_CODE && (buf[i]&0xF0) != 0x80) + pc->frame_start_found--; + else if(state == EXT_START_CODE+2){ + if((buf[i]&3) == 3) pc->frame_start_found= 0; + else pc->frame_start_found= (pc->frame_start_found+1)&3; + } + state++; + }else{ i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1; - if(state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){ + if(pc->frame_start_found==0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){ i++; - pc->frame_start_found=1; - break; + pc->frame_start_found=4; } - } - } - - if(pc->frame_start_found){ - /* EOF considered as end of frame */ - if (buf_size == 0) - return 0; - for(; istate=-1; + return i+1; + } + if(pc->frame_start_found==2 && state == SEQ_START_CODE) + pc->frame_start_found= 0; + if(pc->frame_start_found<4 && state == EXT_START_CODE) + pc->frame_start_found++; + if(pc->frame_start_found == 4 && (state&0xFFFFFF00) == 0x100){ if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){ pc->frame_start_found=0; pc->state=-1; @@ -3076,7 +2234,7 @@ static int mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_si /* handle buffering and image synchronisation */ static int mpeg_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { Mpeg1Context *s = avctx->priv_data; const uint8_t *buf_end; @@ -3087,7 +2245,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx, MpegEncContext *s2 = &s->mpeg_enc_ctx; dprintf(avctx, "fill_buffer\n"); - if (buf_size == 0) { + if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == SEQ_END_CODE)) { /* special case for last picture */ if (s2->low_delay==0 && s2->next_picture_ptr) { *picture= *(AVFrame*)s2->next_picture_ptr; @@ -3095,13 +2253,13 @@ static int mpeg_decode_frame(AVCodecContext *avctx, *data_size = sizeof(AVFrame); } - return 0; + return buf_size; } if(s2->flags&CODEC_FLAG_TRUNCATED){ - int next= mpeg1_find_frame_end(&s2->parse_context, buf, buf_size); + int next= ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size); - if( ff_combine_frame(&s2->parse_context, next, &buf, &buf_size) < 0 ) + if( ff_combine_frame(&s2->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 ) return buf_size; } @@ -3183,18 +2341,20 @@ static int mpeg_decode_frame(AVCodecContext *avctx, int mb_y= start_code - SLICE_MIN_START_CODE; if(s2->last_picture_ptr==NULL){ - /* skip b frames if we dont have reference frames */ + /* Skip B-frames if we do not have reference frames. */ if(s2->pict_type==B_TYPE) break; - /* skip P frames if we dont have reference frame no valid header */ -// if(s2->pict_type==P_TYPE && s2->first_field && !s2->first_slice) break; } - /* skip b frames if we are in a hurry */ + if(s2->next_picture_ptr==NULL){ + /* Skip P-frames if we do not have reference frame no valid header. */ + if(s2->pict_type==P_TYPE && (s2->first_field || s2->picture_structure==PICT_FRAME)) break; + } + /* Skip B-frames if we are in a hurry. */ if(avctx->hurry_up && s2->pict_type==B_TYPE) break; if( (avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type==B_TYPE) ||(avctx->skip_frame >= AVDISCARD_NONKEY && s2->pict_type!=I_TYPE) || avctx->skip_frame >= AVDISCARD_ALL) break; - /* skip everything if we are in a hurry>=5 */ + /* Skip everything if we are in a hurry>=5. */ if(avctx->hurry_up>=5) break; if (!s->mpeg_enc_ctx_allocated) break; @@ -3210,7 +2370,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx, return -1; } if(!s2->current_picture_ptr){ - av_log(avctx, AV_LOG_ERROR, "current_picture not initalized\n"); + av_log(avctx, AV_LOG_ERROR, "current_picture not initialized\n"); return -1; } @@ -3295,35 +2455,6 @@ AVCodec mpegvideo_decoder = { .flush= ff_mpeg_flush, }; -#ifdef CONFIG_ENCODERS - -AVCodec mpeg1video_encoder = { - "mpeg1video", - CODEC_TYPE_VIDEO, - CODEC_ID_MPEG1VIDEO, - sizeof(MpegEncContext), - encode_init, - MPV_encode_picture, - MPV_encode_end, - .supported_framerates= ff_frame_rate_tab+1, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, - .capabilities= CODEC_CAP_DELAY, -}; - -AVCodec mpeg2video_encoder = { - "mpeg2video", - CODEC_TYPE_VIDEO, - CODEC_ID_MPEG2VIDEO, - sizeof(MpegEncContext), - encode_init, - MPV_encode_picture, - MPV_encode_end, - .supported_framerates= ff_frame_rate_tab+1, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, -1}, - .capabilities= CODEC_CAP_DELAY, -}; -#endif - #ifdef HAVE_XVMC static int mpeg_mc_decode_init(AVCodecContext *avctx){ Mpeg1Context *s; @@ -3359,198 +2490,6 @@ AVCodec mpeg_xvmc_decoder = { #endif -#ifdef CONFIG_MPEGVIDEO_PARSER -static void mpegvideo_extract_headers(AVCodecParserContext *s, - AVCodecContext *avctx, - const uint8_t *buf, int buf_size) -{ - ParseContext1 *pc = s->priv_data; - const uint8_t *buf_end; - uint32_t start_code; - int frame_rate_index, ext_type, bytes_left; - int frame_rate_ext_n, frame_rate_ext_d; - int picture_structure, top_field_first, repeat_first_field, progressive_frame; - int horiz_size_ext, vert_size_ext, bit_rate_ext; -//FIXME replace the crap with get_bits() - s->repeat_pict = 0; - buf_end = buf + buf_size; - while (buf < buf_end) { - start_code= -1; - buf= ff_find_start_code(buf, buf_end, &start_code); - bytes_left = buf_end - buf; - switch(start_code) { - case PICTURE_START_CODE: - if (bytes_left >= 2) { - s->pict_type = (buf[1] >> 3) & 7; - } - break; - case SEQ_START_CODE: - if (bytes_left >= 7) { - pc->width = (buf[0] << 4) | (buf[1] >> 4); - pc->height = ((buf[1] & 0x0f) << 8) | buf[2]; - avcodec_set_dimensions(avctx, pc->width, pc->height); - frame_rate_index = buf[3] & 0xf; - pc->frame_rate.den = avctx->time_base.den = ff_frame_rate_tab[frame_rate_index].num; - pc->frame_rate.num = avctx->time_base.num = ff_frame_rate_tab[frame_rate_index].den; - avctx->bit_rate = ((buf[4]<<10) | (buf[5]<<2) | (buf[6]>>6))*400; - avctx->codec_id = CODEC_ID_MPEG1VIDEO; - avctx->sub_id = 1; - } - break; - case EXT_START_CODE: - if (bytes_left >= 1) { - ext_type = (buf[0] >> 4); - switch(ext_type) { - case 0x1: /* sequence extension */ - if (bytes_left >= 6) { - horiz_size_ext = ((buf[1] & 1) << 1) | (buf[2] >> 7); - vert_size_ext = (buf[2] >> 5) & 3; - bit_rate_ext = ((buf[2] & 0x1F)<<7) | (buf[3]>>1); - frame_rate_ext_n = (buf[5] >> 5) & 3; - frame_rate_ext_d = (buf[5] & 0x1f); - pc->progressive_sequence = buf[1] & (1 << 3); - avctx->has_b_frames= !(buf[5] >> 7); - - pc->width |=(horiz_size_ext << 12); - pc->height |=( vert_size_ext << 12); - avctx->bit_rate += (bit_rate_ext << 18) * 400; - avcodec_set_dimensions(avctx, pc->width, pc->height); - avctx->time_base.den = pc->frame_rate.den * (frame_rate_ext_n + 1); - avctx->time_base.num = pc->frame_rate.num * (frame_rate_ext_d + 1); - avctx->codec_id = CODEC_ID_MPEG2VIDEO; - avctx->sub_id = 2; /* forces MPEG2 */ - } - break; - case 0x8: /* picture coding extension */ - if (bytes_left >= 5) { - picture_structure = buf[2]&3; - top_field_first = buf[3] & (1 << 7); - repeat_first_field = buf[3] & (1 << 1); - progressive_frame = buf[4] & (1 << 7); - - /* check if we must repeat the frame */ - if (repeat_first_field) { - if (pc->progressive_sequence) { - if (top_field_first) - s->repeat_pict = 4; - else - s->repeat_pict = 2; - } else if (progressive_frame) { - s->repeat_pict = 1; - } - } - - /* the packet only represents half a frame - XXX,FIXME maybe find a different solution */ - if(picture_structure != 3) - s->repeat_pict = -1; - } - break; - } - } - break; - case -1: - goto the_end; - default: - /* we stop parsing when we encounter a slice. It ensures - that this function takes a negligible amount of time */ - if (start_code >= SLICE_MIN_START_CODE && - start_code <= SLICE_MAX_START_CODE) - goto the_end; - break; - } - } - the_end: ; -} - -static int mpegvideo_parse(AVCodecParserContext *s, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - ParseContext1 *pc1 = s->priv_data; - ParseContext *pc= &pc1->pc; - int next; - - if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ - next= buf_size; - }else{ - next= mpeg1_find_frame_end(pc, buf, buf_size); - - if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { - *poutbuf = NULL; - *poutbuf_size = 0; - return buf_size; - } - - } - /* we have a full frame : we just parse the first few MPEG headers - to have the full timing information. The time take by this - function should be negligible for uncorrupted streams */ - mpegvideo_extract_headers(s, avctx, buf, buf_size); -#if 0 - printf("pict_type=%d frame_rate=%0.3f repeat_pict=%d\n", - s->pict_type, (double)avctx->time_base.den / avctx->time_base.num, s->repeat_pict); -#endif - - *poutbuf = (uint8_t *)buf; - *poutbuf_size = buf_size; - return next; -} - -static int mpegvideo_split(AVCodecContext *avctx, - const uint8_t *buf, int buf_size) -{ - int i; - uint32_t state= -1; - - for(i=0; i= 0x100) - return i-3; - } - return 0; -} - -AVCodecParser mpegvideo_parser = { - { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO }, - sizeof(ParseContext1), - NULL, - mpegvideo_parse, - ff_parse1_close, - mpegvideo_split, -}; -#endif /* !CONFIG_MPEGVIDEO_PARSER */ - -static int imx_dump_header(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size, int keyframe) -{ - /* MXF essence element key */ - static const uint8_t imx_header[16] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x05,0x01,0x01,0x00 }; - uint8_t *poutbufp; - - if (avctx->codec_id != CODEC_ID_MPEG2VIDEO) { - av_log(avctx, AV_LOG_ERROR, "imx bitstream filter only applies to mpeg2video codec\n"); - return 0; - } - - *poutbuf = av_malloc(buf_size + 20 + FF_INPUT_BUFFER_PADDING_SIZE); - poutbufp = *poutbuf; - bytestream_put_buffer(&poutbufp, imx_header, 16); - bytestream_put_byte(&poutbufp, 0x83); /* KLV BER long form */ - bytestream_put_be24(&poutbufp, buf_size); - bytestream_put_buffer(&poutbufp, buf, buf_size); - *poutbuf_size = poutbufp - *poutbuf; - return 1; -} - -AVBitStreamFilter imx_dump_header_bsf = { - "imxdump", - 0, - imx_dump_header, -}; - /* this is ugly i know, but the alternative is too make hundreds of vars global and prefix them with ff_mpeg1_ which is far uglier. */ diff --git a/contrib/ffmpeg/libavcodec/mpeg12.h b/contrib/ffmpeg/libavcodec/mpeg12.h new file mode 100644 index 000000000..662e3b38f --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpeg12.h @@ -0,0 +1,31 @@ +/* + * MPEG1/2 common code + * Copyright (c) 2007 Aurelien Jacobs + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_MPEG12_H +#define FFMPEG_MPEG12_H + +#include "mpegvideo.h" + +extern uint8_t ff_mpeg12_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3]; + +void ff_mpeg12_common_init(MpegEncContext *s); + +#endif /* FFMPEG_MPEG12_H */ diff --git a/contrib/ffmpeg/libavcodec/mpeg12data.c b/contrib/ffmpeg/libavcodec/mpeg12data.c new file mode 100644 index 000000000..93d491f3c --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpeg12data.c @@ -0,0 +1,374 @@ +/* + * MPEG1/2 tables + * copyright (c) 2000,2001 Fabrice Bellard + * copyright (c) 2002-2004 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mpeg12data.c + * MPEG1/2 tables. + */ + +#include "mpeg12data.h" + +const uint16_t ff_mpeg1_default_intra_matrix[64] = { + 8, 16, 19, 22, 26, 27, 29, 34, + 16, 16, 22, 24, 27, 29, 34, 37, + 19, 22, 26, 27, 29, 34, 34, 38, + 22, 22, 26, 27, 29, 34, 37, 40, + 22, 26, 27, 29, 32, 35, 40, 48, + 26, 27, 29, 32, 35, 40, 48, 58, + 26, 27, 29, 34, 38, 46, 56, 69, + 27, 29, 35, 38, 46, 56, 69, 83 +}; + +const uint16_t ff_mpeg1_default_non_intra_matrix[64] = { + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, +}; + +const uint16_t ff_mpeg12_vlc_dc_lum_code[12] = { + 0x4, 0x0, 0x1, 0x5, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x1ff, +}; +const unsigned char ff_mpeg12_vlc_dc_lum_bits[12] = { + 3, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, 9, +}; + +const uint16_t ff_mpeg12_vlc_dc_chroma_code[12] = { + 0x0, 0x1, 0x2, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x3fe, 0x3ff, +}; +const unsigned char ff_mpeg12_vlc_dc_chroma_bits[12] = { + 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, +}; + +static const uint16_t mpeg1_vlc[113][2] = { + { 0x3, 2 }, { 0x4, 4 }, { 0x5, 5 }, { 0x6, 7 }, + { 0x26, 8 }, { 0x21, 8 }, { 0xa, 10 }, { 0x1d, 12 }, + { 0x18, 12 }, { 0x13, 12 }, { 0x10, 12 }, { 0x1a, 13 }, + { 0x19, 13 }, { 0x18, 13 }, { 0x17, 13 }, { 0x1f, 14 }, + { 0x1e, 14 }, { 0x1d, 14 }, { 0x1c, 14 }, { 0x1b, 14 }, + { 0x1a, 14 }, { 0x19, 14 }, { 0x18, 14 }, { 0x17, 14 }, + { 0x16, 14 }, { 0x15, 14 }, { 0x14, 14 }, { 0x13, 14 }, + { 0x12, 14 }, { 0x11, 14 }, { 0x10, 14 }, { 0x18, 15 }, + { 0x17, 15 }, { 0x16, 15 }, { 0x15, 15 }, { 0x14, 15 }, + { 0x13, 15 }, { 0x12, 15 }, { 0x11, 15 }, { 0x10, 15 }, + { 0x3, 3 }, { 0x6, 6 }, { 0x25, 8 }, { 0xc, 10 }, + { 0x1b, 12 }, { 0x16, 13 }, { 0x15, 13 }, { 0x1f, 15 }, + { 0x1e, 15 }, { 0x1d, 15 }, { 0x1c, 15 }, { 0x1b, 15 }, + { 0x1a, 15 }, { 0x19, 15 }, { 0x13, 16 }, { 0x12, 16 }, + { 0x11, 16 }, { 0x10, 16 }, { 0x5, 4 }, { 0x4, 7 }, + { 0xb, 10 }, { 0x14, 12 }, { 0x14, 13 }, { 0x7, 5 }, + { 0x24, 8 }, { 0x1c, 12 }, { 0x13, 13 }, { 0x6, 5 }, + { 0xf, 10 }, { 0x12, 12 }, { 0x7, 6 }, { 0x9, 10 }, + { 0x12, 13 }, { 0x5, 6 }, { 0x1e, 12 }, { 0x14, 16 }, + { 0x4, 6 }, { 0x15, 12 }, { 0x7, 7 }, { 0x11, 12 }, + { 0x5, 7 }, { 0x11, 13 }, { 0x27, 8 }, { 0x10, 13 }, + { 0x23, 8 }, { 0x1a, 16 }, { 0x22, 8 }, { 0x19, 16 }, + { 0x20, 8 }, { 0x18, 16 }, { 0xe, 10 }, { 0x17, 16 }, + { 0xd, 10 }, { 0x16, 16 }, { 0x8, 10 }, { 0x15, 16 }, + { 0x1f, 12 }, { 0x1a, 12 }, { 0x19, 12 }, { 0x17, 12 }, + { 0x16, 12 }, { 0x1f, 13 }, { 0x1e, 13 }, { 0x1d, 13 }, + { 0x1c, 13 }, { 0x1b, 13 }, { 0x1f, 16 }, { 0x1e, 16 }, + { 0x1d, 16 }, { 0x1c, 16 }, { 0x1b, 16 }, + { 0x1, 6 }, /* escape */ + { 0x2, 2 }, /* EOB */ +}; + +static const uint16_t mpeg2_vlc[113][2] = { + {0x02, 2}, {0x06, 3}, {0x07, 4}, {0x1c, 5}, + {0x1d, 5}, {0x05, 6}, {0x04, 6}, {0x7b, 7}, + {0x7c, 7}, {0x23, 8}, {0x22, 8}, {0xfa, 8}, + {0xfb, 8}, {0xfe, 8}, {0xff, 8}, {0x1f,14}, + {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14}, + {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14}, + {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14}, + {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15}, + {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15}, + {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15}, + {0x02, 3}, {0x06, 5}, {0x79, 7}, {0x27, 8}, + {0x20, 8}, {0x16,13}, {0x15,13}, {0x1f,15}, + {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15}, + {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16}, + {0x11,16}, {0x10,16}, {0x05, 5}, {0x07, 7}, + {0xfc, 8}, {0x0c,10}, {0x14,13}, {0x07, 5}, + {0x26, 8}, {0x1c,12}, {0x13,13}, {0x06, 6}, + {0xfd, 8}, {0x12,12}, {0x07, 6}, {0x04, 9}, + {0x12,13}, {0x06, 7}, {0x1e,12}, {0x14,16}, + {0x04, 7}, {0x15,12}, {0x05, 7}, {0x11,12}, + {0x78, 7}, {0x11,13}, {0x7a, 7}, {0x10,13}, + {0x21, 8}, {0x1a,16}, {0x25, 8}, {0x19,16}, + {0x24, 8}, {0x18,16}, {0x05, 9}, {0x17,16}, + {0x07, 9}, {0x16,16}, {0x0d,10}, {0x15,16}, + {0x1f,12}, {0x1a,12}, {0x19,12}, {0x17,12}, + {0x16,12}, {0x1f,13}, {0x1e,13}, {0x1d,13}, + {0x1c,13}, {0x1b,13}, {0x1f,16}, {0x1e,16}, + {0x1d,16}, {0x1c,16}, {0x1b,16}, + {0x01,6}, /* escape */ + {0x06,4}, /* EOB */ +}; + +static const int8_t mpeg1_level[111] = { + 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 40, + 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 1, 2, 3, 4, 5, 1, + 2, 3, 4, 1, 2, 3, 1, 2, + 3, 1, 2, 3, 1, 2, 1, 2, + 1, 2, 1, 2, 1, 2, 1, 2, + 1, 2, 1, 2, 1, 2, 1, 2, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, +}; + +static const int8_t mpeg1_run[111] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 2, 2, 2, 2, 2, 3, + 3, 3, 3, 4, 4, 4, 5, 5, + 5, 6, 6, 6, 7, 7, 8, 8, + 9, 9, 10, 10, 11, 11, 12, 12, + 13, 13, 14, 14, 15, 15, 16, 16, + 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, +}; + +RLTable ff_rl_mpeg1 = { + 111, + 111, + mpeg1_vlc, + mpeg1_run, + mpeg1_level, +}; + +RLTable ff_rl_mpeg2 = { + 111, + 111, + mpeg2_vlc, + mpeg1_run, + mpeg1_level, +}; + +const uint8_t ff_mpeg12_mbAddrIncrTable[36][2] = { + {0x1, 1}, + {0x3, 3}, + {0x2, 3}, + {0x3, 4}, + {0x2, 4}, + {0x3, 5}, + {0x2, 5}, + {0x7, 7}, + {0x6, 7}, + {0xb, 8}, + {0xa, 8}, + {0x9, 8}, + {0x8, 8}, + {0x7, 8}, + {0x6, 8}, + {0x17, 10}, + {0x16, 10}, + {0x15, 10}, + {0x14, 10}, + {0x13, 10}, + {0x12, 10}, + {0x23, 11}, + {0x22, 11}, + {0x21, 11}, + {0x20, 11}, + {0x1f, 11}, + {0x1e, 11}, + {0x1d, 11}, + {0x1c, 11}, + {0x1b, 11}, + {0x1a, 11}, + {0x19, 11}, + {0x18, 11}, + {0x8, 11}, /* escape */ + {0xf, 11}, /* stuffing */ + {0x0, 8}, /* end (and 15 more 0 bits should follow) */ +}; + +const uint8_t ff_mpeg12_mbPatTable[64][2] = { + {0x1, 9}, + {0xb, 5}, + {0x9, 5}, + {0xd, 6}, + {0xd, 4}, + {0x17, 7}, + {0x13, 7}, + {0x1f, 8}, + {0xc, 4}, + {0x16, 7}, + {0x12, 7}, + {0x1e, 8}, + {0x13, 5}, + {0x1b, 8}, + {0x17, 8}, + {0x13, 8}, + {0xb, 4}, + {0x15, 7}, + {0x11, 7}, + {0x1d, 8}, + {0x11, 5}, + {0x19, 8}, + {0x15, 8}, + {0x11, 8}, + {0xf, 6}, + {0xf, 8}, + {0xd, 8}, + {0x3, 9}, + {0xf, 5}, + {0xb, 8}, + {0x7, 8}, + {0x7, 9}, + {0xa, 4}, + {0x14, 7}, + {0x10, 7}, + {0x1c, 8}, + {0xe, 6}, + {0xe, 8}, + {0xc, 8}, + {0x2, 9}, + {0x10, 5}, + {0x18, 8}, + {0x14, 8}, + {0x10, 8}, + {0xe, 5}, + {0xa, 8}, + {0x6, 8}, + {0x6, 9}, + {0x12, 5}, + {0x1a, 8}, + {0x16, 8}, + {0x12, 8}, + {0xd, 5}, + {0x9, 8}, + {0x5, 8}, + {0x5, 9}, + {0xc, 5}, + {0x8, 8}, + {0x4, 8}, + {0x4, 9}, + {0x7, 3}, + {0xa, 5}, + {0x8, 5}, + {0xc, 6} +}; + +const uint8_t ff_mpeg12_mbMotionVectorTable[17][2] = { +{ 0x1, 1 }, +{ 0x1, 2 }, +{ 0x1, 3 }, +{ 0x1, 4 }, +{ 0x3, 6 }, +{ 0x5, 7 }, +{ 0x4, 7 }, +{ 0x3, 7 }, +{ 0xb, 9 }, +{ 0xa, 9 }, +{ 0x9, 9 }, +{ 0x11, 10 }, +{ 0x10, 10 }, +{ 0xf, 10 }, +{ 0xe, 10 }, +{ 0xd, 10 }, +{ 0xc, 10 }, +}; + +const AVRational ff_frame_rate_tab[] = { + { 0, 0}, + {24000, 1001}, + { 24, 1}, + { 25, 1}, + {30000, 1001}, + { 30, 1}, + { 50, 1}, + {60000, 1001}, + { 60, 1}, + // Xing's 15fps: (9) + { 15, 1}, + // libmpeg3's "Unofficial economy rates": (10-13) + { 5, 1}, + { 10, 1}, + { 12, 1}, + { 15, 1}, + { 0, 0}, +}; + +const uint8_t ff_mpeg1_dc_scale_table[128]={ +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, +}; + +const float ff_mpeg1_aspect[16]={ + 0.0000, + 1.0000, + 0.6735, + 0.7031, + + 0.7615, + 0.8055, + 0.8437, + 0.8935, + + 0.9157, + 0.9815, + 1.0255, + 1.0695, + + 1.0950, + 1.1575, + 1.2015, +}; + +const AVRational ff_mpeg2_aspect[16]={ + {0,1}, + {1,1}, + {4,3}, + {16,9}, + {221,100}, + {0,1}, + {0,1}, + {0,1}, + {0,1}, + {0,1}, + {0,1}, + {0,1}, + {0,1}, + {0,1}, + {0,1}, + {0,1}, +}; diff --git a/contrib/ffmpeg/libavcodec/mpeg12data.h b/contrib/ffmpeg/libavcodec/mpeg12data.h index 1176a75fa..190817f64 100644 --- a/contrib/ffmpeg/libavcodec/mpeg12data.h +++ b/contrib/ffmpeg/libavcodec/mpeg12data.h @@ -1,5 +1,5 @@ /* - * MPEG1 codec / MPEG2 decoder + * MPEG1/2 tables * copyright (c) 2000,2001 Fabrice Bellard * copyright (c) 2002-2004 Michael Niedermayer * @@ -25,450 +25,26 @@ * MPEG1/2 tables. */ -const uint16_t ff_mpeg1_default_intra_matrix[64] = { - 8, 16, 19, 22, 26, 27, 29, 34, - 16, 16, 22, 24, 27, 29, 34, 37, - 19, 22, 26, 27, 29, 34, 34, 38, - 22, 22, 26, 27, 29, 34, 37, 40, - 22, 26, 27, 29, 32, 35, 40, 48, - 26, 27, 29, 32, 35, 40, 48, 58, - 26, 27, 29, 34, 38, 46, 56, 69, - 27, 29, 35, 38, 46, 56, 69, 83 -}; +#ifndef FFMPEG_MPEG12DATA_H +#define FFMPEG_MPEG12DATA_H -const uint16_t ff_mpeg1_default_non_intra_matrix[64] = { - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, -}; +#include +#include "mpegvideo.h" -static const uint16_t vlc_dc_lum_code[12] = { - 0x4, 0x0, 0x1, 0x5, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x1ff, -}; -static const unsigned char vlc_dc_lum_bits[12] = { - 3, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9, 9, -}; +extern const uint16_t ff_mpeg12_vlc_dc_lum_code[12]; +extern const unsigned char ff_mpeg12_vlc_dc_lum_bits[12]; +extern const uint16_t ff_mpeg12_vlc_dc_chroma_code[12]; +extern const unsigned char ff_mpeg12_vlc_dc_chroma_bits[12]; -static const uint16_t vlc_dc_chroma_code[12] = { - 0x0, 0x1, 0x2, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe, 0x3fe, 0x3ff, -}; -static const unsigned char vlc_dc_chroma_bits[12] = { - 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, -}; +extern RLTable ff_rl_mpeg1; +extern RLTable ff_rl_mpeg2; -static const uint16_t mpeg1_vlc[113][2] = { - { 0x3, 2 }, { 0x4, 4 }, { 0x5, 5 }, { 0x6, 7 }, - { 0x26, 8 }, { 0x21, 8 }, { 0xa, 10 }, { 0x1d, 12 }, - { 0x18, 12 }, { 0x13, 12 }, { 0x10, 12 }, { 0x1a, 13 }, - { 0x19, 13 }, { 0x18, 13 }, { 0x17, 13 }, { 0x1f, 14 }, - { 0x1e, 14 }, { 0x1d, 14 }, { 0x1c, 14 }, { 0x1b, 14 }, - { 0x1a, 14 }, { 0x19, 14 }, { 0x18, 14 }, { 0x17, 14 }, - { 0x16, 14 }, { 0x15, 14 }, { 0x14, 14 }, { 0x13, 14 }, - { 0x12, 14 }, { 0x11, 14 }, { 0x10, 14 }, { 0x18, 15 }, - { 0x17, 15 }, { 0x16, 15 }, { 0x15, 15 }, { 0x14, 15 }, - { 0x13, 15 }, { 0x12, 15 }, { 0x11, 15 }, { 0x10, 15 }, - { 0x3, 3 }, { 0x6, 6 }, { 0x25, 8 }, { 0xc, 10 }, - { 0x1b, 12 }, { 0x16, 13 }, { 0x15, 13 }, { 0x1f, 15 }, - { 0x1e, 15 }, { 0x1d, 15 }, { 0x1c, 15 }, { 0x1b, 15 }, - { 0x1a, 15 }, { 0x19, 15 }, { 0x13, 16 }, { 0x12, 16 }, - { 0x11, 16 }, { 0x10, 16 }, { 0x5, 4 }, { 0x4, 7 }, - { 0xb, 10 }, { 0x14, 12 }, { 0x14, 13 }, { 0x7, 5 }, - { 0x24, 8 }, { 0x1c, 12 }, { 0x13, 13 }, { 0x6, 5 }, - { 0xf, 10 }, { 0x12, 12 }, { 0x7, 6 }, { 0x9, 10 }, - { 0x12, 13 }, { 0x5, 6 }, { 0x1e, 12 }, { 0x14, 16 }, - { 0x4, 6 }, { 0x15, 12 }, { 0x7, 7 }, { 0x11, 12 }, - { 0x5, 7 }, { 0x11, 13 }, { 0x27, 8 }, { 0x10, 13 }, - { 0x23, 8 }, { 0x1a, 16 }, { 0x22, 8 }, { 0x19, 16 }, - { 0x20, 8 }, { 0x18, 16 }, { 0xe, 10 }, { 0x17, 16 }, - { 0xd, 10 }, { 0x16, 16 }, { 0x8, 10 }, { 0x15, 16 }, - { 0x1f, 12 }, { 0x1a, 12 }, { 0x19, 12 }, { 0x17, 12 }, - { 0x16, 12 }, { 0x1f, 13 }, { 0x1e, 13 }, { 0x1d, 13 }, - { 0x1c, 13 }, { 0x1b, 13 }, { 0x1f, 16 }, { 0x1e, 16 }, - { 0x1d, 16 }, { 0x1c, 16 }, { 0x1b, 16 }, - { 0x1, 6 }, /* escape */ - { 0x2, 2 }, /* EOB */ -}; +extern const uint8_t ff_mpeg12_mbAddrIncrTable[36][2]; +extern const uint8_t ff_mpeg12_mbPatTable[64][2]; -static const uint16_t mpeg2_vlc[113][2] = { - {0x02, 2}, {0x06, 3}, {0x07, 4}, {0x1c, 5}, - {0x1d, 5}, {0x05, 6}, {0x04, 6}, {0x7b, 7}, - {0x7c, 7}, {0x23, 8}, {0x22, 8}, {0xfa, 8}, - {0xfb, 8}, {0xfe, 8}, {0xff, 8}, {0x1f,14}, - {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14}, - {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14}, - {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14}, - {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15}, - {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15}, - {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15}, - {0x02, 3}, {0x06, 5}, {0x79, 7}, {0x27, 8}, - {0x20, 8}, {0x16,13}, {0x15,13}, {0x1f,15}, - {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15}, - {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16}, - {0x11,16}, {0x10,16}, {0x05, 5}, {0x07, 7}, - {0xfc, 8}, {0x0c,10}, {0x14,13}, {0x07, 5}, - {0x26, 8}, {0x1c,12}, {0x13,13}, {0x06, 6}, - {0xfd, 8}, {0x12,12}, {0x07, 6}, {0x04, 9}, - {0x12,13}, {0x06, 7}, {0x1e,12}, {0x14,16}, - {0x04, 7}, {0x15,12}, {0x05, 7}, {0x11,12}, - {0x78, 7}, {0x11,13}, {0x7a, 7}, {0x10,13}, - {0x21, 8}, {0x1a,16}, {0x25, 8}, {0x19,16}, - {0x24, 8}, {0x18,16}, {0x05, 9}, {0x17,16}, - {0x07, 9}, {0x16,16}, {0x0d,10}, {0x15,16}, - {0x1f,12}, {0x1a,12}, {0x19,12}, {0x17,12}, - {0x16,12}, {0x1f,13}, {0x1e,13}, {0x1d,13}, - {0x1c,13}, {0x1b,13}, {0x1f,16}, {0x1e,16}, - {0x1d,16}, {0x1c,16}, {0x1b,16}, - {0x01,6}, /* escape */ - {0x06,4}, /* EOB */ -}; +extern const uint8_t ff_mpeg12_mbMotionVectorTable[17][2]; -static const int8_t mpeg1_level[111] = { - 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32, - 33, 34, 35, 36, 37, 38, 39, 40, - 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 1, 2, 3, 4, 5, 1, - 2, 3, 4, 1, 2, 3, 1, 2, - 3, 1, 2, 3, 1, 2, 1, 2, - 1, 2, 1, 2, 1, 2, 1, 2, - 1, 2, 1, 2, 1, 2, 1, 2, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, -}; +extern const float ff_mpeg1_aspect[16]; +extern const AVRational ff_mpeg2_aspect[16]; -static const int8_t mpeg1_run[111] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 2, 2, 2, 2, 2, 3, - 3, 3, 3, 4, 4, 4, 5, 5, - 5, 6, 6, 6, 7, 7, 8, 8, - 9, 9, 10, 10, 11, 11, 12, 12, - 13, 13, 14, 14, 15, 15, 16, 16, - 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, -}; - -static RLTable rl_mpeg1 = { - 111, - 111, - mpeg1_vlc, - mpeg1_run, - mpeg1_level, -}; - -static RLTable rl_mpeg2 = { - 111, - 111, - mpeg2_vlc, - mpeg1_run, - mpeg1_level, -}; - -static const uint8_t mbAddrIncrTable[36][2] = { - {0x1, 1}, - {0x3, 3}, - {0x2, 3}, - {0x3, 4}, - {0x2, 4}, - {0x3, 5}, - {0x2, 5}, - {0x7, 7}, - {0x6, 7}, - {0xb, 8}, - {0xa, 8}, - {0x9, 8}, - {0x8, 8}, - {0x7, 8}, - {0x6, 8}, - {0x17, 10}, - {0x16, 10}, - {0x15, 10}, - {0x14, 10}, - {0x13, 10}, - {0x12, 10}, - {0x23, 11}, - {0x22, 11}, - {0x21, 11}, - {0x20, 11}, - {0x1f, 11}, - {0x1e, 11}, - {0x1d, 11}, - {0x1c, 11}, - {0x1b, 11}, - {0x1a, 11}, - {0x19, 11}, - {0x18, 11}, - {0x8, 11}, /* escape */ - {0xf, 11}, /* stuffing */ - {0x0, 8}, /* end (and 15 more 0 bits should follow) */ -}; - -static const uint8_t mbPatTable[64][2] = { - {0x1, 9}, - {0xb, 5}, - {0x9, 5}, - {0xd, 6}, - {0xd, 4}, - {0x17, 7}, - {0x13, 7}, - {0x1f, 8}, - {0xc, 4}, - {0x16, 7}, - {0x12, 7}, - {0x1e, 8}, - {0x13, 5}, - {0x1b, 8}, - {0x17, 8}, - {0x13, 8}, - {0xb, 4}, - {0x15, 7}, - {0x11, 7}, - {0x1d, 8}, - {0x11, 5}, - {0x19, 8}, - {0x15, 8}, - {0x11, 8}, - {0xf, 6}, - {0xf, 8}, - {0xd, 8}, - {0x3, 9}, - {0xf, 5}, - {0xb, 8}, - {0x7, 8}, - {0x7, 9}, - {0xa, 4}, - {0x14, 7}, - {0x10, 7}, - {0x1c, 8}, - {0xe, 6}, - {0xe, 8}, - {0xc, 8}, - {0x2, 9}, - {0x10, 5}, - {0x18, 8}, - {0x14, 8}, - {0x10, 8}, - {0xe, 5}, - {0xa, 8}, - {0x6, 8}, - {0x6, 9}, - {0x12, 5}, - {0x1a, 8}, - {0x16, 8}, - {0x12, 8}, - {0xd, 5}, - {0x9, 8}, - {0x5, 8}, - {0x5, 9}, - {0xc, 5}, - {0x8, 8}, - {0x4, 8}, - {0x4, 9}, - {0x7, 3}, - {0xa, 5}, - {0x8, 5}, - {0xc, 6} -}; - -#define MB_TYPE_ZERO_MV 0x20000000 -#define IS_ZERO_MV(a) ((a)&MB_TYPE_ZERO_MV) - -static const uint8_t table_mb_ptype[7][2] = { - { 3, 5 }, // 0x01 MB_INTRA - { 1, 2 }, // 0x02 MB_PAT - { 1, 3 }, // 0x08 MB_FOR - { 1, 1 }, // 0x0A MB_FOR|MB_PAT - { 1, 6 }, // 0x11 MB_QUANT|MB_INTRA - { 1, 5 }, // 0x12 MB_QUANT|MB_PAT - { 2, 5 }, // 0x1A MB_QUANT|MB_FOR|MB_PAT -}; - -static const uint32_t ptype2mb_type[7] = { - MB_TYPE_INTRA, - MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16, - MB_TYPE_L0, - MB_TYPE_L0 | MB_TYPE_CBP, - MB_TYPE_QUANT | MB_TYPE_INTRA, - MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16, - MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP, -}; - -static const uint8_t table_mb_btype[11][2] = { - { 3, 5 }, // 0x01 MB_INTRA - { 2, 3 }, // 0x04 MB_BACK - { 3, 3 }, // 0x06 MB_BACK|MB_PAT - { 2, 4 }, // 0x08 MB_FOR - { 3, 4 }, // 0x0A MB_FOR|MB_PAT - { 2, 2 }, // 0x0C MB_FOR|MB_BACK - { 3, 2 }, // 0x0E MB_FOR|MB_BACK|MB_PAT - { 1, 6 }, // 0x11 MB_QUANT|MB_INTRA - { 2, 6 }, // 0x16 MB_QUANT|MB_BACK|MB_PAT - { 3, 6 }, // 0x1A MB_QUANT|MB_FOR|MB_PAT - { 2, 5 }, // 0x1E MB_QUANT|MB_FOR|MB_BACK|MB_PAT -}; - -static const uint32_t btype2mb_type[11] = { - MB_TYPE_INTRA, - MB_TYPE_L1, - MB_TYPE_L1 | MB_TYPE_CBP, - MB_TYPE_L0, - MB_TYPE_L0 | MB_TYPE_CBP, - MB_TYPE_L0L1, - MB_TYPE_L0L1 | MB_TYPE_CBP, - MB_TYPE_QUANT | MB_TYPE_INTRA, - MB_TYPE_QUANT | MB_TYPE_L1 | MB_TYPE_CBP, - MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP, - MB_TYPE_QUANT | MB_TYPE_L0L1 | MB_TYPE_CBP, -}; - -static const uint8_t mbMotionVectorTable[17][2] = { -{ 0x1, 1 }, -{ 0x1, 2 }, -{ 0x1, 3 }, -{ 0x1, 4 }, -{ 0x3, 6 }, -{ 0x5, 7 }, -{ 0x4, 7 }, -{ 0x3, 7 }, -{ 0xb, 9 }, -{ 0xa, 9 }, -{ 0x9, 9 }, -{ 0x11, 10 }, -{ 0x10, 10 }, -{ 0xf, 10 }, -{ 0xe, 10 }, -{ 0xd, 10 }, -{ 0xc, 10 }, -}; - -const AVRational ff_frame_rate_tab[] = { - { 0, 0}, - {24000, 1001}, - { 24, 1}, - { 25, 1}, - {30000, 1001}, - { 30, 1}, - { 50, 1}, - {60000, 1001}, - { 60, 1}, - // Xing's 15fps: (9) - { 15, 1}, - // libmpeg3's "Unofficial economy rates": (10-13) - { 5, 1}, - { 10, 1}, - { 12, 1}, - { 15, 1}, - { 0, 0}, -}; - -static const uint8_t non_linear_qscale[32] = { - 0, 1, 2, 3, 4, 5, 6, 7, - 8,10,12,14,16,18,20,22, - 24,28,32,36,40,44,48,52, - 56,64,72,80,88,96,104,112, -}; - -static const uint8_t inv_non_linear_qscale[13] = { - 0, 2, 4, 6, 8, - 9,10,11,12,13,14,15,16, -}; - -const uint8_t ff_mpeg1_dc_scale_table[128]={ -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, -}; - -static const uint8_t mpeg2_dc_scale_table1[128]={ -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, -}; - -static const uint8_t mpeg2_dc_scale_table2[128]={ -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -}; - -static const uint8_t mpeg2_dc_scale_table3[128]={ -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -}; - -static const uint8_t *mpeg2_dc_scale_table[4]={ - ff_mpeg1_dc_scale_table, - mpeg2_dc_scale_table1, - mpeg2_dc_scale_table2, - mpeg2_dc_scale_table3, -}; - -static const float mpeg1_aspect[16]={ - 0.0000, - 1.0000, - 0.6735, - 0.7031, - - 0.7615, - 0.8055, - 0.8437, - 0.8935, - - 0.9157, - 0.9815, - 1.0255, - 1.0695, - - 1.0950, - 1.1575, - 1.2015, -}; - -static const AVRational mpeg2_aspect[16]={ - {0,1}, - {1,1}, - {4,3}, - {16,9}, - {221,100}, - {0,1}, - {0,1}, - {0,1}, - {0,1}, - {0,1}, - {0,1}, - {0,1}, - {0,1}, - {0,1}, - {0,1}, - {0,1}, -}; - -static const uint8_t svcd_scan_offset_placeholder[14]={ - 0x10, 0x0E, - 0x00, 0x80, 0x81, - 0x00, 0x80, 0x81, - 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, -}; +#endif /* FFMPEG_MPEG12DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/mpeg12decdata.h b/contrib/ffmpeg/libavcodec/mpeg12decdata.h new file mode 100644 index 000000000..52816d416 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpeg12decdata.h @@ -0,0 +1,124 @@ +/* + * MPEG1/2 decoder tables + * copyright (c) 2000,2001 Fabrice Bellard + * copyright (c) 2002-2004 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mpeg12decdata.h + * MPEG1/2 decoder tables. + */ + +#ifndef FFMPEG_MPEG12DECDATA_H +#define FFMPEG_MPEG12DECDATA_H + +#include +#include "mpegvideo.h" + + +#define MB_TYPE_ZERO_MV 0x20000000 +#define IS_ZERO_MV(a) ((a)&MB_TYPE_ZERO_MV) + +static const uint8_t table_mb_ptype[7][2] = { + { 3, 5 }, // 0x01 MB_INTRA + { 1, 2 }, // 0x02 MB_PAT + { 1, 3 }, // 0x08 MB_FOR + { 1, 1 }, // 0x0A MB_FOR|MB_PAT + { 1, 6 }, // 0x11 MB_QUANT|MB_INTRA + { 1, 5 }, // 0x12 MB_QUANT|MB_PAT + { 2, 5 }, // 0x1A MB_QUANT|MB_FOR|MB_PAT +}; + +static const uint32_t ptype2mb_type[7] = { + MB_TYPE_INTRA, + MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16, + MB_TYPE_L0, + MB_TYPE_L0 | MB_TYPE_CBP, + MB_TYPE_QUANT | MB_TYPE_INTRA, + MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16, + MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP, +}; + +static const uint8_t table_mb_btype[11][2] = { + { 3, 5 }, // 0x01 MB_INTRA + { 2, 3 }, // 0x04 MB_BACK + { 3, 3 }, // 0x06 MB_BACK|MB_PAT + { 2, 4 }, // 0x08 MB_FOR + { 3, 4 }, // 0x0A MB_FOR|MB_PAT + { 2, 2 }, // 0x0C MB_FOR|MB_BACK + { 3, 2 }, // 0x0E MB_FOR|MB_BACK|MB_PAT + { 1, 6 }, // 0x11 MB_QUANT|MB_INTRA + { 2, 6 }, // 0x16 MB_QUANT|MB_BACK|MB_PAT + { 3, 6 }, // 0x1A MB_QUANT|MB_FOR|MB_PAT + { 2, 5 }, // 0x1E MB_QUANT|MB_FOR|MB_BACK|MB_PAT +}; + +static const uint32_t btype2mb_type[11] = { + MB_TYPE_INTRA, + MB_TYPE_L1, + MB_TYPE_L1 | MB_TYPE_CBP, + MB_TYPE_L0, + MB_TYPE_L0 | MB_TYPE_CBP, + MB_TYPE_L0L1, + MB_TYPE_L0L1 | MB_TYPE_CBP, + MB_TYPE_QUANT | MB_TYPE_INTRA, + MB_TYPE_QUANT | MB_TYPE_L1 | MB_TYPE_CBP, + MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP, + MB_TYPE_QUANT | MB_TYPE_L0L1 | MB_TYPE_CBP, +}; + +static const uint8_t non_linear_qscale[32] = { + 0, 1, 2, 3, 4, 5, 6, 7, + 8,10,12,14,16,18,20,22, + 24,28,32,36,40,44,48,52, + 56,64,72,80,88,96,104,112, +}; + +static const uint8_t mpeg2_dc_scale_table1[128]={ +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +}; + +static const uint8_t mpeg2_dc_scale_table2[128]={ +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +}; + +static const uint8_t mpeg2_dc_scale_table3[128]={ +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; + +static const uint8_t *mpeg2_dc_scale_table[4]={ + ff_mpeg1_dc_scale_table, + mpeg2_dc_scale_table1, + mpeg2_dc_scale_table2, + mpeg2_dc_scale_table3, +}; + +#endif /* FFMPEG_MPEG12DECDATA_H */ diff --git a/contrib/ffmpeg/libavcodec/mpeg12enc.c b/contrib/ffmpeg/libavcodec/mpeg12enc.c new file mode 100644 index 000000000..aac90e04e --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpeg12enc.c @@ -0,0 +1,954 @@ +/* + * MPEG1/2 encoder + * Copyright (c) 2000,2001 Fabrice Bellard. + * Copyright (c) 2002-2004 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mpeg12enc.c + * MPEG1/2 encoder + */ + +#include "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" + +#include "mpeg12.h" +#include "mpeg12data.h" +#include "bytestream.h" + + +static const uint8_t inv_non_linear_qscale[13] = { + 0, 2, 4, 6, 8, + 9,10,11,12,13,14,15,16, +}; + +static const uint8_t svcd_scan_offset_placeholder[14] = { + 0x10, 0x0E, + 0x00, 0x80, 0x81, + 0x00, 0x80, 0x81, + 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, +}; + +static void mpeg1_encode_block(MpegEncContext *s, + DCTELEM *block, + int component); +static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code); // RAL: f_code parameter added + +static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; +static uint8_t fcode_tab[MAX_MV*2+1]; + +static uint8_t uni_mpeg1_ac_vlc_len [64*64*2]; +static uint8_t uni_mpeg2_ac_vlc_len [64*64*2]; + +/* simple include everything table for dc, first byte is bits number next 3 are code*/ +static uint32_t mpeg1_lum_dc_uni[512]; +static uint32_t mpeg1_chr_dc_uni[512]; + +static uint8_t mpeg1_index_run[2][64]; +static int8_t mpeg1_max_level[2][64]; + +static void init_uni_ac_vlc(RLTable *rl, uint8_t *uni_ac_vlc_len){ + int i; + + for(i=0; i<128; i++){ + int level= i-64; + int run; + for(run=0; run<64; run++){ + int len, bits, code; + + int alevel= FFABS(level); + int sign= (level>>31)&1; + + if (alevel > rl->max_level[0][run]) + code= 111; /*rl->n*/ + else + code= rl->index_run[0][run] + alevel - 1; + + if (code < 111 /* rl->n */) { + /* store the vlc & sign at once */ + len= rl->table_vlc[code][1]+1; + bits= (rl->table_vlc[code][0]<<1) + sign; + } else { + len= rl->table_vlc[111/*rl->n*/][1]+6; + bits= rl->table_vlc[111/*rl->n*/][0]<<6; + + bits|= run; + if (alevel < 128) { + bits<<=8; len+=8; + bits|= level & 0xff; + } else { + bits<<=16; len+=16; + bits|= level & 0xff; + if (level < 0) { + bits|= 0x8001 + level + 255; + } else { + bits|= level & 0xffff; + } + } + } + + uni_ac_vlc_len [UNI_AC_ENC_INDEX(run, i)]= len; + } + } +} + + +static int find_frame_rate_index(MpegEncContext *s){ + int i; + int64_t dmin= INT64_MAX; + int64_t d; + + for(i=1;i<14;i++) { + int64_t n0= 1001LL/ff_frame_rate_tab[i].den*ff_frame_rate_tab[i].num*s->avctx->time_base.num; + int64_t n1= 1001LL*s->avctx->time_base.den; + if(s->avctx->strict_std_compliance > FF_COMPLIANCE_INOFFICIAL && i>=9) break; + + d = FFABS(n0 - n1); + if(d < dmin){ + dmin=d; + s->frame_rate_index= i; + } + } + if(dmin) + return -1; + else + return 0; +} + +static int encode_init(AVCodecContext *avctx) +{ + MpegEncContext *s = avctx->priv_data; + + if(MPV_encode_init(avctx) < 0) + return -1; + + if(find_frame_rate_index(s) < 0){ + if(s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ + av_log(avctx, AV_LOG_ERROR, "MPEG1/2 does not support %d/%d fps\n", avctx->time_base.den, avctx->time_base.num); + return -1; + }else{ + av_log(avctx, AV_LOG_INFO, "MPEG1/2 does not support %d/%d fps, there may be AV sync issues\n", avctx->time_base.den, avctx->time_base.num); + } + } + + if(avctx->profile == FF_PROFILE_UNKNOWN){ + if(avctx->level != FF_LEVEL_UNKNOWN){ + av_log(avctx, AV_LOG_ERROR, "Set profile and level\n"); + return -1; + } + avctx->profile = s->chroma_format == CHROMA_420 ? 4 : 0; /* Main or 4:2:2 */ + } + + if(avctx->level == FF_LEVEL_UNKNOWN){ + if(avctx->profile == 0){ /* 4:2:2 */ + if(avctx->width <= 720 && avctx->height <= 608) avctx->level = 5; /* Main */ + else avctx->level = 2; /* High */ + }else{ + if(avctx->profile != 1 && s->chroma_format != CHROMA_420){ + av_log(avctx, AV_LOG_ERROR, "Only High(1) and 4:2:2(0) profiles support 4:2:2 color sampling\n"); + return -1; + } + if(avctx->width <= 720 && avctx->height <= 576) avctx->level = 8; /* Main */ + else if(avctx->width <= 1440) avctx->level = 6; /* High 1440 */ + else avctx->level = 4; /* High */ + } + } + + if((avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) && s->frame_rate_index != 4){ + av_log(avctx, AV_LOG_ERROR, "Drop frame time code only allowed with 1001/30000 fps\n"); + return -1; + } + + return 0; +} + +static void put_header(MpegEncContext *s, int header) +{ + align_put_bits(&s->pb); + put_bits(&s->pb, 16, header>>16); + put_bits(&s->pb, 16, header&0xFFFF); +} + +/* put sequence header if needed */ +static void mpeg1_encode_sequence_header(MpegEncContext *s) +{ + unsigned int vbv_buffer_size; + unsigned int fps, v; + int i; + uint64_t time_code; + float best_aspect_error= 1E10; + float aspect_ratio= av_q2d(s->avctx->sample_aspect_ratio); + int constraint_parameter_flag; + + if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA) + + if (s->current_picture.key_frame) { + AVRational framerate= ff_frame_rate_tab[s->frame_rate_index]; + + /* mpeg1 header repeated every gop */ + put_header(s, SEQ_START_CODE); + + put_bits(&s->pb, 12, s->width); + put_bits(&s->pb, 12, s->height); + + for(i=1; i<15; i++){ + float error= aspect_ratio; + if(s->codec_id == CODEC_ID_MPEG1VIDEO || i <=1) + error-= 1.0/ff_mpeg1_aspect[i]; + else + error-= av_q2d(ff_mpeg2_aspect[i])*s->height/s->width; + + error= FFABS(error); + + if(error < best_aspect_error){ + best_aspect_error= error; + s->aspect_ratio_info= i; + } + } + + put_bits(&s->pb, 4, s->aspect_ratio_info); + put_bits(&s->pb, 4, s->frame_rate_index); + + if(s->avctx->rc_max_rate){ + v = (s->avctx->rc_max_rate + 399) / 400; + if (v > 0x3ffff && s->codec_id == CODEC_ID_MPEG1VIDEO) + v = 0x3ffff; + }else{ + v= 0x3FFFF; + } + + if(s->avctx->rc_buffer_size) + vbv_buffer_size = s->avctx->rc_buffer_size; + else + /* VBV calculation: Scaled so that a VCD has the proper VBV size of 40 kilobytes */ + vbv_buffer_size = (( 20 * s->bit_rate) / (1151929 / 2)) * 8 * 1024; + vbv_buffer_size= (vbv_buffer_size + 16383) / 16384; + + put_bits(&s->pb, 18, v & 0x3FFFF); + put_bits(&s->pb, 1, 1); /* marker */ + put_bits(&s->pb, 10, vbv_buffer_size & 0x3FF); + + constraint_parameter_flag= + s->width <= 768 && s->height <= 576 && + s->mb_width * s->mb_height <= 396 && + s->mb_width * s->mb_height * framerate.num <= framerate.den*396*25 && + framerate.num <= framerate.den*30 && + s->avctx->me_range && s->avctx->me_range < 128 && + vbv_buffer_size <= 20 && + v <= 1856000/400 && + s->codec_id == CODEC_ID_MPEG1VIDEO; + + put_bits(&s->pb, 1, constraint_parameter_flag); + + ff_write_quant_matrix(&s->pb, s->avctx->intra_matrix); + ff_write_quant_matrix(&s->pb, s->avctx->inter_matrix); + + if(s->codec_id == CODEC_ID_MPEG2VIDEO){ + put_header(s, EXT_START_CODE); + put_bits(&s->pb, 4, 1); //seq ext + + put_bits(&s->pb, 1, s->avctx->profile == 0); //escx 1 for 4:2:2 profile */ + + put_bits(&s->pb, 3, s->avctx->profile); //profile + put_bits(&s->pb, 4, s->avctx->level); //level + + put_bits(&s->pb, 1, s->progressive_sequence); + put_bits(&s->pb, 2, s->chroma_format); + put_bits(&s->pb, 2, 0); //horizontal size ext + put_bits(&s->pb, 2, 0); //vertical size ext + put_bits(&s->pb, 12, v>>18); //bitrate ext + put_bits(&s->pb, 1, 1); //marker + put_bits(&s->pb, 8, vbv_buffer_size >>10); //vbv buffer ext + put_bits(&s->pb, 1, s->low_delay); + put_bits(&s->pb, 2, 0); // frame_rate_ext_n + put_bits(&s->pb, 5, 0); // frame_rate_ext_d + } + + put_header(s, GOP_START_CODE); + put_bits(&s->pb, 1, !!(s->avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE)); /* drop frame flag */ + /* time code : we must convert from the real frame rate to a + fake mpeg frame rate in case of low frame rate */ + fps = (framerate.num + framerate.den/2)/ framerate.den; + time_code = s->current_picture_ptr->coded_picture_number + s->avctx->timecode_frame_start; + + s->gop_picture_number = s->current_picture_ptr->coded_picture_number; + if (s->avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) { + /* only works for NTSC 29.97 */ + int d = time_code / 17982; + int m = time_code % 17982; + //if (m < 2) m += 2; /* not needed since -2,-1 / 1798 in C returns 0 */ + time_code += 18 * d + 2 * ((m - 2) / 1798); + } + put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24)); + put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60)); + put_bits(&s->pb, 1, 1); + put_bits(&s->pb, 6, (uint32_t)((time_code / fps) % 60)); + put_bits(&s->pb, 6, (uint32_t)((time_code % fps))); + put_bits(&s->pb, 1, !!(s->flags & CODEC_FLAG_CLOSED_GOP)); + put_bits(&s->pb, 1, 0); /* broken link */ + } +} + +static inline void encode_mb_skip_run(MpegEncContext *s, int run){ + while (run >= 33) { + put_bits(&s->pb, 11, 0x008); + run -= 33; + } + put_bits(&s->pb, ff_mpeg12_mbAddrIncrTable[run][1], + ff_mpeg12_mbAddrIncrTable[run][0]); +} + +static av_always_inline void put_qscale(MpegEncContext *s) +{ + if(s->q_scale_type){ + assert(s->qscale>=1 && s->qscale <=12); + put_bits(&s->pb, 5, inv_non_linear_qscale[s->qscale]); + }else{ + put_bits(&s->pb, 5, s->qscale); + } +} + +void ff_mpeg1_encode_slice_header(MpegEncContext *s){ + put_header(s, SLICE_MIN_START_CODE + s->mb_y); + put_qscale(s); + put_bits(&s->pb, 1, 0); /* slice extra information */ +} + +void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number) +{ + mpeg1_encode_sequence_header(s); + + /* mpeg1 picture header */ + put_header(s, PICTURE_START_CODE); + /* temporal reference */ + + // RAL: s->picture_number instead of s->fake_picture_number + put_bits(&s->pb, 10, (s->picture_number - + s->gop_picture_number) & 0x3ff); + put_bits(&s->pb, 3, s->pict_type); + + s->vbv_delay_ptr= s->pb.buf + put_bits_count(&s->pb)/8; + put_bits(&s->pb, 16, 0xFFFF); /* vbv_delay */ + + // RAL: Forward f_code also needed for B frames + if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) { + put_bits(&s->pb, 1, 0); /* half pel coordinates */ + if(s->codec_id == CODEC_ID_MPEG1VIDEO) + put_bits(&s->pb, 3, s->f_code); /* forward_f_code */ + else + put_bits(&s->pb, 3, 7); /* forward_f_code */ + } + + // RAL: Backward f_code necessary for B frames + if (s->pict_type == B_TYPE) { + put_bits(&s->pb, 1, 0); /* half pel coordinates */ + if(s->codec_id == CODEC_ID_MPEG1VIDEO) + put_bits(&s->pb, 3, s->b_code); /* backward_f_code */ + else + put_bits(&s->pb, 3, 7); /* backward_f_code */ + } + + put_bits(&s->pb, 1, 0); /* extra bit picture */ + + s->frame_pred_frame_dct = 1; + if(s->codec_id == CODEC_ID_MPEG2VIDEO){ + put_header(s, EXT_START_CODE); + put_bits(&s->pb, 4, 8); //pic ext + if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) { + put_bits(&s->pb, 4, s->f_code); + put_bits(&s->pb, 4, s->f_code); + }else{ + put_bits(&s->pb, 8, 255); + } + if (s->pict_type == B_TYPE) { + put_bits(&s->pb, 4, s->b_code); + put_bits(&s->pb, 4, s->b_code); + }else{ + put_bits(&s->pb, 8, 255); + } + put_bits(&s->pb, 2, s->intra_dc_precision); + + assert(s->picture_structure == PICT_FRAME); + put_bits(&s->pb, 2, s->picture_structure); + if (s->progressive_sequence) { + put_bits(&s->pb, 1, 0); /* no repeat */ + } else { + put_bits(&s->pb, 1, s->current_picture_ptr->top_field_first); + } + /* XXX: optimize the generation of this flag with entropy + measures */ + s->frame_pred_frame_dct = s->progressive_sequence; + + put_bits(&s->pb, 1, s->frame_pred_frame_dct); + put_bits(&s->pb, 1, s->concealment_motion_vectors); + put_bits(&s->pb, 1, s->q_scale_type); + put_bits(&s->pb, 1, s->intra_vlc_format); + put_bits(&s->pb, 1, s->alternate_scan); + put_bits(&s->pb, 1, s->repeat_first_field); + s->progressive_frame = s->progressive_sequence; + put_bits(&s->pb, 1, s->chroma_format == CHROMA_420 ? s->progressive_frame : 0); /* chroma_420_type */ + put_bits(&s->pb, 1, s->progressive_frame); + put_bits(&s->pb, 1, 0); //composite_display_flag + } + if(s->flags & CODEC_FLAG_SVCD_SCAN_OFFSET){ + int i; + + put_header(s, USER_START_CODE); + for(i=0; ipb, 8, svcd_scan_offset_placeholder[i]); + } + } + + s->mb_y=0; + ff_mpeg1_encode_slice_header(s); +} + +static inline void put_mb_modes(MpegEncContext *s, int n, int bits, + int has_mv, int field_motion) +{ + put_bits(&s->pb, n, bits); + if (!s->frame_pred_frame_dct) { + if (has_mv) + put_bits(&s->pb, 2, 2 - field_motion); /* motion_type: frame/field */ + put_bits(&s->pb, 1, s->interlaced_dct); + } +} + +static av_always_inline void mpeg1_encode_mb_internal(MpegEncContext *s, + DCTELEM block[6][64], + int motion_x, int motion_y, + int mb_block_count) +{ + int i, cbp; + const int mb_x = s->mb_x; + const int mb_y = s->mb_y; + const int first_mb= mb_x == s->resync_mb_x && mb_y == s->resync_mb_y; + + /* compute cbp */ + cbp = 0; + for(i=0;iblock_last_index[i] >= 0) + cbp |= 1 << (mb_block_count - 1 - i); + } + + if (cbp == 0 && !first_mb && s->mv_type == MV_TYPE_16X16 && + (mb_x != s->mb_width - 1 || (mb_y != s->mb_height - 1 && s->codec_id == CODEC_ID_MPEG1VIDEO)) && + ((s->pict_type == P_TYPE && (motion_x | motion_y) == 0) || + (s->pict_type == B_TYPE && s->mv_dir == s->last_mv_dir && (((s->mv_dir & MV_DIR_FORWARD) ? ((s->mv[0][0][0] - s->last_mv[0][0][0])|(s->mv[0][0][1] - s->last_mv[0][0][1])) : 0) | + ((s->mv_dir & MV_DIR_BACKWARD) ? ((s->mv[1][0][0] - s->last_mv[1][0][0])|(s->mv[1][0][1] - s->last_mv[1][0][1])) : 0)) == 0))) { + s->mb_skip_run++; + s->qscale -= s->dquant; + s->skip_count++; + s->misc_bits++; + s->last_bits++; + if(s->pict_type == P_TYPE){ + s->last_mv[0][1][0]= s->last_mv[0][0][0]= + s->last_mv[0][1][1]= s->last_mv[0][0][1]= 0; + } + } else { + if(first_mb){ + assert(s->mb_skip_run == 0); + encode_mb_skip_run(s, s->mb_x); + }else{ + encode_mb_skip_run(s, s->mb_skip_run); + } + + if (s->pict_type == I_TYPE) { + if(s->dquant && cbp){ + put_mb_modes(s, 2, 1, 0, 0); /* macroblock_type : macroblock_quant = 1 */ + put_qscale(s); + }else{ + put_mb_modes(s, 1, 1, 0, 0); /* macroblock_type : macroblock_quant = 0 */ + s->qscale -= s->dquant; + } + s->misc_bits+= get_bits_diff(s); + s->i_count++; + } else if (s->mb_intra) { + if(s->dquant && cbp){ + put_mb_modes(s, 6, 0x01, 0, 0); + put_qscale(s); + }else{ + put_mb_modes(s, 5, 0x03, 0, 0); + s->qscale -= s->dquant; + } + s->misc_bits+= get_bits_diff(s); + s->i_count++; + memset(s->last_mv, 0, sizeof(s->last_mv)); + } else if (s->pict_type == P_TYPE) { + if(s->mv_type == MV_TYPE_16X16){ + if (cbp != 0) { + if ((motion_x|motion_y) == 0) { + if(s->dquant){ + put_mb_modes(s, 5, 1, 0, 0); /* macroblock_pattern & quant */ + put_qscale(s); + }else{ + put_mb_modes(s, 2, 1, 0, 0); /* macroblock_pattern only */ + } + s->misc_bits+= get_bits_diff(s); + } else { + if(s->dquant){ + put_mb_modes(s, 5, 2, 1, 0); /* motion + cbp */ + put_qscale(s); + }else{ + put_mb_modes(s, 1, 1, 1, 0); /* motion + cbp */ + } + s->misc_bits+= get_bits_diff(s); + mpeg1_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code); // RAL: f_code parameter added + mpeg1_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code); // RAL: f_code parameter added + s->mv_bits+= get_bits_diff(s); + } + } else { + put_bits(&s->pb, 3, 1); /* motion only */ + if (!s->frame_pred_frame_dct) + put_bits(&s->pb, 2, 2); /* motion_type: frame */ + s->misc_bits+= get_bits_diff(s); + mpeg1_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code); // RAL: f_code parameter added + mpeg1_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code); // RAL: f_code parameter added + s->qscale -= s->dquant; + s->mv_bits+= get_bits_diff(s); + } + s->last_mv[0][1][0]= s->last_mv[0][0][0]= motion_x; + s->last_mv[0][1][1]= s->last_mv[0][0][1]= motion_y; + }else{ + assert(!s->frame_pred_frame_dct && s->mv_type == MV_TYPE_FIELD); + + if (cbp) { + if(s->dquant){ + put_mb_modes(s, 5, 2, 1, 1); /* motion + cbp */ + put_qscale(s); + }else{ + put_mb_modes(s, 1, 1, 1, 1); /* motion + cbp */ + } + } else { + put_bits(&s->pb, 3, 1); /* motion only */ + put_bits(&s->pb, 2, 1); /* motion_type: field */ + s->qscale -= s->dquant; + } + s->misc_bits+= get_bits_diff(s); + for(i=0; i<2; i++){ + put_bits(&s->pb, 1, s->field_select[0][i]); + mpeg1_encode_motion(s, s->mv[0][i][0] - s->last_mv[0][i][0] , s->f_code); + mpeg1_encode_motion(s, s->mv[0][i][1] - (s->last_mv[0][i][1]>>1), s->f_code); + s->last_mv[0][i][0]= s->mv[0][i][0]; + s->last_mv[0][i][1]= 2*s->mv[0][i][1]; + } + s->mv_bits+= get_bits_diff(s); + } + if(cbp) { + if (s->chroma_y_shift) { + put_bits(&s->pb, ff_mpeg12_mbPatTable[cbp][1], ff_mpeg12_mbPatTable[cbp][0]); + } else { + put_bits(&s->pb, ff_mpeg12_mbPatTable[cbp>>2][1], ff_mpeg12_mbPatTable[cbp>>2][0]); + put_bits(&s->pb, 2, cbp & 3); + } + } + s->f_count++; + } else{ + if(s->mv_type == MV_TYPE_16X16){ + if (cbp){ // With coded bloc pattern + if (s->dquant) { + if(s->mv_dir == MV_DIR_FORWARD) + put_mb_modes(s, 6, 3, 1, 0); + else + put_mb_modes(s, 8-s->mv_dir, 2, 1, 0); + put_qscale(s); + } else { + put_mb_modes(s, 5-s->mv_dir, 3, 1, 0); + } + }else{ // No coded bloc pattern + put_bits(&s->pb, 5-s->mv_dir, 2); + if (!s->frame_pred_frame_dct) + put_bits(&s->pb, 2, 2); /* motion_type: frame */ + s->qscale -= s->dquant; + } + s->misc_bits += get_bits_diff(s); + if (s->mv_dir&MV_DIR_FORWARD){ + mpeg1_encode_motion(s, s->mv[0][0][0] - s->last_mv[0][0][0], s->f_code); + mpeg1_encode_motion(s, s->mv[0][0][1] - s->last_mv[0][0][1], s->f_code); + s->last_mv[0][0][0]=s->last_mv[0][1][0]= s->mv[0][0][0]; + s->last_mv[0][0][1]=s->last_mv[0][1][1]= s->mv[0][0][1]; + s->f_count++; + } + if (s->mv_dir&MV_DIR_BACKWARD){ + mpeg1_encode_motion(s, s->mv[1][0][0] - s->last_mv[1][0][0], s->b_code); + mpeg1_encode_motion(s, s->mv[1][0][1] - s->last_mv[1][0][1], s->b_code); + s->last_mv[1][0][0]=s->last_mv[1][1][0]= s->mv[1][0][0]; + s->last_mv[1][0][1]=s->last_mv[1][1][1]= s->mv[1][0][1]; + s->b_count++; + } + }else{ + assert(s->mv_type == MV_TYPE_FIELD); + assert(!s->frame_pred_frame_dct); + if (cbp){ // With coded bloc pattern + if (s->dquant) { + if(s->mv_dir == MV_DIR_FORWARD) + put_mb_modes(s, 6, 3, 1, 1); + else + put_mb_modes(s, 8-s->mv_dir, 2, 1, 1); + put_qscale(s); + } else { + put_mb_modes(s, 5-s->mv_dir, 3, 1, 1); + } + }else{ // No coded bloc pattern + put_bits(&s->pb, 5-s->mv_dir, 2); + put_bits(&s->pb, 2, 1); /* motion_type: field */ + s->qscale -= s->dquant; + } + s->misc_bits += get_bits_diff(s); + if (s->mv_dir&MV_DIR_FORWARD){ + for(i=0; i<2; i++){ + put_bits(&s->pb, 1, s->field_select[0][i]); + mpeg1_encode_motion(s, s->mv[0][i][0] - s->last_mv[0][i][0] , s->f_code); + mpeg1_encode_motion(s, s->mv[0][i][1] - (s->last_mv[0][i][1]>>1), s->f_code); + s->last_mv[0][i][0]= s->mv[0][i][0]; + s->last_mv[0][i][1]= 2*s->mv[0][i][1]; + } + s->f_count++; + } + if (s->mv_dir&MV_DIR_BACKWARD){ + for(i=0; i<2; i++){ + put_bits(&s->pb, 1, s->field_select[1][i]); + mpeg1_encode_motion(s, s->mv[1][i][0] - s->last_mv[1][i][0] , s->b_code); + mpeg1_encode_motion(s, s->mv[1][i][1] - (s->last_mv[1][i][1]>>1), s->b_code); + s->last_mv[1][i][0]= s->mv[1][i][0]; + s->last_mv[1][i][1]= 2*s->mv[1][i][1]; + } + s->b_count++; + } + } + s->mv_bits += get_bits_diff(s); + if(cbp) { + if (s->chroma_y_shift) { + put_bits(&s->pb, ff_mpeg12_mbPatTable[cbp][1], ff_mpeg12_mbPatTable[cbp][0]); + } else { + put_bits(&s->pb, ff_mpeg12_mbPatTable[cbp>>2][1], ff_mpeg12_mbPatTable[cbp>>2][0]); + put_bits(&s->pb, 2, cbp & 3); + } + } + } + for(i=0;imb_skip_run = 0; + if(s->mb_intra) + s->i_tex_bits+= get_bits_diff(s); + else + s->p_tex_bits+= get_bits_diff(s); + } +} + +void mpeg1_encode_mb(MpegEncContext *s, DCTELEM block[6][64], int motion_x, int motion_y) +{ + if (s->chroma_format == CHROMA_420) mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 6); + else mpeg1_encode_mb_internal(s, block, motion_x, motion_y, 8); +} + +// RAL: Parameter added: f_or_b_code +static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code) +{ + int code, bit_size, l, bits, range, sign; + + if (val == 0) { + /* zero vector */ + code = 0; + put_bits(&s->pb, + ff_mpeg12_mbMotionVectorTable[0][1], + ff_mpeg12_mbMotionVectorTable[0][0]); + } else { + bit_size = f_or_b_code - 1; + range = 1 << bit_size; + /* modulo encoding */ + l= INT_BIT - 5 - bit_size; + val= (val<>l; + + if (val >= 0) { + val--; + code = (val >> bit_size) + 1; + bits = val & (range - 1); + sign = 0; + } else { + val = -val; + val--; + code = (val >> bit_size) + 1; + bits = val & (range - 1); + sign = 1; + } + + assert(code > 0 && code <= 16); + + put_bits(&s->pb, + ff_mpeg12_mbMotionVectorTable[code][1], + ff_mpeg12_mbMotionVectorTable[code][0]); + + put_bits(&s->pb, 1, sign); + if (bit_size > 0) { + put_bits(&s->pb, bit_size, bits); + } + } +} + +void ff_mpeg1_encode_init(MpegEncContext *s) +{ + static int done=0; + + ff_mpeg12_common_init(s); + + if(!done){ + int f_code; + int mv; + int i; + + done=1; + init_rl(&ff_rl_mpeg1, ff_mpeg12_static_rl_table_store[0]); + init_rl(&ff_rl_mpeg2, ff_mpeg12_static_rl_table_store[1]); + + for(i=0; i<64; i++) + { + mpeg1_max_level[0][i]= ff_rl_mpeg1.max_level[0][i]; + mpeg1_index_run[0][i]= ff_rl_mpeg1.index_run[0][i]; + } + + init_uni_ac_vlc(&ff_rl_mpeg1, uni_mpeg1_ac_vlc_len); + if(s->intra_vlc_format) + init_uni_ac_vlc(&ff_rl_mpeg2, uni_mpeg2_ac_vlc_len); + + /* build unified dc encoding tables */ + for(i=-255; i<256; i++) + { + int adiff, index; + int bits, code; + int diff=i; + + adiff = FFABS(diff); + if(diff<0) diff--; + index = av_log2(2*adiff); + + bits= ff_mpeg12_vlc_dc_lum_bits[index] + index; + code= (ff_mpeg12_vlc_dc_lum_code[index]<> bit_size) + 1; + if(code<17){ + len= ff_mpeg12_mbMotionVectorTable[code][1] + 1 + bit_size; + }else{ + len= ff_mpeg12_mbMotionVectorTable[16][1] + 2 + bit_size; + } + } + + mv_penalty[f_code][mv+MAX_MV]= len; + } + } + + + for(f_code=MAX_FCODE; f_code>0; f_code--){ + for(mv=-(8<me.mv_penalty= mv_penalty; + s->fcode_tab= fcode_tab; + if(s->codec_id == CODEC_ID_MPEG1VIDEO){ + s->min_qcoeff=-255; + s->max_qcoeff= 255; + }else{ + s->min_qcoeff=-2047; + s->max_qcoeff= 2047; + } + if (s->intra_vlc_format) { + s->intra_ac_vlc_length= + s->intra_ac_vlc_last_length= uni_mpeg2_ac_vlc_len; + } else { + s->intra_ac_vlc_length= + s->intra_ac_vlc_last_length= uni_mpeg1_ac_vlc_len; + } + s->inter_ac_vlc_length= + s->inter_ac_vlc_last_length= uni_mpeg1_ac_vlc_len; +} + +static inline void encode_dc(MpegEncContext *s, int diff, int component) +{ + if(((unsigned) (diff+255)) >= 511){ + int index; + + if(diff<0){ + index= av_log2_16bit(-2*diff); + diff--; + }else{ + index= av_log2_16bit(2*diff); + } + if (component == 0) { + put_bits( + &s->pb, + ff_mpeg12_vlc_dc_lum_bits[index] + index, + (ff_mpeg12_vlc_dc_lum_code[index]<pb, + ff_mpeg12_vlc_dc_chroma_bits[index] + index, + (ff_mpeg12_vlc_dc_chroma_code[index]<pb, + mpeg1_lum_dc_uni[diff+255]&0xFF, + mpeg1_lum_dc_uni[diff+255]>>8); + } else { + put_bits( + &s->pb, + mpeg1_chr_dc_uni[diff+255]&0xFF, + mpeg1_chr_dc_uni[diff+255]>>8); + } + } +} + +static void mpeg1_encode_block(MpegEncContext *s, + DCTELEM *block, + int n) +{ + int alevel, level, last_non_zero, dc, diff, i, j, run, last_index, sign; + int code, component; + const uint16_t (*table_vlc)[2] = ff_rl_mpeg1.table_vlc; + + last_index = s->block_last_index[n]; + + /* DC coef */ + if (s->mb_intra) { + component = (n <= 3 ? 0 : (n&1) + 1); + dc = block[0]; /* overflow is impossible */ + diff = dc - s->last_dc[component]; + encode_dc(s, diff, component); + s->last_dc[component] = dc; + i = 1; + if (s->intra_vlc_format) + table_vlc = ff_rl_mpeg2.table_vlc; + } else { + /* encode the first coefficient : needs to be done here because + it is handled slightly differently */ + level = block[0]; + if (abs(level) == 1) { + code = ((uint32_t)level >> 31); /* the sign bit */ + put_bits(&s->pb, 2, code | 0x02); + i = 1; + } else { + i = 0; + last_non_zero = -1; + goto next_coef; + } + } + + /* now quantify & encode AC coefs */ + last_non_zero = i - 1; + + for(;i<=last_index;i++) { + j = s->intra_scantable.permutated[i]; + level = block[j]; + next_coef: +#if 0 + if (level != 0) + dprintf(s->avctx, "level[%d]=%d\n", i, level); +#endif + /* encode using VLC */ + if (level != 0) { + run = i - last_non_zero - 1; + + alevel= level; + MASK_ABS(sign, alevel) + sign&=1; + + if (alevel <= mpeg1_max_level[0][run]){ + code= mpeg1_index_run[0][run] + alevel - 1; + /* store the vlc & sign at once */ + put_bits(&s->pb, table_vlc[code][1]+1, (table_vlc[code][0]<<1) + sign); + } else { + /* escape seems to be pretty rare <5% so I do not optimize it */ + put_bits(&s->pb, table_vlc[111][1], table_vlc[111][0]); + /* escape: only clip in this case */ + put_bits(&s->pb, 6, run); + if(s->codec_id == CODEC_ID_MPEG1VIDEO){ + if (alevel < 128) { + put_bits(&s->pb, 8, level & 0xff); + } else { + if (level < 0) { + put_bits(&s->pb, 16, 0x8001 + level + 255); + } else { + put_bits(&s->pb, 16, level & 0xffff); + } + } + }else{ + put_bits(&s->pb, 12, level & 0xfff); + } + } + last_non_zero = i; + } + } + /* end of block */ + put_bits(&s->pb, table_vlc[112][1], table_vlc[112][0]); +} + +AVCodec mpeg1video_encoder = { + "mpeg1video", + CODEC_TYPE_VIDEO, + CODEC_ID_MPEG1VIDEO, + sizeof(MpegEncContext), + encode_init, + MPV_encode_picture, + MPV_encode_end, + .supported_framerates= ff_frame_rate_tab+1, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, + .capabilities= CODEC_CAP_DELAY, +}; + +AVCodec mpeg2video_encoder = { + "mpeg2video", + CODEC_TYPE_VIDEO, + CODEC_ID_MPEG2VIDEO, + sizeof(MpegEncContext), + encode_init, + MPV_encode_picture, + MPV_encode_end, + .supported_framerates= ff_frame_rate_tab+1, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, -1}, + .capabilities= CODEC_CAP_DELAY, +}; diff --git a/contrib/ffmpeg/libavcodec/mpeg4data.h b/contrib/ffmpeg/libavcodec/mpeg4data.h index e199c6a14..ba8f9463c 100644 --- a/contrib/ffmpeg/libavcodec/mpeg4data.h +++ b/contrib/ffmpeg/libavcodec/mpeg4data.h @@ -25,6 +25,12 @@ * mpeg4 tables. */ +#ifndef FFMPEG_MPEG4DATA_H +#define FFMPEG_MPEG4DATA_H + +#include +#include "mpegvideo.h" + // shapes #define RECT_SHAPE 0 #define BIN_SHAPE 1 @@ -145,7 +151,8 @@ static RLTable rl_intra = { intra_level, }; -static const uint16_t inter_rvlc[170][2]={ //note this is identical to the intra rvlc except that its reordered +/* Note this is identical to the intra rvlc except that it is reordered. */ +static const uint16_t inter_rvlc[170][2]={ {0x0006, 3},{0x0001, 4},{0x0004, 5},{0x001C, 7}, {0x003C, 8},{0x003D, 8},{0x007C, 9},{0x00FC, 10}, {0x00FD, 10},{0x01FC, 11},{0x01FD, 11},{0x03FC, 12}, @@ -421,3 +428,5 @@ const uint16_t ff_mpeg4_resync_prefix[8]={ static const uint8_t mpeg4_dc_threshold[8]={ 99, 13, 15, 17, 19, 21, 23, 0 }; + +#endif /* FFMPEG_MPEG4DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/mpeg4video_parser.c b/contrib/ffmpeg/libavcodec/mpeg4video_parser.c new file mode 100644 index 000000000..9accc9126 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpeg4video_parser.c @@ -0,0 +1,138 @@ +/* + * MPEG4 Video frame extraction + * Copyright (c) 2003 Fabrice Bellard. + * Copyright (c) 2003 Michael Niedermayer. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "parser.h" +#include "mpegvideo.h" +#include "mpeg4video_parser.h" + + +int ff_mpeg4_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){ + int vop_found, i; + uint32_t state; + + vop_found= pc->frame_start_found; + state= pc->state; + + i=0; + if(!vop_found){ + for(i=0; iframe_start_found=0; + pc->state=-1; + return i-3; + } + } + } + pc->frame_start_found= vop_found; + pc->state= state; + return END_NOT_FOUND; +} + +/* XXX: make it use less memory */ +static int av_mpeg4_decode_header(AVCodecParserContext *s1, + AVCodecContext *avctx, + const uint8_t *buf, int buf_size) +{ + ParseContext1 *pc = s1->priv_data; + MpegEncContext *s = pc->enc; + GetBitContext gb1, *gb = &gb1; + int ret; + + s->avctx = avctx; + s->current_picture_ptr = &s->current_picture; + + if (avctx->extradata_size && pc->first_picture){ + init_get_bits(gb, avctx->extradata, avctx->extradata_size*8); + ret = ff_mpeg4_decode_picture_header(s, gb); + } + + init_get_bits(gb, buf, 8 * buf_size); + ret = ff_mpeg4_decode_picture_header(s, gb); + if (s->width) { + avcodec_set_dimensions(avctx, s->width, s->height); + } + s1->pict_type= s->pict_type; + pc->first_picture = 0; + return ret; +} + +static int mpeg4video_parse_init(AVCodecParserContext *s) +{ + ParseContext1 *pc = s->priv_data; + + pc->enc = av_mallocz(sizeof(MpegEncContext)); + if (!pc->enc) + return -1; + pc->first_picture = 1; + return 0; +} + +static int mpeg4video_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + ParseContext *pc = s->priv_data; + int next; + + if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ + next= buf_size; + }else{ + next= ff_mpeg4_find_frame_end(pc, buf, buf_size); + + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + } + av_mpeg4_decode_header(s, avctx, buf, buf_size); + + *poutbuf = buf; + *poutbuf_size = buf_size; + return next; +} + + +AVCodecParser mpeg4video_parser = { + { CODEC_ID_MPEG4 }, + sizeof(ParseContext1), + mpeg4video_parse_init, + mpeg4video_parse, + ff_parse1_close, + ff_mpeg4video_split, +}; diff --git a/contrib/ffmpeg/libavcodec/mpeg4video_parser.h b/contrib/ffmpeg/libavcodec/mpeg4video_parser.h new file mode 100644 index 000000000..125f6aa50 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpeg4video_parser.h @@ -0,0 +1,34 @@ +/* + * MPEG4 video parser prototypes + * Copyright (c) 2003 Fabrice Bellard. + * Copyright (c) 2003 Michael Niedermayer. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_MPEG4VIDEO_PARSER_H +#define FFMPEG_MPEG4VIDEO_PARSER_H + +#include "parser.h" + +/** + * finds the end of the current frame in the bitstream. + * @return the position of the first byte of the next frame, or -1 + */ +int ff_mpeg4_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size); + +#endif /* FFMPEG_MPEG4VIDEO_PARSER_H */ diff --git a/contrib/ffmpeg/libavcodec/mpegaudio.c b/contrib/ffmpeg/libavcodec/mpegaudio.c index aa93442d5..663427a43 100644 --- a/contrib/ffmpeg/libavcodec/mpegaudio.c +++ b/contrib/ffmpeg/libavcodec/mpegaudio.c @@ -1,6 +1,6 @@ /* - * The simplest mpeg audio layer 2 encoder - * Copyright (c) 2000, 2001 Fabrice Bellard. + * MPEG Audio common code + * Copyright (c) 2001, 2002 Fabrice Bellard. * * This file is part of FFmpeg. * @@ -21,779 +21,30 @@ /** * @file mpegaudio.c - * The simplest mpeg audio layer 2 encoder. + * MPEG Audio common code. */ -#include "avcodec.h" -#include "bitstream.h" #include "mpegaudio.h" -/* currently, cannot change these constants (need to modify - quantization stage) */ -#define MUL(a,b) (((int64_t)(a) * (int64_t)(b)) >> FRAC_BITS) -#define FIX(a) ((int)((a) * (1 << FRAC_BITS))) -#define SAMPLES_BUF_SIZE 4096 - -typedef struct MpegAudioContext { - PutBitContext pb; - int nb_channels; - int freq, bit_rate; - int lsf; /* 1 if mpeg2 low bitrate selected */ - int bitrate_index; /* bit rate */ - int freq_index; - int frame_size; /* frame size, in bits, without padding */ - int64_t nb_samples; /* total number of samples encoded */ - /* padding computation */ - int frame_frac, frame_frac_incr, do_padding; - short samples_buf[MPA_MAX_CHANNELS][SAMPLES_BUF_SIZE]; /* buffer for filter */ - int samples_offset[MPA_MAX_CHANNELS]; /* offset in samples_buf */ - int sb_samples[MPA_MAX_CHANNELS][3][12][SBLIMIT]; - unsigned char scale_factors[MPA_MAX_CHANNELS][SBLIMIT][3]; /* scale factors */ - /* code to group 3 scale factors */ - unsigned char scale_code[MPA_MAX_CHANNELS][SBLIMIT]; - int sblimit; /* number of used subbands */ - const unsigned char *alloc_table; -} MpegAudioContext; - -/* define it to use floats in quantization (I don't like floats !) */ -//#define USE_FLOATS - -#include "mpegaudiotab.h" - -static int MPA_encode_init(AVCodecContext *avctx) +/* bitrate is in kb/s */ +int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf) { - MpegAudioContext *s = avctx->priv_data; - int freq = avctx->sample_rate; - int bitrate = avctx->bit_rate; - int channels = avctx->channels; - int i, v, table; - float a; - - if (channels > 2) - return -1; - bitrate = bitrate / 1000; - s->nb_channels = channels; - s->freq = freq; - s->bit_rate = bitrate * 1000; - avctx->frame_size = MPA_FRAME_SIZE; - - /* encoding freq */ - s->lsf = 0; - for(i=0;i<3;i++) { - if (mpa_freq_tab[i] == freq) - break; - if ((mpa_freq_tab[i] / 2) == freq) { - s->lsf = 1; - break; - } - } - if (i == 3){ - av_log(avctx, AV_LOG_ERROR, "Sampling rate %d is not allowed in mp2\n", freq); - return -1; - } - s->freq_index = i; - - /* encoding bitrate & frequency */ - for(i=0;i<15;i++) { - if (mpa_bitrate_tab[s->lsf][1][i] == bitrate) - break; - } - if (i == 15){ - av_log(avctx, AV_LOG_ERROR, "bitrate %d is not allowed in mp2\n", bitrate); - return -1; - } - s->bitrate_index = i; - - /* compute total header size & pad bit */ - - a = (float)(bitrate * 1000 * MPA_FRAME_SIZE) / (freq * 8.0); - s->frame_size = ((int)a) * 8; - - /* frame fractional size to compute padding */ - s->frame_frac = 0; - s->frame_frac_incr = (int)((a - floor(a)) * 65536.0); - - /* select the right allocation table */ - table = l2_select_table(bitrate, s->nb_channels, freq, s->lsf); - - /* number of used subbands */ - s->sblimit = sblimit_table[table]; - s->alloc_table = alloc_tables[table]; + int ch_bitrate, table; -#ifdef DEBUG - av_log(avctx, AV_LOG_DEBUG, "%d kb/s, %d Hz, frame_size=%d bits, table=%d, padincr=%x\n", - bitrate, freq, s->frame_size, table, s->frame_frac_incr); -#endif - - for(i=0;inb_channels;i++) - s->samples_offset[i] = 0; - - for(i=0;i<257;i++) { - int v; - v = mpa_enwindow[i]; -#if WFRAC_BITS != 16 - v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS); -#endif - filter_bank[i] = v; - if ((i & 63) != 0) - v = -v; - if (i != 0) - filter_bank[512 - i] = v; - } - - for(i=0;i<64;i++) { - v = (int)(pow(2.0, (3 - i) / 3.0) * (1 << 20)); - if (v <= 0) - v = 1; - scale_factor_table[i] = v; -#ifdef USE_FLOATS - scale_factor_inv_table[i] = pow(2.0, -(3 - i) / 3.0) / (float)(1 << 20); -#else -#define P 15 - scale_factor_shift[i] = 21 - P - (i / 3); - scale_factor_mult[i] = (1 << P) * pow(2.0, (i % 3) / 3.0); -#endif - } - for(i=0;i<128;i++) { - v = i - 64; - if (v <= -3) - v = 0; - else if (v < 0) - v = 1; - else if (v == 0) - v = 2; - else if (v < 3) - v = 3; - else - v = 4; - scale_diff_table[i] = v; - } - - for(i=0;i<17;i++) { - v = quant_bits[i]; - if (v < 0) - v = -v; + ch_bitrate = bitrate / nb_channels; + if (!lsf) { + if ((freq == 48000 && ch_bitrate >= 56) || + (ch_bitrate >= 56 && ch_bitrate <= 80)) + table = 0; + else if (freq != 48000 && ch_bitrate >= 96) + table = 1; + else if (freq != 32000 && ch_bitrate <= 48) + table = 2; else - v = v * 3; - total_quant_bits[i] = 12 * v; - } - - avctx->coded_frame= avcodec_alloc_frame(); - avctx->coded_frame->key_frame= 1; - - return 0; -} - -/* 32 point floating point IDCT without 1/sqrt(2) coef zero scaling */ -static void idct32(int *out, int *tab) -{ - int i, j; - int *t, *t1, xr; - const int *xp = costab32; - - for(j=31;j>=3;j-=2) tab[j] += tab[j - 2]; - - t = tab + 30; - t1 = tab + 2; - do { - t[0] += t[-4]; - t[1] += t[1 - 4]; - t -= 4; - } while (t != t1); - - t = tab + 28; - t1 = tab + 4; - do { - t[0] += t[-8]; - t[1] += t[1-8]; - t[2] += t[2-8]; - t[3] += t[3-8]; - t -= 8; - } while (t != t1); - - t = tab; - t1 = tab + 32; - do { - t[ 3] = -t[ 3]; - t[ 6] = -t[ 6]; - - t[11] = -t[11]; - t[12] = -t[12]; - t[13] = -t[13]; - t[15] = -t[15]; - t += 16; - } while (t != t1); - - - t = tab; - t1 = tab + 8; - do { - int x1, x2, x3, x4; - - x3 = MUL(t[16], FIX(SQRT2*0.5)); - x4 = t[0] - x3; - x3 = t[0] + x3; - - x2 = MUL(-(t[24] + t[8]), FIX(SQRT2*0.5)); - x1 = MUL((t[8] - x2), xp[0]); - x2 = MUL((t[8] + x2), xp[1]); - - t[ 0] = x3 + x1; - t[ 8] = x4 - x2; - t[16] = x4 + x2; - t[24] = x3 - x1; - t++; - } while (t != t1); - - xp += 2; - t = tab; - t1 = tab + 4; - do { - xr = MUL(t[28],xp[0]); - t[28] = (t[0] - xr); - t[0] = (t[0] + xr); - - xr = MUL(t[4],xp[1]); - t[ 4] = (t[24] - xr); - t[24] = (t[24] + xr); - - xr = MUL(t[20],xp[2]); - t[20] = (t[8] - xr); - t[ 8] = (t[8] + xr); - - xr = MUL(t[12],xp[3]); - t[12] = (t[16] - xr); - t[16] = (t[16] + xr); - t++; - } while (t != t1); - xp += 4; - - for (i = 0; i < 4; i++) { - xr = MUL(tab[30-i*4],xp[0]); - tab[30-i*4] = (tab[i*4] - xr); - tab[ i*4] = (tab[i*4] + xr); - - xr = MUL(tab[ 2+i*4],xp[1]); - tab[ 2+i*4] = (tab[28-i*4] - xr); - tab[28-i*4] = (tab[28-i*4] + xr); - - xr = MUL(tab[31-i*4],xp[0]); - tab[31-i*4] = (tab[1+i*4] - xr); - tab[ 1+i*4] = (tab[1+i*4] + xr); - - xr = MUL(tab[ 3+i*4],xp[1]); - tab[ 3+i*4] = (tab[29-i*4] - xr); - tab[29-i*4] = (tab[29-i*4] + xr); - - xp += 2; - } - - t = tab + 30; - t1 = tab + 1; - do { - xr = MUL(t1[0], *xp); - t1[0] = (t[0] - xr); - t[0] = (t[0] + xr); - t -= 2; - t1 += 2; - xp++; - } while (t >= tab); - - for(i=0;i<32;i++) { - out[i] = tab[bitinv32[i]]; - } -} - -#define WSHIFT (WFRAC_BITS + 15 - FRAC_BITS) - -static void filter(MpegAudioContext *s, int ch, short *samples, int incr) -{ - short *p, *q; - int sum, offset, i, j; - int tmp[64]; - int tmp1[32]; - int *out; - - // print_pow1(samples, 1152); - - offset = s->samples_offset[ch]; - out = &s->sb_samples[ch][0][0][0]; - for(j=0;j<36;j++) { - /* 32 samples at once */ - for(i=0;i<32;i++) { - s->samples_buf[ch][offset + (31 - i)] = samples[0]; - samples += incr; - } - - /* filter */ - p = s->samples_buf[ch] + offset; - q = filter_bank; - /* maxsum = 23169 */ - for(i=0;i<64;i++) { - sum = p[0*64] * q[0*64]; - sum += p[1*64] * q[1*64]; - sum += p[2*64] * q[2*64]; - sum += p[3*64] * q[3*64]; - sum += p[4*64] * q[4*64]; - sum += p[5*64] * q[5*64]; - sum += p[6*64] * q[6*64]; - sum += p[7*64] * q[7*64]; - tmp[i] = sum; - p++; - q++; - } - tmp1[0] = tmp[16] >> WSHIFT; - for( i=1; i<=16; i++ ) tmp1[i] = (tmp[i+16]+tmp[16-i]) >> WSHIFT; - for( i=17; i<=31; i++ ) tmp1[i] = (tmp[i+16]-tmp[80-i]) >> WSHIFT; - - idct32(out, tmp1); - - /* advance of 32 samples */ - offset -= 32; - out += 32; - /* handle the wrap around */ - if (offset < 0) { - memmove(s->samples_buf[ch] + SAMPLES_BUF_SIZE - (512 - 32), - s->samples_buf[ch], (512 - 32) * 2); - offset = SAMPLES_BUF_SIZE - 512; - } - } - s->samples_offset[ch] = offset; - - // print_pow(s->sb_samples, 1152); -} - -static void compute_scale_factors(unsigned char scale_code[SBLIMIT], - unsigned char scale_factors[SBLIMIT][3], - int sb_samples[3][12][SBLIMIT], - int sblimit) -{ - int *p, vmax, v, n, i, j, k, code; - int index, d1, d2; - unsigned char *sf = &scale_factors[0][0]; - - for(j=0;j vmax) - vmax = v; - } - /* compute the scale factor index using log 2 computations */ - if (vmax > 0) { - n = av_log2(vmax); - /* n is the position of the MSB of vmax. now - use at most 2 compares to find the index */ - index = (21 - n) * 3 - 3; - if (index >= 0) { - while (vmax <= scale_factor_table[index+1]) - index++; - } else { - index = 0; /* very unlikely case of overflow */ - } - } else { - index = 62; /* value 63 is not allowed */ - } - -#if 0 - printf("%2d:%d in=%x %x %d\n", - j, i, vmax, scale_factor_table[index], index); -#endif - /* store the scale factor */ - assert(index >=0 && index <= 63); - sf[i] = index; - } - - /* compute the transmission factor : look if the scale factors - are close enough to each other */ - d1 = scale_diff_table[sf[0] - sf[1] + 64]; - d2 = scale_diff_table[sf[1] - sf[2] + 64]; - - /* handle the 25 cases */ - switch(d1 * 5 + d2) { - case 0*5+0: - case 0*5+4: - case 3*5+4: - case 4*5+0: - case 4*5+4: - code = 0; - break; - case 0*5+1: - case 0*5+2: - case 4*5+1: - case 4*5+2: - code = 3; - sf[2] = sf[1]; - break; - case 0*5+3: - case 4*5+3: - code = 3; - sf[1] = sf[2]; - break; - case 1*5+0: - case 1*5+4: - case 2*5+4: - code = 1; - sf[1] = sf[0]; - break; - case 1*5+1: - case 1*5+2: - case 2*5+0: - case 2*5+1: - case 2*5+2: - code = 2; - sf[1] = sf[2] = sf[0]; - break; - case 2*5+3: - case 3*5+3: - code = 2; - sf[0] = sf[1] = sf[2]; - break; - case 3*5+0: - case 3*5+1: - case 3*5+2: - code = 2; - sf[0] = sf[2] = sf[1]; - break; - case 1*5+3: - code = 2; - if (sf[0] > sf[2]) - sf[0] = sf[2]; - sf[1] = sf[2] = sf[0]; - break; - default: - assert(0); //cant happen - code = 0; /* kill warning */ - } - -#if 0 - printf("%d: %2d %2d %2d %d %d -> %d\n", j, - sf[0], sf[1], sf[2], d1, d2, code); -#endif - scale_code[j] = code; - sf += 3; - } -} - -/* The most important function : psycho acoustic module. In this - encoder there is basically none, so this is the worst you can do, - but also this is the simpler. */ -static void psycho_acoustic_model(MpegAudioContext *s, short smr[SBLIMIT]) -{ - int i; - - for(i=0;isblimit;i++) { - smr[i] = (int)(fixed_smr[i] * 10); - } -} - - -#define SB_NOTALLOCATED 0 -#define SB_ALLOCATED 1 -#define SB_NOMORE 2 - -/* Try to maximize the smr while using a number of bits inferior to - the frame size. I tried to make the code simpler, faster and - smaller than other encoders :-) */ -static void compute_bit_allocation(MpegAudioContext *s, - short smr1[MPA_MAX_CHANNELS][SBLIMIT], - unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT], - int *padding) -{ - int i, ch, b, max_smr, max_ch, max_sb, current_frame_size, max_frame_size; - int incr; - short smr[MPA_MAX_CHANNELS][SBLIMIT]; - unsigned char subband_status[MPA_MAX_CHANNELS][SBLIMIT]; - const unsigned char *alloc; - - memcpy(smr, smr1, s->nb_channels * sizeof(short) * SBLIMIT); - memset(subband_status, SB_NOTALLOCATED, s->nb_channels * SBLIMIT); - memset(bit_alloc, 0, s->nb_channels * SBLIMIT); - - /* compute frame size and padding */ - max_frame_size = s->frame_size; - s->frame_frac += s->frame_frac_incr; - if (s->frame_frac >= 65536) { - s->frame_frac -= 65536; - s->do_padding = 1; - max_frame_size += 8; + table = 3; } else { - s->do_padding = 0; - } - - /* compute the header + bit alloc size */ - current_frame_size = 32; - alloc = s->alloc_table; - for(i=0;isblimit;i++) { - incr = alloc[0]; - current_frame_size += incr * s->nb_channels; - alloc += 1 << incr; - } - for(;;) { - /* look for the subband with the largest signal to mask ratio */ - max_sb = -1; - max_ch = -1; - max_smr = 0x80000000; - for(ch=0;chnb_channels;ch++) { - for(i=0;isblimit;i++) { - if (smr[ch][i] > max_smr && subband_status[ch][i] != SB_NOMORE) { - max_smr = smr[ch][i]; - max_sb = i; - max_ch = ch; - } - } - } -#if 0 - printf("current=%d max=%d max_sb=%d alloc=%d\n", - current_frame_size, max_frame_size, max_sb, - bit_alloc[max_sb]); -#endif - if (max_sb < 0) - break; - - /* find alloc table entry (XXX: not optimal, should use - pointer table) */ - alloc = s->alloc_table; - for(i=0;iscale_code[max_ch][max_sb]] * 6; - incr += total_quant_bits[alloc[1]]; - } else { - /* increments bit allocation */ - b = bit_alloc[max_ch][max_sb]; - incr = total_quant_bits[alloc[b + 1]] - - total_quant_bits[alloc[b]]; - } - - if (current_frame_size + incr <= max_frame_size) { - /* can increase size */ - b = ++bit_alloc[max_ch][max_sb]; - current_frame_size += incr; - /* decrease smr by the resolution we added */ - smr[max_ch][max_sb] = smr1[max_ch][max_sb] - quant_snr[alloc[b]]; - /* max allocation size reached ? */ - if (b == ((1 << alloc[0]) - 1)) - subband_status[max_ch][max_sb] = SB_NOMORE; - else - subband_status[max_ch][max_sb] = SB_ALLOCATED; - } else { - /* cannot increase the size of this subband */ - subband_status[max_ch][max_sb] = SB_NOMORE; - } - } - *padding = max_frame_size - current_frame_size; - assert(*padding >= 0); - -#if 0 - for(i=0;isblimit;i++) { - printf("%d ", bit_alloc[i]); - } - printf("\n"); -#endif -} - -/* - * Output the mpeg audio layer 2 frame. Note how the code is small - * compared to other encoders :-) - */ -static void encode_frame(MpegAudioContext *s, - unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT], - int padding) -{ - int i, j, k, l, bit_alloc_bits, b, ch; - unsigned char *sf; - int q[3]; - PutBitContext *p = &s->pb; - - /* header */ - - put_bits(p, 12, 0xfff); - put_bits(p, 1, 1 - s->lsf); /* 1 = mpeg1 ID, 0 = mpeg2 lsf ID */ - put_bits(p, 2, 4-2); /* layer 2 */ - put_bits(p, 1, 1); /* no error protection */ - put_bits(p, 4, s->bitrate_index); - put_bits(p, 2, s->freq_index); - put_bits(p, 1, s->do_padding); /* use padding */ - put_bits(p, 1, 0); /* private_bit */ - put_bits(p, 2, s->nb_channels == 2 ? MPA_STEREO : MPA_MONO); - put_bits(p, 2, 0); /* mode_ext */ - put_bits(p, 1, 0); /* no copyright */ - put_bits(p, 1, 1); /* original */ - put_bits(p, 2, 0); /* no emphasis */ - - /* bit allocation */ - j = 0; - for(i=0;isblimit;i++) { - bit_alloc_bits = s->alloc_table[j]; - for(ch=0;chnb_channels;ch++) { - put_bits(p, bit_alloc_bits, bit_alloc[ch][i]); - } - j += 1 << bit_alloc_bits; - } - - /* scale codes */ - for(i=0;isblimit;i++) { - for(ch=0;chnb_channels;ch++) { - if (bit_alloc[ch][i]) - put_bits(p, 2, s->scale_code[ch][i]); - } - } - - /* scale factors */ - for(i=0;isblimit;i++) { - for(ch=0;chnb_channels;ch++) { - if (bit_alloc[ch][i]) { - sf = &s->scale_factors[ch][i][0]; - switch(s->scale_code[ch][i]) { - case 0: - put_bits(p, 6, sf[0]); - put_bits(p, 6, sf[1]); - put_bits(p, 6, sf[2]); - break; - case 3: - case 1: - put_bits(p, 6, sf[0]); - put_bits(p, 6, sf[2]); - break; - case 2: - put_bits(p, 6, sf[0]); - break; - } - } - } - } - - /* quantization & write sub band samples */ - - for(k=0;k<3;k++) { - for(l=0;l<12;l+=3) { - j = 0; - for(i=0;isblimit;i++) { - bit_alloc_bits = s->alloc_table[j]; - for(ch=0;chnb_channels;ch++) { - b = bit_alloc[ch][i]; - if (b) { - int qindex, steps, m, sample, bits; - /* we encode 3 sub band samples of the same sub band at a time */ - qindex = s->alloc_table[j+b]; - steps = quant_steps[qindex]; - for(m=0;m<3;m++) { - sample = s->sb_samples[ch][k][l + m][i]; - /* divide by scale factor */ -#ifdef USE_FLOATS - { - float a; - a = (float)sample * scale_factor_inv_table[s->scale_factors[ch][i][k]]; - q[m] = (int)((a + 1.0) * steps * 0.5); - } -#else - { - int q1, e, shift, mult; - e = s->scale_factors[ch][i][k]; - shift = scale_factor_shift[e]; - mult = scale_factor_mult[e]; - - /* normalize to P bits */ - if (shift < 0) - q1 = sample << (-shift); - else - q1 = sample >> shift; - q1 = (q1 * mult) >> P; - q[m] = ((q1 + (1 << P)) * steps) >> (P + 1); - } -#endif - if (q[m] >= steps) - q[m] = steps - 1; - assert(q[m] >= 0 && q[m] < steps); - } - bits = quant_bits[qindex]; - if (bits < 0) { - /* group the 3 values to save bits */ - put_bits(p, -bits, - q[0] + steps * (q[1] + steps * q[2])); -#if 0 - printf("%d: gr1 %d\n", - i, q[0] + steps * (q[1] + steps * q[2])); -#endif - } else { -#if 0 - printf("%d: gr3 %d %d %d\n", - i, q[0], q[1], q[2]); -#endif - put_bits(p, bits, q[0]); - put_bits(p, bits, q[1]); - put_bits(p, bits, q[2]); - } - } - } - /* next subband in alloc table */ - j += 1 << bit_alloc_bits; - } - } - } - - /* padding */ - for(i=0;ipriv_data; - short *samples = data; - short smr[MPA_MAX_CHANNELS][SBLIMIT]; - unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT]; - int padding, i; - - for(i=0;inb_channels;i++) { - filter(s, i, samples + i, s->nb_channels); - } - - for(i=0;inb_channels;i++) { - compute_scale_factors(s->scale_code[i], s->scale_factors[i], - s->sb_samples[i], s->sblimit); - } - for(i=0;inb_channels;i++) { - psycho_acoustic_model(s, smr[i]); + table = 4; } - compute_bit_allocation(s, smr, bit_alloc, &padding); - - init_put_bits(&s->pb, frame, MPA_MAX_CODED_FRAME_SIZE); - - encode_frame(s, bit_alloc, padding); - - s->nb_samples += MPA_FRAME_SIZE; - return pbBufPtr(&s->pb) - s->pb.buf; -} - -static int MPA_encode_close(AVCodecContext *avctx) -{ - av_freep(&avctx->coded_frame); - return 0; + return table; } - -AVCodec mp2_encoder = { - "mp2", - CODEC_TYPE_AUDIO, - CODEC_ID_MP2, - sizeof(MpegAudioContext), - MPA_encode_init, - MPA_encode_frame, - MPA_encode_close, - NULL, -}; - -#undef FIX diff --git a/contrib/ffmpeg/libavcodec/mpegaudio.h b/contrib/ffmpeg/libavcodec/mpegaudio.h index 3eadf92a8..6d602a1dc 100644 --- a/contrib/ffmpeg/libavcodec/mpegaudio.h +++ b/contrib/ffmpeg/libavcodec/mpegaudio.h @@ -23,6 +23,13 @@ * mpeg audio declarations for both encoder and decoder. */ +#ifndef FFMPEG_MPEGAUDIO_H +#define FFMPEG_MPEGAUDIO_H + +#include "avcodec.h" +#include "bitstream.h" +#include "dsputil.h" + /* max frame size, in samples */ #define MPA_FRAME_SIZE 1152 @@ -42,6 +49,8 @@ #define SAME_HEADER_MASK \ (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19)) +#define MP3_MASK 0xFFFE0CCF + /* define USE_HIGHPRECISION to have a bit exact (but slower) mpeg audio decoder */ @@ -53,6 +62,10 @@ #define WFRAC_BITS 14 /* fractional bits for window */ #endif +#define FRAC_ONE (1 << FRAC_BITS) + +#define FIX(a) ((int)((a) * FRAC_ONE)) + #if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT) typedef int32_t OUT_INT; #define OUT_MAX INT32_MAX @@ -71,23 +84,57 @@ typedef int16_t MPA_INT; typedef int32_t MPA_INT; #endif -int l2_select_table(int bitrate, int nb_channels, int freq, int lsf); -int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate); +#define BACKSTEP_SIZE 512 +#define EXTRABYTES 24 + +struct GranuleDef; + +typedef struct MPADecodeContext { + DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]); + int last_buf_size; + int frame_size; + /* next header (used in free format parsing) */ + uint32_t free_format_next_header; + int error_protection; + int layer; + int sample_rate; + int sample_rate_index; /* between 0 and 8 */ + int bit_rate; + GetBitContext gb; + GetBitContext in_gb; + int nb_channels; + int mode; + int mode_ext; + int lsf; + DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512 * 2]); + int synth_buf_offset[MPA_MAX_CHANNELS]; + DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]); + int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */ +#ifdef DEBUG + int frame_count; +#endif + void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g); + int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3 + int dither_state; + int error_resilience; + AVCodecContext* avctx; +} MPADecodeContext; + +/* layer 3 huffman tables */ +typedef struct HuffTable { + int xsize; + const uint8_t *bits; + const uint16_t *codes; +} HuffTable; + +int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf); +int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate); void ff_mpa_synth_init(MPA_INT *window); void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset, MPA_INT *window, int *dither_state, OUT_INT *samples, int incr, int32_t sb_samples[SBLIMIT]); -extern const uint16_t mpa_bitrate_tab[2][3][15]; -extern const uint16_t mpa_freq_tab[3]; -extern const unsigned char *alloc_tables[5]; -extern const double enwindow[512]; -extern const int sblimit_table[5]; -extern const int quant_steps[17]; -extern const int quant_bits[17]; -extern const int32_t mpa_enwindow[257]; - /* fast header check for resync */ static inline int ff_mpa_check_header(uint32_t header){ /* header */ @@ -104,3 +151,5 @@ static inline int ff_mpa_check_header(uint32_t header){ return -1; return 0; } + +#endif /* FFMPEG_MPEGAUDIO_H */ diff --git a/contrib/ffmpeg/libavcodec/mpegaudio_parser.c b/contrib/ffmpeg/libavcodec/mpegaudio_parser.c new file mode 100644 index 000000000..e7cb7439e --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpegaudio_parser.c @@ -0,0 +1,252 @@ +/* + * MPEG Audio parser + * Copyright (c) 2003 Fabrice Bellard. + * Copyright (c) 2003 Michael Niedermayer. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "parser.h" +#include "mpegaudio.h" +#include "mpegaudiodecheader.h" + + +typedef struct MpegAudioParseContext { + uint8_t inbuf[MPA_MAX_CODED_FRAME_SIZE]; /* input buffer */ + uint8_t *inbuf_ptr; + int frame_size; + int free_format_frame_size; + int free_format_next_header; + uint32_t header; + int header_count; +} MpegAudioParseContext; + +#define MPA_HEADER_SIZE 4 + +/* header + layer + bitrate + freq + lsf/mpeg25 */ +#undef SAME_HEADER_MASK /* mpegaudio.h defines different version */ +#define SAME_HEADER_MASK \ + (0xffe00000 | (3 << 17) | (3 << 10) | (3 << 19)) + +/* useful helper to get mpeg audio stream infos. Return -1 if error in + header, otherwise the coded frame size in bytes */ +int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate) +{ + MPADecodeContext s1, *s = &s1; + s1.avctx = avctx; + + if (ff_mpa_check_header(head) != 0) + return -1; + + if (ff_mpegaudio_decode_header(s, head) != 0) { + return -1; + } + + switch(s->layer) { + case 1: + avctx->frame_size = 384; + break; + case 2: + avctx->frame_size = 1152; + break; + default: + case 3: + if (s->lsf) + avctx->frame_size = 576; + else + avctx->frame_size = 1152; + break; + } + + *sample_rate = s->sample_rate; + avctx->channels = s->nb_channels; + avctx->bit_rate = s->bit_rate; + avctx->sub_id = s->layer; + return s->frame_size; +} + +static int mpegaudio_parse_init(AVCodecParserContext *s1) +{ + MpegAudioParseContext *s = s1->priv_data; + s->inbuf_ptr = s->inbuf; + return 0; +} + +static int mpegaudio_parse(AVCodecParserContext *s1, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + MpegAudioParseContext *s = s1->priv_data; + int len, ret, sr; + uint32_t header; + const uint8_t *buf_ptr; + + *poutbuf = NULL; + *poutbuf_size = 0; + buf_ptr = buf; + while (buf_size > 0) { + len = s->inbuf_ptr - s->inbuf; + if (s->frame_size == 0) { + /* special case for next header for first frame in free + format case (XXX: find a simpler method) */ + if (s->free_format_next_header != 0) { + AV_WB32(s->inbuf, s->free_format_next_header); + s->inbuf_ptr = s->inbuf + 4; + s->free_format_next_header = 0; + goto got_header; + } + /* no header seen : find one. We need at least MPA_HEADER_SIZE + bytes to parse it */ + len = FFMIN(MPA_HEADER_SIZE - len, buf_size); + if (len > 0) { + memcpy(s->inbuf_ptr, buf_ptr, len); + buf_ptr += len; + buf_size -= len; + s->inbuf_ptr += len; + } + if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) { + got_header: + header = AV_RB32(s->inbuf); + + ret = ff_mpa_decode_header(avctx, header, &sr); + if (ret < 0) { + s->header_count= -2; + /* no sync found : move by one byte (inefficient, but simple!) */ + memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); + s->inbuf_ptr--; + dprintf(avctx, "skip %x\n", header); + /* reset free format frame size to give a chance + to get a new bitrate */ + s->free_format_frame_size = 0; + } else { + if((header&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header) + s->header_count= -3; + s->header= header; + s->header_count++; + s->frame_size = ret; + +#if 0 + /* free format: prepare to compute frame size */ + if (ff_mpegaudio_decode_header(s, header) == 1) { + s->frame_size = -1; + } +#endif + if(s->header_count > 1) + avctx->sample_rate= sr; + } + } + } else +#if 0 + if (s->frame_size == -1) { + /* free format : find next sync to compute frame size */ + len = MPA_MAX_CODED_FRAME_SIZE - len; + if (len > buf_size) + len = buf_size; + if (len == 0) { + /* frame too long: resync */ + s->frame_size = 0; + memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); + s->inbuf_ptr--; + } else { + uint8_t *p, *pend; + uint32_t header1; + int padding; + + memcpy(s->inbuf_ptr, buf_ptr, len); + /* check for header */ + p = s->inbuf_ptr - 3; + pend = s->inbuf_ptr + len - 4; + while (p <= pend) { + header = AV_RB32(p); + header1 = AV_RB32(s->inbuf); + /* check with high probability that we have a + valid header */ + if ((header & SAME_HEADER_MASK) == + (header1 & SAME_HEADER_MASK)) { + /* header found: update pointers */ + len = (p + 4) - s->inbuf_ptr; + buf_ptr += len; + buf_size -= len; + s->inbuf_ptr = p; + /* compute frame size */ + s->free_format_next_header = header; + s->free_format_frame_size = s->inbuf_ptr - s->inbuf; + padding = (header1 >> 9) & 1; + if (s->layer == 1) + s->free_format_frame_size -= padding * 4; + else + s->free_format_frame_size -= padding; + dprintf(avctx, "free frame size=%d padding=%d\n", + s->free_format_frame_size, padding); + ff_mpegaudio_decode_header(s, header1); + goto next_data; + } + p++; + } + /* not found: simply increase pointers */ + buf_ptr += len; + s->inbuf_ptr += len; + buf_size -= len; + } + } else +#endif + if (len < s->frame_size) { + if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE) + s->frame_size = MPA_MAX_CODED_FRAME_SIZE; + len = FFMIN(s->frame_size - len, buf_size); + memcpy(s->inbuf_ptr, buf_ptr, len); + buf_ptr += len; + s->inbuf_ptr += len; + buf_size -= len; + } + + if(s->frame_size > 0 && buf_ptr - buf == s->inbuf_ptr - s->inbuf + && buf_size + buf_ptr - buf >= s->frame_size){ + if(s->header_count > 0){ + *poutbuf = buf; + *poutbuf_size = s->frame_size; + } + buf_ptr = buf + s->frame_size; + s->inbuf_ptr = s->inbuf; + s->frame_size = 0; + break; + } + + // next_data: + if (s->frame_size > 0 && + (s->inbuf_ptr - s->inbuf) >= s->frame_size) { + if(s->header_count > 0){ + *poutbuf = s->inbuf; + *poutbuf_size = s->inbuf_ptr - s->inbuf; + } + s->inbuf_ptr = s->inbuf; + s->frame_size = 0; + break; + } + } + return buf_ptr - buf; +} + + +AVCodecParser mpegaudio_parser = { + { CODEC_ID_MP2, CODEC_ID_MP3 }, + sizeof(MpegAudioParseContext), + mpegaudio_parse_init, + mpegaudio_parse, + NULL, +}; diff --git a/contrib/ffmpeg/libavcodec/mpegaudiodata.c b/contrib/ffmpeg/libavcodec/mpegaudiodata.c new file mode 100644 index 000000000..5089c9567 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpegaudiodata.c @@ -0,0 +1,225 @@ +/* + * MPEG Audio common tables + * copyright (c) 2002 Fabrice Bellard + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mpegaudiodata.c + * mpeg audio layer common tables. + */ + +#include "mpegaudiodata.h" + + +const uint16_t ff_mpa_bitrate_tab[2][3][15] = { + { {0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 }, + {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 }, + {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 } }, + { {0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256}, + {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160}, + {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160} + } +}; + +const uint16_t ff_mpa_freq_tab[3] = { 44100, 48000, 32000 }; + +/*******************************************************/ +/* half mpeg encoding window (full precision) */ +const int32_t ff_mpa_enwindow[257] = { + 0, -1, -1, -1, -1, -1, -1, -2, + -2, -2, -2, -3, -3, -4, -4, -5, + -5, -6, -7, -7, -8, -9, -10, -11, + -13, -14, -16, -17, -19, -21, -24, -26, + -29, -31, -35, -38, -41, -45, -49, -53, + -58, -63, -68, -73, -79, -85, -91, -97, + -104, -111, -117, -125, -132, -139, -147, -154, + -161, -169, -176, -183, -190, -196, -202, -208, + 213, 218, 222, 225, 227, 228, 228, 227, + 224, 221, 215, 208, 200, 189, 177, 163, + 146, 127, 106, 83, 57, 29, -2, -36, + -72, -111, -153, -197, -244, -294, -347, -401, + -459, -519, -581, -645, -711, -779, -848, -919, + -991, -1064, -1137, -1210, -1283, -1356, -1428, -1498, + -1567, -1634, -1698, -1759, -1817, -1870, -1919, -1962, + -2001, -2032, -2057, -2075, -2085, -2087, -2080, -2063, + 2037, 2000, 1952, 1893, 1822, 1739, 1644, 1535, + 1414, 1280, 1131, 970, 794, 605, 402, 185, + -45, -288, -545, -814, -1095, -1388, -1692, -2006, + -2330, -2663, -3004, -3351, -3705, -4063, -4425, -4788, + -5153, -5517, -5879, -6237, -6589, -6935, -7271, -7597, + -7910, -8209, -8491, -8755, -8998, -9219, -9416, -9585, + -9727, -9838, -9916, -9959, -9966, -9935, -9863, -9750, + -9592, -9389, -9139, -8840, -8492, -8092, -7640, -7134, + 6574, 5959, 5288, 4561, 3776, 2935, 2037, 1082, + 70, -998, -2122, -3300, -4533, -5818, -7154, -8540, + -9975,-11455,-12980,-14548,-16155,-17799,-19478,-21189, +-22929,-24694,-26482,-28289,-30112,-31947,-33791,-35640, +-37489,-39336,-41176,-43006,-44821,-46617,-48390,-50137, +-51853,-53534,-55178,-56778,-58333,-59838,-61289,-62684, +-64019,-65290,-66494,-67629,-68692,-69679,-70590,-71420, +-72169,-72835,-73415,-73908,-74313,-74630,-74856,-74992, + 75038, +}; + +/*******************************************************/ +/* layer 2 tables */ + +const int ff_mpa_sblimit_table[5] = { 27 , 30 , 8, 12 , 30 }; + +const int ff_mpa_quant_steps[17] = { + 3, 5, 7, 9, 15, + 31, 63, 127, 255, 511, + 1023, 2047, 4095, 8191, 16383, + 32767, 65535 +}; + +/* we use a negative value if grouped */ +const int ff_mpa_quant_bits[17] = { + -5, -7, 3, -10, 4, + 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, + 15, 16 +}; + +/* encoding tables which give the quantization index. Note how it is + possible to store them efficiently ! */ +static const unsigned char alloc_table_0[] = { + 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 2, 0, 1, 16, + 2, 0, 1, 16, + 2, 0, 1, 16, + 2, 0, 1, 16, +}; + +static const unsigned char alloc_table_1[] = { + 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 3, 0, 1, 2, 3, 4, 5, 16, + 2, 0, 1, 16, + 2, 0, 1, 16, + 2, 0, 1, 16, + 2, 0, 1, 16, + 2, 0, 1, 16, + 2, 0, 1, 16, + 2, 0, 1, 16, +}; + +static const unsigned char alloc_table_2[] = { + 4, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 4, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, +}; + +static const unsigned char alloc_table_3[] = { + 4, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 4, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, +}; + +static const unsigned char alloc_table_4[] = { + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 3, 0, 1, 3, 4, 5, 6, 7, + 2, 0, 1, 3, + 2, 0, 1, 3, + 2, 0, 1, 3, + 2, 0, 1, 3, + 2, 0, 1, 3, + 2, 0, 1, 3, + 2, 0, 1, 3, + 2, 0, 1, 3, + 2, 0, 1, 3, + 2, 0, 1, 3, + 2, 0, 1, 3, + 2, 0, 1, 3, + 2, 0, 1, 3, + 2, 0, 1, 3, + 2, 0, 1, 3, + 2, 0, 1, 3, + 2, 0, 1, 3, + 2, 0, 1, 3, + 2, 0, 1, 3, +}; + +const unsigned char *ff_mpa_alloc_tables[5] = +{ alloc_table_0, alloc_table_1, alloc_table_2, alloc_table_3, alloc_table_4, }; diff --git a/contrib/ffmpeg/libavcodec/mpegaudiodata.h b/contrib/ffmpeg/libavcodec/mpegaudiodata.h new file mode 100644 index 000000000..d513645b5 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpegaudiodata.h @@ -0,0 +1,43 @@ +/* + * MPEG Audio common tables + * copyright (c) 2002 Fabrice Bellard + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mpegaudiodata.h + * mpeg audio layer common tables. + */ + +#ifndef FFMPEG_MPEGAUDIODATA_H +#define FFMPEG_MPEGAUDIODATA_H + +#include "common.h" + +#define MODE_EXT_MS_STEREO 2 +#define MODE_EXT_I_STEREO 1 + +extern const uint16_t ff_mpa_bitrate_tab[2][3][15]; +extern const uint16_t ff_mpa_freq_tab[3]; +extern const int32_t ff_mpa_enwindow[257]; +extern const int ff_mpa_sblimit_table[5]; +extern const int ff_mpa_quant_steps[17]; +extern const int ff_mpa_quant_bits[17]; +extern const unsigned char *ff_mpa_alloc_tables[5]; + +#endif /* FFMPEG_MPEGAUDIODATA_H */ diff --git a/contrib/ffmpeg/libavcodec/mpegaudiodec.c b/contrib/ffmpeg/libavcodec/mpegaudiodec.c index d64c9f611..98f7f3b5e 100644 --- a/contrib/ffmpeg/libavcodec/mpegaudiodec.c +++ b/contrib/ffmpeg/libavcodec/mpegaudiodec.c @@ -42,12 +42,10 @@ #endif #include "mpegaudio.h" +#include "mpegaudiodecheader.h" #include "mathops.h" -#define FRAC_ONE (1 << FRAC_BITS) - -#define FIX(a) ((int)((a) * FRAC_ONE)) /* WARNING: only correct for posititive numbers */ #define FIXR(a) ((int)((a) * FRAC_ONE + 0.5)) #define FRAC_RND(a) (((a) + (FRAC_ONE/2)) >> FRAC_BITS) @@ -57,41 +55,6 @@ /****************/ #define HEADER_SIZE 4 -#define BACKSTEP_SIZE 512 -#define EXTRABYTES 24 - -struct GranuleDef; - -typedef struct MPADecodeContext { - DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]); - int last_buf_size; - int frame_size; - /* next header (used in free format parsing) */ - uint32_t free_format_next_header; - int error_protection; - int layer; - int sample_rate; - int sample_rate_index; /* between 0 and 8 */ - int bit_rate; - GetBitContext gb; - GetBitContext in_gb; - int nb_channels; - int mode; - int mode_ext; - int lsf; - MPA_INT synth_buf[MPA_MAX_CHANNELS][512 * 2] __attribute__((aligned(16))); - int synth_buf_offset[MPA_MAX_CHANNELS]; - int32_t sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT] __attribute__((aligned(16))); - int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */ -#ifdef DEBUG - int frame_count; -#endif - void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g); - int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3 - int dither_state; - int error_resilience; - AVCodecContext* avctx; -} MPADecodeContext; /** * Context for MP3On4 decoder @@ -122,16 +85,7 @@ typedef struct GranuleDef { int32_t sb_hybrid[SBLIMIT * 18]; /* 576 samples */ } GranuleDef; -#define MODE_EXT_MS_STEREO 2 -#define MODE_EXT_I_STEREO 1 - -/* layer 3 huffman tables */ -typedef struct HuffTable { - int xsize; - const uint8_t *bits; - const uint16_t *codes; -} HuffTable; - +#include "mpegaudiodata.h" #include "mpegaudiodectab.h" static void compute_antialias_integer(MPADecodeContext *s, GranuleDef *g); @@ -170,7 +124,69 @@ static const int32_t scale_factor_mult2[3][3] = { SCALE_GEN(4.0 / 9.0), /* 9 steps */ }; -static MPA_INT window[512] __attribute__((aligned(16))); +static DECLARE_ALIGNED_16(MPA_INT, window[512]); + +/** + * Convert region offsets to region sizes and truncate + * size to big_values. + */ +void ff_region_offset2size(GranuleDef *g){ + int i, k, j=0; + g->region_size[2] = (576 / 2); + for(i=0;i<3;i++) { + k = FFMIN(g->region_size[i], g->big_values); + g->region_size[i] = k - j; + j = k; + } +} + +void ff_init_short_region(MPADecodeContext *s, GranuleDef *g){ + if (g->block_type == 2) + g->region_size[0] = (36 / 2); + else { + if (s->sample_rate_index <= 2) + g->region_size[0] = (36 / 2); + else if (s->sample_rate_index != 8) + g->region_size[0] = (54 / 2); + else + g->region_size[0] = (108 / 2); + } + g->region_size[1] = (576 / 2); +} + +void ff_init_long_region(MPADecodeContext *s, GranuleDef *g, int ra1, int ra2){ + int l; + g->region_size[0] = + band_index_long[s->sample_rate_index][ra1 + 1] >> 1; + /* should not overflow */ + l = FFMIN(ra1 + ra2 + 2, 22); + g->region_size[1] = + band_index_long[s->sample_rate_index][l] >> 1; +} + +void ff_compute_band_indexes(MPADecodeContext *s, GranuleDef *g){ + if (g->block_type == 2) { + if (g->switch_point) { + /* if switched mode, we handle the 36 first samples as + long blocks. For 8000Hz, we handle the 48 first + exponents as long blocks (XXX: check this!) */ + if (s->sample_rate_index <= 2) + g->long_end = 8; + else if (s->sample_rate_index != 8) + g->long_end = 6; + else + g->long_end = 4; /* 8000 Hz */ + + g->short_start = 2 + (s->sample_rate_index != 8); + } else { + g->long_end = 0; + g->short_start = 0; + } + } else { + g->short_start = 13; + g->long_end = 22; + } +} /* layer 1 unscaling */ /* n = number of bits of the mantissa minus 1 */ @@ -824,7 +840,7 @@ void ff_mpa_synth_init(MPA_INT *window) /* max = 18760, max sum over all 16 coefs : 44736 */ for(i=0;i<257;i++) { int v; - v = mpa_enwindow[i]; + v = ff_mpa_enwindow[i]; #if WFRAC_BITS < 16 v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS); #endif @@ -865,10 +881,7 @@ void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset, #if FRAC_BITS <= 15 /* NOTE: can cause a loss in precision if very high amplitude sound */ - if (v > 32767) - v = 32767; - else if (v < -32768) - v = -32768; + v = av_clip_int16(v); #endif synth_buf[j] = v; } @@ -1106,124 +1119,6 @@ static void imdct36(int *out, int *buf, int *in, int *win) buf[8 - 4] = MULH(t0, win[18 + 8 - 4]); } -/* header decoding. MUST check the header before because no - consistency check is done there. Return 1 if free format found and - that the frame size must be computed externally */ -static int decode_header(MPADecodeContext *s, uint32_t header) -{ - int sample_rate, frame_size, mpeg25, padding; - int sample_rate_index, bitrate_index; - if (header & (1<<20)) { - s->lsf = (header & (1<<19)) ? 0 : 1; - mpeg25 = 0; - } else { - s->lsf = 1; - mpeg25 = 1; - } - - s->layer = 4 - ((header >> 17) & 3); - /* extract frequency */ - sample_rate_index = (header >> 10) & 3; - sample_rate = mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25); - sample_rate_index += 3 * (s->lsf + mpeg25); - s->sample_rate_index = sample_rate_index; - s->error_protection = ((header >> 16) & 1) ^ 1; - s->sample_rate = sample_rate; - - bitrate_index = (header >> 12) & 0xf; - padding = (header >> 9) & 1; - //extension = (header >> 8) & 1; - s->mode = (header >> 6) & 3; - s->mode_ext = (header >> 4) & 3; - //copyright = (header >> 3) & 1; - //original = (header >> 2) & 1; - //emphasis = header & 3; - - if (s->mode == MPA_MONO) - s->nb_channels = 1; - else - s->nb_channels = 2; - - if (bitrate_index != 0) { - frame_size = mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index]; - s->bit_rate = frame_size * 1000; - switch(s->layer) { - case 1: - frame_size = (frame_size * 12000) / sample_rate; - frame_size = (frame_size + padding) * 4; - break; - case 2: - frame_size = (frame_size * 144000) / sample_rate; - frame_size += padding; - break; - default: - case 3: - frame_size = (frame_size * 144000) / (sample_rate << s->lsf); - frame_size += padding; - break; - } - s->frame_size = frame_size; - } else { - /* if no frame size computed, signal it */ - return 1; - } - -#if defined(DEBUG) - dprintf(s->avctx, "layer%d, %d Hz, %d kbits/s, ", - s->layer, s->sample_rate, s->bit_rate); - if (s->nb_channels == 2) { - if (s->layer == 3) { - if (s->mode_ext & MODE_EXT_MS_STEREO) - dprintf(s->avctx, "ms-"); - if (s->mode_ext & MODE_EXT_I_STEREO) - dprintf(s->avctx, "i-"); - } - dprintf(s->avctx, "stereo"); - } else { - dprintf(s->avctx, "mono"); - } - dprintf(s->avctx, "\n"); -#endif - return 0; -} - -/* useful helper to get mpeg audio stream infos. Return -1 if error in - header, otherwise the coded frame size in bytes */ -int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate) -{ - MPADecodeContext s1, *s = &s1; - s1.avctx = avctx; - - if (ff_mpa_check_header(head) != 0) - return -1; - - if (decode_header(s, head) != 0) { - return -1; - } - - switch(s->layer) { - case 1: - avctx->frame_size = 384; - break; - case 2: - avctx->frame_size = 1152; - break; - default: - case 3: - if (s->lsf) - avctx->frame_size = 576; - else - avctx->frame_size = 1152; - break; - } - - *sample_rate = s->sample_rate; - avctx->channels = s->nb_channels; - avctx->bit_rate = s->bit_rate; - avctx->sub_id = s->layer; - return s->frame_size; -} - /* return the number of decoded frames */ static int mp_decode_layer1(MPADecodeContext *s) { @@ -1291,28 +1186,6 @@ static int mp_decode_layer1(MPADecodeContext *s) return 12; } -/* bitrate is in kb/s */ -int l2_select_table(int bitrate, int nb_channels, int freq, int lsf) -{ - int ch_bitrate, table; - - ch_bitrate = bitrate / nb_channels; - if (!lsf) { - if ((freq == 48000 && ch_bitrate >= 56) || - (ch_bitrate >= 56 && ch_bitrate <= 80)) - table = 0; - else if (freq != 48000 && ch_bitrate >= 96) - table = 1; - else if (freq != 32000 && ch_bitrate <= 48) - table = 2; - else - table = 3; - } else { - table = 4; - } - return table; -} - static int mp_decode_layer2(MPADecodeContext *s) { int sblimit; /* number of used subbands */ @@ -1324,10 +1197,10 @@ static int mp_decode_layer2(MPADecodeContext *s) int scale, qindex, bits, steps, k, l, m, b; /* select decoding table */ - table = l2_select_table(s->bit_rate / 1000, s->nb_channels, + table = ff_mpa_l2_select_table(s->bit_rate / 1000, s->nb_channels, s->sample_rate, s->lsf); - sblimit = sblimit_table[table]; - alloc_table = alloc_tables[table]; + sblimit = ff_mpa_sblimit_table[table]; + alloc_table = ff_mpa_alloc_tables[table]; if (s->mode == MPA_JSTEREO) bound = (s->mode_ext + 1) * 4; @@ -1431,11 +1304,11 @@ static int mp_decode_layer2(MPADecodeContext *s) if (b) { scale = scale_factors[ch][i][k]; qindex = alloc_table[j+b]; - bits = quant_bits[qindex]; + bits = ff_mpa_quant_bits[qindex]; if (bits < 0) { /* 3 values at the same time */ v = get_bits(&s->gb, -bits); - steps = quant_steps[qindex]; + steps = ff_mpa_quant_steps[qindex]; s->sb_samples[ch][k * 12 + l + 0][i] = l2_unscale_group(steps, v % steps, scale); v = v / steps; @@ -1469,11 +1342,11 @@ static int mp_decode_layer2(MPADecodeContext *s) scale0 = scale_factors[0][i][k]; scale1 = scale_factors[1][i][k]; qindex = alloc_table[j+b]; - bits = quant_bits[qindex]; + bits = ff_mpa_quant_bits[qindex]; if (bits < 0) { /* 3 values at the same time */ v = get_bits(&s->gb, -bits); - steps = quant_steps[qindex]; + steps = ff_mpa_quant_steps[qindex]; mant = v % steps; v = v / steps; s->sb_samples[0][k * 12 + l + 0][i] = @@ -1729,7 +1602,7 @@ static int huffman_decode(MPADecodeContext *s, GranuleDef *g, g->sb_hybrid[s_index+2]= g->sb_hybrid[s_index+3]= 0; while(code){ - const static int idxtab[16]={3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0}; + static const int idxtab[16]={3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0}; int v; int pos= s_index+idxtab[code]; code ^= 8>>idxtab[code]; @@ -2185,32 +2058,21 @@ static int mp_decode_layer3(MPADecodeContext *s) g->scalefac_compress = get_bits(&s->gb, 9); else g->scalefac_compress = get_bits(&s->gb, 4); - blocksplit_flag = get_bits(&s->gb, 1); + blocksplit_flag = get_bits1(&s->gb); if (blocksplit_flag) { g->block_type = get_bits(&s->gb, 2); if (g->block_type == 0){ av_log(NULL, AV_LOG_ERROR, "invalid block type\n"); return -1; } - g->switch_point = get_bits(&s->gb, 1); + g->switch_point = get_bits1(&s->gb); for(i=0;i<2;i++) g->table_select[i] = get_bits(&s->gb, 5); for(i=0;i<3;i++) g->subblock_gain[i] = get_bits(&s->gb, 3); - /* compute huffman coded region sizes */ - if (g->block_type == 2) - g->region_size[0] = (36 / 2); - else { - if (s->sample_rate_index <= 2) - g->region_size[0] = (36 / 2); - else if (s->sample_rate_index != 8) - g->region_size[0] = (54 / 2); - else - g->region_size[0] = (108 / 2); - } - g->region_size[1] = (576 / 2); + ff_init_short_region(s, g); } else { - int region_address1, region_address2, l; + int region_address1, region_address2; g->block_type = 0; g->switch_point = 0; for(i=0;i<3;i++) @@ -2220,53 +2082,16 @@ static int mp_decode_layer3(MPADecodeContext *s) region_address2 = get_bits(&s->gb, 3); dprintf(s->avctx, "region1=%d region2=%d\n", region_address1, region_address2); - g->region_size[0] = - band_index_long[s->sample_rate_index][region_address1 + 1] >> 1; - l = region_address1 + region_address2 + 2; - /* should not overflow */ - if (l > 22) - l = 22; - g->region_size[1] = - band_index_long[s->sample_rate_index][l] >> 1; - } - /* convert region offsets to region sizes and truncate - size to big_values */ - g->region_size[2] = (576 / 2); - j = 0; - for(i=0;i<3;i++) { - k = FFMIN(g->region_size[i], g->big_values); - g->region_size[i] = k - j; - j = k; - } - - /* compute band indexes */ - if (g->block_type == 2) { - if (g->switch_point) { - /* if switched mode, we handle the 36 first samples as - long blocks. For 8000Hz, we handle the 48 first - exponents as long blocks (XXX: check this!) */ - if (s->sample_rate_index <= 2) - g->long_end = 8; - else if (s->sample_rate_index != 8) - g->long_end = 6; - else - g->long_end = 4; /* 8000 Hz */ - - g->short_start = 2 + (s->sample_rate_index != 8); - } else { - g->long_end = 0; - g->short_start = 0; - } - } else { - g->short_start = 13; - g->long_end = 22; + ff_init_long_region(s, g, region_address1, region_address2); } + ff_region_offset2size(g); + ff_compute_band_indexes(s, g); g->preflag = 0; if (!s->lsf) - g->preflag = get_bits(&s->gb, 1); - g->scalefac_scale = get_bits(&s->gb, 1); - g->count1table_select = get_bits(&s->gb, 1); + g->preflag = get_bits1(&s->gb); + g->scalefac_scale = get_bits1(&s->gb); + g->count1table_select = get_bits1(&s->gb); dprintf(s->avctx, "block_type=%d switch_point=%d\n", g->block_type, g->switch_point); } @@ -2289,7 +2114,7 @@ static int mp_decode_layer3(MPADecodeContext *s) for(ch=0;chnb_channels;ch++) { g = &granules[ch][gr]; if(get_bits_count(&s->gb)<0){ - av_log(NULL, AV_LOG_ERROR, "mdb:%d, lastbuf:%d skiping granule %d\n", + av_log(NULL, AV_LOG_ERROR, "mdb:%d, lastbuf:%d skipping granule %d\n", main_data_begin, s->last_buf_size, gr); skip_bits_long(&s->gb, g->part2_3_length); memset(g->sb_hybrid, 0, sizeof(g->sb_hybrid)); @@ -2471,7 +2296,7 @@ static int mp_decode_frame(MPADecodeContext *s, /* skip error protection field */ if (s->error_protection) - get_bits(&s->gb, 16); + skip_bits(&s->gb, 16); dprintf(s->avctx, "frame %d:\n", s->frame_count); switch(s->layer) { @@ -2542,7 +2367,7 @@ static int mp_decode_frame(MPADecodeContext *s, static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, - uint8_t * buf, int buf_size) + const uint8_t * buf, int buf_size) { MPADecodeContext *s = avctx->priv_data; uint32_t header; @@ -2553,7 +2378,7 @@ retry: if(buf_size < HEADER_SIZE) return -1; - header = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; + header = AV_RB32(buf); if(ff_mpa_check_header(header) < 0){ buf++; // buf_size--; @@ -2561,7 +2386,7 @@ retry: goto retry; } - if (decode_header(s, header) == 1) { + if (ff_mpegaudio_decode_header(s, header) == 1) { /* free format: prepare to compute frame size */ s->frame_size = -1; return -1; @@ -2590,6 +2415,7 @@ retry: return -1; }else if(s->frame_size < buf_size){ av_log(avctx, AV_LOG_ERROR, "incorrect frame size\n"); + buf_size= s->frame_size; } out_size = mp_decode_frame(s, out_samples, buf, buf_size); @@ -2605,13 +2431,14 @@ retry: static void flush(AVCodecContext *avctx){ MPADecodeContext *s = avctx->priv_data; + memset(s->synth_buf, 0, sizeof(s->synth_buf)); s->last_buf_size= 0; } #ifdef CONFIG_MP3ADU_DECODER static int decode_frame_adu(AVCodecContext * avctx, void *data, int *data_size, - uint8_t * buf, int buf_size) + const uint8_t * buf, int buf_size) { MPADecodeContext *s = avctx->priv_data; uint32_t header; @@ -2631,14 +2458,14 @@ static int decode_frame_adu(AVCodecContext * avctx, len = MPA_MAX_CODED_FRAME_SIZE; // Get header and restore sync word - header = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3] | 0xffe00000; + header = AV_RB32(buf) | 0xffe00000; if (ff_mpa_check_header(header) < 0) { // Bad header, discard frame *data_size = 0; return buf_size; } - decode_header(s, header); + ff_mpegaudio_decode_header(s, header); /* update codec info */ avctx->sample_rate = s->sample_rate; avctx->channels = s->nb_channels; @@ -2697,7 +2524,7 @@ static int decode_init_mp3on4(AVCodecContext * avctx) /* Init the first mp3 decoder in standard way, so that all tables get builded * We replace avctx->priv_data with the context of the first decoder so that * decode_init() does not have to be changed. - * Other decoders will be inited here copying data from the first context + * Other decoders will be initialized here copying data from the first context */ // Allocate zeroed memory for the first decoder context s->mp3decctx[0] = av_mallocz(sizeof(MPADecodeContext)); @@ -2737,7 +2564,7 @@ static int decode_close_mp3on4(AVCodecContext * avctx) static int decode_frame_mp3on4(AVCodecContext * avctx, void *data, int *data_size, - uint8_t * buf, int buf_size) + const uint8_t * buf, int buf_size) { MP3On4DecodeContext *s = avctx->priv_data; MPADecodeContext *m; @@ -2747,7 +2574,7 @@ static int decode_frame_mp3on4(AVCodecContext * avctx, OUT_INT decoded_buf[MPA_FRAME_SIZE * MPA_MAX_CHANNELS]; OUT_INT *outptr, *bp; int fsize; - unsigned char *start2 = buf, *start; + const unsigned char *start2 = buf, *start; int fr, i, j, n; int off = avctx->channels; int *coff = chan_offset[s->chan_cfg]; @@ -2776,14 +2603,14 @@ static int decode_frame_mp3on4(AVCodecContext * avctx, assert (m != NULL); // Get header - header = (start[0] << 24) | (start[1] << 16) | (start[2] << 8) | start[3] | 0xfff00000; + header = AV_RB32(start) | 0xfff00000; if (ff_mpa_check_header(header) < 0) { // Bad header, discard block *data_size = 0; return buf_size; } - decode_header(m, header); + ff_mpegaudio_decode_header(m, header); mp_decode_frame(m, decoded_buf, start, fsize); n = MPA_FRAME_SIZE * m->nb_channels; @@ -2830,6 +2657,7 @@ AVCodec mp2_decoder = NULL, decode_frame, CODEC_CAP_PARSE_ONLY, + .flush= flush, }; #endif #ifdef CONFIG_MP3_DECODER diff --git a/contrib/ffmpeg/libavcodec/mpegaudiodecheader.c b/contrib/ffmpeg/libavcodec/mpegaudiodecheader.c new file mode 100644 index 000000000..efea49961 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpegaudiodecheader.c @@ -0,0 +1,109 @@ +/* + * MPEG Audio header decoder + * Copyright (c) 2001, 2002 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mpegaudiodecheader.c + * MPEG Audio header decoder. + */ + +//#define DEBUG +#include "avcodec.h" +#include "mpegaudio.h" +#include "mpegaudiodata.h" + + +int ff_mpegaudio_decode_header(MPADecodeContext *s, uint32_t header) +{ + int sample_rate, frame_size, mpeg25, padding; + int sample_rate_index, bitrate_index; + if (header & (1<<20)) { + s->lsf = (header & (1<<19)) ? 0 : 1; + mpeg25 = 0; + } else { + s->lsf = 1; + mpeg25 = 1; + } + + s->layer = 4 - ((header >> 17) & 3); + /* extract frequency */ + sample_rate_index = (header >> 10) & 3; + sample_rate = ff_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25); + sample_rate_index += 3 * (s->lsf + mpeg25); + s->sample_rate_index = sample_rate_index; + s->error_protection = ((header >> 16) & 1) ^ 1; + s->sample_rate = sample_rate; + + bitrate_index = (header >> 12) & 0xf; + padding = (header >> 9) & 1; + //extension = (header >> 8) & 1; + s->mode = (header >> 6) & 3; + s->mode_ext = (header >> 4) & 3; + //copyright = (header >> 3) & 1; + //original = (header >> 2) & 1; + //emphasis = header & 3; + + if (s->mode == MPA_MONO) + s->nb_channels = 1; + else + s->nb_channels = 2; + + if (bitrate_index != 0) { + frame_size = ff_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index]; + s->bit_rate = frame_size * 1000; + switch(s->layer) { + case 1: + frame_size = (frame_size * 12000) / sample_rate; + frame_size = (frame_size + padding) * 4; + break; + case 2: + frame_size = (frame_size * 144000) / sample_rate; + frame_size += padding; + break; + default: + case 3: + frame_size = (frame_size * 144000) / (sample_rate << s->lsf); + frame_size += padding; + break; + } + s->frame_size = frame_size; + } else { + /* if no frame size computed, signal it */ + return 1; + } + +#if defined(DEBUG) + dprintf(s->avctx, "layer%d, %d Hz, %d kbits/s, ", + s->layer, s->sample_rate, s->bit_rate); + if (s->nb_channels == 2) { + if (s->layer == 3) { + if (s->mode_ext & MODE_EXT_MS_STEREO) + dprintf(s->avctx, "ms-"); + if (s->mode_ext & MODE_EXT_I_STEREO) + dprintf(s->avctx, "i-"); + } + dprintf(s->avctx, "stereo"); + } else { + dprintf(s->avctx, "mono"); + } + dprintf(s->avctx, "\n"); +#endif + return 0; +} diff --git a/contrib/ffmpeg/libavcodec/mpegaudiodecheader.h b/contrib/ffmpeg/libavcodec/mpegaudiodecheader.h new file mode 100644 index 000000000..21e8cf016 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpegaudiodecheader.h @@ -0,0 +1,39 @@ +/* + * MPEG Audio header decoder + * Copyright (c) 2001, 2002 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mpegaudiodecheader.c + * MPEG Audio header decoder. + */ + +#ifndef FFMPEG_MPEGAUDIODECHEADER_H +#define FFMPEG_MPEGAUDIODECHEADER_H + +#include "common.h" +#include "mpegaudio.h" + + +/* header decoding. MUST check the header before because no + consistency check is done there. Return 1 if free format found and + that the frame size must be computed externally */ +int ff_mpegaudio_decode_header(MPADecodeContext *s, uint32_t header); + +#endif /* FFMPEG_MPEGAUDIODECHEADER_H */ diff --git a/contrib/ffmpeg/libavcodec/mpegaudiodectab.h b/contrib/ffmpeg/libavcodec/mpegaudiodectab.h index fdd1096fc..a41ff7aaa 100644 --- a/contrib/ffmpeg/libavcodec/mpegaudiodectab.h +++ b/contrib/ffmpeg/libavcodec/mpegaudiodectab.h @@ -24,202 +24,11 @@ * mpeg audio layer decoder tables. */ -const uint16_t mpa_bitrate_tab[2][3][15] = { - { {0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 }, - {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 }, - {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 } }, - { {0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256}, - {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160}, - {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160} - } -}; - -const uint16_t mpa_freq_tab[3] = { 44100, 48000, 32000 }; +#ifndef FFMPEG_MPEGAUDIODECTAB_H +#define FFMPEG_MPEGAUDIODECTAB_H -/*******************************************************/ -/* half mpeg encoding window (full precision) */ -const int32_t mpa_enwindow[257] = { - 0, -1, -1, -1, -1, -1, -1, -2, - -2, -2, -2, -3, -3, -4, -4, -5, - -5, -6, -7, -7, -8, -9, -10, -11, - -13, -14, -16, -17, -19, -21, -24, -26, - -29, -31, -35, -38, -41, -45, -49, -53, - -58, -63, -68, -73, -79, -85, -91, -97, - -104, -111, -117, -125, -132, -139, -147, -154, - -161, -169, -176, -183, -190, -196, -202, -208, - 213, 218, 222, 225, 227, 228, 228, 227, - 224, 221, 215, 208, 200, 189, 177, 163, - 146, 127, 106, 83, 57, 29, -2, -36, - -72, -111, -153, -197, -244, -294, -347, -401, - -459, -519, -581, -645, -711, -779, -848, -919, - -991, -1064, -1137, -1210, -1283, -1356, -1428, -1498, - -1567, -1634, -1698, -1759, -1817, -1870, -1919, -1962, - -2001, -2032, -2057, -2075, -2085, -2087, -2080, -2063, - 2037, 2000, 1952, 1893, 1822, 1739, 1644, 1535, - 1414, 1280, 1131, 970, 794, 605, 402, 185, - -45, -288, -545, -814, -1095, -1388, -1692, -2006, - -2330, -2663, -3004, -3351, -3705, -4063, -4425, -4788, - -5153, -5517, -5879, -6237, -6589, -6935, -7271, -7597, - -7910, -8209, -8491, -8755, -8998, -9219, -9416, -9585, - -9727, -9838, -9916, -9959, -9966, -9935, -9863, -9750, - -9592, -9389, -9139, -8840, -8492, -8092, -7640, -7134, - 6574, 5959, 5288, 4561, 3776, 2935, 2037, 1082, - 70, -998, -2122, -3300, -4533, -5818, -7154, -8540, - -9975,-11455,-12980,-14548,-16155,-17799,-19478,-21189, --22929,-24694,-26482,-28289,-30112,-31947,-33791,-35640, --37489,-39336,-41176,-43006,-44821,-46617,-48390,-50137, --51853,-53534,-55178,-56778,-58333,-59838,-61289,-62684, --64019,-65290,-66494,-67629,-68692,-69679,-70590,-71420, --72169,-72835,-73415,-73908,-74313,-74630,-74856,-74992, - 75038, -}; - -/*******************************************************/ -/* layer 2 tables */ - -const int sblimit_table[5] = { 27 , 30 , 8, 12 , 30 }; - -const int quant_steps[17] = { - 3, 5, 7, 9, 15, - 31, 63, 127, 255, 511, - 1023, 2047, 4095, 8191, 16383, - 32767, 65535 -}; - -/* we use a negative value if grouped */ -const int quant_bits[17] = { - -5, -7, 3, -10, 4, - 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, - 15, 16 -}; - -/* encoding tables which give the quantization index. Note how it is - possible to store them efficiently ! */ -static const unsigned char alloc_table_0[] = { - 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 2, 0, 1, 16, - 2, 0, 1, 16, - 2, 0, 1, 16, - 2, 0, 1, 16, -}; - -static const unsigned char alloc_table_1[] = { - 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 4, 0, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 3, 0, 1, 2, 3, 4, 5, 16, - 2, 0, 1, 16, - 2, 0, 1, 16, - 2, 0, 1, 16, - 2, 0, 1, 16, - 2, 0, 1, 16, - 2, 0, 1, 16, - 2, 0, 1, 16, -}; - -static const unsigned char alloc_table_2[] = { - 4, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 4, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, -}; - -static const unsigned char alloc_table_3[] = { - 4, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 4, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, -}; - -static const unsigned char alloc_table_4[] = { - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 3, 0, 1, 3, 4, 5, 6, 7, - 2, 0, 1, 3, - 2, 0, 1, 3, - 2, 0, 1, 3, - 2, 0, 1, 3, - 2, 0, 1, 3, - 2, 0, 1, 3, - 2, 0, 1, 3, - 2, 0, 1, 3, - 2, 0, 1, 3, - 2, 0, 1, 3, - 2, 0, 1, 3, - 2, 0, 1, 3, - 2, 0, 1, 3, - 2, 0, 1, 3, - 2, 0, 1, 3, - 2, 0, 1, 3, - 2, 0, 1, 3, - 2, 0, 1, 3, - 2, 0, 1, 3, -}; - -const unsigned char *alloc_tables[5] = -{ alloc_table_0, alloc_table_1, alloc_table_2, alloc_table_3, alloc_table_4, }; +#include +#include "mpegaudio.h" /*******************************************************/ /* layer 3 tables */ @@ -793,3 +602,5 @@ static const uint8_t mpa_pretab[2][22] = { static const float ci_table[8] = { -0.6, -0.535, -0.33, -0.185, -0.095, -0.041, -0.0142, -0.0037, }; + +#endif /* FFMPEG_MPEGAUDIODECTAB_H */ diff --git a/contrib/ffmpeg/libavcodec/mpegaudioenc.c b/contrib/ffmpeg/libavcodec/mpegaudioenc.c new file mode 100644 index 000000000..ede44927c --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpegaudioenc.c @@ -0,0 +1,801 @@ +/* + * The simplest mpeg audio layer 2 encoder + * Copyright (c) 2000, 2001 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mpegaudio.c + * The simplest mpeg audio layer 2 encoder. + */ + +#include "avcodec.h" +#include "bitstream.h" +#include "mpegaudio.h" + +/* currently, cannot change these constants (need to modify + quantization stage) */ +#define MUL(a,b) (((int64_t)(a) * (int64_t)(b)) >> FRAC_BITS) + +#define SAMPLES_BUF_SIZE 4096 + +typedef struct MpegAudioContext { + PutBitContext pb; + int nb_channels; + int freq, bit_rate; + int lsf; /* 1 if mpeg2 low bitrate selected */ + int bitrate_index; /* bit rate */ + int freq_index; + int frame_size; /* frame size, in bits, without padding */ + int64_t nb_samples; /* total number of samples encoded */ + /* padding computation */ + int frame_frac, frame_frac_incr, do_padding; + short samples_buf[MPA_MAX_CHANNELS][SAMPLES_BUF_SIZE]; /* buffer for filter */ + int samples_offset[MPA_MAX_CHANNELS]; /* offset in samples_buf */ + int sb_samples[MPA_MAX_CHANNELS][3][12][SBLIMIT]; + unsigned char scale_factors[MPA_MAX_CHANNELS][SBLIMIT][3]; /* scale factors */ + /* code to group 3 scale factors */ + unsigned char scale_code[MPA_MAX_CHANNELS][SBLIMIT]; + int sblimit; /* number of used subbands */ + const unsigned char *alloc_table; +} MpegAudioContext; + +/* define it to use floats in quantization (I don't like floats !) */ +//#define USE_FLOATS + +#include "mpegaudiodata.h" +#include "mpegaudiotab.h" + +static int MPA_encode_init(AVCodecContext *avctx) +{ + MpegAudioContext *s = avctx->priv_data; + int freq = avctx->sample_rate; + int bitrate = avctx->bit_rate; + int channels = avctx->channels; + int i, v, table; + float a; + + if (channels <= 0 || channels > 2){ + av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed in mp2\n", channels); + return -1; + } + bitrate = bitrate / 1000; + s->nb_channels = channels; + s->freq = freq; + s->bit_rate = bitrate * 1000; + avctx->frame_size = MPA_FRAME_SIZE; + + /* encoding freq */ + s->lsf = 0; + for(i=0;i<3;i++) { + if (ff_mpa_freq_tab[i] == freq) + break; + if ((ff_mpa_freq_tab[i] / 2) == freq) { + s->lsf = 1; + break; + } + } + if (i == 3){ + av_log(avctx, AV_LOG_ERROR, "Sampling rate %d is not allowed in mp2\n", freq); + return -1; + } + s->freq_index = i; + + /* encoding bitrate & frequency */ + for(i=0;i<15;i++) { + if (ff_mpa_bitrate_tab[s->lsf][1][i] == bitrate) + break; + } + if (i == 15){ + av_log(avctx, AV_LOG_ERROR, "bitrate %d is not allowed in mp2\n", bitrate); + return -1; + } + s->bitrate_index = i; + + /* compute total header size & pad bit */ + + a = (float)(bitrate * 1000 * MPA_FRAME_SIZE) / (freq * 8.0); + s->frame_size = ((int)a) * 8; + + /* frame fractional size to compute padding */ + s->frame_frac = 0; + s->frame_frac_incr = (int)((a - floor(a)) * 65536.0); + + /* select the right allocation table */ + table = ff_mpa_l2_select_table(bitrate, s->nb_channels, freq, s->lsf); + + /* number of used subbands */ + s->sblimit = ff_mpa_sblimit_table[table]; + s->alloc_table = ff_mpa_alloc_tables[table]; + +#ifdef DEBUG + av_log(avctx, AV_LOG_DEBUG, "%d kb/s, %d Hz, frame_size=%d bits, table=%d, padincr=%x\n", + bitrate, freq, s->frame_size, table, s->frame_frac_incr); +#endif + + for(i=0;inb_channels;i++) + s->samples_offset[i] = 0; + + for(i=0;i<257;i++) { + int v; + v = ff_mpa_enwindow[i]; +#if WFRAC_BITS != 16 + v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS); +#endif + filter_bank[i] = v; + if ((i & 63) != 0) + v = -v; + if (i != 0) + filter_bank[512 - i] = v; + } + + for(i=0;i<64;i++) { + v = (int)(pow(2.0, (3 - i) / 3.0) * (1 << 20)); + if (v <= 0) + v = 1; + scale_factor_table[i] = v; +#ifdef USE_FLOATS + scale_factor_inv_table[i] = pow(2.0, -(3 - i) / 3.0) / (float)(1 << 20); +#else +#define P 15 + scale_factor_shift[i] = 21 - P - (i / 3); + scale_factor_mult[i] = (1 << P) * pow(2.0, (i % 3) / 3.0); +#endif + } + for(i=0;i<128;i++) { + v = i - 64; + if (v <= -3) + v = 0; + else if (v < 0) + v = 1; + else if (v == 0) + v = 2; + else if (v < 3) + v = 3; + else + v = 4; + scale_diff_table[i] = v; + } + + for(i=0;i<17;i++) { + v = ff_mpa_quant_bits[i]; + if (v < 0) + v = -v; + else + v = v * 3; + total_quant_bits[i] = 12 * v; + } + + avctx->coded_frame= avcodec_alloc_frame(); + avctx->coded_frame->key_frame= 1; + + return 0; +} + +/* 32 point floating point IDCT without 1/sqrt(2) coef zero scaling */ +static void idct32(int *out, int *tab) +{ + int i, j; + int *t, *t1, xr; + const int *xp = costab32; + + for(j=31;j>=3;j-=2) tab[j] += tab[j - 2]; + + t = tab + 30; + t1 = tab + 2; + do { + t[0] += t[-4]; + t[1] += t[1 - 4]; + t -= 4; + } while (t != t1); + + t = tab + 28; + t1 = tab + 4; + do { + t[0] += t[-8]; + t[1] += t[1-8]; + t[2] += t[2-8]; + t[3] += t[3-8]; + t -= 8; + } while (t != t1); + + t = tab; + t1 = tab + 32; + do { + t[ 3] = -t[ 3]; + t[ 6] = -t[ 6]; + + t[11] = -t[11]; + t[12] = -t[12]; + t[13] = -t[13]; + t[15] = -t[15]; + t += 16; + } while (t != t1); + + + t = tab; + t1 = tab + 8; + do { + int x1, x2, x3, x4; + + x3 = MUL(t[16], FIX(SQRT2*0.5)); + x4 = t[0] - x3; + x3 = t[0] + x3; + + x2 = MUL(-(t[24] + t[8]), FIX(SQRT2*0.5)); + x1 = MUL((t[8] - x2), xp[0]); + x2 = MUL((t[8] + x2), xp[1]); + + t[ 0] = x3 + x1; + t[ 8] = x4 - x2; + t[16] = x4 + x2; + t[24] = x3 - x1; + t++; + } while (t != t1); + + xp += 2; + t = tab; + t1 = tab + 4; + do { + xr = MUL(t[28],xp[0]); + t[28] = (t[0] - xr); + t[0] = (t[0] + xr); + + xr = MUL(t[4],xp[1]); + t[ 4] = (t[24] - xr); + t[24] = (t[24] + xr); + + xr = MUL(t[20],xp[2]); + t[20] = (t[8] - xr); + t[ 8] = (t[8] + xr); + + xr = MUL(t[12],xp[3]); + t[12] = (t[16] - xr); + t[16] = (t[16] + xr); + t++; + } while (t != t1); + xp += 4; + + for (i = 0; i < 4; i++) { + xr = MUL(tab[30-i*4],xp[0]); + tab[30-i*4] = (tab[i*4] - xr); + tab[ i*4] = (tab[i*4] + xr); + + xr = MUL(tab[ 2+i*4],xp[1]); + tab[ 2+i*4] = (tab[28-i*4] - xr); + tab[28-i*4] = (tab[28-i*4] + xr); + + xr = MUL(tab[31-i*4],xp[0]); + tab[31-i*4] = (tab[1+i*4] - xr); + tab[ 1+i*4] = (tab[1+i*4] + xr); + + xr = MUL(tab[ 3+i*4],xp[1]); + tab[ 3+i*4] = (tab[29-i*4] - xr); + tab[29-i*4] = (tab[29-i*4] + xr); + + xp += 2; + } + + t = tab + 30; + t1 = tab + 1; + do { + xr = MUL(t1[0], *xp); + t1[0] = (t[0] - xr); + t[0] = (t[0] + xr); + t -= 2; + t1 += 2; + xp++; + } while (t >= tab); + + for(i=0;i<32;i++) { + out[i] = tab[bitinv32[i]]; + } +} + +#define WSHIFT (WFRAC_BITS + 15 - FRAC_BITS) + +static void filter(MpegAudioContext *s, int ch, short *samples, int incr) +{ + short *p, *q; + int sum, offset, i, j; + int tmp[64]; + int tmp1[32]; + int *out; + + // print_pow1(samples, 1152); + + offset = s->samples_offset[ch]; + out = &s->sb_samples[ch][0][0][0]; + for(j=0;j<36;j++) { + /* 32 samples at once */ + for(i=0;i<32;i++) { + s->samples_buf[ch][offset + (31 - i)] = samples[0]; + samples += incr; + } + + /* filter */ + p = s->samples_buf[ch] + offset; + q = filter_bank; + /* maxsum = 23169 */ + for(i=0;i<64;i++) { + sum = p[0*64] * q[0*64]; + sum += p[1*64] * q[1*64]; + sum += p[2*64] * q[2*64]; + sum += p[3*64] * q[3*64]; + sum += p[4*64] * q[4*64]; + sum += p[5*64] * q[5*64]; + sum += p[6*64] * q[6*64]; + sum += p[7*64] * q[7*64]; + tmp[i] = sum; + p++; + q++; + } + tmp1[0] = tmp[16] >> WSHIFT; + for( i=1; i<=16; i++ ) tmp1[i] = (tmp[i+16]+tmp[16-i]) >> WSHIFT; + for( i=17; i<=31; i++ ) tmp1[i] = (tmp[i+16]-tmp[80-i]) >> WSHIFT; + + idct32(out, tmp1); + + /* advance of 32 samples */ + offset -= 32; + out += 32; + /* handle the wrap around */ + if (offset < 0) { + memmove(s->samples_buf[ch] + SAMPLES_BUF_SIZE - (512 - 32), + s->samples_buf[ch], (512 - 32) * 2); + offset = SAMPLES_BUF_SIZE - 512; + } + } + s->samples_offset[ch] = offset; + + // print_pow(s->sb_samples, 1152); +} + +static void compute_scale_factors(unsigned char scale_code[SBLIMIT], + unsigned char scale_factors[SBLIMIT][3], + int sb_samples[3][12][SBLIMIT], + int sblimit) +{ + int *p, vmax, v, n, i, j, k, code; + int index, d1, d2; + unsigned char *sf = &scale_factors[0][0]; + + for(j=0;j vmax) + vmax = v; + } + /* compute the scale factor index using log 2 computations */ + if (vmax > 0) { + n = av_log2(vmax); + /* n is the position of the MSB of vmax. now + use at most 2 compares to find the index */ + index = (21 - n) * 3 - 3; + if (index >= 0) { + while (vmax <= scale_factor_table[index+1]) + index++; + } else { + index = 0; /* very unlikely case of overflow */ + } + } else { + index = 62; /* value 63 is not allowed */ + } + +#if 0 + printf("%2d:%d in=%x %x %d\n", + j, i, vmax, scale_factor_table[index], index); +#endif + /* store the scale factor */ + assert(index >=0 && index <= 63); + sf[i] = index; + } + + /* compute the transmission factor : look if the scale factors + are close enough to each other */ + d1 = scale_diff_table[sf[0] - sf[1] + 64]; + d2 = scale_diff_table[sf[1] - sf[2] + 64]; + + /* handle the 25 cases */ + switch(d1 * 5 + d2) { + case 0*5+0: + case 0*5+4: + case 3*5+4: + case 4*5+0: + case 4*5+4: + code = 0; + break; + case 0*5+1: + case 0*5+2: + case 4*5+1: + case 4*5+2: + code = 3; + sf[2] = sf[1]; + break; + case 0*5+3: + case 4*5+3: + code = 3; + sf[1] = sf[2]; + break; + case 1*5+0: + case 1*5+4: + case 2*5+4: + code = 1; + sf[1] = sf[0]; + break; + case 1*5+1: + case 1*5+2: + case 2*5+0: + case 2*5+1: + case 2*5+2: + code = 2; + sf[1] = sf[2] = sf[0]; + break; + case 2*5+3: + case 3*5+3: + code = 2; + sf[0] = sf[1] = sf[2]; + break; + case 3*5+0: + case 3*5+1: + case 3*5+2: + code = 2; + sf[0] = sf[2] = sf[1]; + break; + case 1*5+3: + code = 2; + if (sf[0] > sf[2]) + sf[0] = sf[2]; + sf[1] = sf[2] = sf[0]; + break; + default: + assert(0); //cannot happen + code = 0; /* kill warning */ + } + +#if 0 + printf("%d: %2d %2d %2d %d %d -> %d\n", j, + sf[0], sf[1], sf[2], d1, d2, code); +#endif + scale_code[j] = code; + sf += 3; + } +} + +/* The most important function : psycho acoustic module. In this + encoder there is basically none, so this is the worst you can do, + but also this is the simpler. */ +static void psycho_acoustic_model(MpegAudioContext *s, short smr[SBLIMIT]) +{ + int i; + + for(i=0;isblimit;i++) { + smr[i] = (int)(fixed_smr[i] * 10); + } +} + + +#define SB_NOTALLOCATED 0 +#define SB_ALLOCATED 1 +#define SB_NOMORE 2 + +/* Try to maximize the smr while using a number of bits inferior to + the frame size. I tried to make the code simpler, faster and + smaller than other encoders :-) */ +static void compute_bit_allocation(MpegAudioContext *s, + short smr1[MPA_MAX_CHANNELS][SBLIMIT], + unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT], + int *padding) +{ + int i, ch, b, max_smr, max_ch, max_sb, current_frame_size, max_frame_size; + int incr; + short smr[MPA_MAX_CHANNELS][SBLIMIT]; + unsigned char subband_status[MPA_MAX_CHANNELS][SBLIMIT]; + const unsigned char *alloc; + + memcpy(smr, smr1, s->nb_channels * sizeof(short) * SBLIMIT); + memset(subband_status, SB_NOTALLOCATED, s->nb_channels * SBLIMIT); + memset(bit_alloc, 0, s->nb_channels * SBLIMIT); + + /* compute frame size and padding */ + max_frame_size = s->frame_size; + s->frame_frac += s->frame_frac_incr; + if (s->frame_frac >= 65536) { + s->frame_frac -= 65536; + s->do_padding = 1; + max_frame_size += 8; + } else { + s->do_padding = 0; + } + + /* compute the header + bit alloc size */ + current_frame_size = 32; + alloc = s->alloc_table; + for(i=0;isblimit;i++) { + incr = alloc[0]; + current_frame_size += incr * s->nb_channels; + alloc += 1 << incr; + } + for(;;) { + /* look for the subband with the largest signal to mask ratio */ + max_sb = -1; + max_ch = -1; + max_smr = 0x80000000; + for(ch=0;chnb_channels;ch++) { + for(i=0;isblimit;i++) { + if (smr[ch][i] > max_smr && subband_status[ch][i] != SB_NOMORE) { + max_smr = smr[ch][i]; + max_sb = i; + max_ch = ch; + } + } + } +#if 0 + printf("current=%d max=%d max_sb=%d alloc=%d\n", + current_frame_size, max_frame_size, max_sb, + bit_alloc[max_sb]); +#endif + if (max_sb < 0) + break; + + /* find alloc table entry (XXX: not optimal, should use + pointer table) */ + alloc = s->alloc_table; + for(i=0;iscale_code[max_ch][max_sb]] * 6; + incr += total_quant_bits[alloc[1]]; + } else { + /* increments bit allocation */ + b = bit_alloc[max_ch][max_sb]; + incr = total_quant_bits[alloc[b + 1]] - + total_quant_bits[alloc[b]]; + } + + if (current_frame_size + incr <= max_frame_size) { + /* can increase size */ + b = ++bit_alloc[max_ch][max_sb]; + current_frame_size += incr; + /* decrease smr by the resolution we added */ + smr[max_ch][max_sb] = smr1[max_ch][max_sb] - quant_snr[alloc[b]]; + /* max allocation size reached ? */ + if (b == ((1 << alloc[0]) - 1)) + subband_status[max_ch][max_sb] = SB_NOMORE; + else + subband_status[max_ch][max_sb] = SB_ALLOCATED; + } else { + /* cannot increase the size of this subband */ + subband_status[max_ch][max_sb] = SB_NOMORE; + } + } + *padding = max_frame_size - current_frame_size; + assert(*padding >= 0); + +#if 0 + for(i=0;isblimit;i++) { + printf("%d ", bit_alloc[i]); + } + printf("\n"); +#endif +} + +/* + * Output the mpeg audio layer 2 frame. Note how the code is small + * compared to other encoders :-) + */ +static void encode_frame(MpegAudioContext *s, + unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT], + int padding) +{ + int i, j, k, l, bit_alloc_bits, b, ch; + unsigned char *sf; + int q[3]; + PutBitContext *p = &s->pb; + + /* header */ + + put_bits(p, 12, 0xfff); + put_bits(p, 1, 1 - s->lsf); /* 1 = mpeg1 ID, 0 = mpeg2 lsf ID */ + put_bits(p, 2, 4-2); /* layer 2 */ + put_bits(p, 1, 1); /* no error protection */ + put_bits(p, 4, s->bitrate_index); + put_bits(p, 2, s->freq_index); + put_bits(p, 1, s->do_padding); /* use padding */ + put_bits(p, 1, 0); /* private_bit */ + put_bits(p, 2, s->nb_channels == 2 ? MPA_STEREO : MPA_MONO); + put_bits(p, 2, 0); /* mode_ext */ + put_bits(p, 1, 0); /* no copyright */ + put_bits(p, 1, 1); /* original */ + put_bits(p, 2, 0); /* no emphasis */ + + /* bit allocation */ + j = 0; + for(i=0;isblimit;i++) { + bit_alloc_bits = s->alloc_table[j]; + for(ch=0;chnb_channels;ch++) { + put_bits(p, bit_alloc_bits, bit_alloc[ch][i]); + } + j += 1 << bit_alloc_bits; + } + + /* scale codes */ + for(i=0;isblimit;i++) { + for(ch=0;chnb_channels;ch++) { + if (bit_alloc[ch][i]) + put_bits(p, 2, s->scale_code[ch][i]); + } + } + + /* scale factors */ + for(i=0;isblimit;i++) { + for(ch=0;chnb_channels;ch++) { + if (bit_alloc[ch][i]) { + sf = &s->scale_factors[ch][i][0]; + switch(s->scale_code[ch][i]) { + case 0: + put_bits(p, 6, sf[0]); + put_bits(p, 6, sf[1]); + put_bits(p, 6, sf[2]); + break; + case 3: + case 1: + put_bits(p, 6, sf[0]); + put_bits(p, 6, sf[2]); + break; + case 2: + put_bits(p, 6, sf[0]); + break; + } + } + } + } + + /* quantization & write sub band samples */ + + for(k=0;k<3;k++) { + for(l=0;l<12;l+=3) { + j = 0; + for(i=0;isblimit;i++) { + bit_alloc_bits = s->alloc_table[j]; + for(ch=0;chnb_channels;ch++) { + b = bit_alloc[ch][i]; + if (b) { + int qindex, steps, m, sample, bits; + /* we encode 3 sub band samples of the same sub band at a time */ + qindex = s->alloc_table[j+b]; + steps = ff_mpa_quant_steps[qindex]; + for(m=0;m<3;m++) { + sample = s->sb_samples[ch][k][l + m][i]; + /* divide by scale factor */ +#ifdef USE_FLOATS + { + float a; + a = (float)sample * scale_factor_inv_table[s->scale_factors[ch][i][k]]; + q[m] = (int)((a + 1.0) * steps * 0.5); + } +#else + { + int q1, e, shift, mult; + e = s->scale_factors[ch][i][k]; + shift = scale_factor_shift[e]; + mult = scale_factor_mult[e]; + + /* normalize to P bits */ + if (shift < 0) + q1 = sample << (-shift); + else + q1 = sample >> shift; + q1 = (q1 * mult) >> P; + q[m] = ((q1 + (1 << P)) * steps) >> (P + 1); + } +#endif + if (q[m] >= steps) + q[m] = steps - 1; + assert(q[m] >= 0 && q[m] < steps); + } + bits = ff_mpa_quant_bits[qindex]; + if (bits < 0) { + /* group the 3 values to save bits */ + put_bits(p, -bits, + q[0] + steps * (q[1] + steps * q[2])); +#if 0 + printf("%d: gr1 %d\n", + i, q[0] + steps * (q[1] + steps * q[2])); +#endif + } else { +#if 0 + printf("%d: gr3 %d %d %d\n", + i, q[0], q[1], q[2]); +#endif + put_bits(p, bits, q[0]); + put_bits(p, bits, q[1]); + put_bits(p, bits, q[2]); + } + } + } + /* next subband in alloc table */ + j += 1 << bit_alloc_bits; + } + } + } + + /* padding */ + for(i=0;ipriv_data; + short *samples = data; + short smr[MPA_MAX_CHANNELS][SBLIMIT]; + unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT]; + int padding, i; + + for(i=0;inb_channels;i++) { + filter(s, i, samples + i, s->nb_channels); + } + + for(i=0;inb_channels;i++) { + compute_scale_factors(s->scale_code[i], s->scale_factors[i], + s->sb_samples[i], s->sblimit); + } + for(i=0;inb_channels;i++) { + psycho_acoustic_model(s, smr[i]); + } + compute_bit_allocation(s, smr, bit_alloc, &padding); + + init_put_bits(&s->pb, frame, MPA_MAX_CODED_FRAME_SIZE); + + encode_frame(s, bit_alloc, padding); + + s->nb_samples += MPA_FRAME_SIZE; + return pbBufPtr(&s->pb) - s->pb.buf; +} + +static int MPA_encode_close(AVCodecContext *avctx) +{ + av_freep(&avctx->coded_frame); + return 0; +} + +AVCodec mp2_encoder = { + "mp2", + CODEC_TYPE_AUDIO, + CODEC_ID_MP2, + sizeof(MpegAudioContext), + MPA_encode_init, + MPA_encode_frame, + MPA_encode_close, + NULL, +}; + +#undef FIX diff --git a/contrib/ffmpeg/libavcodec/mpegaudiotab.h b/contrib/ffmpeg/libavcodec/mpegaudiotab.h index 8fb37ddff..61ea471b1 100644 --- a/contrib/ffmpeg/libavcodec/mpegaudiotab.h +++ b/contrib/ffmpeg/libavcodec/mpegaudiotab.h @@ -27,6 +27,12 @@ * Most of them come from the mpeg audio specification. */ +#ifndef FFMPEG_MPEGAUDIOTAB_H +#define FFMPEG_MPEGAUDIOTAB_H + +#include +#include "mpegaudio.h" + #define SQRT2 1.41421356237309514547 static const int costab32[30] = { @@ -109,3 +115,4 @@ static const float fixed_smr[SBLIMIT] = { static const unsigned char nb_scale_factors[4] = { 3, 2, 1, 2 }; +#endif /* FFMPEG_MPEGAUDIOTAB_H */ diff --git a/contrib/ffmpeg/libavcodec/mpegvideo.c b/contrib/ffmpeg/libavcodec/mpegvideo.c index f0069fa1e..76a17d56d 100644 --- a/contrib/ffmpeg/libavcodec/mpegvideo.c +++ b/contrib/ffmpeg/libavcodec/mpegvideo.c @@ -3,6 +3,8 @@ * Copyright (c) 2000,2001 Fabrice Bellard. * Copyright (c) 2002-2004 Michael Niedermayer * + * 4MV & hq & B-frame encoding stuff by Michael Niedermayer + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -18,8 +20,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * 4MV & hq & b-frame encoding stuff by Michael Niedermayer */ /** @@ -30,19 +30,15 @@ #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" +#include "mpegvideo_common.h" +#include "mjpegenc.h" +#include "msmpeg4.h" #include "faandct.h" #include -#ifdef USE_FASTMEMCPY -#include "libvo/fastmemcpy.h" -#endif - //#undef NDEBUG //#include -#ifdef CONFIG_ENCODERS -static int encode_picture(MpegEncContext *s, int picture_number); -#endif //CONFIG_ENCODERS static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s, DCTELEM *block, int n, int qscale); static void dct_unquantize_mpeg1_inter_c(MpegEncContext *s, @@ -58,19 +54,10 @@ static void dct_unquantize_h263_intra_c(MpegEncContext *s, static void dct_unquantize_h263_inter_c(MpegEncContext *s, DCTELEM *block, int n, int qscale); static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w); -#ifdef CONFIG_ENCODERS -static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); -static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); -static int dct_quantize_refine(MpegEncContext *s, DCTELEM *block, int16_t *weight, DCTELEM *orig, int n, int qscale); -static int sse_mb(MpegEncContext *s); -static void denoise_dct_c(MpegEncContext *s, DCTELEM *block); -#endif //CONFIG_ENCODERS -#ifdef HAVE_XVMC extern int XVMC_field_start(MpegEncContext*s, AVCodecContext *avctx); extern void XVMC_field_end(MpegEncContext *s); extern void XVMC_decode_mb(MpegEncContext *s); -#endif void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w)= draw_edges_c; @@ -81,119 +68,11 @@ void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w)= draw_e //#define DEBUG -/* for jpeg fast DCT */ -#define CONST_BITS 14 - -static const uint16_t aanscales[64] = { - /* precomputed values scaled up by 14 bits */ - 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, - 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, - 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, - 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, - 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, - 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, - 8867 , 12299, 11585, 10426, 8867, 6967, 4799, 2446, - 4520 , 6270, 5906, 5315, 4520, 3552, 2446, 1247 -}; - -static const uint8_t h263_chroma_roundtab[16] = { -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 - 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, -}; - static const uint8_t ff_default_chroma_qscale_table[32]={ // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 }; -#ifdef CONFIG_ENCODERS -static uint8_t default_mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; -static uint8_t default_fcode_tab[MAX_MV*2+1]; - -enum PixelFormat ff_yuv420p_list[2]= {PIX_FMT_YUV420P, -1}; - -static void convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64], - const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra) -{ - int qscale; - int shift=0; - - for(qscale=qmin; qscale<=qmax; qscale++){ - int i; - if (dsp->fdct == ff_jpeg_fdct_islow -#ifdef FAAN_POSTSCALE - || dsp->fdct == ff_faandct -#endif - ) { - for(i=0;i<64;i++) { - const int j= dsp->idct_permutation[i]; - /* 16 <= qscale * quant_matrix[i] <= 7905 */ - /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ - /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ - /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ - - qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) / - (qscale * quant_matrix[j])); - } - } else if (dsp->fdct == fdct_ifast -#ifndef FAAN_POSTSCALE - || dsp->fdct == ff_faandct -#endif - ) { - for(i=0;i<64;i++) { - const int j= dsp->idct_permutation[i]; - /* 16 <= qscale * quant_matrix[i] <= 7905 */ - /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ - /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ - /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ - - qmat[qscale][i] = (int)((UINT64_C(1) << (QMAT_SHIFT + 14)) / - (aanscales[i] * qscale * quant_matrix[j])); - } - } else { - for(i=0;i<64;i++) { - const int j= dsp->idct_permutation[i]; - /* We can safely suppose that 16 <= quant_matrix[i] <= 255 - So 16 <= qscale * quant_matrix[i] <= 7905 - so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 - so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 - */ - qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j])); -// qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]); - qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]); - - if(qmat16[qscale][0][i]==0 || qmat16[qscale][0][i]==128*256) qmat16[qscale][0][i]=128*256-1; - qmat16[qscale][1][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][0][i]); - } - } - - for(i=intra; i<64; i++){ - int64_t max= 8191; - if (dsp->fdct == fdct_ifast -#ifndef FAAN_POSTSCALE - || dsp->fdct == ff_faandct -#endif - ) { - max= (8191LL*aanscales[i]) >> 14; - } - while(((max * qmat[qscale][i]) >> shift) > INT_MAX){ - shift++; - } - } - } - if(shift){ - av_log(NULL, AV_LOG_INFO, "Warning, QMAT_SHIFT is larger than %d, overflows possible\n", QMAT_SHIFT - shift); - } -} - -static inline void update_qscale(MpegEncContext *s){ - s->qscale= (s->lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); - s->qscale= av_clip(s->qscale, s->avctx->qmin, s->avctx->qmax); - - s->lambda2= (s->lambda*s->lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT; -} -#endif //CONFIG_ENCODERS - void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable){ int i; int end; @@ -218,20 +97,6 @@ void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_s } } -#ifdef CONFIG_ENCODERS -void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix){ - int i; - - if(matrix){ - put_bits(pb, 1, 1); - for(i=0;i<64;i++) { - put_bits(pb, 8, matrix[ ff_zigzag_direct[i] ]); - } - }else - put_bits(pb, 1, 0); -} -#endif //CONFIG_ENCODERS - const uint8_t *ff_find_start_code(const uint8_t * restrict p, const uint8_t *end, uint32_t * restrict state){ int i; @@ -257,13 +122,13 @@ const uint8_t *ff_find_start_code(const uint8_t * restrict p, const uint8_t *end } p= FFMIN(p, end)-4; - *state= be2me_32(unaligned32(p)); + *state= AV_RB32(p); return p+4; } /* init common dct for both encoder and decoder */ -int DCT_common_init(MpegEncContext *s) +int ff_dct_common_init(MpegEncContext *s) { s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c; s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c; @@ -274,39 +139,22 @@ int DCT_common_init(MpegEncContext *s) s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_bitexact; s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c; -#ifdef CONFIG_ENCODERS - s->dct_quantize= dct_quantize_c; - s->denoise_dct= denoise_dct_c; -#endif //CONFIG_ENCODERS - -#ifdef HAVE_MMX +#if defined(HAVE_MMX) MPV_common_init_mmx(s); -#endif -#ifdef ARCH_ALPHA +#elif defined(ARCH_ALPHA) MPV_common_init_axp(s); -#endif -#ifdef HAVE_MLIB +#elif defined(HAVE_MLIB) MPV_common_init_mlib(s); -#endif -#ifdef HAVE_MMI +#elif defined(HAVE_MMI) MPV_common_init_mmi(s); -#endif -#ifdef ARCH_ARMV4L +#elif defined(ARCH_ARMV4L) MPV_common_init_armv4l(s); -#endif -#ifdef ARCH_POWERPC - MPV_common_init_ppc(s); +#elif defined(HAVE_ALTIVEC) + MPV_common_init_altivec(s); +#elif defined(ARCH_BFIN) + MPV_common_init_bfin(s); #endif -#ifdef CONFIG_ENCODERS - s->fast_dct_quantize= s->dct_quantize; - - if(s->flags&CODEC_FLAG_TRELLIS_QUANT){ - s->dct_quantize= dct_quantize_trellis_c; //move before MPV_common_init_* - } - -#endif //CONFIG_ENCODERS - /* load & permutate scantables note: only wmv uses different ones */ @@ -323,70 +171,28 @@ int DCT_common_init(MpegEncContext *s) return 0; } -static void copy_picture(Picture *dst, Picture *src){ +void copy_picture(Picture *dst, Picture *src){ *dst = *src; dst->type= FF_BUFFER_TYPE_COPY; } -#ifdef CONFIG_ENCODERS -static void copy_picture_attributes(MpegEncContext *s, AVFrame *dst, AVFrame *src){ - int i; - - dst->pict_type = src->pict_type; - dst->quality = src->quality; - dst->coded_picture_number = src->coded_picture_number; - dst->display_picture_number = src->display_picture_number; -// dst->reference = src->reference; - dst->pts = src->pts; - dst->interlaced_frame = src->interlaced_frame; - dst->top_field_first = src->top_field_first; - - if(s->avctx->me_threshold){ - if(!src->motion_val[0]) - av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_val not set!\n"); - if(!src->mb_type) - av_log(s->avctx, AV_LOG_ERROR, "AVFrame.mb_type not set!\n"); - if(!src->ref_index[0]) - av_log(s->avctx, AV_LOG_ERROR, "AVFrame.ref_index not set!\n"); - if(src->motion_subsample_log2 != dst->motion_subsample_log2) - av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_subsample_log2 doesn't match! (%d!=%d)\n", - src->motion_subsample_log2, dst->motion_subsample_log2); - - memcpy(dst->mb_type, src->mb_type, s->mb_stride * s->mb_height * sizeof(dst->mb_type[0])); - - for(i=0; i<2; i++){ - int stride= ((16*s->mb_width )>>src->motion_subsample_log2) + 1; - int height= ((16*s->mb_height)>>src->motion_subsample_log2); - - if(src->motion_val[i] && src->motion_val[i] != dst->motion_val[i]){ - memcpy(dst->motion_val[i], src->motion_val[i], 2*stride*height*sizeof(int16_t)); - } - if(src->ref_index[i] && src->ref_index[i] != dst->ref_index[i]){ - memcpy(dst->ref_index[i], src->ref_index[i], s->b8_stride*2*s->mb_height*sizeof(int8_t)); - } - } - } -} -#endif - /** * allocates a Picture * The pixels are allocated/set by calling get_buffer() if shared=0 */ -static int alloc_picture(MpegEncContext *s, Picture *pic, int shared){ - const int big_mb_num= s->mb_stride*(s->mb_height+1) + 1; //the +1 is needed so memset(,,stride*height) doesnt sig11 +int alloc_picture(MpegEncContext *s, Picture *pic, int shared){ + const int big_mb_num= s->mb_stride*(s->mb_height+1) + 1; //the +1 is needed so memset(,,stride*height) does not sig11 const int mb_array_size= s->mb_stride*s->mb_height; const int b8_array_size= s->b8_stride*s->mb_height*2; const int b4_array_size= s->b4_stride*s->mb_height*4; int i; + int r= -1; if(shared){ assert(pic->data[0]); assert(pic->type == 0 || pic->type == FF_BUFFER_TYPE_SHARED); pic->type= FF_BUFFER_TYPE_SHARED; }else{ - int r; - assert(!pic->data[0]); r= s->avctx->get_buffer(s->avctx, (AVFrame*)pic); @@ -398,11 +204,13 @@ static int alloc_picture(MpegEncContext *s, Picture *pic, int shared){ if(s->linesize && (s->linesize != pic->linesize[0] || s->uvlinesize != pic->linesize[1])){ av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (stride changed)\n"); + s->avctx->release_buffer(s->avctx, (AVFrame*)pic); return -1; } if(pic->linesize[1] != pic->linesize[2]){ av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (uv stride mismatch)\n"); + s->avctx->release_buffer(s->avctx, (AVFrame*)pic); return -1; } @@ -419,8 +227,8 @@ static int alloc_picture(MpegEncContext *s, Picture *pic, int shared){ CHECKED_ALLOCZ(pic->mbskip_table , mb_array_size * sizeof(uint8_t)+2) //the +2 is for the slice end check CHECKED_ALLOCZ(pic->qscale_table , mb_array_size * sizeof(uint8_t)) - CHECKED_ALLOCZ(pic->mb_type_base , big_mb_num * sizeof(uint32_t)) - pic->mb_type= pic->mb_type_base + s->mb_stride+1; + CHECKED_ALLOCZ(pic->mb_type_base , (big_mb_num + s->mb_stride) * sizeof(uint32_t)) + pic->mb_type= pic->mb_type_base + 2*s->mb_stride+1; if(s->out_format == FMT_H264){ for(i=0; i<2; i++){ CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b4_array_size+4) * sizeof(int16_t)) @@ -443,14 +251,17 @@ static int alloc_picture(MpegEncContext *s, Picture *pic, int shared){ CHECKED_ALLOCZ(pic->pan_scan , 1 * sizeof(AVPanScan)) } - //it might be nicer if the application would keep track of these but it would require a API change + /* It might be nicer if the application would keep track of these + * but it would require an API change. */ memmove(s->prev_pict_types+1, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE-1); s->prev_pict_types[0]= s->pict_type; if(pic->age < PREV_PICT_TYPES_BUFFER_SIZE && s->prev_pict_types[pic->age] == B_TYPE) - pic->age= INT_MAX; // skipped MBs in b frames are quite rare in mpeg1/2 and its a bit tricky to skip them anyway + pic->age= INT_MAX; // Skipped MBs in B-frames are quite rare in MPEG-1/2 and it is a bit tricky to skip them anyway. return 0; fail: //for the CHECKED_ALLOCZ macro + if(r>=0) + s->avctx->release_buffer(s->avctx, (AVFrame*)pic); return -1; } @@ -494,7 +305,7 @@ static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base){ CHECKED_ALLOCZ(s->allocated_edge_emu_buffer, (s->width+64)*2*21*2); //(width + edge + align)*interlaced*MBsize*tolerance s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*21; - //FIXME should be linesize instead of s->width*2 but that isnt known before get_buffer() + //FIXME should be linesize instead of s->width*2 but that is not known before get_buffer() CHECKED_ALLOCZ(s->me.scratchpad, (s->width+64)*4*16*2*sizeof(uint8_t)) s->rd_scratchpad= s->me.scratchpad; s->b_scratchpad= s->me.scratchpad; @@ -569,30 +380,11 @@ void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src){ //STOP_TIMER("update_duplicate_context") //about 10k cycles / 0.01 sec for 1000frames on 1ghz with 2 threads } -#ifdef CONFIG_ENCODERS -static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContext *src){ -#define COPY(a) dst->a= src->a - COPY(pict_type); - COPY(current_picture); - COPY(f_code); - COPY(b_code); - COPY(qscale); - COPY(lambda); - COPY(lambda2); - COPY(picture_in_gop_number); - COPY(gop_picture_number); - COPY(frame_pred_frame_dct); //FIXME don't set in encode_header - COPY(progressive_frame); //FIXME don't set in encode_header - COPY(partitioned_frame); //FIXME don't set in encode_header -#undef COPY -} -#endif - /** * sets the given MpegEncContext to common defaults (same for encoding and decoding). * the changed fields will not depend upon the prior state of the MpegEncContext. */ -static void MPV_common_defaults(MpegEncContext *s){ +void MPV_common_defaults(MpegEncContext *s){ s->y_dc_scale_table= s->c_dc_scale_table= ff_mpeg1_dc_scale_table; s->chroma_qscale_table= ff_default_chroma_qscale_table; @@ -618,31 +410,13 @@ void MPV_decode_defaults(MpegEncContext *s){ MPV_common_defaults(s); } -/** - * sets the given MpegEncContext to defaults for encoding. - * the changed fields will not depend upon the prior state of the MpegEncContext. - */ - -#ifdef CONFIG_ENCODERS -static void MPV_encode_defaults(MpegEncContext *s){ - int i; - MPV_common_defaults(s); - - for(i=-16; i<16; i++){ - default_fcode_tab[i + MAX_MV]= 1; - } - s->me.mv_penalty= default_mv_penalty; - s->fcode_tab= default_fcode_tab; -} -#endif //CONFIG_ENCODERS - /** * init common structure for both encoder and decoder. * this assumes that some variables like width/height are already set */ int MPV_common_init(MpegEncContext *s) { - int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y; + int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y, threads; s->mb_height = (s->height + 15) / 16; @@ -655,7 +429,7 @@ int MPV_common_init(MpegEncContext *s) return -1; dsputil_init(&s->dsp, s->avctx); - DCT_common_init(s); + ff_dct_common_init(s); s->flags= s->avctx->flags; s->flags2= s->avctx->flags2; @@ -811,12 +585,14 @@ int MPV_common_init(MpegEncContext *s) s->context_initialized = 1; s->thread_context[0]= s; - for(i=1; iavctx->thread_count; i++){ + threads = s->avctx->thread_count; + + for(i=1; ithread_context[i]= av_malloc(sizeof(MpegEncContext)); memcpy(s->thread_context[i], s, sizeof(MpegEncContext)); } - for(i=0; iavctx->thread_count; i++){ + for(i=0; ithread_context[i], s) < 0) goto fail; s->thread_context[i]->start_mb_y= (s->mb_height*(i ) + s->avctx->thread_count/2) / s->avctx->thread_count; @@ -913,504 +689,6 @@ void MPV_common_end(MpegEncContext *s) avcodec_default_free_buffers(s->avctx); } -#ifdef CONFIG_ENCODERS - -/* init video encoder */ -int MPV_encode_init(AVCodecContext *avctx) -{ - MpegEncContext *s = avctx->priv_data; - int i; - int chroma_h_shift, chroma_v_shift; - - MPV_encode_defaults(s); - - switch (avctx->codec_id) { - case CODEC_ID_MPEG2VIDEO: - if(avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P){ - av_log(avctx, AV_LOG_ERROR, "only YUV420 and YUV422 are supported\n"); - return -1; - } - break; - case CODEC_ID_LJPEG: - case CODEC_ID_MJPEG: - if(avctx->pix_fmt != PIX_FMT_YUVJ420P && avctx->pix_fmt != PIX_FMT_YUVJ422P && - ((avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P) || avctx->strict_std_compliance>FF_COMPLIANCE_INOFFICIAL)){ - av_log(avctx, AV_LOG_ERROR, "colorspace not supported in jpeg\n"); - return -1; - } - break; - default: - if(avctx->pix_fmt != PIX_FMT_YUV420P){ - av_log(avctx, AV_LOG_ERROR, "only YUV420 is supported\n"); - return -1; - } - } - - switch (avctx->pix_fmt) { - case PIX_FMT_YUVJ422P: - case PIX_FMT_YUV422P: - s->chroma_format = CHROMA_422; - break; - case PIX_FMT_YUVJ420P: - case PIX_FMT_YUV420P: - default: - s->chroma_format = CHROMA_420; - break; - } - - s->bit_rate = avctx->bit_rate; - s->width = avctx->width; - s->height = avctx->height; - if(avctx->gop_size > 600 && avctx->strict_std_compliance>FF_COMPLIANCE_EXPERIMENTAL){ - av_log(avctx, AV_LOG_ERROR, "Warning keyframe interval too large! reducing it ...\n"); - avctx->gop_size=600; - } - s->gop_size = avctx->gop_size; - s->avctx = avctx; - s->flags= avctx->flags; - s->flags2= avctx->flags2; - s->max_b_frames= avctx->max_b_frames; - s->codec_id= avctx->codec->id; - s->luma_elim_threshold = avctx->luma_elim_threshold; - s->chroma_elim_threshold= avctx->chroma_elim_threshold; - s->strict_std_compliance= avctx->strict_std_compliance; - s->data_partitioning= avctx->flags & CODEC_FLAG_PART; - s->quarter_sample= (avctx->flags & CODEC_FLAG_QPEL)!=0; - s->mpeg_quant= avctx->mpeg_quant; - s->rtp_mode= !!avctx->rtp_payload_size; - s->intra_dc_precision= avctx->intra_dc_precision; - s->user_specified_pts = AV_NOPTS_VALUE; - - if (s->gop_size <= 1) { - s->intra_only = 1; - s->gop_size = 12; - } else { - s->intra_only = 0; - } - - s->me_method = avctx->me_method; - - /* Fixed QSCALE */ - s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE); - - s->adaptive_quant= ( s->avctx->lumi_masking - || s->avctx->dark_masking - || s->avctx->temporal_cplx_masking - || s->avctx->spatial_cplx_masking - || s->avctx->p_masking - || s->avctx->border_masking - || (s->flags&CODEC_FLAG_QP_RD)) - && !s->fixed_qscale; - - s->obmc= !!(s->flags & CODEC_FLAG_OBMC); - s->loop_filter= !!(s->flags & CODEC_FLAG_LOOP_FILTER); - s->alternate_scan= !!(s->flags & CODEC_FLAG_ALT_SCAN); - s->intra_vlc_format= !!(s->flags2 & CODEC_FLAG2_INTRA_VLC); - s->q_scale_type= !!(s->flags2 & CODEC_FLAG2_NON_LINEAR_QUANT); - - if(avctx->rc_max_rate && !avctx->rc_buffer_size){ - av_log(avctx, AV_LOG_ERROR, "a vbv buffer size is needed, for encoding with a maximum bitrate\n"); - return -1; - } - - if(avctx->rc_min_rate && avctx->rc_max_rate != avctx->rc_min_rate){ - av_log(avctx, AV_LOG_INFO, "Warning min_rate > 0 but min_rate != max_rate isn't recommended!\n"); - } - - if(avctx->rc_min_rate && avctx->rc_min_rate > avctx->bit_rate){ - av_log(avctx, AV_LOG_INFO, "bitrate below min bitrate\n"); - return -1; - } - - if(avctx->rc_max_rate && avctx->rc_max_rate < avctx->bit_rate){ - av_log(avctx, AV_LOG_INFO, "bitrate above max bitrate\n"); - return -1; - } - - if( s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate - && (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO) - && 90000LL * (avctx->rc_buffer_size-1) > s->avctx->rc_max_rate*0xFFFFLL){ - - av_log(avctx, AV_LOG_INFO, "Warning vbv_delay will be set to 0xFFFF (=VBR) as the specified vbv buffer is too large for the given bitrate!\n"); - } - - if((s->flags & CODEC_FLAG_4MV) && s->codec_id != CODEC_ID_MPEG4 - && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P && s->codec_id != CODEC_ID_FLV1){ - av_log(avctx, AV_LOG_ERROR, "4MV not supported by codec\n"); - return -1; - } - - if(s->obmc && s->avctx->mb_decision != FF_MB_DECISION_SIMPLE){ - av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with simple mb decision\n"); - return -1; - } - - if(s->obmc && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P){ - av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with H263(+)\n"); - return -1; - } - - if(s->quarter_sample && s->codec_id != CODEC_ID_MPEG4){ - av_log(avctx, AV_LOG_ERROR, "qpel not supported by codec\n"); - return -1; - } - - if(s->data_partitioning && s->codec_id != CODEC_ID_MPEG4){ - av_log(avctx, AV_LOG_ERROR, "data partitioning not supported by codec\n"); - return -1; - } - - if(s->max_b_frames && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO){ - av_log(avctx, AV_LOG_ERROR, "b frames not supported by codec\n"); - return -1; - } - - if((s->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN)) - && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG2VIDEO){ - av_log(avctx, AV_LOG_ERROR, "interlacing not supported by codec\n"); - return -1; - } - - if(s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4){ //FIXME mpeg2 uses that too - av_log(avctx, AV_LOG_ERROR, "mpeg2 style quantization not supported by codec\n"); - return -1; - } - - if((s->flags & CODEC_FLAG_CBP_RD) && !(s->flags & CODEC_FLAG_TRELLIS_QUANT)){ - av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n"); - return -1; - } - - if((s->flags & CODEC_FLAG_QP_RD) && s->avctx->mb_decision != FF_MB_DECISION_RD){ - av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n"); - return -1; - } - - if(s->avctx->scenechange_threshold < 1000000000 && (s->flags & CODEC_FLAG_CLOSED_GOP)){ - av_log(avctx, AV_LOG_ERROR, "closed gop with scene change detection arent supported yet, set threshold to 1000000000\n"); - return -1; - } - - if((s->flags2 & CODEC_FLAG2_INTRA_VLC) && s->codec_id != CODEC_ID_MPEG2VIDEO){ - av_log(avctx, AV_LOG_ERROR, "intra vlc table not supported by codec\n"); - return -1; - } - - if(s->flags & CODEC_FLAG_LOW_DELAY){ - if (s->codec_id != CODEC_ID_MPEG2VIDEO && s->codec_id != CODEC_ID_MPEG1VIDEO){ - av_log(avctx, AV_LOG_ERROR, "low delay forcing is only available for mpeg1/2\n"); - return -1; - } - if (s->max_b_frames != 0){ - av_log(avctx, AV_LOG_ERROR, "b frames cannot be used with low delay\n"); - return -1; - } - } - - if(s->q_scale_type == 1){ - if(s->codec_id != CODEC_ID_MPEG2VIDEO){ - av_log(avctx, AV_LOG_ERROR, "non linear quant is only available for mpeg2\n"); - return -1; - } - if(avctx->qmax > 12){ - av_log(avctx, AV_LOG_ERROR, "non linear quant only supports qmax <= 12 currently\n"); - return -1; - } - } - - if(s->avctx->thread_count > 1 && s->codec_id != CODEC_ID_MPEG4 - && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO - && (s->codec_id != CODEC_ID_H263P || !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))){ - av_log(avctx, AV_LOG_ERROR, "multi threaded encoding not supported by codec\n"); - return -1; - } - - if(s->avctx->thread_count > 1) - s->rtp_mode= 1; - - if(!avctx->time_base.den || !avctx->time_base.num){ - av_log(avctx, AV_LOG_ERROR, "framerate not set\n"); - return -1; - } - - i= (INT_MAX/2+128)>>8; - if(avctx->me_threshold >= i){ - av_log(avctx, AV_LOG_ERROR, "me_threshold too large, max is %d\n", i - 1); - return -1; - } - if(avctx->mb_threshold >= i){ - av_log(avctx, AV_LOG_ERROR, "mb_threshold too large, max is %d\n", i - 1); - return -1; - } - - if(avctx->b_frame_strategy && (avctx->flags&CODEC_FLAG_PASS2)){ - av_log(avctx, AV_LOG_INFO, "notice: b_frame_strategy only affects the first pass\n"); - avctx->b_frame_strategy = 0; - } - - i= ff_gcd(avctx->time_base.den, avctx->time_base.num); - if(i > 1){ - av_log(avctx, AV_LOG_INFO, "removing common factors from framerate\n"); - avctx->time_base.den /= i; - avctx->time_base.num /= i; -// return -1; - } - - if(s->codec_id==CODEC_ID_MJPEG){ - s->intra_quant_bias= 1<<(QUANT_BIAS_SHIFT-1); //(a + x/2)/x - s->inter_quant_bias= 0; - }else if(s->mpeg_quant || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO){ - s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x - s->inter_quant_bias= 0; - }else{ - s->intra_quant_bias=0; - s->inter_quant_bias=-(1<<(QUANT_BIAS_SHIFT-2)); //(a - x/4)/x - } - - if(avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS) - s->intra_quant_bias= avctx->intra_quant_bias; - if(avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS) - s->inter_quant_bias= avctx->inter_quant_bias; - - avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, &chroma_v_shift); - - if(avctx->codec_id == CODEC_ID_MPEG4 && s->avctx->time_base.den > (1<<16)-1){ - av_log(avctx, AV_LOG_ERROR, "timebase not supported by mpeg 4 standard\n"); - return -1; - } - s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1; - - switch(avctx->codec->id) { - case CODEC_ID_MPEG1VIDEO: - s->out_format = FMT_MPEG1; - s->low_delay= !!(s->flags & CODEC_FLAG_LOW_DELAY); - avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); - break; - case CODEC_ID_MPEG2VIDEO: - s->out_format = FMT_MPEG1; - s->low_delay= !!(s->flags & CODEC_FLAG_LOW_DELAY); - avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); - s->rtp_mode= 1; - break; - case CODEC_ID_LJPEG: - case CODEC_ID_JPEGLS: - case CODEC_ID_MJPEG: - s->out_format = FMT_MJPEG; - s->intra_only = 1; /* force intra only for jpeg */ - s->mjpeg_write_tables = avctx->codec->id != CODEC_ID_JPEGLS; - s->mjpeg_data_only_frames = 0; /* write all the needed headers */ - s->mjpeg_vsample[0] = 2; - s->mjpeg_vsample[1] = 2>>chroma_v_shift; - s->mjpeg_vsample[2] = 2>>chroma_v_shift; - s->mjpeg_hsample[0] = 2; - s->mjpeg_hsample[1] = 2>>chroma_h_shift; - s->mjpeg_hsample[2] = 2>>chroma_h_shift; - if (mjpeg_init(s) < 0) - return -1; - avctx->delay=0; - s->low_delay=1; - break; -#ifdef CONFIG_H261_ENCODER - case CODEC_ID_H261: - if (ff_h261_get_picture_format(s->width, s->height) < 0) { - av_log(avctx, AV_LOG_ERROR, "The specified picture size of %dx%d is not valid for the H.261 codec.\nValid sizes are 176x144, 352x288\n", s->width, s->height); - return -1; - } - s->out_format = FMT_H261; - avctx->delay=0; - s->low_delay=1; - break; -#endif - case CODEC_ID_H263: - if (h263_get_picture_format(s->width, s->height) == 7) { - av_log(avctx, AV_LOG_INFO, "The specified picture size of %dx%d is not valid for the H.263 codec.\nValid sizes are 128x96, 176x144, 352x288, 704x576, and 1408x1152. Try H.263+.\n", s->width, s->height); - return -1; - } - s->out_format = FMT_H263; - s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0; - avctx->delay=0; - s->low_delay=1; - break; - case CODEC_ID_H263P: - s->out_format = FMT_H263; - s->h263_plus = 1; - /* Fx */ - s->umvplus = (avctx->flags & CODEC_FLAG_H263P_UMV) ? 1:0; - s->h263_aic= (avctx->flags & CODEC_FLAG_AC_PRED) ? 1:0; - s->modified_quant= s->h263_aic; - s->alt_inter_vlc= (avctx->flags & CODEC_FLAG_H263P_AIV) ? 1:0; - s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0; - s->loop_filter= (avctx->flags & CODEC_FLAG_LOOP_FILTER) ? 1:0; - s->unrestricted_mv= s->obmc || s->loop_filter || s->umvplus; - s->h263_slice_structured= (s->flags & CODEC_FLAG_H263P_SLICE_STRUCT) ? 1:0; - - /* /Fx */ - /* These are just to be sure */ - avctx->delay=0; - s->low_delay=1; - break; - case CODEC_ID_FLV1: - s->out_format = FMT_H263; - s->h263_flv = 2; /* format = 1; 11-bit codes */ - s->unrestricted_mv = 1; - s->rtp_mode=0; /* don't allow GOB */ - avctx->delay=0; - s->low_delay=1; - break; - case CODEC_ID_RV10: - s->out_format = FMT_H263; - avctx->delay=0; - s->low_delay=1; - break; - case CODEC_ID_RV20: - s->out_format = FMT_H263; - avctx->delay=0; - s->low_delay=1; - s->modified_quant=1; - s->h263_aic=1; - s->h263_plus=1; - s->loop_filter=1; - s->unrestricted_mv= s->obmc || s->loop_filter || s->umvplus; - break; - case CODEC_ID_MPEG4: - s->out_format = FMT_H263; - s->h263_pred = 1; - s->unrestricted_mv = 1; - s->low_delay= s->max_b_frames ? 0 : 1; - avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); - break; - case CODEC_ID_MSMPEG4V1: - s->out_format = FMT_H263; - s->h263_msmpeg4 = 1; - s->h263_pred = 1; - s->unrestricted_mv = 1; - s->msmpeg4_version= 1; - avctx->delay=0; - s->low_delay=1; - break; - case CODEC_ID_MSMPEG4V2: - s->out_format = FMT_H263; - s->h263_msmpeg4 = 1; - s->h263_pred = 1; - s->unrestricted_mv = 1; - s->msmpeg4_version= 2; - avctx->delay=0; - s->low_delay=1; - break; - case CODEC_ID_MSMPEG4V3: - s->out_format = FMT_H263; - s->h263_msmpeg4 = 1; - s->h263_pred = 1; - s->unrestricted_mv = 1; - s->msmpeg4_version= 3; - s->flipflop_rounding=1; - avctx->delay=0; - s->low_delay=1; - break; - case CODEC_ID_WMV1: - s->out_format = FMT_H263; - s->h263_msmpeg4 = 1; - s->h263_pred = 1; - s->unrestricted_mv = 1; - s->msmpeg4_version= 4; - s->flipflop_rounding=1; - avctx->delay=0; - s->low_delay=1; - break; - case CODEC_ID_WMV2: - s->out_format = FMT_H263; - s->h263_msmpeg4 = 1; - s->h263_pred = 1; - s->unrestricted_mv = 1; - s->msmpeg4_version= 5; - s->flipflop_rounding=1; - avctx->delay=0; - s->low_delay=1; - break; - default: - return -1; - } - - avctx->has_b_frames= !s->low_delay; - - s->encoding = 1; - - /* init */ - if (MPV_common_init(s) < 0) - return -1; - - if(s->modified_quant) - s->chroma_qscale_table= ff_h263_chroma_qscale_table; - s->progressive_frame= - s->progressive_sequence= !(avctx->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN)); - s->quant_precision=5; - - ff_set_cmp(&s->dsp, s->dsp.ildct_cmp, s->avctx->ildct_cmp); - ff_set_cmp(&s->dsp, s->dsp.frame_skip_cmp, s->avctx->frame_skip_cmp); - -#ifdef CONFIG_H261_ENCODER - if (s->out_format == FMT_H261) - ff_h261_encode_init(s); -#endif - if (s->out_format == FMT_H263) - h263_encode_init(s); - if(s->msmpeg4_version) - ff_msmpeg4_encode_init(s); - if (s->out_format == FMT_MPEG1) - ff_mpeg1_encode_init(s); - - /* init q matrix */ - for(i=0;i<64;i++) { - int j= s->dsp.idct_permutation[i]; - if(s->codec_id==CODEC_ID_MPEG4 && s->mpeg_quant){ - s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i]; - s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i]; - }else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){ - s->intra_matrix[j] = - s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; - }else - { /* mpeg1/2 */ - s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i]; - s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; - } - if(s->avctx->intra_matrix) - s->intra_matrix[j] = s->avctx->intra_matrix[i]; - if(s->avctx->inter_matrix) - s->inter_matrix[j] = s->avctx->inter_matrix[i]; - } - - /* precompute matrix */ - /* for mjpeg, we do include qscale in the matrix */ - if (s->out_format != FMT_MJPEG) { - convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, - s->intra_matrix, s->intra_quant_bias, avctx->qmin, 31, 1); - convert_matrix(&s->dsp, s->q_inter_matrix, s->q_inter_matrix16, - s->inter_matrix, s->inter_quant_bias, avctx->qmin, 31, 0); - } - - if(ff_rate_control_init(s) < 0) - return -1; - - return 0; -} - -int MPV_encode_end(AVCodecContext *avctx) -{ - MpegEncContext *s = avctx->priv_data; - - ff_rate_control_uninit(s); - - MPV_common_end(s); - if (s->out_format == FMT_MJPEG) - mjpeg_close(s); - - av_freep(&avctx->extradata); - - return 0; -} - -#endif //CONFIG_ENCODERS - void init_rl(RLTable *rl, uint8_t static_store[2][2*MAX_RUN + MAX_LEVEL + 3]) { int8_t max_level[MAX_RUN+1], max_run[MAX_LEVEL+1]; @@ -1462,15 +740,68 @@ void init_rl(RLTable *rl, uint8_t static_store[2][2*MAX_RUN + MAX_LEVEL + 3]) } } -/* draw the edges of width 'w' of an image of size width, height */ -//FIXME check that this is ok for mpeg4 interlaced -static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w) +void init_vlc_rl(RLTable *rl, int use_static) { - uint8_t *ptr, *last_line; - int i; + int i, q; - last_line = buf + (height - 1) * wrap; - for(i=0;irl_vlc[0]) + return; + + init_vlc(&rl->vlc, 9, rl->n + 1, + &rl->table_vlc[0][1], 4, 2, + &rl->table_vlc[0][0], 4, 2, use_static); + + + for(q=0; q<32; q++){ + int qmul= q*2; + int qadd= (q-1)|1; + + if(q==0){ + qmul=1; + qadd=0; + } + if(use_static) + rl->rl_vlc[q]= av_mallocz_static(rl->vlc.table_size*sizeof(RL_VLC_ELEM)); + else + rl->rl_vlc[q]= av_malloc(rl->vlc.table_size*sizeof(RL_VLC_ELEM)); + for(i=0; ivlc.table_size; i++){ + int code= rl->vlc.table[i][0]; + int len = rl->vlc.table[i][1]; + int level, run; + + if(len==0){ // illegal code + run= 66; + level= MAX_LEVEL; + }else if(len<0){ //more bits needed + run= 0; + level= code; + }else{ + if(code==rl->n){ //esc + run= 66; + level= 0; + }else{ + run= rl->table_run [code] + 1; + level= rl->table_level[code] * qmul + qadd; + if(code >= rl->last) run+=192; + } + } + rl->rl_vlc[q][i].len= len; + rl->rl_vlc[q][i].level= level; + rl->rl_vlc[q][i].run= run; + } + } +} + +/* draw the edges of width 'w' of an image of size width, height */ +//FIXME check that this is ok for mpeg4 interlaced +static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w) +{ + uint8_t *ptr, *last_line; + int i; + + last_line = buf + (height - 1) * wrap; + for(i=0;iavctx, AV_LOG_FATAL, "Internal error, picture buffer overflow\n"); + /* We could return -1, but the codec would crash trying to draw into a + * non-existing frame anyway. This is safer than waiting for a random crash. + * Also the return of this is never useful, an encoder must only allocate + * as much as allowed in the specification. This has no relationship to how + * much libavcodec could allocate (and MAX_PICTURE_COUNT is always large + * enough for such valid streams). + * Plus, a decoder has to check stream validity and remove frames if too + * many reference frames are around. Waiting for "OOM" is not correct at + * all. Similarly, missing reference frames have to be replaced by + * interpolated/MC frames, anything else is a bug in the codec ... + */ + abort(); return -1; } @@ -1572,8 +915,13 @@ alloc: pic= (AVFrame*)&s->picture[i]; } - pic->reference= (s->pict_type != B_TYPE || s->codec_id == CODEC_ID_H264) - && !s->dropable ? 3 : 0; + pic->reference= 0; + if (!s->dropable){ + if (s->codec_id == CODEC_ID_H264) + pic->reference = s->picture_structure; + else if (s->pict_type != B_TYPE) + pic->reference = 3; + } pic->coded_picture_number= s->coded_picture_number++; @@ -1614,7 +962,7 @@ alloc: assert(s->pict_type == I_TYPE || (s->last_picture_ptr && s->last_picture_ptr->data[0])); - if(s->picture_structure!=PICT_FRAME){ + if(s->picture_structure!=PICT_FRAME && s->out_format != FMT_H264){ int i; for(i=0; i<4; i++){ if(s->picture_structure == PICT_BOTTOM_FIELD){ @@ -1630,7 +978,7 @@ alloc: s->error_resilience= avctx->error_resilience; /* set dequantizer, we can't do it during init as it might change for mpeg4 - and we can't do it in the header decode as init isnt called for mpeg4 there yet */ + and we can't do it in the header decode as init is not called for mpeg4 there yet */ if(s->mpeg_quant || s->codec_id == CODEC_ID_MPEG2VIDEO){ s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra; s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter; @@ -1749,8 +1097,8 @@ static void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h for(y= 0; y <= ey; y++){ x = (y*f)>>16; fr= (y*f)&0xFFFF; - buf[y*stride + x ]+= (color*(0x10000-fr))>>16;; - buf[y*stride + x+1]+= (color* fr )>>16;; + buf[y*stride + x ]+= (color*(0x10000-fr))>>16; + buf[y*stride + x+1]+= (color* fr )>>16; } } } @@ -2049,751 +1397,6 @@ v= (int)(128 + r*sin(theta*3.141592/180)); } } -#ifdef CONFIG_ENCODERS - -static int get_sae(uint8_t *src, int ref, int stride){ - int x,y; - int acc=0; - - for(y=0; y<16; y++){ - for(x=0; x<16; x++){ - acc+= FFABS(src[x+y*stride] - ref); - } - } - - return acc; -} - -static int get_intra_count(MpegEncContext *s, uint8_t *src, uint8_t *ref, int stride){ - int x, y, w, h; - int acc=0; - - w= s->width &~15; - h= s->height&~15; - - for(y=0; ydsp.sad[0](NULL, src + offset, ref + offset, stride, 16); - int mean= (s->dsp.pix_sum(src + offset, stride) + 128)>>8; - int sae = get_sae(src + offset, mean, stride); - - acc+= sae + 500 < sad; - } - } - return acc; -} - - -static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg){ - AVFrame *pic=NULL; - int64_t pts; - int i; - const int encoding_delay= s->max_b_frames; - int direct=1; - - if(pic_arg){ - pts= pic_arg->pts; - pic_arg->display_picture_number= s->input_picture_number++; - - if(pts != AV_NOPTS_VALUE){ - if(s->user_specified_pts != AV_NOPTS_VALUE){ - int64_t time= pts; - int64_t last= s->user_specified_pts; - - if(time <= last){ - av_log(s->avctx, AV_LOG_ERROR, "Error, Invalid timestamp=%"PRId64", last=%"PRId64"\n", pts, s->user_specified_pts); - return -1; - } - } - s->user_specified_pts= pts; - }else{ - if(s->user_specified_pts != AV_NOPTS_VALUE){ - s->user_specified_pts= - pts= s->user_specified_pts + 1; - av_log(s->avctx, AV_LOG_INFO, "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", pts); - }else{ - pts= pic_arg->display_picture_number; - } - } - } - - if(pic_arg){ - if(encoding_delay && !(s->flags&CODEC_FLAG_INPUT_PRESERVED)) direct=0; - if(pic_arg->linesize[0] != s->linesize) direct=0; - if(pic_arg->linesize[1] != s->uvlinesize) direct=0; - if(pic_arg->linesize[2] != s->uvlinesize) direct=0; - -// av_log(AV_LOG_DEBUG, "%d %d %d %d\n",pic_arg->linesize[0], pic_arg->linesize[1], s->linesize, s->uvlinesize); - - if(direct){ - i= ff_find_unused_picture(s, 1); - - pic= (AVFrame*)&s->picture[i]; - pic->reference= 3; - - for(i=0; i<4; i++){ - pic->data[i]= pic_arg->data[i]; - pic->linesize[i]= pic_arg->linesize[i]; - } - alloc_picture(s, (Picture*)pic, 1); - }else{ - i= ff_find_unused_picture(s, 0); - - pic= (AVFrame*)&s->picture[i]; - pic->reference= 3; - - alloc_picture(s, (Picture*)pic, 0); - - if( pic->data[0] + INPLACE_OFFSET == pic_arg->data[0] - && pic->data[1] + INPLACE_OFFSET == pic_arg->data[1] - && pic->data[2] + INPLACE_OFFSET == pic_arg->data[2]){ - // empty - }else{ - int h_chroma_shift, v_chroma_shift; - avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift); - - for(i=0; i<3; i++){ - int src_stride= pic_arg->linesize[i]; - int dst_stride= i ? s->uvlinesize : s->linesize; - int h_shift= i ? h_chroma_shift : 0; - int v_shift= i ? v_chroma_shift : 0; - int w= s->width >>h_shift; - int h= s->height>>v_shift; - uint8_t *src= pic_arg->data[i]; - uint8_t *dst= pic->data[i]; - - if(!s->avctx->rc_buffer_size) - dst +=INPLACE_OFFSET; - - if(src_stride==dst_stride) - memcpy(dst, src, src_stride*h); - else{ - while(h--){ - memcpy(dst, src, w); - dst += dst_stride; - src += src_stride; - } - } - } - } - } - copy_picture_attributes(s, pic, pic_arg); - pic->pts= pts; //we set this here to avoid modifiying pic_arg - } - - /* shift buffer entries */ - for(i=1; iencoding_delay+1*/; i++) - s->input_picture[i-1]= s->input_picture[i]; - - s->input_picture[encoding_delay]= (Picture*)pic; - - return 0; -} - -static int skip_check(MpegEncContext *s, Picture *p, Picture *ref){ - int x, y, plane; - int score=0; - int64_t score64=0; - - for(plane=0; plane<3; plane++){ - const int stride= p->linesize[plane]; - const int bw= plane ? 1 : 2; - for(y=0; ymb_height*bw; y++){ - for(x=0; xmb_width*bw; x++){ - int off= p->type == FF_BUFFER_TYPE_SHARED ? 0: 16; - int v= s->dsp.frame_skip_cmp[1](s, p->data[plane] + 8*(x + y*stride)+off, ref->data[plane] + 8*(x + y*stride), stride, 8); - - switch(s->avctx->frame_skip_exp){ - case 0: score= FFMAX(score, v); break; - case 1: score+= FFABS(v);break; - case 2: score+= v*v;break; - case 3: score64+= FFABS(v*v*(int64_t)v);break; - case 4: score64+= v*v*(int64_t)(v*v);break; - } - } - } - } - - if(score) score64= score; - - if(score64 < s->avctx->frame_skip_threshold) - return 1; - if(score64 < ((s->avctx->frame_skip_factor * (int64_t)s->lambda)>>8)) - return 1; - return 0; -} - -static int estimate_best_b_count(MpegEncContext *s){ - AVCodec *codec= avcodec_find_encoder(s->avctx->codec_id); - AVCodecContext *c= avcodec_alloc_context(); - AVFrame input[FF_MAX_B_FRAMES+2]; - const int scale= s->avctx->brd_scale; - int i, j, out_size, p_lambda, b_lambda, lambda2; - int outbuf_size= s->width * s->height; //FIXME - uint8_t *outbuf= av_malloc(outbuf_size); - int64_t best_rd= INT64_MAX; - int best_b_count= -1; - - assert(scale>=0 && scale <=3); - -// emms_c(); - p_lambda= s->last_lambda_for[P_TYPE]; //s->next_picture_ptr->quality; - b_lambda= s->last_lambda_for[B_TYPE]; //p_lambda *FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset; - if(!b_lambda) b_lambda= p_lambda; //FIXME we should do this somewhere else - lambda2= (b_lambda*b_lambda + (1<> FF_LAMBDA_SHIFT; - - c->width = s->width >> scale; - c->height= s->height>> scale; - c->flags= CODEC_FLAG_QSCALE | CODEC_FLAG_PSNR | CODEC_FLAG_INPUT_PRESERVED /*| CODEC_FLAG_EMU_EDGE*/; - c->flags|= s->avctx->flags & CODEC_FLAG_QPEL; - c->mb_decision= s->avctx->mb_decision; - c->me_cmp= s->avctx->me_cmp; - c->mb_cmp= s->avctx->mb_cmp; - c->me_sub_cmp= s->avctx->me_sub_cmp; - c->pix_fmt = PIX_FMT_YUV420P; - c->time_base= s->avctx->time_base; - c->max_b_frames= s->max_b_frames; - - if (avcodec_open(c, codec) < 0) - return -1; - - for(i=0; imax_b_frames+2; i++){ - int ysize= c->width*c->height; - int csize= (c->width/2)*(c->height/2); - Picture pre_input, *pre_input_ptr= i ? s->input_picture[i-1] : s->next_picture_ptr; - - avcodec_get_frame_defaults(&input[i]); - input[i].data[0]= av_malloc(ysize + 2*csize); - input[i].data[1]= input[i].data[0] + ysize; - input[i].data[2]= input[i].data[1] + csize; - input[i].linesize[0]= c->width; - input[i].linesize[1]= - input[i].linesize[2]= c->width/2; - - if(pre_input_ptr && (!i || s->input_picture[i-1])) { - pre_input= *pre_input_ptr; - - if(pre_input.type != FF_BUFFER_TYPE_SHARED && i) { - pre_input.data[0]+=INPLACE_OFFSET; - pre_input.data[1]+=INPLACE_OFFSET; - pre_input.data[2]+=INPLACE_OFFSET; - } - - s->dsp.shrink[scale](input[i].data[0], input[i].linesize[0], pre_input.data[0], pre_input.linesize[0], c->width, c->height); - s->dsp.shrink[scale](input[i].data[1], input[i].linesize[1], pre_input.data[1], pre_input.linesize[1], c->width>>1, c->height>>1); - s->dsp.shrink[scale](input[i].data[2], input[i].linesize[2], pre_input.data[2], pre_input.linesize[2], c->width>>1, c->height>>1); - } - } - - for(j=0; jmax_b_frames+1; j++){ - int64_t rd=0; - - if(!s->input_picture[j]) - break; - - c->error[0]= c->error[1]= c->error[2]= 0; - - input[0].pict_type= I_TYPE; - input[0].quality= 1 * FF_QP2LAMBDA; - out_size = avcodec_encode_video(c, outbuf, outbuf_size, &input[0]); -// rd += (out_size * lambda2) >> FF_LAMBDA_SHIFT; - - for(i=0; imax_b_frames+1; i++){ - int is_p= i % (j+1) == j || i==s->max_b_frames; - - input[i+1].pict_type= is_p ? P_TYPE : B_TYPE; - input[i+1].quality= is_p ? p_lambda : b_lambda; - out_size = avcodec_encode_video(c, outbuf, outbuf_size, &input[i+1]); - rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3); - } - - /* get the delayed frames */ - while(out_size){ - out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL); - rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3); - } - - rd += c->error[0] + c->error[1] + c->error[2]; - - if(rd < best_rd){ - best_rd= rd; - best_b_count= j; - } - } - - av_freep(&outbuf); - avcodec_close(c); - av_freep(&c); - - for(i=0; imax_b_frames+2; i++){ - av_freep(&input[i].data[0]); - } - - return best_b_count; -} - -static void select_input_picture(MpegEncContext *s){ - int i; - - for(i=1; ireordered_input_picture[i-1]= s->reordered_input_picture[i]; - s->reordered_input_picture[MAX_PICTURE_COUNT-1]= NULL; - - /* set next picture type & ordering */ - if(s->reordered_input_picture[0]==NULL && s->input_picture[0]){ - if(/*s->picture_in_gop_number >= s->gop_size ||*/ s->next_picture_ptr==NULL || s->intra_only){ - s->reordered_input_picture[0]= s->input_picture[0]; - s->reordered_input_picture[0]->pict_type= I_TYPE; - s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++; - }else{ - int b_frames; - - if(s->avctx->frame_skip_threshold || s->avctx->frame_skip_factor){ - if(s->picture_in_gop_number < s->gop_size && skip_check(s, s->input_picture[0], s->next_picture_ptr)){ - //FIXME check that te gop check above is +-1 correct -//av_log(NULL, AV_LOG_DEBUG, "skip %p %"PRId64"\n", s->input_picture[0]->data[0], s->input_picture[0]->pts); - - if(s->input_picture[0]->type == FF_BUFFER_TYPE_SHARED){ - for(i=0; i<4; i++) - s->input_picture[0]->data[i]= NULL; - s->input_picture[0]->type= 0; - }else{ - assert( s->input_picture[0]->type==FF_BUFFER_TYPE_USER - || s->input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL); - - s->avctx->release_buffer(s->avctx, (AVFrame*)s->input_picture[0]); - } - - emms_c(); - ff_vbv_update(s, 0); - - goto no_output_pic; - } - } - - if(s->flags&CODEC_FLAG_PASS2){ - for(i=0; imax_b_frames+1; i++){ - int pict_num= s->input_picture[0]->display_picture_number + i; - - if(pict_num >= s->rc_context.num_entries) - break; - if(!s->input_picture[i]){ - s->rc_context.entry[pict_num-1].new_pict_type = P_TYPE; - break; - } - - s->input_picture[i]->pict_type= - s->rc_context.entry[pict_num].new_pict_type; - } - } - - if(s->avctx->b_frame_strategy==0){ - b_frames= s->max_b_frames; - while(b_frames && !s->input_picture[b_frames]) b_frames--; - }else if(s->avctx->b_frame_strategy==1){ - for(i=1; imax_b_frames+1; i++){ - if(s->input_picture[i] && s->input_picture[i]->b_frame_score==0){ - s->input_picture[i]->b_frame_score= - get_intra_count(s, s->input_picture[i ]->data[0], - s->input_picture[i-1]->data[0], s->linesize) + 1; - } - } - for(i=0; imax_b_frames+1; i++){ - if(s->input_picture[i]==NULL || s->input_picture[i]->b_frame_score - 1 > s->mb_num/s->avctx->b_sensitivity) break; - } - - b_frames= FFMAX(0, i-1); - - /* reset scores */ - for(i=0; iinput_picture[i]->b_frame_score=0; - } - }else if(s->avctx->b_frame_strategy==2){ - b_frames= estimate_best_b_count(s); - }else{ - av_log(s->avctx, AV_LOG_ERROR, "illegal b frame strategy\n"); - b_frames=0; - } - - emms_c(); -//static int b_count=0; -//b_count+= b_frames; -//av_log(s->avctx, AV_LOG_DEBUG, "b_frames: %d\n", b_count); - - for(i= b_frames - 1; i>=0; i--){ - int type= s->input_picture[i]->pict_type; - if(type && type != B_TYPE) - b_frames= i; - } - if(s->input_picture[b_frames]->pict_type == B_TYPE && b_frames == s->max_b_frames){ - av_log(s->avctx, AV_LOG_ERROR, "warning, too many b frames in a row\n"); - } - - if(s->picture_in_gop_number + b_frames >= s->gop_size){ - if((s->flags2 & CODEC_FLAG2_STRICT_GOP) && s->gop_size > s->picture_in_gop_number){ - b_frames= s->gop_size - s->picture_in_gop_number - 1; - }else{ - if(s->flags & CODEC_FLAG_CLOSED_GOP) - b_frames=0; - s->input_picture[b_frames]->pict_type= I_TYPE; - } - } - - if( (s->flags & CODEC_FLAG_CLOSED_GOP) - && b_frames - && s->input_picture[b_frames]->pict_type== I_TYPE) - b_frames--; - - s->reordered_input_picture[0]= s->input_picture[b_frames]; - if(s->reordered_input_picture[0]->pict_type != I_TYPE) - s->reordered_input_picture[0]->pict_type= P_TYPE; - s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++; - for(i=0; ireordered_input_picture[i+1]= s->input_picture[i]; - s->reordered_input_picture[i+1]->pict_type= B_TYPE; - s->reordered_input_picture[i+1]->coded_picture_number= s->coded_picture_number++; - } - } - } -no_output_pic: - if(s->reordered_input_picture[0]){ - s->reordered_input_picture[0]->reference= s->reordered_input_picture[0]->pict_type!=B_TYPE ? 3 : 0; - - copy_picture(&s->new_picture, s->reordered_input_picture[0]); - - if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_SHARED || s->avctx->rc_buffer_size){ - // input is a shared pix, so we can't modifiy it -> alloc a new one & ensure that the shared one is reuseable - - int i= ff_find_unused_picture(s, 0); - Picture *pic= &s->picture[i]; - - pic->reference = s->reordered_input_picture[0]->reference; - alloc_picture(s, pic, 0); - - /* mark us unused / free shared pic */ - if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_INTERNAL) - s->avctx->release_buffer(s->avctx, (AVFrame*)s->reordered_input_picture[0]); - for(i=0; i<4; i++) - s->reordered_input_picture[0]->data[i]= NULL; - s->reordered_input_picture[0]->type= 0; - - copy_picture_attributes(s, (AVFrame*)pic, (AVFrame*)s->reordered_input_picture[0]); - - s->current_picture_ptr= pic; - }else{ - // input is not a shared pix -> reuse buffer for current_pix - - assert( s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_USER - || s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL); - - s->current_picture_ptr= s->reordered_input_picture[0]; - for(i=0; i<4; i++){ - s->new_picture.data[i]+= INPLACE_OFFSET; - } - } - copy_picture(&s->current_picture, s->current_picture_ptr); - - s->picture_number= s->new_picture.display_picture_number; -//printf("dpn:%d\n", s->picture_number); - }else{ - memset(&s->new_picture, 0, sizeof(Picture)); - } -} - -int MPV_encode_picture(AVCodecContext *avctx, - unsigned char *buf, int buf_size, void *data) -{ - MpegEncContext *s = avctx->priv_data; - AVFrame *pic_arg = data; - int i, stuffing_count; - - for(i=0; ithread_count; i++){ - int start_y= s->thread_context[i]->start_mb_y; - int end_y= s->thread_context[i]-> end_mb_y; - int h= s->mb_height; - uint8_t *start= buf + (size_t)(((int64_t) buf_size)*start_y/h); - uint8_t *end = buf + (size_t)(((int64_t) buf_size)* end_y/h); - - init_put_bits(&s->thread_context[i]->pb, start, end - start); - } - - s->picture_in_gop_number++; - - if(load_input_picture(s, pic_arg) < 0) - return -1; - - select_input_picture(s); - - /* output? */ - if(s->new_picture.data[0]){ - s->pict_type= s->new_picture.pict_type; -//emms_c(); -//printf("qs:%f %f %d\n", s->new_picture.quality, s->current_picture.quality, s->qscale); - MPV_frame_start(s, avctx); -vbv_retry: - if (encode_picture(s, s->picture_number) < 0) - return -1; - - avctx->real_pict_num = s->picture_number; - avctx->header_bits = s->header_bits; - avctx->mv_bits = s->mv_bits; - avctx->misc_bits = s->misc_bits; - avctx->i_tex_bits = s->i_tex_bits; - avctx->p_tex_bits = s->p_tex_bits; - avctx->i_count = s->i_count; - avctx->p_count = s->mb_num - s->i_count - s->skip_count; //FIXME f/b_count in avctx - avctx->skip_count = s->skip_count; - - MPV_frame_end(s); - - if (s->out_format == FMT_MJPEG) - mjpeg_picture_trailer(s); - - if(avctx->rc_buffer_size){ - RateControlContext *rcc= &s->rc_context; - int max_size= rcc->buffer_index/3; - - if(put_bits_count(&s->pb) > max_size && s->lambda < s->avctx->lmax){ - s->next_lambda= FFMAX(s->lambda+1, s->lambda*(s->qscale+1) / s->qscale); - if(s->adaptive_quant){ - int i; - for(i=0; imb_height*s->mb_stride; i++) - s->lambda_table[i]= FFMAX(s->lambda_table[i]+1, s->lambda_table[i]*(s->qscale+1) / s->qscale); - } - s->mb_skipped = 0; //done in MPV_frame_start() - if(s->pict_type==P_TYPE){ //done in encode_picture() so we must undo it - if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4) - s->no_rounding ^= 1; - } - if(s->pict_type!=B_TYPE){ - s->time_base= s->last_time_base; - s->last_non_b_time= s->time - s->pp_time; - } -// av_log(NULL, AV_LOG_ERROR, "R:%d ", s->next_lambda); - for(i=0; ithread_count; i++){ - PutBitContext *pb= &s->thread_context[i]->pb; - init_put_bits(pb, pb->buf, pb->buf_end - pb->buf); - } - goto vbv_retry; - } - - assert(s->avctx->rc_max_rate); - } - - if(s->flags&CODEC_FLAG_PASS1) - ff_write_pass1_stats(s); - - for(i=0; i<4; i++){ - s->current_picture_ptr->error[i]= s->current_picture.error[i]; - avctx->error[i] += s->current_picture_ptr->error[i]; - } - - if(s->flags&CODEC_FLAG_PASS1) - assert(avctx->header_bits + avctx->mv_bits + avctx->misc_bits + avctx->i_tex_bits + avctx->p_tex_bits == put_bits_count(&s->pb)); - flush_put_bits(&s->pb); - s->frame_bits = put_bits_count(&s->pb); - - stuffing_count= ff_vbv_update(s, s->frame_bits); - if(stuffing_count){ - if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < stuffing_count + 50){ - av_log(s->avctx, AV_LOG_ERROR, "stuffing too large\n"); - return -1; - } - - switch(s->codec_id){ - case CODEC_ID_MPEG1VIDEO: - case CODEC_ID_MPEG2VIDEO: - while(stuffing_count--){ - put_bits(&s->pb, 8, 0); - } - break; - case CODEC_ID_MPEG4: - put_bits(&s->pb, 16, 0); - put_bits(&s->pb, 16, 0x1C3); - stuffing_count -= 4; - while(stuffing_count--){ - put_bits(&s->pb, 8, 0xFF); - } - break; - default: - av_log(s->avctx, AV_LOG_ERROR, "vbv buffer overflow\n"); - } - flush_put_bits(&s->pb); - s->frame_bits = put_bits_count(&s->pb); - } - - /* update mpeg1/2 vbv_delay for CBR */ - if(s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate && s->out_format == FMT_MPEG1 - && 90000LL * (avctx->rc_buffer_size-1) <= s->avctx->rc_max_rate*0xFFFFLL){ - int vbv_delay; - - assert(s->repeat_first_field==0); - - vbv_delay= lrintf(90000 * s->rc_context.buffer_index / s->avctx->rc_max_rate); - assert(vbv_delay < 0xFFFF); - - s->vbv_delay_ptr[0] &= 0xF8; - s->vbv_delay_ptr[0] |= vbv_delay>>13; - s->vbv_delay_ptr[1] = vbv_delay>>5; - s->vbv_delay_ptr[2] &= 0x07; - s->vbv_delay_ptr[2] |= vbv_delay<<3; - } - s->total_bits += s->frame_bits; - avctx->frame_bits = s->frame_bits; - }else{ - assert((pbBufPtr(&s->pb) == s->pb.buf)); - s->frame_bits=0; - } - assert((s->frame_bits&7)==0); - - return s->frame_bits/8; -} - -#endif //CONFIG_ENCODERS - -static inline void gmc1_motion(MpegEncContext *s, - uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, - uint8_t **ref_picture) -{ - uint8_t *ptr; - int offset, src_x, src_y, linesize, uvlinesize; - int motion_x, motion_y; - int emu=0; - - motion_x= s->sprite_offset[0][0]; - motion_y= s->sprite_offset[0][1]; - src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1)); - src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1)); - motion_x<<=(3-s->sprite_warping_accuracy); - motion_y<<=(3-s->sprite_warping_accuracy); - src_x = av_clip(src_x, -16, s->width); - if (src_x == s->width) - motion_x =0; - src_y = av_clip(src_y, -16, s->height); - if (src_y == s->height) - motion_y =0; - - linesize = s->linesize; - uvlinesize = s->uvlinesize; - - ptr = ref_picture[0] + (src_y * linesize) + src_x; - - if(s->flags&CODEC_FLAG_EMU_EDGE){ - if( (unsigned)src_x >= s->h_edge_pos - 17 - || (unsigned)src_y >= s->v_edge_pos - 17){ - ff_emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos); - ptr= s->edge_emu_buffer; - } - } - - if((motion_x|motion_y)&7){ - s->dsp.gmc1(dest_y , ptr , linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding); - s->dsp.gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding); - }else{ - int dxy; - - dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2); - if (s->no_rounding){ - s->dsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16); - }else{ - s->dsp.put_pixels_tab [0][dxy](dest_y, ptr, linesize, 16); - } - } - - if(s->flags&CODEC_FLAG_GRAY) return; - - motion_x= s->sprite_offset[1][0]; - motion_y= s->sprite_offset[1][1]; - src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1)); - src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1)); - motion_x<<=(3-s->sprite_warping_accuracy); - motion_y<<=(3-s->sprite_warping_accuracy); - src_x = av_clip(src_x, -8, s->width>>1); - if (src_x == s->width>>1) - motion_x =0; - src_y = av_clip(src_y, -8, s->height>>1); - if (src_y == s->height>>1) - motion_y =0; - - offset = (src_y * uvlinesize) + src_x; - ptr = ref_picture[1] + offset; - if(s->flags&CODEC_FLAG_EMU_EDGE){ - if( (unsigned)src_x >= (s->h_edge_pos>>1) - 9 - || (unsigned)src_y >= (s->v_edge_pos>>1) - 9){ - ff_emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); - ptr= s->edge_emu_buffer; - emu=1; - } - } - s->dsp.gmc1(dest_cb, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); - - ptr = ref_picture[2] + offset; - if(emu){ - ff_emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); - ptr= s->edge_emu_buffer; - } - s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); - - return; -} - -static inline void gmc_motion(MpegEncContext *s, - uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, - uint8_t **ref_picture) -{ - uint8_t *ptr; - int linesize, uvlinesize; - const int a= s->sprite_warping_accuracy; - int ox, oy; - - linesize = s->linesize; - uvlinesize = s->uvlinesize; - - ptr = ref_picture[0]; - - ox= s->sprite_offset[0][0] + s->sprite_delta[0][0]*s->mb_x*16 + s->sprite_delta[0][1]*s->mb_y*16; - oy= s->sprite_offset[0][1] + s->sprite_delta[1][0]*s->mb_x*16 + s->sprite_delta[1][1]*s->mb_y*16; - - s->dsp.gmc(dest_y, ptr, linesize, 16, - ox, - oy, - s->sprite_delta[0][0], s->sprite_delta[0][1], - s->sprite_delta[1][0], s->sprite_delta[1][1], - a+1, (1<<(2*a+1)) - s->no_rounding, - s->h_edge_pos, s->v_edge_pos); - s->dsp.gmc(dest_y+8, ptr, linesize, 16, - ox + s->sprite_delta[0][0]*8, - oy + s->sprite_delta[1][0]*8, - s->sprite_delta[0][0], s->sprite_delta[0][1], - s->sprite_delta[1][0], s->sprite_delta[1][1], - a+1, (1<<(2*a+1)) - s->no_rounding, - s->h_edge_pos, s->v_edge_pos); - - if(s->flags&CODEC_FLAG_GRAY) return; - - ox= s->sprite_offset[1][0] + s->sprite_delta[0][0]*s->mb_x*8 + s->sprite_delta[0][1]*s->mb_y*8; - oy= s->sprite_offset[1][1] + s->sprite_delta[1][0]*s->mb_x*8 + s->sprite_delta[1][1]*s->mb_y*8; - - ptr = ref_picture[1]; - s->dsp.gmc(dest_cb, ptr, uvlinesize, 8, - ox, - oy, - s->sprite_delta[0][0], s->sprite_delta[0][1], - s->sprite_delta[1][0], s->sprite_delta[1][1], - a+1, (1<<(2*a+1)) - s->no_rounding, - s->h_edge_pos>>1, s->v_edge_pos>>1); - - ptr = ref_picture[2]; - s->dsp.gmc(dest_cr, ptr, uvlinesize, 8, - ox, - oy, - s->sprite_delta[0][0], s->sprite_delta[0][1], - s->sprite_delta[1][0], s->sprite_delta[1][1], - a+1, (1<<(2*a+1)) - s->no_rounding, - s->h_edge_pos>>1, s->v_edge_pos>>1); -} - /** * Copies a rectangular area of samples to a temporary buffer and replicates the boarder samples. * @param buf destination buffer @@ -2865,59 +1468,19 @@ void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize, int block_w, } } -static inline int hpel_motion(MpegEncContext *s, +static inline int hpel_motion_lowres(MpegEncContext *s, uint8_t *dest, uint8_t *src, int field_based, int field_select, int src_x, int src_y, int width, int height, int stride, int h_edge_pos, int v_edge_pos, - int w, int h, op_pixels_func *pix_op, + int w, int h, h264_chroma_mc_func *pix_op, int motion_x, int motion_y) { - int dxy; + const int lowres= s->avctx->lowres; + const int s_mask= (2<> 1; - src_y += motion_y >> 1; - - /* WARNING: do no forget half pels */ - src_x = av_clip(src_x, -16, width); //FIXME unneeded for emu? - if (src_x == width) - dxy &= ~1; - src_y = av_clip(src_y, -16, height); - if (src_y == height) - dxy &= ~2; - src += src_y * stride + src_x; - - if(s->unrestricted_mv && (s->flags&CODEC_FLAG_EMU_EDGE)){ - if( (unsigned)src_x > h_edge_pos - (motion_x&1) - w - || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){ - ff_emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<v_edge_pos); - src= s->edge_emu_buffer; - emu=1; - } - } - if(field_select) - src += s->linesize; - pix_op[dxy](dest, src, stride, h); - return emu; -} - -static inline int hpel_motion_lowres(MpegEncContext *s, - uint8_t *dest, uint8_t *src, - int field_based, int field_select, - int src_x, int src_y, - int width, int height, int stride, - int h_edge_pos, int v_edge_pos, - int w, int h, h264_chroma_mc_func *pix_op, - int motion_x, int motion_y) -{ - const int lowres= s->avctx->lowres; - const int s_mask= (2<quarter_sample){ motion_x/=2; @@ -2947,123 +1510,6 @@ static inline int hpel_motion_lowres(MpegEncContext *s, return emu; } -/* apply one mpeg motion vector to the three components */ -static av_always_inline void mpeg_motion(MpegEncContext *s, - uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, - int field_based, int bottom_field, int field_select, - uint8_t **ref_picture, op_pixels_func (*pix_op)[4], - int motion_x, int motion_y, int h) -{ - uint8_t *ptr_y, *ptr_cb, *ptr_cr; - int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize; - -#if 0 -if(s->quarter_sample) -{ - motion_x>>=1; - motion_y>>=1; -} -#endif - - v_edge_pos = s->v_edge_pos >> field_based; - linesize = s->current_picture.linesize[0] << field_based; - uvlinesize = s->current_picture.linesize[1] << field_based; - - dxy = ((motion_y & 1) << 1) | (motion_x & 1); - src_x = s->mb_x* 16 + (motion_x >> 1); - src_y =(s->mb_y<<(4-field_based)) + (motion_y >> 1); - - if (s->out_format == FMT_H263) { - if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){ - mx = (motion_x>>1)|(motion_x&1); - my = motion_y >>1; - uvdxy = ((my & 1) << 1) | (mx & 1); - uvsrc_x = s->mb_x* 8 + (mx >> 1); - uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1); - }else{ - uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1); - uvsrc_x = src_x>>1; - uvsrc_y = src_y>>1; - } - }else if(s->out_format == FMT_H261){//even chroma mv's are full pel in H261 - mx = motion_x / 4; - my = motion_y / 4; - uvdxy = 0; - uvsrc_x = s->mb_x*8 + mx; - uvsrc_y = s->mb_y*8 + my; - } else { - if(s->chroma_y_shift){ - mx = motion_x / 2; - my = motion_y / 2; - uvdxy = ((my & 1) << 1) | (mx & 1); - uvsrc_x = s->mb_x* 8 + (mx >> 1); - uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1); - } else { - if(s->chroma_x_shift){ - //Chroma422 - mx = motion_x / 2; - uvdxy = ((motion_y & 1) << 1) | (mx & 1); - uvsrc_x = s->mb_x* 8 + (mx >> 1); - uvsrc_y = src_y; - } else { - //Chroma444 - uvdxy = dxy; - uvsrc_x = src_x; - uvsrc_y = src_y; - } - } - } - - ptr_y = ref_picture[0] + src_y * linesize + src_x; - ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; - ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; - - if( (unsigned)src_x > s->h_edge_pos - (motion_x&1) - 16 - || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){ - if(s->codec_id == CODEC_ID_MPEG2VIDEO || - s->codec_id == CODEC_ID_MPEG1VIDEO){ - av_log(s->avctx,AV_LOG_DEBUG,"MPEG motion vector out of boundary\n"); - return ; - } - ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based, - src_x, src_y<h_edge_pos, s->v_edge_pos); - ptr_y = s->edge_emu_buffer; - if(!(s->flags&CODEC_FLAG_GRAY)){ - uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize; - ff_emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based, - uvsrc_x, uvsrc_y<h_edge_pos>>1, s->v_edge_pos>>1); - ff_emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based, - uvsrc_x, uvsrc_y<h_edge_pos>>1, s->v_edge_pos>>1); - ptr_cb= uvbuf; - ptr_cr= uvbuf+16; - } - } - - if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data - dest_y += s->linesize; - dest_cb+= s->uvlinesize; - dest_cr+= s->uvlinesize; - } - - if(field_select){ - ptr_y += s->linesize; - ptr_cb+= s->uvlinesize; - ptr_cr+= s->uvlinesize; - } - - pix_op[0][dxy](dest_y, ptr_y, linesize, h); - - if(!(s->flags&CODEC_FLAG_GRAY)){ - pix_op[s->chroma_x_shift][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift); - pix_op[s->chroma_x_shift][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift); - } -#if defined(CONFIG_H261_ENCODER) || defined(CONFIG_H261_DECODER) - if(s->out_format == FMT_H261){ - ff_h261_loop_filter(s); - } -#endif -} - /* apply one mpeg motion vector to the three components */ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, @@ -3125,7 +1571,7 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based, src_x, src_y<edge_emu_buffer; - if(!(s->flags&CODEC_FLAG_GRAY)){ + if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize; ff_emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based, uvsrc_x, uvsrc_y<>1, v_edge_pos>>1); @@ -3152,7 +1598,7 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, sy <<= 2 - lowres; pix_op[lowres-1](dest_y, ptr_y, linesize, h, sx, sy); - if(!(s->flags&CODEC_FLAG_GRAY)){ + if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ uvsx <<= 2 - lowres; uvsy <<= 2 - lowres; pix_op[lowres](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy); @@ -3161,233 +1607,6 @@ static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, //FIXME h261 lowres loop filter } -//FIXME move to dsputil, avg variant, 16x16 version -static inline void put_obmc(uint8_t *dst, uint8_t *src[5], int stride){ - int x; - uint8_t * const top = src[1]; - uint8_t * const left = src[2]; - uint8_t * const mid = src[0]; - uint8_t * const right = src[3]; - uint8_t * const bottom= src[4]; -#define OBMC_FILTER(x, t, l, m, r, b)\ - dst[x]= (t*top[x] + l*left[x] + m*mid[x] + r*right[x] + b*bottom[x] + 4)>>3 -#define OBMC_FILTER4(x, t, l, m, r, b)\ - OBMC_FILTER(x , t, l, m, r, b);\ - OBMC_FILTER(x+1 , t, l, m, r, b);\ - OBMC_FILTER(x +stride, t, l, m, r, b);\ - OBMC_FILTER(x+1+stride, t, l, m, r, b); - - x=0; - OBMC_FILTER (x , 2, 2, 4, 0, 0); - OBMC_FILTER (x+1, 2, 1, 5, 0, 0); - OBMC_FILTER4(x+2, 2, 1, 5, 0, 0); - OBMC_FILTER4(x+4, 2, 0, 5, 1, 0); - OBMC_FILTER (x+6, 2, 0, 5, 1, 0); - OBMC_FILTER (x+7, 2, 0, 4, 2, 0); - x+= stride; - OBMC_FILTER (x , 1, 2, 5, 0, 0); - OBMC_FILTER (x+1, 1, 2, 5, 0, 0); - OBMC_FILTER (x+6, 1, 0, 5, 2, 0); - OBMC_FILTER (x+7, 1, 0, 5, 2, 0); - x+= stride; - OBMC_FILTER4(x , 1, 2, 5, 0, 0); - OBMC_FILTER4(x+2, 1, 1, 6, 0, 0); - OBMC_FILTER4(x+4, 1, 0, 6, 1, 0); - OBMC_FILTER4(x+6, 1, 0, 5, 2, 0); - x+= 2*stride; - OBMC_FILTER4(x , 0, 2, 5, 0, 1); - OBMC_FILTER4(x+2, 0, 1, 6, 0, 1); - OBMC_FILTER4(x+4, 0, 0, 6, 1, 1); - OBMC_FILTER4(x+6, 0, 0, 5, 2, 1); - x+= 2*stride; - OBMC_FILTER (x , 0, 2, 5, 0, 1); - OBMC_FILTER (x+1, 0, 2, 5, 0, 1); - OBMC_FILTER4(x+2, 0, 1, 5, 0, 2); - OBMC_FILTER4(x+4, 0, 0, 5, 1, 2); - OBMC_FILTER (x+6, 0, 0, 5, 2, 1); - OBMC_FILTER (x+7, 0, 0, 5, 2, 1); - x+= stride; - OBMC_FILTER (x , 0, 2, 4, 0, 2); - OBMC_FILTER (x+1, 0, 1, 5, 0, 2); - OBMC_FILTER (x+6, 0, 0, 5, 1, 2); - OBMC_FILTER (x+7, 0, 0, 4, 2, 2); -} - -/* obmc for 1 8x8 luma block */ -static inline void obmc_motion(MpegEncContext *s, - uint8_t *dest, uint8_t *src, - int src_x, int src_y, - op_pixels_func *pix_op, - int16_t mv[5][2]/* mid top left right bottom*/) -#define MID 0 -{ - int i; - uint8_t *ptr[5]; - - assert(s->quarter_sample==0); - - for(i=0; i<5; i++){ - if(i && mv[i][0]==mv[MID][0] && mv[i][1]==mv[MID][1]){ - ptr[i]= ptr[MID]; - }else{ - ptr[i]= s->obmc_scratchpad + 8*(i&1) + s->linesize*8*(i>>1); - hpel_motion(s, ptr[i], src, 0, 0, - src_x, src_y, - s->width, s->height, s->linesize, - s->h_edge_pos, s->v_edge_pos, - 8, 8, pix_op, - mv[i][0], mv[i][1]); - } - } - - put_obmc(dest, ptr, s->linesize); -} - -static inline void qpel_motion(MpegEncContext *s, - uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, - int field_based, int bottom_field, int field_select, - uint8_t **ref_picture, op_pixels_func (*pix_op)[4], - qpel_mc_func (*qpix_op)[16], - int motion_x, int motion_y, int h) -{ - uint8_t *ptr_y, *ptr_cb, *ptr_cr; - int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, linesize, uvlinesize; - - dxy = ((motion_y & 3) << 2) | (motion_x & 3); - src_x = s->mb_x * 16 + (motion_x >> 2); - src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2); - - v_edge_pos = s->v_edge_pos >> field_based; - linesize = s->linesize << field_based; - uvlinesize = s->uvlinesize << field_based; - - if(field_based){ - mx= motion_x/2; - my= motion_y>>1; - }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA2){ - static const int rtab[8]= {0,0,1,1,0,0,0,1}; - mx= (motion_x>>1) + rtab[motion_x&7]; - my= (motion_y>>1) + rtab[motion_y&7]; - }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA){ - mx= (motion_x>>1)|(motion_x&1); - my= (motion_y>>1)|(motion_y&1); - }else{ - mx= motion_x/2; - my= motion_y/2; - } - mx= (mx>>1)|(mx&1); - my= (my>>1)|(my&1); - - uvdxy= (mx&1) | ((my&1)<<1); - mx>>=1; - my>>=1; - - uvsrc_x = s->mb_x * 8 + mx; - uvsrc_y = s->mb_y * (8 >> field_based) + my; - - ptr_y = ref_picture[0] + src_y * linesize + src_x; - ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; - ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; - - if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 16 - || (unsigned)src_y > v_edge_pos - (motion_y&3) - h ){ - ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based, - src_x, src_y<h_edge_pos, s->v_edge_pos); - ptr_y= s->edge_emu_buffer; - if(!(s->flags&CODEC_FLAG_GRAY)){ - uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize; - ff_emulated_edge_mc(uvbuf, ptr_cb, s->uvlinesize, 9, 9 + field_based, - uvsrc_x, uvsrc_y<h_edge_pos>>1, s->v_edge_pos>>1); - ff_emulated_edge_mc(uvbuf + 16, ptr_cr, s->uvlinesize, 9, 9 + field_based, - uvsrc_x, uvsrc_y<h_edge_pos>>1, s->v_edge_pos>>1); - ptr_cb= uvbuf; - ptr_cr= uvbuf + 16; - } - } - - if(!field_based) - qpix_op[0][dxy](dest_y, ptr_y, linesize); - else{ - if(bottom_field){ - dest_y += s->linesize; - dest_cb+= s->uvlinesize; - dest_cr+= s->uvlinesize; - } - - if(field_select){ - ptr_y += s->linesize; - ptr_cb += s->uvlinesize; - ptr_cr += s->uvlinesize; - } - //damn interlaced mode - //FIXME boundary mirroring is not exactly correct here - qpix_op[1][dxy](dest_y , ptr_y , linesize); - qpix_op[1][dxy](dest_y+8, ptr_y+8, linesize); - } - if(!(s->flags&CODEC_FLAG_GRAY)){ - pix_op[1][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> 1); - pix_op[1][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> 1); - } -} - -inline int ff_h263_round_chroma(int x){ - if (x >= 0) - return (h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1)); - else { - x = -x; - return -(h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1)); - } -} - -/** - * h263 chorma 4mv motion compensation. - */ -static inline void chroma_4mv_motion(MpegEncContext *s, - uint8_t *dest_cb, uint8_t *dest_cr, - uint8_t **ref_picture, - op_pixels_func *pix_op, - int mx, int my){ - int dxy, emu=0, src_x, src_y, offset; - uint8_t *ptr; - - /* In case of 8X8, we construct a single chroma motion vector - with a special rounding */ - mx= ff_h263_round_chroma(mx); - my= ff_h263_round_chroma(my); - - dxy = ((my & 1) << 1) | (mx & 1); - mx >>= 1; - my >>= 1; - - src_x = s->mb_x * 8 + mx; - src_y = s->mb_y * 8 + my; - src_x = av_clip(src_x, -8, s->width/2); - if (src_x == s->width/2) - dxy &= ~1; - src_y = av_clip(src_y, -8, s->height/2); - if (src_y == s->height/2) - dxy &= ~2; - - offset = (src_y * (s->uvlinesize)) + src_x; - ptr = ref_picture[1] + offset; - if(s->flags&CODEC_FLAG_EMU_EDGE){ - if( (unsigned)src_x > (s->h_edge_pos>>1) - (dxy &1) - 8 - || (unsigned)src_y > (s->v_edge_pos>>1) - (dxy>>1) - 8){ - ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); - ptr= s->edge_emu_buffer; - emu=1; - } - } - pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8); - - ptr = ref_picture[2] + offset; - if(emu){ - ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); - ptr= s->edge_emu_buffer; - } - pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8); -} - static inline void chroma_4mv_motion_lowres(MpegEncContext *s, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t **ref_picture, @@ -3438,18 +1657,6 @@ static inline void chroma_4mv_motion_lowres(MpegEncContext *s, pix_op[lowres](dest_cr, ptr, s->uvlinesize, block_s, sx, sy); } -static inline void prefetch_motion(MpegEncContext *s, uint8_t **pix, int dir){ - /* fetch pixels for estimated mv 4 macroblocks ahead - * optimized for 64byte cache lines */ - const int shift = s->quarter_sample ? 2 : 1; - const int mx= (s->mv[dir][0][0]>>shift) + 16*s->mb_x + 8; - const int my= (s->mv[dir][0][1]>>shift) + 16*s->mb_y; - int off= mx + (my + (s->mb_x&3)*4)*s->linesize + 64; - s->dsp.prefetch(pix[0]+off, s->linesize, 4); - off= (mx>>1) + ((my>>1) + (s->mb_x&7))*s->uvlinesize + 64; - s->dsp.prefetch(pix[1]+off, pix[2]-pix[1], 2); -} - /** * motion compensation of a single macroblock * @param s context @@ -3459,193 +1666,68 @@ static inline void prefetch_motion(MpegEncContext *s, uint8_t **pix, int dir){ * @param dir direction (0->forward, 1->backward) * @param ref_picture array[3] of pointers to the 3 planes of the reference picture * @param pic_op halfpel motion compensation function (average or put normally) - * @param pic_op qpel motion compensation function (average or put normally) * the motion vectors are taken from s->mv and the MV type from s->mv_type */ -static inline void MPV_motion(MpegEncContext *s, +static inline void MPV_motion_lowres(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int dir, uint8_t **ref_picture, - op_pixels_func (*pix_op)[4], qpel_mc_func (*qpix_op)[16]) + h264_chroma_mc_func *pix_op) { - int dxy, mx, my, src_x, src_y, motion_x, motion_y; + int mx, my; int mb_x, mb_y, i; - uint8_t *ptr, *dest; + const int lowres= s->avctx->lowres; + const int block_s= 8>>lowres; mb_x = s->mb_x; mb_y = s->mb_y; - prefetch_motion(s, ref_picture, dir); - - if(s->obmc && s->pict_type != B_TYPE){ - int16_t mv_cache[4][4][2]; - const int xy= s->mb_x + s->mb_y*s->mb_stride; - const int mot_stride= s->b8_stride; - const int mot_xy= mb_x*2 + mb_y*2*mot_stride; - - assert(!s->mb_skipped); - - memcpy(mv_cache[1][1], s->current_picture.motion_val[0][mot_xy ], sizeof(int16_t)*4); - memcpy(mv_cache[2][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4); - memcpy(mv_cache[3][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4); - - if(mb_y==0 || IS_INTRA(s->current_picture.mb_type[xy-s->mb_stride])){ - memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4); - }else{ - memcpy(mv_cache[0][1], s->current_picture.motion_val[0][mot_xy-mot_stride], sizeof(int16_t)*4); - } - - if(mb_x==0 || IS_INTRA(s->current_picture.mb_type[xy-1])){ - *(int32_t*)mv_cache[1][0]= *(int32_t*)mv_cache[1][1]; - *(int32_t*)mv_cache[2][0]= *(int32_t*)mv_cache[2][1]; - }else{ - *(int32_t*)mv_cache[1][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1]; - *(int32_t*)mv_cache[2][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1+mot_stride]; - } - - if(mb_x+1>=s->mb_width || IS_INTRA(s->current_picture.mb_type[xy+1])){ - *(int32_t*)mv_cache[1][3]= *(int32_t*)mv_cache[1][2]; - *(int32_t*)mv_cache[2][3]= *(int32_t*)mv_cache[2][2]; - }else{ - *(int32_t*)mv_cache[1][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2]; - *(int32_t*)mv_cache[2][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2+mot_stride]; - } - - mx = 0; - my = 0; - for(i=0;i<4;i++) { - const int x= (i&1)+1; - const int y= (i>>1)+1; - int16_t mv[5][2]= { - {mv_cache[y][x ][0], mv_cache[y][x ][1]}, - {mv_cache[y-1][x][0], mv_cache[y-1][x][1]}, - {mv_cache[y][x-1][0], mv_cache[y][x-1][1]}, - {mv_cache[y][x+1][0], mv_cache[y][x+1][1]}, - {mv_cache[y+1][x][0], mv_cache[y+1][x][1]}}; - //FIXME cleanup - obmc_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize, - ref_picture[0], - mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8, - pix_op[1], - mv); - - mx += mv[0][0]; - my += mv[0][1]; - } - if(!(s->flags&CODEC_FLAG_GRAY)) - chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my); - - return; - } - switch(s->mv_type) { case MV_TYPE_16X16: - if(s->mcsel){ - if(s->real_sprite_warping_points==1){ - gmc1_motion(s, dest_y, dest_cb, dest_cr, - ref_picture); - }else{ - gmc_motion(s, dest_y, dest_cb, dest_cr, - ref_picture); - } - }else if(s->quarter_sample){ - qpel_motion(s, dest_y, dest_cb, dest_cr, - 0, 0, 0, - ref_picture, pix_op, qpix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 16); - }else if(s->mspel){ - ff_mspel_motion(s, dest_y, dest_cb, dest_cr, - ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 16); - }else - { - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 0, 0, 0, - ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 16); - } + mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, + 0, 0, 0, + ref_picture, pix_op, + s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s); break; case MV_TYPE_8X8: mx = 0; my = 0; - if(s->quarter_sample){ - for(i=0;i<4;i++) { - motion_x = s->mv[dir][i][0]; - motion_y = s->mv[dir][i][1]; - - dxy = ((motion_y & 3) << 2) | (motion_x & 3); - src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8; - src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8; - - /* WARNING: do no forget half pels */ - src_x = av_clip(src_x, -16, s->width); - if (src_x == s->width) - dxy &= ~3; - src_y = av_clip(src_y, -16, s->height); - if (src_y == s->height) - dxy &= ~12; - - ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); - if(s->flags&CODEC_FLAG_EMU_EDGE){ - if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 8 - || (unsigned)src_y > s->v_edge_pos - (motion_y&3) - 8 ){ - ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos); - ptr= s->edge_emu_buffer; - } - } - dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; - qpix_op[1][dxy](dest, ptr, s->linesize); - - mx += s->mv[dir][i][0]/2; - my += s->mv[dir][i][1]/2; - } - }else{ for(i=0;i<4;i++) { - hpel_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize, + hpel_motion_lowres(s, dest_y + ((i & 1) + (i >> 1) * s->linesize)*block_s, ref_picture[0], 0, 0, - mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8, + (2*mb_x + (i & 1))*block_s, (2*mb_y + (i >>1))*block_s, s->width, s->height, s->linesize, - s->h_edge_pos, s->v_edge_pos, - 8, 8, pix_op[1], + s->h_edge_pos >> lowres, s->v_edge_pos >> lowres, + block_s, block_s, pix_op, s->mv[dir][i][0], s->mv[dir][i][1]); mx += s->mv[dir][i][0]; my += s->mv[dir][i][1]; } - } - if(!(s->flags&CODEC_FLAG_GRAY)) - chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my); + if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)) + chroma_4mv_motion_lowres(s, dest_cb, dest_cr, ref_picture, pix_op, mx, my); break; case MV_TYPE_FIELD: if (s->picture_structure == PICT_FRAME) { - if(s->quarter_sample){ - for(i=0; i<2; i++){ - qpel_motion(s, dest_y, dest_cb, dest_cr, - 1, i, s->field_select[dir][i], - ref_picture, pix_op, qpix_op, - s->mv[dir][i][0], s->mv[dir][i][1], 8); - } - }else{ - /* top field */ - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 1, 0, s->field_select[dir][0], - ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 8); - /* bottom field */ - mpeg_motion(s, dest_y, dest_cb, dest_cr, - 1, 1, s->field_select[dir][1], - ref_picture, pix_op, - s->mv[dir][1][0], s->mv[dir][1][1], 8); - } + /* top field */ + mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, + 1, 0, s->field_select[dir][0], + ref_picture, pix_op, + s->mv[dir][0][0], s->mv[dir][0][1], block_s); + /* bottom field */ + mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, + 1, 1, s->field_select[dir][1], + ref_picture, pix_op, + s->mv[dir][1][0], s->mv[dir][1][1], block_s); } else { if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != B_TYPE && !s->first_field){ ref_picture= s->current_picture_ptr->data; } - mpeg_motion(s, dest_y, dest_cb, dest_cr, + mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, 0, s->field_select[dir][0], ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 16); + s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s); } break; case MV_TYPE_16X8: @@ -3658,14 +1740,14 @@ static inline void MPV_motion(MpegEncContext *s, ref2picture= s->current_picture_ptr->data; } - mpeg_motion(s, dest_y, dest_cb, dest_cr, + mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, 0, s->field_select[dir][i], ref2picture, pix_op, - s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8); + s->mv[dir][i][0], s->mv[dir][i][1] + 2*block_s*i, block_s); - dest_y += 16*s->linesize; - dest_cb+= (16>>s->chroma_y_shift)*s->uvlinesize; - dest_cr+= (16>>s->chroma_y_shift)*s->uvlinesize; + dest_y += 2*block_s*s->linesize; + dest_cb+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize; + dest_cr+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize; } break; case MV_TYPE_DMV: @@ -3673,22 +1755,22 @@ static inline void MPV_motion(MpegEncContext *s, for(i=0; i<2; i++){ int j; for(j=0; j<2; j++){ - mpeg_motion(s, dest_y, dest_cb, dest_cr, + mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, j, j^i, ref_picture, pix_op, - s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], 8); + s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], block_s); } - pix_op = s->dsp.avg_pixels_tab; + pix_op = s->dsp.avg_h264_chroma_pixels_tab; } }else{ for(i=0; i<2; i++){ - mpeg_motion(s, dest_y, dest_cb, dest_cr, + mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, 0, s->picture_structure != i+1, ref_picture, pix_op, - s->mv[dir][2*i][0],s->mv[dir][2*i][1],16); + s->mv[dir][2*i][0],s->mv[dir][2*i][1],2*block_s); // after put we make avg of the same block - pix_op=s->dsp.avg_pixels_tab; + pix_op = s->dsp.avg_h264_chroma_pixels_tab; //opposite parity is always in the same frame if this is second field if(!s->first_field){ @@ -3701,139 +1783,13 @@ static inline void MPV_motion(MpegEncContext *s, } } -/** - * motion compensation of a single macroblock - * @param s context - * @param dest_y luma destination pointer - * @param dest_cb chroma cb/u destination pointer - * @param dest_cr chroma cr/v destination pointer - * @param dir direction (0->forward, 1->backward) - * @param ref_picture array[3] of pointers to the 3 planes of the reference picture - * @param pic_op halfpel motion compensation function (average or put normally) - * the motion vectors are taken from s->mv and the MV type from s->mv_type - */ -static inline void MPV_motion_lowres(MpegEncContext *s, - uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, - int dir, uint8_t **ref_picture, - h264_chroma_mc_func *pix_op) +/* put block[] to dest[] */ +static inline void put_dct(MpegEncContext *s, + DCTELEM *block, int i, uint8_t *dest, int line_size, int qscale) { - int mx, my; - int mb_x, mb_y, i; - const int lowres= s->avctx->lowres; - const int block_s= 8>>lowres; - - mb_x = s->mb_x; - mb_y = s->mb_y; - - switch(s->mv_type) { - case MV_TYPE_16X16: - mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, - 0, 0, 0, - ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s); - break; - case MV_TYPE_8X8: - mx = 0; - my = 0; - for(i=0;i<4;i++) { - hpel_motion_lowres(s, dest_y + ((i & 1) + (i >> 1) * s->linesize)*block_s, - ref_picture[0], 0, 0, - (2*mb_x + (i & 1))*block_s, (2*mb_y + (i >>1))*block_s, - s->width, s->height, s->linesize, - s->h_edge_pos >> lowres, s->v_edge_pos >> lowres, - block_s, block_s, pix_op, - s->mv[dir][i][0], s->mv[dir][i][1]); - - mx += s->mv[dir][i][0]; - my += s->mv[dir][i][1]; - } - - if(!(s->flags&CODEC_FLAG_GRAY)) - chroma_4mv_motion_lowres(s, dest_cb, dest_cr, ref_picture, pix_op, mx, my); - break; - case MV_TYPE_FIELD: - if (s->picture_structure == PICT_FRAME) { - /* top field */ - mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, - 1, 0, s->field_select[dir][0], - ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], block_s); - /* bottom field */ - mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, - 1, 1, s->field_select[dir][1], - ref_picture, pix_op, - s->mv[dir][1][0], s->mv[dir][1][1], block_s); - } else { - if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != B_TYPE && !s->first_field){ - ref_picture= s->current_picture_ptr->data; - } - - mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, - 0, 0, s->field_select[dir][0], - ref_picture, pix_op, - s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s); - } - break; - case MV_TYPE_16X8: - for(i=0; i<2; i++){ - uint8_t ** ref2picture; - - if(s->picture_structure == s->field_select[dir][i] + 1 || s->pict_type == B_TYPE || s->first_field){ - ref2picture= ref_picture; - }else{ - ref2picture= s->current_picture_ptr->data; - } - - mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, - 0, 0, s->field_select[dir][i], - ref2picture, pix_op, - s->mv[dir][i][0], s->mv[dir][i][1] + 2*block_s*i, block_s); - - dest_y += 2*block_s*s->linesize; - dest_cb+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize; - dest_cr+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize; - } - break; - case MV_TYPE_DMV: - if(s->picture_structure == PICT_FRAME){ - for(i=0; i<2; i++){ - int j; - for(j=0; j<2; j++){ - mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, - 1, j, j^i, - ref_picture, pix_op, - s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], block_s); - } - pix_op = s->dsp.avg_h264_chroma_pixels_tab; - } - }else{ - for(i=0; i<2; i++){ - mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, - 0, 0, s->picture_structure != i+1, - ref_picture, pix_op, - s->mv[dir][2*i][0],s->mv[dir][2*i][1],2*block_s); - - // after put we make avg of the same block - pix_op = s->dsp.avg_h264_chroma_pixels_tab; - - //opposite parity is always in the same frame if this is second field - if(!s->first_field){ - ref_picture = s->current_picture_ptr->data; - } - } - } - break; - default: assert(0); - } -} - -/* put block[] to dest[] */ -static inline void put_dct(MpegEncContext *s, - DCTELEM *block, int i, uint8_t *dest, int line_size, int qscale) -{ - s->dct_unquantize_intra(s, block, i, qscale); - s->dsp.idct_put (dest, line_size, block); -} + s->dct_unquantize_intra(s, block, i, qscale); + s->dsp.idct_put (dest, line_size, block); +} /* add block[] to dest[] */ static inline void add_dct(MpegEncContext *s, @@ -4035,7 +1991,7 @@ static av_always_inline void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM b add_dequant_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale); add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale); - if(!(s->flags&CODEC_FLAG_GRAY)){ + if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ if (s->chroma_y_shift){ add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale); add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale); @@ -4054,7 +2010,7 @@ static av_always_inline void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM b add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize); add_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize); - if(!(s->flags&CODEC_FLAG_GRAY)){ + if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ if(s->chroma_y_shift){//Chroma420 add_dct(s, block[4], 4, dest_cb, uvlinesize); add_dct(s, block[5], 5, dest_cr, uvlinesize); @@ -4076,7 +2032,7 @@ static av_always_inline void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM b } }//fi gray } - else{ + else if (ENABLE_WMV2) { ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr); } } else { @@ -4087,7 +2043,7 @@ static av_always_inline void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM b put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale); put_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale); - if(!(s->flags&CODEC_FLAG_GRAY)){ + if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ if(s->chroma_y_shift){ put_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale); put_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale); @@ -4106,7 +2062,7 @@ static av_always_inline void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM b s->dsp.idct_put(dest_y + dct_offset , dct_linesize, block[2]); s->dsp.idct_put(dest_y + dct_offset + block_size, dct_linesize, block[3]); - if(!(s->flags&CODEC_FLAG_GRAY)){ + if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ if(s->chroma_y_shift){ s->dsp.idct_put(dest_cb, uvlinesize, block[4]); s->dsp.idct_put(dest_cr, uvlinesize, block[5]); @@ -4143,90 +2099,6 @@ void MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64]){ else MPV_decode_mb_internal(s, block, 0); } -#ifdef CONFIG_ENCODERS - -static inline void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold) -{ - static const char tab[64]= - {3,2,2,1,1,1,1,1, - 1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1, - 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0}; - int score=0; - int run=0; - int i; - DCTELEM *block= s->block[n]; - const int last_index= s->block_last_index[n]; - int skip_dc; - - if(threshold<0){ - skip_dc=0; - threshold= -threshold; - }else - skip_dc=1; - - /* are all which we could set to zero are allready zero? */ - if(last_index<=skip_dc - 1) return; - - for(i=0; i<=last_index; i++){ - const int j = s->intra_scantable.permutated[i]; - const int level = FFABS(block[j]); - if(level==1){ - if(skip_dc && i==0) continue; - score+= tab[run]; - run=0; - }else if(level>1){ - return; - }else{ - run++; - } - } - if(score >= threshold) return; - for(i=skip_dc; i<=last_index; i++){ - const int j = s->intra_scantable.permutated[i]; - block[j]=0; - } - if(block[0]) s->block_last_index[n]= 0; - else s->block_last_index[n]= -1; -} - -static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index) -{ - int i; - const int maxlevel= s->max_qcoeff; - const int minlevel= s->min_qcoeff; - int overflow=0; - - if(s->mb_intra){ - i=1; //skip clipping of intra dc - }else - i=0; - - for(;i<=last_index; i++){ - const int j= s->intra_scantable.permutated[i]; - int level = block[j]; - - if (level>maxlevel){ - level=maxlevel; - overflow++; - }else if(levelavctx->mb_decision == FF_MB_DECISION_SIMPLE) - av_log(s->avctx, AV_LOG_INFO, "warning, clipping %d dct coefficients to %d..%d\n", overflow, minlevel, maxlevel); -} - -#endif //CONFIG_ENCODERS - /** * * @param h is the normal height, this will be reduced automatically if needed for the last row @@ -4257,7 +2129,7 @@ void ff_draw_horiz_band(MpegEncContext *s, int y, int h){ offset[2]= offset[3]= 0; }else{ - offset[0]= y * s->linesize;; + offset[0]= y * s->linesize; offset[1]= offset[2]= (y >> s->chroma_y_shift) * s->uvlinesize; offset[3]= 0; @@ -4295,320 +2167,6 @@ void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename } } -#ifdef CONFIG_ENCODERS - -static void get_vissual_weight(int16_t *weight, uint8_t *ptr, int stride){ - int x, y; -//FIXME optimize - for(y=0; y<8; y++){ - for(x=0; x<8; x++){ - int x2, y2; - int sum=0; - int sqr=0; - int count=0; - - for(y2= FFMAX(y-1, 0); y2 < FFMIN(8, y+2); y2++){ - for(x2= FFMAX(x-1, 0); x2 < FFMIN(8, x+2); x2++){ - int v= ptr[x2 + y2*stride]; - sum += v; - sqr += v*v; - count++; - } - } - weight[x + 8*y]= (36*ff_sqrt(count*sqr - sum*sum)) / count; - } - } -} - -static av_always_inline void encode_mb_internal(MpegEncContext *s, int motion_x, int motion_y, int mb_block_height, int mb_block_count) -{ - int16_t weight[8][64]; - DCTELEM orig[8][64]; - const int mb_x= s->mb_x; - const int mb_y= s->mb_y; - int i; - int skip_dct[8]; - int dct_offset = s->linesize*8; //default for progressive frames - uint8_t *ptr_y, *ptr_cb, *ptr_cr; - int wrap_y, wrap_c; - - for(i=0; iskipdct; - - if(s->adaptive_quant){ - const int last_qp= s->qscale; - const int mb_xy= mb_x + mb_y*s->mb_stride; - - s->lambda= s->lambda_table[mb_xy]; - update_qscale(s); - - if(!(s->flags&CODEC_FLAG_QP_RD)){ - s->qscale= s->current_picture_ptr->qscale_table[mb_xy]; - s->dquant= s->qscale - last_qp; - - if(s->out_format==FMT_H263){ - s->dquant= av_clip(s->dquant, -2, 2); - - if(s->codec_id==CODEC_ID_MPEG4){ - if(!s->mb_intra){ - if(s->pict_type == B_TYPE){ - if(s->dquant&1 || s->mv_dir&MV_DIRECT) - s->dquant= 0; - } - if(s->mv_type==MV_TYPE_8X8) - s->dquant=0; - } - } - } - } - ff_set_qscale(s, last_qp + s->dquant); - }else if(s->flags&CODEC_FLAG_QP_RD) - ff_set_qscale(s, s->qscale + s->dquant); - - wrap_y = s->linesize; - wrap_c = s->uvlinesize; - ptr_y = s->new_picture.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16; - ptr_cb = s->new_picture.data[1] + (mb_y * mb_block_height * wrap_c) + mb_x * 8; - ptr_cr = s->new_picture.data[2] + (mb_y * mb_block_height * wrap_c) + mb_x * 8; - - if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){ - uint8_t *ebuf= s->edge_emu_buffer + 32; - ff_emulated_edge_mc(ebuf , ptr_y , wrap_y,16,16,mb_x*16,mb_y*16, s->width , s->height); - ptr_y= ebuf; - ff_emulated_edge_mc(ebuf+18*wrap_y , ptr_cb, wrap_c, 8, mb_block_height, mb_x*8, mb_y*8, s->width>>1, s->height>>1); - ptr_cb= ebuf+18*wrap_y; - ff_emulated_edge_mc(ebuf+18*wrap_y+8, ptr_cr, wrap_c, 8, mb_block_height, mb_x*8, mb_y*8, s->width>>1, s->height>>1); - ptr_cr= ebuf+18*wrap_y+8; - } - - if (s->mb_intra) { - if(s->flags&CODEC_FLAG_INTERLACED_DCT){ - int progressive_score, interlaced_score; - - s->interlaced_dct=0; - progressive_score= s->dsp.ildct_cmp[4](s, ptr_y , NULL, wrap_y, 8) - +s->dsp.ildct_cmp[4](s, ptr_y + wrap_y*8, NULL, wrap_y, 8) - 400; - - if(progressive_score > 0){ - interlaced_score = s->dsp.ildct_cmp[4](s, ptr_y , NULL, wrap_y*2, 8) - +s->dsp.ildct_cmp[4](s, ptr_y + wrap_y , NULL, wrap_y*2, 8); - if(progressive_score > interlaced_score){ - s->interlaced_dct=1; - - dct_offset= wrap_y; - wrap_y<<=1; - if (s->chroma_format == CHROMA_422) - wrap_c<<=1; - } - } - } - - s->dsp.get_pixels(s->block[0], ptr_y , wrap_y); - s->dsp.get_pixels(s->block[1], ptr_y + 8, wrap_y); - s->dsp.get_pixels(s->block[2], ptr_y + dct_offset , wrap_y); - s->dsp.get_pixels(s->block[3], ptr_y + dct_offset + 8, wrap_y); - - if(s->flags&CODEC_FLAG_GRAY){ - skip_dct[4]= 1; - skip_dct[5]= 1; - }else{ - s->dsp.get_pixels(s->block[4], ptr_cb, wrap_c); - s->dsp.get_pixels(s->block[5], ptr_cr, wrap_c); - if(!s->chroma_y_shift){ /* 422 */ - s->dsp.get_pixels(s->block[6], ptr_cb + (dct_offset>>1), wrap_c); - s->dsp.get_pixels(s->block[7], ptr_cr + (dct_offset>>1), wrap_c); - } - } - }else{ - op_pixels_func (*op_pix)[4]; - qpel_mc_func (*op_qpix)[16]; - uint8_t *dest_y, *dest_cb, *dest_cr; - - dest_y = s->dest[0]; - dest_cb = s->dest[1]; - dest_cr = s->dest[2]; - - if ((!s->no_rounding) || s->pict_type==B_TYPE){ - op_pix = s->dsp.put_pixels_tab; - op_qpix= s->dsp.put_qpel_pixels_tab; - }else{ - op_pix = s->dsp.put_no_rnd_pixels_tab; - op_qpix= s->dsp.put_no_rnd_qpel_pixels_tab; - } - - if (s->mv_dir & MV_DIR_FORWARD) { - MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix, op_qpix); - op_pix = s->dsp.avg_pixels_tab; - op_qpix= s->dsp.avg_qpel_pixels_tab; - } - if (s->mv_dir & MV_DIR_BACKWARD) { - MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix); - } - - if(s->flags&CODEC_FLAG_INTERLACED_DCT){ - int progressive_score, interlaced_score; - - s->interlaced_dct=0; - progressive_score= s->dsp.ildct_cmp[0](s, dest_y , ptr_y , wrap_y, 8) - +s->dsp.ildct_cmp[0](s, dest_y + wrap_y*8, ptr_y + wrap_y*8, wrap_y, 8) - 400; - - if(s->avctx->ildct_cmp == FF_CMP_VSSE) progressive_score -= 400; - - if(progressive_score>0){ - interlaced_score = s->dsp.ildct_cmp[0](s, dest_y , ptr_y , wrap_y*2, 8) - +s->dsp.ildct_cmp[0](s, dest_y + wrap_y , ptr_y + wrap_y , wrap_y*2, 8); - - if(progressive_score > interlaced_score){ - s->interlaced_dct=1; - - dct_offset= wrap_y; - wrap_y<<=1; - if (s->chroma_format == CHROMA_422) - wrap_c<<=1; - } - } - } - - s->dsp.diff_pixels(s->block[0], ptr_y , dest_y , wrap_y); - s->dsp.diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y); - s->dsp.diff_pixels(s->block[2], ptr_y + dct_offset , dest_y + dct_offset , wrap_y); - s->dsp.diff_pixels(s->block[3], ptr_y + dct_offset + 8, dest_y + dct_offset + 8, wrap_y); - - if(s->flags&CODEC_FLAG_GRAY){ - skip_dct[4]= 1; - skip_dct[5]= 1; - }else{ - s->dsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c); - s->dsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c); - if(!s->chroma_y_shift){ /* 422 */ - s->dsp.diff_pixels(s->block[6], ptr_cb + (dct_offset>>1), dest_cb + (dct_offset>>1), wrap_c); - s->dsp.diff_pixels(s->block[7], ptr_cr + (dct_offset>>1), dest_cr + (dct_offset>>1), wrap_c); - } - } - /* pre quantization */ - if(s->current_picture.mc_mb_var[s->mb_stride*mb_y+ mb_x]<2*s->qscale*s->qscale){ - //FIXME optimize - if(s->dsp.sad[1](NULL, ptr_y , dest_y , wrap_y, 8) < 20*s->qscale) skip_dct[0]= 1; - if(s->dsp.sad[1](NULL, ptr_y + 8, dest_y + 8, wrap_y, 8) < 20*s->qscale) skip_dct[1]= 1; - if(s->dsp.sad[1](NULL, ptr_y +dct_offset , dest_y +dct_offset , wrap_y, 8) < 20*s->qscale) skip_dct[2]= 1; - if(s->dsp.sad[1](NULL, ptr_y +dct_offset+ 8, dest_y +dct_offset+ 8, wrap_y, 8) < 20*s->qscale) skip_dct[3]= 1; - if(s->dsp.sad[1](NULL, ptr_cb , dest_cb , wrap_c, 8) < 20*s->qscale) skip_dct[4]= 1; - if(s->dsp.sad[1](NULL, ptr_cr , dest_cr , wrap_c, 8) < 20*s->qscale) skip_dct[5]= 1; - if(!s->chroma_y_shift){ /* 422 */ - if(s->dsp.sad[1](NULL, ptr_cb +(dct_offset>>1), dest_cb +(dct_offset>>1), wrap_c, 8) < 20*s->qscale) skip_dct[6]= 1; - if(s->dsp.sad[1](NULL, ptr_cr +(dct_offset>>1), dest_cr +(dct_offset>>1), wrap_c, 8) < 20*s->qscale) skip_dct[7]= 1; - } - } - } - - if(s->avctx->quantizer_noise_shaping){ - if(!skip_dct[0]) get_vissual_weight(weight[0], ptr_y , wrap_y); - if(!skip_dct[1]) get_vissual_weight(weight[1], ptr_y + 8, wrap_y); - if(!skip_dct[2]) get_vissual_weight(weight[2], ptr_y + dct_offset , wrap_y); - if(!skip_dct[3]) get_vissual_weight(weight[3], ptr_y + dct_offset + 8, wrap_y); - if(!skip_dct[4]) get_vissual_weight(weight[4], ptr_cb , wrap_c); - if(!skip_dct[5]) get_vissual_weight(weight[5], ptr_cr , wrap_c); - if(!s->chroma_y_shift){ /* 422 */ - if(!skip_dct[6]) get_vissual_weight(weight[6], ptr_cb + (dct_offset>>1), wrap_c); - if(!skip_dct[7]) get_vissual_weight(weight[7], ptr_cr + (dct_offset>>1), wrap_c); - } - memcpy(orig[0], s->block[0], sizeof(DCTELEM)*64*mb_block_count); - } - - /* DCT & quantize */ - assert(s->out_format!=FMT_MJPEG || s->qscale==8); - { - for(i=0;iblock_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow); - // FIXME we could decide to change to quantizer instead of clipping - // JS: I don't think that would be a good idea it could lower quality instead - // of improve it. Just INTRADC clipping deserves changes in quantizer - if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); - }else - s->block_last_index[i]= -1; - } - if(s->avctx->quantizer_noise_shaping){ - for(i=0;iblock_last_index[i] = dct_quantize_refine(s, s->block[i], weight[i], orig[i], i, s->qscale); - } - } - } - - if(s->luma_elim_threshold && !s->mb_intra) - for(i=0; i<4; i++) - dct_single_coeff_elimination(s, i, s->luma_elim_threshold); - if(s->chroma_elim_threshold && !s->mb_intra) - for(i=4; ichroma_elim_threshold); - - if(s->flags & CODEC_FLAG_CBP_RD){ - for(i=0;iblock_last_index[i] == -1) - s->coded_score[i]= INT_MAX/256; - } - } - } - - if((s->flags&CODEC_FLAG_GRAY) && s->mb_intra){ - s->block_last_index[4]= - s->block_last_index[5]= 0; - s->block[4][0]= - s->block[5][0]= (1024 + s->c_dc_scale/2)/ s->c_dc_scale; - } - - //non c quantize code returns incorrect block_last_index FIXME - if(s->alternate_scan && s->dct_quantize != dct_quantize_c){ - for(i=0; iblock_last_index[i]>0){ - for(j=63; j>0; j--){ - if(s->block[i][ s->intra_scantable.permutated[j] ]) break; - } - s->block_last_index[i]= j; - } - } - } - - /* huffman encode */ - switch(s->codec_id){ //FIXME funct ptr could be slightly faster - case CODEC_ID_MPEG1VIDEO: - case CODEC_ID_MPEG2VIDEO: - mpeg1_encode_mb(s, s->block, motion_x, motion_y); break; - case CODEC_ID_MPEG4: - mpeg4_encode_mb(s, s->block, motion_x, motion_y); break; - case CODEC_ID_MSMPEG4V2: - case CODEC_ID_MSMPEG4V3: - case CODEC_ID_WMV1: - msmpeg4_encode_mb(s, s->block, motion_x, motion_y); break; - case CODEC_ID_WMV2: - ff_wmv2_encode_mb(s, s->block, motion_x, motion_y); break; -#ifdef CONFIG_H261_ENCODER - case CODEC_ID_H261: - ff_h261_encode_mb(s, s->block, motion_x, motion_y); break; -#endif - case CODEC_ID_H263: - case CODEC_ID_H263P: - case CODEC_ID_FLV1: - case CODEC_ID_RV10: - case CODEC_ID_RV20: - h263_encode_mb(s, s->block, motion_x, motion_y); break; - case CODEC_ID_MJPEG: - mjpeg_encode_mb(s, s->block); break; - default: - assert(0); - } -} - -static av_always_inline void encode_mb(MpegEncContext *s, int motion_x, int motion_y) -{ - if (s->chroma_format == CHROMA_420) encode_mb_internal(s, motion_x, motion_y, 8, 6); - else encode_mb_internal(s, motion_x, motion_y, 16, 8); -} - -#endif //CONFIG_ENCODERS - void ff_mpeg_flush(AVCodecContext *avctx){ int i; MpegEncContext *s = avctx->priv_data; @@ -4635,2005 +2193,35 @@ void ff_mpeg_flush(AVCodecContext *avctx){ s->pp_time=0; } -#ifdef CONFIG_ENCODERS -void ff_copy_bits(PutBitContext *pb, uint8_t *src, int length) +static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s, + DCTELEM *block, int n, int qscale) { - const uint16_t *srcw= (uint16_t*)src; - int words= length>>4; - int bits= length&15; - int i; + int i, level, nCoeffs; + const uint16_t *quant_matrix; - if(length==0) return; + nCoeffs= s->block_last_index[n]; - if(words < 16){ - for(i=0; i>(16-bits)); -} - -static inline void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type){ - int i; - - memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? - - /* mpeg1 */ - d->mb_skip_run= s->mb_skip_run; - for(i=0; i<3; i++) - d->last_dc[i]= s->last_dc[i]; - - /* statistics */ - d->mv_bits= s->mv_bits; - d->i_tex_bits= s->i_tex_bits; - d->p_tex_bits= s->p_tex_bits; - d->i_count= s->i_count; - d->f_count= s->f_count; - d->b_count= s->b_count; - d->skip_count= s->skip_count; - d->misc_bits= s->misc_bits; - d->last_bits= 0; - - d->mb_skipped= 0; - d->qscale= s->qscale; - d->dquant= s->dquant; -} - -static inline void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type){ - int i; - - memcpy(d->mv, s->mv, 2*4*2*sizeof(int)); - memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? - - /* mpeg1 */ - d->mb_skip_run= s->mb_skip_run; - for(i=0; i<3; i++) - d->last_dc[i]= s->last_dc[i]; - - /* statistics */ - d->mv_bits= s->mv_bits; - d->i_tex_bits= s->i_tex_bits; - d->p_tex_bits= s->p_tex_bits; - d->i_count= s->i_count; - d->f_count= s->f_count; - d->b_count= s->b_count; - d->skip_count= s->skip_count; - d->misc_bits= s->misc_bits; - - d->mb_intra= s->mb_intra; - d->mb_skipped= s->mb_skipped; - d->mv_type= s->mv_type; - d->mv_dir= s->mv_dir; - d->pb= s->pb; - if(s->data_partitioning){ - d->pb2= s->pb2; - d->tex_pb= s->tex_pb; - } - d->block= s->block; - for(i=0; i<8; i++) - d->block_last_index[i]= s->block_last_index[i]; - d->interlaced_dct= s->interlaced_dct; - d->qscale= s->qscale; -} - -static inline void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegEncContext *best, int type, - PutBitContext pb[2], PutBitContext pb2[2], PutBitContext tex_pb[2], - int *dmin, int *next_block, int motion_x, int motion_y) -{ - int score; - uint8_t *dest_backup[3]; - - copy_context_before_encode(s, backup, type); - - s->block= s->blocks[*next_block]; - s->pb= pb[*next_block]; - if(s->data_partitioning){ - s->pb2 = pb2 [*next_block]; - s->tex_pb= tex_pb[*next_block]; - } - - if(*next_block){ - memcpy(dest_backup, s->dest, sizeof(s->dest)); - s->dest[0] = s->rd_scratchpad; - s->dest[1] = s->rd_scratchpad + 16*s->linesize; - s->dest[2] = s->rd_scratchpad + 16*s->linesize + 8; - assert(s->linesize >= 32); //FIXME - } - - encode_mb(s, motion_x, motion_y); - - score= put_bits_count(&s->pb); - if(s->data_partitioning){ - score+= put_bits_count(&s->pb2); - score+= put_bits_count(&s->tex_pb); - } - - if(s->avctx->mb_decision == FF_MB_DECISION_RD){ - MPV_decode_mb(s, s->block); - - score *= s->lambda2; - score += sse_mb(s) << FF_LAMBDA_SHIFT; - } - - if(*next_block){ - memcpy(s->dest, dest_backup, sizeof(s->dest)); - } - - if(score<*dmin){ - *dmin= score; - *next_block^=1; - - copy_context_after_encode(best, s, type); - } -} - -static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride){ - uint32_t *sq = ff_squareTbl + 256; - int acc=0; - int x,y; - - if(w==16 && h==16) - return s->dsp.sse[0](NULL, src1, src2, stride, 16); - else if(w==8 && h==8) - return s->dsp.sse[1](NULL, src1, src2, stride, 8); - - for(y=0; y=0); - - return acc; -} - -static int sse_mb(MpegEncContext *s){ - int w= 16; - int h= 16; - - if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16; - if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16; - - if(w==16 && h==16) - if(s->avctx->mb_cmp == FF_CMP_NSSE){ - return s->dsp.nsse[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16) - +s->dsp.nsse[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8) - +s->dsp.nsse[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8); - }else{ - return s->dsp.sse[0](NULL, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16) - +s->dsp.sse[1](NULL, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8) - +s->dsp.sse[1](NULL, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8); - } - else - return sse(s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], w, h, s->linesize) - +sse(s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], w>>1, h>>1, s->uvlinesize) - +sse(s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], w>>1, h>>1, s->uvlinesize); -} - -static int pre_estimate_motion_thread(AVCodecContext *c, void *arg){ - MpegEncContext *s= arg; - - - s->me.pre_pass=1; - s->me.dia_size= s->avctx->pre_dia_size; - s->first_slice_line=1; - for(s->mb_y= s->end_mb_y-1; s->mb_y >= s->start_mb_y; s->mb_y--) { - for(s->mb_x=s->mb_width-1; s->mb_x >=0 ;s->mb_x--) { - ff_pre_estimate_p_frame_motion(s, s->mb_x, s->mb_y); - } - s->first_slice_line=0; - } - - s->me.pre_pass=0; - - return 0; -} - -static int estimate_motion_thread(AVCodecContext *c, void *arg){ - MpegEncContext *s= arg; - - ff_check_alignment(); - - s->me.dia_size= s->avctx->dia_size; - s->first_slice_line=1; - for(s->mb_y= s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) { - s->mb_x=0; //for block init below - ff_init_block_index(s); - for(s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) { - s->block_index[0]+=2; - s->block_index[1]+=2; - s->block_index[2]+=2; - s->block_index[3]+=2; - - /* compute motion vector & mb_type and store in context */ - if(s->pict_type==B_TYPE) - ff_estimate_b_frame_motion(s, s->mb_x, s->mb_y); - else - ff_estimate_p_frame_motion(s, s->mb_x, s->mb_y); - } - s->first_slice_line=0; - } - return 0; -} - -static int mb_var_thread(AVCodecContext *c, void *arg){ - MpegEncContext *s= arg; - int mb_x, mb_y; - - ff_check_alignment(); - - for(mb_y=s->start_mb_y; mb_y < s->end_mb_y; mb_y++) { - for(mb_x=0; mb_x < s->mb_width; mb_x++) { - int xx = mb_x * 16; - int yy = mb_y * 16; - uint8_t *pix = s->new_picture.data[0] + (yy * s->linesize) + xx; - int varc; - int sum = s->dsp.pix_sum(pix, s->linesize); - - varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8; - - s->current_picture.mb_var [s->mb_stride * mb_y + mb_x] = varc; - s->current_picture.mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8; - s->me.mb_var_sum_temp += varc; - } - } - return 0; -} - -static void write_slice_end(MpegEncContext *s){ - if(s->codec_id==CODEC_ID_MPEG4){ - if(s->partitioned_frame){ - ff_mpeg4_merge_partitions(s); - } - - ff_mpeg4_stuffing(&s->pb); - }else if(s->out_format == FMT_MJPEG){ - ff_mjpeg_stuffing(&s->pb); - } - - align_put_bits(&s->pb); - flush_put_bits(&s->pb); - - if((s->flags&CODEC_FLAG_PASS1) && !s->partitioned_frame) - s->misc_bits+= get_bits_diff(s); -} - -static int encode_thread(AVCodecContext *c, void *arg){ - MpegEncContext *s= arg; - int mb_x, mb_y, pdif = 0; - int i, j; - MpegEncContext best_s, backup_s; - uint8_t bit_buf[2][MAX_MB_BYTES]; - uint8_t bit_buf2[2][MAX_MB_BYTES]; - uint8_t bit_buf_tex[2][MAX_MB_BYTES]; - PutBitContext pb[2], pb2[2], tex_pb[2]; -//printf("%d->%d\n", s->resync_mb_y, s->end_mb_y); - - ff_check_alignment(); - - for(i=0; i<2; i++){ - init_put_bits(&pb [i], bit_buf [i], MAX_MB_BYTES); - init_put_bits(&pb2 [i], bit_buf2 [i], MAX_MB_BYTES); - init_put_bits(&tex_pb[i], bit_buf_tex[i], MAX_MB_BYTES); - } - - s->last_bits= put_bits_count(&s->pb); - s->mv_bits=0; - s->misc_bits=0; - s->i_tex_bits=0; - s->p_tex_bits=0; - s->i_count=0; - s->f_count=0; - s->b_count=0; - s->skip_count=0; - - for(i=0; i<3; i++){ - /* init last dc values */ - /* note: quant matrix value (8) is implied here */ - s->last_dc[i] = 128 << s->intra_dc_precision; - - s->current_picture.error[i] = 0; - } - s->mb_skip_run = 0; - memset(s->last_mv, 0, sizeof(s->last_mv)); - - s->last_mv_dir = 0; - - switch(s->codec_id){ - case CODEC_ID_H263: - case CODEC_ID_H263P: - case CODEC_ID_FLV1: - s->gob_index = ff_h263_get_gob_height(s); - break; - case CODEC_ID_MPEG4: - if(s->partitioned_frame) - ff_mpeg4_init_partitions(s); - break; - } - - s->resync_mb_x=0; - s->resync_mb_y=0; - s->first_slice_line = 1; - s->ptr_lastgob = s->pb.buf; - for(mb_y= s->start_mb_y; mb_y < s->end_mb_y; mb_y++) { -// printf("row %d at %X\n", s->mb_y, (int)s); - s->mb_x=0; - s->mb_y= mb_y; - - ff_set_qscale(s, s->qscale); - ff_init_block_index(s); - - for(mb_x=0; mb_x < s->mb_width; mb_x++) { - int xy= mb_y*s->mb_stride + mb_x; // removed const, H261 needs to adjust this - int mb_type= s->mb_type[xy]; -// int d; - int dmin= INT_MAX; - int dir; - - if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < MAX_MB_BYTES){ - av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); - return -1; - } - if(s->data_partitioning){ - if( s->pb2 .buf_end - s->pb2 .buf - (put_bits_count(&s-> pb2)>>3) < MAX_MB_BYTES - || s->tex_pb.buf_end - s->tex_pb.buf - (put_bits_count(&s->tex_pb )>>3) < MAX_MB_BYTES){ - av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); - return -1; - } - } - - s->mb_x = mb_x; - s->mb_y = mb_y; // moved into loop, can get changed by H.261 - ff_update_block_index(s); - -#ifdef CONFIG_H261_ENCODER - if(s->codec_id == CODEC_ID_H261){ - ff_h261_reorder_mb_index(s); - xy= s->mb_y*s->mb_stride + s->mb_x; - mb_type= s->mb_type[xy]; - } -#endif - - /* write gob / video packet header */ - if(s->rtp_mode){ - int current_packet_size, is_gob_start; - - current_packet_size= ((put_bits_count(&s->pb)+7)>>3) - (s->ptr_lastgob - s->pb.buf); - - is_gob_start= s->avctx->rtp_payload_size && current_packet_size >= s->avctx->rtp_payload_size && mb_y + mb_x>0; - - if(s->start_mb_y == mb_y && mb_y > 0 && mb_x==0) is_gob_start=1; - - switch(s->codec_id){ - case CODEC_ID_H263: - case CODEC_ID_H263P: - if(!s->h263_slice_structured) - if(s->mb_x || s->mb_y%s->gob_index) is_gob_start=0; - break; - case CODEC_ID_MPEG2VIDEO: - if(s->mb_x==0 && s->mb_y!=0) is_gob_start=1; - case CODEC_ID_MPEG1VIDEO: - if(s->mb_skip_run) is_gob_start=0; - break; - } - - if(is_gob_start){ - if(s->start_mb_y != mb_y || mb_x!=0){ - write_slice_end(s); - - if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame){ - ff_mpeg4_init_partitions(s); - } - } - - assert((put_bits_count(&s->pb)&7) == 0); - current_packet_size= pbBufPtr(&s->pb) - s->ptr_lastgob; - - if(s->avctx->error_rate && s->resync_mb_x + s->resync_mb_y > 0){ - int r= put_bits_count(&s->pb)/8 + s->picture_number + 16 + s->mb_x + s->mb_y; - int d= 100 / s->avctx->error_rate; - if(r % d == 0){ - current_packet_size=0; -#ifndef ALT_BITSTREAM_WRITER - s->pb.buf_ptr= s->ptr_lastgob; -#endif - assert(pbBufPtr(&s->pb) == s->ptr_lastgob); - } - } - - if (s->avctx->rtp_callback){ - int number_mb = (mb_y - s->resync_mb_y)*s->mb_width + mb_x - s->resync_mb_x; - s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, current_packet_size, number_mb); - } - - switch(s->codec_id){ - case CODEC_ID_MPEG4: - ff_mpeg4_encode_video_packet_header(s); - ff_mpeg4_clean_buffers(s); - break; - case CODEC_ID_MPEG1VIDEO: - case CODEC_ID_MPEG2VIDEO: - ff_mpeg1_encode_slice_header(s); - ff_mpeg1_clean_buffers(s); - break; - case CODEC_ID_H263: - case CODEC_ID_H263P: - h263_encode_gob_header(s, mb_y); - break; - } - - if(s->flags&CODEC_FLAG_PASS1){ - int bits= put_bits_count(&s->pb); - s->misc_bits+= bits - s->last_bits; - s->last_bits= bits; - } - - s->ptr_lastgob += current_packet_size; - s->first_slice_line=1; - s->resync_mb_x=mb_x; - s->resync_mb_y=mb_y; - } - } - - if( (s->resync_mb_x == s->mb_x) - && s->resync_mb_y+1 == s->mb_y){ - s->first_slice_line=0; - } - - s->mb_skipped=0; - s->dquant=0; //only for QP_RD - - if(mb_type & (mb_type-1) || (s->flags & CODEC_FLAG_QP_RD)){ // more than 1 MB type possible or CODEC_FLAG_QP_RD - int next_block=0; - int pb_bits_count, pb2_bits_count, tex_pb_bits_count; - - copy_context_before_encode(&backup_s, s, -1); - backup_s.pb= s->pb; - best_s.data_partitioning= s->data_partitioning; - best_s.partitioned_frame= s->partitioned_frame; - if(s->data_partitioning){ - backup_s.pb2= s->pb2; - backup_s.tex_pb= s->tex_pb; - } - - if(mb_type&CANDIDATE_MB_TYPE_INTER){ - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_16X16; - s->mb_intra= 0; - s->mv[0][0][0] = s->p_mv_table[xy][0]; - s->mv[0][0][1] = s->p_mv_table[xy][1]; - encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER, pb, pb2, tex_pb, - &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); - } - if(mb_type&CANDIDATE_MB_TYPE_INTER_I){ - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_FIELD; - s->mb_intra= 0; - for(i=0; i<2; i++){ - j= s->field_select[0][i] = s->p_field_select_table[i][xy]; - s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0]; - s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1]; - } - encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER_I, pb, pb2, tex_pb, - &dmin, &next_block, 0, 0); - } - if(mb_type&CANDIDATE_MB_TYPE_SKIPPED){ - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_16X16; - s->mb_intra= 0; - s->mv[0][0][0] = 0; - s->mv[0][0][1] = 0; - encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_SKIPPED, pb, pb2, tex_pb, - &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); - } - if(mb_type&CANDIDATE_MB_TYPE_INTER4V){ - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_8X8; - s->mb_intra= 0; - for(i=0; i<4; i++){ - s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0]; - s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1]; - } - encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER4V, pb, pb2, tex_pb, - &dmin, &next_block, 0, 0); - } - if(mb_type&CANDIDATE_MB_TYPE_FORWARD){ - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_16X16; - s->mb_intra= 0; - s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; - s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; - encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD, pb, pb2, tex_pb, - &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); - } - if(mb_type&CANDIDATE_MB_TYPE_BACKWARD){ - s->mv_dir = MV_DIR_BACKWARD; - s->mv_type = MV_TYPE_16X16; - s->mb_intra= 0; - s->mv[1][0][0] = s->b_back_mv_table[xy][0]; - s->mv[1][0][1] = s->b_back_mv_table[xy][1]; - encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD, pb, pb2, tex_pb, - &dmin, &next_block, s->mv[1][0][0], s->mv[1][0][1]); - } - if(mb_type&CANDIDATE_MB_TYPE_BIDIR){ - s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; - s->mv_type = MV_TYPE_16X16; - s->mb_intra= 0; - s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; - s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; - s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; - s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; - encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR, pb, pb2, tex_pb, - &dmin, &next_block, 0, 0); - } - if(mb_type&CANDIDATE_MB_TYPE_FORWARD_I){ - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_FIELD; - s->mb_intra= 0; - for(i=0; i<2; i++){ - j= s->field_select[0][i] = s->b_field_select_table[0][i][xy]; - s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0]; - s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1]; - } - encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD_I, pb, pb2, tex_pb, - &dmin, &next_block, 0, 0); - } - if(mb_type&CANDIDATE_MB_TYPE_BACKWARD_I){ - s->mv_dir = MV_DIR_BACKWARD; - s->mv_type = MV_TYPE_FIELD; - s->mb_intra= 0; - for(i=0; i<2; i++){ - j= s->field_select[1][i] = s->b_field_select_table[1][i][xy]; - s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0]; - s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1]; - } - encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD_I, pb, pb2, tex_pb, - &dmin, &next_block, 0, 0); - } - if(mb_type&CANDIDATE_MB_TYPE_BIDIR_I){ - s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; - s->mv_type = MV_TYPE_FIELD; - s->mb_intra= 0; - for(dir=0; dir<2; dir++){ - for(i=0; i<2; i++){ - j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy]; - s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0]; - s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1]; - } - } - encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR_I, pb, pb2, tex_pb, - &dmin, &next_block, 0, 0); - } - if(mb_type&CANDIDATE_MB_TYPE_INTRA){ - s->mv_dir = 0; - s->mv_type = MV_TYPE_16X16; - s->mb_intra= 1; - s->mv[0][0][0] = 0; - s->mv[0][0][1] = 0; - encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTRA, pb, pb2, tex_pb, - &dmin, &next_block, 0, 0); - if(s->h263_pred || s->h263_aic){ - if(best_s.mb_intra) - s->mbintra_table[mb_x + mb_y*s->mb_stride]=1; - else - ff_clean_intra_table_entries(s); //old mode? - } - } - - if((s->flags & CODEC_FLAG_QP_RD) && dmin < INT_MAX){ - if(best_s.mv_type==MV_TYPE_16X16){ //FIXME move 4mv after QPRD - const int last_qp= backup_s.qscale; - int qpi, qp, dc[6]; - DCTELEM ac[6][16]; - const int mvdir= (best_s.mv_dir&MV_DIR_BACKWARD) ? 1 : 0; - static const int dquant_tab[4]={-1,1,-2,2}; - - assert(backup_s.dquant == 0); - - //FIXME intra - s->mv_dir= best_s.mv_dir; - s->mv_type = MV_TYPE_16X16; - s->mb_intra= best_s.mb_intra; - s->mv[0][0][0] = best_s.mv[0][0][0]; - s->mv[0][0][1] = best_s.mv[0][0][1]; - s->mv[1][0][0] = best_s.mv[1][0][0]; - s->mv[1][0][1] = best_s.mv[1][0][1]; - - qpi = s->pict_type == B_TYPE ? 2 : 0; - for(; qpi<4; qpi++){ - int dquant= dquant_tab[qpi]; - qp= last_qp + dquant; - if(qp < s->avctx->qmin || qp > s->avctx->qmax) - continue; - backup_s.dquant= dquant; - if(s->mb_intra && s->dc_val[0]){ - for(i=0; i<6; i++){ - dc[i]= s->dc_val[0][ s->block_index[i] ]; - memcpy(ac[i], s->ac_val[0][s->block_index[i]], sizeof(DCTELEM)*16); - } - } - - encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER /* wrong but unused */, pb, pb2, tex_pb, - &dmin, &next_block, s->mv[mvdir][0][0], s->mv[mvdir][0][1]); - if(best_s.qscale != qp){ - if(s->mb_intra && s->dc_val[0]){ - for(i=0; i<6; i++){ - s->dc_val[0][ s->block_index[i] ]= dc[i]; - memcpy(s->ac_val[0][s->block_index[i]], ac[i], sizeof(DCTELEM)*16); - } - } - } - } - } - } - if(mb_type&CANDIDATE_MB_TYPE_DIRECT){ - int mx= s->b_direct_mv_table[xy][0]; - int my= s->b_direct_mv_table[xy][1]; - - backup_s.dquant = 0; - s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; - s->mb_intra= 0; - ff_mpeg4_set_direct_mv(s, mx, my); - encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb, - &dmin, &next_block, mx, my); - } - if(mb_type&CANDIDATE_MB_TYPE_DIRECT0){ - backup_s.dquant = 0; - s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; - s->mb_intra= 0; - ff_mpeg4_set_direct_mv(s, 0, 0); - encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb, - &dmin, &next_block, 0, 0); - } - if(!best_s.mb_intra && s->flags2&CODEC_FLAG2_SKIP_RD){ - int coded=0; - for(i=0; i<6; i++) - coded |= s->block_last_index[i]; - if(coded){ - int mx,my; - memcpy(s->mv, best_s.mv, sizeof(s->mv)); - if(best_s.mv_dir & MV_DIRECT){ - mx=my=0; //FIXME find the one we actually used - ff_mpeg4_set_direct_mv(s, mx, my); - }else if(best_s.mv_dir&MV_DIR_BACKWARD){ - mx= s->mv[1][0][0]; - my= s->mv[1][0][1]; - }else{ - mx= s->mv[0][0][0]; - my= s->mv[0][0][1]; - } - - s->mv_dir= best_s.mv_dir; - s->mv_type = best_s.mv_type; - s->mb_intra= 0; -/* s->mv[0][0][0] = best_s.mv[0][0][0]; - s->mv[0][0][1] = best_s.mv[0][0][1]; - s->mv[1][0][0] = best_s.mv[1][0][0]; - s->mv[1][0][1] = best_s.mv[1][0][1];*/ - backup_s.dquant= 0; - s->skipdct=1; - encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER /* wrong but unused */, pb, pb2, tex_pb, - &dmin, &next_block, mx, my); - s->skipdct=0; - } - } - - s->current_picture.qscale_table[xy]= best_s.qscale; - - copy_context_after_encode(s, &best_s, -1); - - pb_bits_count= put_bits_count(&s->pb); - flush_put_bits(&s->pb); - ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count); - s->pb= backup_s.pb; - - if(s->data_partitioning){ - pb2_bits_count= put_bits_count(&s->pb2); - flush_put_bits(&s->pb2); - ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count); - s->pb2= backup_s.pb2; - - tex_pb_bits_count= put_bits_count(&s->tex_pb); - flush_put_bits(&s->tex_pb); - ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count); - s->tex_pb= backup_s.tex_pb; - } - s->last_bits= put_bits_count(&s->pb); - - if (s->out_format == FMT_H263 && s->pict_type!=B_TYPE) - ff_h263_update_motion_val(s); - - if(next_block==0){ //FIXME 16 vs linesize16 - s->dsp.put_pixels_tab[0][0](s->dest[0], s->rd_scratchpad , s->linesize ,16); - s->dsp.put_pixels_tab[1][0](s->dest[1], s->rd_scratchpad + 16*s->linesize , s->uvlinesize, 8); - s->dsp.put_pixels_tab[1][0](s->dest[2], s->rd_scratchpad + 16*s->linesize + 8, s->uvlinesize, 8); - } - - if(s->avctx->mb_decision == FF_MB_DECISION_BITS) - MPV_decode_mb(s, s->block); - } else { - int motion_x = 0, motion_y = 0; - s->mv_type=MV_TYPE_16X16; - // only one MB-Type possible - - switch(mb_type){ - case CANDIDATE_MB_TYPE_INTRA: - s->mv_dir = 0; - s->mb_intra= 1; - motion_x= s->mv[0][0][0] = 0; - motion_y= s->mv[0][0][1] = 0; - break; - case CANDIDATE_MB_TYPE_INTER: - s->mv_dir = MV_DIR_FORWARD; - s->mb_intra= 0; - motion_x= s->mv[0][0][0] = s->p_mv_table[xy][0]; - motion_y= s->mv[0][0][1] = s->p_mv_table[xy][1]; - break; - case CANDIDATE_MB_TYPE_INTER_I: - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_FIELD; - s->mb_intra= 0; - for(i=0; i<2; i++){ - j= s->field_select[0][i] = s->p_field_select_table[i][xy]; - s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0]; - s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1]; - } - break; - case CANDIDATE_MB_TYPE_INTER4V: - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_8X8; - s->mb_intra= 0; - for(i=0; i<4; i++){ - s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0]; - s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1]; - } - break; - case CANDIDATE_MB_TYPE_DIRECT: - s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; - s->mb_intra= 0; - motion_x=s->b_direct_mv_table[xy][0]; - motion_y=s->b_direct_mv_table[xy][1]; - ff_mpeg4_set_direct_mv(s, motion_x, motion_y); - break; - case CANDIDATE_MB_TYPE_DIRECT0: - s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; - s->mb_intra= 0; - ff_mpeg4_set_direct_mv(s, 0, 0); - break; - case CANDIDATE_MB_TYPE_BIDIR: - s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; - s->mb_intra= 0; - s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; - s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; - s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; - s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; - break; - case CANDIDATE_MB_TYPE_BACKWARD: - s->mv_dir = MV_DIR_BACKWARD; - s->mb_intra= 0; - motion_x= s->mv[1][0][0] = s->b_back_mv_table[xy][0]; - motion_y= s->mv[1][0][1] = s->b_back_mv_table[xy][1]; - break; - case CANDIDATE_MB_TYPE_FORWARD: - s->mv_dir = MV_DIR_FORWARD; - s->mb_intra= 0; - motion_x= s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; - motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; -// printf(" %d %d ", motion_x, motion_y); - break; - case CANDIDATE_MB_TYPE_FORWARD_I: - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_FIELD; - s->mb_intra= 0; - for(i=0; i<2; i++){ - j= s->field_select[0][i] = s->b_field_select_table[0][i][xy]; - s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0]; - s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1]; - } - break; - case CANDIDATE_MB_TYPE_BACKWARD_I: - s->mv_dir = MV_DIR_BACKWARD; - s->mv_type = MV_TYPE_FIELD; - s->mb_intra= 0; - for(i=0; i<2; i++){ - j= s->field_select[1][i] = s->b_field_select_table[1][i][xy]; - s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0]; - s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1]; - } - break; - case CANDIDATE_MB_TYPE_BIDIR_I: - s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; - s->mv_type = MV_TYPE_FIELD; - s->mb_intra= 0; - for(dir=0; dir<2; dir++){ - for(i=0; i<2; i++){ - j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy]; - s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0]; - s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1]; - } - } - break; - default: - av_log(s->avctx, AV_LOG_ERROR, "illegal MB type\n"); - } - - encode_mb(s, motion_x, motion_y); - - // RAL: Update last macroblock type - s->last_mv_dir = s->mv_dir; - - if (s->out_format == FMT_H263 && s->pict_type!=B_TYPE) - ff_h263_update_motion_val(s); - - MPV_decode_mb(s, s->block); - } - - /* clean the MV table in IPS frames for direct mode in B frames */ - if(s->mb_intra /* && I,P,S_TYPE */){ - s->p_mv_table[xy][0]=0; - s->p_mv_table[xy][1]=0; - } - - if(s->flags&CODEC_FLAG_PSNR){ - int w= 16; - int h= 16; - - if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16; - if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16; - - s->current_picture.error[0] += sse( - s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, - s->dest[0], w, h, s->linesize); - s->current_picture.error[1] += sse( - s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8, - s->dest[1], w>>1, h>>1, s->uvlinesize); - s->current_picture.error[2] += sse( - s, s->new_picture .data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8, - s->dest[2], w>>1, h>>1, s->uvlinesize); - } - if(s->loop_filter){ - if(s->out_format == FMT_H263) - ff_h263_loop_filter(s); - } -//printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_stride, put_bits_count(&s->pb)); - } - } - - //not beautiful here but we must write it before flushing so it has to be here - if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == I_TYPE) - msmpeg4_encode_ext_header(s); - - write_slice_end(s); - - /* Send the last GOB if RTP */ - if (s->avctx->rtp_callback) { - int number_mb = (mb_y - s->resync_mb_y)*s->mb_width - s->resync_mb_x; - pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; - /* Call the RTP callback to send the last GOB */ - emms_c(); - s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, pdif, number_mb); - } - - return 0; -} - -#define MERGE(field) dst->field += src->field; src->field=0 -static void merge_context_after_me(MpegEncContext *dst, MpegEncContext *src){ - MERGE(me.scene_change_score); - MERGE(me.mc_mb_var_sum_temp); - MERGE(me.mb_var_sum_temp); -} - -static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src){ - int i; - - MERGE(dct_count[0]); //note, the other dct vars are not part of the context - MERGE(dct_count[1]); - MERGE(mv_bits); - MERGE(i_tex_bits); - MERGE(p_tex_bits); - MERGE(i_count); - MERGE(f_count); - MERGE(b_count); - MERGE(skip_count); - MERGE(misc_bits); - MERGE(error_count); - MERGE(padding_bug_score); - MERGE(current_picture.error[0]); - MERGE(current_picture.error[1]); - MERGE(current_picture.error[2]); - - if(dst->avctx->noise_reduction){ - for(i=0; i<64; i++){ - MERGE(dct_error_sum[0][i]); - MERGE(dct_error_sum[1][i]); - } - } - - assert(put_bits_count(&src->pb) % 8 ==0); - assert(put_bits_count(&dst->pb) % 8 ==0); - ff_copy_bits(&dst->pb, src->pb.buf, put_bits_count(&src->pb)); - flush_put_bits(&dst->pb); -} - -static int estimate_qp(MpegEncContext *s, int dry_run){ - if (s->next_lambda){ - s->current_picture_ptr->quality= - s->current_picture.quality = s->next_lambda; - if(!dry_run) s->next_lambda= 0; - } else if (!s->fixed_qscale) { - s->current_picture_ptr->quality= - s->current_picture.quality = ff_rate_estimate_qscale(s, dry_run); - if (s->current_picture.quality < 0) - return -1; - } - - if(s->adaptive_quant){ - switch(s->codec_id){ - case CODEC_ID_MPEG4: - ff_clean_mpeg4_qscales(s); - break; - case CODEC_ID_H263: - case CODEC_ID_H263P: - case CODEC_ID_FLV1: - ff_clean_h263_qscales(s); - break; - } - - s->lambda= s->lambda_table[0]; - //FIXME broken - }else - s->lambda= s->current_picture.quality; -//printf("%d %d\n", s->avctx->global_quality, s->current_picture.quality); - update_qscale(s); - return 0; -} - -static int encode_picture(MpegEncContext *s, int picture_number) -{ - int i; - int bits; - - s->picture_number = picture_number; - - /* Reset the average MB variance */ - s->me.mb_var_sum_temp = - s->me.mc_mb_var_sum_temp = 0; - - /* we need to initialize some time vars before we can encode b-frames */ - // RAL: Condition added for MPEG1VIDEO - if (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO || (s->h263_pred && !s->h263_msmpeg4)) - ff_set_mpeg4_time(s, s->picture_number); //FIXME rename and use has_b_frames or similar - - s->me.scene_change_score=0; - -// s->lambda= s->current_picture_ptr->quality; //FIXME qscale / ... stuff for ME ratedistoration - - if(s->pict_type==I_TYPE){ - if(s->msmpeg4_version >= 3) s->no_rounding=1; - else s->no_rounding=0; - }else if(s->pict_type!=B_TYPE){ - if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4) - s->no_rounding ^= 1; - } - - if(s->flags & CODEC_FLAG_PASS2){ - if (estimate_qp(s,1) < 0) - return -1; - ff_get_2pass_fcode(s); - }else if(!(s->flags & CODEC_FLAG_QSCALE)){ - if(s->pict_type==B_TYPE) - s->lambda= s->last_lambda_for[s->pict_type]; - else - s->lambda= s->last_lambda_for[s->last_non_b_pict_type]; - update_qscale(s); - } - - s->mb_intra=0; //for the rate distortion & bit compare functions - for(i=1; iavctx->thread_count; i++){ - ff_update_duplicate_context(s->thread_context[i], s); - } - - ff_init_me(s); - - /* Estimate motion for every MB */ - if(s->pict_type != I_TYPE){ - s->lambda = (s->lambda * s->avctx->me_penalty_compensation + 128)>>8; - s->lambda2= (s->lambda2* (int64_t)s->avctx->me_penalty_compensation + 128)>>8; - if(s->pict_type != B_TYPE && s->avctx->me_threshold==0){ - if((s->avctx->pre_me && s->last_non_b_pict_type==I_TYPE) || s->avctx->pre_me==2){ - s->avctx->execute(s->avctx, pre_estimate_motion_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count); - } - } - - s->avctx->execute(s->avctx, estimate_motion_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count); - }else /* if(s->pict_type == I_TYPE) */{ - /* I-Frame */ - for(i=0; imb_stride*s->mb_height; i++) - s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA; - - if(!s->fixed_qscale){ - /* finding spatial complexity for I-frame rate control */ - s->avctx->execute(s->avctx, mb_var_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count); - } - } - for(i=1; iavctx->thread_count; i++){ - merge_context_after_me(s, s->thread_context[i]); - } - s->current_picture.mc_mb_var_sum= s->current_picture_ptr->mc_mb_var_sum= s->me.mc_mb_var_sum_temp; - s->current_picture. mb_var_sum= s->current_picture_ptr-> mb_var_sum= s->me. mb_var_sum_temp; - emms_c(); - - if(s->me.scene_change_score > s->avctx->scenechange_threshold && s->pict_type == P_TYPE){ - s->pict_type= I_TYPE; - for(i=0; imb_stride*s->mb_height; i++) - s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA; -//printf("Scene change detected, encoding as I Frame %d %d\n", s->current_picture.mb_var_sum, s->current_picture.mc_mb_var_sum); - } - - if(!s->umvplus){ - if(s->pict_type==P_TYPE || s->pict_type==S_TYPE) { - s->f_code= ff_get_best_fcode(s, s->p_mv_table, CANDIDATE_MB_TYPE_INTER); - - if(s->flags & CODEC_FLAG_INTERLACED_ME){ - int a,b; - a= ff_get_best_fcode(s, s->p_field_mv_table[0][0], CANDIDATE_MB_TYPE_INTER_I); //FIXME field_select - b= ff_get_best_fcode(s, s->p_field_mv_table[1][1], CANDIDATE_MB_TYPE_INTER_I); - s->f_code= FFMAX(s->f_code, FFMAX(a,b)); - } - - ff_fix_long_p_mvs(s); - ff_fix_long_mvs(s, NULL, 0, s->p_mv_table, s->f_code, CANDIDATE_MB_TYPE_INTER, 0); - if(s->flags & CODEC_FLAG_INTERLACED_ME){ - int j; - for(i=0; i<2; i++){ - for(j=0; j<2; j++) - ff_fix_long_mvs(s, s->p_field_select_table[i], j, - s->p_field_mv_table[i][j], s->f_code, CANDIDATE_MB_TYPE_INTER_I, 0); - } - } - } - - if(s->pict_type==B_TYPE){ - int a, b; - - a = ff_get_best_fcode(s, s->b_forw_mv_table, CANDIDATE_MB_TYPE_FORWARD); - b = ff_get_best_fcode(s, s->b_bidir_forw_mv_table, CANDIDATE_MB_TYPE_BIDIR); - s->f_code = FFMAX(a, b); - - a = ff_get_best_fcode(s, s->b_back_mv_table, CANDIDATE_MB_TYPE_BACKWARD); - b = ff_get_best_fcode(s, s->b_bidir_back_mv_table, CANDIDATE_MB_TYPE_BIDIR); - s->b_code = FFMAX(a, b); - - ff_fix_long_mvs(s, NULL, 0, s->b_forw_mv_table, s->f_code, CANDIDATE_MB_TYPE_FORWARD, 1); - ff_fix_long_mvs(s, NULL, 0, s->b_back_mv_table, s->b_code, CANDIDATE_MB_TYPE_BACKWARD, 1); - ff_fix_long_mvs(s, NULL, 0, s->b_bidir_forw_mv_table, s->f_code, CANDIDATE_MB_TYPE_BIDIR, 1); - ff_fix_long_mvs(s, NULL, 0, s->b_bidir_back_mv_table, s->b_code, CANDIDATE_MB_TYPE_BIDIR, 1); - if(s->flags & CODEC_FLAG_INTERLACED_ME){ - int dir, j; - for(dir=0; dir<2; dir++){ - for(i=0; i<2; i++){ - for(j=0; j<2; j++){ - int type= dir ? (CANDIDATE_MB_TYPE_BACKWARD_I|CANDIDATE_MB_TYPE_BIDIR_I) - : (CANDIDATE_MB_TYPE_FORWARD_I |CANDIDATE_MB_TYPE_BIDIR_I); - ff_fix_long_mvs(s, s->b_field_select_table[dir][i], j, - s->b_field_mv_table[dir][i][j], dir ? s->b_code : s->f_code, type, 1); - } - } - } - } - } - } - - if (estimate_qp(s, 0) < 0) - return -1; - - if(s->qscale < 3 && s->max_qcoeff<=128 && s->pict_type==I_TYPE && !(s->flags & CODEC_FLAG_QSCALE)) - s->qscale= 3; //reduce clipping problems - - if (s->out_format == FMT_MJPEG) { - /* for mjpeg, we do include qscale in the matrix */ - s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0]; - for(i=1;i<64;i++){ - int j= s->dsp.idct_permutation[i]; - - s->intra_matrix[j] = av_clip_uint8((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); - } - convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, - s->intra_matrix, s->intra_quant_bias, 8, 8, 1); - s->qscale= 8; - } - - //FIXME var duplication - s->current_picture_ptr->key_frame= - s->current_picture.key_frame= s->pict_type == I_TYPE; //FIXME pic_ptr - s->current_picture_ptr->pict_type= - s->current_picture.pict_type= s->pict_type; - - if(s->current_picture.key_frame) - s->picture_in_gop_number=0; - - s->last_bits= put_bits_count(&s->pb); - switch(s->out_format) { - case FMT_MJPEG: - mjpeg_picture_header(s); - break; -#ifdef CONFIG_H261_ENCODER - case FMT_H261: - ff_h261_encode_picture_header(s, picture_number); - break; -#endif - case FMT_H263: - if (s->codec_id == CODEC_ID_WMV2) - ff_wmv2_encode_picture_header(s, picture_number); - else if (s->h263_msmpeg4) - msmpeg4_encode_picture_header(s, picture_number); - else if (s->h263_pred) - mpeg4_encode_picture_header(s, picture_number); -#ifdef CONFIG_RV10_ENCODER - else if (s->codec_id == CODEC_ID_RV10) - rv10_encode_picture_header(s, picture_number); -#endif -#ifdef CONFIG_RV20_ENCODER - else if (s->codec_id == CODEC_ID_RV20) - rv20_encode_picture_header(s, picture_number); -#endif - else if (s->codec_id == CODEC_ID_FLV1) - ff_flv_encode_picture_header(s, picture_number); - else - h263_encode_picture_header(s, picture_number); - break; - case FMT_MPEG1: - mpeg1_encode_picture_header(s, picture_number); - break; - case FMT_H264: - break; - default: - assert(0); - } - bits= put_bits_count(&s->pb); - s->header_bits= bits - s->last_bits; - - for(i=1; iavctx->thread_count; i++){ - update_duplicate_context_after_me(s->thread_context[i], s); - } - s->avctx->execute(s->avctx, encode_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count); - for(i=1; iavctx->thread_count; i++){ - merge_context_after_encode(s, s->thread_context[i]); - } - emms_c(); - return 0; -} - -static void denoise_dct_c(MpegEncContext *s, DCTELEM *block){ - const int intra= s->mb_intra; - int i; - - s->dct_count[intra]++; - - for(i=0; i<64; i++){ - int level= block[i]; - - if(level){ - if(level>0){ - s->dct_error_sum[intra][i] += level; - level -= s->dct_offset[intra][i]; - if(level<0) level=0; - }else{ - s->dct_error_sum[intra][i] -= level; - level += s->dct_offset[intra][i]; - if(level>0) level=0; - } - block[i]= level; - } - } -} - -static int dct_quantize_trellis_c(MpegEncContext *s, - DCTELEM *block, int n, - int qscale, int *overflow){ - const int *qmat; - const uint8_t *scantable= s->intra_scantable.scantable; - const uint8_t *perm_scantable= s->intra_scantable.permutated; - int max=0; - unsigned int threshold1, threshold2; - int bias=0; - int run_tab[65]; - int level_tab[65]; - int score_tab[65]; - int survivor[65]; - int survivor_count; - int last_run=0; - int last_level=0; - int last_score= 0; - int last_i; - int coeff[2][64]; - int coeff_count[64]; - int qmul, qadd, start_i, last_non_zero, i, dc; - const int esc_length= s->ac_esc_length; - uint8_t * length; - uint8_t * last_length; - const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6); - - s->dsp.fdct (block); - - if(s->dct_error_sum) - s->denoise_dct(s, block); - qmul= qscale*16; - qadd= ((qscale-1)|1)*8; - - if (s->mb_intra) { - int q; - if (!s->h263_aic) { - if (n < 4) - q = s->y_dc_scale; - else - q = s->c_dc_scale; - q = q << 3; - } else{ - /* For AIC we skip quant/dequant of INTRADC */ - q = 1 << 3; - qadd=0; - } - - /* note: block[0] is assumed to be positive */ - block[0] = (block[0] + (q >> 1)) / q; - start_i = 1; - last_non_zero = 0; - qmat = s->q_intra_matrix[qscale]; - if(s->mpeg_quant || s->out_format == FMT_MPEG1) - bias= 1<<(QMAT_SHIFT-1); - length = s->intra_ac_vlc_length; - last_length= s->intra_ac_vlc_last_length; - } else { - start_i = 0; - last_non_zero = -1; - qmat = s->q_inter_matrix[qscale]; - length = s->inter_ac_vlc_length; - last_length= s->inter_ac_vlc_last_length; - } - last_i= start_i; - - threshold1= (1<=start_i; i--) { - const int j = scantable[i]; - int level = block[j] * qmat[j]; - - if(((unsigned)(level+threshold1))>threshold2){ - last_non_zero = i; - break; - } - } - - for(i=start_i; i<=last_non_zero; i++) { - const int j = scantable[i]; - int level = block[j] * qmat[j]; - -// if( bias+level >= (1<<(QMAT_SHIFT - 3)) -// || bias-level >= (1<<(QMAT_SHIFT - 3))){ - if(((unsigned)(level+threshold1))>threshold2){ - if(level>0){ - level= (bias + level)>>QMAT_SHIFT; - coeff[0][i]= level; - coeff[1][i]= level-1; -// coeff[2][k]= level-2; - }else{ - level= (bias - level)>>QMAT_SHIFT; - coeff[0][i]= -level; - coeff[1][i]= -level+1; -// coeff[2][k]= -level+2; - } - coeff_count[i]= FFMIN(level, 2); - assert(coeff_count[i]); - max |=level; - }else{ - coeff[0][i]= (level>>31)|1; - coeff_count[i]= 1; - } - } - - *overflow= s->max_qcoeff < max; //overflow might have happened - - if(last_non_zero < start_i){ - memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM)); - return last_non_zero; - } - - score_tab[start_i]= 0; - survivor[0]= start_i; - survivor_count= 1; - - for(i=start_i; i<=last_non_zero; i++){ - int level_index, j; - const int dct_coeff= FFABS(block[ scantable[i] ]); - const int zero_distoration= dct_coeff*dct_coeff; - int best_score=256*256*256*120; - for(level_index=0; level_index < coeff_count[i]; level_index++){ - int distoration; - int level= coeff[level_index][i]; - const int alevel= FFABS(level); - int unquant_coeff; - - assert(level); - - if(s->out_format == FMT_H263){ - unquant_coeff= alevel*qmul + qadd; - }else{ //MPEG1 - j= s->dsp.idct_permutation[ scantable[i] ]; //FIXME optimize - if(s->mb_intra){ - unquant_coeff = (int)( alevel * qscale * s->intra_matrix[j]) >> 3; - unquant_coeff = (unquant_coeff - 1) | 1; - }else{ - unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->inter_matrix[j])) >> 4; - unquant_coeff = (unquant_coeff - 1) | 1; - } - unquant_coeff<<= 3; - } - - distoration= (unquant_coeff - dct_coeff) * (unquant_coeff - dct_coeff) - zero_distoration; - level+=64; - if((level&(~127)) == 0){ - for(j=survivor_count-1; j>=0; j--){ - int run= i - survivor[j]; - int score= distoration + length[UNI_AC_ENC_INDEX(run, level)]*lambda; - score += score_tab[i-run]; - - if(score < best_score){ - best_score= score; - run_tab[i+1]= run; - level_tab[i+1]= level-64; - } - } - - if(s->out_format == FMT_H263){ - for(j=survivor_count-1; j>=0; j--){ - int run= i - survivor[j]; - int score= distoration + last_length[UNI_AC_ENC_INDEX(run, level)]*lambda; - score += score_tab[i-run]; - if(score < last_score){ - last_score= score; - last_run= run; - last_level= level-64; - last_i= i+1; - } - } - } - }else{ - distoration += esc_length*lambda; - for(j=survivor_count-1; j>=0; j--){ - int run= i - survivor[j]; - int score= distoration + score_tab[i-run]; - - if(score < best_score){ - best_score= score; - run_tab[i+1]= run; - level_tab[i+1]= level-64; - } - } - - if(s->out_format == FMT_H263){ - for(j=survivor_count-1; j>=0; j--){ - int run= i - survivor[j]; - int score= distoration + score_tab[i-run]; - if(score < last_score){ - last_score= score; - last_run= run; - last_level= level-64; - last_i= i+1; - } - } - } - } - } - - score_tab[i+1]= best_score; - - //Note: there is a vlc code in mpeg4 which is 1 bit shorter then another one with a shorter run and the same level - if(last_non_zero <= 27){ - for(; survivor_count; survivor_count--){ - if(score_tab[ survivor[survivor_count-1] ] <= best_score) - break; - } - }else{ - for(; survivor_count; survivor_count--){ - if(score_tab[ survivor[survivor_count-1] ] <= best_score + lambda) - break; - } - } - - survivor[ survivor_count++ ]= i+1; - } - - if(s->out_format != FMT_H263){ - last_score= 256*256*256*120; - for(i= survivor[0]; i<=last_non_zero + 1; i++){ - int score= score_tab[i]; - if(i) score += lambda*2; //FIXME exacter? - - if(score < last_score){ - last_score= score; - last_i= i; - last_level= level_tab[i]; - last_run= run_tab[i]; - } - } - } - - s->coded_score[n] = last_score; - - dc= FFABS(block[0]); - last_non_zero= last_i - 1; - memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM)); - - if(last_non_zero < start_i) - return last_non_zero; - - if(last_non_zero == 0 && start_i == 0){ - int best_level= 0; - int best_score= dc * dc; - - for(i=0; iout_format == FMT_H263){ - unquant_coeff= (alevel*qmul + qadd)>>3; - }else{ //MPEG1 - unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->inter_matrix[0])) >> 4; - unquant_coeff = (unquant_coeff - 1) | 1; - } - unquant_coeff = (unquant_coeff + 4) >> 3; - unquant_coeff<<= 3 + 3; - - distortion= (unquant_coeff - dc) * (unquant_coeff - dc); - level+=64; - if((level&(~127)) == 0) score= distortion + last_length[UNI_AC_ENC_INDEX(0, level)]*lambda; - else score= distortion + esc_length*lambda; - - if(score < best_score){ - best_score= score; - best_level= level - 64; - } - } - block[0]= best_level; - s->coded_score[n] = best_score - dc*dc; - if(best_level == 0) return -1; - else return last_non_zero; - } - - i= last_i; - assert(last_level); - - block[ perm_scantable[last_non_zero] ]= last_level; - i -= last_run + 1; - - for(; i>start_i; i -= run_tab[i] + 1){ - block[ perm_scantable[i-1] ]= level_tab[i]; - } - - return last_non_zero; -} - -//#define REFINE_STATS 1 -static int16_t basis[64][64]; - -static void build_basis(uint8_t *perm){ - int i, j, x, y; - emms_c(); - for(i=0; i<8; i++){ - for(j=0; j<8; j++){ - for(y=0; y<8; y++){ - for(x=0; x<8; x++){ - double s= 0.25*(1<intra_scantable.scantable; - const uint8_t *perm_scantable= s->intra_scantable.permutated; -// unsigned int threshold1, threshold2; -// int bias=0; - int run_tab[65]; - int prev_run=0; - int prev_level=0; - int qmul, qadd, start_i, last_non_zero, i, dc; - uint8_t * length; - uint8_t * last_length; - int lambda; - int rle_index, run, q = 1, sum; //q is only used when s->mb_intra is true -#ifdef REFINE_STATS -static int count=0; -static int after_last=0; -static int to_zero=0; -static int from_zero=0; -static int raise=0; -static int lower=0; -static int messed_sign=0; -#endif - - if(basis[0][0] == 0) - build_basis(s->dsp.idct_permutation); - - qmul= qscale*2; - qadd= (qscale-1)|1; - if (s->mb_intra) { - if (!s->h263_aic) { - if (n < 4) - q = s->y_dc_scale; - else - q = s->c_dc_scale; - } else{ - /* For AIC we skip quant/dequant of INTRADC */ - q = 1; - qadd=0; - } - q <<= RECON_SHIFT-3; - /* note: block[0] is assumed to be positive */ - dc= block[0]*q; -// block[0] = (block[0] + (q >> 1)) / q; - start_i = 1; - qmat = s->q_intra_matrix[qscale]; -// if(s->mpeg_quant || s->out_format == FMT_MPEG1) -// bias= 1<<(QMAT_SHIFT-1); - length = s->intra_ac_vlc_length; - last_length= s->intra_ac_vlc_last_length; - } else { - dc= 0; - start_i = 0; - qmat = s->q_inter_matrix[qscale]; - length = s->inter_ac_vlc_length; - last_length= s->inter_ac_vlc_last_length; - } - last_non_zero = s->block_last_index[n]; - -#ifdef REFINE_STATS -{START_TIMER -#endif - dc += (1<<(RECON_SHIFT-1)); - for(i=0; i<64; i++){ - rem[i]= dc - (orig[i]<0); - assert(w<(1<<6)); - sum += w*w; - } - lambda= sum*(uint64_t)s->lambda2 >> (FF_LAMBDA_SHIFT - 6 + 6 + 6 + 6); -#ifdef REFINE_STATS -{START_TIMER -#endif - run=0; - rle_index=0; - for(i=start_i; i<=last_non_zero; i++){ - int j= perm_scantable[i]; - const int level= block[j]; - int coeff; - - if(level){ - if(level<0) coeff= qmul*level - qadd; - else coeff= qmul*level + qadd; - run_tab[rle_index++]=run; - run=0; - - s->dsp.add_8x8basis(rem, basis[j], coeff); - }else{ - run++; - } - } -#ifdef REFINE_STATS -if(last_non_zero>0){ -STOP_TIMER("init rem[]") -} -} - -{START_TIMER -#endif - for(;;){ - int best_score=s->dsp.try_8x8basis(rem, weight, basis[0], 0); - int best_coeff=0; - int best_change=0; - int run2, best_unquant_change=0, analyze_gradient; -#ifdef REFINE_STATS -{START_TIMER -#endif - analyze_gradient = last_non_zero > 2 || s->avctx->quantizer_noise_shaping >= 3; - - if(analyze_gradient){ -#ifdef REFINE_STATS -{START_TIMER -#endif - for(i=0; i<64; i++){ - int w= weight[i]; - - d1[i] = (rem[i]*w*w + (1<<(RECON_SHIFT+12-1)))>>(RECON_SHIFT+12); - } -#ifdef REFINE_STATS -STOP_TIMER("rem*w*w")} -{START_TIMER -#endif - s->dsp.fdct(d1); -#ifdef REFINE_STATS -STOP_TIMER("dct")} -#endif - } - - if(start_i){ - const int level= block[0]; - int change, old_coeff; - - assert(s->mb_intra); - - old_coeff= q*level; - - for(change=-1; change<=1; change+=2){ - int new_level= level + change; - int score, new_coeff; - - new_coeff= q*new_level; - if(new_coeff >= 2048 || new_coeff < 0) - continue; - - score= s->dsp.try_8x8basis(rem, weight, basis[0], new_coeff - old_coeff); - if(scoreavctx->quantizer_noise_shaping < 3 && i > last_non_zero + 1) - break; - - if(level){ - if(level<0) old_coeff= qmul*level - qadd; - else old_coeff= qmul*level + qadd; - run2= run_tab[rle_index++]; //FIXME ! maybe after last - }else{ - old_coeff=0; - run2--; - assert(run2>=0 || i >= last_non_zero ); - } - - for(change=-1; change<=1; change+=2){ - int new_level= level + change; - int score, new_coeff, unquant_change; - - score=0; - if(s->avctx->quantizer_noise_shaping < 2 && FFABS(new_level) > FFABS(level)) - continue; - - if(new_level){ - if(new_level<0) new_coeff= qmul*new_level - qadd; - else new_coeff= qmul*new_level + qadd; - if(new_coeff >= 2048 || new_coeff <= -2048) - continue; - //FIXME check for overflow - - if(level){ - if(level < 63 && level > -63){ - if(i < last_non_zero) - score += length[UNI_AC_ENC_INDEX(run, new_level+64)] - - length[UNI_AC_ENC_INDEX(run, level+64)]; - else - score += last_length[UNI_AC_ENC_INDEX(run, new_level+64)] - - last_length[UNI_AC_ENC_INDEX(run, level+64)]; - } - }else{ - assert(FFABS(new_level)==1); - - if(analyze_gradient){ - int g= d1[ scantable[i] ]; - if(g && (g^new_level) >= 0) - continue; - } - - if(i < last_non_zero){ - int next_i= i + run2 + 1; - int next_level= block[ perm_scantable[next_i] ] + 64; - - if(next_level&(~127)) - next_level= 0; - - if(next_i < last_non_zero) - score += length[UNI_AC_ENC_INDEX(run, 65)] - + length[UNI_AC_ENC_INDEX(run2, next_level)] - - length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)]; - else - score += length[UNI_AC_ENC_INDEX(run, 65)] - + last_length[UNI_AC_ENC_INDEX(run2, next_level)] - - last_length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)]; - }else{ - score += last_length[UNI_AC_ENC_INDEX(run, 65)]; - if(prev_level){ - score += length[UNI_AC_ENC_INDEX(prev_run, prev_level)] - - last_length[UNI_AC_ENC_INDEX(prev_run, prev_level)]; - } - } - } - }else{ - new_coeff=0; - assert(FFABS(level)==1); - - if(i < last_non_zero){ - int next_i= i + run2 + 1; - int next_level= block[ perm_scantable[next_i] ] + 64; - - if(next_level&(~127)) - next_level= 0; - - if(next_i < last_non_zero) - score += length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)] - - length[UNI_AC_ENC_INDEX(run2, next_level)] - - length[UNI_AC_ENC_INDEX(run, 65)]; - else - score += last_length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)] - - last_length[UNI_AC_ENC_INDEX(run2, next_level)] - - length[UNI_AC_ENC_INDEX(run, 65)]; - }else{ - score += -last_length[UNI_AC_ENC_INDEX(run, 65)]; - if(prev_level){ - score += last_length[UNI_AC_ENC_INDEX(prev_run, prev_level)] - - length[UNI_AC_ENC_INDEX(prev_run, prev_level)]; - } - } - } - - score *= lambda; - - unquant_change= new_coeff - old_coeff; - assert((score < 100*lambda && score > -100*lambda) || lambda==0); - - score+= s->dsp.try_8x8basis(rem, weight, basis[j], unquant_change); - if(score last_non_zero){ - last_non_zero= best_coeff; - assert(block[j]); -#ifdef REFINE_STATS -after_last++; -#endif - }else{ -#ifdef REFINE_STATS -if(block[j]){ - if(block[j] - best_change){ - if(FFABS(block[j]) > FFABS(block[j] - best_change)){ - raise++; - }else{ - lower++; - } - }else{ - from_zero++; - } -}else{ - to_zero++; -} -#endif - for(; last_non_zero>=start_i; last_non_zero--){ - if(block[perm_scantable[last_non_zero]]) - break; - } - } -#ifdef REFINE_STATS -count++; -if(256*256*256*64 % count == 0){ - printf("after_last:%d to_zero:%d from_zero:%d raise:%d lower:%d sign:%d xyp:%d/%d/%d\n", after_last, to_zero, from_zero, raise, lower, messed_sign, s->mb_x, s->mb_y, s->picture_number); -} -#endif - run=0; - rle_index=0; - for(i=start_i; i<=last_non_zero; i++){ - int j= perm_scantable[i]; - const int level= block[j]; - - if(level){ - run_tab[rle_index++]=run; - run=0; - }else{ - run++; - } - } - - s->dsp.add_8x8basis(rem, basis[j], best_unquant_change); - }else{ - break; - } - } -#ifdef REFINE_STATS -if(last_non_zero>0){ -STOP_TIMER("iterative search") -} -} -#endif - - return last_non_zero; -} - -static int dct_quantize_c(MpegEncContext *s, - DCTELEM *block, int n, - int qscale, int *overflow) -{ - int i, j, level, last_non_zero, q, start_i; - const int *qmat; - const uint8_t *scantable= s->intra_scantable.scantable; - int bias; - int max=0; - unsigned int threshold1, threshold2; - - s->dsp.fdct (block); - - if(s->dct_error_sum) - s->denoise_dct(s, block); - - if (s->mb_intra) { - if (!s->h263_aic) { - if (n < 4) - q = s->y_dc_scale; - else - q = s->c_dc_scale; - q = q << 3; - } else - /* For AIC we skip quant/dequant of INTRADC */ - q = 1 << 3; - - /* note: block[0] is assumed to be positive */ - block[0] = (block[0] + (q >> 1)) / q; - start_i = 1; - last_non_zero = 0; - qmat = s->q_intra_matrix[qscale]; - bias= s->intra_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT); - } else { - start_i = 0; - last_non_zero = -1; - qmat = s->q_inter_matrix[qscale]; - bias= s->inter_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT); - } - threshold1= (1<=start_i;i--) { - j = scantable[i]; - level = block[j] * qmat[j]; - - if(((unsigned)(level+threshold1))>threshold2){ - last_non_zero = i; - break; - }else{ - block[j]=0; - } - } - for(i=start_i; i<=last_non_zero; i++) { - j = scantable[i]; - level = block[j] * qmat[j]; - -// if( bias+level >= (1<= (1<threshold2){ - if(level>0){ - level= (bias + level)>>QMAT_SHIFT; - block[j]= level; - }else{ - level= (bias - level)>>QMAT_SHIFT; - block[j]= -level; - } - max |=level; - }else{ - block[j]=0; - } - } - *overflow= s->max_qcoeff < max; //overflow might have happened - - /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */ - if (s->dsp.idct_permutation_type != FF_NO_IDCT_PERM) - ff_block_permute(block, s->dsp.idct_permutation, scantable, last_non_zero); - - return last_non_zero; -} - -#endif //CONFIG_ENCODERS - -static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s, - DCTELEM *block, int n, int qscale) -{ - int i, level, nCoeffs; - const uint16_t *quant_matrix; - - nCoeffs= s->block_last_index[n]; - - if (n < 4) - block[0] = block[0] * s->y_dc_scale; - else - block[0] = block[0] * s->c_dc_scale; - /* XXX: only mpeg1 */ - quant_matrix = s->intra_matrix; - for(i=1;i<=nCoeffs;i++) { - int j= s->intra_scantable.permutated[i]; - level = block[j]; - if (level) { - if (level < 0) { - level = -level; - level = (int)(level * qscale * quant_matrix[j]) >> 3; - level = (level - 1) | 1; - level = -level; - } else { - level = (int)(level * qscale * quant_matrix[j]) >> 3; - level = (level - 1) | 1; - } - block[j] = level; - } + if (n < 4) + block[0] = block[0] * s->y_dc_scale; + else + block[0] = block[0] * s->c_dc_scale; + /* XXX: only mpeg1 */ + quant_matrix = s->intra_matrix; + for(i=1;i<=nCoeffs;i++) { + int j= s->intra_scantable.permutated[i]; + level = block[j]; + if (level) { + if (level < 0) { + level = -level; + level = (int)(level * qscale * quant_matrix[j]) >> 3; + level = (level - 1) | 1; + level = -level; + } else { + level = (int)(level * qscale * quant_matrix[j]) >> 3; + level = (level - 1) | 1; + } + block[j] = level; + } } } @@ -6823,127 +2411,19 @@ static void dct_unquantize_h263_inter_c(MpegEncContext *s, } } -#ifdef CONFIG_ENCODERS -AVCodec h263_encoder = { - "h263", - CODEC_TYPE_VIDEO, - CODEC_ID_H263, - sizeof(MpegEncContext), - MPV_encode_init, - MPV_encode_picture, - MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, -}; - -AVCodec h263p_encoder = { - "h263p", - CODEC_TYPE_VIDEO, - CODEC_ID_H263P, - sizeof(MpegEncContext), - MPV_encode_init, - MPV_encode_picture, - MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, -}; - -AVCodec flv_encoder = { - "flv", - CODEC_TYPE_VIDEO, - CODEC_ID_FLV1, - sizeof(MpegEncContext), - MPV_encode_init, - MPV_encode_picture, - MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, -}; - -AVCodec rv10_encoder = { - "rv10", - CODEC_TYPE_VIDEO, - CODEC_ID_RV10, - sizeof(MpegEncContext), - MPV_encode_init, - MPV_encode_picture, - MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, -}; - -AVCodec rv20_encoder = { - "rv20", - CODEC_TYPE_VIDEO, - CODEC_ID_RV20, - sizeof(MpegEncContext), - MPV_encode_init, - MPV_encode_picture, - MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, -}; - -AVCodec mpeg4_encoder = { - "mpeg4", - CODEC_TYPE_VIDEO, - CODEC_ID_MPEG4, - sizeof(MpegEncContext), - MPV_encode_init, - MPV_encode_picture, - MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, - .capabilities= CODEC_CAP_DELAY, -}; - -AVCodec msmpeg4v1_encoder = { - "msmpeg4v1", - CODEC_TYPE_VIDEO, - CODEC_ID_MSMPEG4V1, - sizeof(MpegEncContext), - MPV_encode_init, - MPV_encode_picture, - MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, -}; - -AVCodec msmpeg4v2_encoder = { - "msmpeg4v2", - CODEC_TYPE_VIDEO, - CODEC_ID_MSMPEG4V2, - sizeof(MpegEncContext), - MPV_encode_init, - MPV_encode_picture, - MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, -}; - -AVCodec msmpeg4v3_encoder = { - "msmpeg4", - CODEC_TYPE_VIDEO, - CODEC_ID_MSMPEG4V3, - sizeof(MpegEncContext), - MPV_encode_init, - MPV_encode_picture, - MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, -}; - -AVCodec wmv1_encoder = { - "wmv1", - CODEC_TYPE_VIDEO, - CODEC_ID_WMV1, - sizeof(MpegEncContext), - MPV_encode_init, - MPV_encode_picture, - MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, -}; +/** + * set qscale and update qscale dependent variables. + */ +void ff_set_qscale(MpegEncContext * s, int qscale) +{ + if (qscale < 1) + qscale = 1; + else if (qscale > 31) + qscale = 31; -AVCodec mjpeg_encoder = { - "mjpeg", - CODEC_TYPE_VIDEO, - CODEC_ID_MJPEG, - sizeof(MpegEncContext), - MPV_encode_init, - MPV_encode_picture, - MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, -1}, -}; + s->qscale = qscale; + s->chroma_qscale= s->chroma_qscale_table[qscale]; -#endif //CONFIG_ENCODERS + s->y_dc_scale= s->y_dc_scale_table[ qscale ]; + s->c_dc_scale= s->c_dc_scale_table[ s->chroma_qscale ]; +} diff --git a/contrib/ffmpeg/libavcodec/mpegvideo.h b/contrib/ffmpeg/libavcodec/mpegvideo.h index 80e0f9065..37c60ca57 100644 --- a/contrib/ffmpeg/libavcodec/mpegvideo.h +++ b/contrib/ffmpeg/libavcodec/mpegvideo.h @@ -25,8 +25,8 @@ * mpegvideo header. */ -#ifndef AVCODEC_MPEGVIDEO_H -#define AVCODEC_MPEGVIDEO_H +#ifndef FFMPEG_MPEGVIDEO_H +#define FFMPEG_MPEGVIDEO_H #include "dsputil.h" #include "bitstream.h" @@ -76,6 +76,16 @@ enum OutputFormat { #define INPLACE_OFFSET 16 +/* Start codes. */ +#define SEQ_END_CODE 0x000001b7 +#define SEQ_START_CODE 0x000001b3 +#define GOP_START_CODE 0x000001b8 +#define PICTURE_START_CODE 0x00000100 +#define SLICE_MIN_START_CODE 0x00000101 +#define SLICE_MAX_START_CODE 0x000001af +#define EXT_START_CODE 0x000001b5 +#define USER_START_CODE 0x000001b2 + /** * Scantable. */ @@ -84,7 +94,7 @@ typedef struct ScanTable{ uint8_t permutated[64]; uint8_t raster_end[64]; #ifdef ARCH_POWERPC - /** Used by dct_quantise_alitvec to find last-non-zero */ + /** Used by dct_quantize_altivec to find last-non-zero */ DECLARE_ALIGNED_8(uint8_t, inverse[64]); #endif } ScanTable; @@ -101,7 +111,7 @@ typedef struct Picture{ uint8_t *interpolated[3]; int16_t (*motion_val_base[2])[2]; uint32_t *mb_type_base; -#define MB_TYPE_INTRA MB_TYPE_INTRA4x4 //default mb_type if theres just one type +#define MB_TYPE_INTRA MB_TYPE_INTRA4x4 //default mb_type if there is just one type #define IS_INTRA4x4(a) ((a)&MB_TYPE_INTRA4x4) #define IS_INTRA16x16(a) ((a)&MB_TYPE_INTRA16x16) #define IS_PCM(a) ((a)&MB_TYPE_INTRA_PCM) @@ -123,13 +133,14 @@ typedef struct Picture{ #define IS_ACPRED(a) ((a)&MB_TYPE_ACPRED) #define IS_QUANT(a) ((a)&MB_TYPE_QUANT) #define IS_DIR(a, part, list) ((a) & (MB_TYPE_P0L0<<((part)+2*(list)))) -#define USES_LIST(a, list) ((a) & ((MB_TYPE_P0L0|MB_TYPE_P1L0)<<(2*(list)))) ///< does this mb use listX, note doesnt work if subMBs +#define USES_LIST(a, list) ((a) & ((MB_TYPE_P0L0|MB_TYPE_P1L0)<<(2*(list)))) ///< does this mb use listX, note does not work if subMBs #define HAS_CBP(a) ((a)&MB_TYPE_CBP) int field_poc[2]; ///< h264 top/bottom POC int poc; ///< h264 frame POC - int frame_num; ///< h264 frame_num - int pic_id; ///< h264 pic_num or long_term_pic_idx + int frame_num; ///< h264 frame_num (raw frame_num from slice header) + int pic_id; /**< h264 pic_num (short -> no wrap version of pic_num, + pic_num & max_pic_num; long -> long_pic_num) */ int long_ref; ///< 1->long term reference 0->short term reference int ref_poc[2][16]; ///< h264 POCs of the frames used as reference int ref_count[2]; ///< number of entries in ref_poc @@ -151,9 +162,9 @@ struct MpegEncContext; typedef struct MotionEstContext{ AVCodecContext *avctx; int skip; ///< set if ME is skipped for the current MB - int co_located_mv[4][2]; ///< mv from last p frame for direct mode ME + int co_located_mv[4][2]; ///< mv from last P-frame for direct mode ME int direct_basis_mv[4][2]; - uint8_t *scratchpad; ///< data area for the me algo, so that the ME doesnt need to malloc/free + uint8_t *scratchpad; ///< data area for the ME algo, so that the ME does not need to malloc/free uint8_t *best_mb; uint8_t *temp_mb[2]; uint8_t *temp; @@ -238,8 +249,8 @@ typedef struct MpegEncContext { /* sequence parameters */ int context_initialized; - int input_picture_number; ///< used to set pic->display_picture_number, shouldnt be used for/by anything else - int coded_picture_number; ///< used to set pic->coded_picture_number, shouldnt be used for/by anything else + int input_picture_number; ///< used to set pic->display_picture_number, should not be used for/by anything else + int coded_picture_number; ///< used to set pic->coded_picture_number, should not be used for/by anything else int picture_number; //FIXME remove, unclear definition int picture_in_gop_number; ///< 0-> first pic in gop, ... int b_frames_since_non_b; ///< used for encoding, relative to not yet reordered input @@ -358,8 +369,8 @@ typedef struct MpegEncContext { uint8_t (*b_field_select_table[2][2]); int me_method; ///< ME algorithm int mv_dir; -#define MV_DIR_BACKWARD 1 -#define MV_DIR_FORWARD 2 +#define MV_DIR_FORWARD 1 +#define MV_DIR_BACKWARD 2 #define MV_DIRECT 4 ///< bidirectional mode where the difference equals the MV of the last P/S/I-Frame (mpeg4) int mv_type; #define MV_TYPE_16X16 0 ///< 1 vector for the whole mb @@ -381,7 +392,7 @@ typedef struct MpegEncContext { MotionEstContext me; int no_rounding; /**< apply no rounding to motion compensation (MPEG4, msmpeg4, ...) - for b-frames rounding mode is allways 0 */ + for b-frames rounding mode is always 0 */ int hurry_up; /**< when set to 1 during decoding, b frames will be skipped when set to 2 idct/dequant will be skipped too */ @@ -579,8 +590,6 @@ typedef struct MpegEncContext { struct MJpegContext *mjpeg_ctx; int mjpeg_vsample[3]; ///< vertical sampling factors, default = {2, 1, 1} int mjpeg_hsample[3]; ///< horizontal sampling factors, default = {2, 1, 1} - int mjpeg_write_tables; ///< do we want to have quantisation- and huffmantables in the jpeg file ? - int mjpeg_data_only_frames; ///< frames only with SOI, SOS and EOI markers /* MSMPEG4 specific */ int mv_table_index; @@ -681,7 +690,6 @@ typedef struct MpegEncContext { } MpegEncContext; -int DCT_common_init(MpegEncContext *s); void MPV_decode_defaults(MpegEncContext *s); int MPV_common_init(MpegEncContext *s); void MPV_common_end(MpegEncContext *s); @@ -691,26 +699,13 @@ void MPV_frame_end(MpegEncContext *s); int MPV_encode_init(AVCodecContext *avctx); int MPV_encode_end(AVCodecContext *avctx); int MPV_encode_picture(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data); -#ifdef HAVE_MMX void MPV_common_init_mmx(MpegEncContext *s); -#endif -#ifdef ARCH_ALPHA void MPV_common_init_axp(MpegEncContext *s); -#endif -#ifdef HAVE_MLIB void MPV_common_init_mlib(MpegEncContext *s); -#endif -#ifdef HAVE_MMI void MPV_common_init_mmi(MpegEncContext *s); -#endif -#ifdef ARCH_ARMV4L void MPV_common_init_armv4l(MpegEncContext *s); -#endif -#ifdef ARCH_POWERPC -void MPV_common_init_ppc(MpegEncContext *s); -#endif +void MPV_common_init_altivec(MpegEncContext *s); extern void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w); -void ff_copy_bits(PutBitContext *pb, uint8_t *src, int length); void ff_clean_intra_table_entries(MpegEncContext *s); void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable); void ff_draw_horiz_band(MpegEncContext *s, int y, int h); @@ -728,8 +723,9 @@ void ff_er_frame_start(MpegEncContext *s); void ff_er_frame_end(MpegEncContext *s); void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status); - -extern enum PixelFormat ff_yuv420p_list[2]; +int ff_dct_common_init(MpegEncContext *s); +void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64], + const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra); void ff_init_block_index(MpegEncContext *s); @@ -756,6 +752,14 @@ static inline int get_bits_diff(MpegEncContext *s){ return bits - last; } +static inline int ff_h263_round_chroma(int x){ + static const uint8_t h263_chroma_roundtab[16] = { + // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 + 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, + }; + return h263_chroma_roundtab[x & 0xf] + (x >> 3); +} + /* motion_est.c */ void ff_estimate_p_frame_motion(MpegEncContext * s, int mb_x, int mb_y); @@ -767,16 +771,17 @@ void ff_fix_long_mvs(MpegEncContext * s, uint8_t *field_select_table, int field_ int16_t (*mv_table)[2], int f_code, int type, int truncate); void ff_init_me(MpegEncContext *s); int ff_pre_estimate_p_frame_motion(MpegEncContext * s, int mb_x, int mb_y); -inline int ff_epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr, +int ff_epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2], int ref_mv_scale, int size, int h); -inline int ff_get_mb_score(MpegEncContext * s, int mx, int my, int src_index, +int ff_get_mb_score(MpegEncContext * s, int mx, int my, int src_index, int ref_index, int size, int h, int add_rate); /* mpeg12.c */ extern const uint16_t ff_mpeg1_default_intra_matrix[64]; extern const uint16_t ff_mpeg1_default_non_intra_matrix[64]; extern const uint8_t ff_mpeg1_dc_scale_table[128]; +extern const AVRational ff_frame_rate_tab[]; void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number); void mpeg1_encode_mb(MpegEncContext *s, @@ -785,6 +790,7 @@ void mpeg1_encode_mb(MpegEncContext *s, void ff_mpeg1_encode_init(MpegEncContext *s); void ff_mpeg1_encode_slice_header(MpegEncContext *s); void ff_mpeg1_clean_buffers(MpegEncContext *s); +int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size); #include "rl.h" @@ -811,7 +817,7 @@ int ff_h261_get_picture_format(int width, int height); int ff_h263_decode_init(AVCodecContext *avctx); int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size); + const uint8_t *buf, int buf_size); int ff_h263_decode_end(AVCodecContext *avctx); void h263_encode_mb(MpegEncContext *s, DCTELEM block[6][64], @@ -826,13 +832,9 @@ int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir, int *px, int *py); void mpeg4_pred_ac(MpegEncContext * s, DCTELEM *block, int n, int dir); -void ff_set_mpeg4_time(MpegEncContext * s, int picture_number); +void ff_set_mpeg4_time(MpegEncContext * s); void mpeg4_encode_picture_header(MpegEncContext *s, int picture_number); -#ifdef CONFIG_ENCODERS void h263_encode_init(MpegEncContext *s); -#else -static void h263_encode_init(MpegEncContext *s) {assert(0);} -#endif void h263_decode_init_vlc(MpegEncContext *s); int h263_decode_picture_header(MpegEncContext *s); int ff_h263_decode_gob_header(MpegEncContext *s); @@ -863,7 +865,6 @@ int ff_h263_resync(MpegEncContext *s); int ff_h263_get_gob_height(MpegEncContext *s); void ff_mpeg4_init_direct_mv(MpegEncContext *s); int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my); -int ff_h263_round_chroma(int x); void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code); @@ -895,14 +896,5 @@ void ff_wmv2_encode_mb(MpegEncContext * s, DCTELEM block[6][64], int motion_x, int motion_y); -/* mjpeg.c */ -int mjpeg_init(MpegEncContext *s); -void mjpeg_close(MpegEncContext *s); -void mjpeg_encode_mb(MpegEncContext *s, - DCTELEM block[6][64]); -void mjpeg_picture_header(MpegEncContext *s); -void mjpeg_picture_trailer(MpegEncContext *s); -void ff_mjpeg_stuffing(PutBitContext * pbc); - -#endif /* AVCODEC_MPEGVIDEO_H */ +#endif /* FFMPEG_MPEGVIDEO_H */ diff --git a/contrib/ffmpeg/libavcodec/mpegvideo_common.h b/contrib/ffmpeg/libavcodec/mpegvideo_common.h new file mode 100644 index 000000000..f2655a954 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpegvideo_common.h @@ -0,0 +1,836 @@ +/* + * The simplest mpeg encoder (well, it was the simplest!) + * Copyright (c) 2000,2001 Fabrice Bellard. + * Copyright (c) 2002-2004 Michael Niedermayer + * + * 4MV & hq & B-frame encoding stuff by Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mpegvideo_common.h + * The simplest mpeg encoder (well, it was the simplest!). + */ + +#ifndef FFMPEG_MPEGVIDEO_COMMON_H +#define FFMPEG_MPEGVIDEO_COMMON_H + +#include "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" +#include "mjpegenc.h" +#include "msmpeg4.h" +#include "faandct.h" +#include + +int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); +int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); +void denoise_dct_c(MpegEncContext *s, DCTELEM *block); +void copy_picture(Picture *dst, Picture *src); + +/** + * allocates a Picture + * The pixels are allocated/set by calling get_buffer() if shared=0 + */ +int alloc_picture(MpegEncContext *s, Picture *pic, int shared); + +/** + * sets the given MpegEncContext to common defaults (same for encoding and decoding). + * the changed fields will not depend upon the prior state of the MpegEncContext. + */ +void MPV_common_defaults(MpegEncContext *s); + +static inline void gmc1_motion(MpegEncContext *s, + uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, + uint8_t **ref_picture) +{ + uint8_t *ptr; + int offset, src_x, src_y, linesize, uvlinesize; + int motion_x, motion_y; + int emu=0; + + motion_x= s->sprite_offset[0][0]; + motion_y= s->sprite_offset[0][1]; + src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1)); + src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1)); + motion_x<<=(3-s->sprite_warping_accuracy); + motion_y<<=(3-s->sprite_warping_accuracy); + src_x = av_clip(src_x, -16, s->width); + if (src_x == s->width) + motion_x =0; + src_y = av_clip(src_y, -16, s->height); + if (src_y == s->height) + motion_y =0; + + linesize = s->linesize; + uvlinesize = s->uvlinesize; + + ptr = ref_picture[0] + (src_y * linesize) + src_x; + + if(s->flags&CODEC_FLAG_EMU_EDGE){ + if( (unsigned)src_x >= s->h_edge_pos - 17 + || (unsigned)src_y >= s->v_edge_pos - 17){ + ff_emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos); + ptr= s->edge_emu_buffer; + } + } + + if((motion_x|motion_y)&7){ + s->dsp.gmc1(dest_y , ptr , linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding); + s->dsp.gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding); + }else{ + int dxy; + + dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2); + if (s->no_rounding){ + s->dsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16); + }else{ + s->dsp.put_pixels_tab [0][dxy](dest_y, ptr, linesize, 16); + } + } + + if(ENABLE_GRAY && s->flags&CODEC_FLAG_GRAY) return; + + motion_x= s->sprite_offset[1][0]; + motion_y= s->sprite_offset[1][1]; + src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1)); + src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1)); + motion_x<<=(3-s->sprite_warping_accuracy); + motion_y<<=(3-s->sprite_warping_accuracy); + src_x = av_clip(src_x, -8, s->width>>1); + if (src_x == s->width>>1) + motion_x =0; + src_y = av_clip(src_y, -8, s->height>>1); + if (src_y == s->height>>1) + motion_y =0; + + offset = (src_y * uvlinesize) + src_x; + ptr = ref_picture[1] + offset; + if(s->flags&CODEC_FLAG_EMU_EDGE){ + if( (unsigned)src_x >= (s->h_edge_pos>>1) - 9 + || (unsigned)src_y >= (s->v_edge_pos>>1) - 9){ + ff_emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); + ptr= s->edge_emu_buffer; + emu=1; + } + } + s->dsp.gmc1(dest_cb, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); + + ptr = ref_picture[2] + offset; + if(emu){ + ff_emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); + ptr= s->edge_emu_buffer; + } + s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); + + return; +} + +static inline void gmc_motion(MpegEncContext *s, + uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, + uint8_t **ref_picture) +{ + uint8_t *ptr; + int linesize, uvlinesize; + const int a= s->sprite_warping_accuracy; + int ox, oy; + + linesize = s->linesize; + uvlinesize = s->uvlinesize; + + ptr = ref_picture[0]; + + ox= s->sprite_offset[0][0] + s->sprite_delta[0][0]*s->mb_x*16 + s->sprite_delta[0][1]*s->mb_y*16; + oy= s->sprite_offset[0][1] + s->sprite_delta[1][0]*s->mb_x*16 + s->sprite_delta[1][1]*s->mb_y*16; + + s->dsp.gmc(dest_y, ptr, linesize, 16, + ox, + oy, + s->sprite_delta[0][0], s->sprite_delta[0][1], + s->sprite_delta[1][0], s->sprite_delta[1][1], + a+1, (1<<(2*a+1)) - s->no_rounding, + s->h_edge_pos, s->v_edge_pos); + s->dsp.gmc(dest_y+8, ptr, linesize, 16, + ox + s->sprite_delta[0][0]*8, + oy + s->sprite_delta[1][0]*8, + s->sprite_delta[0][0], s->sprite_delta[0][1], + s->sprite_delta[1][0], s->sprite_delta[1][1], + a+1, (1<<(2*a+1)) - s->no_rounding, + s->h_edge_pos, s->v_edge_pos); + + if(ENABLE_GRAY && s->flags&CODEC_FLAG_GRAY) return; + + ox= s->sprite_offset[1][0] + s->sprite_delta[0][0]*s->mb_x*8 + s->sprite_delta[0][1]*s->mb_y*8; + oy= s->sprite_offset[1][1] + s->sprite_delta[1][0]*s->mb_x*8 + s->sprite_delta[1][1]*s->mb_y*8; + + ptr = ref_picture[1]; + s->dsp.gmc(dest_cb, ptr, uvlinesize, 8, + ox, + oy, + s->sprite_delta[0][0], s->sprite_delta[0][1], + s->sprite_delta[1][0], s->sprite_delta[1][1], + a+1, (1<<(2*a+1)) - s->no_rounding, + s->h_edge_pos>>1, s->v_edge_pos>>1); + + ptr = ref_picture[2]; + s->dsp.gmc(dest_cr, ptr, uvlinesize, 8, + ox, + oy, + s->sprite_delta[0][0], s->sprite_delta[0][1], + s->sprite_delta[1][0], s->sprite_delta[1][1], + a+1, (1<<(2*a+1)) - s->no_rounding, + s->h_edge_pos>>1, s->v_edge_pos>>1); +} + +static inline int hpel_motion(MpegEncContext *s, + uint8_t *dest, uint8_t *src, + int field_based, int field_select, + int src_x, int src_y, + int width, int height, int stride, + int h_edge_pos, int v_edge_pos, + int w, int h, op_pixels_func *pix_op, + int motion_x, int motion_y) +{ + int dxy; + int emu=0; + + dxy = ((motion_y & 1) << 1) | (motion_x & 1); + src_x += motion_x >> 1; + src_y += motion_y >> 1; + + /* WARNING: do no forget half pels */ + src_x = av_clip(src_x, -16, width); //FIXME unneeded for emu? + if (src_x == width) + dxy &= ~1; + src_y = av_clip(src_y, -16, height); + if (src_y == height) + dxy &= ~2; + src += src_y * stride + src_x; + + if(s->unrestricted_mv && (s->flags&CODEC_FLAG_EMU_EDGE)){ + if( (unsigned)src_x > h_edge_pos - (motion_x&1) - w + || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){ + ff_emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<v_edge_pos); + src= s->edge_emu_buffer; + emu=1; + } + } + if(field_select) + src += s->linesize; + pix_op[dxy](dest, src, stride, h); + return emu; +} + +/* apply one mpeg motion vector to the three components */ +static av_always_inline void mpeg_motion(MpegEncContext *s, + uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, + int field_based, int bottom_field, int field_select, + uint8_t **ref_picture, op_pixels_func (*pix_op)[4], + int motion_x, int motion_y, int h) +{ + uint8_t *ptr_y, *ptr_cb, *ptr_cr; + int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize; + +#if 0 +if(s->quarter_sample) +{ + motion_x>>=1; + motion_y>>=1; +} +#endif + + v_edge_pos = s->v_edge_pos >> field_based; + linesize = s->current_picture.linesize[0] << field_based; + uvlinesize = s->current_picture.linesize[1] << field_based; + + dxy = ((motion_y & 1) << 1) | (motion_x & 1); + src_x = s->mb_x* 16 + (motion_x >> 1); + src_y =(s->mb_y<<(4-field_based)) + (motion_y >> 1); + + if (s->out_format == FMT_H263) { + if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){ + mx = (motion_x>>1)|(motion_x&1); + my = motion_y >>1; + uvdxy = ((my & 1) << 1) | (mx & 1); + uvsrc_x = s->mb_x* 8 + (mx >> 1); + uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1); + }else{ + uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1); + uvsrc_x = src_x>>1; + uvsrc_y = src_y>>1; + } + }else if(s->out_format == FMT_H261){//even chroma mv's are full pel in H261 + mx = motion_x / 4; + my = motion_y / 4; + uvdxy = 0; + uvsrc_x = s->mb_x*8 + mx; + uvsrc_y = s->mb_y*8 + my; + } else { + if(s->chroma_y_shift){ + mx = motion_x / 2; + my = motion_y / 2; + uvdxy = ((my & 1) << 1) | (mx & 1); + uvsrc_x = s->mb_x* 8 + (mx >> 1); + uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1); + } else { + if(s->chroma_x_shift){ + //Chroma422 + mx = motion_x / 2; + uvdxy = ((motion_y & 1) << 1) | (mx & 1); + uvsrc_x = s->mb_x* 8 + (mx >> 1); + uvsrc_y = src_y; + } else { + //Chroma444 + uvdxy = dxy; + uvsrc_x = src_x; + uvsrc_y = src_y; + } + } + } + + ptr_y = ref_picture[0] + src_y * linesize + src_x; + ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; + ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; + + if( (unsigned)src_x > s->h_edge_pos - (motion_x&1) - 16 + || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){ + if(s->codec_id == CODEC_ID_MPEG2VIDEO || + s->codec_id == CODEC_ID_MPEG1VIDEO){ + av_log(s->avctx,AV_LOG_DEBUG,"MPEG motion vector out of boundary\n"); + return ; + } + ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based, + src_x, src_y<h_edge_pos, s->v_edge_pos); + ptr_y = s->edge_emu_buffer; + if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ + uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize; + ff_emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based, + uvsrc_x, uvsrc_y<h_edge_pos>>1, s->v_edge_pos>>1); + ff_emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based, + uvsrc_x, uvsrc_y<h_edge_pos>>1, s->v_edge_pos>>1); + ptr_cb= uvbuf; + ptr_cr= uvbuf+16; + } + } + + if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data + dest_y += s->linesize; + dest_cb+= s->uvlinesize; + dest_cr+= s->uvlinesize; + } + + if(field_select){ + ptr_y += s->linesize; + ptr_cb+= s->uvlinesize; + ptr_cr+= s->uvlinesize; + } + + pix_op[0][dxy](dest_y, ptr_y, linesize, h); + + if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ + pix_op[s->chroma_x_shift][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift); + pix_op[s->chroma_x_shift][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift); + } + if((ENABLE_H261_ENCODER || ENABLE_H261_DECODER) && s->out_format == FMT_H261){ + ff_h261_loop_filter(s); + } +} + +//FIXME move to dsputil, avg variant, 16x16 version +static inline void put_obmc(uint8_t *dst, uint8_t *src[5], int stride){ + int x; + uint8_t * const top = src[1]; + uint8_t * const left = src[2]; + uint8_t * const mid = src[0]; + uint8_t * const right = src[3]; + uint8_t * const bottom= src[4]; +#define OBMC_FILTER(x, t, l, m, r, b)\ + dst[x]= (t*top[x] + l*left[x] + m*mid[x] + r*right[x] + b*bottom[x] + 4)>>3 +#define OBMC_FILTER4(x, t, l, m, r, b)\ + OBMC_FILTER(x , t, l, m, r, b);\ + OBMC_FILTER(x+1 , t, l, m, r, b);\ + OBMC_FILTER(x +stride, t, l, m, r, b);\ + OBMC_FILTER(x+1+stride, t, l, m, r, b); + + x=0; + OBMC_FILTER (x , 2, 2, 4, 0, 0); + OBMC_FILTER (x+1, 2, 1, 5, 0, 0); + OBMC_FILTER4(x+2, 2, 1, 5, 0, 0); + OBMC_FILTER4(x+4, 2, 0, 5, 1, 0); + OBMC_FILTER (x+6, 2, 0, 5, 1, 0); + OBMC_FILTER (x+7, 2, 0, 4, 2, 0); + x+= stride; + OBMC_FILTER (x , 1, 2, 5, 0, 0); + OBMC_FILTER (x+1, 1, 2, 5, 0, 0); + OBMC_FILTER (x+6, 1, 0, 5, 2, 0); + OBMC_FILTER (x+7, 1, 0, 5, 2, 0); + x+= stride; + OBMC_FILTER4(x , 1, 2, 5, 0, 0); + OBMC_FILTER4(x+2, 1, 1, 6, 0, 0); + OBMC_FILTER4(x+4, 1, 0, 6, 1, 0); + OBMC_FILTER4(x+6, 1, 0, 5, 2, 0); + x+= 2*stride; + OBMC_FILTER4(x , 0, 2, 5, 0, 1); + OBMC_FILTER4(x+2, 0, 1, 6, 0, 1); + OBMC_FILTER4(x+4, 0, 0, 6, 1, 1); + OBMC_FILTER4(x+6, 0, 0, 5, 2, 1); + x+= 2*stride; + OBMC_FILTER (x , 0, 2, 5, 0, 1); + OBMC_FILTER (x+1, 0, 2, 5, 0, 1); + OBMC_FILTER4(x+2, 0, 1, 5, 0, 2); + OBMC_FILTER4(x+4, 0, 0, 5, 1, 2); + OBMC_FILTER (x+6, 0, 0, 5, 2, 1); + OBMC_FILTER (x+7, 0, 0, 5, 2, 1); + x+= stride; + OBMC_FILTER (x , 0, 2, 4, 0, 2); + OBMC_FILTER (x+1, 0, 1, 5, 0, 2); + OBMC_FILTER (x+6, 0, 0, 5, 1, 2); + OBMC_FILTER (x+7, 0, 0, 4, 2, 2); +} + +/* obmc for 1 8x8 luma block */ +static inline void obmc_motion(MpegEncContext *s, + uint8_t *dest, uint8_t *src, + int src_x, int src_y, + op_pixels_func *pix_op, + int16_t mv[5][2]/* mid top left right bottom*/) +#define MID 0 +{ + int i; + uint8_t *ptr[5]; + + assert(s->quarter_sample==0); + + for(i=0; i<5; i++){ + if(i && mv[i][0]==mv[MID][0] && mv[i][1]==mv[MID][1]){ + ptr[i]= ptr[MID]; + }else{ + ptr[i]= s->obmc_scratchpad + 8*(i&1) + s->linesize*8*(i>>1); + hpel_motion(s, ptr[i], src, 0, 0, + src_x, src_y, + s->width, s->height, s->linesize, + s->h_edge_pos, s->v_edge_pos, + 8, 8, pix_op, + mv[i][0], mv[i][1]); + } + } + + put_obmc(dest, ptr, s->linesize); +} + +static inline void qpel_motion(MpegEncContext *s, + uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, + int field_based, int bottom_field, int field_select, + uint8_t **ref_picture, op_pixels_func (*pix_op)[4], + qpel_mc_func (*qpix_op)[16], + int motion_x, int motion_y, int h) +{ + uint8_t *ptr_y, *ptr_cb, *ptr_cr; + int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, linesize, uvlinesize; + + dxy = ((motion_y & 3) << 2) | (motion_x & 3); + src_x = s->mb_x * 16 + (motion_x >> 2); + src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2); + + v_edge_pos = s->v_edge_pos >> field_based; + linesize = s->linesize << field_based; + uvlinesize = s->uvlinesize << field_based; + + if(field_based){ + mx= motion_x/2; + my= motion_y>>1; + }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA2){ + static const int rtab[8]= {0,0,1,1,0,0,0,1}; + mx= (motion_x>>1) + rtab[motion_x&7]; + my= (motion_y>>1) + rtab[motion_y&7]; + }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA){ + mx= (motion_x>>1)|(motion_x&1); + my= (motion_y>>1)|(motion_y&1); + }else{ + mx= motion_x/2; + my= motion_y/2; + } + mx= (mx>>1)|(mx&1); + my= (my>>1)|(my&1); + + uvdxy= (mx&1) | ((my&1)<<1); + mx>>=1; + my>>=1; + + uvsrc_x = s->mb_x * 8 + mx; + uvsrc_y = s->mb_y * (8 >> field_based) + my; + + ptr_y = ref_picture[0] + src_y * linesize + src_x; + ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; + ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; + + if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 16 + || (unsigned)src_y > v_edge_pos - (motion_y&3) - h ){ + ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based, + src_x, src_y<h_edge_pos, s->v_edge_pos); + ptr_y= s->edge_emu_buffer; + if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ + uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize; + ff_emulated_edge_mc(uvbuf, ptr_cb, s->uvlinesize, 9, 9 + field_based, + uvsrc_x, uvsrc_y<h_edge_pos>>1, s->v_edge_pos>>1); + ff_emulated_edge_mc(uvbuf + 16, ptr_cr, s->uvlinesize, 9, 9 + field_based, + uvsrc_x, uvsrc_y<h_edge_pos>>1, s->v_edge_pos>>1); + ptr_cb= uvbuf; + ptr_cr= uvbuf + 16; + } + } + + if(!field_based) + qpix_op[0][dxy](dest_y, ptr_y, linesize); + else{ + if(bottom_field){ + dest_y += s->linesize; + dest_cb+= s->uvlinesize; + dest_cr+= s->uvlinesize; + } + + if(field_select){ + ptr_y += s->linesize; + ptr_cb += s->uvlinesize; + ptr_cr += s->uvlinesize; + } + //damn interlaced mode + //FIXME boundary mirroring is not exactly correct here + qpix_op[1][dxy](dest_y , ptr_y , linesize); + qpix_op[1][dxy](dest_y+8, ptr_y+8, linesize); + } + if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ + pix_op[1][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> 1); + pix_op[1][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> 1); + } +} + +/** + * h263 chroma 4mv motion compensation. + */ +static inline void chroma_4mv_motion(MpegEncContext *s, + uint8_t *dest_cb, uint8_t *dest_cr, + uint8_t **ref_picture, + op_pixels_func *pix_op, + int mx, int my){ + int dxy, emu=0, src_x, src_y, offset; + uint8_t *ptr; + + /* In case of 8X8, we construct a single chroma motion vector + with a special rounding */ + mx= ff_h263_round_chroma(mx); + my= ff_h263_round_chroma(my); + + dxy = ((my & 1) << 1) | (mx & 1); + mx >>= 1; + my >>= 1; + + src_x = s->mb_x * 8 + mx; + src_y = s->mb_y * 8 + my; + src_x = av_clip(src_x, -8, s->width/2); + if (src_x == s->width/2) + dxy &= ~1; + src_y = av_clip(src_y, -8, s->height/2); + if (src_y == s->height/2) + dxy &= ~2; + + offset = (src_y * (s->uvlinesize)) + src_x; + ptr = ref_picture[1] + offset; + if(s->flags&CODEC_FLAG_EMU_EDGE){ + if( (unsigned)src_x > (s->h_edge_pos>>1) - (dxy &1) - 8 + || (unsigned)src_y > (s->v_edge_pos>>1) - (dxy>>1) - 8){ + ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); + ptr= s->edge_emu_buffer; + emu=1; + } + } + pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8); + + ptr = ref_picture[2] + offset; + if(emu){ + ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); + ptr= s->edge_emu_buffer; + } + pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8); +} + +static inline void prefetch_motion(MpegEncContext *s, uint8_t **pix, int dir){ + /* fetch pixels for estimated mv 4 macroblocks ahead + * optimized for 64byte cache lines */ + const int shift = s->quarter_sample ? 2 : 1; + const int mx= (s->mv[dir][0][0]>>shift) + 16*s->mb_x + 8; + const int my= (s->mv[dir][0][1]>>shift) + 16*s->mb_y; + int off= mx + (my + (s->mb_x&3)*4)*s->linesize + 64; + s->dsp.prefetch(pix[0]+off, s->linesize, 4); + off= (mx>>1) + ((my>>1) + (s->mb_x&7))*s->uvlinesize + 64; + s->dsp.prefetch(pix[1]+off, pix[2]-pix[1], 2); +} + +/** + * motion compensation of a single macroblock + * @param s context + * @param dest_y luma destination pointer + * @param dest_cb chroma cb/u destination pointer + * @param dest_cr chroma cr/v destination pointer + * @param dir direction (0->forward, 1->backward) + * @param ref_picture array[3] of pointers to the 3 planes of the reference picture + * @param pic_op halfpel motion compensation function (average or put normally) + * @param pic_op qpel motion compensation function (average or put normally) + * the motion vectors are taken from s->mv and the MV type from s->mv_type + */ +static inline void MPV_motion(MpegEncContext *s, + uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, + int dir, uint8_t **ref_picture, + op_pixels_func (*pix_op)[4], qpel_mc_func (*qpix_op)[16]) +{ + int dxy, mx, my, src_x, src_y, motion_x, motion_y; + int mb_x, mb_y, i; + uint8_t *ptr, *dest; + + mb_x = s->mb_x; + mb_y = s->mb_y; + + prefetch_motion(s, ref_picture, dir); + + if(s->obmc && s->pict_type != B_TYPE){ + int16_t mv_cache[4][4][2]; + const int xy= s->mb_x + s->mb_y*s->mb_stride; + const int mot_stride= s->b8_stride; + const int mot_xy= mb_x*2 + mb_y*2*mot_stride; + + assert(!s->mb_skipped); + + memcpy(mv_cache[1][1], s->current_picture.motion_val[0][mot_xy ], sizeof(int16_t)*4); + memcpy(mv_cache[2][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4); + memcpy(mv_cache[3][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4); + + if(mb_y==0 || IS_INTRA(s->current_picture.mb_type[xy-s->mb_stride])){ + memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4); + }else{ + memcpy(mv_cache[0][1], s->current_picture.motion_val[0][mot_xy-mot_stride], sizeof(int16_t)*4); + } + + if(mb_x==0 || IS_INTRA(s->current_picture.mb_type[xy-1])){ + *(int32_t*)mv_cache[1][0]= *(int32_t*)mv_cache[1][1]; + *(int32_t*)mv_cache[2][0]= *(int32_t*)mv_cache[2][1]; + }else{ + *(int32_t*)mv_cache[1][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1]; + *(int32_t*)mv_cache[2][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1+mot_stride]; + } + + if(mb_x+1>=s->mb_width || IS_INTRA(s->current_picture.mb_type[xy+1])){ + *(int32_t*)mv_cache[1][3]= *(int32_t*)mv_cache[1][2]; + *(int32_t*)mv_cache[2][3]= *(int32_t*)mv_cache[2][2]; + }else{ + *(int32_t*)mv_cache[1][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2]; + *(int32_t*)mv_cache[2][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2+mot_stride]; + } + + mx = 0; + my = 0; + for(i=0;i<4;i++) { + const int x= (i&1)+1; + const int y= (i>>1)+1; + int16_t mv[5][2]= { + {mv_cache[y][x ][0], mv_cache[y][x ][1]}, + {mv_cache[y-1][x][0], mv_cache[y-1][x][1]}, + {mv_cache[y][x-1][0], mv_cache[y][x-1][1]}, + {mv_cache[y][x+1][0], mv_cache[y][x+1][1]}, + {mv_cache[y+1][x][0], mv_cache[y+1][x][1]}}; + //FIXME cleanup + obmc_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize, + ref_picture[0], + mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8, + pix_op[1], + mv); + + mx += mv[0][0]; + my += mv[0][1]; + } + if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)) + chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my); + + return; + } + + switch(s->mv_type) { + case MV_TYPE_16X16: + if(s->mcsel){ + if(s->real_sprite_warping_points==1){ + gmc1_motion(s, dest_y, dest_cb, dest_cr, + ref_picture); + }else{ + gmc_motion(s, dest_y, dest_cb, dest_cr, + ref_picture); + } + }else if(s->quarter_sample){ + qpel_motion(s, dest_y, dest_cb, dest_cr, + 0, 0, 0, + ref_picture, pix_op, qpix_op, + s->mv[dir][0][0], s->mv[dir][0][1], 16); + }else if(ENABLE_WMV2 && s->mspel){ + ff_mspel_motion(s, dest_y, dest_cb, dest_cr, + ref_picture, pix_op, + s->mv[dir][0][0], s->mv[dir][0][1], 16); + }else + { + mpeg_motion(s, dest_y, dest_cb, dest_cr, + 0, 0, 0, + ref_picture, pix_op, + s->mv[dir][0][0], s->mv[dir][0][1], 16); + } + break; + case MV_TYPE_8X8: + mx = 0; + my = 0; + if(s->quarter_sample){ + for(i=0;i<4;i++) { + motion_x = s->mv[dir][i][0]; + motion_y = s->mv[dir][i][1]; + + dxy = ((motion_y & 3) << 2) | (motion_x & 3); + src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8; + src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8; + + /* WARNING: do no forget half pels */ + src_x = av_clip(src_x, -16, s->width); + if (src_x == s->width) + dxy &= ~3; + src_y = av_clip(src_y, -16, s->height); + if (src_y == s->height) + dxy &= ~12; + + ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); + if(s->flags&CODEC_FLAG_EMU_EDGE){ + if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 8 + || (unsigned)src_y > s->v_edge_pos - (motion_y&3) - 8 ){ + ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos); + ptr= s->edge_emu_buffer; + } + } + dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; + qpix_op[1][dxy](dest, ptr, s->linesize); + + mx += s->mv[dir][i][0]/2; + my += s->mv[dir][i][1]/2; + } + }else{ + for(i=0;i<4;i++) { + hpel_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize, + ref_picture[0], 0, 0, + mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8, + s->width, s->height, s->linesize, + s->h_edge_pos, s->v_edge_pos, + 8, 8, pix_op[1], + s->mv[dir][i][0], s->mv[dir][i][1]); + + mx += s->mv[dir][i][0]; + my += s->mv[dir][i][1]; + } + } + + if(!ENABLE_GRAY || !(s->flags&CODEC_FLAG_GRAY)) + chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my); + break; + case MV_TYPE_FIELD: + if (s->picture_structure == PICT_FRAME) { + if(s->quarter_sample){ + for(i=0; i<2; i++){ + qpel_motion(s, dest_y, dest_cb, dest_cr, + 1, i, s->field_select[dir][i], + ref_picture, pix_op, qpix_op, + s->mv[dir][i][0], s->mv[dir][i][1], 8); + } + }else{ + /* top field */ + mpeg_motion(s, dest_y, dest_cb, dest_cr, + 1, 0, s->field_select[dir][0], + ref_picture, pix_op, + s->mv[dir][0][0], s->mv[dir][0][1], 8); + /* bottom field */ + mpeg_motion(s, dest_y, dest_cb, dest_cr, + 1, 1, s->field_select[dir][1], + ref_picture, pix_op, + s->mv[dir][1][0], s->mv[dir][1][1], 8); + } + } else { + if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != B_TYPE && !s->first_field){ + ref_picture= s->current_picture_ptr->data; + } + + mpeg_motion(s, dest_y, dest_cb, dest_cr, + 0, 0, s->field_select[dir][0], + ref_picture, pix_op, + s->mv[dir][0][0], s->mv[dir][0][1], 16); + } + break; + case MV_TYPE_16X8: + for(i=0; i<2; i++){ + uint8_t ** ref2picture; + + if(s->picture_structure == s->field_select[dir][i] + 1 || s->pict_type == B_TYPE || s->first_field){ + ref2picture= ref_picture; + }else{ + ref2picture= s->current_picture_ptr->data; + } + + mpeg_motion(s, dest_y, dest_cb, dest_cr, + 0, 0, s->field_select[dir][i], + ref2picture, pix_op, + s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8); + + dest_y += 16*s->linesize; + dest_cb+= (16>>s->chroma_y_shift)*s->uvlinesize; + dest_cr+= (16>>s->chroma_y_shift)*s->uvlinesize; + } + break; + case MV_TYPE_DMV: + if(s->picture_structure == PICT_FRAME){ + for(i=0; i<2; i++){ + int j; + for(j=0; j<2; j++){ + mpeg_motion(s, dest_y, dest_cb, dest_cr, + 1, j, j^i, + ref_picture, pix_op, + s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], 8); + } + pix_op = s->dsp.avg_pixels_tab; + } + }else{ + for(i=0; i<2; i++){ + mpeg_motion(s, dest_y, dest_cb, dest_cr, + 0, 0, s->picture_structure != i+1, + ref_picture, pix_op, + s->mv[dir][2*i][0],s->mv[dir][2*i][1],16); + + // after put we make avg of the same block + pix_op=s->dsp.avg_pixels_tab; + + //opposite parity is always in the same frame if this is second field + if(!s->first_field){ + ref_picture = s->current_picture_ptr->data; + } + } + } + break; + default: assert(0); + } +} + +#endif /* FFMPEG_MPEGVIDEO_COMMON_H */ diff --git a/contrib/ffmpeg/libavcodec/mpegvideo_enc.c b/contrib/ffmpeg/libavcodec/mpegvideo_enc.c new file mode 100644 index 000000000..bebdf71f3 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpegvideo_enc.c @@ -0,0 +1,3847 @@ +/* + * The simplest mpeg encoder (well, it was the simplest!) + * Copyright (c) 2000,2001 Fabrice Bellard. + * Copyright (c) 2002-2004 Michael Niedermayer + * + * 4MV & hq & B-frame encoding stuff by Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file mpegvideo_enc.c + * The simplest mpeg encoder (well, it was the simplest!). + */ + +#include "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" +#include "mpegvideo_common.h" +#include "mjpegenc.h" +#include "msmpeg4.h" +#include "h263.h" +#include "faandct.h" +#include + +//#undef NDEBUG +//#include + +static int encode_picture(MpegEncContext *s, int picture_number); +static int dct_quantize_refine(MpegEncContext *s, DCTELEM *block, int16_t *weight, DCTELEM *orig, int n, int qscale); +static int sse_mb(MpegEncContext *s); + +/* enable all paranoid tests for rounding, overflows, etc... */ +//#define PARANOID + +//#define DEBUG + +static const uint16_t aanscales[64] = { + /* precomputed values scaled up by 14 bits */ + 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, + 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, + 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, + 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, + 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, + 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, + 8867 , 12299, 11585, 10426, 8867, 6967, 4799, 2446, + 4520 , 6270, 5906, 5315, 4520, 3552, 2446, 1247 +}; + +static const uint16_t inv_aanscales[64] = { + 4096, 2953, 3135, 3483, 4096, 5213, 7568, 14846, + 2953, 2129, 2260, 2511, 2953, 3759, 5457, 10703, + 3135, 2260, 2399, 2666, 3135, 3990, 5793, 11363, + 3483, 2511, 2666, 2962, 3483, 4433, 6436, 12625, + 4096, 2953, 3135, 3483, 4096, 5213, 7568, 14846, + 5213, 3759, 3990, 4433, 5213, 6635, 9633, 18895, + 7568, 5457, 5793, 6436, 7568, 9633, 13985, 27432, + 14846, 10703, 11363, 12625, 14846, 18895, 27432, 53809, +}; + +static uint8_t default_mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; +static uint8_t default_fcode_tab[MAX_MV*2+1]; + +void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64], + const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra) +{ + int qscale; + int shift=0; + + for(qscale=qmin; qscale<=qmax; qscale++){ + int i; + if (dsp->fdct == ff_jpeg_fdct_islow +#ifdef FAAN_POSTSCALE + || dsp->fdct == ff_faandct +#endif + ) { + for(i=0;i<64;i++) { + const int j= dsp->idct_permutation[i]; + /* 16 <= qscale * quant_matrix[i] <= 7905 */ + /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ + /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ + /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ + + qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) / + (qscale * quant_matrix[j])); + } + } else if (dsp->fdct == fdct_ifast +#ifndef FAAN_POSTSCALE + || dsp->fdct == ff_faandct +#endif + ) { + for(i=0;i<64;i++) { + const int j= dsp->idct_permutation[i]; + /* 16 <= qscale * quant_matrix[i] <= 7905 */ + /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ + /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ + /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ + + qmat[qscale][i] = (int)((UINT64_C(1) << (QMAT_SHIFT + 14)) / + (aanscales[i] * qscale * quant_matrix[j])); + } + } else { + for(i=0;i<64;i++) { + const int j= dsp->idct_permutation[i]; + /* We can safely suppose that 16 <= quant_matrix[i] <= 255 + So 16 <= qscale * quant_matrix[i] <= 7905 + so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 + so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 + */ + qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j])); +// qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]); + qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]); + + if(qmat16[qscale][0][i]==0 || qmat16[qscale][0][i]==128*256) qmat16[qscale][0][i]=128*256-1; + qmat16[qscale][1][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][0][i]); + } + } + + for(i=intra; i<64; i++){ + int64_t max= 8191; + if (dsp->fdct == fdct_ifast +#ifndef FAAN_POSTSCALE + || dsp->fdct == ff_faandct +#endif + ) { + max= (8191LL*aanscales[i]) >> 14; + } + while(((max * qmat[qscale][i]) >> shift) > INT_MAX){ + shift++; + } + } + } + if(shift){ + av_log(NULL, AV_LOG_INFO, "Warning, QMAT_SHIFT is larger than %d, overflows possible\n", QMAT_SHIFT - shift); + } +} + +static inline void update_qscale(MpegEncContext *s){ + s->qscale= (s->lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); + s->qscale= av_clip(s->qscale, s->avctx->qmin, s->avctx->qmax); + + s->lambda2= (s->lambda*s->lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT; +} + +void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix){ + int i; + + if(matrix){ + put_bits(pb, 1, 1); + for(i=0;i<64;i++) { + put_bits(pb, 8, matrix[ ff_zigzag_direct[i] ]); + } + }else + put_bits(pb, 1, 0); +} + +static void copy_picture_attributes(MpegEncContext *s, AVFrame *dst, AVFrame *src){ + int i; + + dst->pict_type = src->pict_type; + dst->quality = src->quality; + dst->coded_picture_number = src->coded_picture_number; + dst->display_picture_number = src->display_picture_number; +// dst->reference = src->reference; + dst->pts = src->pts; + dst->interlaced_frame = src->interlaced_frame; + dst->top_field_first = src->top_field_first; + + if(s->avctx->me_threshold){ + if(!src->motion_val[0]) + av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_val not set!\n"); + if(!src->mb_type) + av_log(s->avctx, AV_LOG_ERROR, "AVFrame.mb_type not set!\n"); + if(!src->ref_index[0]) + av_log(s->avctx, AV_LOG_ERROR, "AVFrame.ref_index not set!\n"); + if(src->motion_subsample_log2 != dst->motion_subsample_log2) + av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_subsample_log2 doesn't match! (%d!=%d)\n", + src->motion_subsample_log2, dst->motion_subsample_log2); + + memcpy(dst->mb_type, src->mb_type, s->mb_stride * s->mb_height * sizeof(dst->mb_type[0])); + + for(i=0; i<2; i++){ + int stride= ((16*s->mb_width )>>src->motion_subsample_log2) + 1; + int height= ((16*s->mb_height)>>src->motion_subsample_log2); + + if(src->motion_val[i] && src->motion_val[i] != dst->motion_val[i]){ + memcpy(dst->motion_val[i], src->motion_val[i], 2*stride*height*sizeof(int16_t)); + } + if(src->ref_index[i] && src->ref_index[i] != dst->ref_index[i]){ + memcpy(dst->ref_index[i], src->ref_index[i], s->b8_stride*2*s->mb_height*sizeof(int8_t)); + } + } + } +} + +static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContext *src){ +#define COPY(a) dst->a= src->a + COPY(pict_type); + COPY(current_picture); + COPY(f_code); + COPY(b_code); + COPY(qscale); + COPY(lambda); + COPY(lambda2); + COPY(picture_in_gop_number); + COPY(gop_picture_number); + COPY(frame_pred_frame_dct); //FIXME don't set in encode_header + COPY(progressive_frame); //FIXME don't set in encode_header + COPY(partitioned_frame); //FIXME don't set in encode_header +#undef COPY +} + +/** + * sets the given MpegEncContext to defaults for encoding. + * the changed fields will not depend upon the prior state of the MpegEncContext. + */ +static void MPV_encode_defaults(MpegEncContext *s){ + int i; + MPV_common_defaults(s); + + for(i=-16; i<16; i++){ + default_fcode_tab[i + MAX_MV]= 1; + } + s->me.mv_penalty= default_mv_penalty; + s->fcode_tab= default_fcode_tab; +} + +/* init video encoder */ +int MPV_encode_init(AVCodecContext *avctx) +{ + MpegEncContext *s = avctx->priv_data; + int i; + int chroma_h_shift, chroma_v_shift; + + MPV_encode_defaults(s); + + switch (avctx->codec_id) { + case CODEC_ID_MPEG2VIDEO: + if(avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P){ + av_log(avctx, AV_LOG_ERROR, "only YUV420 and YUV422 are supported\n"); + return -1; + } + break; + case CODEC_ID_LJPEG: + case CODEC_ID_MJPEG: + if(avctx->pix_fmt != PIX_FMT_YUVJ420P && avctx->pix_fmt != PIX_FMT_YUVJ422P && + ((avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P) || avctx->strict_std_compliance>FF_COMPLIANCE_INOFFICIAL)){ + av_log(avctx, AV_LOG_ERROR, "colorspace not supported in jpeg\n"); + return -1; + } + break; + default: + if(avctx->pix_fmt != PIX_FMT_YUV420P){ + av_log(avctx, AV_LOG_ERROR, "only YUV420 is supported\n"); + return -1; + } + } + + switch (avctx->pix_fmt) { + case PIX_FMT_YUVJ422P: + case PIX_FMT_YUV422P: + s->chroma_format = CHROMA_422; + break; + case PIX_FMT_YUVJ420P: + case PIX_FMT_YUV420P: + default: + s->chroma_format = CHROMA_420; + break; + } + + s->bit_rate = avctx->bit_rate; + s->width = avctx->width; + s->height = avctx->height; + if(avctx->gop_size > 600 && avctx->strict_std_compliance>FF_COMPLIANCE_EXPERIMENTAL){ + av_log(avctx, AV_LOG_ERROR, "Warning keyframe interval too large! reducing it ...\n"); + avctx->gop_size=600; + } + s->gop_size = avctx->gop_size; + s->avctx = avctx; + s->flags= avctx->flags; + s->flags2= avctx->flags2; + s->max_b_frames= avctx->max_b_frames; + s->codec_id= avctx->codec->id; + s->luma_elim_threshold = avctx->luma_elim_threshold; + s->chroma_elim_threshold= avctx->chroma_elim_threshold; + s->strict_std_compliance= avctx->strict_std_compliance; + s->data_partitioning= avctx->flags & CODEC_FLAG_PART; + s->quarter_sample= (avctx->flags & CODEC_FLAG_QPEL)!=0; + s->mpeg_quant= avctx->mpeg_quant; + s->rtp_mode= !!avctx->rtp_payload_size; + s->intra_dc_precision= avctx->intra_dc_precision; + s->user_specified_pts = AV_NOPTS_VALUE; + + if (s->gop_size <= 1) { + s->intra_only = 1; + s->gop_size = 12; + } else { + s->intra_only = 0; + } + + s->me_method = avctx->me_method; + + /* Fixed QSCALE */ + s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE); + + s->adaptive_quant= ( s->avctx->lumi_masking + || s->avctx->dark_masking + || s->avctx->temporal_cplx_masking + || s->avctx->spatial_cplx_masking + || s->avctx->p_masking + || s->avctx->border_masking + || (s->flags&CODEC_FLAG_QP_RD)) + && !s->fixed_qscale; + + s->obmc= !!(s->flags & CODEC_FLAG_OBMC); + s->loop_filter= !!(s->flags & CODEC_FLAG_LOOP_FILTER); + s->alternate_scan= !!(s->flags & CODEC_FLAG_ALT_SCAN); + s->intra_vlc_format= !!(s->flags2 & CODEC_FLAG2_INTRA_VLC); + s->q_scale_type= !!(s->flags2 & CODEC_FLAG2_NON_LINEAR_QUANT); + + if(avctx->rc_max_rate && !avctx->rc_buffer_size){ + av_log(avctx, AV_LOG_ERROR, "a vbv buffer size is needed, for encoding with a maximum bitrate\n"); + return -1; + } + + if(avctx->rc_min_rate && avctx->rc_max_rate != avctx->rc_min_rate){ + av_log(avctx, AV_LOG_INFO, "Warning min_rate > 0 but min_rate != max_rate isn't recommended!\n"); + } + + if(avctx->rc_min_rate && avctx->rc_min_rate > avctx->bit_rate){ + av_log(avctx, AV_LOG_ERROR, "bitrate below min bitrate\n"); + return -1; + } + + if(avctx->rc_max_rate && avctx->rc_max_rate < avctx->bit_rate){ + av_log(avctx, AV_LOG_INFO, "bitrate above max bitrate\n"); + return -1; + } + + if(avctx->rc_max_rate && avctx->rc_max_rate == avctx->bit_rate && avctx->rc_max_rate != avctx->rc_min_rate){ + av_log(avctx, AV_LOG_INFO, "impossible bitrate constraints, this will fail\n"); + } + + if(avctx->rc_buffer_size && avctx->bit_rate*av_q2d(avctx->time_base) > avctx->rc_buffer_size){ + av_log(avctx, AV_LOG_ERROR, "VBV buffer too small for bitrate\n"); + return -1; + } + + if(avctx->bit_rate*av_q2d(avctx->time_base) > avctx->bit_rate_tolerance){ + av_log(avctx, AV_LOG_ERROR, "bitrate tolerance too small for bitrate\n"); + return -1; + } + + if( s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate + && (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO) + && 90000LL * (avctx->rc_buffer_size-1) > s->avctx->rc_max_rate*0xFFFFLL){ + + av_log(avctx, AV_LOG_INFO, "Warning vbv_delay will be set to 0xFFFF (=VBR) as the specified vbv buffer is too large for the given bitrate!\n"); + } + + if((s->flags & CODEC_FLAG_4MV) && s->codec_id != CODEC_ID_MPEG4 + && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P && s->codec_id != CODEC_ID_FLV1){ + av_log(avctx, AV_LOG_ERROR, "4MV not supported by codec\n"); + return -1; + } + + if(s->obmc && s->avctx->mb_decision != FF_MB_DECISION_SIMPLE){ + av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with simple mb decision\n"); + return -1; + } + + if(s->obmc && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P){ + av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with H263(+)\n"); + return -1; + } + + if(s->quarter_sample && s->codec_id != CODEC_ID_MPEG4){ + av_log(avctx, AV_LOG_ERROR, "qpel not supported by codec\n"); + return -1; + } + + if(s->data_partitioning && s->codec_id != CODEC_ID_MPEG4){ + av_log(avctx, AV_LOG_ERROR, "data partitioning not supported by codec\n"); + return -1; + } + + if(s->max_b_frames && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO){ + av_log(avctx, AV_LOG_ERROR, "b frames not supported by codec\n"); + return -1; + } + + if((s->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN)) + && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG2VIDEO){ + av_log(avctx, AV_LOG_ERROR, "interlacing not supported by codec\n"); + return -1; + } + + if(s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4){ //FIXME mpeg2 uses that too + av_log(avctx, AV_LOG_ERROR, "mpeg2 style quantization not supported by codec\n"); + return -1; + } + + if((s->flags & CODEC_FLAG_CBP_RD) && !(s->flags & CODEC_FLAG_TRELLIS_QUANT)){ + av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n"); + return -1; + } + + if((s->flags & CODEC_FLAG_QP_RD) && s->avctx->mb_decision != FF_MB_DECISION_RD){ + av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n"); + return -1; + } + + if(s->avctx->scenechange_threshold < 1000000000 && (s->flags & CODEC_FLAG_CLOSED_GOP)){ + av_log(avctx, AV_LOG_ERROR, "closed gop with scene change detection arent supported yet, set threshold to 1000000000\n"); + return -1; + } + + if((s->flags2 & CODEC_FLAG2_INTRA_VLC) && s->codec_id != CODEC_ID_MPEG2VIDEO){ + av_log(avctx, AV_LOG_ERROR, "intra vlc table not supported by codec\n"); + return -1; + } + + if(s->flags & CODEC_FLAG_LOW_DELAY){ + if (s->codec_id != CODEC_ID_MPEG2VIDEO && s->codec_id != CODEC_ID_MPEG1VIDEO){ + av_log(avctx, AV_LOG_ERROR, "low delay forcing is only available for mpeg1/2\n"); + return -1; + } + if (s->max_b_frames != 0){ + av_log(avctx, AV_LOG_ERROR, "b frames cannot be used with low delay\n"); + return -1; + } + } + + if(s->q_scale_type == 1){ + if(s->codec_id != CODEC_ID_MPEG2VIDEO){ + av_log(avctx, AV_LOG_ERROR, "non linear quant is only available for mpeg2\n"); + return -1; + } + if(avctx->qmax > 12){ + av_log(avctx, AV_LOG_ERROR, "non linear quant only supports qmax <= 12 currently\n"); + return -1; + } + } + + if(s->avctx->thread_count > 1 && s->codec_id != CODEC_ID_MPEG4 + && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO + && (s->codec_id != CODEC_ID_H263P || !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))){ + av_log(avctx, AV_LOG_ERROR, "multi threaded encoding not supported by codec\n"); + return -1; + } + + if(s->avctx->thread_count > 1) + s->rtp_mode= 1; + + if(!avctx->time_base.den || !avctx->time_base.num){ + av_log(avctx, AV_LOG_ERROR, "framerate not set\n"); + return -1; + } + + i= (INT_MAX/2+128)>>8; + if(avctx->me_threshold >= i){ + av_log(avctx, AV_LOG_ERROR, "me_threshold too large, max is %d\n", i - 1); + return -1; + } + if(avctx->mb_threshold >= i){ + av_log(avctx, AV_LOG_ERROR, "mb_threshold too large, max is %d\n", i - 1); + return -1; + } + + if(avctx->b_frame_strategy && (avctx->flags&CODEC_FLAG_PASS2)){ + av_log(avctx, AV_LOG_INFO, "notice: b_frame_strategy only affects the first pass\n"); + avctx->b_frame_strategy = 0; + } + + i= ff_gcd(avctx->time_base.den, avctx->time_base.num); + if(i > 1){ + av_log(avctx, AV_LOG_INFO, "removing common factors from framerate\n"); + avctx->time_base.den /= i; + avctx->time_base.num /= i; +// return -1; + } + + if(s->codec_id==CODEC_ID_MJPEG){ + s->intra_quant_bias= 1<<(QUANT_BIAS_SHIFT-1); //(a + x/2)/x + s->inter_quant_bias= 0; + }else if(s->mpeg_quant || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO){ + s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x + s->inter_quant_bias= 0; + }else{ + s->intra_quant_bias=0; + s->inter_quant_bias=-(1<<(QUANT_BIAS_SHIFT-2)); //(a - x/4)/x + } + + if(avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS) + s->intra_quant_bias= avctx->intra_quant_bias; + if(avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS) + s->inter_quant_bias= avctx->inter_quant_bias; + + avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, &chroma_v_shift); + + if(avctx->codec_id == CODEC_ID_MPEG4 && s->avctx->time_base.den > (1<<16)-1){ + av_log(avctx, AV_LOG_ERROR, "timebase not supported by mpeg 4 standard\n"); + return -1; + } + s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1; + + switch(avctx->codec->id) { + case CODEC_ID_MPEG1VIDEO: + s->out_format = FMT_MPEG1; + s->low_delay= !!(s->flags & CODEC_FLAG_LOW_DELAY); + avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); + break; + case CODEC_ID_MPEG2VIDEO: + s->out_format = FMT_MPEG1; + s->low_delay= !!(s->flags & CODEC_FLAG_LOW_DELAY); + avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); + s->rtp_mode= 1; + break; + case CODEC_ID_LJPEG: + case CODEC_ID_MJPEG: + s->out_format = FMT_MJPEG; + s->intra_only = 1; /* force intra only for jpeg */ + s->mjpeg_vsample[0] = 2; + s->mjpeg_vsample[1] = 2>>chroma_v_shift; + s->mjpeg_vsample[2] = 2>>chroma_v_shift; + s->mjpeg_hsample[0] = 2; + s->mjpeg_hsample[1] = 2>>chroma_h_shift; + s->mjpeg_hsample[2] = 2>>chroma_h_shift; + if (!(ENABLE_MJPEG_ENCODER || ENABLE_LJPEG_ENCODER) + || ff_mjpeg_encode_init(s) < 0) + return -1; + avctx->delay=0; + s->low_delay=1; + break; + case CODEC_ID_H261: + if (!ENABLE_H261_ENCODER) return -1; + if (ff_h261_get_picture_format(s->width, s->height) < 0) { + av_log(avctx, AV_LOG_ERROR, "The specified picture size of %dx%d is not valid for the H.261 codec.\nValid sizes are 176x144, 352x288\n", s->width, s->height); + return -1; + } + s->out_format = FMT_H261; + avctx->delay=0; + s->low_delay=1; + break; + case CODEC_ID_H263: + if (!ENABLE_H263_ENCODER) return -1; + if (h263_get_picture_format(s->width, s->height) == 7) { + av_log(avctx, AV_LOG_INFO, "The specified picture size of %dx%d is not valid for the H.263 codec.\nValid sizes are 128x96, 176x144, 352x288, 704x576, and 1408x1152. Try H.263+.\n", s->width, s->height); + return -1; + } + s->out_format = FMT_H263; + s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0; + avctx->delay=0; + s->low_delay=1; + break; + case CODEC_ID_H263P: + s->out_format = FMT_H263; + s->h263_plus = 1; + /* Fx */ + s->umvplus = (avctx->flags & CODEC_FLAG_H263P_UMV) ? 1:0; + s->h263_aic= (avctx->flags & CODEC_FLAG_AC_PRED) ? 1:0; + s->modified_quant= s->h263_aic; + s->alt_inter_vlc= (avctx->flags & CODEC_FLAG_H263P_AIV) ? 1:0; + s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0; + s->loop_filter= (avctx->flags & CODEC_FLAG_LOOP_FILTER) ? 1:0; + s->unrestricted_mv= s->obmc || s->loop_filter || s->umvplus; + s->h263_slice_structured= (s->flags & CODEC_FLAG_H263P_SLICE_STRUCT) ? 1:0; + + /* /Fx */ + /* These are just to be sure */ + avctx->delay=0; + s->low_delay=1; + break; + case CODEC_ID_FLV1: + s->out_format = FMT_H263; + s->h263_flv = 2; /* format = 1; 11-bit codes */ + s->unrestricted_mv = 1; + s->rtp_mode=0; /* don't allow GOB */ + avctx->delay=0; + s->low_delay=1; + break; + case CODEC_ID_RV10: + s->out_format = FMT_H263; + avctx->delay=0; + s->low_delay=1; + break; + case CODEC_ID_RV20: + s->out_format = FMT_H263; + avctx->delay=0; + s->low_delay=1; + s->modified_quant=1; + s->h263_aic=1; + s->h263_plus=1; + s->loop_filter=1; + s->unrestricted_mv= s->obmc || s->loop_filter || s->umvplus; + break; + case CODEC_ID_MPEG4: + s->out_format = FMT_H263; + s->h263_pred = 1; + s->unrestricted_mv = 1; + s->low_delay= s->max_b_frames ? 0 : 1; + avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); + break; + case CODEC_ID_MSMPEG4V1: + s->out_format = FMT_H263; + s->h263_msmpeg4 = 1; + s->h263_pred = 1; + s->unrestricted_mv = 1; + s->msmpeg4_version= 1; + avctx->delay=0; + s->low_delay=1; + break; + case CODEC_ID_MSMPEG4V2: + s->out_format = FMT_H263; + s->h263_msmpeg4 = 1; + s->h263_pred = 1; + s->unrestricted_mv = 1; + s->msmpeg4_version= 2; + avctx->delay=0; + s->low_delay=1; + break; + case CODEC_ID_MSMPEG4V3: + s->out_format = FMT_H263; + s->h263_msmpeg4 = 1; + s->h263_pred = 1; + s->unrestricted_mv = 1; + s->msmpeg4_version= 3; + s->flipflop_rounding=1; + avctx->delay=0; + s->low_delay=1; + break; + case CODEC_ID_WMV1: + s->out_format = FMT_H263; + s->h263_msmpeg4 = 1; + s->h263_pred = 1; + s->unrestricted_mv = 1; + s->msmpeg4_version= 4; + s->flipflop_rounding=1; + avctx->delay=0; + s->low_delay=1; + break; + case CODEC_ID_WMV2: + s->out_format = FMT_H263; + s->h263_msmpeg4 = 1; + s->h263_pred = 1; + s->unrestricted_mv = 1; + s->msmpeg4_version= 5; + s->flipflop_rounding=1; + avctx->delay=0; + s->low_delay=1; + break; + default: + return -1; + } + + avctx->has_b_frames= !s->low_delay; + + s->encoding = 1; + + /* init */ + if (MPV_common_init(s) < 0) + return -1; + + if(!s->dct_quantize) + s->dct_quantize = dct_quantize_c; + if(!s->denoise_dct) + s->denoise_dct = denoise_dct_c; + s->fast_dct_quantize = s->dct_quantize; + if(s->flags & CODEC_FLAG_TRELLIS_QUANT) + s->dct_quantize = dct_quantize_trellis_c; + + if((ENABLE_H263P_ENCODER || ENABLE_RV20_ENCODER) && s->modified_quant) + s->chroma_qscale_table= ff_h263_chroma_qscale_table; + s->progressive_frame= + s->progressive_sequence= !(avctx->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN)); + s->quant_precision=5; + + ff_set_cmp(&s->dsp, s->dsp.ildct_cmp, s->avctx->ildct_cmp); + ff_set_cmp(&s->dsp, s->dsp.frame_skip_cmp, s->avctx->frame_skip_cmp); + + if (ENABLE_H261_ENCODER && s->out_format == FMT_H261) + ff_h261_encode_init(s); + if (ENABLE_ANY_H263_ENCODER && s->out_format == FMT_H263) + h263_encode_init(s); + if (ENABLE_MSMPEG4_ENCODER && s->msmpeg4_version) + ff_msmpeg4_encode_init(s); + if ((ENABLE_MPEG1VIDEO_ENCODER || ENABLE_MPEG2VIDEO_ENCODER) + && s->out_format == FMT_MPEG1) + ff_mpeg1_encode_init(s); + + /* init q matrix */ + for(i=0;i<64;i++) { + int j= s->dsp.idct_permutation[i]; + if(ENABLE_MPEG4_ENCODER && s->codec_id==CODEC_ID_MPEG4 && s->mpeg_quant){ + s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i]; + s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i]; + }else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){ + s->intra_matrix[j] = + s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; + }else + { /* mpeg1/2 */ + s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i]; + s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; + } + if(s->avctx->intra_matrix) + s->intra_matrix[j] = s->avctx->intra_matrix[i]; + if(s->avctx->inter_matrix) + s->inter_matrix[j] = s->avctx->inter_matrix[i]; + } + + /* precompute matrix */ + /* for mjpeg, we do include qscale in the matrix */ + if (s->out_format != FMT_MJPEG) { + ff_convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, + s->intra_matrix, s->intra_quant_bias, avctx->qmin, 31, 1); + ff_convert_matrix(&s->dsp, s->q_inter_matrix, s->q_inter_matrix16, + s->inter_matrix, s->inter_quant_bias, avctx->qmin, 31, 0); + } + + if(ff_rate_control_init(s) < 0) + return -1; + + return 0; +} + +int MPV_encode_end(AVCodecContext *avctx) +{ + MpegEncContext *s = avctx->priv_data; + + ff_rate_control_uninit(s); + + MPV_common_end(s); + if ((ENABLE_MJPEG_ENCODER || ENABLE_LJPEG_ENCODER) && s->out_format == FMT_MJPEG) + ff_mjpeg_encode_close(s); + + av_freep(&avctx->extradata); + + return 0; +} + +static int get_sae(uint8_t *src, int ref, int stride){ + int x,y; + int acc=0; + + for(y=0; y<16; y++){ + for(x=0; x<16; x++){ + acc+= FFABS(src[x+y*stride] - ref); + } + } + + return acc; +} + +static int get_intra_count(MpegEncContext *s, uint8_t *src, uint8_t *ref, int stride){ + int x, y, w, h; + int acc=0; + + w= s->width &~15; + h= s->height&~15; + + for(y=0; ydsp.sad[0](NULL, src + offset, ref + offset, stride, 16); + int mean= (s->dsp.pix_sum(src + offset, stride) + 128)>>8; + int sae = get_sae(src + offset, mean, stride); + + acc+= sae + 500 < sad; + } + } + return acc; +} + + +static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg){ + AVFrame *pic=NULL; + int64_t pts; + int i; + const int encoding_delay= s->max_b_frames; + int direct=1; + + if(pic_arg){ + pts= pic_arg->pts; + pic_arg->display_picture_number= s->input_picture_number++; + + if(pts != AV_NOPTS_VALUE){ + if(s->user_specified_pts != AV_NOPTS_VALUE){ + int64_t time= pts; + int64_t last= s->user_specified_pts; + + if(time <= last){ + av_log(s->avctx, AV_LOG_ERROR, "Error, Invalid timestamp=%"PRId64", last=%"PRId64"\n", pts, s->user_specified_pts); + return -1; + } + } + s->user_specified_pts= pts; + }else{ + if(s->user_specified_pts != AV_NOPTS_VALUE){ + s->user_specified_pts= + pts= s->user_specified_pts + 1; + av_log(s->avctx, AV_LOG_INFO, "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", pts); + }else{ + pts= pic_arg->display_picture_number; + } + } + } + + if(pic_arg){ + if(encoding_delay && !(s->flags&CODEC_FLAG_INPUT_PRESERVED)) direct=0; + if(pic_arg->linesize[0] != s->linesize) direct=0; + if(pic_arg->linesize[1] != s->uvlinesize) direct=0; + if(pic_arg->linesize[2] != s->uvlinesize) direct=0; + +// av_log(AV_LOG_DEBUG, "%d %d %d %d\n",pic_arg->linesize[0], pic_arg->linesize[1], s->linesize, s->uvlinesize); + + if(direct){ + i= ff_find_unused_picture(s, 1); + + pic= (AVFrame*)&s->picture[i]; + pic->reference= 3; + + for(i=0; i<4; i++){ + pic->data[i]= pic_arg->data[i]; + pic->linesize[i]= pic_arg->linesize[i]; + } + alloc_picture(s, (Picture*)pic, 1); + }else{ + i= ff_find_unused_picture(s, 0); + + pic= (AVFrame*)&s->picture[i]; + pic->reference= 3; + + alloc_picture(s, (Picture*)pic, 0); + + if( pic->data[0] + INPLACE_OFFSET == pic_arg->data[0] + && pic->data[1] + INPLACE_OFFSET == pic_arg->data[1] + && pic->data[2] + INPLACE_OFFSET == pic_arg->data[2]){ + // empty + }else{ + int h_chroma_shift, v_chroma_shift; + avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift); + + for(i=0; i<3; i++){ + int src_stride= pic_arg->linesize[i]; + int dst_stride= i ? s->uvlinesize : s->linesize; + int h_shift= i ? h_chroma_shift : 0; + int v_shift= i ? v_chroma_shift : 0; + int w= s->width >>h_shift; + int h= s->height>>v_shift; + uint8_t *src= pic_arg->data[i]; + uint8_t *dst= pic->data[i]; + + if(!s->avctx->rc_buffer_size) + dst +=INPLACE_OFFSET; + + if(src_stride==dst_stride) + memcpy(dst, src, src_stride*h); + else{ + while(h--){ + memcpy(dst, src, w); + dst += dst_stride; + src += src_stride; + } + } + } + } + } + copy_picture_attributes(s, pic, pic_arg); + pic->pts= pts; //we set this here to avoid modifiying pic_arg + } + + /* shift buffer entries */ + for(i=1; iencoding_delay+1*/; i++) + s->input_picture[i-1]= s->input_picture[i]; + + s->input_picture[encoding_delay]= (Picture*)pic; + + return 0; +} + +static int skip_check(MpegEncContext *s, Picture *p, Picture *ref){ + int x, y, plane; + int score=0; + int64_t score64=0; + + for(plane=0; plane<3; plane++){ + const int stride= p->linesize[plane]; + const int bw= plane ? 1 : 2; + for(y=0; ymb_height*bw; y++){ + for(x=0; xmb_width*bw; x++){ + int off= p->type == FF_BUFFER_TYPE_SHARED ? 0: 16; + int v= s->dsp.frame_skip_cmp[1](s, p->data[plane] + 8*(x + y*stride)+off, ref->data[plane] + 8*(x + y*stride), stride, 8); + + switch(s->avctx->frame_skip_exp){ + case 0: score= FFMAX(score, v); break; + case 1: score+= FFABS(v);break; + case 2: score+= v*v;break; + case 3: score64+= FFABS(v*v*(int64_t)v);break; + case 4: score64+= v*v*(int64_t)(v*v);break; + } + } + } + } + + if(score) score64= score; + + if(score64 < s->avctx->frame_skip_threshold) + return 1; + if(score64 < ((s->avctx->frame_skip_factor * (int64_t)s->lambda)>>8)) + return 1; + return 0; +} + +static int estimate_best_b_count(MpegEncContext *s){ + AVCodec *codec= avcodec_find_encoder(s->avctx->codec_id); + AVCodecContext *c= avcodec_alloc_context(); + AVFrame input[FF_MAX_B_FRAMES+2]; + const int scale= s->avctx->brd_scale; + int i, j, out_size, p_lambda, b_lambda, lambda2; + int outbuf_size= s->width * s->height; //FIXME + uint8_t *outbuf= av_malloc(outbuf_size); + int64_t best_rd= INT64_MAX; + int best_b_count= -1; + + assert(scale>=0 && scale <=3); + +// emms_c(); + p_lambda= s->last_lambda_for[P_TYPE]; //s->next_picture_ptr->quality; + b_lambda= s->last_lambda_for[B_TYPE]; //p_lambda *FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset; + if(!b_lambda) b_lambda= p_lambda; //FIXME we should do this somewhere else + lambda2= (b_lambda*b_lambda + (1<> FF_LAMBDA_SHIFT; + + c->width = s->width >> scale; + c->height= s->height>> scale; + c->flags= CODEC_FLAG_QSCALE | CODEC_FLAG_PSNR | CODEC_FLAG_INPUT_PRESERVED /*| CODEC_FLAG_EMU_EDGE*/; + c->flags|= s->avctx->flags & CODEC_FLAG_QPEL; + c->mb_decision= s->avctx->mb_decision; + c->me_cmp= s->avctx->me_cmp; + c->mb_cmp= s->avctx->mb_cmp; + c->me_sub_cmp= s->avctx->me_sub_cmp; + c->pix_fmt = PIX_FMT_YUV420P; + c->time_base= s->avctx->time_base; + c->max_b_frames= s->max_b_frames; + + if (avcodec_open(c, codec) < 0) + return -1; + + for(i=0; imax_b_frames+2; i++){ + int ysize= c->width*c->height; + int csize= (c->width/2)*(c->height/2); + Picture pre_input, *pre_input_ptr= i ? s->input_picture[i-1] : s->next_picture_ptr; + + avcodec_get_frame_defaults(&input[i]); + input[i].data[0]= av_malloc(ysize + 2*csize); + input[i].data[1]= input[i].data[0] + ysize; + input[i].data[2]= input[i].data[1] + csize; + input[i].linesize[0]= c->width; + input[i].linesize[1]= + input[i].linesize[2]= c->width/2; + + if(pre_input_ptr && (!i || s->input_picture[i-1])) { + pre_input= *pre_input_ptr; + + if(pre_input.type != FF_BUFFER_TYPE_SHARED && i) { + pre_input.data[0]+=INPLACE_OFFSET; + pre_input.data[1]+=INPLACE_OFFSET; + pre_input.data[2]+=INPLACE_OFFSET; + } + + s->dsp.shrink[scale](input[i].data[0], input[i].linesize[0], pre_input.data[0], pre_input.linesize[0], c->width, c->height); + s->dsp.shrink[scale](input[i].data[1], input[i].linesize[1], pre_input.data[1], pre_input.linesize[1], c->width>>1, c->height>>1); + s->dsp.shrink[scale](input[i].data[2], input[i].linesize[2], pre_input.data[2], pre_input.linesize[2], c->width>>1, c->height>>1); + } + } + + for(j=0; jmax_b_frames+1; j++){ + int64_t rd=0; + + if(!s->input_picture[j]) + break; + + c->error[0]= c->error[1]= c->error[2]= 0; + + input[0].pict_type= I_TYPE; + input[0].quality= 1 * FF_QP2LAMBDA; + out_size = avcodec_encode_video(c, outbuf, outbuf_size, &input[0]); +// rd += (out_size * lambda2) >> FF_LAMBDA_SHIFT; + + for(i=0; imax_b_frames+1; i++){ + int is_p= i % (j+1) == j || i==s->max_b_frames; + + input[i+1].pict_type= is_p ? P_TYPE : B_TYPE; + input[i+1].quality= is_p ? p_lambda : b_lambda; + out_size = avcodec_encode_video(c, outbuf, outbuf_size, &input[i+1]); + rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3); + } + + /* get the delayed frames */ + while(out_size){ + out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL); + rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3); + } + + rd += c->error[0] + c->error[1] + c->error[2]; + + if(rd < best_rd){ + best_rd= rd; + best_b_count= j; + } + } + + av_freep(&outbuf); + avcodec_close(c); + av_freep(&c); + + for(i=0; imax_b_frames+2; i++){ + av_freep(&input[i].data[0]); + } + + return best_b_count; +} + +static void select_input_picture(MpegEncContext *s){ + int i; + + for(i=1; ireordered_input_picture[i-1]= s->reordered_input_picture[i]; + s->reordered_input_picture[MAX_PICTURE_COUNT-1]= NULL; + + /* set next picture type & ordering */ + if(s->reordered_input_picture[0]==NULL && s->input_picture[0]){ + if(/*s->picture_in_gop_number >= s->gop_size ||*/ s->next_picture_ptr==NULL || s->intra_only){ + s->reordered_input_picture[0]= s->input_picture[0]; + s->reordered_input_picture[0]->pict_type= I_TYPE; + s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++; + }else{ + int b_frames; + + if(s->avctx->frame_skip_threshold || s->avctx->frame_skip_factor){ + if(s->picture_in_gop_number < s->gop_size && skip_check(s, s->input_picture[0], s->next_picture_ptr)){ + //FIXME check that te gop check above is +-1 correct +//av_log(NULL, AV_LOG_DEBUG, "skip %p %"PRId64"\n", s->input_picture[0]->data[0], s->input_picture[0]->pts); + + if(s->input_picture[0]->type == FF_BUFFER_TYPE_SHARED){ + for(i=0; i<4; i++) + s->input_picture[0]->data[i]= NULL; + s->input_picture[0]->type= 0; + }else{ + assert( s->input_picture[0]->type==FF_BUFFER_TYPE_USER + || s->input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL); + + s->avctx->release_buffer(s->avctx, (AVFrame*)s->input_picture[0]); + } + + emms_c(); + ff_vbv_update(s, 0); + + goto no_output_pic; + } + } + + if(s->flags&CODEC_FLAG_PASS2){ + for(i=0; imax_b_frames+1; i++){ + int pict_num= s->input_picture[0]->display_picture_number + i; + + if(pict_num >= s->rc_context.num_entries) + break; + if(!s->input_picture[i]){ + s->rc_context.entry[pict_num-1].new_pict_type = P_TYPE; + break; + } + + s->input_picture[i]->pict_type= + s->rc_context.entry[pict_num].new_pict_type; + } + } + + if(s->avctx->b_frame_strategy==0){ + b_frames= s->max_b_frames; + while(b_frames && !s->input_picture[b_frames]) b_frames--; + }else if(s->avctx->b_frame_strategy==1){ + for(i=1; imax_b_frames+1; i++){ + if(s->input_picture[i] && s->input_picture[i]->b_frame_score==0){ + s->input_picture[i]->b_frame_score= + get_intra_count(s, s->input_picture[i ]->data[0], + s->input_picture[i-1]->data[0], s->linesize) + 1; + } + } + for(i=0; imax_b_frames+1; i++){ + if(s->input_picture[i]==NULL || s->input_picture[i]->b_frame_score - 1 > s->mb_num/s->avctx->b_sensitivity) break; + } + + b_frames= FFMAX(0, i-1); + + /* reset scores */ + for(i=0; iinput_picture[i]->b_frame_score=0; + } + }else if(s->avctx->b_frame_strategy==2){ + b_frames= estimate_best_b_count(s); + }else{ + av_log(s->avctx, AV_LOG_ERROR, "illegal b frame strategy\n"); + b_frames=0; + } + + emms_c(); +//static int b_count=0; +//b_count+= b_frames; +//av_log(s->avctx, AV_LOG_DEBUG, "b_frames: %d\n", b_count); + + for(i= b_frames - 1; i>=0; i--){ + int type= s->input_picture[i]->pict_type; + if(type && type != B_TYPE) + b_frames= i; + } + if(s->input_picture[b_frames]->pict_type == B_TYPE && b_frames == s->max_b_frames){ + av_log(s->avctx, AV_LOG_ERROR, "warning, too many b frames in a row\n"); + } + + if(s->picture_in_gop_number + b_frames >= s->gop_size){ + if((s->flags2 & CODEC_FLAG2_STRICT_GOP) && s->gop_size > s->picture_in_gop_number){ + b_frames= s->gop_size - s->picture_in_gop_number - 1; + }else{ + if(s->flags & CODEC_FLAG_CLOSED_GOP) + b_frames=0; + s->input_picture[b_frames]->pict_type= I_TYPE; + } + } + + if( (s->flags & CODEC_FLAG_CLOSED_GOP) + && b_frames + && s->input_picture[b_frames]->pict_type== I_TYPE) + b_frames--; + + s->reordered_input_picture[0]= s->input_picture[b_frames]; + if(s->reordered_input_picture[0]->pict_type != I_TYPE) + s->reordered_input_picture[0]->pict_type= P_TYPE; + s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++; + for(i=0; ireordered_input_picture[i+1]= s->input_picture[i]; + s->reordered_input_picture[i+1]->pict_type= B_TYPE; + s->reordered_input_picture[i+1]->coded_picture_number= s->coded_picture_number++; + } + } + } +no_output_pic: + if(s->reordered_input_picture[0]){ + s->reordered_input_picture[0]->reference= s->reordered_input_picture[0]->pict_type!=B_TYPE ? 3 : 0; + + copy_picture(&s->new_picture, s->reordered_input_picture[0]); + + if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_SHARED || s->avctx->rc_buffer_size){ + // input is a shared pix, so we can't modifiy it -> alloc a new one & ensure that the shared one is reuseable + + int i= ff_find_unused_picture(s, 0); + Picture *pic= &s->picture[i]; + + pic->reference = s->reordered_input_picture[0]->reference; + alloc_picture(s, pic, 0); + + /* mark us unused / free shared pic */ + if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_INTERNAL) + s->avctx->release_buffer(s->avctx, (AVFrame*)s->reordered_input_picture[0]); + for(i=0; i<4; i++) + s->reordered_input_picture[0]->data[i]= NULL; + s->reordered_input_picture[0]->type= 0; + + copy_picture_attributes(s, (AVFrame*)pic, (AVFrame*)s->reordered_input_picture[0]); + + s->current_picture_ptr= pic; + }else{ + // input is not a shared pix -> reuse buffer for current_pix + + assert( s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_USER + || s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL); + + s->current_picture_ptr= s->reordered_input_picture[0]; + for(i=0; i<4; i++){ + s->new_picture.data[i]+= INPLACE_OFFSET; + } + } + copy_picture(&s->current_picture, s->current_picture_ptr); + + s->picture_number= s->new_picture.display_picture_number; +//printf("dpn:%d\n", s->picture_number); + }else{ + memset(&s->new_picture, 0, sizeof(Picture)); + } +} + +int MPV_encode_picture(AVCodecContext *avctx, + unsigned char *buf, int buf_size, void *data) +{ + MpegEncContext *s = avctx->priv_data; + AVFrame *pic_arg = data; + int i, stuffing_count; + + for(i=0; ithread_count; i++){ + int start_y= s->thread_context[i]->start_mb_y; + int end_y= s->thread_context[i]-> end_mb_y; + int h= s->mb_height; + uint8_t *start= buf + (size_t)(((int64_t) buf_size)*start_y/h); + uint8_t *end = buf + (size_t)(((int64_t) buf_size)* end_y/h); + + init_put_bits(&s->thread_context[i]->pb, start, end - start); + } + + s->picture_in_gop_number++; + + if(load_input_picture(s, pic_arg) < 0) + return -1; + + select_input_picture(s); + + /* output? */ + if(s->new_picture.data[0]){ + s->pict_type= s->new_picture.pict_type; +//emms_c(); +//printf("qs:%f %f %d\n", s->new_picture.quality, s->current_picture.quality, s->qscale); + MPV_frame_start(s, avctx); +vbv_retry: + if (encode_picture(s, s->picture_number) < 0) + return -1; + + avctx->real_pict_num = s->picture_number; + avctx->header_bits = s->header_bits; + avctx->mv_bits = s->mv_bits; + avctx->misc_bits = s->misc_bits; + avctx->i_tex_bits = s->i_tex_bits; + avctx->p_tex_bits = s->p_tex_bits; + avctx->i_count = s->i_count; + avctx->p_count = s->mb_num - s->i_count - s->skip_count; //FIXME f/b_count in avctx + avctx->skip_count = s->skip_count; + + MPV_frame_end(s); + + if (ENABLE_MJPEG_ENCODER && s->out_format == FMT_MJPEG) + ff_mjpeg_encode_picture_trailer(s); + + if(avctx->rc_buffer_size){ + RateControlContext *rcc= &s->rc_context; + int max_size= rcc->buffer_index/3; + + if(put_bits_count(&s->pb) > max_size && s->lambda < s->avctx->lmax){ + s->next_lambda= FFMAX(s->lambda+1, s->lambda*(s->qscale+1) / s->qscale); + if(s->adaptive_quant){ + int i; + for(i=0; imb_height*s->mb_stride; i++) + s->lambda_table[i]= FFMAX(s->lambda_table[i]+1, s->lambda_table[i]*(s->qscale+1) / s->qscale); + } + s->mb_skipped = 0; //done in MPV_frame_start() + if(s->pict_type==P_TYPE){ //done in encode_picture() so we must undo it + if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4) + s->no_rounding ^= 1; + } + if(s->pict_type!=B_TYPE){ + s->time_base= s->last_time_base; + s->last_non_b_time= s->time - s->pp_time; + } +// av_log(NULL, AV_LOG_ERROR, "R:%d ", s->next_lambda); + for(i=0; ithread_count; i++){ + PutBitContext *pb= &s->thread_context[i]->pb; + init_put_bits(pb, pb->buf, pb->buf_end - pb->buf); + } + goto vbv_retry; + } + + assert(s->avctx->rc_max_rate); + } + + if(s->flags&CODEC_FLAG_PASS1) + ff_write_pass1_stats(s); + + for(i=0; i<4; i++){ + s->current_picture_ptr->error[i]= s->current_picture.error[i]; + avctx->error[i] += s->current_picture_ptr->error[i]; + } + + if(s->flags&CODEC_FLAG_PASS1) + assert(avctx->header_bits + avctx->mv_bits + avctx->misc_bits + avctx->i_tex_bits + avctx->p_tex_bits == put_bits_count(&s->pb)); + flush_put_bits(&s->pb); + s->frame_bits = put_bits_count(&s->pb); + + stuffing_count= ff_vbv_update(s, s->frame_bits); + if(stuffing_count){ + if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < stuffing_count + 50){ + av_log(s->avctx, AV_LOG_ERROR, "stuffing too large\n"); + return -1; + } + + switch(s->codec_id){ + case CODEC_ID_MPEG1VIDEO: + case CODEC_ID_MPEG2VIDEO: + while(stuffing_count--){ + put_bits(&s->pb, 8, 0); + } + break; + case CODEC_ID_MPEG4: + put_bits(&s->pb, 16, 0); + put_bits(&s->pb, 16, 0x1C3); + stuffing_count -= 4; + while(stuffing_count--){ + put_bits(&s->pb, 8, 0xFF); + } + break; + default: + av_log(s->avctx, AV_LOG_ERROR, "vbv buffer overflow\n"); + } + flush_put_bits(&s->pb); + s->frame_bits = put_bits_count(&s->pb); + } + + /* update mpeg1/2 vbv_delay for CBR */ + if(s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate && s->out_format == FMT_MPEG1 + && 90000LL * (avctx->rc_buffer_size-1) <= s->avctx->rc_max_rate*0xFFFFLL){ + int vbv_delay; + + assert(s->repeat_first_field==0); + + vbv_delay= lrintf(90000 * s->rc_context.buffer_index / s->avctx->rc_max_rate); + assert(vbv_delay < 0xFFFF); + + s->vbv_delay_ptr[0] &= 0xF8; + s->vbv_delay_ptr[0] |= vbv_delay>>13; + s->vbv_delay_ptr[1] = vbv_delay>>5; + s->vbv_delay_ptr[2] &= 0x07; + s->vbv_delay_ptr[2] |= vbv_delay<<3; + } + s->total_bits += s->frame_bits; + avctx->frame_bits = s->frame_bits; + }else{ + assert((pbBufPtr(&s->pb) == s->pb.buf)); + s->frame_bits=0; + } + assert((s->frame_bits&7)==0); + + return s->frame_bits/8; +} + +static inline void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold) +{ + static const char tab[64]= + {3,2,2,1,1,1,1,1, + 1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0}; + int score=0; + int run=0; + int i; + DCTELEM *block= s->block[n]; + const int last_index= s->block_last_index[n]; + int skip_dc; + + if(threshold<0){ + skip_dc=0; + threshold= -threshold; + }else + skip_dc=1; + + /* are all which we could set to zero are allready zero? */ + if(last_index<=skip_dc - 1) return; + + for(i=0; i<=last_index; i++){ + const int j = s->intra_scantable.permutated[i]; + const int level = FFABS(block[j]); + if(level==1){ + if(skip_dc && i==0) continue; + score+= tab[run]; + run=0; + }else if(level>1){ + return; + }else{ + run++; + } + } + if(score >= threshold) return; + for(i=skip_dc; i<=last_index; i++){ + const int j = s->intra_scantable.permutated[i]; + block[j]=0; + } + if(block[0]) s->block_last_index[n]= 0; + else s->block_last_index[n]= -1; +} + +static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index) +{ + int i; + const int maxlevel= s->max_qcoeff; + const int minlevel= s->min_qcoeff; + int overflow=0; + + if(s->mb_intra){ + i=1; //skip clipping of intra dc + }else + i=0; + + for(;i<=last_index; i++){ + const int j= s->intra_scantable.permutated[i]; + int level = block[j]; + + if (level>maxlevel){ + level=maxlevel; + overflow++; + }else if(levelavctx->mb_decision == FF_MB_DECISION_SIMPLE) + av_log(s->avctx, AV_LOG_INFO, "warning, clipping %d dct coefficients to %d..%d\n", overflow, minlevel, maxlevel); +} + +static void get_visual_weight(int16_t *weight, uint8_t *ptr, int stride){ + int x, y; +//FIXME optimize + for(y=0; y<8; y++){ + for(x=0; x<8; x++){ + int x2, y2; + int sum=0; + int sqr=0; + int count=0; + + for(y2= FFMAX(y-1, 0); y2 < FFMIN(8, y+2); y2++){ + for(x2= FFMAX(x-1, 0); x2 < FFMIN(8, x+2); x2++){ + int v= ptr[x2 + y2*stride]; + sum += v; + sqr += v*v; + count++; + } + } + weight[x + 8*y]= (36*ff_sqrt(count*sqr - sum*sum)) / count; + } + } +} + +static av_always_inline void encode_mb_internal(MpegEncContext *s, int motion_x, int motion_y, int mb_block_height, int mb_block_count) +{ + int16_t weight[8][64]; + DCTELEM orig[8][64]; + const int mb_x= s->mb_x; + const int mb_y= s->mb_y; + int i; + int skip_dct[8]; + int dct_offset = s->linesize*8; //default for progressive frames + uint8_t *ptr_y, *ptr_cb, *ptr_cr; + int wrap_y, wrap_c; + + for(i=0; iskipdct; + + if(s->adaptive_quant){ + const int last_qp= s->qscale; + const int mb_xy= mb_x + mb_y*s->mb_stride; + + s->lambda= s->lambda_table[mb_xy]; + update_qscale(s); + + if(!(s->flags&CODEC_FLAG_QP_RD)){ + s->qscale= s->current_picture_ptr->qscale_table[mb_xy]; + s->dquant= s->qscale - last_qp; + + if(s->out_format==FMT_H263){ + s->dquant= av_clip(s->dquant, -2, 2); + + if(s->codec_id==CODEC_ID_MPEG4){ + if(!s->mb_intra){ + if(s->pict_type == B_TYPE){ + if(s->dquant&1 || s->mv_dir&MV_DIRECT) + s->dquant= 0; + } + if(s->mv_type==MV_TYPE_8X8) + s->dquant=0; + } + } + } + } + ff_set_qscale(s, last_qp + s->dquant); + }else if(s->flags&CODEC_FLAG_QP_RD) + ff_set_qscale(s, s->qscale + s->dquant); + + wrap_y = s->linesize; + wrap_c = s->uvlinesize; + ptr_y = s->new_picture.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16; + ptr_cb = s->new_picture.data[1] + (mb_y * mb_block_height * wrap_c) + mb_x * 8; + ptr_cr = s->new_picture.data[2] + (mb_y * mb_block_height * wrap_c) + mb_x * 8; + + if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){ + uint8_t *ebuf= s->edge_emu_buffer + 32; + ff_emulated_edge_mc(ebuf , ptr_y , wrap_y,16,16,mb_x*16,mb_y*16, s->width , s->height); + ptr_y= ebuf; + ff_emulated_edge_mc(ebuf+18*wrap_y , ptr_cb, wrap_c, 8, mb_block_height, mb_x*8, mb_y*8, s->width>>1, s->height>>1); + ptr_cb= ebuf+18*wrap_y; + ff_emulated_edge_mc(ebuf+18*wrap_y+8, ptr_cr, wrap_c, 8, mb_block_height, mb_x*8, mb_y*8, s->width>>1, s->height>>1); + ptr_cr= ebuf+18*wrap_y+8; + } + + if (s->mb_intra) { + if(s->flags&CODEC_FLAG_INTERLACED_DCT){ + int progressive_score, interlaced_score; + + s->interlaced_dct=0; + progressive_score= s->dsp.ildct_cmp[4](s, ptr_y , NULL, wrap_y, 8) + +s->dsp.ildct_cmp[4](s, ptr_y + wrap_y*8, NULL, wrap_y, 8) - 400; + + if(progressive_score > 0){ + interlaced_score = s->dsp.ildct_cmp[4](s, ptr_y , NULL, wrap_y*2, 8) + +s->dsp.ildct_cmp[4](s, ptr_y + wrap_y , NULL, wrap_y*2, 8); + if(progressive_score > interlaced_score){ + s->interlaced_dct=1; + + dct_offset= wrap_y; + wrap_y<<=1; + if (s->chroma_format == CHROMA_422) + wrap_c<<=1; + } + } + } + + s->dsp.get_pixels(s->block[0], ptr_y , wrap_y); + s->dsp.get_pixels(s->block[1], ptr_y + 8, wrap_y); + s->dsp.get_pixels(s->block[2], ptr_y + dct_offset , wrap_y); + s->dsp.get_pixels(s->block[3], ptr_y + dct_offset + 8, wrap_y); + + if(s->flags&CODEC_FLAG_GRAY){ + skip_dct[4]= 1; + skip_dct[5]= 1; + }else{ + s->dsp.get_pixels(s->block[4], ptr_cb, wrap_c); + s->dsp.get_pixels(s->block[5], ptr_cr, wrap_c); + if(!s->chroma_y_shift){ /* 422 */ + s->dsp.get_pixels(s->block[6], ptr_cb + (dct_offset>>1), wrap_c); + s->dsp.get_pixels(s->block[7], ptr_cr + (dct_offset>>1), wrap_c); + } + } + }else{ + op_pixels_func (*op_pix)[4]; + qpel_mc_func (*op_qpix)[16]; + uint8_t *dest_y, *dest_cb, *dest_cr; + + dest_y = s->dest[0]; + dest_cb = s->dest[1]; + dest_cr = s->dest[2]; + + if ((!s->no_rounding) || s->pict_type==B_TYPE){ + op_pix = s->dsp.put_pixels_tab; + op_qpix= s->dsp.put_qpel_pixels_tab; + }else{ + op_pix = s->dsp.put_no_rnd_pixels_tab; + op_qpix= s->dsp.put_no_rnd_qpel_pixels_tab; + } + + if (s->mv_dir & MV_DIR_FORWARD) { + MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix, op_qpix); + op_pix = s->dsp.avg_pixels_tab; + op_qpix= s->dsp.avg_qpel_pixels_tab; + } + if (s->mv_dir & MV_DIR_BACKWARD) { + MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix); + } + + if(s->flags&CODEC_FLAG_INTERLACED_DCT){ + int progressive_score, interlaced_score; + + s->interlaced_dct=0; + progressive_score= s->dsp.ildct_cmp[0](s, dest_y , ptr_y , wrap_y, 8) + +s->dsp.ildct_cmp[0](s, dest_y + wrap_y*8, ptr_y + wrap_y*8, wrap_y, 8) - 400; + + if(s->avctx->ildct_cmp == FF_CMP_VSSE) progressive_score -= 400; + + if(progressive_score>0){ + interlaced_score = s->dsp.ildct_cmp[0](s, dest_y , ptr_y , wrap_y*2, 8) + +s->dsp.ildct_cmp[0](s, dest_y + wrap_y , ptr_y + wrap_y , wrap_y*2, 8); + + if(progressive_score > interlaced_score){ + s->interlaced_dct=1; + + dct_offset= wrap_y; + wrap_y<<=1; + if (s->chroma_format == CHROMA_422) + wrap_c<<=1; + } + } + } + + s->dsp.diff_pixels(s->block[0], ptr_y , dest_y , wrap_y); + s->dsp.diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y); + s->dsp.diff_pixels(s->block[2], ptr_y + dct_offset , dest_y + dct_offset , wrap_y); + s->dsp.diff_pixels(s->block[3], ptr_y + dct_offset + 8, dest_y + dct_offset + 8, wrap_y); + + if(s->flags&CODEC_FLAG_GRAY){ + skip_dct[4]= 1; + skip_dct[5]= 1; + }else{ + s->dsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c); + s->dsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c); + if(!s->chroma_y_shift){ /* 422 */ + s->dsp.diff_pixels(s->block[6], ptr_cb + (dct_offset>>1), dest_cb + (dct_offset>>1), wrap_c); + s->dsp.diff_pixels(s->block[7], ptr_cr + (dct_offset>>1), dest_cr + (dct_offset>>1), wrap_c); + } + } + /* pre quantization */ + if(s->current_picture.mc_mb_var[s->mb_stride*mb_y+ mb_x]<2*s->qscale*s->qscale){ + //FIXME optimize + if(s->dsp.sad[1](NULL, ptr_y , dest_y , wrap_y, 8) < 20*s->qscale) skip_dct[0]= 1; + if(s->dsp.sad[1](NULL, ptr_y + 8, dest_y + 8, wrap_y, 8) < 20*s->qscale) skip_dct[1]= 1; + if(s->dsp.sad[1](NULL, ptr_y +dct_offset , dest_y +dct_offset , wrap_y, 8) < 20*s->qscale) skip_dct[2]= 1; + if(s->dsp.sad[1](NULL, ptr_y +dct_offset+ 8, dest_y +dct_offset+ 8, wrap_y, 8) < 20*s->qscale) skip_dct[3]= 1; + if(s->dsp.sad[1](NULL, ptr_cb , dest_cb , wrap_c, 8) < 20*s->qscale) skip_dct[4]= 1; + if(s->dsp.sad[1](NULL, ptr_cr , dest_cr , wrap_c, 8) < 20*s->qscale) skip_dct[5]= 1; + if(!s->chroma_y_shift){ /* 422 */ + if(s->dsp.sad[1](NULL, ptr_cb +(dct_offset>>1), dest_cb +(dct_offset>>1), wrap_c, 8) < 20*s->qscale) skip_dct[6]= 1; + if(s->dsp.sad[1](NULL, ptr_cr +(dct_offset>>1), dest_cr +(dct_offset>>1), wrap_c, 8) < 20*s->qscale) skip_dct[7]= 1; + } + } + } + + if(s->avctx->quantizer_noise_shaping){ + if(!skip_dct[0]) get_visual_weight(weight[0], ptr_y , wrap_y); + if(!skip_dct[1]) get_visual_weight(weight[1], ptr_y + 8, wrap_y); + if(!skip_dct[2]) get_visual_weight(weight[2], ptr_y + dct_offset , wrap_y); + if(!skip_dct[3]) get_visual_weight(weight[3], ptr_y + dct_offset + 8, wrap_y); + if(!skip_dct[4]) get_visual_weight(weight[4], ptr_cb , wrap_c); + if(!skip_dct[5]) get_visual_weight(weight[5], ptr_cr , wrap_c); + if(!s->chroma_y_shift){ /* 422 */ + if(!skip_dct[6]) get_visual_weight(weight[6], ptr_cb + (dct_offset>>1), wrap_c); + if(!skip_dct[7]) get_visual_weight(weight[7], ptr_cr + (dct_offset>>1), wrap_c); + } + memcpy(orig[0], s->block[0], sizeof(DCTELEM)*64*mb_block_count); + } + + /* DCT & quantize */ + assert(s->out_format!=FMT_MJPEG || s->qscale==8); + { + for(i=0;iblock_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow); + // FIXME we could decide to change to quantizer instead of clipping + // JS: I don't think that would be a good idea it could lower quality instead + // of improve it. Just INTRADC clipping deserves changes in quantizer + if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); + }else + s->block_last_index[i]= -1; + } + if(s->avctx->quantizer_noise_shaping){ + for(i=0;iblock_last_index[i] = dct_quantize_refine(s, s->block[i], weight[i], orig[i], i, s->qscale); + } + } + } + + if(s->luma_elim_threshold && !s->mb_intra) + for(i=0; i<4; i++) + dct_single_coeff_elimination(s, i, s->luma_elim_threshold); + if(s->chroma_elim_threshold && !s->mb_intra) + for(i=4; ichroma_elim_threshold); + + if(s->flags & CODEC_FLAG_CBP_RD){ + for(i=0;iblock_last_index[i] == -1) + s->coded_score[i]= INT_MAX/256; + } + } + } + + if((s->flags&CODEC_FLAG_GRAY) && s->mb_intra){ + s->block_last_index[4]= + s->block_last_index[5]= 0; + s->block[4][0]= + s->block[5][0]= (1024 + s->c_dc_scale/2)/ s->c_dc_scale; + } + + //non c quantize code returns incorrect block_last_index FIXME + if(s->alternate_scan && s->dct_quantize != dct_quantize_c){ + for(i=0; iblock_last_index[i]>0){ + for(j=63; j>0; j--){ + if(s->block[i][ s->intra_scantable.permutated[j] ]) break; + } + s->block_last_index[i]= j; + } + } + } + + /* huffman encode */ + switch(s->codec_id){ //FIXME funct ptr could be slightly faster + case CODEC_ID_MPEG1VIDEO: + case CODEC_ID_MPEG2VIDEO: + if (ENABLE_MPEG1VIDEO_ENCODER || ENABLE_MPEG2VIDEO_ENCODER) + mpeg1_encode_mb(s, s->block, motion_x, motion_y); + break; + case CODEC_ID_MPEG4: + if (ENABLE_MPEG4_ENCODER) + mpeg4_encode_mb(s, s->block, motion_x, motion_y); + break; + case CODEC_ID_MSMPEG4V2: + case CODEC_ID_MSMPEG4V3: + case CODEC_ID_WMV1: + if (ENABLE_MSMPEG4_ENCODER) + msmpeg4_encode_mb(s, s->block, motion_x, motion_y); + break; + case CODEC_ID_WMV2: + if (ENABLE_WMV2_ENCODER) + ff_wmv2_encode_mb(s, s->block, motion_x, motion_y); + break; + case CODEC_ID_H261: + if (ENABLE_H261_ENCODER) + ff_h261_encode_mb(s, s->block, motion_x, motion_y); + break; + case CODEC_ID_H263: + case CODEC_ID_H263P: + case CODEC_ID_FLV1: + case CODEC_ID_RV10: + case CODEC_ID_RV20: + if (ENABLE_H263_ENCODER || ENABLE_H263P_ENCODER || + ENABLE_FLV_ENCODER || ENABLE_RV10_ENCODER || ENABLE_RV20_ENCODER) + h263_encode_mb(s, s->block, motion_x, motion_y); + break; + case CODEC_ID_MJPEG: + if (ENABLE_MJPEG_ENCODER) + ff_mjpeg_encode_mb(s, s->block); + break; + default: + assert(0); + } +} + +static av_always_inline void encode_mb(MpegEncContext *s, int motion_x, int motion_y) +{ + if (s->chroma_format == CHROMA_420) encode_mb_internal(s, motion_x, motion_y, 8, 6); + else encode_mb_internal(s, motion_x, motion_y, 16, 8); +} + +static inline void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type){ + int i; + + memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? + + /* mpeg1 */ + d->mb_skip_run= s->mb_skip_run; + for(i=0; i<3; i++) + d->last_dc[i]= s->last_dc[i]; + + /* statistics */ + d->mv_bits= s->mv_bits; + d->i_tex_bits= s->i_tex_bits; + d->p_tex_bits= s->p_tex_bits; + d->i_count= s->i_count; + d->f_count= s->f_count; + d->b_count= s->b_count; + d->skip_count= s->skip_count; + d->misc_bits= s->misc_bits; + d->last_bits= 0; + + d->mb_skipped= 0; + d->qscale= s->qscale; + d->dquant= s->dquant; + + d->esc3_level_length= s->esc3_level_length; +} + +static inline void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type){ + int i; + + memcpy(d->mv, s->mv, 2*4*2*sizeof(int)); + memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? + + /* mpeg1 */ + d->mb_skip_run= s->mb_skip_run; + for(i=0; i<3; i++) + d->last_dc[i]= s->last_dc[i]; + + /* statistics */ + d->mv_bits= s->mv_bits; + d->i_tex_bits= s->i_tex_bits; + d->p_tex_bits= s->p_tex_bits; + d->i_count= s->i_count; + d->f_count= s->f_count; + d->b_count= s->b_count; + d->skip_count= s->skip_count; + d->misc_bits= s->misc_bits; + + d->mb_intra= s->mb_intra; + d->mb_skipped= s->mb_skipped; + d->mv_type= s->mv_type; + d->mv_dir= s->mv_dir; + d->pb= s->pb; + if(s->data_partitioning){ + d->pb2= s->pb2; + d->tex_pb= s->tex_pb; + } + d->block= s->block; + for(i=0; i<8; i++) + d->block_last_index[i]= s->block_last_index[i]; + d->interlaced_dct= s->interlaced_dct; + d->qscale= s->qscale; + + d->esc3_level_length= s->esc3_level_length; +} + +static inline void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegEncContext *best, int type, + PutBitContext pb[2], PutBitContext pb2[2], PutBitContext tex_pb[2], + int *dmin, int *next_block, int motion_x, int motion_y) +{ + int score; + uint8_t *dest_backup[3]; + + copy_context_before_encode(s, backup, type); + + s->block= s->blocks[*next_block]; + s->pb= pb[*next_block]; + if(s->data_partitioning){ + s->pb2 = pb2 [*next_block]; + s->tex_pb= tex_pb[*next_block]; + } + + if(*next_block){ + memcpy(dest_backup, s->dest, sizeof(s->dest)); + s->dest[0] = s->rd_scratchpad; + s->dest[1] = s->rd_scratchpad + 16*s->linesize; + s->dest[2] = s->rd_scratchpad + 16*s->linesize + 8; + assert(s->linesize >= 32); //FIXME + } + + encode_mb(s, motion_x, motion_y); + + score= put_bits_count(&s->pb); + if(s->data_partitioning){ + score+= put_bits_count(&s->pb2); + score+= put_bits_count(&s->tex_pb); + } + + if(s->avctx->mb_decision == FF_MB_DECISION_RD){ + MPV_decode_mb(s, s->block); + + score *= s->lambda2; + score += sse_mb(s) << FF_LAMBDA_SHIFT; + } + + if(*next_block){ + memcpy(s->dest, dest_backup, sizeof(s->dest)); + } + + if(score<*dmin){ + *dmin= score; + *next_block^=1; + + copy_context_after_encode(best, s, type); + } +} + +static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride){ + uint32_t *sq = ff_squareTbl + 256; + int acc=0; + int x,y; + + if(w==16 && h==16) + return s->dsp.sse[0](NULL, src1, src2, stride, 16); + else if(w==8 && h==8) + return s->dsp.sse[1](NULL, src1, src2, stride, 8); + + for(y=0; y=0); + + return acc; +} + +static int sse_mb(MpegEncContext *s){ + int w= 16; + int h= 16; + + if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16; + if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16; + + if(w==16 && h==16) + if(s->avctx->mb_cmp == FF_CMP_NSSE){ + return s->dsp.nsse[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16) + +s->dsp.nsse[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8) + +s->dsp.nsse[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8); + }else{ + return s->dsp.sse[0](NULL, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16) + +s->dsp.sse[1](NULL, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8) + +s->dsp.sse[1](NULL, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8); + } + else + return sse(s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], w, h, s->linesize) + +sse(s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], w>>1, h>>1, s->uvlinesize) + +sse(s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], w>>1, h>>1, s->uvlinesize); +} + +static int pre_estimate_motion_thread(AVCodecContext *c, void *arg){ + MpegEncContext *s= arg; + + + s->me.pre_pass=1; + s->me.dia_size= s->avctx->pre_dia_size; + s->first_slice_line=1; + for(s->mb_y= s->end_mb_y-1; s->mb_y >= s->start_mb_y; s->mb_y--) { + for(s->mb_x=s->mb_width-1; s->mb_x >=0 ;s->mb_x--) { + ff_pre_estimate_p_frame_motion(s, s->mb_x, s->mb_y); + } + s->first_slice_line=0; + } + + s->me.pre_pass=0; + + return 0; +} + +static int estimate_motion_thread(AVCodecContext *c, void *arg){ + MpegEncContext *s= arg; + + ff_check_alignment(); + + s->me.dia_size= s->avctx->dia_size; + s->first_slice_line=1; + for(s->mb_y= s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) { + s->mb_x=0; //for block init below + ff_init_block_index(s); + for(s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) { + s->block_index[0]+=2; + s->block_index[1]+=2; + s->block_index[2]+=2; + s->block_index[3]+=2; + + /* compute motion vector & mb_type and store in context */ + if(s->pict_type==B_TYPE) + ff_estimate_b_frame_motion(s, s->mb_x, s->mb_y); + else + ff_estimate_p_frame_motion(s, s->mb_x, s->mb_y); + } + s->first_slice_line=0; + } + return 0; +} + +static int mb_var_thread(AVCodecContext *c, void *arg){ + MpegEncContext *s= arg; + int mb_x, mb_y; + + ff_check_alignment(); + + for(mb_y=s->start_mb_y; mb_y < s->end_mb_y; mb_y++) { + for(mb_x=0; mb_x < s->mb_width; mb_x++) { + int xx = mb_x * 16; + int yy = mb_y * 16; + uint8_t *pix = s->new_picture.data[0] + (yy * s->linesize) + xx; + int varc; + int sum = s->dsp.pix_sum(pix, s->linesize); + + varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8; + + s->current_picture.mb_var [s->mb_stride * mb_y + mb_x] = varc; + s->current_picture.mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8; + s->me.mb_var_sum_temp += varc; + } + } + return 0; +} + +static void write_slice_end(MpegEncContext *s){ + if(ENABLE_MPEG4_ENCODER && s->codec_id==CODEC_ID_MPEG4){ + if(s->partitioned_frame){ + ff_mpeg4_merge_partitions(s); + } + + ff_mpeg4_stuffing(&s->pb); + }else if(ENABLE_MJPEG_ENCODER && s->out_format == FMT_MJPEG){ + ff_mjpeg_encode_stuffing(&s->pb); + } + + align_put_bits(&s->pb); + flush_put_bits(&s->pb); + + if((s->flags&CODEC_FLAG_PASS1) && !s->partitioned_frame) + s->misc_bits+= get_bits_diff(s); +} + +static int encode_thread(AVCodecContext *c, void *arg){ + MpegEncContext *s= arg; + int mb_x, mb_y, pdif = 0; + int i, j; + MpegEncContext best_s, backup_s; + uint8_t bit_buf[2][MAX_MB_BYTES]; + uint8_t bit_buf2[2][MAX_MB_BYTES]; + uint8_t bit_buf_tex[2][MAX_MB_BYTES]; + PutBitContext pb[2], pb2[2], tex_pb[2]; +//printf("%d->%d\n", s->resync_mb_y, s->end_mb_y); + + ff_check_alignment(); + + for(i=0; i<2; i++){ + init_put_bits(&pb [i], bit_buf [i], MAX_MB_BYTES); + init_put_bits(&pb2 [i], bit_buf2 [i], MAX_MB_BYTES); + init_put_bits(&tex_pb[i], bit_buf_tex[i], MAX_MB_BYTES); + } + + s->last_bits= put_bits_count(&s->pb); + s->mv_bits=0; + s->misc_bits=0; + s->i_tex_bits=0; + s->p_tex_bits=0; + s->i_count=0; + s->f_count=0; + s->b_count=0; + s->skip_count=0; + + for(i=0; i<3; i++){ + /* init last dc values */ + /* note: quant matrix value (8) is implied here */ + s->last_dc[i] = 128 << s->intra_dc_precision; + + s->current_picture.error[i] = 0; + } + s->mb_skip_run = 0; + memset(s->last_mv, 0, sizeof(s->last_mv)); + + s->last_mv_dir = 0; + + switch(s->codec_id){ + case CODEC_ID_H263: + case CODEC_ID_H263P: + case CODEC_ID_FLV1: + if (ENABLE_H263_ENCODER || ENABLE_H263P_ENCODER || ENABLE_FLV_ENCODER) + s->gob_index = ff_h263_get_gob_height(s); + break; + case CODEC_ID_MPEG4: + if(ENABLE_MPEG4_ENCODER && s->partitioned_frame) + ff_mpeg4_init_partitions(s); + break; + } + + s->resync_mb_x=0; + s->resync_mb_y=0; + s->first_slice_line = 1; + s->ptr_lastgob = s->pb.buf; + for(mb_y= s->start_mb_y; mb_y < s->end_mb_y; mb_y++) { +// printf("row %d at %X\n", s->mb_y, (int)s); + s->mb_x=0; + s->mb_y= mb_y; + + ff_set_qscale(s, s->qscale); + ff_init_block_index(s); + + for(mb_x=0; mb_x < s->mb_width; mb_x++) { + int xy= mb_y*s->mb_stride + mb_x; // removed const, H261 needs to adjust this + int mb_type= s->mb_type[xy]; +// int d; + int dmin= INT_MAX; + int dir; + + if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < MAX_MB_BYTES){ + av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); + return -1; + } + if(s->data_partitioning){ + if( s->pb2 .buf_end - s->pb2 .buf - (put_bits_count(&s-> pb2)>>3) < MAX_MB_BYTES + || s->tex_pb.buf_end - s->tex_pb.buf - (put_bits_count(&s->tex_pb )>>3) < MAX_MB_BYTES){ + av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); + return -1; + } + } + + s->mb_x = mb_x; + s->mb_y = mb_y; // moved into loop, can get changed by H.261 + ff_update_block_index(s); + + if(ENABLE_H261_ENCODER && s->codec_id == CODEC_ID_H261){ + ff_h261_reorder_mb_index(s); + xy= s->mb_y*s->mb_stride + s->mb_x; + mb_type= s->mb_type[xy]; + } + + /* write gob / video packet header */ + if(s->rtp_mode){ + int current_packet_size, is_gob_start; + + current_packet_size= ((put_bits_count(&s->pb)+7)>>3) - (s->ptr_lastgob - s->pb.buf); + + is_gob_start= s->avctx->rtp_payload_size && current_packet_size >= s->avctx->rtp_payload_size && mb_y + mb_x>0; + + if(s->start_mb_y == mb_y && mb_y > 0 && mb_x==0) is_gob_start=1; + + switch(s->codec_id){ + case CODEC_ID_H263: + case CODEC_ID_H263P: + if(!s->h263_slice_structured) + if(s->mb_x || s->mb_y%s->gob_index) is_gob_start=0; + break; + case CODEC_ID_MPEG2VIDEO: + if(s->mb_x==0 && s->mb_y!=0) is_gob_start=1; + case CODEC_ID_MPEG1VIDEO: + if(s->mb_skip_run) is_gob_start=0; + break; + } + + if(is_gob_start){ + if(s->start_mb_y != mb_y || mb_x!=0){ + write_slice_end(s); + + if(ENABLE_MPEG4_ENCODER && s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame){ + ff_mpeg4_init_partitions(s); + } + } + + assert((put_bits_count(&s->pb)&7) == 0); + current_packet_size= pbBufPtr(&s->pb) - s->ptr_lastgob; + + if(s->avctx->error_rate && s->resync_mb_x + s->resync_mb_y > 0){ + int r= put_bits_count(&s->pb)/8 + s->picture_number + 16 + s->mb_x + s->mb_y; + int d= 100 / s->avctx->error_rate; + if(r % d == 0){ + current_packet_size=0; +#ifndef ALT_BITSTREAM_WRITER + s->pb.buf_ptr= s->ptr_lastgob; +#endif + assert(pbBufPtr(&s->pb) == s->ptr_lastgob); + } + } + + if (s->avctx->rtp_callback){ + int number_mb = (mb_y - s->resync_mb_y)*s->mb_width + mb_x - s->resync_mb_x; + s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, current_packet_size, number_mb); + } + + switch(s->codec_id){ + case CODEC_ID_MPEG4: + if (ENABLE_MPEG4_ENCODER) { + ff_mpeg4_encode_video_packet_header(s); + ff_mpeg4_clean_buffers(s); + } + break; + case CODEC_ID_MPEG1VIDEO: + case CODEC_ID_MPEG2VIDEO: + if (ENABLE_MPEG1VIDEO_ENCODER || ENABLE_MPEG2VIDEO_ENCODER) { + ff_mpeg1_encode_slice_header(s); + ff_mpeg1_clean_buffers(s); + } + break; + case CODEC_ID_H263: + case CODEC_ID_H263P: + if (ENABLE_H263_ENCODER || ENABLE_H263P_ENCODER) + h263_encode_gob_header(s, mb_y); + break; + } + + if(s->flags&CODEC_FLAG_PASS1){ + int bits= put_bits_count(&s->pb); + s->misc_bits+= bits - s->last_bits; + s->last_bits= bits; + } + + s->ptr_lastgob += current_packet_size; + s->first_slice_line=1; + s->resync_mb_x=mb_x; + s->resync_mb_y=mb_y; + } + } + + if( (s->resync_mb_x == s->mb_x) + && s->resync_mb_y+1 == s->mb_y){ + s->first_slice_line=0; + } + + s->mb_skipped=0; + s->dquant=0; //only for QP_RD + + if(mb_type & (mb_type-1) || (s->flags & CODEC_FLAG_QP_RD)){ // more than 1 MB type possible or CODEC_FLAG_QP_RD + int next_block=0; + int pb_bits_count, pb2_bits_count, tex_pb_bits_count; + + copy_context_before_encode(&backup_s, s, -1); + backup_s.pb= s->pb; + best_s.data_partitioning= s->data_partitioning; + best_s.partitioned_frame= s->partitioned_frame; + if(s->data_partitioning){ + backup_s.pb2= s->pb2; + backup_s.tex_pb= s->tex_pb; + } + + if(mb_type&CANDIDATE_MB_TYPE_INTER){ + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; + s->mb_intra= 0; + s->mv[0][0][0] = s->p_mv_table[xy][0]; + s->mv[0][0][1] = s->p_mv_table[xy][1]; + encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER, pb, pb2, tex_pb, + &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); + } + if(mb_type&CANDIDATE_MB_TYPE_INTER_I){ + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_FIELD; + s->mb_intra= 0; + for(i=0; i<2; i++){ + j= s->field_select[0][i] = s->p_field_select_table[i][xy]; + s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0]; + s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1]; + } + encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER_I, pb, pb2, tex_pb, + &dmin, &next_block, 0, 0); + } + if(mb_type&CANDIDATE_MB_TYPE_SKIPPED){ + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; + s->mb_intra= 0; + s->mv[0][0][0] = 0; + s->mv[0][0][1] = 0; + encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_SKIPPED, pb, pb2, tex_pb, + &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); + } + if(mb_type&CANDIDATE_MB_TYPE_INTER4V){ + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_8X8; + s->mb_intra= 0; + for(i=0; i<4; i++){ + s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0]; + s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1]; + } + encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER4V, pb, pb2, tex_pb, + &dmin, &next_block, 0, 0); + } + if(mb_type&CANDIDATE_MB_TYPE_FORWARD){ + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; + s->mb_intra= 0; + s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; + s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; + encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD, pb, pb2, tex_pb, + &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); + } + if(mb_type&CANDIDATE_MB_TYPE_BACKWARD){ + s->mv_dir = MV_DIR_BACKWARD; + s->mv_type = MV_TYPE_16X16; + s->mb_intra= 0; + s->mv[1][0][0] = s->b_back_mv_table[xy][0]; + s->mv[1][0][1] = s->b_back_mv_table[xy][1]; + encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD, pb, pb2, tex_pb, + &dmin, &next_block, s->mv[1][0][0], s->mv[1][0][1]); + } + if(mb_type&CANDIDATE_MB_TYPE_BIDIR){ + s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; + s->mv_type = MV_TYPE_16X16; + s->mb_intra= 0; + s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; + s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; + s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; + s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; + encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR, pb, pb2, tex_pb, + &dmin, &next_block, 0, 0); + } + if(mb_type&CANDIDATE_MB_TYPE_FORWARD_I){ + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_FIELD; + s->mb_intra= 0; + for(i=0; i<2; i++){ + j= s->field_select[0][i] = s->b_field_select_table[0][i][xy]; + s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0]; + s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1]; + } + encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD_I, pb, pb2, tex_pb, + &dmin, &next_block, 0, 0); + } + if(mb_type&CANDIDATE_MB_TYPE_BACKWARD_I){ + s->mv_dir = MV_DIR_BACKWARD; + s->mv_type = MV_TYPE_FIELD; + s->mb_intra= 0; + for(i=0; i<2; i++){ + j= s->field_select[1][i] = s->b_field_select_table[1][i][xy]; + s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0]; + s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1]; + } + encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD_I, pb, pb2, tex_pb, + &dmin, &next_block, 0, 0); + } + if(mb_type&CANDIDATE_MB_TYPE_BIDIR_I){ + s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; + s->mv_type = MV_TYPE_FIELD; + s->mb_intra= 0; + for(dir=0; dir<2; dir++){ + for(i=0; i<2; i++){ + j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy]; + s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0]; + s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1]; + } + } + encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR_I, pb, pb2, tex_pb, + &dmin, &next_block, 0, 0); + } + if(mb_type&CANDIDATE_MB_TYPE_INTRA){ + s->mv_dir = 0; + s->mv_type = MV_TYPE_16X16; + s->mb_intra= 1; + s->mv[0][0][0] = 0; + s->mv[0][0][1] = 0; + encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTRA, pb, pb2, tex_pb, + &dmin, &next_block, 0, 0); + if(s->h263_pred || s->h263_aic){ + if(best_s.mb_intra) + s->mbintra_table[mb_x + mb_y*s->mb_stride]=1; + else + ff_clean_intra_table_entries(s); //old mode? + } + } + + if((s->flags & CODEC_FLAG_QP_RD) && dmin < INT_MAX){ + if(best_s.mv_type==MV_TYPE_16X16){ //FIXME move 4mv after QPRD + const int last_qp= backup_s.qscale; + int qpi, qp, dc[6]; + DCTELEM ac[6][16]; + const int mvdir= (best_s.mv_dir&MV_DIR_BACKWARD) ? 1 : 0; + static const int dquant_tab[4]={-1,1,-2,2}; + + assert(backup_s.dquant == 0); + + //FIXME intra + s->mv_dir= best_s.mv_dir; + s->mv_type = MV_TYPE_16X16; + s->mb_intra= best_s.mb_intra; + s->mv[0][0][0] = best_s.mv[0][0][0]; + s->mv[0][0][1] = best_s.mv[0][0][1]; + s->mv[1][0][0] = best_s.mv[1][0][0]; + s->mv[1][0][1] = best_s.mv[1][0][1]; + + qpi = s->pict_type == B_TYPE ? 2 : 0; + for(; qpi<4; qpi++){ + int dquant= dquant_tab[qpi]; + qp= last_qp + dquant; + if(qp < s->avctx->qmin || qp > s->avctx->qmax) + continue; + backup_s.dquant= dquant; + if(s->mb_intra && s->dc_val[0]){ + for(i=0; i<6; i++){ + dc[i]= s->dc_val[0][ s->block_index[i] ]; + memcpy(ac[i], s->ac_val[0][s->block_index[i]], sizeof(DCTELEM)*16); + } + } + + encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER /* wrong but unused */, pb, pb2, tex_pb, + &dmin, &next_block, s->mv[mvdir][0][0], s->mv[mvdir][0][1]); + if(best_s.qscale != qp){ + if(s->mb_intra && s->dc_val[0]){ + for(i=0; i<6; i++){ + s->dc_val[0][ s->block_index[i] ]= dc[i]; + memcpy(s->ac_val[0][s->block_index[i]], ac[i], sizeof(DCTELEM)*16); + } + } + } + } + } + } + if(ENABLE_MPEG4_ENCODER && mb_type&CANDIDATE_MB_TYPE_DIRECT){ + int mx= s->b_direct_mv_table[xy][0]; + int my= s->b_direct_mv_table[xy][1]; + + backup_s.dquant = 0; + s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; + s->mb_intra= 0; + ff_mpeg4_set_direct_mv(s, mx, my); + encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb, + &dmin, &next_block, mx, my); + } + if(ENABLE_MPEG4_ENCODER && mb_type&CANDIDATE_MB_TYPE_DIRECT0){ + backup_s.dquant = 0; + s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; + s->mb_intra= 0; + ff_mpeg4_set_direct_mv(s, 0, 0); + encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb, + &dmin, &next_block, 0, 0); + } + if(!best_s.mb_intra && s->flags2&CODEC_FLAG2_SKIP_RD){ + int coded=0; + for(i=0; i<6; i++) + coded |= s->block_last_index[i]; + if(coded){ + int mx,my; + memcpy(s->mv, best_s.mv, sizeof(s->mv)); + if(ENABLE_MPEG4_ENCODER && best_s.mv_dir & MV_DIRECT){ + mx=my=0; //FIXME find the one we actually used + ff_mpeg4_set_direct_mv(s, mx, my); + }else if(best_s.mv_dir&MV_DIR_BACKWARD){ + mx= s->mv[1][0][0]; + my= s->mv[1][0][1]; + }else{ + mx= s->mv[0][0][0]; + my= s->mv[0][0][1]; + } + + s->mv_dir= best_s.mv_dir; + s->mv_type = best_s.mv_type; + s->mb_intra= 0; +/* s->mv[0][0][0] = best_s.mv[0][0][0]; + s->mv[0][0][1] = best_s.mv[0][0][1]; + s->mv[1][0][0] = best_s.mv[1][0][0]; + s->mv[1][0][1] = best_s.mv[1][0][1];*/ + backup_s.dquant= 0; + s->skipdct=1; + encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER /* wrong but unused */, pb, pb2, tex_pb, + &dmin, &next_block, mx, my); + s->skipdct=0; + } + } + + s->current_picture.qscale_table[xy]= best_s.qscale; + + copy_context_after_encode(s, &best_s, -1); + + pb_bits_count= put_bits_count(&s->pb); + flush_put_bits(&s->pb); + ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count); + s->pb= backup_s.pb; + + if(s->data_partitioning){ + pb2_bits_count= put_bits_count(&s->pb2); + flush_put_bits(&s->pb2); + ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count); + s->pb2= backup_s.pb2; + + tex_pb_bits_count= put_bits_count(&s->tex_pb); + flush_put_bits(&s->tex_pb); + ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count); + s->tex_pb= backup_s.tex_pb; + } + s->last_bits= put_bits_count(&s->pb); + + if (ENABLE_ANY_H263_ENCODER && + s->out_format == FMT_H263 && s->pict_type!=B_TYPE) + ff_h263_update_motion_val(s); + + if(next_block==0){ //FIXME 16 vs linesize16 + s->dsp.put_pixels_tab[0][0](s->dest[0], s->rd_scratchpad , s->linesize ,16); + s->dsp.put_pixels_tab[1][0](s->dest[1], s->rd_scratchpad + 16*s->linesize , s->uvlinesize, 8); + s->dsp.put_pixels_tab[1][0](s->dest[2], s->rd_scratchpad + 16*s->linesize + 8, s->uvlinesize, 8); + } + + if(s->avctx->mb_decision == FF_MB_DECISION_BITS) + MPV_decode_mb(s, s->block); + } else { + int motion_x = 0, motion_y = 0; + s->mv_type=MV_TYPE_16X16; + // only one MB-Type possible + + switch(mb_type){ + case CANDIDATE_MB_TYPE_INTRA: + s->mv_dir = 0; + s->mb_intra= 1; + motion_x= s->mv[0][0][0] = 0; + motion_y= s->mv[0][0][1] = 0; + break; + case CANDIDATE_MB_TYPE_INTER: + s->mv_dir = MV_DIR_FORWARD; + s->mb_intra= 0; + motion_x= s->mv[0][0][0] = s->p_mv_table[xy][0]; + motion_y= s->mv[0][0][1] = s->p_mv_table[xy][1]; + break; + case CANDIDATE_MB_TYPE_INTER_I: + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_FIELD; + s->mb_intra= 0; + for(i=0; i<2; i++){ + j= s->field_select[0][i] = s->p_field_select_table[i][xy]; + s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0]; + s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1]; + } + break; + case CANDIDATE_MB_TYPE_INTER4V: + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_8X8; + s->mb_intra= 0; + for(i=0; i<4; i++){ + s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0]; + s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1]; + } + break; + case CANDIDATE_MB_TYPE_DIRECT: + if (ENABLE_MPEG4_ENCODER) { + s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD|MV_DIRECT; + s->mb_intra= 0; + motion_x=s->b_direct_mv_table[xy][0]; + motion_y=s->b_direct_mv_table[xy][1]; + ff_mpeg4_set_direct_mv(s, motion_x, motion_y); + } + break; + case CANDIDATE_MB_TYPE_DIRECT0: + if (ENABLE_MPEG4_ENCODER) { + s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD|MV_DIRECT; + s->mb_intra= 0; + ff_mpeg4_set_direct_mv(s, 0, 0); + } + break; + case CANDIDATE_MB_TYPE_BIDIR: + s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; + s->mb_intra= 0; + s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; + s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; + s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; + s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; + break; + case CANDIDATE_MB_TYPE_BACKWARD: + s->mv_dir = MV_DIR_BACKWARD; + s->mb_intra= 0; + motion_x= s->mv[1][0][0] = s->b_back_mv_table[xy][0]; + motion_y= s->mv[1][0][1] = s->b_back_mv_table[xy][1]; + break; + case CANDIDATE_MB_TYPE_FORWARD: + s->mv_dir = MV_DIR_FORWARD; + s->mb_intra= 0; + motion_x= s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; + motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; +// printf(" %d %d ", motion_x, motion_y); + break; + case CANDIDATE_MB_TYPE_FORWARD_I: + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_FIELD; + s->mb_intra= 0; + for(i=0; i<2; i++){ + j= s->field_select[0][i] = s->b_field_select_table[0][i][xy]; + s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0]; + s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1]; + } + break; + case CANDIDATE_MB_TYPE_BACKWARD_I: + s->mv_dir = MV_DIR_BACKWARD; + s->mv_type = MV_TYPE_FIELD; + s->mb_intra= 0; + for(i=0; i<2; i++){ + j= s->field_select[1][i] = s->b_field_select_table[1][i][xy]; + s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0]; + s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1]; + } + break; + case CANDIDATE_MB_TYPE_BIDIR_I: + s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; + s->mv_type = MV_TYPE_FIELD; + s->mb_intra= 0; + for(dir=0; dir<2; dir++){ + for(i=0; i<2; i++){ + j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy]; + s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0]; + s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1]; + } + } + break; + default: + av_log(s->avctx, AV_LOG_ERROR, "illegal MB type\n"); + } + + encode_mb(s, motion_x, motion_y); + + // RAL: Update last macroblock type + s->last_mv_dir = s->mv_dir; + + if (ENABLE_ANY_H263_ENCODER && + s->out_format == FMT_H263 && s->pict_type!=B_TYPE) + ff_h263_update_motion_val(s); + + MPV_decode_mb(s, s->block); + } + + /* clean the MV table in IPS frames for direct mode in B frames */ + if(s->mb_intra /* && I,P,S_TYPE */){ + s->p_mv_table[xy][0]=0; + s->p_mv_table[xy][1]=0; + } + + if(s->flags&CODEC_FLAG_PSNR){ + int w= 16; + int h= 16; + + if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16; + if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16; + + s->current_picture.error[0] += sse( + s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, + s->dest[0], w, h, s->linesize); + s->current_picture.error[1] += sse( + s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8, + s->dest[1], w>>1, h>>1, s->uvlinesize); + s->current_picture.error[2] += sse( + s, s->new_picture .data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8, + s->dest[2], w>>1, h>>1, s->uvlinesize); + } + if(s->loop_filter){ + if(ENABLE_ANY_H263_ENCODER && s->out_format == FMT_H263) + ff_h263_loop_filter(s); + } +//printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_stride, put_bits_count(&s->pb)); + } + } + + //not beautiful here but we must write it before flushing so it has to be here + if (ENABLE_MSMPEG4_ENCODER && s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == I_TYPE) + msmpeg4_encode_ext_header(s); + + write_slice_end(s); + + /* Send the last GOB if RTP */ + if (s->avctx->rtp_callback) { + int number_mb = (mb_y - s->resync_mb_y)*s->mb_width - s->resync_mb_x; + pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; + /* Call the RTP callback to send the last GOB */ + emms_c(); + s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, pdif, number_mb); + } + + return 0; +} + +#define MERGE(field) dst->field += src->field; src->field=0 +static void merge_context_after_me(MpegEncContext *dst, MpegEncContext *src){ + MERGE(me.scene_change_score); + MERGE(me.mc_mb_var_sum_temp); + MERGE(me.mb_var_sum_temp); +} + +static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src){ + int i; + + MERGE(dct_count[0]); //note, the other dct vars are not part of the context + MERGE(dct_count[1]); + MERGE(mv_bits); + MERGE(i_tex_bits); + MERGE(p_tex_bits); + MERGE(i_count); + MERGE(f_count); + MERGE(b_count); + MERGE(skip_count); + MERGE(misc_bits); + MERGE(error_count); + MERGE(padding_bug_score); + MERGE(current_picture.error[0]); + MERGE(current_picture.error[1]); + MERGE(current_picture.error[2]); + + if(dst->avctx->noise_reduction){ + for(i=0; i<64; i++){ + MERGE(dct_error_sum[0][i]); + MERGE(dct_error_sum[1][i]); + } + } + + assert(put_bits_count(&src->pb) % 8 ==0); + assert(put_bits_count(&dst->pb) % 8 ==0); + ff_copy_bits(&dst->pb, src->pb.buf, put_bits_count(&src->pb)); + flush_put_bits(&dst->pb); +} + +static int estimate_qp(MpegEncContext *s, int dry_run){ + if (s->next_lambda){ + s->current_picture_ptr->quality= + s->current_picture.quality = s->next_lambda; + if(!dry_run) s->next_lambda= 0; + } else if (!s->fixed_qscale) { + s->current_picture_ptr->quality= + s->current_picture.quality = ff_rate_estimate_qscale(s, dry_run); + if (s->current_picture.quality < 0) + return -1; + } + + if(s->adaptive_quant){ + switch(s->codec_id){ + case CODEC_ID_MPEG4: + if (ENABLE_MPEG4_ENCODER) + ff_clean_mpeg4_qscales(s); + break; + case CODEC_ID_H263: + case CODEC_ID_H263P: + case CODEC_ID_FLV1: + if (ENABLE_H263_ENCODER||ENABLE_H263P_ENCODER||ENABLE_FLV_ENCODER) + ff_clean_h263_qscales(s); + break; + } + + s->lambda= s->lambda_table[0]; + //FIXME broken + }else + s->lambda= s->current_picture.quality; +//printf("%d %d\n", s->avctx->global_quality, s->current_picture.quality); + update_qscale(s); + return 0; +} + +/* must be called before writing the header */ +static void set_frame_distances(MpegEncContext * s){ + assert(s->current_picture_ptr->pts != AV_NOPTS_VALUE); + s->time= s->current_picture_ptr->pts*s->avctx->time_base.num; + + if(s->pict_type==B_TYPE){ + s->pb_time= s->pp_time - (s->last_non_b_time - s->time); + assert(s->pb_time > 0 && s->pb_time < s->pp_time); + }else{ + s->pp_time= s->time - s->last_non_b_time; + s->last_non_b_time= s->time; + assert(s->picture_number==0 || s->pp_time > 0); + } +} + +static int encode_picture(MpegEncContext *s, int picture_number) +{ + int i; + int bits; + + s->picture_number = picture_number; + + /* Reset the average MB variance */ + s->me.mb_var_sum_temp = + s->me.mc_mb_var_sum_temp = 0; + + /* we need to initialize some time vars before we can encode b-frames */ + // RAL: Condition added for MPEG1VIDEO + if (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO || (s->h263_pred && !s->h263_msmpeg4)) + set_frame_distances(s); + if(ENABLE_MPEG4_ENCODER && s->codec_id == CODEC_ID_MPEG4) + ff_set_mpeg4_time(s); + + s->me.scene_change_score=0; + +// s->lambda= s->current_picture_ptr->quality; //FIXME qscale / ... stuff for ME ratedistoration + + if(s->pict_type==I_TYPE){ + if(s->msmpeg4_version >= 3) s->no_rounding=1; + else s->no_rounding=0; + }else if(s->pict_type!=B_TYPE){ + if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4) + s->no_rounding ^= 1; + } + + if(s->flags & CODEC_FLAG_PASS2){ + if (estimate_qp(s,1) < 0) + return -1; + ff_get_2pass_fcode(s); + }else if(!(s->flags & CODEC_FLAG_QSCALE)){ + if(s->pict_type==B_TYPE) + s->lambda= s->last_lambda_for[s->pict_type]; + else + s->lambda= s->last_lambda_for[s->last_non_b_pict_type]; + update_qscale(s); + } + + s->mb_intra=0; //for the rate distortion & bit compare functions + for(i=1; iavctx->thread_count; i++){ + ff_update_duplicate_context(s->thread_context[i], s); + } + + ff_init_me(s); + + /* Estimate motion for every MB */ + if(s->pict_type != I_TYPE){ + s->lambda = (s->lambda * s->avctx->me_penalty_compensation + 128)>>8; + s->lambda2= (s->lambda2* (int64_t)s->avctx->me_penalty_compensation + 128)>>8; + if(s->pict_type != B_TYPE && s->avctx->me_threshold==0){ + if((s->avctx->pre_me && s->last_non_b_pict_type==I_TYPE) || s->avctx->pre_me==2){ + s->avctx->execute(s->avctx, pre_estimate_motion_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count); + } + } + + s->avctx->execute(s->avctx, estimate_motion_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count); + }else /* if(s->pict_type == I_TYPE) */{ + /* I-Frame */ + for(i=0; imb_stride*s->mb_height; i++) + s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA; + + if(!s->fixed_qscale){ + /* finding spatial complexity for I-frame rate control */ + s->avctx->execute(s->avctx, mb_var_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count); + } + } + for(i=1; iavctx->thread_count; i++){ + merge_context_after_me(s, s->thread_context[i]); + } + s->current_picture.mc_mb_var_sum= s->current_picture_ptr->mc_mb_var_sum= s->me.mc_mb_var_sum_temp; + s->current_picture. mb_var_sum= s->current_picture_ptr-> mb_var_sum= s->me. mb_var_sum_temp; + emms_c(); + + if(s->me.scene_change_score > s->avctx->scenechange_threshold && s->pict_type == P_TYPE){ + s->pict_type= I_TYPE; + for(i=0; imb_stride*s->mb_height; i++) + s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA; +//printf("Scene change detected, encoding as I Frame %d %d\n", s->current_picture.mb_var_sum, s->current_picture.mc_mb_var_sum); + } + + if(!s->umvplus){ + if(s->pict_type==P_TYPE || s->pict_type==S_TYPE) { + s->f_code= ff_get_best_fcode(s, s->p_mv_table, CANDIDATE_MB_TYPE_INTER); + + if(s->flags & CODEC_FLAG_INTERLACED_ME){ + int a,b; + a= ff_get_best_fcode(s, s->p_field_mv_table[0][0], CANDIDATE_MB_TYPE_INTER_I); //FIXME field_select + b= ff_get_best_fcode(s, s->p_field_mv_table[1][1], CANDIDATE_MB_TYPE_INTER_I); + s->f_code= FFMAX(s->f_code, FFMAX(a,b)); + } + + ff_fix_long_p_mvs(s); + ff_fix_long_mvs(s, NULL, 0, s->p_mv_table, s->f_code, CANDIDATE_MB_TYPE_INTER, 0); + if(s->flags & CODEC_FLAG_INTERLACED_ME){ + int j; + for(i=0; i<2; i++){ + for(j=0; j<2; j++) + ff_fix_long_mvs(s, s->p_field_select_table[i], j, + s->p_field_mv_table[i][j], s->f_code, CANDIDATE_MB_TYPE_INTER_I, 0); + } + } + } + + if(s->pict_type==B_TYPE){ + int a, b; + + a = ff_get_best_fcode(s, s->b_forw_mv_table, CANDIDATE_MB_TYPE_FORWARD); + b = ff_get_best_fcode(s, s->b_bidir_forw_mv_table, CANDIDATE_MB_TYPE_BIDIR); + s->f_code = FFMAX(a, b); + + a = ff_get_best_fcode(s, s->b_back_mv_table, CANDIDATE_MB_TYPE_BACKWARD); + b = ff_get_best_fcode(s, s->b_bidir_back_mv_table, CANDIDATE_MB_TYPE_BIDIR); + s->b_code = FFMAX(a, b); + + ff_fix_long_mvs(s, NULL, 0, s->b_forw_mv_table, s->f_code, CANDIDATE_MB_TYPE_FORWARD, 1); + ff_fix_long_mvs(s, NULL, 0, s->b_back_mv_table, s->b_code, CANDIDATE_MB_TYPE_BACKWARD, 1); + ff_fix_long_mvs(s, NULL, 0, s->b_bidir_forw_mv_table, s->f_code, CANDIDATE_MB_TYPE_BIDIR, 1); + ff_fix_long_mvs(s, NULL, 0, s->b_bidir_back_mv_table, s->b_code, CANDIDATE_MB_TYPE_BIDIR, 1); + if(s->flags & CODEC_FLAG_INTERLACED_ME){ + int dir, j; + for(dir=0; dir<2; dir++){ + for(i=0; i<2; i++){ + for(j=0; j<2; j++){ + int type= dir ? (CANDIDATE_MB_TYPE_BACKWARD_I|CANDIDATE_MB_TYPE_BIDIR_I) + : (CANDIDATE_MB_TYPE_FORWARD_I |CANDIDATE_MB_TYPE_BIDIR_I); + ff_fix_long_mvs(s, s->b_field_select_table[dir][i], j, + s->b_field_mv_table[dir][i][j], dir ? s->b_code : s->f_code, type, 1); + } + } + } + } + } + } + + if (estimate_qp(s, 0) < 0) + return -1; + + if(s->qscale < 3 && s->max_qcoeff<=128 && s->pict_type==I_TYPE && !(s->flags & CODEC_FLAG_QSCALE)) + s->qscale= 3; //reduce clipping problems + + if (s->out_format == FMT_MJPEG) { + /* for mjpeg, we do include qscale in the matrix */ + s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0]; + for(i=1;i<64;i++){ + int j= s->dsp.idct_permutation[i]; + + s->intra_matrix[j] = av_clip_uint8((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); + } + ff_convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, + s->intra_matrix, s->intra_quant_bias, 8, 8, 1); + s->qscale= 8; + } + + //FIXME var duplication + s->current_picture_ptr->key_frame= + s->current_picture.key_frame= s->pict_type == I_TYPE; //FIXME pic_ptr + s->current_picture_ptr->pict_type= + s->current_picture.pict_type= s->pict_type; + + if(s->current_picture.key_frame) + s->picture_in_gop_number=0; + + s->last_bits= put_bits_count(&s->pb); + switch(s->out_format) { + case FMT_MJPEG: + if (ENABLE_MJPEG_ENCODER) + ff_mjpeg_encode_picture_header(s); + break; + case FMT_H261: + if (ENABLE_H261_ENCODER) + ff_h261_encode_picture_header(s, picture_number); + break; + case FMT_H263: + if (ENABLE_WMV2_ENCODER && s->codec_id == CODEC_ID_WMV2) + ff_wmv2_encode_picture_header(s, picture_number); + else if (ENABLE_MSMPEG4_ENCODER && s->h263_msmpeg4) + msmpeg4_encode_picture_header(s, picture_number); + else if (ENABLE_MPEG4_ENCODER && s->h263_pred) + mpeg4_encode_picture_header(s, picture_number); + else if (ENABLE_RV10_ENCODER && s->codec_id == CODEC_ID_RV10) + rv10_encode_picture_header(s, picture_number); + else if (ENABLE_RV20_ENCODER && s->codec_id == CODEC_ID_RV20) + rv20_encode_picture_header(s, picture_number); + else if (ENABLE_FLV_ENCODER && s->codec_id == CODEC_ID_FLV1) + ff_flv_encode_picture_header(s, picture_number); + else if (ENABLE_ANY_H263_ENCODER) + h263_encode_picture_header(s, picture_number); + break; + case FMT_MPEG1: + if (ENABLE_MPEG1VIDEO_ENCODER || ENABLE_MPEG2VIDEO_ENCODER) + mpeg1_encode_picture_header(s, picture_number); + break; + case FMT_H264: + break; + default: + assert(0); + } + bits= put_bits_count(&s->pb); + s->header_bits= bits - s->last_bits; + + for(i=1; iavctx->thread_count; i++){ + update_duplicate_context_after_me(s->thread_context[i], s); + } + s->avctx->execute(s->avctx, encode_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count); + for(i=1; iavctx->thread_count; i++){ + merge_context_after_encode(s, s->thread_context[i]); + } + emms_c(); + return 0; +} + +void denoise_dct_c(MpegEncContext *s, DCTELEM *block){ + const int intra= s->mb_intra; + int i; + + s->dct_count[intra]++; + + for(i=0; i<64; i++){ + int level= block[i]; + + if(level){ + if(level>0){ + s->dct_error_sum[intra][i] += level; + level -= s->dct_offset[intra][i]; + if(level<0) level=0; + }else{ + s->dct_error_sum[intra][i] -= level; + level += s->dct_offset[intra][i]; + if(level>0) level=0; + } + block[i]= level; + } + } +} + +int dct_quantize_trellis_c(MpegEncContext *s, + DCTELEM *block, int n, + int qscale, int *overflow){ + const int *qmat; + const uint8_t *scantable= s->intra_scantable.scantable; + const uint8_t *perm_scantable= s->intra_scantable.permutated; + int max=0; + unsigned int threshold1, threshold2; + int bias=0; + int run_tab[65]; + int level_tab[65]; + int score_tab[65]; + int survivor[65]; + int survivor_count; + int last_run=0; + int last_level=0; + int last_score= 0; + int last_i; + int coeff[2][64]; + int coeff_count[64]; + int qmul, qadd, start_i, last_non_zero, i, dc; + const int esc_length= s->ac_esc_length; + uint8_t * length; + uint8_t * last_length; + const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6); + + s->dsp.fdct (block); + + if(s->dct_error_sum) + s->denoise_dct(s, block); + qmul= qscale*16; + qadd= ((qscale-1)|1)*8; + + if (s->mb_intra) { + int q; + if (!s->h263_aic) { + if (n < 4) + q = s->y_dc_scale; + else + q = s->c_dc_scale; + q = q << 3; + } else{ + /* For AIC we skip quant/dequant of INTRADC */ + q = 1 << 3; + qadd=0; + } + + /* note: block[0] is assumed to be positive */ + block[0] = (block[0] + (q >> 1)) / q; + start_i = 1; + last_non_zero = 0; + qmat = s->q_intra_matrix[qscale]; + if(s->mpeg_quant || s->out_format == FMT_MPEG1) + bias= 1<<(QMAT_SHIFT-1); + length = s->intra_ac_vlc_length; + last_length= s->intra_ac_vlc_last_length; + } else { + start_i = 0; + last_non_zero = -1; + qmat = s->q_inter_matrix[qscale]; + length = s->inter_ac_vlc_length; + last_length= s->inter_ac_vlc_last_length; + } + last_i= start_i; + + threshold1= (1<=start_i; i--) { + const int j = scantable[i]; + int level = block[j] * qmat[j]; + + if(((unsigned)(level+threshold1))>threshold2){ + last_non_zero = i; + break; + } + } + + for(i=start_i; i<=last_non_zero; i++) { + const int j = scantable[i]; + int level = block[j] * qmat[j]; + +// if( bias+level >= (1<<(QMAT_SHIFT - 3)) +// || bias-level >= (1<<(QMAT_SHIFT - 3))){ + if(((unsigned)(level+threshold1))>threshold2){ + if(level>0){ + level= (bias + level)>>QMAT_SHIFT; + coeff[0][i]= level; + coeff[1][i]= level-1; +// coeff[2][k]= level-2; + }else{ + level= (bias - level)>>QMAT_SHIFT; + coeff[0][i]= -level; + coeff[1][i]= -level+1; +// coeff[2][k]= -level+2; + } + coeff_count[i]= FFMIN(level, 2); + assert(coeff_count[i]); + max |=level; + }else{ + coeff[0][i]= (level>>31)|1; + coeff_count[i]= 1; + } + } + + *overflow= s->max_qcoeff < max; //overflow might have happened + + if(last_non_zero < start_i){ + memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM)); + return last_non_zero; + } + + score_tab[start_i]= 0; + survivor[0]= start_i; + survivor_count= 1; + + for(i=start_i; i<=last_non_zero; i++){ + int level_index, j, zero_distoration; + int dct_coeff= FFABS(block[ scantable[i] ]); + int best_score=256*256*256*120; + + if ( s->dsp.fdct == fdct_ifast +#ifndef FAAN_POSTSCALE + || s->dsp.fdct == ff_faandct +#endif + ) + dct_coeff= (dct_coeff*inv_aanscales[ scantable[i] ]) >> 12; + zero_distoration= dct_coeff*dct_coeff; + + for(level_index=0; level_index < coeff_count[i]; level_index++){ + int distoration; + int level= coeff[level_index][i]; + const int alevel= FFABS(level); + int unquant_coeff; + + assert(level); + + if(s->out_format == FMT_H263){ + unquant_coeff= alevel*qmul + qadd; + }else{ //MPEG1 + j= s->dsp.idct_permutation[ scantable[i] ]; //FIXME optimize + if(s->mb_intra){ + unquant_coeff = (int)( alevel * qscale * s->intra_matrix[j]) >> 3; + unquant_coeff = (unquant_coeff - 1) | 1; + }else{ + unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->inter_matrix[j])) >> 4; + unquant_coeff = (unquant_coeff - 1) | 1; + } + unquant_coeff<<= 3; + } + + distoration= (unquant_coeff - dct_coeff) * (unquant_coeff - dct_coeff) - zero_distoration; + level+=64; + if((level&(~127)) == 0){ + for(j=survivor_count-1; j>=0; j--){ + int run= i - survivor[j]; + int score= distoration + length[UNI_AC_ENC_INDEX(run, level)]*lambda; + score += score_tab[i-run]; + + if(score < best_score){ + best_score= score; + run_tab[i+1]= run; + level_tab[i+1]= level-64; + } + } + + if(s->out_format == FMT_H263){ + for(j=survivor_count-1; j>=0; j--){ + int run= i - survivor[j]; + int score= distoration + last_length[UNI_AC_ENC_INDEX(run, level)]*lambda; + score += score_tab[i-run]; + if(score < last_score){ + last_score= score; + last_run= run; + last_level= level-64; + last_i= i+1; + } + } + } + }else{ + distoration += esc_length*lambda; + for(j=survivor_count-1; j>=0; j--){ + int run= i - survivor[j]; + int score= distoration + score_tab[i-run]; + + if(score < best_score){ + best_score= score; + run_tab[i+1]= run; + level_tab[i+1]= level-64; + } + } + + if(s->out_format == FMT_H263){ + for(j=survivor_count-1; j>=0; j--){ + int run= i - survivor[j]; + int score= distoration + score_tab[i-run]; + if(score < last_score){ + last_score= score; + last_run= run; + last_level= level-64; + last_i= i+1; + } + } + } + } + } + + score_tab[i+1]= best_score; + + //Note: there is a vlc code in mpeg4 which is 1 bit shorter then another one with a shorter run and the same level + if(last_non_zero <= 27){ + for(; survivor_count; survivor_count--){ + if(score_tab[ survivor[survivor_count-1] ] <= best_score) + break; + } + }else{ + for(; survivor_count; survivor_count--){ + if(score_tab[ survivor[survivor_count-1] ] <= best_score + lambda) + break; + } + } + + survivor[ survivor_count++ ]= i+1; + } + + if(s->out_format != FMT_H263){ + last_score= 256*256*256*120; + for(i= survivor[0]; i<=last_non_zero + 1; i++){ + int score= score_tab[i]; + if(i) score += lambda*2; //FIXME exacter? + + if(score < last_score){ + last_score= score; + last_i= i; + last_level= level_tab[i]; + last_run= run_tab[i]; + } + } + } + + s->coded_score[n] = last_score; + + dc= FFABS(block[0]); + last_non_zero= last_i - 1; + memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM)); + + if(last_non_zero < start_i) + return last_non_zero; + + if(last_non_zero == 0 && start_i == 0){ + int best_level= 0; + int best_score= dc * dc; + + for(i=0; iout_format == FMT_H263){ + unquant_coeff= (alevel*qmul + qadd)>>3; + }else{ //MPEG1 + unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->inter_matrix[0])) >> 4; + unquant_coeff = (unquant_coeff - 1) | 1; + } + unquant_coeff = (unquant_coeff + 4) >> 3; + unquant_coeff<<= 3 + 3; + + distortion= (unquant_coeff - dc) * (unquant_coeff - dc); + level+=64; + if((level&(~127)) == 0) score= distortion + last_length[UNI_AC_ENC_INDEX(0, level)]*lambda; + else score= distortion + esc_length*lambda; + + if(score < best_score){ + best_score= score; + best_level= level - 64; + } + } + block[0]= best_level; + s->coded_score[n] = best_score - dc*dc; + if(best_level == 0) return -1; + else return last_non_zero; + } + + i= last_i; + assert(last_level); + + block[ perm_scantable[last_non_zero] ]= last_level; + i -= last_run + 1; + + for(; i>start_i; i -= run_tab[i] + 1){ + block[ perm_scantable[i-1] ]= level_tab[i]; + } + + return last_non_zero; +} + +//#define REFINE_STATS 1 +static int16_t basis[64][64]; + +static void build_basis(uint8_t *perm){ + int i, j, x, y; + emms_c(); + for(i=0; i<8; i++){ + for(j=0; j<8; j++){ + for(y=0; y<8; y++){ + for(x=0; x<8; x++){ + double s= 0.25*(1<intra_scantable.scantable; + const uint8_t *perm_scantable= s->intra_scantable.permutated; +// unsigned int threshold1, threshold2; +// int bias=0; + int run_tab[65]; + int prev_run=0; + int prev_level=0; + int qmul, qadd, start_i, last_non_zero, i, dc; + uint8_t * length; + uint8_t * last_length; + int lambda; + int rle_index, run, q = 1, sum; //q is only used when s->mb_intra is true +#ifdef REFINE_STATS +static int count=0; +static int after_last=0; +static int to_zero=0; +static int from_zero=0; +static int raise=0; +static int lower=0; +static int messed_sign=0; +#endif + + if(basis[0][0] == 0) + build_basis(s->dsp.idct_permutation); + + qmul= qscale*2; + qadd= (qscale-1)|1; + if (s->mb_intra) { + if (!s->h263_aic) { + if (n < 4) + q = s->y_dc_scale; + else + q = s->c_dc_scale; + } else{ + /* For AIC we skip quant/dequant of INTRADC */ + q = 1; + qadd=0; + } + q <<= RECON_SHIFT-3; + /* note: block[0] is assumed to be positive */ + dc= block[0]*q; +// block[0] = (block[0] + (q >> 1)) / q; + start_i = 1; + qmat = s->q_intra_matrix[qscale]; +// if(s->mpeg_quant || s->out_format == FMT_MPEG1) +// bias= 1<<(QMAT_SHIFT-1); + length = s->intra_ac_vlc_length; + last_length= s->intra_ac_vlc_last_length; + } else { + dc= 0; + start_i = 0; + qmat = s->q_inter_matrix[qscale]; + length = s->inter_ac_vlc_length; + last_length= s->inter_ac_vlc_last_length; + } + last_non_zero = s->block_last_index[n]; + +#ifdef REFINE_STATS +{START_TIMER +#endif + dc += (1<<(RECON_SHIFT-1)); + for(i=0; i<64; i++){ + rem[i]= dc - (orig[i]<0); + assert(w<(1<<6)); + sum += w*w; + } + lambda= sum*(uint64_t)s->lambda2 >> (FF_LAMBDA_SHIFT - 6 + 6 + 6 + 6); +#ifdef REFINE_STATS +{START_TIMER +#endif + run=0; + rle_index=0; + for(i=start_i; i<=last_non_zero; i++){ + int j= perm_scantable[i]; + const int level= block[j]; + int coeff; + + if(level){ + if(level<0) coeff= qmul*level - qadd; + else coeff= qmul*level + qadd; + run_tab[rle_index++]=run; + run=0; + + s->dsp.add_8x8basis(rem, basis[j], coeff); + }else{ + run++; + } + } +#ifdef REFINE_STATS +if(last_non_zero>0){ +STOP_TIMER("init rem[]") +} +} + +{START_TIMER +#endif + for(;;){ + int best_score=s->dsp.try_8x8basis(rem, weight, basis[0], 0); + int best_coeff=0; + int best_change=0; + int run2, best_unquant_change=0, analyze_gradient; +#ifdef REFINE_STATS +{START_TIMER +#endif + analyze_gradient = last_non_zero > 2 || s->avctx->quantizer_noise_shaping >= 3; + + if(analyze_gradient){ +#ifdef REFINE_STATS +{START_TIMER +#endif + for(i=0; i<64; i++){ + int w= weight[i]; + + d1[i] = (rem[i]*w*w + (1<<(RECON_SHIFT+12-1)))>>(RECON_SHIFT+12); + } +#ifdef REFINE_STATS +STOP_TIMER("rem*w*w")} +{START_TIMER +#endif + s->dsp.fdct(d1); +#ifdef REFINE_STATS +STOP_TIMER("dct")} +#endif + } + + if(start_i){ + const int level= block[0]; + int change, old_coeff; + + assert(s->mb_intra); + + old_coeff= q*level; + + for(change=-1; change<=1; change+=2){ + int new_level= level + change; + int score, new_coeff; + + new_coeff= q*new_level; + if(new_coeff >= 2048 || new_coeff < 0) + continue; + + score= s->dsp.try_8x8basis(rem, weight, basis[0], new_coeff - old_coeff); + if(scoreavctx->quantizer_noise_shaping < 3 && i > last_non_zero + 1) + break; + + if(level){ + if(level<0) old_coeff= qmul*level - qadd; + else old_coeff= qmul*level + qadd; + run2= run_tab[rle_index++]; //FIXME ! maybe after last + }else{ + old_coeff=0; + run2--; + assert(run2>=0 || i >= last_non_zero ); + } + + for(change=-1; change<=1; change+=2){ + int new_level= level + change; + int score, new_coeff, unquant_change; + + score=0; + if(s->avctx->quantizer_noise_shaping < 2 && FFABS(new_level) > FFABS(level)) + continue; + + if(new_level){ + if(new_level<0) new_coeff= qmul*new_level - qadd; + else new_coeff= qmul*new_level + qadd; + if(new_coeff >= 2048 || new_coeff <= -2048) + continue; + //FIXME check for overflow + + if(level){ + if(level < 63 && level > -63){ + if(i < last_non_zero) + score += length[UNI_AC_ENC_INDEX(run, new_level+64)] + - length[UNI_AC_ENC_INDEX(run, level+64)]; + else + score += last_length[UNI_AC_ENC_INDEX(run, new_level+64)] + - last_length[UNI_AC_ENC_INDEX(run, level+64)]; + } + }else{ + assert(FFABS(new_level)==1); + + if(analyze_gradient){ + int g= d1[ scantable[i] ]; + if(g && (g^new_level) >= 0) + continue; + } + + if(i < last_non_zero){ + int next_i= i + run2 + 1; + int next_level= block[ perm_scantable[next_i] ] + 64; + + if(next_level&(~127)) + next_level= 0; + + if(next_i < last_non_zero) + score += length[UNI_AC_ENC_INDEX(run, 65)] + + length[UNI_AC_ENC_INDEX(run2, next_level)] + - length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)]; + else + score += length[UNI_AC_ENC_INDEX(run, 65)] + + last_length[UNI_AC_ENC_INDEX(run2, next_level)] + - last_length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)]; + }else{ + score += last_length[UNI_AC_ENC_INDEX(run, 65)]; + if(prev_level){ + score += length[UNI_AC_ENC_INDEX(prev_run, prev_level)] + - last_length[UNI_AC_ENC_INDEX(prev_run, prev_level)]; + } + } + } + }else{ + new_coeff=0; + assert(FFABS(level)==1); + + if(i < last_non_zero){ + int next_i= i + run2 + 1; + int next_level= block[ perm_scantable[next_i] ] + 64; + + if(next_level&(~127)) + next_level= 0; + + if(next_i < last_non_zero) + score += length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)] + - length[UNI_AC_ENC_INDEX(run2, next_level)] + - length[UNI_AC_ENC_INDEX(run, 65)]; + else + score += last_length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)] + - last_length[UNI_AC_ENC_INDEX(run2, next_level)] + - length[UNI_AC_ENC_INDEX(run, 65)]; + }else{ + score += -last_length[UNI_AC_ENC_INDEX(run, 65)]; + if(prev_level){ + score += last_length[UNI_AC_ENC_INDEX(prev_run, prev_level)] + - length[UNI_AC_ENC_INDEX(prev_run, prev_level)]; + } + } + } + + score *= lambda; + + unquant_change= new_coeff - old_coeff; + assert((score < 100*lambda && score > -100*lambda) || lambda==0); + + score+= s->dsp.try_8x8basis(rem, weight, basis[j], unquant_change); + if(score last_non_zero){ + last_non_zero= best_coeff; + assert(block[j]); +#ifdef REFINE_STATS +after_last++; +#endif + }else{ +#ifdef REFINE_STATS +if(block[j]){ + if(block[j] - best_change){ + if(FFABS(block[j]) > FFABS(block[j] - best_change)){ + raise++; + }else{ + lower++; + } + }else{ + from_zero++; + } +}else{ + to_zero++; +} +#endif + for(; last_non_zero>=start_i; last_non_zero--){ + if(block[perm_scantable[last_non_zero]]) + break; + } + } +#ifdef REFINE_STATS +count++; +if(256*256*256*64 % count == 0){ + printf("after_last:%d to_zero:%d from_zero:%d raise:%d lower:%d sign:%d xyp:%d/%d/%d\n", after_last, to_zero, from_zero, raise, lower, messed_sign, s->mb_x, s->mb_y, s->picture_number); +} +#endif + run=0; + rle_index=0; + for(i=start_i; i<=last_non_zero; i++){ + int j= perm_scantable[i]; + const int level= block[j]; + + if(level){ + run_tab[rle_index++]=run; + run=0; + }else{ + run++; + } + } + + s->dsp.add_8x8basis(rem, basis[j], best_unquant_change); + }else{ + break; + } + } +#ifdef REFINE_STATS +if(last_non_zero>0){ +STOP_TIMER("iterative search") +} +} +#endif + + return last_non_zero; +} + +int dct_quantize_c(MpegEncContext *s, + DCTELEM *block, int n, + int qscale, int *overflow) +{ + int i, j, level, last_non_zero, q, start_i; + const int *qmat; + const uint8_t *scantable= s->intra_scantable.scantable; + int bias; + int max=0; + unsigned int threshold1, threshold2; + + s->dsp.fdct (block); + + if(s->dct_error_sum) + s->denoise_dct(s, block); + + if (s->mb_intra) { + if (!s->h263_aic) { + if (n < 4) + q = s->y_dc_scale; + else + q = s->c_dc_scale; + q = q << 3; + } else + /* For AIC we skip quant/dequant of INTRADC */ + q = 1 << 3; + + /* note: block[0] is assumed to be positive */ + block[0] = (block[0] + (q >> 1)) / q; + start_i = 1; + last_non_zero = 0; + qmat = s->q_intra_matrix[qscale]; + bias= s->intra_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT); + } else { + start_i = 0; + last_non_zero = -1; + qmat = s->q_inter_matrix[qscale]; + bias= s->inter_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT); + } + threshold1= (1<=start_i;i--) { + j = scantable[i]; + level = block[j] * qmat[j]; + + if(((unsigned)(level+threshold1))>threshold2){ + last_non_zero = i; + break; + }else{ + block[j]=0; + } + } + for(i=start_i; i<=last_non_zero; i++) { + j = scantable[i]; + level = block[j] * qmat[j]; + +// if( bias+level >= (1<= (1<threshold2){ + if(level>0){ + level= (bias + level)>>QMAT_SHIFT; + block[j]= level; + }else{ + level= (bias - level)>>QMAT_SHIFT; + block[j]= -level; + } + max |=level; + }else{ + block[j]=0; + } + } + *overflow= s->max_qcoeff < max; //overflow might have happened + + /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */ + if (s->dsp.idct_permutation_type != FF_NO_IDCT_PERM) + ff_block_permute(block, s->dsp.idct_permutation, scantable, last_non_zero); + + return last_non_zero; +} + +AVCodec h263_encoder = { + "h263", + CODEC_TYPE_VIDEO, + CODEC_ID_H263, + sizeof(MpegEncContext), + MPV_encode_init, + MPV_encode_picture, + MPV_encode_end, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, +}; + +AVCodec h263p_encoder = { + "h263p", + CODEC_TYPE_VIDEO, + CODEC_ID_H263P, + sizeof(MpegEncContext), + MPV_encode_init, + MPV_encode_picture, + MPV_encode_end, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, +}; + +AVCodec flv_encoder = { + "flv", + CODEC_TYPE_VIDEO, + CODEC_ID_FLV1, + sizeof(MpegEncContext), + MPV_encode_init, + MPV_encode_picture, + MPV_encode_end, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, +}; + +AVCodec rv10_encoder = { + "rv10", + CODEC_TYPE_VIDEO, + CODEC_ID_RV10, + sizeof(MpegEncContext), + MPV_encode_init, + MPV_encode_picture, + MPV_encode_end, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, +}; + +AVCodec rv20_encoder = { + "rv20", + CODEC_TYPE_VIDEO, + CODEC_ID_RV20, + sizeof(MpegEncContext), + MPV_encode_init, + MPV_encode_picture, + MPV_encode_end, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, +}; + +AVCodec mpeg4_encoder = { + "mpeg4", + CODEC_TYPE_VIDEO, + CODEC_ID_MPEG4, + sizeof(MpegEncContext), + MPV_encode_init, + MPV_encode_picture, + MPV_encode_end, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, + .capabilities= CODEC_CAP_DELAY, +}; + +AVCodec msmpeg4v1_encoder = { + "msmpeg4v1", + CODEC_TYPE_VIDEO, + CODEC_ID_MSMPEG4V1, + sizeof(MpegEncContext), + MPV_encode_init, + MPV_encode_picture, + MPV_encode_end, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, +}; + +AVCodec msmpeg4v2_encoder = { + "msmpeg4v2", + CODEC_TYPE_VIDEO, + CODEC_ID_MSMPEG4V2, + sizeof(MpegEncContext), + MPV_encode_init, + MPV_encode_picture, + MPV_encode_end, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, +}; + +AVCodec msmpeg4v3_encoder = { + "msmpeg4", + CODEC_TYPE_VIDEO, + CODEC_ID_MSMPEG4V3, + sizeof(MpegEncContext), + MPV_encode_init, + MPV_encode_picture, + MPV_encode_end, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, +}; + +AVCodec wmv1_encoder = { + "wmv1", + CODEC_TYPE_VIDEO, + CODEC_ID_WMV1, + sizeof(MpegEncContext), + MPV_encode_init, + MPV_encode_picture, + MPV_encode_end, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, +}; diff --git a/contrib/ffmpeg/libavcodec/mpegvideo_parser.c b/contrib/ffmpeg/libavcodec/mpegvideo_parser.c new file mode 100644 index 000000000..a7ce09d4c --- /dev/null +++ b/contrib/ffmpeg/libavcodec/mpegvideo_parser.c @@ -0,0 +1,180 @@ +/* + * MPEG1 / MPEG2 video parser + * Copyright (c) 2000,2001 Fabrice Bellard. + * Copyright (c) 2002-2004 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "parser.h" +#include "mpegvideo.h" + +static void mpegvideo_extract_headers(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t *buf, int buf_size) +{ + ParseContext1 *pc = s->priv_data; + const uint8_t *buf_end; + uint32_t start_code; + int frame_rate_index, ext_type, bytes_left; + int frame_rate_ext_n, frame_rate_ext_d; + int picture_structure, top_field_first, repeat_first_field, progressive_frame; + int horiz_size_ext, vert_size_ext, bit_rate_ext; +//FIXME replace the crap with get_bits() + s->repeat_pict = 0; + buf_end = buf + buf_size; + while (buf < buf_end) { + start_code= -1; + buf= ff_find_start_code(buf, buf_end, &start_code); + bytes_left = buf_end - buf; + switch(start_code) { + case PICTURE_START_CODE: + if (bytes_left >= 2) { + s->pict_type = (buf[1] >> 3) & 7; + } + break; + case SEQ_START_CODE: + if (bytes_left >= 7) { + pc->width = (buf[0] << 4) | (buf[1] >> 4); + pc->height = ((buf[1] & 0x0f) << 8) | buf[2]; + avcodec_set_dimensions(avctx, pc->width, pc->height); + frame_rate_index = buf[3] & 0xf; + pc->frame_rate.den = avctx->time_base.den = ff_frame_rate_tab[frame_rate_index].num; + pc->frame_rate.num = avctx->time_base.num = ff_frame_rate_tab[frame_rate_index].den; + avctx->bit_rate = ((buf[4]<<10) | (buf[5]<<2) | (buf[6]>>6))*400; + avctx->codec_id = CODEC_ID_MPEG1VIDEO; + avctx->sub_id = 1; + } + break; + case EXT_START_CODE: + if (bytes_left >= 1) { + ext_type = (buf[0] >> 4); + switch(ext_type) { + case 0x1: /* sequence extension */ + if (bytes_left >= 6) { + horiz_size_ext = ((buf[1] & 1) << 1) | (buf[2] >> 7); + vert_size_ext = (buf[2] >> 5) & 3; + bit_rate_ext = ((buf[2] & 0x1F)<<7) | (buf[3]>>1); + frame_rate_ext_n = (buf[5] >> 5) & 3; + frame_rate_ext_d = (buf[5] & 0x1f); + pc->progressive_sequence = buf[1] & (1 << 3); + avctx->has_b_frames= !(buf[5] >> 7); + + pc->width |=(horiz_size_ext << 12); + pc->height |=( vert_size_ext << 12); + avctx->bit_rate += (bit_rate_ext << 18) * 400; + avcodec_set_dimensions(avctx, pc->width, pc->height); + avctx->time_base.den = pc->frame_rate.den * (frame_rate_ext_n + 1); + avctx->time_base.num = pc->frame_rate.num * (frame_rate_ext_d + 1); + avctx->codec_id = CODEC_ID_MPEG2VIDEO; + avctx->sub_id = 2; /* forces MPEG2 */ + } + break; + case 0x8: /* picture coding extension */ + if (bytes_left >= 5) { + picture_structure = buf[2]&3; + top_field_first = buf[3] & (1 << 7); + repeat_first_field = buf[3] & (1 << 1); + progressive_frame = buf[4] & (1 << 7); + + /* check if we must repeat the frame */ + if (repeat_first_field) { + if (pc->progressive_sequence) { + if (top_field_first) + s->repeat_pict = 4; + else + s->repeat_pict = 2; + } else if (progressive_frame) { + s->repeat_pict = 1; + } + } + } + break; + } + } + break; + case -1: + goto the_end; + default: + /* we stop parsing when we encounter a slice. It ensures + that this function takes a negligible amount of time */ + if (start_code >= SLICE_MIN_START_CODE && + start_code <= SLICE_MAX_START_CODE) + goto the_end; + break; + } + } + the_end: ; +} + +static int mpegvideo_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + ParseContext1 *pc1 = s->priv_data; + ParseContext *pc= &pc1->pc; + int next; + + if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ + next= buf_size; + }else{ + next= ff_mpeg1_find_frame_end(pc, buf, buf_size); + + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + + } + /* we have a full frame : we just parse the first few MPEG headers + to have the full timing information. The time take by this + function should be negligible for uncorrupted streams */ + mpegvideo_extract_headers(s, avctx, buf, buf_size); +#if 0 + printf("pict_type=%d frame_rate=%0.3f repeat_pict=%d\n", + s->pict_type, (double)avctx->time_base.den / avctx->time_base.num, s->repeat_pict); +#endif + + *poutbuf = buf; + *poutbuf_size = buf_size; + return next; +} + +static int mpegvideo_split(AVCodecContext *avctx, + const uint8_t *buf, int buf_size) +{ + int i; + uint32_t state= -1; + + for(i=0; i= 0x100) + return i-3; + } + return 0; +} + +AVCodecParser mpegvideo_parser = { + { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO }, + sizeof(ParseContext1), + NULL, + mpegvideo_parse, + ff_parse1_close, + mpegvideo_split, +}; diff --git a/contrib/ffmpeg/libavcodec/msmpeg4.c b/contrib/ffmpeg/libavcodec/msmpeg4.c index 62076d140..0ffcc6040 100644 --- a/contrib/ffmpeg/libavcodec/msmpeg4.c +++ b/contrib/ffmpeg/libavcodec/msmpeg4.c @@ -3,6 +3,8 @@ * Copyright (c) 2001 Fabrice Bellard. * Copyright (c) 2002-2004 Michael Niedermayer * + * msmpeg4v1 & v2 stuff by Michael Niedermayer + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -18,8 +20,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * msmpeg4v1 & v2 stuff by Michael Niedermayer */ /** @@ -30,6 +30,7 @@ #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" +#include "msmpeg4.h" /* * You can also call this codec : MPEG4 with a twist ! @@ -42,7 +43,6 @@ #define DC_VLC_BITS 9 #define CBPY_VLC_BITS 6 -#define INTER_INTRA_VLC_BITS 3 #define V1_INTRA_CBPC_VLC_BITS 6 #define V1_INTER_CBPC_VLC_BITS 6 #define V2_INTRA_CBPC_VLC_BITS 3 @@ -50,8 +50,6 @@ #define MV_VLC_BITS 9 #define V2_MV_VLC_BITS 9 #define TEX_VLC_BITS 9 -#define MB_NON_INTRA_VLC_BITS 9 -#define MB_INTRA_VLC_BITS 9 #define II_BITRATE 128*1024 #define MBAC_BITRATE 50*1024 @@ -61,12 +59,7 @@ static uint32_t v2_dc_lum_table[512][2]; static uint32_t v2_dc_chroma_table[512][2]; -static inline void msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n); -static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, - int n, int coded, const uint8_t *scantable); static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr); -static int msmpeg4_decode_motion(MpegEncContext * s, - int *mx_ptr, int *my_ptr); static void init_h263_dc_for_msmpeg4(void); static inline void msmpeg4_memsetw(short *tab, int val, int n); #ifdef CONFIG_ENCODERS @@ -75,10 +68,9 @@ static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, #endif //CONFIG_ENCODERS static int msmpeg4v12_decode_mb(MpegEncContext *s, DCTELEM block[6][64]); static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64]); -static int wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64]); /* vc1 externs */ -extern uint8_t wmv3_dc_scale_table[32]; +extern const uint8_t wmv3_dc_scale_table[32]; #ifdef DEBUG int intra_count = 0; @@ -87,7 +79,7 @@ int frame_count = 0; #include "msmpeg4data.h" -#ifdef CONFIG_ENCODERS //strangely gcc includes this even if its not references +#ifdef CONFIG_ENCODERS //strangely gcc includes this even if it is not references static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2]; #endif //CONFIG_ENCODERS @@ -95,7 +87,7 @@ static uint8_t static_rl_table_store[NB_RL_TABLES][2][2*MAX_RUN + MAX_LEVEL + 3] static void common_init(MpegEncContext * s) { - static int inited=0; + static int initialized=0; switch(s->msmpeg4_version){ case 1: @@ -135,8 +127,8 @@ static void common_init(MpegEncContext * s) } //Note the default tables are set in common_init in mpegvideo.c - if(!inited){ - inited=1; + if(!initialized){ + initialized=1; init_h263_dc_for_msmpeg4(); } @@ -161,7 +153,7 @@ static void init_mv_table(MVTable *tab) } } -static void code012(PutBitContext *pb, int n) +void ff_msmpeg4_code012(PutBitContext *pb, int n) { if (n == 0) { put_bits(pb, 1, 0); @@ -246,7 +238,7 @@ static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, return size; } -static void find_best_tables(MpegEncContext * s) +void ff_find_best_tables(MpegEncContext * s) { int i; int best =-1, best_size =9999999; @@ -316,7 +308,7 @@ static void find_best_tables(MpegEncContext * s) /* write MSMPEG4 compatible frame header */ void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number) { - find_best_tables(s); + ff_find_best_tables(s); align_put_bits(&s->pb); put_bits(&s->pb, 2, s->pict_type - 1); @@ -347,8 +339,8 @@ void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number) if(s->msmpeg4_version>2){ if(!s->per_mb_rl_table){ - code012(&s->pb, s->rl_chroma_table_index); - code012(&s->pb, s->rl_table_index); + ff_msmpeg4_code012(&s->pb, s->rl_chroma_table_index); + ff_msmpeg4_code012(&s->pb, s->rl_table_index); } put_bits(&s->pb, 1, s->dc_table_index); @@ -361,7 +353,7 @@ void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number) if(s->msmpeg4_version>2){ if(!s->per_mb_rl_table) - code012(&s->pb, s->rl_table_index); + ff_msmpeg4_code012(&s->pb, s->rl_table_index); put_bits(&s->pb, 1, s->dc_table_index); @@ -393,7 +385,7 @@ void msmpeg4_encode_ext_header(MpegEncContext * s) #endif //CONFIG_ENCODERS /* predict coded block */ -static inline int coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr) +int ff_msmpeg4_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr) { int xy, wrap, pred, a, b, c; @@ -421,7 +413,7 @@ static inline int coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_bl #ifdef CONFIG_ENCODERS -static void msmpeg4_encode_motion(MpegEncContext * s, +void ff_msmpeg4_encode_motion(MpegEncContext * s, int mx, int my) { int code; @@ -453,13 +445,13 @@ static void msmpeg4_encode_motion(MpegEncContext * s, mv->table_mv_bits[code], mv->table_mv_code[code]); if (code == mv->n) { - /* escape : code litterally */ + /* escape : code literally */ put_bits(&s->pb, 6, mx); put_bits(&s->pb, 6, my); } } -static inline void handle_slices(MpegEncContext *s){ +void ff_msmpeg4_handle_slices(MpegEncContext *s){ if (s->mb_x == 0) { if (s->slice_height && (s->mb_y % s->slice_height) == 0) { if(s->msmpeg4_version < 4){ @@ -480,7 +472,7 @@ void msmpeg4_encode_mb(MpegEncContext * s, int pred_x, pred_y; uint8_t *coded_block; - handle_slices(s); + ff_msmpeg4_handle_slices(s); if (!s->mb_intra) { /* compute cbp */ @@ -526,14 +518,14 @@ void msmpeg4_encode_mb(MpegEncContext * s, /* motion vector */ h263_pred_motion(s, 0, 0, &pred_x, &pred_y); - msmpeg4_encode_motion(s, motion_x - pred_x, + ff_msmpeg4_encode_motion(s, motion_x - pred_x, motion_y - pred_y); } s->mv_bits += get_bits_diff(s); for (i = 0; i < 6; i++) { - msmpeg4_encode_block(s, block[i], i); + ff_msmpeg4_encode_block(s, block[i], i); } s->p_tex_bits += get_bits_diff(s); } else { @@ -546,7 +538,7 @@ void msmpeg4_encode_mb(MpegEncContext * s, cbp |= val << (5 - i); if (i < 4) { /* predict value for close blocks only for luma */ - pred = coded_block_pred(s, i, &coded_block); + pred = ff_msmpeg4_coded_block_pred(s, i, &coded_block); *coded_block = val; val = val ^ pred; } @@ -592,7 +584,7 @@ void msmpeg4_encode_mb(MpegEncContext * s, s->misc_bits += get_bits_diff(s); for (i = 0; i < 6; i++) { - msmpeg4_encode_block(s, block[i], i); + ff_msmpeg4_encode_block(s, block[i], i); } s->i_tex_bits += get_bits_diff(s); s->i_count++; @@ -782,7 +774,8 @@ static inline int msmpeg4_pred_dc(MpegEncContext * s, int n, static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr) { int sign, code; - int pred; + int pred, extquant; + int extrabits = 0; if(s->msmpeg4_version==1){ int32_t *dc_val; @@ -824,6 +817,15 @@ static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr code = level; if (code > DC_MAX) code = DC_MAX; + else if( s->msmpeg4_version>=6 ) { + if( s->qscale == 1 ) { + extquant = (level + 3) & 0x3; + code = ((level+3)>>2); + } else if( s->qscale == 2 ) { + extquant = (level + 1) & 0x1; + code = ((level+1)>>1); + } + } if (s->dc_table_index == 0) { if (n < 4) { @@ -839,8 +841,13 @@ static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr } } + if(s->msmpeg4_version>=6 && s->qscale<=2) + extrabits = 3 - s->qscale; + if (code == DC_MAX) - put_bits(&s->pb, 8, level); + put_bits(&s->pb, 8 + extrabits, level); + else if(extrabits > 0)//== VC1 && s->qscale<=2 + put_bits(&s->pb, extrabits, extquant); if (level != 0) { put_bits(&s->pb, 1, sign); @@ -851,7 +858,7 @@ static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr /* Encoding of a block. Very similar to MPEG4 except for a different escape coding (same as H263) and more vlc tables. */ -static inline void msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n) +void ff_msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n) { int level, run, last, i, j, last_index; int last_non_zero, sign, slevel; @@ -867,7 +874,7 @@ static inline void msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int } else { rl = &rl_table[3 + s->rl_chroma_table_index]; } - run_diff = 0; + run_diff = s->msmpeg4_version>=4; scantable= s->intra_scantable.permutated; } else { i = 0; @@ -880,7 +887,7 @@ static inline void msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int } /* recalculate block_last_index for M$ wmv1 */ - if(s->msmpeg4_version>=4 && s->block_last_index[n]>0){ + if(s->msmpeg4_version>=4 && s->msmpeg4_version<6 && s->block_last_index[n]>0){ for(last_index=63; last_index>=0; last_index--){ if(block[scantable[last_index]]) break; } @@ -926,6 +933,9 @@ else run1 = run - rl->max_run[last][level] - run_diff; if (run1 < 0) goto esc3; + code = get_rl_index(rl, last, run1+1, level); + if (s->msmpeg4_version == 4 && code == rl->n) + goto esc3; code = get_rl_index(rl, last, run1, level); if (code == rl->n) { esc3: @@ -936,8 +946,9 @@ else if(s->esc3_level_length==0){ s->esc3_level_length=8; s->esc3_run_length= 6; + //ESCLVLSZ + ESCRUNSZ if(s->qscale<8) - put_bits(&s->pb, 6, 3); + put_bits(&s->pb, 6 + (s->msmpeg4_version>=6), 3); else put_bits(&s->pb, 8, 3); } @@ -971,10 +982,7 @@ else /****************************************/ /* decoding stuff */ -static VLC mb_non_intra_vlc[4]; -VLC ff_msmp4_mb_i_vlc; -VLC ff_msmp4_dc_luma_vlc[2]; -VLC ff_msmp4_dc_chroma_vlc[2]; +VLC ff_mb_non_intra_vlc[4]; static VLC v2_dc_lum_vlc; static VLC v2_dc_chroma_vlc; static VLC cbpy_vlc; @@ -983,9 +991,10 @@ static VLC v2_mb_type_vlc; static VLC v2_mv_vlc; static VLC v1_intra_cbpc_vlc; static VLC v1_inter_cbpc_vlc; -static VLC inter_intra_vlc; +VLC ff_inter_intra_vlc; -/* this table is practically identical to the one from h263 except that its inverted */ +/* This table is practically identical to the one from h263 + * except that it is inverted. */ static void init_h263_dc_for_msmpeg4(void) { int level, uni_code, uni_len; @@ -1008,7 +1017,7 @@ static void init_h263_dc_for_msmpeg4(void) /* luminance h263 */ uni_code= DCtab_lum[size][0]; uni_len = DCtab_lum[size][1]; - uni_code ^= (1< 0) { uni_code<<=size; uni_code|=l; @@ -1024,7 +1033,7 @@ static void init_h263_dc_for_msmpeg4(void) /* chrominance h263 */ uni_code= DCtab_chrom[size][0]; uni_len = DCtab_chrom[size][1]; - uni_code ^= (1< 0) { uni_code<<=size; uni_code|=l; @@ -1097,7 +1106,7 @@ int ff_msmpeg4_decode_init(MpegEncContext *s) &mvtab[0][0], 2, 1, 1); for(i=0; i<4; i++){ - init_vlc(&mb_non_intra_vlc[i], MB_NON_INTRA_VLC_BITS, 128, + init_vlc(&ff_mb_non_intra_vlc[i], MB_NON_INTRA_VLC_BITS, 128, &wmv2_inter_table[i][0][1], 8, 4, &wmv2_inter_table[i][0][0], 8, 4, 1); //FIXME name? } @@ -1113,7 +1122,7 @@ int ff_msmpeg4_decode_init(MpegEncContext *s) inter_MCBPC_bits, 1, 1, inter_MCBPC_code, 1, 1, 1); - init_vlc(&inter_intra_vlc, INTER_INTRA_VLC_BITS, 4, + init_vlc(&ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 4, &table_inter_intra[0][1], 2, 1, &table_inter_intra[0][0], 2, 1, 1); } @@ -1128,13 +1137,14 @@ int ff_msmpeg4_decode_init(MpegEncContext *s) s->decode_mb= msmpeg4v34_decode_mb; break; case 5: - s->decode_mb= wmv2_decode_mb; + if (ENABLE_WMV2_DECODER) + s->decode_mb= ff_wmv2_decode_mb; case 6: //FIXME + TODO VC1 decode mb break; } - s->slice_height= s->mb_height; //to avoid 1/0 if the first frame isnt a keyframe + s->slice_height= s->mb_height; //to avoid 1/0 if the first frame is not a keyframe return 0; } @@ -1382,7 +1392,7 @@ static void msmpeg4v2_encode_motion(MpegEncContext * s, int val) } #endif -/* this is identical to h263 except that its range is multiplied by 2 */ +/* This is identical to h263 except that its range is multiplied by 2. */ static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code) { int code, val, sign, shift; @@ -1491,7 +1501,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) s->dsp.clear_blocks(s->block[0]); for (i = 0; i < 6; i++) { - if (msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0) + if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0) { av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i); return -1; @@ -1524,7 +1534,7 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) } } - code = get_vlc2(&s->gb, mb_non_intra_vlc[DEFAULT_INTER_INDEX].table, MB_NON_INTRA_VLC_BITS, 3); + code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX].table, MB_NON_INTRA_VLC_BITS, 3); if (code < 0) return -1; //s->mb_intra = (code & 0x40) ? 0 : 1; @@ -1541,7 +1551,7 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) for(i=0;i<6;i++) { int val = ((code >> (5 - i)) & 1); if (i < 4) { - int pred = coded_block_pred(s, i, &coded_val); + int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_val); val = val ^ pred; *coded_val = val; } @@ -1557,7 +1567,7 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) s->rl_chroma_table_index = s->rl_table_index; } h263_pred_motion(s, 0, 0, &mx, &my); - if (msmpeg4_decode_motion(s, &mx, &my) < 0) + if (ff_msmpeg4_decode_motion(s, &mx, &my) < 0) return -1; s->mv_dir = MV_DIR_FORWARD; s->mv_type = MV_TYPE_16X16; @@ -1569,7 +1579,7 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) s->ac_pred = get_bits1(&s->gb); *mb_type_ptr = MB_TYPE_INTRA; if(s->inter_intra_pred){ - s->h263_aic_dir= get_vlc2(&s->gb, inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1); + s->h263_aic_dir= get_vlc2(&s->gb, ff_inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1); // printf("%d%d %d %d/", s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y); } if(s->per_mb_rl_table && cbp){ @@ -1580,7 +1590,7 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) s->dsp.clear_blocks(s->block[0]); for (i = 0; i < 6; i++) { - if (msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0) + if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0) { av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i); return -1; @@ -1590,7 +1600,7 @@ static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) return 0; } //#define ERROR_DETAILS -static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, +int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, int n, int coded, const uint8_t *scan_table) { int level, i, last, run, run_diff; @@ -1626,7 +1636,7 @@ static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, } block[0] = level; - run_diff = 0; + run_diff = s->msmpeg4_version >= 4; i = 0; if (!coded) { goto not_coded; @@ -1894,7 +1904,7 @@ static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) return level; } -static int msmpeg4_decode_motion(MpegEncContext * s, +int ff_msmpeg4_decode_motion(MpegEncContext * s, int *mx_ptr, int *my_ptr) { MVTable *mv; @@ -1932,9 +1942,3 @@ static int msmpeg4_decode_motion(MpegEncContext * s, *my_ptr = my; return 0; } - -/* cleanest way to support it - * there is too much shared between versions so that we cant have 1 file per version & 1 common - * as allmost everything would be in the common file - */ -#include "wmv2.c" diff --git a/contrib/ffmpeg/libavcodec/msmpeg4.h b/contrib/ffmpeg/libavcodec/msmpeg4.h new file mode 100644 index 000000000..17288b8e2 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/msmpeg4.h @@ -0,0 +1,65 @@ +/* + * MSMPEG4 backend for ffmpeg encoder and decoder + * copyright (c) 2007 Aurelien Jacobs + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file msmpeg4.h + */ + +#ifndef FFMPEG_MSMPEG4_H +#define FFMPEG_MSMPEG4_H + +#include "config.h" +#include "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" + +#define INTER_INTRA_VLC_BITS 3 +#define MB_NON_INTRA_VLC_BITS 9 +#define MB_INTRA_VLC_BITS 9 + +extern VLC ff_mb_non_intra_vlc[4]; +extern VLC ff_inter_intra_vlc; + +void ff_msmpeg4_code012(PutBitContext *pb, int n); +void ff_msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n); +void ff_msmpeg4_handle_slices(MpegEncContext *s); +void ff_msmpeg4_encode_motion(MpegEncContext * s, int mx, int my); +int ff_msmpeg4_coded_block_pred(MpegEncContext * s, int n, + uint8_t **coded_block_ptr); +int ff_msmpeg4_decode_motion(MpegEncContext * s, int *mx_ptr, int *my_ptr); +int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, + int n, int coded, const uint8_t *scan_table); +int ff_wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64]); + +#define ENABLE_MSMPEG4_DECODER (ENABLE_MSMPEG4V1_DECODER || \ + ENABLE_MSMPEG4V2_DECODER || \ + ENABLE_MSMPEG4V3_DECODER || \ + ENABLE_WMV2_DECODER) +#define ENABLE_MSMPEG4_ENCODER (ENABLE_MSMPEG4V1_ENCODER || \ + ENABLE_MSMPEG4V2_ENCODER || \ + ENABLE_MSMPEG4V3_ENCODER || \ + ENABLE_WMV2_ENCODER) +#define ENABLE_MSMPEG4 (ENABLE_MSMPEG4_DECODER || ENABLE_MSMPEG4_ENCODER) +#define ENABLE_WMV2 (ENABLE_WMV2_DECODER || ENABLE_WMV2_ENCODER) +#define ENABLE_WMV_DECODER (ENABLE_WMV1_DECODER || ENABLE_WMV2_DECODER) +#define ENABLE_WMV_ENCODER (ENABLE_WMV1_ENCODER || ENABLE_WMV2_ENCODER) + +#endif /* FFMPEG_MSMPEG4_H */ diff --git a/contrib/ffmpeg/libavcodec/msmpeg4data.c b/contrib/ffmpeg/libavcodec/msmpeg4data.c new file mode 100644 index 000000000..8ad462c03 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/msmpeg4data.c @@ -0,0 +1,2005 @@ +/* + * MSMPEG4 backend for ffmpeg encoder and decoder + * copyright (c) 2001 Fabrice Bellard + * copyright (c) 2002-2004 Michael Niedermayer + * + * msmpeg4v1 & v2 stuff by Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file msmpeg4data.c + * MSMPEG4 data tables. + */ + +#include "msmpeg4data.h" + +VLC ff_msmp4_mb_i_vlc; +VLC ff_msmp4_dc_luma_vlc[2]; +VLC ff_msmp4_dc_chroma_vlc[2]; + +/* intra picture macro block coded block pattern */ +const uint16_t ff_msmp4_mb_i_table[64][2] = { +{ 0x1, 1 },{ 0x17, 6 },{ 0x9, 5 },{ 0x5, 5 }, +{ 0x6, 5 },{ 0x47, 9 },{ 0x20, 7 },{ 0x10, 7 }, +{ 0x2, 5 },{ 0x7c, 9 },{ 0x3a, 7 },{ 0x1d, 7 }, +{ 0x2, 6 },{ 0xec, 9 },{ 0x77, 8 },{ 0x0, 8 }, +{ 0x3, 5 },{ 0xb7, 9 },{ 0x2c, 7 },{ 0x13, 7 }, +{ 0x1, 6 },{ 0x168, 10 },{ 0x46, 8 },{ 0x3f, 8 }, +{ 0x1e, 6 },{ 0x712, 13 },{ 0xb5, 9 },{ 0x42, 8 }, +{ 0x22, 7 },{ 0x1c5, 11 },{ 0x11e, 10 },{ 0x87, 9 }, +{ 0x6, 4 },{ 0x3, 9 },{ 0x1e, 7 },{ 0x1c, 6 }, +{ 0x12, 7 },{ 0x388, 12 },{ 0x44, 9 },{ 0x70, 9 }, +{ 0x1f, 6 },{ 0x23e, 11 },{ 0x39, 8 },{ 0x8e, 9 }, +{ 0x1, 7 },{ 0x1c6, 11 },{ 0xb6, 9 },{ 0x45, 9 }, +{ 0x14, 6 },{ 0x23f, 11 },{ 0x7d, 9 },{ 0x18, 9 }, +{ 0x7, 7 },{ 0x1c7, 11 },{ 0x86, 9 },{ 0x19, 9 }, +{ 0x15, 6 },{ 0x1db, 10 },{ 0x2, 9 },{ 0x46, 9 }, +{ 0xd, 8 },{ 0x713, 13 },{ 0x1da, 10 },{ 0x169, 10 }, +}; + +/* non intra picture macro block coded block pattern + mb type */ +const uint32_t table_mb_non_intra[128][2] = { +{ 0x40, 7 },{ 0x13c9, 13 },{ 0x9fd, 12 },{ 0x1fc, 15 }, +{ 0x9fc, 12 },{ 0xa83, 18 },{ 0x12d34, 17 },{ 0x83bc, 16 }, +{ 0x83a, 12 },{ 0x7f8, 17 },{ 0x3fd, 16 },{ 0x3ff, 16 }, +{ 0x79, 13 },{ 0xa82, 18 },{ 0x969d, 16 },{ 0x2a4, 16 }, +{ 0x978, 12 },{ 0x543, 17 },{ 0x41df, 15 },{ 0x7f9, 17 }, +{ 0x12f3, 13 },{ 0x25a6b, 18 },{ 0x25ef9, 18 },{ 0x3fa, 16 }, +{ 0x20ee, 14 },{ 0x969ab, 20 },{ 0x969c, 16 },{ 0x25ef8, 18 }, +{ 0x12d2, 13 },{ 0xa85, 18 },{ 0x969e, 16 },{ 0x4bc8, 15 }, +{ 0x3d, 12 },{ 0x12f7f, 17 },{ 0x2a2, 16 },{ 0x969f, 16 }, +{ 0x25ee, 14 },{ 0x12d355, 21 },{ 0x12f7d, 17 },{ 0x12f7e, 17 }, +{ 0x9e5, 12 },{ 0xa81, 18 },{ 0x4b4d4, 19 },{ 0x83bd, 16 }, +{ 0x78, 13 },{ 0x969b, 16 },{ 0x3fe, 16 },{ 0x2a5, 16 }, +{ 0x7e, 13 },{ 0xa80, 18 },{ 0x2a3, 16 },{ 0x3fb, 16 }, +{ 0x1076, 13 },{ 0xa84, 18 },{ 0x153, 15 },{ 0x4bc9, 15 }, +{ 0x55, 13 },{ 0x12d354, 21 },{ 0x4bde, 15 },{ 0x25e5, 14 }, +{ 0x25b, 10 },{ 0x4b4c, 15 },{ 0x96b, 12 },{ 0x96a, 12 }, +{ 0x1, 2 },{ 0x0, 7 },{ 0x26, 6 },{ 0x12b, 9 }, +{ 0x7, 3 },{ 0x20f, 10 },{ 0x4, 9 },{ 0x28, 12 }, +{ 0x6, 3 },{ 0x20a, 10 },{ 0x128, 9 },{ 0x2b, 12 }, +{ 0x11, 5 },{ 0x1b, 11 },{ 0x13a, 9 },{ 0x4ff, 11 }, +{ 0x3, 4 },{ 0x277, 10 },{ 0x106, 9 },{ 0x839, 12 }, +{ 0xb, 4 },{ 0x27b, 10 },{ 0x12c, 9 },{ 0x4bf, 11 }, +{ 0x9, 6 },{ 0x35, 12 },{ 0x27e, 10 },{ 0x13c8, 13 }, +{ 0x1, 6 },{ 0x4aa, 11 },{ 0x208, 10 },{ 0x29, 12 }, +{ 0x1, 4 },{ 0x254, 10 },{ 0x12e, 9 },{ 0x838, 12 }, +{ 0x24, 6 },{ 0x4f3, 11 },{ 0x276, 10 },{ 0x12f6, 13 }, +{ 0x1, 5 },{ 0x27a, 10 },{ 0x13e, 9 },{ 0x3e, 12 }, +{ 0x8, 6 },{ 0x413, 11 },{ 0xc, 10 },{ 0x4be, 11 }, +{ 0x14, 5 },{ 0x412, 11 },{ 0x253, 10 },{ 0x97a, 12 }, +{ 0x21, 6 },{ 0x4ab, 11 },{ 0x20b, 10 },{ 0x34, 12 }, +{ 0x15, 5 },{ 0x278, 10 },{ 0x252, 10 },{ 0x968, 12 }, +{ 0x5, 5 },{ 0xb, 10 },{ 0x9c, 8 },{ 0xe, 10 }, +}; + +/* dc table 0 */ + +const uint32_t ff_table0_dc_lum[120][2] = { +{ 0x1, 1 },{ 0x1, 2 },{ 0x1, 4 },{ 0x1, 5 }, +{ 0x5, 5 },{ 0x7, 5 },{ 0x8, 6 },{ 0xc, 6 }, +{ 0x0, 7 },{ 0x2, 7 },{ 0x12, 7 },{ 0x1a, 7 }, +{ 0x3, 8 },{ 0x7, 8 },{ 0x27, 8 },{ 0x37, 8 }, +{ 0x5, 9 },{ 0x4c, 9 },{ 0x6c, 9 },{ 0x6d, 9 }, +{ 0x8, 10 },{ 0x19, 10 },{ 0x9b, 10 },{ 0x1b, 10 }, +{ 0x9a, 10 },{ 0x13, 11 },{ 0x34, 11 },{ 0x35, 11 }, +{ 0x61, 12 },{ 0x48, 13 },{ 0xc4, 13 },{ 0x4a, 13 }, +{ 0xc6, 13 },{ 0xc7, 13 },{ 0x92, 14 },{ 0x18b, 14 }, +{ 0x93, 14 },{ 0x183, 14 },{ 0x182, 14 },{ 0x96, 14 }, +{ 0x97, 14 },{ 0x180, 14 },{ 0x314, 15 },{ 0x315, 15 }, +{ 0x605, 16 },{ 0x604, 16 },{ 0x606, 16 },{ 0xc0e, 17 }, +{ 0x303cd, 23 },{ 0x303c9, 23 },{ 0x303c8, 23 },{ 0x303ca, 23 }, +{ 0x303cb, 23 },{ 0x303cc, 23 },{ 0x303ce, 23 },{ 0x303cf, 23 }, +{ 0x303d0, 23 },{ 0x303d1, 23 },{ 0x303d2, 23 },{ 0x303d3, 23 }, +{ 0x303d4, 23 },{ 0x303d5, 23 },{ 0x303d6, 23 },{ 0x303d7, 23 }, +{ 0x303d8, 23 },{ 0x303d9, 23 },{ 0x303da, 23 },{ 0x303db, 23 }, +{ 0x303dc, 23 },{ 0x303dd, 23 },{ 0x303de, 23 },{ 0x303df, 23 }, +{ 0x303e0, 23 },{ 0x303e1, 23 },{ 0x303e2, 23 },{ 0x303e3, 23 }, +{ 0x303e4, 23 },{ 0x303e5, 23 },{ 0x303e6, 23 },{ 0x303e7, 23 }, +{ 0x303e8, 23 },{ 0x303e9, 23 },{ 0x303ea, 23 },{ 0x303eb, 23 }, +{ 0x303ec, 23 },{ 0x303ed, 23 },{ 0x303ee, 23 },{ 0x303ef, 23 }, +{ 0x303f0, 23 },{ 0x303f1, 23 },{ 0x303f2, 23 },{ 0x303f3, 23 }, +{ 0x303f4, 23 },{ 0x303f5, 23 },{ 0x303f6, 23 },{ 0x303f7, 23 }, +{ 0x303f8, 23 },{ 0x303f9, 23 },{ 0x303fa, 23 },{ 0x303fb, 23 }, +{ 0x303fc, 23 },{ 0x303fd, 23 },{ 0x303fe, 23 },{ 0x303ff, 23 }, +{ 0x60780, 24 },{ 0x60781, 24 },{ 0x60782, 24 },{ 0x60783, 24 }, +{ 0x60784, 24 },{ 0x60785, 24 },{ 0x60786, 24 },{ 0x60787, 24 }, +{ 0x60788, 24 },{ 0x60789, 24 },{ 0x6078a, 24 },{ 0x6078b, 24 }, +{ 0x6078c, 24 },{ 0x6078d, 24 },{ 0x6078e, 24 },{ 0x6078f, 24 }, +}; + +const uint32_t ff_table0_dc_chroma[120][2] = { +{ 0x0, 2 },{ 0x1, 2 },{ 0x5, 3 },{ 0x9, 4 }, +{ 0xd, 4 },{ 0x11, 5 },{ 0x1d, 5 },{ 0x1f, 5 }, +{ 0x21, 6 },{ 0x31, 6 },{ 0x38, 6 },{ 0x33, 6 }, +{ 0x39, 6 },{ 0x3d, 6 },{ 0x61, 7 },{ 0x79, 7 }, +{ 0x80, 8 },{ 0xc8, 8 },{ 0xca, 8 },{ 0xf0, 8 }, +{ 0x81, 8 },{ 0xc0, 8 },{ 0xc9, 8 },{ 0x107, 9 }, +{ 0x106, 9 },{ 0x196, 9 },{ 0x183, 9 },{ 0x1e3, 9 }, +{ 0x1e2, 9 },{ 0x20a, 10 },{ 0x20b, 10 },{ 0x609, 11 }, +{ 0x412, 11 },{ 0x413, 11 },{ 0x60b, 11 },{ 0x411, 11 }, +{ 0x60a, 11 },{ 0x65f, 11 },{ 0x410, 11 },{ 0x65d, 11 }, +{ 0x65e, 11 },{ 0xcb8, 12 },{ 0xc10, 12 },{ 0xcb9, 12 }, +{ 0x1823, 13 },{ 0x3045, 14 },{ 0x6089, 15 },{ 0xc110, 16 }, +{ 0x304448, 22 },{ 0x304449, 22 },{ 0x30444a, 22 },{ 0x30444b, 22 }, +{ 0x30444c, 22 },{ 0x30444d, 22 },{ 0x30444e, 22 },{ 0x30444f, 22 }, +{ 0x304450, 22 },{ 0x304451, 22 },{ 0x304452, 22 },{ 0x304453, 22 }, +{ 0x304454, 22 },{ 0x304455, 22 },{ 0x304456, 22 },{ 0x304457, 22 }, +{ 0x304458, 22 },{ 0x304459, 22 },{ 0x30445a, 22 },{ 0x30445b, 22 }, +{ 0x30445c, 22 },{ 0x30445d, 22 },{ 0x30445e, 22 },{ 0x30445f, 22 }, +{ 0x304460, 22 },{ 0x304461, 22 },{ 0x304462, 22 },{ 0x304463, 22 }, +{ 0x304464, 22 },{ 0x304465, 22 },{ 0x304466, 22 },{ 0x304467, 22 }, +{ 0x304468, 22 },{ 0x304469, 22 },{ 0x30446a, 22 },{ 0x30446b, 22 }, +{ 0x30446c, 22 },{ 0x30446d, 22 },{ 0x30446e, 22 },{ 0x30446f, 22 }, +{ 0x304470, 22 },{ 0x304471, 22 },{ 0x304472, 22 },{ 0x304473, 22 }, +{ 0x304474, 22 },{ 0x304475, 22 },{ 0x304476, 22 },{ 0x304477, 22 }, +{ 0x304478, 22 },{ 0x304479, 22 },{ 0x30447a, 22 },{ 0x30447b, 22 }, +{ 0x30447c, 22 },{ 0x30447d, 22 },{ 0x30447e, 22 },{ 0x30447f, 22 }, +{ 0x608880, 23 },{ 0x608881, 23 },{ 0x608882, 23 },{ 0x608883, 23 }, +{ 0x608884, 23 },{ 0x608885, 23 },{ 0x608886, 23 },{ 0x608887, 23 }, +{ 0x608888, 23 },{ 0x608889, 23 },{ 0x60888a, 23 },{ 0x60888b, 23 }, +{ 0x60888c, 23 },{ 0x60888d, 23 },{ 0x60888e, 23 },{ 0x60888f, 23 }, +}; + +/* dc table 1 */ + +const uint32_t ff_table1_dc_lum[120][2] = { +{ 0x2, 2 },{ 0x3, 2 },{ 0x3, 3 },{ 0x2, 4 }, +{ 0x5, 4 },{ 0x1, 5 },{ 0x3, 5 },{ 0x8, 5 }, +{ 0x0, 6 },{ 0x5, 6 },{ 0xd, 6 },{ 0xf, 6 }, +{ 0x13, 6 },{ 0x8, 7 },{ 0x18, 7 },{ 0x1c, 7 }, +{ 0x24, 7 },{ 0x4, 8 },{ 0x6, 8 },{ 0x12, 8 }, +{ 0x32, 8 },{ 0x3b, 8 },{ 0x4a, 8 },{ 0x4b, 8 }, +{ 0xb, 9 },{ 0x26, 9 },{ 0x27, 9 },{ 0x66, 9 }, +{ 0x74, 9 },{ 0x75, 9 },{ 0x14, 10 },{ 0x1c, 10 }, +{ 0x1f, 10 },{ 0x1d, 10 },{ 0x2b, 11 },{ 0x3d, 11 }, +{ 0x19d, 11 },{ 0x19f, 11 },{ 0x54, 12 },{ 0x339, 12 }, +{ 0x338, 12 },{ 0x33d, 12 },{ 0xab, 13 },{ 0xf1, 13 }, +{ 0x678, 13 },{ 0xf2, 13 },{ 0x1e0, 14 },{ 0x1e1, 14 }, +{ 0x154, 14 },{ 0xcf2, 14 },{ 0x3cc, 15 },{ 0x2ab, 15 }, +{ 0x19e7, 15 },{ 0x3ce, 15 },{ 0x19e6, 15 },{ 0x554, 16 }, +{ 0x79f, 16 },{ 0x555, 16 },{ 0xf3d, 17 },{ 0xf37, 17 }, +{ 0xf3c, 17 },{ 0xf35, 17 },{ 0x1e6d, 18 },{ 0x1e68, 18 }, +{ 0x3cd8, 19 },{ 0x3cd3, 19 },{ 0x3cd9, 19 },{ 0x79a4, 20 }, +{ 0xf34ba, 25 },{ 0xf34b4, 25 },{ 0xf34b5, 25 },{ 0xf34b6, 25 }, +{ 0xf34b7, 25 },{ 0xf34b8, 25 },{ 0xf34b9, 25 },{ 0xf34bb, 25 }, +{ 0xf34bc, 25 },{ 0xf34bd, 25 },{ 0xf34be, 25 },{ 0xf34bf, 25 }, +{ 0x1e6940, 26 },{ 0x1e6941, 26 },{ 0x1e6942, 26 },{ 0x1e6943, 26 }, +{ 0x1e6944, 26 },{ 0x1e6945, 26 },{ 0x1e6946, 26 },{ 0x1e6947, 26 }, +{ 0x1e6948, 26 },{ 0x1e6949, 26 },{ 0x1e694a, 26 },{ 0x1e694b, 26 }, +{ 0x1e694c, 26 },{ 0x1e694d, 26 },{ 0x1e694e, 26 },{ 0x1e694f, 26 }, +{ 0x1e6950, 26 },{ 0x1e6951, 26 },{ 0x1e6952, 26 },{ 0x1e6953, 26 }, +{ 0x1e6954, 26 },{ 0x1e6955, 26 },{ 0x1e6956, 26 },{ 0x1e6957, 26 }, +{ 0x1e6958, 26 },{ 0x1e6959, 26 },{ 0x1e695a, 26 },{ 0x1e695b, 26 }, +{ 0x1e695c, 26 },{ 0x1e695d, 26 },{ 0x1e695e, 26 },{ 0x1e695f, 26 }, +{ 0x1e6960, 26 },{ 0x1e6961, 26 },{ 0x1e6962, 26 },{ 0x1e6963, 26 }, +{ 0x1e6964, 26 },{ 0x1e6965, 26 },{ 0x1e6966, 26 },{ 0x1e6967, 26 }, +}; + +const uint32_t ff_table1_dc_chroma[120][2] = { +{ 0x0, 2 },{ 0x1, 2 },{ 0x4, 3 },{ 0x7, 3 }, +{ 0xb, 4 },{ 0xd, 4 },{ 0x15, 5 },{ 0x28, 6 }, +{ 0x30, 6 },{ 0x32, 6 },{ 0x52, 7 },{ 0x62, 7 }, +{ 0x66, 7 },{ 0xa6, 8 },{ 0xc6, 8 },{ 0xcf, 8 }, +{ 0x14f, 9 },{ 0x18e, 9 },{ 0x19c, 9 },{ 0x29d, 10 }, +{ 0x33a, 10 },{ 0x538, 11 },{ 0x63c, 11 },{ 0x63e, 11 }, +{ 0x63f, 11 },{ 0x676, 11 },{ 0xa73, 12 },{ 0xc7a, 12 }, +{ 0xcef, 12 },{ 0x14e5, 13 },{ 0x19dd, 13 },{ 0x29c8, 14 }, +{ 0x29c9, 14 },{ 0x63dd, 15 },{ 0x33b8, 14 },{ 0x33b9, 14 }, +{ 0xc7b6, 16 },{ 0x63d8, 15 },{ 0x63df, 15 },{ 0xc7b3, 16 }, +{ 0xc7b4, 16 },{ 0xc7b5, 16 },{ 0x63de, 15 },{ 0xc7b7, 16 }, +{ 0xc7b8, 16 },{ 0xc7b9, 16 },{ 0x18f65, 17 },{ 0x31ec8, 18 }, +{ 0xc7b248, 24 },{ 0xc7b249, 24 },{ 0xc7b24a, 24 },{ 0xc7b24b, 24 }, +{ 0xc7b24c, 24 },{ 0xc7b24d, 24 },{ 0xc7b24e, 24 },{ 0xc7b24f, 24 }, +{ 0xc7b250, 24 },{ 0xc7b251, 24 },{ 0xc7b252, 24 },{ 0xc7b253, 24 }, +{ 0xc7b254, 24 },{ 0xc7b255, 24 },{ 0xc7b256, 24 },{ 0xc7b257, 24 }, +{ 0xc7b258, 24 },{ 0xc7b259, 24 },{ 0xc7b25a, 24 },{ 0xc7b25b, 24 }, +{ 0xc7b25c, 24 },{ 0xc7b25d, 24 },{ 0xc7b25e, 24 },{ 0xc7b25f, 24 }, +{ 0xc7b260, 24 },{ 0xc7b261, 24 },{ 0xc7b262, 24 },{ 0xc7b263, 24 }, +{ 0xc7b264, 24 },{ 0xc7b265, 24 },{ 0xc7b266, 24 },{ 0xc7b267, 24 }, +{ 0xc7b268, 24 },{ 0xc7b269, 24 },{ 0xc7b26a, 24 },{ 0xc7b26b, 24 }, +{ 0xc7b26c, 24 },{ 0xc7b26d, 24 },{ 0xc7b26e, 24 },{ 0xc7b26f, 24 }, +{ 0xc7b270, 24 },{ 0xc7b271, 24 },{ 0xc7b272, 24 },{ 0xc7b273, 24 }, +{ 0xc7b274, 24 },{ 0xc7b275, 24 },{ 0xc7b276, 24 },{ 0xc7b277, 24 }, +{ 0xc7b278, 24 },{ 0xc7b279, 24 },{ 0xc7b27a, 24 },{ 0xc7b27b, 24 }, +{ 0xc7b27c, 24 },{ 0xc7b27d, 24 },{ 0xc7b27e, 24 },{ 0xc7b27f, 24 }, +{ 0x18f6480, 25 },{ 0x18f6481, 25 },{ 0x18f6482, 25 },{ 0x18f6483, 25 }, +{ 0x18f6484, 25 },{ 0x18f6485, 25 },{ 0x18f6486, 25 },{ 0x18f6487, 25 }, +{ 0x18f6488, 25 },{ 0x18f6489, 25 },{ 0x18f648a, 25 },{ 0x18f648b, 25 }, +{ 0x18f648c, 25 },{ 0x18f648d, 25 },{ 0x18f648e, 25 },{ 0x18f648f, 25 }, +}; + +/* vlc table 0, for intra luma */ + +static const uint16_t table0_vlc[133][2] = { +{ 0x1, 2 },{ 0x6, 3 },{ 0xf, 4 },{ 0x16, 5 }, +{ 0x20, 6 },{ 0x18, 7 },{ 0x8, 8 },{ 0x9a, 8 }, +{ 0x56, 9 },{ 0x13e, 9 },{ 0xf0, 10 },{ 0x3a5, 10 }, +{ 0x77, 11 },{ 0x1ef, 11 },{ 0x9a, 12 },{ 0x5d, 13 }, +{ 0x1, 4 },{ 0x11, 5 },{ 0x2, 7 },{ 0xb, 8 }, +{ 0x12, 9 },{ 0x1d6, 9 },{ 0x27e, 10 },{ 0x191, 11 }, +{ 0xea, 12 },{ 0x3dc, 12 },{ 0x13b, 13 },{ 0x4, 5 }, +{ 0x14, 7 },{ 0x9e, 8 },{ 0x9, 10 },{ 0x1ac, 11 }, +{ 0x1e2, 11 },{ 0x3ca, 12 },{ 0x5f, 13 },{ 0x17, 5 }, +{ 0x4e, 7 },{ 0x5e, 9 },{ 0xf3, 10 },{ 0x1ad, 11 }, +{ 0xec, 12 },{ 0x5f0, 13 },{ 0xe, 6 },{ 0xe1, 8 }, +{ 0x3a4, 10 },{ 0x9c, 12 },{ 0x13d, 13 },{ 0x3b, 6 }, +{ 0x1c, 9 },{ 0x14, 11 },{ 0x9be, 12 },{ 0x6, 7 }, +{ 0x7a, 9 },{ 0x190, 11 },{ 0x137, 13 },{ 0x1b, 7 }, +{ 0x8, 10 },{ 0x75c, 11 },{ 0x71, 7 },{ 0xd7, 10 }, +{ 0x9bf, 12 },{ 0x7, 8 },{ 0xaf, 10 },{ 0x4cc, 11 }, +{ 0x34, 8 },{ 0x265, 10 },{ 0x9f, 12 },{ 0xe0, 8 }, +{ 0x16, 11 },{ 0x327, 12 },{ 0x15, 9 },{ 0x17d, 11 }, +{ 0xebb, 12 },{ 0x14, 9 },{ 0xf6, 10 },{ 0x1e4, 11 }, +{ 0xcb, 10 },{ 0x99d, 12 },{ 0xca, 10 },{ 0x2fc, 12 }, +{ 0x17f, 11 },{ 0x4cd, 11 },{ 0x2fd, 12 },{ 0x4fe, 11 }, +{ 0x13a, 13 },{ 0xa, 4 },{ 0x42, 7 },{ 0x1d3, 9 }, +{ 0x4dd, 11 },{ 0x12, 5 },{ 0xe8, 8 },{ 0x4c, 11 }, +{ 0x136, 13 },{ 0x39, 6 },{ 0x264, 10 },{ 0xeba, 12 }, +{ 0x0, 7 },{ 0xae, 10 },{ 0x99c, 12 },{ 0x1f, 7 }, +{ 0x4de, 11 },{ 0x43, 7 },{ 0x4dc, 11 },{ 0x3, 8 }, +{ 0x3cb, 12 },{ 0x6, 8 },{ 0x99e, 12 },{ 0x2a, 8 }, +{ 0x5f1, 13 },{ 0xf, 8 },{ 0x9fe, 12 },{ 0x33, 8 }, +{ 0x9ff, 12 },{ 0x98, 8 },{ 0x99f, 12 },{ 0xea, 8 }, +{ 0x13c, 13 },{ 0x2e, 8 },{ 0x192, 11 },{ 0x136, 9 }, +{ 0x6a, 9 },{ 0x15, 11 },{ 0x3af, 10 },{ 0x1e3, 11 }, +{ 0x74, 11 },{ 0xeb, 12 },{ 0x2f9, 12 },{ 0x5c, 13 }, +{ 0xed, 12 },{ 0x3dd, 12 },{ 0x326, 12 },{ 0x5e, 13 }, +{ 0x16, 7 }, +}; + +static const int8_t table0_level[132] = { + 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 1, 2, 3, 4, 5, + 6, 7, 8, 1, 2, 3, 4, 5, + 6, 7, 1, 2, 3, 4, 5, 1, + 2, 3, 4, 1, 2, 3, 4, 1, + 2, 3, 1, 2, 3, 1, 2, 3, + 1, 2, 3, 1, 2, 3, 1, 2, + 3, 1, 2, 3, 1, 2, 1, 2, + 1, 1, 1, 1, 1, 1, 2, 3, + 4, 1, 2, 3, 4, 1, 2, 3, + 1, 2, 3, 1, 2, 1, 2, 1, + 2, 1, 2, 1, 2, 1, 2, 1, + 2, 1, 2, 1, 2, 1, 2, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, +}; + +static const int8_t table0_run[132] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 2, 2, 2, 2, 2, + 2, 2, 2, 3, 3, 3, 3, 3, + 3, 3, 4, 4, 4, 4, 4, 5, + 5, 5, 5, 6, 6, 6, 6, 7, + 7, 7, 8, 8, 8, 9, 9, 9, + 10, 10, 10, 11, 11, 11, 12, 12, + 12, 13, 13, 13, 14, 14, 15, 15, + 16, 17, 18, 19, 20, 0, 0, 0, + 0, 1, 1, 1, 1, 2, 2, 2, + 3, 3, 3, 4, 4, 5, 5, 6, + 6, 7, 7, 8, 8, 9, 9, 10, + 10, 11, 11, 12, 12, 13, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, + 23, 24, 25, 26, +}; + +/* vlc table 1, for intra chroma and P macro blocks */ + +static const uint16_t table1_vlc[149][2] = { +{ 0x4, 3 },{ 0x14, 5 },{ 0x17, 7 },{ 0x7f, 8 }, +{ 0x154, 9 },{ 0x1f2, 10 },{ 0xbf, 11 },{ 0x65, 12 }, +{ 0xaaa, 12 },{ 0x630, 13 },{ 0x1597, 13 },{ 0x3b7, 14 }, +{ 0x2b22, 14 },{ 0xbe6, 15 },{ 0xb, 4 },{ 0x37, 7 }, +{ 0x62, 9 },{ 0x7, 11 },{ 0x166, 12 },{ 0xce, 13 }, +{ 0x1590, 13 },{ 0x5f6, 14 },{ 0xbe7, 15 },{ 0x7, 5 }, +{ 0x6d, 8 },{ 0x3, 11 },{ 0x31f, 12 },{ 0x5f2, 14 }, +{ 0x2, 6 },{ 0x61, 9 },{ 0x55, 12 },{ 0x1df, 14 }, +{ 0x1a, 6 },{ 0x1e, 10 },{ 0xac9, 12 },{ 0x2b23, 14 }, +{ 0x1e, 6 },{ 0x1f, 10 },{ 0xac3, 12 },{ 0x2b2b, 14 }, +{ 0x6, 7 },{ 0x4, 11 },{ 0x2f8, 13 },{ 0x19, 7 }, +{ 0x6, 11 },{ 0x63d, 13 },{ 0x57, 7 },{ 0x182, 11 }, +{ 0x2aa2, 14 },{ 0x4, 8 },{ 0x180, 11 },{ 0x59c, 14 }, +{ 0x7d, 8 },{ 0x164, 12 },{ 0x76d, 15 },{ 0x2, 9 }, +{ 0x18d, 11 },{ 0x1581, 13 },{ 0xad, 8 },{ 0x60, 12 }, +{ 0xc67, 14 },{ 0x1c, 9 },{ 0xee, 13 },{ 0x3, 9 }, +{ 0x2cf, 13 },{ 0xd9, 9 },{ 0x1580, 13 },{ 0x2, 11 }, +{ 0x183, 11 },{ 0x57, 12 },{ 0x61, 12 },{ 0x31, 11 }, +{ 0x66, 12 },{ 0x631, 13 },{ 0x632, 13 },{ 0xac, 13 }, +{ 0x31d, 12 },{ 0x76, 12 },{ 0x3a, 11 },{ 0x165, 12 }, +{ 0xc66, 14 },{ 0x3, 2 },{ 0x54, 7 },{ 0x2ab, 10 }, +{ 0x16, 13 },{ 0x5f7, 14 },{ 0x5, 4 },{ 0xf8, 9 }, +{ 0xaa9, 12 },{ 0x5f, 15 },{ 0x4, 4 },{ 0x1c, 10 }, +{ 0x1550, 13 },{ 0x4, 5 },{ 0x77, 11 },{ 0x76c, 15 }, +{ 0xe, 5 },{ 0xa, 12 },{ 0xc, 5 },{ 0x562, 11 }, +{ 0x4, 6 },{ 0x31c, 12 },{ 0x6, 6 },{ 0xc8, 13 }, +{ 0xd, 6 },{ 0x1da, 13 },{ 0x7, 6 },{ 0xc9, 13 }, +{ 0x1, 7 },{ 0x2e, 14 },{ 0x14, 7 },{ 0x1596, 13 }, +{ 0xa, 7 },{ 0xac2, 12 },{ 0x16, 7 },{ 0x15b, 14 }, +{ 0x15, 7 },{ 0x15a, 14 },{ 0xf, 8 },{ 0x5e, 15 }, +{ 0x7e, 8 },{ 0xab, 8 },{ 0x2d, 9 },{ 0xd8, 9 }, +{ 0xb, 9 },{ 0x14, 10 },{ 0x2b3, 10 },{ 0x1f3, 10 }, +{ 0x3a, 10 },{ 0x0, 10 },{ 0x58, 10 },{ 0x2e, 9 }, +{ 0x5e, 10 },{ 0x563, 11 },{ 0xec, 12 },{ 0x54, 12 }, +{ 0xac1, 12 },{ 0x1556, 13 },{ 0x2fa, 13 },{ 0x181, 11 }, +{ 0x1557, 13 },{ 0x59d, 14 },{ 0x2aa3, 14 },{ 0x2b2a, 14 }, +{ 0x1de, 14 },{ 0x63c, 13 },{ 0xcf, 13 },{ 0x1594, 13 }, +{ 0xd, 9 }, +}; + +static const int8_t table1_level[148] = { + 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 1, 2, + 3, 4, 5, 6, 7, 8, 9, 1, + 2, 3, 4, 5, 1, 2, 3, 4, + 1, 2, 3, 4, 1, 2, 3, 4, + 1, 2, 3, 1, 2, 3, 1, 2, + 3, 1, 2, 3, 1, 2, 3, 1, + 2, 3, 1, 2, 3, 1, 2, 1, + 2, 1, 2, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 2, 3, 4, 5, 1, 2, + 3, 4, 1, 2, 3, 1, 2, 3, + 1, 2, 1, 2, 1, 2, 1, 2, + 1, 2, 1, 2, 1, 2, 1, 2, + 1, 2, 1, 2, 1, 2, 1, 2, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, +}; + +static const int8_t table1_run[148] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 2, + 2, 2, 2, 2, 3, 3, 3, 3, + 4, 4, 4, 4, 5, 5, 5, 5, + 6, 6, 6, 7, 7, 7, 8, 8, + 8, 9, 9, 9, 10, 10, 10, 11, + 11, 11, 12, 12, 12, 13, 13, 14, + 14, 15, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, + 29, 0, 0, 0, 0, 0, 1, 1, + 1, 1, 2, 2, 2, 3, 3, 3, + 4, 4, 5, 5, 6, 6, 7, 7, + 8, 8, 9, 9, 10, 10, 11, 11, + 12, 12, 13, 13, 14, 14, 15, 15, + 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, +}; + +/* third vlc table */ + +static const uint16_t table2_vlc[186][2] = { +{ 0x1, 2 },{ 0x5, 3 },{ 0xd, 4 },{ 0x12, 5 }, +{ 0xe, 6 },{ 0x15, 7 },{ 0x13, 8 },{ 0x3f, 8 }, +{ 0x4b, 9 },{ 0x11f, 9 },{ 0xb8, 10 },{ 0x3e3, 10 }, +{ 0x172, 11 },{ 0x24d, 12 },{ 0x3da, 12 },{ 0x2dd, 13 }, +{ 0x1f55, 13 },{ 0x5b9, 14 },{ 0x3eae, 14 },{ 0x0, 4 }, +{ 0x10, 5 },{ 0x8, 7 },{ 0x20, 8 },{ 0x29, 9 }, +{ 0x1f4, 9 },{ 0x233, 10 },{ 0x1e0, 11 },{ 0x12a, 12 }, +{ 0x3dd, 12 },{ 0x50a, 13 },{ 0x1f29, 13 },{ 0xa42, 14 }, +{ 0x1272, 15 },{ 0x1737, 15 },{ 0x3, 5 },{ 0x11, 7 }, +{ 0xc4, 8 },{ 0x4b, 10 },{ 0xb4, 11 },{ 0x7d4, 11 }, +{ 0x345, 12 },{ 0x2d7, 13 },{ 0x7bf, 13 },{ 0x938, 14 }, +{ 0xbbb, 14 },{ 0x95e, 15 },{ 0x13, 5 },{ 0x78, 7 }, +{ 0x69, 9 },{ 0x232, 10 },{ 0x461, 11 },{ 0x3ec, 12 }, +{ 0x520, 13 },{ 0x1f2a, 13 },{ 0x3e50, 14 },{ 0x3e51, 14 }, +{ 0x1486, 15 },{ 0xc, 6 },{ 0x24, 9 },{ 0x94, 11 }, +{ 0x8c0, 12 },{ 0xf09, 14 },{ 0x1ef0, 15 },{ 0x3d, 6 }, +{ 0x53, 9 },{ 0x1a0, 11 },{ 0x2d6, 13 },{ 0xf08, 14 }, +{ 0x13, 7 },{ 0x7c, 9 },{ 0x7c1, 11 },{ 0x4ac, 14 }, +{ 0x1b, 7 },{ 0xa0, 10 },{ 0x344, 12 },{ 0xf79, 14 }, +{ 0x79, 7 },{ 0x3e1, 10 },{ 0x2d4, 13 },{ 0x2306, 14 }, +{ 0x21, 8 },{ 0x23c, 10 },{ 0xfae, 12 },{ 0x23de, 14 }, +{ 0x35, 8 },{ 0x175, 11 },{ 0x7b3, 13 },{ 0xc5, 8 }, +{ 0x174, 11 },{ 0x785, 13 },{ 0x48, 9 },{ 0x1a3, 11 }, +{ 0x49e, 13 },{ 0x2c, 9 },{ 0xfa, 10 },{ 0x7d6, 11 }, +{ 0x92, 10 },{ 0x5cc, 13 },{ 0x1ef1, 15 },{ 0xa3, 10 }, +{ 0x3ed, 12 },{ 0x93e, 14 },{ 0x1e2, 11 },{ 0x1273, 15 }, +{ 0x7c4, 11 },{ 0x1487, 15 },{ 0x291, 12 },{ 0x293, 12 }, +{ 0xf8a, 12 },{ 0x509, 13 },{ 0x508, 13 },{ 0x78d, 13 }, +{ 0x7be, 13 },{ 0x78c, 13 },{ 0x4ae, 14 },{ 0xbba, 14 }, +{ 0x2307, 14 },{ 0xb9a, 14 },{ 0x1736, 15 },{ 0xe, 4 }, +{ 0x45, 7 },{ 0x1f3, 9 },{ 0x47a, 11 },{ 0x5dc, 13 }, +{ 0x23df, 14 },{ 0x19, 5 },{ 0x28, 9 },{ 0x176, 11 }, +{ 0x49d, 13 },{ 0x23dd, 14 },{ 0x30, 6 },{ 0xa2, 10 }, +{ 0x2ef, 12 },{ 0x5b8, 14 },{ 0x3f, 6 },{ 0xa5, 10 }, +{ 0x3db, 12 },{ 0x93f, 14 },{ 0x44, 7 },{ 0x7cb, 11 }, +{ 0x95f, 15 },{ 0x63, 7 },{ 0x3c3, 12 },{ 0x15, 8 }, +{ 0x8f6, 12 },{ 0x17, 8 },{ 0x498, 13 },{ 0x2c, 8 }, +{ 0x7b2, 13 },{ 0x2f, 8 },{ 0x1f54, 13 },{ 0x8d, 8 }, +{ 0x7bd, 13 },{ 0x8e, 8 },{ 0x1182, 13 },{ 0xfb, 8 }, +{ 0x50b, 13 },{ 0x2d, 8 },{ 0x7c0, 11 },{ 0x79, 9 }, +{ 0x1f5f, 13 },{ 0x7a, 9 },{ 0x1f56, 13 },{ 0x231, 10 }, +{ 0x3e4, 10 },{ 0x1a1, 11 },{ 0x143, 11 },{ 0x1f7, 11 }, +{ 0x16f, 12 },{ 0x292, 12 },{ 0x2e7, 12 },{ 0x16c, 12 }, +{ 0x16d, 12 },{ 0x3dc, 12 },{ 0xf8b, 12 },{ 0x499, 13 }, +{ 0x3d8, 12 },{ 0x78e, 13 },{ 0x2d5, 13 },{ 0x1f5e, 13 }, +{ 0x1f2b, 13 },{ 0x78f, 13 },{ 0x4ad, 14 },{ 0x3eaf, 14 }, +{ 0x23dc, 14 },{ 0x4a, 9 }, +}; + +static const int8_t table2_level[185] = { + 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 1, 2, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 1, 2, + 3, 4, 5, 6, 7, 8, 9, 10, + 11, 1, 2, 3, 4, 5, 6, 1, + 2, 3, 4, 5, 1, 2, 3, 4, + 1, 2, 3, 4, 1, 2, 3, 4, + 1, 2, 3, 4, 1, 2, 3, 1, + 2, 3, 1, 2, 3, 1, 2, 3, + 1, 2, 3, 1, 2, 3, 1, 2, + 1, 2, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 2, 3, 4, 5, 6, 1, 2, 3, + 4, 5, 1, 2, 3, 4, 1, 2, + 3, 4, 1, 2, 3, 1, 2, 1, + 2, 1, 2, 1, 2, 1, 2, 1, + 2, 1, 2, 1, 2, 1, 2, 1, + 2, 1, 2, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, +}; + +static const int8_t table2_run[185] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 4, 4, 4, 4, 4, 4, 5, + 5, 5, 5, 5, 6, 6, 6, 6, + 7, 7, 7, 7, 8, 8, 8, 8, + 9, 9, 9, 9, 10, 10, 10, 11, + 11, 11, 12, 12, 12, 13, 13, 13, + 14, 14, 14, 15, 15, 15, 16, 16, + 17, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 0, + 0, 0, 0, 0, 0, 1, 1, 1, + 1, 1, 2, 2, 2, 2, 3, 3, + 3, 3, 4, 4, 4, 5, 5, 6, + 6, 7, 7, 8, 8, 9, 9, 10, + 10, 11, 11, 12, 12, 13, 13, 14, + 14, 15, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, + 37, +}; + +/* second non intra vlc table */ +static const uint16_t table4_vlc[169][2] = { +{ 0x0, 3 },{ 0x3, 4 },{ 0xb, 5 },{ 0x14, 6 }, +{ 0x3f, 6 },{ 0x5d, 7 },{ 0xa2, 8 },{ 0xac, 9 }, +{ 0x16e, 9 },{ 0x20a, 10 },{ 0x2e2, 10 },{ 0x432, 11 }, +{ 0x5c9, 11 },{ 0x827, 12 },{ 0xb54, 12 },{ 0x4e6, 13 }, +{ 0x105f, 13 },{ 0x172a, 13 },{ 0x20b2, 14 },{ 0x2d4e, 14 }, +{ 0x39f0, 14 },{ 0x4175, 15 },{ 0x5a9e, 15 },{ 0x4, 4 }, +{ 0x1e, 5 },{ 0x42, 7 },{ 0xb6, 8 },{ 0x173, 9 }, +{ 0x395, 10 },{ 0x72e, 11 },{ 0xb94, 12 },{ 0x16a4, 13 }, +{ 0x20b3, 14 },{ 0x2e45, 14 },{ 0x5, 5 },{ 0x40, 7 }, +{ 0x49, 9 },{ 0x28f, 10 },{ 0x5cb, 11 },{ 0x48a, 13 }, +{ 0x9dd, 14 },{ 0x73e2, 15 },{ 0x18, 5 },{ 0x25, 8 }, +{ 0x8a, 10 },{ 0x51b, 11 },{ 0xe5f, 12 },{ 0x9c9, 14 }, +{ 0x139c, 15 },{ 0x29, 6 },{ 0x4f, 9 },{ 0x412, 11 }, +{ 0x48d, 13 },{ 0x2e41, 14 },{ 0x38, 6 },{ 0x10e, 9 }, +{ 0x5a8, 11 },{ 0x105c, 13 },{ 0x39f2, 14 },{ 0x58, 7 }, +{ 0x21f, 10 },{ 0xe7e, 12 },{ 0x39ff, 14 },{ 0x23, 8 }, +{ 0x2e3, 10 },{ 0x4e5, 13 },{ 0x2e40, 14 },{ 0xa1, 8 }, +{ 0x5be, 11 },{ 0x9c8, 14 },{ 0x83, 8 },{ 0x13a, 11 }, +{ 0x1721, 13 },{ 0x44, 9 },{ 0x276, 12 },{ 0x39f6, 14 }, +{ 0x8b, 10 },{ 0x4ef, 13 },{ 0x5a9b, 15 },{ 0x208, 10 }, +{ 0x1cfe, 13 },{ 0x399, 10 },{ 0x1cb4, 13 },{ 0x39e, 10 }, +{ 0x39f3, 14 },{ 0x5ab, 11 },{ 0x73e3, 15 },{ 0x737, 11 }, +{ 0x5a9f, 15 },{ 0x82d, 12 },{ 0xe69, 12 },{ 0xe68, 12 }, +{ 0x433, 11 },{ 0xb7b, 12 },{ 0x2df8, 14 },{ 0x2e56, 14 }, +{ 0x2e57, 14 },{ 0x39f7, 14 },{ 0x51a5, 15 },{ 0x3, 3 }, +{ 0x2a, 6 },{ 0xe4, 8 },{ 0x28e, 10 },{ 0x735, 11 }, +{ 0x1058, 13 },{ 0x1cfa, 13 },{ 0x2df9, 14 },{ 0x4174, 15 }, +{ 0x9, 4 },{ 0x54, 8 },{ 0x398, 10 },{ 0x48b, 13 }, +{ 0x139d, 15 },{ 0xd, 4 },{ 0xad, 9 },{ 0x826, 12 }, +{ 0x2d4c, 14 },{ 0x11, 5 },{ 0x16b, 9 },{ 0xb7f, 12 }, +{ 0x51a4, 15 },{ 0x19, 5 },{ 0x21b, 10 },{ 0x16fd, 13 }, +{ 0x1d, 5 },{ 0x394, 10 },{ 0x28d3, 14 },{ 0x2b, 6 }, +{ 0x5bc, 11 },{ 0x5a9a, 15 },{ 0x2f, 6 },{ 0x247, 12 }, +{ 0x10, 7 },{ 0xa35, 12 },{ 0x3e, 6 },{ 0xb7a, 12 }, +{ 0x59, 7 },{ 0x105e, 13 },{ 0x26, 8 },{ 0x9cf, 14 }, +{ 0x55, 8 },{ 0x1cb5, 13 },{ 0x57, 8 },{ 0xe5b, 12 }, +{ 0xa0, 8 },{ 0x1468, 13 },{ 0x170, 9 },{ 0x90, 10 }, +{ 0x1ce, 9 },{ 0x21a, 10 },{ 0x218, 10 },{ 0x168, 9 }, +{ 0x21e, 10 },{ 0x244, 12 },{ 0x736, 11 },{ 0x138, 11 }, +{ 0x519, 11 },{ 0xe5e, 12 },{ 0x72c, 11 },{ 0xb55, 12 }, +{ 0x9dc, 14 },{ 0x20bb, 14 },{ 0x48c, 13 },{ 0x1723, 13 }, +{ 0x2e44, 14 },{ 0x16a5, 13 },{ 0x518, 11 },{ 0x39fe, 14 }, +{ 0x169, 9 }, +}; + +static const int8_t table4_level[168] = { + 1, 2, 3, 4, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 1, + 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 1, 2, 3, 4, 5, 6, + 7, 8, 1, 2, 3, 4, 5, 6, + 7, 1, 2, 3, 4, 5, 1, 2, + 3, 4, 5, 1, 2, 3, 4, 1, + 2, 3, 4, 1, 2, 3, 1, 2, + 3, 1, 2, 3, 1, 2, 3, 1, + 2, 1, 2, 1, 2, 1, 2, 1, + 2, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 2, 3, 4, 5, + 6, 7, 8, 9, 1, 2, 3, 4, + 5, 1, 2, 3, 4, 1, 2, 3, + 4, 1, 2, 3, 1, 2, 3, 1, + 2, 3, 1, 2, 1, 2, 1, 2, + 1, 2, 1, 2, 1, 2, 1, 2, + 1, 2, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, +}; + +static const int8_t table4_run[168] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 2, 2, 2, 2, 2, 2, + 2, 2, 3, 3, 3, 3, 3, 3, + 3, 4, 4, 4, 4, 4, 5, 5, + 5, 5, 5, 6, 6, 6, 6, 7, + 7, 7, 7, 8, 8, 8, 9, 9, + 9, 10, 10, 10, 11, 11, 11, 12, + 12, 13, 13, 14, 14, 15, 15, 16, + 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 1, + 1, 2, 2, 2, 2, 3, 3, 3, + 3, 4, 4, 4, 5, 5, 5, 6, + 6, 6, 7, 7, 8, 8, 9, 9, + 10, 10, 11, 11, 12, 12, 13, 13, + 14, 14, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, +}; + +extern const uint16_t inter_vlc[103][2]; +extern const int8_t inter_level[102]; +extern const int8_t inter_run[102]; + +extern const uint16_t intra_vlc[103][2]; +extern const int8_t intra_level[102]; +extern const int8_t intra_run[102]; + +RLTable rl_table[NB_RL_TABLES] = { + /* intra luminance tables */ + /* low motion */ + { + 132, + 85, + table0_vlc, + table0_run, + table0_level, + }, + /* high motion */ + { + 185, + 119, + table2_vlc, + table2_run, + table2_level, + }, + /* mid-rate */ + { + 102, + 67, + intra_vlc, + intra_run, + intra_level, + }, + /* intra chrominance / non intra tables */ + /* low motion inter */ + { + 148, + 81, + table1_vlc, + table1_run, + table1_level, + }, + /* high motion inter */ + { + 168, + 99, + table4_vlc, + table4_run, + table4_level, + }, + /* mid rate inter */ + { + 102, + 58, + inter_vlc, + inter_run, + inter_level, + }, +}; + +/* motion vector table 0 */ + +static const uint16_t table0_mv_code[1100] = { + 0x0001, 0x0003, 0x0005, 0x0007, 0x0003, 0x0008, 0x000c, 0x0001, + 0x0002, 0x001b, 0x0006, 0x000b, 0x0015, 0x0002, 0x000e, 0x000f, + 0x0014, 0x0020, 0x0022, 0x0025, 0x0027, 0x0029, 0x002d, 0x004b, + 0x004d, 0x0003, 0x0022, 0x0023, 0x0025, 0x0027, 0x0042, 0x0048, + 0x0049, 0x0050, 0x005c, 0x0091, 0x009f, 0x000e, 0x0043, 0x004c, + 0x0054, 0x0056, 0x008c, 0x0098, 0x009a, 0x009b, 0x00b1, 0x00b2, + 0x0120, 0x0121, 0x0126, 0x0133, 0x0139, 0x01a1, 0x01a4, 0x01a5, + 0x01a6, 0x01a7, 0x01ae, 0x01af, 0x000b, 0x0019, 0x0085, 0x0090, + 0x009b, 0x00aa, 0x00af, 0x010c, 0x010e, 0x011c, 0x011e, 0x0133, + 0x0144, 0x0160, 0x0174, 0x0175, 0x0177, 0x0178, 0x0249, 0x024b, + 0x0252, 0x0261, 0x0265, 0x0270, 0x0352, 0x0353, 0x0355, 0x0359, + 0x0010, 0x0011, 0x0013, 0x0034, 0x0035, 0x0036, 0x0037, 0x003d, + 0x003e, 0x0109, 0x0126, 0x0156, 0x021a, 0x021e, 0x023a, 0x023e, + 0x028e, 0x028f, 0x02cf, 0x0491, 0x0494, 0x049f, 0x04a0, 0x04a3, + 0x04a6, 0x04a7, 0x04ad, 0x04ae, 0x04c0, 0x04c4, 0x04c6, 0x04c8, + 0x04c9, 0x04f5, 0x04f6, 0x04f7, 0x0680, 0x0682, 0x0683, 0x0688, + 0x0689, 0x068d, 0x068e, 0x068f, 0x06a2, 0x06a3, 0x06a9, 0x06b0, + 0x06b1, 0x06b4, 0x06b5, 0x0024, 0x0060, 0x0063, 0x0078, 0x0079, + 0x0211, 0x0244, 0x0245, 0x0247, 0x0248, 0x0249, 0x024a, 0x024b, + 0x026b, 0x02af, 0x02b8, 0x02bb, 0x0436, 0x0476, 0x0477, 0x047e, + 0x04c8, 0x04c9, 0x04ca, 0x0514, 0x0586, 0x0587, 0x0598, 0x059d, + 0x05d9, 0x05da, 0x0920, 0x0921, 0x093b, 0x093c, 0x093d, 0x0942, + 0x0943, 0x0944, 0x0945, 0x0959, 0x095e, 0x095f, 0x0982, 0x0983, + 0x098e, 0x098f, 0x09c4, 0x09e7, 0x09e8, 0x09e9, 0x0d02, 0x0d17, + 0x0d18, 0x0d19, 0x0d41, 0x0d42, 0x0d43, 0x0d50, 0x0d5f, 0x0d6d, + 0x0d6e, 0x0d6f, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, + 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x041e, 0x041f, 0x0420, 0x0421, + 0x048c, 0x048d, 0x04d3, 0x04d4, 0x04d5, 0x055c, 0x055d, 0x0572, + 0x0573, 0x0574, 0x0575, 0x08de, 0x08df, 0x08fe, 0x08ff, 0x0996, + 0x0a36, 0x0a37, 0x0b08, 0x0b09, 0x0b0a, 0x0b0b, 0x0b32, 0x0b33, + 0x0b34, 0x0b35, 0x0b36, 0x0b37, 0x0b38, 0x0b39, 0x0bb0, 0x0bf7, + 0x0bf8, 0x0bf9, 0x0bfa, 0x0bfb, 0x0bfc, 0x0bfd, 0x0bfe, 0x0bff, + 0x1254, 0x1255, 0x1256, 0x1257, 0x1270, 0x1271, 0x1272, 0x1273, + 0x1274, 0x1275, 0x12ab, 0x12ac, 0x12ad, 0x12ae, 0x12af, 0x12b0, + 0x12b1, 0x1315, 0x1316, 0x1317, 0x13bf, 0x13c0, 0x13c1, 0x13c2, + 0x13c3, 0x13c4, 0x13c5, 0x13c6, 0x13c7, 0x13c8, 0x13c9, 0x13ca, + 0x13cb, 0x13cc, 0x13cd, 0x1a06, 0x1a07, 0x1a28, 0x1a29, 0x1a2a, + 0x1a2b, 0x1a2c, 0x1a2d, 0x1a80, 0x1abb, 0x1abc, 0x1abd, 0x1ad8, + 0x1ad9, 0x0094, 0x0095, 0x0096, 0x0097, 0x00a0, 0x00a1, 0x00a2, + 0x00a3, 0x0831, 0x0832, 0x0833, 0x0834, 0x0835, 0x0836, 0x0837, + 0x0838, 0x0839, 0x083a, 0x083b, 0x0939, 0x093a, 0x093b, 0x093c, + 0x093d, 0x093e, 0x093f, 0x09a0, 0x09a1, 0x09a2, 0x09a3, 0x09a4, + 0x09a5, 0x11ac, 0x11ad, 0x11ae, 0x11af, 0x11b0, 0x11b1, 0x11b2, + 0x11b3, 0x11b4, 0x11b5, 0x11b6, 0x11b7, 0x11b8, 0x11b9, 0x11ba, + 0x11bb, 0x132f, 0x1454, 0x1455, 0x1456, 0x1457, 0x1458, 0x1459, + 0x145a, 0x145b, 0x145c, 0x145d, 0x145e, 0x145f, 0x1460, 0x1461, + 0x1462, 0x1463, 0x1464, 0x1465, 0x1466, 0x1467, 0x1468, 0x1469, + 0x146a, 0x146b, 0x17de, 0x17df, 0x17e0, 0x17e1, 0x17e2, 0x17e3, + 0x17e4, 0x17e5, 0x17e6, 0x17e7, 0x17e8, 0x17e9, 0x17ea, 0x17eb, + 0x17ec, 0x17ed, 0x2540, 0x2541, 0x2542, 0x2543, 0x2544, 0x2545, + 0x2546, 0x2547, 0x2548, 0x2549, 0x254a, 0x254b, 0x254c, 0x254d, + 0x254e, 0x254f, 0x2550, 0x2551, 0x2552, 0x2553, 0x2554, 0x2555, + 0x2628, 0x2766, 0x2767, 0x2768, 0x2769, 0x276a, 0x276b, 0x276c, + 0x276d, 0x276e, 0x276f, 0x2770, 0x2771, 0x2772, 0x2773, 0x2774, + 0x2775, 0x2776, 0x2777, 0x2778, 0x2779, 0x277a, 0x277b, 0x277c, + 0x277d, 0x3503, 0x3544, 0x3545, 0x3546, 0x3547, 0x3560, 0x3561, + 0x3562, 0x3563, 0x3564, 0x3565, 0x3566, 0x3567, 0x3568, 0x3569, + 0x356a, 0x356b, 0x356c, 0x356d, 0x356e, 0x356f, 0x3570, 0x3571, + 0x3572, 0x3573, 0x3574, 0x3575, 0x03f0, 0x103d, 0x103e, 0x103f, + 0x1040, 0x1041, 0x1042, 0x1043, 0x1044, 0x1045, 0x1046, 0x1047, + 0x1048, 0x1049, 0x104a, 0x104b, 0x104c, 0x104d, 0x104e, 0x104f, + 0x1050, 0x1051, 0x1052, 0x1053, 0x1054, 0x1055, 0x1056, 0x1057, + 0x1058, 0x1059, 0x105a, 0x105b, 0x105c, 0x105d, 0x105e, 0x105f, + 0x1060, 0x1061, 0x1270, 0x1271, 0x21b8, 0x21b9, 0x21ba, 0x21bb, + 0x21bc, 0x21bd, 0x21be, 0x21bf, 0x21f0, 0x21f1, 0x21f2, 0x21f3, + 0x21f4, 0x21f5, 0x21f6, 0x21f7, 0x21f8, 0x21f9, 0x21fa, 0x21fb, + 0x21fc, 0x21fd, 0x21fe, 0x21ff, 0x2340, 0x2341, 0x2342, 0x2343, + 0x2344, 0x2345, 0x2346, 0x2347, 0x2348, 0x2349, 0x234a, 0x234b, + 0x234c, 0x234d, 0x234e, 0x234f, 0x2350, 0x2351, 0x2352, 0x2353, + 0x2354, 0x2355, 0x2356, 0x2357, 0x265c, 0x2f88, 0x2f89, 0x2f8a, + 0x2f8b, 0x2f8c, 0x2f8d, 0x2f8e, 0x2f8f, 0x2f90, 0x2f91, 0x2f92, + 0x2f93, 0x2f94, 0x2f95, 0x2f96, 0x2f97, 0x2f98, 0x2f99, 0x2f9a, + 0x2f9b, 0x2f9c, 0x2f9d, 0x2f9e, 0x2f9f, 0x2fa0, 0x2fa1, 0x2fa2, + 0x2fa3, 0x2fa4, 0x2fa5, 0x2fa6, 0x2fa7, 0x2fa8, 0x2fa9, 0x2faa, + 0x2fab, 0x2fac, 0x2fad, 0x2fae, 0x2faf, 0x2fb0, 0x2fb1, 0x2fb2, + 0x2fb3, 0x2fb4, 0x2fb5, 0x2fb6, 0x2fb7, 0x2fb8, 0x2fb9, 0x2fba, + 0x2fbb, 0x4c52, 0x4c53, 0x4e28, 0x4e29, 0x4e2a, 0x4e2b, 0x4e2c, + 0x4e2d, 0x4e2e, 0x4e2f, 0x4e30, 0x4e31, 0x4e32, 0x4e33, 0x4e34, + 0x4e35, 0x4e36, 0x4e37, 0x4e38, 0x4e39, 0x4e3a, 0x4e3b, 0x4e3c, + 0x4e3d, 0x4e3e, 0x4e3f, 0x4e80, 0x4e81, 0x4e82, 0x4e83, 0x4e84, + 0x4e85, 0x4e86, 0x4e87, 0x4e88, 0x4e89, 0x4e8a, 0x4e8b, 0x4e8c, + 0x4e8d, 0x4e8e, 0x4e8f, 0x4e90, 0x4e91, 0x4e92, 0x4e93, 0x4e94, + 0x4e95, 0x4e96, 0x4e97, 0x4e98, 0x4e99, 0x4e9a, 0x4e9b, 0x4e9c, + 0x4e9d, 0x4e9e, 0x4e9f, 0x4ea0, 0x4ea1, 0x4ea2, 0x4ea3, 0x4ea4, + 0x4ea5, 0x4ea6, 0x4ea7, 0x4ea8, 0x4ea9, 0x4eaa, 0x4eab, 0x4eac, + 0x4ead, 0x4eae, 0x4eaf, 0x4eb0, 0x4eb1, 0x4eb2, 0x4eb3, 0x4eb4, + 0x4eb5, 0x4eb6, 0x4eb7, 0x4eb8, 0x4eb9, 0x4eba, 0x4ebb, 0x4ebc, + 0x4ebd, 0x4ebe, 0x4ebf, 0x4ec0, 0x4ec1, 0x4ec2, 0x4ec3, 0x4ec4, + 0x4ec5, 0x4ec6, 0x4ec7, 0x4ec8, 0x4ec9, 0x4eca, 0x4ecb, 0x6a04, + 0x6a05, 0x07e2, 0x07e3, 0x07e4, 0x07e5, 0x07e6, 0x07e7, 0x07e8, + 0x07e9, 0x07ea, 0x07eb, 0x07ec, 0x07ed, 0x07ee, 0x07ef, 0x07f0, + 0x07f1, 0x07f2, 0x07f3, 0x07f4, 0x07f5, 0x07f6, 0x07f7, 0x07f8, + 0x07f9, 0x07fa, 0x07fb, 0x07fc, 0x07fd, 0x07fe, 0x07ff, 0x2000, + 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, + 0x2009, 0x200a, 0x200b, 0x200c, 0x200d, 0x200e, 0x200f, 0x2010, + 0x2011, 0x2012, 0x2013, 0x2014, 0x2015, 0x2016, 0x2017, 0x2018, + 0x2019, 0x201a, 0x201b, 0x201c, 0x201d, 0x201e, 0x201f, 0x2020, + 0x2021, 0x2022, 0x2023, 0x2024, 0x2025, 0x2026, 0x2027, 0x2028, + 0x2029, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e, 0x202f, 0x2030, + 0x2031, 0x2032, 0x2033, 0x2034, 0x2035, 0x2036, 0x2037, 0x2038, + 0x2039, 0x203a, 0x203b, 0x203c, 0x203d, 0x203e, 0x203f, 0x2040, + 0x2041, 0x2042, 0x2043, 0x2044, 0x2045, 0x2046, 0x2047, 0x2048, + 0x2049, 0x204a, 0x204b, 0x204c, 0x204d, 0x204e, 0x204f, 0x2050, + 0x2051, 0x2052, 0x2053, 0x2054, 0x2055, 0x2056, 0x2057, 0x2058, + 0x2059, 0x205a, 0x205b, 0x205c, 0x205d, 0x205e, 0x205f, 0x2060, + 0x2061, 0x2062, 0x2063, 0x2064, 0x2065, 0x2066, 0x2067, 0x2068, + 0x2069, 0x206a, 0x206b, 0x206c, 0x206d, 0x206e, 0x206f, 0x2070, + 0x2071, 0x2072, 0x2073, 0x2074, 0x2075, 0x2076, 0x2077, 0x2078, + 0x2079, 0x4cba, 0x4cbb, 0x5d88, 0x5d89, 0x5d8a, 0x5d8b, 0x5d8c, + 0x5d8d, 0x5d8e, 0x5d8f, 0x5db0, 0x5db1, 0x5db2, 0x5db3, 0x5db4, + 0x5db5, 0x5db6, 0x5db7, 0x5db8, 0x5db9, 0x5dba, 0x5dbb, 0x5dbc, + 0x5dbd, 0x5dbe, 0x5dbf, 0x5e40, 0x5e41, 0x5e42, 0x5e43, 0x5e44, + 0x5e45, 0x5e46, 0x5e47, 0x5e48, 0x5e49, 0x5e4a, 0x5e4b, 0x5e4c, + 0x5e4d, 0x5e4e, 0x5e4f, 0x5e50, 0x5e51, 0x5e52, 0x5e53, 0x5e54, + 0x5e55, 0x5e56, 0x5e57, 0x5e58, 0x5e59, 0x5e5a, 0x5e5b, 0x5e5c, + 0x5e5d, 0x5e5e, 0x5e5f, 0x5e60, 0x5e61, 0x5e62, 0x5e63, 0x5e64, + 0x5e65, 0x5e66, 0x5e67, 0x5e68, 0x5e69, 0x5e6a, 0x5e6b, 0x5e6c, + 0x5e6d, 0x5e6e, 0x5e6f, 0x5e70, 0x5e71, 0x5e72, 0x5e73, 0x5e74, + 0x5e75, 0x5e76, 0x5e77, 0x5e78, 0x5e79, 0x5e7a, 0x5e7b, 0x5e7c, + 0x5e7d, 0x5e7e, 0x5e7f, 0x5e80, 0x5e81, 0x5e82, 0x5e83, 0x5e84, + 0x5e85, 0x5e86, 0x5e87, 0x5e88, 0x5e89, 0x5e8a, 0x5e8b, 0x5e8c, + 0x5e8d, 0x5e8e, 0x5e8f, 0x5e90, 0x5e91, 0x5e92, 0x5e93, 0x5e94, + 0x5e95, 0x5e96, 0x5e97, 0x5e98, 0x5e99, 0x5e9a, 0x5e9b, 0x5e9c, + 0x5e9d, 0x5e9e, 0x5e9f, 0x5ea0, 0x5ea1, 0x5ea2, 0x5ea3, 0x5ea4, + 0x5ea5, 0x5ea6, 0x5ea7, 0x5ea8, 0x5ea9, 0x5eaa, 0x5eab, 0x5eac, + 0x5ead, 0x5eae, 0x5eaf, 0x5eb0, 0x5eb1, 0x5eb2, 0x5eb3, 0x5eb4, + 0x5eb5, 0x5eb6, 0x5eb7, 0x5eb8, 0x5eb9, 0x5eba, 0x5ebb, 0x5ebc, + 0x5ebd, 0x5ebe, 0x5ebf, 0x5ec0, 0x5ec1, 0x5ec2, 0x5ec3, 0x5ec4, + 0x5ec5, 0x5ec6, 0x5ec7, 0x5ec8, 0x5ec9, 0x5eca, 0x5ecb, 0x5ecc, + 0x5ecd, 0x5ece, 0x5ecf, 0x5ed0, 0x5ed1, 0x5ed2, 0x5ed3, 0x5ed4, + 0x5ed5, 0x5ed6, 0x5ed7, 0x5ed8, 0x5ed9, 0x5eda, 0x5edb, 0x5edc, + 0x5edd, 0x5ede, 0x5edf, 0x5ee0, 0x5ee1, 0x5ee2, 0x5ee3, 0x5ee4, + 0x5ee5, 0x5ee6, 0x5ee7, 0x5ee8, 0x5ee9, 0x5eea, 0x5eeb, 0x5eec, + 0x5eed, 0x5eee, 0x5eef, 0x5ef0, 0x5ef1, 0x5ef2, 0x5ef3, 0x5ef4, + 0x5ef5, 0x5ef6, 0x5ef7, 0x5ef8, 0x5ef9, 0x5efa, 0x5efb, 0x5efc, + 0x5efd, 0x5efe, 0x5eff, 0x5f00, 0x5f01, 0x5f02, 0x5f03, 0x5f04, + 0x5f05, 0x5f06, 0x5f07, 0x5f08, 0x5f09, 0x5f0a, 0x5f0b, 0x5f0c, + 0x5f0d, 0x5f0e, 0x5f0f, 0x0000, +}; + +static const uint8_t table0_mv_bits[1100] = { + 1, 4, 4, 4, 5, 5, 5, 6, + 6, 6, 7, 7, 7, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 10, 10, 10, + 10, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 10, 10, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, + 16, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, + 17, 17, 17, 8, +}; + +static const uint8_t table0_mvx[1099] = { + 32, 32, 31, 32, 33, 31, 33, 31, + 33, 32, 34, 32, 30, 32, 31, 34, + 35, 32, 34, 33, 29, 33, 30, 30, + 31, 31, 35, 29, 33, 35, 33, 34, + 31, 29, 30, 34, 30, 36, 28, 32, + 34, 37, 30, 27, 32, 25, 39, 32, + 34, 32, 35, 35, 35, 31, 35, 29, + 32, 29, 30, 29, 37, 27, 36, 38, + 37, 33, 32, 31, 29, 31, 28, 36, + 33, 30, 34, 33, 33, 28, 27, 25, + 31, 26, 39, 32, 32, 31, 33, 39, + 31, 38, 28, 36, 21, 23, 43, 36, + 34, 41, 30, 25, 28, 31, 30, 34, + 38, 35, 61, 34, 28, 30, 37, 37, + 35, 27, 36, 3, 59, 38, 37, 32, + 31, 29, 26, 33, 37, 33, 27, 27, + 35, 34, 34, 40, 42, 33, 32, 29, + 4, 5, 28, 24, 25, 35, 39, 38, + 32, 23, 27, 32, 30, 35, 26, 34, + 60, 36, 29, 22, 26, 41, 7, 30, + 38, 30, 36, 29, 30, 41, 26, 25, + 32, 34, 24, 39, 1, 25, 39, 32, + 28, 29, 32, 38, 26, 36, 28, 63, + 28, 39, 23, 21, 26, 35, 31, 35, + 57, 31, 29, 29, 28, 30, 27, 35, + 2, 38, 40, 34, 37, 29, 38, 43, + 26, 32, 33, 42, 24, 40, 28, 32, + 32, 32, 36, 32, 43, 25, 21, 31, + 30, 31, 41, 29, 33, 37, 26, 37, + 27, 59, 23, 33, 35, 31, 31, 37, + 38, 39, 32, 23, 32, 27, 37, 36, + 31, 40, 25, 27, 38, 31, 36, 28, + 31, 36, 25, 45, 3, 34, 38, 39, + 40, 38, 30, 32, 19, 24, 25, 26, + 45, 20, 24, 33, 33, 31, 41, 34, + 39, 47, 40, 58, 59, 41, 33, 3, + 17, 61, 42, 30, 26, 29, 36, 61, + 33, 37, 62, 28, 25, 38, 25, 38, + 17, 23, 34, 33, 21, 33, 49, 27, + 32, 23, 27, 22, 24, 22, 39, 43, + 27, 37, 6, 42, 47, 26, 30, 31, + 41, 39, 33, 22, 45, 36, 32, 45, + 19, 22, 30, 5, 5, 17, 29, 22, + 31, 31, 43, 37, 27, 32, 32, 32, + 33, 34, 43, 35, 29, 26, 22, 32, + 19, 32, 25, 31, 41, 49, 28, 34, + 28, 39, 34, 19, 37, 38, 29, 21, + 36, 42, 24, 48, 16, 28, 49, 22, + 34, 31, 38, 39, 44, 11, 35, 30, + 33, 33, 23, 28, 33, 46, 15, 13, + 24, 41, 24, 34, 34, 30, 26, 24, + 14, 60, 21, 29, 39, 23, 35, 37, + 63, 45, 33, 34, 47, 41, 22, 42, + 35, 35, 23, 32, 35, 43, 32, 7, + 31, 41, 20, 31, 16, 13, 63, 25, + 30, 32, 35, 30, 30, 31, 42, 47, + 39, 38, 40, 40, 51, 55, 56, 18, + 21, 39, 39, 33, 17, 41, 23, 24, + 43, 25, 31, 20, 19, 45, 1, 34, + 31, 22, 35, 15, 46, 46, 35, 31, + 28, 29, 29, 23, 41, 27, 14, 53, + 53, 27, 24, 32, 57, 32, 17, 42, + 37, 29, 33, 1, 25, 32, 32, 63, + 26, 40, 44, 36, 31, 39, 20, 20, + 44, 23, 33, 34, 35, 33, 33, 28, + 41, 23, 41, 41, 29, 25, 26, 49, + 29, 24, 37, 49, 50, 51, 51, 26, + 39, 25, 26, 15, 39, 18, 42, 17, + 4, 31, 32, 32, 60, 1, 42, 32, + 0, 12, 19, 35, 21, 41, 17, 26, + 20, 45, 46, 32, 37, 22, 47, 29, + 31, 27, 29, 30, 21, 33, 35, 18, + 25, 33, 50, 51, 42, 2, 15, 51, + 53, 33, 25, 29, 55, 37, 38, 33, + 38, 59, 38, 33, 39, 13, 32, 40, + 61, 61, 32, 9, 44, 3, 31, 29, + 25, 31, 27, 23, 9, 25, 9, 29, + 20, 30, 30, 42, 18, 28, 25, 28, + 28, 21, 29, 43, 29, 43, 26, 44, + 44, 21, 38, 21, 24, 45, 45, 35, + 39, 22, 35, 36, 34, 34, 45, 34, + 29, 31, 46, 25, 46, 16, 17, 31, + 20, 32, 47, 47, 47, 32, 49, 49, + 49, 31, 1, 27, 28, 39, 39, 21, + 36, 23, 51, 2, 40, 51, 32, 53, + 24, 30, 24, 30, 21, 40, 57, 57, + 31, 41, 58, 32, 12, 4, 32, 34, + 59, 31, 32, 13, 9, 35, 26, 35, + 37, 61, 37, 63, 26, 29, 41, 38, + 23, 20, 41, 26, 41, 42, 42, 42, + 26, 26, 26, 26, 1, 26, 37, 37, + 37, 23, 34, 42, 27, 43, 34, 27, + 31, 24, 33, 16, 3, 31, 24, 33, + 24, 4, 44, 44, 11, 44, 31, 13, + 13, 44, 45, 13, 25, 22, 38, 26, + 38, 38, 39, 32, 30, 39, 30, 22, + 32, 26, 30, 47, 47, 47, 19, 47, + 30, 31, 35, 8, 23, 47, 47, 27, + 35, 47, 31, 48, 35, 19, 36, 49, + 49, 33, 31, 39, 27, 39, 49, 49, + 50, 50, 50, 39, 31, 51, 51, 39, + 28, 33, 33, 21, 40, 31, 52, 53, + 40, 53, 9, 33, 31, 53, 54, 54, + 54, 55, 55, 34, 15, 56, 25, 56, + 21, 21, 40, 40, 25, 40, 58, 36, + 5, 41, 41, 12, 60, 41, 41, 37, + 22, 61, 18, 29, 29, 30, 61, 30, + 61, 62, 62, 30, 30, 63, 18, 13, + 30, 23, 19, 20, 20, 41, 13, 2, + 5, 5, 1, 5, 32, 6, 32, 35, + 20, 35, 27, 35, 35, 36, 36, 13, + 36, 41, 41, 41, 3, 30, 42, 27, + 20, 30, 27, 28, 30, 21, 33, 33, + 14, 24, 30, 42, 24, 33, 25, 42, + 43, 14, 43, 43, 14, 43, 7, 36, + 37, 37, 37, 37, 7, 14, 25, 43, + 43, 44, 15, 37, 7, 7, 3, 1, + 8, 15, 15, 8, 44, 44, 44, 45, + 45, 45, 45, 8, 8, 45, 21, 45, + 28, 28, 28, 21, 28, 28, 22, 37, + 46, 46, 37, 8, 29, 37, 29, 22, + 46, 37, 22, 29, 47, 47, 38, 38, + 16, 38, 38, 33, 38, 22, 47, 47, + 29, 25, 16, 0, 48, 1, 34, 48, + 48, 34, 25, 26, 26, 49, 49, 26, + 1, 49, 4, 26, 4, 49, 1, 9, + 49, 49, 49, 10, 49, 17, 38, 17, + 17, 50, 38, 50, 50, 22, 38, 51, + 38, 38, 51, 39, 39, 18, 22, 39, + 51, 22, 52, 52, 52, 39, 53, 53, + 10, 23, 18, 29, 10, 53, 29, 54, + 11, 54, 11, 11, 55, 1, 18, 55, + 55, 55, 55, 55, 55, 29, 34, 18, + 29, 56, 56, 34, 57, 34, 34, 29, + 29, 57, 57, 35, 35, 35, 35, 35, + 39, 35, 59, 59, 18, 59, 39, 30, + 18, 40, 60, 60, 61, 30, 18, 61, + 61, 19, 19, +}; + +static const uint8_t table0_mvy[1099] = { + 32, 31, 32, 33, 32, 31, 31, 33, + 33, 34, 32, 30, 32, 35, 34, 31, + 32, 29, 33, 30, 32, 34, 33, 31, + 30, 35, 31, 31, 29, 33, 35, 30, + 29, 33, 34, 34, 30, 32, 32, 36, + 29, 32, 35, 32, 28, 32, 32, 27, + 35, 37, 34, 29, 30, 36, 35, 34, + 25, 30, 29, 35, 33, 31, 31, 32, + 31, 28, 39, 28, 29, 37, 31, 33, + 27, 36, 28, 36, 37, 33, 33, 31, + 27, 32, 31, 38, 26, 25, 25, 33, + 39, 31, 34, 30, 32, 32, 32, 34, + 36, 32, 28, 33, 30, 38, 37, 27, + 33, 28, 32, 37, 35, 38, 29, 34, + 27, 29, 29, 32, 32, 34, 35, 3, + 26, 36, 31, 38, 30, 26, 35, 34, + 37, 26, 25, 32, 32, 39, 23, 37, + 32, 32, 29, 32, 29, 36, 29, 30, + 41, 31, 30, 21, 39, 25, 34, 38, + 32, 35, 39, 32, 33, 33, 32, 27, + 29, 25, 28, 27, 26, 31, 30, 35, + 24, 24, 31, 34, 32, 30, 35, 40, + 28, 38, 5, 35, 29, 36, 36, 32, + 38, 30, 33, 31, 35, 26, 23, 38, + 32, 41, 28, 25, 37, 40, 37, 39, + 32, 36, 33, 39, 25, 26, 28, 31, + 28, 42, 23, 31, 33, 31, 39, 1, + 59, 22, 27, 4, 33, 34, 33, 24, + 41, 3, 35, 41, 41, 28, 36, 36, + 28, 33, 35, 21, 23, 21, 22, 37, + 27, 27, 43, 29, 60, 39, 27, 25, + 59, 34, 27, 27, 26, 40, 37, 27, + 61, 26, 39, 33, 31, 22, 37, 25, + 30, 25, 24, 61, 31, 34, 25, 38, + 32, 32, 30, 3, 61, 43, 29, 23, + 28, 32, 28, 32, 31, 34, 5, 33, + 32, 33, 33, 42, 37, 23, 38, 31, + 40, 26, 32, 26, 37, 38, 36, 24, + 29, 30, 20, 22, 29, 24, 32, 41, + 2, 34, 25, 33, 29, 31, 39, 35, + 36, 24, 32, 30, 33, 27, 44, 60, + 30, 36, 19, 34, 31, 24, 16, 35, + 32, 38, 21, 33, 31, 31, 21, 35, + 5, 17, 29, 38, 38, 18, 58, 19, + 43, 41, 30, 41, 43, 39, 29, 7, + 29, 17, 28, 19, 28, 31, 25, 19, + 40, 26, 21, 33, 39, 23, 40, 30, + 39, 34, 35, 32, 32, 24, 33, 30, + 40, 47, 39, 37, 32, 33, 24, 23, + 45, 47, 27, 23, 42, 32, 32, 33, + 36, 37, 37, 17, 18, 22, 40, 38, + 32, 31, 35, 24, 17, 25, 17, 23, + 33, 34, 51, 42, 31, 36, 36, 29, + 21, 22, 37, 44, 43, 25, 47, 33, + 45, 27, 31, 58, 31, 32, 31, 38, + 43, 20, 47, 45, 54, 1, 26, 34, + 38, 14, 22, 24, 33, 34, 32, 32, + 37, 21, 23, 49, 35, 23, 28, 39, + 39, 23, 55, 33, 30, 30, 63, 16, + 42, 28, 13, 33, 33, 35, 19, 46, + 43, 17, 19, 36, 39, 24, 31, 32, + 33, 26, 28, 62, 33, 63, 33, 39, + 19, 49, 17, 31, 43, 13, 15, 29, + 25, 35, 33, 23, 49, 41, 28, 29, + 34, 38, 7, 61, 11, 50, 13, 41, + 19, 47, 25, 26, 15, 42, 41, 29, + 45, 27, 17, 35, 32, 29, 32, 24, + 13, 26, 26, 31, 24, 33, 28, 30, + 31, 11, 45, 46, 33, 33, 35, 57, + 32, 32, 35, 45, 34, 11, 37, 42, + 39, 37, 31, 49, 21, 27, 29, 47, + 53, 40, 51, 16, 26, 1, 40, 30, + 41, 44, 34, 25, 27, 31, 35, 35, + 31, 15, 49, 1, 35, 40, 5, 58, + 21, 29, 22, 59, 45, 31, 9, 26, + 9, 29, 11, 32, 30, 3, 13, 20, + 18, 20, 11, 3, 29, 40, 31, 53, + 30, 17, 20, 37, 31, 42, 47, 47, + 54, 38, 9, 34, 13, 37, 21, 25, + 27, 43, 42, 45, 40, 25, 27, 46, + 22, 25, 53, 20, 2, 14, 39, 15, + 22, 44, 34, 21, 38, 33, 27, 48, + 34, 52, 35, 47, 49, 54, 2, 13, + 23, 52, 29, 45, 22, 49, 54, 21, + 40, 42, 31, 30, 29, 34, 0, 25, + 23, 51, 24, 59, 28, 38, 29, 31, + 2, 13, 31, 8, 31, 33, 12, 45, + 41, 7, 14, 30, 25, 18, 43, 20, + 43, 35, 44, 1, 49, 42, 42, 18, + 41, 38, 41, 44, 53, 11, 20, 25, + 45, 46, 47, 48, 39, 52, 46, 49, + 63, 55, 44, 38, 13, 13, 57, 22, + 51, 16, 12, 28, 35, 57, 25, 20, + 26, 28, 28, 29, 32, 31, 62, 34, + 35, 35, 19, 49, 48, 39, 40, 18, + 43, 46, 11, 6, 48, 19, 49, 41, + 10, 23, 58, 17, 21, 23, 34, 30, + 60, 0, 44, 34, 26, 37, 46, 43, + 49, 59, 4, 34, 59, 37, 22, 25, + 28, 46, 6, 40, 59, 42, 36, 61, + 28, 30, 31, 43, 10, 22, 23, 47, + 20, 52, 55, 36, 25, 16, 1, 11, + 27, 29, 5, 63, 18, 41, 31, 34, + 38, 1, 5, 13, 28, 31, 17, 38, + 39, 41, 36, 37, 22, 39, 33, 43, + 43, 15, 17, 49, 30, 21, 22, 20, + 10, 17, 25, 54, 57, 3, 34, 8, + 36, 25, 31, 14, 15, 19, 29, 25, + 18, 39, 53, 22, 27, 20, 29, 33, + 41, 42, 35, 62, 50, 29, 53, 50, + 35, 55, 42, 61, 63, 4, 7, 42, + 21, 46, 47, 49, 27, 46, 17, 55, + 41, 50, 63, 4, 56, 18, 8, 10, + 18, 51, 63, 36, 55, 18, 5, 55, + 9, 29, 17, 21, 30, 27, 1, 59, + 7, 11, 12, 15, 5, 42, 24, 41, + 43, 7, 27, 22, 25, 31, 30, 37, + 22, 39, 53, 29, 36, 37, 48, 0, + 5, 13, 17, 31, 32, 26, 46, 28, + 44, 45, 46, 53, 49, 51, 3, 41, + 3, 22, 42, 33, 5, 45, 7, 22, + 40, 53, 24, 14, 25, 27, 10, 12, + 34, 16, 17, 53, 20, 26, 39, 45, + 18, 45, 35, 33, 31, 49, 4, 39, + 42, 11, 51, 5, 13, 26, 27, 17, + 52, 30, 0, 22, 12, 34, 62, 36, + 38, 41, 47, 30, 63, 38, 41, 43, + 59, 33, 45, 37, 38, 40, 47, 24, + 48, 49, 30, 1, 10, 22, 49, 15, + 39, 59, 31, 32, 33, 18, 13, 15, + 31, 21, 27, 44, 42, 39, 46, 17, + 26, 32, 30, 31, 0, 30, 34, 9, + 12, 13, 25, 31, 32, 55, 43, 35, + 61, 33, 35, 46, 25, 47, 48, 62, + 63, 38, 61, 1, 2, 5, 7, 9, + 46, 10, 34, 35, 36, 55, 51, 7, + 40, 23, 34, 37, 5, 13, 42, 18, + 25, 27, 28, +}; + +/* motion vector table 1 */ +static const uint16_t table1_mv_code[1100] = { + 0x0000, 0x0007, 0x0009, 0x000f, 0x000a, 0x0011, 0x001a, 0x001c, + 0x0011, 0x0031, 0x0025, 0x002d, 0x002f, 0x006f, 0x0075, 0x0041, + 0x004c, 0x004e, 0x005c, 0x0060, 0x0062, 0x0066, 0x0068, 0x0069, + 0x006b, 0x00a6, 0x00c1, 0x00cb, 0x00cc, 0x00ce, 0x00da, 0x00e8, + 0x00ee, 0x0087, 0x0090, 0x009e, 0x009f, 0x00ba, 0x00ca, 0x00d8, + 0x00db, 0x00df, 0x0104, 0x0109, 0x010c, 0x0143, 0x0145, 0x014a, + 0x0156, 0x015c, 0x01b3, 0x01d3, 0x01da, 0x0103, 0x0109, 0x010b, + 0x0122, 0x0127, 0x0134, 0x0161, 0x0164, 0x0176, 0x0184, 0x018d, + 0x018e, 0x018f, 0x0190, 0x0193, 0x0196, 0x019d, 0x019e, 0x019f, + 0x01a9, 0x01b2, 0x01b4, 0x01ba, 0x01bb, 0x01bc, 0x0201, 0x0202, + 0x0205, 0x0207, 0x020d, 0x0210, 0x0211, 0x0215, 0x021b, 0x021f, + 0x0281, 0x0285, 0x0290, 0x029c, 0x029d, 0x02a2, 0x02a7, 0x02a8, + 0x02aa, 0x02b0, 0x02b1, 0x02b4, 0x02bc, 0x02bf, 0x0320, 0x0326, + 0x0327, 0x0329, 0x032a, 0x0336, 0x0360, 0x0362, 0x0363, 0x0372, + 0x03b2, 0x03bc, 0x03bd, 0x0203, 0x0205, 0x021a, 0x0249, 0x024a, + 0x024c, 0x02c7, 0x02ca, 0x02ce, 0x02ef, 0x030d, 0x0322, 0x0325, + 0x0338, 0x0373, 0x037a, 0x0409, 0x0415, 0x0416, 0x0418, 0x0428, + 0x042d, 0x042f, 0x0434, 0x0508, 0x0509, 0x0510, 0x0511, 0x051c, + 0x051e, 0x0524, 0x0541, 0x0543, 0x0546, 0x0547, 0x054d, 0x0557, + 0x055f, 0x056a, 0x056c, 0x056d, 0x056f, 0x0576, 0x0577, 0x057a, + 0x057b, 0x057c, 0x057d, 0x0600, 0x0601, 0x0603, 0x0614, 0x0616, + 0x0617, 0x061c, 0x061f, 0x0642, 0x0648, 0x0649, 0x064a, 0x064b, + 0x0657, 0x0668, 0x0669, 0x066b, 0x066e, 0x067f, 0x06c2, 0x06c8, + 0x06cb, 0x06de, 0x06df, 0x06e2, 0x06e3, 0x06ef, 0x0748, 0x074b, + 0x076e, 0x076f, 0x077c, 0x0409, 0x0423, 0x0428, 0x0429, 0x042a, + 0x042b, 0x0432, 0x0433, 0x0496, 0x049a, 0x04d5, 0x04db, 0x0581, + 0x0582, 0x058b, 0x058c, 0x058d, 0x0598, 0x0599, 0x059a, 0x059e, + 0x05dd, 0x0619, 0x0632, 0x0633, 0x0648, 0x0672, 0x06a1, 0x06a2, + 0x06a3, 0x06af, 0x06e2, 0x06e3, 0x06e4, 0x0800, 0x0801, 0x0802, + 0x0803, 0x081a, 0x081b, 0x0829, 0x082f, 0x0832, 0x083e, 0x083f, + 0x0852, 0x0853, 0x0858, 0x086b, 0x0877, 0x0878, 0x0879, 0x087a, + 0x087b, 0x0a00, 0x0a01, 0x0a0d, 0x0a0e, 0x0a0f, 0x0a24, 0x0a37, + 0x0a3a, 0x0a3b, 0x0a3e, 0x0a46, 0x0a47, 0x0a4a, 0x0a4b, 0x0a5f, + 0x0a79, 0x0a7a, 0x0a7b, 0x0a80, 0x0a81, 0x0a84, 0x0a85, 0x0a99, + 0x0aa5, 0x0aa6, 0x0ab8, 0x0aba, 0x0abb, 0x0abc, 0x0abd, 0x0ac8, + 0x0ace, 0x0acf, 0x0ad7, 0x0adc, 0x0aeb, 0x0c04, 0x0c25, 0x0c26, + 0x0c27, 0x0c2a, 0x0c2b, 0x0c3a, 0x0c3b, 0x0c3c, 0x0c3d, 0x0ca0, + 0x0cad, 0x0cd4, 0x0cd5, 0x0cfc, 0x0cfd, 0x0d86, 0x0d92, 0x0d93, + 0x0d94, 0x0d95, 0x0db0, 0x0db8, 0x0db9, 0x0dba, 0x0dbb, 0x0dc0, + 0x0dc2, 0x0dc3, 0x0dda, 0x0ddb, 0x0ddc, 0x0ddd, 0x0e92, 0x0e93, + 0x0e94, 0x0e95, 0x0ec7, 0x0ecc, 0x0ece, 0x0ecf, 0x0ed8, 0x0ed9, + 0x0eda, 0x0edb, 0x0808, 0x0809, 0x080a, 0x0810, 0x0811, 0x0844, + 0x0845, 0x0861, 0x0862, 0x0863, 0x086c, 0x0922, 0x0923, 0x092e, + 0x092f, 0x0936, 0x0937, 0x09b1, 0x09b2, 0x09b3, 0x09b4, 0x09b5, + 0x09b8, 0x09b9, 0x09ba, 0x09bb, 0x09bc, 0x09bd, 0x09be, 0x09bf, + 0x0b00, 0x0b15, 0x0b2c, 0x0b2d, 0x0b2e, 0x0b2f, 0x0b36, 0x0bb9, + 0x0c28, 0x0c2a, 0x0c2b, 0x0c2c, 0x0c2d, 0x0c2e, 0x0c2f, 0x0c30, + 0x0c31, 0x0c38, 0x0c60, 0x0c61, 0x0c62, 0x0c63, 0x0c8d, 0x0c8e, + 0x0c8f, 0x0c92, 0x0cbe, 0x0cbf, 0x0ce6, 0x0ce7, 0x0d40, 0x0d41, + 0x0d57, 0x0d58, 0x0d59, 0x0d5a, 0x0d5b, 0x0d5c, 0x0d5d, 0x0d98, + 0x0d99, 0x0d9a, 0x0d9b, 0x0d9c, 0x0d9d, 0x0dad, 0x0dae, 0x0daf, + 0x0dc0, 0x0dc1, 0x0dc2, 0x0dc3, 0x0dca, 0x0dcb, 0x0dec, 0x0ded, + 0x0dee, 0x0def, 0x1018, 0x1022, 0x1023, 0x1030, 0x1031, 0x1032, + 0x1033, 0x1050, 0x1051, 0x105c, 0x1074, 0x1075, 0x1076, 0x1077, + 0x1078, 0x1079, 0x107a, 0x107b, 0x10b2, 0x10b3, 0x10b8, 0x10b9, + 0x10ba, 0x10bb, 0x10d4, 0x10ea, 0x10eb, 0x10ec, 0x10ed, 0x1404, + 0x1405, 0x1406, 0x1407, 0x1410, 0x1411, 0x1412, 0x1413, 0x1414, + 0x1415, 0x1416, 0x1417, 0x1418, 0x1419, 0x1466, 0x1467, 0x1468, + 0x1469, 0x146a, 0x146b, 0x146c, 0x146d, 0x147e, 0x147f, 0x1488, + 0x1489, 0x148a, 0x148b, 0x14b6, 0x14b7, 0x14b8, 0x14b9, 0x14ba, + 0x14bb, 0x14bc, 0x14bd, 0x14f0, 0x14f1, 0x14f8, 0x14f9, 0x14fa, + 0x14fb, 0x14fc, 0x14fd, 0x14fe, 0x14ff, 0x152a, 0x152b, 0x152c, + 0x152d, 0x152e, 0x152f, 0x1530, 0x1531, 0x1548, 0x1549, 0x154e, + 0x154f, 0x1558, 0x1559, 0x155a, 0x155b, 0x1572, 0x159a, 0x159b, + 0x15ac, 0x15ba, 0x15bb, 0x15d0, 0x15d1, 0x15d2, 0x15d3, 0x15d4, + 0x15d5, 0x181d, 0x181e, 0x181f, 0x1840, 0x1841, 0x1842, 0x1843, + 0x1844, 0x1845, 0x1846, 0x1847, 0x1848, 0x1849, 0x1861, 0x1862, + 0x1863, 0x1864, 0x1865, 0x1866, 0x1867, 0x1868, 0x1869, 0x186a, + 0x186b, 0x186c, 0x186d, 0x186e, 0x191b, 0x191c, 0x191d, 0x191e, + 0x191f, 0x1942, 0x1943, 0x1944, 0x1945, 0x1946, 0x1947, 0x1958, + 0x1959, 0x19ed, 0x19ee, 0x19ef, 0x19f0, 0x19f1, 0x19f2, 0x19f3, + 0x19f4, 0x19f5, 0x19f6, 0x19f7, 0x1b0e, 0x1b0f, 0x1b62, 0x1b63, + 0x1b64, 0x1b65, 0x1b66, 0x1b67, 0x1b68, 0x1b69, 0x1b6a, 0x1b6b, + 0x1b6c, 0x1b6d, 0x1b6e, 0x1b6f, 0x1b82, 0x1ba8, 0x1ba9, 0x1baa, + 0x1bab, 0x1bac, 0x1bad, 0x1bae, 0x1baf, 0x1bb0, 0x1bb1, 0x1bb2, + 0x1bb3, 0x1d80, 0x1d81, 0x1d82, 0x1d83, 0x1d84, 0x1d85, 0x1d86, + 0x1d87, 0x1d88, 0x1d89, 0x1d8a, 0x1d8b, 0x1d8c, 0x1d8d, 0x1007, + 0x1008, 0x1009, 0x100a, 0x100b, 0x100c, 0x100d, 0x100e, 0x100f, + 0x1016, 0x1080, 0x1081, 0x1082, 0x1083, 0x1084, 0x1085, 0x1086, + 0x1087, 0x10c0, 0x123a, 0x123b, 0x123c, 0x123d, 0x123e, 0x123f, + 0x1240, 0x1241, 0x1242, 0x1243, 0x1350, 0x1352, 0x1353, 0x1358, + 0x1359, 0x135a, 0x135b, 0x135c, 0x135d, 0x135e, 0x135f, 0x1360, + 0x1361, 0x1602, 0x1603, 0x160c, 0x160d, 0x160e, 0x160f, 0x1620, + 0x1621, 0x1622, 0x1623, 0x1624, 0x1625, 0x1626, 0x1627, 0x1628, + 0x1629, 0x166e, 0x166f, 0x167c, 0x167d, 0x167e, 0x167f, 0x1770, + 0x1771, 0x1852, 0x1853, 0x1872, 0x1873, 0x1874, 0x1875, 0x1876, + 0x1877, 0x1878, 0x1879, 0x187a, 0x187b, 0x187c, 0x187d, 0x187e, + 0x187f, 0x1918, 0x1919, 0x1926, 0x1927, 0x1970, 0x1971, 0x1972, + 0x1973, 0x1974, 0x1975, 0x1976, 0x1977, 0x1978, 0x1979, 0x197a, + 0x197b, 0x1aa0, 0x1aa1, 0x1aa2, 0x1aa3, 0x1aa4, 0x1aa5, 0x1aa6, + 0x1aa7, 0x1aa8, 0x1aa9, 0x1aaa, 0x1aab, 0x1aac, 0x1aad, 0x1b3c, + 0x1b3d, 0x1b3e, 0x1b3f, 0x1b50, 0x1b51, 0x1b52, 0x1b53, 0x1b54, + 0x1b55, 0x1b56, 0x1b57, 0x1b58, 0x1b59, 0x2032, 0x2033, 0x2034, + 0x2035, 0x2036, 0x2037, 0x2038, 0x2039, 0x203a, 0x203b, 0x203c, + 0x203d, 0x203e, 0x203f, 0x2040, 0x2041, 0x2042, 0x2043, 0x20ba, + 0x20bb, 0x20cc, 0x20cd, 0x20ce, 0x20cf, 0x20e0, 0x20e1, 0x20e2, + 0x20e3, 0x20e4, 0x20e5, 0x20e6, 0x20e7, 0x21aa, 0x21ab, 0x21c0, + 0x21c1, 0x21c2, 0x21c3, 0x21c4, 0x21c5, 0x21c6, 0x21c7, 0x21c8, + 0x21c9, 0x21ca, 0x21cb, 0x21cc, 0x21cd, 0x21ce, 0x21cf, 0x21d0, + 0x21d1, 0x21d2, 0x21d3, 0x2894, 0x2895, 0x2896, 0x2897, 0x2898, + 0x2899, 0x289a, 0x289b, 0x289c, 0x289d, 0x289e, 0x289f, 0x28c0, + 0x28c1, 0x28c2, 0x28c3, 0x28c4, 0x28c5, 0x28c6, 0x28c7, 0x28c8, + 0x28c9, 0x28ca, 0x28cb, 0x2930, 0x2931, 0x2932, 0x2933, 0x2934, + 0x2935, 0x2936, 0x2937, 0x2938, 0x2939, 0x293a, 0x293b, 0x293c, + 0x293d, 0x293e, 0x293f, 0x2960, 0x2961, 0x2962, 0x2963, 0x2964, + 0x2965, 0x2966, 0x2967, 0x2968, 0x2969, 0x296a, 0x296b, 0x2a40, + 0x2a41, 0x2a42, 0x2a43, 0x2a44, 0x2a45, 0x2a46, 0x2a47, 0x2a48, + 0x2a49, 0x2a4a, 0x2a4b, 0x2a4c, 0x2a4d, 0x2a4e, 0x2a4f, 0x2a50, + 0x2a51, 0x2a52, 0x2a53, 0x2ae6, 0x2ae7, 0x2b24, 0x2b25, 0x2b26, + 0x2b27, 0x2b28, 0x2b29, 0x2b2a, 0x2b2b, 0x2b2c, 0x2b2d, 0x2b2e, + 0x2b2f, 0x2b30, 0x2b31, 0x2b32, 0x2b33, 0x2b5a, 0x2b5b, 0x3014, + 0x3015, 0x3016, 0x3017, 0x3020, 0x3021, 0x3022, 0x3023, 0x3024, + 0x3025, 0x3026, 0x3027, 0x3028, 0x3029, 0x302a, 0x302b, 0x302c, + 0x302d, 0x302e, 0x302f, 0x3030, 0x3031, 0x3032, 0x3033, 0x3034, + 0x3035, 0x3036, 0x3037, 0x3038, 0x3039, 0x30c0, 0x30c1, 0x30de, + 0x30df, 0x3218, 0x3219, 0x321a, 0x321b, 0x321c, 0x321d, 0x321e, + 0x321f, 0x3220, 0x3221, 0x3222, 0x3223, 0x3224, 0x3225, 0x3226, + 0x3227, 0x3228, 0x3229, 0x322a, 0x322b, 0x322c, 0x322d, 0x322e, + 0x322f, 0x3230, 0x3231, 0x3232, 0x3233, 0x3234, 0x3235, 0x3378, + 0x3379, 0x337a, 0x337b, 0x337c, 0x337d, 0x337e, 0x337f, 0x33c0, + 0x33c1, 0x33c2, 0x33c3, 0x33c4, 0x33c5, 0x33c6, 0x33c7, 0x33c8, + 0x33c9, 0x33ca, 0x33cb, 0x33cc, 0x33cd, 0x33ce, 0x33cf, 0x33d0, + 0x33d1, 0x33d2, 0x33d3, 0x33d4, 0x33d5, 0x33d6, 0x33d7, 0x33d8, + 0x33d9, 0x3706, 0x3707, 0x3730, 0x3731, 0x3732, 0x3733, 0x3734, + 0x3735, 0x3736, 0x3737, 0x3738, 0x3739, 0x373a, 0x373b, 0x373c, + 0x373d, 0x373e, 0x373f, 0x3740, 0x3741, 0x3742, 0x3743, 0x3744, + 0x3745, 0x3746, 0x3747, 0x3748, 0x3749, 0x374a, 0x374b, 0x374c, + 0x374d, 0x374e, 0x374f, 0x3b34, 0x3b35, 0x3b36, 0x3b37, 0x3be8, + 0x3be9, 0x3bea, 0x3beb, 0x3bec, 0x3bed, 0x3bee, 0x3bef, 0x3bf0, + 0x3bf1, 0x3bf2, 0x3bf3, 0x3bf4, 0x3bf5, 0x3bf6, 0x3bf7, 0x3bf8, + 0x3bf9, 0x3bfa, 0x3bfb, 0x3bfc, 0x3bfd, 0x3bfe, 0x3bff, 0x2000, + 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, + 0x2009, 0x200a, 0x200b, 0x200c, 0x200d, 0x202e, 0x202f, 0x2182, + 0x2183, 0x21b4, 0x21b5, 0x21b6, 0x21b7, 0x21b8, 0x21b9, 0x21ba, + 0x21bb, 0x21bc, 0x21bd, 0x21be, 0x21bf, 0x2460, 0x2461, 0x2462, + 0x2463, 0x2464, 0x2465, 0x2466, 0x2467, 0x2468, 0x2469, 0x246a, + 0x246b, 0x246c, 0x246d, 0x246e, 0x246f, 0x2470, 0x2471, 0x2472, + 0x2473, 0x26a2, 0x26a3, 0x000b, +}; + +static const uint8_t table1_mv_bits[1100] = { + 2, 4, 4, 4, 5, 5, 5, 5, + 6, 6, 7, 7, 7, 7, 7, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, + 8, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 10, 10, 10, + 10, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 10, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 13, + 13, 13, 13, 13, 13, 13, 13, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 15, 15, 15, 15, 15, + 15, 15, 15, 4, +}; + +static const uint8_t table1_mvx[1099] = { + 32, 31, 32, 31, 33, 32, 33, 33, + 31, 34, 30, 32, 32, 34, 35, 32, + 34, 33, 29, 30, 30, 32, 31, 31, + 33, 35, 35, 33, 31, 29, 29, 33, + 34, 30, 31, 28, 36, 30, 34, 32, + 32, 37, 32, 32, 25, 27, 39, 32, + 32, 32, 38, 35, 36, 32, 37, 61, + 26, 32, 34, 35, 3, 35, 27, 28, + 29, 34, 28, 37, 31, 36, 32, 27, + 31, 30, 29, 39, 33, 29, 33, 35, + 25, 25, 29, 33, 31, 31, 31, 33, + 32, 30, 32, 32, 41, 39, 33, 36, + 32, 28, 34, 36, 38, 24, 60, 31, + 23, 28, 32, 33, 59, 32, 40, 30, + 5, 34, 32, 38, 32, 30, 43, 4, + 32, 32, 42, 31, 31, 32, 26, 38, + 26, 22, 21, 37, 61, 63, 37, 31, + 32, 33, 2, 1, 23, 33, 41, 27, + 35, 30, 38, 23, 33, 3, 28, 34, + 34, 27, 41, 29, 39, 35, 36, 29, + 32, 27, 30, 32, 24, 61, 37, 26, + 59, 25, 35, 27, 36, 37, 30, 31, + 34, 40, 3, 28, 34, 39, 32, 31, + 32, 30, 24, 28, 35, 36, 26, 32, + 31, 33, 29, 33, 39, 25, 30, 24, + 35, 59, 29, 34, 25, 30, 21, 35, + 43, 40, 32, 29, 5, 28, 31, 62, + 33, 33, 25, 31, 21, 31, 43, 31, + 34, 33, 20, 40, 39, 31, 31, 57, + 38, 32, 42, 33, 32, 31, 32, 29, + 30, 44, 5, 31, 22, 34, 36, 17, + 38, 58, 38, 35, 32, 60, 35, 24, + 32, 38, 16, 45, 42, 32, 31, 29, + 4, 30, 17, 40, 46, 48, 63, 32, + 42, 19, 41, 22, 28, 36, 45, 33, + 33, 32, 29, 7, 41, 42, 18, 33, + 33, 32, 22, 37, 1, 26, 22, 23, + 49, 28, 26, 27, 32, 33, 27, 23, + 28, 36, 15, 6, 34, 27, 31, 26, + 23, 2, 33, 32, 34, 41, 28, 32, + 41, 0, 36, 38, 34, 31, 47, 32, + 17, 31, 39, 33, 37, 51, 30, 47, + 32, 50, 32, 19, 63, 30, 25, 27, + 33, 62, 24, 31, 27, 30, 37, 31, + 45, 32, 39, 20, 46, 47, 35, 19, + 34, 1, 49, 21, 21, 14, 51, 26, + 23, 31, 36, 35, 58, 29, 29, 21, + 20, 42, 13, 28, 12, 40, 31, 33, + 39, 60, 32, 44, 33, 31, 28, 37, + 29, 32, 30, 49, 43, 28, 39, 25, + 32, 48, 2, 15, 20, 25, 31, 28, + 21, 24, 25, 15, 31, 17, 37, 43, + 18, 32, 33, 24, 33, 36, 13, 33, + 31, 39, 11, 31, 33, 32, 39, 37, + 32, 32, 29, 17, 44, 46, 36, 35, + 26, 37, 58, 32, 34, 38, 8, 38, + 38, 22, 29, 25, 16, 35, 32, 35, + 33, 43, 18, 46, 38, 50, 33, 18, + 53, 60, 13, 32, 36, 33, 51, 36, + 43, 45, 27, 42, 29, 24, 30, 25, + 31, 52, 31, 35, 38, 9, 22, 34, + 4, 17, 28, 55, 42, 25, 17, 20, + 47, 34, 33, 16, 40, 25, 16, 30, + 53, 29, 10, 11, 14, 26, 33, 4, + 35, 44, 26, 16, 31, 26, 34, 38, + 29, 31, 30, 24, 22, 61, 32, 9, + 45, 34, 31, 19, 9, 31, 46, 31, + 35, 54, 29, 57, 30, 50, 3, 31, + 63, 34, 47, 41, 51, 18, 31, 14, + 37, 38, 31, 24, 32, 31, 50, 33, + 31, 54, 27, 9, 33, 23, 19, 32, + 29, 29, 33, 28, 47, 49, 30, 47, + 33, 27, 25, 54, 44, 45, 50, 58, + 51, 48, 33, 59, 33, 34, 57, 13, + 26, 33, 13, 48, 30, 11, 7, 56, + 34, 55, 26, 0, 26, 35, 1, 51, + 33, 53, 31, 45, 12, 29, 29, 51, + 31, 48, 2, 6, 34, 30, 28, 33, + 60, 40, 27, 46, 31, 9, 35, 29, + 31, 39, 55, 46, 19, 37, 62, 34, + 30, 16, 19, 49, 41, 41, 39, 37, + 14, 5, 13, 35, 55, 30, 40, 40, + 42, 8, 20, 25, 45, 35, 33, 36, + 54, 38, 27, 37, 62, 40, 15, 59, + 49, 31, 29, 34, 34, 39, 24, 29, + 25, 29, 21, 29, 10, 61, 33, 49, + 35, 34, 3, 38, 39, 29, 7, 41, + 1, 35, 4, 23, 15, 23, 11, 37, + 28, 35, 30, 30, 24, 1, 43, 56, + 8, 34, 42, 24, 45, 30, 20, 23, + 8, 38, 22, 33, 17, 52, 34, 22, + 53, 43, 44, 1, 27, 31, 41, 43, + 41, 30, 31, 36, 30, 5, 55, 31, + 33, 30, 40, 23, 15, 29, 34, 34, + 59, 34, 30, 11, 13, 38, 5, 0, + 30, 42, 5, 30, 29, 34, 10, 44, + 30, 63, 35, 12, 3, 26, 15, 17, + 25, 34, 43, 39, 34, 56, 29, 23, + 30, 12, 30, 10, 35, 9, 24, 58, + 10, 12, 54, 33, 37, 20, 41, 35, + 29, 18, 61, 30, 40, 24, 39, 53, + 62, 26, 29, 33, 34, 53, 49, 21, + 27, 11, 63, 20, 26, 23, 7, 13, + 6, 47, 29, 30, 9, 51, 22, 34, + 21, 25, 33, 56, 57, 30, 38, 51, + 51, 38, 63, 28, 40, 35, 33, 18, + 33, 33, 24, 58, 58, 34, 49, 29, + 43, 4, 1, 4, 42, 35, 35, 30, + 17, 5, 56, 61, 25, 37, 36, 55, + 28, 35, 29, 50, 48, 52, 2, 42, + 34, 40, 46, 46, 43, 35, 29, 48, + 20, 29, 31, 41, 7, 30, 35, 19, + 14, 21, 8, 39, 39, 40, 46, 55, + 34, 6, 30, 34, 37, 25, 37, 33, + 22, 44, 52, 17, 35, 29, 36, 35, + 40, 37, 28, 30, 50, 14, 28, 55, + 6, 23, 19, 14, 30, 3, 30, 28, + 28, 61, 61, 47, 45, 48, 40, 40, + 34, 34, 25, 30, 29, 35, 4, 26, + 53, 50, 26, 41, 27, 59, 27, 38, + 39, 3, 50, 43, 47, 23, 33, 55, + 35, 21, 23, 35, 61, 33, 46, 52, + 35, 34, 24, 30, 43, 16, 37, 21, + 2, 24, 45, 34, 30, 55, 55, 1, + 29, 29, 26, 28, 25, 31, 36, 22, + 17, 30, 52, 2, 44, 44, 57, 26, + 62, 41, 39, 57, 26, 46, 49, 11, + 16, 19, 5, 59, 38, 39, 58, 38, + 25, 49, 50, 22, 28, 59, 9, 59, + 7, 28, 55, 17, 4, 35, 50, 21, + 29, 44, 47, 18, 24, 19, 25, 42, + 35, 3, 51, 35, 16, 35, 30, 63, + 57, 39, 39, 25, 35, 38, 9, 16, + 36, 45, 31, 60, 14, 34, 42, 24, + 0, 37, 18, 61, 57, 37, 28, 53, + 20, 46, 14, 47, 38, 38, 38, 9, + 34, 39, 43, 17, 39, 59, 5, 27, + 0, 12, 27, +}; + +static const uint8_t table1_mvy[1099] = { + 32, 32, 31, 31, 32, 33, 31, 33, + 33, 32, 32, 30, 34, 31, 32, 29, + 33, 30, 32, 33, 31, 35, 34, 30, + 34, 31, 33, 29, 29, 31, 33, 35, + 30, 30, 35, 32, 32, 34, 34, 28, + 25, 32, 36, 27, 32, 32, 32, 37, + 39, 3, 32, 30, 31, 26, 31, 32, + 32, 38, 29, 29, 32, 34, 31, 31, + 34, 35, 33, 33, 28, 33, 1, 33, + 27, 29, 30, 31, 28, 29, 37, 35, + 31, 33, 35, 27, 36, 37, 25, 25, + 61, 35, 4, 5, 32, 33, 36, 30, + 23, 30, 28, 34, 31, 32, 32, 39, + 32, 34, 21, 39, 32, 59, 32, 28, + 32, 36, 60, 33, 24, 36, 32, 32, + 41, 2, 32, 38, 26, 22, 33, 30, + 31, 32, 32, 30, 31, 32, 29, 3, + 40, 38, 32, 32, 33, 26, 31, 34, + 28, 38, 34, 31, 3, 31, 35, 38, + 27, 35, 33, 28, 29, 27, 29, 27, + 43, 29, 37, 63, 31, 33, 34, 30, + 31, 30, 37, 30, 35, 35, 26, 41, + 37, 31, 33, 28, 26, 30, 42, 24, + 7, 27, 33, 29, 36, 28, 34, 57, + 23, 41, 36, 23, 35, 34, 25, 30, + 25, 33, 25, 25, 29, 24, 33, 39, + 33, 33, 0, 37, 31, 36, 21, 32, + 61, 24, 35, 61, 31, 5, 31, 59, + 39, 21, 32, 30, 34, 22, 40, 32, + 29, 16, 31, 5, 62, 2, 20, 39, + 39, 32, 33, 1, 31, 24, 36, 32, + 36, 32, 28, 26, 6, 31, 38, 34, + 58, 35, 32, 33, 33, 17, 43, 26, + 31, 40, 31, 34, 32, 32, 31, 19, + 30, 32, 29, 33, 38, 38, 32, 59, + 40, 18, 38, 32, 35, 34, 32, 17, + 1, 15, 30, 28, 31, 28, 34, 29, + 32, 27, 35, 27, 49, 22, 37, 34, + 37, 26, 32, 32, 22, 28, 45, 29, + 30, 31, 43, 46, 41, 30, 26, 13, + 34, 32, 27, 38, 42, 42, 33, 47, + 33, 60, 27, 42, 25, 32, 22, 32, + 48, 32, 45, 33, 33, 41, 27, 25, + 19, 31, 35, 19, 36, 42, 27, 17, + 31, 44, 28, 33, 33, 31, 23, 31, + 40, 33, 31, 34, 30, 32, 33, 36, + 35, 47, 37, 41, 31, 23, 41, 29, + 30, 35, 32, 25, 32, 28, 58, 2, + 37, 33, 14, 33, 49, 20, 39, 36, + 21, 9, 23, 33, 35, 24, 39, 37, + 11, 33, 30, 31, 31, 28, 51, 40, + 35, 29, 25, 33, 46, 35, 37, 30, + 30, 8, 63, 28, 15, 40, 33, 45, + 49, 25, 32, 4, 47, 51, 36, 39, + 53, 10, 24, 29, 30, 31, 25, 40, + 38, 38, 33, 56, 23, 27, 32, 37, + 26, 29, 43, 36, 33, 24, 55, 43, + 9, 29, 34, 34, 24, 33, 18, 33, + 33, 30, 31, 50, 24, 60, 30, 39, + 34, 30, 39, 28, 22, 38, 2, 26, + 63, 32, 57, 21, 39, 33, 28, 18, + 30, 34, 22, 33, 29, 41, 30, 34, + 35, 21, 13, 34, 35, 39, 30, 46, + 32, 42, 32, 31, 33, 26, 11, 33, + 22, 31, 25, 31, 53, 27, 43, 25, + 40, 50, 21, 36, 38, 30, 12, 31, + 34, 20, 15, 29, 32, 62, 30, 13, + 17, 32, 19, 31, 20, 31, 30, 7, + 1, 17, 34, 37, 31, 31, 44, 34, + 26, 40, 16, 37, 52, 48, 30, 20, + 18, 33, 38, 29, 7, 25, 30, 54, + 45, 47, 46, 41, 29, 29, 16, 30, + 14, 26, 38, 34, 34, 29, 34, 30, + 29, 30, 57, 30, 4, 46, 33, 29, + 39, 44, 30, 31, 50, 33, 31, 32, + 19, 32, 40, 31, 37, 47, 1, 35, + 16, 31, 0, 35, 33, 1, 17, 34, + 9, 34, 33, 31, 49, 43, 42, 51, + 34, 29, 23, 29, 14, 30, 45, 49, + 11, 24, 31, 28, 35, 41, 30, 44, + 18, 29, 34, 35, 36, 25, 26, 21, + 31, 30, 34, 19, 34, 44, 36, 38, + 25, 31, 28, 23, 37, 3, 55, 41, + 30, 22, 41, 24, 33, 26, 35, 35, + 30, 55, 51, 47, 48, 38, 24, 15, + 21, 50, 25, 46, 30, 29, 10, 34, + 42, 45, 29, 42, 22, 3, 33, 27, + 34, 1, 34, 28, 34, 36, 35, 23, + 23, 13, 58, 3, 26, 63, 25, 31, + 34, 61, 38, 39, 25, 61, 29, 37, + 30, 41, 26, 48, 28, 33, 50, 35, + 30, 37, 29, 29, 40, 6, 39, 28, + 28, 19, 8, 22, 45, 34, 35, 10, + 58, 17, 37, 39, 30, 18, 54, 14, + 29, 16, 59, 30, 35, 23, 35, 30, + 47, 36, 29, 55, 20, 12, 31, 35, + 14, 29, 18, 34, 34, 24, 29, 26, + 22, 2, 27, 23, 8, 30, 55, 38, + 60, 31, 4, 34, 49, 34, 27, 34, + 33, 30, 31, 54, 42, 35, 38, 46, + 44, 26, 27, 9, 39, 25, 21, 29, + 28, 42, 13, 0, 5, 34, 37, 28, + 24, 29, 63, 26, 22, 27, 29, 25, + 33, 25, 61, 0, 35, 25, 36, 15, + 27, 40, 53, 33, 3, 10, 16, 37, + 38, 18, 30, 46, 27, 9, 6, 29, + 62, 8, 42, 28, 29, 3, 25, 16, + 26, 29, 35, 28, 27, 51, 61, 48, + 37, 9, 34, 7, 49, 45, 20, 29, + 21, 5, 5, 29, 28, 34, 29, 24, + 10, 24, 35, 36, 38, 55, 11, 36, + 38, 53, 54, 26, 30, 49, 20, 27, + 30, 39, 33, 41, 49, 22, 38, 38, + 4, 30, 8, 9, 3, 24, 22, 50, + 37, 36, 31, 27, 2, 9, 42, 63, + 25, 19, 44, 1, 28, 28, 48, 30, + 34, 41, 41, 38, 12, 27, 15, 0, + 16, 34, 35, 38, 28, 29, 40, 42, + 51, 52, 45, 54, 59, 59, 42, 44, + 37, 26, 46, 24, 15, 39, 22, 46, + 19, 35, 38, 17, 37, 23, 52, 55, + 50, 37, 26, 11, 37, 12, 24, 30, + 16, 13, 22, 13, 36, 35, 40, 41, + 34, 41, 26, 53, 51, 5, 21, 30, + 2, 63, 41, 20, 1, 56, 21, 24, + 25, 5, 28, 35, 26, 28, 30, 18, + 29, 23, 40, 34, 20, 42, 39, 34, + 28, 61, 38, 27, 62, 9, 36, 17, + 9, 49, 24, 25, 54, 34, 39, 37, + 3, 1, 25, 38, 38, 44, 35, 36, + 12, 60, 36, 38, 40, 25, 43, 39, + 53, 28, 39, 57, 46, 10, 52, 27, + 35, 42, 45, 59, 15, 60, 38, 24, + 23, 39, 12, 29, 24, 0, 20, 16, + 28, 43, 35, 28, 1, 49, 4, 21, + 42, 39, 29, 3, 44, 21, 53, 55, + 11, 5, 3, 39, 53, 28, 25, 19, + 34, 28, 21, +}; + +MVTable mv_tables[2] = { + { + 1099, + table0_mv_code, + table0_mv_bits, + table0_mvx, + table0_mvy, + }, + { + 1099, + table1_mv_code, + table1_mv_bits, + table1_mvx, + table1_mvy, + } +}; + +const uint8_t v2_mb_type[8][2] = { + {1, 1}, {0 , 2}, {3 , 3}, {9 , 5}, + {5, 4}, {0x21, 7}, {0x20, 7}, {0x11, 6}, +}; + +const uint8_t v2_intra_cbpc[4][2] = { + {1, 1}, {0, 3}, {1, 3}, {1, 2}, +}; + +const uint8_t wmv1_y_dc_scale_table[32]={ +// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 + 0, 8, 8, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21 +}; +const uint8_t wmv1_c_dc_scale_table[32]={ +// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 + 0, 8, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22 +}; + +const uint8_t old_ff_y_dc_scale_table[32]={ +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 + 0, 8, 8, 8, 8,10,12,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39 +}; +const uint8_t old_ff_c_dc_scale_table[32]={ +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 + 0, 8, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22 +}; + +const uint8_t wmv1_scantable[WMV1_SCANTABLE_COUNT][64]={ + { + 0x00, 0x08, 0x01, 0x02, 0x09, 0x10, 0x18, 0x11, + 0x0A, 0x03, 0x04, 0x0B, 0x12, 0x19, 0x20, 0x28, + 0x30, 0x38, 0x29, 0x21, 0x1A, 0x13, 0x0C, 0x05, + 0x06, 0x0D, 0x14, 0x1B, 0x22, 0x31, 0x39, 0x3A, + 0x32, 0x2A, 0x23, 0x1C, 0x15, 0x0E, 0x07, 0x0F, + 0x16, 0x1D, 0x24, 0x2B, 0x33, 0x3B, 0x3C, 0x34, + 0x2C, 0x25, 0x1E, 0x17, 0x1F, 0x26, 0x2D, 0x35, + 0x3D, 0x3E, 0x36, 0x2E, 0x27, 0x2F, 0x37, 0x3F, + }, + { + 0x00, 0x08, 0x01, 0x02, 0x09, 0x10, 0x18, 0x11, + 0x0A, 0x03, 0x04, 0x0B, 0x12, 0x19, 0x20, 0x28, + 0x21, 0x30, 0x1A, 0x13, 0x0C, 0x05, 0x06, 0x0D, + 0x14, 0x1B, 0x22, 0x29, 0x38, 0x31, 0x39, 0x2A, + 0x23, 0x1C, 0x15, 0x0E, 0x07, 0x0F, 0x16, 0x1D, + 0x24, 0x2B, 0x32, 0x3A, 0x33, 0x3B, 0x2C, 0x25, + 0x1E, 0x17, 0x1F, 0x26, 0x2D, 0x34, 0x3C, 0x35, + 0x3D, 0x2E, 0x27, 0x2F, 0x36, 0x3E, 0x37, 0x3F, + }, + { + 0x00, 0x01, 0x08, 0x02, 0x03, 0x09, 0x10, 0x18, + 0x11, 0x0A, 0x04, 0x05, 0x0B, 0x12, 0x19, 0x20, + 0x28, 0x30, 0x21, 0x1A, 0x13, 0x0C, 0x06, 0x07, + 0x0D, 0x14, 0x1B, 0x22, 0x29, 0x38, 0x31, 0x39, + 0x2A, 0x23, 0x1C, 0x15, 0x0E, 0x0F, 0x16, 0x1D, + 0x24, 0x2B, 0x32, 0x3A, 0x33, 0x2C, 0x25, 0x1E, + 0x17, 0x1F, 0x26, 0x2D, 0x34, 0x3B, 0x3C, 0x35, + 0x2E, 0x27, 0x2F, 0x36, 0x3D, 0x3E, 0x37, 0x3F, + }, + { + 0x00, 0x08, 0x10, 0x01, 0x18, 0x20, 0x28, 0x09, + 0x02, 0x03, 0x0A, 0x11, 0x19, 0x30, 0x38, 0x29, + 0x21, 0x1A, 0x12, 0x0B, 0x04, 0x05, 0x0C, 0x13, + 0x1B, 0x22, 0x31, 0x39, 0x32, 0x2A, 0x23, 0x1C, + 0x14, 0x0D, 0x06, 0x07, 0x0E, 0x15, 0x1D, 0x24, + 0x2B, 0x33, 0x3A, 0x3B, 0x34, 0x2C, 0x25, 0x1E, + 0x16, 0x0F, 0x17, 0x1F, 0x26, 0x2D, 0x3C, 0x35, + 0x2E, 0x27, 0x2F, 0x36, 0x3D, 0x3E, 0x37, 0x3F, + } +}; + +const uint8_t table_inter_intra[4][2]={ + {0,1} /*Luma-Left Chroma-Left*/, + {2,2} /*Luma-Top Chroma-Left*/, + {6,3} /*luma-Left Chroma-Top */, + {7,3} /*luma-Top Chroma-Top */ +}; + +static const uint32_t table_mb_non_intra2[128][2] = { +{0x0000A7, 14}, {0x01B2B8, 18}, {0x01B28E, 18}, {0x036575, 19}, +{0x006CAC, 16}, {0x000A69, 18}, {0x002934, 20}, {0x00526B, 21}, +{0x006CA1, 16}, {0x01B2B9, 18}, {0x0029AD, 20}, {0x029353, 24}, +{0x006CA7, 16}, {0x006CAB, 16}, {0x01B2BB, 18}, {0x00029B, 16}, +{0x00D944, 17}, {0x000A6A, 18}, {0x0149A8, 23}, {0x03651F, 19}, +{0x006CAF, 16}, {0x000A4C, 18}, {0x03651E, 19}, {0x000A48, 18}, +{0x00299C, 20}, {0x00299F, 20}, {0x029352, 24}, {0x0029AC, 20}, +{0x000296, 16}, {0x00D946, 17}, {0x000A68, 18}, {0x000298, 16}, +{0x000527, 17}, {0x00D94D, 17}, {0x0014D7, 19}, {0x036574, 19}, +{0x000A5C, 18}, {0x01B299, 18}, {0x00299D, 20}, {0x00299E, 20}, +{0x000525, 17}, {0x000A66, 18}, {0x00A4D5, 22}, {0x00149B, 19}, +{0x000295, 16}, {0x006CAD, 16}, {0x000A49, 18}, {0x000521, 17}, +{0x006CAA, 16}, {0x00D945, 17}, {0x01B298, 18}, {0x00052F, 17}, +{0x003654, 15}, {0x006CA0, 16}, {0x000532, 17}, {0x000291, 16}, +{0x003652, 15}, {0x000520, 17}, {0x000A5D, 18}, {0x000294, 16}, +{0x00009B, 11}, {0x0006E2, 12}, {0x000028, 12}, {0x0001B0, 10}, +{0x000001, 3}, {0x000010, 8}, {0x00002F, 6}, {0x00004C, 10}, +{0x00000D, 4}, {0x000000, 10}, {0x000006, 9}, {0x000134, 12}, +{0x00000C, 4}, {0x000007, 10}, {0x000007, 9}, {0x0006E1, 12}, +{0x00000E, 5}, {0x0000DA, 9}, {0x000022, 9}, {0x000364, 11}, +{0x00000F, 4}, {0x000006, 10}, {0x00000F, 9}, {0x000135, 12}, +{0x000014, 5}, {0x0000DD, 9}, {0x000004, 9}, {0x000015, 11}, +{0x00001A, 6}, {0x0001B3, 10}, {0x000005, 10}, {0x0006E3, 12}, +{0x00000C, 5}, {0x0000B9, 8}, {0x000004, 8}, {0x0000DB, 9}, +{0x00000E, 4}, {0x00000B, 10}, {0x000023, 9}, {0x0006CB, 12}, +{0x000005, 6}, {0x0001B1, 10}, {0x000001, 10}, {0x0006E0, 12}, +{0x000011, 5}, {0x0000DF, 9}, {0x00000E, 9}, {0x000373, 11}, +{0x000003, 5}, {0x0000B8, 8}, {0x000006, 8}, {0x000175, 9}, +{0x000015, 5}, {0x000174, 9}, {0x000027, 9}, {0x000372, 11}, +{0x000010, 5}, {0x0000BB, 8}, {0x000005, 8}, {0x0000DE, 9}, +{0x00000F, 5}, {0x000001, 9}, {0x000012, 8}, {0x000004, 10}, +{0x000002, 3}, {0x000016, 5}, {0x000009, 4}, {0x000001, 5}, +}; + +static const uint32_t table_mb_non_intra3[128][2] = { +{0x0002A1, 10}, {0x005740, 15}, {0x01A0BF, 18}, {0x015D19, 17}, +{0x001514, 13}, {0x00461E, 15}, {0x015176, 17}, {0x015177, 17}, +{0x0011AD, 13}, {0x00682E, 16}, {0x0682F9, 20}, {0x03417D, 19}, +{0x001A36, 14}, {0x002A2D, 14}, {0x00D05E, 17}, {0x006824, 16}, +{0x001515, 13}, {0x00545C, 15}, {0x0230E9, 18}, {0x011AFA, 17}, +{0x0015D7, 13}, {0x005747, 15}, {0x008D79, 16}, {0x006825, 16}, +{0x002BA2, 14}, {0x00A8BA, 16}, {0x0235F6, 18}, {0x015D18, 17}, +{0x0011AE, 13}, {0x00346F, 15}, {0x008C3B, 16}, {0x00346E, 15}, +{0x000D1A, 13}, {0x00461F, 15}, {0x0682F8, 20}, {0x011875, 17}, +{0x002BA1, 14}, {0x008D61, 16}, {0x0235F7, 18}, {0x0230E8, 18}, +{0x001513, 13}, {0x008D7B, 16}, {0x011AF4, 17}, {0x011AF5, 17}, +{0x001185, 13}, {0x0046BF, 15}, {0x008D60, 16}, {0x008D7C, 16}, +{0x001512, 13}, {0x00461C, 15}, {0x00AE8D, 16}, {0x008D78, 16}, +{0x000D0E, 13}, {0x003413, 15}, {0x0046B1, 15}, {0x003416, 15}, +{0x000AEA, 12}, {0x002A2C, 14}, {0x005741, 15}, {0x002A2F, 14}, +{0x000158, 9}, {0x0008D2, 12}, {0x00054C, 11}, {0x000686, 12}, +{0x000000, 2}, {0x000069, 8}, {0x00006B, 8}, {0x00068C, 12}, +{0x000007, 3}, {0x00015E, 9}, {0x0002A3, 10}, {0x000AE9, 12}, +{0x000006, 3}, {0x000231, 10}, {0x0002B8, 10}, {0x001A08, 14}, +{0x000010, 5}, {0x0001A9, 10}, {0x000342, 11}, {0x000A88, 12}, +{0x000004, 4}, {0x0001A2, 10}, {0x0002A4, 10}, {0x001184, 13}, +{0x000012, 5}, {0x000232, 10}, {0x0002B2, 10}, {0x000680, 12}, +{0x00001B, 6}, {0x00046A, 11}, {0x00068E, 12}, {0x002359, 14}, +{0x000016, 5}, {0x00015F, 9}, {0x0002A0, 10}, {0x00054D, 11}, +{0x000005, 4}, {0x000233, 10}, {0x0002B9, 10}, {0x0015D6, 13}, +{0x000022, 6}, {0x000468, 11}, {0x000683, 12}, {0x001A0A, 14}, +{0x000013, 5}, {0x000236, 10}, {0x0002BB, 10}, {0x001186, 13}, +{0x000017, 5}, {0x0001AB, 10}, {0x0002A7, 10}, {0x0008D3, 12}, +{0x000014, 5}, {0x000237, 10}, {0x000460, 11}, {0x000D0F, 13}, +{0x000019, 6}, {0x0001AA, 10}, {0x0002B3, 10}, {0x000681, 12}, +{0x000018, 6}, {0x0001A8, 10}, {0x0002A5, 10}, {0x00068F, 12}, +{0x000007, 4}, {0x000055, 7}, {0x000047, 7}, {0x0000AD, 8}, +}; + +static const uint32_t table_mb_non_intra4[128][2] = { +{0x0000D4, 8}, {0x0021C5, 14}, {0x00F18A, 16}, {0x00D5BC, 16}, +{0x000879, 12}, {0x00354D, 14}, {0x010E3F, 17}, {0x010F54, 17}, +{0x000866, 12}, {0x00356E, 14}, {0x010F55, 17}, {0x010E3E, 17}, +{0x0010CE, 13}, {0x003C84, 14}, {0x00D5BD, 16}, {0x00F18B, 16}, +{0x000868, 12}, {0x00438C, 15}, {0x0087AB, 16}, {0x00790B, 15}, +{0x000F10, 12}, {0x00433D, 15}, {0x006AD3, 15}, {0x00790A, 15}, +{0x001AA7, 13}, {0x0043D4, 15}, {0x00871E, 16}, {0x006ADF, 15}, +{0x000D7C, 12}, {0x003C94, 14}, {0x00438D, 15}, {0x006AD2, 15}, +{0x0006BC, 11}, {0x0021E9, 14}, {0x006ADA, 15}, {0x006A99, 15}, +{0x0010F7, 13}, {0x004389, 15}, {0x006ADB, 15}, {0x0078C4, 15}, +{0x000D56, 12}, {0x0035F7, 14}, {0x00438E, 15}, {0x006A98, 15}, +{0x000D52, 12}, {0x003C95, 14}, {0x004388, 15}, {0x00433C, 15}, +{0x000D54, 12}, {0x001E4B, 13}, {0x003C63, 14}, {0x003C83, 14}, +{0x000861, 12}, {0x0021EB, 14}, {0x00356C, 14}, {0x0035F6, 14}, +{0x000863, 12}, {0x00219F, 14}, {0x003568, 14}, {0x003C82, 14}, +{0x0001AE, 9}, {0x0010C0, 13}, {0x000F11, 12}, {0x001AFA, 13}, +{0x000000, 1}, {0x0000F0, 8}, {0x0001AD, 9}, {0x0010C1, 13}, +{0x00000A, 4}, {0x0003C5, 10}, {0x000789, 11}, {0x001AB5, 13}, +{0x000009, 4}, {0x000435, 11}, {0x000793, 11}, {0x001E40, 13}, +{0x00001D, 5}, {0x0003CB, 10}, {0x000878, 12}, {0x001AAF, 13}, +{0x00000B, 4}, {0x0003C7, 10}, {0x000791, 11}, {0x001AAB, 13}, +{0x00001F, 5}, {0x000436, 11}, {0x0006BF, 11}, {0x000F19, 12}, +{0x00003D, 6}, {0x000D51, 12}, {0x0010C4, 13}, {0x0021E8, 14}, +{0x000036, 6}, {0x000437, 11}, {0x0006AF, 11}, {0x0010C5, 13}, +{0x00000C, 4}, {0x000432, 11}, {0x000794, 11}, {0x001E30, 13}, +{0x000042, 7}, {0x000870, 12}, {0x000F24, 12}, {0x001E43, 13}, +{0x000020, 6}, {0x00043E, 11}, {0x000795, 11}, {0x001AAA, 13}, +{0x000037, 6}, {0x0006AC, 11}, {0x0006AE, 11}, {0x0010F6, 13}, +{0x000034, 6}, {0x00043A, 11}, {0x000D50, 12}, {0x001AAE, 13}, +{0x000039, 6}, {0x00043F, 11}, {0x00078D, 11}, {0x0010D2, 13}, +{0x000038, 6}, {0x00043B, 11}, {0x0006BD, 11}, {0x0010D3, 13}, +{0x000011, 5}, {0x0001AC, 9}, {0x0000F3, 8}, {0x000439, 11}, +}; + +const uint32_t (*wmv2_inter_table[WMV2_INTER_CBP_TABLE_COUNT])[2]={ + table_mb_non_intra2, + table_mb_non_intra3, + table_mb_non_intra4, + table_mb_non_intra, +}; + +const uint8_t wmv2_scantableA[64]={ +0x00, 0x01, 0x02, 0x08, 0x03, 0x09, 0x0A, 0x10, +0x04, 0x0B, 0x11, 0x18, 0x12, 0x0C, 0x05, 0x13, +0x19, 0x0D, 0x14, 0x1A, 0x1B, 0x06, 0x15, 0x1C, +0x0E, 0x16, 0x1D, 0x07, 0x1E, 0x0F, 0x17, 0x1F, +}; + +const uint8_t wmv2_scantableB[64]={ +0x00, 0x08, 0x01, 0x10, 0x09, 0x18, 0x11, 0x02, +0x20, 0x0A, 0x19, 0x28, 0x12, 0x30, 0x21, 0x1A, +0x38, 0x29, 0x22, 0x03, 0x31, 0x39, 0x0B, 0x2A, +0x13, 0x32, 0x1B, 0x3A, 0x23, 0x2B, 0x33, 0x3B, +}; diff --git a/contrib/ffmpeg/libavcodec/msmpeg4data.h b/contrib/ffmpeg/libavcodec/msmpeg4data.h index d1ff70371..9bfb1ba99 100644 --- a/contrib/ffmpeg/libavcodec/msmpeg4data.h +++ b/contrib/ffmpeg/libavcodec/msmpeg4data.h @@ -3,6 +3,8 @@ * copyright (c) 2001 Fabrice Bellard * copyright (c) 2002-2004 Michael Niedermayer * + * msmpeg4v1 & v2 stuff by Michael Niedermayer + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -18,8 +20,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * msmpeg4v1 & v2 stuff by Michael Niedermayer */ /** @@ -27,1764 +27,12 @@ * MSMPEG4 data tables. */ -/* intra picture macro block coded block pattern */ -const uint16_t ff_msmp4_mb_i_table[64][2] = { -{ 0x1, 1 },{ 0x17, 6 },{ 0x9, 5 },{ 0x5, 5 }, -{ 0x6, 5 },{ 0x47, 9 },{ 0x20, 7 },{ 0x10, 7 }, -{ 0x2, 5 },{ 0x7c, 9 },{ 0x3a, 7 },{ 0x1d, 7 }, -{ 0x2, 6 },{ 0xec, 9 },{ 0x77, 8 },{ 0x0, 8 }, -{ 0x3, 5 },{ 0xb7, 9 },{ 0x2c, 7 },{ 0x13, 7 }, -{ 0x1, 6 },{ 0x168, 10 },{ 0x46, 8 },{ 0x3f, 8 }, -{ 0x1e, 6 },{ 0x712, 13 },{ 0xb5, 9 },{ 0x42, 8 }, -{ 0x22, 7 },{ 0x1c5, 11 },{ 0x11e, 10 },{ 0x87, 9 }, -{ 0x6, 4 },{ 0x3, 9 },{ 0x1e, 7 },{ 0x1c, 6 }, -{ 0x12, 7 },{ 0x388, 12 },{ 0x44, 9 },{ 0x70, 9 }, -{ 0x1f, 6 },{ 0x23e, 11 },{ 0x39, 8 },{ 0x8e, 9 }, -{ 0x1, 7 },{ 0x1c6, 11 },{ 0xb6, 9 },{ 0x45, 9 }, -{ 0x14, 6 },{ 0x23f, 11 },{ 0x7d, 9 },{ 0x18, 9 }, -{ 0x7, 7 },{ 0x1c7, 11 },{ 0x86, 9 },{ 0x19, 9 }, -{ 0x15, 6 },{ 0x1db, 10 },{ 0x2, 9 },{ 0x46, 9 }, -{ 0xd, 8 },{ 0x713, 13 },{ 0x1da, 10 },{ 0x169, 10 }, -}; - -/* non intra picture macro block coded block pattern + mb type */ -static const uint32_t table_mb_non_intra[128][2] = { -{ 0x40, 7 },{ 0x13c9, 13 },{ 0x9fd, 12 },{ 0x1fc, 15 }, -{ 0x9fc, 12 },{ 0xa83, 18 },{ 0x12d34, 17 },{ 0x83bc, 16 }, -{ 0x83a, 12 },{ 0x7f8, 17 },{ 0x3fd, 16 },{ 0x3ff, 16 }, -{ 0x79, 13 },{ 0xa82, 18 },{ 0x969d, 16 },{ 0x2a4, 16 }, -{ 0x978, 12 },{ 0x543, 17 },{ 0x41df, 15 },{ 0x7f9, 17 }, -{ 0x12f3, 13 },{ 0x25a6b, 18 },{ 0x25ef9, 18 },{ 0x3fa, 16 }, -{ 0x20ee, 14 },{ 0x969ab, 20 },{ 0x969c, 16 },{ 0x25ef8, 18 }, -{ 0x12d2, 13 },{ 0xa85, 18 },{ 0x969e, 16 },{ 0x4bc8, 15 }, -{ 0x3d, 12 },{ 0x12f7f, 17 },{ 0x2a2, 16 },{ 0x969f, 16 }, -{ 0x25ee, 14 },{ 0x12d355, 21 },{ 0x12f7d, 17 },{ 0x12f7e, 17 }, -{ 0x9e5, 12 },{ 0xa81, 18 },{ 0x4b4d4, 19 },{ 0x83bd, 16 }, -{ 0x78, 13 },{ 0x969b, 16 },{ 0x3fe, 16 },{ 0x2a5, 16 }, -{ 0x7e, 13 },{ 0xa80, 18 },{ 0x2a3, 16 },{ 0x3fb, 16 }, -{ 0x1076, 13 },{ 0xa84, 18 },{ 0x153, 15 },{ 0x4bc9, 15 }, -{ 0x55, 13 },{ 0x12d354, 21 },{ 0x4bde, 15 },{ 0x25e5, 14 }, -{ 0x25b, 10 },{ 0x4b4c, 15 },{ 0x96b, 12 },{ 0x96a, 12 }, -{ 0x1, 2 },{ 0x0, 7 },{ 0x26, 6 },{ 0x12b, 9 }, -{ 0x7, 3 },{ 0x20f, 10 },{ 0x4, 9 },{ 0x28, 12 }, -{ 0x6, 3 },{ 0x20a, 10 },{ 0x128, 9 },{ 0x2b, 12 }, -{ 0x11, 5 },{ 0x1b, 11 },{ 0x13a, 9 },{ 0x4ff, 11 }, -{ 0x3, 4 },{ 0x277, 10 },{ 0x106, 9 },{ 0x839, 12 }, -{ 0xb, 4 },{ 0x27b, 10 },{ 0x12c, 9 },{ 0x4bf, 11 }, -{ 0x9, 6 },{ 0x35, 12 },{ 0x27e, 10 },{ 0x13c8, 13 }, -{ 0x1, 6 },{ 0x4aa, 11 },{ 0x208, 10 },{ 0x29, 12 }, -{ 0x1, 4 },{ 0x254, 10 },{ 0x12e, 9 },{ 0x838, 12 }, -{ 0x24, 6 },{ 0x4f3, 11 },{ 0x276, 10 },{ 0x12f6, 13 }, -{ 0x1, 5 },{ 0x27a, 10 },{ 0x13e, 9 },{ 0x3e, 12 }, -{ 0x8, 6 },{ 0x413, 11 },{ 0xc, 10 },{ 0x4be, 11 }, -{ 0x14, 5 },{ 0x412, 11 },{ 0x253, 10 },{ 0x97a, 12 }, -{ 0x21, 6 },{ 0x4ab, 11 },{ 0x20b, 10 },{ 0x34, 12 }, -{ 0x15, 5 },{ 0x278, 10 },{ 0x252, 10 },{ 0x968, 12 }, -{ 0x5, 5 },{ 0xb, 10 },{ 0x9c, 8 },{ 0xe, 10 }, -}; - -/* dc table 0 */ - -const uint32_t ff_table0_dc_lum[120][2] = { -{ 0x1, 1 },{ 0x1, 2 },{ 0x1, 4 },{ 0x1, 5 }, -{ 0x5, 5 },{ 0x7, 5 },{ 0x8, 6 },{ 0xc, 6 }, -{ 0x0, 7 },{ 0x2, 7 },{ 0x12, 7 },{ 0x1a, 7 }, -{ 0x3, 8 },{ 0x7, 8 },{ 0x27, 8 },{ 0x37, 8 }, -{ 0x5, 9 },{ 0x4c, 9 },{ 0x6c, 9 },{ 0x6d, 9 }, -{ 0x8, 10 },{ 0x19, 10 },{ 0x9b, 10 },{ 0x1b, 10 }, -{ 0x9a, 10 },{ 0x13, 11 },{ 0x34, 11 },{ 0x35, 11 }, -{ 0x61, 12 },{ 0x48, 13 },{ 0xc4, 13 },{ 0x4a, 13 }, -{ 0xc6, 13 },{ 0xc7, 13 },{ 0x92, 14 },{ 0x18b, 14 }, -{ 0x93, 14 },{ 0x183, 14 },{ 0x182, 14 },{ 0x96, 14 }, -{ 0x97, 14 },{ 0x180, 14 },{ 0x314, 15 },{ 0x315, 15 }, -{ 0x605, 16 },{ 0x604, 16 },{ 0x606, 16 },{ 0xc0e, 17 }, -{ 0x303cd, 23 },{ 0x303c9, 23 },{ 0x303c8, 23 },{ 0x303ca, 23 }, -{ 0x303cb, 23 },{ 0x303cc, 23 },{ 0x303ce, 23 },{ 0x303cf, 23 }, -{ 0x303d0, 23 },{ 0x303d1, 23 },{ 0x303d2, 23 },{ 0x303d3, 23 }, -{ 0x303d4, 23 },{ 0x303d5, 23 },{ 0x303d6, 23 },{ 0x303d7, 23 }, -{ 0x303d8, 23 },{ 0x303d9, 23 },{ 0x303da, 23 },{ 0x303db, 23 }, -{ 0x303dc, 23 },{ 0x303dd, 23 },{ 0x303de, 23 },{ 0x303df, 23 }, -{ 0x303e0, 23 },{ 0x303e1, 23 },{ 0x303e2, 23 },{ 0x303e3, 23 }, -{ 0x303e4, 23 },{ 0x303e5, 23 },{ 0x303e6, 23 },{ 0x303e7, 23 }, -{ 0x303e8, 23 },{ 0x303e9, 23 },{ 0x303ea, 23 },{ 0x303eb, 23 }, -{ 0x303ec, 23 },{ 0x303ed, 23 },{ 0x303ee, 23 },{ 0x303ef, 23 }, -{ 0x303f0, 23 },{ 0x303f1, 23 },{ 0x303f2, 23 },{ 0x303f3, 23 }, -{ 0x303f4, 23 },{ 0x303f5, 23 },{ 0x303f6, 23 },{ 0x303f7, 23 }, -{ 0x303f8, 23 },{ 0x303f9, 23 },{ 0x303fa, 23 },{ 0x303fb, 23 }, -{ 0x303fc, 23 },{ 0x303fd, 23 },{ 0x303fe, 23 },{ 0x303ff, 23 }, -{ 0x60780, 24 },{ 0x60781, 24 },{ 0x60782, 24 },{ 0x60783, 24 }, -{ 0x60784, 24 },{ 0x60785, 24 },{ 0x60786, 24 },{ 0x60787, 24 }, -{ 0x60788, 24 },{ 0x60789, 24 },{ 0x6078a, 24 },{ 0x6078b, 24 }, -{ 0x6078c, 24 },{ 0x6078d, 24 },{ 0x6078e, 24 },{ 0x6078f, 24 }, -}; - -const uint32_t ff_table0_dc_chroma[120][2] = { -{ 0x0, 2 },{ 0x1, 2 },{ 0x5, 3 },{ 0x9, 4 }, -{ 0xd, 4 },{ 0x11, 5 },{ 0x1d, 5 },{ 0x1f, 5 }, -{ 0x21, 6 },{ 0x31, 6 },{ 0x38, 6 },{ 0x33, 6 }, -{ 0x39, 6 },{ 0x3d, 6 },{ 0x61, 7 },{ 0x79, 7 }, -{ 0x80, 8 },{ 0xc8, 8 },{ 0xca, 8 },{ 0xf0, 8 }, -{ 0x81, 8 },{ 0xc0, 8 },{ 0xc9, 8 },{ 0x107, 9 }, -{ 0x106, 9 },{ 0x196, 9 },{ 0x183, 9 },{ 0x1e3, 9 }, -{ 0x1e2, 9 },{ 0x20a, 10 },{ 0x20b, 10 },{ 0x609, 11 }, -{ 0x412, 11 },{ 0x413, 11 },{ 0x60b, 11 },{ 0x411, 11 }, -{ 0x60a, 11 },{ 0x65f, 11 },{ 0x410, 11 },{ 0x65d, 11 }, -{ 0x65e, 11 },{ 0xcb8, 12 },{ 0xc10, 12 },{ 0xcb9, 12 }, -{ 0x1823, 13 },{ 0x3045, 14 },{ 0x6089, 15 },{ 0xc110, 16 }, -{ 0x304448, 22 },{ 0x304449, 22 },{ 0x30444a, 22 },{ 0x30444b, 22 }, -{ 0x30444c, 22 },{ 0x30444d, 22 },{ 0x30444e, 22 },{ 0x30444f, 22 }, -{ 0x304450, 22 },{ 0x304451, 22 },{ 0x304452, 22 },{ 0x304453, 22 }, -{ 0x304454, 22 },{ 0x304455, 22 },{ 0x304456, 22 },{ 0x304457, 22 }, -{ 0x304458, 22 },{ 0x304459, 22 },{ 0x30445a, 22 },{ 0x30445b, 22 }, -{ 0x30445c, 22 },{ 0x30445d, 22 },{ 0x30445e, 22 },{ 0x30445f, 22 }, -{ 0x304460, 22 },{ 0x304461, 22 },{ 0x304462, 22 },{ 0x304463, 22 }, -{ 0x304464, 22 },{ 0x304465, 22 },{ 0x304466, 22 },{ 0x304467, 22 }, -{ 0x304468, 22 },{ 0x304469, 22 },{ 0x30446a, 22 },{ 0x30446b, 22 }, -{ 0x30446c, 22 },{ 0x30446d, 22 },{ 0x30446e, 22 },{ 0x30446f, 22 }, -{ 0x304470, 22 },{ 0x304471, 22 },{ 0x304472, 22 },{ 0x304473, 22 }, -{ 0x304474, 22 },{ 0x304475, 22 },{ 0x304476, 22 },{ 0x304477, 22 }, -{ 0x304478, 22 },{ 0x304479, 22 },{ 0x30447a, 22 },{ 0x30447b, 22 }, -{ 0x30447c, 22 },{ 0x30447d, 22 },{ 0x30447e, 22 },{ 0x30447f, 22 }, -{ 0x608880, 23 },{ 0x608881, 23 },{ 0x608882, 23 },{ 0x608883, 23 }, -{ 0x608884, 23 },{ 0x608885, 23 },{ 0x608886, 23 },{ 0x608887, 23 }, -{ 0x608888, 23 },{ 0x608889, 23 },{ 0x60888a, 23 },{ 0x60888b, 23 }, -{ 0x60888c, 23 },{ 0x60888d, 23 },{ 0x60888e, 23 },{ 0x60888f, 23 }, -}; - -/* dc table 1 */ - -const uint32_t ff_table1_dc_lum[120][2] = { -{ 0x2, 2 },{ 0x3, 2 },{ 0x3, 3 },{ 0x2, 4 }, -{ 0x5, 4 },{ 0x1, 5 },{ 0x3, 5 },{ 0x8, 5 }, -{ 0x0, 6 },{ 0x5, 6 },{ 0xd, 6 },{ 0xf, 6 }, -{ 0x13, 6 },{ 0x8, 7 },{ 0x18, 7 },{ 0x1c, 7 }, -{ 0x24, 7 },{ 0x4, 8 },{ 0x6, 8 },{ 0x12, 8 }, -{ 0x32, 8 },{ 0x3b, 8 },{ 0x4a, 8 },{ 0x4b, 8 }, -{ 0xb, 9 },{ 0x26, 9 },{ 0x27, 9 },{ 0x66, 9 }, -{ 0x74, 9 },{ 0x75, 9 },{ 0x14, 10 },{ 0x1c, 10 }, -{ 0x1f, 10 },{ 0x1d, 10 },{ 0x2b, 11 },{ 0x3d, 11 }, -{ 0x19d, 11 },{ 0x19f, 11 },{ 0x54, 12 },{ 0x339, 12 }, -{ 0x338, 12 },{ 0x33d, 12 },{ 0xab, 13 },{ 0xf1, 13 }, -{ 0x678, 13 },{ 0xf2, 13 },{ 0x1e0, 14 },{ 0x1e1, 14 }, -{ 0x154, 14 },{ 0xcf2, 14 },{ 0x3cc, 15 },{ 0x2ab, 15 }, -{ 0x19e7, 15 },{ 0x3ce, 15 },{ 0x19e6, 15 },{ 0x554, 16 }, -{ 0x79f, 16 },{ 0x555, 16 },{ 0xf3d, 17 },{ 0xf37, 17 }, -{ 0xf3c, 17 },{ 0xf35, 17 },{ 0x1e6d, 18 },{ 0x1e68, 18 }, -{ 0x3cd8, 19 },{ 0x3cd3, 19 },{ 0x3cd9, 19 },{ 0x79a4, 20 }, -{ 0xf34ba, 25 },{ 0xf34b4, 25 },{ 0xf34b5, 25 },{ 0xf34b6, 25 }, -{ 0xf34b7, 25 },{ 0xf34b8, 25 },{ 0xf34b9, 25 },{ 0xf34bb, 25 }, -{ 0xf34bc, 25 },{ 0xf34bd, 25 },{ 0xf34be, 25 },{ 0xf34bf, 25 }, -{ 0x1e6940, 26 },{ 0x1e6941, 26 },{ 0x1e6942, 26 },{ 0x1e6943, 26 }, -{ 0x1e6944, 26 },{ 0x1e6945, 26 },{ 0x1e6946, 26 },{ 0x1e6947, 26 }, -{ 0x1e6948, 26 },{ 0x1e6949, 26 },{ 0x1e694a, 26 },{ 0x1e694b, 26 }, -{ 0x1e694c, 26 },{ 0x1e694d, 26 },{ 0x1e694e, 26 },{ 0x1e694f, 26 }, -{ 0x1e6950, 26 },{ 0x1e6951, 26 },{ 0x1e6952, 26 },{ 0x1e6953, 26 }, -{ 0x1e6954, 26 },{ 0x1e6955, 26 },{ 0x1e6956, 26 },{ 0x1e6957, 26 }, -{ 0x1e6958, 26 },{ 0x1e6959, 26 },{ 0x1e695a, 26 },{ 0x1e695b, 26 }, -{ 0x1e695c, 26 },{ 0x1e695d, 26 },{ 0x1e695e, 26 },{ 0x1e695f, 26 }, -{ 0x1e6960, 26 },{ 0x1e6961, 26 },{ 0x1e6962, 26 },{ 0x1e6963, 26 }, -{ 0x1e6964, 26 },{ 0x1e6965, 26 },{ 0x1e6966, 26 },{ 0x1e6967, 26 }, -}; - -const uint32_t ff_table1_dc_chroma[120][2] = { -{ 0x0, 2 },{ 0x1, 2 },{ 0x4, 3 },{ 0x7, 3 }, -{ 0xb, 4 },{ 0xd, 4 },{ 0x15, 5 },{ 0x28, 6 }, -{ 0x30, 6 },{ 0x32, 6 },{ 0x52, 7 },{ 0x62, 7 }, -{ 0x66, 7 },{ 0xa6, 8 },{ 0xc6, 8 },{ 0xcf, 8 }, -{ 0x14f, 9 },{ 0x18e, 9 },{ 0x19c, 9 },{ 0x29d, 10 }, -{ 0x33a, 10 },{ 0x538, 11 },{ 0x63c, 11 },{ 0x63e, 11 }, -{ 0x63f, 11 },{ 0x676, 11 },{ 0xa73, 12 },{ 0xc7a, 12 }, -{ 0xcef, 12 },{ 0x14e5, 13 },{ 0x19dd, 13 },{ 0x29c8, 14 }, -{ 0x29c9, 14 },{ 0x63dd, 15 },{ 0x33b8, 14 },{ 0x33b9, 14 }, -{ 0xc7b6, 16 },{ 0x63d8, 15 },{ 0x63df, 15 },{ 0xc7b3, 16 }, -{ 0xc7b4, 16 },{ 0xc7b5, 16 },{ 0x63de, 15 },{ 0xc7b7, 16 }, -{ 0xc7b8, 16 },{ 0xc7b9, 16 },{ 0x18f65, 17 },{ 0x31ec8, 18 }, -{ 0xc7b248, 24 },{ 0xc7b249, 24 },{ 0xc7b24a, 24 },{ 0xc7b24b, 24 }, -{ 0xc7b24c, 24 },{ 0xc7b24d, 24 },{ 0xc7b24e, 24 },{ 0xc7b24f, 24 }, -{ 0xc7b250, 24 },{ 0xc7b251, 24 },{ 0xc7b252, 24 },{ 0xc7b253, 24 }, -{ 0xc7b254, 24 },{ 0xc7b255, 24 },{ 0xc7b256, 24 },{ 0xc7b257, 24 }, -{ 0xc7b258, 24 },{ 0xc7b259, 24 },{ 0xc7b25a, 24 },{ 0xc7b25b, 24 }, -{ 0xc7b25c, 24 },{ 0xc7b25d, 24 },{ 0xc7b25e, 24 },{ 0xc7b25f, 24 }, -{ 0xc7b260, 24 },{ 0xc7b261, 24 },{ 0xc7b262, 24 },{ 0xc7b263, 24 }, -{ 0xc7b264, 24 },{ 0xc7b265, 24 },{ 0xc7b266, 24 },{ 0xc7b267, 24 }, -{ 0xc7b268, 24 },{ 0xc7b269, 24 },{ 0xc7b26a, 24 },{ 0xc7b26b, 24 }, -{ 0xc7b26c, 24 },{ 0xc7b26d, 24 },{ 0xc7b26e, 24 },{ 0xc7b26f, 24 }, -{ 0xc7b270, 24 },{ 0xc7b271, 24 },{ 0xc7b272, 24 },{ 0xc7b273, 24 }, -{ 0xc7b274, 24 },{ 0xc7b275, 24 },{ 0xc7b276, 24 },{ 0xc7b277, 24 }, -{ 0xc7b278, 24 },{ 0xc7b279, 24 },{ 0xc7b27a, 24 },{ 0xc7b27b, 24 }, -{ 0xc7b27c, 24 },{ 0xc7b27d, 24 },{ 0xc7b27e, 24 },{ 0xc7b27f, 24 }, -{ 0x18f6480, 25 },{ 0x18f6481, 25 },{ 0x18f6482, 25 },{ 0x18f6483, 25 }, -{ 0x18f6484, 25 },{ 0x18f6485, 25 },{ 0x18f6486, 25 },{ 0x18f6487, 25 }, -{ 0x18f6488, 25 },{ 0x18f6489, 25 },{ 0x18f648a, 25 },{ 0x18f648b, 25 }, -{ 0x18f648c, 25 },{ 0x18f648d, 25 },{ 0x18f648e, 25 },{ 0x18f648f, 25 }, -}; - -/* vlc table 0, for intra luma */ - -static const uint16_t table0_vlc[133][2] = { -{ 0x1, 2 },{ 0x6, 3 },{ 0xf, 4 },{ 0x16, 5 }, -{ 0x20, 6 },{ 0x18, 7 },{ 0x8, 8 },{ 0x9a, 8 }, -{ 0x56, 9 },{ 0x13e, 9 },{ 0xf0, 10 },{ 0x3a5, 10 }, -{ 0x77, 11 },{ 0x1ef, 11 },{ 0x9a, 12 },{ 0x5d, 13 }, -{ 0x1, 4 },{ 0x11, 5 },{ 0x2, 7 },{ 0xb, 8 }, -{ 0x12, 9 },{ 0x1d6, 9 },{ 0x27e, 10 },{ 0x191, 11 }, -{ 0xea, 12 },{ 0x3dc, 12 },{ 0x13b, 13 },{ 0x4, 5 }, -{ 0x14, 7 },{ 0x9e, 8 },{ 0x9, 10 },{ 0x1ac, 11 }, -{ 0x1e2, 11 },{ 0x3ca, 12 },{ 0x5f, 13 },{ 0x17, 5 }, -{ 0x4e, 7 },{ 0x5e, 9 },{ 0xf3, 10 },{ 0x1ad, 11 }, -{ 0xec, 12 },{ 0x5f0, 13 },{ 0xe, 6 },{ 0xe1, 8 }, -{ 0x3a4, 10 },{ 0x9c, 12 },{ 0x13d, 13 },{ 0x3b, 6 }, -{ 0x1c, 9 },{ 0x14, 11 },{ 0x9be, 12 },{ 0x6, 7 }, -{ 0x7a, 9 },{ 0x190, 11 },{ 0x137, 13 },{ 0x1b, 7 }, -{ 0x8, 10 },{ 0x75c, 11 },{ 0x71, 7 },{ 0xd7, 10 }, -{ 0x9bf, 12 },{ 0x7, 8 },{ 0xaf, 10 },{ 0x4cc, 11 }, -{ 0x34, 8 },{ 0x265, 10 },{ 0x9f, 12 },{ 0xe0, 8 }, -{ 0x16, 11 },{ 0x327, 12 },{ 0x15, 9 },{ 0x17d, 11 }, -{ 0xebb, 12 },{ 0x14, 9 },{ 0xf6, 10 },{ 0x1e4, 11 }, -{ 0xcb, 10 },{ 0x99d, 12 },{ 0xca, 10 },{ 0x2fc, 12 }, -{ 0x17f, 11 },{ 0x4cd, 11 },{ 0x2fd, 12 },{ 0x4fe, 11 }, -{ 0x13a, 13 },{ 0xa, 4 },{ 0x42, 7 },{ 0x1d3, 9 }, -{ 0x4dd, 11 },{ 0x12, 5 },{ 0xe8, 8 },{ 0x4c, 11 }, -{ 0x136, 13 },{ 0x39, 6 },{ 0x264, 10 },{ 0xeba, 12 }, -{ 0x0, 7 },{ 0xae, 10 },{ 0x99c, 12 },{ 0x1f, 7 }, -{ 0x4de, 11 },{ 0x43, 7 },{ 0x4dc, 11 },{ 0x3, 8 }, -{ 0x3cb, 12 },{ 0x6, 8 },{ 0x99e, 12 },{ 0x2a, 8 }, -{ 0x5f1, 13 },{ 0xf, 8 },{ 0x9fe, 12 },{ 0x33, 8 }, -{ 0x9ff, 12 },{ 0x98, 8 },{ 0x99f, 12 },{ 0xea, 8 }, -{ 0x13c, 13 },{ 0x2e, 8 },{ 0x192, 11 },{ 0x136, 9 }, -{ 0x6a, 9 },{ 0x15, 11 },{ 0x3af, 10 },{ 0x1e3, 11 }, -{ 0x74, 11 },{ 0xeb, 12 },{ 0x2f9, 12 },{ 0x5c, 13 }, -{ 0xed, 12 },{ 0x3dd, 12 },{ 0x326, 12 },{ 0x5e, 13 }, -{ 0x16, 7 }, -}; - -static const int8_t table0_level[132] = { - 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 14, 15, 16, - 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 1, 2, 3, 4, 5, - 6, 7, 8, 1, 2, 3, 4, 5, - 6, 7, 1, 2, 3, 4, 5, 1, - 2, 3, 4, 1, 2, 3, 4, 1, - 2, 3, 1, 2, 3, 1, 2, 3, - 1, 2, 3, 1, 2, 3, 1, 2, - 3, 1, 2, 3, 1, 2, 1, 2, - 1, 1, 1, 1, 1, 1, 2, 3, - 4, 1, 2, 3, 4, 1, 2, 3, - 1, 2, 3, 1, 2, 1, 2, 1, - 2, 1, 2, 1, 2, 1, 2, 1, - 2, 1, 2, 1, 2, 1, 2, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, -}; - -static const int8_t table0_run[132] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 2, 2, 2, 2, 2, - 2, 2, 2, 3, 3, 3, 3, 3, - 3, 3, 4, 4, 4, 4, 4, 5, - 5, 5, 5, 6, 6, 6, 6, 7, - 7, 7, 8, 8, 8, 9, 9, 9, - 10, 10, 10, 11, 11, 11, 12, 12, - 12, 13, 13, 13, 14, 14, 15, 15, - 16, 17, 18, 19, 20, 0, 0, 0, - 0, 1, 1, 1, 1, 2, 2, 2, - 3, 3, 3, 4, 4, 5, 5, 6, - 6, 7, 7, 8, 8, 9, 9, 10, - 10, 11, 11, 12, 12, 13, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, - 23, 24, 25, 26, -}; - -/* vlc table 1, for intra chroma and P macro blocks */ - -static const uint16_t table1_vlc[149][2] = { -{ 0x4, 3 },{ 0x14, 5 },{ 0x17, 7 },{ 0x7f, 8 }, -{ 0x154, 9 },{ 0x1f2, 10 },{ 0xbf, 11 },{ 0x65, 12 }, -{ 0xaaa, 12 },{ 0x630, 13 },{ 0x1597, 13 },{ 0x3b7, 14 }, -{ 0x2b22, 14 },{ 0xbe6, 15 },{ 0xb, 4 },{ 0x37, 7 }, -{ 0x62, 9 },{ 0x7, 11 },{ 0x166, 12 },{ 0xce, 13 }, -{ 0x1590, 13 },{ 0x5f6, 14 },{ 0xbe7, 15 },{ 0x7, 5 }, -{ 0x6d, 8 },{ 0x3, 11 },{ 0x31f, 12 },{ 0x5f2, 14 }, -{ 0x2, 6 },{ 0x61, 9 },{ 0x55, 12 },{ 0x1df, 14 }, -{ 0x1a, 6 },{ 0x1e, 10 },{ 0xac9, 12 },{ 0x2b23, 14 }, -{ 0x1e, 6 },{ 0x1f, 10 },{ 0xac3, 12 },{ 0x2b2b, 14 }, -{ 0x6, 7 },{ 0x4, 11 },{ 0x2f8, 13 },{ 0x19, 7 }, -{ 0x6, 11 },{ 0x63d, 13 },{ 0x57, 7 },{ 0x182, 11 }, -{ 0x2aa2, 14 },{ 0x4, 8 },{ 0x180, 11 },{ 0x59c, 14 }, -{ 0x7d, 8 },{ 0x164, 12 },{ 0x76d, 15 },{ 0x2, 9 }, -{ 0x18d, 11 },{ 0x1581, 13 },{ 0xad, 8 },{ 0x60, 12 }, -{ 0xc67, 14 },{ 0x1c, 9 },{ 0xee, 13 },{ 0x3, 9 }, -{ 0x2cf, 13 },{ 0xd9, 9 },{ 0x1580, 13 },{ 0x2, 11 }, -{ 0x183, 11 },{ 0x57, 12 },{ 0x61, 12 },{ 0x31, 11 }, -{ 0x66, 12 },{ 0x631, 13 },{ 0x632, 13 },{ 0xac, 13 }, -{ 0x31d, 12 },{ 0x76, 12 },{ 0x3a, 11 },{ 0x165, 12 }, -{ 0xc66, 14 },{ 0x3, 2 },{ 0x54, 7 },{ 0x2ab, 10 }, -{ 0x16, 13 },{ 0x5f7, 14 },{ 0x5, 4 },{ 0xf8, 9 }, -{ 0xaa9, 12 },{ 0x5f, 15 },{ 0x4, 4 },{ 0x1c, 10 }, -{ 0x1550, 13 },{ 0x4, 5 },{ 0x77, 11 },{ 0x76c, 15 }, -{ 0xe, 5 },{ 0xa, 12 },{ 0xc, 5 },{ 0x562, 11 }, -{ 0x4, 6 },{ 0x31c, 12 },{ 0x6, 6 },{ 0xc8, 13 }, -{ 0xd, 6 },{ 0x1da, 13 },{ 0x7, 6 },{ 0xc9, 13 }, -{ 0x1, 7 },{ 0x2e, 14 },{ 0x14, 7 },{ 0x1596, 13 }, -{ 0xa, 7 },{ 0xac2, 12 },{ 0x16, 7 },{ 0x15b, 14 }, -{ 0x15, 7 },{ 0x15a, 14 },{ 0xf, 8 },{ 0x5e, 15 }, -{ 0x7e, 8 },{ 0xab, 8 },{ 0x2d, 9 },{ 0xd8, 9 }, -{ 0xb, 9 },{ 0x14, 10 },{ 0x2b3, 10 },{ 0x1f3, 10 }, -{ 0x3a, 10 },{ 0x0, 10 },{ 0x58, 10 },{ 0x2e, 9 }, -{ 0x5e, 10 },{ 0x563, 11 },{ 0xec, 12 },{ 0x54, 12 }, -{ 0xac1, 12 },{ 0x1556, 13 },{ 0x2fa, 13 },{ 0x181, 11 }, -{ 0x1557, 13 },{ 0x59d, 14 },{ 0x2aa3, 14 },{ 0x2b2a, 14 }, -{ 0x1de, 14 },{ 0x63c, 13 },{ 0xcf, 13 },{ 0x1594, 13 }, -{ 0xd, 9 }, -}; - -static const int8_t table1_level[148] = { - 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 14, 1, 2, - 3, 4, 5, 6, 7, 8, 9, 1, - 2, 3, 4, 5, 1, 2, 3, 4, - 1, 2, 3, 4, 1, 2, 3, 4, - 1, 2, 3, 1, 2, 3, 1, 2, - 3, 1, 2, 3, 1, 2, 3, 1, - 2, 3, 1, 2, 3, 1, 2, 1, - 2, 1, 2, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 2, 3, 4, 5, 1, 2, - 3, 4, 1, 2, 3, 1, 2, 3, - 1, 2, 1, 2, 1, 2, 1, 2, - 1, 2, 1, 2, 1, 2, 1, 2, - 1, 2, 1, 2, 1, 2, 1, 2, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, -}; - -static const int8_t table1_run[148] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 2, - 2, 2, 2, 2, 3, 3, 3, 3, - 4, 4, 4, 4, 5, 5, 5, 5, - 6, 6, 6, 7, 7, 7, 8, 8, - 8, 9, 9, 9, 10, 10, 10, 11, - 11, 11, 12, 12, 12, 13, 13, 14, - 14, 15, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, - 29, 0, 0, 0, 0, 0, 1, 1, - 1, 1, 2, 2, 2, 3, 3, 3, - 4, 4, 5, 5, 6, 6, 7, 7, - 8, 8, 9, 9, 10, 10, 11, 11, - 12, 12, 13, 13, 14, 14, 15, 15, - 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, -}; - -/* third vlc table */ - -static const uint16_t table2_vlc[186][2] = { -{ 0x1, 2 },{ 0x5, 3 },{ 0xd, 4 },{ 0x12, 5 }, -{ 0xe, 6 },{ 0x15, 7 },{ 0x13, 8 },{ 0x3f, 8 }, -{ 0x4b, 9 },{ 0x11f, 9 },{ 0xb8, 10 },{ 0x3e3, 10 }, -{ 0x172, 11 },{ 0x24d, 12 },{ 0x3da, 12 },{ 0x2dd, 13 }, -{ 0x1f55, 13 },{ 0x5b9, 14 },{ 0x3eae, 14 },{ 0x0, 4 }, -{ 0x10, 5 },{ 0x8, 7 },{ 0x20, 8 },{ 0x29, 9 }, -{ 0x1f4, 9 },{ 0x233, 10 },{ 0x1e0, 11 },{ 0x12a, 12 }, -{ 0x3dd, 12 },{ 0x50a, 13 },{ 0x1f29, 13 },{ 0xa42, 14 }, -{ 0x1272, 15 },{ 0x1737, 15 },{ 0x3, 5 },{ 0x11, 7 }, -{ 0xc4, 8 },{ 0x4b, 10 },{ 0xb4, 11 },{ 0x7d4, 11 }, -{ 0x345, 12 },{ 0x2d7, 13 },{ 0x7bf, 13 },{ 0x938, 14 }, -{ 0xbbb, 14 },{ 0x95e, 15 },{ 0x13, 5 },{ 0x78, 7 }, -{ 0x69, 9 },{ 0x232, 10 },{ 0x461, 11 },{ 0x3ec, 12 }, -{ 0x520, 13 },{ 0x1f2a, 13 },{ 0x3e50, 14 },{ 0x3e51, 14 }, -{ 0x1486, 15 },{ 0xc, 6 },{ 0x24, 9 },{ 0x94, 11 }, -{ 0x8c0, 12 },{ 0xf09, 14 },{ 0x1ef0, 15 },{ 0x3d, 6 }, -{ 0x53, 9 },{ 0x1a0, 11 },{ 0x2d6, 13 },{ 0xf08, 14 }, -{ 0x13, 7 },{ 0x7c, 9 },{ 0x7c1, 11 },{ 0x4ac, 14 }, -{ 0x1b, 7 },{ 0xa0, 10 },{ 0x344, 12 },{ 0xf79, 14 }, -{ 0x79, 7 },{ 0x3e1, 10 },{ 0x2d4, 13 },{ 0x2306, 14 }, -{ 0x21, 8 },{ 0x23c, 10 },{ 0xfae, 12 },{ 0x23de, 14 }, -{ 0x35, 8 },{ 0x175, 11 },{ 0x7b3, 13 },{ 0xc5, 8 }, -{ 0x174, 11 },{ 0x785, 13 },{ 0x48, 9 },{ 0x1a3, 11 }, -{ 0x49e, 13 },{ 0x2c, 9 },{ 0xfa, 10 },{ 0x7d6, 11 }, -{ 0x92, 10 },{ 0x5cc, 13 },{ 0x1ef1, 15 },{ 0xa3, 10 }, -{ 0x3ed, 12 },{ 0x93e, 14 },{ 0x1e2, 11 },{ 0x1273, 15 }, -{ 0x7c4, 11 },{ 0x1487, 15 },{ 0x291, 12 },{ 0x293, 12 }, -{ 0xf8a, 12 },{ 0x509, 13 },{ 0x508, 13 },{ 0x78d, 13 }, -{ 0x7be, 13 },{ 0x78c, 13 },{ 0x4ae, 14 },{ 0xbba, 14 }, -{ 0x2307, 14 },{ 0xb9a, 14 },{ 0x1736, 15 },{ 0xe, 4 }, -{ 0x45, 7 },{ 0x1f3, 9 },{ 0x47a, 11 },{ 0x5dc, 13 }, -{ 0x23df, 14 },{ 0x19, 5 },{ 0x28, 9 },{ 0x176, 11 }, -{ 0x49d, 13 },{ 0x23dd, 14 },{ 0x30, 6 },{ 0xa2, 10 }, -{ 0x2ef, 12 },{ 0x5b8, 14 },{ 0x3f, 6 },{ 0xa5, 10 }, -{ 0x3db, 12 },{ 0x93f, 14 },{ 0x44, 7 },{ 0x7cb, 11 }, -{ 0x95f, 15 },{ 0x63, 7 },{ 0x3c3, 12 },{ 0x15, 8 }, -{ 0x8f6, 12 },{ 0x17, 8 },{ 0x498, 13 },{ 0x2c, 8 }, -{ 0x7b2, 13 },{ 0x2f, 8 },{ 0x1f54, 13 },{ 0x8d, 8 }, -{ 0x7bd, 13 },{ 0x8e, 8 },{ 0x1182, 13 },{ 0xfb, 8 }, -{ 0x50b, 13 },{ 0x2d, 8 },{ 0x7c0, 11 },{ 0x79, 9 }, -{ 0x1f5f, 13 },{ 0x7a, 9 },{ 0x1f56, 13 },{ 0x231, 10 }, -{ 0x3e4, 10 },{ 0x1a1, 11 },{ 0x143, 11 },{ 0x1f7, 11 }, -{ 0x16f, 12 },{ 0x292, 12 },{ 0x2e7, 12 },{ 0x16c, 12 }, -{ 0x16d, 12 },{ 0x3dc, 12 },{ 0xf8b, 12 },{ 0x499, 13 }, -{ 0x3d8, 12 },{ 0x78e, 13 },{ 0x2d5, 13 },{ 0x1f5e, 13 }, -{ 0x1f2b, 13 },{ 0x78f, 13 },{ 0x4ad, 14 },{ 0x3eaf, 14 }, -{ 0x23dc, 14 },{ 0x4a, 9 }, -}; - -static const int8_t table2_level[185] = { - 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 1, 2, 3, 4, 5, - 6, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 1, 2, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 1, 2, - 3, 4, 5, 6, 7, 8, 9, 10, - 11, 1, 2, 3, 4, 5, 6, 1, - 2, 3, 4, 5, 1, 2, 3, 4, - 1, 2, 3, 4, 1, 2, 3, 4, - 1, 2, 3, 4, 1, 2, 3, 1, - 2, 3, 1, 2, 3, 1, 2, 3, - 1, 2, 3, 1, 2, 3, 1, 2, - 1, 2, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 2, 3, 4, 5, 6, 1, 2, 3, - 4, 5, 1, 2, 3, 4, 1, 2, - 3, 4, 1, 2, 3, 1, 2, 1, - 2, 1, 2, 1, 2, 1, 2, 1, - 2, 1, 2, 1, 2, 1, 2, 1, - 2, 1, 2, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, -}; - -static const int8_t table2_run[185] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, - 3, 4, 4, 4, 4, 4, 4, 5, - 5, 5, 5, 5, 6, 6, 6, 6, - 7, 7, 7, 7, 8, 8, 8, 8, - 9, 9, 9, 9, 10, 10, 10, 11, - 11, 11, 12, 12, 12, 13, 13, 13, - 14, 14, 14, 15, 15, 15, 16, 16, - 17, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 27, 28, 29, 30, 0, - 0, 0, 0, 0, 0, 1, 1, 1, - 1, 1, 2, 2, 2, 2, 3, 3, - 3, 3, 4, 4, 4, 5, 5, 6, - 6, 7, 7, 8, 8, 9, 9, 10, - 10, 11, 11, 12, 12, 13, 13, 14, - 14, 15, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, - 29, 30, 31, 32, 33, 34, 35, 36, - 37, -}; - -/* second non intra vlc table */ -static const uint16_t table4_vlc[169][2] = { -{ 0x0, 3 },{ 0x3, 4 },{ 0xb, 5 },{ 0x14, 6 }, -{ 0x3f, 6 },{ 0x5d, 7 },{ 0xa2, 8 },{ 0xac, 9 }, -{ 0x16e, 9 },{ 0x20a, 10 },{ 0x2e2, 10 },{ 0x432, 11 }, -{ 0x5c9, 11 },{ 0x827, 12 },{ 0xb54, 12 },{ 0x4e6, 13 }, -{ 0x105f, 13 },{ 0x172a, 13 },{ 0x20b2, 14 },{ 0x2d4e, 14 }, -{ 0x39f0, 14 },{ 0x4175, 15 },{ 0x5a9e, 15 },{ 0x4, 4 }, -{ 0x1e, 5 },{ 0x42, 7 },{ 0xb6, 8 },{ 0x173, 9 }, -{ 0x395, 10 },{ 0x72e, 11 },{ 0xb94, 12 },{ 0x16a4, 13 }, -{ 0x20b3, 14 },{ 0x2e45, 14 },{ 0x5, 5 },{ 0x40, 7 }, -{ 0x49, 9 },{ 0x28f, 10 },{ 0x5cb, 11 },{ 0x48a, 13 }, -{ 0x9dd, 14 },{ 0x73e2, 15 },{ 0x18, 5 },{ 0x25, 8 }, -{ 0x8a, 10 },{ 0x51b, 11 },{ 0xe5f, 12 },{ 0x9c9, 14 }, -{ 0x139c, 15 },{ 0x29, 6 },{ 0x4f, 9 },{ 0x412, 11 }, -{ 0x48d, 13 },{ 0x2e41, 14 },{ 0x38, 6 },{ 0x10e, 9 }, -{ 0x5a8, 11 },{ 0x105c, 13 },{ 0x39f2, 14 },{ 0x58, 7 }, -{ 0x21f, 10 },{ 0xe7e, 12 },{ 0x39ff, 14 },{ 0x23, 8 }, -{ 0x2e3, 10 },{ 0x4e5, 13 },{ 0x2e40, 14 },{ 0xa1, 8 }, -{ 0x5be, 11 },{ 0x9c8, 14 },{ 0x83, 8 },{ 0x13a, 11 }, -{ 0x1721, 13 },{ 0x44, 9 },{ 0x276, 12 },{ 0x39f6, 14 }, -{ 0x8b, 10 },{ 0x4ef, 13 },{ 0x5a9b, 15 },{ 0x208, 10 }, -{ 0x1cfe, 13 },{ 0x399, 10 },{ 0x1cb4, 13 },{ 0x39e, 10 }, -{ 0x39f3, 14 },{ 0x5ab, 11 },{ 0x73e3, 15 },{ 0x737, 11 }, -{ 0x5a9f, 15 },{ 0x82d, 12 },{ 0xe69, 12 },{ 0xe68, 12 }, -{ 0x433, 11 },{ 0xb7b, 12 },{ 0x2df8, 14 },{ 0x2e56, 14 }, -{ 0x2e57, 14 },{ 0x39f7, 14 },{ 0x51a5, 15 },{ 0x3, 3 }, -{ 0x2a, 6 },{ 0xe4, 8 },{ 0x28e, 10 },{ 0x735, 11 }, -{ 0x1058, 13 },{ 0x1cfa, 13 },{ 0x2df9, 14 },{ 0x4174, 15 }, -{ 0x9, 4 },{ 0x54, 8 },{ 0x398, 10 },{ 0x48b, 13 }, -{ 0x139d, 15 },{ 0xd, 4 },{ 0xad, 9 },{ 0x826, 12 }, -{ 0x2d4c, 14 },{ 0x11, 5 },{ 0x16b, 9 },{ 0xb7f, 12 }, -{ 0x51a4, 15 },{ 0x19, 5 },{ 0x21b, 10 },{ 0x16fd, 13 }, -{ 0x1d, 5 },{ 0x394, 10 },{ 0x28d3, 14 },{ 0x2b, 6 }, -{ 0x5bc, 11 },{ 0x5a9a, 15 },{ 0x2f, 6 },{ 0x247, 12 }, -{ 0x10, 7 },{ 0xa35, 12 },{ 0x3e, 6 },{ 0xb7a, 12 }, -{ 0x59, 7 },{ 0x105e, 13 },{ 0x26, 8 },{ 0x9cf, 14 }, -{ 0x55, 8 },{ 0x1cb5, 13 },{ 0x57, 8 },{ 0xe5b, 12 }, -{ 0xa0, 8 },{ 0x1468, 13 },{ 0x170, 9 },{ 0x90, 10 }, -{ 0x1ce, 9 },{ 0x21a, 10 },{ 0x218, 10 },{ 0x168, 9 }, -{ 0x21e, 10 },{ 0x244, 12 },{ 0x736, 11 },{ 0x138, 11 }, -{ 0x519, 11 },{ 0xe5e, 12 },{ 0x72c, 11 },{ 0xb55, 12 }, -{ 0x9dc, 14 },{ 0x20bb, 14 },{ 0x48c, 13 },{ 0x1723, 13 }, -{ 0x2e44, 14 },{ 0x16a5, 13 },{ 0x518, 11 },{ 0x39fe, 14 }, -{ 0x169, 9 }, -}; - -static const int8_t table4_level[168] = { - 1, 2, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 1, - 2, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 1, 2, 3, 4, 5, 6, - 7, 8, 1, 2, 3, 4, 5, 6, - 7, 1, 2, 3, 4, 5, 1, 2, - 3, 4, 5, 1, 2, 3, 4, 1, - 2, 3, 4, 1, 2, 3, 1, 2, - 3, 1, 2, 3, 1, 2, 3, 1, - 2, 1, 2, 1, 2, 1, 2, 1, - 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 2, 3, 4, 5, - 6, 7, 8, 9, 1, 2, 3, 4, - 5, 1, 2, 3, 4, 1, 2, 3, - 4, 1, 2, 3, 1, 2, 3, 1, - 2, 3, 1, 2, 1, 2, 1, 2, - 1, 2, 1, 2, 1, 2, 1, 2, - 1, 2, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, -}; - -static const int8_t table4_run[168] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, - 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 2, 2, 2, 2, 2, 2, - 2, 2, 3, 3, 3, 3, 3, 3, - 3, 4, 4, 4, 4, 4, 5, 5, - 5, 5, 5, 6, 6, 6, 6, 7, - 7, 7, 7, 8, 8, 8, 9, 9, - 9, 10, 10, 10, 11, 11, 11, 12, - 12, 13, 13, 14, 14, 15, 15, 16, - 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 1, 1, 1, - 1, 2, 2, 2, 2, 3, 3, 3, - 3, 4, 4, 4, 5, 5, 5, 6, - 6, 6, 7, 7, 8, 8, 9, 9, - 10, 10, 11, 11, 12, 12, 13, 13, - 14, 14, 15, 16, 17, 18, 19, 20, - 21, 22, 23, 24, 25, 26, 27, 28, - 29, 30, 31, 32, 33, 34, 35, 36, -}; - -extern const uint16_t inter_vlc[103][2]; -extern const int8_t inter_level[102]; -extern const int8_t inter_run[102]; - -extern const uint16_t intra_vlc[103][2]; -extern const int8_t intra_level[102]; -extern const int8_t intra_run[102]; - -extern const uint8_t DCtab_lum[13][2]; -extern const uint8_t DCtab_chrom[13][2]; - -extern const uint8_t cbpy_tab[16][2]; -extern const uint8_t mvtab[33][2]; - -extern const uint8_t intra_MCBPC_code[9]; -extern const uint8_t intra_MCBPC_bits[9]; - -extern const uint8_t inter_MCBPC_code[28]; -extern const uint8_t inter_MCBPC_bits[28]; - -#define NB_RL_TABLES 6 - -static RLTable rl_table[NB_RL_TABLES] = { - /* intra luminance tables */ - { - 132, - 85, - table0_vlc, - table0_run, - table0_level, - }, - { - 185, - 119, - table2_vlc, - table2_run, - table2_level, - }, - { - 102, - 67, - intra_vlc, - intra_run, - intra_level, - }, - /* intra chrominance / non intra tables */ - { - 148, - 81, - table1_vlc, - table1_run, - table1_level, - }, - { - 168, - 99, - table4_vlc, - table4_run, - table4_level, - }, - { - 102, - 58, - inter_vlc, - inter_run, - inter_level, - }, -}; - -/* motion vector table 0 */ - -static const uint16_t table0_mv_code[1100] = { - 0x0001, 0x0003, 0x0005, 0x0007, 0x0003, 0x0008, 0x000c, 0x0001, - 0x0002, 0x001b, 0x0006, 0x000b, 0x0015, 0x0002, 0x000e, 0x000f, - 0x0014, 0x0020, 0x0022, 0x0025, 0x0027, 0x0029, 0x002d, 0x004b, - 0x004d, 0x0003, 0x0022, 0x0023, 0x0025, 0x0027, 0x0042, 0x0048, - 0x0049, 0x0050, 0x005c, 0x0091, 0x009f, 0x000e, 0x0043, 0x004c, - 0x0054, 0x0056, 0x008c, 0x0098, 0x009a, 0x009b, 0x00b1, 0x00b2, - 0x0120, 0x0121, 0x0126, 0x0133, 0x0139, 0x01a1, 0x01a4, 0x01a5, - 0x01a6, 0x01a7, 0x01ae, 0x01af, 0x000b, 0x0019, 0x0085, 0x0090, - 0x009b, 0x00aa, 0x00af, 0x010c, 0x010e, 0x011c, 0x011e, 0x0133, - 0x0144, 0x0160, 0x0174, 0x0175, 0x0177, 0x0178, 0x0249, 0x024b, - 0x0252, 0x0261, 0x0265, 0x0270, 0x0352, 0x0353, 0x0355, 0x0359, - 0x0010, 0x0011, 0x0013, 0x0034, 0x0035, 0x0036, 0x0037, 0x003d, - 0x003e, 0x0109, 0x0126, 0x0156, 0x021a, 0x021e, 0x023a, 0x023e, - 0x028e, 0x028f, 0x02cf, 0x0491, 0x0494, 0x049f, 0x04a0, 0x04a3, - 0x04a6, 0x04a7, 0x04ad, 0x04ae, 0x04c0, 0x04c4, 0x04c6, 0x04c8, - 0x04c9, 0x04f5, 0x04f6, 0x04f7, 0x0680, 0x0682, 0x0683, 0x0688, - 0x0689, 0x068d, 0x068e, 0x068f, 0x06a2, 0x06a3, 0x06a9, 0x06b0, - 0x06b1, 0x06b4, 0x06b5, 0x0024, 0x0060, 0x0063, 0x0078, 0x0079, - 0x0211, 0x0244, 0x0245, 0x0247, 0x0248, 0x0249, 0x024a, 0x024b, - 0x026b, 0x02af, 0x02b8, 0x02bb, 0x0436, 0x0476, 0x0477, 0x047e, - 0x04c8, 0x04c9, 0x04ca, 0x0514, 0x0586, 0x0587, 0x0598, 0x059d, - 0x05d9, 0x05da, 0x0920, 0x0921, 0x093b, 0x093c, 0x093d, 0x0942, - 0x0943, 0x0944, 0x0945, 0x0959, 0x095e, 0x095f, 0x0982, 0x0983, - 0x098e, 0x098f, 0x09c4, 0x09e7, 0x09e8, 0x09e9, 0x0d02, 0x0d17, - 0x0d18, 0x0d19, 0x0d41, 0x0d42, 0x0d43, 0x0d50, 0x0d5f, 0x0d6d, - 0x0d6e, 0x0d6f, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, - 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x041e, 0x041f, 0x0420, 0x0421, - 0x048c, 0x048d, 0x04d3, 0x04d4, 0x04d5, 0x055c, 0x055d, 0x0572, - 0x0573, 0x0574, 0x0575, 0x08de, 0x08df, 0x08fe, 0x08ff, 0x0996, - 0x0a36, 0x0a37, 0x0b08, 0x0b09, 0x0b0a, 0x0b0b, 0x0b32, 0x0b33, - 0x0b34, 0x0b35, 0x0b36, 0x0b37, 0x0b38, 0x0b39, 0x0bb0, 0x0bf7, - 0x0bf8, 0x0bf9, 0x0bfa, 0x0bfb, 0x0bfc, 0x0bfd, 0x0bfe, 0x0bff, - 0x1254, 0x1255, 0x1256, 0x1257, 0x1270, 0x1271, 0x1272, 0x1273, - 0x1274, 0x1275, 0x12ab, 0x12ac, 0x12ad, 0x12ae, 0x12af, 0x12b0, - 0x12b1, 0x1315, 0x1316, 0x1317, 0x13bf, 0x13c0, 0x13c1, 0x13c2, - 0x13c3, 0x13c4, 0x13c5, 0x13c6, 0x13c7, 0x13c8, 0x13c9, 0x13ca, - 0x13cb, 0x13cc, 0x13cd, 0x1a06, 0x1a07, 0x1a28, 0x1a29, 0x1a2a, - 0x1a2b, 0x1a2c, 0x1a2d, 0x1a80, 0x1abb, 0x1abc, 0x1abd, 0x1ad8, - 0x1ad9, 0x0094, 0x0095, 0x0096, 0x0097, 0x00a0, 0x00a1, 0x00a2, - 0x00a3, 0x0831, 0x0832, 0x0833, 0x0834, 0x0835, 0x0836, 0x0837, - 0x0838, 0x0839, 0x083a, 0x083b, 0x0939, 0x093a, 0x093b, 0x093c, - 0x093d, 0x093e, 0x093f, 0x09a0, 0x09a1, 0x09a2, 0x09a3, 0x09a4, - 0x09a5, 0x11ac, 0x11ad, 0x11ae, 0x11af, 0x11b0, 0x11b1, 0x11b2, - 0x11b3, 0x11b4, 0x11b5, 0x11b6, 0x11b7, 0x11b8, 0x11b9, 0x11ba, - 0x11bb, 0x132f, 0x1454, 0x1455, 0x1456, 0x1457, 0x1458, 0x1459, - 0x145a, 0x145b, 0x145c, 0x145d, 0x145e, 0x145f, 0x1460, 0x1461, - 0x1462, 0x1463, 0x1464, 0x1465, 0x1466, 0x1467, 0x1468, 0x1469, - 0x146a, 0x146b, 0x17de, 0x17df, 0x17e0, 0x17e1, 0x17e2, 0x17e3, - 0x17e4, 0x17e5, 0x17e6, 0x17e7, 0x17e8, 0x17e9, 0x17ea, 0x17eb, - 0x17ec, 0x17ed, 0x2540, 0x2541, 0x2542, 0x2543, 0x2544, 0x2545, - 0x2546, 0x2547, 0x2548, 0x2549, 0x254a, 0x254b, 0x254c, 0x254d, - 0x254e, 0x254f, 0x2550, 0x2551, 0x2552, 0x2553, 0x2554, 0x2555, - 0x2628, 0x2766, 0x2767, 0x2768, 0x2769, 0x276a, 0x276b, 0x276c, - 0x276d, 0x276e, 0x276f, 0x2770, 0x2771, 0x2772, 0x2773, 0x2774, - 0x2775, 0x2776, 0x2777, 0x2778, 0x2779, 0x277a, 0x277b, 0x277c, - 0x277d, 0x3503, 0x3544, 0x3545, 0x3546, 0x3547, 0x3560, 0x3561, - 0x3562, 0x3563, 0x3564, 0x3565, 0x3566, 0x3567, 0x3568, 0x3569, - 0x356a, 0x356b, 0x356c, 0x356d, 0x356e, 0x356f, 0x3570, 0x3571, - 0x3572, 0x3573, 0x3574, 0x3575, 0x03f0, 0x103d, 0x103e, 0x103f, - 0x1040, 0x1041, 0x1042, 0x1043, 0x1044, 0x1045, 0x1046, 0x1047, - 0x1048, 0x1049, 0x104a, 0x104b, 0x104c, 0x104d, 0x104e, 0x104f, - 0x1050, 0x1051, 0x1052, 0x1053, 0x1054, 0x1055, 0x1056, 0x1057, - 0x1058, 0x1059, 0x105a, 0x105b, 0x105c, 0x105d, 0x105e, 0x105f, - 0x1060, 0x1061, 0x1270, 0x1271, 0x21b8, 0x21b9, 0x21ba, 0x21bb, - 0x21bc, 0x21bd, 0x21be, 0x21bf, 0x21f0, 0x21f1, 0x21f2, 0x21f3, - 0x21f4, 0x21f5, 0x21f6, 0x21f7, 0x21f8, 0x21f9, 0x21fa, 0x21fb, - 0x21fc, 0x21fd, 0x21fe, 0x21ff, 0x2340, 0x2341, 0x2342, 0x2343, - 0x2344, 0x2345, 0x2346, 0x2347, 0x2348, 0x2349, 0x234a, 0x234b, - 0x234c, 0x234d, 0x234e, 0x234f, 0x2350, 0x2351, 0x2352, 0x2353, - 0x2354, 0x2355, 0x2356, 0x2357, 0x265c, 0x2f88, 0x2f89, 0x2f8a, - 0x2f8b, 0x2f8c, 0x2f8d, 0x2f8e, 0x2f8f, 0x2f90, 0x2f91, 0x2f92, - 0x2f93, 0x2f94, 0x2f95, 0x2f96, 0x2f97, 0x2f98, 0x2f99, 0x2f9a, - 0x2f9b, 0x2f9c, 0x2f9d, 0x2f9e, 0x2f9f, 0x2fa0, 0x2fa1, 0x2fa2, - 0x2fa3, 0x2fa4, 0x2fa5, 0x2fa6, 0x2fa7, 0x2fa8, 0x2fa9, 0x2faa, - 0x2fab, 0x2fac, 0x2fad, 0x2fae, 0x2faf, 0x2fb0, 0x2fb1, 0x2fb2, - 0x2fb3, 0x2fb4, 0x2fb5, 0x2fb6, 0x2fb7, 0x2fb8, 0x2fb9, 0x2fba, - 0x2fbb, 0x4c52, 0x4c53, 0x4e28, 0x4e29, 0x4e2a, 0x4e2b, 0x4e2c, - 0x4e2d, 0x4e2e, 0x4e2f, 0x4e30, 0x4e31, 0x4e32, 0x4e33, 0x4e34, - 0x4e35, 0x4e36, 0x4e37, 0x4e38, 0x4e39, 0x4e3a, 0x4e3b, 0x4e3c, - 0x4e3d, 0x4e3e, 0x4e3f, 0x4e80, 0x4e81, 0x4e82, 0x4e83, 0x4e84, - 0x4e85, 0x4e86, 0x4e87, 0x4e88, 0x4e89, 0x4e8a, 0x4e8b, 0x4e8c, - 0x4e8d, 0x4e8e, 0x4e8f, 0x4e90, 0x4e91, 0x4e92, 0x4e93, 0x4e94, - 0x4e95, 0x4e96, 0x4e97, 0x4e98, 0x4e99, 0x4e9a, 0x4e9b, 0x4e9c, - 0x4e9d, 0x4e9e, 0x4e9f, 0x4ea0, 0x4ea1, 0x4ea2, 0x4ea3, 0x4ea4, - 0x4ea5, 0x4ea6, 0x4ea7, 0x4ea8, 0x4ea9, 0x4eaa, 0x4eab, 0x4eac, - 0x4ead, 0x4eae, 0x4eaf, 0x4eb0, 0x4eb1, 0x4eb2, 0x4eb3, 0x4eb4, - 0x4eb5, 0x4eb6, 0x4eb7, 0x4eb8, 0x4eb9, 0x4eba, 0x4ebb, 0x4ebc, - 0x4ebd, 0x4ebe, 0x4ebf, 0x4ec0, 0x4ec1, 0x4ec2, 0x4ec3, 0x4ec4, - 0x4ec5, 0x4ec6, 0x4ec7, 0x4ec8, 0x4ec9, 0x4eca, 0x4ecb, 0x6a04, - 0x6a05, 0x07e2, 0x07e3, 0x07e4, 0x07e5, 0x07e6, 0x07e7, 0x07e8, - 0x07e9, 0x07ea, 0x07eb, 0x07ec, 0x07ed, 0x07ee, 0x07ef, 0x07f0, - 0x07f1, 0x07f2, 0x07f3, 0x07f4, 0x07f5, 0x07f6, 0x07f7, 0x07f8, - 0x07f9, 0x07fa, 0x07fb, 0x07fc, 0x07fd, 0x07fe, 0x07ff, 0x2000, - 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, - 0x2009, 0x200a, 0x200b, 0x200c, 0x200d, 0x200e, 0x200f, 0x2010, - 0x2011, 0x2012, 0x2013, 0x2014, 0x2015, 0x2016, 0x2017, 0x2018, - 0x2019, 0x201a, 0x201b, 0x201c, 0x201d, 0x201e, 0x201f, 0x2020, - 0x2021, 0x2022, 0x2023, 0x2024, 0x2025, 0x2026, 0x2027, 0x2028, - 0x2029, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e, 0x202f, 0x2030, - 0x2031, 0x2032, 0x2033, 0x2034, 0x2035, 0x2036, 0x2037, 0x2038, - 0x2039, 0x203a, 0x203b, 0x203c, 0x203d, 0x203e, 0x203f, 0x2040, - 0x2041, 0x2042, 0x2043, 0x2044, 0x2045, 0x2046, 0x2047, 0x2048, - 0x2049, 0x204a, 0x204b, 0x204c, 0x204d, 0x204e, 0x204f, 0x2050, - 0x2051, 0x2052, 0x2053, 0x2054, 0x2055, 0x2056, 0x2057, 0x2058, - 0x2059, 0x205a, 0x205b, 0x205c, 0x205d, 0x205e, 0x205f, 0x2060, - 0x2061, 0x2062, 0x2063, 0x2064, 0x2065, 0x2066, 0x2067, 0x2068, - 0x2069, 0x206a, 0x206b, 0x206c, 0x206d, 0x206e, 0x206f, 0x2070, - 0x2071, 0x2072, 0x2073, 0x2074, 0x2075, 0x2076, 0x2077, 0x2078, - 0x2079, 0x4cba, 0x4cbb, 0x5d88, 0x5d89, 0x5d8a, 0x5d8b, 0x5d8c, - 0x5d8d, 0x5d8e, 0x5d8f, 0x5db0, 0x5db1, 0x5db2, 0x5db3, 0x5db4, - 0x5db5, 0x5db6, 0x5db7, 0x5db8, 0x5db9, 0x5dba, 0x5dbb, 0x5dbc, - 0x5dbd, 0x5dbe, 0x5dbf, 0x5e40, 0x5e41, 0x5e42, 0x5e43, 0x5e44, - 0x5e45, 0x5e46, 0x5e47, 0x5e48, 0x5e49, 0x5e4a, 0x5e4b, 0x5e4c, - 0x5e4d, 0x5e4e, 0x5e4f, 0x5e50, 0x5e51, 0x5e52, 0x5e53, 0x5e54, - 0x5e55, 0x5e56, 0x5e57, 0x5e58, 0x5e59, 0x5e5a, 0x5e5b, 0x5e5c, - 0x5e5d, 0x5e5e, 0x5e5f, 0x5e60, 0x5e61, 0x5e62, 0x5e63, 0x5e64, - 0x5e65, 0x5e66, 0x5e67, 0x5e68, 0x5e69, 0x5e6a, 0x5e6b, 0x5e6c, - 0x5e6d, 0x5e6e, 0x5e6f, 0x5e70, 0x5e71, 0x5e72, 0x5e73, 0x5e74, - 0x5e75, 0x5e76, 0x5e77, 0x5e78, 0x5e79, 0x5e7a, 0x5e7b, 0x5e7c, - 0x5e7d, 0x5e7e, 0x5e7f, 0x5e80, 0x5e81, 0x5e82, 0x5e83, 0x5e84, - 0x5e85, 0x5e86, 0x5e87, 0x5e88, 0x5e89, 0x5e8a, 0x5e8b, 0x5e8c, - 0x5e8d, 0x5e8e, 0x5e8f, 0x5e90, 0x5e91, 0x5e92, 0x5e93, 0x5e94, - 0x5e95, 0x5e96, 0x5e97, 0x5e98, 0x5e99, 0x5e9a, 0x5e9b, 0x5e9c, - 0x5e9d, 0x5e9e, 0x5e9f, 0x5ea0, 0x5ea1, 0x5ea2, 0x5ea3, 0x5ea4, - 0x5ea5, 0x5ea6, 0x5ea7, 0x5ea8, 0x5ea9, 0x5eaa, 0x5eab, 0x5eac, - 0x5ead, 0x5eae, 0x5eaf, 0x5eb0, 0x5eb1, 0x5eb2, 0x5eb3, 0x5eb4, - 0x5eb5, 0x5eb6, 0x5eb7, 0x5eb8, 0x5eb9, 0x5eba, 0x5ebb, 0x5ebc, - 0x5ebd, 0x5ebe, 0x5ebf, 0x5ec0, 0x5ec1, 0x5ec2, 0x5ec3, 0x5ec4, - 0x5ec5, 0x5ec6, 0x5ec7, 0x5ec8, 0x5ec9, 0x5eca, 0x5ecb, 0x5ecc, - 0x5ecd, 0x5ece, 0x5ecf, 0x5ed0, 0x5ed1, 0x5ed2, 0x5ed3, 0x5ed4, - 0x5ed5, 0x5ed6, 0x5ed7, 0x5ed8, 0x5ed9, 0x5eda, 0x5edb, 0x5edc, - 0x5edd, 0x5ede, 0x5edf, 0x5ee0, 0x5ee1, 0x5ee2, 0x5ee3, 0x5ee4, - 0x5ee5, 0x5ee6, 0x5ee7, 0x5ee8, 0x5ee9, 0x5eea, 0x5eeb, 0x5eec, - 0x5eed, 0x5eee, 0x5eef, 0x5ef0, 0x5ef1, 0x5ef2, 0x5ef3, 0x5ef4, - 0x5ef5, 0x5ef6, 0x5ef7, 0x5ef8, 0x5ef9, 0x5efa, 0x5efb, 0x5efc, - 0x5efd, 0x5efe, 0x5eff, 0x5f00, 0x5f01, 0x5f02, 0x5f03, 0x5f04, - 0x5f05, 0x5f06, 0x5f07, 0x5f08, 0x5f09, 0x5f0a, 0x5f0b, 0x5f0c, - 0x5f0d, 0x5f0e, 0x5f0f, 0x0000, -}; - -static const uint8_t table0_mv_bits[1100] = { - 1, 4, 4, 4, 5, 5, 5, 6, - 6, 6, 7, 7, 7, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, - 8, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 16, 16, 16, 16, 16, 16, 16, - 16, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 17, 17, 17, 17, 17, - 17, 17, 17, 8, -}; - -static const uint8_t table0_mvx[1099] = { - 32, 32, 31, 32, 33, 31, 33, 31, - 33, 32, 34, 32, 30, 32, 31, 34, - 35, 32, 34, 33, 29, 33, 30, 30, - 31, 31, 35, 29, 33, 35, 33, 34, - 31, 29, 30, 34, 30, 36, 28, 32, - 34, 37, 30, 27, 32, 25, 39, 32, - 34, 32, 35, 35, 35, 31, 35, 29, - 32, 29, 30, 29, 37, 27, 36, 38, - 37, 33, 32, 31, 29, 31, 28, 36, - 33, 30, 34, 33, 33, 28, 27, 25, - 31, 26, 39, 32, 32, 31, 33, 39, - 31, 38, 28, 36, 21, 23, 43, 36, - 34, 41, 30, 25, 28, 31, 30, 34, - 38, 35, 61, 34, 28, 30, 37, 37, - 35, 27, 36, 3, 59, 38, 37, 32, - 31, 29, 26, 33, 37, 33, 27, 27, - 35, 34, 34, 40, 42, 33, 32, 29, - 4, 5, 28, 24, 25, 35, 39, 38, - 32, 23, 27, 32, 30, 35, 26, 34, - 60, 36, 29, 22, 26, 41, 7, 30, - 38, 30, 36, 29, 30, 41, 26, 25, - 32, 34, 24, 39, 1, 25, 39, 32, - 28, 29, 32, 38, 26, 36, 28, 63, - 28, 39, 23, 21, 26, 35, 31, 35, - 57, 31, 29, 29, 28, 30, 27, 35, - 2, 38, 40, 34, 37, 29, 38, 43, - 26, 32, 33, 42, 24, 40, 28, 32, - 32, 32, 36, 32, 43, 25, 21, 31, - 30, 31, 41, 29, 33, 37, 26, 37, - 27, 59, 23, 33, 35, 31, 31, 37, - 38, 39, 32, 23, 32, 27, 37, 36, - 31, 40, 25, 27, 38, 31, 36, 28, - 31, 36, 25, 45, 3, 34, 38, 39, - 40, 38, 30, 32, 19, 24, 25, 26, - 45, 20, 24, 33, 33, 31, 41, 34, - 39, 47, 40, 58, 59, 41, 33, 3, - 17, 61, 42, 30, 26, 29, 36, 61, - 33, 37, 62, 28, 25, 38, 25, 38, - 17, 23, 34, 33, 21, 33, 49, 27, - 32, 23, 27, 22, 24, 22, 39, 43, - 27, 37, 6, 42, 47, 26, 30, 31, - 41, 39, 33, 22, 45, 36, 32, 45, - 19, 22, 30, 5, 5, 17, 29, 22, - 31, 31, 43, 37, 27, 32, 32, 32, - 33, 34, 43, 35, 29, 26, 22, 32, - 19, 32, 25, 31, 41, 49, 28, 34, - 28, 39, 34, 19, 37, 38, 29, 21, - 36, 42, 24, 48, 16, 28, 49, 22, - 34, 31, 38, 39, 44, 11, 35, 30, - 33, 33, 23, 28, 33, 46, 15, 13, - 24, 41, 24, 34, 34, 30, 26, 24, - 14, 60, 21, 29, 39, 23, 35, 37, - 63, 45, 33, 34, 47, 41, 22, 42, - 35, 35, 23, 32, 35, 43, 32, 7, - 31, 41, 20, 31, 16, 13, 63, 25, - 30, 32, 35, 30, 30, 31, 42, 47, - 39, 38, 40, 40, 51, 55, 56, 18, - 21, 39, 39, 33, 17, 41, 23, 24, - 43, 25, 31, 20, 19, 45, 1, 34, - 31, 22, 35, 15, 46, 46, 35, 31, - 28, 29, 29, 23, 41, 27, 14, 53, - 53, 27, 24, 32, 57, 32, 17, 42, - 37, 29, 33, 1, 25, 32, 32, 63, - 26, 40, 44, 36, 31, 39, 20, 20, - 44, 23, 33, 34, 35, 33, 33, 28, - 41, 23, 41, 41, 29, 25, 26, 49, - 29, 24, 37, 49, 50, 51, 51, 26, - 39, 25, 26, 15, 39, 18, 42, 17, - 4, 31, 32, 32, 60, 1, 42, 32, - 0, 12, 19, 35, 21, 41, 17, 26, - 20, 45, 46, 32, 37, 22, 47, 29, - 31, 27, 29, 30, 21, 33, 35, 18, - 25, 33, 50, 51, 42, 2, 15, 51, - 53, 33, 25, 29, 55, 37, 38, 33, - 38, 59, 38, 33, 39, 13, 32, 40, - 61, 61, 32, 9, 44, 3, 31, 29, - 25, 31, 27, 23, 9, 25, 9, 29, - 20, 30, 30, 42, 18, 28, 25, 28, - 28, 21, 29, 43, 29, 43, 26, 44, - 44, 21, 38, 21, 24, 45, 45, 35, - 39, 22, 35, 36, 34, 34, 45, 34, - 29, 31, 46, 25, 46, 16, 17, 31, - 20, 32, 47, 47, 47, 32, 49, 49, - 49, 31, 1, 27, 28, 39, 39, 21, - 36, 23, 51, 2, 40, 51, 32, 53, - 24, 30, 24, 30, 21, 40, 57, 57, - 31, 41, 58, 32, 12, 4, 32, 34, - 59, 31, 32, 13, 9, 35, 26, 35, - 37, 61, 37, 63, 26, 29, 41, 38, - 23, 20, 41, 26, 41, 42, 42, 42, - 26, 26, 26, 26, 1, 26, 37, 37, - 37, 23, 34, 42, 27, 43, 34, 27, - 31, 24, 33, 16, 3, 31, 24, 33, - 24, 4, 44, 44, 11, 44, 31, 13, - 13, 44, 45, 13, 25, 22, 38, 26, - 38, 38, 39, 32, 30, 39, 30, 22, - 32, 26, 30, 47, 47, 47, 19, 47, - 30, 31, 35, 8, 23, 47, 47, 27, - 35, 47, 31, 48, 35, 19, 36, 49, - 49, 33, 31, 39, 27, 39, 49, 49, - 50, 50, 50, 39, 31, 51, 51, 39, - 28, 33, 33, 21, 40, 31, 52, 53, - 40, 53, 9, 33, 31, 53, 54, 54, - 54, 55, 55, 34, 15, 56, 25, 56, - 21, 21, 40, 40, 25, 40, 58, 36, - 5, 41, 41, 12, 60, 41, 41, 37, - 22, 61, 18, 29, 29, 30, 61, 30, - 61, 62, 62, 30, 30, 63, 18, 13, - 30, 23, 19, 20, 20, 41, 13, 2, - 5, 5, 1, 5, 32, 6, 32, 35, - 20, 35, 27, 35, 35, 36, 36, 13, - 36, 41, 41, 41, 3, 30, 42, 27, - 20, 30, 27, 28, 30, 21, 33, 33, - 14, 24, 30, 42, 24, 33, 25, 42, - 43, 14, 43, 43, 14, 43, 7, 36, - 37, 37, 37, 37, 7, 14, 25, 43, - 43, 44, 15, 37, 7, 7, 3, 1, - 8, 15, 15, 8, 44, 44, 44, 45, - 45, 45, 45, 8, 8, 45, 21, 45, - 28, 28, 28, 21, 28, 28, 22, 37, - 46, 46, 37, 8, 29, 37, 29, 22, - 46, 37, 22, 29, 47, 47, 38, 38, - 16, 38, 38, 33, 38, 22, 47, 47, - 29, 25, 16, 0, 48, 1, 34, 48, - 48, 34, 25, 26, 26, 49, 49, 26, - 1, 49, 4, 26, 4, 49, 1, 9, - 49, 49, 49, 10, 49, 17, 38, 17, - 17, 50, 38, 50, 50, 22, 38, 51, - 38, 38, 51, 39, 39, 18, 22, 39, - 51, 22, 52, 52, 52, 39, 53, 53, - 10, 23, 18, 29, 10, 53, 29, 54, - 11, 54, 11, 11, 55, 1, 18, 55, - 55, 55, 55, 55, 55, 29, 34, 18, - 29, 56, 56, 34, 57, 34, 34, 29, - 29, 57, 57, 35, 35, 35, 35, 35, - 39, 35, 59, 59, 18, 59, 39, 30, - 18, 40, 60, 60, 61, 30, 18, 61, - 61, 19, 19, -}; - -static const uint8_t table0_mvy[1099] = { - 32, 31, 32, 33, 32, 31, 31, 33, - 33, 34, 32, 30, 32, 35, 34, 31, - 32, 29, 33, 30, 32, 34, 33, 31, - 30, 35, 31, 31, 29, 33, 35, 30, - 29, 33, 34, 34, 30, 32, 32, 36, - 29, 32, 35, 32, 28, 32, 32, 27, - 35, 37, 34, 29, 30, 36, 35, 34, - 25, 30, 29, 35, 33, 31, 31, 32, - 31, 28, 39, 28, 29, 37, 31, 33, - 27, 36, 28, 36, 37, 33, 33, 31, - 27, 32, 31, 38, 26, 25, 25, 33, - 39, 31, 34, 30, 32, 32, 32, 34, - 36, 32, 28, 33, 30, 38, 37, 27, - 33, 28, 32, 37, 35, 38, 29, 34, - 27, 29, 29, 32, 32, 34, 35, 3, - 26, 36, 31, 38, 30, 26, 35, 34, - 37, 26, 25, 32, 32, 39, 23, 37, - 32, 32, 29, 32, 29, 36, 29, 30, - 41, 31, 30, 21, 39, 25, 34, 38, - 32, 35, 39, 32, 33, 33, 32, 27, - 29, 25, 28, 27, 26, 31, 30, 35, - 24, 24, 31, 34, 32, 30, 35, 40, - 28, 38, 5, 35, 29, 36, 36, 32, - 38, 30, 33, 31, 35, 26, 23, 38, - 32, 41, 28, 25, 37, 40, 37, 39, - 32, 36, 33, 39, 25, 26, 28, 31, - 28, 42, 23, 31, 33, 31, 39, 1, - 59, 22, 27, 4, 33, 34, 33, 24, - 41, 3, 35, 41, 41, 28, 36, 36, - 28, 33, 35, 21, 23, 21, 22, 37, - 27, 27, 43, 29, 60, 39, 27, 25, - 59, 34, 27, 27, 26, 40, 37, 27, - 61, 26, 39, 33, 31, 22, 37, 25, - 30, 25, 24, 61, 31, 34, 25, 38, - 32, 32, 30, 3, 61, 43, 29, 23, - 28, 32, 28, 32, 31, 34, 5, 33, - 32, 33, 33, 42, 37, 23, 38, 31, - 40, 26, 32, 26, 37, 38, 36, 24, - 29, 30, 20, 22, 29, 24, 32, 41, - 2, 34, 25, 33, 29, 31, 39, 35, - 36, 24, 32, 30, 33, 27, 44, 60, - 30, 36, 19, 34, 31, 24, 16, 35, - 32, 38, 21, 33, 31, 31, 21, 35, - 5, 17, 29, 38, 38, 18, 58, 19, - 43, 41, 30, 41, 43, 39, 29, 7, - 29, 17, 28, 19, 28, 31, 25, 19, - 40, 26, 21, 33, 39, 23, 40, 30, - 39, 34, 35, 32, 32, 24, 33, 30, - 40, 47, 39, 37, 32, 33, 24, 23, - 45, 47, 27, 23, 42, 32, 32, 33, - 36, 37, 37, 17, 18, 22, 40, 38, - 32, 31, 35, 24, 17, 25, 17, 23, - 33, 34, 51, 42, 31, 36, 36, 29, - 21, 22, 37, 44, 43, 25, 47, 33, - 45, 27, 31, 58, 31, 32, 31, 38, - 43, 20, 47, 45, 54, 1, 26, 34, - 38, 14, 22, 24, 33, 34, 32, 32, - 37, 21, 23, 49, 35, 23, 28, 39, - 39, 23, 55, 33, 30, 30, 63, 16, - 42, 28, 13, 33, 33, 35, 19, 46, - 43, 17, 19, 36, 39, 24, 31, 32, - 33, 26, 28, 62, 33, 63, 33, 39, - 19, 49, 17, 31, 43, 13, 15, 29, - 25, 35, 33, 23, 49, 41, 28, 29, - 34, 38, 7, 61, 11, 50, 13, 41, - 19, 47, 25, 26, 15, 42, 41, 29, - 45, 27, 17, 35, 32, 29, 32, 24, - 13, 26, 26, 31, 24, 33, 28, 30, - 31, 11, 45, 46, 33, 33, 35, 57, - 32, 32, 35, 45, 34, 11, 37, 42, - 39, 37, 31, 49, 21, 27, 29, 47, - 53, 40, 51, 16, 26, 1, 40, 30, - 41, 44, 34, 25, 27, 31, 35, 35, - 31, 15, 49, 1, 35, 40, 5, 58, - 21, 29, 22, 59, 45, 31, 9, 26, - 9, 29, 11, 32, 30, 3, 13, 20, - 18, 20, 11, 3, 29, 40, 31, 53, - 30, 17, 20, 37, 31, 42, 47, 47, - 54, 38, 9, 34, 13, 37, 21, 25, - 27, 43, 42, 45, 40, 25, 27, 46, - 22, 25, 53, 20, 2, 14, 39, 15, - 22, 44, 34, 21, 38, 33, 27, 48, - 34, 52, 35, 47, 49, 54, 2, 13, - 23, 52, 29, 45, 22, 49, 54, 21, - 40, 42, 31, 30, 29, 34, 0, 25, - 23, 51, 24, 59, 28, 38, 29, 31, - 2, 13, 31, 8, 31, 33, 12, 45, - 41, 7, 14, 30, 25, 18, 43, 20, - 43, 35, 44, 1, 49, 42, 42, 18, - 41, 38, 41, 44, 53, 11, 20, 25, - 45, 46, 47, 48, 39, 52, 46, 49, - 63, 55, 44, 38, 13, 13, 57, 22, - 51, 16, 12, 28, 35, 57, 25, 20, - 26, 28, 28, 29, 32, 31, 62, 34, - 35, 35, 19, 49, 48, 39, 40, 18, - 43, 46, 11, 6, 48, 19, 49, 41, - 10, 23, 58, 17, 21, 23, 34, 30, - 60, 0, 44, 34, 26, 37, 46, 43, - 49, 59, 4, 34, 59, 37, 22, 25, - 28, 46, 6, 40, 59, 42, 36, 61, - 28, 30, 31, 43, 10, 22, 23, 47, - 20, 52, 55, 36, 25, 16, 1, 11, - 27, 29, 5, 63, 18, 41, 31, 34, - 38, 1, 5, 13, 28, 31, 17, 38, - 39, 41, 36, 37, 22, 39, 33, 43, - 43, 15, 17, 49, 30, 21, 22, 20, - 10, 17, 25, 54, 57, 3, 34, 8, - 36, 25, 31, 14, 15, 19, 29, 25, - 18, 39, 53, 22, 27, 20, 29, 33, - 41, 42, 35, 62, 50, 29, 53, 50, - 35, 55, 42, 61, 63, 4, 7, 42, - 21, 46, 47, 49, 27, 46, 17, 55, - 41, 50, 63, 4, 56, 18, 8, 10, - 18, 51, 63, 36, 55, 18, 5, 55, - 9, 29, 17, 21, 30, 27, 1, 59, - 7, 11, 12, 15, 5, 42, 24, 41, - 43, 7, 27, 22, 25, 31, 30, 37, - 22, 39, 53, 29, 36, 37, 48, 0, - 5, 13, 17, 31, 32, 26, 46, 28, - 44, 45, 46, 53, 49, 51, 3, 41, - 3, 22, 42, 33, 5, 45, 7, 22, - 40, 53, 24, 14, 25, 27, 10, 12, - 34, 16, 17, 53, 20, 26, 39, 45, - 18, 45, 35, 33, 31, 49, 4, 39, - 42, 11, 51, 5, 13, 26, 27, 17, - 52, 30, 0, 22, 12, 34, 62, 36, - 38, 41, 47, 30, 63, 38, 41, 43, - 59, 33, 45, 37, 38, 40, 47, 24, - 48, 49, 30, 1, 10, 22, 49, 15, - 39, 59, 31, 32, 33, 18, 13, 15, - 31, 21, 27, 44, 42, 39, 46, 17, - 26, 32, 30, 31, 0, 30, 34, 9, - 12, 13, 25, 31, 32, 55, 43, 35, - 61, 33, 35, 46, 25, 47, 48, 62, - 63, 38, 61, 1, 2, 5, 7, 9, - 46, 10, 34, 35, 36, 55, 51, 7, - 40, 23, 34, 37, 5, 13, 42, 18, - 25, 27, 28, -}; - -/* motion vector table 1 */ -static const uint16_t table1_mv_code[1100] = { - 0x0000, 0x0007, 0x0009, 0x000f, 0x000a, 0x0011, 0x001a, 0x001c, - 0x0011, 0x0031, 0x0025, 0x002d, 0x002f, 0x006f, 0x0075, 0x0041, - 0x004c, 0x004e, 0x005c, 0x0060, 0x0062, 0x0066, 0x0068, 0x0069, - 0x006b, 0x00a6, 0x00c1, 0x00cb, 0x00cc, 0x00ce, 0x00da, 0x00e8, - 0x00ee, 0x0087, 0x0090, 0x009e, 0x009f, 0x00ba, 0x00ca, 0x00d8, - 0x00db, 0x00df, 0x0104, 0x0109, 0x010c, 0x0143, 0x0145, 0x014a, - 0x0156, 0x015c, 0x01b3, 0x01d3, 0x01da, 0x0103, 0x0109, 0x010b, - 0x0122, 0x0127, 0x0134, 0x0161, 0x0164, 0x0176, 0x0184, 0x018d, - 0x018e, 0x018f, 0x0190, 0x0193, 0x0196, 0x019d, 0x019e, 0x019f, - 0x01a9, 0x01b2, 0x01b4, 0x01ba, 0x01bb, 0x01bc, 0x0201, 0x0202, - 0x0205, 0x0207, 0x020d, 0x0210, 0x0211, 0x0215, 0x021b, 0x021f, - 0x0281, 0x0285, 0x0290, 0x029c, 0x029d, 0x02a2, 0x02a7, 0x02a8, - 0x02aa, 0x02b0, 0x02b1, 0x02b4, 0x02bc, 0x02bf, 0x0320, 0x0326, - 0x0327, 0x0329, 0x032a, 0x0336, 0x0360, 0x0362, 0x0363, 0x0372, - 0x03b2, 0x03bc, 0x03bd, 0x0203, 0x0205, 0x021a, 0x0249, 0x024a, - 0x024c, 0x02c7, 0x02ca, 0x02ce, 0x02ef, 0x030d, 0x0322, 0x0325, - 0x0338, 0x0373, 0x037a, 0x0409, 0x0415, 0x0416, 0x0418, 0x0428, - 0x042d, 0x042f, 0x0434, 0x0508, 0x0509, 0x0510, 0x0511, 0x051c, - 0x051e, 0x0524, 0x0541, 0x0543, 0x0546, 0x0547, 0x054d, 0x0557, - 0x055f, 0x056a, 0x056c, 0x056d, 0x056f, 0x0576, 0x0577, 0x057a, - 0x057b, 0x057c, 0x057d, 0x0600, 0x0601, 0x0603, 0x0614, 0x0616, - 0x0617, 0x061c, 0x061f, 0x0642, 0x0648, 0x0649, 0x064a, 0x064b, - 0x0657, 0x0668, 0x0669, 0x066b, 0x066e, 0x067f, 0x06c2, 0x06c8, - 0x06cb, 0x06de, 0x06df, 0x06e2, 0x06e3, 0x06ef, 0x0748, 0x074b, - 0x076e, 0x076f, 0x077c, 0x0409, 0x0423, 0x0428, 0x0429, 0x042a, - 0x042b, 0x0432, 0x0433, 0x0496, 0x049a, 0x04d5, 0x04db, 0x0581, - 0x0582, 0x058b, 0x058c, 0x058d, 0x0598, 0x0599, 0x059a, 0x059e, - 0x05dd, 0x0619, 0x0632, 0x0633, 0x0648, 0x0672, 0x06a1, 0x06a2, - 0x06a3, 0x06af, 0x06e2, 0x06e3, 0x06e4, 0x0800, 0x0801, 0x0802, - 0x0803, 0x081a, 0x081b, 0x0829, 0x082f, 0x0832, 0x083e, 0x083f, - 0x0852, 0x0853, 0x0858, 0x086b, 0x0877, 0x0878, 0x0879, 0x087a, - 0x087b, 0x0a00, 0x0a01, 0x0a0d, 0x0a0e, 0x0a0f, 0x0a24, 0x0a37, - 0x0a3a, 0x0a3b, 0x0a3e, 0x0a46, 0x0a47, 0x0a4a, 0x0a4b, 0x0a5f, - 0x0a79, 0x0a7a, 0x0a7b, 0x0a80, 0x0a81, 0x0a84, 0x0a85, 0x0a99, - 0x0aa5, 0x0aa6, 0x0ab8, 0x0aba, 0x0abb, 0x0abc, 0x0abd, 0x0ac8, - 0x0ace, 0x0acf, 0x0ad7, 0x0adc, 0x0aeb, 0x0c04, 0x0c25, 0x0c26, - 0x0c27, 0x0c2a, 0x0c2b, 0x0c3a, 0x0c3b, 0x0c3c, 0x0c3d, 0x0ca0, - 0x0cad, 0x0cd4, 0x0cd5, 0x0cfc, 0x0cfd, 0x0d86, 0x0d92, 0x0d93, - 0x0d94, 0x0d95, 0x0db0, 0x0db8, 0x0db9, 0x0dba, 0x0dbb, 0x0dc0, - 0x0dc2, 0x0dc3, 0x0dda, 0x0ddb, 0x0ddc, 0x0ddd, 0x0e92, 0x0e93, - 0x0e94, 0x0e95, 0x0ec7, 0x0ecc, 0x0ece, 0x0ecf, 0x0ed8, 0x0ed9, - 0x0eda, 0x0edb, 0x0808, 0x0809, 0x080a, 0x0810, 0x0811, 0x0844, - 0x0845, 0x0861, 0x0862, 0x0863, 0x086c, 0x0922, 0x0923, 0x092e, - 0x092f, 0x0936, 0x0937, 0x09b1, 0x09b2, 0x09b3, 0x09b4, 0x09b5, - 0x09b8, 0x09b9, 0x09ba, 0x09bb, 0x09bc, 0x09bd, 0x09be, 0x09bf, - 0x0b00, 0x0b15, 0x0b2c, 0x0b2d, 0x0b2e, 0x0b2f, 0x0b36, 0x0bb9, - 0x0c28, 0x0c2a, 0x0c2b, 0x0c2c, 0x0c2d, 0x0c2e, 0x0c2f, 0x0c30, - 0x0c31, 0x0c38, 0x0c60, 0x0c61, 0x0c62, 0x0c63, 0x0c8d, 0x0c8e, - 0x0c8f, 0x0c92, 0x0cbe, 0x0cbf, 0x0ce6, 0x0ce7, 0x0d40, 0x0d41, - 0x0d57, 0x0d58, 0x0d59, 0x0d5a, 0x0d5b, 0x0d5c, 0x0d5d, 0x0d98, - 0x0d99, 0x0d9a, 0x0d9b, 0x0d9c, 0x0d9d, 0x0dad, 0x0dae, 0x0daf, - 0x0dc0, 0x0dc1, 0x0dc2, 0x0dc3, 0x0dca, 0x0dcb, 0x0dec, 0x0ded, - 0x0dee, 0x0def, 0x1018, 0x1022, 0x1023, 0x1030, 0x1031, 0x1032, - 0x1033, 0x1050, 0x1051, 0x105c, 0x1074, 0x1075, 0x1076, 0x1077, - 0x1078, 0x1079, 0x107a, 0x107b, 0x10b2, 0x10b3, 0x10b8, 0x10b9, - 0x10ba, 0x10bb, 0x10d4, 0x10ea, 0x10eb, 0x10ec, 0x10ed, 0x1404, - 0x1405, 0x1406, 0x1407, 0x1410, 0x1411, 0x1412, 0x1413, 0x1414, - 0x1415, 0x1416, 0x1417, 0x1418, 0x1419, 0x1466, 0x1467, 0x1468, - 0x1469, 0x146a, 0x146b, 0x146c, 0x146d, 0x147e, 0x147f, 0x1488, - 0x1489, 0x148a, 0x148b, 0x14b6, 0x14b7, 0x14b8, 0x14b9, 0x14ba, - 0x14bb, 0x14bc, 0x14bd, 0x14f0, 0x14f1, 0x14f8, 0x14f9, 0x14fa, - 0x14fb, 0x14fc, 0x14fd, 0x14fe, 0x14ff, 0x152a, 0x152b, 0x152c, - 0x152d, 0x152e, 0x152f, 0x1530, 0x1531, 0x1548, 0x1549, 0x154e, - 0x154f, 0x1558, 0x1559, 0x155a, 0x155b, 0x1572, 0x159a, 0x159b, - 0x15ac, 0x15ba, 0x15bb, 0x15d0, 0x15d1, 0x15d2, 0x15d3, 0x15d4, - 0x15d5, 0x181d, 0x181e, 0x181f, 0x1840, 0x1841, 0x1842, 0x1843, - 0x1844, 0x1845, 0x1846, 0x1847, 0x1848, 0x1849, 0x1861, 0x1862, - 0x1863, 0x1864, 0x1865, 0x1866, 0x1867, 0x1868, 0x1869, 0x186a, - 0x186b, 0x186c, 0x186d, 0x186e, 0x191b, 0x191c, 0x191d, 0x191e, - 0x191f, 0x1942, 0x1943, 0x1944, 0x1945, 0x1946, 0x1947, 0x1958, - 0x1959, 0x19ed, 0x19ee, 0x19ef, 0x19f0, 0x19f1, 0x19f2, 0x19f3, - 0x19f4, 0x19f5, 0x19f6, 0x19f7, 0x1b0e, 0x1b0f, 0x1b62, 0x1b63, - 0x1b64, 0x1b65, 0x1b66, 0x1b67, 0x1b68, 0x1b69, 0x1b6a, 0x1b6b, - 0x1b6c, 0x1b6d, 0x1b6e, 0x1b6f, 0x1b82, 0x1ba8, 0x1ba9, 0x1baa, - 0x1bab, 0x1bac, 0x1bad, 0x1bae, 0x1baf, 0x1bb0, 0x1bb1, 0x1bb2, - 0x1bb3, 0x1d80, 0x1d81, 0x1d82, 0x1d83, 0x1d84, 0x1d85, 0x1d86, - 0x1d87, 0x1d88, 0x1d89, 0x1d8a, 0x1d8b, 0x1d8c, 0x1d8d, 0x1007, - 0x1008, 0x1009, 0x100a, 0x100b, 0x100c, 0x100d, 0x100e, 0x100f, - 0x1016, 0x1080, 0x1081, 0x1082, 0x1083, 0x1084, 0x1085, 0x1086, - 0x1087, 0x10c0, 0x123a, 0x123b, 0x123c, 0x123d, 0x123e, 0x123f, - 0x1240, 0x1241, 0x1242, 0x1243, 0x1350, 0x1352, 0x1353, 0x1358, - 0x1359, 0x135a, 0x135b, 0x135c, 0x135d, 0x135e, 0x135f, 0x1360, - 0x1361, 0x1602, 0x1603, 0x160c, 0x160d, 0x160e, 0x160f, 0x1620, - 0x1621, 0x1622, 0x1623, 0x1624, 0x1625, 0x1626, 0x1627, 0x1628, - 0x1629, 0x166e, 0x166f, 0x167c, 0x167d, 0x167e, 0x167f, 0x1770, - 0x1771, 0x1852, 0x1853, 0x1872, 0x1873, 0x1874, 0x1875, 0x1876, - 0x1877, 0x1878, 0x1879, 0x187a, 0x187b, 0x187c, 0x187d, 0x187e, - 0x187f, 0x1918, 0x1919, 0x1926, 0x1927, 0x1970, 0x1971, 0x1972, - 0x1973, 0x1974, 0x1975, 0x1976, 0x1977, 0x1978, 0x1979, 0x197a, - 0x197b, 0x1aa0, 0x1aa1, 0x1aa2, 0x1aa3, 0x1aa4, 0x1aa5, 0x1aa6, - 0x1aa7, 0x1aa8, 0x1aa9, 0x1aaa, 0x1aab, 0x1aac, 0x1aad, 0x1b3c, - 0x1b3d, 0x1b3e, 0x1b3f, 0x1b50, 0x1b51, 0x1b52, 0x1b53, 0x1b54, - 0x1b55, 0x1b56, 0x1b57, 0x1b58, 0x1b59, 0x2032, 0x2033, 0x2034, - 0x2035, 0x2036, 0x2037, 0x2038, 0x2039, 0x203a, 0x203b, 0x203c, - 0x203d, 0x203e, 0x203f, 0x2040, 0x2041, 0x2042, 0x2043, 0x20ba, - 0x20bb, 0x20cc, 0x20cd, 0x20ce, 0x20cf, 0x20e0, 0x20e1, 0x20e2, - 0x20e3, 0x20e4, 0x20e5, 0x20e6, 0x20e7, 0x21aa, 0x21ab, 0x21c0, - 0x21c1, 0x21c2, 0x21c3, 0x21c4, 0x21c5, 0x21c6, 0x21c7, 0x21c8, - 0x21c9, 0x21ca, 0x21cb, 0x21cc, 0x21cd, 0x21ce, 0x21cf, 0x21d0, - 0x21d1, 0x21d2, 0x21d3, 0x2894, 0x2895, 0x2896, 0x2897, 0x2898, - 0x2899, 0x289a, 0x289b, 0x289c, 0x289d, 0x289e, 0x289f, 0x28c0, - 0x28c1, 0x28c2, 0x28c3, 0x28c4, 0x28c5, 0x28c6, 0x28c7, 0x28c8, - 0x28c9, 0x28ca, 0x28cb, 0x2930, 0x2931, 0x2932, 0x2933, 0x2934, - 0x2935, 0x2936, 0x2937, 0x2938, 0x2939, 0x293a, 0x293b, 0x293c, - 0x293d, 0x293e, 0x293f, 0x2960, 0x2961, 0x2962, 0x2963, 0x2964, - 0x2965, 0x2966, 0x2967, 0x2968, 0x2969, 0x296a, 0x296b, 0x2a40, - 0x2a41, 0x2a42, 0x2a43, 0x2a44, 0x2a45, 0x2a46, 0x2a47, 0x2a48, - 0x2a49, 0x2a4a, 0x2a4b, 0x2a4c, 0x2a4d, 0x2a4e, 0x2a4f, 0x2a50, - 0x2a51, 0x2a52, 0x2a53, 0x2ae6, 0x2ae7, 0x2b24, 0x2b25, 0x2b26, - 0x2b27, 0x2b28, 0x2b29, 0x2b2a, 0x2b2b, 0x2b2c, 0x2b2d, 0x2b2e, - 0x2b2f, 0x2b30, 0x2b31, 0x2b32, 0x2b33, 0x2b5a, 0x2b5b, 0x3014, - 0x3015, 0x3016, 0x3017, 0x3020, 0x3021, 0x3022, 0x3023, 0x3024, - 0x3025, 0x3026, 0x3027, 0x3028, 0x3029, 0x302a, 0x302b, 0x302c, - 0x302d, 0x302e, 0x302f, 0x3030, 0x3031, 0x3032, 0x3033, 0x3034, - 0x3035, 0x3036, 0x3037, 0x3038, 0x3039, 0x30c0, 0x30c1, 0x30de, - 0x30df, 0x3218, 0x3219, 0x321a, 0x321b, 0x321c, 0x321d, 0x321e, - 0x321f, 0x3220, 0x3221, 0x3222, 0x3223, 0x3224, 0x3225, 0x3226, - 0x3227, 0x3228, 0x3229, 0x322a, 0x322b, 0x322c, 0x322d, 0x322e, - 0x322f, 0x3230, 0x3231, 0x3232, 0x3233, 0x3234, 0x3235, 0x3378, - 0x3379, 0x337a, 0x337b, 0x337c, 0x337d, 0x337e, 0x337f, 0x33c0, - 0x33c1, 0x33c2, 0x33c3, 0x33c4, 0x33c5, 0x33c6, 0x33c7, 0x33c8, - 0x33c9, 0x33ca, 0x33cb, 0x33cc, 0x33cd, 0x33ce, 0x33cf, 0x33d0, - 0x33d1, 0x33d2, 0x33d3, 0x33d4, 0x33d5, 0x33d6, 0x33d7, 0x33d8, - 0x33d9, 0x3706, 0x3707, 0x3730, 0x3731, 0x3732, 0x3733, 0x3734, - 0x3735, 0x3736, 0x3737, 0x3738, 0x3739, 0x373a, 0x373b, 0x373c, - 0x373d, 0x373e, 0x373f, 0x3740, 0x3741, 0x3742, 0x3743, 0x3744, - 0x3745, 0x3746, 0x3747, 0x3748, 0x3749, 0x374a, 0x374b, 0x374c, - 0x374d, 0x374e, 0x374f, 0x3b34, 0x3b35, 0x3b36, 0x3b37, 0x3be8, - 0x3be9, 0x3bea, 0x3beb, 0x3bec, 0x3bed, 0x3bee, 0x3bef, 0x3bf0, - 0x3bf1, 0x3bf2, 0x3bf3, 0x3bf4, 0x3bf5, 0x3bf6, 0x3bf7, 0x3bf8, - 0x3bf9, 0x3bfa, 0x3bfb, 0x3bfc, 0x3bfd, 0x3bfe, 0x3bff, 0x2000, - 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, - 0x2009, 0x200a, 0x200b, 0x200c, 0x200d, 0x202e, 0x202f, 0x2182, - 0x2183, 0x21b4, 0x21b5, 0x21b6, 0x21b7, 0x21b8, 0x21b9, 0x21ba, - 0x21bb, 0x21bc, 0x21bd, 0x21be, 0x21bf, 0x2460, 0x2461, 0x2462, - 0x2463, 0x2464, 0x2465, 0x2466, 0x2467, 0x2468, 0x2469, 0x246a, - 0x246b, 0x246c, 0x246d, 0x246e, 0x246f, 0x2470, 0x2471, 0x2472, - 0x2473, 0x26a2, 0x26a3, 0x000b, -}; +#ifndef FFMPEG_MSMPEG4DATA_H +#define FFMPEG_MSMPEG4DATA_H -static const uint8_t table1_mv_bits[1100] = { - 2, 4, 4, 4, 5, 5, 5, 5, - 6, 6, 7, 7, 7, 7, 7, 8, - 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, - 8, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 12, 12, 12, 12, 12, 12, - 12, 12, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 13, - 13, 13, 13, 13, 13, 13, 13, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 4, -}; - -static const uint8_t table1_mvx[1099] = { - 32, 31, 32, 31, 33, 32, 33, 33, - 31, 34, 30, 32, 32, 34, 35, 32, - 34, 33, 29, 30, 30, 32, 31, 31, - 33, 35, 35, 33, 31, 29, 29, 33, - 34, 30, 31, 28, 36, 30, 34, 32, - 32, 37, 32, 32, 25, 27, 39, 32, - 32, 32, 38, 35, 36, 32, 37, 61, - 26, 32, 34, 35, 3, 35, 27, 28, - 29, 34, 28, 37, 31, 36, 32, 27, - 31, 30, 29, 39, 33, 29, 33, 35, - 25, 25, 29, 33, 31, 31, 31, 33, - 32, 30, 32, 32, 41, 39, 33, 36, - 32, 28, 34, 36, 38, 24, 60, 31, - 23, 28, 32, 33, 59, 32, 40, 30, - 5, 34, 32, 38, 32, 30, 43, 4, - 32, 32, 42, 31, 31, 32, 26, 38, - 26, 22, 21, 37, 61, 63, 37, 31, - 32, 33, 2, 1, 23, 33, 41, 27, - 35, 30, 38, 23, 33, 3, 28, 34, - 34, 27, 41, 29, 39, 35, 36, 29, - 32, 27, 30, 32, 24, 61, 37, 26, - 59, 25, 35, 27, 36, 37, 30, 31, - 34, 40, 3, 28, 34, 39, 32, 31, - 32, 30, 24, 28, 35, 36, 26, 32, - 31, 33, 29, 33, 39, 25, 30, 24, - 35, 59, 29, 34, 25, 30, 21, 35, - 43, 40, 32, 29, 5, 28, 31, 62, - 33, 33, 25, 31, 21, 31, 43, 31, - 34, 33, 20, 40, 39, 31, 31, 57, - 38, 32, 42, 33, 32, 31, 32, 29, - 30, 44, 5, 31, 22, 34, 36, 17, - 38, 58, 38, 35, 32, 60, 35, 24, - 32, 38, 16, 45, 42, 32, 31, 29, - 4, 30, 17, 40, 46, 48, 63, 32, - 42, 19, 41, 22, 28, 36, 45, 33, - 33, 32, 29, 7, 41, 42, 18, 33, - 33, 32, 22, 37, 1, 26, 22, 23, - 49, 28, 26, 27, 32, 33, 27, 23, - 28, 36, 15, 6, 34, 27, 31, 26, - 23, 2, 33, 32, 34, 41, 28, 32, - 41, 0, 36, 38, 34, 31, 47, 32, - 17, 31, 39, 33, 37, 51, 30, 47, - 32, 50, 32, 19, 63, 30, 25, 27, - 33, 62, 24, 31, 27, 30, 37, 31, - 45, 32, 39, 20, 46, 47, 35, 19, - 34, 1, 49, 21, 21, 14, 51, 26, - 23, 31, 36, 35, 58, 29, 29, 21, - 20, 42, 13, 28, 12, 40, 31, 33, - 39, 60, 32, 44, 33, 31, 28, 37, - 29, 32, 30, 49, 43, 28, 39, 25, - 32, 48, 2, 15, 20, 25, 31, 28, - 21, 24, 25, 15, 31, 17, 37, 43, - 18, 32, 33, 24, 33, 36, 13, 33, - 31, 39, 11, 31, 33, 32, 39, 37, - 32, 32, 29, 17, 44, 46, 36, 35, - 26, 37, 58, 32, 34, 38, 8, 38, - 38, 22, 29, 25, 16, 35, 32, 35, - 33, 43, 18, 46, 38, 50, 33, 18, - 53, 60, 13, 32, 36, 33, 51, 36, - 43, 45, 27, 42, 29, 24, 30, 25, - 31, 52, 31, 35, 38, 9, 22, 34, - 4, 17, 28, 55, 42, 25, 17, 20, - 47, 34, 33, 16, 40, 25, 16, 30, - 53, 29, 10, 11, 14, 26, 33, 4, - 35, 44, 26, 16, 31, 26, 34, 38, - 29, 31, 30, 24, 22, 61, 32, 9, - 45, 34, 31, 19, 9, 31, 46, 31, - 35, 54, 29, 57, 30, 50, 3, 31, - 63, 34, 47, 41, 51, 18, 31, 14, - 37, 38, 31, 24, 32, 31, 50, 33, - 31, 54, 27, 9, 33, 23, 19, 32, - 29, 29, 33, 28, 47, 49, 30, 47, - 33, 27, 25, 54, 44, 45, 50, 58, - 51, 48, 33, 59, 33, 34, 57, 13, - 26, 33, 13, 48, 30, 11, 7, 56, - 34, 55, 26, 0, 26, 35, 1, 51, - 33, 53, 31, 45, 12, 29, 29, 51, - 31, 48, 2, 6, 34, 30, 28, 33, - 60, 40, 27, 46, 31, 9, 35, 29, - 31, 39, 55, 46, 19, 37, 62, 34, - 30, 16, 19, 49, 41, 41, 39, 37, - 14, 5, 13, 35, 55, 30, 40, 40, - 42, 8, 20, 25, 45, 35, 33, 36, - 54, 38, 27, 37, 62, 40, 15, 59, - 49, 31, 29, 34, 34, 39, 24, 29, - 25, 29, 21, 29, 10, 61, 33, 49, - 35, 34, 3, 38, 39, 29, 7, 41, - 1, 35, 4, 23, 15, 23, 11, 37, - 28, 35, 30, 30, 24, 1, 43, 56, - 8, 34, 42, 24, 45, 30, 20, 23, - 8, 38, 22, 33, 17, 52, 34, 22, - 53, 43, 44, 1, 27, 31, 41, 43, - 41, 30, 31, 36, 30, 5, 55, 31, - 33, 30, 40, 23, 15, 29, 34, 34, - 59, 34, 30, 11, 13, 38, 5, 0, - 30, 42, 5, 30, 29, 34, 10, 44, - 30, 63, 35, 12, 3, 26, 15, 17, - 25, 34, 43, 39, 34, 56, 29, 23, - 30, 12, 30, 10, 35, 9, 24, 58, - 10, 12, 54, 33, 37, 20, 41, 35, - 29, 18, 61, 30, 40, 24, 39, 53, - 62, 26, 29, 33, 34, 53, 49, 21, - 27, 11, 63, 20, 26, 23, 7, 13, - 6, 47, 29, 30, 9, 51, 22, 34, - 21, 25, 33, 56, 57, 30, 38, 51, - 51, 38, 63, 28, 40, 35, 33, 18, - 33, 33, 24, 58, 58, 34, 49, 29, - 43, 4, 1, 4, 42, 35, 35, 30, - 17, 5, 56, 61, 25, 37, 36, 55, - 28, 35, 29, 50, 48, 52, 2, 42, - 34, 40, 46, 46, 43, 35, 29, 48, - 20, 29, 31, 41, 7, 30, 35, 19, - 14, 21, 8, 39, 39, 40, 46, 55, - 34, 6, 30, 34, 37, 25, 37, 33, - 22, 44, 52, 17, 35, 29, 36, 35, - 40, 37, 28, 30, 50, 14, 28, 55, - 6, 23, 19, 14, 30, 3, 30, 28, - 28, 61, 61, 47, 45, 48, 40, 40, - 34, 34, 25, 30, 29, 35, 4, 26, - 53, 50, 26, 41, 27, 59, 27, 38, - 39, 3, 50, 43, 47, 23, 33, 55, - 35, 21, 23, 35, 61, 33, 46, 52, - 35, 34, 24, 30, 43, 16, 37, 21, - 2, 24, 45, 34, 30, 55, 55, 1, - 29, 29, 26, 28, 25, 31, 36, 22, - 17, 30, 52, 2, 44, 44, 57, 26, - 62, 41, 39, 57, 26, 46, 49, 11, - 16, 19, 5, 59, 38, 39, 58, 38, - 25, 49, 50, 22, 28, 59, 9, 59, - 7, 28, 55, 17, 4, 35, 50, 21, - 29, 44, 47, 18, 24, 19, 25, 42, - 35, 3, 51, 35, 16, 35, 30, 63, - 57, 39, 39, 25, 35, 38, 9, 16, - 36, 45, 31, 60, 14, 34, 42, 24, - 0, 37, 18, 61, 57, 37, 28, 53, - 20, 46, 14, 47, 38, 38, 38, 9, - 34, 39, 43, 17, 39, 59, 5, 27, - 0, 12, 27, -}; - -static const uint8_t table1_mvy[1099] = { - 32, 32, 31, 31, 32, 33, 31, 33, - 33, 32, 32, 30, 34, 31, 32, 29, - 33, 30, 32, 33, 31, 35, 34, 30, - 34, 31, 33, 29, 29, 31, 33, 35, - 30, 30, 35, 32, 32, 34, 34, 28, - 25, 32, 36, 27, 32, 32, 32, 37, - 39, 3, 32, 30, 31, 26, 31, 32, - 32, 38, 29, 29, 32, 34, 31, 31, - 34, 35, 33, 33, 28, 33, 1, 33, - 27, 29, 30, 31, 28, 29, 37, 35, - 31, 33, 35, 27, 36, 37, 25, 25, - 61, 35, 4, 5, 32, 33, 36, 30, - 23, 30, 28, 34, 31, 32, 32, 39, - 32, 34, 21, 39, 32, 59, 32, 28, - 32, 36, 60, 33, 24, 36, 32, 32, - 41, 2, 32, 38, 26, 22, 33, 30, - 31, 32, 32, 30, 31, 32, 29, 3, - 40, 38, 32, 32, 33, 26, 31, 34, - 28, 38, 34, 31, 3, 31, 35, 38, - 27, 35, 33, 28, 29, 27, 29, 27, - 43, 29, 37, 63, 31, 33, 34, 30, - 31, 30, 37, 30, 35, 35, 26, 41, - 37, 31, 33, 28, 26, 30, 42, 24, - 7, 27, 33, 29, 36, 28, 34, 57, - 23, 41, 36, 23, 35, 34, 25, 30, - 25, 33, 25, 25, 29, 24, 33, 39, - 33, 33, 0, 37, 31, 36, 21, 32, - 61, 24, 35, 61, 31, 5, 31, 59, - 39, 21, 32, 30, 34, 22, 40, 32, - 29, 16, 31, 5, 62, 2, 20, 39, - 39, 32, 33, 1, 31, 24, 36, 32, - 36, 32, 28, 26, 6, 31, 38, 34, - 58, 35, 32, 33, 33, 17, 43, 26, - 31, 40, 31, 34, 32, 32, 31, 19, - 30, 32, 29, 33, 38, 38, 32, 59, - 40, 18, 38, 32, 35, 34, 32, 17, - 1, 15, 30, 28, 31, 28, 34, 29, - 32, 27, 35, 27, 49, 22, 37, 34, - 37, 26, 32, 32, 22, 28, 45, 29, - 30, 31, 43, 46, 41, 30, 26, 13, - 34, 32, 27, 38, 42, 42, 33, 47, - 33, 60, 27, 42, 25, 32, 22, 32, - 48, 32, 45, 33, 33, 41, 27, 25, - 19, 31, 35, 19, 36, 42, 27, 17, - 31, 44, 28, 33, 33, 31, 23, 31, - 40, 33, 31, 34, 30, 32, 33, 36, - 35, 47, 37, 41, 31, 23, 41, 29, - 30, 35, 32, 25, 32, 28, 58, 2, - 37, 33, 14, 33, 49, 20, 39, 36, - 21, 9, 23, 33, 35, 24, 39, 37, - 11, 33, 30, 31, 31, 28, 51, 40, - 35, 29, 25, 33, 46, 35, 37, 30, - 30, 8, 63, 28, 15, 40, 33, 45, - 49, 25, 32, 4, 47, 51, 36, 39, - 53, 10, 24, 29, 30, 31, 25, 40, - 38, 38, 33, 56, 23, 27, 32, 37, - 26, 29, 43, 36, 33, 24, 55, 43, - 9, 29, 34, 34, 24, 33, 18, 33, - 33, 30, 31, 50, 24, 60, 30, 39, - 34, 30, 39, 28, 22, 38, 2, 26, - 63, 32, 57, 21, 39, 33, 28, 18, - 30, 34, 22, 33, 29, 41, 30, 34, - 35, 21, 13, 34, 35, 39, 30, 46, - 32, 42, 32, 31, 33, 26, 11, 33, - 22, 31, 25, 31, 53, 27, 43, 25, - 40, 50, 21, 36, 38, 30, 12, 31, - 34, 20, 15, 29, 32, 62, 30, 13, - 17, 32, 19, 31, 20, 31, 30, 7, - 1, 17, 34, 37, 31, 31, 44, 34, - 26, 40, 16, 37, 52, 48, 30, 20, - 18, 33, 38, 29, 7, 25, 30, 54, - 45, 47, 46, 41, 29, 29, 16, 30, - 14, 26, 38, 34, 34, 29, 34, 30, - 29, 30, 57, 30, 4, 46, 33, 29, - 39, 44, 30, 31, 50, 33, 31, 32, - 19, 32, 40, 31, 37, 47, 1, 35, - 16, 31, 0, 35, 33, 1, 17, 34, - 9, 34, 33, 31, 49, 43, 42, 51, - 34, 29, 23, 29, 14, 30, 45, 49, - 11, 24, 31, 28, 35, 41, 30, 44, - 18, 29, 34, 35, 36, 25, 26, 21, - 31, 30, 34, 19, 34, 44, 36, 38, - 25, 31, 28, 23, 37, 3, 55, 41, - 30, 22, 41, 24, 33, 26, 35, 35, - 30, 55, 51, 47, 48, 38, 24, 15, - 21, 50, 25, 46, 30, 29, 10, 34, - 42, 45, 29, 42, 22, 3, 33, 27, - 34, 1, 34, 28, 34, 36, 35, 23, - 23, 13, 58, 3, 26, 63, 25, 31, - 34, 61, 38, 39, 25, 61, 29, 37, - 30, 41, 26, 48, 28, 33, 50, 35, - 30, 37, 29, 29, 40, 6, 39, 28, - 28, 19, 8, 22, 45, 34, 35, 10, - 58, 17, 37, 39, 30, 18, 54, 14, - 29, 16, 59, 30, 35, 23, 35, 30, - 47, 36, 29, 55, 20, 12, 31, 35, - 14, 29, 18, 34, 34, 24, 29, 26, - 22, 2, 27, 23, 8, 30, 55, 38, - 60, 31, 4, 34, 49, 34, 27, 34, - 33, 30, 31, 54, 42, 35, 38, 46, - 44, 26, 27, 9, 39, 25, 21, 29, - 28, 42, 13, 0, 5, 34, 37, 28, - 24, 29, 63, 26, 22, 27, 29, 25, - 33, 25, 61, 0, 35, 25, 36, 15, - 27, 40, 53, 33, 3, 10, 16, 37, - 38, 18, 30, 46, 27, 9, 6, 29, - 62, 8, 42, 28, 29, 3, 25, 16, - 26, 29, 35, 28, 27, 51, 61, 48, - 37, 9, 34, 7, 49, 45, 20, 29, - 21, 5, 5, 29, 28, 34, 29, 24, - 10, 24, 35, 36, 38, 55, 11, 36, - 38, 53, 54, 26, 30, 49, 20, 27, - 30, 39, 33, 41, 49, 22, 38, 38, - 4, 30, 8, 9, 3, 24, 22, 50, - 37, 36, 31, 27, 2, 9, 42, 63, - 25, 19, 44, 1, 28, 28, 48, 30, - 34, 41, 41, 38, 12, 27, 15, 0, - 16, 34, 35, 38, 28, 29, 40, 42, - 51, 52, 45, 54, 59, 59, 42, 44, - 37, 26, 46, 24, 15, 39, 22, 46, - 19, 35, 38, 17, 37, 23, 52, 55, - 50, 37, 26, 11, 37, 12, 24, 30, - 16, 13, 22, 13, 36, 35, 40, 41, - 34, 41, 26, 53, 51, 5, 21, 30, - 2, 63, 41, 20, 1, 56, 21, 24, - 25, 5, 28, 35, 26, 28, 30, 18, - 29, 23, 40, 34, 20, 42, 39, 34, - 28, 61, 38, 27, 62, 9, 36, 17, - 9, 49, 24, 25, 54, 34, 39, 37, - 3, 1, 25, 38, 38, 44, 35, 36, - 12, 60, 36, 38, 40, 25, 43, 39, - 53, 28, 39, 57, 46, 10, 52, 27, - 35, 42, 45, 59, 15, 60, 38, 24, - 23, 39, 12, 29, 24, 0, 20, 16, - 28, 43, 35, 28, 1, 49, 4, 21, - 42, 39, 29, 3, 44, 21, 53, 55, - 11, 5, 3, 39, 53, 28, 25, 19, - 34, 28, 21, -}; +#include "common.h" +#include "bitstream.h" +#include "rl.h" /* motion vector table */ typedef struct MVTable { @@ -1797,232 +45,56 @@ typedef struct MVTable { VLC vlc; /* decoding: vlc */ } MVTable; -static MVTable mv_tables[2] = { - { - 1099, - table0_mv_code, - table0_mv_bits, - table0_mvx, - table0_mvy, - }, - { - 1099, - table1_mv_code, - table1_mv_bits, - table1_mvx, - table1_mvy, - } -}; +extern VLC ff_msmp4_mb_i_vlc; +extern VLC ff_msmp4_dc_luma_vlc[2]; +extern VLC ff_msmp4_dc_chroma_vlc[2]; + +/* intra picture macro block coded block pattern */ +extern const uint16_t ff_msmp4_mb_i_table[64][2]; -static const uint8_t v2_mb_type[8][2] = { - {1, 1}, {0 , 2}, {3 , 3}, {9 , 5}, - {5, 4}, {0x21, 7}, {0x20, 7}, {0x11, 6}, -}; +extern const uint8_t cbpy_tab[16][2]; -static const uint8_t v2_intra_cbpc[4][2] = { - {1, 1}, {0, 3}, {1, 3}, {1, 2}, -}; +extern const uint8_t DCtab_lum[13][2]; +extern const uint8_t DCtab_chrom[13][2]; -static const uint8_t wmv1_y_dc_scale_table[32]={ -// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 - 0, 8, 8, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21 -}; -static const uint8_t wmv1_c_dc_scale_table[32]={ -// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 - 0, 8, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22 -}; +extern const uint8_t mvtab[33][2]; -static const uint8_t old_ff_y_dc_scale_table[32]={ -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 - 0, 8, 8, 8, 8,10,12,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39 -}; -static const uint8_t old_ff_c_dc_scale_table[32]={ -// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 - 0, 8, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22 -}; +extern const uint8_t intra_MCBPC_code[9]; +extern const uint8_t intra_MCBPC_bits[9]; +extern const uint8_t inter_MCBPC_code[28]; +extern const uint8_t inter_MCBPC_bits[28]; #define WMV1_SCANTABLE_COUNT 4 -static const uint8_t wmv1_scantable00[64]= { -0x00, 0x08, 0x01, 0x02, 0x09, 0x10, 0x18, 0x11, -0x0A, 0x03, 0x04, 0x0B, 0x12, 0x19, 0x20, 0x28, -0x30, 0x38, 0x29, 0x21, 0x1A, 0x13, 0x0C, 0x05, -0x06, 0x0D, 0x14, 0x1B, 0x22, 0x31, 0x39, 0x3A, -0x32, 0x2A, 0x23, 0x1C, 0x15, 0x0E, 0x07, 0x0F, -0x16, 0x1D, 0x24, 0x2B, 0x33, 0x3B, 0x3C, 0x34, -0x2C, 0x25, 0x1E, 0x17, 0x1F, 0x26, 0x2D, 0x35, -0x3D, 0x3E, 0x36, 0x2E, 0x27, 0x2F, 0x37, 0x3F, -}; -static const uint8_t wmv1_scantable01[64]= { -0x00, 0x08, 0x01, 0x02, 0x09, 0x10, 0x18, 0x11, -0x0A, 0x03, 0x04, 0x0B, 0x12, 0x19, 0x20, 0x28, -0x21, 0x30, 0x1A, 0x13, 0x0C, 0x05, 0x06, 0x0D, -0x14, 0x1B, 0x22, 0x29, 0x38, 0x31, 0x39, 0x2A, -0x23, 0x1C, 0x15, 0x0E, 0x07, 0x0F, 0x16, 0x1D, -0x24, 0x2B, 0x32, 0x3A, 0x33, 0x3B, 0x2C, 0x25, -0x1E, 0x17, 0x1F, 0x26, 0x2D, 0x34, 0x3C, 0x35, -0x3D, 0x2E, 0x27, 0x2F, 0x36, 0x3E, 0x37, 0x3F, -}; -static const uint8_t wmv1_scantable02[64]= { -0x00, 0x01, 0x08, 0x02, 0x03, 0x09, 0x10, 0x18, -0x11, 0x0A, 0x04, 0x05, 0x0B, 0x12, 0x19, 0x20, -0x28, 0x30, 0x21, 0x1A, 0x13, 0x0C, 0x06, 0x07, -0x0D, 0x14, 0x1B, 0x22, 0x29, 0x38, 0x31, 0x39, -0x2A, 0x23, 0x1C, 0x15, 0x0E, 0x0F, 0x16, 0x1D, -0x24, 0x2B, 0x32, 0x3A, 0x33, 0x2C, 0x25, 0x1E, -0x17, 0x1F, 0x26, 0x2D, 0x34, 0x3B, 0x3C, 0x35, -0x2E, 0x27, 0x2F, 0x36, 0x3D, 0x3E, 0x37, 0x3F, -}; -static const uint8_t wmv1_scantable03[64]= { -0x00, 0x08, 0x10, 0x01, 0x18, 0x20, 0x28, 0x09, -0x02, 0x03, 0x0A, 0x11, 0x19, 0x30, 0x38, 0x29, -0x21, 0x1A, 0x12, 0x0B, 0x04, 0x05, 0x0C, 0x13, -0x1B, 0x22, 0x31, 0x39, 0x32, 0x2A, 0x23, 0x1C, -0x14, 0x0D, 0x06, 0x07, 0x0E, 0x15, 0x1D, 0x24, -0x2B, 0x33, 0x3A, 0x3B, 0x34, 0x2C, 0x25, 0x1E, -0x16, 0x0F, 0x17, 0x1F, 0x26, 0x2D, 0x3C, 0x35, -0x2E, 0x27, 0x2F, 0x36, 0x3D, 0x3E, 0x37, 0x3F, -}; +extern const uint8_t wmv1_scantable[WMV1_SCANTABLE_COUNT][64]; -static const uint8_t *wmv1_scantable[WMV1_SCANTABLE_COUNT+1]={ - wmv1_scantable00, - wmv1_scantable01, - wmv1_scantable02, - wmv1_scantable03, -}; +#define NB_RL_TABLES 6 -static const uint8_t table_inter_intra[4][2]={ - {0,1} /*Luma-Left Chroma-Left*/, - {2,2} /*Luma-Top Chroma-Left*/, - {6,3} /*luma-Left Chroma-Top */, - {7,3} /*luma-Top Chroma-Top */ -}; +extern RLTable rl_table[NB_RL_TABLES]; -#define WMV2_INTER_CBP_TABLE_COUNT 4 +extern const uint8_t wmv1_y_dc_scale_table[32]; +extern const uint8_t wmv1_c_dc_scale_table[32]; +extern const uint8_t old_ff_y_dc_scale_table[32]; +extern const uint8_t old_ff_c_dc_scale_table[32]; -static const uint32_t table_mb_non_intra2[128][2] = { -{0x0000A7, 14}, {0x01B2B8, 18}, {0x01B28E, 18}, {0x036575, 19}, -{0x006CAC, 16}, {0x000A69, 18}, {0x002934, 20}, {0x00526B, 21}, -{0x006CA1, 16}, {0x01B2B9, 18}, {0x0029AD, 20}, {0x029353, 24}, -{0x006CA7, 16}, {0x006CAB, 16}, {0x01B2BB, 18}, {0x00029B, 16}, -{0x00D944, 17}, {0x000A6A, 18}, {0x0149A8, 23}, {0x03651F, 19}, -{0x006CAF, 16}, {0x000A4C, 18}, {0x03651E, 19}, {0x000A48, 18}, -{0x00299C, 20}, {0x00299F, 20}, {0x029352, 24}, {0x0029AC, 20}, -{0x000296, 16}, {0x00D946, 17}, {0x000A68, 18}, {0x000298, 16}, -{0x000527, 17}, {0x00D94D, 17}, {0x0014D7, 19}, {0x036574, 19}, -{0x000A5C, 18}, {0x01B299, 18}, {0x00299D, 20}, {0x00299E, 20}, -{0x000525, 17}, {0x000A66, 18}, {0x00A4D5, 22}, {0x00149B, 19}, -{0x000295, 16}, {0x006CAD, 16}, {0x000A49, 18}, {0x000521, 17}, -{0x006CAA, 16}, {0x00D945, 17}, {0x01B298, 18}, {0x00052F, 17}, -{0x003654, 15}, {0x006CA0, 16}, {0x000532, 17}, {0x000291, 16}, -{0x003652, 15}, {0x000520, 17}, {0x000A5D, 18}, {0x000294, 16}, -{0x00009B, 11}, {0x0006E2, 12}, {0x000028, 12}, {0x0001B0, 10}, -{0x000001, 3}, {0x000010, 8}, {0x00002F, 6}, {0x00004C, 10}, -{0x00000D, 4}, {0x000000, 10}, {0x000006, 9}, {0x000134, 12}, -{0x00000C, 4}, {0x000007, 10}, {0x000007, 9}, {0x0006E1, 12}, -{0x00000E, 5}, {0x0000DA, 9}, {0x000022, 9}, {0x000364, 11}, -{0x00000F, 4}, {0x000006, 10}, {0x00000F, 9}, {0x000135, 12}, -{0x000014, 5}, {0x0000DD, 9}, {0x000004, 9}, {0x000015, 11}, -{0x00001A, 6}, {0x0001B3, 10}, {0x000005, 10}, {0x0006E3, 12}, -{0x00000C, 5}, {0x0000B9, 8}, {0x000004, 8}, {0x0000DB, 9}, -{0x00000E, 4}, {0x00000B, 10}, {0x000023, 9}, {0x0006CB, 12}, -{0x000005, 6}, {0x0001B1, 10}, {0x000001, 10}, {0x0006E0, 12}, -{0x000011, 5}, {0x0000DF, 9}, {0x00000E, 9}, {0x000373, 11}, -{0x000003, 5}, {0x0000B8, 8}, {0x000006, 8}, {0x000175, 9}, -{0x000015, 5}, {0x000174, 9}, {0x000027, 9}, {0x000372, 11}, -{0x000010, 5}, {0x0000BB, 8}, {0x000005, 8}, {0x0000DE, 9}, -{0x00000F, 5}, {0x000001, 9}, {0x000012, 8}, {0x000004, 10}, -{0x000002, 3}, {0x000016, 5}, {0x000009, 4}, {0x000001, 5}, -}; +extern MVTable mv_tables[2]; -static const uint32_t table_mb_non_intra3[128][2] = { -{0x0002A1, 10}, {0x005740, 15}, {0x01A0BF, 18}, {0x015D19, 17}, -{0x001514, 13}, {0x00461E, 15}, {0x015176, 17}, {0x015177, 17}, -{0x0011AD, 13}, {0x00682E, 16}, {0x0682F9, 20}, {0x03417D, 19}, -{0x001A36, 14}, {0x002A2D, 14}, {0x00D05E, 17}, {0x006824, 16}, -{0x001515, 13}, {0x00545C, 15}, {0x0230E9, 18}, {0x011AFA, 17}, -{0x0015D7, 13}, {0x005747, 15}, {0x008D79, 16}, {0x006825, 16}, -{0x002BA2, 14}, {0x00A8BA, 16}, {0x0235F6, 18}, {0x015D18, 17}, -{0x0011AE, 13}, {0x00346F, 15}, {0x008C3B, 16}, {0x00346E, 15}, -{0x000D1A, 13}, {0x00461F, 15}, {0x0682F8, 20}, {0x011875, 17}, -{0x002BA1, 14}, {0x008D61, 16}, {0x0235F7, 18}, {0x0230E8, 18}, -{0x001513, 13}, {0x008D7B, 16}, {0x011AF4, 17}, {0x011AF5, 17}, -{0x001185, 13}, {0x0046BF, 15}, {0x008D60, 16}, {0x008D7C, 16}, -{0x001512, 13}, {0x00461C, 15}, {0x00AE8D, 16}, {0x008D78, 16}, -{0x000D0E, 13}, {0x003413, 15}, {0x0046B1, 15}, {0x003416, 15}, -{0x000AEA, 12}, {0x002A2C, 14}, {0x005741, 15}, {0x002A2F, 14}, -{0x000158, 9}, {0x0008D2, 12}, {0x00054C, 11}, {0x000686, 12}, -{0x000000, 2}, {0x000069, 8}, {0x00006B, 8}, {0x00068C, 12}, -{0x000007, 3}, {0x00015E, 9}, {0x0002A3, 10}, {0x000AE9, 12}, -{0x000006, 3}, {0x000231, 10}, {0x0002B8, 10}, {0x001A08, 14}, -{0x000010, 5}, {0x0001A9, 10}, {0x000342, 11}, {0x000A88, 12}, -{0x000004, 4}, {0x0001A2, 10}, {0x0002A4, 10}, {0x001184, 13}, -{0x000012, 5}, {0x000232, 10}, {0x0002B2, 10}, {0x000680, 12}, -{0x00001B, 6}, {0x00046A, 11}, {0x00068E, 12}, {0x002359, 14}, -{0x000016, 5}, {0x00015F, 9}, {0x0002A0, 10}, {0x00054D, 11}, -{0x000005, 4}, {0x000233, 10}, {0x0002B9, 10}, {0x0015D6, 13}, -{0x000022, 6}, {0x000468, 11}, {0x000683, 12}, {0x001A0A, 14}, -{0x000013, 5}, {0x000236, 10}, {0x0002BB, 10}, {0x001186, 13}, -{0x000017, 5}, {0x0001AB, 10}, {0x0002A7, 10}, {0x0008D3, 12}, -{0x000014, 5}, {0x000237, 10}, {0x000460, 11}, {0x000D0F, 13}, -{0x000019, 6}, {0x0001AA, 10}, {0x0002B3, 10}, {0x000681, 12}, -{0x000018, 6}, {0x0001A8, 10}, {0x0002A5, 10}, {0x00068F, 12}, -{0x000007, 4}, {0x000055, 7}, {0x000047, 7}, {0x0000AD, 8}, -}; +extern const uint8_t v2_mb_type[8][2]; +extern const uint8_t v2_intra_cbpc[4][2]; -static const uint32_t table_mb_non_intra4[128][2] = { -{0x0000D4, 8}, {0x0021C5, 14}, {0x00F18A, 16}, {0x00D5BC, 16}, -{0x000879, 12}, {0x00354D, 14}, {0x010E3F, 17}, {0x010F54, 17}, -{0x000866, 12}, {0x00356E, 14}, {0x010F55, 17}, {0x010E3E, 17}, -{0x0010CE, 13}, {0x003C84, 14}, {0x00D5BD, 16}, {0x00F18B, 16}, -{0x000868, 12}, {0x00438C, 15}, {0x0087AB, 16}, {0x00790B, 15}, -{0x000F10, 12}, {0x00433D, 15}, {0x006AD3, 15}, {0x00790A, 15}, -{0x001AA7, 13}, {0x0043D4, 15}, {0x00871E, 16}, {0x006ADF, 15}, -{0x000D7C, 12}, {0x003C94, 14}, {0x00438D, 15}, {0x006AD2, 15}, -{0x0006BC, 11}, {0x0021E9, 14}, {0x006ADA, 15}, {0x006A99, 15}, -{0x0010F7, 13}, {0x004389, 15}, {0x006ADB, 15}, {0x0078C4, 15}, -{0x000D56, 12}, {0x0035F7, 14}, {0x00438E, 15}, {0x006A98, 15}, -{0x000D52, 12}, {0x003C95, 14}, {0x004388, 15}, {0x00433C, 15}, -{0x000D54, 12}, {0x001E4B, 13}, {0x003C63, 14}, {0x003C83, 14}, -{0x000861, 12}, {0x0021EB, 14}, {0x00356C, 14}, {0x0035F6, 14}, -{0x000863, 12}, {0x00219F, 14}, {0x003568, 14}, {0x003C82, 14}, -{0x0001AE, 9}, {0x0010C0, 13}, {0x000F11, 12}, {0x001AFA, 13}, -{0x000000, 1}, {0x0000F0, 8}, {0x0001AD, 9}, {0x0010C1, 13}, -{0x00000A, 4}, {0x0003C5, 10}, {0x000789, 11}, {0x001AB5, 13}, -{0x000009, 4}, {0x000435, 11}, {0x000793, 11}, {0x001E40, 13}, -{0x00001D, 5}, {0x0003CB, 10}, {0x000878, 12}, {0x001AAF, 13}, -{0x00000B, 4}, {0x0003C7, 10}, {0x000791, 11}, {0x001AAB, 13}, -{0x00001F, 5}, {0x000436, 11}, {0x0006BF, 11}, {0x000F19, 12}, -{0x00003D, 6}, {0x000D51, 12}, {0x0010C4, 13}, {0x0021E8, 14}, -{0x000036, 6}, {0x000437, 11}, {0x0006AF, 11}, {0x0010C5, 13}, -{0x00000C, 4}, {0x000432, 11}, {0x000794, 11}, {0x001E30, 13}, -{0x000042, 7}, {0x000870, 12}, {0x000F24, 12}, {0x001E43, 13}, -{0x000020, 6}, {0x00043E, 11}, {0x000795, 11}, {0x001AAA, 13}, -{0x000037, 6}, {0x0006AC, 11}, {0x0006AE, 11}, {0x0010F6, 13}, -{0x000034, 6}, {0x00043A, 11}, {0x000D50, 12}, {0x001AAE, 13}, -{0x000039, 6}, {0x00043F, 11}, {0x00078D, 11}, {0x0010D2, 13}, -{0x000038, 6}, {0x00043B, 11}, {0x0006BD, 11}, {0x0010D3, 13}, -{0x000011, 5}, {0x0001AC, 9}, {0x0000F3, 8}, {0x000439, 11}, -}; +extern const uint32_t table_mb_non_intra[128][2]; +extern const uint8_t table_inter_intra[4][2]; -static const uint32_t (*wmv2_inter_table[WMV2_INTER_CBP_TABLE_COUNT])[2]={ - table_mb_non_intra2, - table_mb_non_intra3, - table_mb_non_intra4, - table_mb_non_intra, -}; +extern const uint32_t ff_table0_dc_lum[120][2]; +extern const uint32_t ff_table1_dc_lum[120][2]; +extern const uint32_t ff_table0_dc_chroma[120][2]; +extern const uint32_t ff_table1_dc_chroma[120][2]; + +#define WMV2_INTER_CBP_TABLE_COUNT 4 +extern const uint32_t (*wmv2_inter_table[WMV2_INTER_CBP_TABLE_COUNT])[2]; -static const uint8_t wmv2_scantableA[64]={ -0x00, 0x01, 0x02, 0x08, 0x03, 0x09, 0x0A, 0x10, -0x04, 0x0B, 0x11, 0x18, 0x12, 0x0C, 0x05, 0x13, -0x19, 0x0D, 0x14, 0x1A, 0x1B, 0x06, 0x15, 0x1C, -0x0E, 0x16, 0x1D, 0x07, 0x1E, 0x0F, 0x17, 0x1F, -}; +extern const uint8_t wmv2_scantableA[64]; +extern const uint8_t wmv2_scantableB[64]; -static const uint8_t wmv2_scantableB[64]={ -0x00, 0x08, 0x01, 0x10, 0x09, 0x18, 0x11, 0x02, -0x20, 0x0A, 0x19, 0x28, 0x12, 0x30, 0x21, 0x1A, -0x38, 0x29, 0x22, 0x03, 0x31, 0x39, 0x0B, 0x2A, -0x13, 0x32, 0x1B, 0x3A, 0x23, 0x2B, 0x33, 0x3B, -}; +#endif /* FFMPEG_MSMPEG4DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/msrle.c b/contrib/ffmpeg/libavcodec/msrle.c index fae5616e5..51893cbb7 100644 --- a/contrib/ffmpeg/libavcodec/msrle.c +++ b/contrib/ffmpeg/libavcodec/msrle.c @@ -36,7 +36,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include "dsputil.h" @@ -44,7 +43,7 @@ typedef struct MsrleContext { AVCodecContext *avctx; AVFrame frame; - unsigned char *buf; + const unsigned char *buf; int size; } MsrleContext; @@ -239,12 +238,11 @@ static void msrle_decode_pal8(MsrleContext *s) static int msrle_decode_init(AVCodecContext *avctx) { - MsrleContext *s = (MsrleContext *)avctx->priv_data; + MsrleContext *s = avctx->priv_data; s->avctx = avctx; avctx->pix_fmt = PIX_FMT_PAL8; - avctx->has_b_frames = 0; s->frame.data[0] = NULL; return 0; @@ -252,9 +250,9 @@ static int msrle_decode_init(AVCodecContext *avctx) static int msrle_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { - MsrleContext *s = (MsrleContext *)avctx->priv_data; + MsrleContext *s = avctx->priv_data; s->buf = buf; s->size = buf_size; @@ -287,7 +285,7 @@ static int msrle_decode_frame(AVCodecContext *avctx, static int msrle_decode_end(AVCodecContext *avctx) { - MsrleContext *s = (MsrleContext *)avctx->priv_data; + MsrleContext *s = avctx->priv_data; /* release the last frame */ if (s->frame.data[0]) diff --git a/contrib/ffmpeg/libavcodec/msvideo1.c b/contrib/ffmpeg/libavcodec/msvideo1.c index 1e3f6cce2..baac48a85 100644 --- a/contrib/ffmpeg/libavcodec/msvideo1.c +++ b/contrib/ffmpeg/libavcodec/msvideo1.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -36,7 +35,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include "dsputil.h" @@ -54,7 +52,7 @@ typedef struct Msvideo1Context { DSPContext dsp; AVFrame frame; - unsigned char *buf; + const unsigned char *buf; int size; int mode_8bit; /* if it's not 8-bit, it's 16-bit */ @@ -63,7 +61,7 @@ typedef struct Msvideo1Context { static int msvideo1_decode_init(AVCodecContext *avctx) { - Msvideo1Context *s = (Msvideo1Context *)avctx->priv_data; + Msvideo1Context *s = avctx->priv_data; s->avctx = avctx; @@ -76,7 +74,6 @@ static int msvideo1_decode_init(AVCodecContext *avctx) avctx->pix_fmt = PIX_FMT_RGB555; } - avctx->has_b_frames = 0; dsputil_init(&s->dsp, avctx); s->frame.data[0] = NULL; @@ -300,9 +297,9 @@ static void msvideo1_decode_16bit(Msvideo1Context *s) static int msvideo1_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { - Msvideo1Context *s = (Msvideo1Context *)avctx->priv_data; + Msvideo1Context *s = avctx->priv_data; s->buf = buf; s->size = buf_size; @@ -328,7 +325,7 @@ static int msvideo1_decode_frame(AVCodecContext *avctx, static int msvideo1_decode_end(AVCodecContext *avctx) { - Msvideo1Context *s = (Msvideo1Context *)avctx->priv_data; + Msvideo1Context *s = avctx->priv_data; if (s->frame.data[0]) avctx->release_buffer(avctx, &s->frame); diff --git a/contrib/ffmpeg/libavcodec/nellymoserdec.c b/contrib/ffmpeg/libavcodec/nellymoserdec.c new file mode 100644 index 000000000..7c83bd562 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/nellymoserdec.c @@ -0,0 +1,411 @@ +/* + * NellyMoser audio decoder + * Copyright (c) 2007 a840bda5870ba11f19698ff6eb9581dfb0f95fa5, + * 539459aeb7d425140b62a3ec7dbf6dc8e408a306, and + * 520e17cd55896441042b14df2566a6eb610ed444 + * Copyright (c) 2007 Loic Minier + * Benjamin Larsson + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * @file nellymoserdec.c + * The 3 alphanumeric copyright notices are md5summed they are from the original + * implementors. The original code is available from http://code.google.com/p/nelly2pcm/ + */ +#include "avcodec.h" +#include "random.h" +#include "dsputil.h" + +#define ALT_BITSTREAM_READER_LE +#include "bitstream.h" + +#define NELLY_BANDS 23 +#define NELLY_BLOCK_LEN 64 +#define NELLY_HEADER_BITS 116 +#define NELLY_DETAIL_BITS 198 +#define NELLY_BUF_LEN 128 +#define NELLY_FILL_LEN 124 +#define NELLY_BIT_CAP 6 +#define NELLY_BASE_OFF 4228 +#define NELLY_BASE_SHIFT 19 +#define NELLY_SAMPLES (2 * NELLY_BUF_LEN) + +static const float dequantization_table[127] = { +0.0000000000,-0.8472560048, 0.7224709988, -1.5247479677, -0.4531480074, 0.3753609955, 1.4717899561, +-1.9822579622, -1.1929379702, -0.5829370022, -0.0693780035, 0.3909569979,0.9069200158, 1.4862740040, + 2.2215409279, -2.3887870312, -1.8067539930, -1.4105420113, -1.0773609877, -0.7995010018,-0.5558109879, +-0.3334020078, -0.1324490011, 0.0568020009, 0.2548770010, 0.4773550034, 0.7386850119, 1.0443060398, +1.3954459429, 1.8098750114, 2.3918759823,-2.3893830776, -1.9884680510, -1.7514040470, -1.5643119812, +-1.3922129869,-1.2164649963, -1.0469499826, -0.8905100226, -0.7645580173, -0.6454579830, -0.5259280205, +-0.4059549868, -0.3029719889, -0.2096900046, -0.1239869967, -0.0479229987, 0.0257730000, 0.1001340002, +0.1737180054, 0.2585540116, 0.3522900045, 0.4569880068, 0.5767750144, 0.7003160119, 0.8425520062, +1.0093879700, 1.1821349859, 1.3534560204, 1.5320819616, 1.7332619429, 1.9722349644, 2.3978140354, +-2.5756309032, -2.0573320389, -1.8984919786, -1.7727810144, -1.6662600040, -1.5742180347, -1.4993319511, +-1.4316639900, -1.3652280569, -1.3000990152, -1.2280930281, -1.1588579416, -1.0921250582, -1.0135740042, +-0.9202849865, -0.8287050128, -0.7374889851, -0.6447759867, -0.5590940118, -0.4857139885, -0.4110319912, +-0.3459700048, -0.2851159871, -0.2341620028, -0.1870580018, -0.1442500055, -0.1107169986, -0.0739680007, +-0.0365610011, -0.0073290002, 0.0203610007, 0.0479039997, 0.0751969963, 0.0980999991, 0.1220389977, +0.1458999962, 0.1694349945, 0.1970459968, 0.2252430022, 0.2556869984, 0.2870100141, 0.3197099864, +0.3525829911, 0.3889069855, 0.4334920049, 0.4769459963, 0.5204820037, 0.5644530058, 0.6122040153, +0.6685929894, 0.7341650128, 0.8032159805, 0.8784040213, 0.9566209912, 1.0397069454, 1.1293770075, +1.2211159468, 1.3080279827, 1.4024800062, 1.5056819916, 1.6227730513, 1.7724959850, 1.9430880547, + 2.2903931141 +}; + +static const uint8_t nelly_band_sizes_table[NELLY_BANDS] = { +2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 9, 10, 12, 14, 15 +}; + +static const uint16_t nelly_init_table[64] = { +3134, 5342, 6870, 7792, 8569, 9185, 9744, 10191, 10631, 11061, 11434, 11770, +12116, 12513, 12925, 13300, 13674, 14027, 14352, 14716, 15117, 15477, 15824, +16157, 16513, 16804, 17090, 17401, 17679, 17948, 18238, 18520, 18764, 19078, +19381, 19640, 19921, 20205, 20500, 20813, 21162, 21465, 21794, 22137, 22453, +22756, 23067, 23350, 23636, 23926, 24227, 24521, 24819, 25107, 25414, 25730, +26120, 26497, 26895, 27344, 27877, 28463, 29426, 31355 +}; + +static const int16_t nelly_delta_table[32] = { +-11725, -9420, -7910, -6801, -5948, -5233, -4599, -4039, -3507, -3030, -2596, +-2170, -1774, -1383, -1016, -660, -329, -1, 337, 696, 1085, 1512, 1962, 2433, +2968, 3569, 4314, 5279, 6622, 8154, 10076, 12975 +}; + +typedef struct NellyMoserDecodeContext { + AVCodecContext* avctx; + DECLARE_ALIGNED_16(float,float_buf[NELLY_SAMPLES]); + float state[64]; + AVRandomState random_state; + GetBitContext gb; + int add_bias; + int scale_bias; + DSPContext dsp; + MDCTContext imdct_ctx; + DECLARE_ALIGNED_16(float,imdct_tmp[NELLY_BUF_LEN]); + DECLARE_ALIGNED_16(float,imdct_out[NELLY_BUF_LEN * 2]); +} NellyMoserDecodeContext; + +static DECLARE_ALIGNED_16(float,sine_window[128]); + +static inline int signed_shift(int i, int shift) { + if (shift > 0) + return i << shift; + return i >> -shift; +} + +static void overlap_and_window(NellyMoserDecodeContext *s, float *state, float *audio) +{ + int bot, mid_up, mid_down, top; + float s_bot, s_top; + + bot = 0; + top = NELLY_BUF_LEN-1; + mid_up = NELLY_BUF_LEN/2; + mid_down = (NELLY_BUF_LEN/2)-1; + + while (bot < NELLY_BUF_LEN/4) { + s_bot = audio[bot]; + s_top = -audio[top]; + audio[bot] = (-audio[mid_up]*sine_window[bot]-state[bot ]*sine_window[top])/s->scale_bias + s->add_bias; + audio[top] = (-state[bot ]*sine_window[bot]+audio[mid_up]*sine_window[top])/s->scale_bias + s->add_bias; + state[bot] = audio[mid_down]; + + audio[mid_down] = (s_top *sine_window[mid_down]-state[mid_down]*sine_window[mid_up])/s->scale_bias + s->add_bias; + audio[mid_up ] = (-state[mid_down]*sine_window[mid_down]-s_top *sine_window[mid_up])/s->scale_bias + s->add_bias; + state[mid_down] = s_bot; + + bot++; + mid_up++; + mid_down--; + top--; + } +} + +static int sum_bits(short *buf, short shift, short off) +{ + int b, i = 0, ret = 0; + + for (i = 0; i < NELLY_FILL_LEN; i++) { + b = buf[i]-off; + b = ((b>>(shift-1))+1)>>1; + ret += av_clip(b, 0, NELLY_BIT_CAP); + } + + return ret; +} + +static int headroom(int *la) +{ + int l; + if (*la == 0) { + return 31; + } + l = 30 - av_log2(FFABS(*la)); + *la <<= l; + return l; +} + + +static void get_sample_bits(const float *buf, int *bits) +{ + int i, j; + short sbuf[128]; + int bitsum = 0, last_bitsum, small_bitsum, big_bitsum; + short shift, shift_saved; + int max, sum, last_off, tmp; + int big_off, small_off; + int off; + + max = 0; + for (i = 0; i < NELLY_FILL_LEN; i++) { + max = FFMAX(max, buf[i]); + } + shift = -16; + shift += headroom(&max); + + sum = 0; + for (i = 0; i < NELLY_FILL_LEN; i++) { + sbuf[i] = signed_shift(buf[i], shift); + sbuf[i] = (3*sbuf[i])>>2; + sum += sbuf[i]; + } + + shift += 11; + shift_saved = shift; + sum -= NELLY_DETAIL_BITS << shift; + shift += headroom(&sum); + small_off = (NELLY_BASE_OFF * (sum>>16)) >> 15; + shift = shift_saved - (NELLY_BASE_SHIFT+shift-31); + + small_off = signed_shift(small_off, shift); + + bitsum = sum_bits(sbuf, shift_saved, small_off); + + if (bitsum != NELLY_DETAIL_BITS) { + shift = 0; + off = bitsum - NELLY_DETAIL_BITS; + + for(shift=0; FFABS(off) <= 16383; shift++) + off *= 2; + + off = (off * NELLY_BASE_OFF) >> 15; + shift = shift_saved-(NELLY_BASE_SHIFT+shift-15); + + off = signed_shift(off, shift); + + for (j = 1; j < 20; j++) { + last_off = small_off; + small_off += off; + last_bitsum = bitsum; + + bitsum = sum_bits(sbuf, shift_saved, small_off); + + if ((bitsum-NELLY_DETAIL_BITS) * (last_bitsum-NELLY_DETAIL_BITS) <= 0) + break; + } + + if (bitsum > NELLY_DETAIL_BITS) { + big_off = small_off; + small_off = last_off; + big_bitsum=bitsum; + small_bitsum=last_bitsum; + } else { + big_off = last_off; + big_bitsum=last_bitsum; + small_bitsum=bitsum; + } + + while (bitsum != NELLY_DETAIL_BITS && j <= 19) { + off = (big_off+small_off)>>1; + bitsum = sum_bits(sbuf, shift_saved, off); + if (bitsum > NELLY_DETAIL_BITS) { + big_off=off; + big_bitsum=bitsum; + } else { + small_off = off; + small_bitsum=bitsum; + } + j++; + } + + if (abs(big_bitsum-NELLY_DETAIL_BITS) >= + abs(small_bitsum-NELLY_DETAIL_BITS)) { + bitsum = small_bitsum; + } else { + small_off = big_off; + bitsum = big_bitsum; + } + } + + for (i = 0; i < NELLY_FILL_LEN; i++) { + tmp = sbuf[i]-small_off; + tmp = ((tmp>>(shift_saved-1))+1)>>1; + bits[i] = av_clip(tmp, 0, NELLY_BIT_CAP); + } + + if (bitsum > NELLY_DETAIL_BITS) { + tmp = i = 0; + while (tmp < NELLY_DETAIL_BITS) { + tmp += bits[i]; + i++; + } + + bits[i-1] -= tmp - NELLY_DETAIL_BITS; + for(; i < NELLY_FILL_LEN; i++) + bits[i] = 0; + } +} + +void nelly_decode_block(NellyMoserDecodeContext *s, const unsigned char block[NELLY_BLOCK_LEN], float audio[NELLY_SAMPLES]) +{ + int i,j; + float buf[NELLY_FILL_LEN], pows[NELLY_FILL_LEN]; + float *aptr, *bptr, *pptr, val, pval; + int bits[NELLY_BUF_LEN]; + unsigned char v; + + init_get_bits(&s->gb, block, NELLY_BLOCK_LEN * 8); + + bptr = buf; + pptr = pows; + val = nelly_init_table[get_bits(&s->gb, 6)]; + for (i=0 ; i 0) + val += nelly_delta_table[get_bits(&s->gb, 5)]; + pval = pow(2, val/2048); + for (j = 0; j < nelly_band_sizes_table[i]; j++) { + *bptr++ = val; + *pptr++ = pval; + } + + } + + get_sample_bits(buf, bits); + + for (i = 0; i < 2; i++) { + aptr = audio + i * NELLY_BUF_LEN; + + init_get_bits(&s->gb, block, NELLY_BLOCK_LEN * 8); + skip_bits(&s->gb, NELLY_HEADER_BITS + i*NELLY_DETAIL_BITS); + + for (j = 0; j < NELLY_FILL_LEN; j++) { + if (bits[j] <= 0) { + aptr[j] = M_SQRT1_2*pows[j]; + if (av_random(&s->random_state) & 1) + aptr[j] *= -1.0; + } else { + v = get_bits(&s->gb, bits[j]); + aptr[j] = dequantization_table[(1<imdct_ctx.fft.imdct_calc(&s->imdct_ctx, s->imdct_out, + aptr, s->imdct_tmp); + /* XXX: overlapping and windowing should be part of a more + generic imdct function */ + memcpy(&aptr[0],&s->imdct_out[NELLY_BUF_LEN+NELLY_BUF_LEN/2], (NELLY_BUF_LEN/2)*sizeof(float)); + memcpy(&aptr[NELLY_BUF_LEN / 2],&s->imdct_out[0],(NELLY_BUF_LEN/2)*sizeof(float)); + overlap_and_window(s, s->state, aptr); + } +} + +static int decode_init(AVCodecContext * avctx) { + NellyMoserDecodeContext *s = avctx->priv_data; + int i; + + s->avctx = avctx; + av_init_random(0, &s->random_state); + ff_mdct_init(&s->imdct_ctx, 8, 1); + + dsputil_init(&s->dsp, avctx); + + if(s->dsp.float_to_int16 == ff_float_to_int16_c) { + s->add_bias = 385; + s->scale_bias = 8*32768; + } else { + s->add_bias = 0; + s->scale_bias = 1*8; + } + + /* Generate overlap window */ + if (!sine_window[0]) + for (i=0 ; i<128; i++) { + sine_window[i] = sin((i + 0.5) / 256.0 * M_PI); + } + + return 0; +} + +static int decode_tag(AVCodecContext * avctx, + void *data, int *data_size, + const uint8_t * buf, int buf_size) { + NellyMoserDecodeContext *s = avctx->priv_data; + int blocks, i; + int16_t* samples; + *data_size = 0; + samples = (int16_t*)data; + + if (buf_size < avctx->block_align) + return buf_size; + + switch (buf_size) { + case 64: // 8000Hz + blocks = 1; break; + case 128: // 11025Hz + blocks = 2; break; + case 256: // 22050Hz + blocks = 4; break; + case 512: // 44100Hz + blocks = 8; break; + default: + av_log(avctx, AV_LOG_ERROR, "Tag size %d unknown, report sample!\n", buf_size); + return buf_size; + } + + for (i=0 ; ifloat_buf); + s->dsp.float_to_int16(&samples[i*NELLY_SAMPLES], s->float_buf, NELLY_SAMPLES); + *data_size += NELLY_SAMPLES*sizeof(int16_t); + } + + return buf_size; +} + +static int decode_end(AVCodecContext * avctx) { + NellyMoserDecodeContext *s = avctx->priv_data; + + ff_mdct_end(&s->imdct_ctx); + return 0; +} + +AVCodec nellymoser_decoder = { + "nellymoser", + CODEC_TYPE_AUDIO, + CODEC_ID_NELLYMOSER, + sizeof(NellyMoserDecodeContext), + decode_init, + NULL, + decode_end, + decode_tag, +}; + diff --git a/contrib/ffmpeg/libavcodec/noise_bsf.c b/contrib/ffmpeg/libavcodec/noise_bsf.c new file mode 100644 index 000000000..c49dd1f9d --- /dev/null +++ b/contrib/ffmpeg/libavcodec/noise_bsf.c @@ -0,0 +1,46 @@ +/* + * copyright (c) 2006 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" + + +static int noise(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, + uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size, int keyframe){ + unsigned int *state= bsfc->priv_data; + int amount= args ? atoi(args) : (*state % 10001+1); + int i; + + *poutbuf= av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); + + memcpy(*poutbuf, buf, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); + for(i=0; i #include -#include "common.h" #include "avcodec.h" #include "bswap.h" @@ -31,6 +30,8 @@ typedef struct { AVFrame pic; + int codec_frameheader; + int quality; int width, height; unsigned int decomp_size; unsigned char* decomp_buf; @@ -39,6 +40,28 @@ typedef struct { DSPContext dsp; } NuvContext; +static const uint8_t fallback_lquant[] = { + 16, 11, 10, 16, 24, 40, 51, 61, + 12, 12, 14, 19, 26, 58, 60, 55, + 14, 13, 16, 24, 40, 57, 69, 56, + 14, 17, 22, 29, 51, 87, 80, 62, + 18, 22, 37, 56, 68, 109, 103, 77, + 24, 35, 55, 64, 81, 104, 113, 92, + 49, 64, 78, 87, 103, 121, 120, 101, + 72, 92, 95, 98, 112, 100, 103, 99 +}; + +static const uint8_t fallback_cquant[] = { + 17, 18, 24, 47, 99, 99, 99, 99, + 18, 21, 26, 66, 99, 99, 99, 99, + 24, 26, 56, 99, 99, 99, 99, 99, + 47, 66, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99, + 99, 99, 99, 99, 99, 99, 99, 99 +}; + /** * \brief copy frame data from buffer to AVFrame, handling stride. * \param f destination AVFrame @@ -46,7 +69,7 @@ typedef struct { * \param width width of the video frame * \param height height of the video frame */ -static void copy_frame(AVFrame *f, uint8_t *src, +static void copy_frame(AVFrame *f, const uint8_t *src, int width, int height) { AVPicture pic; avpicture_fill(&pic, src, PIX_FMT_YUV420P, width, height); @@ -57,7 +80,7 @@ static void copy_frame(AVFrame *f, uint8_t *src, * \brief extract quantization tables from codec data into our context */ static int get_quant(AVCodecContext *avctx, NuvContext *c, - uint8_t *buf, int size) { + const uint8_t *buf, int size) { int i; if (size < 2 * 64 * 4) { av_log(avctx, AV_LOG_ERROR, "insufficient rtjpeg quant data\n"); @@ -70,9 +93,44 @@ static int get_quant(AVCodecContext *avctx, NuvContext *c, return 0; } +/** + * \brief set quantization tables from a quality value + */ +static void get_quant_quality(NuvContext *c, int quality) { + int i; + quality = FFMAX(quality, 1); + for (i = 0; i < 64; i++) { + c->lq[i] = (fallback_lquant[i] << 7) / quality; + c->cq[i] = (fallback_cquant[i] << 7) / quality; + } +} + +static int codec_reinit(AVCodecContext *avctx, int width, int height, int quality) { + NuvContext *c = avctx->priv_data; + width = (width + 1) & ~1; + height = (height + 1) & ~1; + if (quality >= 0) + get_quant_quality(c, quality); + if (width != c->width || height != c->height) { + if (avcodec_check_dimensions(avctx, height, width) < 0) + return 0; + avctx->width = c->width = width; + avctx->height = c->height = height; + c->decomp_size = c->height * c->width * 3 / 2; + c->decomp_buf = av_realloc(c->decomp_buf, c->decomp_size + LZO_OUTPUT_PADDING); + if (!c->decomp_buf) { + av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n"); + return 0; + } + rtjpeg_decode_init(&c->rtj, &c->dsp, c->width, c->height, c->lq, c->cq); + } else if (quality != c->quality) + rtjpeg_decode_init(&c->rtj, &c->dsp, c->width, c->height, c->lq, c->cq); + return 1; +} + static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) { - NuvContext *c = (NuvContext *)avctx->priv_data; + const uint8_t *buf, int buf_size) { + NuvContext *c = avctx->priv_data; AVFrame *picture = data; int orig_size = buf_size; enum {NUV_UNCOMPRESSED = '0', NUV_RTJPEG = '1', @@ -84,16 +142,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, return -1; } - if (c->pic.data[0]) - avctx->release_buffer(avctx, &c->pic); - c->pic.reference = 1; - c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE | - FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; - if (avctx->get_buffer(avctx, &c->pic) < 0) { - av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; - } - // codec data (rtjpeg quant tables) if (buf[0] == 'D' && buf[1] == 'R') { int ret; @@ -115,11 +163,43 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, // skip rest of the frameheader. buf = &buf[12]; buf_size -= 12; + if (comptype == NUV_RTJPEG_IN_LZO || comptype == NUV_LZO) { + int outlen = c->decomp_size, inlen = buf_size; + if (lzo1x_decode(c->decomp_buf, &outlen, buf, &inlen)) + av_log(avctx, AV_LOG_ERROR, "error during lzo decompression\n"); + buf = c->decomp_buf; + buf_size = c->decomp_size; + } + if (c->codec_frameheader) { + int w, h, q; + if (buf_size < 12) { + av_log(avctx, AV_LOG_ERROR, "invalid nuv video frame\n"); + return -1; + } + w = AV_RL16(&buf[6]); + h = AV_RL16(&buf[8]); + q = buf[10]; + if (!codec_reinit(avctx, w, h, q)) + return -1; + buf = &buf[12]; + buf_size -= 12; + } + + if (c->pic.data[0]) + avctx->release_buffer(avctx, &c->pic); + c->pic.reference = 1; + c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE | + FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + if (avctx->get_buffer(avctx, &c->pic) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } c->pic.pict_type = FF_I_TYPE; c->pic.key_frame = 1; // decompress/copy/whatever data switch (comptype) { + case NUV_LZO: case NUV_UNCOMPRESSED: { int height = c->height; if (buf_size < c->width * height * 3 / 2) { @@ -129,24 +209,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, copy_frame(&c->pic, buf, c->width, height); break; } + case NUV_RTJPEG_IN_LZO: case NUV_RTJPEG: { rtjpeg_decode_frame_yuv420(&c->rtj, &c->pic, buf, buf_size); break; } - case NUV_RTJPEG_IN_LZO: { - int outlen = c->decomp_size, inlen = buf_size; - if (lzo1x_decode(c->decomp_buf, &outlen, buf, &inlen)) - av_log(avctx, AV_LOG_ERROR, "error during lzo decompression\n"); - rtjpeg_decode_frame_yuv420(&c->rtj, &c->pic, c->decomp_buf, c->decomp_size); - break; - } - case NUV_LZO: { - int outlen = c->decomp_size, inlen = buf_size; - if (lzo1x_decode(c->decomp_buf, &outlen, buf, &inlen)) - av_log(avctx, AV_LOG_ERROR, "error during lzo decompression\n"); - copy_frame(&c->pic, c->decomp_buf, c->width, c->height); - break; - } case NUV_BLACK: { memset(c->pic.data[0], 0, c->width * c->height); memset(c->pic.data[1], 128, c->width * c->height / 4); @@ -170,32 +237,24 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, } static int decode_init(AVCodecContext *avctx) { - NuvContext *c = (NuvContext *)avctx->priv_data; - avctx->width = (avctx->width + 1) & ~1; - avctx->height = (avctx->height + 1) & ~1; - if (avcodec_check_dimensions(avctx, avctx->height, avctx->width) < 0) { - return 1; - } - avctx->has_b_frames = 0; + NuvContext *c = avctx->priv_data; avctx->pix_fmt = PIX_FMT_YUV420P; c->pic.data[0] = NULL; - c->width = avctx->width; - c->height = avctx->height; - c->decomp_size = c->height * c->width * 3 / 2; - c->decomp_buf = av_malloc(c->decomp_size + LZO_OUTPUT_PADDING); - if (!c->decomp_buf) { - av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n"); - return 1; - } - dsputil_init(&c->dsp, avctx); + c->decomp_buf = NULL; + c->quality = -1; + c->width = 0; + c->height = 0; + c->codec_frameheader = avctx->codec_tag == MKTAG('R', 'J', 'P', 'G'); if (avctx->extradata_size) get_quant(avctx, c, avctx->extradata, avctx->extradata_size); - rtjpeg_decode_init(&c->rtj, &c->dsp, c->width, c->height, c->lq, c->cq); + dsputil_init(&c->dsp, avctx); + if (!codec_reinit(avctx, avctx->width, avctx->height, -1)) + return 1; return 0; } static int decode_end(AVCodecContext *avctx) { - NuvContext *c = (NuvContext *)avctx->priv_data; + NuvContext *c = avctx->priv_data; av_freep(&c->decomp_buf); if (c->pic.data[0]) avctx->release_buffer(avctx, &c->pic); diff --git a/contrib/ffmpeg/libavcodec/oggvorbis.c b/contrib/ffmpeg/libavcodec/oggvorbis.c deleted file mode 100644 index da97e9a78..000000000 --- a/contrib/ffmpeg/libavcodec/oggvorbis.c +++ /dev/null @@ -1,383 +0,0 @@ -/* - * copyright (c) 2002 Mark Hills - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file oggvorbis.c - * Ogg Vorbis codec support via libvorbisenc. - * @author Mark Hills - */ - -#include - -#include "avcodec.h" - -#undef NDEBUG -#include - -#define OGGVORBIS_FRAME_SIZE 64 - -#define BUFFER_SIZE (1024*64) - -typedef struct OggVorbisContext { - vorbis_info vi ; - vorbis_dsp_state vd ; - vorbis_block vb ; - uint8_t buffer[BUFFER_SIZE]; - int buffer_index; - - /* decoder */ - vorbis_comment vc ; - ogg_packet op; -} OggVorbisContext ; - - -static int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) { - double cfreq; - - if(avccontext->flags & CODEC_FLAG_QSCALE) { - /* variable bitrate */ - if(vorbis_encode_setup_vbr(vi, avccontext->channels, - avccontext->sample_rate, - avccontext->global_quality / (float)FF_QP2LAMBDA)) - return -1; - } else { - /* constant bitrate */ - if(vorbis_encode_setup_managed(vi, avccontext->channels, - avccontext->sample_rate, -1, avccontext->bit_rate, -1)) - return -1; - -#ifdef OGGVORBIS_VBR_BY_ESTIMATE - /* variable bitrate by estimate */ - if(vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE_AVG, NULL)) - return -1; -#endif - } - - /* cutoff frequency */ - if(avccontext->cutoff > 0) { - cfreq = avccontext->cutoff / 1000.0; - if(vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq)) - return -1; - } - - return vorbis_encode_setup_init(vi); -} - -static int oggvorbis_encode_init(AVCodecContext *avccontext) { - OggVorbisContext *context = avccontext->priv_data ; - ogg_packet header, header_comm, header_code; - uint8_t *p; - unsigned int offset, len; - - vorbis_info_init(&context->vi) ; - if(oggvorbis_init_encoder(&context->vi, avccontext) < 0) { - av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init: init_encoder failed") ; - return -1 ; - } - vorbis_analysis_init(&context->vd, &context->vi) ; - vorbis_block_init(&context->vd, &context->vb) ; - - vorbis_comment_init(&context->vc); - vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT) ; - - vorbis_analysis_headerout(&context->vd, &context->vc, &header, - &header_comm, &header_code); - - len = header.bytes + header_comm.bytes + header_code.bytes; - avccontext->extradata_size= 64 + len + len/255; - p = avccontext->extradata= av_mallocz(avccontext->extradata_size); - p[0] = 2; - offset = 1; - offset += av_xiphlacing(&p[offset], header.bytes); - offset += av_xiphlacing(&p[offset], header_comm.bytes); - memcpy(&p[offset], header.packet, header.bytes); - offset += header.bytes; - memcpy(&p[offset], header_comm.packet, header_comm.bytes); - offset += header_comm.bytes; - memcpy(&p[offset], header_code.packet, header_code.bytes); - offset += header_code.bytes; - avccontext->extradata_size = offset; - avccontext->extradata= av_realloc(avccontext->extradata, avccontext->extradata_size); - -/* vorbis_block_clear(&context->vb); - vorbis_dsp_clear(&context->vd); - vorbis_info_clear(&context->vi);*/ - vorbis_comment_clear(&context->vc); - - avccontext->frame_size = OGGVORBIS_FRAME_SIZE ; - - avccontext->coded_frame= avcodec_alloc_frame(); - avccontext->coded_frame->key_frame= 1; - - return 0 ; -} - - -static int oggvorbis_encode_frame(AVCodecContext *avccontext, - unsigned char *packets, - int buf_size, void *data) -{ - OggVorbisContext *context = avccontext->priv_data ; - float **buffer ; - ogg_packet op ; - signed short *audio = data ; - int l, samples = data ? OGGVORBIS_FRAME_SIZE : 0; - - buffer = vorbis_analysis_buffer(&context->vd, samples) ; - - if(context->vi.channels == 1) { - for(l = 0 ; l < samples ; l++) - buffer[0][l]=audio[l]/32768.f; - } else { - for(l = 0 ; l < samples ; l++){ - buffer[0][l]=audio[l*2]/32768.f; - buffer[1][l]=audio[l*2+1]/32768.f; - } - } - - vorbis_analysis_wrote(&context->vd, samples) ; - - while(vorbis_analysis_blockout(&context->vd, &context->vb) == 1) { - vorbis_analysis(&context->vb, NULL); - vorbis_bitrate_addblock(&context->vb) ; - - while(vorbis_bitrate_flushpacket(&context->vd, &op)) { - /* i'd love to say the following line is a hack, but sadly it's - * not, apparently the end of stream decision is in libogg. */ - if(op.bytes==1) - continue; - memcpy(context->buffer + context->buffer_index, &op, sizeof(ogg_packet)); - context->buffer_index += sizeof(ogg_packet); - memcpy(context->buffer + context->buffer_index, op.packet, op.bytes); - context->buffer_index += op.bytes; -// av_log(avccontext, AV_LOG_DEBUG, "e%d / %d\n", context->buffer_index, op.bytes); - } - } - - l=0; - if(context->buffer_index){ - ogg_packet *op2= (ogg_packet*)context->buffer; - op2->packet = context->buffer + sizeof(ogg_packet); - - l= op2->bytes; - avccontext->coded_frame->pts= av_rescale_q(op2->granulepos, (AVRational){1, avccontext->sample_rate}, avccontext->time_base); - //FIXME we should reorder the user supplied pts and not assume that they are spaced by 1/sample_rate - - memcpy(packets, op2->packet, l); - context->buffer_index -= l + sizeof(ogg_packet); - memcpy(context->buffer, context->buffer + l + sizeof(ogg_packet), context->buffer_index); -// av_log(avccontext, AV_LOG_DEBUG, "E%d\n", l); - } - - return l; -} - - -static int oggvorbis_encode_close(AVCodecContext *avccontext) { - OggVorbisContext *context = avccontext->priv_data ; -/* ogg_packet op ; */ - - vorbis_analysis_wrote(&context->vd, 0) ; /* notify vorbisenc this is EOF */ - - vorbis_block_clear(&context->vb); - vorbis_dsp_clear(&context->vd); - vorbis_info_clear(&context->vi); - - av_freep(&avccontext->coded_frame); - av_freep(&avccontext->extradata); - - return 0 ; -} - - -AVCodec oggvorbis_encoder = { - "vorbis", - CODEC_TYPE_AUDIO, - CODEC_ID_VORBIS, - sizeof(OggVorbisContext), - oggvorbis_encode_init, - oggvorbis_encode_frame, - oggvorbis_encode_close, - .capabilities= CODEC_CAP_DELAY, -} ; - -static int oggvorbis_decode_init(AVCodecContext *avccontext) { - OggVorbisContext *context = avccontext->priv_data ; - uint8_t *p= avccontext->extradata; - int i, hsizes[3]; - unsigned char *headers[3], *extradata = avccontext->extradata; - - vorbis_info_init(&context->vi) ; - vorbis_comment_init(&context->vc) ; - - if(! avccontext->extradata_size || ! p) { - av_log(avccontext, AV_LOG_ERROR, "vorbis extradata absent\n"); - return -1; - } - - if(p[0] == 0 && p[1] == 30) { - for(i = 0; i < 3; i++){ - hsizes[i] = *p++ << 8; - hsizes[i] += *p++; - headers[i] = p; - p += hsizes[i]; - } - } else if(*p == 2) { - unsigned int offset = 1; - p++; - for(i=0; i<2; i++) { - hsizes[i] = 0; - while((*p == 0xFF) && (offset < avccontext->extradata_size)) { - hsizes[i] += 0xFF; - offset++; - p++; - } - if(offset >= avccontext->extradata_size - 1) { - av_log(avccontext, AV_LOG_ERROR, - "vorbis header sizes damaged\n"); - return -1; - } - hsizes[i] += *p; - offset++; - p++; - } - hsizes[2] = avccontext->extradata_size - hsizes[0]-hsizes[1]-offset; -#if 0 - av_log(avccontext, AV_LOG_DEBUG, - "vorbis header sizes: %d, %d, %d, / extradata_len is %d \n", - hsizes[0], hsizes[1], hsizes[2], avccontext->extradata_size); -#endif - headers[0] = extradata + offset; - headers[1] = extradata + offset + hsizes[0]; - headers[2] = extradata + offset + hsizes[0] + hsizes[1]; - } else { - av_log(avccontext, AV_LOG_ERROR, - "vorbis initial header len is wrong: %d\n", *p); - return -1; - } - - for(i=0; i<3; i++){ - context->op.b_o_s= i==0; - context->op.bytes = hsizes[i]; - context->op.packet = headers[i]; - if(vorbis_synthesis_headerin(&context->vi, &context->vc, &context->op)<0){ - av_log(avccontext, AV_LOG_ERROR, "%d. vorbis header damaged\n", i+1); - return -1; - } - } - - avccontext->channels = context->vi.channels; - avccontext->sample_rate = context->vi.rate; - avccontext->time_base= (AVRational){1, avccontext->sample_rate}; - - vorbis_synthesis_init(&context->vd, &context->vi); - vorbis_block_init(&context->vd, &context->vb); - - return 0 ; -} - - -static inline int conv(int samples, float **pcm, char *buf, int channels) { - int i, j, val ; - ogg_int16_t *ptr, *data = (ogg_int16_t*)buf ; - float *mono ; - - for(i = 0 ; i < channels ; i++){ - ptr = &data[i]; - mono = pcm[i] ; - - for(j = 0 ; j < samples ; j++) { - - val = mono[j] * 32767.f; - - if(val > 32767) val = 32767 ; - if(val < -32768) val = -32768 ; - - *ptr = val ; - ptr += channels; - } - } - - return 0 ; -} - - -static int oggvorbis_decode_frame(AVCodecContext *avccontext, - void *data, int *data_size, - uint8_t *buf, int buf_size) -{ - OggVorbisContext *context = avccontext->priv_data ; - float **pcm ; - ogg_packet *op= &context->op; - int samples, total_samples, total_bytes; - - if(!buf_size){ - //FIXME flush - return 0; - } - - op->packet = buf; - op->bytes = buf_size; - -// av_log(avccontext, AV_LOG_DEBUG, "%d %d %d %"PRId64" %"PRId64" %d %d\n", op->bytes, op->b_o_s, op->e_o_s, op->granulepos, op->packetno, buf_size, context->vi.rate); - -/* for(i=0; ibytes; i++) - av_log(avccontext, AV_LOG_DEBUG, "%02X ", op->packet[i]); - av_log(avccontext, AV_LOG_DEBUG, "\n");*/ - - if(vorbis_synthesis(&context->vb, op) == 0) - vorbis_synthesis_blockin(&context->vd, &context->vb) ; - - total_samples = 0 ; - total_bytes = 0 ; - - while((samples = vorbis_synthesis_pcmout(&context->vd, &pcm)) > 0) { - conv(samples, pcm, (char*)data + total_bytes, context->vi.channels) ; - total_bytes += samples * 2 * context->vi.channels ; - total_samples += samples ; - vorbis_synthesis_read(&context->vd, samples) ; - } - - *data_size = total_bytes ; - return buf_size ; -} - - -static int oggvorbis_decode_close(AVCodecContext *avccontext) { - OggVorbisContext *context = avccontext->priv_data ; - - vorbis_info_clear(&context->vi) ; - vorbis_comment_clear(&context->vc) ; - - return 0 ; -} - - -AVCodec oggvorbis_decoder = { - "vorbis", - CODEC_TYPE_AUDIO, - CODEC_ID_VORBIS, - sizeof(OggVorbisContext), - oggvorbis_decode_init, - NULL, - oggvorbis_decode_close, - oggvorbis_decode_frame, - .capabilities= CODEC_CAP_DELAY, -} ; diff --git a/contrib/ffmpeg/libavcodec/opt.c b/contrib/ffmpeg/libavcodec/opt.c index 97b593cb2..42e8eff9f 100644 --- a/contrib/ffmpeg/libavcodec/opt.c +++ b/contrib/ffmpeg/libavcodec/opt.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -70,6 +69,7 @@ static const AVOption *av_set_number(void *obj, const char *name, double num, in case FF_OPT_TYPE_RATIONAL: if((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den}; else *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24); + break; default: return NULL; } @@ -108,6 +108,13 @@ static const char *const_names[]={ 0 }; +static int hexchar2int(char c) { + if (c >= '0' && c <= '9') return c - '0'; + if (c >= 'a' && c <= 'f') return c - 'a' + 10; + if (c >= 'A' && c <= 'F') return c - 'A' + 10; + return -1; +} + const AVOption *av_set_string(void *obj, const char *name, const char *val){ const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); if(o && o->offset==0 && o->type == FF_OPT_TYPE_CONST && o->unit){ @@ -115,13 +122,36 @@ const AVOption *av_set_string(void *obj, const char *name, const char *val){ } if(!o || !val || o->offset<=0) return NULL; + if(o->type == FF_OPT_TYPE_BINARY){ + uint8_t **dst = (uint8_t **)(((uint8_t*)obj) + o->offset); + int *lendst = (int *)(dst + 1); + uint8_t *bin, *ptr; + int len = strlen(val); + av_freep(dst); + *lendst = 0; + if (len & 1) return NULL; + len /= 2; + ptr = bin = av_malloc(len); + while (*val) { + int a = hexchar2int(*val++); + int b = hexchar2int(*val++); + if (a < 0 || b < 0) { + av_free(bin); + return NULL; + } + *ptr++ = (a << 4) | b; + } + *dst = bin; + *lendst = len; + return o; + } if(o->type != FF_OPT_TYPE_STRING){ for(;;){ int i; char buf[256]; int cmd=0; double d; - char *error = NULL; + const char *error = NULL; if(*val == '+' || *val == '-') cmd= *(val++); @@ -160,7 +190,7 @@ const AVOption *av_set_string(void *obj, const char *name, const char *val){ return NULL; } - memcpy(((uint8_t*)obj) + o->offset, val, sizeof(val)); + memcpy(((uint8_t*)obj) + o->offset, &val, sizeof(val)); return o; } @@ -184,6 +214,8 @@ const AVOption *av_set_int(void *obj, const char *name, int64_t n){ const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len){ const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); void *dst; + uint8_t *bin; + int len, i; if(!o || o->offset<=0) return NULL; if(o->type != FF_OPT_TYPE_STRING && (!buf || !buf_len)) @@ -192,9 +224,6 @@ const char *av_get_string(void *obj, const char *name, const AVOption **o_out, c dst= ((uint8_t*)obj) + o->offset; if(o_out) *o_out= o; - if(o->type == FF_OPT_TYPE_STRING) - return dst; - switch(o->type){ case FF_OPT_TYPE_FLAGS: snprintf(buf, buf_len, "0x%08X",*(int *)dst);break; case FF_OPT_TYPE_INT: snprintf(buf, buf_len, "%d" , *(int *)dst);break; @@ -202,6 +231,13 @@ const char *av_get_string(void *obj, const char *name, const AVOption **o_out, c case FF_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break; case FF_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break; case FF_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break; + case FF_OPT_TYPE_STRING: return *(void**)dst; + case FF_OPT_TYPE_BINARY: + len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *)); + if(len >= (buf_len + 1)/2) return NULL; + bin = *(uint8_t**)dst; + for(i = 0; i < len; i++) snprintf(buf + i*2, 3, "%02X", bin[i]); + break; default: return NULL; } return buf; @@ -308,6 +344,9 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit) case FF_OPT_TYPE_RATIONAL: av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "" ); break; + case FF_OPT_TYPE_BINARY: + av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "" ); + break; case FF_OPT_TYPE_CONST: default: av_log( av_log_obj, AV_LOG_INFO, "%-7s ", "" ); @@ -375,6 +414,7 @@ void av_opt_set_defaults2(void *s, int mask, int flags) } break; case FF_OPT_TYPE_STRING: + case FF_OPT_TYPE_BINARY: /* Cannot set default for string as default_val is of type * double */ break; default: diff --git a/contrib/ffmpeg/libavcodec/opt.h b/contrib/ffmpeg/libavcodec/opt.h index 151dbb788..4691d1dfb 100644 --- a/contrib/ffmpeg/libavcodec/opt.h +++ b/contrib/ffmpeg/libavcodec/opt.h @@ -19,14 +19,16 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVOPT_H -#define AVOPT_H +#ifndef FFMPEG_OPT_H +#define FFMPEG_OPT_H /** * @file opt.h * AVOptions */ +#include "libavutil/rational.h" + enum AVOptionType{ FF_OPT_TYPE_FLAGS, FF_OPT_TYPE_INT, @@ -35,6 +37,7 @@ enum AVOptionType{ FF_OPT_TYPE_FLOAT, FF_OPT_TYPE_STRING, FF_OPT_TYPE_RATIONAL, + FF_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length FF_OPT_TYPE_CONST=128, }; @@ -46,7 +49,7 @@ typedef struct AVOption { /** * short English text help. - * @fixme what about other languages + * @todo what about other languages */ const char *help; int offset; ///< offset to context structure where the parsed value should be stored @@ -82,4 +85,4 @@ int av_opt_show(void *obj, void *av_log_obj); void av_opt_set_defaults(void *s); void av_opt_set_defaults2(void *s, int mask, int flags); -#endif +#endif /* FFMPEG_OPT_H */ diff --git a/contrib/ffmpeg/libavcodec/os2thread.c b/contrib/ffmpeg/libavcodec/os2thread.c index c52b7ae02..5c74a7d65 100644 --- a/contrib/ffmpeg/libavcodec/os2thread.c +++ b/contrib/ffmpeg/libavcodec/os2thread.c @@ -15,15 +15,13 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ //#define DEBUG // Ported by Vlad Stelmahovsky #include "avcodec.h" -#include "common.h" #define INCL_DOS #define INCL_DOSERRORS @@ -63,7 +61,7 @@ void thread_func(void *v){ /** * free what has been allocated by avcodec_thread_init(). - * must be called after decoding has finished, especially dont call while avcodec_thread_execute() is running + * must be called after decoding has finished, especially do not call while avcodec_thread_execute() is running */ void avcodec_thread_free(AVCodecContext *s){ ThreadContext *c= s->thread_opaque; diff --git a/contrib/ffmpeg/libavcodec/parser.c b/contrib/ffmpeg/libavcodec/parser.c index f3e7ee335..b0a6a2a1b 100644 --- a/contrib/ffmpeg/libavcodec/parser.c +++ b/contrib/ffmpeg/libavcodec/parser.c @@ -19,14 +19,16 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "avcodec.h" -#include "mpegvideo.h" -#include "mpegaudio.h" -#include "ac3.h" + #include "parser.h" AVCodecParser *av_first_parser = NULL; +AVCodecParser* av_parser_next(AVCodecParser *p){ + if(p) return p->next; + else return av_first_parser; +} + void av_register_codec_parser(AVCodecParser *parser) { parser->next = av_first_parser; @@ -124,13 +126,14 @@ int av_parser_parse(AVCodecParserContext *s, s->fetch_timestamp=0; s->last_pts = pts; s->last_dts = dts; + s->last_offset = 0; s->cur_frame_pts[k] = s->cur_frame_dts[k] = AV_NOPTS_VALUE; } } /* WARNING: the returned index can be negative */ - index = s->parser->parser_parse(s, avctx, poutbuf, poutbuf_size, buf, buf_size); + index = s->parser->parser_parse(s, avctx, (const uint8_t **)poutbuf, poutbuf_size, buf, buf_size); //av_log(NULL, AV_LOG_DEBUG, "parser: in:%"PRId64", %"PRId64", out:%"PRId64", %"PRId64", in:%d out:%d id:%d\n", pts, dts, s->last_pts, s->last_dts, buf_size, *poutbuf_size, avctx->codec_id); /* update the file pointer */ if (*poutbuf_size) { @@ -138,6 +141,7 @@ int av_parser_parse(AVCodecParserContext *s, s->frame_offset = s->last_frame_offset; s->pts = s->last_pts; s->dts = s->last_dts; + s->offset = s->last_offset; /* offset of the next frame */ s->last_frame_offset = s->cur_offset + index; @@ -156,6 +160,7 @@ int av_parser_parse(AVCodecParserContext *s, s->last_pts = s->cur_frame_pts[k]; s->last_dts = s->cur_frame_dts[k]; + s->last_offset = s->last_frame_offset - s->cur_frame_offset[k]; /* some parsers tell us the packet size even before seeing the first byte of the next packet, so the next pts/dts is in the next chunk */ @@ -221,7 +226,7 @@ void av_parser_close(AVCodecParserContext *s) * combines the (truncated) bitstream to a complete frame * @returns -1 if no complete frame could be created */ -int ff_combine_frame(ParseContext *pc, int next, uint8_t **buf, int *buf_size) +int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size) { #if 0 if(pc->overread){ @@ -230,7 +235,7 @@ int ff_combine_frame(ParseContext *pc, int next, uint8_t **buf, int *buf_size) } #endif - /* copy overreaded bytes from last frame into buffer */ + /* Copy overread bytes from last frame into buffer. */ for(; pc->overread>0; pc->overread--){ pc->buffer[pc->index++]= pc->buffer[pc->overread_index++]; } @@ -296,74 +301,6 @@ void ff_parse1_close(AVCodecParserContext *s) /*************************/ -#ifdef CONFIG_MPEG4VIDEO_PARSER -/* used by parser */ -/* XXX: make it use less memory */ -static int av_mpeg4_decode_header(AVCodecParserContext *s1, - AVCodecContext *avctx, - const uint8_t *buf, int buf_size) -{ - ParseContext1 *pc = s1->priv_data; - MpegEncContext *s = pc->enc; - GetBitContext gb1, *gb = &gb1; - int ret; - - s->avctx = avctx; - s->current_picture_ptr = &s->current_picture; - - if (avctx->extradata_size && pc->first_picture){ - init_get_bits(gb, avctx->extradata, avctx->extradata_size*8); - ret = ff_mpeg4_decode_picture_header(s, gb); - } - - init_get_bits(gb, buf, 8 * buf_size); - ret = ff_mpeg4_decode_picture_header(s, gb); - if (s->width) { - avcodec_set_dimensions(avctx, s->width, s->height); - } - s1->pict_type= s->pict_type; - pc->first_picture = 0; - return ret; -} - -static int mpeg4video_parse_init(AVCodecParserContext *s) -{ - ParseContext1 *pc = s->priv_data; - - pc->enc = av_mallocz(sizeof(MpegEncContext)); - if (!pc->enc) - return -1; - pc->first_picture = 1; - return 0; -} - -static int mpeg4video_parse(AVCodecParserContext *s, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - ParseContext *pc = s->priv_data; - int next; - - if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ - next= buf_size; - }else{ - next= ff_mpeg4_find_frame_end(pc, buf, buf_size); - - if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { - *poutbuf = NULL; - *poutbuf_size = 0; - return buf_size; - } - } - av_mpeg4_decode_header(s, avctx, buf, buf_size); - - *poutbuf = (uint8_t *)buf; - *poutbuf_size = buf_size; - return next; -} -#endif - int ff_mpeg4video_split(AVCodecContext *avctx, const uint8_t *buf, int buf_size) { @@ -377,458 +314,3 @@ int ff_mpeg4video_split(AVCodecContext *avctx, } return 0; } - -/*************************/ - -#ifdef CONFIG_MPEGAUDIO_PARSER -typedef struct MpegAudioParseContext { - uint8_t inbuf[MPA_MAX_CODED_FRAME_SIZE]; /* input buffer */ - uint8_t *inbuf_ptr; - int frame_size; - int free_format_frame_size; - int free_format_next_header; - uint32_t header; - int header_count; -} MpegAudioParseContext; - -#define MPA_HEADER_SIZE 4 - -/* header + layer + bitrate + freq + lsf/mpeg25 */ -#undef SAME_HEADER_MASK /* mpegaudio.h defines different version */ -#define SAME_HEADER_MASK \ - (0xffe00000 | (3 << 17) | (3 << 10) | (3 << 19)) - -static int mpegaudio_parse_init(AVCodecParserContext *s1) -{ - MpegAudioParseContext *s = s1->priv_data; - s->inbuf_ptr = s->inbuf; - return 0; -} - -static int mpegaudio_parse(AVCodecParserContext *s1, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - MpegAudioParseContext *s = s1->priv_data; - int len, ret, sr; - uint32_t header; - const uint8_t *buf_ptr; - - *poutbuf = NULL; - *poutbuf_size = 0; - buf_ptr = buf; - while (buf_size > 0) { - len = s->inbuf_ptr - s->inbuf; - if (s->frame_size == 0) { - /* special case for next header for first frame in free - format case (XXX: find a simpler method) */ - if (s->free_format_next_header != 0) { - s->inbuf[0] = s->free_format_next_header >> 24; - s->inbuf[1] = s->free_format_next_header >> 16; - s->inbuf[2] = s->free_format_next_header >> 8; - s->inbuf[3] = s->free_format_next_header; - s->inbuf_ptr = s->inbuf + 4; - s->free_format_next_header = 0; - goto got_header; - } - /* no header seen : find one. We need at least MPA_HEADER_SIZE - bytes to parse it */ - len = FFMIN(MPA_HEADER_SIZE - len, buf_size); - if (len > 0) { - memcpy(s->inbuf_ptr, buf_ptr, len); - buf_ptr += len; - buf_size -= len; - s->inbuf_ptr += len; - } - if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) { - got_header: - header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | - (s->inbuf[2] << 8) | s->inbuf[3]; - - ret = mpa_decode_header(avctx, header, &sr); - if (ret < 0) { - s->header_count= -2; - /* no sync found : move by one byte (inefficient, but simple!) */ - memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); - s->inbuf_ptr--; - dprintf(avctx, "skip %x\n", header); - /* reset free format frame size to give a chance - to get a new bitrate */ - s->free_format_frame_size = 0; - } else { - if((header&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header) - s->header_count= -3; - s->header= header; - s->header_count++; - s->frame_size = ret; - -#if 0 - /* free format: prepare to compute frame size */ - if (decode_header(s, header) == 1) { - s->frame_size = -1; - } -#endif - } - if(s->header_count > 1) - avctx->sample_rate= sr; - } - } else -#if 0 - if (s->frame_size == -1) { - /* free format : find next sync to compute frame size */ - len = MPA_MAX_CODED_FRAME_SIZE - len; - if (len > buf_size) - len = buf_size; - if (len == 0) { - /* frame too long: resync */ - s->frame_size = 0; - memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1); - s->inbuf_ptr--; - } else { - uint8_t *p, *pend; - uint32_t header1; - int padding; - - memcpy(s->inbuf_ptr, buf_ptr, len); - /* check for header */ - p = s->inbuf_ptr - 3; - pend = s->inbuf_ptr + len - 4; - while (p <= pend) { - header = (p[0] << 24) | (p[1] << 16) | - (p[2] << 8) | p[3]; - header1 = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) | - (s->inbuf[2] << 8) | s->inbuf[3]; - /* check with high probability that we have a - valid header */ - if ((header & SAME_HEADER_MASK) == - (header1 & SAME_HEADER_MASK)) { - /* header found: update pointers */ - len = (p + 4) - s->inbuf_ptr; - buf_ptr += len; - buf_size -= len; - s->inbuf_ptr = p; - /* compute frame size */ - s->free_format_next_header = header; - s->free_format_frame_size = s->inbuf_ptr - s->inbuf; - padding = (header1 >> 9) & 1; - if (s->layer == 1) - s->free_format_frame_size -= padding * 4; - else - s->free_format_frame_size -= padding; - dprintf(avctx, "free frame size=%d padding=%d\n", - s->free_format_frame_size, padding); - decode_header(s, header1); - goto next_data; - } - p++; - } - /* not found: simply increase pointers */ - buf_ptr += len; - s->inbuf_ptr += len; - buf_size -= len; - } - } else -#endif - if (len < s->frame_size) { - if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE) - s->frame_size = MPA_MAX_CODED_FRAME_SIZE; - len = FFMIN(s->frame_size - len, buf_size); - memcpy(s->inbuf_ptr, buf_ptr, len); - buf_ptr += len; - s->inbuf_ptr += len; - buf_size -= len; - } - - if(s->frame_size > 0 && buf_ptr - buf == s->inbuf_ptr - s->inbuf - && buf_size + buf_ptr - buf >= s->frame_size){ - if(s->header_count > 0){ - *poutbuf = buf; - *poutbuf_size = s->frame_size; - } - buf_ptr = buf + s->frame_size; - s->inbuf_ptr = s->inbuf; - s->frame_size = 0; - break; - } - - // next_data: - if (s->frame_size > 0 && - (s->inbuf_ptr - s->inbuf) >= s->frame_size) { - if(s->header_count > 0){ - *poutbuf = s->inbuf; - *poutbuf_size = s->inbuf_ptr - s->inbuf; - } - s->inbuf_ptr = s->inbuf; - s->frame_size = 0; - break; - } - } - return buf_ptr - buf; -} -#endif /* CONFIG_MPEGAUDIO_PARSER */ - -#if defined(CONFIG_AC3_PARSER) || defined(CONFIG_AAC_PARSER) -/* also used for ADTS AAC */ -typedef struct AC3ParseContext { - uint8_t *inbuf_ptr; - int frame_size; - int header_size; - int (*sync)(const uint8_t *buf, int *channels, int *sample_rate, - int *bit_rate, int *samples); - uint8_t inbuf[8192]; /* input buffer */ -} AC3ParseContext; - -#define AC3_HEADER_SIZE 7 -#define AAC_HEADER_SIZE 7 - -#ifdef CONFIG_AC3_PARSER - -static const uint8_t eac3_blocks[4] = { - 1, 2, 3, 6 -}; - -#endif /* CONFIG_AC3_PARSER */ - -#ifdef CONFIG_AAC_PARSER -static const int aac_sample_rates[16] = { - 96000, 88200, 64000, 48000, 44100, 32000, - 24000, 22050, 16000, 12000, 11025, 8000, 7350 -}; - -static const int aac_channels[8] = { - 0, 1, 2, 3, 4, 5, 6, 8 -}; -#endif - -#ifdef CONFIG_AC3_PARSER -static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate, - int *bit_rate, int *samples) -{ - int err; - unsigned int fscod, acmod, bsid, lfeon; - unsigned int strmtyp, substreamid, frmsiz, fscod2, numblkscod; - GetBitContext bits; - AC3HeaderInfo hdr; - - err = ff_ac3_parse_header(buf, &hdr); - - if(err < 0 && err != -2) - return 0; - - bsid = hdr.bsid; - if(bsid <= 10) { /* Normal AC-3 */ - *sample_rate = hdr.sample_rate; - *bit_rate = hdr.bit_rate; - *channels = hdr.channels; - *samples = AC3_FRAME_SIZE; - return hdr.frame_size; - } else if (bsid > 10 && bsid <= 16) { /* Enhanced AC-3 */ - init_get_bits(&bits, &buf[2], (AC3_HEADER_SIZE-2) * 8); - strmtyp = get_bits(&bits, 2); - substreamid = get_bits(&bits, 3); - - if (strmtyp != 0 || substreamid != 0) - return 0; /* Currently don't support additional streams */ - - frmsiz = get_bits(&bits, 11) + 1; - fscod = get_bits(&bits, 2); - if (fscod == 3) { - fscod2 = get_bits(&bits, 2); - numblkscod = 3; - - if(fscod2 == 3) - return 0; - - *sample_rate = ff_ac3_freqs[fscod2] / 2; - } else { - numblkscod = get_bits(&bits, 2); - - *sample_rate = ff_ac3_freqs[fscod]; - } - - acmod = get_bits(&bits, 3); - lfeon = get_bits1(&bits); - - *samples = eac3_blocks[numblkscod] * 256; - *bit_rate = frmsiz * (*sample_rate) * 16 / (*samples); - *channels = ff_ac3_channels[acmod] + lfeon; - - return frmsiz * 2; - } - - /* Unsupported bitstream version */ - return 0; -} -#endif /* CONFIG_AC3_PARSER */ - -#ifdef CONFIG_AAC_PARSER -static int aac_sync(const uint8_t *buf, int *channels, int *sample_rate, - int *bit_rate, int *samples) -{ - GetBitContext bits; - int size, rdb, ch, sr; - - init_get_bits(&bits, buf, AAC_HEADER_SIZE * 8); - - if(get_bits(&bits, 12) != 0xfff) - return 0; - - skip_bits1(&bits); /* id */ - skip_bits(&bits, 2); /* layer */ - skip_bits1(&bits); /* protection_absent */ - skip_bits(&bits, 2); /* profile_objecttype */ - sr = get_bits(&bits, 4); /* sample_frequency_index */ - if(!aac_sample_rates[sr]) - return 0; - skip_bits1(&bits); /* private_bit */ - ch = get_bits(&bits, 3); /* channel_configuration */ - if(!aac_channels[ch]) - return 0; - skip_bits1(&bits); /* original/copy */ - skip_bits1(&bits); /* home */ - - /* adts_variable_header */ - skip_bits1(&bits); /* copyright_identification_bit */ - skip_bits1(&bits); /* copyright_identification_start */ - size = get_bits(&bits, 13); /* aac_frame_length */ - skip_bits(&bits, 11); /* adts_buffer_fullness */ - rdb = get_bits(&bits, 2); /* number_of_raw_data_blocks_in_frame */ - - *channels = aac_channels[ch]; - *sample_rate = aac_sample_rates[sr]; - *samples = (rdb + 1) * 1024; - *bit_rate = size * 8 * *sample_rate / *samples; - - return size; -} -#endif /* CONFIG_AAC_PARSER */ - -#ifdef CONFIG_AC3_PARSER -static int ac3_parse_init(AVCodecParserContext *s1) -{ - AC3ParseContext *s = s1->priv_data; - s->inbuf_ptr = s->inbuf; - s->header_size = AC3_HEADER_SIZE; - s->sync = ac3_sync; - return 0; -} -#endif - -#ifdef CONFIG_AAC_PARSER -static int aac_parse_init(AVCodecParserContext *s1) -{ - AC3ParseContext *s = s1->priv_data; - s->inbuf_ptr = s->inbuf; - s->header_size = AAC_HEADER_SIZE; - s->sync = aac_sync; - return 0; -} -#endif - -/* also used for ADTS AAC */ -static int ac3_parse(AVCodecParserContext *s1, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - AC3ParseContext *s = s1->priv_data; - const uint8_t *buf_ptr; - int len, sample_rate, bit_rate, channels, samples; - - *poutbuf = NULL; - *poutbuf_size = 0; - - buf_ptr = buf; - while (buf_size > 0) { - len = s->inbuf_ptr - s->inbuf; - if (s->frame_size == 0) { - /* no header seen : find one. We need at least s->header_size - bytes to parse it */ - len = FFMIN(s->header_size - len, buf_size); - - memcpy(s->inbuf_ptr, buf_ptr, len); - buf_ptr += len; - s->inbuf_ptr += len; - buf_size -= len; - if ((s->inbuf_ptr - s->inbuf) == s->header_size) { - len = s->sync(s->inbuf, &channels, &sample_rate, &bit_rate, - &samples); - if (len == 0) { - /* no sync found : move by one byte (inefficient, but simple!) */ - memmove(s->inbuf, s->inbuf + 1, s->header_size - 1); - s->inbuf_ptr--; - } else { - s->frame_size = len; - /* update codec info */ - avctx->sample_rate = sample_rate; - /* set channels,except if the user explicitly requests 1 or 2 channels, XXX/FIXME this is a bit ugly */ - if(avctx->codec_id == CODEC_ID_AC3){ - if(avctx->channels!=1 && avctx->channels!=2){ - avctx->channels = channels; - } - } else { - avctx->channels = channels; - } - avctx->bit_rate = bit_rate; - avctx->frame_size = samples; - } - } - } else { - len = FFMIN(s->frame_size - len, buf_size); - - memcpy(s->inbuf_ptr, buf_ptr, len); - buf_ptr += len; - s->inbuf_ptr += len; - buf_size -= len; - - if(s->inbuf_ptr - s->inbuf == s->frame_size){ - *poutbuf = s->inbuf; - *poutbuf_size = s->frame_size; - s->inbuf_ptr = s->inbuf; - s->frame_size = 0; - break; - } - } - } - return buf_ptr - buf; -} -#endif /* CONFIG_AC3_PARSER || CONFIG_AAC_PARSER */ - -#ifdef CONFIG_MPEG4VIDEO_PARSER -AVCodecParser mpeg4video_parser = { - { CODEC_ID_MPEG4 }, - sizeof(ParseContext1), - mpeg4video_parse_init, - mpeg4video_parse, - ff_parse1_close, - ff_mpeg4video_split, -}; -#endif -#ifdef CONFIG_MPEGAUDIO_PARSER -AVCodecParser mpegaudio_parser = { - { CODEC_ID_MP2, CODEC_ID_MP3 }, - sizeof(MpegAudioParseContext), - mpegaudio_parse_init, - mpegaudio_parse, - NULL, -}; -#endif -#ifdef CONFIG_AC3_PARSER -AVCodecParser ac3_parser = { - { CODEC_ID_AC3 }, - sizeof(AC3ParseContext), - ac3_parse_init, - ac3_parse, - NULL, -}; -#endif -#ifdef CONFIG_AAC_PARSER -AVCodecParser aac_parser = { - { CODEC_ID_AAC }, - sizeof(AC3ParseContext), - aac_parse_init, - ac3_parse, - NULL, -}; -#endif diff --git a/contrib/ffmpeg/libavcodec/parser.h b/contrib/ffmpeg/libavcodec/parser.h index 3496b341f..47eeb4cde 100644 --- a/contrib/ffmpeg/libavcodec/parser.h +++ b/contrib/ffmpeg/libavcodec/parser.h @@ -23,6 +23,8 @@ #ifndef FFMPEG_PARSER_H #define FFMPEG_PARSER_H +#include "avcodec.h" + typedef struct ParseContext{ uint8_t *buffer; int index; @@ -31,7 +33,7 @@ typedef struct ParseContext{ uint32_t state; ///< contains the last few bytes in MSB order int frame_start_found; int overread; ///< the number of bytes which where irreversibly read from the next frame - int overread_index; ///< the index into ParseContext.buffer of the overreaded bytes + int overread_index; ///< the index into ParseContext.buffer of the overread bytes } ParseContext; struct MpegEncContext; @@ -51,13 +53,10 @@ typedef struct ParseContext1{ #define END_NOT_FOUND (-100) -int ff_combine_frame(ParseContext *pc, int next, uint8_t **buf, int *buf_size); +int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size); int ff_mpeg4video_split(AVCodecContext *avctx, const uint8_t *buf, int buf_size); void ff_parse_close(AVCodecParserContext *s); void ff_parse1_close(AVCodecParserContext *s); -/* h263dec.c */ -int ff_mpeg4_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size); - -#endif /* !FFMPEG_PARSER_H */ +#endif /* FFMPEG_PARSER_H */ diff --git a/contrib/ffmpeg/libavcodec/pcm.c b/contrib/ffmpeg/libavcodec/pcm.c index 5570c01bd..926c6f010 100644 --- a/contrib/ffmpeg/libavcodec/pcm.c +++ b/contrib/ffmpeg/libavcodec/pcm.c @@ -26,6 +26,9 @@ #include "avcodec.h" #include "bitstream.h" // for ff_reverse +#include "bytestream.h" + +#define MAX_CHANNELS 64 /* from g711.c by SUN microsystems (unrestricted use) */ @@ -169,14 +172,15 @@ static int pcm_encode_close(AVCodecContext *avctx) */ static inline void encode_from16(int bps, int le, int us, short **samples, uint8_t **dst, int n) { + int usum = us ? 0x8000 : 0; if (bps > 2) memset(*dst, 0, n * bps); if (le) *dst += bps - 2; for(;n>0;n--) { register int v = *(*samples)++; - if (us) v += 0x8000; - (*dst)[le] = v >> 8; - (*dst)[1 - le] = v; + v += usum; + if (le) AV_WL16(*dst, v); + else AV_WB16(*dst, v); *dst += bps; } if (le) *dst -= bps - 2; @@ -247,74 +251,66 @@ static int pcm_encode_frame(AVCodecContext *avctx, uint32_t tmp = ff_reverse[*samples >> 8] + (ff_reverse[*samples & 0xff] << 8); tmp <<= 4; // sync flags would go here - dst[2] = tmp & 0xff; - tmp >>= 8; - dst[1] = tmp & 0xff; - dst[0] = tmp >> 8; + bytestream_put_be24(&dst, tmp); samples++; - dst += 3; } break; case CODEC_ID_PCM_S16LE: for(;n>0;n--) { v = *samples++; - dst[0] = v & 0xff; - dst[1] = v >> 8; - dst += 2; + bytestream_put_le16(&dst, v); } break; case CODEC_ID_PCM_S16BE: for(;n>0;n--) { v = *samples++; - dst[0] = v >> 8; - dst[1] = v; - dst += 2; + bytestream_put_be16(&dst, v); } break; case CODEC_ID_PCM_U16LE: for(;n>0;n--) { v = *samples++; v += 0x8000; - dst[0] = v & 0xff; - dst[1] = v >> 8; - dst += 2; + bytestream_put_le16(&dst, v); } break; case CODEC_ID_PCM_U16BE: for(;n>0;n--) { v = *samples++; v += 0x8000; - dst[0] = v >> 8; - dst[1] = v; - dst += 2; + bytestream_put_be16(&dst, v); } break; case CODEC_ID_PCM_S8: for(;n>0;n--) { v = *samples++; - dst[0] = v >> 8; - dst++; + *dst++ = v >> 8; } break; case CODEC_ID_PCM_U8: for(;n>0;n--) { v = *samples++; - dst[0] = (v >> 8) + 128; - dst++; + *dst++ = (v >> 8) + 128; + } + break; + case CODEC_ID_PCM_ZORK: + for(;n>0;n--) { + v= *samples++ >> 8; + if(v<0) v = -v; + else v+= 128; + *dst++ = v; } break; case CODEC_ID_PCM_ALAW: for(;n>0;n--) { v = *samples++; - dst[0] = linear_to_alaw[(v + 32768) >> 2]; - dst++; + *dst++ = linear_to_alaw[(v + 32768) >> 2]; } break; case CODEC_ID_PCM_MULAW: for(;n>0;n--) { v = *samples++; - dst[0] = linear_to_ulaw[(v + 32768) >> 2]; - dst++; + *dst++ = linear_to_ulaw[(v + 32768) >> 2]; } break; default: @@ -359,12 +355,17 @@ static int pcm_decode_init(AVCodecContext * avctx) * \param src_len number of bytes in src */ static inline void decode_to16(int bps, int le, int us, - uint8_t **src, short **samples, int src_len) + const uint8_t **src, short **samples, int src_len) { + int usum = us ? -0x8000 : 0; register int n = src_len / bps; if (le) *src += bps - 2; for(;n>0;n--) { - *(*samples)++ = ((*src)[le] << 8 | (*src)[1 - le]) - (us?0x8000:0); + register int v; + if (le) v = AV_RL16(*src); + else v = AV_RB16(*src); + v += usum; + *(*samples)++ = v; *src += bps; } if (le) *src -= bps - 2; @@ -372,12 +373,12 @@ static inline void decode_to16(int bps, int le, int us, static int pcm_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { PCMDecode *s = avctx->priv_data; - int n; + int c, n; short *samples; - uint8_t *src; + const uint8_t *src, *src2[MAX_CHANNELS]; samples = data; src = buf; @@ -387,10 +388,18 @@ static int pcm_decode_frame(AVCodecContext *avctx, av_log(avctx, AV_LOG_ERROR, "invalid PCM packet\n"); return -1; } + if(avctx->channels <= 0 || avctx->channels > MAX_CHANNELS){ + av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n"); + return -1; + } buf_size= FFMIN(buf_size, *data_size/2); *data_size=0; + n = buf_size/avctx->channels; + for(c=0;cchannels;c++) + src2[c] = &src[c*n]; + switch(avctx->codec->id) { case CODEC_ID_PCM_S32LE: decode_to16(4, 1, 0, &src, &samples, buf_size); @@ -419,61 +428,68 @@ static int pcm_decode_frame(AVCodecContext *avctx, case CODEC_ID_PCM_S24DAUD: n = buf_size / 3; for(;n>0;n--) { - uint32_t v = src[0] << 16 | src[1] << 8 | src[2]; + uint32_t v = bytestream_get_be24(&src); v >>= 4; // sync flags are here *samples++ = ff_reverse[(v >> 8) & 0xff] + (ff_reverse[v & 0xff] << 8); - src += 3; } break; case CODEC_ID_PCM_S16LE: n = buf_size >> 1; for(;n>0;n--) { - *samples++ = src[0] | (src[1] << 8); - src += 2; + *samples++ = bytestream_get_le16(&src); } break; + case CODEC_ID_PCM_S16LE_PLANAR: + for(n>>=1;n>0;n--) + for(c=0;cchannels;c++) + *samples++ = bytestream_get_le16(&src2[c]); + src = src2[avctx->channels-1]; + break; case CODEC_ID_PCM_S16BE: n = buf_size >> 1; for(;n>0;n--) { - *samples++ = (src[0] << 8) | src[1]; - src += 2; + *samples++ = bytestream_get_be16(&src); } break; case CODEC_ID_PCM_U16LE: n = buf_size >> 1; for(;n>0;n--) { - *samples++ = (src[0] | (src[1] << 8)) - 0x8000; - src += 2; + *samples++ = bytestream_get_le16(&src) - 0x8000; } break; case CODEC_ID_PCM_U16BE: n = buf_size >> 1; for(;n>0;n--) { - *samples++ = ((src[0] << 8) | src[1]) - 0x8000; - src += 2; + *samples++ = bytestream_get_be16(&src) - 0x8000; } break; case CODEC_ID_PCM_S8: n = buf_size; for(;n>0;n--) { - *samples++ = src[0] << 8; - src++; + *samples++ = *src++ << 8; } break; case CODEC_ID_PCM_U8: n = buf_size; for(;n>0;n--) { - *samples++ = ((int)src[0] - 128) << 8; - src++; + *samples++ = ((int)*src++ - 128) << 8; + } + break; + case CODEC_ID_PCM_ZORK: + n = buf_size; + for(;n>0;n--) { + int x= *src++; + if(x&128) x-= 128; + else x = -x; + *samples++ = x << 8; } break; case CODEC_ID_PCM_ALAW: case CODEC_ID_PCM_MULAW: n = buf_size; for(;n>0;n--) { - *samples++ = s->table[src[0]]; - src++; + *samples++ = s->table[*src++]; } break; default: @@ -483,7 +499,8 @@ static int pcm_decode_frame(AVCodecContext *avctx, return src - buf; } -#define PCM_CODEC(id, name) \ +#ifdef CONFIG_ENCODERS +#define PCM_ENCODER(id,name) \ AVCodec name ## _encoder = { \ #name, \ CODEC_TYPE_AUDIO, \ @@ -493,7 +510,13 @@ AVCodec name ## _encoder = { \ pcm_encode_frame, \ pcm_encode_close, \ NULL, \ -}; \ +}; +#else +#define PCM_ENCODER(id,name) +#endif + +#ifdef CONFIG_DECODERS +#define PCM_DECODER(id,name) \ AVCodec name ## _decoder = { \ #name, \ CODEC_TYPE_AUDIO, \ @@ -503,24 +526,30 @@ AVCodec name ## _decoder = { \ NULL, \ NULL, \ pcm_decode_frame, \ -} +}; +#else +#define PCM_DECODER(id,name) +#endif -PCM_CODEC(CODEC_ID_PCM_S32LE, pcm_s32le); -PCM_CODEC(CODEC_ID_PCM_S32BE, pcm_s32be); -PCM_CODEC(CODEC_ID_PCM_U32LE, pcm_u32le); -PCM_CODEC(CODEC_ID_PCM_U32BE, pcm_u32be); -PCM_CODEC(CODEC_ID_PCM_S24LE, pcm_s24le); -PCM_CODEC(CODEC_ID_PCM_S24BE, pcm_s24be); -PCM_CODEC(CODEC_ID_PCM_U24LE, pcm_u24le); -PCM_CODEC(CODEC_ID_PCM_U24BE, pcm_u24be); -PCM_CODEC(CODEC_ID_PCM_S24DAUD, pcm_s24daud); -PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le); -PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be); -PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le); -PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be); -PCM_CODEC(CODEC_ID_PCM_S8, pcm_s8); -PCM_CODEC(CODEC_ID_PCM_U8, pcm_u8); -PCM_CODEC(CODEC_ID_PCM_ALAW, pcm_alaw); -PCM_CODEC(CODEC_ID_PCM_MULAW, pcm_mulaw); - -#undef PCM_CODEC +#define PCM_CODEC(id, name) \ +PCM_ENCODER(id,name) PCM_DECODER(id,name) + +PCM_CODEC (CODEC_ID_PCM_S32LE, pcm_s32le); +PCM_CODEC (CODEC_ID_PCM_S32BE, pcm_s32be); +PCM_CODEC (CODEC_ID_PCM_U32LE, pcm_u32le); +PCM_CODEC (CODEC_ID_PCM_U32BE, pcm_u32be); +PCM_CODEC (CODEC_ID_PCM_S24LE, pcm_s24le); +PCM_CODEC (CODEC_ID_PCM_S24BE, pcm_s24be); +PCM_CODEC (CODEC_ID_PCM_U24LE, pcm_u24le); +PCM_CODEC (CODEC_ID_PCM_U24BE, pcm_u24be); +PCM_CODEC (CODEC_ID_PCM_S24DAUD, pcm_s24daud); +PCM_CODEC (CODEC_ID_PCM_S16LE, pcm_s16le); +PCM_DECODER(CODEC_ID_PCM_S16LE_PLANAR, pcm_s16le_planar); +PCM_CODEC (CODEC_ID_PCM_S16BE, pcm_s16be); +PCM_CODEC (CODEC_ID_PCM_U16LE, pcm_u16le); +PCM_CODEC (CODEC_ID_PCM_U16BE, pcm_u16be); +PCM_CODEC (CODEC_ID_PCM_S8, pcm_s8); +PCM_CODEC (CODEC_ID_PCM_U8, pcm_u8); +PCM_CODEC (CODEC_ID_PCM_ALAW, pcm_alaw); +PCM_CODEC (CODEC_ID_PCM_MULAW, pcm_mulaw); +PCM_CODEC (CODEC_ID_PCM_ZORK, pcm_zork); diff --git a/contrib/ffmpeg/libavcodec/pcx.c b/contrib/ffmpeg/libavcodec/pcx.c new file mode 100644 index 000000000..5aa7b0846 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/pcx.c @@ -0,0 +1,247 @@ +/* + * PC Paintbrush PCX (.pcx) image decoder + * Copyright (c) 2007, 2008 Ivo van Poorten + * + * This decoder does not support CGA palettes. I am unable to find samples + * and Netpbm cannot generate them. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "bytestream.h" +#include "bitstream.h" + +typedef struct PCXContext { + AVFrame picture; +} PCXContext; + +static int pcx_init(AVCodecContext *avctx) { + PCXContext *s = avctx->priv_data; + + avcodec_get_frame_defaults(&s->picture); + avctx->coded_frame= &s->picture; + + return 0; +} + +/** + * @return advanced src pointer + */ +static const char *pcx_rle_decode(const uint8_t *src, uint8_t *dst, + unsigned int bytes_per_scanline) { + unsigned int i = 0; + unsigned char run, value; + + while (i= 0xc0) { + run = value & 0x3f; + value = *src++; + } + while (ipriv_data; + AVFrame *picture = data; + AVFrame * const p = &s->picture; + int xmin, ymin, xmax, ymax; + unsigned int w, h, bits_per_pixel, bytes_per_line, nplanes, stride, y, x, + bytes_per_scanline; + uint8_t *ptr; + uint8_t const *bufstart = buf; + + if (buf[0] != 0x0a || buf[1] > 5 || buf[1] == 1 || buf[2] != 1) { + av_log(avctx, AV_LOG_ERROR, "this is not PCX encoded data\n"); + return -1; + } + + xmin = AV_RL16(buf+ 4); + ymin = AV_RL16(buf+ 6); + xmax = AV_RL16(buf+ 8); + ymax = AV_RL16(buf+10); + + if (xmax < xmin || ymax < ymin) { + av_log(avctx, AV_LOG_ERROR, "invalid image dimensions\n"); + return -1; + } + + w = xmax - xmin + 1; + h = ymax - ymin + 1; + + bits_per_pixel = buf[3]; + bytes_per_line = AV_RL16(buf+66); + nplanes = buf[65]; + bytes_per_scanline = nplanes * bytes_per_line; + + if (bytes_per_scanline < w * bits_per_pixel * nplanes / 8) { + av_log(avctx, AV_LOG_ERROR, "PCX data is corrupted\n"); + return -1; + } + + switch ((nplanes<<8) + bits_per_pixel) { + case 0x0308: + avctx->pix_fmt = PIX_FMT_RGB24; + break; + case 0x0108: + case 0x0104: + case 0x0102: + case 0x0101: + case 0x0401: + case 0x0301: + case 0x0201: + avctx->pix_fmt = PIX_FMT_PAL8; + break; + default: + av_log(avctx, AV_LOG_ERROR, "invalid PCX file\n"); + return -1; + } + + buf += 128; + + if (p->data[0]) + avctx->release_buffer(avctx, p); + + if (avcodec_check_dimensions(avctx, w, h)) + return -1; + if (w != avctx->width || h != avctx->height) + avcodec_set_dimensions(avctx, w, h); + if (avctx->get_buffer(avctx, p) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + + p->pict_type = FF_I_TYPE; + + ptr = p->data[0]; + stride = p->linesize[0]; + + if (nplanes == 3 && bits_per_pixel == 8) { + uint8_t scanline[bytes_per_scanline]; + + for (y=0; y> (x&7), v = 0; + for (i=nplanes - 1; i>=0; i--) { + v <<= 1; + v += !!(scanline[i*bytes_per_line + (x>>3)] & m); + } + ptr[x] = v; + } + ptr += stride; + } + } + + if (nplanes == 1 && bits_per_pixel == 8) { + pcx_palette(&buf, (uint32_t *) p->data[1], 256); + } else if (bits_per_pixel < 8) { + const uint8_t *palette = bufstart+16; + pcx_palette(&palette, (uint32_t *) p->data[1], 16); + } + + *picture = s->picture; + *data_size = sizeof(AVFrame); + + return buf - bufstart; +} + +static int pcx_end(AVCodecContext *avctx) { + PCXContext *s = avctx->priv_data; + + if(s->picture.data[0]) + avctx->release_buffer(avctx, &s->picture); + + return 0; +} + +AVCodec pcx_decoder = { + "pcx", + CODEC_TYPE_VIDEO, + CODEC_ID_PCX, + sizeof(PCXContext), + pcx_init, + NULL, + pcx_end, + pcx_decode_frame, + 0, + NULL +}; diff --git a/contrib/ffmpeg/libavcodec/png.c b/contrib/ffmpeg/libavcodec/png.c index 05b4512b7..c95ba3e10 100644 --- a/contrib/ffmpeg/libavcodec/png.c +++ b/contrib/ffmpeg/libavcodec/png.c @@ -19,141 +19,45 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avcodec.h" +#include "bytestream.h" +#include "png.h" -/* TODO: - * - add 2, 4 and 16 bit depth support - * - use filters when generating a png (better compression) - */ - -#include - -//#define DEBUG - -#define PNG_COLOR_MASK_PALETTE 1 -#define PNG_COLOR_MASK_COLOR 2 -#define PNG_COLOR_MASK_ALPHA 4 - -#define PNG_COLOR_TYPE_GRAY 0 -#define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE) -#define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR) -#define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA) -#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA) - -#define PNG_FILTER_VALUE_NONE 0 -#define PNG_FILTER_VALUE_SUB 1 -#define PNG_FILTER_VALUE_UP 2 -#define PNG_FILTER_VALUE_AVG 3 -#define PNG_FILTER_VALUE_PAETH 4 - -#define PNG_IHDR 0x0001 -#define PNG_IDAT 0x0002 -#define PNG_ALLIMAGE 0x0004 -#define PNG_PLTE 0x0008 - -#define NB_PASSES 7 - -#define IOBUF_SIZE 4096 - -typedef struct PNGContext { - uint8_t *bytestream; - uint8_t *bytestream_start; - uint8_t *bytestream_end; - AVFrame picture; - - int state; - int width, height; - int bit_depth; - int color_type; - int compression_type; - int interlace_type; - int filter_type; - int channels; - int bits_per_pixel; - int bpp; - - uint8_t *image_buf; - int image_linesize; - uint32_t palette[256]; - uint8_t *crow_buf; - uint8_t *last_row; - uint8_t *tmp_row; - int pass; - int crow_size; /* compressed row size (include filter type) */ - int row_size; /* decompressed row size */ - int pass_row_size; /* decompress row size of the current pass */ - int y; - z_stream zstream; - uint8_t buf[IOBUF_SIZE]; -} PNGContext; - -static unsigned int get32(uint8_t **b){ - (*b) += 4; - return ((*b)[-4]<<24) + ((*b)[-3]<<16) + ((*b)[-2]<<8) + (*b)[-1]; -} - -#ifdef CONFIG_ENCODERS -static void put32(uint8_t **b, unsigned int v){ - *(*b)++= v>>24; - *(*b)++= v>>16; - *(*b)++= v>>8; - *(*b)++= v; -} -#endif - -static const uint8_t pngsig[8] = {137, 80, 78, 71, 13, 10, 26, 10}; +const uint8_t ff_pngsig[8] = {137, 80, 78, 71, 13, 10, 26, 10}; +const uint8_t ff_mngsig[8] = {138, 77, 78, 71, 13, 10, 26, 10}; /* Mask to determine which y pixels are valid in a pass */ -static const uint8_t png_pass_ymask[NB_PASSES] = { +const uint8_t ff_png_pass_ymask[NB_PASSES] = { 0x80, 0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, }; -/* Mask to determine which y pixels can be written in a pass */ -static const uint8_t png_pass_dsp_ymask[NB_PASSES] = { - 0xff, 0xff, 0x0f, 0xcc, 0x33, 0xff, 0x55, -}; - /* minimum x value */ -static const uint8_t png_pass_xmin[NB_PASSES] = { +const uint8_t ff_png_pass_xmin[NB_PASSES] = { 0, 4, 0, 2, 0, 1, 0 }; /* x shift to get row width */ -static const uint8_t png_pass_xshift[NB_PASSES] = { +const uint8_t ff_png_pass_xshift[NB_PASSES] = { 3, 3, 2, 2, 1, 1, 0 }; /* Mask to determine which pixels are valid in a pass */ -static const uint8_t png_pass_mask[NB_PASSES] = { +const uint8_t ff_png_pass_mask[NB_PASSES] = { 0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff }; -/* Mask to determine which pixels to overwrite while displaying */ -static const uint8_t png_pass_dsp_mask[NB_PASSES] = { - 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff -}; -#if 0 -static int png_probe(AVProbeData *pd) -{ - if (pd->buf_size >= 8 && - memcmp(pd->buf, pngsig, 8) == 0) - return AVPROBE_SCORE_MAX; - else - return 0; -} -#endif -static void *png_zalloc(void *opaque, unsigned int items, unsigned int size) +void *ff_png_zalloc(void *opaque, unsigned int items, unsigned int size) { if(items >= UINT_MAX / size) return NULL; return av_malloc(items * size); } -static void png_zfree(void *opaque, void *ptr) +void ff_png_zfree(void *opaque, void *ptr) { av_free(ptr); } -static int png_get_nb_channels(int color_type) +int ff_png_get_nb_channels(int color_type) { int channels; channels = 1; @@ -166,801 +70,14 @@ static int png_get_nb_channels(int color_type) } /* compute the row size of an interleaved pass */ -static int png_pass_row_size(int pass, int bits_per_pixel, int width) +int ff_png_pass_row_size(int pass, int bits_per_pixel, int width) { int shift, xmin, pass_width; - xmin = png_pass_xmin[pass]; + xmin = ff_png_pass_xmin[pass]; if (width <= xmin) return 0; - shift = png_pass_xshift[pass]; + shift = ff_png_pass_xshift[pass]; pass_width = (width - xmin + (1 << shift) - 1) >> shift; return (pass_width * bits_per_pixel + 7) >> 3; } - -/* NOTE: we try to construct a good looking image at each pass. width - is the original image width. We also do pixel format convertion at - this stage */ -static void png_put_interlaced_row(uint8_t *dst, int width, - int bits_per_pixel, int pass, - int color_type, const uint8_t *src) -{ - int x, mask, dsp_mask, j, src_x, b, bpp; - uint8_t *d; - const uint8_t *s; - - mask = png_pass_mask[pass]; - dsp_mask = png_pass_dsp_mask[pass]; - switch(bits_per_pixel) { - case 1: - /* we must intialize the line to zero before writing to it */ - if (pass == 0) - memset(dst, 0, (width + 7) >> 3); - src_x = 0; - for(x = 0; x < width; x++) { - j = (x & 7); - if ((dsp_mask << j) & 0x80) { - b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1; - dst[x >> 3] |= b << (7 - j); - } - if ((mask << j) & 0x80) - src_x++; - } - break; - default: - bpp = bits_per_pixel >> 3; - d = dst; - s = src; - if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) { - for(x = 0; x < width; x++) { - j = x & 7; - if ((dsp_mask << j) & 0x80) { - *(uint32_t *)d = (s[3] << 24) | (s[0] << 16) | (s[1] << 8) | s[2]; - } - d += bpp; - if ((mask << j) & 0x80) - s += bpp; - } - } else { - for(x = 0; x < width; x++) { - j = x & 7; - if ((dsp_mask << j) & 0x80) { - memcpy(d, s, bpp); - } - d += bpp; - if ((mask << j) & 0x80) - s += bpp; - } - } - break; - } -} - -#ifdef CONFIG_ENCODERS -static void png_get_interlaced_row(uint8_t *dst, int row_size, - int bits_per_pixel, int pass, - const uint8_t *src, int width) -{ - int x, mask, dst_x, j, b, bpp; - uint8_t *d; - const uint8_t *s; - - mask = png_pass_mask[pass]; - switch(bits_per_pixel) { - case 1: - memset(dst, 0, row_size); - dst_x = 0; - for(x = 0; x < width; x++) { - j = (x & 7); - if ((mask << j) & 0x80) { - b = (src[x >> 3] >> (7 - j)) & 1; - dst[dst_x >> 3] |= b << (7 - (dst_x & 7)); - dst_x++; - } - } - break; - default: - bpp = bits_per_pixel >> 3; - d = dst; - s = src; - for(x = 0; x < width; x++) { - j = x & 7; - if ((mask << j) & 0x80) { - memcpy(d, s, bpp); - d += bpp; - } - s += bpp; - } - break; - } -} -#endif - -/* XXX: optimize */ -/* NOTE: 'dst' can be equal to 'last' */ -static void png_filter_row(uint8_t *dst, int filter_type, - uint8_t *src, uint8_t *last, int size, int bpp) -{ - int i, p; - - switch(filter_type) { - case PNG_FILTER_VALUE_NONE: - memcpy(dst, src, size); - break; - case PNG_FILTER_VALUE_SUB: - for(i = 0; i < bpp; i++) { - dst[i] = src[i]; - } - for(i = bpp; i < size; i++) { - p = dst[i - bpp]; - dst[i] = p + src[i]; - } - break; - case PNG_FILTER_VALUE_UP: - for(i = 0; i < size; i++) { - p = last[i]; - dst[i] = p + src[i]; - } - break; - case PNG_FILTER_VALUE_AVG: - for(i = 0; i < bpp; i++) { - p = (last[i] >> 1); - dst[i] = p + src[i]; - } - for(i = bpp; i < size; i++) { - p = ((dst[i - bpp] + last[i]) >> 1); - dst[i] = p + src[i]; - } - break; - case PNG_FILTER_VALUE_PAETH: - for(i = 0; i < bpp; i++) { - p = last[i]; - dst[i] = p + src[i]; - } - for(i = bpp; i < size; i++) { - int a, b, c, pa, pb, pc; - - a = dst[i - bpp]; - b = last[i]; - c = last[i - bpp]; - - p = b - c; - pc = a - c; - - pa = abs(p); - pb = abs(pc); - pc = abs(p + pc); - - if (pa <= pb && pa <= pc) - p = a; - else if (pb <= pc) - p = b; - else - p = c; - dst[i] = p + src[i]; - } - break; - } -} - -#ifdef CONFIG_ENCODERS -static void convert_from_rgb32(uint8_t *dst, const uint8_t *src, int width) -{ - uint8_t *d; - int j; - unsigned int v; - - d = dst; - for(j = 0; j < width; j++) { - v = ((const uint32_t *)src)[j]; - d[0] = v >> 16; - d[1] = v >> 8; - d[2] = v; - d[3] = v >> 24; - d += 4; - } -} -#endif - -#ifdef CONFIG_DECODERS -static void convert_to_rgb32(uint8_t *dst, const uint8_t *src, int width) -{ - int j; - unsigned int r, g, b, a; - - for(j = 0;j < width; j++) { - r = src[0]; - g = src[1]; - b = src[2]; - a = src[3]; - *(uint32_t *)dst = (a << 24) | (r << 16) | (g << 8) | b; - dst += 4; - src += 4; - } -} - -/* process exactly one decompressed row */ -static void png_handle_row(PNGContext *s) -{ - uint8_t *ptr, *last_row; - int got_line; - - if (!s->interlace_type) { - ptr = s->image_buf + s->image_linesize * s->y; - /* need to swap bytes correctly for RGB_ALPHA */ - if (s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) { - png_filter_row(s->tmp_row, s->crow_buf[0], s->crow_buf + 1, - s->last_row, s->row_size, s->bpp); - memcpy(s->last_row, s->tmp_row, s->row_size); - convert_to_rgb32(ptr, s->tmp_row, s->width); - } else { - /* in normal case, we avoid one copy */ - if (s->y == 0) - last_row = s->last_row; - else - last_row = ptr - s->image_linesize; - - png_filter_row(ptr, s->crow_buf[0], s->crow_buf + 1, - last_row, s->row_size, s->bpp); - } - s->y++; - if (s->y == s->height) { - s->state |= PNG_ALLIMAGE; - } - } else { - got_line = 0; - for(;;) { - ptr = s->image_buf + s->image_linesize * s->y; - if ((png_pass_ymask[s->pass] << (s->y & 7)) & 0x80) { - /* if we already read one row, it is time to stop to - wait for the next one */ - if (got_line) - break; - png_filter_row(s->tmp_row, s->crow_buf[0], s->crow_buf + 1, - s->last_row, s->pass_row_size, s->bpp); - memcpy(s->last_row, s->tmp_row, s->pass_row_size); - got_line = 1; - } - if ((png_pass_dsp_ymask[s->pass] << (s->y & 7)) & 0x80) { - /* NOTE: RGB32 is handled directly in png_put_interlaced_row */ - png_put_interlaced_row(ptr, s->width, s->bits_per_pixel, s->pass, - s->color_type, s->last_row); - } - s->y++; - if (s->y == s->height) { - for(;;) { - if (s->pass == NB_PASSES - 1) { - s->state |= PNG_ALLIMAGE; - goto the_end; - } else { - s->pass++; - s->y = 0; - s->pass_row_size = png_pass_row_size(s->pass, - s->bits_per_pixel, - s->width); - s->crow_size = s->pass_row_size + 1; - if (s->pass_row_size != 0) - break; - /* skip pass if empty row */ - } - } - } - } - the_end: ; - } -} - -static int png_decode_idat(PNGContext *s, int length) -{ - int ret; - s->zstream.avail_in = length; - s->zstream.next_in = s->bytestream; - s->bytestream += length; - - if(s->bytestream > s->bytestream_end) - return -1; - - /* decode one line if possible */ - while (s->zstream.avail_in > 0) { - ret = inflate(&s->zstream, Z_PARTIAL_FLUSH); - if (ret != Z_OK && ret != Z_STREAM_END) { - return -1; - } - if (s->zstream.avail_out == 0) { - if (!(s->state & PNG_ALLIMAGE)) { - png_handle_row(s); - } - s->zstream.avail_out = s->crow_size; - s->zstream.next_out = s->crow_buf; - } - } - return 0; -} - -static int decode_frame(AVCodecContext *avctx, - void *data, int *data_size, - uint8_t *buf, int buf_size) -{ - PNGContext * const s = avctx->priv_data; - AVFrame *picture = data; - AVFrame * const p= (AVFrame*)&s->picture; - uint32_t tag, length; - int ret, crc; - - s->bytestream_start= - s->bytestream= buf; - s->bytestream_end= buf + buf_size; - - /* check signature */ - if (memcmp(s->bytestream, pngsig, 8) != 0) - return -1; - s->bytestream+= 8; - s->y= - s->state=0; -// memset(s, 0, sizeof(PNGContext)); - /* init the zlib */ - s->zstream.zalloc = png_zalloc; - s->zstream.zfree = png_zfree; - s->zstream.opaque = NULL; - ret = inflateInit(&s->zstream); - if (ret != Z_OK) - return -1; - for(;;) { - int tag32; - if (s->bytestream >= s->bytestream_end) - goto fail; - length = get32(&s->bytestream); - if (length > 0x7fffffff) - goto fail; - tag32 = get32(&s->bytestream); - tag = bswap_32(tag32); -#ifdef DEBUG - av_log(avctx, AV_LOG_DEBUG, "png: tag=%c%c%c%c length=%u\n", - (tag & 0xff), - ((tag >> 8) & 0xff), - ((tag >> 16) & 0xff), - ((tag >> 24) & 0xff), length); -#endif - switch(tag) { - case MKTAG('I', 'H', 'D', 'R'): - if (length != 13) - goto fail; - s->width = get32(&s->bytestream); - s->height = get32(&s->bytestream); - if(avcodec_check_dimensions(avctx, s->width, s->height)){ - s->width= s->height= 0; - goto fail; - } - s->bit_depth = *s->bytestream++; - s->color_type = *s->bytestream++; - s->compression_type = *s->bytestream++; - s->filter_type = *s->bytestream++; - s->interlace_type = *s->bytestream++; - crc = get32(&s->bytestream); - s->state |= PNG_IHDR; -#ifdef DEBUG - av_log(avctx, AV_LOG_DEBUG, "width=%d height=%d depth=%d color_type=%d compression_type=%d filter_type=%d interlace_type=%d\n", - s->width, s->height, s->bit_depth, s->color_type, - s->compression_type, s->filter_type, s->interlace_type); -#endif - break; - case MKTAG('I', 'D', 'A', 'T'): - if (!(s->state & PNG_IHDR)) - goto fail; - if (!(s->state & PNG_IDAT)) { - /* init image info */ - avctx->width = s->width; - avctx->height = s->height; - - s->channels = png_get_nb_channels(s->color_type); - s->bits_per_pixel = s->bit_depth * s->channels; - s->bpp = (s->bits_per_pixel + 7) >> 3; - s->row_size = (avctx->width * s->bits_per_pixel + 7) >> 3; - - if (s->bit_depth == 8 && - s->color_type == PNG_COLOR_TYPE_RGB) { - avctx->pix_fmt = PIX_FMT_RGB24; - } else if (s->bit_depth == 8 && - s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) { - avctx->pix_fmt = PIX_FMT_RGB32; - } else if (s->bit_depth == 8 && - s->color_type == PNG_COLOR_TYPE_GRAY) { - avctx->pix_fmt = PIX_FMT_GRAY8; - } else if (s->bit_depth == 16 && - s->color_type == PNG_COLOR_TYPE_GRAY) { - avctx->pix_fmt = PIX_FMT_GRAY16BE; - } else if (s->bit_depth == 1 && - s->color_type == PNG_COLOR_TYPE_GRAY) { - avctx->pix_fmt = PIX_FMT_MONOBLACK; - } else if (s->color_type == PNG_COLOR_TYPE_PALETTE) { - avctx->pix_fmt = PIX_FMT_PAL8; - } else { - goto fail; - } - if(p->data[0]) - avctx->release_buffer(avctx, p); - - p->reference= 0; - if(avctx->get_buffer(avctx, p) < 0){ - av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - goto fail; - } - p->pict_type= FF_I_TYPE; - p->key_frame= 1; - p->interlaced_frame = !!s->interlace_type; - - /* compute the compressed row size */ - if (!s->interlace_type) { - s->crow_size = s->row_size + 1; - } else { - s->pass = 0; - s->pass_row_size = png_pass_row_size(s->pass, - s->bits_per_pixel, - s->width); - s->crow_size = s->pass_row_size + 1; - } -#ifdef DEBUG - av_log(avctx, AV_LOG_DEBUG, "row_size=%d crow_size =%d\n", - s->row_size, s->crow_size); -#endif - s->image_buf = p->data[0]; - s->image_linesize = p->linesize[0]; - /* copy the palette if needed */ - if (s->color_type == PNG_COLOR_TYPE_PALETTE) - memcpy(p->data[1], s->palette, 256 * sizeof(uint32_t)); - /* empty row is used if differencing to the first row */ - s->last_row = av_mallocz(s->row_size); - if (!s->last_row) - goto fail; - if (s->interlace_type || - s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) { - s->tmp_row = av_malloc(s->row_size); - if (!s->tmp_row) - goto fail; - } - /* compressed row */ - s->crow_buf = av_malloc(s->row_size + 1); - if (!s->crow_buf) - goto fail; - s->zstream.avail_out = s->crow_size; - s->zstream.next_out = s->crow_buf; - } - s->state |= PNG_IDAT; - if (png_decode_idat(s, length) < 0) - goto fail; - /* skip crc */ - crc = get32(&s->bytestream); - break; - case MKTAG('P', 'L', 'T', 'E'): - { - int n, i, r, g, b; - - if ((length % 3) != 0 || length > 256 * 3) - goto skip_tag; - /* read the palette */ - n = length / 3; - for(i=0;ibytestream++; - g = *s->bytestream++; - b = *s->bytestream++; - s->palette[i] = (0xff << 24) | (r << 16) | (g << 8) | b; - } - for(;i<256;i++) { - s->palette[i] = (0xff << 24); - } - s->state |= PNG_PLTE; - crc = get32(&s->bytestream); - } - break; - case MKTAG('t', 'R', 'N', 'S'): - { - int v, i; - - /* read the transparency. XXX: Only palette mode supported */ - if (s->color_type != PNG_COLOR_TYPE_PALETTE || - length > 256 || - !(s->state & PNG_PLTE)) - goto skip_tag; - for(i=0;ibytestream++; - s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24); - } - crc = get32(&s->bytestream); - } - break; - case MKTAG('I', 'E', 'N', 'D'): - if (!(s->state & PNG_ALLIMAGE)) - goto fail; - crc = get32(&s->bytestream); - goto exit_loop; - default: - /* skip tag */ - skip_tag: - s->bytestream += length + 4; - break; - } - } - exit_loop: - *picture= *(AVFrame*)&s->picture; - *data_size = sizeof(AVPicture); - - ret = s->bytestream - s->bytestream_start; - the_end: - inflateEnd(&s->zstream); - av_freep(&s->crow_buf); - av_freep(&s->last_row); - av_freep(&s->tmp_row); - return ret; - fail: - ret = -1; - goto the_end; -} -#endif - -#ifdef CONFIG_ENCODERS -static void png_write_chunk(uint8_t **f, uint32_t tag, - const uint8_t *buf, int length) -{ - uint32_t crc; - uint8_t tagbuf[4]; - - put32(f, length); - crc = crc32(0, Z_NULL, 0); - tagbuf[0] = tag; - tagbuf[1] = tag >> 8; - tagbuf[2] = tag >> 16; - tagbuf[3] = tag >> 24; - crc = crc32(crc, tagbuf, 4); - put32(f, bswap_32(tag)); - if (length > 0) { - crc = crc32(crc, buf, length); - memcpy(*f, buf, length); - *f += length; - } - put32(f, crc); -} - -/* XXX: use avcodec generic function ? */ -static void to_be32(uint8_t *p, uint32_t v) -{ - p[0] = v >> 24; - p[1] = v >> 16; - p[2] = v >> 8; - p[3] = v; -} - -/* XXX: do filtering */ -static int png_write_row(PNGContext *s, const uint8_t *data, int size) -{ - int ret; - - s->zstream.avail_in = size; - s->zstream.next_in = (uint8_t *)data; - while (s->zstream.avail_in > 0) { - ret = deflate(&s->zstream, Z_NO_FLUSH); - if (ret != Z_OK) - return -1; - if (s->zstream.avail_out == 0) { - if(s->bytestream_end - s->bytestream > IOBUF_SIZE + 100) - png_write_chunk(&s->bytestream, MKTAG('I', 'D', 'A', 'T'), s->buf, IOBUF_SIZE); - s->zstream.avail_out = IOBUF_SIZE; - s->zstream.next_out = s->buf; - } - } - return 0; -} -#endif /* CONFIG_ENCODERS */ - -static int common_init(AVCodecContext *avctx){ - PNGContext *s = avctx->priv_data; - - avcodec_get_frame_defaults((AVFrame*)&s->picture); - avctx->coded_frame= (AVFrame*)&s->picture; -// s->avctx= avctx; - - return 0; -} - -#ifdef CONFIG_ENCODERS -static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ - PNGContext *s = avctx->priv_data; - AVFrame *pict = data; - AVFrame * const p= (AVFrame*)&s->picture; - int bit_depth, color_type, y, len, row_size, ret, is_progressive; - int bits_per_pixel, pass_row_size; - uint8_t *ptr; - uint8_t *crow_buf = NULL; - uint8_t *tmp_buf = NULL; - - *p = *pict; - p->pict_type= FF_I_TYPE; - p->key_frame= 1; - - s->bytestream_start= - s->bytestream= buf; - s->bytestream_end= buf+buf_size; - - is_progressive = !!(avctx->flags & CODEC_FLAG_INTERLACED_DCT); - switch(avctx->pix_fmt) { - case PIX_FMT_RGB32: - bit_depth = 8; - color_type = PNG_COLOR_TYPE_RGB_ALPHA; - break; - case PIX_FMT_RGB24: - bit_depth = 8; - color_type = PNG_COLOR_TYPE_RGB; - break; - case PIX_FMT_GRAY8: - bit_depth = 8; - color_type = PNG_COLOR_TYPE_GRAY; - break; - case PIX_FMT_MONOBLACK: - bit_depth = 1; - color_type = PNG_COLOR_TYPE_GRAY; - break; - case PIX_FMT_PAL8: - bit_depth = 8; - color_type = PNG_COLOR_TYPE_PALETTE; - break; - default: - return -1; - } - bits_per_pixel = png_get_nb_channels(color_type) * bit_depth; - row_size = (avctx->width * bits_per_pixel + 7) >> 3; - - s->zstream.zalloc = png_zalloc; - s->zstream.zfree = png_zfree; - s->zstream.opaque = NULL; - ret = deflateInit2(&s->zstream, Z_DEFAULT_COMPRESSION, - Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY); - if (ret != Z_OK) - return -1; - crow_buf = av_malloc(row_size + 1); - if (!crow_buf) - goto fail; - if (is_progressive) { - tmp_buf = av_malloc(row_size + 1); - if (!tmp_buf) - goto fail; - } - - /* write png header */ - memcpy(s->bytestream, pngsig, 8); - s->bytestream += 8; - - to_be32(s->buf, avctx->width); - to_be32(s->buf + 4, avctx->height); - s->buf[8] = bit_depth; - s->buf[9] = color_type; - s->buf[10] = 0; /* compression type */ - s->buf[11] = 0; /* filter type */ - s->buf[12] = is_progressive; /* interlace type */ - - png_write_chunk(&s->bytestream, MKTAG('I', 'H', 'D', 'R'), s->buf, 13); - - /* put the palette if needed */ - if (color_type == PNG_COLOR_TYPE_PALETTE) { - int has_alpha, alpha, i; - unsigned int v; - uint32_t *palette; - uint8_t *alpha_ptr; - - palette = (uint32_t *)p->data[1]; - ptr = s->buf; - alpha_ptr = s->buf + 256 * 3; - has_alpha = 0; - for(i = 0; i < 256; i++) { - v = palette[i]; - alpha = v >> 24; - if (alpha && alpha != 0xff) - has_alpha = 1; - *alpha_ptr++ = alpha; - ptr[0] = v >> 16; - ptr[1] = v >> 8; - ptr[2] = v; - ptr += 3; - } - png_write_chunk(&s->bytestream, MKTAG('P', 'L', 'T', 'E'), s->buf, 256 * 3); - if (has_alpha) { - png_write_chunk(&s->bytestream, MKTAG('t', 'R', 'N', 'S'), s->buf + 256 * 3, 256); - } - } - - /* now put each row */ - s->zstream.avail_out = IOBUF_SIZE; - s->zstream.next_out = s->buf; - if (is_progressive) { - uint8_t *ptr1; - int pass; - - for(pass = 0; pass < NB_PASSES; pass++) { - /* NOTE: a pass is completely omited if no pixels would be - output */ - pass_row_size = png_pass_row_size(pass, bits_per_pixel, avctx->width); - if (pass_row_size > 0) { - for(y = 0; y < avctx->height; y++) { - if ((png_pass_ymask[pass] << (y & 7)) & 0x80) { - ptr = p->data[0] + y * p->linesize[0]; - if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) { - convert_from_rgb32(tmp_buf, ptr, avctx->width); - ptr1 = tmp_buf; - } else { - ptr1 = ptr; - } - png_get_interlaced_row(crow_buf + 1, pass_row_size, - bits_per_pixel, pass, - ptr1, avctx->width); - crow_buf[0] = PNG_FILTER_VALUE_NONE; - png_write_row(s, crow_buf, pass_row_size + 1); - } - } - } - } - } else { - for(y = 0; y < avctx->height; y++) { - ptr = p->data[0] + y * p->linesize[0]; - if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) - convert_from_rgb32(crow_buf + 1, ptr, avctx->width); - else - memcpy(crow_buf + 1, ptr, row_size); - crow_buf[0] = PNG_FILTER_VALUE_NONE; - png_write_row(s, crow_buf, row_size + 1); - } - } - /* compress last bytes */ - for(;;) { - ret = deflate(&s->zstream, Z_FINISH); - if (ret == Z_OK || ret == Z_STREAM_END) { - len = IOBUF_SIZE - s->zstream.avail_out; - if (len > 0 && s->bytestream_end - s->bytestream > len + 100) { - png_write_chunk(&s->bytestream, MKTAG('I', 'D', 'A', 'T'), s->buf, len); - } - s->zstream.avail_out = IOBUF_SIZE; - s->zstream.next_out = s->buf; - if (ret == Z_STREAM_END) - break; - } else { - goto fail; - } - } - png_write_chunk(&s->bytestream, MKTAG('I', 'E', 'N', 'D'), NULL, 0); - - ret = s->bytestream - s->bytestream_start; - the_end: - av_free(crow_buf); - av_free(tmp_buf); - deflateEnd(&s->zstream); - return ret; - fail: - ret = -1; - goto the_end; -} -#endif - -#ifdef CONFIG_PNG_DECODER -AVCodec png_decoder = { - "png", - CODEC_TYPE_VIDEO, - CODEC_ID_PNG, - sizeof(PNGContext), - common_init, - NULL, - NULL, //decode_end, - decode_frame, - 0 /*CODEC_CAP_DR1*/ /*| CODEC_CAP_DRAW_HORIZ_BAND*/, - NULL -}; -#endif - -#ifdef CONFIG_PNG_ENCODER -AVCodec png_encoder = { - "png", - CODEC_TYPE_VIDEO, - CODEC_ID_PNG, - sizeof(PNGContext), - common_init, - encode_frame, - NULL, //encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_PAL8, PIX_FMT_GRAY8, PIX_FMT_MONOBLACK, -1}, -}; -#endif // CONFIG_PNG_ENCODER diff --git a/contrib/ffmpeg/libavcodec/png.h b/contrib/ffmpeg/libavcodec/png.h new file mode 100644 index 000000000..6e16f62e0 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/png.h @@ -0,0 +1,77 @@ +/* + * PNG image format + * Copyright (c) 2003 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_PNG_H +#define FFMPEG_PNG_H + +#include + +#define PNG_COLOR_MASK_PALETTE 1 +#define PNG_COLOR_MASK_COLOR 2 +#define PNG_COLOR_MASK_ALPHA 4 + +#define PNG_COLOR_TYPE_GRAY 0 +#define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE) +#define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR) +#define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA) +#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA) + +#define PNG_FILTER_TYPE_LOCO 64 +#define PNG_FILTER_VALUE_NONE 0 +#define PNG_FILTER_VALUE_SUB 1 +#define PNG_FILTER_VALUE_UP 2 +#define PNG_FILTER_VALUE_AVG 3 +#define PNG_FILTER_VALUE_PAETH 4 +#define PNG_FILTER_VALUE_MIXED 5 + +#define PNG_IHDR 0x0001 +#define PNG_IDAT 0x0002 +#define PNG_ALLIMAGE 0x0004 +#define PNG_PLTE 0x0008 + +#define NB_PASSES 7 + +extern const uint8_t ff_pngsig[8]; +extern const uint8_t ff_mngsig[8]; + +/* Mask to determine which y pixels are valid in a pass */ +extern const uint8_t ff_png_pass_ymask[NB_PASSES]; + +/* minimum x value */ +extern const uint8_t ff_png_pass_xmin[NB_PASSES]; + +/* x shift to get row width */ +extern const uint8_t ff_png_pass_xshift[NB_PASSES]; + +/* Mask to determine which pixels are valid in a pass */ +extern const uint8_t ff_png_pass_mask[NB_PASSES]; + +extern void *ff_png_zalloc(void *opaque, unsigned int items, + unsigned int size); + +extern void ff_png_zfree(void *opaque, void *ptr); + +extern int ff_png_get_nb_channels(int color_type); + +/* compute the row size of an interleaved pass */ +extern int ff_png_pass_row_size(int pass, int bits_per_pixel, int width); + +#endif /* FFMPEG_PNG_H */ diff --git a/contrib/ffmpeg/libavcodec/pngdec.c b/contrib/ffmpeg/libavcodec/pngdec.c new file mode 100644 index 000000000..90dac4dfa --- /dev/null +++ b/contrib/ffmpeg/libavcodec/pngdec.c @@ -0,0 +1,621 @@ +/* + * PNG image format + * Copyright (c) 2003 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avcodec.h" +#include "bytestream.h" +#include "png.h" +#include "dsputil.h" + +/* TODO: + * - add 2, 4 and 16 bit depth support + */ + +#include + +//#define DEBUG + +typedef struct PNGDecContext { + DSPContext dsp; + + const uint8_t *bytestream; + const uint8_t *bytestream_start; + const uint8_t *bytestream_end; + AVFrame picture; + + int state; + int width, height; + int bit_depth; + int color_type; + int compression_type; + int interlace_type; + int filter_type; + int channels; + int bits_per_pixel; + int bpp; + + uint8_t *image_buf; + int image_linesize; + uint32_t palette[256]; + uint8_t *crow_buf; + uint8_t *last_row; + uint8_t *tmp_row; + int pass; + int crow_size; /* compressed row size (include filter type) */ + int row_size; /* decompressed row size */ + int pass_row_size; /* decompress row size of the current pass */ + int y; + z_stream zstream; +} PNGDecContext; + +/* Mask to determine which y pixels can be written in a pass */ +static const uint8_t png_pass_dsp_ymask[NB_PASSES] = { + 0xff, 0xff, 0x0f, 0xcc, 0x33, 0xff, 0x55, +}; + +/* Mask to determine which pixels to overwrite while displaying */ +static const uint8_t png_pass_dsp_mask[NB_PASSES] = { + 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff +}; + +/* NOTE: we try to construct a good looking image at each pass. width + is the original image width. We also do pixel format conversion at + this stage */ +static void png_put_interlaced_row(uint8_t *dst, int width, + int bits_per_pixel, int pass, + int color_type, const uint8_t *src) +{ + int x, mask, dsp_mask, j, src_x, b, bpp; + uint8_t *d; + const uint8_t *s; + + mask = ff_png_pass_mask[pass]; + dsp_mask = png_pass_dsp_mask[pass]; + switch(bits_per_pixel) { + case 1: + /* we must initialize the line to zero before writing to it */ + if (pass == 0) + memset(dst, 0, (width + 7) >> 3); + src_x = 0; + for(x = 0; x < width; x++) { + j = (x & 7); + if ((dsp_mask << j) & 0x80) { + b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1; + dst[x >> 3] |= b << (7 - j); + } + if ((mask << j) & 0x80) + src_x++; + } + break; + default: + bpp = bits_per_pixel >> 3; + d = dst; + s = src; + if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) { + for(x = 0; x < width; x++) { + j = x & 7; + if ((dsp_mask << j) & 0x80) { + *(uint32_t *)d = (s[3] << 24) | (s[0] << 16) | (s[1] << 8) | s[2]; + } + d += bpp; + if ((mask << j) & 0x80) + s += bpp; + } + } else { + for(x = 0; x < width; x++) { + j = x & 7; + if ((dsp_mask << j) & 0x80) { + memcpy(d, s, bpp); + } + d += bpp; + if ((mask << j) & 0x80) + s += bpp; + } + } + break; + } +} + +void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp) +{ + int i; + for(i = 0; i < w; i++) { + int a, b, c, p, pa, pb, pc; + + a = dst[i - bpp]; + b = top[i]; + c = top[i - bpp]; + + p = b - c; + pc = a - c; + + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); + + if (pa <= pb && pa <= pc) + p = a; + else if (pb <= pc) + p = b; + else + p = c; + dst[i] = p + src[i]; + } +} + +#define UNROLL1(bpp, op) {\ + r = dst[0];\ + if(bpp >= 2) g = dst[1];\ + if(bpp >= 3) b = dst[2];\ + if(bpp >= 4) a = dst[3];\ + for(; i < size; i+=bpp) {\ + dst[i+0] = r = op(r, src[i+0], last[i+0]);\ + if(bpp == 1) continue;\ + dst[i+1] = g = op(g, src[i+1], last[i+1]);\ + if(bpp == 2) continue;\ + dst[i+2] = b = op(b, src[i+2], last[i+2]);\ + if(bpp == 3) continue;\ + dst[i+3] = a = op(a, src[i+3], last[i+3]);\ + }\ +} + +#define UNROLL_FILTER(op)\ + if(bpp == 1) UNROLL1(1, op)\ + else if(bpp == 2) UNROLL1(2, op)\ + else if(bpp == 3) UNROLL1(3, op)\ + else if(bpp == 4) UNROLL1(4, op)\ + +/* NOTE: 'dst' can be equal to 'last' */ +static void png_filter_row(DSPContext *dsp, uint8_t *dst, int filter_type, + uint8_t *src, uint8_t *last, int size, int bpp) +{ + int i, p, r, g, b, a; + + switch(filter_type) { + case PNG_FILTER_VALUE_NONE: + memcpy(dst, src, size); + break; + case PNG_FILTER_VALUE_SUB: + for(i = 0; i < bpp; i++) { + dst[i] = src[i]; + } + if(bpp == 4) { + p = *(int*)dst; + for(; i < size; i+=bpp) { + int s = *(int*)(src+i); + p = ((s&0x7f7f7f7f) + (p&0x7f7f7f7f)) ^ ((s^p)&0x80808080); + *(int*)(dst+i) = p; + } + } else { +#define OP_SUB(x,s,l) x+s + UNROLL_FILTER(OP_SUB); + } + break; + case PNG_FILTER_VALUE_UP: + dsp->add_bytes_l2(dst, src, last, size); + break; + case PNG_FILTER_VALUE_AVG: + for(i = 0; i < bpp; i++) { + p = (last[i] >> 1); + dst[i] = p + src[i]; + } +#define OP_AVG(x,s,l) (((x + l) >> 1) + s) & 0xff + UNROLL_FILTER(OP_AVG); + break; + case PNG_FILTER_VALUE_PAETH: + for(i = 0; i < bpp; i++) { + p = last[i]; + dst[i] = p + src[i]; + } + if(bpp > 1 && size > 4) { + // would write off the end of the array if we let it process the last pixel with bpp=3 + int w = bpp==4 ? size : size-3; + dsp->add_png_paeth_prediction(dst+i, src+i, last+i, w-i, bpp); + i = w; + } + ff_add_png_paeth_prediction(dst+i, src+i, last+i, size-i, bpp); + break; + } +} + +static av_always_inline void convert_to_rgb32_loco(uint8_t *dst, const uint8_t *src, int width, int loco) +{ + int j; + unsigned int r, g, b, a; + + for(j = 0;j < width; j++) { + r = src[0]; + g = src[1]; + b = src[2]; + a = src[3]; + if(loco) { + r = (r+g)&0xff; + b = (b+g)&0xff; + } + *(uint32_t *)dst = (a << 24) | (r << 16) | (g << 8) | b; + dst += 4; + src += 4; + } +} + +static void convert_to_rgb32(uint8_t *dst, const uint8_t *src, int width, int loco) +{ + if(loco) + convert_to_rgb32_loco(dst, src, width, 1); + else + convert_to_rgb32_loco(dst, src, width, 0); +} + +static void deloco_rgb24(uint8_t *dst, int size) +{ + int i; + for(i=0; iinterlace_type) { + ptr = s->image_buf + s->image_linesize * s->y; + /* need to swap bytes correctly for RGB_ALPHA */ + if (s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) { + png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1, + s->last_row, s->row_size, s->bpp); + convert_to_rgb32(ptr, s->tmp_row, s->width, s->filter_type == PNG_FILTER_TYPE_LOCO); + FFSWAP(uint8_t*, s->last_row, s->tmp_row); + } else { + /* in normal case, we avoid one copy */ + if (s->y == 0) + last_row = s->last_row; + else + last_row = ptr - s->image_linesize; + + png_filter_row(&s->dsp, ptr, s->crow_buf[0], s->crow_buf + 1, + last_row, s->row_size, s->bpp); + } + /* loco lags by 1 row so that it doesn't interfere with top prediction */ + if (s->filter_type == PNG_FILTER_TYPE_LOCO && + s->color_type == PNG_COLOR_TYPE_RGB && s->y > 0) + deloco_rgb24(ptr - s->image_linesize, s->row_size); + s->y++; + if (s->y == s->height) { + s->state |= PNG_ALLIMAGE; + if (s->filter_type == PNG_FILTER_TYPE_LOCO && + s->color_type == PNG_COLOR_TYPE_RGB) + deloco_rgb24(ptr, s->row_size); + } + } else { + got_line = 0; + for(;;) { + ptr = s->image_buf + s->image_linesize * s->y; + if ((ff_png_pass_ymask[s->pass] << (s->y & 7)) & 0x80) { + /* if we already read one row, it is time to stop to + wait for the next one */ + if (got_line) + break; + png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1, + s->last_row, s->pass_row_size, s->bpp); + FFSWAP(uint8_t*, s->last_row, s->tmp_row); + got_line = 1; + } + if ((png_pass_dsp_ymask[s->pass] << (s->y & 7)) & 0x80) { + /* NOTE: RGB32 is handled directly in png_put_interlaced_row */ + png_put_interlaced_row(ptr, s->width, s->bits_per_pixel, s->pass, + s->color_type, s->last_row); + } + s->y++; + if (s->y == s->height) { + for(;;) { + if (s->pass == NB_PASSES - 1) { + s->state |= PNG_ALLIMAGE; + goto the_end; + } else { + s->pass++; + s->y = 0; + s->pass_row_size = ff_png_pass_row_size(s->pass, + s->bits_per_pixel, + s->width); + s->crow_size = s->pass_row_size + 1; + if (s->pass_row_size != 0) + break; + /* skip pass if empty row */ + } + } + } + } + the_end: ; + } +} + +static int png_decode_idat(PNGDecContext *s, int length) +{ + int ret; + s->zstream.avail_in = length; + s->zstream.next_in = s->bytestream; + s->bytestream += length; + + if(s->bytestream > s->bytestream_end) + return -1; + + /* decode one line if possible */ + while (s->zstream.avail_in > 0) { + ret = inflate(&s->zstream, Z_PARTIAL_FLUSH); + if (ret != Z_OK && ret != Z_STREAM_END) { + return -1; + } + if (s->zstream.avail_out == 0) { + if (!(s->state & PNG_ALLIMAGE)) { + png_handle_row(s); + } + s->zstream.avail_out = s->crow_size; + s->zstream.next_out = s->crow_buf; + } + } + return 0; +} + +static int decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size) +{ + PNGDecContext * const s = avctx->priv_data; + AVFrame *picture = data; + AVFrame * const p= (AVFrame*)&s->picture; + uint32_t tag, length; + int ret, crc; + + s->bytestream_start= + s->bytestream= buf; + s->bytestream_end= buf + buf_size; + + /* check signature */ + if (memcmp(s->bytestream, ff_pngsig, 8) != 0 && + memcmp(s->bytestream, ff_mngsig, 8) != 0) + return -1; + s->bytestream+= 8; + s->y= + s->state=0; +// memset(s, 0, sizeof(PNGDecContext)); + /* init the zlib */ + s->zstream.zalloc = ff_png_zalloc; + s->zstream.zfree = ff_png_zfree; + s->zstream.opaque = NULL; + ret = inflateInit(&s->zstream); + if (ret != Z_OK) + return -1; + for(;;) { + int tag32; + if (s->bytestream >= s->bytestream_end) + goto fail; + length = bytestream_get_be32(&s->bytestream); + if (length > 0x7fffffff) + goto fail; + tag32 = bytestream_get_be32(&s->bytestream); + tag = bswap_32(tag32); +#ifdef DEBUG + av_log(avctx, AV_LOG_DEBUG, "png: tag=%c%c%c%c length=%u\n", + (tag & 0xff), + ((tag >> 8) & 0xff), + ((tag >> 16) & 0xff), + ((tag >> 24) & 0xff), length); +#endif + switch(tag) { + case MKTAG('I', 'H', 'D', 'R'): + if (length != 13) + goto fail; + s->width = bytestream_get_be32(&s->bytestream); + s->height = bytestream_get_be32(&s->bytestream); + if(avcodec_check_dimensions(avctx, s->width, s->height)){ + s->width= s->height= 0; + goto fail; + } + s->bit_depth = *s->bytestream++; + s->color_type = *s->bytestream++; + s->compression_type = *s->bytestream++; + s->filter_type = *s->bytestream++; + s->interlace_type = *s->bytestream++; + crc = bytestream_get_be32(&s->bytestream); + s->state |= PNG_IHDR; +#ifdef DEBUG + av_log(avctx, AV_LOG_DEBUG, "width=%d height=%d depth=%d color_type=%d compression_type=%d filter_type=%d interlace_type=%d\n", + s->width, s->height, s->bit_depth, s->color_type, + s->compression_type, s->filter_type, s->interlace_type); +#endif + break; + case MKTAG('I', 'D', 'A', 'T'): + if (!(s->state & PNG_IHDR)) + goto fail; + if (!(s->state & PNG_IDAT)) { + /* init image info */ + avctx->width = s->width; + avctx->height = s->height; + + s->channels = ff_png_get_nb_channels(s->color_type); + s->bits_per_pixel = s->bit_depth * s->channels; + s->bpp = (s->bits_per_pixel + 7) >> 3; + s->row_size = (avctx->width * s->bits_per_pixel + 7) >> 3; + + if (s->bit_depth == 8 && + s->color_type == PNG_COLOR_TYPE_RGB) { + avctx->pix_fmt = PIX_FMT_RGB24; + } else if (s->bit_depth == 8 && + s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) { + avctx->pix_fmt = PIX_FMT_RGB32; + } else if (s->bit_depth == 8 && + s->color_type == PNG_COLOR_TYPE_GRAY) { + avctx->pix_fmt = PIX_FMT_GRAY8; + } else if (s->bit_depth == 16 && + s->color_type == PNG_COLOR_TYPE_GRAY) { + avctx->pix_fmt = PIX_FMT_GRAY16BE; + } else if (s->bit_depth == 1 && + s->color_type == PNG_COLOR_TYPE_GRAY) { + avctx->pix_fmt = PIX_FMT_MONOBLACK; + } else if (s->color_type == PNG_COLOR_TYPE_PALETTE) { + avctx->pix_fmt = PIX_FMT_PAL8; + } else { + goto fail; + } + if(p->data[0]) + avctx->release_buffer(avctx, p); + + p->reference= 0; + if(avctx->get_buffer(avctx, p) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + goto fail; + } + p->pict_type= FF_I_TYPE; + p->key_frame= 1; + p->interlaced_frame = !!s->interlace_type; + + /* compute the compressed row size */ + if (!s->interlace_type) { + s->crow_size = s->row_size + 1; + } else { + s->pass = 0; + s->pass_row_size = ff_png_pass_row_size(s->pass, + s->bits_per_pixel, + s->width); + s->crow_size = s->pass_row_size + 1; + } +#ifdef DEBUG + av_log(avctx, AV_LOG_DEBUG, "row_size=%d crow_size =%d\n", + s->row_size, s->crow_size); +#endif + s->image_buf = p->data[0]; + s->image_linesize = p->linesize[0]; + /* copy the palette if needed */ + if (s->color_type == PNG_COLOR_TYPE_PALETTE) + memcpy(p->data[1], s->palette, 256 * sizeof(uint32_t)); + /* empty row is used if differencing to the first row */ + s->last_row = av_mallocz(s->row_size); + if (!s->last_row) + goto fail; + if (s->interlace_type || + s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) { + s->tmp_row = av_malloc(s->row_size); + if (!s->tmp_row) + goto fail; + } + /* compressed row */ + s->crow_buf = av_malloc(s->row_size + 1); + if (!s->crow_buf) + goto fail; + s->zstream.avail_out = s->crow_size; + s->zstream.next_out = s->crow_buf; + } + s->state |= PNG_IDAT; + if (png_decode_idat(s, length) < 0) + goto fail; + /* skip crc */ + crc = bytestream_get_be32(&s->bytestream); + break; + case MKTAG('P', 'L', 'T', 'E'): + { + int n, i, r, g, b; + + if ((length % 3) != 0 || length > 256 * 3) + goto skip_tag; + /* read the palette */ + n = length / 3; + for(i=0;ibytestream++; + g = *s->bytestream++; + b = *s->bytestream++; + s->palette[i] = (0xff << 24) | (r << 16) | (g << 8) | b; + } + for(;i<256;i++) { + s->palette[i] = (0xff << 24); + } + s->state |= PNG_PLTE; + crc = bytestream_get_be32(&s->bytestream); + } + break; + case MKTAG('t', 'R', 'N', 'S'): + { + int v, i; + + /* read the transparency. XXX: Only palette mode supported */ + if (s->color_type != PNG_COLOR_TYPE_PALETTE || + length > 256 || + !(s->state & PNG_PLTE)) + goto skip_tag; + for(i=0;ibytestream++; + s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24); + } + crc = bytestream_get_be32(&s->bytestream); + } + break; + case MKTAG('I', 'E', 'N', 'D'): + if (!(s->state & PNG_ALLIMAGE)) + goto fail; + crc = bytestream_get_be32(&s->bytestream); + goto exit_loop; + default: + /* skip tag */ + skip_tag: + s->bytestream += length + 4; + break; + } + } + exit_loop: + *picture= *(AVFrame*)&s->picture; + *data_size = sizeof(AVPicture); + + ret = s->bytestream - s->bytestream_start; + the_end: + inflateEnd(&s->zstream); + av_freep(&s->crow_buf); + av_freep(&s->last_row); + av_freep(&s->tmp_row); + return ret; + fail: + ret = -1; + goto the_end; +} + +static int png_dec_init(AVCodecContext *avctx){ + PNGDecContext *s = avctx->priv_data; + + avcodec_get_frame_defaults((AVFrame*)&s->picture); + avctx->coded_frame= (AVFrame*)&s->picture; + dsputil_init(&s->dsp, avctx); + + return 0; +} + +AVCodec png_decoder = { + "png", + CODEC_TYPE_VIDEO, + CODEC_ID_PNG, + sizeof(PNGDecContext), + png_dec_init, + NULL, + NULL, //decode_end, + decode_frame, + 0 /*CODEC_CAP_DR1*/ /*| CODEC_CAP_DRAW_HORIZ_BAND*/, + NULL +}; diff --git a/contrib/ffmpeg/libavcodec/pngenc.c b/contrib/ffmpeg/libavcodec/pngenc.c new file mode 100644 index 000000000..703371d85 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/pngenc.c @@ -0,0 +1,448 @@ +/* + * PNG image format + * Copyright (c) 2003 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avcodec.h" +#include "bytestream.h" +#include "png.h" +#include + +/* TODO: + * - add 2, 4 and 16 bit depth support + */ + +#include + +//#define DEBUG + +#define IOBUF_SIZE 4096 + +typedef struct PNGEncContext { + DSPContext dsp; + + uint8_t *bytestream; + uint8_t *bytestream_start; + uint8_t *bytestream_end; + AVFrame picture; + + int filter_type; + + z_stream zstream; + uint8_t buf[IOBUF_SIZE]; +} PNGEncContext; + +static void png_get_interlaced_row(uint8_t *dst, int row_size, + int bits_per_pixel, int pass, + const uint8_t *src, int width) +{ + int x, mask, dst_x, j, b, bpp; + uint8_t *d; + const uint8_t *s; + + mask = ff_png_pass_mask[pass]; + switch(bits_per_pixel) { + case 1: + memset(dst, 0, row_size); + dst_x = 0; + for(x = 0; x < width; x++) { + j = (x & 7); + if ((mask << j) & 0x80) { + b = (src[x >> 3] >> (7 - j)) & 1; + dst[dst_x >> 3] |= b << (7 - (dst_x & 7)); + dst_x++; + } + } + break; + default: + bpp = bits_per_pixel >> 3; + d = dst; + s = src; + for(x = 0; x < width; x++) { + j = x & 7; + if ((mask << j) & 0x80) { + memcpy(d, s, bpp); + d += bpp; + } + s += bpp; + } + break; + } +} + +static void sub_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp) +{ + int i; + for(i = 0; i < w; i++) { + int a, b, c, p, pa, pb, pc; + + a = src[i - bpp]; + b = top[i]; + c = top[i - bpp]; + + p = b - c; + pc = a - c; + + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); + + if (pa <= pb && pa <= pc) + p = a; + else if (pb <= pc) + p = b; + else + p = c; + dst[i] = src[i] - p; + } +} + +static void png_filter_row(DSPContext *dsp, uint8_t *dst, int filter_type, + uint8_t *src, uint8_t *top, int size, int bpp) +{ + int i; + + switch(filter_type) { + case PNG_FILTER_VALUE_NONE: + memcpy(dst, src, size); + break; + case PNG_FILTER_VALUE_SUB: + dsp->diff_bytes(dst, src, src-bpp, size); + memcpy(dst, src, bpp); + break; + case PNG_FILTER_VALUE_UP: + dsp->diff_bytes(dst, src, top, size); + break; + case PNG_FILTER_VALUE_AVG: + for(i = 0; i < bpp; i++) + dst[i] = src[i] - (top[i] >> 1); + for(; i < size; i++) + dst[i] = src[i] - ((src[i-bpp] + top[i]) >> 1); + break; + case PNG_FILTER_VALUE_PAETH: + for(i = 0; i < bpp; i++) + dst[i] = src[i] - top[i]; + sub_png_paeth_prediction(dst+i, src+i, top+i, size-i, bpp); + break; + } +} + +static uint8_t *png_choose_filter(PNGEncContext *s, uint8_t *dst, + uint8_t *src, uint8_t *top, int size, int bpp) +{ + int pred = s->filter_type; + assert(bpp || !pred); + if(!top && pred) + pred = PNG_FILTER_VALUE_SUB; + if(pred == PNG_FILTER_VALUE_MIXED) { + int i; + int cost, bcost = INT_MAX; + uint8_t *buf1 = dst, *buf2 = dst + size + 16; + for(pred=0; pred<5; pred++) { + png_filter_row(&s->dsp, buf1+1, pred, src, top, size, bpp); + buf1[0] = pred; + cost = 0; + for(i=0; i<=size; i++) + cost += abs((int8_t)buf1[i]); + if(cost < bcost) { + bcost = cost; + FFSWAP(uint8_t*, buf1, buf2); + } + } + return buf2; + } else { + png_filter_row(&s->dsp, dst+1, pred, src, top, size, bpp); + dst[0] = pred; + return dst; + } +} + +static void convert_from_rgb32(uint8_t *dst, const uint8_t *src, int width) +{ + uint8_t *d; + int j; + unsigned int v; + + d = dst; + for(j = 0; j < width; j++) { + v = ((const uint32_t *)src)[j]; + d[0] = v >> 16; + d[1] = v >> 8; + d[2] = v; + d[3] = v >> 24; + d += 4; + } +} + +static void png_write_chunk(uint8_t **f, uint32_t tag, + const uint8_t *buf, int length) +{ + uint32_t crc; + uint8_t tagbuf[4]; + + bytestream_put_be32(f, length); + crc = crc32(0, Z_NULL, 0); + AV_WL32(tagbuf, tag); + crc = crc32(crc, tagbuf, 4); + bytestream_put_be32(f, bswap_32(tag)); + if (length > 0) { + crc = crc32(crc, buf, length); + memcpy(*f, buf, length); + *f += length; + } + bytestream_put_be32(f, crc); +} + +/* XXX: do filtering */ +static int png_write_row(PNGEncContext *s, const uint8_t *data, int size) +{ + int ret; + + s->zstream.avail_in = size; + s->zstream.next_in = (uint8_t *)data; + while (s->zstream.avail_in > 0) { + ret = deflate(&s->zstream, Z_NO_FLUSH); + if (ret != Z_OK) + return -1; + if (s->zstream.avail_out == 0) { + if(s->bytestream_end - s->bytestream > IOBUF_SIZE + 100) + png_write_chunk(&s->bytestream, MKTAG('I', 'D', 'A', 'T'), s->buf, IOBUF_SIZE); + s->zstream.avail_out = IOBUF_SIZE; + s->zstream.next_out = s->buf; + } + } + return 0; +} + +static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ + PNGEncContext *s = avctx->priv_data; + AVFrame *pict = data; + AVFrame * const p= (AVFrame*)&s->picture; + int bit_depth, color_type, y, len, row_size, ret, is_progressive; + int bits_per_pixel, pass_row_size; + int compression_level; + uint8_t *ptr, *top; + uint8_t *crow_base = NULL, *crow_buf, *crow; + uint8_t *progressive_buf = NULL; + uint8_t *rgba_buf = NULL; + uint8_t *top_buf = NULL; + + *p = *pict; + p->pict_type= FF_I_TYPE; + p->key_frame= 1; + + s->bytestream_start= + s->bytestream= buf; + s->bytestream_end= buf+buf_size; + + is_progressive = !!(avctx->flags & CODEC_FLAG_INTERLACED_DCT); + switch(avctx->pix_fmt) { + case PIX_FMT_RGB32: + bit_depth = 8; + color_type = PNG_COLOR_TYPE_RGB_ALPHA; + break; + case PIX_FMT_RGB24: + bit_depth = 8; + color_type = PNG_COLOR_TYPE_RGB; + break; + case PIX_FMT_GRAY8: + bit_depth = 8; + color_type = PNG_COLOR_TYPE_GRAY; + break; + case PIX_FMT_MONOBLACK: + bit_depth = 1; + color_type = PNG_COLOR_TYPE_GRAY; + break; + case PIX_FMT_PAL8: + bit_depth = 8; + color_type = PNG_COLOR_TYPE_PALETTE; + break; + default: + return -1; + } + bits_per_pixel = ff_png_get_nb_channels(color_type) * bit_depth; + row_size = (avctx->width * bits_per_pixel + 7) >> 3; + + s->zstream.zalloc = ff_png_zalloc; + s->zstream.zfree = ff_png_zfree; + s->zstream.opaque = NULL; + compression_level = avctx->compression_level == FF_COMPRESSION_DEFAULT ? + Z_DEFAULT_COMPRESSION : + av_clip(avctx->compression_level, 0, 9); + ret = deflateInit2(&s->zstream, compression_level, + Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY); + if (ret != Z_OK) + return -1; + crow_base = av_malloc((row_size + 32) << (s->filter_type == PNG_FILTER_VALUE_MIXED)); + if (!crow_base) + goto fail; + crow_buf = crow_base + 15; // pixel data should be aligned, but there's a control byte before it + if (is_progressive) { + progressive_buf = av_malloc(row_size + 1); + if (!progressive_buf) + goto fail; + } + if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) { + rgba_buf = av_malloc(row_size + 1); + if (!rgba_buf) + goto fail; + } + if (is_progressive || color_type == PNG_COLOR_TYPE_RGB_ALPHA) { + top_buf = av_malloc(row_size + 1); + if (!top_buf) + goto fail; + } + + /* write png header */ + memcpy(s->bytestream, ff_pngsig, 8); + s->bytestream += 8; + + AV_WB32(s->buf, avctx->width); + AV_WB32(s->buf + 4, avctx->height); + s->buf[8] = bit_depth; + s->buf[9] = color_type; + s->buf[10] = 0; /* compression type */ + s->buf[11] = 0; /* filter type */ + s->buf[12] = is_progressive; /* interlace type */ + + png_write_chunk(&s->bytestream, MKTAG('I', 'H', 'D', 'R'), s->buf, 13); + + /* put the palette if needed */ + if (color_type == PNG_COLOR_TYPE_PALETTE) { + int has_alpha, alpha, i; + unsigned int v; + uint32_t *palette; + uint8_t *alpha_ptr; + + palette = (uint32_t *)p->data[1]; + ptr = s->buf; + alpha_ptr = s->buf + 256 * 3; + has_alpha = 0; + for(i = 0; i < 256; i++) { + v = palette[i]; + alpha = v >> 24; + if (alpha && alpha != 0xff) + has_alpha = 1; + *alpha_ptr++ = alpha; + bytestream_put_be24(&ptr, v); + } + png_write_chunk(&s->bytestream, MKTAG('P', 'L', 'T', 'E'), s->buf, 256 * 3); + if (has_alpha) { + png_write_chunk(&s->bytestream, MKTAG('t', 'R', 'N', 'S'), s->buf + 256 * 3, 256); + } + } + + /* now put each row */ + s->zstream.avail_out = IOBUF_SIZE; + s->zstream.next_out = s->buf; + if (is_progressive) { + int pass; + + for(pass = 0; pass < NB_PASSES; pass++) { + /* NOTE: a pass is completely omited if no pixels would be + output */ + pass_row_size = ff_png_pass_row_size(pass, bits_per_pixel, avctx->width); + if (pass_row_size > 0) { + top = NULL; + for(y = 0; y < avctx->height; y++) { + if ((ff_png_pass_ymask[pass] << (y & 7)) & 0x80) { + ptr = p->data[0] + y * p->linesize[0]; + FFSWAP(uint8_t*, progressive_buf, top_buf); + if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) { + convert_from_rgb32(rgba_buf, ptr, avctx->width); + ptr = rgba_buf; + } + png_get_interlaced_row(progressive_buf, pass_row_size, + bits_per_pixel, pass, + ptr, avctx->width); + crow = png_choose_filter(s, crow_buf, progressive_buf, top, pass_row_size, bits_per_pixel>>3); + png_write_row(s, crow, pass_row_size + 1); + top = progressive_buf; + } + } + } + } + } else { + top = NULL; + for(y = 0; y < avctx->height; y++) { + ptr = p->data[0] + y * p->linesize[0]; + if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) { + FFSWAP(uint8_t*, rgba_buf, top_buf); + convert_from_rgb32(rgba_buf, ptr, avctx->width); + ptr = rgba_buf; + } + crow = png_choose_filter(s, crow_buf, ptr, top, row_size, bits_per_pixel>>3); + png_write_row(s, crow, row_size + 1); + top = ptr; + } + } + /* compress last bytes */ + for(;;) { + ret = deflate(&s->zstream, Z_FINISH); + if (ret == Z_OK || ret == Z_STREAM_END) { + len = IOBUF_SIZE - s->zstream.avail_out; + if (len > 0 && s->bytestream_end - s->bytestream > len + 100) { + png_write_chunk(&s->bytestream, MKTAG('I', 'D', 'A', 'T'), s->buf, len); + } + s->zstream.avail_out = IOBUF_SIZE; + s->zstream.next_out = s->buf; + if (ret == Z_STREAM_END) + break; + } else { + goto fail; + } + } + png_write_chunk(&s->bytestream, MKTAG('I', 'E', 'N', 'D'), NULL, 0); + + ret = s->bytestream - s->bytestream_start; + the_end: + av_free(crow_base); + av_free(progressive_buf); + av_free(rgba_buf); + av_free(top_buf); + deflateEnd(&s->zstream); + return ret; + fail: + ret = -1; + goto the_end; +} + +static int png_enc_init(AVCodecContext *avctx){ + PNGEncContext *s = avctx->priv_data; + + avcodec_get_frame_defaults((AVFrame*)&s->picture); + avctx->coded_frame= (AVFrame*)&s->picture; + dsputil_init(&s->dsp, avctx); + + s->filter_type = av_clip(avctx->prediction_method, PNG_FILTER_VALUE_NONE, PNG_FILTER_VALUE_MIXED); + if(avctx->pix_fmt == PIX_FMT_MONOBLACK) + s->filter_type = PNG_FILTER_VALUE_NONE; + + return 0; +} + +AVCodec png_encoder = { + "png", + CODEC_TYPE_VIDEO, + CODEC_ID_PNG, + sizeof(PNGEncContext), + png_enc_init, + encode_frame, + NULL, //encode_end, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_PAL8, PIX_FMT_GRAY8, PIX_FMT_MONOBLACK, -1}, +}; diff --git a/contrib/ffmpeg/libavcodec/pnm.c b/contrib/ffmpeg/libavcodec/pnm.c index 4c9c46fee..1f28aced6 100644 --- a/contrib/ffmpeg/libavcodec/pnm.c +++ b/contrib/ffmpeg/libavcodec/pnm.c @@ -19,14 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avcodec.h" -#include "parser.h" //for ParseContext - -typedef struct PNMContext { - uint8_t *bytestream; - uint8_t *bytestream_start; - uint8_t *bytestream_end; - AVFrame picture; -} PNMContext; +#include "pnm.h" static inline int pnm_space(int c) { @@ -59,16 +52,7 @@ static void pnm_get(PNMContext *sc, char *str, int buf_size) *s = '\0'; } -static int common_init(AVCodecContext *avctx){ - PNMContext *s = avctx->priv_data; - - avcodec_get_frame_defaults((AVFrame*)&s->picture); - avctx->coded_frame= (AVFrame*)&s->picture; - - return 0; -} - -static int pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){ +int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){ char buf1[32], tuple_type[32]; int h, w, depth, maxval; @@ -142,8 +126,12 @@ static int pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){ return -1; if (avctx->pix_fmt != PIX_FMT_MONOWHITE) { pnm_get(s, buf1, sizeof(buf1)); - if(atoi(buf1) == 65535 && avctx->pix_fmt == PIX_FMT_GRAY8) + s->maxval = atoi(buf1); + if(s->maxval >= 256 && avctx->pix_fmt == PIX_FMT_GRAY8) { avctx->pix_fmt = PIX_FMT_GRAY16BE; + if (s->maxval != 65535) + avctx->pix_fmt = PIX_FMT_GRAY16; + } } /* more check if YUV420 */ if (avctx->pix_fmt == PIX_FMT_YUV420P) { @@ -157,450 +145,3 @@ static int pnm_decode_header(AVCodecContext *avctx, PNMContext * const s){ } return 0; } - -static int pnm_decode_frame(AVCodecContext *avctx, - void *data, int *data_size, - uint8_t *buf, int buf_size) -{ - PNMContext * const s = avctx->priv_data; - AVFrame *picture = data; - AVFrame * const p= (AVFrame*)&s->picture; - int i, n, linesize, h; - unsigned char *ptr; - - s->bytestream_start= - s->bytestream= buf; - s->bytestream_end= buf + buf_size; - - if(pnm_decode_header(avctx, s) < 0) - return -1; - - if(p->data[0]) - avctx->release_buffer(avctx, p); - - p->reference= 0; - if(avctx->get_buffer(avctx, p) < 0){ - av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; - } - p->pict_type= FF_I_TYPE; - p->key_frame= 1; - - switch(avctx->pix_fmt) { - default: - return -1; - case PIX_FMT_RGB24: - n = avctx->width * 3; - goto do_read; - case PIX_FMT_GRAY8: - n = avctx->width; - goto do_read; - case PIX_FMT_GRAY16BE: - n = avctx->width * 2; - goto do_read; - case PIX_FMT_MONOWHITE: - case PIX_FMT_MONOBLACK: - n = (avctx->width + 7) >> 3; - do_read: - ptr = p->data[0]; - linesize = p->linesize[0]; - if(s->bytestream + n*avctx->height > s->bytestream_end) - return -1; - for(i = 0; i < avctx->height; i++) { - memcpy(ptr, s->bytestream, n); - s->bytestream += n; - ptr += linesize; - } - break; - case PIX_FMT_YUV420P: - { - unsigned char *ptr1, *ptr2; - - n = avctx->width; - ptr = p->data[0]; - linesize = p->linesize[0]; - if(s->bytestream + n*avctx->height*3/2 > s->bytestream_end) - return -1; - for(i = 0; i < avctx->height; i++) { - memcpy(ptr, s->bytestream, n); - s->bytestream += n; - ptr += linesize; - } - ptr1 = p->data[1]; - ptr2 = p->data[2]; - n >>= 1; - h = avctx->height >> 1; - for(i = 0; i < h; i++) { - memcpy(ptr1, s->bytestream, n); - s->bytestream += n; - memcpy(ptr2, s->bytestream, n); - s->bytestream += n; - ptr1 += p->linesize[1]; - ptr2 += p->linesize[2]; - } - } - break; - case PIX_FMT_RGB32: - ptr = p->data[0]; - linesize = p->linesize[0]; - if(s->bytestream + avctx->width*avctx->height*4 > s->bytestream_end) - return -1; - for(i = 0; i < avctx->height; i++) { - int j, r, g, b, a; - - for(j = 0;j < avctx->width; j++) { - r = *s->bytestream++; - g = *s->bytestream++; - b = *s->bytestream++; - a = *s->bytestream++; - ((uint32_t *)ptr)[j] = (a << 24) | (r << 16) | (g << 8) | b; - } - ptr += linesize; - } - break; - } - *picture= *(AVFrame*)&s->picture; - *data_size = sizeof(AVPicture); - - return s->bytestream - s->bytestream_start; -} - -static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int buf_size, void *data){ - PNMContext *s = avctx->priv_data; - AVFrame *pict = data; - AVFrame * const p= (AVFrame*)&s->picture; - int i, h, h1, c, n, linesize; - uint8_t *ptr, *ptr1, *ptr2; - - if(buf_size < avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height) + 200){ - av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n"); - return -1; - } - - *p = *pict; - p->pict_type= FF_I_TYPE; - p->key_frame= 1; - - s->bytestream_start= - s->bytestream= outbuf; - s->bytestream_end= outbuf+buf_size; - - h = avctx->height; - h1 = h; - switch(avctx->pix_fmt) { - case PIX_FMT_MONOWHITE: - c = '4'; - n = (avctx->width + 7) >> 3; - break; - case PIX_FMT_GRAY8: - c = '5'; - n = avctx->width; - break; - case PIX_FMT_GRAY16BE: - c = '5'; - n = avctx->width * 2; - break; - case PIX_FMT_RGB24: - c = '6'; - n = avctx->width * 3; - break; - case PIX_FMT_YUV420P: - c = '5'; - n = avctx->width; - h1 = (h * 3) / 2; - break; - default: - return -1; - } - snprintf(s->bytestream, s->bytestream_end - s->bytestream, - "P%c\n%d %d\n", - c, avctx->width, h1); - s->bytestream += strlen(s->bytestream); - if (avctx->pix_fmt != PIX_FMT_MONOWHITE) { - snprintf(s->bytestream, s->bytestream_end - s->bytestream, - "%d\n", (avctx->pix_fmt != PIX_FMT_GRAY16BE) ? 255 : 65535); - s->bytestream += strlen(s->bytestream); - } - - ptr = p->data[0]; - linesize = p->linesize[0]; - for(i=0;ibytestream, ptr, n); - s->bytestream += n; - ptr += linesize; - } - - if (avctx->pix_fmt == PIX_FMT_YUV420P) { - h >>= 1; - n >>= 1; - ptr1 = p->data[1]; - ptr2 = p->data[2]; - for(i=0;ibytestream, ptr1, n); - s->bytestream += n; - memcpy(s->bytestream, ptr2, n); - s->bytestream += n; - ptr1 += p->linesize[1]; - ptr2 += p->linesize[2]; - } - } - return s->bytestream - s->bytestream_start; -} - -static int pam_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int buf_size, void *data){ - PNMContext *s = avctx->priv_data; - AVFrame *pict = data; - AVFrame * const p= (AVFrame*)&s->picture; - int i, h, w, n, linesize, depth, maxval; - const char *tuple_type; - uint8_t *ptr; - - if(buf_size < avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height) + 200){ - av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n"); - return -1; - } - - *p = *pict; - p->pict_type= FF_I_TYPE; - p->key_frame= 1; - - s->bytestream_start= - s->bytestream= outbuf; - s->bytestream_end= outbuf+buf_size; - - h = avctx->height; - w = avctx->width; - switch(avctx->pix_fmt) { - case PIX_FMT_MONOWHITE: - n = (w + 7) >> 3; - depth = 1; - maxval = 1; - tuple_type = "BLACKANDWHITE"; - break; - case PIX_FMT_GRAY8: - n = w; - depth = 1; - maxval = 255; - tuple_type = "GRAYSCALE"; - break; - case PIX_FMT_RGB24: - n = w * 3; - depth = 3; - maxval = 255; - tuple_type = "RGB"; - break; - case PIX_FMT_RGB32: - n = w * 4; - depth = 4; - maxval = 255; - tuple_type = "RGB_ALPHA"; - break; - default: - return -1; - } - snprintf(s->bytestream, s->bytestream_end - s->bytestream, - "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLETYPE %s\nENDHDR\n", - w, h, depth, maxval, tuple_type); - s->bytestream += strlen(s->bytestream); - - ptr = p->data[0]; - linesize = p->linesize[0]; - - if (avctx->pix_fmt == PIX_FMT_RGB32) { - int j; - unsigned int v; - - for(i=0;ibytestream++ = v >> 16; - *s->bytestream++ = v >> 8; - *s->bytestream++ = v; - *s->bytestream++ = v >> 24; - } - ptr += linesize; - } - } else { - for(i=0;ibytestream, ptr, n); - s->bytestream += n; - ptr += linesize; - } - } - return s->bytestream - s->bytestream_start; -} - -#if 0 -static int pnm_probe(AVProbeData *pd) -{ - const char *p = pd->buf; - if (pd->buf_size >= 8 && - p[0] == 'P' && - p[1] >= '4' && p[1] <= '6' && - pnm_space(p[2]) ) - return AVPROBE_SCORE_MAX - 1; /* to permit pgmyuv probe */ - else - return 0; -} - -static int pgmyuv_probe(AVProbeData *pd) -{ - if (match_ext(pd->filename, "pgmyuv")) - return AVPROBE_SCORE_MAX; - else - return 0; -} - -static int pam_probe(AVProbeData *pd) -{ - const char *p = pd->buf; - if (pd->buf_size >= 8 && - p[0] == 'P' && - p[1] == '7' && - p[2] == '\n') - return AVPROBE_SCORE_MAX; - else - return 0; -} -#endif - -#ifdef CONFIG_PNM_PARSER -static int pnm_parse(AVCodecParserContext *s, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - ParseContext *pc = s->priv_data; - PNMContext pnmctx; - int next; - - for(; pc->overread>0; pc->overread--){ - pc->buffer[pc->index++]= pc->buffer[pc->overread_index++]; - } -retry: - if(pc->index){ - pnmctx.bytestream_start= - pnmctx.bytestream= pc->buffer; - pnmctx.bytestream_end= pc->buffer + pc->index; - }else{ - pnmctx.bytestream_start= - pnmctx.bytestream= (uint8_t *) buf; /* casts avoid warnings */ - pnmctx.bytestream_end= (uint8_t *) buf + buf_size; - } - if(pnm_decode_header(avctx, &pnmctx) < 0){ - if(pnmctx.bytestream < pnmctx.bytestream_end){ - if(pc->index){ - pc->index=0; - }else{ - buf++; - buf_size--; - } - goto retry; - } -#if 0 - if(pc->index && pc->index*2 + FF_INPUT_BUFFER_PADDING_SIZE < pc->buffer_size && buf_size > pc->index){ - memcpy(pc->buffer + pc->index, buf, pc->index); - pc->index += pc->index; - buf += pc->index; - buf_size -= pc->index; - goto retry; - } -#endif - next= END_NOT_FOUND; - }else{ - next= pnmctx.bytestream - pnmctx.bytestream_start - + avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); - if(pnmctx.bytestream_start!=buf) - next-= pc->index; - if(next > buf_size) - next= END_NOT_FOUND; - } - - if(ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size)<0){ - *poutbuf = NULL; - *poutbuf_size = 0; - return buf_size; - } - *poutbuf = (uint8_t *)buf; - *poutbuf_size = buf_size; - return next; -} - -AVCodecParser pnm_parser = { - { CODEC_ID_PGM, CODEC_ID_PGMYUV, CODEC_ID_PPM, CODEC_ID_PBM, CODEC_ID_PAM}, - sizeof(ParseContext), - NULL, - pnm_parse, - ff_parse_close, -}; -#endif /* CONFIG_PNM_PARSER */ - -#ifdef CONFIG_PGM_ENCODER -AVCodec pgm_encoder = { - "pgm", - CODEC_TYPE_VIDEO, - CODEC_ID_PGM, - sizeof(PNMContext), - common_init, - pnm_encode_frame, - NULL, //encode_end, - pnm_decode_frame, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, -1}, -}; -#endif // CONFIG_PGM_ENCODER - -#ifdef CONFIG_PGMYUV_ENCODER -AVCodec pgmyuv_encoder = { - "pgmyuv", - CODEC_TYPE_VIDEO, - CODEC_ID_PGMYUV, - sizeof(PNMContext), - common_init, - pnm_encode_frame, - NULL, //encode_end, - pnm_decode_frame, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, -}; -#endif // CONFIG_PGMYUV_ENCODER - -#ifdef CONFIG_PPM_ENCODER -AVCodec ppm_encoder = { - "ppm", - CODEC_TYPE_VIDEO, - CODEC_ID_PPM, - sizeof(PNMContext), - common_init, - pnm_encode_frame, - NULL, //encode_end, - pnm_decode_frame, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, -1}, -}; -#endif // CONFIG_PPM_ENCODER - -#ifdef CONFIG_PBM_ENCODER -AVCodec pbm_encoder = { - "pbm", - CODEC_TYPE_VIDEO, - CODEC_ID_PBM, - sizeof(PNMContext), - common_init, - pnm_encode_frame, - NULL, //encode_end, - pnm_decode_frame, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_MONOWHITE, -1}, -}; -#endif // CONFIG_PBM_ENCODER - -#ifdef CONFIG_PAM_ENCODER -AVCodec pam_encoder = { - "pam", - CODEC_TYPE_VIDEO, - CODEC_ID_PAM, - sizeof(PNMContext), - common_init, - pam_encode_frame, - NULL, //encode_end, - pnm_decode_frame, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_GRAY8, PIX_FMT_MONOWHITE, -1}, -}; -#endif // CONFIG_PAM_ENCODER diff --git a/contrib/ffmpeg/libavcodec/pnm.h b/contrib/ffmpeg/libavcodec/pnm.h new file mode 100644 index 000000000..c77bcca09 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/pnm.h @@ -0,0 +1,37 @@ +/* + * PNM image format + * Copyright (c) 2002, 2003 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_PNM_H +#define FFMPEG_PNM_H + +#include "avcodec.h" + +typedef struct PNMContext { + uint8_t *bytestream; + uint8_t *bytestream_start; + uint8_t *bytestream_end; + AVFrame picture; + int maxval; ///< maximum value of a pixel +} PNMContext; + +int ff_pnm_decode_header(AVCodecContext *avctx, PNMContext * const s); + +#endif /* FFMPEG_PNM_H */ diff --git a/contrib/ffmpeg/libavcodec/pnm_parser.c b/contrib/ffmpeg/libavcodec/pnm_parser.c new file mode 100644 index 000000000..f5212f024 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/pnm_parser.c @@ -0,0 +1,93 @@ +/* + * PNM image parser + * Copyright (c) 2002, 2003 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "parser.h" //for ParseContext +#include "pnm.h" + + +static int pnm_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + ParseContext *pc = s->priv_data; + PNMContext pnmctx; + int next; + + for(; pc->overread>0; pc->overread--){ + pc->buffer[pc->index++]= pc->buffer[pc->overread_index++]; + } +retry: + if(pc->index){ + pnmctx.bytestream_start= + pnmctx.bytestream= pc->buffer; + pnmctx.bytestream_end= pc->buffer + pc->index; + }else{ + pnmctx.bytestream_start= + pnmctx.bytestream= (uint8_t *) buf; /* casts avoid warnings */ + pnmctx.bytestream_end= (uint8_t *) buf + buf_size; + } + if(ff_pnm_decode_header(avctx, &pnmctx) < 0){ + if(pnmctx.bytestream < pnmctx.bytestream_end){ + if(pc->index){ + pc->index=0; + }else{ + buf++; + buf_size--; + } + goto retry; + } +#if 0 + if(pc->index && pc->index*2 + FF_INPUT_BUFFER_PADDING_SIZE < pc->buffer_size && buf_size > pc->index){ + memcpy(pc->buffer + pc->index, buf, pc->index); + pc->index += pc->index; + buf += pc->index; + buf_size -= pc->index; + goto retry; + } +#endif + next= END_NOT_FOUND; + }else{ + next= pnmctx.bytestream - pnmctx.bytestream_start + + avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); + if(pnmctx.bytestream_start!=buf) + next-= pc->index; + if(next > buf_size) + next= END_NOT_FOUND; + } + + if(ff_combine_frame(pc, next, &buf, &buf_size)<0){ + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + *poutbuf = buf; + *poutbuf_size = buf_size; + return next; +} + +AVCodecParser pnm_parser = { + { CODEC_ID_PGM, CODEC_ID_PGMYUV, CODEC_ID_PPM, CODEC_ID_PBM, CODEC_ID_PAM}, + sizeof(ParseContext), + NULL, + pnm_parse, + ff_parse_close, +}; diff --git a/contrib/ffmpeg/libavcodec/pnmenc.c b/contrib/ffmpeg/libavcodec/pnmenc.c new file mode 100644 index 000000000..c5061f2e7 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/pnmenc.c @@ -0,0 +1,425 @@ +/* + * PNM image format + * Copyright (c) 2002, 2003 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avcodec.h" +#include "bytestream.h" +#include "pnm.h" + + +static int common_init(AVCodecContext *avctx){ + PNMContext *s = avctx->priv_data; + + avcodec_get_frame_defaults((AVFrame*)&s->picture); + avctx->coded_frame= (AVFrame*)&s->picture; + + return 0; +} + +static int pnm_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size) +{ + PNMContext * const s = avctx->priv_data; + AVFrame *picture = data; + AVFrame * const p= (AVFrame*)&s->picture; + int i, n, linesize, h, upgrade = 0; + unsigned char *ptr; + + s->bytestream_start= + s->bytestream= buf; + s->bytestream_end= buf + buf_size; + + if(ff_pnm_decode_header(avctx, s) < 0) + return -1; + + if(p->data[0]) + avctx->release_buffer(avctx, p); + + p->reference= 0; + if(avctx->get_buffer(avctx, p) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + p->pict_type= FF_I_TYPE; + p->key_frame= 1; + + switch(avctx->pix_fmt) { + default: + return -1; + case PIX_FMT_RGB24: + n = avctx->width * 3; + goto do_read; + case PIX_FMT_GRAY8: + n = avctx->width; + if (s->maxval < 255) + upgrade = 1; + goto do_read; + case PIX_FMT_GRAY16BE: + case PIX_FMT_GRAY16LE: + n = avctx->width * 2; + if (s->maxval < 65535) + upgrade = 2; + goto do_read; + case PIX_FMT_MONOWHITE: + case PIX_FMT_MONOBLACK: + n = (avctx->width + 7) >> 3; + do_read: + ptr = p->data[0]; + linesize = p->linesize[0]; + if(s->bytestream + n*avctx->height > s->bytestream_end) + return -1; + for(i = 0; i < avctx->height; i++) { + if (!upgrade) + memcpy(ptr, s->bytestream, n); + else if (upgrade == 1) { + unsigned int j, f = (255*128 + s->maxval/2) / s->maxval; + for (j=0; jbytestream[j] * f + 64) >> 7; + } else if (upgrade == 2) { + unsigned int j, v, f = (65535*32768 + s->maxval/2) / s->maxval; + for (j=0; jbytestream)[j]); + ((uint16_t *)ptr)[j] = (v * f + 16384) >> 15; + } + } + s->bytestream += n; + ptr += linesize; + } + break; + case PIX_FMT_YUV420P: + { + unsigned char *ptr1, *ptr2; + + n = avctx->width; + ptr = p->data[0]; + linesize = p->linesize[0]; + if(s->bytestream + n*avctx->height*3/2 > s->bytestream_end) + return -1; + for(i = 0; i < avctx->height; i++) { + memcpy(ptr, s->bytestream, n); + s->bytestream += n; + ptr += linesize; + } + ptr1 = p->data[1]; + ptr2 = p->data[2]; + n >>= 1; + h = avctx->height >> 1; + for(i = 0; i < h; i++) { + memcpy(ptr1, s->bytestream, n); + s->bytestream += n; + memcpy(ptr2, s->bytestream, n); + s->bytestream += n; + ptr1 += p->linesize[1]; + ptr2 += p->linesize[2]; + } + } + break; + case PIX_FMT_RGB32: + ptr = p->data[0]; + linesize = p->linesize[0]; + if(s->bytestream + avctx->width*avctx->height*4 > s->bytestream_end) + return -1; + for(i = 0; i < avctx->height; i++) { + int j, r, g, b, a; + + for(j = 0;j < avctx->width; j++) { + r = *s->bytestream++; + g = *s->bytestream++; + b = *s->bytestream++; + a = *s->bytestream++; + ((uint32_t *)ptr)[j] = (a << 24) | (r << 16) | (g << 8) | b; + } + ptr += linesize; + } + break; + } + *picture= *(AVFrame*)&s->picture; + *data_size = sizeof(AVPicture); + + return s->bytestream - s->bytestream_start; +} + +static int pnm_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int buf_size, void *data){ + PNMContext *s = avctx->priv_data; + AVFrame *pict = data; + AVFrame * const p= (AVFrame*)&s->picture; + int i, h, h1, c, n, linesize; + uint8_t *ptr, *ptr1, *ptr2; + + if(buf_size < avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height) + 200){ + av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n"); + return -1; + } + + *p = *pict; + p->pict_type= FF_I_TYPE; + p->key_frame= 1; + + s->bytestream_start= + s->bytestream= outbuf; + s->bytestream_end= outbuf+buf_size; + + h = avctx->height; + h1 = h; + switch(avctx->pix_fmt) { + case PIX_FMT_MONOWHITE: + c = '4'; + n = (avctx->width + 7) >> 3; + break; + case PIX_FMT_GRAY8: + c = '5'; + n = avctx->width; + break; + case PIX_FMT_GRAY16BE: + c = '5'; + n = avctx->width * 2; + break; + case PIX_FMT_RGB24: + c = '6'; + n = avctx->width * 3; + break; + case PIX_FMT_YUV420P: + c = '5'; + n = avctx->width; + h1 = (h * 3) / 2; + break; + default: + return -1; + } + snprintf(s->bytestream, s->bytestream_end - s->bytestream, + "P%c\n%d %d\n", + c, avctx->width, h1); + s->bytestream += strlen(s->bytestream); + if (avctx->pix_fmt != PIX_FMT_MONOWHITE) { + snprintf(s->bytestream, s->bytestream_end - s->bytestream, + "%d\n", (avctx->pix_fmt != PIX_FMT_GRAY16BE) ? 255 : 65535); + s->bytestream += strlen(s->bytestream); + } + + ptr = p->data[0]; + linesize = p->linesize[0]; + for(i=0;ibytestream, ptr, n); + s->bytestream += n; + ptr += linesize; + } + + if (avctx->pix_fmt == PIX_FMT_YUV420P) { + h >>= 1; + n >>= 1; + ptr1 = p->data[1]; + ptr2 = p->data[2]; + for(i=0;ibytestream, ptr1, n); + s->bytestream += n; + memcpy(s->bytestream, ptr2, n); + s->bytestream += n; + ptr1 += p->linesize[1]; + ptr2 += p->linesize[2]; + } + } + return s->bytestream - s->bytestream_start; +} + +static int pam_encode_frame(AVCodecContext *avctx, unsigned char *outbuf, int buf_size, void *data){ + PNMContext *s = avctx->priv_data; + AVFrame *pict = data; + AVFrame * const p= (AVFrame*)&s->picture; + int i, h, w, n, linesize, depth, maxval; + const char *tuple_type; + uint8_t *ptr; + + if(buf_size < avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height) + 200){ + av_log(avctx, AV_LOG_ERROR, "encoded frame too large\n"); + return -1; + } + + *p = *pict; + p->pict_type= FF_I_TYPE; + p->key_frame= 1; + + s->bytestream_start= + s->bytestream= outbuf; + s->bytestream_end= outbuf+buf_size; + + h = avctx->height; + w = avctx->width; + switch(avctx->pix_fmt) { + case PIX_FMT_MONOWHITE: + n = (w + 7) >> 3; + depth = 1; + maxval = 1; + tuple_type = "BLACKANDWHITE"; + break; + case PIX_FMT_GRAY8: + n = w; + depth = 1; + maxval = 255; + tuple_type = "GRAYSCALE"; + break; + case PIX_FMT_RGB24: + n = w * 3; + depth = 3; + maxval = 255; + tuple_type = "RGB"; + break; + case PIX_FMT_RGB32: + n = w * 4; + depth = 4; + maxval = 255; + tuple_type = "RGB_ALPHA"; + break; + default: + return -1; + } + snprintf(s->bytestream, s->bytestream_end - s->bytestream, + "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLETYPE %s\nENDHDR\n", + w, h, depth, maxval, tuple_type); + s->bytestream += strlen(s->bytestream); + + ptr = p->data[0]; + linesize = p->linesize[0]; + + if (avctx->pix_fmt == PIX_FMT_RGB32) { + int j; + unsigned int v; + + for(i=0;ibytestream, v); + *s->bytestream++ = v >> 24; + } + ptr += linesize; + } + } else { + for(i=0;ibytestream, ptr, n); + s->bytestream += n; + ptr += linesize; + } + } + return s->bytestream - s->bytestream_start; +} + +#if 0 +static int pnm_probe(AVProbeData *pd) +{ + const char *p = pd->buf; + if (pd->buf_size >= 8 && + p[0] == 'P' && + p[1] >= '4' && p[1] <= '6' && + pnm_space(p[2]) ) + return AVPROBE_SCORE_MAX - 1; /* to permit pgmyuv probe */ + else + return 0; +} + +static int pgmyuv_probe(AVProbeData *pd) +{ + if (match_ext(pd->filename, "pgmyuv")) + return AVPROBE_SCORE_MAX; + else + return 0; +} + +static int pam_probe(AVProbeData *pd) +{ + const char *p = pd->buf; + if (pd->buf_size >= 8 && + p[0] == 'P' && + p[1] == '7' && + p[2] == '\n') + return AVPROBE_SCORE_MAX; + else + return 0; +} +#endif + + +#ifdef CONFIG_PGM_ENCODER +AVCodec pgm_encoder = { + "pgm", + CODEC_TYPE_VIDEO, + CODEC_ID_PGM, + sizeof(PNMContext), + common_init, + pnm_encode_frame, + NULL, //encode_end, + pnm_decode_frame, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, -1}, +}; +#endif // CONFIG_PGM_ENCODER + +#ifdef CONFIG_PGMYUV_ENCODER +AVCodec pgmyuv_encoder = { + "pgmyuv", + CODEC_TYPE_VIDEO, + CODEC_ID_PGMYUV, + sizeof(PNMContext), + common_init, + pnm_encode_frame, + NULL, //encode_end, + pnm_decode_frame, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, +}; +#endif // CONFIG_PGMYUV_ENCODER + +#ifdef CONFIG_PPM_ENCODER +AVCodec ppm_encoder = { + "ppm", + CODEC_TYPE_VIDEO, + CODEC_ID_PPM, + sizeof(PNMContext), + common_init, + pnm_encode_frame, + NULL, //encode_end, + pnm_decode_frame, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, -1}, +}; +#endif // CONFIG_PPM_ENCODER + +#ifdef CONFIG_PBM_ENCODER +AVCodec pbm_encoder = { + "pbm", + CODEC_TYPE_VIDEO, + CODEC_ID_PBM, + sizeof(PNMContext), + common_init, + pnm_encode_frame, + NULL, //encode_end, + pnm_decode_frame, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_MONOWHITE, -1}, +}; +#endif // CONFIG_PBM_ENCODER + +#ifdef CONFIG_PAM_ENCODER +AVCodec pam_encoder = { + "pam", + CODEC_TYPE_VIDEO, + CODEC_ID_PAM, + sizeof(PNMContext), + common_init, + pam_encode_frame, + NULL, //encode_end, + pnm_decode_frame, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_GRAY8, PIX_FMT_MONOWHITE, -1}, +}; +#endif // CONFIG_PAM_ENCODER diff --git a/contrib/ffmpeg/libavcodec/ppc/check_altivec.c b/contrib/ffmpeg/libavcodec/ppc/check_altivec.c new file mode 100644 index 000000000..cf55b9a1d --- /dev/null +++ b/contrib/ffmpeg/libavcodec/ppc/check_altivec.c @@ -0,0 +1,75 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +/** + * @file check_altivec.c + * Checks for AltiVec presence. + */ + +#ifdef __APPLE__ +#include +#elif __AMIGAOS4__ +#include +#include +#include +#endif /* __APPLE__ */ + +/** + * This function MAY rely on signal() or fork() in order to make sure altivec + * is present + */ + +int has_altivec(void) +{ +#ifdef __AMIGAOS4__ + ULONG result = 0; + extern struct ExecIFace *IExec; + + IExec->GetCPUInfoTags(GCIT_VectorUnit, &result, TAG_DONE); + if (result == VECTORTYPE_ALTIVEC) return 1; + return 0; +#elif __APPLE__ + int sels[2] = {CTL_HW, HW_VECTORUNIT}; + int has_vu = 0; + size_t len = sizeof(has_vu); + int err; + + err = sysctl(sels, 2, &has_vu, &len, NULL, 0); + + if (err == 0) return (has_vu != 0); + return 0; +#elif defined(RUNTIME_CPUDETECT) + int proc_ver; + // support of mfspr PVR emulation added in Linux 2.6.17 + asm volatile("mfspr %0, 287" : "=r" (proc_ver)); + proc_ver >>= 16; + if (proc_ver & 0x8000 || + proc_ver == 0x000c || + proc_ver == 0x0039 || proc_ver == 0x003c || + proc_ver == 0x0044 || proc_ver == 0x0045 || + proc_ver == 0x0070) + return 1; + return 0; +#else + // since we were compiled for altivec, just assume we have it + // until someone comes up with a proper way (not involving signal hacks). + return 1; +#endif /* __AMIGAOS4__ */ +} + diff --git a/contrib/ffmpeg/libavcodec/ppc/dsputil_altivec.c b/contrib/ffmpeg/libavcodec/ppc/dsputil_altivec.c index bbc53d761..3d79c3ab5 100644 --- a/contrib/ffmpeg/libavcodec/ppc/dsputil_altivec.c +++ b/contrib/ffmpeg/libavcodec/ppc/dsputil_altivec.c @@ -20,44 +20,18 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../dsputil.h" +#include "dsputil.h" #include "gcc_fixes.h" -#include "dsputil_altivec.h" - -#ifdef CONFIG_DARWIN -#include -#else /* CONFIG_DARWIN */ -#ifdef __AMIGAOS4__ -#include -#include -#include -#else /* __AMIGAOS4__ */ -#include -#include - -static sigjmp_buf jmpbuf; -static volatile sig_atomic_t canjump = 0; - -static void sigill_handler (int sig) -{ - if (!canjump) { - signal (sig, SIG_DFL); - raise (sig); - } - - canjump = 0; - siglongjmp (jmpbuf, 1); -} -#endif /* CONFIG_DARWIN */ -#endif /* __AMIGAOS4__ */ +#include "dsputil_ppc.h" +#include "util_altivec.h" int sad16_x2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int i; - int s __attribute__((aligned(16))); - const_vector unsigned char zero = (const_vector unsigned char)vec_splat_u8(0); + DECLARE_ALIGNED_16(int, s); + const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0); vector unsigned char *tv; vector unsigned char pix1v, pix2v, pix2iv, avgv, t5; vector unsigned int sad; @@ -103,8 +77,8 @@ int sad16_x2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h int sad16_y2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int i; - int s __attribute__((aligned(16))); - const_vector unsigned char zero = (const_vector unsigned char)vec_splat_u8(0); + DECLARE_ALIGNED_16(int, s); + const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0); vector unsigned char *tv; vector unsigned char pix1v, pix2v, pix3v, avgv, t5; vector unsigned int sad; @@ -163,10 +137,10 @@ int sad16_y2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h int sad16_xy2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int i; - int s __attribute__((aligned(16))); + DECLARE_ALIGNED_16(int, s); uint8_t *pix3 = pix2 + line_size; - const_vector unsigned char zero = (const_vector unsigned char)vec_splat_u8(0); - const_vector unsigned short two = (const_vector unsigned short)vec_splat_u16(2); + const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0); + const vector unsigned short two = (const vector unsigned short)vec_splat_u16(2); vector unsigned char *tv, avgv, t5; vector unsigned char pix1v, pix2v, pix3v, pix2iv, pix3iv; vector unsigned short pix2lv, pix2hv, pix2ilv, pix2ihv; @@ -218,7 +192,7 @@ int sad16_xy2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int pix3iv = vec_perm(tv[0], tv[1], vec_lvsl(0, &pix3[1])); /* - Note that Altivec does have vec_avg, but this works on vector pairs + Note that AltiVec does have vec_avg, but this works on vector pairs and rounds up. We could do avg(avg(a,b),avg(c,d)), but the rounding would mean that, for example, avg(3,0,0,1) = 2, when it should be 1. Instead, we have to split the pixel vectors into vectors of shorts, @@ -264,8 +238,8 @@ int sad16_xy2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int int sad16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int i; - int s __attribute__((aligned(16))); - const_vector unsigned int zero = (const_vector unsigned int)vec_splat_u32(0); + DECLARE_ALIGNED_16(int, s); + const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0); vector unsigned char perm1, perm2, *pix1v, *pix2v; vector unsigned char t1, t2, t3,t4, t5; vector unsigned int sad; @@ -306,8 +280,8 @@ int sad16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) int sad8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int i; - int s __attribute__((aligned(16))); - const_vector unsigned int zero = (const_vector unsigned int)vec_splat_u32(0); + DECLARE_ALIGNED_16(int, s); + const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0); vector unsigned char perm1, perm2, permclear, *pix1v, *pix2v; vector unsigned char t1, t2, t3,t4, t5; vector unsigned int sad; @@ -351,8 +325,8 @@ int sad8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) int pix_norm1_altivec(uint8_t *pix, int line_size) { int i; - int s __attribute__((aligned(16))); - const_vector unsigned int zero = (const_vector unsigned int)vec_splat_u32(0); + DECLARE_ALIGNED_16(int, s); + const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0); vector unsigned char *tv; vector unsigned char pixv; vector unsigned int sv; @@ -387,8 +361,8 @@ int pix_norm1_altivec(uint8_t *pix, int line_size) int sse8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int i; - int s __attribute__((aligned(16))); - const_vector unsigned int zero = (const_vector unsigned int)vec_splat_u32(0); + DECLARE_ALIGNED_16(int, s); + const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0); vector unsigned char perm1, perm2, permclear, *pix1v, *pix2v; vector unsigned char t1, t2, t3,t4, t5; vector unsigned int sum; @@ -443,8 +417,8 @@ int sse8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) int sse16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) { int i; - int s __attribute__((aligned(16))); - const_vector unsigned int zero = (const_vector unsigned int)vec_splat_u32(0); + DECLARE_ALIGNED_16(int, s); + const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0); vector unsigned char perm1, perm2, *pix1v, *pix2v; vector unsigned char t1, t2, t3,t4, t5; vector unsigned int sum; @@ -488,14 +462,14 @@ int sse16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) int pix_sum_altivec(uint8_t * pix, int line_size) { - const_vector unsigned int zero = (const_vector unsigned int)vec_splat_u32(0); + const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0); vector unsigned char perm, *pixv; vector unsigned char t1; vector unsigned int sad; vector signed int sumdiffs; int i; - int s __attribute__((aligned(16))); + DECLARE_ALIGNED_16(int, s); sad = (vector unsigned int)vec_splat_u32(0); @@ -523,7 +497,7 @@ void get_pixels_altivec(DCTELEM *restrict block, const uint8_t *pixels, int line { int i; vector unsigned char perm, bytes, *pixv; - const_vector unsigned char zero = (const_vector unsigned char)vec_splat_u8(0); + const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0); vector signed short shorts; for(i=0;i<8;i++) @@ -550,7 +524,7 @@ void diff_pixels_altivec(DCTELEM *restrict block, const uint8_t *s1, { int i; vector unsigned char perm, bytes, *pixv; - const_vector unsigned char zero = (const_vector unsigned char)vec_splat_u8(0); + const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0); vector signed short shorts1, shorts2; for(i=0;i<4;i++) @@ -769,8 +743,8 @@ POWERPC_PERF_DECLARE(altivec_put_pixels8_xy2_num, 1); blockv, temp1, temp2; register vector unsigned short pixelssum1, pixelssum2, temp3; - register const_vector unsigned char vczero = (const_vector unsigned char)vec_splat_u8(0); - register const_vector unsigned short vctwo = (const_vector unsigned short)vec_splat_u16(2); + register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0); + register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2); temp1 = vec_ld(0, pixels); temp2 = vec_ld(16, pixels); @@ -845,9 +819,9 @@ POWERPC_PERF_DECLARE(altivec_put_no_rnd_pixels8_xy2_num, 1); blockv, temp1, temp2; register vector unsigned short pixelssum1, pixelssum2, temp3; - register const_vector unsigned char vczero = (const_vector unsigned char)vec_splat_u8(0); - register const_vector unsigned short vcone = (const_vector unsigned short)vec_splat_u16(1); - register const_vector unsigned short vctwo = (const_vector unsigned short)vec_splat_u16(2); + register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0); + register const vector unsigned short vcone = (const vector unsigned short)vec_splat_u16(1); + register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2); temp1 = vec_ld(0, pixels); temp2 = vec_ld(16, pixels); @@ -922,8 +896,8 @@ POWERPC_PERF_DECLARE(altivec_put_pixels16_xy2_num, 1); register vector unsigned short pixelssum1, pixelssum2, temp3, pixelssum3, pixelssum4, temp4; - register const_vector unsigned char vczero = (const_vector unsigned char)vec_splat_u8(0); - register const_vector unsigned short vctwo = (const_vector unsigned short)vec_splat_u16(2); + register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0); + register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2); POWERPC_PERF_START_COUNT(altivec_put_pixels16_xy2_num, 1); @@ -1004,9 +978,9 @@ POWERPC_PERF_DECLARE(altivec_put_no_rnd_pixels16_xy2_num, 1); register vector unsigned short pixelssum1, pixelssum2, temp3, pixelssum3, pixelssum4, temp4; - register const_vector unsigned char vczero = (const_vector unsigned char)vec_splat_u8(0); - register const_vector unsigned short vcone = (const_vector unsigned short)vec_splat_u16(1); - register const_vector unsigned short vctwo = (const_vector unsigned short)vec_splat_u16(2); + register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0); + register const vector unsigned short vcone = (const vector unsigned short)vec_splat_u16(1); + register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2); POWERPC_PERF_START_COUNT(altivec_put_no_rnd_pixels16_xy2_num, 1); @@ -1078,25 +1052,25 @@ POWERPC_PERF_STOP_COUNT(altivec_put_no_rnd_pixels16_xy2_num, 1); int hadamard8_diff8x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){ POWERPC_PERF_DECLARE(altivec_hadamard8_diff8x8_num, 1); int sum; - register const_vector unsigned char vzero = - (const_vector unsigned char)vec_splat_u8(0); + register const vector unsigned char vzero = + (const vector unsigned char)vec_splat_u8(0); register vector signed short temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7; POWERPC_PERF_START_COUNT(altivec_hadamard8_diff8x8_num, 1); { - register const_vector signed short vprod1 =(const_vector signed short) + register const vector signed short vprod1 =(const vector signed short) AVV( 1,-1, 1,-1, 1,-1, 1,-1); - register const_vector signed short vprod2 =(const_vector signed short) + register const vector signed short vprod2 =(const vector signed short) AVV( 1, 1,-1,-1, 1, 1,-1,-1); - register const_vector signed short vprod3 =(const_vector signed short) + register const vector signed short vprod3 =(const vector signed short) AVV( 1, 1, 1, 1,-1,-1,-1,-1); - register const_vector unsigned char perm1 = (const_vector unsigned char) + register const vector unsigned char perm1 = (const vector unsigned char) AVV(0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, 0x0A, 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D); - register const_vector unsigned char perm2 = (const_vector unsigned char) + register const vector unsigned char perm2 = (const vector unsigned char) AVV(0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x0C, 0x0D, 0x0E, 0x0F, 0x08, 0x09, 0x0A, 0x0B); - register const_vector unsigned char perm3 = (const_vector unsigned char) + register const vector unsigned char perm3 = (const vector unsigned char) AVV(0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07); @@ -1120,7 +1094,7 @@ POWERPC_PERF_START_COUNT(altivec_hadamard8_diff8x8_num, 1); dstV = \ (vector signed short)vec_mergeh((vector signed char)vzero, \ (vector signed char)dstO); \ - /* substractions inside the first butterfly */ \ + /* subtractions inside the first butterfly */ \ but0 = vec_sub(srcV, dstV); \ op1 = vec_perm(but0, but0, perm1); \ but1 = vec_mladd(but0, vprod1, op1); \ @@ -1201,7 +1175,7 @@ POWERPC_PERF_STOP_COUNT(altivec_hadamard8_diff8x8_num, 1); schedule for the 7450, and its code isn't much faster than gcc-3.3 on the 7450 (but uses 25% less instructions...) - On the 970, the hand-made RA is still a win (arount 690 + On the 970, the hand-made RA is still a win (around 690 vs. around 780), but xlc goes to around 660 on the regular C code... */ @@ -1226,25 +1200,25 @@ static int hadamard8_diff16x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, temp5S REG_v(v13), temp6S REG_v(v14), temp7S REG_v(v15); - register const_vector unsigned char vzero REG_v(v31)= - (const_vector unsigned char)vec_splat_u8(0); + register const vector unsigned char vzero REG_v(v31)= + (const vector unsigned char)vec_splat_u8(0); { - register const_vector signed short vprod1 REG_v(v16)= - (const_vector signed short)AVV( 1,-1, 1,-1, 1,-1, 1,-1); - register const_vector signed short vprod2 REG_v(v17)= - (const_vector signed short)AVV( 1, 1,-1,-1, 1, 1,-1,-1); - register const_vector signed short vprod3 REG_v(v18)= - (const_vector signed short)AVV( 1, 1, 1, 1,-1,-1,-1,-1); - register const_vector unsigned char perm1 REG_v(v19)= - (const_vector unsigned char) + register const vector signed short vprod1 REG_v(v16)= + (const vector signed short)AVV( 1,-1, 1,-1, 1,-1, 1,-1); + register const vector signed short vprod2 REG_v(v17)= + (const vector signed short)AVV( 1, 1,-1,-1, 1, 1,-1,-1); + register const vector signed short vprod3 REG_v(v18)= + (const vector signed short)AVV( 1, 1, 1, 1,-1,-1,-1,-1); + register const vector unsigned char perm1 REG_v(v19)= + (const vector unsigned char) AVV(0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05, 0x0A, 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D); - register const_vector unsigned char perm2 REG_v(v20)= - (const_vector unsigned char) + register const vector unsigned char perm2 REG_v(v20)= + (const vector unsigned char) AVV(0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x0C, 0x0D, 0x0E, 0x0F, 0x08, 0x09, 0x0A, 0x0B); - register const_vector unsigned char perm3 REG_v(v21)= - (const_vector unsigned char) + register const vector unsigned char perm3 REG_v(v21)= + (const vector unsigned char) AVV(0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07); @@ -1293,7 +1267,7 @@ static int hadamard8_diff16x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, dstW = \ (vector signed short)vec_mergel((vector signed char)vzero, \ (vector signed char)dstO); \ - /* substractions inside the first butterfly */ \ + /* subtractions inside the first butterfly */ \ but0 = vec_sub(srcV, dstV); \ but0S = vec_sub(srcW, dstW); \ op1 = vec_perm(but0, but0, perm1); \ @@ -1419,50 +1393,6 @@ POWERPC_PERF_STOP_COUNT(altivec_hadamard8_diff16_num, 1); return score; } -int has_altivec(void) -{ -#ifdef __AMIGAOS4__ - ULONG result = 0; - extern struct ExecIFace *IExec; - - IExec->GetCPUInfoTags(GCIT_VectorUnit, &result, TAG_DONE); - if (result == VECTORTYPE_ALTIVEC) return 1; - return 0; -#else /* __AMIGAOS4__ */ - -#ifdef CONFIG_DARWIN - int sels[2] = {CTL_HW, HW_VECTORUNIT}; - int has_vu = 0; - size_t len = sizeof(has_vu); - int err; - - err = sysctl(sels, 2, &has_vu, &len, NULL, 0); - - if (err == 0) return (has_vu != 0); -#else /* CONFIG_DARWIN */ -/* no Darwin, do it the brute-force way */ -/* this is borrowed from the libmpeg2 library */ - { - signal (SIGILL, sigill_handler); - if (sigsetjmp (jmpbuf, 1)) { - signal (SIGILL, SIG_DFL); - } else { - canjump = 1; - - asm volatile ("mtspr 256, %0\n\t" - "vand %%v0, %%v0, %%v0" - : - : "r" (-1)); - - signal (SIGILL, SIG_DFL); - return 1; - } - } -#endif /* CONFIG_DARWIN */ - return 0; -#endif /* __AMIGAOS4__ */ -} - static void vorbis_inverse_coupling_altivec(float *mag, float *ang, int blocksize) { @@ -1495,9 +1425,9 @@ POWERPC_PERF_DECLARE(altivec_avg_pixels8_xy2_num, 1); register vector unsigned char blockv, temp1, temp2, blocktemp; register vector unsigned short pixelssum1, pixelssum2, temp3; - register const_vector unsigned char vczero = (const_vector unsigned char) + register const vector unsigned char vczero = (const vector unsigned char) vec_splat_u8(0); - register const_vector unsigned short vctwo = (const_vector unsigned short) + register const vector unsigned short vctwo = (const vector unsigned short) vec_splat_u16(2); temp1 = vec_ld(0, pixels); @@ -1583,7 +1513,6 @@ void dsputil_init_altivec(DSPContext* c, AVCodecContext *avctx) c->hadamard8_diff[0] = hadamard8_diff16_altivec; c->hadamard8_diff[1] = hadamard8_diff8x8_altivec; -#ifdef CONFIG_VORBIS_DECODER - c->vorbis_inverse_coupling = vorbis_inverse_coupling_altivec; -#endif + if (ENABLE_VORBIS_DECODER) + c->vorbis_inverse_coupling = vorbis_inverse_coupling_altivec; } diff --git a/contrib/ffmpeg/libavcodec/ppc/dsputil_altivec.h b/contrib/ffmpeg/libavcodec/ppc/dsputil_altivec.h index 560d778bb..43bd5abab 100644 --- a/contrib/ffmpeg/libavcodec/ppc/dsputil_altivec.h +++ b/contrib/ffmpeg/libavcodec/ppc/dsputil_altivec.h @@ -20,12 +20,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _DSPUTIL_ALTIVEC_ -#define _DSPUTIL_ALTIVEC_ +#ifndef FFMPEG_DSPUTIL_ALTIVEC_H +#define FFMPEG_DSPUTIL_ALTIVEC_H -#include "dsputil_ppc.h" - -#ifdef HAVE_ALTIVEC +#include extern int has_altivec(void); @@ -33,74 +31,4 @@ void put_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, void avg_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h); -// used to build registers permutation vectors (vcprm) -// the 's' are for words in the _s_econd vector -#define WORD_0 0x00,0x01,0x02,0x03 -#define WORD_1 0x04,0x05,0x06,0x07 -#define WORD_2 0x08,0x09,0x0a,0x0b -#define WORD_3 0x0c,0x0d,0x0e,0x0f -#define WORD_s0 0x10,0x11,0x12,0x13 -#define WORD_s1 0x14,0x15,0x16,0x17 -#define WORD_s2 0x18,0x19,0x1a,0x1b -#define WORD_s3 0x1c,0x1d,0x1e,0x1f - -#ifdef CONFIG_DARWIN -#define vcprm(a,b,c,d) (const vector unsigned char)(WORD_ ## a, WORD_ ## b, WORD_ ## c, WORD_ ## d) -#else -#define vcprm(a,b,c,d) (const vector unsigned char){WORD_ ## a, WORD_ ## b, WORD_ ## c, WORD_ ## d} -#endif - -// vcprmle is used to keep the same index as in the SSE version. -// it's the same as vcprm, with the index inversed -// ('le' is Little Endian) -#define vcprmle(a,b,c,d) vcprm(d,c,b,a) - -// used to build inverse/identity vectors (vcii) -// n is _n_egative, p is _p_ositive -#define FLOAT_n -1. -#define FLOAT_p 1. - - -#ifdef CONFIG_DARWIN -#define vcii(a,b,c,d) (const vector float)(FLOAT_ ## a, FLOAT_ ## b, FLOAT_ ## c, FLOAT_ ## d) -#else -#define vcii(a,b,c,d) (const vector float){FLOAT_ ## a, FLOAT_ ## b, FLOAT_ ## c, FLOAT_ ## d} -#endif - -// Transpose 8x8 matrix of 16-bit elements (in-place) -#define TRANSPOSE8(a,b,c,d,e,f,g,h) \ -do { \ - vector signed short A1, B1, C1, D1, E1, F1, G1, H1; \ - vector signed short A2, B2, C2, D2, E2, F2, G2, H2; \ - \ - A1 = vec_mergeh (a, e); \ - B1 = vec_mergel (a, e); \ - C1 = vec_mergeh (b, f); \ - D1 = vec_mergel (b, f); \ - E1 = vec_mergeh (c, g); \ - F1 = vec_mergel (c, g); \ - G1 = vec_mergeh (d, h); \ - H1 = vec_mergel (d, h); \ - \ - A2 = vec_mergeh (A1, E1); \ - B2 = vec_mergel (A1, E1); \ - C2 = vec_mergeh (B1, F1); \ - D2 = vec_mergel (B1, F1); \ - E2 = vec_mergeh (C1, G1); \ - F2 = vec_mergel (C1, G1); \ - G2 = vec_mergeh (D1, H1); \ - H2 = vec_mergel (D1, H1); \ - \ - a = vec_mergeh (A2, E2); \ - b = vec_mergel (A2, E2); \ - c = vec_mergeh (B2, F2); \ - d = vec_mergel (B2, F2); \ - e = vec_mergeh (C2, G2); \ - f = vec_mergel (C2, G2); \ - g = vec_mergeh (D2, H2); \ - h = vec_mergel (D2, H2); \ -} while (0) - -#endif /* HAVE_ALTIVEC */ - -#endif /* _DSPUTIL_ALTIVEC_ */ +#endif /* FFMPEG_DSPUTIL_ALTIVEC_H */ diff --git a/contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.c b/contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.c index 117a7adf1..13dea06a1 100644 --- a/contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.c +++ b/contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.c @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../dsputil.h" +#include "dsputil.h" #include "dsputil_ppc.h" @@ -39,6 +39,7 @@ void dsputil_init_altivec(DSPContext* c, AVCodecContext *avctx); void vc1dsp_init_altivec(DSPContext* c, AVCodecContext *avctx); void snow_init_altivec(DSPContext* c, AVCodecContext *avctx); void float_init_altivec(DSPContext* c, AVCodecContext *avctx); +void int_init_altivec(DSPContext* c, AVCodecContext *avctx); #endif @@ -154,11 +155,7 @@ POWERPC_PERF_START_COUNT(powerpc_clear_blocks_dcbz32, 1); i += 16; } for ( ; i < sizeof(DCTELEM)*6*64-31 ; i += 32) { -#ifndef __MWERKS__ asm volatile("dcbz %0,%1" : : "b" (blocks), "r" (i) : "memory"); -#else - __dcbz( blocks, i ); -#endif } if (misal) { ((unsigned long*)blocks)[188] = 0L; @@ -213,7 +210,7 @@ void clear_blocks_dcbz128_ppc(DCTELEM *blocks) knows about dcbzl ... */ long check_dcbzl_effect(void) { - register char *fakedata = (char*)av_malloc(1024); + register char *fakedata = av_malloc(1024); register char *fakedata_middle; register long zero = 0; register long i = 0; @@ -260,7 +257,7 @@ static void prefetch_ppc(void *mem, int stride, int h) void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx) { - // Common optimizations whether Altivec is available or not + // Common optimizations whether AltiVec is available or not c->prefetch = prefetch_ppc; switch (check_dcbzl_effect()) { case 32: @@ -284,6 +281,7 @@ void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx) if(ENABLE_VC1_DECODER || ENABLE_WMV3_DECODER) vc1dsp_init_altivec(c, avctx); float_init_altivec(c, avctx); + int_init_altivec(c, avctx); c->gmc1 = gmc1_altivec; #ifdef CONFIG_ENCODERS diff --git a/contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.h b/contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.h index 5b25732b2..d8f6b27f9 100644 --- a/contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.h +++ b/contrib/ffmpeg/libavcodec/ppc/dsputil_ppc.h @@ -18,14 +18,14 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _DSPUTIL_PPC_ -#define _DSPUTIL_PPC_ +#ifndef FFMPEG_DSPUTIL_PPC_H +#define FFMPEG_DSPUTIL_PPC_H #ifdef CONFIG_POWERPC_PERF void powerpc_display_perf_report(void); /* the 604* have 2, the G3* have 4, the G4s have 6, and the G5 are completely different (they MUST use - POWERPC_MODE_64BITS, and let's hope all future 64 bis PPC + HAVE_PPC64, and let's hope all future 64 bis PPC will use the same PMCs... */ #define POWERPC_NUM_PMC_ENABLED 6 /* if you add to the enum below, also add to the perfname array @@ -68,7 +68,7 @@ enum powerpc_data_index { }; extern unsigned long long perfdata[POWERPC_NUM_PMC_ENABLED][powerpc_perf_total][powerpc_data_total]; -#ifndef POWERPC_MODE_64BITS +#ifndef HAVE_PPC64 #define POWERP_PMC_DATATYPE unsigned long #define POWERPC_GET_PMC1(a) asm volatile("mfspr %0, 937" : "=r" (a)) #define POWERPC_GET_PMC2(a) asm volatile("mfspr %0, 938" : "=r" (a)) @@ -86,7 +86,7 @@ extern unsigned long long perfdata[POWERPC_NUM_PMC_ENABLED][powerpc_perf_total][ #define POWERPC_GET_PMC5(a) do {} while (0) #define POWERPC_GET_PMC6(a) do {} while (0) #endif -#else /* POWERPC_MODE_64BITS */ +#else /* HAVE_PPC64 */ #define POWERP_PMC_DATATYPE unsigned long long #define POWERPC_GET_PMC1(a) asm volatile("mfspr %0, 771" : "=r" (a)) #define POWERPC_GET_PMC2(a) asm volatile("mfspr %0, 772" : "=r" (a)) @@ -104,7 +104,7 @@ extern unsigned long long perfdata[POWERPC_NUM_PMC_ENABLED][powerpc_perf_total][ #define POWERPC_GET_PMC5(a) do {} while (0) #define POWERPC_GET_PMC6(a) do {} while (0) #endif -#endif /* POWERPC_MODE_64BITS */ +#endif /* HAVE_PPC64 */ #define POWERPC_PERF_DECLARE(a, cond) \ POWERP_PMC_DATATYPE \ pmc_start[POWERPC_NUM_PMC_ENABLED], \ @@ -152,4 +152,4 @@ extern unsigned long long perfdata[POWERPC_NUM_PMC_ENABLED][powerpc_perf_total][ #define POWERPC_PERF_STOP_COUNT(a, cond) do {} while (0) #endif /* CONFIG_POWERPC_PERF */ -#endif /* _DSPUTIL_PPC_ */ +#endif /* FFMPEG_DSPUTIL_PPC_H */ diff --git a/contrib/ffmpeg/libavcodec/ppc/fdct_altivec.c b/contrib/ffmpeg/libavcodec/ppc/fdct_altivec.c index 2418c32bb..6b9a35ba8 100644 --- a/contrib/ffmpeg/libavcodec/ppc/fdct_altivec.c +++ b/contrib/ffmpeg/libavcodec/ppc/fdct_altivec.c @@ -21,8 +21,8 @@ #include "common.h" -#include "../dsputil.h" -#include "dsputil_altivec.h" +#include "dsputil.h" +#include "dsputil_ppc.h" #include "gcc_fixes.h" diff --git a/contrib/ffmpeg/libavcodec/ppc/fft_altivec.c b/contrib/ffmpeg/libavcodec/ppc/fft_altivec.c index 384a774ff..e0b77807f 100644 --- a/contrib/ffmpeg/libavcodec/ppc/fft_altivec.c +++ b/contrib/ffmpeg/libavcodec/ppc/fft_altivec.c @@ -20,12 +20,12 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../dsputil.h" +#include "dsputil.h" #include "gcc_fixes.h" -#include "dsputil_altivec.h" - +#include "dsputil_ppc.h" +#include "util_altivec.h" /* those three macros are from libavcodec/fft.c and are required for the reference C code diff --git a/contrib/ffmpeg/libavcodec/ppc/float_altivec.c b/contrib/ffmpeg/libavcodec/ppc/float_altivec.c index 22c2de61a..750e6d7f9 100644 --- a/contrib/ffmpeg/libavcodec/ppc/float_altivec.c +++ b/contrib/ffmpeg/libavcodec/ppc/float_altivec.c @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../dsputil.h" +#include "dsputil.h" #include "gcc_fixes.h" diff --git a/contrib/ffmpeg/libavcodec/ppc/gcc_fixes.h b/contrib/ffmpeg/libavcodec/ppc/gcc_fixes.h index 5a4a55188..b8a908a61 100644 --- a/contrib/ffmpeg/libavcodec/ppc/gcc_fixes.h +++ b/contrib/ffmpeg/libavcodec/ppc/gcc_fixes.h @@ -20,31 +20,22 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _GCC_FIXES_ -#define _GCC_FIXES_ +#ifndef FFMPEG_GCC_FIXES_H +#define FFMPEG_GCC_FIXES_H + +#include "config.h" #ifdef HAVE_ALTIVEC_H #include #endif -#ifdef CONFIG_DARWIN -# ifndef __MWERKS__ -# define AVV(x...) (x) -# else -# define AVV -# endif -#define REG_v(a) asm ( #a ) -#else - -#define AVV(x...) {x} - #if (__GNUC__ < 4) # define REG_v(a) #else # define REG_v(a) asm ( #a ) #endif -#if (__GNUC__ * 100 + __GNUC_MINOR__ < 303) +#if (__GNUC__ == 3 && __GNUC_MINOR__ < 3) /* This code was provided to me by Bartosch Pixa * as a separate header file (broken_mergel.h). @@ -106,14 +97,6 @@ __ch (__bin_args_eq (vector unsigned int, (a1), vector unsigned int, (a2)), \ ((vector unsigned int) ff_vmrglw ((vector signed int) (a1), (vector signed int) (a2))), \ __altivec_link_error_invalid_argument ()))))))) -#endif - -#endif /* CONFIG_DARWIN */ - -#ifndef __MWERKS__ -#define const_vector const vector -#else -#define const_vector vector -#endif +#endif /* (__GNUC__ == 3 && __GNUC_MINOR__ < 3) */ -#endif /* _GCC_FIXES_ */ +#endif /* FFMPEG_GCC_FIXES_H */ diff --git a/contrib/ffmpeg/libavcodec/ppc/gmc_altivec.c b/contrib/ffmpeg/libavcodec/ppc/gmc_altivec.c index 42c936bb3..8151410d4 100644 --- a/contrib/ffmpeg/libavcodec/ppc/gmc_altivec.c +++ b/contrib/ffmpeg/libavcodec/ppc/gmc_altivec.c @@ -20,24 +20,25 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../dsputil.h" +#include "dsputil.h" #include "gcc_fixes.h" -#include "dsputil_altivec.h" +#include "dsputil_ppc.h" +#include "util_altivec.h" /* altivec-enhanced gmc1. ATM this code assume stride is a multiple of 8, - to preserve proper dst alignement. + to preserve proper dst alignment. */ #define GMC1_PERF_COND (h==8) void gmc1_altivec(uint8_t *dst /* align 8 */, uint8_t *src /* align1 */, int stride, int h, int x16, int y16, int rounder) { POWERPC_PERF_DECLARE(altivec_gmc1_num, GMC1_PERF_COND); - const unsigned short __attribute__ ((aligned(16))) rounder_a[8] = + const DECLARE_ALIGNED_16(unsigned short, rounder_a[8]) = {rounder, rounder, rounder, rounder, rounder, rounder, rounder, rounder}; - const unsigned short __attribute__ ((aligned(16))) ABCD[8] = + const DECLARE_ALIGNED_16(unsigned short, ABCD[8]) = { (16-x16)*(16-y16), /* A */ ( x16)*(16-y16), /* B */ @@ -45,8 +46,8 @@ POWERPC_PERF_DECLARE(altivec_gmc1_num, GMC1_PERF_COND); ( x16)*( y16), /* D */ 0, 0, 0, 0 /* padding */ }; - register const_vector unsigned char vczero = (const_vector unsigned char)vec_splat_u8(0); - register const_vector unsigned short vcsr8 = (const_vector unsigned short)vec_splat_u16(8); + register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0); + register const vector unsigned short vcsr8 = (const vector unsigned short)vec_splat_u16(8); register vector unsigned char dstv, dstv2, src_0, src_1, srcvA, srcvB, srcvC, srcvD; register vector unsigned short Av, Bv, Cv, Dv, rounderV, tempA, tempB, tempC, tempD; int i; diff --git a/contrib/ffmpeg/libavcodec/ppc/h264_altivec.c b/contrib/ffmpeg/libavcodec/ppc/h264_altivec.c index bac620e82..c716b1e33 100644 --- a/contrib/ffmpeg/libavcodec/ppc/h264_altivec.c +++ b/contrib/ffmpeg/libavcodec/ppc/h264_altivec.c @@ -18,11 +18,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../dsputil.h" +#include "dsputil.h" #include "gcc_fixes.h" +#include "dsputil_ppc.h" #include "dsputil_altivec.h" +#include "util_altivec.h" #include "types_altivec.h" #define PUT_OP_U8_ALTIVEC(d, s, dst) d = s @@ -180,130 +182,124 @@ static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## CODETYPE(uint8_t *dst, uint /* this code assume that stride % 16 == 0 */ void put_no_rnd_h264_chroma_mc8_altivec(uint8_t * dst, uint8_t * src, int stride, int h, int x, int y) { - signed int ABCD[4] __attribute__((aligned(16))) = + DECLARE_ALIGNED_16(signed int, ABCD[4]) = {((8 - x) * (8 - y)), - ((x) * (8 - y)), - ((8 - x) * (y)), - ((x) * (y))}; + ((x) * (8 - y)), + ((8 - x) * (y)), + ((x) * (y))}; register int i; - vector unsigned char fperm; - const vector signed int vABCD = vec_ld(0, ABCD); - const vector signed short vA = vec_splat((vector signed short)vABCD, 1); - const vector signed short vB = vec_splat((vector signed short)vABCD, 3); - const vector signed short vC = vec_splat((vector signed short)vABCD, 5); - const vector signed short vD = vec_splat((vector signed short)vABCD, 7); - const vector signed int vzero = vec_splat_s32(0); - const vector signed short v28ss = vec_sub(vec_sl(vec_splat_s16(1),vec_splat_u16(5)),vec_splat_s16(4)); - const vector unsigned short v6us = vec_splat_u16(6); - register int loadSecond = (((unsigned long)src) % 16) <= 7 ? 0 : 1; + vec_u8_t fperm; + const vec_s32_t vABCD = vec_ld(0, ABCD); + const vec_s16_t vA = vec_splat((vec_s16_t)vABCD, 1); + const vec_s16_t vB = vec_splat((vec_s16_t)vABCD, 3); + const vec_s16_t vC = vec_splat((vec_s16_t)vABCD, 5); + const vec_s16_t vD = vec_splat((vec_s16_t)vABCD, 7); + LOAD_ZERO; + const vec_s16_t v28ss = vec_sub(vec_sl(vec_splat_s16(1),vec_splat_u16(5)),vec_splat_s16(4)); + const vec_u16_t v6us = vec_splat_u16(6); + register int loadSecond = (((unsigned long)src) % 16) <= 7 ? 0 : 1; register int reallyBadAlign = (((unsigned long)src) % 16) == 15 ? 1 : 0; - vector unsigned char vsrcAuc, vsrcBuc, vsrcperm0, vsrcperm1; - vector unsigned char vsrc0uc, vsrc1uc; - vector signed short vsrc0ssH, vsrc1ssH; - vector unsigned char vsrcCuc, vsrc2uc, vsrc3uc; - vector signed short vsrc2ssH, vsrc3ssH, psum; - vector unsigned char vdst, ppsum, fsum; + vec_u8_t vsrcAuc, vsrcBuc, vsrcperm0, vsrcperm1; + vec_u8_t vsrc0uc, vsrc1uc; + vec_s16_t vsrc0ssH, vsrc1ssH; + vec_u8_t vsrcCuc, vsrc2uc, vsrc3uc; + vec_s16_t vsrc2ssH, vsrc3ssH, psum; + vec_u8_t vdst, ppsum, fsum; if (((unsigned long)dst) % 16 == 0) { - fperm = (vector unsigned char)AVV(0x10, 0x11, 0x12, 0x13, - 0x14, 0x15, 0x16, 0x17, - 0x08, 0x09, 0x0A, 0x0B, - 0x0C, 0x0D, 0x0E, 0x0F); + fperm = (vec_u8_t)AVV(0x10, 0x11, 0x12, 0x13, + 0x14, 0x15, 0x16, 0x17, + 0x08, 0x09, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0F); } else { - fperm = (vector unsigned char)AVV(0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, - 0x18, 0x19, 0x1A, 0x1B, - 0x1C, 0x1D, 0x1E, 0x1F); + fperm = (vec_u8_t)AVV(0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, + 0x18, 0x19, 0x1A, 0x1B, + 0x1C, 0x1D, 0x1E, 0x1F); } vsrcAuc = vec_ld(0, src); if (loadSecond) - vsrcBuc = vec_ld(16, src); + vsrcBuc = vec_ld(16, src); vsrcperm0 = vec_lvsl(0, src); vsrcperm1 = vec_lvsl(1, src); vsrc0uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm0); if (reallyBadAlign) - vsrc1uc = vsrcBuc; + vsrc1uc = vsrcBuc; else - vsrc1uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm1); + vsrc1uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm1); - vsrc0ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero, - (vector unsigned char)vsrc0uc); - vsrc1ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero, - (vector unsigned char)vsrc1uc); + vsrc0ssH = (vec_s16_t)vec_mergeh(zero_u8v, (vec_u8_t)vsrc0uc); + vsrc1ssH = (vec_s16_t)vec_mergeh(zero_u8v, (vec_u8_t)vsrc1uc); if (!loadSecond) {// -> !reallyBadAlign - for (i = 0 ; i < h ; i++) { + for (i = 0 ; i < h ; i++) { - vsrcCuc = vec_ld(stride + 0, src); + vsrcCuc = vec_ld(stride + 0, src); - vsrc2uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0); - vsrc3uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1); + vsrc2uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0); + vsrc3uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1); - vsrc2ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero, - (vector unsigned char)vsrc2uc); - vsrc3ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero, - (vector unsigned char)vsrc3uc); + vsrc2ssH = (vec_s16_t)vec_mergeh(zero_u8v, (vec_u8_t)vsrc2uc); + vsrc3ssH = (vec_s16_t)vec_mergeh(zero_u8v, (vec_u8_t)vsrc3uc); - psum = vec_mladd(vA, vsrc0ssH, vec_splat_s16(0)); - psum = vec_mladd(vB, vsrc1ssH, psum); - psum = vec_mladd(vC, vsrc2ssH, psum); - psum = vec_mladd(vD, vsrc3ssH, psum); - psum = vec_add(v28ss, psum); - psum = vec_sra(psum, v6us); + psum = vec_mladd(vA, vsrc0ssH, vec_splat_s16(0)); + psum = vec_mladd(vB, vsrc1ssH, psum); + psum = vec_mladd(vC, vsrc2ssH, psum); + psum = vec_mladd(vD, vsrc3ssH, psum); + psum = vec_add(v28ss, psum); + psum = vec_sra(psum, v6us); - vdst = vec_ld(0, dst); - ppsum = (vector unsigned char)vec_packsu(psum, psum); - fsum = vec_perm(vdst, ppsum, fperm); + vdst = vec_ld(0, dst); + ppsum = (vec_u8_t)vec_packsu(psum, psum); + fsum = vec_perm(vdst, ppsum, fperm); - vec_st(fsum, 0, dst); + vec_st(fsum, 0, dst); - vsrc0ssH = vsrc2ssH; - vsrc1ssH = vsrc3ssH; + vsrc0ssH = vsrc2ssH; + vsrc1ssH = vsrc3ssH; - dst += stride; - src += stride; - } + dst += stride; + src += stride; + } } else { - vector unsigned char vsrcDuc; - for (i = 0 ; i < h ; i++) { - vsrcCuc = vec_ld(stride + 0, src); - vsrcDuc = vec_ld(stride + 16, src); - - vsrc2uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0); - if (reallyBadAlign) - vsrc3uc = vsrcDuc; - else - vsrc3uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1); - - vsrc2ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero, - (vector unsigned char)vsrc2uc); - vsrc3ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero, - (vector unsigned char)vsrc3uc); - - psum = vec_mladd(vA, vsrc0ssH, vec_splat_s16(0)); - psum = vec_mladd(vB, vsrc1ssH, psum); - psum = vec_mladd(vC, vsrc2ssH, psum); - psum = vec_mladd(vD, vsrc3ssH, psum); - psum = vec_add(v28ss, psum); - psum = vec_sr(psum, v6us); - - vdst = vec_ld(0, dst); - ppsum = (vector unsigned char)vec_pack(psum, psum); - fsum = vec_perm(vdst, ppsum, fperm); - - vec_st(fsum, 0, dst); - - vsrc0ssH = vsrc2ssH; - vsrc1ssH = vsrc3ssH; - - dst += stride; - src += stride; - } + vec_u8_t vsrcDuc; + for (i = 0 ; i < h ; i++) { + vsrcCuc = vec_ld(stride + 0, src); + vsrcDuc = vec_ld(stride + 16, src); + + vsrc2uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0); + if (reallyBadAlign) + vsrc3uc = vsrcDuc; + else + vsrc3uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1); + + vsrc2ssH = (vec_s16_t)vec_mergeh(zero_u8v, (vec_u8_t)vsrc2uc); + vsrc3ssH = (vec_s16_t)vec_mergeh(zero_u8v, (vec_u8_t)vsrc3uc); + + psum = vec_mladd(vA, vsrc0ssH, vec_splat_s16(0)); + psum = vec_mladd(vB, vsrc1ssH, psum); + psum = vec_mladd(vC, vsrc2ssH, psum); + psum = vec_mladd(vD, vsrc3ssH, psum); + psum = vec_add(v28ss, psum); + psum = vec_sr(psum, v6us); + + vdst = vec_ld(0, dst); + ppsum = (vec_u8_t)vec_pack(psum, psum); + fsum = vec_perm(vdst, ppsum, fperm); + + vec_st(fsum, 0, dst); + + vsrc0ssH = vsrc2ssH; + vsrc1ssH = vsrc3ssH; + + dst += stride; + src += stride; + } } } @@ -312,7 +308,7 @@ static inline void put_pixels16_l2_altivec( uint8_t * dst, const uint8_t * src1, int src_stride1, int h) { int i; - vector unsigned char a, b, d, tmp1, tmp2, mask, mask_, edges, align; + vec_u8_t a, b, d, tmp1, tmp2, mask, mask_, edges, align; mask_ = vec_lvsl(0, src2); @@ -354,7 +350,7 @@ static inline void avg_pixels16_l2_altivec( uint8_t * dst, const uint8_t * src1, int src_stride1, int h) { int i; - vector unsigned char a, b, d, tmp1, tmp2, mask, mask_, edges, align; + vec_u8_t a, b, d, tmp1, tmp2, mask, mask_, edges, align; mask_ = vec_lvsl(0, src2); @@ -404,6 +400,82 @@ static inline void avg_pixels16_l2_altivec( uint8_t * dst, const uint8_t * src1, * IDCT transform: ****************************************************************************/ +#define VEC_1D_DCT(vb0,vb1,vb2,vb3,va0,va1,va2,va3) \ + /* 1st stage */ \ + vz0 = vec_add(vb0,vb2); /* temp[0] = Y[0] + Y[2] */ \ + vz1 = vec_sub(vb0,vb2); /* temp[1] = Y[0] - Y[2] */ \ + vz2 = vec_sra(vb1,vec_splat_u16(1)); \ + vz2 = vec_sub(vz2,vb3); /* temp[2] = Y[1].1/2 - Y[3] */ \ + vz3 = vec_sra(vb3,vec_splat_u16(1)); \ + vz3 = vec_add(vb1,vz3); /* temp[3] = Y[1] + Y[3].1/2 */ \ + /* 2nd stage: output */ \ + va0 = vec_add(vz0,vz3); /* x[0] = temp[0] + temp[3] */ \ + va1 = vec_add(vz1,vz2); /* x[1] = temp[1] + temp[2] */ \ + va2 = vec_sub(vz1,vz2); /* x[2] = temp[1] - temp[2] */ \ + va3 = vec_sub(vz0,vz3) /* x[3] = temp[0] - temp[3] */ + +#define VEC_TRANSPOSE_4(a0,a1,a2,a3,b0,b1,b2,b3) \ + b0 = vec_mergeh( a0, a0 ); \ + b1 = vec_mergeh( a1, a0 ); \ + b2 = vec_mergeh( a2, a0 ); \ + b3 = vec_mergeh( a3, a0 ); \ + a0 = vec_mergeh( b0, b2 ); \ + a1 = vec_mergel( b0, b2 ); \ + a2 = vec_mergeh( b1, b3 ); \ + a3 = vec_mergel( b1, b3 ); \ + b0 = vec_mergeh( a0, a2 ); \ + b1 = vec_mergel( a0, a2 ); \ + b2 = vec_mergeh( a1, a3 ); \ + b3 = vec_mergel( a1, a3 ) + +#define VEC_LOAD_U8_ADD_S16_STORE_U8(va) \ + vdst_orig = vec_ld(0, dst); \ + vdst = vec_perm(vdst_orig, zero_u8v, vdst_mask); \ + vdst_ss = (vec_s16_t) vec_mergeh(zero_u8v, vdst); \ + va = vec_add(va, vdst_ss); \ + va_u8 = vec_packsu(va, zero_s16v); \ + va_u32 = vec_splat((vec_u32_t)va_u8, 0); \ + vec_ste(va_u32, element, (uint32_t*)dst); + +static void ff_h264_idct_add_altivec(uint8_t *dst, DCTELEM *block, int stride) +{ + vec_s16_t va0, va1, va2, va3; + vec_s16_t vz0, vz1, vz2, vz3; + vec_s16_t vtmp0, vtmp1, vtmp2, vtmp3; + vec_u8_t va_u8; + vec_u32_t va_u32; + vec_s16_t vdst_ss; + const vec_u16_t v6us = vec_splat_u16(6); + vec_u8_t vdst, vdst_orig; + vec_u8_t vdst_mask = vec_lvsl(0, dst); + int element = ((unsigned long)dst & 0xf) >> 2; + LOAD_ZERO; + + block[0] += 32; /* add 32 as a DC-level for rounding */ + + vtmp0 = vec_ld(0,block); + vtmp1 = vec_sld(vtmp0, vtmp0, 8); + vtmp2 = vec_ld(16,block); + vtmp3 = vec_sld(vtmp2, vtmp2, 8); + + VEC_1D_DCT(vtmp0,vtmp1,vtmp2,vtmp3,va0,va1,va2,va3); + VEC_TRANSPOSE_4(va0,va1,va2,va3,vtmp0,vtmp1,vtmp2,vtmp3); + VEC_1D_DCT(vtmp0,vtmp1,vtmp2,vtmp3,va0,va1,va2,va3); + + va0 = vec_sra(va0,v6us); + va1 = vec_sra(va1,v6us); + va2 = vec_sra(va2,v6us); + va3 = vec_sra(va3,v6us); + + VEC_LOAD_U8_ADD_S16_STORE_U8(va0); + dst += stride; + VEC_LOAD_U8_ADD_S16_STORE_U8(va1); + dst += stride; + VEC_LOAD_U8_ADD_S16_STORE_U8(va2); + dst += stride; + VEC_LOAD_U8_ADD_S16_STORE_U8(va3); +} + #define IDCT8_1D_ALTIVEC(s0, s1, s2, s3, s4, s5, s6, s7, d0, d1, d2, d3, d4, d5, d6, d7) {\ /* a0 = SRC(0) + SRC(4); */ \ vec_s16_t a0v = vec_add(s0, s4); \ @@ -491,8 +563,7 @@ void ff_h264_idct8_add_altivec( uint8_t *dst, DCTELEM *dct, int stride ) { const vec_u16_t twov = vec_splat_u16(2); const vec_u16_t sixv = vec_splat_u16(6); - const vec_u8_t sel = (vec_u8_t) AVV(0,0,0,0,0,0,0,0, - -1,-1,-1,-1,-1,-1,-1,-1); + const vec_u8_t sel = (vec_u8_t) AVV(0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1); LOAD_ZERO; dct[0] += 32; // rounding for the >>6 at the end @@ -524,42 +595,310 @@ void ff_h264_idct8_add_altivec( uint8_t *dst, DCTELEM *dct, int stride ) { ALTIVEC_STORE_SUM_CLIP(&dst[7*stride], idct7, perm_ldv, perm_stv, sel); } +#define transpose4x16(r0, r1, r2, r3) { \ + register vec_u8_t r4; \ + register vec_u8_t r5; \ + register vec_u8_t r6; \ + register vec_u8_t r7; \ + \ + r4 = vec_mergeh(r0, r2); /*0, 2 set 0*/ \ + r5 = vec_mergel(r0, r2); /*0, 2 set 1*/ \ + r6 = vec_mergeh(r1, r3); /*1, 3 set 0*/ \ + r7 = vec_mergel(r1, r3); /*1, 3 set 1*/ \ + \ + r0 = vec_mergeh(r4, r6); /*all set 0*/ \ + r1 = vec_mergel(r4, r6); /*all set 1*/ \ + r2 = vec_mergeh(r5, r7); /*all set 2*/ \ + r3 = vec_mergel(r5, r7); /*all set 3*/ \ +} + +static inline void write16x4(uint8_t *dst, int dst_stride, + register vec_u8_t r0, register vec_u8_t r1, + register vec_u8_t r2, register vec_u8_t r3) { + DECLARE_ALIGNED_16(unsigned char, result[64]); + uint32_t *src_int = (uint32_t *)result, *dst_int = (uint32_t *)dst; + int int_dst_stride = dst_stride/4; + + vec_st(r0, 0, result); + vec_st(r1, 16, result); + vec_st(r2, 32, result); + vec_st(r3, 48, result); + /* FIXME: there has to be a better way!!!! */ + *dst_int = *src_int; + *(dst_int+ int_dst_stride) = *(src_int + 1); + *(dst_int+ 2*int_dst_stride) = *(src_int + 2); + *(dst_int+ 3*int_dst_stride) = *(src_int + 3); + *(dst_int+ 4*int_dst_stride) = *(src_int + 4); + *(dst_int+ 5*int_dst_stride) = *(src_int + 5); + *(dst_int+ 6*int_dst_stride) = *(src_int + 6); + *(dst_int+ 7*int_dst_stride) = *(src_int + 7); + *(dst_int+ 8*int_dst_stride) = *(src_int + 8); + *(dst_int+ 9*int_dst_stride) = *(src_int + 9); + *(dst_int+10*int_dst_stride) = *(src_int + 10); + *(dst_int+11*int_dst_stride) = *(src_int + 11); + *(dst_int+12*int_dst_stride) = *(src_int + 12); + *(dst_int+13*int_dst_stride) = *(src_int + 13); + *(dst_int+14*int_dst_stride) = *(src_int + 14); + *(dst_int+15*int_dst_stride) = *(src_int + 15); +} + +/** \brief performs a 6x16 transpose of data in src, and stores it to dst + \todo FIXME: see if we can't spare some vec_lvsl() by them factorizing + out of unaligned_load() */ +#define readAndTranspose16x6(src, src_stride, r8, r9, r10, r11, r12, r13) {\ + register vec_u8_t r0 = unaligned_load(0, src); \ + register vec_u8_t r1 = unaligned_load( src_stride, src); \ + register vec_u8_t r2 = unaligned_load(2* src_stride, src); \ + register vec_u8_t r3 = unaligned_load(3* src_stride, src); \ + register vec_u8_t r4 = unaligned_load(4* src_stride, src); \ + register vec_u8_t r5 = unaligned_load(5* src_stride, src); \ + register vec_u8_t r6 = unaligned_load(6* src_stride, src); \ + register vec_u8_t r7 = unaligned_load(7* src_stride, src); \ + register vec_u8_t r14 = unaligned_load(14*src_stride, src); \ + register vec_u8_t r15 = unaligned_load(15*src_stride, src); \ + \ + r8 = unaligned_load( 8*src_stride, src); \ + r9 = unaligned_load( 9*src_stride, src); \ + r10 = unaligned_load(10*src_stride, src); \ + r11 = unaligned_load(11*src_stride, src); \ + r12 = unaligned_load(12*src_stride, src); \ + r13 = unaligned_load(13*src_stride, src); \ + \ + /*Merge first pairs*/ \ + r0 = vec_mergeh(r0, r8); /*0, 8*/ \ + r1 = vec_mergeh(r1, r9); /*1, 9*/ \ + r2 = vec_mergeh(r2, r10); /*2,10*/ \ + r3 = vec_mergeh(r3, r11); /*3,11*/ \ + r4 = vec_mergeh(r4, r12); /*4,12*/ \ + r5 = vec_mergeh(r5, r13); /*5,13*/ \ + r6 = vec_mergeh(r6, r14); /*6,14*/ \ + r7 = vec_mergeh(r7, r15); /*7,15*/ \ + \ + /*Merge second pairs*/ \ + r8 = vec_mergeh(r0, r4); /*0,4, 8,12 set 0*/ \ + r9 = vec_mergel(r0, r4); /*0,4, 8,12 set 1*/ \ + r10 = vec_mergeh(r1, r5); /*1,5, 9,13 set 0*/ \ + r11 = vec_mergel(r1, r5); /*1,5, 9,13 set 1*/ \ + r12 = vec_mergeh(r2, r6); /*2,6,10,14 set 0*/ \ + r13 = vec_mergel(r2, r6); /*2,6,10,14 set 1*/ \ + r14 = vec_mergeh(r3, r7); /*3,7,11,15 set 0*/ \ + r15 = vec_mergel(r3, r7); /*3,7,11,15 set 1*/ \ + \ + /*Third merge*/ \ + r0 = vec_mergeh(r8, r12); /*0,2,4,6,8,10,12,14 set 0*/ \ + r1 = vec_mergel(r8, r12); /*0,2,4,6,8,10,12,14 set 1*/ \ + r2 = vec_mergeh(r9, r13); /*0,2,4,6,8,10,12,14 set 2*/ \ + r4 = vec_mergeh(r10, r14); /*1,3,5,7,9,11,13,15 set 0*/ \ + r5 = vec_mergel(r10, r14); /*1,3,5,7,9,11,13,15 set 1*/ \ + r6 = vec_mergeh(r11, r15); /*1,3,5,7,9,11,13,15 set 2*/ \ + /* Don't need to compute 3 and 7*/ \ + \ + /*Final merge*/ \ + r8 = vec_mergeh(r0, r4); /*all set 0*/ \ + r9 = vec_mergel(r0, r4); /*all set 1*/ \ + r10 = vec_mergeh(r1, r5); /*all set 2*/ \ + r11 = vec_mergel(r1, r5); /*all set 3*/ \ + r12 = vec_mergeh(r2, r6); /*all set 4*/ \ + r13 = vec_mergel(r2, r6); /*all set 5*/ \ + /* Don't need to compute 14 and 15*/ \ + \ +} + +// out: o = |x-y| < a +static inline vec_u8_t diff_lt_altivec ( register vec_u8_t x, + register vec_u8_t y, + register vec_u8_t a) { + + register vec_u8_t diff = vec_subs(x, y); + register vec_u8_t diffneg = vec_subs(y, x); + register vec_u8_t o = vec_or(diff, diffneg); /* |x-y| */ + o = (vec_u8_t)vec_cmplt(o, a); + return o; +} + +static inline vec_u8_t h264_deblock_mask ( register vec_u8_t p0, + register vec_u8_t p1, + register vec_u8_t q0, + register vec_u8_t q1, + register vec_u8_t alpha, + register vec_u8_t beta) { + + register vec_u8_t mask; + register vec_u8_t tempmask; + + mask = diff_lt_altivec(p0, q0, alpha); + tempmask = diff_lt_altivec(p1, p0, beta); + mask = vec_and(mask, tempmask); + tempmask = diff_lt_altivec(q1, q0, beta); + mask = vec_and(mask, tempmask); + + return mask; +} + +// out: newp1 = clip((p2 + ((p0 + q0 + 1) >> 1)) >> 1, p1-tc0, p1+tc0) +static inline vec_u8_t h264_deblock_q1(register vec_u8_t p0, + register vec_u8_t p1, + register vec_u8_t p2, + register vec_u8_t q0, + register vec_u8_t tc0) { + + register vec_u8_t average = vec_avg(p0, q0); + register vec_u8_t temp; + register vec_u8_t uncliped; + register vec_u8_t ones; + register vec_u8_t max; + register vec_u8_t min; + register vec_u8_t newp1; + + temp = vec_xor(average, p2); + average = vec_avg(average, p2); /*avg(p2, avg(p0, q0)) */ + ones = vec_splat_u8(1); + temp = vec_and(temp, ones); /*(p2^avg(p0, q0)) & 1 */ + uncliped = vec_subs(average, temp); /*(p2+((p0+q0+1)>>1))>>1 */ + max = vec_adds(p1, tc0); + min = vec_subs(p1, tc0); + newp1 = vec_max(min, uncliped); + newp1 = vec_min(max, newp1); + return newp1; +} + +#define h264_deblock_p0_q0(p0, p1, q0, q1, tc0masked) { \ + \ + const vec_u8_t A0v = vec_sl(vec_splat_u8(10), vec_splat_u8(4)); \ + \ + register vec_u8_t pq0bit = vec_xor(p0,q0); \ + register vec_u8_t q1minus; \ + register vec_u8_t p0minus; \ + register vec_u8_t stage1; \ + register vec_u8_t stage2; \ + register vec_u8_t vec160; \ + register vec_u8_t delta; \ + register vec_u8_t deltaneg; \ + \ + q1minus = vec_nor(q1, q1); /* 255 - q1 */ \ + stage1 = vec_avg(p1, q1minus); /* (p1 - q1 + 256)>>1 */ \ + stage2 = vec_sr(stage1, vec_splat_u8(1)); /* (p1 - q1 + 256)>>2 = 64 + (p1 - q1) >> 2 */ \ + p0minus = vec_nor(p0, p0); /* 255 - p0 */ \ + stage1 = vec_avg(q0, p0minus); /* (q0 - p0 + 256)>>1 */ \ + pq0bit = vec_and(pq0bit, vec_splat_u8(1)); \ + stage2 = vec_avg(stage2, pq0bit); /* 32 + ((q0 - p0)&1 + (p1 - q1) >> 2 + 1) >> 1 */ \ + stage2 = vec_adds(stage2, stage1); /* 160 + ((p0 - q0) + (p1 - q1) >> 2 + 1) >> 1 */ \ + vec160 = vec_ld(0, &A0v); \ + deltaneg = vec_subs(vec160, stage2); /* -d */ \ + delta = vec_subs(stage2, vec160); /* d */ \ + deltaneg = vec_min(tc0masked, deltaneg); \ + delta = vec_min(tc0masked, delta); \ + p0 = vec_subs(p0, deltaneg); \ + q0 = vec_subs(q0, delta); \ + p0 = vec_adds(p0, delta); \ + q0 = vec_adds(q0, deltaneg); \ +} + +#define h264_loop_filter_luma_altivec(p2, p1, p0, q0, q1, q2, alpha, beta, tc0) { \ + DECLARE_ALIGNED_16(unsigned char, temp[16]); \ + register vec_u8_t alphavec; \ + register vec_u8_t betavec; \ + register vec_u8_t mask; \ + register vec_u8_t p1mask; \ + register vec_u8_t q1mask; \ + register vector signed char tc0vec; \ + register vec_u8_t finaltc0; \ + register vec_u8_t tc0masked; \ + register vec_u8_t newp1; \ + register vec_u8_t newq1; \ + \ + temp[0] = alpha; \ + temp[1] = beta; \ + alphavec = vec_ld(0, temp); \ + betavec = vec_splat(alphavec, 0x1); \ + alphavec = vec_splat(alphavec, 0x0); \ + mask = h264_deblock_mask(p0, p1, q0, q1, alphavec, betavec); /*if in block */ \ + \ + *((int *)temp) = *((int *)tc0); \ + tc0vec = vec_ld(0, (signed char*)temp); \ + tc0vec = vec_mergeh(tc0vec, tc0vec); \ + tc0vec = vec_mergeh(tc0vec, tc0vec); \ + mask = vec_and(mask, vec_cmpgt(tc0vec, vec_splat_s8(-1))); /* if tc0[i] >= 0 */ \ + finaltc0 = vec_and((vec_u8_t)tc0vec, mask); /* tc = tc0 */ \ + \ + p1mask = diff_lt_altivec(p2, p0, betavec); \ + p1mask = vec_and(p1mask, mask); /* if ( |p2 - p0| < beta) */ \ + tc0masked = vec_and(p1mask, (vec_u8_t)tc0vec); \ + finaltc0 = vec_sub(finaltc0, p1mask); /* tc++ */ \ + newp1 = h264_deblock_q1(p0, p1, p2, q0, tc0masked); \ + /*end if*/ \ + \ + q1mask = diff_lt_altivec(q2, q0, betavec); \ + q1mask = vec_and(q1mask, mask); /* if ( |q2 - q0| < beta ) */\ + tc0masked = vec_and(q1mask, (vec_u8_t)tc0vec); \ + finaltc0 = vec_sub(finaltc0, q1mask); /* tc++ */ \ + newq1 = h264_deblock_q1(p0, q1, q2, q0, tc0masked); \ + /*end if*/ \ + \ + h264_deblock_p0_q0(p0, p1, q0, q1, finaltc0); \ + p1 = newp1; \ + q1 = newq1; \ +} + +static void h264_v_loop_filter_luma_altivec(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) { + + if ((tc0[0] & tc0[1] & tc0[2] & tc0[3]) >= 0) { + register vec_u8_t p2 = vec_ld(-3*stride, pix); + register vec_u8_t p1 = vec_ld(-2*stride, pix); + register vec_u8_t p0 = vec_ld(-1*stride, pix); + register vec_u8_t q0 = vec_ld(0, pix); + register vec_u8_t q1 = vec_ld(stride, pix); + register vec_u8_t q2 = vec_ld(2*stride, pix); + h264_loop_filter_luma_altivec(p2, p1, p0, q0, q1, q2, alpha, beta, tc0); + vec_st(p1, -2*stride, pix); + vec_st(p0, -1*stride, pix); + vec_st(q0, 0, pix); + vec_st(q1, stride, pix); + } +} + +static void h264_h_loop_filter_luma_altivec(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) { + + register vec_u8_t line0, line1, line2, line3, line4, line5; + if ((tc0[0] & tc0[1] & tc0[2] & tc0[3]) < 0) + return; + readAndTranspose16x6(pix-3, stride, line0, line1, line2, line3, line4, line5); + h264_loop_filter_luma_altivec(line0, line1, line2, line3, line4, line5, alpha, beta, tc0); + transpose4x16(line1, line2, line3, line4); + write16x4(pix-2, stride, line1, line2, line3, line4); +} + void dsputil_h264_init_ppc(DSPContext* c, AVCodecContext *avctx) { -#ifdef HAVE_ALTIVEC - if (has_altivec()) { - c->put_h264_chroma_pixels_tab[0] = put_h264_chroma_mc8_altivec; - c->put_no_rnd_h264_chroma_pixels_tab[0] = put_no_rnd_h264_chroma_mc8_altivec; - c->avg_h264_chroma_pixels_tab[0] = avg_h264_chroma_mc8_altivec; - c->h264_idct8_add = ff_h264_idct8_add_altivec; + if (has_altivec()) { + c->put_h264_chroma_pixels_tab[0] = put_h264_chroma_mc8_altivec; + c->put_no_rnd_h264_chroma_pixels_tab[0] = put_no_rnd_h264_chroma_mc8_altivec; + c->avg_h264_chroma_pixels_tab[0] = avg_h264_chroma_mc8_altivec; + c->h264_idct_add = ff_h264_idct_add_altivec; + c->h264_idct8_add = ff_h264_idct8_add_altivec; + c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_altivec; + c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_altivec; #define dspfunc(PFX, IDX, NUM) \ - c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_altivec; \ - c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_altivec; \ - c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_altivec; \ - c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_altivec; \ - c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_altivec; \ - c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_altivec; \ - c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_altivec; \ - c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_altivec; \ - c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_altivec; \ - c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_altivec; \ - c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_altivec; \ - c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_altivec; \ - c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_altivec; \ - c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_altivec; \ - c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_altivec; \ - c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_altivec - - dspfunc(put_h264_qpel, 0, 16); - dspfunc(avg_h264_qpel, 0, 16); + c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_altivec; \ + c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_altivec; \ + c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_altivec; \ + c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_altivec; \ + c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_altivec; \ + c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_altivec; \ + c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_altivec; \ + c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_altivec; \ + c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_altivec; \ + c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_altivec; \ + c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_altivec; \ + c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_altivec; \ + c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_altivec; \ + c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_altivec; \ + c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_altivec; \ + c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_altivec + + dspfunc(put_h264_qpel, 0, 16); + dspfunc(avg_h264_qpel, 0, 16); #undef dspfunc - - } else -#endif /* HAVE_ALTIVEC */ - { - // Non-AltiVec PPC optimisations - - // ... pending ... - } + } } diff --git a/contrib/ffmpeg/libavcodec/ppc/h264_template_altivec.c b/contrib/ffmpeg/libavcodec/ppc/h264_template_altivec.c index e8ad67f2f..d8ad96419 100644 --- a/contrib/ffmpeg/libavcodec/ppc/h264_template_altivec.c +++ b/contrib/ffmpeg/libavcodec/ppc/h264_template_altivec.c @@ -18,186 +18,227 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +//#define DEBUG_ALIGNMENT +#ifdef DEBUG_ALIGNMENT +#define ASSERT_ALIGNED(ptr) assert(((unsigned long)ptr&0x0000000F)); +#else +#define ASSERT_ALIGNED(ptr) ; +#endif + /* this code assume that stride % 16 == 0 */ -void PREFIX_h264_chroma_mc8_altivec(uint8_t * dst, uint8_t * src, int stride, int h, int x, int y) { + +#define CHROMA_MC8_ALTIVEC_CORE \ + vsrc2ssH = (vec_s16_t)vec_mergeh(zero_u8v,(vec_u8_t)vsrc2uc);\ + vsrc3ssH = (vec_s16_t)vec_mergeh(zero_u8v,(vec_u8_t)vsrc3uc);\ +\ + psum = vec_mladd(vA, vsrc0ssH, v32ss);\ + psum = vec_mladd(vB, vsrc1ssH, psum);\ + psum = vec_mladd(vC, vsrc2ssH, psum);\ + psum = vec_mladd(vD, vsrc3ssH, psum);\ + psum = vec_sr(psum, v6us);\ +\ + vdst = vec_ld(0, dst);\ + ppsum = (vec_u8_t)vec_pack(psum, psum);\ + vfdst = vec_perm(vdst, ppsum, fperm);\ +\ + OP_U8_ALTIVEC(fsum, vfdst, vdst);\ +\ + vec_st(fsum, 0, dst);\ +\ + vsrc0ssH = vsrc2ssH;\ + vsrc1ssH = vsrc3ssH;\ +\ + dst += stride;\ + src += stride; + +#define CHROMA_MC8_ALTIVEC_CORE_SIMPLE \ +\ + vsrc0ssH = (vec_s16_t)vec_mergeh(zero_u8v,(vec_u8_t)vsrc0uc);\ + vsrc1ssH = (vec_s16_t)vec_mergeh(zero_u8v,(vec_u8_t)vsrc1uc);\ +\ + psum = vec_mladd(vA, vsrc0ssH, v32ss);\ + psum = vec_mladd(vE, vsrc1ssH, psum);\ + psum = vec_sr(psum, v6us);\ +\ + vdst = vec_ld(0, dst);\ + ppsum = (vec_u8_t)vec_pack(psum, psum);\ + vfdst = vec_perm(vdst, ppsum, fperm);\ +\ + OP_U8_ALTIVEC(fsum, vfdst, vdst);\ +\ + vec_st(fsum, 0, dst);\ +\ + dst += stride;\ + src += stride; + +void PREFIX_h264_chroma_mc8_altivec(uint8_t * dst, uint8_t * src, + int stride, int h, int x, int y) { POWERPC_PERF_DECLARE(PREFIX_h264_chroma_mc8_num, 1); - signed int ABCD[4] __attribute__((aligned(16))) = + DECLARE_ALIGNED_16(signed int, ABCD[4]) = {((8 - x) * (8 - y)), - ((x) * (8 - y)), - ((8 - x) * (y)), - ((x) * (y))}; + (( x) * (8 - y)), + ((8 - x) * ( y)), + (( x) * ( y))}; register int i; - vector unsigned char fperm; - const vector signed int vABCD = vec_ld(0, ABCD); - const vector signed short vA = vec_splat((vector signed short)vABCD, 1); - const vector signed short vB = vec_splat((vector signed short)vABCD, 3); - const vector signed short vC = vec_splat((vector signed short)vABCD, 5); - const vector signed short vD = vec_splat((vector signed short)vABCD, 7); - const vector signed int vzero = vec_splat_s32(0); - const vector signed short v32ss = vec_sl(vec_splat_s16(1),vec_splat_u16(5)); - const vector unsigned short v6us = vec_splat_u16(6); + vec_u8_t fperm; + const vec_s32_t vABCD = vec_ld(0, ABCD); + const vec_s16_t vA = vec_splat((vec_s16_t)vABCD, 1); + const vec_s16_t vB = vec_splat((vec_s16_t)vABCD, 3); + const vec_s16_t vC = vec_splat((vec_s16_t)vABCD, 5); + const vec_s16_t vD = vec_splat((vec_s16_t)vABCD, 7); + LOAD_ZERO; + const vec_s16_t v32ss = vec_sl(vec_splat_s16(1),vec_splat_u16(5)); + const vec_u16_t v6us = vec_splat_u16(6); register int loadSecond = (((unsigned long)src) % 16) <= 7 ? 0 : 1; register int reallyBadAlign = (((unsigned long)src) % 16) == 15 ? 1 : 0; - vector unsigned char vsrcAuc, vsrcBuc, vsrcperm0, vsrcperm1; - vector unsigned char vsrc0uc, vsrc1uc; - vector signed short vsrc0ssH, vsrc1ssH; - vector unsigned char vsrcCuc, vsrc2uc, vsrc3uc; - vector signed short vsrc2ssH, vsrc3ssH, psum; - vector unsigned char vdst, ppsum, vfdst, fsum; + vec_u8_t vsrcAuc, vsrcBuc, vsrcperm0, vsrcperm1; + vec_u8_t vsrc0uc, vsrc1uc; + vec_s16_t vsrc0ssH, vsrc1ssH; + vec_u8_t vsrcCuc, vsrc2uc, vsrc3uc; + vec_s16_t vsrc2ssH, vsrc3ssH, psum; + vec_u8_t vdst, ppsum, vfdst, fsum; POWERPC_PERF_START_COUNT(PREFIX_h264_chroma_mc8_num, 1); if (((unsigned long)dst) % 16 == 0) { - fperm = (vector unsigned char)AVV(0x10, 0x11, 0x12, 0x13, - 0x14, 0x15, 0x16, 0x17, - 0x08, 0x09, 0x0A, 0x0B, - 0x0C, 0x0D, 0x0E, 0x0F); + fperm = (vec_u8_t)AVV(0x10, 0x11, 0x12, 0x13, + 0x14, 0x15, 0x16, 0x17, + 0x08, 0x09, 0x0A, 0x0B, + 0x0C, 0x0D, 0x0E, 0x0F); } else { - fperm = (vector unsigned char)AVV(0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, - 0x18, 0x19, 0x1A, 0x1B, - 0x1C, 0x1D, 0x1E, 0x1F); + fperm = (vec_u8_t)AVV(0x00, 0x01, 0x02, 0x03, + 0x04, 0x05, 0x06, 0x07, + 0x18, 0x19, 0x1A, 0x1B, + 0x1C, 0x1D, 0x1E, 0x1F); } vsrcAuc = vec_ld(0, src); if (loadSecond) - vsrcBuc = vec_ld(16, src); + vsrcBuc = vec_ld(16, src); vsrcperm0 = vec_lvsl(0, src); vsrcperm1 = vec_lvsl(1, src); vsrc0uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm0); if (reallyBadAlign) - vsrc1uc = vsrcBuc; + vsrc1uc = vsrcBuc; else - vsrc1uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm1); - - vsrc0ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero, - (vector unsigned char)vsrc0uc); - vsrc1ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero, - (vector unsigned char)vsrc1uc); - - if (!loadSecond) {// -> !reallyBadAlign - for (i = 0 ; i < h ; i++) { - - - vsrcCuc = vec_ld(stride + 0, src); - - vsrc2uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0); - vsrc3uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1); - - vsrc2ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero, - (vector unsigned char)vsrc2uc); - vsrc3ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero, - (vector unsigned char)vsrc3uc); - - psum = vec_mladd(vA, vsrc0ssH, vec_splat_s16(0)); - psum = vec_mladd(vB, vsrc1ssH, psum); - psum = vec_mladd(vC, vsrc2ssH, psum); - psum = vec_mladd(vD, vsrc3ssH, psum); - psum = vec_add(v32ss, psum); - psum = vec_sra(psum, v6us); - - vdst = vec_ld(0, dst); - ppsum = (vector unsigned char)vec_packsu(psum, psum); - vfdst = vec_perm(vdst, ppsum, fperm); - - OP_U8_ALTIVEC(fsum, vfdst, vdst); - - vec_st(fsum, 0, dst); - - vsrc0ssH = vsrc2ssH; - vsrc1ssH = vsrc3ssH; - - dst += stride; - src += stride; - } + vsrc1uc = vec_perm(vsrcAuc, vsrcBuc, vsrcperm1); + + vsrc0ssH = (vec_s16_t)vec_mergeh(zero_u8v,(vec_u8_t)vsrc0uc); + vsrc1ssH = (vec_s16_t)vec_mergeh(zero_u8v,(vec_u8_t)vsrc1uc); + + if (ABCD[3]) { + if (!loadSecond) {// -> !reallyBadAlign + for (i = 0 ; i < h ; i++) { + vsrcCuc = vec_ld(stride + 0, src); + vsrc2uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0); + vsrc3uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1); + + CHROMA_MC8_ALTIVEC_CORE + } + } else { + vec_u8_t vsrcDuc; + for (i = 0 ; i < h ; i++) { + vsrcCuc = vec_ld(stride + 0, src); + vsrcDuc = vec_ld(stride + 16, src); + vsrc2uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0); + if (reallyBadAlign) + vsrc3uc = vsrcDuc; + else + vsrc3uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1); + + CHROMA_MC8_ALTIVEC_CORE + } + } } else { - vector unsigned char vsrcDuc; - for (i = 0 ; i < h ; i++) { - vsrcCuc = vec_ld(stride + 0, src); - vsrcDuc = vec_ld(stride + 16, src); - - vsrc2uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0); - if (reallyBadAlign) - vsrc3uc = vsrcDuc; - else - vsrc3uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1); - - vsrc2ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero, - (vector unsigned char)vsrc2uc); - vsrc3ssH = (vector signed short)vec_mergeh((vector unsigned char)vzero, - (vector unsigned char)vsrc3uc); - - psum = vec_mladd(vA, vsrc0ssH, vec_splat_s16(0)); - psum = vec_mladd(vB, vsrc1ssH, psum); - psum = vec_mladd(vC, vsrc2ssH, psum); - psum = vec_mladd(vD, vsrc3ssH, psum); - psum = vec_add(v32ss, psum); - psum = vec_sr(psum, v6us); - - vdst = vec_ld(0, dst); - ppsum = (vector unsigned char)vec_pack(psum, psum); - vfdst = vec_perm(vdst, ppsum, fperm); - - OP_U8_ALTIVEC(fsum, vfdst, vdst); - - vec_st(fsum, 0, dst); - - vsrc0ssH = vsrc2ssH; - vsrc1ssH = vsrc3ssH; - - dst += stride; - src += stride; - } + const vec_s16_t vE = vec_add(vB, vC); + if (ABCD[2]) { // x == 0 B == 0 + if (!loadSecond) {// -> !reallyBadAlign + for (i = 0 ; i < h ; i++) { + vsrcCuc = vec_ld(stride + 0, src); + vsrc1uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0); + CHROMA_MC8_ALTIVEC_CORE_SIMPLE + + vsrc0uc = vsrc1uc; + } + } else { + vec_u8_t vsrcDuc; + for (i = 0 ; i < h ; i++) { + vsrcCuc = vec_ld(stride + 0, src); + vsrcDuc = vec_ld(stride + 15, src); + vsrc1uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0); + CHROMA_MC8_ALTIVEC_CORE_SIMPLE + + vsrc0uc = vsrc1uc; + } + } + } else { // y == 0 C == 0 + if (!loadSecond) {// -> !reallyBadAlign + for (i = 0 ; i < h ; i++) { + vsrcCuc = vec_ld(0, src); + vsrc0uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm0); + vsrc1uc = vec_perm(vsrcCuc, vsrcCuc, vsrcperm1); + + CHROMA_MC8_ALTIVEC_CORE_SIMPLE + } + } else { + vec_u8_t vsrcDuc; + for (i = 0 ; i < h ; i++) { + vsrcCuc = vec_ld(0, src); + vsrcDuc = vec_ld(15, src); + vsrc0uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm0); + if (reallyBadAlign) + vsrc1uc = vsrcDuc; + else + vsrc1uc = vec_perm(vsrcCuc, vsrcDuc, vsrcperm1); + + CHROMA_MC8_ALTIVEC_CORE_SIMPLE + } + } + } } POWERPC_PERF_STOP_COUNT(PREFIX_h264_chroma_mc8_num, 1); } +#undef CHROMA_MC8_ALTIVEC_CORE + /* this code assume stride % 16 == 0 */ static void PREFIX_h264_qpel16_h_lowpass_altivec(uint8_t * dst, uint8_t * src, int dstStride, int srcStride) { POWERPC_PERF_DECLARE(PREFIX_h264_qpel16_h_lowpass_num, 1); register int i; - const vector signed int vzero = vec_splat_s32(0); - const vector unsigned char permM2 = vec_lvsl(-2, src); - const vector unsigned char permM1 = vec_lvsl(-1, src); - const vector unsigned char permP0 = vec_lvsl(+0, src); - const vector unsigned char permP1 = vec_lvsl(+1, src); - const vector unsigned char permP2 = vec_lvsl(+2, src); - const vector unsigned char permP3 = vec_lvsl(+3, src); - const vector signed short v5ss = vec_splat_s16(5); - const vector unsigned short v5us = vec_splat_u16(5); - const vector signed short v20ss = vec_sl(vec_splat_s16(5),vec_splat_u16(2)); - const vector signed short v16ss = vec_sl(vec_splat_s16(1),vec_splat_u16(4)); - const vector unsigned char dstperm = vec_lvsr(0, dst); - const vector unsigned char neg1 = - (const vector unsigned char) vec_splat_s8(-1); - - const vector unsigned char dstmask = - vec_perm((const vector unsigned char)vzero, - neg1, dstperm); - - vector unsigned char srcM2, srcM1, srcP0, srcP1, srcP2, srcP3; + LOAD_ZERO; + const vec_u8_t permM2 = vec_lvsl(-2, src); + const vec_u8_t permM1 = vec_lvsl(-1, src); + const vec_u8_t permP0 = vec_lvsl(+0, src); + const vec_u8_t permP1 = vec_lvsl(+1, src); + const vec_u8_t permP2 = vec_lvsl(+2, src); + const vec_u8_t permP3 = vec_lvsl(+3, src); + const vec_s16_t v5ss = vec_splat_s16(5); + const vec_u16_t v5us = vec_splat_u16(5); + const vec_s16_t v20ss = vec_sl(vec_splat_s16(5),vec_splat_u16(2)); + const vec_s16_t v16ss = vec_sl(vec_splat_s16(1),vec_splat_u16(4)); + + vec_u8_t srcM2, srcM1, srcP0, srcP1, srcP2, srcP3; register int align = ((((unsigned long)src) - 2) % 16); - vector signed short srcP0A, srcP0B, srcP1A, srcP1B, + vec_s16_t srcP0A, srcP0B, srcP1A, srcP1B, srcP2A, srcP2B, srcP3A, srcP3B, srcM1A, srcM1B, srcM2A, srcM2B, sum1A, sum1B, sum2A, sum2B, sum3A, sum3B, pp1A, pp1B, pp2A, pp2B, pp3A, pp3B, psumA, psumB, sumA, sumB; - vector unsigned char sum, dst1, dst2, vdst, fsum, - rsum, fdst1, fdst2; + vec_u8_t sum, vdst, fsum; POWERPC_PERF_START_COUNT(PREFIX_h264_qpel16_h_lowpass_num, 1); for (i = 0 ; i < 16 ; i ++) { - vector unsigned char srcR1 = vec_ld(-2, src); - vector unsigned char srcR2 = vec_ld(14, src); + vec_u8_t srcR1 = vec_ld(-2, src); + vec_u8_t srcR2 = vec_ld(14, src); switch (align) { default: { @@ -217,7 +258,7 @@ static void PREFIX_h264_qpel16_h_lowpass_altivec(uint8_t * dst, uint8_t * src, i srcP3 = srcR2; } break; case 12: { - vector unsigned char srcR3 = vec_ld(30, src); + vec_u8_t srcR3 = vec_ld(30, src); srcM2 = vec_perm(srcR1, srcR2, permM2); srcM1 = vec_perm(srcR1, srcR2, permM1); srcP0 = vec_perm(srcR1, srcR2, permP0); @@ -226,7 +267,7 @@ static void PREFIX_h264_qpel16_h_lowpass_altivec(uint8_t * dst, uint8_t * src, i srcP3 = vec_perm(srcR2, srcR3, permP3); } break; case 13: { - vector unsigned char srcR3 = vec_ld(30, src); + vec_u8_t srcR3 = vec_ld(30, src); srcM2 = vec_perm(srcR1, srcR2, permM2); srcM1 = vec_perm(srcR1, srcR2, permM1); srcP0 = vec_perm(srcR1, srcR2, permP0); @@ -235,7 +276,7 @@ static void PREFIX_h264_qpel16_h_lowpass_altivec(uint8_t * dst, uint8_t * src, i srcP3 = vec_perm(srcR2, srcR3, permP3); } break; case 14: { - vector unsigned char srcR3 = vec_ld(30, src); + vec_u8_t srcR3 = vec_ld(30, src); srcM2 = vec_perm(srcR1, srcR2, permM2); srcM1 = vec_perm(srcR1, srcR2, permM1); srcP0 = srcR2; @@ -244,7 +285,7 @@ static void PREFIX_h264_qpel16_h_lowpass_altivec(uint8_t * dst, uint8_t * src, i srcP3 = vec_perm(srcR2, srcR3, permP3); } break; case 15: { - vector unsigned char srcR3 = vec_ld(30, src); + vec_u8_t srcR3 = vec_ld(30, src); srcM2 = vec_perm(srcR1, srcR2, permM2); srcM1 = srcR2; srcP0 = vec_perm(srcR2, srcR3, permP0); @@ -254,32 +295,20 @@ static void PREFIX_h264_qpel16_h_lowpass_altivec(uint8_t * dst, uint8_t * src, i } break; } - srcP0A = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcP0); - srcP0B = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcP0); - srcP1A = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcP1); - srcP1B = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcP1); - - srcP2A = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcP2); - srcP2B = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcP2); - srcP3A = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcP3); - srcP3B = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcP3); - - srcM1A = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcM1); - srcM1B = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcM1); - srcM2A = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcM2); - srcM2B = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcM2); + srcP0A = (vec_s16_t) vec_mergeh(zero_u8v, srcP0); + srcP0B = (vec_s16_t) vec_mergel(zero_u8v, srcP0); + srcP1A = (vec_s16_t) vec_mergeh(zero_u8v, srcP1); + srcP1B = (vec_s16_t) vec_mergel(zero_u8v, srcP1); + + srcP2A = (vec_s16_t) vec_mergeh(zero_u8v, srcP2); + srcP2B = (vec_s16_t) vec_mergel(zero_u8v, srcP2); + srcP3A = (vec_s16_t) vec_mergeh(zero_u8v, srcP3); + srcP3B = (vec_s16_t) vec_mergel(zero_u8v, srcP3); + + srcM1A = (vec_s16_t) vec_mergeh(zero_u8v, srcM1); + srcM1B = (vec_s16_t) vec_mergel(zero_u8v, srcM1); + srcM2A = (vec_s16_t) vec_mergeh(zero_u8v, srcM2); + srcM2B = (vec_s16_t) vec_mergel(zero_u8v, srcM2); sum1A = vec_adds(srcP0A, srcP1A); sum1B = vec_adds(srcP0B, srcP1B); @@ -291,8 +320,8 @@ static void PREFIX_h264_qpel16_h_lowpass_altivec(uint8_t * dst, uint8_t * src, i pp1A = vec_mladd(sum1A, v20ss, v16ss); pp1B = vec_mladd(sum1B, v20ss, v16ss); - pp2A = vec_mladd(sum2A, v5ss, (vector signed short)vzero); - pp2B = vec_mladd(sum2B, v5ss, (vector signed short)vzero); + pp2A = vec_mladd(sum2A, v5ss, zero_s16v); + pp2B = vec_mladd(sum2B, v5ss, zero_s16v); pp3A = vec_add(sum3A, pp1A); pp3B = vec_add(sum3B, pp1B); @@ -305,18 +334,12 @@ static void PREFIX_h264_qpel16_h_lowpass_altivec(uint8_t * dst, uint8_t * src, i sum = vec_packsu(sumA, sumB); - dst1 = vec_ld(0, dst); - dst2 = vec_ld(16, dst); - vdst = vec_perm(dst1, dst2, vec_lvsl(0, dst)); + ASSERT_ALIGNED(dst); + vdst = vec_ld(0, dst); OP_U8_ALTIVEC(fsum, sum, vdst); - rsum = vec_perm(fsum, fsum, dstperm); - fdst1 = vec_sel(dst1, rsum, dstmask); - fdst2 = vec_sel(rsum, dst2, dstmask); - - vec_st(fdst1, 0, dst); - vec_st(fdst2, 16, dst); + vec_st(fsum, 0, dst); src += srcStride; dst += dstStride; @@ -330,67 +353,53 @@ static void PREFIX_h264_qpel16_v_lowpass_altivec(uint8_t * dst, uint8_t * src, i register int i; - const vector signed int vzero = vec_splat_s32(0); - const vector unsigned char perm = vec_lvsl(0, src); - const vector signed short v20ss = vec_sl(vec_splat_s16(5),vec_splat_u16(2)); - const vector unsigned short v5us = vec_splat_u16(5); - const vector signed short v5ss = vec_splat_s16(5); - const vector signed short v16ss = vec_sl(vec_splat_s16(1),vec_splat_u16(4)); - const vector unsigned char dstperm = vec_lvsr(0, dst); - const vector unsigned char neg1 = (const vector unsigned char)vec_splat_s8(-1); - const vector unsigned char dstmask = vec_perm((const vector unsigned char)vzero, neg1, dstperm); + LOAD_ZERO; + const vec_u8_t perm = vec_lvsl(0, src); + const vec_s16_t v20ss = vec_sl(vec_splat_s16(5),vec_splat_u16(2)); + const vec_u16_t v5us = vec_splat_u16(5); + const vec_s16_t v5ss = vec_splat_s16(5); + const vec_s16_t v16ss = vec_sl(vec_splat_s16(1),vec_splat_u16(4)); uint8_t *srcbis = src - (srcStride * 2); - const vector unsigned char srcM2a = vec_ld(0, srcbis); - const vector unsigned char srcM2b = vec_ld(16, srcbis); - const vector unsigned char srcM2 = vec_perm(srcM2a, srcM2b, perm); + const vec_u8_t srcM2a = vec_ld(0, srcbis); + const vec_u8_t srcM2b = vec_ld(16, srcbis); + const vec_u8_t srcM2 = vec_perm(srcM2a, srcM2b, perm); // srcbis += srcStride; - const vector unsigned char srcM1a = vec_ld(0, srcbis += srcStride); - const vector unsigned char srcM1b = vec_ld(16, srcbis); - const vector unsigned char srcM1 = vec_perm(srcM1a, srcM1b, perm); + const vec_u8_t srcM1a = vec_ld(0, srcbis += srcStride); + const vec_u8_t srcM1b = vec_ld(16, srcbis); + const vec_u8_t srcM1 = vec_perm(srcM1a, srcM1b, perm); // srcbis += srcStride; - const vector unsigned char srcP0a = vec_ld(0, srcbis += srcStride); - const vector unsigned char srcP0b = vec_ld(16, srcbis); - const vector unsigned char srcP0 = vec_perm(srcP0a, srcP0b, perm); + const vec_u8_t srcP0a = vec_ld(0, srcbis += srcStride); + const vec_u8_t srcP0b = vec_ld(16, srcbis); + const vec_u8_t srcP0 = vec_perm(srcP0a, srcP0b, perm); // srcbis += srcStride; - const vector unsigned char srcP1a = vec_ld(0, srcbis += srcStride); - const vector unsigned char srcP1b = vec_ld(16, srcbis); - const vector unsigned char srcP1 = vec_perm(srcP1a, srcP1b, perm); + const vec_u8_t srcP1a = vec_ld(0, srcbis += srcStride); + const vec_u8_t srcP1b = vec_ld(16, srcbis); + const vec_u8_t srcP1 = vec_perm(srcP1a, srcP1b, perm); // srcbis += srcStride; - const vector unsigned char srcP2a = vec_ld(0, srcbis += srcStride); - const vector unsigned char srcP2b = vec_ld(16, srcbis); - const vector unsigned char srcP2 = vec_perm(srcP2a, srcP2b, perm); + const vec_u8_t srcP2a = vec_ld(0, srcbis += srcStride); + const vec_u8_t srcP2b = vec_ld(16, srcbis); + const vec_u8_t srcP2 = vec_perm(srcP2a, srcP2b, perm); // srcbis += srcStride; - vector signed short srcM2ssA = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcM2); - vector signed short srcM2ssB = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcM2); - vector signed short srcM1ssA = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcM1); - vector signed short srcM1ssB = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcM1); - vector signed short srcP0ssA = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcP0); - vector signed short srcP0ssB = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcP0); - vector signed short srcP1ssA = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcP1); - vector signed short srcP1ssB = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcP1); - vector signed short srcP2ssA = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcP2); - vector signed short srcP2ssB = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcP2); - - vector signed short pp1A, pp1B, pp2A, pp2B, pp3A, pp3B, + vec_s16_t srcM2ssA = (vec_s16_t) vec_mergeh(zero_u8v, srcM2); + vec_s16_t srcM2ssB = (vec_s16_t) vec_mergel(zero_u8v, srcM2); + vec_s16_t srcM1ssA = (vec_s16_t) vec_mergeh(zero_u8v, srcM1); + vec_s16_t srcM1ssB = (vec_s16_t) vec_mergel(zero_u8v, srcM1); + vec_s16_t srcP0ssA = (vec_s16_t) vec_mergeh(zero_u8v, srcP0); + vec_s16_t srcP0ssB = (vec_s16_t) vec_mergel(zero_u8v, srcP0); + vec_s16_t srcP1ssA = (vec_s16_t) vec_mergeh(zero_u8v, srcP1); + vec_s16_t srcP1ssB = (vec_s16_t) vec_mergel(zero_u8v, srcP1); + vec_s16_t srcP2ssA = (vec_s16_t) vec_mergeh(zero_u8v, srcP2); + vec_s16_t srcP2ssB = (vec_s16_t) vec_mergel(zero_u8v, srcP2); + + vec_s16_t pp1A, pp1B, pp2A, pp2B, pp3A, pp3B, psumA, psumB, sumA, sumB, srcP3ssA, srcP3ssB, sum1A, sum1B, sum2A, sum2B, sum3A, sum3B; - vector unsigned char sum, dst1, dst2, vdst, fsum, rsum, fdst1, fdst2, - srcP3a, srcP3b, srcP3; + vec_u8_t sum, vdst, fsum, srcP3a, srcP3b, srcP3; POWERPC_PERF_START_COUNT(PREFIX_h264_qpel16_v_lowpass_num, 1); @@ -398,10 +407,8 @@ static void PREFIX_h264_qpel16_v_lowpass_altivec(uint8_t * dst, uint8_t * src, i srcP3a = vec_ld(0, srcbis += srcStride); srcP3b = vec_ld(16, srcbis); srcP3 = vec_perm(srcP3a, srcP3b, perm); - srcP3ssA = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcP3); - srcP3ssB = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcP3); + srcP3ssA = (vec_s16_t) vec_mergeh(zero_u8v, srcP3); + srcP3ssB = (vec_s16_t) vec_mergel(zero_u8v, srcP3); // srcbis += srcStride; sum1A = vec_adds(srcP0ssA, srcP1ssA); @@ -425,8 +432,8 @@ static void PREFIX_h264_qpel16_v_lowpass_altivec(uint8_t * dst, uint8_t * src, i pp1A = vec_mladd(sum1A, v20ss, v16ss); pp1B = vec_mladd(sum1B, v20ss, v16ss); - pp2A = vec_mladd(sum2A, v5ss, (vector signed short)vzero); - pp2B = vec_mladd(sum2B, v5ss, (vector signed short)vzero); + pp2A = vec_mladd(sum2A, v5ss, zero_s16v); + pp2B = vec_mladd(sum2B, v5ss, zero_s16v); pp3A = vec_add(sum3A, pp1A); pp3B = vec_add(sum3B, pp1B); @@ -439,18 +446,12 @@ static void PREFIX_h264_qpel16_v_lowpass_altivec(uint8_t * dst, uint8_t * src, i sum = vec_packsu(sumA, sumB); - dst1 = vec_ld(0, dst); - dst2 = vec_ld(16, dst); - vdst = vec_perm(dst1, dst2, vec_lvsl(0, dst)); + ASSERT_ALIGNED(dst); + vdst = vec_ld(0, dst); OP_U8_ALTIVEC(fsum, sum, vdst); - rsum = vec_perm(fsum, fsum, dstperm); - fdst1 = vec_sel(dst1, rsum, dstmask); - fdst2 = vec_sel(rsum, dst2, dstmask); - - vec_st(fdst1, 0, dst); - vec_st(fdst2, 16, dst); + vec_st(fsum, 0, dst); dst += dstStride; } @@ -461,58 +462,50 @@ static void PREFIX_h264_qpel16_v_lowpass_altivec(uint8_t * dst, uint8_t * src, i static void PREFIX_h264_qpel16_hv_lowpass_altivec(uint8_t * dst, int16_t * tmp, uint8_t * src, int dstStride, int tmpStride, int srcStride) { POWERPC_PERF_DECLARE(PREFIX_h264_qpel16_hv_lowpass_num, 1); register int i; - const vector signed int vzero = vec_splat_s32(0); - const vector unsigned char permM2 = vec_lvsl(-2, src); - const vector unsigned char permM1 = vec_lvsl(-1, src); - const vector unsigned char permP0 = vec_lvsl(+0, src); - const vector unsigned char permP1 = vec_lvsl(+1, src); - const vector unsigned char permP2 = vec_lvsl(+2, src); - const vector unsigned char permP3 = vec_lvsl(+3, src); - const vector signed short v20ss = vec_sl(vec_splat_s16(5),vec_splat_u16(2)); - const vector unsigned int v10ui = vec_splat_u32(10); - const vector signed short v5ss = vec_splat_s16(5); - const vector signed short v1ss = vec_splat_s16(1); - const vector signed int v512si = vec_sl(vec_splat_s32(1),vec_splat_u32(9)); - const vector unsigned int v16ui = vec_sl(vec_splat_u32(1),vec_splat_u32(4)); + LOAD_ZERO; + const vec_u8_t permM2 = vec_lvsl(-2, src); + const vec_u8_t permM1 = vec_lvsl(-1, src); + const vec_u8_t permP0 = vec_lvsl(+0, src); + const vec_u8_t permP1 = vec_lvsl(+1, src); + const vec_u8_t permP2 = vec_lvsl(+2, src); + const vec_u8_t permP3 = vec_lvsl(+3, src); + const vec_s16_t v20ss = vec_sl(vec_splat_s16(5),vec_splat_u16(2)); + const vec_u32_t v10ui = vec_splat_u32(10); + const vec_s16_t v5ss = vec_splat_s16(5); + const vec_s16_t v1ss = vec_splat_s16(1); + const vec_s32_t v512si = vec_sl(vec_splat_s32(1),vec_splat_u32(9)); + const vec_u32_t v16ui = vec_sl(vec_splat_u32(1),vec_splat_u32(4)); register int align = ((((unsigned long)src) - 2) % 16); - const vector unsigned char neg1 = (const vector unsigned char) - vec_splat_s8(-1); - - vector signed short srcP0A, srcP0B, srcP1A, srcP1B, + vec_s16_t srcP0A, srcP0B, srcP1A, srcP1B, srcP2A, srcP2B, srcP3A, srcP3B, srcM1A, srcM1B, srcM2A, srcM2B, sum1A, sum1B, sum2A, sum2B, sum3A, sum3B, pp1A, pp1B, pp2A, pp2B, psumA, psumB; - const vector unsigned char dstperm = vec_lvsr(0, dst); - - const vector unsigned char dstmask = vec_perm((const vector unsigned char)vzero, neg1, dstperm); - - const vector unsigned char mperm = (const vector unsigned char) + const vec_u8_t mperm = (const vec_u8_t) AVV(0x00, 0x08, 0x01, 0x09, 0x02, 0x0A, 0x03, 0x0B, 0x04, 0x0C, 0x05, 0x0D, 0x06, 0x0E, 0x07, 0x0F); int16_t *tmpbis = tmp; - vector signed short tmpM1ssA, tmpM1ssB, tmpM2ssA, tmpM2ssB, + vec_s16_t tmpM1ssA, tmpM1ssB, tmpM2ssA, tmpM2ssB, tmpP0ssA, tmpP0ssB, tmpP1ssA, tmpP1ssB, tmpP2ssA, tmpP2ssB; - vector signed int pp1Ae, pp1Ao, pp1Be, pp1Bo, pp2Ae, pp2Ao, pp2Be, pp2Bo, + vec_s32_t pp1Ae, pp1Ao, pp1Be, pp1Bo, pp2Ae, pp2Ao, pp2Be, pp2Bo, pp3Ae, pp3Ao, pp3Be, pp3Bo, pp1cAe, pp1cAo, pp1cBe, pp1cBo, pp32Ae, pp32Ao, pp32Be, pp32Bo, sumAe, sumAo, sumBe, sumBo, ssumAe, ssumAo, ssumBe, ssumBo; - vector unsigned char fsum, sumv, sum, dst1, dst2, vdst, - rsum, fdst1, fdst2; - vector signed short ssume, ssumo; + vec_u8_t fsum, sumv, sum, vdst; + vec_s16_t ssume, ssumo; POWERPC_PERF_START_COUNT(PREFIX_h264_qpel16_hv_lowpass_num, 1); src -= (2 * srcStride); for (i = 0 ; i < 21 ; i ++) { - vector unsigned char srcM2, srcM1, srcP0, srcP1, srcP2, srcP3; - vector unsigned char srcR1 = vec_ld(-2, src); - vector unsigned char srcR2 = vec_ld(14, src); + vec_u8_t srcM2, srcM1, srcP0, srcP1, srcP2, srcP3; + vec_u8_t srcR1 = vec_ld(-2, src); + vec_u8_t srcR2 = vec_ld(14, src); switch (align) { default: { @@ -532,7 +525,7 @@ static void PREFIX_h264_qpel16_hv_lowpass_altivec(uint8_t * dst, int16_t * tmp, srcP3 = srcR2; } break; case 12: { - vector unsigned char srcR3 = vec_ld(30, src); + vec_u8_t srcR3 = vec_ld(30, src); srcM2 = vec_perm(srcR1, srcR2, permM2); srcM1 = vec_perm(srcR1, srcR2, permM1); srcP0 = vec_perm(srcR1, srcR2, permP0); @@ -541,7 +534,7 @@ static void PREFIX_h264_qpel16_hv_lowpass_altivec(uint8_t * dst, int16_t * tmp, srcP3 = vec_perm(srcR2, srcR3, permP3); } break; case 13: { - vector unsigned char srcR3 = vec_ld(30, src); + vec_u8_t srcR3 = vec_ld(30, src); srcM2 = vec_perm(srcR1, srcR2, permM2); srcM1 = vec_perm(srcR1, srcR2, permM1); srcP0 = vec_perm(srcR1, srcR2, permP0); @@ -550,7 +543,7 @@ static void PREFIX_h264_qpel16_hv_lowpass_altivec(uint8_t * dst, int16_t * tmp, srcP3 = vec_perm(srcR2, srcR3, permP3); } break; case 14: { - vector unsigned char srcR3 = vec_ld(30, src); + vec_u8_t srcR3 = vec_ld(30, src); srcM2 = vec_perm(srcR1, srcR2, permM2); srcM1 = vec_perm(srcR1, srcR2, permM1); srcP0 = srcR2; @@ -559,7 +552,7 @@ static void PREFIX_h264_qpel16_hv_lowpass_altivec(uint8_t * dst, int16_t * tmp, srcP3 = vec_perm(srcR2, srcR3, permP3); } break; case 15: { - vector unsigned char srcR3 = vec_ld(30, src); + vec_u8_t srcR3 = vec_ld(30, src); srcM2 = vec_perm(srcR1, srcR2, permM2); srcM1 = srcR2; srcP0 = vec_perm(srcR2, srcR3, permP0); @@ -569,32 +562,20 @@ static void PREFIX_h264_qpel16_hv_lowpass_altivec(uint8_t * dst, int16_t * tmp, } break; } - srcP0A = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcP0); - srcP0B = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcP0); - srcP1A = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcP1); - srcP1B = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcP1); - - srcP2A = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcP2); - srcP2B = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcP2); - srcP3A = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcP3); - srcP3B = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcP3); - - srcM1A = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcM1); - srcM1B = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcM1); - srcM2A = (vector signed short) - vec_mergeh((vector unsigned char)vzero, srcM2); - srcM2B = (vector signed short) - vec_mergel((vector unsigned char)vzero, srcM2); + srcP0A = (vec_s16_t) vec_mergeh(zero_u8v, srcP0); + srcP0B = (vec_s16_t) vec_mergel(zero_u8v, srcP0); + srcP1A = (vec_s16_t) vec_mergeh(zero_u8v, srcP1); + srcP1B = (vec_s16_t) vec_mergel(zero_u8v, srcP1); + + srcP2A = (vec_s16_t) vec_mergeh(zero_u8v, srcP2); + srcP2B = (vec_s16_t) vec_mergel(zero_u8v, srcP2); + srcP3A = (vec_s16_t) vec_mergeh(zero_u8v, srcP3); + srcP3B = (vec_s16_t) vec_mergel(zero_u8v, srcP3); + + srcM1A = (vec_s16_t) vec_mergeh(zero_u8v, srcM1); + srcM1B = (vec_s16_t) vec_mergel(zero_u8v, srcM1); + srcM2A = (vec_s16_t) vec_mergeh(zero_u8v, srcM2); + srcM2B = (vec_s16_t) vec_mergel(zero_u8v, srcM2); sum1A = vec_adds(srcP0A, srcP1A); sum1B = vec_adds(srcP0B, srcP1B); @@ -606,8 +587,8 @@ static void PREFIX_h264_qpel16_hv_lowpass_altivec(uint8_t * dst, int16_t * tmp, pp1A = vec_mladd(sum1A, v20ss, sum3A); pp1B = vec_mladd(sum1B, v20ss, sum3B); - pp2A = vec_mladd(sum2A, v5ss, (vector signed short)vzero); - pp2B = vec_mladd(sum2B, v5ss, (vector signed short)vzero); + pp2A = vec_mladd(sum2A, v5ss, zero_s16v); + pp2B = vec_mladd(sum2B, v5ss, zero_s16v); psumA = vec_sub(pp1A, pp2A); psumB = vec_sub(pp1B, pp2B); @@ -636,15 +617,15 @@ static void PREFIX_h264_qpel16_hv_lowpass_altivec(uint8_t * dst, int16_t * tmp, tmpbis += tmpStride; for (i = 0 ; i < 16 ; i++) { - const vector signed short tmpP3ssA = vec_ld(0, tmpbis); - const vector signed short tmpP3ssB = vec_ld(16, tmpbis); + const vec_s16_t tmpP3ssA = vec_ld(0, tmpbis); + const vec_s16_t tmpP3ssB = vec_ld(16, tmpbis); - const vector signed short sum1A = vec_adds(tmpP0ssA, tmpP1ssA); - const vector signed short sum1B = vec_adds(tmpP0ssB, tmpP1ssB); - const vector signed short sum2A = vec_adds(tmpM1ssA, tmpP2ssA); - const vector signed short sum2B = vec_adds(tmpM1ssB, tmpP2ssB); - const vector signed short sum3A = vec_adds(tmpM2ssA, tmpP3ssA); - const vector signed short sum3B = vec_adds(tmpM2ssB, tmpP3ssB); + const vec_s16_t sum1A = vec_adds(tmpP0ssA, tmpP1ssA); + const vec_s16_t sum1B = vec_adds(tmpP0ssB, tmpP1ssB); + const vec_s16_t sum2A = vec_adds(tmpM1ssA, tmpP2ssA); + const vec_s16_t sum2B = vec_adds(tmpM1ssB, tmpP2ssB); + const vec_s16_t sum3A = vec_adds(tmpM2ssA, tmpP3ssA); + const vec_s16_t sum3B = vec_adds(tmpM2ssB, tmpP3ssB); tmpbis += tmpStride; @@ -669,9 +650,9 @@ static void PREFIX_h264_qpel16_hv_lowpass_altivec(uint8_t * dst, int16_t * tmp, pp2Be = vec_mule(sum2B, v5ss); pp2Bo = vec_mulo(sum2B, v5ss); - pp3Ae = vec_sra((vector signed int)sum3A, v16ui); + pp3Ae = vec_sra((vec_s32_t)sum3A, v16ui); pp3Ao = vec_mulo(sum3A, v1ss); - pp3Be = vec_sra((vector signed int)sum3B, v16ui); + pp3Be = vec_sra((vec_s32_t)sum3B, v16ui); pp3Bo = vec_mulo(sum3B, v1ss); pp1cAe = vec_add(pp1Ae, v512si); @@ -700,18 +681,12 @@ static void PREFIX_h264_qpel16_hv_lowpass_altivec(uint8_t * dst, int16_t * tmp, sumv = vec_packsu(ssume, ssumo); sum = vec_perm(sumv, sumv, mperm); - dst1 = vec_ld(0, dst); - dst2 = vec_ld(16, dst); - vdst = vec_perm(dst1, dst2, vec_lvsl(0, dst)); + ASSERT_ALIGNED(dst); + vdst = vec_ld(0, dst); OP_U8_ALTIVEC(fsum, sum, vdst); - rsum = vec_perm(fsum, fsum, dstperm); - fdst1 = vec_sel(dst1, rsum, dstmask); - fdst2 = vec_sel(rsum, dst2, dstmask); - - vec_st(fdst1, 0, dst); - vec_st(fdst2, 16, dst); + vec_st(fsum, 0, dst); dst += dstStride; } diff --git a/contrib/ffmpeg/libavcodec/ppc/idct_altivec.c b/contrib/ffmpeg/libavcodec/ppc/idct_altivec.c index 66c8082f7..37b2f62c3 100644 --- a/contrib/ffmpeg/libavcodec/ppc/idct_altivec.c +++ b/contrib/ffmpeg/libavcodec/ppc/idct_altivec.c @@ -16,7 +16,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /* @@ -39,14 +38,14 @@ #include /* malloc(), free() */ #include -#include "../dsputil.h" +#include "dsputil.h" #include "gcc_fixes.h" -#include "dsputil_altivec.h" +#include "dsputil_ppc.h" #define vector_s16_t vector signed short -#define const_vector_s16_t const_vector signed short +#define const_vector_s16_t const vector signed short #define vector_u16_t vector unsigned short #define vector_s8_t vector signed char #define vector_u8_t vector unsigned char diff --git a/contrib/ffmpeg/libavcodec/ppc/imgresample_altivec.c b/contrib/ffmpeg/libavcodec/ppc/imgresample_altivec.c new file mode 100644 index 000000000..3b161c5a6 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/ppc/imgresample_altivec.c @@ -0,0 +1,153 @@ +/* + * High quality image resampling with polyphase filters + * Copyright (c) 2001 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file imgresample_altivec.c + * High quality image resampling with polyphase filters - AltiVec bits + */ + +#include "gcc_fixes.h" + +typedef union { + vector unsigned char v; + unsigned char c[16]; +} vec_uc_t; + +typedef union { + vector signed short v; + signed short s[8]; +} vec_ss_t; + +void v_resample16_altivec(uint8_t *dst, int dst_width, const uint8_t *src, + int wrap, int16_t *filter) +{ + int sum, i; + const uint8_t *s; + vector unsigned char *tv, tmp, dstv, zero; + vec_ss_t srchv[4], srclv[4], fv[4]; + vector signed short zeros, sumhv, sumlv; + s = src; + + for(i=0;i<4;i++) + { + /* + The vec_madds later on does an implicit >>15 on the result. + Since FILTER_BITS is 8, and we have 15 bits of magnitude in + a signed short, we have just enough bits to pre-shift our + filter constants <<7 to compensate for vec_madds. + */ + fv[i].s[0] = filter[i] << (15-FILTER_BITS); + fv[i].v = vec_splat(fv[i].v, 0); + } + + zero = vec_splat_u8(0); + zeros = vec_splat_s16(0); + + + /* + When we're resampling, we'd ideally like both our input buffers, + and output buffers to be 16-byte aligned, so we can do both aligned + reads and writes. Sadly we can't always have this at the moment, so + we opt for aligned writes, as unaligned writes have a huge overhead. + To do this, do enough scalar resamples to get dst 16-byte aligned. + */ + i = (-(int)dst) & 0xf; + while(i>0) { + sum = s[0 * wrap] * filter[0] + + s[1 * wrap] * filter[1] + + s[2 * wrap] * filter[2] + + s[3 * wrap] * filter[3]; + sum = sum >> FILTER_BITS; + if (sum<0) sum = 0; else if (sum>255) sum=255; + dst[0] = sum; + dst++; + s++; + dst_width--; + i--; + } + + /* Do our altivec resampling on 16 pixels at once. */ + while(dst_width>=16) { + /* + Read 16 (potentially unaligned) bytes from each of + 4 lines into 4 vectors, and split them into shorts. + Interleave the multipy/accumulate for the resample + filter with the loads to hide the 3 cycle latency + the vec_madds have. + */ + tv = (vector unsigned char *) &s[0 * wrap]; + tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[i * wrap])); + srchv[0].v = (vector signed short) vec_mergeh(zero, tmp); + srclv[0].v = (vector signed short) vec_mergel(zero, tmp); + sumhv = vec_madds(srchv[0].v, fv[0].v, zeros); + sumlv = vec_madds(srclv[0].v, fv[0].v, zeros); + + tv = (vector unsigned char *) &s[1 * wrap]; + tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[1 * wrap])); + srchv[1].v = (vector signed short) vec_mergeh(zero, tmp); + srclv[1].v = (vector signed short) vec_mergel(zero, tmp); + sumhv = vec_madds(srchv[1].v, fv[1].v, sumhv); + sumlv = vec_madds(srclv[1].v, fv[1].v, sumlv); + + tv = (vector unsigned char *) &s[2 * wrap]; + tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[2 * wrap])); + srchv[2].v = (vector signed short) vec_mergeh(zero, tmp); + srclv[2].v = (vector signed short) vec_mergel(zero, tmp); + sumhv = vec_madds(srchv[2].v, fv[2].v, sumhv); + sumlv = vec_madds(srclv[2].v, fv[2].v, sumlv); + + tv = (vector unsigned char *) &s[3 * wrap]; + tmp = vec_perm(tv[0], tv[1], vec_lvsl(0, &s[3 * wrap])); + srchv[3].v = (vector signed short) vec_mergeh(zero, tmp); + srclv[3].v = (vector signed short) vec_mergel(zero, tmp); + sumhv = vec_madds(srchv[3].v, fv[3].v, sumhv); + sumlv = vec_madds(srclv[3].v, fv[3].v, sumlv); + + /* + Pack the results into our destination vector, + and do an aligned write of that back to memory. + */ + dstv = vec_packsu(sumhv, sumlv) ; + vec_st(dstv, 0, (vector unsigned char *) dst); + + dst+=16; + s+=16; + dst_width-=16; + } + + /* + If there are any leftover pixels, resample them + with the slow scalar method. + */ + while(dst_width>0) { + sum = s[0 * wrap] * filter[0] + + s[1 * wrap] * filter[1] + + s[2 * wrap] * filter[2] + + s[3 * wrap] * filter[3]; + sum = sum >> FILTER_BITS; + if (sum<0) sum = 0; else if (sum>255) sum=255; + dst[0] = sum; + dst++; + s++; + dst_width--; + } +} + diff --git a/contrib/ffmpeg/libavcodec/ppc/imgresample_altivec.h b/contrib/ffmpeg/libavcodec/ppc/imgresample_altivec.h new file mode 100644 index 000000000..538c1bee6 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/ppc/imgresample_altivec.h @@ -0,0 +1,26 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_IMGRESAMPLE_ALTIVEC_H +#define FFMPEG_IMGRESAMPLE_ALTIVEC_H + +#include + +void v_resample16_altivec(uint8_t *dst, int dst_width, const uint8_t *src, + int wrap, int16_t *filter); +#endif /* FFMPEG_IMGRESAMPLE_ALTIVEC_H */ diff --git a/contrib/ffmpeg/libavcodec/ppc/int_altivec.c b/contrib/ffmpeg/libavcodec/ppc/int_altivec.c new file mode 100644 index 000000000..95497c99a --- /dev/null +++ b/contrib/ffmpeg/libavcodec/ppc/int_altivec.c @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2007 Luca Barbato + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + ** @file int_altivec.c + ** integer misc ops. + **/ + +#include "dsputil.h" + +#include "gcc_fixes.h" + +#include "dsputil_altivec.h" + +static int ssd_int8_vs_int16_altivec(const int8_t *pix1, const int16_t *pix2, + int size) { + int i, size16; + vector signed char vpix1; + vector signed short vpix2, vdiff, vpix1l,vpix1h; + union { vector signed int vscore; + int32_t score[4]; + } u; + u.vscore = vec_splat_s32(0); +// +//XXX lazy way, fix it later + +#define vec_unaligned_load(b) \ + vec_perm(vec_ld(0,b),vec_ld(15,b),vec_lvsl(0, b)); + + size16 = size >> 4; + while(size16) { +// score += (pix1[i]-pix2[i])*(pix1[i]-pix2[i]); + //load pix1 and the first batch of pix2 + + vpix1 = vec_unaligned_load(pix1); + vpix2 = vec_unaligned_load(pix2); + pix2 += 8; + //unpack + vpix1h = vec_unpackh(vpix1); + vdiff = vec_sub(vpix1h, vpix2); + vpix1l = vec_unpackl(vpix1); + // load another batch from pix2 + vpix2 = vec_unaligned_load(pix2); + u.vscore = vec_msum(vdiff, vdiff, u.vscore); + vdiff = vec_sub(vpix1l, vpix2); + u.vscore = vec_msum(vdiff, vdiff, u.vscore); + pix1 += 16; + pix2 += 8; + size16--; + } + u.vscore = vec_sums(u.vscore, vec_splat_s32(0)); + + size %= 16; + for (i = 0; i < size; i++) { + u.score[3] += (pix1[i]-pix2[i])*(pix1[i]-pix2[i]); + } + return u.score[3]; +} + +void int_init_altivec(DSPContext* c, AVCodecContext *avctx) +{ + c->ssd_int8_vs_int16 = ssd_int8_vs_int16_altivec; +} diff --git a/contrib/ffmpeg/libavcodec/ppc/mathops.h b/contrib/ffmpeg/libavcodec/ppc/mathops.h index 6af23f246..d7cc85365 100644 --- a/contrib/ffmpeg/libavcodec/ppc/mathops.h +++ b/contrib/ffmpeg/libavcodec/ppc/mathops.h @@ -20,6 +20,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef FFMPEG_PPC_MATHOPS_H +#define FFMPEG_PPC_MATHOPS_H + #if defined(ARCH_POWERPC_405) /* signed 16x16 -> 32 multiply add accumulate */ # define MAC16(rt, ra, rb) \ @@ -31,3 +34,5 @@ asm ("mullhw %0, %1, %2" : "=r" (__rt) : "r" (ra), "r" (rb)); __rt; }) #endif + +#endif /* FFMPEG_PPC_MATHOPS_H */ diff --git a/contrib/ffmpeg/libavcodec/ppc/mpegvideo_altivec.c b/contrib/ffmpeg/libavcodec/ppc/mpegvideo_altivec.c index 3822cb20e..a2ba5e125 100644 --- a/contrib/ffmpeg/libavcodec/ppc/mpegvideo_altivec.c +++ b/contrib/ffmpeg/libavcodec/ppc/mpegvideo_altivec.c @@ -23,13 +23,13 @@ #include #include -#include "../dsputil.h" -#include "../mpegvideo.h" +#include "dsputil.h" +#include "mpegvideo.h" #include "gcc_fixes.h" -#include "dsputil_altivec.h" - +#include "dsputil_ppc.h" +#include "util_altivec.h" // Swaps two variables (used for altivec registers) #define SWAP(a,b) \ do { \ @@ -66,12 +66,8 @@ do { \ } -#ifdef CONFIG_DARWIN -#define FOUROF(a) (a) -#else -// slower, for dumb non-apple GCC -#define FOUROF(a) {a,a,a,a} -#endif +#define FOUROF(a) AVV(a,a,a,a) + int dct_quantize_altivec(MpegEncContext* s, DCTELEM* data, int n, int qscale, int* overflow) @@ -79,8 +75,8 @@ int dct_quantize_altivec(MpegEncContext* s, int lastNonZero; vector float row0, row1, row2, row3, row4, row5, row6, row7; vector float alt0, alt1, alt2, alt3, alt4, alt5, alt6, alt7; - const_vector float zero = (const_vector float)FOUROF(0.); - // used after quantise step + const vector float zero = (const vector float)FOUROF(0.); + // used after quantize step int oldBaseValue = 0; // Load the data into the row/alt vectors @@ -258,7 +254,7 @@ int dct_quantize_altivec(MpegEncContext* s, } } - // perform the quantise step, using the floating point data + // perform the quantize step, using the floating point data // still in the row/alt registers { const int* biasAddr; @@ -474,7 +470,7 @@ int dct_quantize_altivec(MpegEncContext* s, data[0] = (oldBaseValue + 4) >> 3; } - // We handled the tranpose permutation above and we don't + // We handled the transpose permutation above and we don't // need to permute the "no" permutation case. if ((lastNonZero > 0) && (s->dsp.idct_permutation_type != FF_TRANSPOSE_IDCT_PERM) && @@ -486,7 +482,6 @@ int dct_quantize_altivec(MpegEncContext* s, return lastNonZero; } -#undef FOUROF /* AltiVec version of dct_unquantize_h263 @@ -515,25 +510,25 @@ POWERPC_PERF_START_COUNT(altivec_dct_unquantize_h263_num, 1); }else qadd = 0; i = 1; - nCoeffs= 63; //does not allways use zigzag table + nCoeffs= 63; //does not always use zigzag table } else { i = 0; nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ]; } { - register const_vector signed short vczero = (const_vector signed short)vec_splat_s16(0); - short __attribute__ ((aligned(16))) qmul8[] = + register const vector signed short vczero = (const vector signed short)vec_splat_s16(0); + DECLARE_ALIGNED_16(short, qmul8[]) = { qmul, qmul, qmul, qmul, qmul, qmul, qmul, qmul }; - short __attribute__ ((aligned(16))) qadd8[] = + DECLARE_ALIGNED_16(short, qadd8[]) = { qadd, qadd, qadd, qadd, qadd, qadd, qadd, qadd }; - short __attribute__ ((aligned(16))) nqadd8[] = + DECLARE_ALIGNED_16(short, nqadd8[]) = { -qadd, -qadd, -qadd, -qadd, -qadd, -qadd, -qadd, -qadd @@ -601,3 +596,50 @@ POWERPC_PERF_START_COUNT(altivec_dct_unquantize_h263_num, 1); } POWERPC_PERF_STOP_COUNT(altivec_dct_unquantize_h263_num, nCoeffs == 63); } + + +extern void idct_put_altivec(uint8_t *dest, int line_size, int16_t *block); +extern void idct_add_altivec(uint8_t *dest, int line_size, int16_t *block); + +void MPV_common_init_altivec(MpegEncContext *s) +{ + if ((mm_flags & MM_ALTIVEC) == 0) return; + + if (s->avctx->lowres==0) + { + if ((s->avctx->idct_algo == FF_IDCT_AUTO) || + (s->avctx->idct_algo == FF_IDCT_ALTIVEC)) + { + s->dsp.idct_put = idct_put_altivec; + s->dsp.idct_add = idct_add_altivec; + s->dsp.idct_permutation_type = FF_TRANSPOSE_IDCT_PERM; + } + } + + // Test to make sure that the dct required alignments are met. + if ((((long)(s->q_intra_matrix) & 0x0f) != 0) || + (((long)(s->q_inter_matrix) & 0x0f) != 0)) + { + av_log(s->avctx, AV_LOG_INFO, "Internal Error: q-matrix blocks must be 16-byte aligned " + "to use AltiVec DCT. Reverting to non-AltiVec version.\n"); + return; + } + + if (((long)(s->intra_scantable.inverse) & 0x0f) != 0) + { + av_log(s->avctx, AV_LOG_INFO, "Internal Error: scan table blocks must be 16-byte aligned " + "to use AltiVec DCT. Reverting to non-AltiVec version.\n"); + return; + } + + + if ((s->avctx->dct_algo == FF_DCT_AUTO) || + (s->avctx->dct_algo == FF_DCT_ALTIVEC)) + { +#if 0 /* seems to cause trouble under some circumstances */ + s->dct_quantize = dct_quantize_altivec; +#endif + s->dct_unquantize_h263_intra = dct_unquantize_h263_altivec; + s->dct_unquantize_h263_inter = dct_unquantize_h263_altivec; + } +} diff --git a/contrib/ffmpeg/libavcodec/ppc/mpegvideo_ppc.c b/contrib/ffmpeg/libavcodec/ppc/mpegvideo_ppc.c deleted file mode 100644 index c5e822f77..000000000 --- a/contrib/ffmpeg/libavcodec/ppc/mpegvideo_ppc.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2002 Dieter Shirley - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "../dsputil.h" -#include "../mpegvideo.h" -#include - -#ifdef HAVE_ALTIVEC -#include "dsputil_altivec.h" -#endif - -extern int dct_quantize_altivec(MpegEncContext *s, - DCTELEM *block, int n, - int qscale, int *overflow); -extern void dct_unquantize_h263_altivec(MpegEncContext *s, - DCTELEM *block, int n, int qscale); - -extern void idct_put_altivec(uint8_t *dest, int line_size, int16_t *block); -extern void idct_add_altivec(uint8_t *dest, int line_size, int16_t *block); - - -void MPV_common_init_ppc(MpegEncContext *s) -{ -#ifdef HAVE_ALTIVEC - if (has_altivec()) - { - if (s->avctx->lowres==0) - { - if ((s->avctx->idct_algo == FF_IDCT_AUTO) || - (s->avctx->idct_algo == FF_IDCT_ALTIVEC)) - { - s->dsp.idct_put = idct_put_altivec; - s->dsp.idct_add = idct_add_altivec; - s->dsp.idct_permutation_type = FF_TRANSPOSE_IDCT_PERM; - } - } - - // Test to make sure that the dct required alignments are met. - if ((((long)(s->q_intra_matrix) & 0x0f) != 0) || - (((long)(s->q_inter_matrix) & 0x0f) != 0)) - { - av_log(s->avctx, AV_LOG_INFO, "Internal Error: q-matrix blocks must be 16-byte aligned " - "to use Altivec DCT. Reverting to non-altivec version.\n"); - return; - } - - if (((long)(s->intra_scantable.inverse) & 0x0f) != 0) - { - av_log(s->avctx, AV_LOG_INFO, "Internal Error: scan table blocks must be 16-byte aligned " - "to use Altivec DCT. Reverting to non-altivec version.\n"); - return; - } - - - if ((s->avctx->dct_algo == FF_DCT_AUTO) || - (s->avctx->dct_algo == FF_DCT_ALTIVEC)) - { -#if 0 /* seems to cause trouble under some circumstances */ - s->dct_quantize = dct_quantize_altivec; -#endif - s->dct_unquantize_h263_intra = dct_unquantize_h263_altivec; - s->dct_unquantize_h263_inter = dct_unquantize_h263_altivec; - } - } else -#endif - { - /* Non-AltiVec PPC optimisations here */ - } -} - diff --git a/contrib/ffmpeg/libavcodec/ppc/snow_altivec.c b/contrib/ffmpeg/libavcodec/ppc/snow_altivec.c index b15672ffe..8770f05f5 100644 --- a/contrib/ffmpeg/libavcodec/ppc/snow_altivec.c +++ b/contrib/ffmpeg/libavcodec/ppc/snow_altivec.c @@ -1,5 +1,5 @@ /* - * Altivec optimized snow DSP utils + * AltiVec-optimized snow DSP utils * Copyright (c) 2006 Luca Barbato * * This file is part of FFmpeg. @@ -17,15 +17,13 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * */ -#include "../dsputil.h" +#include "dsputil.h" #include "gcc_fixes.h" #include "dsputil_altivec.h" -#include "../snow.h" +#include "snow.h" #undef NDEBUG #include @@ -60,57 +58,56 @@ static DWTELEM * slice_buffer_load_line(slice_buffer * buf, int line) //altivec code -void ff_snow_horizontal_compose97i_altivec(DWTELEM *b, int width) +void ff_snow_horizontal_compose97i_altivec(IDWTELEM *b, int width) { +#if 0 const int w2= (width+1)>>1; - DECLARE_ALIGNED_16(DWTELEM, temp[(width>>1)]); + DECLARE_ALIGNED_16(IDWTELEM, temp[(width>>1)]); const int w_l= (width>>1); const int w_r= w2 - 1; int i; - vector signed int t1, t2, x, y, tmp1, tmp2; - vector signed int *vbuf, *vtmp; + vector signed short t1, t2, x, y, tmp1, tmp2; + vector signed short *vbuf, *vtmp; vector unsigned char align; - - { // Lift 0 - DWTELEM * const ref = b + w2 - 1; - DWTELEM b_0 = b[0]; - vbuf = (vector signed int *)b; + IDWTELEM * const ref = b + w2 - 1; + IDWTELEM b_0 = b[0]; + vector signed short v7 = vec_splat_s16(7); + vbuf = (vector signed short *)b; tmp1 = vec_ld (0, ref); align = vec_lvsl (0, ref); tmp2 = vec_ld (15, ref); - t1= vec_perm(tmp1, tmp2, align); - - i = 0; + t1 = vec_perm(tmp1, tmp2, align); for (i=0; i> 3); +/* b[i+0] = b[i+0] - ((3 * (ref[i+0] + ref[i+1]) + 4) >> 3); b[i+1] = b[i+1] - ((3 * (ref[i+1] + ref[i+2]) + 4) >> 3); b[i+2] = b[i+2] - ((3 * (ref[i+2] + ref[i+3]) + 4) >> 3); - b[i+3] = b[i+3] - ((3 * (ref[i+3] + ref[i+4]) + 4) >> 3); + b[i+3] = b[i+3] - ((3 * (ref[i+3] + ref[i+4]) + 4) >> 3);*/ + b[i+0] = b[i+0] + ((7 * (ref[i+0] + ref[i+1])-1) >> 8); #else - tmp1 = vec_ld (0, ref+4+i); - tmp2 = vec_ld (15, ref+4+i); + tmp1 = vec_ld (0, ref+8+i); + tmp2 = vec_ld (15, ref+8+i); t2 = vec_perm(tmp1, tmp2, align); - y = vec_add(t1,vec_sld(t1,t2,4)); - y = vec_add(vec_add(y,y),y); + y = vec_add(t1, vec_sld(t1,t2,2)); +// y = vec_add(vec_add(y,y),y); - tmp1 = vec_ld (0, ref+8+i); + tmp1 = vec_ld (0, ref+12+i); y = vec_add(y, vec_splat_s32(4)); y = vec_sra(y, vec_splat_u32(3)); - tmp2 = vec_ld (15, ref+8+i); + tmp2 = vec_ld (15, ref+12+i); *vbuf = vec_sub(*vbuf, y); - t1=t2; + t1 = t2; vbuf++; @@ -164,6 +161,7 @@ void ff_snow_horizontal_compose97i_altivec(DWTELEM *b, int width) vbuf++; #endif + } snow_horizontal_compose_lift_lead_out(i, b, b, ref, width, w_l, 0, W_DM, W_DO, W_DS); @@ -365,6 +363,7 @@ void ff_snow_horizontal_compose97i_altivec(DWTELEM *b, int width) } } +#endif } void ff_snow_vertical_compose97i_altivec(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width) @@ -524,7 +523,7 @@ static void inner_add_yblock_bw_8_obmc_16_altivec(uint8_t *obmc, vector signed int *v = (vector signed int *)vbuf, *d; for(y=0; y>1); @@ -590,7 +589,7 @@ static void inner_add_yblock_bw_16_obmc_32_altivec(uint8_t *obmc, vector signed int *v = (vector signed int *)vbuf, *d; for(y=0; y>1); @@ -673,7 +672,7 @@ static void inner_add_yblock_a_bw_8_obmc_16_altivec(uint8_t *obmc, vector signed int *v = (vector signed int *)vbuf, *d; for(y=0; y>1); @@ -719,7 +718,7 @@ static void inner_add_yblock_a_bw_16_obmc_32_altivec(uint8_t *obmc, vector signed int *v = (vector signed int *)vbuf, *d; for(y=0; y>1); @@ -782,7 +781,9 @@ void ff_snow_inner_add_yblock_altivec(uint8_t *obmc, const int obmc_stride, void snow_init_altivec(DSPContext* c, AVCodecContext *avctx) { +#if 0 c->horizontal_compose97i = ff_snow_horizontal_compose97i_altivec; c->vertical_compose97i = ff_snow_vertical_compose97i_altivec; c->inner_add_yblock = ff_snow_inner_add_yblock_altivec; +#endif } diff --git a/contrib/ffmpeg/libavcodec/ppc/types_altivec.h b/contrib/ffmpeg/libavcodec/ppc/types_altivec.h index f29026e04..6d41a928b 100644 --- a/contrib/ffmpeg/libavcodec/ppc/types_altivec.h +++ b/contrib/ffmpeg/libavcodec/ppc/types_altivec.h @@ -18,6 +18,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef FFMPEG_TYPES_ALTIVEC_H +#define FFMPEG_TYPES_ALTIVEC_H + /*********************************************************************** * Vector types **********************************************************************/ @@ -39,3 +42,5 @@ #define zero_s16v (vec_s16_t) zerov #define zero_u32v (vec_u32_t) zerov #define zero_s32v (vec_s32_t) zerov + +#endif /* FFMPEG_TYPES_ALTIVEC_H */ diff --git a/contrib/ffmpeg/libavcodec/ppc/util_altivec.h b/contrib/ffmpeg/libavcodec/ppc/util_altivec.h new file mode 100644 index 000000000..6a8afb1b2 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/ppc/util_altivec.h @@ -0,0 +1,105 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file util_altivec.h + * Contains misc utility macros and inline functions + */ + +#ifndef FFMPEG_UTIL_ALTIVEC_H +#define FFMPEG_UTIL_ALTIVEC_H + +#include + +#include "config.h" + +#ifdef HAVE_ALTIVEC_H +#include +#endif + +// used to build registers permutation vectors (vcprm) +// the 's' are for words in the _s_econd vector +#define WORD_0 0x00,0x01,0x02,0x03 +#define WORD_1 0x04,0x05,0x06,0x07 +#define WORD_2 0x08,0x09,0x0a,0x0b +#define WORD_3 0x0c,0x0d,0x0e,0x0f +#define WORD_s0 0x10,0x11,0x12,0x13 +#define WORD_s1 0x14,0x15,0x16,0x17 +#define WORD_s2 0x18,0x19,0x1a,0x1b +#define WORD_s3 0x1c,0x1d,0x1e,0x1f + +#define vcprm(a,b,c,d) (const vector unsigned char)AVV(WORD_ ## a, WORD_ ## b, WORD_ ## c, WORD_ ## d) +#define vcii(a,b,c,d) (const vector float)AVV(FLOAT_ ## a, FLOAT_ ## b, FLOAT_ ## c, FLOAT_ ## d) + +// vcprmle is used to keep the same index as in the SSE version. +// it's the same as vcprm, with the index inversed +// ('le' is Little Endian) +#define vcprmle(a,b,c,d) vcprm(d,c,b,a) + +// used to build inverse/identity vectors (vcii) +// n is _n_egative, p is _p_ositive +#define FLOAT_n -1. +#define FLOAT_p 1. + + +// Transpose 8x8 matrix of 16-bit elements (in-place) +#define TRANSPOSE8(a,b,c,d,e,f,g,h) \ +do { \ + vector signed short A1, B1, C1, D1, E1, F1, G1, H1; \ + vector signed short A2, B2, C2, D2, E2, F2, G2, H2; \ + \ + A1 = vec_mergeh (a, e); \ + B1 = vec_mergel (a, e); \ + C1 = vec_mergeh (b, f); \ + D1 = vec_mergel (b, f); \ + E1 = vec_mergeh (c, g); \ + F1 = vec_mergel (c, g); \ + G1 = vec_mergeh (d, h); \ + H1 = vec_mergel (d, h); \ + \ + A2 = vec_mergeh (A1, E1); \ + B2 = vec_mergel (A1, E1); \ + C2 = vec_mergeh (B1, F1); \ + D2 = vec_mergel (B1, F1); \ + E2 = vec_mergeh (C1, G1); \ + F2 = vec_mergel (C1, G1); \ + G2 = vec_mergeh (D1, H1); \ + H2 = vec_mergel (D1, H1); \ + \ + a = vec_mergeh (A2, E2); \ + b = vec_mergel (A2, E2); \ + c = vec_mergeh (B2, F2); \ + d = vec_mergel (B2, F2); \ + e = vec_mergeh (C2, G2); \ + f = vec_mergel (C2, G2); \ + g = vec_mergeh (D2, H2); \ + h = vec_mergel (D2, H2); \ +} while (0) + + +/** \brief loads unaligned vector \a *src with offset \a offset + and returns it */ +static inline vector unsigned char unaligned_load(int offset, uint8_t *src) +{ + register vector unsigned char first = vec_ld(offset, src); + register vector unsigned char second = vec_ld(offset+15, src); + register vector unsigned char mask = vec_lvsl(offset, src); + return vec_perm(first, second, mask); +} + +#endif /* FFMPEG_UTIL_ALTIVEC_H */ diff --git a/contrib/ffmpeg/libavcodec/ppc/vc1dsp_altivec.c b/contrib/ffmpeg/libavcodec/ppc/vc1dsp_altivec.c index 114c9d41f..87bef808e 100644 --- a/contrib/ffmpeg/libavcodec/ppc/vc1dsp_altivec.c +++ b/contrib/ffmpeg/libavcodec/ppc/vc1dsp_altivec.c @@ -17,14 +17,13 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ -#include "../dsputil.h" +#include "dsputil.h" #include "gcc_fixes.h" -#include "dsputil_altivec.h" +#include "util_altivec.h" // main steps of 8x8 transform #define STEP8(s0, s1, s2, s3, s4, s5, s6, s7, vec_rnd) \ @@ -139,7 +138,6 @@ static void vc1_inv_trans_8x8_altivec(DCTELEM block[64]) vector signed int t0, t1, t2, t3, t4, t5, t6, t7; const vector signed int vec_64 = vec_sl(vec_splat_s32(4), vec_splat_u32(4)); const vector unsigned int vec_7 = vec_splat_u32(7); - const vector unsigned int vec_5 = vec_splat_u32(5); const vector unsigned int vec_4 = vec_splat_u32(4); const vector signed int vec_4s = vec_splat_s32(4); const vector unsigned int vec_3 = vec_splat_u32(3); @@ -229,7 +227,7 @@ static void vc1_inv_trans_8x8_altivec(DCTELEM block[64]) /** Do inverse transform on 8x4 part of block */ -static void vc1_inv_trans_8x4_altivec(DCTELEM block[64], int n) +static void vc1_inv_trans_8x4_altivec(uint8_t *dest, int stride, DCTELEM *block) { vector signed short src0, src1, src2, src3, src4, src5, src6, src7; vector signed int s0, s1, s2, s3, s4, s5, s6, s7; @@ -243,6 +241,9 @@ static void vc1_inv_trans_8x4_altivec(DCTELEM block[64], int n) const vector unsigned int vec_3 = vec_splat_u32(3); const vector unsigned int vec_2 = vec_splat_u32(2); const vector unsigned int vec_1 = vec_splat_u32(1); + vector unsigned char tmp; + vector signed short tmp2, tmp3; + vector unsigned char perm0, perm1, p0, p1, p; src0 = vec_ld( 0, block); src1 = vec_ld( 16, block); @@ -284,51 +285,42 @@ static void vc1_inv_trans_8x4_altivec(DCTELEM block[64], int n) src7 = vec_pack(sF, s7); TRANSPOSE8(src0, src1, src2, src3, src4, src5, src6, src7); - if(!n){ // upper half of block - s0 = vec_unpackh(src0); - s1 = vec_unpackh(src1); - s2 = vec_unpackh(src2); - s3 = vec_unpackh(src3); - s8 = vec_unpackl(src0); - s9 = vec_unpackl(src1); - sA = vec_unpackl(src2); - sB = vec_unpackl(src3); - STEP4(s0, s1, s2, s3, vec_64); - SHIFT_VERT4(s0, s1, s2, s3); - STEP4(s8, s9, sA, sB, vec_64); - SHIFT_VERT4(s8, s9, sA, sB); - src0 = vec_pack(s0, s8); - src1 = vec_pack(s1, s9); - src2 = vec_pack(s2, sA); - src3 = vec_pack(s3, sB); + s0 = vec_unpackh(src0); + s1 = vec_unpackh(src1); + s2 = vec_unpackh(src2); + s3 = vec_unpackh(src3); + s8 = vec_unpackl(src0); + s9 = vec_unpackl(src1); + sA = vec_unpackl(src2); + sB = vec_unpackl(src3); + STEP4(s0, s1, s2, s3, vec_64); + SHIFT_VERT4(s0, s1, s2, s3); + STEP4(s8, s9, sA, sB, vec_64); + SHIFT_VERT4(s8, s9, sA, sB); + src0 = vec_pack(s0, s8); + src1 = vec_pack(s1, s9); + src2 = vec_pack(s2, sA); + src3 = vec_pack(s3, sB); + + p0 = vec_lvsl (0, dest); + p1 = vec_lvsl (stride, dest); + p = vec_splat_u8 (-1); + perm0 = vec_mergeh (p, p0); + perm1 = vec_mergeh (p, p1); - vec_st(src0, 0, block); - vec_st(src1, 16, block); - vec_st(src2, 32, block); - vec_st(src3, 48, block); - } else { //lower half of block - s0 = vec_unpackh(src4); - s1 = vec_unpackh(src5); - s2 = vec_unpackh(src6); - s3 = vec_unpackh(src7); - s8 = vec_unpackl(src4); - s9 = vec_unpackl(src5); - sA = vec_unpackl(src6); - sB = vec_unpackl(src7); - STEP4(s0, s1, s2, s3, vec_64); - SHIFT_VERT4(s0, s1, s2, s3); - STEP4(s8, s9, sA, sB, vec_64); - SHIFT_VERT4(s8, s9, sA, sB); - src4 = vec_pack(s0, s8); - src5 = vec_pack(s1, s9); - src6 = vec_pack(s2, sA); - src7 = vec_pack(s3, sB); +#define ADD(dest,src,perm) \ + /* *(uint64_t *)&tmp = *(uint64_t *)dest; */ \ + tmp = vec_ld (0, dest); \ + tmp2 = (vector signed short)vec_perm (tmp, vec_splat_u8(0), perm); \ + tmp3 = vec_adds (tmp2, src); \ + tmp = vec_packsu (tmp3, tmp3); \ + vec_ste ((vector unsigned int)tmp, 0, (unsigned int *)dest); \ + vec_ste ((vector unsigned int)tmp, 4, (unsigned int *)dest); - vec_st(src4, 64, block); - vec_st(src5, 80, block); - vec_st(src6, 96, block); - vec_st(src7,112, block); - } + ADD (dest, src0, perm0) dest += stride; + ADD (dest, src1, perm1) dest += stride; + ADD (dest, src2, perm0) dest += stride; + ADD (dest, src3, perm1) } diff --git a/contrib/ffmpeg/libavcodec/ps2/dsputil_mmi.c b/contrib/ffmpeg/libavcodec/ps2/dsputil_mmi.c index 0d72ae88c..6a0582fe4 100644 --- a/contrib/ffmpeg/libavcodec/ps2/dsputil_mmi.c +++ b/contrib/ffmpeg/libavcodec/ps2/dsputil_mmi.c @@ -2,6 +2,9 @@ * MMI optimized DSP utils * Copyright (c) 2000, 2001 Fabrice Bellard. * + * MMI optimization by Leon van Stuivenberg + * clear_blocks_mmi() by BroadQ + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -17,12 +20,9 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * MMI optimization by Leon van Stuivenberg - * clear_blocks_mmi() by BroadQ */ -#include "../dsputil.h" +#include "dsputil.h" #include "mmi.h" void ff_mmi_idct_put(uint8_t *dest, int line_size, DCTELEM *block); diff --git a/contrib/ffmpeg/libavcodec/ps2/idct_mmi.c b/contrib/ffmpeg/libavcodec/ps2/idct_mmi.c index dfe9b3726..2ba2ad02d 100644 --- a/contrib/ffmpeg/libavcodec/ps2/idct_mmi.c +++ b/contrib/ffmpeg/libavcodec/ps2/idct_mmi.c @@ -23,11 +23,10 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * -*/ + */ -#include "../common.h" -#include "../dsputil.h" +#include "common.h" +#include "dsputil.h" #include "mmi.h" #define BITS_INV_ACC 5 // 4 or 5 for IEEE diff --git a/contrib/ffmpeg/libavcodec/ps2/mmi.h b/contrib/ffmpeg/libavcodec/ps2/mmi.h index e2e49a86c..1e0a504f8 100644 --- a/contrib/ffmpeg/libavcodec/ps2/mmi.h +++ b/contrib/ffmpeg/libavcodec/ps2/mmi.h @@ -18,8 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef __mmi_H -#define __mmi_H +#ifndef FFMPEG_MMI_H +#define FFMPEG_MMI_H #define align16 __attribute__ ((aligned (16))) @@ -168,5 +168,4 @@ #define pextlb(rs, rt, rd) \ __asm__ __volatile__ ("pextlb " #rd ", " #rs ", " #rt ) -#endif - +#endif /* FFMPEG_MMI_H */ diff --git a/contrib/ffmpeg/libavcodec/ps2/mpegvideo_mmi.c b/contrib/ffmpeg/libavcodec/ps2/mpegvideo_mmi.c index 1e5f08aae..7f62e6e6d 100644 --- a/contrib/ffmpeg/libavcodec/ps2/mpegvideo_mmi.c +++ b/contrib/ffmpeg/libavcodec/ps2/mpegvideo_mmi.c @@ -1,6 +1,8 @@ /* * Copyright (c) 2000,2001 Fabrice Bellard. * + * MMI optimization by Leon van Stuivenberg + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -16,13 +18,11 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * MMI optimization by Leon van Stuivenberg */ -#include "../dsputil.h" -#include "../mpegvideo.h" -#include "../avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" +#include "avcodec.h" static void dct_unquantize_h263_mmi(MpegEncContext *s, DCTELEM *block, int n, int qscale) @@ -45,7 +45,7 @@ static void dct_unquantize_h263_mmi(MpegEncContext *s, qadd = 0; level = block[0]; } - nCoeffs= 63; //does not allways use zigzag table + nCoeffs= 63; //does not always use zigzag table } else { nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ]; } diff --git a/contrib/ffmpeg/libavcodec/pthread.c b/contrib/ffmpeg/libavcodec/pthread.c index f2c636bbe..702adb533 100644 --- a/contrib/ffmpeg/libavcodec/pthread.c +++ b/contrib/ffmpeg/libavcodec/pthread.c @@ -20,12 +20,10 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ #include #include "avcodec.h" -#include "common.h" typedef int (action_t)(AVCodecContext *c, void *arg); @@ -44,7 +42,7 @@ typedef struct ThreadContext { int done; } ThreadContext; -static void* worker(void *v) +static void* attribute_align_arg worker(void *v) { AVCodecContext *avctx = v; ThreadContext *c = avctx->thread_opaque; @@ -99,7 +97,7 @@ void avcodec_thread_free(AVCodecContext *avctx) pthread_cond_destroy(&c->current_job_cond); pthread_cond_destroy(&c->last_job_cond); av_free(c->workers); - av_free(c); + av_freep(&avctx->thread_opaque); } int avcodec_thread_execute(AVCodecContext *avctx, action_t* func, void **arg, int *ret, int job_count) diff --git a/contrib/ffmpeg/libavcodec/ptx.c b/contrib/ffmpeg/libavcodec/ptx.c new file mode 100644 index 000000000..22bb46178 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/ptx.c @@ -0,0 +1,117 @@ +/* + * V.Flash PTX (.ptx) image decoder + * Copyright (c) 2007 Ivo van Poorten + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" + +typedef struct PTXContext { + AVFrame picture; +} PTXContext; + +static int ptx_init(AVCodecContext *avctx) { + PTXContext *s = avctx->priv_data; + + avcodec_get_frame_defaults(&s->picture); + avctx->coded_frame= &s->picture; + + return 0; +} + +static int ptx_decode_frame(AVCodecContext *avctx, void *data, int *data_size, + const uint8_t *buf, int buf_size) { + PTXContext * const s = avctx->priv_data; + AVFrame *picture = data; + AVFrame * const p = &s->picture; + unsigned int offset, w, h, y, stride, bytes_per_pixel; + uint8_t *ptr; + + offset = AV_RL16(buf); + w = AV_RL16(buf+8); + h = AV_RL16(buf+10); + bytes_per_pixel = AV_RL16(buf+12) >> 3; + + if (bytes_per_pixel != 2) { + av_log(avctx, AV_LOG_ERROR, "image format is not rgb15, please report on ffmpeg-users mailing list\n"); + return -1; + } + + avctx->pix_fmt = PIX_FMT_RGB555; + + if (offset != 0x2c) + av_log(avctx, AV_LOG_WARNING, "offset != 0x2c, untested due to lack of sample files\n"); + + buf += offset; + + if (p->data[0]) + avctx->release_buffer(avctx, p); + + if (avcodec_check_dimensions(avctx, w, h)) + return -1; + if (w != avctx->width || h != avctx->height) + avcodec_set_dimensions(avctx, w, h); + if (avctx->get_buffer(avctx, p) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + + p->pict_type = FF_I_TYPE; + + ptr = p->data[0]; + stride = p->linesize[0]; + + for (y=0; ypicture; + *data_size = sizeof(AVPicture); + + return offset + w*h*bytes_per_pixel; +} + +static int ptx_end(AVCodecContext *avctx) { + PTXContext *s = avctx->priv_data; + + if(s->picture.data[0]) + avctx->release_buffer(avctx, &s->picture); + + return 0; +} + +AVCodec ptx_decoder = { + "ptx", + CODEC_TYPE_VIDEO, + CODEC_ID_PTX, + sizeof(PTXContext), + ptx_init, + NULL, + ptx_end, + ptx_decode_frame, + 0, + NULL +}; diff --git a/contrib/ffmpeg/libavcodec/qdm2.c b/contrib/ffmpeg/libavcodec/qdm2.c index a2630fe7f..55ddbef45 100644 --- a/contrib/ffmpeg/libavcodec/qdm2.c +++ b/contrib/ffmpeg/libavcodec/qdm2.c @@ -20,7 +20,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -98,16 +97,16 @@ typedef struct { /** * A node in the subpacket list */ -typedef struct _QDM2SubPNode { +typedef struct QDM2SubPNode { QDM2SubPacket *packet; ///< packet - struct _QDM2SubPNode *next; ///< pointer to next packet in the list, NULL if leaf node + struct QDM2SubPNode *next; ///< pointer to next packet in the list, NULL if leaf node } QDM2SubPNode; typedef struct { float level; float *samples_im; float *samples_re; - float *table; + const float *table; int phase; int phase_shift; int duration; @@ -129,7 +128,7 @@ typedef struct { } QDM2Complex; typedef struct { - QDM2Complex complex[256 + 1] __attribute__((aligned(16))); + DECLARE_ALIGNED_16(QDM2Complex, complex[256 + 1]); float samples_im[MPA_MAX_CHANNELS][256]; float samples_re[MPA_MAX_CHANNELS][256]; } QDM2FFT; @@ -177,14 +176,14 @@ typedef struct { QDM2FFT fft; /// I/O data - uint8_t *compressed_data; + const uint8_t *compressed_data; int compressed_size; float output_buffer[1024]; /// Synthesis filter - MPA_INT synth_buf[MPA_MAX_CHANNELS][512*2] __attribute__((aligned(16))); + DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512*2]); int synth_buf_offset[MPA_MAX_CHANNELS]; - int32_t sb_samples[MPA_MAX_CHANNELS][128][SBLIMIT] __attribute__((aligned(16))); + DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][128][SBLIMIT]); /// Mixed temporary data used in decoding float tone_level[MPA_MAX_CHANNELS][30][64]; @@ -229,7 +228,7 @@ static uint8_t random_dequant_index[256][5]; static uint8_t random_dequant_type24[128][3]; static float noise_samples[128]; -static MPA_INT mpa_window[512] __attribute__((aligned(16))); +static DECLARE_ALIGNED_16(MPA_INT, mpa_window[512]); static void softclip_table_init(void) { @@ -405,7 +404,7 @@ static int qdm2_get_se_vlc (VLC *vlc, GetBitContext *gb, int depth) * * @return 0 if checksum is OK */ -static uint16_t qdm2_packet_checksum (uint8_t *data, int length, int value) { +static uint16_t qdm2_packet_checksum (const uint8_t *data, int length, int value) { int i; for (i=0; i < length; i++) @@ -1599,7 +1598,7 @@ static void qdm2_fft_tone_synthesizer (QDM2Context *q, int sub_packet) tone.level = (q->fft_coefs[j].exp < 0) ? 0.0 : fft_tone_level_table[q->superblocktype_2_3 ? 0 : 1][q->fft_coefs[j].exp & 63]; tone.samples_im = &q->fft.samples_im[ch][offset]; tone.samples_re = &q->fft.samples_re[ch][offset]; - tone.table = (float*)fft_tone_sample_table[i][q->fft_coefs[j].offset - (offset << four_i)]; + tone.table = fft_tone_sample_table[i][q->fft_coefs[j].offset - (offset << four_i)]; tone.phase = 64 * q->fft_coefs[j].phase - (offset << 8) - 128; tone.phase_shift = (2 * q->fft_coefs[j].offset + 1) << (7 - four_i); tone.duration = i; @@ -1693,11 +1692,11 @@ static void qdm2_synthesis_filter (QDM2Context *q, int index) * @param q context */ static void qdm2_init(QDM2Context *q) { - static int inited = 0; + static int initialized = 0; - if (inited != 0) + if (initialized != 0) return; - inited = 1; + initialized = 1; qdm2_init_vlc(); ff_mpa_synth_init(mpa_window); @@ -1944,7 +1943,7 @@ static int qdm2_decode_close(AVCodecContext *avctx) } -static void qdm2_decode (QDM2Context *q, uint8_t *in, int16_t *out) +static void qdm2_decode (QDM2Context *q, const uint8_t *in, int16_t *out) { int ch, i; const int frame_size = (q->frame_size * q->channels); @@ -2006,7 +2005,7 @@ static void qdm2_decode (QDM2Context *q, uint8_t *in, int16_t *out) static int qdm2_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { QDM2Context *s = avctx->priv_data; diff --git a/contrib/ffmpeg/libavcodec/qdm2data.h b/contrib/ffmpeg/libavcodec/qdm2data.h index 6d7d07463..8edb246e4 100644 --- a/contrib/ffmpeg/libavcodec/qdm2data.h +++ b/contrib/ffmpeg/libavcodec/qdm2data.h @@ -20,7 +20,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -28,8 +27,10 @@ * Various QDM2 tables. */ -#ifndef QDM2DATA_H -#define QDM2DATA_H +#ifndef FFMPEG_QDM2DATA_H +#define FFMPEG_QDM2DATA_H + +#include /** VLC TABLES **/ @@ -527,4 +528,4 @@ static const float type34_delta[10] = { // FIXME: covers 8 entries.. 0.138071194291115f,0.333333343267441f,0.60947573184967f,1.0f,0.0f, }; -#endif /* QDM2DATA_H */ +#endif /* FFMPEG_QDM2DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/qdrw.c b/contrib/ffmpeg/libavcodec/qdrw.c index 664be2f4f..0ee9a8f7c 100644 --- a/contrib/ffmpeg/libavcodec/qdrw.c +++ b/contrib/ffmpeg/libavcodec/qdrw.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -31,18 +30,19 @@ typedef struct QdrawContext{ AVCodecContext *avctx; AVFrame pic; - uint8_t palette[256*3]; } QdrawContext; static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { QdrawContext * const a = avctx->priv_data; AVFrame * const p= (AVFrame*)&a->pic; uint8_t* outdata; int colors; int i; + uint32_t *pal; + int r, g, b; if(p->data[0]) avctx->release_buffer(avctx, p); @@ -66,6 +66,7 @@ static int decode_frame(AVCodecContext *avctx, return -1; } + pal = (uint32_t*)p->data[1]; for (i = 0; i <= colors; i++) { unsigned int idx; idx = AV_RB16(buf); /* color index */ @@ -76,18 +77,20 @@ static int decode_frame(AVCodecContext *avctx, buf += 6; continue; } - a->palette[idx * 3 + 0] = *buf++; + r = *buf++; buf++; - a->palette[idx * 3 + 1] = *buf++; + g = *buf++; buf++; - a->palette[idx * 3 + 2] = *buf++; + b = *buf++; buf++; + pal[idx] = (r << 16) | (g << 8) | b; } + p->palette_has_changed = 1; buf += 18; /* skip unneeded data */ for (i = 0; i < avctx->height; i++) { int size, left, code, pix; - uint8_t *next; + const uint8_t *next; uint8_t *out; int tsize = 0; @@ -100,27 +103,19 @@ static int decode_frame(AVCodecContext *avctx, while (left > 0) { code = *buf++; if (code & 0x80 ) { /* run */ - int i; pix = *buf++; - if ((out + (257 - code) * 3) > (outdata + a->pic.linesize[0])) + if ((out + (257 - code)) > (outdata + a->pic.linesize[0])) break; - for (i = 0; i < 257 - code; i++) { - *out++ = a->palette[pix * 3 + 0]; - *out++ = a->palette[pix * 3 + 1]; - *out++ = a->palette[pix * 3 + 2]; - } + memset(out, pix, 257 - code); + out += 257 - code; tsize += 257 - code; left -= 2; } else { /* copy */ - int i, pix; - if ((out + code * 3) > (outdata + a->pic.linesize[0])) + if ((out + code) > (outdata + a->pic.linesize[0])) break; - for (i = 0; i <= code; i++) { - pix = *buf++; - *out++ = a->palette[pix * 3 + 0]; - *out++ = a->palette[pix * 3 + 1]; - *out++ = a->palette[pix * 3 + 2]; - } + memcpy(out, buf, code + 1); + out += code + 1; + buf += code + 1; left -= 2 + code; tsize += code + 1; } @@ -142,7 +137,7 @@ static int decode_init(AVCodecContext *avctx){ return 1; } - avctx->pix_fmt= PIX_FMT_RGB24; + avctx->pix_fmt= PIX_FMT_PAL8; return 0; } diff --git a/contrib/ffmpeg/libavcodec/qpeg.c b/contrib/ffmpeg/libavcodec/qpeg.c index d995bc3b7..5f902e304 100644 --- a/contrib/ffmpeg/libavcodec/qpeg.c +++ b/contrib/ffmpeg/libavcodec/qpeg.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -34,7 +33,7 @@ typedef struct QpegContext{ uint8_t *refdata; } QpegContext; -static void qpeg_decode_intra(uint8_t *src, uint8_t *dst, int size, +static void qpeg_decode_intra(const uint8_t *src, uint8_t *dst, int size, int stride, int width, int height) { int i; @@ -116,22 +115,20 @@ static int qpeg_table_w[16] = { 0x00, 0x20, 0x18, 0x08, 0x18, 0x10, 0x20, 0x10, 0x08, 0x10, 0x20, 0x20, 0x08, 0x10, 0x18, 0x04}; /* Decodes delta frames */ -static void qpeg_decode_inter(uint8_t *src, uint8_t *dst, int size, +static void qpeg_decode_inter(const uint8_t *src, uint8_t *dst, int size, int stride, int width, int height, - int delta, uint8_t *ctable, uint8_t *refdata) + int delta, const uint8_t *ctable, uint8_t *refdata) { int i, j; int code; int filled = 0; int orig_height; - uint8_t *blkdata; /* copy prev frame */ for(i = 0; i < height; i++) memcpy(refdata + (i * width), dst + (i * stride), width); orig_height = height; - blkdata = src - 0x86; height--; dst = dst + height * stride; @@ -252,7 +249,7 @@ static void qpeg_decode_inter(uint8_t *src, uint8_t *dst, int size, static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { QpegContext * const a = avctx->priv_data; AVFrame * const p= (AVFrame*)&a->pic; diff --git a/contrib/ffmpeg/libavcodec/qtrle.c b/contrib/ffmpeg/libavcodec/qtrle.c index 415f08098..84482bac7 100644 --- a/contrib/ffmpeg/libavcodec/qtrle.c +++ b/contrib/ffmpeg/libavcodec/qtrle.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -37,7 +36,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include "dsputil.h" @@ -47,7 +45,7 @@ typedef struct QtrleContext { DSPContext dsp; AVFrame frame; - unsigned char *buf; + const unsigned char *buf; int size; } QtrleContext; @@ -491,7 +489,7 @@ static void qtrle_decode_32bpp(QtrleContext *s) static int qtrle_decode_init(AVCodecContext *avctx) { - QtrleContext *s = (QtrleContext *)avctx->priv_data; + QtrleContext *s = avctx->priv_data; s->avctx = avctx; switch (avctx->bits_per_sample) { @@ -523,7 +521,6 @@ static int qtrle_decode_init(AVCodecContext *avctx) avctx->bits_per_sample); break; } - avctx->has_b_frames = 0; dsputil_init(&s->dsp, avctx); s->frame.data[0] = NULL; @@ -533,9 +530,9 @@ static int qtrle_decode_init(AVCodecContext *avctx) static int qtrle_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { - QtrleContext *s = (QtrleContext *)avctx->priv_data; + QtrleContext *s = avctx->priv_data; s->buf = buf; s->size = buf_size; @@ -608,7 +605,7 @@ static int qtrle_decode_frame(AVCodecContext *avctx, static int qtrle_decode_end(AVCodecContext *avctx) { - QtrleContext *s = (QtrleContext *)avctx->priv_data; + QtrleContext *s = avctx->priv_data; if (s->frame.data[0]) avctx->release_buffer(avctx, &s->frame); diff --git a/contrib/ffmpeg/libavcodec/qtrleenc.c b/contrib/ffmpeg/libavcodec/qtrleenc.c new file mode 100644 index 000000000..2f41f3ce1 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/qtrleenc.c @@ -0,0 +1,326 @@ +/* + * Quicktime Animation (RLE) Video Encoder + * Copyright (C) 2007 Clemens Fruhwirth + * Copyright (C) 2007 Alexis Ballier + * + * This file is part of FFmpeg. + * + * This file is based on flashsvenc.c + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License, version 2.1, as published by the Free Software Foundation + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "bytestream.h" + +/** Maximum RLE code for bulk copy */ +#define MAX_RLE_BULK 127 +/** Maximum RLE code for repeat */ +#define MAX_RLE_REPEAT 128 +/** Maximum RLE code for skip */ +#define MAX_RLE_SKIP 254 + +typedef struct QtrleEncContext { + AVCodecContext *avctx; + AVFrame frame; + int pixel_size; + AVPicture previous_frame; + unsigned int max_buf_size; + /** + * This array will contain at ith position the value of the best RLE code + * if the line started at pixel i + * There can be 3 values : + * skip (0) : skip as much as possible pixels because they are equal to the + * previous frame ones + * repeat (<-1) : repeat that pixel -rle_code times, still as much as + * possible + * copy (>0) : copy the raw next rle_code pixels */ + signed char *rlecode_table; + /** + * This array will contain the length of the best rle encoding of the line + * starting at ith pixel */ + int *length_table; + /** + * Will contain at ith position the number of consecutive pixels equal to the previous + * frame starting from pixel i */ + uint8_t* skip_table; +} QtrleEncContext; + +static int qtrle_encode_init(AVCodecContext *avctx) +{ + QtrleEncContext *s = avctx->priv_data; + + if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { + return -1; + } + s->avctx=avctx; + + switch (avctx->pix_fmt) { +/* case PIX_FMT_RGB555: + s->pixel_size = 2; + break;*/ + case PIX_FMT_RGB24: + s->pixel_size = 3; + break; + default: + av_log(avctx, AV_LOG_ERROR, "Unsupported colorspace.\n"); + break; + } + avctx->bits_per_sample = s->pixel_size*8; + + s->rlecode_table = av_mallocz(s->avctx->width); + s->skip_table = av_mallocz(s->avctx->width); + s->length_table = av_mallocz((s->avctx->width + 1)*sizeof(int)); + if (!s->skip_table || !s->length_table || !s->rlecode_table) { + av_log(avctx, AV_LOG_ERROR, "Error allocating memory.\n"); + return -1; + } + if (avpicture_alloc(&s->previous_frame, avctx->pix_fmt, avctx->width, avctx->height) < 0) { + av_log(avctx, AV_LOG_ERROR, "Error allocating picture\n"); + return -1; + } + + s->max_buf_size = s->avctx->width*s->avctx->height*s->pixel_size /* image base material */ + + 15 /* header + footer */ + + s->avctx->height*2 /* skip code+rle end */ + + s->avctx->width/MAX_RLE_BULK + 1 /* rle codes */; + avctx->coded_frame = &s->frame; + return 0; +} + +/** + * Computes the best RLE sequence for a line + */ +static void qtrle_encode_line(QtrleEncContext *s, AVFrame *p, int line, uint8_t **buf) +{ + int width=s->avctx->width; + int i; + signed char rlecode; + + /* We will use it to compute the best bulk copy sequence */ + unsigned int bulkcount; + /* This will be the number of pixels equal to the preivous frame one's + * starting from the ith pixel */ + unsigned int skipcount; + /* This will be the number of consecutive equal pixels in the current + * frame, starting from the ith one also */ + unsigned int repeatcount; + + /* The cost of the three different possibilities */ + int total_bulk_cost; + int total_skip_cost; + int total_repeat_cost; + + int temp_cost; + int j; + + uint8_t *this_line = p-> data[0] + line*p->linesize[0] + (width - 1)*s->pixel_size; + uint8_t *prev_line = s->previous_frame.data[0] + line*p->linesize[0] + (width - 1)*s->pixel_size; + + s->length_table[width] = 0; + skipcount = 0; + + for (i = width - 1; i >= 0; i--) { + + if (!s->frame.key_frame && !memcmp(this_line, prev_line, s->pixel_size)) + skipcount = FFMIN(skipcount + 1, MAX_RLE_SKIP); + else + skipcount = 0; + + total_skip_cost = s->length_table[i + skipcount] + 2; + s->skip_table[i] = skipcount; + + + if (i < width - 1 && !memcmp(this_line, this_line + s->pixel_size, s->pixel_size)) + repeatcount = FFMIN(repeatcount + 1, MAX_RLE_REPEAT); + else + repeatcount = 1; + + total_repeat_cost = s->length_table[i + repeatcount] + 1 + s->pixel_size; + + /* skip code is free for the first pixel, it costs one byte for repeat and bulk copy + * so let's make it aware */ + if (i == 0) { + total_skip_cost--; + total_repeat_cost++; + } + + if (repeatcount > 1 && (skipcount == 0 || total_repeat_cost < total_skip_cost)) { + /* repeat is the best */ + s->length_table[i] = total_repeat_cost; + s->rlecode_table[i] = -repeatcount; + } + else if (skipcount > 0) { + /* skip is the best choice here */ + s->length_table[i] = total_skip_cost; + s->rlecode_table[i] = 0; + } + else { + /* We cannot do neither skip nor repeat + * thus we search for the best bulk copy to do */ + + int limit = FFMIN(width - i, MAX_RLE_BULK); + + temp_cost = 1 + s->pixel_size + !i; + total_bulk_cost = INT_MAX; + + for (j = 1; j <= limit; j++) { + if (s->length_table[i + j] + temp_cost < total_bulk_cost) { + /* We have found a better bulk copy ... */ + total_bulk_cost = s->length_table[i + j] + temp_cost; + bulkcount = j; + } + temp_cost += s->pixel_size; + } + + s->length_table[i] = total_bulk_cost; + s->rlecode_table[i] = bulkcount; + } + + this_line -= s->pixel_size; + prev_line -= s->pixel_size; + } + + /* Good ! Now we have the best sequence for this line, let's ouput it */ + + /* We do a special case for the first pixel so that we avoid testing it in + * the whole loop */ + + i=0; + this_line = p-> data[0] + line*p->linesize[0]; + prev_line = s->previous_frame.data[0] + line*p->linesize[0]; + + if (s->rlecode_table[0] == 0) { + bytestream_put_byte(buf, s->skip_table[0] + 1); + i += s->skip_table[0]; + } + else bytestream_put_byte(buf, 1); + + + while (i < width) { + rlecode = s->rlecode_table[i]; + bytestream_put_byte(buf, rlecode); + if (rlecode == 0) { + /* Write a skip sequence */ + bytestream_put_byte(buf, s->skip_table[i] + 1); + i += s->skip_table[i]; + } + else if (rlecode > 0) { + /* bulk copy */ + bytestream_put_buffer(buf, this_line + i*s->pixel_size, rlecode*s->pixel_size); + i += rlecode; + } + else { + /* repeat the bits */ + bytestream_put_buffer(buf, this_line + i*s->pixel_size, s->pixel_size); + i -= rlecode; + } + } + bytestream_put_byte(buf, -1); // end RLE line +} + +/** Encodes frame including header */ +static int encode_frame(QtrleEncContext *s, AVFrame *p, uint8_t *buf) +{ + int i; + int start_line = 0; + int end_line = s->avctx->height; + uint8_t *orig_buf = buf; + + if (!s->frame.key_frame) { + for (start_line = 0; start_line < s->avctx->height; start_line++) + if (memcmp(p->data[0] + start_line*p->linesize[0], + s->previous_frame.data[0] + start_line*p->linesize[0], + p->linesize[0])) + break; + + for (end_line=s->avctx->height; end_line > start_line; end_line--) + if (memcmp(p->data[0] + (end_line - 1)*p->linesize[0], + s->previous_frame.data[0] + (end_line - 1)*p->linesize[0], + p->linesize[0])) + break; + } + + bytestream_put_be32(&buf, 0); // CHUNK SIZE, patched later + + if ((start_line == 0 && end_line == s->avctx->height) || start_line == s->avctx->height) + bytestream_put_be16(&buf, 0); // header + else { + bytestream_put_be16(&buf, 8); // header + bytestream_put_be16(&buf, start_line); // starting line + bytestream_put_be16(&buf, 0); // unknown + bytestream_put_be16(&buf, end_line - start_line); // lines to update + bytestream_put_be16(&buf, 0); // unknown + } + for (i = start_line; i < end_line; i++) + qtrle_encode_line(s, p, i, &buf); + + bytestream_put_byte(&buf, 0); // zero skip code = frame finished + AV_WB32(orig_buf, buf - orig_buf); // patch the chunk size + return buf - orig_buf; +} + +static int qtrle_encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void *data) +{ + QtrleEncContext * const s = avctx->priv_data; + AVFrame *pict = data; + AVFrame * const p = &s->frame; + int chunksize; + + *p = *pict; + + if (buf_size < s->max_buf_size) { + /* Upper bound check for compressed data */ + av_log(avctx, AV_LOG_ERROR, "buf_size %d < %d\n", buf_size, s->max_buf_size); + return -1; + } + + if (avctx->gop_size == 0 || (s->avctx->frame_number % avctx->gop_size) == 0) { + /* I-Frame */ + p->pict_type = FF_I_TYPE; + p->key_frame = 1; + } else { + /* P-Frame */ + p->pict_type = FF_P_TYPE; + p->key_frame = 0; + } + + chunksize = encode_frame(s, pict, buf); + + /* save the current frame */ + av_picture_copy(&s->previous_frame, (AVPicture *)p, avctx->pix_fmt, avctx->width, avctx->height); + return chunksize; +} + +static int qtrle_encode_end(AVCodecContext *avctx) +{ + QtrleEncContext *s = avctx->priv_data; + + avpicture_free(&s->previous_frame); + av_free(s->rlecode_table); + av_free(s->length_table); + av_free(s->skip_table); + return 0; +} + +AVCodec qtrle_encoder = { + "qtrle", + CODEC_TYPE_VIDEO, + CODEC_ID_QTRLE, + sizeof(QtrleEncContext), + qtrle_encode_init, + qtrle_encode_frame, + qtrle_encode_end, + .pix_fmts = (enum PixelFormat[]){PIX_FMT_RGB24, -1}, +}; diff --git a/contrib/ffmpeg/libavcodec/ra144.c b/contrib/ffmpeg/libavcodec/ra144.c index c4f4b813b..30fd4a417 100644 --- a/contrib/ffmpeg/libavcodec/ra144.c +++ b/contrib/ffmpeg/libavcodec/ra144.c @@ -251,7 +251,7 @@ static void final(Real144_internal *glob, short *i1, short *i2, void *out, int * } /* Decode 20-byte input */ -static void unpack_input(unsigned char *input, unsigned int *output) +static void unpack_input(const unsigned char *input, unsigned int *output) { unsigned int outbuffer[28]; unsigned short inbuffer[10]; @@ -427,10 +427,9 @@ static void dec2(Real144_internal *glob, int *data, int *inp, int n, int f, int /* Uncompress one block (20 bytes -> 160*2 bytes) */ static int ra144_decode_frame(AVCodecContext * avctx, void *vdata, int *data_size, - uint8_t * buf, int buf_size) + const uint8_t * buf, int buf_size) { unsigned int a,b,c; - long s; signed short *shptr; unsigned int *lptr,*temp; const short **dptr; @@ -484,13 +483,8 @@ static int ra144_decode_frame(AVCodecContext * avctx, glob->resetflag=0; shptr=glob->output_buffer; - while (shptroutput_buffer+BLOCKSIZE) { - s=*(shptr++)<<2; - *data=s; - if (s>32767) *data=32767; - if (s<-32767) *data=-32768; - data++; - } + while (shptroutput_buffer+BLOCKSIZE) + *data++=av_clip_int16(*(shptr++)<<2); b+=30; } diff --git a/contrib/ffmpeg/libavcodec/ra144.h b/contrib/ffmpeg/libavcodec/ra144.h index 6d477b2f8..0d7a14a4f 100644 --- a/contrib/ffmpeg/libavcodec/ra144.h +++ b/contrib/ffmpeg/libavcodec/ra144.h @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef RA144TABLES_H -#define RA144TABLES_H +#ifndef FFMPEG_RA144_H +#define FFMPEG_RA144_H /* 14.4 data tables */ static const unsigned short sqrt_table[4096]={ @@ -2425,4 +2425,4 @@ decodetable1,decodetable2,decodetable3,decodetable4,decodetable5, decodetable6,decodetable7,decodetable8,decodetable9,decodetable10, decodetable11}; -#endif /* RA144TABLES_H */ +#endif /* FFMPEG_RA144_H */ diff --git a/contrib/ffmpeg/libavcodec/ra288.c b/contrib/ffmpeg/libavcodec/ra288.c index 9ba5209ab..ad36ff2ec 100644 --- a/contrib/ffmpeg/libavcodec/ra288.c +++ b/contrib/ffmpeg/libavcodec/ra288.c @@ -49,7 +49,7 @@ static void colmult(float *tgt, float *m1, const float *m2, int n); /* initial decode */ -static void unpack(unsigned short *tgt, unsigned char *src, unsigned int len) +static void unpack(unsigned short *tgt, const unsigned char *src, unsigned int len) { int x,y,z; int n,temp; @@ -208,7 +208,7 @@ static void prodsum(float *tgt, float *src, int len, int n) } } -static void * decode_block(AVCodecContext * avctx, unsigned char *in, signed short int *out,unsigned len) +static void * decode_block(AVCodecContext * avctx, const unsigned char *in, signed short int *out,unsigned len) { int x,y; Real288_internal *glob=avctx->priv_data; @@ -228,7 +228,7 @@ static void * decode_block(AVCodecContext * avctx, unsigned char *in, signed sho /* Decode a block (celp) */ static int ra288_decode_frame(AVCodecContext * avctx, void *data, int *data_size, - uint8_t * buf, int buf_size) + const uint8_t * buf, int buf_size) { void *datao; diff --git a/contrib/ffmpeg/libavcodec/ra288.h b/contrib/ffmpeg/libavcodec/ra288.h index 8cc290397..e222035a2 100644 --- a/contrib/ffmpeg/libavcodec/ra288.h +++ b/contrib/ffmpeg/libavcodec/ra288.h @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef RA288TABLES_H -#define RA288TABLES_H +#ifndef FFMPEG_RA288_H +#define FFMPEG_RA288_H static const float amptable[8]={ 0.515625, 0.90234375, 1.57910156, 2.76342773, -0.515625,-0.90234375,-1.57910156,-2.76342773 }; @@ -202,4 +202,4 @@ static const float table2a[10]={ 0.553955078, 0.50201416, 0.454956055, 0.41229248, 0.373657227 }; -#endif /* RA288TABLES_H */ +#endif /* FFMPEG_RA288_H */ diff --git a/contrib/ffmpeg/libavcodec/rangecoder.c b/contrib/ffmpeg/libavcodec/rangecoder.c index fcd564ace..34cda723f 100644 --- a/contrib/ffmpeg/libavcodec/rangecoder.c +++ b/contrib/ffmpeg/libavcodec/rangecoder.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -35,8 +34,8 @@ #include #include "avcodec.h" -#include "common.h" #include "rangecoder.h" +#include "bytestream.h" void ff_init_range_encoder(RangeCoder *c, uint8_t *buf, int buf_size){ @@ -54,8 +53,7 @@ void ff_init_range_decoder(RangeCoder *c, const uint8_t *buf, int buf_size){ /* cast to avoid compiler warning */ ff_init_range_encoder(c, (uint8_t *) buf, buf_size); - c->low =(*c->bytestream++)<<8; - c->low+= *c->bytestream++; + c->low = bytestream_get_be16(&c->bytestream); } void ff_build_rac_states(RangeCoder *c, int factor, int max_p){ @@ -111,9 +109,10 @@ int ff_rac_terminate(RangeCoder *c){ return c->bytestream - c->bytestream_start; } -#if 0 //selftest +#ifdef TEST #define SIZE 10240 -int main(){ +#undef random +int main(void){ RangeCoder c; uint8_t b[9*SIZE]; uint8_t r[9*SIZE]; @@ -135,7 +134,7 @@ START_TIMER STOP_TIMER("put_rac") } - ff_put_rac_terminate(&c); + ff_rac_terminate(&c); ff_init_range_decoder(&c, b, SIZE); @@ -150,4 +149,4 @@ STOP_TIMER("get_rac") return 0; } -#endif +#endif /* TEST */ diff --git a/contrib/ffmpeg/libavcodec/rangecoder.h b/contrib/ffmpeg/libavcodec/rangecoder.h index 68bd3b60e..4726afb56 100644 --- a/contrib/ffmpeg/libavcodec/rangecoder.h +++ b/contrib/ffmpeg/libavcodec/rangecoder.h @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -25,6 +24,13 @@ * Range coder. */ +#ifndef FFMPEG_RANGECODER_H +#define FFMPEG_RANGECODER_H + +#include +#include +#include "common.h" + typedef struct RangeCoder{ int low; int range; @@ -66,6 +72,13 @@ static inline void renorm_encoder(RangeCoder *c){ } } +static inline int get_rac_count(RangeCoder *c){ + int x= c->bytestream - c->bytestream_start + c->outstanding_count; + if(c->outstanding_byte >= 0) + x++; + return 8*x - av_log2(c->range); +} + static inline void put_rac(RangeCoder *c, uint8_t * const state, int bit){ int range1= (c->range * (*state)) >> 8; @@ -96,7 +109,7 @@ static inline void refill(RangeCoder *c){ static inline int get_rac(RangeCoder *c, uint8_t * const state){ int range1= (c->range * (*state)) >> 8; - int attribute_unused one_mask; + int av_unused one_mask; c->range -= range1; #if 1 @@ -125,3 +138,4 @@ static inline int get_rac(RangeCoder *c, uint8_t * const state){ #endif } +#endif /* FFMPEG_RANGECODER_H */ diff --git a/contrib/ffmpeg/libavcodec/ratecontrol.c b/contrib/ffmpeg/libavcodec/ratecontrol.c index 6d9270da8..d289a19cb 100644 --- a/contrib/ffmpeg/libavcodec/ratecontrol.c +++ b/contrib/ffmpeg/libavcodec/ratecontrol.c @@ -31,7 +31,7 @@ #include "mpegvideo.h" #include "eval.h" -#undef NDEBUG // allways check asserts, the speed effect is far too small to disable them +#undef NDEBUG // Always check asserts, the speed effect is far too small to disable them. #include #ifndef M_E @@ -66,7 +66,7 @@ int ff_rate_control_init(MpegEncContext *s) { RateControlContext *rcc= &s->rc_context; int i; - char *error = NULL; + const char *error = NULL; static const char *const_names[]={ "PI", "E", @@ -138,7 +138,7 @@ int ff_rate_control_init(MpegEncContext *s) i+= s->max_b_frames; if(i<=0 || i>=INT_MAX / sizeof(RateControlEntry)) return -1; - rcc->entry = (RateControlEntry*)av_mallocz(i*sizeof(RateControlEntry)); + rcc->entry = av_mallocz(i*sizeof(RateControlEntry)); rcc->num_entries= i; /* init all to skipped p frames (with b frames we might have a not encoded frame at the end FIXME) */ @@ -160,7 +160,7 @@ int ff_rate_control_init(MpegEncContext *s) next= strchr(p, ';'); if(next){ - (*next)=0; //sscanf in unbelieavle slow on looong strings //FIXME copy / dont write + (*next)=0; //sscanf in unbelievably slow on looong strings //FIXME copy / do not write next++; } e= sscanf(p, " in:%d ", &picture_number); @@ -184,7 +184,7 @@ int ff_rate_control_init(MpegEncContext *s) //FIXME maybe move to end if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID) { -#ifdef CONFIG_XVID +#ifdef CONFIG_LIBXVID return ff_xvid_rate_control_init(s); #else av_log(s->avctx, AV_LOG_ERROR, "XviD ratecontrol requires libavcodec compiled with XviD support\n"); @@ -201,6 +201,10 @@ int ff_rate_control_init(MpegEncContext *s) rcc->pass1_rc_eq_output_sum= 0.001; rcc->pass1_wanted_bits=0.001; + if(s->avctx->qblur > 1.0){ + av_log(s->avctx, AV_LOG_ERROR, "qblur too large\n"); + return -1; + } /* init stuff with the user specified complexity */ if(s->avctx->rc_initial_cplx){ for(i=0; i<60*30; i++){ @@ -239,7 +243,7 @@ int ff_rate_control_init(MpegEncContext *s) bits= rce.i_tex_bits + rce.p_tex_bits; q= get_qscale(s, &rce, rcc->pass1_wanted_bits/rcc->pass1_rc_eq_output_sum, i); - rcc->pass1_wanted_bits+= s->bit_rate/(1/av_q2d(s->avctx->time_base)); //FIXME missbehaves a little for variable fps + rcc->pass1_wanted_bits+= s->bit_rate/(1/av_q2d(s->avctx->time_base)); //FIXME misbehaves a little for variable fps } } @@ -256,7 +260,7 @@ void ff_rate_control_uninit(MpegEncContext *s) ff_eval_free(rcc->rc_eq_eval); av_freep(&rcc->entry); -#ifdef CONFIG_XVID +#ifdef CONFIG_LIBXVID if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID) ff_xvid_rate_control_uninit(s); #endif @@ -367,6 +371,7 @@ static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_f q= -q*s->avctx->i_quant_factor + s->avctx->i_quant_offset; else if(pict_type==B_TYPE && s->avctx->b_quant_factor<0.0) q= -q*s->avctx->b_quant_factor + s->avctx->b_quant_offset; + if(q<1) q=1; return q; } @@ -382,6 +387,7 @@ static double get_diff_limited_q(MpegEncContext *s, RateControlEntry *rce, doubl q= last_p_q *FFABS(a->i_quant_factor) + a->i_quant_offset; else if(pict_type==B_TYPE && a->b_quant_factor>0.0) q= last_non_b_q* a->b_quant_factor + a->b_quant_offset; + if(q<1) q=1; /* last qscale / qdiff stuff */ if(rcc->last_non_b_pict_type==pict_type || pict_type!=I_TYPE){ @@ -392,7 +398,7 @@ static double get_diff_limited_q(MpegEncContext *s, RateControlEntry *rce, doubl else if(q < last_q - maxdiff) q= last_q - maxdiff; } - rcc->last_qscale_for[pict_type]= q; //Note we cant do that after blurring + rcc->last_qscale_for[pict_type]= q; //Note we cannot do that after blurring if(pict_type!=B_TYPE) rcc->last_non_b_pict_type= pict_type; @@ -601,7 +607,7 @@ static void adaptive_quantization(MpegEncContext *s, double q){ bits_tab[i]= bits; } - /* handle qmin/qmax cliping */ + /* handle qmin/qmax clipping */ if(s->flags&CODEC_FLAG_NORMALIZE_AQP){ float factor= bits_sum/cplx_sum; for(i=0; imb_num; i++){ @@ -672,7 +678,7 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run) Picture * const pic= &s->current_picture; emms_c(); -#ifdef CONFIG_XVID +#ifdef CONFIG_LIBXVID if((s->flags&CODEC_FLAG_PASS2) && s->avctx->rc_strategy == FF_RC_STRATEGY_XVID) return ff_xvid_rate_estimate_qscale(s, dry_run); #endif @@ -693,8 +699,23 @@ float ff_rate_estimate_qscale(MpegEncContext *s, int dry_run) rce= &rcc->entry[picture_number]; wanted_bits= rce->expected_bits; }else{ + Picture *dts_pic; rce= &local_rce; - wanted_bits= (uint64_t)(s->bit_rate*(double)picture_number/fps); + + //FIXME add a dts field to AVFrame and ensure its set and use it here instead of reordering + //but the reordering is simpler for now until h.264 b pyramid must be handeld + if(s->pict_type == B_TYPE || s->low_delay) + dts_pic= s->current_picture_ptr; + else + dts_pic= s->last_picture_ptr; + +//if(dts_pic) +// av_log(NULL, AV_LOG_ERROR, "%Ld %Ld %Ld %d\n", s->current_picture_ptr->pts, s->user_specified_pts, dts_pic->pts, picture_number); + + if(!dts_pic || dts_pic->pts == AV_NOPTS_VALUE) + wanted_bits= (uint64_t)(s->bit_rate*(double)picture_number/fps); + else + wanted_bits= (uint64_t)(s->bit_rate*(double)dts_pic->pts/fps); } diff= s->total_bits - wanted_bits; diff --git a/contrib/ffmpeg/libavcodec/ratecontrol.h b/contrib/ffmpeg/libavcodec/ratecontrol.h index c428923a5..8704b4301 100644 --- a/contrib/ffmpeg/libavcodec/ratecontrol.h +++ b/contrib/ffmpeg/libavcodec/ratecontrol.h @@ -20,14 +20,16 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVCODEC_RATECONTROL_H -#define AVCODEC_RATECONTROL_H +#ifndef FFMPEG_RATECONTROL_H +#define FFMPEG_RATECONTROL_H /** * @file ratecontrol.h * ratecontrol header. */ +#include +#include #include "eval.h" typedef struct Predictor{ @@ -99,5 +101,5 @@ int ff_xvid_rate_control_init(struct MpegEncContext *s); void ff_xvid_rate_control_uninit(struct MpegEncContext *s); float ff_xvid_rate_estimate_qscale(struct MpegEncContext *s, int dry_run); -#endif /* AVCODEC_RATECONTROL_H */ +#endif /* FFMPEG_RATECONTROL_H */ diff --git a/contrib/ffmpeg/libavcodec/raw.c b/contrib/ffmpeg/libavcodec/raw.c index 268779803..d0cf50d9e 100644 --- a/contrib/ffmpeg/libavcodec/raw.c +++ b/contrib/ffmpeg/libavcodec/raw.c @@ -25,19 +25,9 @@ */ #include "avcodec.h" +#include "raw.h" -typedef struct RawVideoContext { - unsigned char * buffer; /* block of memory for holding one frame */ - int length; /* number of bytes in buffer */ - AVFrame pic; ///< AVCodecContext.coded_frame -} RawVideoContext; - -typedef struct PixelFormatTag { - int pix_fmt; - unsigned int fourcc; -} PixelFormatTag; - -static const PixelFormatTag pixelFormatTags[] = { +const PixelFormatTag ff_raw_pixelFormatTags[] = { { PIX_FMT_YUV420P, MKTAG('I', '4', '2', '0') }, /* Planar formats */ { PIX_FMT_YUV420P, MKTAG('I', 'Y', 'U', 'V') }, { PIX_FMT_YUV420P, MKTAG('Y', 'V', '1', '2') }, @@ -51,6 +41,7 @@ static const PixelFormatTag pixelFormatTags[] = { { PIX_FMT_YUYV422, MKTAG('Y', 'U', 'Y', '2') }, /* Packed formats */ { PIX_FMT_YUYV422, MKTAG('Y', '4', '2', '2') }, { PIX_FMT_UYVY422, MKTAG('U', 'Y', 'V', 'Y') }, + { PIX_FMT_UYVY422, MKTAG('H', 'D', 'Y', 'C') }, { PIX_FMT_GRAY8, MKTAG('G', 'R', 'E', 'Y') }, { PIX_FMT_RGB555, MKTAG('R', 'G', 'B', 15) }, { PIX_FMT_BGR555, MKTAG('B', 'G', 'R', 15) }, @@ -64,38 +55,9 @@ static const PixelFormatTag pixelFormatTags[] = { { -1, 0 }, }; -static const PixelFormatTag pixelFormatBpsAVI[] = { - { PIX_FMT_PAL8, 8 }, - { PIX_FMT_RGB555, 15 }, - { PIX_FMT_RGB555, 16 }, - { PIX_FMT_BGR24, 24 }, - { PIX_FMT_RGB32, 32 }, - { -1, 0 }, -}; - -static const PixelFormatTag pixelFormatBpsMOV[] = { - /* FIXME fix swscaler to support those */ - /* http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html */ - { PIX_FMT_PAL8, 8 }, - { PIX_FMT_BGR555, 16 }, - { PIX_FMT_RGB24, 24 }, - { PIX_FMT_BGR32_1, 32 }, - { -1, 0 }, -}; - -static int findPixelFormat(const PixelFormatTag *tags, unsigned int fourcc) -{ - while (tags->pix_fmt >= 0) { - if (tags->fourcc == fourcc) - return tags->pix_fmt; - tags++; - } - return PIX_FMT_YUV420P; -} - unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat fmt) { - const PixelFormatTag * tags = pixelFormatTags; + const PixelFormatTag * tags = ff_raw_pixelFormatTags; while (tags->pix_fmt >= 0) { if (tags->pix_fmt == fmt) return tags->fourcc; @@ -103,122 +65,3 @@ unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat fmt) } return 0; } - -/* RAW Decoder Implementation */ - -static int raw_init_decoder(AVCodecContext *avctx) -{ - RawVideoContext *context = avctx->priv_data; - - if (avctx->codec_tag == MKTAG('r','a','w',' ')) - avctx->pix_fmt = findPixelFormat(pixelFormatBpsMOV, avctx->bits_per_sample); - else if (avctx->codec_tag) - avctx->pix_fmt = findPixelFormat(pixelFormatTags, avctx->codec_tag); - else if (avctx->bits_per_sample) - avctx->pix_fmt = findPixelFormat(pixelFormatBpsAVI, avctx->bits_per_sample); - - context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); - context->buffer = av_malloc(context->length); - context->pic.pict_type = FF_I_TYPE; - context->pic.key_frame = 1; - - avctx->coded_frame= &context->pic; - - if (!context->buffer) - return -1; - - return 0; -} - -static void flip(AVCodecContext *avctx, AVPicture * picture){ - if(!avctx->codec_tag && avctx->bits_per_sample && picture->linesize[2]==0){ - picture->data[0] += picture->linesize[0] * (avctx->height-1); - picture->linesize[0] *= -1; - } -} - -static int raw_decode(AVCodecContext *avctx, - void *data, int *data_size, - uint8_t *buf, int buf_size) -{ - RawVideoContext *context = avctx->priv_data; - - AVFrame * frame = (AVFrame *) data; - AVPicture * picture = (AVPicture *) data; - - frame->interlaced_frame = avctx->coded_frame->interlaced_frame; - frame->top_field_first = avctx->coded_frame->top_field_first; - - if(buf_size < context->length - (avctx->pix_fmt==PIX_FMT_PAL8 ? 256*4 : 0)) - return -1; - - avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height); - if(avctx->pix_fmt==PIX_FMT_PAL8 && buf_size < context->length){ - frame->data[1]= context->buffer; - } - if (avctx->palctrl && avctx->palctrl->palette_changed) { - memcpy(frame->data[1], avctx->palctrl->palette, AVPALETTE_SIZE); - avctx->palctrl->palette_changed = 0; - } - - flip(avctx, picture); - - if (avctx->codec_tag == MKTAG('Y', 'V', '1', '2')) - { - // swap fields - unsigned char *tmp = picture->data[1]; - picture->data[1] = picture->data[2]; - picture->data[2] = tmp; - } - - *data_size = sizeof(AVPicture); - return buf_size; -} - -static int raw_close_decoder(AVCodecContext *avctx) -{ - RawVideoContext *context = avctx->priv_data; - - av_freep(&context->buffer); - return 0; -} - -/* RAW Encoder Implementation */ -#ifdef CONFIG_RAWVIDEO_ENCODER -static int raw_init_encoder(AVCodecContext *avctx) -{ - avctx->coded_frame = (AVFrame *)avctx->priv_data; - avctx->coded_frame->pict_type = FF_I_TYPE; - avctx->coded_frame->key_frame = 1; - if(!avctx->codec_tag) - avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); - return 0; -} - -static int raw_encode(AVCodecContext *avctx, - unsigned char *frame, int buf_size, void *data) -{ - return avpicture_layout((AVPicture *)data, avctx->pix_fmt, avctx->width, - avctx->height, frame, buf_size); -} - -AVCodec rawvideo_encoder = { - "rawvideo", - CODEC_TYPE_VIDEO, - CODEC_ID_RAWVIDEO, - sizeof(AVFrame), - raw_init_encoder, - raw_encode, -}; -#endif // CONFIG_RAWVIDEO_ENCODER - -AVCodec rawvideo_decoder = { - "rawvideo", - CODEC_TYPE_VIDEO, - CODEC_ID_RAWVIDEO, - sizeof(RawVideoContext), - raw_init_decoder, - NULL, - raw_close_decoder, - raw_decode, -}; diff --git a/contrib/ffmpeg/libavcodec/raw.h b/contrib/ffmpeg/libavcodec/raw.h new file mode 100644 index 000000000..1110114e2 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/raw.h @@ -0,0 +1,39 @@ +/* + * Raw Video Codec + * Copyright (c) 2001 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file raw.h + * Raw Video Codec + */ + +#ifndef FFMPEG_RAW_H +#define FFMPEG_RAW_H + +#include "avcodec.h" + +typedef struct PixelFormatTag { + int pix_fmt; + unsigned int fourcc; +} PixelFormatTag; + +extern const PixelFormatTag ff_raw_pixelFormatTags[]; + +#endif /* FFMPEG_RAW_H */ diff --git a/contrib/ffmpeg/libavcodec/rawdec.c b/contrib/ffmpeg/libavcodec/rawdec.c new file mode 100644 index 000000000..11d2a185e --- /dev/null +++ b/contrib/ffmpeg/libavcodec/rawdec.c @@ -0,0 +1,165 @@ +/* + * Raw Video Decoder + * Copyright (c) 2001 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file rawdec.c + * Raw Video Decoder + */ + +#include "avcodec.h" +#include "raw.h" + +typedef struct RawVideoContext { + unsigned char * buffer; /* block of memory for holding one frame */ + int length; /* number of bytes in buffer */ + AVFrame pic; ///< AVCodecContext.coded_frame +} RawVideoContext; + +static const PixelFormatTag pixelFormatBpsAVI[] = { + { PIX_FMT_PAL8, 4 }, + { PIX_FMT_PAL8, 8 }, + { PIX_FMT_RGB555, 15 }, + { PIX_FMT_RGB555, 16 }, + { PIX_FMT_BGR24, 24 }, + { PIX_FMT_RGB32, 32 }, + { -1, 0 }, +}; + +static const PixelFormatTag pixelFormatBpsMOV[] = { + /* FIXME fix swscaler to support those */ + /* http://developer.apple.com/documentation/QuickTime/QTFF/QTFFChap3/chapter_4_section_2.html */ + { PIX_FMT_PAL8, 4 }, + { PIX_FMT_PAL8, 8 }, + { PIX_FMT_BGR555, 16 }, + { PIX_FMT_RGB24, 24 }, + { PIX_FMT_BGR32_1, 32 }, + { -1, 0 }, +}; + +static int findPixelFormat(const PixelFormatTag *tags, unsigned int fourcc) +{ + while (tags->pix_fmt >= 0) { + if (tags->fourcc == fourcc) + return tags->pix_fmt; + tags++; + } + return PIX_FMT_YUV420P; +} + +static int raw_init_decoder(AVCodecContext *avctx) +{ + RawVideoContext *context = avctx->priv_data; + + if (avctx->codec_tag == MKTAG('r','a','w',' ')) + avctx->pix_fmt = findPixelFormat(pixelFormatBpsMOV, avctx->bits_per_sample); + else if (avctx->codec_tag) + avctx->pix_fmt = findPixelFormat(ff_raw_pixelFormatTags, avctx->codec_tag); + else if (avctx->bits_per_sample) + avctx->pix_fmt = findPixelFormat(pixelFormatBpsAVI, avctx->bits_per_sample); + + context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); + context->buffer = av_malloc(context->length); + context->pic.pict_type = FF_I_TYPE; + context->pic.key_frame = 1; + + avctx->coded_frame= &context->pic; + + if (!context->buffer) + return -1; + + return 0; +} + +static void flip(AVCodecContext *avctx, AVPicture * picture){ + if(!avctx->codec_tag && avctx->bits_per_sample && picture->linesize[2]==0){ + picture->data[0] += picture->linesize[0] * (avctx->height-1); + picture->linesize[0] *= -1; + } +} + +static int raw_decode(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size) +{ + RawVideoContext *context = avctx->priv_data; + + AVFrame * frame = (AVFrame *) data; + AVPicture * picture = (AVPicture *) data; + + frame->interlaced_frame = avctx->coded_frame->interlaced_frame; + frame->top_field_first = avctx->coded_frame->top_field_first; + + //4bpp raw in avi and mov (yes this is ugly ...) + if(avctx->bits_per_sample == 4 && avctx->pix_fmt==PIX_FMT_PAL8 && + (!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))){ + int i; + for(i=256*2; i+1 < context->length>>1; i++){ + context->buffer[2*i+0]= buf[i-256*2]>>4; + context->buffer[2*i+1]= buf[i-256*2]&15; + } + buf= context->buffer + 256*4; + buf_size= context->length - 256*4; + } + + if(buf_size < context->length - (avctx->pix_fmt==PIX_FMT_PAL8 ? 256*4 : 0)) + return -1; + + avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height); + if(avctx->pix_fmt==PIX_FMT_PAL8 && buf_size < context->length){ + frame->data[1]= context->buffer; + } + if (avctx->palctrl && avctx->palctrl->palette_changed) { + memcpy(frame->data[1], avctx->palctrl->palette, AVPALETTE_SIZE); + avctx->palctrl->palette_changed = 0; + } + + flip(avctx, picture); + + if (avctx->codec_tag == MKTAG('Y', 'V', '1', '2')) + { + // swap fields + unsigned char *tmp = picture->data[1]; + picture->data[1] = picture->data[2]; + picture->data[2] = tmp; + } + + *data_size = sizeof(AVPicture); + return buf_size; +} + +static int raw_close_decoder(AVCodecContext *avctx) +{ + RawVideoContext *context = avctx->priv_data; + + av_freep(&context->buffer); + return 0; +} + +AVCodec rawvideo_decoder = { + "rawvideo", + CODEC_TYPE_VIDEO, + CODEC_ID_RAWVIDEO, + sizeof(RawVideoContext), + raw_init_decoder, + NULL, + raw_close_decoder, + raw_decode, +}; diff --git a/contrib/ffmpeg/libavcodec/rawenc.c b/contrib/ffmpeg/libavcodec/rawenc.c new file mode 100644 index 000000000..61608bcc3 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/rawenc.c @@ -0,0 +1,54 @@ +/* + * Raw Video Encoder + * Copyright (c) 2001 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file rawenc.c + * Raw Video Encoder + */ + +#include "avcodec.h" +#include "raw.h" + +static int raw_init_encoder(AVCodecContext *avctx) +{ + avctx->coded_frame = (AVFrame *)avctx->priv_data; + avctx->coded_frame->pict_type = FF_I_TYPE; + avctx->coded_frame->key_frame = 1; + if(!avctx->codec_tag) + avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); + return 0; +} + +static int raw_encode(AVCodecContext *avctx, + unsigned char *frame, int buf_size, void *data) +{ + return avpicture_layout((AVPicture *)data, avctx->pix_fmt, avctx->width, + avctx->height, frame, buf_size); +} + +AVCodec rawvideo_encoder = { + "rawvideo", + CODEC_TYPE_VIDEO, + CODEC_ID_RAWVIDEO, + sizeof(AVFrame), + raw_init_encoder, + raw_encode, +}; diff --git a/contrib/ffmpeg/libavcodec/rectangle.h b/contrib/ffmpeg/libavcodec/rectangle.h new file mode 100644 index 000000000..4dd9028f1 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/rectangle.h @@ -0,0 +1,121 @@ +/* + * rectangle filling function + * Copyright (c) 2003 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file rectangle.h + * useful rectangle filling function + * @author Michael Niedermayer + */ + +#ifndef FFMPEG_RECTANGLE_H +#define FFMPEG_RECTANGLE_H + +#include "common.h" + +/** + * fill a rectangle. + * @param h height of the rectangle, should be a constant + * @param w width of the rectangle, should be a constant + * @param size the size of val (1 or 4), should be a constant + */ +static av_always_inline void fill_rectangle(void *vp, int w, int h, int stride, uint32_t val, int size){ + uint8_t *p= (uint8_t*)vp; + assert(size==1 || size==4); + assert(w<=4); + + w *= size; + stride *= size; + + assert((((long)vp)&(FFMIN(w, STRIDE_ALIGN)-1)) == 0); + assert((stride&(w-1))==0); + if(w==2){ + const uint16_t v= size==4 ? val : val*0x0101; + *(uint16_t*)(p + 0*stride)= v; + if(h==1) return; + *(uint16_t*)(p + 1*stride)= v; + if(h==2) return; + *(uint16_t*)(p + 2*stride)= v; + *(uint16_t*)(p + 3*stride)= v; + }else if(w==4){ + const uint32_t v= size==4 ? val : val*0x01010101; + *(uint32_t*)(p + 0*stride)= v; + if(h==1) return; + *(uint32_t*)(p + 1*stride)= v; + if(h==2) return; + *(uint32_t*)(p + 2*stride)= v; + *(uint32_t*)(p + 3*stride)= v; + }else if(w==8){ + //gcc can't optimize 64bit math on x86_32 +#if defined(ARCH_X86_64) || (defined(MP_WORDSIZE) && MP_WORDSIZE >= 64) + const uint64_t v= val*0x0100000001ULL; + *(uint64_t*)(p + 0*stride)= v; + if(h==1) return; + *(uint64_t*)(p + 1*stride)= v; + if(h==2) return; + *(uint64_t*)(p + 2*stride)= v; + *(uint64_t*)(p + 3*stride)= v; + }else if(w==16){ + const uint64_t v= val*0x0100000001ULL; + *(uint64_t*)(p + 0+0*stride)= v; + *(uint64_t*)(p + 8+0*stride)= v; + *(uint64_t*)(p + 0+1*stride)= v; + *(uint64_t*)(p + 8+1*stride)= v; + if(h==2) return; + *(uint64_t*)(p + 0+2*stride)= v; + *(uint64_t*)(p + 8+2*stride)= v; + *(uint64_t*)(p + 0+3*stride)= v; + *(uint64_t*)(p + 8+3*stride)= v; +#else + *(uint32_t*)(p + 0+0*stride)= val; + *(uint32_t*)(p + 4+0*stride)= val; + if(h==1) return; + *(uint32_t*)(p + 0+1*stride)= val; + *(uint32_t*)(p + 4+1*stride)= val; + if(h==2) return; + *(uint32_t*)(p + 0+2*stride)= val; + *(uint32_t*)(p + 4+2*stride)= val; + *(uint32_t*)(p + 0+3*stride)= val; + *(uint32_t*)(p + 4+3*stride)= val; + }else if(w==16){ + *(uint32_t*)(p + 0+0*stride)= val; + *(uint32_t*)(p + 4+0*stride)= val; + *(uint32_t*)(p + 8+0*stride)= val; + *(uint32_t*)(p +12+0*stride)= val; + *(uint32_t*)(p + 0+1*stride)= val; + *(uint32_t*)(p + 4+1*stride)= val; + *(uint32_t*)(p + 8+1*stride)= val; + *(uint32_t*)(p +12+1*stride)= val; + if(h==2) return; + *(uint32_t*)(p + 0+2*stride)= val; + *(uint32_t*)(p + 4+2*stride)= val; + *(uint32_t*)(p + 8+2*stride)= val; + *(uint32_t*)(p +12+2*stride)= val; + *(uint32_t*)(p + 0+3*stride)= val; + *(uint32_t*)(p + 4+3*stride)= val; + *(uint32_t*)(p + 8+3*stride)= val; + *(uint32_t*)(p +12+3*stride)= val; +#endif + }else + assert(0); + assert(h==4); +} + +#endif /* FFMPEG_RECTANGLE_H */ diff --git a/contrib/ffmpeg/libavcodec/remove_extradata_bsf.c b/contrib/ffmpeg/libavcodec/remove_extradata_bsf.c new file mode 100644 index 000000000..95bd98bef --- /dev/null +++ b/contrib/ffmpeg/libavcodec/remove_extradata_bsf.c @@ -0,0 +1,55 @@ +/* + * copyright (c) 2006 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" + + +static int remove_extradata(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, + uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size, int keyframe){ + int cmd= args ? *args : 0; + AVCodecParserContext *s; + + if(!bsfc->parser){ + bsfc->parser= av_parser_init(avctx->codec_id); + } + s= bsfc->parser; + + if(s && s->parser->split){ + if( (((avctx->flags & CODEC_FLAG_GLOBAL_HEADER) || (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)) && cmd=='a') + ||(!keyframe && cmd=='k') + ||(cmd=='e' || !cmd) + ){ + int i= s->parser->split(avctx, buf, buf_size); + buf += i; + buf_size -= i; + } + } + *poutbuf= (uint8_t *) buf; + *poutbuf_size= buf_size; + + return 0; +} + +AVBitStreamFilter remove_extradata_bsf={ + "remove_extra", + 0, + remove_extradata, +}; diff --git a/contrib/ffmpeg/libavcodec/resample.c b/contrib/ffmpeg/libavcodec/resample.c index ea5c6d61c..c6547d8d8 100644 --- a/contrib/ffmpeg/libavcodec/resample.c +++ b/contrib/ffmpeg/libavcodec/resample.c @@ -1,5 +1,5 @@ /* - * Sample rate convertion for both audio and video + * samplerate conversion for both audio and video * Copyright (c) 2000 Fabrice Bellard. * * This file is part of FFmpeg. @@ -21,7 +21,7 @@ /** * @file resample.c - * Sample rate convertion for both audio and video. + * samplerate conversion for both audio and video */ #include "avcodec.h" @@ -133,14 +133,14 @@ ReSampleContext *audio_resample_init(int output_channels, int input_channels, if ( input_channels > 2) { - av_log(NULL, AV_LOG_ERROR, "Resampling with input channels greater than 2 unsupported."); + av_log(NULL, AV_LOG_ERROR, "Resampling with input channels greater than 2 unsupported.\n"); return NULL; } s = av_mallocz(sizeof(ReSampleContext)); if (!s) { - av_log(NULL, AV_LOG_ERROR, "Can't allocate memory for resample context."); + av_log(NULL, AV_LOG_ERROR, "Can't allocate memory for resample context.\n"); return NULL; } @@ -185,15 +185,15 @@ int audio_resample(ReSampleContext *s, short *output, short *input, int nb_sampl /* XXX: move those malloc to resample init code */ for(i=0; ifilter_channels; i++){ - bufin[i]= (short*) av_malloc( (nb_samples + s->temp_len) * sizeof(short) ); + bufin[i]= av_malloc( (nb_samples + s->temp_len) * sizeof(short) ); memcpy(bufin[i], s->temp[i], s->temp_len * sizeof(short)); buftmp2[i] = bufin[i] + s->temp_len; } /* make some zoom to avoid round pb */ - lenout= (int)(nb_samples * s->ratio) + 16; - bufout[0]= (short*) av_malloc( lenout * sizeof(short) ); - bufout[1]= (short*) av_malloc( lenout * sizeof(short) ); + lenout= 4*nb_samples * s->ratio + 16; + bufout[0]= av_malloc( lenout * sizeof(short) ); + bufout[1]= av_malloc( lenout * sizeof(short) ); if (s->input_channels == 2 && s->output_channels == 1) { diff --git a/contrib/ffmpeg/libavcodec/resample2.c b/contrib/ffmpeg/libavcodec/resample2.c index 4209b9705..da1443d98 100644 --- a/contrib/ffmpeg/libavcodec/resample2.c +++ b/contrib/ffmpeg/libavcodec/resample2.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -27,7 +26,6 @@ */ #include "avcodec.h" -#include "common.h" #include "dsputil.h" #ifndef CONFIG_RESAMPLE_HP @@ -95,7 +93,7 @@ static double bessel(double x){ * @param type 0->cubic, 1->blackman nuttall windowed sinc, 2..16->kaiser windowed sinc beta=2..16 */ void av_build_filter(FELEM *filter, double factor, int tap_count, int phase_count, int scale, int type){ - int ph, i, v; + int ph, i; double x, y, w, tab[tap_count]; const int center= (tap_count-1)/2; @@ -178,8 +176,8 @@ void av_build_filter(FELEM *filter, double factor, int tap_count, int phase_coun } /** - * initalizes a audio resampler. - * note, if either rate is not a integer then simply scale both rates up so they are + * Initializes an audio resampler. + * Note, if either rate is not an integer then simply scale both rates up so they are. */ AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff){ AVResampleContext *c= av_mallocz(sizeof(AVResampleContext)); @@ -281,7 +279,7 @@ int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int } #ifdef CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE - dst[dst_index] = av_clip(lrintf(val), -32768, 32767); + dst[dst_index] = av_clip_int16(lrintf(val)); #else val = (val + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT; dst[dst_index] = (unsigned)(val + 32768) > 65535 ? (val>>31) ^ 32767 : val; diff --git a/contrib/ffmpeg/libavcodec/rl.h b/contrib/ffmpeg/libavcodec/rl.h index 1c2aae25a..ecea2c891 100644 --- a/contrib/ffmpeg/libavcodec/rl.h +++ b/contrib/ffmpeg/libavcodec/rl.h @@ -1,10 +1,35 @@ +/* + * Copyright (c) 2000-2002 Fabrice Bellard + * Copyright (c) 2002-2004 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + /** * @file rl.h * rl header. */ -#ifndef AVCODEC_RL_H -#define AVCODEC_RL_H +#ifndef FFMPEG_RL_H +#define FFMPEG_RL_H + +#include +#include "bitstream.h" +#include "mpegvideo.h" /** RLTable. */ typedef struct RLTable { @@ -16,7 +41,7 @@ typedef struct RLTable { uint8_t *index_run[2]; ///< encoding only int8_t *max_level[2]; ///< encoding & decoding int8_t *max_run[2]; ///< encoding & decoding - VLC vlc; ///< decoding only deprected FIXME remove + VLC vlc; ///< decoding only deprecated FIXME remove RL_VLC_ELEM *rl_vlc[32]; ///< decoding only } RLTable; @@ -39,4 +64,4 @@ static inline int get_rl_index(const RLTable *rl, int last, int run, int level) return index + level - 1; } -#endif +#endif /* FFMPEG_RL_H */ diff --git a/contrib/ffmpeg/libavcodec/rle.c b/contrib/ffmpeg/libavcodec/rle.c new file mode 100644 index 000000000..2fb0d0e48 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/rle.c @@ -0,0 +1,84 @@ +/* + * RLE encoder + * Copyright (c) 2007 Bobby Bingham + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avcodec.h" +#include "rle.h" + +/** + * Count up to 127 consecutive pixels which are either all the same or + * all differ from the previous and next pixels. + * @param start Pointer to the first pixel + * @param len Maximum number of pixels + * @param bpp Bytes per pixel + * @param same 1 if searching for identical pixel values. 0 for differing + * @return Number of matching consecutive pixels found + */ +static int count_pixels(const uint8_t *start, int len, int bpp, int same) +{ + const uint8_t *pos; + int count = 1; + + for(pos = start + bpp; count < FFMIN(128, len); pos += bpp, count ++) { + if(same != !memcmp(pos-bpp, pos, bpp)) { + if(!same) { + /* if bpp == 1, then 0 1 1 0 is more efficiently encoded as a single + * raw block of pixels. for larger bpp, RLE is as good or better */ + if(bpp == 1 && count + 1 < FFMIN(128, len) && *pos != *(pos+1)) + continue; + + /* if RLE can encode the next block better than as a raw block, + * back up and leave _all_ the identical pixels for RLE */ + count --; + } + break; + } + } + + return count; +} + +int ff_rle_encode(uint8_t *outbuf, int out_size, const uint8_t *ptr , int bpp, int w, + int add_rep, int xor_rep, int add_raw, int xor_raw) +{ + int count, x; + uint8_t *out = outbuf; + + for(x = 0; x < w; x += count) { + /* see if we can encode the next set of pixels with RLE */ + if((count = count_pixels(ptr, w-x, bpp, 1)) > 1) { + if(out + bpp + 1 > outbuf + out_size) return -1; + *out++ = (count ^ xor_rep) + add_rep; + memcpy(out, ptr, bpp); + out += bpp; + } else { + /* fall back on uncompressed */ + count = count_pixels(ptr, w-x, bpp, 0); + *out++ = (count ^ xor_raw) + add_raw; + + if(out + bpp*count > outbuf + out_size) return -1; + memcpy(out, ptr, bpp * count); + out += bpp * count; + } + + ptr += count * bpp; + } + + return out - outbuf; +} diff --git a/contrib/ffmpeg/libavcodec/rle.h b/contrib/ffmpeg/libavcodec/rle.h new file mode 100644 index 000000000..14d07084f --- /dev/null +++ b/contrib/ffmpeg/libavcodec/rle.h @@ -0,0 +1,39 @@ +/* + * RLE encoder + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_RLE_H +#define FFMPEG_RLE_H + +#include + +/** + * RLE compress the row, with maximum size of out_size. Value before repeated bytes is (count ^ xor_rep) + add_rep. + * Value before raw bytes is (count ^ xor_raw) + add_raw. + * @param outbuf Output buffer + * @param out_size Maximum output size + * @param ptr Input buffer + * @param bpp Bytes per pixel + * @param w Image width + * @return Size of output in bytes, or -1 if larger than out_size + */ +int ff_rle_encode(uint8_t *outbuf, int out_size, const uint8_t *inbuf, int bpp, int w, + int add_rep, int xor_rep, int add_raw, int xor_raw); + +#endif /* FFMPEG_RLE_H */ diff --git a/contrib/ffmpeg/libavcodec/roqaudioenc.c b/contrib/ffmpeg/libavcodec/roqaudioenc.c new file mode 100644 index 000000000..f76079e1d --- /dev/null +++ b/contrib/ffmpeg/libavcodec/roqaudioenc.c @@ -0,0 +1,177 @@ +/* + * RoQ audio encoder + * + * Copyright (c) 2005 Eric Lasota + * Based on RoQ specs (c)2001 Tim Ferguson + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "bytestream.h" + +#define ROQ_FIRST_FRAME_SIZE (735*8) +#define ROQ_FRAME_SIZE 735 + + +#define MAX_DPCM (127*127) +static unsigned char dpcmValues[MAX_DPCM]; + + +typedef struct +{ + short lastSample[2]; +} ROQDPCMContext_t; + +static void roq_dpcm_table_init(void) +{ + int i; + + /* Create a table of quick DPCM values */ + for (i=0; imid); + } +} + +static int roq_dpcm_encode_init(AVCodecContext *avctx) +{ + ROQDPCMContext_t *context = avctx->priv_data; + + if (avctx->channels > 2) { + av_log(avctx, AV_LOG_ERROR, "Audio must be mono or stereo\n"); + return -1; + } + if (avctx->sample_rate != 22050) { + av_log(avctx, AV_LOG_ERROR, "Audio must be 22050 Hz\n"); + return -1; + } + if (avctx->sample_fmt != SAMPLE_FMT_S16) { + av_log(avctx, AV_LOG_ERROR, "Audio must be signed 16-bit\n"); + return -1; + } + + roq_dpcm_table_init(); + + avctx->frame_size = ROQ_FIRST_FRAME_SIZE; + + context->lastSample[0] = context->lastSample[1] = 0; + + avctx->coded_frame= avcodec_alloc_frame(); + avctx->coded_frame->key_frame= 1; + + return 0; +} + +static unsigned char dpcm_predict(short *previous, short current) +{ + int diff; + int negative; + int result; + int predicted; + + diff = current - *previous; + + negative = diff<0; + diff = FFABS(diff); + + if (diff >= MAX_DPCM) + result = 127; + else + result = dpcmValues[diff]; + + /* See if this overflows */ + retry: + diff = result*result; + if (negative) + diff = -diff; + predicted = *previous + diff; + + /* If it overflows, back off a step */ + if (predicted > 32767 || predicted < -32768) { + result--; + goto retry; + } + + /* Add the sign bit */ + result |= negative << 7; //if (negative) result |= 128; + + *previous = predicted; + + return result; +} + +static int roq_dpcm_encode_frame(AVCodecContext *avctx, + unsigned char *frame, int buf_size, void *data) +{ + int i, samples, stereo, ch; + short *in; + unsigned char *out; + + ROQDPCMContext_t *context = avctx->priv_data; + + stereo = (avctx->channels == 2); + + if (stereo) { + context->lastSample[0] &= 0xFF00; + context->lastSample[1] &= 0xFF00; + } + + out = frame; + in = data; + + bytestream_put_byte(&out, stereo ? 0x21 : 0x20); + bytestream_put_byte(&out, 0x10); + bytestream_put_le32(&out, avctx->frame_size*avctx->channels); + + if (stereo) { + bytestream_put_byte(&out, (context->lastSample[1])>>8); + bytestream_put_byte(&out, (context->lastSample[0])>>8); + } else + bytestream_put_le16(&out, context->lastSample[0]); + + /* Write the actual samples */ + samples = avctx->frame_size; + for (i=0; ichannels; ch++) + *out++ = dpcm_predict(&context->lastSample[ch], *in++); + + /* Use smaller frames from now on */ + avctx->frame_size = ROQ_FRAME_SIZE; + + /* Return the result size */ + return out - frame; +} + +static int roq_dpcm_encode_close(AVCodecContext *avctx) +{ + av_freep(&avctx->coded_frame); + + return 0; +} + +AVCodec roq_dpcm_encoder = { + "roq_dpcm", + CODEC_TYPE_AUDIO, + CODEC_ID_ROQ_DPCM, + sizeof(ROQDPCMContext_t), + roq_dpcm_encode_init, + roq_dpcm_encode_frame, + roq_dpcm_encode_close, + NULL, +}; diff --git a/contrib/ffmpeg/libavcodec/roqvideo.c b/contrib/ffmpeg/libavcodec/roqvideo.c index 2a9aa6242..53d60a19e 100644 --- a/contrib/ffmpeg/libavcodec/roqvideo.c +++ b/contrib/ffmpeg/libavcodec/roqvideo.c @@ -1,5 +1,6 @@ /* - * Copyright (C) 2003 the ffmpeg project + * Copyright (C) 2003 Mike Melanson + * Copyright (C) 2003 Dr. Tim Ferguson * * This file is part of FFmpeg. * @@ -16,462 +17,122 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** * @file roqvideo.c - * Id RoQ Video Decoder by Dr. Tim Ferguson - * For more information about the Id RoQ format, visit: - * http://www.csse.monash.edu.au/~timf/ + * Id RoQ Video common functions based on work by Dr. Tim Ferguson */ -#include -#include -#include -#include - -#include "common.h" #include "avcodec.h" -#include "dsputil.h" - -typedef struct { - unsigned char y0, y1, y2, y3, u, v; -} roq_cell; - -typedef struct { - int idx[4]; -} roq_qcell; - -static int uiclip[1024], *uiclp; /* clipping table */ -#define avg2(a,b) uiclp[(((int)(a)+(int)(b)+1)>>1)] -#define avg4(a,b,c,d) uiclp[(((int)(a)+(int)(b)+(int)(c)+(int)(d)+2)>>2)] - -typedef struct RoqContext { - - AVCodecContext *avctx; - DSPContext dsp; - AVFrame frames[2]; - AVFrame *last_frame; - AVFrame *current_frame; - int first_frame; - int y_stride; - int c_stride; - - roq_cell cells[256]; - roq_qcell qcells[256]; - - unsigned char *buf; - int size; - -} RoqContext; +#include "roqvideo.h" -#define RoQ_INFO 0x1001 -#define RoQ_QUAD_CODEBOOK 0x1002 -#define RoQ_QUAD_VQ 0x1011 -#define RoQ_SOUND_MONO 0x1020 -#define RoQ_SOUND_STEREO 0x1021 - -#define RoQ_ID_MOT 0x00 -#define RoQ_ID_FCC 0x01 -#define RoQ_ID_SLD 0x02 -#define RoQ_ID_CCC 0x03 - -#define get_byte(in_buffer) *(in_buffer++) -#define get_word(in_buffer) ((unsigned short)(in_buffer += 2, \ - (in_buffer[-1] << 8 | in_buffer[-2]))) -#define get_long(in_buffer) ((unsigned long)(in_buffer += 4, \ - (in_buffer[-1] << 24 | in_buffer[-2] << 16 | in_buffer[-3] << 8 | in_buffer[-4]))) - - -static void apply_vector_2x2(RoqContext *ri, int x, int y, roq_cell *cell) +static inline void block_copy(unsigned char *out, unsigned char *in, + int outstride, int instride, int sz) { - unsigned char *yptr; - - yptr = ri->current_frame->data[0] + (y * ri->y_stride) + x; - *yptr++ = cell->y0; - *yptr++ = cell->y1; - yptr += (ri->y_stride - 2); - *yptr++ = cell->y2; - *yptr++ = cell->y3; - ri->current_frame->data[1][(y/2) * (ri->c_stride) + x/2] = cell->u; - ri->current_frame->data[2][(y/2) * (ri->c_stride) + x/2] = cell->v; + int rows = sz; + while(rows--) { + memcpy(out, in, sz); + out += outstride; + in += instride; + } } -static void apply_vector_4x4(RoqContext *ri, int x, int y, roq_cell *cell) +void ff_apply_vector_2x2(RoqContext *ri, int x, int y, roq_cell *cell) { - unsigned long row_inc, c_row_inc; - register unsigned char y0, y1, u, v; - unsigned char *yptr, *uptr, *vptr; - - yptr = ri->current_frame->data[0] + (y * ri->y_stride) + x; - uptr = ri->current_frame->data[1] + (y/2) * (ri->c_stride) + x/2; - vptr = ri->current_frame->data[2] + (y/2) * (ri->c_stride) + x/2; - - row_inc = ri->y_stride - 4; - c_row_inc = (ri->c_stride) - 2; - *yptr++ = y0 = cell->y0; *uptr++ = u = cell->u; *vptr++ = v = cell->v; - *yptr++ = y0; - *yptr++ = y1 = cell->y1; *uptr++ = u; *vptr++ = v; - *yptr++ = y1; - - yptr += row_inc; - - *yptr++ = y0; - *yptr++ = y0; - *yptr++ = y1; - *yptr++ = y1; - - yptr += row_inc; uptr += c_row_inc; vptr += c_row_inc; - - *yptr++ = y0 = cell->y2; *uptr++ = u; *vptr++ = v; - *yptr++ = y0; - *yptr++ = y1 = cell->y3; *uptr++ = u; *vptr++ = v; - *yptr++ = y1; - - yptr += row_inc; - - *yptr++ = y0; - *yptr++ = y0; - *yptr++ = y1; - *yptr++ = y1; + unsigned char *bptr; + int boffs,stride; + + stride = ri->current_frame->linesize[0]; + boffs = y*stride + x; + + bptr = ri->current_frame->data[0] + boffs; + bptr[0 ] = cell->y[0]; + bptr[1 ] = cell->y[1]; + bptr[stride ] = cell->y[2]; + bptr[stride+1] = cell->y[3]; + + stride = ri->current_frame->linesize[1]; + boffs = y*stride + x; + + bptr = ri->current_frame->data[1] + boffs; + bptr[0 ] = + bptr[1 ] = + bptr[stride ] = + bptr[stride+1] = cell->u; + + bptr = ri->current_frame->data[2] + boffs; + bptr[0 ] = + bptr[1 ] = + bptr[stride ] = + bptr[stride+1] = cell->v; } -static void apply_motion_4x4(RoqContext *ri, int x, int y, unsigned char mv, - signed char mean_x, signed char mean_y) +void ff_apply_vector_4x4(RoqContext *ri, int x, int y, roq_cell *cell) { - int i, hw, mx, my; - unsigned char *pa, *pb; - - mx = x + 8 - (mv >> 4) - mean_x; - my = y + 8 - (mv & 0xf) - mean_y; - - /* check MV against frame boundaries */ - if ((mx < 0) || (mx > ri->avctx->width - 4) || - (my < 0) || (my > ri->avctx->height - 4)) { - av_log(ri->avctx, AV_LOG_ERROR, "motion vector out of bounds: MV = (%d, %d), boundaries = (0, 0, %d, %d)\n", - mx, my, ri->avctx->width, ri->avctx->height); - return; - } - - pa = ri->current_frame->data[0] + (y * ri->y_stride) + x; - pb = ri->last_frame->data[0] + (my * ri->y_stride) + mx; - for(i = 0; i < 4; i++) { - pa[0] = pb[0]; - pa[1] = pb[1]; - pa[2] = pb[2]; - pa[3] = pb[3]; - pa += ri->y_stride; - pb += ri->y_stride; - } - - hw = ri->y_stride/2; - pa = ri->current_frame->data[1] + (y * ri->y_stride)/4 + x/2; - pb = ri->last_frame->data[1] + (my/2) * (ri->y_stride/2) + (mx + 1)/2; - - for(i = 0; i < 2; i++) { - switch(((my & 0x01) << 1) | (mx & 0x01)) { - - case 0: - pa[0] = pb[0]; - pa[1] = pb[1]; - pa[hw] = pb[hw]; - pa[hw+1] = pb[hw+1]; - break; - - case 1: - pa[0] = avg2(pb[0], pb[1]); - pa[1] = avg2(pb[1], pb[2]); - pa[hw] = avg2(pb[hw], pb[hw+1]); - pa[hw+1] = avg2(pb[hw+1], pb[hw+2]); - break; - - case 2: - pa[0] = avg2(pb[0], pb[hw]); - pa[1] = avg2(pb[1], pb[hw+1]); - pa[hw] = avg2(pb[hw], pb[hw*2]); - pa[hw+1] = avg2(pb[hw+1], pb[(hw*2)+1]); - break; - - case 3: - pa[0] = avg4(pb[0], pb[1], pb[hw], pb[hw+1]); - pa[1] = avg4(pb[1], pb[2], pb[hw+1], pb[hw+2]); - pa[hw] = avg4(pb[hw], pb[hw+1], pb[hw*2], pb[(hw*2)+1]); - pa[hw+1] = avg4(pb[hw+1], pb[hw+2], pb[(hw*2)+1], pb[(hw*2)+1]); - break; - } - - pa = ri->current_frame->data[2] + (y * ri->y_stride)/4 + x/2; - pb = ri->last_frame->data[2] + (my/2) * (ri->y_stride/2) + (mx + 1)/2; - } + unsigned char *bptr; + int boffs,stride; + + stride = ri->current_frame->linesize[0]; + boffs = y*stride + x; + + bptr = ri->current_frame->data[0] + boffs; + bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] = cell->y[0]; + bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] = cell->y[1]; + bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] = cell->y[2]; + bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->y[3]; + + stride = ri->current_frame->linesize[1]; + boffs = y*stride + x; + + bptr = ri->current_frame->data[1] + boffs; + bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] = + bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] = + bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] = + bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->u; + + bptr = ri->current_frame->data[2] + boffs; + bptr[ 0] = bptr[ 1] = bptr[stride ] = bptr[stride +1] = + bptr[ 2] = bptr[ 3] = bptr[stride +2] = bptr[stride +3] = + bptr[stride*2 ] = bptr[stride*2+1] = bptr[stride*3 ] = bptr[stride*3+1] = + bptr[stride*2+2] = bptr[stride*2+3] = bptr[stride*3+2] = bptr[stride*3+3] = cell->v; } -static void apply_motion_8x8(RoqContext *ri, int x, int y, - unsigned char mv, signed char mean_x, signed char mean_y) + +static inline void apply_motion_generic(RoqContext *ri, int x, int y, int deltax, + int deltay, int sz) { - int mx, my, i, j, hw; - unsigned char *pa, *pb; + int mx, my, cp; - mx = x + 8 - (mv >> 4) - mean_x; - my = y + 8 - (mv & 0xf) - mean_y; + mx = x + deltax; + my = y + deltay; /* check MV against frame boundaries */ - if ((mx < 0) || (mx > ri->avctx->width - 8) || - (my < 0) || (my > ri->avctx->height - 8)) { + if ((mx < 0) || (mx > ri->width - sz) || + (my < 0) || (my > ri->height - sz)) { av_log(ri->avctx, AV_LOG_ERROR, "motion vector out of bounds: MV = (%d, %d), boundaries = (0, 0, %d, %d)\n", - mx, my, ri->avctx->width, ri->avctx->height); + mx, my, ri->width, ri->height); return; } - pa = ri->current_frame->data[0] + (y * ri->y_stride) + x; - pb = ri->last_frame->data[0] + (my * ri->y_stride) + mx; - for(i = 0; i < 8; i++) { - pa[0] = pb[0]; - pa[1] = pb[1]; - pa[2] = pb[2]; - pa[3] = pb[3]; - pa[4] = pb[4]; - pa[5] = pb[5]; - pa[6] = pb[6]; - pa[7] = pb[7]; - pa += ri->y_stride; - pb += ri->y_stride; - } - - hw = ri->c_stride; - pa = ri->current_frame->data[1] + (y * ri->y_stride)/4 + x/2; - pb = ri->last_frame->data[1] + (my/2) * (ri->y_stride/2) + (mx + 1)/2; - for(j = 0; j < 2; j++) { - for(i = 0; i < 4; i++) { - switch(((my & 0x01) << 1) | (mx & 0x01)) { - - case 0: - pa[0] = pb[0]; - pa[1] = pb[1]; - pa[2] = pb[2]; - pa[3] = pb[3]; - break; - - case 1: - pa[0] = avg2(pb[0], pb[1]); - pa[1] = avg2(pb[1], pb[2]); - pa[2] = avg2(pb[2], pb[3]); - pa[3] = avg2(pb[3], pb[4]); - break; - - case 2: - pa[0] = avg2(pb[0], pb[hw]); - pa[1] = avg2(pb[1], pb[hw+1]); - pa[2] = avg2(pb[2], pb[hw+2]); - pa[3] = avg2(pb[3], pb[hw+3]); - break; - - case 3: - pa[0] = avg4(pb[0], pb[1], pb[hw], pb[hw+1]); - pa[1] = avg4(pb[1], pb[2], pb[hw+1], pb[hw+2]); - pa[2] = avg4(pb[2], pb[3], pb[hw+2], pb[hw+3]); - pa[3] = avg4(pb[3], pb[4], pb[hw+3], pb[hw+4]); - break; - } - pa += ri->c_stride; - pb += ri->c_stride; - } - - pa = ri->current_frame->data[2] + (y * ri->y_stride)/4 + x/2; - pb = ri->last_frame->data[2] + (my/2) * (ri->y_stride/2) + (mx + 1)/2; + for(cp = 0; cp < 3; cp++) { + int outstride = ri->current_frame->linesize[cp]; + int instride = ri->last_frame ->linesize[cp]; + block_copy(ri->current_frame->data[cp] + y*outstride + x, + ri->last_frame->data[cp] + my*instride + mx, + outstride, instride, sz); } } -static void roqvideo_decode_frame(RoqContext *ri) -{ - unsigned int chunk_id = 0, chunk_arg = 0; - unsigned long chunk_size = 0; - int i, j, k, nv1, nv2, vqflg = 0, vqflg_pos = -1; - int vqid, bpos, xpos, ypos, xp, yp, x, y; - int frame_stats[2][4] = {{0},{0}}; - roq_qcell *qcell; - unsigned char *buf = ri->buf; - unsigned char *buf_end = ri->buf + ri->size; - - while (buf < buf_end) { - chunk_id = get_word(buf); - chunk_size = get_long(buf); - chunk_arg = get_word(buf); - - if(chunk_id == RoQ_QUAD_VQ) - break; - if(chunk_id == RoQ_QUAD_CODEBOOK) { - if((nv1 = chunk_arg >> 8) == 0) - nv1 = 256; - if((nv2 = chunk_arg & 0xff) == 0 && nv1 * 6 < chunk_size) - nv2 = 256; - for(i = 0; i < nv1; i++) { - ri->cells[i].y0 = get_byte(buf); - ri->cells[i].y1 = get_byte(buf); - ri->cells[i].y2 = get_byte(buf); - ri->cells[i].y3 = get_byte(buf); - ri->cells[i].u = get_byte(buf); - ri->cells[i].v = get_byte(buf); - } - for(i = 0; i < nv2; i++) - for(j = 0; j < 4; j++) - ri->qcells[i].idx[j] = get_byte(buf); - } - } - - bpos = xpos = ypos = 0; - while(bpos < chunk_size) { - for (yp = ypos; yp < ypos + 16; yp += 8) - for (xp = xpos; xp < xpos + 16; xp += 8) { - if (vqflg_pos < 0) { - vqflg = buf[bpos++]; vqflg |= (buf[bpos++] << 8); - vqflg_pos = 7; - } - vqid = (vqflg >> (vqflg_pos * 2)) & 0x3; - frame_stats[0][vqid]++; - vqflg_pos--; - switch(vqid) { - case RoQ_ID_MOT: - apply_motion_8x8(ri, xp, yp, 0, 8, 8); - break; - case RoQ_ID_FCC: - apply_motion_8x8(ri, xp, yp, buf[bpos++], chunk_arg >> 8, - chunk_arg & 0xff); - break; - case RoQ_ID_SLD: - qcell = ri->qcells + buf[bpos++]; - apply_vector_4x4(ri, xp, yp, ri->cells + qcell->idx[0]); - apply_vector_4x4(ri, xp+4, yp, ri->cells + qcell->idx[1]); - apply_vector_4x4(ri, xp, yp+4, ri->cells + qcell->idx[2]); - apply_vector_4x4(ri, xp+4, yp+4, ri->cells + qcell->idx[3]); - break; - case RoQ_ID_CCC: - for (k = 0; k < 4; k++) { - x = xp; y = yp; - if(k & 0x01) x += 4; - if(k & 0x02) y += 4; - - if (vqflg_pos < 0) { - vqflg = buf[bpos++]; - vqflg |= (buf[bpos++] << 8); - vqflg_pos = 7; - } - vqid = (vqflg >> (vqflg_pos * 2)) & 0x3; - frame_stats[1][vqid]++; - vqflg_pos--; - switch(vqid) { - case RoQ_ID_MOT: - apply_motion_4x4(ri, x, y, 0, 8, 8); - break; - case RoQ_ID_FCC: - apply_motion_4x4(ri, x, y, buf[bpos++], - chunk_arg >> 8, chunk_arg & 0xff); - break; - case RoQ_ID_SLD: - qcell = ri->qcells + buf[bpos++]; - apply_vector_2x2(ri, x, y, ri->cells + qcell->idx[0]); - apply_vector_2x2(ri, x+2, y, ri->cells + qcell->idx[1]); - apply_vector_2x2(ri, x, y+2, ri->cells + qcell->idx[2]); - apply_vector_2x2(ri, x+2, y+2, ri->cells + qcell->idx[3]); - break; - case RoQ_ID_CCC: - apply_vector_2x2(ri, x, y, ri->cells + buf[bpos]); - apply_vector_2x2(ri, x+2, y, ri->cells + buf[bpos+1]); - apply_vector_2x2(ri, x, y+2, ri->cells + buf[bpos+2]); - apply_vector_2x2(ri, x+2, y+2, ri->cells + buf[bpos+3]); - bpos += 4; - break; - } - } - break; - default: - av_log(ri->avctx, AV_LOG_ERROR, "Unknown vq code: %d\n", vqid); - } - } - - xpos += 16; - if (xpos >= ri->avctx->width) { - xpos -= ri->avctx->width; - ypos += 16; - } - if(ypos >= ri->avctx->height) - break; - } -} - - -static int roq_decode_init(AVCodecContext *avctx) +void ff_apply_motion_4x4(RoqContext *ri, int x, int y, + int deltax, int deltay) { - RoqContext *s = avctx->priv_data; - int i; - - s->avctx = avctx; - s->first_frame = 1; - s->last_frame = &s->frames[0]; - s->current_frame = &s->frames[1]; - avctx->pix_fmt = PIX_FMT_YUV420P; - avctx->has_b_frames = 0; - dsputil_init(&s->dsp, avctx); - - uiclp = uiclip+512; - for(i = -512; i < 512; i++) - uiclp[i] = (i < 0 ? 0 : (i > 255 ? 255 : i)); - - return 0; -} - -static int roq_decode_frame(AVCodecContext *avctx, - void *data, int *data_size, - uint8_t *buf, int buf_size) -{ - RoqContext *s = avctx->priv_data; - - if (avctx->get_buffer(avctx, s->current_frame)) { - av_log(avctx, AV_LOG_ERROR, " RoQ: get_buffer() failed\n"); - return -1; - } - s->y_stride = s->current_frame->linesize[0]; - s->c_stride = s->current_frame->linesize[1]; - - s->buf = buf; - s->size = buf_size; - roqvideo_decode_frame(s); - - /* release the last frame if it is allocated */ - if (s->first_frame) - s->first_frame = 0; - else - avctx->release_buffer(avctx, s->last_frame); - - *data_size = sizeof(AVFrame); - *(AVFrame*)data = *s->current_frame; - - /* shuffle frames */ - FFSWAP(AVFrame *, s->current_frame, s->last_frame); - - return buf_size; + apply_motion_generic(ri, x, y, deltax, deltay, 4); } -static int roq_decode_end(AVCodecContext *avctx) +void ff_apply_motion_8x8(RoqContext *ri, int x, int y, + int deltax, int deltay) { - RoqContext *s = avctx->priv_data; - - /* release the last frame */ - if (s->last_frame->data[0]) - avctx->release_buffer(avctx, s->last_frame); - - return 0; + apply_motion_generic(ri, x, y, deltax, deltay, 8); } - -AVCodec roq_decoder = { - "roqvideo", - CODEC_TYPE_VIDEO, - CODEC_ID_ROQ, - sizeof(RoqContext), - roq_decode_init, - NULL, - roq_decode_end, - roq_decode_frame, - CODEC_CAP_DR1, -}; diff --git a/contrib/ffmpeg/libavcodec/roqvideo.h b/contrib/ffmpeg/libavcodec/roqvideo.h new file mode 100644 index 000000000..3345635ee --- /dev/null +++ b/contrib/ffmpeg/libavcodec/roqvideo.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2003 Mike Melanson + * Copyright (C) 2003 Dr. Tim Ferguson + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_ROQVIDEO_H +#define FFMPEG_ROQVIDEO_H + +#include "avcodec.h" +#include "dsputil.h" +#include "random.h" + +typedef struct { + unsigned char y[4]; + unsigned char u, v; +} roq_cell; + +typedef struct { + int idx[4]; +} roq_qcell; + +typedef struct { + int d[2]; +} motion_vect; + +typedef struct RoqContext { + + AVCodecContext *avctx; + DSPContext dsp; + AVFrame frames[2]; + AVFrame *last_frame; + AVFrame *current_frame; + int first_frame; + + roq_cell cb2x2[256]; + roq_qcell cb4x4[256]; + + const unsigned char *buf; + int size; + int width, height; + + /* Encoder only data */ + AVRandomState randctx; + uint64_t lambda; + + motion_vect *this_motion4; + motion_vect *last_motion4; + + motion_vect *this_motion8; + motion_vect *last_motion8; + + unsigned int framesSinceKeyframe; + + AVFrame *frame_to_enc; + uint8_t *out_buf; +} RoqContext; + +#define RoQ_INFO 0x1001 +#define RoQ_QUAD_CODEBOOK 0x1002 +#define RoQ_QUAD_VQ 0x1011 +#define RoQ_SOUND_MONO 0x1020 +#define RoQ_SOUND_STEREO 0x1021 + +#define RoQ_ID_MOT 0x00 +#define RoQ_ID_FCC 0x01 +#define RoQ_ID_SLD 0x02 +#define RoQ_ID_CCC 0x03 + +void ff_apply_vector_2x2(RoqContext *ri, int x, int y, roq_cell *cell); +void ff_apply_vector_4x4(RoqContext *ri, int x, int y, roq_cell *cell); + +void ff_apply_motion_4x4(RoqContext *ri, int x, int y, int deltax, int deltay); + +void ff_apply_motion_8x8(RoqContext *ri, int x, int y, int deltax, int deltay); + +#endif /* FFMPEG_ROQVIDEO_H */ diff --git a/contrib/ffmpeg/libavcodec/roqvideodec.c b/contrib/ffmpeg/libavcodec/roqvideodec.c new file mode 100644 index 000000000..a4e32c3fa --- /dev/null +++ b/contrib/ffmpeg/libavcodec/roqvideodec.c @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2003 the ffmpeg project + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file roqvideodec.c + * Id RoQ Video Decoder by Dr. Tim Ferguson + * For more information about the Id RoQ format, visit: + * http://www.csse.monash.edu.au/~timf/ + */ + +#include +#include +#include +#include + +#include "avcodec.h" +#include "bytestream.h" +#include "dsputil.h" +#include "roqvideo.h" + +static void roqvideo_decode_frame(RoqContext *ri) +{ + unsigned int chunk_id = 0, chunk_arg = 0; + unsigned long chunk_size = 0; + int i, j, k, nv1, nv2, vqflg = 0, vqflg_pos = -1; + int vqid, bpos, xpos, ypos, xp, yp, x, y, mx, my; + int frame_stats[2][4] = {{0},{0}}; + roq_qcell *qcell; + const unsigned char *buf = ri->buf; + const unsigned char *buf_end = ri->buf + ri->size; + + while (buf < buf_end) { + chunk_id = bytestream_get_le16(&buf); + chunk_size = bytestream_get_le32(&buf); + chunk_arg = bytestream_get_le16(&buf); + + if(chunk_id == RoQ_QUAD_VQ) + break; + if(chunk_id == RoQ_QUAD_CODEBOOK) { + if((nv1 = chunk_arg >> 8) == 0) + nv1 = 256; + if((nv2 = chunk_arg & 0xff) == 0 && nv1 * 6 < chunk_size) + nv2 = 256; + for(i = 0; i < nv1; i++) { + ri->cb2x2[i].y[0] = *buf++; + ri->cb2x2[i].y[1] = *buf++; + ri->cb2x2[i].y[2] = *buf++; + ri->cb2x2[i].y[3] = *buf++; + ri->cb2x2[i].u = *buf++; + ri->cb2x2[i].v = *buf++; + } + for(i = 0; i < nv2; i++) + for(j = 0; j < 4; j++) + ri->cb4x4[i].idx[j] = *buf++; + } + } + + bpos = xpos = ypos = 0; + while(bpos < chunk_size) { + for (yp = ypos; yp < ypos + 16; yp += 8) + for (xp = xpos; xp < xpos + 16; xp += 8) { + if (vqflg_pos < 0) { + vqflg = buf[bpos++]; vqflg |= (buf[bpos++] << 8); + vqflg_pos = 7; + } + vqid = (vqflg >> (vqflg_pos * 2)) & 0x3; + frame_stats[0][vqid]++; + vqflg_pos--; + + switch(vqid) { + case RoQ_ID_MOT: + break; + case RoQ_ID_FCC: + mx = 8 - (buf[bpos] >> 4) - ((signed char) (chunk_arg >> 8)); + my = 8 - (buf[bpos++] & 0xf) - ((signed char) chunk_arg); + ff_apply_motion_8x8(ri, xp, yp, mx, my); + break; + case RoQ_ID_SLD: + qcell = ri->cb4x4 + buf[bpos++]; + ff_apply_vector_4x4(ri, xp, yp, ri->cb2x2 + qcell->idx[0]); + ff_apply_vector_4x4(ri, xp+4, yp, ri->cb2x2 + qcell->idx[1]); + ff_apply_vector_4x4(ri, xp, yp+4, ri->cb2x2 + qcell->idx[2]); + ff_apply_vector_4x4(ri, xp+4, yp+4, ri->cb2x2 + qcell->idx[3]); + break; + case RoQ_ID_CCC: + for (k = 0; k < 4; k++) { + x = xp; y = yp; + if(k & 0x01) x += 4; + if(k & 0x02) y += 4; + + if (vqflg_pos < 0) { + vqflg = buf[bpos++]; + vqflg |= (buf[bpos++] << 8); + vqflg_pos = 7; + } + vqid = (vqflg >> (vqflg_pos * 2)) & 0x3; + frame_stats[1][vqid]++; + vqflg_pos--; + switch(vqid) { + case RoQ_ID_MOT: + break; + case RoQ_ID_FCC: + mx = 8 - (buf[bpos] >> 4) - ((signed char) (chunk_arg >> 8)); + my = 8 - (buf[bpos++] & 0xf) - ((signed char) chunk_arg); + ff_apply_motion_4x4(ri, x, y, mx, my); + break; + case RoQ_ID_SLD: + qcell = ri->cb4x4 + buf[bpos++]; + ff_apply_vector_2x2(ri, x, y, ri->cb2x2 + qcell->idx[0]); + ff_apply_vector_2x2(ri, x+2, y, ri->cb2x2 + qcell->idx[1]); + ff_apply_vector_2x2(ri, x, y+2, ri->cb2x2 + qcell->idx[2]); + ff_apply_vector_2x2(ri, x+2, y+2, ri->cb2x2 + qcell->idx[3]); + break; + case RoQ_ID_CCC: + ff_apply_vector_2x2(ri, x, y, ri->cb2x2 + buf[bpos]); + ff_apply_vector_2x2(ri, x+2, y, ri->cb2x2 + buf[bpos+1]); + ff_apply_vector_2x2(ri, x, y+2, ri->cb2x2 + buf[bpos+2]); + ff_apply_vector_2x2(ri, x+2, y+2, ri->cb2x2 + buf[bpos+3]); + bpos += 4; + break; + } + } + break; + default: + av_log(ri->avctx, AV_LOG_ERROR, "Unknown vq code: %d\n", vqid); + } + } + + xpos += 16; + if (xpos >= ri->width) { + xpos -= ri->width; + ypos += 16; + } + if(ypos >= ri->height) + break; + } +} + + +static int roq_decode_init(AVCodecContext *avctx) +{ + RoqContext *s = avctx->priv_data; + + s->avctx = avctx; + s->width = avctx->width; + s->height = avctx->height; + s->last_frame = &s->frames[0]; + s->current_frame = &s->frames[1]; + avctx->pix_fmt = PIX_FMT_YUV444P; + dsputil_init(&s->dsp, avctx); + + return 0; +} + +static int roq_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size) +{ + RoqContext *s = avctx->priv_data; + int copy= !s->current_frame->data[0]; + + if (avctx->reget_buffer(avctx, s->current_frame)) { + av_log(avctx, AV_LOG_ERROR, " RoQ: get_buffer() failed\n"); + return -1; + } + + if(copy) + av_picture_copy((AVPicture*)s->current_frame, (AVPicture*)s->last_frame, + avctx->pix_fmt, avctx->width, avctx->height); + + s->buf = buf; + s->size = buf_size; + roqvideo_decode_frame(s); + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = *s->current_frame; + + /* shuffle frames */ + FFSWAP(AVFrame *, s->current_frame, s->last_frame); + + return buf_size; +} + +static int roq_decode_end(AVCodecContext *avctx) +{ + RoqContext *s = avctx->priv_data; + + /* release the last frame */ + if (s->last_frame->data[0]) + avctx->release_buffer(avctx, s->last_frame); + if (s->current_frame->data[0]) + avctx->release_buffer(avctx, s->current_frame); + + return 0; +} + +AVCodec roq_decoder = { + "roqvideo", + CODEC_TYPE_VIDEO, + CODEC_ID_ROQ, + sizeof(RoqContext), + roq_decode_init, + NULL, + roq_decode_end, + roq_decode_frame, + CODEC_CAP_DR1, +}; diff --git a/contrib/ffmpeg/libavcodec/roqvideoenc.c b/contrib/ffmpeg/libavcodec/roqvideoenc.c new file mode 100644 index 000000000..ca939b9c4 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/roqvideoenc.c @@ -0,0 +1,1069 @@ +/* + * RoQ Video Encoder. + * + * Copyright (C) 2007 Vitor Sessak + * Copyright (C) 2004-2007 Eric Lasota + * Based on RoQ specs (C) 2001 Tim Ferguson + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file roqvideoenc.c + * Id RoQ encoder by Vitor. Based on the Switchblade3 library and the + * Switchblade3 FFmpeg glue by Eric Lasota. + */ + +/* + * COSTS: + * Level 1: + * SKIP - 2 bits + * MOTION - 2 + 8 bits + * CODEBOOK - 2 + 8 bits + * SUBDIVIDE - 2 + combined subcel cost + * + * Level 2: + * SKIP - 2 bits + * MOTION - 2 + 8 bits + * CODEBOOK - 2 + 8 bits + * SUBDIVIDE - 2 + 4*8 bits + * + * Maximum cost: 138 bits per cel + * + * Proper evaluation requires LCD fraction comparison, which requires + * Squared Error (SE) loss * savings increase + * + * Maximum savings increase: 136 bits + * Maximum SE loss without overflow: 31580641 + * Components in 8x8 supercel: 192 + * Maximum SE precision per component: 164482 + * >65025, so no truncation is needed (phew) + */ + +#include +#include + +#include "roqvideo.h" +#include "bytestream.h" +#include "elbg.h" + +#define CHROMA_BIAS 1 + +/** + * Maximum number of generated 4x4 codebooks. Can't be 256 to workaround a + * Quake 3 bug. + */ +#define MAX_CBS_4x4 255 + +#define MAX_CBS_2x2 256 ///< Maximum number of 2x2 codebooks. + +/* The cast is useful when multiplying it by INT_MAX */ +#define ROQ_LAMBDA_SCALE ((uint64_t) FF_LAMBDA_SCALE) + +/* Macroblock support functions */ +static void unpack_roq_cell(roq_cell *cell, uint8_t u[4*3]) +{ + memcpy(u , cell->y, 4); + memset(u+4, cell->u, 4); + memset(u+8, cell->v, 4); +} + +static void unpack_roq_qcell(uint8_t cb2[], roq_qcell *qcell, uint8_t u[4*4*3]) +{ + int i,cp; + static const int offsets[4] = {0, 2, 8, 10}; + + for (cp=0; cp<3; cp++) + for (i=0; i<4; i++) { + u[4*4*cp + offsets[i] ] = cb2[qcell->idx[i]*2*2*3 + 4*cp ]; + u[4*4*cp + offsets[i]+1] = cb2[qcell->idx[i]*2*2*3 + 4*cp+1]; + u[4*4*cp + offsets[i]+4] = cb2[qcell->idx[i]*2*2*3 + 4*cp+2]; + u[4*4*cp + offsets[i]+5] = cb2[qcell->idx[i]*2*2*3 + 4*cp+3]; + } +} + + +static void enlarge_roq_mb4(uint8_t base[3*16], uint8_t u[3*64]) +{ + int x,y,cp; + + for(cp=0; cp<3; cp++) + for(y=0; y<8; y++) + for(x=0; x<8; x++) + *u++ = base[(y/2)*4 + (x/2) + 16*cp]; +} + +static inline int square(int x) +{ + return x*x; +} + +static inline int eval_sse(uint8_t *a, uint8_t *b, int count) +{ + int diff=0; + + while(count--) + diff += square(*b++ - *a++); + + return diff; +} + +// FIXME Could use DSPContext.sse, but it is not so speed critical (used +// just for motion estimation). +static int block_sse(uint8_t **buf1, uint8_t **buf2, int x1, int y1, int x2, + int y2, int *stride1, int *stride2, int size) +{ + int i, k; + int sse=0; + + for (k=0; k<3; k++) { + int bias = (k ? CHROMA_BIAS : 4); + for (i=0; i 7) + return INT_MAX; + + if (my < -7 || my > 7) + return INT_MAX; + + mx += x; + my += y; + + if ((unsigned) mx > enc->width-size || (unsigned) my > enc->height-size) + return INT_MAX; + + return block_sse(enc->frame_to_enc->data, enc->last_frame->data, x, y, + mx, my, + enc->frame_to_enc->linesize, enc->last_frame->linesize, + size); +} + +/** + * Returns distortion between two macroblocks + */ +static inline int squared_diff_macroblock(uint8_t a[], uint8_t b[], int size) +{ + int cp, sdiff=0; + + for(cp=0;cp<3;cp++) { + int bias = (cp ? CHROMA_BIAS : 4); + sdiff += bias*eval_sse(a, b, size*size); + a += size*size; + b += size*size; + } + + return sdiff; +} + +typedef struct +{ + int eval_dist[4]; + int best_bit_use; + int best_coding; + + int subCels[4]; + motion_vect motion; + int cbEntry; +} subcel_evaluation_t; + +typedef struct +{ + int eval_dist[4]; + int best_coding; + + subcel_evaluation_t subCels[4]; + + motion_vect motion; + int cbEntry; + + int sourceX, sourceY; +} cel_evaluation_t; + +typedef struct +{ + int numCB4; + int numCB2; + int usedCB2[MAX_CBS_2x2]; + int usedCB4[MAX_CBS_4x4]; + uint8_t unpacked_cb2[MAX_CBS_2x2*2*2*3]; + uint8_t unpacked_cb4[MAX_CBS_4x4*4*4*3]; + uint8_t unpacked_cb4_enlarged[MAX_CBS_4x4*8*8*3]; +} roq_codebooks_t; + +/** + * Temporary vars + */ +typedef struct +{ + cel_evaluation_t *cel_evals; + + int f2i4[MAX_CBS_4x4]; + int i2f4[MAX_CBS_4x4]; + int f2i2[MAX_CBS_2x2]; + int i2f2[MAX_CBS_2x2]; + + int mainChunkSize; + + int numCB4; + int numCB2; + + roq_codebooks_t codebooks; + + int *closest_cb2; + int used_option[4]; +} roq_tempdata_t; + +/** + * Initializes cel evaluators and sets their source coordinates + */ +static void create_cel_evals(RoqContext *enc, roq_tempdata_t *tempData) +{ + int n=0, x, y, i; + + tempData->cel_evals = av_malloc(enc->width*enc->height/64 * sizeof(cel_evaluation_t)); + + /* Map to the ROQ quadtree order */ + for (y=0; yheight; y+=16) + for (x=0; xwidth; x+=16) + for(i=0; i<4; i++) { + tempData->cel_evals[n ].sourceX = x + (i&1)*8; + tempData->cel_evals[n++].sourceY = y + (i&2)*4; + } +} + +/** + * Get macroblocks from parts of the image + */ +static void get_frame_mb(AVFrame *frame, int x, int y, uint8_t mb[], int dim) +{ + int i, j, cp; + + for (cp=0; cp<3; cp++) { + int stride = frame->linesize[cp]; + for (i=0; idata[cp][(y+i)*stride + x + j]; + } +} + +/** + * Find the codebook with the lowest distortion from an image + */ +static int index_mb(uint8_t cluster[], uint8_t cb[], int numCB, + int *outIndex, int dim) +{ + int i, lDiff = INT_MAX, pick=0; + + /* Diff against the others */ + for (i=0; iwidth/blocksize)*enc->height/blocksize; + + if (blocksize == 4) { + last_motion = enc->last_motion4; + this_motion = enc->this_motion4; + } else { + last_motion = enc->last_motion8; + this_motion = enc->this_motion8; + } + + for (i=0; iheight; i+=blocksize) + for (j=0; jwidth; j+=blocksize) { + lowestdiff = eval_motion_dist(enc, j, i, (motion_vect) {{0,0}}, + blocksize); + bestpick.d[0] = 0; + bestpick.d[1] = 0; + + if (blocksize == 4) + EVAL_MOTION(enc->this_motion8[(i/8)*(enc->width/8) + j/8]); + + offset = (i/blocksize)*enc->width/blocksize + j/blocksize; + if (offset < max && offset >= 0) + EVAL_MOTION(last_motion[offset]); + + offset++; + if (offset < max && offset >= 0) + EVAL_MOTION(last_motion[offset]); + + offset = (i/blocksize + 1)*enc->width/blocksize + j/blocksize; + if (offset < max && offset >= 0) + EVAL_MOTION(last_motion[offset]); + + off[0]= (i/blocksize)*enc->width/blocksize + j/blocksize - 1; + off[1]= off[0] - enc->width/blocksize + 1; + off[2]= off[1] + 1; + + if (i) { + + for(k=0; k<2; k++) + vect.d[k]= mid_pred(this_motion[off[0]].d[k], + this_motion[off[1]].d[k], + this_motion[off[2]].d[k]); + + EVAL_MOTION(vect); + for(k=0; k<3; k++) + EVAL_MOTION(this_motion[off[k]]); + } else if(j) + EVAL_MOTION(this_motion[off[0]]); + + vect = bestpick; + + oldbest = -1; + while (oldbest != lowestdiff) { + oldbest = lowestdiff; + for (k=0; k<8; k++) { + vect2 = vect; + vect2.d[0] += offsets[k].d[0]; + vect2.d[1] += offsets[k].d[1]; + EVAL_MOTION(vect2); + } + vect = bestpick; + } + offset = (i/blocksize)*enc->width/blocksize + j/blocksize; + this_motion[offset] = bestpick; + } +} + +/** + * Gets distortion for all options available to a subcel + */ +static void gather_data_for_subcel(subcel_evaluation_t *subcel, int x, + int y, RoqContext *enc, roq_tempdata_t *tempData) +{ + uint8_t mb4[4*4*3]; + uint8_t mb2[2*2*3]; + int cluster_index; + int i, best_dist; + + static const int bitsUsed[4] = {2, 10, 10, 34}; + + if (enc->framesSinceKeyframe >= 1) { + subcel->motion = enc->this_motion4[y*enc->width/16 + x/4]; + + subcel->eval_dist[RoQ_ID_FCC] = + eval_motion_dist(enc, x, y, + enc->this_motion4[y*enc->width/16 + x/4], 4); + } else + subcel->eval_dist[RoQ_ID_FCC] = INT_MAX; + + if (enc->framesSinceKeyframe >= 2) + subcel->eval_dist[RoQ_ID_MOT] = block_sse(enc->frame_to_enc->data, + enc->current_frame->data, x, + y, x, y, + enc->frame_to_enc->linesize, + enc->current_frame->linesize, + 4); + else + subcel->eval_dist[RoQ_ID_MOT] = INT_MAX; + + cluster_index = y*enc->width/16 + x/4; + + get_frame_mb(enc->frame_to_enc, x, y, mb4, 4); + + subcel->eval_dist[RoQ_ID_SLD] = index_mb(mb4, + tempData->codebooks.unpacked_cb4, + tempData->codebooks.numCB4, + &subcel->cbEntry, 4); + + subcel->eval_dist[RoQ_ID_CCC] = 0; + + for(i=0;i<4;i++) { + subcel->subCels[i] = tempData->closest_cb2[cluster_index*4+i]; + + get_frame_mb(enc->frame_to_enc, x+2*(i&1), + y+(i&2), mb2, 2); + + subcel->eval_dist[RoQ_ID_CCC] += + squared_diff_macroblock(tempData->codebooks.unpacked_cb2 + subcel->subCels[i]*2*2*3, mb2, 2); + } + + best_dist = INT_MAX; + for (i=0; i<4; i++) + if (ROQ_LAMBDA_SCALE*subcel->eval_dist[i] + enc->lambda*bitsUsed[i] < + best_dist) { + subcel->best_coding = i; + subcel->best_bit_use = bitsUsed[i]; + best_dist = ROQ_LAMBDA_SCALE*subcel->eval_dist[i] + + enc->lambda*bitsUsed[i]; + } +} + +/** + * Gets distortion for all options available to a cel + */ +static void gather_data_for_cel(cel_evaluation_t *cel, RoqContext *enc, + roq_tempdata_t *tempData) +{ + uint8_t mb8[8*8*3]; + int index = cel->sourceY*enc->width/64 + cel->sourceX/8; + int i, j, best_dist, divide_bit_use; + + int bitsUsed[4] = {2, 10, 10, 0}; + + if (enc->framesSinceKeyframe >= 1) { + cel->motion = enc->this_motion8[index]; + + cel->eval_dist[RoQ_ID_FCC] = + eval_motion_dist(enc, cel->sourceX, cel->sourceY, + enc->this_motion8[index], 8); + } else + cel->eval_dist[RoQ_ID_FCC] = INT_MAX; + + if (enc->framesSinceKeyframe >= 2) + cel->eval_dist[RoQ_ID_MOT] = block_sse(enc->frame_to_enc->data, + enc->current_frame->data, + cel->sourceX, cel->sourceY, + cel->sourceX, cel->sourceY, + enc->frame_to_enc->linesize, + enc->current_frame->linesize,8); + else + cel->eval_dist[RoQ_ID_MOT] = INT_MAX; + + get_frame_mb(enc->frame_to_enc, cel->sourceX, cel->sourceY, mb8, 8); + + cel->eval_dist[RoQ_ID_SLD] = + index_mb(mb8, tempData->codebooks.unpacked_cb4_enlarged, + tempData->codebooks.numCB4, &cel->cbEntry, 8); + + gather_data_for_subcel(cel->subCels + 0, cel->sourceX+0, cel->sourceY+0, enc, tempData); + gather_data_for_subcel(cel->subCels + 1, cel->sourceX+4, cel->sourceY+0, enc, tempData); + gather_data_for_subcel(cel->subCels + 2, cel->sourceX+0, cel->sourceY+4, enc, tempData); + gather_data_for_subcel(cel->subCels + 3, cel->sourceX+4, cel->sourceY+4, enc, tempData); + + cel->eval_dist[RoQ_ID_CCC] = 0; + divide_bit_use = 0; + for (i=0; i<4; i++) { + cel->eval_dist[RoQ_ID_CCC] += + cel->subCels[i].eval_dist[cel->subCels[i].best_coding]; + divide_bit_use += cel->subCels[i].best_bit_use; + } + + best_dist = INT_MAX; + bitsUsed[3] = 2 + divide_bit_use; + + for (i=0; i<4; i++) + if (ROQ_LAMBDA_SCALE*cel->eval_dist[i] + enc->lambda*bitsUsed[i] < + best_dist) { + cel->best_coding = i; + best_dist = ROQ_LAMBDA_SCALE*cel->eval_dist[i] + + enc->lambda*bitsUsed[i]; + } + + tempData->used_option[cel->best_coding]++; + tempData->mainChunkSize += bitsUsed[cel->best_coding]; + + if (cel->best_coding == RoQ_ID_SLD) + tempData->codebooks.usedCB4[cel->cbEntry]++; + + if (cel->best_coding == RoQ_ID_CCC) + for (i=0; i<4; i++) { + if (cel->subCels[i].best_coding == RoQ_ID_SLD) + tempData->codebooks.usedCB4[cel->subCels[i].cbEntry]++; + else if (cel->subCels[i].best_coding == RoQ_ID_CCC) + for (j=0; j<4; j++) + tempData->codebooks.usedCB2[cel->subCels[i].subCels[j]]++; + } +} + +static void remap_codebooks(RoqContext *enc, roq_tempdata_t *tempData) +{ + int i, j, idx=0; + + /* Make remaps for the final codebook usage */ + for (i=0; icodebooks.usedCB4[i]) { + tempData->i2f4[i] = idx; + tempData->f2i4[idx] = i; + for (j=0; j<4; j++) + tempData->codebooks.usedCB2[enc->cb4x4[i].idx[j]]++; + idx++; + } + } + + tempData->numCB4 = idx; + + idx = 0; + for (i=0; icodebooks.usedCB2[i]) { + tempData->i2f2[i] = idx; + tempData->f2i2[idx] = i; + idx++; + } + } + tempData->numCB2 = idx; + +} + +/** + * Write codebook chunk + */ +static void write_codebooks(RoqContext *enc, roq_tempdata_t *tempData) +{ + int i, j; + uint8_t **outp= &enc->out_buf; + + if (tempData->numCB2) { + bytestream_put_le16(outp, RoQ_QUAD_CODEBOOK); + bytestream_put_le32(outp, tempData->numCB2*6 + tempData->numCB4*4); + bytestream_put_byte(outp, tempData->numCB4); + bytestream_put_byte(outp, tempData->numCB2); + + for (i=0; inumCB2; i++) { + bytestream_put_buffer(outp, enc->cb2x2[tempData->f2i2[i]].y, 4); + bytestream_put_byte(outp, enc->cb2x2[tempData->f2i2[i]].u); + bytestream_put_byte(outp, enc->cb2x2[tempData->f2i2[i]].v); + } + + for (i=0; inumCB4; i++) + for (j=0; j<4; j++) + bytestream_put_byte(outp, tempData->i2f2[enc->cb4x4[tempData->f2i4[i]].idx[j]]); + + } +} + +static inline uint8_t motion_arg(motion_vect mot) +{ + uint8_t ax = 8 - ((uint8_t) mot.d[0]); + uint8_t ay = 8 - ((uint8_t) mot.d[1]); + return ((ax&15)<<4) | (ay&15); +} + +typedef struct +{ + int typeSpool; + int typeSpoolLength; + uint8_t argumentSpool[64]; + uint8_t *args; + uint8_t **pout; +} CodingSpool; + +/* NOTE: Typecodes must be spooled AFTER arguments!! */ +static void write_typecode(CodingSpool *s, uint8_t type) +{ + s->typeSpool |= (type & 3) << (14 - s->typeSpoolLength); + s->typeSpoolLength += 2; + if (s->typeSpoolLength == 16) { + bytestream_put_le16(s->pout, s->typeSpool); + bytestream_put_buffer(s->pout, s->argumentSpool, + s->args - s->argumentSpool); + s->typeSpoolLength = 0; + s->typeSpool = 0; + s->args = s->argumentSpool; + } +} + +static void reconstruct_and_encode_image(RoqContext *enc, roq_tempdata_t *tempData, int w, int h, int numBlocks) +{ + int i, j, k; + int x, y; + int subX, subY; + int dist=0; + + roq_qcell *qcell; + cel_evaluation_t *eval; + + CodingSpool spool; + + spool.typeSpool=0; + spool.typeSpoolLength=0; + spool.args = spool.argumentSpool; + spool.pout = &enc->out_buf; + + if (tempData->used_option[RoQ_ID_CCC]%2) + tempData->mainChunkSize+=8; //FIXME + + /* Write the video chunk header */ + bytestream_put_le16(&enc->out_buf, RoQ_QUAD_VQ); + bytestream_put_le32(&enc->out_buf, tempData->mainChunkSize/8); + bytestream_put_byte(&enc->out_buf, 0x0); + bytestream_put_byte(&enc->out_buf, 0x0); + + for (i=0; icel_evals + i; + + x = eval->sourceX; + y = eval->sourceY; + dist += eval->eval_dist[eval->best_coding]; + + switch (eval->best_coding) { + case RoQ_ID_MOT: + write_typecode(&spool, RoQ_ID_MOT); + break; + + case RoQ_ID_FCC: + bytestream_put_byte(&spool.args, motion_arg(eval->motion)); + + write_typecode(&spool, RoQ_ID_FCC); + ff_apply_motion_8x8(enc, x, y, + eval->motion.d[0], eval->motion.d[1]); + break; + + case RoQ_ID_SLD: + bytestream_put_byte(&spool.args, tempData->i2f4[eval->cbEntry]); + write_typecode(&spool, RoQ_ID_SLD); + + qcell = enc->cb4x4 + eval->cbEntry; + ff_apply_vector_4x4(enc, x , y , enc->cb2x2 + qcell->idx[0]); + ff_apply_vector_4x4(enc, x+4, y , enc->cb2x2 + qcell->idx[1]); + ff_apply_vector_4x4(enc, x , y+4, enc->cb2x2 + qcell->idx[2]); + ff_apply_vector_4x4(enc, x+4, y+4, enc->cb2x2 + qcell->idx[3]); + break; + + case RoQ_ID_CCC: + write_typecode(&spool, RoQ_ID_CCC); + + for (j=0; j<4; j++) { + subX = x + 4*(j&1); + subY = y + 2*(j&2); + + switch(eval->subCels[j].best_coding) { + case RoQ_ID_MOT: + break; + + case RoQ_ID_FCC: + bytestream_put_byte(&spool.args, + motion_arg(eval->subCels[j].motion)); + + ff_apply_motion_4x4(enc, subX, subY, + eval->subCels[j].motion.d[0], + eval->subCels[j].motion.d[1]); + break; + + case RoQ_ID_SLD: + bytestream_put_byte(&spool.args, + tempData->i2f4[eval->subCels[j].cbEntry]); + + qcell = enc->cb4x4 + eval->subCels[j].cbEntry; + + ff_apply_vector_2x2(enc, subX , subY , + enc->cb2x2 + qcell->idx[0]); + ff_apply_vector_2x2(enc, subX+2, subY , + enc->cb2x2 + qcell->idx[1]); + ff_apply_vector_2x2(enc, subX , subY+2, + enc->cb2x2 + qcell->idx[2]); + ff_apply_vector_2x2(enc, subX+2, subY+2, + enc->cb2x2 + qcell->idx[3]); + break; + + case RoQ_ID_CCC: + for (k=0; k<4; k++) { + int cb_idx = eval->subCels[j].subCels[k]; + bytestream_put_byte(&spool.args, + tempData->i2f2[cb_idx]); + + ff_apply_vector_2x2(enc, subX + 2*(k&1), subY + (k&2), + enc->cb2x2 + cb_idx); + } + break; + } + write_typecode(&spool, eval->subCels[j].best_coding); + } + break; + } + } + + /* Flush the remainder of the argument/type spool */ + while (spool.typeSpoolLength) + write_typecode(&spool, 0x0); + +#if 0 + uint8_t *fdata[3] = {enc->frame_to_enc->data[0], + enc->frame_to_enc->data[1], + enc->frame_to_enc->data[2]}; + uint8_t *cdata[3] = {enc->current_frame->data[0], + enc->current_frame->data[1], + enc->current_frame->data[2]}; + av_log(enc->avctx, AV_LOG_ERROR, "Expected distortion: %i Actual: %i\n", + dist, + block_sse(fdata, cdata, 0, 0, 0, 0, + enc->frame_to_enc->linesize, + enc->current_frame->linesize, + enc->width)); //WARNING: Square dimensions implied... +#endif +} + + +/** + * Create a single YUV cell from a 2x2 section of the image + */ +static inline void frame_block_to_cell(uint8_t *block, uint8_t **data, + int top, int left, int *stride) +{ + int i, j, u=0, v=0; + + for (i=0; i<2; i++) + for (j=0; j<2; j++) { + int x = (top+i)*stride[0] + left + j; + *block++ = data[0][x]; + x = (top+i)*stride[1] + left + j; + u += data[1][x]; + v += data[2][x]; + } + + *block++ = (u+2)/4; + *block++ = (v+2)/4; +} + +/** + * Creates YUV clusters for the entire image + */ +static void create_clusters(AVFrame *frame, int w, int h, uint8_t *yuvClusters) +{ + int i, j, k, l; + + for (i=0; idata, + i+2*k, j+2*l, frame->linesize); + yuvClusters += 24; + } +} + +static void generate_codebook(RoqContext *enc, roq_tempdata_t *tempdata, + int *points, int inputCount, roq_cell *results, + int size, int cbsize) +{ + int i, j, k; + int c_size = size*size/4; + int *buf = points; + int *codebook = av_malloc(6*c_size*cbsize*sizeof(int)); + int *closest_cb; + + if (size == 4) + closest_cb = av_malloc(6*c_size*inputCount*sizeof(int)); + else + closest_cb = tempdata->closest_cb2; + + ff_init_elbg(points, 6*c_size, inputCount, codebook, cbsize, 1, closest_cb, &enc->randctx); + ff_do_elbg(points, 6*c_size, inputCount, codebook, cbsize, 1, closest_cb, &enc->randctx); + + if (size == 4) + av_free(closest_cb); + + buf = codebook; + for (i=0; iy[j] = *buf++; + + results->u = (*buf++ + CHROMA_BIAS/2)/CHROMA_BIAS; + results->v = (*buf++ + CHROMA_BIAS/2)/CHROMA_BIAS; + results++; + } + + av_free(codebook); +} + +static void generate_new_codebooks(RoqContext *enc, roq_tempdata_t *tempData) +{ + int i,j; + roq_codebooks_t *codebooks = &tempData->codebooks; + int max = enc->width*enc->height/16; + uint8_t mb2[3*4]; + roq_cell *results4 = av_malloc(sizeof(roq_cell)*MAX_CBS_4x4*4); + uint8_t *yuvClusters=av_malloc(sizeof(int)*max*6*4); + int *points = av_malloc(max*6*4*sizeof(int)); + int bias; + + /* Subsample YUV data */ + create_clusters(enc->frame_to_enc, enc->width, enc->height, yuvClusters); + + /* Cast to integer and apply chroma bias */ + for (i=0; inumCB4 = MAX_CBS_4x4; + + tempData->closest_cb2 = av_malloc(max*4*sizeof(int)); + + /* Create 2x2 codebooks */ + generate_codebook(enc, tempData, points, max*4, enc->cb2x2, 2, MAX_CBS_2x2); + + codebooks->numCB2 = MAX_CBS_2x2; + + /* Unpack 2x2 codebook clusters */ + for (i=0; inumCB2; i++) + unpack_roq_cell(enc->cb2x2 + i, codebooks->unpacked_cb2 + i*2*2*3); + + /* Index all 4x4 entries to the 2x2 entries, unpack, and enlarge */ + for (i=0; inumCB4; i++) { + for (j=0; j<4; j++) { + unpack_roq_cell(&results4[4*i + j], mb2); + index_mb(mb2, codebooks->unpacked_cb2, codebooks->numCB2, + &enc->cb4x4[i].idx[j], 2); + } + unpack_roq_qcell(codebooks->unpacked_cb2, enc->cb4x4 + i, + codebooks->unpacked_cb4 + i*4*4*3); + enlarge_roq_mb4(codebooks->unpacked_cb4 + i*4*4*3, + codebooks->unpacked_cb4_enlarged + i*8*8*3); + } + + av_free(yuvClusters); + av_free(points); + av_free(results4); +} + +static void roq_encode_video(RoqContext *enc) +{ + roq_tempdata_t tempData; + int i; + + memset(&tempData, 0, sizeof(tempData)); + + create_cel_evals(enc, &tempData); + + generate_new_codebooks(enc, &tempData); + + if (enc->framesSinceKeyframe >= 1) { + motion_search(enc, 8); + motion_search(enc, 4); + } + + retry_encode: + for (i=0; iwidth*enc->height/64; i++) + gather_data_for_cel(tempData.cel_evals + i, enc, &tempData); + + /* Quake 3 can't handle chunks bigger than 65536 bytes */ + if (tempData.mainChunkSize/8 > 65536) { + enc->lambda *= .8; + goto retry_encode; + } + + remap_codebooks(enc, &tempData); + + write_codebooks(enc, &tempData); + + reconstruct_and_encode_image(enc, &tempData, enc->width, enc->height, + enc->width*enc->height/64); + + /* Rotate frame history */ + FFSWAP(AVFrame *, enc->current_frame, enc->last_frame); + FFSWAP(motion_vect *, enc->last_motion4, enc->this_motion4); + FFSWAP(motion_vect *, enc->last_motion8, enc->this_motion8); + + av_free(tempData.cel_evals); + av_free(tempData.closest_cb2); + + enc->framesSinceKeyframe++; +} + +static int roq_encode_init(AVCodecContext *avctx) +{ + RoqContext *enc = avctx->priv_data; + + av_init_random(1, &enc->randctx); + + enc->framesSinceKeyframe = 0; + if ((avctx->width & 0xf) || (avctx->height & 0xf)) { + av_log(avctx, AV_LOG_ERROR, "Dimensions must be divisible by 16\n"); + return -1; + } + + if (((avctx->width)&(avctx->width-1))||((avctx->height)&(avctx->height-1))) + av_log(avctx, AV_LOG_ERROR, "Warning: dimensions not power of two\n"); + + if (avcodec_check_dimensions(avctx, avctx->width, avctx->height)) { + av_log(avctx, AV_LOG_ERROR, "Invalid dimensions (%dx%d)\n", + avctx->width, avctx->height); + return -1; + } + + enc->width = avctx->width; + enc->height = avctx->height; + + enc->framesSinceKeyframe = 0; + enc->first_frame = 1; + + enc->last_frame = &enc->frames[0]; + enc->current_frame = &enc->frames[1]; + + enc->this_motion4 = + av_mallocz((enc->width*enc->height/16)*sizeof(motion_vect)); + + enc->last_motion4 = + av_malloc ((enc->width*enc->height/16)*sizeof(motion_vect)); + + enc->this_motion8 = + av_mallocz((enc->width*enc->height/64)*sizeof(motion_vect)); + + enc->last_motion8 = + av_malloc ((enc->width*enc->height/64)*sizeof(motion_vect)); + + return 0; +} + +static void roq_write_video_info_chunk(RoqContext *enc) +{ + /* ROQ info chunk */ + bytestream_put_le16(&enc->out_buf, RoQ_INFO); + + /* Size: 8 bytes */ + bytestream_put_le32(&enc->out_buf, 8); + + /* Unused argument */ + bytestream_put_byte(&enc->out_buf, 0x00); + bytestream_put_byte(&enc->out_buf, 0x00); + + /* Width */ + bytestream_put_le16(&enc->out_buf, enc->width); + + /* Height */ + bytestream_put_le16(&enc->out_buf, enc->height); + + /* Unused in Quake 3, mimics the output of the real encoder */ + bytestream_put_byte(&enc->out_buf, 0x08); + bytestream_put_byte(&enc->out_buf, 0x00); + bytestream_put_byte(&enc->out_buf, 0x04); + bytestream_put_byte(&enc->out_buf, 0x00); +} + +static int roq_encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data) +{ + RoqContext *enc = avctx->priv_data; + AVFrame *frame= data; + uint8_t *buf_start = buf; + + enc->out_buf = buf; + enc->avctx = avctx; + + enc->frame_to_enc = frame; + + if (frame->quality) + enc->lambda = frame->quality - 1; + else + enc->lambda = 2*ROQ_LAMBDA_SCALE; + + /* 138 bits max per 8x8 block + + * 256 codebooks*(6 bytes 2x2 + 4 bytes 4x4) + 8 bytes frame header */ + if (((enc->width*enc->height/64)*138+7)/8 + 256*(6+4) + 8 > buf_size) { + av_log(avctx, AV_LOG_ERROR, " RoQ: Output buffer too small!\n"); + return -1; + } + + /* Check for I frame */ + if (enc->framesSinceKeyframe == avctx->gop_size) + enc->framesSinceKeyframe = 0; + + if (enc->first_frame) { + /* Alloc memory for the reconstruction data (we must know the stride + for that) */ + if (avctx->get_buffer(avctx, enc->current_frame) || + avctx->get_buffer(avctx, enc->last_frame)) { + av_log(avctx, AV_LOG_ERROR, " RoQ: get_buffer() failed\n"); + return -1; + } + + /* Before the first video frame, write a "video info" chunk */ + roq_write_video_info_chunk(enc); + + enc->first_frame = 0; + } + + /* Encode the actual frame */ + roq_encode_video(enc); + + return enc->out_buf - buf_start; +} + +static int roq_encode_end(AVCodecContext *avctx) +{ + RoqContext *enc = avctx->priv_data; + + avctx->release_buffer(avctx, enc->last_frame); + avctx->release_buffer(avctx, enc->current_frame); + + av_free(enc->this_motion4); + av_free(enc->last_motion4); + av_free(enc->this_motion8); + av_free(enc->last_motion8); + + return 0; +} + +AVCodec roq_encoder = +{ + "roqvideo", + CODEC_TYPE_VIDEO, + CODEC_ID_ROQ, + sizeof(RoqContext), + roq_encode_init, + roq_encode_frame, + roq_encode_end, + .supported_framerates = (AVRational[]){{30,1}, {0,0}}, + .pix_fmts = (enum PixelFormat[]){PIX_FMT_YUV444P, -1}, +}; diff --git a/contrib/ffmpeg/libavcodec/rpza.c b/contrib/ffmpeg/libavcodec/rpza.c index 8ab5dbb92..ea36393aa 100644 --- a/contrib/ffmpeg/libavcodec/rpza.c +++ b/contrib/ffmpeg/libavcodec/rpza.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -40,7 +39,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include "dsputil.h" @@ -50,7 +48,7 @@ typedef struct RpzaContext { DSPContext dsp; AVFrame frame; - unsigned char *buf; + const unsigned char *buf; int size; } RpzaContext; @@ -232,11 +230,10 @@ static void rpza_decode_stream(RpzaContext *s) static int rpza_decode_init(AVCodecContext *avctx) { - RpzaContext *s = (RpzaContext *)avctx->priv_data; + RpzaContext *s = avctx->priv_data; s->avctx = avctx; avctx->pix_fmt = PIX_FMT_RGB555; - avctx->has_b_frames = 0; dsputil_init(&s->dsp, avctx); s->frame.data[0] = NULL; @@ -246,9 +243,9 @@ static int rpza_decode_init(AVCodecContext *avctx) static int rpza_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { - RpzaContext *s = (RpzaContext *)avctx->priv_data; + RpzaContext *s = avctx->priv_data; s->buf = buf; s->size = buf_size; @@ -271,7 +268,7 @@ static int rpza_decode_frame(AVCodecContext *avctx, static int rpza_decode_end(AVCodecContext *avctx) { - RpzaContext *s = (RpzaContext *)avctx->priv_data; + RpzaContext *s = avctx->priv_data; if (s->frame.data[0]) avctx->release_buffer(avctx, &s->frame); diff --git a/contrib/ffmpeg/libavcodec/rtjpeg.c b/contrib/ffmpeg/libavcodec/rtjpeg.c index dbc6cfd88..48fb35c95 100644 --- a/contrib/ffmpeg/libavcodec/rtjpeg.c +++ b/contrib/ffmpeg/libavcodec/rtjpeg.c @@ -43,8 +43,8 @@ * aligned this could be done faster in a different way, e.g. as it is done * in MPlayer libmpcodecs/native/RTjpegN.c */ -static inline int get_block(GetBitContext *gb, DCTELEM *block, uint8_t *scan, - uint32_t *quant) { +static inline int get_block(GetBitContext *gb, DCTELEM *block, const uint8_t *scan, + const uint32_t *quant) { int coeff, i, n; int8_t ac; uint8_t dc = get_bits(gb, 8); @@ -97,7 +97,7 @@ static inline int get_block(GetBitContext *gb, DCTELEM *block, uint8_t *scan, * \return number of bytes consumed from the input buffer */ int rtjpeg_decode_frame_yuv420(RTJpegContext *c, AVFrame *f, - uint8_t *buf, int buf_size) { + const uint8_t *buf, int buf_size) { DECLARE_ALIGNED_16(DCTELEM, block[64]); GetBitContext gb; int w = c->w / 16, h = c->h / 16; @@ -147,7 +147,7 @@ int rtjpeg_decode_frame_yuv420(RTJpegContext *c, AVFrame *f, */ void rtjpeg_decode_init(RTJpegContext *c, DSPContext *dsp, int width, int height, - uint32_t *lquant, uint32_t *cquant) { + const uint32_t *lquant, const uint32_t *cquant) { int i; c->dsp = dsp; for (i = 0; i < 64; i++) { diff --git a/contrib/ffmpeg/libavcodec/rtjpeg.h b/contrib/ffmpeg/libavcodec/rtjpeg.h index daecc8a75..0c23eced5 100644 --- a/contrib/ffmpeg/libavcodec/rtjpeg.h +++ b/contrib/ffmpeg/libavcodec/rtjpeg.h @@ -19,8 +19,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef RTJPEG_H -#define RTJPEG_H +#ifndef FFMPEG_RTJPEG_H +#define FFMPEG_RTJPEG_H + +#include +#include typedef struct { int w, h; @@ -32,8 +35,8 @@ typedef struct { void rtjpeg_decode_init(RTJpegContext *c, DSPContext *dsp, int width, int height, - uint32_t *lquant, uint32_t *cquant); + const uint32_t *lquant, const uint32_t *cquant); int rtjpeg_decode_frame_yuv420(RTJpegContext *c, AVFrame *f, - uint8_t *buf, int buf_size); -#endif + const uint8_t *buf, int buf_size); +#endif /* FFMPEG_RTJPEG_H */ diff --git a/contrib/ffmpeg/libavcodec/rv10.c b/contrib/ffmpeg/libavcodec/rv10.c index e1e8287d5..7ee812a7e 100644 --- a/contrib/ffmpeg/libavcodec/rv10.c +++ b/contrib/ffmpeg/libavcodec/rv10.c @@ -195,12 +195,12 @@ int rv_decode_dc(MpegEncContext *s, int n) } else if (code == 0x7d) { code = -128 + get_bits(&s->gb, 7); } else if (code == 0x7e) { - if (get_bits(&s->gb, 1) == 0) + if (get_bits1(&s->gb) == 0) code = (int8_t)(get_bits(&s->gb, 8) + 1); else code = (int8_t)(get_bits(&s->gb, 8)); } else if (code == 0x7f) { - get_bits(&s->gb, 11); + skip_bits(&s->gb, 11); code = 1; } } else { @@ -216,7 +216,7 @@ int rv_decode_dc(MpegEncContext *s, int n) } else if (code == 0x1fd) { code = -128 + get_bits(&s->gb, 7); } else if (code == 0x1fe) { - get_bits(&s->gb, 9); + skip_bits(&s->gb, 9); code = 1; } else { av_log(s->avctx, AV_LOG_ERROR, "chroma dc error\n"); @@ -312,15 +312,15 @@ static int rv10_decode_picture_header(MpegEncContext *s) int mb_count, pb_frame, marker, unk, mb_xy; //printf("ff:%d\n", full_frame); - marker = get_bits(&s->gb, 1); + marker = get_bits1(&s->gb); - if (get_bits(&s->gb, 1)) + if (get_bits1(&s->gb)) s->pict_type = P_TYPE; else s->pict_type = I_TYPE; //printf("h:%X ver:%d\n",h,s->rv10_version); if(!marker) av_log(s->avctx, AV_LOG_ERROR, "marker missing\n"); - pb_frame = get_bits(&s->gb, 1); + pb_frame = get_bits1(&s->gb); #ifdef DEBUG av_log(s->avctx, AV_LOG_DEBUG, "pict_type=%d pb_frame=%d\n", s->pict_type, pb_frame); @@ -416,7 +416,7 @@ static int rv20_decode_picture_header(MpegEncContext *s) return -1; } - if (get_bits(&s->gb, 1)){ + if (get_bits1(&s->gb)){ av_log(s->avctx, AV_LOG_ERROR, "unknown bit set\n"); return -1; } @@ -427,7 +427,7 @@ static int rv20_decode_picture_header(MpegEncContext *s) return -1; } if(s->avctx->sub_id == 0x30203002){ - if (get_bits(&s->gb, 1)){ + if (get_bits1(&s->gb)){ av_log(s->avctx, AV_LOG_ERROR, "unknown bit2 set\n"); return -1; } @@ -437,7 +437,7 @@ static int rv20_decode_picture_header(MpegEncContext *s) int f, new_w, new_h; int v= s->avctx->extradata_size >= 4 ? 7&((uint8_t*)s->avctx->extradata)[1] : 0; - if (get_bits(&s->gb, 1)){ + if (get_bits1(&s->gb)){ av_log(s->avctx, AV_LOG_ERROR, "unknown bit3 set\n"); // return -1; } @@ -539,43 +539,29 @@ static int rv10_decode_init(AVCodecContext *avctx) s->h263_long_vectors= ((uint8_t*)avctx->extradata)[3] & 1; avctx->sub_id= AV_RB32((uint8_t*)avctx->extradata + 4); - switch(avctx->sub_id){ - case 0x10000000: + if (avctx->sub_id == 0x10000000) { s->rv10_version= 0; s->low_delay=1; - break; - case 0x10002000: + } else if (avctx->sub_id == 0x10002000) { s->rv10_version= 3; s->low_delay=1; s->obmc=1; - break; - case 0x10003000: + } else if (avctx->sub_id == 0x10003000) { s->rv10_version= 3; s->low_delay=1; - break; - case 0x10003001: + } else if (avctx->sub_id == 0x10003001) { s->rv10_version= 3; s->low_delay=1; - break; - case 0x20001000: /* real rv20 decoder fail on this id */ - /*case 0x20100001: - case 0x20101001: - case 0x20103001:*/ - case 0x20100000 ... 0x2019ffff: + } else if ( avctx->sub_id == 0x20001000 + || (avctx->sub_id >= 0x20100000 && avctx->sub_id < 0x201a0000)) { s->low_delay=1; - break; - /*case 0x20200002: - case 0x20201002: - case 0x20203002:*/ - case 0x20200002 ... 0x202fffff: - case 0x30202002: - case 0x30203002: + } else if ( avctx->sub_id == 0x30202002 + || avctx->sub_id == 0x30203002 + || (avctx->sub_id >= 0x20200002 && avctx->sub_id < 0x20300000)) { s->low_delay=0; s->avctx->has_b_frames=1; - break; - default: + } else av_log(s->avctx, AV_LOG_ERROR, "unknown header %X\n", avctx->sub_id); - } if(avctx->debug & FF_DEBUG_PICT_INFO){ av_log(avctx, AV_LOG_DEBUG, "ver:%X ver0:%X\n", avctx->sub_id, avctx->extradata_size >= 4 ? ((uint32_t*)avctx->extradata)[0] : -1); @@ -611,7 +597,7 @@ static int rv10_decode_end(AVCodecContext *avctx) } static int rv10_decode_packet(AVCodecContext *avctx, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { MpegEncContext *s = avctx->priv_data; int mb_count, mb_pos, left, start_mb_x; @@ -725,13 +711,21 @@ static int rv10_decode_packet(AVCodecContext *avctx, return buf_size; } +static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n) +{ + if(avctx->slice_count) return avctx->slice_offset[n]; + else return AV_RL32(buf + n*8); +} + static int rv10_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { MpegEncContext *s = avctx->priv_data; int i; AVFrame *pict = data; + int slice_count; + const uint8_t *slices_hdr = NULL; #ifdef DEBUG av_log(avctx, AV_LOG_DEBUG, "*****frame %d size=%d\n", avctx->frame_number, buf_size); @@ -742,20 +736,23 @@ static int rv10_decode_frame(AVCodecContext *avctx, return 0; } - if(avctx->slice_count){ - for(i=0; islice_count; i++){ - int offset= avctx->slice_offset[i]; - int size; + if(!avctx->slice_count){ + slice_count = (*buf++) + 1; + slices_hdr = buf + 4; + buf += 8 * slice_count; + }else + slice_count = avctx->slice_count; - if(i+1 == avctx->slice_count) - size= buf_size - offset; - else - size= avctx->slice_offset[i+1] - offset; + for(i=0; icurrent_picture_ptr != NULL && s->mb_y>=s->mb_height){ diff --git a/contrib/ffmpeg/libavcodec/rv30.c b/contrib/ffmpeg/libavcodec/rv30.c new file mode 100644 index 000000000..ff7b32d1e --- /dev/null +++ b/contrib/ffmpeg/libavcodec/rv30.c @@ -0,0 +1,147 @@ +/* + * RV30 decoder + * Copyright (c) 2007 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file rv30.c + * RV30 decoder + */ + +#include "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" +#include "golomb.h" + +#include "rv34.h" +#include "rv30data.h" + + +static int rv30_parse_slice_header(RV34DecContext *r, GetBitContext *gb, SliceInfo *si) +{ + int mb_bits; + int w = r->s.width, h = r->s.height; + int mb_size; + + memset(si, 0, sizeof(SliceInfo)); + skip_bits(gb, 3); + si->type = get_bits(gb, 2); + if(si->type == 1) si->type = 0; + if(get_bits1(gb)) + return -1; + si->quant = get_bits(gb, 5); + skip_bits1(gb); + skip_bits(gb, 13); // timestamp + skip_bits(gb, r->rpr); + si->width = w; + si->height = h; + mb_size = ((w + 15) >> 4) * ((h + 15) >> 4); + mb_bits = ff_rv34_get_start_offset(gb, mb_size); + si->start = get_bits(gb, mb_bits); + skip_bits1(gb); + return 0; +} + +/** + * Decode 4x4 intra types array. + */ +static int rv30_decode_intra_types(RV34DecContext *r, GetBitContext *gb, int8_t *dst) +{ + int i, j, k; + + for(i = 0; i < 4; i++, dst += r->s.b4_stride - 4){ + for(j = 0; j < 4; j+= 2){ + int code = svq3_get_ue_golomb(gb) << 1; + if(code >= 81*2){ + av_log(r->s.avctx, AV_LOG_ERROR, "Incorrect intra prediction code\n"); + return -1; + } + for(k = 0; k < 2; k++){ + int A = dst[-r->s.b4_stride] + 1; + int B = dst[-1] + 1; + *dst++ = rv30_itype_from_context[A * 90 + B * 9 + rv30_itype_code[code + k]]; + if(dst[-1] == 9){ + av_log(r->s.avctx, AV_LOG_ERROR, "Incorrect intra prediction mode\n"); + return -1; + } + } + } + } + return 0; +} + +/** + * Decode macroblock information. + */ +static int rv30_decode_mb_info(RV34DecContext *r) +{ + static const int rv30_p_types[6] = { RV34_MB_SKIP, RV34_MB_P_16x16, RV34_MB_P_8x8, -1, RV34_MB_TYPE_INTRA, RV34_MB_TYPE_INTRA16x16 }; + static const int rv30_b_types[6] = { RV34_MB_SKIP, RV34_MB_B_DIRECT, RV34_MB_B_FORWARD, RV34_MB_B_BACKWARD, RV34_MB_TYPE_INTRA, RV34_MB_TYPE_INTRA16x16 }; + MpegEncContext *s = &r->s; + GetBitContext *gb = &s->gb; + int code = svq3_get_ue_golomb(gb); + + if(code > 11){ + av_log(s->avctx, AV_LOG_ERROR, "Incorrect MB type code\n"); + return -1; + } + if(code > 5){ + av_log(s->avctx, AV_LOG_ERROR, "dquant needed\n"); + code -= 6; + } + if(s->pict_type != B_TYPE) + return rv30_p_types[code]; + else + return rv30_b_types[code]; +} + +/** + * Initialize decoder. + */ +static int rv30_decode_init(AVCodecContext *avctx) +{ + RV34DecContext *r = avctx->priv_data; + + r->rv30 = 1; + ff_rv34_decode_init(avctx); + if(avctx->extradata_size < 2){ + av_log(avctx, AV_LOG_ERROR, "Extradata is too small.\n"); + return -1; + } + r->rpr = (avctx->extradata[1] & 7) >> 1; + r->rpr = FFMIN(r->rpr + 1, 3); + r->parse_slice_header = rv30_parse_slice_header; + r->decode_intra_types = rv30_decode_intra_types; + r->decode_mb_info = rv30_decode_mb_info; + r->luma_dc_quant_i = rv30_luma_dc_quant; + r->luma_dc_quant_p = rv30_luma_dc_quant; + return 0; +} + +AVCodec rv30_decoder = { + "rv30", + CODEC_TYPE_VIDEO, + CODEC_ID_RV30, + sizeof(RV34DecContext), + rv30_decode_init, + NULL, + ff_rv34_decode_end, + ff_rv34_decode_frame, + CODEC_CAP_DR1 | CODEC_CAP_DELAY, +}; diff --git a/contrib/ffmpeg/libavcodec/rv30data.h b/contrib/ffmpeg/libavcodec/rv30data.h new file mode 100644 index 000000000..98ccb352d --- /dev/null +++ b/contrib/ffmpeg/libavcodec/rv30data.h @@ -0,0 +1,174 @@ +/* + * RealVideo 3 decoder + * copyright (c) 2007 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file rv30data.h + * miscellaneous RV30 tables + */ + +#ifndef FFMPEG_RV30DATA_H +#define FFMPEG_RV30DATA_H + +#include + +/** DC quantizer mapping for RV30 */ +static const uint8_t rv30_luma_dc_quant[32] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 22, 22, 23, 23, 23, 24, 24, 25, 25 +}; + +/** + * This table is used for storing the differences + * between the predicted and the real intra type. + */ +static const uint8_t rv30_itype_code[9*9*2] = { + 0, 0, 0, 1, 1, 0, 1, 1, 0, 2, 2, 0, 0, 3, 3, 0, 1, 2, + 2, 1, 0, 4, 4, 0, 3, 1, 1, 3, 0, 5, 5, 0, 2, 2, 1, 4, + 4, 1, 0, 6, 3, 2, 1, 5, 2, 3, 5, 1, 6, 0, 0, 7, 4, 2, + 2, 4, 3, 3, 6, 1, 1, 6, 7, 0, 0, 8, 5, 2, 4, 3, 2, 5, + 3, 4, 1, 7, 4, 4, 7, 1, 8, 0, 6, 2, 3, 5, 5, 3, 2, 6, + 1, 8, 2, 7, 7, 2, 8, 1, 5, 4, 4, 5, 3, 6, 6, 3, 8, 2, + 4, 6, 5, 5, 6, 4, 2, 8, 7, 3, 3, 7, 6, 5, 5, 6, 7, 4, + 4, 7, 8, 3, 3, 8, 7, 5, 8, 4, 5, 7, 4, 8, 6, 6, 7, 6, + 5, 8, 8, 5, 6, 7, 8, 6, 7, 7, 6, 8, 8, 7, 7, 8, 8, 8, +}; + +/** + * This table is used for retrieving the current intra type + * based on its neighbors and adjustment provided by + * code read and decoded before. + * + * This is really a three-dimensional matrix with dimensions + * [-1..9][-1..9][0..9]. The first and second coordinates are + * detemined by the top and left neighbors (-1 if unavailable). + */ +static const uint8_t rv30_itype_from_context[900] = { + 0, 9, 9, 9, 9, 9, 9, 9, 9, + 0, 2, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, + 2, 0, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, + + 0, 1, 9, 9, 9, 9, 9, 9, 9, + 0, 2, 1, 6, 4, 8, 5, 7, 3, + 1, 0, 2, 6, 5, 4, 3, 8, 7, + 2, 8, 0, 1, 7, 4, 3, 6, 5, + 2, 0, 1, 3, 8, 5, 4, 7, 6, + 2, 0, 1, 4, 6, 7, 8, 3, 5, + 0, 1, 5, 2, 6, 3, 8, 4, 7, + 0, 1, 6, 2, 4, 7, 5, 8, 3, + 2, 7, 0, 1, 4, 8, 6, 3, 5, + 2, 8, 0, 1, 7, 3, 4, 5, 6, + + 1, 0, 9, 9, 9, 9, 9, 9, 9, + 1, 2, 5, 6, 3, 0, 4, 8, 7, + 1, 6, 2, 5, 3, 0, 4, 8, 7, + 2, 1, 7, 6, 8, 3, 5, 0, 4, + 1, 2, 5, 3, 6, 8, 4, 7, 0, + 1, 6, 2, 0, 4, 5, 8, 7, 3, + 1, 5, 2, 6, 3, 8, 4, 0, 7, + 1, 6, 0, 2, 4, 5, 7, 3, 8, + 2, 1, 7, 6, 0, 8, 5, 4, 3, + 1, 2, 7, 8, 3, 4, 5, 6, 0, + + 9, 9, 9, 9, 9, 9, 9, 9, 9, + 0, 2, 1, 8, 7, 6, 5, 4, 3, + 1, 2, 0, 6, 5, 7, 4, 8, 3, + 2, 8, 7, 1, 0, 6, 4, 3, 5, + 2, 0, 8, 1, 3, 7, 5, 4, 6, + 2, 0, 4, 1, 7, 8, 6, 3, 5, + 2, 0, 1, 5, 8, 4, 6, 7, 3, + 2, 0, 6, 1, 4, 7, 8, 5, 3, + 2, 7, 8, 1, 0, 5, 4, 6, 3, + 2, 8, 7, 1, 0, 4, 3, 6, 5, + + 9, 9, 9, 9, 9, 9, 9, 9, 9, + 0, 2, 1, 3, 5, 8, 6, 4, 7, + 1, 0, 2, 5, 3, 6, 4, 8, 7, + 2, 8, 1, 0, 3, 5, 7, 6, 4, + 3, 2, 5, 8, 1, 4, 6, 7, 0, + 4, 2, 0, 6, 1, 5, 8, 3, 7, + 5, 3, 1, 2, 8, 6, 4, 0, 7, + 1, 6, 0, 2, 4, 5, 8, 3, 7, + 2, 7, 0, 1, 5, 4, 8, 6, 3, + 2, 8, 3, 5, 1, 0, 7, 6, 4, + + 9, 9, 9, 9, 9, 9, 9, 9, 9, + 2, 0, 6, 1, 4, 7, 5, 8, 3, + 1, 6, 2, 0, 4, 5, 3, 7, 8, + 2, 8, 7, 6, 4, 0, 1, 5, 3, + 4, 2, 1, 0, 6, 8, 3, 5, 7, + 4, 2, 6, 0, 1, 5, 7, 8, 3, + 1, 2, 5, 0, 6, 3, 4, 7, 8, + 6, 4, 0, 1, 2, 7, 5, 3, 8, + 2, 7, 4, 6, 0, 1, 8, 5, 3, + 2, 8, 7, 4, 6, 1, 3, 5, 0, + + 9, 9, 9, 9, 9, 9, 9, 9, 9, + 5, 1, 2, 3, 6, 8, 0, 4, 7, + 1, 5, 6, 3, 2, 0, 4, 8, 7, + 2, 1, 5, 3, 6, 8, 7, 4, 0, + 5, 3, 1, 2, 6, 8, 4, 7, 0, + 1, 6, 2, 4, 5, 8, 0, 3, 7, + 5, 1, 3, 6, 2, 0, 8, 4, 7, + 1, 6, 5, 2, 0, 4, 3, 7, 8, + 2, 7, 1, 6, 5, 0, 8, 3, 4, + 2, 5, 1, 3, 6, 8, 4, 0, 7, + + 9, 9, 9, 9, 9, 9, 9, 9, 9, + 1, 6, 2, 0, 5, 4, 3, 7, 8, + 1, 6, 5, 4, 2, 3, 0, 7, 8, + 2, 1, 6, 7, 4, 8, 5, 3, 0, + 2, 1, 6, 5, 8, 4, 3, 0, 7, + 6, 4, 1, 2, 0, 5, 7, 8, 3, + 1, 6, 5, 2, 3, 0, 4, 8, 7, + 6, 1, 4, 0, 2, 7, 5, 3, 8, + 2, 7, 4, 6, 1, 5, 0, 8, 3, + 2, 1, 6, 8, 4, 7, 3, 5, 0, + + 9, 9, 9, 9, 9, 9, 9, 9, 9, + 2, 0, 4, 7, 6, 1, 8, 5, 3, + 6, 1, 2, 0, 4, 7, 5, 8, 3, + 2, 7, 8, 0, 1, 6, 4, 3, 5, + 2, 4, 0, 8, 3, 1, 7, 6, 5, + 4, 2, 7, 0, 6, 1, 8, 5, 3, + 2, 1, 0, 8, 5, 6, 7, 4, 3, + 2, 6, 4, 1, 7, 0, 5, 8, 3, + 2, 7, 4, 0, 8, 6, 1, 5, 3, + 2, 8, 7, 4, 1, 0, 3, 6, 5, + + 9, 9, 9, 9, 9, 9, 9, 9, 9, + 2, 0, 8, 1, 3, 4, 6, 5, 7, + 1, 2, 0, 6, 8, 5, 7, 3, 4, + 2, 8, 7, 1, 0, 3, 6, 5, 4, + 8, 3, 2, 5, 1, 0, 4, 7, 6, + 2, 0, 4, 8, 5, 1, 7, 6, 3, + 2, 1, 0, 8, 5, 3, 6, 4, 7, + 2, 1, 6, 0, 8, 4, 5, 7, 3, + 2, 7, 8, 4, 0, 6, 1, 5, 3, + 2, 8, 3, 0, 7, 4, 1, 6, 5, +}; +#endif /* FFMPEG_RV30DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/rv30dsp.c b/contrib/ffmpeg/libavcodec/rv30dsp.c new file mode 100644 index 000000000..13b218b88 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/rv30dsp.c @@ -0,0 +1,249 @@ +/* + * RV30 decoder motion compensation functions + * Copyright (c) 2007 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file rv30dsp.c + * RV30 decoder motion compensation functions + */ + +#include "avcodec.h" +#include "dsputil.h" + +#define RV30_LOWPASS(OPNAME, OP) \ +static av_unused void OPNAME ## rv30_tpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, const int C1, const int C2){\ + const int h=8;\ + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ + int i;\ + for(i=0; i>4]+1)>>1) +#define op_put(a, b) a = cm[((b) + 8)>>4] + +RV30_LOWPASS(put_ , op_put) +RV30_LOWPASS(avg_ , op_avg) +RV30_MC(put_, 8) +RV30_MC(put_, 16) +RV30_MC(avg_, 8) +RV30_MC(avg_, 16) + +void ff_rv30dsp_init(DSPContext* c, AVCodecContext *avctx) { + c->put_rv30_tpel_pixels_tab[0][ 0] = c->put_h264_qpel_pixels_tab[0][0]; + c->put_rv30_tpel_pixels_tab[0][ 1] = put_rv30_tpel16_mc10_c; + c->put_rv30_tpel_pixels_tab[0][ 2] = put_rv30_tpel16_mc20_c; + c->put_rv30_tpel_pixels_tab[0][ 4] = put_rv30_tpel16_mc01_c; + c->put_rv30_tpel_pixels_tab[0][ 5] = put_rv30_tpel16_mc11_c; + c->put_rv30_tpel_pixels_tab[0][ 6] = put_rv30_tpel16_mc21_c; + c->put_rv30_tpel_pixels_tab[0][ 8] = put_rv30_tpel16_mc02_c; + c->put_rv30_tpel_pixels_tab[0][ 9] = put_rv30_tpel16_mc12_c; + c->put_rv30_tpel_pixels_tab[0][10] = put_rv30_tpel16_mc22_c; + c->avg_rv30_tpel_pixels_tab[0][ 0] = c->avg_h264_qpel_pixels_tab[0][0]; + c->avg_rv30_tpel_pixels_tab[0][ 1] = avg_rv30_tpel16_mc10_c; + c->avg_rv30_tpel_pixels_tab[0][ 2] = avg_rv30_tpel16_mc20_c; + c->avg_rv30_tpel_pixels_tab[0][ 4] = avg_rv30_tpel16_mc01_c; + c->avg_rv30_tpel_pixels_tab[0][ 5] = avg_rv30_tpel16_mc11_c; + c->avg_rv30_tpel_pixels_tab[0][ 6] = avg_rv30_tpel16_mc21_c; + c->avg_rv30_tpel_pixels_tab[0][ 8] = avg_rv30_tpel16_mc02_c; + c->avg_rv30_tpel_pixels_tab[0][ 9] = avg_rv30_tpel16_mc12_c; + c->avg_rv30_tpel_pixels_tab[0][10] = avg_rv30_tpel16_mc22_c; + c->put_rv30_tpel_pixels_tab[1][ 0] = c->put_h264_qpel_pixels_tab[1][0]; + c->put_rv30_tpel_pixels_tab[1][ 1] = put_rv30_tpel8_mc10_c; + c->put_rv30_tpel_pixels_tab[1][ 2] = put_rv30_tpel8_mc20_c; + c->put_rv30_tpel_pixels_tab[1][ 4] = put_rv30_tpel8_mc01_c; + c->put_rv30_tpel_pixels_tab[1][ 5] = put_rv30_tpel8_mc11_c; + c->put_rv30_tpel_pixels_tab[1][ 6] = put_rv30_tpel8_mc21_c; + c->put_rv30_tpel_pixels_tab[1][ 8] = put_rv30_tpel8_mc02_c; + c->put_rv30_tpel_pixels_tab[1][ 9] = put_rv30_tpel8_mc12_c; + c->put_rv30_tpel_pixels_tab[1][10] = put_rv30_tpel8_mc22_c; + c->avg_rv30_tpel_pixels_tab[1][ 0] = c->avg_h264_qpel_pixels_tab[1][0]; + c->avg_rv30_tpel_pixels_tab[1][ 1] = avg_rv30_tpel8_mc10_c; + c->avg_rv30_tpel_pixels_tab[1][ 2] = avg_rv30_tpel8_mc20_c; + c->avg_rv30_tpel_pixels_tab[1][ 4] = avg_rv30_tpel8_mc01_c; + c->avg_rv30_tpel_pixels_tab[1][ 5] = avg_rv30_tpel8_mc11_c; + c->avg_rv30_tpel_pixels_tab[1][ 6] = avg_rv30_tpel8_mc21_c; + c->avg_rv30_tpel_pixels_tab[1][ 8] = avg_rv30_tpel8_mc02_c; + c->avg_rv30_tpel_pixels_tab[1][ 9] = avg_rv30_tpel8_mc12_c; + c->avg_rv30_tpel_pixels_tab[1][10] = avg_rv30_tpel8_mc22_c; +} diff --git a/contrib/ffmpeg/libavcodec/rv34.c b/contrib/ffmpeg/libavcodec/rv34.c new file mode 100644 index 000000000..5b5849896 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/rv34.c @@ -0,0 +1,1299 @@ +/* + * RV30/40 decoder common data + * Copyright (c) 2007 Mike Melanson, Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file rv34.c + * RV30/40 decoder common data + */ + +#include "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" +#include "golomb.h" +#include "rectangle.h" + +#include "rv34vlc.h" +#include "rv34data.h" +#include "rv34.h" + +//#define DEBUG + +/** translation of RV30/40 macroblock types to lavc ones */ +static const int rv34_mb_type_to_lavc[12] = { + MB_TYPE_INTRA, + MB_TYPE_INTRA16x16, + MB_TYPE_16x16 | MB_TYPE_L0, + MB_TYPE_8x8 | MB_TYPE_L0, + MB_TYPE_16x16 | MB_TYPE_L0, + MB_TYPE_16x16 | MB_TYPE_L1, + MB_TYPE_SKIP, + MB_TYPE_DIRECT2 | MB_TYPE_16x16, + MB_TYPE_16x8 | MB_TYPE_L0, + MB_TYPE_8x16 | MB_TYPE_L0, + MB_TYPE_16x16 | MB_TYPE_L0L1, + MB_TYPE_16x16 | MB_TYPE_L0 +}; + + +static RV34VLC intra_vlcs[NUM_INTRA_TABLES], inter_vlcs[NUM_INTER_TABLES]; + +/** + * @defgroup vlc RV30/40 VLC generating functions + * @{ + */ + +/** + * Generate VLC from codeword lengths. + * @param bits codeword lengths (zeroes are accepted) + * @param size length of input data + * @param insyms symbols for input codes (NULL for default ones) + */ +static void rv34_gen_vlc(const uint8_t *bits, int size, VLC *vlc, const uint8_t *insyms) +{ + int i; + int counts[17] = {0}, codes[17]; + uint16_t cw[size], syms[size]; + uint8_t bits2[size]; + int maxbits = 0, realsize = 0; + + for(i = 0; i < size; i++){ + if(bits[i]){ + bits2[realsize] = bits[i]; + syms[realsize] = insyms ? insyms[i] : i; + realsize++; + maxbits = FFMAX(maxbits, bits[i]); + counts[bits[i]]++; + } + } + + codes[0] = 0; + for(i = 0; i < 16; i++) + codes[i+1] = (codes[i] + counts[i]) << 1; + for(i = 0; i < realsize; i++) + cw[i] = codes[bits2[i]]++; + + init_vlc_sparse(vlc, FFMIN(maxbits, 9), realsize, + bits2, 1, 1, + cw, 2, 2, + syms, 2, 2, INIT_VLC_USE_STATIC); +} + +/** + * Initialize all tables. + */ +static void rv34_init_tables() +{ + int i, j, k; + + for(i = 0; i < NUM_INTRA_TABLES; i++){ + for(j = 0; j < 2; j++){ + rv34_gen_vlc(rv34_table_intra_cbppat [i][j], CBPPAT_VLC_SIZE, &intra_vlcs[i].cbppattern[j], NULL); + rv34_gen_vlc(rv34_table_intra_secondpat[i][j], OTHERBLK_VLC_SIZE, &intra_vlcs[i].second_pattern[j], NULL); + rv34_gen_vlc(rv34_table_intra_thirdpat [i][j], OTHERBLK_VLC_SIZE, &intra_vlcs[i].third_pattern[j], NULL); + for(k = 0; k < 4; k++) + rv34_gen_vlc(rv34_table_intra_cbp[i][j+k*2], CBP_VLC_SIZE, &intra_vlcs[i].cbp[j][k], rv34_cbp_code); + } + for(j = 0; j < 4; j++) + rv34_gen_vlc(rv34_table_intra_firstpat[i][j], FIRSTBLK_VLC_SIZE, &intra_vlcs[i].first_pattern[j], NULL); + rv34_gen_vlc(rv34_intra_coeff[i], COEFF_VLC_SIZE, &intra_vlcs[i].coefficient, NULL); + } + + for(i = 0; i < NUM_INTER_TABLES; i++){ + rv34_gen_vlc(rv34_inter_cbppat[i], CBPPAT_VLC_SIZE, &inter_vlcs[i].cbppattern[0], NULL); + for(j = 0; j < 4; j++) + rv34_gen_vlc(rv34_inter_cbp[i][j], CBP_VLC_SIZE, &inter_vlcs[i].cbp[0][j], rv34_cbp_code); + for(j = 0; j < 2; j++){ + rv34_gen_vlc(rv34_table_inter_firstpat [i][j], FIRSTBLK_VLC_SIZE, &inter_vlcs[i].first_pattern[j], NULL); + rv34_gen_vlc(rv34_table_inter_secondpat[i][j], OTHERBLK_VLC_SIZE, &inter_vlcs[i].second_pattern[j], NULL); + rv34_gen_vlc(rv34_table_inter_thirdpat [i][j], OTHERBLK_VLC_SIZE, &inter_vlcs[i].third_pattern[j], NULL); + } + rv34_gen_vlc(rv34_inter_coeff[i], COEFF_VLC_SIZE, &inter_vlcs[i].coefficient, NULL); + } +} + +/** @} */ // vlc group + + +/** + * @defgroup transform RV30/40 inverse transform functions + * @{ + */ + +static av_always_inline void rv34_row_transform(int temp[16], DCTELEM *block) +{ + int i; + + for(i=0; i<4; i++){ + const int z0= 13*(block[i+8*0] + block[i+8*2]); + const int z1= 13*(block[i+8*0] - block[i+8*2]); + const int z2= 7* block[i+8*1] - 17*block[i+8*3]; + const int z3= 17* block[i+8*1] + 7*block[i+8*3]; + + temp[4*i+0]= z0+z3; + temp[4*i+1]= z1+z2; + temp[4*i+2]= z1-z2; + temp[4*i+3]= z0-z3; + } +} + +/** + * Real Video 3.0/4.0 inverse transform + * Code is almost the same as in SVQ3, only scaling is different. + */ +static void rv34_inv_transform(DCTELEM *block){ + int temp[16]; + int i; + + rv34_row_transform(temp, block); + + for(i=0; i<4; i++){ + const int z0= 13*(temp[4*0+i] + temp[4*2+i]) + 0x200; + const int z1= 13*(temp[4*0+i] - temp[4*2+i]) + 0x200; + const int z2= 7* temp[4*1+i] - 17*temp[4*3+i]; + const int z3= 17* temp[4*1+i] + 7*temp[4*3+i]; + + block[i*8+0]= (z0 + z3)>>10; + block[i*8+1]= (z1 + z2)>>10; + block[i*8+2]= (z1 - z2)>>10; + block[i*8+3]= (z0 - z3)>>10; + } + +} + +/** + * RealVideo 3.0/4.0 inverse transform for DC block + * + * Code is almost the same as rv34_inv_transform() + * but final coefficients are multiplied by 1.5 and have no rounding. + */ +static void rv34_inv_transform_noround(DCTELEM *block){ + int temp[16]; + int i; + + rv34_row_transform(temp, block); + + for(i=0; i<4; i++){ + const int z0= 13*(temp[4*0+i] + temp[4*2+i]); + const int z1= 13*(temp[4*0+i] - temp[4*2+i]); + const int z2= 7* temp[4*1+i] - 17*temp[4*3+i]; + const int z3= 17* temp[4*1+i] + 7*temp[4*3+i]; + + block[i*8+0]= ((z0 + z3)*3)>>11; + block[i*8+1]= ((z1 + z2)*3)>>11; + block[i*8+2]= ((z1 - z2)*3)>>11; + block[i*8+3]= ((z0 - z3)*3)>>11; + } + +} + +/** @} */ // transform + + +/** + * @defgroup block RV30/40 4x4 block decoding functions + * @{ + */ + +/** + * Decode coded block pattern. + */ +static int rv34_decode_cbp(GetBitContext *gb, RV34VLC *vlc, int table) +{ + int pattern, code, cbp=0; + int ones; + static const int cbp_masks[3] = {0x100000, 0x010000, 0x110000}; + static const int shifts[4] = { 0, 2, 8, 10 }; + int *curshift = shifts; + int i, t, mask; + + code = get_vlc2(gb, vlc->cbppattern[table].table, 9, 2); + pattern = code & 0xF; + code >>= 4; + + ones = rv34_count_ones[pattern]; + + for(mask = 8; mask; mask >>= 1, curshift++){ + if(pattern & mask) + cbp |= get_vlc2(gb, vlc->cbp[table][ones].table, vlc->cbp[table][ones].bits, 1) << curshift[0]; + } + + for(i = 0; i < 4; i++){ + t = modulo_three_table[code][i]; + if(t == 1) + cbp |= cbp_masks[get_bits1(gb)] << i; + if(t == 2) + cbp |= cbp_masks[2] << i; + } + return cbp; +} + +/** + * Get one coefficient value from the bistream and store it. + */ +static inline void decode_coeff(DCTELEM *dst, int coef, int esc, GetBitContext *gb, VLC* vlc) +{ + if(coef){ + if(coef == esc){ + coef = get_vlc2(gb, vlc->table, 9, 2); + if(coef > 23){ + coef -= 23; + coef = 22 + ((1 << coef) | get_bits(gb, coef)); + } + coef += esc; + } + if(get_bits1(gb)) + coef = -coef; + *dst = coef; + } +} + +/** + * Decode 2x2 subblock of coefficients. + */ +static inline void decode_subblock(DCTELEM *dst, int code, const int is_block2, GetBitContext *gb, VLC *vlc) +{ + int coeffs[4]; + + coeffs[0] = modulo_three_table[code][0]; + coeffs[1] = modulo_three_table[code][1]; + coeffs[2] = modulo_three_table[code][2]; + coeffs[3] = modulo_three_table[code][3]; + decode_coeff(dst , coeffs[0], 3, gb, vlc); + if(is_block2){ + decode_coeff(dst+8, coeffs[1], 2, gb, vlc); + decode_coeff(dst+1, coeffs[2], 2, gb, vlc); + }else{ + decode_coeff(dst+1, coeffs[1], 2, gb, vlc); + decode_coeff(dst+8, coeffs[2], 2, gb, vlc); + } + decode_coeff(dst+9, coeffs[3], 2, gb, vlc); +} + +/** + * Decode coefficients for 4x4 block. + * + * This is done by filling 2x2 subblocks with decoded coefficients + * in this order (the same for subblocks and subblock coefficients): + * o--o + * / + * / + * o--o + */ + +static inline void rv34_decode_block(DCTELEM *dst, GetBitContext *gb, RV34VLC *rvlc, int fc, int sc) +{ + int code, pattern; + + code = get_vlc2(gb, rvlc->first_pattern[fc].table, 9, 2); + + pattern = code & 0x7; + + code >>= 3; + decode_subblock(dst, code, 0, gb, &rvlc->coefficient); + + if(pattern & 4){ + code = get_vlc2(gb, rvlc->second_pattern[sc].table, 9, 2); + decode_subblock(dst + 2, code, 0, gb, &rvlc->coefficient); + } + if(pattern & 2){ // Looks like coefficients 1 and 2 are swapped for this block + code = get_vlc2(gb, rvlc->second_pattern[sc].table, 9, 2); + decode_subblock(dst + 8*2, code, 1, gb, &rvlc->coefficient); + } + if(pattern & 1){ + code = get_vlc2(gb, rvlc->third_pattern[sc].table, 9, 2); + decode_subblock(dst + 8*2+2, code, 0, gb, &rvlc->coefficient); + } + +} + +/** + * Dequantize ordinary 4x4 block. + * @todo optimize + */ +static inline void rv34_dequant4x4(DCTELEM *block, int Qdc, int Q) +{ + int i, j; + + block[0] = (block[0] * Qdc + 8) >> 4; + for(i = 0; i < 4; i++) + for(j = !i; j < 4; j++) + block[j + i*8] = (block[j + i*8] * Q + 8) >> 4; +} + +/** + * Dequantize 4x4 block of DC values for 16x16 macroblock. + * @todo optimize + */ +static inline void rv34_dequant4x4_16x16(DCTELEM *block, int Qdc, int Q) +{ + int i; + + for(i = 0; i < 3; i++) + block[rv34_dezigzag[i]] = (block[rv34_dezigzag[i]] * Qdc + 8) >> 4; + for(; i < 16; i++) + block[rv34_dezigzag[i]] = (block[rv34_dezigzag[i]] * Q + 8) >> 4; +} +/** @} */ //block functions + + +/** + * @defgroup bitstream RV30/40 bitstream parsing + * @{ + */ + +/** + * Decode starting slice position. + * @todo Maybe replace with ff_h263_decode_mba() ? + */ +int ff_rv34_get_start_offset(GetBitContext *gb, int mb_size) +{ + int i; + for(i = 0; i < 5; i++) + if(rv34_mb_max_sizes[i] > mb_size) + break; + return rv34_mb_bits_sizes[i]; +} + +/** + * Select VLC set for decoding from current quantizer, modifier and frame type. + */ +static inline RV34VLC* choose_vlc_set(int quant, int mod, int type) +{ + if(mod == 2 && quant < 19) quant += 10; + else if(mod && quant < 26) quant += 5; + return type ? &inter_vlcs[rv34_quant_to_vlc_set[1][av_clip(quant, 0, 30)]] + : &intra_vlcs[rv34_quant_to_vlc_set[0][av_clip(quant, 0, 30)]]; +} + +/** + * Decode quantizer difference and return modified quantizer. + */ +static inline int rv34_decode_dquant(GetBitContext *gb, int quant) +{ + if(get_bits1(gb)) + return rv34_dquant_tab[get_bits1(gb)][quant]; + else + return get_bits(gb, 5); +} + +/** @} */ //bitstream functions + +/** + * @defgroup mv motion vector related code (prediction, reconstruction, motion compensation) + * @{ + */ + +/** macroblock partition width in 8x8 blocks */ +static const uint8_t part_sizes_w[RV34_MB_TYPES] = { 2, 2, 2, 1, 2, 2, 2, 2, 2, 1, 2, 2 }; + +/** macroblock partition height in 8x8 blocks */ +static const uint8_t part_sizes_h[RV34_MB_TYPES] = { 2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 2, 2 }; + +/** availability index for subblocks */ +static const uint8_t avail_indexes[4] = { 5, 6, 9, 10 }; + +/** + * motion vector prediction + * + * Motion prediction performed for the block by using median prediction of + * motion vectors from the left, top and right top blocks but in corner cases + * some other vectors may be used instead. + */ +static void rv34_pred_mv(RV34DecContext *r, int block_type, int subblock_no, int dmv_no) +{ + MpegEncContext *s = &r->s; + int mv_pos = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride; + int A[2] = {0}, B[2], C[2]; + int i, j; + int mx, my; + int avail_index = avail_indexes[subblock_no]; + int c_off = part_sizes_w[block_type]; + + mv_pos += (subblock_no & 1) + (subblock_no >> 1)*s->b8_stride; + if(subblock_no == 3) + c_off = -1; + + if(r->avail_cache[avail_index - 1]){ + A[0] = s->current_picture_ptr->motion_val[0][mv_pos-1][0]; + A[1] = s->current_picture_ptr->motion_val[0][mv_pos-1][1]; + } + if(r->avail_cache[avail_index - 4]){ + B[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride][0]; + B[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride][1]; + }else{ + B[0] = A[0]; + B[1] = A[1]; + } + if(!r->avail_cache[avail_index - 4 + c_off]){ + if(r->avail_cache[avail_index - 4] && (r->avail_cache[avail_index - 1] || r->rv30)){ + C[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride-1][0]; + C[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride-1][1]; + }else{ + C[0] = A[0]; + C[1] = A[1]; + } + }else{ + C[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride+c_off][0]; + C[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride+c_off][1]; + } + mx = mid_pred(A[0], B[0], C[0]); + my = mid_pred(A[1], B[1], C[1]); + mx += r->dmv[dmv_no][0]; + my += r->dmv[dmv_no][1]; + for(j = 0; j < part_sizes_h[block_type]; j++){ + for(i = 0; i < part_sizes_w[block_type]; i++){ + s->current_picture_ptr->motion_val[0][mv_pos + i + j*s->b8_stride][0] = mx; + s->current_picture_ptr->motion_val[0][mv_pos + i + j*s->b8_stride][1] = my; + } + } +} + +/** + * Calculate motion vector component that should be added for direct blocks. + */ +static int calc_add_mv(MpegEncContext *s, int dir, int component) +{ + int mv_pos = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride; + int sum; + + sum = (s->next_picture_ptr->motion_val[0][mv_pos][component] + + s->next_picture_ptr->motion_val[0][mv_pos + 1][component] + + s->next_picture_ptr->motion_val[0][mv_pos + s->b8_stride][component] + + s->next_picture_ptr->motion_val[0][mv_pos + s->b8_stride + 1][component]) >> 2; + return dir ? -(sum >> 1) : ((sum + 1) >> 1); +} + +/** + * Predict motion vector for B-frame macroblock. + */ +static inline void rv34_pred_b_vector(int A[2], int B[2], int C[2], + int A_avail, int B_avail, int C_avail, + int *mx, int *my) +{ + if(A_avail + B_avail + C_avail != 3){ + *mx = A[0] + B[0] + C[0]; + *my = A[1] + B[1] + C[1]; + if(A_avail + B_avail + C_avail == 2){ + *mx /= 2; + *my /= 2; + } + }else{ + *mx = mid_pred(A[0], B[0], C[0]); + *my = mid_pred(A[1], B[1], C[1]); + } +} + +/** + * motion vector prediction for B-frames + */ +static void rv34_pred_mv_b(RV34DecContext *r, int block_type, int dir) +{ + MpegEncContext *s = &r->s; + int mb_pos = s->mb_x + s->mb_y * s->mb_stride; + int mv_pos = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride; + int A[2], B[2], C[2]; + int has_A = 0, has_B = 0, has_C = 0; + int mx, my; + int i, j; + Picture *cur_pic = s->current_picture_ptr; + const int mask = dir ? MB_TYPE_L1 : MB_TYPE_L0; + int type = cur_pic->mb_type[mb_pos]; + + memset(A, 0, sizeof(A)); + memset(B, 0, sizeof(B)); + memset(C, 0, sizeof(C)); + if((r->avail_cache[5-1] & type) & mask){ + A[0] = cur_pic->motion_val[dir][mv_pos - 1][0]; + A[1] = cur_pic->motion_val[dir][mv_pos - 1][1]; + has_A = 1; + } + if((r->avail_cache[5-4] & type) & mask){ + B[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride][0]; + B[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride][1]; + has_B = 1; + } + if((r->avail_cache[5-2] & type) & mask){ + C[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride + 2][0]; + C[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride + 2][1]; + has_C = 1; + }else if((s->mb_x+1) == s->mb_width && (r->avail_cache[5-5] & type) & mask){ + C[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride - 1][0]; + C[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride - 1][1]; + has_C = 1; + } + + rv34_pred_b_vector(A, B, C, has_A, has_B, has_C, &mx, &my); + + mx += r->dmv[dir][0]; + my += r->dmv[dir][1]; + + if(block_type == RV34_MB_B_DIRECT){ + mx += calc_add_mv(s, dir, 0); + my += calc_add_mv(s, dir, 1); + } + for(j = 0; j < 2; j++){ + for(i = 0; i < 2; i++){ + cur_pic->motion_val[dir][mv_pos + i + j*s->b8_stride][0] = mx; + cur_pic->motion_val[dir][mv_pos + i + j*s->b8_stride][1] = my; + } + } + if(block_type == RV34_MB_B_BACKWARD || block_type == RV34_MB_B_FORWARD) + fill_rectangle(cur_pic->motion_val[!dir][mv_pos], 2, 2, s->b8_stride, 0, 4); +} + +static const int chroma_coeffs[3] = { 8, 5, 3 }; + +/** + * generic motion compensation function + * + * @param r decoder context + * @param block_type type of the current block + * @param xoff horizontal offset from the start of the current block + * @param yoff vertical offset from the start of the current block + * @param mv_off offset to the motion vector information + * @param width width of the current partition in 8x8 blocks + * @param height height of the current partition in 8x8 blocks + */ +static inline void rv34_mc(RV34DecContext *r, const int block_type, + const int xoff, const int yoff, int mv_off, + const int width, const int height, int dir, + const int thirdpel, + qpel_mc_func (*qpel_mc)[16], + h264_chroma_mc_func (*chroma_mc)) +{ + MpegEncContext *s = &r->s; + uint8_t *Y, *U, *V, *srcY, *srcU, *srcV; + int dxy, mx, my, lx, ly, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y; + int mv_pos = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride + mv_off; + int is16x16 = 1; + + if(thirdpel){ + mx = (s->current_picture_ptr->motion_val[dir][mv_pos][0] + (3 << 24)) / 3 - (1 << 24); + my = (s->current_picture_ptr->motion_val[dir][mv_pos][1] + (3 << 24)) / 3 - (1 << 24); + lx = (s->current_picture_ptr->motion_val[dir][mv_pos][0] + (3 << 24)) % 3; + ly = (s->current_picture_ptr->motion_val[dir][mv_pos][1] + (3 << 24)) % 3; + uvmx = chroma_coeffs[(3*(mx&1) + lx) >> 1]; + uvmy = chroma_coeffs[(3*(my&1) + ly) >> 1]; + }else{ + mx = s->current_picture_ptr->motion_val[dir][mv_pos][0] >> 2; + my = s->current_picture_ptr->motion_val[dir][mv_pos][1] >> 2; + lx = s->current_picture_ptr->motion_val[dir][mv_pos][0] & 3; + ly = s->current_picture_ptr->motion_val[dir][mv_pos][1] & 3; + uvmx = mx & 6; + uvmy = my & 6; + } + dxy = ly*4 + lx; + srcY = dir ? s->next_picture_ptr->data[0] : s->last_picture_ptr->data[0]; + srcU = dir ? s->next_picture_ptr->data[1] : s->last_picture_ptr->data[1]; + srcV = dir ? s->next_picture_ptr->data[2] : s->last_picture_ptr->data[2]; + src_x = s->mb_x * 16 + xoff + mx; + src_y = s->mb_y * 16 + yoff + my; + uvsrc_x = s->mb_x * 8 + (xoff >> 1) + (mx >> 1); + uvsrc_y = s->mb_y * 8 + (yoff >> 1) + (my >> 1); + srcY += src_y * s->linesize + src_x; + srcU += uvsrc_y * s->uvlinesize + uvsrc_x; + srcV += uvsrc_y * s->uvlinesize + uvsrc_x; + if( (unsigned)(src_x - !!lx*2) > s->h_edge_pos - !!lx*2 - (width <<3) - 3 + || (unsigned)(src_y - !!ly*2) > s->v_edge_pos - !!ly*2 - (height<<3) - 3){ + uint8_t *uvbuf= s->edge_emu_buffer + 20 * s->linesize; + + srcY -= 2 + 2*s->linesize; + ff_emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, (width<<3)+4, (height<<3)+4, + src_x - 2, src_y - 2, s->h_edge_pos, s->v_edge_pos); + srcY = s->edge_emu_buffer + 2 + 2*s->linesize; + ff_emulated_edge_mc(uvbuf , srcU, s->uvlinesize, (width<<2)+1, (height<<2)+1, + uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1); + ff_emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, (width<<2)+1, (height<<2)+1, + uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1); + srcU = uvbuf; + srcV = uvbuf + 16; + } + Y = s->dest[0] + xoff + yoff *s->linesize; + U = s->dest[1] + (xoff>>1) + (yoff>>1)*s->uvlinesize; + V = s->dest[2] + (xoff>>1) + (yoff>>1)*s->uvlinesize; + + if(block_type == RV34_MB_P_16x8){ + qpel_mc[1][dxy](Y, srcY, s->linesize); + Y += 8; + srcY += 8; + }else if(block_type == RV34_MB_P_8x16){ + qpel_mc[1][dxy](Y, srcY, s->linesize); + Y += 8 * s->linesize; + srcY += 8 * s->linesize; + } + is16x16 = (block_type != RV34_MB_P_8x8) && (block_type != RV34_MB_P_16x8) && (block_type != RV34_MB_P_8x16); + qpel_mc[!is16x16][dxy](Y, srcY, s->linesize); + chroma_mc[2-width] (U, srcU, s->uvlinesize, height*4, uvmx, uvmy); + chroma_mc[2-width] (V, srcV, s->uvlinesize, height*4, uvmx, uvmy); +} + +static void rv34_mc_1mv(RV34DecContext *r, const int block_type, + const int xoff, const int yoff, int mv_off, + const int width, const int height, int dir) +{ + rv34_mc(r, block_type, xoff, yoff, mv_off, width, height, dir, r->rv30, + r->rv30 ? r->s.dsp.put_rv30_tpel_pixels_tab + : r->s.dsp.put_h264_qpel_pixels_tab, + r->s.dsp.put_h264_chroma_pixels_tab); +} + +static void rv34_mc_2mv(RV34DecContext *r, const int block_type) +{ + rv34_mc(r, block_type, 0, 0, 0, 2, 2, 0, r->rv30, + r->rv30 ? r->s.dsp.put_rv30_tpel_pixels_tab + : r->s.dsp.put_h264_qpel_pixels_tab, + r->s.dsp.put_h264_chroma_pixels_tab); + rv34_mc(r, block_type, 0, 0, 0, 2, 2, 1, r->rv30, + r->rv30 ? r->s.dsp.avg_rv30_tpel_pixels_tab + : r->s.dsp.avg_h264_qpel_pixels_tab, + r->s.dsp.avg_h264_chroma_pixels_tab); +} + +/** number of motion vectors in each macroblock type */ +static const int num_mvs[RV34_MB_TYPES] = { 0, 0, 1, 4, 1, 1, 0, 0, 2, 2, 2, 1 }; + +/** + * Decode motion vector differences + * and perform motion vector reconstruction and motion compensation. + */ +static int rv34_decode_mv(RV34DecContext *r, int block_type) +{ + MpegEncContext *s = &r->s; + GetBitContext *gb = &s->gb; + int i; + + memset(r->dmv, 0, sizeof(r->dmv)); + for(i = 0; i < num_mvs[block_type]; i++){ + r->dmv[i][0] = svq3_get_se_golomb(gb); + r->dmv[i][1] = svq3_get_se_golomb(gb); + } + switch(block_type){ + case RV34_MB_TYPE_INTRA: + case RV34_MB_TYPE_INTRA16x16: + fill_rectangle(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], 2, 2, s->b8_stride, 0, 4); + return 0; + case RV34_MB_SKIP: + if(s->pict_type == P_TYPE){ + fill_rectangle(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], 2, 2, s->b8_stride, 0, 4); + rv34_mc_1mv (r, block_type, 0, 0, 0, 2, 2, 0); + break; + } + case RV34_MB_B_DIRECT: + rv34_pred_mv_b (r, RV34_MB_B_DIRECT, 0); + rv34_pred_mv_b (r, RV34_MB_B_DIRECT, 1); + rv34_mc_2mv (r, RV34_MB_B_DIRECT); + break; + case RV34_MB_P_16x16: + case RV34_MB_P_MIX16x16: + rv34_pred_mv(r, block_type, 0, 0); + rv34_mc_1mv (r, block_type, 0, 0, 0, 2, 2, 0); + break; + case RV34_MB_B_FORWARD: + case RV34_MB_B_BACKWARD: + r->dmv[1][0] = r->dmv[0][0]; + r->dmv[1][1] = r->dmv[0][1]; + rv34_pred_mv_b (r, block_type, block_type == RV34_MB_B_BACKWARD); + rv34_mc_1mv (r, block_type, 0, 0, 0, 2, 2, block_type == RV34_MB_B_BACKWARD); + break; + case RV34_MB_P_16x8: + case RV34_MB_P_8x16: + rv34_pred_mv(r, block_type, 0, 0); + rv34_pred_mv(r, block_type, 1 + (block_type == RV34_MB_P_16x8), 1); + if(block_type == RV34_MB_P_16x8){ + rv34_mc_1mv(r, block_type, 0, 0, 0, 2, 1, 0); + rv34_mc_1mv(r, block_type, 0, 8, s->b8_stride, 2, 1, 0); + } + if(block_type == RV34_MB_P_8x16){ + rv34_mc_1mv(r, block_type, 0, 0, 0, 1, 2, 0); + rv34_mc_1mv(r, block_type, 8, 0, 1, 1, 2, 0); + } + break; + case RV34_MB_B_BIDIR: + rv34_pred_mv_b (r, block_type, 0); + rv34_pred_mv_b (r, block_type, 1); + rv34_mc_2mv (r, block_type); + break; + case RV34_MB_P_8x8: + for(i=0;i< 4;i++){ + rv34_pred_mv(r, block_type, i, i); + rv34_mc_1mv (r, block_type, (i&1)<<3, (i&2)<<2, (i&1)+(i>>1)*s->b8_stride, 1, 1, 0); + } + break; + } + + return 0; +} +/** @} */ // mv group + +/** + * @defgroup recons Macroblock reconstruction functions + * @{ + */ +/** mapping of RV30/40 intra prediction types to standard H.264 types */ +static const int ittrans[9] = { + DC_PRED, VERT_PRED, HOR_PRED, DIAG_DOWN_RIGHT_PRED, DIAG_DOWN_LEFT_PRED, + VERT_RIGHT_PRED, VERT_LEFT_PRED, HOR_UP_PRED, HOR_DOWN_PRED, +}; + +/** mapping of RV30/40 intra 16x16 prediction types to standard H.264 types */ +static const int ittrans16[4] = { + DC_PRED8x8, VERT_PRED8x8, HOR_PRED8x8, PLANE_PRED8x8, +}; + +/** + * Perform 4x4 intra prediction. + */ +static void rv34_pred_4x4_block(RV34DecContext *r, uint8_t *dst, int stride, int itype, int up, int left, int down, int right) +{ + uint8_t *prev = dst - stride + 4; + uint32_t topleft; + + if(!up && !left) + itype = DC_128_PRED; + else if(!up){ + if(itype == VERT_PRED) itype = HOR_PRED; + if(itype == DC_PRED) itype = LEFT_DC_PRED; + }else if(!left){ + if(itype == HOR_PRED) itype = VERT_PRED; + if(itype == DC_PRED) itype = TOP_DC_PRED; + if(itype == DIAG_DOWN_LEFT_PRED) itype = DIAG_DOWN_LEFT_PRED_RV40_NODOWN; + } + if(!down){ + if(itype == DIAG_DOWN_LEFT_PRED) itype = DIAG_DOWN_LEFT_PRED_RV40_NODOWN; + if(itype == HOR_UP_PRED) itype = HOR_UP_PRED_RV40_NODOWN; + if(itype == VERT_LEFT_PRED) itype = VERT_LEFT_PRED_RV40_NODOWN; + } + if(!right && up){ + topleft = dst[-stride + 3] * 0x01010101; + prev = &topleft; + } + r->h.pred4x4[itype](dst, prev, stride); +} + +/** add_pixels_clamped for 4x4 block */ +static void rv34_add_4x4_block(uint8_t *dst, int stride, DCTELEM block[64], int off) +{ + int x, y; + for(y = 0; y < 4; y++) + for(x = 0; x < 4; x++) + dst[x + y*stride] = av_clip_uint8(dst[x + y*stride] + block[off + x+y*8]); +} + +static inline int adjust_pred16(int itype, int up, int left) +{ + if(!up && !left) + itype = DC_128_PRED8x8; + else if(!up){ + if(itype == PLANE_PRED8x8)itype = HOR_PRED8x8; + if(itype == VERT_PRED8x8) itype = HOR_PRED8x8; + if(itype == DC_PRED8x8) itype = LEFT_DC_PRED8x8; + }else if(!left){ + if(itype == PLANE_PRED8x8)itype = VERT_PRED8x8; + if(itype == HOR_PRED8x8) itype = VERT_PRED8x8; + if(itype == DC_PRED8x8) itype = TOP_DC_PRED8x8; + } + return itype; +} + +static void rv34_output_macroblock(RV34DecContext *r, int8_t *intra_types, int cbp, int is16) +{ + MpegEncContext *s = &r->s; + DSPContext *dsp = &s->dsp; + int i, j; + uint8_t *Y, *U, *V; + int itype; + int avail[6*8] = {0}; + int idx; + + // Set neighbour information. + if(r->avail_cache[0]) + avail[0] = 1; + if(r->avail_cache[1]) + avail[1] = avail[2] = 1; + if(r->avail_cache[2]) + avail[3] = avail[4] = 1; + if(r->avail_cache[3]) + avail[5] = 1; + if(r->avail_cache[4]) + avail[8] = avail[16] = 1; + if(r->avail_cache[8]) + avail[24] = avail[32] = 1; + + Y = s->dest[0]; + U = s->dest[1]; + V = s->dest[2]; + if(!is16){ + for(j = 0; j < 4; j++){ + idx = 9 + j*8; + for(i = 0; i < 4; i++, cbp >>= 1, Y += 4, idx++){ + rv34_pred_4x4_block(r, Y, s->linesize, ittrans[intra_types[i]], avail[idx-8], avail[idx-1], avail[idx+7], avail[idx-7]); + avail[idx] = 1; + if(cbp & 1) + rv34_add_4x4_block(Y, s->linesize, s->block[(i>>1)+(j&2)], (i&1)*4+(j&1)*32); + } + Y += s->linesize * 4 - 4*4; + intra_types += s->b4_stride; + } + intra_types -= s->b4_stride * 4; + fill_rectangle(r->avail_cache + 5, 2, 2, 4, 0, 4); + for(j = 0; j < 2; j++){ + idx = 5 + j*4; + for(i = 0; i < 2; i++, cbp >>= 1, idx++){ + rv34_pred_4x4_block(r, U + i*4 + j*4*s->uvlinesize, s->uvlinesize, ittrans[intra_types[i*2+j*2*s->b4_stride]], r->avail_cache[idx-4], r->avail_cache[idx-1], !i && !j, r->avail_cache[idx-3]); + rv34_pred_4x4_block(r, V + i*4 + j*4*s->uvlinesize, s->uvlinesize, ittrans[intra_types[i*2+j*2*s->b4_stride]], r->avail_cache[idx-4], r->avail_cache[idx-1], !i && !j, r->avail_cache[idx-3]); + r->avail_cache[idx] = 1; + if(cbp & 0x01) + rv34_add_4x4_block(U + i*4 + j*4*s->uvlinesize, s->uvlinesize, s->block[4], i*4+j*32); + if(cbp & 0x10) + rv34_add_4x4_block(V + i*4 + j*4*s->uvlinesize, s->uvlinesize, s->block[5], i*4+j*32); + } + } + }else{ + itype = ittrans16[intra_types[0]]; + itype = adjust_pred16(itype, r->avail_cache[5-4], r->avail_cache[5-1]); + r->h.pred16x16[itype](Y, s->linesize); + dsp->add_pixels_clamped(s->block[0], Y, s->current_picture.linesize[0]); + dsp->add_pixels_clamped(s->block[1], Y + 8, s->current_picture.linesize[0]); + Y += s->current_picture.linesize[0] * 8; + dsp->add_pixels_clamped(s->block[2], Y, s->current_picture.linesize[0]); + dsp->add_pixels_clamped(s->block[3], Y + 8, s->current_picture.linesize[0]); + + itype = ittrans16[intra_types[0]]; + if(itype == PLANE_PRED8x8) itype = DC_PRED8x8; + itype = adjust_pred16(itype, r->avail_cache[5-4], r->avail_cache[5-1]); + r->h.pred8x8[itype](U, s->uvlinesize); + dsp->add_pixels_clamped(s->block[4], U, s->uvlinesize); + r->h.pred8x8[itype](V, s->uvlinesize); + dsp->add_pixels_clamped(s->block[5], V, s->uvlinesize); + } +} + +/** @} */ // recons group + +/** + * @addtogroup bitstream + * Decode macroblock header and return CBP in case of success, -1 otherwise. + */ +static int rv34_decode_mb_header(RV34DecContext *r, int8_t *intra_types) +{ + MpegEncContext *s = &r->s; + GetBitContext *gb = &s->gb; + int mb_pos = s->mb_x + s->mb_y * s->mb_stride; + int i, t; + + if(!r->si.type){ + r->is16 = get_bits1(gb); + if(!r->is16 && !r->rv30){ + if(!get_bits1(gb)) + av_log(s->avctx, AV_LOG_ERROR, "Need DQUANT\n"); + } + s->current_picture_ptr->mb_type[mb_pos] = r->is16 ? MB_TYPE_INTRA16x16 : MB_TYPE_INTRA; + r->block_type = r->is16 ? RV34_MB_TYPE_INTRA16x16 : RV34_MB_TYPE_INTRA; + }else{ + r->block_type = r->decode_mb_info(r); + if(r->block_type == -1) + return -1; + s->current_picture_ptr->mb_type[mb_pos] = rv34_mb_type_to_lavc[r->block_type]; + r->mb_type[mb_pos] = r->block_type; + if(r->block_type == RV34_MB_SKIP){ + if(s->pict_type == P_TYPE) + r->mb_type[mb_pos] = RV34_MB_P_16x16; + if(s->pict_type == B_TYPE) + r->mb_type[mb_pos] = RV34_MB_B_DIRECT; + } + r->is16 = !!IS_INTRA16x16(s->current_picture_ptr->mb_type[mb_pos]); + rv34_decode_mv(r, r->block_type); + if(r->block_type == RV34_MB_SKIP){ + fill_rectangle(intra_types, 4, 4, s->b4_stride, 0, sizeof(intra_types[0])); + return 0; + } + r->chroma_vlc = 1; + r->luma_vlc = 0; + } + if(IS_INTRA(s->current_picture_ptr->mb_type[mb_pos])){ + if(r->is16){ + t = get_bits(gb, 2); + fill_rectangle(intra_types, 4, 4, s->b4_stride, t, sizeof(intra_types[0])); + r->luma_vlc = 2; + }else{ + if(r->decode_intra_types(r, gb, intra_types) < 0) + return -1; + r->luma_vlc = 1; + } + r->chroma_vlc = 0; + r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 0); + }else{ + for(i = 0; i < 16; i++) + intra_types[(i & 3) + (i>>2) * s->b4_stride] = 0; + r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 1); + if(r->mb_type[mb_pos] == RV34_MB_P_MIX16x16){ + r->is16 = 1; + r->chroma_vlc = 1; + r->luma_vlc = 2; + r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 0); + } + } + + return rv34_decode_cbp(gb, r->cur_vlcs, r->is16); +} + +/** + * @addtogroup recons + * @{ + */ +/** + * mask for retrieving all bits in coded block pattern + * corresponding to one 8x8 block + */ +#define LUMA_CBP_BLOCK_MASK 0x303 + +#define U_CBP_MASK 0x0F0000 +#define V_CBP_MASK 0xF00000 + + +static void rv34_apply_differences(RV34DecContext *r, int cbp) +{ + static const int shifts[4] = { 0, 2, 8, 10 }; + MpegEncContext *s = &r->s; + int i; + + for(i = 0; i < 4; i++) + if(cbp & (LUMA_CBP_BLOCK_MASK << shifts[i])) + s->dsp.add_pixels_clamped(s->block[i], s->dest[0] + (i & 1)*8 + (i&2)*4*s->linesize, s->linesize); + if(cbp & U_CBP_MASK) + s->dsp.add_pixels_clamped(s->block[4], s->dest[1], s->uvlinesize); + if(cbp & V_CBP_MASK) + s->dsp.add_pixels_clamped(s->block[5], s->dest[2], s->uvlinesize); +} + +static int rv34_decode_macroblock(RV34DecContext *r, int8_t *intra_types) +{ + MpegEncContext *s = &r->s; + GetBitContext *gb = &s->gb; + int cbp, cbp2; + int i, blknum, blkoff; + DCTELEM block16[64]; + int luma_dc_quant; + int dist; + int mb_pos = s->mb_x + s->mb_y * s->mb_stride; + + // Calculate which neighbours are available. Maybe it's worth optimizing too. + memset(r->avail_cache, 0, sizeof(r->avail_cache)); + fill_rectangle(r->avail_cache + 5, 2, 2, 4, 1, 4); + dist = (s->mb_x - s->resync_mb_x) + (s->mb_y - s->resync_mb_y) * s->mb_width; + if(s->mb_x && dist) + r->avail_cache[4] = + r->avail_cache[8] = s->current_picture_ptr->mb_type[mb_pos - 1]; + if(dist >= s->mb_width) + r->avail_cache[1] = + r->avail_cache[2] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride]; + if(((s->mb_x+1) < s->mb_width) && dist >= s->mb_width - 1) + r->avail_cache[3] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride + 1]; + if(s->mb_x && dist > s->mb_width) + r->avail_cache[0] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride - 1]; + + s->qscale = r->si.quant; + cbp = cbp2 = rv34_decode_mb_header(r, intra_types); + r->cbp_luma [s->mb_x + s->mb_y * s->mb_stride] = cbp; + r->cbp_chroma[s->mb_x + s->mb_y * s->mb_stride] = cbp >> 16; + s->current_picture.qscale_table[s->mb_x + s->mb_y * s->mb_stride] = s->qscale; + + if(cbp == -1) + return -1; + + luma_dc_quant = r->si.type ? r->luma_dc_quant_p[s->qscale] : r->luma_dc_quant_i[s->qscale]; + if(r->is16){ + memset(block16, 0, sizeof(block16)); + rv34_decode_block(block16, gb, r->cur_vlcs, 3, 0); + rv34_dequant4x4_16x16(block16, rv34_qscale_tab[luma_dc_quant],rv34_qscale_tab[s->qscale]); + rv34_inv_transform_noround(block16); + } + + for(i = 0; i < 16; i++, cbp >>= 1){ + if(!r->is16 && !(cbp & 1)) continue; + blknum = ((i & 2) >> 1) + ((i & 8) >> 2); + blkoff = ((i & 1) << 2) + ((i & 4) << 3); + if(cbp & 1) + rv34_decode_block(s->block[blknum] + blkoff, gb, r->cur_vlcs, r->luma_vlc, 0); + rv34_dequant4x4(s->block[blknum] + blkoff, rv34_qscale_tab[luma_dc_quant],rv34_qscale_tab[s->qscale]); + if(r->is16) //FIXME: optimize + s->block[blknum][blkoff] = block16[(i & 3) | ((i & 0xC) << 1)]; + rv34_inv_transform(s->block[blknum] + blkoff); + } + if(r->block_type == RV34_MB_P_MIX16x16) + r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 1); + for(; i < 24; i++, cbp >>= 1){ + if(!(cbp & 1)) continue; + blknum = ((i & 4) >> 2) + 4; + blkoff = ((i & 1) << 2) + ((i & 2) << 4); + rv34_decode_block(s->block[blknum] + blkoff, gb, r->cur_vlcs, r->chroma_vlc, 1); + rv34_dequant4x4(s->block[blknum] + blkoff, rv34_qscale_tab[rv34_chroma_quant[1][s->qscale]],rv34_qscale_tab[rv34_chroma_quant[0][s->qscale]]); + rv34_inv_transform(s->block[blknum] + blkoff); + } + if(IS_INTRA(s->current_picture_ptr->mb_type[s->mb_x + s->mb_y*s->mb_stride])) + rv34_output_macroblock(r, intra_types, cbp2, r->is16); + else + rv34_apply_differences(r, cbp2); + + return 0; +} + +static int check_slice_end(RV34DecContext *r, MpegEncContext *s) +{ + int bits; + if(s->mb_y >= s->mb_height) + return 1; + if(!s->mb_num_left) + return 1; + if(r->s.mb_skip_run > 1) + return 0; + bits = r->bits - get_bits_count(&s->gb); + if(bits < 0 || (bits < 8 && !show_bits(&s->gb, bits))) + return 1; + return 0; +} + +static inline int slice_compare(SliceInfo *si1, SliceInfo *si2) +{ + return si1->type != si2->type || + si1->start >= si2->start || + si1->width != si2->width || + si1->height != si2->height; +} + +static int rv34_decode_slice(RV34DecContext *r, int end, uint8_t* buf, int buf_size) +{ + MpegEncContext *s = &r->s; + GetBitContext *gb = &s->gb; + int mb_pos; + int res; + + init_get_bits(&r->s.gb, buf, buf_size*8); + res = r->parse_slice_header(r, gb, &r->si); + if(res < 0){ + av_log(s->avctx, AV_LOG_ERROR, "Incorrect or unknown slice header\n"); + return -1; + } + + if ((s->mb_x == 0 && s->mb_y == 0) || s->current_picture_ptr==NULL) { + if(s->width != r->si.width || s->height != r->si.height){ + av_log(s->avctx, AV_LOG_DEBUG, "Changing dimensions to %dx%d\n", r->si.width,r->si.height); + MPV_common_end(s); + s->width = r->si.width; + s->height = r->si.height; + if(MPV_common_init(s) < 0) + return -1; + r->intra_types_hist = av_realloc(r->intra_types_hist, s->b4_stride * 4 * 2 * sizeof(*r->intra_types_hist)); + r->intra_types = r->intra_types_hist + s->b4_stride * 4; + r->mb_type = av_realloc(r->mb_type, r->s.mb_stride * r->s.mb_height * sizeof(*r->mb_type)); + r->cbp_luma = av_realloc(r->cbp_luma, r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_luma)); + r->cbp_chroma = av_realloc(r->cbp_chroma, r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_chroma)); + } + s->pict_type = r->si.type ? r->si.type : I_TYPE; + if(MPV_frame_start(s, s->avctx) < 0) + return -1; + ff_er_frame_start(s); + s->current_picture_ptr = &s->current_picture; + s->mb_x = s->mb_y = 0; + } + + r->si.end = end; + s->qscale = r->si.quant; + r->bits = buf_size*8; + s->mb_num_left = r->si.end - r->si.start; + r->s.mb_skip_run = 0; + + mb_pos = s->mb_x + s->mb_y * s->mb_width; + if(r->si.start != mb_pos){ + av_log(s->avctx, AV_LOG_ERROR, "Slice indicates MB offset %d, got %d\n", r->si.start, mb_pos); + s->mb_x = r->si.start % s->mb_width; + s->mb_y = r->si.start / s->mb_width; + } + memset(r->intra_types_hist, -1, s->b4_stride * 4 * 2 * sizeof(*r->intra_types_hist)); + s->first_slice_line = 1; + s->resync_mb_x= s->mb_x; + s->resync_mb_y= s->mb_y; + + ff_init_block_index(s); + while(!check_slice_end(r, s)) { + ff_update_block_index(s); + s->dsp.clear_blocks(s->block[0]); + + if(rv34_decode_macroblock(r, r->intra_types + s->mb_x * 4 + 1) < 0){ + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_ERROR|DC_ERROR|MV_ERROR); + return -1; + } + if (++s->mb_x == s->mb_width) { + s->mb_x = 0; + s->mb_y++; + ff_init_block_index(s); + + memmove(r->intra_types_hist, r->intra_types, s->b4_stride * 4 * sizeof(*r->intra_types_hist)); + memset(r->intra_types, -1, s->b4_stride * 4 * sizeof(*r->intra_types_hist)); + } + if(s->mb_x == s->resync_mb_x) + s->first_slice_line=0; + s->mb_num_left--; + } + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END|DC_END|MV_END); + + return (s->mb_y == s->mb_height); +} + +/** @} */ // recons group end + +/** + * Initialize decoder. + */ +int ff_rv34_decode_init(AVCodecContext *avctx) +{ + RV34DecContext *r = avctx->priv_data; + MpegEncContext *s = &r->s; + + MPV_decode_defaults(s); + s->avctx= avctx; + s->out_format = FMT_H263; + s->codec_id= avctx->codec_id; + + s->width = avctx->width; + s->height = avctx->height; + + r->s.avctx = avctx; + avctx->flags |= CODEC_FLAG_EMU_EDGE; + r->s.flags |= CODEC_FLAG_EMU_EDGE; + avctx->pix_fmt = PIX_FMT_YUV420P; + avctx->has_b_frames = 1; + s->low_delay = 0; + + if (MPV_common_init(s) < 0) + return -1; + + ff_h264_pred_init(&r->h, CODEC_ID_RV40); + + r->intra_types_hist = av_malloc(s->b4_stride * 4 * 2 * sizeof(*r->intra_types_hist)); + r->intra_types = r->intra_types_hist + s->b4_stride * 4; + + r->mb_type = av_mallocz(r->s.mb_stride * r->s.mb_height * sizeof(*r->mb_type)); + + r->cbp_luma = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_luma)); + r->cbp_chroma = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_chroma)); + + if(!intra_vlcs[0].cbppattern[0].bits) + rv34_init_tables(); + + return 0; +} + +static int get_slice_offset(AVCodecContext *avctx, uint8_t *buf, int n) +{ + if(avctx->slice_count) return avctx->slice_offset[n]; + else return AV_RL32(buf + n*8 - 4) == 1 ? AV_RL32(buf + n*8) : AV_RB32(buf + n*8); +} + +int ff_rv34_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + uint8_t *buf, int buf_size) +{ + RV34DecContext *r = avctx->priv_data; + MpegEncContext *s = &r->s; + AVFrame *pict = data; + SliceInfo si; + int i; + int slice_count; + uint8_t *slices_hdr = NULL; + int last = 0; + + /* no supplementary picture */ + if (buf_size == 0) { + /* special case for last picture */ + if (s->low_delay==0 && s->next_picture_ptr) { + *pict= *(AVFrame*)s->next_picture_ptr; + s->next_picture_ptr= NULL; + + *data_size = sizeof(AVFrame); + } + return 0; + } + + if(!avctx->slice_count){ + slice_count = (*buf++) + 1; + slices_hdr = buf + 4; + buf += 8 * slice_count; + }else + slice_count = avctx->slice_count; + + for(i=0; isi.end = s->mb_width * s->mb_height; + if(i+1 < slice_count){ + init_get_bits(&s->gb, buf+get_slice_offset(avctx, slices_hdr, i+1), (buf_size-get_slice_offset(avctx, slices_hdr, i+1))*8); + if(r->parse_slice_header(r, &r->s.gb, &si) < 0){ + if(i+2 < slice_count) + size = get_slice_offset(avctx, slices_hdr, i+2) - offset; + else + size = buf_size - offset; + }else + r->si.end = si.start; + } + last = rv34_decode_slice(r, r->si.end, buf + offset, size); + s->mb_num_left = r->s.mb_x + r->s.mb_y*r->s.mb_width - r->si.start; + if(last) + break; + } + + if(last){ + if(r->loop_filter) + r->loop_filter(r); + ff_er_frame_end(s); + MPV_frame_end(s); + if (s->pict_type == B_TYPE || s->low_delay) { + *pict= *(AVFrame*)s->current_picture_ptr; + } else if (s->last_picture_ptr != NULL) { + *pict= *(AVFrame*)s->last_picture_ptr; + } + + if(s->last_picture_ptr || s->low_delay){ + *data_size = sizeof(AVFrame); + ff_print_debug_info(s, pict); + } + s->current_picture_ptr= NULL; //so we can detect if frame_end wasnt called (find some nicer solution...) + } + return buf_size; +} + +int ff_rv34_decode_end(AVCodecContext *avctx) +{ + RV34DecContext *r = avctx->priv_data; + + MPV_common_end(&r->s); + + av_freep(&r->intra_types_hist); + r->intra_types = NULL; + av_freep(&r->mb_type); + + return 0; +} diff --git a/contrib/ffmpeg/libavcodec/rv34.h b/contrib/ffmpeg/libavcodec/rv34.h new file mode 100644 index 000000000..dff36f29e --- /dev/null +++ b/contrib/ffmpeg/libavcodec/rv34.h @@ -0,0 +1,122 @@ +/* + * RV30/40 decoder common data declarations + * Copyright (c) 2007 Mike Melanson, Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file rv34.h + * RV30 and RV40 decoder common data declarations + */ + +#ifndef FFMPEG_RV34_H +#define FFMPEG_RV34_H + +#include "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" + +#include "h264pred.h" + +/** + * RV30 and RV40 Macroblock types + */ +enum RV40BlockTypes{ + RV34_MB_TYPE_INTRA, ///< Intra macroblock + RV34_MB_TYPE_INTRA16x16, ///< Intra macroblock with DCs in a separate 4x4 block + RV34_MB_P_16x16, ///< P-frame macroblock, one motion frame + RV34_MB_P_8x8, ///< P-frame macroblock, 8x8 motion compensation partitions + RV34_MB_B_FORWARD, ///< B-frame macroblock, forward prediction + RV34_MB_B_BACKWARD, ///< B-frame macroblock, backward prediction + RV34_MB_SKIP, ///< Skipped block + RV34_MB_B_DIRECT, ///< Bidirectionally predicted B-frame macroblock, no motion vectors + RV34_MB_P_16x8, ///< P-frame macroblock, 16x8 motion compensation partitions + RV34_MB_P_8x16, ///< P-frame macroblock, 8x16 motion compensation partitions + RV34_MB_B_BIDIR, ///< Bidirectionally predicted B-frame macroblock, two motion vectors + RV34_MB_P_MIX16x16, ///< P-frame macroblock with DCs in a separate 4x4 block, one motion vector + RV34_MB_TYPES +}; + +/** + * VLC tables used by the decoder + * + * Intra frame VLC sets do not contain some of those tables. + */ +typedef struct RV34VLC{ + VLC cbppattern[2]; ///< VLCs used for pattern of coded block patterns decoding + VLC cbp[2][4]; ///< VLCs used for coded block patterns decoding + VLC first_pattern[4]; ///< VLCs used for decoding coefficients in the first subblock + VLC second_pattern[2]; ///< VLCs used for decoding coefficients in the subblocks 2 and 3 + VLC third_pattern[2]; ///< VLCs used for decoding coefficients in the last subblock + VLC coefficient; ///< VLCs used for decoding big coefficients +}RV34VLC; + +/** essential slice information */ +typedef struct SliceInfo{ + int type; ///< slice type (intra, inter) + int quant; ///< quantizer used for this slice + int vlc_set; ///< VLCs used for this slice + int start, end; ///< start and end macroblocks of the slice + int width; ///< coded width + int height; ///< coded height +}SliceInfo; + +/** decoder context */ +typedef struct RV34DecContext{ + MpegEncContext s; + int8_t *intra_types_hist;///< old block types, used for prediction + int8_t *intra_types; ///< block types + const uint8_t *luma_dc_quant_i;///< luma subblock DC quantizer for intraframes + const uint8_t *luma_dc_quant_p;///< luma subblock DC quantizer for interframes + + RV34VLC *cur_vlcs; ///< VLC set used for current frame decoding + int bits; ///< slice size in bits + H264PredContext h; ///< functions for 4x4 and 16x16 intra block prediction + SliceInfo si; ///< current slice information + + int *mb_type; ///< internal macroblock types + int block_type; ///< current block type + int luma_vlc; ///< which VLC set will be used for decoding of luma blocks + int chroma_vlc; ///< which VLC set will be used for decoding of chroma blocks + int is16; ///< current block has additional 16x16 specific features or not + int dmv[4][2]; ///< differential motion vectors for the current macroblock + + int rv30; ///< indicates which RV variasnt is currently decoded + int rpr; ///< one field size in RV30 slice header + + uint16_t *cbp_luma; ///< CBP values for luma subblocks + uint8_t *cbp_chroma; ///< CBP values for chroma subblocks + + /** 8x8 block available flags (for MV prediction) */ + DECLARE_ALIGNED_8(uint32_t, avail_cache[3*4]); + + int (*parse_slice_header)(struct RV34DecContext *r, GetBitContext *gb, SliceInfo *si); + int (*decode_mb_info)(struct RV34DecContext *r); + int (*decode_intra_types)(struct RV34DecContext *r, GetBitContext *gb, int8_t *dst); + void (*loop_filter)(struct RV34DecContext *r); +}RV34DecContext; + +/** + * common decoding functions + */ +int ff_rv34_get_start_offset(GetBitContext *gb, int blocks); +int ff_rv34_decode_init(AVCodecContext *avctx); +int ff_rv34_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size); +int ff_rv34_decode_end(AVCodecContext *avctx); + +#endif /* FFMPEG_RV34_H */ diff --git a/contrib/ffmpeg/libavcodec/rv34data.h b/contrib/ffmpeg/libavcodec/rv34data.h new file mode 100644 index 000000000..25256e23d --- /dev/null +++ b/contrib/ffmpeg/libavcodec/rv34data.h @@ -0,0 +1,148 @@ +/* + * RealVideo 4 decoder + * copyright (c) 2007 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file rv34data.h + * miscellaneous RV30/40 tables + */ + +#ifndef FFMPEG_RV34DATA_H +#define FFMPEG_RV34DATA_H + +#include + +/** + * number of ones in nibble minus one + */ +static const uint8_t rv34_count_ones[16] = { + 0, 0, 0, 1, 0, 1, 1, 2, 0, 1, 1, 2, 1, 2, 2, 3 +}; + +/** + * values used to reconstruct coded block pattern + */ +static const uint8_t rv34_cbp_code[16] = { + 0x00, 0x20, 0x10, 0x30, 0x02, 0x22, 0x12, 0x32, + 0x01, 0x21, 0x11, 0x31, 0x03, 0x23, 0x13, 0x33 +}; + +/** + * precalculated results of division by three and modulo three for values 0-107 + * + * A lot of four-tuples in RV40 are represented as c0*27+c1*9+c2*3+c3. + * This table allows conversion from a value back to a vector. + */ +static const uint8_t modulo_three_table[108][4] = { + { 0, 0, 0, 0 }, { 0, 0, 0, 1 }, { 0, 0, 0, 2 }, { 0, 0, 1, 0 }, + { 0, 0, 1, 1 }, { 0, 0, 1, 2 }, { 0, 0, 2, 0 }, { 0, 0, 2, 1 }, + { 0, 0, 2, 2 }, { 0, 1, 0, 0 }, { 0, 1, 0, 1 }, { 0, 1, 0, 2 }, + { 0, 1, 1, 0 }, { 0, 1, 1, 1 }, { 0, 1, 1, 2 }, { 0, 1, 2, 0 }, + { 0, 1, 2, 1 }, { 0, 1, 2, 2 }, { 0, 2, 0, 0 }, { 0, 2, 0, 1 }, + { 0, 2, 0, 2 }, { 0, 2, 1, 0 }, { 0, 2, 1, 1 }, { 0, 2, 1, 2 }, + { 0, 2, 2, 0 }, { 0, 2, 2, 1 }, { 0, 2, 2, 2 }, { 1, 0, 0, 0 }, + { 1, 0, 0, 1 }, { 1, 0, 0, 2 }, { 1, 0, 1, 0 }, { 1, 0, 1, 1 }, + { 1, 0, 1, 2 }, { 1, 0, 2, 0 }, { 1, 0, 2, 1 }, { 1, 0, 2, 2 }, + { 1, 1, 0, 0 }, { 1, 1, 0, 1 }, { 1, 1, 0, 2 }, { 1, 1, 1, 0 }, + { 1, 1, 1, 1 }, { 1, 1, 1, 2 }, { 1, 1, 2, 0 }, { 1, 1, 2, 1 }, + { 1, 1, 2, 2 }, { 1, 2, 0, 0 }, { 1, 2, 0, 1 }, { 1, 2, 0, 2 }, + { 1, 2, 1, 0 }, { 1, 2, 1, 1 }, { 1, 2, 1, 2 }, { 1, 2, 2, 0 }, + { 1, 2, 2, 1 }, { 1, 2, 2, 2 }, { 2, 0, 0, 0 }, { 2, 0, 0, 1 }, + { 2, 0, 0, 2 }, { 2, 0, 1, 0 }, { 2, 0, 1, 1 }, { 2, 0, 1, 2 }, + { 2, 0, 2, 0 }, { 2, 0, 2, 1 }, { 2, 0, 2, 2 }, { 2, 1, 0, 0 }, + { 2, 1, 0, 1 }, { 2, 1, 0, 2 }, { 2, 1, 1, 0 }, { 2, 1, 1, 1 }, + { 2, 1, 1, 2 }, { 2, 1, 2, 0 }, { 2, 1, 2, 1 }, { 2, 1, 2, 2 }, + { 2, 2, 0, 0 }, { 2, 2, 0, 1 }, { 2, 2, 0, 2 }, { 2, 2, 1, 0 }, + { 2, 2, 1, 1 }, { 2, 2, 1, 2 }, { 2, 2, 2, 0 }, { 2, 2, 2, 1 }, + { 2, 2, 2, 2 }, { 3, 0, 0, 0 }, { 3, 0, 0, 1 }, { 3, 0, 0, 2 }, + { 3, 0, 1, 0 }, { 3, 0, 1, 1 }, { 3, 0, 1, 2 }, { 3, 0, 2, 0 }, + { 3, 0, 2, 1 }, { 3, 0, 2, 2 }, { 3, 1, 0, 0 }, { 3, 1, 0, 1 }, + { 3, 1, 0, 2 }, { 3, 1, 1, 0 }, { 3, 1, 1, 1 }, { 3, 1, 1, 2 }, + { 3, 1, 2, 0 }, { 3, 1, 2, 1 }, { 3, 1, 2, 2 }, { 3, 2, 0, 0 }, + { 3, 2, 0, 1 }, { 3, 2, 0, 2 }, { 3, 2, 1, 0 }, { 3, 2, 1, 1 }, + { 3, 2, 1, 2 }, { 3, 2, 2, 0 }, { 3, 2, 2, 1 }, { 3, 2, 2, 2 }, +}; + +/** + * quantizer values used for AC and DC coefficients in chroma blocks + */ +static const uint8_t rv34_chroma_quant[2][32] = { + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 17, 18, 19, 20, 20, 21, 22, 22, 23, 23, 24, 24, 25, 25 }, + { 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 15, 16, 17, 18, 18, 19, 20, 20, 21, 21, 22, 22, 23, 23 } +}; + +/** + * This table is used for dequantizing. + */ +static const uint16_t rv34_qscale_tab[32] = { + 60, 67, 76, 85, 96, 108, 121, 136, + 152, 171, 192, 216, 242, 272, 305, 341, + 383, 432, 481, 544, 606, 683, 767, 854, + 963, 1074, 1212, 1392, 1566, 1708, 1978, 2211 +}; + +/** + * 4x4 dezigzag pattern + */ +static const uint8_t rv34_dezigzag[16] = { + 0, 1, 8, 16, + 9, 2, 3, 10, + 17, 24, 25, 18, + 11, 19, 26, 27 +}; + +/** + * tables used to translate a quantizer value into a VLC set for decoding + * The first table is used for intraframes. + */ +static const uint8_t rv34_quant_to_vlc_set[2][31] = { + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 0 }, + { 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, + 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6 }, +}; + +/** + * table for obtaining the quantizer difference + * @todo Use with modified_quant_tab from h263data.h. + */ +static const uint8_t rv34_dquant_tab[2][32]={ +// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 +{ + 0, 3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9,10,11,12,13,14,15,16,17,18,18,19,20,21,22,23,24,25,26,27,28 +},{ + 0, 2, 3, 4, 5, 6, 7, 8, 9,10,11,13,14,15,16,17,18,19,20,21,22,24,25,26,27,28,29,30,31,31,31,26 +} +}; + +/** + * maximum number of macroblocks for each of the possible slice offset sizes + * @todo This is the same as ff_mba_max, maybe use it instead. + */ +static const uint16_t rv34_mb_max_sizes[6] = { 0x2F, 0x68, 0x18B, 0x62F, 0x18BF, 0x23FF }; +/** + * bits needed to code the slice offset for the given size + * @todo This is the same as ff_mba_length, maybe use it instead. + */ +static const uint8_t rv34_mb_bits_sizes[6] = { 6, 7, 9, 11, 13, 14 }; + +#endif /* FFMPEG_RV34DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/rv34vlc.h b/contrib/ffmpeg/libavcodec/rv34vlc.h new file mode 100644 index 000000000..ef3cfbab3 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/rv34vlc.h @@ -0,0 +1,4054 @@ +/* + * RealVideo 3/4 decoder + * Copyright (c) 2007 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file rv34vlc.h + * RV30/40 VLC tables + */ + +#ifndef FFMPEG_RV34VLC_H +#define FFMPEG_RV34VLC_H + +#include + +#define NUM_INTRA_TABLES 5 +#define NUM_INTER_TABLES 7 + +#define CBPPAT_VLC_SIZE 1296 +#define CBP_VLC_SIZE 16 +#define FIRSTBLK_VLC_SIZE 864 +#define OTHERBLK_VLC_SIZE 108 +#define COEFF_VLC_SIZE 32 + +static const uint8_t rv34_table_intra_cbppat[NUM_INTRA_TABLES][2][CBPPAT_VLC_SIZE] = { + { + { + 8, 10, 10, 10, 10, 10, 11, 10, 10, 11, 10, 10, 10, 10, 10, 6, + 12, 12, 13, 12, 13, 12, 13, 11, 13, 13, 13, 12, 13, 12, 12, 8, + 14, 13, 16, 13, 15, 13, 16, 12, 16, 16, 16, 14, 16, 13, 14, 10, + 12, 13, 12, 12, 13, 13, 13, 12, 13, 13, 12, 12, 13, 12, 12, 8, + 13, 14, 14, 12, 14, 14, 14, 12, 14, 15, 14, 12, 14, 13, 13, 8, + 16, 16, 16, 12, 16, 16, 16, 13, 16, 16, 16, 13, 16, 14, 14, 9, + 14, 16, 13, 13, 16, 16, 16, 14, 15, 16, 14, 13, 15, 15, 14, 10, + 16, 16, 14, 13, 16, 16, 16, 13, 16, 16, 16, 13, 16, 15, 14, 10, + 16, 16, 16, 11, 16, 16, 16, 12, 16, 16, 16, 12, 16, 16, 15, 9, + 12, 13, 13, 13, 12, 12, 14, 12, 12, 14, 13, 12, 12, 12, 12, 8, + 14, 14, 16, 14, 13, 12, 14, 12, 14, 15, 14, 13, 13, 12, 13, 8, + 16, 16, 16, 15, 16, 13, 16, 13, 16, 16, 16, 15, 16, 13, 15, 10, + 14, 16, 14, 14, 14, 14, 15, 13, 14, 16, 14, 13, 13, 13, 13, 9, + 16, 16, 16, 14, 16, 14, 16, 12, 16, 16, 14, 13, 14, 13, 13, 8, + 16, 16, 16, 14, 16, 14, 16, 13, 16, 16, 16, 14, 16, 14, 14, 9, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 14, 10, + 16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 16, 14, 16, 15, 14, 9, + 16, 16, 16, 13, 16, 16, 16, 12, 16, 16, 16, 13, 16, 15, 15, 8, + 14, 16, 16, 16, 14, 14, 16, 14, 16, 16, 16, 15, 13, 13, 14, 10, + 16, 16, 16, 16, 15, 13, 16, 13, 16, 16, 16, 16, 16, 13, 14, 10, + 16, 16, 16, 16, 16, 11, 16, 12, 16, 16, 16, 16, 16, 12, 16, 9, + 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 16, 14, 14, 10, + 16, 16, 16, 16, 16, 15, 16, 13, 16, 16, 16, 15, 16, 13, 14, 9, + 16, 16, 16, 16, 16, 13, 16, 12, 16, 16, 16, 16, 16, 13, 14, 8, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 11, + 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 14, 9, + 16, 16, 16, 14, 16, 15, 16, 11, 16, 16, 16, 14, 16, 14, 14, 8, + 12, 13, 13, 13, 13, 13, 14, 12, 12, 13, 12, 12, 12, 12, 12, 8, + 14, 14, 16, 14, 15, 14, 16, 13, 14, 15, 14, 13, 14, 13, 13, 9, + 16, 16, 16, 15, 16, 16, 16, 14, 16, 16, 16, 14, 16, 14, 16, 10, + 14, 15, 14, 14, 15, 14, 15, 13, 14, 14, 13, 12, 13, 13, 13, 9, + 15, 16, 15, 14, 16, 16, 16, 13, 15, 16, 14, 12, 14, 13, 13, 8, + 16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 16, 13, 16, 14, 14, 9, + 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 13, 13, 16, 16, 14, 10, + 16, 16, 16, 14, 16, 16, 16, 14, 16, 16, 15, 13, 16, 14, 14, 9, + 16, 16, 16, 12, 16, 16, 16, 13, 16, 16, 16, 12, 16, 16, 15, 8, + 13, 14, 14, 14, 14, 14, 16, 13, 13, 14, 14, 13, 12, 12, 12, 8, + 16, 16, 16, 14, 15, 14, 16, 13, 15, 16, 14, 13, 13, 12, 13, 8, + 16, 16, 16, 16, 16, 14, 16, 14, 16, 16, 16, 14, 16, 13, 14, 9, + 15, 16, 16, 15, 16, 15, 16, 13, 14, 16, 14, 13, 13, 13, 12, 8, + 16, 16, 16, 14, 16, 14, 15, 12, 15, 15, 14, 12, 13, 12, 12, 7, + 16, 16, 16, 14, 16, 14, 16, 12, 16, 16, 16, 13, 16, 13, 13, 7, + 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 14, 14, 16, 14, 13, 9, + 16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 14, 12, 16, 13, 12, 7, + 16, 16, 16, 12, 16, 16, 16, 11, 16, 16, 15, 12, 16, 13, 13, 6, + 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 15, 13, 13, 14, 10, + 16, 16, 16, 16, 16, 14, 16, 14, 16, 16, 16, 16, 14, 13, 14, 9, + 16, 16, 16, 16, 16, 13, 16, 13, 16, 16, 16, 16, 16, 12, 14, 8, + 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 14, 14, 13, 13, 9, + 16, 16, 16, 16, 16, 14, 16, 13, 16, 16, 16, 13, 14, 12, 12, 7, + 16, 16, 16, 16, 16, 13, 16, 12, 16, 16, 16, 13, 14, 12, 13, 6, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 14, 9, + 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 13, 15, 13, 12, 7, + 16, 16, 16, 13, 16, 14, 16, 11, 16, 16, 16, 12, 16, 12, 12, 5, + 14, 16, 15, 16, 16, 16, 16, 15, 14, 15, 14, 14, 13, 14, 13, 10, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 14, 16, 10, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 11, + 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 14, 14, 15, 14, 13, 10, + 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 14, 13, 16, 14, 14, 9, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 15, 9, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12, 13, 16, 16, 13, 10, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, 13, 16, 16, 13, 9, + 16, 16, 16, 14, 16, 16, 16, 14, 16, 16, 15, 12, 16, 16, 14, 8, + 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 15, 14, 13, 13, 13, 9, + 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 14, 14, 13, 13, 9, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 15, 9, + 16, 16, 16, 16, 16, 16, 16, 15, 15, 16, 14, 14, 14, 13, 13, 9, + 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 14, 12, 13, 12, 12, 7, + 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 13, 16, 13, 13, 7, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, 13, 16, 14, 13, 9, + 16, 16, 16, 15, 16, 16, 16, 13, 16, 16, 13, 12, 14, 13, 12, 6, + 16, 16, 16, 13, 16, 16, 16, 12, 16, 16, 14, 10, 15, 12, 12, 5, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12, 13, 13, 9, + 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 15, 13, 12, 13, 8, + 16, 16, 16, 16, 16, 14, 16, 14, 16, 16, 16, 16, 15, 12, 14, 8, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 13, 13, 13, 8, + 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 15, 13, 12, 11, 12, 6, + 16, 16, 16, 15, 16, 14, 16, 12, 16, 16, 16, 12, 13, 10, 12, 5, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 13, 14, 12, 8, + 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 13, 12, 13, 12, 10, 5, + 16, 16, 16, 13, 16, 13, 16, 10, 16, 16, 13, 10, 13, 10, 10, 1, + }, + { + 2, 7, 7, 8, 7, 8, 9, 8, 7, 9, 8, 8, 8, 8, 9, 7, + 6, 9, 10, 10, 10, 10, 11, 10, 10, 11, 11, 11, 10, 11, 11, 9, + 9, 11, 12, 12, 12, 13, 14, 13, 13, 14, 14, 13, 13, 13, 14, 11, + 6, 10, 9, 10, 10, 11, 11, 11, 10, 11, 10, 11, 11, 11, 11, 9, + 6, 9, 10, 10, 10, 11, 12, 11, 10, 12, 11, 11, 11, 11, 11, 8, + 9, 11, 12, 12, 12, 13, 13, 13, 12, 14, 14, 13, 13, 13, 13, 10, + 9, 13, 11, 13, 13, 14, 14, 13, 13, 14, 13, 13, 14, 14, 14, 12, + 9, 12, 12, 12, 12, 14, 14, 13, 13, 14, 13, 13, 13, 14, 13, 11, + 8, 12, 12, 11, 12, 14, 14, 12, 13, 14, 14, 13, 13, 13, 14, 11, + 6, 10, 10, 11, 9, 10, 12, 11, 10, 12, 11, 11, 10, 11, 11, 9, + 7, 10, 10, 11, 10, 11, 12, 11, 11, 12, 11, 11, 11, 11, 11, 9, + 9, 12, 13, 13, 12, 12, 14, 13, 13, 14, 14, 13, 14, 13, 14, 11, + 8, 11, 11, 12, 11, 12, 12, 12, 11, 13, 12, 12, 12, 12, 12, 10, + 7, 10, 10, 11, 10, 11, 12, 11, 10, 12, 11, 11, 11, 11, 11, 8, + 9, 11, 12, 12, 12, 12, 13, 12, 12, 13, 13, 12, 13, 12, 13, 10, + 10, 13, 13, 14, 14, 14, 15, 14, 14, 15, 14, 15, 14, 14, 14, 12, + 9, 12, 12, 13, 12, 13, 14, 13, 12, 13, 13, 12, 13, 13, 13, 10, + 9, 12, 12, 12, 12, 13, 14, 12, 12, 14, 13, 12, 13, 13, 13, 10, + 9, 12, 13, 13, 11, 13, 14, 13, 13, 14, 14, 14, 12, 13, 13, 11, + 10, 12, 13, 13, 12, 12, 14, 13, 13, 14, 14, 14, 13, 13, 14, 11, + 10, 13, 14, 14, 13, 12, 15, 13, 14, 14, 14, 14, 15, 13, 14, 11, + 11, 14, 14, 14, 13, 14, 15, 14, 14, 15, 15, 14, 13, 14, 14, 12, + 10, 13, 12, 13, 12, 12, 14, 13, 13, 14, 13, 13, 13, 13, 13, 10, + 10, 12, 13, 13, 13, 12, 14, 12, 13, 14, 14, 13, 13, 13, 13, 10, + 13, 15, 16, 16, 15, 15, 16, 16, 15, 16, 15, 16, 16, 16, 16, 14, + 11, 14, 14, 14, 14, 14, 15, 14, 14, 15, 15, 14, 14, 14, 15, 11, + 10, 13, 13, 13, 13, 13, 14, 12, 13, 14, 14, 13, 13, 13, 13, 10, + 6, 10, 10, 11, 10, 11, 12, 11, 10, 12, 10, 11, 10, 11, 11, 9, + 8, 11, 11, 12, 11, 12, 13, 12, 11, 12, 12, 12, 12, 12, 12, 10, + 11, 13, 14, 14, 13, 14, 15, 14, 13, 15, 15, 14, 14, 14, 15, 12, + 7, 11, 10, 12, 11, 12, 12, 12, 11, 12, 11, 12, 11, 12, 12, 10, + 7, 10, 10, 11, 10, 11, 12, 11, 11, 12, 11, 11, 11, 11, 11, 9, + 10, 12, 13, 13, 12, 13, 14, 13, 13, 14, 13, 13, 13, 13, 13, 10, + 10, 13, 12, 14, 13, 14, 14, 14, 13, 14, 12, 14, 15, 14, 14, 11, + 10, 12, 12, 12, 12, 13, 14, 13, 13, 14, 13, 12, 13, 13, 13, 10, + 9, 12, 13, 13, 13, 14, 14, 13, 13, 14, 14, 13, 13, 13, 13, 10, + 7, 10, 10, 11, 10, 11, 12, 11, 10, 12, 12, 11, 9, 11, 11, 9, + 7, 10, 11, 11, 10, 11, 12, 11, 10, 12, 12, 11, 11, 11, 11, 9, + 10, 12, 13, 13, 13, 13, 15, 13, 13, 14, 13, 13, 13, 13, 13, 10, + 8, 11, 11, 11, 11, 11, 12, 11, 11, 12, 12, 11, 11, 12, 11, 9, + 6, 9, 9, 10, 9, 10, 10, 10, 9, 11, 10, 10, 9, 10, 10, 7, + 8, 10, 11, 11, 11, 11, 12, 11, 11, 12, 12, 11, 11, 11, 11, 8, + 10, 13, 13, 13, 13, 14, 14, 13, 13, 14, 13, 13, 13, 13, 13, 11, + 8, 11, 11, 11, 11, 12, 12, 11, 11, 12, 11, 11, 11, 11, 11, 8, + 8, 11, 11, 11, 11, 12, 12, 10, 11, 12, 12, 11, 11, 11, 11, 8, + 10, 13, 13, 13, 12, 13, 14, 13, 12, 14, 14, 14, 10, 13, 13, 11, + 10, 12, 12, 13, 12, 13, 14, 12, 12, 13, 13, 13, 12, 12, 13, 10, + 11, 13, 14, 14, 13, 13, 14, 13, 13, 15, 14, 13, 13, 13, 13, 10, + 10, 12, 13, 13, 12, 13, 14, 13, 13, 14, 14, 13, 12, 13, 13, 11, + 8, 11, 11, 11, 11, 11, 12, 11, 11, 12, 12, 11, 11, 11, 11, 8, + 9, 11, 12, 12, 11, 11, 12, 11, 12, 12, 12, 11, 12, 11, 11, 8, + 12, 15, 14, 14, 14, 15, 15, 14, 14, 15, 15, 14, 14, 14, 15, 12, + 10, 12, 12, 12, 12, 12, 13, 12, 12, 13, 13, 12, 12, 12, 12, 9, + 9, 11, 11, 11, 11, 11, 12, 10, 11, 12, 12, 11, 11, 11, 11, 7, + 10, 13, 13, 13, 13, 14, 15, 14, 13, 14, 14, 14, 12, 14, 15, 12, + 11, 14, 14, 14, 14, 15, 15, 14, 14, 15, 15, 15, 14, 15, 15, 12, + 13, 16, 16, 16, 15, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 14, + 10, 13, 13, 14, 13, 15, 14, 14, 13, 15, 13, 14, 14, 14, 14, 12, + 10, 13, 13, 13, 13, 13, 14, 13, 13, 14, 13, 13, 13, 13, 14, 11, + 12, 14, 14, 14, 14, 15, 15, 14, 14, 15, 15, 14, 15, 14, 14, 12, + 11, 14, 14, 15, 14, 15, 15, 14, 14, 15, 12, 14, 15, 16, 15, 12, + 11, 13, 13, 14, 13, 14, 14, 14, 14, 14, 13, 13, 14, 14, 14, 11, + 11, 14, 14, 14, 14, 15, 15, 14, 14, 16, 14, 13, 14, 14, 14, 11, + 10, 13, 13, 13, 12, 14, 14, 14, 12, 15, 14, 14, 11, 13, 13, 12, + 10, 12, 13, 14, 12, 13, 14, 13, 13, 14, 14, 13, 12, 13, 13, 11, + 12, 14, 14, 15, 14, 15, 16, 15, 15, 15, 15, 15, 14, 14, 15, 12, + 10, 13, 13, 13, 12, 13, 14, 13, 13, 14, 13, 13, 12, 13, 13, 11, + 9, 11, 11, 12, 11, 12, 12, 11, 11, 12, 12, 11, 11, 11, 11, 9, + 10, 12, 12, 12, 12, 12, 13, 12, 12, 13, 13, 12, 13, 12, 12, 9, + 11, 13, 13, 15, 14, 14, 15, 14, 14, 15, 14, 14, 14, 14, 14, 11, + 10, 12, 12, 12, 12, 12, 13, 12, 12, 13, 11, 11, 12, 12, 12, 8, + 9, 12, 12, 11, 12, 12, 13, 11, 12, 12, 12, 11, 12, 11, 11, 8, + 10, 13, 13, 14, 12, 14, 15, 14, 13, 15, 15, 14, 10, 13, 13, 11, + 11, 13, 14, 13, 13, 14, 14, 13, 13, 14, 14, 14, 11, 13, 13, 11, + 12, 14, 14, 14, 14, 14, 15, 14, 15, 16, 15, 14, 13, 13, 14, 11, + 11, 14, 13, 14, 13, 14, 15, 14, 13, 15, 14, 14, 11, 13, 13, 11, + 9, 12, 12, 12, 11, 12, 13, 11, 12, 13, 12, 11, 10, 11, 11, 8, + 10, 12, 12, 12, 12, 12, 13, 11, 12, 12, 12, 11, 11, 11, 11, 8, + 12, 15, 14, 15, 14, 15, 16, 15, 15, 15, 15, 14, 14, 14, 14, 12, + 10, 12, 12, 12, 12, 12, 13, 11, 12, 13, 12, 11, 11, 11, 11, 8, + 8, 10, 10, 10, 10, 10, 11, 9, 10, 11, 10, 9, 10, 9, 9, 5, + }, + }, + { + { + 12, 12, 11, 9, 11, 10, 11, 9, 11, 11, 10, 9, 9, 8, 9, 5, + 14, 13, 14, 11, 14, 11, 13, 10, 14, 13, 12, 10, 12, 10, 11, 6, + 16, 13, 16, 12, 16, 12, 16, 11, 16, 14, 16, 12, 15, 12, 13, 8, + 14, 14, 12, 11, 14, 12, 13, 10, 13, 13, 11, 10, 12, 11, 10, 6, + 16, 15, 14, 11, 16, 13, 14, 10, 15, 14, 13, 10, 13, 11, 11, 7, + 16, 16, 16, 11, 16, 14, 16, 11, 16, 16, 15, 12, 15, 13, 13, 8, + 16, 16, 13, 12, 16, 16, 15, 12, 16, 16, 12, 11, 15, 13, 12, 8, + 16, 16, 14, 11, 16, 16, 16, 11, 16, 16, 14, 11, 15, 14, 13, 8, + 16, 16, 15, 10, 16, 16, 16, 10, 16, 16, 15, 11, 16, 14, 14, 8, + 14, 14, 14, 12, 13, 11, 13, 10, 13, 13, 12, 11, 11, 10, 10, 6, + 16, 15, 16, 13, 13, 11, 14, 11, 15, 14, 13, 11, 12, 10, 11, 7, + 16, 15, 16, 14, 16, 11, 16, 11, 16, 16, 16, 13, 16, 12, 13, 8, + 16, 16, 14, 13, 15, 13, 14, 11, 14, 15, 13, 11, 13, 11, 11, 7, + 16, 16, 15, 13, 15, 13, 14, 11, 16, 15, 14, 11, 13, 11, 11, 7, + 16, 16, 16, 13, 16, 13, 16, 11, 16, 16, 16, 12, 16, 12, 13, 8, + 16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 14, 13, 15, 14, 13, 9, + 16, 16, 16, 13, 16, 16, 16, 12, 16, 16, 14, 12, 15, 13, 13, 8, + 16, 16, 16, 12, 16, 16, 16, 11, 16, 16, 15, 12, 16, 13, 13, 7, + 16, 16, 16, 16, 13, 12, 16, 12, 16, 16, 14, 13, 12, 11, 12, 8, + 16, 16, 16, 15, 14, 11, 16, 11, 16, 16, 16, 13, 14, 11, 13, 8, + 16, 16, 16, 16, 15, 10, 16, 11, 16, 16, 16, 14, 15, 11, 13, 8, + 16, 16, 16, 16, 16, 14, 16, 13, 16, 16, 14, 14, 14, 12, 13, 9, + 16, 16, 16, 15, 16, 13, 16, 12, 16, 16, 16, 13, 14, 12, 13, 8, + 16, 16, 16, 14, 16, 12, 16, 11, 16, 16, 16, 13, 15, 12, 13, 7, + 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 15, 16, 14, 13, 9, + 16, 16, 16, 16, 16, 16, 16, 12, 16, 16, 16, 14, 16, 13, 13, 8, + 16, 16, 16, 14, 16, 14, 16, 10, 16, 16, 16, 13, 16, 13, 13, 7, + 14, 14, 13, 12, 13, 12, 13, 11, 12, 13, 11, 10, 11, 10, 10, 6, + 16, 16, 15, 13, 16, 13, 15, 11, 14, 14, 13, 11, 13, 11, 11, 7, + 16, 16, 16, 14, 16, 14, 16, 12, 16, 16, 16, 13, 16, 13, 14, 9, + 16, 16, 13, 13, 15, 14, 14, 11, 13, 14, 11, 11, 12, 11, 11, 7, + 16, 16, 15, 12, 16, 14, 15, 11, 14, 14, 12, 11, 13, 11, 11, 7, + 16, 16, 16, 13, 16, 14, 16, 12, 16, 16, 14, 12, 16, 13, 13, 8, + 16, 16, 14, 14, 16, 16, 16, 13, 16, 16, 12, 11, 15, 13, 12, 8, + 16, 16, 15, 13, 16, 16, 16, 12, 16, 16, 13, 11, 16, 13, 12, 8, + 16, 16, 16, 11, 16, 16, 16, 11, 16, 16, 14, 11, 16, 14, 13, 7, + 16, 16, 15, 13, 14, 13, 14, 11, 14, 14, 12, 11, 11, 10, 11, 7, + 16, 16, 16, 13, 14, 12, 15, 11, 15, 14, 13, 11, 12, 11, 11, 7, + 16, 16, 16, 14, 16, 13, 16, 12, 16, 16, 16, 13, 14, 12, 13, 8, + 16, 16, 15, 13, 15, 14, 14, 12, 14, 14, 12, 11, 12, 11, 11, 7, + 16, 16, 14, 12, 15, 13, 14, 11, 15, 14, 13, 11, 12, 11, 11, 6, + 16, 16, 16, 13, 16, 13, 16, 11, 16, 15, 14, 11, 14, 11, 12, 6, + 16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 13, 12, 14, 13, 12, 8, + 16, 16, 15, 13, 16, 14, 15, 11, 16, 16, 13, 11, 14, 12, 11, 6, + 16, 16, 16, 12, 16, 14, 15, 11, 16, 16, 13, 10, 14, 12, 12, 6, + 16, 16, 16, 16, 16, 14, 16, 13, 16, 16, 14, 13, 12, 11, 12, 8, + 16, 16, 16, 16, 16, 13, 16, 12, 16, 16, 15, 13, 13, 11, 12, 8, + 16, 16, 16, 15, 16, 12, 16, 12, 16, 16, 16, 14, 14, 11, 13, 7, + 16, 16, 16, 16, 16, 15, 16, 13, 16, 16, 14, 13, 13, 12, 12, 8, + 16, 16, 16, 14, 15, 13, 15, 11, 16, 15, 14, 12, 13, 11, 11, 6, + 16, 16, 16, 14, 16, 12, 15, 11, 16, 16, 15, 12, 14, 11, 12, 6, + 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 15, 13, 14, 13, 12, 8, + 16, 16, 16, 14, 16, 14, 16, 12, 16, 16, 14, 12, 13, 12, 11, 6, + 16, 16, 16, 13, 16, 13, 15, 10, 16, 16, 14, 11, 14, 11, 11, 5, + 16, 16, 15, 14, 16, 16, 16, 13, 14, 14, 12, 12, 12, 12, 12, 8, + 16, 16, 16, 15, 16, 16, 16, 14, 16, 16, 14, 13, 14, 13, 13, 9, + 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 14, 16, 13, 15, 9, + 16, 16, 14, 15, 16, 16, 16, 14, 14, 16, 12, 12, 13, 13, 12, 8, + 16, 16, 16, 14, 16, 16, 16, 13, 16, 15, 13, 12, 14, 12, 12, 8, + 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 14, 12, 16, 13, 13, 8, + 16, 16, 16, 15, 16, 16, 16, 14, 16, 16, 11, 11, 15, 14, 12, 8, + 16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 12, 11, 15, 13, 12, 8, + 16, 16, 16, 13, 16, 16, 16, 12, 16, 16, 13, 10, 16, 13, 12, 7, + 16, 16, 16, 16, 16, 15, 16, 13, 14, 16, 13, 13, 12, 12, 12, 8, + 16, 16, 16, 15, 16, 14, 16, 13, 16, 16, 14, 13, 13, 12, 12, 8, + 16, 16, 16, 16, 16, 15, 16, 13, 16, 16, 16, 13, 15, 12, 14, 8, + 16, 16, 16, 15, 16, 16, 16, 13, 14, 16, 13, 12, 12, 12, 11, 8, + 16, 16, 16, 14, 16, 14, 16, 12, 14, 14, 13, 11, 13, 11, 11, 6, + 16, 16, 16, 14, 16, 14, 16, 12, 16, 15, 14, 11, 14, 11, 12, 6, + 16, 16, 16, 15, 16, 16, 16, 14, 16, 16, 12, 12, 14, 13, 11, 8, + 16, 16, 15, 14, 16, 16, 16, 12, 16, 15, 12, 11, 13, 12, 11, 6, + 16, 16, 16, 13, 16, 14, 16, 11, 16, 14, 13, 10, 14, 11, 11, 5, + 16, 16, 16, 16, 16, 16, 16, 14, 14, 16, 15, 13, 11, 11, 11, 8, + 16, 16, 16, 16, 16, 15, 16, 13, 16, 16, 16, 13, 12, 11, 12, 7, + 16, 16, 16, 16, 16, 13, 16, 12, 16, 16, 16, 13, 13, 11, 13, 7, + 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 14, 13, 12, 12, 11, 7, + 16, 16, 16, 15, 16, 14, 15, 12, 16, 14, 13, 12, 12, 11, 11, 6, + 16, 16, 16, 14, 16, 13, 15, 11, 16, 14, 14, 11, 13, 10, 11, 5, + 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 13, 12, 12, 12, 11, 7, + 16, 16, 16, 14, 16, 14, 15, 12, 16, 15, 12, 11, 12, 11, 10, 5, + 16, 16, 16, 13, 16, 13, 14, 10, 16, 14, 12, 9, 12, 10, 9, 3, + }, + { + 2, 6, 6, 7, 6, 7, 8, 7, 7, 8, 7, 8, 7, 8, 8, 5, + 5, 8, 9, 9, 9, 9, 12, 10, 10, 11, 10, 10, 10, 11, 11, 8, + 9, 10, 13, 12, 13, 12, 15, 13, 13, 14, 13, 14, 13, 13, 14, 11, + 5, 10, 9, 10, 10, 10, 12, 10, 10, 12, 10, 11, 11, 11, 11, 8, + 6, 9, 10, 9, 10, 11, 12, 10, 10, 12, 11, 11, 10, 11, 11, 8, + 9, 11, 12, 11, 12, 13, 14, 12, 13, 14, 14, 12, 13, 13, 13, 11, + 10, 13, 11, 12, 14, 14, 15, 13, 13, 15, 12, 13, 14, 14, 14, 12, + 9, 12, 12, 12, 13, 13, 15, 13, 13, 14, 13, 13, 14, 13, 15, 11, + 8, 11, 12, 10, 12, 13, 14, 12, 13, 14, 14, 13, 13, 13, 14, 11, + 5, 9, 10, 10, 9, 10, 12, 11, 10, 12, 11, 11, 9, 11, 11, 9, + 6, 10, 10, 11, 10, 10, 12, 11, 11, 12, 11, 11, 11, 11, 11, 9, + 9, 11, 13, 13, 12, 11, 14, 12, 13, 15, 13, 13, 14, 13, 14, 11, + 8, 11, 11, 12, 11, 12, 13, 12, 12, 13, 12, 13, 12, 12, 12, 10, + 7, 10, 10, 11, 10, 11, 12, 11, 11, 12, 11, 11, 11, 11, 12, 9, + 9, 12, 12, 12, 12, 12, 14, 12, 13, 14, 13, 13, 13, 13, 13, 11, + 11, 14, 13, 15, 15, 16, 16, 15, 15, 16, 15, 15, 16, 16, 15, 13, + 10, 12, 13, 13, 13, 14, 15, 13, 13, 14, 13, 13, 14, 14, 14, 11, + 9, 12, 12, 12, 13, 13, 14, 12, 13, 14, 14, 13, 13, 13, 14, 11, + 9, 13, 13, 13, 11, 12, 15, 13, 13, 15, 14, 14, 11, 13, 14, 11, + 10, 13, 13, 13, 12, 12, 15, 13, 13, 15, 14, 14, 13, 13, 14, 11, + 10, 12, 13, 13, 12, 11, 14, 12, 13, 15, 13, 13, 13, 13, 14, 11, + 11, 14, 15, 15, 13, 14, 16, 14, 14, 16, 16, 14, 14, 15, 15, 13, + 10, 13, 13, 13, 12, 13, 14, 13, 13, 14, 14, 14, 13, 13, 14, 11, + 10, 12, 13, 13, 13, 12, 14, 13, 13, 14, 14, 13, 13, 13, 13, 11, + 13, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, + 12, 15, 15, 15, 14, 15, 16, 14, 15, 16, 16, 15, 16, 15, 15, 13, + 10, 12, 12, 12, 13, 13, 14, 12, 13, 14, 13, 13, 13, 13, 13, 11, + 6, 10, 10, 11, 10, 11, 12, 11, 10, 12, 11, 11, 10, 11, 11, 9, + 8, 11, 12, 12, 12, 12, 13, 12, 12, 13, 12, 13, 12, 13, 13, 10, + 11, 13, 15, 14, 15, 14, 16, 14, 15, 16, 16, 14, 15, 15, 15, 13, + 7, 11, 10, 12, 11, 11, 13, 11, 11, 13, 10, 11, 12, 12, 12, 10, + 7, 11, 11, 11, 11, 11, 13, 11, 11, 13, 11, 12, 12, 12, 12, 9, + 10, 12, 13, 13, 13, 13, 15, 13, 14, 15, 14, 14, 14, 14, 15, 11, + 10, 13, 12, 14, 14, 14, 15, 13, 13, 15, 12, 13, 15, 15, 14, 12, + 10, 13, 12, 12, 13, 13, 15, 14, 13, 15, 13, 13, 14, 14, 14, 11, + 10, 13, 13, 12, 13, 14, 15, 13, 13, 15, 13, 13, 14, 14, 14, 11, + 7, 10, 11, 11, 10, 11, 12, 11, 10, 12, 12, 12, 9, 11, 12, 9, + 7, 11, 11, 11, 11, 11, 13, 11, 11, 13, 12, 12, 11, 12, 12, 9, + 10, 12, 14, 13, 13, 13, 16, 13, 14, 16, 14, 14, 13, 13, 14, 11, + 8, 11, 11, 12, 11, 12, 13, 12, 12, 13, 12, 12, 12, 12, 12, 10, + 6, 9, 9, 10, 9, 10, 11, 10, 10, 11, 10, 10, 10, 10, 10, 8, + 8, 11, 11, 11, 12, 11, 13, 11, 12, 13, 12, 12, 12, 12, 12, 10, + 11, 14, 13, 14, 14, 14, 16, 14, 14, 16, 14, 14, 15, 15, 14, 12, + 9, 12, 11, 12, 12, 12, 13, 12, 12, 13, 12, 12, 12, 12, 12, 10, + 8, 11, 11, 11, 11, 11, 13, 11, 12, 12, 12, 12, 12, 12, 12, 9, + 10, 13, 14, 13, 11, 13, 14, 14, 13, 15, 15, 14, 10, 13, 14, 11, + 10, 13, 13, 13, 12, 13, 14, 13, 13, 14, 14, 14, 13, 13, 13, 11, + 10, 13, 14, 13, 13, 12, 15, 13, 14, 15, 14, 14, 14, 13, 14, 12, + 11, 14, 14, 14, 13, 13, 15, 14, 14, 15, 14, 15, 13, 14, 14, 12, + 9, 11, 12, 12, 11, 11, 13, 12, 12, 13, 12, 12, 12, 12, 12, 10, + 9, 11, 12, 12, 12, 11, 13, 11, 12, 13, 12, 12, 12, 12, 12, 10, + 13, 15, 15, 16, 15, 16, 16, 15, 16, 16, 16, 15, 15, 15, 16, 14, + 10, 13, 13, 13, 13, 13, 14, 13, 13, 14, 13, 13, 13, 13, 13, 11, + 8, 11, 11, 11, 11, 11, 12, 11, 11, 12, 12, 11, 12, 11, 12, 9, + 11, 14, 14, 15, 14, 15, 15, 14, 13, 15, 14, 15, 12, 14, 15, 13, + 12, 15, 15, 15, 15, 15, 16, 15, 15, 16, 16, 16, 15, 16, 15, 13, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, + 11, 14, 13, 15, 14, 14, 16, 14, 14, 16, 13, 14, 15, 14, 15, 12, + 11, 14, 13, 14, 14, 14, 16, 15, 14, 16, 14, 14, 15, 15, 15, 12, + 13, 15, 15, 15, 15, 16, 16, 15, 16, 16, 16, 15, 16, 16, 16, 13, + 11, 14, 13, 14, 14, 14, 15, 14, 14, 16, 12, 14, 16, 16, 14, 12, + 11, 14, 14, 14, 14, 15, 16, 15, 14, 16, 13, 14, 16, 15, 14, 12, + 12, 14, 14, 14, 14, 14, 16, 14, 15, 16, 14, 14, 14, 15, 15, 12, + 11, 14, 14, 14, 13, 14, 16, 15, 13, 16, 15, 15, 11, 14, 14, 12, + 11, 14, 14, 15, 14, 14, 16, 14, 14, 15, 14, 14, 13, 15, 15, 12, + 13, 15, 16, 15, 15, 15, 16, 15, 16, 16, 16, 16, 15, 15, 16, 13, + 11, 14, 14, 14, 14, 14, 15, 14, 14, 16, 14, 14, 14, 15, 14, 12, + 9, 12, 12, 12, 12, 12, 13, 12, 12, 13, 12, 13, 12, 12, 12, 10, + 11, 13, 13, 13, 13, 13, 14, 13, 13, 14, 13, 14, 13, 13, 14, 11, + 12, 15, 14, 15, 15, 15, 16, 15, 14, 16, 14, 14, 16, 16, 14, 13, + 10, 12, 12, 12, 12, 12, 14, 12, 13, 13, 12, 12, 13, 13, 13, 10, + 10, 12, 12, 12, 12, 12, 14, 12, 12, 13, 12, 12, 12, 12, 12, 10, + 10, 14, 14, 14, 12, 14, 16, 14, 13, 16, 16, 16, 10, 13, 14, 12, + 11, 14, 14, 14, 13, 14, 16, 14, 14, 16, 15, 14, 12, 13, 14, 12, + 12, 14, 14, 14, 14, 14, 16, 14, 14, 16, 15, 15, 14, 14, 15, 12, + 12, 14, 15, 15, 14, 15, 16, 14, 15, 15, 15, 15, 13, 15, 14, 12, + 9, 12, 12, 12, 12, 13, 13, 12, 12, 13, 13, 12, 11, 12, 12, 10, + 10, 12, 12, 12, 12, 12, 13, 12, 12, 13, 12, 12, 12, 12, 12, 10, + 13, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 15, 16, 15, 13, + 10, 12, 12, 13, 12, 13, 13, 12, 13, 14, 13, 13, 12, 13, 13, 10, + 7, 10, 10, 10, 10, 10, 11, 10, 10, 11, 10, 10, 10, 10, 10, 7, + }, + }, + { + { + 10, 10, 9, 8, 9, 8, 9, 7, 9, 9, 8, 7, 8, 7, 7, 4, + 13, 11, 12, 9, 12, 9, 12, 9, 12, 11, 11, 9, 10, 9, 9, 6, + 15, 12, 15, 11, 14, 10, 14, 10, 14, 13, 13, 11, 13, 11, 12, 7, + 13, 12, 11, 9, 12, 11, 12, 9, 12, 12, 10, 9, 10, 10, 9, 6, + 14, 13, 12, 10, 13, 12, 13, 9, 13, 12, 11, 10, 12, 11, 10, 6, + 16, 14, 14, 10, 15, 13, 14, 10, 15, 15, 14, 11, 14, 12, 12, 8, + 15, 14, 12, 11, 15, 14, 13, 11, 14, 14, 11, 10, 13, 12, 11, 8, + 15, 16, 13, 11, 16, 14, 14, 11, 15, 15, 12, 10, 14, 13, 12, 8, + 16, 15, 14, 10, 16, 14, 14, 10, 16, 15, 14, 10, 14, 13, 12, 7, + 13, 12, 12, 11, 11, 9, 12, 9, 12, 12, 11, 10, 10, 9, 9, 6, + 13, 13, 14, 12, 12, 10, 12, 10, 14, 13, 12, 11, 11, 10, 10, 7, + 16, 14, 16, 13, 14, 11, 15, 10, 16, 15, 14, 12, 14, 11, 12, 8, + 14, 14, 13, 12, 13, 12, 13, 10, 13, 13, 12, 11, 11, 10, 10, 7, + 15, 14, 14, 12, 14, 12, 13, 10, 14, 13, 12, 11, 12, 11, 11, 7, + 16, 15, 16, 13, 15, 13, 15, 10, 16, 15, 14, 12, 14, 12, 12, 7, + 15, 16, 14, 13, 16, 14, 14, 12, 15, 15, 12, 12, 13, 12, 12, 8, + 16, 16, 14, 13, 16, 14, 14, 11, 15, 15, 14, 11, 14, 12, 12, 8, + 16, 16, 15, 12, 16, 14, 15, 10, 16, 16, 13, 12, 14, 13, 12, 7, + 14, 14, 14, 13, 13, 11, 13, 11, 14, 14, 13, 12, 11, 10, 11, 8, + 16, 15, 16, 13, 13, 11, 14, 11, 15, 14, 14, 13, 12, 11, 12, 8, + 15, 15, 16, 14, 14, 10, 14, 10, 16, 15, 15, 13, 14, 10, 12, 8, + 16, 16, 16, 14, 15, 13, 14, 12, 15, 15, 13, 13, 13, 12, 12, 8, + 16, 16, 16, 14, 15, 13, 14, 11, 16, 16, 14, 13, 13, 12, 12, 8, + 16, 16, 16, 14, 16, 12, 15, 11, 16, 15, 15, 13, 14, 12, 12, 8, + 16, 16, 16, 16, 16, 15, 15, 13, 16, 16, 14, 13, 14, 13, 12, 9, + 16, 16, 16, 14, 16, 15, 15, 11, 16, 16, 14, 13, 15, 13, 12, 8, + 16, 16, 16, 14, 16, 14, 14, 10, 16, 16, 15, 13, 14, 12, 12, 7, + 12, 12, 12, 11, 12, 11, 12, 10, 11, 11, 10, 9, 9, 9, 9, 6, + 14, 13, 14, 12, 13, 12, 13, 10, 13, 13, 12, 10, 12, 10, 11, 7, + 16, 14, 16, 13, 15, 13, 16, 12, 15, 14, 14, 12, 14, 12, 13, 8, + 14, 14, 13, 11, 14, 12, 13, 11, 12, 12, 10, 10, 11, 10, 10, 7, + 14, 14, 13, 12, 14, 12, 13, 11, 13, 13, 12, 10, 12, 11, 10, 7, + 16, 15, 15, 12, 16, 14, 15, 11, 16, 14, 13, 11, 14, 12, 12, 8, + 16, 16, 13, 13, 16, 15, 14, 12, 14, 14, 11, 11, 13, 12, 11, 8, + 16, 16, 14, 12, 16, 14, 14, 12, 15, 14, 12, 11, 14, 12, 12, 8, + 16, 15, 14, 11, 16, 15, 15, 11, 16, 15, 13, 11, 14, 13, 12, 8, + 14, 13, 13, 12, 13, 11, 13, 10, 12, 13, 11, 10, 10, 10, 10, 7, + 15, 14, 14, 13, 13, 12, 13, 11, 14, 13, 12, 11, 12, 10, 11, 7, + 16, 15, 16, 14, 15, 12, 15, 11, 16, 14, 14, 12, 14, 11, 12, 8, + 14, 15, 13, 12, 14, 13, 13, 11, 13, 13, 11, 11, 11, 10, 10, 7, + 14, 14, 14, 12, 14, 13, 13, 10, 14, 13, 12, 10, 12, 10, 10, 6, + 16, 15, 15, 13, 16, 13, 15, 11, 15, 14, 13, 11, 13, 11, 11, 7, + 16, 16, 14, 13, 16, 15, 14, 12, 15, 15, 12, 11, 13, 12, 11, 8, + 16, 16, 14, 13, 16, 14, 14, 11, 15, 14, 12, 11, 13, 12, 11, 7, + 16, 16, 15, 12, 16, 14, 14, 11, 15, 15, 13, 11, 14, 12, 11, 6, + 16, 15, 15, 14, 14, 12, 14, 12, 13, 14, 13, 12, 11, 11, 11, 8, + 16, 16, 16, 14, 14, 12, 15, 12, 15, 14, 14, 12, 12, 11, 12, 8, + 16, 16, 16, 15, 14, 12, 15, 12, 16, 15, 14, 13, 13, 11, 12, 8, + 16, 16, 16, 15, 15, 14, 15, 12, 14, 14, 13, 12, 12, 11, 11, 8, + 16, 16, 15, 14, 14, 12, 14, 11, 14, 14, 13, 12, 12, 11, 11, 7, + 16, 16, 16, 14, 15, 12, 14, 11, 15, 15, 14, 12, 13, 11, 12, 7, + 16, 16, 16, 16, 16, 15, 16, 13, 15, 15, 14, 12, 13, 12, 11, 8, + 16, 16, 16, 14, 15, 14, 14, 12, 16, 15, 13, 12, 13, 12, 11, 7, + 16, 16, 16, 13, 16, 13, 14, 10, 16, 15, 14, 11, 13, 11, 11, 6, + 14, 15, 13, 13, 14, 13, 14, 12, 12, 13, 11, 11, 11, 11, 10, 8, + 16, 16, 15, 13, 16, 14, 16, 13, 14, 14, 13, 12, 13, 12, 12, 8, + 16, 16, 16, 14, 16, 14, 16, 13, 16, 14, 15, 13, 15, 13, 13, 9, + 15, 15, 14, 14, 15, 14, 14, 12, 13, 14, 11, 11, 12, 12, 11, 8, + 15, 16, 15, 13, 15, 14, 14, 12, 14, 14, 12, 11, 13, 12, 12, 8, + 16, 16, 16, 13, 16, 15, 15, 13, 16, 15, 14, 11, 15, 12, 13, 8, + 16, 16, 14, 13, 16, 15, 15, 13, 14, 14, 10, 11, 14, 12, 11, 8, + 16, 16, 15, 13, 16, 16, 15, 13, 15, 14, 12, 11, 14, 13, 12, 8, + 16, 16, 15, 13, 16, 15, 16, 12, 16, 14, 13, 10, 15, 13, 12, 7, + 15, 15, 15, 14, 14, 14, 15, 12, 13, 14, 12, 12, 11, 11, 11, 8, + 16, 15, 16, 14, 15, 13, 15, 12, 14, 14, 13, 12, 12, 11, 12, 8, + 16, 16, 16, 15, 16, 14, 16, 13, 16, 15, 14, 12, 14, 11, 13, 8, + 16, 16, 15, 14, 16, 14, 15, 13, 14, 14, 12, 11, 12, 11, 11, 8, + 15, 16, 15, 14, 15, 14, 14, 12, 14, 13, 12, 11, 12, 11, 11, 7, + 16, 16, 16, 14, 16, 13, 16, 12, 15, 14, 13, 11, 13, 11, 12, 7, + 16, 16, 15, 14, 16, 15, 15, 13, 14, 15, 11, 11, 13, 12, 11, 8, + 16, 16, 15, 13, 16, 14, 15, 12, 15, 14, 12, 11, 13, 11, 11, 7, + 16, 16, 15, 13, 16, 14, 16, 12, 15, 14, 13, 10, 13, 11, 11, 6, + 16, 16, 16, 14, 14, 14, 15, 13, 14, 14, 14, 12, 11, 11, 11, 8, + 16, 16, 16, 14, 15, 14, 16, 13, 15, 14, 14, 13, 12, 11, 11, 7, + 16, 16, 16, 16, 15, 13, 16, 12, 15, 15, 14, 12, 13, 10, 12, 7, + 16, 16, 16, 14, 15, 15, 14, 13, 14, 14, 13, 12, 12, 11, 11, 8, + 16, 15, 16, 14, 16, 13, 15, 12, 14, 14, 13, 12, 12, 10, 10, 6, + 16, 15, 16, 14, 16, 13, 16, 11, 16, 14, 13, 11, 13, 10, 11, 6, + 16, 16, 16, 15, 16, 16, 15, 13, 14, 16, 12, 12, 12, 12, 10, 7, + 16, 16, 16, 14, 16, 14, 14, 12, 15, 15, 12, 11, 12, 11, 10, 6, + 16, 16, 16, 13, 16, 13, 15, 10, 15, 14, 13, 10, 13, 10, 10, 4, + }, + { + 1, 6, 6, 7, 6, 7, 9, 8, 7, 9, 7, 8, 7, 8, 8, 6, + 6, 9, 10, 10, 10, 10, 12, 11, 10, 12, 11, 11, 11, 11, 12, 9, + 9, 10, 13, 11, 13, 12, 14, 13, 14, 14, 14, 14, 14, 14, 14, 12, + 6, 10, 9, 10, 10, 11, 13, 11, 11, 13, 10, 12, 11, 12, 12, 9, + 6, 10, 10, 10, 10, 11, 13, 11, 11, 13, 12, 12, 11, 12, 12, 9, + 9, 11, 13, 12, 13, 14, 15, 13, 14, 16, 14, 14, 14, 14, 15, 12, + 10, 13, 11, 13, 14, 14, 16, 14, 14, 15, 13, 14, 15, 15, 16, 12, + 9, 13, 12, 12, 14, 14, 16, 14, 14, 15, 14, 14, 15, 15, 15, 12, + 8, 11, 12, 11, 13, 14, 15, 13, 13, 15, 14, 14, 13, 15, 15, 11, + 6, 10, 10, 11, 9, 10, 13, 11, 10, 13, 11, 12, 10, 12, 12, 9, + 6, 10, 10, 11, 11, 10, 13, 11, 11, 13, 11, 12, 12, 12, 13, 10, + 9, 12, 13, 13, 13, 12, 16, 13, 14, 15, 14, 14, 15, 14, 15, 12, + 8, 12, 12, 13, 12, 13, 15, 14, 13, 15, 13, 14, 13, 13, 14, 11, + 7, 11, 11, 12, 11, 12, 13, 12, 12, 13, 12, 13, 12, 13, 13, 10, + 9, 12, 13, 13, 13, 13, 16, 13, 13, 15, 14, 14, 14, 15, 15, 12, + 11, 15, 14, 15, 15, 16, 16, 16, 15, 16, 15, 16, 16, 16, 16, 14, + 10, 13, 13, 14, 14, 14, 16, 15, 14, 16, 15, 15, 15, 15, 16, 13, + 9, 12, 13, 13, 13, 14, 16, 14, 13, 15, 14, 14, 14, 16, 15, 12, + 10, 13, 14, 14, 11, 13, 16, 14, 14, 16, 15, 15, 12, 14, 15, 12, + 10, 13, 14, 14, 12, 12, 16, 15, 14, 16, 15, 15, 14, 14, 16, 12, + 9, 12, 13, 14, 13, 11, 16, 13, 14, 15, 13, 14, 14, 14, 15, 12, + 11, 15, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 10, 13, 14, 14, 13, 14, 16, 15, 14, 16, 16, 16, 14, 15, 16, 13, + 10, 13, 13, 14, 13, 13, 16, 13, 13, 14, 14, 15, 15, 14, 15, 13, + 13, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, + 12, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 10, 12, 13, 14, 13, 13, 14, 13, 13, 14, 13, 14, 14, 14, 15, 12, + 6, 10, 11, 11, 10, 11, 13, 12, 11, 13, 11, 12, 11, 12, 12, 10, + 8, 12, 13, 13, 12, 13, 14, 14, 13, 15, 14, 14, 14, 14, 15, 12, + 12, 14, 16, 15, 15, 15, 16, 15, 16, 16, 16, 16, 16, 16, 16, 14, + 7, 11, 11, 12, 12, 12, 14, 13, 12, 14, 11, 12, 13, 13, 13, 11, + 8, 11, 12, 12, 12, 12, 14, 13, 12, 14, 12, 13, 13, 14, 14, 11, + 11, 13, 14, 14, 14, 14, 16, 15, 15, 16, 15, 15, 16, 16, 16, 13, + 10, 14, 12, 14, 14, 15, 16, 15, 13, 16, 12, 14, 16, 16, 15, 13, + 10, 13, 13, 14, 14, 15, 16, 15, 14, 16, 14, 15, 15, 16, 16, 12, + 10, 13, 14, 13, 14, 14, 16, 15, 14, 16, 15, 15, 14, 16, 16, 13, + 7, 11, 11, 11, 10, 12, 14, 13, 11, 14, 13, 13, 10, 12, 13, 10, + 8, 11, 12, 12, 11, 12, 14, 13, 12, 15, 13, 13, 12, 13, 14, 11, + 11, 13, 14, 14, 14, 14, 16, 15, 14, 16, 15, 16, 16, 16, 16, 14, + 8, 12, 12, 13, 12, 13, 15, 14, 12, 15, 13, 13, 13, 14, 14, 11, + 6, 10, 10, 11, 10, 11, 13, 12, 11, 13, 11, 12, 11, 12, 12, 9, + 9, 12, 13, 13, 13, 13, 14, 13, 13, 15, 14, 14, 14, 14, 14, 12, + 11, 15, 14, 15, 14, 15, 16, 16, 16, 16, 15, 16, 16, 16, 16, 14, + 9, 13, 12, 13, 13, 13, 15, 14, 13, 14, 13, 14, 14, 15, 14, 12, + 9, 12, 12, 12, 12, 13, 14, 13, 13, 14, 13, 13, 13, 13, 14, 11, + 10, 13, 15, 14, 12, 14, 16, 14, 14, 16, 15, 15, 12, 14, 16, 12, + 10, 14, 14, 14, 13, 14, 16, 15, 14, 16, 16, 16, 13, 14, 16, 13, + 11, 13, 14, 14, 14, 13, 16, 14, 14, 16, 15, 15, 15, 15, 16, 13, + 11, 15, 15, 15, 14, 15, 16, 16, 15, 16, 16, 16, 14, 16, 16, 13, + 9, 13, 13, 13, 12, 13, 15, 14, 13, 15, 14, 14, 13, 14, 15, 11, + 9, 12, 12, 13, 12, 12, 14, 13, 13, 14, 13, 14, 14, 14, 14, 11, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, + 11, 14, 14, 15, 15, 14, 16, 16, 14, 16, 14, 15, 15, 16, 16, 12, + 9, 12, 12, 13, 12, 12, 14, 12, 12, 14, 13, 13, 13, 13, 14, 11, + 11, 14, 14, 16, 14, 16, 16, 16, 13, 16, 14, 16, 14, 16, 16, 13, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 15, 14, 16, 14, 15, 16, 16, 15, 16, 14, 15, 16, 16, 16, 13, + 11, 15, 14, 16, 15, 16, 16, 16, 15, 16, 15, 16, 16, 16, 16, 14, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 11, 14, 13, 14, 15, 14, 16, 15, 14, 16, 12, 14, 16, 16, 15, 13, + 11, 14, 14, 16, 14, 15, 16, 16, 15, 16, 14, 15, 16, 16, 16, 14, + 12, 14, 14, 15, 14, 16, 16, 15, 14, 16, 15, 15, 15, 16, 16, 13, + 11, 14, 15, 15, 13, 15, 16, 16, 14, 16, 16, 16, 12, 15, 15, 13, + 11, 15, 16, 16, 15, 16, 16, 16, 15, 16, 16, 16, 14, 16, 16, 14, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, + 11, 15, 14, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, + 10, 13, 13, 14, 14, 14, 16, 15, 14, 16, 14, 15, 14, 14, 15, 12, + 12, 15, 14, 16, 14, 15, 16, 15, 15, 16, 15, 15, 16, 15, 16, 13, + 12, 16, 14, 16, 15, 16, 16, 16, 16, 16, 14, 15, 16, 16, 16, 14, + 10, 13, 13, 14, 14, 13, 16, 14, 13, 16, 13, 14, 15, 15, 15, 12, + 10, 13, 13, 14, 13, 13, 16, 14, 14, 15, 14, 14, 14, 14, 15, 12, + 10, 14, 15, 14, 13, 15, 16, 15, 14, 16, 16, 16, 11, 14, 16, 12, + 11, 14, 14, 16, 14, 15, 16, 15, 15, 16, 16, 16, 13, 15, 16, 13, + 12, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 15, 16, 13, + 12, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 13, + 10, 13, 14, 14, 13, 14, 16, 14, 13, 16, 15, 14, 12, 14, 16, 11, + 10, 13, 13, 14, 13, 14, 16, 14, 14, 15, 14, 14, 13, 14, 14, 11, + 13, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 11, 13, 14, 15, 14, 14, 16, 15, 14, 16, 14, 15, 14, 15, 16, 12, + 8, 11, 11, 11, 11, 12, 13, 12, 11, 13, 11, 12, 11, 12, 12, 9, + }, + }, + { + { + 8, 8, 8, 7, 8, 7, 8, 6, 8, 8, 7, 6, 7, 6, 6, 4, + 11, 10, 11, 9, 11, 9, 11, 8, 11, 10, 10, 9, 10, 8, 9, 6, + 13, 11, 13, 10, 12, 10, 13, 9, 13, 12, 13, 10, 12, 10, 11, 7, + 11, 11, 10, 9, 11, 10, 11, 9, 10, 11, 9, 8, 10, 9, 9, 6, + 12, 12, 11, 9, 12, 11, 12, 9, 12, 12, 11, 9, 11, 10, 10, 7, + 14, 13, 13, 10, 15, 12, 13, 10, 15, 13, 13, 10, 13, 12, 12, 8, + 13, 13, 11, 10, 14, 13, 12, 10, 13, 13, 10, 10, 12, 11, 10, 8, + 15, 14, 13, 10, 14, 13, 13, 10, 14, 13, 12, 10, 13, 12, 11, 8, + 14, 14, 13, 10, 16, 13, 13, 10, 15, 14, 13, 10, 13, 12, 12, 8, + 11, 11, 11, 10, 10, 9, 10, 9, 10, 10, 10, 9, 9, 8, 9, 6, + 12, 12, 12, 11, 11, 9, 12, 9, 12, 12, 11, 10, 11, 9, 10, 7, + 14, 13, 14, 12, 13, 10, 13, 10, 15, 13, 14, 12, 12, 10, 12, 8, + 13, 13, 12, 11, 12, 11, 12, 10, 12, 12, 11, 10, 11, 10, 10, 7, + 14, 13, 13, 11, 13, 12, 12, 10, 13, 13, 12, 11, 12, 10, 10, 7, + 16, 15, 15, 12, 14, 12, 13, 10, 15, 14, 13, 12, 13, 12, 12, 8, + 15, 15, 13, 13, 14, 14, 14, 12, 14, 14, 12, 11, 13, 12, 11, 8, + 15, 16, 14, 12, 15, 14, 13, 11, 15, 15, 13, 12, 13, 12, 11, 8, + 16, 15, 15, 12, 16, 14, 14, 10, 15, 15, 14, 12, 14, 12, 12, 8, + 13, 13, 13, 13, 11, 10, 12, 10, 12, 13, 12, 11, 10, 10, 10, 8, + 14, 13, 14, 13, 12, 10, 13, 10, 14, 14, 13, 12, 12, 10, 11, 8, + 15, 14, 16, 14, 13, 10, 14, 10, 16, 14, 14, 13, 13, 10, 12, 8, + 15, 15, 14, 14, 14, 13, 13, 12, 14, 14, 13, 12, 12, 11, 11, 9, + 15, 15, 15, 14, 14, 12, 14, 11, 15, 14, 13, 13, 13, 11, 11, 8, + 16, 15, 16, 14, 15, 12, 14, 11, 16, 16, 15, 13, 14, 12, 12, 8, + 16, 16, 16, 14, 15, 14, 14, 12, 15, 15, 14, 13, 13, 12, 11, 9, + 16, 16, 15, 15, 16, 14, 14, 11, 16, 16, 14, 13, 14, 12, 12, 8, + 16, 16, 16, 13, 15, 13, 14, 10, 16, 16, 15, 13, 14, 12, 12, 8, + 11, 11, 11, 10, 11, 10, 11, 9, 10, 10, 9, 8, 9, 9, 9, 6, + 12, 12, 13, 11, 12, 11, 12, 10, 12, 12, 11, 10, 11, 10, 10, 7, + 15, 13, 15, 12, 14, 13, 14, 11, 14, 13, 13, 11, 13, 11, 12, 8, + 12, 13, 12, 11, 13, 11, 12, 10, 11, 12, 10, 9, 11, 10, 10, 7, + 14, 13, 13, 11, 14, 12, 13, 11, 12, 12, 11, 10, 12, 11, 10, 7, + 15, 14, 15, 12, 15, 13, 15, 11, 15, 14, 13, 11, 13, 12, 12, 8, + 14, 14, 13, 12, 15, 14, 13, 12, 13, 13, 11, 10, 13, 12, 11, 8, + 16, 15, 13, 12, 15, 14, 14, 12, 14, 14, 12, 11, 14, 12, 11, 8, + 16, 15, 14, 12, 16, 15, 15, 11, 15, 14, 13, 11, 14, 13, 12, 8, + 12, 12, 12, 11, 12, 11, 12, 10, 11, 11, 11, 10, 10, 9, 9, 7, + 13, 13, 14, 12, 13, 11, 13, 11, 13, 12, 12, 11, 11, 10, 10, 7, + 15, 14, 16, 13, 14, 12, 14, 11, 14, 14, 14, 12, 13, 11, 12, 8, + 13, 13, 13, 12, 13, 12, 13, 11, 12, 12, 11, 10, 11, 10, 10, 7, + 14, 14, 13, 12, 13, 12, 13, 10, 13, 13, 11, 10, 12, 10, 10, 7, + 16, 15, 15, 13, 15, 12, 14, 11, 15, 14, 13, 11, 13, 11, 11, 7, + 15, 16, 14, 13, 15, 14, 14, 12, 14, 14, 12, 11, 13, 12, 11, 8, + 16, 15, 14, 13, 15, 14, 14, 11, 14, 14, 12, 11, 13, 12, 11, 7, + 16, 15, 15, 12, 16, 14, 14, 11, 15, 14, 13, 11, 14, 12, 11, 7, + 14, 15, 14, 14, 13, 12, 13, 12, 13, 13, 12, 12, 11, 10, 11, 8, + 15, 15, 15, 14, 13, 12, 14, 12, 14, 14, 13, 12, 12, 11, 11, 8, + 16, 15, 16, 14, 14, 12, 15, 12, 16, 14, 14, 13, 13, 11, 12, 8, + 15, 15, 15, 14, 14, 13, 14, 12, 14, 14, 13, 12, 12, 11, 11, 8, + 15, 15, 15, 14, 14, 13, 14, 12, 14, 14, 13, 12, 12, 11, 11, 7, + 16, 15, 16, 14, 15, 12, 15, 11, 15, 14, 14, 12, 13, 11, 12, 7, + 16, 16, 16, 15, 16, 15, 14, 13, 15, 15, 13, 12, 13, 12, 11, 9, + 16, 16, 16, 14, 15, 14, 14, 12, 15, 15, 13, 12, 14, 12, 11, 8, + 16, 16, 16, 14, 16, 14, 14, 11, 15, 15, 14, 12, 14, 12, 11, 7, + 13, 13, 13, 12, 13, 12, 13, 11, 11, 12, 11, 10, 10, 10, 10, 8, + 15, 14, 14, 13, 14, 13, 14, 12, 13, 13, 12, 11, 13, 11, 11, 8, + 16, 15, 16, 14, 16, 14, 16, 13, 15, 14, 14, 12, 14, 12, 13, 9, + 14, 15, 13, 13, 14, 13, 14, 12, 12, 13, 11, 11, 12, 11, 11, 8, + 15, 15, 14, 13, 15, 14, 14, 12, 13, 13, 12, 11, 13, 12, 11, 8, + 16, 16, 16, 13, 16, 15, 16, 13, 15, 14, 14, 12, 14, 13, 13, 9, + 14, 15, 13, 13, 16, 15, 15, 13, 13, 14, 11, 11, 13, 12, 11, 9, + 16, 16, 14, 13, 16, 15, 16, 13, 14, 14, 12, 11, 14, 13, 12, 8, + 16, 16, 15, 12, 16, 15, 15, 12, 15, 14, 13, 11, 14, 13, 12, 8, + 14, 14, 14, 13, 14, 13, 14, 12, 12, 13, 12, 11, 11, 11, 11, 8, + 15, 15, 15, 14, 14, 13, 15, 12, 14, 13, 13, 12, 12, 11, 11, 8, + 16, 16, 16, 15, 15, 14, 16, 13, 15, 14, 14, 12, 14, 12, 12, 9, + 15, 15, 14, 14, 14, 14, 14, 13, 13, 14, 12, 11, 12, 11, 11, 8, + 15, 15, 15, 13, 15, 14, 14, 12, 13, 13, 12, 11, 12, 11, 11, 7, + 16, 15, 16, 14, 16, 14, 15, 12, 15, 14, 14, 12, 13, 12, 12, 8, + 16, 16, 15, 14, 16, 15, 15, 13, 14, 14, 12, 11, 13, 12, 11, 8, + 16, 16, 15, 13, 16, 14, 14, 12, 14, 15, 12, 11, 13, 12, 11, 7, + 16, 16, 16, 13, 16, 15, 15, 12, 15, 14, 13, 11, 14, 12, 11, 7, + 15, 15, 15, 14, 13, 13, 14, 13, 13, 14, 13, 12, 11, 11, 11, 8, + 16, 16, 16, 14, 15, 13, 15, 12, 14, 14, 14, 13, 12, 11, 12, 8, + 16, 16, 16, 14, 15, 13, 15, 12, 15, 14, 14, 12, 13, 11, 12, 8, + 15, 16, 16, 14, 15, 14, 15, 13, 14, 14, 12, 12, 11, 11, 11, 8, + 16, 15, 15, 14, 15, 14, 14, 12, 14, 14, 13, 12, 12, 11, 11, 7, + 16, 16, 16, 13, 15, 13, 15, 12, 15, 14, 14, 12, 13, 11, 11, 7, + 16, 16, 16, 15, 15, 16, 15, 13, 14, 14, 12, 12, 12, 12, 11, 8, + 16, 16, 16, 14, 16, 14, 14, 12, 15, 15, 13, 11, 12, 11, 10, 7, + 16, 16, 15, 13, 16, 14, 14, 11, 15, 14, 13, 10, 13, 11, 10, 5, + }, + { + 1, 6, 6, 7, 6, 7, 9, 7, 6, 9, 7, 8, 7, 8, 8, 5, + 5, 8, 10, 10, 10, 10, 12, 11, 11, 12, 11, 11, 11, 12, 12, 9, + 9, 10, 12, 11, 13, 12, 15, 13, 14, 15, 15, 14, 14, 15, 15, 12, + 6, 10, 9, 10, 10, 11, 13, 12, 11, 13, 11, 12, 12, 12, 12, 10, + 6, 10, 10, 10, 11, 11, 13, 11, 11, 13, 12, 12, 11, 12, 12, 10, + 9, 12, 13, 12, 13, 13, 16, 13, 14, 16, 15, 14, 14, 15, 16, 12, + 9, 13, 11, 13, 14, 14, 16, 15, 14, 16, 13, 15, 15, 15, 15, 12, + 9, 13, 12, 13, 14, 15, 16, 15, 14, 16, 15, 15, 15, 15, 16, 12, + 8, 12, 12, 11, 13, 14, 15, 13, 13, 15, 14, 14, 14, 14, 14, 12, + 6, 10, 10, 11, 9, 10, 13, 11, 11, 13, 12, 12, 10, 12, 12, 9, + 6, 10, 11, 11, 11, 10, 13, 12, 11, 13, 12, 12, 12, 12, 13, 10, + 9, 12, 13, 13, 13, 12, 16, 13, 14, 16, 14, 15, 16, 14, 15, 12, + 8, 12, 13, 13, 13, 13, 16, 14, 13, 16, 13, 14, 14, 14, 14, 12, + 7, 11, 11, 12, 11, 12, 14, 13, 12, 14, 13, 13, 12, 13, 13, 11, + 9, 12, 13, 13, 13, 13, 15, 14, 14, 16, 16, 15, 15, 15, 16, 12, + 11, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 10, 14, 14, 15, 15, 16, 16, 16, 14, 16, 14, 16, 16, 16, 16, 13, + 9, 13, 13, 13, 14, 14, 16, 14, 14, 16, 15, 14, 14, 16, 16, 13, + 9, 13, 14, 14, 11, 13, 16, 14, 13, 16, 15, 16, 13, 14, 15, 12, + 10, 13, 14, 15, 13, 12, 16, 14, 14, 16, 15, 15, 14, 14, 16, 13, + 9, 12, 13, 14, 12, 11, 15, 13, 13, 15, 13, 14, 15, 14, 16, 12, + 11, 15, 16, 16, 14, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 13, + 11, 14, 14, 15, 13, 14, 16, 15, 15, 16, 16, 16, 16, 16, 16, 13, + 10, 12, 13, 14, 13, 13, 16, 14, 14, 14, 14, 16, 15, 14, 16, 13, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 9, 12, 13, 14, 13, 13, 16, 13, 13, 15, 15, 16, 15, 15, 16, 12, + 6, 11, 11, 12, 10, 12, 13, 12, 11, 13, 11, 12, 11, 12, 13, 10, + 9, 12, 13, 13, 13, 13, 16, 14, 14, 15, 14, 14, 14, 14, 14, 12, + 12, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 7, 11, 11, 12, 12, 12, 14, 13, 12, 14, 11, 13, 13, 13, 13, 11, + 8, 12, 12, 13, 12, 13, 14, 13, 13, 14, 13, 13, 13, 14, 14, 11, + 11, 14, 14, 15, 16, 15, 16, 16, 15, 16, 16, 16, 16, 16, 16, 13, + 10, 14, 12, 14, 15, 15, 16, 16, 14, 16, 12, 15, 16, 16, 16, 13, + 11, 14, 13, 15, 15, 15, 16, 16, 14, 16, 14, 14, 16, 16, 16, 13, + 11, 14, 14, 14, 15, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 13, + 7, 11, 12, 11, 10, 12, 14, 13, 12, 14, 13, 13, 10, 12, 13, 10, + 8, 12, 12, 13, 12, 12, 15, 13, 13, 14, 13, 13, 13, 13, 14, 11, + 11, 13, 15, 16, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, + 9, 12, 13, 13, 13, 13, 15, 14, 13, 15, 13, 14, 13, 14, 14, 12, + 7, 11, 11, 11, 11, 11, 13, 12, 11, 13, 11, 12, 11, 12, 12, 10, + 9, 12, 13, 13, 13, 13, 16, 13, 14, 16, 15, 14, 14, 14, 16, 12, + 12, 14, 14, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 14, + 10, 13, 13, 14, 14, 14, 16, 15, 14, 16, 14, 14, 16, 15, 15, 12, + 9, 12, 13, 13, 13, 15, 16, 14, 13, 16, 14, 13, 13, 14, 14, 11, + 10, 14, 15, 14, 12, 14, 16, 15, 13, 16, 16, 16, 12, 14, 16, 12, + 11, 14, 14, 14, 14, 14, 16, 15, 15, 16, 16, 16, 14, 15, 16, 13, + 11, 14, 14, 16, 14, 13, 16, 15, 14, 16, 15, 16, 15, 15, 16, 13, + 12, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 14, + 10, 13, 14, 14, 13, 14, 16, 14, 13, 16, 15, 15, 13, 14, 14, 12, + 9, 12, 13, 14, 13, 12, 16, 14, 13, 16, 14, 14, 14, 14, 15, 12, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, + 9, 12, 13, 13, 13, 13, 14, 13, 12, 15, 14, 14, 14, 14, 14, 11, + 11, 14, 14, 16, 14, 16, 16, 16, 13, 16, 14, 16, 14, 16, 16, 13, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 14, 14, 16, 16, 15, 16, 16, 15, 16, 14, 16, 16, 16, 16, 14, + 12, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 10, 14, 12, 15, 15, 15, 16, 16, 14, 16, 12, 14, 16, 16, 15, 14, + 12, 15, 14, 16, 16, 16, 16, 16, 15, 16, 14, 16, 16, 16, 16, 14, + 12, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 14, + 11, 15, 15, 16, 14, 16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 13, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 11, 15, 14, 16, 14, 14, 16, 15, 14, 16, 15, 16, 15, 16, 16, 12, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, + 12, 16, 15, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 14, + 10, 14, 13, 14, 15, 14, 16, 15, 14, 16, 13, 16, 16, 16, 15, 13, + 10, 14, 14, 14, 13, 14, 16, 15, 15, 16, 14, 14, 14, 16, 16, 12, + 10, 14, 15, 14, 13, 16, 16, 15, 13, 16, 16, 16, 12, 14, 16, 12, + 11, 16, 16, 16, 14, 15, 16, 16, 16, 16, 16, 16, 14, 16, 16, 13, + 12, 15, 14, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 14, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 14, + 11, 14, 14, 14, 14, 15, 16, 14, 14, 16, 16, 16, 13, 15, 15, 12, + 10, 14, 13, 14, 14, 14, 16, 15, 14, 16, 15, 15, 14, 14, 16, 12, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 12, 14, 14, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 13, + 8, 11, 11, 12, 12, 12, 13, 12, 11, 13, 12, 12, 12, 13, 12, 10, + }, + }, + { + { + 5, 6, 6, 6, 6, 6, 7, 6, 6, 7, 6, 6, 6, 6, 6, 4, + 9, 9, 9, 8, 9, 8, 10, 8, 10, 10, 9, 9, 9, 8, 9, 6, + 11, 10, 12, 10, 11, 10, 12, 9, 12, 11, 11, 10, 11, 10, 11, 8, + 9, 10, 9, 8, 10, 10, 10, 9, 9, 10, 8, 8, 9, 9, 8, 7, + 10, 11, 10, 9, 11, 11, 11, 9, 11, 11, 10, 9, 10, 10, 10, 7, + 13, 12, 12, 10, 13, 12, 13, 10, 13, 12, 12, 11, 13, 12, 11, 9, + 11, 12, 10, 10, 12, 12, 11, 10, 11, 12, 10, 10, 11, 11, 10, 8, + 12, 12, 11, 10, 13, 13, 13, 10, 13, 13, 12, 11, 13, 12, 11, 9, + 12, 12, 12, 10, 13, 13, 13, 10, 13, 13, 12, 10, 13, 12, 12, 9, + 9, 9, 10, 10, 9, 8, 10, 9, 9, 10, 9, 9, 8, 8, 9, 6, + 10, 11, 11, 11, 10, 9, 11, 9, 11, 11, 11, 10, 10, 9, 10, 7, + 12, 12, 13, 12, 12, 10, 13, 10, 13, 13, 13, 12, 12, 11, 11, 9, + 11, 12, 11, 11, 11, 11, 11, 10, 11, 12, 10, 10, 10, 10, 10, 8, + 12, 12, 12, 11, 12, 11, 11, 10, 12, 12, 11, 11, 11, 11, 10, 8, + 14, 13, 13, 12, 13, 12, 13, 10, 14, 14, 13, 12, 13, 12, 12, 9, + 13, 14, 13, 12, 13, 13, 13, 12, 13, 13, 12, 12, 12, 12, 11, 9, + 14, 14, 13, 12, 13, 13, 13, 11, 14, 14, 13, 12, 13, 12, 12, 9, + 14, 15, 14, 12, 15, 13, 13, 11, 15, 14, 14, 12, 14, 13, 12, 9, + 11, 11, 12, 12, 10, 10, 12, 11, 11, 12, 11, 11, 10, 10, 10, 8, + 12, 12, 14, 13, 11, 10, 12, 11, 13, 13, 13, 12, 12, 10, 11, 9, + 13, 13, 14, 14, 12, 10, 13, 11, 14, 14, 14, 13, 12, 11, 12, 9, + 13, 13, 13, 13, 12, 13, 13, 12, 13, 14, 12, 12, 12, 12, 11, 9, + 13, 14, 14, 13, 13, 12, 13, 11, 14, 14, 13, 12, 13, 12, 12, 9, + 14, 14, 14, 14, 14, 12, 13, 11, 15, 15, 15, 13, 14, 12, 12, 9, + 14, 15, 15, 13, 14, 14, 13, 12, 13, 14, 13, 13, 12, 12, 11, 10, + 16, 16, 15, 14, 15, 14, 13, 11, 15, 15, 14, 13, 13, 13, 12, 9, + 15, 15, 15, 13, 14, 13, 13, 11, 15, 15, 15, 13, 14, 13, 12, 9, + 8, 9, 9, 9, 9, 9, 10, 9, 8, 10, 9, 9, 8, 8, 9, 7, + 11, 11, 11, 11, 11, 11, 12, 10, 11, 11, 11, 10, 10, 10, 10, 8, + 13, 13, 14, 12, 13, 12, 14, 11, 13, 13, 13, 12, 13, 11, 12, 9, + 10, 11, 10, 11, 11, 11, 12, 10, 10, 11, 10, 10, 10, 10, 10, 8, + 12, 12, 12, 11, 12, 12, 12, 11, 11, 12, 11, 10, 11, 11, 10, 8, + 14, 13, 14, 12, 14, 13, 14, 12, 14, 13, 13, 11, 13, 12, 12, 9, + 12, 13, 12, 12, 13, 13, 13, 12, 12, 13, 11, 11, 12, 12, 11, 9, + 13, 14, 13, 12, 14, 14, 14, 12, 14, 13, 12, 11, 13, 12, 12, 9, + 14, 14, 13, 12, 15, 14, 15, 12, 14, 14, 13, 11, 13, 13, 12, 9, + 10, 11, 11, 11, 10, 10, 12, 10, 10, 11, 10, 10, 9, 9, 10, 7, + 12, 12, 13, 12, 12, 11, 12, 11, 12, 12, 12, 11, 11, 10, 10, 8, + 14, 13, 14, 13, 14, 12, 13, 12, 14, 13, 14, 12, 13, 11, 12, 9, + 12, 13, 12, 12, 12, 12, 12, 11, 11, 12, 11, 10, 10, 10, 10, 8, + 12, 12, 12, 12, 12, 12, 12, 11, 12, 12, 11, 10, 11, 10, 10, 7, + 14, 14, 14, 12, 14, 12, 14, 11, 14, 13, 13, 11, 13, 11, 11, 8, + 13, 15, 13, 13, 14, 14, 14, 12, 13, 14, 12, 12, 12, 12, 11, 9, + 14, 15, 13, 12, 14, 13, 13, 11, 13, 13, 12, 11, 13, 12, 11, 8, + 15, 15, 15, 12, 15, 14, 14, 11, 14, 14, 13, 11, 13, 12, 12, 8, + 12, 13, 13, 13, 12, 12, 13, 12, 12, 13, 12, 12, 11, 11, 11, 9, + 13, 14, 15, 14, 13, 12, 14, 12, 13, 13, 14, 12, 12, 11, 12, 9, + 14, 14, 15, 14, 14, 12, 14, 12, 14, 14, 14, 13, 13, 11, 12, 9, + 13, 14, 14, 14, 13, 13, 14, 13, 13, 13, 12, 12, 12, 12, 11, 9, + 14, 14, 14, 13, 13, 13, 13, 12, 13, 14, 13, 12, 12, 11, 11, 8, + 15, 14, 15, 14, 14, 13, 14, 11, 15, 14, 14, 12, 13, 11, 12, 8, + 14, 15, 14, 14, 15, 14, 14, 13, 14, 15, 13, 13, 12, 12, 11, 10, + 16, 15, 14, 14, 14, 14, 13, 12, 14, 14, 13, 12, 13, 12, 11, 9, + 15, 15, 15, 14, 16, 14, 14, 11, 15, 15, 14, 12, 13, 12, 11, 8, + 11, 12, 11, 12, 12, 12, 12, 11, 10, 11, 10, 10, 10, 10, 10, 8, + 13, 13, 13, 13, 13, 13, 14, 12, 12, 12, 12, 12, 12, 11, 12, 9, + 14, 14, 14, 13, 15, 13, 15, 13, 14, 14, 14, 12, 14, 12, 13, 10, + 12, 13, 12, 13, 13, 13, 13, 12, 11, 12, 11, 11, 12, 11, 11, 9, + 14, 14, 13, 13, 14, 14, 14, 12, 12, 13, 12, 11, 13, 12, 12, 9, + 14, 14, 15, 13, 15, 15, 15, 13, 15, 13, 13, 12, 14, 12, 13, 10, + 13, 15, 12, 13, 14, 14, 14, 13, 12, 13, 11, 11, 13, 12, 11, 10, + 14, 15, 14, 13, 15, 14, 15, 13, 14, 14, 12, 11, 13, 13, 12, 9, + 14, 15, 14, 13, 15, 14, 15, 13, 14, 14, 13, 11, 14, 13, 12, 9, + 12, 13, 13, 13, 12, 13, 13, 12, 11, 12, 12, 11, 11, 11, 11, 9, + 13, 14, 14, 13, 14, 13, 14, 12, 13, 13, 13, 12, 12, 11, 11, 9, + 15, 15, 16, 14, 15, 14, 14, 13, 15, 14, 14, 13, 13, 12, 13, 10, + 13, 14, 14, 13, 13, 14, 14, 13, 12, 13, 12, 12, 11, 11, 11, 9, + 14, 14, 14, 13, 14, 13, 14, 12, 13, 13, 12, 11, 12, 11, 11, 8, + 15, 15, 15, 13, 15, 14, 14, 12, 14, 13, 13, 12, 13, 12, 12, 9, + 14, 15, 14, 14, 15, 15, 14, 13, 13, 14, 12, 12, 13, 12, 12, 9, + 15, 15, 14, 13, 15, 14, 14, 13, 14, 14, 12, 11, 13, 12, 11, 8, + 15, 16, 14, 13, 15, 15, 15, 12, 14, 14, 13, 11, 14, 12, 12, 8, + 12, 14, 13, 13, 13, 13, 14, 12, 12, 13, 12, 12, 10, 11, 11, 9, + 14, 15, 15, 14, 13, 13, 15, 13, 13, 14, 14, 12, 12, 11, 12, 9, + 15, 15, 16, 14, 14, 13, 15, 13, 14, 14, 14, 13, 13, 11, 12, 9, + 14, 15, 14, 14, 14, 14, 14, 13, 13, 14, 13, 12, 12, 12, 11, 9, + 14, 15, 15, 14, 14, 14, 14, 12, 13, 14, 13, 12, 12, 11, 11, 8, + 15, 15, 15, 14, 14, 13, 15, 12, 15, 14, 14, 12, 13, 11, 11, 8, + 14, 16, 14, 14, 14, 15, 14, 13, 13, 14, 12, 12, 12, 12, 11, 9, + 15, 15, 15, 14, 15, 14, 14, 12, 14, 14, 13, 12, 12, 11, 11, 8, + 15, 15, 14, 13, 15, 13, 14, 12, 14, 14, 13, 11, 13, 11, 11, 7, + }, + { + 1, 5, 6, 7, 6, 7, 9, 8, 6, 9, 8, 8, 7, 8, 8, 6, + 5, 8, 10, 10, 10, 11, 13, 12, 11, 13, 12, 12, 12, 12, 13, 10, + 8, 10, 13, 12, 13, 13, 16, 14, 14, 16, 16, 14, 16, 16, 16, 12, + 5, 10, 9, 11, 11, 12, 13, 12, 11, 13, 11, 12, 12, 12, 13, 10, + 6, 10, 11, 11, 11, 12, 14, 12, 11, 13, 13, 13, 12, 13, 13, 11, + 8, 12, 13, 12, 14, 14, 16, 14, 14, 16, 16, 16, 16, 16, 16, 13, + 9, 13, 11, 14, 14, 16, 16, 16, 14, 16, 14, 16, 16, 16, 16, 13, + 9, 13, 13, 13, 14, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 14, + 8, 12, 13, 12, 13, 14, 16, 14, 14, 16, 16, 16, 14, 16, 16, 13, + 5, 10, 11, 12, 9, 11, 13, 12, 11, 13, 13, 13, 11, 12, 13, 10, + 6, 10, 11, 12, 11, 11, 14, 13, 12, 14, 12, 13, 13, 13, 13, 11, + 9, 12, 14, 15, 13, 13, 16, 16, 14, 16, 16, 16, 16, 16, 16, 13, + 8, 13, 13, 14, 13, 14, 16, 16, 14, 16, 14, 16, 14, 16, 14, 13, + 7, 11, 12, 13, 12, 12, 14, 13, 12, 14, 13, 14, 13, 14, 14, 12, + 9, 13, 14, 14, 14, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, + 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 15, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 9, 13, 14, 14, 14, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 14, + 9, 13, 14, 15, 11, 13, 16, 14, 14, 16, 16, 16, 13, 14, 16, 13, + 9, 13, 14, 16, 13, 13, 16, 16, 14, 16, 16, 16, 16, 15, 16, 14, + 8, 12, 13, 16, 13, 12, 16, 14, 13, 16, 14, 16, 16, 16, 16, 13, + 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 14, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 9, 13, 16, 16, 14, 14, 16, 16, 14, 16, 16, 16, 16, 16, 16, 14, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 9, 13, 14, 15, 14, 14, 16, 14, 13, 16, 16, 16, 14, 16, 16, 14, + 6, 11, 11, 12, 11, 12, 14, 13, 11, 14, 12, 13, 12, 13, 13, 11, + 9, 13, 13, 14, 13, 14, 16, 16, 14, 16, 16, 16, 15, 16, 16, 13, + 11, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 7, 11, 11, 13, 12, 13, 16, 14, 12, 16, 12, 14, 14, 14, 14, 12, + 8, 12, 12, 13, 12, 14, 16, 14, 13, 16, 14, 14, 14, 14, 14, 12, + 11, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 10, 14, 13, 16, 16, 16, 16, 16, 14, 16, 14, 16, 16, 16, 16, 16, + 10, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 10, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 7, 11, 12, 12, 11, 13, 16, 14, 12, 15, 14, 14, 11, 13, 13, 12, + 8, 12, 12, 13, 13, 13, 16, 14, 13, 16, 13, 15, 13, 14, 14, 12, + 11, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 8, 12, 13, 14, 13, 14, 16, 16, 14, 16, 14, 16, 14, 16, 15, 13, + 6, 11, 11, 12, 11, 12, 13, 13, 11, 13, 12, 13, 12, 13, 13, 11, + 9, 13, 14, 14, 14, 14, 16, 14, 14, 16, 16, 16, 16, 16, 14, 13, + 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 14, 13, 14, 14, 16, 16, 16, 14, 16, 14, 16, 16, 16, 16, 13, + 9, 13, 14, 13, 13, 16, 16, 14, 13, 16, 16, 16, 13, 16, 14, 13, + 10, 14, 14, 16, 13, 16, 16, 16, 16, 16, 16, 16, 13, 14, 16, 14, + 11, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 10, 14, 16, 16, 14, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 14, 14, 14, 14, 16, 16, 16, 14, 16, 16, 16, 14, 16, 16, 13, + 9, 13, 13, 16, 14, 14, 16, 16, 14, 16, 14, 16, 16, 16, 16, 13, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 9, 13, 14, 14, 13, 16, 16, 14, 13, 16, 14, 16, 14, 14, 16, 12, + 10, 14, 14, 16, 16, 16, 16, 16, 13, 16, 16, 16, 14, 16, 16, 14, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 14, 13, 16, 16, 16, 16, 16, 14, 16, 12, 16, 16, 16, 16, 14, + 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 16, + 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 14, 16, 16, 14, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, + 11, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 13, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 15, 14, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 14, + 10, 14, 14, 14, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, + 10, 14, 16, 16, 13, 16, 16, 16, 14, 16, 16, 16, 12, 16, 16, 14, + 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, + 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 15, 14, 16, 14, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 13, + 10, 15, 14, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 14, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 8, 12, 12, 13, 12, 14, 14, 14, 12, 16, 13, 14, 12, 14, 14, 11, + }, + }, +}; + + +static const uint8_t rv34_table_intra_cbp[NUM_INTRA_TABLES][8][CBP_VLC_SIZE] = { + { + { 0, 3, 3, 4, 3, 5, 5, 5, 2, 5, 4, 6, 4, 6, 6, 6, }, + { 0, 2, 3, 4, 2, 5, 6, 7, 3, 6, 5, 7, 4, 7, 8, 8, }, + { 0, 3, 4, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 3, }, + { 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 6, 3, 5, 6, 5, }, + { 0, 4, 4, 4, 4, 5, 5, 4, 4, 5, 4, 5, 4, 4, 4, 2, }, + { 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, }, + { 0, 6, 6, 5, 6, 5, 6, 4, 6, 6, 5, 4, 4, 4, 4, 1, }, + { 0, 4, 4, 4, 4, 5, 5, 4, 4, 5, 5, 4, 4, 4, 4, 2, }, + }, + { + { 0, 4, 3, 4, 3, 4, 5, 4, 3, 5, 4, 5, 3, 5, 5, 5, }, + { 0, 2, 3, 4, 2, 5, 6, 7, 3, 6, 5, 7, 4, 7, 8, 8, }, + { 0, 4, 4, 4, 4, 4, 5, 4, 4, 5, 4, 4, 3, 4, 4, 3, }, + { 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 6, 3, 5, 6, 5, }, + { 0, 4, 4, 4, 4, 4, 5, 4, 4, 5, 5, 5, 4, 4, 4, 2, }, + { 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, }, + { 0, 5, 6, 5, 5, 5, 6, 4, 6, 6, 5, 4, 5, 4, 4, 1, }, + { 0, 4, 4, 4, 4, 4, 5, 4, 4, 5, 5, 4, 4, 4, 5, 2, }, + }, + { + { 0, 3, 3, 4, 3, 4, 4, 5, 3, 5, 4, 5, 4, 5, 5, 5, }, + { 0, 2, 3, 4, 2, 4, 6, 7, 3, 6, 5, 7, 5, 7, 8, 8, }, + { 0, 4, 4, 4, 4, 4, 5, 4, 3, 5, 4, 4, 4, 4, 4, 3, }, + { 0, 3, 3, 4, 3, 3, 6, 6, 3, 6, 4, 6, 3, 6, 6, 5, }, + { 0, 4, 4, 4, 3, 4, 5, 4, 4, 5, 4, 4, 4, 4, 4, 3, }, + { 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, }, + { 0, 5, 5, 5, 5, 5, 6, 4, 5, 6, 5, 5, 5, 4, 4, 1, }, + { 0, 4, 4, 4, 4, 4, 6, 4, 4, 6, 5, 4, 4, 4, 4, 2, }, + }, + { + { 0, 3, 3, 4, 3, 4, 4, 5, 3, 5, 4, 5, 4, 5, 5, 5, }, + { 0, 2, 3, 4, 2, 4, 7, 6, 3, 7, 5, 7, 5, 7, 7, 7, }, + { 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, }, + { 0, 3, 3, 3, 3, 4, 6, 6, 3, 6, 4, 6, 3, 6, 6, 5, }, + { 0, 3, 4, 4, 3, 4, 5, 4, 4, 5, 4, 5, 4, 5, 4, 3, }, + { 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, }, + { 0, 4, 5, 4, 4, 4, 5, 4, 4, 5, 5, 4, 4, 4, 4, 2, }, + { 0, 4, 4, 4, 4, 5, 5, 4, 4, 5, 5, 4, 4, 4, 4, 2, }, + }, + { + { 0, 3, 3, 4, 3, 4, 5, 6, 2, 5, 4, 7, 4, 6, 6, 7, }, + { 0, 2, 3, 4, 2, 4, 6, 7, 3, 7, 5, 7, 5, 7, 7, 7, }, + { 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, }, + { 0, 2, 3, 4, 3, 4, 6, 5, 3, 6, 4, 6, 4, 6, 6, 6, }, + { 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, }, + { 0, 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, }, + { 0, 4, 4, 4, 4, 5, 5, 4, 4, 5, 5, 4, 4, 4, 4, 2, }, + { 0, 3, 4, 4, 4, 4, 5, 4, 4, 5, 4, 4, 4, 4, 4, 3, }, + }, +}; + + +static const uint8_t rv34_table_intra_firstpat[NUM_INTRA_TABLES][4][FIRSTBLK_VLC_SIZE] = { + { + { + 0, 10, 5, 10, 7, 12, 9, 11, 8, 13, 9, 12, 10, 13, 11, 12, + 16, 16, 14, 15, 15, 16, 13, 14, 5, 12, 6, 11, 9, 13, 10, 11, + 9, 14, 9, 12, 11, 14, 11, 12, 16, 16, 14, 15, 15, 16, 13, 13, + 10, 15, 9, 12, 12, 16, 11, 12, 12, 16, 10, 13, 13, 16, 11, 12, + 16, 16, 13, 14, 15, 16, 13, 12, 6, 12, 8, 11, 8, 12, 10, 11, + 9, 14, 10, 12, 10, 13, 11, 12, 15, 16, 14, 15, 14, 16, 13, 13, + 8, 13, 9, 12, 10, 13, 10, 12, 10, 14, 9, 12, 11, 14, 10, 12, + 15, 16, 13, 15, 14, 16, 13, 13, 11, 16, 10, 13, 13, 16, 11, 12, + 12, 16, 11, 13, 13, 16, 11, 12, 16, 16, 13, 14, 15, 16, 12, 12, + 10, 16, 12, 14, 10, 14, 11, 12, 12, 16, 13, 14, 11, 14, 12, 12, + 16, 16, 15, 16, 14, 15, 13, 13, 11, 16, 12, 14, 11, 14, 11, 12, + 12, 16, 12, 14, 11, 14, 11, 12, 16, 16, 14, 15, 13, 15, 13, 12, + 14, 16, 13, 14, 13, 16, 12, 12, 14, 16, 13, 14, 13, 16, 12, 12, + 16, 16, 14, 14, 14, 15, 12, 11, 2, 10, 6, 10, 7, 12, 9, 11, + 8, 12, 9, 11, 10, 13, 10, 11, 15, 16, 14, 15, 14, 16, 13, 13, + 5, 12, 6, 11, 9, 13, 10, 11, 9, 13, 9, 11, 10, 13, 10, 11, + 15, 16, 13, 14, 14, 16, 13, 13, 9, 15, 8, 12, 12, 15, 11, 11, + 11, 16, 10, 12, 13, 15, 11, 11, 15, 16, 13, 14, 15, 16, 12, 12, + 6, 12, 8, 11, 8, 12, 9, 11, 9, 14, 9, 12, 10, 13, 10, 11, + 15, 16, 14, 15, 14, 16, 13, 13, 7, 13, 8, 11, 9, 13, 10, 11, + 9, 14, 9, 12, 10, 13, 10, 11, 14, 16, 13, 14, 13, 16, 12, 12, + 11, 16, 10, 12, 12, 15, 11, 11, 11, 16, 10, 12, 12, 15, 11, 11, + 15, 16, 12, 13, 14, 16, 12, 11, 9, 15, 11, 13, 9, 13, 11, 12, + 11, 16, 12, 14, 10, 14, 11, 12, 16, 16, 14, 15, 13, 15, 12, 12, + 11, 16, 11, 14, 10, 14, 11, 12, 11, 16, 12, 13, 11, 14, 11, 11, + 15, 16, 14, 15, 13, 14, 12, 12, 13, 16, 12, 14, 13, 15, 11, 11, + 13, 16, 12, 14, 13, 15, 11, 11, 16, 16, 13, 14, 13, 15, 11, 10, + 5, 12, 7, 11, 8, 13, 10, 11, 9, 13, 9, 12, 10, 14, 11, 12, + 16, 16, 14, 15, 14, 16, 13, 13, 7, 13, 7, 11, 9, 13, 10, 11, + 9, 14, 9, 12, 11, 14, 11, 12, 16, 16, 14, 14, 14, 16, 13, 13, + 9, 15, 8, 12, 12, 15, 11, 12, 11, 16, 10, 12, 13, 16, 11, 12, + 16, 16, 13, 14, 15, 16, 12, 12, 7, 13, 8, 12, 9, 13, 10, 11, + 10, 14, 10, 12, 10, 14, 11, 12, 16, 16, 14, 15, 14, 16, 13, 13, + 8, 14, 9, 12, 10, 13, 10, 11, 9, 14, 9, 12, 10, 14, 10, 11, + 15, 16, 13, 14, 14, 16, 12, 12, 11, 16, 10, 12, 12, 15, 11, 12, + 11, 16, 10, 12, 12, 15, 11, 11, 15, 16, 12, 14, 14, 16, 12, 11, + 10, 16, 11, 13, 9, 14, 11, 12, 12, 16, 12, 14, 11, 14, 11, 12, + 16, 16, 14, 16, 14, 15, 13, 12, 11, 16, 11, 14, 10, 14, 11, 12, + 11, 16, 12, 14, 11, 14, 11, 11, 15, 16, 14, 15, 13, 15, 12, 12, + 13, 16, 12, 14, 13, 15, 11, 11, 13, 16, 12, 14, 12, 14, 11, 11, + 15, 16, 12, 13, 13, 14, 11, 10, 6, 13, 8, 11, 9, 13, 10, 11, + 10, 14, 10, 12, 10, 13, 10, 11, 15, 16, 13, 13, 13, 14, 12, 11, + 7, 13, 8, 11, 9, 13, 9, 11, 10, 14, 9, 11, 10, 13, 10, 11, + 15, 16, 13, 13, 13, 14, 11, 11, 9, 14, 8, 11, 10, 13, 9, 10, + 11, 15, 9, 11, 11, 13, 9, 10, 15, 16, 12, 13, 13, 14, 10, 9, + 7, 13, 8, 11, 9, 13, 9, 11, 10, 14, 10, 12, 10, 13, 10, 11, + 15, 16, 13, 13, 13, 14, 11, 11, 8, 13, 8, 11, 9, 13, 9, 10, + 9, 14, 9, 11, 10, 13, 9, 10, 14, 16, 12, 13, 13, 14, 11, 10, + 9, 14, 8, 11, 10, 13, 9, 9, 10, 14, 8, 11, 10, 13, 9, 9, + 14, 16, 11, 12, 12, 14, 10, 9, 9, 14, 9, 12, 8, 12, 9, 10, + 11, 15, 10, 12, 10, 13, 9, 10, 15, 16, 13, 13, 12, 13, 11, 10, + 9, 14, 9, 12, 9, 12, 9, 10, 10, 14, 10, 12, 9, 12, 9, 9, + 14, 16, 12, 13, 11, 13, 10, 9, 10, 14, 9, 11, 10, 12, 8, 8, + 10, 14, 9, 11, 10, 12, 8, 8, 12, 14, 9, 10, 10, 11, 8, 7, + }, + { + 0, 9, 6, 9, 6, 10, 8, 9, 7, 11, 8, 11, 9, 11, 9, 10, + 14, 16, 13, 14, 13, 14, 12, 11, 5, 11, 7, 10, 8, 10, 8, 9, + 8, 12, 8, 11, 9, 12, 9, 10, 14, 16, 12, 13, 13, 14, 11, 11, + 10, 14, 9, 11, 11, 13, 10, 10, 11, 15, 9, 11, 12, 13, 10, 10, + 15, 16, 12, 12, 13, 14, 11, 9, 6, 11, 7, 10, 7, 10, 8, 9, + 8, 12, 9, 11, 9, 11, 9, 10, 14, 16, 13, 13, 13, 14, 11, 11, + 7, 12, 8, 11, 8, 11, 9, 9, 9, 13, 9, 11, 9, 12, 9, 10, + 14, 16, 12, 13, 12, 14, 11, 10, 11, 14, 10, 12, 11, 13, 10, 10, + 12, 15, 10, 12, 12, 13, 10, 10, 15, 16, 12, 12, 13, 14, 10, 9, + 10, 14, 11, 13, 9, 12, 10, 10, 11, 15, 12, 13, 10, 12, 10, 10, + 14, 16, 13, 14, 12, 13, 11, 10, 11, 14, 11, 13, 10, 12, 10, 10, + 12, 15, 11, 13, 10, 12, 10, 10, 15, 16, 13, 13, 12, 13, 11, 9, + 13, 16, 12, 13, 12, 13, 10, 9, 14, 16, 12, 13, 12, 13, 10, 9, + 16, 16, 12, 12, 13, 13, 10, 7, 4, 10, 6, 9, 7, 10, 8, 9, + 8, 12, 9, 11, 9, 11, 9, 9, 14, 16, 13, 13, 13, 14, 11, 11, + 6, 11, 7, 10, 8, 11, 8, 9, 9, 12, 9, 11, 9, 12, 9, 9, + 14, 16, 12, 13, 13, 14, 11, 10, 10, 14, 9, 11, 11, 13, 9, 9, + 11, 14, 9, 11, 11, 13, 10, 9, 14, 16, 11, 12, 13, 14, 10, 9, + 6, 11, 8, 10, 7, 10, 8, 9, 9, 12, 9, 11, 9, 11, 9, 9, + 14, 16, 13, 13, 12, 13, 11, 10, 8, 12, 8, 10, 8, 11, 9, 9, + 9, 12, 9, 11, 9, 11, 9, 9, 14, 16, 12, 13, 12, 13, 11, 10, + 11, 14, 10, 11, 11, 13, 9, 9, 11, 14, 10, 11, 11, 13, 9, 9, + 14, 16, 11, 12, 13, 14, 10, 8, 10, 14, 11, 12, 9, 12, 10, 10, + 11, 14, 11, 13, 10, 12, 10, 10, 14, 16, 13, 14, 12, 13, 11, 9, + 11, 14, 11, 12, 10, 12, 10, 10, 11, 14, 11, 12, 10, 12, 10, 9, + 14, 16, 13, 13, 11, 12, 10, 9, 13, 16, 12, 13, 12, 13, 10, 9, + 13, 16, 11, 12, 11, 13, 10, 8, 15, 16, 12, 12, 12, 12, 9, 7, + 8, 12, 8, 11, 9, 12, 9, 10, 10, 14, 10, 12, 11, 13, 10, 10, + 16, 16, 14, 14, 14, 14, 12, 11, 8, 13, 8, 11, 9, 12, 10, 10, + 11, 14, 10, 12, 11, 13, 10, 10, 16, 16, 13, 14, 14, 14, 12, 11, + 11, 14, 9, 12, 11, 13, 10, 10, 12, 15, 10, 12, 12, 14, 10, 10, + 15, 16, 12, 12, 14, 14, 11, 9, 9, 13, 9, 11, 9, 12, 10, 10, + 11, 14, 10, 12, 10, 12, 10, 10, 15, 16, 14, 14, 13, 14, 12, 11, + 9, 13, 9, 11, 10, 12, 10, 10, 10, 14, 10, 12, 10, 12, 10, 10, + 15, 16, 13, 13, 13, 14, 11, 10, 11, 15, 10, 12, 11, 13, 10, 10, + 11, 15, 10, 12, 12, 13, 10, 9, 15, 16, 11, 12, 13, 14, 10, 9, + 11, 15, 11, 13, 10, 12, 10, 10, 12, 16, 12, 13, 11, 13, 10, 10, + 16, 16, 14, 14, 12, 13, 11, 9, 11, 15, 11, 13, 10, 13, 10, 10, + 12, 15, 12, 13, 10, 12, 10, 10, 14, 16, 13, 13, 12, 13, 10, 9, + 13, 16, 12, 13, 12, 13, 10, 9, 13, 16, 11, 12, 11, 13, 10, 9, + 14, 16, 11, 12, 12, 12, 9, 7, 10, 15, 10, 12, 11, 13, 10, 10, + 12, 16, 12, 13, 12, 13, 11, 10, 16, 16, 14, 14, 14, 15, 12, 10, + 10, 14, 10, 12, 10, 13, 10, 10, 12, 15, 11, 12, 11, 13, 10, 10, + 16, 16, 14, 13, 14, 14, 11, 9, 11, 14, 10, 11, 11, 12, 9, 9, + 12, 15, 10, 11, 11, 13, 9, 8, 16, 16, 12, 12, 13, 13, 10, 7, + 10, 15, 10, 12, 10, 13, 10, 10, 12, 15, 11, 12, 11, 13, 10, 10, + 16, 16, 14, 13, 14, 14, 11, 9, 10, 14, 10, 12, 10, 12, 10, 10, + 12, 15, 11, 12, 11, 13, 10, 10, 16, 16, 13, 13, 13, 14, 11, 9, + 11, 14, 10, 11, 10, 12, 9, 8, 11, 14, 9, 11, 11, 12, 9, 8, + 14, 16, 10, 11, 12, 13, 9, 7, 11, 15, 11, 12, 10, 12, 10, 9, + 13, 16, 11, 12, 11, 12, 10, 9, 16, 16, 13, 13, 12, 13, 10, 7, + 11, 15, 10, 12, 10, 12, 9, 8, 12, 15, 11, 12, 10, 12, 9, 8, + 14, 16, 12, 12, 11, 12, 9, 7, 11, 14, 10, 11, 10, 12, 8, 7, + 11, 14, 9, 10, 10, 11, 8, 6, 12, 15, 9, 9, 9, 10, 7, 4, + }, + { + 0, 6, 3, 7, 3, 7, 6, 7, 5, 9, 6, 9, 7, 9, 8, 8, + 16, 16, 16, 16, 16, 16, 16, 11, 3, 8, 5, 8, 6, 8, 7, 7, + 7, 11, 7, 10, 8, 10, 8, 9, 16, 16, 16, 16, 16, 16, 14, 10, + 8, 16, 7, 11, 10, 16, 9, 9, 11, 16, 9, 14, 16, 16, 10, 9, + 16, 16, 16, 16, 16, 16, 16, 10, 3, 8, 5, 8, 5, 8, 7, 7, + 7, 11, 8, 10, 8, 10, 8, 9, 16, 16, 16, 16, 16, 16, 16, 11, + 6, 10, 7, 9, 7, 10, 8, 8, 8, 11, 8, 10, 8, 11, 8, 8, + 16, 16, 16, 16, 16, 16, 11, 10, 10, 16, 9, 13, 11, 16, 10, 9, + 11, 16, 9, 11, 16, 16, 10, 9, 16, 16, 11, 16, 16, 16, 11, 9, + 9, 16, 10, 11, 8, 11, 9, 9, 11, 16, 12, 16, 10, 16, 10, 10, + 16, 16, 16, 16, 16, 16, 16, 10, 10, 16, 11, 16, 10, 16, 10, 10, + 11, 16, 11, 16, 10, 16, 10, 9, 16, 16, 16, 16, 16, 16, 11, 9, + 16, 16, 16, 16, 16, 16, 11, 9, 16, 16, 16, 16, 16, 16, 11, 9, + 16, 16, 11, 16, 16, 16, 9, 7, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + { + 2, 8, 5, 9, 6, 9, 8, 8, 8, 12, 9, 11, 9, 11, 10, 10, + 16, 16, 14, 16, 14, 16, 14, 12, 5, 10, 6, 9, 8, 10, 8, 9, + 9, 12, 9, 11, 10, 12, 10, 10, 16, 16, 14, 15, 15, 16, 13, 12, + 10, 13, 9, 12, 11, 12, 10, 10, 12, 15, 11, 12, 12, 13, 11, 10, + 16, 16, 15, 14, 15, 16, 13, 12, 6, 10, 8, 10, 7, 10, 8, 9, + 9, 13, 10, 11, 10, 12, 10, 10, 16, 16, 14, 16, 14, 16, 13, 12, + 7, 11, 8, 11, 9, 11, 9, 9, 10, 13, 10, 11, 10, 12, 10, 9, + 16, 16, 14, 14, 14, 15, 12, 11, 11, 14, 11, 12, 11, 13, 10, 10, + 12, 15, 11, 13, 12, 13, 11, 10, 16, 16, 14, 16, 15, 15, 13, 11, + 10, 13, 11, 12, 10, 12, 10, 10, 12, 15, 12, 13, 11, 13, 11, 11, + 16, 16, 15, 16, 14, 15, 13, 11, 11, 14, 11, 13, 11, 12, 11, 10, + 12, 16, 12, 13, 12, 13, 11, 10, 16, 16, 15, 16, 13, 15, 12, 11, + 13, 15, 12, 13, 13, 14, 11, 11, 14, 16, 13, 13, 13, 14, 11, 11, + 16, 16, 15, 14, 15, 15, 12, 10, 3, 8, 6, 9, 7, 9, 8, 8, + 8, 12, 9, 11, 9, 11, 9, 9, 16, 16, 15, 15, 15, 16, 13, 12, + 6, 10, 7, 9, 8, 10, 8, 8, 9, 12, 9, 11, 10, 12, 10, 9, + 16, 16, 14, 14, 14, 15, 13, 11, 10, 13, 9, 11, 11, 12, 10, 10, + 12, 14, 11, 12, 12, 13, 11, 10, 16, 16, 14, 14, 15, 15, 13, 11, + 6, 10, 8, 10, 7, 10, 8, 9, 10, 12, 10, 11, 10, 11, 10, 9, + 16, 16, 14, 15, 14, 15, 13, 11, 8, 11, 8, 10, 9, 11, 9, 9, + 9, 13, 9, 11, 10, 11, 9, 9, 16, 16, 13, 14, 14, 14, 12, 10, + 11, 14, 10, 12, 11, 12, 10, 10, 12, 14, 11, 12, 12, 13, 10, 10, + 16, 16, 13, 14, 15, 15, 12, 10, 10, 13, 11, 12, 10, 12, 10, 10, + 12, 14, 12, 13, 11, 13, 11, 10, 16, 16, 15, 14, 14, 14, 12, 11, + 11, 14, 11, 12, 10, 12, 10, 10, 12, 15, 12, 12, 11, 13, 10, 10, + 16, 16, 14, 15, 13, 14, 12, 10, 13, 15, 12, 13, 12, 13, 11, 10, + 13, 16, 12, 13, 12, 13, 11, 10, 16, 16, 13, 14, 13, 15, 11, 9, + 6, 10, 8, 10, 8, 11, 9, 10, 11, 13, 11, 12, 11, 13, 11, 10, + 16, 16, 16, 16, 16, 16, 13, 12, 8, 11, 9, 11, 9, 11, 10, 10, + 11, 14, 11, 12, 11, 12, 11, 10, 16, 16, 15, 15, 16, 16, 13, 12, + 11, 14, 10, 12, 12, 13, 11, 10, 13, 16, 12, 13, 13, 14, 11, 11, + 16, 16, 15, 16, 16, 16, 13, 12, 8, 12, 9, 11, 9, 11, 10, 10, + 11, 14, 11, 12, 11, 12, 11, 10, 16, 16, 16, 16, 16, 16, 13, 12, + 9, 12, 10, 11, 10, 12, 10, 10, 11, 14, 11, 12, 11, 13, 10, 10, + 16, 16, 15, 14, 15, 15, 13, 11, 12, 14, 11, 13, 12, 13, 11, 10, + 12, 15, 11, 12, 13, 13, 11, 10, 16, 16, 14, 15, 16, 15, 13, 11, + 11, 15, 12, 13, 11, 13, 11, 10, 13, 16, 13, 14, 12, 14, 11, 11, + 16, 16, 16, 16, 15, 15, 13, 12, 12, 14, 12, 13, 11, 13, 11, 10, + 13, 15, 12, 13, 11, 13, 11, 10, 16, 16, 15, 15, 13, 15, 13, 11, + 13, 16, 13, 13, 13, 13, 12, 11, 13, 16, 13, 13, 13, 13, 11, 10, + 16, 16, 13, 15, 14, 14, 12, 9, 9, 13, 10, 12, 11, 13, 11, 11, + 13, 16, 13, 14, 13, 14, 12, 11, 16, 16, 16, 16, 16, 16, 14, 12, + 10, 14, 11, 13, 11, 13, 11, 10, 13, 16, 13, 13, 13, 14, 12, 11, + 16, 16, 16, 16, 16, 16, 14, 12, 11, 15, 11, 13, 12, 13, 11, 10, + 14, 16, 12, 13, 13, 14, 12, 10, 16, 16, 15, 16, 16, 16, 13, 11, + 10, 14, 11, 12, 11, 13, 11, 10, 13, 16, 12, 13, 12, 14, 12, 11, + 16, 16, 16, 16, 16, 16, 14, 12, 11, 14, 11, 12, 11, 13, 11, 10, + 13, 15, 12, 13, 12, 13, 11, 10, 16, 16, 15, 15, 16, 16, 13, 11, + 12, 15, 12, 13, 12, 13, 11, 10, 13, 16, 12, 13, 13, 13, 11, 10, + 16, 16, 14, 14, 16, 15, 13, 10, 12, 15, 12, 13, 12, 13, 11, 10, + 14, 16, 13, 14, 13, 14, 12, 11, 16, 16, 16, 16, 15, 16, 13, 11, + 12, 16, 12, 13, 12, 13, 11, 10, 13, 16, 13, 13, 12, 14, 11, 10, + 16, 16, 15, 16, 14, 15, 13, 10, 12, 15, 12, 14, 12, 13, 11, 10, + 13, 16, 12, 13, 12, 13, 11, 10, 16, 16, 13, 14, 13, 14, 11, 8, + }, + }, + { + { + 0, 11, 5, 11, 7, 13, 10, 12, 7, 13, 9, 13, 10, 14, 12, 13, + 16, 16, 15, 16, 16, 16, 15, 15, 4, 13, 6, 12, 10, 14, 11, 12, + 8, 14, 9, 13, 11, 15, 12, 13, 16, 16, 15, 16, 15, 16, 15, 14, + 9, 16, 9, 13, 13, 16, 12, 13, 12, 16, 10, 14, 14, 16, 13, 13, + 16, 16, 14, 16, 16, 16, 14, 14, 5, 13, 8, 13, 8, 13, 11, 12, + 9, 14, 10, 13, 10, 14, 12, 13, 16, 16, 15, 16, 15, 16, 14, 15, + 7, 14, 9, 13, 10, 14, 11, 13, 9, 15, 10, 13, 11, 14, 12, 13, + 16, 16, 14, 16, 15, 16, 14, 14, 11, 16, 11, 14, 13, 16, 12, 13, + 12, 16, 11, 14, 14, 16, 12, 13, 16, 16, 14, 15, 16, 16, 14, 13, + 10, 16, 12, 15, 10, 15, 12, 14, 12, 16, 13, 16, 11, 15, 13, 14, + 16, 16, 16, 16, 14, 16, 14, 14, 11, 16, 12, 15, 11, 16, 12, 13, + 12, 16, 13, 15, 12, 16, 12, 13, 16, 16, 16, 16, 14, 16, 14, 14, + 14, 16, 13, 15, 14, 16, 13, 13, 14, 16, 14, 15, 14, 16, 13, 13, + 16, 16, 15, 16, 15, 16, 13, 13, 2, 12, 6, 11, 7, 13, 10, 12, + 7, 13, 9, 12, 10, 14, 11, 12, 16, 16, 15, 16, 15, 16, 14, 15, + 5, 13, 6, 12, 9, 13, 10, 12, 8, 14, 9, 13, 11, 14, 11, 13, + 16, 16, 14, 16, 15, 16, 14, 14, 9, 16, 8, 13, 12, 16, 11, 13, + 11, 16, 10, 13, 13, 16, 12, 13, 16, 16, 13, 15, 16, 16, 13, 13, + 5, 13, 8, 12, 7, 13, 10, 12, 8, 14, 10, 13, 10, 14, 11, 13, + 16, 16, 14, 16, 15, 16, 14, 14, 7, 14, 8, 12, 9, 14, 11, 12, + 8, 14, 9, 13, 10, 14, 11, 12, 15, 16, 14, 15, 14, 16, 13, 14, + 11, 16, 10, 13, 13, 16, 12, 13, 11, 16, 10, 13, 13, 16, 12, 13, + 16, 16, 13, 15, 15, 16, 13, 13, 9, 16, 12, 15, 9, 14, 11, 13, + 11, 16, 13, 15, 11, 14, 12, 13, 16, 16, 15, 16, 14, 16, 14, 14, + 11, 16, 12, 14, 11, 15, 12, 13, 11, 16, 12, 14, 11, 15, 12, 13, + 16, 16, 15, 16, 14, 16, 13, 13, 13, 16, 13, 15, 13, 16, 12, 13, + 14, 16, 13, 15, 13, 16, 12, 12, 16, 16, 14, 15, 14, 16, 12, 12, + 4, 13, 7, 12, 8, 14, 11, 12, 9, 14, 10, 13, 11, 14, 12, 13, + 16, 16, 15, 16, 16, 16, 15, 15, 6, 14, 7, 12, 10, 14, 11, 12, + 9, 15, 10, 13, 11, 15, 12, 13, 16, 16, 15, 16, 16, 16, 14, 14, + 9, 16, 8, 13, 12, 16, 11, 13, 12, 16, 10, 14, 13, 16, 12, 13, + 16, 16, 14, 16, 16, 16, 14, 14, 6, 14, 8, 13, 8, 14, 11, 13, + 9, 15, 10, 13, 11, 14, 12, 13, 16, 16, 15, 16, 16, 16, 14, 14, + 7, 15, 9, 13, 10, 14, 11, 13, 9, 15, 10, 13, 11, 14, 11, 13, + 16, 16, 14, 16, 15, 16, 14, 14, 10, 16, 10, 13, 12, 16, 12, 13, + 11, 16, 10, 13, 13, 16, 12, 13, 16, 16, 13, 14, 15, 16, 13, 13, + 9, 16, 12, 14, 9, 14, 11, 13, 12, 16, 12, 15, 11, 15, 12, 13, + 16, 16, 16, 16, 15, 16, 14, 14, 10, 16, 12, 15, 11, 15, 12, 13, + 11, 16, 12, 14, 11, 15, 12, 13, 16, 16, 14, 16, 13, 16, 13, 13, + 13, 16, 13, 15, 13, 16, 12, 13, 13, 16, 12, 14, 13, 16, 12, 12, + 15, 16, 13, 14, 13, 16, 12, 12, 6, 14, 8, 13, 9, 14, 10, 12, + 10, 15, 10, 12, 11, 14, 11, 12, 16, 16, 14, 14, 14, 16, 13, 13, + 7, 15, 8, 13, 9, 14, 10, 12, 10, 15, 10, 13, 11, 14, 11, 12, + 16, 16, 14, 14, 14, 16, 13, 12, 9, 16, 8, 12, 11, 14, 10, 11, + 11, 16, 10, 13, 11, 14, 10, 11, 16, 16, 13, 14, 14, 16, 12, 11, + 7, 14, 9, 13, 9, 14, 10, 12, 10, 16, 10, 13, 11, 14, 11, 12, + 16, 16, 14, 14, 14, 15, 13, 12, 7, 14, 9, 13, 9, 14, 10, 12, + 9, 14, 10, 12, 10, 14, 11, 12, 15, 16, 13, 14, 14, 15, 12, 12, + 9, 15, 9, 12, 11, 14, 10, 11, 10, 15, 9, 12, 11, 14, 10, 11, + 14, 16, 11, 13, 13, 15, 11, 11, 9, 16, 10, 13, 9, 14, 10, 11, + 11, 16, 11, 13, 10, 14, 10, 11, 16, 16, 14, 15, 13, 15, 12, 12, + 9, 16, 10, 13, 9, 13, 10, 11, 10, 15, 10, 13, 10, 13, 10, 11, + 14, 16, 13, 14, 12, 14, 11, 11, 11, 16, 10, 13, 11, 13, 9, 10, + 11, 14, 10, 12, 10, 13, 9, 9, 13, 15, 10, 11, 11, 12, 9, 8, + }, + { + 0, 10, 5, 10, 6, 11, 8, 10, 7, 12, 8, 11, 9, 12, 9, 10, + 14, 16, 13, 13, 13, 14, 12, 11, 5, 12, 6, 10, 8, 12, 9, 10, + 8, 13, 8, 11, 9, 12, 9, 10, 14, 16, 12, 13, 13, 14, 11, 11, + 9, 15, 8, 12, 11, 14, 10, 10, 11, 16, 9, 12, 12, 14, 10, 10, + 14, 16, 11, 12, 13, 14, 11, 10, 5, 12, 8, 11, 7, 11, 9, 10, + 8, 13, 9, 11, 9, 12, 9, 10, 14, 16, 12, 13, 13, 14, 11, 11, + 7, 13, 8, 11, 9, 12, 9, 10, 9, 13, 9, 11, 9, 12, 9, 10, + 14, 16, 12, 13, 12, 13, 11, 10, 11, 15, 10, 12, 12, 14, 10, 10, + 12, 16, 10, 12, 12, 14, 10, 10, 14, 16, 11, 12, 13, 14, 10, 9, + 10, 15, 11, 13, 9, 13, 10, 10, 11, 15, 12, 13, 10, 12, 10, 10, + 14, 16, 13, 14, 12, 13, 11, 10, 11, 16, 11, 13, 10, 13, 10, 10, + 11, 16, 11, 13, 10, 13, 10, 10, 14, 16, 13, 14, 12, 13, 11, 9, + 13, 16, 12, 13, 12, 14, 11, 10, 14, 16, 12, 13, 12, 14, 10, 9, + 16, 16, 12, 13, 13, 13, 10, 8, 3, 11, 6, 10, 7, 11, 9, 10, + 8, 12, 8, 11, 9, 12, 9, 10, 14, 16, 13, 13, 13, 14, 11, 11, + 5, 12, 6, 10, 8, 12, 9, 10, 8, 13, 8, 11, 9, 12, 9, 10, + 14, 16, 12, 13, 13, 14, 11, 10, 9, 14, 8, 11, 11, 14, 10, 10, + 11, 15, 9, 11, 12, 14, 10, 10, 14, 16, 11, 12, 13, 14, 11, 9, + 6, 12, 8, 11, 7, 11, 9, 10, 8, 13, 9, 11, 9, 12, 9, 10, + 14, 16, 12, 13, 13, 13, 11, 10, 7, 13, 8, 11, 8, 12, 9, 10, + 9, 13, 9, 11, 9, 12, 9, 9, 14, 16, 12, 13, 12, 13, 11, 10, + 10, 15, 9, 12, 11, 14, 10, 10, 11, 15, 9, 11, 11, 13, 10, 9, + 14, 16, 11, 12, 13, 14, 10, 9, 9, 15, 11, 13, 9, 12, 10, 10, + 11, 15, 11, 13, 9, 12, 10, 10, 14, 16, 13, 14, 12, 13, 11, 10, + 10, 15, 11, 13, 10, 13, 10, 10, 11, 15, 11, 13, 10, 12, 10, 10, + 14, 16, 12, 13, 11, 12, 10, 9, 13, 16, 12, 13, 12, 14, 10, 9, + 13, 16, 11, 12, 12, 13, 10, 9, 14, 16, 11, 12, 12, 13, 9, 8, + 7, 13, 8, 12, 9, 13, 10, 11, 10, 14, 10, 12, 11, 13, 11, 11, + 16, 16, 13, 14, 14, 14, 12, 11, 8, 14, 8, 12, 9, 13, 10, 10, + 10, 14, 10, 12, 11, 13, 10, 10, 16, 16, 13, 13, 14, 14, 12, 11, + 10, 15, 9, 12, 11, 14, 10, 10, 12, 16, 10, 12, 12, 14, 10, 10, + 16, 16, 12, 13, 14, 15, 11, 10, 8, 14, 9, 12, 9, 13, 10, 11, + 10, 15, 10, 12, 10, 13, 10, 11, 16, 16, 13, 14, 14, 14, 12, 11, + 8, 14, 9, 12, 9, 13, 10, 10, 10, 14, 10, 12, 10, 13, 10, 10, + 15, 16, 13, 13, 13, 14, 11, 10, 10, 15, 10, 12, 12, 14, 10, 10, + 11, 16, 9, 12, 12, 14, 10, 10, 14, 16, 11, 12, 13, 14, 10, 9, + 11, 16, 11, 13, 10, 13, 10, 10, 12, 16, 12, 13, 10, 13, 11, 10, + 15, 16, 14, 14, 12, 13, 11, 10, 11, 16, 11, 13, 10, 13, 10, 10, + 11, 16, 12, 13, 10, 12, 10, 10, 14, 16, 13, 14, 11, 13, 11, 9, + 13, 16, 12, 13, 12, 14, 10, 10, 12, 16, 11, 12, 12, 13, 10, 9, + 14, 16, 11, 12, 11, 12, 9, 8, 10, 16, 10, 13, 11, 14, 11, 11, + 12, 16, 11, 13, 12, 14, 11, 11, 16, 16, 14, 13, 14, 14, 12, 10, + 10, 15, 10, 13, 10, 13, 10, 11, 12, 16, 11, 13, 11, 13, 11, 10, + 16, 16, 14, 13, 14, 14, 12, 10, 11, 15, 9, 12, 11, 13, 10, 9, + 12, 16, 10, 12, 12, 13, 10, 9, 16, 16, 12, 12, 13, 14, 10, 8, + 10, 16, 10, 13, 10, 14, 11, 11, 12, 16, 11, 13, 12, 14, 11, 10, + 16, 16, 14, 13, 14, 14, 12, 10, 9, 15, 9, 12, 10, 13, 10, 10, + 11, 16, 10, 12, 11, 13, 10, 10, 16, 16, 13, 13, 13, 14, 11, 9, + 10, 15, 9, 11, 11, 13, 9, 9, 11, 15, 9, 11, 11, 13, 9, 8, + 14, 16, 10, 11, 13, 13, 10, 8, 11, 16, 11, 13, 10, 13, 10, 9, + 13, 16, 11, 13, 11, 13, 10, 9, 16, 16, 13, 13, 13, 13, 10, 8, + 11, 16, 10, 12, 10, 13, 10, 9, 11, 16, 11, 12, 10, 12, 9, 9, + 15, 16, 12, 13, 11, 12, 10, 8, 11, 16, 10, 12, 11, 12, 9, 8, + 11, 15, 9, 11, 10, 12, 9, 7, 13, 15, 9, 9, 10, 10, 7, 5, + }, + { + 0, 7, 3, 8, 4, 9, 7, 8, 5, 10, 7, 10, 8, 11, 8, 9, + 16, 16, 16, 16, 16, 16, 11, 10, 2, 10, 4, 9, 7, 10, 7, 8, + 7, 16, 7, 10, 9, 16, 8, 9, 16, 16, 16, 16, 16, 16, 11, 10, + 8, 16, 7, 10, 10, 16, 9, 8, 10, 16, 9, 11, 16, 16, 9, 9, + 16, 16, 16, 16, 16, 16, 11, 9, 3, 10, 6, 9, 6, 11, 8, 8, + 7, 16, 8, 10, 9, 16, 9, 9, 16, 16, 16, 16, 16, 16, 11, 10, + 5, 16, 7, 10, 8, 11, 8, 8, 8, 16, 8, 10, 9, 16, 8, 8, + 16, 16, 11, 16, 16, 16, 10, 9, 9, 16, 9, 11, 11, 16, 9, 9, + 11, 16, 9, 11, 11, 16, 9, 8, 16, 16, 10, 16, 16, 16, 10, 9, + 8, 16, 10, 16, 8, 16, 10, 9, 12, 16, 11, 16, 10, 16, 10, 9, + 16, 16, 16, 16, 16, 16, 12, 10, 10, 16, 11, 16, 10, 16, 10, 9, + 11, 16, 11, 16, 10, 16, 10, 9, 16, 16, 16, 16, 16, 16, 11, 9, + 16, 16, 16, 16, 16, 16, 10, 9, 16, 16, 11, 16, 16, 16, 10, 9, + 16, 16, 10, 11, 11, 16, 9, 7, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + { + 2, 9, 6, 9, 6, 10, 8, 9, 8, 12, 9, 11, 9, 12, 10, 10, + 16, 16, 14, 14, 15, 15, 13, 12, 5, 11, 7, 10, 8, 11, 9, 9, + 9, 13, 9, 11, 10, 12, 10, 10, 15, 16, 14, 14, 14, 16, 12, 11, + 10, 14, 9, 11, 11, 13, 10, 10, 12, 15, 10, 12, 12, 13, 11, 10, + 16, 16, 14, 15, 14, 15, 12, 11, 5, 11, 8, 10, 7, 11, 9, 9, + 9, 13, 9, 12, 9, 12, 10, 10, 15, 16, 13, 14, 13, 16, 12, 11, + 7, 12, 8, 11, 9, 11, 9, 10, 9, 13, 9, 11, 10, 12, 9, 9, + 16, 16, 13, 14, 13, 14, 11, 11, 10, 14, 10, 12, 11, 13, 10, 10, + 11, 16, 11, 12, 12, 13, 10, 10, 16, 16, 13, 14, 13, 14, 12, 11, + 10, 14, 11, 13, 10, 13, 10, 11, 12, 16, 12, 13, 10, 12, 11, 11, + 16, 16, 14, 15, 13, 14, 12, 11, 11, 15, 11, 13, 11, 13, 10, 10, + 12, 15, 12, 13, 11, 13, 11, 10, 15, 16, 14, 15, 13, 15, 12, 11, + 12, 16, 12, 13, 12, 14, 11, 11, 13, 16, 12, 13, 12, 14, 11, 10, + 16, 16, 13, 14, 13, 14, 11, 10, 3, 10, 6, 9, 7, 10, 8, 9, + 9, 12, 9, 11, 10, 12, 9, 10, 15, 16, 14, 14, 14, 14, 12, 11, + 6, 11, 7, 10, 8, 10, 9, 9, 9, 13, 9, 11, 10, 12, 9, 9, + 15, 16, 13, 14, 14, 15, 12, 11, 10, 14, 9, 11, 11, 12, 10, 10, + 12, 14, 10, 12, 11, 13, 10, 10, 15, 16, 13, 14, 14, 16, 12, 11, + 6, 11, 8, 10, 7, 11, 9, 9, 9, 13, 9, 11, 9, 12, 9, 9, + 15, 16, 14, 14, 13, 14, 12, 11, 7, 11, 8, 11, 8, 11, 9, 9, + 9, 12, 9, 11, 9, 12, 9, 9, 15, 16, 13, 13, 13, 14, 11, 10, + 10, 13, 10, 12, 11, 13, 10, 10, 11, 15, 10, 12, 11, 13, 10, 10, + 14, 16, 12, 13, 13, 14, 11, 10, 10, 14, 11, 12, 9, 12, 10, 10, + 11, 15, 11, 13, 10, 13, 10, 10, 15, 16, 14, 14, 13, 14, 12, 11, + 10, 14, 10, 12, 10, 12, 10, 10, 11, 15, 11, 12, 10, 12, 10, 10, + 15, 16, 13, 14, 12, 14, 11, 10, 12, 16, 11, 13, 12, 14, 11, 10, + 12, 16, 12, 13, 11, 13, 10, 10, 15, 16, 12, 14, 12, 14, 11, 9, + 7, 12, 9, 11, 9, 12, 10, 10, 11, 14, 11, 12, 11, 13, 11, 11, + 16, 16, 15, 16, 15, 16, 13, 12, 8, 12, 9, 11, 9, 12, 10, 10, + 11, 14, 11, 12, 11, 13, 10, 10, 16, 16, 14, 15, 15, 16, 13, 12, + 11, 14, 10, 12, 11, 13, 10, 10, 12, 16, 11, 13, 12, 14, 11, 10, + 16, 16, 14, 15, 14, 16, 12, 11, 8, 13, 9, 11, 9, 12, 10, 10, + 11, 14, 11, 12, 11, 13, 10, 10, 16, 16, 15, 15, 14, 15, 13, 12, + 9, 13, 9, 12, 9, 12, 10, 10, 11, 14, 10, 12, 10, 12, 10, 10, + 16, 16, 14, 15, 14, 14, 12, 11, 11, 15, 11, 12, 11, 13, 11, 10, + 12, 16, 11, 12, 12, 13, 11, 10, 16, 16, 13, 15, 14, 15, 11, 11, + 11, 16, 11, 13, 10, 13, 11, 11, 12, 16, 12, 14, 11, 13, 11, 11, + 16, 16, 14, 15, 14, 15, 13, 11, 11, 16, 11, 13, 11, 13, 11, 10, + 12, 16, 12, 13, 10, 13, 11, 10, 16, 16, 14, 14, 12, 14, 12, 10, + 12, 16, 12, 14, 12, 14, 11, 11, 13, 16, 12, 14, 12, 14, 11, 10, + 15, 16, 12, 14, 12, 14, 11, 9, 9, 14, 11, 13, 11, 13, 11, 11, + 13, 16, 12, 14, 13, 14, 12, 11, 16, 16, 16, 16, 16, 16, 14, 12, + 9, 14, 10, 12, 10, 13, 11, 11, 12, 16, 12, 13, 13, 14, 11, 11, + 16, 16, 16, 16, 16, 14, 13, 12, 10, 15, 11, 13, 11, 14, 11, 10, + 13, 16, 12, 13, 12, 15, 11, 10, 16, 16, 14, 16, 15, 16, 13, 11, + 10, 14, 10, 13, 11, 14, 11, 11, 13, 16, 12, 13, 12, 14, 11, 11, + 16, 16, 16, 16, 15, 16, 13, 12, 10, 14, 10, 12, 10, 13, 10, 11, + 12, 15, 12, 13, 12, 13, 11, 10, 16, 16, 14, 14, 15, 15, 13, 11, + 11, 16, 11, 13, 11, 14, 11, 10, 12, 16, 11, 13, 12, 14, 11, 10, + 16, 16, 13, 14, 14, 15, 12, 10, 11, 16, 12, 13, 11, 14, 11, 10, + 13, 16, 13, 14, 12, 14, 11, 11, 16, 16, 15, 16, 15, 15, 12, 11, + 11, 16, 12, 13, 11, 14, 11, 10, 13, 16, 12, 13, 11, 14, 11, 10, + 16, 16, 14, 15, 13, 14, 12, 10, 12, 16, 12, 14, 12, 14, 10, 10, + 12, 16, 11, 13, 11, 14, 10, 10, 14, 16, 11, 13, 12, 13, 10, 8, + }, + }, + { + { + 0, 12, 6, 13, 7, 14, 11, 14, 8, 14, 10, 14, 11, 15, 13, 15, + 16, 16, 16, 16, 16, 16, 16, 16, 5, 14, 7, 13, 10, 16, 12, 14, + 9, 16, 10, 14, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 9, 14, 14, 16, 13, 16, 12, 16, 11, 16, 16, 16, 14, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 5, 14, 9, 14, 8, 14, 12, 14, + 9, 16, 11, 14, 11, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 16, 10, 14, 11, 16, 12, 14, 10, 16, 11, 15, 12, 16, 13, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 12, 16, 14, 16, 14, 16, + 13, 16, 12, 16, 15, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 13, 16, 11, 16, 14, 16, 13, 16, 14, 16, 13, 16, 14, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 14, 16, 13, 16, 14, 16, + 13, 16, 14, 16, 13, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 15, 16, 16, 16, 14, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 1, 12, 6, 12, 8, 14, 11, 13, + 8, 14, 10, 13, 11, 14, 13, 14, 16, 16, 16, 16, 16, 16, 16, 16, + 5, 14, 7, 13, 10, 14, 11, 14, 9, 16, 10, 14, 12, 16, 13, 15, + 16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 9, 14, 13, 16, 13, 14, + 12, 16, 11, 15, 14, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 5, 14, 9, 13, 8, 14, 12, 14, 9, 16, 11, 14, 11, 16, 13, 14, + 16, 16, 16, 16, 16, 16, 16, 16, 7, 15, 9, 14, 10, 16, 12, 14, + 9, 16, 10, 14, 11, 16, 12, 14, 16, 16, 16, 16, 16, 16, 15, 16, + 11, 16, 11, 15, 14, 16, 13, 15, 12, 16, 11, 15, 14, 16, 13, 14, + 16, 16, 14, 16, 16, 16, 14, 16, 10, 16, 13, 16, 10, 16, 13, 16, + 12, 16, 14, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 13, 16, 12, 16, 13, 16, 12, 16, 13, 16, 12, 16, 13, 16, + 16, 16, 16, 16, 16, 16, 15, 16, 14, 16, 14, 16, 16, 16, 14, 16, + 15, 16, 14, 16, 14, 16, 14, 16, 16, 16, 16, 16, 16, 16, 14, 14, + 4, 14, 8, 13, 9, 16, 12, 14, 9, 16, 11, 14, 11, 16, 13, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 6, 15, 8, 13, 10, 16, 12, 14, + 10, 16, 11, 14, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 9, 16, 9, 14, 13, 16, 13, 15, 12, 16, 11, 16, 14, 16, 13, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 9, 14, 9, 16, 12, 14, + 10, 16, 11, 15, 12, 16, 13, 15, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 16, 10, 14, 11, 16, 12, 14, 10, 16, 11, 14, 12, 16, 13, 15, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 11, 15, 14, 16, 13, 15, + 12, 16, 11, 15, 14, 16, 13, 14, 16, 16, 14, 16, 16, 16, 14, 16, + 10, 16, 13, 16, 10, 16, 13, 15, 13, 16, 14, 16, 12, 16, 14, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 13, 16, 12, 16, 13, 16, + 12, 16, 13, 16, 11, 16, 13, 16, 16, 16, 16, 16, 15, 16, 15, 16, + 14, 16, 14, 16, 15, 16, 14, 16, 14, 16, 14, 16, 14, 16, 14, 14, + 16, 16, 14, 16, 15, 16, 14, 14, 6, 16, 9, 14, 10, 16, 12, 14, + 10, 16, 11, 13, 12, 16, 13, 14, 16, 16, 16, 16, 16, 16, 14, 14, + 7, 16, 9, 14, 10, 16, 12, 13, 11, 16, 11, 14, 12, 16, 12, 14, + 16, 16, 16, 16, 16, 16, 14, 14, 9, 16, 9, 14, 12, 16, 11, 13, + 12, 16, 11, 14, 12, 16, 12, 13, 16, 16, 14, 16, 16, 16, 13, 14, + 7, 16, 10, 14, 10, 16, 12, 14, 11, 16, 11, 14, 11, 16, 12, 14, + 16, 16, 16, 16, 16, 16, 14, 14, 8, 16, 10, 14, 10, 16, 11, 13, + 10, 16, 11, 13, 11, 16, 12, 13, 16, 16, 14, 16, 16, 16, 14, 14, + 10, 16, 9, 13, 12, 16, 11, 13, 11, 16, 10, 13, 12, 16, 11, 12, + 16, 16, 13, 15, 15, 16, 13, 13, 9, 16, 11, 14, 9, 16, 11, 13, + 12, 16, 12, 16, 12, 16, 12, 13, 16, 16, 16, 16, 15, 16, 14, 14, + 10, 16, 11, 14, 10, 16, 11, 13, 11, 16, 12, 14, 10, 15, 11, 13, + 16, 16, 15, 16, 13, 16, 13, 13, 12, 16, 11, 13, 12, 16, 11, 12, + 12, 16, 11, 13, 11, 14, 11, 11, 13, 16, 12, 13, 12, 14, 11, 11, + }, + { + 0, 10, 5, 10, 6, 11, 8, 10, 7, 12, 8, 11, 8, 12, 9, 10, + 14, 16, 13, 13, 13, 14, 12, 11, 4, 12, 6, 10, 8, 12, 9, 10, + 8, 13, 8, 11, 9, 12, 9, 10, 14, 16, 12, 13, 13, 14, 11, 11, + 9, 15, 8, 12, 12, 14, 10, 11, 11, 16, 9, 12, 12, 14, 10, 10, + 14, 16, 11, 13, 13, 15, 11, 11, 4, 12, 8, 11, 6, 11, 9, 10, + 8, 13, 9, 11, 8, 12, 9, 10, 14, 16, 12, 13, 13, 14, 11, 11, + 7, 13, 8, 11, 9, 12, 9, 10, 8, 13, 9, 11, 9, 12, 9, 10, + 14, 16, 12, 13, 12, 13, 11, 10, 11, 16, 10, 12, 12, 14, 10, 11, + 11, 16, 10, 12, 12, 14, 10, 10, 15, 16, 11, 13, 13, 14, 11, 10, + 10, 16, 11, 13, 9, 13, 10, 11, 11, 15, 12, 13, 10, 12, 10, 11, + 15, 16, 13, 14, 12, 13, 11, 11, 11, 16, 11, 13, 10, 13, 10, 11, + 12, 16, 11, 13, 10, 13, 10, 10, 15, 16, 13, 14, 12, 13, 11, 10, + 13, 16, 12, 13, 13, 14, 11, 11, 14, 16, 12, 13, 12, 14, 11, 10, + 16, 16, 13, 13, 13, 14, 11, 9, 3, 11, 6, 10, 6, 11, 9, 10, + 8, 12, 8, 11, 9, 12, 9, 10, 14, 16, 13, 13, 13, 13, 12, 11, + 5, 12, 6, 10, 8, 12, 9, 10, 8, 13, 8, 11, 9, 12, 9, 10, + 14, 16, 12, 13, 13, 14, 11, 11, 9, 15, 8, 11, 11, 14, 10, 10, + 11, 15, 9, 11, 12, 14, 10, 10, 14, 16, 11, 12, 13, 14, 11, 10, + 5, 12, 8, 11, 7, 11, 9, 10, 8, 13, 9, 11, 9, 12, 9, 10, + 14, 16, 12, 13, 13, 13, 11, 11, 7, 13, 8, 11, 8, 12, 9, 10, + 8, 13, 8, 11, 9, 12, 9, 9, 13, 16, 11, 13, 12, 13, 11, 10, + 10, 15, 9, 12, 11, 14, 10, 10, 11, 15, 9, 11, 11, 13, 10, 10, + 14, 16, 11, 12, 13, 14, 10, 10, 9, 16, 11, 13, 9, 12, 10, 10, + 11, 16, 11, 13, 9, 12, 10, 10, 15, 16, 13, 14, 12, 13, 11, 10, + 11, 16, 11, 13, 10, 13, 10, 10, 11, 15, 11, 13, 9, 12, 10, 10, + 14, 16, 12, 13, 11, 13, 10, 10, 13, 16, 12, 13, 12, 14, 11, 10, + 13, 16, 11, 13, 12, 13, 10, 10, 14, 16, 11, 12, 12, 13, 10, 9, + 7, 14, 8, 12, 9, 13, 10, 11, 10, 14, 10, 12, 11, 13, 11, 11, + 16, 16, 14, 14, 14, 14, 12, 12, 7, 14, 8, 12, 9, 13, 10, 11, + 10, 14, 10, 12, 11, 13, 10, 11, 16, 16, 13, 13, 14, 14, 12, 11, + 10, 15, 9, 12, 12, 14, 10, 10, 12, 16, 9, 12, 12, 14, 10, 10, + 16, 16, 12, 13, 14, 15, 12, 11, 8, 14, 9, 12, 9, 13, 10, 11, + 10, 15, 10, 12, 10, 13, 10, 11, 16, 16, 14, 14, 14, 14, 12, 11, + 8, 14, 9, 12, 9, 13, 10, 11, 10, 14, 10, 12, 10, 13, 10, 10, + 15, 16, 13, 13, 13, 14, 12, 11, 10, 15, 10, 12, 12, 14, 10, 10, + 11, 16, 9, 12, 12, 14, 10, 10, 14, 16, 11, 12, 13, 14, 11, 10, + 11, 16, 11, 14, 9, 13, 10, 11, 12, 16, 12, 14, 10, 13, 11, 11, + 16, 16, 14, 15, 13, 14, 12, 11, 11, 16, 12, 14, 10, 13, 11, 11, + 11, 16, 11, 13, 10, 13, 10, 10, 15, 16, 13, 14, 12, 13, 11, 10, + 13, 16, 12, 14, 13, 14, 11, 10, 12, 16, 11, 13, 12, 13, 10, 10, + 14, 16, 11, 12, 11, 13, 10, 9, 10, 16, 10, 13, 11, 14, 11, 11, + 12, 16, 11, 13, 12, 14, 11, 11, 16, 16, 14, 13, 14, 15, 12, 11, + 10, 16, 10, 13, 10, 14, 11, 11, 12, 16, 11, 13, 11, 14, 11, 11, + 16, 16, 14, 13, 14, 14, 12, 11, 11, 15, 9, 12, 11, 14, 10, 10, + 13, 16, 10, 12, 12, 14, 10, 10, 16, 16, 13, 13, 14, 14, 11, 10, + 10, 16, 10, 13, 11, 14, 11, 11, 12, 16, 11, 13, 12, 14, 11, 11, + 16, 16, 14, 14, 14, 14, 12, 11, 9, 16, 10, 13, 10, 14, 11, 11, + 11, 15, 11, 12, 11, 13, 11, 11, 16, 16, 13, 13, 14, 14, 12, 10, + 10, 15, 9, 12, 11, 14, 10, 10, 11, 16, 9, 11, 11, 13, 10, 9, + 15, 16, 11, 12, 13, 14, 10, 9, 11, 16, 11, 13, 10, 13, 10, 10, + 13, 16, 12, 13, 11, 13, 10, 10, 16, 16, 14, 14, 13, 13, 11, 10, + 11, 16, 11, 13, 10, 13, 10, 10, 12, 16, 11, 13, 10, 13, 10, 10, + 15, 16, 13, 13, 12, 13, 11, 9, 11, 16, 11, 12, 11, 13, 10, 9, + 11, 15, 10, 11, 11, 12, 9, 8, 13, 15, 10, 10, 10, 11, 8, 7, + }, + { + 0, 9, 3, 8, 5, 9, 7, 8, 5, 11, 6, 9, 8, 11, 8, 9, + 16, 16, 16, 16, 16, 16, 11, 10, 2, 10, 4, 9, 7, 10, 7, 8, + 7, 16, 7, 10, 9, 11, 8, 9, 16, 16, 11, 16, 16, 16, 11, 10, + 7, 16, 7, 10, 10, 16, 8, 9, 10, 16, 8, 10, 11, 16, 9, 9, + 16, 16, 16, 16, 16, 16, 11, 10, 3, 11, 6, 9, 6, 11, 8, 8, + 7, 16, 8, 10, 8, 11, 8, 9, 16, 16, 15, 16, 16, 16, 11, 10, + 5, 11, 7, 9, 8, 11, 8, 8, 7, 16, 7, 10, 8, 11, 8, 8, + 16, 16, 11, 16, 16, 16, 10, 9, 9, 16, 8, 11, 11, 16, 9, 9, + 10, 16, 8, 11, 11, 16, 9, 9, 16, 16, 10, 16, 16, 16, 10, 9, + 8, 16, 10, 11, 8, 16, 9, 9, 11, 16, 11, 16, 10, 16, 10, 9, + 16, 16, 16, 16, 16, 16, 11, 10, 9, 16, 10, 16, 10, 16, 9, 9, + 10, 16, 10, 16, 9, 16, 9, 9, 16, 16, 16, 16, 15, 16, 10, 9, + 16, 16, 11, 16, 16, 16, 10, 10, 13, 16, 11, 16, 11, 16, 10, 9, + 16, 16, 10, 11, 11, 16, 9, 8, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + { + 1, 10, 6, 10, 7, 11, 9, 10, 8, 12, 9, 12, 9, 12, 10, 10, + 16, 16, 14, 16, 14, 15, 13, 12, 5, 12, 7, 10, 9, 11, 9, 10, + 9, 13, 9, 12, 10, 13, 10, 10, 16, 16, 14, 15, 14, 14, 13, 12, + 10, 15, 10, 12, 12, 14, 11, 11, 12, 16, 11, 13, 12, 14, 11, 11, + 16, 16, 14, 16, 15, 16, 13, 12, 6, 12, 8, 11, 8, 11, 10, 10, + 9, 13, 10, 12, 10, 12, 10, 10, 15, 16, 13, 15, 13, 14, 12, 12, + 7, 13, 9, 11, 9, 12, 10, 10, 9, 14, 10, 12, 10, 13, 10, 10, + 15, 16, 13, 15, 13, 14, 12, 11, 11, 15, 11, 13, 12, 14, 11, 11, + 12, 16, 11, 13, 12, 14, 11, 11, 16, 16, 13, 15, 14, 16, 12, 11, + 10, 16, 12, 14, 10, 13, 11, 11, 12, 16, 12, 14, 11, 13, 11, 11, + 16, 16, 15, 16, 14, 16, 13, 12, 11, 16, 12, 14, 11, 14, 11, 11, + 12, 16, 12, 14, 11, 14, 11, 11, 16, 16, 14, 15, 13, 15, 12, 12, + 13, 16, 13, 15, 13, 15, 12, 12, 13, 16, 12, 15, 12, 15, 11, 11, + 16, 16, 13, 16, 13, 15, 12, 11, 4, 11, 7, 10, 7, 11, 9, 10, + 9, 13, 9, 12, 10, 12, 10, 10, 15, 16, 14, 15, 14, 15, 13, 12, + 6, 12, 7, 11, 9, 11, 9, 10, 9, 13, 9, 12, 10, 12, 10, 10, + 15, 16, 14, 15, 14, 15, 12, 12, 10, 15, 9, 12, 12, 13, 11, 11, + 12, 15, 11, 13, 12, 14, 11, 11, 16, 16, 13, 15, 14, 16, 12, 12, + 6, 12, 8, 11, 8, 11, 9, 10, 9, 14, 10, 12, 10, 12, 10, 10, + 14, 16, 13, 14, 13, 14, 12, 12, 8, 13, 9, 11, 9, 12, 10, 10, + 9, 13, 9, 12, 9, 12, 9, 10, 14, 16, 13, 14, 13, 14, 12, 11, + 11, 15, 11, 13, 11, 14, 11, 11, 12, 16, 10, 13, 12, 13, 11, 10, + 15, 16, 12, 15, 13, 16, 12, 11, 10, 15, 11, 13, 10, 13, 11, 11, + 12, 16, 12, 14, 11, 13, 11, 11, 16, 16, 14, 15, 13, 16, 13, 12, + 11, 16, 11, 14, 11, 13, 11, 11, 12, 16, 12, 14, 10, 13, 11, 11, + 15, 16, 13, 16, 12, 14, 12, 11, 12, 16, 12, 14, 12, 15, 11, 11, + 13, 16, 12, 14, 12, 14, 11, 11, 15, 16, 13, 15, 13, 15, 11, 10, + 7, 13, 9, 12, 10, 13, 11, 11, 11, 15, 12, 13, 12, 13, 11, 11, + 16, 16, 15, 16, 16, 16, 14, 13, 8, 13, 9, 12, 10, 13, 11, 11, + 12, 15, 11, 13, 12, 13, 11, 11, 16, 16, 14, 15, 15, 16, 13, 12, + 11, 16, 11, 13, 12, 14, 11, 11, 13, 16, 12, 14, 13, 15, 12, 11, + 16, 16, 14, 16, 15, 16, 13, 12, 9, 15, 10, 13, 10, 13, 11, 11, + 12, 15, 11, 13, 11, 13, 11, 11, 16, 16, 14, 16, 16, 16, 13, 12, + 9, 14, 10, 13, 10, 13, 11, 11, 11, 14, 11, 13, 11, 13, 11, 11, + 16, 16, 14, 16, 14, 16, 12, 12, 11, 16, 11, 14, 12, 14, 12, 11, + 12, 16, 11, 13, 13, 14, 11, 11, 16, 16, 13, 15, 14, 16, 12, 11, + 12, 16, 12, 14, 11, 14, 11, 11, 13, 16, 13, 14, 12, 15, 12, 11, + 16, 16, 16, 16, 14, 16, 13, 12, 12, 16, 12, 14, 11, 14, 12, 11, + 12, 16, 12, 15, 11, 14, 11, 11, 16, 16, 14, 16, 13, 15, 12, 12, + 13, 16, 13, 16, 13, 16, 12, 12, 13, 16, 12, 15, 12, 16, 11, 11, + 14, 16, 12, 15, 12, 15, 11, 10, 9, 16, 11, 14, 12, 14, 12, 12, + 13, 16, 13, 15, 14, 16, 12, 12, 16, 16, 16, 16, 16, 16, 14, 13, + 10, 16, 11, 14, 12, 14, 12, 12, 13, 16, 13, 14, 13, 16, 12, 12, + 16, 16, 15, 16, 16, 16, 13, 12, 11, 16, 11, 14, 12, 15, 12, 11, + 13, 16, 12, 14, 13, 16, 12, 11, 16, 16, 14, 16, 16, 16, 13, 12, + 11, 16, 11, 14, 12, 14, 12, 12, 13, 16, 12, 15, 13, 16, 12, 12, + 16, 16, 16, 16, 16, 16, 14, 13, 10, 16, 11, 14, 11, 15, 11, 11, + 13, 16, 12, 14, 12, 14, 12, 11, 16, 16, 14, 16, 16, 16, 13, 12, + 11, 16, 11, 15, 12, 15, 12, 11, 13, 16, 11, 14, 13, 15, 12, 11, + 16, 16, 13, 16, 14, 16, 12, 11, 12, 16, 12, 15, 11, 15, 12, 11, + 14, 16, 13, 15, 12, 16, 12, 11, 16, 16, 15, 16, 14, 16, 13, 12, + 11, 16, 12, 15, 11, 15, 11, 11, 13, 16, 13, 16, 11, 15, 11, 11, + 16, 16, 14, 16, 13, 15, 12, 11, 12, 16, 12, 15, 12, 16, 11, 11, + 12, 16, 11, 15, 12, 14, 11, 11, 13, 16, 12, 13, 11, 13, 10, 9, + }, + }, + { + { + 0, 13, 6, 13, 8, 14, 12, 16, 8, 16, 11, 16, 12, 16, 14, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 4, 16, 7, 14, 11, 16, 13, 16, + 9, 16, 11, 16, 12, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 10, 16, 16, 16, 16, 16, 13, 16, 12, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 5, 16, 10, 16, 8, 16, 13, 16, + 10, 16, 12, 16, 12, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 16, 10, 16, 11, 16, 13, 16, 10, 16, 12, 16, 12, 16, 14, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 12, 16, 16, 16, 16, 16, + 14, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 16, 16, 11, 16, 16, 16, 13, 16, 16, 16, 13, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 13, 16, 16, 16, + 14, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 1, 13, 7, 13, 8, 16, 12, 16, + 8, 16, 10, 16, 11, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 4, 16, 7, 14, 10, 16, 12, 16, 9, 16, 10, 16, 12, 16, 14, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 10, 16, 9, 16, 14, 16, 14, 16, + 13, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 5, 16, 9, 16, 8, 16, 12, 16, 9, 16, 11, 16, 11, 16, 13, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 7, 16, 10, 16, 11, 16, 13, 16, + 9, 16, 11, 16, 11, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 12, 16, 16, 16, 14, 16, 13, 16, 12, 16, 16, 16, 14, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 10, 16, 13, 16, 11, 16, 14, 16, + 13, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 14, 16, 13, 16, 14, 16, 13, 16, 14, 16, 13, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 4, 16, 8, 16, 9, 16, 13, 16, 10, 16, 11, 16, 12, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 8, 16, 11, 16, 13, 16, + 10, 16, 11, 16, 13, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 9, 16, 9, 16, 13, 16, 13, 16, 13, 16, 12, 16, 16, 16, 14, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 10, 16, 10, 16, 13, 16, + 10, 16, 12, 16, 12, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 16, 10, 16, 11, 16, 13, 16, 10, 16, 11, 16, 12, 16, 14, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 11, 16, 16, 16, 14, 16, + 12, 16, 11, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 13, 16, 10, 16, 13, 16, 13, 16, 16, 16, 13, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 13, 16, 12, 16, 14, 16, + 12, 16, 15, 16, 12, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 10, 16, 10, 16, 13, 16, + 11, 16, 11, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 16, 9, 16, 11, 16, 12, 16, 11, 16, 11, 16, 12, 16, 13, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 9, 16, 12, 16, 12, 16, + 13, 16, 11, 16, 13, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 16, 10, 16, 10, 16, 12, 16, 11, 16, 12, 16, 12, 16, 13, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 10, 16, 11, 16, 12, 16, + 10, 16, 11, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 10, 14, 12, 16, 12, 16, 11, 16, 10, 14, 13, 16, 12, 14, + 16, 16, 14, 16, 16, 16, 14, 16, 9, 16, 12, 16, 10, 16, 12, 16, + 13, 16, 13, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 12, 16, 11, 16, 12, 16, 11, 16, 12, 16, 11, 16, 12, 15, + 16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 12, 16, 13, 16, 12, 13, + 12, 16, 12, 16, 12, 16, 12, 13, 16, 16, 13, 14, 13, 16, 13, 13, + }, + { + 0, 10, 5, 10, 5, 10, 8, 10, 6, 11, 8, 11, 8, 11, 9, 10, + 14, 16, 13, 14, 13, 14, 12, 12, 4, 12, 5, 10, 8, 12, 9, 10, + 7, 12, 8, 11, 9, 12, 9, 10, 14, 16, 12, 13, 13, 14, 12, 12, + 9, 16, 8, 12, 12, 14, 10, 11, 11, 16, 9, 12, 12, 14, 11, 11, + 14, 16, 12, 13, 14, 15, 12, 12, 4, 12, 7, 11, 6, 11, 9, 10, + 8, 12, 9, 11, 8, 11, 9, 10, 14, 16, 12, 14, 13, 14, 12, 12, + 7, 13, 8, 11, 8, 12, 9, 10, 8, 13, 8, 11, 9, 12, 9, 10, + 14, 16, 12, 13, 12, 13, 11, 11, 11, 16, 10, 12, 12, 14, 11, 11, + 12, 16, 10, 12, 12, 14, 11, 11, 16, 16, 12, 13, 14, 15, 12, 11, + 10, 16, 11, 14, 9, 13, 10, 11, 11, 16, 12, 14, 10, 13, 11, 11, + 15, 16, 13, 14, 13, 14, 12, 12, 11, 16, 12, 14, 10, 13, 11, 11, + 12, 16, 12, 14, 11, 13, 11, 11, 15, 16, 13, 14, 13, 14, 12, 11, + 14, 16, 13, 14, 13, 15, 12, 12, 14, 16, 12, 14, 13, 15, 11, 11, + 16, 16, 13, 14, 14, 15, 12, 11, 3, 11, 5, 10, 6, 11, 9, 10, + 7, 12, 8, 11, 9, 11, 9, 10, 14, 16, 13, 13, 13, 14, 12, 12, + 5, 12, 6, 10, 8, 12, 9, 10, 8, 13, 8, 11, 9, 12, 9, 10, + 14, 16, 12, 13, 13, 14, 12, 12, 9, 16, 8, 11, 11, 14, 10, 11, + 11, 16, 9, 12, 12, 14, 10, 11, 15, 16, 12, 13, 14, 15, 12, 11, + 5, 12, 7, 11, 6, 11, 9, 10, 8, 13, 9, 11, 8, 11, 9, 10, + 14, 16, 12, 14, 13, 13, 12, 12, 7, 13, 8, 11, 8, 12, 9, 10, + 8, 12, 8, 11, 9, 12, 9, 10, 13, 16, 12, 13, 12, 13, 11, 11, + 10, 16, 9, 12, 12, 14, 10, 11, 11, 15, 9, 12, 12, 14, 10, 11, + 14, 16, 11, 13, 13, 14, 11, 11, 9, 16, 11, 14, 8, 13, 10, 11, + 11, 16, 12, 13, 10, 13, 10, 11, 16, 16, 13, 15, 13, 14, 12, 12, + 11, 16, 11, 14, 10, 13, 10, 11, 11, 16, 11, 13, 10, 13, 10, 11, + 14, 16, 13, 14, 12, 13, 11, 11, 14, 16, 12, 14, 13, 15, 11, 11, + 13, 16, 12, 13, 12, 14, 11, 11, 14, 16, 12, 13, 12, 13, 11, 10, + 6, 14, 8, 12, 9, 13, 10, 11, 10, 14, 10, 12, 11, 13, 11, 12, + 16, 16, 14, 14, 14, 14, 13, 12, 7, 14, 8, 12, 9, 13, 10, 11, + 10, 14, 10, 12, 11, 13, 11, 11, 16, 16, 13, 14, 14, 15, 13, 12, + 10, 16, 8, 12, 12, 14, 10, 11, 12, 16, 10, 12, 13, 15, 11, 11, + 16, 16, 13, 14, 15, 16, 12, 12, 8, 15, 9, 13, 9, 13, 10, 11, + 10, 15, 10, 13, 10, 13, 11, 11, 16, 16, 14, 14, 14, 14, 13, 12, + 8, 15, 9, 12, 10, 13, 10, 11, 10, 14, 10, 12, 10, 13, 10, 11, + 16, 16, 13, 14, 13, 14, 12, 12, 10, 16, 10, 13, 12, 15, 11, 11, + 11, 16, 9, 12, 12, 14, 11, 11, 14, 16, 11, 13, 14, 16, 12, 11, + 10, 16, 12, 14, 9, 13, 11, 11, 12, 16, 12, 14, 11, 13, 11, 11, + 16, 16, 15, 16, 14, 14, 13, 12, 11, 16, 12, 14, 11, 14, 11, 11, + 11, 16, 12, 14, 10, 13, 11, 11, 15, 16, 13, 15, 12, 14, 12, 11, + 14, 16, 13, 14, 13, 16, 12, 12, 12, 16, 12, 13, 12, 14, 11, 11, + 14, 16, 11, 12, 12, 13, 10, 10, 9, 16, 10, 14, 11, 15, 12, 12, + 12, 16, 11, 13, 12, 15, 12, 12, 16, 16, 14, 13, 15, 15, 13, 12, + 10, 16, 10, 14, 11, 15, 11, 12, 12, 16, 11, 13, 12, 14, 12, 12, + 16, 16, 14, 13, 15, 14, 13, 12, 11, 16, 9, 12, 12, 14, 11, 11, + 13, 16, 11, 13, 13, 15, 11, 11, 16, 16, 14, 14, 16, 16, 12, 12, + 10, 16, 10, 14, 11, 14, 11, 12, 12, 16, 11, 13, 12, 14, 12, 12, + 16, 16, 14, 14, 15, 15, 13, 12, 10, 16, 10, 13, 11, 14, 11, 12, + 11, 16, 11, 13, 11, 14, 11, 12, 16, 16, 14, 14, 14, 14, 13, 12, + 11, 16, 10, 12, 12, 15, 11, 11, 12, 16, 9, 12, 12, 14, 10, 11, + 16, 16, 12, 13, 14, 15, 11, 11, 11, 16, 12, 14, 10, 14, 11, 11, + 13, 16, 12, 14, 12, 14, 11, 11, 16, 16, 15, 15, 14, 15, 12, 12, + 11, 16, 12, 14, 11, 14, 11, 11, 12, 16, 12, 14, 11, 13, 11, 11, + 16, 16, 14, 14, 13, 14, 12, 11, 12, 16, 11, 13, 12, 14, 10, 10, + 12, 15, 11, 12, 12, 13, 10, 10, 14, 15, 11, 11, 12, 12, 10, 9, + }, + { + 0, 8, 3, 8, 5, 9, 7, 8, 5, 10, 6, 10, 8, 11, 8, 9, + 16, 16, 15, 16, 16, 16, 11, 11, 2, 10, 4, 9, 7, 10, 7, 8, + 7, 16, 7, 10, 9, 11, 8, 9, 16, 16, 15, 16, 16, 16, 11, 11, + 7, 16, 6, 11, 10, 16, 9, 10, 10, 16, 9, 11, 11, 16, 9, 10, + 16, 16, 16, 16, 16, 16, 16, 11, 3, 10, 6, 9, 5, 10, 7, 9, + 7, 16, 8, 10, 8, 11, 8, 9, 16, 16, 16, 16, 16, 16, 11, 11, + 5, 11, 7, 10, 8, 11, 8, 9, 7, 14, 7, 10, 8, 11, 8, 9, + 16, 16, 11, 16, 16, 16, 10, 11, 9, 16, 9, 11, 11, 16, 9, 10, + 10, 16, 8, 11, 11, 16, 9, 10, 16, 16, 11, 16, 16, 16, 11, 10, + 8, 16, 9, 16, 7, 16, 9, 10, 11, 16, 11, 16, 10, 16, 10, 10, + 16, 16, 16, 16, 16, 16, 16, 11, 9, 16, 10, 16, 9, 16, 9, 10, + 10, 16, 10, 16, 9, 16, 9, 10, 16, 16, 16, 16, 11, 16, 11, 11, + 16, 16, 16, 16, 16, 16, 10, 10, 11, 16, 11, 16, 11, 16, 10, 10, + 16, 16, 11, 16, 11, 16, 10, 9, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + { + 1, 10, 6, 10, 7, 11, 9, 10, 8, 12, 9, 12, 9, 12, 10, 10, + 15, 16, 14, 15, 14, 16, 13, 12, 5, 12, 7, 11, 8, 11, 9, 10, + 9, 13, 9, 12, 10, 12, 10, 10, 16, 16, 14, 15, 13, 16, 13, 12, + 10, 15, 10, 13, 12, 14, 11, 11, 12, 16, 11, 13, 12, 14, 11, 11, + 16, 16, 14, 16, 14, 16, 13, 12, 5, 12, 8, 11, 7, 11, 9, 10, + 9, 13, 10, 12, 9, 12, 10, 10, 14, 16, 14, 15, 13, 14, 13, 12, + 7, 13, 9, 12, 9, 12, 10, 10, 9, 13, 9, 12, 9, 12, 10, 10, + 14, 16, 13, 14, 13, 15, 12, 12, 11, 16, 11, 13, 12, 14, 11, 11, + 12, 16, 11, 14, 12, 14, 11, 11, 16, 16, 14, 16, 14, 16, 13, 12, + 10, 16, 11, 14, 10, 13, 11, 11, 12, 16, 12, 14, 11, 13, 11, 11, + 15, 16, 15, 16, 14, 16, 13, 12, 11, 16, 12, 14, 11, 14, 11, 12, + 12, 16, 12, 14, 11, 14, 11, 11, 15, 16, 14, 16, 13, 16, 13, 12, + 13, 16, 13, 16, 13, 16, 12, 12, 13, 16, 13, 16, 13, 16, 12, 12, + 16, 16, 14, 15, 14, 16, 13, 12, 4, 11, 7, 10, 7, 11, 9, 10, + 9, 13, 9, 11, 9, 12, 10, 10, 15, 16, 14, 15, 14, 15, 13, 12, + 6, 12, 7, 11, 8, 11, 9, 10, 9, 13, 9, 12, 10, 12, 10, 10, + 15, 16, 13, 14, 14, 15, 12, 12, 10, 14, 10, 12, 12, 13, 11, 11, + 12, 16, 11, 13, 12, 14, 11, 11, 16, 16, 14, 15, 15, 16, 13, 12, + 6, 12, 8, 11, 8, 11, 9, 10, 9, 13, 10, 12, 9, 12, 10, 10, + 16, 16, 14, 15, 13, 14, 12, 12, 8, 13, 9, 11, 9, 12, 9, 10, + 9, 13, 9, 12, 9, 12, 9, 10, 14, 16, 13, 14, 13, 14, 12, 11, + 11, 15, 11, 13, 12, 14, 11, 11, 11, 16, 10, 13, 12, 14, 11, 11, + 15, 16, 13, 15, 14, 16, 12, 11, 10, 16, 12, 13, 10, 13, 11, 11, + 11, 16, 12, 14, 10, 13, 11, 11, 16, 16, 14, 16, 13, 16, 13, 12, + 11, 16, 12, 14, 10, 14, 11, 11, 11, 16, 12, 14, 10, 13, 11, 11, + 16, 16, 14, 16, 12, 15, 12, 11, 13, 16, 13, 15, 13, 15, 12, 12, + 13, 16, 12, 15, 12, 15, 12, 11, 15, 16, 13, 16, 13, 16, 12, 11, + 8, 14, 9, 12, 10, 13, 11, 11, 11, 16, 11, 13, 11, 13, 11, 11, + 16, 16, 16, 16, 16, 16, 14, 13, 9, 14, 10, 12, 10, 13, 11, 11, + 11, 16, 11, 13, 12, 13, 11, 11, 16, 16, 15, 16, 15, 16, 14, 12, + 11, 16, 11, 13, 12, 14, 12, 11, 13, 16, 12, 14, 13, 14, 12, 11, + 16, 16, 15, 16, 16, 16, 14, 13, 9, 14, 10, 13, 10, 13, 11, 11, + 11, 16, 11, 13, 11, 13, 11, 11, 16, 16, 15, 16, 14, 15, 14, 13, + 9, 14, 10, 13, 10, 13, 11, 11, 11, 15, 11, 13, 11, 13, 11, 11, + 16, 16, 14, 16, 14, 16, 13, 12, 12, 16, 12, 14, 13, 14, 12, 11, + 12, 16, 11, 14, 12, 15, 12, 11, 16, 16, 13, 16, 15, 16, 13, 11, + 11, 16, 12, 14, 11, 14, 12, 11, 13, 16, 13, 15, 12, 14, 12, 12, + 16, 16, 16, 16, 14, 16, 14, 13, 12, 16, 13, 15, 11, 14, 12, 12, + 12, 16, 13, 14, 11, 15, 12, 11, 16, 16, 15, 16, 13, 15, 13, 12, + 13, 16, 13, 15, 13, 16, 12, 12, 13, 16, 13, 15, 13, 15, 12, 12, + 15, 16, 13, 16, 13, 15, 11, 10, 10, 16, 12, 14, 12, 15, 12, 12, + 14, 16, 13, 15, 13, 16, 13, 12, 16, 16, 16, 16, 16, 16, 15, 13, + 10, 16, 12, 14, 12, 15, 12, 12, 13, 16, 13, 15, 13, 15, 13, 12, + 16, 16, 16, 16, 16, 16, 14, 13, 11, 16, 12, 15, 13, 16, 12, 12, + 14, 16, 13, 16, 13, 16, 12, 12, 16, 16, 15, 16, 15, 16, 14, 12, + 11, 16, 12, 14, 12, 16, 12, 12, 14, 16, 13, 15, 13, 15, 13, 12, + 16, 16, 16, 16, 16, 16, 15, 13, 11, 16, 12, 14, 12, 15, 12, 12, + 13, 16, 12, 14, 12, 15, 12, 12, 16, 16, 16, 16, 16, 16, 14, 12, + 12, 16, 12, 15, 13, 16, 12, 12, 13, 16, 12, 15, 13, 15, 12, 11, + 16, 16, 14, 16, 15, 16, 13, 12, 12, 16, 13, 16, 12, 16, 12, 12, + 15, 16, 14, 16, 13, 16, 12, 12, 16, 16, 16, 16, 16, 16, 14, 13, + 12, 16, 13, 15, 12, 16, 12, 12, 13, 16, 13, 15, 12, 15, 12, 12, + 16, 16, 15, 16, 14, 16, 13, 12, 13, 16, 13, 16, 12, 16, 12, 12, + 13, 16, 12, 16, 12, 15, 12, 12, 14, 16, 12, 14, 12, 14, 11, 10, + }, + }, + { + { + 0, 16, 6, 16, 8, 16, 16, 16, 9, 16, 11, 16, 12, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 4, 16, 7, 16, 11, 16, 16, 16, + 10, 16, 11, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 10, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 5, 16, 10, 16, 9, 16, 16, 16, + 10, 16, 13, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 16, 11, 16, 12, 16, 16, 16, 10, 16, 12, 16, 13, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 1, 16, 7, 16, 8, 16, 13, 16, + 9, 16, 11, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 4, 16, 7, 16, 11, 16, 13, 16, 9, 16, 11, 16, 13, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 9, 16, 16, 16, 16, 16, + 13, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 4, 16, 10, 16, 8, 16, 16, 16, 10, 16, 12, 16, 12, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 7, 16, 10, 16, 11, 16, 16, 16, + 9, 16, 11, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 12, 16, 16, 16, 16, 16, 13, 16, 12, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 10, 16, 16, 16, 11, 16, 16, 16, + 16, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 13, 16, 16, 16, 13, 16, 16, 16, 13, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 4, 16, 8, 16, 10, 16, 16, 16, 10, 16, 11, 16, 12, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 8, 16, 11, 16, 16, 16, + 10, 16, 12, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 9, 16, 9, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 10, 16, 10, 16, 16, 16, + 11, 16, 12, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 16, 11, 16, 11, 16, 16, 16, 10, 16, 12, 16, 12, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 12, 16, 16, 16, 16, 16, + 12, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 16, 16, 10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 16, 16, 12, 16, 16, 16, + 12, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 10, 16, 11, 16, 16, 16, + 11, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 16, 9, 16, 11, 16, 13, 16, 11, 16, 12, 16, 13, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 9, 16, 13, 16, 12, 16, + 13, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 16, 10, 16, 10, 16, 14, 16, 12, 16, 12, 16, 12, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 11, 16, 11, 16, 13, 16, + 10, 16, 12, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 10, 16, 13, 16, 12, 16, 12, 16, 11, 16, 16, 16, 13, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 12, 16, 10, 16, 13, 16, + 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 13, 16, 11, 16, 13, 16, 12, 16, 13, 16, 12, 16, 13, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 13, 16, 16, 16, 12, 16, + 13, 16, 12, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + { + 0, 10, 4, 10, 5, 11, 9, 11, 6, 11, 8, 11, 8, 12, 10, 12, + 15, 16, 13, 15, 14, 15, 13, 14, 4, 12, 5, 11, 8, 12, 9, 11, + 7, 13, 8, 12, 9, 13, 10, 12, 15, 16, 13, 15, 14, 16, 13, 14, + 10, 16, 9, 13, 12, 16, 11, 13, 11, 16, 10, 14, 13, 16, 12, 13, + 16, 16, 14, 16, 15, 16, 14, 15, 4, 12, 7, 12, 6, 12, 9, 11, + 8, 13, 9, 12, 9, 12, 10, 12, 15, 16, 13, 15, 14, 15, 13, 14, + 7, 13, 8, 12, 9, 13, 10, 12, 8, 13, 9, 12, 9, 13, 10, 12, + 14, 16, 13, 15, 13, 15, 13, 14, 12, 16, 11, 14, 13, 16, 12, 13, + 12, 16, 11, 14, 13, 16, 12, 13, 16, 16, 14, 16, 15, 16, 14, 15, + 10, 16, 12, 16, 10, 14, 12, 13, 12, 16, 13, 16, 11, 14, 12, 13, + 16, 16, 16, 16, 15, 16, 14, 15, 12, 16, 13, 16, 11, 15, 12, 13, + 13, 16, 13, 16, 12, 15, 12, 14, 16, 16, 16, 16, 14, 16, 13, 14, + 16, 16, 14, 16, 14, 16, 13, 15, 16, 16, 14, 16, 14, 16, 13, 15, + 16, 16, 16, 16, 16, 16, 14, 16, 2, 11, 5, 11, 6, 11, 9, 11, + 7, 12, 8, 11, 9, 12, 10, 12, 15, 16, 14, 14, 14, 14, 13, 14, + 4, 13, 6, 11, 8, 12, 9, 11, 8, 13, 8, 12, 10, 13, 10, 12, + 15, 16, 13, 15, 14, 15, 13, 14, 9, 16, 8, 13, 12, 15, 11, 12, + 11, 16, 10, 14, 13, 16, 12, 13, 16, 16, 14, 16, 16, 16, 14, 15, + 5, 13, 8, 12, 7, 12, 9, 11, 8, 13, 9, 12, 9, 12, 10, 12, + 16, 16, 14, 15, 14, 15, 13, 13, 7, 13, 8, 12, 9, 13, 10, 12, + 8, 13, 8, 12, 9, 13, 10, 12, 14, 16, 13, 14, 13, 15, 12, 13, + 11, 16, 10, 14, 13, 16, 12, 13, 11, 16, 10, 13, 12, 15, 11, 13, + 14, 16, 12, 14, 14, 16, 13, 14, 10, 16, 12, 15, 9, 14, 11, 13, + 12, 16, 12, 16, 11, 14, 12, 13, 16, 16, 15, 16, 16, 16, 14, 15, + 11, 16, 12, 15, 11, 15, 12, 13, 12, 16, 12, 15, 11, 14, 12, 13, + 16, 16, 14, 16, 13, 15, 13, 14, 15, 16, 14, 16, 14, 16, 13, 14, + 14, 16, 13, 16, 14, 16, 13, 14, 16, 16, 14, 16, 14, 16, 13, 14, + 7, 15, 8, 13, 9, 14, 11, 13, 10, 14, 10, 13, 11, 14, 12, 13, + 16, 16, 15, 16, 15, 16, 15, 14, 7, 16, 8, 13, 10, 14, 11, 13, + 11, 15, 10, 13, 12, 14, 12, 13, 16, 16, 16, 16, 16, 16, 15, 15, + 10, 16, 9, 13, 13, 16, 12, 13, 13, 16, 11, 14, 14, 16, 13, 14, + 16, 16, 16, 16, 16, 16, 15, 16, 8, 16, 10, 14, 9, 14, 11, 13, + 11, 16, 11, 14, 11, 14, 12, 13, 16, 16, 16, 16, 16, 16, 14, 15, + 8, 16, 10, 14, 10, 14, 11, 13, 10, 15, 10, 14, 11, 14, 12, 13, + 16, 16, 14, 16, 15, 16, 14, 14, 11, 16, 10, 14, 13, 16, 12, 13, + 11, 16, 10, 13, 13, 16, 12, 13, 16, 16, 13, 16, 16, 16, 14, 14, + 11, 16, 12, 16, 10, 15, 12, 13, 14, 16, 14, 16, 12, 16, 13, 14, + 16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 13, 16, 11, 16, 12, 14, + 12, 16, 13, 16, 11, 14, 12, 13, 16, 16, 16, 16, 14, 16, 14, 14, + 15, 16, 14, 16, 16, 16, 13, 14, 13, 16, 13, 15, 14, 16, 13, 14, + 14, 16, 13, 14, 14, 15, 13, 14, 9, 16, 11, 16, 12, 16, 13, 14, + 12, 16, 12, 15, 13, 16, 13, 14, 16, 16, 16, 15, 16, 16, 15, 15, + 10, 16, 10, 16, 12, 16, 12, 14, 12, 16, 12, 14, 13, 16, 13, 14, + 16, 16, 16, 16, 16, 16, 15, 15, 11, 16, 10, 14, 14, 16, 12, 13, + 14, 16, 12, 16, 14, 16, 13, 14, 16, 16, 16, 16, 16, 16, 16, 15, + 10, 16, 12, 16, 11, 16, 12, 14, 13, 16, 12, 15, 13, 16, 13, 14, + 16, 16, 16, 16, 16, 16, 16, 15, 10, 16, 11, 16, 12, 16, 12, 14, + 12, 16, 12, 15, 13, 16, 13, 14, 16, 16, 16, 16, 16, 16, 14, 14, + 11, 16, 10, 14, 14, 16, 12, 13, 13, 16, 11, 14, 14, 16, 12, 13, + 16, 16, 15, 16, 16, 16, 14, 14, 12, 16, 13, 16, 11, 16, 12, 14, + 15, 16, 14, 16, 13, 16, 13, 14, 16, 16, 16, 16, 16, 16, 14, 16, + 12, 16, 13, 16, 12, 16, 12, 14, 13, 16, 13, 16, 12, 16, 12, 13, + 16, 16, 16, 16, 16, 16, 14, 15, 13, 16, 13, 16, 14, 16, 12, 13, + 13, 16, 13, 14, 14, 16, 12, 13, 16, 16, 14, 14, 14, 15, 13, 13, + }, + { + 0, 9, 3, 9, 5, 9, 7, 9, 5, 10, 7, 11, 8, 11, 9, 10, + 16, 16, 16, 16, 16, 16, 16, 16, 2, 11, 4, 10, 7, 11, 8, 10, + 7, 16, 7, 11, 9, 16, 9, 11, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 16, 7, 16, 11, 16, 10, 11, 11, 16, 10, 16, 16, 16, 11, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 2, 11, 6, 10, 6, 10, 8, 10, + 7, 16, 8, 16, 8, 11, 9, 11, 16, 16, 16, 16, 16, 16, 16, 16, + 5, 13, 7, 11, 8, 11, 9, 11, 6, 12, 8, 12, 8, 12, 9, 11, + 16, 16, 16, 16, 16, 16, 16, 16, 10, 16, 10, 16, 12, 16, 10, 13, + 10, 16, 9, 16, 11, 16, 11, 12, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 16, 10, 16, 8, 16, 10, 12, 11, 16, 12, 16, 10, 16, 11, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 10, 16, 11, 16, 10, 16, 11, 16, + 11, 16, 12, 16, 10, 16, 11, 12, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + { + 1, 10, 5, 10, 6, 10, 9, 10, 7, 12, 9, 12, 9, 12, 10, 10, + 16, 16, 15, 16, 14, 16, 13, 13, 5, 12, 7, 11, 8, 11, 9, 10, + 8, 13, 9, 12, 10, 12, 10, 11, 16, 16, 16, 16, 14, 16, 13, 12, + 10, 16, 10, 13, 12, 14, 12, 12, 12, 16, 11, 14, 13, 15, 12, 12, + 16, 16, 16, 15, 16, 16, 14, 13, 5, 12, 8, 11, 7, 11, 9, 10, + 8, 13, 10, 12, 9, 12, 10, 10, 15, 16, 14, 15, 14, 14, 13, 13, + 7, 13, 9, 12, 9, 12, 10, 10, 9, 13, 10, 13, 10, 13, 10, 10, + 14, 16, 14, 15, 14, 16, 13, 12, 11, 16, 12, 14, 12, 15, 12, 12, + 12, 16, 12, 15, 13, 16, 12, 12, 16, 16, 15, 16, 16, 16, 14, 13, + 10, 16, 12, 14, 10, 14, 12, 12, 12, 16, 13, 14, 11, 14, 12, 12, + 16, 16, 16, 16, 14, 16, 14, 13, 11, 16, 12, 14, 11, 14, 12, 12, + 12, 16, 13, 16, 11, 15, 12, 12, 16, 16, 16, 16, 14, 16, 14, 13, + 13, 16, 14, 16, 14, 16, 13, 13, 13, 16, 13, 16, 13, 16, 13, 12, + 16, 16, 16, 16, 16, 16, 13, 13, 4, 11, 7, 10, 7, 11, 9, 10, + 8, 12, 9, 12, 9, 12, 10, 11, 15, 16, 14, 15, 14, 16, 13, 13, + 6, 12, 7, 11, 8, 11, 9, 10, 9, 13, 9, 12, 10, 12, 10, 10, + 16, 16, 15, 16, 15, 16, 13, 12, 10, 16, 10, 13, 12, 14, 12, 11, + 12, 16, 11, 14, 13, 14, 12, 12, 16, 16, 16, 14, 16, 16, 14, 13, + 6, 12, 8, 11, 7, 11, 9, 10, 9, 14, 10, 12, 9, 12, 10, 10, + 15, 16, 14, 16, 14, 16, 14, 13, 7, 13, 9, 12, 9, 12, 10, 10, + 9, 13, 9, 12, 9, 12, 10, 10, 14, 16, 13, 14, 14, 16, 12, 11, + 11, 16, 11, 14, 12, 14, 12, 12, 12, 16, 11, 14, 12, 14, 12, 11, + 16, 16, 13, 16, 14, 16, 13, 12, 10, 16, 12, 14, 10, 14, 11, 11, + 12, 16, 13, 14, 11, 14, 12, 12, 16, 16, 16, 16, 14, 16, 13, 13, + 11, 16, 12, 16, 11, 14, 12, 12, 12, 16, 12, 14, 11, 14, 12, 11, + 16, 16, 15, 16, 13, 15, 13, 12, 13, 16, 14, 16, 13, 16, 13, 12, + 13, 16, 13, 16, 13, 16, 13, 12, 16, 16, 14, 16, 14, 16, 12, 11, + 8, 13, 10, 12, 10, 13, 11, 11, 11, 14, 12, 14, 12, 14, 12, 12, + 16, 16, 16, 16, 16, 16, 14, 13, 9, 14, 10, 13, 10, 13, 11, 11, + 12, 16, 12, 13, 12, 13, 12, 11, 16, 16, 16, 16, 16, 16, 15, 14, + 12, 16, 11, 14, 13, 15, 12, 12, 13, 16, 12, 15, 14, 15, 13, 12, + 16, 16, 16, 16, 16, 16, 15, 13, 9, 14, 11, 13, 10, 13, 11, 11, + 11, 16, 12, 14, 12, 14, 12, 12, 16, 16, 16, 16, 16, 16, 16, 13, + 10, 15, 11, 13, 11, 14, 12, 11, 11, 16, 12, 14, 11, 14, 12, 11, + 16, 16, 16, 16, 16, 16, 14, 12, 12, 16, 12, 14, 13, 15, 13, 12, + 12, 16, 12, 14, 13, 15, 12, 12, 16, 16, 14, 16, 16, 16, 14, 12, + 12, 16, 13, 16, 11, 14, 12, 12, 14, 16, 14, 16, 12, 16, 13, 12, + 16, 16, 16, 16, 16, 16, 16, 13, 12, 16, 13, 16, 12, 16, 13, 12, + 12, 16, 13, 16, 12, 16, 12, 12, 16, 16, 16, 16, 14, 16, 14, 12, + 14, 16, 14, 16, 14, 16, 14, 13, 13, 16, 13, 16, 13, 16, 13, 12, + 16, 16, 13, 16, 13, 16, 12, 11, 9, 16, 12, 15, 13, 16, 13, 12, + 13, 16, 14, 16, 14, 16, 14, 13, 16, 16, 16, 16, 16, 16, 16, 14, + 10, 16, 12, 15, 12, 15, 13, 12, 13, 16, 14, 16, 13, 16, 13, 12, + 16, 16, 16, 16, 16, 16, 16, 13, 12, 16, 12, 16, 13, 16, 13, 12, + 14, 16, 13, 16, 14, 16, 13, 12, 16, 16, 16, 16, 16, 16, 16, 13, + 11, 16, 12, 15, 12, 16, 13, 12, 14, 16, 14, 16, 13, 16, 13, 13, + 16, 16, 16, 16, 16, 16, 15, 13, 11, 16, 12, 16, 12, 16, 13, 12, + 13, 16, 13, 15, 13, 16, 13, 12, 16, 16, 16, 16, 16, 16, 15, 13, + 12, 16, 12, 16, 13, 16, 13, 12, 13, 16, 12, 16, 13, 16, 13, 12, + 16, 16, 14, 16, 16, 16, 14, 12, 12, 16, 14, 16, 11, 16, 13, 12, + 14, 16, 14, 16, 13, 16, 13, 12, 16, 16, 16, 16, 16, 16, 16, 13, + 12, 16, 13, 16, 12, 16, 13, 12, 13, 16, 13, 16, 12, 16, 13, 12, + 16, 16, 16, 16, 14, 16, 14, 12, 13, 16, 13, 16, 13, 16, 13, 13, + 13, 16, 12, 16, 12, 16, 12, 12, 14, 16, 13, 15, 13, 16, 12, 11, + }, + }, +}; + + +static const uint8_t rv34_table_intra_secondpat[NUM_INTRA_TABLES][2][OTHERBLK_VLC_SIZE] = { + { + { + 0, 5, 10, 3, 6, 10, 7, 8, 9, 4, 6, 10, 6, 7, 9, 8, + 8, 9, 8, 8, 9, 8, 9, 9, 9, 9, 8, 3, 6, 10, 4, 6, + 10, 7, 7, 9, 5, 7, 10, 6, 7, 9, 7, 7, 8, 7, 8, 9, + 8, 8, 9, 8, 8, 7, 6, 8, 10, 6, 8, 10, 7, 8, 9, 7, + 8, 10, 7, 8, 10, 8, 8, 8, 8, 9, 9, 8, 8, 9, 9, 8, + 7, 7, 8, 9, 7, 8, 9, 7, 7, 7, 8, 8, 9, 7, 8, 9, + 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 6, 5, + }, + { + 0, 5, 11, 3, 6, 11, 8, 9, 11, 3, 6, 10, 6, 7, 11, 9, + 9, 11, 7, 9, 11, 9, 9, 11, 10, 10, 11, 2, 6, 10, 4, 7, + 10, 7, 9, 11, 4, 7, 11, 6, 7, 10, 9, 9, 11, 7, 9, 11, + 8, 9, 10, 10, 10, 10, 5, 8, 11, 6, 8, 11, 8, 9, 11, 6, + 8, 11, 7, 8, 11, 9, 9, 11, 8, 10, 11, 9, 9, 11, 10, 10, + 10, 8, 9, 11, 8, 9, 11, 9, 9, 10, 8, 9, 11, 8, 9, 11, + 9, 9, 10, 8, 9, 10, 9, 9, 10, 9, 9, 8, + }, + }, + { + { + 0, 5, 10, 4, 6, 10, 7, 8, 10, 4, 6, 10, 6, 7, 9, 8, + 8, 9, 8, 8, 9, 8, 9, 9, 9, 9, 9, 2, 6, 10, 4, 6, + 10, 7, 7, 9, 5, 7, 10, 6, 7, 9, 7, 7, 9, 7, 8, 9, + 8, 8, 9, 9, 8, 8, 6, 8, 10, 6, 8, 10, 7, 8, 9, 6, + 8, 10, 7, 8, 10, 8, 8, 9, 8, 9, 10, 8, 8, 9, 9, 9, + 8, 8, 8, 10, 7, 8, 9, 7, 8, 8, 7, 8, 10, 7, 8, 9, + 7, 7, 8, 8, 8, 9, 8, 8, 8, 7, 7, 6, + }, + { + 0, 5, 12, 4, 7, 12, 8, 10, 13, 4, 7, 12, 6, 8, 12, 10, + 10, 12, 8, 9, 12, 10, 10, 12, 12, 12, 12, 1, 6, 12, 4, 7, + 12, 8, 9, 12, 4, 7, 12, 6, 8, 11, 9, 10, 12, 8, 9, 12, + 9, 10, 11, 11, 11, 12, 6, 8, 12, 7, 9, 12, 9, 10, 13, 6, + 9, 12, 8, 9, 12, 10, 10, 12, 9, 10, 12, 10, 10, 12, 12, 12, + 12, 8, 10, 12, 9, 10, 12, 10, 10, 12, 8, 10, 12, 9, 10, 12, + 10, 10, 11, 9, 10, 12, 10, 10, 11, 11, 10, 10, + }, + }, + { + { + 0, 5, 10, 3, 6, 10, 7, 8, 11, 4, 6, 10, 6, 7, 10, 8, + 9, 10, 8, 8, 10, 9, 9, 10, 10, 10, 10, 2, 6, 10, 4, 6, + 10, 7, 8, 10, 4, 7, 10, 6, 7, 10, 8, 8, 10, 7, 8, 10, + 8, 8, 9, 10, 9, 9, 5, 8, 11, 6, 8, 10, 7, 9, 10, 6, + 8, 11, 7, 8, 10, 8, 8, 10, 8, 9, 11, 9, 9, 10, 10, 9, + 9, 8, 9, 10, 8, 9, 10, 8, 9, 10, 8, 9, 10, 8, 8, 10, + 8, 8, 9, 8, 9, 10, 8, 8, 9, 9, 8, 8, + }, + { + 0, 6, 13, 4, 7, 14, 9, 11, 14, 3, 7, 13, 7, 8, 13, 11, + 11, 14, 8, 10, 13, 10, 11, 13, 13, 13, 14, 1, 6, 12, 4, 8, + 13, 9, 10, 15, 4, 8, 13, 7, 8, 12, 11, 11, 14, 8, 10, 13, + 10, 10, 13, 13, 13, 14, 5, 9, 13, 7, 9, 13, 10, 11, 14, 6, + 10, 14, 8, 10, 14, 11, 11, 14, 9, 11, 14, 11, 11, 13, 13, 13, + 14, 9, 10, 14, 9, 11, 13, 11, 12, 14, 9, 11, 13, 9, 11, 14, + 11, 12, 13, 10, 12, 15, 11, 11, 13, 13, 12, 13, + }, + }, + { + { + 0, 5, 11, 3, 6, 11, 7, 9, 12, 3, 6, 11, 6, 7, 11, 9, + 9, 11, 8, 9, 11, 9, 9, 11, 11, 11, 12, 2, 6, 11, 4, 6, + 11, 7, 9, 11, 4, 7, 11, 5, 7, 10, 9, 9, 11, 7, 8, 11, + 9, 9, 10, 11, 11, 11, 5, 8, 11, 6, 8, 11, 8, 9, 12, 6, + 8, 11, 7, 8, 11, 9, 9, 11, 8, 9, 12, 9, 9, 11, 11, 11, + 11, 8, 10, 12, 8, 10, 11, 9, 10, 12, 8, 10, 12, 8, 9, 12, + 10, 10, 12, 9, 10, 12, 9, 9, 11, 11, 10, 11, + }, + { + 0, 6, 13, 3, 8, 14, 10, 12, 16, 3, 8, 15, 7, 9, 15, 12, + 13, 15, 9, 11, 15, 11, 12, 16, 14, 16, 16, 1, 7, 13, 4, 8, + 14, 9, 11, 15, 4, 8, 14, 7, 9, 14, 12, 13, 15, 8, 10, 14, + 11, 11, 14, 16, 14, 16, 6, 9, 14, 7, 10, 14, 11, 13, 15, 7, + 10, 14, 9, 10, 13, 12, 12, 15, 10, 11, 14, 11, 11, 14, 14, 14, + 16, 9, 11, 14, 10, 11, 14, 13, 14, 15, 9, 12, 14, 10, 12, 16, + 13, 14, 16, 10, 13, 16, 12, 12, 14, 15, 14, 15, + }, + }, + { + { + 0, 6, 12, 3, 7, 12, 9, 11, 13, 4, 7, 12, 6, 8, 12, 10, + 11, 13, 8, 10, 13, 10, 11, 13, 13, 13, 14, 1, 6, 12, 4, 7, + 12, 9, 10, 14, 4, 7, 12, 6, 7, 12, 10, 11, 13, 8, 9, 13, + 10, 10, 12, 13, 13, 14, 6, 9, 13, 7, 9, 13, 10, 12, 14, 7, + 9, 13, 8, 10, 13, 11, 11, 14, 9, 11, 13, 11, 11, 14, 13, 13, + 14, 10, 12, 14, 10, 12, 14, 12, 13, 15, 10, 12, 14, 10, 12, 14, + 12, 13, 15, 11, 13, 15, 12, 12, 15, 14, 14, 14, + }, + { + 0, 6, 16, 3, 8, 16, 10, 13, 16, 3, 8, 16, 7, 9, 16, 13, + 16, 16, 8, 10, 16, 11, 13, 16, 16, 16, 16, 1, 7, 14, 4, 8, + 16, 10, 12, 16, 4, 8, 13, 7, 9, 16, 13, 14, 16, 8, 10, 16, + 11, 11, 14, 16, 16, 16, 6, 9, 14, 8, 10, 14, 12, 16, 16, 6, + 10, 13, 9, 11, 16, 13, 14, 16, 9, 12, 16, 12, 11, 16, 16, 16, + 16, 10, 12, 16, 11, 12, 16, 16, 14, 16, 9, 12, 16, 11, 12, 16, + 16, 15, 16, 10, 13, 16, 12, 13, 16, 16, 16, 16, + }, + }, +}; + +static const uint8_t rv34_table_intra_thirdpat[NUM_INTRA_TABLES][2][OTHERBLK_VLC_SIZE] = { + { + { + 0, 5, 10, 3, 6, 10, 7, 8, 10, 4, 7, 10, 6, 7, 10, 8, + 8, 10, 8, 9, 10, 9, 9, 10, 9, 9, 9, 2, 6, 10, 4, 7, + 10, 7, 8, 9, 5, 7, 10, 6, 7, 10, 8, 8, 9, 8, 9, 10, + 8, 8, 9, 9, 9, 8, 6, 8, 11, 6, 8, 10, 7, 8, 10, 6, + 8, 11, 7, 8, 10, 8, 8, 9, 8, 9, 10, 9, 9, 10, 9, 9, + 9, 7, 8, 10, 7, 8, 10, 7, 8, 8, 7, 8, 10, 7, 8, 9, + 7, 8, 8, 8, 8, 9, 8, 8, 8, 7, 7, 7, + }, + { + 0, 4, 10, 3, 6, 10, 7, 8, 11, 3, 6, 10, 5, 7, 10, 9, + 9, 11, 9, 10, 11, 9, 10, 11, 11, 11, 11, 2, 6, 10, 4, 6, + 10, 7, 8, 10, 4, 7, 10, 6, 7, 10, 8, 9, 10, 8, 9, 11, + 9, 9, 11, 10, 10, 11, 6, 8, 11, 6, 8, 11, 8, 9, 11, 7, + 9, 11, 7, 8, 11, 9, 9, 11, 9, 10, 12, 10, 10, 12, 11, 11, + 11, 8, 9, 11, 8, 9, 11, 9, 9, 11, 9, 10, 11, 9, 10, 11, + 9, 10, 11, 10, 11, 12, 10, 10, 12, 10, 10, 10, + }, + }, + { + { + 0, 5, 10, 3, 6, 10, 7, 8, 10, 4, 7, 10, 6, 7, 10, 8, + 9, 10, 8, 9, 11, 8, 9, 10, 10, 10, 10, 2, 6, 10, 4, 6, + 10, 7, 8, 10, 4, 7, 10, 5, 7, 10, 8, 8, 10, 8, 9, 10, + 8, 9, 10, 9, 9, 9, 5, 7, 11, 6, 8, 11, 7, 8, 11, 6, + 8, 11, 7, 8, 10, 8, 9, 10, 8, 9, 11, 9, 9, 10, 10, 9, + 10, 7, 8, 10, 7, 8, 10, 8, 9, 10, 8, 9, 10, 8, 9, 10, + 8, 8, 10, 9, 9, 10, 9, 9, 10, 9, 9, 9, + }, + { + 0, 5, 11, 3, 6, 11, 8, 9, 12, 4, 7, 12, 6, 7, 12, 9, + 10, 13, 10, 11, 13, 10, 11, 14, 12, 13, 14, 1, 6, 11, 4, 7, + 11, 8, 9, 12, 5, 7, 11, 6, 8, 12, 9, 10, 13, 10, 11, 14, + 10, 11, 13, 12, 12, 14, 6, 8, 12, 7, 9, 13, 9, 10, 14, 7, + 10, 13, 8, 10, 12, 11, 11, 13, 11, 13, 14, 11, 12, 14, 13, 13, + 15, 9, 10, 12, 9, 11, 14, 10, 11, 14, 11, 11, 13, 10, 11, 13, + 11, 12, 14, 12, 14, 15, 13, 13, 14, 13, 13, 14, + }, + }, + { + { + 0, 5, 11, 3, 6, 11, 7, 9, 11, 4, 6, 11, 5, 7, 10, 9, + 9, 11, 8, 9, 11, 9, 10, 11, 11, 11, 11, 2, 6, 10, 3, 6, + 10, 7, 9, 11, 4, 7, 10, 5, 7, 10, 8, 9, 11, 8, 9, 11, + 9, 9, 11, 11, 11, 11, 5, 8, 11, 6, 8, 11, 8, 10, 12, 6, + 8, 11, 7, 8, 11, 9, 10, 11, 9, 10, 12, 9, 10, 11, 11, 11, + 11, 8, 9, 11, 8, 10, 12, 9, 11, 12, 8, 10, 12, 9, 10, 12, + 10, 11, 12, 10, 11, 12, 10, 10, 11, 11, 11, 11, + }, + { + 0, 5, 13, 2, 7, 16, 9, 11, 16, 4, 8, 16, 7, 9, 16, 12, + 12, 16, 12, 16, 16, 12, 16, 16, 16, 16, 16, 1, 6, 13, 4, 8, + 16, 9, 11, 16, 6, 9, 16, 7, 10, 16, 13, 13, 16, 13, 15, 16, + 12, 16, 16, 16, 16, 16, 7, 9, 16, 8, 11, 15, 11, 13, 16, 10, + 12, 16, 10, 12, 16, 16, 13, 16, 16, 16, 16, 14, 16, 16, 16, 16, + 16, 12, 12, 16, 12, 16, 16, 16, 16, 16, 13, 14, 16, 12, 13, 16, + 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, + }, + }, + { + { + 0, 6, 11, 3, 7, 11, 8, 10, 12, 4, 7, 11, 6, 8, 11, 10, + 11, 12, 9, 10, 12, 10, 10, 12, 12, 12, 13, 1, 6, 11, 4, 7, + 11, 8, 10, 12, 4, 7, 11, 6, 8, 11, 10, 10, 12, 9, 10, 12, + 10, 10, 12, 13, 13, 13, 6, 8, 12, 7, 10, 12, 10, 12, 13, 7, + 9, 12, 8, 10, 12, 11, 11, 13, 11, 12, 14, 11, 11, 13, 13, 13, + 13, 9, 11, 13, 10, 12, 14, 12, 13, 15, 10, 12, 14, 11, 12, 14, + 13, 13, 14, 12, 13, 15, 13, 13, 14, 14, 14, 14, + }, + { + 0, 5, 16, 2, 6, 16, 10, 14, 16, 4, 8, 16, 7, 9, 16, 11, + 16, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16, 1, 6, 12, 4, 8, + 12, 12, 12, 16, 6, 8, 16, 8, 10, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 12, 16, 16, 7, 10, 16, 8, 11, 14, 16, 16, 16, 10, + 12, 16, 10, 16, 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + }, + { + { + 0, 5, 11, 3, 6, 11, 10, 10, 12, 3, 7, 11, 6, 8, 11, 11, + 11, 12, 10, 10, 12, 11, 11, 13, 14, 13, 14, 1, 6, 11, 4, 7, + 11, 10, 11, 13, 5, 7, 11, 7, 8, 11, 11, 11, 13, 10, 11, 13, + 11, 11, 12, 13, 13, 14, 7, 10, 12, 9, 11, 13, 12, 13, 14, 9, + 10, 13, 9, 10, 13, 12, 11, 13, 12, 13, 16, 12, 13, 13, 14, 14, + 14, 11, 14, 16, 12, 14, 15, 14, 13, 16, 13, 13, 15, 13, 14, 16, + 14, 13, 16, 13, 13, 16, 13, 14, 15, 15, 14, 15, + }, + { + 0, 4, 16, 2, 7, 16, 10, 16, 16, 4, 10, 16, 7, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 1, 6, 13, 4, 11, + 16, 16, 16, 16, 6, 10, 16, 8, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 8, 16, 16, 10, 16, 16, 16, 16, 16, 10, + 16, 16, 10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + }, +}; + + +static const uint8_t rv34_intra_coeff[NUM_INTRA_TABLES][COEFF_VLC_SIZE] = { +{ + 1, 3, 3, 4, 4, 5, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9, + 9, 9, 10, 10, 10, 11, 11, 11, 10, 10, 10, 12, 13, 14, 15, 15, +}, +{ + 1, 2, 3, 5, 5, 6, 6, 7, 7, 8, 8, 9, 10, 10, 10, 11, + 11, 11, 12, 12, 13, 13, 13, 13, 13, 13, 13, 14, 16, 16, 16, 16, +}, +{ + 1, 2, 3, 4, 5, 6, 8, 8, 9, 9, 10, 10, 11, 12, 12, 12, + 13, 13, 14, 14, 14, 14, 16, 16, 14, 16, 16, 16, 14, 16, 16, 16, +}, +{ + 1, 2, 3, 4, 5, 6, 8, 8, 9, 9, 10, 10, 11, 12, 12, 12, + 13, 13, 16, 16, 16, 16, 16, 16, 16, 16, 14, 12, 16, 16, 16, 16, +}, +{ + 1, 2, 3, 4, 5, 7, 7, 8, 8, 9, 10, 10, 12, 11, 13, 12, + 15, 13, 14, 13, 12, 15, 14, 13, 12, 12, 10, 11, 16, 16, 16, 16, +} +}; + + +static const uint8_t rv34_inter_cbppat[NUM_INTER_TABLES][CBPPAT_VLC_SIZE] = { +{ + 7, 9, 9, 8, 9, 8, 9, 8, 9, 9, 8, 8, 8, 8, 8, 4, + 7, 10, 11, 10, 11, 10, 12, 10, 12, 11, 11, 10, 11, 10, 10, 7, + 10, 11, 15, 12, 15, 12, 15, 12, 15, 14, 14, 12, 14, 12, 14, 9, + 7, 11, 10, 10, 12, 11, 11, 10, 11, 12, 10, 10, 11, 10, 10, 7, + 8, 12, 12, 11, 13, 12, 12, 10, 13, 13, 12, 10, 12, 11, 11, 7, + 11, 13, 15, 11, 15, 13, 15, 12, 16, 14, 14, 12, 15, 13, 13, 9, + 10, 15, 11, 12, 15, 14, 14, 12, 15, 15, 12, 12, 14, 14, 12, 9, + 11, 15, 13, 12, 16, 15, 14, 12, 15, 15, 13, 12, 15, 14, 13, 9, + 13, 15, 14, 10, 16, 15, 16, 11, 16, 16, 15, 12, 16, 15, 15, 9, + 7, 11, 11, 11, 11, 10, 11, 10, 11, 12, 11, 10, 10, 10, 10, 7, + 9, 12, 13, 12, 12, 11, 13, 10, 13, 13, 12, 11, 12, 10, 11, 7, + 12, 13, 16, 14, 15, 12, 16, 12, 16, 15, 15, 13, 15, 12, 14, 9, + 9, 13, 13, 12, 13, 12, 13, 11, 13, 13, 12, 11, 12, 11, 11, 7, + 9, 13, 13, 12, 13, 12, 13, 11, 13, 13, 13, 11, 12, 11, 11, 7, + 12, 14, 15, 13, 16, 13, 15, 11, 16, 14, 15, 12, 15, 12, 13, 8, + 12, 16, 14, 14, 16, 15, 15, 13, 16, 15, 14, 13, 15, 14, 13, 9, + 12, 15, 14, 13, 15, 14, 15, 12, 16, 15, 14, 12, 14, 13, 13, 8, + 13, 16, 16, 12, 16, 14, 16, 11, 16, 16, 15, 12, 16, 14, 14, 8, + 10, 15, 15, 15, 12, 12, 14, 12, 14, 15, 15, 14, 12, 12, 13, 9, + 11, 15, 16, 14, 13, 12, 15, 12, 16, 15, 15, 14, 14, 12, 13, 9, + 14, 15, 16, 16, 15, 11, 16, 12, 16, 16, 16, 15, 16, 12, 15, 9, + 12, 16, 16, 15, 14, 14, 14, 13, 16, 16, 15, 14, 14, 13, 13, 9, + 12, 15, 15, 14, 14, 13, 15, 12, 16, 15, 14, 13, 14, 13, 13, 8, + 13, 16, 16, 15, 16, 12, 16, 11, 16, 16, 16, 14, 16, 13, 14, 8, + 14, 16, 16, 16, 16, 16, 15, 14, 16, 16, 16, 15, 16, 15, 14, 11, + 13, 16, 16, 15, 16, 15, 15, 12, 16, 16, 16, 14, 15, 14, 14, 9, + 14, 16, 16, 13, 16, 14, 16, 10, 16, 16, 16, 13, 16, 14, 14, 8, + 7, 12, 11, 11, 11, 11, 12, 10, 11, 11, 10, 10, 10, 10, 10, 7, + 9, 13, 13, 12, 13, 12, 13, 11, 13, 13, 12, 11, 12, 11, 11, 8, + 12, 14, 16, 14, 16, 14, 16, 13, 16, 14, 15, 13, 15, 13, 14, 9, + 9, 13, 12, 12, 13, 12, 13, 11, 12, 13, 11, 10, 12, 11, 11, 7, + 9, 13, 13, 12, 13, 12, 13, 11, 13, 13, 12, 11, 12, 11, 11, 7, + 12, 14, 16, 13, 16, 14, 15, 12, 15, 15, 14, 12, 15, 13, 13, 8, + 11, 15, 13, 14, 15, 15, 14, 13, 15, 15, 12, 12, 14, 14, 12, 9, + 11, 15, 14, 13, 15, 14, 14, 12, 15, 14, 13, 11, 14, 13, 12, 8, + 13, 16, 15, 12, 16, 15, 16, 12, 16, 16, 14, 11, 15, 14, 14, 8, + 8, 13, 13, 12, 12, 12, 13, 11, 12, 13, 12, 11, 11, 10, 10, 7, + 9, 13, 14, 12, 13, 12, 13, 11, 13, 13, 13, 11, 12, 11, 11, 7, + 12, 14, 16, 14, 15, 13, 15, 12, 15, 15, 15, 13, 14, 12, 13, 8, + 9, 13, 13, 12, 13, 12, 13, 11, 13, 13, 12, 11, 12, 11, 11, 7, + 9, 13, 12, 12, 13, 12, 12, 10, 13, 13, 12, 10, 12, 10, 10, 6, + 11, 14, 14, 12, 14, 12, 14, 11, 14, 14, 13, 11, 13, 11, 12, 7, + 12, 16, 14, 14, 15, 15, 14, 13, 15, 15, 13, 12, 14, 13, 12, 8, + 11, 14, 13, 12, 14, 13, 13, 11, 14, 14, 13, 11, 13, 12, 11, 7, + 11, 14, 14, 12, 15, 13, 14, 11, 15, 14, 13, 11, 14, 12, 12, 6, + 11, 16, 15, 15, 13, 14, 15, 13, 14, 15, 15, 13, 12, 12, 12, 9, + 12, 15, 15, 14, 14, 13, 15, 12, 15, 15, 14, 13, 13, 11, 12, 8, + 13, 16, 16, 15, 16, 13, 16, 13, 16, 16, 15, 14, 14, 12, 14, 8, + 11, 16, 15, 14, 14, 14, 14, 13, 15, 15, 14, 13, 13, 12, 12, 8, + 11, 14, 14, 13, 13, 12, 14, 11, 14, 14, 13, 12, 12, 11, 11, 7, + 12, 14, 15, 13, 14, 12, 14, 11, 15, 14, 14, 12, 13, 11, 12, 7, + 13, 16, 16, 16, 16, 15, 16, 14, 16, 16, 15, 14, 15, 14, 13, 9, + 12, 15, 14, 13, 15, 13, 14, 12, 15, 15, 13, 12, 13, 12, 12, 7, + 11, 15, 14, 12, 14, 13, 14, 10, 15, 14, 13, 11, 13, 11, 11, 5, + 10, 15, 15, 15, 15, 14, 15, 13, 12, 14, 12, 12, 12, 13, 12, 9, + 12, 16, 16, 15, 16, 15, 16, 14, 14, 15, 14, 13, 14, 13, 13, 9, + 14, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 14, 16, 14, 15, 11, + 11, 15, 15, 14, 15, 15, 15, 14, 14, 15, 12, 12, 13, 13, 12, 9, + 12, 15, 15, 14, 16, 14, 15, 13, 14, 14, 13, 12, 14, 13, 12, 8, + 13, 16, 16, 15, 16, 16, 16, 14, 16, 16, 15, 12, 16, 14, 14, 9, + 13, 16, 14, 16, 16, 16, 16, 15, 15, 16, 11, 12, 16, 15, 12, 9, + 13, 16, 15, 14, 16, 15, 16, 14, 15, 16, 12, 11, 15, 14, 13, 8, + 13, 16, 16, 13, 16, 16, 16, 13, 16, 16, 13, 11, 16, 14, 14, 8, + 11, 15, 15, 15, 14, 14, 15, 13, 13, 15, 14, 13, 12, 12, 12, 9, + 11, 15, 16, 14, 15, 14, 15, 13, 14, 14, 14, 13, 13, 12, 13, 8, + 13, 16, 16, 16, 16, 15, 16, 14, 16, 16, 16, 13, 15, 12, 14, 9, + 11, 16, 15, 14, 14, 14, 15, 13, 14, 14, 13, 12, 13, 12, 11, 8, + 11, 14, 14, 13, 14, 13, 14, 12, 13, 13, 12, 11, 12, 11, 11, 7, + 12, 15, 15, 13, 15, 14, 15, 12, 15, 14, 14, 11, 13, 12, 12, 7, + 13, 16, 15, 15, 16, 16, 16, 14, 15, 16, 12, 12, 14, 14, 12, 8, + 11, 15, 14, 13, 15, 13, 14, 12, 14, 14, 12, 11, 13, 12, 11, 6, + 11, 14, 14, 12, 15, 13, 14, 11, 15, 14, 12, 10, 13, 11, 11, 5, + 12, 16, 16, 16, 15, 15, 16, 15, 14, 16, 15, 15, 10, 12, 12, 9, + 13, 16, 16, 16, 15, 14, 16, 13, 15, 15, 15, 14, 12, 11, 13, 8, + 14, 16, 16, 16, 16, 14, 16, 13, 16, 16, 16, 14, 14, 11, 14, 8, + 13, 16, 16, 15, 15, 15, 15, 14, 15, 16, 14, 13, 12, 12, 11, 8, + 11, 15, 15, 13, 14, 13, 14, 12, 14, 14, 13, 12, 12, 11, 11, 6, + 11, 15, 15, 13, 15, 12, 14, 11, 14, 14, 13, 11, 12, 10, 11, 5, + 13, 16, 16, 15, 16, 16, 16, 14, 16, 16, 14, 14, 14, 13, 11, 8, + 11, 14, 14, 13, 14, 13, 14, 11, 14, 14, 12, 11, 12, 11, 10, 5, + 10, 13, 13, 11, 13, 12, 13, 9, 13, 13, 12, 9, 12, 10, 10, 3, +}, +{ + 5, 7, 7, 7, 7, 7, 8, 7, 7, 8, 7, 7, 7, 7, 7, 4, + 7, 9, 11, 9, 11, 9, 11, 9, 11, 10, 10, 9, 10, 9, 10, 6, + 11, 11, 14, 11, 14, 11, 14, 11, 15, 13, 14, 12, 14, 12, 13, 9, + 6, 11, 10, 9, 11, 10, 11, 9, 11, 11, 9, 9, 10, 10, 9, 6, + 8, 11, 11, 10, 12, 11, 12, 10, 12, 12, 11, 10, 12, 11, 11, 7, + 11, 13, 14, 11, 15, 13, 15, 11, 15, 14, 14, 12, 14, 13, 13, 9, + 10, 14, 11, 11, 15, 14, 13, 12, 14, 14, 11, 11, 14, 13, 12, 9, + 11, 14, 13, 11, 15, 14, 14, 11, 15, 15, 13, 11, 14, 14, 13, 9, + 12, 14, 14, 10, 16, 15, 16, 11, 16, 16, 15, 11, 16, 15, 14, 9, + 6, 10, 11, 10, 10, 9, 11, 9, 10, 11, 10, 10, 9, 9, 9, 6, + 9, 12, 12, 11, 12, 10, 12, 10, 12, 12, 12, 11, 11, 10, 11, 7, + 12, 13, 15, 13, 14, 11, 15, 11, 15, 15, 14, 13, 14, 12, 14, 9, + 9, 12, 12, 11, 12, 11, 12, 11, 12, 13, 11, 11, 12, 11, 11, 7, + 9, 12, 12, 11, 13, 11, 12, 10, 13, 13, 12, 11, 12, 11, 11, 7, + 12, 14, 15, 12, 15, 12, 14, 11, 15, 15, 14, 12, 14, 13, 13, 8, + 12, 15, 14, 13, 15, 14, 14, 13, 16, 16, 14, 13, 15, 14, 13, 9, + 12, 15, 14, 13, 15, 14, 14, 12, 15, 15, 13, 12, 14, 13, 13, 9, + 13, 15, 15, 12, 16, 14, 15, 11, 16, 16, 15, 12, 15, 14, 14, 9, + 10, 14, 14, 14, 12, 11, 13, 12, 14, 15, 14, 13, 12, 11, 12, 9, + 12, 14, 15, 14, 13, 11, 14, 12, 15, 15, 15, 14, 13, 11, 13, 9, + 13, 15, 16, 15, 14, 11, 16, 11, 16, 16, 16, 14, 15, 12, 15, 9, + 12, 15, 15, 14, 14, 14, 14, 13, 15, 15, 14, 14, 14, 13, 13, 9, + 12, 15, 15, 14, 14, 13, 14, 12, 15, 15, 14, 13, 14, 13, 13, 9, + 13, 15, 16, 14, 15, 13, 16, 11, 16, 16, 15, 14, 15, 13, 14, 9, + 14, 16, 16, 16, 16, 16, 15, 14, 16, 16, 16, 16, 16, 16, 14, 11, + 14, 16, 16, 14, 16, 15, 15, 12, 16, 16, 16, 14, 15, 14, 14, 9, + 14, 16, 16, 14, 16, 14, 16, 11, 16, 16, 16, 14, 16, 14, 14, 9, + 6, 11, 10, 10, 10, 10, 11, 10, 10, 11, 9, 9, 9, 9, 9, 6, + 9, 12, 12, 11, 13, 11, 13, 11, 12, 12, 11, 11, 12, 11, 11, 7, + 12, 14, 16, 13, 16, 14, 16, 13, 15, 14, 15, 12, 15, 13, 14, 9, + 8, 12, 11, 11, 12, 12, 12, 11, 11, 12, 10, 10, 11, 11, 10, 7, + 9, 12, 12, 11, 13, 12, 13, 11, 13, 12, 11, 10, 12, 11, 11, 7, + 12, 14, 15, 12, 15, 14, 15, 12, 15, 14, 14, 12, 14, 13, 13, 9, + 11, 15, 13, 13, 15, 14, 14, 13, 14, 15, 11, 11, 14, 14, 12, 9, + 11, 14, 13, 12, 15, 14, 14, 12, 14, 14, 12, 11, 14, 13, 12, 8, + 13, 15, 15, 12, 16, 15, 15, 12, 15, 15, 14, 11, 15, 14, 14, 8, + 8, 12, 12, 11, 11, 11, 12, 11, 11, 12, 11, 11, 10, 10, 10, 7, + 9, 13, 13, 12, 13, 11, 13, 11, 12, 13, 12, 11, 11, 10, 11, 7, + 12, 14, 15, 14, 15, 13, 15, 12, 15, 14, 14, 13, 14, 12, 13, 9, + 9, 13, 12, 12, 12, 12, 12, 11, 12, 13, 11, 11, 11, 11, 10, 7, + 9, 12, 12, 11, 12, 11, 12, 10, 12, 12, 11, 10, 11, 10, 10, 7, + 11, 13, 14, 12, 14, 12, 14, 11, 14, 13, 13, 11, 13, 11, 12, 7, + 12, 15, 14, 13, 15, 14, 14, 13, 15, 15, 13, 12, 13, 13, 12, 9, + 11, 14, 13, 12, 14, 13, 13, 11, 14, 14, 12, 11, 13, 12, 11, 7, + 11, 14, 14, 12, 14, 13, 14, 11, 14, 14, 13, 11, 13, 12, 12, 7, + 11, 15, 15, 14, 13, 13, 14, 13, 14, 15, 14, 13, 11, 11, 12, 9, + 12, 15, 15, 14, 14, 12, 14, 12, 14, 14, 14, 13, 12, 11, 12, 8, + 13, 16, 16, 15, 15, 12, 16, 13, 16, 15, 15, 14, 14, 12, 14, 9, + 12, 15, 15, 14, 14, 14, 14, 13, 15, 15, 14, 13, 12, 12, 12, 9, + 11, 14, 14, 13, 13, 12, 13, 11, 14, 13, 13, 12, 12, 11, 11, 7, + 12, 14, 15, 13, 14, 12, 14, 11, 15, 14, 13, 12, 13, 11, 12, 7, + 13, 16, 16, 15, 16, 15, 15, 14, 16, 16, 15, 14, 14, 14, 12, 9, + 12, 15, 14, 13, 14, 13, 14, 12, 15, 14, 13, 12, 13, 12, 12, 8, + 12, 14, 14, 13, 15, 13, 14, 11, 14, 14, 13, 12, 13, 12, 12, 6, + 10, 14, 14, 13, 14, 14, 14, 13, 12, 13, 12, 12, 12, 12, 11, 9, + 12, 15, 15, 14, 15, 14, 16, 14, 14, 14, 13, 12, 14, 13, 13, 9, + 14, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 14, 16, 14, 16, 11, + 11, 15, 14, 14, 15, 14, 14, 14, 13, 14, 11, 12, 13, 13, 12, 9, + 12, 15, 14, 14, 15, 14, 15, 13, 14, 14, 13, 12, 14, 13, 13, 9, + 13, 16, 16, 14, 16, 15, 16, 14, 16, 15, 15, 12, 16, 14, 14, 9, + 13, 16, 14, 15, 16, 16, 16, 14, 14, 16, 11, 12, 15, 14, 12, 9, + 13, 16, 15, 14, 16, 15, 16, 14, 15, 15, 12, 11, 15, 14, 13, 9, + 14, 16, 16, 13, 16, 16, 16, 14, 16, 15, 13, 11, 16, 14, 14, 9, + 11, 15, 15, 14, 14, 14, 14, 13, 13, 14, 13, 13, 11, 11, 11, 9, + 12, 15, 15, 14, 15, 14, 15, 13, 14, 14, 13, 13, 13, 12, 12, 9, + 13, 16, 16, 16, 16, 14, 16, 14, 16, 15, 16, 14, 15, 12, 14, 9, + 11, 15, 14, 14, 15, 14, 14, 13, 14, 14, 12, 12, 12, 12, 11, 8, + 11, 14, 14, 13, 14, 13, 13, 12, 13, 13, 12, 11, 12, 11, 11, 7, + 12, 14, 15, 13, 15, 13, 14, 13, 14, 14, 13, 12, 13, 12, 12, 8, + 13, 16, 15, 15, 16, 15, 15, 14, 15, 16, 12, 12, 14, 14, 11, 9, + 12, 15, 14, 13, 15, 13, 14, 12, 14, 14, 12, 11, 13, 12, 11, 7, + 12, 14, 14, 13, 15, 13, 14, 12, 15, 14, 13, 10, 13, 12, 12, 6, + 12, 16, 16, 15, 14, 14, 15, 14, 13, 15, 14, 14, 10, 11, 11, 9, + 13, 16, 16, 15, 15, 14, 15, 14, 15, 15, 15, 14, 12, 11, 12, 8, + 14, 16, 16, 16, 16, 14, 16, 14, 16, 15, 15, 14, 14, 11, 14, 8, + 12, 16, 16, 15, 15, 14, 15, 14, 14, 16, 14, 14, 12, 12, 11, 8, + 11, 14, 14, 13, 14, 13, 14, 12, 14, 14, 13, 12, 12, 11, 11, 7, + 12, 14, 15, 13, 14, 13, 14, 12, 14, 14, 13, 12, 13, 11, 12, 6, + 14, 16, 16, 16, 16, 16, 15, 14, 16, 16, 14, 13, 13, 13, 11, 8, + 12, 15, 15, 13, 15, 13, 14, 12, 14, 14, 13, 12, 13, 12, 10, 6, + 11, 14, 13, 12, 14, 12, 13, 10, 14, 13, 12, 10, 12, 10, 10, 4, +}, +{ + 4, 6, 6, 6, 6, 6, 7, 6, 6, 7, 6, 6, 6, 6, 6, 3, + 6, 9, 10, 9, 10, 9, 11, 9, 10, 10, 10, 9, 10, 9, 10, 6, + 10, 11, 14, 11, 14, 11, 14, 11, 14, 13, 14, 11, 14, 11, 13, 9, + 6, 10, 9, 9, 10, 10, 10, 9, 10, 11, 9, 9, 10, 10, 9, 6, + 8, 11, 11, 9, 12, 11, 12, 10, 12, 12, 11, 10, 12, 11, 11, 7, + 11, 13, 14, 11, 15, 13, 15, 11, 15, 14, 14, 11, 15, 13, 14, 9, + 10, 13, 11, 11, 14, 14, 13, 11, 14, 14, 11, 11, 13, 13, 11, 9, + 11, 14, 12, 11, 15, 14, 14, 11, 15, 15, 13, 11, 14, 14, 13, 9, + 12, 14, 13, 10, 16, 15, 16, 11, 16, 16, 14, 11, 16, 14, 14, 9, + 6, 10, 10, 10, 9, 9, 10, 9, 10, 11, 10, 10, 9, 9, 9, 6, + 8, 11, 12, 11, 11, 10, 12, 10, 12, 12, 12, 11, 11, 10, 11, 7, + 11, 13, 15, 13, 14, 11, 15, 11, 15, 14, 14, 13, 14, 12, 14, 9, + 8, 12, 12, 12, 12, 12, 12, 11, 12, 13, 11, 11, 11, 11, 11, 8, + 9, 12, 12, 11, 12, 12, 13, 11, 13, 13, 12, 11, 12, 11, 11, 8, + 11, 14, 15, 13, 14, 13, 15, 11, 15, 15, 14, 13, 15, 13, 14, 9, + 12, 16, 14, 14, 15, 15, 14, 12, 15, 16, 14, 13, 14, 14, 13, 10, + 11, 15, 14, 13, 15, 14, 15, 12, 15, 16, 14, 13, 15, 14, 13, 9, + 13, 15, 15, 12, 16, 15, 16, 12, 16, 16, 15, 13, 15, 14, 14, 9, + 10, 14, 14, 14, 11, 11, 13, 11, 14, 14, 14, 13, 11, 11, 11, 9, + 11, 14, 15, 14, 13, 11, 14, 12, 15, 15, 15, 14, 13, 11, 13, 9, + 13, 14, 16, 15, 14, 11, 16, 12, 16, 16, 16, 14, 15, 12, 15, 10, + 12, 16, 15, 15, 14, 14, 14, 12, 16, 16, 14, 14, 14, 13, 13, 10, + 12, 15, 15, 14, 14, 13, 14, 12, 15, 16, 14, 14, 14, 13, 13, 9, + 13, 16, 16, 14, 16, 13, 16, 12, 16, 16, 16, 14, 16, 13, 15, 10, + 14, 16, 16, 16, 16, 16, 15, 14, 16, 16, 16, 16, 16, 16, 14, 11, + 13, 16, 16, 15, 16, 16, 16, 13, 16, 16, 16, 15, 16, 15, 14, 10, + 14, 16, 16, 14, 16, 14, 16, 12, 16, 16, 16, 15, 16, 15, 15, 10, + 6, 10, 10, 10, 10, 10, 11, 10, 9, 10, 9, 9, 9, 9, 9, 6, + 9, 12, 12, 11, 12, 11, 13, 11, 12, 12, 11, 10, 12, 11, 11, 8, + 12, 14, 15, 14, 15, 14, 16, 13, 15, 14, 14, 12, 15, 13, 14, 10, + 8, 12, 11, 11, 12, 12, 12, 11, 11, 12, 10, 10, 11, 11, 10, 7, + 9, 12, 12, 11, 13, 12, 13, 11, 12, 13, 11, 10, 12, 12, 11, 8, + 11, 14, 14, 13, 15, 14, 15, 13, 15, 14, 14, 12, 15, 13, 14, 9, + 11, 15, 12, 13, 15, 15, 14, 13, 14, 15, 11, 11, 14, 14, 12, 9, + 11, 14, 13, 13, 15, 14, 15, 13, 15, 15, 13, 11, 15, 14, 13, 9, + 13, 15, 15, 12, 16, 15, 16, 13, 16, 15, 14, 11, 16, 15, 14, 9, + 8, 12, 12, 11, 11, 11, 12, 11, 11, 12, 11, 11, 9, 10, 10, 7, + 9, 12, 13, 12, 12, 11, 13, 11, 12, 13, 12, 12, 11, 11, 11, 8, + 12, 14, 15, 14, 15, 13, 16, 13, 15, 14, 15, 13, 14, 12, 14, 9, + 9, 13, 12, 12, 12, 12, 13, 12, 12, 13, 11, 11, 11, 11, 10, 8, + 9, 12, 12, 12, 12, 12, 13, 11, 12, 13, 11, 11, 12, 11, 11, 7, + 11, 13, 14, 13, 14, 13, 15, 12, 14, 14, 14, 12, 14, 12, 13, 8, + 12, 15, 14, 14, 15, 15, 14, 13, 15, 16, 13, 13, 14, 14, 12, 9, + 11, 14, 13, 13, 14, 14, 14, 12, 14, 15, 13, 12, 14, 13, 12, 8, + 11, 14, 14, 13, 15, 14, 15, 12, 15, 15, 14, 12, 14, 13, 13, 8, + 11, 14, 14, 14, 13, 13, 14, 13, 13, 14, 14, 13, 11, 11, 11, 9, + 11, 15, 15, 14, 14, 13, 15, 13, 14, 15, 14, 14, 13, 11, 13, 9, + 13, 16, 16, 16, 15, 13, 16, 13, 16, 16, 16, 15, 15, 12, 15, 10, + 11, 15, 15, 15, 14, 14, 14, 13, 15, 15, 14, 14, 13, 13, 12, 9, + 11, 14, 14, 13, 13, 13, 14, 12, 14, 14, 13, 13, 13, 12, 12, 8, + 12, 15, 15, 14, 15, 13, 15, 12, 15, 15, 14, 13, 14, 12, 13, 8, + 13, 16, 16, 16, 16, 16, 16, 14, 16, 16, 15, 15, 15, 15, 13, 10, + 12, 15, 15, 14, 15, 14, 15, 13, 15, 16, 14, 13, 14, 14, 13, 9, + 12, 15, 15, 14, 15, 14, 15, 12, 15, 15, 14, 13, 14, 13, 13, 8, + 10, 14, 13, 13, 14, 13, 14, 13, 11, 13, 11, 11, 11, 11, 11, 9, + 12, 15, 16, 14, 15, 14, 16, 14, 14, 14, 14, 13, 14, 13, 13, 10, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 13, 16, 14, 16, 11, + 11, 15, 14, 14, 15, 14, 15, 14, 13, 14, 11, 12, 13, 13, 11, 9, + 12, 15, 15, 14, 15, 15, 16, 14, 14, 14, 13, 12, 14, 13, 13, 9, + 13, 16, 16, 15, 16, 16, 16, 15, 16, 15, 15, 12, 16, 14, 15, 10, + 12, 16, 14, 15, 16, 16, 16, 14, 14, 16, 11, 12, 14, 15, 12, 9, + 13, 16, 15, 14, 16, 16, 16, 14, 15, 16, 13, 12, 15, 15, 13, 9, + 14, 16, 16, 14, 16, 16, 16, 15, 16, 16, 14, 12, 16, 15, 15, 10, + 11, 14, 14, 14, 14, 14, 14, 13, 12, 14, 13, 13, 11, 11, 11, 9, + 11, 15, 15, 14, 14, 14, 16, 14, 14, 14, 14, 13, 13, 12, 13, 9, + 13, 16, 16, 16, 16, 15, 16, 15, 16, 15, 16, 14, 15, 13, 15, 10, + 11, 15, 15, 14, 14, 14, 15, 14, 14, 15, 13, 13, 12, 13, 11, 9, + 11, 14, 14, 13, 14, 14, 14, 13, 13, 14, 13, 12, 13, 12, 12, 8, + 12, 15, 15, 14, 16, 14, 16, 14, 15, 15, 15, 13, 14, 13, 14, 9, + 13, 16, 15, 16, 16, 16, 16, 15, 15, 16, 13, 13, 14, 14, 12, 9, + 12, 15, 14, 14, 15, 15, 15, 13, 14, 15, 13, 12, 14, 13, 12, 8, + 12, 15, 14, 14, 15, 15, 15, 13, 15, 15, 14, 12, 14, 13, 13, 8, + 12, 16, 15, 15, 13, 14, 15, 14, 13, 15, 14, 14, 10, 11, 11, 9, + 12, 16, 16, 15, 15, 14, 16, 14, 15, 15, 15, 14, 13, 12, 13, 9, + 14, 16, 16, 16, 16, 14, 16, 15, 16, 15, 16, 15, 14, 12, 15, 10, + 12, 16, 15, 15, 15, 15, 15, 14, 15, 16, 14, 14, 12, 13, 11, 9, + 11, 15, 15, 14, 14, 14, 15, 13, 14, 15, 14, 13, 13, 12, 12, 8, + 12, 15, 15, 14, 15, 14, 15, 13, 15, 15, 14, 13, 14, 12, 13, 8, + 14, 16, 16, 16, 16, 16, 16, 15, 16, 16, 14, 14, 14, 14, 11, 9, + 12, 15, 15, 14, 15, 15, 15, 13, 15, 15, 14, 13, 14, 13, 12, 8, + 11, 14, 14, 13, 14, 13, 14, 12, 13, 14, 13, 12, 13, 12, 12, 7, +}, +{ + 2, 6, 6, 5, 6, 6, 7, 6, 6, 7, 6, 6, 6, 6, 6, 3, + 6, 9, 10, 9, 10, 9, 11, 9, 10, 10, 10, 9, 10, 9, 10, 7, + 10, 11, 14, 11, 14, 11, 14, 11, 14, 13, 14, 12, 14, 12, 13, 9, + 6, 10, 9, 9, 10, 10, 10, 9, 10, 11, 9, 9, 10, 10, 9, 7, + 8, 11, 11, 9, 12, 11, 12, 10, 12, 12, 11, 10, 12, 11, 11, 8, + 11, 13, 14, 11, 16, 13, 15, 12, 16, 14, 14, 12, 15, 13, 14, 10, + 10, 13, 11, 11, 14, 14, 13, 11, 13, 14, 11, 11, 13, 13, 11, 9, + 11, 13, 13, 11, 15, 14, 14, 12, 15, 15, 13, 12, 15, 14, 13, 10, + 12, 14, 14, 11, 16, 15, 16, 12, 16, 16, 15, 12, 16, 15, 15, 10, + 6, 10, 10, 10, 9, 9, 10, 9, 10, 11, 10, 10, 9, 9, 9, 7, + 8, 11, 12, 11, 11, 10, 12, 10, 12, 12, 12, 11, 11, 10, 11, 8, + 12, 13, 16, 13, 14, 11, 16, 12, 16, 15, 15, 13, 14, 12, 14, 10, + 9, 13, 12, 12, 12, 12, 12, 11, 13, 13, 12, 12, 12, 12, 11, 8, + 10, 13, 13, 12, 13, 12, 13, 11, 14, 14, 13, 12, 13, 12, 12, 9, + 12, 14, 16, 13, 15, 13, 15, 12, 16, 16, 16, 13, 16, 14, 14, 10, + 12, 16, 14, 14, 16, 15, 14, 13, 16, 16, 14, 14, 15, 15, 13, 11, + 12, 16, 15, 14, 16, 15, 15, 12, 16, 16, 15, 14, 16, 15, 14, 10, + 14, 16, 16, 14, 16, 15, 16, 13, 16, 16, 16, 14, 16, 16, 15, 11, + 10, 14, 14, 13, 11, 11, 13, 12, 14, 14, 13, 13, 11, 11, 12, 9, + 12, 14, 16, 14, 13, 11, 14, 12, 16, 15, 15, 14, 14, 12, 13, 10, + 13, 14, 16, 15, 14, 11, 16, 12, 16, 16, 16, 15, 16, 13, 15, 11, + 12, 16, 15, 15, 14, 14, 14, 13, 16, 16, 15, 15, 14, 14, 13, 11, + 13, 16, 16, 15, 14, 14, 15, 13, 16, 16, 16, 15, 15, 14, 14, 11, + 14, 16, 16, 15, 16, 14, 16, 13, 16, 16, 16, 15, 16, 14, 15, 11, + 15, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 14, 12, + 15, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 15, 12, + 15, 16, 16, 15, 16, 15, 16, 13, 16, 16, 16, 16, 16, 16, 16, 11, + 6, 10, 10, 10, 10, 10, 11, 10, 9, 10, 9, 9, 9, 9, 9, 7, + 9, 12, 13, 12, 13, 12, 14, 12, 12, 12, 12, 11, 12, 11, 11, 8, + 12, 14, 16, 14, 16, 14, 16, 14, 15, 14, 15, 13, 16, 13, 14, 11, + 8, 12, 11, 11, 12, 12, 12, 11, 11, 12, 10, 10, 11, 11, 10, 8, + 10, 13, 13, 12, 14, 13, 14, 12, 13, 13, 12, 11, 13, 12, 12, 9, + 12, 15, 15, 13, 16, 15, 16, 14, 16, 15, 15, 12, 16, 14, 15, 10, + 11, 15, 13, 13, 16, 15, 14, 13, 14, 15, 11, 12, 14, 14, 12, 10, + 12, 16, 14, 13, 16, 16, 16, 14, 16, 15, 13, 12, 15, 15, 14, 10, + 14, 16, 16, 14, 16, 16, 16, 14, 16, 16, 15, 13, 16, 16, 15, 11, + 8, 12, 12, 12, 11, 11, 12, 11, 11, 12, 11, 11, 9, 10, 10, 8, + 10, 13, 14, 13, 13, 12, 14, 12, 13, 13, 13, 12, 12, 11, 12, 9, + 13, 15, 16, 15, 16, 14, 16, 14, 16, 15, 16, 14, 15, 13, 15, 11, + 10, 13, 13, 13, 13, 13, 13, 12, 13, 14, 12, 12, 12, 12, 11, 9, + 10, 13, 13, 13, 13, 13, 14, 12, 13, 14, 13, 12, 12, 12, 12, 9, + 12, 15, 15, 14, 16, 14, 16, 13, 16, 15, 15, 13, 15, 13, 14, 10, + 13, 16, 15, 15, 16, 16, 15, 14, 16, 16, 13, 14, 15, 15, 12, 10, + 12, 16, 14, 14, 16, 16, 15, 13, 16, 16, 14, 13, 15, 14, 13, 10, + 13, 16, 16, 14, 16, 15, 16, 13, 16, 16, 16, 13, 16, 15, 15, 10, + 11, 15, 15, 14, 13, 13, 14, 13, 13, 15, 14, 14, 11, 12, 12, 10, + 12, 15, 16, 15, 14, 13, 16, 14, 16, 15, 16, 14, 13, 12, 13, 10, + 14, 16, 16, 16, 16, 14, 16, 14, 16, 16, 16, 16, 16, 13, 16, 11, + 12, 16, 16, 16, 15, 15, 15, 14, 15, 16, 14, 14, 13, 14, 12, 10, + 12, 16, 16, 15, 15, 14, 16, 13, 16, 16, 15, 14, 14, 13, 13, 10, + 13, 16, 16, 15, 16, 14, 16, 13, 16, 16, 16, 15, 16, 14, 15, 10, + 15, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 13, 12, + 14, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 15, 16, 15, 14, 11, + 14, 16, 16, 15, 16, 16, 16, 13, 16, 16, 16, 15, 16, 15, 14, 10, + 10, 14, 13, 13, 13, 13, 14, 13, 11, 13, 11, 11, 11, 11, 11, 9, + 12, 15, 16, 15, 16, 15, 16, 14, 14, 14, 14, 13, 14, 13, 14, 11, + 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 14, 16, 12, + 11, 15, 14, 14, 15, 15, 15, 14, 13, 14, 11, 12, 13, 13, 12, 10, + 13, 16, 15, 15, 16, 16, 16, 15, 15, 15, 13, 12, 15, 14, 13, 10, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 12, + 13, 16, 14, 15, 16, 16, 16, 15, 14, 16, 11, 12, 15, 15, 12, 10, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, 13, 16, 16, 14, 11, + 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 11, + 11, 15, 15, 14, 13, 14, 14, 14, 13, 14, 13, 13, 11, 12, 11, 10, + 12, 16, 16, 16, 16, 15, 16, 15, 15, 15, 15, 14, 13, 12, 14, 10, + 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 14, 16, 12, + 12, 16, 15, 15, 16, 16, 16, 14, 14, 15, 13, 13, 13, 13, 12, 10, + 12, 16, 16, 15, 15, 15, 16, 14, 14, 15, 14, 13, 14, 13, 13, 10, + 14, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 14, 16, 14, 15, 11, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 15, 15, 12, 11, + 13, 16, 16, 15, 16, 16, 16, 14, 16, 16, 14, 13, 16, 14, 13, 10, + 14, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 14, 16, 14, 15, 10, + 12, 16, 16, 15, 14, 15, 16, 14, 13, 15, 14, 14, 11, 12, 12, 10, + 13, 16, 16, 16, 16, 15, 16, 16, 16, 16, 16, 15, 13, 12, 14, 11, + 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 11, + 14, 16, 16, 16, 16, 16, 16, 15, 16, 16, 15, 15, 13, 14, 12, 11, + 13, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 14, 14, 13, 13, 10, + 14, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 15, 15, 14, 14, 10, + 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 15, 16, 13, 11, + 14, 16, 16, 16, 16, 16, 16, 14, 16, 16, 15, 14, 15, 14, 13, 10, + 12, 15, 15, 14, 15, 14, 16, 14, 14, 16, 15, 13, 14, 13, 13, 9, +}, +{ + 2, 5, 5, 5, 5, 5, 6, 6, 5, 6, 5, 6, 5, 6, 6, 4, + 6, 8, 10, 8, 10, 9, 11, 9, 10, 10, 10, 9, 10, 9, 10, 8, + 10, 11, 13, 11, 13, 11, 14, 11, 14, 13, 13, 12, 13, 12, 13, 10, + 6, 10, 8, 9, 10, 10, 10, 9, 10, 11, 9, 9, 10, 10, 9, 7, + 8, 11, 11, 10, 12, 11, 12, 10, 12, 12, 11, 10, 12, 12, 11, 9, + 11, 13, 14, 11, 15, 14, 15, 12, 16, 14, 14, 12, 15, 14, 14, 11, + 10, 13, 11, 11, 14, 13, 13, 12, 13, 14, 11, 11, 13, 13, 12, 10, + 11, 14, 13, 11, 16, 14, 14, 12, 15, 15, 14, 12, 15, 14, 14, 11, + 12, 14, 14, 11, 16, 16, 16, 13, 16, 16, 16, 13, 16, 16, 15, 12, + 6, 10, 10, 10, 8, 9, 10, 9, 10, 11, 10, 10, 9, 9, 9, 8, + 8, 11, 12, 12, 11, 10, 12, 11, 12, 12, 12, 12, 12, 11, 12, 9, + 11, 13, 16, 14, 14, 12, 15, 12, 16, 15, 16, 14, 14, 13, 14, 11, + 9, 13, 12, 12, 12, 12, 12, 11, 13, 13, 12, 12, 12, 12, 11, 10, + 10, 13, 13, 12, 13, 12, 13, 11, 14, 14, 13, 13, 13, 13, 12, 10, + 13, 14, 16, 14, 15, 14, 16, 13, 16, 16, 16, 14, 16, 14, 15, 12, + 12, 16, 14, 14, 16, 15, 14, 13, 16, 16, 14, 14, 15, 15, 13, 12, + 13, 16, 15, 14, 16, 16, 15, 13, 16, 16, 15, 14, 16, 16, 14, 12, + 14, 16, 16, 14, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 12, + 10, 13, 14, 13, 11, 11, 13, 12, 13, 14, 13, 13, 11, 12, 12, 10, + 11, 14, 15, 15, 13, 12, 14, 13, 16, 16, 16, 15, 14, 13, 14, 11, + 12, 14, 16, 16, 14, 12, 16, 13, 16, 16, 16, 16, 15, 13, 16, 12, + 12, 16, 15, 16, 14, 15, 14, 14, 16, 16, 15, 16, 14, 14, 13, 12, + 13, 16, 16, 16, 16, 14, 16, 13, 16, 16, 16, 16, 16, 14, 15, 12, + 14, 16, 16, 16, 16, 14, 16, 14, 16, 16, 16, 16, 16, 15, 16, 13, + 15, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 15, 13, + 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 16, 13, + 15, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 13, + 6, 10, 10, 10, 10, 10, 10, 10, 8, 10, 9, 9, 8, 9, 9, 7, + 9, 12, 13, 12, 13, 12, 13, 12, 12, 12, 12, 11, 12, 11, 12, 10, + 12, 14, 16, 14, 16, 14, 16, 14, 16, 15, 15, 14, 16, 14, 15, 12, + 8, 12, 11, 11, 12, 12, 12, 11, 11, 12, 10, 10, 11, 12, 10, 9, + 10, 13, 13, 12, 14, 13, 14, 12, 13, 13, 12, 11, 13, 13, 12, 10, + 13, 15, 16, 14, 16, 16, 16, 14, 16, 15, 15, 13, 16, 15, 15, 12, + 11, 15, 13, 13, 15, 15, 15, 14, 14, 14, 11, 12, 14, 14, 12, 11, + 13, 16, 14, 14, 16, 16, 16, 14, 16, 15, 13, 13, 16, 14, 14, 11, + 14, 16, 16, 14, 16, 16, 16, 15, 16, 16, 16, 14, 16, 16, 16, 12, + 8, 12, 12, 12, 11, 11, 12, 12, 11, 12, 11, 11, 9, 10, 10, 9, + 10, 13, 14, 13, 13, 12, 14, 13, 13, 13, 13, 13, 12, 11, 12, 10, + 13, 15, 16, 15, 16, 14, 16, 14, 16, 16, 16, 15, 16, 13, 15, 12, + 10, 14, 13, 13, 13, 13, 13, 13, 13, 14, 12, 12, 12, 12, 11, 10, + 10, 13, 13, 13, 13, 13, 14, 12, 13, 14, 13, 12, 13, 12, 12, 10, + 13, 16, 16, 14, 16, 15, 16, 14, 16, 16, 15, 14, 16, 14, 15, 11, + 13, 16, 15, 16, 16, 16, 15, 14, 16, 16, 14, 14, 15, 15, 13, 12, + 13, 16, 15, 14, 16, 16, 16, 14, 16, 16, 14, 14, 15, 15, 14, 11, + 14, 16, 16, 15, 16, 16, 16, 14, 16, 16, 16, 15, 16, 16, 15, 12, + 11, 14, 15, 14, 13, 13, 14, 14, 13, 15, 14, 14, 11, 12, 12, 11, + 13, 16, 16, 16, 14, 14, 16, 14, 16, 16, 16, 15, 14, 13, 14, 12, + 14, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 14, 16, 13, + 13, 16, 16, 16, 15, 16, 15, 15, 16, 16, 15, 16, 14, 14, 13, 12, + 13, 16, 16, 15, 15, 14, 16, 14, 16, 16, 16, 15, 14, 14, 14, 11, + 14, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 16, 15, 16, 12, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 13, + 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 12, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12, + 9, 13, 13, 13, 13, 13, 14, 13, 10, 12, 11, 12, 11, 12, 11, 10, + 12, 15, 16, 15, 16, 16, 16, 16, 14, 14, 14, 13, 14, 13, 14, 12, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 14, + 11, 15, 14, 14, 15, 14, 15, 14, 13, 14, 11, 12, 13, 13, 12, 11, + 13, 16, 16, 15, 16, 16, 16, 15, 15, 15, 14, 13, 16, 15, 14, 12, + 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 13, + 12, 16, 14, 15, 16, 16, 16, 16, 14, 16, 11, 13, 15, 16, 13, 12, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 16, 16, 15, 12, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 13, + 11, 15, 14, 14, 13, 14, 15, 14, 12, 14, 13, 13, 11, 12, 12, 11, + 13, 16, 16, 16, 16, 15, 16, 16, 15, 15, 15, 15, 14, 13, 14, 12, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 13, + 13, 16, 16, 16, 16, 16, 16, 15, 14, 16, 13, 14, 13, 14, 13, 11, + 13, 16, 16, 16, 16, 16, 16, 15, 15, 16, 15, 14, 14, 14, 14, 11, + 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 15, 16, 16, 13, 12, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 16, 16, 15, 12, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 12, + 11, 16, 16, 15, 13, 15, 16, 15, 13, 15, 15, 15, 11, 12, 12, 11, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 15, 12, + 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 13, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 14, 14, 13, 12, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 14, 14, 12, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 12, + 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 14, 13, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 12, + 12, 14, 14, 14, 14, 15, 16, 14, 14, 16, 15, 14, 14, 15, 14, 11, +}, +{ + 1, 5, 5, 6, 5, 6, 7, 7, 5, 7, 6, 7, 5, 6, 6, 6, + 6, 9, 10, 9, 10, 9, 11, 10, 11, 11, 11, 10, 11, 10, 11, 9, + 10, 11, 14, 12, 14, 12, 16, 12, 16, 13, 16, 13, 14, 13, 16, 12, + 6, 10, 9, 9, 10, 11, 11, 10, 10, 11, 9, 10, 10, 11, 10, 9, + 8, 11, 11, 10, 13, 12, 13, 12, 13, 13, 12, 12, 13, 13, 13, 11, + 11, 13, 16, 12, 16, 16, 16, 13, 16, 16, 16, 14, 16, 16, 16, 13, + 10, 14, 11, 12, 14, 14, 13, 13, 13, 16, 12, 13, 14, 16, 13, 12, + 11, 14, 13, 12, 16, 16, 16, 14, 16, 16, 14, 14, 16, 16, 16, 13, + 12, 14, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 6, 10, 10, 11, 9, 9, 11, 10, 10, 11, 11, 11, 9, 10, 10, 9, + 9, 12, 13, 12, 12, 11, 13, 12, 13, 13, 13, 13, 12, 12, 13, 11, + 12, 13, 16, 16, 16, 13, 16, 14, 16, 16, 16, 16, 16, 14, 16, 13, + 9, 13, 13, 13, 13, 13, 13, 13, 13, 14, 13, 13, 13, 13, 12, 11, + 10, 14, 14, 13, 14, 13, 14, 13, 16, 16, 14, 15, 14, 14, 14, 12, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 14, 14, 16, 11, 12, 14, 13, 14, 16, 16, 16, 12, 13, 13, 12, + 12, 16, 16, 16, 13, 13, 16, 14, 16, 16, 16, 16, 16, 14, 16, 13, + 13, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 6, 10, 10, 10, 10, 11, 11, 11, 9, 11, 9, 10, 9, 10, 10, 9, + 9, 13, 13, 13, 13, 13, 14, 13, 12, 13, 13, 12, 13, 12, 13, 11, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 8, 13, 12, 12, 13, 13, 13, 13, 11, 13, 10, 12, 12, 13, 12, 11, + 10, 14, 13, 13, 16, 16, 16, 14, 14, 14, 13, 13, 14, 14, 14, 12, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 11, 16, 13, 16, 16, 16, 16, 16, 14, 16, 12, 13, 16, 16, 14, 13, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 13, 13, 13, 11, 12, 13, 13, 11, 13, 12, 13, 10, 12, 12, 11, + 10, 14, 16, 16, 14, 13, 16, 14, 14, 16, 16, 14, 13, 13, 14, 12, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 10, 16, 14, 16, 14, 14, 14, 14, 13, 16, 13, 14, 13, 14, 12, 12, + 10, 14, 14, 14, 14, 16, 16, 14, 14, 16, 14, 14, 14, 14, 14, 12, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 16, 16, 13, 16, 16, 16, 14, 16, 16, 16, 12, 14, 14, 13, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 9, 14, 13, 14, 13, 14, 16, 16, 11, 13, 12, 13, 11, 13, 12, 12, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 14, 16, 16, 16, 16, 16, 13, 16, 12, 13, 14, 16, 13, 13, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 16, 16, 16, 16, 14, 16, 12, 16, 16, 16, 14, 14, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 16, 16, 14, 16, 16, 16, 13, 16, 14, 16, 12, 13, 13, 13, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 14, 14, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 16, 16, 14, 16, 16, 16, 14, 16, 16, 16, 12, 16, 14, 14, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, +}, +{ + 1, 5, 5, 6, 5, 6, 7, 8, 5, 7, 6, 8, 6, 7, 7, 7, + 5, 9, 10, 10, 10, 10, 12, 11, 10, 11, 11, 11, 10, 11, 12, 10, + 9, 11, 13, 12, 13, 12, 16, 14, 16, 14, 16, 16, 16, 13, 16, 13, + 5, 10, 9, 10, 10, 11, 11, 11, 10, 11, 9, 11, 10, 11, 11, 10, + 8, 11, 11, 11, 12, 13, 13, 13, 12, 13, 12, 12, 13, 13, 13, 12, + 11, 13, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 9, 14, 11, 12, 14, 16, 13, 14, 13, 16, 12, 14, 16, 16, 13, 13, + 11, 16, 13, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 14, 14, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 5, 10, 11, 11, 9, 10, 11, 11, 10, 12, 11, 12, 9, 11, 11, 11, + 8, 12, 13, 13, 11, 11, 14, 13, 13, 14, 13, 16, 12, 12, 13, 12, + 11, 13, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 9, 13, 12, 13, 12, 13, 13, 14, 13, 16, 13, 16, 13, 16, 13, 13, + 10, 14, 13, 14, 13, 13, 16, 14, 16, 16, 16, 16, 16, 16, 16, 13, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 9, 14, 16, 16, 11, 12, 14, 16, 13, 16, 16, 16, 12, 14, 13, 13, + 11, 16, 16, 16, 13, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 14, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 5, 10, 10, 11, 10, 11, 12, 12, 8, 11, 10, 11, 9, 11, 11, 11, + 9, 12, 13, 13, 13, 13, 16, 16, 12, 13, 13, 13, 13, 13, 16, 13, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 13, 11, 13, 12, 13, 13, 14, 11, 13, 10, 13, 12, 14, 12, 12, + 10, 14, 13, 14, 16, 16, 16, 16, 13, 16, 13, 14, 16, 16, 16, 14, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 13, 16, 16, 16, 16, 16, 13, 16, 12, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 13, 13, 13, 11, 13, 14, 16, 11, 13, 13, 14, 10, 12, 12, 12, + 10, 14, 16, 16, 13, 16, 16, 16, 13, 16, 16, 16, 13, 13, 16, 14, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 14, 16, 13, 16, 16, 16, 13, 16, 13, 16, 13, 16, 13, 14, + 10, 16, 16, 16, 14, 16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 13, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 16, 16, 13, 16, 16, 16, 14, 16, 16, 16, 12, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 9, 14, 13, 16, 13, 16, 16, 16, 10, 14, 12, 14, 11, 13, 13, 13, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 16, 16, 16, 16, 16, 16, 12, 16, 12, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 16, 16, 16, 16, 16, 16, 13, 16, 13, 16, 16, 16, 16, 16, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 16, 16, 14, 16, 16, 16, 12, 16, 16, 16, 12, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 16, 16, 14, 16, 16, 16, 14, 16, 16, 16, 12, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 14, +} +}; + + +static const uint8_t rv34_inter_cbp[NUM_INTER_TABLES][4][CBP_VLC_SIZE] = { +{ + { 0, 6, 6, 3, 6, 4, 5, 3, 6, 5, 4, 3, 3, 4, 4, 3 }, + { 0, 6, 6, 4, 6, 4, 5, 3, 6, 5, 4, 3, 4, 4, 4, 2 }, + { 0, 7, 7, 4, 7, 5, 5, 4, 7, 5, 5, 4, 5, 4, 4, 1 }, + { 0, 7, 7, 5, 7, 5, 6, 4, 7, 6, 5, 3, 5, 4, 4, 1 } +}, +{ + { 0, 6, 6, 3, 6, 3, 5, 4, 6, 5, 3, 4, 3, 4, 4, 3 }, + { 0, 6, 6, 4, 6, 4, 4, 4, 6, 4, 4, 3, 4, 4, 4, 2 }, + { 0, 6, 6, 4, 6, 4, 5, 4, 6, 5, 4, 3, 4, 4, 3, 2 }, + { 0, 7, 7, 5, 7, 5, 6, 4, 7, 6, 5, 3, 5, 4, 4, 1 } +}, +{ + { 0, 6, 6, 3, 6, 3, 5, 4, 6, 5, 3, 4, 3, 4, 4, 3 }, + { 0, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, 4, 4, 4, 4, 2 }, + { 0, 6, 6, 4, 6, 4, 5, 3, 6, 5, 4, 3, 4, 4, 4, 2 }, + { 0, 7, 7, 5, 7, 5, 6, 4, 7, 6, 5, 3, 5, 4, 4, 1 } +}, +{ + { 0, 6, 6, 3, 6, 3, 5, 4, 6, 5, 3, 4, 3, 4, 4, 3 }, + { 0, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4, 4, 4, 4, 4, 2 }, + { 0, 6, 6, 4, 6, 4, 5, 3, 6, 5, 4, 3, 4, 4, 4, 2 }, + { 0, 7, 7, 4, 7, 5, 6, 4, 7, 6, 5, 4, 4, 4, 4, 1 } +}, +{ + { 0, 5, 5, 3, 5, 3, 5, 4, 5, 5, 3, 4, 3, 4, 4, 4 }, + { 0, 5, 5, 3, 5, 4, 5, 4, 5, 5, 3, 4, 3, 4, 4, 3 }, + { 0, 6, 6, 4, 6, 4, 5, 4, 6, 5, 4, 3, 4, 4, 3, 2 }, + { 0, 7, 7, 4, 7, 5, 6, 4, 7, 6, 5, 4, 4, 4, 4, 1 } +}, +{ + { 0, 5, 5, 3, 5, 3, 5, 4, 5, 5, 3, 4, 3, 4, 4, 4 }, + { 0, 5, 5, 3, 5, 4, 5, 4, 5, 5, 3, 4, 3, 4, 4, 3 }, + { 0, 5, 5, 3, 5, 4, 4, 4, 5, 4, 4, 4, 3, 4, 4, 3 }, + { 0, 6, 6, 4, 6, 4, 5, 4, 6, 5, 4, 3, 4, 4, 3, 2 } +}, +{ + { 0, 4, 4, 3, 4, 3, 5, 5, 4, 5, 3, 5, 3, 5, 4, 5 }, + { 0, 4, 4, 3, 4, 4, 5, 4, 4, 5, 3, 5, 3, 5, 4, 4 }, + { 0, 4, 4, 3, 4, 4, 5, 4, 4, 5, 4, 4, 3, 4, 4, 4 }, + { 0, 4, 4, 3, 5, 4, 5, 4, 5, 5, 4, 4, 3, 4, 4, 3 } +} +}; + + +static const uint8_t rv34_table_inter_firstpat[NUM_INTER_TABLES][2][FIRSTBLK_VLC_SIZE] = { + { + { + 0, 7, 5, 7, 5, 7, 6, 6, 7, 10, 7, 9, 8, 9, 8, 7, + 12, 14, 11, 12, 12, 12, 11, 9, 6, 9, 6, 8, 7, 9, 7, 7, + 8, 11, 8, 9, 9, 10, 9, 8, 13, 15, 12, 12, 12, 13, 11, 9, + 10, 13, 9, 10, 11, 12, 9, 8, 12, 14, 10, 11, 12, 13, 10, 9, + 16, 16, 12, 12, 14, 13, 11, 9, 6, 9, 7, 9, 7, 9, 8, 7, + 9, 11, 9, 10, 9, 10, 9, 8, 14, 16, 12, 12, 13, 13, 11, 9, + 8, 11, 8, 10, 9, 10, 9, 8, 10, 13, 10, 11, 10, 11, 9, 8, + 14, 16, 12, 12, 13, 13, 11, 9, 12, 14, 10, 11, 12, 13, 10, 9, + 13, 16, 11, 12, 13, 13, 10, 9, 16, 16, 13, 12, 14, 14, 11, 9, + 11, 13, 11, 12, 10, 11, 10, 9, 13, 14, 12, 12, 11, 12, 10, 9, + 16, 16, 13, 13, 13, 13, 11, 9, 12, 15, 12, 12, 11, 12, 10, 9, + 13, 16, 13, 13, 12, 12, 11, 9, 16, 16, 14, 13, 13, 13, 11, 9, + 14, 16, 13, 13, 13, 14, 11, 9, 16, 16, 13, 13, 14, 14, 11, 9, + 16, 16, 13, 13, 14, 13, 11, 8, 4, 9, 6, 8, 6, 9, 7, 7, + 8, 11, 8, 9, 9, 10, 8, 8, 13, 15, 12, 12, 13, 13, 11, 9, + 7, 10, 7, 9, 8, 10, 8, 8, 9, 12, 9, 10, 10, 11, 9, 8, + 14, 16, 12, 12, 13, 13, 11, 9, 11, 13, 9, 10, 11, 12, 9, 8, + 12, 14, 10, 11, 12, 13, 10, 9, 16, 16, 13, 12, 14, 14, 11, 9, + 7, 10, 8, 9, 8, 10, 8, 8, 10, 12, 10, 11, 10, 11, 9, 8, + 14, 16, 13, 13, 13, 13, 11, 9, 9, 12, 9, 10, 9, 11, 9, 8, + 11, 13, 10, 11, 10, 11, 10, 9, 15, 16, 13, 13, 13, 13, 11, 9, + 12, 14, 11, 11, 12, 13, 10, 9, 13, 16, 11, 12, 13, 13, 10, 9, + 16, 16, 12, 12, 14, 13, 11, 8, 11, 14, 11, 12, 10, 11, 10, 9, + 13, 15, 12, 13, 11, 12, 10, 9, 16, 16, 14, 13, 13, 13, 11, 9, + 12, 15, 12, 13, 11, 12, 10, 9, 13, 16, 13, 13, 12, 12, 11, 9, + 16, 16, 14, 13, 13, 13, 11, 9, 15, 16, 13, 13, 13, 13, 11, 9, + 16, 16, 13, 13, 13, 13, 11, 9, 16, 16, 13, 12, 13, 13, 10, 7, + 8, 11, 8, 10, 9, 11, 9, 9, 10, 13, 10, 11, 11, 12, 10, 9, + 15, 16, 13, 13, 14, 14, 12, 10, 9, 12, 9, 11, 10, 11, 9, 9, + 12, 14, 11, 11, 11, 12, 10, 9, 16, 16, 13, 13, 14, 14, 12, 10, + 12, 14, 10, 11, 12, 13, 10, 9, 14, 16, 11, 12, 13, 14, 10, 9, + 16, 16, 13, 13, 15, 14, 11, 9, 9, 12, 10, 11, 9, 11, 10, 9, + 12, 14, 11, 12, 11, 12, 10, 9, 16, 16, 14, 13, 14, 14, 12, 10, + 11, 14, 10, 12, 11, 12, 10, 9, 12, 15, 11, 12, 12, 13, 11, 10, + 16, 16, 14, 13, 14, 14, 12, 10, 13, 16, 11, 12, 13, 14, 11, 9, + 14, 16, 12, 12, 13, 14, 11, 9, 16, 16, 13, 13, 14, 14, 11, 9, + 12, 15, 12, 13, 10, 12, 10, 9, 14, 16, 13, 13, 11, 12, 11, 10, + 16, 16, 14, 14, 14, 13, 12, 9, 13, 16, 13, 13, 12, 13, 11, 10, + 14, 16, 13, 13, 12, 13, 11, 10, 16, 16, 14, 14, 13, 13, 12, 9, + 15, 16, 13, 13, 13, 14, 11, 9, 16, 16, 13, 13, 13, 14, 11, 9, + 16, 16, 13, 12, 13, 13, 10, 8, 10, 13, 10, 11, 10, 12, 10, 9, + 12, 14, 11, 12, 12, 13, 11, 10, 16, 16, 13, 13, 14, 14, 12, 9, + 11, 14, 10, 11, 11, 12, 10, 9, 13, 16, 11, 12, 12, 13, 11, 10, + 16, 16, 14, 13, 14, 14, 12, 9, 12, 15, 10, 11, 12, 13, 9, 8, + 14, 16, 11, 11, 13, 14, 10, 8, 16, 16, 12, 12, 14, 14, 10, 8, + 11, 14, 11, 12, 11, 12, 10, 9, 13, 16, 12, 13, 12, 13, 11, 10, + 16, 16, 14, 13, 14, 14, 12, 9, 12, 15, 11, 12, 11, 13, 10, 10, + 13, 16, 12, 13, 12, 13, 11, 10, 16, 16, 14, 13, 14, 14, 12, 9, + 13, 16, 11, 11, 13, 13, 10, 8, 14, 16, 11, 12, 13, 14, 10, 8, + 16, 16, 12, 12, 14, 14, 10, 8, 12, 15, 12, 13, 10, 11, 10, 9, + 14, 16, 13, 13, 11, 12, 10, 9, 16, 16, 14, 13, 13, 13, 11, 8, + 13, 16, 12, 13, 11, 12, 10, 9, 14, 16, 13, 13, 12, 12, 10, 9, + 16, 16, 14, 13, 13, 12, 10, 8, 14, 16, 12, 12, 12, 13, 10, 8, + 14, 16, 12, 12, 12, 13, 10, 7, 16, 16, 11, 11, 12, 11, 8, 5, + }, + { + 0, 7, 4, 8, 5, 8, 7, 8, 6, 10, 7, 10, 8, 10, 9, 9, + 13, 16, 12, 13, 13, 14, 12, 12, 4, 10, 6, 9, 8, 11, 8, 9, + 8, 12, 8, 11, 10, 12, 10, 10, 14, 16, 12, 13, 14, 15, 12, 12, + 9, 14, 9, 11, 12, 14, 11, 11, 11, 15, 10, 12, 13, 14, 11, 11, + 15, 16, 13, 14, 15, 16, 13, 12, 5, 10, 7, 10, 7, 10, 9, 9, + 8, 12, 9, 11, 10, 11, 10, 10, 14, 16, 13, 14, 14, 14, 12, 12, + 8, 12, 8, 11, 10, 12, 10, 10, 10, 14, 10, 12, 11, 13, 10, 11, + 15, 16, 13, 14, 14, 15, 13, 12, 11, 16, 10, 12, 13, 15, 11, 11, + 13, 16, 11, 13, 14, 15, 12, 12, 16, 16, 14, 14, 16, 16, 13, 12, + 11, 15, 11, 13, 11, 13, 11, 11, 13, 16, 12, 14, 12, 13, 12, 12, + 16, 16, 14, 15, 15, 15, 13, 12, 12, 16, 12, 14, 12, 14, 12, 12, + 14, 16, 13, 14, 13, 14, 12, 12, 16, 16, 14, 16, 16, 16, 13, 12, + 14, 16, 13, 14, 15, 16, 13, 12, 16, 16, 14, 15, 16, 16, 13, 12, + 16, 16, 15, 16, 16, 16, 13, 12, 2, 9, 5, 8, 6, 9, 8, 9, + 7, 11, 8, 10, 9, 11, 9, 10, 13, 16, 12, 13, 14, 14, 12, 12, + 5, 11, 6, 10, 9, 11, 9, 9, 9, 13, 9, 11, 10, 12, 10, 10, + 14, 16, 12, 14, 14, 15, 12, 12, 9, 14, 9, 11, 12, 14, 10, 11, + 11, 16, 10, 12, 13, 14, 11, 11, 16, 16, 13, 14, 15, 16, 13, 12, + 6, 11, 7, 10, 8, 11, 9, 9, 9, 13, 9, 11, 10, 12, 10, 10, + 14, 16, 13, 14, 14, 14, 12, 12, 8, 13, 8, 11, 10, 12, 10, 10, + 10, 13, 10, 12, 11, 13, 10, 11, 14, 16, 13, 14, 14, 15, 12, 12, + 11, 15, 10, 12, 13, 15, 11, 11, 12, 16, 11, 13, 13, 15, 12, 11, + 16, 16, 13, 14, 15, 16, 13, 12, 11, 15, 11, 13, 10, 13, 11, 11, + 13, 16, 12, 14, 12, 13, 12, 11, 16, 16, 14, 15, 15, 15, 13, 12, + 12, 16, 12, 13, 12, 14, 12, 12, 13, 16, 12, 14, 13, 14, 12, 12, + 16, 16, 14, 15, 15, 15, 13, 12, 14, 16, 13, 14, 15, 16, 12, 12, + 16, 16, 13, 14, 15, 16, 12, 12, 16, 16, 14, 15, 16, 16, 13, 12, + 6, 12, 7, 10, 9, 12, 9, 10, 9, 13, 9, 12, 11, 13, 11, 11, + 14, 16, 13, 14, 15, 15, 13, 12, 8, 13, 8, 11, 10, 13, 10, 10, + 10, 14, 10, 12, 12, 14, 11, 11, 15, 16, 13, 14, 16, 16, 13, 12, + 10, 15, 9, 12, 12, 15, 11, 11, 12, 16, 11, 13, 14, 16, 12, 12, + 16, 16, 14, 14, 16, 16, 13, 12, 8, 13, 9, 11, 10, 12, 10, 11, + 11, 14, 11, 12, 11, 13, 11, 11, 16, 16, 14, 15, 15, 16, 13, 12, + 10, 14, 10, 12, 11, 13, 11, 11, 11, 15, 11, 13, 12, 14, 11, 11, + 15, 16, 13, 14, 15, 16, 13, 12, 12, 16, 11, 13, 13, 16, 12, 12, + 13, 16, 11, 13, 14, 16, 12, 12, 16, 16, 13, 14, 16, 16, 13, 12, + 12, 16, 12, 14, 11, 13, 11, 11, 13, 16, 13, 14, 12, 14, 12, 12, + 16, 16, 15, 16, 16, 16, 14, 13, 13, 16, 12, 14, 12, 14, 12, 12, + 14, 16, 13, 14, 13, 14, 12, 12, 16, 16, 14, 16, 14, 16, 13, 12, + 15, 16, 13, 15, 15, 16, 13, 12, 15, 16, 13, 15, 14, 16, 13, 12, + 16, 16, 14, 15, 15, 16, 13, 11, 8, 13, 8, 11, 10, 13, 10, 11, + 11, 15, 10, 12, 12, 14, 11, 11, 15, 16, 13, 14, 15, 15, 13, 12, + 9, 14, 9, 12, 11, 14, 10, 11, 11, 16, 10, 12, 13, 14, 11, 11, + 16, 16, 13, 14, 15, 16, 13, 12, 11, 15, 9, 12, 12, 14, 10, 10, + 12, 16, 11, 12, 14, 15, 11, 11, 16, 16, 13, 14, 16, 16, 12, 11, + 9, 14, 10, 12, 11, 13, 11, 11, 12, 16, 11, 13, 12, 14, 11, 11, + 16, 16, 14, 14, 15, 15, 13, 12, 10, 15, 10, 12, 12, 14, 11, 11, + 12, 16, 11, 13, 13, 14, 11, 11, 16, 16, 14, 14, 15, 16, 13, 12, + 12, 16, 10, 12, 13, 15, 11, 11, 13, 16, 11, 13, 14, 15, 11, 11, + 16, 16, 13, 13, 15, 16, 12, 11, 12, 16, 11, 13, 10, 13, 11, 11, + 14, 16, 13, 14, 12, 14, 11, 11, 16, 16, 15, 16, 14, 15, 13, 11, + 13, 16, 12, 14, 12, 14, 11, 11, 13, 16, 12, 14, 12, 14, 11, 11, + 16, 16, 14, 15, 14, 14, 12, 11, 14, 16, 12, 13, 13, 15, 11, 11, + 14, 16, 12, 13, 13, 14, 11, 11, 15, 16, 12, 13, 13, 13, 10, 9, + }, + }, + { + { + 0, 7, 4, 7, 5, 7, 6, 6, 6, 10, 7, 8, 8, 9, 8, 7, + 13, 14, 11, 12, 12, 12, 11, 9, 5, 9, 6, 8, 7, 9, 7, 7, + 8, 11, 8, 9, 9, 10, 9, 8, 13, 16, 12, 12, 12, 13, 11, 9, + 10, 13, 8, 10, 11, 12, 9, 9, 12, 14, 10, 11, 12, 13, 10, 9, + 15, 16, 12, 12, 14, 14, 11, 9, 6, 10, 7, 9, 7, 9, 8, 7, + 8, 11, 9, 10, 9, 10, 9, 8, 14, 16, 12, 12, 13, 12, 11, 9, + 8, 11, 8, 10, 9, 10, 9, 8, 10, 13, 10, 11, 10, 11, 9, 9, + 14, 16, 12, 12, 13, 13, 11, 9, 12, 15, 10, 11, 12, 13, 10, 9, + 13, 16, 11, 12, 13, 13, 10, 9, 16, 16, 12, 13, 14, 14, 11, 9, + 10, 14, 11, 12, 9, 11, 10, 9, 12, 15, 12, 13, 11, 12, 11, 9, + 16, 16, 13, 13, 13, 13, 11, 9, 12, 15, 12, 13, 11, 12, 11, 9, + 13, 16, 12, 13, 12, 13, 11, 10, 16, 16, 13, 13, 13, 13, 11, 9, + 14, 16, 13, 13, 13, 14, 11, 10, 16, 16, 13, 13, 13, 14, 11, 10, + 16, 16, 13, 13, 14, 14, 11, 9, 4, 9, 6, 8, 6, 9, 7, 7, + 8, 11, 8, 9, 9, 10, 9, 8, 13, 15, 12, 12, 13, 13, 11, 9, + 6, 10, 7, 9, 8, 10, 8, 8, 9, 12, 9, 10, 10, 11, 9, 8, + 14, 16, 12, 12, 13, 13, 11, 10, 10, 13, 8, 10, 11, 12, 9, 9, + 12, 15, 10, 11, 12, 13, 10, 9, 16, 16, 12, 12, 14, 14, 11, 9, + 7, 11, 8, 9, 7, 10, 8, 8, 9, 12, 10, 11, 9, 11, 9, 9, + 14, 16, 12, 13, 13, 13, 11, 10, 9, 12, 9, 10, 9, 11, 9, 9, + 10, 13, 10, 11, 10, 11, 10, 9, 14, 16, 12, 13, 13, 13, 11, 9, + 12, 15, 10, 11, 12, 13, 10, 9, 13, 16, 11, 12, 13, 13, 10, 9, + 16, 16, 12, 12, 14, 14, 11, 9, 10, 14, 11, 12, 9, 11, 10, 9, + 12, 16, 12, 13, 11, 12, 11, 9, 16, 16, 14, 14, 13, 13, 11, 9, + 12, 16, 12, 13, 11, 12, 10, 10, 13, 16, 12, 13, 11, 12, 11, 10, + 16, 16, 13, 13, 13, 13, 11, 9, 14, 16, 13, 13, 13, 14, 11, 9, + 15, 16, 13, 13, 13, 14, 11, 9, 16, 16, 13, 13, 13, 13, 10, 8, + 7, 11, 8, 10, 9, 11, 9, 9, 10, 13, 10, 11, 11, 12, 10, 10, + 15, 16, 13, 13, 14, 14, 12, 10, 9, 13, 9, 11, 10, 12, 10, 9, + 11, 14, 10, 12, 12, 13, 10, 10, 16, 16, 13, 13, 14, 14, 12, 10, + 11, 15, 9, 11, 12, 13, 10, 9, 13, 16, 11, 12, 13, 14, 11, 10, + 16, 16, 13, 13, 15, 15, 11, 10, 9, 13, 10, 11, 9, 11, 10, 9, + 11, 14, 11, 12, 11, 12, 11, 10, 16, 16, 14, 14, 14, 14, 12, 10, + 10, 14, 10, 12, 11, 12, 10, 10, 12, 15, 11, 12, 12, 13, 11, 10, + 16, 16, 13, 13, 14, 14, 12, 10, 13, 16, 11, 12, 13, 14, 11, 10, + 13, 16, 11, 12, 13, 14, 11, 10, 16, 16, 12, 13, 14, 14, 11, 9, + 11, 15, 12, 13, 10, 12, 10, 10, 13, 16, 13, 14, 11, 13, 11, 10, + 16, 16, 14, 14, 14, 14, 12, 10, 13, 16, 13, 13, 11, 13, 11, 10, + 14, 16, 13, 14, 12, 13, 11, 10, 16, 16, 14, 14, 13, 13, 12, 10, + 15, 16, 13, 14, 14, 14, 11, 10, 15, 16, 13, 13, 13, 14, 11, 10, + 16, 16, 12, 13, 13, 13, 10, 8, 9, 13, 10, 11, 10, 12, 10, 10, + 12, 15, 11, 12, 12, 13, 11, 10, 16, 16, 14, 13, 14, 14, 12, 10, + 10, 14, 10, 12, 11, 13, 10, 10, 13, 16, 11, 12, 12, 14, 11, 10, + 16, 16, 13, 13, 14, 14, 12, 10, 12, 16, 9, 11, 12, 14, 10, 9, + 13, 16, 10, 12, 13, 14, 10, 9, 16, 16, 12, 12, 14, 14, 11, 9, + 10, 14, 11, 12, 10, 12, 10, 10, 13, 16, 12, 13, 12, 13, 11, 10, + 16, 16, 14, 14, 14, 14, 12, 10, 11, 16, 11, 12, 11, 13, 11, 10, + 13, 16, 12, 13, 12, 14, 11, 10, 16, 16, 14, 14, 14, 14, 12, 10, + 13, 16, 11, 12, 13, 14, 10, 9, 14, 16, 11, 12, 13, 14, 10, 9, + 16, 16, 12, 12, 14, 14, 10, 8, 12, 16, 12, 13, 10, 12, 10, 9, + 14, 16, 13, 13, 11, 12, 11, 9, 16, 16, 14, 14, 13, 13, 11, 9, + 13, 16, 12, 13, 11, 12, 10, 9, 14, 16, 13, 13, 11, 13, 11, 9, + 16, 16, 14, 14, 13, 13, 11, 9, 14, 16, 12, 13, 12, 13, 10, 8, + 14, 16, 12, 12, 12, 13, 10, 8, 15, 16, 11, 11, 11, 12, 9, 6, + }, + { + 0, 7, 4, 7, 5, 8, 7, 8, 5, 10, 7, 10, 8, 10, 9, 10, + 13, 16, 12, 14, 14, 14, 13, 12, 4, 10, 6, 9, 8, 11, 9, 9, + 8, 12, 8, 11, 10, 12, 10, 10, 14, 16, 13, 14, 14, 15, 13, 12, + 9, 14, 9, 12, 12, 14, 11, 11, 12, 16, 11, 13, 13, 15, 12, 12, + 15, 16, 14, 15, 15, 16, 13, 13, 5, 10, 7, 10, 7, 10, 9, 9, + 8, 12, 9, 11, 9, 11, 10, 10, 14, 16, 13, 14, 14, 15, 13, 12, + 7, 12, 8, 11, 10, 12, 10, 10, 10, 13, 10, 12, 11, 13, 11, 11, + 15, 16, 13, 15, 14, 16, 13, 13, 11, 16, 11, 13, 13, 16, 12, 12, + 13, 16, 12, 14, 14, 16, 12, 12, 16, 16, 14, 16, 16, 16, 14, 13, + 11, 15, 12, 14, 11, 13, 11, 12, 13, 16, 12, 14, 12, 14, 12, 12, + 16, 16, 14, 16, 14, 16, 13, 13, 13, 16, 12, 14, 12, 14, 12, 12, + 14, 16, 13, 15, 13, 15, 13, 13, 16, 16, 15, 16, 16, 16, 14, 13, + 15, 16, 13, 16, 15, 16, 13, 13, 16, 16, 14, 16, 16, 16, 14, 13, + 16, 16, 16, 16, 16, 16, 14, 13, 2, 9, 5, 8, 6, 9, 8, 9, + 7, 11, 8, 10, 9, 11, 9, 10, 14, 16, 13, 14, 14, 15, 13, 12, + 5, 11, 6, 10, 9, 11, 9, 10, 8, 13, 9, 11, 11, 12, 10, 11, + 14, 16, 13, 14, 14, 16, 13, 13, 9, 15, 9, 12, 12, 14, 11, 11, + 12, 16, 11, 13, 13, 15, 12, 12, 16, 16, 14, 15, 16, 16, 14, 13, + 6, 11, 7, 10, 8, 11, 9, 10, 9, 13, 9, 12, 10, 12, 10, 11, + 14, 16, 13, 14, 14, 15, 13, 13, 8, 12, 8, 11, 10, 12, 10, 11, + 9, 13, 10, 12, 11, 13, 11, 11, 14, 16, 13, 14, 14, 16, 13, 13, + 12, 16, 11, 13, 13, 15, 12, 12, 13, 16, 11, 13, 14, 16, 12, 12, + 16, 16, 14, 15, 16, 16, 13, 13, 11, 15, 11, 14, 10, 13, 11, 12, + 13, 16, 13, 15, 12, 14, 12, 12, 16, 16, 15, 16, 15, 16, 14, 13, + 12, 16, 12, 14, 12, 14, 12, 12, 13, 16, 13, 15, 13, 14, 12, 13, + 16, 16, 15, 16, 15, 16, 13, 13, 15, 16, 13, 16, 15, 16, 13, 13, + 16, 16, 14, 16, 16, 16, 13, 13, 16, 16, 15, 16, 16, 16, 14, 13, + 5, 12, 7, 10, 9, 12, 10, 10, 9, 13, 9, 12, 11, 13, 11, 11, + 15, 16, 13, 14, 15, 15, 13, 13, 7, 13, 8, 11, 10, 13, 10, 11, + 10, 14, 10, 12, 12, 14, 11, 12, 16, 16, 14, 15, 16, 16, 14, 13, + 10, 16, 9, 12, 13, 15, 11, 12, 13, 16, 11, 13, 14, 16, 12, 12, + 16, 16, 14, 16, 16, 16, 14, 13, 8, 13, 9, 12, 9, 12, 10, 11, + 11, 15, 11, 13, 11, 13, 11, 12, 16, 16, 14, 16, 16, 16, 14, 13, + 9, 14, 10, 12, 11, 13, 11, 12, 11, 15, 11, 13, 12, 14, 12, 12, + 16, 16, 14, 16, 15, 16, 14, 13, 12, 16, 11, 14, 14, 16, 12, 12, + 13, 16, 12, 14, 14, 16, 13, 13, 16, 16, 13, 15, 16, 16, 14, 13, + 11, 16, 12, 14, 10, 13, 12, 12, 13, 16, 13, 15, 12, 14, 12, 13, + 16, 16, 16, 16, 16, 16, 14, 14, 13, 16, 13, 15, 12, 15, 12, 13, + 13, 16, 13, 15, 12, 15, 13, 13, 16, 16, 15, 16, 14, 16, 14, 13, + 16, 16, 14, 16, 16, 16, 14, 13, 15, 16, 14, 16, 15, 16, 14, 13, + 16, 16, 14, 16, 15, 16, 13, 12, 8, 14, 9, 12, 10, 14, 11, 12, + 11, 16, 10, 13, 12, 14, 12, 12, 16, 16, 14, 15, 15, 16, 14, 13, + 9, 15, 9, 12, 12, 14, 11, 12, 12, 16, 11, 13, 13, 15, 12, 12, + 16, 16, 14, 15, 16, 16, 14, 13, 11, 16, 9, 12, 13, 15, 11, 11, + 13, 16, 11, 13, 14, 16, 12, 12, 16, 16, 14, 14, 16, 16, 13, 12, + 9, 15, 10, 13, 11, 14, 11, 12, 12, 16, 11, 14, 12, 14, 12, 12, + 16, 16, 14, 16, 16, 16, 14, 13, 10, 16, 10, 13, 12, 15, 12, 12, + 12, 16, 12, 14, 13, 15, 12, 12, 16, 16, 14, 16, 16, 16, 14, 13, + 12, 16, 11, 13, 13, 16, 12, 12, 13, 16, 11, 13, 14, 16, 12, 12, + 16, 16, 13, 14, 16, 16, 13, 12, 11, 16, 12, 14, 10, 13, 11, 12, + 13, 16, 13, 15, 12, 14, 12, 12, 16, 16, 16, 16, 15, 16, 13, 12, + 12, 16, 12, 15, 12, 14, 12, 12, 13, 16, 13, 15, 12, 14, 12, 12, + 16, 16, 15, 16, 14, 15, 13, 12, 14, 16, 13, 14, 13, 16, 12, 12, + 13, 16, 12, 14, 13, 15, 12, 12, 14, 16, 12, 13, 13, 14, 11, 10, + }, + }, + { + { + 0, 7, 4, 7, 5, 7, 6, 6, 6, 10, 7, 8, 8, 9, 8, 8, + 13, 14, 11, 12, 12, 12, 11, 10, 5, 9, 6, 8, 7, 9, 7, 7, + 8, 11, 8, 9, 9, 10, 9, 8, 13, 16, 12, 12, 13, 13, 11, 10, + 10, 14, 8, 10, 11, 13, 9, 9, 12, 15, 10, 11, 12, 13, 10, 10, + 16, 16, 12, 13, 14, 14, 11, 10, 5, 10, 7, 9, 6, 9, 8, 8, + 8, 11, 9, 10, 9, 10, 9, 8, 14, 16, 12, 12, 13, 13, 11, 10, + 8, 12, 8, 10, 9, 10, 9, 9, 10, 13, 9, 11, 10, 11, 9, 9, + 14, 16, 12, 13, 13, 13, 11, 10, 12, 16, 10, 12, 12, 13, 10, 10, + 13, 16, 11, 12, 13, 14, 11, 10, 16, 16, 12, 13, 14, 14, 11, 10, + 10, 14, 11, 13, 9, 11, 10, 10, 12, 16, 12, 13, 11, 12, 11, 10, + 16, 16, 13, 14, 13, 13, 12, 10, 12, 16, 12, 13, 11, 13, 11, 10, + 13, 16, 12, 13, 12, 13, 11, 10, 16, 16, 13, 14, 13, 14, 12, 10, + 14, 16, 13, 14, 13, 14, 12, 11, 16, 16, 13, 14, 14, 15, 12, 11, + 16, 16, 13, 14, 14, 14, 11, 10, 3, 9, 5, 8, 6, 9, 7, 7, + 8, 11, 8, 10, 9, 10, 9, 8, 14, 15, 12, 12, 13, 13, 11, 10, + 6, 11, 6, 9, 8, 10, 8, 8, 9, 12, 9, 10, 10, 11, 9, 9, + 14, 16, 12, 13, 13, 13, 11, 10, 10, 14, 8, 11, 12, 13, 9, 9, + 12, 16, 10, 11, 12, 13, 10, 10, 16, 16, 12, 13, 14, 14, 11, 10, + 6, 11, 8, 10, 7, 10, 8, 8, 9, 12, 10, 11, 9, 11, 9, 9, + 14, 16, 12, 13, 13, 13, 12, 10, 9, 12, 9, 11, 9, 11, 9, 9, + 10, 13, 10, 11, 10, 12, 10, 9, 14, 16, 12, 13, 13, 13, 11, 10, + 12, 16, 10, 12, 12, 14, 10, 10, 13, 16, 10, 12, 13, 14, 11, 10, + 16, 16, 12, 13, 14, 14, 11, 10, 10, 15, 11, 13, 9, 11, 10, 10, + 12, 16, 12, 13, 11, 12, 11, 10, 16, 16, 14, 14, 13, 14, 12, 10, + 12, 16, 12, 13, 11, 13, 11, 10, 13, 16, 12, 13, 11, 13, 11, 10, + 16, 16, 13, 14, 13, 13, 12, 10, 14, 16, 13, 14, 14, 14, 11, 11, + 15, 16, 13, 14, 13, 14, 11, 10, 16, 16, 13, 13, 13, 14, 11, 9, + 7, 12, 8, 11, 9, 11, 9, 10, 10, 14, 10, 12, 11, 12, 11, 10, + 16, 16, 13, 13, 14, 14, 12, 11, 9, 13, 9, 11, 10, 12, 10, 10, + 11, 15, 10, 12, 12, 13, 11, 10, 16, 16, 13, 14, 14, 14, 12, 11, + 11, 16, 9, 11, 12, 14, 10, 10, 13, 16, 10, 12, 13, 14, 11, 10, + 16, 16, 13, 14, 16, 16, 12, 11, 9, 13, 10, 12, 9, 12, 10, 10, + 11, 15, 11, 13, 11, 13, 11, 11, 16, 16, 14, 14, 14, 14, 13, 11, + 10, 14, 10, 12, 11, 13, 11, 10, 12, 16, 11, 13, 12, 13, 11, 11, + 16, 16, 13, 14, 14, 14, 12, 11, 13, 16, 11, 13, 13, 14, 11, 11, + 13, 16, 11, 13, 13, 14, 11, 11, 16, 16, 12, 13, 14, 15, 12, 10, + 11, 16, 12, 14, 10, 12, 11, 10, 13, 16, 13, 14, 11, 13, 11, 11, + 16, 16, 15, 16, 14, 14, 13, 11, 13, 16, 13, 14, 12, 13, 11, 11, + 13, 16, 13, 14, 12, 13, 11, 11, 16, 16, 14, 14, 13, 14, 12, 11, + 15, 16, 13, 14, 14, 16, 12, 11, 14, 16, 13, 14, 13, 14, 12, 11, + 16, 16, 12, 13, 13, 14, 11, 9, 9, 14, 10, 12, 10, 13, 11, 11, + 12, 16, 12, 13, 12, 14, 12, 11, 16, 16, 14, 14, 14, 14, 13, 11, + 10, 16, 10, 13, 12, 14, 11, 11, 13, 16, 12, 13, 13, 14, 12, 11, + 16, 16, 14, 14, 15, 15, 13, 11, 12, 16, 9, 12, 13, 14, 10, 10, + 14, 16, 11, 12, 13, 15, 11, 10, 16, 16, 13, 13, 15, 16, 11, 10, + 10, 16, 11, 13, 11, 13, 11, 11, 13, 16, 12, 14, 12, 14, 12, 11, + 16, 16, 14, 14, 14, 14, 13, 11, 11, 16, 11, 13, 12, 14, 11, 11, + 13, 16, 12, 14, 13, 14, 12, 11, 16, 16, 14, 14, 14, 15, 13, 11, + 13, 16, 11, 13, 13, 14, 11, 10, 14, 16, 11, 13, 13, 14, 11, 10, + 16, 16, 12, 13, 14, 15, 11, 9, 12, 16, 12, 14, 10, 13, 11, 10, + 14, 16, 13, 14, 11, 13, 11, 10, 16, 16, 14, 15, 13, 14, 12, 10, + 13, 16, 13, 14, 11, 13, 11, 10, 14, 16, 13, 14, 12, 13, 11, 10, + 16, 16, 14, 14, 13, 13, 11, 10, 14, 16, 12, 13, 13, 14, 11, 9, + 14, 16, 12, 13, 12, 13, 10, 9, 14, 16, 11, 11, 12, 12, 9, 7, + }, + { + 0, 7, 3, 8, 5, 8, 7, 9, 5, 10, 7, 10, 8, 11, 10, 10, + 14, 16, 14, 15, 14, 16, 14, 14, 4, 10, 6, 10, 8, 11, 9, 10, + 8, 12, 9, 11, 10, 12, 11, 11, 15, 16, 14, 16, 15, 16, 14, 14, + 10, 16, 10, 13, 13, 16, 12, 13, 13, 16, 12, 14, 14, 16, 13, 13, + 16, 16, 16, 16, 16, 16, 14, 15, 4, 10, 7, 10, 7, 10, 9, 10, + 8, 12, 9, 12, 10, 12, 11, 12, 14, 16, 14, 16, 15, 16, 14, 14, + 8, 12, 9, 12, 10, 13, 11, 12, 10, 14, 11, 13, 11, 14, 12, 13, + 16, 16, 14, 16, 16, 16, 14, 15, 12, 16, 12, 14, 14, 16, 13, 14, + 14, 16, 13, 16, 16, 16, 14, 14, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 12, 16, 11, 14, 13, 13, 13, 16, 13, 16, 13, 15, 13, 14, + 16, 16, 16, 16, 16, 16, 15, 16, 13, 16, 13, 16, 13, 16, 13, 14, + 14, 16, 14, 16, 14, 16, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 15, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 2, 9, 5, 9, 6, 10, 8, 10, + 7, 11, 8, 11, 9, 12, 10, 11, 14, 16, 14, 16, 15, 16, 14, 14, + 5, 11, 6, 10, 9, 12, 10, 11, 9, 13, 9, 12, 11, 13, 11, 12, + 16, 16, 14, 16, 16, 16, 14, 14, 10, 16, 9, 13, 13, 16, 12, 13, + 13, 16, 12, 14, 14, 16, 13, 13, 16, 16, 16, 16, 16, 16, 16, 14, + 5, 11, 8, 11, 7, 11, 10, 11, 9, 13, 10, 13, 10, 13, 11, 12, + 16, 16, 14, 16, 16, 16, 14, 14, 8, 13, 9, 12, 10, 13, 11, 12, + 10, 14, 10, 13, 11, 14, 12, 12, 16, 16, 14, 16, 15, 16, 14, 14, + 12, 16, 12, 14, 14, 16, 13, 14, 14, 16, 12, 16, 15, 16, 13, 14, + 16, 16, 15, 16, 16, 16, 15, 15, 11, 16, 12, 16, 10, 14, 12, 13, + 13, 16, 14, 16, 13, 16, 13, 14, 16, 16, 16, 16, 16, 16, 15, 16, + 13, 16, 13, 16, 13, 16, 13, 14, 14, 16, 14, 16, 13, 16, 13, 14, + 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 15, 16, 16, 16, 15, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, + 5, 13, 7, 12, 9, 13, 11, 12, 10, 14, 10, 13, 11, 13, 12, 13, + 16, 16, 16, 16, 16, 16, 16, 15, 7, 14, 8, 12, 11, 14, 11, 12, + 11, 16, 11, 13, 13, 16, 13, 13, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 10, 14, 14, 16, 12, 13, 13, 16, 12, 15, 16, 16, 14, 14, + 16, 16, 16, 16, 16, 16, 16, 16, 8, 14, 10, 13, 9, 13, 11, 12, + 11, 16, 12, 14, 12, 14, 13, 13, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 11, 14, 12, 14, 12, 13, 11, 16, 12, 14, 12, 15, 13, 13, + 16, 16, 15, 16, 16, 16, 15, 16, 13, 16, 12, 16, 15, 16, 14, 14, + 13, 16, 12, 16, 16, 16, 14, 14, 16, 16, 14, 16, 16, 16, 14, 16, + 11, 16, 13, 16, 10, 14, 12, 13, 14, 16, 14, 16, 13, 16, 14, 14, + 16, 16, 16, 16, 16, 16, 16, 16, 13, 16, 14, 16, 13, 16, 14, 15, + 13, 16, 14, 16, 13, 16, 14, 15, 16, 16, 16, 16, 15, 16, 15, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 15, 16, + 16, 16, 15, 16, 16, 16, 14, 14, 8, 16, 10, 14, 11, 16, 12, 13, + 12, 16, 12, 14, 13, 16, 13, 14, 16, 16, 16, 16, 16, 16, 16, 14, + 10, 16, 10, 14, 12, 16, 12, 13, 13, 16, 12, 15, 14, 16, 13, 14, + 16, 16, 16, 16, 16, 16, 16, 15, 11, 16, 10, 13, 13, 16, 12, 13, + 14, 16, 12, 14, 15, 16, 13, 13, 16, 16, 16, 16, 16, 16, 15, 14, + 10, 16, 11, 14, 11, 16, 12, 13, 13, 16, 13, 16, 13, 16, 13, 14, + 16, 16, 16, 16, 16, 16, 16, 15, 11, 16, 12, 14, 13, 16, 13, 14, + 13, 16, 13, 16, 14, 16, 13, 14, 16, 16, 16, 16, 16, 16, 16, 15, + 13, 16, 12, 14, 14, 16, 13, 13, 13, 16, 12, 15, 14, 16, 13, 13, + 16, 16, 14, 16, 16, 16, 14, 13, 11, 16, 12, 16, 11, 15, 12, 13, + 14, 16, 14, 16, 13, 16, 13, 14, 16, 16, 16, 16, 16, 16, 14, 14, + 12, 16, 13, 16, 12, 16, 13, 14, 13, 16, 14, 16, 13, 16, 13, 14, + 16, 16, 16, 16, 14, 16, 14, 14, 14, 16, 13, 16, 14, 16, 13, 13, + 13, 16, 13, 16, 14, 16, 13, 13, 15, 16, 13, 14, 13, 15, 12, 12, + }, + }, + { + { + 0, 7, 4, 6, 4, 7, 6, 7, 6, 9, 7, 8, 7, 9, 8, 8, + 13, 14, 12, 12, 12, 13, 11, 11, 5, 9, 5, 8, 7, 9, 7, 8, + 8, 11, 8, 10, 9, 10, 9, 9, 13, 15, 12, 13, 12, 13, 11, 11, + 9, 14, 8, 11, 11, 13, 10, 10, 11, 15, 10, 12, 12, 13, 10, 11, + 14, 16, 12, 13, 14, 14, 12, 11, 5, 9, 7, 9, 6, 9, 8, 8, + 8, 11, 8, 10, 8, 10, 9, 9, 13, 16, 12, 13, 13, 13, 11, 11, + 7, 11, 8, 10, 9, 11, 9, 9, 9, 13, 9, 11, 10, 11, 10, 10, + 14, 16, 12, 13, 13, 13, 12, 11, 11, 16, 10, 12, 12, 14, 11, 11, + 13, 16, 11, 13, 13, 14, 11, 11, 16, 16, 13, 14, 14, 15, 12, 11, + 10, 15, 11, 13, 9, 12, 10, 10, 12, 16, 12, 13, 11, 12, 11, 11, + 15, 16, 13, 14, 13, 14, 12, 11, 12, 16, 12, 14, 11, 13, 11, 11, + 13, 16, 12, 14, 12, 13, 12, 11, 16, 16, 13, 14, 14, 14, 12, 11, + 14, 16, 13, 14, 14, 15, 12, 12, 16, 16, 13, 14, 14, 16, 12, 12, + 16, 16, 14, 14, 14, 15, 12, 11, 3, 9, 5, 8, 6, 9, 7, 8, + 7, 11, 8, 10, 9, 10, 9, 9, 13, 14, 12, 13, 13, 13, 12, 11, + 6, 11, 6, 9, 8, 10, 8, 9, 9, 12, 8, 10, 10, 11, 9, 10, + 14, 16, 12, 13, 13, 14, 12, 11, 9, 14, 8, 11, 11, 13, 10, 10, + 12, 16, 10, 12, 12, 14, 11, 11, 16, 16, 12, 13, 14, 15, 12, 11, + 6, 11, 8, 10, 7, 10, 8, 9, 9, 12, 9, 11, 9, 11, 10, 10, + 14, 16, 13, 13, 13, 14, 12, 11, 8, 12, 9, 11, 9, 11, 9, 10, + 10, 13, 9, 11, 10, 12, 10, 10, 14, 16, 12, 13, 13, 14, 12, 11, + 12, 16, 10, 12, 12, 14, 11, 11, 12, 16, 10, 12, 13, 14, 11, 11, + 15, 16, 12, 13, 14, 14, 11, 11, 10, 15, 11, 13, 9, 12, 10, 10, + 12, 16, 12, 14, 11, 13, 11, 11, 16, 16, 14, 14, 14, 14, 12, 11, + 12, 16, 12, 14, 11, 13, 11, 11, 13, 16, 12, 14, 11, 13, 11, 11, + 16, 16, 13, 14, 13, 14, 12, 11, 14, 16, 13, 14, 14, 15, 12, 11, + 14, 16, 13, 14, 13, 15, 12, 11, 16, 16, 13, 14, 13, 14, 11, 10, + 6, 13, 8, 11, 9, 12, 10, 10, 10, 14, 10, 12, 11, 13, 11, 11, + 16, 16, 13, 14, 14, 14, 13, 12, 8, 14, 8, 12, 10, 13, 10, 11, + 11, 15, 10, 12, 12, 13, 11, 11, 16, 16, 14, 14, 15, 16, 13, 12, + 11, 16, 9, 12, 12, 14, 11, 11, 13, 16, 11, 13, 13, 16, 11, 11, + 16, 16, 13, 14, 16, 16, 13, 12, 8, 14, 10, 12, 9, 12, 10, 11, + 11, 15, 11, 13, 11, 13, 11, 11, 16, 16, 14, 15, 14, 15, 13, 12, + 10, 15, 10, 13, 11, 13, 11, 11, 11, 15, 11, 13, 12, 13, 11, 11, + 16, 16, 13, 15, 14, 15, 13, 12, 12, 16, 11, 13, 13, 15, 11, 11, + 13, 16, 11, 13, 13, 15, 11, 11, 16, 16, 12, 14, 14, 16, 12, 11, + 11, 16, 12, 14, 10, 13, 11, 11, 13, 16, 13, 15, 12, 14, 12, 12, + 16, 16, 15, 16, 14, 15, 13, 12, 12, 16, 13, 14, 12, 14, 12, 12, + 13, 16, 13, 14, 12, 14, 12, 12, 16, 16, 14, 15, 13, 14, 12, 12, + 15, 16, 13, 15, 14, 16, 12, 12, 14, 16, 13, 14, 13, 15, 12, 12, + 15, 16, 12, 13, 13, 14, 11, 10, 9, 15, 10, 13, 11, 14, 11, 12, + 12, 16, 12, 14, 12, 14, 12, 12, 16, 16, 14, 14, 14, 15, 13, 12, + 10, 16, 10, 13, 12, 14, 12, 12, 13, 16, 12, 14, 13, 15, 12, 12, + 16, 16, 14, 14, 15, 16, 13, 12, 11, 16, 9, 12, 13, 15, 11, 11, + 14, 16, 11, 13, 14, 16, 11, 11, 16, 16, 13, 14, 16, 16, 12, 11, + 10, 16, 11, 14, 11, 14, 12, 12, 13, 16, 13, 14, 12, 14, 12, 12, + 16, 16, 14, 15, 15, 15, 13, 12, 11, 16, 12, 14, 12, 15, 12, 12, + 13, 16, 12, 14, 13, 15, 12, 12, 16, 16, 14, 15, 15, 16, 13, 12, + 12, 16, 11, 13, 13, 15, 11, 11, 13, 16, 11, 13, 13, 15, 11, 11, + 16, 16, 12, 13, 14, 16, 12, 10, 11, 16, 12, 14, 10, 13, 11, 11, + 14, 16, 13, 14, 12, 14, 11, 11, 16, 16, 15, 16, 14, 14, 12, 11, + 12, 16, 13, 14, 11, 14, 11, 11, 13, 16, 13, 14, 12, 14, 11, 11, + 16, 16, 14, 15, 13, 14, 12, 11, 14, 16, 12, 14, 13, 14, 11, 10, + 13, 16, 12, 13, 12, 14, 11, 10, 14, 16, 11, 12, 12, 12, 10, 8, + }, + { + 0, 8, 4, 9, 5, 9, 8, 10, 6, 11, 8, 11, 9, 12, 11, 12, + 16, 16, 16, 16, 16, 16, 16, 16, 4, 11, 6, 11, 9, 12, 10, 12, + 9, 13, 10, 13, 11, 16, 12, 13, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 11, 16, 16, 16, 14, 16, 14, 16, 13, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 4, 11, 8, 12, 7, 12, 10, 12, + 8, 13, 10, 13, 10, 13, 12, 14, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 13, 10, 14, 11, 16, 12, 14, 11, 16, 12, 16, 12, 16, 13, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 13, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 14, 16, 12, 16, 16, 16, 13, 16, 16, 16, 14, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 1, 10, 5, 10, 7, 11, 9, 11, + 8, 12, 9, 12, 10, 13, 12, 13, 16, 16, 16, 16, 16, 16, 16, 16, + 5, 12, 7, 12, 10, 13, 11, 12, 9, 16, 10, 13, 12, 16, 13, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 10, 16, 16, 16, 14, 16, + 14, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 6, 12, 9, 13, 8, 12, 11, 13, 10, 16, 11, 16, 11, 16, 13, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 10, 14, 11, 16, 12, 16, + 10, 16, 11, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 14, 16, 13, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 14, 16, 11, 16, 14, 16, + 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 6, 16, 9, 13, 10, 16, 12, 14, 11, 16, 12, 16, 12, 16, 13, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 9, 14, 12, 16, 13, 16, + 12, 16, 12, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 10, 16, 16, 16, 14, 16, 16, 16, 13, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 11, 16, 10, 16, 12, 16, + 12, 16, 13, 16, 13, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 12, 16, 13, 16, 14, 16, 11, 16, 13, 16, 13, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 13, 16, 16, 16, 16, 16, + 14, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 11, 16, 14, 16, 16, 16, 16, 16, 14, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 11, 16, 12, 16, 13, 16, + 13, 16, 13, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 11, 16, 13, 16, 14, 16, 14, 16, 13, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 10, 16, 16, 16, 13, 16, + 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 12, 16, 12, 16, 13, 16, 13, 16, 16, 16, 14, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 13, 16, 14, 16, 16, 16, + 13, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 12, 16, 16, 16, 14, 16, 14, 16, 13, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 13, 16, 11, 16, 13, 16, + 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 13, 16, 16, 16, 13, 16, 16, 16, 13, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 14, 15, + }, + }, + { + { + 0, 7, 3, 7, 4, 7, 6, 7, 6, 9, 7, 9, 7, 9, 8, 9, + 13, 14, 12, 13, 13, 13, 12, 12, 4, 9, 5, 9, 7, 9, 8, 9, + 7, 11, 8, 10, 9, 11, 9, 10, 13, 16, 12, 14, 13, 14, 12, 12, + 9, 14, 8, 12, 12, 14, 10, 11, 11, 16, 10, 13, 13, 14, 11, 12, + 15, 16, 13, 14, 14, 16, 12, 12, 5, 10, 7, 9, 6, 9, 8, 9, + 8, 11, 8, 11, 8, 10, 9, 10, 14, 16, 12, 14, 13, 14, 12, 12, + 7, 12, 8, 11, 9, 11, 9, 10, 9, 13, 9, 12, 10, 12, 10, 11, + 14, 16, 12, 14, 13, 14, 12, 12, 12, 16, 11, 13, 13, 15, 11, 12, + 13, 16, 11, 14, 13, 15, 12, 12, 15, 16, 13, 15, 14, 16, 13, 13, + 10, 15, 12, 14, 9, 13, 11, 12, 12, 16, 12, 14, 11, 13, 12, 12, + 15, 16, 13, 15, 14, 15, 13, 13, 12, 16, 12, 14, 12, 14, 12, 12, + 13, 16, 13, 14, 12, 14, 12, 12, 16, 16, 14, 15, 14, 16, 13, 13, + 15, 16, 13, 15, 14, 16, 12, 13, 16, 16, 14, 16, 14, 16, 13, 13, + 16, 16, 14, 16, 15, 16, 13, 13, 3, 9, 5, 9, 6, 9, 8, 9, + 7, 11, 8, 10, 9, 11, 9, 10, 14, 15, 13, 14, 13, 14, 12, 12, + 5, 11, 6, 10, 8, 11, 9, 10, 9, 12, 9, 11, 10, 12, 10, 11, + 14, 16, 13, 14, 14, 15, 13, 13, 9, 15, 8, 12, 12, 14, 10, 11, + 12, 16, 10, 13, 13, 15, 11, 12, 15, 16, 13, 14, 14, 16, 13, 13, + 6, 11, 8, 11, 7, 10, 9, 10, 9, 13, 10, 12, 9, 12, 10, 11, + 14, 16, 13, 14, 14, 14, 13, 13, 8, 13, 9, 12, 9, 12, 10, 11, + 9, 13, 9, 12, 10, 12, 10, 11, 14, 16, 12, 14, 13, 14, 12, 12, + 12, 16, 11, 13, 13, 15, 11, 12, 12, 16, 11, 13, 13, 15, 11, 12, + 14, 16, 12, 14, 14, 15, 12, 12, 10, 15, 11, 14, 9, 13, 11, 12, + 12, 16, 12, 14, 11, 14, 12, 12, 16, 16, 14, 16, 14, 15, 13, 13, + 12, 16, 12, 14, 11, 14, 12, 12, 12, 16, 13, 14, 11, 14, 12, 12, + 15, 16, 14, 15, 13, 15, 12, 13, 14, 16, 13, 15, 14, 16, 13, 13, + 14, 16, 13, 15, 14, 16, 12, 13, 15, 16, 13, 15, 13, 15, 12, 12, + 6, 13, 8, 12, 9, 12, 10, 11, 10, 14, 11, 13, 11, 13, 12, 12, + 15, 16, 14, 15, 15, 15, 14, 13, 8, 14, 9, 12, 11, 13, 11, 12, + 11, 15, 11, 13, 12, 14, 12, 12, 16, 16, 14, 15, 15, 16, 14, 14, + 10, 16, 9, 13, 12, 15, 11, 12, 13, 16, 11, 14, 13, 16, 12, 12, + 16, 16, 14, 15, 16, 16, 13, 13, 8, 14, 10, 13, 9, 13, 11, 12, + 11, 15, 12, 14, 11, 14, 12, 12, 16, 16, 15, 16, 15, 16, 14, 14, + 10, 15, 10, 13, 11, 14, 11, 12, 11, 15, 11, 14, 12, 14, 12, 12, + 15, 16, 14, 15, 14, 16, 13, 13, 12, 16, 11, 14, 13, 16, 12, 12, + 12, 16, 11, 14, 13, 15, 12, 12, 15, 16, 12, 14, 15, 16, 13, 13, + 11, 16, 12, 14, 10, 14, 11, 12, 13, 16, 13, 16, 12, 14, 12, 13, + 16, 16, 16, 16, 15, 16, 14, 13, 12, 16, 13, 15, 12, 14, 12, 13, + 13, 16, 13, 15, 12, 14, 12, 13, 16, 16, 14, 16, 13, 15, 13, 13, + 15, 16, 14, 16, 14, 16, 13, 13, 14, 16, 13, 15, 13, 16, 13, 13, + 14, 16, 12, 14, 13, 14, 12, 12, 9, 16, 11, 14, 11, 15, 12, 13, + 13, 16, 12, 14, 12, 15, 13, 13, 16, 16, 14, 15, 15, 15, 14, 13, + 11, 16, 11, 14, 12, 16, 12, 13, 13, 16, 12, 14, 13, 16, 13, 13, + 16, 16, 14, 15, 16, 16, 14, 13, 11, 16, 10, 13, 13, 16, 11, 12, + 14, 16, 11, 14, 14, 16, 12, 12, 16, 16, 14, 14, 16, 16, 13, 12, + 11, 16, 12, 14, 11, 15, 12, 13, 13, 16, 13, 15, 13, 16, 13, 13, + 16, 16, 15, 16, 15, 16, 14, 13, 11, 16, 12, 15, 12, 16, 12, 13, + 13, 16, 13, 15, 13, 16, 13, 13, 16, 16, 15, 16, 15, 16, 14, 13, + 12, 16, 11, 14, 13, 16, 12, 12, 13, 16, 11, 14, 13, 16, 12, 12, + 16, 16, 13, 14, 15, 16, 12, 12, 11, 16, 12, 14, 10, 14, 11, 12, + 14, 16, 13, 15, 12, 15, 12, 12, 16, 16, 16, 16, 14, 15, 13, 12, + 12, 16, 13, 15, 12, 14, 12, 12, 13, 16, 13, 15, 12, 14, 12, 12, + 16, 16, 14, 16, 14, 15, 12, 12, 14, 16, 13, 15, 13, 16, 11, 12, + 13, 16, 12, 14, 13, 15, 11, 11, 14, 16, 12, 13, 12, 13, 11, 10, + }, + { + 0, 8, 4, 9, 5, 10, 9, 11, 5, 11, 9, 12, 9, 13, 12, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 4, 11, 6, 12, 9, 13, 11, 13, + 9, 16, 10, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 4, 12, 8, 13, 7, 12, 11, 16, + 8, 16, 11, 16, 11, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 16, 10, 16, 11, 16, 13, 16, 11, 16, 12, 16, 13, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 1, 10, 6, 11, 7, 12, 10, 13, + 7, 12, 10, 13, 10, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 5, 13, 7, 12, 10, 16, 12, 16, 10, 16, 11, 16, 12, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 11, 16, 16, 16, 16, 16, + 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 5, 13, 9, 16, 8, 16, 12, 16, 9, 16, 12, 16, 11, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 11, 16, 12, 16, 13, 16, + 10, 16, 12, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 16, 16, 12, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 6, 16, 9, 16, 10, 16, 13, 16, 11, 16, 12, 16, 13, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 9, 16, 12, 16, 13, 16, + 12, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 10, 16, 16, 16, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 11, 16, 11, 16, 13, 16, + 12, 16, 13, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 12, 16, 13, 16, 16, 16, 11, 16, 13, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 7, 16, 11, 16, 12, 16, 16, 16, + 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 11, 16, 13, 16, 16, 16, 16, 16, 13, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 10, 16, 16, 16, 16, 16, + 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 12, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 13, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 12, 16, 16, 16, 16, 16, 16, 16, 12, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 16, 16, 11, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 16, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + }, + { + { + 0, 7, 4, 8, 4, 8, 7, 8, 6, 10, 7, 10, 8, 10, 9, 10, + 13, 16, 13, 15, 13, 15, 13, 14, 4, 10, 5, 10, 7, 10, 9, 10, + 7, 12, 8, 11, 9, 12, 10, 11, 13, 16, 13, 15, 13, 16, 13, 14, + 9, 16, 9, 13, 12, 16, 11, 13, 11, 16, 11, 14, 13, 16, 12, 14, + 15, 16, 14, 16, 15, 16, 14, 14, 4, 10, 7, 10, 6, 10, 9, 10, + 8, 12, 9, 12, 9, 11, 10, 12, 13, 16, 13, 16, 14, 16, 13, 14, + 7, 12, 8, 12, 9, 12, 10, 12, 9, 13, 10, 13, 10, 13, 11, 12, + 14, 16, 13, 16, 14, 16, 13, 14, 12, 16, 11, 14, 13, 16, 12, 14, + 13, 16, 12, 16, 14, 16, 13, 14, 16, 16, 14, 16, 15, 16, 14, 14, + 10, 16, 12, 15, 10, 14, 12, 13, 12, 16, 13, 16, 12, 14, 13, 14, + 15, 16, 14, 16, 14, 16, 14, 14, 12, 16, 13, 16, 12, 16, 13, 14, + 13, 16, 13, 16, 13, 16, 13, 14, 16, 16, 14, 16, 15, 16, 14, 15, + 15, 16, 14, 16, 15, 16, 13, 15, 16, 16, 14, 16, 15, 16, 14, 15, + 16, 16, 16, 16, 16, 16, 15, 15, 2, 9, 5, 10, 6, 10, 8, 10, + 7, 11, 8, 11, 9, 11, 10, 11, 14, 16, 13, 15, 14, 15, 14, 14, + 5, 11, 6, 11, 8, 12, 9, 11, 8, 13, 9, 12, 10, 13, 11, 12, + 14, 16, 13, 15, 14, 16, 14, 14, 9, 16, 8, 13, 12, 16, 11, 13, + 12, 16, 11, 14, 13, 16, 12, 13, 16, 16, 14, 16, 15, 16, 14, 15, + 5, 12, 8, 11, 7, 11, 9, 11, 9, 13, 10, 13, 10, 13, 11, 12, + 14, 16, 14, 16, 14, 16, 14, 15, 8, 13, 9, 13, 10, 13, 11, 12, + 9, 13, 10, 13, 10, 13, 11, 13, 13, 16, 13, 15, 13, 16, 13, 14, + 12, 16, 11, 14, 13, 16, 12, 14, 12, 16, 11, 14, 13, 16, 12, 14, + 14, 16, 13, 16, 14, 16, 13, 14, 10, 16, 12, 15, 9, 14, 11, 13, + 12, 16, 13, 16, 12, 15, 12, 14, 16, 16, 15, 16, 15, 16, 14, 14, + 12, 16, 13, 16, 12, 16, 12, 14, 12, 16, 13, 16, 12, 15, 13, 14, + 15, 16, 14, 16, 14, 16, 14, 14, 15, 16, 14, 16, 14, 16, 14, 15, + 14, 16, 13, 16, 14, 16, 13, 14, 16, 16, 14, 16, 14, 16, 13, 14, + 6, 14, 9, 13, 9, 14, 11, 12, 10, 14, 11, 13, 11, 14, 12, 13, + 16, 16, 15, 16, 15, 16, 14, 15, 8, 15, 9, 13, 11, 14, 11, 13, + 11, 16, 11, 14, 12, 15, 12, 14, 16, 16, 15, 16, 16, 16, 15, 16, + 10, 16, 9, 14, 12, 16, 12, 13, 13, 16, 11, 15, 14, 16, 13, 14, + 16, 16, 15, 16, 16, 16, 15, 16, 8, 15, 10, 13, 10, 14, 11, 13, + 11, 16, 12, 14, 12, 14, 12, 14, 16, 16, 16, 16, 16, 16, 15, 16, + 10, 16, 11, 14, 11, 15, 12, 13, 11, 16, 11, 14, 12, 15, 12, 14, + 16, 16, 14, 16, 15, 16, 14, 15, 12, 16, 11, 15, 13, 16, 13, 14, + 12, 16, 11, 14, 13, 16, 13, 14, 15, 16, 13, 16, 16, 16, 14, 15, + 10, 16, 12, 15, 10, 15, 12, 13, 13, 16, 13, 16, 12, 16, 13, 14, + 16, 16, 16, 16, 16, 16, 15, 15, 12, 16, 13, 16, 12, 16, 13, 14, + 12, 16, 13, 16, 12, 16, 13, 14, 16, 16, 15, 16, 14, 16, 14, 15, + 15, 16, 14, 16, 15, 16, 14, 15, 14, 16, 13, 16, 14, 16, 13, 14, + 14, 16, 13, 15, 14, 16, 13, 14, 9, 16, 11, 16, 11, 16, 12, 14, + 13, 16, 12, 16, 13, 16, 13, 14, 16, 16, 15, 16, 16, 16, 15, 15, + 11, 16, 11, 16, 12, 16, 13, 14, 13, 16, 12, 16, 13, 16, 13, 14, + 16, 16, 15, 16, 16, 16, 15, 15, 11, 16, 10, 15, 13, 16, 12, 13, + 14, 16, 12, 16, 14, 16, 13, 14, 16, 16, 15, 16, 16, 16, 14, 14, + 11, 16, 12, 16, 11, 16, 13, 14, 13, 16, 13, 16, 13, 16, 13, 14, + 16, 16, 16, 16, 16, 16, 15, 15, 11, 16, 12, 16, 12, 16, 13, 14, + 13, 16, 13, 16, 13, 16, 13, 14, 16, 16, 15, 16, 16, 16, 15, 14, + 12, 16, 12, 15, 13, 16, 12, 14, 13, 16, 12, 16, 14, 16, 13, 14, + 16, 16, 14, 16, 16, 16, 14, 14, 11, 16, 12, 16, 11, 16, 12, 14, + 14, 16, 14, 16, 12, 16, 13, 14, 16, 16, 16, 16, 16, 16, 15, 14, + 12, 16, 13, 16, 12, 16, 12, 14, 13, 16, 13, 16, 12, 16, 13, 14, + 16, 16, 16, 16, 15, 16, 14, 14, 14, 16, 13, 16, 14, 16, 12, 14, + 13, 16, 13, 16, 13, 16, 12, 13, 15, 16, 13, 14, 14, 15, 13, 13, + }, + { + 0, 8, 4, 10, 5, 11, 10, 16, 5, 12, 9, 16, 10, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 4, 12, 7, 12, 9, 16, 12, 16, + 9, 16, 11, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 4, 12, 9, 16, 8, 16, 12, 16, + 8, 16, 11, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 8, 16, 11, 16, 12, 16, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 1, 11, 6, 12, 7, 16, 11, 16, + 7, 16, 10, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 5, 16, 7, 16, 10, 16, 12, 16, 9, 16, 11, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 11, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 5, 16, 10, 16, 8, 16, 12, 16, 9, 16, 12, 16, 12, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 11, 16, 12, 16, 16, 16, + 10, 16, 12, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 16, 16, 12, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 5, 16, 9, 16, 10, 16, 16, 16, 11, 16, 12, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 9, 16, 12, 16, 16, 16, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 11, 16, 11, 16, 16, 16, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 12, 16, 16, 16, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 11, 16, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 10, 16, 12, 16, 16, 16, + 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 9, 16, 10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 9, 16, 16, 16, 16, 16, + 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 9, 16, 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 13, 16, 12, 16, 16, 16, 16, 16, 16, 16, 12, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 16, 16, 11, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + }, + { + { + 0, 8, 4, 10, 5, 9, 8, 10, 6, 11, 8, 12, 8, 11, 10, 13, + 14, 16, 14, 16, 14, 16, 16, 16, 3, 11, 5, 11, 8, 12, 10, 12, + 7, 12, 9, 13, 10, 13, 11, 13, 14, 16, 14, 16, 16, 16, 16, 16, + 9, 16, 9, 16, 12, 16, 12, 16, 11, 16, 11, 16, 14, 16, 13, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 4, 11, 7, 12, 6, 11, 10, 12, + 8, 13, 9, 13, 9, 13, 11, 14, 13, 16, 14, 16, 14, 16, 16, 16, + 7, 13, 9, 13, 9, 13, 11, 13, 9, 14, 10, 16, 11, 16, 12, 16, + 15, 16, 14, 16, 16, 16, 16, 16, 12, 16, 12, 16, 14, 16, 13, 16, + 13, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 12, 16, 10, 16, 13, 16, 12, 16, 13, 16, 12, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 13, 16, 13, 16, 14, 16, + 13, 16, 14, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 2, 10, 5, 11, 6, 11, 9, 11, + 7, 12, 9, 13, 9, 13, 11, 13, 14, 16, 16, 16, 16, 16, 16, 16, + 4, 12, 6, 12, 8, 13, 10, 13, 8, 13, 9, 13, 11, 16, 12, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 8, 16, 12, 16, 12, 16, + 12, 16, 11, 16, 13, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 5, 12, 8, 13, 7, 13, 10, 13, 8, 14, 10, 14, 10, 14, 12, 14, + 16, 16, 16, 16, 16, 16, 16, 16, 7, 14, 9, 16, 10, 16, 11, 14, + 8, 14, 10, 16, 11, 16, 12, 16, 13, 16, 14, 16, 16, 16, 16, 16, + 11, 16, 11, 16, 13, 16, 13, 16, 12, 16, 12, 16, 14, 16, 14, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 12, 16, 10, 16, 12, 16, + 12, 16, 13, 16, 12, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 13, 16, 12, 16, 14, 16, 12, 16, 13, 16, 12, 16, 14, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 6, 16, 8, 16, 9, 16, 11, 13, 10, 16, 11, 16, 11, 16, 13, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 7, 16, 9, 16, 10, 16, 12, 16, + 11, 16, 11, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 9, 16, 12, 16, 13, 16, 13, 16, 12, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 7, 16, 10, 16, 9, 16, 12, 16, + 11, 16, 12, 16, 12, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 9, 16, 11, 16, 11, 16, 12, 16, 11, 16, 12, 16, 13, 16, 13, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 12, 16, 14, 16, 14, 16, + 12, 16, 12, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 12, 16, 10, 16, 13, 16, 13, 16, 14, 16, 13, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 13, 16, 12, 16, 14, 16, + 12, 16, 14, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 11, 16, 11, 16, 13, 16, + 12, 16, 13, 16, 13, 16, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 11, 16, 13, 16, 13, 16, 13, 16, 13, 16, 14, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 11, 16, 14, 16, 13, 16, + 14, 16, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 12, 16, 12, 16, 13, 16, 13, 16, 13, 16, 13, 16, 14, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 12, 16, 13, 16, 14, 16, + 13, 16, 13, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 12, 16, 14, 16, 14, 16, 14, 16, 14, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 13, 16, 11, 16, 14, 16, + 16, 16, 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 14, 16, 13, 16, 14, 16, 16, 16, 16, 16, 14, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + { + 0, 10, 4, 12, 5, 16, 11, 16, 6, 16, 10, 16, 11, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 3, 16, 7, 16, 10, 16, 16, 16, + 9, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 4, 16, 10, 16, 9, 16, 16, 16, + 9, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 9, 16, 12, 16, 16, 16, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 1, 16, 6, 16, 8, 16, 16, 16, + 8, 16, 11, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 5, 16, 8, 16, 11, 16, 16, 16, 10, 16, 12, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 11, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 5, 16, 11, 16, 9, 16, 16, 16, 10, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 9, 16, 12, 16, 16, 16, 16, 16, + 10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 5, 16, 9, 16, 11, 16, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 10, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 8, 16, 16, 16, 11, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 16, 16, 16, 16, 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 12, 16, 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 6, 16, 11, 16, 15, 16, 16, 16, + 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 9, 16, 10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 9, 16, 16, 16, 16, 16, + 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 10, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + }, +}; + +static const uint8_t rv34_table_inter_secondpat[NUM_INTER_TABLES][2][OTHERBLK_VLC_SIZE] = { + { + { + 0, 4, 8, 3, 6, 8, 6, 7, 8, 4, 6, 8, 6, 7, 8, 7, + 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 3, 6, 8, 4, 6, + 9, 7, 7, 8, 5, 7, 9, 6, 7, 9, 8, 8, 8, 7, 8, 8, + 8, 8, 8, 8, 8, 7, 6, 8, 9, 7, 8, 9, 7, 8, 9, 7, + 8, 9, 7, 8, 9, 8, 8, 9, 8, 8, 9, 8, 9, 9, 8, 8, + 8, 8, 9, 9, 8, 9, 9, 7, 8, 8, 8, 9, 9, 8, 9, 9, + 8, 8, 8, 7, 8, 8, 8, 8, 8, 7, 7, 6, + }, + { + 0, 4, 9, 3, 6, 9, 7, 8, 10, 3, 6, 9, 5, 7, 10, 9, + 9, 10, 7, 8, 10, 8, 9, 10, 10, 10, 10, 2, 6, 9, 4, 7, + 10, 8, 9, 10, 4, 7, 10, 6, 7, 10, 9, 9, 10, 7, 8, 10, + 8, 9, 10, 10, 10, 10, 6, 8, 10, 7, 9, 11, 9, 10, 11, 7, + 9, 11, 8, 9, 11, 10, 10, 11, 8, 9, 11, 9, 10, 11, 11, 11, + 10, 8, 10, 11, 9, 10, 11, 9, 10, 11, 8, 10, 11, 9, 10, 11, + 10, 10, 11, 8, 10, 11, 9, 10, 10, 10, 10, 9, + }, + }, + { + { + 0, 4, 8, 3, 6, 8, 6, 7, 9, 4, 6, 8, 5, 7, 8, 8, + 8, 9, 7, 7, 8, 8, 8, 8, 8, 9, 8, 3, 6, 8, 4, 6, + 9, 7, 7, 9, 5, 6, 9, 6, 7, 9, 8, 8, 9, 7, 8, 8, + 8, 8, 8, 8, 8, 8, 6, 8, 9, 7, 8, 10, 7, 8, 9, 7, + 8, 10, 7, 8, 10, 8, 8, 9, 7, 8, 9, 8, 9, 9, 9, 9, + 8, 7, 9, 10, 8, 9, 10, 8, 8, 8, 8, 9, 10, 8, 9, 9, + 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 7, 6, + }, + { + 0, 4, 9, 3, 6, 10, 8, 9, 11, 3, 5, 9, 5, 7, 10, 9, + 10, 11, 7, 8, 10, 9, 9, 11, 11, 11, 12, 2, 5, 10, 4, 7, + 10, 8, 9, 11, 4, 6, 10, 6, 7, 10, 9, 10, 11, 7, 9, 10, + 9, 9, 11, 11, 11, 11, 6, 8, 11, 7, 9, 11, 9, 10, 12, 7, + 9, 11, 8, 9, 12, 10, 10, 12, 8, 10, 11, 10, 10, 11, 12, 11, + 11, 8, 10, 12, 9, 11, 12, 10, 11, 12, 9, 10, 12, 10, 11, 12, + 11, 11, 12, 9, 10, 12, 10, 10, 11, 11, 11, 10, + }, + }, + { + { + 0, 4, 8, 3, 6, 9, 7, 8, 9, 4, 6, 8, 5, 7, 9, 8, + 9, 9, 7, 8, 9, 8, 8, 9, 9, 9, 9, 2, 6, 9, 4, 6, + 9, 7, 8, 10, 5, 7, 9, 6, 7, 9, 8, 8, 9, 7, 8, 9, + 8, 8, 9, 9, 9, 9, 6, 8, 10, 7, 8, 10, 8, 9, 10, 6, + 8, 10, 8, 8, 10, 9, 9, 10, 8, 9, 10, 9, 9, 10, 10, 10, + 9, 8, 9, 10, 8, 9, 10, 8, 9, 10, 8, 9, 10, 9, 9, 10, + 9, 9, 9, 8, 9, 9, 8, 9, 9, 9, 9, 8, + }, + { + 0, 4, 10, 3, 6, 10, 8, 10, 12, 2, 6, 10, 6, 8, 11, 10, + 11, 12, 7, 9, 11, 9, 10, 12, 12, 13, 13, 2, 6, 10, 4, 7, + 11, 9, 10, 13, 4, 7, 11, 7, 8, 11, 10, 11, 12, 8, 9, 12, + 10, 10, 12, 12, 12, 13, 6, 9, 12, 8, 10, 13, 10, 12, 14, 7, + 10, 13, 9, 10, 13, 11, 11, 13, 9, 11, 13, 11, 11, 13, 13, 13, + 13, 9, 11, 13, 10, 12, 14, 11, 12, 14, 9, 11, 14, 11, 12, 14, + 12, 12, 14, 9, 12, 13, 11, 12, 13, 13, 12, 12, + }, + }, + { + { + 0, 4, 9, 3, 6, 9, 7, 8, 10, 3, 6, 9, 6, 7, 9, 9, + 9, 10, 7, 8, 9, 8, 9, 10, 10, 10, 11, 2, 6, 9, 4, 7, + 10, 7, 9, 10, 4, 7, 10, 6, 7, 10, 9, 9, 10, 7, 8, 10, + 8, 9, 10, 10, 10, 10, 6, 8, 11, 7, 9, 11, 8, 10, 11, 6, + 9, 11, 8, 9, 11, 9, 9, 11, 8, 9, 11, 9, 10, 11, 11, 10, + 10, 8, 10, 11, 9, 10, 11, 9, 10, 11, 8, 10, 11, 9, 10, 11, + 10, 10, 11, 8, 10, 11, 9, 10, 11, 10, 10, 10, + }, + { + 0, 4, 12, 3, 7, 12, 10, 11, 14, 3, 6, 12, 7, 9, 13, 12, + 13, 14, 8, 11, 13, 11, 12, 14, 14, 14, 14, 1, 7, 12, 5, 8, + 13, 10, 12, 14, 4, 8, 13, 8, 9, 13, 12, 13, 14, 9, 11, 14, + 11, 12, 14, 14, 14, 14, 7, 10, 14, 9, 11, 14, 11, 13, 16, 8, + 11, 14, 10, 12, 14, 13, 13, 16, 10, 12, 15, 12, 13, 15, 15, 15, + 15, 10, 13, 15, 12, 13, 14, 13, 15, 15, 10, 13, 15, 12, 13, 15, + 13, 14, 15, 10, 13, 14, 12, 13, 14, 14, 14, 14, + }, + }, + { + { + 0, 4, 9, 3, 6, 10, 7, 9, 11, 3, 5, 9, 5, 7, 10, 9, + 10, 12, 7, 8, 10, 9, 10, 11, 11, 12, 12, 2, 6, 10, 4, 7, + 10, 7, 9, 12, 4, 7, 10, 6, 7, 11, 9, 10, 12, 7, 9, 11, + 9, 9, 11, 11, 11, 12, 5, 8, 11, 7, 9, 12, 9, 10, 13, 6, + 9, 12, 8, 9, 12, 10, 10, 12, 8, 10, 12, 10, 10, 12, 12, 12, + 12, 8, 10, 12, 9, 11, 13, 10, 11, 13, 9, 11, 13, 10, 11, 13, + 11, 11, 13, 9, 11, 12, 10, 11, 12, 11, 11, 12, + }, + { + 0, 4, 12, 3, 7, 13, 10, 12, 15, 3, 7, 13, 7, 9, 14, 12, + 12, 13, 8, 11, 14, 11, 13, 15, 15, 14, 14, 1, 6, 13, 5, 8, + 13, 10, 13, 15, 4, 8, 13, 8, 9, 14, 13, 13, 15, 8, 11, 14, + 12, 12, 15, 15, 14, 14, 7, 10, 13, 9, 11, 13, 12, 14, 16, 8, + 11, 14, 10, 12, 15, 13, 13, 16, 10, 12, 15, 12, 13, 15, 15, 14, + 15, 11, 12, 14, 12, 14, 14, 13, 15, 15, 10, 12, 14, 12, 13, 15, + 14, 15, 15, 10, 13, 13, 12, 13, 15, 14, 14, 15, + }, + }, + { + { + 0, 5, 10, 3, 7, 11, 9, 11, 14, 3, 7, 11, 7, 8, 12, 11, + 12, 14, 7, 9, 12, 10, 11, 14, 13, 14, 16, 1, 7, 11, 5, 8, + 12, 9, 11, 15, 4, 8, 12, 7, 9, 13, 11, 12, 15, 8, 10, 13, + 10, 11, 14, 14, 14, 16, 6, 9, 13, 8, 11, 14, 10, 13, 16, 7, + 10, 14, 9, 11, 15, 12, 13, 16, 9, 11, 15, 12, 12, 15, 14, 14, + 16, 10, 12, 14, 11, 13, 15, 12, 14, 16, 10, 12, 15, 11, 13, 16, + 13, 14, 16, 10, 13, 16, 12, 13, 15, 14, 15, 16, + }, + { + 0, 5, 16, 3, 8, 14, 11, 13, 14, 2, 8, 14, 8, 10, 16, 13, + 13, 14, 9, 13, 16, 12, 13, 16, 16, 14, 16, 1, 7, 14, 6, 10, + 14, 12, 16, 16, 5, 9, 14, 9, 11, 16, 15, 16, 16, 10, 12, 16, + 13, 13, 16, 16, 14, 16, 8, 11, 14, 11, 13, 14, 14, 14, 16, 8, + 12, 14, 11, 13, 16, 16, 16, 16, 10, 12, 15, 13, 14, 16, 16, 16, + 16, 11, 14, 14, 14, 15, 16, 16, 15, 16, 10, 13, 16, 13, 14, 14, + 16, 16, 16, 10, 13, 16, 13, 14, 16, 16, 16, 16, + }, + }, + { + { + 0, 5, 11, 3, 7, 13, 9, 12, 16, 3, 7, 12, 6, 9, 14, 11, + 13, 16, 7, 10, 16, 11, 12, 16, 16, 16, 16, 1, 6, 12, 5, 9, + 16, 9, 13, 16, 4, 8, 16, 7, 10, 16, 12, 15, 16, 7, 11, 16, + 11, 12, 16, 16, 16, 16, 6, 10, 15, 8, 11, 16, 11, 14, 16, 7, + 11, 16, 10, 12, 16, 13, 16, 16, 9, 13, 16, 13, 14, 16, 16, 16, + 16, 10, 12, 16, 12, 16, 16, 16, 16, 16, 11, 13, 16, 13, 16, 16, + 16, 16, 16, 12, 16, 16, 16, 16, 16, 16, 16, 16, + }, + { + 0, 5, 16, 3, 8, 16, 12, 12, 16, 2, 8, 16, 8, 10, 16, 13, + 13, 16, 9, 13, 16, 12, 13, 16, 16, 16, 16, 1, 8, 16, 6, 10, + 16, 12, 16, 16, 5, 9, 16, 9, 11, 16, 13, 16, 16, 9, 12, 14, + 12, 12, 16, 16, 16, 16, 8, 11, 13, 11, 12, 16, 14, 16, 16, 8, + 12, 16, 11, 13, 16, 16, 15, 16, 9, 13, 14, 12, 13, 16, 16, 16, + 16, 10, 12, 13, 14, 13, 16, 16, 16, 16, 9, 13, 16, 13, 12, 16, + 16, 16, 16, 10, 12, 16, 14, 15, 16, 16, 16, 16, + }, + }, +}; + +static const uint8_t rv34_table_inter_thirdpat[NUM_INTER_TABLES][2][OTHERBLK_VLC_SIZE] = { + { + { + 0, 5, 8, 3, 6, 9, 6, 7, 9, 4, 6, 9, 6, 7, 9, 8, + 8, 9, 7, 8, 9, 8, 9, 9, 9, 9, 9, 2, 6, 9, 4, 7, + 9, 7, 8, 9, 5, 7, 9, 6, 7, 9, 8, 8, 9, 7, 8, 9, + 8, 9, 9, 9, 9, 8, 5, 8, 10, 6, 8, 10, 8, 9, 9, 7, + 8, 10, 7, 9, 10, 8, 9, 9, 8, 9, 10, 9, 9, 10, 9, 9, + 9, 7, 9, 10, 8, 9, 10, 8, 8, 9, 8, 9, 10, 8, 9, 10, + 8, 8, 9, 8, 9, 9, 8, 9, 9, 8, 8, 7, + }, + { + 0, 4, 9, 2, 6, 10, 7, 8, 10, 3, 6, 10, 6, 7, 10, 9, + 9, 10, 8, 9, 11, 9, 10, 11, 10, 11, 11, 2, 6, 10, 4, 7, + 10, 8, 9, 10, 5, 7, 10, 7, 8, 10, 9, 9, 10, 9, 10, 11, + 10, 10, 11, 11, 11, 11, 6, 9, 11, 7, 9, 11, 9, 10, 12, 8, + 9, 11, 8, 10, 11, 10, 10, 11, 10, 11, 12, 11, 11, 12, 11, 11, + 11, 9, 11, 12, 10, 11, 12, 10, 11, 12, 10, 11, 12, 10, 11, 12, + 11, 11, 12, 11, 12, 12, 11, 12, 12, 12, 11, 11, + }, + }, + { + { + 0, 4, 9, 3, 6, 9, 6, 8, 9, 4, 6, 9, 5, 7, 9, 8, + 8, 9, 7, 8, 10, 8, 9, 10, 9, 9, 9, 2, 6, 9, 4, 7, + 9, 7, 8, 9, 5, 7, 9, 6, 7, 10, 8, 9, 9, 7, 9, 10, + 8, 9, 10, 9, 9, 9, 5, 8, 10, 6, 8, 10, 8, 9, 10, 7, + 8, 10, 7, 9, 11, 9, 9, 10, 8, 9, 10, 9, 10, 10, 10, 10, + 9, 7, 9, 10, 8, 9, 11, 8, 9, 10, 8, 9, 11, 8, 9, 11, + 9, 9, 10, 9, 9, 10, 9, 9, 10, 9, 9, 8, + }, + { + 0, 4, 9, 2, 5, 10, 7, 8, 11, 3, 6, 10, 6, 7, 10, 9, + 10, 11, 8, 9, 11, 9, 10, 11, 11, 11, 12, 2, 6, 10, 4, 7, + 10, 8, 9, 11, 5, 7, 10, 6, 8, 10, 9, 10, 11, 9, 10, 12, + 10, 10, 12, 11, 12, 12, 6, 9, 11, 8, 9, 12, 9, 11, 13, 8, + 10, 12, 9, 10, 12, 11, 11, 12, 10, 12, 13, 11, 12, 13, 13, 12, + 13, 10, 11, 13, 10, 12, 13, 11, 12, 13, 11, 12, 13, 11, 12, 13, + 12, 12, 13, 12, 13, 14, 13, 13, 14, 13, 13, 13, + }, + }, + { + { + 0, 4, 9, 3, 6, 9, 7, 8, 10, 3, 6, 9, 5, 7, 10, 8, + 9, 10, 7, 9, 10, 8, 9, 10, 10, 10, 10, 2, 6, 9, 4, 7, + 10, 7, 9, 10, 4, 7, 10, 6, 8, 10, 8, 9, 10, 8, 9, 10, + 9, 9, 10, 10, 10, 10, 5, 8, 11, 7, 9, 11, 8, 10, 11, 7, + 9, 11, 8, 9, 11, 9, 10, 11, 9, 10, 11, 10, 10, 11, 11, 11, + 11, 8, 10, 11, 9, 10, 11, 9, 10, 11, 9, 10, 12, 9, 10, 12, + 10, 11, 11, 9, 10, 11, 10, 11, 11, 10, 10, 10, + }, + { + 0, 4, 10, 3, 6, 11, 8, 10, 12, 3, 6, 11, 6, 8, 11, 10, + 11, 13, 9, 10, 13, 11, 12, 14, 13, 13, 14, 1, 6, 10, 5, 8, + 12, 9, 10, 13, 5, 8, 11, 7, 9, 12, 11, 11, 13, 10, 12, 13, + 11, 12, 14, 14, 13, 15, 7, 10, 12, 9, 11, 14, 11, 12, 15, 9, + 11, 13, 10, 11, 14, 12, 12, 14, 12, 14, 16, 13, 13, 16, 14, 14, + 16, 12, 13, 15, 12, 14, 15, 13, 14, 16, 13, 14, 16, 14, 14, 16, + 14, 15, 16, 14, 16, 16, 15, 16, 16, 15, 15, 16, + }, + }, + { + { + 0, 4, 9, 2, 6, 9, 7, 9, 11, 3, 6, 10, 6, 7, 10, 9, + 10, 11, 7, 9, 10, 9, 10, 11, 11, 11, 12, 2, 6, 10, 4, 7, + 10, 8, 9, 11, 5, 7, 10, 7, 8, 10, 9, 10, 11, 8, 9, 11, + 9, 10, 11, 11, 12, 11, 6, 9, 11, 7, 10, 12, 9, 11, 12, 7, + 10, 12, 9, 10, 12, 11, 11, 12, 9, 11, 12, 10, 11, 12, 12, 12, + 12, 9, 11, 12, 9, 11, 13, 11, 12, 13, 9, 11, 13, 10, 12, 13, + 11, 12, 13, 11, 12, 13, 11, 12, 13, 12, 13, 12, + }, + { + 0, 4, 11, 2, 6, 12, 9, 11, 16, 4, 7, 12, 7, 9, 15, 11, + 12, 16, 10, 11, 16, 11, 13, 16, 16, 16, 16, 1, 6, 11, 5, 8, + 16, 9, 12, 16, 6, 9, 15, 8, 10, 16, 12, 13, 16, 12, 14, 16, + 12, 16, 16, 16, 16, 16, 8, 11, 14, 10, 12, 16, 12, 16, 16, 10, + 13, 16, 12, 16, 16, 13, 14, 16, 14, 16, 16, 16, 16, 16, 16, 16, + 16, 13, 13, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + }, + { + { + 0, 5, 9, 3, 6, 10, 8, 10, 12, 3, 6, 10, 6, 8, 10, 10, + 11, 12, 8, 9, 11, 10, 10, 12, 13, 13, 13, 1, 6, 10, 5, 8, + 11, 9, 11, 13, 5, 8, 11, 7, 9, 11, 11, 11, 13, 8, 9, 11, + 10, 10, 12, 13, 13, 14, 6, 9, 12, 8, 11, 13, 11, 13, 15, 8, + 10, 13, 10, 11, 13, 12, 13, 15, 10, 12, 13, 12, 12, 13, 14, 14, + 14, 9, 12, 14, 11, 13, 15, 13, 15, 16, 11, 13, 15, 12, 14, 15, + 14, 15, 16, 13, 14, 15, 14, 14, 15, 15, 16, 16, + }, + { + 0, 4, 16, 2, 7, 16, 10, 13, 16, 3, 8, 16, 7, 10, 16, 16, + 16, 16, 12, 16, 16, 15, 16, 16, 16, 16, 16, 1, 7, 16, 6, 9, + 16, 10, 16, 16, 7, 12, 16, 9, 13, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 9, 16, 16, 11, 13, 16, 16, 16, 16, 12, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 14, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + }, + { + { + 0, 4, 9, 3, 6, 11, 9, 12, 16, 3, 6, 10, 6, 8, 11, 12, + 13, 16, 8, 9, 12, 10, 11, 13, 16, 16, 16, 1, 6, 10, 5, 8, + 12, 10, 13, 16, 5, 8, 11, 8, 9, 13, 13, 14, 16, 9, 10, 14, + 11, 12, 15, 16, 16, 16, 6, 10, 13, 9, 12, 16, 14, 16, 16, 9, + 12, 14, 11, 13, 16, 16, 16, 16, 12, 14, 16, 14, 16, 16, 16, 16, + 16, 11, 16, 16, 13, 16, 16, 16, 16, 16, 12, 16, 16, 13, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + { + 0, 4, 16, 2, 8, 16, 10, 16, 16, 3, 9, 16, 8, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 1, 7, 16, 5, 10, + 16, 16, 16, 16, 7, 16, 16, 11, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 10, 15, 16, 10, 16, 16, 16, 16, 16, 14, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + }, + { + { + 0, 3, 9, 3, 7, 11, 11, 15, 16, 3, 6, 11, 7, 9, 12, 16, + 16, 16, 8, 10, 16, 11, 16, 16, 16, 16, 16, 1, 6, 11, 6, 9, + 15, 16, 16, 16, 5, 8, 16, 9, 11, 16, 16, 16, 16, 10, 16, 16, + 16, 16, 16, 16, 16, 16, 7, 11, 16, 11, 16, 16, 16, 16, 16, 11, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + { + 0, 4, 16, 2, 8, 16, 16, 16, 16, 3, 12, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 1, 7, 16, 5, 12, + 16, 16, 16, 16, 6, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 9, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + }, + }, +}; + + +static const uint8_t rv34_inter_coeff[NUM_INTER_TABLES][COEFF_VLC_SIZE] = { +{ + 1, 2, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 8, 9, 9, 10, + 10, 10, 10, 11, 11, 11, 11, 12, 11, 11, 11, 13, 14, 15, 16, 16, +}, +{ + 1, 2, 3, 5, 5, 6, 6, 7, 7, 8, 9, 9, 9, 10, 10, 10, + 11, 11, 12, 12, 12, 12, 13, 13, 12, 12, 13, 14, 16, 16, 16, 16, +}, +{ + 1, 2, 3, 4, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12, + 12, 12, 13, 13, 13, 14, 14, 15, 14, 14, 16, 16, 16, 16, 16, 16, +}, +{ + 1, 2, 3, 4, 5, 6, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, + 13, 13, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, +}, +{ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, +}, +{ + 1, 2, 3, 4, 5, 6, 7, 8, 10, 10, 11, 11, 13, 12, 12, 13, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, +}, +{ + 1, 2, 3, 4, 5, 6, 7, 8, 10, 10, 10, 11, 14, 13, 15, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 15, 16, 16, 16, +} +}; + +#endif /* FFMPEG_RV34VLC_H */ diff --git a/contrib/ffmpeg/libavcodec/rv40.c b/contrib/ffmpeg/libavcodec/rv40.c new file mode 100644 index 000000000..f0e0d915f --- /dev/null +++ b/contrib/ffmpeg/libavcodec/rv40.c @@ -0,0 +1,279 @@ +/* + * RV40 decoder + * Copyright (c) 2007 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file rv40.c + * RV40 decoder + */ + +#include "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" +#include "golomb.h" + +#include "rv34.h" +#include "rv40vlc2.h" +#include "rv40data.h" + +static VLC aic_top_vlc; +static VLC aic_mode1_vlc[AIC_MODE1_NUM], aic_mode2_vlc[AIC_MODE2_NUM]; +static VLC ptype_vlc[NUM_PTYPE_VLCS], btype_vlc[NUM_BTYPE_VLCS]; + +/** + * Initialize all tables. + */ +static void rv40_init_tables() +{ + int i; + + init_vlc(&aic_top_vlc, AIC_TOP_BITS, AIC_TOP_SIZE, + rv40_aic_top_vlc_bits, 1, 1, + rv40_aic_top_vlc_codes, 1, 1, INIT_VLC_USE_STATIC); + for(i = 0; i < AIC_MODE1_NUM; i++){ + // Every tenth VLC table is empty + if((i % 10) == 9) continue; + init_vlc(&aic_mode1_vlc[i], AIC_MODE1_BITS, AIC_MODE1_SIZE, + aic_mode1_vlc_bits[i], 1, 1, + aic_mode1_vlc_codes[i], 1, 1, INIT_VLC_USE_STATIC); + } + for(i = 0; i < AIC_MODE2_NUM; i++){ + init_vlc(&aic_mode2_vlc[i], AIC_MODE2_BITS, AIC_MODE2_SIZE, + aic_mode2_vlc_bits[i], 1, 1, + aic_mode2_vlc_codes[i], 2, 2, INIT_VLC_USE_STATIC); + } + for(i = 0; i < NUM_PTYPE_VLCS; i++) + init_vlc_sparse(&ptype_vlc[i], PTYPE_VLC_BITS, PTYPE_VLC_SIZE, + ptype_vlc_bits[i], 1, 1, + ptype_vlc_codes[i], 1, 1, + ptype_vlc_syms, 1, 1, INIT_VLC_USE_STATIC); + for(i = 0; i < NUM_BTYPE_VLCS; i++) + init_vlc_sparse(&btype_vlc[i], BTYPE_VLC_BITS, BTYPE_VLC_SIZE, + btype_vlc_bits[i], 1, 1, + btype_vlc_codes[i], 1, 1, + btype_vlc_syms, 1, 1, INIT_VLC_USE_STATIC); +} + +/** + * Get stored dimension from bitstream. + * + * If the width/height is the standard one then it's coded as a 3-bit index. + * Otherwise it is coded as escaped 8-bit portions. + */ +static int get_dimension(GetBitContext *gb, const int *dim) +{ + int t = get_bits(gb, 3); + int val = dim[t]; + if(val < 0) + val = dim[get_bits1(gb) - val]; + if(!val){ + do{ + t = get_bits(gb, 8); + val += t << 2; + }while(t == 0xFF); + } + return val; +} + +/** + * Get encoded picture size - usually this is called from rv40_parse_slice_header. + */ +static void rv40_parse_picture_size(GetBitContext *gb, int *w, int *h) +{ + *w = get_dimension(gb, rv40_standard_widths); + *h = get_dimension(gb, rv40_standard_heights); +} + +static int rv40_parse_slice_header(RV34DecContext *r, GetBitContext *gb, SliceInfo *si) +{ + int t, mb_bits; + int w = r->s.width, h = r->s.height; + int mb_size; + + memset(si, 0, sizeof(SliceInfo)); + if(get_bits1(gb)) + return -1; + si->type = get_bits(gb, 2); + if(si->type == 1) si->type = 0; + si->quant = get_bits(gb, 5); + if(get_bits(gb, 2)) + return -1; + si->vlc_set = get_bits(gb, 2); + skip_bits1(gb); + t = get_bits(gb, 13); /// ??? + if(!si->type || !get_bits1(gb)) + rv40_parse_picture_size(gb, &w, &h); + if(avcodec_check_dimensions(r->s.avctx, w, h) < 0) + return -1; + si->width = w; + si->height = h; + mb_size = ((w + 15) >> 4) * ((h + 15) >> 4); + mb_bits = ff_rv34_get_start_offset(gb, mb_size); + si->start = get_bits(gb, mb_bits); + + return 0; +} + +/** + * Decode 4x4 intra types array. + */ +static int rv40_decode_intra_types(RV34DecContext *r, GetBitContext *gb, int8_t *dst) +{ + MpegEncContext *s = &r->s; + int i, j, k, v; + int A, B, C; + int pattern; + int8_t *ptr; + + for(i = 0; i < 4; i++, dst += s->b4_stride){ + if(!i && s->first_slice_line){ + pattern = get_vlc2(gb, aic_top_vlc.table, AIC_TOP_BITS, 1); + dst[0] = (pattern >> 2) & 2; + dst[1] = (pattern >> 1) & 2; + dst[2] = pattern & 2; + dst[3] = (pattern << 1) & 2; + continue; + } + ptr = dst; + for(j = 0; j < 4; j++){ + /* Coefficients are read using VLC chosen by the prediction pattern + * The first one (used for retrieving a pair of coefficients) is + * constructed from the top, top right and left coefficients + * The second one (used for retrieving only one coefficient) is + * top + 10 * left. + */ + A = ptr[-s->b4_stride + 1]; // it won't be used for the last coefficient in a row + B = ptr[-s->b4_stride]; + C = ptr[-1]; + pattern = A + (B << 4) + (C << 8); + for(k = 0; k < MODE2_PATTERNS_NUM; k++) + if(pattern == rv40_aic_table_index[k]) + break; + if(j < 3 && k < MODE2_PATTERNS_NUM){ //pattern is found, decoding 2 coefficients + v = get_vlc2(gb, aic_mode2_vlc[k].table, AIC_MODE2_BITS, 2); + *ptr++ = v/9; + *ptr++ = v%9; + j++; + }else{ + if(B != -1 && C != -1) + v = get_vlc2(gb, aic_mode1_vlc[B + C*10].table, AIC_MODE1_BITS, 1); + else{ // tricky decoding + v = 0; + switch(C){ + case -1: // code 0 -> 1, 1 -> 0 + if(B < 2) + v = get_bits1(gb) ^ 1; + break; + case 0: + case 2: // code 0 -> 2, 1 -> 0 + v = (get_bits1(gb) ^ 1) << 1; + break; + } + } + *ptr++ = v; + } + } + } + return 0; +} + +/** + * Decode macroblock information. + */ +static int rv40_decode_mb_info(RV34DecContext *r) +{ + MpegEncContext *s = &r->s; + GetBitContext *gb = &s->gb; + int q, i; + int prev_type = 0; + int mb_pos = s->mb_x + s->mb_y * s->mb_stride; + int blocks[RV34_MB_TYPES] = {0}; + int count = 0; + + if(!r->s.mb_skip_run) + r->s.mb_skip_run = svq3_get_ue_golomb(gb) + 1; + + if(--r->s.mb_skip_run) + return RV34_MB_SKIP; + + if(r->avail_cache[5-1]) + blocks[r->mb_type[mb_pos - 1]]++; + if(r->avail_cache[5-4]){ + blocks[r->mb_type[mb_pos - s->mb_stride]]++; + if(r->avail_cache[5-2]) + blocks[r->mb_type[mb_pos - s->mb_stride + 1]]++; + if(r->avail_cache[5-5]) + blocks[r->mb_type[mb_pos - s->mb_stride - 1]]++; + } + + for(i = 0; i < RV34_MB_TYPES; i++){ + if(blocks[i] > count){ + count = blocks[i]; + prev_type = i; + } + } + if(s->pict_type == P_TYPE){ + prev_type = block_num_to_ptype_vlc_num[prev_type]; + q = get_vlc2(gb, ptype_vlc[prev_type].table, PTYPE_VLC_BITS, 1); + if(q < PBTYPE_ESCAPE) + return q; + q = get_vlc2(gb, ptype_vlc[prev_type].table, PTYPE_VLC_BITS, 1); + av_log(s->avctx, AV_LOG_ERROR, "Dquant for P-frame\n"); + }else{ + prev_type = block_num_to_btype_vlc_num[prev_type]; + q = get_vlc2(gb, btype_vlc[prev_type].table, BTYPE_VLC_BITS, 1); + if(q < PBTYPE_ESCAPE) + return q; + q = get_vlc2(gb, btype_vlc[prev_type].table, BTYPE_VLC_BITS, 1); + av_log(s->avctx, AV_LOG_ERROR, "Dquant for B-frame\n"); + } + return 0; +} + +/** + * Initialize decoder. + */ +static int rv40_decode_init(AVCodecContext *avctx) +{ + RV34DecContext *r = avctx->priv_data; + + r->rv30 = 0; + ff_rv34_decode_init(avctx); + if(!aic_top_vlc.bits) + rv40_init_tables(); + r->parse_slice_header = rv40_parse_slice_header; + r->decode_intra_types = rv40_decode_intra_types; + r->decode_mb_info = rv40_decode_mb_info; + r->luma_dc_quant_i = rv40_luma_dc_quant[0]; + r->luma_dc_quant_p = rv40_luma_dc_quant[1]; + return 0; +} + +AVCodec rv40_decoder = { + "rv40", + CODEC_TYPE_VIDEO, + CODEC_ID_RV40, + sizeof(RV34DecContext), + rv40_decode_init, + NULL, + ff_rv34_decode_end, + ff_rv34_decode_frame, + CODEC_CAP_DR1 | CODEC_CAP_DELAY, +}; diff --git a/contrib/ffmpeg/libavcodec/rv40data.h b/contrib/ffmpeg/libavcodec/rv40data.h new file mode 100644 index 000000000..17bcb04cf --- /dev/null +++ b/contrib/ffmpeg/libavcodec/rv40data.h @@ -0,0 +1,115 @@ +/* + * RealVideo 4 decoder + * copyright (c) 2007 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file rv40data.h + * miscellaneous RV40 tables + */ + +#ifndef FFMPEG_RV40DATA_H +#define FFMPEG_RV40DATA_H + +#include + +/** + * standard widths and heights coded in RV40 + */ +//@{ +static const int rv40_standard_widths[] = { 160, 172, 240, 320, 352, 640, 704, 0}; +static const int rv40_standard_heights[] = { 120, 132, 144, 240, 288, 480, -8, -10, 180, 360, 576, 0}; +//@} + +#define MODE2_PATTERNS_NUM 20 +/** + * intra types table + * + * These values are actually coded 3-tuples + * used for detecting standard block configurations. + */ +static const uint16_t rv40_aic_table_index[MODE2_PATTERNS_NUM] = { + 0x000, 0x100, 0x200, + 0x011, 0x111, 0x211, 0x511, 0x611, + 0x022, 0x122, 0x222, 0x722, + 0x272, 0x227, + 0x822, 0x282, 0x228, + 0x112, 0x116, 0x221 +}; + +/** + * luma quantizer values + * The second table is used for inter blocks. + */ +static const uint8_t rv40_luma_dc_quant[2][32] = { + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 17, 18, 18, 18, 19, 19, 19, 20, 20, 20, 22, 22, 22, 22 }, + { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 20, 21, 21, 22, 23, 23, 23, 24, 24, 24, 24 } +}; + +/** + * @begingroup loopfilter coefficients used by the RV40 loop filter + * @{ + */ +/** + * dither values for deblocking filter - left/top values + */ +static const uint8_t rv40_dither_l[16] = { + 0x40, 0x50, 0x20, 0x60, 0x30, 0x50, 0x40, 0x30, + 0x50, 0x40, 0x50, 0x30, 0x60, 0x20, 0x50, 0x40 +}; +/** + * dither values for deblocking filter - right/bottom values + */ +static const uint8_t rv40_dither_r[16] = { + 0x40, 0x30, 0x60, 0x20, 0x50, 0x30, 0x30, 0x40, + 0x40, 0x40, 0x50, 0x30, 0x20, 0x60, 0x30, 0x40 +}; + +/** alpha parameter for RV40 loop filter - almost the same as in JVT-A003r1 */ +static const uint8_t rv40_alpha_tab[32] = { + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 122, 96, 75, 59, 47, 37, + 29, 23, 18, 15, 13, 11, 10, 9, + 8, 7, 6, 5, 4, 3, 2, 1 +}; +/** beta parameter for RV40 loop filter - almost the same as in JVT-A003r1 */ +static const uint8_t rv40_beta_tab[32] = { + 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 6, 6, + 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 13, 14, 15, 16, 17 +}; +/** clip table for RV40 loop filter - the same as in JVT-A003r1 */ +static const uint8_t rv40_filter_clip_tbl[3][32] = { + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }, + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 5, 5 + }, + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 7, 8, 9 + } +}; +/** @} */ // end loopfilter group + +#endif /* FFMPEG_RV40DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/rv40vlc2.h b/contrib/ffmpeg/libavcodec/rv40vlc2.h new file mode 100644 index 000000000..f1664fcd6 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/rv40vlc2.h @@ -0,0 +1,706 @@ +/* + * RealVideo 4 decoder + * copyright (c) 2007 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file rv40vlc2.h + * RV40 VLC tables used for macroblock information decoding + */ + +#ifndef FFMPEG_RV40VLC2_H +#define FFMPEG_RV40VLC2_H + +#include + +/** + * codes used for the first four block types + */ +//@{ +#define AIC_TOP_BITS 8 +#define AIC_TOP_SIZE 16 +static const uint8_t rv40_aic_top_vlc_codes[AIC_TOP_SIZE] = { + 0x01, 0x05, 0x01, 0x00, 0x03, 0x3D, 0x1D, 0x02, + 0x04, 0x3C, 0x3F, 0x1C, 0x0D, 0x3E, 0x0C, 0x01 +}; + +static const uint8_t rv40_aic_top_vlc_bits[AIC_TOP_SIZE] = { + 1, 4, 5, 5, 5, 7, 6, 5, 4, 7, 7, 6, 5, 7, 5, 3 +}; +//@} + +/** + * codes used for determining a pair of block types + */ +//@{ +#define AIC_MODE2_NUM 20 +#define AIC_MODE2_SIZE 81 +#define AIC_MODE2_BITS 9 + +static const uint16_t aic_mode2_vlc_codes[AIC_MODE2_NUM][AIC_MODE2_SIZE] = { +{ 0x0001, 0x0001, 0x0005, 0x01F5, 0x0011, 0x0049, 0x0000, 0x0048, 0x004B, + 0x0035, 0x0003, 0x0034, 0x03C9, 0x01F4, 0x00C9, 0x004A, 0x0FD9, 0x03C8, + 0x0010, 0x0037, 0x0001, 0x00C8, 0x0075, 0x01F7, 0x00CB, 0x0074, 0x0002, + 0x01F6, 0x00CA, 0x01F1, 0x01F0, 0x1F81, 0x07F9, 0x1F80, 0x1F83, 0x07F8, + 0x0077, 0x00F5, 0x0036, 0x07FB, 0x0076, 0x1F82, 0x00F4, 0x00F7, 0x07FA, + 0x0071, 0x00F6, 0x03CB, 0x03CA, 0x0FD8, 0x00F1, 0x03F5, 0x1F8D, 0x07E5, + 0x0013, 0x0031, 0x00F0, 0x0FDB, 0x00F3, 0x07E4, 0x0030, 0x01F3, 0x07E7, + 0x03F4, 0x07E6, 0x0070, 0x3F19, 0x01F2, 0x3F18, 0x0FDA, 0x0033, 0x07E1, + 0x01FD, 0x01FC, 0x0073, 0x01FF, 0x0FC5, 0x0FC4, 0x0FC7, 0x03F7, 0x0072, }, +{ 0x0005, 0x0005, 0x0005, 0x0079, 0x0005, 0x000D, 0x001D, 0x0078, 0x0069, + 0x0004, 0x0001, 0x0007, 0x0068, 0x001C, 0x001F, 0x0004, 0x006B, 0x000C, + 0x0004, 0x001E, 0x0006, 0x006A, 0x0015, 0x000F, 0x0014, 0x0017, 0x0007, + 0x0016, 0x000E, 0x0011, 0x0009, 0x00D1, 0x00D0, 0x0181, 0x00D3, 0x007B, + 0x0010, 0x0013, 0x0004, 0x00D2, 0x0007, 0x0319, 0x0008, 0x007A, 0x00DD, + 0x0019, 0x0006, 0x000B, 0x0065, 0x00DC, 0x0012, 0x0064, 0x0180, 0x00DF, + 0x0006, 0x0018, 0x0001, 0x00DE, 0x001D, 0x00D9, 0x001B, 0x0067, 0x000A, + 0x00D8, 0x00DB, 0x001C, 0x0318, 0x00DA, 0x0635, 0x0183, 0x0000, 0x00C5, + 0x0066, 0x0061, 0x0035, 0x00C4, 0x0182, 0x0634, 0x031B, 0x00C7, 0x001F, }, +{ 0x0005, 0x0001, 0x001D, 0x01C1, 0x0035, 0x00F1, 0x006D, 0x00F0, 0x0049, + 0x0000, 0x0004, 0x0003, 0x00F3, 0x0048, 0x0034, 0x006C, 0x01C0, 0x01C3, + 0x0007, 0x0006, 0x0001, 0x006F, 0x0002, 0x004B, 0x006E, 0x001C, 0x0005, + 0x0069, 0x0068, 0x006B, 0x0037, 0x01C2, 0x00F2, 0x0395, 0x01CD, 0x00FD, + 0x006A, 0x0036, 0x0015, 0x01CC, 0x0014, 0x0394, 0x004A, 0x00FC, 0x00FF, + 0x0017, 0x0031, 0x00FE, 0x01CF, 0x0397, 0x00F9, 0x01CE, 0x0725, 0x0396, + 0x0016, 0x0030, 0x0075, 0x0724, 0x00F8, 0x0727, 0x0033, 0x0391, 0x0390, + 0x0011, 0x0032, 0x001F, 0x00FB, 0x0074, 0x0726, 0x00FA, 0x001E, 0x0077, + 0x0019, 0x0018, 0x0004, 0x0010, 0x003D, 0x0076, 0x0071, 0x0013, 0x0001, }, +{ 0x000D, 0x0019, 0x0011, 0x0015, 0x0061, 0x0019, 0x0014, 0x01AD, 0x0060, + 0x0018, 0x0001, 0x0005, 0x001B, 0x0010, 0x0019, 0x0005, 0x0017, 0x0018, + 0x0016, 0x0004, 0x0004, 0x0013, 0x000C, 0x0012, 0x001A, 0x0018, 0x0005, + 0x000F, 0x001B, 0x0004, 0x001D, 0x0011, 0x001C, 0x0010, 0x000E, 0x001B, + 0x0013, 0x001F, 0x001A, 0x0029, 0x0005, 0x0063, 0x001E, 0x0009, 0x0062, + 0x0008, 0x0007, 0x0007, 0x0019, 0x0004, 0x001A, 0x0018, 0x006D, 0x0007, + 0x001B, 0x0007, 0x001A, 0x006C, 0x0006, 0x0012, 0x0005, 0x006F, 0x000B, + 0x006E, 0x0069, 0x001D, 0x0359, 0x0028, 0x002B, 0x002A, 0x001C, 0x00D5, + 0x0358, 0x001F, 0x0001, 0x001E, 0x0068, 0x00D4, 0x00D7, 0x0019, 0x0000, }, +{ 0x00B9, 0x0061, 0x0060, 0x00B8, 0x02B5, 0x01AD, 0x00BB, 0x0AF5, 0x0151, + 0x0001, 0x0001, 0x0005, 0x0000, 0x0003, 0x0005, 0x0004, 0x0063, 0x0025, + 0x00BA, 0x0004, 0x0007, 0x0062, 0x00A5, 0x0024, 0x006D, 0x0002, 0x006C, + 0x02B4, 0x000D, 0x006F, 0x0027, 0x00A4, 0x0026, 0x01AC, 0x0150, 0x01AF, + 0x01AE, 0x0021, 0x006E, 0x02B7, 0x0020, 0x0153, 0x0023, 0x00A7, 0x0152, + 0x00A6, 0x0006, 0x000C, 0x0022, 0x01A9, 0x0019, 0x002D, 0x02B6, 0x01A8, + 0x000F, 0x0007, 0x000E, 0x00A1, 0x0069, 0x002C, 0x0001, 0x01AB, 0x00A0, + 0x02B1, 0x00A3, 0x002F, 0x0AF4, 0x02B0, 0x0AF7, 0x02B3, 0x0068, 0x015D, + 0x0AF6, 0x01AA, 0x0055, 0x015C, 0x02B2, 0x0579, 0x0578, 0x015F, 0x00A2, }, +{ 0x0905, 0x013D, 0x013C, 0x0904, 0x121D, 0x049D, 0x049C, 0x243D, 0x0907, + 0x00ED, 0x0001, 0x0015, 0x0041, 0x013F, 0x0031, 0x0014, 0x025D, 0x025C, + 0x013E, 0x000D, 0x0000, 0x0040, 0x0139, 0x0043, 0x0030, 0x0017, 0x0033, + 0x0906, 0x0032, 0x0042, 0x00EC, 0x025F, 0x00EF, 0x025E, 0x049F, 0x0138, + 0x0901, 0x013B, 0x0259, 0x121C, 0x049E, 0x0900, 0x0258, 0x243C, 0x121F, + 0x0903, 0x003D, 0x00EE, 0x025B, 0x025A, 0x004D, 0x013A, 0x0902, 0x0245, + 0x00E9, 0x0016, 0x00E8, 0x0499, 0x0125, 0x0244, 0x004C, 0x0498, 0x090D, + 0x00EB, 0x003C, 0x0011, 0x049B, 0x049A, 0x0485, 0x00EA, 0x003F, 0x0124, + 0x090C, 0x003E, 0x0039, 0x0095, 0x0247, 0x0246, 0x0484, 0x0094, 0x0038, }, +{ 0x0F09, 0x00CD, 0x01FD, 0x0791, 0x1E6D, 0x0790, 0x03D9, 0x3CD1, 0x3CD0, + 0x0075, 0x0001, 0x0001, 0x0035, 0x00CC, 0x0011, 0x0000, 0x03D8, 0x01FC, + 0x03DB, 0x0010, 0x0003, 0x00CF, 0x03DA, 0x00CE, 0x0074, 0x0034, 0x0077, + 0x0793, 0x0013, 0x0076, 0x0071, 0x03C5, 0x0070, 0x01FF, 0x0792, 0x01FE, + 0x01F9, 0x0037, 0x00C9, 0x0F08, 0x01F8, 0x03C4, 0x00C8, 0x0F0B, 0x079D, + 0x03C7, 0x0001, 0x0012, 0x0073, 0x00CB, 0x0005, 0x0036, 0x03C6, 0x0072, + 0x007D, 0x0002, 0x00CA, 0x079C, 0x01FB, 0x00F5, 0x0031, 0x079F, 0x0F0A, + 0x0F35, 0x079E, 0x01FA, 0x1E6C, 0x1E6F, 0x3CD3, 0x0799, 0x03C1, 0x1E6E, + 0x3CD2, 0x0030, 0x00F4, 0x007C, 0x03C0, 0x03C3, 0x0798, 0x01E5, 0x00F7, }, +{ 0x01A5, 0x0001, 0x001D, 0x0021, 0x00A1, 0x000D, 0x0061, 0x06B9, 0x00A0, + 0x0060, 0x0001, 0x0005, 0x000C, 0x0020, 0x001C, 0x0004, 0x01A4, 0x01A7, + 0x00A3, 0x001F, 0x001E, 0x0023, 0x0022, 0x002D, 0x002C, 0x0063, 0x0062, + 0x1A81, 0x01A6, 0x01A1, 0x06B8, 0x06BB, 0x00A2, 0x06BA, 0x0D59, 0x06A5, + 0x01A0, 0x000F, 0x006D, 0x06A4, 0x002F, 0x00AD, 0x006C, 0x06A7, 0x00AC, + 0x0D58, 0x000E, 0x01A3, 0x00AF, 0x00AE, 0x006F, 0x01A2, 0x0D5B, 0x00A9, + 0x0019, 0x0001, 0x0009, 0x00A8, 0x006E, 0x002E, 0x0000, 0x01AD, 0x00AB, + 0x00AA, 0x0355, 0x0029, 0x1A80, 0x1A83, 0x1A82, 0x0354, 0x01AC, 0x0D5A, + 0x1A8D, 0x01AF, 0x0357, 0x0D45, 0x0D44, 0x0D47, 0x1A8C, 0x06A6, 0x06A1, }, +{ 0x0001, 0x0011, 0x0005, 0x0775, 0x00F9, 0x00F8, 0x0031, 0x0030, 0x0049, + 0x00FB, 0x0010, 0x0033, 0x0EC9, 0x038D, 0x038C, 0x00FA, 0x038F, 0x0774, + 0x0048, 0x0032, 0x0000, 0x01D5, 0x00E5, 0x038E, 0x00E4, 0x0013, 0x000D, + 0x0389, 0x0777, 0x0388, 0x038B, 0x1DF9, 0x0EC8, 0x3BC9, 0x1DF8, 0x038A, + 0x03B5, 0x0776, 0x00E7, 0x3BC8, 0x01D4, 0x3BCB, 0x0ECB, 0x0771, 0x0ECA, + 0x01D7, 0x03B4, 0x01D6, 0x1DFB, 0x0EF5, 0x0770, 0x0EF4, 0x3BCA, 0x0773, + 0x00E6, 0x03B7, 0x004B, 0x1DFA, 0x03B6, 0x0EF7, 0x00E1, 0x0EF6, 0x0EF1, + 0x03B1, 0x01D1, 0x003D, 0x0EF0, 0x0772, 0x077D, 0x077C, 0x003C, 0x01D0, + 0x03B0, 0x01D3, 0x003F, 0x03B3, 0x01D2, 0x0EF3, 0x077F, 0x00E0, 0x004A, }, +{ 0x0015, 0x0049, 0x0014, 0x07D1, 0x03FD, 0x03FC, 0x01C1, 0x01C0, 0x00F1, + 0x0017, 0x0001, 0x0001, 0x01C3, 0x0048, 0x004B, 0x0016, 0x0031, 0x01C2, + 0x004A, 0x0011, 0x0000, 0x01CD, 0x00F0, 0x01CC, 0x0075, 0x0010, 0x000D, + 0x03FF, 0x01CF, 0x01CE, 0x07D0, 0x0F81, 0x07D3, 0x1F1D, 0x0F80, 0x07D2, + 0x01C9, 0x03FE, 0x0074, 0x07DD, 0x00F3, 0x1F1C, 0x07DC, 0x03F9, 0x07DF, + 0x00F2, 0x00FD, 0x0077, 0x07DE, 0x07D9, 0x01C8, 0x07D8, 0x0F83, 0x03F8, + 0x0030, 0x0076, 0x0013, 0x0F82, 0x00FC, 0x03FB, 0x0033, 0x03FA, 0x03E5, + 0x03E4, 0x01CB, 0x0032, 0x1F1F, 0x03E7, 0x07DB, 0x07DA, 0x003D, 0x01CA, + 0x07C5, 0x03E6, 0x0071, 0x0F8D, 0x07C4, 0x1F1E, 0x0F8C, 0x03E1, 0x01F5, }, +{ 0x0019, 0x0065, 0x0018, 0x0351, 0x0350, 0x0353, 0x0021, 0x0020, 0x0064, + 0x001D, 0x0005, 0x0005, 0x01A5, 0x0023, 0x0067, 0x0005, 0x0066, 0x0022, + 0x001B, 0x0004, 0x0001, 0x0004, 0x001C, 0x0061, 0x001A, 0x0005, 0x0004, + 0x0007, 0x002D, 0x0006, 0x002C, 0x01A4, 0x002F, 0x0352, 0x035D, 0x0060, + 0x0001, 0x002E, 0x001F, 0x035C, 0x0000, 0x06B1, 0x01A7, 0x0029, 0x01A6, + 0x0028, 0x0063, 0x0062, 0x035F, 0x01A1, 0x002B, 0x06B0, 0x06B3, 0x01A0, + 0x0003, 0x006D, 0x001E, 0x035E, 0x006C, 0x06B2, 0x0002, 0x01A3, 0x01A2, + 0x000D, 0x0005, 0x0007, 0x01AD, 0x006F, 0x002A, 0x006E, 0x0004, 0x0004, + 0x000C, 0x0007, 0x0006, 0x000F, 0x000E, 0x00D5, 0x0009, 0x0006, 0x0007, }, +{ 0x0065, 0x0181, 0x0064, 0x36C9, 0x06D5, 0x0DB5, 0x0379, 0x0180, 0x0183, + 0x00D5, 0x001D, 0x001C, 0x0DB4, 0x0182, 0x0378, 0x00D4, 0x00D7, 0x06D4, + 0x0067, 0x001F, 0x0001, 0x00D6, 0x00D1, 0x018D, 0x0066, 0x0001, 0x0000, + 0x037B, 0x06D7, 0x037A, 0x0DB7, 0x36C8, 0x06D6, 0x0DB6, 0x1B79, 0x0DB1, + 0x018C, 0x0365, 0x00D0, 0x1B78, 0x00D3, 0x1B7B, 0x0364, 0x06D1, 0x06D0, + 0x018F, 0x018E, 0x00D2, 0x36CB, 0x0367, 0x0366, 0x06D3, 0x0DB0, 0x06D2, + 0x0361, 0x06DD, 0x0189, 0x36CA, 0x0360, 0x36F5, 0x0188, 0x0DB3, 0x36F4, + 0x0009, 0x0008, 0x0005, 0x06DC, 0x00DD, 0x018B, 0x00DC, 0x0004, 0x000B, + 0x018A, 0x0061, 0x0003, 0x0363, 0x00DF, 0x06DF, 0x0362, 0x000A, 0x001E, }, +{ 0x001D, 0x0061, 0x000D, 0x0D55, 0x06B9, 0x06B8, 0x01A5, 0x0021, 0x0020, + 0x0023, 0x000C, 0x0060, 0x0D54, 0x00AD, 0x00AC, 0x0022, 0x00AF, 0x06BB, + 0x000F, 0x001C, 0x0001, 0x002D, 0x0063, 0x01A4, 0x000E, 0x0001, 0x0005, + 0x01A7, 0x06BA, 0x01A6, 0x06A5, 0x0D57, 0x0D56, 0x1ABD, 0x0D51, 0x00AE, + 0x002C, 0x00A9, 0x002F, 0x0D50, 0x01A1, 0x1ABC, 0x06A4, 0x06A7, 0x06A6, + 0x00A8, 0x06A1, 0x01A0, 0x1ABF, 0x0D53, 0x06A0, 0x0D52, 0x1ABE, 0x06A3, + 0x0062, 0x002E, 0x0009, 0x0D5D, 0x01A3, 0x0D5C, 0x006D, 0x00AB, 0x06A2, + 0x006C, 0x001F, 0x0001, 0x06AD, 0x0029, 0x01A2, 0x0028, 0x0004, 0x001E, + 0x01AD, 0x006F, 0x0000, 0x01AC, 0x01AF, 0x06AC, 0x00AA, 0x006E, 0x0019, }, +{ 0x0019, 0x007D, 0x0018, 0x01B5, 0x000D, 0x01B4, 0x007C, 0x007F, 0x01B7, + 0x000C, 0x001B, 0x001A, 0x01B6, 0x000F, 0x00D5, 0x0019, 0x007E, 0x00D4, + 0x0018, 0x001B, 0x0001, 0x000E, 0x0011, 0x0009, 0x0005, 0x0005, 0x0005, + 0x00D7, 0x01B1, 0x0008, 0x01B0, 0x0079, 0x06FD, 0x0371, 0x0370, 0x00D6, + 0x0078, 0x01B3, 0x0010, 0x0373, 0x0013, 0x06FC, 0x007B, 0x007A, 0x00D1, + 0x00D0, 0x00D3, 0x0065, 0x0372, 0x06FF, 0x0064, 0x06FE, 0x037D, 0x00D2, + 0x00DD, 0x0067, 0x0004, 0x037C, 0x0012, 0x01B2, 0x0007, 0x0066, 0x01BD, + 0x0006, 0x0061, 0x0004, 0x01BC, 0x001A, 0x0060, 0x001D, 0x0004, 0x001C, + 0x0063, 0x0001, 0x0007, 0x000B, 0x0000, 0x0062, 0x000A, 0x0005, 0x0007, }, +{ 0x0069, 0x0045, 0x0068, 0x04BD, 0x0255, 0x04BC, 0x00E5, 0x00E4, 0x0031, + 0x0030, 0x0019, 0x0001, 0x0121, 0x00E7, 0x00E6, 0x0033, 0x00E1, 0x00E0, + 0x006B, 0x0018, 0x0001, 0x0044, 0x0032, 0x0047, 0x006A, 0x001B, 0x0005, + 0x003D, 0x0046, 0x0015, 0x0041, 0x0120, 0x0123, 0x04BF, 0x0122, 0x0040, + 0x003C, 0x00E3, 0x0014, 0x0254, 0x0043, 0x0975, 0x012D, 0x00E2, 0x00ED, + 0x0042, 0x00EC, 0x004D, 0x0257, 0x0256, 0x0251, 0x04BE, 0x0974, 0x0250, + 0x00EF, 0x00EE, 0x004C, 0x04B9, 0x012C, 0x04B8, 0x004F, 0x04BB, 0x0253, + 0x003F, 0x0017, 0x0001, 0x0252, 0x00E9, 0x00E8, 0x00EB, 0x0000, 0x0003, + 0x0016, 0x0002, 0x0004, 0x004E, 0x003E, 0x00EA, 0x0049, 0x000D, 0x0007, }, +{ 0x000D, 0x01BD, 0x000C, 0x0D31, 0x0D30, 0x0D33, 0x0359, 0x0358, 0x002D, + 0x0065, 0x001D, 0x001C, 0x0D32, 0x035B, 0x035A, 0x002C, 0x01BC, 0x0345, + 0x000F, 0x001F, 0x0001, 0x002F, 0x0064, 0x01BF, 0x0067, 0x0001, 0x0005, + 0x0066, 0x002E, 0x0061, 0x0029, 0x0695, 0x0694, 0x0697, 0x0696, 0x0060, + 0x01BE, 0x0D3D, 0x0028, 0x1A49, 0x0344, 0x1A48, 0x1A4B, 0x0D3C, 0x0691, + 0x002B, 0x01B9, 0x002A, 0x0D3F, 0x0690, 0x0347, 0x0D3E, 0x1A4A, 0x0346, + 0x00D5, 0x0341, 0x0063, 0x0D39, 0x0340, 0x0D38, 0x01B8, 0x0D3B, 0x0D3A, + 0x00D4, 0x0062, 0x0000, 0x0693, 0x01BB, 0x0343, 0x0342, 0x001E, 0x000E, + 0x006D, 0x0009, 0x0001, 0x006C, 0x00D7, 0x034D, 0x01BA, 0x0008, 0x0004, }, +{ 0x0075, 0x00CD, 0x0035, 0x03C1, 0x03C0, 0x07F9, 0x03C3, 0x1F8D, 0x00CC, + 0x0074, 0x0011, 0x0010, 0x03C2, 0x0FD9, 0x01F1, 0x00CF, 0x03CD, 0x00CE, + 0x0034, 0x0001, 0x0001, 0x0037, 0x00C9, 0x00C8, 0x0036, 0x0000, 0x0001, + 0x0FD8, 0x03CC, 0x00CB, 0x01F0, 0x07F8, 0x03CF, 0x07FB, 0x07FA, 0x00CA, + 0x01F3, 0x03CE, 0x00F5, 0x0FDB, 0x00F4, 0x07E5, 0x07E4, 0x07E7, 0x01F2, + 0x07E6, 0x03C9, 0x01FD, 0x0FDA, 0x1F8C, 0x07E1, 0x1F8F, 0x1F8E, 0x03C8, + 0x03CB, 0x0077, 0x0076, 0x0FC5, 0x03CA, 0x07E0, 0x00F7, 0x0FC4, 0x03F5, + 0x00F6, 0x01FC, 0x0003, 0x03F4, 0x0071, 0x03F7, 0x00F1, 0x0013, 0x0031, + 0x0030, 0x0070, 0x0005, 0x0012, 0x0073, 0x01FF, 0x0072, 0x007D, 0x0002, }, +{ 0x0061, 0x0055, 0x0060, 0x02C9, 0x02C8, 0x02CB, 0x0171, 0x00B5, 0x0054, + 0x0001, 0x0001, 0x0001, 0x0057, 0x0001, 0x0063, 0x001D, 0x0062, 0x0039, + 0x006D, 0x0000, 0x0005, 0x0038, 0x0056, 0x00B4, 0x006C, 0x0003, 0x001C, + 0x006F, 0x003B, 0x0002, 0x003A, 0x0170, 0x00B7, 0x0173, 0x0051, 0x006E, + 0x0025, 0x0050, 0x0069, 0x02CA, 0x0024, 0x0027, 0x0172, 0x00B6, 0x00B1, + 0x000D, 0x000C, 0x001F, 0x017D, 0x0026, 0x0068, 0x0053, 0x017C, 0x006B, + 0x001E, 0x000F, 0x0004, 0x017F, 0x006A, 0x02F5, 0x0019, 0x0021, 0x0052, + 0x02F4, 0x02F7, 0x0020, 0x0BCD, 0x05E5, 0x05E4, 0x0BCC, 0x0023, 0x00B0, + 0x02F6, 0x00B3, 0x0022, 0x02F1, 0x02F0, 0x0BCF, 0x0BCE, 0x017E, 0x005D, }, +{ 0x00BD, 0x0025, 0x01A1, 0x0159, 0x0299, 0x00BC, 0x0024, 0x0505, 0x0504, + 0x01A0, 0x0001, 0x001D, 0x006D, 0x001C, 0x0001, 0x0005, 0x0027, 0x01A3, + 0x0158, 0x001F, 0x001E, 0x01A2, 0x0026, 0x0021, 0x000D, 0x0020, 0x0023, + 0x0298, 0x006C, 0x0022, 0x00BF, 0x00BE, 0x01AD, 0x002D, 0x029B, 0x00B9, + 0x01AC, 0x00B8, 0x01AF, 0x029A, 0x006F, 0x015B, 0x006E, 0x0285, 0x0284, + 0x01AE, 0x0019, 0x002C, 0x01A9, 0x01A8, 0x000C, 0x000F, 0x015A, 0x00BB, + 0x000E, 0x0000, 0x0069, 0x01AB, 0x0018, 0x01AA, 0x0004, 0x0055, 0x00BA, + 0x0507, 0x0145, 0x0054, 0x0506, 0x00A5, 0x0501, 0x00A4, 0x0057, 0x0500, + 0x0A05, 0x0144, 0x00A7, 0x0287, 0x0286, 0x0503, 0x0147, 0x0A04, 0x0146, }, +{ 0x0759, 0x0041, 0x00E5, 0x03BD, 0x0E9D, 0x012D, 0x012C, 0x3A1D, 0x03BC, + 0x012F, 0x000D, 0x0040, 0x00E4, 0x03BF, 0x0043, 0x0042, 0x0758, 0x03BE, + 0x00E7, 0x0001, 0x0000, 0x003D, 0x00E6, 0x0015, 0x0014, 0x0017, 0x003C, + 0x743D, 0x012E, 0x03B9, 0x03B8, 0x0E9C, 0x03BB, 0x075B, 0x3A1C, 0x0E9F, + 0x0129, 0x00E1, 0x0128, 0x0E9E, 0x012B, 0x075A, 0x00E0, 0x0E99, 0x0745, + 0x3A1F, 0x03BA, 0x0744, 0x0E98, 0x1D0D, 0x03A5, 0x0E9B, 0x743C, 0x0E9A, + 0x012A, 0x004D, 0x00E3, 0x0E85, 0x01D5, 0x0E84, 0x004C, 0x0747, 0x1D0C, + 0x01D4, 0x003F, 0x0016, 0x0746, 0x03A4, 0x0741, 0x004F, 0x003E, 0x01D7, + 0x0740, 0x000C, 0x0011, 0x004E, 0x00E2, 0x00ED, 0x00EC, 0x0049, 0x0048, }, +}; + +static const uint8_t aic_mode2_vlc_bits[AIC_MODE2_NUM][AIC_MODE2_SIZE] = { +{ 1, 5, 4, 10, 6, 8, 5, 8, 8, + 7, 5, 7, 11, 10, 9, 8, 13, 11, + 6, 7, 3, 9, 8, 10, 9, 8, 5, + 10, 9, 10, 10, 14, 12, 14, 14, 12, + 8, 9, 7, 12, 8, 14, 9, 9, 12, + 8, 9, 11, 11, 13, 9, 11, 14, 12, + 6, 7, 9, 13, 9, 12, 7, 10, 12, + 11, 12, 8, 15, 10, 15, 13, 7, 12, + 10, 10, 8, 10, 13, 13, 13, 11, 8, }, +{ 4, 6, 5, 11, 8, 10, 7, 11, 9, + 4, 1, 4, 9, 7, 7, 5, 9, 10, + 6, 7, 4, 9, 9, 10, 9, 9, 6, + 9, 10, 9, 10, 12, 12, 13, 12, 11, + 9, 9, 8, 12, 8, 14, 10, 11, 12, + 7, 8, 10, 11, 12, 9, 11, 13, 12, + 6, 7, 8, 12, 9, 12, 7, 11, 10, + 12, 12, 9, 14, 12, 15, 13, 8, 12, + 11, 11, 10, 12, 13, 15, 14, 12, 9, }, +{ 5, 7, 6, 12, 9, 11, 8, 11, 10, + 7, 5, 7, 11, 10, 9, 8, 12, 12, + 5, 5, 1, 8, 7, 10, 8, 6, 4, + 8, 8, 8, 9, 12, 11, 13, 12, 11, + 8, 9, 8, 12, 8, 13, 10, 11, 11, + 8, 9, 11, 12, 13, 11, 12, 14, 13, + 8, 9, 10, 14, 11, 14, 9, 13, 13, + 8, 9, 6, 11, 10, 14, 11, 6, 10, + 6, 6, 4, 8, 9, 10, 10, 8, 5, }, +{ 11, 7, 8, 10, 12, 9, 10, 14, 12, + 7, 1, 5, 7, 8, 6, 4, 10, 9, + 10, 5, 4, 8, 11, 8, 7, 6, 7, + 11, 6, 7, 8, 10, 8, 10, 11, 9, + 10, 8, 9, 13, 9, 12, 8, 11, 12, + 11, 4, 7, 8, 9, 6, 8, 12, 9, + 8, 5, 8, 12, 9, 10, 6, 12, 11, + 12, 12, 10, 15, 13, 13, 13, 10, 13, + 15, 10, 9, 10, 12, 13, 13, 10, 9, }, +{ 11, 8, 8, 11, 13, 10, 11, 15, 12, + 7, 1, 4, 7, 7, 5, 4, 8, 9, + 11, 5, 5, 8, 11, 9, 8, 7, 8, + 13, 7, 8, 9, 11, 9, 10, 12, 10, + 10, 9, 8, 13, 9, 12, 9, 11, 12, + 11, 5, 7, 9, 10, 6, 9, 13, 10, + 7, 4, 7, 11, 8, 9, 5, 10, 11, + 13, 11, 9, 15, 13, 15, 13, 8, 12, + 15, 10, 10, 12, 13, 14, 14, 12, 11, }, +{ 12, 9, 9, 12, 13, 11, 11, 14, 12, + 8, 2, 5, 7, 9, 6, 5, 10, 10, + 9, 4, 2, 7, 9, 7, 6, 5, 6, + 12, 6, 7, 8, 10, 8, 10, 11, 9, + 12, 9, 10, 13, 11, 12, 10, 14, 13, + 12, 6, 8, 10, 10, 7, 9, 12, 10, + 8, 5, 8, 11, 9, 10, 7, 11, 12, + 8, 6, 5, 11, 11, 11, 8, 6, 9, + 12, 6, 6, 8, 10, 10, 11, 8, 6, }, +{ 13, 9, 10, 12, 14, 12, 11, 15, 15, + 8, 1, 5, 7, 9, 6, 5, 11, 10, + 11, 6, 5, 9, 11, 9, 8, 7, 8, + 12, 6, 8, 8, 11, 8, 10, 12, 10, + 10, 7, 9, 13, 10, 11, 9, 13, 12, + 11, 3, 6, 8, 9, 4, 7, 11, 8, + 8, 5, 9, 12, 10, 9, 7, 12, 13, + 13, 12, 10, 14, 14, 15, 12, 11, 14, + 15, 7, 9, 8, 11, 11, 12, 10, 9, }, +{ 10, 5, 6, 9, 11, 7, 8, 12, 11, + 8, 1, 4, 7, 9, 6, 4, 10, 10, + 11, 6, 6, 9, 9, 9, 9, 8, 8, + 14, 10, 10, 12, 12, 11, 12, 13, 12, + 10, 7, 8, 12, 9, 11, 8, 12, 11, + 13, 7, 10, 11, 11, 8, 10, 13, 11, + 6, 3, 7, 11, 8, 9, 5, 10, 11, + 11, 11, 9, 14, 14, 14, 11, 10, 13, + 14, 10, 11, 13, 13, 13, 14, 12, 12, }, +{ 2, 5, 3, 11, 8, 8, 6, 6, 7, + 8, 5, 6, 12, 10, 10, 8, 10, 11, + 7, 6, 2, 9, 8, 10, 8, 5, 4, + 10, 11, 10, 10, 13, 12, 14, 13, 10, + 10, 11, 8, 14, 9, 14, 12, 11, 12, + 9, 10, 9, 13, 12, 11, 12, 14, 11, + 8, 10, 7, 13, 10, 12, 8, 12, 12, + 10, 9, 6, 12, 11, 11, 11, 6, 9, + 10, 9, 6, 10, 9, 12, 11, 8, 7, }, +{ 6, 8, 6, 12, 11, 11, 10, 10, 9, + 6, 1, 3, 10, 8, 8, 6, 7, 10, + 8, 6, 3, 10, 9, 10, 8, 6, 5, + 11, 10, 10, 12, 13, 12, 14, 13, 12, + 10, 11, 8, 12, 9, 14, 12, 11, 12, + 9, 9, 8, 12, 12, 10, 12, 13, 11, + 7, 8, 6, 13, 9, 11, 7, 11, 11, + 11, 10, 7, 14, 11, 12, 12, 7, 10, + 12, 11, 8, 13, 12, 14, 13, 11, 10, }, +{ 7, 10, 7, 13, 13, 13, 11, 11, 10, + 8, 5, 6, 12, 11, 10, 9, 10, 11, + 7, 5, 1, 9, 8, 10, 7, 4, 4, + 9, 11, 9, 11, 12, 11, 13, 13, 10, + 9, 11, 8, 13, 9, 14, 12, 11, 12, + 11, 10, 10, 13, 12, 11, 14, 14, 12, + 9, 10, 8, 13, 10, 14, 9, 12, 12, + 9, 7, 4, 12, 10, 11, 10, 6, 7, + 9, 7, 4, 9, 9, 11, 9, 7, 5, }, +{ 7, 9, 7, 14, 11, 12, 10, 9, 9, + 8, 5, 5, 12, 9, 10, 8, 8, 11, + 7, 5, 2, 8, 8, 9, 7, 4, 4, + 10, 11, 10, 12, 14, 11, 12, 13, 12, + 9, 10, 8, 13, 8, 13, 10, 11, 11, + 9, 9, 8, 14, 10, 10, 11, 12, 11, + 10, 11, 9, 14, 10, 14, 9, 12, 14, + 6, 6, 3, 11, 8, 9, 8, 3, 6, + 9, 7, 4, 10, 8, 11, 10, 6, 5, }, +{ 6, 8, 7, 13, 12, 12, 10, 9, 9, + 9, 7, 8, 13, 11, 11, 9, 11, 12, + 7, 6, 1, 9, 8, 10, 7, 5, 4, + 10, 12, 10, 12, 13, 13, 14, 13, 11, + 9, 11, 9, 13, 10, 14, 12, 12, 12, + 11, 12, 10, 14, 13, 12, 13, 14, 12, + 8, 9, 7, 13, 10, 13, 8, 11, 12, + 8, 6, 3, 12, 9, 10, 9, 4, 6, + 10, 8, 5, 10, 10, 12, 11, 8, 6, }, +{ 7, 10, 7, 12, 9, 12, 10, 10, 12, + 9, 7, 7, 12, 9, 11, 6, 10, 11, + 6, 6, 1, 9, 8, 9, 7, 4, 5, + 11, 12, 9, 12, 10, 14, 13, 13, 11, + 10, 12, 8, 13, 8, 14, 10, 10, 11, + 11, 11, 10, 13, 14, 10, 14, 13, 11, + 11, 10, 7, 13, 8, 12, 7, 10, 12, + 7, 10, 4, 12, 6, 10, 8, 5, 8, + 10, 7, 4, 9, 7, 10, 9, 6, 5, }, +{ 7, 9, 7, 13, 12, 13, 10, 10, 8, + 8, 5, 6, 11, 10, 10, 8, 10, 10, + 7, 5, 2, 9, 8, 9, 7, 5, 3, + 8, 9, 7, 9, 11, 11, 13, 11, 9, + 8, 10, 7, 12, 9, 14, 11, 10, 10, + 9, 10, 9, 12, 12, 12, 13, 14, 12, + 10, 10, 9, 13, 11, 13, 9, 13, 12, + 8, 7, 4, 12, 10, 10, 10, 6, 6, + 7, 6, 3, 9, 8, 10, 9, 6, 3, }, +{ 7, 10, 7, 13, 13, 13, 11, 11, 9, + 8, 6, 6, 13, 11, 11, 9, 10, 11, + 7, 6, 1, 9, 8, 10, 8, 5, 4, + 8, 9, 8, 9, 12, 12, 12, 12, 8, + 10, 13, 9, 14, 11, 14, 14, 13, 12, + 9, 10, 9, 13, 12, 11, 13, 14, 11, + 9, 11, 8, 13, 11, 13, 10, 13, 13, + 9, 8, 5, 12, 10, 11, 11, 6, 7, + 8, 7, 3, 8, 9, 11, 10, 7, 4, }, +{ 8, 9, 7, 11, 11, 12, 11, 14, 9, + 8, 6, 6, 11, 13, 10, 9, 11, 9, + 7, 5, 1, 7, 9, 9, 7, 5, 3, + 13, 11, 9, 10, 12, 11, 12, 12, 9, + 10, 11, 9, 13, 9, 12, 12, 12, 10, + 12, 11, 10, 13, 14, 12, 14, 14, 11, + 11, 8, 8, 13, 11, 12, 9, 13, 11, + 9, 10, 5, 11, 8, 11, 9, 6, 7, + 7, 8, 4, 6, 8, 10, 8, 8, 5, }, +{ 8, 10, 8, 13, 13, 13, 12, 11, 10, + 5, 1, 3, 10, 7, 8, 6, 8, 9, + 8, 7, 4, 9, 10, 11, 8, 7, 6, + 8, 9, 7, 9, 12, 11, 12, 10, 8, + 9, 10, 8, 13, 9, 9, 12, 11, 11, + 7, 7, 6, 12, 9, 8, 10, 12, 8, + 6, 7, 4, 12, 8, 13, 6, 9, 10, + 13, 13, 9, 15, 14, 14, 15, 9, 11, + 13, 11, 9, 13, 13, 15, 15, 12, 10, }, +{ 10, 8, 9, 11, 12, 10, 8, 13, 13, + 9, 2, 5, 7, 5, 4, 3, 8, 9, + 11, 5, 5, 9, 8, 8, 6, 8, 8, + 12, 7, 8, 10, 10, 9, 8, 12, 10, + 9, 10, 9, 12, 7, 11, 7, 12, 12, + 9, 5, 8, 9, 9, 6, 6, 11, 10, + 6, 4, 7, 9, 5, 9, 3, 9, 10, + 13, 11, 9, 13, 10, 13, 10, 9, 13, + 14, 11, 10, 12, 12, 13, 11, 14, 11, }, +{ 11, 7, 8, 10, 12, 9, 9, 14, 10, + 9, 4, 7, 8, 10, 7, 7, 11, 10, + 8, 2, 2, 6, 8, 5, 5, 5, 6, + 15, 9, 10, 10, 12, 10, 11, 14, 12, + 9, 8, 9, 12, 9, 11, 8, 12, 11, + 14, 10, 11, 12, 13, 10, 12, 15, 12, + 9, 7, 8, 12, 9, 12, 7, 11, 13, + 9, 6, 5, 11, 10, 11, 7, 6, 9, + 11, 4, 5, 7, 8, 8, 8, 7, 7, }, +}; +//@} + +/** + * Codes used for determining block type + */ +//@{ +#define AIC_MODE1_NUM 90 +#define AIC_MODE1_SIZE 9 +#define AIC_MODE1_BITS 7 + +static const uint8_t aic_mode1_vlc_codes[AIC_MODE1_NUM][AIC_MODE1_SIZE] = { + { 0x01, 0x01, 0x01, 0x11, 0x00, 0x09, 0x03, 0x10, 0x05,}, + { 0x09, 0x01, 0x01, 0x05, 0x11, 0x00, 0x03, 0x21, 0x20,}, + { 0x01, 0x01, 0x01, 0x11, 0x09, 0x10, 0x05, 0x00, 0x03,}, + { 0x01, 0x01, 0x00, 0x03, 0x21, 0x05, 0x09, 0x20, 0x11,}, + { 0x01, 0x09, 0x00, 0x29, 0x08, 0x15, 0x03, 0x0B, 0x28,}, + { 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x03, 0x02,}, + { 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x01, 0x09, 0x08,}, + { 0x01, 0x01, 0x01, 0x09, 0x01, 0x08, 0x00, 0x03, 0x05,}, + { 0x01, 0x01, 0x01, 0x00, 0x05, 0x11, 0x09, 0x10, 0x03,}, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,}, + + { 0x01, 0x01, 0x01, 0x05, 0x01, 0x00, 0x03, 0x09, 0x08,}, + { 0x09, 0x01, 0x01, 0x05, 0x11, 0x00, 0x03, 0x21, 0x20,}, + { 0x01, 0x01, 0x01, 0x0D, 0x05, 0x04, 0x00, 0x07, 0x0C,}, + { 0x01, 0x01, 0x00, 0x05, 0x11, 0x03, 0x09, 0x21, 0x20,}, + { 0x05, 0x01, 0x01, 0x11, 0x00, 0x09, 0x03, 0x21, 0x20,}, + { 0x09, 0x01, 0x01, 0x00, 0x05, 0x01, 0x03, 0x11, 0x10,}, + { 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x01, 0x03, 0x02,}, + { 0x01, 0x01, 0x01, 0x09, 0x00, 0x05, 0x01, 0x03, 0x08,}, + { 0x01, 0x01, 0x01, 0x09, 0x11, 0x05, 0x00, 0x10, 0x03,}, + { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,}, + + { 0x01, 0x00, 0x01, 0x09, 0x08, 0x15, 0x14, 0x0B, 0x03,}, + { 0x0D, 0x01, 0x01, 0x05, 0x0C, 0x04, 0x01, 0x00, 0x07,}, + { 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x03, 0x01, 0x01,}, + { 0x05, 0x01, 0x01, 0x04, 0x19, 0x07, 0x18, 0x0D, 0x00,}, + { 0x11, 0x09, 0x01, 0x21, 0x05, 0x20, 0x01, 0x00, 0x03,}, + { 0x41, 0x01, 0x00, 0x05, 0x40, 0x03, 0x09, 0x21, 0x11,}, + { 0x29, 0x01, 0x00, 0x28, 0x09, 0x15, 0x03, 0x08, 0x0B,}, + { 0x01, 0x00, 0x01, 0x11, 0x09, 0x10, 0x05, 0x01, 0x03,}, + { 0x05, 0x01, 0x01, 0x04, 0x0D, 0x0C, 0x07, 0x00, 0x01,}, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,}, + + { 0x01, 0x00, 0x03, 0x05, 0x11, 0x10, 0x25, 0x24, 0x13,}, + { 0x21, 0x01, 0x01, 0x00, 0x11, 0x03, 0x05, 0x20, 0x09,}, + { 0x01, 0x01, 0x01, 0x00, 0x09, 0x11, 0x10, 0x05, 0x03,}, + { 0x21, 0x05, 0x01, 0x01, 0x09, 0x00, 0x11, 0x20, 0x03,}, + { 0x05, 0x01, 0x00, 0x04, 0x01, 0x19, 0x07, 0x18, 0x0D,}, + { 0x11, 0x01, 0x00, 0x01, 0x09, 0x01, 0x03, 0x10, 0x05,}, + { 0x1D, 0x01, 0x05, 0x0D, 0x0C, 0x04, 0x00, 0x1C, 0x0F,}, + { 0x05, 0x19, 0x01, 0x04, 0x00, 0x18, 0x1B, 0x1A, 0x07,}, + { 0x09, 0x01, 0x00, 0x01, 0x05, 0x03, 0x11, 0x10, 0x01,}, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,}, + + { 0x01, 0x00, 0x03, 0x41, 0x05, 0x40, 0x09, 0x11, 0x21,}, + { 0x05, 0x01, 0x01, 0x19, 0x04, 0x07, 0x00, 0x18, 0x0D,}, + { 0x01, 0x01, 0x01, 0x05, 0x01, 0x04, 0x01, 0x00, 0x03,}, + { 0x01, 0x05, 0x00, 0x0D, 0x01, 0x04, 0x07, 0x19, 0x18,}, + { 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x03, 0x02,}, + { 0x31, 0x01, 0x05, 0x19, 0x04, 0x07, 0x00, 0x30, 0x0D,}, + { 0x01, 0x00, 0x03, 0x11, 0x01, 0x05, 0x01, 0x09, 0x10,}, + { 0x01, 0x05, 0x01, 0x11, 0x01, 0x10, 0x00, 0x03, 0x09,}, + { 0x01, 0x09, 0x00, 0x29, 0x03, 0x08, 0x28, 0x15, 0x0B,}, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,}, + + { 0x01, 0x01, 0x00, 0x09, 0x15, 0x03, 0x08, 0x14, 0x0B,}, + { 0x11, 0x01, 0x01, 0x00, 0x09, 0x01, 0x03, 0x10, 0x05,}, + { 0x01, 0x00, 0x03, 0x25, 0x11, 0x05, 0x10, 0x24, 0x13,}, + { 0x11, 0x01, 0x00, 0x01, 0x09, 0x01, 0x05, 0x10, 0x03,}, + { 0x05, 0x01, 0x00, 0x0D, 0x0C, 0x04, 0x0F, 0x1D, 0x1C,}, + { 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x01, 0x03, 0x02,}, + { 0x21, 0x01, 0x05, 0x09, 0x11, 0x00, 0x03, 0x41, 0x40,}, + { 0x05, 0x01, 0x00, 0x1D, 0x1C, 0x0D, 0x0C, 0x0F, 0x04,}, + { 0x05, 0x01, 0x00, 0x0D, 0x31, 0x04, 0x19, 0x30, 0x07,}, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,}, + + { 0x01, 0x01, 0x00, 0x21, 0x05, 0x11, 0x03, 0x09, 0x20,}, + { 0x01, 0x01, 0x00, 0x11, 0x03, 0x05, 0x01, 0x09, 0x10,}, + { 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x03, 0x02,}, + { 0x05, 0x01, 0x04, 0x19, 0x07, 0x0D, 0x00, 0x31, 0x30,}, + { 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x03, 0x02,}, + { 0x05, 0x01, 0x01, 0x11, 0x09, 0x00, 0x03, 0x21, 0x20,}, + { 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, 0x03, 0x02,}, + { 0x01, 0x01, 0x01, 0x00, 0x01, 0x03, 0x01, 0x01, 0x02,}, + { 0x09, 0x01, 0x00, 0x29, 0x08, 0x15, 0x03, 0x28, 0x0B,}, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,}, + + { 0x01, 0x01, 0x01, 0x05, 0x01, 0x04, 0x00, 0x01, 0x03,}, + { 0x09, 0x01, 0x00, 0x29, 0x28, 0x15, 0x08, 0x03, 0x0B,}, + { 0x01, 0x00, 0x01, 0x11, 0x05, 0x10, 0x09, 0x01, 0x03,}, + { 0x05, 0x04, 0x01, 0x1D, 0x0D, 0x0C, 0x1C, 0x00, 0x0F,}, + { 0x09, 0x11, 0x01, 0x41, 0x00, 0x40, 0x05, 0x03, 0x21,}, + { 0x0D, 0x05, 0x01, 0x1D, 0x1C, 0x0C, 0x04, 0x00, 0x0F,}, + { 0x41, 0x09, 0x01, 0x40, 0x00, 0x11, 0x05, 0x03, 0x21,}, + { 0x01, 0x01, 0x01, 0x05, 0x01, 0x04, 0x00, 0x01, 0x03,}, + { 0x05, 0x04, 0x01, 0x0D, 0x01, 0x0C, 0x07, 0x01, 0x00,}, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,}, + + { 0x05, 0x04, 0x01, 0x07, 0x19, 0x31, 0x30, 0x0D, 0x00,}, + { 0x21, 0x01, 0x01, 0x00, 0x11, 0x09, 0x20, 0x05, 0x03,}, + { 0x05, 0x01, 0x01, 0x04, 0x07, 0x0D, 0x0C, 0x00, 0x01,}, + { 0x21, 0x09, 0x01, 0x00, 0x20, 0x05, 0x23, 0x22, 0x03,}, + { 0x31, 0x0D, 0x01, 0x19, 0x05, 0x30, 0x04, 0x07, 0x00,}, + { 0x31, 0x05, 0x01, 0x04, 0x19, 0x00, 0x0D, 0x30, 0x07,}, + { 0x31, 0x01, 0x00, 0x0D, 0x05, 0x19, 0x04, 0x30, 0x07,}, + { 0x01, 0x01, 0x01, 0x00, 0x01, 0x03, 0x02, 0x01, 0x01,}, + { 0x01, 0x00, 0x01, 0x01, 0x05, 0x09, 0x08, 0x03, 0x01,}, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,}, +}; + +static const uint8_t aic_mode1_vlc_bits[AIC_MODE1_NUM][AIC_MODE1_SIZE] = { + { 1, 4, 2, 7, 4, 6, 4, 7, 5,}, + { 5, 1, 3, 4, 6, 3, 3, 7, 7,}, + { 1, 4, 2, 7, 6, 7, 5, 4, 4,}, + { 1, 3, 3, 3, 7, 4, 5, 7, 6,}, + { 2, 4, 2, 6, 4, 5, 2, 4, 6,}, + { 7, 2, 3, 4, 7, 1, 5, 7, 7,}, + { 5, 1, 3, 6, 5, 5, 2, 7, 7,}, + { 2, 5, 1, 7, 3, 7, 5, 5, 6,}, + { 2, 4, 1, 4, 5, 7, 6, 7, 4,}, + { 0, 0, 0, 0, 0, 0, 0, 0, 0,}, + + { 2, 1, 3, 6, 5, 5, 5, 7, 7,}, + { 5, 1, 3, 4, 6, 3, 3, 7, 7,}, + { 4, 1, 2, 6, 5, 5, 4, 5, 6,}, + { 3, 1, 3, 4, 6, 3, 5, 7, 7,}, + { 4, 1, 3, 6, 3, 5, 3, 7, 7,}, + { 6, 1, 4, 4, 5, 2, 4, 7, 7,}, + { 7, 1, 5, 7, 4, 3, 2, 7, 7,}, + { 5, 3, 2, 7, 5, 6, 1, 5, 7,}, + { 4, 1, 2, 6, 7, 5, 4, 7, 4,}, + { 1, 0, 1, 0, 0, 0, 0, 0, 0,}, + + { 3, 3, 1, 5, 5, 6, 6, 5, 3,}, + { 6, 2, 1, 5, 6, 5, 4, 4, 5,}, + { 6, 4, 1, 7, 6, 7, 6, 3, 2,}, + { 4, 3, 1, 4, 6, 4, 6, 5, 3,}, + { 6, 5, 1, 7, 4, 7, 3, 3, 3,}, + { 7, 2, 2, 3, 7, 2, 4, 6, 5,}, + { 6, 2, 2, 6, 4, 5, 2, 4, 4,}, + { 4, 4, 1, 7, 6, 7, 5, 2, 4,}, + { 5, 4, 1, 5, 6, 6, 5, 4, 2,}, + { 0, 0, 0, 0, 0, 0, 0, 0, 0,}, + + { 2, 2, 2, 3, 5, 5, 6, 6, 5,}, + { 7, 1, 3, 3, 6, 3, 4, 7, 5,}, + { 2, 4, 1, 4, 6, 7, 7, 5, 4,}, + { 7, 4, 3, 1, 5, 3, 6, 7, 3,}, + { 4, 3, 3, 4, 1, 6, 4, 6, 5,}, + { 7, 4, 4, 2, 6, 1, 4, 7, 5,}, + { 5, 2, 3, 4, 4, 3, 2, 5, 4,}, + { 3, 5, 2, 3, 2, 5, 5, 5, 3,}, + { 6, 4, 4, 2, 5, 4, 7, 7, 1,}, + { 0, 0, 0, 0, 0, 0, 0, 0, 0,}, + + { 2, 2, 2, 7, 3, 7, 4, 5, 6,}, + { 4, 1, 3, 6, 4, 4, 3, 6, 5,}, + { 2, 4, 1, 7, 3, 7, 6, 6, 6,}, + { 3, 4, 3, 5, 1, 4, 4, 6, 6,}, + { 4, 5, 2, 7, 1, 7, 3, 7, 7,}, + { 6, 2, 3, 5, 3, 3, 2, 6, 4,}, + { 4, 4, 4, 7, 2, 5, 1, 6, 7,}, + { 4, 5, 2, 7, 1, 7, 4, 4, 6,}, + { 2, 4, 2, 6, 2, 4, 6, 5, 4,}, + { 0, 0, 0, 0, 0, 0, 0, 0, 0,}, + + { 1, 3, 3, 5, 6, 3, 5, 6, 5,}, + { 7, 1, 4, 4, 6, 2, 4, 7, 5,}, + { 2, 2, 2, 6, 5, 3, 5, 6, 5,}, + { 7, 4, 4, 2, 6, 1, 5, 7, 4,}, + { 3, 2, 2, 4, 4, 3, 4, 5, 5,}, + { 7, 2, 5, 3, 7, 1, 4, 7, 7,}, + { 6, 2, 3, 4, 5, 2, 2, 7, 7,}, + { 3, 2, 2, 5, 5, 4, 4, 4, 3,}, + { 3, 2, 2, 4, 6, 3, 5, 6, 3,}, + { 0, 0, 0, 0, 0, 0, 0, 0, 0,}, + + { 1, 3, 3, 7, 4, 6, 3, 5, 7,}, + { 4, 1, 4, 7, 4, 5, 2, 6, 7,}, + { 2, 4, 1, 7, 5, 7, 3, 7, 7,}, + { 3, 2, 3, 5, 3, 4, 2, 6, 6,}, + { 3, 5, 4, 7, 2, 7, 1, 7, 7,}, + { 4, 1, 3, 6, 5, 3, 3, 7, 7,}, + { 4, 2, 5, 7, 3, 7, 1, 7, 7,}, + { 7, 4, 1, 7, 3, 7, 2, 5, 7,}, + { 4, 2, 2, 6, 4, 5, 2, 6, 4,}, + { 0, 0, 0, 0, 0, 0, 0, 0, 0,}, + + { 3, 4, 1, 7, 6, 7, 6, 2, 6,}, + { 4, 2, 2, 6, 6, 5, 4, 2, 4,}, + { 4, 4, 1, 7, 5, 7, 6, 2, 4,}, + { 3, 3, 2, 5, 4, 4, 5, 2, 4,}, + { 4, 5, 2, 7, 2, 7, 3, 2, 6,}, + { 4, 3, 2, 5, 5, 4, 3, 2, 4,}, + { 7, 4, 2, 7, 2, 5, 3, 2, 6,}, + { 4, 6, 2, 7, 3, 7, 6, 1, 6,}, + { 5, 5, 1, 6, 4, 6, 5, 2, 4,}, + { 0, 0, 0, 0, 0, 0, 0, 0, 0,}, + + { 3, 3, 2, 3, 5, 6, 6, 4, 2,}, + { 7, 1, 3, 3, 6, 5, 7, 4, 3,}, + { 5, 4, 1, 5, 5, 6, 6, 4, 2,}, + { 6, 4, 2, 2, 6, 3, 6, 6, 2,}, + { 6, 4, 2, 5, 3, 6, 3, 3, 2,}, + { 6, 3, 2, 3, 5, 2, 4, 6, 3,}, + { 6, 2, 2, 4, 3, 5, 3, 6, 3,}, + { 7, 5, 1, 7, 4, 7, 7, 3, 2,}, + { 5, 5, 2, 3, 6, 7, 7, 5, 1,}, + { 0, 0, 0, 0, 0, 0, 0, 0, 0,}, +}; + +//@} + +#define PBTYPE_ESCAPE 0xFF + +/** tables used for P-frame macroblock type decoding */ +//@{ +#define NUM_PTYPE_VLCS 7 +#define PTYPE_VLC_SIZE 8 +#define PTYPE_VLC_BITS 7 + +static const uint8_t ptype_vlc_codes[NUM_PTYPE_VLCS][PTYPE_VLC_SIZE] = { + { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 }, + { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 }, + { 0x0D, 0x05, 0x01, 0x04, 0x01, 0x00, 0x07, 0x0C }, + { 0x09, 0x11, 0x01, 0x00, 0x05, 0x03, 0x21, 0x20 }, + { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 }, + { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 }, + { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 } +}; + +static const uint8_t ptype_vlc_bits[NUM_PTYPE_VLCS][PTYPE_VLC_SIZE] = { + { 1, 2, 3, 6, 5, 4, 7, 7 }, + { 3, 1, 2, 7, 6, 5, 4, 7 }, + { 5, 4, 1, 4, 3, 3, 4, 5 }, + { 4, 5, 2, 2, 3, 2, 6, 6 }, + { 5, 6, 1, 4, 2, 3, 7, 7 }, + { 5, 6, 1, 4, 3, 2, 7, 7 }, + { 6, 3, 2, 7, 5, 4, 1, 7 } +}; + +static const uint8_t ptype_vlc_syms[PTYPE_VLC_SIZE] = { + 0, 1, 2, 3, 8, 9, 11, PBTYPE_ESCAPE +}; + +/** reverse of ptype_vlc_syms */ +static const uint8_t block_num_to_ptype_vlc_num[12] = { + 0, 1, 2, 3, 0, 0, 2, 0, 4, 5, 0, 6 +}; +//@} + +/** tables used for P-frame macroblock type decoding */ +//@{ +#define NUM_BTYPE_VLCS 6 +#define BTYPE_VLC_SIZE 7 +#define BTYPE_VLC_BITS 6 + +static const uint8_t btype_vlc_codes[NUM_BTYPE_VLCS][BTYPE_VLC_SIZE] = { + { 0x01, 0x05, 0x00, 0x03, 0x11, 0x09, 0x10 }, + { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 }, + { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 }, + { 0x09, 0x01, 0x00, 0x01, 0x05, 0x03, 0x08 }, + { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 }, + { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 } +}; + +static const uint8_t btype_vlc_bits[NUM_BTYPE_VLCS][PTYPE_VLC_SIZE] = { + { 2, 3, 2, 2, 5, 4, 5 }, + { 4, 1, 3, 2, 6, 5, 6 }, + { 6, 4, 1, 2, 5, 3, 6 }, + { 5, 3, 3, 1, 4, 3, 5 }, + { 6, 5, 3, 2, 4, 1, 6 }, + { 6, 5, 3, 1, 4, 2, 6 } +}; + +static const uint8_t btype_vlc_syms[BTYPE_VLC_SIZE] = { + 0, 1, 4, 5, 10, 7, PBTYPE_ESCAPE +}; + +/** reverse of btype_vlc_syms */ +static const uint8_t block_num_to_btype_vlc_num[12] = { + 0, 1, 0, 0, 2, 3, 0, 5, 0, 0, 4, 0 +}; +//@} +#endif /* FFMPEG_RV40VLC2_H */ diff --git a/contrib/ffmpeg/libavcodec/s3tc.c b/contrib/ffmpeg/libavcodec/s3tc.c new file mode 100644 index 000000000..fc035e577 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/s3tc.c @@ -0,0 +1,96 @@ +/* + * S3 Texture Compression (S3TC) decoding functions + * Copyright (c) 2007 by Ivo van Poorten + * + * see also: http://wiki.multimedia.cx/index.php?title=S3TC + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "s3tc.h" + +static inline void dxt1_decode_pixels(const uint8_t *s, uint32_t *d, + unsigned int qstride, unsigned int flag, + uint64_t alpha) { + unsigned int x, y, c0, c1, a = (!flag * 255) << 24; + unsigned int rb0, rb1, rb2, rb3, g0, g1, g2, g3; + uint32_t colors[4], pixels; + + c0 = AV_RL16(s); + c1 = AV_RL16(s+2); + + rb0 = (c0<<3 | c0<<8) & 0xf800f8; + rb1 = (c1<<3 | c1<<8) & 0xf800f8; + rb0 += (rb0>>5) & 0x070007; + rb1 += (rb1>>5) & 0x070007; + g0 = (c0 <<5) & 0x00fc00; + g1 = (c1 <<5) & 0x00fc00; + g0 += (g0 >>6) & 0x000300; + g1 += (g1 >>6) & 0x000300; + + colors[0] = rb0 + g0 + a; + colors[1] = rb1 + g1 + a; + + if (c0 > c1 || flag) { + rb2 = (((2*rb0+rb1) * 21) >> 6) & 0xff00ff; + rb3 = (((2*rb1+rb0) * 21) >> 6) & 0xff00ff; + g2 = (((2*g0 +g1 ) * 21) >> 6) & 0x00ff00; + g3 = (((2*g1 +g0 ) * 21) >> 6) & 0x00ff00; + colors[3] = rb3 + g3 + a; + } else { + rb2 = ((rb0+rb1) >> 1) & 0xff00ff; + g2 = ((g0 +g1 ) >> 1) & 0x00ff00; + colors[3] = 0; + } + + colors[2] = rb2 + g2 + a; + + pixels = AV_RL32(s+4); + for (y=0; y<4; y++) { + for (x=0; x<4; x++) { + a = (alpha & 0x0f) << 28; + a += a >> 4; + d[x] = a + colors[pixels&3]; + pixels >>= 2; + alpha >>= 4; + } + d += qstride; + } +} + +void ff_decode_dxt1(const uint8_t *s, uint8_t *dst, + const unsigned int w, const unsigned int h, + const unsigned int stride) { + unsigned int bx, by, qstride = stride/4; + uint32_t *d = (uint32_t *) dst; + + for (by=0; by < h/4; by++, d += stride-w) + for (bx=0; bx < w/4; bx++, s+=8, d+=4) + dxt1_decode_pixels(s, d, qstride, 0, 0LL); +} + +void ff_decode_dxt3(const uint8_t *s, uint8_t *dst, + const unsigned int w, const unsigned int h, + const unsigned int stride) { + unsigned int bx, by, qstride = stride/4; + uint32_t *d = (uint32_t *) dst; + + for (by=0; by < h/4; by++, d += stride-w) + for (bx=0; bx < w/4; bx++, s+=16, d+=4) + dxt1_decode_pixels(s+8, d, qstride, 1, AV_RL64(s)); +} diff --git a/contrib/ffmpeg/libavcodec/s3tc.h b/contrib/ffmpeg/libavcodec/s3tc.h new file mode 100644 index 000000000..9ead901b6 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/s3tc.h @@ -0,0 +1,53 @@ +/* + * S3 Texture Compression (S3TC) decoding functions + * Copyright (c) 2007 by Ivo van Poorten + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_S3TC_H +#define FFMPEG_S3TC_H + +#include + +#define FF_S3TC_DXT1 0x31545844 +#define FF_S3TC_DXT3 0x33545844 + +/** + * Decode DXT1 encoded data to RGB32 + * @param *src source buffer, has to be aligned on a 4-byte boundary + * @param *dst destination buffer + * @param w width of output image + * @param h height of output image + * @param stride line size of output image + */ +void ff_decode_dxt1(const uint8_t *src, uint8_t *dst, + const unsigned int w, const unsigned int h, + const unsigned int stride); +/** + * Decode DXT3 encoded data to RGB32 + * @param *src source buffer, has to be aligned on a 4-byte boundary + * @param *dst destination buffer + * @param w width of output image + * @param h height of output image + * @param stride line size of output image + */ +void ff_decode_dxt3(const uint8_t *src, uint8_t *dst, + const unsigned int w, const unsigned int h, + const unsigned int stride); + +#endif /* FFMPEG_S3TC_H */ diff --git a/contrib/ffmpeg/libavcodec/sgi.h b/contrib/ffmpeg/libavcodec/sgi.h new file mode 100644 index 000000000..8c658761d --- /dev/null +++ b/contrib/ffmpeg/libavcodec/sgi.h @@ -0,0 +1,36 @@ + /* + * SGI image encoder + * Xiaohui Sun + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_SGI_H +#define FFMPEG_SGI_H + +/** + * SGI image file signature + */ +#define SGI_MAGIC 474 + +#define SGI_HEADER_SIZE 512 + +#define SGI_GRAYSCALE 1 +#define SGI_RGB 3 +#define SGI_RGBA 4 + +#endif /* FFMPEG_SGI_H */ diff --git a/contrib/ffmpeg/libavcodec/sgidec.c b/contrib/ffmpeg/libavcodec/sgidec.c new file mode 100644 index 000000000..5a85cdcdd --- /dev/null +++ b/contrib/ffmpeg/libavcodec/sgidec.c @@ -0,0 +1,267 @@ +/* + * SGI image decoder + * Todd Kirby + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "bytestream.h" +#include "sgi.h" + +typedef struct SgiState { + AVFrame picture; + unsigned int width; + unsigned int height; + unsigned int depth; + int linesize; +} SgiState; + +/** + * Expand an RLE row into a channel. + * @param in_buf input buffer + * @param in_end end of input buffer + * @param out_buf Points to one line after the output buffer. + * @param out_end end of line in output buffer + * @param pixelstride pixel stride of input buffer + * @return size of output in bytes, -1 if buffer overflows + */ +static int expand_rle_row(const uint8_t *in_buf, const uint8_t* in_end, + unsigned char *out_buf, uint8_t* out_end, int pixelstride) +{ + unsigned char pixel, count; + unsigned char *orig = out_buf; + + while (1) { + if(in_buf + 1 > in_end) return -1; + pixel = bytestream_get_byte(&in_buf); + if (!(count = (pixel & 0x7f))) { + return (out_buf - orig) / pixelstride; + } + + /* Check for buffer overflow. */ + if(out_buf + pixelstride * count >= out_end) return -1; + + if (pixel & 0x80) { + while (count--) { + *out_buf = bytestream_get_byte(&in_buf); + out_buf += pixelstride; + } + } else { + pixel = bytestream_get_byte(&in_buf); + + while (count--) { + *out_buf = pixel; + out_buf += pixelstride; + } + } + } +} + +/** + * Read a run length encoded SGI image. + * @param out_buf output buffer + * @param in_buf input buffer + * @param in_end end of input buffer + * @param s the current image state + * @return 0 if no error, else return error number. + */ +static int read_rle_sgi(unsigned char* out_buf, const uint8_t *in_buf, + const uint8_t *in_end, SgiState* s) +{ + uint8_t *dest_row; + unsigned int len = s->height * s->depth * 4; + const uint8_t *start_table = in_buf; + unsigned int y, z; + unsigned int start_offset; + + /* size of RLE offset and length tables */ + if(len * 2 > in_end - in_buf) { + return AVERROR_INVALIDDATA; + } + + in_buf -= SGI_HEADER_SIZE; + for (z = 0; z < s->depth; z++) { + dest_row = out_buf; + for (y = 0; y < s->height; y++) { + dest_row -= s->linesize; + start_offset = bytestream_get_be32(&start_table); + if(start_offset > in_end - in_buf) { + return AVERROR_INVALIDDATA; + } + if (expand_rle_row(in_buf + start_offset, in_end, dest_row + z, + dest_row + FFABS(s->linesize), s->depth) != s->width) + return AVERROR_INVALIDDATA; + } + } + return 0; +} + +/** + * Read an uncompressed SGI image. + * @param out_buf output buffer + * @param out_end end ofoutput buffer + * @param in_buf input buffer + * @param in_end end of input buffer + * @param s the current image state + * @return 0 if read success, otherwise return -1. + */ +static int read_uncompressed_sgi(unsigned char* out_buf, uint8_t* out_end, + const uint8_t *in_buf, const uint8_t *in_end, SgiState* s) +{ + int x, y, z; + const uint8_t *ptr; + unsigned int offset = s->height * s->width; + + /* Test buffer size. */ + if (offset * s->depth > in_end - in_buf) { + return -1; + } + + for (y = s->height - 1; y >= 0; y--) { + out_end = out_buf + (y * s->linesize); + for (x = s->width; x > 0; x--) { + ptr = in_buf++; + for(z = 0; z < s->depth; z ++) { + bytestream_put_byte(&out_end, *ptr); + ptr += offset; + } + } + } + return 0; +} + +static int decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *in_buf, int buf_size) +{ + SgiState *s = avctx->priv_data; + AVFrame *picture = data; + AVFrame *p = &s->picture; + const uint8_t *in_end = in_buf + buf_size; + unsigned int dimension, bytes_per_channel, rle; + int ret = 0; + uint8_t *out_buf, *out_end; + + if (buf_size < SGI_HEADER_SIZE){ + av_log(avctx, AV_LOG_ERROR, "buf_size too small (%d)\n", buf_size); + return -1; + } + + /* Test for SGI magic. */ + if (bytestream_get_be16(&in_buf) != SGI_MAGIC) { + av_log(avctx, AV_LOG_ERROR, "bad magic number\n"); + return -1; + } + + rle = bytestream_get_byte(&in_buf); + bytes_per_channel = bytestream_get_byte(&in_buf); + dimension = bytestream_get_be16(&in_buf); + s->width = bytestream_get_be16(&in_buf); + s->height = bytestream_get_be16(&in_buf); + s->depth = bytestream_get_be16(&in_buf); + + if (bytes_per_channel != 1) { + av_log(avctx, AV_LOG_ERROR, "wrong channel number\n"); + return -1; + } + + /* Check for supported image dimensions. */ + if (dimension != 2 && dimension != 3) { + av_log(avctx, AV_LOG_ERROR, "wrong dimension number\n"); + return -1; + } + + if (s->depth == SGI_GRAYSCALE) { + avctx->pix_fmt = PIX_FMT_GRAY8; + } else if (s->depth == SGI_RGB) { + avctx->pix_fmt = PIX_FMT_RGB24; + } else if (s->depth == SGI_RGBA) { + avctx->pix_fmt = PIX_FMT_RGBA; + } else { + av_log(avctx, AV_LOG_ERROR, "wrong picture format\n"); + return -1; + } + + if (avcodec_check_dimensions(avctx, s->width, s->height)) + return -1; + avcodec_set_dimensions(avctx, s->width, s->height); + + if (p->data[0]) + avctx->release_buffer(avctx, p); + + p->reference = 0; + if (avctx->get_buffer(avctx, p) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed.\n"); + return -1; + } + + p->pict_type = FF_I_TYPE; + p->key_frame = 1; + out_buf = p->data[0]; + + out_end = out_buf + p->linesize[0] * s->height; + + s->linesize = p->linesize[0]; + + /* Skip header. */ + in_buf += SGI_HEADER_SIZE - 12; + if (rle) { + ret = read_rle_sgi(out_end, in_buf, in_end, s); + } else { + ret = read_uncompressed_sgi(out_buf, out_end, in_buf, in_end, s); + } + + if (ret == 0) { + *picture = s->picture; + *data_size = sizeof(AVPicture); + return buf_size; + } else { + return -1; + } +} + +static int sgi_init(AVCodecContext *avctx){ + SgiState *s = avctx->priv_data; + + avcodec_get_frame_defaults(&s->picture); + avctx->coded_frame = &s->picture; + + return 0; +} + +static int sgi_end(AVCodecContext *avctx) +{ + SgiState * const s = avctx->priv_data; + + if (s->picture.data[0]) + avctx->release_buffer(avctx, &s->picture); + + return 0; +} + +AVCodec sgi_decoder = { + "sgi", + CODEC_TYPE_VIDEO, + CODEC_ID_SGI, + sizeof(SgiState), + sgi_init, + NULL, + sgi_end, + decode_frame, +}; + diff --git a/contrib/ffmpeg/libavcodec/sgienc.c b/contrib/ffmpeg/libavcodec/sgienc.c new file mode 100644 index 000000000..147bc8961 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/sgienc.c @@ -0,0 +1,156 @@ +/* + * SGI image encoder + * Todd Kirby + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "bytestream.h" +#include "sgi.h" +#include "rle.h" + +#define SGI_SINGLE_CHAN 2 +#define SGI_MULTI_CHAN 3 + +typedef struct SgiContext { + AVFrame picture; +} SgiContext; + +static int encode_init(AVCodecContext *avctx){ + SgiContext *s = avctx->priv_data; + + avcodec_get_frame_defaults(&s->picture); + avctx->coded_frame = &s->picture; + + return 0; +} + +static int encode_frame(AVCodecContext *avctx, unsigned char *buf, + int buf_size, void *data) { + SgiContext *s = avctx->priv_data; + AVFrame * const p = &s->picture; + uint8_t *offsettab, *lengthtab, *in_buf, *encode_buf; + int x, y, z, length, tablesize; + unsigned int width, height, depth, dimension; + unsigned char *orig_buf = buf, *end_buf = buf + buf_size; + + *p = *(AVFrame*)data; + p->pict_type = FF_I_TYPE; + p->key_frame = 1; + + width = avctx->width; + height = avctx->height; + + switch (avctx->pix_fmt) { + case PIX_FMT_GRAY8: + dimension = SGI_SINGLE_CHAN; + depth = SGI_GRAYSCALE; + break; + case PIX_FMT_RGB24: + dimension = SGI_MULTI_CHAN; + depth = SGI_RGB; + break; + case PIX_FMT_RGBA: + dimension = SGI_MULTI_CHAN; + depth = SGI_RGBA; + break; + default: + return AVERROR_INVALIDDATA; + } + + tablesize = depth * height * 4; + length = tablesize * 2 + SGI_HEADER_SIZE; + + if (buf_size < length) { + av_log(avctx, AV_LOG_ERROR, "buf_size too small(need %d, got %d)\n", length, buf_size); + return -1; + } + + /* Encode header. */ + bytestream_put_be16(&buf, SGI_MAGIC); + bytestream_put_byte(&buf, 1); /* RLE */ + bytestream_put_byte(&buf, 1); /* bytes_per_channel */ + bytestream_put_be16(&buf, dimension); + bytestream_put_be16(&buf, width); + bytestream_put_be16(&buf, height); + bytestream_put_be16(&buf, depth); + + /* The rest are constant in this implementation. */ + bytestream_put_be32(&buf, 0L); /* pixmin */ + bytestream_put_be32(&buf, 255L); /* pixmax */ + bytestream_put_be32(&buf, 0L); /* dummy */ + + /* name */ + memset(buf, 0, SGI_HEADER_SIZE); + buf += 80; + + /* colormap */ + bytestream_put_be32(&buf, 0L); + + /* The rest of the 512 byte header is unused. */ + buf += 404; + offsettab = buf; + + /* Skip RLE offset table. */ + buf += tablesize; + lengthtab = buf; + + /* Skip RLE length table. */ + buf += tablesize; + + /* Make an intermediate consecutive buffer. */ + if ((encode_buf = av_malloc(width)) == NULL) + return -1; + + for (z = 0; z < depth; z++) { + in_buf = p->data[0] + p->linesize[0] * (height - 1) + z; + + for (y = 0; y < height; y++) { + bytestream_put_be32(&offsettab, buf - orig_buf); + + for (x = 0; x < width; x++) + encode_buf[x] = in_buf[depth * x]; + + if((length = ff_rle_encode(buf, end_buf - buf - 1, encode_buf, 1, width, 0, 0, 0x80, 0)) < 1) { + av_free(encode_buf); + return -1; + } + + buf += length; + bytestream_put_byte(&buf, 0); + bytestream_put_be32(&lengthtab, length + 1); + in_buf -= p->linesize[0]; + } + } + + av_free(encode_buf); + /* total length */ + return buf - orig_buf; +} + +AVCodec sgi_encoder = { + "sgi", + CODEC_TYPE_VIDEO, + CODEC_ID_SGI, + sizeof(SgiContext), + encode_init, + encode_frame, + NULL, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGBA, PIX_FMT_PAL8, PIX_FMT_GRAY8, -1}, +}; + diff --git a/contrib/ffmpeg/libavcodec/sh4/dsputil_align.c b/contrib/ffmpeg/libavcodec/sh4/dsputil_align.c index 7e7e3304b..15b0350f2 100644 --- a/contrib/ffmpeg/libavcodec/sh4/dsputil_align.c +++ b/contrib/ffmpeg/libavcodec/sh4/dsputil_align.c @@ -21,8 +21,8 @@ */ -#include "../avcodec.h" -#include "../dsputil.h" +#include "avcodec.h" +#include "dsputil.h" #define LP(p) *(uint32_t*)(p) diff --git a/contrib/ffmpeg/libavcodec/sh4/dsputil_sh4.c b/contrib/ffmpeg/libavcodec/sh4/dsputil_sh4.c index b38eb2551..18b19b1c3 100644 --- a/contrib/ffmpeg/libavcodec/sh4/dsputil_sh4.c +++ b/contrib/ffmpeg/libavcodec/sh4/dsputil_sh4.c @@ -20,8 +20,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../avcodec.h" -#include "../dsputil.h" +#include "avcodec.h" +#include "dsputil.h" static void memzero_align8(void *dst,size_t size) { diff --git a/contrib/ffmpeg/libavcodec/sh4/idct_sh4.c b/contrib/ffmpeg/libavcodec/sh4/idct_sh4.c index 3b8428c3c..8259c0075 100644 --- a/contrib/ffmpeg/libavcodec/sh4/idct_sh4.c +++ b/contrib/ffmpeg/libavcodec/sh4/idct_sh4.c @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "../dsputil.h" +#include "dsputil.h" #define c1 1.38703984532214752434 /* sqrt(2)*cos(1*pi/16) */ #define c2 1.30656296487637657577 /* sqrt(2)*cos(2*pi/16) */ #define c3 1.17587560241935884520 /* sqrt(2)*cos(3*pi/16) */ diff --git a/contrib/ffmpeg/libavcodec/sh4/qpel.c b/contrib/ffmpeg/libavcodec/sh4/qpel.c index 7a73ac50d..a75d22f6c 100644 --- a/contrib/ffmpeg/libavcodec/sh4/qpel.c +++ b/contrib/ffmpeg/libavcodec/sh4/qpel.c @@ -21,14 +21,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#define LD(adr) *(uint32_t*)(adr) - #define PIXOP2(OPNAME, OP) \ /*static inline void OPNAME ## _no_rnd_pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \ {\ do {\ - OP(LP(dst ),no_rnd_avg32(LD32(src1 ),LD32(src2 )) ); \ - OP(LP(dst+4),no_rnd_avg32(LD32(src1+4),LD32(src2+4)) ); \ + OP(LP(dst ),no_rnd_avg32(AV_RN32(src1 ),AV_RN32(src2 )) ); \ + OP(LP(dst+4),no_rnd_avg32(AV_RN32(src1+4),AV_RN32(src2+4)) ); \ src1+=src_stride1; \ src2+=src_stride2; \ dst+=dst_stride; \ @@ -38,8 +36,8 @@ static inline void OPNAME ## _pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \ {\ do {\ - OP(LP(dst ),rnd_avg32(LD32(src1 ),LD32(src2 )) ); \ - OP(LP(dst+4),rnd_avg32(LD32(src1+4),LD32(src2+4)) ); \ + OP(LP(dst ),rnd_avg32(AV_RN32(src1 ),AV_RN32(src2 )) ); \ + OP(LP(dst+4),rnd_avg32(AV_RN32(src1+4),AV_RN32(src2+4)) ); \ src1+=src_stride1; \ src2+=src_stride2; \ dst+=dst_stride; \ @@ -49,7 +47,7 @@ static inline void OPNAME ## _pixels8_l2(uint8_t *dst, const uint8_t *src1, cons static inline void OPNAME ## _pixels4_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \ {\ do {\ - OP(LP(dst ),rnd_avg32(LD32(src1 ),LD32(src2 )) ); \ + OP(LP(dst ),rnd_avg32(AV_RN32(src1 ),AV_RN32(src2 )) ); \ src1+=src_stride1; \ src2+=src_stride2; \ dst+=dst_stride; \ @@ -59,10 +57,10 @@ static inline void OPNAME ## _pixels4_l2(uint8_t *dst, const uint8_t *src1, cons static inline void OPNAME ## _no_rnd_pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \ {\ do {\ - OP(LP(dst ),no_rnd_avg32(LD32(src1 ),LD32(src2 )) ); \ - OP(LP(dst+4),no_rnd_avg32(LD32(src1+4),LD32(src2+4)) ); \ - OP(LP(dst+8),no_rnd_avg32(LD32(src1+8),LD32(src2+8)) ); \ - OP(LP(dst+12),no_rnd_avg32(LD32(src1+12),LD32(src2+12)) ); \ + OP(LP(dst ),no_rnd_avg32(AV_RN32(src1 ),AV_RN32(src2 )) ); \ + OP(LP(dst+4),no_rnd_avg32(AV_RN32(src1+4),AV_RN32(src2+4)) ); \ + OP(LP(dst+8),no_rnd_avg32(AV_RN32(src1+8),AV_RN32(src2+8)) ); \ + OP(LP(dst+12),no_rnd_avg32(AV_RN32(src1+12),AV_RN32(src2+12)) ); \ src1+=src_stride1; \ src2+=src_stride2; \ dst+=dst_stride; \ @@ -72,10 +70,10 @@ static inline void OPNAME ## _no_rnd_pixels16_l2(uint8_t *dst, const uint8_t *sr static inline void OPNAME ## _pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \ {\ do {\ - OP(LP(dst ),rnd_avg32(LD32(src1 ),LD32(src2 )) ); \ - OP(LP(dst+4),rnd_avg32(LD32(src1+4),LD32(src2+4)) ); \ - OP(LP(dst+8),rnd_avg32(LD32(src1+8),LD32(src2+8)) ); \ - OP(LP(dst+12),rnd_avg32(LD32(src1+12),LD32(src2+12)) ); \ + OP(LP(dst ),rnd_avg32(AV_RN32(src1 ),AV_RN32(src2 )) ); \ + OP(LP(dst+4),rnd_avg32(AV_RN32(src1+4),AV_RN32(src2+4)) ); \ + OP(LP(dst+8),rnd_avg32(AV_RN32(src1+8),AV_RN32(src2+8)) ); \ + OP(LP(dst+12),rnd_avg32(AV_RN32(src1+12),AV_RN32(src2+12)) ); \ src1+=src_stride1; \ src2+=src_stride2; \ dst+=dst_stride; \ @@ -95,7 +93,7 @@ static inline void OPNAME ## _pixels4_l2_aligned(uint8_t *dst, const uint8_t *sr static inline void OPNAME ## _pixels4_l2_aligned2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \ {\ do {\ - OP(LP(dst ),rnd_avg32(LD32(src1 ),LP(src2 )) ); \ + OP(LP(dst ),rnd_avg32(AV_RN32(src1 ),LP(src2 )) ); \ src1+=src_stride1; \ src2+=src_stride2; \ dst+=dst_stride; \ @@ -105,10 +103,10 @@ static inline void OPNAME ## _pixels4_l2_aligned2(uint8_t *dst, const uint8_t *s static inline void OPNAME ## _no_rnd_pixels16_l2_aligned2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \ {\ do {\ - OP(LP(dst ),no_rnd_avg32(LD32(src1 ),LP(src2 )) ); \ - OP(LP(dst+4),no_rnd_avg32(LD32(src1+4),LP(src2+4)) ); \ - OP(LP(dst+8),no_rnd_avg32(LD32(src1+8),LP(src2+8)) ); \ - OP(LP(dst+12),no_rnd_avg32(LD32(src1+12),LP(src2+12)) ); \ + OP(LP(dst ),no_rnd_avg32(AV_RN32(src1 ),LP(src2 )) ); \ + OP(LP(dst+4),no_rnd_avg32(AV_RN32(src1+4),LP(src2+4)) ); \ + OP(LP(dst+8),no_rnd_avg32(AV_RN32(src1+8),LP(src2+8)) ); \ + OP(LP(dst+12),no_rnd_avg32(AV_RN32(src1+12),LP(src2+12)) ); \ src1+=src_stride1; \ src2+=src_stride2; \ dst+=dst_stride; \ @@ -118,10 +116,10 @@ static inline void OPNAME ## _no_rnd_pixels16_l2_aligned2(uint8_t *dst, const ui static inline void OPNAME ## _pixels16_l2_aligned2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \ {\ do {\ - OP(LP(dst ),rnd_avg32(LD32(src1 ),LP(src2 )) ); \ - OP(LP(dst+4),rnd_avg32(LD32(src1+4),LP(src2+4)) ); \ - OP(LP(dst+8),rnd_avg32(LD32(src1+8),LP(src2+8)) ); \ - OP(LP(dst+12),rnd_avg32(LD32(src1+12),LP(src2+12)) ); \ + OP(LP(dst ),rnd_avg32(AV_RN32(src1 ),LP(src2 )) ); \ + OP(LP(dst+4),rnd_avg32(AV_RN32(src1+4),LP(src2+4)) ); \ + OP(LP(dst+8),rnd_avg32(AV_RN32(src1+8),LP(src2+8)) ); \ + OP(LP(dst+12),rnd_avg32(AV_RN32(src1+12),LP(src2+12)) ); \ src1+=src_stride1; \ src2+=src_stride2; \ dst+=dst_stride; \ @@ -131,8 +129,8 @@ static inline void OPNAME ## _pixels16_l2_aligned2(uint8_t *dst, const uint8_t * static inline void OPNAME ## _no_rnd_pixels8_l2_aligned2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \ {\ do { /* onlye src2 aligned */\ - OP(LP(dst ),no_rnd_avg32(LD32(src1 ),LP(src2 )) ); \ - OP(LP(dst+4),no_rnd_avg32(LD32(src1+4),LP(src2+4)) ); \ + OP(LP(dst ),no_rnd_avg32(AV_RN32(src1 ),LP(src2 )) ); \ + OP(LP(dst+4),no_rnd_avg32(AV_RN32(src1+4),LP(src2+4)) ); \ src1+=src_stride1; \ src2+=src_stride2; \ dst+=dst_stride; \ @@ -142,8 +140,8 @@ static inline void OPNAME ## _no_rnd_pixels8_l2_aligned2(uint8_t *dst, const uin static inline void OPNAME ## _pixels8_l2_aligned2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, int src_stride1, int src_stride2, int h) \ {\ do {\ - OP(LP(dst ),rnd_avg32(LD32(src1 ),LP(src2 )) ); \ - OP(LP(dst+4),rnd_avg32(LD32(src1+4),LP(src2+4)) ); \ + OP(LP(dst ),rnd_avg32(AV_RN32(src1 ),LP(src2 )) ); \ + OP(LP(dst+4),rnd_avg32(AV_RN32(src1+4),LP(src2+4)) ); \ src1+=src_stride1; \ src2+=src_stride2; \ dst+=dst_stride; \ @@ -247,10 +245,10 @@ static inline void OPNAME ## _no_rnd_pixels8_l4_aligned(uint8_t *dst, const uint static inline void OPNAME ## _pixels8_l4_aligned0(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\ do { \ uint32_t a0,a1,a2,a3; /* src1 only not aligned */\ - UNPACK(a0,a1,LD32(src1),LP(src2)); \ + UNPACK(a0,a1,AV_RN32(src1),LP(src2)); \ UNPACK(a2,a3,LP(src3),LP(src4)); \ OP(LP(dst),rnd_PACK(a0,a1,a2,a3)); \ - UNPACK(a0,a1,LD32(src1+4),LP(src2+4)); \ + UNPACK(a0,a1,AV_RN32(src1+4),LP(src2+4)); \ UNPACK(a2,a3,LP(src3+4),LP(src4+4)); \ OP(LP(dst+4),rnd_PACK(a0,a1,a2,a3)); \ src1+=src_stride1;\ @@ -264,10 +262,10 @@ static inline void OPNAME ## _pixels8_l4_aligned0(uint8_t *dst, const uint8_t *s static inline void OPNAME ## _no_rnd_pixels8_l4_aligned0(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\ do { \ uint32_t a0,a1,a2,a3; \ - UNPACK(a0,a1,LD32(src1),LP(src2)); \ + UNPACK(a0,a1,AV_RN32(src1),LP(src2)); \ UNPACK(a2,a3,LP(src3),LP(src4)); \ OP(LP(dst),no_rnd_PACK(a0,a1,a2,a3)); \ - UNPACK(a0,a1,LD32(src1+4),LP(src2+4)); \ + UNPACK(a0,a1,AV_RN32(src1+4),LP(src2+4)); \ UNPACK(a2,a3,LP(src3+4),LP(src4+4)); \ OP(LP(dst+4),no_rnd_PACK(a0,a1,a2,a3)); \ src1+=src_stride1;\ @@ -327,16 +325,16 @@ static inline void OPNAME ## _no_rnd_pixels16_l4_aligned(uint8_t *dst, const uin static inline void OPNAME ## _pixels16_l4_aligned0(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\ do { /* src1 is unaligned */\ uint32_t a0,a1,a2,a3; \ - UNPACK(a0,a1,LD32(src1),LP(src2)); \ + UNPACK(a0,a1,AV_RN32(src1),LP(src2)); \ UNPACK(a2,a3,LP(src3),LP(src4)); \ OP(LP(dst),rnd_PACK(a0,a1,a2,a3)); \ - UNPACK(a0,a1,LD32(src1+4),LP(src2+4)); \ + UNPACK(a0,a1,AV_RN32(src1+4),LP(src2+4)); \ UNPACK(a2,a3,LP(src3+4),LP(src4+4)); \ OP(LP(dst+8),rnd_PACK(a0,a1,a2,a3)); \ - UNPACK(a0,a1,LD32(src1+8),LP(src2+8)); \ + UNPACK(a0,a1,AV_RN32(src1+8),LP(src2+8)); \ UNPACK(a2,a3,LP(src3+8),LP(src4+8)); \ OP(LP(dst+8),rnd_PACK(a0,a1,a2,a3)); \ - UNPACK(a0,a1,LD32(src1+12),LP(src2+12)); \ + UNPACK(a0,a1,AV_RN32(src1+12),LP(src2+12)); \ UNPACK(a2,a3,LP(src3+12),LP(src4+12)); \ OP(LP(dst+12),rnd_PACK(a0,a1,a2,a3)); \ src1+=src_stride1;\ @@ -350,16 +348,16 @@ static inline void OPNAME ## _pixels16_l4_aligned0(uint8_t *dst, const uint8_t * static inline void OPNAME ## _no_rnd_pixels16_l4_aligned0(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\ do { \ uint32_t a0,a1,a2,a3; \ - UNPACK(a0,a1,LD32(src1),LP(src2)); \ + UNPACK(a0,a1,AV_RN32(src1),LP(src2)); \ UNPACK(a2,a3,LP(src3),LP(src4)); \ OP(LP(dst),no_rnd_PACK(a0,a1,a2,a3)); \ - UNPACK(a0,a1,LD32(src1+4),LP(src2+4)); \ + UNPACK(a0,a1,AV_RN32(src1+4),LP(src2+4)); \ UNPACK(a2,a3,LP(src3+4),LP(src4+4)); \ OP(LP(dst+4),no_rnd_PACK(a0,a1,a2,a3)); \ - UNPACK(a0,a1,LD32(src1+8),LP(src2+8)); \ + UNPACK(a0,a1,AV_RN32(src1+8),LP(src2+8)); \ UNPACK(a2,a3,LP(src3+8),LP(src4+8)); \ OP(LP(dst+8),no_rnd_PACK(a0,a1,a2,a3)); \ - UNPACK(a0,a1,LD32(src1+12),LP(src2+12)); \ + UNPACK(a0,a1,AV_RN32(src1+12),LP(src2+12)); \ UNPACK(a2,a3,LP(src3+12),LP(src4+12)); \ OP(LP(dst+12),no_rnd_PACK(a0,a1,a2,a3)); \ src1+=src_stride1;\ @@ -449,19 +447,19 @@ static void gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy, + src[index+stride+1]* frac_x )* frac_y + r)>>(shift*2); }else{ - index= src_x + clip(src_y, 0, height)*stride; + index= src_x + av_clip(src_y, 0, height)*stride; dst[y*stride + x]= ( ( src[index ]*(s-frac_x) + src[index +1]* frac_x )*s + r)>>(shift*2); } }else{ if((unsigned)src_y < height){ - index= clip(src_x, 0, width) + src_y*stride; + index= av_clip(src_x, 0, width) + src_y*stride; dst[y*stride + x]= ( ( src[index ]*(s-frac_y) + src[index+stride ]* frac_y )*s + r)>>(shift*2); }else{ - index= clip(src_x, 0, width) + clip(src_y, 0, height)*stride; + index= av_clip(src_x, 0, width) + av_clip(src_y, 0, height)*stride; dst[y*stride + x]= src[index ]; } } diff --git a/contrib/ffmpeg/libavcodec/shorten.c b/contrib/ffmpeg/libavcodec/shorten.c index efb48b51d..36e0d0918 100644 --- a/contrib/ffmpeg/libavcodec/shorten.c +++ b/contrib/ffmpeg/libavcodec/shorten.c @@ -172,12 +172,12 @@ static void init_offset(ShortenContext *s) s->offset[chan][i] = mean; } -static int inline get_le32(GetBitContext *gb) +static inline int get_le32(GetBitContext *gb) { return bswap_32(get_bits_long(gb, 32)); } -static short inline get_le16(GetBitContext *gb) +static inline short get_le16(GetBitContext *gb) { return bswap_16(get_bits_long(gb, 16)); } @@ -268,7 +268,7 @@ static void decode_subframe_lpc(ShortenContext *s, int channel, int residual_siz static int shorten_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { ShortenContext *s = avctx->priv_data; int i, input_buf_size = 0; @@ -299,7 +299,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, } } init_get_bits(&s->gb, buf, buf_size*8); - get_bits(&s->gb, s->bitindex); + skip_bits(&s->gb, s->bitindex); if (!s->blocksize) { int maxnlpc = 0; @@ -345,7 +345,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, s->lpcqoffset = V2LPCQOFFSET; if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) { - av_log(s->avctx, AV_LOG_ERROR, "missing verbatim section at begining of stream\n"); + av_log(s->avctx, AV_LOG_ERROR, "missing verbatim section at beginning of stream\n"); return -1; } diff --git a/contrib/ffmpeg/libavcodec/simple_idct.c b/contrib/ffmpeg/libavcodec/simple_idct.c index dcf752e16..7bf0836aa 100644 --- a/contrib/ffmpeg/libavcodec/simple_idct.c +++ b/contrib/ffmpeg/libavcodec/simple_idct.c @@ -387,7 +387,7 @@ static inline void idctSparseCol (DCTELEM * col) col[56] = ((a0 - b0) >> COL_SHIFT); } -void simple_idct_put(uint8_t *dest, int line_size, DCTELEM *block) +void ff_simple_idct_put(uint8_t *dest, int line_size, DCTELEM *block) { int i; for(i=0; i<8; i++) @@ -397,7 +397,7 @@ void simple_idct_put(uint8_t *dest, int line_size, DCTELEM *block) idctSparseColPut(dest + i, line_size, block + i); } -void simple_idct_add(uint8_t *dest, int line_size, DCTELEM *block) +void ff_simple_idct_add(uint8_t *dest, int line_size, DCTELEM *block) { int i; for(i=0; i<8; i++) @@ -407,7 +407,7 @@ void simple_idct_add(uint8_t *dest, int line_size, DCTELEM *block) idctSparseColAdd(dest + i, line_size, block + i); } -void simple_idct(DCTELEM *block) +void ff_simple_idct(DCTELEM *block) { int i; for(i=0; i<8; i++) @@ -428,7 +428,7 @@ void simple_idct(DCTELEM *block) and the butterfly must be multiplied by 0.5 * sqrt(2.0) */ #define C_SHIFT (4+1+12) -static inline void idct4col(uint8_t *dest, int line_size, const DCTELEM *col) +static inline void idct4col_put(uint8_t *dest, int line_size, const DCTELEM *col) { int c0, c1, c2, c3, a0, a1, a2, a3; const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; @@ -465,7 +465,7 @@ static inline void idct4col(uint8_t *dest, int line_size, const DCTELEM *col) /* XXX: I think a 1.0/sqrt(2) normalization should be needed to compensate the extra butterfly stage - I don't have the full DV specification */ -void simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block) +void ff_simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block) { int i; DCTELEM *ptr; @@ -491,8 +491,8 @@ void simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block) /* IDCT4 and store */ for(i=0;i<8;i++) { - idct4col(dest + i, 2 * line_size, block + i); - idct4col(dest + line_size + i, 2 * line_size, block + 8 + i); + idct4col_put(dest + i, 2 * line_size, block + i); + idct4col_put(dest + line_size + i, 2 * line_size, block + 8 + i); } } @@ -555,7 +555,7 @@ static inline void idct4row(DCTELEM *row) row[3]= (c0 - c1) >> R_SHIFT; } -void simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block) +void ff_simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block) { int i; @@ -570,7 +570,7 @@ void simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block) } } -void simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block) +void ff_simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block) { int i; @@ -585,3 +585,17 @@ void simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block) } } +void ff_simple_idct44_add(uint8_t *dest, int line_size, DCTELEM *block) +{ + int i; + + /* IDCT4 on each line */ + for(i=0; i<4; i++) { + idct4row(block + i*8); + } + + /* IDCT4 and store */ + for(i=0; i<4; i++){ + idct4col_add(dest + i, line_size, block + i); + } +} diff --git a/contrib/ffmpeg/libavcodec/simple_idct.h b/contrib/ffmpeg/libavcodec/simple_idct.h index c4b453329..6ae48a24e 100644 --- a/contrib/ffmpeg/libavcodec/simple_idct.h +++ b/contrib/ffmpeg/libavcodec/simple_idct.h @@ -25,14 +25,23 @@ * simple idct header. */ -void simple_idct_put(uint8_t *dest, int line_size, DCTELEM *block); -void simple_idct_add(uint8_t *dest, int line_size, DCTELEM *block); +#ifndef FFMPEG_SIMPLE_IDCT_H +#define FFMPEG_SIMPLE_IDCT_H + +#include +#include "dsputil.h" + +void ff_simple_idct_put(uint8_t *dest, int line_size, DCTELEM *block); +void ff_simple_idct_add(uint8_t *dest, int line_size, DCTELEM *block); void ff_simple_idct_mmx(int16_t *block); void ff_simple_idct_add_mmx(uint8_t *dest, int line_size, int16_t *block); void ff_simple_idct_put_mmx(uint8_t *dest, int line_size, int16_t *block); -void simple_idct(DCTELEM *block); +void ff_simple_idct(DCTELEM *block); + +void ff_simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block); -void simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block); +void ff_simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block); +void ff_simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block); +void ff_simple_idct44_add(uint8_t *dest, int line_size, DCTELEM *block); -void simple_idct84_add(uint8_t *dest, int line_size, DCTELEM *block); -void simple_idct48_add(uint8_t *dest, int line_size, DCTELEM *block); +#endif /* FFMPEG_SIMPLE_IDCT_H */ diff --git a/contrib/ffmpeg/libavcodec/smacker.c b/contrib/ffmpeg/libavcodec/smacker.c index 0dd76107b..d8639383d 100644 --- a/contrib/ffmpeg/libavcodec/smacker.c +++ b/contrib/ffmpeg/libavcodec/smacker.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -32,11 +31,11 @@ #include #include -#include "common.h" #include "avcodec.h" #define ALT_BITSTREAM_READER_LE #include "bitstream.h" +#include "bytestream.h" #define SMKTREE_BITS 9 #define SMK_NODE 0x80000000 @@ -203,7 +202,7 @@ static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int if(get_bits1(gb)) { smacker_decode_tree(gb, &tmp1, 0, 0); - get_bits1(gb); + skip_bits1(gb); res = init_vlc(&vlc[0], SMKTREE_BITS, tmp1.length, tmp1.lengths, sizeof(int), sizeof(int), tmp1.bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE); @@ -216,7 +215,7 @@ static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int } if(get_bits1(gb)){ smacker_decode_tree(gb, &tmp2, 0, 0); - get_bits1(gb); + skip_bits1(gb); res = init_vlc(&vlc[1], SMKTREE_BITS, tmp2.length, tmp2.lengths, sizeof(int), sizeof(int), tmp2.bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE); @@ -252,7 +251,7 @@ static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int huff.values = av_mallocz(huff.length * sizeof(int)); smacker_decode_bigtree(gb, &huff, &ctx); - get_bits1(gb); + skip_bits1(gb); if(ctx.last[0] == -1) ctx.last[0] = huff.current++; if(ctx.last[1] == -1) ctx.last[1] = huff.current++; if(ctx.last[2] == -1) ctx.last[2] = huff.current++; @@ -292,7 +291,7 @@ static int decode_header_trees(SmackVContext *smk) { } else { smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size); } - if(!get_bits(&gb, 1)) { + if(!get_bits1(&gb)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping MCLR tree\n"); smk->mclr_tbl = av_malloc(sizeof(int) * 2); smk->mclr_tbl[0] = 0; @@ -300,7 +299,7 @@ static int decode_header_trees(SmackVContext *smk) { } else { smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size); } - if(!get_bits(&gb, 1)) { + if(!get_bits1(&gb)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping FULL tree\n"); smk->full_tbl = av_malloc(sizeof(int) * 2); smk->full_tbl[0] = 0; @@ -308,7 +307,7 @@ static int decode_header_trees(SmackVContext *smk) { } else { smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size); } - if(!get_bits(&gb, 1)) { + if(!get_bits1(&gb)) { av_log(smk->avctx, AV_LOG_INFO, "Skipping TYPE tree\n"); smk->type_tbl = av_malloc(sizeof(int) * 2); smk->type_tbl[0] = 0; @@ -346,9 +345,9 @@ static av_always_inline int smk_get_code(GetBitContext *gb, int *recode, int *la return v; } -static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size) { - SmackVContext * const smk = (SmackVContext *)avctx->priv_data; + SmackVContext * const smk = avctx->priv_data; uint8_t *out; uint32_t *pal; GetBitContext gb; @@ -356,7 +355,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 int i; int stride; - if(buf_size == 769) + if(buf_size <= 769) return 0; if(smk->pic.data[0]) avctx->release_buffer(avctx, &smk->pic); @@ -369,7 +368,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 } /* make the palette available on the way out */ - out = buf + 1; pal = (uint32_t*)smk->pic.data[1]; smk->pic.palette_has_changed = buf[0] & 1; smk->pic.key_frame = !!(buf[0] & 2); @@ -378,19 +376,16 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 else smk->pic.pict_type = FF_P_TYPE; - for(i = 0; i < 256; i++) { - int r, g, b; - r = *out++; - g = *out++; - b = *out++; - *pal++ = (r << 16) | (g << 8) | b; - } + buf++; + for(i = 0; i < 256; i++) + *pal++ = bytestream_get_be24(&buf); + buf_size -= 769; last_reset(smk->mmap_tbl, smk->mmap_last); last_reset(smk->mclr_tbl, smk->mclr_last); last_reset(smk->full_tbl, smk->full_last); last_reset(smk->type_tbl, smk->type_last); - init_get_bits(&gb, buf + 769, (buf_size - 769) * 8); + init_get_bits(&gb, buf, buf_size * 8); blk = 0; bw = avctx->width >> 2; @@ -437,11 +432,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 case 0: for(i = 0; i < 4; i++) { pix = smk_get_code(&gb, smk->full_tbl, smk->full_last); - out[2] = pix & 0xFF; - out[3] = pix >> 8; + AV_WL16(out+2,pix); pix = smk_get_code(&gb, smk->full_tbl, smk->full_last); - out[0] = pix & 0xFF; - out[1] = pix >> 8; + AV_WL16(out,pix); out += stride; } break; @@ -466,11 +459,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 uint16_t pix1, pix2; pix1 = smk_get_code(&gb, smk->full_tbl, smk->full_last); pix2 = smk_get_code(&gb, smk->full_tbl, smk->full_last); - out[0] = pix1 & 0xFF; out[1] = pix1 >> 8; - out[2] = pix2 & 0xFF; out[3] = pix2 >> 8; + AV_WL16(out,pix1); + AV_WL16(out+2,pix2); out += stride; - out[0] = pix1 & 0xFF; out[1] = pix1 >> 8; - out[2] = pix2 & 0xFF; out[3] = pix2 >> 8; + AV_WL16(out,pix1); + AV_WL16(out+2,pix2); out += stride; } break; @@ -515,10 +508,9 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 */ static int decode_init(AVCodecContext *avctx) { - SmackVContext * const c = (SmackVContext *)avctx->priv_data; + SmackVContext * const c = avctx->priv_data; c->avctx = avctx; - avctx->has_b_frames = 0; c->pic.data[0] = NULL; @@ -550,7 +542,7 @@ static int decode_init(AVCodecContext *avctx) */ static int decode_end(AVCodecContext *avctx) { - SmackVContext * const smk = (SmackVContext *)avctx->priv_data; + SmackVContext * const smk = avctx->priv_data; av_freep(&smk->mmap_tbl); av_freep(&smk->mclr_tbl); @@ -572,7 +564,7 @@ static int smka_decode_init(AVCodecContext *avctx) /** * Decode Smacker audio data */ -static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) +static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size) { GetBitContext gb; HuffContext h[4]; @@ -595,6 +587,10 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size, } stereo = get_bits1(&gb); bits = get_bits1(&gb); + if (unp_size & 0xC0000000 || (unp_size << !bits) > *data_size) { + av_log(avctx, AV_LOG_ERROR, "Frame is too large to fit in buffer\n"); + return -1; + } memset(vlc, 0, sizeof(VLC) * 4); memset(h, 0, sizeof(HuffContext) * 4); @@ -606,9 +602,9 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size, h[i].bits = av_mallocz(256 * 4); h[i].lengths = av_mallocz(256 * sizeof(int)); h[i].values = av_mallocz(256 * sizeof(int)); - get_bits1(&gb); + skip_bits1(&gb); smacker_decode_tree(&gb, &h[i], 0, 0); - get_bits1(&gb); + skip_bits1(&gb); if(h[i].current > 1) { res = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length, h[i].lengths, sizeof(int), sizeof(int), diff --git a/contrib/ffmpeg/libavcodec/smc.c b/contrib/ffmpeg/libavcodec/smc.c index 349e5f81c..f181e0c4c 100644 --- a/contrib/ffmpeg/libavcodec/smc.c +++ b/contrib/ffmpeg/libavcodec/smc.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -34,7 +33,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include "dsputil.h" @@ -50,7 +48,7 @@ typedef struct SmcContext { DSPContext dsp; AVFrame frame; - unsigned char *buf; + const unsigned char *buf; int size; /* SMC color tables */ @@ -432,11 +430,10 @@ static void smc_decode_stream(SmcContext *s) static int smc_decode_init(AVCodecContext *avctx) { - SmcContext *s = (SmcContext *)avctx->priv_data; + SmcContext *s = avctx->priv_data; s->avctx = avctx; avctx->pix_fmt = PIX_FMT_PAL8; - avctx->has_b_frames = 0; dsputil_init(&s->dsp, avctx); s->frame.data[0] = NULL; @@ -446,9 +443,9 @@ static int smc_decode_init(AVCodecContext *avctx) static int smc_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { - SmcContext *s = (SmcContext *)avctx->priv_data; + SmcContext *s = avctx->priv_data; s->buf = buf; s->size = buf_size; @@ -472,7 +469,7 @@ static int smc_decode_frame(AVCodecContext *avctx, static int smc_decode_end(AVCodecContext *avctx) { - SmcContext *s = (SmcContext *)avctx->priv_data; + SmcContext *s = avctx->priv_data; if (s->frame.data[0]) avctx->release_buffer(avctx, &s->frame); diff --git a/contrib/ffmpeg/libavcodec/snow.c b/contrib/ffmpeg/libavcodec/snow.c index dc50941fa..9fcb2d0ea 100644 --- a/contrib/ffmpeg/libavcodec/snow.c +++ b/contrib/ffmpeg/libavcodec/snow.c @@ -19,7 +19,6 @@ */ #include "avcodec.h" -#include "common.h" #include "dsputil.h" #include "snow.h" @@ -177,57 +176,57 @@ static const int8_t quant13[256]={ #if 0 //64*cubic static const uint8_t obmc32[1024]={ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, - 0, 0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8, 8, 8, 7, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1, 1, 0, 0, - 0, 0, 1, 2, 2, 3, 4, 6, 7, 8, 9,10,11,12,12,12,12,12,12,11,10, 9, 8, 7, 6, 4, 3, 2, 2, 1, 0, 0, - 0, 1, 1, 2, 3, 5, 6, 8,10,11,13,14,15,16,17,18,18,17,16,15,14,13,11,10, 8, 6, 5, 3, 2, 1, 1, 0, - 0, 1, 1, 3, 4, 6, 8,10,13,15,17,19,20,22,22,23,23,22,22,20,19,17,15,13,10, 8, 6, 4, 3, 1, 1, 0, - 0, 1, 2, 4, 6, 8,10,13,16,19,21,23,25,27,28,29,29,28,27,25,23,21,19,16,13,10, 8, 6, 4, 2, 1, 0, - 0, 1, 2, 4, 7,10,13,16,19,22,25,28,31,33,34,35,35,34,33,31,28,25,22,19,16,13,10, 7, 4, 2, 1, 0, - 0, 1, 3, 5, 8,11,15,19,22,26,30,33,36,38,40,41,41,40,38,36,33,30,26,22,19,15,11, 8, 5, 3, 1, 0, - 0, 1, 3, 6, 9,12,17,21,25,30,34,38,41,44,45,46,46,45,44,41,38,34,30,25,21,17,12, 9, 6, 3, 1, 0, - 0, 1, 3, 6,10,14,19,23,28,33,38,42,45,48,51,52,52,51,48,45,42,38,33,28,23,19,14,10, 6, 3, 1, 0, - 0, 1, 4, 7,11,15,20,25,31,36,41,45,49,52,55,56,56,55,52,49,45,41,36,31,25,20,15,11, 7, 4, 1, 0, - 0, 2, 4, 7,12,16,22,27,33,38,44,48,52,56,58,60,60,58,56,52,48,44,38,33,27,22,16,12, 7, 4, 2, 0, - 0, 1, 4, 8,12,17,22,28,34,40,45,51,55,58,61,62,62,61,58,55,51,45,40,34,28,22,17,12, 8, 4, 1, 0, - 0, 2, 4, 8,12,18,23,29,35,41,46,52,56,60,62,64,64,62,60,56,52,46,41,35,29,23,18,12, 8, 4, 2, 0, - 0, 2, 4, 8,12,18,23,29,35,41,46,52,56,60,62,64,64,62,60,56,52,46,41,35,29,23,18,12, 8, 4, 2, 0, - 0, 1, 4, 8,12,17,22,28,34,40,45,51,55,58,61,62,62,61,58,55,51,45,40,34,28,22,17,12, 8, 4, 1, 0, - 0, 2, 4, 7,12,16,22,27,33,38,44,48,52,56,58,60,60,58,56,52,48,44,38,33,27,22,16,12, 7, 4, 2, 0, - 0, 1, 4, 7,11,15,20,25,31,36,41,45,49,52,55,56,56,55,52,49,45,41,36,31,25,20,15,11, 7, 4, 1, 0, - 0, 1, 3, 6,10,14,19,23,28,33,38,42,45,48,51,52,52,51,48,45,42,38,33,28,23,19,14,10, 6, 3, 1, 0, - 0, 1, 3, 6, 9,12,17,21,25,30,34,38,41,44,45,46,46,45,44,41,38,34,30,25,21,17,12, 9, 6, 3, 1, 0, - 0, 1, 3, 5, 8,11,15,19,22,26,30,33,36,38,40,41,41,40,38,36,33,30,26,22,19,15,11, 8, 5, 3, 1, 0, - 0, 1, 2, 4, 7,10,13,16,19,22,25,28,31,33,34,35,35,34,33,31,28,25,22,19,16,13,10, 7, 4, 2, 1, 0, - 0, 1, 2, 4, 6, 8,10,13,16,19,21,23,25,27,28,29,29,28,27,25,23,21,19,16,13,10, 8, 6, 4, 2, 1, 0, - 0, 1, 1, 3, 4, 6, 8,10,13,15,17,19,20,22,22,23,23,22,22,20,19,17,15,13,10, 8, 6, 4, 3, 1, 1, 0, - 0, 1, 1, 2, 3, 5, 6, 8,10,11,13,14,15,16,17,18,18,17,16,15,14,13,11,10, 8, 6, 5, 3, 2, 1, 1, 0, - 0, 0, 1, 2, 2, 3, 4, 6, 7, 8, 9,10,11,12,12,12,12,12,12,11,10, 9, 8, 7, 6, 4, 3, 2, 2, 1, 0, 0, - 0, 0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 7, 8, 8, 8, 8, 7, 7, 6, 6, 5, 4, 4, 3, 2, 2, 1, 1, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, + 0, 0, 0, 4, 4, 4, 4, 8, 8, 12, 12, 12, 16, 16, 16, 16, 16, 16, 16, 16, 12, 12, 12, 8, 8, 4, 4, 4, 4, 0, 0, 0, + 0, 0, 4, 4, 8, 8, 12, 16, 16, 20, 24, 24, 28, 28, 32, 32, 32, 32, 28, 28, 24, 24, 20, 16, 16, 12, 8, 8, 4, 4, 0, 0, + 0, 0, 4, 8, 8, 12, 16, 24, 28, 32, 36, 40, 44, 48, 48, 48, 48, 48, 48, 44, 40, 36, 32, 28, 24, 16, 12, 8, 8, 4, 0, 0, + 0, 4, 4, 8, 12, 20, 24, 32, 40, 44, 52, 56, 60, 64, 68, 72, 72, 68, 64, 60, 56, 52, 44, 40, 32, 24, 20, 12, 8, 4, 4, 0, + 0, 4, 4, 12, 16, 24, 32, 40, 52, 60, 68, 76, 80, 88, 88, 92, 92, 88, 88, 80, 76, 68, 60, 52, 40, 32, 24, 16, 12, 4, 4, 0, + 0, 4, 8, 16, 24, 32, 40, 52, 64, 76, 84, 92,100,108,112,116,116,112,108,100, 92, 84, 76, 64, 52, 40, 32, 24, 16, 8, 4, 0, + 0, 4, 8, 16, 28, 40, 52, 64, 76, 88,100,112,124,132,136,140,140,136,132,124,112,100, 88, 76, 64, 52, 40, 28, 16, 8, 4, 0, + 0, 4, 12, 20, 32, 44, 60, 76, 88,104,120,132,144,152,160,164,164,160,152,144,132,120,104, 88, 76, 60, 44, 32, 20, 12, 4, 0, + 0, 4, 12, 24, 36, 48, 68, 84,100,120,136,152,164,176,180,184,184,180,176,164,152,136,120,100, 84, 68, 48, 36, 24, 12, 4, 0, + 0, 4, 12, 24, 40, 56, 76, 92,112,132,152,168,180,192,204,208,208,204,192,180,168,152,132,112, 92, 76, 56, 40, 24, 12, 4, 0, + 0, 4, 16, 28, 44, 60, 80,100,124,144,164,180,196,208,220,224,224,220,208,196,180,164,144,124,100, 80, 60, 44, 28, 16, 4, 0, + 0, 8, 16, 28, 48, 64, 88,108,132,152,176,192,208,224,232,240,240,232,224,208,192,176,152,132,108, 88, 64, 48, 28, 16, 8, 0, + 0, 4, 16, 32, 48, 68, 88,112,136,160,180,204,220,232,244,248,248,244,232,220,204,180,160,136,112, 88, 68, 48, 32, 16, 4, 0, + 1, 8, 16, 32, 48, 72, 92,116,140,164,184,208,224,240,248,255,255,248,240,224,208,184,164,140,116, 92, 72, 48, 32, 16, 8, 1, + 1, 8, 16, 32, 48, 72, 92,116,140,164,184,208,224,240,248,255,255,248,240,224,208,184,164,140,116, 92, 72, 48, 32, 16, 8, 1, + 0, 4, 16, 32, 48, 68, 88,112,136,160,180,204,220,232,244,248,248,244,232,220,204,180,160,136,112, 88, 68, 48, 32, 16, 4, 0, + 0, 8, 16, 28, 48, 64, 88,108,132,152,176,192,208,224,232,240,240,232,224,208,192,176,152,132,108, 88, 64, 48, 28, 16, 8, 0, + 0, 4, 16, 28, 44, 60, 80,100,124,144,164,180,196,208,220,224,224,220,208,196,180,164,144,124,100, 80, 60, 44, 28, 16, 4, 0, + 0, 4, 12, 24, 40, 56, 76, 92,112,132,152,168,180,192,204,208,208,204,192,180,168,152,132,112, 92, 76, 56, 40, 24, 12, 4, 0, + 0, 4, 12, 24, 36, 48, 68, 84,100,120,136,152,164,176,180,184,184,180,176,164,152,136,120,100, 84, 68, 48, 36, 24, 12, 4, 0, + 0, 4, 12, 20, 32, 44, 60, 76, 88,104,120,132,144,152,160,164,164,160,152,144,132,120,104, 88, 76, 60, 44, 32, 20, 12, 4, 0, + 0, 4, 8, 16, 28, 40, 52, 64, 76, 88,100,112,124,132,136,140,140,136,132,124,112,100, 88, 76, 64, 52, 40, 28, 16, 8, 4, 0, + 0, 4, 8, 16, 24, 32, 40, 52, 64, 76, 84, 92,100,108,112,116,116,112,108,100, 92, 84, 76, 64, 52, 40, 32, 24, 16, 8, 4, 0, + 0, 4, 4, 12, 16, 24, 32, 40, 52, 60, 68, 76, 80, 88, 88, 92, 92, 88, 88, 80, 76, 68, 60, 52, 40, 32, 24, 16, 12, 4, 4, 0, + 0, 4, 4, 8, 12, 20, 24, 32, 40, 44, 52, 56, 60, 64, 68, 72, 72, 68, 64, 60, 56, 52, 44, 40, 32, 24, 20, 12, 8, 4, 4, 0, + 0, 0, 4, 8, 8, 12, 16, 24, 28, 32, 36, 40, 44, 48, 48, 48, 48, 48, 48, 44, 40, 36, 32, 28, 24, 16, 12, 8, 8, 4, 0, 0, + 0, 0, 4, 4, 8, 8, 12, 16, 16, 20, 24, 24, 28, 28, 32, 32, 32, 32, 28, 28, 24, 24, 20, 16, 16, 12, 8, 8, 4, 4, 0, 0, + 0, 0, 0, 4, 4, 4, 4, 8, 8, 12, 12, 12, 16, 16, 16, 16, 16, 16, 16, 16, 12, 12, 12, 8, 8, 4, 4, 4, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //error:0.000022 }; static const uint8_t obmc16[256]={ - 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, - 0, 1, 1, 2, 4, 5, 5, 6, 6, 5, 5, 4, 2, 1, 1, 0, - 0, 1, 4, 6, 9,11,13,15,15,13,11, 9, 6, 4, 1, 0, - 0, 2, 6,11,15,20,24,26,26,24,20,15,11, 6, 2, 0, - 0, 4, 9,15,23,29,34,38,38,34,29,23,15, 9, 4, 0, - 0, 5,11,20,29,38,45,49,49,45,38,29,20,11, 5, 0, - 1, 5,13,24,34,45,53,57,57,53,45,34,24,13, 5, 1, - 1, 6,15,26,38,49,57,62,62,57,49,38,26,15, 6, 1, - 1, 6,15,26,38,49,57,62,62,57,49,38,26,15, 6, 1, - 1, 5,13,24,34,45,53,57,57,53,45,34,24,13, 5, 1, - 0, 5,11,20,29,38,45,49,49,45,38,29,20,11, 5, 0, - 0, 4, 9,15,23,29,34,38,38,34,29,23,15, 9, 4, 0, - 0, 2, 6,11,15,20,24,26,26,24,20,15,11, 6, 2, 0, - 0, 1, 4, 6, 9,11,13,15,15,13,11, 9, 6, 4, 1, 0, - 0, 1, 1, 2, 4, 5, 5, 6, 6, 5, 5, 4, 2, 1, 1, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, + 0, 4, 4, 8, 16, 20, 20, 24, 24, 20, 20, 16, 8, 4, 4, 0, + 0, 4, 16, 24, 36, 44, 52, 60, 60, 52, 44, 36, 24, 16, 4, 0, + 0, 8, 24, 44, 60, 80, 96,104,104, 96, 80, 60, 44, 24, 8, 0, + 0, 16, 36, 60, 92,116,136,152,152,136,116, 92, 60, 36, 16, 0, + 0, 20, 44, 80,116,152,180,196,196,180,152,116, 80, 44, 20, 0, + 4, 20, 52, 96,136,180,212,228,228,212,180,136, 96, 52, 20, 4, + 4, 24, 60,104,152,196,228,248,248,228,196,152,104, 60, 24, 4, + 4, 24, 60,104,152,196,228,248,248,228,196,152,104, 60, 24, 4, + 4, 20, 52, 96,136,180,212,228,228,212,180,136, 96, 52, 20, 4, + 0, 20, 44, 80,116,152,180,196,196,180,152,116, 80, 44, 20, 0, + 0, 16, 36, 60, 92,116,136,152,152,136,116, 92, 60, 36, 16, 0, + 0, 8, 24, 44, 60, 80, 96,104,104, 96, 80, 60, 44, 24, 8, 0, + 0, 4, 16, 24, 36, 44, 52, 60, 60, 52, 44, 36, 24, 16, 4, 0, + 0, 4, 4, 8, 16, 20, 20, 24, 24, 20, 20, 16, 8, 4, 4, 0, + 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, //error:0.000033 }; #elif 1 // 64*linear @@ -287,60 +286,60 @@ static const uint8_t obmc16[256]={ }; #else //64*cos static const uint8_t obmc32[1024]={ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, - 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, - 0, 0, 1, 1, 2, 3, 4, 5, 6, 7, 9,10,11,11,12,12,12,12,11,11,10, 9, 7, 6, 5, 4, 3, 2, 1, 1, 0, 0, - 0, 0, 1, 2, 3, 5, 6, 8, 9,11,12,14,15,16,17,17,17,17,16,15,14,12,11, 9, 8, 6, 5, 3, 2, 1, 0, 0, - 0, 1, 1, 2, 4, 6, 8,10,12,15,17,19,20,21,22,23,23,22,21,20,19,17,15,12,10, 8, 6, 4, 2, 1, 1, 0, - 0, 1, 2, 3, 5, 8,10,13,16,19,21,24,26,27,28,29,29,28,27,26,24,21,19,16,13,10, 8, 5, 3, 2, 1, 0, - 0, 1, 2, 4, 6, 9,12,16,19,23,26,29,31,33,34,35,35,34,33,31,29,26,23,19,16,12, 9, 6, 4, 2, 1, 0, - 0, 1, 3, 5, 7,11,15,19,23,26,30,34,37,39,40,41,41,40,39,37,34,30,26,23,19,15,11, 7, 5, 3, 1, 0, - 0, 1, 3, 5, 9,12,17,21,26,30,35,38,42,44,46,47,47,46,44,42,38,35,30,26,21,17,12, 9, 5, 3, 1, 0, - 0, 1, 3, 6, 9,14,19,24,29,34,38,43,46,49,51,52,52,51,49,46,43,38,34,29,24,19,14, 9, 6, 3, 1, 0, - 0, 1, 3, 6,11,15,20,26,31,37,42,46,50,53,56,57,57,56,53,50,46,42,37,31,26,20,15,11, 6, 3, 1, 0, - 0, 1, 3, 7,11,16,21,27,33,39,44,49,53,57,59,60,60,59,57,53,49,44,39,33,27,21,16,11, 7, 3, 1, 0, - 0, 1, 4, 7,12,17,22,28,34,40,46,51,56,59,61,63,63,61,59,56,51,46,40,34,28,22,17,12, 7, 4, 1, 0, - 0, 1, 4, 7,12,17,23,29,35,41,47,52,57,60,63,64,64,63,60,57,52,47,41,35,29,23,17,12, 7, 4, 1, 0, - 0, 1, 4, 7,12,17,23,29,35,41,47,52,57,60,63,64,64,63,60,57,52,47,41,35,29,23,17,12, 7, 4, 1, 0, - 0, 1, 4, 7,12,17,22,28,34,40,46,51,56,59,61,63,63,61,59,56,51,46,40,34,28,22,17,12, 7, 4, 1, 0, - 0, 1, 3, 7,11,16,21,27,33,39,44,49,53,57,59,60,60,59,57,53,49,44,39,33,27,21,16,11, 7, 3, 1, 0, - 0, 1, 3, 6,11,15,20,26,31,37,42,46,50,53,56,57,57,56,53,50,46,42,37,31,26,20,15,11, 6, 3, 1, 0, - 0, 1, 3, 6, 9,14,19,24,29,34,38,43,46,49,51,52,52,51,49,46,43,38,34,29,24,19,14, 9, 6, 3, 1, 0, - 0, 1, 3, 5, 9,12,17,21,26,30,35,38,42,44,46,47,47,46,44,42,38,35,30,26,21,17,12, 9, 5, 3, 1, 0, - 0, 1, 3, 5, 7,11,15,19,23,26,30,34,37,39,40,41,41,40,39,37,34,30,26,23,19,15,11, 7, 5, 3, 1, 0, - 0, 1, 2, 4, 6, 9,12,16,19,23,26,29,31,33,34,35,35,34,33,31,29,26,23,19,16,12, 9, 6, 4, 2, 1, 0, - 0, 1, 2, 3, 5, 8,10,13,16,19,21,24,26,27,28,29,29,28,27,26,24,21,19,16,13,10, 8, 5, 3, 2, 1, 0, - 0, 1, 1, 2, 4, 6, 8,10,12,15,17,19,20,21,22,23,23,22,21,20,19,17,15,12,10, 8, 6, 4, 2, 1, 1, 0, - 0, 0, 1, 2, 3, 5, 6, 8, 9,11,12,14,15,16,17,17,17,17,16,15,14,12,11, 9, 8, 6, 5, 3, 2, 1, 0, 0, - 0, 0, 1, 1, 2, 3, 4, 5, 6, 7, 9,10,11,11,12,12,12,12,11,11,10, 9, 7, 6, 5, 4, 3, 2, 1, 1, 0, 0, - 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, - 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 4, 4, 4, 4, 8, 8, 12, 12, 12, 12, 16, 16, 16, 16, 16, 16, 12, 12, 12, 12, 8, 8, 4, 4, 4, 4, 0, 0, 0, + 0, 0, 4, 4, 4, 8, 8, 12, 16, 20, 20, 24, 28, 28, 28, 28, 28, 28, 28, 28, 24, 20, 20, 16, 12, 8, 8, 4, 4, 4, 0, 0, + 0, 0, 4, 4, 8, 12, 16, 20, 24, 28, 36, 40, 44, 44, 48, 48, 48, 48, 44, 44, 40, 36, 28, 24, 20, 16, 12, 8, 4, 4, 0, 0, + 0, 0, 4, 8, 12, 20, 24, 32, 36, 44, 48, 56, 60, 64, 68, 68, 68, 68, 64, 60, 56, 48, 44, 36, 32, 24, 20, 12, 8, 4, 0, 0, + 0, 4, 4, 8, 16, 24, 32, 40, 48, 60, 68, 76, 80, 84, 88, 92, 92, 88, 84, 80, 76, 68, 60, 48, 40, 32, 24, 16, 8, 4, 4, 0, + 0, 4, 8, 12, 20, 32, 40, 52, 64, 76, 84, 96,104,108,112,116,116,112,108,104, 96, 84, 76, 64, 52, 40, 32, 20, 12, 8, 4, 0, + 0, 4, 8, 16, 24, 36, 48, 64, 76, 92,104,116,124,132,136,140,140,136,132,124,116,104, 92, 76, 64, 48, 36, 24, 16, 8, 4, 0, + 0, 4, 12, 20, 28, 44, 60, 76, 92,104,120,136,148,156,160,164,164,160,156,148,136,120,104, 92, 76, 60, 44, 28, 20, 12, 4, 0, + 0, 4, 12, 20, 36, 48, 68, 84,104,120,140,152,168,176,184,188,188,184,176,168,152,140,120,104, 84, 68, 48, 36, 20, 12, 4, 0, + 0, 4, 12, 24, 36, 56, 76, 96,116,136,152,172,184,196,204,208,208,204,196,184,172,152,136,116, 96, 76, 56, 36, 24, 12, 4, 0, + 0, 4, 12, 24, 44, 60, 80,104,124,148,168,184,200,212,224,228,228,224,212,200,184,168,148,124,104, 80, 60, 44, 24, 12, 4, 0, + 0, 4, 12, 28, 44, 64, 84,108,132,156,176,196,212,228,236,240,240,236,228,212,196,176,156,132,108, 84, 64, 44, 28, 12, 4, 0, + 0, 4, 16, 28, 48, 68, 88,112,136,160,184,204,224,236,244,252,252,244,236,224,204,184,160,136,112, 88, 68, 48, 28, 16, 4, 0, + 1, 4, 16, 28, 48, 68, 92,116,140,164,188,208,228,240,252,255,255,252,240,228,208,188,164,140,116, 92, 68, 48, 28, 16, 4, 1, + 1, 4, 16, 28, 48, 68, 92,116,140,164,188,208,228,240,252,255,255,252,240,228,208,188,164,140,116, 92, 68, 48, 28, 16, 4, 1, + 0, 4, 16, 28, 48, 68, 88,112,136,160,184,204,224,236,244,252,252,244,236,224,204,184,160,136,112, 88, 68, 48, 28, 16, 4, 0, + 0, 4, 12, 28, 44, 64, 84,108,132,156,176,196,212,228,236,240,240,236,228,212,196,176,156,132,108, 84, 64, 44, 28, 12, 4, 0, + 0, 4, 12, 24, 44, 60, 80,104,124,148,168,184,200,212,224,228,228,224,212,200,184,168,148,124,104, 80, 60, 44, 24, 12, 4, 0, + 0, 4, 12, 24, 36, 56, 76, 96,116,136,152,172,184,196,204,208,208,204,196,184,172,152,136,116, 96, 76, 56, 36, 24, 12, 4, 0, + 0, 4, 12, 20, 36, 48, 68, 84,104,120,140,152,168,176,184,188,188,184,176,168,152,140,120,104, 84, 68, 48, 36, 20, 12, 4, 0, + 0, 4, 12, 20, 28, 44, 60, 76, 92,104,120,136,148,156,160,164,164,160,156,148,136,120,104, 92, 76, 60, 44, 28, 20, 12, 4, 0, + 0, 4, 8, 16, 24, 36, 48, 64, 76, 92,104,116,124,132,136,140,140,136,132,124,116,104, 92, 76, 64, 48, 36, 24, 16, 8, 4, 0, + 0, 4, 8, 12, 20, 32, 40, 52, 64, 76, 84, 96,104,108,112,116,116,112,108,104, 96, 84, 76, 64, 52, 40, 32, 20, 12, 8, 4, 0, + 0, 4, 4, 8, 16, 24, 32, 40, 48, 60, 68, 76, 80, 84, 88, 92, 92, 88, 84, 80, 76, 68, 60, 48, 40, 32, 24, 16, 8, 4, 4, 0, + 0, 0, 4, 8, 12, 20, 24, 32, 36, 44, 48, 56, 60, 64, 68, 68, 68, 68, 64, 60, 56, 48, 44, 36, 32, 24, 20, 12, 8, 4, 0, 0, + 0, 0, 4, 4, 8, 12, 16, 20, 24, 28, 36, 40, 44, 44, 48, 48, 48, 48, 44, 44, 40, 36, 28, 24, 20, 16, 12, 8, 4, 4, 0, 0, + 0, 0, 4, 4, 4, 8, 8, 12, 16, 20, 20, 24, 28, 28, 28, 28, 28, 28, 28, 28, 24, 20, 20, 16, 12, 8, 8, 4, 4, 4, 0, 0, + 0, 0, 0, 4, 4, 4, 4, 8, 8, 12, 12, 12, 12, 16, 16, 16, 16, 16, 16, 12, 12, 12, 12, 8, 8, 4, 4, 4, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //error:0.000022 }; static const uint8_t obmc16[256]={ - 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, - 0, 0, 1, 2, 3, 4, 5, 5, 5, 5, 4, 3, 2, 1, 0, 0, - 0, 1, 3, 6, 8,11,13,14,14,13,11, 8, 6, 3, 1, 0, - 0, 2, 6,10,15,20,24,26,26,24,20,15,10, 6, 2, 0, - 0, 3, 8,16,23,30,35,38,38,35,30,23,16, 8, 3, 0, - 1, 4,11,20,30,39,46,49,49,46,39,30,20,11, 4, 1, - 1, 5,13,24,35,46,54,58,58,54,46,35,24,13, 5, 1, - 0, 5,14,26,38,49,58,63,63,58,49,38,26,14, 5, 0, - 0, 5,14,26,38,49,58,63,63,58,49,38,26,14, 5, 0, - 1, 5,13,24,35,46,54,58,58,54,46,35,24,13, 5, 1, - 1, 4,11,20,30,39,46,49,49,46,39,30,20,11, 4, 1, - 0, 3, 8,16,23,30,35,38,38,35,30,23,16, 8, 3, 0, - 0, 2, 6,10,15,20,24,26,26,24,20,15,10, 6, 2, 0, - 0, 1, 3, 6, 8,11,13,14,14,13,11, 8, 6, 3, 1, 0, - 0, 0, 1, 2, 3, 4, 5, 5, 5, 5, 4, 3, 2, 1, 0, 0, - 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, + 0, 0, 4, 8, 12, 16, 20, 20, 20, 20, 16, 12, 8, 4, 0, 0, + 0, 4, 12, 24, 32, 44, 52, 56, 56, 52, 44, 32, 24, 12, 4, 0, + 0, 8, 24, 40, 60, 80, 96,104,104, 96, 80, 60, 40, 24, 8, 0, + 0, 12, 32, 64, 92,120,140,152,152,140,120, 92, 64, 32, 12, 0, + 4, 16, 44, 80,120,156,184,196,196,184,156,120, 80, 44, 16, 4, + 4, 20, 52, 96,140,184,216,232,232,216,184,140, 96, 52, 20, 4, + 0, 20, 56,104,152,196,232,252,252,232,196,152,104, 56, 20, 0, + 0, 20, 56,104,152,196,232,252,252,232,196,152,104, 56, 20, 0, + 4, 20, 52, 96,140,184,216,232,232,216,184,140, 96, 52, 20, 4, + 4, 16, 44, 80,120,156,184,196,196,184,156,120, 80, 44, 16, 4, + 0, 12, 32, 64, 92,120,140,152,152,140,120, 92, 64, 32, 12, 0, + 0, 8, 24, 40, 60, 80, 96,104,104, 96, 80, 60, 40, 24, 8, 0, + 0, 4, 12, 24, 32, 44, 52, 56, 56, 52, 44, 32, 24, 12, 4, 0, + 0, 0, 4, 8, 12, 16, 20, 20, 20, 20, 16, 12, 8, 4, 0, 0, + 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, //error:0.000022 }; -#endif +#endif /* 0 */ //linear *64 static const uint8_t obmc8[64]={ @@ -394,6 +393,8 @@ static const BlockNode null_block= { //FIXME add border maybe #define LOG2_MB_SIZE 4 #define MB_SIZE (1<line_count = line_count; buf->line_width = line_width; buf->data_count = max_allocated_lines; - buf->line = (DWTELEM * *) av_mallocz (sizeof(DWTELEM *) * line_count); - buf->data_stack = (DWTELEM * *) av_malloc (sizeof(DWTELEM *) * max_allocated_lines); + buf->line = av_mallocz (sizeof(IDWTELEM *) * line_count); + buf->data_stack = av_malloc (sizeof(IDWTELEM *) * max_allocated_lines); for (i = 0; i < max_allocated_lines; i++) { - buf->data_stack[i] = (DWTELEM *) av_malloc (sizeof(DWTELEM) * line_width); + buf->data_stack[i] = av_malloc (sizeof(IDWTELEM) * line_width); } buf->data_stack_top = max_allocated_lines - 1; } -static DWTELEM * slice_buffer_load_line(slice_buffer * buf, int line) +static IDWTELEM * slice_buffer_load_line(slice_buffer * buf, int line) { int offset; - DWTELEM * buffer; - -// av_log(NULL, AV_LOG_DEBUG, "Cache hit: %d\n", line); + IDWTELEM * buffer; assert(buf->data_stack_top >= 0); // assert(!buf->line[line]); @@ -525,15 +537,13 @@ static DWTELEM * slice_buffer_load_line(slice_buffer * buf, int line) buf->data_stack_top--; buf->line[line] = buffer; -// av_log(NULL, AV_LOG_DEBUG, "slice_buffer_load_line: line: %d remaining: %d\n", line, buf->data_stack_top + 1); - return buffer; } static void slice_buffer_release(slice_buffer * buf, int line) { int offset; - DWTELEM * buffer; + IDWTELEM * buffer; assert(line >= 0 && line < buf->line_count); assert(buf->line[line]); @@ -543,8 +553,6 @@ static void slice_buffer_release(slice_buffer * buf, int line) buf->data_stack_top++; buf->data_stack[buf->data_stack_top] = buffer; buf->line[line] = NULL; - -// av_log(NULL, AV_LOG_DEBUG, "slice_buffer_release: line: %d remaining: %d\n", line, buf->data_stack_top + 1); } static void slice_buffer_flush(slice_buffer * buf) @@ -553,10 +561,7 @@ static void slice_buffer_flush(slice_buffer * buf) for (i = 0; i < buf->line_count; i++) { if (buf->line[i]) - { -// av_log(NULL, AV_LOG_DEBUG, "slice_buffer_flush: line: %d \n", i); slice_buffer_release(buf, i); - } } } @@ -567,12 +572,9 @@ static void slice_buffer_destroy(slice_buffer * buf) for (i = buf->data_count - 1; i >= 0; i--) { - assert(buf->data_stack[i]); av_freep(&buf->data_stack[i]); } - assert(buf->data_stack); av_freep(&buf->data_stack); - assert(buf->line); av_freep(&buf->line); } @@ -646,7 +648,7 @@ static inline void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signe if(is_signed) put_rac(c, state+11 + FFMIN(e,10), v < 0); //11..21 } -#endif +#endif /* 1 */ }else{ put_rac(c, state+0, 1); } @@ -714,7 +716,11 @@ static inline int get_symbol2(RangeCoder *c, uint8_t *state, int log2){ return v; } -static av_always_inline void lift(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, int dst_step, int src_step, int ref_step, int width, int mul, int add, int shift, int highpass, int inverse){ +static av_always_inline void +lift(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, + int dst_step, int src_step, int ref_step, + int width, int mul, int add, int shift, + int highpass, int inverse){ const int mirror_left= !highpass; const int mirror_right= (width&1) ^ highpass; const int w= (width>>1) - 1 + (highpass & width); @@ -728,55 +734,68 @@ static av_always_inline void lift(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, int } for(i=0; i>shift), inverse); + dst[i*dst_step] = + LIFT(src[i*src_step], + ((mul*(ref[i*ref_step] + ref[(i+1)*ref_step])+add)>>shift), + inverse); } if(mirror_right){ - dst[w*dst_step] = LIFT(src[w*src_step], ((mul*2*ref[w*ref_step]+add)>>shift), inverse); + dst[w*dst_step] = + LIFT(src[w*src_step], + ((mul*2*ref[w*ref_step]+add)>>shift), + inverse); } } -#ifndef lift5 -static av_always_inline void lift5(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, int dst_step, int src_step, int ref_step, int width, int mul, int add, int shift, int highpass, int inverse){ +static av_always_inline void +inv_lift(IDWTELEM *dst, IDWTELEM *src, IDWTELEM *ref, + int dst_step, int src_step, int ref_step, + int width, int mul, int add, int shift, + int highpass, int inverse){ const int mirror_left= !highpass; const int mirror_right= (width&1) ^ highpass; const int w= (width>>1) - 1 + (highpass & width); int i; +#define LIFT(src, ref, inv) ((src) + ((inv) ? - (ref) : + (ref))) if(mirror_left){ - int r= 3*2*ref[0]; - r += r>>4; - r += r>>8; - dst[0] = LIFT(src[0], ((r+add)>>shift), inverse); + dst[0] = LIFT(src[0], ((mul*2*ref[0]+add)>>shift), inverse); dst += dst_step; src += src_step; } for(i=0; i>4; - r += r>>8; - dst[i*dst_step] = LIFT(src[i*src_step], ((r+add)>>shift), inverse); + dst[i*dst_step] = + LIFT(src[i*src_step], + ((mul*(ref[i*ref_step] + ref[(i+1)*ref_step])+add)>>shift), + inverse); } if(mirror_right){ - int r= 3*2*ref[w*ref_step]; - r += r>>4; - r += r>>8; - dst[w*dst_step] = LIFT(src[w*src_step], ((r+add)>>shift), inverse); + dst[w*dst_step] = + LIFT(src[w*src_step], + ((mul*2*ref[w*ref_step]+add)>>shift), + inverse); } } -#endif #ifndef liftS -static av_always_inline void liftS(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, int dst_step, int src_step, int ref_step, int width, int mul, int add, int shift, int highpass, int inverse){ +static av_always_inline void +liftS(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, + int dst_step, int src_step, int ref_step, + int width, int mul, int add, int shift, + int highpass, int inverse){ const int mirror_left= !highpass; const int mirror_right= (width&1) ^ highpass; const int w= (width>>1) - 1 + (highpass & width); int i; assert(shift == 4); -#define LIFTS(src, ref, inv) ((inv) ? (src) - (((ref) - 4*(src))>>shift): (16*4*(src) + 4*(ref) + 8 + (5<<27))/(5*16) - (1<<23)) +#define LIFTS(src, ref, inv) \ + ((inv) ? \ + (src) + (((ref) + 4*(src))>>shift): \ + -((-16*(src) + (ref) + add/4 + 1 + (5<<25))/(5*4) - (1<<23))) if(mirror_left){ dst[0] = LIFTS(src[0], mul*2*ref[0]+add, inverse); dst += dst_step; @@ -784,242 +803,51 @@ static av_always_inline void liftS(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, int } for(i=0; i=width) x2= 2*width-x2-2; - sum += coeffs[i]*(int64_t)dst[x2]; - } - if(inverse) dst[x] -= (sum + (1<>shift; - else dst[x] += (sum + (1<>shift; - } -} - -static void inplace_liftV(DWTELEM *dst, int width, int height, int stride, int *coeffs, int n, int shift, int start, int inverse){ - int x, y, i; - for(y=start; y=height) y2= 2*height-y2-2; - sum += coeffs[i]*(int64_t)dst[x + y2*stride]; - } - if(inverse) dst[x + y*stride] -= (sum + (1<>shift; - else dst[x + y*stride] += (sum + (1<>shift; - } - } -} - -#define SCALEX 1 -#define LX0 0 -#define LX1 1 - -#if 0 // more accurate 9/7 -#define N1 2 -#define SHIFT1 14 -#define COEFFS1 (int[]){-25987,-25987} -#define N2 2 -#define SHIFT2 19 -#define COEFFS2 (int[]){-27777,-27777} -#define N3 2 -#define SHIFT3 15 -#define COEFFS3 (int[]){28931,28931} -#define N4 2 -#define SHIFT4 15 -#define COEFFS4 (int[]){14533,14533} -#elif 1 // 13/7 CRF -#define N1 4 -#define SHIFT1 4 -#define COEFFS1 (int[]){1,-9,-9,1} -#define N2 4 -#define SHIFT2 4 -#define COEFFS2 (int[]){-1,5,5,-1} -#define N3 0 -#define SHIFT3 1 -#define COEFFS3 NULL -#define N4 0 -#define SHIFT4 1 -#define COEFFS4 NULL -#elif 1 // 3/5 -#define LX0 1 -#define LX1 0 -#define SCALEX 0.5 -#define N1 2 -#define SHIFT1 1 -#define COEFFS1 (int[]){1,1} -#define N2 2 -#define SHIFT2 2 -#define COEFFS2 (int[]){-1,-1} -#define N3 0 -#define SHIFT3 0 -#define COEFFS3 NULL -#define N4 0 -#define SHIFT4 0 -#define COEFFS4 NULL -#elif 1 // 11/5 -#define N1 0 -#define SHIFT1 1 -#define COEFFS1 NULL -#define N2 2 -#define SHIFT2 2 -#define COEFFS2 (int[]){-1,-1} -#define N3 2 -#define SHIFT3 0 -#define COEFFS3 (int[]){-1,-1} -#define N4 4 -#define SHIFT4 7 -#define COEFFS4 (int[]){-5,29,29,-5} -#define SCALEX 4 -#elif 1 // 9/7 CDF -#define N1 2 -#define SHIFT1 7 -#define COEFFS1 (int[]){-203,-203} -#define N2 2 -#define SHIFT2 12 -#define COEFFS2 (int[]){-217,-217} -#define N3 2 -#define SHIFT3 7 -#define COEFFS3 (int[]){113,113} -#define N4 2 -#define SHIFT4 9 -#define COEFFS4 (int[]){227,227} -#define SCALEX 1 -#elif 1 // 7/5 CDF -#define N1 0 -#define SHIFT1 1 -#define COEFFS1 NULL -#define N2 2 -#define SHIFT2 2 -#define COEFFS2 (int[]){-1,-1} -#define N3 2 -#define SHIFT3 0 -#define COEFFS3 (int[]){-1,-1} -#define N4 2 -#define SHIFT4 4 -#define COEFFS4 (int[]){3,3} -#elif 1 // 9/7 MN -#define N1 4 -#define SHIFT1 4 -#define COEFFS1 (int[]){1,-9,-9,1} -#define N2 2 -#define SHIFT2 2 -#define COEFFS2 (int[]){1,1} -#define N3 0 -#define SHIFT3 1 -#define COEFFS3 NULL -#define N4 0 -#define SHIFT4 1 -#define COEFFS4 NULL -#else // 13/7 CRF -#define N1 4 -#define SHIFT1 4 -#define COEFFS1 (int[]){1,-9,-9,1} -#define N2 4 -#define SHIFT2 4 -#define COEFFS2 (int[]){-1,5,5,-1} -#define N3 0 -#define SHIFT3 1 -#define COEFFS3 NULL -#define N4 0 -#define SHIFT4 1 -#define COEFFS4 NULL -#endif -static void horizontal_decomposeX(DWTELEM *b, int width){ - DWTELEM temp[width]; - const int width2= width>>1; - const int w2= (width+1)>>1; - int x; - - inplace_lift(b, width, COEFFS1, N1, SHIFT1, LX1, 0); - inplace_lift(b, width, COEFFS2, N2, SHIFT2, LX0, 0); - inplace_lift(b, width, COEFFS3, N3, SHIFT3, LX1, 0); - inplace_lift(b, width, COEFFS4, N4, SHIFT4, LX0, 0); - - for(x=0; x>1; - int x; - const int w2= (width+1)>>1; - - memcpy(temp, b, width*sizeof(int)); - for(x=0; x>1) - 1 + (highpass & width); + int i; - for(y=0; y>shift): \ + -((-16*(src) + (ref) + add/4 + 1 + (5<<25))/(5*4) - (1<<23))) + if(mirror_left){ + dst[0] = LIFTS(src[0], mul*2*ref[0]+add, inverse); + dst += dst_step; + src += src_step; } - inplace_liftV(buffer, width, height, stride, COEFFS1, N1, SHIFT1, LX1, 0); - inplace_liftV(buffer, width, height, stride, COEFFS2, N2, SHIFT2, LX0, 0); - inplace_liftV(buffer, width, height, stride, COEFFS3, N3, SHIFT3, LX1, 0); - inplace_liftV(buffer, width, height, stride, COEFFS4, N4, SHIFT4, LX0, 0); -} - -static void spatial_composeX(DWTELEM *buffer, int width, int height, int stride){ - int x, y; - - inplace_liftV(buffer, width, height, stride, COEFFS4, N4, SHIFT4, LX0, 1); - inplace_liftV(buffer, width, height, stride, COEFFS3, N3, SHIFT3, LX1, 1); - inplace_liftV(buffer, width, height, stride, COEFFS2, N2, SHIFT2, LX0, 1); - inplace_liftV(buffer, width, height, stride, COEFFS1, N1, SHIFT1, LX1, 1); - - for(y=0; y>1; - lift (temp+w2, b +1, b , 1, 2, 2, width, -W_AM, W_AO, W_AS, 1, 0); - liftS(temp , b , temp+w2, 1, 2, 1, width, -W_BM, W_BO, W_BS, 0, 0); - lift5(b +w2, temp+w2, temp , 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 0); + lift (temp+w2, b +1, b , 1, 2, 2, width, W_AM, W_AO, W_AS, 1, 1); + liftS(temp , b , temp+w2, 1, 2, 1, width, W_BM, W_BO, W_BS, 0, 0); + lift (b +w2, temp+w2, temp , 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 0); lift (b , temp , b +w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 0); } @@ -1133,14 +957,7 @@ static void vertical_decompose97iH1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int w int i; for(i=0; i>W_CS; -#else - int r= 3*(b0[i] + b2[i]); - r+= r>>4; - r+= r>>8; - b1[i] += (r+W_CO)>>W_CS; -#endif } } @@ -1151,7 +968,7 @@ static void vertical_decompose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int w #ifdef liftS b1[i] -= (W_BM*(b0[i] + b2[i])+W_BO)>>W_BS; #else - b1[i] = (16*4*b1[i] - 4*(b0[i] + b2[i]) + 8*5 + (5<<27)) / (5*16) - (1<<23); + b1[i] = (16*4*b1[i] - 4*(b0[i] + b2[i]) + W_BO*5 + (5<<27)) / (5*16) - (1<<23); #endif } } @@ -1175,23 +992,14 @@ static void spatial_decompose97i(DWTELEM *buffer, int width, int height, int str DWTELEM *b4= buffer + mirror(y+3, height-1)*stride; DWTELEM *b5= buffer + mirror(y+4, height-1)*stride; -{START_TIMER if(y+3<(unsigned)height) horizontal_decompose97i(b4, width); if(y+4<(unsigned)height) horizontal_decompose97i(b5, width); -if(width>400){ -STOP_TIMER("horizontal_decompose97i") -}} -{START_TIMER if(y+3<(unsigned)height) vertical_decompose97iH0(b3, b4, b5, width); if(y+2<(unsigned)height) vertical_decompose97iL0(b2, b3, b4, width); if(y+1<(unsigned)height) vertical_decompose97iH1(b1, b2, b3, width); if(y+0<(unsigned)height) vertical_decompose97iL1(b0, b1, b2, width); -if(width>400){ -STOP_TIMER("vertical_decompose97i") -}} - b0=b2; b1=b3; b2=b4; @@ -1206,13 +1014,12 @@ void ff_spatial_dwt(DWTELEM *buffer, int width, int height, int stride, int type switch(type){ case DWT_97: spatial_decompose97i(buffer, width>>level, height>>level, stride<>level, height>>level, stride<>level, height>>level, stride<>1; const int w2= (width+1)>>1; int x; @@ -1247,9 +1054,9 @@ static void horizontal_compose53i(DWTELEM *b, int width){ b[width -1] = A3; b[width2-1] = A2; #else - lift(temp , b , b+w2, 1, 1, 1, width, 1, 2, 2, 0, 1); - lift(temp+w2, b+w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 1); -#endif + inv_lift(temp , b , b+w2, 1, 1, 1, width, 1, 2, 2, 0, 1); + inv_lift(temp+w2, b+w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 1); +#endif /* 0 */ for(x=0; xy = -1; } -static void spatial_compose53i_init(dwt_compose_t *cs, DWTELEM *buffer, int height, int stride){ +static void spatial_compose53i_init(dwt_compose_t *cs, IDWTELEM *buffer, int height, int stride){ cs->b0 = buffer + mirror(-1-1, height-1)*stride; cs->b1 = buffer + mirror(-1 , height-1)*stride; cs->y = -1; @@ -1289,49 +1096,41 @@ static void spatial_compose53i_init(dwt_compose_t *cs, DWTELEM *buffer, int heig static void spatial_compose53i_dy_buffered(dwt_compose_t *cs, slice_buffer * sb, int width, int height, int stride_line){ int y= cs->y; - DWTELEM *b0= cs->b0; - DWTELEM *b1= cs->b1; - DWTELEM *b2= slice_buffer_get_line(sb, mirror(y+1, height-1) * stride_line); - DWTELEM *b3= slice_buffer_get_line(sb, mirror(y+2, height-1) * stride_line); + IDWTELEM *b0= cs->b0; + IDWTELEM *b1= cs->b1; + IDWTELEM *b2= slice_buffer_get_line(sb, mirror(y+1, height-1) * stride_line); + IDWTELEM *b3= slice_buffer_get_line(sb, mirror(y+2, height-1) * stride_line); -{START_TIMER if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width); if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width); -STOP_TIMER("vertical_compose53i*")} -{START_TIMER if(y-1<(unsigned)height) horizontal_compose53i(b0, width); if(y+0<(unsigned)height) horizontal_compose53i(b1, width); -STOP_TIMER("horizontal_compose53i")} cs->b0 = b2; cs->b1 = b3; cs->y += 2; } -static void spatial_compose53i_dy(dwt_compose_t *cs, DWTELEM *buffer, int width, int height, int stride){ +static void spatial_compose53i_dy(dwt_compose_t *cs, IDWTELEM *buffer, int width, int height, int stride){ int y= cs->y; - DWTELEM *b0= cs->b0; - DWTELEM *b1= cs->b1; - DWTELEM *b2= buffer + mirror(y+1, height-1)*stride; - DWTELEM *b3= buffer + mirror(y+2, height-1)*stride; + IDWTELEM *b0= cs->b0; + IDWTELEM *b1= cs->b1; + IDWTELEM *b2= buffer + mirror(y+1, height-1)*stride; + IDWTELEM *b3= buffer + mirror(y+2, height-1)*stride; -{START_TIMER if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width); if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width); -STOP_TIMER("vertical_compose53i*")} -{START_TIMER if(y-1<(unsigned)height) horizontal_compose53i(b0, width); if(y+0<(unsigned)height) horizontal_compose53i(b1, width); -STOP_TIMER("horizontal_compose53i")} cs->b0 = b2; cs->b1 = b3; cs->y += 2; } -static void spatial_compose53i(DWTELEM *buffer, int width, int height, int stride){ +static void av_unused spatial_compose53i(IDWTELEM *buffer, int width, int height, int stride){ dwt_compose_t cs; spatial_compose53i_init(&cs, buffer, height, stride); while(cs.y <= height) @@ -1339,17 +1138,17 @@ static void spatial_compose53i(DWTELEM *buffer, int width, int height, int strid } -void ff_snow_horizontal_compose97i(DWTELEM *b, int width){ - DWTELEM temp[width]; +void ff_snow_horizontal_compose97i(IDWTELEM *b, int width){ + IDWTELEM temp[width]; const int w2= (width+1)>>1; - lift (temp , b , b +w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 1); - lift5(temp+w2, b +w2, temp , 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 1); - liftS(b , temp , temp+w2, 2, 1, 1, width, -W_BM, W_BO, W_BS, 0, 1); - lift (b+1 , temp+w2, b , 2, 1, 2, width, -W_AM, W_AO, W_AS, 1, 1); + inv_lift (temp , b , b +w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 1); + inv_lift (temp+w2, b +w2, temp , 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 1); + inv_liftS(b , temp , temp+w2, 2, 1, 1, width, W_BM, W_BO, W_BS, 0, 1); + inv_lift (b+1 , temp+w2, b , 2, 1, 2, width, W_AM, W_AO, W_AS, 1, 0); } -static void vertical_compose97iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ +static void vertical_compose97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ int i; for(i=0; i>W_CS; -#else - int r= 3*(b0[i] + b2[i]); - r+= r>>4; - r+= r>>8; - b1[i] -= (r+W_CO)>>W_CS; -#endif } } -static void vertical_compose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ +static void vertical_compose97iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ int i; for(i=0; i>W_DS; -#ifdef lift5 b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS; -#else - r= 3*(b2[i] + b4[i]); - r+= r>>4; - r+= r>>8; - b3[i] -= (r+W_CO)>>W_CS; -#endif #ifdef liftS b2[i] += (W_BM*(b1[i] + b3[i])+W_BO)>>W_BS; #else @@ -1425,7 +1207,7 @@ static void spatial_compose97i_buffered_init(dwt_compose_t *cs, slice_buffer * s cs->y = -3; } -static void spatial_compose97i_init(dwt_compose_t *cs, DWTELEM *buffer, int height, int stride){ +static void spatial_compose97i_init(dwt_compose_t *cs, IDWTELEM *buffer, int height, int stride){ cs->b0 = buffer + mirror(-3-1, height-1)*stride; cs->b1 = buffer + mirror(-3 , height-1)*stride; cs->b2 = buffer + mirror(-3+1, height-1)*stride; @@ -1436,14 +1218,13 @@ static void spatial_compose97i_init(dwt_compose_t *cs, DWTELEM *buffer, int heig static void spatial_compose97i_dy_buffered(DSPContext *dsp, dwt_compose_t *cs, slice_buffer * sb, int width, int height, int stride_line){ int y = cs->y; - DWTELEM *b0= cs->b0; - DWTELEM *b1= cs->b1; - DWTELEM *b2= cs->b2; - DWTELEM *b3= cs->b3; - DWTELEM *b4= slice_buffer_get_line(sb, mirror(y + 3, height - 1) * stride_line); - DWTELEM *b5= slice_buffer_get_line(sb, mirror(y + 4, height - 1) * stride_line); + IDWTELEM *b0= cs->b0; + IDWTELEM *b1= cs->b1; + IDWTELEM *b2= cs->b2; + IDWTELEM *b3= cs->b3; + IDWTELEM *b4= slice_buffer_get_line(sb, mirror(y + 3, height - 1) * stride_line); + IDWTELEM *b5= slice_buffer_get_line(sb, mirror(y + 4, height - 1) * stride_line); -{START_TIMER if(y>0 && y+4vertical_compose97i(b0, b1, b2, b3, b4, b5, width); }else{ @@ -1452,14 +1233,9 @@ static void spatial_compose97i_dy_buffered(DSPContext *dsp, dwt_compose_t *cs, s if(y+1<(unsigned)height) vertical_compose97iL0(b1, b2, b3, width); if(y+0<(unsigned)height) vertical_compose97iH0(b0, b1, b2, width); } -if(width>400){ -STOP_TIMER("vertical_compose97i")}} -{START_TIMER if(y-1<(unsigned)height) dsp->horizontal_compose97i(b0, width); if(y+0<(unsigned)height) dsp->horizontal_compose97i(b1, width); -if(width>400 && y+0<(unsigned)height){ -STOP_TIMER("horizontal_compose97i")}} cs->b0=b2; cs->b1=b3; @@ -1468,28 +1244,22 @@ STOP_TIMER("horizontal_compose97i")}} cs->y += 2; } -static void spatial_compose97i_dy(dwt_compose_t *cs, DWTELEM *buffer, int width, int height, int stride){ +static void spatial_compose97i_dy(dwt_compose_t *cs, IDWTELEM *buffer, int width, int height, int stride){ int y = cs->y; - DWTELEM *b0= cs->b0; - DWTELEM *b1= cs->b1; - DWTELEM *b2= cs->b2; - DWTELEM *b3= cs->b3; - DWTELEM *b4= buffer + mirror(y+3, height-1)*stride; - DWTELEM *b5= buffer + mirror(y+4, height-1)*stride; - -{START_TIMER + IDWTELEM *b0= cs->b0; + IDWTELEM *b1= cs->b1; + IDWTELEM *b2= cs->b2; + IDWTELEM *b3= cs->b3; + IDWTELEM *b4= buffer + mirror(y+3, height-1)*stride; + IDWTELEM *b5= buffer + mirror(y+4, height-1)*stride; + if(y+3<(unsigned)height) vertical_compose97iL1(b3, b4, b5, width); if(y+2<(unsigned)height) vertical_compose97iH1(b2, b3, b4, width); if(y+1<(unsigned)height) vertical_compose97iL0(b1, b2, b3, width); if(y+0<(unsigned)height) vertical_compose97iH0(b0, b1, b2, width); -if(width>400){ -STOP_TIMER("vertical_compose97i")}} -{START_TIMER if(y-1<(unsigned)height) ff_snow_horizontal_compose97i(b0, width); if(y+0<(unsigned)height) ff_snow_horizontal_compose97i(b1, width); -if(width>400 && b0 <= b2){ -STOP_TIMER("horizontal_compose97i")}} cs->b0=b2; cs->b1=b3; @@ -1498,7 +1268,7 @@ STOP_TIMER("horizontal_compose97i")}} cs->y += 2; } -static void spatial_compose97i(DWTELEM *buffer, int width, int height, int stride){ +static void av_unused spatial_compose97i(IDWTELEM *buffer, int width, int height, int stride){ dwt_compose_t cs; spatial_compose97i_init(&cs, buffer, height, stride); while(cs.y <= height) @@ -1511,26 +1281,21 @@ static void ff_spatial_idwt_buffered_init(dwt_compose_t *cs, slice_buffer * sb, switch(type){ case DWT_97: spatial_compose97i_buffered_init(cs+level, sb, height>>level, stride_line<>level, stride_line<>level, height>>level, stride<=0; level--){ switch(type){ case DWT_97: spatial_compose97i_init(cs+level, buffer, height>>level, stride<>level, stride<>level, height>>level, stride<>level)+support, height>>level)){ switch(type){ case DWT_97: spatial_compose97i_dy(cs+level, buffer, width>>level, height>>level, stride<>level, height>>level, stride<>level)+support, height>>level)){ switch(type){ case DWT_97: spatial_compose97i_dy_buffered(dsp, cs+level, slice_buf, width>>level, height>>level, stride_line<>level, height>>level, stride_line<=0; level--) - spatial_composeX (buffer, width>>level, height>>level, stride<width; const int h= b->height; int x, y; @@ -1700,7 +1457,7 @@ static int encode_subband_c0run(SnowContext *s, SubBand *b, DWTELEM *src, DWTELE return 0; } -static int encode_subband(SnowContext *s, SubBand *b, DWTELEM *src, DWTELEM *parent, int stride, int orientation){ +static int encode_subband(SnowContext *s, SubBand *b, IDWTELEM *src, IDWTELEM *parent, int stride, int orientation){ // encode_subband_qtree(s, b, src, parent, stride, orientation); // encode_subband_z0run(s, b, src, parent, stride, orientation); return encode_subband_c0run(s, b, src, parent, stride, orientation); @@ -1815,9 +1572,7 @@ static inline void decode_subband_slice_buffered(SnowContext *s, SubBand *b, sli int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; int new_index = 0; - START_TIMER - - if(b->buf == s->spatial_dwt_buffer || s->qlog == LOSSLESS_QLOG){ + if(b->ibuf == s->spatial_idwt_buffer || s->qlog == LOSSLESS_QLOG){ qadd= 0; qmul= 1<stride_line + b->buf_y_offset) + b->buf_x_offset; - memset(line, 0, b->width*sizeof(DWTELEM)); + IDWTELEM * line = slice_buffer_get_line(sb, y * b->stride_line + b->buf_y_offset) + b->buf_x_offset; + memset(line, 0, b->width*sizeof(IDWTELEM)); v = b->x_coeff[new_index].coeff; x = b->x_coeff[new_index++].x; while(x < w) @@ -1844,9 +1599,6 @@ static inline void decode_subband_slice_buffered(SnowContext *s, SubBand *b, sli x = b->x_coeff[new_index++].x; } } - if(w > 200 && start_y != 0/*level+1 == s->spatial_decomposition_count*/){ - STOP_TIMER("decode_subband") - } /* Save our variables for the next slice. */ save_state[0] = new_index; @@ -1858,7 +1610,7 @@ static void reset_contexts(SnowContext *s){ //FIXME better initial contexts int plane_index, level, orientation; for(plane_index=0; plane_index<3; plane_index++){ - for(level=0; levelspatial_decomposition_count; level++){ + for(level=0; levelplane[plane_index].band[level][orientation].state, MID_STATE, sizeof(s->plane[plane_index].band[level][orientation].state)); } @@ -1990,7 +1742,7 @@ static int encode_q_branch(SnowContext *s, int level, int x, int y){ RangeCoder pc, ic; uint8_t *pbbak= s->c.bytestream; uint8_t *pbbak_start= s->c.bytestream_start; - int score, score2, iscore, i_len, p_len, block_s, sum; + int score, score2, iscore, i_len, p_len, block_s, sum, base_bits; const int w= s->b_width << s->block_max_depth; const int h= s->b_height << s->block_max_depth; const int rem_depth= s->block_max_depth - level; @@ -2113,9 +1865,10 @@ static int encode_q_branch(SnowContext *s, int level, int x, int y){ my= ref_my; } } - //FIXME if mb_cmp != SSE then intra cant be compared currently and mb_penalty vs. lambda2 + //FIXME if mb_cmp != SSE then intra cannot be compared currently and mb_penalty vs. lambda2 // subpel search + base_bits= get_rac_count(&s->c) - 8*(s->c.bytestream - s->c.bytestream_start); pc= s->c; pc.bytestream_start= pc.bytestream= p_buffer; //FIXME end/start? and at the other stoo @@ -2130,10 +1883,7 @@ static int encode_q_branch(SnowContext *s, int level, int x, int y){ put_symbol(&pc, &p_state[128 + 32*(mx_context + 16*!!best_ref)], mx - pmx, 1); put_symbol(&pc, &p_state[128 + 32*(my_context + 16*!!best_ref)], my - pmy, 1); p_len= pc.bytestream - pc.bytestream_start; - score += (s->lambda2*(p_len*8 - + (pc.outstanding_count - s->c.outstanding_count)*8 - + (-av_log2(pc.range) + av_log2(s->c.range)) - ))>>FF_LAMBDA_SHIFT; + score += (s->lambda2*(get_rac_count(&pc)-base_bits))>>FF_LAMBDA_SHIFT; block_s= block_w*block_w; sum = pix_sum(current_data[0], stride, block_w); @@ -2159,10 +1909,7 @@ static int encode_q_branch(SnowContext *s, int level, int x, int y){ put_symbol(&ic, &i_state[64], cb-pcb, 1); put_symbol(&ic, &i_state[96], cr-pcr, 1); i_len= ic.bytestream - ic.bytestream_start; - iscore += (s->lambda2*(i_len*8 - + (ic.outstanding_count - s->c.outstanding_count)*8 - + (-av_log2(ic.range) + av_log2(s->c.range)) - ))>>FF_LAMBDA_SHIFT; + iscore += (s->lambda2*(get_rac_count(&ic)-base_bits))>>FF_LAMBDA_SHIFT; // assert(score==256*256*256*64-1); assert(iscore < 255*255*256 + s->lambda2*10); @@ -2356,80 +2103,195 @@ static void decode_blocks(SnowContext *s){ } } -static void mc_block(uint8_t *dst, uint8_t *src, uint8_t *tmp, int stride, int b_w, int b_h, int dx, int dy){ - int x, y; -START_TIMER - for(y=0; y < b_h+5; y++){ - for(x=0; x < b_w; x++){ - int a0= src[x ]; - int a1= src[x + 1]; - int a2= src[x + 2]; - int a3= src[x + 3]; - int a4= src[x + 4]; - int a5= src[x + 5]; -// int am= 9*(a1+a2) - (a0+a3); - int am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5); -// int am= 18*(a2+a3) - 2*(a1+a4); -// int aL= (-7*a0 + 105*a1 + 35*a2 - 5*a3)>>3; -// int aR= (-7*a3 + 105*a2 + 35*a1 - 5*a0)>>3; - -// if(b_w==16) am= 8*(a1+a2); - - if(dx<8) am = (32*a2*( 8-dx) + am* dx + 128)>>8; - else am = ( am*(16-dx) + 32*a3*(dx-8) + 128)>>8; - - /* FIXME Try increasing tmp buffer to 16 bits and not clipping here. Should give marginally better results. - Robert*/ - if(am&(~255)) am= ~(am>>31); - - tmp[x] = am; - -/* if (dx< 4) tmp[x + y*stride]= (16*a1*( 4-dx) + aL* dx + 32)>>6; - else if(dx< 8) tmp[x + y*stride]= ( aL*( 8-dx) + am*(dx- 4) + 32)>>6; - else if(dx<12) tmp[x + y*stride]= ( am*(12-dx) + aR*(dx- 8) + 32)>>6; - else tmp[x + y*stride]= ( aR*(16-dx) + 16*a2*(dx-12) + 32)>>6;*/ +static void mc_block(Plane *p, uint8_t *dst, const uint8_t *src, uint8_t *tmp, int stride, int b_w, int b_h, int dx, int dy){ + const static uint8_t weight[64]={ + 8,7,6,5,4,3,2,1, + 7,7,0,0,0,0,0,1, + 6,0,6,0,0,0,2,0, + 5,0,0,5,0,3,0,0, + 4,0,0,0,4,0,0,0, + 3,0,0,5,0,3,0,0, + 2,0,6,0,0,0,2,0, + 1,7,0,0,0,0,0,1, + }; + + const static uint8_t brane[256]={ + 0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x11,0x12,0x12,0x12,0x12,0x12,0x12,0x12, + 0x04,0x05,0xcc,0xcc,0xcc,0xcc,0xcc,0x41,0x15,0x16,0xcc,0xcc,0xcc,0xcc,0xcc,0x52, + 0x04,0xcc,0x05,0xcc,0xcc,0xcc,0x41,0xcc,0x15,0xcc,0x16,0xcc,0xcc,0xcc,0x52,0xcc, + 0x04,0xcc,0xcc,0x05,0xcc,0x41,0xcc,0xcc,0x15,0xcc,0xcc,0x16,0xcc,0x52,0xcc,0xcc, + 0x04,0xcc,0xcc,0xcc,0x41,0xcc,0xcc,0xcc,0x15,0xcc,0xcc,0xcc,0x16,0xcc,0xcc,0xcc, + 0x04,0xcc,0xcc,0x41,0xcc,0x05,0xcc,0xcc,0x15,0xcc,0xcc,0x52,0xcc,0x16,0xcc,0xcc, + 0x04,0xcc,0x41,0xcc,0xcc,0xcc,0x05,0xcc,0x15,0xcc,0x52,0xcc,0xcc,0xcc,0x16,0xcc, + 0x04,0x41,0xcc,0xcc,0xcc,0xcc,0xcc,0x05,0x15,0x52,0xcc,0xcc,0xcc,0xcc,0xcc,0x16, + 0x44,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0x55,0x56,0x56,0x56,0x56,0x56,0x56,0x56, + 0x48,0x49,0xcc,0xcc,0xcc,0xcc,0xcc,0x85,0x59,0x5A,0xcc,0xcc,0xcc,0xcc,0xcc,0x96, + 0x48,0xcc,0x49,0xcc,0xcc,0xcc,0x85,0xcc,0x59,0xcc,0x5A,0xcc,0xcc,0xcc,0x96,0xcc, + 0x48,0xcc,0xcc,0x49,0xcc,0x85,0xcc,0xcc,0x59,0xcc,0xcc,0x5A,0xcc,0x96,0xcc,0xcc, + 0x48,0xcc,0xcc,0xcc,0x49,0xcc,0xcc,0xcc,0x59,0xcc,0xcc,0xcc,0x96,0xcc,0xcc,0xcc, + 0x48,0xcc,0xcc,0x85,0xcc,0x49,0xcc,0xcc,0x59,0xcc,0xcc,0x96,0xcc,0x5A,0xcc,0xcc, + 0x48,0xcc,0x85,0xcc,0xcc,0xcc,0x49,0xcc,0x59,0xcc,0x96,0xcc,0xcc,0xcc,0x5A,0xcc, + 0x48,0x85,0xcc,0xcc,0xcc,0xcc,0xcc,0x49,0x59,0x96,0xcc,0xcc,0xcc,0xcc,0xcc,0x5A, + }; + + const static uint8_t needs[16]={ + 0,1,0,0, + 2,4,2,0, + 0,1,0,0, + 15 + }; + + int x, y, b, r, l; + int16_t tmpIt [64*(32+HTAPS_MAX)]; + uint8_t tmp2t[3][stride*(32+HTAPS_MAX)]; + int16_t *tmpI= tmpIt; + uint8_t *tmp2= tmp2t[0]; + const uint8_t *hpel[11]; + assert(dx<16 && dy<16); + r= brane[dx + 16*dy]&15; + l= brane[dx + 16*dy]>>4; + + b= needs[l] | needs[r]; + if(p && !p->diag_mc) + b= 15; + + if(b&5){ + for(y=0; y < b_h+HTAPS_MAX-1; y++){ + for(x=0; x < b_w; x++){ + int a_1=src[x + HTAPS_MAX/2-4]; + int a0= src[x + HTAPS_MAX/2-3]; + int a1= src[x + HTAPS_MAX/2-2]; + int a2= src[x + HTAPS_MAX/2-1]; + int a3= src[x + HTAPS_MAX/2+0]; + int a4= src[x + HTAPS_MAX/2+1]; + int a5= src[x + HTAPS_MAX/2+2]; + int a6= src[x + HTAPS_MAX/2+3]; + int am=0; + if(!p || p->fast_mc){ + am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5); + tmpI[x]= am; + am= (am+16)>>5; + }else{ + am= p->hcoeff[0]*(a2+a3) + p->hcoeff[1]*(a1+a4) + p->hcoeff[2]*(a0+a5) + p->hcoeff[3]*(a_1+a6); + tmpI[x]= am; + am= (am+32)>>6; + } + + if(am&(~255)) am= ~(am>>31); + tmp2[x]= am; + } + tmpI+= 64; + tmp2+= stride; + src += stride; } - tmp += stride; - src += stride; - } - tmp -= (b_h+5)*stride; - - for(y=0; y < b_h; y++){ - for(x=0; x < b_w; x++){ - int a0= tmp[x + 0*stride]; - int a1= tmp[x + 1*stride]; - int a2= tmp[x + 2*stride]; - int a3= tmp[x + 3*stride]; - int a4= tmp[x + 4*stride]; - int a5= tmp[x + 5*stride]; - int am= 20*(a2+a3) - 5*(a1+a4) + (a0+a5); -// int am= 18*(a2+a3) - 2*(a1+a4); -/* int aL= (-7*a0 + 105*a1 + 35*a2 - 5*a3)>>3; - int aR= (-7*a3 + 105*a2 + 35*a1 - 5*a0)>>3;*/ - -// if(b_w==16) am= 8*(a1+a2); - - if(dy<8) am = (32*a2*( 8-dy) + am* dy + 128)>>8; - else am = ( am*(16-dy) + 32*a3*(dy-8) + 128)>>8; - - if(am&(~255)) am= ~(am>>31); - - dst[x] = am; -/* if (dy< 4) tmp[x + y*stride]= (16*a1*( 4-dy) + aL* dy + 32)>>6; - else if(dy< 8) tmp[x + y*stride]= ( aL*( 8-dy) + am*(dy- 4) + 32)>>6; - else if(dy<12) tmp[x + y*stride]= ( am*(12-dy) + aR*(dy- 8) + 32)>>6; - else tmp[x + y*stride]= ( aR*(16-dy) + 16*a2*(dy-12) + 32)>>6;*/ + src -= stride*y; + } + src += HTAPS_MAX/2 - 1; + tmp2= tmp2t[1]; + + if(b&2){ + for(y=0; y < b_h; y++){ + for(x=0; x < b_w+1; x++){ + int a_1=src[x + (HTAPS_MAX/2-4)*stride]; + int a0= src[x + (HTAPS_MAX/2-3)*stride]; + int a1= src[x + (HTAPS_MAX/2-2)*stride]; + int a2= src[x + (HTAPS_MAX/2-1)*stride]; + int a3= src[x + (HTAPS_MAX/2+0)*stride]; + int a4= src[x + (HTAPS_MAX/2+1)*stride]; + int a5= src[x + (HTAPS_MAX/2+2)*stride]; + int a6= src[x + (HTAPS_MAX/2+3)*stride]; + int am=0; + if(!p || p->fast_mc) + am= (20*(a2+a3) - 5*(a1+a4) + (a0+a5) + 16)>>5; + else + am= (p->hcoeff[0]*(a2+a3) + p->hcoeff[1]*(a1+a4) + p->hcoeff[2]*(a0+a5) + p->hcoeff[3]*(a_1+a6) + 32)>>6; + + if(am&(~255)) am= ~(am>>31); + tmp2[x]= am; + } + src += stride; + tmp2+= stride; + } + src -= stride*y; + } + src += stride*(HTAPS_MAX/2 - 1); + tmp2= tmp2t[2]; + tmpI= tmpIt; + if(b&4){ + for(y=0; y < b_h; y++){ + for(x=0; x < b_w; x++){ + int a_1=tmpI[x + (HTAPS_MAX/2-4)*64]; + int a0= tmpI[x + (HTAPS_MAX/2-3)*64]; + int a1= tmpI[x + (HTAPS_MAX/2-2)*64]; + int a2= tmpI[x + (HTAPS_MAX/2-1)*64]; + int a3= tmpI[x + (HTAPS_MAX/2+0)*64]; + int a4= tmpI[x + (HTAPS_MAX/2+1)*64]; + int a5= tmpI[x + (HTAPS_MAX/2+2)*64]; + int a6= tmpI[x + (HTAPS_MAX/2+3)*64]; + int am=0; + if(!p || p->fast_mc) + am= (20*(a2+a3) - 5*(a1+a4) + (a0+a5) + 512)>>10; + else + am= (p->hcoeff[0]*(a2+a3) + p->hcoeff[1]*(a1+a4) + p->hcoeff[2]*(a0+a5) + p->hcoeff[3]*(a_1+a6) + 2048)>>12; + if(am&(~255)) am= ~(am>>31); + tmp2[x]= am; + } + tmpI+= 64; + tmp2+= stride; + } + } + + hpel[ 0]= src; + hpel[ 1]= tmp2t[0] + stride*(HTAPS_MAX/2-1); + hpel[ 2]= src + 1; + + hpel[ 4]= tmp2t[1]; + hpel[ 5]= tmp2t[2]; + hpel[ 6]= tmp2t[1] + 1; + + hpel[ 8]= src + stride; + hpel[ 9]= hpel[1] + stride; + hpel[10]= hpel[8] + 1; + + if(b==15){ + const uint8_t *src1= hpel[dx/8 + dy/8*4 ]; + const uint8_t *src2= hpel[dx/8 + dy/8*4+1]; + const uint8_t *src3= hpel[dx/8 + dy/8*4+4]; + const uint8_t *src4= hpel[dx/8 + dy/8*4+5]; + dx&=7; + dy&=7; + for(y=0; y < b_h; y++){ + for(x=0; x < b_w; x++){ + dst[x]= ((8-dx)*(8-dy)*src1[x] + dx*(8-dy)*src2[x]+ + (8-dx)* dy *src3[x] + dx* dy *src4[x]+32)>>6; + } + src1+=stride; + src2+=stride; + src3+=stride; + src4+=stride; + dst +=stride; + } + }else{ + const uint8_t *src1= hpel[l]; + const uint8_t *src2= hpel[r]; + int a= weight[((dx&7) + (8*(dy&7)))]; + int b= 8-a; + for(y=0; y < b_h; y++){ + for(x=0; x < b_w; x++){ + dst[x]= (a*src1[x] + b*src2[x] + 4)>>3; + } + src1+=stride; + src2+=stride; + dst +=stride; } - dst += stride; - tmp += stride; } -STOP_TIMER("mc_block") } #define mca(dx,dy,b_w)\ -static void mc_block_hpel ## dx ## dy ## b_w(uint8_t *dst, uint8_t *src, int stride, int h){\ - uint8_t tmp[stride*(b_w+5)];\ +static void mc_block_hpel ## dx ## dy ## b_w(uint8_t *dst, const uint8_t *src, int stride, int h){\ + uint8_t tmp[stride*(b_w+HTAPS_MAX-1)];\ assert(h==b_w);\ - mc_block(dst, src-2-2*stride, tmp, stride, b_w, b_w, dx, dy);\ + mc_block(NULL, dst, src-(HTAPS_MAX/2-1)-(HTAPS_MAX/2-1)*stride, tmp, stride, b_w, b_w, dx, dy);\ } mca( 0, 0,16) @@ -2488,35 +2350,35 @@ static void pred_block(SnowContext *s, uint8_t *dst, uint8_t *tmp, int stride, i const int dx= mx&15; const int dy= my&15; const int tab_index= 3 - (b_w>>2) + (b_w>>4); - sx += (mx>>4) - 2; - sy += (my>>4) - 2; + sx += (mx>>4) - (HTAPS_MAX/2-1); + sy += (my>>4) - (HTAPS_MAX/2-1); src += sx + sy*stride; - if( (unsigned)sx >= w - b_w - 4 - || (unsigned)sy >= h - b_h - 4){ - ff_emulated_edge_mc(tmp + MB_SIZE, src, stride, b_w+5, b_h+5, sx, sy, w, h); + if( (unsigned)sx >= w - b_w - (HTAPS_MAX-2) + || (unsigned)sy >= h - b_h - (HTAPS_MAX-2)){ + ff_emulated_edge_mc(tmp + MB_SIZE, src, stride, b_w+HTAPS_MAX-1, b_h+HTAPS_MAX-1, sx, sy, w, h); src= tmp + MB_SIZE; } // assert(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h); // assert(!(b_w&(b_w-1))); assert(b_w>1 && b_h>1); - assert(tab_index>=0 && tab_index<4 || b_w==32); - if((dx&3) || (dy&3) || !(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h) || (b_w&(b_w-1))) - mc_block(dst, src, tmp, stride, b_w, b_h, dx, dy); + assert((tab_index>=0 && tab_index<4) || b_w==32); + if((dx&3) || (dy&3) || !(b_w == b_h || 2*b_w == b_h || b_w == 2*b_h) || (b_w&(b_w-1)) || !s->plane[plane_index].fast_mc ) + mc_block(&s->plane[plane_index], dst, src, tmp, stride, b_w, b_h, dx, dy); else if(b_w==32){ int y; for(y=0; ydsp.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + y*stride, src + 2 + (y+2)*stride,stride); - s->dsp.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + 16 + y*stride, src + 18 + (y+2)*stride,stride); + s->dsp.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + y*stride, src + 3 + (y+3)*stride,stride); + s->dsp.put_h264_qpel_pixels_tab[0][dy+(dx>>2)](dst + 16 + y*stride, src + 19 + (y+3)*stride,stride); } }else if(b_w==b_h) - s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst,src + 2 + 2*stride,stride); + s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst,src + 3 + 3*stride,stride); else if(b_w==2*b_h){ - s->dsp.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst ,src + 2 + 2*stride,stride); - s->dsp.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst+b_h,src + 2 + b_h + 2*stride,stride); + s->dsp.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst ,src + 3 + 3*stride,stride); + s->dsp.put_h264_qpel_pixels_tab[tab_index+1][dy+(dx>>2)](dst+b_h,src + 3 + b_h + 3*stride,stride); }else{ assert(2*b_w==b_h); - s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst ,src + 2 + 2*stride ,stride); - s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst+b_w*stride,src + 2 + 2*stride+b_w*stride,stride); + s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst ,src + 3 + 3*stride ,stride); + s->dsp.put_h264_qpel_pixels_tab[tab_index ][dy+(dx>>2)](dst+b_w*stride,src + 3 + 3*stride+b_w*stride,stride); } } } @@ -2524,9 +2386,9 @@ static void pred_block(SnowContext *s, uint8_t *dst, uint8_t *tmp, int stride, i void ff_snow_inner_add_yblock(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8){ int y, x; - DWTELEM * dst; + IDWTELEM * dst; for(y=0; y>1); const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1); @@ -2540,7 +2402,6 @@ void ff_snow_inner_add_yblock(const uint8_t *obmc, const int obmc_stride, uint8_ v <<= 8 - LOG2_OBMC_MAX; if(FRAC_BITS != 8){ - v += 1<<(7 - FRAC_BITS); v >>= 8 - FRAC_BITS; } if(add){ @@ -2555,8 +2416,8 @@ void ff_snow_inner_add_yblock(const uint8_t *obmc, const int obmc_stride, uint8_ } } -//FIXME name clenup (b_w, block_w, b_width stuff) -static av_always_inline void add_yblock(SnowContext *s, int sliced, slice_buffer *sb, DWTELEM *dst, uint8_t *dst8, const uint8_t *obmc, int src_x, int src_y, int b_w, int b_h, int w, int h, int dst_stride, int src_stride, int obmc_stride, int b_x, int b_y, int add, int offset_dst, int plane_index){ +//FIXME name cleanup (b_w, block_w, b_width stuff) +static av_always_inline void add_yblock(SnowContext *s, int sliced, slice_buffer *sb, IDWTELEM *dst, uint8_t *dst8, const uint8_t *obmc, int src_x, int src_y, int b_w, int b_h, int w, int h, int dst_stride, int src_stride, int obmc_stride, int b_x, int b_y, int add, int offset_dst, int plane_index){ const int b_width = s->b_width << s->block_max_depth; const int b_height= s->b_height << s->block_max_depth; const int b_stride= b_width; @@ -2585,7 +2446,7 @@ static av_always_inline void add_yblock(SnowContext *s, int sliced, slice_buffer rb= rt; } - if(src_x<0){ //FIXME merge with prev & always round internal width upto *16 + if(src_x<0){ //FIXME merge with prev & always round internal width up to *16 obmc -= src_x; b_w += src_x; if(!sliced && !offset_dst) @@ -2606,7 +2467,8 @@ static av_always_inline void add_yblock(SnowContext *s, int sliced, slice_buffer if(b_w<=0 || b_h<=0) return; -assert(src_stride > 2*MB_SIZE + 5); + assert(src_stride > 2*MB_SIZE + 5); + if(!sliced && offset_dst) dst += src_x + src_y*dst_stride; dst8+= src_x + src_y*src_stride; @@ -2680,13 +2542,10 @@ assert(src_stride > 2*MB_SIZE + 5); } #else if(sliced){ - START_TIMER - s->dsp.inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); - STOP_TIMER("inner_add_yblock") }else for(y=0; y>1); const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1); @@ -2699,7 +2558,6 @@ assert(src_stride > 2*MB_SIZE + 5); v <<= 8 - LOG2_OBMC_MAX; if(FRAC_BITS != 8){ - v += 1<<(7 - FRAC_BITS); v >>= 8 - FRAC_BITS; } if(add){ @@ -2712,10 +2570,10 @@ assert(src_stride > 2*MB_SIZE + 5); } } } -#endif +#endif /* 0 */ } -static av_always_inline void predict_slice_buffered(SnowContext *s, slice_buffer * sb, DWTELEM * old_buffer, int plane_index, int add, int mb_y){ +static av_always_inline void predict_slice_buffered(SnowContext *s, slice_buffer * sb, IDWTELEM * old_buffer, int plane_index, int add, int mb_y){ Plane *p= &s->plane[plane_index]; const int mb_w= s->b_width << s->block_max_depth; const int mb_h= s->b_height << s->block_max_depth; @@ -2728,7 +2586,6 @@ static av_always_inline void predict_slice_buffered(SnowContext *s, slice_buffer uint8_t *dst8= s->current_picture.data[plane_index]; int w= p->width; int h= p->height; - START_TIMER if(s->keyframe || (s->avctx->debug&512)){ if(mb_y==mb_h) @@ -2738,7 +2595,7 @@ static av_always_inline void predict_slice_buffered(SnowContext *s, slice_buffer for(y=block_w*mb_y; yline[y]; + IDWTELEM * line = sb->line[y]; for(x=0; xline[y]; + IDWTELEM * line = sb->line[y]; for(x=0; xplane[plane_index]; const int mb_w= s->b_width << s->block_max_depth; const int mb_h= s->b_height << s->block_max_depth; @@ -2795,7 +2646,6 @@ static av_always_inline void predict_slice(SnowContext *s, DWTELEM *buf, int pla uint8_t *dst8= s->current_picture.data[plane_index]; int w= p->width; int h= p->height; - START_TIMER if(s->keyframe || (s->avctx->debug&512)){ if(mb_y==mb_h) @@ -2821,25 +2671,19 @@ static av_always_inline void predict_slice(SnowContext *s, DWTELEM *buf, int pla return; } - for(mb_x=0; mb_x<=mb_w; mb_x++){ - START_TIMER - - add_yblock(s, 0, NULL, buf, dst8, obmc, - block_w*mb_x - block_w/2, - block_w*mb_y - block_w/2, - block_w, block_w, - w, h, - w, ref_stride, obmc_stride, - mb_x - 1, mb_y - 1, - add, 1, plane_index); - - STOP_TIMER("add_yblock") - } - - STOP_TIMER("predict_slice") + for(mb_x=0; mb_x<=mb_w; mb_x++){ + add_yblock(s, 0, NULL, buf, dst8, obmc, + block_w*mb_x - block_w/2, + block_w*mb_y - block_w/2, + block_w, block_w, + w, h, + w, ref_stride, obmc_stride, + mb_x - 1, mb_y - 1, + add, 1, plane_index); + } } -static av_always_inline void predict_plane(SnowContext *s, DWTELEM *buf, int plane_index, int add){ +static av_always_inline void predict_plane(SnowContext *s, IDWTELEM *buf, int plane_index, int add){ const int mb_h= s->b_height << s->block_max_depth; int mb_y; for(mb_y=0; mb_y<=mb_h; mb_y++) @@ -2855,7 +2699,7 @@ static int get_dc(SnowContext *s, int mb_x, int mb_y, int plane_index){ const int obmc_stride= plane_index ? block_size : 2*block_size; const int ref_stride= s->current_picture.linesize[plane_index]; uint8_t *src= s-> input_picture.data[plane_index]; - DWTELEM *dst= (DWTELEM*)s->m.obmc_scratchpad + plane_index*block_size*block_size*4; + IDWTELEM *dst= (IDWTELEM*)s->m.obmc_scratchpad + plane_index*block_size*block_size*4; //FIXME change to unsigned const int b_stride = s->b_width << s->block_max_depth; const int w= p->width; const int h= p->height; @@ -2867,7 +2711,7 @@ static int get_dc(SnowContext *s, int mb_x, int mb_y, int plane_index){ b->type|= BLOCK_INTRA; b->color[plane_index]= 0; - memset(dst, 0, obmc_stride*obmc_stride*sizeof(DWTELEM)); + memset(dst, 0, obmc_stride*obmc_stride*sizeof(IDWTELEM)); for(i=0; i<4; i++){ int mb_x2= mb_x + (i &1) - 1; @@ -2887,18 +2731,18 @@ static int get_dc(SnowContext *s, int mb_x, int mb_y, int plane_index){ if(x<0) obmc_v += obmc[index + block_w]; if(y+block_w>h) obmc_v += obmc[index - block_w*obmc_stride]; if(x+block_w>w) obmc_v += obmc[index - block_w]; - //FIXME precalc this or simplify it somehow else + //FIXME precalculate this or simplify it somehow else d = -dst[index] + (1<<(FRAC_BITS-1)); dst[index] = d; ab += (src[x2 + y2*ref_stride] - (d>>FRAC_BITS)) * obmc_v; - aa += obmc_v * obmc_v; //FIXME precalclate this + aa += obmc_v * obmc_v; //FIXME precalculate this } } } *b= backup; - return av_clip(((ab<type & BLOCK_INTRA){ return 3+2*( av_log2(2*FFABS(left->color[0] - b->color[0])) + av_log2(2*FFABS(left->color[1] - b->color[1])) @@ -2947,9 +2791,9 @@ static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, con const int ref_stride= s->current_picture.linesize[plane_index]; uint8_t *dst= s->current_picture.data[plane_index]; uint8_t *src= s-> input_picture.data[plane_index]; - DWTELEM *pred= (DWTELEM*)s->m.obmc_scratchpad + plane_index*block_size*block_size*4; + IDWTELEM *pred= (IDWTELEM*)s->m.obmc_scratchpad + plane_index*block_size*block_size*4; uint8_t cur[ref_stride*2*MB_SIZE]; //FIXME alignment - uint8_t tmp[ref_stride*(2*MB_SIZE+5)]; + uint8_t tmp[ref_stride*(2*MB_SIZE+HTAPS_MAX-1)]; const int b_stride = s->b_width << s->block_max_depth; const int b_height = s->b_height<< s->block_max_depth; const int w= p->width; @@ -2969,11 +2813,15 @@ static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, con for(y=y0; y= LOG2_OBMC_MAX int v = (cur1[x] * obmc1[x]) << (FRAC_BITS - LOG2_OBMC_MAX); +#else + int v = (cur1[x] * obmc1[x] + (1<<(LOG2_OBMC_MAX - FRAC_BITS-1))) >> (LOG2_OBMC_MAX - FRAC_BITS); +#endif v = (v + pred1[x]) >> FRAC_BITS; if(v&(~255)) v= ~(v>>31); dst1[x] = v; @@ -2999,10 +2847,10 @@ static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, con if(block_w==16){ /* FIXME rearrange dsputil to fit 32x32 cmp functions */ /* FIXME check alignment of the cmp wavelet vs the encoding wavelet */ - /* FIXME cmps overlap but don't cover the wavelet's whole support, - * so improving the score of one block is not strictly guaranteed to - * improve the score of the whole frame, so iterative motion est - * doesn't always converge. */ + /* FIXME cmps overlap but do not cover the wavelet's whole support. + * So improving the score of one block is not strictly guaranteed + * to improve the score of the whole frame, thus iterative motion + * estimation does not always converge. */ if(s->avctx->me_cmp == FF_CMP_W97) distortion = w97_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); else if(s->avctx->me_cmp == FF_CMP_W53) @@ -3043,7 +2891,9 @@ static int get_4block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index){ const int ref_stride= s->current_picture.linesize[plane_index]; uint8_t *dst= s->current_picture.data[plane_index]; uint8_t *src= s-> input_picture.data[plane_index]; - static const DWTELEM zero_dst[4096]; //FIXME + //FIXME zero_dst is const but add_yblock changes dst if add is 0 (this is never the case for dst=zero_dst + // const has only been removed from zero_dst to suppress a warning + static IDWTELEM zero_dst[4096]; //FIXME const int b_stride = s->b_width << s->block_max_depth; const int w= p->width; const int h= p->height; @@ -3135,7 +2985,8 @@ static av_always_inline int check_block(SnowContext *s, int mb_x, int mb_y, int } } -/* special case for int[2] args we discard afterward, fixes compilation prob with gcc 2.95 */ +/* special case for int[2] args we discard afterwards, + * fixes compilation problem with gcc 2.95 */ static av_always_inline int check_block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, const uint8_t *obmc_edged, int *best_rd){ int p[2] = {p0, p1}; return check_block(s, mb_x, mb_y, p, 0, obmc_edged, best_rd); @@ -3227,7 +3078,7 @@ static void iterative_me(SnowContext *s){ memset(s->me_cache, 0, sizeof(s->me_cache)); s->me_cache_generation += 1<<22; - //FIXME precalc + //FIXME precalculate { int x, y; memcpy(obmc_edged, obmc_tab[s->block_max_depth], b_w*b_w*4); @@ -3282,7 +3133,7 @@ static void iterative_me(SnowContext *s){ for(i=0; i<3; i++) color[i]= get_dc(s, mb_x, mb_y, i); - // get previous score (cant be cached due to OBMC) + // get previous score (cannot be cached due to OBMC) if(pass > 0 && (block->type&BLOCK_INTRA)){ int color0[3]= {block->color[0], block->color[1], block->color[2]}; check_block(s, mb_x, mb_y, color0, 1, *obmc_edged, &best_rd); @@ -3310,7 +3161,7 @@ static void iterative_me(SnowContext *s){ check_block_inter(s, mb_x, mb_y, mvr[b_stride][0], mvr[b_stride][1], *obmc_edged, &best_rd); /* fullpel ME */ - //FIXME avoid subpel interpol / round to nearest integer + //FIXME avoid subpel interpolation / round to nearest integer do{ dia_change=0; for(i=0; iavctx->dia_size, 1); i++){ @@ -3403,16 +3254,19 @@ static void iterative_me(SnowContext *s){ } } -static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int bias){ - const int level= b->level; +static void quantize(SnowContext *s, SubBand *b, IDWTELEM *dst, DWTELEM *src, int stride, int bias){ const int w= b->width; const int h= b->height; const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); - const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); + const int qmul= qexp[qlog&(QROOT-1)]<<((qlog>>QSHIFT) + ENCODER_EXTRA_BITS); int x,y, thres1, thres2; -// START_TIMER - if(s->qlog == LOSSLESS_QLOG) return; + if(s->qlog == LOSSLESS_QLOG){ + for(y=0; y>3; thres1= ((qmul - bias)>>QEXPSHIFT) - 1; @@ -3427,15 +3281,15 @@ static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int b if(i>=0){ i<<= QEXPSHIFT; i/= qmul; //FIXME optimize - src[x + y*stride]= i; + dst[x + y*stride]= i; }else{ i= -i; i<<= QEXPSHIFT; i/= qmul; //FIXME optimize - src[x + y*stride]= -i; + dst[x + y*stride]= -i; } }else - src[x + y*stride]= 0; + dst[x + y*stride]= 0; } } }else{ @@ -3447,36 +3301,32 @@ static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int b if(i>=0){ i<<= QEXPSHIFT; i= (i + bias) / qmul; //FIXME optimize - src[x + y*stride]= i; + dst[x + y*stride]= i; }else{ i= -i; i<<= QEXPSHIFT; i= (i + bias) / qmul; //FIXME optimize - src[x + y*stride]= -i; + dst[x + y*stride]= -i; } }else - src[x + y*stride]= 0; + dst[x + y*stride]= 0; } } } - if(level+1 == s->spatial_decomposition_count){ -// STOP_TIMER("quantize") - } } -static void dequantize_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, DWTELEM *src, int stride, int start_y, int end_y){ +static void dequantize_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, IDWTELEM *src, int stride, int start_y, int end_y){ const int w= b->width; const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; int x,y; - START_TIMER if(s->qlog == LOSSLESS_QLOG) return; for(y=start_y; ystride_line) + b->buf_y_offset) + b->buf_x_offset; + IDWTELEM * line = slice_buffer_get_line(sb, (y * b->stride_line) + b->buf_y_offset) + b->buf_x_offset; for(x=0; x 200 /*level+1 == s->spatial_decomposition_count*/){ - STOP_TIMER("dquant") - } } -static void dequantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride){ +static void dequantize(SnowContext *s, SubBand *b, IDWTELEM *src, int stride){ const int w= b->width; const int h= b->height; const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; int x,y; - START_TIMER if(s->qlog == LOSSLESS_QLOG) return; @@ -3512,12 +3358,9 @@ static void dequantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride){ } } } - if(w > 200 /*level+1 == s->spatial_decomposition_count*/){ - STOP_TIMER("dquant") - } } -static void decorrelate(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int inverse, int use_median){ +static void decorrelate(SnowContext *s, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median){ const int w= b->width; const int h= b->height; int x,y; @@ -3541,14 +3384,12 @@ static void decorrelate(SnowContext *s, SubBand *b, DWTELEM *src, int stride, in } } -static void correlate_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, DWTELEM *src, int stride, int inverse, int use_median, int start_y, int end_y){ +static void correlate_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median, int start_y, int end_y){ const int w= b->width; int x,y; -// START_TIMER - - DWTELEM * line=0; // silence silly "could be used without having been initialized" warning - DWTELEM * prev; + IDWTELEM * line=0; // silence silly "could be used without having been initialized" warning + IDWTELEM * prev; if (start_y != 0) line = slice_buffer_get_line(sb, ((start_y - 1) * b->stride_line) + b->buf_y_offset) + b->buf_x_offset; @@ -3571,11 +3412,9 @@ static void correlate_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand } } } - -// STOP_TIMER("correlate") } -static void correlate(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int inverse, int use_median){ +static void correlate(SnowContext *s, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median){ const int w= b->width; const int h= b->height; int x,y; @@ -3599,8 +3438,21 @@ static void correlate(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int } } -static void encode_header(SnowContext *s){ +static void encode_qlogs(SnowContext *s){ int plane_index, level, orientation; + + for(plane_index=0; plane_index<2; plane_index++){ + for(level=0; levelspatial_decomposition_count; level++){ + for(orientation=level ? 1:0; orientation<4; orientation++){ + if(orientation==2) continue; + put_symbol(&s->c, s->header_state, s->plane[plane_index].band[level][orientation].qlog, 1); + } + } + } +} + +static void encode_header(SnowContext *s){ + int plane_index, i; uint8_t kstate[32]; memset(kstate, MID_STATE, sizeof(kstate)); @@ -3613,6 +3465,12 @@ static void encode_header(SnowContext *s){ s->last_qbias= s->last_mv_scale= s->last_block_max_depth= 0; + for(plane_index=0; plane_index<2; plane_index++){ + Plane *p= &s->plane[plane_index]; + p->last_htaps=0; + p->last_diag_mc=0; + memset(p->last_hcoeff, 0, sizeof(p->last_hcoeff)); + } } if(s->keyframe){ put_symbol(&s->c, s->header_state, s->version, 0); @@ -3627,30 +3485,81 @@ static void encode_header(SnowContext *s){ // put_rac(&s->c, s->header_state, s->rate_scalability); put_symbol(&s->c, s->header_state, s->max_ref_frames-1, 0); + encode_qlogs(s); + } + + if(!s->keyframe){ + int update_mc=0; for(plane_index=0; plane_index<2; plane_index++){ - for(level=0; levelspatial_decomposition_count; level++){ - for(orientation=level ? 1:0; orientation<4; orientation++){ - if(orientation==2) continue; - put_symbol(&s->c, s->header_state, s->plane[plane_index].band[level][orientation].qlog, 1); - } + Plane *p= &s->plane[plane_index]; + update_mc |= p->last_htaps != p->htaps; + update_mc |= p->last_diag_mc != p->diag_mc; + update_mc |= !!memcmp(p->last_hcoeff, p->hcoeff, sizeof(p->hcoeff)); + } + put_rac(&s->c, s->header_state, update_mc); + if(update_mc){ + for(plane_index=0; plane_index<2; plane_index++){ + Plane *p= &s->plane[plane_index]; + put_rac(&s->c, s->header_state, p->diag_mc); + put_symbol(&s->c, s->header_state, p->htaps/2-1, 0); + for(i= p->htaps/2; i; i--) + put_symbol(&s->c, s->header_state, FFABS(p->hcoeff[i]), 0); } } + if(s->last_spatial_decomposition_count != s->spatial_decomposition_count){ + put_rac(&s->c, s->header_state, 1); + put_symbol(&s->c, s->header_state, s->spatial_decomposition_count, 0); + encode_qlogs(s); + }else + put_rac(&s->c, s->header_state, 0); } + put_symbol(&s->c, s->header_state, s->spatial_decomposition_type - s->last_spatial_decomposition_type, 1); put_symbol(&s->c, s->header_state, s->qlog - s->last_qlog , 1); put_symbol(&s->c, s->header_state, s->mv_scale - s->last_mv_scale, 1); put_symbol(&s->c, s->header_state, s->qbias - s->last_qbias , 1); put_symbol(&s->c, s->header_state, s->block_max_depth - s->last_block_max_depth, 1); - s->last_spatial_decomposition_type= s->spatial_decomposition_type; - s->last_qlog = s->qlog; - s->last_qbias = s->qbias; - s->last_mv_scale = s->mv_scale; - s->last_block_max_depth = s->block_max_depth; } -static int decode_header(SnowContext *s){ +static void update_last_header_values(SnowContext *s){ + int plane_index; + + if(!s->keyframe){ + for(plane_index=0; plane_index<2; plane_index++){ + Plane *p= &s->plane[plane_index]; + p->last_diag_mc= p->diag_mc; + p->last_htaps = p->htaps; + memcpy(p->last_hcoeff, p->hcoeff, sizeof(p->hcoeff)); + } + } + + s->last_spatial_decomposition_type = s->spatial_decomposition_type; + s->last_qlog = s->qlog; + s->last_qbias = s->qbias; + s->last_mv_scale = s->mv_scale; + s->last_block_max_depth = s->block_max_depth; + s->last_spatial_decomposition_count = s->spatial_decomposition_count; +} + +static void decode_qlogs(SnowContext *s){ int plane_index, level, orientation; + + for(plane_index=0; plane_index<3; plane_index++){ + for(level=0; levelspatial_decomposition_count; level++){ + for(orientation=level ? 1:0; orientation<4; orientation++){ + int q; + if (plane_index==2) q= s->plane[1].band[level][orientation].qlog; + else if(orientation==2) q= s->plane[plane_index].band[level][1].qlog; + else q= get_symbol(&s->c, s->header_state, 1); + s->plane[plane_index].band[level][orientation].qlog= q; + } + } + } +} + +static int decode_header(SnowContext *s){ + int plane_index; uint8_t kstate[32]; memset(kstate, MID_STATE, sizeof(kstate)); @@ -3681,21 +3590,37 @@ static int decode_header(SnowContext *s){ // s->rate_scalability= get_rac(&s->c, s->header_state); s->max_ref_frames= get_symbol(&s->c, s->header_state, 0)+1; - for(plane_index=0; plane_index<3; plane_index++){ - for(level=0; levelspatial_decomposition_count; level++){ - for(orientation=level ? 1:0; orientation<4; orientation++){ - int q; - if (plane_index==2) q= s->plane[1].band[level][orientation].qlog; - else if(orientation==2) q= s->plane[plane_index].band[level][1].qlog; - else q= get_symbol(&s->c, s->header_state, 1); - s->plane[plane_index].band[level][orientation].qlog= q; + decode_qlogs(s); + } + + if(!s->keyframe){ + if(get_rac(&s->c, s->header_state)){ + for(plane_index=0; plane_index<2; plane_index++){ + int htaps, i, sum=0; + Plane *p= &s->plane[plane_index]; + p->diag_mc= get_rac(&s->c, s->header_state); + htaps= get_symbol(&s->c, s->header_state, 0)*2 + 2; + if((unsigned)htaps > HTAPS_MAX || htaps==0) + return -1; + p->htaps= htaps; + for(i= htaps/2; i; i--){ + p->hcoeff[i]= get_symbol(&s->c, s->header_state, 0) * (1-2*(i&1)); + sum += p->hcoeff[i]; } + p->hcoeff[0]= 32-sum; } + s->plane[2].diag_mc= s->plane[1].diag_mc; + s->plane[2].htaps = s->plane[1].htaps; + memcpy(s->plane[2].hcoeff, s->plane[1].hcoeff, sizeof(s->plane[1].hcoeff)); + } + if(get_rac(&s->c, s->header_state)){ + s->spatial_decomposition_count= get_symbol(&s->c, s->header_state, 0); + decode_qlogs(s); } } s->spatial_decomposition_type+= get_symbol(&s->c, s->header_state, 1); - if(s->spatial_decomposition_type > 2){ + if(s->spatial_decomposition_type > 1){ av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_type %d not supported", s->spatial_decomposition_type); return -1; } @@ -3726,7 +3651,6 @@ static void init_qexp(void){ static int common_init(AVCodecContext *avctx){ SnowContext *s = avctx->priv_data; int width, height; - int level, orientation, plane_index, dec; int i, j; s->avctx= avctx; @@ -3774,21 +3698,26 @@ static int common_init(AVCodecContext *avctx){ if(!qexp[0]) init_qexp(); - dec= s->spatial_decomposition_count= 5; - s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type - - s->chroma_h_shift= 1; //FIXME XXX - s->chroma_v_shift= 1; - // dec += FFMAX(s->chroma_h_shift, s->chroma_v_shift); width= s->avctx->width; height= s->avctx->height; - s->spatial_dwt_buffer= av_mallocz(width*height*sizeof(DWTELEM)); + s->spatial_idwt_buffer= av_mallocz(width*height*sizeof(IDWTELEM)); + s->spatial_dwt_buffer= av_mallocz(width*height*sizeof(DWTELEM)); //FIXME this does not belong here + + for(i=0; iavctx->get_buffer(s->avctx, &s->mconly_picture); - s->mv_scale= (s->avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4; - s->block_max_depth= (s->avctx->flags & CODEC_FLAG_4MV) ? 1 : 0; + return 0; +} + +static int common_init_after_header(AVCodecContext *avctx){ + SnowContext *s = avctx->priv_data; + int plane_index, level, orientation; for(plane_index=0; plane_index<3; plane_index++){ int w= s->avctx->width; @@ -3800,7 +3729,7 @@ static int common_init(AVCodecContext *avctx){ } s->plane[plane_index].width = w; s->plane[plane_index].height= h; -//av_log(NULL, AV_LOG_DEBUG, "%d %d\n", w, h); + for(level=s->spatial_decomposition_count-1; level>=0; level--){ for(orientation=level ? 1 : 0; orientation<4; orientation++){ SubBand *b= &s->plane[plane_index].band[level][orientation]; @@ -3823,9 +3752,12 @@ static int common_init(AVCodecContext *avctx){ b->buf += b->stride>>1; b->buf_y_offset = b->stride_line >> 1; } + b->ibuf= s->spatial_idwt_buffer + (b->buf - s->spatial_dwt_buffer); if(level) b->parent= &s->plane[plane_index].band[level-1][orientation]; + //FIXME avoid this realloc + av_freep(&b->x_coeff); b->x_coeff=av_mallocz(((b->width+1) * b->height+1)*sizeof(x_and_coeff)); } w= (w+1)>>1; @@ -3833,19 +3765,6 @@ static int common_init(AVCodecContext *avctx){ } } - for(i=0; iwidth= avctx->width; - height= s->height= avctx->height; - - assert(width && height); -*/ - s->avctx->get_buffer(s->avctx, &s->mconly_picture); - return 0; } @@ -3856,7 +3775,7 @@ static int qscale2qlog(int qscale){ static int ratecontrol_1pass(SnowContext *s, AVFrame *pict) { - /* estimate the frame's complexity as a sum of weighted dwt coefs. + /* Estimate the frame's complexity as a sum of weighted dwt coefficients. * FIXME we know exact mv bits at this point, * but ratecontrol isn't set up to include them. */ uint32_t coef_sum= 0; @@ -3865,7 +3784,7 @@ static int ratecontrol_1pass(SnowContext *s, AVFrame *pict) for(level=0; levelspatial_decomposition_count; level++){ for(orientation=level ? 1 : 0; orientation<4; orientation++){ SubBand *b= &s->plane[0].band[level][orientation]; - DWTELEM *buf= b->buf; + IDWTELEM *buf= b->ibuf; const int w= b->width; const int h= b->height; const int stride= b->stride; @@ -3873,13 +3792,15 @@ static int ratecontrol_1pass(SnowContext *s, AVFrame *pict) const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); const int qdiv= (1<<16)/qmul; int x, y; + //FIXME this is ugly + for(y=0; ybuf[x+y*stride]; if(orientation==0) decorrelate(s, b, buf, stride, 1, 0); for(y=0; y> 16; - if(orientation==0) - correlate(s, b, buf, stride, 1, 0); } } @@ -3904,7 +3825,7 @@ static int ratecontrol_1pass(SnowContext *s, AVFrame *pict) return delta_qlog; } -static void calculate_vissual_weight(SnowContext *s, Plane *p){ +static void calculate_visual_weight(SnowContext *s, Plane *p){ int width = p->width; int height= p->height; int level, orientation, x, y; @@ -3912,43 +3833,176 @@ static void calculate_vissual_weight(SnowContext *s, Plane *p){ for(level=0; levelspatial_decomposition_count; level++){ for(orientation=level ? 1 : 0; orientation<4; orientation++){ SubBand *b= &p->band[level][orientation]; - DWTELEM *buf= b->buf; + IDWTELEM *ibuf= b->ibuf; int64_t error=0; - memset(s->spatial_dwt_buffer, 0, sizeof(int)*width*height); - buf[b->width/2 + b->height/2*b->stride]= 256*256; - ff_spatial_idwt(s->spatial_dwt_buffer, width, height, width, s->spatial_decomposition_type, s->spatial_decomposition_count); + memset(s->spatial_idwt_buffer, 0, sizeof(*s->spatial_idwt_buffer)*width*height); + ibuf[b->width/2 + b->height/2*b->stride]= 256*16; + ff_spatial_idwt(s->spatial_idwt_buffer, width, height, width, s->spatial_decomposition_type, s->spatial_decomposition_count); for(y=0; yspatial_dwt_buffer[x + y*width]; + int64_t d= s->spatial_idwt_buffer[x + y*width]*16; error += d*d; } } b->qlog= (int)(log(352256.0/sqrt(error)) / log(pow(2.0, 1.0/QROOT))+0.5); -// av_log(NULL, AV_LOG_DEBUG, "%d %d %d\n", level, orientation, b->qlog/*, sqrt(error)*/); } } } +#define QUANTIZE2 0 + +#if QUANTIZE2==1 +#define Q2_STEP 8 + +static void find_sse(SnowContext *s, Plane *p, int *score, int score_stride, IDWTELEM *r0, IDWTELEM *r1, int level, int orientation){ + SubBand *b= &p->band[level][orientation]; + int x, y; + int xo=0; + int yo=0; + int step= 1 << (s->spatial_decomposition_count - level); + + if(orientation&1) + xo= step>>1; + if(orientation&2) + yo= step>>1; + + //FIXME bias for nonzero ? + //FIXME optimize + memset(score, 0, sizeof(*score)*score_stride*((p->height + Q2_STEP-1)/Q2_STEP)); + for(y=0; yheight; y++){ + for(x=0; xwidth; x++){ + int sx= (x-xo + step/2) / step / Q2_STEP; + int sy= (y-yo + step/2) / step / Q2_STEP; + int v= r0[x + y*p->width] - r1[x + y*p->width]; + assert(sx>=0 && sy>=0 && sx < score_stride); + v= ((v+8)>>4)<<4; + score[sx + sy*score_stride] += v*v; + assert(score[sx + sy*score_stride] >= 0); + } + } +} + +static void dequantize_all(SnowContext *s, Plane *p, IDWTELEM *buffer, int width, int height){ + int level, orientation; + + for(level=0; levelspatial_decomposition_count; level++){ + for(orientation=level ? 1 : 0; orientation<4; orientation++){ + SubBand *b= &p->band[level][orientation]; + IDWTELEM *dst= buffer + (b->ibuf - s->spatial_idwt_buffer); + + dequantize(s, b, dst, b->stride); + } + } +} + +static void dwt_quantize(SnowContext *s, Plane *p, DWTELEM *buffer, int width, int height, int stride, int type){ + int level, orientation, ys, xs, x, y, pass; + IDWTELEM best_dequant[height * stride]; + IDWTELEM idwt2_buffer[height * stride]; + const int score_stride= (width + 10)/Q2_STEP; + int best_score[(width + 10)/Q2_STEP * (height + 10)/Q2_STEP]; //FIXME size + int score[(width + 10)/Q2_STEP * (height + 10)/Q2_STEP]; //FIXME size + int threshold= (s->m.lambda * s->m.lambda) >> 6; + + //FIXME pass the copy cleanly ? + +// memcpy(dwt_buffer, buffer, height * stride * sizeof(DWTELEM)); + ff_spatial_dwt(buffer, width, height, stride, type, s->spatial_decomposition_count); + + for(level=0; levelspatial_decomposition_count; level++){ + for(orientation=level ? 1 : 0; orientation<4; orientation++){ + SubBand *b= &p->band[level][orientation]; + IDWTELEM *dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); + DWTELEM *src= buffer + (b-> buf - s->spatial_dwt_buffer); + assert(src == b->buf); // code does not depend on this but it is true currently + + quantize(s, b, dst, src, b->stride, s->qbias); + } + } + for(pass=0; pass<1; pass++){ + if(s->qbias == 0) //keyframe + continue; + for(level=0; levelspatial_decomposition_count; level++){ + for(orientation=level ? 1 : 0; orientation<4; orientation++){ + SubBand *b= &p->band[level][orientation]; + IDWTELEM *dst= idwt2_buffer + (b->ibuf - s->spatial_idwt_buffer); + IDWTELEM *best_dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); + + for(ys= 0; ysspatial_decomposition_count); + find_sse(s, p, best_score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); + memcpy(idwt2_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); + for(y=ys; yheight; y+= Q2_STEP){ + for(x=xs; xwidth; x+= Q2_STEP){ + if(dst[x + y*b->stride]<0) dst[x + y*b->stride]++; + if(dst[x + y*b->stride]>0) dst[x + y*b->stride]--; + //FIXME try more than just -- + } + } + dequantize_all(s, p, idwt2_buffer, width, height); + ff_spatial_idwt(idwt2_buffer, width, height, stride, type, s->spatial_decomposition_count); + find_sse(s, p, score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); + for(y=ys; yheight; y+= Q2_STEP){ + for(x=xs; xwidth; x+= Q2_STEP){ + int score_idx= x/Q2_STEP + (y/Q2_STEP)*score_stride; + if(score[score_idx] <= best_score[score_idx] + threshold){ + best_score[score_idx]= score[score_idx]; + if(best_dst[x + y*b->stride]<0) best_dst[x + y*b->stride]++; + if(best_dst[x + y*b->stride]>0) best_dst[x + y*b->stride]--; + //FIXME copy instead + } + } + } + } + } + } + } + } + memcpy(s->spatial_idwt_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); //FIXME work with that directly instead of copy at the end +} + +#endif /* QUANTIZE2==1 */ + static int encode_init(AVCodecContext *avctx) { SnowContext *s = avctx->priv_data; int plane_index; if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ - av_log(avctx, AV_LOG_ERROR, "this codec is under development, files encoded with it may not be decodable with future versions!!!\n" - "use vstrict=-2 / -strict -2 to use it anyway\n"); + av_log(avctx, AV_LOG_ERROR, "This codec is under development, files encoded with it may not be decodable with future versions!!!\n" + "Use vstrict=-2 / -strict -2 to use it anyway.\n"); return -1; } if(avctx->prediction_method == DWT_97 && (avctx->flags & CODEC_FLAG_QSCALE) && avctx->global_quality == 0){ - av_log(avctx, AV_LOG_ERROR, "the 9/7 wavelet is incompatible with lossless mode\n"); + av_log(avctx, AV_LOG_ERROR, "The 9/7 wavelet is incompatible with lossless mode.\n"); return -1; } + s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type + + s->chroma_h_shift= 1; //FIXME XXX + s->chroma_v_shift= 1; + + s->mv_scale = (avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4; + s->block_max_depth= (avctx->flags & CODEC_FLAG_4MV ) ? 1 : 0; + + for(plane_index=0; plane_index<3; plane_index++){ + s->plane[plane_index].diag_mc= 1; + s->plane[plane_index].htaps= 6; + s->plane[plane_index].hcoeff[0]= 40; + s->plane[plane_index].hcoeff[1]= -10; + s->plane[plane_index].hcoeff[2]= 2; + s->plane[plane_index].fast_mc= 1; + } + common_init(avctx); alloc_blocks(s); @@ -3976,11 +4030,6 @@ static int encode_init(AVCodecContext *avctx) } s->pass1_rc= !(avctx->flags & (CODEC_FLAG_QSCALE|CODEC_FLAG_PASS2)); - for(plane_index=0; plane_index<3; plane_index++){ - calculate_vissual_weight(s, &s->plane[plane_index]); - } - - avctx->coded_frame= &s->current_picture; switch(avctx->pix_fmt){ // case PIX_FMT_YUV444P: @@ -3995,7 +4044,7 @@ static int encode_init(AVCodecContext *avctx) s->colorspace= 1; break;*/ default: - av_log(avctx, AV_LOG_ERROR, "format not supported\n"); + av_log(avctx, AV_LOG_ERROR, "pixel format not supported\n"); return -1; } // avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift); @@ -4019,6 +4068,52 @@ static int encode_init(AVCodecContext *avctx) return 0; } +#define USE_HALFPEL_PLANE 0 + +static void halfpel_interpol(SnowContext *s, uint8_t *halfpel[4][4], AVFrame *frame){ + int p,x,y; + + assert(!(s->avctx->flags & CODEC_FLAG_EMU_EDGE)); + + for(p=0; p<3; p++){ + int is_chroma= !!p; + int w= s->avctx->width >>is_chroma; + int h= s->avctx->height >>is_chroma; + int ls= frame->linesize[p]; + uint8_t *src= frame->data[p]; + + halfpel[1][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); + halfpel[2][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); + halfpel[3][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); + + halfpel[0][p]= src; + for(y=0; y>5; + } + } + for(y=0; y>5; + } + } + src= halfpel[1][p]; + for(y=0; y>5; + } + } + +//FIXME border! + } +} + static int frame_start(SnowContext *s){ AVFrame tmp; int w= s->avctx->width; //FIXME round up to x16 ? @@ -4032,6 +4127,9 @@ static int frame_start(SnowContext *s){ tmp= s->last_picture[s->max_ref_frames-1]; memmove(s->last_picture+1, s->last_picture, (s->max_ref_frames-1)*sizeof(AVFrame)); + memmove(s->halfpel_plane+1, s->halfpel_plane, (s->max_ref_frames-1)*sizeof(void*)*4*4); + if(USE_HALFPEL_PLANE && s->current_picture.data[0]) + halfpel_interpol(s, s->halfpel_plane[0], &s->current_picture); s->last_picture[0]= s->current_picture; s->current_picture= tmp; @@ -4103,7 +4201,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, if(s->qlog < 0 || (!pict->quality && (avctx->flags & CODEC_FLAG_QSCALE))){ s->qlog= LOSSLESS_QLOG; s->lambda = 0; - }//else keep previous frame's qlog until after motion est + }//else keep previous frame's qlog until after motion estimation frame_start(s); @@ -4157,9 +4255,22 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, redo_frame: + if(pict->pict_type == I_TYPE) + s->spatial_decomposition_count= 5; + else + s->spatial_decomposition_count= 5; + s->m.pict_type = pict->pict_type; s->qbias= pict->pict_type == P_TYPE ? 2 : 0; + common_init_after_header(avctx); + + if(s->last_spatial_decomposition_count != s->spatial_decomposition_count){ + for(plane_index=0; plane_index<3; plane_index++){ + calculate_visual_weight(s, &s->plane[plane_index]); + } + } + encode_header(s); s->m.misc_bits = 8*(s->c.bytestream - s->c.bytestream_start); encode_blocks(s, 1); @@ -4172,87 +4283,94 @@ redo_frame: int x, y; // int bits= put_bits_count(&s->c.pb); - if(!(avctx->flags2 & CODEC_FLAG2_MEMC_ONLY)){ - //FIXME optimize - if(pict->data[plane_index]) //FIXME gray hack - for(y=0; yspatial_dwt_buffer[y*w + x]= pict->data[plane_index][y*pict->linesize[plane_index] + x]<flags2 & CODEC_FLAG2_MEMC_ONLY)){ + //FIXME optimize + if(pict->data[plane_index]) //FIXME gray hack + for(y=0; yspatial_idwt_buffer[y*w + x]= pict->data[plane_index][y*pict->linesize[plane_index] + x]<spatial_idwt_buffer, plane_index, 0); + + if( plane_index==0 + && pict->pict_type == P_TYPE + && !(avctx->flags&CODEC_FLAG_PASS2) + && s->m.me.scene_change_score > s->avctx->scenechange_threshold){ + ff_init_range_encoder(c, buf, buf_size); + ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); + pict->pict_type= FF_I_TYPE; + s->keyframe=1; + s->current_picture.key_frame=1; + goto redo_frame; } - } - predict_plane(s, s->spatial_dwt_buffer, plane_index, 0); - - if( plane_index==0 - && pict->pict_type == P_TYPE - && !(avctx->flags&CODEC_FLAG_PASS2) - && s->m.me.scene_change_score > s->avctx->scenechange_threshold){ - ff_init_range_encoder(c, buf, buf_size); - ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); - pict->pict_type= FF_I_TYPE; - s->keyframe=1; - s->current_picture.key_frame=1; - goto redo_frame; - } - if(s->qlog == LOSSLESS_QLOG){ - for(y=0; yspatial_dwt_buffer[y*w + x]= (s->spatial_dwt_buffer[y*w + x] + (1<<(FRAC_BITS-1))-1)>>FRAC_BITS; + if(s->qlog == LOSSLESS_QLOG){ + for(y=0; yspatial_dwt_buffer[y*w + x]= (s->spatial_idwt_buffer[y*w + x] + (1<<(FRAC_BITS-1))-1)>>FRAC_BITS; + } + } + }else{ + for(y=0; yspatial_dwt_buffer[y*w + x]=s->spatial_idwt_buffer[y*w + x]<spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); - if(s->pass1_rc && plane_index==0){ - int delta_qlog = ratecontrol_1pass(s, pict); - if (delta_qlog <= INT_MIN) - return -1; - if(delta_qlog){ - //reordering qlog in the bitstream would eliminate this reset - ff_init_range_encoder(c, buf, buf_size); - memcpy(s->header_state, rc_header_bak, sizeof(s->header_state)); - memcpy(s->block_state, rc_block_bak, sizeof(s->block_state)); - encode_header(s); - encode_blocks(s, 0); + /* if(QUANTIZE2) + dwt_quantize(s, p, s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type); + else*/ + ff_spatial_dwt(s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); + + if(s->pass1_rc && plane_index==0){ + int delta_qlog = ratecontrol_1pass(s, pict); + if (delta_qlog <= INT_MIN) + return -1; + if(delta_qlog){ + //reordering qlog in the bitstream would eliminate this reset + ff_init_range_encoder(c, buf, buf_size); + memcpy(s->header_state, rc_header_bak, sizeof(s->header_state)); + memcpy(s->block_state, rc_block_bak, sizeof(s->block_state)); + encode_header(s); + encode_blocks(s, 0); + } } - } - - for(level=0; levelspatial_decomposition_count; level++){ - for(orientation=level ? 1 : 0; orientation<4; orientation++){ - SubBand *b= &p->band[level][orientation]; - quantize(s, b, b->buf, b->stride, s->qbias); - if(orientation==0) - decorrelate(s, b, b->buf, b->stride, pict->pict_type == P_TYPE, 0); - encode_subband(s, b, b->buf, b->parent ? b->parent->buf : NULL, b->stride, orientation); - assert(b->parent==NULL || b->parent->stride == b->stride*2); - if(orientation==0) - correlate(s, b, b->buf, b->stride, 1, 0); + for(level=0; levelspatial_decomposition_count; level++){ + for(orientation=level ? 1 : 0; orientation<4; orientation++){ + SubBand *b= &p->band[level][orientation]; + + if(!QUANTIZE2) + quantize(s, b, b->ibuf, b->buf, b->stride, s->qbias); + if(orientation==0) + decorrelate(s, b, b->ibuf, b->stride, pict->pict_type == P_TYPE, 0); + encode_subband(s, b, b->ibuf, b->parent ? b->parent->ibuf : NULL, b->stride, orientation); + assert(b->parent==NULL || b->parent->stride == b->stride*2); + if(orientation==0) + correlate(s, b, b->ibuf, b->stride, 1, 0); + } } - } -// av_log(NULL, AV_LOG_DEBUG, "plane:%d bits:%d\n", plane_index, put_bits_count(&s->c.pb) - bits); - for(level=0; levelspatial_decomposition_count; level++){ - for(orientation=level ? 1 : 0; orientation<4; orientation++){ - SubBand *b= &p->band[level][orientation]; + for(level=0; levelspatial_decomposition_count; level++){ + for(orientation=level ? 1 : 0; orientation<4; orientation++){ + SubBand *b= &p->band[level][orientation]; - dequantize(s, b, b->buf, b->stride); + dequantize(s, b, b->ibuf, b->stride); + } } - } - ff_spatial_idwt(s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); - if(s->qlog == LOSSLESS_QLOG){ - for(y=0; yspatial_dwt_buffer[y*w + x]<<=FRAC_BITS; + ff_spatial_idwt(s->spatial_idwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); + if(s->qlog == LOSSLESS_QLOG){ + for(y=0; yspatial_idwt_buffer[y*w + x]<<=FRAC_BITS; + } } } - } -{START_TIMER - predict_plane(s, s->spatial_dwt_buffer, plane_index, 1); -STOP_TIMER("pred-conv")} - }else{ + predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); + }else{ //ME/MC only if(pict->pict_type == I_TYPE){ for(y=0; yspatial_dwt_buffer, 0, sizeof(DWTELEM)*w*h); - predict_plane(s, s->spatial_dwt_buffer, plane_index, 1); + memset(s->spatial_idwt_buffer, 0, sizeof(IDWTELEM)*w*h); + predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); } - } + } if(s->avctx->flags&CODEC_FLAG_PSNR){ int64_t error= 0; - if(pict->data[plane_index]) //FIXME gray hack - for(y=0; ycurrent_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x] - pict->data[plane_index][y*pict->linesize[plane_index] + x]; - error += d*d; + if(pict->data[plane_index]) //FIXME gray hack + for(y=0; ycurrent_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x] - pict->data[plane_index][y*pict->linesize[plane_index] + x]; + error += d*d; + } } - } s->avctx->error[plane_index] += error; s->current_picture.error[plane_index] = error; } + } - if(s->last_picture[s->max_ref_frames-1].data[0]) + update_last_header_values(s); + + if(s->last_picture[s->max_ref_frames-1].data[0]){ avctx->release_buffer(avctx, &s->last_picture[s->max_ref_frames-1]); + for(i=0; i<9; i++) + if(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3]) + av_free(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3] - EDGE_WIDTH*(1+s->current_picture.linesize[i%3])); + } s->current_picture.coded_picture_number = avctx->frame_number; s->current_picture.pict_type = pict->pict_type; @@ -4313,6 +4438,7 @@ static void common_end(SnowContext *s){ int plane_index, level, orientation, i; av_freep(&s->spatial_dwt_buffer); + av_freep(&s->spatial_idwt_buffer); av_freep(&s->m.me.scratchpad); av_freep(&s->m.me.map); @@ -4351,35 +4477,43 @@ static int encode_end(AVCodecContext *avctx) static int decode_init(AVCodecContext *avctx) { - SnowContext *s = avctx->priv_data; - int block_size; - avctx->pix_fmt= PIX_FMT_YUV420P; common_init(avctx); - block_size = MB_SIZE >> s->block_max_depth; - slice_buffer_init(&s->sb, s->plane[0].height, (block_size) + (s->spatial_decomposition_count * (s->spatial_decomposition_count + 3)) + 1, s->plane[0].width, s->spatial_dwt_buffer); - return 0; } -static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size){ +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size){ SnowContext *s = avctx->priv_data; RangeCoder * const c= &s->c; int bytes_read; AVFrame *picture = data; - int level, orientation, plane_index; + int level, orientation, plane_index, i; ff_init_range_decoder(c, buf, buf_size); ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); s->current_picture.pict_type= FF_I_TYPE; //FIXME I vs. P - decode_header(s); + if(decode_header(s)<0) + return -1; + common_init_after_header(avctx); + + // realloc slice buffer for the case that spatial_decomposition_count changed + slice_buffer_destroy(&s->sb); + slice_buffer_init(&s->sb, s->plane[0].height, (MB_SIZE >> s->block_max_depth) + s->spatial_decomposition_count * 8 + 1, s->plane[0].width, s->spatial_idwt_buffer); + + for(plane_index=0; plane_index<3; plane_index++){ + Plane *p= &s->plane[plane_index]; + p->fast_mc= p->diag_mc && p->htaps==6 && p->hcoeff[0]==40 + && p->hcoeff[1]==-10 + && p->hcoeff[2]==2; + } + if(!s->block) alloc_blocks(s); frame_start(s); - //keyframe flag dupliaction mess FIXME + //keyframe flag duplication mess FIXME if(avctx->debug&FF_DEBUG_PICT_INFO) av_log(avctx, AV_LOG_ERROR, "keyframe:%d qlog:%d\n", s->keyframe, s->qlog); @@ -4392,122 +4526,118 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 int x, y; int decode_state[MAX_DECOMPOSITIONS][4][1]; /* Stored state info for unpack_coeffs. 1 variable per instance. */ -if(s->avctx->debug&2048){ - memset(s->spatial_dwt_buffer, 0, sizeof(DWTELEM)*w*h); - predict_plane(s, s->spatial_dwt_buffer, plane_index, 1); + if(s->avctx->debug&2048){ + memset(s->spatial_dwt_buffer, 0, sizeof(DWTELEM)*w*h); + predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); - for(y=0; ycurrent_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]; - s->mconly_picture.data[plane_index][y*s->mconly_picture.linesize[plane_index] + x]= v; + for(y=0; ycurrent_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]; + s->mconly_picture.data[plane_index][y*s->mconly_picture.linesize[plane_index] + x]= v; + } } } -} - -{ START_TIMER - for(level=0; levelspatial_decomposition_count; level++){ - for(orientation=level ? 1 : 0; orientation<4; orientation++){ - SubBand *b= &p->band[level][orientation]; - unpack_coeffs(s, b, b->parent, orientation); - } - } - STOP_TIMER("unpack coeffs"); -} - -{START_TIMER - const int mb_h= s->b_height << s->block_max_depth; - const int block_size = MB_SIZE >> s->block_max_depth; - const int block_w = plane_index ? block_size/2 : block_size; - int mb_y; - dwt_compose_t cs[MAX_DECOMPOSITIONS]; - int yd=0, yq=0; - int y; - int end_y; - - ff_spatial_idwt_buffered_init(cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count); - for(mb_y=0; mb_y<=mb_h; mb_y++){ - - int slice_starty = block_w*mb_y; - int slice_h = block_w*(mb_y+1); - if (!(s->keyframe || s->avctx->debug&512)){ - slice_starty = FFMAX(0, slice_starty - (block_w >> 1)); - slice_h -= (block_w >> 1); - } { - START_TIMER for(level=0; levelspatial_decomposition_count; level++){ for(orientation=level ? 1 : 0; orientation<4; orientation++){ SubBand *b= &p->band[level][orientation]; - int start_y; - int end_y; - int our_mb_start = mb_y; - int our_mb_end = (mb_y + 1); - const int extra= 3; - start_y = (mb_y ? ((block_w * our_mb_start) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra: 0); - end_y = (((block_w * our_mb_end) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra); - if (!(s->keyframe || s->avctx->debug&512)){ - start_y = FFMAX(0, start_y - (block_w >> (1+s->spatial_decomposition_count - level))); - end_y = FFMAX(0, end_y - (block_w >> (1+s->spatial_decomposition_count - level))); - } - start_y = FFMIN(b->height, start_y); - end_y = FFMIN(b->height, end_y); - - if (start_y != end_y){ - if (orientation == 0){ - SubBand * correlate_band = &p->band[0][0]; - int correlate_end_y = FFMIN(b->height, end_y + 1); - int correlate_start_y = FFMIN(b->height, (start_y ? start_y + 1 : 0)); - decode_subband_slice_buffered(s, correlate_band, &s->sb, correlate_start_y, correlate_end_y, decode_state[0][0]); - correlate_slice_buffered(s, &s->sb, correlate_band, correlate_band->buf, correlate_band->stride, 1, 0, correlate_start_y, correlate_end_y); - dequantize_slice_buffered(s, &s->sb, correlate_band, correlate_band->buf, correlate_band->stride, start_y, end_y); - } - else - decode_subband_slice_buffered(s, b, &s->sb, start_y, end_y, decode_state[level][orientation]); - } + unpack_coeffs(s, b, b->parent, orientation); } } - STOP_TIMER("decode_subband_slice"); } -{ START_TIMER - for(; yddsp, cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count, yd); - } - STOP_TIMER("idwt slice");} + { + const int mb_h= s->b_height << s->block_max_depth; + const int block_size = MB_SIZE >> s->block_max_depth; + const int block_w = plane_index ? block_size/2 : block_size; + int mb_y; + dwt_compose_t cs[MAX_DECOMPOSITIONS]; + int yd=0, yq=0; + int y; + int end_y; + ff_spatial_idwt_buffered_init(cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count); + for(mb_y=0; mb_y<=mb_h; mb_y++){ - if(s->qlog == LOSSLESS_QLOG){ - for(; yqsb, yq); - for(x=0; xkeyframe || s->avctx->debug&512)){ + slice_starty = FFMAX(0, slice_starty - (block_w >> 1)); + slice_h -= (block_w >> 1); + } + + for(level=0; levelspatial_decomposition_count; level++){ + for(orientation=level ? 1 : 0; orientation<4; orientation++){ + SubBand *b= &p->band[level][orientation]; + int start_y; + int end_y; + int our_mb_start = mb_y; + int our_mb_end = (mb_y + 1); + const int extra= 3; + start_y = (mb_y ? ((block_w * our_mb_start) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra: 0); + end_y = (((block_w * our_mb_end) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra); + if (!(s->keyframe || s->avctx->debug&512)){ + start_y = FFMAX(0, start_y - (block_w >> (1+s->spatial_decomposition_count - level))); + end_y = FFMAX(0, end_y - (block_w >> (1+s->spatial_decomposition_count - level))); + } + start_y = FFMIN(b->height, start_y); + end_y = FFMIN(b->height, end_y); + + if (start_y != end_y){ + if (orientation == 0){ + SubBand * correlate_band = &p->band[0][0]; + int correlate_end_y = FFMIN(b->height, end_y + 1); + int correlate_start_y = FFMIN(b->height, (start_y ? start_y + 1 : 0)); + decode_subband_slice_buffered(s, correlate_band, &s->sb, correlate_start_y, correlate_end_y, decode_state[0][0]); + correlate_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, 1, 0, correlate_start_y, correlate_end_y); + dequantize_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, start_y, end_y); + } + else + decode_subband_slice_buffered(s, b, &s->sb, start_y, end_y, decode_state[level][orientation]); + } } } - } - predict_slice_buffered(s, &s->sb, s->spatial_dwt_buffer, plane_index, 1, mb_y); + for(; yddsp, cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count, yd); + } - y = FFMIN(p->height, slice_starty); - end_y = FFMIN(p->height, slice_h); - while(y < end_y) - slice_buffer_release(&s->sb, y++); - } + if(s->qlog == LOSSLESS_QLOG){ + for(; yqsb, yq); + for(x=0; xsb, s->spatial_idwt_buffer, plane_index, 1, mb_y); - slice_buffer_flush(&s->sb); + y = FFMIN(p->height, slice_starty); + end_y = FFMIN(p->height, slice_h); + while(y < end_y) + slice_buffer_release(&s->sb, y++); + } + + slice_buffer_flush(&s->sb); + } -STOP_TIMER("idwt + predict_slices")} } emms_c(); - if(s->last_picture[s->max_ref_frames-1].data[0]) + if(s->last_picture[s->max_ref_frames-1].data[0]){ avctx->release_buffer(avctx, &s->last_picture[s->max_ref_frames-1]); + for(i=0; i<9; i++) + if(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3]) + av_free(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3] - EDGE_WIDTH*(1+s->current_picture.linesize[i%3])); + } -if(!(s->avctx->debug&2048)) - *picture= s->current_picture; -else - *picture= s->mconly_picture; + if(!(s->avctx->debug&2048)) + *picture= s->current_picture; + else + *picture= s->mconly_picture; *data_size = sizeof(AVFrame); @@ -4541,7 +4671,7 @@ AVCodec snow_decoder = { NULL }; -#ifdef CONFIG_ENCODERS +#ifdef CONFIG_SNOW_ENCODER AVCodec snow_encoder = { "snow", CODEC_TYPE_VIDEO, @@ -4554,12 +4684,13 @@ AVCodec snow_encoder = { #endif -#if 0 +#ifdef TEST #undef malloc #undef free #undef printf +#undef random -int main(){ +int main(void){ int width=256; int height=256; int buffer[2][width*height]; @@ -4596,9 +4727,7 @@ int main(){ ff_init_cabac_states(&s.c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64); for(i=-256; i<256; i++){ -START_TIMER put_symbol(&s.c, s.header_state, i*i*i/3*FFABS(i), 1); -STOP_TIMER("put_symbol") } ff_rac_terminate(&s.c); @@ -4608,62 +4737,59 @@ STOP_TIMER("put_symbol") for(i=-256; i<256; i++){ int j; -START_TIMER j= get_symbol(&s.c, s.header_state, 1); -STOP_TIMER("get_symbol") if(j!=i*i*i/3*FFABS(i)) printf("fsck: %d != %d\n", i, j); } #endif -{ -int level, orientation, x, y; -int64_t errors[8][4]; -int64_t g=0; - - memset(errors, 0, sizeof(errors)); - s.spatial_decomposition_count=3; - s.spatial_decomposition_type=0; - for(level=0; level> (s.spatial_decomposition_count-level); - int h= height >> (s.spatial_decomposition_count-level); - int stride= width << (s.spatial_decomposition_count-level); - DWTELEM *buf= buffer[0]; - int64_t error=0; - - if(orientation&1) buf+=w; - if(orientation>1) buf+=stride>>1; + { + int level, orientation, x, y; + int64_t errors[8][4]; + int64_t g=0; - memset(buffer[0], 0, sizeof(int)*width*height); - buf[w/2 + h/2*stride]= 256*256; - ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count); - for(y=0; y> (s.spatial_decomposition_count-level); + int h= height >> (s.spatial_decomposition_count-level); + int stride= width << (s.spatial_decomposition_count-level); + DWTELEM *buf= buffer[0]; + int64_t error=0; + + if(orientation&1) buf+=w; + if(orientation>1) buf+=stride>>1; + + memset(buffer[0], 0, sizeof(int)*width*height); + buf[w/2 + h/2*stride]= 256*256; + ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count); + for(y=0; y> (s.spatial_decomposition_count-level); - int h= height >> (s.spatial_decomposition_count-level); + //int h= height >> (s.spatial_decomposition_count-level); int stride= width << (s.spatial_decomposition_count-level); DWTELEM *buf= buffer[0]; int64_t error=0; @@ -4697,10 +4823,9 @@ int64_t g=0; } if(FFABS(height/2-y)<9) printf("\n"); } - } + } -} + } return 0; } -#endif - +#endif /* TEST */ diff --git a/contrib/ffmpeg/libavcodec/snow.h b/contrib/ffmpeg/libavcodec/snow.h index d75d6e3e0..e9b988986 100644 --- a/contrib/ffmpeg/libavcodec/snow.h +++ b/contrib/ffmpeg/libavcodec/snow.h @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _SNOW_H -#define _SNOW_H +#ifndef FFMPEG_SNOW_H +#define FFMPEG_SNOW_H #include "dsputil.h" @@ -31,7 +31,7 @@ #define QSHIFT 5 #define QROOT (1<=0; (*i)-=2){ low[(*i)+1] = high[(*i)>>1]; low[*i] = low[(*i)>>1]; } } -static av_always_inline void snow_horizontal_compose_lift_lead_out(int i, DWTELEM * dst, DWTELEM * src, DWTELEM * ref, int width, int w, int lift_high, int mul, int add, int shift){ +static av_always_inline void snow_horizontal_compose_lift_lead_out(int i, IDWTELEM * dst, IDWTELEM * src, IDWTELEM * ref, int width, int w, int lift_high, int mul, int add, int shift){ for(; i> shift); } @@ -163,14 +161,14 @@ static av_always_inline void snow_horizontal_compose_lift_lead_out(int i, DWTELE } } -static av_always_inline void snow_horizontal_compose_liftS_lead_out(int i, DWTELEM * dst, DWTELEM * src, DWTELEM * ref, int width, int w){ +static av_always_inline void snow_horizontal_compose_liftS_lead_out(int i, IDWTELEM * dst, IDWTELEM * src, IDWTELEM * ref, int width, int w){ for(; i> W_BS); + dst[i] = src[i] + ((ref[i] + ref[(i+1)]+W_BO + 4 * src[i]) >> W_BS); } if(width&1){ - dst[w] = src[w] - (((-2 * ref[w] + W_BO) - 4 * src[w]) >> W_BS); + dst[w] = src[w] + ((2 * ref[w] + W_BO + 4 * src[w]) >> W_BS); } } -#endif +#endif /* FFMPEG_SNOW_H */ diff --git a/contrib/ffmpeg/libavcodec/sonic.c b/contrib/ffmpeg/libavcodec/sonic.c index f3388589b..9e193d469 100644 --- a/contrib/ffmpeg/libavcodec/sonic.c +++ b/contrib/ffmpeg/libavcodec/sonic.c @@ -851,7 +851,7 @@ static int sonic_decode_close(AVCodecContext *avctx) static int sonic_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { SonicContext *s = avctx->priv_data; GetBitContext gb; @@ -926,14 +926,7 @@ static int sonic_decode_frame(AVCodecContext *avctx, // internal -> short for (i = 0; i < s->frame_size; i++) - { - if (s->int_samples[i] > 32767) - samples[i] = 32767; - else if (s->int_samples[i] < -32768) - samples[i] = -32768; - else - samples[i] = s->int_samples[i]; - } + samples[i] = av_clip_int16(s->int_samples[i]); align_get_bits(&gb); diff --git a/contrib/ffmpeg/libavcodec/sp5x.h b/contrib/ffmpeg/libavcodec/sp5x.h index 0d0d3551f..e93408b34 100644 --- a/contrib/ffmpeg/libavcodec/sp5x.h +++ b/contrib/ffmpeg/libavcodec/sp5x.h @@ -19,8 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef SP5X_H -#define SP5X_H +#ifndef FFMPEG_SP5X_H +#define FFMPEG_SP5X_H + +#include static const uint8_t sp5x_data_sof[] = { @@ -329,4 +331,4 @@ static const uint8_t sp5x_quant_table_orig[18][64] = }; #endif -#endif /* SP5X_H */ +#endif /* FFMPEG_SP5X_H */ diff --git a/contrib/ffmpeg/libavcodec/sp5xdec.c b/contrib/ffmpeg/libavcodec/sp5xdec.c new file mode 100644 index 000000000..e5dd5ea05 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/sp5xdec.c @@ -0,0 +1,213 @@ +/* + * Sunplus JPEG decoder (SP5X) + * Copyright (c) 2003 Alex Beregszaszi + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file sp5xdec.c + * Sunplus JPEG decoder (SP5X). + */ + +#include "avcodec.h" +#include "mjpeg.h" +#include "mjpegdec.h" +#include "sp5x.h" + + +static int sp5x_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size) +{ +#if 0 + MJpegDecodeContext *s = avctx->priv_data; +#endif + const int qscale = 5; + const uint8_t *buf_ptr, *buf_end; + uint8_t *recoded; + int i = 0, j = 0; + + if (!avctx->width || !avctx->height) + return -1; + + buf_ptr = buf; + buf_end = buf + buf_size; + +#if 1 + recoded = av_mallocz(buf_size + 1024); + if (!recoded) + return -1; + + /* SOI */ + recoded[j++] = 0xFF; + recoded[j++] = 0xD8; + + memcpy(recoded+j, &sp5x_data_dqt[0], sizeof(sp5x_data_dqt)); + memcpy(recoded+j+5, &sp5x_quant_table[qscale * 2], 64); + memcpy(recoded+j+70, &sp5x_quant_table[(qscale * 2) + 1], 64); + j += sizeof(sp5x_data_dqt); + + memcpy(recoded+j, &sp5x_data_dht[0], sizeof(sp5x_data_dht)); + j += sizeof(sp5x_data_dht); + + memcpy(recoded+j, &sp5x_data_sof[0], sizeof(sp5x_data_sof)); + AV_WB16(recoded+j+5, avctx->coded_height); + AV_WB16(recoded+j+7, avctx->coded_width); + j += sizeof(sp5x_data_sof); + + memcpy(recoded+j, &sp5x_data_sos[0], sizeof(sp5x_data_sos)); + j += sizeof(sp5x_data_sos); + + if(avctx->codec_id==CODEC_ID_AMV) + for (i = 2; i < buf_size-2 && j < buf_size+1024-2; i++) + recoded[j++] = buf[i]; + else + for (i = 14; i < buf_size && j < buf_size+1024-2; i++) + { + recoded[j++] = buf[i]; + if (buf[i] == 0xff) + recoded[j++] = 0; + } + + /* EOI */ + recoded[j++] = 0xFF; + recoded[j++] = 0xD9; + + avctx->flags &= ~CODEC_FLAG_EMU_EDGE; + i = ff_mjpeg_decode_frame(avctx, data, data_size, recoded, j); + + av_free(recoded); + +#else + /* SOF */ + s->bits = 8; + s->width = avctx->coded_width; + s->height = avctx->coded_height; + s->nb_components = 3; + s->component_id[0] = 0; + s->h_count[0] = 2; + s->v_count[0] = 2; + s->quant_index[0] = 0; + s->component_id[1] = 1; + s->h_count[1] = 1; + s->v_count[1] = 1; + s->quant_index[1] = 1; + s->component_id[2] = 2; + s->h_count[2] = 1; + s->v_count[2] = 1; + s->quant_index[2] = 1; + s->h_max = 2; + s->v_max = 2; + + s->qscale_table = av_mallocz((s->width+15)/16); + avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV420P : PIX_FMT_YUVJ420; + s->interlaced = 0; + + s->picture.reference = 0; + if (avctx->get_buffer(avctx, &s->picture) < 0) + { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + + s->picture.pict_type = I_TYPE; + s->picture.key_frame = 1; + + for (i = 0; i < 3; i++) + s->linesize[i] = s->picture.linesize[i] << s->interlaced; + + /* DQT */ + for (i = 0; i < 64; i++) + { + j = s->scantable.permutated[i]; + s->quant_matrixes[0][j] = sp5x_quant_table[(qscale * 2) + i]; + } + s->qscale[0] = FFMAX( + s->quant_matrixes[0][s->scantable.permutated[1]], + s->quant_matrixes[0][s->scantable.permutated[8]]) >> 1; + + for (i = 0; i < 64; i++) + { + j = s->scantable.permutated[i]; + s->quant_matrixes[1][j] = sp5x_quant_table[(qscale * 2) + 1 + i]; + } + s->qscale[1] = FFMAX( + s->quant_matrixes[1][s->scantable.permutated[1]], + s->quant_matrixes[1][s->scantable.permutated[8]]) >> 1; + + /* DHT */ + + /* SOS */ + s->comp_index[0] = 0; + s->nb_blocks[0] = s->h_count[0] * s->v_count[0]; + s->h_scount[0] = s->h_count[0]; + s->v_scount[0] = s->v_count[0]; + s->dc_index[0] = 0; + s->ac_index[0] = 0; + + s->comp_index[1] = 1; + s->nb_blocks[1] = s->h_count[1] * s->v_count[1]; + s->h_scount[1] = s->h_count[1]; + s->v_scount[1] = s->v_count[1]; + s->dc_index[1] = 1; + s->ac_index[1] = 1; + + s->comp_index[2] = 2; + s->nb_blocks[2] = s->h_count[2] * s->v_count[2]; + s->h_scount[2] = s->h_count[2]; + s->v_scount[2] = s->v_count[2]; + s->dc_index[2] = 1; + s->ac_index[2] = 1; + + for (i = 0; i < 3; i++) + s->last_dc[i] = 1024; + + s->mb_width = (s->width * s->h_max * 8 -1) / (s->h_max * 8); + s->mb_height = (s->height * s->v_max * 8 -1) / (s->v_max * 8); + + init_get_bits(&s->gb, buf+14, (buf_size-14)*8); + + return mjpeg_decode_scan(s); +#endif + + return i; +} + +AVCodec sp5x_decoder = { + "sp5x", + CODEC_TYPE_VIDEO, + CODEC_ID_SP5X, + sizeof(MJpegDecodeContext), + ff_mjpeg_decode_init, + NULL, + ff_mjpeg_decode_end, + sp5x_decode_frame, + CODEC_CAP_DR1, + NULL +}; + +AVCodec amv_decoder = { + "amv", + CODEC_TYPE_VIDEO, + CODEC_ID_AMV, + sizeof(MJpegDecodeContext), + ff_mjpeg_decode_init, + NULL, + ff_mjpeg_decode_end, + sp5x_decode_frame +}; diff --git a/contrib/ffmpeg/libavcodec/sparc/dsputil_vis.c b/contrib/ffmpeg/libavcodec/sparc/dsputil_vis.c index 5e59ce776..437260311 100644 --- a/contrib/ffmpeg/libavcodec/sparc/dsputil_vis.c +++ b/contrib/ffmpeg/libavcodec/sparc/dsputil_vis.c @@ -25,16 +25,16 @@ #include "config.h" -#ifdef ARCH_SPARC - #include -#include -#include -#include "../dsputil.h" +#include "dsputil.h" #include "vis.h" +extern void ff_simple_idct_put_vis(uint8_t *dest, int line_size, DCTELEM *data); +extern void ff_simple_idct_add_vis(uint8_t *dest, int line_size, DCTELEM *data); +extern void ff_simple_idct_vis(DCTELEM *data); + /* The trick used in some of this file is the formula from the MMX * motion comp code, which is: * @@ -3985,66 +3985,31 @@ static void MC_avg_no_round_xy_8_vis (uint8_t * dest, const uint8_t * _ref, /* End of no rounding code */ -static sigjmp_buf jmpbuf; -static volatile sig_atomic_t canjump = 0; - -static void sigill_handler (int sig) -{ - if (!canjump) { - signal (sig, SIG_DFL); - raise (sig); - } - - canjump = 0; - siglongjmp (jmpbuf, 1); -} - #define ACCEL_SPARC_VIS 1 #define ACCEL_SPARC_VIS2 2 static int vis_level () { int accel = 0; - - signal (SIGILL, sigill_handler); - if (sigsetjmp (jmpbuf, 1)) { - signal (SIGILL, SIG_DFL); - return accel; - } - - canjump = 1; - - /* pdist %f0, %f0, %f0 */ - __asm__ __volatile__(".word\t0x81b007c0"); - - canjump = 0; accel |= ACCEL_SPARC_VIS; - - if (sigsetjmp (jmpbuf, 1)) { - signal (SIGILL, SIG_DFL); - return accel; - } - - canjump = 1; - - /* edge8n %g0, %g0, %g0 */ - __asm__ __volatile__(".word\t0x81b00020"); - - canjump = 0; accel |= ACCEL_SPARC_VIS2; - - signal (SIGILL, SIG_DFL); - return accel; } /* libavcodec initialization code */ void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx) { - /* VIS specific optimisations */ + /* VIS-specific optimizations */ int accel = vis_level (); if (accel & ACCEL_SPARC_VIS) { + if(avctx->idct_algo==FF_IDCT_SIMPLEVIS){ + c->idct_put = ff_simple_idct_put_vis; + c->idct_add = ff_simple_idct_add_vis; + c->idct = ff_simple_idct_vis; + c->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM; + } + c->put_pixels_tab[0][0] = MC_put_o_16_vis; c->put_pixels_tab[0][1] = MC_put_x_16_vis; c->put_pixels_tab[0][2] = MC_put_y_16_vis; @@ -4086,5 +4051,3 @@ void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx) c->avg_no_rnd_pixels_tab[1][3] = MC_avg_no_round_xy_8_vis; } } - -#endif /* !(ARCH_SPARC) */ diff --git a/contrib/ffmpeg/libavcodec/sparc/simple_idct_vis.c b/contrib/ffmpeg/libavcodec/sparc/simple_idct_vis.c new file mode 100644 index 000000000..716d3de48 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/sparc/simple_idct_vis.c @@ -0,0 +1,528 @@ +/* + * SPARC VIS optimized inverse DCT + * Copyright (c) 2007 Denes Balatoni < dbalatoni XatX interware XdotX hu > + * + * I did consult the following fine web page about dct + * http://www.geocities.com/ssavekar/dct.htm + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "dsputil.h" + +static const DECLARE_ALIGNED_8(int16_t, coeffs[28]) = { + - 1259,- 1259,- 1259,- 1259, + - 4989,- 4989,- 4989,- 4989, + -11045,-11045,-11045,-11045, + -19195,-19195,-19195,-19195, + -29126,-29126,-29126,-29126, + 25080, 25080, 25080, 25080, + 12785, 12785, 12785, 12785 +}; +static const DECLARE_ALIGNED_8(uint16_t, scale[4]) = { + 65536>>6, 65536>>6, 65536>>6, 65536>>6 +}; +static const DECLARE_ALIGNED_8(uint16_t, rounder[4]) = { + 1<<5, 1<<5, 1<<5, 1<<5 +}; +static const DECLARE_ALIGNED_8(uint16_t, expand[4]) = { + 1<<14, 1<<14, 1<<14, 1<<14 +}; + +#define INIT_IDCT \ + "ldd [%1], %%f32 \n\t"\ + "ldd [%1+8], %%f34 \n\t"\ + "ldd [%1+16], %%f36 \n\t"\ + "ldd [%1+24], %%f38 \n\t"\ + "ldd [%1+32], %%f40 \n\t"\ + "ldd [%1+40], %%f42 \n\t"\ + "ldd [%1+48], %%f44 \n\t"\ + "ldd [%0], %%f46 \n\t"\ + "fzero %%f62 \n\t"\ + +#define LOADSCALE(in) \ + "ldd [" in "], %%f0 \n\t"\ + "ldd [" in "+16], %%f2 \n\t"\ + "ldd [" in "+32], %%f4 \n\t"\ + "ldd [" in "+48], %%f6 \n\t"\ + "ldd [" in "+64], %%f8 \n\t"\ + "ldd [" in "+80], %%f10 \n\t"\ + "ldd [" in "+96], %%f12 \n\t"\ + "ldd [" in "+112], %%f14 \n\t"\ + "fpadd16 %%f0, %%f0, %%f0 \n\t"\ + "fpadd16 %%f2, %%f2, %%f2 \n\t"\ + "fpadd16 %%f4, %%f4, %%f4 \n\t"\ + "fpadd16 %%f6, %%f6, %%f6 \n\t"\ + "fpadd16 %%f8, %%f8, %%f8 \n\t"\ + "fpadd16 %%f10, %%f10, %%f10 \n\t"\ + "fpadd16 %%f12, %%f12, %%f12 \n\t"\ + "fpadd16 %%f14, %%f14, %%f14 \n\t"\ +\ + "fpadd16 %%f0, %%f0, %%f0 \n\t"\ + "fpadd16 %%f2, %%f2, %%f2 \n\t"\ + "fpadd16 %%f4, %%f4, %%f4 \n\t"\ + "fpadd16 %%f6, %%f6, %%f6 \n\t"\ + "fpadd16 %%f8, %%f8, %%f8 \n\t"\ + "fpadd16 %%f10, %%f10, %%f10 \n\t"\ + "fpadd16 %%f12, %%f12, %%f12 \n\t"\ + "fpadd16 %%f14, %%f14, %%f14 \n\t"\ +\ + "fpadd16 %%f0, %%f0, %%f0 \n\t"\ + "fpadd16 %%f2, %%f2, %%f2 \n\t"\ + "fpadd16 %%f4, %%f4, %%f4 \n\t"\ + "fpadd16 %%f6, %%f6, %%f6 \n\t"\ + "fpadd16 %%f8, %%f8, %%f8 \n\t"\ + "fpadd16 %%f10, %%f10, %%f10 \n\t"\ + "fpadd16 %%f12, %%f12, %%f12 \n\t"\ + "fpadd16 %%f14, %%f14, %%f14 \n\t"\ +\ + "fpadd16 %%f0, %%f0, %%f0 \n\t"\ + "fpadd16 %%f2, %%f2, %%f2 \n\t"\ + "fpadd16 %%f4, %%f4, %%f4 \n\t"\ + "fpadd16 %%f6, %%f6, %%f6 \n\t"\ + "fpadd16 %%f8, %%f8, %%f8 \n\t"\ + "fpadd16 %%f10, %%f10, %%f10 \n\t"\ + "fpadd16 %%f12, %%f12, %%f12 \n\t"\ + "fpadd16 %%f14, %%f14, %%f14 \n\t"\ + +#define LOAD(in) \ + "ldd [" in "], %%f16 \n\t"\ + "ldd [" in "+8], %%f18 \n\t"\ + "ldd [" in "+16], %%f20 \n\t"\ + "ldd [" in "+24], %%f22 \n\t"\ + "ldd [" in "+32], %%f24 \n\t"\ + "ldd [" in "+40], %%f26 \n\t"\ + "ldd [" in "+48], %%f28 \n\t"\ + "ldd [" in "+56], %%f30 \n\t"\ + +#define TRANSPOSE \ + "fpmerge %%f16, %%f24, %%f0 \n\t"\ + "fpmerge %%f20, %%f28, %%f2 \n\t"\ + "fpmerge %%f17, %%f25, %%f4 \n\t"\ + "fpmerge %%f21, %%f29, %%f6 \n\t"\ + "fpmerge %%f18, %%f26, %%f8 \n\t"\ + "fpmerge %%f22, %%f30, %%f10 \n\t"\ + "fpmerge %%f19, %%f27, %%f12 \n\t"\ + "fpmerge %%f23, %%f31, %%f14 \n\t"\ +\ + "fpmerge %%f0, %%f2, %%f16 \n\t"\ + "fpmerge %%f1, %%f3, %%f18 \n\t"\ + "fpmerge %%f4, %%f6, %%f20 \n\t"\ + "fpmerge %%f5, %%f7, %%f22 \n\t"\ + "fpmerge %%f8, %%f10, %%f24 \n\t"\ + "fpmerge %%f9, %%f11, %%f26 \n\t"\ + "fpmerge %%f12, %%f14, %%f28 \n\t"\ + "fpmerge %%f13, %%f15, %%f30 \n\t"\ +\ + "fpmerge %%f16, %%f17, %%f0 \n\t"\ + "fpmerge %%f18, %%f19, %%f2 \n\t"\ + "fpmerge %%f20, %%f21, %%f4 \n\t"\ + "fpmerge %%f22, %%f23, %%f6 \n\t"\ + "fpmerge %%f24, %%f25, %%f8 \n\t"\ + "fpmerge %%f26, %%f27, %%f10 \n\t"\ + "fpmerge %%f28, %%f29, %%f12 \n\t"\ + "fpmerge %%f30, %%f31, %%f14 \n\t"\ + +#define IDCT4ROWS \ + /* 1. column */\ + "fmul8ulx16 %%f0, %%f38, %%f28 \n\t"\ + "for %%f4, %%f6, %%f60 \n\t"\ + "fmul8ulx16 %%f2, %%f32, %%f18 \n\t"\ + "fmul8ulx16 %%f2, %%f36, %%f22 \n\t"\ + "fmul8ulx16 %%f2, %%f40, %%f26 \n\t"\ + "fmul8ulx16 %%f2, %%f44, %%f30 \n\t"\ +\ + ADDROUNDER\ +\ + "fmul8sux16 %%f0, %%f38, %%f48 \n\t"\ + "fcmpd %%fcc0, %%f62, %%f60 \n\t"\ + "for %%f8, %%f10, %%f60 \n\t"\ + "fmul8sux16 %%f2, %%f32, %%f50 \n\t"\ + "fmul8sux16 %%f2, %%f36, %%f52 \n\t"\ + "fmul8sux16 %%f2, %%f40, %%f54 \n\t"\ + "fmul8sux16 %%f2, %%f44, %%f56 \n\t"\ +\ + "fpadd16 %%f48, %%f28, %%f28 \n\t"\ + "fcmpd %%fcc1, %%f62, %%f60 \n\t"\ + "for %%f12, %%f14, %%f60 \n\t"\ + "fpadd16 %%f50, %%f18, %%f18 \n\t"\ + "fpadd16 %%f52, %%f22, %%f22 \n\t"\ + "fpadd16 %%f54, %%f26, %%f26 \n\t"\ + "fpadd16 %%f56, %%f30, %%f30 \n\t"\ +\ + "fpadd16 %%f28, %%f0, %%f16 \n\t"\ + "fcmpd %%fcc2, %%f62, %%f60 \n\t"\ + "fpadd16 %%f28, %%f0, %%f20 \n\t"\ + "fpadd16 %%f28, %%f0, %%f24 \n\t"\ + "fpadd16 %%f28, %%f0, %%f28 \n\t"\ + "fpadd16 %%f18, %%f2, %%f18 \n\t"\ + "fpadd16 %%f22, %%f2, %%f22 \n\t"\ + /* 2. column */\ + "fbe %%fcc0, 3f \n\t"\ + "fpadd16 %%f26, %%f2, %%f26 \n\t"\ + "fmul8ulx16 %%f4, %%f34, %%f48 \n\t"\ + "fmul8ulx16 %%f4, %%f42, %%f50 \n\t"\ + "fmul8ulx16 %%f6, %%f36, %%f52 \n\t"\ + "fmul8ulx16 %%f6, %%f44, %%f54 \n\t"\ + "fmul8ulx16 %%f6, %%f32, %%f56 \n\t"\ + "fmul8ulx16 %%f6, %%f40, %%f58 \n\t"\ +\ + "fpadd16 %%f16, %%f48, %%f16 \n\t"\ + "fpadd16 %%f20, %%f50, %%f20 \n\t"\ + "fpsub16 %%f24, %%f50, %%f24 \n\t"\ + "fpsub16 %%f28, %%f48, %%f28 \n\t"\ + "fpadd16 %%f18, %%f52, %%f18 \n\t"\ + "fpsub16 %%f22, %%f54, %%f22 \n\t"\ + "fpsub16 %%f26, %%f56, %%f26 \n\t"\ + "fpsub16 %%f30, %%f58, %%f30 \n\t"\ +\ + "fmul8sux16 %%f4, %%f34, %%f48 \n\t"\ + "fmul8sux16 %%f4, %%f42, %%f50 \n\t"\ + "fmul8sux16 %%f6, %%f36, %%f52 \n\t"\ + "fmul8sux16 %%f6, %%f44, %%f54 \n\t"\ + "fmul8sux16 %%f6, %%f32, %%f56 \n\t"\ + "fmul8sux16 %%f6, %%f40, %%f58 \n\t"\ +\ + "fpadd16 %%f16, %%f48, %%f16 \n\t"\ + "fpadd16 %%f20, %%f50, %%f20 \n\t"\ + "fpsub16 %%f24, %%f50, %%f24 \n\t"\ + "fpsub16 %%f28, %%f48, %%f28 \n\t"\ + "fpadd16 %%f18, %%f52, %%f18 \n\t"\ + "fpsub16 %%f22, %%f54, %%f22 \n\t"\ + "fpsub16 %%f26, %%f56, %%f26 \n\t"\ + "fpsub16 %%f30, %%f58, %%f30 \n\t"\ +\ + "fpadd16 %%f16, %%f4, %%f16 \n\t"\ + "fpsub16 %%f28, %%f4, %%f28 \n\t"\ + "fpadd16 %%f18, %%f6, %%f18 \n\t"\ + "fpsub16 %%f26, %%f6, %%f26 \n\t"\ + /* 3. column */\ + "3: \n\t"\ + "fbe %%fcc1, 4f \n\t"\ + "fpsub16 %%f30, %%f6, %%f30 \n\t"\ + "fmul8ulx16 %%f8, %%f38, %%f48 \n\t"\ + "fmul8ulx16 %%f10, %%f40, %%f50 \n\t"\ + "fmul8ulx16 %%f10, %%f32, %%f52 \n\t"\ + "fmul8ulx16 %%f10, %%f44, %%f54 \n\t"\ + "fmul8ulx16 %%f10, %%f36, %%f56 \n\t"\ +\ + "fpadd16 %%f16, %%f48, %%f16 \n\t"\ + "fpsub16 %%f20, %%f48, %%f20 \n\t"\ + "fpsub16 %%f24, %%f48, %%f24 \n\t"\ + "fpadd16 %%f28, %%f48, %%f28 \n\t"\ + "fpadd16 %%f18, %%f50, %%f18 \n\t"\ + "fpsub16 %%f22, %%f52, %%f22 \n\t"\ + "fpadd16 %%f26, %%f54, %%f26 \n\t"\ + "fpadd16 %%f30, %%f56, %%f30 \n\t"\ +\ + "fmul8sux16 %%f8, %%f38, %%f48 \n\t"\ + "fmul8sux16 %%f10, %%f40, %%f50 \n\t"\ + "fmul8sux16 %%f10, %%f32, %%f52 \n\t"\ + "fmul8sux16 %%f10, %%f44, %%f54 \n\t"\ + "fmul8sux16 %%f10, %%f36, %%f56 \n\t"\ +\ + "fpadd16 %%f16, %%f48, %%f16 \n\t"\ + "fpsub16 %%f20, %%f48, %%f20 \n\t"\ + "fpsub16 %%f24, %%f48, %%f24 \n\t"\ + "fpadd16 %%f28, %%f48, %%f28 \n\t"\ + "fpadd16 %%f18, %%f50, %%f18 \n\t"\ + "fpsub16 %%f22, %%f52, %%f22 \n\t"\ + "fpadd16 %%f26, %%f54, %%f26 \n\t"\ + "fpadd16 %%f30, %%f56, %%f30 \n\t"\ +\ + "fpadd16 %%f16, %%f8, %%f16 \n\t"\ + "fpsub16 %%f20, %%f8, %%f20 \n\t"\ + "fpsub16 %%f24, %%f8, %%f24 \n\t"\ + "fpadd16 %%f28, %%f8, %%f28 \n\t"\ + "fpadd16 %%f18, %%f10, %%f18 \n\t"\ + "fpsub16 %%f22, %%f10, %%f22 \n\t"\ + /* 4. column */\ + "4: \n\t"\ + "fbe %%fcc2, 5f \n\t"\ + "fpadd16 %%f30, %%f10, %%f30 \n\t"\ + "fmul8ulx16 %%f12, %%f42, %%f48 \n\t"\ + "fmul8ulx16 %%f12, %%f34, %%f50 \n\t"\ + "fmul8ulx16 %%f14, %%f44, %%f52 \n\t"\ + "fmul8ulx16 %%f14, %%f40, %%f54 \n\t"\ + "fmul8ulx16 %%f14, %%f36, %%f56 \n\t"\ + "fmul8ulx16 %%f14, %%f32, %%f58 \n\t"\ +\ + "fpadd16 %%f16, %%f48, %%f16 \n\t"\ + "fpsub16 %%f20, %%f50, %%f20 \n\t"\ + "fpadd16 %%f24, %%f50, %%f24 \n\t"\ + "fpsub16 %%f28, %%f48, %%f28 \n\t"\ + "fpadd16 %%f18, %%f52, %%f18 \n\t"\ + "fpsub16 %%f22, %%f54, %%f22 \n\t"\ + "fpadd16 %%f26, %%f56, %%f26 \n\t"\ + "fpsub16 %%f30, %%f58, %%f30 \n\t"\ +\ + "fmul8sux16 %%f12, %%f42, %%f48 \n\t"\ + "fmul8sux16 %%f12, %%f34, %%f50 \n\t"\ + "fmul8sux16 %%f14, %%f44, %%f52 \n\t"\ + "fmul8sux16 %%f14, %%f40, %%f54 \n\t"\ + "fmul8sux16 %%f14, %%f36, %%f56 \n\t"\ + "fmul8sux16 %%f14, %%f32, %%f58 \n\t"\ +\ + "fpadd16 %%f16, %%f48, %%f16 \n\t"\ + "fpsub16 %%f20, %%f50, %%f20 \n\t"\ + "fpadd16 %%f24, %%f50, %%f24 \n\t"\ + "fpsub16 %%f28, %%f48, %%f28 \n\t"\ + "fpadd16 %%f18, %%f52, %%f18 \n\t"\ + "fpsub16 %%f22, %%f54, %%f22 \n\t"\ + "fpadd16 %%f26, %%f56, %%f26 \n\t"\ + "fpsub16 %%f30, %%f58, %%f30 \n\t"\ +\ + "fpsub16 %%f20, %%f12, %%f20 \n\t"\ + "fpadd16 %%f24, %%f12, %%f24 \n\t"\ + "fpsub16 %%f22, %%f14, %%f22 \n\t"\ + "fpadd16 %%f26, %%f14, %%f26 \n\t"\ + "fpsub16 %%f30, %%f14, %%f30 \n\t"\ + /* final butterfly */\ + "5: \n\t"\ + "fpsub16 %%f16, %%f18, %%f48 \n\t"\ + "fpsub16 %%f20, %%f22, %%f50 \n\t"\ + "fpsub16 %%f24, %%f26, %%f52 \n\t"\ + "fpsub16 %%f28, %%f30, %%f54 \n\t"\ + "fpadd16 %%f16, %%f18, %%f16 \n\t"\ + "fpadd16 %%f20, %%f22, %%f20 \n\t"\ + "fpadd16 %%f24, %%f26, %%f24 \n\t"\ + "fpadd16 %%f28, %%f30, %%f28 \n\t"\ + +#define STOREROWS(out) \ + "std %%f48, [" out "+112] \n\t"\ + "std %%f50, [" out "+96] \n\t"\ + "std %%f52, [" out "+80] \n\t"\ + "std %%f54, [" out "+64] \n\t"\ + "std %%f16, [" out "] \n\t"\ + "std %%f20, [" out "+16] \n\t"\ + "std %%f24, [" out "+32] \n\t"\ + "std %%f28, [" out "+48] \n\t"\ + +#define SCALEROWS \ + "fmul8sux16 %%f46, %%f48, %%f48 \n\t"\ + "fmul8sux16 %%f46, %%f50, %%f50 \n\t"\ + "fmul8sux16 %%f46, %%f52, %%f52 \n\t"\ + "fmul8sux16 %%f46, %%f54, %%f54 \n\t"\ + "fmul8sux16 %%f46, %%f16, %%f16 \n\t"\ + "fmul8sux16 %%f46, %%f20, %%f20 \n\t"\ + "fmul8sux16 %%f46, %%f24, %%f24 \n\t"\ + "fmul8sux16 %%f46, %%f28, %%f28 \n\t"\ + +#define PUTPIXELSCLAMPED(dest) \ + "fpack16 %%f48, %%f14 \n\t"\ + "fpack16 %%f50, %%f12 \n\t"\ + "fpack16 %%f16, %%f0 \n\t"\ + "fpack16 %%f20, %%f2 \n\t"\ + "fpack16 %%f24, %%f4 \n\t"\ + "fpack16 %%f28, %%f6 \n\t"\ + "fpack16 %%f54, %%f8 \n\t"\ + "fpack16 %%f52, %%f10 \n\t"\ + "st %%f0, [%3+" dest "] \n\t"\ + "st %%f2, [%5+" dest "] \n\t"\ + "st %%f4, [%6+" dest "] \n\t"\ + "st %%f6, [%7+" dest "] \n\t"\ + "st %%f8, [%8+" dest "] \n\t"\ + "st %%f10, [%9+" dest "] \n\t"\ + "st %%f12, [%10+" dest "] \n\t"\ + "st %%f14, [%11+" dest "] \n\t"\ + +#define ADDPIXELSCLAMPED(dest) \ + "ldd [%5], %%f18 \n\t"\ + "ld [%3+" dest"], %%f0 \n\t"\ + "ld [%6+" dest"], %%f2 \n\t"\ + "ld [%7+" dest"], %%f4 \n\t"\ + "ld [%8+" dest"], %%f6 \n\t"\ + "ld [%9+" dest"], %%f8 \n\t"\ + "ld [%10+" dest"], %%f10 \n\t"\ + "ld [%11+" dest"], %%f12 \n\t"\ + "ld [%12+" dest"], %%f14 \n\t"\ + "fmul8x16 %%f0, %%f18, %%f0 \n\t"\ + "fmul8x16 %%f2, %%f18, %%f2 \n\t"\ + "fmul8x16 %%f4, %%f18, %%f4 \n\t"\ + "fmul8x16 %%f6, %%f18, %%f6 \n\t"\ + "fmul8x16 %%f8, %%f18, %%f8 \n\t"\ + "fmul8x16 %%f10, %%f18, %%f10 \n\t"\ + "fmul8x16 %%f12, %%f18, %%f12 \n\t"\ + "fmul8x16 %%f14, %%f18, %%f14 \n\t"\ + "fpadd16 %%f0, %%f16, %%f0 \n\t"\ + "fpadd16 %%f2, %%f20, %%f2 \n\t"\ + "fpadd16 %%f4, %%f24, %%f4 \n\t"\ + "fpadd16 %%f6, %%f28, %%f6 \n\t"\ + "fpadd16 %%f8, %%f54, %%f8 \n\t"\ + "fpadd16 %%f10, %%f52, %%f10 \n\t"\ + "fpadd16 %%f12, %%f50, %%f12 \n\t"\ + "fpadd16 %%f14, %%f48, %%f14 \n\t"\ + "fpack16 %%f0, %%f0 \n\t"\ + "fpack16 %%f2, %%f2 \n\t"\ + "fpack16 %%f4, %%f4 \n\t"\ + "fpack16 %%f6, %%f6 \n\t"\ + "fpack16 %%f8, %%f8 \n\t"\ + "fpack16 %%f10, %%f10 \n\t"\ + "fpack16 %%f12, %%f12 \n\t"\ + "fpack16 %%f14, %%f14 \n\t"\ + "st %%f0, [%3+" dest "] \n\t"\ + "st %%f2, [%6+" dest "] \n\t"\ + "st %%f4, [%7+" dest "] \n\t"\ + "st %%f6, [%8+" dest "] \n\t"\ + "st %%f8, [%9+" dest "] \n\t"\ + "st %%f10, [%10+" dest "] \n\t"\ + "st %%f12, [%11+" dest "] \n\t"\ + "st %%f14, [%12+" dest "] \n\t"\ + + +inline void ff_simple_idct_vis(DCTELEM *data) { + int out1, out2, out3, out4; + DECLARE_ALIGNED_8(int16_t, temp[8*8]); + + asm volatile( + INIT_IDCT + +#define ADDROUNDER + + // shift right 16-4=12 + LOADSCALE("%2+8") + IDCT4ROWS + STOREROWS("%3+8") + LOADSCALE("%2+0") + IDCT4ROWS + "std %%f48, [%3+112] \n\t" + "std %%f50, [%3+96] \n\t" + "std %%f52, [%3+80] \n\t" + "std %%f54, [%3+64] \n\t" + + // shift right 16+4 + "ldd [%3+8], %%f18 \n\t" + "ldd [%3+24], %%f22 \n\t" + "ldd [%3+40], %%f26 \n\t" + "ldd [%3+56], %%f30 \n\t" + TRANSPOSE + IDCT4ROWS + SCALEROWS + STOREROWS("%2+0") + LOAD("%3+64") + TRANSPOSE + IDCT4ROWS + SCALEROWS + STOREROWS("%2+8") + + : "=r" (out1), "=r" (out2), "=r" (out3), "=r" (out4) + : "0" (scale), "1" (coeffs), "2" (data), "3" (temp) + ); +} + +void ff_simple_idct_put_vis(uint8_t *dest, int line_size, DCTELEM *data) { + int out1, out2, out3, out4, out5; + int r1, r2, r3, r4, r5, r6, r7; + + asm volatile( + "wr %%g0, 0x8, %%gsr \n\t" + + INIT_IDCT + + "add %3, %4, %5 \n\t" + "add %5, %4, %6 \n\t" + "add %6, %4, %7 \n\t" + "add %7, %4, %8 \n\t" + "add %8, %4, %9 \n\t" + "add %9, %4, %10 \n\t" + "add %10, %4, %11 \n\t" + + // shift right 16-4=12 + LOADSCALE("%2+8") + IDCT4ROWS + STOREROWS("%2+8") + LOADSCALE("%2+0") + IDCT4ROWS + "std %%f48, [%2+112] \n\t" + "std %%f50, [%2+96] \n\t" + "std %%f52, [%2+80] \n\t" + "std %%f54, [%2+64] \n\t" + +#undef ADDROUNDER +#define ADDROUNDER "fpadd16 %%f28, %%f46, %%f28 \n\t" + + // shift right 16+4 + "ldd [%2+8], %%f18 \n\t" + "ldd [%2+24], %%f22 \n\t" + "ldd [%2+40], %%f26 \n\t" + "ldd [%2+56], %%f30 \n\t" + TRANSPOSE + IDCT4ROWS + PUTPIXELSCLAMPED("0") + LOAD("%2+64") + TRANSPOSE + IDCT4ROWS + PUTPIXELSCLAMPED("4") + + : "=r" (out1), "=r" (out2), "=r" (out3), "=r" (out4), "=r" (out5), + "=r" (r1), "=r" (r2), "=r" (r3), "=r" (r4), "=r" (r5), "=r" (r6), "=r" (r7) + : "0" (rounder), "1" (coeffs), "2" (data), "3" (dest), "4" (line_size) + ); +} + +void ff_simple_idct_add_vis(uint8_t *dest, int line_size, DCTELEM *data) { + int out1, out2, out3, out4, out5, out6; + int r1, r2, r3, r4, r5, r6, r7; + + asm volatile( + "wr %%g0, 0x8, %%gsr \n\t" + + INIT_IDCT + + "add %3, %4, %6 \n\t" + "add %6, %4, %7 \n\t" + "add %7, %4, %8 \n\t" + "add %8, %4, %9 \n\t" + "add %9, %4, %10 \n\t" + "add %10, %4, %11 \n\t" + "add %11, %4, %12 \n\t" + +#undef ADDROUNDER +#define ADDROUNDER + + // shift right 16-4=12 + LOADSCALE("%2+8") + IDCT4ROWS + STOREROWS("%2+8") + LOADSCALE("%2+0") + IDCT4ROWS + "std %%f48, [%2+112] \n\t" + "std %%f50, [%2+96] \n\t" + "std %%f52, [%2+80] \n\t" + "std %%f54, [%2+64] \n\t" + +#undef ADDROUNDER +#define ADDROUNDER "fpadd16 %%f28, %%f46, %%f28 \n\t" + + // shift right 16+4 + "ldd [%2+8], %%f18 \n\t" + "ldd [%2+24], %%f22 \n\t" + "ldd [%2+40], %%f26 \n\t" + "ldd [%2+56], %%f30 \n\t" + TRANSPOSE + IDCT4ROWS + ADDPIXELSCLAMPED("0") + LOAD("%2+64") + TRANSPOSE + IDCT4ROWS + ADDPIXELSCLAMPED("4") + + : "=r" (out1), "=r" (out2), "=r" (out3), "=r" (out4), "=r" (out5), "=r" (out6), + "=r" (r1), "=r" (r2), "=r" (r3), "=r" (r4), "=r" (r5), "=r" (r6), "=r" (r7) + : "0" (rounder), "1" (coeffs), "2" (data), "3" (dest), "4" (line_size), "5" (expand) + ); +} diff --git a/contrib/ffmpeg/libavcodec/sparc/vis.h b/contrib/ffmpeg/libavcodec/sparc/vis.h index d4a8ce092..a0b09f5bc 100644 --- a/contrib/ffmpeg/libavcodec/sparc/vis.h +++ b/contrib/ffmpeg/libavcodec/sparc/vis.h @@ -40,6 +40,9 @@ * the assembler to keep the binary from becoming tainted. */ +#ifndef FFMPEG_VIS_H +#define FFMPEG_VIS_H + #define vis_opc_base ((0x1 << 31) | (0x36 << 19)) #define vis_opf(X) ((X) << 5) #define vis_sreg(X) (X) @@ -325,3 +328,5 @@ static inline void vis_alignaddrl_g0(void *_ptr) /* Pixel component distance. */ #define vis_pdist(rs1,rs2,rd) vis_dd2d(0x3e, rs1, rs2, rd) + +#endif /* FFMPEG_VIS_H */ diff --git a/contrib/ffmpeg/libavcodec/sunrast.c b/contrib/ffmpeg/libavcodec/sunrast.c new file mode 100644 index 000000000..7e71f21ef --- /dev/null +++ b/contrib/ffmpeg/libavcodec/sunrast.c @@ -0,0 +1,195 @@ +/* + * Sun Rasterfile (.sun/.ras/im{1,8,24}/.sunras) image decoder + * Copyright (c) 2007, 2008 Ivo van Poorten + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" + +#define RT_OLD 0 +#define RT_STANDARD 1 +#define RT_BYTE_ENCODED 2 +#define RT_FORMAT_RGB 3 +#define RT_FORMAT_TIFF 4 +#define RT_FORMAT_IFF 5 + +typedef struct SUNRASTContext { + AVFrame picture; +} SUNRASTContext; + +static int sunrast_init(AVCodecContext *avctx) { + SUNRASTContext *s = avctx->priv_data; + + avcodec_get_frame_defaults(&s->picture); + avctx->coded_frame= &s->picture; + + return 0; +} + +static int sunrast_decode_frame(AVCodecContext *avctx, void *data, + int *data_size, const uint8_t *buf, int buf_size) { + SUNRASTContext * const s = avctx->priv_data; + AVFrame *picture = data; + AVFrame * const p = &s->picture; + unsigned int w, h, depth, type, maptype, maplength, stride, x, y, len, alen; + uint8_t *ptr; + const uint8_t *bufstart = buf; + + if (AV_RB32(buf) != 0x59a66a95) { + av_log(avctx, AV_LOG_ERROR, "this is not sunras encoded data\n"); + return -1; + } + + w = AV_RB32(buf+4); + h = AV_RB32(buf+8); + depth = AV_RB32(buf+12); + type = AV_RB32(buf+20); + maptype = AV_RB32(buf+24); + maplength = AV_RB32(buf+28); + + if (type > RT_BYTE_ENCODED && type <= RT_FORMAT_IFF) { + av_log(avctx, AV_LOG_ERROR, "unsupported (compression) type\n"); + return -1; + } + if (type > RT_FORMAT_IFF) { + av_log(avctx, AV_LOG_ERROR, "invalid (compression) type\n"); + return -1; + } + if (maptype & ~1) { + av_log(avctx, AV_LOG_ERROR, "invalid colormap type\n"); + return -1; + } + + buf += 32; + + switch (depth) { + case 1: + avctx->pix_fmt = PIX_FMT_MONOWHITE; + break; + case 8: + avctx->pix_fmt = PIX_FMT_PAL8; + break; + case 24: + avctx->pix_fmt = PIX_FMT_BGR24; + break; + default: + av_log(avctx, AV_LOG_ERROR, "invalid depth\n"); + return -1; + } + + if (p->data[0]) + avctx->release_buffer(avctx, p); + + if (avcodec_check_dimensions(avctx, w, h)) + return -1; + if (w != avctx->width || h != avctx->height) + avcodec_set_dimensions(avctx, w, h); + if (avctx->get_buffer(avctx, p) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + + p->pict_type = FF_I_TYPE; + + if (depth != 8 && maplength) { + av_log(avctx, AV_LOG_WARNING, "useless colormap found or file is corrupted, trying to recover\n"); + + } else if (depth == 8) { + unsigned int len = maplength / 3; + + if (!maplength) { + av_log(avctx, AV_LOG_ERROR, "colormap expected\n"); + return -1; + } + if (maplength % 3 || maplength > 768) { + av_log(avctx, AV_LOG_WARNING, "invalid colormap length\n"); + return -1; + } + + ptr = p->data[1]; + for (x=0; xdata[0]; + stride = p->linesize[0]; + + /* scanlines are aligned on 16 bit boundaries */ + len = (depth * w + 7) >> 3; + alen = len + (len&1); + + if (type == RT_BYTE_ENCODED) { + int value, run; + uint8_t *end = ptr + h*stride; + + x = 0; + while (ptr != end) { + run = 1; + if ((value = *buf++) == 0x80) { + run = *buf++ + 1; + if (run != 1) + value = *buf++; + } + while (run--) { + if (x < len) + ptr[x] = value; + if (++x >= alen) { + x = 0; + ptr += stride; + if (ptr == end) + break; + } + } + } + } else { + for (y=0; ypicture; + *data_size = sizeof(AVFrame); + + return buf - bufstart; +} + +static int sunrast_end(AVCodecContext *avctx) { + SUNRASTContext *s = avctx->priv_data; + + if(s->picture.data[0]) + avctx->release_buffer(avctx, &s->picture); + + return 0; +} + +AVCodec sunrast_decoder = { + "sunrast", + CODEC_TYPE_VIDEO, + CODEC_ID_SUNRAST, + sizeof(SUNRASTContext), + sunrast_init, + NULL, + sunrast_end, + sunrast_decode_frame, + 0, + NULL +}; diff --git a/contrib/ffmpeg/libavcodec/svq1.c b/contrib/ffmpeg/libavcodec/svq1.c index 5087ba8cc..a4991837d 100644 --- a/contrib/ffmpeg/libavcodec/svq1.c +++ b/contrib/ffmpeg/libavcodec/svq1.c @@ -1,8 +1,13 @@ /* + * SVQ1 decoder + * ported to MPlayer by Arpi + * ported to libavcodec by Nick Kurshev * * Copyright (C) 2002 the xine project * Copyright (C) 2002 the ffmpeg project * + * SVQ1 Encoder (c) 2004 Mike Melanson + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -18,12 +23,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * (SVQ1 Decoder) - * Ported to mplayer by Arpi - * Ported to libavcodec by Nick Kurshev - * - * SVQ1 Encoder (c) 2004 Mike Melanson */ /** @@ -33,1393 +32,12 @@ * http://www.pcisys.net/~melanson/codecs/ */ - -//#define DEBUG_SVQ1 -#include -#include -#include -#include -#include - -#include "common.h" -#include "avcodec.h" -#include "dsputil.h" -#include "mpegvideo.h" -#include "bswap.h" - -#undef NDEBUG -#include - -extern const uint8_t mvtab[33][2]; - -static VLC svq1_block_type; -static VLC svq1_motion_component; -static VLC svq1_intra_multistage[6]; -static VLC svq1_inter_multistage[6]; -static VLC svq1_intra_mean; -static VLC svq1_inter_mean; - -#define SVQ1_BLOCK_SKIP 0 -#define SVQ1_BLOCK_INTER 1 -#define SVQ1_BLOCK_INTER_4V 2 -#define SVQ1_BLOCK_INTRA 3 - -typedef struct SVQ1Context { - MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independent of MpegEncContext, so this will be removed then (FIXME/XXX) - AVCodecContext *avctx; - DSPContext dsp; - AVFrame picture; - AVFrame current_picture; - AVFrame last_picture; - PutBitContext pb; - GetBitContext gb; - - PutBitContext reorder_pb[6]; //why ooh why this sick breadth first order, everything is slower and more complex - - int frame_width; - int frame_height; - - /* Y plane block dimensions */ - int y_block_width; - int y_block_height; - - /* U & V plane (C planes) block dimensions */ - int c_block_width; - int c_block_height; - - uint16_t *mb_type; - uint32_t *dummy; - int16_t (*motion_val8[3])[2]; - int16_t (*motion_val16[3])[2]; - - int64_t rd_total; -} SVQ1Context; - -/* motion vector (prediction) */ -typedef struct svq1_pmv_s { - int x; - int y; -} svq1_pmv_t; - +#include "svq1.h" #include "svq1_cb.h" #include "svq1_vlc.h" -static const uint16_t checksum_table[256] = { - 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, - 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, - 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, - 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, - 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, - 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, - 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, - 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, - 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, - 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, - 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, - 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, - 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, - 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, - 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, - 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, - 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, - 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, - 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, - 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, - 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, - 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, - 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, - 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, - 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, - 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, - 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, - 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, - 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, - 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, - 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, - 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 -}; - -static const uint8_t string_table[256] = { - 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54, - 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D, - 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06, - 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F, - 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0, - 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9, - 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2, - 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B, - 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9, - 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0, - 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B, - 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2, - 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D, - 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44, - 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F, - 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16, - 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB, - 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92, - 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9, - 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0, - 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F, - 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36, - 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D, - 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64, - 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26, - 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F, - 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74, - 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D, - 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82, - 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB, - 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0, - 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9 -}; - -#define SVQ1_PROCESS_VECTOR()\ - for (; level > 0; i++) {\ - /* process next depth */\ - if (i == m) {\ - m = n;\ - if (--level == 0)\ - break;\ - }\ - /* divide block if next bit set */\ - if (get_bits (bitbuf, 1) == 0)\ - break;\ - /* add child nodes */\ - list[n++] = list[i];\ - list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level / 2) + 1));\ - } - -#define SVQ1_ADD_CODEBOOK()\ - /* add codebook entries to vector */\ - for (j=0; j < stages; j++) {\ - n3 = codebook[entries[j]] ^ 0x80808080;\ - n1 += ((n3 & 0xFF00FF00) >> 8);\ - n2 += (n3 & 0x00FF00FF);\ - }\ -\ - /* clip to [0..255] */\ - if (n1 & 0xFF00FF00) {\ - n3 = ((( n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\ - n1 += 0x7F007F00;\ - n1 |= (((~n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\ - n1 &= (n3 & 0x00FF00FF);\ - }\ -\ - if (n2 & 0xFF00FF00) {\ - n3 = ((( n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\ - n2 += 0x7F007F00;\ - n2 |= (((~n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\ - n2 &= (n3 & 0x00FF00FF);\ - } - -#define SVQ1_DO_CODEBOOK_INTRA()\ - for (y=0; y < height; y++) {\ - for (x=0; x < (width / 4); x++, codebook++) {\ - n1 = n4;\ - n2 = n4;\ - SVQ1_ADD_CODEBOOK()\ - /* store result */\ - dst[x] = (n1 << 8) | n2;\ - }\ - dst += (pitch / 4);\ - } - -#define SVQ1_DO_CODEBOOK_NONINTRA()\ - for (y=0; y < height; y++) {\ - for (x=0; x < (width / 4); x++, codebook++) {\ - n3 = dst[x];\ - /* add mean value to vector */\ - n1 = ((n3 & 0xFF00FF00) >> 8) + n4;\ - n2 = (n3 & 0x00FF00FF) + n4;\ - SVQ1_ADD_CODEBOOK()\ - /* store result */\ - dst[x] = (n1 << 8) | n2;\ - }\ - dst += (pitch / 4);\ - } - -#define SVQ1_CALC_CODEBOOK_ENTRIES(cbook)\ - codebook = (const uint32_t *) cbook[level];\ - bit_cache = get_bits (bitbuf, 4*stages);\ - /* calculate codebook entries for this vector */\ - for (j=0; j < stages; j++) {\ - entries[j] = (((bit_cache >> (4*(stages - j - 1))) & 0xF) + 16*j) << (level + 1);\ - }\ - mean -= (stages * 128);\ - n4 = ((mean + (mean >> 31)) << 16) | (mean & 0xFFFF); - -static int svq1_decode_block_intra (GetBitContext *bitbuf, uint8_t *pixels, int pitch ) { - uint32_t bit_cache; - uint8_t *list[63]; - uint32_t *dst; - const uint32_t *codebook; - int entries[6]; - int i, j, m, n; - int mean, stages; - unsigned x, y, width, height, level; - uint32_t n1, n2, n3, n4; - - /* initialize list for breadth first processing of vectors */ - list[0] = pixels; - - /* recursively process vector */ - for (i=0, m=1, n=1, level=5; i < n; i++) { - SVQ1_PROCESS_VECTOR(); - - /* destination address and vector size */ - dst = (uint32_t *) list[i]; - width = 1 << ((4 + level) /2); - height = 1 << ((3 + level) /2); - - /* get number of stages (-1 skips vector, 0 for mean only) */ - stages = get_vlc2(bitbuf, svq1_intra_multistage[level].table, 3, 3) - 1; - - if (stages == -1) { - for (y=0; y < height; y++) { - memset (&dst[y*(pitch / 4)], 0, width); - } - continue; /* skip vector */ - } - - if ((stages > 0) && (level >= 4)) { -#ifdef DEBUG_SVQ1 - av_log(s->avctx, AV_LOG_INFO, "Error (svq1_decode_block_intra): invalid vector: stages=%i level=%i\n",stages,level); -#endif - return -1; /* invalid vector */ - } - - mean = get_vlc2(bitbuf, svq1_intra_mean.table, 8, 3); - - if (stages == 0) { - for (y=0; y < height; y++) { - memset (&dst[y*(pitch / 4)], mean, width); - } - } else { - SVQ1_CALC_CODEBOOK_ENTRIES(svq1_intra_codebooks); - SVQ1_DO_CODEBOOK_INTRA() - } - } - - return 0; -} - -static int svq1_decode_block_non_intra (GetBitContext *bitbuf, uint8_t *pixels, int pitch ) { - uint32_t bit_cache; - uint8_t *list[63]; - uint32_t *dst; - const uint32_t *codebook; - int entries[6]; - int i, j, m, n; - int mean, stages; - int x, y, width, height, level; - uint32_t n1, n2, n3, n4; - - /* initialize list for breadth first processing of vectors */ - list[0] = pixels; - - /* recursively process vector */ - for (i=0, m=1, n=1, level=5; i < n; i++) { - SVQ1_PROCESS_VECTOR(); - - /* destination address and vector size */ - dst = (uint32_t *) list[i]; - width = 1 << ((4 + level) /2); - height = 1 << ((3 + level) /2); - - /* get number of stages (-1 skips vector, 0 for mean only) */ - stages = get_vlc2(bitbuf, svq1_inter_multistage[level].table, 3, 2) - 1; - - if (stages == -1) continue; /* skip vector */ - - if ((stages > 0) && (level >= 4)) { -#ifdef DEBUG_SVQ1 - av_log(s->avctx, AV_LOG_INFO, "Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i\n",stages,level); -#endif - return -1; /* invalid vector */ - } - - mean = get_vlc2(bitbuf, svq1_inter_mean.table, 9, 3) - 256; - - SVQ1_CALC_CODEBOOK_ENTRIES(svq1_inter_codebooks); - SVQ1_DO_CODEBOOK_NONINTRA() - } - return 0; -} - -static int svq1_decode_motion_vector (GetBitContext *bitbuf, svq1_pmv_t *mv, svq1_pmv_t **pmv) { - int diff; - int i; - - for (i=0; i < 2; i++) { - - /* get motion code */ - diff = get_vlc2(bitbuf, svq1_motion_component.table, 7, 2); - if(diff<0) - return -1; - else if(diff){ - if(get_bits1(bitbuf)) diff= -diff; - } - - /* add median of motion vector predictors and clip result */ - if (i == 1) - mv->y = ((diff + mid_pred(pmv[0]->y, pmv[1]->y, pmv[2]->y)) << 26) >> 26; - else - mv->x = ((diff + mid_pred(pmv[0]->x, pmv[1]->x, pmv[2]->x)) << 26) >> 26; - } - - return 0; -} - -static void svq1_skip_block (uint8_t *current, uint8_t *previous, int pitch, int x, int y) { - uint8_t *src; - uint8_t *dst; - int i; - - src = &previous[x + y*pitch]; - dst = current; - - for (i=0; i < 16; i++) { - memcpy (dst, src, 16); - src += pitch; - dst += pitch; - } -} - -static int svq1_motion_inter_block (MpegEncContext *s, GetBitContext *bitbuf, - uint8_t *current, uint8_t *previous, int pitch, - svq1_pmv_t *motion, int x, int y) { - uint8_t *src; - uint8_t *dst; - svq1_pmv_t mv; - svq1_pmv_t *pmv[3]; - int result; - - /* predict and decode motion vector */ - pmv[0] = &motion[0]; - if (y == 0) { - pmv[1] = - pmv[2] = pmv[0]; - } - else { - pmv[1] = &motion[(x / 8) + 2]; - pmv[2] = &motion[(x / 8) + 4]; - } - - result = svq1_decode_motion_vector (bitbuf, &mv, pmv); - - if (result != 0) - return result; - - motion[0].x = - motion[(x / 8) + 2].x = - motion[(x / 8) + 3].x = mv.x; - motion[0].y = - motion[(x / 8) + 2].y = - motion[(x / 8) + 3].y = mv.y; - - if(y + (mv.y >> 1)<0) - mv.y= 0; - if(x + (mv.x >> 1)<0) - mv.x= 0; - -#if 0 - int w= (s->width+15)&~15; - int h= (s->height+15)&~15; - if(x + (mv.x >> 1)<0 || y + (mv.y >> 1)<0 || x + (mv.x >> 1) + 16 > w || y + (mv.y >> 1) + 16> h) - av_log(s->avctx, AV_LOG_INFO, "%d %d %d %d\n", x, y, x + (mv.x >> 1), y + (mv.y >> 1)); -#endif - - src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1))*pitch]; - dst = current; - - s->dsp.put_pixels_tab[0][((mv.y & 1) << 1) | (mv.x & 1)](dst,src,pitch,16); - - return 0; -} - -static int svq1_motion_inter_4v_block (MpegEncContext *s, GetBitContext *bitbuf, - uint8_t *current, uint8_t *previous, int pitch, - svq1_pmv_t *motion,int x, int y) { - uint8_t *src; - uint8_t *dst; - svq1_pmv_t mv; - svq1_pmv_t *pmv[4]; - int i, result; - - /* predict and decode motion vector (0) */ - pmv[0] = &motion[0]; - if (y == 0) { - pmv[1] = - pmv[2] = pmv[0]; - } - else { - pmv[1] = &motion[(x / 8) + 2]; - pmv[2] = &motion[(x / 8) + 4]; - } - - result = svq1_decode_motion_vector (bitbuf, &mv, pmv); - - if (result != 0) - return result; - - /* predict and decode motion vector (1) */ - pmv[0] = &mv; - if (y == 0) { - pmv[1] = - pmv[2] = pmv[0]; - } - else { - pmv[1] = &motion[(x / 8) + 3]; - } - result = svq1_decode_motion_vector (bitbuf, &motion[0], pmv); - - if (result != 0) - return result; - - /* predict and decode motion vector (2) */ - pmv[1] = &motion[0]; - pmv[2] = &motion[(x / 8) + 1]; - - result = svq1_decode_motion_vector (bitbuf, &motion[(x / 8) + 2], pmv); - - if (result != 0) - return result; - - /* predict and decode motion vector (3) */ - pmv[2] = &motion[(x / 8) + 2]; - pmv[3] = &motion[(x / 8) + 3]; - - result = svq1_decode_motion_vector (bitbuf, pmv[3], pmv); - - if (result != 0) - return result; - - /* form predictions */ - for (i=0; i < 4; i++) { - int mvx= pmv[i]->x + (i&1)*16; - int mvy= pmv[i]->y + (i>>1)*16; - - ///XXX /FIXME cliping or padding? - if(y + (mvy >> 1)<0) - mvy= 0; - if(x + (mvx >> 1)<0) - mvx= 0; - -#if 0 - int w= (s->width+15)&~15; - int h= (s->height+15)&~15; - if(x + (mvx >> 1)<0 || y + (mvy >> 1)<0 || x + (mvx >> 1) + 8 > w || y + (mvy >> 1) + 8> h) - av_log(s->avctx, AV_LOG_INFO, "%d %d %d %d\n", x, y, x + (mvx >> 1), y + (mvy >> 1)); -#endif - src = &previous[(x + (mvx >> 1)) + (y + (mvy >> 1))*pitch]; - dst = current; - - s->dsp.put_pixels_tab[1][((mvy & 1) << 1) | (mvx & 1)](dst,src,pitch,8); - - /* select next block */ - if (i & 1) { - current += 8*(pitch - 1); - } else { - current += 8; - } - } - - return 0; -} - -static int svq1_decode_delta_block (MpegEncContext *s, GetBitContext *bitbuf, - uint8_t *current, uint8_t *previous, int pitch, - svq1_pmv_t *motion, int x, int y) { - uint32_t block_type; - int result = 0; - - /* get block type */ - block_type = get_vlc2(bitbuf, svq1_block_type.table, 2, 2); - - /* reset motion vectors */ - if (block_type == SVQ1_BLOCK_SKIP || block_type == SVQ1_BLOCK_INTRA) { - motion[0].x = - motion[0].y = - motion[(x / 8) + 2].x = - motion[(x / 8) + 2].y = - motion[(x / 8) + 3].x = - motion[(x / 8) + 3].y = 0; - } - - switch (block_type) { - case SVQ1_BLOCK_SKIP: - svq1_skip_block (current, previous, pitch, x, y); - break; - - case SVQ1_BLOCK_INTER: - result = svq1_motion_inter_block (s, bitbuf, current, previous, pitch, motion, x, y); - - if (result != 0) - { -#ifdef DEBUG_SVQ1 - av_log(s->avctx, AV_LOG_INFO, "Error in svq1_motion_inter_block %i\n",result); -#endif - break; - } - result = svq1_decode_block_non_intra (bitbuf, current, pitch); - break; - - case SVQ1_BLOCK_INTER_4V: - result = svq1_motion_inter_4v_block (s, bitbuf, current, previous, pitch, motion, x, y); - - if (result != 0) - { -#ifdef DEBUG_SVQ1 - av_log(s->avctx, AV_LOG_INFO, "Error in svq1_motion_inter_4v_block %i\n",result); -#endif - break; - } - result = svq1_decode_block_non_intra (bitbuf, current, pitch); - break; - - case SVQ1_BLOCK_INTRA: - result = svq1_decode_block_intra (bitbuf, current, pitch); - break; - } - - return result; -} - /* standard video sizes */ -static struct { int width; int height; } svq1_frame_size_table[8] = { +const svq1_frame_size_t ff_svq1_frame_size_table[8] = { { 160, 120 }, { 128, 96 }, { 176, 144 }, { 352, 288 }, { 704, 576 }, { 240, 180 }, { 320, 240 }, { -1, -1 } }; - -static uint16_t svq1_packet_checksum (uint8_t *data, int length, int value) { - int i; - - for (i=0; i < length; i++) { - value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8); - } - - return value; -} - -#if 0 /* unused, remove? */ -static uint16_t svq1_component_checksum (uint16_t *pixels, int pitch, - int width, int height, int value) { - int x, y; - - for (y=0; y < height; y++) { - for (x=0; x < width; x++) { - value = checksum_table[pixels[x] ^ (value >> 8)] ^ ((value & 0xFF) << 8); - } - - pixels += pitch; - } - - return value; -} -#endif - -#ifdef CONFIG_DECODERS -static void svq1_parse_string (GetBitContext *bitbuf, uint8_t *out) { - uint8_t seed; - int i; - - out[0] = get_bits (bitbuf, 8); - - seed = string_table[out[0]]; - - for (i=1; i <= out[0]; i++) { - out[i] = get_bits (bitbuf, 8) ^ seed; - seed = string_table[out[i] ^ seed]; - } -} - -static int svq1_decode_frame_header (GetBitContext *bitbuf,MpegEncContext *s) { - int frame_size_code; - int temporal_reference; - - temporal_reference = get_bits (bitbuf, 8); - - /* frame type */ - s->pict_type= get_bits (bitbuf, 2)+1; - if(s->pict_type==4) - return -1; - - if (s->pict_type == I_TYPE) { - - /* unknown fields */ - if (s->f_code == 0x50 || s->f_code == 0x60) { - int csum = get_bits (bitbuf, 16); - - csum = svq1_packet_checksum ((uint8_t *)bitbuf->buffer, bitbuf->size_in_bits>>3, csum); - -// av_log(s->avctx, AV_LOG_INFO, "%s checksum (%02x) for packet data\n", -// (csum == 0) ? "correct" : "incorrect", csum); - } - - if ((s->f_code ^ 0x10) >= 0x50) { - uint8_t msg[256]; - - svq1_parse_string (bitbuf, msg); - - av_log(s->avctx, AV_LOG_INFO, "embedded message: \"%s\"\n", (char *) msg); - } - - skip_bits (bitbuf, 2); - skip_bits (bitbuf, 2); - skip_bits1 (bitbuf); - - /* load frame size */ - frame_size_code = get_bits (bitbuf, 3); - - if (frame_size_code == 7) { - /* load width, height (12 bits each) */ - s->width = get_bits (bitbuf, 12); - s->height = get_bits (bitbuf, 12); - - if (!s->width || !s->height) - return -1; - } else { - /* get width, height from table */ - s->width = svq1_frame_size_table[frame_size_code].width; - s->height = svq1_frame_size_table[frame_size_code].height; - } - } - - /* unknown fields */ - if (get_bits (bitbuf, 1) == 1) { - skip_bits1 (bitbuf); /* use packet checksum if (1) */ - skip_bits1 (bitbuf); /* component checksums after image data if (1) */ - - if (get_bits (bitbuf, 2) != 0) - return -1; - } - - if (get_bits (bitbuf, 1) == 1) { - skip_bits1 (bitbuf); - skip_bits (bitbuf, 4); - skip_bits1 (bitbuf); - skip_bits (bitbuf, 2); - - while (get_bits (bitbuf, 1) == 1) { - skip_bits (bitbuf, 8); - } - } - - return 0; -} - -static int svq1_decode_frame(AVCodecContext *avctx, - void *data, int *data_size, - uint8_t *buf, int buf_size) -{ - MpegEncContext *s=avctx->priv_data; - uint8_t *current, *previous; - int result, i, x, y, width, height; - AVFrame *pict = data; - - /* initialize bit buffer */ - init_get_bits(&s->gb,buf,buf_size*8); - - /* decode frame header */ - s->f_code = get_bits (&s->gb, 22); - - if ((s->f_code & ~0x70) || !(s->f_code & 0x60)) - return -1; - - /* swap some header bytes (why?) */ - if (s->f_code != 0x20) { - uint32_t *src = (uint32_t *) (buf + 4); - - for (i=0; i < 4; i++) { - src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i]; - } - } - - result = svq1_decode_frame_header (&s->gb, s); - - if (result != 0) - { -#ifdef DEBUG_SVQ1 - av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_frame_header %i\n",result); -#endif - return result; - } - - //FIXME this avoids some confusion for "B frames" without 2 references - //this should be removed after libavcodec can handle more flexible picture types & ordering - if(s->pict_type==B_TYPE && s->last_picture_ptr==NULL) return buf_size; - - if(avctx->hurry_up && s->pict_type==B_TYPE) return buf_size; - if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE) - ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE) - || avctx->skip_frame >= AVDISCARD_ALL) - return buf_size; - - if(MPV_frame_start(s, avctx) < 0) - return -1; - - /* decode y, u and v components */ - for (i=0; i < 3; i++) { - int linesize; - if (i == 0) { - width = (s->width+15)&~15; - height = (s->height+15)&~15; - linesize= s->linesize; - } else { - if(s->flags&CODEC_FLAG_GRAY) break; - width = (s->width/4+15)&~15; - height = (s->height/4+15)&~15; - linesize= s->uvlinesize; - } - - current = s->current_picture.data[i]; - - if(s->pict_type==B_TYPE){ - previous = s->next_picture.data[i]; - }else{ - previous = s->last_picture.data[i]; - } - - if (s->pict_type == I_TYPE) { - /* keyframe */ - for (y=0; y < height; y+=16) { - for (x=0; x < width; x+=16) { - result = svq1_decode_block_intra (&s->gb, ¤t[x], linesize); - if (result != 0) - { -//#ifdef DEBUG_SVQ1 - av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_block %i (keyframe)\n",result); -//#endif - return result; - } - } - current += 16*linesize; - } - } else { - svq1_pmv_t pmv[width/8+3]; - /* delta frame */ - memset (pmv, 0, ((width / 8) + 3) * sizeof(svq1_pmv_t)); - - for (y=0; y < height; y+=16) { - for (x=0; x < width; x+=16) { - result = svq1_decode_delta_block (s, &s->gb, ¤t[x], previous, - linesize, pmv, x, y); - if (result != 0) - { -#ifdef DEBUG_SVQ1 - av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_delta_block %i\n",result); -#endif - return result; - } - } - - pmv[0].x = - pmv[0].y = 0; - - current += 16*linesize; - } - } - } - - *pict = *(AVFrame*)&s->current_picture; - - - MPV_frame_end(s); - - *data_size=sizeof(AVFrame); - return buf_size; -} - -static int svq1_decode_init(AVCodecContext *avctx) -{ - MpegEncContext *s = avctx->priv_data; - int i; - - MPV_decode_defaults(s); - - s->avctx = avctx; - s->width = (avctx->width+3)&~3; - s->height = (avctx->height+3)&~3; - s->codec_id= avctx->codec->id; - avctx->pix_fmt = PIX_FMT_YUV410P; - avctx->has_b_frames= 1; // not true, but DP frames and these behave like unidirectional b frames - s->flags= avctx->flags; - if (MPV_common_init(s) < 0) return -1; - - init_vlc(&svq1_block_type, 2, 4, - &svq1_block_type_vlc[0][1], 2, 1, - &svq1_block_type_vlc[0][0], 2, 1, 1); - - init_vlc(&svq1_motion_component, 7, 33, - &mvtab[0][1], 2, 1, - &mvtab[0][0], 2, 1, 1); - - for (i = 0; i < 6; i++) { - init_vlc(&svq1_intra_multistage[i], 3, 8, - &svq1_intra_multistage_vlc[i][0][1], 2, 1, - &svq1_intra_multistage_vlc[i][0][0], 2, 1, 1); - init_vlc(&svq1_inter_multistage[i], 3, 8, - &svq1_inter_multistage_vlc[i][0][1], 2, 1, - &svq1_inter_multistage_vlc[i][0][0], 2, 1, 1); - } - - init_vlc(&svq1_intra_mean, 8, 256, - &svq1_intra_mean_vlc[0][1], 4, 2, - &svq1_intra_mean_vlc[0][0], 4, 2, 1); - - init_vlc(&svq1_inter_mean, 9, 512, - &svq1_inter_mean_vlc[0][1], 4, 2, - &svq1_inter_mean_vlc[0][0], 4, 2, 1); - - return 0; -} - -static int svq1_decode_end(AVCodecContext *avctx) -{ - MpegEncContext *s = avctx->priv_data; - - MPV_common_end(s); - return 0; -} -#endif /* CONFIG_DECODERS */ - -#ifdef CONFIG_ENCODERS -static void svq1_write_header(SVQ1Context *s, int frame_type) -{ - int i; - - /* frame code */ - put_bits(&s->pb, 22, 0x20); - - /* temporal reference (sure hope this is a "don't care") */ - put_bits(&s->pb, 8, 0x00); - - /* frame type */ - put_bits(&s->pb, 2, frame_type - 1); - - if (frame_type == I_TYPE) { - - /* no checksum since frame code is 0x20 */ - - /* no embedded string either */ - - /* output 5 unknown bits (2 + 2 + 1) */ - put_bits(&s->pb, 5, 2); /* 2 needed by quicktime decoder */ - - for (i = 0; i < 7; i++) - { - if ((svq1_frame_size_table[i].width == s->frame_width) && - (svq1_frame_size_table[i].height == s->frame_height)) - { - put_bits(&s->pb, 3, i); - break; - } - } - - if (i == 7) - { - put_bits(&s->pb, 3, 7); - put_bits(&s->pb, 12, s->frame_width); - put_bits(&s->pb, 12, s->frame_height); - } - } - - /* no checksum or extra data (next 2 bits get 0) */ - put_bits(&s->pb, 2, 0); -} - - -#define QUALITY_THRESHOLD 100 -#define THRESHOLD_MULTIPLIER 0.6 - -#if defined(HAVE_ALTIVEC) -#undef vector -#endif - -static int encode_block(SVQ1Context *s, uint8_t *src, uint8_t *ref, uint8_t *decoded, int stride, int level, int threshold, int lambda, int intra){ - int count, y, x, i, j, split, best_mean, best_score, best_count; - int best_vector[6]; - int block_sum[7]= {0, 0, 0, 0, 0, 0}; - int w= 2<<((level+2)>>1); - int h= 2<<((level+1)>>1); - int size=w*h; - int16_t block[7][256]; - const int8_t *codebook_sum, *codebook; - const uint16_t (*mean_vlc)[2]; - const uint8_t (*multistage_vlc)[2]; - - best_score=0; - //FIXME optimize, this doenst need to be done multiple times - if(intra){ - codebook_sum= svq1_intra_codebook_sum[level]; - codebook= svq1_intra_codebooks[level]; - mean_vlc= svq1_intra_mean_vlc; - multistage_vlc= svq1_intra_multistage_vlc[level]; - for(y=0; y>(level+3)); - best_mean= (block_sum[0] + (size>>1)) >> (level+3); - - if(level<4){ - for(count=1; count<7; count++){ - int best_vector_score= INT_MAX; - int best_vector_sum=-999, best_vector_mean=-999; - const int stage= count-1; - const int8_t *vector; - - for(i=0; i<16; i++){ - int sum= codebook_sum[stage*16 + i]; - int sqr, diff, score; - - vector = codebook + stage*size*16 + i*size; - sqr = s->dsp.ssd_int8_vs_int16(vector, block[stage], size); - diff= block_sum[stage] - sum; - score= sqr - ((diff*(int64_t)diff)>>(level+3)); //FIXME 64bit slooow - if(score < best_vector_score){ - int mean= (diff + (size>>1)) >> (level+3); - assert(mean >-300 && mean<300); - mean= av_clip(mean, intra?0:-256, 255); - best_vector_score= score; - best_vector[stage]= i; - best_vector_sum= sum; - best_vector_mean= mean; - } - } - assert(best_vector_mean != -999); - vector= codebook + stage*size*16 + best_vector[stage]*size; - for(j=0; j threshold && level){ - int score=0; - int offset= (level&1) ? stride*h/2 : w/2; - PutBitContext backup[6]; - - for(i=level-1; i>=0; i--){ - backup[i]= s->reorder_pb[i]; - } - score += encode_block(s, src , ref , decoded , stride, level-1, threshold>>1, lambda, intra); - score += encode_block(s, src + offset, ref + offset, decoded + offset, stride, level-1, threshold>>1, lambda, intra); - score += lambda; - - if(score < best_score){ - best_score= score; - split=1; - }else{ - for(i=level-1; i>=0; i--){ - s->reorder_pb[i]= backup[i]; - } - } - } - if (level > 0) - put_bits(&s->reorder_pb[level], 1, split); - - if(!split){ - assert((best_mean >= 0 && best_mean<256) || !intra); - assert(best_mean >= -256 && best_mean<256); - assert(best_count >=0 && best_count<7); - assert(level<4 || best_count==0); - - /* output the encoding */ - put_bits(&s->reorder_pb[level], - multistage_vlc[1 + best_count][1], - multistage_vlc[1 + best_count][0]); - put_bits(&s->reorder_pb[level], mean_vlc[best_mean][1], - mean_vlc[best_mean][0]); - - for (i = 0; i < best_count; i++){ - assert(best_vector[i]>=0 && best_vector[i]<16); - put_bits(&s->reorder_pb[level], 4, best_vector[i]); - } - - for(y=0; ypicture.quality*s->picture.quality) >> (2*FF_LAMBDA_SHIFT); - - /* figure out the acceptable level thresholds in advance */ - threshold[5] = QUALITY_THRESHOLD; - for (level = 4; level >= 0; level--) - threshold[level] = threshold[level + 1] * THRESHOLD_MULTIPLIER; - - block_width = (width + 15) / 16; - block_height = (height + 15) / 16; - - if(s->picture.pict_type == P_TYPE){ - s->m.avctx= s->avctx; - s->m.current_picture_ptr= &s->m.current_picture; - s->m.last_picture_ptr = &s->m.last_picture; - s->m.last_picture.data[0]= ref_plane; - s->m.linesize= - s->m.last_picture.linesize[0]= - s->m.new_picture.linesize[0]= - s->m.current_picture.linesize[0]= stride; - s->m.width= width; - s->m.height= height; - s->m.mb_width= block_width; - s->m.mb_height= block_height; - s->m.mb_stride= s->m.mb_width+1; - s->m.b8_stride= 2*s->m.mb_width+1; - s->m.f_code=1; - s->m.pict_type= s->picture.pict_type; - s->m.me_method= s->avctx->me_method; - s->m.me.scene_change_score=0; - s->m.flags= s->avctx->flags; -// s->m.out_format = FMT_H263; -// s->m.unrestricted_mv= 1; - - s->m.lambda= s->picture.quality; - s->m.qscale= (s->m.lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); - s->m.lambda2= (s->m.lambda*s->m.lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT; - - if(!s->motion_val8[plane]){ - s->motion_val8 [plane]= av_mallocz((s->m.b8_stride*block_height*2 + 2)*2*sizeof(int16_t)); - s->motion_val16[plane]= av_mallocz((s->m.mb_stride*(block_height + 2) + 1)*2*sizeof(int16_t)); - } - - s->m.mb_type= s->mb_type; - - //dummies, to avoid segfaults - s->m.current_picture.mb_mean= (uint8_t *)s->dummy; - s->m.current_picture.mb_var= (uint16_t*)s->dummy; - s->m.current_picture.mc_mb_var= (uint16_t*)s->dummy; - s->m.current_picture.mb_type= s->dummy; - - s->m.current_picture.motion_val[0]= s->motion_val8[plane] + 2; - s->m.p_mv_table= s->motion_val16[plane] + s->m.mb_stride + 1; - s->m.dsp= s->dsp; //move - ff_init_me(&s->m); - - s->m.me.dia_size= s->avctx->dia_size; - s->m.first_slice_line=1; - for (y = 0; y < block_height; y++) { - uint8_t src[stride*16]; - - s->m.new_picture.data[0]= src - y*16*stride; //ugly - s->m.mb_y= y; - - for(i=0; i<16 && i + 16*ym.mb_x= x; - ff_init_block_index(&s->m); - ff_update_block_index(&s->m); - - ff_estimate_p_frame_motion(&s->m, x, y); - } - s->m.first_slice_line=0; - } - - ff_fix_long_p_mvs(&s->m); - ff_fix_long_mvs(&s->m, NULL, 0, s->m.p_mv_table, s->m.f_code, CANDIDATE_MB_TYPE_INTER, 0); - } - - s->m.first_slice_line=1; - for (y = 0; y < block_height; y++) { - uint8_t src[stride*16]; - - for(i=0; i<16 && i + 16*ym.mb_y= y; - for (x = 0; x < block_width; x++) { - uint8_t reorder_buffer[3][6][7*32]; - int count[3][6]; - int offset = y * 16 * stride + x * 16; - uint8_t *decoded= decoded_plane + offset; - uint8_t *ref= ref_plane + offset; - int score[4]={0,0,0,0}, best; - uint8_t temp[16*stride]; - - if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 3000){ //FIXME check size - av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); - return -1; - } - - s->m.mb_x= x; - ff_init_block_index(&s->m); - ff_update_block_index(&s->m); - - if(s->picture.pict_type == I_TYPE || (s->m.mb_type[x + y*s->m.mb_stride]&CANDIDATE_MB_TYPE_INTRA)){ - for(i=0; i<6; i++){ - init_put_bits(&s->reorder_pb[i], reorder_buffer[0][i], 7*32); - } - if(s->picture.pict_type == P_TYPE){ - const uint8_t *vlc= svq1_block_type_vlc[SVQ1_BLOCK_INTRA]; - put_bits(&s->reorder_pb[5], vlc[1], vlc[0]); - score[0]= vlc[1]*lambda; - } - score[0]+= encode_block(s, src+16*x, NULL, temp, stride, 5, 64, lambda, 1); - for(i=0; i<6; i++){ - count[0][i]= put_bits_count(&s->reorder_pb[i]); - flush_put_bits(&s->reorder_pb[i]); - } - }else - score[0]= INT_MAX; - - best=0; - - if(s->picture.pict_type == P_TYPE){ - const uint8_t *vlc= svq1_block_type_vlc[SVQ1_BLOCK_INTER]; - int mx, my, pred_x, pred_y, dxy; - int16_t *motion_ptr; - - motion_ptr= h263_pred_motion(&s->m, 0, 0, &pred_x, &pred_y); - if(s->m.mb_type[x + y*s->m.mb_stride]&CANDIDATE_MB_TYPE_INTER){ - for(i=0; i<6; i++) - init_put_bits(&s->reorder_pb[i], reorder_buffer[1][i], 7*32); - - put_bits(&s->reorder_pb[5], vlc[1], vlc[0]); - - s->m.pb= s->reorder_pb[5]; - mx= motion_ptr[0]; - my= motion_ptr[1]; - assert(mx>=-32 && mx<=31); - assert(my>=-32 && my<=31); - assert(pred_x>=-32 && pred_x<=31); - assert(pred_y>=-32 && pred_y<=31); - ff_h263_encode_motion(&s->m, mx - pred_x, 1); - ff_h263_encode_motion(&s->m, my - pred_y, 1); - s->reorder_pb[5]= s->m.pb; - score[1] += lambda*put_bits_count(&s->reorder_pb[5]); - - dxy= (mx&1) + 2*(my&1); - - s->dsp.put_pixels_tab[0][dxy](temp+16, ref + (mx>>1) + stride*(my>>1), stride, 16); - - score[1]+= encode_block(s, src+16*x, temp+16, decoded, stride, 5, 64, lambda, 0); - best= score[1] <= score[0]; - - vlc= svq1_block_type_vlc[SVQ1_BLOCK_SKIP]; - score[2]= s->dsp.sse[0](NULL, src+16*x, ref, stride, 16); - score[2]+= vlc[1]*lambda; - if(score[2] < score[best] && mx==0 && my==0){ - best=2; - s->dsp.put_pixels_tab[0][0](decoded, ref, stride, 16); - for(i=0; i<6; i++){ - count[2][i]=0; - } - put_bits(&s->pb, vlc[1], vlc[0]); - } - } - - if(best==1){ - for(i=0; i<6; i++){ - count[1][i]= put_bits_count(&s->reorder_pb[i]); - flush_put_bits(&s->reorder_pb[i]); - } - }else{ - motion_ptr[0 ] = motion_ptr[1 ]= - motion_ptr[2 ] = motion_ptr[3 ]= - motion_ptr[0+2*s->m.b8_stride] = motion_ptr[1+2*s->m.b8_stride]= - motion_ptr[2+2*s->m.b8_stride] = motion_ptr[3+2*s->m.b8_stride]=0; - } - } - - s->rd_total += score[best]; - - for(i=5; i>=0; i--){ - ff_copy_bits(&s->pb, reorder_buffer[best][i], count[best][i]); - } - if(best==0){ - s->dsp.put_pixels_tab[0][0](decoded, temp, stride, 16); - } - } - s->m.first_slice_line=0; - } - return 0; -} - -static int svq1_encode_init(AVCodecContext *avctx) -{ - SVQ1Context * const s = avctx->priv_data; - - dsputil_init(&s->dsp, avctx); - avctx->coded_frame= (AVFrame*)&s->picture; - - s->frame_width = avctx->width; - s->frame_height = avctx->height; - - s->y_block_width = (s->frame_width + 15) / 16; - s->y_block_height = (s->frame_height + 15) / 16; - - s->c_block_width = (s->frame_width / 4 + 15) / 16; - s->c_block_height = (s->frame_height / 4 + 15) / 16; - - s->avctx= avctx; - s->m.avctx= avctx; - s->m.me.scratchpad= av_mallocz((avctx->width+64)*2*16*2*sizeof(uint8_t)); - s->m.me.map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); - s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); - s->mb_type = av_mallocz((s->y_block_width+1)*s->y_block_height*sizeof(int16_t)); - s->dummy = av_mallocz((s->y_block_width+1)*s->y_block_height*sizeof(int32_t)); - h263_encode_init(&s->m); //mv_penalty - - return 0; -} - -static int svq1_encode_frame(AVCodecContext *avctx, unsigned char *buf, - int buf_size, void *data) -{ - SVQ1Context * const s = avctx->priv_data; - AVFrame *pict = data; - AVFrame * const p= (AVFrame*)&s->picture; - AVFrame temp; - int i; - - if(avctx->pix_fmt != PIX_FMT_YUV410P){ - av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n"); - return -1; - } - - if(!s->current_picture.data[0]){ - avctx->get_buffer(avctx, &s->current_picture); - avctx->get_buffer(avctx, &s->last_picture); - } - - temp= s->current_picture; - s->current_picture= s->last_picture; - s->last_picture= temp; - - init_put_bits(&s->pb, buf, buf_size); - - *p = *pict; - p->pict_type = avctx->gop_size && avctx->frame_number % avctx->gop_size ? P_TYPE : I_TYPE; - p->key_frame = p->pict_type == I_TYPE; - - svq1_write_header(s, p->pict_type); - for(i=0; i<3; i++){ - if(svq1_encode_plane(s, i, - s->picture.data[i], s->last_picture.data[i], s->current_picture.data[i], - s->frame_width / (i?4:1), s->frame_height / (i?4:1), - s->picture.linesize[i], s->current_picture.linesize[i]) < 0) - return -1; - } - -// align_put_bits(&s->pb); - while(put_bits_count(&s->pb) & 31) - put_bits(&s->pb, 1, 0); - - flush_put_bits(&s->pb); - - return (put_bits_count(&s->pb) / 8); -} - -static int svq1_encode_end(AVCodecContext *avctx) -{ - SVQ1Context * const s = avctx->priv_data; - int i; - - av_log(avctx, AV_LOG_DEBUG, "RD: %f\n", s->rd_total/(double)(avctx->width*avctx->height*avctx->frame_number)); - - av_freep(&s->m.me.scratchpad); - av_freep(&s->m.me.map); - av_freep(&s->m.me.score_map); - av_freep(&s->mb_type); - av_freep(&s->dummy); - - for(i=0; i<3; i++){ - av_freep(&s->motion_val8[i]); - av_freep(&s->motion_val16[i]); - } - - return 0; -} - -#endif //CONFIG_ENCODERS - -#ifdef CONFIG_DECODERS -AVCodec svq1_decoder = { - "svq1", - CODEC_TYPE_VIDEO, - CODEC_ID_SVQ1, - sizeof(MpegEncContext), - svq1_decode_init, - NULL, - svq1_decode_end, - svq1_decode_frame, - CODEC_CAP_DR1, - .flush= ff_mpeg_flush, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV410P, -1}, -}; -#endif - -#ifdef CONFIG_ENCODERS - -AVCodec svq1_encoder = { - "svq1", - CODEC_TYPE_VIDEO, - CODEC_ID_SVQ1, - sizeof(SVQ1Context), - svq1_encode_init, - svq1_encode_frame, - svq1_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV410P, -1}, -}; - -#endif //CONFIG_ENCODERS diff --git a/contrib/ffmpeg/libavcodec/svq1.h b/contrib/ffmpeg/libavcodec/svq1.h new file mode 100644 index 000000000..7764dd8dd --- /dev/null +++ b/contrib/ffmpeg/libavcodec/svq1.h @@ -0,0 +1,61 @@ +/* + * SVQ1 decoder + * ported to MPlayer by Arpi + * ported to libavcodec by Nick Kurshev + * + * Copyright (C) 2002 the xine project + * Copyright (C) 2002 the ffmpeg project + * + * SVQ1 Encoder (c) 2004 Mike Melanson + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file svq1.h + * Sorenson Vector Quantizer #1 (SVQ1) video codec. + * For more information of the SVQ1 algorithm, visit: + * http://www.pcisys.net/~melanson/codecs/ + */ + +#ifndef FFMPEG_SVQ1_H +#define FFMPEG_SVQ1_H + +#include + +#define SVQ1_BLOCK_SKIP 0 +#define SVQ1_BLOCK_INTER 1 +#define SVQ1_BLOCK_INTER_4V 2 +#define SVQ1_BLOCK_INTRA 3 + +typedef struct { + int width; + int height; +} svq1_frame_size_t; + +extern const int8_t* const ff_svq1_inter_codebooks[6]; +extern const int8_t* const ff_svq1_intra_codebooks[6]; + +extern const uint8_t ff_svq1_block_type_vlc[4][2]; +extern const uint8_t ff_svq1_intra_multistage_vlc[6][8][2]; +extern const uint8_t ff_svq1_inter_multistage_vlc[6][8][2]; +extern const uint16_t ff_svq1_intra_mean_vlc[256][2]; +extern const uint16_t ff_svq1_inter_mean_vlc[512][2]; + +extern const svq1_frame_size_t ff_svq1_frame_size_table[8]; + +#endif /* FFMPEG_SVQ1_H */ diff --git a/contrib/ffmpeg/libavcodec/svq1_cb.h b/contrib/ffmpeg/libavcodec/svq1_cb.h index a0748bd44..f4a4054d1 100644 --- a/contrib/ffmpeg/libavcodec/svq1_cb.h +++ b/contrib/ffmpeg/libavcodec/svq1_cb.h @@ -1,4 +1,7 @@ /* + * SVQ1 decoder + * ported to MPlayer by Arpi + * ported to libavcodec by Nick Kurshev * * Copyright (C) 2002 the xine project * Copyright (C) 2002 the ffmpeg project @@ -18,10 +21,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Ported to mplayer by Arpi - * Ported to libavcodec by Nick Kurshev - * */ /** @@ -29,6 +28,12 @@ * svq1 code books. */ +#ifndef FFMPEG_SVQ1_CB_H +#define FFMPEG_SVQ1_CB_H + +#include +#include + /* 6x16-entry codebook for inter-coded 4x2 vectors */ static const int8_t svq1_inter_codebook_4x2[768] = { 7, 2, -6, -7, 7, 3, -3, -4, -7, -2, 7, 8, -8, -4, 3, 4, @@ -766,44 +771,12 @@ static const int8_t svq1_inter_codebook_8x8[6144] = { }; /* list of codebooks for inter-coded vectors */ -static const int8_t* const svq1_inter_codebooks[6] = { +const int8_t* const ff_svq1_inter_codebooks[6] = { svq1_inter_codebook_4x2, svq1_inter_codebook_4x4, svq1_inter_codebook_8x4, svq1_inter_codebook_8x8, NULL, NULL, }; -static const int8_t svq1_inter_codebook_sum[4][16*6] = { - { - -1, 1, -2, 0, 1, -1, -1, -1, -2, -1, 1, -1, -1, 0, -1, -1, - 0, -1, -1, -1, -1, 0, -1, 0, 0, 0, -3, 1, -1, 0, 1, -1, - 1, -1, 2, 2, 1, 1, 2, 0, 0, 0, -1, 1, 1, 0, 0, 0, - 1, -1, 0, 1, -1, 1, 1, 0, 1, 0, -1, 1, 1, 0, 0, 0, - -2, 0, 0, -2, 0, 0, -2, 0, -2, -1, -2, -1, 0, 0, -1, 0, - 1, 0, 1, -1, 2, 2, 1, 2, 2, 1, 0, 1, 1, 0, 1, 1, - },{ - -2, 1, -1, -1, 1, 0, 1, -1, -1, -1, 1, -1, 0, -1, 0, -1, - 0, 0, 0, -2, 0, 1, 0, -1, -1, 0, 2, -3, 1, -2, 3, -1, - 2, 0, 2, 1, 1, -1, 1, 1, 0, 0, 1, 1, 2, -2, 1, 0, - -2, -1, 2, -2, -2, 0, -3, 0, -1, 0, -1, 0, -1, 0, -2, -3, - 1, -2, -2, -1, 1, -1, -1, 1, -1, 1, 1, 0, -2, 0, 1, 1, - 1, 1, 2, 1, 0, 0, -1, 0, 0, 1, 0, 1, -1, 1, 0, 2, - },{ - 0, 0, 0, -3, 1, 1, 1, -3, 0, -1, 0, -3, 1, -3, 0, -2, - 1, 2, -1, -3, 0, -3, 1, -1, 0, -1, 0, 0, 1, 2, 1, 1, - -1, 2, -3, 3, 1, 0, -5, 1, 0, -1, -3, 1, 0, 2, 0, -3, - 4, 2, 0, -2, 1, -2, 3, -2, 1, 1, 0, -1, 2, 5, 3, 1, - -1, 0, 2, -3, -2, 0, 0, -2, 2, -3, -1, -1, 2, 1, 0, -2, - 3, -1, 1, -1, 2, 4, 0, 1, 0, 1, 0, -1, -3, -2, -1, 0, - },{ - 0, 2, -1, -1, 2, -4, -2, 3, 0, -1, -5, 1, 0, 1, 0, 6, - -2, 2, 0, 1, 1, -1, -1, -2, 1, -2, -1, 0, 2, -2, -2, -1, - -4, 2, -1, -3, -1, -2, 2, -1, 2, -1, 2, 0, 3, -3, -3, 0, - -3, 0, 0, -2, 4, -4, 0, -1, 4, 0, -2, -2, 3, -2, 0, 4, - 5, 0, 1, 0, -3, 3, 3, 2, 0, 0, 1, 2, -5, -2, -3, 0, - -3, 2, -2, 2, -2, 4, 7, -3, 4, 2, 3, 2, -1, 0, -3, 1, - } -}; - /* 6x16-entry codebook for intra-coded 4x2 vectors */ static const int8_t svq1_intra_codebook_4x2[768] = { 12, 13, 13, 11, -7,-10,-15,-17,-16,-15,-12,-10, 11, 15, 15, 12, @@ -1541,40 +1514,10 @@ static const int8_t svq1_intra_codebook_8x8[6144] = { }; /* list of codebooks for intra-coded vectors */ -static const int8_t* const svq1_intra_codebooks[6] = { +const int8_t* const ff_svq1_intra_codebooks[6] = { svq1_intra_codebook_4x2, svq1_intra_codebook_4x4, svq1_intra_codebook_8x4, svq1_intra_codebook_8x8, NULL, NULL, }; -static const int8_t svq1_intra_codebook_sum[4][16*6] = { - { - 0, 0, 0, -1, -1, -1, -1, -2, 0, -1, -1, 0, -1, 0, 1, 0, - 1, 0, -1, 1, 0, 0, -1, 1, -1, 0, 0, 0, -1, 1, 0, 0, - -1, 0, 0, 1, -1, 1, 0, -1, -1, 0, 1, 1, 0, 0, -1, 1, - 0, 1, 0, 0, 1, -1, 0, 0, 0, -1, 1, 0, 1, 0, -2, 1, - 0, -1, 1, 0, 0, 0, 1, 0, -1, 0, 0, 0, -1, 0, 0, 0, - 0, 1, 1, 0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 1, 1, -1, - },{ - -1, -2, 0, -1, 1, 0, -1, 0, -1, -4, -1, -2, -1, -2, 1, -2, - 0, 0, 4, -2, -1, 1, 1, 0, 2, 1, 1, 0, 2, 0, 0, 0, - 1, 1, 0, -1, -1, -1, 1, 0, -1, -3, -3, 1, -1, 1, -2, -1, - 1, -1, 0, 1, 2, 1, -1, -1, 1, 1, 1, 2, 1, 0, 1, -2, - -2, 0, -1, -2, -2, 0, -1, -1, -1, 0, 1, 0, -1, -1, 0, -1, - 0, 2, 1, 2, 2, 1, -1, 1, 0, 2, 0, -1, 1, 0, 0, 0, - },{ - -2, 0, -1, -1, 1, 1, -2, 0, -2, 0, 1, -2, -2, 1, -1, -1, - 3, -2, 0, -3, -4, -3, 2, 1, 0, 3, -2, 2, 3, 2, 2, -1, - -3, 1, 0, 1, 0, 0, 0, 1, -2, 1, -2, -2, -1, -2, -2, 2, - 0, -4, 0, 2, -1, 0, 2, 2, 2, 1, 0, -1, -1, 1, -3, 2, - 2, 1, 0, 3, 1, -1, 1, 3, 1, 0, 1, 1, 2, -1, 1, -1, - -2, -1, 0, -1, 1, -1, 1, -2, -2, -1, -1, -3, 1, -4, -3, 1, - },{ - -2, 0, -2, 3, -1, -1, 0, 2, 2, -1, -3, 2, 1, 0, -2, -1, - -3, -2, -2, 1, 2, -3, 0, 1, -5, -2, -3, 0, -2, -1, 2, 0, - -1, -1, 0, -2, 1, 3, -7, -2, -2, -1, 2, -1, 0, 3, 1, 3, - 1, 0, 0, 1, 2, 3, 1, 2, 0, -2, -2, 1, 1, 2, 2, 3, - 4, 1, -1, 2, -2, 4, 0, 0, 0, 4, 2, 0, -2, -2, 2, -4, - -1, 5, -2, -2, -3, 2, -3, -1, 3, -3, 0, 4, 3, 0, 1, -2, - } -}; +#endif /* FFMPEG_SVQ1_CB_H */ diff --git a/contrib/ffmpeg/libavcodec/svq1_vlc.h b/contrib/ffmpeg/libavcodec/svq1_vlc.h index 56463700f..05fb12aad 100644 --- a/contrib/ffmpeg/libavcodec/svq1_vlc.h +++ b/contrib/ffmpeg/libavcodec/svq1_vlc.h @@ -18,18 +18,20 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef SVQ1_VLC_H -#define SVQ1_VLC_H +#ifndef FFMPEG_SVQ1_VLC_H +#define FFMPEG_SVQ1_VLC_H + +#include /* values in this table range from 0..3; adjust retrieved value by +0 */ -static const uint8_t svq1_block_type_vlc[4][2] = { +const uint8_t ff_svq1_block_type_vlc[4][2] = { /* { code, length } */ { 0x1, 1 }, { 0x1, 2 }, { 0x1, 3 }, { 0x0, 3 } }; /* values in this table range from -1..6; adjust retrieved value by -1 */ -static const uint8_t svq1_intra_multistage_vlc[6][8][2] = { +const uint8_t ff_svq1_intra_multistage_vlc[6][8][2] = { /* { code, length } */ { { 0x1, 5 }, { 0x1, 1 }, { 0x3, 3 }, { 0x2, 3 }, @@ -53,7 +55,7 @@ static const uint8_t svq1_intra_multistage_vlc[6][8][2] = { }; /* values in this table range from -1..6; adjust retrieved value by -1 */ -static const uint8_t svq1_inter_multistage_vlc[6][8][2] = { +const uint8_t ff_svq1_inter_multistage_vlc[6][8][2] = { /* { code, length } */ { { 0x3, 2 }, { 0x5, 3 }, { 0x4, 3 }, { 0x3, 3 }, @@ -77,7 +79,7 @@ static const uint8_t svq1_inter_multistage_vlc[6][8][2] = { }; /* values in this table range from 0..255; adjust retrieved value by +0 */ -static const uint16_t svq1_intra_mean_vlc[256][2] = { +const uint16_t ff_svq1_intra_mean_vlc[256][2] = { /* { code, length } */ { 0x37, 6 }, { 0x56, 7 }, { 0x1, 17 }, { 0x1, 20 }, { 0x2, 20 }, { 0x3, 20 }, { 0x0, 20 }, { 0x4, 20 }, @@ -146,7 +148,7 @@ static const uint16_t svq1_intra_mean_vlc[256][2] = { }; /* values in this table range from -256..255; adjust retrieved value by -256 */ -static const uint16_t svq1_inter_mean_vlc[512][2] = { +const uint16_t ff_svq1_inter_mean_vlc[512][2] = { /* { code, length } */ { 0x5A, 22 }, { 0xD4, 22 }, { 0xD5, 22 }, { 0xD6, 22 }, { 0xD7, 22 }, { 0xD8, 22 }, { 0xD9, 22 }, { 0xDA, 22 }, @@ -278,4 +280,4 @@ static const uint16_t svq1_inter_mean_vlc[512][2] = { { 0x3, 22 }, { 0x2, 22 }, { 0x1, 22 }, { 0x0, 22 } }; -#endif +#endif /* FFMPEG_SVQ1_VLC_H */ diff --git a/contrib/ffmpeg/libavcodec/svq1dec.c b/contrib/ffmpeg/libavcodec/svq1dec.c new file mode 100644 index 000000000..099c185db --- /dev/null +++ b/contrib/ffmpeg/libavcodec/svq1dec.c @@ -0,0 +1,829 @@ +/* + * SVQ1 decoder + * ported to MPlayer by Arpi + * ported to libavcodec by Nick Kurshev + * + * Copyright (C) 2002 the xine project + * Copyright (C) 2002 the ffmpeg project + * + * SVQ1 Encoder (c) 2004 Mike Melanson + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file svq1.c + * Sorenson Vector Quantizer #1 (SVQ1) video codec. + * For more information of the SVQ1 algorithm, visit: + * http://www.pcisys.net/~melanson/codecs/ + */ + + +//#define DEBUG_SVQ1 +#include "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" + +#include "svq1.h" + +#undef NDEBUG +#include + +extern const uint8_t mvtab[33][2]; + +static VLC svq1_block_type; +static VLC svq1_motion_component; +static VLC svq1_intra_multistage[6]; +static VLC svq1_inter_multistage[6]; +static VLC svq1_intra_mean; +static VLC svq1_inter_mean; + +/* motion vector (prediction) */ +typedef struct svq1_pmv_s { + int x; + int y; +} svq1_pmv_t; + +static const uint16_t checksum_table[256] = { + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, + 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, + 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, + 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, + 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, + 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, + 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, + 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, + 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, + 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, + 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, + 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, + 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, + 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, + 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, + 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, + 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, + 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, + 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, + 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, + 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, + 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, + 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 +}; + +static const uint8_t string_table[256] = { + 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54, + 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D, + 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06, + 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F, + 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0, + 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9, + 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2, + 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B, + 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9, + 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0, + 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B, + 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2, + 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D, + 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44, + 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F, + 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16, + 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB, + 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92, + 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9, + 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0, + 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F, + 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36, + 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D, + 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64, + 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26, + 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F, + 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74, + 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D, + 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82, + 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB, + 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0, + 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9 +}; + +#define SVQ1_PROCESS_VECTOR()\ + for (; level > 0; i++) {\ + /* process next depth */\ + if (i == m) {\ + m = n;\ + if (--level == 0)\ + break;\ + }\ + /* divide block if next bit set */\ + if (get_bits1 (bitbuf) == 0)\ + break;\ + /* add child nodes */\ + list[n++] = list[i];\ + list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level / 2) + 1));\ + } + +#define SVQ1_ADD_CODEBOOK()\ + /* add codebook entries to vector */\ + for (j=0; j < stages; j++) {\ + n3 = codebook[entries[j]] ^ 0x80808080;\ + n1 += ((n3 & 0xFF00FF00) >> 8);\ + n2 += (n3 & 0x00FF00FF);\ + }\ +\ + /* clip to [0..255] */\ + if (n1 & 0xFF00FF00) {\ + n3 = ((( n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\ + n1 += 0x7F007F00;\ + n1 |= (((~n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\ + n1 &= (n3 & 0x00FF00FF);\ + }\ +\ + if (n2 & 0xFF00FF00) {\ + n3 = ((( n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\ + n2 += 0x7F007F00;\ + n2 |= (((~n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\ + n2 &= (n3 & 0x00FF00FF);\ + } + +#define SVQ1_DO_CODEBOOK_INTRA()\ + for (y=0; y < height; y++) {\ + for (x=0; x < (width / 4); x++, codebook++) {\ + n1 = n4;\ + n2 = n4;\ + SVQ1_ADD_CODEBOOK()\ + /* store result */\ + dst[x] = (n1 << 8) | n2;\ + }\ + dst += (pitch / 4);\ + } + +#define SVQ1_DO_CODEBOOK_NONINTRA()\ + for (y=0; y < height; y++) {\ + for (x=0; x < (width / 4); x++, codebook++) {\ + n3 = dst[x];\ + /* add mean value to vector */\ + n1 = ((n3 & 0xFF00FF00) >> 8) + n4;\ + n2 = (n3 & 0x00FF00FF) + n4;\ + SVQ1_ADD_CODEBOOK()\ + /* store result */\ + dst[x] = (n1 << 8) | n2;\ + }\ + dst += (pitch / 4);\ + } + +#define SVQ1_CALC_CODEBOOK_ENTRIES(cbook)\ + codebook = (const uint32_t *) cbook[level];\ + bit_cache = get_bits (bitbuf, 4*stages);\ + /* calculate codebook entries for this vector */\ + for (j=0; j < stages; j++) {\ + entries[j] = (((bit_cache >> (4*(stages - j - 1))) & 0xF) + 16*j) << (level + 1);\ + }\ + mean -= (stages * 128);\ + n4 = ((mean + (mean >> 31)) << 16) | (mean & 0xFFFF); + +static int svq1_decode_block_intra (GetBitContext *bitbuf, uint8_t *pixels, int pitch ) { + uint32_t bit_cache; + uint8_t *list[63]; + uint32_t *dst; + const uint32_t *codebook; + int entries[6]; + int i, j, m, n; + int mean, stages; + unsigned x, y, width, height, level; + uint32_t n1, n2, n3, n4; + + /* initialize list for breadth first processing of vectors */ + list[0] = pixels; + + /* recursively process vector */ + for (i=0, m=1, n=1, level=5; i < n; i++) { + SVQ1_PROCESS_VECTOR(); + + /* destination address and vector size */ + dst = (uint32_t *) list[i]; + width = 1 << ((4 + level) /2); + height = 1 << ((3 + level) /2); + + /* get number of stages (-1 skips vector, 0 for mean only) */ + stages = get_vlc2(bitbuf, svq1_intra_multistage[level].table, 3, 3) - 1; + + if (stages == -1) { + for (y=0; y < height; y++) { + memset (&dst[y*(pitch / 4)], 0, width); + } + continue; /* skip vector */ + } + + if ((stages > 0) && (level >= 4)) { +#ifdef DEBUG_SVQ1 + av_log(s->avctx, AV_LOG_INFO, "Error (svq1_decode_block_intra): invalid vector: stages=%i level=%i\n",stages,level); +#endif + return -1; /* invalid vector */ + } + + mean = get_vlc2(bitbuf, svq1_intra_mean.table, 8, 3); + + if (stages == 0) { + for (y=0; y < height; y++) { + memset (&dst[y*(pitch / 4)], mean, width); + } + } else { + SVQ1_CALC_CODEBOOK_ENTRIES(ff_svq1_intra_codebooks); + SVQ1_DO_CODEBOOK_INTRA() + } + } + + return 0; +} + +static int svq1_decode_block_non_intra (GetBitContext *bitbuf, uint8_t *pixels, int pitch ) { + uint32_t bit_cache; + uint8_t *list[63]; + uint32_t *dst; + const uint32_t *codebook; + int entries[6]; + int i, j, m, n; + int mean, stages; + int x, y, width, height, level; + uint32_t n1, n2, n3, n4; + + /* initialize list for breadth first processing of vectors */ + list[0] = pixels; + + /* recursively process vector */ + for (i=0, m=1, n=1, level=5; i < n; i++) { + SVQ1_PROCESS_VECTOR(); + + /* destination address and vector size */ + dst = (uint32_t *) list[i]; + width = 1 << ((4 + level) /2); + height = 1 << ((3 + level) /2); + + /* get number of stages (-1 skips vector, 0 for mean only) */ + stages = get_vlc2(bitbuf, svq1_inter_multistage[level].table, 3, 2) - 1; + + if (stages == -1) continue; /* skip vector */ + + if ((stages > 0) && (level >= 4)) { +#ifdef DEBUG_SVQ1 + av_log(s->avctx, AV_LOG_INFO, "Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i\n",stages,level); +#endif + return -1; /* invalid vector */ + } + + mean = get_vlc2(bitbuf, svq1_inter_mean.table, 9, 3) - 256; + + SVQ1_CALC_CODEBOOK_ENTRIES(ff_svq1_inter_codebooks); + SVQ1_DO_CODEBOOK_NONINTRA() + } + return 0; +} + +static int svq1_decode_motion_vector (GetBitContext *bitbuf, svq1_pmv_t *mv, svq1_pmv_t **pmv) { + int diff; + int i; + + for (i=0; i < 2; i++) { + + /* get motion code */ + diff = get_vlc2(bitbuf, svq1_motion_component.table, 7, 2); + if(diff<0) + return -1; + else if(diff){ + if(get_bits1(bitbuf)) diff= -diff; + } + + /* add median of motion vector predictors and clip result */ + if (i == 1) + mv->y = ((diff + mid_pred(pmv[0]->y, pmv[1]->y, pmv[2]->y)) << 26) >> 26; + else + mv->x = ((diff + mid_pred(pmv[0]->x, pmv[1]->x, pmv[2]->x)) << 26) >> 26; + } + + return 0; +} + +static void svq1_skip_block (uint8_t *current, uint8_t *previous, int pitch, int x, int y) { + uint8_t *src; + uint8_t *dst; + int i; + + src = &previous[x + y*pitch]; + dst = current; + + for (i=0; i < 16; i++) { + memcpy (dst, src, 16); + src += pitch; + dst += pitch; + } +} + +static int svq1_motion_inter_block (MpegEncContext *s, GetBitContext *bitbuf, + uint8_t *current, uint8_t *previous, int pitch, + svq1_pmv_t *motion, int x, int y) { + uint8_t *src; + uint8_t *dst; + svq1_pmv_t mv; + svq1_pmv_t *pmv[3]; + int result; + + /* predict and decode motion vector */ + pmv[0] = &motion[0]; + if (y == 0) { + pmv[1] = + pmv[2] = pmv[0]; + } + else { + pmv[1] = &motion[(x / 8) + 2]; + pmv[2] = &motion[(x / 8) + 4]; + } + + result = svq1_decode_motion_vector (bitbuf, &mv, pmv); + + if (result != 0) + return result; + + motion[0].x = + motion[(x / 8) + 2].x = + motion[(x / 8) + 3].x = mv.x; + motion[0].y = + motion[(x / 8) + 2].y = + motion[(x / 8) + 3].y = mv.y; + + if(y + (mv.y >> 1)<0) + mv.y= 0; + if(x + (mv.x >> 1)<0) + mv.x= 0; + +#if 0 + int w= (s->width+15)&~15; + int h= (s->height+15)&~15; + if(x + (mv.x >> 1)<0 || y + (mv.y >> 1)<0 || x + (mv.x >> 1) + 16 > w || y + (mv.y >> 1) + 16> h) + av_log(s->avctx, AV_LOG_INFO, "%d %d %d %d\n", x, y, x + (mv.x >> 1), y + (mv.y >> 1)); +#endif + + src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1))*pitch]; + dst = current; + + s->dsp.put_pixels_tab[0][((mv.y & 1) << 1) | (mv.x & 1)](dst,src,pitch,16); + + return 0; +} + +static int svq1_motion_inter_4v_block (MpegEncContext *s, GetBitContext *bitbuf, + uint8_t *current, uint8_t *previous, int pitch, + svq1_pmv_t *motion,int x, int y) { + uint8_t *src; + uint8_t *dst; + svq1_pmv_t mv; + svq1_pmv_t *pmv[4]; + int i, result; + + /* predict and decode motion vector (0) */ + pmv[0] = &motion[0]; + if (y == 0) { + pmv[1] = + pmv[2] = pmv[0]; + } + else { + pmv[1] = &motion[(x / 8) + 2]; + pmv[2] = &motion[(x / 8) + 4]; + } + + result = svq1_decode_motion_vector (bitbuf, &mv, pmv); + + if (result != 0) + return result; + + /* predict and decode motion vector (1) */ + pmv[0] = &mv; + if (y == 0) { + pmv[1] = + pmv[2] = pmv[0]; + } + else { + pmv[1] = &motion[(x / 8) + 3]; + } + result = svq1_decode_motion_vector (bitbuf, &motion[0], pmv); + + if (result != 0) + return result; + + /* predict and decode motion vector (2) */ + pmv[1] = &motion[0]; + pmv[2] = &motion[(x / 8) + 1]; + + result = svq1_decode_motion_vector (bitbuf, &motion[(x / 8) + 2], pmv); + + if (result != 0) + return result; + + /* predict and decode motion vector (3) */ + pmv[2] = &motion[(x / 8) + 2]; + pmv[3] = &motion[(x / 8) + 3]; + + result = svq1_decode_motion_vector (bitbuf, pmv[3], pmv); + + if (result != 0) + return result; + + /* form predictions */ + for (i=0; i < 4; i++) { + int mvx= pmv[i]->x + (i&1)*16; + int mvy= pmv[i]->y + (i>>1)*16; + + ///XXX /FIXME clipping or padding? + if(y + (mvy >> 1)<0) + mvy= 0; + if(x + (mvx >> 1)<0) + mvx= 0; + +#if 0 + int w= (s->width+15)&~15; + int h= (s->height+15)&~15; + if(x + (mvx >> 1)<0 || y + (mvy >> 1)<0 || x + (mvx >> 1) + 8 > w || y + (mvy >> 1) + 8> h) + av_log(s->avctx, AV_LOG_INFO, "%d %d %d %d\n", x, y, x + (mvx >> 1), y + (mvy >> 1)); +#endif + src = &previous[(x + (mvx >> 1)) + (y + (mvy >> 1))*pitch]; + dst = current; + + s->dsp.put_pixels_tab[1][((mvy & 1) << 1) | (mvx & 1)](dst,src,pitch,8); + + /* select next block */ + if (i & 1) { + current += 8*(pitch - 1); + } else { + current += 8; + } + } + + return 0; +} + +static int svq1_decode_delta_block (MpegEncContext *s, GetBitContext *bitbuf, + uint8_t *current, uint8_t *previous, int pitch, + svq1_pmv_t *motion, int x, int y) { + uint32_t block_type; + int result = 0; + + /* get block type */ + block_type = get_vlc2(bitbuf, svq1_block_type.table, 2, 2); + + /* reset motion vectors */ + if (block_type == SVQ1_BLOCK_SKIP || block_type == SVQ1_BLOCK_INTRA) { + motion[0].x = + motion[0].y = + motion[(x / 8) + 2].x = + motion[(x / 8) + 2].y = + motion[(x / 8) + 3].x = + motion[(x / 8) + 3].y = 0; + } + + switch (block_type) { + case SVQ1_BLOCK_SKIP: + svq1_skip_block (current, previous, pitch, x, y); + break; + + case SVQ1_BLOCK_INTER: + result = svq1_motion_inter_block (s, bitbuf, current, previous, pitch, motion, x, y); + + if (result != 0) + { +#ifdef DEBUG_SVQ1 + av_log(s->avctx, AV_LOG_INFO, "Error in svq1_motion_inter_block %i\n",result); +#endif + break; + } + result = svq1_decode_block_non_intra (bitbuf, current, pitch); + break; + + case SVQ1_BLOCK_INTER_4V: + result = svq1_motion_inter_4v_block (s, bitbuf, current, previous, pitch, motion, x, y); + + if (result != 0) + { +#ifdef DEBUG_SVQ1 + av_log(s->avctx, AV_LOG_INFO, "Error in svq1_motion_inter_4v_block %i\n",result); +#endif + break; + } + result = svq1_decode_block_non_intra (bitbuf, current, pitch); + break; + + case SVQ1_BLOCK_INTRA: + result = svq1_decode_block_intra (bitbuf, current, pitch); + break; + } + + return result; +} + +static uint16_t svq1_packet_checksum (const uint8_t *data, const int length, int value) { + int i; + + for (i=0; i < length; i++) { + value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8); + } + + return value; +} + +static void svq1_parse_string (GetBitContext *bitbuf, uint8_t *out) { + uint8_t seed; + int i; + + out[0] = get_bits (bitbuf, 8); + + seed = string_table[out[0]]; + + for (i=1; i <= out[0]; i++) { + out[i] = get_bits (bitbuf, 8) ^ seed; + seed = string_table[out[i] ^ seed]; + } +} + +static int svq1_decode_frame_header (GetBitContext *bitbuf,MpegEncContext *s) { + int frame_size_code; + int temporal_reference; + + temporal_reference = get_bits (bitbuf, 8); + + /* frame type */ + s->pict_type= get_bits (bitbuf, 2)+1; + if(s->pict_type==4) + return -1; + + if (s->pict_type == I_TYPE) { + + /* unknown fields */ + if (s->f_code == 0x50 || s->f_code == 0x60) { + int csum = get_bits (bitbuf, 16); + + csum = svq1_packet_checksum (bitbuf->buffer, bitbuf->size_in_bits>>3, csum); + +// av_log(s->avctx, AV_LOG_INFO, "%s checksum (%02x) for packet data\n", +// (csum == 0) ? "correct" : "incorrect", csum); + } + + if ((s->f_code ^ 0x10) >= 0x50) { + uint8_t msg[256]; + + svq1_parse_string (bitbuf, msg); + + av_log(s->avctx, AV_LOG_INFO, "embedded message: \"%s\"\n", (char *) msg); + } + + skip_bits (bitbuf, 2); + skip_bits (bitbuf, 2); + skip_bits1 (bitbuf); + + /* load frame size */ + frame_size_code = get_bits (bitbuf, 3); + + if (frame_size_code == 7) { + /* load width, height (12 bits each) */ + s->width = get_bits (bitbuf, 12); + s->height = get_bits (bitbuf, 12); + + if (!s->width || !s->height) + return -1; + } else { + /* get width, height from table */ + s->width = ff_svq1_frame_size_table[frame_size_code].width; + s->height = ff_svq1_frame_size_table[frame_size_code].height; + } + } + + /* unknown fields */ + if (get_bits1 (bitbuf) == 1) { + skip_bits1 (bitbuf); /* use packet checksum if (1) */ + skip_bits1 (bitbuf); /* component checksums after image data if (1) */ + + if (get_bits (bitbuf, 2) != 0) + return -1; + } + + if (get_bits1 (bitbuf) == 1) { + skip_bits1 (bitbuf); + skip_bits (bitbuf, 4); + skip_bits1 (bitbuf); + skip_bits (bitbuf, 2); + + while (get_bits1 (bitbuf) == 1) { + skip_bits (bitbuf, 8); + } + } + + return 0; +} + +static int svq1_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + const uint8_t *buf, int buf_size) +{ + MpegEncContext *s=avctx->priv_data; + uint8_t *current, *previous; + int result, i, x, y, width, height; + AVFrame *pict = data; + + /* initialize bit buffer */ + init_get_bits(&s->gb,buf,buf_size*8); + + /* decode frame header */ + s->f_code = get_bits (&s->gb, 22); + + if ((s->f_code & ~0x70) || !(s->f_code & 0x60)) + return -1; + + /* swap some header bytes (why?) */ + if (s->f_code != 0x20) { + uint32_t *src = (uint32_t *) (buf + 4); + + for (i=0; i < 4; i++) { + src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i]; + } + } + + result = svq1_decode_frame_header (&s->gb, s); + + if (result != 0) + { +#ifdef DEBUG_SVQ1 + av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_frame_header %i\n",result); +#endif + return result; + } + + //FIXME this avoids some confusion for "B frames" without 2 references + //this should be removed after libavcodec can handle more flexible picture types & ordering + if(s->pict_type==B_TYPE && s->last_picture_ptr==NULL) return buf_size; + + if(avctx->hurry_up && s->pict_type==B_TYPE) return buf_size; + if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE) + ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE) + || avctx->skip_frame >= AVDISCARD_ALL) + return buf_size; + + if(MPV_frame_start(s, avctx) < 0) + return -1; + + /* decode y, u and v components */ + for (i=0; i < 3; i++) { + int linesize; + if (i == 0) { + width = (s->width+15)&~15; + height = (s->height+15)&~15; + linesize= s->linesize; + } else { + if(s->flags&CODEC_FLAG_GRAY) break; + width = (s->width/4+15)&~15; + height = (s->height/4+15)&~15; + linesize= s->uvlinesize; + } + + current = s->current_picture.data[i]; + + if(s->pict_type==B_TYPE){ + previous = s->next_picture.data[i]; + }else{ + previous = s->last_picture.data[i]; + } + + if (s->pict_type == I_TYPE) { + /* keyframe */ + for (y=0; y < height; y+=16) { + for (x=0; x < width; x+=16) { + result = svq1_decode_block_intra (&s->gb, ¤t[x], linesize); + if (result != 0) + { +//#ifdef DEBUG_SVQ1 + av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_block %i (keyframe)\n",result); +//#endif + return result; + } + } + current += 16*linesize; + } + } else { + svq1_pmv_t pmv[width/8+3]; + /* delta frame */ + memset (pmv, 0, ((width / 8) + 3) * sizeof(svq1_pmv_t)); + + for (y=0; y < height; y+=16) { + for (x=0; x < width; x+=16) { + result = svq1_decode_delta_block (s, &s->gb, ¤t[x], previous, + linesize, pmv, x, y); + if (result != 0) + { +#ifdef DEBUG_SVQ1 + av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_delta_block %i\n",result); +#endif + return result; + } + } + + pmv[0].x = + pmv[0].y = 0; + + current += 16*linesize; + } + } + } + + *pict = *(AVFrame*)&s->current_picture; + + + MPV_frame_end(s); + + *data_size=sizeof(AVFrame); + return buf_size; +} + +static int svq1_decode_init(AVCodecContext *avctx) +{ + MpegEncContext *s = avctx->priv_data; + int i; + + MPV_decode_defaults(s); + + s->avctx = avctx; + s->width = (avctx->width+3)&~3; + s->height = (avctx->height+3)&~3; + s->codec_id= avctx->codec->id; + avctx->pix_fmt = PIX_FMT_YUV410P; + avctx->has_b_frames= 1; // not true, but DP frames and these behave like unidirectional b frames + s->flags= avctx->flags; + if (MPV_common_init(s) < 0) return -1; + + init_vlc(&svq1_block_type, 2, 4, + &ff_svq1_block_type_vlc[0][1], 2, 1, + &ff_svq1_block_type_vlc[0][0], 2, 1, 1); + + init_vlc(&svq1_motion_component, 7, 33, + &mvtab[0][1], 2, 1, + &mvtab[0][0], 2, 1, 1); + + for (i = 0; i < 6; i++) { + init_vlc(&svq1_intra_multistage[i], 3, 8, + &ff_svq1_intra_multistage_vlc[i][0][1], 2, 1, + &ff_svq1_intra_multistage_vlc[i][0][0], 2, 1, 1); + init_vlc(&svq1_inter_multistage[i], 3, 8, + &ff_svq1_inter_multistage_vlc[i][0][1], 2, 1, + &ff_svq1_inter_multistage_vlc[i][0][0], 2, 1, 1); + } + + init_vlc(&svq1_intra_mean, 8, 256, + &ff_svq1_intra_mean_vlc[0][1], 4, 2, + &ff_svq1_intra_mean_vlc[0][0], 4, 2, 1); + + init_vlc(&svq1_inter_mean, 9, 512, + &ff_svq1_inter_mean_vlc[0][1], 4, 2, + &ff_svq1_inter_mean_vlc[0][0], 4, 2, 1); + + return 0; +} + +static int svq1_decode_end(AVCodecContext *avctx) +{ + MpegEncContext *s = avctx->priv_data; + + MPV_common_end(s); + return 0; +} + + +AVCodec svq1_decoder = { + "svq1", + CODEC_TYPE_VIDEO, + CODEC_ID_SVQ1, + sizeof(MpegEncContext), + svq1_decode_init, + NULL, + svq1_decode_end, + svq1_decode_frame, + CODEC_CAP_DR1, + .flush= ff_mpeg_flush, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV410P, -1}, +}; diff --git a/contrib/ffmpeg/libavcodec/svq1enc.c b/contrib/ffmpeg/libavcodec/svq1enc.c new file mode 100644 index 000000000..5345ed6dc --- /dev/null +++ b/contrib/ffmpeg/libavcodec/svq1enc.c @@ -0,0 +1,588 @@ +/* + * SVQ1 Encoder + * Copyright (C) 2004 Mike Melanson + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file svq1enc.c + * Sorenson Vector Quantizer #1 (SVQ1) video codec. + * For more information of the SVQ1 algorithm, visit: + * http://www.pcisys.net/~melanson/codecs/ + */ + + +#include "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" + +#include "svq1.h" +#include "svq1enc_cb.h" + +#undef NDEBUG +#include + + +typedef struct SVQ1Context { + MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independent of MpegEncContext, so this will be removed then (FIXME/XXX) + AVCodecContext *avctx; + DSPContext dsp; + AVFrame picture; + AVFrame current_picture; + AVFrame last_picture; + PutBitContext pb; + GetBitContext gb; + + PutBitContext reorder_pb[6]; //why ooh why this sick breadth first order, everything is slower and more complex + + int frame_width; + int frame_height; + + /* Y plane block dimensions */ + int y_block_width; + int y_block_height; + + /* U & V plane (C planes) block dimensions */ + int c_block_width; + int c_block_height; + + uint16_t *mb_type; + uint32_t *dummy; + int16_t (*motion_val8[3])[2]; + int16_t (*motion_val16[3])[2]; + + int64_t rd_total; +} SVQ1Context; + +static void svq1_write_header(SVQ1Context *s, int frame_type) +{ + int i; + + /* frame code */ + put_bits(&s->pb, 22, 0x20); + + /* temporal reference (sure hope this is a "don't care") */ + put_bits(&s->pb, 8, 0x00); + + /* frame type */ + put_bits(&s->pb, 2, frame_type - 1); + + if (frame_type == I_TYPE) { + + /* no checksum since frame code is 0x20 */ + + /* no embedded string either */ + + /* output 5 unknown bits (2 + 2 + 1) */ + put_bits(&s->pb, 5, 2); /* 2 needed by quicktime decoder */ + + for (i = 0; i < 7; i++) + { + if ((ff_svq1_frame_size_table[i].width == s->frame_width) && + (ff_svq1_frame_size_table[i].height == s->frame_height)) + { + put_bits(&s->pb, 3, i); + break; + } + } + + if (i == 7) + { + put_bits(&s->pb, 3, 7); + put_bits(&s->pb, 12, s->frame_width); + put_bits(&s->pb, 12, s->frame_height); + } + } + + /* no checksum or extra data (next 2 bits get 0) */ + put_bits(&s->pb, 2, 0); +} + + +#define QUALITY_THRESHOLD 100 +#define THRESHOLD_MULTIPLIER 0.6 + +#if defined(HAVE_ALTIVEC) +#undef vector +#endif + +static int encode_block(SVQ1Context *s, uint8_t *src, uint8_t *ref, uint8_t *decoded, int stride, int level, int threshold, int lambda, int intra){ + int count, y, x, i, j, split, best_mean, best_score, best_count; + int best_vector[6]; + int block_sum[7]= {0, 0, 0, 0, 0, 0}; + int w= 2<<((level+2)>>1); + int h= 2<<((level+1)>>1); + int size=w*h; + int16_t block[7][256]; + const int8_t *codebook_sum, *codebook; + const uint16_t (*mean_vlc)[2]; + const uint8_t (*multistage_vlc)[2]; + + best_score=0; + //FIXME optimize, this doenst need to be done multiple times + if(intra){ + codebook_sum= svq1_intra_codebook_sum[level]; + codebook= ff_svq1_intra_codebooks[level]; + mean_vlc= ff_svq1_intra_mean_vlc; + multistage_vlc= ff_svq1_intra_multistage_vlc[level]; + for(y=0; y>(level+3)); + best_mean= (block_sum[0] + (size>>1)) >> (level+3); + + if(level<4){ + for(count=1; count<7; count++){ + int best_vector_score= INT_MAX; + int best_vector_sum=-999, best_vector_mean=-999; + const int stage= count-1; + const int8_t *vector; + + for(i=0; i<16; i++){ + int sum= codebook_sum[stage*16 + i]; + int sqr, diff, score; + + vector = codebook + stage*size*16 + i*size; + sqr = s->dsp.ssd_int8_vs_int16(vector, block[stage], size); + diff= block_sum[stage] - sum; + score= sqr - ((diff*(int64_t)diff)>>(level+3)); //FIXME 64bit slooow + if(score < best_vector_score){ + int mean= (diff + (size>>1)) >> (level+3); + assert(mean >-300 && mean<300); + mean= av_clip(mean, intra?0:-256, 255); + best_vector_score= score; + best_vector[stage]= i; + best_vector_sum= sum; + best_vector_mean= mean; + } + } + assert(best_vector_mean != -999); + vector= codebook + stage*size*16 + best_vector[stage]*size; + for(j=0; j threshold && level){ + int score=0; + int offset= (level&1) ? stride*h/2 : w/2; + PutBitContext backup[6]; + + for(i=level-1; i>=0; i--){ + backup[i]= s->reorder_pb[i]; + } + score += encode_block(s, src , ref , decoded , stride, level-1, threshold>>1, lambda, intra); + score += encode_block(s, src + offset, ref + offset, decoded + offset, stride, level-1, threshold>>1, lambda, intra); + score += lambda; + + if(score < best_score){ + best_score= score; + split=1; + }else{ + for(i=level-1; i>=0; i--){ + s->reorder_pb[i]= backup[i]; + } + } + } + if (level > 0) + put_bits(&s->reorder_pb[level], 1, split); + + if(!split){ + assert((best_mean >= 0 && best_mean<256) || !intra); + assert(best_mean >= -256 && best_mean<256); + assert(best_count >=0 && best_count<7); + assert(level<4 || best_count==0); + + /* output the encoding */ + put_bits(&s->reorder_pb[level], + multistage_vlc[1 + best_count][1], + multistage_vlc[1 + best_count][0]); + put_bits(&s->reorder_pb[level], mean_vlc[best_mean][1], + mean_vlc[best_mean][0]); + + for (i = 0; i < best_count; i++){ + assert(best_vector[i]>=0 && best_vector[i]<16); + put_bits(&s->reorder_pb[level], 4, best_vector[i]); + } + + for(y=0; ypicture.quality*s->picture.quality) >> (2*FF_LAMBDA_SHIFT); + + /* figure out the acceptable level thresholds in advance */ + threshold[5] = QUALITY_THRESHOLD; + for (level = 4; level >= 0; level--) + threshold[level] = threshold[level + 1] * THRESHOLD_MULTIPLIER; + + block_width = (width + 15) / 16; + block_height = (height + 15) / 16; + + if(s->picture.pict_type == P_TYPE){ + s->m.avctx= s->avctx; + s->m.current_picture_ptr= &s->m.current_picture; + s->m.last_picture_ptr = &s->m.last_picture; + s->m.last_picture.data[0]= ref_plane; + s->m.linesize= + s->m.last_picture.linesize[0]= + s->m.new_picture.linesize[0]= + s->m.current_picture.linesize[0]= stride; + s->m.width= width; + s->m.height= height; + s->m.mb_width= block_width; + s->m.mb_height= block_height; + s->m.mb_stride= s->m.mb_width+1; + s->m.b8_stride= 2*s->m.mb_width+1; + s->m.f_code=1; + s->m.pict_type= s->picture.pict_type; + s->m.me_method= s->avctx->me_method; + s->m.me.scene_change_score=0; + s->m.flags= s->avctx->flags; +// s->m.out_format = FMT_H263; +// s->m.unrestricted_mv= 1; + + s->m.lambda= s->picture.quality; + s->m.qscale= (s->m.lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); + s->m.lambda2= (s->m.lambda*s->m.lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT; + + if(!s->motion_val8[plane]){ + s->motion_val8 [plane]= av_mallocz((s->m.b8_stride*block_height*2 + 2)*2*sizeof(int16_t)); + s->motion_val16[plane]= av_mallocz((s->m.mb_stride*(block_height + 2) + 1)*2*sizeof(int16_t)); + } + + s->m.mb_type= s->mb_type; + + //dummies, to avoid segfaults + s->m.current_picture.mb_mean= (uint8_t *)s->dummy; + s->m.current_picture.mb_var= (uint16_t*)s->dummy; + s->m.current_picture.mc_mb_var= (uint16_t*)s->dummy; + s->m.current_picture.mb_type= s->dummy; + + s->m.current_picture.motion_val[0]= s->motion_val8[plane] + 2; + s->m.p_mv_table= s->motion_val16[plane] + s->m.mb_stride + 1; + s->m.dsp= s->dsp; //move + ff_init_me(&s->m); + + s->m.me.dia_size= s->avctx->dia_size; + s->m.first_slice_line=1; + for (y = 0; y < block_height; y++) { + uint8_t src[stride*16]; + + s->m.new_picture.data[0]= src - y*16*stride; //ugly + s->m.mb_y= y; + + for(i=0; i<16 && i + 16*ym.mb_x= x; + ff_init_block_index(&s->m); + ff_update_block_index(&s->m); + + ff_estimate_p_frame_motion(&s->m, x, y); + } + s->m.first_slice_line=0; + } + + ff_fix_long_p_mvs(&s->m); + ff_fix_long_mvs(&s->m, NULL, 0, s->m.p_mv_table, s->m.f_code, CANDIDATE_MB_TYPE_INTER, 0); + } + + s->m.first_slice_line=1; + for (y = 0; y < block_height; y++) { + uint8_t src[stride*16]; + + for(i=0; i<16 && i + 16*ym.mb_y= y; + for (x = 0; x < block_width; x++) { + uint8_t reorder_buffer[3][6][7*32]; + int count[3][6]; + int offset = y * 16 * stride + x * 16; + uint8_t *decoded= decoded_plane + offset; + uint8_t *ref= ref_plane + offset; + int score[4]={0,0,0,0}, best; + uint8_t temp[16*stride]; + + if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 3000){ //FIXME check size + av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); + return -1; + } + + s->m.mb_x= x; + ff_init_block_index(&s->m); + ff_update_block_index(&s->m); + + if(s->picture.pict_type == I_TYPE || (s->m.mb_type[x + y*s->m.mb_stride]&CANDIDATE_MB_TYPE_INTRA)){ + for(i=0; i<6; i++){ + init_put_bits(&s->reorder_pb[i], reorder_buffer[0][i], 7*32); + } + if(s->picture.pict_type == P_TYPE){ + const uint8_t *vlc= ff_svq1_block_type_vlc[SVQ1_BLOCK_INTRA]; + put_bits(&s->reorder_pb[5], vlc[1], vlc[0]); + score[0]= vlc[1]*lambda; + } + score[0]+= encode_block(s, src+16*x, NULL, temp, stride, 5, 64, lambda, 1); + for(i=0; i<6; i++){ + count[0][i]= put_bits_count(&s->reorder_pb[i]); + flush_put_bits(&s->reorder_pb[i]); + } + }else + score[0]= INT_MAX; + + best=0; + + if(s->picture.pict_type == P_TYPE){ + const uint8_t *vlc= ff_svq1_block_type_vlc[SVQ1_BLOCK_INTER]; + int mx, my, pred_x, pred_y, dxy; + int16_t *motion_ptr; + + motion_ptr= h263_pred_motion(&s->m, 0, 0, &pred_x, &pred_y); + if(s->m.mb_type[x + y*s->m.mb_stride]&CANDIDATE_MB_TYPE_INTER){ + for(i=0; i<6; i++) + init_put_bits(&s->reorder_pb[i], reorder_buffer[1][i], 7*32); + + put_bits(&s->reorder_pb[5], vlc[1], vlc[0]); + + s->m.pb= s->reorder_pb[5]; + mx= motion_ptr[0]; + my= motion_ptr[1]; + assert(mx>=-32 && mx<=31); + assert(my>=-32 && my<=31); + assert(pred_x>=-32 && pred_x<=31); + assert(pred_y>=-32 && pred_y<=31); + ff_h263_encode_motion(&s->m, mx - pred_x, 1); + ff_h263_encode_motion(&s->m, my - pred_y, 1); + s->reorder_pb[5]= s->m.pb; + score[1] += lambda*put_bits_count(&s->reorder_pb[5]); + + dxy= (mx&1) + 2*(my&1); + + s->dsp.put_pixels_tab[0][dxy](temp+16, ref + (mx>>1) + stride*(my>>1), stride, 16); + + score[1]+= encode_block(s, src+16*x, temp+16, decoded, stride, 5, 64, lambda, 0); + best= score[1] <= score[0]; + + vlc= ff_svq1_block_type_vlc[SVQ1_BLOCK_SKIP]; + score[2]= s->dsp.sse[0](NULL, src+16*x, ref, stride, 16); + score[2]+= vlc[1]*lambda; + if(score[2] < score[best] && mx==0 && my==0){ + best=2; + s->dsp.put_pixels_tab[0][0](decoded, ref, stride, 16); + for(i=0; i<6; i++){ + count[2][i]=0; + } + put_bits(&s->pb, vlc[1], vlc[0]); + } + } + + if(best==1){ + for(i=0; i<6; i++){ + count[1][i]= put_bits_count(&s->reorder_pb[i]); + flush_put_bits(&s->reorder_pb[i]); + } + }else{ + motion_ptr[0 ] = motion_ptr[1 ]= + motion_ptr[2 ] = motion_ptr[3 ]= + motion_ptr[0+2*s->m.b8_stride] = motion_ptr[1+2*s->m.b8_stride]= + motion_ptr[2+2*s->m.b8_stride] = motion_ptr[3+2*s->m.b8_stride]=0; + } + } + + s->rd_total += score[best]; + + for(i=5; i>=0; i--){ + ff_copy_bits(&s->pb, reorder_buffer[best][i], count[best][i]); + } + if(best==0){ + s->dsp.put_pixels_tab[0][0](decoded, temp, stride, 16); + } + } + s->m.first_slice_line=0; + } + return 0; +} + +static int svq1_encode_init(AVCodecContext *avctx) +{ + SVQ1Context * const s = avctx->priv_data; + + dsputil_init(&s->dsp, avctx); + avctx->coded_frame= (AVFrame*)&s->picture; + + s->frame_width = avctx->width; + s->frame_height = avctx->height; + + s->y_block_width = (s->frame_width + 15) / 16; + s->y_block_height = (s->frame_height + 15) / 16; + + s->c_block_width = (s->frame_width / 4 + 15) / 16; + s->c_block_height = (s->frame_height / 4 + 15) / 16; + + s->avctx= avctx; + s->m.avctx= avctx; + s->m.me.scratchpad= av_mallocz((avctx->width+64)*2*16*2*sizeof(uint8_t)); + s->m.me.map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); + s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); + s->mb_type = av_mallocz((s->y_block_width+1)*s->y_block_height*sizeof(int16_t)); + s->dummy = av_mallocz((s->y_block_width+1)*s->y_block_height*sizeof(int32_t)); + h263_encode_init(&s->m); //mv_penalty + + return 0; +} + +static int svq1_encode_frame(AVCodecContext *avctx, unsigned char *buf, + int buf_size, void *data) +{ + SVQ1Context * const s = avctx->priv_data; + AVFrame *pict = data; + AVFrame * const p= (AVFrame*)&s->picture; + AVFrame temp; + int i; + + if(avctx->pix_fmt != PIX_FMT_YUV410P){ + av_log(avctx, AV_LOG_ERROR, "unsupported pixel format\n"); + return -1; + } + + if(!s->current_picture.data[0]){ + avctx->get_buffer(avctx, &s->current_picture); + avctx->get_buffer(avctx, &s->last_picture); + } + + temp= s->current_picture; + s->current_picture= s->last_picture; + s->last_picture= temp; + + init_put_bits(&s->pb, buf, buf_size); + + *p = *pict; + p->pict_type = avctx->gop_size && avctx->frame_number % avctx->gop_size ? P_TYPE : I_TYPE; + p->key_frame = p->pict_type == I_TYPE; + + svq1_write_header(s, p->pict_type); + for(i=0; i<3; i++){ + if(svq1_encode_plane(s, i, + s->picture.data[i], s->last_picture.data[i], s->current_picture.data[i], + s->frame_width / (i?4:1), s->frame_height / (i?4:1), + s->picture.linesize[i], s->current_picture.linesize[i]) < 0) + return -1; + } + +// align_put_bits(&s->pb); + while(put_bits_count(&s->pb) & 31) + put_bits(&s->pb, 1, 0); + + flush_put_bits(&s->pb); + + return (put_bits_count(&s->pb) / 8); +} + +static int svq1_encode_end(AVCodecContext *avctx) +{ + SVQ1Context * const s = avctx->priv_data; + int i; + + av_log(avctx, AV_LOG_DEBUG, "RD: %f\n", s->rd_total/(double)(avctx->width*avctx->height*avctx->frame_number)); + + av_freep(&s->m.me.scratchpad); + av_freep(&s->m.me.map); + av_freep(&s->m.me.score_map); + av_freep(&s->mb_type); + av_freep(&s->dummy); + + for(i=0; i<3; i++){ + av_freep(&s->motion_val8[i]); + av_freep(&s->motion_val16[i]); + } + + return 0; +} + + +AVCodec svq1_encoder = { + "svq1", + CODEC_TYPE_VIDEO, + CODEC_ID_SVQ1, + sizeof(SVQ1Context), + svq1_encode_init, + svq1_encode_frame, + svq1_encode_end, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV410P, -1}, +}; diff --git a/contrib/ffmpeg/libavcodec/svq1enc_cb.h b/contrib/ffmpeg/libavcodec/svq1enc_cb.h new file mode 100644 index 000000000..1feeed0ab --- /dev/null +++ b/contrib/ffmpeg/libavcodec/svq1enc_cb.h @@ -0,0 +1,96 @@ +/* + * SVQ1 Encoder + * Copyright (C) 2004 Mike Melanson + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file svq1enc_cb.h + * svq1 code books. + */ + +#ifndef FFMPEG_SVQ1ENC_CB_H +#define FFMPEG_SVQ1ENC_CB_H + +#include + +static const int8_t svq1_inter_codebook_sum[4][16*6] = { + { + -1, 1, -2, 0, 1, -1, -1, -1, -2, -1, 1, -1, -1, 0, -1, -1, + 0, -1, -1, -1, -1, 0, -1, 0, 0, 0, -3, 1, -1, 0, 1, -1, + 1, -1, 2, 2, 1, 1, 2, 0, 0, 0, -1, 1, 1, 0, 0, 0, + 1, -1, 0, 1, -1, 1, 1, 0, 1, 0, -1, 1, 1, 0, 0, 0, + -2, 0, 0, -2, 0, 0, -2, 0, -2, -1, -2, -1, 0, 0, -1, 0, + 1, 0, 1, -1, 2, 2, 1, 2, 2, 1, 0, 1, 1, 0, 1, 1, + },{ + -2, 1, -1, -1, 1, 0, 1, -1, -1, -1, 1, -1, 0, -1, 0, -1, + 0, 0, 0, -2, 0, 1, 0, -1, -1, 0, 2, -3, 1, -2, 3, -1, + 2, 0, 2, 1, 1, -1, 1, 1, 0, 0, 1, 1, 2, -2, 1, 0, + -2, -1, 2, -2, -2, 0, -3, 0, -1, 0, -1, 0, -1, 0, -2, -3, + 1, -2, -2, -1, 1, -1, -1, 1, -1, 1, 1, 0, -2, 0, 1, 1, + 1, 1, 2, 1, 0, 0, -1, 0, 0, 1, 0, 1, -1, 1, 0, 2, + },{ + 0, 0, 0, -3, 1, 1, 1, -3, 0, -1, 0, -3, 1, -3, 0, -2, + 1, 2, -1, -3, 0, -3, 1, -1, 0, -1, 0, 0, 1, 2, 1, 1, + -1, 2, -3, 3, 1, 0, -5, 1, 0, -1, -3, 1, 0, 2, 0, -3, + 4, 2, 0, -2, 1, -2, 3, -2, 1, 1, 0, -1, 2, 5, 3, 1, + -1, 0, 2, -3, -2, 0, 0, -2, 2, -3, -1, -1, 2, 1, 0, -2, + 3, -1, 1, -1, 2, 4, 0, 1, 0, 1, 0, -1, -3, -2, -1, 0, + },{ + 0, 2, -1, -1, 2, -4, -2, 3, 0, -1, -5, 1, 0, 1, 0, 6, + -2, 2, 0, 1, 1, -1, -1, -2, 1, -2, -1, 0, 2, -2, -2, -1, + -4, 2, -1, -3, -1, -2, 2, -1, 2, -1, 2, 0, 3, -3, -3, 0, + -3, 0, 0, -2, 4, -4, 0, -1, 4, 0, -2, -2, 3, -2, 0, 4, + 5, 0, 1, 0, -3, 3, 3, 2, 0, 0, 1, 2, -5, -2, -3, 0, + -3, 2, -2, 2, -2, 4, 7, -3, 4, 2, 3, 2, -1, 0, -3, 1, + } +}; + +static const int8_t svq1_intra_codebook_sum[4][16*6] = { + { + 0, 0, 0, -1, -1, -1, -1, -2, 0, -1, -1, 0, -1, 0, 1, 0, + 1, 0, -1, 1, 0, 0, -1, 1, -1, 0, 0, 0, -1, 1, 0, 0, + -1, 0, 0, 1, -1, 1, 0, -1, -1, 0, 1, 1, 0, 0, -1, 1, + 0, 1, 0, 0, 1, -1, 0, 0, 0, -1, 1, 0, 1, 0, -2, 1, + 0, -1, 1, 0, 0, 0, 1, 0, -1, 0, 0, 0, -1, 0, 0, 0, + 0, 1, 1, 0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 1, 1, -1, + },{ + -1, -2, 0, -1, 1, 0, -1, 0, -1, -4, -1, -2, -1, -2, 1, -2, + 0, 0, 4, -2, -1, 1, 1, 0, 2, 1, 1, 0, 2, 0, 0, 0, + 1, 1, 0, -1, -1, -1, 1, 0, -1, -3, -3, 1, -1, 1, -2, -1, + 1, -1, 0, 1, 2, 1, -1, -1, 1, 1, 1, 2, 1, 0, 1, -2, + -2, 0, -1, -2, -2, 0, -1, -1, -1, 0, 1, 0, -1, -1, 0, -1, + 0, 2, 1, 2, 2, 1, -1, 1, 0, 2, 0, -1, 1, 0, 0, 0, + },{ + -2, 0, -1, -1, 1, 1, -2, 0, -2, 0, 1, -2, -2, 1, -1, -1, + 3, -2, 0, -3, -4, -3, 2, 1, 0, 3, -2, 2, 3, 2, 2, -1, + -3, 1, 0, 1, 0, 0, 0, 1, -2, 1, -2, -2, -1, -2, -2, 2, + 0, -4, 0, 2, -1, 0, 2, 2, 2, 1, 0, -1, -1, 1, -3, 2, + 2, 1, 0, 3, 1, -1, 1, 3, 1, 0, 1, 1, 2, -1, 1, -1, + -2, -1, 0, -1, 1, -1, 1, -2, -2, -1, -1, -3, 1, -4, -3, 1, + },{ + -2, 0, -2, 3, -1, -1, 0, 2, 2, -1, -3, 2, 1, 0, -2, -1, + -3, -2, -2, 1, 2, -3, 0, 1, -5, -2, -3, 0, -2, -1, 2, 0, + -1, -1, 0, -2, 1, 3, -7, -2, -2, -1, 2, -1, 0, 3, 1, 3, + 1, 0, 0, 1, 2, 3, 1, 2, 0, -2, -2, 1, 1, 2, 2, 3, + 4, 1, -1, 2, -2, 4, 0, 0, 0, 4, 2, 0, -2, -2, 2, -4, + -1, 5, -2, -2, -3, 2, -3, -1, 3, -3, 0, 4, 3, 0, 1, -2, + } +}; + +#endif /* FFMPEG_SVQ1ENC_CB_H */ diff --git a/contrib/ffmpeg/libavcodec/svq3.c b/contrib/ffmpeg/libavcodec/svq3.c index db601010b..98260adf4 100644 --- a/contrib/ffmpeg/libavcodec/svq3.c +++ b/contrib/ffmpeg/libavcodec/svq3.c @@ -16,8 +16,9 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * + */ + +/* * How to use this decoder: * SVQ3 data is transported within Apple Quicktime files. Quicktime files * have stsd atoms to describe media trak properties. A stsd atom for a @@ -37,7 +38,6 @@ * You will know you have these parameters passed correctly when the decoder * correctly decodes this file: * ftp://ftp.mplayerhq.hu/MPlayer/samples/V-codecs/SVQ3/Vertical400kbit.sorenson3.mov - * */ /** @@ -180,34 +180,6 @@ static void svq3_add_idct_c (uint8_t *dst, DCTELEM *block, int stride, int qp, i } } -static void pred4x4_down_left_svq3_c(uint8_t *src, uint8_t *topright, int stride){ - LOAD_TOP_EDGE - LOAD_LEFT_EDGE - const __attribute__((unused)) int unu0= t0; - const __attribute__((unused)) int unu1= l0; - - src[0+0*stride]=(l1 + t1)>>1; - src[1+0*stride]= - src[0+1*stride]=(l2 + t2)>>1; - src[2+0*stride]= - src[1+1*stride]= - src[0+2*stride]= - src[3+0*stride]= - src[2+1*stride]= - src[1+2*stride]= - src[0+3*stride]= - src[3+1*stride]= - src[2+2*stride]= - src[1+3*stride]= - src[3+2*stride]= - src[2+3*stride]= - src[3+3*stride]=(l3 + t3)>>1; -} - -static void pred16x16_plane_svq3_c(uint8_t *src, int stride){ - pred16x16_plane_compat_c(src, stride, 1); -} - static inline int svq3_decode_block (GetBitContext *gb, DCTELEM *block, int index, const int type) { @@ -465,9 +437,9 @@ static int svq3_decode_mb (H264Context *h, unsigned int mb_type) { mb_type = MB_TYPE_16x16; } } else if (mb_type < 8) { /* INTER */ - if (h->thirdpel_flag && h->halfpel_flag == !get_bits (&s->gb, 1)) { + if (h->thirdpel_flag && h->halfpel_flag == !get_bits1 (&s->gb)) { mode = THIRDPEL_MODE; - } else if (h->halfpel_flag && h->thirdpel_flag == !get_bits (&s->gb, 1)) { + } else if (h->halfpel_flag && h->thirdpel_flag == !get_bits1 (&s->gb)) { mode = HALFPEL_MODE; } else { mode = FULLPEL_MODE; @@ -480,7 +452,6 @@ static int svq3_decode_mb (H264Context *h, unsigned int mb_type) { N??11111 N??11111 N??11111 - N */ for (m=0; m < 2; m++) { @@ -749,7 +720,7 @@ static int svq3_decode_slice_header (H264Context *h) { i = (s->mb_num < 64) ? 6 : (1 + av_log2 (s->mb_num - 1)); s->mb_skip_run = get_bits (&s->gb, i) - (s->mb_x + (s->mb_y * s->mb_width)); } else { - get_bits1 (&s->gb); + skip_bits1 (&s->gb); s->mb_skip_run = 0; } @@ -758,17 +729,17 @@ static int svq3_decode_slice_header (H264Context *h) { s->adaptive_quant = get_bits1 (&s->gb); /* unknown fields */ - get_bits1 (&s->gb); + skip_bits1 (&s->gb); if (h->unknown_svq3_flag) { - get_bits1 (&s->gb); + skip_bits1 (&s->gb); } - get_bits1 (&s->gb); - get_bits (&s->gb, 2); + skip_bits1 (&s->gb); + skip_bits (&s->gb, 2); while (get_bits1 (&s->gb)) { - get_bits (&s->gb, 8); + skip_bits (&s->gb, 8); } /* reset intra predictors and invalidate motion vector references */ @@ -789,7 +760,7 @@ static int svq3_decode_slice_header (H264Context *h) { static int svq3_decode_frame (AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) { + const uint8_t *buf, int buf_size) { MpegEncContext *const s = avctx->priv_data; H264Context *const h = avctx->priv_data; int m, mb_type; @@ -803,12 +774,10 @@ static int svq3_decode_frame (AVCodecContext *avctx, if (!s->context_initialized) { s->width = avctx->width; s->height = avctx->height; - h->pred4x4[DIAG_DOWN_LEFT_PRED] = pred4x4_down_left_svq3_c; - h->pred16x16[PLANE_PRED8x8] = pred16x16_plane_svq3_c; h->halfpel_flag = 1; h->thirdpel_flag = 1; h->unknown_svq3_flag = 0; - h->chroma_qp = 4; + h->chroma_qp[0] = h->chroma_qp[1] = 4; if (MPV_common_init (s) < 0) return -1; @@ -835,26 +804,26 @@ static int svq3_decode_frame (AVCodecContext *avctx, /* 'frame size code' and optional 'width, height' */ if (get_bits (&gb, 3) == 7) { - get_bits (&gb, 12); - get_bits (&gb, 12); + skip_bits (&gb, 12); + skip_bits (&gb, 12); } h->halfpel_flag = get_bits1 (&gb); h->thirdpel_flag = get_bits1 (&gb); /* unknown fields */ - get_bits1 (&gb); - get_bits1 (&gb); - get_bits1 (&gb); - get_bits1 (&gb); + skip_bits1 (&gb); + skip_bits1 (&gb); + skip_bits1 (&gb); + skip_bits1 (&gb); s->low_delay = get_bits1 (&gb); /* unknown field */ - get_bits1 (&gb); + skip_bits1 (&gb); while (get_bits1 (&gb)) { - get_bits (&gb, 8); + skip_bits (&gb, 8); } h->unknown_svq3_flag = get_bits1 (&gb); @@ -892,11 +861,11 @@ static int svq3_decode_frame (AVCodecContext *avctx, s->current_picture.pict_type = s->pict_type; s->current_picture.key_frame = (s->pict_type == I_TYPE); - /* skip b frames if we dont have reference frames */ + /* Skip B-frames if we do not have reference frames. */ if (s->last_picture_ptr == NULL && s->pict_type == B_TYPE) return 0; - /* skip b frames if we are in a hurry */ + /* Skip B-frames if we are in a hurry. */ if (avctx->hurry_up && s->pict_type == B_TYPE) return 0; - /* skip everything if we are in a hurry >= 5 */ + /* Skip everything if we are in a hurry >= 5. */ if (avctx->hurry_up >= 5) return 0; if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==B_TYPE) ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=I_TYPE) @@ -939,7 +908,8 @@ static int svq3_decode_frame (AVCodecContext *avctx, int j; for(j=-1; j<4; j++) h->ref_cache[m][scan8[0] + 8*i + j]= 1; - h->ref_cache[m][scan8[0] + 8*i + j]= PART_NOT_AVAILABLE; + if(i<3) + h->ref_cache[m][scan8[0] + 8*i + j]= PART_NOT_AVAILABLE; } } @@ -993,7 +963,7 @@ static int svq3_decode_frame (AVCodecContext *avctx, avctx->frame_number = s->picture_number - 1; - /* dont output the last pic after seeking */ + /* Do not output the last pic after seeking. */ if (s->last_picture_ptr || s->low_delay) { *data_size = sizeof(AVFrame); } diff --git a/contrib/ffmpeg/libavcodec/targa.c b/contrib/ffmpeg/libavcodec/targa.c index d637bedae..930915777 100644 --- a/contrib/ffmpeg/libavcodec/targa.c +++ b/contrib/ffmpeg/libavcodec/targa.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ #include "avcodec.h" @@ -38,7 +37,7 @@ typedef struct TargaContext { int compression_type; } TargaContext; -static void targa_decode_rle(AVCodecContext *avctx, TargaContext *s, uint8_t *src, uint8_t *dst, int w, int h, int stride, int bpp) +static void targa_decode_rle(AVCodecContext *avctx, TargaContext *s, const uint8_t *src, uint8_t *dst, int w, int h, int stride, int bpp) { int i, x, y; int depth = (bpp + 1) >> 3; @@ -90,7 +89,7 @@ static void targa_decode_rle(AVCodecContext *avctx, TargaContext *s, uint8_t *sr static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { TargaContext * const s = avctx->priv_data; AVFrame *picture = data; diff --git a/contrib/ffmpeg/libavcodec/targaenc.c b/contrib/ffmpeg/libavcodec/targaenc.c index 8b36e1d3d..47e33b19e 100644 --- a/contrib/ffmpeg/libavcodec/targaenc.c +++ b/contrib/ffmpeg/libavcodec/targaenc.c @@ -17,42 +17,9 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ #include "avcodec.h" - -/** - * Count up to 127 consecutive pixels which are either all the same or - * all differ from the previous and next pixels. - * @param start Pointer to the first pixel - * @param len Maximum number of pixels - * @param bpp Bytes per pixel - * @param same 1 if searching for identical pixel values. 0 for differing - * @return Number of matching consecutive pixels found - */ -static int count_pixels(uint8_t *start, int len, int bpp, int same) -{ - uint8_t *pos; - int count = 1; - - for(pos = start + bpp; count < FFMIN(128, len); pos += bpp, count ++) { - if(same != !memcmp(pos-bpp, pos, bpp)) { - if(!same) { - /* if bpp == 1, then 0 1 1 0 is more efficiently encoded as a single - * raw block of pixels. for larger bpp, RLE is as good or better */ - if(bpp == 1 && count + 1 < FFMIN(128, len) && *pos != *(pos+1)) - continue; - - /* if RLE can encode the next block better than as a raw block, - * back up and leave _all_ the identical pixels for RLE */ - count --; - } - break; - } - } - - return count; -} +#include "rle.h" /** * RLE compress the image, with maximum size of out_size @@ -67,35 +34,18 @@ static int count_pixels(uint8_t *start, int len, int bpp, int same) static int targa_encode_rle(uint8_t *outbuf, int out_size, AVFrame *pic, int bpp, int w, int h) { - int count, x, y; - uint8_t *ptr, *line, *out; + int y,ret; + uint8_t *out; out = outbuf; - line = pic->data[0]; for(y = 0; y < h; y ++) { - ptr = line; - - for(x = 0; x < w; x += count) { - /* see if we can encode the next set of pixels with RLE */ - if((count = count_pixels(ptr, w-x, bpp, 1)) > 1) { - if(out + bpp + 1 > outbuf + out_size) return -1; - *out++ = 0x80 | (count - 1); - memcpy(out, ptr, bpp); - out += bpp; - } else { - /* fall back on uncompressed */ - count = count_pixels(ptr, w-x, bpp, 0); - *out++ = count - 1; - - if(out + bpp*count > outbuf + out_size) return -1; - memcpy(out, ptr, bpp * count); - out += bpp * count; - } - ptr += count * bpp; + ret = ff_rle_encode(out, out_size, pic->data[0] + pic->linesize[0] * y, bpp, w, 0x7f, 0, -1, 0); + if(ret == -1){ + return -1; } - - line += pic->linesize[0]; + out+= ret; + out_size -= ret; } return out - outbuf; diff --git a/contrib/ffmpeg/libavcodec/tiertexseqv.c b/contrib/ffmpeg/libavcodec/tiertexseqv.c index ca3baf09e..f106ceb32 100644 --- a/contrib/ffmpeg/libavcodec/tiertexseqv.c +++ b/contrib/ffmpeg/libavcodec/tiertexseqv.c @@ -25,7 +25,6 @@ */ #include "avcodec.h" -#include "common.h" #define ALT_BITSTREAM_READER_LE #include "bitstream.h" @@ -38,7 +37,7 @@ typedef struct SeqVideoContext { } SeqVideoContext; -static unsigned char *seq_unpack_rle_block(unsigned char *src, unsigned char *dst, int dst_size) +static const unsigned char *seq_unpack_rle_block(const unsigned char *src, unsigned char *dst, int dst_size) { int i, len, sz; GetBitContext gb; @@ -68,9 +67,9 @@ static unsigned char *seq_unpack_rle_block(unsigned char *src, unsigned char *ds return src; } -static unsigned char *seq_decode_op1(SeqVideoContext *seq, unsigned char *src, unsigned char *dst) +static const unsigned char *seq_decode_op1(SeqVideoContext *seq, const unsigned char *src, unsigned char *dst) { - unsigned char *color_table; + const unsigned char *color_table; int b, i, len, bits; GetBitContext gb; @@ -108,7 +107,7 @@ static unsigned char *seq_decode_op1(SeqVideoContext *seq, unsigned char *src, u return src; } -static unsigned char *seq_decode_op2(SeqVideoContext *seq, unsigned char *src, unsigned char *dst) +static const unsigned char *seq_decode_op2(SeqVideoContext *seq, const unsigned char *src, unsigned char *dst) { int i; @@ -121,7 +120,7 @@ static unsigned char *seq_decode_op2(SeqVideoContext *seq, unsigned char *src, u return src; } -static unsigned char *seq_decode_op3(SeqVideoContext *seq, unsigned char *src, unsigned char *dst) +static const unsigned char *seq_decode_op3(SeqVideoContext *seq, const unsigned char *src, unsigned char *dst) { int pos, offset; @@ -134,7 +133,7 @@ static unsigned char *seq_decode_op3(SeqVideoContext *seq, unsigned char *src, u return src; } -static void seqvideo_decode(SeqVideoContext *seq, unsigned char *data, int data_size) +static void seqvideo_decode(SeqVideoContext *seq, const unsigned char *data, int data_size) { GetBitContext gb; int flags, i, j, x, y, op; @@ -147,7 +146,7 @@ static void seqvideo_decode(SeqVideoContext *seq, unsigned char *data, int data_ for (i = 0; i < 256; i++) { for (j = 0; j < 3; j++, data++) c[j] = (*data << 2) | (*data >> 4); - seq->palette[i] = (c[0] << 16) | (c[1] << 8) | c[2]; + seq->palette[i] = AV_RB24(c); } memcpy(seq->frame.data[1], seq->palette, sizeof(seq->palette)); seq->frame.palette_has_changed = 1; @@ -176,11 +175,10 @@ static void seqvideo_decode(SeqVideoContext *seq, unsigned char *data, int data_ static int seqvideo_decode_init(AVCodecContext *avctx) { - SeqVideoContext *seq = (SeqVideoContext *)avctx->priv_data; + SeqVideoContext *seq = avctx->priv_data; seq->avctx = avctx; avctx->pix_fmt = PIX_FMT_PAL8; - avctx->has_b_frames = 0; seq->frame.data[0] = NULL; @@ -189,10 +187,10 @@ static int seqvideo_decode_init(AVCodecContext *avctx) static int seqvideo_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { - SeqVideoContext *seq = (SeqVideoContext *)avctx->priv_data; + SeqVideoContext *seq = avctx->priv_data; seq->frame.reference = 1; seq->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; @@ -211,7 +209,7 @@ static int seqvideo_decode_frame(AVCodecContext *avctx, static int seqvideo_decode_end(AVCodecContext *avctx) { - SeqVideoContext *seq = (SeqVideoContext *)avctx->priv_data; + SeqVideoContext *seq = avctx->priv_data; if (seq->frame.data[0]) avctx->release_buffer(avctx, &seq->frame); diff --git a/contrib/ffmpeg/libavcodec/tiff.c b/contrib/ffmpeg/libavcodec/tiff.c index 344b5a311..a172b6253 100644 --- a/contrib/ffmpeg/libavcodec/tiff.c +++ b/contrib/ffmpeg/libavcodec/tiff.c @@ -17,56 +17,20 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + */ + +/** + * TIFF image decoder + * @file tiff.c + * @author Konstantin Shishkov */ #include "avcodec.h" #ifdef CONFIG_ZLIB #include #endif #include "lzw.h" +#include "tiff.h" -/* abridged list of TIFF tags */ -enum TiffTags{ - TIFF_WIDTH = 0x100, - TIFF_HEIGHT, - TIFF_BPP, - TIFF_COMPR, - TIFF_INVERT = 0x106, - TIFF_STRIP_OFFS = 0x111, - TIFF_ROWSPERSTRIP = 0x116, - TIFF_STRIP_SIZE, - TIFF_PLANAR = 0x11C, - TIFF_XPOS = 0x11E, - TIFF_YPOS = 0x11F, - TIFF_PREDICTOR = 0x13D, - TIFF_PAL = 0x140 -}; - -enum TiffCompr{ - TIFF_RAW = 1, - TIFF_CCITT_RLE, - TIFF_G3, - TIFF_G4, - TIFF_LZW, - TIFF_JPEG, - TIFF_NEWJPEG, - TIFF_ADOBE_DEFLATE, - TIFF_PACKBITS = 0x8005, - TIFF_DEFLATE = 0x80B2 -}; - -enum TiffTypes{ - TIFF_BYTE = 1, - TIFF_STRING, - TIFF_SHORT, - TIFF_LONG, - TIFF_LONGLONG -}; - -/** sizes of various TIFF field types */ -static const int type_sizes[6] = { - 0, 1, 100, 2, 4, 8 -}; typedef struct TiffContext { AVCodecContext *avctx; @@ -80,25 +44,25 @@ typedef struct TiffContext { int strips, rps; int sot; - uint8_t* stripdata; - uint8_t* stripsizes; + const uint8_t* stripdata; + const uint8_t* stripsizes; int stripsize, stripoff; LZWState *lzw; } TiffContext; -static int tget_short(uint8_t **p, int le){ +static int tget_short(const uint8_t **p, int le){ int v = le ? AV_RL16(*p) : AV_RB16(*p); *p += 2; return v; } -static int tget_long(uint8_t **p, int le){ +static int tget_long(const uint8_t **p, int le){ int v = le ? AV_RL32(*p) : AV_RB32(*p); *p += 4; return v; } -static int tget(uint8_t **p, int type, int le){ +static int tget(const uint8_t **p, int type, int le){ switch(type){ case TIFF_BYTE : return *(*p)++; case TIFF_SHORT: return tget_short(p, le); @@ -107,9 +71,9 @@ static int tget(uint8_t **p, int type, int le){ } } -static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, uint8_t *src, int size, int lines){ +static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uint8_t *src, int size, int lines){ int c, line, pixels, code; - uint8_t *ssrc = src; + const uint8_t *ssrc = src; int width = s->width * (s->bpp / 8); #ifdef CONFIG_ZLIB uint8_t *zbuf; unsigned long outlen; @@ -186,12 +150,14 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, uint8_t * } -static int tiff_decode_tag(TiffContext *s, uint8_t *start, uint8_t *buf, uint8_t *end_buf, AVFrame *pic) +static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *buf, const uint8_t *end_buf, AVFrame *pic) { int tag, type, count, off, value = 0; - uint8_t *src, *dst; + const uint8_t *src; + uint8_t *dst; int i, j, ssize, soff, stride; - int *pal, *rp, *gp, *bp; + uint32_t *pal; + const uint8_t *rp, *gp, *bp; tag = tget_short(&buf, s->le); type = tget_short(&buf, s->le); @@ -280,7 +246,7 @@ static int tiff_decode_tag(TiffContext *s, uint8_t *start, uint8_t *buf, uint8_t } if(s->bpp == 8){ /* make default grayscale pal */ - pal = s->picture.data[1]; + pal = (uint32_t *) s->picture.data[1]; for(i = 0; i < 256; i++) pal[i] = i * 0x010101; } @@ -381,14 +347,14 @@ static int tiff_decode_tag(TiffContext *s, uint8_t *start, uint8_t *buf, uint8_t return -1; } if(value == 2){ - src = pic->data[0]; + dst = pic->data[0]; stride = pic->linesize[0]; soff = s->bpp >> 3; ssize = s->width * soff; for(i = 0; i < s->height; i++) { for(j = soff; j < ssize; j++) - src[j] += src[j - soff]; - src += stride; + dst[j] += dst[j - soff]; + dst += stride; } } break; @@ -413,7 +379,7 @@ static int tiff_decode_tag(TiffContext *s, uint8_t *start, uint8_t *buf, uint8_t av_log(s->avctx, AV_LOG_ERROR, "Palette met but this is not palettized format\n"); return -1; } - pal = s->picture.data[1]; + pal = (uint32_t *) s->picture.data[1]; off = type_sizes[type]; rp = buf; gp = buf + count / 3 * off; @@ -438,12 +404,12 @@ static int tiff_decode_tag(TiffContext *s, uint8_t *start, uint8_t *buf, uint8_t static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { TiffContext * const s = avctx->priv_data; AVFrame *picture = data; AVFrame * const p= (AVFrame*)&s->picture; - uint8_t *orig_buf = buf, *end_buf = buf + buf_size; + const uint8_t *orig_buf = buf, *end_buf = buf + buf_size; int id, le, off; int i, entries; @@ -457,6 +423,7 @@ static int decode_frame(AVCodecContext *avctx, } s->le = le; s->invert = 0; + s->compr = TIFF_RAW; // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number // that further identifies the file as a TIFF file" if(tget_short(&buf, le) != 42){ diff --git a/contrib/ffmpeg/libavcodec/tiff.h b/contrib/ffmpeg/libavcodec/tiff.h new file mode 100644 index 000000000..c5687d7df --- /dev/null +++ b/contrib/ffmpeg/libavcodec/tiff.h @@ -0,0 +1,86 @@ +/* + * TIFF tables + * Copyright (c) 2006 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * TIFF tables + * @file tiff.h + * @author Konstantin Shishkov + */ +#ifndef FFMPEG_TIFF_H +#define FFMPEG_TIFF_H + +#include + +/** abridged list of TIFF tags */ +enum TiffTags{ + TIFF_SUBFILE = 0xfe, + TIFF_WIDTH = 0x100, + TIFF_HEIGHT, + TIFF_BPP, + TIFF_COMPR, + TIFF_INVERT = 0x106, + TIFF_STRIP_OFFS = 0x111, + TIFF_SAMPLES_PER_PIXEL = 0x115, + TIFF_ROWSPERSTRIP = 0x116, + TIFF_STRIP_SIZE, + TIFF_XRES = 0x11A, + TIFF_YRES = 0x11B, + TIFF_PLANAR = 0x11C, + TIFF_XPOS = 0x11E, + TIFF_YPOS = 0x11F, + TIFF_RES_UNIT = 0x128, + TIFF_SOFTWARE_NAME = 0x131, + TIFF_PREDICTOR = 0x13D, + TIFF_PAL = 0x140, + TIFF_YCBCR_COEFFICIENTS = 0x211, + TIFF_YCBCR_SUBSAMPLING = 0x212, + TIFF_YCBCR_POSITIONING = 0x213, + TIFF_REFERENCE_BW = 0x214, +}; + +/** list of TIFF compression types */ +enum TiffCompr{ + TIFF_RAW = 1, + TIFF_CCITT_RLE, + TIFF_G3, + TIFF_G4, + TIFF_LZW, + TIFF_JPEG, + TIFF_NEWJPEG, + TIFF_ADOBE_DEFLATE, + TIFF_PACKBITS = 0x8005, + TIFF_DEFLATE = 0x80B2 +}; + +enum TiffTypes{ + TIFF_BYTE = 1, + TIFF_STRING, + TIFF_SHORT, + TIFF_LONG, + TIFF_RATIONAL, +}; + +/** sizes of various TIFF field types (string size = 100)*/ +static const uint8_t type_sizes[6] = { + 0, 1, 100, 2, 4, 8 +}; + +#endif /* FFMPEG_TIFF_H */ diff --git a/contrib/ffmpeg/libavcodec/tiffenc.c b/contrib/ffmpeg/libavcodec/tiffenc.c new file mode 100644 index 000000000..69f8e59f6 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/tiffenc.c @@ -0,0 +1,461 @@ +/* + * TIFF image encoder + * Copyright (c) 2007 Bartlomiej Wolowiec + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * TIFF image encoder + * @file tiffenc.c + * @author Bartlomiej Wolowiec + */ +#include "avcodec.h" +#ifdef CONFIG_ZLIB +#include +#endif +#include "bytestream.h" +#include "tiff.h" +#include "rle.h" +#include "lzw.h" + +#define TIFF_MAX_ENTRY 32 + +/** sizes of various TIFF field types (string size = 1)*/ +static const uint8_t type_sizes2[6] = { + 0, 1, 1, 2, 4, 8 +}; + +typedef struct TiffEncoderContext { + AVCodecContext *avctx; + AVFrame picture; + + int width; ///< picture width + int height; ///< picture height + unsigned int bpp; ///< bits per pixel + int compr; ///< compression level + int bpp_tab_size; ///< bpp_tab size + int photometric_interpretation; ///< photometric interpretation + int strips; ///< number of strips + int rps; ///< row per strip + uint8_t entries[TIFF_MAX_ENTRY*12]; ///< entires in header + int num_entries; ///< number of entires + uint8_t **buf; ///< actual position in buffer + uint8_t *buf_start; ///< pointer to first byte in buffer + int buf_size; ///< buffer size + uint16_t subsampling[2]; ///< YUV subsampling factors + struct LZWEncodeState *lzws; ///< LZW Encode state +} TiffEncoderContext; + + +/** + * Check free space in buffer + * @param s Tiff context + * @param need Needed bytes + * @return 0 - ok, 1 - no free space + */ +inline static int check_size(TiffEncoderContext * s, uint64_t need) +{ + if (s->buf_size < *s->buf - s->buf_start + need) { + *s->buf = s->buf_start + s->buf_size + 1; + av_log(s->avctx, AV_LOG_ERROR, "Buffer is too small\n"); + return 1; + } + return 0; +} + +/** + * Put n values to buffer + * + * @param p Pointer to pointer to output buffer + * @param n Number of values + * @param val Pointer to values + * @param type Type of values + * @param flip =0 - normal copy, >0 - flip + */ +static void tnput(uint8_t ** p, int n, const uint8_t * val, enum TiffTypes type, + int flip) +{ + int i; +#ifdef WORDS_BIGENDIAN + flip ^= ((int[]) {0, 0, 0, 1, 3, 3})[type]; +#endif + for (i = 0; i < n * type_sizes2[type]; i++) + *(*p)++ = val[i ^ flip]; +} + +/** + * Add entry to directory in tiff header. + * @param s Tiff context + * @param tag Tag that identifies the entry + * @param type Entry type + * @param count The number of values + * @param ptr_val Pointer to values + */ +static void add_entry(TiffEncoderContext * s, + enum TiffTags tag, enum TiffTypes type, int count, + const void *ptr_val) +{ + uint8_t *entries_ptr = s->entries + 12 * s->num_entries; + + assert(s->num_entries < TIFF_MAX_ENTRY); + + bytestream_put_le16(&entries_ptr, tag); + bytestream_put_le16(&entries_ptr, type); + bytestream_put_le32(&entries_ptr, count); + + if (type_sizes[type] * count <= 4) { + tnput(&entries_ptr, count, ptr_val, type, 0); + } else { + bytestream_put_le32(&entries_ptr, *s->buf - s->buf_start); + check_size(s, count * type_sizes2[type]); + tnput(s->buf, count, ptr_val, type, 0); + } + + s->num_entries++; +} + +static void add_entry1(TiffEncoderContext * s, + enum TiffTags tag, enum TiffTypes type, int val){ + uint16_t w = val; + uint32_t dw= val; + add_entry(s, tag, type, 1, type == TIFF_SHORT ? (void *)&w : (void *)&dw); +} + +/** + * Encode one strip in tiff file + * + * @param s Tiff context + * @param src Input buffer + * @param dst Output buffer + * @param n Size of input buffer + * @param compr Compression method + * @return Number of output bytes. If an output error is encountered, -1 returned + */ +static int encode_strip(TiffEncoderContext * s, const int8_t * src, + uint8_t * dst, int n, int compr) +{ + + switch (compr) { +#ifdef CONFIG_ZLIB + case TIFF_DEFLATE: + case TIFF_ADOBE_DEFLATE: + { + unsigned long zlen = s->buf_size - (*s->buf - s->buf_start); + if (compress(dst, &zlen, src, n) != Z_OK) { + av_log(s->avctx, AV_LOG_ERROR, "Compressing failed\n"); + return -1; + } + return zlen; + } +#endif + case TIFF_RAW: + if (check_size(s, n)) + return -1; + memcpy(dst, src, n); + return n; + case TIFF_PACKBITS: + return ff_rle_encode(dst, s->buf_size - (*s->buf - s->buf_start), src, 1, n, 2, 0xff, -1, 0); + case TIFF_LZW: + return ff_lzw_encode(s->lzws, src, n); + default: + return -1; + } +} + +static void pack_yuv(TiffEncoderContext * s, uint8_t * dst, int lnum) +{ + AVFrame *p = &s->picture; + int i, j, k; + int w = (s->width - 1) / s->subsampling[0] + 1; + uint8_t *pu = &p->data[1][lnum / s->subsampling[1] * p->linesize[1]]; + uint8_t *pv = &p->data[2][lnum / s->subsampling[1] * p->linesize[2]]; + for (i = 0; i < w; i++){ + for (j = 0; j < s->subsampling[1]; j++) + for (k = 0; k < s->subsampling[0]; k++) + *dst++ = p->data[0][(lnum + j) * p->linesize[0] + + i * s->subsampling[0] + k]; + *dst++ = *pu++; + *dst++ = *pv++; + } +} + +static int encode_frame(AVCodecContext * avctx, unsigned char *buf, + int buf_size, void *data) +{ + TiffEncoderContext *s = avctx->priv_data; + AVFrame *pict = data; + AVFrame *const p = (AVFrame *) & s->picture; + int i; + int n; + uint8_t *ptr = buf; + uint8_t *offset; + uint32_t strips; + uint32_t *strip_sizes = NULL; + uint32_t *strip_offsets = NULL; + int bytes_per_row; + uint32_t res[2] = { 72, 1 }; // image resolution (72/1) + static const uint16_t bpp_tab[] = { 8, 8, 8, 8 }; + int ret = -1; + int is_yuv = 0; + uint8_t *yuv_line = NULL; + int shift_h, shift_v; + + s->buf_start = buf; + s->buf = &ptr; + s->buf_size = buf_size; + + *p = *pict; + p->pict_type = FF_I_TYPE; + p->key_frame = 1; + + s->compr = TIFF_PACKBITS; + if (avctx->compression_level == 0) { + s->compr = TIFF_RAW; + } else if(avctx->compression_level == 2) { + s->compr = TIFF_LZW; +#ifdef CONFIG_ZLIB + } else if ((avctx->compression_level >= 3)) { + s->compr = TIFF_DEFLATE; +#endif + } + + s->width = avctx->width; + s->height = avctx->height; + s->subsampling[0] = 1; + s->subsampling[1] = 1; + + switch (avctx->pix_fmt) { + case PIX_FMT_RGB24: + s->bpp = 24; + s->photometric_interpretation = 2; + break; + case PIX_FMT_GRAY8: + s->bpp = 8; + s->photometric_interpretation = 1; + break; + case PIX_FMT_PAL8: + s->bpp = 8; + s->photometric_interpretation = 3; + break; + case PIX_FMT_MONOBLACK: + s->bpp = 1; + s->photometric_interpretation = 1; + break; + case PIX_FMT_MONOWHITE: + s->bpp = 1; + s->photometric_interpretation = 0; + break; + case PIX_FMT_YUV420P: + case PIX_FMT_YUV422P: + case PIX_FMT_YUV444P: + case PIX_FMT_YUV410P: + case PIX_FMT_YUV411P: + s->photometric_interpretation = 6; + avcodec_get_chroma_sub_sample(avctx->pix_fmt, + &shift_h, &shift_v); + s->bpp = 8 + (16 >> (shift_h + shift_v)); + s->subsampling[0] = 1 << shift_h; + s->subsampling[1] = 1 << shift_v; + s->bpp_tab_size = 3; + is_yuv = 1; + break; + default: + av_log(s->avctx, AV_LOG_ERROR, + "This colors format is not supported\n"); + return -1; + } + if (!is_yuv) + s->bpp_tab_size = (s->bpp >> 3); + + if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE || s->compr == TIFF_LZW) + //best choose for DEFLATE + s->rps = s->height; + else + s->rps = FFMAX(8192 / (((s->width * s->bpp) >> 3) + 1), 1); // suggest size of strip + s->rps = ((s->rps - 1) / s->subsampling[1] + 1) * s->subsampling[1]; // round rps up + + strips = (s->height - 1) / s->rps + 1; + + if (check_size(s, 8)) + goto fail; + + // write header + bytestream_put_le16(&ptr, 0x4949); + bytestream_put_le16(&ptr, 42); + + offset = ptr; + bytestream_put_le32(&ptr, 0); + + strip_sizes = av_mallocz(sizeof(*strip_sizes) * strips); + strip_offsets = av_mallocz(sizeof(*strip_offsets) * strips); + + bytes_per_row = (((s->width - 1)/s->subsampling[0] + 1) * s->bpp + * s->subsampling[0] * s->subsampling[1] + 7) >> 3; + if (is_yuv){ + yuv_line = av_malloc(bytes_per_row); + if (yuv_line == NULL){ + av_log(s->avctx, AV_LOG_ERROR, "Not enough memory\n"); + goto fail; + } + } + +#ifdef CONFIG_ZLIB + if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) { + uint8_t *zbuf; + int zlen, zn; + int j; + + zlen = bytes_per_row * s->rps; + zbuf = av_malloc(zlen); + strip_offsets[0] = ptr - buf; + zn = 0; + for (j = 0; j < s->rps; j++) { + if (is_yuv){ + pack_yuv(s, yuv_line, j); + memcpy(zbuf + zn, yuv_line, bytes_per_row); + j += s->subsampling[1] - 1; + } + else + memcpy(zbuf + j * bytes_per_row, + p->data[0] + j * p->linesize[0], bytes_per_row); + zn += bytes_per_row; + } + n = encode_strip(s, zbuf, ptr, zn, s->compr); + av_free(zbuf); + if (n<0) { + av_log(s->avctx, AV_LOG_ERROR, "Encode strip failed\n"); + goto fail; + } + ptr += n; + strip_sizes[0] = ptr - buf - strip_offsets[0]; + } else +#endif + { + if(s->compr == TIFF_LZW) + s->lzws = av_malloc(ff_lzw_encode_state_size); + for (i = 0; i < s->height; i++) { + if (strip_sizes[i / s->rps] == 0) { + if(s->compr == TIFF_LZW){ + ff_lzw_encode_init(s->lzws, ptr, s->buf_size - (*s->buf - s->buf_start), 12); + } + strip_offsets[i / s->rps] = ptr - buf; + } + if (is_yuv){ + pack_yuv(s, yuv_line, i); + n = encode_strip(s, yuv_line, ptr, bytes_per_row, s->compr); + i += s->subsampling[1] - 1; + } + else + n = encode_strip(s, p->data[0] + i * p->linesize[0], + ptr, bytes_per_row, s->compr); + if (n < 0) { + av_log(s->avctx, AV_LOG_ERROR, "Encode strip failed\n"); + goto fail; + } + strip_sizes[i / s->rps] += n; + ptr += n; + if(s->compr == TIFF_LZW && (i==s->height-1 || i%s->rps == s->rps-1)){ + int ret; + ret = ff_lzw_encode_flush(s->lzws); + strip_sizes[(i / s->rps )] += ret ; + ptr += ret; + } + } + if(s->compr == TIFF_LZW) + av_free(s->lzws); + } + + s->num_entries = 0; + + add_entry1(s,TIFF_SUBFILE, TIFF_LONG, 0); + add_entry1(s,TIFF_WIDTH, TIFF_LONG, s->width); + add_entry1(s,TIFF_HEIGHT, TIFF_LONG, s->height); + + if (s->bpp_tab_size) + add_entry(s, TIFF_BPP, TIFF_SHORT, s->bpp_tab_size, bpp_tab); + + add_entry1(s,TIFF_COMPR, TIFF_SHORT, s->compr); + add_entry1(s,TIFF_INVERT, TIFF_SHORT, s->photometric_interpretation); + add_entry(s, TIFF_STRIP_OFFS, TIFF_LONG, strips, strip_offsets); + + if (s->bpp_tab_size) + add_entry1(s,TIFF_SAMPLES_PER_PIXEL, TIFF_SHORT, s->bpp_tab_size); + + add_entry1(s,TIFF_ROWSPERSTRIP, TIFF_LONG, s->rps); + add_entry(s, TIFF_STRIP_SIZE, TIFF_LONG, strips, strip_sizes); + add_entry(s, TIFF_XRES, TIFF_RATIONAL, 1, res); + add_entry(s, TIFF_YRES, TIFF_RATIONAL, 1, res); + add_entry1(s,TIFF_RES_UNIT, TIFF_SHORT, 2); + + if(!(avctx->flags & CODEC_FLAG_BITEXACT)) + add_entry(s, TIFF_SOFTWARE_NAME, TIFF_STRING, + strlen(LIBAVCODEC_IDENT) + 1, LIBAVCODEC_IDENT); + + if (avctx->pix_fmt == PIX_FMT_PAL8) { + uint16_t pal[256 * 3]; + for (i = 0; i < 256; i++) { + uint32_t rgb = *(uint32_t *) (p->data[1] + i * 4); + pal[i] = ((rgb >> 16) & 0xff) * 257; + pal[i + 256] = ((rgb >> 8 ) & 0xff) * 257; + pal[i + 512] = ( rgb & 0xff) * 257; + } + add_entry(s, TIFF_PAL, TIFF_SHORT, 256 * 3, pal); + } + if (is_yuv){ + /** according to CCIR Recommendation 601.1 */ + uint32_t refbw[12] = {15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1}; + add_entry(s, TIFF_YCBCR_SUBSAMPLING, TIFF_SHORT, 2, s->subsampling); + add_entry(s, TIFF_REFERENCE_BW, TIFF_RATIONAL, 6, refbw); + } + bytestream_put_le32(&offset, ptr - buf); // write offset to dir + + if (check_size(s, 6 + s->num_entries * 12)) + goto fail; + bytestream_put_le16(&ptr, s->num_entries); // write tag count + bytestream_put_buffer(&ptr, s->entries, s->num_entries * 12); + bytestream_put_le32(&ptr, 0); + + ret = ptr - buf; + +fail: + av_free(strip_sizes); + av_free(strip_offsets); + av_free(yuv_line); + return ret; +} + +AVCodec tiff_encoder = { + "tiff", + CODEC_TYPE_VIDEO, + CODEC_ID_TIFF, + sizeof(TiffEncoderContext), + NULL, + encode_frame, + NULL, + NULL, + 0, + NULL, + .pix_fmts = + (enum PixelFormat[]) {PIX_FMT_RGB24, PIX_FMT_PAL8, PIX_FMT_GRAY8, + PIX_FMT_MONOBLACK, PIX_FMT_MONOWHITE, + PIX_FMT_YUV420P, PIX_FMT_YUV422P, + PIX_FMT_YUV444P, PIX_FMT_YUV410P, + PIX_FMT_YUV411P + -1} + +}; diff --git a/contrib/ffmpeg/libavcodec/truemotion1.c b/contrib/ffmpeg/libavcodec/truemotion1.c index a7d3544f4..50948fdda 100644 --- a/contrib/ffmpeg/libavcodec/truemotion1.c +++ b/contrib/ffmpeg/libavcodec/truemotion1.c @@ -22,7 +22,7 @@ /** * @file truemotion1.c * Duck TrueMotion v1 Video Decoder by - * Alex Beregszaszi (alex@fsn.hu) and + * Alex Beregszaszi and * Mike Melanson (melanson@pcisys.net) * * The TrueMotion v1 decoder presently only decodes 16-bit TM1 data and @@ -34,7 +34,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include "dsputil.h" @@ -43,14 +42,13 @@ typedef struct TrueMotion1Context { AVCodecContext *avctx; AVFrame frame; - AVFrame prev_frame; - uint8_t *buf; + const uint8_t *buf; int size; - uint8_t *mb_change_bits; + const uint8_t *mb_change_bits; int mb_change_bits_row_size; - uint8_t *index_stream; + const uint8_t *index_stream; int index_stream_size; int flags; @@ -465,7 +463,7 @@ static int truemotion1_decode_header(TrueMotion1Context *s) static int truemotion1_decode_init(AVCodecContext *avctx) { - TrueMotion1Context *s = (TrueMotion1Context *)avctx->priv_data; + TrueMotion1Context *s = avctx->priv_data; s->avctx = avctx; @@ -475,8 +473,7 @@ static int truemotion1_decode_init(AVCodecContext *avctx) // else // avctx->pix_fmt = PIX_FMT_RGB555; - avctx->has_b_frames = 0; - s->frame.data[0] = s->prev_frame.data[0] = NULL; + s->frame.data[0] = NULL; /* there is a vertical predictor for each pixel in a line; each vertical * predictor is 0 to start with */ @@ -592,8 +589,7 @@ hres,vres,i,i%vres (0 < i < 4) #define OUTPUT_PIXEL_PAIR() \ *current_pixel_pair = *vert_pred + horiz_pred; \ - *vert_pred++ = *current_pixel_pair++; \ - prev_pixel_pair++; + *vert_pred++ = *current_pixel_pair++; static void truemotion1_decode_16bit(TrueMotion1Context *s) { @@ -603,13 +599,11 @@ static void truemotion1_decode_16bit(TrueMotion1Context *s) unsigned int horiz_pred; unsigned int *vert_pred; unsigned int *current_pixel_pair; - unsigned int *prev_pixel_pair; unsigned char *current_line = s->frame.data[0]; - unsigned char *prev_line = s->prev_frame.data[0]; int keyframe = s->flags & FLAG_KEYFRAME; /* these variables are for managing the stream of macroblock change bits */ - unsigned char *mb_change_bits = s->mb_change_bits; + const unsigned char *mb_change_bits = s->mb_change_bits; unsigned char mb_change_byte; unsigned char mb_change_byte_mask; int mb_change_index; @@ -628,7 +622,6 @@ static void truemotion1_decode_16bit(TrueMotion1Context *s) /* re-init variables for the next line iteration */ horiz_pred = 0; current_pixel_pair = (unsigned int *)current_line; - prev_pixel_pair = (unsigned int *)prev_line; vert_pred = s->vert_pred; mb_change_index = 0; mb_change_byte = mb_change_bits[mb_change_index++]; @@ -697,9 +690,7 @@ static void truemotion1_decode_16bit(TrueMotion1Context *s) /* skip (copy) four pixels, but reassign the horizontal * predictor */ - *current_pixel_pair = *prev_pixel_pair++; *vert_pred++ = *current_pixel_pair++; - *current_pixel_pair = *prev_pixel_pair++; horiz_pred = *current_pixel_pair - *vert_pred; *vert_pred++ = *current_pixel_pair++; @@ -723,7 +714,6 @@ static void truemotion1_decode_16bit(TrueMotion1Context *s) mb_change_bits += s->mb_change_bits_row_size; current_line += s->frame.linesize[0]; - prev_line += s->prev_frame.linesize[0]; } } @@ -735,13 +725,11 @@ static void truemotion1_decode_24bit(TrueMotion1Context *s) unsigned int horiz_pred; unsigned int *vert_pred; unsigned int *current_pixel_pair; - unsigned int *prev_pixel_pair; unsigned char *current_line = s->frame.data[0]; - unsigned char *prev_line = s->prev_frame.data[0]; int keyframe = s->flags & FLAG_KEYFRAME; /* these variables are for managing the stream of macroblock change bits */ - unsigned char *mb_change_bits = s->mb_change_bits; + const unsigned char *mb_change_bits = s->mb_change_bits; unsigned char mb_change_byte; unsigned char mb_change_byte_mask; int mb_change_index; @@ -760,7 +748,6 @@ static void truemotion1_decode_24bit(TrueMotion1Context *s) /* re-init variables for the next line iteration */ horiz_pred = 0; current_pixel_pair = (unsigned int *)current_line; - prev_pixel_pair = (unsigned int *)prev_line; vert_pred = s->vert_pred; mb_change_index = 0; mb_change_byte = mb_change_bits[mb_change_index++]; @@ -829,9 +816,7 @@ static void truemotion1_decode_24bit(TrueMotion1Context *s) /* skip (copy) four pixels, but reassign the horizontal * predictor */ - *current_pixel_pair = *prev_pixel_pair++; *vert_pred++ = *current_pixel_pair++; - *current_pixel_pair = *prev_pixel_pair++; horiz_pred = *current_pixel_pair - *vert_pred; *vert_pred++ = *current_pixel_pair++; @@ -855,16 +840,15 @@ static void truemotion1_decode_24bit(TrueMotion1Context *s) mb_change_bits += s->mb_change_bits_row_size; current_line += s->frame.linesize[0]; - prev_line += s->prev_frame.linesize[0]; } } static int truemotion1_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { - TrueMotion1Context *s = (TrueMotion1Context *)avctx->priv_data; + TrueMotion1Context *s = avctx->priv_data; s->buf = buf; s->size = buf_size; @@ -873,28 +857,19 @@ static int truemotion1_decode_frame(AVCodecContext *avctx, return -1; s->frame.reference = 1; - if (avctx->get_buffer(avctx, &s->frame) < 0) { + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | + FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + if (avctx->reget_buffer(avctx, &s->frame) < 0) { av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; } - /* check for a do-nothing frame and copy the previous frame */ - if (compression_types[s->compression].algorithm == ALGO_NOP) - { - memcpy(s->frame.data[0], s->prev_frame.data[0], - s->frame.linesize[0] * s->avctx->height); - } else if (compression_types[s->compression].algorithm == ALGO_RGB24H) { + if (compression_types[s->compression].algorithm == ALGO_RGB24H) { truemotion1_decode_24bit(s); - } else { + } else if (compression_types[s->compression].algorithm != ALGO_NOP) { truemotion1_decode_16bit(s); } - if (s->prev_frame.data[0]) - avctx->release_buffer(avctx, &s->prev_frame); - - /* shuffle frames */ - s->prev_frame = s->frame; - *data_size = sizeof(AVFrame); *(AVFrame*)data = s->frame; @@ -904,11 +879,10 @@ static int truemotion1_decode_frame(AVCodecContext *avctx, static int truemotion1_decode_end(AVCodecContext *avctx) { - TrueMotion1Context *s = (TrueMotion1Context *)avctx->priv_data; + TrueMotion1Context *s = avctx->priv_data; - /* release the last frame */ - if (s->prev_frame.data[0]) - avctx->release_buffer(avctx, &s->prev_frame); + if (s->frame.data[0]) + avctx->release_buffer(avctx, &s->frame); av_free(s->vert_pred); diff --git a/contrib/ffmpeg/libavcodec/truemotion1data.h b/contrib/ffmpeg/libavcodec/truemotion1data.h index 63d307c65..e9662e3d0 100644 --- a/contrib/ffmpeg/libavcodec/truemotion1data.h +++ b/contrib/ffmpeg/libavcodec/truemotion1data.h @@ -22,8 +22,11 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef TRUEMOTION1DATA_H -#define TRUEMOTION1DATA_H +#ifndef FFMPEG_TRUEMOTION1DATA_H +#define FFMPEG_TRUEMOTION1DATA_H + +#include +#include /* Y delta tables, skinny and fat */ static const int16_t ydt1[8] = { 0, -2, 2, -6, 6, -12, 12, -12 }; @@ -826,4 +829,5 @@ static const uint8_t pc_tbl4[] = { }; static const uint8_t *tables[] = { pc_tbl2, pc_tbl3, pc_tbl4 }; -#endif + +#endif /* FFMPEG_TRUEMOTION1DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/truemotion2.c b/contrib/ffmpeg/libavcodec/truemotion2.c index b282c967b..4a4ea7b41 100644 --- a/contrib/ffmpeg/libavcodec/truemotion2.c +++ b/contrib/ffmpeg/libavcodec/truemotion2.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -26,7 +25,6 @@ */ #include "avcodec.h" -#include "common.h" #include "bitstream.h" #include "dsputil.h" @@ -200,10 +198,10 @@ static inline int tm2_get_token(GetBitContext *gb, TM2Codes *code) return code->recode[val]; } -static inline int tm2_read_header(TM2Context *ctx, uint8_t *buf) +static inline int tm2_read_header(TM2Context *ctx, const uint8_t *buf) { uint32_t magic; - uint8_t *obuf; + const uint8_t *obuf; int length; obuf = buf; @@ -262,7 +260,7 @@ static int tm2_read_deltas(TM2Context *ctx, int stream_id) { return 0; } -static int tm2_read_stream(TM2Context *ctx, uint8_t *buf, int stream_id) { +static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id) { int i; int cur = 0; int skip = 0; @@ -761,7 +759,7 @@ static int tm2_decode_blocks(TM2Context *ctx, AVFrame *p) static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { TM2Context * const l = avctx->priv_data; AVFrame * const p= (AVFrame*)&l->pic; @@ -774,7 +772,7 @@ static int decode_frame(AVCodecContext *avctx, return -1; } - l->dsp.bswap_buf((uint32_t*)buf, (uint32_t*)buf, buf_size >> 2); + l->dsp.bswap_buf((uint32_t*)buf, (const uint32_t*)buf, buf_size >> 2); //FIXME SERIOUS BUG skip = tm2_read_header(l, buf); if(skip == -1) diff --git a/contrib/ffmpeg/libavcodec/truespeech.c b/contrib/ffmpeg/libavcodec/truespeech.c index a03f2a0ce..9deac28be 100644 --- a/contrib/ffmpeg/libavcodec/truespeech.c +++ b/contrib/ffmpeg/libavcodec/truespeech.c @@ -57,7 +57,7 @@ static int truespeech_decode_init(AVCodecContext * avctx) return 0; } -static void truespeech_read_frame(TSContext *dec, uint8_t *input) +static void truespeech_read_frame(TSContext *dec, const uint8_t *input) { uint32_t t; @@ -329,19 +329,21 @@ static void truespeech_save_prevvec(TSContext *c) static int truespeech_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { TSContext *c = avctx->priv_data; - int i; + int i, j; short *samples = data; int consumed = 0; int16_t out_buf[240]; + int iterations; if (!buf_size) return 0; - while (consumed < buf_size) { + iterations = FFMIN(buf_size / 32, *data_size / 480); + for(j = 0; j < iterations; j++) { truespeech_read_frame(c, buf + consumed); consumed += 32; @@ -366,7 +368,7 @@ static int truespeech_decode_frame(AVCodecContext *avctx, *data_size = consumed * 15; - return buf_size; + return consumed; } AVCodec truespeech_decoder = { diff --git a/contrib/ffmpeg/libavcodec/truespeech_data.h b/contrib/ffmpeg/libavcodec/truespeech_data.h index cd8822fde..c7ca55910 100644 --- a/contrib/ffmpeg/libavcodec/truespeech_data.h +++ b/contrib/ffmpeg/libavcodec/truespeech_data.h @@ -19,8 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef __TRUESPEECH_DATA__ -#define __TRUESPEECH_DATA__ +#ifndef FFMPEG_TRUESPEECH_DATA_H +#define FFMPEG_TRUESPEECH_DATA_H + +#include /* codebooks fo expanding input filter */ static const int16_t ts_cb_0[32] = { @@ -154,4 +156,4 @@ static const int16_t ts_5E2[8] = static const int16_t ts_5F2[8] = { 0x6000, 0x4800, 0x3600, 0x2880, 0x1E60, 0x16C8, 0x1116, 0x0CD1 }; -#endif +#endif /* FFMPEG_TRUESPEECH_DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/tscc.c b/contrib/ffmpeg/libavcodec/tscc.c index 1453eb568..30bb19f97 100644 --- a/contrib/ffmpeg/libavcodec/tscc.c +++ b/contrib/ffmpeg/libavcodec/tscc.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -39,7 +38,6 @@ #include #include -#include "common.h" #include "avcodec.h" #ifdef CONFIG_ZLIB @@ -184,10 +182,10 @@ static int decode_rle(CamtasiaContext *c, unsigned int srcsize) * Decode a frame * */ -static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size) { - CamtasiaContext * const c = (CamtasiaContext *)avctx->priv_data; - unsigned char *encoded = (unsigned char *)buf; + CamtasiaContext * const c = avctx->priv_data; + const unsigned char *encoded = buf; unsigned char *outptr; #ifdef CONFIG_ZLIB int zret; // Zlib return code @@ -257,7 +255,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 */ static int decode_init(AVCodecContext *avctx) { - CamtasiaContext * const c = (CamtasiaContext *)avctx->priv_data; + CamtasiaContext * const c = avctx->priv_data; int zret; // Zlib return code c->avctx = avctx; @@ -320,7 +318,7 @@ static int decode_init(AVCodecContext *avctx) */ static int decode_end(AVCodecContext *avctx) { - CamtasiaContext * const c = (CamtasiaContext *)avctx->priv_data; + CamtasiaContext * const c = avctx->priv_data; av_freep(&c->decomp_buf); diff --git a/contrib/ffmpeg/libavcodec/tta.c b/contrib/ffmpeg/libavcodec/tta.c index 82713fb0f..f08b12d90 100644 --- a/contrib/ffmpeg/libavcodec/tta.c +++ b/contrib/ffmpeg/libavcodec/tta.c @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** @@ -287,7 +287,7 @@ static int tta_decode_init(AVCodecContext * avctx) static int tta_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { TTAContext *s = avctx->priv_data; int i; diff --git a/contrib/ffmpeg/libavcodec/txd.c b/contrib/ffmpeg/libavcodec/txd.c new file mode 100644 index 000000000..13e1938bb --- /dev/null +++ b/contrib/ffmpeg/libavcodec/txd.c @@ -0,0 +1,166 @@ +/* + * Renderware TeXture Dictionary (.txd) image decoder + * Copyright (c) 2007 Ivo van Poorten + * + * See also: http://wiki.multimedia.cx/index.php?title=TXD + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "s3tc.h" + +typedef struct TXDContext { + AVFrame picture; +} TXDContext; + +static int txd_init(AVCodecContext *avctx) { + TXDContext *s = avctx->priv_data; + + avcodec_get_frame_defaults(&s->picture); + avctx->coded_frame = &s->picture; + + return 0; +} + +static int txd_decode_frame(AVCodecContext *avctx, void *data, int *data_size, + const uint8_t *buf, int buf_size) { + TXDContext * const s = avctx->priv_data; + AVFrame *picture = data; + AVFrame * const p = &s->picture; + unsigned int version, w, h, d3d_format, depth, stride, mipmap_count, flags; + unsigned int y, v; + uint8_t *ptr; + const uint8_t *cur = buf; + const uint32_t *palette = (const uint32_t *)(cur + 88); + uint32_t *pal; + + version = AV_RL32(cur); + d3d_format = AV_RL32(cur+76); + w = AV_RL16(cur+80); + h = AV_RL16(cur+82); + depth = AV_RL8 (cur+84); + mipmap_count = AV_RL8 (cur+85); + flags = AV_RL8 (cur+87); + cur += 92; + + if (version < 8 || version > 9) { + av_log(avctx, AV_LOG_ERROR, "texture data version %i is unsupported\n", + version); + return -1; + } + + if (depth == 8) { + avctx->pix_fmt = PIX_FMT_PAL8; + cur += 1024; + } else if (depth == 16 || depth == 32) + avctx->pix_fmt = PIX_FMT_RGB32; + else { + av_log(avctx, AV_LOG_ERROR, "depth of %i is unsupported\n", depth); + return -1; + } + + if (p->data[0]) + avctx->release_buffer(avctx, p); + + if (avcodec_check_dimensions(avctx, w, h)) + return -1; + if (w != avctx->width || h != avctx->height) + avcodec_set_dimensions(avctx, w, h); + if (avctx->get_buffer(avctx, p) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + + p->pict_type = FF_I_TYPE; + + ptr = p->data[0]; + stride = p->linesize[0]; + + if (depth == 8) { + pal = (uint32_t *) p->data[1]; + for (y=0; y<256; y++) { + v = AV_RB32(palette+y); + pal[y] = (v>>8) + (v<<24); + } + for (y=0; y 1; mipmap_count--) + cur += AV_RL32(cur) + 4; + + *picture = s->picture; + *data_size = sizeof(AVPicture); + + return cur - buf; + +unsupported: + av_log(avctx, AV_LOG_ERROR, "unsupported d3d format (%08x)\n", d3d_format); + return -1; +} + +static int txd_end(AVCodecContext *avctx) { + TXDContext *s = avctx->priv_data; + + if (s->picture.data[0]) + avctx->release_buffer(avctx, &s->picture); + + return 0; +} + +AVCodec txd_decoder = { + "txd", + CODEC_TYPE_VIDEO, + CODEC_ID_TXD, + sizeof(TXDContext), + txd_init, + NULL, + txd_end, + txd_decode_frame, + 0, + NULL +}; diff --git a/contrib/ffmpeg/libavcodec/ulti.c b/contrib/ffmpeg/libavcodec/ulti.c index d84a88dad..cf0c28f1f 100644 --- a/contrib/ffmpeg/libavcodec/ulti.c +++ b/contrib/ffmpeg/libavcodec/ulti.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -30,8 +29,8 @@ #include #include -#include "common.h" #include "avcodec.h" +#include "bytestream.h" #include "ulti_cb.h" @@ -201,7 +200,7 @@ static void ulti_grad(AVFrame *frame, int x, int y, uint8_t *Y, int chroma, int static int ulti_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { UltimotionDecodeContext *s=avctx->priv_data; int modifier = 0; @@ -306,9 +305,7 @@ static int ulti_decode_frame(AVCodecContext *avctx, case 2: if (modifier) { // unpack four luma samples - tmp = (*buf++) << 16; - tmp += (*buf++) << 8; - tmp += *buf++; + tmp = bytestream_get_be24(&buf); Y[0] = (tmp >> 18) & 0x3F; Y[1] = (tmp >> 12) & 0x3F; @@ -316,8 +313,7 @@ static int ulti_decode_frame(AVCodecContext *avctx, Y[3] = tmp & 0x3F; angle = 16; } else { // retrieve luma samples from codebook - tmp = (*buf++) << 8; - tmp += (*buf++); + tmp = bytestream_get_be16(&buf); angle = (tmp >> 12) & 0xF; tmp &= 0xFFF; @@ -333,33 +329,25 @@ static int ulti_decode_frame(AVCodecContext *avctx, if (modifier) { // all 16 luma samples uint8_t Luma[16]; - tmp = (*buf++) << 16; - tmp += (*buf++) << 8; - tmp += *buf++; + tmp = bytestream_get_be24(&buf); Luma[0] = (tmp >> 18) & 0x3F; Luma[1] = (tmp >> 12) & 0x3F; Luma[2] = (tmp >> 6) & 0x3F; Luma[3] = tmp & 0x3F; - tmp = (*buf++) << 16; - tmp += (*buf++) << 8; - tmp += *buf++; + tmp = bytestream_get_be24(&buf); Luma[4] = (tmp >> 18) & 0x3F; Luma[5] = (tmp >> 12) & 0x3F; Luma[6] = (tmp >> 6) & 0x3F; Luma[7] = tmp & 0x3F; - tmp = (*buf++) << 16; - tmp += (*buf++) << 8; - tmp += *buf++; + tmp = bytestream_get_be24(&buf); Luma[8] = (tmp >> 18) & 0x3F; Luma[9] = (tmp >> 12) & 0x3F; Luma[10] = (tmp >> 6) & 0x3F; Luma[11] = tmp & 0x3F; - tmp = (*buf++) << 16; - tmp += (*buf++) << 8; - tmp += *buf++; + tmp = bytestream_get_be24(&buf); Luma[12] = (tmp >> 18) & 0x3F; Luma[13] = (tmp >> 12) & 0x3F; Luma[14] = (tmp >> 6) & 0x3F; diff --git a/contrib/ffmpeg/libavcodec/ulti_cb.h b/contrib/ffmpeg/libavcodec/ulti_cb.h index 2d8c9082c..e7bd3b86b 100644 --- a/contrib/ffmpeg/libavcodec/ulti_cb.h +++ b/contrib/ffmpeg/libavcodec/ulti_cb.h @@ -19,6 +19,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef FFMPEG_ULTI_CB_H +#define FFMPEG_ULTI_CB_H + static const unsigned char ulti_codebook[16384]={ 0x00, 0x01, 0x01, 0x02, 0x00, 0x01, 0x02, 0x03, @@ -4117,3 +4120,5 @@ static const unsigned char ulti_codebook[16384]={ 0x3C, 0x3D, 0x3E, 0x3F, 0x3D, 0x3E, 0x3E, 0x3F }; + +#endif /* FFMPEG_ULTI_CB_H */ diff --git a/contrib/ffmpeg/libavcodec/unary.h b/contrib/ffmpeg/libavcodec/unary.h new file mode 100644 index 000000000..abd7a531b --- /dev/null +++ b/contrib/ffmpeg/libavcodec/unary.h @@ -0,0 +1,56 @@ +/* + * copyright (c) 2004 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_UNARY_H +#define FFMPEG_UNARY_H + +#include "bitstream.h" + +/** + * Get unary code of limited length + * @param gb GetBitContext + * @param[in] stop The bitstop value (unary code of 1's or 0's) + * @param[in] len Maximum length + * @return Unary length/index + */ +static inline int get_unary(GetBitContext *gb, int stop, int len) +{ + int i; + + for(i = 0; i < len && get_bits1(gb) != stop; i++); + return i; +} + +/** + * Get unary code terminated by a 0 with a maximum length of 33 + * @param gb GetBitContext + * @return Unary length/index + */ +static inline int get_unary_0_33(GetBitContext *gb) +{ + return get_unary(gb, 0, 33); +} + +static inline int get_unary_0_9(GetBitContext *gb) +{ + return get_unary(gb, 0, 9); +} + +#endif /* FFMPEG_UNARY_H */ diff --git a/contrib/ffmpeg/libavcodec/utils.c b/contrib/ffmpeg/libavcodec/utils.c index 2129c9d15..d40428a28 100644 --- a/contrib/ffmpeg/libavcodec/utils.c +++ b/contrib/ffmpeg/libavcodec/utils.c @@ -31,10 +31,11 @@ #include "integer.h" #include "opt.h" #include "crc.h" +#include "imgconvert.h" #include #include #include -#ifdef __MINGW32__ +#if !defined(HAVE_MKSTEMP) #include #endif @@ -126,6 +127,11 @@ static void do_free(void) /* encoder management */ AVCodec *first_avcodec = NULL; +AVCodec *av_codec_next(AVCodec *c){ + if(c) return c->next; + else return first_avcodec; +} + void register_avcodec(AVCodec *format) { AVCodec **p; @@ -147,6 +153,8 @@ typedef struct InternalBuffer{ uint8_t *base[4]; uint8_t *data[4]; int linesize[4]; + int width, height; + enum PixelFormat pix_fmt; }InternalBuffer; #define INTERNAL_BUFFER_SIZE 32 @@ -169,6 +177,7 @@ void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){ case PIX_FMT_YUVJ420P: case PIX_FMT_YUVJ422P: case PIX_FMT_YUVJ444P: + case PIX_FMT_YUVA420P: w_align= 16; //FIXME check for non mpeg style codecs and use less alignment h_align= 16; break; @@ -251,12 +260,20 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE-1]).last_pic_num; //FIXME ugly hack (*picture_number)++; + if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){ + for(i=0; i<4; i++){ + av_freep(&buf->base[i]); + buf->data[i]= NULL; + } + } + if(buf->base[0]){ pic->age= *picture_number - buf->last_pic_num; buf->last_pic_num= *picture_number; }else{ int h_chroma_shift, v_chroma_shift; - int pixel_size, size[3]; + int size[4] = {0}; + int tmpsize; AVPicture picture; avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); @@ -267,28 +284,24 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ w+= EDGE_WIDTH*2; h+= EDGE_WIDTH*2; } - avpicture_fill(&picture, NULL, s->pix_fmt, w, h); - pixel_size= picture.linesize[0]*8 / w; -//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d\n", (int)picture.data[1], w, h, s->pix_fmt); - assert(pixel_size>=1); - //FIXME next ensures that linesize= 2^x uvlinesize, thats needed because some MC code assumes it - if(pixel_size == 3*8) - w= ALIGN(w, STRIDE_ALIGN<pix_fmt, w, h); - size[0] = picture.linesize[0] * h; - size[1] -= size[0]; - if(picture.data[2]) - size[1]= size[2]= size[1]/2; - else - size[2]= 0; + avcodec_align_dimensions(s, &w, &h); + + ff_fill_linesize(&picture, s->pix_fmt, w); + + for (i=0; i<4; i++) + picture.linesize[i] = ALIGN(picture.linesize[i], STRIDE_ALIGN); + + tmpsize = ff_fill_pointer(&picture, NULL, s->pix_fmt, h); + + for (i=0; i<3 && picture.data[i+1]; i++) + size[i] = picture.data[i+1] - picture.data[i]; + size[i] = tmpsize - (picture.data[i] - picture.data[0]); buf->last_pic_num= -256*256*256*64; memset(buf->base, 0, sizeof(buf->base)); memset(buf->data, 0, sizeof(buf->data)); - for(i=0; i<3 && size[i]; i++){ + for(i=0; i<4 && size[i]; i++){ const int h_shift= i==0 ? 0 : h_chroma_shift; const int v_shift= i==0 ? 0 : v_chroma_shift; @@ -304,6 +317,9 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ else buf->data[i] = buf->base[i] + ALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), STRIDE_ALIGN); } + buf->width = s->width; + buf->height = s->height; + buf->pix_fmt= s->pix_fmt; pic->age= 256*256*256*64; } pic->type= FF_BUFFER_TYPE_INTERNAL; @@ -337,7 +353,7 @@ void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){ FFSWAP(InternalBuffer, *buf, *last); - for(i=0; i<3; i++){ + for(i=0; i<4; i++){ pic->data[i]=NULL; // pic->base[i]=NULL; } @@ -400,7 +416,7 @@ static const char* context_to_name(void* ptr) { } #define OFFSET(x) offsetof(AVCodecContext,x) -#define DEFAULT 0 //should be NAN but it doesnt work as its not a constant in glibc as required by ANSI/ISO C +#define DEFAULT 0 //should be NAN but it does not work as it is not a constant in glibc as required by ANSI/ISO C //these names are too long to be readable #define V AV_OPT_FLAG_VIDEO_PARAM #define A AV_OPT_FLAG_AUDIO_PARAM @@ -453,6 +469,18 @@ static const AVOption options[]={ {"local_header", "place global headers at every keyframe instead of in extradata", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_LOCAL_HEADER, INT_MIN, INT_MAX, V|E, "flags2"}, {"sub_id", NULL, OFFSET(sub_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, {"me_method", "set motion estimation method", OFFSET(me_method), FF_OPT_TYPE_INT, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method"}, +#if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) +{"me", "set motion estimation method (deprecated, use me_method instead)", OFFSET(me_method), FF_OPT_TYPE_INT, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method"}, +#endif +{"zero", "zero motion estimation (fastest)", 0, FF_OPT_TYPE_CONST, ME_ZERO, INT_MIN, INT_MAX, V|E, "me_method" }, +{"full", "full motion estimation (slowest)", 0, FF_OPT_TYPE_CONST, ME_FULL, INT_MIN, INT_MAX, V|E, "me_method" }, +{"epzs", "EPZS motion estimation (default)", 0, FF_OPT_TYPE_CONST, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method" }, +{"log", "log motion estimation", 0, FF_OPT_TYPE_CONST, ME_LOG, INT_MIN, INT_MAX, V|E, "me_method" }, +{"phods", "phods motion estimation", 0, FF_OPT_TYPE_CONST, ME_PHODS, INT_MIN, INT_MAX, V|E, "me_method" }, +{"x1", "X1 motion estimation", 0, FF_OPT_TYPE_CONST, ME_X1, INT_MIN, INT_MAX, V|E, "me_method" }, +{"hex", "hex motion estimation", 0, FF_OPT_TYPE_CONST, ME_HEX, INT_MIN, INT_MAX, V|E, "me_method" }, +{"umh", "umh motion estimation", 0, FF_OPT_TYPE_CONST, ME_UMH, INT_MIN, INT_MAX, V|E, "me_method" }, +{"iter", "iter motion estimation", 0, FF_OPT_TYPE_CONST, ME_ITER, INT_MIN, INT_MAX, V|E, "me_method" }, {"extradata_size", NULL, OFFSET(extradata_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, {"time_base", NULL, OFFSET(time_base), FF_OPT_TYPE_RATIONAL, DEFAULT, INT_MIN, INT_MAX}, {"g", "set the group of picture size", OFFSET(gop_size), FF_OPT_TYPE_INT, 12, INT_MIN, INT_MAX, V|E}, @@ -511,7 +539,7 @@ static const AVOption options[]={ {"strict", "strictly conform to all the things in the spec no matter what consequences", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_STRICT, INT_MIN, INT_MAX, V|E, "strict"}, {"normal", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_NORMAL, INT_MIN, INT_MAX, V|E, "strict"}, {"inofficial", "allow inofficial extensions", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_INOFFICIAL, INT_MIN, INT_MAX, V|E, "strict"}, -{"experimental", "allow non standarized experimental things", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_EXPERIMENTAL, INT_MIN, INT_MAX, V|E, "strict"}, +{"experimental", "allow non standardized experimental things", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_EXPERIMENTAL, INT_MIN, INT_MAX, V|E, "strict"}, {"b_qoffset", "qp offset between p and b frames", OFFSET(b_quant_offset), FF_OPT_TYPE_FLOAT, 1.25, FLT_MIN, FLT_MAX, V|E}, {"er", "set error resilience strategy", OFFSET(error_resilience), FF_OPT_TYPE_INT, FF_ER_CAREFUL, INT_MIN, INT_MAX, A|V|D, "er"}, {"careful", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_CAREFUL, INT_MIN, INT_MAX, V|D, "er"}, @@ -531,7 +559,7 @@ static const AVOption options[]={ {"rc_eq", "set rate control equation", OFFSET(rc_eq), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX, V|E}, {"maxrate", "set max video bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, {"minrate", "set min video bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, -{"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +{"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|V|E}, {"rc_buf_aggressivity", "currently useless", OFFSET(rc_buffer_aggressivity), FF_OPT_TYPE_FLOAT, 1.0, FLT_MIN, FLT_MAX, V|E}, {"i_qfactor", "qp factor between p and i frames", OFFSET(i_quant_factor), FF_OPT_TYPE_FLOAT, -0.8, -FLT_MAX, FLT_MAX, V|E}, {"i_qoffset", "qp offset between p and i frames", OFFSET(i_quant_offset), FF_OPT_TYPE_FLOAT, 0.0, -FLT_MAX, FLT_MAX, V|E}, @@ -567,6 +595,7 @@ static const AVOption options[]={ {"vp3", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_VP3, INT_MIN, INT_MAX, V|E|D, "idct"}, {"ipp", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_IPP, INT_MIN, INT_MAX, V|E|D, "idct"}, {"xvidmmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_XVIDMMX, INT_MIN, INT_MAX, V|E|D, "idct"}, +{"faani", "floating point AAN IDCT", 0, FF_OPT_TYPE_CONST, FF_IDCT_FAAN, INT_MIN, INT_MAX, V|D|E, "idct"}, {"slice_count", NULL, OFFSET(slice_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, {"ec", "set error concealment strategy", OFFSET(error_concealment), FF_OPT_TYPE_FLAGS, 3, INT_MIN, INT_MAX, V|D, "ec"}, {"guess_mvs", "iterative motion vector (MV) search (slow)", 0, FF_OPT_TYPE_CONST, FF_EC_GUESS_MVS, INT_MIN, INT_MAX, V|D, "ec"}, @@ -636,6 +665,9 @@ static const AVOption options[]={ {"coder", NULL, OFFSET(coder_type), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "coder"}, {"vlc", "variable length coder / huffman coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_VLC, INT_MIN, INT_MAX, V|E, "coder"}, {"ac", "arithmetic coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_AC, INT_MIN, INT_MAX, V|E, "coder"}, +{"raw", "raw (no encoding)", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_RAW, INT_MIN, INT_MAX, V|E, "coder"}, +{"rle", "run-length coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_RLE, INT_MIN, INT_MAX, V|E, "coder"}, +{"deflate", "deflate-based coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_DEFLATE, INT_MIN, INT_MAX, V|E, "coder"}, {"context", "context model", OFFSET(context_model), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, {"slice_flags", NULL, OFFSET(slice_flags), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, {"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, @@ -650,7 +682,7 @@ static const AVOption options[]={ {"nr", "noise reduction", OFFSET(noise_reduction), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, {"rc_init_occupancy", "number of bits which should be loaded into the rc buffer before decoding starts", OFFSET(rc_initial_buffer_occupancy), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, {"inter_threshold", NULL, OFFSET(inter_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, -{"flags2", NULL, OFFSET(flags2), FF_OPT_TYPE_FLAGS, CODEC_FLAG2_FASTPSKIP, INT_MIN, INT_MAX, V|A|E|D, "flags2"}, +{"flags2", NULL, OFFSET(flags2), FF_OPT_TYPE_FLAGS, CODEC_FLAG2_FASTPSKIP|CODEC_FLAG2_BIT_RESERVOIR, INT_MIN, INT_MAX, V|A|E|D, "flags2"}, {"error", NULL, OFFSET(error_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, {"antialias", "MP3 antialias algorithm", OFFSET(antialias_algo), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D, "aa"}, {"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_AUTO, INT_MIN, INT_MAX, V|D, "aa"}, @@ -667,6 +699,10 @@ static const AVOption options[]={ {"skip_bottom", "number of macroblock rows at the bottom which are skipped", OFFSET(skip_bottom), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D}, {"profile", NULL, OFFSET(profile), FF_OPT_TYPE_INT, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"}, {"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"}, +{"aac_main", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_MAIN, INT_MIN, INT_MAX, A|E, "profile"}, +{"aac_low", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_LOW, INT_MIN, INT_MAX, A|E, "profile"}, +{"aac_ssr", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_SSR, INT_MIN, INT_MAX, A|E, "profile"}, +{"aac_ltp", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_LTP, INT_MIN, INT_MAX, A|E, "profile"}, {"level", NULL, OFFSET(level), FF_OPT_TYPE_INT, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"}, {"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"}, {"lowres", "decode at 1= 1/2, 2=1/4, 3=1/8 resolutions", OFFSET(lowres), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|D}, @@ -695,7 +731,7 @@ static const AVOption options[]={ {"fastpskip", "fast pskip (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FASTPSKIP, INT_MIN, INT_MAX, V|E, "flags2"}, {"aud", "access unit delimiters (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_AUD, INT_MIN, INT_MAX, V|E, "flags2"}, {"brdo", "b-frame rate-distortion optimization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BRDO, INT_MIN, INT_MAX, V|E, "flags2"}, -{"skiprd", "RD optimal MB level residual skiping", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_SKIP_RD, INT_MIN, INT_MAX, V|E, "flags2"}, +{"skiprd", "RD optimal MB level residual skipping", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_SKIP_RD, INT_MIN, INT_MAX, V|E, "flags2"}, {"complexityblur", "reduce fluctuations in qp (before curve compression)", OFFSET(complexityblur), FF_OPT_TYPE_FLOAT, 20.0, FLT_MIN, FLT_MAX, V|E}, {"deblockalpha", "in-loop deblocking filter alphac0 parameter", OFFSET(deblockalpha), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E}, {"deblockbeta", "in-loop deblocking filter beta parameter", OFFSET(deblockbeta), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E}, @@ -720,6 +756,9 @@ static const AVOption options[]={ {"timecode_frame_start", "GOP timecode frame start number, in non drop frame format", OFFSET(timecode_frame_start), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|E}, {"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_DROP_FRAME_TIMECODE, INT_MIN, INT_MAX, V|E, "flags2"}, {"non_linear_q", "use non linear quantizer", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NON_LINEAR_QUANT, INT_MIN, INT_MAX, V|E, "flags2"}, +{"request_channels", "set desired number of audio channels", OFFSET(request_channels), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|D}, +{"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), FF_OPT_TYPE_FLOAT, 1.0, 0.0, 1.0, A|D}, +{"reservoir", "use bit reservoir", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BIT_RESERVOIR, INT_MIN, INT_MAX, A|E, "flags2"}, {NULL}, }; @@ -738,6 +777,7 @@ void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType codec_type) s->av_class= &av_codec_context_class; + s->codec_type = codec_type; if(codec_type == CODEC_TYPE_AUDIO) flags= AV_OPT_FLAG_AUDIO_PARAM; else if(codec_type == CODEC_TYPE_VIDEO) @@ -795,7 +835,7 @@ AVFrame *avcodec_alloc_frame(void){ return pic; } -int avcodec_open(AVCodecContext *avctx, AVCodec *codec) +int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) { int ret= -1; @@ -805,13 +845,15 @@ int avcodec_open(AVCodecContext *avctx, AVCodec *codec) goto end; } - if(avctx->codec) + if(avctx->codec || !codec) goto end; if (codec->priv_data_size > 0) { avctx->priv_data = av_mallocz(codec->priv_data_size); - if (!avctx->priv_data) + if (!avctx->priv_data) { + ret = AVERROR(ENOMEM); goto end; + } } else { avctx->priv_data = NULL; } @@ -823,6 +865,7 @@ int avcodec_open(AVCodecContext *avctx, AVCodec *codec) if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height)){ av_freep(&avctx->priv_data); + ret = AVERROR(EINVAL); goto end; } @@ -843,7 +886,7 @@ end: return ret; } -int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, +int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, const short *samples) { if(buf_size < FF_MIN_BUFFER_SIZE && 0){ @@ -858,7 +901,7 @@ int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, return 0; } -int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, +int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVFrame *pict) { if(buf_size < FF_MIN_BUFFER_SIZE){ @@ -886,9 +929,9 @@ int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, return ret; } -int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, +int attribute_align_arg avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { int ret; @@ -909,9 +952,9 @@ int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, return ret; } -int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples, +int attribute_align_arg avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { int ret; @@ -922,8 +965,7 @@ int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples, return -1; } if(*frame_size_ptr < FF_MIN_BUFFER_SIZE || - *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t) || - *frame_size_ptr < buf_size){ + *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t)){ av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr); return -1; } @@ -941,7 +983,7 @@ int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples, #if LIBAVCODEC_VERSION_INT < ((52<<16)+(0<<8)+0) int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, - uint8_t *buf, int buf_size){ + const uint8_t *buf, int buf_size){ *frame_size_ptr= AVCODEC_MAX_AUDIO_FRAME_SIZE; return avcodec_decode_audio2(avctx, samples, frame_size_ptr, buf, buf_size); } @@ -955,7 +997,7 @@ int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub, *got_sub_ptr = 0; ret = avctx->codec->decode(avctx, sub, got_sub_ptr, - (uint8_t *)buf, buf_size); + buf, buf_size); if (*got_sub_ptr) avctx->frame_number++; return ret; @@ -970,6 +1012,8 @@ int avcodec_close(AVCodecContext *avctx) return -1; } + if (ENABLE_THREADS && avctx->thread_opaque) + avcodec_thread_free(avctx); if (avctx->codec->close) avctx->codec->close(avctx); avcodec_default_free_buffers(avctx); @@ -1034,6 +1078,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) char buf1[32]; char channels_str[100]; int bitrate; + AVRational display_aspect_ratio; if (encode) p = avcodec_find_encoder(enc->codec_id); @@ -1084,7 +1129,15 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) snprintf(buf + strlen(buf), buf_size - strlen(buf), ", %dx%d", enc->width, enc->height); - if(av_log_level >= AV_LOG_DEBUG){ + av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den, + enc->width*enc->sample_aspect_ratio.num, + enc->height*enc->sample_aspect_ratio.den, + 1024*1024); + snprintf(buf + strlen(buf), buf_size - strlen(buf), + " [PAR %d:%d DAR %d:%d]", + enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den, + display_aspect_ratio.num, display_aspect_ratio.den); + if(av_log_get_level() >= AV_LOG_DEBUG){ int g= ff_gcd(enc->time_base.num, enc->time_base.den); snprintf(buf + strlen(buf), buf_size - strlen(buf), ", %d/%d", @@ -1139,6 +1192,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) break; case CODEC_ID_PCM_S16LE: case CODEC_ID_PCM_S16BE: + case CODEC_ID_PCM_S16LE_PLANAR: case CODEC_ID_PCM_U16LE: case CODEC_ID_PCM_U16BE: bitrate = enc->sample_rate * enc->channels * 16; @@ -1162,6 +1216,10 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) snprintf(buf, buf_size, "Subtitle: %s", codec_name); bitrate = enc->bit_rate; break; + case CODEC_TYPE_ATTACHMENT: + snprintf(buf, buf_size, "Attachment: %s", codec_name); + bitrate = enc->bit_rate; + break; default: snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type); return; @@ -1190,27 +1248,15 @@ unsigned avcodec_build( void ) return LIBAVCODEC_BUILD; } -static void init_crcs(void){ -#if LIBAVUTIL_VERSION_INT < (50<<16) - av_crc04C11DB7= av_mallocz_static(sizeof(AVCRC) * 257); - av_crc8005 = av_mallocz_static(sizeof(AVCRC) * 257); - av_crc07 = av_mallocz_static(sizeof(AVCRC) * 257); -#endif - av_crc_init(av_crc04C11DB7, 0, 32, 0x04c11db7, sizeof(AVCRC)*257); - av_crc_init(av_crc8005 , 0, 16, 0x8005 , sizeof(AVCRC)*257); - av_crc_init(av_crc07 , 0, 8, 0x07 , sizeof(AVCRC)*257); -} - void avcodec_init(void) { - static int inited = 0; + static int initialized = 0; - if (inited != 0) + if (initialized != 0) return; - inited = 1; + initialized = 1; dsputil_static_init(); - init_crcs(); } void avcodec_flush_buffers(AVCodecContext *avctx) @@ -1264,6 +1310,7 @@ int av_get_bits_per_sample(enum CodecID codec_id){ return 8; case CODEC_ID_PCM_S16BE: case CODEC_ID_PCM_S16LE: + case CODEC_ID_PCM_S16LE_PLANAR: case CODEC_ID_PCM_U16BE: case CODEC_ID_PCM_U16LE: return 16; @@ -1283,6 +1330,22 @@ int av_get_bits_per_sample(enum CodecID codec_id){ } } +int av_get_bits_per_sample_format(enum SampleFormat sample_fmt) { + switch (sample_fmt) { + case SAMPLE_FMT_U8: + return 8; + case SAMPLE_FMT_S16: + return 16; + case SAMPLE_FMT_S24: + return 24; + case SAMPLE_FMT_S32: + case SAMPLE_FMT_FLT: + return 32; + default: + return 0; + } +} + #if !defined(HAVE_THREADS) int avcodec_thread_init(AVCodecContext *s, int thread_count){ return -1; @@ -1310,7 +1373,7 @@ unsigned int av_xiphlacing(unsigned char *s, unsigned int v) * and opened file name in **filename. */ int av_tempfile(char *prefix, char **filename) { int fd=-1; -#ifdef __MINGW32__ +#if !defined(HAVE_MKSTEMP) *filename = tempnam(".", prefix); #else size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */ @@ -1321,8 +1384,8 @@ int av_tempfile(char *prefix, char **filename) { av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n"); return -1; } -#ifdef __MINGW32__ - fd = open(*filename, _O_RDWR | _O_BINARY | _O_CREAT, 0444); +#if !defined(HAVE_MKSTEMP) + fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444); #else snprintf(*filename, len, "/tmp/%sXXXXXX", prefix); fd = mkstemp(*filename); @@ -1338,3 +1401,129 @@ int av_tempfile(char *prefix, char **filename) { } return fd; /* success */ } + +typedef struct { + const char *abbr; + int width, height; +} VideoFrameSizeAbbr; + +typedef struct { + const char *abbr; + int rate_num, rate_den; +} VideoFrameRateAbbr; + +static VideoFrameSizeAbbr video_frame_size_abbrs[] = { + { "ntsc", 720, 480 }, + { "pal", 720, 576 }, + { "qntsc", 352, 240 }, /* VCD compliant NTSC */ + { "qpal", 352, 288 }, /* VCD compliant PAL */ + { "sntsc", 640, 480 }, /* square pixel NTSC */ + { "spal", 768, 576 }, /* square pixel PAL */ + { "film", 352, 240 }, + { "ntsc-film", 352, 240 }, + { "sqcif", 128, 96 }, + { "qcif", 176, 144 }, + { "cif", 352, 288 }, + { "4cif", 704, 576 }, + { "qqvga", 160, 120 }, + { "qvga", 320, 240 }, + { "vga", 640, 480 }, + { "svga", 800, 600 }, + { "xga", 1024, 768 }, + { "uxga", 1600,1200 }, + { "qxga", 2048,1536 }, + { "sxga", 1280,1024 }, + { "qsxga", 2560,2048 }, + { "hsxga", 5120,4096 }, + { "wvga", 852, 480 }, + { "wxga", 1366, 768 }, + { "wsxga", 1600,1024 }, + { "wuxga", 1920,1200 }, + { "woxga", 2560,1600 }, + { "wqsxga", 3200,2048 }, + { "wquxga", 3840,2400 }, + { "whsxga", 6400,4096 }, + { "whuxga", 7680,4800 }, + { "cga", 320, 200 }, + { "ega", 640, 350 }, + { "hd480", 852, 480 }, + { "hd720", 1280, 720 }, + { "hd1080", 1920,1080 }, +}; + +static VideoFrameRateAbbr video_frame_rate_abbrs[]= { + { "ntsc", 30000, 1001 }, + { "pal", 25, 1 }, + { "qntsc", 30000, 1001 }, /* VCD compliant NTSC */ + { "qpal", 25, 1 }, /* VCD compliant PAL */ + { "sntsc", 30000, 1001 }, /* square pixel NTSC */ + { "spal", 25, 1 }, /* square pixel PAL */ + { "film", 24, 1 }, + { "ntsc-film", 24000, 1001 }, +}; + +int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str) +{ + int i; + int n = sizeof(video_frame_size_abbrs) / sizeof(VideoFrameSizeAbbr); + const char *p; + int frame_width = 0, frame_height = 0; + + for(i=0;inum = video_frame_rate_abbrs[i].rate_num; + frame_rate->den = video_frame_rate_abbrs[i].rate_den; + return 0; + } + + /* Then, we try to parse it as fraction */ + cp = strchr(arg, '/'); + if (!cp) + cp = strchr(arg, ':'); + if (cp) { + char* cpp; + frame_rate->num = strtol(arg, &cpp, 10); + if (cpp != arg || cpp == cp) + frame_rate->den = strtol(cp+1, &cpp, 10); + else + frame_rate->num = 0; + } + else { + /* Finally we give up and parse it as double */ + AVRational time_base = av_d2q(strtod(arg, 0), DEFAULT_FRAME_RATE_BASE); + frame_rate->den = time_base.den; + frame_rate->num = time_base.num; + } + if (!frame_rate->num || !frame_rate->den) + return -1; + else + return 0; +} diff --git a/contrib/ffmpeg/libavcodec/vb.c b/contrib/ffmpeg/libavcodec/vb.c new file mode 100644 index 000000000..7a2e00705 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/vb.c @@ -0,0 +1,282 @@ +/* + * Beam Software VB decoder + * Copyright (c) 2007 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file vb.c + * VB Video decoder + */ + +#include +#include + +#include "avcodec.h" +#include "bytestream.h" + +enum VBFlags{ + VB_HAS_GMC = 0x01, + VB_HAS_AUDIO = 0x04, + VB_HAS_VIDEO = 0x08, + VB_HAS_PALETTE = 0x10, + VB_HAS_LENGTH = 0x20 +}; + +typedef struct VBDecContext { + AVCodecContext *avctx; + AVFrame pic; + + uint8_t *frame, *prev_frame; + uint32_t pal[256]; + const uint8_t *stream; +} VBDecContext; + +static const uint16_t vb_patterns[64] = { + 0x0660, 0xFF00, 0xCCCC, 0xF000, 0x8888, 0x000F, 0x1111, 0xFEC8, + 0x8CEF, 0x137F, 0xF731, 0xC800, 0x008C, 0x0013, 0x3100, 0xCC00, + 0x00CC, 0x0033, 0x3300, 0x0FF0, 0x6666, 0x00F0, 0x0F00, 0x2222, + 0x4444, 0xF600, 0x8CC8, 0x006F, 0x1331, 0x318C, 0xC813, 0x33CC, + 0x6600, 0x0CC0, 0x0066, 0x0330, 0xF900, 0xC88C, 0x009F, 0x3113, + 0x6000, 0x0880, 0x0006, 0x0110, 0xCC88, 0xFC00, 0x00CF, 0x88CC, + 0x003F, 0x1133, 0x3311, 0xF300, 0x6FF6, 0x0603, 0x08C6, 0x8C63, + 0xC631, 0x6310, 0xC060, 0x0136, 0x136C, 0x36C8, 0x6C80, 0x324C +}; + +static void vb_decode_palette(VBDecContext *c) +{ + int start, size, i; + + start = bytestream_get_byte(&c->stream); + size = (bytestream_get_byte(&c->stream) - 1) & 0xFF; + if(start + size > 255){ + av_log(c->avctx, AV_LOG_ERROR, "Palette change runs beyond entry 256\n"); + return; + } + for(i = start; i <= start + size; i++) + c->pal[i] = bytestream_get_be24(&c->stream); +} + +static inline int check_pixel(uint8_t *buf, uint8_t *start, uint8_t *end) +{ + return buf >= start && buf < end; +} + +static inline int check_line(uint8_t *buf, uint8_t *start, uint8_t *end) +{ + return buf >= start && (buf + 4) <= end; +} + +static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int offset) +{ + uint8_t *prev, *cur; + int blk, blocks, t, blk2; + int blocktypes = 0; + int x, y, a, b; + int pattype, pattern; + const int width = c->avctx->width; + uint8_t *pstart = c->prev_frame; + uint8_t *pend = c->prev_frame + width*c->avctx->height; + + prev = c->prev_frame + offset; + cur = c->frame; + + blocks = (c->avctx->width >> 2) * (c->avctx->height >> 2); + blk2 = 0; + for(blk = 0; blk < blocks; blk++){ + if(!(blk & 3)) + blocktypes = bytestream_get_byte(&buf); + switch(blocktypes & 0xC0){ + case 0x00: //skip + for(y = 0; y < 4; y++) + if(check_line(prev + y*width, pstart, pend)) + memcpy(cur + y*width, prev + y*width, 4); + else + memset(cur + y*width, 0, 4); + break; + case 0x40: + t = bytestream_get_byte(&buf); + if(!t){ //raw block + for(y = 0; y < 4; y++) + memcpy(cur + y*width, buf + y*4, 4); + buf += 16; + }else{ // motion compensation + x = ((t & 0xF)^8) - 8; + y = ((t >> 4) ^8) - 8; + t = x + y*width; + for(y = 0; y < 4; y++) + if(check_line(prev + t + y*width, pstart, pend)) + memcpy(cur + y*width, prev + t + y*width, 4); + else + memset(cur + y*width, 0, 4); + } + break; + case 0x80: // fill + t = bytestream_get_byte(&buf); + for(y = 0; y < 4; y++) + memset(cur + y*width, t, 4); + break; + case 0xC0: // pattern fill + t = bytestream_get_byte(&buf); + pattype = t >> 6; + pattern = vb_patterns[t & 0x3F]; + switch(pattype){ + case 0: + a = bytestream_get_byte(&buf); + b = bytestream_get_byte(&buf); + for(y = 0; y < 4; y++) + for(x = 0; x < 4; x++, pattern >>= 1) + cur[x + y*width] = (pattern & 1) ? b : a; + break; + case 1: + pattern = ~pattern; + case 2: + a = bytestream_get_byte(&buf); + for(y = 0; y < 4; y++) + for(x = 0; x < 4; x++, pattern >>= 1) + if(pattern & 1 && check_pixel(prev + x + y*width, pstart, pend)) + cur[x + y*width] = prev[x + y*width]; + else + cur[x + y*width] = a; + break; + case 3: + av_log(c->avctx, AV_LOG_ERROR, "Invalid opcode seen @%d\n",blk); + return -1; + } + break; + } + blocktypes <<= 2; + cur += 4; + prev += 4; + blk2++; + if(blk2 == (width >> 2)){ + blk2 = 0; + cur += width * 3; + prev += width * 3; + } + } + return 0; +} + +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size) +{ + VBDecContext * const c = avctx->priv_data; + uint8_t *outptr, *srcptr; + int i, j; + int flags; + uint32_t size; + int rest = buf_size; + int offset = 0; + + c->stream = buf; + flags = bytestream_get_le16(&c->stream); + rest -= 2; + + if(flags & VB_HAS_GMC){ + i = (int16_t)bytestream_get_le16(&c->stream); + j = (int16_t)bytestream_get_le16(&c->stream); + offset = i + j * avctx->width; + rest -= 4; + } + if(flags & VB_HAS_VIDEO){ + size = bytestream_get_le32(&c->stream); + if(size > rest){ + av_log(avctx, AV_LOG_ERROR, "Frame size is too big\n"); + return -1; + } + vb_decode_framedata(c, c->stream, offset); + c->stream += size - 4; + rest -= size; + } + if(flags & VB_HAS_PALETTE){ + size = bytestream_get_le32(&c->stream); + if(size > rest){ + av_log(avctx, AV_LOG_ERROR, "Palette size is too big\n"); + return -1; + } + vb_decode_palette(c); + rest -= size; + } + + memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE); + c->pic.palette_has_changed = flags & VB_HAS_PALETTE; + + outptr = c->pic.data[0]; + srcptr = c->frame; + + for(i = 0; i < avctx->height; i++){ + memcpy(outptr, srcptr, avctx->width); + srcptr += avctx->width; + outptr += c->pic.linesize[0]; + } + + FFSWAP(uint8_t*, c->frame, c->prev_frame); + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = c->pic; + + /* always report that the buffer was completely consumed */ + return buf_size; +} + +static int decode_init(AVCodecContext *avctx) +{ + VBDecContext * const c = avctx->priv_data; + + c->avctx = avctx; + avctx->pix_fmt = PIX_FMT_PAL8; + + if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) { + return -1; + } + + c->pic.reference = 1; + if(avctx->get_buffer(avctx, &c->pic) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + + c->frame = av_malloc( avctx->width * avctx->height); + c->prev_frame = av_malloc( avctx->width * avctx->height); + + return 0; +} + +static int decode_end(AVCodecContext *avctx) +{ + VBDecContext *c = avctx->priv_data; + + av_freep(&c->frame); + av_freep(&c->prev_frame); + if(c->pic.data[0]) + avctx->release_buffer(avctx, &c->pic); + + return 0; +} + +AVCodec vb_decoder = { + "vb", + CODEC_TYPE_VIDEO, + CODEC_ID_VB, + sizeof(VBDecContext), + decode_init, + NULL, + decode_end, + decode_frame +}; + diff --git a/contrib/ffmpeg/libavcodec/vc1.c b/contrib/ffmpeg/libavcodec/vc1.c index 84868904d..80eaca691 100644 --- a/contrib/ffmpeg/libavcodec/vc1.c +++ b/contrib/ffmpeg/libavcodec/vc1.c @@ -18,7 +18,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -26,421 +25,24 @@ * VC-1 and WMV3 decoder * */ -#include "common.h" #include "dsputil.h" #include "avcodec.h" #include "mpegvideo.h" +#include "vc1.h" #include "vc1data.h" #include "vc1acdata.h" +#include "msmpeg4data.h" +#include "unary.h" +#include "simple_idct.h" #undef NDEBUG #include -extern const uint32_t ff_table0_dc_lum[120][2], ff_table1_dc_lum[120][2]; -extern const uint32_t ff_table0_dc_chroma[120][2], ff_table1_dc_chroma[120][2]; -extern VLC ff_msmp4_dc_luma_vlc[2], ff_msmp4_dc_chroma_vlc[2]; #define MB_INTRA_VLC_BITS 9 -extern VLC ff_msmp4_mb_i_vlc; -extern const uint16_t ff_msmp4_mb_i_table[64][2]; #define DC_VLC_BITS 9 #define AC_VLC_BITS 9 static const uint16_t table_mb_intra[64][2]; -/** Markers used if VC-1 AP frame data */ -//@{ -enum VC1Code{ - VC1_CODE_RES0 = 0x00000100, - VC1_CODE_ENDOFSEQ = 0x0000010A, - VC1_CODE_SLICE, - VC1_CODE_FIELD, - VC1_CODE_FRAME, - VC1_CODE_ENTRYPOINT, - VC1_CODE_SEQHDR, -}; -//@} - -/** Available Profiles */ -//@{ -enum Profile { - PROFILE_SIMPLE, - PROFILE_MAIN, - PROFILE_COMPLEX, ///< TODO: WMV9 specific - PROFILE_ADVANCED -}; -//@} - -/** Sequence quantizer mode */ -//@{ -enum QuantMode { - QUANT_FRAME_IMPLICIT, ///< Implicitly specified at frame level - QUANT_FRAME_EXPLICIT, ///< Explicitly specified at frame level - QUANT_NON_UNIFORM, ///< Non-uniform quant used for all frames - QUANT_UNIFORM ///< Uniform quant used for all frames -}; -//@} - -/** Where quant can be changed */ -//@{ -enum DQProfile { - DQPROFILE_FOUR_EDGES, - DQPROFILE_DOUBLE_EDGES, - DQPROFILE_SINGLE_EDGE, - DQPROFILE_ALL_MBS -}; -//@} - -/** @name Where quant can be changed - */ -//@{ -enum DQSingleEdge { - DQSINGLE_BEDGE_LEFT, - DQSINGLE_BEDGE_TOP, - DQSINGLE_BEDGE_RIGHT, - DQSINGLE_BEDGE_BOTTOM -}; -//@} - -/** Which pair of edges is quantized with ALTPQUANT */ -//@{ -enum DQDoubleEdge { - DQDOUBLE_BEDGE_TOPLEFT, - DQDOUBLE_BEDGE_TOPRIGHT, - DQDOUBLE_BEDGE_BOTTOMRIGHT, - DQDOUBLE_BEDGE_BOTTOMLEFT -}; -//@} - -/** MV modes for P frames */ -//@{ -enum MVModes { - MV_PMODE_1MV_HPEL_BILIN, - MV_PMODE_1MV, - MV_PMODE_1MV_HPEL, - MV_PMODE_MIXED_MV, - MV_PMODE_INTENSITY_COMP -}; -//@} - -/** @name MV types for B frames */ -//@{ -enum BMVTypes { - BMV_TYPE_BACKWARD, - BMV_TYPE_FORWARD, - BMV_TYPE_INTERPOLATED -}; -//@} - -/** @name Block types for P/B frames */ -//@{ -enum TransformTypes { - TT_8X8, - TT_8X4_BOTTOM, - TT_8X4_TOP, - TT_8X4, //Both halves - TT_4X8_RIGHT, - TT_4X8_LEFT, - TT_4X8, //Both halves - TT_4X4 -}; -//@} - -/** Table for conversion between TTBLK and TTMB */ -static const int ttblk_to_tt[3][8] = { - { TT_8X4, TT_4X8, TT_8X8, TT_4X4, TT_8X4_TOP, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT }, - { TT_8X8, TT_4X8_RIGHT, TT_4X8_LEFT, TT_4X4, TT_8X4, TT_4X8, TT_8X4_BOTTOM, TT_8X4_TOP }, - { TT_8X8, TT_4X8, TT_4X4, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT, TT_8X4, TT_8X4_TOP } -}; - -static const int ttfrm_to_tt[4] = { TT_8X8, TT_8X4, TT_4X8, TT_4X4 }; - -/** MV P mode - the 5th element is only used for mode 1 */ -static const uint8_t mv_pmode_table[2][5] = { - { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_MIXED_MV }, - { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_1MV_HPEL_BILIN } -}; -static const uint8_t mv_pmode_table2[2][4] = { - { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_MIXED_MV }, - { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_1MV_HPEL_BILIN } -}; - -/** One more frame type */ -#define BI_TYPE 7 - -static const int fps_nr[5] = { 24, 25, 30, 50, 60 }, - fps_dr[2] = { 1000, 1001 }; -static const uint8_t pquant_table[3][32] = { - { /* Implicit quantizer */ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 6, 7, 8, 9, 10, 11, 12, - 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 29, 31 - }, - { /* Explicit quantizer, pquantizer uniform */ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 - }, - { /* Explicit quantizer, pquantizer non-uniform */ - 0, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 31 - } -}; - -/** @name VC-1 VLC tables and defines - * @todo TODO move this into the context - */ -//@{ -#define VC1_BFRACTION_VLC_BITS 7 -static VLC vc1_bfraction_vlc; -#define VC1_IMODE_VLC_BITS 4 -static VLC vc1_imode_vlc; -#define VC1_NORM2_VLC_BITS 3 -static VLC vc1_norm2_vlc; -#define VC1_NORM6_VLC_BITS 9 -static VLC vc1_norm6_vlc; -/* Could be optimized, one table only needs 8 bits */ -#define VC1_TTMB_VLC_BITS 9 //12 -static VLC vc1_ttmb_vlc[3]; -#define VC1_MV_DIFF_VLC_BITS 9 //15 -static VLC vc1_mv_diff_vlc[4]; -#define VC1_CBPCY_P_VLC_BITS 9 //14 -static VLC vc1_cbpcy_p_vlc[4]; -#define VC1_4MV_BLOCK_PATTERN_VLC_BITS 6 -static VLC vc1_4mv_block_pattern_vlc[4]; -#define VC1_TTBLK_VLC_BITS 5 -static VLC vc1_ttblk_vlc[3]; -#define VC1_SUBBLKPAT_VLC_BITS 6 -static VLC vc1_subblkpat_vlc[3]; - -static VLC vc1_ac_coeff_table[8]; -//@} - -enum CodingSet { - CS_HIGH_MOT_INTRA = 0, - CS_HIGH_MOT_INTER, - CS_LOW_MOT_INTRA, - CS_LOW_MOT_INTER, - CS_MID_RATE_INTRA, - CS_MID_RATE_INTER, - CS_HIGH_RATE_INTRA, - CS_HIGH_RATE_INTER -}; - -/** @name Overlap conditions for Advanced Profile */ -//@{ -enum COTypes { - CONDOVER_NONE = 0, - CONDOVER_ALL, - CONDOVER_SELECT -}; -//@} - - -/** The VC1 Context - * @fixme Change size wherever another size is more efficient - * Many members are only used for Advanced Profile - */ -typedef struct VC1Context{ - MpegEncContext s; - - int bits; - - /** Simple/Main Profile sequence header */ - //@{ - int res_sm; ///< reserved, 2b - int res_x8; ///< reserved - int multires; ///< frame-level RESPIC syntax element present - int res_fasttx; ///< reserved, always 1 - int res_transtab; ///< reserved, always 0 - int rangered; ///< RANGEREDFRM (range reduction) syntax element present - ///< at frame level - int res_rtm_flag; ///< reserved, set to 1 - int reserved; ///< reserved - //@} - - /** Advanced Profile */ - //@{ - int level; ///< 3bits, for Advanced/Simple Profile, provided by TS layer - int chromaformat; ///< 2bits, 2=4:2:0, only defined - int postprocflag; ///< Per-frame processing suggestion flag present - int broadcast; ///< TFF/RFF present - int interlace; ///< Progressive/interlaced (RPTFTM syntax element) - int tfcntrflag; ///< TFCNTR present - int panscanflag; ///< NUMPANSCANWIN, TOPLEFT{X,Y}, BOTRIGHT{X,Y} present - int extended_dmv; ///< Additional extended dmv range at P/B frame-level - int color_prim; ///< 8bits, chroma coordinates of the color primaries - int transfer_char; ///< 8bits, Opto-electronic transfer characteristics - int matrix_coef; ///< 8bits, Color primaries->YCbCr transform matrix - int hrd_param_flag; ///< Presence of Hypothetical Reference - ///< Decoder parameters - int psf; ///< Progressive Segmented Frame - //@} - - /** Sequence header data for all Profiles - * TODO: choose between ints, uint8_ts and monobit flags - */ - //@{ - int profile; ///< 2bits, Profile - int frmrtq_postproc; ///< 3bits, - int bitrtq_postproc; ///< 5bits, quantized framerate-based postprocessing strength - int fastuvmc; ///< Rounding of qpel vector to hpel ? (not in Simple) - int extended_mv; ///< Ext MV in P/B (not in Simple) - int dquant; ///< How qscale varies with MBs, 2bits (not in Simple) - int vstransform; ///< variable-size [48]x[48] transform type + info - int overlap; ///< overlapped transforms in use - int quantizer_mode; ///< 2bits, quantizer mode used for sequence, see QUANT_* - int finterpflag; ///< INTERPFRM present - //@} - - /** Frame decoding info for all profiles */ - //@{ - uint8_t mv_mode; ///< MV coding monde - uint8_t mv_mode2; ///< Secondary MV coding mode (B frames) - int k_x; ///< Number of bits for MVs (depends on MV range) - int k_y; ///< Number of bits for MVs (depends on MV range) - int range_x, range_y; ///< MV range - uint8_t pq, altpq; ///< Current/alternate frame quantizer scale - /** pquant parameters */ - //@{ - uint8_t dquantfrm; - uint8_t dqprofile; - uint8_t dqsbedge; - uint8_t dqbilevel; - //@} - /** AC coding set indexes - * @see 8.1.1.10, p(1)10 - */ - //@{ - int c_ac_table_index; ///< Chroma index from ACFRM element - int y_ac_table_index; ///< Luma index from AC2FRM element - //@} - int ttfrm; ///< Transform type info present at frame level - uint8_t ttmbf; ///< Transform type flag - uint8_t ttblk4x4; ///< Value of ttblk which indicates a 4x4 transform - int codingset; ///< index of current table set from 11.8 to use for luma block decoding - int codingset2; ///< index of current table set from 11.8 to use for chroma block decoding - int pqindex; ///< raw pqindex used in coding set selection - int a_avail, c_avail; - uint8_t *mb_type_base, *mb_type[3]; - - - /** Luma compensation parameters */ - //@{ - uint8_t lumscale; - uint8_t lumshift; - //@} - int16_t bfraction; ///< Relative position % anchors=> how to scale MVs - uint8_t halfpq; ///< Uniform quant over image and qp+.5 - uint8_t respic; ///< Frame-level flag for resized images - int buffer_fullness; ///< HRD info - /** Ranges: - * -# 0 -> [-64n 63.f] x [-32, 31.f] - * -# 1 -> [-128, 127.f] x [-64, 63.f] - * -# 2 -> [-512, 511.f] x [-128, 127.f] - * -# 3 -> [-1024, 1023.f] x [-256, 255.f] - */ - uint8_t mvrange; - uint8_t pquantizer; ///< Uniform (over sequence) quantizer in use - VLC *cbpcy_vlc; ///< CBPCY VLC table - int tt_index; ///< Index for Transform Type tables - uint8_t* mv_type_mb_plane; ///< bitplane for mv_type == (4MV) - uint8_t* direct_mb_plane; ///< bitplane for "direct" MBs - int mv_type_is_raw; ///< mv type mb plane is not coded - int dmb_is_raw; ///< direct mb plane is raw - int skip_is_raw; ///< skip mb plane is not coded - uint8_t luty[256], lutuv[256]; // lookup tables used for intensity compensation - int use_ic; ///< use intensity compensation in B-frames - int rnd; ///< rounding control - - /** Frame decoding info for S/M profiles only */ - //@{ - uint8_t rangeredfrm; ///< out_sample = CLIP((in_sample-128)*2+128) - uint8_t interpfrm; - //@} - - /** Frame decoding info for Advanced profile */ - //@{ - uint8_t fcm; ///< 0->Progressive, 2->Frame-Interlace, 3->Field-Interlace - uint8_t numpanscanwin; - uint8_t tfcntr; - uint8_t rptfrm, tff, rff; - uint16_t topleftx; - uint16_t toplefty; - uint16_t bottomrightx; - uint16_t bottomrighty; - uint8_t uvsamp; - uint8_t postproc; - int hrd_num_leaky_buckets; - uint8_t bit_rate_exponent; - uint8_t buffer_size_exponent; - uint8_t* acpred_plane; ///< AC prediction flags bitplane - int acpred_is_raw; - uint8_t* over_flags_plane; ///< Overflags bitplane - int overflg_is_raw; - uint8_t condover; - uint16_t *hrd_rate, *hrd_buffer; - uint8_t *hrd_fullness; - uint8_t range_mapy_flag; - uint8_t range_mapuv_flag; - uint8_t range_mapy; - uint8_t range_mapuv; - //@} - - int p_frame_skipped; - int bi_type; -} VC1Context; - -/** - * Get unary code of limited length - * @fixme FIXME Slow and ugly - * @param gb GetBitContext - * @param[in] stop The bitstop value (unary code of 1's or 0's) - * @param[in] len Maximum length - * @return Unary length/index - */ -static int get_prefix(GetBitContext *gb, int stop, int len) -{ -#if 1 - int i; - - for(i = 0; i < len && get_bits1(gb) != stop; i++); - return i; -/* int i = 0, tmp = !stop; - - while (i != len && tmp != stop) - { - tmp = get_bits(gb, 1); - i++; - } - if (i == len && tmp != stop) return len+1; - return i;*/ -#else - unsigned int buf; - int log; - - OPEN_READER(re, gb); - UPDATE_CACHE(re, gb); - buf=GET_CACHE(re, gb); //Still not sure - if (stop) buf = ~buf; - - log= av_log2(-buf); //FIXME: -? - if (log < limit){ - LAST_SKIP_BITS(re, gb, log+1); - CLOSE_READER(re, gb); - return log; - } - - LAST_SKIP_BITS(re, gb, limit); - CLOSE_READER(re, gb); - return limit; -#endif -} - -static inline int decode210(GetBitContext *gb){ - int n; - n = get_bits1(gb); - if (n == 1) - return 0; - else - return 2 - get_bits1(gb); -} /** * Init VC-1 specific tables and VC1Context members @@ -458,44 +60,44 @@ static int vc1_init_common(VC1Context *v) if(!done) { done = 1; - init_vlc(&vc1_bfraction_vlc, VC1_BFRACTION_VLC_BITS, 23, - vc1_bfraction_bits, 1, 1, - vc1_bfraction_codes, 1, 1, 1); - init_vlc(&vc1_norm2_vlc, VC1_NORM2_VLC_BITS, 4, - vc1_norm2_bits, 1, 1, - vc1_norm2_codes, 1, 1, 1); - init_vlc(&vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 64, - vc1_norm6_bits, 1, 1, - vc1_norm6_codes, 2, 2, 1); - init_vlc(&vc1_imode_vlc, VC1_IMODE_VLC_BITS, 7, - vc1_imode_bits, 1, 1, - vc1_imode_codes, 1, 1, 1); + init_vlc(&ff_vc1_bfraction_vlc, VC1_BFRACTION_VLC_BITS, 23, + ff_vc1_bfraction_bits, 1, 1, + ff_vc1_bfraction_codes, 1, 1, 1); + init_vlc(&ff_vc1_norm2_vlc, VC1_NORM2_VLC_BITS, 4, + ff_vc1_norm2_bits, 1, 1, + ff_vc1_norm2_codes, 1, 1, 1); + init_vlc(&ff_vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 64, + ff_vc1_norm6_bits, 1, 1, + ff_vc1_norm6_codes, 2, 2, 1); + init_vlc(&ff_vc1_imode_vlc, VC1_IMODE_VLC_BITS, 7, + ff_vc1_imode_bits, 1, 1, + ff_vc1_imode_codes, 1, 1, 1); for (i=0; i<3; i++) { - init_vlc(&vc1_ttmb_vlc[i], VC1_TTMB_VLC_BITS, 16, - vc1_ttmb_bits[i], 1, 1, - vc1_ttmb_codes[i], 2, 2, 1); - init_vlc(&vc1_ttblk_vlc[i], VC1_TTBLK_VLC_BITS, 8, - vc1_ttblk_bits[i], 1, 1, - vc1_ttblk_codes[i], 1, 1, 1); - init_vlc(&vc1_subblkpat_vlc[i], VC1_SUBBLKPAT_VLC_BITS, 15, - vc1_subblkpat_bits[i], 1, 1, - vc1_subblkpat_codes[i], 1, 1, 1); + init_vlc(&ff_vc1_ttmb_vlc[i], VC1_TTMB_VLC_BITS, 16, + ff_vc1_ttmb_bits[i], 1, 1, + ff_vc1_ttmb_codes[i], 2, 2, 1); + init_vlc(&ff_vc1_ttblk_vlc[i], VC1_TTBLK_VLC_BITS, 8, + ff_vc1_ttblk_bits[i], 1, 1, + ff_vc1_ttblk_codes[i], 1, 1, 1); + init_vlc(&ff_vc1_subblkpat_vlc[i], VC1_SUBBLKPAT_VLC_BITS, 15, + ff_vc1_subblkpat_bits[i], 1, 1, + ff_vc1_subblkpat_codes[i], 1, 1, 1); } for(i=0; i<4; i++) { - init_vlc(&vc1_4mv_block_pattern_vlc[i], VC1_4MV_BLOCK_PATTERN_VLC_BITS, 16, - vc1_4mv_block_pattern_bits[i], 1, 1, - vc1_4mv_block_pattern_codes[i], 1, 1, 1); - init_vlc(&vc1_cbpcy_p_vlc[i], VC1_CBPCY_P_VLC_BITS, 64, - vc1_cbpcy_p_bits[i], 1, 1, - vc1_cbpcy_p_codes[i], 2, 2, 1); - init_vlc(&vc1_mv_diff_vlc[i], VC1_MV_DIFF_VLC_BITS, 73, - vc1_mv_diff_bits[i], 1, 1, - vc1_mv_diff_codes[i], 2, 2, 1); + init_vlc(&ff_vc1_4mv_block_pattern_vlc[i], VC1_4MV_BLOCK_PATTERN_VLC_BITS, 16, + ff_vc1_4mv_block_pattern_bits[i], 1, 1, + ff_vc1_4mv_block_pattern_codes[i], 1, 1, 1); + init_vlc(&ff_vc1_cbpcy_p_vlc[i], VC1_CBPCY_P_VLC_BITS, 64, + ff_vc1_cbpcy_p_bits[i], 1, 1, + ff_vc1_cbpcy_p_codes[i], 2, 2, 1); + init_vlc(&ff_vc1_mv_diff_vlc[i], VC1_MV_DIFF_VLC_BITS, 73, + ff_vc1_mv_diff_bits[i], 1, 1, + ff_vc1_mv_diff_codes[i], 2, 2, 1); } for(i=0; i<8; i++) - init_vlc(&vc1_ac_coeff_table[i], AC_VLC_BITS, vc1_ac_sizes[i], + init_vlc(&ff_vc1_ac_coeff_table[i], AC_VLC_BITS, vc1_ac_sizes[i], &vc1_ac_tables[i][0][1], 8, 4, &vc1_ac_tables[i][0][0], 8, 4, 1); init_vlc(&ff_msmp4_mb_i_vlc, MB_INTRA_VLC_BITS, 64, @@ -542,11 +144,11 @@ static void decode_rowskip(uint8_t* plane, int width, int height, int stride, Ge int x, y; for (y=0; ys.mb_width; height = v->s.mb_height; stride = v->s.mb_stride; - invert = get_bits(gb, 1); - imode = get_vlc2(gb, vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1); + invert = get_bits1(gb); + imode = get_vlc2(gb, ff_vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1); *raw_flag = 0; switch (imode) @@ -603,13 +205,13 @@ static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v) case IMODE_NORM2: if ((height * width) & 1) { - *planep++ = get_bits(gb, 1); + *planep++ = get_bits1(gb); offset = 1; } else offset = 0; // decode bitplane as one long line for (y = offset; y < height * width; y += 2) { - code = get_vlc2(gb, vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1); + code = get_vlc2(gb, ff_vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1); *planep++ = code & 1; offset++; if(offset == width) { @@ -629,7 +231,7 @@ static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v) if(!(height % 3) && (width % 3)) { // use 2x3 decoding for(y = 0; y < height; y+= 3) { for(x = width & 1; x < width; x += 2) { - code = get_vlc2(gb, vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2); + code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2); if(code < 0){ av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n"); return -1; @@ -648,7 +250,7 @@ static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v) planep += (height & 1) * stride; for(y = height & 1; y < height; y += 2) { for(x = width % 3; x < width; x += 3) { - code = get_vlc2(gb, vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2); + code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2); if(code < 0){ av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n"); return -1; @@ -722,7 +324,7 @@ static int vop_dquant_decoding(VC1Context *v) } else { - v->dquantfrm = get_bits(gb, 1); + v->dquantfrm = get_bits1(gb); if ( v->dquantfrm ) { v->dqprofile = get_bits(gb, 2); @@ -733,7 +335,9 @@ static int vop_dquant_decoding(VC1Context *v) v->dqsbedge = get_bits(gb, 2); break; case DQPROFILE_ALL_MBS: - v->dqbilevel = get_bits(gb, 1); + v->dqbilevel = get_bits1(gb); + if(!v->dqbilevel) + v->halfpq = 0; default: break; //Forbidden ? } if (v->dqbilevel || v->dqprofile != DQPROFILE_ALL_MBS) @@ -1173,10 +777,14 @@ static int decode_sequence_header(AVCodecContext *avctx, GetBitContext *gb) if (v->profile == PROFILE_ADVANCED) { + v->zz_8x4 = ff_vc1_adv_progressive_8x4_zz; + v->zz_4x8 = ff_vc1_adv_progressive_4x8_zz; return decode_sequence_header_adv(v, gb); } else { + v->zz_8x4 = ff_vc1_simple_progressive_8x4_zz; + v->zz_4x8 = ff_vc1_simple_progressive_4x8_zz; v->res_sm = get_bits(gb, 2); //reserved if (v->res_sm) { @@ -1190,37 +798,32 @@ static int decode_sequence_header(AVCodecContext *avctx, GetBitContext *gb) v->frmrtq_postproc = get_bits(gb, 3); //common // (bitrate-32kbps)/64kbps v->bitrtq_postproc = get_bits(gb, 5); //common - v->s.loop_filter = get_bits(gb, 1); //common + v->s.loop_filter = get_bits1(gb); //common if(v->s.loop_filter == 1 && v->profile == PROFILE_SIMPLE) { av_log(avctx, AV_LOG_ERROR, "LOOPFILTER shell not be enabled in simple profile\n"); } - v->res_x8 = get_bits(gb, 1); //reserved - if (v->res_x8) - { - av_log(avctx, AV_LOG_ERROR, - "1 for reserved RES_X8 is forbidden\n"); - //return -1; - } - v->multires = get_bits(gb, 1); - v->res_fasttx = get_bits(gb, 1); + v->res_x8 = get_bits1(gb); //reserved + v->multires = get_bits1(gb); + v->res_fasttx = get_bits1(gb); if (!v->res_fasttx) { - av_log(avctx, AV_LOG_ERROR, - "0 for reserved RES_FASTTX is forbidden\n"); - //return -1; + v->s.dsp.vc1_inv_trans_8x8 = ff_simple_idct; + v->s.dsp.vc1_inv_trans_8x4 = ff_simple_idct84_add; + v->s.dsp.vc1_inv_trans_4x8 = ff_simple_idct48_add; + v->s.dsp.vc1_inv_trans_4x4 = ff_simple_idct44_add; } - v->fastuvmc = get_bits(gb, 1); //common + v->fastuvmc = get_bits1(gb); //common if (!v->profile && !v->fastuvmc) { av_log(avctx, AV_LOG_ERROR, "FASTUVMC unavailable in Simple Profile\n"); return -1; } - v->extended_mv = get_bits(gb, 1); //common + v->extended_mv = get_bits1(gb); //common if (!v->profile && v->extended_mv) { av_log(avctx, AV_LOG_ERROR, @@ -1228,9 +831,9 @@ static int decode_sequence_header(AVCodecContext *avctx, GetBitContext *gb) return -1; } v->dquant = get_bits(gb, 2); //common - v->vstransform = get_bits(gb, 1); //common + v->vstransform = get_bits1(gb); //common - v->res_transtab = get_bits(gb, 1); + v->res_transtab = get_bits1(gb); if (v->res_transtab) { av_log(avctx, AV_LOG_ERROR, @@ -1238,10 +841,10 @@ static int decode_sequence_header(AVCodecContext *avctx, GetBitContext *gb) return -1; } - v->overlap = get_bits(gb, 1); //common + v->overlap = get_bits1(gb); //common - v->s.resync_marker = get_bits(gb, 1); - v->rangered = get_bits(gb, 1); + v->s.resync_marker = get_bits1(gb); + v->rangered = get_bits1(gb); if (v->rangered && v->profile == PROFILE_SIMPLE) { av_log(avctx, AV_LOG_INFO, @@ -1251,8 +854,8 @@ static int decode_sequence_header(AVCodecContext *avctx, GetBitContext *gb) v->s.max_b_frames = avctx->max_b_frames = get_bits(gb, 3); //common v->quantizer_mode = get_bits(gb, 2); //common - v->finterpflag = get_bits(gb, 1); //common - v->res_rtm_flag = get_bits(gb, 1); //reserved + v->finterpflag = get_bits1(gb); //common + v->res_rtm_flag = get_bits1(gb); //reserved if (!v->res_rtm_flag) { // av_log(avctx, AV_LOG_ERROR, @@ -1296,7 +899,7 @@ static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb) v->frmrtq_postproc = get_bits(gb, 3); //common // (bitrate-32kbps)/64kbps v->bitrtq_postproc = get_bits(gb, 5); //common - v->postprocflag = get_bits(gb, 1); //common + v->postprocflag = get_bits1(gb); //common v->s.avctx->coded_width = (get_bits(gb, 12) + 1) << 1; v->s.avctx->coded_height = (get_bits(gb, 12) + 1) << 1; @@ -1306,7 +909,7 @@ static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb) v->interlace = get_bits1(gb); v->tfcntrflag = get_bits1(gb); v->finterpflag = get_bits1(gb); - get_bits1(gb); // reserved + skip_bits1(gb); // reserved v->s.h_edge_pos = v->s.avctx->coded_width; v->s.v_edge_pos = v->s.avctx->coded_height; @@ -1335,7 +938,7 @@ static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb) if(get_bits1(gb)) ar = get_bits(gb, 4); if(ar && ar < 14){ - v->s.avctx->sample_aspect_ratio = vc1_pixel_aspect[ar]; + v->s.avctx->sample_aspect_ratio = ff_vc1_pixel_aspect[ar]; }else if(ar == 15){ w = get_bits(gb, 8); h = get_bits(gb, 8); @@ -1351,8 +954,8 @@ static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb) nr = get_bits(gb, 8); dr = get_bits(gb, 4); if(nr && nr < 8 && dr && dr < 3){ - v->s.avctx->time_base.num = fps_dr[dr - 1]; - v->s.avctx->time_base.den = fps_nr[nr - 1] * 1000; + v->s.avctx->time_base.num = ff_vc1_fps_dr[dr - 1]; + v->s.avctx->time_base.den = ff_vc1_fps_nr[nr - 1] * 1000; } } } @@ -1368,11 +971,11 @@ static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb) if(v->hrd_param_flag) { int i; v->hrd_num_leaky_buckets = get_bits(gb, 5); - get_bits(gb, 4); //bitrate exponent - get_bits(gb, 4); //buffer size exponent + skip_bits(gb, 4); //bitrate exponent + skip_bits(gb, 4); //buffer size exponent for(i = 0; i < v->hrd_num_leaky_buckets; i++) { - get_bits(gb, 16); //hrd_rate[n] - get_bits(gb, 16); //hrd_buffer[n] + skip_bits(gb, 16); //hrd_rate[n] + skip_bits(gb, 16); //hrd_buffer[n] } } return 0; @@ -1398,7 +1001,7 @@ static int decode_entry_point(AVCodecContext *avctx, GetBitContext *gb) if(v->hrd_param_flag){ for(i = 0; i < v->hrd_num_leaky_buckets; i++) { - get_bits(gb, 8); //hrd_full[n] + skip_bits(gb, 8); //hrd_full[n] } } @@ -1431,28 +1034,28 @@ static int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb) { int pqindex, lowquant, status; - if(v->finterpflag) v->interpfrm = get_bits(gb, 1); + if(v->finterpflag) v->interpfrm = get_bits1(gb); skip_bits(gb, 2); //framecnt unused v->rangeredfrm = 0; - if (v->rangered) v->rangeredfrm = get_bits(gb, 1); - v->s.pict_type = get_bits(gb, 1); + if (v->rangered) v->rangeredfrm = get_bits1(gb); + v->s.pict_type = get_bits1(gb); if (v->s.avctx->max_b_frames) { if (!v->s.pict_type) { - if (get_bits(gb, 1)) v->s.pict_type = I_TYPE; + if (get_bits1(gb)) v->s.pict_type = I_TYPE; else v->s.pict_type = B_TYPE; } else v->s.pict_type = P_TYPE; } else v->s.pict_type = v->s.pict_type ? P_TYPE : I_TYPE; v->bi_type = 0; if(v->s.pict_type == B_TYPE) { - v->bfraction = get_vlc2(gb, vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1); - v->bfraction = vc1_bfraction_lut[v->bfraction]; + v->bfraction = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1); + v->bfraction = ff_vc1_bfraction_lut[v->bfraction]; if(v->bfraction == 0) { v->s.pict_type = BI_TYPE; } } if(v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE) - get_bits(gb, 7); // skip buffer fullness + skip_bits(gb, 7); // skip buffer fullness /* calculate RND */ if(v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE) @@ -1462,10 +1065,11 @@ static int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb) /* Quantizer stuff */ pqindex = get_bits(gb, 5); + if(!pqindex) return -1; if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) - v->pq = pquant_table[0][pqindex]; + v->pq = ff_vc1_pquant_table[0][pqindex]; else - v->pq = pquant_table[1][pqindex]; + v->pq = ff_vc1_pquant_table[1][pqindex]; v->pquantizer = 1; if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) @@ -1473,26 +1077,26 @@ static int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb) if (v->quantizer_mode == QUANT_NON_UNIFORM) v->pquantizer = 0; v->pqindex = pqindex; - if (pqindex < 9) v->halfpq = get_bits(gb, 1); + if (pqindex < 9) v->halfpq = get_bits1(gb); else v->halfpq = 0; if (v->quantizer_mode == QUANT_FRAME_EXPLICIT) - v->pquantizer = get_bits(gb, 1); + v->pquantizer = get_bits1(gb); v->dquantfrm = 0; - if (v->extended_mv == 1) v->mvrange = get_prefix(gb, 0, 3); + if (v->extended_mv == 1) v->mvrange = get_unary(gb, 0, 3); v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13 v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11 v->range_x = 1 << (v->k_x - 1); v->range_y = 1 << (v->k_y - 1); if (v->profile == PROFILE_ADVANCED) { - if (v->postprocflag) v->postproc = get_bits(gb, 1); + if (v->postprocflag) v->postproc = get_bits1(gb); } else if (v->multires && v->s.pict_type != B_TYPE) v->respic = get_bits(gb, 2); if(v->res_x8 && (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE)){ - if(get_bits1(gb))return -1; - } + v->x8_type = get_bits1(gb); + }else v->x8_type = 0; //av_log(v->s.avctx, AV_LOG_INFO, "%c Frame: QP=[%i]%i (+%i/2) %i\n", // (v->s.pict_type == P_TYPE) ? 'P' : ((v->s.pict_type == I_TYPE) ? 'I' : 'B'), pqindex, v->pq, v->halfpq, v->rangeredfrm); @@ -1505,11 +1109,11 @@ static int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb) else v->tt_index = 2; lowquant = (v->pq > 12) ? 0 : 1; - v->mv_mode = mv_pmode_table[lowquant][get_prefix(gb, 1, 4)]; + v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)]; if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { int scale, shift, i; - v->mv_mode2 = mv_pmode_table2[lowquant][get_prefix(gb, 1, 3)]; + v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)]; v->lumscale = get_bits(gb, 6); v->lumshift = get_bits(gb, 6); v->use_ic = 1; @@ -1560,8 +1164,8 @@ static int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb) "Imode: %i, Invert: %i\n", status>>1, status&1); /* Hopefully this is correct for P frames */ - v->s.mv_table_index = get_bits(gb, 2); //but using vc1_ tables - v->cbpcy_vlc = &vc1_cbpcy_p_vlc[get_bits(gb, 2)]; + v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables + v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)]; if (v->dquant) { @@ -1572,10 +1176,10 @@ static int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb) v->ttfrm = 0; //FIXME Is that so ? if (v->vstransform) { - v->ttmbf = get_bits(gb, 1); + v->ttmbf = get_bits1(gb); if (v->ttmbf) { - v->ttfrm = ttfrm_to_tt[get_bits(gb, 2)]; + v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)]; } } else { v->ttmbf = 1; @@ -1602,7 +1206,7 @@ static int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb) "Imode: %i, Invert: %i\n", status>>1, status&1); v->s.mv_table_index = get_bits(gb, 2); - v->cbpcy_vlc = &vc1_cbpcy_p_vlc[get_bits(gb, 2)]; + v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)]; if (v->dquant) { @@ -1613,10 +1217,10 @@ static int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb) v->ttfrm = 0; if (v->vstransform) { - v->ttmbf = get_bits(gb, 1); + v->ttmbf = get_bits1(gb); if (v->ttmbf) { - v->ttfrm = ttfrm_to_tt[get_bits(gb, 2)]; + v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)]; } } else { v->ttmbf = 1; @@ -1625,14 +1229,17 @@ static int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb) break; } - /* AC Syntax */ - v->c_ac_table_index = decode012(gb); - if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE) + if(!v->x8_type) { - v->y_ac_table_index = decode012(gb); + /* AC Syntax */ + v->c_ac_table_index = decode012(gb); + if (v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE) + { + v->y_ac_table_index = decode012(gb); + } + /* DC Syntax */ + v->s.dc_table_index = get_bits1(gb); } - /* DC Syntax */ - v->s.dc_table_index = get_bits(gb, 1); if(v->s.pict_type == BI_TYPE) { v->s.pict_type = B_TYPE; @@ -1652,7 +1259,7 @@ static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) v->fcm = decode012(gb); if(v->fcm) return -1; // interlaced frames/fields are not implemented } - switch(get_prefix(gb, 0, 4)) { + switch(get_unary(gb, 0, 4)) { case 0: v->s.pict_type = P_TYPE; break; @@ -1671,7 +1278,7 @@ static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) return 0; } if(v->tfcntrflag) - get_bits(gb, 8); + skip_bits(gb, 8); if(v->broadcast) { if(!v->interlace || v->psf) { v->rptfrm = get_bits(gb, 2); @@ -1686,20 +1293,21 @@ static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) v->rnd = get_bits1(gb); if(v->interlace) v->uvsamp = get_bits1(gb); - if(v->finterpflag) v->interpfrm = get_bits(gb, 1); + if(v->finterpflag) v->interpfrm = get_bits1(gb); if(v->s.pict_type == B_TYPE) { - v->bfraction = get_vlc2(gb, vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1); - v->bfraction = vc1_bfraction_lut[v->bfraction]; + v->bfraction = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1); + v->bfraction = ff_vc1_bfraction_lut[v->bfraction]; if(v->bfraction == 0) { v->s.pict_type = BI_TYPE; /* XXX: should not happen here */ } } pqindex = get_bits(gb, 5); + if(!pqindex) return -1; v->pqindex = pqindex; if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) - v->pq = pquant_table[0][pqindex]; + v->pq = ff_vc1_pquant_table[0][pqindex]; else - v->pq = pquant_table[1][pqindex]; + v->pq = ff_vc1_pquant_table[1][pqindex]; v->pquantizer = 1; if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) @@ -1707,10 +1315,10 @@ static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) if (v->quantizer_mode == QUANT_NON_UNIFORM) v->pquantizer = 0; v->pqindex = pqindex; - if (pqindex < 9) v->halfpq = get_bits(gb, 1); + if (pqindex < 9) v->halfpq = get_bits1(gb); else v->halfpq = 0; if (v->quantizer_mode == QUANT_FRAME_EXPLICIT) - v->pquantizer = get_bits(gb, 1); + v->pquantizer = get_bits1(gb); if(v->s.pict_type == I_TYPE || v->s.pict_type == P_TYPE) v->use_ic = 0; @@ -1735,7 +1343,7 @@ static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) case P_TYPE: if(v->postprocflag) v->postproc = get_bits1(gb); - if (v->extended_mv) v->mvrange = get_prefix(gb, 0, 3); + if (v->extended_mv) v->mvrange = get_unary(gb, 0, 3); else v->mvrange = 0; v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13 v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11 @@ -1747,11 +1355,11 @@ static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) else v->tt_index = 2; lowquant = (v->pq > 12) ? 0 : 1; - v->mv_mode = mv_pmode_table[lowquant][get_prefix(gb, 1, 4)]; + v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)]; if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { int scale, shift, i; - v->mv_mode2 = mv_pmode_table2[lowquant][get_prefix(gb, 1, 3)]; + v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)]; v->lumscale = get_bits(gb, 6); v->lumshift = get_bits(gb, 6); /* fill lookup tables for intensity compensation */ @@ -1802,8 +1410,8 @@ static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) "Imode: %i, Invert: %i\n", status>>1, status&1); /* Hopefully this is correct for P frames */ - v->s.mv_table_index = get_bits(gb, 2); //but using vc1_ tables - v->cbpcy_vlc = &vc1_cbpcy_p_vlc[get_bits(gb, 2)]; + v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables + v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)]; if (v->dquant) { av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n"); @@ -1813,10 +1421,10 @@ static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) v->ttfrm = 0; //FIXME Is that so ? if (v->vstransform) { - v->ttmbf = get_bits(gb, 1); + v->ttmbf = get_bits1(gb); if (v->ttmbf) { - v->ttfrm = ttfrm_to_tt[get_bits(gb, 2)]; + v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)]; } } else { v->ttmbf = 1; @@ -1826,7 +1434,7 @@ static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) case B_TYPE: if(v->postprocflag) v->postproc = get_bits1(gb); - if (v->extended_mv) v->mvrange = get_prefix(gb, 0, 3); + if (v->extended_mv) v->mvrange = get_unary(gb, 0, 3); else v->mvrange = 0; v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13 v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11 @@ -1852,7 +1460,7 @@ static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) "Imode: %i, Invert: %i\n", status>>1, status&1); v->s.mv_table_index = get_bits(gb, 2); - v->cbpcy_vlc = &vc1_cbpcy_p_vlc[get_bits(gb, 2)]; + v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)]; if (v->dquant) { @@ -1863,10 +1471,10 @@ static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) v->ttfrm = 0; if (v->vstransform) { - v->ttmbf = get_bits(gb, 1); + v->ttmbf = get_bits1(gb); if (v->ttmbf) { - v->ttfrm = ttfrm_to_tt[get_bits(gb, 2)]; + v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)]; } } else { v->ttmbf = 1; @@ -1882,7 +1490,7 @@ static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) v->y_ac_table_index = decode012(gb); } /* DC Syntax */ - v->s.dc_table_index = get_bits(gb, 1); + v->s.dc_table_index = get_bits1(gb); if ((v->s.pict_type == I_TYPE || v->s.pict_type == BI_TYPE) && v->dquant) { av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n"); vop_dquant_decoding(v); @@ -1915,7 +1523,7 @@ static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) { \ if (v->dqbilevel) \ { \ - mquant = (get_bits(gb, 1)) ? v->altpq : v->pq; \ + mquant = (get_bits1(gb)) ? v->altpq : v->pq; \ } \ else \ { \ @@ -1948,7 +1556,7 @@ static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) * @param _dmv_y Vertical differential for decoded MV */ #define GET_MVDATA(_dmv_x, _dmv_y) \ - index = 1 + get_vlc2(gb, vc1_mv_diff_vlc[s->mv_table_index].table,\ + index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index].table,\ VC1_MV_DIFF_VLC_BITS, 2); \ if (index > 36) \ { \ @@ -2304,6 +1912,12 @@ static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int s->mv[0][0][1] = scale_mv(s->next_picture.motion_val[1][xy][1], v->bfraction, 0, s->quarter_sample); s->mv[1][0][0] = scale_mv(s->next_picture.motion_val[1][xy][0], v->bfraction, 1, s->quarter_sample); s->mv[1][0][1] = scale_mv(s->next_picture.motion_val[1][xy][1], v->bfraction, 1, s->quarter_sample); + + /* Pullback predicted motion vectors as specified in 8.4.5.4 */ + s->mv[0][0][0] = av_clip(s->mv[0][0][0], -60 - (s->mb_x << 6), (s->mb_width << 6) - 4 - (s->mb_x << 6)); + s->mv[0][0][1] = av_clip(s->mv[0][0][1], -60 - (s->mb_y << 6), (s->mb_height << 6) - 4 - (s->mb_y << 6)); + s->mv[1][0][0] = av_clip(s->mv[1][0][0], -60 - (s->mb_x << 6), (s->mb_width << 6) - 4 - (s->mb_x << 6)); + s->mv[1][0][1] = av_clip(s->mv[1][0][1], -60 - (s->mb_y << 6), (s->mb_height << 6) - 4 - (s->mb_y << 6)); if(direct) { s->current_picture.motion_val[0][xy][0] = s->mv[0][0][0]; s->current_picture.motion_val[0][xy][1] = s->mv[0][0][1]; @@ -2318,6 +1932,7 @@ static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2; B = s->current_picture.motion_val[0][xy - wrap*2 + off]; + if(!s->mb_x) C[0] = C[1] = 0; if(!s->first_slice_line) { // predictor A is not out of bounds if(s->mb_width == 1) { px = A[0]; @@ -2395,6 +2010,7 @@ static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2; B = s->current_picture.motion_val[1][xy - wrap*2 + off]; + if(!s->mb_x) C[0] = C[1] = 0; if(!s->first_slice_line) { // predictor A is not out of bounds if(s->mb_width == 1) { px = A[0]; @@ -2567,12 +2183,12 @@ static inline int vc1_pred_dc(MpegEncContext *s, int overlap, int pq, int n, if(c_avail && (n!= 1 && n!=3)) { q2 = s->current_picture.qscale_table[mb_pos - 1]; if(q2 && q2 != q1) - c = (c * s->y_dc_scale_table[q2] * vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18; + c = (c * s->y_dc_scale_table[q2] * ff_vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18; } if(a_avail && (n!= 2 && n!=3)) { q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride]; if(q2 && q2 != q1) - a = (a * s->y_dc_scale_table[q2] * vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18; + a = (a * s->y_dc_scale_table[q2] * ff_vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18; } if(a_avail && c_avail && (n!=3)) { int off = mb_pos; @@ -2580,7 +2196,7 @@ static inline int vc1_pred_dc(MpegEncContext *s, int overlap, int pq, int n, if(n != 2) off -= s->mb_stride; q2 = s->current_picture.qscale_table[off]; if(q2 && q2 != q1) - b = (b * s->y_dc_scale_table[q2] * vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18; + b = (b * s->y_dc_scale_table[q2] * ff_vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18; } if(a_avail && c_avail) { @@ -2653,17 +2269,17 @@ static void vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip, int *value, GetBitContext *gb = &v->s.gb; int index, escape, run = 0, level = 0, lst = 0; - index = get_vlc2(gb, vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3); + index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3); if (index != vc1_ac_sizes[codingset] - 1) { run = vc1_index_decode_table[codingset][index][0]; level = vc1_index_decode_table[codingset][index][1]; lst = index >= vc1_last_decode_table[codingset]; - if(get_bits(gb, 1)) + if(get_bits1(gb)) level = -level; } else { escape = decode210(gb); if (escape != 2) { - index = get_vlc2(gb, vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3); + index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3); run = vc1_index_decode_table[codingset][index][0]; level = vc1_index_decode_table[codingset][index][1]; lst = index >= vc1_last_decode_table[codingset]; @@ -2678,23 +2294,23 @@ static void vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip, int *value, else run += vc1_delta_run_table[codingset][level] + 1; } - if(get_bits(gb, 1)) + if(get_bits1(gb)) level = -level; } else { int sign; - lst = get_bits(gb, 1); + lst = get_bits1(gb); if(v->s.esc3_level_length == 0) { if(v->pq < 8 || v->dquantfrm) { // table 59 v->s.esc3_level_length = get_bits(gb, 3); if(!v->s.esc3_level_length) v->s.esc3_level_length = get_bits(gb, 2) + 8; } else { //table 60 - v->s.esc3_level_length = get_prefix(gb, 1, 6) + 2; + v->s.esc3_level_length = get_unary(gb, 1, 6) + 2; } v->s.esc3_run_length = 3 + get_bits(gb, 2); } run = get_bits(gb, v->s.esc3_run_length); - sign = get_bits(gb, 1); + sign = get_bits1(gb); level = get_bits(gb, v->s.esc3_level_length); if(sign) level = -level; @@ -2746,9 +2362,9 @@ static int vc1_decode_i_block(VC1Context *v, DCTELEM block[64], int n, int coded if (v->pq == 1) dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3; else if (v->pq == 2) - dcdiff = (dcdiff<<1) + get_bits(gb, 1) - 1; + dcdiff = (dcdiff<<1) + get_bits1(gb) - 1; } - if (get_bits(gb, 1)) + if (get_bits1(gb)) dcdiff = -dcdiff; } @@ -2782,11 +2398,11 @@ static int vc1_decode_i_block(VC1Context *v, DCTELEM block[64], int n, int coded if(v->s.ac_pred) { if(!dc_pred_dir) - zz_table = vc1_horizontal_zz; + zz_table = ff_vc1_horizontal_zz; else - zz_table = vc1_vertical_zz; + zz_table = ff_vc1_vertical_zz; } else - zz_table = vc1_normal_zz; + zz_table = ff_vc1_normal_zz; ac_val = s->ac_val[0][0] + s->block_index[n] * 16; ac_val2 = ac_val; @@ -2916,9 +2532,9 @@ static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n, int c if (mquant == 1) dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3; else if (mquant == 2) - dcdiff = (dcdiff<<1) + get_bits(gb, 1) - 1; + dcdiff = (dcdiff<<1) + get_bits1(gb) - 1; } - if (get_bits(gb, 1)) + if (get_bits1(gb)) dcdiff = -dcdiff; } @@ -2939,14 +2555,12 @@ static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n, int c //AC Decoding i = 1; - /* check if AC is needed at all and adjust direction if needed */ - if(!a_avail) dc_pred_dir = 1; - if(!c_avail) dc_pred_dir = 0; + /* check if AC is needed at all */ if(!a_avail && !c_avail) use_pred = 0; ac_val = s->ac_val[0][0] + s->block_index[n] * 16; ac_val2 = ac_val; - scale = mquant * 2 + v->halfpq; + scale = mquant * 2 + ((mquant == v->pq) ? v->halfpq : 0); if(dc_pred_dir) //left ac_val -= 16; @@ -2967,11 +2581,11 @@ static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n, int c if(v->s.ac_pred) { if(!dc_pred_dir) - zz_table = vc1_horizontal_zz; + zz_table = ff_vc1_horizontal_zz; else - zz_table = vc1_vertical_zz; + zz_table = ff_vc1_vertical_zz; } else - zz_table = vc1_normal_zz; + zz_table = ff_vc1_normal_zz; while (!last) { vc1_decode_ac_coeff(v, &last, &skip, &value, codingset); @@ -2990,10 +2604,10 @@ static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n, int c if(dc_pred_dir) { //left for(k = 1; k < 8; k++) - block[k << 3] += (ac_val[k] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18; + block[k << 3] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; } else { //top for(k = 1; k < 8; k++) - block[k] += (ac_val[k + 8] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18; + block[k] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; } } else { if(dc_pred_dir) { //left @@ -3031,7 +2645,7 @@ static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n, int c q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1; q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1; for(k = 1; k < 8; k++) - ac_val2[k] = (ac_val2[k] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18; + ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; } } } else {//top @@ -3041,7 +2655,7 @@ static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n, int c q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1; q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1; for(k = 1; k < 8; k++) - ac_val2[k + 8] = (ac_val2[k + 8] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18; + ac_val2[k + 8] = (ac_val2[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; } } } @@ -3122,9 +2736,9 @@ static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int c if (mquant == 1) dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3; else if (mquant == 2) - dcdiff = (dcdiff<<1) + get_bits(gb, 1) - 1; + dcdiff = (dcdiff<<1) + get_bits1(gb) - 1; } - if (get_bits(gb, 1)) + if (get_bits1(gb)) dcdiff = -dcdiff; } @@ -3172,7 +2786,7 @@ static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int c const int8_t *zz_table; int k; - zz_table = vc1_simple_progressive_8x8_zz; + zz_table = ff_vc1_simple_progressive_8x8_zz; while (!last) { vc1_decode_ac_coeff(v, &last, &skip, &value, codingset); @@ -3191,10 +2805,10 @@ static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int c if(dc_pred_dir) { //left for(k = 1; k < 8; k++) - block[k << 3] += (ac_val[k] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18; + block[k << 3] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; } else { //top for(k = 1; k < 8; k++) - block[k] += (ac_val[k + 8] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18; + block[k] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; } } else { if(dc_pred_dir) { //left @@ -3232,7 +2846,7 @@ static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int c q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1; q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1; for(k = 1; k < 8; k++) - ac_val2[k] = (ac_val2[k] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18; + ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; } } } else {//top @@ -3242,7 +2856,7 @@ static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int c q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1; q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1; for(k = 1; k < 8; k++) - ac_val2[k + 8] = (ac_val2[k + 8] * q2 * vc1_dqscale[q1 - 1] + 0x20000) >> 18; + ac_val2[k + 8] = (ac_val2[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; } } } @@ -3272,7 +2886,8 @@ static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int c /** Decode P block */ -static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquant, int ttmb, int first_block) +static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquant, int ttmb, int first_block, + uint8_t *dst, int linesize, int skip_block) { MpegEncContext *s = &v->s; GetBitContext *gb = &s->gb; @@ -3282,10 +2897,10 @@ static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquan int ttblk = ttmb & 7; if(ttmb == -1) { - ttblk = ttblk_to_tt[v->tt_index][get_vlc2(gb, vc1_ttblk_vlc[v->tt_index].table, VC1_TTBLK_VLC_BITS, 1)]; + ttblk = ff_vc1_ttblk_to_tt[v->tt_index][get_vlc2(gb, ff_vc1_ttblk_vlc[v->tt_index].table, VC1_TTBLK_VLC_BITS, 1)]; } if(ttblk == TT_4X4) { - subblkpat = ~(get_vlc2(gb, vc1_subblkpat_vlc[v->tt_index].table, VC1_SUBBLKPAT_VLC_BITS, 1) + 1); + subblkpat = ~(get_vlc2(gb, ff_vc1_subblkpat_vlc[v->tt_index].table, VC1_SUBBLKPAT_VLC_BITS, 1) + 1); } if((ttblk != TT_8X8 && ttblk != TT_4X4) && (v->ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block))) { subblkpat = decode012(gb); @@ -3293,7 +2908,7 @@ static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquan if(ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) ttblk = TT_8X4; if(ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) ttblk = TT_4X8; } - scale = 2 * mquant + v->halfpq; + scale = 2 * mquant + ((v->pq == mquant) ? v->halfpq : 0); // convert transforms like 8X4_TOP to generic TT and SUBBLKPAT if(ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) { @@ -3313,12 +2928,15 @@ static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquan i += skip; if(i > 63) break; - idx = vc1_simple_progressive_8x8_zz[i++]; + idx = ff_vc1_simple_progressive_8x8_zz[i++]; block[idx] = value * scale; if(!v->pquantizer) block[idx] += (block[idx] < 0) ? -mquant : mquant; } - s->dsp.vc1_inv_trans_8x8(block); + if(!skip_block){ + s->dsp.vc1_inv_trans_8x8(block); + s->dsp.add_pixels_clamped(block, dst, linesize); + } break; case TT_4X4: for(j = 0; j < 4; j++) { @@ -3330,13 +2948,13 @@ static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquan i += skip; if(i > 15) break; - idx = vc1_simple_progressive_4x4_zz[i++]; + idx = ff_vc1_simple_progressive_4x4_zz[i++]; block[idx + off] = value * scale; if(!v->pquantizer) block[idx + off] += (block[idx + off] < 0) ? -mquant : mquant; } - if(!(subblkpat & (1 << (3 - j)))) - s->dsp.vc1_inv_trans_4x4(block, j); + if(!(subblkpat & (1 << (3 - j))) && !skip_block) + s->dsp.vc1_inv_trans_4x4(dst + (j&1)*4 + (j&2)*2*linesize, linesize, block + off); } break; case TT_8X4: @@ -3349,16 +2967,13 @@ static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquan i += skip; if(i > 31) break; - if(v->profile < PROFILE_ADVANCED) - idx = vc1_simple_progressive_8x4_zz[i++]; - else - idx = vc1_adv_progressive_8x4_zz[i++]; - block[idx + off] = value * scale; + idx = v->zz_8x4[i++]+off; + block[idx] = value * scale; if(!v->pquantizer) - block[idx + off] += (block[idx + off] < 0) ? -mquant : mquant; + block[idx] += (block[idx] < 0) ? -mquant : mquant; } - if(!(subblkpat & (1 << (1 - j)))) - s->dsp.vc1_inv_trans_8x4(block, j); + if(!(subblkpat & (1 << (1 - j))) && !skip_block) + s->dsp.vc1_inv_trans_8x4(dst + j*4*linesize, linesize, block + off); } break; case TT_4X8: @@ -3371,16 +2986,13 @@ static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquan i += skip; if(i > 31) break; - if(v->profile < PROFILE_ADVANCED) - idx = vc1_simple_progressive_4x8_zz[i++]; - else - idx = vc1_adv_progressive_4x8_zz[i++]; - block[idx + off] = value * scale; + idx = v->zz_4x8[i++]+off; + block[idx] = value * scale; if(!v->pquantizer) - block[idx + off] += (block[idx + off] < 0) ? -mquant : mquant; + block[idx] += (block[idx] < 0) ? -mquant : mquant; } - if(!(subblkpat & (1 << (1 - j)))) - s->dsp.vc1_inv_trans_4x8(block, j); + if(!(subblkpat & (1 << (1 - j))) && !skip_block) + s->dsp.vc1_inv_trans_4x8(dst + j*4, linesize, block + off); } break; } @@ -3441,12 +3053,12 @@ static int vc1_decode_p_mb(VC1Context *v) if (s->mb_intra && !mb_has_coeffs) { GET_MQUANT(); - s->ac_pred = get_bits(gb, 1); + s->ac_pred = get_bits1(gb); cbp = 0; } else if (mb_has_coeffs) { - if (s->mb_intra) s->ac_pred = get_bits(gb, 1); + if (s->mb_intra) s->ac_pred = get_bits1(gb); cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2); GET_MQUANT(); } @@ -3458,7 +3070,7 @@ static int vc1_decode_p_mb(VC1Context *v) s->current_picture.qscale_table[mb_pos] = mquant; if (!v->ttmbf && !s->mb_intra && mb_has_coeffs) - ttmb = get_vlc2(gb, vc1_ttmb_vlc[v->tt_index].table, + ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2); if(!s->mb_intra) vc1_mc_1mv(v, 0); dst_idx = 0; @@ -3481,9 +3093,7 @@ static int vc1_decode_p_mb(VC1Context *v) if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue; s->dsp.vc1_inv_trans_8x8(s->block[i]); if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1; - for(j = 0; j < 64; j++) s->block[i][j] += 128; - if(!v->res_fasttx && v->res_x8) for(j = 0; j < 64; j++) s->block[i][j] += 16; - s->dsp.put_pixels_clamped(s->block[i], s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2)); + s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2)); if(v->pq >= 9 && v->overlap) { if(v->c_avail) s->dsp.vc1_h_overlap(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2)); @@ -3491,11 +3101,9 @@ static int vc1_decode_p_mb(VC1Context *v) s->dsp.vc1_v_overlap(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2)); } } else if(val) { - vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block); + vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize, (i&4) && (s->flags & CODEC_FLAG_GRAY)); if(!v->ttmbf && ttmb < 8) ttmb = -1; first_block = 0; - if((i<4) || !(s->flags & CODEC_FLAG_GRAY)) - s->dsp.add_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize); } } } @@ -3563,11 +3171,11 @@ static int vc1_decode_p_mb(VC1Context *v) break; } } - if(intrapred)s->ac_pred = get_bits(gb, 1); + if(intrapred)s->ac_pred = get_bits1(gb); else s->ac_pred = 0; } if (!v->ttmbf && coded_inter) - ttmb = get_vlc2(gb, vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2); + ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2); for (i=0; i<6; i++) { dst_idx += i >> 2; @@ -3585,9 +3193,7 @@ static int vc1_decode_p_mb(VC1Context *v) if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue; s->dsp.vc1_inv_trans_8x8(s->block[i]); if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1; - for(j = 0; j < 64; j++) s->block[i][j] += 128; - if(!v->res_fasttx && v->res_x8) for(j = 0; j < 64; j++) s->block[i][j] += 16; - s->dsp.put_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize); + s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize); if(v->pq >= 9 && v->overlap) { if(v->c_avail) s->dsp.vc1_h_overlap(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2)); @@ -3595,11 +3201,9 @@ static int vc1_decode_p_mb(VC1Context *v) s->dsp.vc1_v_overlap(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2)); } } else if(is_coded[i]) { - status = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block); + status = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize, (i&4) && (s->flags & CODEC_FLAG_GRAY)); if(!v->ttmbf && ttmb < 8) ttmb = -1; first_block = 0; - if((i<4) || !(s->flags & CODEC_FLAG_GRAY)) - s->dsp.add_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize); } } return status; @@ -3707,7 +3311,7 @@ static void vc1_decode_b_mb(VC1Context *v) mb_has_coeffs = 0; s->current_picture.qscale_table[mb_pos] = mquant; if(!v->ttmbf) - ttmb = get_vlc2(gb, vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2); + ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2); dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0; vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype); vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype); @@ -3744,7 +3348,7 @@ static void vc1_decode_b_mb(VC1Context *v) GET_MQUANT(); s->current_picture.qscale_table[mb_pos] = mquant; if(!v->ttmbf && !s->mb_intra && mb_has_coeffs) - ttmb = get_vlc2(gb, vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2); + ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2); } } dst_idx = 0; @@ -3767,14 +3371,11 @@ static void vc1_decode_b_mb(VC1Context *v) if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue; s->dsp.vc1_inv_trans_8x8(s->block[i]); if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1; - for(j = 0; j < 64; j++) s->block[i][j] += 128; - s->dsp.put_pixels_clamped(s->block[i], s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2)); + s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2)); } else if(val) { - vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block); + vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize, (i&4) && (s->flags & CODEC_FLAG_GRAY)); if(!v->ttmbf && ttmb < 8) ttmb = -1; first_block = 0; - if((i<4) || !(s->flags & CODEC_FLAG_GRAY)) - s->dsp.add_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize); } } } @@ -3822,7 +3423,6 @@ static void vc1_decode_i_blocks(VC1Context *v) s->mb_x = s->mb_y = 0; s->mb_intra = 1; s->first_slice_line = 1; - ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END)); for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) { for(s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) { ff_init_block_index(s); @@ -3836,7 +3436,7 @@ static void vc1_decode_i_blocks(VC1Context *v) // do actual MB decoding and displaying cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2); - v->s.ac_pred = get_bits(&v->s.gb, 1); + v->s.ac_pred = get_bits1(&v->s.gb); for(k = 0; k < 6; k++) { val = ((cbp >> (5 - k)) & 1); @@ -3851,7 +3451,6 @@ static void vc1_decode_i_blocks(VC1Context *v) vc1_decode_i_block(v, s->block[k], k, val, (k<4)? v->codingset : v->codingset2); s->dsp.vc1_inv_trans_8x8(s->block[k]); - if(!v->res_fasttx && !v->res_x8) for(j = 0; j < 64; j++) s->block[k][j] -= 16; if(v->pq >= 9 && v->overlap) { for(j = 0; j < 64; j++) s->block[k][j] += 128; } @@ -3882,6 +3481,7 @@ static void vc1_decode_i_blocks(VC1Context *v) } if(get_bits_count(&s->gb) > v->bits) { + ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)); av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits); return; } @@ -3889,6 +3489,7 @@ static void vc1_decode_i_blocks(VC1Context *v) ff_draw_horiz_band(s, s->mb_y * 16, 16); s->first_slice_line = 0; } + ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END)); } /** Decode blocks of I-frame for advanced profile @@ -3934,7 +3535,6 @@ static void vc1_decode_i_blocks_adv(VC1Context *v) s->mb_x = s->mb_y = 0; s->mb_intra = 1; s->first_slice_line = 1; - ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END)); for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) { for(s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) { ff_init_block_index(s); @@ -3948,13 +3548,13 @@ static void vc1_decode_i_blocks_adv(VC1Context *v) // do actual MB decoding and displaying cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2); if(v->acpred_is_raw) - v->s.ac_pred = get_bits(&v->s.gb, 1); + v->s.ac_pred = get_bits1(&v->s.gb); else v->s.ac_pred = v->acpred_plane[mb_pos]; if(v->condover == CONDOVER_SELECT) { if(v->overflg_is_raw) - overlap = get_bits(&v->s.gb, 1); + overlap = get_bits1(&v->s.gb); else overlap = v->over_flags_plane[mb_pos]; } else @@ -4011,6 +3611,7 @@ static void vc1_decode_i_blocks_adv(VC1Context *v) } if(get_bits_count(&s->gb) > v->bits) { + ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)); av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits); return; } @@ -4018,6 +3619,7 @@ static void vc1_decode_i_blocks_adv(VC1Context *v) ff_draw_horiz_band(s, s->mb_y * 16, 16); s->first_slice_line = 0; } + ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END)); } static void vc1_decode_p_blocks(VC1Context *v) @@ -4049,7 +3651,6 @@ static void vc1_decode_p_blocks(VC1Context *v) break; } - ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END)); s->first_slice_line = 1; for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) { for(s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) { @@ -4059,6 +3660,7 @@ static void vc1_decode_p_blocks(VC1Context *v) vc1_decode_p_mb(v); if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) { + ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)); av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits,s->mb_x,s->mb_y); return; } @@ -4066,6 +3668,7 @@ static void vc1_decode_p_blocks(VC1Context *v) ff_draw_horiz_band(s, s->mb_y * 16, 16); s->first_slice_line = 0; } + ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END)); } static void vc1_decode_b_blocks(VC1Context *v) @@ -4097,7 +3700,6 @@ static void vc1_decode_b_blocks(VC1Context *v) break; } - ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END)); s->first_slice_line = 1; for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) { for(s->mb_x = 0; s->mb_x < s->mb_width; s->mb_x++) { @@ -4107,6 +3709,7 @@ static void vc1_decode_b_blocks(VC1Context *v) vc1_decode_b_mb(v); if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) { + ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)); av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits,s->mb_x,s->mb_y); return; } @@ -4114,6 +3717,7 @@ static void vc1_decode_b_blocks(VC1Context *v) ff_draw_horiz_band(s, s->mb_y * 16, 16); s->first_slice_line = 0; } + ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END)); } static void vc1_decode_skip_blocks(VC1Context *v) @@ -4139,38 +3743,40 @@ static void vc1_decode_blocks(VC1Context *v) { v->s.esc3_level_length = 0; + if(v->x8_type){ + ff_intrax8_decode_picture(&v->x8, 2*v->pq+v->halfpq, v->pq*(!v->pquantizer) ); + }else{ - switch(v->s.pict_type) { - case I_TYPE: - if(v->profile == PROFILE_ADVANCED) - vc1_decode_i_blocks_adv(v); - else - vc1_decode_i_blocks(v); - break; - case P_TYPE: - if(v->p_frame_skipped) - vc1_decode_skip_blocks(v); - else - vc1_decode_p_blocks(v); - break; - case B_TYPE: - if(v->bi_type){ + switch(v->s.pict_type) { + case I_TYPE: if(v->profile == PROFILE_ADVANCED) vc1_decode_i_blocks_adv(v); else vc1_decode_i_blocks(v); - }else - vc1_decode_b_blocks(v); - break; + break; + case P_TYPE: + if(v->p_frame_skipped) + vc1_decode_skip_blocks(v); + else + vc1_decode_p_blocks(v); + break; + case B_TYPE: + if(v->bi_type){ + if(v->profile == PROFILE_ADVANCED) + vc1_decode_i_blocks_adv(v); + else + vc1_decode_i_blocks(v); + }else + vc1_decode_b_blocks(v); + break; + } } } -#define IS_MARKER(x) (((x) & ~0xFF) == VC1_CODE_RES0) - /** Find VC-1 marker in buffer * @return position where next marker starts or end of buffer if no marker found */ -static av_always_inline uint8_t* find_next_marker(uint8_t *src, uint8_t *end) +static av_always_inline const uint8_t* find_next_marker(const uint8_t *src, const uint8_t *end) { uint32_t mrk = 0xFFFFFFFF; @@ -4183,7 +3789,7 @@ static av_always_inline uint8_t* find_next_marker(uint8_t *src, uint8_t *end) return end; } -static av_always_inline int vc1_unescape_buffer(uint8_t *src, int size, uint8_t *dst) +static av_always_inline int vc1_unescape_buffer(const uint8_t *src, int size, uint8_t *dst) { int dsize = 0, i; @@ -4221,6 +3827,10 @@ static int vc1_decode_init(AVCodecContext *avctx) avctx->flags |= CODEC_FLAG_EMU_EDGE; v->s.flags |= CODEC_FLAG_EMU_EDGE; + if(avctx->idct_algo==FF_IDCT_AUTO){ + avctx->idct_algo=FF_IDCT_WMV2; + } + if(ff_h263_decode_init(avctx) < 0) return -1; if (vc1_init_common(v) < 0) return -1; @@ -4252,10 +3862,12 @@ static int vc1_decode_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count); } } else { // VC1/WVC1 - uint8_t *start = avctx->extradata, *end = avctx->extradata + avctx->extradata_size; - uint8_t *next; int size, buf2_size; + const uint8_t *start = avctx->extradata; + uint8_t *end = avctx->extradata + avctx->extradata_size; + const uint8_t *next; + int size, buf2_size; uint8_t *buf2 = NULL; - int seq_inited = 0, ep_inited = 0; + int seq_initialized = 0, ep_initialized = 0; if(avctx->extradata_size < 16) { av_log(avctx, AV_LOG_ERROR, "Extradata size too small: %i\n", avctx->extradata_size); @@ -4277,19 +3889,19 @@ static int vc1_decode_init(AVCodecContext *avctx) av_free(buf2); return -1; } - seq_inited = 1; + seq_initialized = 1; break; case VC1_CODE_ENTRYPOINT: if(decode_entry_point(avctx, &gb) < 0){ av_free(buf2); return -1; } - ep_inited = 1; + ep_initialized = 1; break; } } av_free(buf2); - if(!seq_inited || !ep_inited){ + if(!seq_initialized || !ep_initialized){ av_log(avctx, AV_LOG_ERROR, "Incomplete extradata\n"); return -1; } @@ -4321,6 +3933,7 @@ static int vc1_decode_init(AVCodecContext *avctx) // return -1; } + ff_intrax8_common_init(&v->x8,s); return 0; } @@ -4330,7 +3943,7 @@ static int vc1_decode_init(AVCodecContext *avctx) */ static int vc1_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { VC1Context *v = avctx->priv_data; MpegEncContext *s = &v->s; @@ -4350,7 +3963,8 @@ static int vc1_decode_frame(AVCodecContext *avctx, return 0; } - //we need to set current_picture_ptr before reading the header, otherwise we cant store anyting im there + /* We need to set current_picture_ptr before reading the header, + * otherwise we cannot store anything in there. */ if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){ int i= ff_find_unused_picture(s, 0); s->current_picture_ptr= &s->picture[i]; @@ -4362,7 +3976,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, buf2 = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); if(IS_MARKER(AV_RB32(buf))){ /* frame starts with marker and needs to be parsed */ - uint8_t *dst = buf2, *start, *end, *next; + const uint8_t *start, *end, *next; int size; next = buf; @@ -4386,7 +4000,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, } } }else if(v->interlace && ((buf[0] & 0xC0) == 0xC0)){ /* WVC1 interlaced stores both fields divided by marker */ - uint8_t *divider; + const uint8_t *divider; divider = find_next_marker(buf, buf + buf_size); if((divider == (buf + buf_size)) || AV_RB32(divider) != VC1_CODE_FIELD){ @@ -4456,6 +4070,9 @@ static int vc1_decode_frame(AVCodecContext *avctx, return -1; } + s->me.qpel_put= s->dsp.put_qpel_pixels_tab; + s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab; + ff_er_frame_start(s); v->bits = buf_size * 8; @@ -4481,7 +4098,7 @@ assert(s->current_picture.pict_type == s->pict_type); } /* Return the Picture timestamp as the frame number */ - /* we substract 1 because it is added on utils.c */ + /* we subtract 1 because it is added on utils.c */ avctx->frame_number = s->picture_number - 1; av_free(buf2); @@ -4504,6 +4121,7 @@ static int vc1_decode_end(AVCodecContext *avctx) av_freep(&v->acpred_plane); av_freep(&v->over_flags_plane); av_freep(&v->mb_type_base); + ff_intrax8_common_end(&v->x8); return 0; } @@ -4533,94 +4151,3 @@ AVCodec wmv3_decoder = { CODEC_CAP_DELAY, NULL }; - -#ifdef CONFIG_VC1_PARSER -/** - * finds the end of the current frame in the bitstream. - * @return the position of the first byte of the next frame, or -1 - */ -static int vc1_find_frame_end(ParseContext *pc, const uint8_t *buf, - int buf_size) { - int pic_found, i; - uint32_t state; - - pic_found= pc->frame_start_found; - state= pc->state; - - i=0; - if(!pic_found){ - for(i=0; iframe_start_found=0; - pc->state=-1; - return i-3; - } - } - } - pc->frame_start_found= pic_found; - pc->state= state; - return END_NOT_FOUND; -} - -static int vc1_parse(AVCodecParserContext *s, - AVCodecContext *avctx, - uint8_t **poutbuf, int *poutbuf_size, - const uint8_t *buf, int buf_size) -{ - ParseContext *pc = s->priv_data; - int next; - - if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ - next= buf_size; - }else{ - next= vc1_find_frame_end(pc, buf, buf_size); - - if (ff_combine_frame(pc, next, (uint8_t **)&buf, &buf_size) < 0) { - *poutbuf = NULL; - *poutbuf_size = 0; - return buf_size; - } - } - *poutbuf = (uint8_t *)buf; - *poutbuf_size = buf_size; - return next; -} - -int vc1_split(AVCodecContext *avctx, - const uint8_t *buf, int buf_size) -{ - int i; - uint32_t state= -1; - - for(i=0; iYCbCr transform matrix + int hrd_param_flag; ///< Presence of Hypothetical Reference + ///< Decoder parameters + int psf; ///< Progressive Segmented Frame + //@} + + /** Sequence header data for all Profiles + * TODO: choose between ints, uint8_ts and monobit flags + */ + //@{ + int profile; ///< 2bits, Profile + int frmrtq_postproc; ///< 3bits, + int bitrtq_postproc; ///< 5bits, quantized framerate-based postprocessing strength + int fastuvmc; ///< Rounding of qpel vector to hpel ? (not in Simple) + int extended_mv; ///< Ext MV in P/B (not in Simple) + int dquant; ///< How qscale varies with MBs, 2bits (not in Simple) + int vstransform; ///< variable-size [48]x[48] transform type + info + int overlap; ///< overlapped transforms in use + int quantizer_mode; ///< 2bits, quantizer mode used for sequence, see QUANT_* + int finterpflag; ///< INTERPFRM present + //@} + + /** Frame decoding info for all profiles */ + //@{ + uint8_t mv_mode; ///< MV coding monde + uint8_t mv_mode2; ///< Secondary MV coding mode (B frames) + int k_x; ///< Number of bits for MVs (depends on MV range) + int k_y; ///< Number of bits for MVs (depends on MV range) + int range_x, range_y; ///< MV range + uint8_t pq, altpq; ///< Current/alternate frame quantizer scale + const uint8_t* zz_8x4;///< Zigzag scan table for TT_8x4 coding mode + const uint8_t* zz_4x8;///< Zigzag scan table for TT_4x8 coding mode + /** pquant parameters */ + //@{ + uint8_t dquantfrm; + uint8_t dqprofile; + uint8_t dqsbedge; + uint8_t dqbilevel; + //@} + /** AC coding set indexes + * @see 8.1.1.10, p(1)10 + */ + //@{ + int c_ac_table_index; ///< Chroma index from ACFRM element + int y_ac_table_index; ///< Luma index from AC2FRM element + //@} + int ttfrm; ///< Transform type info present at frame level + uint8_t ttmbf; ///< Transform type flag + uint8_t ttblk4x4; ///< Value of ttblk which indicates a 4x4 transform + int codingset; ///< index of current table set from 11.8 to use for luma block decoding + int codingset2; ///< index of current table set from 11.8 to use for chroma block decoding + int pqindex; ///< raw pqindex used in coding set selection + int a_avail, c_avail; + uint8_t *mb_type_base, *mb_type[3]; + + + /** Luma compensation parameters */ + //@{ + uint8_t lumscale; + uint8_t lumshift; + //@} + int16_t bfraction; ///< Relative position % anchors=> how to scale MVs + uint8_t halfpq; ///< Uniform quant over image and qp+.5 + uint8_t respic; ///< Frame-level flag for resized images + int buffer_fullness; ///< HRD info + /** Ranges: + * -# 0 -> [-64n 63.f] x [-32, 31.f] + * -# 1 -> [-128, 127.f] x [-64, 63.f] + * -# 2 -> [-512, 511.f] x [-128, 127.f] + * -# 3 -> [-1024, 1023.f] x [-256, 255.f] + */ + uint8_t mvrange; + uint8_t pquantizer; ///< Uniform (over sequence) quantizer in use + VLC *cbpcy_vlc; ///< CBPCY VLC table + int tt_index; ///< Index for Transform Type tables + uint8_t* mv_type_mb_plane; ///< bitplane for mv_type == (4MV) + uint8_t* direct_mb_plane; ///< bitplane for "direct" MBs + int mv_type_is_raw; ///< mv type mb plane is not coded + int dmb_is_raw; ///< direct mb plane is raw + int skip_is_raw; ///< skip mb plane is not coded + uint8_t luty[256], lutuv[256]; // lookup tables used for intensity compensation + int use_ic; ///< use intensity compensation in B-frames + int rnd; ///< rounding control + + /** Frame decoding info for S/M profiles only */ + //@{ + uint8_t rangeredfrm; ///< out_sample = CLIP((in_sample-128)*2+128) + uint8_t interpfrm; + //@} + + /** Frame decoding info for Advanced profile */ + //@{ + uint8_t fcm; ///< 0->Progressive, 2->Frame-Interlace, 3->Field-Interlace + uint8_t numpanscanwin; + uint8_t tfcntr; + uint8_t rptfrm, tff, rff; + uint16_t topleftx; + uint16_t toplefty; + uint16_t bottomrightx; + uint16_t bottomrighty; + uint8_t uvsamp; + uint8_t postproc; + int hrd_num_leaky_buckets; + uint8_t bit_rate_exponent; + uint8_t buffer_size_exponent; + uint8_t* acpred_plane; ///< AC prediction flags bitplane + int acpred_is_raw; + uint8_t* over_flags_plane; ///< Overflags bitplane + int overflg_is_raw; + uint8_t condover; + uint16_t *hrd_rate, *hrd_buffer; + uint8_t *hrd_fullness; + uint8_t range_mapy_flag; + uint8_t range_mapuv_flag; + uint8_t range_mapy; + uint8_t range_mapuv; + //@} + + int p_frame_skipped; + int bi_type; + int x8_type; +} VC1Context; + +#endif /* FFMPEG_VC1_H */ diff --git a/contrib/ffmpeg/libavcodec/vc1_parser.c b/contrib/ffmpeg/libavcodec/vc1_parser.c new file mode 100644 index 000000000..a76d14707 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/vc1_parser.c @@ -0,0 +1,118 @@ +/* + * VC-1 and WMV3 parser + * Copyright (c) 2006-2007 Konstantin Shishkov + * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file vc1_parser.c + * VC-1 and WMV3 parser + */ + +#include "parser.h" +#include "vc1.h" + +/** + * finds the end of the current frame in the bitstream. + * @return the position of the first byte of the next frame, or -1 + */ +static int vc1_find_frame_end(ParseContext *pc, const uint8_t *buf, + int buf_size) { + int pic_found, i; + uint32_t state; + + pic_found= pc->frame_start_found; + state= pc->state; + + i=0; + if(!pic_found){ + for(i=0; iframe_start_found=0; + pc->state=-1; + return i-3; + } + } + } + pc->frame_start_found= pic_found; + pc->state= state; + return END_NOT_FOUND; +} + +static int vc1_parse(AVCodecParserContext *s, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + ParseContext *pc = s->priv_data; + int next; + + if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ + next= buf_size; + }else{ + next= vc1_find_frame_end(pc, buf, buf_size); + + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + } + *poutbuf = buf; + *poutbuf_size = buf_size; + return next; +} + +static int vc1_split(AVCodecContext *avctx, + const uint8_t *buf, int buf_size) +{ + int i; + uint32_t state= -1; + + for(i=0; i + #define AC_MODES 8 static const int vc1_ac_sizes[AC_MODES] = { @@ -583,3 +588,5 @@ static const uint8_t vc1_last_delta_run_table[AC_MODES][10] = { -1, 30, 28, 3, 0 } }; + +#endif /* FFMPEG_VC1ACDATA_H */ diff --git a/contrib/ffmpeg/libavcodec/vc1data.c b/contrib/ffmpeg/libavcodec/vc1data.c new file mode 100644 index 000000000..7f50d715f --- /dev/null +++ b/contrib/ffmpeg/libavcodec/vc1data.c @@ -0,0 +1,712 @@ +/* + * VC-1 and WMV3 decoder + * copyright (c) 2006 Konstantin Shishkov + * (c) 2005 anonymous, Alex Beregszaszi, Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file vc1data.c + * VC-1 tables. + */ + +#include "avcodec.h" +#include "vc1.h" +#include "vc1data.h" + +/** Table for conversion between TTBLK and TTMB */ +const int ff_vc1_ttblk_to_tt[3][8] = { + { TT_8X4, TT_4X8, TT_8X8, TT_4X4, TT_8X4_TOP, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT }, + { TT_8X8, TT_4X8_RIGHT, TT_4X8_LEFT, TT_4X4, TT_8X4, TT_4X8, TT_8X4_BOTTOM, TT_8X4_TOP }, + { TT_8X8, TT_4X8, TT_4X4, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT, TT_8X4, TT_8X4_TOP } +}; + +const int ff_vc1_ttfrm_to_tt[4] = { TT_8X8, TT_8X4, TT_4X8, TT_4X4 }; + +/** MV P mode - the 5th element is only used for mode 1 */ +const uint8_t ff_vc1_mv_pmode_table[2][5] = { + { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_MIXED_MV }, + { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_1MV_HPEL_BILIN } +}; +const uint8_t ff_vc1_mv_pmode_table2[2][4] = { + { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_MIXED_MV }, + { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_1MV_HPEL_BILIN } +}; + +const int ff_vc1_fps_nr[5] = { 24, 25, 30, 50, 60 }, + ff_vc1_fps_dr[2] = { 1000, 1001 }; +const uint8_t ff_vc1_pquant_table[3][32] = { + { /* Implicit quantizer */ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 29, 31 + }, + { /* Explicit quantizer, pquantizer uniform */ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 + }, + { /* Explicit quantizer, pquantizer non-uniform */ + 0, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 31 + } +}; + +/** @name VC-1 VLC tables and defines + * @todo TODO move this into the context + */ +//@{ +#define VC1_BFRACTION_VLC_BITS 7 +VLC ff_vc1_bfraction_vlc; +#define VC1_IMODE_VLC_BITS 4 +VLC ff_vc1_imode_vlc; +#define VC1_NORM2_VLC_BITS 3 +VLC ff_vc1_norm2_vlc; +#define VC1_NORM6_VLC_BITS 9 +VLC ff_vc1_norm6_vlc; +/* Could be optimized, one table only needs 8 bits */ +#define VC1_TTMB_VLC_BITS 9 //12 +VLC ff_vc1_ttmb_vlc[3]; +#define VC1_MV_DIFF_VLC_BITS 9 //15 +VLC ff_vc1_mv_diff_vlc[4]; +#define VC1_CBPCY_P_VLC_BITS 9 //14 +VLC ff_vc1_cbpcy_p_vlc[4]; +#define VC1_4MV_BLOCK_PATTERN_VLC_BITS 6 +VLC ff_vc1_4mv_block_pattern_vlc[4]; +#define VC1_TTBLK_VLC_BITS 5 +VLC ff_vc1_ttblk_vlc[3]; +#define VC1_SUBBLKPAT_VLC_BITS 6 +VLC ff_vc1_subblkpat_vlc[3]; + +VLC ff_vc1_ac_coeff_table[8]; +//@} + + +#if B_FRACTION_DEN==840 //original bfraction from vc9data.h, not conforming to standard +/* bfraction is fractional, we scale to the GCD 3*5*7*8 = 840 */ +const int16_t ff_vc1_bfraction_lut[23] = { + 420 /*1/2*/, 280 /*1/3*/, 560 /*2/3*/, 210 /*1/4*/, + 630 /*3/4*/, 168 /*1/5*/, 336 /*2/5*/, + 504 /*3/5*/, 672 /*4/5*/, 140 /*1/6*/, 700 /*5/6*/, + 120 /*1/7*/, 240 /*2/7*/, 360 /*3/7*/, 480 /*4/7*/, + 600 /*5/7*/, 720 /*6/7*/, 105 /*1/8*/, 315 /*3/8*/, + 525 /*5/8*/, 735 /*7/8*/, + -1 /*inv.*/, 0 /*BI fm*/ +}; +#else +/* pre-computed scales for all bfractions and base=256 */ +const int16_t ff_vc1_bfraction_lut[23] = { + 128 /*1/2*/, 85 /*1/3*/, 170 /*2/3*/, 64 /*1/4*/, + 192 /*3/4*/, 51 /*1/5*/, 102 /*2/5*/, + 153 /*3/5*/, 204 /*4/5*/, 43 /*1/6*/, 215 /*5/6*/, + 37 /*1/7*/, 74 /*2/7*/, 111 /*3/7*/, 148 /*4/7*/, + 185 /*5/7*/, 222 /*6/7*/, 32 /*1/8*/, 96 /*3/8*/, + 160 /*5/8*/, 224 /*7/8*/, + -1 /*inv.*/, 0 /*BI fm*/ +}; +#endif + +const uint8_t ff_vc1_bfraction_bits[23] = { + 3, 3, 3, 3, + 3, 3, 3, + 7, 7, 7, 7, + 7, 7, 7, 7, + 7, 7, 7, 7, + 7, 7, + 7, 7 +}; +const uint8_t ff_vc1_bfraction_codes[23] = { + 0, 1, 2, 3, + 4, 5, 6, + 112, 113, 114, 115, + 116, 117, 118, 119, + 120, 121, 122, 123, + 124, 125, + 126, 127 +}; + +//Same as H.264 +const AVRational ff_vc1_pixel_aspect[16]={ + {0, 1}, + {1, 1}, + {12, 11}, + {10, 11}, + {16, 11}, + {40, 33}, + {24, 11}, + {20, 11}, + {32, 11}, + {80, 33}, + {18, 11}, + {15, 11}, + {64, 33}, + {160, 99}, + {0, 1}, + {0, 1} +}; + +/* BitPlane IMODE - such a small table... */ +const uint8_t ff_vc1_imode_codes[7] = { + 0, 2, 1, 3, 1, 2, 3 +}; +const uint8_t ff_vc1_imode_bits[7] = { + 4, 2, 3, 2, 4, 3, 3 +}; + +/* Normal-2 imode */ +const uint8_t ff_vc1_norm2_codes[4] = { + 0, 4, 5, 3 +}; +const uint8_t ff_vc1_norm2_bits[4] = { + 1, 3, 3, 2 +}; + +const uint16_t ff_vc1_norm6_codes[64] = { +0x001, 0x002, 0x003, 0x000, 0x004, 0x001, 0x002, 0x047, 0x005, 0x003, 0x004, 0x04B, 0x005, 0x04D, 0x04E, 0x30E, +0x006, 0x006, 0x007, 0x053, 0x008, 0x055, 0x056, 0x30D, 0x009, 0x059, 0x05A, 0x30C, 0x05C, 0x30B, 0x30A, 0x037, +0x007, 0x00A, 0x00B, 0x043, 0x00C, 0x045, 0x046, 0x309, 0x00D, 0x049, 0x04A, 0x308, 0x04C, 0x307, 0x306, 0x036, +0x00E, 0x051, 0x052, 0x305, 0x054, 0x304, 0x303, 0x035, 0x058, 0x302, 0x301, 0x034, 0x300, 0x033, 0x032, 0x007, +}; + +const uint8_t ff_vc1_norm6_bits[64] = { + 1, 4, 4, 8, 4, 8, 8, 10, 4, 8, 8, 10, 8, 10, 10, 13, + 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9, + 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9, + 8, 10, 10, 13, 10, 13, 13, 9, 10, 13, 13, 9, 13, 9, 9, 6, +}; +/* Normal-6 imode */ +const uint8_t ff_vc1_norm6_spec[64][5] = { +{ 0, 1, 1 }, +{ 1, 2, 4 }, +{ 2, 3, 4 }, +{ 3, 0, 8 }, +{ 4, 4, 4 }, +{ 5, 1, 8 }, +{ 6, 2, 8 }, +{ 7, 2, 5, 7, 5 }, +{ 8, 5, 4 }, +{ 9, 3, 8 }, +{10, 4, 8 }, +{11, 2, 5, 11, 5 }, +{12, 5, 8 }, +{13, 2, 5, 13, 5 }, +{14, 2, 5, 14, 5 }, +{15, 3, 5, 14, 8 }, +{16, 6, 4 }, +{17, 6, 8 }, +{18, 7, 8 }, +{19, 2, 5, 19, 5 }, +{20, 8, 8 }, +{21, 2, 5, 21, 5 }, +{22, 2, 5, 22, 5 }, +{23, 3, 5, 13, 8 }, +{24, 9, 8 }, +{25, 2, 5, 25, 5 }, +{26, 2, 5, 26, 5 }, +{27, 3, 5, 12, 8 }, +{28, 2, 5, 28, 5 }, +{29, 3, 5, 11, 8 }, +{30, 3, 5, 10, 8 }, +{31, 3, 5, 7, 4 }, +{32, 7, 4 }, +{33, 10, 8 }, +{34, 11, 8 }, +{35, 2, 5, 3, 5 }, +{36, 12, 8 }, +{37, 2, 5, 5, 5 }, +{38, 2, 5, 6, 5 }, +{39, 3, 5, 9, 8 }, +{40, 13, 8 }, +{41, 2, 5, 9, 5 }, +{42, 2, 5, 10, 5 }, +{43, 3, 5, 8, 8 }, +{44, 2, 5, 12, 5 }, +{45, 3, 5, 7, 8 }, +{46, 3, 5, 6, 8 }, +{47, 3, 5, 6, 4 }, +{48, 14, 8 }, +{49, 2, 5, 17, 5 }, +{50, 2, 5, 18, 5 }, +{51, 3, 5, 5, 8 }, +{52, 2, 5, 20, 5 }, +{53, 3, 5, 4, 8 }, +{54, 3, 5, 3, 8 }, +{55, 3, 5, 5, 4 }, +{56, 2, 5, 24, 5 }, +{57, 3, 5, 2, 8 }, +{58, 3, 5, 1, 8 }, +{59, 3, 5, 4, 4 }, +{60, 3, 5, 0, 8 }, +{61, 3, 5, 3, 4 }, +{62, 3, 5, 2, 4 }, +{63, 3, 5, 1, 1 }, +}; + +/* 4MV Block pattern VLC tables */ +const uint8_t ff_vc1_4mv_block_pattern_codes[4][16] = { + { 14, 58, 59, 25, 12, 26, 15, 15, 13, 24, 27, 0, 28, 1, 2, 2}, + { 8, 18, 19, 4, 20, 5, 30, 11, 21, 31, 6, 12, 7, 13, 14, 0}, + { 15, 6, 7, 2, 8, 3, 28, 9, 10, 29, 4, 11, 5, 12, 13, 0}, + { 0, 11, 12, 4, 13, 5, 30, 16, 14, 31, 6, 17, 7, 18, 19, 10} +}; +const uint8_t ff_vc1_4mv_block_pattern_bits[4][16] = { + { 5, 6, 6, 5, 5, 5, 5, 4, 5, 5, 5, 3, 5, 3, 3, 2}, + { 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4, 4, 4, 4, 4, 2}, + { 4, 4, 4, 4, 4, 4, 5, 4, 4, 5, 4, 4, 4, 4, 4, 3}, + { 2, 4, 4, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4} +}; + +const uint8_t wmv3_dc_scale_table[32]={ + 0, 2, 4, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21 +}; + +/* P-Picture CBPCY VLC tables */ +#if 1 // Looks like original tables are not conforming to standard at all. Are they used for old WMV? +const uint16_t ff_vc1_cbpcy_p_codes[4][64] = { + { + 0, 6, 15, 13, 13, 11, 3, 13, 5, 8, 49, 10, 12, 114, 102, 119, + 1, 54, 96, 8, 10, 111, 5, 15, 12, 10, 2, 12, 13, 115, 53, 63, + 1, 7, 1, 7, 14, 12, 4, 14, 1, 9, 97, 11, 7, 58, 52, 62, + 4, 103, 1, 9, 11, 56, 101, 118, 4, 110, 100, 30, 2, 5, 4, 3 + }, + { + 0, 9, 1, 18, 5, 14, 237, 26, 3, 121, 3, 22, 13, 16, 6, 30, + 2, 10, 1, 20, 12, 241, 5, 28, 16, 12, 3, 24, 28, 124, 239, 247, + 1, 240, 1, 19, 18, 15, 4, 27, 1, 122, 2, 23, 1, 17, 7, 31, + 1, 11, 2, 21, 19, 246, 238, 29, 17, 13, 236, 25, 58, 63, 8, 125 + }, + { + 0, 201, 25, 231, 5, 221, 1, 3, 2, 414, 2, 241, 16, 225, 195, 492, + 2, 412, 1, 240, 7, 224, 98, 245, 1, 220, 96, 5, 9, 230, 101, 247, + 1, 102, 1, 415, 24, 3, 2, 244, 3, 54, 3, 484, 17, 114, 200, 493, + 3, 413, 1, 4, 13, 113, 99, 485, 4, 111, 194, 243, 5, 29, 26, 31 + }, + { + 0, 28, 12, 44, 3, 36, 20, 52, 2, 32, 16, 48, 8, 40, 24, 28, + 1, 30, 14, 46, 6, 38, 22, 54, 3, 34, 18, 50, 10, 42, 26, 30, + 1, 29, 13, 45, 5, 37, 21, 53, 2, 33, 17, 49, 9, 41, 25, 29, + 1, 31, 15, 47, 7, 39, 23, 55, 4, 35, 19, 51, 11, 43, 27, 31 + } +}; + +const uint8_t ff_vc1_cbpcy_p_bits[4][64] = { + { + 13, 13, 7, 13, 7, 13, 13, 12, 6, 13, 7, 12, 6, 8, 8, 8, + 5, 7, 8, 12, 6, 8, 13, 12, 7, 13, 13, 12, 6, 8, 7, 7, + 6, 13, 8, 12, 7, 13, 13, 12, 7, 13, 8, 12, 5, 7, 7, 7, + 6, 8, 13, 12, 6, 7, 8, 8, 5, 8, 8, 6, 3, 3, 3, 2 + }, + { + 14, 13, 8, 13, 3, 13, 8, 13, 3, 7, 8, 13, 4, 13, 13, 13, + 3, 13, 13, 13, 4, 8, 13, 13, 5, 13, 13, 13, 5, 7, 8, 8, + 3, 8, 14, 13, 5, 13, 13, 13, 4, 7, 13, 13, 6, 13, 13, 13, + 5, 13, 8, 13, 5, 8, 8, 13, 5, 13, 8, 13, 6, 6, 13, 7 + }, + { + 13, 8, 6, 8, 4, 8, 13, 12, 4, 9, 8, 8, 5, 8, 8, 9, + 5, 9, 10, 8, 4, 8, 7, 8, 6, 8, 7, 13, 4, 8, 7, 8, + 5, 7, 8, 9, 6, 13, 13, 8, 4, 6, 8, 9, 5, 7, 8, 9, + 5, 9, 9, 13, 5, 7, 7, 9, 4, 7, 8, 8, 3, 5, 5, 5 + }, + { + 9, 9, 9, 9, 2, 9, 9, 9, 2, 9, 9, 9, 9, 9, 9, 8, + 3, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, + 2, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8 + } +}; +#else +const uint16_t ff_vc1_cbpcy_p_codes[4][64] = { + { + 0, 1, 1, 4, 5, 1, 12, 4, 13, 14, 10, 11, 12, 7, 13, 2, + 15, 1, 96, 1, 49, 97, 2, 100, 3, 4, 5, 101, 102, 52, 53, 4, + 6, 7, 54, 103, 8, 9, 10, 110, 11, 12, 111, 56, 114, 58, 115, 5, + 13, 7, 8, 9, 10, 11, 12, 30, 13, 14, 15, 118, 119, 62, 63, 3 + }, + { + 0, 1, 2, 1, 3, 1, 16, 17, 5, 18, 12, 19, 13, 1, 28, 58, + 1, 1, 1, 2, 3, 2, 3, 236, 237, 4, 5, 238, 6, 7, 239, 8, + 9, 240, 10, 11, 121, 122, 12, 13, 14, 15, 241, 246, 16, 17, 124, 63, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 247, 125 + }, + { + 0, 1, 2, 3, 2, 3, 1, 4, 5, 24, 7, 13, 16, 17, 9, 5, + 25, 1, 1, 1, 2, 3, 96, 194, 1, 2, 98, 99, 195, 200, 101, 26, + 201, 102, 412, 413, 414, 54, 220, 111, 221, 3, 224, 113, 225, 114, 230, 29, + 231, 415, 240, 4, 241, 484, 5, 243, 3, 244, 245, 485, 492, 493, 247, 31 + }, + { + 0, 1, 1, 1, 2, 2, 3, 4, 3, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, + 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 28, 29, 30, 31 + } +}; +const uint8_t ff_vc1_cbpcy_p_bits[4][64] = { + { + 13, 6, 5, 6, 6, 7, 7, 5, 7, 7, 6, 6, 6, 5, 6, 3, + 7, 8, 8, 13, 7, 8, 13, 8, 13, 13, 13, 8, 8, 7, 7, 3, + 13, 13, 7, 8, 13, 13, 13, 8, 13, 13, 8, 7, 8, 7, 8, 3, + 13, 12, 12, 12, 12, 12, 12, 6, 12, 12, 12, 8, 8, 7, 7, 2 + }, + { + 14, 3, 3, 5, 3, 4, 5, 5, 3, 5, 4, 5, 4, 6, 5, 6, + 8, 14, 13, 8, 8, 13, 13, 8, 8, 13, 13, 8, 13, 13, 8, 13, + 13, 8, 13, 13, 7, 7, 13, 13, 13, 13, 8, 8, 13, 13, 7, 6, + 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 8, 7 + }, + { + 13, 5, 5, 5, 4, 4, 6, 4, 4, 6, 4, 5, 5, 5, 4, 3, + 6, 8, 10, 9, 8, 8, 7, 8, 13, 13, 7, 7, 8, 8, 7, 5, + 8, 7, 9, 9, 9, 6, 8, 7, 8, 13, 8, 7, 8, 7, 8, 5, + 8, 9, 8, 13, 8, 9, 13, 8, 12, 8, 8, 9, 9, 9, 8, 5 + }, + { + 9, 2, 3, 9, 2, 9, 9, 9, 2, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8 + } +}; +#endif + +/* MacroBlock Transform Type: 7.1.3.11, p89 + * 8x8:B + * 8x4:B:btm 8x4:B:top 8x4:B:both, + * 4x8:B:right 4x8:B:left 4x8:B:both + * 4x4:B 8x8:MB + * 8x4:MB:btm 8x4:MB:top 8x4,MB,both + * 4x8,MB,right 4x8,MB,left + * 4x4,MB */ +const uint16_t ff_vc1_ttmb_codes[3][16] = { + { + 0x0003, + 0x002E, 0x005F, 0x0000, + 0x0016, 0x0015, 0x0001, + 0x0004, 0x0014, + 0x02F1, 0x0179, 0x017B, + 0x0BC0, 0x0BC1, 0x05E1, + 0x017A + }, + { + 0x0006, + 0x0006, 0x0003, 0x0007, + 0x000F, 0x000E, 0x0000, + 0x0002, 0x0002, + 0x0014, 0x0011, 0x000B, + 0x0009, 0x0021, 0x0015, + 0x0020 + }, + { + 0x0006, + 0x0000, 0x000E, 0x0005, + 0x0002, 0x0003, 0x0003, + 0x000F, 0x0002, + 0x0081, 0x0021, 0x0009, + 0x0101, 0x0041, 0x0011, + 0x0100 + } +}; + +const uint8_t ff_vc1_ttmb_bits[3][16] = { + { + 2, + 6, 7, 2, + 5, 5, 2, + 3, 5, + 10, 9, 9, + 12, 12, 11, + 9 + }, + { + 3, + 4, 4, 4, + 4, 4, 3, + 3, 2, + 7, 7, 6, + 6, 8, 7, + 8 + }, + { + 3, + 3, 4, 5, + 3, 3, 4, + 4, 2, + 10, 8, 6, + 11, 9, 7, + 11 + } +}; + +/* TTBLK (Transform Type per Block) tables */ +const uint8_t ff_vc1_ttblk_codes[3][8] = { + { 0, 1, 3, 5, 16, 17, 18, 19}, + { 3, 0, 1, 2, 3, 5, 8, 9}, + { 1, 0, 1, 4, 6, 7, 10, 11} +}; +const uint8_t ff_vc1_ttblk_bits[3][8] = { + { 2, 2, 2, 3, 5, 5, 5, 5}, + { 2, 3, 3, 3, 3, 3, 4, 4}, + { 2, 3, 3, 3, 3, 3, 4, 4} +}; + +/* SUBBLKPAT tables, p93-94, reordered */ +const uint8_t ff_vc1_subblkpat_codes[3][15] = { + { 14, 12, 7, 11, 9, 26, 2, 10, 27, 8, 0, 6, 1, 15, 1}, + { 14, 0, 8, 15, 10, 4, 23, 13, 5, 9, 25, 3, 24, 22, 1}, + { 5, 6, 2, 2, 8, 0, 28, 3, 1, 3, 29, 1, 19, 18, 15} +}; +const uint8_t ff_vc1_subblkpat_bits[3][15] = { + { 5, 5, 5, 5, 5, 6, 4, 5, 6, 5, 4, 5, 4, 5, 1}, + { 4, 3, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 2}, + { 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4} +}; + +/* MV differential tables, p265 */ +const uint16_t ff_vc1_mv_diff_codes[4][73] = { + { + 0, 2, 3, 8, 576, 3, 2, 6, + 5, 577, 578, 7, 8, 9, 40, 19, + 37, 82, 21, 22, 23, 579, 580, 166, + 96, 167, 49, 194, 195, 581, 582, 583, + 292, 293, 294, 13, 2, 7, 24, 50, + 102, 295, 13, 7, 8, 18, 50, 103, + 38, 20, 21, 22, 39, 204, 103, 23, + 24, 25, 104, 410, 105, 106, 107, 108, + 109, 220, 411, 442, 222, 443, 446, 447, + 7 /* 73 elements */ + }, + { + 0, 4, 5, 3, 4, 3, 4, 5, + 20, 6, 21, 44, 45, 46, 3008, 95, + 112, 113, 57, 3009, 3010, 116, 117, 3011, + 118, 3012, 3013, 3014, 3015, 3016, 3017, 3018, + 3019, 3020, 3021, 3022, 1, 4, 15, 160, + 161, 41, 6, 11, 42, 162, 43, 119, + 56, 57, 58, 163, 236, 237, 3023, 119, + 120, 242, 122, 486, 1512, 487, 246, 494, + 1513, 495, 1514, 1515, 1516, 1517, 1518, 1519, + 31 /* 73 elements */ + }, + { + 0, 512, 513, 514, 515, 2, 3, 258, + 259, 260, 261, 262, 263, 264, 265, 266, + 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 281, 282, + 283, 284, 285, 286, 1, 5, 287, 288, + 289, 290, 6, 7, 291, 292, 293, 294, + 295, 296, 297, 298, 299, 300, 301, 302, + 303, 304, 305, 306, 307, 308, 309, 310, + 311, 312, 313, 314, 315, 316, 317, 318, + 319 /* 73 elements */ + }, + { + 0, 1, 1, 2, 3, 4, 1, 5, + 4, 3, 5, 8, 6, 9, 10, 11, + 12, 7, 104, 14, 105, 4, 10, 15, + 11, 6, 14, 8, 106, 107, 108, 15, + 109, 9, 55, 10, 1, 2, 1, 2, + 3, 12, 6, 2, 6, 7, 28, 7, + 15, 8, 5, 18, 29, 152, 77, 24, + 25, 26, 39, 108, 13, 109, 55, 56, + 57, 116, 11, 153, 234, 235, 118, 119, + 15 /* 73 elements */ + } +}; +const uint8_t ff_vc1_mv_diff_bits[4][73] = { + { + 6, 7, 7, 8, 14, 6, 5, 6, 7, 14, 14, 6, 6, 6, 8, 9, + 10, 9, 7, 7, 7, 14, 14, 10, 9, 10, 8, 10, 10, 14, 14, 14, + 13, 13, 13, 6, 3, 5, 6, 8, 9, 13, 5, 4, 4, 5, 7, 9, + 6, 5, 5, 5, 6, 9, 8, 5, 5, 5, 7, 10, 7, 7, 7, 7, + 7, 8, 10, 9, 8, 9, 9, 9, 3 /* 73 elements */ + }, + { + 5, 7, 7, 6, 6, 5, 5, 6, 7, 5, 7, 8, 8, 8, 14, 9, + 9, 9, 8, 14, 14, 9, 9, 14, 9, 14, 14, 14, 14, 14, 14, 14, + 14, 14, 14, 14, 2, 3, 6, 8, 8, 6, 3, 4, 6, 8, 6, 9, + 6, 6, 6, 8, 8, 8, 14, 7, 7, 8, 7, 9, 13, 9, 8, 9, + 13, 9, 13, 13, 13, 13, 13, 13, 5 /* 73 elements */ + + }, + { + 3, 12, 12, 12, 12, 3, 4, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 1, 5, 11, 11, 11, 11, 4, 4, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 11, 11 /* 73 elements */ + }, + { + 15, 11, 15, 15, 15, 15, 12, 15, 12, 11, 12, 12, 15, 12, 12, 12, + 12, 15, 15, 12, 15, 10, 11, 12, 11, 10, 11, 10, 15, 15, 15, 11, + 15, 10, 14, 10, 4, 4, 5, 7, 8, 9, 5, 3, 4, 5, 6, 8, + 5, 4, 3, 5, 6, 8, 7, 5, 5, 5, 6, 7, 9, 7, 6, 6, + 6, 7, 10, 8, 8, 8, 7, 7, 4 /* 73 elements */ + } +}; + +/* DC differentials low+hi-mo, p217 are the same as in msmpeg4data .h */ + +/* Scantables/ZZ scan are at 11.9 (p262) and 8.1.1.12 (p10) */ +const int8_t ff_vc1_normal_zz[64] = { + 0, 8, 1, 2, 9, 16, 24, 17, + 10, 3, 4, 11, 18, 25, 32, 40, + 33, 48, 26, 19, 12, 5, 6, 13, + 20, 27, 34, 41, 56, 49, 57, 42, + 35, 28, 21, 14, 7, 15, 22, 29, + 36, 43, 50, 58, 51, 59, 44, 37, + 30, 23, 31, 38, 45, 52, 60, 53, + 61, 46, 39, 47, 54, 62, 55, 63 +}; + +const int8_t ff_vc1_horizontal_zz [64] = /* Table 227 */ +{ + 0, 1, 8, 2, 3, 9, 16, 24, + 17, 10, 4, 5, 11, 18, 25, 32, + 40, 48, 33, 26, 19, 12, 6, 7, + 13, 20, 27, 34, 41, 56, 49, 57, + 42, 35, 28, 21, 14, 15, 22, 29, + 36, 43, 50, 58, 51, 44, 37, 30, + 23, 31, 38, 45, 52, 59, 60, 53, + 46, 39, 47, 54, 61, 62, 55, 63 +}; + +const int8_t ff_vc1_vertical_zz [64] = /* Table 228 */ +{ + 0, 8, 16, 1, 24, 32, 40, 9, + 2, 3, 10, 17, 25, 48, 56, 41, + 33, 26, 18, 11, 4, 5, 12, 19, + 27, 34, 49, 57, 50, 42, 35, 28, + 20, 13, 6, 7, 14, 21, 29, 36, + 43, 51, 58, 59, 52, 44, 37, 30, + 22, 15, 23, 31, 38, 45, 60, 53, + 46, 39, 47, 54, 61, 62, 55, 63 +}; + +const int8_t ff_vc1_simple_progressive_8x8_zz [64] = +/* Table 229 */ +{ + 0, 8, 1, 2, 9, 16, 24, 17, + 10, 3, 4, 11, 18, 25, 32, 40, + 48, 56, 41, 33, 26, 19, 12, 5, + 6, 13, 20, 27, 34, 49, 57, 58, + 50, 42, 35, 28, 21, 14, 7, 15, + 22, 29, 36, 43, 51, 59, 60, 52, + 44, 37, 30, 23, 31, 38, 45, 53, + 61, 62, 54, 46, 39, 47, 55, 63 +}; + +const int8_t ff_vc1_simple_progressive_8x4_zz [32] = /* Table 230 */ +{ + 0, 1, 2, 8, 3, 9, 10, 16, + 4, 11, 17, 24, 18, 12, 5, 19, + 25, 13, 20, 26, 27, 6, 21, 28, + 14, 22, 29, 7, 30, 15, 23, 31 +}; + +const int8_t ff_vc1_simple_progressive_4x8_zz [32] = /* Table 231 */ +{ + 0, 8, 1, 16, + 9, 24, 17, 2, + 32, 10, 25, 40, + 18, 48, 33, 26, + 56, 41, 34, 3, + 49, 57, 11, 42, + 19, 50, 27, 58, + 35, 43, 51, 59 +}; + +/* Table 232 */ +const int8_t ff_vc1_simple_progressive_4x4_zz [16] = +{ + 0, 8, 16, 1, + 9, 24, 17, 2, + 10, 18, 25, 3, + 11, 26, 19, 27 +}; + +const int8_t ff_vc1_adv_progressive_8x4_zz [32] = /* Table 233 */ +{ + 0, 8, 1, 16, 2, 9, 10, 3, + 24, 17, 4, 11, 18, 12, 5, 19, + 25, 13, 20, 26, 27, 6, 21, 28, + 14, 22, 29, 7, 30, 15, 23, 31 +}; + +const int8_t ff_vc1_adv_progressive_4x8_zz [32] = /* Table 234 */ +{ + 0, 1, 8, 2, + 9, 16, 17, 24, + 10, 32, 25, 18, + 40, 3, 33, 26, + 48, 11, 56, 41, + 34, 49, 57, 42, + 19, 50, 27, 58, + 35, 43, 51, 59 +}; + +const int8_t ff_vc1_adv_interlaced_8x8_zz [64] = /* Table 235 */ +{ + 0, 8, 1, 16, 24, 9, 2, 32, + 40, 48, 56, 17, 10, 3, 25, 18, + 11, 4, 33, 41, 49, 57, 26, 34, + 42, 50, 58, 19, 12, 5, 27, 20, + 13, 6, 35, 28, 21, 14, 7, 15, + 22, 29, 36, 43, 51, 59, 60, 52, + 44, 37, 30, 23, 31, 38, 45, 53, + 61, 62, 54, 46, 39, 47, 55, 63 +}; + +const int8_t ff_vc1_adv_interlaced_8x4_zz [32] = /* Table 236 */ +{ + 0, 8, 16, 24, 1, 9, 2, 17, + 25, 10, 3, 18, 26, 4, 11, 19, + 12, 5, 13, 20, 27, 6, 21, 28, + 14, 22, 29, 7, 30, 15, 23, 31 +}; + +const int8_t ff_vc1_adv_interlaced_4x8_zz [32] = /* Table 237 */ +{ + 0, 1, 2, 8, + 16, 9, 24, 17, + 10, 3, 32, 40, + 48, 56, 25, 18, + 33, 26, 41, 34, + 49, 57, 11, 42, + 19, 50, 27, 58, + 35, 43, 51, 59 +}; + +const int8_t ff_vc1_adv_interlaced_4x4_zz [16] = /* Table 238 */ +{ + 0, 8, 16, 24, + 1, 9, 17, 2, + 25, 10, 18, 3, + 26, 11, 19, 27 +}; + + +/* DQScale as specified in 8.1.3.9 - almost identical to 0x40000/i */ +const int32_t ff_vc1_dqscale[63] = { +0x40000, 0x20000, 0x15555, 0x10000, 0xCCCD, 0xAAAB, 0x9249, 0x8000, + 0x71C7, 0x6666, 0x5D17, 0x5555, 0x4EC5, 0x4925, 0x4444, 0x4000, + 0x3C3C, 0x38E4, 0x35E5, 0x3333, 0x30C3, 0x2E8C, 0x2C86, 0x2AAB, + 0x28F6, 0x2762, 0x25ED, 0x2492, 0x234F, 0x2222, 0x2108, 0x2000, + 0x1F08, 0x1E1E, 0x1D42, 0x1C72, 0x1BAD, 0x1AF3, 0x1A42, 0x199A, + 0x18FA, 0x1862, 0x17D0, 0x1746, 0x16C1, 0x1643, 0x15CA, 0x1555, + 0x14E6, 0x147B, 0x1414, 0x13B1, 0x1352, 0x12F7, 0x129E, 0x1249, + 0x11F7, 0x11A8, 0x115B, 0x1111, 0x10C9, 0x1084, 0x1000 +}; diff --git a/contrib/ffmpeg/libavcodec/vc1data.h b/contrib/ffmpeg/libavcodec/vc1data.h index 9b0a854bf..5d995d754 100644 --- a/contrib/ffmpeg/libavcodec/vc1data.h +++ b/contrib/ffmpeg/libavcodec/vc1data.h @@ -25,302 +25,96 @@ * VC-1 tables. */ -#ifndef VC1DATA_H -#define VC1DATA_H +#ifndef FFMPEG_VC1DATA_H +#define FFMPEG_VC1DATA_H + +#include +#include "bitstream.h" +#include "rational.h" + +/** Table for conversion between TTBLK and TTMB */ +extern const int ff_vc1_ttblk_to_tt[3][8]; + +extern const int ff_vc1_ttfrm_to_tt[4]; + +/** MV P mode - the 5th element is only used for mode 1 */ +extern const uint8_t ff_vc1_mv_pmode_table[2][5]; +extern const uint8_t ff_vc1_mv_pmode_table2[2][4]; + +extern const int ff_vc1_fps_nr[5], ff_vc1_fps_dr[2]; +extern const uint8_t ff_vc1_pquant_table[3][32]; + +/** @name VC-1 VLC tables and defines + * @todo TODO move this into the context + */ +//@{ +#define VC1_BFRACTION_VLC_BITS 7 +extern VLC ff_vc1_bfraction_vlc; +#define VC1_IMODE_VLC_BITS 4 +extern VLC ff_vc1_imode_vlc; +#define VC1_NORM2_VLC_BITS 3 +extern VLC ff_vc1_norm2_vlc; +#define VC1_NORM6_VLC_BITS 9 +extern VLC ff_vc1_norm6_vlc; +/* Could be optimized, one table only needs 8 bits */ +#define VC1_TTMB_VLC_BITS 9 //12 +extern VLC ff_vc1_ttmb_vlc[3]; +#define VC1_MV_DIFF_VLC_BITS 9 //15 +extern VLC ff_vc1_mv_diff_vlc[4]; +#define VC1_CBPCY_P_VLC_BITS 9 //14 +extern VLC ff_vc1_cbpcy_p_vlc[4]; +#define VC1_4MV_BLOCK_PATTERN_VLC_BITS 6 +extern VLC ff_vc1_4mv_block_pattern_vlc[4]; +#define VC1_TTBLK_VLC_BITS 5 +extern VLC ff_vc1_ttblk_vlc[3]; +#define VC1_SUBBLKPAT_VLC_BITS 6 +extern VLC ff_vc1_subblkpat_vlc[3]; + +extern VLC ff_vc1_ac_coeff_table[8]; +//@} + #if 0 //original bfraction from vc9data.h, not conforming to standard -/* Denominator used for vc1_bfraction_lut */ +/* Denominator used for ff_vc1_bfraction_lut */ #define B_FRACTION_DEN 840 /* bfraction is fractional, we scale to the GCD 3*5*7*8 = 840 */ -const int16_t vc1_bfraction_lut[23] = { - 420 /*1/2*/, 280 /*1/3*/, 560 /*2/3*/, 210 /*1/4*/, - 630 /*3/4*/, 168 /*1/5*/, 336 /*2/5*/, - 504 /*3/5*/, 672 /*4/5*/, 140 /*1/6*/, 700 /*5/6*/, - 120 /*1/7*/, 240 /*2/7*/, 360 /*3/7*/, 480 /*4/7*/, - 600 /*5/7*/, 720 /*6/7*/, 105 /*1/8*/, 315 /*3/8*/, - 525 /*5/8*/, 735 /*7/8*/, - -1 /*inv.*/, 0 /*BI fm*/ -}; +extern const int16_t ff_vc1_bfraction_lut[23]; #else -/* Denominator used for vc1_bfraction_lut */ +/* Denominator used for ff_vc1_bfraction_lut */ #define B_FRACTION_DEN 256 /* pre-computed scales for all bfractions and base=256 */ -static const int16_t vc1_bfraction_lut[23] = { - 128 /*1/2*/, 85 /*1/3*/, 170 /*2/3*/, 64 /*1/4*/, - 192 /*3/4*/, 51 /*1/5*/, 102 /*2/5*/, - 153 /*3/5*/, 204 /*4/5*/, 43 /*1/6*/, 215 /*5/6*/, - 37 /*1/7*/, 74 /*2/7*/, 111 /*3/7*/, 148 /*4/7*/, - 185 /*5/7*/, 222 /*6/7*/, 32 /*1/8*/, 96 /*3/8*/, - 160 /*5/8*/, 224 /*7/8*/, - -1 /*inv.*/, 0 /*BI fm*/ -}; +extern const int16_t ff_vc1_bfraction_lut[23]; #endif -static const uint8_t vc1_bfraction_bits[23] = { - 3, 3, 3, 3, - 3, 3, 3, - 7, 7, 7, 7, - 7, 7, 7, 7, - 7, 7, 7, 7, - 7, 7, - 7, 7 -}; -static const uint8_t vc1_bfraction_codes[23] = { - 0, 1, 2, 3, - 4, 5, 6, - 112, 113, 114, 115, - 116, 117, 118, 119, - 120, 121, 122, 123, - 124, 125, - 126, 127 -}; +extern const uint8_t ff_vc1_bfraction_bits[23]; +extern const uint8_t ff_vc1_bfraction_codes[23]; //Same as H.264 -static const AVRational vc1_pixel_aspect[16]={ - {0, 1}, - {1, 1}, - {12, 11}, - {10, 11}, - {16, 11}, - {40, 33}, - {24, 11}, - {20, 11}, - {32, 11}, - {80, 33}, - {18, 11}, - {15, 11}, - {64, 33}, - {160, 99}, - {0, 1}, - {0, 1} -}; +extern const AVRational ff_vc1_pixel_aspect[16]; /* BitPlane IMODE - such a small table... */ -static const uint8_t vc1_imode_codes[7] = { - 0, 2, 1, 3, 1, 2, 3 -}; -static const uint8_t vc1_imode_bits[7] = { - 4, 2, 3, 2, 4, 3, 3 -}; +extern const uint8_t ff_vc1_imode_codes[7]; +extern const uint8_t ff_vc1_imode_bits[7]; /* Normal-2 imode */ -static const uint8_t vc1_norm2_codes[4] = { - 0, 4, 5, 3 -}; -static const uint8_t vc1_norm2_bits[4] = { - 1, 3, 3, 2 -}; - -static const uint16_t vc1_norm6_codes[64] = { -0x001, 0x002, 0x003, 0x000, 0x004, 0x001, 0x002, 0x047, 0x005, 0x003, 0x004, 0x04B, 0x005, 0x04D, 0x04E, 0x30E, -0x006, 0x006, 0x007, 0x053, 0x008, 0x055, 0x056, 0x30D, 0x009, 0x059, 0x05A, 0x30C, 0x05C, 0x30B, 0x30A, 0x037, -0x007, 0x00A, 0x00B, 0x043, 0x00C, 0x045, 0x046, 0x309, 0x00D, 0x049, 0x04A, 0x308, 0x04C, 0x307, 0x306, 0x036, -0x00E, 0x051, 0x052, 0x305, 0x054, 0x304, 0x303, 0x035, 0x058, 0x302, 0x301, 0x034, 0x300, 0x033, 0x032, 0x007, -}; - -static const uint8_t vc1_norm6_bits[64] = { - 1, 4, 4, 8, 4, 8, 8, 10, 4, 8, 8, 10, 8, 10, 10, 13, - 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9, - 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9, - 8, 10, 10, 13, 10, 13, 13, 9, 10, 13, 13, 9, 13, 9, 9, 6, -}; +extern const uint8_t ff_vc1_norm2_codes[4]; +extern const uint8_t ff_vc1_norm2_bits[4]; +extern const uint16_t ff_vc1_norm6_codes[64]; +extern const uint8_t ff_vc1_norm6_bits[64]; /* Normal-6 imode */ -static const uint8_t vc1_norm6_spec[64][5] = { -{ 0, 1, 1 }, -{ 1, 2, 4 }, -{ 2, 3, 4 }, -{ 3, 0, 8 }, -{ 4, 4, 4 }, -{ 5, 1, 8 }, -{ 6, 2, 8 }, -{ 7, 2, 5, 7, 5 }, -{ 8, 5, 4 }, -{ 9, 3, 8 }, -{10, 4, 8 }, -{11, 2, 5, 11, 5 }, -{12, 5, 8 }, -{13, 2, 5, 13, 5 }, -{14, 2, 5, 14, 5 }, -{15, 3, 5, 14, 8 }, -{16, 6, 4 }, -{17, 6, 8 }, -{18, 7, 8 }, -{19, 2, 5, 19, 5 }, -{20, 8, 8 }, -{21, 2, 5, 21, 5 }, -{22, 2, 5, 22, 5 }, -{23, 3, 5, 13, 8 }, -{24, 9, 8 }, -{25, 2, 5, 25, 5 }, -{26, 2, 5, 26, 5 }, -{27, 3, 5, 12, 8 }, -{28, 2, 5, 28, 5 }, -{29, 3, 5, 11, 8 }, -{30, 3, 5, 10, 8 }, -{31, 3, 5, 7, 4 }, -{32, 7, 4 }, -{33, 10, 8 }, -{34, 11, 8 }, -{35, 2, 5, 3, 5 }, -{36, 12, 8 }, -{37, 2, 5, 5, 5 }, -{38, 2, 5, 6, 5 }, -{39, 3, 5, 9, 8 }, -{40, 13, 8 }, -{41, 2, 5, 9, 5 }, -{42, 2, 5, 10, 5 }, -{43, 3, 5, 8, 8 }, -{44, 2, 5, 12, 5 }, -{45, 3, 5, 7, 8 }, -{46, 3, 5, 6, 8 }, -{47, 3, 5, 6, 4 }, -{48, 14, 8 }, -{49, 2, 5, 17, 5 }, -{50, 2, 5, 18, 5 }, -{51, 3, 5, 5, 8 }, -{52, 2, 5, 20, 5 }, -{53, 3, 5, 4, 8 }, -{54, 3, 5, 3, 8 }, -{55, 3, 5, 5, 4 }, -{56, 2, 5, 24, 5 }, -{57, 3, 5, 2, 8 }, -{58, 3, 5, 1, 8 }, -{59, 3, 5, 4, 4 }, -{60, 3, 5, 0, 8 }, -{61, 3, 5, 3, 4 }, -{62, 3, 5, 2, 4 }, -{63, 3, 5, 1, 1 }, -}; +extern const uint8_t ff_vc1_norm6_spec[64][5]; /* 4MV Block pattern VLC tables */ -static const uint8_t vc1_4mv_block_pattern_codes[4][16] = { - { 14, 58, 59, 25, 12, 26, 15, 15, 13, 24, 27, 0, 28, 1, 2, 2}, - { 8, 18, 19, 4, 20, 5, 30, 11, 21, 31, 6, 12, 7, 13, 14, 0}, - { 15, 6, 7, 2, 8, 3, 28, 9, 10, 29, 4, 11, 5, 12, 13, 0}, - { 0, 11, 12, 4, 13, 5, 30, 16, 14, 31, 6, 17, 7, 18, 19, 10} -}; -static const uint8_t vc1_4mv_block_pattern_bits[4][16] = { - { 5, 6, 6, 5, 5, 5, 5, 4, 5, 5, 5, 3, 5, 3, 3, 2}, - { 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4, 4, 4, 4, 4, 2}, - { 4, 4, 4, 4, 4, 4, 5, 4, 4, 5, 4, 4, 4, 4, 4, 3}, - { 2, 4, 4, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4} -}; +extern const uint8_t ff_vc1_4mv_block_pattern_codes[4][16]; +extern const uint8_t ff_vc1_4mv_block_pattern_bits[4][16]; -const uint8_t wmv3_dc_scale_table[32]={ - 0, 2, 4, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21 -}; +extern const uint8_t wmv3_dc_scale_table[32]; /* P-Picture CBPCY VLC tables */ -#if 1 // Looks like original tables are not conforming to standard at all. Are they used for old WMV? -static const uint16_t vc1_cbpcy_p_codes[4][64] = { - { - 0, 6, 15, 13, 13, 11, 3, 13, 5, 8, 49, 10, 12, 114, 102, 119, - 1, 54, 96, 8, 10, 111, 5, 15, 12, 10, 2, 12, 13, 115, 53, 63, - 1, 7, 1, 7, 14, 12, 4, 14, 1, 9, 97, 11, 7, 58, 52, 62, - 4, 103, 1, 9, 11, 56, 101, 118, 4, 110, 100, 30, 2, 5, 4, 3 - }, - { - 0, 9, 1, 18, 5, 14, 237, 26, 3, 121, 3, 22, 13, 16, 6, 30, - 2, 10, 1, 20, 12, 241, 5, 28, 16, 12, 3, 24, 28, 124, 239, 247, - 1, 240, 1, 19, 18, 15, 4, 27, 1, 122, 2, 23, 1, 17, 7, 31, - 1, 11, 2, 21, 19, 246, 238, 29, 17, 13, 236, 25, 58, 63, 8, 125 - }, - { - 0, 201, 25, 231, 5, 221, 1, 3, 2, 414, 2, 241, 16, 225, 195, 492, - 2, 412, 1, 240, 7, 224, 98, 245, 1, 220, 96, 5, 9, 230, 101, 247, - 1, 102, 1, 415, 24, 3, 2, 244, 3, 54, 3, 484, 17, 114, 200, 493, - 3, 413, 1, 4, 13, 113, 99, 485, 4, 111, 194, 243, 5, 29, 26, 31 - }, - { - 0, 28, 12, 44, 3, 36, 20, 52, 2, 32, 16, 48, 8, 40, 24, 28, - 1, 30, 14, 46, 6, 38, 22, 54, 3, 34, 18, 50, 10, 42, 26, 30, - 1, 29, 13, 45, 5, 37, 21, 53, 2, 33, 17, 49, 9, 41, 25, 29, - 1, 31, 15, 47, 7, 39, 23, 55, 4, 35, 19, 51, 11, 43, 27, 31 - } -}; - -static const uint8_t vc1_cbpcy_p_bits[4][64] = { - { - 13, 13, 7, 13, 7, 13, 13, 12, 6, 13, 7, 12, 6, 8, 8, 8, - 5, 7, 8, 12, 6, 8, 13, 12, 7, 13, 13, 12, 6, 8, 7, 7, - 6, 13, 8, 12, 7, 13, 13, 12, 7, 13, 8, 12, 5, 7, 7, 7, - 6, 8, 13, 12, 6, 7, 8, 8, 5, 8, 8, 6, 3, 3, 3, 2 - }, - { - 14, 13, 8, 13, 3, 13, 8, 13, 3, 7, 8, 13, 4, 13, 13, 13, - 3, 13, 13, 13, 4, 8, 13, 13, 5, 13, 13, 13, 5, 7, 8, 8, - 3, 8, 14, 13, 5, 13, 13, 13, 4, 7, 13, 13, 6, 13, 13, 13, - 5, 13, 8, 13, 5, 8, 8, 13, 5, 13, 8, 13, 6, 6, 13, 7 - }, - { - 13, 8, 6, 8, 4, 8, 13, 12, 4, 9, 8, 8, 5, 8, 8, 9, - 5, 9, 10, 8, 4, 8, 7, 8, 6, 8, 7, 13, 4, 8, 7, 8, - 5, 7, 8, 9, 6, 13, 13, 8, 4, 6, 8, 9, 5, 7, 8, 9, - 5, 9, 9, 13, 5, 7, 7, 9, 4, 7, 8, 8, 3, 5, 5, 5 - }, - { - 9, 9, 9, 9, 2, 9, 9, 9, 2, 9, 9, 9, 9, 9, 9, 8, - 3, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, - 2, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8 - } -}; -#else -static const uint16_t vc1_cbpcy_p_codes[4][64] = { - { - 0, 1, 1, 4, 5, 1, 12, 4, 13, 14, 10, 11, 12, 7, 13, 2, - 15, 1, 96, 1, 49, 97, 2, 100, 3, 4, 5, 101, 102, 52, 53, 4, - 6, 7, 54, 103, 8, 9, 10, 110, 11, 12, 111, 56, 114, 58, 115, 5, - 13, 7, 8, 9, 10, 11, 12, 30, 13, 14, 15, 118, 119, 62, 63, 3 - }, - { - 0, 1, 2, 1, 3, 1, 16, 17, 5, 18, 12, 19, 13, 1, 28, 58, - 1, 1, 1, 2, 3, 2, 3, 236, 237, 4, 5, 238, 6, 7, 239, 8, - 9, 240, 10, 11, 121, 122, 12, 13, 14, 15, 241, 246, 16, 17, 124, 63, - 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 247, 125 - }, - { - 0, 1, 2, 3, 2, 3, 1, 4, 5, 24, 7, 13, 16, 17, 9, 5, - 25, 1, 1, 1, 2, 3, 96, 194, 1, 2, 98, 99, 195, 200, 101, 26, - 201, 102, 412, 413, 414, 54, 220, 111, 221, 3, 224, 113, 225, 114, 230, 29, - 231, 415, 240, 4, 241, 484, 5, 243, 3, 244, 245, 485, 492, 493, 247, 31 - }, - { - 0, 1, 1, 1, 2, 2, 3, 4, 3, 5, 6, 7, 8, 9, 10, 11, - 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, - 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, - 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 28, 29, 30, 31 - } -}; -static const uint8_t vc1_cbpcy_p_bits[4][64] = { - { - 13, 6, 5, 6, 6, 7, 7, 5, 7, 7, 6, 6, 6, 5, 6, 3, - 7, 8, 8, 13, 7, 8, 13, 8, 13, 13, 13, 8, 8, 7, 7, 3, - 13, 13, 7, 8, 13, 13, 13, 8, 13, 13, 8, 7, 8, 7, 8, 3, - 13, 12, 12, 12, 12, 12, 12, 6, 12, 12, 12, 8, 8, 7, 7, 2 - }, - { - 14, 3, 3, 5, 3, 4, 5, 5, 3, 5, 4, 5, 4, 6, 5, 6, - 8, 14, 13, 8, 8, 13, 13, 8, 8, 13, 13, 8, 13, 13, 8, 13, - 13, 8, 13, 13, 7, 7, 13, 13, 13, 13, 8, 8, 13, 13, 7, 6, - 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 8, 7 - }, - { - 13, 5, 5, 5, 4, 4, 6, 4, 4, 6, 4, 5, 5, 5, 4, 3, - 6, 8, 10, 9, 8, 8, 7, 8, 13, 13, 7, 7, 8, 8, 7, 5, - 8, 7, 9, 9, 9, 6, 8, 7, 8, 13, 8, 7, 8, 7, 8, 5, - 8, 9, 8, 13, 8, 9, 13, 8, 12, 8, 8, 9, 9, 9, 8, 5 - }, - { - 9, 2, 3, 9, 2, 9, 9, 9, 2, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8 - } -}; -#endif +extern const uint16_t ff_vc1_cbpcy_p_codes[4][64]; +extern const uint8_t ff_vc1_cbpcy_p_bits[4][64]; /* MacroBlock Transform Type: 7.1.3.11, p89 * 8x8:B @@ -330,323 +124,40 @@ static const uint8_t vc1_cbpcy_p_bits[4][64] = { * 8x4:MB:btm 8x4:MB:top 8x4,MB,both * 4x8,MB,right 4x8,MB,left * 4x4,MB */ -static const uint16_t vc1_ttmb_codes[3][16] = { - { - 0x0003, - 0x002E, 0x005F, 0x0000, - 0x0016, 0x0015, 0x0001, - 0x0004, 0x0014, - 0x02F1, 0x0179, 0x017B, - 0x0BC0, 0x0BC1, 0x05E1, - 0x017A - }, - { - 0x0006, - 0x0006, 0x0003, 0x0007, - 0x000F, 0x000E, 0x0000, - 0x0002, 0x0002, - 0x0014, 0x0011, 0x000B, - 0x0009, 0x0021, 0x0015, - 0x0020 - }, - { - 0x0006, - 0x0000, 0x000E, 0x0005, - 0x0002, 0x0003, 0x0003, - 0x000F, 0x0002, - 0x0081, 0x0021, 0x0009, - 0x0101, 0x0041, 0x0011, - 0x0100 - } -}; +extern const uint16_t ff_vc1_ttmb_codes[3][16]; -static const uint8_t vc1_ttmb_bits[3][16] = { - { - 2, - 6, 7, 2, - 5, 5, 2, - 3, 5, - 10, 9, 9, - 12, 12, 11, - 9 - }, - { - 3, - 4, 4, 4, - 4, 4, 3, - 3, 2, - 7, 7, 6, - 6, 8, 7, - 8 - }, - { - 3, - 3, 4, 5, - 3, 3, 4, - 4, 2, - 10, 8, 6, - 11, 9, 7, - 11 - } -}; +extern const uint8_t ff_vc1_ttmb_bits[3][16]; /* TTBLK (Transform Type per Block) tables */ -static const uint8_t vc1_ttblk_codes[3][8] = { - { 0, 1, 3, 5, 16, 17, 18, 19}, - { 3, 0, 1, 2, 3, 5, 8, 9}, - { 1, 0, 1, 4, 6, 7, 10, 11} -}; -static const uint8_t vc1_ttblk_bits[3][8] = { - { 2, 2, 2, 3, 5, 5, 5, 5}, - { 2, 3, 3, 3, 3, 3, 4, 4}, - { 2, 3, 3, 3, 3, 3, 4, 4} -}; +extern const uint8_t ff_vc1_ttblk_codes[3][8]; +extern const uint8_t ff_vc1_ttblk_bits[3][8]; /* SUBBLKPAT tables, p93-94, reordered */ -static const uint8_t vc1_subblkpat_codes[3][15] = { - { 14, 12, 7, 11, 9, 26, 2, 10, 27, 8, 0, 6, 1, 15, 1}, - { 14, 0, 8, 15, 10, 4, 23, 13, 5, 9, 25, 3, 24, 22, 1}, - { 5, 6, 2, 2, 8, 0, 28, 3, 1, 3, 29, 1, 19, 18, 15} -}; -static const uint8_t vc1_subblkpat_bits[3][15] = { - { 5, 5, 5, 5, 5, 6, 4, 5, 6, 5, 4, 5, 4, 5, 1}, - { 4, 3, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 2}, - { 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4} -}; +extern const uint8_t ff_vc1_subblkpat_codes[3][15]; +extern const uint8_t ff_vc1_subblkpat_bits[3][15]; /* MV differential tables, p265 */ -static const uint16_t vc1_mv_diff_codes[4][73] = { - { - 0, 2, 3, 8, 576, 3, 2, 6, - 5, 577, 578, 7, 8, 9, 40, 19, - 37, 82, 21, 22, 23, 579, 580, 166, - 96, 167, 49, 194, 195, 581, 582, 583, - 292, 293, 294, 13, 2, 7, 24, 50, - 102, 295, 13, 7, 8, 18, 50, 103, - 38, 20, 21, 22, 39, 204, 103, 23, - 24, 25, 104, 410, 105, 106, 107, 108, - 109, 220, 411, 442, 222, 443, 446, 447, - 7 /* 73 elements */ - }, - { - 0, 4, 5, 3, 4, 3, 4, 5, - 20, 6, 21, 44, 45, 46, 3008, 95, - 112, 113, 57, 3009, 3010, 116, 117, 3011, - 118, 3012, 3013, 3014, 3015, 3016, 3017, 3018, - 3019, 3020, 3021, 3022, 1, 4, 15, 160, - 161, 41, 6, 11, 42, 162, 43, 119, - 56, 57, 58, 163, 236, 237, 3023, 119, - 120, 242, 122, 486, 1512, 487, 246, 494, - 1513, 495, 1514, 1515, 1516, 1517, 1518, 1519, - 31 /* 73 elements */ - }, - { - 0, 512, 513, 514, 515, 2, 3, 258, - 259, 260, 261, 262, 263, 264, 265, 266, - 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 279, 280, 281, 282, - 283, 284, 285, 286, 1, 5, 287, 288, - 289, 290, 6, 7, 291, 292, 293, 294, - 295, 296, 297, 298, 299, 300, 301, 302, - 303, 304, 305, 306, 307, 308, 309, 310, - 311, 312, 313, 314, 315, 316, 317, 318, - 319 /* 73 elements */ - }, - { - 0, 1, 1, 2, 3, 4, 1, 5, - 4, 3, 5, 8, 6, 9, 10, 11, - 12, 7, 104, 14, 105, 4, 10, 15, - 11, 6, 14, 8, 106, 107, 108, 15, - 109, 9, 55, 10, 1, 2, 1, 2, - 3, 12, 6, 2, 6, 7, 28, 7, - 15, 8, 5, 18, 29, 152, 77, 24, - 25, 26, 39, 108, 13, 109, 55, 56, - 57, 116, 11, 153, 234, 235, 118, 119, - 15 /* 73 elements */ - } -}; -static const uint8_t vc1_mv_diff_bits[4][73] = { - { - 6, 7, 7, 8, 14, 6, 5, 6, 7, 14, 14, 6, 6, 6, 8, 9, - 10, 9, 7, 7, 7, 14, 14, 10, 9, 10, 8, 10, 10, 14, 14, 14, - 13, 13, 13, 6, 3, 5, 6, 8, 9, 13, 5, 4, 4, 5, 7, 9, - 6, 5, 5, 5, 6, 9, 8, 5, 5, 5, 7, 10, 7, 7, 7, 7, - 7, 8, 10, 9, 8, 9, 9, 9, 3 /* 73 elements */ - }, - { - 5, 7, 7, 6, 6, 5, 5, 6, 7, 5, 7, 8, 8, 8, 14, 9, - 9, 9, 8, 14, 14, 9, 9, 14, 9, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 2, 3, 6, 8, 8, 6, 3, 4, 6, 8, 6, 9, - 6, 6, 6, 8, 8, 8, 14, 7, 7, 8, 7, 9, 13, 9, 8, 9, - 13, 9, 13, 13, 13, 13, 13, 13, 5 /* 73 elements */ - - }, - { - 3, 12, 12, 12, 12, 3, 4, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 1, 5, 11, 11, 11, 11, 4, 4, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 11 /* 73 elements */ - }, - { - 15, 11, 15, 15, 15, 15, 12, 15, 12, 11, 12, 12, 15, 12, 12, 12, - 12, 15, 15, 12, 15, 10, 11, 12, 11, 10, 11, 10, 15, 15, 15, 11, - 15, 10, 14, 10, 4, 4, 5, 7, 8, 9, 5, 3, 4, 5, 6, 8, - 5, 4, 3, 5, 6, 8, 7, 5, 5, 5, 6, 7, 9, 7, 6, 6, - 6, 7, 10, 8, 8, 8, 7, 7, 4 /* 73 elements */ - } -}; +extern const uint16_t ff_vc1_mv_diff_codes[4][73]; +extern const uint8_t ff_vc1_mv_diff_bits[4][73]; /* DC differentials low+hi-mo, p217 are the same as in msmpeg4data .h */ /* Scantables/ZZ scan are at 11.9 (p262) and 8.1.1.12 (p10) */ -static const int8_t vc1_normal_zz[64] = { - 0, 8, 1, 2, 9, 16, 24, 17, - 10, 3, 4, 11, 18, 25, 32, 40, - 33, 48, 26, 19, 12, 5, 6, 13, - 20, 27, 34, 41, 56, 49, 57, 42, - 35, 28, 21, 14, 7, 15, 22, 29, - 36, 43, 50, 58, 51, 59, 44, 37, - 30, 23, 31, 38, 45, 52, 60, 53, - 61, 46, 39, 47, 54, 62, 55, 63 -}; - -static const int8_t vc1_horizontal_zz [64] = /* Table 227 */ -{ - 0, 1, 8, 2, 3, 9, 16, 24, - 17, 10, 4, 5, 11, 18, 25, 32, - 40, 48, 33, 26, 19, 12, 6, 7, - 13, 20, 27, 34, 41, 56, 49, 57, - 42, 35, 28, 21, 14, 15, 22, 29, - 36, 43, 50, 58, 51, 44, 37, 30, - 23, 31, 38, 45, 52, 59, 60, 53, - 46, 39, 47, 54, 61, 62, 55, 63 -}; - -static const int8_t vc1_vertical_zz [64] = /* Table 228 */ -{ - 0, 8, 16, 1, 24, 32, 40, 9, - 2, 3, 10, 17, 25, 48, 56, 41, - 33, 26, 18, 11, 4, 5, 12, 19, - 27, 34, 49, 57, 50, 42, 35, 28, - 20, 13, 6, 7, 14, 21, 29, 36, - 43, 51, 58, 59, 52, 44, 37, 30, - 22, 15, 23, 31, 38, 45, 60, 53, - 46, 39, 47, 54, 61, 62, 55, 63 -}; - -static const int8_t vc1_simple_progressive_8x8_zz [64] = -/* Table 229 */ -{ - 0, 8, 1, 2, 9, 16, 24, 17, - 10, 3, 4, 11, 18, 25, 32, 40, - 48, 56, 41, 33, 26, 19, 12, 5, - 6, 13, 20, 27, 34, 49, 57, 58, - 50, 42, 35, 28, 21, 14, 7, 15, - 22, 29, 36, 43, 51, 59, 60, 52, - 44, 37, 30, 23, 31, 38, 45, 53, - 61, 62, 54, 46, 39, 47, 55, 63 -}; - -static const int8_t vc1_simple_progressive_8x4_zz [32] = /* Table 230 */ -{ - 0, 1, 2, 8, 3, 9, 10, 16, - 4, 11, 17, 24, 18, 12, 5, 19, - 25, 13, 20, 26, 27, 6, 21, 28, - 14, 22, 29, 7, 30, 15, 23, 31 -}; - -static const int8_t vc1_simple_progressive_4x8_zz [32] = /* Table 231 */ -{ - 0, 8, 1, 16, - 9, 24, 17, 2, - 32, 10, 25, 40, - 18, 48, 33, 26, - 56, 41, 34, 3, - 49, 57, 11, 42, - 19, 50, 27, 58, - 35, 43, 51, 59 -}; - -/* Table 232 */ -static const int8_t vc1_simple_progressive_4x4_zz [16] = -{ - 0, 8, 16, 1, - 9, 24, 17, 2, - 10, 18, 25, 3, - 11, 26, 19, 27 -}; - -static const int8_t vc1_adv_progressive_8x4_zz [32] = /* Table 233 */ -{ - 0, 8, 1, 16, 2, 9, 10, 3, - 24, 17, 4, 11, 18, 12, 5, 19, - 25, 13, 20, 26, 27, 6, 21, 28, - 14, 22, 29, 7, 30, 15, 23, 31 -}; - -static const int8_t vc1_adv_progressive_4x8_zz [32] = /* Table 234 */ -{ - 0, 1, 8, 2, - 9, 16, 17, 24, - 10, 32, 25, 18, - 40, 3, 33, 26, - 48, 11, 56, 41, - 34, 49, 57, 42, - 19, 50, 27, 58, - 35, 43, 51, 59 -}; - -static const int8_t vc1_adv_interlaced_8x8_zz [64] = /* Table 235 */ -{ - 0, 8, 1, 16, 24, 9, 2, 32, - 40, 48, 56, 17, 10, 3, 25, 18, - 11, 4, 33, 41, 49, 57, 26, 34, - 42, 50, 58, 19, 12, 5, 27, 20, - 13, 6, 35, 28, 21, 14, 7, 15, - 22, 29, 36, 43, 51, 59, 60, 52, - 44, 37, 30, 23, 31, 38, 45, 53, - 61, 62, 54, 46, 39, 47, 55, 63 -}; - -static const int8_t vc1_adv_interlaced_8x4_zz [32] = /* Table 236 */ -{ - 0, 8, 16, 24, 1, 9, 2, 17, - 25, 10, 3, 18, 26, 4, 11, 19, - 12, 5, 13, 20, 27, 6, 21, 28, - 14, 22, 29, 7, 30, 15, 23, 31 -}; - -static const int8_t vc1_adv_interlaced_4x8_zz [32] = /* Table 237 */ -{ - 0, 1, 2, 8, - 16, 9, 24, 17, - 10, 3, 32, 40, - 48, 56, 25, 18, - 33, 26, 41, 34, - 49, 57, 11, 42, - 19, 50, 27, 58, - 35, 43, 51, 59 -}; - -static const int8_t vc1_adv_interlaced_4x4_zz [16] = /* Table 238 */ -{ - 0, 8, 16, 24, - 1, 9, 17, 2, - 25, 10, 18, 3, - 26, 11, 19, 27 -}; - +extern const int8_t ff_vc1_normal_zz[64]; +extern const int8_t ff_vc1_horizontal_zz [64]; +extern const int8_t ff_vc1_vertical_zz [64]; +extern const int8_t ff_vc1_simple_progressive_8x8_zz [64]; +extern const int8_t ff_vc1_simple_progressive_8x4_zz [32]; +extern const int8_t ff_vc1_simple_progressive_4x8_zz [32]; +extern const int8_t ff_vc1_simple_progressive_4x4_zz [16]; +extern const int8_t ff_vc1_adv_progressive_8x4_zz [32]; +extern const int8_t ff_vc1_adv_progressive_4x8_zz [32]; +extern const int8_t ff_vc1_adv_interlaced_8x8_zz [64]; +extern const int8_t ff_vc1_adv_interlaced_8x4_zz [32]; +extern const int8_t ff_vc1_adv_interlaced_4x8_zz [32]; +extern const int8_t ff_vc1_adv_interlaced_4x4_zz [16]; /* DQScale as specified in 8.1.3.9 - almost identical to 0x40000/i */ -static const int32_t vc1_dqscale[63] = { -0x40000, 0x20000, 0x15555, 0x10000, 0xCCCD, 0xAAAB, 0x9249, 0x8000, - 0x71C7, 0x6666, 0x5D17, 0x5555, 0x4EC5, 0x4925, 0x4444, 0x4000, - 0x3C3C, 0x38E4, 0x35E5, 0x3333, 0x30C3, 0x2E8C, 0x2C86, 0x2AAB, - 0x28F6, 0x2762, 0x25ED, 0x2492, 0x234F, 0x2222, 0x2108, 0x2000, - 0x1F08, 0x1E1E, 0x1D42, 0x1C72, 0x1BAD, 0x1AF3, 0x1A42, 0x199A, - 0x18FA, 0x1862, 0x17D0, 0x1746, 0x16C1, 0x1643, 0x15CA, 0x1555, - 0x14E6, 0x147B, 0x1414, 0x13B1, 0x1352, 0x12F7, 0x129E, 0x1249, - 0x11F7, 0x11A8, 0x115B, 0x1111, 0x10C9, 0x1084, 0x1000 -}; -#endif /* VC1DATA_H */ +extern const int32_t ff_vc1_dqscale[63]; + +#endif /* FFMPEG_VC1DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/vc1dsp.c b/contrib/ffmpeg/libavcodec/vc1dsp.c index 6102c0960..8a1a83411 100644 --- a/contrib/ffmpeg/libavcodec/vc1dsp.c +++ b/contrib/ffmpeg/libavcodec/vc1dsp.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -91,8 +90,8 @@ static void vc1_inv_trans_8x8_c(DCTELEM block[64]) src = block; dst = block; for(i = 0; i < 8; i++){ - t1 = 12 * (src[0] + src[4]); - t2 = 12 * (src[0] - src[4]); + t1 = 12 * (src[0] + src[4]) + 4; + t2 = 12 * (src[0] - src[4]) + 4; t3 = 16 * src[2] + 6 * src[6]; t4 = 6 * src[2] - 16 * src[6]; @@ -106,14 +105,14 @@ static void vc1_inv_trans_8x8_c(DCTELEM block[64]) t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7]; t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7]; - dst[0] = (t5 + t1 + 4) >> 3; - dst[1] = (t6 + t2 + 4) >> 3; - dst[2] = (t7 + t3 + 4) >> 3; - dst[3] = (t8 + t4 + 4) >> 3; - dst[4] = (t8 - t4 + 4) >> 3; - dst[5] = (t7 - t3 + 4) >> 3; - dst[6] = (t6 - t2 + 4) >> 3; - dst[7] = (t5 - t1 + 4) >> 3; + dst[0] = (t5 + t1) >> 3; + dst[1] = (t6 + t2) >> 3; + dst[2] = (t7 + t3) >> 3; + dst[3] = (t8 + t4) >> 3; + dst[4] = (t8 - t4) >> 3; + dst[5] = (t7 - t3) >> 3; + dst[6] = (t6 - t2) >> 3; + dst[7] = (t5 - t1) >> 3; src += 8; dst += 8; @@ -122,8 +121,8 @@ static void vc1_inv_trans_8x8_c(DCTELEM block[64]) src = block; dst = block; for(i = 0; i < 8; i++){ - t1 = 12 * (src[ 0] + src[32]); - t2 = 12 * (src[ 0] - src[32]); + t1 = 12 * (src[ 0] + src[32]) + 64; + t2 = 12 * (src[ 0] - src[32]) + 64; t3 = 16 * src[16] + 6 * src[48]; t4 = 6 * src[16] - 16 * src[48]; @@ -137,14 +136,14 @@ static void vc1_inv_trans_8x8_c(DCTELEM block[64]) t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56]; t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56]; - dst[ 0] = (t5 + t1 + 64) >> 7; - dst[ 8] = (t6 + t2 + 64) >> 7; - dst[16] = (t7 + t3 + 64) >> 7; - dst[24] = (t8 + t4 + 64) >> 7; - dst[32] = (t8 - t4 + 64 + 1) >> 7; - dst[40] = (t7 - t3 + 64 + 1) >> 7; - dst[48] = (t6 - t2 + 64 + 1) >> 7; - dst[56] = (t5 - t1 + 64 + 1) >> 7; + dst[ 0] = (t5 + t1) >> 7; + dst[ 8] = (t6 + t2) >> 7; + dst[16] = (t7 + t3) >> 7; + dst[24] = (t8 + t4) >> 7; + dst[32] = (t8 - t4 + 1) >> 7; + dst[40] = (t7 - t3 + 1) >> 7; + dst[48] = (t6 - t2 + 1) >> 7; + dst[56] = (t5 - t1 + 1) >> 7; src++; dst++; @@ -153,19 +152,18 @@ static void vc1_inv_trans_8x8_c(DCTELEM block[64]) /** Do inverse transform on 8x4 part of block */ -static void vc1_inv_trans_8x4_c(DCTELEM block[64], int n) +static void vc1_inv_trans_8x4_c(uint8_t *dest, int linesize, DCTELEM *block) { int i; register int t1,t2,t3,t4,t5,t6,t7,t8; DCTELEM *src, *dst; - int off; + const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; - off = n * 32; - src = block + off; - dst = block + off; + src = block; + dst = block; for(i = 0; i < 4; i++){ - t1 = 12 * (src[0] + src[4]); - t2 = 12 * (src[0] - src[4]); + t1 = 12 * (src[0] + src[4]) + 4; + t2 = 12 * (src[0] - src[4]) + 4; t3 = 16 * src[2] + 6 * src[6]; t4 = 6 * src[2] - 16 * src[6]; @@ -179,73 +177,66 @@ static void vc1_inv_trans_8x4_c(DCTELEM block[64], int n) t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7]; t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7]; - dst[0] = (t5 + t1 + 4) >> 3; - dst[1] = (t6 + t2 + 4) >> 3; - dst[2] = (t7 + t3 + 4) >> 3; - dst[3] = (t8 + t4 + 4) >> 3; - dst[4] = (t8 - t4 + 4) >> 3; - dst[5] = (t7 - t3 + 4) >> 3; - dst[6] = (t6 - t2 + 4) >> 3; - dst[7] = (t5 - t1 + 4) >> 3; + dst[0] = (t5 + t1) >> 3; + dst[1] = (t6 + t2) >> 3; + dst[2] = (t7 + t3) >> 3; + dst[3] = (t8 + t4) >> 3; + dst[4] = (t8 - t4) >> 3; + dst[5] = (t7 - t3) >> 3; + dst[6] = (t6 - t2) >> 3; + dst[7] = (t5 - t1) >> 3; src += 8; dst += 8; } - src = block + off; - dst = block + off; + src = block; for(i = 0; i < 8; i++){ - t1 = 17 * (src[ 0] + src[16]); - t2 = 17 * (src[ 0] - src[16]); - t3 = 22 * src[ 8]; - t4 = 22 * src[24]; - t5 = 10 * src[ 8]; - t6 = 10 * src[24]; - - dst[ 0] = (t1 + t3 + t6 + 64) >> 7; - dst[ 8] = (t2 - t4 + t5 + 64) >> 7; - dst[16] = (t2 + t4 - t5 + 64) >> 7; - dst[24] = (t1 - t3 - t6 + 64) >> 7; + t1 = 17 * (src[ 0] + src[16]) + 64; + t2 = 17 * (src[ 0] - src[16]) + 64; + t3 = 22 * src[ 8] + 10 * src[24]; + t4 = 22 * src[24] - 10 * src[ 8]; + + dest[0*linesize] = cm[dest[0*linesize] + ((t1 + t3) >> 7)]; + dest[1*linesize] = cm[dest[1*linesize] + ((t2 - t4) >> 7)]; + dest[2*linesize] = cm[dest[2*linesize] + ((t2 + t4) >> 7)]; + dest[3*linesize] = cm[dest[3*linesize] + ((t1 - t3) >> 7)]; src ++; - dst ++; + dest++; } } /** Do inverse transform on 4x8 parts of block */ -static void vc1_inv_trans_4x8_c(DCTELEM block[64], int n) +static void vc1_inv_trans_4x8_c(uint8_t *dest, int linesize, DCTELEM *block) { int i; register int t1,t2,t3,t4,t5,t6,t7,t8; DCTELEM *src, *dst; - int off; + const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; - off = n * 4; - src = block + off; - dst = block + off; + src = block; + dst = block; for(i = 0; i < 8; i++){ - t1 = 17 * (src[0] + src[2]); - t2 = 17 * (src[0] - src[2]); - t3 = 22 * src[1]; - t4 = 22 * src[3]; - t5 = 10 * src[1]; - t6 = 10 * src[3]; - - dst[0] = (t1 + t3 + t6 + 4) >> 3; - dst[1] = (t2 - t4 + t5 + 4) >> 3; - dst[2] = (t2 + t4 - t5 + 4) >> 3; - dst[3] = (t1 - t3 - t6 + 4) >> 3; + t1 = 17 * (src[0] + src[2]) + 4; + t2 = 17 * (src[0] - src[2]) + 4; + t3 = 22 * src[1] + 10 * src[3]; + t4 = 22 * src[3] - 10 * src[1]; + + dst[0] = (t1 + t3) >> 3; + dst[1] = (t2 - t4) >> 3; + dst[2] = (t2 + t4) >> 3; + dst[3] = (t1 - t3) >> 3; src += 8; dst += 8; } - src = block + off; - dst = block + off; + src = block; for(i = 0; i < 4; i++){ - t1 = 12 * (src[ 0] + src[32]); - t2 = 12 * (src[ 0] - src[32]); + t1 = 12 * (src[ 0] + src[32]) + 64; + t2 = 12 * (src[ 0] - src[32]) + 64; t3 = 16 * src[16] + 6 * src[48]; t4 = 6 * src[16] - 16 * src[48]; @@ -259,70 +250,84 @@ static void vc1_inv_trans_4x8_c(DCTELEM block[64], int n) t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56]; t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56]; - dst[ 0] = (t5 + t1 + 64) >> 7; - dst[ 8] = (t6 + t2 + 64) >> 7; - dst[16] = (t7 + t3 + 64) >> 7; - dst[24] = (t8 + t4 + 64) >> 7; - dst[32] = (t8 - t4 + 64 + 1) >> 7; - dst[40] = (t7 - t3 + 64 + 1) >> 7; - dst[48] = (t6 - t2 + 64 + 1) >> 7; - dst[56] = (t5 - t1 + 64 + 1) >> 7; + dest[0*linesize] = cm[dest[0*linesize] + ((t5 + t1) >> 7)]; + dest[1*linesize] = cm[dest[1*linesize] + ((t6 + t2) >> 7)]; + dest[2*linesize] = cm[dest[2*linesize] + ((t7 + t3) >> 7)]; + dest[3*linesize] = cm[dest[3*linesize] + ((t8 + t4) >> 7)]; + dest[4*linesize] = cm[dest[4*linesize] + ((t8 - t4 + 1) >> 7)]; + dest[5*linesize] = cm[dest[5*linesize] + ((t7 - t3 + 1) >> 7)]; + dest[6*linesize] = cm[dest[6*linesize] + ((t6 - t2 + 1) >> 7)]; + dest[7*linesize] = cm[dest[7*linesize] + ((t5 - t1 + 1) >> 7)]; - src++; - dst++; + src ++; + dest++; } } /** Do inverse transform on 4x4 part of block */ -static void vc1_inv_trans_4x4_c(DCTELEM block[64], int n) +static void vc1_inv_trans_4x4_c(uint8_t *dest, int linesize, DCTELEM *block) { int i; - register int t1,t2,t3,t4,t5,t6; + register int t1,t2,t3,t4; DCTELEM *src, *dst; - int off; + const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; - off = (n&1) * 4 + (n&2) * 16; - src = block + off; - dst = block + off; + src = block; + dst = block; for(i = 0; i < 4; i++){ - t1 = 17 * (src[0] + src[2]); - t2 = 17 * (src[0] - src[2]); - t3 = 22 * src[1]; - t4 = 22 * src[3]; - t5 = 10 * src[1]; - t6 = 10 * src[3]; - - dst[0] = (t1 + t3 + t6 + 4) >> 3; - dst[1] = (t2 - t4 + t5 + 4) >> 3; - dst[2] = (t2 + t4 - t5 + 4) >> 3; - dst[3] = (t1 - t3 - t6 + 4) >> 3; + t1 = 17 * (src[0] + src[2]) + 4; + t2 = 17 * (src[0] - src[2]) + 4; + t3 = 22 * src[1] + 10 * src[3]; + t4 = 22 * src[3] - 10 * src[1]; + + dst[0] = (t1 + t3) >> 3; + dst[1] = (t2 - t4) >> 3; + dst[2] = (t2 + t4) >> 3; + dst[3] = (t1 - t3) >> 3; src += 8; dst += 8; } - src = block + off; - dst = block + off; + src = block; for(i = 0; i < 4; i++){ - t1 = 17 * (src[ 0] + src[16]); - t2 = 17 * (src[ 0] - src[16]); - t3 = 22 * src[ 8]; - t4 = 22 * src[24]; - t5 = 10 * src[ 8]; - t6 = 10 * src[24]; - - dst[ 0] = (t1 + t3 + t6 + 64) >> 7; - dst[ 8] = (t2 - t4 + t5 + 64) >> 7; - dst[16] = (t2 + t4 - t5 + 64) >> 7; - dst[24] = (t1 - t3 - t6 + 64) >> 7; + t1 = 17 * (src[ 0] + src[16]) + 64; + t2 = 17 * (src[ 0] - src[16]) + 64; + t3 = 22 * src[ 8] + 10 * src[24]; + t4 = 22 * src[24] - 10 * src[ 8]; + + dest[0*linesize] = cm[dest[0*linesize] + ((t1 + t3) >> 7)]; + dest[1*linesize] = cm[dest[1*linesize] + ((t2 - t4) >> 7)]; + dest[2*linesize] = cm[dest[2*linesize] + ((t2 + t4) >> 7)]; + dest[3*linesize] = cm[dest[3*linesize] + ((t1 - t3) >> 7)]; src ++; - dst ++; + dest++; } } /* motion compensation functions */ +/** Filter in case of 2 filters */ +#define VC1_MSPEL_FILTER_16B(DIR, TYPE) \ +static av_always_inline int vc1_mspel_ ## DIR ## _filter_16bits(const TYPE *src, int stride, int mode) \ +{ \ + switch(mode){ \ + case 0: /* no shift - should not occur */ \ + return 0; \ + case 1: /* 1/4 shift */ \ + return -4*src[-stride] + 53*src[0] + 18*src[stride] - 3*src[stride*2]; \ + case 2: /* 1/2 shift */ \ + return -src[-stride] + 9*src[0] + 9*src[stride] - src[stride*2]; \ + case 3: /* 3/4 shift */ \ + return -3*src[-stride] + 18*src[0] + 53*src[stride] - 4*src[stride*2]; \ + } \ + return 0; /* should not occur */ \ +} + +VC1_MSPEL_FILTER_16B(ver, uint8_t); +VC1_MSPEL_FILTER_16B(hor, int16_t); + /** Filter used to interpolate fractional pel values */ @@ -343,31 +348,58 @@ static av_always_inline int vc1_mspel_filter(const uint8_t *src, int stride, int /** Function used to do motion compensation with bicubic interpolation */ -static void vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride, int mode, int rnd) +static void vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride, int hmode, int vmode, int rnd) { - int i, j; - uint8_t tmp[8*11], *tptr; - int m, r; - - m = (mode & 3); - r = rnd; - src -= stride; - tptr = tmp; - for(j = 0; j < 11; j++) { - for(i = 0; i < 8; i++) - tptr[i] = av_clip_uint8(vc1_mspel_filter(src + i, 1, m, r)); - src += stride; - tptr += 8; + int i, j; + + if (vmode) { /* Horizontal filter to apply */ + int r; + + if (hmode) { /* Vertical filter to apply, output to tmp */ + static const int shift_value[] = { 0, 5, 1, 5 }; + int shift = (shift_value[hmode]+shift_value[vmode])>>1; + int16_t tmp[11*8], *tptr = tmp; + + r = (1<<(shift-1)) + rnd-1; + + src -= 1; + for(j = 0; j < 8; j++) { + for(i = 0; i < 11; i++) + tptr[i] = (vc1_mspel_ver_filter_16bits(src + i, stride, vmode)+r)>>shift; + src += stride; + tptr += 11; + } + + r = 64-rnd; + tptr = tmp+1; + for(j = 0; j < 8; j++) { + for(i = 0; i < 8; i++) + dst[i] = av_clip_uint8((vc1_mspel_hor_filter_16bits(tptr + i, 1, hmode)+r)>>7); + dst += stride; + tptr += 11; + } + + return; + } + else { /* No horizontal filter, output 8 lines to dst */ + r = 1-rnd; + + for(j = 0; j < 8; j++) { + for(i = 0; i < 8; i++) + dst[i] = av_clip_uint8(vc1_mspel_filter(src + i, stride, vmode, r)); + src += stride; + dst += stride; + } + return; + } } - r = 1 - rnd; - m = (mode >> 2) & 3; - tptr = tmp + 8; + /* Horizontal mode with no vertical mode */ for(j = 0; j < 8; j++) { for(i = 0; i < 8; i++) - dst[i] = av_clip_uint8(vc1_mspel_filter(tptr + i, 8, m, r)); + dst[i] = av_clip_uint8(vc1_mspel_filter(src + i, 1, hmode, rnd)); dst += stride; - tptr += 8; + src += stride; } } @@ -376,65 +408,29 @@ static void vc1_mspel_mc(uint8_t *dst, const uint8_t *src, int stride, int mode, /* this one is defined in dsputil.c */ void ff_put_vc1_mspel_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int rnd); -static void ff_put_vc1_mspel_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { - vc1_mspel_mc(dst, src, stride, 0x1, rnd); +#define PUT_VC1_MSPEL(a, b)\ +static void put_vc1_mspel_mc ## a ## b ##_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { \ + vc1_mspel_mc(dst, src, stride, a, b, rnd); \ } -static void ff_put_vc1_mspel_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { - vc1_mspel_mc(dst, src, stride, 0x2, rnd); -} +PUT_VC1_MSPEL(1, 0) +PUT_VC1_MSPEL(2, 0) +PUT_VC1_MSPEL(3, 0) -static void ff_put_vc1_mspel_mc30_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { - vc1_mspel_mc(dst, src, stride, 0x3, rnd); -} - -static void ff_put_vc1_mspel_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { - vc1_mspel_mc(dst, src, stride, 0x4, rnd); -} - -static void ff_put_vc1_mspel_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { - vc1_mspel_mc(dst, src, stride, 0x5, rnd); -} - -static void ff_put_vc1_mspel_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { - vc1_mspel_mc(dst, src, stride, 0x6, rnd); -} - -static void ff_put_vc1_mspel_mc31_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { - vc1_mspel_mc(dst, src, stride, 0x7, rnd); -} +PUT_VC1_MSPEL(0, 1) +PUT_VC1_MSPEL(1, 1) +PUT_VC1_MSPEL(2, 1) +PUT_VC1_MSPEL(3, 1) -static void ff_put_vc1_mspel_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { - vc1_mspel_mc(dst, src, stride, 0x8, rnd); -} - -static void ff_put_vc1_mspel_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { - vc1_mspel_mc(dst, src, stride, 0x9, rnd); -} +PUT_VC1_MSPEL(0, 2) +PUT_VC1_MSPEL(1, 2) +PUT_VC1_MSPEL(2, 2) +PUT_VC1_MSPEL(3, 2) -static void ff_put_vc1_mspel_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { - vc1_mspel_mc(dst, src, stride, 0xA, rnd); -} - -static void ff_put_vc1_mspel_mc32_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { - vc1_mspel_mc(dst, src, stride, 0xB, rnd); -} - -static void ff_put_vc1_mspel_mc03_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { - vc1_mspel_mc(dst, src, stride, 0xC, rnd); -} - -static void ff_put_vc1_mspel_mc13_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { - vc1_mspel_mc(dst, src, stride, 0xD, rnd); -} - -static void ff_put_vc1_mspel_mc23_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { - vc1_mspel_mc(dst, src, stride, 0xE, rnd); -} - -static void ff_put_vc1_mspel_mc33_c(uint8_t *dst, const uint8_t *src, int stride, int rnd) { - vc1_mspel_mc(dst, src, stride, 0xF, rnd); -} +PUT_VC1_MSPEL(0, 3) +PUT_VC1_MSPEL(1, 3) +PUT_VC1_MSPEL(2, 3) +PUT_VC1_MSPEL(3, 3) void ff_vc1dsp_init(DSPContext* dsp, AVCodecContext *avctx) { dsp->vc1_inv_trans_8x8 = vc1_inv_trans_8x8_c; @@ -445,19 +441,19 @@ void ff_vc1dsp_init(DSPContext* dsp, AVCodecContext *avctx) { dsp->vc1_v_overlap = vc1_v_overlap_c; dsp->put_vc1_mspel_pixels_tab[ 0] = ff_put_vc1_mspel_mc00_c; - dsp->put_vc1_mspel_pixels_tab[ 1] = ff_put_vc1_mspel_mc10_c; - dsp->put_vc1_mspel_pixels_tab[ 2] = ff_put_vc1_mspel_mc20_c; - dsp->put_vc1_mspel_pixels_tab[ 3] = ff_put_vc1_mspel_mc30_c; - dsp->put_vc1_mspel_pixels_tab[ 4] = ff_put_vc1_mspel_mc01_c; - dsp->put_vc1_mspel_pixels_tab[ 5] = ff_put_vc1_mspel_mc11_c; - dsp->put_vc1_mspel_pixels_tab[ 6] = ff_put_vc1_mspel_mc21_c; - dsp->put_vc1_mspel_pixels_tab[ 7] = ff_put_vc1_mspel_mc31_c; - dsp->put_vc1_mspel_pixels_tab[ 8] = ff_put_vc1_mspel_mc02_c; - dsp->put_vc1_mspel_pixels_tab[ 9] = ff_put_vc1_mspel_mc12_c; - dsp->put_vc1_mspel_pixels_tab[10] = ff_put_vc1_mspel_mc22_c; - dsp->put_vc1_mspel_pixels_tab[11] = ff_put_vc1_mspel_mc32_c; - dsp->put_vc1_mspel_pixels_tab[12] = ff_put_vc1_mspel_mc03_c; - dsp->put_vc1_mspel_pixels_tab[13] = ff_put_vc1_mspel_mc13_c; - dsp->put_vc1_mspel_pixels_tab[14] = ff_put_vc1_mspel_mc23_c; - dsp->put_vc1_mspel_pixels_tab[15] = ff_put_vc1_mspel_mc33_c; + dsp->put_vc1_mspel_pixels_tab[ 1] = put_vc1_mspel_mc10_c; + dsp->put_vc1_mspel_pixels_tab[ 2] = put_vc1_mspel_mc20_c; + dsp->put_vc1_mspel_pixels_tab[ 3] = put_vc1_mspel_mc30_c; + dsp->put_vc1_mspel_pixels_tab[ 4] = put_vc1_mspel_mc01_c; + dsp->put_vc1_mspel_pixels_tab[ 5] = put_vc1_mspel_mc11_c; + dsp->put_vc1_mspel_pixels_tab[ 6] = put_vc1_mspel_mc21_c; + dsp->put_vc1_mspel_pixels_tab[ 7] = put_vc1_mspel_mc31_c; + dsp->put_vc1_mspel_pixels_tab[ 8] = put_vc1_mspel_mc02_c; + dsp->put_vc1_mspel_pixels_tab[ 9] = put_vc1_mspel_mc12_c; + dsp->put_vc1_mspel_pixels_tab[10] = put_vc1_mspel_mc22_c; + dsp->put_vc1_mspel_pixels_tab[11] = put_vc1_mspel_mc32_c; + dsp->put_vc1_mspel_pixels_tab[12] = put_vc1_mspel_mc03_c; + dsp->put_vc1_mspel_pixels_tab[13] = put_vc1_mspel_mc13_c; + dsp->put_vc1_mspel_pixels_tab[14] = put_vc1_mspel_mc23_c; + dsp->put_vc1_mspel_pixels_tab[15] = put_vc1_mspel_mc33_c; } diff --git a/contrib/ffmpeg/libavcodec/vcr1.c b/contrib/ffmpeg/libavcodec/vcr1.c index 62bf12320..30fc302d1 100644 --- a/contrib/ffmpeg/libavcodec/vcr1.c +++ b/contrib/ffmpeg/libavcodec/vcr1.c @@ -39,12 +39,12 @@ typedef struct VCR1Context{ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { VCR1Context * const a = avctx->priv_data; AVFrame *picture = data; AVFrame * const p= (AVFrame*)&a->picture; - uint8_t *bytestream= buf; + const uint8_t *bytestream= buf; int i, x, y; if(p->data[0]) diff --git a/contrib/ffmpeg/libavcodec/vmdav.c b/contrib/ffmpeg/libavcodec/vmdav.c index 69e8a44d3..d39ae91e3 100644 --- a/contrib/ffmpeg/libavcodec/vmdav.c +++ b/contrib/ffmpeg/libavcodec/vmdav.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -45,7 +44,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include "dsputil.h" @@ -63,21 +61,22 @@ typedef struct VmdVideoContext { AVFrame frame; AVFrame prev_frame; - unsigned char *buf; + const unsigned char *buf; int size; unsigned char palette[PALETTE_COUNT * 4]; unsigned char *unpack_buffer; int unpack_buffer_size; + int x_off, y_off; } VmdVideoContext; #define QUEUE_SIZE 0x1000 #define QUEUE_MASK 0x0FFF -static void lz_unpack(unsigned char *src, unsigned char *dest, int dest_len) +static void lz_unpack(const unsigned char *src, unsigned char *dest, int dest_len) { - unsigned char *s; + const unsigned char *s; unsigned char *d; unsigned char *d_end; unsigned char queue[QUEUE_SIZE]; @@ -145,10 +144,10 @@ static void lz_unpack(unsigned char *src, unsigned char *dest, int dest_len) } } -static int rle_unpack(unsigned char *src, unsigned char *dest, +static int rle_unpack(const unsigned char *src, unsigned char *dest, int src_len, int dest_len) { - unsigned char *ps; + const unsigned char *ps; unsigned char *pd; int i, l; unsigned char *dest_end = dest + dest_len; @@ -191,9 +190,9 @@ static void vmd_decode(VmdVideoContext *s) unsigned char r, g, b; /* point to the start of the encoded data */ - unsigned char *p = s->buf + 16; + const unsigned char *p = s->buf + 16; - unsigned char *pb; + const unsigned char *pb; unsigned char meth; unsigned char *dp; /* pointer to current frame */ unsigned char *pp; /* pointer to previous frame */ @@ -209,6 +208,15 @@ static void vmd_decode(VmdVideoContext *s) frame_width = AV_RL16(&s->buf[10]) - frame_x + 1; frame_height = AV_RL16(&s->buf[12]) - frame_y + 1; + if ((frame_width == s->avctx->width && frame_height == s->avctx->height) && + (frame_x || frame_y)) { + + s->x_off = frame_x; + s->y_off = frame_y; + } + frame_x -= s->x_off; + frame_y -= s->y_off; + /* if only a certain region will be updated, copy the entire previous * frame before the decode */ if (frame_x || frame_y || (frame_width != s->avctx->width) || @@ -318,7 +326,7 @@ static void vmd_decode(VmdVideoContext *s) static int vmdvideo_decode_init(AVCodecContext *avctx) { - VmdVideoContext *s = (VmdVideoContext *)avctx->priv_data; + VmdVideoContext *s = avctx->priv_data; int i; unsigned int *palette32; int palette_index = 0; @@ -328,7 +336,6 @@ static int vmdvideo_decode_init(AVCodecContext *avctx) s->avctx = avctx; avctx->pix_fmt = PIX_FMT_PAL8; - avctx->has_b_frames = 0; dsputil_init(&s->dsp, avctx); /* make sure the VMD header made it */ @@ -361,9 +368,9 @@ static int vmdvideo_decode_init(AVCodecContext *avctx) static int vmdvideo_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { - VmdVideoContext *s = (VmdVideoContext *)avctx->priv_data; + VmdVideoContext *s = avctx->priv_data; s->buf = buf; s->size = buf_size; @@ -382,14 +389,13 @@ static int vmdvideo_decode_frame(AVCodecContext *avctx, /* make the palette available on the way out */ memcpy(s->frame.data[1], s->palette, PALETTE_COUNT * 4); - if (s->prev_frame.data[0]) - avctx->release_buffer(avctx, &s->prev_frame); - /* shuffle frames */ - s->prev_frame = s->frame; + FFSWAP(AVFrame, s->frame, s->prev_frame); + if (s->frame.data[0]) + avctx->release_buffer(avctx, &s->frame); *data_size = sizeof(AVFrame); - *(AVFrame*)data = s->frame; + *(AVFrame*)data = s->prev_frame; /* report that the buffer was completely consumed */ return buf_size; @@ -397,7 +403,7 @@ static int vmdvideo_decode_frame(AVCodecContext *avctx, static int vmdvideo_decode_end(AVCodecContext *avctx) { - VmdVideoContext *s = (VmdVideoContext *)avctx->priv_data; + VmdVideoContext *s = avctx->priv_data; if (s->prev_frame.data[0]) avctx->release_buffer(avctx, &s->prev_frame); @@ -437,7 +443,7 @@ static uint16_t vmdaudio_table[128] = { static int vmdaudio_decode_init(AVCodecContext *avctx) { - VmdAudioContext *s = (VmdAudioContext *)avctx->priv_data; + VmdAudioContext *s = avctx->priv_data; s->avctx = avctx; s->channels = avctx->channels; @@ -451,7 +457,7 @@ static int vmdaudio_decode_init(AVCodecContext *avctx) } static void vmdaudio_decode_audio(VmdAudioContext *s, unsigned char *data, - uint8_t *buf, int stereo) + const uint8_t *buf, int stereo) { int i; int chan = 0; @@ -462,14 +468,14 @@ static void vmdaudio_decode_audio(VmdAudioContext *s, unsigned char *data, s->predictors[chan] -= vmdaudio_table[buf[i] & 0x7F]; else s->predictors[chan] += vmdaudio_table[buf[i]]; - s->predictors[chan] = av_clip(s->predictors[chan], -32768, 32767); + s->predictors[chan] = av_clip_int16(s->predictors[chan]); out[i] = s->predictors[chan]; chan ^= stereo; } } static int vmdaudio_loadsound(VmdAudioContext *s, unsigned char *data, - uint8_t *buf, int silence) + const uint8_t *buf, int silence) { int bytes_decoded = 0; int i; @@ -516,13 +522,13 @@ static int vmdaudio_loadsound(VmdAudioContext *s, unsigned char *data, static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { - VmdAudioContext *s = (VmdAudioContext *)avctx->priv_data; + VmdAudioContext *s = avctx->priv_data; unsigned char *output_samples = (unsigned char *)data; /* point to the start of the encoded data */ - unsigned char *p = buf + 16; + const unsigned char *p = buf + 16; if (buf_size < 16) return buf_size; diff --git a/contrib/ffmpeg/libavcodec/vmnc.c b/contrib/ffmpeg/libavcodec/vmnc.c index b430a7e66..12f414856 100644 --- a/contrib/ffmpeg/libavcodec/vmnc.c +++ b/contrib/ffmpeg/libavcodec/vmnc.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -29,7 +28,6 @@ #include #include -#include "common.h" #include "avcodec.h" enum EncTypes { @@ -72,7 +70,7 @@ typedef struct VmncContext { } VmncContext; /* read pixel value from stream */ -static av_always_inline int vmnc_get_pixel(uint8_t* buf, int bpp, int be) { +static av_always_inline int vmnc_get_pixel(const uint8_t* buf, int bpp, int be) { switch(bpp * 2 + be) { case 2: case 3: return *buf; @@ -84,7 +82,7 @@ static av_always_inline int vmnc_get_pixel(uint8_t* buf, int bpp, int be) { } } -static void load_cursor(VmncContext *c, uint8_t *src) +static void load_cursor(VmncContext *c, const uint8_t *src) { int i, j, p; const int bpp = c->bpp2; @@ -171,7 +169,7 @@ static void put_cursor(uint8_t *dst, int stride, VmncContext *c, int dx, int dy) } } -/* fill rectangle with given colour */ +/* fill rectangle with given color */ static av_always_inline void paint_rect(uint8_t *dst, int dx, int dy, int w, int h, int color, int bpp, int stride) { int i, j; @@ -202,7 +200,7 @@ static av_always_inline void paint_rect(uint8_t *dst, int dx, int dy, int w, int } } -static av_always_inline void paint_raw(uint8_t *dst, int w, int h, uint8_t* src, int bpp, int be, int stride) +static av_always_inline void paint_raw(uint8_t *dst, int w, int h, const uint8_t* src, int bpp, int be, int stride) { int i, j, p; for(j = 0; j < h; j++) { @@ -225,14 +223,14 @@ static av_always_inline void paint_raw(uint8_t *dst, int w, int h, uint8_t* src, } } -static int decode_hextile(VmncContext *c, uint8_t* dst, uint8_t* src, int ssize, int w, int h, int stride) +static int decode_hextile(VmncContext *c, uint8_t* dst, const uint8_t* src, int ssize, int w, int h, int stride) { int i, j, k; int bg = 0, fg = 0, rects, color, flags, xy, wh; const int bpp = c->bpp2; uint8_t *dst2; int bw = 16, bh = 16; - uint8_t *ssrc=src; + const uint8_t *ssrc=src; for(j = 0; j < h; j += 16) { dst2 = dst; @@ -285,11 +283,11 @@ static int decode_hextile(VmncContext *c, uint8_t* dst, uint8_t* src, int ssize, return src - ssrc; } -static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size) { - VmncContext * const c = (VmncContext *)avctx->priv_data; + VmncContext * const c = avctx->priv_data; uint8_t *outptr; - uint8_t *src = buf; + const uint8_t *src = buf; int dx, dy, w, h, depth, enc, chunks, res, size_left; c->pic.reference = 1; @@ -460,7 +458,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 */ static int decode_init(AVCodecContext *avctx) { - VmncContext * const c = (VmncContext *)avctx->priv_data; + VmncContext * const c = avctx->priv_data; c->avctx = avctx; @@ -500,7 +498,7 @@ static int decode_init(AVCodecContext *avctx) */ static int decode_end(AVCodecContext *avctx) { - VmncContext * const c = (VmncContext *)avctx->priv_data; + VmncContext * const c = avctx->priv_data; if (c->pic.data[0]) avctx->release_buffer(avctx, &c->pic); diff --git a/contrib/ffmpeg/libavcodec/vorbis.c b/contrib/ffmpeg/libavcodec/vorbis.c index 7e5f0d349..76d6308b5 100644 --- a/contrib/ffmpeg/libavcodec/vorbis.c +++ b/contrib/ffmpeg/libavcodec/vorbis.c @@ -1,6 +1,6 @@ /** * @file vorbis.c - * Vorbis I decoder + * Common code for Vorbis I encoder and decoder * @author Denes Balatoni ( dbalatoni programozo hu ) * This file is part of FFmpeg. @@ -18,154 +18,20 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ #undef V_DEBUG //#define V_DEBUG -//#define AV_DEBUG(...) av_log(NULL, AV_LOG_INFO, __VA_ARGS__) - -#include #define ALT_BITSTREAM_READER_LE #include "avcodec.h" #include "bitstream.h" -#include "dsputil.h" #include "vorbis.h" -#include "xiph.h" - -#define V_NB_BITS 8 -#define V_NB_BITS2 11 -#define V_MAX_VLCS (1<<16) - -#ifndef V_DEBUG -#define AV_DEBUG(...) -#endif - -#undef NDEBUG -#include - -typedef struct { - uint_fast8_t dimensions; - uint_fast8_t lookup_type; - uint_fast8_t maxdepth; - VLC vlc; - float *codevectors; - unsigned int nb_bits; -} vorbis_codebook; - -typedef union vorbis_floor_u vorbis_floor_data; -typedef struct vorbis_floor0_s vorbis_floor0; -typedef struct vorbis_floor1_s vorbis_floor1; -struct vorbis_context_s; -typedef -uint_fast8_t (* vorbis_floor_decode_func) - (struct vorbis_context_s *, vorbis_floor_data *, float *); -typedef struct { - uint_fast8_t floor_type; - vorbis_floor_decode_func decode; - union vorbis_floor_u - { - struct vorbis_floor0_s - { - uint_fast8_t order; - uint_fast16_t rate; - uint_fast16_t bark_map_size; - int_fast32_t * map[2]; - uint_fast32_t map_size[2]; - uint_fast8_t amplitude_bits; - uint_fast8_t amplitude_offset; - uint_fast8_t num_books; - uint_fast8_t * book_list; - float * lsp; - } t0; - struct vorbis_floor1_s - { - uint_fast8_t partitions; - uint_fast8_t maximum_class; - uint_fast8_t partition_class[32]; - uint_fast8_t class_dimensions[16]; - uint_fast8_t class_subclasses[16]; - uint_fast8_t class_masterbook[16]; - int_fast16_t subclass_books[16][8]; - uint_fast8_t multiplier; - uint_fast16_t x_list_dim; - floor1_entry_t * list; - } t1; - } data; -} vorbis_floor; -typedef struct { - uint_fast16_t type; - uint_fast32_t begin; - uint_fast32_t end; - uint_fast32_t partition_size; - uint_fast8_t classifications; - uint_fast8_t classbook; - int_fast16_t books[64][8]; - uint_fast8_t maxpass; -} vorbis_residue; - -typedef struct { - uint_fast8_t submaps; - uint_fast16_t coupling_steps; - uint_fast8_t *magnitude; - uint_fast8_t *angle; - uint_fast8_t *mux; - uint_fast8_t submap_floor[16]; - uint_fast8_t submap_residue[16]; -} vorbis_mapping; - -typedef struct { - uint_fast8_t blockflag; - uint_fast16_t windowtype; - uint_fast16_t transformtype; - uint_fast8_t mapping; -} vorbis_mode; - -typedef struct vorbis_context_s { - AVCodecContext *avccontext; - GetBitContext gb; - DSPContext dsp; - - MDCTContext mdct[2]; - uint_fast8_t first_frame; - uint_fast32_t version; - uint_fast8_t audio_channels; - uint_fast32_t audio_samplerate; - uint_fast32_t bitrate_maximum; - uint_fast32_t bitrate_nominal; - uint_fast32_t bitrate_minimum; - uint_fast32_t blocksize[2]; - const float * win[2]; - uint_fast16_t codebook_count; - vorbis_codebook *codebooks; - uint_fast8_t floor_count; - vorbis_floor *floors; - uint_fast8_t residue_count; - vorbis_residue *residues; - uint_fast8_t mapping_count; - vorbis_mapping *mappings; - uint_fast8_t mode_count; - vorbis_mode *modes; - uint_fast8_t mode_number; // mode number for the current packet - float *channel_residues; - float *channel_floors; - float *saved; - uint_fast16_t saved_start; - float *ret; - float *buf; - float *buf_tmp; - uint_fast32_t add_bias; // for float->int conversion - uint_fast32_t exp_bias; -} vorbis_context; /* Helper functions */ -#define BARK(x) \ - (13.1f*atan(0.00074f*(x))+2.24f*atan(1.85e-8f*(x)*(x))+1e-4f*(x)) - unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n) { // x^(1/n) unsigned int ret=0, i, j; @@ -177,14 +43,6 @@ unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n) { // x^(1/n) return (ret-1); } -static float vorbisfloat2float(uint_fast32_t val) { - double mant=val&0x1fffff; - long exp=(val&0x7fe00000L)>>21; - if (val&0x80000000) mant=-mant; - return(ldexp(mant, exp-20-768)); -} - - // Generate vlc codes from vorbis huffman code lengths int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, uint_fast32_t num) { @@ -283,955 +141,23 @@ void ff_vorbis_ready_floor1_list(floor1_entry_t * list, int values) { } } -// Free all allocated memory ----------------------------------------- - -static void vorbis_free(vorbis_context *vc) { - int_fast16_t i; - - av_freep(&vc->channel_residues); - av_freep(&vc->channel_floors); - av_freep(&vc->saved); - av_freep(&vc->ret); - av_freep(&vc->buf); - av_freep(&vc->buf_tmp); - - av_freep(&vc->residues); - av_freep(&vc->modes); - - ff_mdct_end(&vc->mdct[0]); - ff_mdct_end(&vc->mdct[1]); - - for(i=0;icodebook_count;++i) { - av_free(vc->codebooks[i].codevectors); - free_vlc(&vc->codebooks[i].vlc); - } - av_freep(&vc->codebooks); - - for(i=0;ifloor_count;++i) { - if(vc->floors[i].floor_type==0) { - av_free(vc->floors[i].data.t0.map[0]); - av_free(vc->floors[i].data.t0.map[1]); - av_free(vc->floors[i].data.t0.book_list); - av_free(vc->floors[i].data.t0.lsp); - } - else { - av_free(vc->floors[i].data.t1.list); - } - } - av_freep(&vc->floors); - - for(i=0;imapping_count;++i) { - av_free(vc->mappings[i].magnitude); - av_free(vc->mappings[i].angle); - av_free(vc->mappings[i].mux); - } - av_freep(&vc->mappings); - - if(vc->exp_bias){ - av_freep(&vc->win[0]); - av_freep(&vc->win[1]); - } -} - -// Parse setup header ------------------------------------------------- - -// Process codebooks part - -static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc) { - uint_fast16_t cb; - uint8_t *tmp_vlc_bits; - uint32_t *tmp_vlc_codes; - GetBitContext *gb=&vc->gb; - - vc->codebook_count=get_bits(gb,8)+1; - - AV_DEBUG(" Codebooks: %d \n", vc->codebook_count); - - vc->codebooks=(vorbis_codebook *)av_mallocz(vc->codebook_count * sizeof(vorbis_codebook)); - tmp_vlc_bits=(uint8_t *)av_mallocz(V_MAX_VLCS * sizeof(uint8_t)); - tmp_vlc_codes=(uint32_t *)av_mallocz(V_MAX_VLCS * sizeof(uint32_t)); - - for(cb=0;cbcodebook_count;++cb) { - vorbis_codebook *codebook_setup=&vc->codebooks[cb]; - uint_fast8_t ordered; - uint_fast32_t t, used_entries=0; - uint_fast32_t entries; - - AV_DEBUG(" %d. Codebook \n", cb); - - if (get_bits(gb, 24)!=0x564342) { - av_log(vc->avccontext, AV_LOG_ERROR, " %"PRIdFAST16". Codebook setup data corrupt. \n", cb); - goto error; - } - - codebook_setup->dimensions=get_bits(gb, 16); - if (codebook_setup->dimensions>16) { - av_log(vc->avccontext, AV_LOG_ERROR, " %"PRIdFAST16". Codebook's dimension is too large (%d). \n", cb, codebook_setup->dimensions); - goto error; - } - entries=get_bits(gb, 24); - if (entries>V_MAX_VLCS) { - av_log(vc->avccontext, AV_LOG_ERROR, " %"PRIdFAST16". Codebook has too many entries (%"PRIdFAST32"). \n", cb, entries); - goto error; - } - - ordered=get_bits1(gb); - - AV_DEBUG(" codebook_dimensions %d, codebook_entries %d \n", codebook_setup->dimensions, entries); - - if (!ordered) { - uint_fast16_t ce; - uint_fast8_t flag; - uint_fast8_t sparse=get_bits1(gb); - - AV_DEBUG(" not ordered \n"); - - if (sparse) { - AV_DEBUG(" sparse \n"); - - used_entries=0; - for(ce=0;ceused_entries) { - av_log(vc->avccontext, AV_LOG_ERROR, " More codelengths than codes in codebook. \n"); - goto error; - } - } - - codebook_setup->lookup_type=get_bits(gb, 4); - - AV_DEBUG(" lookup type: %d : %s \n", codebook_setup->lookup_type, codebook_setup->lookup_type ? "vq" : "no lookup" ); - -// If the codebook is used for (inverse) VQ, calculate codevectors. - - if (codebook_setup->lookup_type==1) { - uint_fast16_t i, j, k; - uint_fast16_t codebook_lookup_values=ff_vorbis_nth_root(entries, codebook_setup->dimensions); - uint_fast16_t codebook_multiplicands[codebook_lookup_values]; - - float codebook_minimum_value=vorbisfloat2float(get_bits_long(gb, 32)); - float codebook_delta_value=vorbisfloat2float(get_bits_long(gb, 32)); - uint_fast8_t codebook_value_bits=get_bits(gb, 4)+1; - uint_fast8_t codebook_sequence_p=get_bits1(gb); - - AV_DEBUG(" We expect %d numbers for building the codevectors. \n", codebook_lookup_values); - AV_DEBUG(" delta %f minmum %f \n", codebook_delta_value, codebook_minimum_value); - - for(i=0;icodevectors=(float *)av_mallocz(used_entries*codebook_setup->dimensions * sizeof(float)); - for(j=0, i=0;idimensions; - - if (tmp_vlc_bits[i]) { - float last=0.0; - uint_fast32_t lookup_offset=i; - -#ifdef V_DEBUG - av_log(vc->avccontext, AV_LOG_INFO, "Lookup offset %d ,", i); -#endif - - for(k=0;kcodevectors[j*dim+k]=codebook_multiplicands[multiplicand_offset]*codebook_delta_value+codebook_minimum_value+last; - if (codebook_sequence_p) { - last=codebook_setup->codevectors[j*dim+k]; - } - lookup_offset/=codebook_lookup_values; - } - tmp_vlc_bits[j]=tmp_vlc_bits[i]; - -#ifdef V_DEBUG - av_log(vc->avccontext, AV_LOG_INFO, "real lookup offset %d, vector: ", j); - for(k=0;kavccontext, AV_LOG_INFO, " %f ", codebook_setup->codevectors[j*dim+k]); - } - av_log(vc->avccontext, AV_LOG_INFO, "\n"); -#endif - - ++j; - } - } - if (j!=used_entries) { - av_log(vc->avccontext, AV_LOG_ERROR, "Bug in codevector vector building code. \n"); - goto error; - } - entries=used_entries; - } - else if (codebook_setup->lookup_type>=2) { - av_log(vc->avccontext, AV_LOG_ERROR, "Codebook lookup type not supported. \n"); - goto error; - } - -// Initialize VLC table - if (ff_vorbis_len2vlc(tmp_vlc_bits, tmp_vlc_codes, entries)) { - av_log(vc->avccontext, AV_LOG_ERROR, " Invalid code lengths while generating vlcs. \n"); - goto error; - } - codebook_setup->maxdepth=0; - for(t=0;t=codebook_setup->maxdepth) codebook_setup->maxdepth=tmp_vlc_bits[t]; - - if(codebook_setup->maxdepth > 3*V_NB_BITS) codebook_setup->nb_bits=V_NB_BITS2; - else codebook_setup->nb_bits=V_NB_BITS; - - codebook_setup->maxdepth=(codebook_setup->maxdepth+codebook_setup->nb_bits-1)/codebook_setup->nb_bits; - - if (init_vlc(&codebook_setup->vlc, codebook_setup->nb_bits, entries, tmp_vlc_bits, sizeof(*tmp_vlc_bits), sizeof(*tmp_vlc_bits), tmp_vlc_codes, sizeof(*tmp_vlc_codes), sizeof(*tmp_vlc_codes), INIT_VLC_LE)) { - av_log(vc->avccontext, AV_LOG_ERROR, " Error generating vlc tables. \n"); - goto error; - } - } - - av_free(tmp_vlc_bits); - av_free(tmp_vlc_codes); - return 0; - -// Error: -error: - av_free(tmp_vlc_bits); - av_free(tmp_vlc_codes); - return 1; -} - -// Process time domain transforms part (unused in Vorbis I) - -static int vorbis_parse_setup_hdr_tdtransforms(vorbis_context *vc) { - GetBitContext *gb=&vc->gb; - uint_fast8_t i; - uint_fast8_t vorbis_time_count=get_bits(gb, 6)+1; - - for(i=0;iavccontext, AV_LOG_ERROR, "Vorbis time domain transform data nonzero. \n"); - return 1; - } - } - return 0; -} - -// Process floors part - -static uint_fast8_t vorbis_floor0_decode(vorbis_context *vc, - vorbis_floor_data *vfu, float *vec); -static void create_map( vorbis_context * vc, uint_fast8_t floor_number ); -static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc, - vorbis_floor_data *vfu, float *vec); -static int vorbis_parse_setup_hdr_floors(vorbis_context *vc) { - GetBitContext *gb=&vc->gb; - uint_fast16_t i,j,k; - - vc->floor_count=get_bits(gb, 6)+1; - - vc->floors=(vorbis_floor *)av_mallocz(vc->floor_count * sizeof(vorbis_floor)); - - for (i=0;ifloor_count;++i) { - vorbis_floor *floor_setup=&vc->floors[i]; - - floor_setup->floor_type=get_bits(gb, 16); - - AV_DEBUG(" %d. floor type %d \n", i, floor_setup->floor_type); - - if (floor_setup->floor_type==1) { - uint_fast8_t maximum_class=0; - uint_fast8_t rangebits; - uint_fast16_t floor1_values=2; - - floor_setup->decode=vorbis_floor1_decode; - - floor_setup->data.t1.partitions=get_bits(gb, 5); - - AV_DEBUG(" %d.floor: %d partitions \n", i, floor_setup->data.t1.partitions); - - for(j=0;jdata.t1.partitions;++j) { - floor_setup->data.t1.partition_class[j]=get_bits(gb, 4); - if (floor_setup->data.t1.partition_class[j]>maximum_class) maximum_class=floor_setup->data.t1.partition_class[j]; - - AV_DEBUG(" %d. floor %d partition class %d \n", i, j, floor_setup->data.t1.partition_class[j]); - - } - - AV_DEBUG(" maximum class %d \n", maximum_class); - - floor_setup->data.t1.maximum_class=maximum_class; - - for(j=0;j<=maximum_class;++j) { - floor_setup->data.t1.class_dimensions[j]=get_bits(gb, 3)+1; - floor_setup->data.t1.class_subclasses[j]=get_bits(gb, 2); - - AV_DEBUG(" %d floor %d class dim: %d subclasses %d \n", i, j, floor_setup->data.t1.class_dimensions[j], floor_setup->data.t1.class_subclasses[j]); - - if (floor_setup->data.t1.class_subclasses[j]) { - floor_setup->data.t1.class_masterbook[j]=get_bits(gb, 8); - - AV_DEBUG(" masterbook: %d \n", floor_setup->data.t1.class_masterbook[j]); - } - - for(k=0;k<(1<data.t1.class_subclasses[j]);++k) { - floor_setup->data.t1.subclass_books[j][k]=(int16_t)get_bits(gb, 8)-1; - - AV_DEBUG(" book %d. : %d \n", k, floor_setup->data.t1.subclass_books[j][k]); - } - } - - floor_setup->data.t1.multiplier=get_bits(gb, 2)+1; - floor_setup->data.t1.x_list_dim=2; - - for(j=0;jdata.t1.partitions;++j) { - floor_setup->data.t1.x_list_dim+=floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]]; - } - - floor_setup->data.t1.list=(floor1_entry_t *)av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(floor1_entry_t)); - - - rangebits=get_bits(gb, 4); - floor_setup->data.t1.list[0].x = 0; - floor_setup->data.t1.list[1].x = (1<data.t1.partitions;++j) { - for(k=0;kdata.t1.class_dimensions[floor_setup->data.t1.partition_class[j]];++k,++floor1_values) { - floor_setup->data.t1.list[floor1_values].x=get_bits(gb, rangebits); - - AV_DEBUG(" %d. floor1 Y coord. %d \n", floor1_values, floor_setup->data.t1.list[floor1_values].x); - } - } - -// Precalculate order of x coordinates - needed for decode - ff_vorbis_ready_floor1_list(floor_setup->data.t1.list, floor_setup->data.t1.x_list_dim); - } - else if(floor_setup->floor_type==0) { - uint_fast8_t max_codebook_dim=0; - - floor_setup->decode=vorbis_floor0_decode; - - floor_setup->data.t0.order=get_bits(gb, 8); - floor_setup->data.t0.rate=get_bits(gb, 16); - floor_setup->data.t0.bark_map_size=get_bits(gb, 16); - floor_setup->data.t0.amplitude_bits=get_bits(gb, 6); - /* zero would result in a div by zero later * - * 2^0 - 1 == 0 */ - if (floor_setup->data.t0.amplitude_bits == 0) { - av_log(vc->avccontext, AV_LOG_ERROR, - "Floor 0 amplitude bits is 0.\n"); - return 1; - } - floor_setup->data.t0.amplitude_offset=get_bits(gb, 8); - floor_setup->data.t0.num_books=get_bits(gb, 4)+1; - - /* allocate mem for booklist */ - floor_setup->data.t0.book_list= - av_malloc(floor_setup->data.t0.num_books); - if(!floor_setup->data.t0.book_list) { return 1; } - /* read book indexes */ - { - int idx; - uint_fast8_t book_idx; - for (idx=0;idxdata.t0.num_books;++idx) { - book_idx=get_bits(gb, 8); - floor_setup->data.t0.book_list[idx]=book_idx; - if (vc->codebooks[book_idx].dimensions > max_codebook_dim) - max_codebook_dim=vc->codebooks[book_idx].dimensions; - - if (floor_setup->data.t0.book_list[idx]>vc->codebook_count) - return 1; - } - } - - create_map( vc, i ); - - /* allocate mem for lsp coefficients */ - { - /* codebook dim is for padding if codebook dim doesn't * - * divide order+1 then we need to read more data */ - floor_setup->data.t0.lsp= - av_malloc((floor_setup->data.t0.order+1 + max_codebook_dim) - * sizeof(float)); - if(!floor_setup->data.t0.lsp) { return 1; } - } - -#ifdef V_DEBUG /* debug output parsed headers */ - AV_DEBUG("floor0 order: %u\n", floor_setup->data.t0.order); - AV_DEBUG("floor0 rate: %u\n", floor_setup->data.t0.rate); - AV_DEBUG("floor0 bark map size: %u\n", - floor_setup->data.t0.bark_map_size); - AV_DEBUG("floor0 amplitude bits: %u\n", - floor_setup->data.t0.amplitude_bits); - AV_DEBUG("floor0 amplitude offset: %u\n", - floor_setup->data.t0.amplitude_offset); - AV_DEBUG("floor0 number of books: %u\n", - floor_setup->data.t0.num_books); - AV_DEBUG("floor0 book list pointer: %p\n", - floor_setup->data.t0.book_list); - { - int idx; - for (idx=0;idxdata.t0.num_books;++idx) { - AV_DEBUG( " Book %d: %u\n", - idx+1, - floor_setup->data.t0.book_list[idx] ); - } - } -#endif - } - else { - av_log(vc->avccontext, AV_LOG_ERROR, "Invalid floor type!\n"); - return 1; - } - } - return 0; -} - -// Process residues part - -static int vorbis_parse_setup_hdr_residues(vorbis_context *vc){ - GetBitContext *gb=&vc->gb; - uint_fast8_t i, j, k; - - vc->residue_count=get_bits(gb, 6)+1; - vc->residues=(vorbis_residue *)av_mallocz(vc->residue_count * sizeof(vorbis_residue)); - - AV_DEBUG(" There are %d residues. \n", vc->residue_count); - - for(i=0;iresidue_count;++i) { - vorbis_residue *res_setup=&vc->residues[i]; - uint_fast8_t cascade[64]; - uint_fast8_t high_bits; - uint_fast8_t low_bits; - - res_setup->type=get_bits(gb, 16); - - AV_DEBUG(" %d. residue type %d \n", i, res_setup->type); - - res_setup->begin=get_bits(gb, 24); - res_setup->end=get_bits(gb, 24); - res_setup->partition_size=get_bits(gb, 24)+1; - res_setup->classifications=get_bits(gb, 6)+1; - res_setup->classbook=get_bits(gb, 8); - - AV_DEBUG(" begin %d end %d part.size %d classif.s %d classbook %d \n", res_setup->begin, res_setup->end, res_setup->partition_size, - res_setup->classifications, res_setup->classbook); - - for(j=0;jclassifications;++j) { - high_bits=0; - low_bits=get_bits(gb, 3); - if (get_bits1(gb)) { - high_bits=get_bits(gb, 5); - } - cascade[j]=(high_bits<<3)+low_bits; - - AV_DEBUG(" %d class casscade depth: %d \n", j, ilog(cascade[j])); - } - - res_setup->maxpass=0; - for(j=0;jclassifications;++j) { - for(k=0;k<8;++k) { - if (cascade[j]&(1<books[j][k]=get_bits(gb, 8); - - AV_DEBUG(" %d class casscade depth %d book: %d \n", j, k, res_setup->books[j][k]); - - if (k>res_setup->maxpass) { - res_setup->maxpass=k; - } - } else { - res_setup->books[j][k]=-1; - } - } - } - } - return 0; -} - -// Process mappings part - -static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc) { - GetBitContext *gb=&vc->gb; - uint_fast8_t i, j; - - vc->mapping_count=get_bits(gb, 6)+1; - vc->mappings=(vorbis_mapping *)av_mallocz(vc->mapping_count * sizeof(vorbis_mapping)); - - AV_DEBUG(" There are %d mappings. \n", vc->mapping_count); - - for(i=0;imapping_count;++i) { - vorbis_mapping *mapping_setup=&vc->mappings[i]; - - if (get_bits(gb, 16)) { - av_log(vc->avccontext, AV_LOG_ERROR, "Other mappings than type 0 are not compliant with the Vorbis I specification. \n"); - return 1; - } - if (get_bits1(gb)) { - mapping_setup->submaps=get_bits(gb, 4)+1; - } else { - mapping_setup->submaps=1; - } - - if (get_bits1(gb)) { - mapping_setup->coupling_steps=get_bits(gb, 8)+1; - mapping_setup->magnitude=(uint_fast8_t *)av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t)); - mapping_setup->angle=(uint_fast8_t *)av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t)); - for(j=0;jcoupling_steps;++j) { - mapping_setup->magnitude[j]=get_bits(gb, ilog(vc->audio_channels-1)); - mapping_setup->angle[j]=get_bits(gb, ilog(vc->audio_channels-1)); - // FIXME: sanity checks - } - } else { - mapping_setup->coupling_steps=0; - } - - AV_DEBUG(" %d mapping coupling steps: %d \n", i, mapping_setup->coupling_steps); - - if(get_bits(gb, 2)) { - av_log(vc->avccontext, AV_LOG_ERROR, "%d. mapping setup data invalid. \n", i); - return 1; // following spec. - } - - if (mapping_setup->submaps>1) { - mapping_setup->mux=(uint_fast8_t *)av_mallocz(vc->audio_channels * sizeof(uint_fast8_t)); - for(j=0;jaudio_channels;++j) { - mapping_setup->mux[j]=get_bits(gb, 4); - } - } - - for(j=0;jsubmaps;++j) { - get_bits(gb, 8); // FIXME check? - mapping_setup->submap_floor[j]=get_bits(gb, 8); - mapping_setup->submap_residue[j]=get_bits(gb, 8); - - AV_DEBUG(" %d mapping %d submap : floor %d, residue %d \n", i, j, mapping_setup->submap_floor[j], mapping_setup->submap_residue[j]); - } - } - return 0; -} - -// Process modes part - -static void create_map( vorbis_context * vc, uint_fast8_t floor_number ) -{ - vorbis_floor * floors=vc->floors; - vorbis_floor0 * vf; - int idx; - int_fast8_t blockflag; - int_fast32_t * map; - int_fast32_t n; //TODO: could theoretically be smaller? - - for (blockflag=0;blockflag<2;++blockflag) - { - n=vc->blocksize[blockflag]/2; - floors[floor_number].data.t0.map[blockflag]= - av_malloc((n+1) * sizeof(int_fast32_t)); // n+sentinel - - map=floors[floor_number].data.t0.map[blockflag]; - vf=&floors[floor_number].data.t0; - - for (idx=0; idxrate*idx)/(2.0f*n)) * - ((vf->bark_map_size)/ - BARK(vf->rate/2.0f )) ); - if (vf->bark_map_size-1 < map[idx]) { - map[idx]=vf->bark_map_size-1; - } - } - map[n]=-1; - vf->map_size[blockflag]=n; - } - -# ifdef V_DEBUG - for(idx=0;idx<=n;++idx) { - AV_DEBUG("floor0 map: map at pos %d is %d\n", - idx, map[idx]); - } -# endif -} - -static int vorbis_parse_setup_hdr_modes(vorbis_context *vc) { - GetBitContext *gb=&vc->gb; - uint_fast8_t i; - - vc->mode_count=get_bits(gb, 6)+1; - vc->modes=(vorbis_mode *)av_mallocz(vc->mode_count * sizeof(vorbis_mode)); - - AV_DEBUG(" There are %d modes.\n", vc->mode_count); - - for(i=0;imode_count;++i) { - vorbis_mode *mode_setup=&vc->modes[i]; - - mode_setup->blockflag=get_bits(gb, 1); - mode_setup->windowtype=get_bits(gb, 16); //FIXME check - mode_setup->transformtype=get_bits(gb, 16); //FIXME check - mode_setup->mapping=get_bits(gb, 8); //FIXME check - - AV_DEBUG(" %d mode: blockflag %d, windowtype %d, transformtype %d, mapping %d \n", i, mode_setup->blockflag, mode_setup->windowtype, mode_setup->transformtype, mode_setup->mapping); - } - return 0; -} - -// Process the whole setup header using the functions above - -static int vorbis_parse_setup_hdr(vorbis_context *vc) { - GetBitContext *gb=&vc->gb; - - if ((get_bits(gb, 8)!='v') || (get_bits(gb, 8)!='o') || - (get_bits(gb, 8)!='r') || (get_bits(gb, 8)!='b') || - (get_bits(gb, 8)!='i') || (get_bits(gb, 8)!='s')) { - av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (no vorbis signature). \n"); - return 1; - } - - if (vorbis_parse_setup_hdr_codebooks(vc)) { - av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (codebooks). \n"); - return 2; - } - if (vorbis_parse_setup_hdr_tdtransforms(vc)) { - av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (time domain transforms). \n"); - return 3; - } - if (vorbis_parse_setup_hdr_floors(vc)) { - av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (floors). \n"); - return 4; - } - if (vorbis_parse_setup_hdr_residues(vc)) { - av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (residues). \n"); - return 5; - } - if (vorbis_parse_setup_hdr_mappings(vc)) { - av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (mappings). \n"); - return 6; - } - if (vorbis_parse_setup_hdr_modes(vc)) { - av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (modes). \n"); - return 7; - } - if (!get_bits1(gb)) { - av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (framing flag). \n"); - return 8; // framing flag bit unset error - } - - return 0; -} - -// Process the identification header - -static int vorbis_parse_id_hdr(vorbis_context *vc){ - GetBitContext *gb=&vc->gb; - uint_fast8_t bl0, bl1; - - if ((get_bits(gb, 8)!='v') || (get_bits(gb, 8)!='o') || - (get_bits(gb, 8)!='r') || (get_bits(gb, 8)!='b') || - (get_bits(gb, 8)!='i') || (get_bits(gb, 8)!='s')) { - av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (no vorbis signature). \n"); - return 1; - } - - vc->version=get_bits_long(gb, 32); //FIXME check 0 - vc->audio_channels=get_bits(gb, 8); //FIXME check >0 - vc->audio_samplerate=get_bits_long(gb, 32); //FIXME check >0 - vc->bitrate_maximum=get_bits_long(gb, 32); - vc->bitrate_nominal=get_bits_long(gb, 32); - vc->bitrate_minimum=get_bits_long(gb, 32); - bl0=get_bits(gb, 4); - bl1=get_bits(gb, 4); - vc->blocksize[0]=(1<blocksize[1]=(1<13 || bl0<6 || bl1>13 || bl1<6 || bl1avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (illegal blocksize). \n"); - return 3; - } - // output format int16 - if (vc->blocksize[1]/2 * vc->audio_channels * 2 > - AVCODEC_MAX_AUDIO_FRAME_SIZE) { - av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis channel count makes " - "output packets too large.\n"); - return 4; - } - vc->win[0]=ff_vorbis_vwin[bl0-6]; - vc->win[1]=ff_vorbis_vwin[bl1-6]; - - if(vc->exp_bias){ - int i, j; - for(j=0; j<2; j++){ - float *win = av_malloc(vc->blocksize[j]/2 * sizeof(float)); - for(i=0; iblocksize[j]/2; i++) - win[i] = vc->win[j][i] * (1<<15); - vc->win[j] = win; - } - } - - if ((get_bits1(gb)) == 0) { - av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (framing flag not set). \n"); - return 2; - } - - vc->channel_residues=(float *)av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float)); - vc->channel_floors=(float *)av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float)); - vc->saved=(float *)av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float)); - vc->ret=(float *)av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float)); - vc->buf=(float *)av_malloc(vc->blocksize[1] * sizeof(float)); - vc->buf_tmp=(float *)av_malloc(vc->blocksize[1] * sizeof(float)); - vc->saved_start=0; - - ff_mdct_init(&vc->mdct[0], bl0, 1); - ff_mdct_init(&vc->mdct[1], bl1, 1); - - AV_DEBUG(" vorbis version %d \n audio_channels %d \n audio_samplerate %d \n bitrate_max %d \n bitrate_nom %d \n bitrate_min %d \n blk_0 %d blk_1 %d \n ", - vc->version, vc->audio_channels, vc->audio_samplerate, vc->bitrate_maximum, vc->bitrate_nominal, vc->bitrate_minimum, vc->blocksize[0], vc->blocksize[1]); - -/* - BLK=vc->blocksize[0]; - for(i=0;iwin[0][i]=sin(0.5*3.14159265358*(sin(((float)i+0.5)/(float)BLK*3.14159265358))*(sin(((float)i+0.5)/(float)BLK*3.14159265358))); - } -*/ - - return 0; -} - -// Process the extradata using the functions above (identification header, setup header) - -static int vorbis_decode_init(AVCodecContext *avccontext) { - vorbis_context *vc = avccontext->priv_data ; - uint8_t *headers = avccontext->extradata; - int headers_len=avccontext->extradata_size; - uint8_t *header_start[3]; - int header_len[3]; - GetBitContext *gb = &(vc->gb); - int hdr_type; - - vc->avccontext = avccontext; - dsputil_init(&vc->dsp, avccontext); - - if(vc->dsp.float_to_int16 == ff_float_to_int16_c) { - vc->add_bias = 385; - vc->exp_bias = 0; - } else { - vc->add_bias = 0; - vc->exp_bias = 15<<23; - } - - if (!headers_len) { - av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n"); - return -1; - } - - if (ff_split_xiph_headers(headers, headers_len, 30, header_start, header_len) < 0) { - av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n"); - return -1; - } - - init_get_bits(gb, header_start[0], header_len[0]*8); - hdr_type=get_bits(gb, 8); - if (hdr_type!=1) { - av_log(avccontext, AV_LOG_ERROR, "First header is not the id header.\n"); - return -1; - } - if (vorbis_parse_id_hdr(vc)) { - av_log(avccontext, AV_LOG_ERROR, "Id header corrupt.\n"); - vorbis_free(vc); - return -1; - } - - init_get_bits(gb, header_start[2], header_len[2]*8); - hdr_type=get_bits(gb, 8); - if (hdr_type!=5) { - av_log(avccontext, AV_LOG_ERROR, "Third header is not the setup header.\n"); - return -1; - } - if (vorbis_parse_setup_hdr(vc)) { - av_log(avccontext, AV_LOG_ERROR, "Setup header corrupt.\n"); - vorbis_free(vc); - return -1; - } - - avccontext->channels = vc->audio_channels; - avccontext->sample_rate = vc->audio_samplerate; - - return 0 ; -} - -// Decode audiopackets ------------------------------------------------- - -// Read and decode floor - -static uint_fast8_t vorbis_floor0_decode(vorbis_context *vc, - vorbis_floor_data *vfu, float *vec) { - vorbis_floor0 * vf=&vfu->t0; - float * lsp=vf->lsp; - uint_fast32_t amplitude; - uint_fast32_t book_idx; - uint_fast8_t blockflag=vc->modes[vc->mode_number].blockflag; - - amplitude=get_bits(&vc->gb, vf->amplitude_bits); - if (amplitude>0) { - float last = 0; - uint_fast16_t lsp_len = 0; - uint_fast16_t idx; - vorbis_codebook codebook; - - book_idx=get_bits(&vc->gb, ilog(vf->num_books)); - if ( book_idx >= vf->num_books ) { - av_log( vc->avccontext, AV_LOG_ERROR, - "floor0 dec: booknumber too high!\n" ); - //FIXME: look above - } - AV_DEBUG( "floor0 dec: booknumber: %u\n", book_idx ); - codebook=vc->codebooks[vf->book_list[book_idx]]; - - while (lsp_lenorder) { - int vec_off; - - AV_DEBUG( "floor0 dec: book dimension: %d\n", codebook.dimensions ); - AV_DEBUG( "floor0 dec: maximum depth: %d\n", codebook.maxdepth ); - /* read temp vector */ - vec_off=get_vlc2(&vc->gb, - codebook.vlc.table, - codebook.nb_bits, - codebook.maxdepth ) * - codebook.dimensions; - AV_DEBUG( "floor0 dec: vector offset: %d\n", vec_off ); - /* copy each vector component and add last to it */ - for (idx=0; idxorder; - float wstep=M_PI/vf->bark_map_size; - - for(i=0;imap_size, order, wstep); - - i=0; - while(imap_size[blockflag]) { - int j, iter_cond=vf->map[blockflag][i]; - float p=0.5f; - float q=0.5f; - float two_cos_w=2.0f*cos(wstep*iter_cond); // needed all times - - /* similar part for the q and p products */ - for(j=0;jamplitude_offset)/ - (((1<amplitude_bits)-1) * sqrt(p+q)) ) - - vf->amplitude_offset ) * .11512925f - ); - } - - /* fill vector */ - do { vec[i]=q; ++i; }while(vf->map[blockflag][i]==iter_cond); - } - } - } - else { - /* this channel is unused */ - return 1; - } - - AV_DEBUG(" Floor0 decoded\n"); - - return 0; -} - -static void render_line(int x0, int y0, int x1, int y1, float * buf, int n) { +static void render_line(int x0, int y0, int x1, int y1, float * buf) { int dy = y1 - y0; int adx = x1 - x0; - int ady = FFABS(dy); int base = dy / adx; + int ady = FFABS(dy) - FFABS(base) * adx; int x = x0; int y = y0; int err = 0; - int sy; - if (dy < 0) sy = base - 1; - else sy = base + 1; - ady = ady - FFABS(base) * adx; - if (x >= n) return; + int sy = dy<0 ? -1 : 1; buf[x] = ff_vorbis_floor1_inverse_db_table[y]; - for (x = x0 + 1; x < x1; x++) { - if (x >= n) return; + while (++x < x1) { err += ady; if (err >= adx) { err -= adx; y += sy; - } else { - y += base; } + y += base; buf[x] = ff_vorbis_floor1_inverse_db_table[y]; } } @@ -1243,548 +169,14 @@ void ff_vorbis_floor1_render_list(floor1_entry_t * list, int values, uint_fast16 for (i = 1; i < values; i++) { int pos = list[i].sort; if (flag[pos]) { - render_line(lx, ly, list[pos].x, y_list[pos] * multiplier, out, samples); - lx = list[pos].x; - ly = y_list[pos] * multiplier; + int x1 = list[pos].x; + int y1 = y_list[pos] * multiplier; + if (lx < samples) + render_line(lx, ly, FFMIN(x1,samples), y1, out); + lx = x1; + ly = y1; } if (lx >= samples) break; } - if (lx < samples) render_line(lx, ly, samples, ly, out, samples); -} - -static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc, vorbis_floor_data *vfu, float *vec) { - vorbis_floor1 * vf=&vfu->t1; - GetBitContext *gb=&vc->gb; - uint_fast16_t range_v[4]={ 256, 128, 86, 64 }; - uint_fast16_t range=range_v[vf->multiplier-1]; - uint_fast16_t floor1_Y[vf->x_list_dim]; - uint_fast16_t floor1_Y_final[vf->x_list_dim]; - int floor1_flag[vf->x_list_dim]; - uint_fast8_t class_; - uint_fast8_t cdim; - uint_fast8_t cbits; - uint_fast8_t csub; - uint_fast8_t cval; - int_fast16_t book; - uint_fast16_t offset; - uint_fast16_t i,j; - /*u*/int_fast16_t adx, ady, off, predicted; // WTF ? dy/adx= (unsigned)dy/adx ? - int_fast16_t dy, err; - - - if (!get_bits1(gb)) return 1; // silence - -// Read values (or differences) for the floor's points - - floor1_Y[0]=get_bits(gb, ilog(range-1)); - floor1_Y[1]=get_bits(gb, ilog(range-1)); - - AV_DEBUG("floor 0 Y %d floor 1 Y %d \n", floor1_Y[0], floor1_Y[1]); - - offset=2; - for(i=0;ipartitions;++i) { - class_=vf->partition_class[i]; - cdim=vf->class_dimensions[class_]; - cbits=vf->class_subclasses[class_]; - csub=(1<codebooks[vf->class_masterbook[class_]].vlc.table, - vc->codebooks[vf->class_masterbook[class_]].nb_bits, 3); - } - - for(j=0;jsubclass_books[class_][cval & csub]; - - AV_DEBUG("book %d Cbits %d cval %d bits:%d \n", book, cbits, cval, get_bits_count(gb)); - - cval=cval>>cbits; - if (book>-1) { - floor1_Y[offset+j]=get_vlc2(gb, vc->codebooks[book].vlc.table, - vc->codebooks[book].nb_bits, 3); - } else { - floor1_Y[offset+j]=0; - } - - AV_DEBUG(" floor(%d) = %d \n", vf->list[offset+j].x, floor1_Y[offset+j]); - } - offset+=cdim; - } - -// Amplitude calculation from the differences - - floor1_flag[0]=1; - floor1_flag[1]=1; - floor1_Y_final[0]=floor1_Y[0]; - floor1_Y_final[1]=floor1_Y[1]; - - for(i=2;ix_list_dim;++i) { - uint_fast16_t val, highroom, lowroom, room; - uint_fast16_t high_neigh_offs; - uint_fast16_t low_neigh_offs; - - low_neigh_offs=vf->list[i].low; - high_neigh_offs=vf->list[i].high; - dy=floor1_Y_final[high_neigh_offs]-floor1_Y_final[low_neigh_offs]; // render_point begin - adx=vf->list[high_neigh_offs].x-vf->list[low_neigh_offs].x; - ady= FFABS(dy); - err=ady*(vf->list[i].x-vf->list[low_neigh_offs].x); - off=(int16_t)err/(int16_t)adx; - if (dy<0) { - predicted=floor1_Y_final[low_neigh_offs]-off; - } else { - predicted=floor1_Y_final[low_neigh_offs]+off; - } // render_point end - - val=floor1_Y[i]; - highroom=range-predicted; - lowroom=predicted; - if (highroom < lowroom) { - room=highroom*2; - } else { - room=lowroom*2; // SPEC mispelling - } - if (val) { - floor1_flag[low_neigh_offs]=1; - floor1_flag[high_neigh_offs]=1; - floor1_flag[i]=1; - if (val>=room) { - if (highroom > lowroom) { - floor1_Y_final[i]=val-lowroom+predicted; - } else { - floor1_Y_final[i]=predicted-val+highroom-1; - } - } else { - if (val & 1) { - floor1_Y_final[i]=predicted-(val+1)/2; - } else { - floor1_Y_final[i]=predicted+val/2; - } - } - } else { - floor1_flag[i]=0; - floor1_Y_final[i]=predicted; - } - - AV_DEBUG(" Decoded floor(%d) = %d / val %d \n", vf->list[i].x, floor1_Y_final[i], val); - } - -// Curve synth - connect the calculated dots and convert from dB scale FIXME optimize ? - - ff_vorbis_floor1_render_list(vf->list, vf->x_list_dim, floor1_Y_final, floor1_flag, vf->multiplier, vec, vf->list[1].x); - - AV_DEBUG(" Floor decoded\n"); - - return 0; -} - -// Read and decode residue - -static int vorbis_residue_decode(vorbis_context *vc, vorbis_residue *vr, uint_fast8_t ch, uint_fast8_t *do_not_decode, float *vec, uint_fast16_t vlen) { - GetBitContext *gb=&vc->gb; - uint_fast8_t c_p_c=vc->codebooks[vr->classbook].dimensions; - uint_fast16_t n_to_read=vr->end-vr->begin; - uint_fast16_t ptns_to_read=n_to_read/vr->partition_size; - uint_fast8_t classifs[ptns_to_read*vc->audio_channels]; - uint_fast8_t pass; - uint_fast8_t ch_used; - uint_fast8_t i,j,l; - uint_fast16_t k; - - if (vr->type==2) { - for(j=1;jmaxpass;++pass) { // FIXME OPTIMIZE? - uint_fast16_t voffset; - uint_fast16_t partition_count; - uint_fast16_t j_times_ptns_to_read; - - voffset=vr->begin; - for(partition_count=0;partition_countclassifications]; - for(j_times_ptns_to_read=0, j=0;jcodebooks[vr->classbook].vlc.table, - vc->codebooks[vr->classbook].nb_bits, 3); - - AV_DEBUG("Classword: %d \n", temp); - - assert(vr->classifications > 1 && temp<=65536); //needed for inverse[] - for(i=0;i>32; - if (partition_count+c_p_c-1-i < ptns_to_read) { - classifs[j_times_ptns_to_read+partition_count+c_p_c-1-i]=temp-temp2*vr->classifications; - } - temp=temp2; - } - } - j_times_ptns_to_read+=ptns_to_read; - } - } - for(i=0;(ibooks[vqclass][pass]; - - if (vqbook>=0) { - uint_fast16_t coffs; - unsigned dim= vc->codebooks[vqbook].dimensions; // not uint_fast8_t: 64bit is slower here on amd64 - uint_fast16_t step= dim==1 ? vr->partition_size - : FASTDIV(vr->partition_size, dim); - vorbis_codebook codebook= vc->codebooks[vqbook]; - - if (vr->type==0) { - - voffs=voffset+j*vlen; - for(k=0;ktype==1) { - voffs=voffset+j*vlen; - for(k=0;ktype==2 && ch==2 && (voffset&1)==0 && (dim&1)==0) { // most frequent case optimized - voffs=voffset>>1; - - if(dim==2) { - for(k=0;ktype==2) { - voffs=voffset; - - for(k=0;kavccontext, AV_LOG_ERROR, " Invalid residue type while residue decode?! \n"); - return 1; - } - } - } - j_times_ptns_to_read+=ptns_to_read; - } - ++partition_count; - voffset+=vr->partition_size; - } - } - } - return 0; -} - -void vorbis_inverse_coupling(float *mag, float *ang, int blocksize) -{ - int i; - for(i=0; i0.0) { - if (ang[i]>0.0) { - ang[i]=mag[i]-ang[i]; - } else { - float temp=ang[i]; - ang[i]=mag[i]; - mag[i]+=temp; - } - } else { - if (ang[i]>0.0) { - ang[i]+=mag[i]; - } else { - float temp=ang[i]; - ang[i]=mag[i]; - mag[i]-=temp; - } - } - } + if (lx < samples) render_line(lx, ly, samples, ly, out); } - -// Decode the audio packet using the functions above - -static int vorbis_parse_audio_packet(vorbis_context *vc) { - GetBitContext *gb=&vc->gb; - - uint_fast8_t previous_window=0,next_window=0; - uint_fast8_t mode_number; - uint_fast16_t blocksize; - int_fast32_t i,j; - uint_fast8_t no_residue[vc->audio_channels]; - uint_fast8_t do_not_decode[vc->audio_channels]; - vorbis_mapping *mapping; - float *ch_res_ptr=vc->channel_residues; - float *ch_floor_ptr=vc->channel_floors; - uint_fast8_t res_chan[vc->audio_channels]; - uint_fast8_t res_num=0; - int_fast16_t retlen=0; - uint_fast16_t saved_start=0; - float fadd_bias = vc->add_bias; - - if (get_bits1(gb)) { - av_log(vc->avccontext, AV_LOG_ERROR, "Not a Vorbis I audio packet.\n"); - return -1; // packet type not audio - } - - if (vc->mode_count==1) { - mode_number=0; - } else { - mode_number=get_bits(gb, ilog(vc->mode_count-1)); - } - vc->mode_number=mode_number; - mapping=&vc->mappings[vc->modes[mode_number].mapping]; - - AV_DEBUG(" Mode number: %d , mapping: %d , blocktype %d \n", mode_number, vc->modes[mode_number].mapping, vc->modes[mode_number].blockflag); - - if (vc->modes[mode_number].blockflag) { - previous_window=get_bits1(gb); - next_window=get_bits1(gb); - } - - blocksize=vc->blocksize[vc->modes[mode_number].blockflag]; - memset(ch_res_ptr, 0, sizeof(float)*vc->audio_channels*blocksize/2); //FIXME can this be removed ? - memset(ch_floor_ptr, 0, sizeof(float)*vc->audio_channels*blocksize/2); //FIXME can this be removed ? - -// Decode floor - - for(i=0;iaudio_channels;++i) { - vorbis_floor *floor; - if (mapping->submaps>1) { - floor=&vc->floors[mapping->submap_floor[mapping->mux[i]]]; - } else { - floor=&vc->floors[mapping->submap_floor[0]]; - } - - no_residue[i]=floor->decode(vc, &floor->data, ch_floor_ptr); - ch_floor_ptr+=blocksize/2; - } - -// Nonzero vector propagate - - for(i=mapping->coupling_steps-1;i>=0;--i) { - if (!(no_residue[mapping->magnitude[i]] & no_residue[mapping->angle[i]])) { - no_residue[mapping->magnitude[i]]=0; - no_residue[mapping->angle[i]]=0; - } - } - -// Decode residue - - for(i=0;isubmaps;++i) { - vorbis_residue *residue; - uint_fast8_t ch=0; - - for(j=0;jaudio_channels;++j) { - if ((mapping->submaps==1) || (i=mapping->mux[j])) { - res_chan[j]=res_num; - if (no_residue[j]) { - do_not_decode[ch]=1; - } else { - do_not_decode[ch]=0; - } - ++ch; - ++res_num; - } - } - residue=&vc->residues[mapping->submap_residue[i]]; - vorbis_residue_decode(vc, residue, ch, do_not_decode, ch_res_ptr, blocksize/2); - - ch_res_ptr+=ch*blocksize/2; - } - -// Inverse coupling - - for(i=mapping->coupling_steps-1;i>=0;--i) { //warning: i has to be signed - float *mag, *ang; - - mag=vc->channel_residues+res_chan[mapping->magnitude[i]]*blocksize/2; - ang=vc->channel_residues+res_chan[mapping->angle[i]]*blocksize/2; - vc->dsp.vorbis_inverse_coupling(mag, ang, blocksize/2); - } - -// Dotproduct - - for(j=0, ch_floor_ptr=vc->channel_floors;jaudio_channels;++j,ch_floor_ptr+=blocksize/2) { - ch_res_ptr=vc->channel_residues+res_chan[j]*blocksize/2; - vc->dsp.vector_fmul(ch_floor_ptr, ch_res_ptr, blocksize/2); - } - -// MDCT, overlap/add, save data for next overlapping FPMATH - - for(j=0;jaudio_channels;++j) { - uint_fast8_t step=vc->audio_channels; - uint_fast16_t k; - float *saved=vc->saved+j*vc->blocksize[1]/2; - float *ret=vc->ret; - const float *lwin=vc->win[1]; - const float *swin=vc->win[0]; - float *buf=vc->buf; - float *buf_tmp=vc->buf_tmp; - - ch_floor_ptr=vc->channel_floors+j*blocksize/2; - - saved_start=vc->saved_start; - - vc->mdct[0].fft.imdct_calc(&vc->mdct[vc->modes[mode_number].blockflag], buf, ch_floor_ptr, buf_tmp); - - //FIXME process channels together, to allow faster simd vector_fmul_add_add? - if (vc->modes[mode_number].blockflag) { - // -- overlap/add - if (previous_window) { - vc->dsp.vector_fmul_add_add(ret+j, buf, lwin, saved, vc->add_bias, vc->blocksize[1]/2, step); - retlen=vc->blocksize[1]/2; - } else { - int len = (vc->blocksize[1]-vc->blocksize[0])/4; - buf += len; - vc->dsp.vector_fmul_add_add(ret+j, buf, swin, saved, vc->add_bias, vc->blocksize[0]/2, step); - k = vc->blocksize[0]/2*step + j; - buf += vc->blocksize[0]/2; - if(vc->exp_bias){ - for(i=0; iexp_bias; // ret[k]=buf[i]*(1<buf; - retlen=vc->blocksize[0]/2+len; - } - // -- save - if (next_window) { - buf += vc->blocksize[1]/2; - vc->dsp.vector_fmul_reverse(saved, buf, lwin, vc->blocksize[1]/2); - saved_start=0; - } else { - saved_start=(vc->blocksize[1]-vc->blocksize[0])/4; - buf += vc->blocksize[1]/2; - for(i=0; iexp_bias; - vc->dsp.vector_fmul_reverse(saved+saved_start, buf+saved_start, swin, vc->blocksize[0]/2); - } - } else { - // --overlap/add - if(vc->add_bias) { - for(k=j, i=0;idsp.vector_fmul_add_add(ret+k, buf, swin, saved+saved_start, vc->add_bias, vc->blocksize[0]/2, step); - retlen=saved_start+vc->blocksize[0]/2; - // -- save - buf += vc->blocksize[0]/2; - vc->dsp.vector_fmul_reverse(saved, buf, swin, vc->blocksize[0]/2); - saved_start=0; - } - } - vc->saved_start=saved_start; - - return retlen*vc->audio_channels; -} - -// Return the decoded audio packet through the standard api - -static int vorbis_decode_frame(AVCodecContext *avccontext, - void *data, int *data_size, - uint8_t *buf, int buf_size) -{ - vorbis_context *vc = avccontext->priv_data ; - GetBitContext *gb = &(vc->gb); - - int_fast16_t len; - - if(!buf_size){ - return 0; - } - - AV_DEBUG("packet length %d \n", buf_size); - - init_get_bits(gb, buf, buf_size*8); - - len=vorbis_parse_audio_packet(vc); - - if (len<=0) { - *data_size=0; - return buf_size; - } - - if (!vc->first_frame) { - vc->first_frame=1; - *data_size=0; - return buf_size ; - } - - AV_DEBUG("parsed %d bytes %d bits, returned %d samples (*ch*bits) \n", get_bits_count(gb)/8, get_bits_count(gb)%8, len); - - vc->dsp.float_to_int16(data, vc->ret, len); - *data_size=len*2; - - return buf_size ; -} - -// Close decoder - -static int vorbis_decode_close(AVCodecContext *avccontext) { - vorbis_context *vc = avccontext->priv_data; - - vorbis_free(vc); - - return 0 ; -} - -AVCodec vorbis_decoder = { - "vorbis", - CODEC_TYPE_AUDIO, - CODEC_ID_VORBIS, - sizeof(vorbis_context), - vorbis_decode_init, - NULL, - vorbis_decode_close, - vorbis_decode_frame, -}; - diff --git a/contrib/ffmpeg/libavcodec/vorbis.h b/contrib/ffmpeg/libavcodec/vorbis.h index cda909aa9..f5e8b7a99 100644 --- a/contrib/ffmpeg/libavcodec/vorbis.h +++ b/contrib/ffmpeg/libavcodec/vorbis.h @@ -18,8 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef VORBIS_H -#define VORBIS_H +#ifndef FFMPEG_VORBIS_H +#define FFMPEG_VORBIS_H #include "avcodec.h" @@ -40,4 +40,4 @@ void ff_vorbis_floor1_render_list(floor1_entry_t * list, int values, uint_fast16 #define ilog(i) av_log2(2*(i)) -#endif +#endif /* FFMPEG_VORBIS_H */ diff --git a/contrib/ffmpeg/libavcodec/vorbis_dec.c b/contrib/ffmpeg/libavcodec/vorbis_dec.c new file mode 100644 index 000000000..3ef56dc16 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/vorbis_dec.c @@ -0,0 +1,1638 @@ +/** + * @file vorbis_dec.c + * Vorbis I decoder + * @author Denes Balatoni ( dbalatoni programozo hu ) + + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#undef V_DEBUG +//#define V_DEBUG +//#define AV_DEBUG(...) av_log(NULL, AV_LOG_INFO, __VA_ARGS__) + +#include + +#define ALT_BITSTREAM_READER_LE +#include "avcodec.h" +#include "bitstream.h" +#include "dsputil.h" + +#include "vorbis.h" +#include "xiph.h" + +#define V_NB_BITS 8 +#define V_NB_BITS2 11 +#define V_MAX_VLCS (1<<16) + +#ifndef V_DEBUG +#define AV_DEBUG(...) +#endif + +#undef NDEBUG +#include + +typedef struct { + uint_fast8_t dimensions; + uint_fast8_t lookup_type; + uint_fast8_t maxdepth; + VLC vlc; + float *codevectors; + unsigned int nb_bits; +} vorbis_codebook; + +typedef union vorbis_floor_u vorbis_floor_data; +typedef struct vorbis_floor0_s vorbis_floor0; +typedef struct vorbis_floor1_s vorbis_floor1; +struct vorbis_context_s; +typedef +uint_fast8_t (* vorbis_floor_decode_func) + (struct vorbis_context_s *, vorbis_floor_data *, float *); +typedef struct { + uint_fast8_t floor_type; + vorbis_floor_decode_func decode; + union vorbis_floor_u + { + struct vorbis_floor0_s + { + uint_fast8_t order; + uint_fast16_t rate; + uint_fast16_t bark_map_size; + int_fast32_t * map[2]; + uint_fast32_t map_size[2]; + uint_fast8_t amplitude_bits; + uint_fast8_t amplitude_offset; + uint_fast8_t num_books; + uint_fast8_t * book_list; + float * lsp; + } t0; + struct vorbis_floor1_s + { + uint_fast8_t partitions; + uint_fast8_t maximum_class; + uint_fast8_t partition_class[32]; + uint_fast8_t class_dimensions[16]; + uint_fast8_t class_subclasses[16]; + uint_fast8_t class_masterbook[16]; + int_fast16_t subclass_books[16][8]; + uint_fast8_t multiplier; + uint_fast16_t x_list_dim; + floor1_entry_t * list; + } t1; + } data; +} vorbis_floor; + +typedef struct { + uint_fast16_t type; + uint_fast32_t begin; + uint_fast32_t end; + uint_fast32_t partition_size; + uint_fast8_t classifications; + uint_fast8_t classbook; + int_fast16_t books[64][8]; + uint_fast8_t maxpass; +} vorbis_residue; + +typedef struct { + uint_fast8_t submaps; + uint_fast16_t coupling_steps; + uint_fast8_t *magnitude; + uint_fast8_t *angle; + uint_fast8_t *mux; + uint_fast8_t submap_floor[16]; + uint_fast8_t submap_residue[16]; +} vorbis_mapping; + +typedef struct { + uint_fast8_t blockflag; + uint_fast16_t windowtype; + uint_fast16_t transformtype; + uint_fast8_t mapping; +} vorbis_mode; + +typedef struct vorbis_context_s { + AVCodecContext *avccontext; + GetBitContext gb; + DSPContext dsp; + + MDCTContext mdct[2]; + uint_fast8_t first_frame; + uint_fast32_t version; + uint_fast8_t audio_channels; + uint_fast32_t audio_samplerate; + uint_fast32_t bitrate_maximum; + uint_fast32_t bitrate_nominal; + uint_fast32_t bitrate_minimum; + uint_fast32_t blocksize[2]; + const float * win[2]; + uint_fast16_t codebook_count; + vorbis_codebook *codebooks; + uint_fast8_t floor_count; + vorbis_floor *floors; + uint_fast8_t residue_count; + vorbis_residue *residues; + uint_fast8_t mapping_count; + vorbis_mapping *mappings; + uint_fast8_t mode_count; + vorbis_mode *modes; + uint_fast8_t mode_number; // mode number for the current packet + float *channel_residues; + float *channel_floors; + float *saved; + uint_fast16_t saved_start; + float *ret; + float *buf; + float *buf_tmp; + uint_fast32_t add_bias; // for float->int conversion + uint_fast32_t exp_bias; +} vorbis_context; + +/* Helper functions */ + +#define BARK(x) \ + (13.1f*atan(0.00074f*(x))+2.24f*atan(1.85e-8f*(x)*(x))+1e-4f*(x)) + +static float vorbisfloat2float(uint_fast32_t val) { + double mant=val&0x1fffff; + long exp=(val&0x7fe00000L)>>21; + if (val&0x80000000) mant=-mant; + return(ldexp(mant, exp-20-768)); +} + + +// Free all allocated memory ----------------------------------------- + +static void vorbis_free(vorbis_context *vc) { + int_fast16_t i; + + av_freep(&vc->channel_residues); + av_freep(&vc->channel_floors); + av_freep(&vc->saved); + av_freep(&vc->ret); + av_freep(&vc->buf); + av_freep(&vc->buf_tmp); + + av_freep(&vc->residues); + av_freep(&vc->modes); + + ff_mdct_end(&vc->mdct[0]); + ff_mdct_end(&vc->mdct[1]); + + for(i=0;icodebook_count;++i) { + av_free(vc->codebooks[i].codevectors); + free_vlc(&vc->codebooks[i].vlc); + } + av_freep(&vc->codebooks); + + for(i=0;ifloor_count;++i) { + if(vc->floors[i].floor_type==0) { + av_free(vc->floors[i].data.t0.map[0]); + av_free(vc->floors[i].data.t0.map[1]); + av_free(vc->floors[i].data.t0.book_list); + av_free(vc->floors[i].data.t0.lsp); + } + else { + av_free(vc->floors[i].data.t1.list); + } + } + av_freep(&vc->floors); + + for(i=0;imapping_count;++i) { + av_free(vc->mappings[i].magnitude); + av_free(vc->mappings[i].angle); + av_free(vc->mappings[i].mux); + } + av_freep(&vc->mappings); + + if(vc->exp_bias){ + av_freep(&vc->win[0]); + av_freep(&vc->win[1]); + } +} + +// Parse setup header ------------------------------------------------- + +// Process codebooks part + +static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc) { + uint_fast16_t cb; + uint8_t *tmp_vlc_bits; + uint32_t *tmp_vlc_codes; + GetBitContext *gb=&vc->gb; + + vc->codebook_count=get_bits(gb,8)+1; + + AV_DEBUG(" Codebooks: %d \n", vc->codebook_count); + + vc->codebooks=av_mallocz(vc->codebook_count * sizeof(vorbis_codebook)); + tmp_vlc_bits =av_mallocz(V_MAX_VLCS * sizeof(uint8_t)); + tmp_vlc_codes=av_mallocz(V_MAX_VLCS * sizeof(uint32_t)); + + for(cb=0;cbcodebook_count;++cb) { + vorbis_codebook *codebook_setup=&vc->codebooks[cb]; + uint_fast8_t ordered; + uint_fast32_t t, used_entries=0; + uint_fast32_t entries; + + AV_DEBUG(" %d. Codebook \n", cb); + + if (get_bits(gb, 24)!=0x564342) { + av_log(vc->avccontext, AV_LOG_ERROR, " %"PRIdFAST16". Codebook setup data corrupt. \n", cb); + goto error; + } + + codebook_setup->dimensions=get_bits(gb, 16); + if (codebook_setup->dimensions>16) { + av_log(vc->avccontext, AV_LOG_ERROR, " %"PRIdFAST16". Codebook's dimension is too large (%d). \n", cb, codebook_setup->dimensions); + goto error; + } + entries=get_bits(gb, 24); + if (entries>V_MAX_VLCS) { + av_log(vc->avccontext, AV_LOG_ERROR, " %"PRIdFAST16". Codebook has too many entries (%"PRIdFAST32"). \n", cb, entries); + goto error; + } + + ordered=get_bits1(gb); + + AV_DEBUG(" codebook_dimensions %d, codebook_entries %d \n", codebook_setup->dimensions, entries); + + if (!ordered) { + uint_fast16_t ce; + uint_fast8_t flag; + uint_fast8_t sparse=get_bits1(gb); + + AV_DEBUG(" not ordered \n"); + + if (sparse) { + AV_DEBUG(" sparse \n"); + + used_entries=0; + for(ce=0;ceused_entries) { + av_log(vc->avccontext, AV_LOG_ERROR, " More codelengths than codes in codebook. \n"); + goto error; + } + } + + codebook_setup->lookup_type=get_bits(gb, 4); + + AV_DEBUG(" lookup type: %d : %s \n", codebook_setup->lookup_type, codebook_setup->lookup_type ? "vq" : "no lookup" ); + +// If the codebook is used for (inverse) VQ, calculate codevectors. + + if (codebook_setup->lookup_type==1) { + uint_fast16_t i, j, k; + uint_fast16_t codebook_lookup_values=ff_vorbis_nth_root(entries, codebook_setup->dimensions); + uint_fast16_t codebook_multiplicands[codebook_lookup_values]; + + float codebook_minimum_value=vorbisfloat2float(get_bits_long(gb, 32)); + float codebook_delta_value=vorbisfloat2float(get_bits_long(gb, 32)); + uint_fast8_t codebook_value_bits=get_bits(gb, 4)+1; + uint_fast8_t codebook_sequence_p=get_bits1(gb); + + AV_DEBUG(" We expect %d numbers for building the codevectors. \n", codebook_lookup_values); + AV_DEBUG(" delta %f minmum %f \n", codebook_delta_value, codebook_minimum_value); + + for(i=0;icodevectors=used_entries ? av_mallocz(used_entries*codebook_setup->dimensions * sizeof(float)) : NULL; + for(j=0, i=0;idimensions; + + if (tmp_vlc_bits[i]) { + float last=0.0; + uint_fast32_t lookup_offset=i; + +#ifdef V_DEBUG + av_log(vc->avccontext, AV_LOG_INFO, "Lookup offset %d ,", i); +#endif + + for(k=0;kcodevectors[j*dim+k]=codebook_multiplicands[multiplicand_offset]*codebook_delta_value+codebook_minimum_value+last; + if (codebook_sequence_p) { + last=codebook_setup->codevectors[j*dim+k]; + } + lookup_offset/=codebook_lookup_values; + } + tmp_vlc_bits[j]=tmp_vlc_bits[i]; + +#ifdef V_DEBUG + av_log(vc->avccontext, AV_LOG_INFO, "real lookup offset %d, vector: ", j); + for(k=0;kavccontext, AV_LOG_INFO, " %f ", codebook_setup->codevectors[j*dim+k]); + } + av_log(vc->avccontext, AV_LOG_INFO, "\n"); +#endif + + ++j; + } + } + if (j!=used_entries) { + av_log(vc->avccontext, AV_LOG_ERROR, "Bug in codevector vector building code. \n"); + goto error; + } + entries=used_entries; + } + else if (codebook_setup->lookup_type>=2) { + av_log(vc->avccontext, AV_LOG_ERROR, "Codebook lookup type not supported. \n"); + goto error; + } + +// Initialize VLC table + if (ff_vorbis_len2vlc(tmp_vlc_bits, tmp_vlc_codes, entries)) { + av_log(vc->avccontext, AV_LOG_ERROR, " Invalid code lengths while generating vlcs. \n"); + goto error; + } + codebook_setup->maxdepth=0; + for(t=0;t=codebook_setup->maxdepth) codebook_setup->maxdepth=tmp_vlc_bits[t]; + + if(codebook_setup->maxdepth > 3*V_NB_BITS) codebook_setup->nb_bits=V_NB_BITS2; + else codebook_setup->nb_bits=V_NB_BITS; + + codebook_setup->maxdepth=(codebook_setup->maxdepth+codebook_setup->nb_bits-1)/codebook_setup->nb_bits; + + if (init_vlc(&codebook_setup->vlc, codebook_setup->nb_bits, entries, tmp_vlc_bits, sizeof(*tmp_vlc_bits), sizeof(*tmp_vlc_bits), tmp_vlc_codes, sizeof(*tmp_vlc_codes), sizeof(*tmp_vlc_codes), INIT_VLC_LE)) { + av_log(vc->avccontext, AV_LOG_ERROR, " Error generating vlc tables. \n"); + goto error; + } + } + + av_free(tmp_vlc_bits); + av_free(tmp_vlc_codes); + return 0; + +// Error: +error: + av_free(tmp_vlc_bits); + av_free(tmp_vlc_codes); + return 1; +} + +// Process time domain transforms part (unused in Vorbis I) + +static int vorbis_parse_setup_hdr_tdtransforms(vorbis_context *vc) { + GetBitContext *gb=&vc->gb; + uint_fast8_t i; + uint_fast8_t vorbis_time_count=get_bits(gb, 6)+1; + + for(i=0;iavccontext, AV_LOG_ERROR, "Vorbis time domain transform data nonzero. \n"); + return 1; + } + } + return 0; +} + +// Process floors part + +static uint_fast8_t vorbis_floor0_decode(vorbis_context *vc, + vorbis_floor_data *vfu, float *vec); +static void create_map( vorbis_context * vc, uint_fast8_t floor_number ); +static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc, + vorbis_floor_data *vfu, float *vec); +static int vorbis_parse_setup_hdr_floors(vorbis_context *vc) { + GetBitContext *gb=&vc->gb; + uint_fast16_t i,j,k; + + vc->floor_count=get_bits(gb, 6)+1; + + vc->floors=av_mallocz(vc->floor_count * sizeof(vorbis_floor)); + + for (i=0;ifloor_count;++i) { + vorbis_floor *floor_setup=&vc->floors[i]; + + floor_setup->floor_type=get_bits(gb, 16); + + AV_DEBUG(" %d. floor type %d \n", i, floor_setup->floor_type); + + if (floor_setup->floor_type==1) { + uint_fast8_t maximum_class=0; + uint_fast8_t rangebits; + uint_fast16_t floor1_values=2; + + floor_setup->decode=vorbis_floor1_decode; + + floor_setup->data.t1.partitions=get_bits(gb, 5); + + AV_DEBUG(" %d.floor: %d partitions \n", i, floor_setup->data.t1.partitions); + + for(j=0;jdata.t1.partitions;++j) { + floor_setup->data.t1.partition_class[j]=get_bits(gb, 4); + if (floor_setup->data.t1.partition_class[j]>maximum_class) maximum_class=floor_setup->data.t1.partition_class[j]; + + AV_DEBUG(" %d. floor %d partition class %d \n", i, j, floor_setup->data.t1.partition_class[j]); + + } + + AV_DEBUG(" maximum class %d \n", maximum_class); + + floor_setup->data.t1.maximum_class=maximum_class; + + for(j=0;j<=maximum_class;++j) { + floor_setup->data.t1.class_dimensions[j]=get_bits(gb, 3)+1; + floor_setup->data.t1.class_subclasses[j]=get_bits(gb, 2); + + AV_DEBUG(" %d floor %d class dim: %d subclasses %d \n", i, j, floor_setup->data.t1.class_dimensions[j], floor_setup->data.t1.class_subclasses[j]); + + if (floor_setup->data.t1.class_subclasses[j]) { + floor_setup->data.t1.class_masterbook[j]=get_bits(gb, 8); + + AV_DEBUG(" masterbook: %d \n", floor_setup->data.t1.class_masterbook[j]); + } + + for(k=0;k<(1<data.t1.class_subclasses[j]);++k) { + floor_setup->data.t1.subclass_books[j][k]=(int16_t)get_bits(gb, 8)-1; + + AV_DEBUG(" book %d. : %d \n", k, floor_setup->data.t1.subclass_books[j][k]); + } + } + + floor_setup->data.t1.multiplier=get_bits(gb, 2)+1; + floor_setup->data.t1.x_list_dim=2; + + for(j=0;jdata.t1.partitions;++j) { + floor_setup->data.t1.x_list_dim+=floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]]; + } + + floor_setup->data.t1.list=av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(floor1_entry_t)); + + + rangebits=get_bits(gb, 4); + floor_setup->data.t1.list[0].x = 0; + floor_setup->data.t1.list[1].x = (1<data.t1.partitions;++j) { + for(k=0;kdata.t1.class_dimensions[floor_setup->data.t1.partition_class[j]];++k,++floor1_values) { + floor_setup->data.t1.list[floor1_values].x=get_bits(gb, rangebits); + + AV_DEBUG(" %d. floor1 Y coord. %d \n", floor1_values, floor_setup->data.t1.list[floor1_values].x); + } + } + +// Precalculate order of x coordinates - needed for decode + ff_vorbis_ready_floor1_list(floor_setup->data.t1.list, floor_setup->data.t1.x_list_dim); + } + else if(floor_setup->floor_type==0) { + uint_fast8_t max_codebook_dim=0; + + floor_setup->decode=vorbis_floor0_decode; + + floor_setup->data.t0.order=get_bits(gb, 8); + floor_setup->data.t0.rate=get_bits(gb, 16); + floor_setup->data.t0.bark_map_size=get_bits(gb, 16); + floor_setup->data.t0.amplitude_bits=get_bits(gb, 6); + /* zero would result in a div by zero later * + * 2^0 - 1 == 0 */ + if (floor_setup->data.t0.amplitude_bits == 0) { + av_log(vc->avccontext, AV_LOG_ERROR, + "Floor 0 amplitude bits is 0.\n"); + return 1; + } + floor_setup->data.t0.amplitude_offset=get_bits(gb, 8); + floor_setup->data.t0.num_books=get_bits(gb, 4)+1; + + /* allocate mem for booklist */ + floor_setup->data.t0.book_list= + av_malloc(floor_setup->data.t0.num_books); + if(!floor_setup->data.t0.book_list) { return 1; } + /* read book indexes */ + { + int idx; + uint_fast8_t book_idx; + for (idx=0;idxdata.t0.num_books;++idx) { + book_idx=get_bits(gb, 8); + floor_setup->data.t0.book_list[idx]=book_idx; + if (vc->codebooks[book_idx].dimensions > max_codebook_dim) + max_codebook_dim=vc->codebooks[book_idx].dimensions; + + if (floor_setup->data.t0.book_list[idx]>vc->codebook_count) + return 1; + } + } + + create_map( vc, i ); + + /* allocate mem for lsp coefficients */ + { + /* codebook dim is for padding if codebook dim doesn't * + * divide order+1 then we need to read more data */ + floor_setup->data.t0.lsp= + av_malloc((floor_setup->data.t0.order+1 + max_codebook_dim) + * sizeof(float)); + if(!floor_setup->data.t0.lsp) { return 1; } + } + +#ifdef V_DEBUG /* debug output parsed headers */ + AV_DEBUG("floor0 order: %u\n", floor_setup->data.t0.order); + AV_DEBUG("floor0 rate: %u\n", floor_setup->data.t0.rate); + AV_DEBUG("floor0 bark map size: %u\n", + floor_setup->data.t0.bark_map_size); + AV_DEBUG("floor0 amplitude bits: %u\n", + floor_setup->data.t0.amplitude_bits); + AV_DEBUG("floor0 amplitude offset: %u\n", + floor_setup->data.t0.amplitude_offset); + AV_DEBUG("floor0 number of books: %u\n", + floor_setup->data.t0.num_books); + AV_DEBUG("floor0 book list pointer: %p\n", + floor_setup->data.t0.book_list); + { + int idx; + for (idx=0;idxdata.t0.num_books;++idx) { + AV_DEBUG( " Book %d: %u\n", + idx+1, + floor_setup->data.t0.book_list[idx] ); + } + } +#endif + } + else { + av_log(vc->avccontext, AV_LOG_ERROR, "Invalid floor type!\n"); + return 1; + } + } + return 0; +} + +// Process residues part + +static int vorbis_parse_setup_hdr_residues(vorbis_context *vc){ + GetBitContext *gb=&vc->gb; + uint_fast8_t i, j, k; + + vc->residue_count=get_bits(gb, 6)+1; + vc->residues=av_mallocz(vc->residue_count * sizeof(vorbis_residue)); + + AV_DEBUG(" There are %d residues. \n", vc->residue_count); + + for(i=0;iresidue_count;++i) { + vorbis_residue *res_setup=&vc->residues[i]; + uint_fast8_t cascade[64]; + uint_fast8_t high_bits; + uint_fast8_t low_bits; + + res_setup->type=get_bits(gb, 16); + + AV_DEBUG(" %d. residue type %d \n", i, res_setup->type); + + res_setup->begin=get_bits(gb, 24); + res_setup->end=get_bits(gb, 24); + res_setup->partition_size=get_bits(gb, 24)+1; + res_setup->classifications=get_bits(gb, 6)+1; + res_setup->classbook=get_bits(gb, 8); + + AV_DEBUG(" begin %d end %d part.size %d classif.s %d classbook %d \n", res_setup->begin, res_setup->end, res_setup->partition_size, + res_setup->classifications, res_setup->classbook); + + for(j=0;jclassifications;++j) { + high_bits=0; + low_bits=get_bits(gb, 3); + if (get_bits1(gb)) { + high_bits=get_bits(gb, 5); + } + cascade[j]=(high_bits<<3)+low_bits; + + AV_DEBUG(" %d class casscade depth: %d \n", j, ilog(cascade[j])); + } + + res_setup->maxpass=0; + for(j=0;jclassifications;++j) { + for(k=0;k<8;++k) { + if (cascade[j]&(1<books[j][k]=get_bits(gb, 8); + + AV_DEBUG(" %d class casscade depth %d book: %d \n", j, k, res_setup->books[j][k]); + + if (k>res_setup->maxpass) { + res_setup->maxpass=k; + } + } else { + res_setup->books[j][k]=-1; + } + } + } + } + return 0; +} + +// Process mappings part + +static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc) { + GetBitContext *gb=&vc->gb; + uint_fast8_t i, j; + + vc->mapping_count=get_bits(gb, 6)+1; + vc->mappings=av_mallocz(vc->mapping_count * sizeof(vorbis_mapping)); + + AV_DEBUG(" There are %d mappings. \n", vc->mapping_count); + + for(i=0;imapping_count;++i) { + vorbis_mapping *mapping_setup=&vc->mappings[i]; + + if (get_bits(gb, 16)) { + av_log(vc->avccontext, AV_LOG_ERROR, "Other mappings than type 0 are not compliant with the Vorbis I specification. \n"); + return 1; + } + if (get_bits1(gb)) { + mapping_setup->submaps=get_bits(gb, 4)+1; + } else { + mapping_setup->submaps=1; + } + + if (get_bits1(gb)) { + mapping_setup->coupling_steps=get_bits(gb, 8)+1; + mapping_setup->magnitude=av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t)); + mapping_setup->angle =av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t)); + for(j=0;jcoupling_steps;++j) { + mapping_setup->magnitude[j]=get_bits(gb, ilog(vc->audio_channels-1)); + mapping_setup->angle[j]=get_bits(gb, ilog(vc->audio_channels-1)); + // FIXME: sanity checks + } + } else { + mapping_setup->coupling_steps=0; + } + + AV_DEBUG(" %d mapping coupling steps: %d \n", i, mapping_setup->coupling_steps); + + if(get_bits(gb, 2)) { + av_log(vc->avccontext, AV_LOG_ERROR, "%d. mapping setup data invalid. \n", i); + return 1; // following spec. + } + + if (mapping_setup->submaps>1) { + mapping_setup->mux=av_mallocz(vc->audio_channels * sizeof(uint_fast8_t)); + for(j=0;jaudio_channels;++j) { + mapping_setup->mux[j]=get_bits(gb, 4); + } + } + + for(j=0;jsubmaps;++j) { + skip_bits(gb, 8); // FIXME check? + mapping_setup->submap_floor[j]=get_bits(gb, 8); + mapping_setup->submap_residue[j]=get_bits(gb, 8); + + AV_DEBUG(" %d mapping %d submap : floor %d, residue %d \n", i, j, mapping_setup->submap_floor[j], mapping_setup->submap_residue[j]); + } + } + return 0; +} + +// Process modes part + +static void create_map( vorbis_context * vc, uint_fast8_t floor_number ) +{ + vorbis_floor * floors=vc->floors; + vorbis_floor0 * vf; + int idx; + int_fast8_t blockflag; + int_fast32_t * map; + int_fast32_t n; //TODO: could theoretically be smaller? + + for (blockflag=0;blockflag<2;++blockflag) + { + n=vc->blocksize[blockflag]/2; + floors[floor_number].data.t0.map[blockflag]= + av_malloc((n+1) * sizeof(int_fast32_t)); // n+sentinel + + map=floors[floor_number].data.t0.map[blockflag]; + vf=&floors[floor_number].data.t0; + + for (idx=0; idxrate*idx)/(2.0f*n)) * + ((vf->bark_map_size)/ + BARK(vf->rate/2.0f )) ); + if (vf->bark_map_size-1 < map[idx]) { + map[idx]=vf->bark_map_size-1; + } + } + map[n]=-1; + vf->map_size[blockflag]=n; + } + +# ifdef V_DEBUG + for(idx=0;idx<=n;++idx) { + AV_DEBUG("floor0 map: map at pos %d is %d\n", + idx, map[idx]); + } +# endif +} + +static int vorbis_parse_setup_hdr_modes(vorbis_context *vc) { + GetBitContext *gb=&vc->gb; + uint_fast8_t i; + + vc->mode_count=get_bits(gb, 6)+1; + vc->modes=av_mallocz(vc->mode_count * sizeof(vorbis_mode)); + + AV_DEBUG(" There are %d modes.\n", vc->mode_count); + + for(i=0;imode_count;++i) { + vorbis_mode *mode_setup=&vc->modes[i]; + + mode_setup->blockflag=get_bits1(gb); + mode_setup->windowtype=get_bits(gb, 16); //FIXME check + mode_setup->transformtype=get_bits(gb, 16); //FIXME check + mode_setup->mapping=get_bits(gb, 8); //FIXME check + + AV_DEBUG(" %d mode: blockflag %d, windowtype %d, transformtype %d, mapping %d \n", i, mode_setup->blockflag, mode_setup->windowtype, mode_setup->transformtype, mode_setup->mapping); + } + return 0; +} + +// Process the whole setup header using the functions above + +static int vorbis_parse_setup_hdr(vorbis_context *vc) { + GetBitContext *gb=&vc->gb; + + if ((get_bits(gb, 8)!='v') || (get_bits(gb, 8)!='o') || + (get_bits(gb, 8)!='r') || (get_bits(gb, 8)!='b') || + (get_bits(gb, 8)!='i') || (get_bits(gb, 8)!='s')) { + av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (no vorbis signature). \n"); + return 1; + } + + if (vorbis_parse_setup_hdr_codebooks(vc)) { + av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (codebooks). \n"); + return 2; + } + if (vorbis_parse_setup_hdr_tdtransforms(vc)) { + av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (time domain transforms). \n"); + return 3; + } + if (vorbis_parse_setup_hdr_floors(vc)) { + av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (floors). \n"); + return 4; + } + if (vorbis_parse_setup_hdr_residues(vc)) { + av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (residues). \n"); + return 5; + } + if (vorbis_parse_setup_hdr_mappings(vc)) { + av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (mappings). \n"); + return 6; + } + if (vorbis_parse_setup_hdr_modes(vc)) { + av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (modes). \n"); + return 7; + } + if (!get_bits1(gb)) { + av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (framing flag). \n"); + return 8; // framing flag bit unset error + } + + return 0; +} + +// Process the identification header + +static int vorbis_parse_id_hdr(vorbis_context *vc){ + GetBitContext *gb=&vc->gb; + uint_fast8_t bl0, bl1; + + if ((get_bits(gb, 8)!='v') || (get_bits(gb, 8)!='o') || + (get_bits(gb, 8)!='r') || (get_bits(gb, 8)!='b') || + (get_bits(gb, 8)!='i') || (get_bits(gb, 8)!='s')) { + av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (no vorbis signature). \n"); + return 1; + } + + vc->version=get_bits_long(gb, 32); //FIXME check 0 + vc->audio_channels=get_bits(gb, 8); //FIXME check >0 + vc->audio_samplerate=get_bits_long(gb, 32); //FIXME check >0 + vc->bitrate_maximum=get_bits_long(gb, 32); + vc->bitrate_nominal=get_bits_long(gb, 32); + vc->bitrate_minimum=get_bits_long(gb, 32); + bl0=get_bits(gb, 4); + bl1=get_bits(gb, 4); + vc->blocksize[0]=(1<blocksize[1]=(1<13 || bl0<6 || bl1>13 || bl1<6 || bl1avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (illegal blocksize). \n"); + return 3; + } + // output format int16 + if (vc->blocksize[1]/2 * vc->audio_channels * 2 > + AVCODEC_MAX_AUDIO_FRAME_SIZE) { + av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis channel count makes " + "output packets too large.\n"); + return 4; + } + vc->win[0]=ff_vorbis_vwin[bl0-6]; + vc->win[1]=ff_vorbis_vwin[bl1-6]; + + if(vc->exp_bias){ + int i, j; + for(j=0; j<2; j++){ + float *win = av_malloc(vc->blocksize[j]/2 * sizeof(float)); + for(i=0; iblocksize[j]/2; i++) + win[i] = vc->win[j][i] * (1<<15); + vc->win[j] = win; + } + } + + if ((get_bits1(gb)) == 0) { + av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (framing flag not set). \n"); + return 2; + } + + vc->channel_residues= av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float)); + vc->channel_floors = av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float)); + vc->saved = av_mallocz((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float)); + vc->ret = av_malloc((vc->blocksize[1]/2)*vc->audio_channels * sizeof(float)); + vc->buf = av_malloc( vc->blocksize[1] * sizeof(float)); + vc->buf_tmp = av_malloc( vc->blocksize[1] * sizeof(float)); + vc->saved_start=0; + + ff_mdct_init(&vc->mdct[0], bl0, 1); + ff_mdct_init(&vc->mdct[1], bl1, 1); + + AV_DEBUG(" vorbis version %d \n audio_channels %d \n audio_samplerate %d \n bitrate_max %d \n bitrate_nom %d \n bitrate_min %d \n blk_0 %d blk_1 %d \n ", + vc->version, vc->audio_channels, vc->audio_samplerate, vc->bitrate_maximum, vc->bitrate_nominal, vc->bitrate_minimum, vc->blocksize[0], vc->blocksize[1]); + +/* + BLK=vc->blocksize[0]; + for(i=0;iwin[0][i]=sin(0.5*3.14159265358*(sin(((float)i+0.5)/(float)BLK*3.14159265358))*(sin(((float)i+0.5)/(float)BLK*3.14159265358))); + } +*/ + + return 0; +} + +// Process the extradata using the functions above (identification header, setup header) + +static int vorbis_decode_init(AVCodecContext *avccontext) { + vorbis_context *vc = avccontext->priv_data ; + uint8_t *headers = avccontext->extradata; + int headers_len=avccontext->extradata_size; + uint8_t *header_start[3]; + int header_len[3]; + GetBitContext *gb = &(vc->gb); + int hdr_type; + + vc->avccontext = avccontext; + dsputil_init(&vc->dsp, avccontext); + + if(vc->dsp.float_to_int16 == ff_float_to_int16_c) { + vc->add_bias = 385; + vc->exp_bias = 0; + } else { + vc->add_bias = 0; + vc->exp_bias = 15<<23; + } + + if (!headers_len) { + av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n"); + return -1; + } + + if (ff_split_xiph_headers(headers, headers_len, 30, header_start, header_len) < 0) { + av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n"); + return -1; + } + + init_get_bits(gb, header_start[0], header_len[0]*8); + hdr_type=get_bits(gb, 8); + if (hdr_type!=1) { + av_log(avccontext, AV_LOG_ERROR, "First header is not the id header.\n"); + return -1; + } + if (vorbis_parse_id_hdr(vc)) { + av_log(avccontext, AV_LOG_ERROR, "Id header corrupt.\n"); + vorbis_free(vc); + return -1; + } + + init_get_bits(gb, header_start[2], header_len[2]*8); + hdr_type=get_bits(gb, 8); + if (hdr_type!=5) { + av_log(avccontext, AV_LOG_ERROR, "Third header is not the setup header.\n"); + return -1; + } + if (vorbis_parse_setup_hdr(vc)) { + av_log(avccontext, AV_LOG_ERROR, "Setup header corrupt.\n"); + vorbis_free(vc); + return -1; + } + + avccontext->channels = vc->audio_channels; + avccontext->sample_rate = vc->audio_samplerate; + + return 0 ; +} + +// Decode audiopackets ------------------------------------------------- + +// Read and decode floor + +static uint_fast8_t vorbis_floor0_decode(vorbis_context *vc, + vorbis_floor_data *vfu, float *vec) { + vorbis_floor0 * vf=&vfu->t0; + float * lsp=vf->lsp; + uint_fast32_t amplitude; + uint_fast32_t book_idx; + uint_fast8_t blockflag=vc->modes[vc->mode_number].blockflag; + + amplitude=get_bits(&vc->gb, vf->amplitude_bits); + if (amplitude>0) { + float last = 0; + uint_fast16_t lsp_len = 0; + uint_fast16_t idx; + vorbis_codebook codebook; + + book_idx=get_bits(&vc->gb, ilog(vf->num_books)); + if ( book_idx >= vf->num_books ) { + av_log( vc->avccontext, AV_LOG_ERROR, + "floor0 dec: booknumber too high!\n" ); + book_idx= 0; + //FIXME: look above + } + AV_DEBUG( "floor0 dec: booknumber: %u\n", book_idx ); + codebook=vc->codebooks[vf->book_list[book_idx]]; + + while (lsp_lenorder) { + int vec_off; + + AV_DEBUG( "floor0 dec: book dimension: %d\n", codebook.dimensions ); + AV_DEBUG( "floor0 dec: maximum depth: %d\n", codebook.maxdepth ); + /* read temp vector */ + vec_off=get_vlc2(&vc->gb, + codebook.vlc.table, + codebook.nb_bits, + codebook.maxdepth ) * + codebook.dimensions; + AV_DEBUG( "floor0 dec: vector offset: %d\n", vec_off ); + /* copy each vector component and add last to it */ + for (idx=0; idxorder; + float wstep=M_PI/vf->bark_map_size; + + for(i=0;imap_size, order, wstep); + + i=0; + while(imap_size[blockflag]) { + int j, iter_cond=vf->map[blockflag][i]; + float p=0.5f; + float q=0.5f; + float two_cos_w=2.0f*cos(wstep*iter_cond); // needed all times + + /* similar part for the q and p products */ + for(j=0;jamplitude_offset)/ + (((1<amplitude_bits)-1) * sqrt(p+q)) ) + - vf->amplitude_offset ) * .11512925f + ); + } + + /* fill vector */ + do { vec[i]=q; ++i; }while(vf->map[blockflag][i]==iter_cond); + } + } + } + else { + /* this channel is unused */ + return 1; + } + + AV_DEBUG(" Floor0 decoded\n"); + + return 0; +} + +static uint_fast8_t vorbis_floor1_decode(vorbis_context *vc, vorbis_floor_data *vfu, float *vec) { + vorbis_floor1 * vf=&vfu->t1; + GetBitContext *gb=&vc->gb; + uint_fast16_t range_v[4]={ 256, 128, 86, 64 }; + uint_fast16_t range=range_v[vf->multiplier-1]; + uint_fast16_t floor1_Y[vf->x_list_dim]; + uint_fast16_t floor1_Y_final[vf->x_list_dim]; + int floor1_flag[vf->x_list_dim]; + uint_fast8_t class_; + uint_fast8_t cdim; + uint_fast8_t cbits; + uint_fast8_t csub; + uint_fast8_t cval; + int_fast16_t book; + uint_fast16_t offset; + uint_fast16_t i,j; + /*u*/int_fast16_t adx, ady, off, predicted; // WTF ? dy/adx= (unsigned)dy/adx ? + int_fast16_t dy, err; + + + if (!get_bits1(gb)) return 1; // silence + +// Read values (or differences) for the floor's points + + floor1_Y[0]=get_bits(gb, ilog(range-1)); + floor1_Y[1]=get_bits(gb, ilog(range-1)); + + AV_DEBUG("floor 0 Y %d floor 1 Y %d \n", floor1_Y[0], floor1_Y[1]); + + offset=2; + for(i=0;ipartitions;++i) { + class_=vf->partition_class[i]; + cdim=vf->class_dimensions[class_]; + cbits=vf->class_subclasses[class_]; + csub=(1<codebooks[vf->class_masterbook[class_]].vlc.table, + vc->codebooks[vf->class_masterbook[class_]].nb_bits, 3); + } + + for(j=0;jsubclass_books[class_][cval & csub]; + + AV_DEBUG("book %d Cbits %d cval %d bits:%d \n", book, cbits, cval, get_bits_count(gb)); + + cval=cval>>cbits; + if (book>-1) { + floor1_Y[offset+j]=get_vlc2(gb, vc->codebooks[book].vlc.table, + vc->codebooks[book].nb_bits, 3); + } else { + floor1_Y[offset+j]=0; + } + + AV_DEBUG(" floor(%d) = %d \n", vf->list[offset+j].x, floor1_Y[offset+j]); + } + offset+=cdim; + } + +// Amplitude calculation from the differences + + floor1_flag[0]=1; + floor1_flag[1]=1; + floor1_Y_final[0]=floor1_Y[0]; + floor1_Y_final[1]=floor1_Y[1]; + + for(i=2;ix_list_dim;++i) { + uint_fast16_t val, highroom, lowroom, room; + uint_fast16_t high_neigh_offs; + uint_fast16_t low_neigh_offs; + + low_neigh_offs=vf->list[i].low; + high_neigh_offs=vf->list[i].high; + dy=floor1_Y_final[high_neigh_offs]-floor1_Y_final[low_neigh_offs]; // render_point begin + adx=vf->list[high_neigh_offs].x-vf->list[low_neigh_offs].x; + ady= FFABS(dy); + err=ady*(vf->list[i].x-vf->list[low_neigh_offs].x); + off=(int16_t)err/(int16_t)adx; + if (dy<0) { + predicted=floor1_Y_final[low_neigh_offs]-off; + } else { + predicted=floor1_Y_final[low_neigh_offs]+off; + } // render_point end + + val=floor1_Y[i]; + highroom=range-predicted; + lowroom=predicted; + if (highroom < lowroom) { + room=highroom*2; + } else { + room=lowroom*2; // SPEC mispelling + } + if (val) { + floor1_flag[low_neigh_offs]=1; + floor1_flag[high_neigh_offs]=1; + floor1_flag[i]=1; + if (val>=room) { + if (highroom > lowroom) { + floor1_Y_final[i]=val-lowroom+predicted; + } else { + floor1_Y_final[i]=predicted-val+highroom-1; + } + } else { + if (val & 1) { + floor1_Y_final[i]=predicted-(val+1)/2; + } else { + floor1_Y_final[i]=predicted+val/2; + } + } + } else { + floor1_flag[i]=0; + floor1_Y_final[i]=predicted; + } + + AV_DEBUG(" Decoded floor(%d) = %d / val %d \n", vf->list[i].x, floor1_Y_final[i], val); + } + +// Curve synth - connect the calculated dots and convert from dB scale FIXME optimize ? + + ff_vorbis_floor1_render_list(vf->list, vf->x_list_dim, floor1_Y_final, floor1_flag, vf->multiplier, vec, vf->list[1].x); + + AV_DEBUG(" Floor decoded\n"); + + return 0; +} + +// Read and decode residue + +static int vorbis_residue_decode(vorbis_context *vc, vorbis_residue *vr, uint_fast8_t ch, uint_fast8_t *do_not_decode, float *vec, uint_fast16_t vlen) { + GetBitContext *gb=&vc->gb; + uint_fast8_t c_p_c=vc->codebooks[vr->classbook].dimensions; + uint_fast16_t n_to_read=vr->end-vr->begin; + uint_fast16_t ptns_to_read=n_to_read/vr->partition_size; + uint_fast8_t classifs[ptns_to_read*vc->audio_channels]; + uint_fast8_t pass; + uint_fast8_t ch_used; + uint_fast8_t i,j,l; + uint_fast16_t k; + + if (vr->type==2) { + for(j=1;jmaxpass;++pass) { // FIXME OPTIMIZE? + uint_fast16_t voffset; + uint_fast16_t partition_count; + uint_fast16_t j_times_ptns_to_read; + + voffset=vr->begin; + for(partition_count=0;partition_countclassifications]; + for(j_times_ptns_to_read=0, j=0;jcodebooks[vr->classbook].vlc.table, + vc->codebooks[vr->classbook].nb_bits, 3); + + AV_DEBUG("Classword: %d \n", temp); + + assert(vr->classifications > 1 && temp<=65536); //needed for inverse[] + for(i=0;i>32; + if (partition_count+c_p_c-1-i < ptns_to_read) { + classifs[j_times_ptns_to_read+partition_count+c_p_c-1-i]=temp-temp2*vr->classifications; + } + temp=temp2; + } + } + j_times_ptns_to_read+=ptns_to_read; + } + } + for(i=0;(ibooks[vqclass][pass]; + + if (vqbook>=0 && vc->codebooks[vqbook].codevectors) { + uint_fast16_t coffs; + unsigned dim= vc->codebooks[vqbook].dimensions; // not uint_fast8_t: 64bit is slower here on amd64 + uint_fast16_t step= dim==1 ? vr->partition_size + : FASTDIV(vr->partition_size, dim); + vorbis_codebook codebook= vc->codebooks[vqbook]; + + if (vr->type==0) { + + voffs=voffset+j*vlen; + for(k=0;ktype==1) { + voffs=voffset+j*vlen; + for(k=0;ktype==2 && ch==2 && (voffset&1)==0 && (dim&1)==0) { // most frequent case optimized + voffs=voffset>>1; + + if(dim==2) { + for(k=0;ktype==2) { + voffs=voffset; + + for(k=0;kavccontext, AV_LOG_ERROR, " Invalid residue type while residue decode?! \n"); + return 1; + } + } + } + j_times_ptns_to_read+=ptns_to_read; + } + ++partition_count; + voffset+=vr->partition_size; + } + } + } + return 0; +} + +void vorbis_inverse_coupling(float *mag, float *ang, int blocksize) +{ + int i; + for(i=0; i0.0) { + if (ang[i]>0.0) { + ang[i]=mag[i]-ang[i]; + } else { + float temp=ang[i]; + ang[i]=mag[i]; + mag[i]+=temp; + } + } else { + if (ang[i]>0.0) { + ang[i]+=mag[i]; + } else { + float temp=ang[i]; + ang[i]=mag[i]; + mag[i]-=temp; + } + } + } +} + +// Decode the audio packet using the functions above + +static int vorbis_parse_audio_packet(vorbis_context *vc) { + GetBitContext *gb=&vc->gb; + + uint_fast8_t previous_window=0,next_window=0; + uint_fast8_t mode_number; + uint_fast16_t blocksize; + int_fast32_t i,j; + uint_fast8_t no_residue[vc->audio_channels]; + uint_fast8_t do_not_decode[vc->audio_channels]; + vorbis_mapping *mapping; + float *ch_res_ptr=vc->channel_residues; + float *ch_floor_ptr=vc->channel_floors; + uint_fast8_t res_chan[vc->audio_channels]; + uint_fast8_t res_num=0; + int_fast16_t retlen=0; + uint_fast16_t saved_start=0; + float fadd_bias = vc->add_bias; + + if (get_bits1(gb)) { + av_log(vc->avccontext, AV_LOG_ERROR, "Not a Vorbis I audio packet.\n"); + return -1; // packet type not audio + } + + if (vc->mode_count==1) { + mode_number=0; + } else { + mode_number=get_bits(gb, ilog(vc->mode_count-1)); + } + vc->mode_number=mode_number; + mapping=&vc->mappings[vc->modes[mode_number].mapping]; + + AV_DEBUG(" Mode number: %d , mapping: %d , blocktype %d \n", mode_number, vc->modes[mode_number].mapping, vc->modes[mode_number].blockflag); + + if (vc->modes[mode_number].blockflag) { + previous_window=get_bits1(gb); + next_window=get_bits1(gb); + } + + blocksize=vc->blocksize[vc->modes[mode_number].blockflag]; + memset(ch_res_ptr, 0, sizeof(float)*vc->audio_channels*blocksize/2); //FIXME can this be removed ? + memset(ch_floor_ptr, 0, sizeof(float)*vc->audio_channels*blocksize/2); //FIXME can this be removed ? + +// Decode floor + + for(i=0;iaudio_channels;++i) { + vorbis_floor *floor; + if (mapping->submaps>1) { + floor=&vc->floors[mapping->submap_floor[mapping->mux[i]]]; + } else { + floor=&vc->floors[mapping->submap_floor[0]]; + } + + no_residue[i]=floor->decode(vc, &floor->data, ch_floor_ptr); + ch_floor_ptr+=blocksize/2; + } + +// Nonzero vector propagate + + for(i=mapping->coupling_steps-1;i>=0;--i) { + if (!(no_residue[mapping->magnitude[i]] & no_residue[mapping->angle[i]])) { + no_residue[mapping->magnitude[i]]=0; + no_residue[mapping->angle[i]]=0; + } + } + +// Decode residue + + for(i=0;isubmaps;++i) { + vorbis_residue *residue; + uint_fast8_t ch=0; + + for(j=0;jaudio_channels;++j) { + if ((mapping->submaps==1) || (i=mapping->mux[j])) { + res_chan[j]=res_num; + if (no_residue[j]) { + do_not_decode[ch]=1; + } else { + do_not_decode[ch]=0; + } + ++ch; + ++res_num; + } + } + residue=&vc->residues[mapping->submap_residue[i]]; + vorbis_residue_decode(vc, residue, ch, do_not_decode, ch_res_ptr, blocksize/2); + + ch_res_ptr+=ch*blocksize/2; + } + +// Inverse coupling + + for(i=mapping->coupling_steps-1;i>=0;--i) { //warning: i has to be signed + float *mag, *ang; + + mag=vc->channel_residues+res_chan[mapping->magnitude[i]]*blocksize/2; + ang=vc->channel_residues+res_chan[mapping->angle[i]]*blocksize/2; + vc->dsp.vorbis_inverse_coupling(mag, ang, blocksize/2); + } + +// Dotproduct + + for(j=0, ch_floor_ptr=vc->channel_floors;jaudio_channels;++j,ch_floor_ptr+=blocksize/2) { + ch_res_ptr=vc->channel_residues+res_chan[j]*blocksize/2; + vc->dsp.vector_fmul(ch_floor_ptr, ch_res_ptr, blocksize/2); + } + +// MDCT, overlap/add, save data for next overlapping FPMATH + + for(j=0;jaudio_channels;++j) { + uint_fast8_t step=vc->audio_channels; + uint_fast16_t k; + float *saved=vc->saved+j*vc->blocksize[1]/2; + float *ret=vc->ret; + const float *lwin=vc->win[1]; + const float *swin=vc->win[0]; + float *buf=vc->buf; + float *buf_tmp=vc->buf_tmp; + + ch_floor_ptr=vc->channel_floors+j*blocksize/2; + + saved_start=vc->saved_start; + + vc->mdct[0].fft.imdct_calc(&vc->mdct[vc->modes[mode_number].blockflag], buf, ch_floor_ptr, buf_tmp); + + //FIXME process channels together, to allow faster simd vector_fmul_add_add? + if (vc->modes[mode_number].blockflag) { + // -- overlap/add + if (previous_window) { + vc->dsp.vector_fmul_add_add(ret+j, buf, lwin, saved, vc->add_bias, vc->blocksize[1]/2, step); + retlen=vc->blocksize[1]/2; + } else { + int len = (vc->blocksize[1]-vc->blocksize[0])/4; + buf += len; + vc->dsp.vector_fmul_add_add(ret+j, buf, swin, saved, vc->add_bias, vc->blocksize[0]/2, step); + k = vc->blocksize[0]/2*step + j; + buf += vc->blocksize[0]/2; + if(vc->exp_bias){ + for(i=0; iexp_bias; // ret[k]=buf[i]*(1<buf; + retlen=vc->blocksize[0]/2+len; + } + // -- save + if (next_window) { + buf += vc->blocksize[1]/2; + vc->dsp.vector_fmul_reverse(saved, buf, lwin, vc->blocksize[1]/2); + saved_start=0; + } else { + saved_start=(vc->blocksize[1]-vc->blocksize[0])/4; + buf += vc->blocksize[1]/2; + for(i=0; iexp_bias; + vc->dsp.vector_fmul_reverse(saved+saved_start, buf+saved_start, swin, vc->blocksize[0]/2); + } + } else { + // --overlap/add + if(vc->add_bias) { + for(k=j, i=0;idsp.vector_fmul_add_add(ret+k, buf, swin, saved+saved_start, vc->add_bias, vc->blocksize[0]/2, step); + retlen=saved_start+vc->blocksize[0]/2; + // -- save + buf += vc->blocksize[0]/2; + vc->dsp.vector_fmul_reverse(saved, buf, swin, vc->blocksize[0]/2); + saved_start=0; + } + } + vc->saved_start=saved_start; + + return retlen*vc->audio_channels; +} + +// Return the decoded audio packet through the standard api + +static int vorbis_decode_frame(AVCodecContext *avccontext, + void *data, int *data_size, + const uint8_t *buf, int buf_size) +{ + vorbis_context *vc = avccontext->priv_data ; + GetBitContext *gb = &(vc->gb); + + int_fast16_t len; + + if(!buf_size){ + return 0; + } + + AV_DEBUG("packet length %d \n", buf_size); + + init_get_bits(gb, buf, buf_size*8); + + len=vorbis_parse_audio_packet(vc); + + if (len<=0) { + *data_size=0; + return buf_size; + } + + if (!vc->first_frame) { + vc->first_frame=1; + *data_size=0; + return buf_size ; + } + + AV_DEBUG("parsed %d bytes %d bits, returned %d samples (*ch*bits) \n", get_bits_count(gb)/8, get_bits_count(gb)%8, len); + + vc->dsp.float_to_int16(data, vc->ret, len); + *data_size=len*2; + + return buf_size ; +} + +// Close decoder + +static int vorbis_decode_close(AVCodecContext *avccontext) { + vorbis_context *vc = avccontext->priv_data; + + vorbis_free(vc); + + return 0 ; +} + +AVCodec vorbis_decoder = { + "vorbis", + CODEC_TYPE_AUDIO, + CODEC_ID_VORBIS, + sizeof(vorbis_context), + vorbis_decode_init, + NULL, + vorbis_decode_close, + vorbis_decode_frame, +}; + diff --git a/contrib/ffmpeg/libavcodec/vorbis_enc.c b/contrib/ffmpeg/libavcodec/vorbis_enc.c index 3789ef7a2..391202211 100644 --- a/contrib/ffmpeg/libavcodec/vorbis_enc.c +++ b/contrib/ffmpeg/libavcodec/vorbis_enc.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** @@ -756,7 +756,7 @@ static void floor_encode(venc_context_t * venc, floor_t * fc, PutBitContext * pb int maxval = 1; if (c->books[l] != -1) maxval = venc->codebooks[c->books[l]].nentries; - // coded could be -1, but this still works, cause thats 0 + // coded could be -1, but this still works, cause that is 0 if (coded[counter + k] < maxval) break; } assert(l != csub); diff --git a/contrib/ffmpeg/libavcodec/vorbis_enc_data.h b/contrib/ffmpeg/libavcodec/vorbis_enc_data.h index e56dc5df5..1b4be9aaa 100644 --- a/contrib/ffmpeg/libavcodec/vorbis_enc_data.h +++ b/contrib/ffmpeg/libavcodec/vorbis_enc_data.h @@ -15,9 +15,14 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef FFMPEG_VORBIS_ENC_DATA_H +#define FFMPEG_VORBIS_ENC_DATA_H + +#include + static const uint8_t codebook0[] = { 2, 10, 8, 14, 7, 12, 11, 14, 1, 5, 3, 7, 4, 9, 7, 13, @@ -496,3 +501,5 @@ static const struct { { 4, 2, 2, (const int[]){ -1, 9, 10, 11 } }, { 3, 2, 3, (const int[]){ -1, 12, 13, 14 } }, }; + +#endif /* FFMPEG_VORBIS_ENC_DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/vp3.c b/contrib/ffmpeg/libavcodec/vp3.c index bf17c2da7..eade1eb3c 100644 --- a/contrib/ffmpeg/libavcodec/vp3.c +++ b/contrib/ffmpeg/libavcodec/vp3.c @@ -16,7 +16,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -35,7 +34,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include "dsputil.h" #include "mpegvideo.h" @@ -275,7 +273,7 @@ typedef struct Vp3DecodeContext { * which of the fragments are coded */ int *coded_fragment_list; int coded_fragment_list_index; - int pixel_addresses_inited; + int pixel_addresses_initialized; VLC dc_vlc[16]; VLC ac_vlc_1[16]; @@ -331,8 +329,6 @@ typedef struct Vp3DecodeContext { int bounding_values_array[256]; } Vp3DecodeContext; -static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb); - /************************************************************************ * VP3 specific functions ************************************************************************/ @@ -477,7 +473,7 @@ static int init_block_mapping(Vp3DecodeContext *s) current_width = -1; current_height = 0; superblock_row_inc = s->macroblock_width - - (s->y_superblock_width * 2 - s->macroblock_width);; + (s->y_superblock_width * 2 - s->macroblock_width); hilbert = hilbert_walk_mb; mapping_index = 0; current_macroblock = -1; @@ -690,7 +686,7 @@ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb) } else { /* unpack the list of partially-coded superblocks */ - bit = get_bits(gb, 1); + bit = get_bits1(gb); /* toggle the bit because as soon as the first run length is * fetched the bit will be toggled again */ bit ^= 1; @@ -726,7 +722,7 @@ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb) current_superblock = 0; current_run = 0; - bit = get_bits(gb, 1); + bit = get_bits1(gb); /* toggle the bit because as soon as the first run length is * fetched the bit will be toggled again */ bit ^= 1; @@ -757,7 +753,7 @@ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb) if (decode_partial_blocks) { current_run = 0; - bit = get_bits(gb, 1); + bit = get_bits1(gb); /* toggle the bit because as soon as the first run length is * fetched the bit will be toggled again */ bit ^= 1; @@ -983,7 +979,7 @@ static int unpack_vectors(Vp3DecodeContext *s, GetBitContext *gb) memset(motion_y, 0, 6 * sizeof(int)); /* coding mode 0 is the VLC scheme; 1 is the fixed code scheme */ - coding_mode = get_bits(gb, 1); + coding_mode = get_bits1(gb); debug_vectors(" using %s scheme for unpacking motion vectors\n", (coding_mode == 0) ? "VLC" : "fixed-length"); @@ -1955,7 +1951,6 @@ static int vp3_decode_init(AVCodecContext *avctx) s->width = (avctx->width + 15) & 0xFFFFFFF0; s->height = (avctx->height + 15) & 0xFFFFFFF0; avctx->pix_fmt = PIX_FMT_YUV420P; - avctx->has_b_frames = 0; if(avctx->idct_algo==FF_IDCT_AUTO) avctx->idct_algo=FF_IDCT_VP3; dsputil_init(&s->dsp, avctx); @@ -2014,7 +2009,7 @@ static int vp3_decode_init(AVCodecContext *avctx) s->all_fragments = av_malloc(s->fragment_count * sizeof(Vp3Fragment)); s->coeffs = av_malloc(s->fragment_count * sizeof(Coeff) * 65); s->coded_fragment_list = av_malloc(s->fragment_count * sizeof(int)); - s->pixel_addresses_inited = 0; + s->pixel_addresses_initialized = 0; if (!s->theora_tables) { @@ -2131,7 +2126,7 @@ static int vp3_decode_init(AVCodecContext *avctx) */ static int vp3_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { Vp3DecodeContext *s = avctx->priv_data; GetBitContext gb; @@ -2142,28 +2137,8 @@ static int vp3_decode_frame(AVCodecContext *avctx, if (s->theora && get_bits1(&gb)) { -#if 1 av_log(avctx, AV_LOG_ERROR, "Header packet passed to frame decoder, skipping\n"); return -1; -#else - int ptype = get_bits(&gb, 7); - - skip_bits(&gb, 6*8); /* "theora" */ - - switch(ptype) - { - case 1: - theora_decode_comments(avctx, &gb); - break; - case 2: - theora_decode_tables(avctx, &gb); - init_dequantizer(s); - break; - default: - av_log(avctx, AV_LOG_ERROR, "Unknown Theora config packet: %d\n", ptype); - } - return buf_size; -#endif } s->keyframe = !get_bits1(&gb); @@ -2228,18 +2203,18 @@ static int vp3_decode_frame(AVCodecContext *avctx, s->current_frame= s->golden_frame; /* time to figure out pixel addresses? */ - if (!s->pixel_addresses_inited) + if (!s->pixel_addresses_initialized) { if (!s->flipped_image) vp3_calculate_pixel_addresses(s); else theora_calculate_pixel_addresses(s); - s->pixel_addresses_inited = 1; + s->pixel_addresses_initialized = 1; } } else { /* allocate a new current frame */ s->current_frame.reference = 3; - if (!s->pixel_addresses_inited) { + if (!s->pixel_addresses_initialized) { av_log(s->avctx, AV_LOG_ERROR, "vp3: first frame not a keyframe\n"); return -1; } @@ -2338,7 +2313,9 @@ if (!s->keyframe) { static int vp3_decode_end(AVCodecContext *avctx) { Vp3DecodeContext *s = avctx->priv_data; + int i; + av_free(s->superblock_coding); av_free(s->all_fragments); av_free(s->coeffs); av_free(s->coded_fragment_list); @@ -2347,6 +2324,19 @@ static int vp3_decode_end(AVCodecContext *avctx) av_free(s->macroblock_fragments); av_free(s->macroblock_coding); + for (i = 0; i < 16; i++) { + free_vlc(&s->dc_vlc[i]); + free_vlc(&s->ac_vlc_1[i]); + free_vlc(&s->ac_vlc_2[i]); + free_vlc(&s->ac_vlc_3[i]); + free_vlc(&s->ac_vlc_4[i]); + } + + free_vlc(&s->superblock_run_length_vlc); + free_vlc(&s->fragment_run_length_vlc); + free_vlc(&s->mode_code_vlc); + free_vlc(&s->motion_vector_vlc); + /* release all frames */ if (s->golden_frame.data[0] && s->golden_frame.data[0] != s->last_frame.data[0]) avctx->release_buffer(avctx, &s->golden_frame); @@ -2362,7 +2352,7 @@ static int read_huffman_tree(AVCodecContext *avctx, GetBitContext *gb) { Vp3DecodeContext *s = avctx->priv_data; - if (get_bits(gb, 1)) { + if (get_bits1(gb)) { int token; if (s->entries >= 32) { /* overflow */ av_log(avctx, AV_LOG_ERROR, "huffman tree overflow\n"); @@ -2390,12 +2380,14 @@ static int read_huffman_tree(AVCodecContext *avctx, GetBitContext *gb) return 0; } +#ifdef CONFIG_THEORA_DECODER static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb) { Vp3DecodeContext *s = avctx->priv_data; + int visible_width, visible_height; s->theora = get_bits_long(gb, 24); - av_log(avctx, AV_LOG_INFO, "Theora bitstream version %X\n", s->theora); + av_log(avctx, AV_LOG_DEBUG, "Theora bitstream version %X\n", s->theora); /* 3.2.0 aka alpha3 has the same frame orientation as original vp3 */ /* but previous versions have the image flipped relative to vp3 */ @@ -2421,20 +2413,15 @@ static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb) skip_bits(gb, 32); /* total number of blocks in a frame */ skip_bits(gb, 4); /* total number of blocks in a frame */ skip_bits(gb, 32); /* total number of macroblocks in a frame */ - - skip_bits(gb, 24); /* frame width */ - skip_bits(gb, 24); /* frame height */ - } - else - { - skip_bits(gb, 24); /* frame width */ - skip_bits(gb, 24); /* frame height */ } - if (s->theora >= 0x030200) { - skip_bits(gb, 8); /* offset x */ - skip_bits(gb, 8); /* offset y */ - } + visible_width = get_bits_long(gb, 24); + visible_height = get_bits_long(gb, 24); + + if (s->theora >= 0x030200) { + skip_bits(gb, 8); /* offset x */ + skip_bits(gb, 8); /* offset y */ + } skip_bits(gb, 32); /* fps numerator */ skip_bits(gb, 32); /* fps denumerator */ @@ -2460,8 +2447,11 @@ static int theora_decode_header(AVCodecContext *avctx, GetBitContext *gb) // align_get_bits(gb); - avctx->width = s->width; - avctx->height = s->height; + if ( visible_width <= s->width && visible_width > s->width-16 + && visible_height <= s->height && visible_height > s->height-16) + avcodec_set_dimensions(avctx, visible_width, visible_height); + else + avcodec_set_dimensions(avctx, s->width, s->height); return 0; } @@ -2513,10 +2503,10 @@ static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb) for (plane = 0; plane <= 2; plane++) { int newqr= 1; if (inter || plane > 0) - newqr = get_bits(gb, 1); + newqr = get_bits1(gb); if (!newqr) { int qtj, plj; - if(inter && get_bits(gb, 1)){ + if(inter && get_bits1(gb)){ qtj = 0; plj = plane; }else{ @@ -2557,7 +2547,7 @@ static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb) for (s->hti = 0; s->hti < 80; s->hti++) { s->entries = 0; s->huff_code_size = 1; - if (!get_bits(gb, 1)) { + if (!get_bits1(gb)) { s->hbits = 0; read_huffman_tree(avctx, gb); s->hbits = 1; @@ -2570,7 +2560,6 @@ static int theora_decode_tables(AVCodecContext *avctx, GetBitContext *gb) return 0; } -#if ENABLE_THEORA_DECODER static int theora_decode_init(AVCodecContext *avctx) { Vp3DecodeContext *s = avctx->priv_data; @@ -2634,32 +2623,30 @@ static int theora_decode_init(AVCodecContext *avctx) vp3_decode_init(avctx); return 0; } -#endif -AVCodec vp3_decoder = { - "vp3", +AVCodec theora_decoder = { + "theora", CODEC_TYPE_VIDEO, - CODEC_ID_VP3, + CODEC_ID_THEORA, sizeof(Vp3DecodeContext), - vp3_decode_init, + theora_decode_init, NULL, vp3_decode_end, vp3_decode_frame, 0, NULL }; +#endif -#if ENABLE_THEORA_DECODER -AVCodec theora_decoder = { - "theora", +AVCodec vp3_decoder = { + "vp3", CODEC_TYPE_VIDEO, - CODEC_ID_THEORA, + CODEC_ID_VP3, sizeof(Vp3DecodeContext), - theora_decode_init, + vp3_decode_init, NULL, vp3_decode_end, vp3_decode_frame, 0, NULL }; -#endif diff --git a/contrib/ffmpeg/libavcodec/vp3data.h b/contrib/ffmpeg/libavcodec/vp3data.h index d69ddfa28..aa33b8327 100644 --- a/contrib/ffmpeg/libavcodec/vp3data.h +++ b/contrib/ffmpeg/libavcodec/vp3data.h @@ -18,8 +18,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef VP3DATA_H -#define VP3DATA_H +#ifndef FFMPEG_VP3DATA_H +#define FFMPEG_VP3DATA_H + +#include +#include /* these coefficients dequantize intraframe Y plane coefficients * (note: same as JPEG) */ @@ -3175,4 +3178,4 @@ static const uint16_t ac_bias_3[16][32][2] = { } }; -#endif /* VP3DATA_H */ +#endif /* FFMPEG_VP3DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/vp3dsp.c b/contrib/ffmpeg/libavcodec/vp3dsp.c index bb9fed091..fc8f54d8d 100644 --- a/contrib/ffmpeg/libavcodec/vp3dsp.c +++ b/contrib/ffmpeg/libavcodec/vp3dsp.c @@ -24,7 +24,6 @@ * source code. */ -#include "common.h" #include "avcodec.h" #include "dsputil.h" diff --git a/contrib/ffmpeg/libavcodec/vp5.c b/contrib/ffmpeg/libavcodec/vp5.c index 8a8c217c0..fc8119c2f 100644 --- a/contrib/ffmpeg/libavcodec/vp5.c +++ b/contrib/ffmpeg/libavcodec/vp5.c @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include @@ -34,7 +34,7 @@ #include "vp5data.h" -static int vp5_parse_header(vp56_context_t *s, uint8_t *buf, int buf_size, +static int vp5_parse_header(vp56_context_t *s, const uint8_t *buf, int buf_size, int *golden_frame) { vp56_range_coder_t *c = &s->c; @@ -88,16 +88,17 @@ static int vp5_adjust(int v, int t) static void vp5_parse_vector_adjustment(vp56_context_t *s, vp56_mv_t *vect) { vp56_range_coder_t *c = &s->c; + vp56_model_t *model = s->modelp; int comp, di; for (comp=0; comp<2; comp++) { int delta = 0; - if (vp56_rac_get_prob(c, s->vector_model_dct[comp])) { - int sign = vp56_rac_get_prob(c, s->vector_model_sig[comp]); - di = vp56_rac_get_prob(c, s->vector_model_pdi[comp][0]); - di |= vp56_rac_get_prob(c, s->vector_model_pdi[comp][1]) << 1; + if (vp56_rac_get_prob(c, model->vector_dct[comp])) { + int sign = vp56_rac_get_prob(c, model->vector_sig[comp]); + di = vp56_rac_get_prob(c, model->vector_pdi[comp][0]); + di |= vp56_rac_get_prob(c, model->vector_pdi[comp][1]) << 1; delta = vp56_rac_get_tree(c, vp56_pva_tree, - s->vector_model_pdv[comp]); + model->vector_pdv[comp]); delta = di | (delta << 2); delta = (delta ^ -sign) + sign; } @@ -111,28 +112,30 @@ static void vp5_parse_vector_adjustment(vp56_context_t *s, vp56_mv_t *vect) static void vp5_parse_vector_models(vp56_context_t *s) { vp56_range_coder_t *c = &s->c; + vp56_model_t *model = s->modelp; int comp, node; for (comp=0; comp<2; comp++) { if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][0])) - s->vector_model_dct[comp] = vp56_rac_gets_nn(c, 7); + model->vector_dct[comp] = vp56_rac_gets_nn(c, 7); if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][1])) - s->vector_model_sig[comp] = vp56_rac_gets_nn(c, 7); + model->vector_sig[comp] = vp56_rac_gets_nn(c, 7); if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][2])) - s->vector_model_pdi[comp][0] = vp56_rac_gets_nn(c, 7); + model->vector_pdi[comp][0] = vp56_rac_gets_nn(c, 7); if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][3])) - s->vector_model_pdi[comp][1] = vp56_rac_gets_nn(c, 7); + model->vector_pdi[comp][1] = vp56_rac_gets_nn(c, 7); } for (comp=0; comp<2; comp++) for (node=0; node<7; node++) if (vp56_rac_get_prob(c, vp5_vmc_pct[comp][4 + node])) - s->vector_model_pdv[comp][node] = vp56_rac_gets_nn(c, 7); + model->vector_pdv[comp][node] = vp56_rac_gets_nn(c, 7); } static void vp5_parse_coeff_models(vp56_context_t *s) { vp56_range_coder_t *c = &s->c; + vp56_model_t *model = s->modelp; uint8_t def_prob[11]; int node, cg, ctx; int ct; /* code type */ @@ -144,9 +147,9 @@ static void vp5_parse_coeff_models(vp56_context_t *s) for (node=0; node<11; node++) if (vp56_rac_get_prob(c, vp5_dccv_pct[pt][node])) { def_prob[node] = vp56_rac_gets_nn(c, 7); - s->coeff_model_dccv[pt][node] = def_prob[node]; + model->coeff_dccv[pt][node] = def_prob[node]; } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) { - s->coeff_model_dccv[pt][node] = def_prob[node]; + model->coeff_dccv[pt][node] = def_prob[node]; } for (ct=0; ct<3; ct++) @@ -155,31 +158,32 @@ static void vp5_parse_coeff_models(vp56_context_t *s) for (node=0; node<11; node++) if (vp56_rac_get_prob(c, vp5_ract_pct[ct][pt][cg][node])) { def_prob[node] = vp56_rac_gets_nn(c, 7); - s->coeff_model_ract[pt][ct][cg][node] = def_prob[node]; + model->coeff_ract[pt][ct][cg][node] = def_prob[node]; } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) { - s->coeff_model_ract[pt][ct][cg][node] = def_prob[node]; + model->coeff_ract[pt][ct][cg][node] = def_prob[node]; } - /* coeff_model_dcct is a linear combination of coeff_model_dccv */ + /* coeff_dcct is a linear combination of coeff_dccv */ for (pt=0; pt<2; pt++) for (ctx=0; ctx<36; ctx++) for (node=0; node<5; node++) - s->coeff_model_dcct[pt][ctx][node] = av_clip(((s->coeff_model_dccv[pt][node] * vp5_dccv_lc[node][ctx][0] + 128) >> 8) + vp5_dccv_lc[node][ctx][1], 1, 254); + model->coeff_dcct[pt][ctx][node] = av_clip(((model->coeff_dccv[pt][node] * vp5_dccv_lc[node][ctx][0] + 128) >> 8) + vp5_dccv_lc[node][ctx][1], 1, 254); - /* coeff_model_acct is a linear combination of coeff_model_ract */ + /* coeff_acct is a linear combination of coeff_ract */ for (ct=0; ct<3; ct++) for (pt=0; pt<2; pt++) for (cg=0; cg<3; cg++) for (ctx=0; ctx<6; ctx++) for (node=0; node<5; node++) - s->coeff_model_acct[pt][ct][cg][ctx][node] = av_clip(((s->coeff_model_ract[pt][ct][cg][node] * vp5_ract_lc[ct][cg][node][ctx][0] + 128) >> 8) + vp5_ract_lc[ct][cg][node][ctx][1], 1, 254); + model->coeff_acct[pt][ct][cg][ctx][node] = av_clip(((model->coeff_ract[pt][ct][cg][node] * vp5_ract_lc[ct][cg][node][ctx][0] + 128) >> 8) + vp5_ract_lc[ct][cg][node][ctx][1], 1, 254); } static void vp5_parse_coeff(vp56_context_t *s) { vp56_range_coder_t *c = &s->c; + vp56_model_t *model = s->modelp; uint8_t *permute = s->scantable.permutated; - uint8_t *model, *model2; + uint8_t *model1, *model2; int coeff, sign, coeff_idx; int b, i, cg, idx, ctx, ctx_last; int pt = 0; /* plane type (0 for Y, 1 for U or V) */ @@ -191,22 +195,22 @@ static void vp5_parse_coeff(vp56_context_t *s) ctx = 6*s->coeff_ctx[vp56_b6to4[b]][0] + s->above_blocks[s->above_block_idx[b]].not_null_dc; - model = s->coeff_model_dccv[pt]; - model2 = s->coeff_model_dcct[pt][ctx]; + model1 = model->coeff_dccv[pt]; + model2 = model->coeff_dcct[pt][ctx]; for (coeff_idx=0; coeff_idx<64; ) { if (vp56_rac_get_prob(c, model2[0])) { if (vp56_rac_get_prob(c, model2[2])) { if (vp56_rac_get_prob(c, model2[3])) { s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 4; - idx = vp56_rac_get_tree(c, vp56_pc_tree, model); + idx = vp56_rac_get_tree(c, vp56_pc_tree, model1); sign = vp56_rac_get(c); - coeff = vp56_coeff_bias[idx]; + coeff = vp56_coeff_bias[idx+5]; for (i=vp56_coeff_bit_length[idx]; i>=0; i--) coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i; } else { if (vp56_rac_get_prob(c, model2[4])) { - coeff = 3 + vp56_rac_get_prob(c, model[5]); + coeff = 3 + vp56_rac_get_prob(c, model1[5]); s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 3; } else { coeff = 2; @@ -234,8 +238,8 @@ static void vp5_parse_coeff(vp56_context_t *s) cg = vp5_coeff_groups[++coeff_idx]; ctx = s->coeff_ctx[vp56_b6to4[b]][coeff_idx]; - model = s->coeff_model_ract[pt][ct][cg]; - model2 = cg > 2 ? model : s->coeff_model_acct[pt][ct][cg][ctx]; + model1 = model->coeff_ract[pt][ct][cg]; + model2 = cg > 2 ? model1 : model->coeff_acct[pt][ct][cg][ctx]; } ctx_last = FFMIN(s->coeff_ctx_last[vp56_b6to4[b]], 24); @@ -249,23 +253,24 @@ static void vp5_parse_coeff(vp56_context_t *s) static void vp5_default_models_init(vp56_context_t *s) { + vp56_model_t *model = s->modelp; int i; for (i=0; i<2; i++) { - s->vector_model_sig[i] = 0x80; - s->vector_model_dct[i] = 0x80; - s->vector_model_pdi[i][0] = 0x55; - s->vector_model_pdi[i][1] = 0x80; + model->vector_sig[i] = 0x80; + model->vector_dct[i] = 0x80; + model->vector_pdi[i][0] = 0x55; + model->vector_pdi[i][1] = 0x80; } - memcpy(s->mb_types_stats, vp56_def_mb_types_stats, sizeof(s->mb_types_stats)); - memset(s->vector_model_pdv, 0x80, sizeof(s->vector_model_pdv)); + memcpy(model->mb_types_stats, vp56_def_mb_types_stats, sizeof(model->mb_types_stats)); + memset(model->vector_pdv, 0x80, sizeof(model->vector_pdv)); } static int vp5_decode_init(AVCodecContext *avctx) { vp56_context_t *s = avctx->priv_data; - vp56_init(s, avctx, 1); + vp56_init(avctx, 1, 0); s->vp56_coord_div = vp5_coord_div; s->parse_vector_adjustment = vp5_parse_vector_adjustment; s->adjust = vp5_adjust; @@ -287,4 +292,5 @@ AVCodec vp5_decoder = { NULL, vp56_free, vp56_decode_frame, + CODEC_CAP_DR1, }; diff --git a/contrib/ffmpeg/libavcodec/vp56.c b/contrib/ffmpeg/libavcodec/vp56.c index abd1b3a63..ca6ae76f9 100644 --- a/contrib/ffmpeg/libavcodec/vp56.c +++ b/contrib/ffmpeg/libavcodec/vp56.c @@ -18,10 +18,11 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avcodec.h" +#include "bytestream.h" #include "vp56.h" #include "vp56data.h" @@ -75,13 +76,15 @@ static int vp56_get_vectors_predictors(vp56_context_t *s, int row, int col, static void vp56_parse_mb_type_models(vp56_context_t *s) { vp56_range_coder_t *c = &s->c; + vp56_model_t *model = s->modelp; int i, ctx, type; for (ctx=0; ctx<3; ctx++) { if (vp56_rac_get_prob(c, 174)) { int idx = vp56_rac_gets(c, 4); - memcpy(s->mb_types_stats[ctx],vp56_pre_def_mb_type_stats[idx][ctx], - sizeof(s->mb_types_stats[ctx])); + memcpy(model->mb_types_stats[ctx], + vp56_pre_def_mb_type_stats[idx][ctx], + sizeof(model->mb_types_stats[ctx])); } if (vp56_rac_get_prob(c, 254)) { for (type=0; type<10; type++) { @@ -93,7 +96,7 @@ static void vp56_parse_mb_type_models(vp56_context_t *s) vp56_mb_type_model_model); if (!delta) delta = 4 * vp56_rac_gets(c, 7); - s->mb_types_stats[ctx][type][i] += (delta ^ -sign) + sign; + model->mb_types_stats[ctx][type][i] += (delta ^ -sign) + sign; } } } @@ -105,13 +108,13 @@ static void vp56_parse_mb_type_models(vp56_context_t *s) int p[10]; for (type=0; type<10; type++) - p[type] = 100 * s->mb_types_stats[ctx][type][1]; + p[type] = 100 * model->mb_types_stats[ctx][type][1]; for (type=0; type<10; type++) { int p02, p34, p0234, p17, p56, p89, p5689, p156789; /* conservative MB type probability */ - s->mb_type_model[ctx][type][0] = 255 - (255 * s->mb_types_stats[ctx][type][0]) / (1 + s->mb_types_stats[ctx][type][0] + s->mb_types_stats[ctx][type][1]); + model->mb_type[ctx][type][0] = 255 - (255 * model->mb_types_stats[ctx][type][0]) / (1 + model->mb_types_stats[ctx][type][0] + model->mb_types_stats[ctx][type][1]); p[type] = 0; /* same MB type => weight is null */ @@ -125,18 +128,18 @@ static void vp56_parse_mb_type_models(vp56_context_t *s) p5689 = p56 + p89; p156789 = p17 + p5689; - s->mb_type_model[ctx][type][1] = 1 + 255 * p0234/(1+p0234+p156789); - s->mb_type_model[ctx][type][2] = 1 + 255 * p02 / (1+p0234); - s->mb_type_model[ctx][type][3] = 1 + 255 * p17 / (1+p156789); - s->mb_type_model[ctx][type][4] = 1 + 255 * p[0] / (1+p02); - s->mb_type_model[ctx][type][5] = 1 + 255 * p[3] / (1+p34); - s->mb_type_model[ctx][type][6] = 1 + 255 * p[1] / (1+p17); - s->mb_type_model[ctx][type][7] = 1 + 255 * p56 / (1+p5689); - s->mb_type_model[ctx][type][8] = 1 + 255 * p[5] / (1+p56); - s->mb_type_model[ctx][type][9] = 1 + 255 * p[8] / (1+p89); + model->mb_type[ctx][type][1] = 1 + 255 * p0234/(1+p0234+p156789); + model->mb_type[ctx][type][2] = 1 + 255 * p02 / (1+p0234); + model->mb_type[ctx][type][3] = 1 + 255 * p17 / (1+p156789); + model->mb_type[ctx][type][4] = 1 + 255 * p[0] / (1+p02); + model->mb_type[ctx][type][5] = 1 + 255 * p[3] / (1+p34); + model->mb_type[ctx][type][6] = 1 + 255 * p[1] / (1+p17); + model->mb_type[ctx][type][7] = 1 + 255 * p56 / (1+p5689); + model->mb_type[ctx][type][8] = 1 + 255 * p[5] / (1+p56); + model->mb_type[ctx][type][9] = 1 + 255 * p[8] / (1+p89); /* restore initial value */ - p[type] = 100 * s->mb_types_stats[ctx][type][1]; + p[type] = 100 * model->mb_types_stats[ctx][type][1]; } } } @@ -144,7 +147,7 @@ static void vp56_parse_mb_type_models(vp56_context_t *s) static vp56_mb_t vp56_parse_mb_type(vp56_context_t *s, vp56_mb_t prev_type, int ctx) { - uint8_t *mb_type_model = s->mb_type_model[ctx][prev_type]; + uint8_t *mb_type_model = s->modelp->mb_type[ctx][prev_type]; vp56_range_coder_t *c = &s->c; if (vp56_rac_get_prob(c, mb_type_model[0])) @@ -258,13 +261,14 @@ static vp56_mb_t vp56_decode_mv(vp56_context_t *s, int row, int col) static void vp56_add_predictors_dc(vp56_context_t *s, vp56_frame_t ref_frame) { int idx = s->scantable.permutated[0]; - int i; + int b; - for (i=0; i<6; i++) { - vp56_ref_dc_t *ab = &s->above_blocks[s->above_block_idx[i]]; - vp56_ref_dc_t *lb = &s->left_block[vp56_b6to4[i]]; + for (b=0; b<6; b++) { + vp56_ref_dc_t *ab = &s->above_blocks[s->above_block_idx[b]]; + vp56_ref_dc_t *lb = &s->left_block[vp56_b6to4[b]]; int count = 0; int dc = 0; + int i; if (ref_frame == lb->ref_frame) { dc += lb->dc_coeff; @@ -274,28 +278,24 @@ static void vp56_add_predictors_dc(vp56_context_t *s, vp56_frame_t ref_frame) dc += ab->dc_coeff; count++; } - if (s->avctx->codec->id == CODEC_ID_VP5) { - if (count < 2 && ref_frame == ab[-1].ref_frame) { - dc += ab[-1].dc_coeff; - count++; - } - if (count < 2 && ref_frame == ab[1].ref_frame) { - dc += ab[1].dc_coeff; - count++; - } - } + if (s->avctx->codec->id == CODEC_ID_VP5) + for (i=0; i<2; i++) + if (count < 2 && ref_frame == ab[-1+2*i].ref_frame) { + dc += ab[-1+2*i].dc_coeff; + count++; + } if (count == 0) - dc = s->prev_dc[vp56_b6to3[i]][ref_frame]; + dc = s->prev_dc[vp56_b2p[b]][ref_frame]; else if (count == 2) dc /= 2; - s->block_coeff[i][idx] += dc; - s->prev_dc[vp56_b6to3[i]][ref_frame] = s->block_coeff[i][idx]; - ab->dc_coeff = s->block_coeff[i][idx]; + s->block_coeff[b][idx] += dc; + s->prev_dc[vp56_b2p[b]][ref_frame] = s->block_coeff[b][idx]; + ab->dc_coeff = s->block_coeff[b][idx]; ab->ref_frame = ref_frame; - lb->dc_coeff = s->block_coeff[i][idx]; + lb->dc_coeff = s->block_coeff[b][idx]; lb->ref_frame = ref_frame; - s->block_coeff[i][idx] *= s->dequant_dc; + s->block_coeff[b][idx] *= s->dequant_dc; } } @@ -322,10 +322,9 @@ static void vp56_deblock_filter(vp56_context_t *s, uint8_t *yuv, if (dy) vp56_edge_filter(s, yuv + stride*(10-dy), stride, 1, t); } -static void vp56_mc(vp56_context_t *s, int b, uint8_t *src, +static void vp56_mc(vp56_context_t *s, int b, int plane, uint8_t *src, int stride, int x, int y) { - int plane = vp56_b6to3[b]; uint8_t *dst=s->framep[VP56_FRAME_CURRENT]->data[plane]+s->block_offset[b]; uint8_t *src_block; int src_offset; @@ -393,12 +392,12 @@ static void vp56_mc(vp56_context_t *s, int b, uint8_t *src, } } -static void vp56_decode_mb(vp56_context_t *s, int row, int col) +static void vp56_decode_mb(vp56_context_t *s, int row, int col, int is_alpha) { AVFrame *frame_current, *frame_ref; vp56_mb_t mb_type; vp56_frame_t ref_frame; - int b, plan, off; + int b, ab, b_max, plane, off; if (s->framep[VP56_FRAME_CURRENT]->key_frame) mb_type = VP56_MB_INTRA; @@ -415,25 +414,28 @@ static void vp56_decode_mb(vp56_context_t *s, int row, int col) frame_current = s->framep[VP56_FRAME_CURRENT]; frame_ref = s->framep[ref_frame]; + ab = 6*is_alpha; + b_max = 6 - 2*is_alpha; + switch (mb_type) { case VP56_MB_INTRA: - for (b=0; b<6; b++) { - plan = vp56_b6to3[b]; - s->dsp.idct_put(frame_current->data[plan] + s->block_offset[b], - s->stride[plan], s->block_coeff[b]); + for (b=0; bdsp.idct_put(frame_current->data[plane] + s->block_offset[b], + s->stride[plane], s->block_coeff[b]); } break; case VP56_MB_INTER_NOVEC_PF: case VP56_MB_INTER_NOVEC_GF: - for (b=0; b<6; b++) { - plan = vp56_b6to3[b]; + for (b=0; bblock_offset[b]; - s->dsp.put_pixels_tab[1][0](frame_current->data[plan] + off, - frame_ref->data[plan] + off, - s->stride[plan], 8); - s->dsp.idct_add(frame_current->data[plan] + off, - s->stride[plan], s->block_coeff[b]); + s->dsp.put_pixels_tab[1][0](frame_current->data[plane] + off, + frame_ref->data[plane] + off, + s->stride[plane], 8); + s->dsp.idct_add(frame_current->data[plane] + off, + s->stride[plane], s->block_coeff[b]); } break; @@ -444,34 +446,35 @@ static void vp56_decode_mb(vp56_context_t *s, int row, int col) case VP56_MB_INTER_4V: case VP56_MB_INTER_V1_GF: case VP56_MB_INTER_V2_GF: - for (b=0; b<6; b++) { + for (b=0; bdata[plan], s->stride[plan], + plane = vp56_b2p[b+ab]; + vp56_mc(s, b, plane, frame_ref->data[plane], s->stride[plane], 16*col+x_off, 16*row+y_off); - s->dsp.idct_add(frame_current->data[plan] + s->block_offset[b], - s->stride[plan], s->block_coeff[b]); + s->dsp.idct_add(frame_current->data[plane] + s->block_offset[b], + s->stride[plane], s->block_coeff[b]); } break; } } -static int vp56_size_changed(AVCodecContext *avctx, vp56_context_t *s) +static int vp56_size_changed(AVCodecContext *avctx) { + vp56_context_t *s = avctx->priv_data; int stride = s->framep[VP56_FRAME_CURRENT]->linesize[0]; int i; - s->plane_width[0] = s->avctx->coded_width; - s->plane_width[1] = s->plane_width[2] = s->avctx->coded_width/2; - s->plane_height[0] = s->avctx->coded_height; - s->plane_height[1] = s->plane_height[2] = s->avctx->coded_height/2; + s->plane_width[0] = s->plane_width[3] = avctx->coded_width; + s->plane_width[1] = s->plane_width[2] = avctx->coded_width/2; + s->plane_height[0] = s->plane_height[3] = avctx->coded_height; + s->plane_height[1] = s->plane_height[2] = avctx->coded_height/2; - for (i=0; i<3; i++) + for (i=0; i<4; i++) s->stride[i] = s->flip * s->framep[VP56_FRAME_CURRENT]->linesize[i]; - s->mb_width = (s->avctx->coded_width+15) / 16; - s->mb_height = (s->avctx->coded_height+15) / 16; + s->mb_width = (avctx->coded_width +15) / 16; + s->mb_height = (avctx->coded_height+15) / 16; if (s->mb_width > 1000 || s->mb_height > 1000) { av_log(avctx, AV_LOG_ERROR, "picture too big\n"); @@ -492,117 +495,145 @@ static int vp56_size_changed(AVCodecContext *avctx, vp56_context_t *s) } int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { vp56_context_t *s = avctx->priv_data; AVFrame *const p = s->framep[VP56_FRAME_CURRENT]; - int mb_row, mb_col, mb_row_flip, mb_offset = 0; - int block, y, uv, stride_y, stride_uv; - int golden_frame = 0; - int res; - - res = s->parse_header(s, buf, buf_size, &golden_frame); - if (!res) - return -1; + int is_alpha, alpha_offset; - p->reference = 1; - if (avctx->get_buffer(avctx, p) < 0) { - av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + if (s->has_alpha) { + alpha_offset = bytestream_get_be24(&buf); + buf_size -= 3; } - if (res == 2) - if (vp56_size_changed(avctx, s)) { - avctx->release_buffer(avctx, p); - return -1; - } + for (is_alpha=0; is_alpha < 1+s->has_alpha; is_alpha++) { + int mb_row, mb_col, mb_row_flip, mb_offset = 0; + int block, y, uv, stride_y, stride_uv; + int golden_frame = 0; + int res; - if (p->key_frame) { - p->pict_type = FF_I_TYPE; - s->default_models_init(s); - for (block=0; blockmb_height*s->mb_width; block++) - s->macroblocks[block].type = VP56_MB_INTRA; - } else { - p->pict_type = FF_P_TYPE; - vp56_parse_mb_type_models(s); - s->parse_vector_models(s); - s->mb_type = VP56_MB_INTER_NOVEC_PF; - } + s->modelp = &s->models[is_alpha]; - s->parse_coeff_models(s); + res = s->parse_header(s, buf, buf_size, &golden_frame); + if (!res) + return -1; - memset(s->prev_dc, 0, sizeof(s->prev_dc)); - s->prev_dc[1][VP56_FRAME_CURRENT] = 128; - s->prev_dc[2][VP56_FRAME_CURRENT] = 128; + if (!is_alpha) { + p->reference = 1; + if (avctx->get_buffer(avctx, p) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } - for (block=0; block < 4*s->mb_width+6; block++) { - s->above_blocks[block].ref_frame = -1; - s->above_blocks[block].dc_coeff = 0; - s->above_blocks[block].not_null_dc = 0; - } - s->above_blocks[2*s->mb_width + 2].ref_frame = 0; - s->above_blocks[3*s->mb_width + 4].ref_frame = 0; + if (res == 2) + if (vp56_size_changed(avctx)) { + avctx->release_buffer(avctx, p); + return -1; + } + } - stride_y = p->linesize[0]; - stride_uv = p->linesize[1]; + if (p->key_frame) { + p->pict_type = FF_I_TYPE; + s->default_models_init(s); + for (block=0; blockmb_height*s->mb_width; block++) + s->macroblocks[block].type = VP56_MB_INTRA; + } else { + p->pict_type = FF_P_TYPE; + vp56_parse_mb_type_models(s); + s->parse_vector_models(s); + s->mb_type = VP56_MB_INTER_NOVEC_PF; + } - if (s->flip < 0) - mb_offset = 7; + s->parse_coeff_models(s); - /* main macroblocks loop */ - for (mb_row=0; mb_rowmb_height; mb_row++) { - if (s->flip < 0) - mb_row_flip = s->mb_height - mb_row - 1; - else - mb_row_flip = mb_row; + memset(s->prev_dc, 0, sizeof(s->prev_dc)); + s->prev_dc[1][VP56_FRAME_CURRENT] = 128; + s->prev_dc[2][VP56_FRAME_CURRENT] = 128; - for (block=0; block<4; block++) { - s->left_block[block].ref_frame = -1; - s->left_block[block].dc_coeff = 0; - s->left_block[block].not_null_dc = 0; - memset(s->coeff_ctx[block], 0, 64*sizeof(s->coeff_ctx[block][0])); + for (block=0; block < 4*s->mb_width+6; block++) { + s->above_blocks[block].ref_frame = -1; + s->above_blocks[block].dc_coeff = 0; + s->above_blocks[block].not_null_dc = 0; } - memset(s->coeff_ctx_last, 24, sizeof(s->coeff_ctx_last)); - - s->above_block_idx[0] = 1; - s->above_block_idx[1] = 2; - s->above_block_idx[2] = 1; - s->above_block_idx[3] = 2; - s->above_block_idx[4] = 2*s->mb_width + 2 + 1; - s->above_block_idx[5] = 3*s->mb_width + 4 + 1; - - s->block_offset[s->frbi] = (mb_row_flip*16 + mb_offset) * stride_y; - s->block_offset[s->srbi] = s->block_offset[s->frbi] + 8*stride_y; - s->block_offset[1] = s->block_offset[0] + 8; - s->block_offset[3] = s->block_offset[2] + 8; - s->block_offset[4] = (mb_row_flip*8 + mb_offset) * stride_uv; - s->block_offset[5] = s->block_offset[4]; - - for (mb_col=0; mb_colmb_width; mb_col++) { - vp56_decode_mb(s, mb_row, mb_col); - - for (y=0; y<4; y++) { - s->above_block_idx[y] += 2; - s->block_offset[y] += 16; + s->above_blocks[2*s->mb_width + 2].ref_frame = 0; + s->above_blocks[3*s->mb_width + 4].ref_frame = 0; + + stride_y = p->linesize[0]; + stride_uv = p->linesize[1]; + + if (s->flip < 0) + mb_offset = 7; + + /* main macroblocks loop */ + for (mb_row=0; mb_rowmb_height; mb_row++) { + if (s->flip < 0) + mb_row_flip = s->mb_height - mb_row - 1; + else + mb_row_flip = mb_row; + + for (block=0; block<4; block++) { + s->left_block[block].ref_frame = -1; + s->left_block[block].dc_coeff = 0; + s->left_block[block].not_null_dc = 0; } + memset(s->coeff_ctx, 0, sizeof(s->coeff_ctx)); + memset(s->coeff_ctx_last, 24, sizeof(s->coeff_ctx_last)); + + s->above_block_idx[0] = 1; + s->above_block_idx[1] = 2; + s->above_block_idx[2] = 1; + s->above_block_idx[3] = 2; + s->above_block_idx[4] = 2*s->mb_width + 2 + 1; + s->above_block_idx[5] = 3*s->mb_width + 4 + 1; + + s->block_offset[s->frbi] = (mb_row_flip*16 + mb_offset) * stride_y; + s->block_offset[s->srbi] = s->block_offset[s->frbi] + 8*stride_y; + s->block_offset[1] = s->block_offset[0] + 8; + s->block_offset[3] = s->block_offset[2] + 8; + s->block_offset[4] = (mb_row_flip*8 + mb_offset) * stride_uv; + s->block_offset[5] = s->block_offset[4]; + + for (mb_col=0; mb_colmb_width; mb_col++) { + vp56_decode_mb(s, mb_row, mb_col, is_alpha); + + for (y=0; y<4; y++) { + s->above_block_idx[y] += 2; + s->block_offset[y] += 16; + } - for (uv=4; uv<6; uv++) { - s->above_block_idx[uv] += 1; - s->block_offset[uv] += 8; + for (uv=4; uv<6; uv++) { + s->above_block_idx[uv] += 1; + s->block_offset[uv] += 8; + } } } + + if (p->key_frame || golden_frame) { + if (s->framep[VP56_FRAME_GOLDEN]->data[0] && + s->framep[VP56_FRAME_GOLDEN] != s->framep[VP56_FRAME_GOLDEN2]) + avctx->release_buffer(avctx, s->framep[VP56_FRAME_GOLDEN]); + s->framep[VP56_FRAME_GOLDEN] = p; + } + + if (s->has_alpha) { + FFSWAP(AVFrame *, s->framep[VP56_FRAME_GOLDEN], + s->framep[VP56_FRAME_GOLDEN2]); + buf += alpha_offset; + buf_size -= alpha_offset; + } } - if (s->framep[VP56_FRAME_PREVIOUS] == s->framep[VP56_FRAME_GOLDEN]) - FFSWAP(AVFrame *, s->framep[VP56_FRAME_PREVIOUS], - s->framep[VP56_FRAME_UNUSED]); - else if (s->framep[VP56_FRAME_PREVIOUS]->data[0]) + if (s->framep[VP56_FRAME_PREVIOUS] == s->framep[VP56_FRAME_GOLDEN] || + s->framep[VP56_FRAME_PREVIOUS] == s->framep[VP56_FRAME_GOLDEN2]) { + if (s->framep[VP56_FRAME_UNUSED] != s->framep[VP56_FRAME_GOLDEN] && + s->framep[VP56_FRAME_UNUSED] != s->framep[VP56_FRAME_GOLDEN2]) + FFSWAP(AVFrame *, s->framep[VP56_FRAME_PREVIOUS], + s->framep[VP56_FRAME_UNUSED]); + else + FFSWAP(AVFrame *, s->framep[VP56_FRAME_PREVIOUS], + s->framep[VP56_FRAME_UNUSED2]); + } else if (s->framep[VP56_FRAME_PREVIOUS]->data[0]) avctx->release_buffer(avctx, s->framep[VP56_FRAME_PREVIOUS]); - if (p->key_frame || golden_frame) { - if (s->framep[VP56_FRAME_GOLDEN]->data[0]) - avctx->release_buffer(avctx, s->framep[VP56_FRAME_GOLDEN]); - s->framep[VP56_FRAME_GOLDEN] = p; - } FFSWAP(AVFrame *, s->framep[VP56_FRAME_CURRENT], s->framep[VP56_FRAME_PREVIOUS]); @@ -612,23 +643,25 @@ int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size, return buf_size; } -void vp56_init(vp56_context_t *s, AVCodecContext *avctx, int flip) +void vp56_init(AVCodecContext *avctx, int flip, int has_alpha) { + vp56_context_t *s = avctx->priv_data; int i; s->avctx = avctx; - avctx->pix_fmt = PIX_FMT_YUV420P; + avctx->pix_fmt = has_alpha ? PIX_FMT_YUVA420P : PIX_FMT_YUV420P; - if (s->avctx->idct_algo == FF_IDCT_AUTO) - s->avctx->idct_algo = FF_IDCT_VP3; - dsputil_init(&s->dsp, s->avctx); + if (avctx->idct_algo == FF_IDCT_AUTO) + avctx->idct_algo = FF_IDCT_VP3; + dsputil_init(&s->dsp, avctx); ff_init_scantable(s->dsp.idct_permutation, &s->scantable,ff_zigzag_direct); - avcodec_set_dimensions(s->avctx, 0, 0); + avcodec_set_dimensions(avctx, 0, 0); - for (i=0; i<3; i++) + for (i=0; i<4; i++) s->framep[i] = &s->frames[i]; s->framep[VP56_FRAME_UNUSED] = s->framep[VP56_FRAME_GOLDEN]; + s->framep[VP56_FRAME_UNUSED2] = s->framep[VP56_FRAME_GOLDEN2]; s->edge_emu_buffer_alloc = NULL; s->above_blocks = NULL; @@ -638,6 +671,7 @@ void vp56_init(vp56_context_t *s, AVCodecContext *avctx, int flip) s->filter = NULL; + s->has_alpha = has_alpha; if (flip) { s->flip = -1; s->frbi = 2; @@ -656,9 +690,10 @@ int vp56_free(AVCodecContext *avctx) av_free(s->above_blocks); av_free(s->macroblocks); av_free(s->edge_emu_buffer_alloc); - if (s->framep[VP56_FRAME_GOLDEN]->data[0] - && (s->framep[VP56_FRAME_PREVIOUS] != s->framep[VP56_FRAME_GOLDEN])) + if (s->framep[VP56_FRAME_GOLDEN]->data[0]) avctx->release_buffer(avctx, s->framep[VP56_FRAME_GOLDEN]); + if (s->framep[VP56_FRAME_GOLDEN2]->data[0]) + avctx->release_buffer(avctx, s->framep[VP56_FRAME_GOLDEN2]); if (s->framep[VP56_FRAME_PREVIOUS]->data[0]) avctx->release_buffer(avctx, s->framep[VP56_FRAME_PREVIOUS]); return 0; diff --git a/contrib/ffmpeg/libavcodec/vp56.h b/contrib/ffmpeg/libavcodec/vp56.h index fb8bbba6f..f85f947e7 100644 --- a/contrib/ffmpeg/libavcodec/vp56.h +++ b/contrib/ffmpeg/libavcodec/vp56.h @@ -18,15 +18,16 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef VP56_H -#define VP56_H +#ifndef FFMPEG_VP56_H +#define FFMPEG_VP56_H #include "vp56data.h" #include "dsputil.h" #include "mpegvideo.h" +#include "bytestream.h" typedef struct vp56_context vp56_context_t; @@ -42,7 +43,7 @@ typedef void (*vp56_parse_coeff_t)(vp56_context_t *s); typedef void (*vp56_default_models_init_t)(vp56_context_t *s); typedef void (*vp56_parse_vector_models_t)(vp56_context_t *s); typedef void (*vp56_parse_coeff_models_t)(vp56_context_t *s); -typedef int (*vp56_parse_header_t)(vp56_context_t *s, uint8_t *buf, +typedef int (*vp56_parse_header_t)(vp56_context_t *s, const uint8_t *buf, int buf_size, int *golden_frame); typedef struct { @@ -68,12 +69,29 @@ typedef struct { vp56_mv_t mv; } vp56_macroblock_t; +typedef struct { + uint8_t coeff_reorder[64]; /* used in vp6 only */ + uint8_t coeff_index_to_pos[64]; /* used in vp6 only */ + uint8_t vector_sig[2]; /* delta sign */ + uint8_t vector_dct[2]; /* delta coding types */ + uint8_t vector_pdi[2][2]; /* predefined delta init */ + uint8_t vector_pdv[2][7]; /* predefined delta values */ + uint8_t vector_fdv[2][8]; /* 8 bit delta value definition */ + uint8_t coeff_dccv[2][11]; /* DC coeff value */ + uint8_t coeff_ract[2][3][6][11]; /* Run/AC coding type and AC coeff value */ + uint8_t coeff_acct[2][3][3][6][5];/* vp5 only AC coding type for coding group < 3 */ + uint8_t coeff_dcct[2][36][5]; /* DC coeff coding type */ + uint8_t coeff_runv[2][14]; /* run value (vp6 only) */ + uint8_t mb_type[3][10][10]; /* model for decoding MB type */ + uint8_t mb_types_stats[3][10][2];/* contextual, next MB type stats */ +} vp56_model_t; + struct vp56_context { AVCodecContext *avctx; DSPContext dsp; ScanTable scantable; - AVFrame frames[3]; - AVFrame *framep[4]; + AVFrame frames[4]; + AVFrame *framep[6]; uint8_t *edge_emu_buffer_alloc; uint8_t *edge_emu_buffer; vp56_range_coder_t c; @@ -82,8 +100,8 @@ struct vp56_context { int sub_version; /* frame info */ - int plane_width[3]; - int plane_height[3]; + int plane_width[4]; + int plane_height[4]; int mb_width; /* number of horizontal MB */ int mb_height; /* number of vertical MB */ int block_offset[6]; @@ -102,8 +120,6 @@ struct vp56_context { vp56_mb_t mb_type; vp56_macroblock_t *macroblocks; DECLARE_ALIGNED_16(DCTELEM, block_coeff[6][64]); - uint8_t coeff_reorder[64]; /* used in vp6 only */ - uint8_t coeff_index_to_pos[64]; /* used in vp6 only */ /* motion vectors */ vp56_mv_t mv[6]; /* vectors for each block in MB */ @@ -118,27 +134,16 @@ struct vp56_context { int max_vector_length; int sample_variance_threshold; - /* AC models */ - uint8_t vector_model_sig[2]; /* delta sign */ - uint8_t vector_model_dct[2]; /* delta coding types */ - uint8_t vector_model_pdi[2][2]; /* predefined delta init */ - uint8_t vector_model_pdv[2][7]; /* predefined delta values */ - uint8_t vector_model_fdv[2][8]; /* 8 bit delta value definition */ - uint8_t mb_type_model[3][10][10]; /* model for decoding MB type */ - uint8_t coeff_model_dccv[2][11]; /* DC coeff value */ - uint8_t coeff_model_ract[2][3][6][11]; /* Run/AC coding type and AC coeff value */ - uint8_t coeff_model_acct[2][3][3][6][5];/* vp5 only AC coding type for coding group < 3 */ - uint8_t coeff_model_dcct[2][36][5]; /* DC coeff coding type */ - uint8_t coeff_model_runv[2][14]; /* run value (vp6 only) */ - uint8_t mb_types_stats[3][10][2]; /* contextual, next MB type stats */ uint8_t coeff_ctx[4][64]; /* used in vp5 only */ uint8_t coeff_ctx_last[4]; /* used in vp5 only */ + int has_alpha; + /* upside-down flipping hints */ int flip; /* are we flipping ? */ int frbi; /* first row block index in MB */ int srbi; /* second row block index in MB */ - int stride[3]; /* stride for each plan */ + int stride[4]; /* stride for each plan */ const uint8_t *vp56_coord_div; vp56_parse_vector_adjustment_t parse_vector_adjustment; @@ -149,14 +154,25 @@ struct vp56_context { vp56_parse_vector_models_t parse_vector_models; vp56_parse_coeff_models_t parse_coeff_models; vp56_parse_header_t parse_header; + + vp56_model_t *modelp; + vp56_model_t models[2]; + + /* huffman decoding */ + int use_huffman; + GetBitContext gb; + VLC dccv_vlc[2]; + VLC runv_vlc[2]; + VLC ract_vlc[2][3][6]; + unsigned int nb_null[2][2]; /* number of consecutive NULL DC/AC */ }; -void vp56_init(vp56_context_t *s, AVCodecContext *avctx, int flip); +void vp56_init(AVCodecContext *avctx, int flip, int has_alpha); int vp56_free(AVCodecContext *avctx); void vp56_init_dequant(vp56_context_t *s, int quantizer); int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size); + const uint8_t *buf, int buf_size); /** @@ -169,8 +185,7 @@ static inline void vp56_init_range_decoder(vp56_range_coder_t *c, c->high = 255; c->bits = 8; c->buffer = buf; - c->code_word = *c->buffer++ << 8; - c->code_word |= *c->buffer++; + c->code_word = bytestream_get_be16(&c->buffer); } static inline int vp56_rac_get_prob(vp56_range_coder_t *c, uint8_t prob) @@ -250,4 +265,4 @@ static inline int vp56_rac_get_tree(vp56_range_coder_t *c, return -tree->val; } -#endif /* VP56_H */ +#endif /* FFMPEG_VP56_H */ diff --git a/contrib/ffmpeg/libavcodec/vp56data.c b/contrib/ffmpeg/libavcodec/vp56data.c index e75c6d1ce..a7171c695 100644 --- a/contrib/ffmpeg/libavcodec/vp56data.c +++ b/contrib/ffmpeg/libavcodec/vp56data.c @@ -18,12 +18,12 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "vp56data.h" -const uint8_t vp56_b6to3[] = { 0, 0, 0, 0, 1, 2 }; +const uint8_t vp56_b2p[] = { 0, 0, 0, 0, 1, 2, 3, 3, 3, 3 }; const uint8_t vp56_b6to4[] = { 0, 0, 1, 1, 2, 3 }; const uint8_t vp56_coeff_parse_table[6][11] = { @@ -62,5 +62,5 @@ const vp56_tree_t vp56_pc_tree[] = { { 2,10}, {-4}, {-5}, }; -const uint8_t vp56_coeff_bias[] = { 5, 7, 11, 19, 35, 67 }; +const uint8_t vp56_coeff_bias[] = { 0, 1, 2, 3, 4, 5, 7, 11, 19, 35, 67 }; const uint8_t vp56_coeff_bit_length[] = { 0, 1, 2, 3, 4, 10 }; diff --git a/contrib/ffmpeg/libavcodec/vp56data.h b/contrib/ffmpeg/libavcodec/vp56data.h index d784b9803..0dd79b06b 100644 --- a/contrib/ffmpeg/libavcodec/vp56data.h +++ b/contrib/ffmpeg/libavcodec/vp56data.h @@ -18,11 +18,11 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef VP56DATA_H -#define VP56DATA_H +#ifndef FFMPEG_VP56DATA_H +#define FFMPEG_VP56DATA_H #include "common.h" @@ -30,7 +30,9 @@ typedef enum { VP56_FRAME_CURRENT = 0, VP56_FRAME_PREVIOUS = 1, VP56_FRAME_GOLDEN = 2, - VP56_FRAME_UNUSED = 3, + VP56_FRAME_GOLDEN2 = 3, + VP56_FRAME_UNUSED = 4, + VP56_FRAME_UNUSED2 = 5, } vp56_frame_t; typedef enum { @@ -51,7 +53,7 @@ typedef struct { int8_t prob_idx; } vp56_tree_t; -extern const uint8_t vp56_b6to3[]; +extern const uint8_t vp56_b2p[]; extern const uint8_t vp56_b6to4[]; extern const uint8_t vp56_coeff_parse_table[6][11]; extern const uint8_t vp56_def_mb_types_stats[3][10][2]; @@ -246,4 +248,4 @@ static const int8_t vp56_candidate_predictor_pos[12][2] = { { 2, -2 }, }; -#endif /* VP56DATA */ +#endif /* FFMPEG_VP56DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/vp5data.h b/contrib/ffmpeg/libavcodec/vp5data.h index effc17c2c..c08688a21 100644 --- a/contrib/ffmpeg/libavcodec/vp5data.h +++ b/contrib/ffmpeg/libavcodec/vp5data.h @@ -18,11 +18,13 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef VP5DATA_H -#define VP5DATA_H +#ifndef FFMPEG_VP5DATA_H +#define FFMPEG_VP5DATA_H + +#include static const uint8_t vp5_coeff_groups[] = { -1, 0, 1, 1, 2, 1, 1, 2, @@ -170,4 +172,4 @@ static const int16_t vp5_ract_lc[3][3][5][6][2] = { static const uint8_t vp5_coord_div[] = { 2, 2, 2, 2, 4, 4 }; -#endif /* VP5DATA_H */ +#endif /* FFMPEG_VP5DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/vp6.c b/contrib/ffmpeg/libavcodec/vp6.c index 2e904b7e0..896f06d4c 100644 --- a/contrib/ffmpeg/libavcodec/vp6.c +++ b/contrib/ffmpeg/libavcodec/vp6.c @@ -4,6 +4,10 @@ * * Copyright (C) 2006 Aurelien Jacobs * + * The VP6F decoder accepts an optional 1 byte extradata. It is composed of: + * - upper 4bits: difference between encoded width and visible width + * - lower 4bits: difference between encoded height and visible height + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -18,12 +22,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * The VP6F decoder accept an optional 1 byte extradata. It is composed of: - * - upper 4bits: difference between encoded width and visible width - * - lower 4bits: difference between encoded height and visible height + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include @@ -31,6 +30,7 @@ #include "avcodec.h" #include "dsputil.h" #include "bitstream.h" +#include "huffman.h" #include "mpegvideo.h" #include "vp56.h" @@ -38,7 +38,10 @@ #include "vp6data.h" -static int vp6_parse_header(vp56_context_t *s, uint8_t *buf, int buf_size, +static void vp6_parse_coeff(vp56_context_t *s); +static void vp6_parse_coeff_huffman(vp56_context_t *s); + +static int vp6_parse_header(vp56_context_t *s, const uint8_t *buf, int buf_size, int *golden_frame) { vp56_range_coder_t *c = &s->c; @@ -127,12 +130,19 @@ static int vp6_parse_header(vp56_context_t *s, uint8_t *buf, int buf_size, s->filter_selection = 16; } - vp56_rac_get(c); + s->use_huffman = vp56_rac_get(c); + s->parse_coeff = vp6_parse_coeff; if (coeff_offset) { - vp56_init_range_decoder(&s->cc, buf+coeff_offset, - buf_size-coeff_offset); - s->ccp = &s->cc; + buf += coeff_offset; + buf_size -= coeff_offset; + if (s->use_huffman) { + s->parse_coeff = vp6_parse_coeff_huffman; + init_get_bits(&s->gb, buf, buf_size<<3); + } else { + vp56_init_range_decoder(&s->cc, buf, buf_size); + s->ccp = &s->cc; + } } else { s->ccp = &s->c; } @@ -144,25 +154,27 @@ static void vp6_coeff_order_table_init(vp56_context_t *s) { int i, pos, idx = 1; - s->coeff_index_to_pos[0] = 0; + s->modelp->coeff_index_to_pos[0] = 0; for (i=0; i<16; i++) for (pos=1; pos<64; pos++) - if (s->coeff_reorder[pos] == i) - s->coeff_index_to_pos[idx++] = pos; + if (s->modelp->coeff_reorder[pos] == i) + s->modelp->coeff_index_to_pos[idx++] = pos; } static void vp6_default_models_init(vp56_context_t *s) { - s->vector_model_dct[0] = 0xA2; - s->vector_model_dct[1] = 0xA4; - s->vector_model_sig[0] = 0x80; - s->vector_model_sig[1] = 0x80; + vp56_model_t *model = s->modelp; + + model->vector_dct[0] = 0xA2; + model->vector_dct[1] = 0xA4; + model->vector_sig[0] = 0x80; + model->vector_sig[1] = 0x80; - memcpy(s->mb_types_stats, vp56_def_mb_types_stats, sizeof(s->mb_types_stats)); - memcpy(s->vector_model_fdv, vp6_def_fdv_vector_model, sizeof(s->vector_model_fdv)); - memcpy(s->vector_model_pdv, vp6_def_pdv_vector_model, sizeof(s->vector_model_pdv)); - memcpy(s->coeff_model_runv, vp6_def_runv_coeff_model, sizeof(s->coeff_model_runv)); - memcpy(s->coeff_reorder, vp6_def_coeff_reorder, sizeof(s->coeff_reorder)); + memcpy(model->mb_types_stats, vp56_def_mb_types_stats, sizeof(model->mb_types_stats)); + memcpy(model->vector_fdv, vp6_def_fdv_vector_model, sizeof(model->vector_fdv)); + memcpy(model->vector_pdv, vp6_def_pdv_vector_model, sizeof(model->vector_pdv)); + memcpy(model->coeff_runv, vp6_def_runv_coeff_model, sizeof(model->coeff_runv)); + memcpy(model->coeff_reorder, vp6_def_coeff_reorder, sizeof(model->coeff_reorder)); vp6_coeff_order_table_init(s); } @@ -170,29 +182,56 @@ static void vp6_default_models_init(vp56_context_t *s) static void vp6_parse_vector_models(vp56_context_t *s) { vp56_range_coder_t *c = &s->c; + vp56_model_t *model = s->modelp; int comp, node; for (comp=0; comp<2; comp++) { if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][0])) - s->vector_model_dct[comp] = vp56_rac_gets_nn(c, 7); + model->vector_dct[comp] = vp56_rac_gets_nn(c, 7); if (vp56_rac_get_prob(c, vp6_sig_dct_pct[comp][1])) - s->vector_model_sig[comp] = vp56_rac_gets_nn(c, 7); + model->vector_sig[comp] = vp56_rac_gets_nn(c, 7); } for (comp=0; comp<2; comp++) for (node=0; node<7; node++) if (vp56_rac_get_prob(c, vp6_pdv_pct[comp][node])) - s->vector_model_pdv[comp][node] = vp56_rac_gets_nn(c, 7); + model->vector_pdv[comp][node] = vp56_rac_gets_nn(c, 7); for (comp=0; comp<2; comp++) for (node=0; node<8; node++) if (vp56_rac_get_prob(c, vp6_fdv_pct[comp][node])) - s->vector_model_fdv[comp][node] = vp56_rac_gets_nn(c, 7); + model->vector_fdv[comp][node] = vp56_rac_gets_nn(c, 7); +} + +static int vp6_huff_cmp(const void *va, const void *vb) +{ + const Node *a = va, *b = vb; + return a->count >= b->count; +} + +static void vp6_build_huff_tree(vp56_context_t *s, uint8_t coeff_model[], + const uint8_t *map, unsigned size, VLC *vlc) +{ + Node nodes[2*size], *tmp = &nodes[size]; + int a, b, i; + + /* first compute probabilities from model */ + tmp[0].count = 256; + for (i=0; i> 8; + b = tmp[i].count * (255 - coeff_model[i]) >> 8; + nodes[map[2*i ]].count = a + !a; + nodes[map[2*i+1]].count = b + !b; + } + + /* then build the huffman tree accodring to probabilities */ + ff_huff_build_tree(s->avctx, vlc, size, nodes, vp6_huff_cmp, 1); } static void vp6_parse_coeff_models(vp56_context_t *s) { vp56_range_coder_t *c = &s->c; + vp56_model_t *model = s->modelp; int def_prob[11]; int node, cg, ctx, pos; int ct; /* code type */ @@ -204,22 +243,22 @@ static void vp6_parse_coeff_models(vp56_context_t *s) for (node=0; node<11; node++) if (vp56_rac_get_prob(c, vp6_dccv_pct[pt][node])) { def_prob[node] = vp56_rac_gets_nn(c, 7); - s->coeff_model_dccv[pt][node] = def_prob[node]; + model->coeff_dccv[pt][node] = def_prob[node]; } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) { - s->coeff_model_dccv[pt][node] = def_prob[node]; + model->coeff_dccv[pt][node] = def_prob[node]; } if (vp56_rac_get(c)) { for (pos=1; pos<64; pos++) if (vp56_rac_get_prob(c, vp6_coeff_reorder_pct[pos])) - s->coeff_reorder[pos] = vp56_rac_gets(c, 4); + model->coeff_reorder[pos] = vp56_rac_gets(c, 4); vp6_coeff_order_table_init(s); } for (cg=0; cg<2; cg++) for (node=0; node<14; node++) if (vp56_rac_get_prob(c, vp6_runv_pct[cg][node])) - s->coeff_model_runv[cg][node] = vp56_rac_gets_nn(c, 7); + model->coeff_runv[cg][node] = vp56_rac_gets_nn(c, 7); for (ct=0; ct<3; ct++) for (pt=0; pt<2; pt++) @@ -227,21 +266,37 @@ static void vp6_parse_coeff_models(vp56_context_t *s) for (node=0; node<11; node++) if (vp56_rac_get_prob(c, vp6_ract_pct[ct][pt][cg][node])) { def_prob[node] = vp56_rac_gets_nn(c, 7); - s->coeff_model_ract[pt][ct][cg][node] = def_prob[node]; + model->coeff_ract[pt][ct][cg][node] = def_prob[node]; } else if (s->framep[VP56_FRAME_CURRENT]->key_frame) { - s->coeff_model_ract[pt][ct][cg][node] = def_prob[node]; + model->coeff_ract[pt][ct][cg][node] = def_prob[node]; } - /* coeff_model_dcct is a linear combination of coeff_model_dccv */ + if (s->use_huffman) { + for (pt=0; pt<2; pt++) { + vp6_build_huff_tree(s, model->coeff_dccv[pt], + vp6_huff_coeff_map, 12, &s->dccv_vlc[pt]); + vp6_build_huff_tree(s, model->coeff_runv[pt], + vp6_huff_run_map, 9, &s->runv_vlc[pt]); + for (ct=0; ct<3; ct++) + for (cg = 0; cg < 6; cg++) + vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg], + vp6_huff_coeff_map, 12, + &s->ract_vlc[pt][ct][cg]); + } + memset(s->nb_null, 0, sizeof(s->nb_null)); + } else { + /* coeff_dcct is a linear combination of coeff_dccv */ for (pt=0; pt<2; pt++) for (ctx=0; ctx<3; ctx++) for (node=0; node<5; node++) - s->coeff_model_dcct[pt][ctx][node] = av_clip(((s->coeff_model_dccv[pt][node] * vp6_dccv_lc[ctx][node][0] + 128) >> 8) + vp6_dccv_lc[ctx][node][1], 1, 255); + model->coeff_dcct[pt][ctx][node] = av_clip(((model->coeff_dccv[pt][node] * vp6_dccv_lc[ctx][node][0] + 128) >> 8) + vp6_dccv_lc[ctx][node][1], 1, 255); + } } static void vp6_parse_vector_adjustment(vp56_context_t *s, vp56_mv_t *vect) { vp56_range_coder_t *c = &s->c; + vp56_model_t *model = s->modelp; int comp; *vect = (vp56_mv_t) {0,0}; @@ -251,22 +306,22 @@ static void vp6_parse_vector_adjustment(vp56_context_t *s, vp56_mv_t *vect) for (comp=0; comp<2; comp++) { int i, delta = 0; - if (vp56_rac_get_prob(c, s->vector_model_dct[comp])) { + if (vp56_rac_get_prob(c, model->vector_dct[comp])) { static const uint8_t prob_order[] = {0, 1, 2, 7, 6, 5, 4}; for (i=0; ivector_model_fdv[comp][j])<vector_fdv[comp][j])<vector_model_fdv[comp][3])<<3; + delta |= vp56_rac_get_prob(c, model->vector_fdv[comp][3])<<3; else delta |= 8; } else { delta = vp56_rac_get_tree(c, vp56_pva_tree, - s->vector_model_pdv[comp]); + model->vector_pdv[comp]); } - if (delta && vp56_rac_get_prob(c, s->vector_model_sig[comp])) + if (delta && vp56_rac_get_prob(c, model->vector_sig[comp])) delta = -delta; if (!comp) @@ -276,11 +331,83 @@ static void vp6_parse_vector_adjustment(vp56_context_t *s, vp56_mv_t *vect) } } +/** + * Read number of consecutive blocks with null DC or AC. + * This value is < 74. + */ +static unsigned vp6_get_nb_null(vp56_context_t *s) +{ + unsigned val = get_bits(&s->gb, 2); + if (val == 2) + val += get_bits(&s->gb, 2); + else if (val == 3) { + val = get_bits1(&s->gb) << 2; + val = 6+val + get_bits(&s->gb, 2+val); + } + return val; +} + +static void vp6_parse_coeff_huffman(vp56_context_t *s) +{ + vp56_model_t *model = s->modelp; + uint8_t *permute = s->scantable.permutated; + VLC *vlc_coeff; + int coeff, sign, coeff_idx; + int b, cg, idx; + int pt = 0; /* plane type (0 for Y, 1 for U or V) */ + + for (b=0; b<6; b++) { + int ct = 0; /* code type */ + if (b > 3) pt = 1; + vlc_coeff = &s->dccv_vlc[pt]; + + for (coeff_idx=0; coeff_idx<64; ) { + int run = 1; + if (coeff_idx<2 && s->nb_null[coeff_idx][pt]) { + s->nb_null[coeff_idx][pt]--; + if (coeff_idx) + break; + } else { + coeff = get_vlc2(&s->gb, vlc_coeff->table, 9, 3); + if (coeff == 0) { + if (coeff_idx) { + int pt = (coeff_idx >= 6); + run += get_vlc2(&s->gb, s->runv_vlc[pt].table, 9, 3); + if (run >= 9) + run += get_bits(&s->gb, 6); + } else + s->nb_null[0][pt] = vp6_get_nb_null(s); + ct = 0; + } else if (coeff == 11) { /* end of block */ + if (coeff_idx == 1) /* first AC coeff ? */ + s->nb_null[1][pt] = vp6_get_nb_null(s); + break; + } else { + int coeff2 = vp56_coeff_bias[coeff]; + if (coeff > 4) + coeff2 += get_bits(&s->gb, coeff <= 9 ? coeff - 4 : 11); + ct = 1 + (coeff2 > 1); + sign = get_bits1(&s->gb); + coeff2 = (coeff2 ^ -sign) + sign; + if (coeff_idx) + coeff2 *= s->dequant_ac; + idx = model->coeff_index_to_pos[coeff_idx]; + s->block_coeff[b][permute[idx]] = coeff2; + } + } + coeff_idx+=run; + cg = FFMIN(vp6_coeff_groups[coeff_idx], 3); + vlc_coeff = &s->ract_vlc[pt][ct][cg]; + } + } +} + static void vp6_parse_coeff(vp56_context_t *s) { vp56_range_coder_t *c = s->ccp; + vp56_model_t *model = s->modelp; uint8_t *permute = s->scantable.permutated; - uint8_t *model, *model2, *model3; + uint8_t *model1, *model2, *model3; int coeff, sign, coeff_idx; int b, i, cg, idx, ctx; int pt = 0; /* plane type (0 for Y, 1 for U or V) */ @@ -293,26 +420,21 @@ static void vp6_parse_coeff(vp56_context_t *s) ctx = s->left_block[vp56_b6to4[b]].not_null_dc + s->above_blocks[s->above_block_idx[b]].not_null_dc; - model = s->coeff_model_dccv[pt]; - model2 = s->coeff_model_dcct[pt][ctx]; + model1 = model->coeff_dccv[pt]; + model2 = model->coeff_dcct[pt][ctx]; for (coeff_idx=0; coeff_idx<64; ) { if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob(c, model2[0])) { /* parse a coeff */ - if (coeff_idx == 0) { - s->left_block[vp56_b6to4[b]].not_null_dc = 1; - s->above_blocks[s->above_block_idx[b]].not_null_dc = 1; - } - if (vp56_rac_get_prob(c, model2[2])) { if (vp56_rac_get_prob(c, model2[3])) { - idx = vp56_rac_get_tree(c, vp56_pc_tree, model); - coeff = vp56_coeff_bias[idx]; + idx = vp56_rac_get_tree(c, vp56_pc_tree, model1); + coeff = vp56_coeff_bias[idx+5]; for (i=vp56_coeff_bit_length[idx]; i>=0; i--) coeff += vp56_rac_get_prob(c, vp56_coeff_parse_table[idx][i]) << i; } else { if (vp56_rac_get_prob(c, model2[4])) - coeff = 3 + vp56_rac_get_prob(c, model[5]); + coeff = 3 + vp56_rac_get_prob(c, model1[5]); else coeff = 2; } @@ -325,20 +447,17 @@ static void vp6_parse_coeff(vp56_context_t *s) coeff = (coeff ^ -sign) + sign; if (coeff_idx) coeff *= s->dequant_ac; - idx = s->coeff_index_to_pos[coeff_idx]; + idx = model->coeff_index_to_pos[coeff_idx]; s->block_coeff[b][permute[idx]] = coeff; run = 1; } else { /* parse a run */ ct = 0; - if (coeff_idx == 0) { - s->left_block[vp56_b6to4[b]].not_null_dc = 0; - s->above_blocks[s->above_block_idx[b]].not_null_dc = 0; - } else { + if (coeff_idx > 0) { if (!vp56_rac_get_prob(c, model2[1])) break; - model3 = s->coeff_model_runv[coeff_idx >= 6]; + model3 = model->coeff_runv[coeff_idx >= 6]; run = vp56_rac_get_tree(c, vp6_pcr_tree, model3); if (!run) for (run=9, i=0; i<6; i++) @@ -347,8 +466,11 @@ static void vp6_parse_coeff(vp56_context_t *s) } cg = vp6_coeff_groups[coeff_idx+=run]; - model = model2 = s->coeff_model_ract[pt][ct][cg]; + model1 = model2 = model->coeff_ract[pt][ct][cg]; } + + s->left_block[vp56_b6to4[b]].not_null_dc = + s->above_blocks[s->above_block_idx[b]].not_null_dc = !!s->block_coeff[b][0]; } } @@ -380,14 +502,6 @@ static int vp6_block_variance(uint8_t *src, int stride) return (16*square_sum - sum*sum) >> 8; } -static void vp6_filter_hv2(vp56_context_t *s, uint8_t *dst, uint8_t *src, - int stride, int delta, int16_t weight) -{ - s->dsp.put_pixels_tab[1][0](dst, src, stride, 8); - s->dsp.biweight_h264_pixels_tab[3](dst, src+delta, stride, 2, - 8-weight, weight, 0); -} - static void vp6_filter_hv4(uint8_t *dst, uint8_t *src, int stride, int delta, const int16_t *weights) { @@ -409,18 +523,8 @@ static void vp6_filter_diag2(vp56_context_t *s, uint8_t *dst, uint8_t *src, int stride, int h_weight, int v_weight) { uint8_t *tmp = s->edge_emu_buffer+16; - int x, xmax; - - s->dsp.put_pixels_tab[1][0](tmp, src, stride, 8); - s->dsp.biweight_h264_pixels_tab[3](tmp, src+1, stride, 2, - 8-h_weight, h_weight, 0); - /* we need a 8x9 block to do vertical filter, so compute one more line */ - for (x=8*stride, xmax=x+8; x> 3; - - s->dsp.put_pixels_tab[1][0](dst, tmp, stride, 8); - s->dsp.biweight_h264_pixels_tab[3](dst, tmp+stride, stride, 2, - 8-v_weight, v_weight, 0); + s->dsp.put_h264_chroma_pixels_tab[0](tmp, src, stride, 9, h_weight, 0); + s->dsp.put_h264_chroma_pixels_tab[0](dst, tmp, stride, 8, 0, v_weight); } static void vp6_filter_diag4(uint8_t *dst, uint8_t *src, int stride, @@ -492,24 +596,16 @@ static void vp6_filter(vp56_context_t *s, uint8_t *dst, uint8_t *src, } else if (!x8) { /* above or below combine */ vp6_filter_hv4(dst, src+offset1, stride, stride, vp6_block_copy_filter[select][y8]); - } else if ((mv.x^mv.y) >> 31) { /* lower-left or upper-right combine */ - vp6_filter_diag4(dst, src+offset1-1, stride, - vp6_block_copy_filter[select][x8], - vp6_block_copy_filter[select][y8]); - } else { /* lower-right or upper-left combine */ - vp6_filter_diag4(dst, src+offset1, stride, + } else { + vp6_filter_diag4(dst, src+offset1 + ((mv.x^mv.y)>>31), stride, vp6_block_copy_filter[select][x8], vp6_block_copy_filter[select][y8]); } } else { - if (!y8) { /* left or right combine */ - vp6_filter_hv2(s, dst, src+offset1, stride, 1, x8); - } else if (!x8) { /* above or below combine */ - vp6_filter_hv2(s, dst, src+offset1, stride, stride, y8); - } else if ((mv.x^mv.y) >> 31) { /* lower-left or upper-right combine */ - vp6_filter_diag2(s, dst, src+offset1-1, stride, x8, y8); - } else { /* lower-right or upper-left combine */ - vp6_filter_diag2(s, dst, src+offset1, stride, x8, y8); + if (!x8 || !y8) { + s->dsp.put_h264_chroma_pixels_tab[0](dst, src+offset1, stride, 8, x8, y8); + } else { + vp6_filter_diag2(s, dst, src+offset1 + ((mv.x^mv.y)>>31), stride, x8, y8); } } } @@ -518,12 +614,12 @@ static int vp6_decode_init(AVCodecContext *avctx) { vp56_context_t *s = avctx->priv_data; - vp56_init(s, avctx, avctx->codec->id == CODEC_ID_VP6); + vp56_init(avctx, avctx->codec->id == CODEC_ID_VP6, + avctx->codec->id == CODEC_ID_VP6A); s->vp56_coord_div = vp6_coord_div; s->parse_vector_adjustment = vp6_parse_vector_adjustment; s->adjust = vp6_adjust; s->filter = vp6_filter; - s->parse_coeff = vp6_parse_coeff; s->default_models_init = vp6_default_models_init; s->parse_vector_models = vp6_parse_vector_models; s->parse_coeff_models = vp6_parse_coeff_models; @@ -541,6 +637,7 @@ AVCodec vp6_decoder = { NULL, vp56_free, vp56_decode_frame, + CODEC_CAP_DR1, }; /* flash version, not flipped upside-down */ @@ -553,4 +650,18 @@ AVCodec vp6f_decoder = { NULL, vp56_free, vp56_decode_frame, + CODEC_CAP_DR1, +}; + +/* flash version, not flipped upside-down, with alpha channel */ +AVCodec vp6a_decoder = { + "vp6a", + CODEC_TYPE_VIDEO, + CODEC_ID_VP6A, + sizeof(vp56_context_t), + vp6_decode_init, + NULL, + vp56_free, + vp56_decode_frame, + CODEC_CAP_DR1, }; diff --git a/contrib/ffmpeg/libavcodec/vp6data.h b/contrib/ffmpeg/libavcodec/vp6data.h index 0545a9d66..8d4bb0b57 100644 --- a/contrib/ffmpeg/libavcodec/vp6data.h +++ b/contrib/ffmpeg/libavcodec/vp6data.h @@ -18,11 +18,11 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef VP6DATA_H -#define VP6DATA_H +#ifndef FFMPEG_VP6DATA_H +#define FFMPEG_VP6DATA_H #include "vp56data.h" @@ -297,4 +297,12 @@ static const vp56_tree_t vp6_pcr_tree[] = { static const uint8_t vp6_coord_div[] = { 4, 4, 4, 4, 8, 8 }; -#endif /* VP6DATA_H */ +static const uint8_t vp6_huff_coeff_map[] = { + 13, 14, 11, 0, 1, 15, 16, 18, 2, 17, 3, 4, 19, 20, 5, 6, 21, 22, 7, 8, 9, 10 +}; + +static const uint8_t vp6_huff_run_map[] = { + 10, 13, 11, 12, 0, 1, 2, 3, 14, 8, 15, 16, 4, 5, 6, 7 +}; + +#endif /* FFMPEG_VP6DATA_H */ diff --git a/contrib/ffmpeg/libavcodec/vqavideo.c b/contrib/ffmpeg/libavcodec/vqavideo.c index 57fe6cf44..8e70143f4 100644 --- a/contrib/ffmpeg/libavcodec/vqavideo.c +++ b/contrib/ffmpeg/libavcodec/vqavideo.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -69,7 +68,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include "dsputil.h" @@ -106,7 +104,7 @@ typedef struct VqaContext { DSPContext dsp; AVFrame frame; - unsigned char *buf; + const unsigned char *buf; int size; uint32_t palette[PALETTE_COUNT]; @@ -133,13 +131,12 @@ typedef struct VqaContext { static int vqa_decode_init(AVCodecContext *avctx) { - VqaContext *s = (VqaContext *)avctx->priv_data; + VqaContext *s = avctx->priv_data; unsigned char *vqa_header; - int i, j, codebook_index;; + int i, j, codebook_index; s->avctx = avctx; avctx->pix_fmt = PIX_FMT_PAL8; - avctx->has_b_frames = 0; dsputil_init(&s->dsp, avctx); /* make sure the extradata made it */ @@ -205,7 +202,7 @@ static int vqa_decode_init(AVCodecContext *avctx) return; \ } -static void decode_format80(unsigned char *src, int src_size, +static void decode_format80(const unsigned char *src, int src_size, unsigned char *dest, int dest_size, int check_size) { int src_index = 0; @@ -570,9 +567,9 @@ static void vqa_decode_chunk(VqaContext *s) static int vqa_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { - VqaContext *s = (VqaContext *)avctx->priv_data; + VqaContext *s = avctx->priv_data; s->buf = buf; s->size = buf_size; @@ -600,7 +597,7 @@ static int vqa_decode_frame(AVCodecContext *avctx, static int vqa_decode_end(AVCodecContext *avctx) { - VqaContext *s = (VqaContext *)avctx->priv_data; + VqaContext *s = avctx->priv_data; av_free(s->codebook); av_free(s->next_codebook_buffer); diff --git a/contrib/ffmpeg/libavcodec/w32thread.c b/contrib/ffmpeg/libavcodec/w32thread.c index e749a64af..fbc0a581e 100644 --- a/contrib/ffmpeg/libavcodec/w32thread.c +++ b/contrib/ffmpeg/libavcodec/w32thread.c @@ -16,12 +16,10 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ //#define DEBUG #include "avcodec.h" -#include "common.h" #define WIN32_LEAN_AND_MEAN #include @@ -38,7 +36,7 @@ typedef struct ThreadContext{ }ThreadContext; -static unsigned __stdcall thread_func(void *v){ +static unsigned __stdcall attribute_align_arg thread_func(void *v){ ThreadContext *c= v; for(;;){ @@ -57,8 +55,8 @@ static unsigned __stdcall thread_func(void *v){ } /** - * free what has been allocated by avcodec_thread_init(). - * must be called after decoding has finished, especially dont call while avcodec_thread_execute() is running + * Free what has been allocated by avcodec_thread_init(). + * Must be called after decoding has finished, especially do not call while avcodec_thread_execute() is running. */ void avcodec_thread_free(AVCodecContext *s){ ThreadContext *c= s->thread_opaque; diff --git a/contrib/ffmpeg/libavcodec/wavpack.c b/contrib/ffmpeg/libavcodec/wavpack.c index e79d4a570..025898da8 100644 --- a/contrib/ffmpeg/libavcodec/wavpack.c +++ b/contrib/ffmpeg/libavcodec/wavpack.c @@ -21,13 +21,15 @@ #define ALT_BITSTREAM_READER_LE #include "avcodec.h" #include "bitstream.h" +#include "unary.h" /** * @file wavpack.c * WavPack lossless audio decoder */ -#define WV_JOINT 0x0010 +#define WV_JOINT_STEREO 0x00000010 +#define WV_FALSE_STEREO 0x40000000 enum WP_ID_Flags{ WP_IDF_MASK = 0x1F, @@ -66,7 +68,7 @@ typedef struct Decorr { typedef struct WavpackContext { AVCodecContext *avctx; - int stereo; + int stereo, stereo_in; int joint; uint32_t CRC; GetBitContext gb; @@ -76,6 +78,7 @@ typedef struct WavpackContext { int terms; Decorr decorr[MAX_TERMS]; int zero, one, zeroes; + int and, or, shift; } WavpackContext; // exponent table copied from WavPack source @@ -113,12 +116,6 @@ static av_always_inline int wp_exp2(int16_t val) return neg ? -res : res; } -static inline int get_unary(GetBitContext *gb){ - int r=0; - while(get_bits1(gb) && r<33)r++; - return r; -} - // macros for manipulating median values #define GET_MED(n) ((median[n] >> 4) + 1) #define DEC_MED(n) median[n] -= ((median[n] + (128>>n) - 2) / (128>>n)) * 2 @@ -164,7 +161,7 @@ static int wv_get_value(WavpackContext *ctx, GetBitContext *gb, int *median, int if(ctx->zeroes) return 0; }else{ - t = get_unary(gb); + t = get_unary_0_33(gb); if(t >= 2) t = get_bits(gb, t - 1) | (1 << (t-1)); ctx->zeroes = t; if(ctx->zeroes){ @@ -183,13 +180,13 @@ static int wv_get_value(WavpackContext *ctx, GetBitContext *gb, int *median, int t = 0; ctx->zero = 0; }else{ - t = get_unary(gb); + t = get_unary_0_33(gb); if(get_bits_count(gb) >= ctx->data_size){ *last = 1; return 0; } if(t == 16) { - t2 = get_unary(gb); + t2 = get_unary_0_33(gb); if(t2 < 2) t += t2; else t += get_bits(gb, t2 - 1) | (1 << (t2 - 1)); } @@ -235,7 +232,7 @@ static int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, int16_t *dst) { int i, j, count = 0; int last, t; - int A, B, L, L2, R, R2; + int A, B, L, L2, R, R2, bit; int pos = 0; uint32_t crc = 0xFFFFFFFF; @@ -299,9 +296,10 @@ static int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, int16_t *dst) if(s->joint) L += (R -= (L >> 1)); crc = (crc * 3 + L) * 3 + R; - *dst++ = L; - *dst++ = R; - + bit = (L & s->and) | s->or; + *dst++ = ((L + bit) << s->shift) - bit; + bit = (R & s->and) | s->or; + *dst++ = ((R + bit) << s->shift) - bit; count++; }while(!last && count < s->samples); @@ -316,7 +314,7 @@ static int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, int16_t *dst) { int i, j, count = 0; int last, t; - int A, S, T; + int A, S, T, bit; int pos = 0; uint32_t crc = 0xFFFFFFFF; @@ -344,7 +342,8 @@ static int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, int16_t *dst) } pos = (pos + 1) & 7; crc = crc * 3 + S; - *dst++ = S; + bit = (S & s->and) | s->or; + *dst++ = ((S + bit) << s->shift) - bit; count++; }while(!last && count < s->samples); @@ -365,22 +364,15 @@ static int wavpack_decode_init(AVCodecContext *avctx) return 0; } -static int wavpack_decode_close(AVCodecContext *avctx) -{ -// WavpackContext *s = avctx->priv_data; - - return 0; -} - static int wavpack_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { WavpackContext *s = avctx->priv_data; int16_t *samples = data; int samplecount; int got_terms = 0, got_weights = 0, got_samples = 0, got_entropy = 0, got_bs = 0; - uint8_t* buf_end = buf + buf_size; + const uint8_t* buf_end = buf + buf_size; int i, j, id, size, ssize, weights, t; if (buf_size == 0){ @@ -389,6 +381,8 @@ static int wavpack_decode_frame(AVCodecContext *avctx, } memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr)); + memset(s->median, 0, sizeof(s->median)); + s->and = s->or = s->shift = 0; s->samples = AV_RL32(buf); buf += 4; if(!s->samples){ @@ -400,7 +394,8 @@ static int wavpack_decode_frame(AVCodecContext *avctx, av_log(avctx, AV_LOG_ERROR, "Packet size is too big to be handled in lavc!\n"); return -1; } - s->joint = AV_RL32(buf) & WV_JOINT; buf += 4; + s->stereo_in = (AV_RL32(buf) & WV_FALSE_STEREO) ? 0 : s->stereo; + s->joint = AV_RL32(buf) & WV_JOINT_STEREO; buf += 4; s->CRC = AV_RL32(buf); buf += 4; // parse metadata blocks while(buf < buf_end){ @@ -445,7 +440,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx, av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n"); continue; } - weights = size >> s->stereo; + weights = size >> s->stereo_in; if(weights > MAX_TERMS || weights > s->terms){ av_log(avctx, AV_LOG_ERROR, "Too many decorrelation weights\n"); buf += ssize; @@ -456,7 +451,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx, s->decorr[s->terms - i - 1].weightA = t << 3; if(s->decorr[s->terms - i - 1].weightA > 0) s->decorr[s->terms - i - 1].weightA += (s->decorr[s->terms - i - 1].weightA + 64) >> 7; - if(s->stereo){ + if(s->stereo_in){ t = (int8_t)(*buf++); s->decorr[s->terms - i - 1].weightB = t << 3; if(s->decorr[s->terms - i - 1].weightB > 0) @@ -475,7 +470,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx, if(s->decorr[i].value > 8){ s->decorr[i].samplesA[0] = wp_exp2(AV_RL16(buf)); buf += 2; s->decorr[i].samplesA[1] = wp_exp2(AV_RL16(buf)); buf += 2; - if(s->stereo){ + if(s->stereo_in){ s->decorr[i].samplesB[0] = wp_exp2(AV_RL16(buf)); buf += 2; s->decorr[i].samplesB[1] = wp_exp2(AV_RL16(buf)); buf += 2; t += 4; @@ -488,27 +483,44 @@ static int wavpack_decode_frame(AVCodecContext *avctx, }else{ for(j = 0; j < s->decorr[i].value; j++){ s->decorr[i].samplesA[j] = wp_exp2(AV_RL16(buf)); buf += 2; - if(s->stereo){ + if(s->stereo_in){ s->decorr[i].samplesB[j] = wp_exp2(AV_RL16(buf)); buf += 2; } } - t += s->decorr[i].value * 2 * avctx->channels; + t += s->decorr[i].value * 2 * (s->stereo_in + 1); } } got_samples = 1; break; case WP_ID_ENTROPY: - if(size != 6 * avctx->channels){ - av_log(avctx, AV_LOG_ERROR, "Entropy vars size should be %i, got %i", 6 * avctx->channels, size); + if(size != 6 * (s->stereo_in + 1)){ + av_log(avctx, AV_LOG_ERROR, "Entropy vars size should be %i, got %i", 6 * (s->stereo_in + 1), size); buf += ssize; continue; } - for(i = 0; i < 3 * avctx->channels; i++){ + for(i = 0; i < 3 * (s->stereo_in + 1); i++){ s->median[i] = wp_exp2(AV_RL16(buf)); buf += 2; } got_entropy = 1; break; + case WP_ID_INT32INFO: + if(size != 4 || *buf){ + av_log(avctx, AV_LOG_ERROR, "Invalid INT32INFO, size = %i, sent_bits = %i\n", size, *buf); + buf += ssize; + continue; + } + if(buf[1]) + s->shift = buf[1]; + else if(buf[2]){ + s->and = s->or = 1; + s->shift = buf[2]; + }else if(buf[3]){ + s->and = 1; + s->shift = buf[3]; + } + buf += 4; + break; case WP_ID_DATA: init_get_bits(&s->gb, buf, size * 8); s->data_size = size * 8; @@ -541,10 +553,21 @@ static int wavpack_decode_frame(AVCodecContext *avctx, return -1; } - if(s->stereo) + if(s->stereo_in) samplecount = wv_unpack_stereo(s, &s->gb, samples); - else + else{ samplecount = wv_unpack_mono(s, &s->gb, samples); + if(s->stereo){ + int16_t *dst = samples + samplecount * 2; + int16_t *src = samples + samplecount; + int cnt = samplecount; + while(cnt--){ + *--dst = *--src; + *--dst = *src; + } + samplecount *= 2; + } + } *data_size = samplecount * 2; return buf_size; @@ -557,6 +580,6 @@ AVCodec wavpack_decoder = { sizeof(WavpackContext), wavpack_decode_init, NULL, - wavpack_decode_close, + NULL, wavpack_decode_frame, }; diff --git a/contrib/ffmpeg/libavcodec/wma.c b/contrib/ffmpeg/libavcodec/wma.c index 2241a07a0..e257aed31 100644 --- a/contrib/ffmpeg/libavcodec/wma.c +++ b/contrib/ffmpeg/libavcodec/wma.c @@ -72,6 +72,11 @@ int ff_wma_init(AVCodecContext * avctx, int flags2) int sample_rate1; int coef_vlc_table; + if( avctx->sample_rate<=0 || avctx->sample_rate>50000 + || avctx->channels<=0 || avctx->channels>8 + || avctx->bit_rate<=0) + return -1; + s->sample_rate = avctx->sample_rate; s->nb_channels = avctx->channels; s->bit_rate = avctx->bit_rate; @@ -380,6 +385,7 @@ int ff_wma_end(AVCodecContext *avctx) free_vlc(&s->coef_vlc[i]); av_free(s->run_table[i]); av_free(s->level_table[i]); + av_free(s->int_table[i]); } return 0; diff --git a/contrib/ffmpeg/libavcodec/wma.h b/contrib/ffmpeg/libavcodec/wma.h index cd4daa7e5..88b5dbf9e 100644 --- a/contrib/ffmpeg/libavcodec/wma.h +++ b/contrib/ffmpeg/libavcodec/wma.h @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef WMA_H -#define WMA_H +#ifndef FFMPEG_WMA_H +#define FFMPEG_WMA_H #include "bitstream.h" #include "dsputil.h" @@ -92,7 +92,7 @@ typedef struct WMACodecContext { uint16_t *run_table[2]; uint16_t *level_table[2]; uint16_t *int_table[2]; - CoefVLCTable *coef_vlcs[2]; + const CoefVLCTable *coef_vlcs[2]; /* frame info */ int frame_len; ///< frame length in samples int frame_len_bits; ///< frame_len = 1 << frame_len_bits @@ -107,6 +107,7 @@ typedef struct WMACodecContext { int block_pos; ///< current position in frame uint8_t ms_stereo; ///< true if mid/side stereo mode uint8_t channel_coded[MAX_CHANNELS]; ///< true if channel is coded + int exponents_bsize[MAX_CHANNELS]; ///< log2 ratio frame/exp. length DECLARE_ALIGNED_16(float, exponents[MAX_CHANNELS][BLOCK_MAX_SIZE]); float max_exponent[MAX_CHANNELS]; int16_t coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE]; @@ -146,4 +147,4 @@ int ff_wma_init(AVCodecContext * avctx, int flags2); int ff_wma_total_gain_to_bits(int total_gain); int ff_wma_end(AVCodecContext *avctx); -#endif +#endif /* FFMPEG_WMA_H */ diff --git a/contrib/ffmpeg/libavcodec/wmadata.h b/contrib/ffmpeg/libavcodec/wmadata.h index 31ed89bf0..aa2a120a2 100644 --- a/contrib/ffmpeg/libavcodec/wmadata.h +++ b/contrib/ffmpeg/libavcodec/wmadata.h @@ -24,6 +24,12 @@ * Various WMA tables. */ +#ifndef FFMPEG_WMADATA_H +#define FFMPEG_WMADATA_H + +#include +#include "wma.h" + static const uint16_t wma_critical_freqs[25] = { 100, 200, 300, 400, 510, 630, 770, 920, 1080, 1270, 1480, 1720, 2000, 2320, 2700, 3150, @@ -1431,3 +1437,5 @@ static const CoefVLCTable coef_vlcs[6] = { sizeof(coef5_huffbits), sizeof(levels5)/2, coef5_huffcodes, coef5_huffbits, levels5, }, }; + +#endif /* FFMPEG_WMADATA_H */ diff --git a/contrib/ffmpeg/libavcodec/wmadec.c b/contrib/ffmpeg/libavcodec/wmadec.c index ef3cc7a33..9e1958419 100644 --- a/contrib/ffmpeg/libavcodec/wmadec.c +++ b/contrib/ffmpeg/libavcodec/wmadec.c @@ -48,7 +48,7 @@ static void wma_lsp_to_curve_init(WMACodecContext *s, int frame_len); #ifdef TRACE -static void dump_shorts(WMADecodeContext *s, const char *name, const short *tab, int n) +static void dump_shorts(WMACodecContext *s, const char *name, const short *tab, int n) { int i; @@ -62,7 +62,7 @@ static void dump_shorts(WMADecodeContext *s, const char *name, const short *tab, } } -static void dump_floats(WMADecodeContext *s, const char *name, int prec, const float *tab, int n) +static void dump_floats(WMACodecContext *s, const char *name, int prec, const float *tab, int n) { int i; @@ -92,12 +92,11 @@ static int wma_decode_init(AVCodecContext * avctx) flags2 = 0; extradata = avctx->extradata; if (avctx->codec->id == CODEC_ID_WMAV1 && avctx->extradata_size >= 4) { - flags1 = extradata[0] | (extradata[1] << 8); - flags2 = extradata[2] | (extradata[3] << 8); + flags1 = AV_RL16(extradata); + flags2 = AV_RL16(extradata+2); } else if (avctx->codec->id == CODEC_ID_WMAV2 && avctx->extradata_size >= 6) { - flags1 = extradata[0] | (extradata[1] << 8) | - (extradata[2] << 16) | (extradata[3] << 24); - flags2 = extradata[4] | (extradata[5] << 8); + flags1 = AV_RL32(extradata); + flags2 = AV_RL16(extradata+4); } // for(i=0; iextradata_size; i++) // av_log(NULL, AV_LOG_ERROR, "%02X ", extradata[i]); @@ -106,7 +105,8 @@ static int wma_decode_init(AVCodecContext * avctx) s->use_bit_reservoir = flags2 & 0x0002; s->use_variable_block_len = flags2 & 0x0004; - ff_wma_init(avctx, flags2); + if(ff_wma_init(avctx, flags2)<0) + return -1; /* init MDCT */ for(i = 0; i < s->nb_block_sizes; i++) @@ -129,35 +129,6 @@ static int wma_decode_init(AVCodecContext * avctx) return 0; } -/** - * interpolate values for a bigger or smaller block. The block must - * have multiple sizes - */ -static void interpolate_array(float *scale, int old_size, int new_size) -{ - int i, j, jincr, k; - float v; - - if (new_size > old_size) { - jincr = new_size / old_size; - j = new_size; - for(i = old_size - 1; i >=0; i--) { - v = scale[i]; - k = jincr; - do { - scale[--j] = v; - } while (--k); - } - } else if (new_size < old_size) { - j = 0; - jincr = old_size / new_size; - for(i = 0; i < new_size; i++) { - scale[i] = scale[j]; - j += jincr; - } - } -} - /** * compute x^-0.25 with an exponent and mantissa table. We use linear * interpolation to reduce the mantissa table size at a small speed @@ -378,7 +349,7 @@ static void wma_window(WMACodecContext *s, float *out) static int wma_decode_block(WMACodecContext *s) { int n, v, a, ch, code, bsize; - int coef_nb_bits, total_gain, parse_exponents; + int coef_nb_bits, total_gain; int nb_coefs[MAX_CHANNELS]; float mdct_norm; @@ -422,11 +393,11 @@ static int wma_decode_block(WMACodecContext *s) return -1; if (s->nb_channels == 2) { - s->ms_stereo = get_bits(&s->gb, 1); + s->ms_stereo = get_bits1(&s->gb); } v = 0; for(ch = 0; ch < s->nb_channels; ch++) { - a = get_bits(&s->gb, 1); + a = get_bits1(&s->gb); s->channel_coded[ch] = a; v |= a; } @@ -462,7 +433,7 @@ static int wma_decode_block(WMACodecContext *s) int i, n, a; n = s->exponent_high_sizes[bsize]; for(i=0;igb, 1); + a = get_bits1(&s->gb); s->high_band_coded[ch][i] = a; /* if noise coding, the coefficients are not transmitted */ if (a) @@ -493,13 +464,9 @@ static int wma_decode_block(WMACodecContext *s) } } - /* exposant can be interpolated in short blocks. */ - parse_exponents = 1; - if (s->block_len_bits != s->frame_len_bits) { - parse_exponents = get_bits(&s->gb, 1); - } - - if (parse_exponents) { + /* exponents can be reused in short blocks. */ + if ((s->block_len_bits == s->frame_len_bits) || + get_bits1(&s->gb)) { for(ch = 0; ch < s->nb_channels; ch++) { if (s->channel_coded[ch]) { if (s->use_exp_vlc) { @@ -508,13 +475,7 @@ static int wma_decode_block(WMACodecContext *s) } else { decode_exp_lsp(s, ch); } - } - } - } else { - for(ch = 0; ch < s->nb_channels; ch++) { - if (s->channel_coded[ch]) { - interpolate_array(s->exponents[ch], 1 << s->prev_block_len_bits, - s->block_len); + s->exponents_bsize[ch] = bsize; } } } @@ -555,7 +516,7 @@ static int wma_decode_block(WMACodecContext *s) run = run_table[code]; level = level_table[code]; } - sign = get_bits(&s->gb, 1); + sign = get_bits1(&s->gb); if (!sign) level = -level; ptr += run; @@ -588,12 +549,13 @@ static int wma_decode_block(WMACodecContext *s) for(ch = 0; ch < s->nb_channels; ch++) { if (s->channel_coded[ch]) { int16_t *coefs1; - float *coefs, *exponents, mult, mult1, noise, *exp_ptr; - int i, j, n, n1, last_high_band; + float *coefs, *exponents, mult, mult1, noise; + int i, j, n, n1, last_high_band, esize; float exp_power[HIGH_BAND_MAX_SIZE]; coefs1 = s->coefs1[ch]; exponents = s->exponents[ch]; + esize = s->exponents_bsize[ch]; mult = pow(10, total_gain * 0.05) / s->max_exponent[ch]; mult *= mdct_norm; coefs = s->coefs[ch]; @@ -601,16 +563,16 @@ static int wma_decode_block(WMACodecContext *s) mult1 = mult; /* very low freqs : noise */ for(i = 0;i < s->coefs_start; i++) { - *coefs++ = s->noise_table[s->noise_index] * (*exponents++) * mult1; + *coefs++ = s->noise_table[s->noise_index] * + exponents[i<>esize] * mult1; s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1); } n1 = s->exponent_high_sizes[bsize]; /* compute power of high bands */ - exp_ptr = exponents + - s->high_band_start[bsize] - - s->coefs_start; + exponents = s->exponents[ch] + + (s->high_band_start[bsize]<exponent_high_bands[s->frame_len_bits - @@ -619,17 +581,18 @@ static int wma_decode_block(WMACodecContext *s) float e2, v; e2 = 0; for(i = 0;i < n; i++) { - v = exp_ptr[i]; + v = exponents[i<>esize]; e2 += v * v; } exp_power[j] = e2 / n; last_high_band = j; tprintf(s->avctx, "%d: power=%f (%d)\n", j, exp_power[j], n); } - exp_ptr += n; + exponents += n<exponents[ch] + (s->coefs_start<high_band_start[bsize] - @@ -648,21 +611,25 @@ static int wma_decode_block(WMACodecContext *s) for(i = 0;i < n; i++) { noise = s->noise_table[s->noise_index]; s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1); - *coefs++ = (*exponents++) * noise * mult1; + *coefs++ = noise * + exponents[i<>esize] * mult1; } + exponents += n<noise_table[s->noise_index]; s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1); - *coefs++ = ((*coefs1++) + noise) * (*exponents++) * mult; + *coefs++ = ((*coefs1++) + noise) * + exponents[i<>esize] * mult; } + exponents += n<block_len - s->coefs_end[bsize]; - mult1 = mult * exponents[-1]; + mult1 = mult * exponents[((-1<>esize]; for(i = 0; i < n; i++) { *coefs++ = s->noise_table[s->noise_index] * mult1; s->noise_index = (s->noise_index + 1) & (NOISE_TAB_SIZE - 1); @@ -673,7 +640,7 @@ static int wma_decode_block(WMACodecContext *s) *coefs++ = 0.0; n = nb_coefs[ch]; for(i = 0;i < n; i++) { - *coefs++ = coefs1[i] * exponents[i] * mult; + *coefs++ = coefs1[i] * exponents[i<>esize] * mult; } n = s->block_len - s->coefs_end[bsize]; for(i = 0;i < n; i++) @@ -745,7 +712,7 @@ static int wma_decode_block(WMACodecContext *s) /* decode a frame of frame_len samples */ static int wma_decode_frame(WMACodecContext *s, int16_t *samples) { - int ret, i, n, a, ch, incr; + int ret, i, n, ch, incr; int16_t *ptr; float *iptr; @@ -772,12 +739,7 @@ static int wma_decode_frame(WMACodecContext *s, int16_t *samples) iptr = s->frame_out[ch]; for(i=0;i 32767) - a = 32767; - else if (a < -32768) - a = -32768; - *ptr = a; + *ptr = av_clip_int16(lrintf(*iptr++)); ptr += incr; } /* prepare for next block */ @@ -793,7 +755,7 @@ static int wma_decode_frame(WMACodecContext *s, int16_t *samples) static int wma_decode_superframe(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { WMACodecContext *s = avctx->priv_data; int nb_frames, bit_offset, i, pos, len; @@ -806,6 +768,9 @@ static int wma_decode_superframe(AVCodecContext *avctx, s->last_superframe_len = 0; return 0; } + if (buf_size < s->block_align) + return 0; + buf_size = s->block_align; samples = data; @@ -813,7 +778,7 @@ static int wma_decode_superframe(AVCodecContext *avctx, if (s->use_bit_reservoir) { /* read super frame header */ - get_bits(&s->gb, 4); /* super frame index */ + skip_bits(&s->gb, 4); /* super frame index */ nb_frames = get_bits(&s->gb, 4) - 1; bit_offset = get_bits(&s->gb, s->byte_offset_bits + 3); diff --git a/contrib/ffmpeg/libavcodec/wmaenc.c b/contrib/ffmpeg/libavcodec/wmaenc.c index e902a6aff..f2feee2f6 100644 --- a/contrib/ffmpeg/libavcodec/wmaenc.c +++ b/contrib/ffmpeg/libavcodec/wmaenc.c @@ -45,19 +45,13 @@ static int encode_init(AVCodecContext * avctx){ if (avctx->codec->id == CODEC_ID_WMAV1) { extradata= av_malloc(4); avctx->extradata_size= 4; - extradata[0] = flags1; - extradata[1] = flags1>>8; - extradata[2] = flags2; - extradata[3] = flags2>>8; + AV_WL16(extradata, flags1); + AV_WL16(extradata+2, flags2); } else if (avctx->codec->id == CODEC_ID_WMAV2) { extradata= av_mallocz(10); avctx->extradata_size= 10; - extradata[0] = flags1; - extradata[1] = flags1>>8; - extradata[2] = flags1>>16; - extradata[3] = flags1>>24; - extradata[4] = flags2; - extradata[5] = flags2>>8; + AV_WL32(extradata, flags1); + AV_WL16(extradata+4, flags2); }else assert(0); avctx->extradata= extradata; @@ -100,7 +94,7 @@ static void apply_window_and_mdct(AVCodecContext * avctx, signed short * audio, } //FIXME use for decoding too -static void init_exp(WMACodecContext *s, int ch, int *exp_param){ +static void init_exp(WMACodecContext *s, int ch, const int *exp_param){ int n; const uint16_t *ptr; float v, *q, max_scale, *q_end; @@ -184,7 +178,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE], } for(ch = 0; ch < s->nb_channels; ch++) { - if (s->channel_coded[ch]= 1) { //FIXME + if ((s->channel_coded[ch]= 1)) { //FIXME only set channel_coded when needed, instead of always init_exp(s, ch, fixed_exp); } } @@ -330,7 +324,7 @@ static int encode_superframe(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ WMACodecContext *s = avctx->priv_data; short *samples = data; - int i, total_gain, best; + int i, total_gain; s->block_len_bits= s->frame_len_bits; //required by non variable block len s->block_len = 1 << s->block_len_bits; diff --git a/contrib/ffmpeg/libavcodec/wmv2.c b/contrib/ffmpeg/libavcodec/wmv2.c index d57eaa5e4..39efea29c 100644 --- a/contrib/ffmpeg/libavcodec/wmv2.c +++ b/contrib/ffmpeg/libavcodec/wmv2.c @@ -16,576 +16,22 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -/** - * @file wmv2.c - * wmv2 codec. */ +#include "avcodec.h" +#include "mpegvideo.h" +#include "msmpeg4data.h" #include "simple_idct.h" - -#define SKIP_TYPE_NONE 0 -#define SKIP_TYPE_MPEG 1 -#define SKIP_TYPE_ROW 2 -#define SKIP_TYPE_COL 3 +#include "wmv2.h" -typedef struct Wmv2Context{ - MpegEncContext s; - int j_type_bit; - int j_type; - int flag3; - int flag63; - int abt_flag; - int abt_type; - int abt_type_table[6]; - int per_mb_abt; - int per_block_abt; - int mspel_bit; - int cbp_table_index; - int top_left_mv_flag; - int per_mb_rl_bit; - int skip_type; - int hshift; - - ScanTable abt_scantable[2]; - DECLARE_ALIGNED_8(DCTELEM, abt_block2[6][64]); -}Wmv2Context; - -static void wmv2_common_init(Wmv2Context * w){ +void ff_wmv2_common_init(Wmv2Context * w){ MpegEncContext * const s= &w->s; ff_init_scantable(s->dsp.idct_permutation, &w->abt_scantable[0], wmv2_scantableA); ff_init_scantable(s->dsp.idct_permutation, &w->abt_scantable[1], wmv2_scantableB); } -#ifdef CONFIG_ENCODERS - -static int encode_ext_header(Wmv2Context *w){ - MpegEncContext * const s= &w->s; - PutBitContext pb; - int code; - - init_put_bits(&pb, s->avctx->extradata, s->avctx->extradata_size); - - put_bits(&pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); //yes 29.97 -> 29 - put_bits(&pb, 11, FFMIN(s->bit_rate/1024, 2047)); - - put_bits(&pb, 1, w->mspel_bit=1); - put_bits(&pb, 1, w->flag3=1); - put_bits(&pb, 1, w->abt_flag=1); - put_bits(&pb, 1, w->j_type_bit=1); - put_bits(&pb, 1, w->top_left_mv_flag=0); - put_bits(&pb, 1, w->per_mb_rl_bit=1); - put_bits(&pb, 3, code=1); - - flush_put_bits(&pb); - - s->slice_height = s->mb_height / code; - - return 0; -} - -static int wmv2_encode_init(AVCodecContext *avctx){ - Wmv2Context * const w= avctx->priv_data; - - if(MPV_encode_init(avctx) < 0) - return -1; - - wmv2_common_init(w); - - avctx->extradata_size= 4; - avctx->extradata= av_mallocz(avctx->extradata_size + 10); - encode_ext_header(w); - - return 0; -} - -#if 0 /* unused, remove? */ -static int wmv2_encode_end(AVCodecContext *avctx){ - - if(MPV_encode_end(avctx) < 0) - return -1; - - avctx->extradata_size= 0; - av_freep(&avctx->extradata); - - return 0; -} -#endif - -int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number) -{ - Wmv2Context * const w= (Wmv2Context*)s; - - put_bits(&s->pb, 1, s->pict_type - 1); - if(s->pict_type == I_TYPE){ - put_bits(&s->pb, 7, 0); - } - put_bits(&s->pb, 5, s->qscale); - - s->dc_table_index = 1; - s->mv_table_index = 1; /* only if P frame */ -// s->use_skip_mb_code = 1; /* only if P frame */ - s->per_mb_rl_table = 0; - s->mspel= 0; - w->per_mb_abt=0; - w->abt_type=0; - w->j_type=0; - - assert(s->flipflop_rounding); - - if (s->pict_type == I_TYPE) { - assert(s->no_rounding==1); - if(w->j_type_bit) put_bits(&s->pb, 1, w->j_type); - - if(w->per_mb_rl_bit) put_bits(&s->pb, 1, s->per_mb_rl_table); - - if(!s->per_mb_rl_table){ - code012(&s->pb, s->rl_chroma_table_index); - code012(&s->pb, s->rl_table_index); - } - - put_bits(&s->pb, 1, s->dc_table_index); - - s->inter_intra_pred= 0; - }else{ - int cbp_index; - - put_bits(&s->pb, 2, SKIP_TYPE_NONE); - - code012(&s->pb, cbp_index=0); - if(s->qscale <= 10){ - int map[3]= {0,2,1}; - w->cbp_table_index= map[cbp_index]; - }else if(s->qscale <= 20){ - int map[3]= {1,0,2}; - w->cbp_table_index= map[cbp_index]; - }else{ - int map[3]= {2,1,0}; - w->cbp_table_index= map[cbp_index]; - } - - if(w->mspel_bit) put_bits(&s->pb, 1, s->mspel); - - if(w->abt_flag){ - put_bits(&s->pb, 1, w->per_mb_abt^1); - if(!w->per_mb_abt){ - code012(&s->pb, w->abt_type); - } - } - - if(w->per_mb_rl_bit) put_bits(&s->pb, 1, s->per_mb_rl_table); - - if(!s->per_mb_rl_table){ - code012(&s->pb, s->rl_table_index); - s->rl_chroma_table_index = s->rl_table_index; - } - put_bits(&s->pb, 1, s->dc_table_index); - put_bits(&s->pb, 1, s->mv_table_index); - - s->inter_intra_pred= 0;//(s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE); - } - s->esc3_level_length= 0; - s->esc3_run_length= 0; - - return 0; -} - -// nearly idential to wmv1 but thats just because we dont use the useless M$ crap features -// its duplicated here in case someone wants to add support for these carp features -void ff_wmv2_encode_mb(MpegEncContext * s, - DCTELEM block[6][64], - int motion_x, int motion_y) -{ - Wmv2Context * const w= (Wmv2Context*)s; - int cbp, coded_cbp, i; - int pred_x, pred_y; - uint8_t *coded_block; - - handle_slices(s); - - if (!s->mb_intra) { - /* compute cbp */ - cbp = 0; - for (i = 0; i < 6; i++) { - if (s->block_last_index[i] >= 0) - cbp |= 1 << (5 - i); - } - - put_bits(&s->pb, - wmv2_inter_table[w->cbp_table_index][cbp + 64][1], - wmv2_inter_table[w->cbp_table_index][cbp + 64][0]); - - /* motion vector */ - h263_pred_motion(s, 0, 0, &pred_x, &pred_y); - msmpeg4_encode_motion(s, motion_x - pred_x, - motion_y - pred_y); - } else { - /* compute cbp */ - cbp = 0; - coded_cbp = 0; - for (i = 0; i < 6; i++) { - int val, pred; - val = (s->block_last_index[i] >= 1); - cbp |= val << (5 - i); - if (i < 4) { - /* predict value for close blocks only for luma */ - pred = coded_block_pred(s, i, &coded_block); - *coded_block = val; - val = val ^ pred; - } - coded_cbp |= val << (5 - i); - } -#if 0 - if (coded_cbp) - printf("cbp=%x %x\n", cbp, coded_cbp); -#endif - - if (s->pict_type == I_TYPE) { - put_bits(&s->pb, - ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]); - } else { - put_bits(&s->pb, - wmv2_inter_table[w->cbp_table_index][cbp][1], - wmv2_inter_table[w->cbp_table_index][cbp][0]); - } - put_bits(&s->pb, 1, 0); /* no AC prediction yet */ - if(s->inter_intra_pred){ - s->h263_aic_dir=0; - put_bits(&s->pb, table_inter_intra[s->h263_aic_dir][1], table_inter_intra[s->h263_aic_dir][0]); - } - } - - for (i = 0; i < 6; i++) { - msmpeg4_encode_block(s, block[i], i); - } -} -#endif //CONFIG_ENCODERS - -static void parse_mb_skip(Wmv2Context * w){ - int mb_x, mb_y; - MpegEncContext * const s= &w->s; - uint32_t * const mb_type= s->current_picture_ptr->mb_type; - - w->skip_type= get_bits(&s->gb, 2); - switch(w->skip_type){ - case SKIP_TYPE_NONE: - for(mb_y=0; mb_ymb_height; mb_y++){ - for(mb_x=0; mb_xmb_width; mb_x++){ - mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_16x16 | MB_TYPE_L0; - } - } - break; - case SKIP_TYPE_MPEG: - for(mb_y=0; mb_ymb_height; mb_y++){ - for(mb_x=0; mb_xmb_width; mb_x++){ - mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0; - } - } - break; - case SKIP_TYPE_ROW: - for(mb_y=0; mb_ymb_height; mb_y++){ - if(get_bits1(&s->gb)){ - for(mb_x=0; mb_xmb_width; mb_x++){ - mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; - } - }else{ - for(mb_x=0; mb_xmb_width; mb_x++){ - mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0; - } - } - } - break; - case SKIP_TYPE_COL: - for(mb_x=0; mb_xmb_width; mb_x++){ - if(get_bits1(&s->gb)){ - for(mb_y=0; mb_ymb_height; mb_y++){ - mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; - } - }else{ - for(mb_y=0; mb_ymb_height; mb_y++){ - mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0; - } - } - } - break; - } -} - -static int decode_ext_header(Wmv2Context *w){ - MpegEncContext * const s= &w->s; - GetBitContext gb; - int fps; - int code; - - if(s->avctx->extradata_size<4) return -1; - - init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size*8); - - fps = get_bits(&gb, 5); - s->bit_rate = get_bits(&gb, 11)*1024; - w->mspel_bit = get_bits1(&gb); - w->flag3 = get_bits1(&gb); - w->abt_flag = get_bits1(&gb); - w->j_type_bit = get_bits1(&gb); - w->top_left_mv_flag= get_bits1(&gb); - w->per_mb_rl_bit = get_bits1(&gb); - code = get_bits(&gb, 3); - - if(code==0) return -1; - - s->slice_height = s->mb_height / code; - - if(s->avctx->debug&FF_DEBUG_PICT_INFO){ - av_log(s->avctx, AV_LOG_DEBUG, "fps:%d, br:%d, qpbit:%d, abt_flag:%d, j_type_bit:%d, tl_mv_flag:%d, mbrl_bit:%d, code:%d, flag3:%d, slices:%d\n", - fps, s->bit_rate, w->mspel_bit, w->abt_flag, w->j_type_bit, w->top_left_mv_flag, w->per_mb_rl_bit, code, w->flag3, - code); - } - return 0; -} - -int ff_wmv2_decode_picture_header(MpegEncContext * s) -{ - Wmv2Context * const w= (Wmv2Context*)s; - int code; - -#if 0 -{ -int i; -for(i=0; igb.size*8; i++) - printf("%d", get_bits1(&s->gb)); -// get_bits1(&s->gb); -printf("END\n"); -return -1; -} -#endif - if(s->picture_number==0) - decode_ext_header(w); - - s->pict_type = get_bits(&s->gb, 1) + 1; - if(s->pict_type == I_TYPE){ - code = get_bits(&s->gb, 7); - av_log(s->avctx, AV_LOG_DEBUG, "I7:%X/\n", code); - } - s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); - if(s->qscale < 0) - return -1; - - return 0; -} - -int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s) -{ - Wmv2Context * const w= (Wmv2Context*)s; - - if (s->pict_type == I_TYPE) { - if(w->j_type_bit) w->j_type= get_bits1(&s->gb); - else w->j_type= 0; //FIXME check - - if(!w->j_type){ - if(w->per_mb_rl_bit) s->per_mb_rl_table= get_bits1(&s->gb); - else s->per_mb_rl_table= 0; - - if(!s->per_mb_rl_table){ - s->rl_chroma_table_index = decode012(&s->gb); - s->rl_table_index = decode012(&s->gb); - } - - s->dc_table_index = get_bits1(&s->gb); - } - s->inter_intra_pred= 0; - s->no_rounding = 1; - if(s->avctx->debug&FF_DEBUG_PICT_INFO){ - av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d j_type:%d \n", - s->qscale, - s->rl_chroma_table_index, - s->rl_table_index, - s->dc_table_index, - s->per_mb_rl_table, - w->j_type); - } - }else{ - int cbp_index; - w->j_type=0; - - parse_mb_skip(w); - cbp_index= decode012(&s->gb); - if(s->qscale <= 10){ - int map[3]= {0,2,1}; - w->cbp_table_index= map[cbp_index]; - }else if(s->qscale <= 20){ - int map[3]= {1,0,2}; - w->cbp_table_index= map[cbp_index]; - }else{ - int map[3]= {2,1,0}; - w->cbp_table_index= map[cbp_index]; - } - - if(w->mspel_bit) s->mspel= get_bits1(&s->gb); - else s->mspel= 0; //FIXME check - - if(w->abt_flag){ - w->per_mb_abt= get_bits1(&s->gb)^1; - if(!w->per_mb_abt){ - w->abt_type= decode012(&s->gb); - } - } - - if(w->per_mb_rl_bit) s->per_mb_rl_table= get_bits1(&s->gb); - else s->per_mb_rl_table= 0; - - if(!s->per_mb_rl_table){ - s->rl_table_index = decode012(&s->gb); - s->rl_chroma_table_index = s->rl_table_index; - } - - s->dc_table_index = get_bits1(&s->gb); - s->mv_table_index = get_bits1(&s->gb); - - s->inter_intra_pred= 0;//(s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE); - s->no_rounding ^= 1; - - if(s->avctx->debug&FF_DEBUG_PICT_INFO){ - av_log(s->avctx, AV_LOG_DEBUG, "rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d mspel:%d per_mb_abt:%d abt_type:%d cbp:%d ii:%d\n", - s->rl_table_index, - s->rl_chroma_table_index, - s->dc_table_index, - s->mv_table_index, - s->per_mb_rl_table, - s->qscale, - s->mspel, - w->per_mb_abt, - w->abt_type, - w->cbp_table_index, - s->inter_intra_pred); - } - } - s->esc3_level_length= 0; - s->esc3_run_length= 0; - -s->picture_number++; //FIXME ? - - -// if(w->j_type) -// return wmv2_decode_j_picture(w); //FIXME - - if(w->j_type){ - av_log(s->avctx, AV_LOG_ERROR, "J-type picture is not supported\n"); - return -1; - } - - return 0; -} - -static inline int wmv2_decode_motion(Wmv2Context *w, int *mx_ptr, int *my_ptr){ - MpegEncContext * const s= &w->s; - int ret; - - ret= msmpeg4_decode_motion(s, mx_ptr, my_ptr); - - if(ret<0) return -1; - - if((((*mx_ptr)|(*my_ptr)) & 1) && s->mspel) - w->hshift= get_bits1(&s->gb); - else - w->hshift= 0; - -//printf("%d %d ", *mx_ptr, *my_ptr); - - return 0; -} - -static int16_t *wmv2_pred_motion(Wmv2Context *w, int *px, int *py){ - MpegEncContext * const s= &w->s; - int xy, wrap, diff, type; - int16_t *A, *B, *C, *mot_val; - - wrap = s->b8_stride; - xy = s->block_index[0]; - - mot_val = s->current_picture.motion_val[0][xy]; - - A = s->current_picture.motion_val[0][xy - 1]; - B = s->current_picture.motion_val[0][xy - wrap]; - C = s->current_picture.motion_val[0][xy + 2 - wrap]; - - if(s->mb_x && !s->first_slice_line && !s->mspel && w->top_left_mv_flag) - diff= FFMAX(FFABS(A[0] - B[0]), FFABS(A[1] - B[1])); - else - diff=0; - - if(diff >= 8) - type= get_bits1(&s->gb); - else - type= 2; - - if(type == 0){ - *px= A[0]; - *py= A[1]; - }else if(type == 1){ - *px= B[0]; - *py= B[1]; - }else{ - /* special case for first (slice) line */ - if (s->first_slice_line) { - *px = A[0]; - *py = A[1]; - } else { - *px = mid_pred(A[0], B[0], C[0]); - *py = mid_pred(A[1], B[1], C[1]); - } - } - - return mot_val; -} - -static inline int wmv2_decode_inter_block(Wmv2Context *w, DCTELEM *block, int n, int cbp){ - MpegEncContext * const s= &w->s; - static const int sub_cbp_table[3]= {2,3,1}; - int sub_cbp; - - if(!cbp){ - s->block_last_index[n] = -1; - - return 0; - } - - if(w->per_block_abt) - w->abt_type= decode012(&s->gb); -#if 0 - if(w->per_block_abt) - printf("B%d", w->abt_type); -#endif - w->abt_type_table[n]= w->abt_type; - - if(w->abt_type){ -// const uint8_t *scantable= w->abt_scantable[w->abt_type-1].permutated; - const uint8_t *scantable= w->abt_scantable[w->abt_type-1].scantable; -// const uint8_t *scantable= w->abt_type-1 ? w->abt_scantable[1].permutated : w->abt_scantable[0].scantable; - - sub_cbp= sub_cbp_table[ decode012(&s->gb) ]; -// printf("S%d", sub_cbp); - - if(sub_cbp&1){ - if (msmpeg4_decode_block(s, block, n, 1, scantable) < 0) - return -1; - } - - if(sub_cbp&2){ - if (msmpeg4_decode_block(s, w->abt_block2[n], n, 1, scantable) < 0) - return -1; - } - s->block_last_index[n] = 63; - - return 0; - }else{ - return msmpeg4_decode_block(s, block, n, 1, s->inter_scantable.permutated); - } -} - static void wmv2_add_block(Wmv2Context *w, DCTELEM *block1, uint8_t *dst, int stride, int n){ MpegEncContext * const s= &w->s; @@ -595,13 +41,13 @@ static void wmv2_add_block(Wmv2Context *w, DCTELEM *block1, uint8_t *dst, int st s->dsp.idct_add (dst, stride, block1); break; case 1: - simple_idct84_add(dst , stride, block1); - simple_idct84_add(dst + 4*stride, stride, w->abt_block2[n]); + ff_simple_idct84_add(dst , stride, block1); + ff_simple_idct84_add(dst + 4*stride, stride, w->abt_block2[n]); memset(w->abt_block2[n], 0, 64*sizeof(DCTELEM)); break; case 2: - simple_idct48_add(dst , stride, block1); - simple_idct48_add(dst + 4 , stride, w->abt_block2[n]); + ff_simple_idct48_add(dst , stride, block1); + ff_simple_idct48_add(dst + 4 , stride, w->abt_block2[n]); memset(w->abt_block2[n], 0, 64*sizeof(DCTELEM)); break; default: @@ -711,151 +157,3 @@ void ff_mspel_motion(MpegEncContext *s, } pix_op[1][dxy](dest_cr, ptr, uvlinesize, h >> 1); } - - -static int wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) -{ - Wmv2Context * const w= (Wmv2Context*)s; - int cbp, code, i; - uint8_t *coded_val; - - if(w->j_type) return 0; - - if (s->pict_type == P_TYPE) { - if(IS_SKIP(s->current_picture.mb_type[s->mb_y * s->mb_stride + s->mb_x])){ - /* skip mb */ - s->mb_intra = 0; - for(i=0;i<6;i++) - s->block_last_index[i] = -1; - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_16X16; - s->mv[0][0][0] = 0; - s->mv[0][0][1] = 0; - s->mb_skipped = 1; - w->hshift=0; - return 0; - } - - code = get_vlc2(&s->gb, mb_non_intra_vlc[w->cbp_table_index].table, MB_NON_INTRA_VLC_BITS, 3); - if (code < 0) - return -1; - s->mb_intra = (~code & 0x40) >> 6; - - cbp = code & 0x3f; - } else { - s->mb_intra = 1; - code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2); - if (code < 0){ - av_log(s->avctx, AV_LOG_ERROR, "II-cbp illegal at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - /* predict coded block pattern */ - cbp = 0; - for(i=0;i<6;i++) { - int val = ((code >> (5 - i)) & 1); - if (i < 4) { - int pred = coded_block_pred(s, i, &coded_val); - val = val ^ pred; - *coded_val = val; - } - cbp |= val << (5 - i); - } - } - - if (!s->mb_intra) { - int mx, my; -//printf("P at %d %d\n", s->mb_x, s->mb_y); - wmv2_pred_motion(w, &mx, &my); - - if(cbp){ - s->dsp.clear_blocks(s->block[0]); - if(s->per_mb_rl_table){ - s->rl_table_index = decode012(&s->gb); - s->rl_chroma_table_index = s->rl_table_index; - } - - if(w->abt_flag && w->per_mb_abt){ - w->per_block_abt= get_bits1(&s->gb); - if(!w->per_block_abt) - w->abt_type= decode012(&s->gb); - }else - w->per_block_abt=0; - } - - if (wmv2_decode_motion(w, &mx, &my) < 0) - return -1; - - s->mv_dir = MV_DIR_FORWARD; - s->mv_type = MV_TYPE_16X16; - s->mv[0][0][0] = mx; - s->mv[0][0][1] = my; - - for (i = 0; i < 6; i++) { - if (wmv2_decode_inter_block(w, block[i], i, (cbp >> (5 - i)) & 1) < 0) - { - av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding inter block: %d x %d (%d)\n", s->mb_x, s->mb_y, i); - return -1; - } - } - } else { -//if(s->pict_type==P_TYPE) -// printf("%d%d ", s->inter_intra_pred, cbp); -//printf("I at %d %d %d %06X\n", s->mb_x, s->mb_y, ((cbp&3)? 1 : 0) +((cbp&0x3C)? 2 : 0), show_bits(&s->gb, 24)); - s->ac_pred = get_bits1(&s->gb); - if(s->inter_intra_pred){ - s->h263_aic_dir= get_vlc2(&s->gb, inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1); -// printf("%d%d %d %d/", s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y); - } - if(s->per_mb_rl_table && cbp){ - s->rl_table_index = decode012(&s->gb); - s->rl_chroma_table_index = s->rl_table_index; - } - - s->dsp.clear_blocks(s->block[0]); - for (i = 0; i < 6; i++) { - if (msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0) - { - av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding intra block: %d x %d (%d)\n", s->mb_x, s->mb_y, i); - return -1; - } - } - } - - return 0; -} - -static int wmv2_decode_init(AVCodecContext *avctx){ - Wmv2Context * const w= avctx->priv_data; - - if(ff_h263_decode_init(avctx) < 0) - return -1; - - wmv2_common_init(w); - - return 0; -} - -AVCodec wmv2_decoder = { - "wmv2", - CODEC_TYPE_VIDEO, - CODEC_ID_WMV2, - sizeof(Wmv2Context), - wmv2_decode_init, - NULL, - ff_h263_decode_end, - ff_h263_decode_frame, - CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, -}; - -#ifdef CONFIG_ENCODERS -AVCodec wmv2_encoder = { - "wmv2", - CODEC_TYPE_VIDEO, - CODEC_ID_WMV2, - sizeof(Wmv2Context), - wmv2_encode_init, - MPV_encode_picture, - MPV_encode_end, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, -}; -#endif diff --git a/contrib/ffmpeg/libavcodec/wmv2.h b/contrib/ffmpeg/libavcodec/wmv2.h new file mode 100644 index 000000000..2fd842e6a --- /dev/null +++ b/contrib/ffmpeg/libavcodec/wmv2.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2002 The FFmpeg Project. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_WMV2_H +#define FFMPEG_WMV2_H + +#include "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" +#include "intrax8.h" + +#define SKIP_TYPE_NONE 0 +#define SKIP_TYPE_MPEG 1 +#define SKIP_TYPE_ROW 2 +#define SKIP_TYPE_COL 3 + + +typedef struct Wmv2Context{ + MpegEncContext s; + IntraX8Context x8; + int j_type_bit; + int j_type; + int abt_flag; + int abt_type; + int abt_type_table[6]; + int per_mb_abt; + int per_block_abt; + int mspel_bit; + int cbp_table_index; + int top_left_mv_flag; + int per_mb_rl_bit; + int skip_type; + int hshift; + + ScanTable abt_scantable[2]; + DECLARE_ALIGNED_8(DCTELEM, abt_block2[6][64]); +}Wmv2Context; + +void ff_wmv2_common_init(Wmv2Context * w); + +#endif /* FFMPEG_WMV2_H */ diff --git a/contrib/ffmpeg/libavcodec/wmv2dec.c b/contrib/ffmpeg/libavcodec/wmv2dec.c new file mode 100644 index 000000000..cb3795512 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/wmv2dec.c @@ -0,0 +1,495 @@ +/* + * Copyright (c) 2002 The FFmpeg Project. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" +#include "msmpeg4.h" +#include "msmpeg4data.h" +#include "intrax8.h" +#include "wmv2.h" + + +static void parse_mb_skip(Wmv2Context * w){ + int mb_x, mb_y; + MpegEncContext * const s= &w->s; + uint32_t * const mb_type= s->current_picture_ptr->mb_type; + + w->skip_type= get_bits(&s->gb, 2); + switch(w->skip_type){ + case SKIP_TYPE_NONE: + for(mb_y=0; mb_ymb_height; mb_y++){ + for(mb_x=0; mb_xmb_width; mb_x++){ + mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_16x16 | MB_TYPE_L0; + } + } + break; + case SKIP_TYPE_MPEG: + for(mb_y=0; mb_ymb_height; mb_y++){ + for(mb_x=0; mb_xmb_width; mb_x++){ + mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0; + } + } + break; + case SKIP_TYPE_ROW: + for(mb_y=0; mb_ymb_height; mb_y++){ + if(get_bits1(&s->gb)){ + for(mb_x=0; mb_xmb_width; mb_x++){ + mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; + } + }else{ + for(mb_x=0; mb_xmb_width; mb_x++){ + mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0; + } + } + } + break; + case SKIP_TYPE_COL: + for(mb_x=0; mb_xmb_width; mb_x++){ + if(get_bits1(&s->gb)){ + for(mb_y=0; mb_ymb_height; mb_y++){ + mb_type[mb_y*s->mb_stride + mb_x]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; + } + }else{ + for(mb_y=0; mb_ymb_height; mb_y++){ + mb_type[mb_y*s->mb_stride + mb_x]= (get_bits1(&s->gb) ? MB_TYPE_SKIP : 0) | MB_TYPE_16x16 | MB_TYPE_L0; + } + } + } + break; + } +} + +static int decode_ext_header(Wmv2Context *w){ + MpegEncContext * const s= &w->s; + GetBitContext gb; + int fps; + int code; + + if(s->avctx->extradata_size<4) return -1; + + init_get_bits(&gb, s->avctx->extradata, s->avctx->extradata_size*8); + + fps = get_bits(&gb, 5); + s->bit_rate = get_bits(&gb, 11)*1024; + w->mspel_bit = get_bits1(&gb); + s->loop_filter = get_bits1(&gb); + w->abt_flag = get_bits1(&gb); + w->j_type_bit = get_bits1(&gb); + w->top_left_mv_flag= get_bits1(&gb); + w->per_mb_rl_bit = get_bits1(&gb); + code = get_bits(&gb, 3); + + if(code==0) return -1; + + s->slice_height = s->mb_height / code; + + if(s->avctx->debug&FF_DEBUG_PICT_INFO){ + av_log(s->avctx, AV_LOG_DEBUG, "fps:%d, br:%d, qpbit:%d, abt_flag:%d, j_type_bit:%d, tl_mv_flag:%d, mbrl_bit:%d, code:%d, loop_filter:%d, slices:%d\n", + fps, s->bit_rate, w->mspel_bit, w->abt_flag, w->j_type_bit, w->top_left_mv_flag, w->per_mb_rl_bit, code, s->loop_filter, + code); + } + return 0; +} + +int ff_wmv2_decode_picture_header(MpegEncContext * s) +{ + Wmv2Context * const w= (Wmv2Context*)s; + int code; + +#if 0 +{ +int i; +for(i=0; igb.size*8; i++) + printf("%d", get_bits1(&s->gb)); +// get_bits1(&s->gb); +printf("END\n"); +return -1; +} +#endif + if(s->picture_number==0) + decode_ext_header(w); + + s->pict_type = get_bits1(&s->gb) + 1; + if(s->pict_type == I_TYPE){ + code = get_bits(&s->gb, 7); + av_log(s->avctx, AV_LOG_DEBUG, "I7:%X/\n", code); + } + s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); + if(s->qscale <= 0) + return -1; + + return 0; +} + +int ff_wmv2_decode_secondary_picture_header(MpegEncContext * s) +{ + Wmv2Context * const w= (Wmv2Context*)s; + + if (s->pict_type == I_TYPE) { + if(w->j_type_bit) w->j_type= get_bits1(&s->gb); + else w->j_type= 0; //FIXME check + + if(!w->j_type){ + if(w->per_mb_rl_bit) s->per_mb_rl_table= get_bits1(&s->gb); + else s->per_mb_rl_table= 0; + + if(!s->per_mb_rl_table){ + s->rl_chroma_table_index = decode012(&s->gb); + s->rl_table_index = decode012(&s->gb); + } + + s->dc_table_index = get_bits1(&s->gb); + } + s->inter_intra_pred= 0; + s->no_rounding = 1; + if(s->avctx->debug&FF_DEBUG_PICT_INFO){ + av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d j_type:%d \n", + s->qscale, + s->rl_chroma_table_index, + s->rl_table_index, + s->dc_table_index, + s->per_mb_rl_table, + w->j_type); + } + }else{ + int cbp_index; + w->j_type=0; + + parse_mb_skip(w); + cbp_index= decode012(&s->gb); + if(s->qscale <= 10){ + int map[3]= {0,2,1}; + w->cbp_table_index= map[cbp_index]; + }else if(s->qscale <= 20){ + int map[3]= {1,0,2}; + w->cbp_table_index= map[cbp_index]; + }else{ + int map[3]= {2,1,0}; + w->cbp_table_index= map[cbp_index]; + } + + if(w->mspel_bit) s->mspel= get_bits1(&s->gb); + else s->mspel= 0; //FIXME check + + if(w->abt_flag){ + w->per_mb_abt= get_bits1(&s->gb)^1; + if(!w->per_mb_abt){ + w->abt_type= decode012(&s->gb); + } + } + + if(w->per_mb_rl_bit) s->per_mb_rl_table= get_bits1(&s->gb); + else s->per_mb_rl_table= 0; + + if(!s->per_mb_rl_table){ + s->rl_table_index = decode012(&s->gb); + s->rl_chroma_table_index = s->rl_table_index; + } + + s->dc_table_index = get_bits1(&s->gb); + s->mv_table_index = get_bits1(&s->gb); + + s->inter_intra_pred= 0;//(s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE); + s->no_rounding ^= 1; + + if(s->avctx->debug&FF_DEBUG_PICT_INFO){ + av_log(s->avctx, AV_LOG_DEBUG, "rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d mspel:%d per_mb_abt:%d abt_type:%d cbp:%d ii:%d\n", + s->rl_table_index, + s->rl_chroma_table_index, + s->dc_table_index, + s->mv_table_index, + s->per_mb_rl_table, + s->qscale, + s->mspel, + w->per_mb_abt, + w->abt_type, + w->cbp_table_index, + s->inter_intra_pred); + } + } + s->esc3_level_length= 0; + s->esc3_run_length= 0; + +s->picture_number++; //FIXME ? + + + if(w->j_type){ + ff_intrax8_decode_picture(&w->x8, 2*s->qscale, (s->qscale-1)|1 ); + return 1; + } + + return 0; +} + +static inline int wmv2_decode_motion(Wmv2Context *w, int *mx_ptr, int *my_ptr){ + MpegEncContext * const s= &w->s; + int ret; + + ret= ff_msmpeg4_decode_motion(s, mx_ptr, my_ptr); + + if(ret<0) return -1; + + if((((*mx_ptr)|(*my_ptr)) & 1) && s->mspel) + w->hshift= get_bits1(&s->gb); + else + w->hshift= 0; + +//printf("%d %d ", *mx_ptr, *my_ptr); + + return 0; +} + +static int16_t *wmv2_pred_motion(Wmv2Context *w, int *px, int *py){ + MpegEncContext * const s= &w->s; + int xy, wrap, diff, type; + int16_t *A, *B, *C, *mot_val; + + wrap = s->b8_stride; + xy = s->block_index[0]; + + mot_val = s->current_picture.motion_val[0][xy]; + + A = s->current_picture.motion_val[0][xy - 1]; + B = s->current_picture.motion_val[0][xy - wrap]; + C = s->current_picture.motion_val[0][xy + 2 - wrap]; + + if(s->mb_x && !s->first_slice_line && !s->mspel && w->top_left_mv_flag) + diff= FFMAX(FFABS(A[0] - B[0]), FFABS(A[1] - B[1])); + else + diff=0; + + if(diff >= 8) + type= get_bits1(&s->gb); + else + type= 2; + + if(type == 0){ + *px= A[0]; + *py= A[1]; + }else if(type == 1){ + *px= B[0]; + *py= B[1]; + }else{ + /* special case for first (slice) line */ + if (s->first_slice_line) { + *px = A[0]; + *py = A[1]; + } else { + *px = mid_pred(A[0], B[0], C[0]); + *py = mid_pred(A[1], B[1], C[1]); + } + } + + return mot_val; +} + +static inline int wmv2_decode_inter_block(Wmv2Context *w, DCTELEM *block, int n, int cbp){ + MpegEncContext * const s= &w->s; + static const int sub_cbp_table[3]= {2,3,1}; + int sub_cbp; + + if(!cbp){ + s->block_last_index[n] = -1; + + return 0; + } + + if(w->per_block_abt) + w->abt_type= decode012(&s->gb); +#if 0 + if(w->per_block_abt) + printf("B%d", w->abt_type); +#endif + w->abt_type_table[n]= w->abt_type; + + if(w->abt_type){ +// const uint8_t *scantable= w->abt_scantable[w->abt_type-1].permutated; + const uint8_t *scantable= w->abt_scantable[w->abt_type-1].scantable; +// const uint8_t *scantable= w->abt_type-1 ? w->abt_scantable[1].permutated : w->abt_scantable[0].scantable; + + sub_cbp= sub_cbp_table[ decode012(&s->gb) ]; +// printf("S%d", sub_cbp); + + if(sub_cbp&1){ + if (ff_msmpeg4_decode_block(s, block, n, 1, scantable) < 0) + return -1; + } + + if(sub_cbp&2){ + if (ff_msmpeg4_decode_block(s, w->abt_block2[n], n, 1, scantable) < 0) + return -1; + } + s->block_last_index[n] = 63; + + return 0; + }else{ + return ff_msmpeg4_decode_block(s, block, n, 1, s->inter_scantable.permutated); + } +} + + +int ff_wmv2_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) +{ + Wmv2Context * const w= (Wmv2Context*)s; + int cbp, code, i; + uint8_t *coded_val; + + if(w->j_type) return 0; + + if (s->pict_type == P_TYPE) { + if(IS_SKIP(s->current_picture.mb_type[s->mb_y * s->mb_stride + s->mb_x])){ + /* skip mb */ + s->mb_intra = 0; + for(i=0;i<6;i++) + s->block_last_index[i] = -1; + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; + s->mv[0][0][0] = 0; + s->mv[0][0][1] = 0; + s->mb_skipped = 1; + w->hshift=0; + return 0; + } + + code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[w->cbp_table_index].table, MB_NON_INTRA_VLC_BITS, 3); + if (code < 0) + return -1; + s->mb_intra = (~code & 0x40) >> 6; + + cbp = code & 0x3f; + } else { + s->mb_intra = 1; + code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2); + if (code < 0){ + av_log(s->avctx, AV_LOG_ERROR, "II-cbp illegal at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + /* predict coded block pattern */ + cbp = 0; + for(i=0;i<6;i++) { + int val = ((code >> (5 - i)) & 1); + if (i < 4) { + int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_val); + val = val ^ pred; + *coded_val = val; + } + cbp |= val << (5 - i); + } + } + + if (!s->mb_intra) { + int mx, my; +//printf("P at %d %d\n", s->mb_x, s->mb_y); + wmv2_pred_motion(w, &mx, &my); + + if(cbp){ + s->dsp.clear_blocks(s->block[0]); + if(s->per_mb_rl_table){ + s->rl_table_index = decode012(&s->gb); + s->rl_chroma_table_index = s->rl_table_index; + } + + if(w->abt_flag && w->per_mb_abt){ + w->per_block_abt= get_bits1(&s->gb); + if(!w->per_block_abt) + w->abt_type= decode012(&s->gb); + }else + w->per_block_abt=0; + } + + if (wmv2_decode_motion(w, &mx, &my) < 0) + return -1; + + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; + s->mv[0][0][0] = mx; + s->mv[0][0][1] = my; + + for (i = 0; i < 6; i++) { + if (wmv2_decode_inter_block(w, block[i], i, (cbp >> (5 - i)) & 1) < 0) + { + av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding inter block: %d x %d (%d)\n", s->mb_x, s->mb_y, i); + return -1; + } + } + } else { +//if(s->pict_type==P_TYPE) +// printf("%d%d ", s->inter_intra_pred, cbp); +//printf("I at %d %d %d %06X\n", s->mb_x, s->mb_y, ((cbp&3)? 1 : 0) +((cbp&0x3C)? 2 : 0), show_bits(&s->gb, 24)); + s->ac_pred = get_bits1(&s->gb); + if(s->inter_intra_pred){ + s->h263_aic_dir= get_vlc2(&s->gb, ff_inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1); +// printf("%d%d %d %d/", s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y); + } + if(s->per_mb_rl_table && cbp){ + s->rl_table_index = decode012(&s->gb); + s->rl_chroma_table_index = s->rl_table_index; + } + + s->dsp.clear_blocks(s->block[0]); + for (i = 0; i < 6; i++) { + if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0) + { + av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding intra block: %d x %d (%d)\n", s->mb_x, s->mb_y, i); + return -1; + } + } + } + + return 0; +} + +static int wmv2_decode_init(AVCodecContext *avctx){ + Wmv2Context * const w= avctx->priv_data; + + if(avctx->idct_algo==FF_IDCT_AUTO){ + avctx->idct_algo=FF_IDCT_WMV2; + } + + if(ff_h263_decode_init(avctx) < 0) + return -1; + + ff_wmv2_common_init(w); + + ff_intrax8_common_init(&w->x8,&w->s); + + return 0; +} + +static int wmv2_decode_end(AVCodecContext *avctx) +{ + Wmv2Context *w = avctx->priv_data; + + ff_intrax8_common_end(&w->x8); + return ff_h263_decode_end(avctx); +} + +AVCodec wmv2_decoder = { + "wmv2", + CODEC_TYPE_VIDEO, + CODEC_ID_WMV2, + sizeof(Wmv2Context), + wmv2_decode_init, + NULL, + wmv2_decode_end, + ff_h263_decode_frame, + CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, +}; diff --git a/contrib/ffmpeg/libavcodec/wmv2enc.c b/contrib/ffmpeg/libavcodec/wmv2enc.c new file mode 100644 index 000000000..641f0dc85 --- /dev/null +++ b/contrib/ffmpeg/libavcodec/wmv2enc.c @@ -0,0 +1,240 @@ +/* + * Copyright (c) 2002 The FFmpeg Project. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" +#include "msmpeg4.h" +#include "msmpeg4data.h" +#include "wmv2.h" + + +static int encode_ext_header(Wmv2Context *w){ + MpegEncContext * const s= &w->s; + PutBitContext pb; + int code; + + init_put_bits(&pb, s->avctx->extradata, s->avctx->extradata_size); + + put_bits(&pb, 5, s->avctx->time_base.den / s->avctx->time_base.num); //yes 29.97 -> 29 + put_bits(&pb, 11, FFMIN(s->bit_rate/1024, 2047)); + + put_bits(&pb, 1, w->mspel_bit=1); + put_bits(&pb, 1, s->loop_filter); + put_bits(&pb, 1, w->abt_flag=1); + put_bits(&pb, 1, w->j_type_bit=1); + put_bits(&pb, 1, w->top_left_mv_flag=0); + put_bits(&pb, 1, w->per_mb_rl_bit=1); + put_bits(&pb, 3, code=1); + + flush_put_bits(&pb); + + s->slice_height = s->mb_height / code; + + return 0; +} + +static int wmv2_encode_init(AVCodecContext *avctx){ + Wmv2Context * const w= avctx->priv_data; + + if(MPV_encode_init(avctx) < 0) + return -1; + + ff_wmv2_common_init(w); + + avctx->extradata_size= 4; + avctx->extradata= av_mallocz(avctx->extradata_size + 10); + encode_ext_header(w); + + return 0; +} + +#if 0 /* unused, remove? */ +static int wmv2_encode_end(AVCodecContext *avctx){ + + if(MPV_encode_end(avctx) < 0) + return -1; + + avctx->extradata_size= 0; + av_freep(&avctx->extradata); + + return 0; +} +#endif + +int ff_wmv2_encode_picture_header(MpegEncContext * s, int picture_number) +{ + Wmv2Context * const w= (Wmv2Context*)s; + + put_bits(&s->pb, 1, s->pict_type - 1); + if(s->pict_type == I_TYPE){ + put_bits(&s->pb, 7, 0); + } + put_bits(&s->pb, 5, s->qscale); + + s->dc_table_index = 1; + s->mv_table_index = 1; /* only if P frame */ +// s->use_skip_mb_code = 1; /* only if P frame */ + s->per_mb_rl_table = 0; + s->mspel= 0; + w->per_mb_abt=0; + w->abt_type=0; + w->j_type=0; + + assert(s->flipflop_rounding); + + if (s->pict_type == I_TYPE) { + assert(s->no_rounding==1); + if(w->j_type_bit) put_bits(&s->pb, 1, w->j_type); + + if(w->per_mb_rl_bit) put_bits(&s->pb, 1, s->per_mb_rl_table); + + if(!s->per_mb_rl_table){ + ff_msmpeg4_code012(&s->pb, s->rl_chroma_table_index); + ff_msmpeg4_code012(&s->pb, s->rl_table_index); + } + + put_bits(&s->pb, 1, s->dc_table_index); + + s->inter_intra_pred= 0; + }else{ + int cbp_index; + + put_bits(&s->pb, 2, SKIP_TYPE_NONE); + + ff_msmpeg4_code012(&s->pb, cbp_index=0); + if(s->qscale <= 10){ + int map[3]= {0,2,1}; + w->cbp_table_index= map[cbp_index]; + }else if(s->qscale <= 20){ + int map[3]= {1,0,2}; + w->cbp_table_index= map[cbp_index]; + }else{ + int map[3]= {2,1,0}; + w->cbp_table_index= map[cbp_index]; + } + + if(w->mspel_bit) put_bits(&s->pb, 1, s->mspel); + + if(w->abt_flag){ + put_bits(&s->pb, 1, w->per_mb_abt^1); + if(!w->per_mb_abt){ + ff_msmpeg4_code012(&s->pb, w->abt_type); + } + } + + if(w->per_mb_rl_bit) put_bits(&s->pb, 1, s->per_mb_rl_table); + + if(!s->per_mb_rl_table){ + ff_msmpeg4_code012(&s->pb, s->rl_table_index); + s->rl_chroma_table_index = s->rl_table_index; + } + put_bits(&s->pb, 1, s->dc_table_index); + put_bits(&s->pb, 1, s->mv_table_index); + + s->inter_intra_pred= 0;//(s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE); + } + s->esc3_level_length= 0; + s->esc3_run_length= 0; + + return 0; +} + +/* Nearly identical to wmv1 but that is just because we do not use the + * useless M$ crap features. It is duplicated here in case someone wants + * to add support for these crap features. */ +void ff_wmv2_encode_mb(MpegEncContext * s, + DCTELEM block[6][64], + int motion_x, int motion_y) +{ + Wmv2Context * const w= (Wmv2Context*)s; + int cbp, coded_cbp, i; + int pred_x, pred_y; + uint8_t *coded_block; + + ff_msmpeg4_handle_slices(s); + + if (!s->mb_intra) { + /* compute cbp */ + cbp = 0; + for (i = 0; i < 6; i++) { + if (s->block_last_index[i] >= 0) + cbp |= 1 << (5 - i); + } + + put_bits(&s->pb, + wmv2_inter_table[w->cbp_table_index][cbp + 64][1], + wmv2_inter_table[w->cbp_table_index][cbp + 64][0]); + + /* motion vector */ + h263_pred_motion(s, 0, 0, &pred_x, &pred_y); + ff_msmpeg4_encode_motion(s, motion_x - pred_x, + motion_y - pred_y); + } else { + /* compute cbp */ + cbp = 0; + coded_cbp = 0; + for (i = 0; i < 6; i++) { + int val, pred; + val = (s->block_last_index[i] >= 1); + cbp |= val << (5 - i); + if (i < 4) { + /* predict value for close blocks only for luma */ + pred = ff_msmpeg4_coded_block_pred(s, i, &coded_block); + *coded_block = val; + val = val ^ pred; + } + coded_cbp |= val << (5 - i); + } +#if 0 + if (coded_cbp) + printf("cbp=%x %x\n", cbp, coded_cbp); +#endif + + if (s->pict_type == I_TYPE) { + put_bits(&s->pb, + ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]); + } else { + put_bits(&s->pb, + wmv2_inter_table[w->cbp_table_index][cbp][1], + wmv2_inter_table[w->cbp_table_index][cbp][0]); + } + put_bits(&s->pb, 1, 0); /* no AC prediction yet */ + if(s->inter_intra_pred){ + s->h263_aic_dir=0; + put_bits(&s->pb, table_inter_intra[s->h263_aic_dir][1], table_inter_intra[s->h263_aic_dir][0]); + } + } + + for (i = 0; i < 6; i++) { + ff_msmpeg4_encode_block(s, block[i], i); + } +} + +AVCodec wmv2_encoder = { + "wmv2", + CODEC_TYPE_VIDEO, + CODEC_ID_WMV2, + sizeof(Wmv2Context), + wmv2_encode_init, + MPV_encode_picture, + MPV_encode_end, + .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, +}; diff --git a/contrib/ffmpeg/libavcodec/wnv1.c b/contrib/ffmpeg/libavcodec/wnv1.c index 46b31a5c5..0aadf4dbe 100644 --- a/contrib/ffmpeg/libavcodec/wnv1.c +++ b/contrib/ffmpeg/libavcodec/wnv1.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -26,7 +25,6 @@ */ #include "avcodec.h" -#include "common.h" #include "bitstream.h" diff --git a/contrib/ffmpeg/libavcodec/ws-snd1.c b/contrib/ffmpeg/libavcodec/ws-snd1.c index 3624909a3..057d4bfc2 100644 --- a/contrib/ffmpeg/libavcodec/ws-snd1.c +++ b/contrib/ffmpeg/libavcodec/ws-snd1.c @@ -45,7 +45,7 @@ static int ws_snd_decode_init(AVCodecContext * avctx) static int ws_snd_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { // WSSNDContext *c = avctx->priv_data; @@ -62,6 +62,14 @@ static int ws_snd_decode_frame(AVCodecContext *avctx, in_size = AV_RL16(&buf[2]); buf += 4; + if (out_size > *data_size) { + av_log(avctx, AV_LOG_ERROR, "Frame is too large to fit in buffer\n"); + return -1; + } + if (in_size > buf_size) { + av_log(avctx, AV_LOG_ERROR, "Frame data is larger than input buffer\n"); + return -1; + } if (in_size == out_size) { for (i = 0; i < out_size; i++) *samples++ = (*buf++ - 0x80) << 8; diff --git a/contrib/ffmpeg/libavcodec/x264.c b/contrib/ffmpeg/libavcodec/x264.c deleted file mode 100644 index c9df820f5..000000000 --- a/contrib/ffmpeg/libavcodec/x264.c +++ /dev/null @@ -1,300 +0,0 @@ -/* - * H.264 encoding using the x264 library - * Copyright (C) 2005 Mans Rullgard - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "avcodec.h" -#include -#include -#include -#include -#include - -typedef struct X264Context { - x264_param_t params; - x264_t *enc; - x264_picture_t pic; - AVFrame out_pic; -} X264Context; - -static void -X264_log(void *p, int level, const char *fmt, va_list args) -{ - static const int level_map[] = { - [X264_LOG_ERROR] = AV_LOG_ERROR, - [X264_LOG_WARNING] = AV_LOG_ERROR, - [X264_LOG_INFO] = AV_LOG_INFO, - [X264_LOG_DEBUG] = AV_LOG_DEBUG - }; - - if(level < 0 || level > X264_LOG_DEBUG) - return; - - av_vlog(p, level_map[level], fmt, args); -} - - -static int -encode_nals(uint8_t *buf, int size, x264_nal_t *nals, int nnal) -{ - uint8_t *p = buf; - int i; - - for(i = 0; i < nnal; i++){ - int s = x264_nal_encode(p, &size, 1, nals + i); - if(s < 0) - return -1; - p += s; - } - - return p - buf; -} - -static int -X264_frame(AVCodecContext *ctx, uint8_t *buf, int bufsize, void *data) -{ - X264Context *x4 = ctx->priv_data; - AVFrame *frame = data; - x264_nal_t *nal; - int nnal, i; - x264_picture_t pic_out; - - x4->pic.img.i_csp = X264_CSP_I420; - x4->pic.img.i_plane = 3; - - if (frame) { - for(i = 0; i < 3; i++){ - x4->pic.img.plane[i] = frame->data[i]; - x4->pic.img.i_stride[i] = frame->linesize[i]; - } - - x4->pic.i_pts = frame->pts; - x4->pic.i_type = X264_TYPE_AUTO; - } - - if(x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, - &pic_out)) - return -1; - - bufsize = encode_nals(buf, bufsize, nal, nnal); - if(bufsize < 0) - return -1; - - /* FIXME: dts */ - x4->out_pic.pts = pic_out.i_pts; - - switch(pic_out.i_type){ - case X264_TYPE_IDR: - case X264_TYPE_I: - x4->out_pic.pict_type = FF_I_TYPE; - break; - case X264_TYPE_P: - x4->out_pic.pict_type = FF_P_TYPE; - break; - case X264_TYPE_B: - case X264_TYPE_BREF: - x4->out_pic.pict_type = FF_B_TYPE; - break; - } - - x4->out_pic.key_frame = pic_out.i_type == X264_TYPE_IDR; - x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; - - return bufsize; -} - -static int -X264_close(AVCodecContext *avctx) -{ - X264Context *x4 = avctx->priv_data; - - if(x4->enc) - x264_encoder_close(x4->enc); - - return 0; -} - -static int -X264_init(AVCodecContext *avctx) -{ - X264Context *x4 = avctx->priv_data; - - x264_param_default(&x4->params); - - x4->params.pf_log = X264_log; - x4->params.p_log_private = avctx; - - x4->params.i_keyint_max = avctx->gop_size; - x4->params.rc.i_bitrate = avctx->bit_rate / 1000; - x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000; - x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000; - x4->params.rc.b_stat_write = (avctx->flags & CODEC_FLAG_PASS1); - if(avctx->flags & CODEC_FLAG_PASS2) x4->params.rc.b_stat_read = 1; - else{ - if(avctx->crf){ - x4->params.rc.i_rc_method = X264_RC_CRF; - x4->params.rc.f_rf_constant = avctx->crf; - }else if(avctx->cqp > -1){ - x4->params.rc.i_rc_method = X264_RC_CQP; - x4->params.rc.i_qp_constant = avctx->cqp; - } - } - - // if neither crf nor cqp modes are selected we have to enable the RC - // we do it this way because we cannot check if the bitrate has been set - if(!(avctx->crf || (avctx->cqp > -1))) x4->params.rc.i_rc_method = X264_RC_ABR; - - x4->params.i_bframe = avctx->max_b_frames; - x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC; - x4->params.b_bframe_adaptive = avctx->b_frame_strategy; - x4->params.i_bframe_bias = avctx->bframebias; - x4->params.b_bframe_pyramid = (avctx->flags2 & CODEC_FLAG2_BPYRAMID); - avctx->has_b_frames= (avctx->flags2 & CODEC_FLAG2_BPYRAMID) ? 2 : !!avctx->max_b_frames; - - x4->params.i_keyint_min = avctx->keyint_min; - if(x4->params.i_keyint_min > x4->params.i_keyint_max) - x4->params.i_keyint_min = x4->params.i_keyint_max; - - x4->params.i_scenecut_threshold = avctx->scenechange_threshold; - - x4->params.b_deblocking_filter = (avctx->flags & CODEC_FLAG_LOOP_FILTER); - x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha; - x4->params.i_deblocking_filter_beta = avctx->deblockbeta; - - x4->params.rc.i_qp_min = avctx->qmin; - x4->params.rc.i_qp_max = avctx->qmax; - x4->params.rc.i_qp_step = avctx->max_qdiff; - - x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */ - x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */ - x4->params.rc.f_complexity_blur = avctx->complexityblur; - - x4->params.i_frame_reference = avctx->refs; - - x4->params.i_width = avctx->width; - x4->params.i_height = avctx->height; - x4->params.vui.i_sar_width = avctx->sample_aspect_ratio.num; - x4->params.vui.i_sar_height = avctx->sample_aspect_ratio.den; - x4->params.i_fps_num = avctx->time_base.den; - x4->params.i_fps_den = avctx->time_base.num; - - x4->params.analyse.inter = 0; - if(avctx->partitions){ - if(avctx->partitions & X264_PART_I4X4) - x4->params.analyse.inter |= X264_ANALYSE_I4x4; - if(avctx->partitions & X264_PART_I8X8) - x4->params.analyse.inter |= X264_ANALYSE_I8x8; - if(avctx->partitions & X264_PART_P8X8) - x4->params.analyse.inter |= X264_ANALYSE_PSUB16x16; - if(avctx->partitions & X264_PART_P4X4) - x4->params.analyse.inter |= X264_ANALYSE_PSUB8x8; - if(avctx->partitions & X264_PART_B8X8) - x4->params.analyse.inter |= X264_ANALYSE_BSUB16x16; - } - - x4->params.analyse.i_direct_mv_pred = avctx->directpred; - - x4->params.analyse.b_weighted_bipred = (avctx->flags2 & CODEC_FLAG2_WPRED); - - if(avctx->me_method == ME_EPZS) - x4->params.analyse.i_me_method = X264_ME_DIA; - else if(avctx->me_method == ME_HEX) - x4->params.analyse.i_me_method = X264_ME_HEX; - else if(avctx->me_method == ME_UMH) - x4->params.analyse.i_me_method = X264_ME_UMH; - else if(avctx->me_method == ME_FULL) - x4->params.analyse.i_me_method = X264_ME_ESA; - else x4->params.analyse.i_me_method = X264_ME_HEX; - - x4->params.analyse.i_me_range = avctx->me_range; - x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality; - - x4->params.analyse.b_bidir_me = (avctx->bidir_refine > 0); - x4->params.analyse.b_bframe_rdo = (avctx->flags2 & CODEC_FLAG2_BRDO); - x4->params.analyse.b_mixed_references = - (avctx->flags2 & CODEC_FLAG2_MIXED_REFS); - x4->params.analyse.b_chroma_me = (avctx->me_cmp & FF_CMP_CHROMA); - x4->params.analyse.b_transform_8x8 = (avctx->flags2 & CODEC_FLAG2_8X8DCT); - x4->params.analyse.b_fast_pskip = (avctx->flags2 & CODEC_FLAG2_FASTPSKIP); - - x4->params.analyse.i_trellis = avctx->trellis; - x4->params.analyse.i_noise_reduction = avctx->noise_reduction; - - if(avctx->level > 0) x4->params.i_level_idc = avctx->level; - - x4->params.rc.f_rate_tolerance = - (float)avctx->bit_rate_tolerance/avctx->bit_rate; - - if((avctx->rc_buffer_size != 0) && - (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)){ - x4->params.rc.f_vbv_buffer_init = - (float)avctx->rc_initial_buffer_occupancy/avctx->rc_buffer_size; - } - else x4->params.rc.f_vbv_buffer_init = 0.9; - - x4->params.rc.f_ip_factor = 1/fabs(avctx->i_quant_factor); - x4->params.rc.f_pb_factor = avctx->b_quant_factor; - x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset; - x4->params.rc.psz_rc_eq = avctx->rc_eq; - - x4->params.analyse.b_psnr = (avctx->flags & CODEC_FLAG_PSNR); - x4->params.i_log_level = X264_LOG_DEBUG; - - x4->params.b_aud = (avctx->flags2 & CODEC_FLAG2_AUD); - - x4->params.i_threads = avctx->thread_count; - - if(avctx->flags & CODEC_FLAG_GLOBAL_HEADER){ - x4->params.b_repeat_headers = 0; - } - - x4->enc = x264_encoder_open(&x4->params); - if(!x4->enc) - return -1; - - avctx->coded_frame = &x4->out_pic; - - if(avctx->flags & CODEC_FLAG_GLOBAL_HEADER){ - x264_nal_t *nal; - int nnal, i, s = 0; - - x264_encoder_headers(x4->enc, &nal, &nnal); - - /* 5 bytes NAL header + worst case escaping */ - for(i = 0; i < nnal; i++) - s += 5 + nal[i].i_payload * 4 / 3; - - avctx->extradata = av_malloc(s); - avctx->extradata_size = encode_nals(avctx->extradata, s, nal, nnal); - } - - return 0; -} - -AVCodec x264_encoder = { - .name = "h264", - .type = CODEC_TYPE_VIDEO, - .id = CODEC_ID_H264, - .priv_data_size = sizeof(X264Context), - .init = X264_init, - .encode = X264_frame, - .close = X264_close, - .capabilities = CODEC_CAP_DELAY, - .pix_fmts = (enum PixelFormat[]) { PIX_FMT_YUV420P, -1 } -}; diff --git a/contrib/ffmpeg/libavcodec/xan.c b/contrib/ffmpeg/libavcodec/xan.c index f697514a0..27fc16488 100644 --- a/contrib/ffmpeg/libavcodec/xan.c +++ b/contrib/ffmpeg/libavcodec/xan.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -34,7 +33,6 @@ #include #include -#include "common.h" #include "avcodec.h" typedef struct XanContext { @@ -43,7 +41,7 @@ typedef struct XanContext { AVFrame last_frame; AVFrame current_frame; - unsigned char *buf; + const unsigned char *buf; int size; /* scratch space */ @@ -70,7 +68,6 @@ static int xan_decode_init(AVCodecContext *avctx) } avctx->pix_fmt = PIX_FMT_PAL8; - avctx->has_b_frames = 0; if(avcodec_check_dimensions(avctx, avctx->width, avctx->height)) return -1; @@ -85,12 +82,12 @@ static int xan_decode_init(AVCodecContext *avctx) return 0; } -/* This function is used in lieu of memcpy(). This decoder can not use +/* This function is used in lieu of memcpy(). This decoder cannot use * memcpy because the memory locations often overlap and * memcpy doesn't like that; it's not uncommon, for example, for * dest = src+1, to turn byte A into pattern AAAAAAAA. * This was originally repz movsb in Intel x86 ASM. */ -static inline void bytecopy(unsigned char *dest, unsigned char *src, int count) +static inline void bytecopy(unsigned char *dest, const unsigned char *src, int count) { int i; @@ -98,12 +95,12 @@ static inline void bytecopy(unsigned char *dest, unsigned char *src, int count) dest[i] = src[i]; } -static int xan_huffman_decode(unsigned char *dest, unsigned char *src, +static int xan_huffman_decode(unsigned char *dest, const unsigned char *src, int dest_len) { unsigned char byte = *src++; unsigned char ival = byte + 0x16; - unsigned char * ptr = src + byte*2; + const unsigned char * ptr = src + byte*2; unsigned char val = ival; int counter = 0; unsigned char *dest_end = dest + dest_len; @@ -132,7 +129,7 @@ static int xan_huffman_decode(unsigned char *dest, unsigned char *src, return 0; } -static void xan_unpack(unsigned char *dest, unsigned char *src, int dest_len) +static void xan_unpack(unsigned char *dest, const unsigned char *src, int dest_len) { unsigned char opcode; int size; @@ -208,8 +205,8 @@ static void xan_unpack(unsigned char *dest, unsigned char *src, int dest_len) bytecopy(dest, src, size); dest += size; src += size; } -static void inline xan_wc3_output_pixel_run(XanContext *s, - unsigned char *pixel_buffer, int x, int y, int pixel_count) +static inline void xan_wc3_output_pixel_run(XanContext *s, + const unsigned char *pixel_buffer, int x, int y, int pixel_count) { int stride; int line_inc; @@ -237,7 +234,7 @@ static void inline xan_wc3_output_pixel_run(XanContext *s, } } -static void inline xan_wc3_copy_pixel_run(XanContext *s, +static inline void xan_wc3_copy_pixel_run(XanContext *s, int x, int y, int pixel_count, int motion_x, int motion_y) { int stride; @@ -287,14 +284,13 @@ static void xan_wc3_decode_frame(XanContext *s) { unsigned char *opcode_buffer = s->buffer1; int opcode_buffer_size = s->buffer1_size; - unsigned char *imagedata_buffer = s->buffer2; - int imagedata_buffer_size = s->buffer2_size; + const unsigned char *imagedata_buffer = s->buffer2; /* pointers to segments inside the compressed chunk */ - unsigned char *huffman_segment; - unsigned char *size_segment; - unsigned char *vector_segment; - unsigned char *imagedata_segment; + const unsigned char *huffman_segment; + const unsigned char *size_segment; + const unsigned char *vector_segment; + const unsigned char *imagedata_segment; huffman_segment = s->buf + AV_RL16(&s->buf[0]); size_segment = s->buf + AV_RL16(&s->buf[2]); @@ -304,8 +300,7 @@ static void xan_wc3_decode_frame(XanContext *s) { xan_huffman_decode(opcode_buffer, huffman_segment, opcode_buffer_size); if (imagedata_segment[0] == 2) - xan_unpack(imagedata_buffer, &imagedata_segment[1], - imagedata_buffer_size); + xan_unpack(s->buffer2, &imagedata_segment[1], s->buffer2_size); else imagedata_buffer = &imagedata_segment[1]; @@ -356,8 +351,7 @@ static void xan_wc3_decode_frame(XanContext *s) { case 11: case 21: - size = (size_segment[0] << 16) | (size_segment[1] << 8) | - size_segment[2]; + size = AV_RB24(size_segment); size_segment += 3; break; } @@ -410,7 +404,7 @@ static void xan_wc4_decode_frame(XanContext *s) { static int xan_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { XanContext *s = avctx->priv_data; AVPaletteControl *palette_control = avctx->palctrl; diff --git a/contrib/ffmpeg/libavcodec/xiph.h b/contrib/ffmpeg/libavcodec/xiph.h index 85cfeebaf..7e7575010 100644 --- a/contrib/ffmpeg/libavcodec/xiph.h +++ b/contrib/ffmpeg/libavcodec/xiph.h @@ -18,6 +18,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef FFMPEG_XIPH_H +#define FFMPEG_XIPH_H + #include "common.h" /** @@ -36,3 +39,5 @@ int ff_split_xiph_headers(uint8_t *extradata, int extradata_size, int first_header_size, uint8_t *header_start[3], int header_len[3]); + +#endif /* FFMPEG_XIPH_H */ diff --git a/contrib/ffmpeg/libavcodec/xl.c b/contrib/ffmpeg/libavcodec/xl.c index 8a011d887..b48a369b8 100644 --- a/contrib/ffmpeg/libavcodec/xl.c +++ b/contrib/ffmpeg/libavcodec/xl.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -41,7 +40,7 @@ static const int xl_table[32] = { static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, - uint8_t *buf, int buf_size) + const uint8_t *buf, int buf_size) { VideoXLContext * const a = avctx->priv_data; AVFrame * const p= (AVFrame*)&a->pic; diff --git a/contrib/ffmpeg/libavcodec/xsubdec.c b/contrib/ffmpeg/libavcodec/xsubdec.c new file mode 100644 index 000000000..391a003ac --- /dev/null +++ b/contrib/ffmpeg/libavcodec/xsubdec.c @@ -0,0 +1,136 @@ +/* + * XSUB subtitle decoder + * Copyright (c) 2007 Reimar Döffinger + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avcodec.h" +#include "bitstream.h" +#include "bytestream.h" + +static int decode_init(AVCodecContext *avctx) { + avctx->pix_fmt = PIX_FMT_PAL8; + return 0; +} + +static const uint8_t tc_offsets[9] = { 0, 1, 3, 4, 6, 7, 9, 10, 11 }; +static const uint8_t tc_muls[9] = { 10, 6, 10, 6, 10, 6, 10, 10, 1 }; + +static uint64_t parse_timecode(const uint8_t *buf) { + int i; + int64_t ms = 0; + if (buf[2] != ':' || buf[5] != ':' || buf[8] != '.') + return AV_NOPTS_VALUE; + for (i = 0; i < sizeof(tc_offsets); i++) { + uint8_t c = buf[tc_offsets[i]] - '0'; + if (c > 9) return AV_NOPTS_VALUE; + ms = (ms + c) * tc_muls[i]; + } + return ms; +} + +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, + const uint8_t *buf, int buf_size) { + AVSubtitle *sub = data; + const uint8_t *buf_end = buf + buf_size; + uint8_t *bitmap; + int w, h, x, y, rlelen, i; + GetBitContext gb; + + // check that at least header fits + if (buf_size < 27 + 7 * 2 + 4 * 3) { + av_log(avctx, AV_LOG_ERROR, "coded frame too small\n"); + return -1; + } + + // read start and end time + if (buf[0] != '[' || buf[13] != '-' || buf[26] != ']') { + av_log(avctx, AV_LOG_ERROR, "invalid time code\n"); + return -1; + } + sub->start_display_time = parse_timecode(buf + 1); + sub->end_display_time = parse_timecode(buf + 14); + buf += 27; + + // read header + w = bytestream_get_le16(&buf); + h = bytestream_get_le16(&buf); + if (avcodec_check_dimensions(avctx, w, h) < 0) + return -1; + x = bytestream_get_le16(&buf); + y = bytestream_get_le16(&buf); + // skip bottom right position, it gives no new information + bytestream_get_le16(&buf); + bytestream_get_le16(&buf); + rlelen = bytestream_get_le16(&buf); + + // allocate sub and set values + if (!sub->rects) { + sub->rects = av_mallocz(sizeof(AVSubtitleRect)); + sub->num_rects = 1; + } + av_freep(&sub->rects[0].bitmap); + sub->rects[0].x = x; sub->rects[0].y = y; + sub->rects[0].w = w; sub->rects[0].h = h; + sub->rects[0].linesize = w; + sub->rects[0].bitmap = av_malloc(w * h); + sub->rects[0].nb_colors = 4; + sub->rects[0].rgba_palette = av_malloc(sub->rects[0].nb_colors * 4); + + // read palette + for (i = 0; i < sub->rects[0].nb_colors; i++) + sub->rects[0].rgba_palette[i] = bytestream_get_be24(&buf); + // make all except background (first entry) non-transparent + for (i = 1; i < sub->rects[0].nb_colors; i++) + sub->rects[0].rgba_palette[i] |= 0xff000000; + + // process RLE-compressed data + rlelen = FFMIN(rlelen, buf_end - buf); + init_get_bits(&gb, buf, rlelen * 8); + bitmap = sub->rects[0].bitmap; + for (y = 0; y < h; y++) { + // interlaced: do odd lines + if (y == (h + 1) / 2) bitmap = sub->rects[0].bitmap + w; + for (x = 0; x < w; ) { + int log2 = ff_log2_tab[show_bits(&gb, 8)]; + int run = get_bits(&gb, 14 - 4 * (log2 >> 1)); + int color = get_bits(&gb, 2); + run = FFMIN(run, w - x); + // run length 0 means till end of row + if (!run) run = w - x; + memset(bitmap, color, run); + bitmap += run; + x += run; + } + // interlaced, skip every second line + bitmap += w; + align_get_bits(&gb); + } + *data_size = 1; + return buf_size; +} + +AVCodec xsub_decoder = { + "xsub", + CODEC_TYPE_SUBTITLE, + CODEC_ID_XSUB, + 0, + decode_init, + NULL, + NULL, + decode_frame, +}; diff --git a/contrib/ffmpeg/libavcodec/xvid_internal.h b/contrib/ffmpeg/libavcodec/xvid_internal.h deleted file mode 100644 index 49c59c205..000000000 --- a/contrib/ffmpeg/libavcodec/xvid_internal.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * copyright (C) 2006 Corey Hickey - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef XVID_INTERNAL_H -#define XVID_INTERNAL_H - -/** - * @file xvid_internal.h - * common functions for use with the XviD wrappers - */ - - -int av_tempfile(char *prefix, char **filename); - -#endif /* XVID_INTERNAL_H */ diff --git a/contrib/ffmpeg/libavcodec/xvid_rc.c b/contrib/ffmpeg/libavcodec/xvid_rc.c deleted file mode 100644 index 6a0029e6d..000000000 --- a/contrib/ffmpeg/libavcodec/xvid_rc.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * xvid Rate control wrapper for lavc video encoders - * - * Copyright (c) 2006 Michael Niedermayer - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include "avcodec.h" -#include "xvid_internal.h" -//#include "dsputil.h" -#include "mpegvideo.h" - -#undef NDEBUG -#include - -extern unsigned int xvid_debug; - -int ff_xvid_rate_control_init(MpegEncContext *s){ - char *tmp_name; - int fd, i; - xvid_plg_create_t xvid_plg_create; - xvid_plugin_2pass2_t xvid_2pass2; - -//xvid_debug=-1; - - fd=av_tempfile("xvidrc.", &tmp_name); - if (fd == -1) { - av_log(NULL, AV_LOG_ERROR, "Can't create temporary pass2 file.\n"); - return -1; - } - - for(i=0; irc_context.num_entries; i++){ - static const char *frame_types = " ipbs"; - char tmp[256]; - RateControlEntry *rce; - - rce= &s->rc_context.entry[i]; - - snprintf(tmp, sizeof(tmp), "%c %d %d %d %d %d %d\n", - frame_types[rce->pict_type], (int)lrintf(rce->qscale / FF_QP2LAMBDA), rce->i_count, s->mb_num - rce->i_count - rce->skip_count, - rce->skip_count, (rce->i_tex_bits + rce->p_tex_bits + rce->misc_bits+7)/8, (rce->header_bits+rce->mv_bits+7)/8); - -//av_log(NULL, AV_LOG_ERROR, "%s\n", tmp); - write(fd, tmp, strlen(tmp)); - } - - close(fd); - - memset(&xvid_2pass2, 0, sizeof(xvid_2pass2)); - xvid_2pass2.version= XVID_MAKE_VERSION(1,1,0); - xvid_2pass2.filename= tmp_name; - xvid_2pass2.bitrate= s->avctx->bit_rate; - xvid_2pass2.vbv_size= s->avctx->rc_buffer_size; - xvid_2pass2.vbv_maxrate= s->avctx->rc_max_rate; - xvid_2pass2.vbv_initial= s->avctx->rc_initial_buffer_occupancy; - - memset(&xvid_plg_create, 0, sizeof(xvid_plg_create)); - xvid_plg_create.version= XVID_MAKE_VERSION(1,1,0); - xvid_plg_create.fbase= s->avctx->time_base.den; - xvid_plg_create.fincr= s->avctx->time_base.num; - xvid_plg_create.param= &xvid_2pass2; - - if(xvid_plugin_2pass2(NULL, XVID_PLG_CREATE, &xvid_plg_create, &s->rc_context.non_lavc_opaque)<0){ - av_log(NULL, AV_LOG_ERROR, "xvid_plugin_2pass2 failed\n"); - return -1; - } - return 0; -} - -float ff_xvid_rate_estimate_qscale(MpegEncContext *s, int dry_run){ - xvid_plg_data_t xvid_plg_data; - - memset(&xvid_plg_data, 0, sizeof(xvid_plg_data)); - xvid_plg_data.version= XVID_MAKE_VERSION(1,1,0); - xvid_plg_data.width = s->width; - xvid_plg_data.height= s->height; - xvid_plg_data.mb_width = s->mb_width; - xvid_plg_data.mb_height= s->mb_height; - xvid_plg_data.fbase= s->avctx->time_base.den; - xvid_plg_data.fincr= s->avctx->time_base.num; - xvid_plg_data.min_quant[0]= s->avctx->qmin; - xvid_plg_data.min_quant[1]= s->avctx->qmin; - xvid_plg_data.min_quant[2]= s->avctx->qmin; //FIXME i/b factor & offset - xvid_plg_data.max_quant[0]= s->avctx->qmax; - xvid_plg_data.max_quant[1]= s->avctx->qmax; - xvid_plg_data.max_quant[2]= s->avctx->qmax; //FIXME i/b factor & offset - xvid_plg_data.bquant_offset = 0; // 100 * s->avctx->b_quant_offset; - xvid_plg_data.bquant_ratio = 100; // * s->avctx->b_quant_factor; - -#if 0 - xvid_plg_data.stats.hlength= X -#endif - - if(!s->rc_context.dry_run_qscale){ - if(s->picture_number){ - xvid_plg_data.length= - xvid_plg_data.stats.length= (s->frame_bits + 7)/8; - xvid_plg_data.frame_num= s->rc_context.last_picture_number; - xvid_plg_data.quant= s->qscale; - - xvid_plg_data.type= s->last_pict_type; - if(xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_AFTER, &xvid_plg_data, NULL)){ - av_log(s->avctx, AV_LOG_ERROR, "xvid_plugin_2pass2(handle, XVID_PLG_AFTER, ...) FAILED\n"); - return -1; - } - } - s->rc_context.last_picture_number= - xvid_plg_data.frame_num= s->picture_number; - xvid_plg_data.quant= 0; - if(xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_BEFORE, &xvid_plg_data, NULL)){ - av_log(s->avctx, AV_LOG_ERROR, "xvid_plugin_2pass2(handle, XVID_PLG_BEFORE, ...) FAILED\n"); - return -1; - } - s->rc_context.dry_run_qscale= xvid_plg_data.quant; - } - xvid_plg_data.quant= s->rc_context.dry_run_qscale; - if(!dry_run) - s->rc_context.dry_run_qscale= 0; - - if(s->pict_type == B_TYPE) //FIXME this is not exactly identical to xvid - return xvid_plg_data.quant * FF_QP2LAMBDA * s->avctx->b_quant_factor + s->avctx->b_quant_offset; - else - return xvid_plg_data.quant * FF_QP2LAMBDA; -} - -void ff_xvid_rate_control_uninit(MpegEncContext *s){ - xvid_plg_destroy_t xvid_plg_destroy; - - xvid_plugin_2pass2(s->rc_context.non_lavc_opaque, XVID_PLG_DESTROY, &xvid_plg_destroy, NULL); -} - diff --git a/contrib/ffmpeg/libavcodec/xvidff.c b/contrib/ffmpeg/libavcodec/xvidff.c deleted file mode 100644 index 590fe4b30..000000000 --- a/contrib/ffmpeg/libavcodec/xvidff.c +++ /dev/null @@ -1,768 +0,0 @@ -/* - * Interface to xvidcore for mpeg4 encoding - * Copyright (c) 2004 Adam Thayer - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file xvidmpeg4.c - * Interface to xvidcore for MPEG-4 compliant encoding. - * @author Adam Thayer (krevnik@comcast.net) - */ - -#include -#include -#include "common.h" -#include "avcodec.h" -#include "xvid_internal.h" - -/** - * Buffer management macros. - */ -#define BUFFER_SIZE 1024 -#define BUFFER_REMAINING(x) (BUFFER_SIZE - strlen(x)) -#define BUFFER_CAT(x) (&((x)[strlen(x)])) - -/* For PPC Use */ -#if HAVE_ALTIVEC==1 -extern int has_altivec(void); -#endif - -/** - * Structure for the private XviD context. - * This stores all the private context for the codec. - */ -typedef struct xvid_context { - void *encoder_handle; /** Handle for XviD Encoder */ - int xsize, ysize; /** Frame size */ - int vop_flags; /** VOP flags for XviD Encoder */ - int vol_flags; /** VOL flags for XviD Encoder */ - int me_flags; /** Motion Estimation flags */ - int qscale; /** Do we use constant scale? */ - int quicktime_format; /** Are we in a QT-based format? */ - AVFrame encoded_picture; /** Encoded frame information */ - char *twopassbuffer; /** Character buffer for two-pass */ - char *old_twopassbuffer; /** Old character buffer (two-pass) */ - char *twopassfile; /** second pass temp file name */ - unsigned char *intra_matrix; /** P-Frame Quant Matrix */ - unsigned char *inter_matrix; /** I-Frame Quant Matrix */ -} xvid_context_t; - -/** - * Structure for the private first-pass plugin. - */ -typedef struct xvid_ff_pass1 { - int version; /** XviD version */ - xvid_context_t *context; /** Pointer to private context */ -} xvid_ff_pass1_t; - -/* Prototypes - See function implementation for details */ -int xvid_strip_vol_header(AVCodecContext *avctx, unsigned char *frame, unsigned int header_len, unsigned int frame_len); -int xvid_ff_2pass(void *ref, int opt, void *p1, void *p2); -void xvid_correct_framerate(AVCodecContext *avctx); - -/** - * Creates the private context for the encoder. - * All buffers are allocated, settings are loaded from the user, - * and the encoder context created. - * - * @param avctx AVCodecContext pointer to context - * @return Returns 0 on success, -1 on failure - */ -int ff_xvid_encode_init(AVCodecContext *avctx) { - int xerr, i; - int xvid_flags = avctx->flags; - xvid_context_t *x = avctx->priv_data; - uint16_t *intra, *inter; - int fd; - - xvid_plugin_single_t single; - xvid_ff_pass1_t rc2pass1; - xvid_plugin_2pass2_t rc2pass2; - xvid_gbl_init_t xvid_gbl_init; - xvid_enc_create_t xvid_enc_create; - xvid_enc_plugin_t plugins[7]; - - /* Bring in VOP flags from ffmpeg command-line */ - x->vop_flags = XVID_VOP_HALFPEL; /* Bare minimum quality */ - if( xvid_flags & CODEC_FLAG_4MV ) - x->vop_flags |= XVID_VOP_INTER4V; /* Level 3 */ - if( xvid_flags & CODEC_FLAG_TRELLIS_QUANT) - x->vop_flags |= XVID_VOP_TRELLISQUANT; /* Level 5 */ - if( xvid_flags & CODEC_FLAG_AC_PRED ) - x->vop_flags |= XVID_VOP_HQACPRED; /* Level 6 */ - if( xvid_flags & CODEC_FLAG_GRAY ) - x->vop_flags |= XVID_VOP_GREYSCALE; - - /* Decide which ME quality setting to use */ - x->me_flags = 0; - switch( avctx->me_method ) { - case ME_FULL: /* Quality 6 */ - x->me_flags |= XVID_ME_EXTSEARCH16 - | XVID_ME_EXTSEARCH8; - - case ME_EPZS: /* Quality 4 */ - x->me_flags |= XVID_ME_ADVANCEDDIAMOND8 - | XVID_ME_HALFPELREFINE8 - | XVID_ME_CHROMA_PVOP - | XVID_ME_CHROMA_BVOP; - - case ME_LOG: /* Quality 2 */ - case ME_PHODS: - case ME_X1: - x->me_flags |= XVID_ME_ADVANCEDDIAMOND16 - | XVID_ME_HALFPELREFINE16; - - case ME_ZERO: /* Quality 0 */ - default: - break; - } - - /* Decide how we should decide blocks */ - switch( avctx->mb_decision ) { - case 2: - x->vop_flags |= XVID_VOP_MODEDECISION_RD; - x->me_flags |= XVID_ME_HALFPELREFINE8_RD - | XVID_ME_QUARTERPELREFINE8_RD - | XVID_ME_EXTSEARCH_RD - | XVID_ME_CHECKPREDICTION_RD; - case 1: - if( !(x->vop_flags & XVID_VOP_MODEDECISION_RD) ) - x->vop_flags |= XVID_VOP_FAST_MODEDECISION_RD; - x->me_flags |= XVID_ME_HALFPELREFINE16_RD - | XVID_ME_QUARTERPELREFINE16_RD; - - default: - break; - } - - /* Bring in VOL flags from ffmpeg command-line */ - x->vol_flags = 0; - if( xvid_flags & CODEC_FLAG_GMC ) { - x->vol_flags |= XVID_VOL_GMC; - x->me_flags |= XVID_ME_GME_REFINE; - } - if( xvid_flags & CODEC_FLAG_QPEL ) { - x->vol_flags |= XVID_VOL_QUARTERPEL; - x->me_flags |= XVID_ME_QUARTERPELREFINE16; - if( x->vop_flags & XVID_VOP_INTER4V ) - x->me_flags |= XVID_ME_QUARTERPELREFINE8; - } - - memset(&xvid_gbl_init, 0, sizeof(xvid_gbl_init)); - xvid_gbl_init.version = XVID_VERSION; - xvid_gbl_init.debug = 0; - -#ifdef ARCH_POWERPC - /* XviD's PPC support is borked, use libavcodec to detect */ -#if HAVE_ALTIVEC==1 - if( has_altivec() ) { - xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ALTIVEC; - } else -#endif - xvid_gbl_init.cpu_flags = XVID_CPU_FORCE; -#else - /* XviD can detect on x86 */ - xvid_gbl_init.cpu_flags = 0; -#endif - - /* Initialize */ - xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL); - - /* Create the encoder reference */ - memset(&xvid_enc_create, 0, sizeof(xvid_enc_create)); - xvid_enc_create.version = XVID_VERSION; - - /* Store the desired frame size */ - xvid_enc_create.width = x->xsize = avctx->width; - xvid_enc_create.height = x->ysize = avctx->height; - - /* XviD can determine the proper profile to use */ - /* xvid_enc_create.profile = XVID_PROFILE_S_L3; */ - - /* We don't use zones or threads */ - xvid_enc_create.zones = NULL; - xvid_enc_create.num_zones = 0; - xvid_enc_create.num_threads = 0; - - xvid_enc_create.plugins = plugins; - xvid_enc_create.num_plugins = 0; - - /* Initialize Buffers */ - x->twopassbuffer = NULL; - x->old_twopassbuffer = NULL; - x->twopassfile = NULL; - - if( xvid_flags & CODEC_FLAG_PASS1 ) { - memset(&rc2pass1, 0, sizeof(xvid_ff_pass1_t)); - rc2pass1.version = XVID_VERSION; - rc2pass1.context = x; - x->twopassbuffer = av_malloc(BUFFER_SIZE); - x->old_twopassbuffer = av_malloc(BUFFER_SIZE); - if( x->twopassbuffer == NULL || x->old_twopassbuffer == NULL ) { - av_log(avctx, AV_LOG_ERROR, - "XviD: Cannot allocate 2-pass log buffers\n"); - return -1; - } - x->twopassbuffer[0] = x->old_twopassbuffer[0] = 0; - - plugins[xvid_enc_create.num_plugins].func = xvid_ff_2pass; - plugins[xvid_enc_create.num_plugins].param = &rc2pass1; - xvid_enc_create.num_plugins++; - } else if( xvid_flags & CODEC_FLAG_PASS2 ) { - memset(&rc2pass2, 0, sizeof(xvid_plugin_2pass2_t)); - rc2pass2.version = XVID_VERSION; - rc2pass2.bitrate = avctx->bit_rate; - - fd = av_tempfile("xvidff.", &(x->twopassfile)); - if( fd == -1 ) { - av_log(avctx, AV_LOG_ERROR, - "XviD: Cannot write 2-pass pipe\n"); - return -1; - } - - if( avctx->stats_in == NULL ) { - av_log(avctx, AV_LOG_ERROR, - "XviD: No 2-pass information loaded for second pass\n"); - return -1; - } - - if( strlen(avctx->stats_in) > - write(fd, avctx->stats_in, strlen(avctx->stats_in)) ) { - close(fd); - av_log(avctx, AV_LOG_ERROR, - "XviD: Cannot write to 2-pass pipe\n"); - return -1; - } - - close(fd); - rc2pass2.filename = x->twopassfile; - plugins[xvid_enc_create.num_plugins].func = xvid_plugin_2pass2; - plugins[xvid_enc_create.num_plugins].param = &rc2pass2; - xvid_enc_create.num_plugins++; - } else if( !(xvid_flags & CODEC_FLAG_QSCALE) ) { - /* Single Pass Bitrate Control! */ - memset(&single, 0, sizeof(xvid_plugin_single_t)); - single.version = XVID_VERSION; - single.bitrate = avctx->bit_rate; - - plugins[xvid_enc_create.num_plugins].func = xvid_plugin_single; - plugins[xvid_enc_create.num_plugins].param = &single; - xvid_enc_create.num_plugins++; - } - - /* Luminance Masking */ - if( 0.0 != avctx->lumi_masking ) { - plugins[xvid_enc_create.num_plugins].func = xvid_plugin_lumimasking; - plugins[xvid_enc_create.num_plugins].param = NULL; - xvid_enc_create.num_plugins++; - } - - /* Frame Rate and Key Frames */ - xvid_correct_framerate(avctx); - xvid_enc_create.fincr = avctx->time_base.num; - xvid_enc_create.fbase = avctx->time_base.den; - if( avctx->gop_size > 0 ) - xvid_enc_create.max_key_interval = avctx->gop_size; - else - xvid_enc_create.max_key_interval = 240; /* XviD's best default */ - - /* Quants */ - if( xvid_flags & CODEC_FLAG_QSCALE ) x->qscale = 1; - else x->qscale = 0; - - xvid_enc_create.min_quant[0] = avctx->qmin; - xvid_enc_create.min_quant[1] = avctx->qmin; - xvid_enc_create.min_quant[2] = avctx->qmin; - xvid_enc_create.max_quant[0] = avctx->qmax; - xvid_enc_create.max_quant[1] = avctx->qmax; - xvid_enc_create.max_quant[2] = avctx->qmax; - - /* Quant Matrices */ - x->intra_matrix = x->inter_matrix = NULL; - if( avctx->mpeg_quant ) - x->vol_flags |= XVID_VOL_MPEGQUANT; - if( (avctx->intra_matrix || avctx->inter_matrix) ) { - x->vol_flags |= XVID_VOL_MPEGQUANT; - - if( avctx->intra_matrix ) { - intra = avctx->intra_matrix; - x->intra_matrix = av_malloc(sizeof(unsigned char) * 64); - } else - intra = NULL; - if( avctx->inter_matrix ) { - inter = avctx->inter_matrix; - x->inter_matrix = av_malloc(sizeof(unsigned char) * 64); - } else - inter = NULL; - - for( i = 0; i < 64; i++ ) { - if( intra ) - x->intra_matrix[i] = (unsigned char)intra[i]; - if( inter ) - x->inter_matrix[i] = (unsigned char)inter[i]; - } - } - - /* Misc Settings */ - xvid_enc_create.frame_drop_ratio = 0; - xvid_enc_create.global = 0; - if( xvid_flags & CODEC_FLAG_CLOSED_GOP ) - xvid_enc_create.global |= XVID_GLOBAL_CLOSED_GOP; - - /* Determines which codec mode we are operating in */ - avctx->extradata = NULL; - avctx->extradata_size = 0; - if( xvid_flags & CODEC_FLAG_GLOBAL_HEADER ) { - /* In this case, we are claiming to be MPEG4 */ - x->quicktime_format = 1; - avctx->codec_id = CODEC_ID_MPEG4; - } else { - /* We are claiming to be XviD */ - x->quicktime_format = 0; - if(!avctx->codec_tag) - avctx->codec_tag = ff_get_fourcc("xvid"); - } - - /* Bframes */ - xvid_enc_create.max_bframes = avctx->max_b_frames; - xvid_enc_create.bquant_offset = 100 * avctx->b_quant_offset; - xvid_enc_create.bquant_ratio = 100 * avctx->b_quant_factor; - if( avctx->max_b_frames > 0 && !x->quicktime_format ) xvid_enc_create.global |= XVID_GLOBAL_PACKED; - - /* Create encoder context */ - xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); - if( xerr ) { - av_log(avctx, AV_LOG_ERROR, "XviD: Could not create encoder reference\n"); - return -1; - } - - x->encoder_handle = xvid_enc_create.handle; - avctx->coded_frame = &x->encoded_picture; - - return 0; -} - -/** - * Encodes a single frame. - * - * @param avctx AVCodecContext pointer to context - * @param frame Pointer to encoded frame buffer - * @param buf_size Size of encoded frame buffer - * @param data Pointer to AVFrame of unencoded frame - * @return Returns 0 on success, -1 on failure - */ -int ff_xvid_encode_frame(AVCodecContext *avctx, - unsigned char *frame, int buf_size, void *data) { - int xerr, i; - char *tmp; - xvid_context_t *x = avctx->priv_data; - AVFrame *picture = data; - AVFrame *p = &(x->encoded_picture); - - xvid_enc_frame_t xvid_enc_frame; - xvid_enc_stats_t xvid_enc_stats; - - /* Start setting up the frame */ - memset(&xvid_enc_frame, 0, sizeof(xvid_enc_frame)); - xvid_enc_frame.version = XVID_VERSION; - memset(&xvid_enc_stats, 0, sizeof(xvid_enc_stats)); - xvid_enc_stats.version = XVID_VERSION; - *p = *picture; - - /* Let XviD know where to put the frame. */ - xvid_enc_frame.bitstream = frame; - xvid_enc_frame.length = buf_size; - - /* Initialize input image fields */ - if( avctx->pix_fmt != PIX_FMT_YUV420P ) { - av_log(avctx, AV_LOG_ERROR, "XviD: Color spaces other than 420p not supported\n"); - return -1; - } - - xvid_enc_frame.input.csp = XVID_CSP_PLANAR; /* YUV420P */ - - for( i = 0; i < 4; i++ ) { - xvid_enc_frame.input.plane[i] = picture->data[i]; - xvid_enc_frame.input.stride[i] = picture->linesize[i]; - } - - /* Encoder Flags */ - xvid_enc_frame.vop_flags = x->vop_flags; - xvid_enc_frame.vol_flags = x->vol_flags; - xvid_enc_frame.motion = x->me_flags; - xvid_enc_frame.type = XVID_TYPE_AUTO; - - /* Quant Setting */ - if( x->qscale ) xvid_enc_frame.quant = picture->quality / FF_QP2LAMBDA; - else xvid_enc_frame.quant = 0; - - /* Matrices */ - xvid_enc_frame.quant_intra_matrix = x->intra_matrix; - xvid_enc_frame.quant_inter_matrix = x->inter_matrix; - - /* Encode */ - xerr = xvid_encore(x->encoder_handle, XVID_ENC_ENCODE, - &xvid_enc_frame, &xvid_enc_stats); - - /* Two-pass log buffer swapping */ - avctx->stats_out = NULL; - if( x->twopassbuffer ) { - tmp = x->old_twopassbuffer; - x->old_twopassbuffer = x->twopassbuffer; - x->twopassbuffer = tmp; - x->twopassbuffer[0] = 0; - if( x->old_twopassbuffer[0] != 0 ) { - avctx->stats_out = x->old_twopassbuffer; - } - } - - if( 0 <= xerr ) { - p->quality = xvid_enc_stats.quant * FF_QP2LAMBDA; - if( xvid_enc_stats.type == XVID_TYPE_PVOP ) - p->pict_type = FF_P_TYPE; - else if( xvid_enc_stats.type == XVID_TYPE_BVOP ) - p->pict_type = FF_B_TYPE; - else if( xvid_enc_stats.type == XVID_TYPE_SVOP ) - p->pict_type = FF_S_TYPE; - else - p->pict_type = FF_I_TYPE; - if( xvid_enc_frame.out_flags & XVID_KEYFRAME ) { - p->key_frame = 1; - if( x->quicktime_format ) - return xvid_strip_vol_header(avctx, frame, - xvid_enc_stats.hlength, xerr); - } else - p->key_frame = 0; - - return xerr; - } else { - av_log(avctx, AV_LOG_ERROR, "XviD: Encoding Error Occurred: %i\n", xerr); - return -1; - } -} - -/** - * Destroys the private context for the encoder. - * All buffers are freed, and the XviD encoder context is destroyed. - * - * @param avctx AVCodecContext pointer to context - * @return Returns 0, success guaranteed - */ -int ff_xvid_encode_close(AVCodecContext *avctx) { - xvid_context_t *x = avctx->priv_data; - - xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL); - - if( avctx->extradata != NULL ) - av_free(avctx->extradata); - if( x->twopassbuffer != NULL ) { - av_free(x->twopassbuffer); - av_free(x->old_twopassbuffer); - } - if( x->twopassfile != NULL ) - av_free(x->twopassfile); - if( x->intra_matrix != NULL ) - av_free(x->intra_matrix); - if( x->inter_matrix != NULL ) - av_free(x->inter_matrix); - - return 0; -} - -/** - * Routine to create a global VO/VOL header for MP4 container. - * What we do here is extract the header from the XviD bitstream - * as it is encoded. We also strip the repeated headers from the - * bitstream when a global header is requested for MPEG-4 ISO - * compliance. - * - * @param avctx AVCodecContext pointer to context - * @param frame Pointer to encoded frame data - * @param header_len Length of header to search - * @param frame_len Length of encoded frame data - * @return Returns new length of frame data - */ -int xvid_strip_vol_header(AVCodecContext *avctx, - unsigned char *frame, - unsigned int header_len, - unsigned int frame_len) { - int vo_len = 0, i; - - for( i = 0; i < header_len - 3; i++ ) { - if( frame[i] == 0x00 && - frame[i+1] == 0x00 && - frame[i+2] == 0x01 && - frame[i+3] == 0xB6 ) { - vo_len = i; - break; - } - } - - if( vo_len > 0 ) { - /* We need to store the header, so extract it */ - if( avctx->extradata == NULL ) { - avctx->extradata = av_malloc(vo_len); - memcpy(avctx->extradata, frame, vo_len); - avctx->extradata_size = vo_len; - } - /* Less dangerous now, memmove properly copies the two - chunks of overlapping data */ - memmove(frame, &(frame[vo_len]), frame_len - vo_len); - return frame_len - vo_len; - } else - return frame_len; -} - -/** - * Routine to correct a possibly erroneous framerate being fed to us. - * XviD currently chokes on framerates where the ticks per frame is - * extremely large. This function works to correct problems in this area - * by estimating a new framerate and taking the simpler fraction of - * the two presented. - * - * @param avctx Context that contains the framerate to correct. - */ -void xvid_correct_framerate(AVCodecContext *avctx) { - int frate, fbase; - int est_frate, est_fbase; - int gcd; - float est_fps, fps; - - frate = avctx->time_base.den; - fbase = avctx->time_base.num; - - gcd = ff_gcd(frate, fbase); - if( gcd > 1 ) { - frate /= gcd; - fbase /= gcd; - } - - if( frate <= 65000 && fbase <= 65000 ) { - avctx->time_base.den = frate; - avctx->time_base.num = fbase; - return; - } - - fps = (float)frate / (float)fbase; - est_fps = roundf(fps * 1000.0) / 1000.0; - - est_frate = (int)est_fps; - if( est_fps > (int)est_fps ) { - est_frate = (est_frate + 1) * 1000; - est_fbase = (int)roundf((float)est_frate / est_fps); - } else - est_fbase = 1; - - gcd = ff_gcd(est_frate, est_fbase); - if( gcd > 1 ) { - est_frate /= gcd; - est_fbase /= gcd; - } - - if( fbase > est_fbase ) { - avctx->time_base.den = est_frate; - avctx->time_base.num = est_fbase; - av_log(avctx, AV_LOG_DEBUG, - "XviD: framerate re-estimated: %.2f, %.3f%% correction\n", - est_fps, (((est_fps - fps)/fps) * 100.0)); - } else { - avctx->time_base.den = frate; - avctx->time_base.num = fbase; - } -} - -/* - * XviD 2-Pass Kludge Section - * - * XviD's default 2-pass doesn't allow us to create data as we need to, so - * this section spends time replacing the first pass plugin so we can write - * statistic information as libavcodec requests in. We have another kludge - * that allows us to pass data to the second pass in XviD without a custom - * rate-control plugin. - */ - -/** - * Initializes the two-pass plugin and context. - * - * @param param Input construction parameter structure - * @param handle Private context handle - * @return Returns XVID_ERR_xxxx on failure, or 0 on success. - */ -static int xvid_ff_2pass_create(xvid_plg_create_t * param, - void ** handle) { - xvid_ff_pass1_t *x = (xvid_ff_pass1_t *)param->param; - char *log = x->context->twopassbuffer; - - /* Do a quick bounds check */ - if( log == NULL ) - return XVID_ERR_FAIL; - - /* We use snprintf() */ - /* This is because we can safely prevent a buffer overflow */ - log[0] = 0; - snprintf(log, BUFFER_REMAINING(log), - "# ffmpeg 2-pass log file, using xvid codec\n"); - snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log), - "# Do not modify. libxvidcore version: %d.%d.%d\n\n", - XVID_VERSION_MAJOR(XVID_VERSION), - XVID_VERSION_MINOR(XVID_VERSION), - XVID_VERSION_PATCH(XVID_VERSION)); - - *handle = x->context; - return 0; -} - -/** - * Destroys the two-pass plugin context. - * - * @param ref Context pointer for the plugin - * @param param Destrooy context - * @return Returns 0, success guaranteed - */ -static int xvid_ff_2pass_destroy(xvid_context_t *ref, - xvid_plg_destroy_t *param) { - /* Currently cannot think of anything to do on destruction */ - /* Still, the framework should be here for reference/use */ - if( ref->twopassbuffer != NULL ) - ref->twopassbuffer[0] = 0; - return 0; -} - -/** - * Enables fast encode mode during the first pass. - * - * @param ref Context pointer for the plugin - * @param param Frame data - * @return Returns 0, success guaranteed - */ -static int xvid_ff_2pass_before(xvid_context_t *ref, - xvid_plg_data_t *param) { - int motion_remove; - int motion_replacements; - int vop_remove; - - /* Nothing to do here, result is changed too much */ - if( param->zone && param->zone->mode == XVID_ZONE_QUANT ) - return 0; - - /* We can implement a 'turbo' first pass mode here */ - param->quant = 2; - - /* Init values */ - motion_remove = ~XVID_ME_CHROMA_PVOP & - ~XVID_ME_CHROMA_BVOP & - ~XVID_ME_EXTSEARCH16 & - ~XVID_ME_ADVANCEDDIAMOND16; - motion_replacements = XVID_ME_FAST_MODEINTERPOLATE | - XVID_ME_SKIP_DELTASEARCH | - XVID_ME_FASTREFINE16 | - XVID_ME_BFRAME_EARLYSTOP; - vop_remove = ~XVID_VOP_MODEDECISION_RD & - ~XVID_VOP_FAST_MODEDECISION_RD & - ~XVID_VOP_TRELLISQUANT & - ~XVID_VOP_INTER4V & - ~XVID_VOP_HQACPRED; - - param->vol_flags &= ~XVID_VOL_GMC; - param->vop_flags &= vop_remove; - param->motion_flags &= motion_remove; - param->motion_flags |= motion_replacements; - - return 0; -} - -/** - * Captures statistic data and writes it during first pass. - * - * @param ref Context pointer for the plugin - * @param param Statistic data - * @return Returns XVID_ERR_xxxx on failure, or 0 on success - */ -static int xvid_ff_2pass_after(xvid_context_t *ref, - xvid_plg_data_t *param) { - char *log = ref->twopassbuffer; - char *frame_types = " ipbs"; - char frame_type; - - /* Quick bounds check */ - if( log == NULL ) - return XVID_ERR_FAIL; - - /* Convert the type given to us into a character */ - if( param->type < 5 && param->type > 0 ) { - frame_type = frame_types[param->type]; - } else { - return XVID_ERR_FAIL; - } - - snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log), - "%c %d %d %d %d %d %d\n", - frame_type, param->stats.quant, param->stats.kblks, param->stats.mblks, - param->stats.ublks, param->stats.length, param->stats.hlength); - - return 0; -} - -/** - * Dispatch function for our custom plugin. - * This handles the dispatch for the XviD plugin. It passes data - * on to other functions for actual processing. - * - * @param ref Context pointer for the plugin - * @param cmd The task given for us to complete - * @param p1 First parameter (varies) - * @param p2 Second parameter (varies) - * @return Returns XVID_ERR_xxxx on failure, or 0 on success - */ -int xvid_ff_2pass(void *ref, int cmd, void *p1, void *p2) { - switch( cmd ) { - case XVID_PLG_INFO: - case XVID_PLG_FRAME: - return 0; - - case XVID_PLG_BEFORE: - return xvid_ff_2pass_before(ref, p1); - - case XVID_PLG_CREATE: - return xvid_ff_2pass_create(p1, p2); - - case XVID_PLG_AFTER: - return xvid_ff_2pass_after(ref, p1); - - case XVID_PLG_DESTROY: - return xvid_ff_2pass_destroy(ref, p1); - - default: - return XVID_ERR_FAIL; - } -} - -/** - * XviD codec definition for libavcodec. - */ -AVCodec xvid_encoder = { - "xvid", - CODEC_TYPE_VIDEO, - CODEC_ID_XVID, - sizeof(xvid_context_t), - ff_xvid_encode_init, - ff_xvid_encode_frame, - ff_xvid_encode_close, - .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, -}; diff --git a/contrib/ffmpeg/libavcodec/xvmc_render.h b/contrib/ffmpeg/libavcodec/xvmc_render.h index 37b342294..10fd56ffa 100644 --- a/contrib/ffmpeg/libavcodec/xvmc_render.h +++ b/contrib/ffmpeg/libavcodec/xvmc_render.h @@ -1,3 +1,26 @@ +/* + * Copyright (C) 2003 Ivan Kalvachev + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_XVMC_RENDER_H +#define FFMPEG_XVMC_RENDER_H + #include #include #include @@ -6,9 +29,9 @@ #include -//the surface should be shown, video driver manipulate this +//the surface should be shown, video driver manipulates this #define MP_XVMC_STATE_DISPLAY_PENDING 1 -//the surface is needed for prediction, codec manipulate this +//the surface is needed for prediction, codec manipulates this #define MP_XVMC_STATE_PREDICTION 2 //this surface is needed for subpicture rendering #define MP_XVMC_STATE_OSD_SOURCE 4 @@ -16,7 +39,7 @@ #define MP_XVMC_RENDER_MAGIC 0x1DC711C0 typedef struct{ -//these are not changed by decoder! +//these are not changed by the decoder! int magic; short * data_blocks; @@ -24,7 +47,7 @@ typedef struct{ int total_number_of_mv_blocks; int total_number_of_data_blocks; int mc_type;//XVMC_MPEG1/2/4,XVMC_H263 without XVMC_IDCT - int idct;//does we use IDCT acceleration? + int idct;//Do we use IDCT acceleration? int chroma_format;//420,422,444 int unsigned_intra;//+-128 for intra pictures after clip XvMCSurface* p_surface;//pointer to rendered surface, never changed @@ -34,17 +57,19 @@ typedef struct{ XvMCSurface* p_past_surface;//pointer to the past surface XvMCSurface* p_future_surface;//pointer to the future prediction surface - unsigned int picture_structure;//top/bottom fields or frame ! + unsigned int picture_structure;//top/bottom fields or frame! unsigned int flags;//XVMC_SECOND_FIELD - 1'st or 2'd field in the sequence unsigned int display_flags; //1,2 or 1+2 fields for XvMCPutSurface, -//these are internal communication one - int state;//0-free,1 Waiting to Display,2 Waiting for prediction - int start_mv_blocks_num;//offset in the array for the current slice,updated by vo - int filled_mv_blocks_num;//processed mv block in this slice,change by decoder +//these are internal communication ones + int state;//0-free, 1 Waiting to Display, 2 Waiting for prediction + int start_mv_blocks_num;//offset in the array for the current slice, updated by vo + int filled_mv_blocks_num;//processed mv block in this slice, changed by decoder int next_free_data_block_num;//used in add_mv_block, pointer to next free block //extensions void * p_osd_target_surface_render;//pointer to the surface where subpicture is rendered } xvmc_render_state_t; + +#endif /* FFMPEG_XVMC_RENDER_H */ diff --git a/contrib/ffmpeg/libavcodec/xvmcvideo.c b/contrib/ffmpeg/libavcodec/xvmcvideo.c index 4a0677f6e..1a112e1c8 100644 --- a/contrib/ffmpeg/libavcodec/xvmcvideo.c +++ b/contrib/ffmpeg/libavcodec/xvmcvideo.c @@ -29,10 +29,6 @@ #undef NDEBUG #include -#ifdef USE_FASTMEMCPY -#include "libvo/fastmemcpy.h" -#endif - #ifdef HAVE_XVMC //X11 includes are in the xvmc_render.h @@ -44,7 +40,7 @@ //#include "xvmc_debug.h" //set s->block -inline void XVMC_init_block(MpegEncContext *s){ +void XVMC_init_block(MpegEncContext *s){ xvmc_render_state_t * render; render = (xvmc_render_state_t*)s->current_picture.data[2]; assert(render != NULL); diff --git a/contrib/ffmpeg/libavcodec/zmbv.c b/contrib/ffmpeg/libavcodec/zmbv.c index 89b8418c5..1eb8ef00a 100644 --- a/contrib/ffmpeg/libavcodec/zmbv.c +++ b/contrib/ffmpeg/libavcodec/zmbv.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -28,12 +27,9 @@ #include #include -#include "common.h" #include "avcodec.h" -#ifdef CONFIG_ZLIB #include -#endif #define ZMBV_KEYFRAME 1 #define ZMBV_DELTAPAL 2 @@ -68,9 +64,7 @@ typedef struct ZmbvContext { int flags; int bw, bh, bx, by; int decomp_len; -#ifdef CONFIG_ZLIB z_stream zstream; -#endif int (*decode_intra)(struct ZmbvContext *c); int (*decode_xor)(struct ZmbvContext *c); } ZmbvContext; @@ -147,7 +141,7 @@ static int zmbv_decode_xor_8(ZmbvContext *c) prev += c->width * c->bh; } if(src - c->decomp_buf != c->decomp_len) - av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len); + av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", src-c->decomp_buf, c->decomp_len); return 0; } @@ -220,7 +214,7 @@ static int zmbv_decode_xor_16(ZmbvContext *c) prev += c->width * c->bh; } if(src - c->decomp_buf != c->decomp_len) - av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len); + av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", src-c->decomp_buf, c->decomp_len); return 0; } @@ -376,7 +370,7 @@ static int zmbv_decode_xor_32(ZmbvContext *c) prev += c->width * c->bh; } if(src - c->decomp_buf != c->decomp_len) - av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len); + av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", src-c->decomp_buf, c->decomp_len); return 0; } @@ -397,13 +391,11 @@ static int zmbv_decode_intra(ZmbvContext *c) return 0; } -static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) +static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size) { - ZmbvContext * const c = (ZmbvContext *)avctx->priv_data; + ZmbvContext * const c = avctx->priv_data; uint8_t *outptr; -#ifdef CONFIG_ZLIB int zret = Z_OK; // Zlib return code -#endif int len = buf_size; int hi_ver, lo_ver; @@ -475,16 +467,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 av_log(avctx, AV_LOG_ERROR, "Unsupported (for now) format %i\n", c->fmt); return -1; } -#ifdef CONFIG_ZLIB + zret = inflateReset(&c->zstream); if (zret != Z_OK) { av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); return -1; } -#else - av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n"); - return -1; -#endif /* CONFIG_ZLIB */ + c->cur = av_realloc(c->cur, avctx->width * avctx->height * (c->bpp / 8)); c->prev = av_realloc(c->prev, avctx->width * avctx->height * (c->bpp / 8)); c->bx = (c->width + c->bw - 1) / c->bw; @@ -500,7 +489,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 memcpy(c->decomp_buf, buf, len); c->decomp_size = 1; } else { // ZLIB-compressed data -#ifdef CONFIG_ZLIB c->zstream.total_in = c->zstream.total_out = 0; c->zstream.next_in = buf; c->zstream.avail_in = len; @@ -508,10 +496,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 c->zstream.avail_out = c->decomp_size; inflate(&c->zstream, Z_FINISH); c->decomp_len = c->zstream.total_out; -#else - av_log(avctx, AV_LOG_ERROR, "BUG! Zlib support not compiled in frame decoder.\n"); - return -1; -#endif } if(c->flags & ZMBV_KEYFRAME) { c->pic.key_frame = 1; @@ -537,7 +521,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 out[i * 3 + 0] = c->pal[(*src) * 3 + 0]; out[i * 3 + 1] = c->pal[(*src) * 3 + 1]; out[i * 3 + 2] = c->pal[(*src) * 3 + 2]; - *src++; + src++; } out += c->pic.linesize[0]; } @@ -580,9 +564,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 for(i = 0; i < c->width; i++) { uint32_t tmp = AV_RL32(src); src += 4; - out[i * 3 + 0] = tmp >> 16; - out[i * 3 + 1] = tmp >> 8; - out[i * 3 + 2] = tmp >> 0; + AV_WB24(out+(i*3), tmp); } out += c->pic.linesize[0]; } @@ -608,7 +590,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8 */ static int decode_init(AVCodecContext *avctx) { - ZmbvContext * const c = (ZmbvContext *)avctx->priv_data; + ZmbvContext * const c = avctx->priv_data; int zret; // Zlib return code c->avctx = avctx; @@ -622,13 +604,9 @@ static int decode_init(AVCodecContext *avctx) } c->bpp = avctx->bits_per_sample; -#ifdef CONFIG_ZLIB // Needed if zlib unused or init aborted before inflateInit memset(&(c->zstream), 0, sizeof(z_stream)); -#else - av_log(avctx, AV_LOG_ERROR, "Zlib support not compiled.\n"); - return 1; -#endif + avctx->pix_fmt = PIX_FMT_RGB24; c->decomp_size = (avctx->width + 255) * 4 * (avctx->height + 64); @@ -640,7 +618,6 @@ static int decode_init(AVCodecContext *avctx) } } -#ifdef CONFIG_ZLIB c->zstream.zalloc = Z_NULL; c->zstream.zfree = Z_NULL; c->zstream.opaque = Z_NULL; @@ -649,7 +626,6 @@ static int decode_init(AVCodecContext *avctx) av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); return 1; } -#endif return 0; } @@ -663,15 +639,13 @@ static int decode_init(AVCodecContext *avctx) */ static int decode_end(AVCodecContext *avctx) { - ZmbvContext * const c = (ZmbvContext *)avctx->priv_data; + ZmbvContext * const c = avctx->priv_data; av_freep(&c->decomp_buf); if (c->pic.data[0]) avctx->release_buffer(avctx, &c->pic); -#ifdef CONFIG_ZLIB inflateEnd(&(c->zstream)); -#endif av_freep(&c->cur); av_freep(&c->prev); diff --git a/contrib/ffmpeg/libavcodec/zmbvenc.c b/contrib/ffmpeg/libavcodec/zmbvenc.c index a79964449..ce62ece4d 100644 --- a/contrib/ffmpeg/libavcodec/zmbvenc.c +++ b/contrib/ffmpeg/libavcodec/zmbvenc.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -28,7 +27,6 @@ #include #include -#include "common.h" #include "avcodec.h" #include @@ -106,7 +104,7 @@ static int zmbv_me(ZmbvEncContext *c, uint8_t *src, int sstride, uint8_t *prev, static int encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void *data) { - ZmbvEncContext * const c = (ZmbvEncContext *)avctx->priv_data; + ZmbvEncContext * const c = avctx->priv_data; AVFrame *pict = data; AVFrame * const p = &c->pic; uint8_t *src, *prev; @@ -145,9 +143,7 @@ static int encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void if(chpal){ uint8_t tpal[3]; for(i = 0; i < 256; i++){ - tpal[0] = palptr[i] >> 16; - tpal[1] = palptr[i] >> 8; - tpal[2] = palptr[i]; + AV_WB24(tpal, palptr[i]); c->work_buf[work_size++] = tpal[0] ^ c->pal[i * 3 + 0]; c->work_buf[work_size++] = tpal[1] ^ c->pal[i * 3 + 1]; c->work_buf[work_size++] = tpal[2] ^ c->pal[i * 3 + 2]; @@ -159,9 +155,7 @@ static int encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void } if(keyframe){ for(i = 0; i < 256; i++){ - c->pal[i*3 + 0] = palptr[i] >> 16; - c->pal[i*3 + 1] = palptr[i] >> 8; - c->pal[i*3 + 2] = palptr[i]; + AV_WB24(c->pal+(i*3), palptr[i]); } memcpy(c->work_buf, c->pal, 768); memcpy(c->pal2, p->data[1], 1024); @@ -239,7 +233,7 @@ static int encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void */ static int encode_init(AVCodecContext *avctx) { - ZmbvEncContext * const c = (ZmbvEncContext *)avctx->priv_data; + ZmbvEncContext * const c = avctx->priv_data; int zret; // Zlib return code int lvl = 9; @@ -305,7 +299,7 @@ static int encode_init(AVCodecContext *avctx) */ static int encode_end(AVCodecContext *avctx) { - ZmbvEncContext * const c = (ZmbvEncContext *)avctx->priv_data; + ZmbvEncContext * const c = avctx->priv_data; av_freep(&c->comp_buf); av_freep(&c->work_buf); diff --git a/contrib/ffmpeg/libavdevice/alldevices.c b/contrib/ffmpeg/libavdevice/alldevices.c new file mode 100644 index 000000000..0334be8c5 --- /dev/null +++ b/contrib/ffmpeg/libavdevice/alldevices.c @@ -0,0 +1,50 @@ +/* + * Register all the grabbing devices. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avformat.h" +#include "avdevice.h" + +#define REGISTER_MUXER(X,x) { \ + extern AVOutputFormat x##_muxer; \ + if(ENABLE_##X##_MUXER) av_register_output_format(&x##_muxer); } +#define REGISTER_DEMUXER(X,x) { \ + extern AVInputFormat x##_demuxer; \ + if(ENABLE_##X##_DEMUXER) av_register_input_format(&x##_demuxer); } +#define REGISTER_MUXDEMUX(X,x) REGISTER_MUXER(X,x); REGISTER_DEMUXER(X,x) + +void avdevice_register_all(void) +{ + static int initialized; + + if (initialized) + return; + initialized = 1; + + /* devices */ + REGISTER_MUXDEMUX (AUDIO_BEOS, audio_beos); + REGISTER_DEMUXER (BKTR, bktr); + REGISTER_DEMUXER (DV1394, dv1394); + REGISTER_MUXDEMUX (OSS, oss); + REGISTER_DEMUXER (V4L2, v4l2); + REGISTER_DEMUXER (V4L, v4l); + REGISTER_DEMUXER (X11_GRAB_DEVICE, x11_grab_device); + + /* external libraries */ + REGISTER_DEMUXER (LIBDC1394, libdc1394); +} diff --git a/contrib/ffmpeg/libavdevice/audio.c b/contrib/ffmpeg/libavdevice/audio.c new file mode 100644 index 000000000..87ffdef12 --- /dev/null +++ b/contrib/ffmpeg/libavdevice/audio.c @@ -0,0 +1,344 @@ +/* + * Linux audio play and grab interface + * Copyright (c) 2000, 2001 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avformat.h" + +#include +#include +#include +#ifdef HAVE_SOUNDCARD_H +#include +#else +#include +#endif +#include +#include +#include +#include +#include + +#define AUDIO_BLOCK_SIZE 4096 + +typedef struct { + int fd; + int sample_rate; + int channels; + int frame_size; /* in bytes ! */ + int codec_id; + int flip_left : 1; + uint8_t buffer[AUDIO_BLOCK_SIZE]; + int buffer_ptr; +} AudioData; + +static int audio_open(AudioData *s, int is_output, const char *audio_device) +{ + int audio_fd; + int tmp, err; + char *flip = getenv("AUDIO_FLIP_LEFT"); + + if (is_output) + audio_fd = open(audio_device, O_WRONLY); + else + audio_fd = open(audio_device, O_RDONLY); + if (audio_fd < 0) { + av_log(NULL, AV_LOG_ERROR, "%s: %s\n", audio_device, strerror(errno)); + return AVERROR(EIO); + } + + if (flip && *flip == '1') { + s->flip_left = 1; + } + + /* non blocking mode */ + if (!is_output) + fcntl(audio_fd, F_SETFL, O_NONBLOCK); + + s->frame_size = AUDIO_BLOCK_SIZE; +#if 0 + tmp = (NB_FRAGMENTS << 16) | FRAGMENT_BITS; + err = ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &tmp); + if (err < 0) { + perror("SNDCTL_DSP_SETFRAGMENT"); + } +#endif + + /* select format : favour native format */ + err = ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &tmp); + +#ifdef WORDS_BIGENDIAN + if (tmp & AFMT_S16_BE) { + tmp = AFMT_S16_BE; + } else if (tmp & AFMT_S16_LE) { + tmp = AFMT_S16_LE; + } else { + tmp = 0; + } +#else + if (tmp & AFMT_S16_LE) { + tmp = AFMT_S16_LE; + } else if (tmp & AFMT_S16_BE) { + tmp = AFMT_S16_BE; + } else { + tmp = 0; + } +#endif + + switch(tmp) { + case AFMT_S16_LE: + s->codec_id = CODEC_ID_PCM_S16LE; + break; + case AFMT_S16_BE: + s->codec_id = CODEC_ID_PCM_S16BE; + break; + default: + av_log(NULL, AV_LOG_ERROR, "Soundcard does not support 16 bit sample format\n"); + close(audio_fd); + return AVERROR(EIO); + } + err=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &tmp); + if (err < 0) { + av_log(NULL, AV_LOG_ERROR, "SNDCTL_DSP_SETFMT: %s\n", strerror(errno)); + goto fail; + } + + tmp = (s->channels == 2); + err = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp); + if (err < 0) { + av_log(NULL, AV_LOG_ERROR, "SNDCTL_DSP_STEREO: %s\n", strerror(errno)); + goto fail; + } + if (tmp) + s->channels = 2; + + tmp = s->sample_rate; + err = ioctl(audio_fd, SNDCTL_DSP_SPEED, &tmp); + if (err < 0) { + av_log(NULL, AV_LOG_ERROR, "SNDCTL_DSP_SPEED: %s\n", strerror(errno)); + goto fail; + } + s->sample_rate = tmp; /* store real sample rate */ + s->fd = audio_fd; + + return 0; + fail: + close(audio_fd); + return AVERROR(EIO); +} + +static int audio_close(AudioData *s) +{ + close(s->fd); + return 0; +} + +/* sound output support */ +static int audio_write_header(AVFormatContext *s1) +{ + AudioData *s = s1->priv_data; + AVStream *st; + int ret; + + st = s1->streams[0]; + s->sample_rate = st->codec->sample_rate; + s->channels = st->codec->channels; + ret = audio_open(s, 1, s1->filename); + if (ret < 0) { + return AVERROR(EIO); + } else { + return 0; + } +} + +static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt) +{ + AudioData *s = s1->priv_data; + int len, ret; + int size= pkt->size; + uint8_t *buf= pkt->data; + + while (size > 0) { + len = AUDIO_BLOCK_SIZE - s->buffer_ptr; + if (len > size) + len = size; + memcpy(s->buffer + s->buffer_ptr, buf, len); + s->buffer_ptr += len; + if (s->buffer_ptr >= AUDIO_BLOCK_SIZE) { + for(;;) { + ret = write(s->fd, s->buffer, AUDIO_BLOCK_SIZE); + if (ret > 0) + break; + if (ret < 0 && (errno != EAGAIN && errno != EINTR)) + return AVERROR(EIO); + } + s->buffer_ptr = 0; + } + buf += len; + size -= len; + } + return 0; +} + +static int audio_write_trailer(AVFormatContext *s1) +{ + AudioData *s = s1->priv_data; + + audio_close(s); + return 0; +} + +/* grab support */ + +static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap) +{ + AudioData *s = s1->priv_data; + AVStream *st; + int ret; + + if (ap->sample_rate <= 0 || ap->channels <= 0) + return -1; + + st = av_new_stream(s1, 0); + if (!st) { + return AVERROR(ENOMEM); + } + s->sample_rate = ap->sample_rate; + s->channels = ap->channels; + + ret = audio_open(s, 0, s1->filename); + if (ret < 0) { + av_free(st); + return AVERROR(EIO); + } + + /* take real parameters */ + st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_id = s->codec_id; + st->codec->sample_rate = s->sample_rate; + st->codec->channels = s->channels; + + av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ + return 0; +} + +static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt) +{ + AudioData *s = s1->priv_data; + int ret, bdelay; + int64_t cur_time; + struct audio_buf_info abufi; + + if (av_new_packet(pkt, s->frame_size) < 0) + return AVERROR(EIO); + for(;;) { + struct timeval tv; + fd_set fds; + + tv.tv_sec = 0; + tv.tv_usec = 30 * 1000; /* 30 msecs -- a bit shorter than 1 frame at 30fps */ + + FD_ZERO(&fds); + FD_SET(s->fd, &fds); + + /* This will block until data is available or we get a timeout */ + (void) select(s->fd + 1, &fds, 0, 0, &tv); + + ret = read(s->fd, pkt->data, pkt->size); + if (ret > 0) + break; + if (ret == -1 && (errno == EAGAIN || errno == EINTR)) { + av_free_packet(pkt); + pkt->size = 0; + pkt->pts = av_gettime(); + return 0; + } + if (!(ret == 0 || (ret == -1 && (errno == EAGAIN || errno == EINTR)))) { + av_free_packet(pkt); + return AVERROR(EIO); + } + } + pkt->size = ret; + + /* compute pts of the start of the packet */ + cur_time = av_gettime(); + bdelay = ret; + if (ioctl(s->fd, SNDCTL_DSP_GETISPACE, &abufi) == 0) { + bdelay += abufi.bytes; + } + /* subtract time represented by the number of bytes in the audio fifo */ + cur_time -= (bdelay * 1000000LL) / (s->sample_rate * s->channels); + + /* convert to wanted units */ + pkt->pts = cur_time; + + if (s->flip_left && s->channels == 2) { + int i; + short *p = (short *) pkt->data; + + for (i = 0; i < ret; i += 4) { + *p = ~*p; + p += 2; + } + } + return 0; +} + +static int audio_read_close(AVFormatContext *s1) +{ + AudioData *s = s1->priv_data; + + audio_close(s); + return 0; +} + +#ifdef CONFIG_OSS_DEMUXER +AVInputFormat oss_demuxer = { + "oss", + "audio grab and output", + sizeof(AudioData), + NULL, + audio_read_header, + audio_read_packet, + audio_read_close, + .flags = AVFMT_NOFILE, +}; +#endif + +#ifdef CONFIG_OSS_MUXER +AVOutputFormat oss_muxer = { + "oss", + "audio grab and output", + "", + "", + sizeof(AudioData), + /* XXX: we make the assumption that the soundcard accepts this format */ + /* XXX: find better solution with "preinit" method, needed also in + other formats */ +#ifdef WORDS_BIGENDIAN + CODEC_ID_PCM_S16BE, +#else + CODEC_ID_PCM_S16LE, +#endif + CODEC_ID_NONE, + audio_write_header, + audio_write_packet, + audio_write_trailer, + .flags = AVFMT_NOFILE, +}; +#endif diff --git a/contrib/ffmpeg/libavdevice/avdevice.h b/contrib/ffmpeg/libavdevice/avdevice.h new file mode 100644 index 000000000..3d4a1a3c7 --- /dev/null +++ b/contrib/ffmpeg/libavdevice/avdevice.h @@ -0,0 +1,41 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_AVDEVICE_H +#define FFMPEG_AVDEVICE_H + +#define LIBAVDEVICE_VERSION_MAJOR 52 +#define LIBAVDEVICE_VERSION_MINOR 0 +#define LIBAVDEVICE_VERSION_MICRO 0 + +#define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ + LIBAVDEVICE_VERSION_MINOR, \ + LIBAVDEVICE_VERSION_MICRO) +#define LIBAVDEVICE_VERSION AV_VERSION(LIBAVDEVICE_VERSION_MAJOR, \ + LIBAVDEVICE_VERSION_MINOR, \ + LIBAVDEVICE_VERSION_MICRO) +#define LIBAVDEVICE_BUILD LIBAVDEVICE_VERSION_INT + +/** + * Initialize libavdevice and register all the input and output devices. + * @warning This function is not thread safe. + */ +void avdevice_register_all(void); + +#endif /* FFMPEG_AVDEVICE_H */ + diff --git a/contrib/ffmpeg/libavdevice/beosaudio.cpp b/contrib/ffmpeg/libavdevice/beosaudio.cpp new file mode 100644 index 000000000..d942d7e45 --- /dev/null +++ b/contrib/ffmpeg/libavdevice/beosaudio.cpp @@ -0,0 +1,465 @@ +/* + * BeOS audio play interface + * Copyright (c) 2000, 2001 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +extern "C" { +#include "avformat.h" +} + +#ifdef HAVE_BSOUNDRECORDER +#include +using namespace BPrivate::Media::Experimental; +#endif + +/* enable performance checks */ +//#define PERF_CHECK + +/* enable Media Kit latency checks */ +//#define LATENCY_CHECK + +#define AUDIO_BLOCK_SIZE 4096 +#define AUDIO_BLOCK_COUNT 8 + +#define AUDIO_BUFFER_SIZE (AUDIO_BLOCK_SIZE*AUDIO_BLOCK_COUNT) + +typedef struct { + int fd; // UNUSED + int sample_rate; + int channels; + int frame_size; /* in bytes ! */ + CodecID codec_id; + uint8_t buffer[AUDIO_BUFFER_SIZE]; + int buffer_ptr; + /* ring buffer */ + sem_id input_sem; + int input_index; + sem_id output_sem; + int output_index; + BSoundPlayer *player; +#ifdef HAVE_BSOUNDRECORDER + BSoundRecorder *recorder; +#endif + int has_quit; /* signal callbacks not to wait */ + volatile bigtime_t starve_time; +} AudioData; + +static thread_id main_thid; +static thread_id bapp_thid; +static int own_BApp_created = 0; +static int refcount = 0; + +/* create the BApplication and Run() it */ +static int32 bapp_thread(void *arg) +{ + new BApplication("application/x-vnd.ffmpeg"); + own_BApp_created = 1; + be_app->Run(); + /* kill the process group */ +// kill(0, SIGINT); +// kill(main_thid, SIGHUP); + return B_OK; +} + +/* create the BApplication only if needed */ +static void create_bapp_if_needed(void) +{ + if (refcount++ == 0) { + /* needed by libmedia */ + if (be_app == NULL) { + bapp_thid = spawn_thread(bapp_thread, "ffmpeg BApplication", B_NORMAL_PRIORITY, NULL); + resume_thread(bapp_thid); + while (!own_BApp_created) + snooze(50000); + } + } +} + +static void destroy_bapp_if_needed(void) +{ + if (--refcount == 0 && own_BApp_created) { + be_app->Lock(); + be_app->Quit(); + be_app = NULL; + } +} + +/* called back by BSoundPlayer */ +static void audioplay_callback(void *cookie, void *buffer, size_t bufferSize, const media_raw_audio_format &format) +{ + AudioData *s; + size_t len, amount; + unsigned char *buf = (unsigned char *)buffer; + + s = (AudioData *)cookie; + if (s->has_quit) + return; + while (bufferSize > 0) { +#ifdef PERF_CHECK + bigtime_t t; + t = system_time(); +#endif + len = MIN(AUDIO_BLOCK_SIZE, bufferSize); + if (acquire_sem_etc(s->output_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK) { + s->has_quit = 1; + s->player->SetHasData(false); + return; + } + amount = MIN(len, (AUDIO_BUFFER_SIZE - s->output_index)); + memcpy(buf, &s->buffer[s->output_index], amount); + s->output_index += amount; + if (s->output_index >= AUDIO_BUFFER_SIZE) { + s->output_index %= AUDIO_BUFFER_SIZE; + memcpy(buf + amount, &s->buffer[s->output_index], len - amount); + s->output_index += len-amount; + s->output_index %= AUDIO_BUFFER_SIZE; + } + release_sem_etc(s->input_sem, len, 0); +#ifdef PERF_CHECK + t = system_time() - t; + s->starve_time = MAX(s->starve_time, t); +#endif + buf += len; + bufferSize -= len; + } +} + +#ifdef HAVE_BSOUNDRECORDER +/* called back by BSoundRecorder */ +static void audiorecord_callback(void *cookie, bigtime_t timestamp, void *buffer, size_t bufferSize, const media_multi_audio_format &format) +{ + AudioData *s; + size_t len, amount; + unsigned char *buf = (unsigned char *)buffer; + + s = (AudioData *)cookie; + if (s->has_quit) + return; + + while (bufferSize > 0) { + len = MIN(bufferSize, AUDIO_BLOCK_SIZE); + //printf("acquire_sem(input, %d)\n", len); + if (acquire_sem_etc(s->input_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK) { + s->has_quit = 1; + return; + } + amount = MIN(len, (AUDIO_BUFFER_SIZE - s->input_index)); + memcpy(&s->buffer[s->input_index], buf, amount); + s->input_index += amount; + if (s->input_index >= AUDIO_BUFFER_SIZE) { + s->input_index %= AUDIO_BUFFER_SIZE; + memcpy(&s->buffer[s->input_index], buf + amount, len - amount); + s->input_index += len - amount; + } + release_sem_etc(s->output_sem, len, 0); + //printf("release_sem(output, %d)\n", len); + buf += len; + bufferSize -= len; + } +} +#endif + +static int audio_open(AudioData *s, int is_output, const char *audio_device) +{ + int p[2]; + int ret; + media_raw_audio_format format; + media_multi_audio_format iformat; + +#ifndef HAVE_BSOUNDRECORDER + if (!is_output) + return AVERROR(EIO); /* not for now */ +#endif + s->input_sem = create_sem(AUDIO_BUFFER_SIZE, "ffmpeg_ringbuffer_input"); + if (s->input_sem < B_OK) + return AVERROR(EIO); + s->output_sem = create_sem(0, "ffmpeg_ringbuffer_output"); + if (s->output_sem < B_OK) { + delete_sem(s->input_sem); + return AVERROR(EIO); + } + s->input_index = 0; + s->output_index = 0; + create_bapp_if_needed(); + s->frame_size = AUDIO_BLOCK_SIZE; + /* bump up the priority (avoid realtime though) */ + set_thread_priority(find_thread(NULL), B_DISPLAY_PRIORITY+1); +#ifdef HAVE_BSOUNDRECORDER + if (!is_output) { + bool wait_for_input = false; + if (audio_device && !strcmp(audio_device, "wait:")) + wait_for_input = true; + s->recorder = new BSoundRecorder(&iformat, wait_for_input, "ffmpeg input", audiorecord_callback); + if (wait_for_input && (s->recorder->InitCheck() == B_OK)) { + s->recorder->WaitForIncomingConnection(&iformat); + } + if (s->recorder->InitCheck() != B_OK || iformat.format != media_raw_audio_format::B_AUDIO_SHORT) { + delete s->recorder; + s->recorder = NULL; + if (s->input_sem) + delete_sem(s->input_sem); + if (s->output_sem) + delete_sem(s->output_sem); + return AVERROR(EIO); + } + s->codec_id = (iformat.byte_order == B_MEDIA_LITTLE_ENDIAN)?CODEC_ID_PCM_S16LE:CODEC_ID_PCM_S16BE; + s->channels = iformat.channel_count; + s->sample_rate = (int)iformat.frame_rate; + s->frame_size = iformat.buffer_size; + s->recorder->SetCookie(s); + s->recorder->SetVolume(1.0); + s->recorder->Start(); + return 0; + } +#endif + format = media_raw_audio_format::wildcard; + format.format = media_raw_audio_format::B_AUDIO_SHORT; + format.byte_order = B_HOST_IS_LENDIAN ? B_MEDIA_LITTLE_ENDIAN : B_MEDIA_BIG_ENDIAN; + format.channel_count = s->channels; + format.buffer_size = s->frame_size; + format.frame_rate = s->sample_rate; + s->player = new BSoundPlayer(&format, "ffmpeg output", audioplay_callback); + if (s->player->InitCheck() != B_OK) { + delete s->player; + s->player = NULL; + if (s->input_sem) + delete_sem(s->input_sem); + if (s->output_sem) + delete_sem(s->output_sem); + return AVERROR(EIO); + } + s->player->SetCookie(s); + s->player->SetVolume(1.0); + s->player->Start(); + s->player->SetHasData(true); + return 0; +} + +static int audio_close(AudioData *s) +{ + if (s->input_sem) + delete_sem(s->input_sem); + if (s->output_sem) + delete_sem(s->output_sem); + s->has_quit = 1; + if (s->player) { + s->player->Stop(); + } + if (s->player) + delete s->player; +#ifdef HAVE_BSOUNDRECORDER + if (s->recorder) + delete s->recorder; +#endif + destroy_bapp_if_needed(); + return 0; +} + +/* sound output support */ +static int audio_write_header(AVFormatContext *s1) +{ + AudioData *s = (AudioData *)s1->priv_data; + AVStream *st; + int ret; + + st = s1->streams[0]; + s->sample_rate = st->codec->sample_rate; + s->channels = st->codec->channels; + ret = audio_open(s, 1, NULL); + if (ret < 0) + return AVERROR(EIO); + return 0; +} + +static int audio_write_packet(AVFormatContext *s1, int stream_index, + const uint8_t *buf, int size, int64_t force_pts) +{ + AudioData *s = (AudioData *)s1->priv_data; + int len, ret; +#ifdef LATENCY_CHECK +bigtime_t lat1, lat2; +lat1 = s->player->Latency(); +#endif +#ifdef PERF_CHECK + bigtime_t t = s->starve_time; + s->starve_time = 0; + printf("starve_time: %lld \n", t); +#endif + while (size > 0) { + int amount; + len = MIN(size, AUDIO_BLOCK_SIZE); + if (acquire_sem_etc(s->input_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK) + return AVERROR(EIO); + amount = MIN(len, (AUDIO_BUFFER_SIZE - s->input_index)); + memcpy(&s->buffer[s->input_index], buf, amount); + s->input_index += amount; + if (s->input_index >= AUDIO_BUFFER_SIZE) { + s->input_index %= AUDIO_BUFFER_SIZE; + memcpy(&s->buffer[s->input_index], buf + amount, len - amount); + s->input_index += len - amount; + } + release_sem_etc(s->output_sem, len, 0); + buf += len; + size -= len; + } +#ifdef LATENCY_CHECK +lat2 = s->player->Latency(); +printf("#### BSoundPlayer::Latency(): before= %lld, after= %lld\n", lat1, lat2); +#endif + return 0; +} + +static int audio_write_trailer(AVFormatContext *s1) +{ + AudioData *s = (AudioData *)s1->priv_data; + + audio_close(s); + return 0; +} + +/* grab support */ + +static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap) +{ + AudioData *s = (AudioData *)s1->priv_data; + AVStream *st; + int ret; + + if (!ap || ap->sample_rate <= 0 || ap->channels <= 0) + return -1; + + st = av_new_stream(s1, 0); + if (!st) { + return AVERROR(ENOMEM); + } + s->sample_rate = ap->sample_rate; + s->channels = ap->channels; + + ret = audio_open(s, 0, s1->filename); + if (ret < 0) { + av_free(st); + return AVERROR(EIO); + } + /* take real parameters */ + st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_id = s->codec_id; + st->codec->sample_rate = s->sample_rate; + st->codec->channels = s->channels; + return 0; + av_set_pts_info(s1, 48, 1, 1000000); /* 48 bits pts in us */ +} + +static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt) +{ + AudioData *s = (AudioData *)s1->priv_data; + int size; + size_t len, amount; + unsigned char *buf; + status_t err; + + if (av_new_packet(pkt, s->frame_size) < 0) + return AVERROR(EIO); + buf = (unsigned char *)pkt->data; + size = pkt->size; + while (size > 0) { + len = MIN(AUDIO_BLOCK_SIZE, size); + //printf("acquire_sem(output, %d)\n", len); + while ((err=acquire_sem_etc(s->output_sem, len, B_CAN_INTERRUPT, 0LL)) == B_INTERRUPTED); + if (err < B_OK) { + av_free_packet(pkt); + return AVERROR(EIO); + } + amount = MIN(len, (AUDIO_BUFFER_SIZE - s->output_index)); + memcpy(buf, &s->buffer[s->output_index], amount); + s->output_index += amount; + if (s->output_index >= AUDIO_BUFFER_SIZE) { + s->output_index %= AUDIO_BUFFER_SIZE; + memcpy(buf + amount, &s->buffer[s->output_index], len - amount); + s->output_index += len-amount; + s->output_index %= AUDIO_BUFFER_SIZE; + } + release_sem_etc(s->input_sem, len, 0); + //printf("release_sem(input, %d)\n", len); + buf += len; + size -= len; + } + //XXX: add pts info + return 0; +} + +static int audio_read_close(AVFormatContext *s1) +{ + AudioData *s = (AudioData *)s1->priv_data; + + audio_close(s); + return 0; +} + +static AVInputFormat audio_beos_demuxer = { + "audio_beos", + "audio grab and output", + sizeof(AudioData), + NULL, + audio_read_header, + audio_read_packet, + audio_read_close, + NULL, + AVFMT_NOFILE, +}; + +AVOutputFormat audio_beos_muxer = { + "audio_beos", + "audio grab and output", + "", + "", + sizeof(AudioData), +#ifdef WORDS_BIGENDIAN + CODEC_ID_PCM_S16BE, +#else + CODEC_ID_PCM_S16LE, +#endif + CODEC_ID_NONE, + audio_write_header, + audio_write_packet, + audio_write_trailer, + AVFMT_NOFILE, +}; + +extern "C" { + +int audio_init(void) +{ + main_thid = find_thread(NULL); + av_register_input_format(&audio_beos_demuxer); + av_register_output_format(&audio_beos_muxer); + return 0; +} + +} // "C" + diff --git a/contrib/ffmpeg/libavdevice/bktr.c b/contrib/ffmpeg/libavdevice/bktr.c new file mode 100644 index 000000000..0ea8dfb02 --- /dev/null +++ b/contrib/ffmpeg/libavdevice/bktr.c @@ -0,0 +1,320 @@ +/* + * *BSD video grab interface + * Copyright (c) 2002 Steve O'Hara-Smith + * based on + * Linux video grab interface + * Copyright (c) 2000,2001 Gerard Lantau. + * and + * simple_grab.c Copyright (c) 1999 Roger Hardiman + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avformat.h" +#if defined (HAVE_DEV_BKTR_IOCTL_METEOR_H) && defined (HAVE_DEV_BKTR_IOCTL_BT848_H) +# include +# include +#elif defined (HAVE_MACHINE_IOCTL_METEOR_H) && defined (HAVE_MACHINE_IOCTL_BT848_H) +# include +# include +#elif defined (HAVE_DEV_VIDEO_METEOR_IOCTL_METEOR_H) && defined (HAVE_DEV_VIDEO_METEOR_IOCTL_BT848_H) +# include +# include +#elif HAVE_DEV_IC_BT8XX_H +# include +#endif +#include +#include +#include +#include +#include +#include + +typedef struct { + int video_fd; + int tuner_fd; + int width, height; + int frame_rate; + int frame_rate_base; + u_int64_t per_frame; +} VideoData; + + +#define PAL 1 +#define PALBDGHI 1 +#define NTSC 2 +#define NTSCM 2 +#define SECAM 3 +#define PALN 4 +#define PALM 5 +#define NTSCJ 6 + +/* PAL is 768 x 576. NTSC is 640 x 480 */ +#define PAL_HEIGHT 576 +#define SECAM_HEIGHT 576 +#define NTSC_HEIGHT 480 + +#ifndef VIDEO_FORMAT +#define VIDEO_FORMAT NTSC +#endif + +static int bktr_dev[] = { METEOR_DEV0, METEOR_DEV1, METEOR_DEV2, + METEOR_DEV3, METEOR_DEV_SVIDEO }; + +uint8_t *video_buf; +size_t video_buf_size; +u_int64_t last_frame_time; +volatile sig_atomic_t nsignals; + + +static void catchsignal(int signal) +{ + nsignals++; + return; +} + +static int bktr_init(const char *video_device, int width, int height, + int format, int *video_fd, int *tuner_fd, int idev, double frequency) +{ + struct meteor_geomet geo; + int h_max; + long ioctl_frequency; + char *arg; + int c; + struct sigaction act, old; + + if (idev < 0 || idev > 4) + { + arg = getenv ("BKTR_DEV"); + if (arg) + idev = atoi (arg); + if (idev < 0 || idev > 4) + idev = 1; + } + + if (format < 1 || format > 6) + { + arg = getenv ("BKTR_FORMAT"); + if (arg) + format = atoi (arg); + if (format < 1 || format > 6) + format = VIDEO_FORMAT; + } + + if (frequency <= 0) + { + arg = getenv ("BKTR_FREQUENCY"); + if (arg) + frequency = atof (arg); + if (frequency <= 0) + frequency = 0.0; + } + + memset(&act, 0, sizeof(act)); + sigemptyset(&act.sa_mask); + act.sa_handler = catchsignal; + sigaction(SIGUSR1, &act, &old); + + *tuner_fd = open("/dev/tuner0", O_RDONLY); + if (*tuner_fd < 0) + av_log(NULL, AV_LOG_ERROR, "Warning. Tuner not opened, continuing: %s\n", strerror(errno)); + + *video_fd = open(video_device, O_RDONLY); + if (*video_fd < 0) { + av_log(NULL, AV_LOG_ERROR, "%s: %s\n", video_device, strerror(errno)); + return -1; + } + + geo.rows = height; + geo.columns = width; + geo.frames = 1; + geo.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12; + + switch (format) { + case PAL: h_max = PAL_HEIGHT; c = BT848_IFORM_F_PALBDGHI; break; + case PALN: h_max = PAL_HEIGHT; c = BT848_IFORM_F_PALN; break; + case PALM: h_max = PAL_HEIGHT; c = BT848_IFORM_F_PALM; break; + case SECAM: h_max = SECAM_HEIGHT; c = BT848_IFORM_F_SECAM; break; + case NTSC: h_max = NTSC_HEIGHT; c = BT848_IFORM_F_NTSCM; break; + case NTSCJ: h_max = NTSC_HEIGHT; c = BT848_IFORM_F_NTSCJ; break; + default: h_max = PAL_HEIGHT; c = BT848_IFORM_F_PALBDGHI; break; + } + + if (height <= h_max / 2) + geo.oformat |= METEOR_GEO_EVEN_ONLY; + + if (ioctl(*video_fd, METEORSETGEO, &geo) < 0) { + av_log(NULL, AV_LOG_ERROR, "METEORSETGEO: %s\n", strerror(errno)); + return -1; + } + + if (ioctl(*video_fd, BT848SFMT, &c) < 0) { + av_log(NULL, AV_LOG_ERROR, "BT848SFMT: %s\n", strerror(errno)); + return -1; + } + + c = bktr_dev[idev]; + if (ioctl(*video_fd, METEORSINPUT, &c) < 0) { + av_log(NULL, AV_LOG_ERROR, "METEORSINPUT: %s\n", strerror(errno)); + return -1; + } + + video_buf_size = width * height * 12 / 8; + + video_buf = (uint8_t *)mmap((caddr_t)0, video_buf_size, + PROT_READ, MAP_SHARED, *video_fd, (off_t)0); + if (video_buf == MAP_FAILED) { + av_log(NULL, AV_LOG_ERROR, "mmap: %s\n", strerror(errno)); + return -1; + } + + if (frequency != 0.0) { + ioctl_frequency = (unsigned long)(frequency*16); + if (ioctl(*tuner_fd, TVTUNER_SETFREQ, &ioctl_frequency) < 0) + av_log(NULL, AV_LOG_ERROR, "TVTUNER_SETFREQ: %s\n", strerror(errno)); + } + + c = AUDIO_UNMUTE; + if (ioctl(*tuner_fd, BT848_SAUDIO, &c) < 0) + av_log(NULL, AV_LOG_ERROR, "TVTUNER_SAUDIO: %s\n", strerror(errno)); + + c = METEOR_CAP_CONTINOUS; + ioctl(*video_fd, METEORCAPTUR, &c); + + c = SIGUSR1; + ioctl(*video_fd, METEORSSIGNAL, &c); + + return 0; +} + +static void bktr_getframe(u_int64_t per_frame) +{ + u_int64_t curtime; + + curtime = av_gettime(); + if (!last_frame_time + || ((last_frame_time + per_frame) > curtime)) { + if (!usleep(last_frame_time + per_frame + per_frame / 8 - curtime)) { + if (!nsignals) + av_log(NULL, AV_LOG_INFO, + "SLEPT NO signals - %d microseconds late\n", + (int)(av_gettime() - last_frame_time - per_frame)); + } + } + nsignals = 0; + last_frame_time = curtime; +} + + +/* note: we support only one picture read at a time */ +static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt) +{ + VideoData *s = s1->priv_data; + + if (av_new_packet(pkt, video_buf_size) < 0) + return AVERROR(EIO); + + bktr_getframe(s->per_frame); + + pkt->pts = av_gettime(); + memcpy(pkt->data, video_buf, video_buf_size); + + return video_buf_size; +} + +static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) +{ + VideoData *s = s1->priv_data; + AVStream *st; + int width, height; + int frame_rate; + int frame_rate_base; + int format = -1; + + if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) + return -1; + + width = ap->width; + height = ap->height; + frame_rate = ap->time_base.den; + frame_rate_base = ap->time_base.num; + + st = av_new_stream(s1, 0); + if (!st) + return AVERROR(ENOMEM); + av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in use */ + + s->width = width; + s->height = height; + s->frame_rate = frame_rate; + s->frame_rate_base = frame_rate_base; + s->per_frame = ((u_int64_t)1000000 * s->frame_rate_base) / s->frame_rate; + + st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->pix_fmt = PIX_FMT_YUV420P; + st->codec->codec_id = CODEC_ID_RAWVIDEO; + st->codec->width = width; + st->codec->height = height; + st->codec->time_base.den = frame_rate; + st->codec->time_base.num = frame_rate_base; + + if (ap->standard) { + if (!strcasecmp(ap->standard, "pal")) + format = PAL; + else if (!strcasecmp(ap->standard, "secam")) + format = SECAM; + else if (!strcasecmp(ap->standard, "ntsc")) + format = NTSC; + } + + if (bktr_init(s1->filename, width, height, format, + &(s->video_fd), &(s->tuner_fd), -1, 0.0) < 0) + return AVERROR(EIO); + + nsignals = 0; + last_frame_time = 0; + + return 0; +} + +static int grab_read_close(AVFormatContext *s1) +{ + VideoData *s = s1->priv_data; + int c; + + c = METEOR_CAP_STOP_CONT; + ioctl(s->video_fd, METEORCAPTUR, &c); + close(s->video_fd); + + c = AUDIO_MUTE; + ioctl(s->tuner_fd, BT848_SAUDIO, &c); + close(s->tuner_fd); + + munmap((caddr_t)video_buf, video_buf_size); + + return 0; +} + +AVInputFormat bktr_demuxer = { + "bktr", + "video grab", + sizeof(VideoData), + NULL, + grab_read_header, + grab_read_packet, + grab_read_close, + .flags = AVFMT_NOFILE, +}; diff --git a/contrib/ffmpeg/libavdevice/dv1394.c b/contrib/ffmpeg/libavdevice/dv1394.c new file mode 100644 index 000000000..8e2e2f607 --- /dev/null +++ b/contrib/ffmpeg/libavdevice/dv1394.c @@ -0,0 +1,236 @@ +/* + * Linux DV1394 interface + * Copyright (c) 2003 Max Krasnyansky + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "avformat.h" + +#undef DV1394_DEBUG + +#include "dv1394.h" +#include "dv.h" + +struct dv1394_data { + int fd; + int channel; + int format; + + uint8_t *ring; /* Ring buffer */ + int index; /* Current frame index */ + int avail; /* Number of frames available for reading */ + int done; /* Number of completed frames */ + + DVDemuxContext* dv_demux; /* Generic DV muxing/demuxing context */ +}; + +/* + * The trick here is to kludge around well known problem with kernel Ooopsing + * when you try to capture PAL on a device node configure for NTSC. That's + * why we have to configure the device node for PAL, and then read only NTSC + * amount of data. + */ +static int dv1394_reset(struct dv1394_data *dv) +{ + struct dv1394_init init; + + init.channel = dv->channel; + init.api_version = DV1394_API_VERSION; + init.n_frames = DV1394_RING_FRAMES; + init.format = DV1394_PAL; + + if (ioctl(dv->fd, DV1394_INIT, &init) < 0) + return -1; + + dv->avail = dv->done = 0; + return 0; +} + +static int dv1394_start(struct dv1394_data *dv) +{ + /* Tell DV1394 driver to enable receiver */ + if (ioctl(dv->fd, DV1394_START_RECEIVE, 0) < 0) { + av_log(NULL, AV_LOG_ERROR, "Failed to start receiver: %s\n", strerror(errno)); + return -1; + } + return 0; +} + +static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap) +{ + struct dv1394_data *dv = context->priv_data; + + dv->dv_demux = dv_init_demux(context); + if (!dv->dv_demux) + goto failed; + + if (ap->standard && !strcasecmp(ap->standard, "pal")) + dv->format = DV1394_PAL; + else + dv->format = DV1394_NTSC; + + if (ap->channel) + dv->channel = ap->channel; + else + dv->channel = DV1394_DEFAULT_CHANNEL; + + /* Open and initialize DV1394 device */ + dv->fd = open(context->filename, O_RDONLY); + if (dv->fd < 0) { + av_log(context, AV_LOG_ERROR, "Failed to open DV interface: %s\n", strerror(errno)); + goto failed; + } + + if (dv1394_reset(dv) < 0) { + av_log(context, AV_LOG_ERROR, "Failed to initialize DV interface: %s\n", strerror(errno)); + goto failed; + } + + dv->ring = mmap(NULL, DV1394_PAL_FRAME_SIZE * DV1394_RING_FRAMES, + PROT_READ, MAP_PRIVATE, dv->fd, 0); + if (dv->ring == MAP_FAILED) { + av_log(context, AV_LOG_ERROR, "Failed to mmap DV ring buffer: %s\n", strerror(errno)); + goto failed; + } + + if (dv1394_start(dv) < 0) + goto failed; + + return 0; + +failed: + close(dv->fd); + return AVERROR(EIO); +} + +static int dv1394_read_packet(AVFormatContext *context, AVPacket *pkt) +{ + struct dv1394_data *dv = context->priv_data; + int size; + + size = dv_get_packet(dv->dv_demux, pkt); + if (size > 0) + return size; + + if (!dv->avail) { + struct dv1394_status s; + struct pollfd p; + + if (dv->done) { + /* Request more frames */ + if (ioctl(dv->fd, DV1394_RECEIVE_FRAMES, dv->done) < 0) { + /* This usually means that ring buffer overflowed. + * We have to reset :(. + */ + + av_log(context, AV_LOG_ERROR, "DV1394: Ring buffer overflow. Reseting ..\n"); + + dv1394_reset(dv); + dv1394_start(dv); + } + dv->done = 0; + } + + /* Wait until more frames are available */ +restart_poll: + p.fd = dv->fd; + p.events = POLLIN | POLLERR | POLLHUP; + if (poll(&p, 1, -1) < 0) { + if (errno == EAGAIN || errno == EINTR) + goto restart_poll; + av_log(context, AV_LOG_ERROR, "Poll failed: %s\n", strerror(errno)); + return AVERROR(EIO); + } + + if (ioctl(dv->fd, DV1394_GET_STATUS, &s) < 0) { + av_log(context, AV_LOG_ERROR, "Failed to get status: %s\n", strerror(errno)); + return AVERROR(EIO); + } +#ifdef DV1394_DEBUG + av_log(context, AV_LOG_DEBUG, "DV1394: status\n" + "\tactive_frame\t%d\n" + "\tfirst_clear_frame\t%d\n" + "\tn_clear_frames\t%d\n" + "\tdropped_frames\t%d\n", + s.active_frame, s.first_clear_frame, + s.n_clear_frames, s.dropped_frames); +#endif + + dv->avail = s.n_clear_frames; + dv->index = s.first_clear_frame; + dv->done = 0; + + if (s.dropped_frames) { + av_log(context, AV_LOG_ERROR, "DV1394: Frame drop detected (%d). Reseting ..\n", + s.dropped_frames); + + dv1394_reset(dv); + dv1394_start(dv); + } + } + +#ifdef DV1394_DEBUG + av_log(context, AV_LOG_DEBUG, "index %d, avail %d, done %d\n", dv->index, dv->avail, + dv->done); +#endif + + size = dv_produce_packet(dv->dv_demux, pkt, + dv->ring + (dv->index * DV1394_PAL_FRAME_SIZE), + DV1394_PAL_FRAME_SIZE); + dv->index = (dv->index + 1) % DV1394_RING_FRAMES; + dv->done++; dv->avail--; + + return size; +} + +static int dv1394_close(AVFormatContext * context) +{ + struct dv1394_data *dv = context->priv_data; + + /* Shutdown DV1394 receiver */ + if (ioctl(dv->fd, DV1394_SHUTDOWN, 0) < 0) + av_log(context, AV_LOG_ERROR, "Failed to shutdown DV1394: %s\n", strerror(errno)); + + /* Unmap ring buffer */ + if (munmap(dv->ring, DV1394_NTSC_FRAME_SIZE * DV1394_RING_FRAMES) < 0) + av_log(context, AV_LOG_ERROR, "Failed to munmap DV1394 ring buffer: %s\n", strerror(errno)); + + close(dv->fd); + av_free(dv->dv_demux); + + return 0; +} + +AVInputFormat dv1394_demuxer = { + .name = "dv1394", + .long_name = "dv1394 A/V grab", + .priv_data_size = sizeof(struct dv1394_data), + .read_header = dv1394_read_header, + .read_packet = dv1394_read_packet, + .read_close = dv1394_close, + .flags = AVFMT_NOFILE +}; diff --git a/contrib/ffmpeg/libavdevice/dv1394.h b/contrib/ffmpeg/libavdevice/dv1394.h new file mode 100644 index 000000000..7f3521d6e --- /dev/null +++ b/contrib/ffmpeg/libavdevice/dv1394.h @@ -0,0 +1,356 @@ +/* + * dv1394.h - DV input/output over IEEE 1394 on OHCI chips + * Copyright (C)2001 Daniel Maas + * receive, proc_fs by Dan Dennedy + * + * based on: + * video1394.h - driver for OHCI 1394 boards + * Copyright (C)1999,2000 Sebastien Rougeaux + * Peter Schlaile + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_DV1394_H +#define FFMPEG_DV1394_H + +#define DV1394_DEFAULT_CHANNEL 63 +#define DV1394_DEFAULT_CARD 0 +#define DV1394_RING_FRAMES 20 + +#define DV1394_WIDTH 720 +#define DV1394_NTSC_HEIGHT 480 +#define DV1394_PAL_HEIGHT 576 + +/* This is the public user-space interface. Try not to break it. */ + +#define DV1394_API_VERSION 0x20011127 + +/* ******************** + ** ** + ** DV1394 API ** + ** ** + ******************** + + There are two methods of operating the DV1394 DV output device. + + 1) + + The simplest is an interface based on write(): simply write + full DV frames of data to the device, and they will be transmitted + as quickly as possible. The FD may be set for non-blocking I/O, + in which case you can use select() or poll() to wait for output + buffer space. + + To set the DV output parameters (e.g. whether you want NTSC or PAL + video), use the DV1394_INIT ioctl, passing in the parameters you + want in a struct dv1394_init. + + Example 1: + To play a raw .DV file: cat foo.DV > /dev/dv1394 + (cat will use write() internally) + + Example 2: + static struct dv1394_init init = { + 0x63, (broadcast channel) + 4, (four-frame ringbuffer) + DV1394_NTSC, (send NTSC video) + 0, 0 (default empty packet rate) + } + + ioctl(fd, DV1394_INIT, &init); + + while(1) { + read( , buf, DV1394_NTSC_FRAME_SIZE ); + write( , buf, DV1394_NTSC_FRAME_SIZE ); + } + + 2) + + For more control over buffering, and to avoid unnecessary copies + of the DV data, you can use the more sophisticated the mmap() interface. + First, call the DV1394_INIT ioctl to specify your parameters, + including the number of frames in the ringbuffer. Then, calling mmap() + on the dv1394 device will give you direct access to the ringbuffer + from which the DV card reads your frame data. + + The ringbuffer is simply one large, contiguous region of memory + containing two or more frames of packed DV data. Each frame of DV data + is 120000 bytes (NTSC) or 144000 bytes (PAL). + + Fill one or more frames in the ringbuffer, then use the DV1394_SUBMIT_FRAMES + ioctl to begin I/O. You can use either the DV1394_WAIT_FRAMES ioctl + or select()/poll() to wait until the frames are transmitted. Next, you'll + need to call the DV1394_GET_STATUS ioctl to determine which ringbuffer + frames are clear (ready to be filled with new DV data). Finally, use + DV1394_SUBMIT_FRAMES again to send the new data to the DV output. + + + Example: here is what a four-frame ringbuffer might look like + during DV transmission: + + + frame 0 frame 1 frame 2 frame 3 + + *--------------------------------------* + | CLEAR | DV data | DV data | CLEAR | + *--------------------------------------* + + + transmission goes in this direction --->>> + + + The DV hardware is currently transmitting the data in frame 1. + Once frame 1 is finished, it will automatically transmit frame 2. + (if frame 2 finishes before frame 3 is submitted, the device + will continue to transmit frame 2, and will increase the dropped_frames + counter each time it repeats the transmission). + + + If you called DV1394_GET_STATUS at this instant, you would + receive the following values: + + n_frames = 4 + active_frame = 1 + first_clear_frame = 3 + n_clear_frames = 2 + + At this point, you should write new DV data into frame 3 and optionally + frame 0. Then call DV1394_SUBMIT_FRAMES to inform the device that + it may transmit the new frames. + + ERROR HANDLING + + An error (buffer underflow/overflow or a break in the DV stream due + to a 1394 bus reset) can be detected by checking the dropped_frames + field of struct dv1394_status (obtained through the + DV1394_GET_STATUS ioctl). + + The best way to recover from such an error is to re-initialize + dv1394, either by using the DV1394_INIT ioctl call, or closing the + file descriptor and opening it again. (note that you must unmap all + ringbuffer mappings when closing the file descriptor, or else + dv1394 will still be considered 'in use'). + + MAIN LOOP + + For maximum efficiency and robustness against bus errors, you are + advised to model the main loop of your application after the + following pseudo-code example: + + (checks of system call return values omitted for brevity; always + check return values in your code!) + + while( frames left ) { + + struct pollfd *pfd = ...; + + pfd->fd = dv1394_fd; + pfd->revents = 0; + pfd->events = POLLOUT | POLLIN; (OUT for transmit, IN for receive) + + (add other sources of I/O here) + + poll(pfd, 1, -1); (or select(); add a timeout if you want) + + if(pfd->revents) { + struct dv1394_status status; + + ioctl(dv1394_fd, DV1394_GET_STATUS, &status); + + if(status.dropped_frames > 0) { + reset_dv1394(); + } else { + for(int i = 0; i < status.n_clear_frames; i++) { + copy_DV_frame(); + } + } + } + } + + where copy_DV_frame() reads or writes on the dv1394 file descriptor + (read/write mode) or copies data to/from the mmap ringbuffer and + then calls ioctl(DV1394_SUBMIT_FRAMES) to notify dv1394 that new + frames are availble (mmap mode). + + reset_dv1394() is called in the event of a buffer + underflow/overflow or a halt in the DV stream (e.g. due to a 1394 + bus reset). To guarantee recovery from the error, this function + should close the dv1394 file descriptor (and munmap() all + ringbuffer mappings, if you are using them), then re-open the + dv1394 device (and re-map the ringbuffer). + +*/ + + +/* maximum number of frames in the ringbuffer */ +#define DV1394_MAX_FRAMES 32 + +/* number of *full* isochronous packets per DV frame */ +#define DV1394_NTSC_PACKETS_PER_FRAME 250 +#define DV1394_PAL_PACKETS_PER_FRAME 300 + +/* size of one frame's worth of DV data, in bytes */ +#define DV1394_NTSC_FRAME_SIZE (480 * DV1394_NTSC_PACKETS_PER_FRAME) +#define DV1394_PAL_FRAME_SIZE (480 * DV1394_PAL_PACKETS_PER_FRAME) + + +/* ioctl() commands */ + +enum { + /* I don't like using 0 as a valid ioctl() */ + DV1394_INVALID = 0, + + + /* get the driver ready to transmit video. + pass a struct dv1394_init* as the parameter (see below), + or NULL to get default parameters */ + DV1394_INIT, + + + /* stop transmitting video and free the ringbuffer */ + DV1394_SHUTDOWN, + + + /* submit N new frames to be transmitted, where + the index of the first new frame is first_clear_buffer, + and the index of the last new frame is + (first_clear_buffer + N) % n_frames */ + DV1394_SUBMIT_FRAMES, + + + /* block until N buffers are clear (pass N as the parameter) + Because we re-transmit the last frame on underrun, there + will at most be n_frames - 1 clear frames at any time */ + DV1394_WAIT_FRAMES, + + /* capture new frames that have been received, where + the index of the first new frame is first_clear_buffer, + and the index of the last new frame is + (first_clear_buffer + N) % n_frames */ + DV1394_RECEIVE_FRAMES, + + + DV1394_START_RECEIVE, + + + /* pass a struct dv1394_status* as the parameter (see below) */ + DV1394_GET_STATUS, +}; + + + +enum pal_or_ntsc { + DV1394_NTSC = 0, + DV1394_PAL +}; + + + + +/* this is the argument to DV1394_INIT */ +struct dv1394_init { + /* DV1394_API_VERSION */ + unsigned int api_version; + + /* isochronous transmission channel to use */ + unsigned int channel; + + /* number of frames in the ringbuffer. Must be at least 2 + and at most DV1394_MAX_FRAMES. */ + unsigned int n_frames; + + /* send/receive PAL or NTSC video format */ + enum pal_or_ntsc format; + + /* the following are used only for transmission */ + + /* set these to zero unless you want a + non-default empty packet rate (see below) */ + unsigned long cip_n; + unsigned long cip_d; + + /* set this to zero unless you want a + non-default SYT cycle offset (default = 3 cycles) */ + unsigned int syt_offset; +}; + +/* NOTE: you may only allocate the DV frame ringbuffer once each time + you open the dv1394 device. DV1394_INIT will fail if you call it a + second time with different 'n_frames' or 'format' arguments (which + would imply a different size for the ringbuffer). If you need a + different buffer size, simply close and re-open the device, then + initialize it with your new settings. */ + +/* Q: What are cip_n and cip_d? */ + +/* + A: DV video streams do not utilize 100% of the potential bandwidth offered + by IEEE 1394 (FireWire). To achieve the correct rate of data transmission, + DV devices must periodically insert empty packets into the 1394 data stream. + Typically there is one empty packet per 14-16 data-carrying packets. + + Some DV devices will accept a wide range of empty packet rates, while others + require a precise rate. If the dv1394 driver produces empty packets at + a rate that your device does not accept, you may see ugly patterns on the + DV output, or even no output at all. + + The default empty packet insertion rate seems to work for many people; if + your DV output is stable, you can simply ignore this discussion. However, + we have exposed the empty packet rate as a parameter to support devices that + do not work with the default rate. + + The decision to insert an empty packet is made with a numerator/denominator + algorithm. Empty packets are produced at an average rate of CIP_N / CIP_D. + You can alter the empty packet rate by passing non-zero values for cip_n + and cip_d to the INIT ioctl. + + */ + + + +struct dv1394_status { + /* this embedded init struct returns the current dv1394 + parameters in use */ + struct dv1394_init init; + + /* the ringbuffer frame that is currently being + displayed. (-1 if the device is not transmitting anything) */ + int active_frame; + + /* index of the first buffer (ahead of active_frame) that + is ready to be filled with data */ + unsigned int first_clear_frame; + + /* how many buffers, including first_clear_buffer, are + ready to be filled with data */ + unsigned int n_clear_frames; + + /* how many times the DV stream has underflowed, overflowed, + or otherwise encountered an error, since the previous call + to DV1394_GET_STATUS */ + unsigned int dropped_frames; + + /* N.B. The dropped_frames counter is only a lower bound on the actual + number of dropped frames, with the special case that if dropped_frames + is zero, then it is guaranteed that NO frames have been dropped + since the last call to DV1394_GET_STATUS. + */ +}; + + +#endif /* FFMPEG_DV1394_H */ diff --git a/contrib/ffmpeg/libavdevice/libdc1394.c b/contrib/ffmpeg/libavdevice/libdc1394.c new file mode 100644 index 000000000..1227aed5e --- /dev/null +++ b/contrib/ffmpeg/libavdevice/libdc1394.c @@ -0,0 +1,372 @@ +/* + * IIDC1394 grab interface (uses libdc1394 and libraw1394) + * Copyright (c) 2004 Roman Shaposhnik + * Copyright (c) 2008 Alessandro Sappia + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" +#include "config.h" + +#if ENABLE_LIBDC1394_2 +#include +#elif ENABLE_LIBDC1394_1 +#include +#include + +#define DC1394_VIDEO_MODE_320x240_YUV422 MODE_320x240_YUV422 +#define DC1394_VIDEO_MODE_640x480_YUV411 MODE_640x480_YUV411 +#define DC1394_VIDEO_MODE_640x480_YUV422 MODE_640x480_YUV422 +#define DC1394_FRAMERATE_1_875 FRAMERATE_1_875 +#define DC1394_FRAMERATE_3_75 FRAMERATE_3_75 +#define DC1394_FRAMERATE_7_5 FRAMERATE_7_5 +#define DC1394_FRAMERATE_15 FRAMERATE_15 +#define DC1394_FRAMERATE_30 FRAMERATE_30 +#define DC1394_FRAMERATE_60 FRAMERATE_60 +#define DC1394_FRAMERATE_120 FRAMERATE_120 +#define DC1394_FRAMERATE_240 FRAMERATE_240 +#endif + +#undef free + +typedef struct dc1394_data { +#if ENABLE_LIBDC1394_1 + raw1394handle_t handle; + dc1394_cameracapture camera; +#elif ENABLE_LIBDC1394_2 + dc1394_t *d; + dc1394camera_t *camera; + dc1394video_frame_t *frame; +#endif + int current_frame; + int fps; + + AVPacket packet; +} dc1394_data; + +struct dc1394_frame_format { + int width; + int height; + enum PixelFormat pix_fmt; + int frame_size_id; +} dc1394_frame_formats[] = { + { 320, 240, PIX_FMT_UYVY422, DC1394_VIDEO_MODE_320x240_YUV422 }, + { 640, 480, PIX_FMT_UYYVYY411, DC1394_VIDEO_MODE_640x480_YUV411 }, + { 640, 480, PIX_FMT_UYVY422, DC1394_VIDEO_MODE_640x480_YUV422 }, + { 0, 0, 0, 0 } /* gotta be the last one */ +}; + +struct dc1394_frame_rate { + int frame_rate; + int frame_rate_id; +} dc1394_frame_rates[] = { + { 1875, DC1394_FRAMERATE_1_875 }, + { 3750, DC1394_FRAMERATE_3_75 }, + { 7500, DC1394_FRAMERATE_7_5 }, + { 15000, DC1394_FRAMERATE_15 }, + { 30000, DC1394_FRAMERATE_30 }, + { 60000, DC1394_FRAMERATE_60 }, + {120000, DC1394_FRAMERATE_120 }, + {240000, DC1394_FRAMERATE_240 }, + { 0, 0 } /* gotta be the last one */ +}; + +static inline int dc1394_read_common(AVFormatContext *c, AVFormatParameters *ap, + struct dc1394_frame_format **select_fmt, struct dc1394_frame_rate **select_fps) +{ + dc1394_data* dc1394 = c->priv_data; + AVStream* vst; + struct dc1394_frame_format *fmt; + struct dc1394_frame_rate *fps; + enum PixelFormat pix_fmt = ap->pix_fmt == PIX_FMT_NONE ? PIX_FMT_UYVY422 : ap->pix_fmt; /* defaults */ + int width = !ap->width ? 320 : ap->width; + int height = !ap->height ? 240 : ap->height; + int frame_rate = !ap->time_base.num ? 30000 : av_rescale(1000, ap->time_base.den, ap->time_base.num); + + for (fmt = dc1394_frame_formats; fmt->width; fmt++) + if (fmt->pix_fmt == pix_fmt && fmt->width == width && fmt->height == height) + break; + + for (fps = dc1394_frame_rates; fps->frame_rate; fps++) + if (fps->frame_rate == frame_rate) + break; + + if (!fps->frame_rate || !fmt->width) { + av_log(c, AV_LOG_ERROR, "Can't find matching camera format for %s, %dx%d@%d:1000fps\n", avcodec_get_pix_fmt_name(pix_fmt), + width, height, frame_rate); + goto out; + } + + /* create a video stream */ + vst = av_new_stream(c, 0); + if (!vst) + goto out; + av_set_pts_info(vst, 64, 1, 1000); + vst->codec->codec_type = CODEC_TYPE_VIDEO; + vst->codec->codec_id = CODEC_ID_RAWVIDEO; + vst->codec->time_base.den = fps->frame_rate; + vst->codec->time_base.num = 1000; + vst->codec->width = fmt->width; + vst->codec->height = fmt->height; + vst->codec->pix_fmt = fmt->pix_fmt; + + /* packet init */ + av_init_packet(&dc1394->packet); + dc1394->packet.size = avpicture_get_size(fmt->pix_fmt, fmt->width, fmt->height); + dc1394->packet.stream_index = vst->index; + dc1394->packet.flags |= PKT_FLAG_KEY; + + dc1394->current_frame = 0; + dc1394->fps = fps->frame_rate; + + vst->codec->bit_rate = av_rescale(dc1394->packet.size * 8, fps->frame_rate, 1000); + *select_fps = fps; + *select_fmt = fmt; + return 0; +out: + return -1; +} + +#if ENABLE_LIBDC1394_1 +static int dc1394_v1_read_header(AVFormatContext *c, AVFormatParameters * ap) +{ + dc1394_data* dc1394 = c->priv_data; + AVStream* vst; + nodeid_t* camera_nodes; + int res; + struct dc1394_frame_format *fmt = NULL; + struct dc1394_frame_rate *fps = NULL; + + if (dc1394_read_common(c,ap,&fmt,&fps) != 0) + return -1; + + /* Now lets prep the hardware */ + dc1394->handle = dc1394_create_handle(0); /* FIXME: gotta have ap->port */ + if (!dc1394->handle) { + av_log(c, AV_LOG_ERROR, "Can't acquire dc1394 handle on port %d\n", 0 /* ap->port */); + goto out; + } + camera_nodes = dc1394_get_camera_nodes(dc1394->handle, &res, 1); + if (!camera_nodes || camera_nodes[ap->channel] == DC1394_NO_CAMERA) { + av_log(c, AV_LOG_ERROR, "There's no IIDC camera on the channel %d\n", ap->channel); + goto out_handle; + } + res = dc1394_dma_setup_capture(dc1394->handle, camera_nodes[ap->channel], + 0, + FORMAT_VGA_NONCOMPRESSED, + fmt->frame_size_id, + SPEED_400, + fps->frame_rate_id, 8, 1, + c->filename, + &dc1394->camera); + dc1394_free_camera_nodes(camera_nodes); + if (res != DC1394_SUCCESS) { + av_log(c, AV_LOG_ERROR, "Can't prepare camera for the DMA capture\n"); + goto out_handle; + } + + res = dc1394_start_iso_transmission(dc1394->handle, dc1394->camera.node); + if (res != DC1394_SUCCESS) { + av_log(c, AV_LOG_ERROR, "Can't start isochronous transmission\n"); + goto out_handle_dma; + } + + return 0; + +out_handle_dma: + dc1394_dma_unlisten(dc1394->handle, &dc1394->camera); + dc1394_dma_release_camera(dc1394->handle, &dc1394->camera); +out_handle: + dc1394_destroy_handle(dc1394->handle); +out: + return -1; +} + +static int dc1394_v1_read_packet(AVFormatContext *c, AVPacket *pkt) +{ + struct dc1394_data *dc1394 = c->priv_data; + int res; + + /* discard stale frame */ + if (dc1394->current_frame++) { + if (dc1394_dma_done_with_buffer(&dc1394->camera) != DC1394_SUCCESS) + av_log(c, AV_LOG_ERROR, "failed to release %d frame\n", dc1394->current_frame); + } + + res = dc1394_dma_single_capture(&dc1394->camera); + + if (res == DC1394_SUCCESS) { + dc1394->packet.data = (uint8_t *)(dc1394->camera.capture_buffer); + dc1394->packet.pts = (dc1394->current_frame * 1000000) / dc1394->fps; + res = dc1394->packet.size; + } else { + av_log(c, AV_LOG_ERROR, "DMA capture failed\n"); + dc1394->packet.data = NULL; + res = -1; + } + + *pkt = dc1394->packet; + return res; +} + +static int dc1394_v1_close(AVFormatContext * context) +{ + struct dc1394_data *dc1394 = context->priv_data; + + dc1394_stop_iso_transmission(dc1394->handle, dc1394->camera.node); + dc1394_dma_unlisten(dc1394->handle, &dc1394->camera); + dc1394_dma_release_camera(dc1394->handle, &dc1394->camera); + dc1394_destroy_handle(dc1394->handle); + + return 0; +} + +#elif ENABLE_LIBDC1394_2 +static int dc1394_v2_read_header(AVFormatContext *c, AVFormatParameters * ap) +{ + dc1394_data* dc1394 = c->priv_data; + dc1394camera_list_t *list; + int res, i; + struct dc1394_frame_format *fmt = NULL; + struct dc1394_frame_rate *fps = NULL; + + if (dc1394_read_common(c,ap,&fmt,&fps) != 0) + return -1; + + /* Now lets prep the hardware */ + dc1394->d = dc1394_new(); + dc1394_camera_enumerate (dc1394->d, &list); + if ( !list || list->num == 0) { + av_log(c, AV_LOG_ERROR, "Unable to look for an IIDC camera\n\n"); + goto out; + } + + /* FIXME: To select a specific camera I need to search in list its guid */ + dc1394->camera = dc1394_camera_new (dc1394->d, list->ids[0].guid); + if (list->num > 1) { + av_log(c, AV_LOG_INFO, "Working with the first camera found\n"); + } + + /* Freeing list of cameras */ + dc1394_camera_free_list (list); + + /* Select MAX Speed possible from the cam */ + if (dc1394->camera->bmode_capable>0) { + dc1394_video_set_operation_mode(dc1394->camera, DC1394_OPERATION_MODE_1394B); + i = DC1394_ISO_SPEED_800; + } else { + i = DC1394_ISO_SPEED_400; + } + + for (res = DC1394_FAILURE; i >= DC1394_ISO_SPEED_MIN && res != DC1394_SUCCESS; i--) { + res=dc1394_video_set_iso_speed(dc1394->camera, i); + } + if (res != DC1394_SUCCESS) { + av_log(c, AV_LOG_ERROR, "Couldn't set ISO Speed\n"); + goto out_camera; + } + + if (dc1394_video_set_mode(dc1394->camera, fmt->frame_size_id) != DC1394_SUCCESS) { + av_log(c, AV_LOG_ERROR, "Couldn't set video format\n"); + goto out_camera; + } + + if (dc1394_video_set_framerate(dc1394->camera,fps->frame_rate_id) != DC1394_SUCCESS) { + av_log(c, AV_LOG_ERROR, "Couldn't set framerate %d \n",fps->frame_rate); + goto out_camera; + } + if (dc1394_capture_setup(dc1394->camera, 10, DC1394_CAPTURE_FLAGS_DEFAULT)!=DC1394_SUCCESS) { + av_log(c, AV_LOG_ERROR, "Cannot setup camera \n"); + goto out_camera; + } + + if (dc1394_video_set_transmission(dc1394->camera, DC1394_ON) !=DC1394_SUCCESS) { + av_log(c, AV_LOG_ERROR, "Cannot start capture\n"); + goto out_camera; + } + return 0; + +out_camera: + dc1394_capture_stop(dc1394->camera); + dc1394_video_set_transmission(dc1394->camera, DC1394_OFF); + dc1394_camera_free (dc1394->camera); +out: + dc1394_free(dc1394->d); + return -1; +} + +static int dc1394_v2_read_packet(AVFormatContext *c, AVPacket *pkt) +{ + struct dc1394_data *dc1394 = c->priv_data; + int res; + + /* discard stale frame */ + if (dc1394->current_frame++) { + if (dc1394_capture_enqueue(dc1394->camera, dc1394->frame) != DC1394_SUCCESS) + av_log(c, AV_LOG_ERROR, "failed to release %d frame\n", dc1394->current_frame); + } + + res = dc1394_capture_dequeue(dc1394->camera, DC1394_CAPTURE_POLICY_WAIT, &dc1394->frame); + if (res == DC1394_SUCCESS) { + dc1394->packet.data = (uint8_t *)(dc1394->frame->image); + dc1394->packet.pts = (dc1394->current_frame * 1000000) / (dc1394->fps); + res = dc1394->frame->image_bytes; + } else { + av_log(c, AV_LOG_ERROR, "DMA capture failed\n"); + dc1394->packet.data = NULL; + res = -1; + } + + *pkt = dc1394->packet; + return res; +} + +static int dc1394_v2_close(AVFormatContext * context) +{ + struct dc1394_data *dc1394 = context->priv_data; + + dc1394_video_set_transmission(dc1394->camera, DC1394_OFF); + dc1394_capture_stop(dc1394->camera); + dc1394_camera_free(dc1394->camera); + dc1394_free(dc1394->d); + + return 0; +} + +AVInputFormat libdc1394_demuxer = { + .name = "libdc1394", + .long_name = "dc1394 v.2 A/V grab", + .priv_data_size = sizeof(struct dc1394_data), + .read_header = dc1394_v2_read_header, + .read_packet = dc1394_v2_read_packet, + .read_close = dc1394_v2_close, + .flags = AVFMT_NOFILE +}; + +#endif +#if ENABLE_LIBDC1394_1 +AVInputFormat libdc1394_demuxer = { + .name = "libdc1394", + .long_name = "dc1394 v.1 A/V grab", + .priv_data_size = sizeof(struct dc1394_data), + .read_header = dc1394_v1_read_header, + .read_packet = dc1394_v1_read_packet, + .read_close = dc1394_v1_close, + .flags = AVFMT_NOFILE +}; +#endif diff --git a/contrib/ffmpeg/libavdevice/v4l.c b/contrib/ffmpeg/libavdevice/v4l.c new file mode 100644 index 000000000..5d57a2bbd --- /dev/null +++ b/contrib/ffmpeg/libavdevice/v4l.c @@ -0,0 +1,354 @@ +/* + * Linux video grab interface + * Copyright (c) 2000,2001 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avformat.h" +#include "dsputil.h" +#include +#include +#include +#include +#include +#define _LINUX_TIME_H 1 +#include +#include + +typedef struct { + int fd; + int frame_format; /* see VIDEO_PALETTE_xxx */ + int use_mmap; + int width, height; + int frame_rate; + int frame_rate_base; + int64_t time_frame; + int frame_size; + struct video_capability video_cap; + struct video_audio audio_saved; + uint8_t *video_buf; + struct video_mbuf gb_buffers; + struct video_mmap gb_buf; + int gb_frame; +} VideoData; + +static const struct { + int palette; + int depth; + enum PixelFormat pix_fmt; +} video_formats [] = { + {.palette = VIDEO_PALETTE_YUV420P, .depth = 12, .pix_fmt = PIX_FMT_YUV420P }, + {.palette = VIDEO_PALETTE_YUV422, .depth = 16, .pix_fmt = PIX_FMT_YUYV422 }, + {.palette = VIDEO_PALETTE_UYVY, .depth = 16, .pix_fmt = PIX_FMT_UYVY422 }, + {.palette = VIDEO_PALETTE_YUYV, .depth = 16, .pix_fmt = PIX_FMT_YUYV422 }, + /* NOTE: v4l uses BGR24, not RGB24 */ + {.palette = VIDEO_PALETTE_RGB24, .depth = 24, .pix_fmt = PIX_FMT_BGR24 }, + {.palette = VIDEO_PALETTE_RGB565, .depth = 16, .pix_fmt = PIX_FMT_BGR565 }, + {.palette = VIDEO_PALETTE_GREY, .depth = 8, .pix_fmt = PIX_FMT_GRAY8 }, +}; + + +static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) +{ + VideoData *s = s1->priv_data; + AVStream *st; + int width, height; + int video_fd, frame_size; + int ret, frame_rate, frame_rate_base; + int desired_palette, desired_depth; + struct video_tuner tuner; + struct video_audio audio; + struct video_picture pict; + int j; + int vformat_num = sizeof(video_formats) / sizeof(video_formats[0]); + + if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) { + av_log(s1, AV_LOG_ERROR, "Bad capture size (%dx%d) or wrong time base (%d)\n", + ap->width, ap->height, ap->time_base.den); + + return -1; + } + + width = ap->width; + height = ap->height; + frame_rate = ap->time_base.den; + frame_rate_base = ap->time_base.num; + + if((unsigned)width > 32767 || (unsigned)height > 32767) { + av_log(s1, AV_LOG_ERROR, "Capture size is out of range: %dx%d\n", + width, height); + + return -1; + } + + st = av_new_stream(s1, 0); + if (!st) + return AVERROR(ENOMEM); + av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ + + s->width = width; + s->height = height; + s->frame_rate = frame_rate; + s->frame_rate_base = frame_rate_base; + + video_fd = open(s1->filename, O_RDWR); + if (video_fd < 0) { + av_log(s1, AV_LOG_ERROR, "%s: %s\n", s1->filename, strerror(errno)); + goto fail; + } + + if (ioctl(video_fd,VIDIOCGCAP, &s->video_cap) < 0) { + av_log(s1, AV_LOG_ERROR, "VIDIOCGCAP: %s\n", strerror(errno)); + goto fail; + } + + if (!(s->video_cap.type & VID_TYPE_CAPTURE)) { + av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not handle capture\n"); + goto fail; + } + + desired_palette = -1; + desired_depth = -1; + for (j = 0; j < vformat_num; j++) { + if (ap->pix_fmt == video_formats[j].pix_fmt) { + desired_palette = video_formats[j].palette; + desired_depth = video_formats[j].depth; + break; + } + } + + /* set tv standard */ + if (ap->standard && !ioctl(video_fd, VIDIOCGTUNER, &tuner)) { + if (!strcasecmp(ap->standard, "pal")) + tuner.mode = VIDEO_MODE_PAL; + else if (!strcasecmp(ap->standard, "secam")) + tuner.mode = VIDEO_MODE_SECAM; + else + tuner.mode = VIDEO_MODE_NTSC; + ioctl(video_fd, VIDIOCSTUNER, &tuner); + } + + /* unmute audio */ + audio.audio = 0; + ioctl(video_fd, VIDIOCGAUDIO, &audio); + memcpy(&s->audio_saved, &audio, sizeof(audio)); + audio.flags &= ~VIDEO_AUDIO_MUTE; + ioctl(video_fd, VIDIOCSAUDIO, &audio); + + ioctl(video_fd, VIDIOCGPICT, &pict); +#if 0 + printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n", + pict.colour, + pict.hue, + pict.brightness, + pict.contrast, + pict.whiteness); +#endif + /* try to choose a suitable video format */ + pict.palette = desired_palette; + pict.depth= desired_depth; + if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) { + for (j = 0; j < vformat_num; j++) { + pict.palette = video_formats[j].palette; + pict.depth = video_formats[j].depth; + if (-1 != ioctl(video_fd, VIDIOCSPICT, &pict)) + break; + } + if (j >= vformat_num) + goto fail1; + } + + ret = ioctl(video_fd,VIDIOCGMBUF,&s->gb_buffers); + if (ret < 0) { + /* try to use read based access */ + struct video_window win; + int val; + + win.x = 0; + win.y = 0; + win.width = width; + win.height = height; + win.chromakey = -1; + win.flags = 0; + + ioctl(video_fd, VIDIOCSWIN, &win); + + s->frame_format = pict.palette; + + val = 1; + ioctl(video_fd, VIDIOCCAPTURE, &val); + + s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base; + s->use_mmap = 0; + } else { + s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,video_fd,0); + if ((unsigned char*)-1 == s->video_buf) { + s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_PRIVATE,video_fd,0); + if ((unsigned char*)-1 == s->video_buf) { + av_log(s1, AV_LOG_ERROR, "mmap: %s\n", strerror(errno)); + goto fail; + } + } + s->gb_frame = 0; + s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base; + + /* start to grab the first frame */ + s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames; + s->gb_buf.height = height; + s->gb_buf.width = width; + s->gb_buf.format = pict.palette; + + ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf); + if (ret < 0) { + if (errno != EAGAIN) { + fail1: + av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not support suitable format\n"); + } else { + av_log(s1, AV_LOG_ERROR,"Fatal: grab device does not receive any video signal\n"); + } + goto fail; + } + for (j = 1; j < s->gb_buffers.frames; j++) { + s->gb_buf.frame = j; + ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf); + } + s->frame_format = s->gb_buf.format; + s->use_mmap = 1; + } + + for (j = 0; j < vformat_num; j++) { + if (s->frame_format == video_formats[j].palette) { + frame_size = width * height * video_formats[j].depth / 8; + st->codec->pix_fmt = video_formats[j].pix_fmt; + break; + } + } + + if (j >= vformat_num) + goto fail; + + s->fd = video_fd; + s->frame_size = frame_size; + + st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_RAWVIDEO; + st->codec->width = width; + st->codec->height = height; + st->codec->time_base.den = frame_rate; + st->codec->time_base.num = frame_rate_base; + st->codec->bit_rate = frame_size * 1/av_q2d(st->codec->time_base) * 8; + + return 0; + fail: + if (video_fd >= 0) + close(video_fd); + av_free(st); + return AVERROR(EIO); +} + +static int v4l_mm_read_picture(VideoData *s, uint8_t *buf) +{ + uint8_t *ptr; + + while (ioctl(s->fd, VIDIOCSYNC, &s->gb_frame) < 0 && + (errno == EAGAIN || errno == EINTR)); + + ptr = s->video_buf + s->gb_buffers.offsets[s->gb_frame]; + memcpy(buf, ptr, s->frame_size); + + /* Setup to capture the next frame */ + s->gb_buf.frame = s->gb_frame; + if (ioctl(s->fd, VIDIOCMCAPTURE, &s->gb_buf) < 0) { + if (errno == EAGAIN) + av_log(NULL, AV_LOG_ERROR, "Cannot Sync\n"); + else + av_log(NULL, AV_LOG_ERROR, "VIDIOCMCAPTURE: %s\n", strerror(errno)); + return AVERROR(EIO); + } + + /* This is now the grabbing frame */ + s->gb_frame = (s->gb_frame + 1) % s->gb_buffers.frames; + + return s->frame_size; +} + +static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt) +{ + VideoData *s = s1->priv_data; + int64_t curtime, delay; + struct timespec ts; + + /* Calculate the time of the next frame */ + s->time_frame += INT64_C(1000000); + + /* wait based on the frame rate */ + for(;;) { + curtime = av_gettime(); + delay = s->time_frame * s->frame_rate_base / s->frame_rate - curtime; + if (delay <= 0) { + if (delay < INT64_C(-1000000) * s->frame_rate_base / s->frame_rate) { + /* printf("grabbing is %d frames late (dropping)\n", (int) -(delay / 16666)); */ + s->time_frame += INT64_C(1000000); + } + break; + } + ts.tv_sec = delay / 1000000; + ts.tv_nsec = (delay % 1000000) * 1000; + nanosleep(&ts, NULL); + } + + if (av_new_packet(pkt, s->frame_size) < 0) + return AVERROR(EIO); + + pkt->pts = curtime; + + /* read one frame */ + if (s->use_mmap) { + return v4l_mm_read_picture(s, pkt->data); + } else { + if (read(s->fd, pkt->data, pkt->size) != pkt->size) + return AVERROR(EIO); + return s->frame_size; + } +} + +static int grab_read_close(AVFormatContext *s1) +{ + VideoData *s = s1->priv_data; + + if (s->use_mmap) + munmap(s->video_buf, s->gb_buffers.size); + + /* mute audio. we must force it because the BTTV driver does not + return its state correctly */ + s->audio_saved.flags |= VIDEO_AUDIO_MUTE; + ioctl(s->fd, VIDIOCSAUDIO, &s->audio_saved); + + close(s->fd); + return 0; +} + +AVInputFormat v4l_demuxer = { + "video4linux", + "video grab", + sizeof(VideoData), + NULL, + grab_read_header, + grab_read_packet, + grab_read_close, + .flags = AVFMT_NOFILE, +}; diff --git a/contrib/ffmpeg/libavdevice/v4l2.c b/contrib/ffmpeg/libavdevice/v4l2.c new file mode 100644 index 000000000..528acc434 --- /dev/null +++ b/contrib/ffmpeg/libavdevice/v4l2.c @@ -0,0 +1,643 @@ +/* + * Video4Linux2 grab interface + * Copyright (c) 2000,2001 Fabrice Bellard. + * Copyright (c) 2006 Luca Abeni. + * + * Part of this file is based on the V4L2 video capture example + * (http://v4l2spec.bytesex.org/v4l2spec/capture.c) + * + * Thanks to Michael Niedermayer for providing the mapping between + * V4L2_PIX_FMT_* and PIX_FMT_* + * + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avformat.h" +#include +#include +#include +#include +#include +#include +#include +#include + +static const int desired_video_buffers = 256; + +enum io_method { + io_read, + io_mmap, + io_userptr +}; + +struct video_data { + int fd; + int frame_format; /* V4L2_PIX_FMT_* */ + enum io_method io_method; + int width, height; + int frame_rate; + int frame_rate_base; + int frame_size; + int top_field_first; + + int buffers; + void **buf_start; + unsigned int *buf_len; +}; + +struct buff_data { + int index; + int fd; +}; + +struct fmt_map { + enum PixelFormat ff_fmt; + int32_t v4l2_fmt; +}; + +static struct fmt_map fmt_conversion_table[] = { + { + .ff_fmt = PIX_FMT_YUV420P, + .v4l2_fmt = V4L2_PIX_FMT_YUV420, + }, + { + .ff_fmt = PIX_FMT_YUV422P, + .v4l2_fmt = V4L2_PIX_FMT_YUV422P, + }, + { + .ff_fmt = PIX_FMT_YUYV422, + .v4l2_fmt = V4L2_PIX_FMT_YUYV, + }, + { + .ff_fmt = PIX_FMT_UYVY422, + .v4l2_fmt = V4L2_PIX_FMT_UYVY, + }, + { + .ff_fmt = PIX_FMT_YUV411P, + .v4l2_fmt = V4L2_PIX_FMT_YUV411P, + }, + { + .ff_fmt = PIX_FMT_YUV410P, + .v4l2_fmt = V4L2_PIX_FMT_YUV410, + }, + { + .ff_fmt = PIX_FMT_BGR24, + .v4l2_fmt = V4L2_PIX_FMT_BGR24, + }, + { + .ff_fmt = PIX_FMT_RGB24, + .v4l2_fmt = V4L2_PIX_FMT_RGB24, + }, + /* + { + .ff_fmt = PIX_FMT_RGB32, + .v4l2_fmt = V4L2_PIX_FMT_BGR32, + }, + */ + { + .ff_fmt = PIX_FMT_GRAY8, + .v4l2_fmt = V4L2_PIX_FMT_GREY, + }, +}; + +static int device_open(AVFormatContext *ctx, uint32_t *capabilities) +{ + struct v4l2_capability cap; + int fd; + int res; + int flags = O_RDWR; + + if (ctx->flags & AVFMT_FLAG_NONBLOCK) { + flags |= O_NONBLOCK; + } + fd = open(ctx->filename, flags, 0); + if (fd < 0) { + av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s : %s\n", + ctx->filename, strerror(errno)); + + return -1; + } + + res = ioctl(fd, VIDIOC_QUERYCAP, &cap); + // ENOIOCTLCMD definition only availble on __KERNEL__ + if (res < 0 && errno == 515) + { + av_log(ctx, AV_LOG_ERROR, "QUERYCAP not implemented, probably V4L device but not supporting V4L2\n"); + close(fd); + + return -1; + } + if (res < 0) { + av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n", + strerror(errno)); + close(fd); + + return -1; + } + if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) { + av_log(ctx, AV_LOG_ERROR, "Not a video capture device\n"); + close(fd); + + return -1; + } + *capabilities = cap.capabilities; + + return fd; +} + +static int device_init(AVFormatContext *ctx, int *width, int *height, int pix_fmt) +{ + struct video_data *s = ctx->priv_data; + int fd = s->fd; + struct v4l2_format fmt; + int res; + + memset(&fmt, 0, sizeof(struct v4l2_format)); + fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + fmt.fmt.pix.width = *width; + fmt.fmt.pix.height = *height; + fmt.fmt.pix.pixelformat = pix_fmt; + fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; + res = ioctl(fd, VIDIOC_S_FMT, &fmt); + if ((*width != fmt.fmt.pix.width) || (*height != fmt.fmt.pix.height)) { + av_log(ctx, AV_LOG_INFO, "The V4L2 driver changed the video from %dx%d to %dx%d\n", *width, *height, fmt.fmt.pix.width, fmt.fmt.pix.height); + *width = fmt.fmt.pix.width; + *height = fmt.fmt.pix.height; + } + + return res; +} + +static int first_field(int fd) +{ + int res; + v4l2_std_id std; + + res = ioctl(fd, VIDIOC_G_STD, &std); + if (res < 0) { + return 0; + } + if (std & V4L2_STD_NTSC) { + return 0; + } + + return 1; +} + +static uint32_t fmt_ff2v4l(enum PixelFormat pix_fmt) +{ + int i; + + for (i = 0; i < sizeof(fmt_conversion_table) / sizeof(struct fmt_map); i++) { + if (fmt_conversion_table[i].ff_fmt == pix_fmt) { + return fmt_conversion_table[i].v4l2_fmt; + } + } + + return 0; +} + +static enum PixelFormat fmt_v4l2ff(uint32_t pix_fmt) +{ + int i; + + for (i = 0; i < sizeof(fmt_conversion_table) / sizeof(struct fmt_map); i++) { + if (fmt_conversion_table[i].v4l2_fmt == pix_fmt) { + return fmt_conversion_table[i].ff_fmt; + } + } + + return -1; +} + +static int mmap_init(AVFormatContext *ctx) +{ + struct video_data *s = ctx->priv_data; + struct v4l2_requestbuffers req; + int i, res; + + memset(&req, 0, sizeof(struct v4l2_requestbuffers)); + req.count = desired_video_buffers; + req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + req.memory = V4L2_MEMORY_MMAP; + res = ioctl (s->fd, VIDIOC_REQBUFS, &req); + if (res < 0) { + if (errno == EINVAL) { + av_log(ctx, AV_LOG_ERROR, "Device does not support mmap\n"); + } else { + av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_REQBUFS)\n"); + } + + return -1; + } + + if (req.count < 2) { + av_log(ctx, AV_LOG_ERROR, "Insufficient buffer memory\n"); + + return -1; + } + s->buffers = req.count; + s->buf_start = av_malloc(sizeof(void *) * s->buffers); + if (s->buf_start == NULL) { + av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer pointers\n"); + + return -1; + } + s->buf_len = av_malloc(sizeof(unsigned int) * s->buffers); + if (s->buf_len == NULL) { + av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer sizes\n"); + av_free(s->buf_start); + + return -1; + } + + for (i = 0; i < req.count; i++) { + struct v4l2_buffer buf; + + memset(&buf, 0, sizeof(struct v4l2_buffer)); + buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + buf.memory = V4L2_MEMORY_MMAP; + buf.index = i; + res = ioctl (s->fd, VIDIOC_QUERYBUF, &buf); + if (res < 0) { + av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYBUF)\n"); + + return -1; + } + + s->buf_len[i] = buf.length; + if (s->buf_len[i] < s->frame_size) { + av_log(ctx, AV_LOG_ERROR, "Buffer len [%d] = %d != %d\n", i, s->buf_len[i], s->frame_size); + + return -1; + } + s->buf_start[i] = mmap (NULL, buf.length, + PROT_READ | PROT_WRITE, MAP_SHARED, s->fd, buf.m.offset); + if (s->buf_start[i] == MAP_FAILED) { + av_log(ctx, AV_LOG_ERROR, "mmap: %s\n", strerror(errno)); + + return -1; + } + } + + return 0; +} + +static int read_init(AVFormatContext *ctx) +{ + return -1; +} + +static void mmap_release_buffer(AVPacket *pkt) +{ + struct v4l2_buffer buf; + int res, fd; + struct buff_data *buf_descriptor = pkt->priv; + + memset(&buf, 0, sizeof(struct v4l2_buffer)); + buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + buf.memory = V4L2_MEMORY_MMAP; + buf.index = buf_descriptor->index; + fd = buf_descriptor->fd; + av_free(buf_descriptor); + + res = ioctl (fd, VIDIOC_QBUF, &buf); + if (res < 0) { + av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF)\n"); + } + pkt->data = NULL; + pkt->size = 0; +} + +static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt) +{ + struct video_data *s = ctx->priv_data; + struct v4l2_buffer buf; + struct buff_data *buf_descriptor; + int res; + + memset(&buf, 0, sizeof(struct v4l2_buffer)); + buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + buf.memory = V4L2_MEMORY_MMAP; + + /* FIXME: Some special treatment might be needed in case of loss of signal... */ + while ((res = ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 && (errno == EINTR)); + if (res < 0) { + if (errno == EAGAIN) { + pkt->size = 0; + + return AVERROR(EAGAIN); + } + av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n", strerror(errno)); + + return -1; + } + assert (buf.index < s->buffers); + if (buf.bytesused != s->frame_size) { + av_log(ctx, AV_LOG_ERROR, "The v4l2 frame is %d bytes, but %d bytes are expected\n", buf.bytesused, s->frame_size); + + return -1; + } + + /* Image is at s->buff_start[buf.index] */ + pkt->data= s->buf_start[buf.index]; + pkt->size = buf.bytesused; + pkt->pts = buf.timestamp.tv_sec * INT64_C(1000000) + buf.timestamp.tv_usec; + pkt->destruct = mmap_release_buffer; + buf_descriptor = av_malloc(sizeof(struct buff_data)); + if (buf_descriptor == NULL) { + /* Something went wrong... Since av_malloc() failed, we cannot even + * allocate a buffer for memcopying into it + */ + av_log(ctx, AV_LOG_ERROR, "Failed to allocate a buffer descriptor\n"); + res = ioctl (s->fd, VIDIOC_QBUF, &buf); + + return -1; + } + buf_descriptor->fd = s->fd; + buf_descriptor->index = buf.index; + pkt->priv = buf_descriptor; + + return s->buf_len[buf.index]; +} + +static int read_frame(AVFormatContext *ctx, AVPacket *pkt) +{ + return -1; +} + +static int mmap_start(AVFormatContext *ctx) +{ + struct video_data *s = ctx->priv_data; + enum v4l2_buf_type type; + int i, res; + + for (i = 0; i < s->buffers; i++) { + struct v4l2_buffer buf; + + memset(&buf, 0, sizeof(struct v4l2_buffer)); + buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + buf.memory = V4L2_MEMORY_MMAP; + buf.index = i; + + res = ioctl (s->fd, VIDIOC_QBUF, &buf); + if (res < 0) { + av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n", strerror(errno)); + + return -1; + } + } + + type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + res = ioctl (s->fd, VIDIOC_STREAMON, &type); + if (res < 0) { + av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_STREAMON): %s\n", strerror(errno)); + + return -1; + } + + return 0; +} + +static void mmap_close(struct video_data *s) +{ + enum v4l2_buf_type type; + int i; + + type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + /* We do not check for the result, because we could + * not do anything about it anyway... + */ + ioctl(s->fd, VIDIOC_STREAMOFF, &type); + for (i = 0; i < s->buffers; i++) { + munmap(s->buf_start[i], s->buf_len[i]); + } + av_free(s->buf_start); + av_free(s->buf_len); +} + +static int v4l2_set_parameters( AVFormatContext *s1, AVFormatParameters *ap ) +{ + struct video_data *s = s1->priv_data; + struct v4l2_input input; + struct v4l2_standard standard; + int i; + + if(ap->channel>=0) { + /* set tv video input */ + memset (&input, 0, sizeof (input)); + input.index = ap->channel; + if(ioctl (s->fd, VIDIOC_ENUMINPUT, &input) < 0) { + av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum input failed:\n"); + return AVERROR(EIO); + } + + av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, input: %s\n", + ap->channel, input.name); + if(ioctl (s->fd, VIDIOC_S_INPUT, &input.index) < 0 ) { + av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set input(%d) failed\n", + ap->channel); + return AVERROR(EIO); + } + } + + if(ap->standard) { + av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s\n", + ap->standard ); + /* set tv standard */ + memset (&standard, 0, sizeof (standard)); + for(i=0;;i++) { + standard.index = i; + if (ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) { + av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set standard(%s) failed\n", + ap->standard); + return AVERROR(EIO); + } + + if(!strcasecmp(standard.name, ap->standard)) { + break; + } + } + + av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s, id: %"PRIu64"\n", + ap->standard, standard.id); + if (ioctl(s->fd, VIDIOC_S_STD, &standard.id) < 0) { + av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set standard(%s) failed\n", + ap->standard); + return AVERROR(EIO); + } + } + + return 0; +} + +static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) +{ + struct video_data *s = s1->priv_data; + AVStream *st; + int width, height; + int res, frame_rate, frame_rate_base; + uint32_t desired_format, capabilities; + + if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) { + av_log(s1, AV_LOG_ERROR, "Missing/Wrong width, height or framerate\n"); + + return -1; + } + + width = ap->width; + height = ap->height; + frame_rate = ap->time_base.den; + frame_rate_base = ap->time_base.num; + + if((unsigned)width > 32767 || (unsigned)height > 32767) { + av_log(s1, AV_LOG_ERROR, "Wrong size %dx%d\n", width, height); + + return -1; + } + + st = av_new_stream(s1, 0); + if (!st) { + return AVERROR(ENOMEM); + } + av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ + + s->width = width; + s->height = height; + s->frame_rate = frame_rate; + s->frame_rate_base = frame_rate_base; + + capabilities = 0; + s->fd = device_open(s1, &capabilities); + if (s->fd < 0) { + av_free(st); + + return AVERROR(EIO); + } + av_log(s1, AV_LOG_INFO, "[%d]Capabilities: %x\n", s->fd, capabilities); + + desired_format = fmt_ff2v4l(ap->pix_fmt); + if (desired_format == 0 || (device_init(s1, &width, &height, desired_format) < 0)) { + int i, done; + + done = 0; i = 0; + while (!done) { + desired_format = fmt_conversion_table[i].v4l2_fmt; + if (device_init(s1, &width, &height, desired_format) < 0) { + desired_format = 0; + i++; + } else { + done = 1; + } + if (i == sizeof(fmt_conversion_table) / sizeof(struct fmt_map)) { + done = 1; + } + } + } + if (desired_format == 0) { + av_log(s1, AV_LOG_ERROR, "Cannot find a proper format.\n"); + close(s->fd); + av_free(st); + + return AVERROR(EIO); + } + s->frame_format = desired_format; + + if( v4l2_set_parameters( s1, ap ) < 0 ) + return AVERROR(EIO); + + st->codec->pix_fmt = fmt_v4l2ff(desired_format); + s->frame_size = avpicture_get_size(st->codec->pix_fmt, width, height); + if (capabilities & V4L2_CAP_STREAMING) { + s->io_method = io_mmap; + res = mmap_init(s1); + if (res == 0) { + res = mmap_start(s1); + } + } else { + s->io_method = io_read; + res = read_init(s1); + } + if (res < 0) { + close(s->fd); + av_free(st); + + return AVERROR(EIO); + } + s->top_field_first = first_field(s->fd); + + st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_RAWVIDEO; + st->codec->width = width; + st->codec->height = height; + st->codec->time_base.den = frame_rate; + st->codec->time_base.num = frame_rate_base; + st->codec->bit_rate = s->frame_size * 1/av_q2d(st->codec->time_base) * 8; + + return 0; +} + +static int v4l2_read_packet(AVFormatContext *s1, AVPacket *pkt) +{ + struct video_data *s = s1->priv_data; + int res; + + if (s->io_method == io_mmap) { + av_init_packet(pkt); + res = mmap_read_frame(s1, pkt); + } else if (s->io_method == io_read) { + if (av_new_packet(pkt, s->frame_size) < 0) + return AVERROR(EIO); + + res = read_frame(s1, pkt); + } else { + return AVERROR(EIO); + } + if (res < 0) { + return res; + } + + if (s1->streams[0]->codec->coded_frame) { + s1->streams[0]->codec->coded_frame->interlaced_frame = 1; + s1->streams[0]->codec->coded_frame->top_field_first = s->top_field_first; + } + + return s->frame_size; +} + +static int v4l2_read_close(AVFormatContext *s1) +{ + struct video_data *s = s1->priv_data; + + if (s->io_method == io_mmap) { + mmap_close(s); + } + + close(s->fd); + return 0; +} + +AVInputFormat v4l2_demuxer = { + "video4linux2", + "video grab", + sizeof(struct video_data), + NULL, + v4l2_read_header, + v4l2_read_packet, + v4l2_read_close, + .flags = AVFMT_NOFILE, +}; diff --git a/contrib/ffmpeg/libavdevice/x11grab.c b/contrib/ffmpeg/libavdevice/x11grab.c new file mode 100644 index 000000000..8ff34bf2b --- /dev/null +++ b/contrib/ffmpeg/libavdevice/x11grab.c @@ -0,0 +1,529 @@ +/* + * X11 video grab interface + * + * This file is part of FFmpeg. + * + * FFmpeg integration: + * Copyright (C) 2006 Clemens Fruhwirth + * Edouard Gomez + * + * This file contains code from grab.c: + * Copyright (c) 2000-2001 Fabrice Bellard + * + * This file contains code from the xvidcap project: + * Copyright (C) 1997-1998 Rasca, Berlin + * 2003-2004 Karl H. Beckers, Frankfurt + * + * FFmpeg is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * FFmpeg 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file x11grab.c + * X11 frame device demuxer by Clemens Fruhwirth + * and Edouard Gomez . + */ + +#include "avformat.h" +#include +#include +#include +#include +#include +#define _LINUX_TIME_H 1 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * X11 Device Demuxer context + */ +typedef struct x11_grab_s +{ + int frame_size; /**< Size in bytes of a grabbed frame */ + AVRational time_base; /**< Time base */ + int64_t time_frame; /**< Current time */ + + int height; /**< Height of the grab frame */ + int width; /**< Width of the grab frame */ + int x_off; /**< Horizontal top-left corner coordinate */ + int y_off; /**< Vertical top-left corner coordinate */ + + Display *dpy; /**< X11 display from which x11grab grabs frames */ + XImage *image; /**< X11 image holding the grab */ + int use_shm; /**< !0 when using XShm extension */ + XShmSegmentInfo shminfo; /**< When using XShm, keeps track of XShm infos */ + int mouse_warning_shown; +} x11_grab_t; + +/** + * Initializes the x11 grab device demuxer (public device demuxer API). + * + * @param s1 Context from avformat core + * @param ap Parameters from avformat core + * @return
    + *
  • AVERROR(ENOMEM) no memory left
  • + *
  • AVERROR(EIO) other failure case
  • + *
  • 0 success
  • + *
+ */ +static int +x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) +{ + x11_grab_t *x11grab = s1->priv_data; + Display *dpy; + AVStream *st = NULL; + int input_pixfmt; + XImage *image; + int x_off = 0; + int y_off = 0; + int use_shm; + char *param, *offset; + + param = av_strdup(s1->filename); + offset = strchr(param, '+'); + if (offset) { + sscanf(offset, "%d,%d", &x_off, &y_off); + *offset= 0; + } + + av_log(s1, AV_LOG_INFO, "device: %s -> display: %s x: %d y: %d width: %d height: %d\n", s1->filename, param, x_off, y_off, ap->width, ap->height); + + dpy = XOpenDisplay(param); + if(!dpy) { + av_log(s1, AV_LOG_ERROR, "Could not open X display.\n"); + return AVERROR(EIO); + } + + if (!ap || ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) { + av_log(s1, AV_LOG_ERROR, "AVParameters don't have video size and/or rate. Use -s and -r.\n"); + return AVERROR(EIO); + } + + st = av_new_stream(s1, 0); + if (!st) { + return AVERROR(ENOMEM); + } + av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ + + use_shm = XShmQueryExtension(dpy); + av_log(s1, AV_LOG_INFO, "shared memory extension %s found\n", use_shm ? "" : "not"); + + if(use_shm) { + int scr = XDefaultScreen(dpy); + image = XShmCreateImage(dpy, + DefaultVisual(dpy, scr), + DefaultDepth(dpy, scr), + ZPixmap, + NULL, + &x11grab->shminfo, + ap->width, ap->height); + x11grab->shminfo.shmid = shmget(IPC_PRIVATE, + image->bytes_per_line * image->height, + IPC_CREAT|0777); + if (x11grab->shminfo.shmid == -1) { + av_log(s1, AV_LOG_ERROR, "Fatal: Can't get shared memory!\n"); + return AVERROR(ENOMEM); + } + x11grab->shminfo.shmaddr = image->data = shmat(x11grab->shminfo.shmid, 0, 0); + x11grab->shminfo.readOnly = False; + + if (!XShmAttach(dpy, &x11grab->shminfo)) { + av_log(s1, AV_LOG_ERROR, "Fatal: Failed to attach shared memory!\n"); + /* needs some better error subroutine :) */ + return AVERROR(EIO); + } + } else { + image = XGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), + x_off,y_off, + ap->width,ap->height, + AllPlanes, ZPixmap); + } + + switch (image->bits_per_pixel) { + case 8: + av_log (s1, AV_LOG_DEBUG, "8 bit palette\n"); + input_pixfmt = PIX_FMT_PAL8; + break; + case 16: + if ( image->red_mask == 0xf800 && + image->green_mask == 0x07e0 && + image->blue_mask == 0x001f ) { + av_log (s1, AV_LOG_DEBUG, "16 bit RGB565\n"); + input_pixfmt = PIX_FMT_RGB565; + } else if (image->red_mask == 0x7c00 && + image->green_mask == 0x03e0 && + image->blue_mask == 0x001f ) { + av_log(s1, AV_LOG_DEBUG, "16 bit RGB555\n"); + input_pixfmt = PIX_FMT_RGB555; + } else { + av_log(s1, AV_LOG_ERROR, "RGB ordering at image depth %i not supported ... aborting\n", image->bits_per_pixel); + av_log(s1, AV_LOG_ERROR, "color masks: r 0x%.6lx g 0x%.6lx b 0x%.6lx\n", image->red_mask, image->green_mask, image->blue_mask); + return AVERROR(EIO); + } + break; + case 24: + if ( image->red_mask == 0xff0000 && + image->green_mask == 0x00ff00 && + image->blue_mask == 0x0000ff ) { + input_pixfmt = PIX_FMT_BGR24; + } else if ( image->red_mask == 0x0000ff && + image->green_mask == 0x00ff00 && + image->blue_mask == 0xff0000 ) { + input_pixfmt = PIX_FMT_RGB24; + } else { + av_log(s1, AV_LOG_ERROR,"rgb ordering at image depth %i not supported ... aborting\n", image->bits_per_pixel); + av_log(s1, AV_LOG_ERROR, "color masks: r 0x%.6lx g 0x%.6lx b 0x%.6lx\n", image->red_mask, image->green_mask, image->blue_mask); + return AVERROR(EIO); + } + break; + case 32: +#if 0 + GetColorInfo (image, &c_info); + if ( c_info.alpha_mask == 0xff000000 && image->green_mask == 0x0000ff00) { + /* byte order is relevant here, not endianness + * endianness is handled by avcodec, but atm no such thing + * as having ABGR, instead of ARGB in a word. Since we + * need this for Solaris/SPARC, but need to do the conversion + * for every frame we do it outside of this loop, cf. below + * this matches both ARGB32 and ABGR32 */ + input_pixfmt = PIX_FMT_ARGB32; + } else { + av_log(s1, AV_LOG_ERROR,"image depth %i not supported ... aborting\n", image->bits_per_pixel); + return AVERROR(EIO); + } +#endif + input_pixfmt = PIX_FMT_RGB32; + break; + default: + av_log(s1, AV_LOG_ERROR, "image depth %i not supported ... aborting\n", image->bits_per_pixel); + return -1; + } + + x11grab->frame_size = ap->width * ap->height * image->bits_per_pixel/8; + x11grab->dpy = dpy; + x11grab->width = ap->width; + x11grab->height = ap->height; + x11grab->time_base = ap->time_base; + x11grab->time_frame = av_gettime() / av_q2d(ap->time_base); + x11grab->x_off = x_off; + x11grab->y_off = y_off; + x11grab->image = image; + x11grab->use_shm = use_shm; + x11grab->mouse_warning_shown = 0; + + st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_RAWVIDEO; + st->codec->width = ap->width; + st->codec->height = ap->height; + st->codec->pix_fmt = input_pixfmt; + st->codec->time_base = ap->time_base; + st->codec->bit_rate = x11grab->frame_size * 1/av_q2d(ap->time_base) * 8; + + return 0; +} + +/** + * Get pointer coordinates from X11. + * + * @param x Integer where horizontal coordinate will be returned + * @param y Integer where vertical coordinate will be returned + * @param dpy X11 display from where pointer coordinates are retrieved + * @param s1 Context used for logging errors if necessary + */ +static void +get_pointer_coordinates(int *x, int *y, Display *dpy, AVFormatContext *s1) +{ + Window mrootwindow, childwindow; + int dummy; + + mrootwindow = DefaultRootWindow(dpy); + + if (XQueryPointer(dpy, mrootwindow, &mrootwindow, &childwindow, + x, y, &dummy, &dummy, (unsigned int*)&dummy)) { + } else { + x11_grab_t *s = s1->priv_data; + if (!s->mouse_warning_shown) { + av_log(s1, AV_LOG_INFO, "couldn't find mouse pointer\n"); + s->mouse_warning_shown = 1; + } + *x = -1; + *y = -1; + } +} + +/** + * Mouse painting helper function that applies an 'and' and 'or' mask pair to + * '*dst' pixel. It actually draws a mouse pointer pixel to grabbed frame. + * + * @param dst Destination pixel + * @param and Part of the mask that must be applied using a bitwise 'and' + * operator + * @param or Part of the mask that must be applied using a bitwise 'or' + * operator + * @param bits_per_pixel Bits per pixel used in the grabbed image + */ +static void inline +apply_masks(uint8_t *dst, int and, int or, int bits_per_pixel) +{ + switch (bits_per_pixel) { + case 32: + *(uint32_t*)dst = (*(uint32_t*)dst & and) | or; + break; + case 16: + *(uint16_t*)dst = (*(uint16_t*)dst & and) | or; + break; + case 8: + *dst = !!or; + break; + } +} + +/** + * Paints a mouse pointer in an X11 image. + * + * @param image Image where to paint the mouse pointer + * @param s context used to retrieve original grabbing rectangle + * coordinates + * @param x Mouse pointer coordinate + * @param y Mouse pointer coordinate + */ +static void +paint_mouse_pointer(XImage *image, x11_grab_t *s, int x, int y) +{ + /* 16x20x1bpp bitmap for the black channel of the mouse pointer */ + static const uint16_t const mousePointerBlack[] = + { + 0x0000, 0x0003, 0x0005, 0x0009, 0x0011, + 0x0021, 0x0041, 0x0081, 0x0101, 0x0201, + 0x03c1, 0x0049, 0x0095, 0x0093, 0x0120, + 0x0120, 0x0240, 0x0240, 0x0380, 0x0000 + }; + + /* 16x20x1bpp bitmap for the white channel of the mouse pointer */ + static const uint16_t const mousePointerWhite[] = + { + 0x0000, 0x0000, 0x0002, 0x0006, 0x000e, + 0x001e, 0x003e, 0x007e, 0x00fe, 0x01fe, + 0x003e, 0x0036, 0x0062, 0x0060, 0x00c0, + 0x00c0, 0x0180, 0x0180, 0x0000, 0x0000 + }; + + int x_off = s->x_off; + int y_off = s->y_off; + int width = s->width; + int height = s->height; + + if ( x - x_off >= 0 && x < width + x_off + && y - y_off >= 0 && y < height + y_off) { + uint8_t *im_data = (uint8_t*)image->data; + int bytes_per_pixel; + int line; + int masks; + + /* Select correct masks and pixel size */ + if (image->bits_per_pixel == 8) { + masks = 1; + } else { + masks = (image->red_mask|image->green_mask|image->blue_mask); + } + bytes_per_pixel = image->bits_per_pixel>>3; + + /* Shift to right line */ + im_data += image->bytes_per_line * (y - y_off); + /* Shift to right pixel in the line */ + im_data += bytes_per_pixel * (x - x_off); + + /* Draw the cursor - proper loop */ + for (line = 0; line < FFMIN(20, (y_off + height) - y); line++) { + uint8_t *cursor = im_data; + int column; + uint16_t bm_b; + uint16_t bm_w; + + bm_b = mousePointerBlack[line]; + bm_w = mousePointerWhite[line]; + + for (column = 0; column < FFMIN(16, (x_off + width) - x); column++) { + apply_masks(cursor, ~(masks*(bm_b&1)), masks*(bm_w&1), + image->bits_per_pixel); + cursor += bytes_per_pixel; + bm_b >>= 1; + bm_w >>= 1; + } + im_data += image->bytes_per_line; + } + } +} + + +/** + * Reads new data in the image structure. + * + * @param dpy X11 display to grab from + * @param d + * @param image Image where the grab will be put + * @param x Top-Left grabbing rectangle horizontal coordinate + * @param y Top-Left grabbing rectangle vertical coordinate + * @return 0 if error, !0 if successful + */ +static int +xget_zpixmap(Display *dpy, Drawable d, XImage *image, int x, int y) +{ + xGetImageReply rep; + xGetImageReq *req; + long nbytes; + + if (!image) { + return 0; + } + + LockDisplay(dpy); + GetReq(GetImage, req); + + /* First set up the standard stuff in the request */ + req->drawable = d; + req->x = x; + req->y = y; + req->width = image->width; + req->height = image->height; + req->planeMask = (unsigned int)AllPlanes; + req->format = ZPixmap; + + if (!_XReply(dpy, (xReply *)&rep, 0, xFalse) || !rep.length) { + UnlockDisplay(dpy); + SyncHandle(); + return 0; + } + + nbytes = (long)rep.length << 2; + _XReadPad(dpy, image->data, nbytes); + + UnlockDisplay(dpy); + SyncHandle(); + return 1; +} + +/** + * Grabs a frame from x11 (public device demuxer API). + * + * @param s1 Context from avformat core + * @param pkt Packet holding the brabbed frame + * @return frame size in bytes + */ +static int +x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt) +{ + x11_grab_t *s = s1->priv_data; + Display *dpy = s->dpy; + XImage *image = s->image; + int x_off = s->x_off; + int y_off = s->y_off; + + int64_t curtime, delay; + struct timespec ts; + + /* Calculate the time of the next frame */ + s->time_frame += INT64_C(1000000); + + /* wait based on the frame rate */ + for(;;) { + curtime = av_gettime(); + delay = s->time_frame * av_q2d(s->time_base) - curtime; + if (delay <= 0) { + if (delay < INT64_C(-1000000) * av_q2d(s->time_base)) { + s->time_frame += INT64_C(1000000); + } + break; + } + ts.tv_sec = delay / 1000000; + ts.tv_nsec = (delay % 1000000) * 1000; + nanosleep(&ts, NULL); + } + + if (av_new_packet(pkt, s->frame_size) < 0) { + return AVERROR(EIO); + } + + pkt->pts = curtime; + + if(s->use_shm) { + if (!XShmGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, x_off, y_off, AllPlanes)) { + av_log (s1, AV_LOG_INFO, "XShmGetImage() failed\n"); + } + } else { + if (!xget_zpixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, x_off, y_off)) { + av_log (s1, AV_LOG_INFO, "XGetZPixmap() failed\n"); + } + } + + { + int pointer_x, pointer_y; + get_pointer_coordinates(&pointer_x, &pointer_y, dpy, s1); + paint_mouse_pointer(image, s, pointer_x, pointer_y); + } + + + /* XXX: avoid memcpy */ + memcpy(pkt->data, image->data, s->frame_size); + return s->frame_size; +} + +/** + * Closes x11 frame grabber (public device demuxer API). + * + * @param s1 Context from avformat core + * @return 0 success, !0 failure + */ +static int +x11grab_read_close(AVFormatContext *s1) +{ + x11_grab_t *x11grab = s1->priv_data; + + /* Detach cleanly from shared mem */ + if (x11grab->use_shm) { + XShmDetach(x11grab->dpy, &x11grab->shminfo); + shmdt(x11grab->shminfo.shmaddr); + shmctl(x11grab->shminfo.shmid, IPC_RMID, NULL); + } + + /* Destroy X11 image */ + if (x11grab->image) { + XDestroyImage(x11grab->image); + x11grab->image = NULL; + } + + /* Free X11 display */ + XCloseDisplay(x11grab->dpy); + return 0; +} + +/** x11 grabber device demuxer declaration */ +AVInputFormat x11_grab_device_demuxer = +{ + "x11grab", + "X11grab", + sizeof(x11_grab_t), + NULL, + x11grab_read_header, + x11grab_read_packet, + x11grab_read_close, + .flags = AVFMT_NOFILE, +}; diff --git a/contrib/ffmpeg/libavfilter/allfilters.c b/contrib/ffmpeg/libavfilter/allfilters.c new file mode 100644 index 000000000..fafd6d1c6 --- /dev/null +++ b/contrib/ffmpeg/libavfilter/allfilters.c @@ -0,0 +1,43 @@ +/* + * filter registration + * copyright (c) 2008 Vitor Sessak + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avfilter.h" + +#define REGISTER_VF(X,x) { \ + extern AVFilter avfilter_vf_##x ; \ + if(ENABLE_VF_##X ) avfilter_register(&avfilter_vf_##x ); } + + +#define REGISTER_VSRC(X,x) { \ + extern AVFilter avfilter_vsrc_##x ; \ + if(ENABLE_VSRC_##X ) avfilter_register(&avfilter_vsrc_##x ); } + +void avfilter_register_all(void) +{ + static int initialized; + + if (initialized) + return; + initialized = 1; + +// REGISTER_VF(CROP,crop); + +} diff --git a/contrib/ffmpeg/libavfilter/avfilter.c b/contrib/ffmpeg/libavfilter/avfilter.c new file mode 100644 index 000000000..0182e4701 --- /dev/null +++ b/contrib/ffmpeg/libavfilter/avfilter.c @@ -0,0 +1,390 @@ +/* + * filter layer + * copyright (c) 2007 Bobby Bingham + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avfilter.h" +#include "imgconvert.h" + +/** list of registered filters */ +struct FilterList +{ + AVFilter *filter; + struct FilterList *next; +} *filters = NULL; + +/** helper macros to get the in/out pad on the dst/src filter */ +#define link_dpad(link) link->dst-> input_pads[link->dstpad] +#define link_spad(link) link->src->output_pads[link->srcpad] + +AVFilterPicRef *avfilter_ref_pic(AVFilterPicRef *ref, int pmask) +{ + AVFilterPicRef *ret = av_malloc(sizeof(AVFilterPicRef)); + *ret = *ref; + ret->perms &= pmask; + ret->pic->refcount ++; + return ret; +} + +void avfilter_unref_pic(AVFilterPicRef *ref) +{ + if(!(--ref->pic->refcount)) + ref->pic->free(ref->pic); + av_free(ref); +} + +void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off, + AVFilterPad **pads, AVFilterLink ***links, + AVFilterPad *newpad) +{ + unsigned i; + + idx = FFMIN(idx, *count); + + *pads = av_realloc(*pads, sizeof(AVFilterPad) * (*count + 1)); + *links = av_realloc(*links, sizeof(AVFilterLink*) * (*count + 1)); + memmove(*pads +idx+1, *pads +idx, sizeof(AVFilterPad) * (*count-idx)); + memmove(*links+idx+1, *links+idx, sizeof(AVFilterLink*) * (*count-idx)); + memcpy(*pads+idx, newpad, sizeof(AVFilterPad)); + (*links)[idx] = NULL; + + (*count) ++; + for(i = idx+1; i < *count; i ++) + if(*links[i]) + (*(unsigned *)((uint8_t *) *links[i] + padidx_off)) ++; +} + +int avfilter_link(AVFilterContext *src, unsigned srcpad, + AVFilterContext *dst, unsigned dstpad) +{ + AVFilterLink *link; + + if(src->output_count <= srcpad || dst->input_count <= dstpad || + src->outputs[srcpad] || dst->inputs[dstpad]) + return -1; + + src->outputs[srcpad] = + dst-> inputs[dstpad] = link = av_mallocz(sizeof(AVFilterLink)); + + link->src = src; + link->dst = dst; + link->srcpad = srcpad; + link->dstpad = dstpad; + link->format = -1; + + return 0; +} + +int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt, + unsigned in, unsigned out) +{ + av_log(link->dst, AV_LOG_INFO, "auto-inserting filter '%s'\n", + filt->filter->name); + + link->dst->inputs[link->dstpad] = NULL; + if(avfilter_link(filt, out, link->dst, link->dstpad)) { + /* failed to link output filter to new filter */ + link->dst->inputs[link->dstpad] = link; + return -1; + } + + /* re-hookup the link to the new destination filter we inserted */ + link->dst = filt; + link->dstpad = in; + filt->inputs[in] = link; + + /* if any information on supported colorspaces already exists on the + * link, we need to preserve that */ + if(link->out_formats) + avfilter_formats_changeref(&link->out_formats, + &filt->outputs[out]->out_formats); + + return 0; +} + +int avfilter_config_links(AVFilterContext *filter) +{ + int (*config_link)(AVFilterLink *); + unsigned i; + + for(i = 0; i < filter->input_count; i ++) { + AVFilterLink *link = filter->inputs[i]; + + if(!link) continue; + + switch(link->init_state) { + case AVLINK_INIT: + continue; + case AVLINK_STARTINIT: + av_log(filter, AV_LOG_INFO, "circular filter chain detected\n"); + return 0; + case AVLINK_UNINIT: + link->init_state = AVLINK_STARTINIT; + + if(avfilter_config_links(link->src)) + return -1; + + if(!(config_link = link_spad(link).config_props)) + config_link = avfilter_default_config_output_link; + if(config_link(link)) + return -1; + + if((config_link = link_dpad(link).config_props)) + if(config_link(link)) + return -1; + + link->init_state = AVLINK_INIT; + } + } + + return 0; +} + +AVFilterPicRef *avfilter_get_video_buffer(AVFilterLink *link, int perms) +{ + AVFilterPicRef *ret = NULL; + + if(link_dpad(link).get_video_buffer) + ret = link_dpad(link).get_video_buffer(link, perms); + + if(!ret) + ret = avfilter_default_get_video_buffer(link, perms); + + return ret; +} + +int avfilter_request_frame(AVFilterLink *link) +{ + if(link_spad(link).request_frame) + return link_spad(link).request_frame(link); + else if(link->src->inputs[0]) + return avfilter_request_frame(link->src->inputs[0]); + else return -1; +} + +int avfilter_poll_frame(AVFilterLink *link) +{ + int i, min=INT_MAX; + + if(link_spad(link).poll_frame) + return link_spad(link).poll_frame(link); + + for (i=0; isrc->input_count; i++) { + if(!link->src->inputs[i]) + return -1; + min = FFMIN(min, avfilter_poll_frame(link->src->inputs[i])); + } + + return min; +} + +/* XXX: should we do the duplicating of the picture ref here, instead of + * forcing the source filter to do it? */ +void avfilter_start_frame(AVFilterLink *link, AVFilterPicRef *picref) +{ + void (*start_frame)(AVFilterLink *, AVFilterPicRef *); + AVFilterPad *dst = &link_dpad(link); + + if(!(start_frame = dst->start_frame)) + start_frame = avfilter_default_start_frame; + + /* prepare to copy the picture if it has insufficient permissions */ + if((dst->min_perms & picref->perms) != dst->min_perms || + dst->rej_perms & picref->perms) { + /* + av_log(link->dst, AV_LOG_INFO, + "frame copy needed (have perms %x, need %x, reject %x)\n", + picref->perms, + link_dpad(link).min_perms, link_dpad(link).rej_perms); + */ + + link->cur_pic = avfilter_default_get_video_buffer(link, dst->min_perms); + link->srcpic = picref; + link->cur_pic->pts = link->srcpic->pts; + } + else + link->cur_pic = picref; + + start_frame(link, link->cur_pic); +} + +void avfilter_end_frame(AVFilterLink *link) +{ + void (*end_frame)(AVFilterLink *); + + if(!(end_frame = link_dpad(link).end_frame)) + end_frame = avfilter_default_end_frame; + + end_frame(link); + + /* unreference the source picture if we're feeding the destination filter + * a copied version dues to permission issues */ + if(link->srcpic) { + avfilter_unref_pic(link->srcpic); + link->srcpic = NULL; + } + +} + +void avfilter_draw_slice(AVFilterLink *link, int y, int h) +{ + uint8_t *src[4], *dst[4]; + int i, j, hsub, vsub; + + /* copy the slice if needed for permission reasons */ + if(link->srcpic) { + avcodec_get_chroma_sub_sample(link->format, &hsub, &vsub); + + for(i = 0; i < 4; i ++) { + if(link->srcpic->data[i]) { + src[i] = link->srcpic-> data[i] + + (y >> (i==0 ? 0 : vsub)) * link->srcpic-> linesize[i]; + dst[i] = link->cur_pic->data[i] + + (y >> (i==0 ? 0 : vsub)) * link->cur_pic->linesize[i]; + } else + src[i] = dst[i] = NULL; + } + + for(i = 0; i < 4; i ++) { + int planew = + ff_get_plane_bytewidth(link->format, link->cur_pic->w, i); + + if(!src[i]) continue; + + for(j = 0; j < h >> (i==0 ? 0 : vsub); j ++) { + memcpy(dst[i], src[i], planew); + src[i] += link->srcpic ->linesize[i]; + dst[i] += link->cur_pic->linesize[i]; + } + } + } + + if(link_dpad(link).draw_slice) + link_dpad(link).draw_slice(link, y, h); +} + +AVFilter *avfilter_get_by_name(const char *name) +{ + struct FilterList *filt; + + for(filt = filters; filt; filt = filt->next) + if(!strcmp(filt->filter->name, name)) + return filt->filter; + + return NULL; +} + +void avfilter_register(AVFilter *filter) +{ + struct FilterList *newfilt = av_malloc(sizeof(struct FilterList)); + + newfilt->filter = filter; + newfilt->next = filters; + filters = newfilt; +} + +void avfilter_uninit(void) +{ + struct FilterList *tmp; + + for(; filters; filters = tmp) { + tmp = filters->next; + av_free(filters); + } +} + +static int pad_count(const AVFilterPad *pads) +{ + int count; + + for(count = 0; pads->name; count ++) pads ++; + return count; +} + +static const char *filter_name(void *p) +{ + AVFilterContext *filter = p; + return filter->filter->name; +} + +AVFilterContext *avfilter_open(AVFilter *filter, const char *inst_name) +{ + AVFilterContext *ret; + + if (!filter) + return 0; + + ret = av_malloc(sizeof(AVFilterContext)); + + ret->av_class = av_mallocz(sizeof(AVClass)); + ret->av_class->item_name = filter_name; + ret->filter = filter; + ret->name = inst_name ? av_strdup(inst_name) : NULL; + ret->priv = av_mallocz(filter->priv_size); + + ret->input_count = pad_count(filter->inputs); + ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->input_count); + memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad)*ret->input_count); + ret->inputs = av_mallocz(sizeof(AVFilterLink*) * ret->input_count); + + ret->output_count = pad_count(filter->outputs); + ret->output_pads = av_malloc(sizeof(AVFilterPad) * ret->output_count); + memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad)*ret->output_count); + ret->outputs = av_mallocz(sizeof(AVFilterLink*) * ret->output_count); + + return ret; +} + +void avfilter_destroy(AVFilterContext *filter) +{ + int i; + + if(filter->filter->uninit) + filter->filter->uninit(filter); + + for(i = 0; i < filter->input_count; i ++) { + if(filter->inputs[i]) + filter->inputs[i]->src->outputs[filter->inputs[i]->srcpad] = NULL; + av_freep(&filter->inputs[i]); + } + for(i = 0; i < filter->output_count; i ++) { + if(filter->outputs[i]) + filter->outputs[i]->dst->inputs[filter->outputs[i]->dstpad] = NULL; + av_freep(&filter->outputs[i]); + } + + av_freep(&filter->name); + av_freep(&filter->input_pads); + av_freep(&filter->output_pads); + av_freep(&filter->inputs); + av_freep(&filter->outputs); + av_freep(&filter->priv); + av_freep(&filter->av_class); + av_free(filter); +} + +int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque) +{ + int ret=0; + + if(filter->filter->init) + ret = filter->filter->init(filter, args, opaque); + return ret; +} + diff --git a/contrib/ffmpeg/libavfilter/avfilter.h b/contrib/ffmpeg/libavfilter/avfilter.h new file mode 100644 index 000000000..1a2aa0f35 --- /dev/null +++ b/contrib/ffmpeg/libavfilter/avfilter.h @@ -0,0 +1,616 @@ +/* + * filter layer + * copyright (c) 2007 Bobby Bingham + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_AVFILTER_H +#define FFMPEG_AVFILTER_H + +#define LIBAVFILTER_VERSION_MAJOR 0 +#define LIBAVFILTER_VERSION_MINOR 0 +#define LIBAVFILTER_VERSION_MICRO 0 + +#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ + LIBAVFILTER_VERSION_MINOR, \ + LIBAVFILTER_VERSION_MICRO) +#define LIBAVFILTER_VERSION AV_VERSION(LIBAVFILTER_VERSION_MAJOR, \ + LIBAVFILTER_VERSION_MINOR, \ + LIBAVFILTER_VERSION_MICRO) +#define LIBAVFILTER_BUILD LIBAVFILTER_VERSION_INT + +#include +#include "avcodec.h" + +typedef struct AVFilterContext AVFilterContext; +typedef struct AVFilterLink AVFilterLink; +typedef struct AVFilterPad AVFilterPad; + +/* TODO: look for other flags which may be useful in this structure (interlace + * flags, etc) + */ +/** + * A reference-counted picture data type used by the filter system. Filters + * should not store pointers to this structure directly, but instead use the + * AVFilterPicRef structure below. + */ +typedef struct AVFilterPic +{ + uint8_t *data[4]; ///< picture data for each plane + int linesize[4]; ///< number of bytes per line + enum PixelFormat format; ///< colorspace + + unsigned refcount; ///< number of references to this image + + /** private data to be used by a custom free function */ + void *priv; + /** + * A pointer to the function to deallocate this image if the default + * function is not sufficient. This could, for example, add the memory + * back into a memory pool to be reused later without the overhead of + * reallocating it from scratch. + */ + void (*free)(struct AVFilterPic *pic); +} AVFilterPic; + +/** + * A reference to an AVFilterPic. Since filters can manipulate the origin of + * a picture to, for example, crop image without any memcpy, the picture origin + * and dimensions are per-reference properties. Linesize is also useful for + * image flipping, frame to field filters, etc, and so is also per-reference. + * + * TODO: add anything necessary for frame reordering + */ +typedef struct AVFilterPicRef +{ + AVFilterPic *pic; ///< the picture that this is a reference to + uint8_t *data[4]; ///< picture data for each plane + int linesize[4]; ///< number of bytes per line + int w; ///< image width + int h; ///< image height + + int64_t pts; ///< presentation timestamp in units of 1/AV_TIME_BASE + + AVRational pixel_aspect; ///< pixel aspect ratio + + int perms; ///< permissions +#define AV_PERM_READ 0x01 ///< can read from the buffer +#define AV_PERM_WRITE 0x02 ///< can write to the buffer +#define AV_PERM_PRESERVE 0x04 ///< nobody else can overwrite the buffer +#define AV_PERM_REUSE 0x08 ///< can output the buffer multiple times, with the same contents each time +#define AV_PERM_REUSE2 0x10 ///< can output the buffer multiple times, modified each time +} AVFilterPicRef; + +/** + * Add a new reference to a picture. + * @param ref an existing reference to the picture + * @param pmask a bitmask containing the allowable permissions in the new + * reference + * @return a new reference to the picture with the same properties as the + * old, excluding any permissions denied by pmask + */ +AVFilterPicRef *avfilter_ref_pic(AVFilterPicRef *ref, int pmask); + +/** + * Remove a reference to a picture. If this is the last reference to the + * picture, the picture itself is also automatically freed. + * @param ref reference to the picture + */ +void avfilter_unref_pic(AVFilterPicRef *ref); + +/** + * A list of supported formats for one end of a filter link. This is used + * during the format negotiation process to try to pick the best format to + * use to minimize the number of necessary conversions. Each filter gives a + * list of the formats supported by each input and output pad. The list + * given for each pad need not be distinct - they may be references to the + * same list of formats, as is often the case when a filter supports multiple + * formats, but will always outut the same format as it is given in input. + * + * In this way, a list of possible input formats and a list of possible + * output formats are associated with each link. When a set of formats is + * negotiated over a link, the input and output lists are merged to form a + * new list containing only the common elements of each list. In the case + * that there were no common elements, a format conversion is necessary. + * Otherwise, the lists are merged, and all other links which reference + * either of the format lists involved in the merge are also affected. + * + * For example, consider the filter chain: + * filter (a) --> (b) filter (b) --> (c) filter + * + * where the letters in parenthesis indicate a list of formats supported on + * the input or output of the link. Suppose the lists are as follows: + * (a) = {A, B} + * (b) = {A, B, C} + * (c) = {B, C} + * + * First, the first link's lists are merged, yielding: + * filter (a) --> (a) filter (a) --> (c) filter + * + * Notice that format list (b) now refers to the same list as filter list (a). + * Next, the lists for the second link are merged, yielding: + * filter (a) --> (a) filter (a) --> (a) filter + * + * where (a) = {B}. + * + * Unfortunately, when the format lists at the two ends of a link are merged, + * we must ensure that all links which reference either pre-merge format list + * get updated as well. Therefore, we have the format list structure store a + * pointer to each of the pointers to itself. + */ +typedef struct AVFilterFormats AVFilterFormats; +struct AVFilterFormats +{ + unsigned format_count; ///< number of formats + int *formats; ///< list of formats + + unsigned refcount; ///< number of references to this list + AVFilterFormats ***refs; ///< references to this list +}; + +/** + * Helper function to create a list of supported formats. This is intended + * for use in AVFilter->query_formats(). + * @param len the number of formats supported + * @param ... a list of the supported formats + * @return the format list, with no existing references + */ +AVFilterFormats *avfilter_make_format_list(int len, ...); + +/** + * Returns a list of all colorspaces supported by FFmpeg. + */ +AVFilterFormats *avfilter_all_colorspaces(void); + +/** + * Returns a format list which contains the intersection of the formats of + * a and b. And all the references of a and b, and a and b will be + * deallocated. + * + * If a and b do not share any common formats, neither is modified, and NULL + * is returned. + */ +AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b); + +/** + * Adds *ref as a new reference to f. + * That is the pointers will point like in the ascii art below: + * ________ + * | f |<--------. + * | ____ | | + * | |refs| | __|_ + * | |* * | | | | | + * | |* *--------->|*ref| + * | |____| | |____| + * |________| + */ +void avfilter_formats_ref(AVFilterFormats *f, AVFilterFormats **ref); + +/** + * Remove *ref as a reference to the format list it currently points to, + * deallocate that list if this was the last reference, and set *ref to NULL. + */ +void avfilter_formats_unref(AVFilterFormats **ref); + +/** + * + * Before After + * ________ ________ + * | f |<---------. | f |<---------. + * | ____ | ___|___ | ____ | ___|___ + * | |refs| | | | | | |refs| | | | | NULL + * | |* *--------->|*oldref| | |* *--------->|*newref| ^ + * | |* * | | |_______| | |* * | | |_______| ___|___ + * | |____| | | |____| | | | | + * |________| |________| |*oldref| + * |_______| + */ +void avfilter_formats_changeref(AVFilterFormats **oldref, + AVFilterFormats **newref); + +/** + * A filter pad used for either input or output. + */ +struct AVFilterPad +{ + /** + * Pad name. The name is unique among inputs and among outputs, but an + * input may have the same name as an output. This may be NULL if this + * pad has no need to ever be referenced by name. + */ + const char *name; + + /** + * AVFilterPad type. Only video supported now, hopefully someone will + * add audio in the future. + */ + enum CodecType type; + + /** + * Minimum required permissions on incoming buffers. Any buffers with + * insufficient permissions will be automatically copied by the filter + * system to a new buffer which provides the needed access permissions. + * + * Input pads only. + */ + int min_perms; + + /** + * Permissions which are not accepted on incoming buffers. Any buffer + * which has any of these permissions set be automatically copied by the + * filter system to a new buffer which does not have those permissions. + * This can be used to easily disallow buffers with AV_PERM_REUSE. + * + * Input pads only. + */ + int rej_perms; + + /** + * Callback called before passing the first slice of a new frame. If + * NULL, the filter layer will default to storing a reference to the + * picture inside the link structure. + * + * Input video pads only. + */ + void (*start_frame)(AVFilterLink *link, AVFilterPicRef *picref); + + /** + * Callback function to get a buffer. If NULL, the filter system will + * handle buffer requests. + * + * Input video pads only. + */ + AVFilterPicRef *(*get_video_buffer)(AVFilterLink *link, int perms); + + /** + * Callback called after the slices of a frame are completely sent. If + * NULL, the filter layer will default to releasing the reference stored + * in the link structure during start_frame(). + * + * Input video pads only. + */ + void (*end_frame)(AVFilterLink *link); + + /** + * Slice drawing callback. This is where a filter receives video data + * and should do its processing. + * + * Input video pads only. + */ + void (*draw_slice)(AVFilterLink *link, int y, int height); + + /** + * Frame poll callback. This returns the number of immediately available + * frames. It should return a positive value if the next request_frame() + * is guaranteed to return one frame (with no delay). + * + * Defaults to just calling the source poll_frame() method. + * + * Output video pads only. + */ + int (*poll_frame)(AVFilterLink *link); + + /** + * Frame request callback. A call to this should result in at least one + * frame being output over the given link. This should return zero on + * success, and another value on error. + * + * Output video pads only. + */ + int (*request_frame)(AVFilterLink *link); + + /** + * Link configuration callback. + * + * For output pads, this should set the link properties such as + * width/height. This should NOT set the format property - that is + * negotiated between filters by the filter system using the + * query_formats() callback before this function is called. + * + * For input pads, this should check the properties of the link, and update + * the filter's internal state as necessary. + * + * For both input and output filters, this should return zero on success, + * and another value on error. + */ + int (*config_props)(AVFilterLink *link); +}; + +/** Default handler for start_frame() for video inputs */ +void avfilter_default_start_frame(AVFilterLink *link, AVFilterPicRef *picref); +/** Default handler for end_frame() for video inputs */ +void avfilter_default_end_frame(AVFilterLink *link); +/** Default handler for config_props() for video outputs */ +int avfilter_default_config_output_link(AVFilterLink *link); +/** Default handler for config_props() for video inputs */ +int avfilter_default_config_input_link (AVFilterLink *link); +/** Default handler for get_video_buffer() for video inputs */ +AVFilterPicRef *avfilter_default_get_video_buffer(AVFilterLink *link, + int perms); +/** + * A helper for query_formats() which sets all links to the same list of + * formats. If there are no links hooked to this filter, the list of formats is + * freed. + */ +void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats); +/** Default handler for query_formats() */ +int avfilter_default_query_formats(AVFilterContext *ctx); + +/** + * Filter definition. This defines the pads a filter contains, and all the + * callback functions used to interact with the filter. + */ +typedef struct +{ + const char *name; ///< filter name + + int priv_size; ///< size of private data to allocate for the filter + + /** + * Filter initialization function. Args contains the user-supplied + * parameters. FIXME: maybe an AVOption-based system would be better? + * opaque is data provided by the code requesting creation of the filter, + * and is used to pass data to the filter. + */ + int (*init)(AVFilterContext *ctx, const char *args, void *opaque); + + /** + * Filter uninitialization function. Should deallocate any memory held + * by the filter, release any picture references, etc. This does not need + * to deallocate the AVFilterContext->priv memory itself. + */ + void (*uninit)(AVFilterContext *ctx); + + /** + * Query formats supported by the filter and its pads. Should set the + * in_formats for links connected to its output pads, and out_formats + * for links connected to its input pads. + * + * Should return zero on success. + */ + int (*query_formats)(AVFilterContext *); + + const AVFilterPad *inputs; ///< NULL terminated list of inputs. NULL if none + const AVFilterPad *outputs; ///< NULL terminated list of outputs. NULL if none +} AVFilter; + +/** An instance of a filter */ +struct AVFilterContext +{ + AVClass *av_class; ///< needed for av_log() + + AVFilter *filter; ///< the AVFilter of which this is an instance + + char *name; ///< name of this filter instance + + unsigned input_count; ///< number of input pads + AVFilterPad *input_pads; ///< array of input pads + AVFilterLink **inputs; ///< array of pointers to input links + + unsigned output_count; ///< number of output pads + AVFilterPad *output_pads; ///< array of output pads + AVFilterLink **outputs; ///< array of pointers to output links + + void *priv; ///< private data for use by the filter +}; + +/** + * A link between two filters. This contains pointers to the source and + * destination filters between which this link exists, and the indices of + * the pads involved. In addition, this link also contains the parameters + * which have been negotiated and agreed upon between the filter, such as + * image dimensions, format, etc + */ +struct AVFilterLink +{ + AVFilterContext *src; ///< source filter + unsigned int srcpad; ///< index of the output pad on the source filter + + AVFilterContext *dst; ///< dest filter + unsigned int dstpad; ///< index of the input pad on the dest filter + + /** stage of the initialization of the link properties (dimensions, etc) */ + enum { + AVLINK_UNINIT = 0, ///< not started + AVLINK_STARTINIT, ///< started, but incomplete + AVLINK_INIT ///< complete + } init_state; + + int w; ///< agreed upon image width + int h; ///< agreed upon image height + enum PixelFormat format; ///< agreed upon image colorspace + + /** + * Lists of formats supported by the input and output filters respectively. + * These lists are used for negotiating the format to actually be used, + * which will be loaded into the format member, above, when chosen. + */ + AVFilterFormats *in_formats; + AVFilterFormats *out_formats; + + /** + * The picture reference currently being sent across the link by the source + * filter. This is used internally by the filter system to allow + * automatic copying of pictures which do not have sufficient permissions + * for the destination. This should not be accessed directly by the + * filters. + */ + AVFilterPicRef *srcpic; + + AVFilterPicRef *cur_pic; + AVFilterPicRef *outpic; +}; + +/** + * Link two filters together. + * @param src the source filter + * @param srcpad index of the output pad on the source filter + * @param dst the destination filter + * @param dstpad index of the input pad on the destination filter + * @return zero on success + */ +int avfilter_link(AVFilterContext *src, unsigned srcpad, + AVFilterContext *dst, unsigned dstpad); + +/** + * Negotiate the colorspace, dimensions, etc of all inputs to a filter. + * @param filter the filter to negotiate the properties for its inputs + * @return zero on successful negotiation + */ +int avfilter_config_links(AVFilterContext *filter); + +/** + * Request a picture buffer with a specific set of permissions + * @param link the output link to the filter from which the picture will + * be requested + * @param perms the required access permissions + * @return A reference to the picture. This must be unreferenced with + * avfilter_unref_pic when you are finished with it. + */ +AVFilterPicRef *avfilter_get_video_buffer(AVFilterLink *link, int perms); + +/** + * Request an input frame from the filter at the other end of the link. + * @param link the input link + * @return zero on success + */ +int avfilter_request_frame(AVFilterLink *link); + +/** + * Poll a frame from the filter chain. + * @param link the input link + * @return the number of imediately available frames + */ +int avfilter_poll_frame(AVFilterLink *link); + +/** + * Notify the next filter of the start of a frame. + * @param link the output link the frame will be sent over + * @param picref A reference to the frame about to be sent. The data for this + * frame need only be valid once draw_slice() is called for that + * portion. The receiving filter will free this reference when + * it no longer needs it. + */ +void avfilter_start_frame(AVFilterLink *link, AVFilterPicRef *picref); + +/** + * Notify the next filter that the current frame has finished + * @param link the output link the frame was sent over + */ +void avfilter_end_frame(AVFilterLink *link); + +/** + * Send a slice to the next filter. + * @param link the output link over which the frame is being sent + * @param y offset in pixels from the top of the image for this slice + * @param h height of this slice in pixels + */ +void avfilter_draw_slice(AVFilterLink *link, int y, int h); + +/** Initialize the filter system. Registers all builtin filters */ +void avfilter_register_all(void); + +/** Uninitialize the filter system. Unregisters all filters */ +void avfilter_uninit(void); + +/** + * Register a filter. This is only needed if you plan to use + * avfilter_get_by_name later to lookup the AVFilter structure by name. A + * filter can still by instantiated with avfilter_open even if it is not + * registered. + * @param filter the filter to register + */ +void avfilter_register(AVFilter *filter); + +/** + * Gets a filter definition matching the given name. + * @param name the filter name to find + * @return the filter definition, if any matching one is registered. + * NULL if none found. + */ +AVFilter *avfilter_get_by_name(const char *name); + +/** + * Create a filter instance. + * @param filter the filter to create an instance of + * @param inst_name Name to give to the new instance. Can be NULL for none. + * @return Pointer to the new instance on success. NULL on failure. + */ +AVFilterContext *avfilter_open(AVFilter *filter, const char *inst_name); + +/** + * Initialize a filter. + * @param filter the filter to initialize + * @param args A string of parameters to use when initializing the filter. + * The format and meaning of this string varies by filter. + * @param opaque Any extra non-string data needed by the filter. The meaning + * of this parameter varies by filter. + * @return zero on success + */ +int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque); + +/** + * Destroy a filter. + * @param filter the filter to destroy + */ +void avfilter_destroy(AVFilterContext *filter); + +/** + * Insert a filter in the middle of an existing link. + * @param link the link into which the filter should be inserted + * @param filt the filter to be inserted + * @param in the input pad on the filter to connect + * @param out the output pad on the filter to connect + * @return zero on success + */ +int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt, + unsigned in, unsigned out); + +/** + * Insert a new pad. + * @param idx Insertion point. Pad is inserted at the end if this point + * is beyond the end of the list of pads. + * @param count Pointer to the number of pads in the list + * @param padidx_off Offset within an AVFilterLink structure to the element + * to increment when inserting a new pad causes link + * numbering to change + * @param pads Pointer to the pointer to the beginning of the list of pads + * @param links Pointer to the pointer to the beginning of the list of links + * @param newpad The new pad to add. A copy is made when adding. + */ +void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off, + AVFilterPad **pads, AVFilterLink ***links, + AVFilterPad *newpad); + +/** insert a new input pad for the filter */ +static inline void avfilter_insert_inpad(AVFilterContext *f, unsigned index, + AVFilterPad *p) +{ + avfilter_insert_pad(index, &f->input_count, offsetof(AVFilterLink, dstpad), + &f->input_pads, &f->inputs, p); +} + +/** insert a new output pad for the filter */ +static inline void avfilter_insert_outpad(AVFilterContext *f, unsigned index, + AVFilterPad *p) +{ + avfilter_insert_pad(index, &f->output_count, offsetof(AVFilterLink, srcpad), + &f->output_pads, &f->outputs, p); +} + +#endif /* FFMPEG_AVFILTER_H */ diff --git a/contrib/ffmpeg/libavfilter/defaults.c b/contrib/ffmpeg/libavfilter/defaults.c new file mode 100644 index 000000000..ab184973a --- /dev/null +++ b/contrib/ffmpeg/libavfilter/defaults.c @@ -0,0 +1,158 @@ +/* + * Filter layer - default implementations + * copyright (c) 2007 Bobby Bingham + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avfilter.h" +#include "imgconvert.h" + +/* TODO: buffer pool. see comment for avfilter_default_get_video_buffer() */ +void avfilter_default_free_video_buffer(AVFilterPic *pic) +{ + av_free(pic->data[0]); + av_free(pic); +} + +#define ALIGN(a) do{ \ + (a) = ((a) + 15) & (~15); \ + } while(0); + +/* TODO: set the buffer's priv member to a context structure for the whole + * filter chain. This will allow for a buffer pool instead of the constant + * alloc & free cycle currently implemented. */ +AVFilterPicRef *avfilter_default_get_video_buffer(AVFilterLink *link, int perms) +{ + AVFilterPic *pic = av_mallocz(sizeof(AVFilterPic)); + AVFilterPicRef *ref = av_mallocz(sizeof(AVFilterPicRef)); + int i, tempsize; + char *buf; + + ref->pic = pic; + ref->w = link->w; + ref->h = link->h; + + /* make sure the buffer gets read permission or it's useless for output */ + ref->perms = perms | AV_PERM_READ; + + pic->refcount = 1; + pic->format = link->format; + pic->free = avfilter_default_free_video_buffer; + ff_fill_linesize((AVPicture *)pic, pic->format, ref->w); + + for (i=0; i<4;i++) + ALIGN(pic->linesize[i]); + + tempsize = ff_fill_pointer((AVPicture *)pic, NULL, pic->format, ref->h); + buf = av_malloc(tempsize); + ff_fill_pointer((AVPicture *)pic, buf, pic->format, ref->h); + + memcpy(ref->data, pic->data, sizeof(pic->data)); + memcpy(ref->linesize, pic->linesize, sizeof(pic->linesize)); + + return ref; +} + +void avfilter_default_start_frame(AVFilterLink *link, AVFilterPicRef *picref) +{ + AVFilterLink *out = NULL; + + if(link->dst->output_count) + out = link->dst->outputs[0]; + + if(out) { + out->outpic = avfilter_get_video_buffer(out, AV_PERM_WRITE); + out->outpic->pts = picref->pts; + avfilter_start_frame(out, avfilter_ref_pic(out->outpic, ~0)); + } +} + +void avfilter_default_end_frame(AVFilterLink *link) +{ + AVFilterLink *out = NULL; + + if(link->dst->output_count) + out = link->dst->outputs[0]; + + avfilter_unref_pic(link->cur_pic); + link->cur_pic = NULL; + + if(out) { + if(out->outpic) { + avfilter_unref_pic(out->outpic); + out->outpic = NULL; + } + avfilter_end_frame(out); + } +} + +/** + * default config_link() implementation for output video links to simplify + * the implementation of one input one output video filters */ +int avfilter_default_config_output_link(AVFilterLink *link) +{ + if(link->src->input_count && link->src->inputs[0]) { + link->w = link->src->inputs[0]->w; + link->h = link->src->inputs[0]->h; + } else { + /* XXX: any non-simple filter which would cause this branch to be taken + * really should implement its own config_props() for this link. */ + return -1; + } + + return 0; +} + +/** + * A helper for query_formats() which sets all links to the same list of + * formats. If there are no links hooked to this filter, the list of formats is + * freed. + * + * FIXME: this will need changed for filters with a mix of pad types + * (video + audio, etc) + */ +void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats) +{ + int count = 0, i; + + for(i = 0; i < ctx->input_count; i ++) { + if(ctx->inputs[i]) { + avfilter_formats_ref(formats, &ctx->inputs[i]->out_formats); + count ++; + } + } + for(i = 0; i < ctx->output_count; i ++) { + if(ctx->outputs[i]) { + avfilter_formats_ref(formats, &ctx->outputs[i]->in_formats); + count ++; + } + } + + if(!count) { + av_free(formats->formats); + av_free(formats->refs); + av_free(formats); + } +} + +int avfilter_default_query_formats(AVFilterContext *ctx) +{ + avfilter_set_common_formats(ctx, avfilter_all_colorspaces()); + return 0; +} + diff --git a/contrib/ffmpeg/libavfilter/formats.c b/contrib/ffmpeg/libavfilter/formats.c new file mode 100644 index 000000000..33fec163a --- /dev/null +++ b/contrib/ffmpeg/libavfilter/formats.c @@ -0,0 +1,148 @@ +/* + * Filter layer - format negotiation + * copyright (c) 2007 Bobby Bingham + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avfilter.h" + +/** + * Add all refs from a to ret and destroy a. + */ +static void merge_ref(AVFilterFormats *ret, AVFilterFormats *a) +{ + int i; + + for(i = 0; i < a->refcount; i ++) { + ret->refs[ret->refcount] = a->refs[i]; + *ret->refs[ret->refcount++] = ret; + } + + av_free(a->refs); + av_free(a->formats); + av_free(a); +} + +AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b) +{ + AVFilterFormats *ret; + unsigned i, j, k = 0; + + ret = av_mallocz(sizeof(AVFilterFormats)); + + /* merge list of formats */ + ret->formats = av_malloc(sizeof(*ret->formats) * FFMIN(a->format_count, + b->format_count)); + for(i = 0; i < a->format_count; i ++) + for(j = 0; j < b->format_count; j ++) + if(a->formats[i] == b->formats[j]) + ret->formats[k++] = a->formats[i]; + + ret->format_count = k; + /* check that there was at least one common format */ + if(!ret->format_count) { + av_free(ret->formats); + av_free(ret); + return NULL; + } + + ret->refs = av_malloc(sizeof(AVFilterFormats**)*(a->refcount+b->refcount)); + + merge_ref(ret, a); + merge_ref(ret, b); + + return ret; +} + +AVFilterFormats *avfilter_make_format_list(int len, ...) +{ + AVFilterFormats *ret; + int i; + va_list vl; + + ret = av_mallocz(sizeof(AVFilterFormats)); + ret->formats = av_malloc(sizeof(*ret->formats) * len); + ret->format_count = len; + + va_start(vl, len); + for(i = 0; i < len; i ++) + ret->formats[i] = va_arg(vl, int); + va_end(vl); + + return ret; +} + +AVFilterFormats *avfilter_all_colorspaces(void) +{ + AVFilterFormats *ret; + int i; + + ret = av_mallocz(sizeof(AVFilterFormats)); + ret->formats = av_malloc(sizeof(*ret->formats) * PIX_FMT_NB); + ret->format_count = PIX_FMT_NB; + + for(i = 0; i < PIX_FMT_NB; i ++) + ret->formats[i] = i; + + return ret; +} + +void avfilter_formats_ref(AVFilterFormats *f, AVFilterFormats **ref) +{ + *ref = f; + f->refs = av_realloc(f->refs, sizeof(AVFilterFormats**) * ++f->refcount); + f->refs[f->refcount-1] = ref; +} + +static int find_ref_index(AVFilterFormats **ref) +{ + int i; + for(i = 0; i < (*ref)->refcount; i ++) + if((*ref)->refs[i] == ref) + return i; + return -1; +} + +void avfilter_formats_unref(AVFilterFormats **ref) +{ + int idx = find_ref_index(ref); + + if(idx >= 0) + memmove((*ref)->refs + idx, (*ref)->refs + idx+1, + sizeof(AVFilterFormats**) * ((*ref)->refcount-idx-1)); + + if(!--(*ref)->refcount) { + av_free((*ref)->formats); + av_free((*ref)->refs); + av_free(*ref); + } + *ref = NULL; +} + +void avfilter_formats_changeref(AVFilterFormats **oldref, + AVFilterFormats **newref) +{ + int idx = find_ref_index(oldref); + + if(idx >= 0) { + (*oldref)->refs[idx] = newref; + *newref = *oldref; + *oldref = NULL; + } +} + diff --git a/contrib/ffmpeg/libavformat/4xm.c b/contrib/ffmpeg/libavformat/4xm.c index bf10b9e82..151e9c9c8 100644 --- a/contrib/ffmpeg/libavformat/4xm.c +++ b/contrib/ffmpeg/libavformat/4xm.c @@ -44,6 +44,9 @@ #define ifrm_TAG MKTAG('i', 'f', 'r', 'm') #define pfrm_TAG MKTAG('p', 'f', 'r', 'm') #define cfrm_TAG MKTAG('c', 'f', 'r', 'm') +#define ifr2_TAG MKTAG('i', 'f', 'r', '2') +#define pfr2_TAG MKTAG('p', 'f', 'r', '2') +#define cfr2_TAG MKTAG('c', 'f', 'r', '2') #define snd__TAG MKTAG('s', 'n', 'd', '_') #define vtrk_SIZE 0x44 @@ -79,9 +82,6 @@ typedef struct FourxmDemuxContext { static int fourxm_probe(AVProbeData *p) { - if (p->buf_size < 12) - return 0; - if ((AV_RL32(&p->buf[0]) != RIFF_TAG) || (AV_RL32(&p->buf[8]) != _4XMV_TAG)) return 0; @@ -92,11 +92,11 @@ static int fourxm_probe(AVProbeData *p) static int fourxm_read_header(AVFormatContext *s, AVFormatParameters *ap) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; unsigned int fourcc_tag; unsigned int size; int header_size; - FourxmDemuxContext *fourxm = (FourxmDemuxContext *)s->priv_data; + FourxmDemuxContext *fourxm = s->priv_data; unsigned char *header; int i; int current_track = -1; @@ -119,9 +119,9 @@ static int fourxm_read_header(AVFormatContext *s, /* allocate space for the header and load the whole thing */ header = av_malloc(header_size); if (!header) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); if (get_buffer(pb, header, header_size) != header_size) - return AVERROR_IO; + return AVERROR(EIO); /* take the lazy approach and search for any and all vtrk and strk chunks */ for (i = 0; i < header_size - 8; i++) { @@ -138,22 +138,24 @@ static int fourxm_read_header(AVFormatContext *s, } fourxm->width = AV_RL32(&header[i + 36]); fourxm->height = AV_RL32(&header[i + 40]); - i += 8 + size; /* allocate a new AVStream */ st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 60, 1, fourxm->fps); fourxm->video_stream_index = st->index; st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_4XM; - st->codec->codec_tag = 0; /* no fourcc */ + st->codec->extradata_size = 4; + st->codec->extradata = av_malloc(4); + AV_WL32(st->codec->extradata, AV_RL32(&header[i + 16])); st->codec->width = fourxm->width; st->codec->height = fourxm->height; + i += 8 + size; } else if (fourcc_tag == strk_TAG) { /* check that there is enough data */ if (size != strk_SIZE) { @@ -169,7 +171,7 @@ static int fourxm_read_header(AVFormatContext *s, fourxm->track_count * sizeof(AudioTrack)); if (!fourxm->tracks) { av_free(header); - return AVERROR_NOMEM; + return AVERROR(ENOMEM); } } fourxm->tracks[current_track].adpcm = AV_RL32(&header[i + 12]); @@ -181,7 +183,7 @@ static int fourxm_read_header(AVFormatContext *s, /* allocate a new AVStream */ st = av_new_stream(s, current_track); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 60, 1, fourxm->tracks[current_track].sample_rate); @@ -222,7 +224,7 @@ static int fourxm_read_packet(AVFormatContext *s, AVPacket *pkt) { FourxmDemuxContext *fourxm = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; unsigned int fourcc_tag; unsigned int size, out_size; int ret = 0; @@ -233,12 +235,12 @@ static int fourxm_read_packet(AVFormatContext *s, while (!packet_read) { - if ((ret = get_buffer(&s->pb, header, 8)) < 0) + if ((ret = get_buffer(s->pb, header, 8)) < 0) return ret; fourcc_tag = AV_RL32(&header[0]); size = AV_RL32(&header[4]); if (url_feof(pb)) - return AVERROR_IO; + return AVERROR(EIO); switch (fourcc_tag) { case LIST_TAG: @@ -251,17 +253,21 @@ static int fourxm_read_packet(AVFormatContext *s, case ifrm_TAG: case pfrm_TAG: - case cfrm_TAG:{ + case cfrm_TAG: + case ifr2_TAG: + case pfr2_TAG: + case cfr2_TAG: + { /* allocate 8 more bytes than 'size' to account for fourcc * and size */ if (size + 8 < size || av_new_packet(pkt, size + 8)) - return AVERROR_IO; + return AVERROR(EIO); pkt->stream_index = fourxm->video_stream_index; pkt->pts = fourxm->video_pts; - pkt->pos = url_ftell(&s->pb); + pkt->pos = url_ftell(s->pb); memcpy(pkt->data, header, 8); - ret = get_buffer(&s->pb, &pkt->data[8], size); + ret = get_buffer(s->pb, &pkt->data[8], size); if (ret < 0) av_free_packet(pkt); @@ -276,9 +282,9 @@ static int fourxm_read_packet(AVFormatContext *s, size-=8; if (track_number == fourxm->selected_track) { - ret= av_get_packet(&s->pb, pkt, size); + ret= av_get_packet(s->pb, pkt, size); if(ret<0) - return AVERROR_IO; + return AVERROR(EIO); pkt->stream_index = fourxm->tracks[fourxm->selected_track].stream_index; pkt->pts = fourxm->audio_pts; @@ -313,7 +319,7 @@ static int fourxm_read_packet(AVFormatContext *s, static int fourxm_read_close(AVFormatContext *s) { - FourxmDemuxContext *fourxm = (FourxmDemuxContext *)s->priv_data; + FourxmDemuxContext *fourxm = s->priv_data; av_free(fourxm->tracks); diff --git a/contrib/ffmpeg/libavformat/Makefile b/contrib/ffmpeg/libavformat/Makefile index f1339bd9d..041f224a7 100644 --- a/contrib/ffmpeg/libavformat/Makefile +++ b/contrib/ffmpeg/libavformat/Makefile @@ -4,135 +4,175 @@ # include ../config.mak -CFLAGS+=-I$(SRC_PATH)/libavcodec +CFLAGS += -I$(SRC_PATH)/libavcodec -OBJS= utils.o cutils.o os_support.o allformats.o +OBJS = allformats.o cutils.o os_support.o sdp.o utils.o -HEADERS = avformat.h avio.h rtp.h rtsp.h rtspcodes.h +HEADERS = avformat.h avio.h rtsp.h rtspcodes.h # muxers/demuxers -OBJS-$(CONFIG_FOURXM_DEMUXER) += 4xm.o +OBJS-$(CONFIG_AAC_DEMUXER) += raw.o +OBJS-$(CONFIG_AC3_DEMUXER) += raw.o +OBJS-$(CONFIG_AC3_MUXER) += raw.o OBJS-$(CONFIG_ADTS_MUXER) += adtsenc.o -OBJS-$(CONFIG_AIFF_DEMUXER) += aiff.o riff.o +OBJS-$(CONFIG_AIFF_DEMUXER) += aiff.o riff.o raw.o OBJS-$(CONFIG_AIFF_MUXER) += aiff.o riff.o OBJS-$(CONFIG_AMR_DEMUXER) += amr.o OBJS-$(CONFIG_AMR_MUXER) += amr.o -OBJS-$(CONFIG_ASF_DEMUXER) += asf.o riff.o +OBJS-$(CONFIG_APC_DEMUXER) += apc.o +OBJS-$(CONFIG_APE_DEMUXER) += ape.o +OBJS-$(CONFIG_ASF_DEMUXER) += asf.o asfcrypt.o riff.o OBJS-$(CONFIG_ASF_MUXER) += asf-enc.o riff.o OBJS-$(CONFIG_ASF_STREAM_MUXER) += asf-enc.o riff.o -OBJS-$(CONFIG_AU_DEMUXER) += au.o riff.o -OBJS-$(CONFIG_AU_MUXER) += au.o riff.o +OBJS-$(CONFIG_AU_DEMUXER) += au.o raw.o +OBJS-$(CONFIG_AU_MUXER) += au.o OBJS-$(CONFIG_AVI_DEMUXER) += avidec.o riff.o OBJS-$(CONFIG_AVI_MUXER) += avienc.o riff.o OBJS-$(CONFIG_AVISYNTH) += avisynth.o -OBJS-$(CONFIG_AVS_DEMUXER) += avs.o vocdec.o voc.o riff.o -OBJS-$(CONFIG_CRC_MUXER) += crc.o -OBJS-$(CONFIG_FRAMECRC_MUXER) += crc.o +OBJS-$(CONFIG_AVM2_MUXER) += swf.o +OBJS-$(CONFIG_AVS_DEMUXER) += avs.o vocdec.o voc.o +OBJS-$(CONFIG_BETHSOFTVID_DEMUXER) += bethsoftvid.o +OBJS-$(CONFIG_C93_DEMUXER) += c93.o vocdec.o voc.o +OBJS-$(CONFIG_CRC_MUXER) += crcenc.o OBJS-$(CONFIG_DAUD_DEMUXER) += daud.o -OBJS-$(CONFIG_DC1394_DEMUXER) += dc1394.o OBJS-$(CONFIG_DSICIN_DEMUXER) += dsicin.o +OBJS-$(CONFIG_DTS_DEMUXER) += raw.o OBJS-$(CONFIG_DV_DEMUXER) += dv.o OBJS-$(CONFIG_DV_MUXER) += dvenc.o -OBJS-$(CONFIG_DV1394_DEMUXER) += dv1394.o -OBJS-$(CONFIG_DXA_DEMUXER) += dxa.o +OBJS-$(CONFIG_DXA_DEMUXER) += dxa.o riff.o +OBJS-$(CONFIG_EA_CDATA_DEMUXER) += eacdata.o OBJS-$(CONFIG_EA_DEMUXER) += electronicarts.o OBJS-$(CONFIG_FFM_DEMUXER) += ffm.o OBJS-$(CONFIG_FFM_MUXER) += ffm.o +OBJS-$(CONFIG_FLAC_DEMUXER) += raw.o +OBJS-$(CONFIG_FLAC_MUXER) += raw.o OBJS-$(CONFIG_FLIC_DEMUXER) += flic.o OBJS-$(CONFIG_FLV_DEMUXER) += flvdec.o OBJS-$(CONFIG_FLV_MUXER) += flvenc.o +OBJS-$(CONFIG_FOURXM_DEMUXER) += 4xm.o +OBJS-$(CONFIG_FRAMECRC_MUXER) += framecrcenc.o OBJS-$(CONFIG_GIF_MUXER) += gif.o OBJS-$(CONFIG_GIF_DEMUXER) += gifdec.o OBJS-$(CONFIG_GXF_DEMUXER) += gxf.o OBJS-$(CONFIG_GXF_MUXER) += gxfenc.o +OBJS-$(CONFIG_H261_DEMUXER) += raw.o +OBJS-$(CONFIG_H261_MUXER) += raw.o +OBJS-$(CONFIG_H263_DEMUXER) += raw.o +OBJS-$(CONFIG_H263_MUXER) += raw.o +OBJS-$(CONFIG_H264_DEMUXER) += raw.o +OBJS-$(CONFIG_H264_MUXER) += raw.o OBJS-$(CONFIG_IDCIN_DEMUXER) += idcin.o -OBJS-$(CONFIG_ROQ_DEMUXER) += idroq.o OBJS-$(CONFIG_IMAGE2_DEMUXER) += img2.o -OBJS-$(CONFIG_IMAGE2PIPE_DEMUXER) += img2.o OBJS-$(CONFIG_IMAGE2_MUXER) += img2.o +OBJS-$(CONFIG_IMAGE2PIPE_DEMUXER) += img2.o OBJS-$(CONFIG_IMAGE2PIPE_MUXER) += img2.o +OBJS-$(CONFIG_INGENIENT_DEMUXER) += raw.o OBJS-$(CONFIG_IPMOVIE_DEMUXER) += ipmovie.o -OBJS-$(CONFIG_MATROSKA_DEMUXER) += matroska.o riff.o +OBJS-$(CONFIG_LMLM4_DEMUXER) += lmlm4.o +OBJS-$(CONFIG_M4V_DEMUXER) += raw.o +OBJS-$(CONFIG_M4V_MUXER) += raw.o +OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER) += matroskaenc.o matroska.o riff.o avc.o +OBJS-$(CONFIG_MATROSKA_DEMUXER) += matroskadec.o matroska.o riff.o +OBJS-$(CONFIG_MATROSKA_MUXER) += matroskaenc.o matroska.o riff.o avc.o +OBJS-$(CONFIG_MJPEG_DEMUXER) += raw.o +OBJS-$(CONFIG_MJPEG_MUXER) += raw.o OBJS-$(CONFIG_MM_DEMUXER) += mm.o -OBJS-$(CONFIG_MMF_DEMUXER) += mmf.o riff.o +OBJS-$(CONFIG_MMF_DEMUXER) += mmf.o raw.o OBJS-$(CONFIG_MMF_MUXER) += mmf.o riff.o OBJS-$(CONFIG_MOV_DEMUXER) += mov.o riff.o isom.o -OBJS-$(CONFIG_MOV_MUXER) += movenc.o riff.o isom.o -OBJS-$(CONFIG_TGP_MUXER) += movenc.o riff.o isom.o -OBJS-$(CONFIG_MP4_MUXER) += movenc.o riff.o isom.o -OBJS-$(CONFIG_PSP_MUXER) += movenc.o riff.o isom.o -OBJS-$(CONFIG_TG2_MUXER) += movenc.o riff.o isom.o -OBJS-$(CONFIG_MP3_DEMUXER) += mp3.o +OBJS-$(CONFIG_MOV_MUXER) += movenc.o riff.o isom.o avc.o OBJS-$(CONFIG_MP2_MUXER) += mp3.o +OBJS-$(CONFIG_MP3_DEMUXER) += mp3.o OBJS-$(CONFIG_MP3_MUXER) += mp3.o +OBJS-$(CONFIG_MP4_MUXER) += movenc.o riff.o isom.o avc.o OBJS-$(CONFIG_MPC_DEMUXER) += mpc.o -OBJS-$(CONFIG_MPEG1SYSTEM_MUXER) += mpeg.o -OBJS-$(CONFIG_MPEG1VCD_MUXER) += mpeg.o -OBJS-$(CONFIG_MPEG2VOB_MUXER) += mpeg.o -OBJS-$(CONFIG_MPEG2SVCD_MUXER) += mpeg.o -OBJS-$(CONFIG_MPEG2DVD_MUXER) += mpeg.o +OBJS-$(CONFIG_MPC8_DEMUXER) += mpc8.o +OBJS-$(CONFIG_MPEG1SYSTEM_MUXER) += mpegenc.o +OBJS-$(CONFIG_MPEG1VCD_MUXER) += mpegenc.o +OBJS-$(CONFIG_MPEG2DVD_MUXER) += mpegenc.o +OBJS-$(CONFIG_MPEG2VOB_MUXER) += mpegenc.o +OBJS-$(CONFIG_MPEG2SVCD_MUXER) += mpegenc.o +OBJS-$(CONFIG_MPEG1VIDEO_MUXER) += raw.o +OBJS-$(CONFIG_MPEG2VIDEO_MUXER) += raw.o OBJS-$(CONFIG_MPEGPS_DEMUXER) += mpeg.o OBJS-$(CONFIG_MPEGTS_DEMUXER) += mpegts.o +OBJS-$(CONFIG_MPEGTSRAW_DEMUXER) += mpegts.o OBJS-$(CONFIG_MPEGTS_MUXER) += mpegtsenc.o +OBJS-$(CONFIG_MPEGVIDEO_DEMUXER) += raw.o OBJS-$(CONFIG_MPJPEG_MUXER) += mpjpeg.o OBJS-$(CONFIG_MTV_DEMUXER) += mtv.o OBJS-$(CONFIG_MXF_DEMUXER) += mxf.o -OBJS-$(CONFIG_NSV_DEMUXER) += nsvdec.o riff.o +OBJS-$(CONFIG_NSV_DEMUXER) += nsvdec.o +OBJS-$(CONFIG_NULL_MUXER) += raw.o +OBJS-$(CONFIG_NUT_DEMUXER) += nutdec.o nut.o riff.o +OBJS-$(CONFIG_NUT_MUXER) += nutenc.o nut.o riff.o OBJS-$(CONFIG_NUV_DEMUXER) += nuv.o riff.o -OBJS-$(CONFIG_OGG_DEMUXER) += ogg2.o \ - oggparsevorbis.o \ - oggparsetheora.o \ +OBJS-$(CONFIG_OGG_DEMUXER) += oggdec.o \ oggparseflac.o \ oggparseogm.o \ + oggparsespeex.o \ + oggparsetheora.o \ + oggparsevorbis.o \ riff.o -OBJS-$(CONFIG_OGG_MUXER) += ogg.o -OBJS-$(CONFIG_STR_DEMUXER) += psxstr.o -OBJS-$(CONFIG_SHORTEN_DEMUXER) += raw.o -OBJS-$(CONFIG_FLAC_DEMUXER) += raw.o -OBJS-$(CONFIG_FLAC_MUXER) += raw.o -OBJS-$(CONFIG_AC3_DEMUXER) += raw.o -OBJS-$(CONFIG_AC3_MUXER) += raw.o -OBJS-$(CONFIG_DTS_DEMUXER) += raw.o -OBJS-$(CONFIG_AAC_DEMUXER) += raw.o -OBJS-$(CONFIG_H261_DEMUXER) += raw.o -OBJS-$(CONFIG_H261_MUXER) += raw.o -OBJS-$(CONFIG_H263_DEMUXER) += raw.o -OBJS-$(CONFIG_H263_MUXER) += raw.o -OBJS-$(CONFIG_M4V_DEMUXER) += raw.o -OBJS-$(CONFIG_M4V_MUXER) += raw.o -OBJS-$(CONFIG_H264_DEMUXER) += raw.o -OBJS-$(CONFIG_H264_MUXER) += raw.o -OBJS-$(CONFIG_MPEGVIDEO_DEMUXER) += raw.o -OBJS-$(CONFIG_MPEG1VIDEO_MUXER) += raw.o -OBJS-$(CONFIG_MPEG2VIDEO_MUXER) += raw.o -OBJS-$(CONFIG_MJPEG_DEMUXER) += raw.o -OBJS-$(CONFIG_INGENIENT_DEMUXER) += raw.o -OBJS-$(CONFIG_MJPEG_MUXER) += raw.o +OBJS-$(CONFIG_OGG_MUXER) += oggenc.o +OBJS-$(CONFIG_PCM_ALAW_DEMUXER) += raw.o +OBJS-$(CONFIG_PCM_ALAW_MUXER) += raw.o +OBJS-$(CONFIG_PCM_MULAW_DEMUXER) += raw.o +OBJS-$(CONFIG_PCM_MULAW_MUXER) += raw.o +OBJS-$(CONFIG_PCM_S16BE_DEMUXER) += raw.o +OBJS-$(CONFIG_PCM_S16BE_MUXER) += raw.o +OBJS-$(CONFIG_PCM_S16LE_DEMUXER) += raw.o +OBJS-$(CONFIG_PCM_S16LE_MUXER) += raw.o +OBJS-$(CONFIG_PCM_S8_DEMUXER) += raw.o +OBJS-$(CONFIG_PCM_S8_MUXER) += raw.o +OBJS-$(CONFIG_PCM_U16BE_DEMUXER) += raw.o +OBJS-$(CONFIG_PCM_U16BE_MUXER) += raw.o +OBJS-$(CONFIG_PCM_U16LE_DEMUXER) += raw.o +OBJS-$(CONFIG_PCM_U16LE_MUXER) += raw.o +OBJS-$(CONFIG_PCM_U8_DEMUXER) += raw.o +OBJS-$(CONFIG_PCM_U8_MUXER) += raw.o +OBJS-$(CONFIG_PSP_MUXER) += movenc.o riff.o isom.o avc.o +OBJS-$(CONFIG_PVA_DEMUXER) += pva.o OBJS-$(CONFIG_RAWVIDEO_DEMUXER) += raw.o OBJS-$(CONFIG_RAWVIDEO_MUXER) += raw.o -OBJS-$(CONFIG_NULL_MUXER) += raw.o -OBJS-$(CONFIG_NUT_DEMUXER) += nutdec.o riff.o -OBJS-$(CONFIG_RM_DEMUXER) += rm.o -OBJS-$(CONFIG_RM_MUXER) += rm.o +OBJS-$(CONFIG_REDIR_DEMUXER) += rtsp.o +OBJS-$(CONFIG_RM_DEMUXER) += rmdec.o +OBJS-$(CONFIG_RM_MUXER) += rmenc.o +OBJS-$(CONFIG_ROQ_DEMUXER) += idroq.o +OBJS-$(CONFIG_ROQ_MUXER) += raw.o +OBJS-$(CONFIG_RTP_MUXER) += rtp.o \ + rtpenc.o \ + rtp_mpv.o \ + rtp_aac.o \ + rtpenc_h264.o \ + avc.o +OBJS-$(CONFIG_RTSP_DEMUXER) += rtsp.o +OBJS-$(CONFIG_SDP_DEMUXER) += rtsp.o rtp.o rtpdec.o rtp_h264.o OBJS-$(CONFIG_SEGAFILM_DEMUXER) += segafilm.o -OBJS-$(CONFIG_VMD_DEMUXER) += sierravmd.o +OBJS-$(CONFIG_SHORTEN_DEMUXER) += raw.o +OBJS-$(CONFIG_SIFF_DEMUXER) += siff.o OBJS-$(CONFIG_SMACKER_DEMUXER) += smacker.o -OBJS-$(CONFIG_SOL_DEMUXER) += sol.o +OBJS-$(CONFIG_SOL_DEMUXER) += sol.o raw.o +OBJS-$(CONFIG_STR_DEMUXER) += psxstr.o OBJS-$(CONFIG_SWF_DEMUXER) += swf.o OBJS-$(CONFIG_SWF_MUXER) += swf.o +OBJS-$(CONFIG_TG2_MUXER) += movenc.o riff.o isom.o avc.o +OBJS-$(CONFIG_TGP_MUXER) += movenc.o riff.o isom.o avc.o OBJS-$(CONFIG_THP_DEMUXER) += thp.o OBJS-$(CONFIG_TIERTEXSEQ_DEMUXER) += tiertexseq.o OBJS-$(CONFIG_TTA_DEMUXER) += tta.o -OBJS-$(CONFIG_V4L2_DEMUXER) += v4l2.o -OBJS-$(CONFIG_VOC_DEMUXER) += vocdec.o voc.o riff.o -OBJS-$(CONFIG_VOC_MUXER) += vocenc.o voc.o riff.o -OBJS-$(CONFIG_WAV_DEMUXER) += wav.o riff.o +OBJS-$(CONFIG_TXD_DEMUXER) += txd.o +OBJS-$(CONFIG_VC1_DEMUXER) += raw.o +OBJS-$(CONFIG_VC1T_DEMUXER) += vc1test.o +OBJS-$(CONFIG_VMD_DEMUXER) += sierravmd.o +OBJS-$(CONFIG_VOC_DEMUXER) += vocdec.o voc.o +OBJS-$(CONFIG_VOC_MUXER) += vocenc.o voc.o +OBJS-$(CONFIG_WAV_DEMUXER) += wav.o riff.o raw.o OBJS-$(CONFIG_WAV_MUXER) += wav.o riff.o OBJS-$(CONFIG_WC3_DEMUXER) += wc3movie.o OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood.o OBJS-$(CONFIG_WSVQA_DEMUXER) += westwood.o OBJS-$(CONFIG_WV_DEMUXER) += wv.o -OBJS-$(CONFIG_X11_GRAB_DEVICE_DEMUXER) += x11grab.o OBJS-$(CONFIG_YUV4MPEGPIPE_MUXER) += yuv4mpeg.o OBJS-$(CONFIG_YUV4MPEGPIPE_DEMUXER) += yuv4mpeg.o @@ -140,37 +180,20 @@ OBJS-$(CONFIG_YUV4MPEGPIPE_DEMUXER) += yuv4mpeg.o OBJS-$(CONFIG_LIBNUT_DEMUXER) += libnut.o riff.o OBJS-$(CONFIG_LIBNUT_MUXER) += libnut.o riff.o -OBJS+= framehook.o - -ifeq ($(CONFIG_V4L),yes) -OBJS-$(CONFIG_VIDEO_GRAB_DEVICE_DEMUXER) += grab.o -endif - -ifeq ($(CONFIG_BKTR),yes) -OBJS-$(CONFIG_VIDEO_GRAB_DEVICE_DEMUXER) += grab_bktr.o -endif - -ifeq ($(CONFIG_AUDIO_OSS),yes) -OBJS-$(CONFIG_AUDIO_DEMUXER) += audio.o -OBJS-$(CONFIG_AUDIO_MUXER) += audio.o -endif - -EXTRALIBS := -L$(BUILD_ROOT)/libavutil -lavutil$(BUILDSUF) \ - -lavcodec$(BUILDSUF) -L$(BUILD_ROOT)/libavcodec $(EXTRALIBS) +OBJS-$(CONFIG_VHOOK) += framehook.o -ifeq ($(CONFIG_AUDIO_BEOS),yes) -CPPOBJS+= beosaudio.o -endif +EXTRALIBS := -L$(BUILD_ROOT)/libavcodec -lavcodec$(BUILDSUF) \ + -L$(BUILD_ROOT)/libavutil -lavutil$(BUILDSUF) $(EXTRALIBS) # protocols I/O OBJS+= avio.o aviobuf.o -ifeq ($(CONFIG_PROTOCOLS),yes) -OBJS+= file.o -ifeq ($(CONFIG_NETWORK),yes) -OBJS+= udp.o tcp.o http.o rtsp.o rtp.o rtpproto.o mpegts.o rtp_h264.o -endif -endif +OBJS-$(CONFIG_FILE_PROTOCOL) += file.o +OBJS-$(CONFIG_HTTP_PROTOCOL) += http.o +OBJS-$(CONFIG_PIPE_PROTOCOL) += file.o +OBJS-$(CONFIG_RTP_PROTOCOL) += rtpproto.o +OBJS-$(CONFIG_TCP_PROTOCOL) += tcp.o +OBJS-$(CONFIG_UDP_PROTOCOL) += udp.o NAME=avformat LIBVERSION=$(LAVFVERSION) diff --git a/contrib/ffmpeg/libavformat/adtsenc.c b/contrib/ffmpeg/libavformat/adtsenc.c index 1ef683838..1949fcf54 100644 --- a/contrib/ffmpeg/libavformat/adtsenc.c +++ b/contrib/ffmpeg/libavformat/adtsenc.c @@ -1,7 +1,7 @@ /* * ADTS muxer. * Copyright (c) 2006 Baptiste Coudurier - * Mans Rullgard + * Mans Rullgard * * This file is part of FFmpeg. * @@ -84,20 +84,15 @@ static int adts_write_frame_header(AVFormatContext *s, int size) put_bits(&pb, 2, 0); /* number_of_raw_data_blocks_in_frame */ flush_put_bits(&pb); - put_buffer(&s->pb, buf, ADTS_HEADER_SIZE); + put_buffer(s->pb, buf, ADTS_HEADER_SIZE); return 0; } -static int adts_write_trailer(AVFormatContext *s) -{ - return 0; -} - static int adts_write_packet(AVFormatContext *s, AVPacket *pkt) { ADTSContext *adts = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; if (!pkt->size) return 0; @@ -119,5 +114,4 @@ AVOutputFormat adts_muxer = { CODEC_ID_NONE, adts_write_header, adts_write_packet, - adts_write_trailer, }; diff --git a/contrib/ffmpeg/libavformat/aiff.c b/contrib/ffmpeg/libavformat/aiff.c index 868d55219..91be89b30 100644 --- a/contrib/ffmpeg/libavformat/aiff.c +++ b/contrib/ffmpeg/libavformat/aiff.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avformat.h" -#include "allformats.h" +#include "raw.h" #include "riff.h" #include "intfloat_readwrite.h" @@ -29,13 +29,14 @@ static const AVCodecTag codec_aiff_tags[] = { { CODEC_ID_PCM_S24BE, MKTAG('N','O','N','E') }, { CODEC_ID_PCM_S32BE, MKTAG('N','O','N','E') }, { CODEC_ID_PCM_ALAW, MKTAG('a','l','a','w') }, - { CODEC_ID_PCM_ALAW, MKTAG('A','L','A','W') }, { CODEC_ID_PCM_MULAW, MKTAG('u','l','a','w') }, - { CODEC_ID_PCM_MULAW, MKTAG('U','L','A','W') }, { CODEC_ID_MACE3, MKTAG('M','A','C','3') }, { CODEC_ID_MACE6, MKTAG('M','A','C','6') }, { CODEC_ID_GSM, MKTAG('G','S','M',' ') }, { CODEC_ID_ADPCM_G726, MKTAG('G','7','2','6') }, + { CODEC_ID_PCM_S16LE, MKTAG('s','o','w','t') }, + { CODEC_ID_ADPCM_IMA_QT, MKTAG('i','m','a','4') }, + { CODEC_ID_QDM2, MKTAG('Q','D','M','2') }, { 0, 0 }, }; @@ -63,7 +64,7 @@ static int get_tag(ByteIOContext *pb, uint32_t * tag) int size; if (url_feof(pb)) - return AVERROR_IO; + return AVERROR(EIO); *tag = get_le32(pb); size = get_be32(pb); @@ -103,10 +104,8 @@ static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec, double sample_rate; unsigned int num_frames; - if (size & 1) size++; - codec->codec_type = CODEC_TYPE_AUDIO; codec->channels = get_be16(pb); num_frames = get_be32(pb); @@ -120,17 +119,28 @@ static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec, /* Got an AIFF-C? */ if (version == AIFF_C_VERSION1) { codec->codec_tag = get_le32(pb); - codec->codec_id = codec_get_id (codec_aiff_tags, codec->codec_tag); + codec->codec_id = codec_get_id(codec_aiff_tags, codec->codec_tag); - if (codec->codec_id == CODEC_ID_PCM_S16BE) { - codec->codec_id = aiff_codec_get_id (codec->bits_per_sample); + switch (codec->codec_id) { + case CODEC_ID_PCM_S16BE: + codec->codec_id = aiff_codec_get_id(codec->bits_per_sample); codec->bits_per_sample = av_get_bits_per_sample(codec->codec_id); + break; + case CODEC_ID_ADPCM_IMA_QT: + codec->block_align = 34*codec->channels; + codec->frame_size = 64; + break; + case CODEC_ID_MACE3: + case CODEC_ID_MACE6: + codec->frame_size = 6; + break; + default: + break; } - size -= 4; } else { /* Need the codec type */ - codec->codec_id = aiff_codec_get_id (codec->bits_per_sample); + codec->codec_id = aiff_codec_get_id(codec->bits_per_sample); codec->bits_per_sample = av_get_bits_per_sample(codec->codec_id); } @@ -139,7 +149,8 @@ static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec, /* Block align needs to be computed in all cases, as the definition * is specific to applications -> here we use the WAVE format definition */ - codec->block_align = (codec->bits_per_sample * codec->channels) >> 3; + if (!codec->block_align) + codec->block_align = (codec->bits_per_sample * codec->channels) >> 3; codec->bit_rate = codec->sample_rate * (codec->block_align << 3); @@ -160,16 +171,14 @@ typedef struct { static int aiff_write_header(AVFormatContext *s) { AIFFOutputContext *aiff = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVCodecContext *enc = s->streams[0]->codec; AVExtFloat sample_rate; int aifc = 0; /* First verify if format is ok */ - if (!enc->codec_tag) { + if (!enc->codec_tag) return -1; - } - if (enc->codec_tag != MKTAG('N','O','N','E')) aifc = 1; @@ -179,7 +188,12 @@ static int aiff_write_header(AVFormatContext *s) put_be32(pb, 0); /* file length */ put_tag(pb, aifc ? "AIFC" : "AIFF"); - if (aifc) { + if (aifc) { // compressed audio + enc->bits_per_sample = 16; + if (!enc->block_align) { + av_log(s, AV_LOG_ERROR, "block align not set\n"); + return -1; + } /* Version chunk */ put_tag(pb, "FVER"); put_be32(pb, 4); @@ -189,10 +203,10 @@ static int aiff_write_header(AVFormatContext *s) /* Common chunk */ put_tag(pb, "COMM"); put_be32(pb, aifc ? 24 : 18); /* size */ - put_be16(pb, enc->channels); /* Number of channels */ + put_be16(pb, enc->channels); /* Number of channels */ aiff->frames = url_ftell(pb); - put_be32(pb, 0); /* Number of frames */ + put_be32(pb, 0); /* Number of frames */ if (!enc->bits_per_sample) enc->bits_per_sample = av_get_bits_per_sample(enc->codec_id); @@ -230,14 +244,14 @@ static int aiff_write_header(AVFormatContext *s) static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; put_buffer(pb, pkt->data, pkt->size); return 0; } static int aiff_write_trailer(AVFormatContext *s) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AIFFOutputContext *aiff = s->priv_data; AVCodecContext *enc = s->streams[0]->codec; @@ -249,18 +263,18 @@ static int aiff_write_trailer(AVFormatContext *s) end_size++; } - if (!url_is_streamed(&s->pb)) { + if (!url_is_streamed(s->pb)) { /* File length */ url_fseek(pb, aiff->form, SEEK_SET); - put_be32(pb, (uint32_t)(file_size - aiff->form - 4)); + put_be32(pb, file_size - aiff->form - 4); /* Number of sample frames */ url_fseek(pb, aiff->frames, SEEK_SET); - put_be32(pb, ((uint32_t)(file_size-aiff->ssnd-12))/enc->block_align); + put_be32(pb, (file_size-aiff->ssnd-12)/enc->block_align); /* Sound Data chunk size */ url_fseek(pb, aiff->ssnd, SEEK_SET); - put_be32(pb, (uint32_t)(file_size - aiff->ssnd - 4)); + put_be32(pb, file_size - aiff->ssnd - 4); /* return to the end */ url_fseek(pb, end_size, SEEK_SET); @@ -275,8 +289,6 @@ static int aiff_write_trailer(AVFormatContext *s) static int aiff_probe(AVProbeData *p) { /* check file header */ - if (p->buf_size < 16) - return 0; if (p->buf[0] == 'F' && p->buf[1] == 'O' && p->buf[2] == 'R' && p->buf[3] == 'M' && p->buf[8] == 'A' && p->buf[9] == 'I' && @@ -290,10 +302,11 @@ static int aiff_probe(AVProbeData *p) static int aiff_read_header(AVFormatContext *s, AVFormatParameters *ap) { - int size, filesize, offset; + int size, filesize; + offset_t offset = 0; uint32_t tag; unsigned version = AIFF_C_VERSION1; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVStream * st = s->streams[0]; /* check FORM header */ @@ -312,7 +325,7 @@ static int aiff_read_header(AVFormatContext *s, st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); while (filesize > 0) { /* parse different chunks */ @@ -323,42 +336,54 @@ static int aiff_read_header(AVFormatContext *s, filesize -= size + 8; switch (tag) { - case MKTAG('C', 'O', 'M', 'M'): /* Common chunk */ - /* Then for the complete header info */ - st->nb_frames = get_aiff_header (pb, st->codec, size, version); - if (st->nb_frames < 0) - return st->nb_frames; - break; - - case MKTAG('F', 'V', 'E', 'R'): /* Version chunk */ - version = get_be32(pb); - break; - - case MKTAG('N', 'A', 'M', 'E'): /* Sample name chunk */ - get_meta (pb, s->title, sizeof(s->title), size); - break; - - case MKTAG('A', 'U', 'T', 'H'): /* Author chunk */ - get_meta (pb, s->author, sizeof(s->author), size); - break; - - case MKTAG('(', 'c', ')', ' '): /* Copyright chunk */ - get_meta (pb, s->copyright, sizeof(s->copyright), size); - break; - - case MKTAG('A', 'N', 'N', 'O'): /* Annotation chunk */ - get_meta (pb, s->comment, sizeof(s->comment), size); - break; - - case MKTAG('S', 'S', 'N', 'D'): /* Sampled sound chunk */ - get_be32(pb); /* Block align... don't care */ - offset = get_be32(pb); /* Offset of sound data */ + case MKTAG('C', 'O', 'M', 'M'): /* Common chunk */ + /* Then for the complete header info */ + st->nb_frames = get_aiff_header (pb, st->codec, size, version); + if (st->nb_frames < 0) + return st->nb_frames; + if (offset > 0) // COMM is after SSND goto got_sound; - - default: /* Jump */ - if (size & 1) /* Always even aligned */ - size++; - url_fskip (pb, size); + break; + case MKTAG('F', 'V', 'E', 'R'): /* Version chunk */ + version = get_be32(pb); + break; + case MKTAG('N', 'A', 'M', 'E'): /* Sample name chunk */ + get_meta (pb, s->title, sizeof(s->title), size); + break; + case MKTAG('A', 'U', 'T', 'H'): /* Author chunk */ + get_meta (pb, s->author, sizeof(s->author), size); + break; + case MKTAG('(', 'c', ')', ' '): /* Copyright chunk */ + get_meta (pb, s->copyright, sizeof(s->copyright), size); + break; + case MKTAG('A', 'N', 'N', 'O'): /* Annotation chunk */ + get_meta (pb, s->comment, sizeof(s->comment), size); + break; + case MKTAG('S', 'S', 'N', 'D'): /* Sampled sound chunk */ + offset = get_be32(pb); /* Offset of sound data */ + get_be32(pb); /* BlockSize... don't care */ + offset += url_ftell(pb); /* Compute absolute data offset */ + if (st->codec->codec_id) /* Assume COMM already parsed */ + goto got_sound; + if (url_is_streamed(pb)) { + av_log(s, AV_LOG_ERROR, "file is not seekable\n"); + return -1; + } + url_fskip(pb, size - 8); + break; + case MKTAG('w', 'a', 'v', 'e'): + if ((uint64_t)size > (1<<30)) + return -1; + st->codec->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!st->codec->extradata) + return AVERROR(ENOMEM); + st->codec->extradata_size = size; + get_buffer(pb, st->codec->extradata, size); + break; + default: /* Jump */ + if (size & 1) /* Always even aligned */ + size++; + url_fskip (pb, size); } } @@ -372,10 +397,11 @@ got_sound: av_set_pts_info(st, 64, 1, st->codec->sample_rate); st->start_time = 0; - st->duration = st->nb_frames; + st->duration = st->codec->frame_size ? + st->nb_frames * st->codec->frame_size : st->nb_frames; /* Position the stream at the first block */ - url_fskip(pb, offset); + url_fseek(pb, offset, SEEK_SET); return 0; } @@ -389,11 +415,11 @@ static int aiff_read_packet(AVFormatContext *s, int res; /* End of stream may be reached */ - if (url_feof(&s->pb)) - return AVERROR_IO; + if (url_feof(s->pb)) + return AVERROR(EIO); /* Now for that packet */ - res = av_get_packet(&s->pb, pkt, (MAX_SIZE / st->codec->block_align) * st->codec->block_align); + res = av_get_packet(s->pb, pkt, (MAX_SIZE / st->codec->block_align) * st->codec->block_align); if (res < 0) return res; @@ -402,11 +428,6 @@ static int aiff_read_packet(AVFormatContext *s, return 0; } -static int aiff_read_close(AVFormatContext *s) -{ - return 0; -} - static int aiff_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { @@ -421,7 +442,7 @@ AVInputFormat aiff_demuxer = { aiff_probe, aiff_read_header, aiff_read_packet, - aiff_read_close, + NULL, aiff_read_seek, .codec_tag= (const AVCodecTag*[]){codec_aiff_tags, 0}, }; diff --git a/contrib/ffmpeg/libavformat/allformats.c b/contrib/ffmpeg/libavformat/allformats.c index 8534a18f6..5cafd6209 100644 --- a/contrib/ffmpeg/libavformat/allformats.c +++ b/contrib/ffmpeg/libavformat/allformats.c @@ -19,13 +19,18 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avformat.h" -#include "allformats.h" +#include "rtp_internal.h" -#define REGISTER_MUXER(X,x) \ - if(ENABLE_##X##_MUXER) av_register_output_format(&x##_muxer) -#define REGISTER_DEMUXER(X,x) \ - if(ENABLE_##X##_DEMUXER) av_register_input_format(&x##_demuxer) +#define REGISTER_MUXER(X,x) { \ + extern AVOutputFormat x##_muxer; \ + if(ENABLE_##X##_MUXER) av_register_output_format(&x##_muxer); } +#define REGISTER_DEMUXER(X,x) { \ + extern AVInputFormat x##_demuxer; \ + if(ENABLE_##X##_DEMUXER) av_register_input_format(&x##_demuxer); } #define REGISTER_MUXDEMUX(X,x) REGISTER_MUXER(X,x); REGISTER_DEMUXER(X,x) +#define REGISTER_PROTOCOL(X,x) { \ + extern URLProtocol x##_protocol; \ + if(ENABLE_##X##_PROTOCOL) register_protocol(&x##_protocol); } /* If you do not call this function, then you can select exactly which formats you want to support */ @@ -35,138 +40,140 @@ */ void av_register_all(void) { - static int inited = 0; + static int initialized; - if (inited != 0) + if (initialized) return; - inited = 1; + initialized = 1; avcodec_init(); avcodec_register_all(); - REGISTER_DEMUXER (AAC, aac); - REGISTER_MUXDEMUX(AC3, ac3); - REGISTER_MUXER (ADTS, adts); - REGISTER_MUXDEMUX(AIFF, aiff); - REGISTER_MUXDEMUX(AMR, amr); - REGISTER_MUXDEMUX(ASF, asf); - REGISTER_MUXER (ASF_STREAM, asf_stream); - REGISTER_MUXDEMUX(AU, au); - REGISTER_MUXDEMUX(AUDIO, audio); - REGISTER_MUXDEMUX(AVI, avi); -#ifdef CONFIG_AVISYNTH - av_register_input_format(&avisynth_demuxer); -#endif - REGISTER_DEMUXER (AVS, avs); - REGISTER_MUXER (CRC, crc); - REGISTER_DEMUXER (DAUD, daud); - REGISTER_DEMUXER (DC1394, dc1394); - REGISTER_DEMUXER (DSICIN, dsicin); - REGISTER_DEMUXER (DTS, dts); - REGISTER_MUXDEMUX(DV, dv); - REGISTER_DEMUXER (DV1394, dv1394); - REGISTER_DEMUXER (DXA, dxa); - REGISTER_DEMUXER (EA, ea); - REGISTER_MUXDEMUX(FFM, ffm); - REGISTER_MUXDEMUX(FLAC, flac); - REGISTER_DEMUXER (FLIC, flic); - REGISTER_MUXDEMUX(FLV, flv); - REGISTER_DEMUXER (FOURXM, fourxm); - REGISTER_MUXER (FRAMECRC, framecrc); - REGISTER_MUXDEMUX(GIF, gif); - REGISTER_DEMUXER (GXF, gxf); - REGISTER_MUXER (GXF, gxf); - REGISTER_MUXDEMUX(H261, h261); - REGISTER_MUXDEMUX(H263, h263); - REGISTER_MUXDEMUX(H264, h264); - REGISTER_DEMUXER (IDCIN, idcin); - REGISTER_MUXDEMUX(IMAGE2, image2); - REGISTER_MUXDEMUX(IMAGE2PIPE, image2pipe); - REGISTER_DEMUXER (INGENIENT, ingenient); - REGISTER_DEMUXER (IPMOVIE, ipmovie); - if (!ENABLE_NUT_DEMUXER) REGISTER_DEMUXER (LIBNUT, libnut); - REGISTER_MUXER (LIBNUT, libnut); - REGISTER_MUXDEMUX(M4V, m4v); - REGISTER_DEMUXER (MATROSKA, matroska); - REGISTER_MUXDEMUX(MJPEG, mjpeg); - REGISTER_DEMUXER (MM, mm); - REGISTER_MUXDEMUX(MMF, mmf); - REGISTER_MUXDEMUX(MOV, mov); - REGISTER_MUXER (MP2, mp2); - REGISTER_MUXDEMUX(MP3, mp3); - REGISTER_MUXER (MP4, mp4); - REGISTER_DEMUXER (MPC, mpc); - REGISTER_MUXER (MPEG1SYSTEM, mpeg1system); - REGISTER_MUXER (MPEG1VCD, mpeg1vcd); - REGISTER_MUXER (MPEG1VIDEO, mpeg1video); - REGISTER_MUXER (MPEG2DVD, mpeg2dvd); - REGISTER_MUXER (MPEG2SVCD, mpeg2svcd); - REGISTER_MUXER (MPEG2VIDEO, mpeg2video); - REGISTER_MUXER (MPEG2VOB, mpeg2vob); - REGISTER_DEMUXER (MPEGPS, mpegps); - REGISTER_MUXDEMUX(MPEGTS, mpegts); - REGISTER_DEMUXER (MPEGVIDEO, mpegvideo); - REGISTER_MUXER (MPJPEG, mpjpeg); - REGISTER_DEMUXER (MTV, mtv); - REGISTER_DEMUXER (MXF, mxf); - REGISTER_DEMUXER (NSV, nsv); - REGISTER_MUXER (NULL, null); - REGISTER_DEMUXER (NUT, nut); - REGISTER_DEMUXER (NUV, nuv); - REGISTER_DEMUXER (OGG, ogg); - REGISTER_MUXER (OGG, ogg); - REGISTER_MUXDEMUX(PCM_ALAW, pcm_alaw); - REGISTER_MUXDEMUX(PCM_MULAW, pcm_mulaw); - REGISTER_MUXDEMUX(PCM_S16BE, pcm_s16be); - REGISTER_MUXDEMUX(PCM_S16LE, pcm_s16le); - REGISTER_MUXDEMUX(PCM_S8, pcm_s8); - REGISTER_MUXDEMUX(PCM_U16BE, pcm_u16be); - REGISTER_MUXDEMUX(PCM_U16LE, pcm_u16le); - REGISTER_MUXDEMUX(PCM_U8, pcm_u8); - REGISTER_MUXER (PSP, psp); - REGISTER_MUXDEMUX(RAWVIDEO, rawvideo); - REGISTER_MUXDEMUX(RM, rm); - REGISTER_DEMUXER (ROQ, roq); - REGISTER_DEMUXER (REDIR, redir); - REGISTER_MUXER (RTP, rtp); - REGISTER_DEMUXER (RTSP, rtsp); - REGISTER_DEMUXER (SDP, sdp); -#ifdef CONFIG_NETWORK + /* (de)muxers */ + REGISTER_DEMUXER (AAC, aac); + REGISTER_MUXDEMUX (AC3, ac3); + REGISTER_MUXER (ADTS, adts); + REGISTER_MUXDEMUX (AIFF, aiff); + REGISTER_MUXDEMUX (AMR, amr); + REGISTER_DEMUXER (APC, apc); + REGISTER_DEMUXER (APE, ape); + REGISTER_MUXDEMUX (ASF, asf); + REGISTER_MUXER (ASF_STREAM, asf_stream); + REGISTER_MUXDEMUX (AU, au); + REGISTER_MUXDEMUX (AVI, avi); + REGISTER_DEMUXER (AVISYNTH, avisynth); + REGISTER_MUXER (AVM2, avm2); + REGISTER_DEMUXER (AVS, avs); + REGISTER_DEMUXER (BETHSOFTVID, bethsoftvid); + REGISTER_DEMUXER (C93, c93); + REGISTER_MUXER (CRC, crc); + REGISTER_DEMUXER (DAUD, daud); + REGISTER_DEMUXER (DSICIN, dsicin); + REGISTER_DEMUXER (DTS, dts); + REGISTER_MUXDEMUX (DV, dv); + REGISTER_DEMUXER (DXA, dxa); + REGISTER_DEMUXER (EA, ea); + REGISTER_DEMUXER (EA_CDATA, ea_cdata); + REGISTER_MUXDEMUX (FFM, ffm); + REGISTER_MUXDEMUX (FLAC, flac); + REGISTER_DEMUXER (FLIC, flic); + REGISTER_MUXDEMUX (FLV, flv); + REGISTER_DEMUXER (FOURXM, fourxm); + REGISTER_MUXER (FRAMECRC, framecrc); + REGISTER_MUXDEMUX (GIF, gif); + REGISTER_MUXDEMUX (GXF, gxf); + REGISTER_MUXDEMUX (H261, h261); + REGISTER_MUXDEMUX (H263, h263); + REGISTER_MUXDEMUX (H264, h264); + REGISTER_DEMUXER (IDCIN, idcin); + REGISTER_MUXDEMUX (IMAGE2, image2); + REGISTER_MUXDEMUX (IMAGE2PIPE, image2pipe); + REGISTER_DEMUXER (INGENIENT, ingenient); + REGISTER_DEMUXER (IPMOVIE, ipmovie); + REGISTER_DEMUXER (LMLM4, lmlm4); + REGISTER_MUXDEMUX (M4V, m4v); + REGISTER_MUXDEMUX (MATROSKA, matroska); + REGISTER_MUXER (MATROSKA_AUDIO, matroska_audio); + REGISTER_MUXDEMUX (MJPEG, mjpeg); + REGISTER_DEMUXER (MM, mm); + REGISTER_MUXDEMUX (MMF, mmf); + REGISTER_MUXDEMUX (MOV, mov); + REGISTER_MUXER (MP2, mp2); + REGISTER_MUXDEMUX (MP3, mp3); + REGISTER_MUXER (MP4, mp4); + REGISTER_DEMUXER (MPC, mpc); + REGISTER_DEMUXER (MPC8, mpc8); + REGISTER_MUXER (MPEG1SYSTEM, mpeg1system); + REGISTER_MUXER (MPEG1VCD, mpeg1vcd); + REGISTER_MUXER (MPEG1VIDEO, mpeg1video); + REGISTER_MUXER (MPEG2DVD, mpeg2dvd); + REGISTER_MUXER (MPEG2SVCD, mpeg2svcd); + REGISTER_MUXER (MPEG2VIDEO, mpeg2video); + REGISTER_MUXER (MPEG2VOB, mpeg2vob); + REGISTER_DEMUXER (MPEGPS, mpegps); + REGISTER_MUXDEMUX (MPEGTS, mpegts); + REGISTER_DEMUXER (MPEGTSRAW, mpegtsraw); + REGISTER_DEMUXER (MPEGVIDEO, mpegvideo); + REGISTER_MUXER (MPJPEG, mpjpeg); + REGISTER_DEMUXER (MTV, mtv); + REGISTER_DEMUXER (MXF, mxf); + REGISTER_DEMUXER (NSV, nsv); + REGISTER_MUXER (NULL, null); + REGISTER_MUXDEMUX (NUT, nut); + REGISTER_DEMUXER (NUV, nuv); + REGISTER_MUXDEMUX (OGG, ogg); + REGISTER_MUXDEMUX (PCM_ALAW, pcm_alaw); + REGISTER_MUXDEMUX (PCM_MULAW, pcm_mulaw); + REGISTER_MUXDEMUX (PCM_S16BE, pcm_s16be); + REGISTER_MUXDEMUX (PCM_S16LE, pcm_s16le); + REGISTER_MUXDEMUX (PCM_S8, pcm_s8); + REGISTER_MUXDEMUX (PCM_U16BE, pcm_u16be); + REGISTER_MUXDEMUX (PCM_U16LE, pcm_u16le); + REGISTER_MUXDEMUX (PCM_U8, pcm_u8); + REGISTER_MUXER (PSP, psp); + REGISTER_DEMUXER (PVA, pva); + REGISTER_MUXDEMUX (RAWVIDEO, rawvideo); + REGISTER_MUXDEMUX (RM, rm); + REGISTER_MUXDEMUX (ROQ, roq); + REGISTER_DEMUXER (REDIR, redir); + REGISTER_MUXER (RTP, rtp); + REGISTER_DEMUXER (RTSP, rtsp); + REGISTER_DEMUXER (SDP, sdp); +#ifdef CONFIG_SDP_DEMUXER av_register_rtp_dynamic_payload_handlers(); #endif - REGISTER_DEMUXER (SEGAFILM, segafilm); - REGISTER_DEMUXER (SHORTEN, shorten); - REGISTER_DEMUXER (SMACKER, smacker); - REGISTER_DEMUXER (SOL, sol); - REGISTER_DEMUXER (STR, str); - REGISTER_MUXDEMUX(SWF, swf); - REGISTER_MUXER (TG2, tg2); - REGISTER_MUXER (TGP, tgp); - REGISTER_DEMUXER (THP, thp); - REGISTER_DEMUXER (TIERTEXSEQ, tiertexseq); - REGISTER_DEMUXER (TTA, tta); - REGISTER_DEMUXER (V4L2, v4l2); - REGISTER_DEMUXER (VC1, vc1); - REGISTER_DEMUXER (VIDEO_GRAB_DEVICE, video_grab_device); - REGISTER_DEMUXER (VMD, vmd); - REGISTER_MUXDEMUX(VOC, voc); - REGISTER_MUXDEMUX(WAV, wav); - REGISTER_DEMUXER (WC3, wc3); - REGISTER_DEMUXER (WSAUD, wsaud); - REGISTER_DEMUXER (WSVQA, wsvqa); - REGISTER_DEMUXER (WV, wv); - REGISTER_DEMUXER (X11_GRAB_DEVICE, x11_grab_device); - REGISTER_MUXDEMUX(YUV4MPEGPIPE, yuv4mpegpipe); + REGISTER_DEMUXER (SEGAFILM, segafilm); + REGISTER_DEMUXER (SHORTEN, shorten); + REGISTER_DEMUXER (SIFF, siff); + REGISTER_DEMUXER (SMACKER, smacker); + REGISTER_DEMUXER (SOL, sol); + REGISTER_DEMUXER (STR, str); + REGISTER_MUXDEMUX (SWF, swf); + REGISTER_MUXER (TG2, tg2); + REGISTER_MUXER (TGP, tgp); + REGISTER_DEMUXER (THP, thp); + REGISTER_DEMUXER (TIERTEXSEQ, tiertexseq); + REGISTER_DEMUXER (TTA, tta); + REGISTER_DEMUXER (TXD, txd); + REGISTER_DEMUXER (VC1, vc1); + REGISTER_DEMUXER (VC1T, vc1t); + REGISTER_DEMUXER (VMD, vmd); + REGISTER_MUXDEMUX (VOC, voc); + REGISTER_MUXDEMUX (WAV, wav); + REGISTER_DEMUXER (WC3, wc3); + REGISTER_DEMUXER (WSAUD, wsaud); + REGISTER_DEMUXER (WSVQA, wsvqa); + REGISTER_DEMUXER (WV, wv); + REGISTER_MUXDEMUX (YUV4MPEGPIPE, yuv4mpegpipe); -#ifdef CONFIG_PROTOCOLS - /* file protocols */ - register_protocol(&file_protocol); - register_protocol(&pipe_protocol); -#ifdef CONFIG_NETWORK - register_protocol(&udp_protocol); - register_protocol(&rtp_protocol); - register_protocol(&tcp_protocol); - register_protocol(&http_protocol); -#endif -#endif + /* external libraries */ + REGISTER_MUXDEMUX (LIBNUT, libnut); + + /* protocols */ + REGISTER_PROTOCOL (FILE, file); + REGISTER_PROTOCOL (HTTP, http); + REGISTER_PROTOCOL (PIPE, pipe); + REGISTER_PROTOCOL (RTP, rtp); + REGISTER_PROTOCOL (TCP, tcp); + REGISTER_PROTOCOL (UDP, udp); } diff --git a/contrib/ffmpeg/libavformat/allformats.h b/contrib/ffmpeg/libavformat/allformats.h deleted file mode 100644 index 9734940d3..000000000 --- a/contrib/ffmpeg/libavformat/allformats.h +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Register all the formats and protocols. - * copyright (c) 2000, 2001, 2002 Fabrice Bellard - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef ALLFORMATS_H -#define ALLFORMATS_H - -extern AVInputFormat fourxm_demuxer; -extern AVOutputFormat adts_muxer; -extern AVInputFormat aiff_demuxer; -extern AVOutputFormat aiff_muxer; -extern AVInputFormat amr_demuxer; -extern AVOutputFormat amr_muxer; -extern AVInputFormat asf_demuxer; -extern AVOutputFormat asf_muxer; -extern AVOutputFormat asf_stream_muxer; -extern AVInputFormat au_demuxer; -extern AVOutputFormat au_muxer; -extern AVInputFormat audio_demuxer; -extern AVOutputFormat audio_muxer; -extern AVInputFormat avi_demuxer; -extern AVOutputFormat avi_muxer; -extern AVInputFormat avisynth_demuxer; -extern AVInputFormat avs_demuxer; -extern AVOutputFormat crc_muxer; -extern AVOutputFormat framecrc_muxer; -extern AVInputFormat daud_demuxer; -extern AVInputFormat dc1394_demuxer; -extern AVInputFormat dsicin_demuxer; -extern AVInputFormat dv1394_demuxer; -extern AVInputFormat dv_demuxer; -extern AVOutputFormat dv_muxer; -extern AVInputFormat dxa_demuxer; -extern AVInputFormat ea_demuxer; -extern AVInputFormat ffm_demuxer; -extern AVOutputFormat ffm_muxer; -extern AVInputFormat flic_demuxer; -extern AVInputFormat flv_demuxer; -extern AVOutputFormat flv_muxer; -extern AVOutputFormat gif_muxer; -extern AVInputFormat gif_demuxer; -extern AVInputFormat video_grab_device_demuxer; -extern AVInputFormat gxf_demuxer; -extern AVOutputFormat gxf_muxer; -extern AVInputFormat idcin_demuxer; -extern AVInputFormat roq_demuxer; -extern AVInputFormat image2_demuxer; -extern AVInputFormat image2pipe_demuxer; -extern AVOutputFormat image2_muxer; -extern AVOutputFormat image2pipe_muxer; -extern AVInputFormat image_demuxer; -extern AVInputFormat imagepipe_demuxer; -extern AVOutputFormat image_muxer; -extern AVOutputFormat imagepipe_muxer; -extern AVInputFormat ipmovie_demuxer; -extern AVInputFormat libnut_demuxer; -extern AVOutputFormat libnut_muxer; -extern AVInputFormat matroska_demuxer; -extern AVInputFormat mm_demuxer; -extern AVInputFormat mmf_demuxer; -extern AVOutputFormat mmf_muxer; -extern AVInputFormat mov_demuxer; -extern AVOutputFormat mov_muxer; -extern AVOutputFormat tgp_muxer; -extern AVOutputFormat mp4_muxer; -extern AVOutputFormat psp_muxer; -extern AVOutputFormat tg2_muxer; -extern AVInputFormat mp3_demuxer; -extern AVOutputFormat mp2_muxer; -extern AVOutputFormat mp3_muxer; -extern AVInputFormat mpc_demuxer; -extern AVOutputFormat mpeg1system_muxer; -extern AVOutputFormat mpeg1vcd_muxer; -extern AVOutputFormat mpeg2vob_muxer; -extern AVOutputFormat mpeg2svcd_muxer; -extern AVOutputFormat mpeg2dvd_muxer; -extern AVInputFormat mpegps_demuxer; -extern AVInputFormat mpegts_demuxer; -extern AVOutputFormat mpegts_muxer; -extern AVOutputFormat mpjpeg_muxer; -extern AVInputFormat mtv_demuxer; -extern AVInputFormat mxf_demuxer; -extern AVInputFormat nsv_demuxer; -extern AVInputFormat nut_demuxer; -extern AVInputFormat nuv_demuxer; -extern AVInputFormat ogg_demuxer; -extern AVOutputFormat ogg_muxer; -extern AVInputFormat str_demuxer; -extern AVInputFormat shorten_demuxer; -extern AVInputFormat flac_demuxer; -extern AVOutputFormat flac_muxer; -extern AVInputFormat ac3_demuxer; -extern AVOutputFormat ac3_muxer; -extern AVInputFormat dts_demuxer; -extern AVInputFormat aac_demuxer; -extern AVInputFormat h261_demuxer; -extern AVOutputFormat h261_muxer; -extern AVInputFormat h263_demuxer; -extern AVOutputFormat h263_muxer; -extern AVInputFormat m4v_demuxer; -extern AVOutputFormat m4v_muxer; -extern AVInputFormat h264_demuxer; -extern AVOutputFormat h264_muxer; -extern AVInputFormat mpegvideo_demuxer; -extern AVOutputFormat mpeg1video_muxer; -extern AVOutputFormat mpeg2video_muxer; -extern AVInputFormat mjpeg_demuxer; -extern AVInputFormat ingenient_demuxer; -extern AVOutputFormat mjpeg_muxer; -extern AVInputFormat pcm_s16le_demuxer; -extern AVOutputFormat pcm_s16le_muxer; -extern AVInputFormat pcm_s16be_demuxer; -extern AVOutputFormat pcm_s16be_muxer; -extern AVInputFormat pcm_u16le_demuxer; -extern AVOutputFormat pcm_u16le_muxer; -extern AVInputFormat pcm_u16be_demuxer; -extern AVOutputFormat pcm_u16be_muxer; -extern AVInputFormat pcm_s8_demuxer; -extern AVOutputFormat pcm_s8_muxer; -extern AVInputFormat pcm_u8_demuxer; -extern AVOutputFormat pcm_u8_muxer; -extern AVInputFormat pcm_mulaw_demuxer; -extern AVOutputFormat pcm_mulaw_muxer; -extern AVInputFormat pcm_alaw_demuxer; -extern AVOutputFormat pcm_alaw_muxer; -extern AVInputFormat rawvideo_demuxer; -extern AVOutputFormat rawvideo_muxer; -extern AVOutputFormat null_muxer; -extern AVInputFormat rm_demuxer; -extern AVOutputFormat rm_muxer; -extern AVInputFormat sdp_demuxer; -extern AVInputFormat redir_demuxer; -extern AVInputFormat segafilm_demuxer; -extern AVInputFormat vmd_demuxer; -extern AVInputFormat smacker_demuxer; -extern AVInputFormat sol_demuxer; -extern AVInputFormat swf_demuxer; -extern AVOutputFormat swf_muxer; -extern AVInputFormat tta_demuxer; -extern AVInputFormat v4l2_demuxer; -extern AVInputFormat vc1_demuxer; -extern AVInputFormat voc_demuxer; -extern AVOutputFormat voc_muxer; -extern AVInputFormat wav_demuxer; -extern AVOutputFormat wav_muxer; -extern AVInputFormat wc3_demuxer; -extern AVInputFormat wsaud_demuxer; -extern AVInputFormat wsvqa_demuxer; -extern AVInputFormat wv_demuxer; -extern AVOutputFormat yuv4mpegpipe_muxer; -extern AVInputFormat yuv4mpegpipe_demuxer; -extern AVInputFormat tiertexseq_demuxer; -extern AVInputFormat x11_grab_device_demuxer; -extern AVInputFormat thp_demuxer; - -/* raw.c */ -int pcm_read_seek(AVFormatContext *s, - int stream_index, int64_t timestamp, int flags); - -/* rtsp.c */ -int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f); -/* rtp.c */ -void av_register_rtp_dynamic_payload_handlers(); - -#endif diff --git a/contrib/ffmpeg/libavformat/amr.c b/contrib/ffmpeg/libavformat/amr.c index 635a898fa..d8c5399e3 100644 --- a/contrib/ffmpeg/libavformat/amr.c +++ b/contrib/ffmpeg/libavformat/amr.c @@ -33,7 +33,7 @@ static const char AMRWB_header [] = "#!AMR-WB\n"; #ifdef CONFIG_MUXERS static int amr_write_header(AVFormatContext *s) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVCodecContext *enc = s->streams[0]->codec; s->priv_data = NULL; @@ -56,13 +56,8 @@ static int amr_write_header(AVFormatContext *s) static int amr_write_packet(AVFormatContext *s, AVPacket *pkt) { - put_buffer(&s->pb, pkt->data, pkt->size); - put_flush_packet(&s->pb); - return 0; -} - -static int amr_write_trailer(AVFormatContext *s) -{ + put_buffer(s->pb, pkt->data, pkt->size); + put_flush_packet(s->pb); return 0; } #endif /* CONFIG_MUXERS */ @@ -73,8 +68,6 @@ static int amr_probe(AVProbeData *p) //This will also trigger multichannel files: "#!AMR_MC1.0\n" and //"#!AMR-WB_MC1.0\n" (not supported) - if (p->buf_size < 5) - return 0; if(memcmp(p->buf,AMR_header,5)==0) return AVPROBE_SCORE_MAX; else @@ -85,7 +78,7 @@ static int amr_probe(AVProbeData *p) static int amr_read_header(AVFormatContext *s, AVFormatParameters *ap) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVStream *st; uint8_t header[9]; @@ -94,7 +87,7 @@ static int amr_read_header(AVFormatContext *s, st = av_new_stream(s, 0); if (!st) { - return AVERROR_NOMEM; + return AVERROR(ENOMEM); } if(memcmp(header,AMR_header,6)!=0) { @@ -125,15 +118,15 @@ static int amr_read_packet(AVFormatContext *s, AVPacket *pkt) { AVCodecContext *enc = s->streams[0]->codec; - int read, size, toc, mode; + int read, size = 0, toc, mode; - if (url_feof(&s->pb)) + if (url_feof(s->pb)) { - return AVERROR_IO; + return AVERROR(EIO); } //FIXME this is wrong, this should rather be in a AVParset - toc=get_byte(&s->pb); + toc=get_byte(s->pb); mode = (toc >> 3) & 0x0F; if (enc->codec_id == CODEC_ID_AMR_NB) @@ -155,19 +148,19 @@ static int amr_read_packet(AVFormatContext *s, if ( (size==0) || av_new_packet(pkt, size)) { - return AVERROR_IO; + return AVERROR(EIO); } pkt->stream_index = 0; - pkt->pos= url_ftell(&s->pb); + pkt->pos= url_ftell(s->pb); pkt->data[0]=toc; pkt->duration= enc->codec_id == CODEC_ID_AMR_NB ? 160 : 320; - read = get_buffer(&s->pb, pkt->data+1, size-1); + read = get_buffer(s->pb, pkt->data+1, size-1); if (read != size-1) { av_free_packet(pkt); - return AVERROR_IO; + return AVERROR(EIO); } return 0; @@ -196,6 +189,5 @@ AVOutputFormat amr_muxer = { CODEC_ID_NONE, amr_write_header, amr_write_packet, - amr_write_trailer, }; #endif diff --git a/contrib/ffmpeg/libavformat/apc.c b/contrib/ffmpeg/libavformat/apc.c new file mode 100644 index 000000000..97de8c88e --- /dev/null +++ b/contrib/ffmpeg/libavformat/apc.c @@ -0,0 +1,90 @@ +/* + * CRYO APC audio format demuxer + * Copyright (c) 2007 Anssi Hannula + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" +#include "string.h" + +static int apc_probe(AVProbeData *p) +{ + if (!strncmp(p->buf, "CRYO_APC", 8)) + return AVPROBE_SCORE_MAX; + + return 0; +} + +static int apc_read_header(AVFormatContext *s, AVFormatParameters *ap) +{ + ByteIOContext *pb = s->pb; + AVStream *st; + + get_le32(pb); /* CRYO */ + get_le32(pb); /* _APC */ + get_le32(pb); /* 1.20 */ + + st = av_new_stream(s, 0); + if (!st) + return AVERROR(ENOMEM); + + st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_ADPCM_IMA_WS; + + get_le32(pb); /* number of samples */ + st->codec->sample_rate = get_le32(pb); + + st->codec->extradata_size = 2 * 4; + st->codec->extradata = av_malloc(st->codec->extradata_size + + FF_INPUT_BUFFER_PADDING_SIZE); + if (!st->codec->extradata) + return AVERROR(ENOMEM); + + /* initial predictor values for adpcm decoder */ + get_buffer(pb, st->codec->extradata, 2 * 4); + + st->codec->channels = 1; + if (get_le32(pb)) + st->codec->channels = 2; + + st->codec->bits_per_sample = 4; + st->codec->bit_rate = st->codec->bits_per_sample * st->codec->channels + * st->codec->sample_rate; + st->codec->block_align = 1; + + return 0; +} + +#define MAX_READ_SIZE 4096 + +static int apc_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + if (av_get_packet(s->pb, pkt, MAX_READ_SIZE) <= 0) + return AVERROR(EIO); + pkt->stream_index = 0; + return 0; +} + +AVInputFormat apc_demuxer = { + "apc", + "CRYO APC format", + 0, + apc_probe, + apc_read_header, + apc_read_packet, +}; diff --git a/contrib/ffmpeg/libavformat/ape.c b/contrib/ffmpeg/libavformat/ape.c new file mode 100644 index 000000000..a90f887e5 --- /dev/null +++ b/contrib/ffmpeg/libavformat/ape.c @@ -0,0 +1,523 @@ +/* + * Monkey's Audio APE demuxer + * Copyright (c) 2007 Benjamin Zores + * based upon libdemac from Dave Chapman. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "avformat.h" + +#define ENABLE_DEBUG 0 + +/* The earliest and latest file formats supported by this library */ +#define APE_MIN_VERSION 3950 +#define APE_MAX_VERSION 3990 + +#define MAC_FORMAT_FLAG_8_BIT 1 // is 8-bit [OBSOLETE] +#define MAC_FORMAT_FLAG_CRC 2 // uses the new CRC32 error detection [OBSOLETE] +#define MAC_FORMAT_FLAG_HAS_PEAK_LEVEL 4 // uint32 nPeakLevel after the header [OBSOLETE] +#define MAC_FORMAT_FLAG_24_BIT 8 // is 24-bit [OBSOLETE] +#define MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS 16 // has the number of seek elements after the peak level +#define MAC_FORMAT_FLAG_CREATE_WAV_HEADER 32 // create the wave header on decompression (not stored) + +#define MAC_SUBFRAME_SIZE 4608 + +#define APE_EXTRADATA_SIZE 6 + +/* APE tags */ +#define APE_TAG_VERSION 2000 +#define APE_TAG_FOOTER_BYTES 32 +#define APE_TAG_FLAG_CONTAINS_HEADER (1 << 31) +#define APE_TAG_FLAG_IS_HEADER (1 << 29) + +#define TAG(name, field) {name, offsetof(AVFormatContext, field), sizeof(((AVFormatContext *)0)->field)} + +static const struct { + const char *name; + int offset; + int size; +} tags[] = { + TAG("Title" , title ), + TAG("Artist" , author ), + TAG("Copyright", copyright), + TAG("Comment" , comment ), + TAG("Album" , album ), + TAG("Year" , year ), + TAG("Track" , track ), + TAG("Genre" , genre ), + { NULL } +}; + +typedef struct { + int64_t pos; + int nblocks; + int size; + int skip; + int64_t pts; +} APEFrame; + +typedef struct { + /* Derived fields */ + uint32_t junklength; + uint32_t firstframe; + uint32_t totalsamples; + int currentframe; + APEFrame *frames; + + /* Info from Descriptor Block */ + char magic[4]; + int16_t fileversion; + int16_t padding1; + uint32_t descriptorlength; + uint32_t headerlength; + uint32_t seektablelength; + uint32_t wavheaderlength; + uint32_t audiodatalength; + uint32_t audiodatalength_high; + uint32_t wavtaillength; + uint8_t md5[16]; + + /* Info from Header Block */ + uint16_t compressiontype; + uint16_t formatflags; + uint32_t blocksperframe; + uint32_t finalframeblocks; + uint32_t totalframes; + uint16_t bps; + uint16_t channels; + uint32_t samplerate; + + /* Seektable */ + uint32_t *seektable; +} APEContext; + +static void ape_tag_read_field(AVFormatContext *s) +{ + ByteIOContext *pb = s->pb; + uint8_t buf[1024]; + uint32_t size; + int i; + + memset(buf, 0, 1024); + size = get_le32(pb); /* field size */ + url_fskip(pb, 4); /* skip field flags */ + + for (i=0; pb->buf_ptr[i]!='0' && pb->buf_ptr[i]>=0x20 && pb->buf_ptr[i]<=0x7E; i++); + + get_buffer(pb, buf, FFMIN(i, 1024)); + url_fskip(pb, 1); + + for (i=0; tags[i].name; i++) + if (!strcmp (buf, tags[i].name)) { + if (tags[i].size == sizeof(int)) { + char tmp[16]; + get_buffer(pb, tmp, FFMIN(sizeof(tmp), size)); + *(int *)(((char *)s)+tags[i].offset) = atoi(tmp); + } else { + get_buffer(pb, ((char *)s) + tags[i].offset, + FFMIN(tags[i].size, size)); + } + break; + } + + if (!tags[i].name) + url_fskip(pb, size); +} + +static void ape_parse_tag(AVFormatContext *s) +{ + ByteIOContext *pb = s->pb; + int file_size = url_fsize(pb); + uint32_t val, fields, tag_bytes; + uint8_t buf[8]; + int i; + + if (file_size < APE_TAG_FOOTER_BYTES) + return; + + url_fseek(pb, file_size - APE_TAG_FOOTER_BYTES, SEEK_SET); + + get_buffer(pb, buf, 8); /* APETAGEX */ + if (strncmp(buf, "APETAGEX", 8)) { + av_log(NULL, AV_LOG_ERROR, "Invalid APE Tags\n"); + return; + } + + val = get_le32(pb); /* APE tag version */ + if (val > APE_TAG_VERSION) { + av_log(NULL, AV_LOG_ERROR, "Unsupported tag version. (>=%d)\n", APE_TAG_VERSION); + return; + } + + tag_bytes = get_le32(pb); /* tag size */ + if (tag_bytes - APE_TAG_FOOTER_BYTES > (1024 * 1024 * 16)) { + av_log(NULL, AV_LOG_ERROR, "Tag size is way too big\n"); + return; + } + + fields = get_le32(pb); /* number of fields */ + if (fields > 65536) { + av_log(NULL, AV_LOG_ERROR, "Too many tag fields (%d)\n", fields); + return; + } + + val = get_le32(pb); /* flags */ + if (val & APE_TAG_FLAG_IS_HEADER) { + av_log(NULL, AV_LOG_ERROR, "APE Tag is a header\n"); + return; + } + + if (val & APE_TAG_FLAG_CONTAINS_HEADER) + tag_bytes += 2*APE_TAG_FOOTER_BYTES; + + url_fseek(pb, file_size - tag_bytes, SEEK_SET); + + for (i=0; ititle); + av_log(NULL, AV_LOG_DEBUG, "author = %s\n", s->author); + av_log(NULL, AV_LOG_DEBUG, "copyright = %s\n", s->copyright); + av_log(NULL, AV_LOG_DEBUG, "comment = %s\n", s->comment); + av_log(NULL, AV_LOG_DEBUG, "album = %s\n", s->album); + av_log(NULL, AV_LOG_DEBUG, "year = %d\n", s->year); + av_log(NULL, AV_LOG_DEBUG, "track = %d\n", s->track); + av_log(NULL, AV_LOG_DEBUG, "genre = %s\n", s->genre); +#endif +} + +static int ape_probe(AVProbeData * p) +{ + if (p->buf[0] == 'M' && p->buf[1] == 'A' && p->buf[2] == 'C' && p->buf[3] == ' ') + return AVPROBE_SCORE_MAX; + + return 0; +} + +static void ape_dumpinfo(APEContext * ape_ctx) +{ +#if ENABLE_DEBUG + int i; + + av_log(NULL, AV_LOG_DEBUG, "Descriptor Block:\n\n"); + av_log(NULL, AV_LOG_DEBUG, "magic = \"%c%c%c%c\"\n", ape_ctx->magic[0], ape_ctx->magic[1], ape_ctx->magic[2], ape_ctx->magic[3]); + av_log(NULL, AV_LOG_DEBUG, "fileversion = %d\n", ape_ctx->fileversion); + av_log(NULL, AV_LOG_DEBUG, "descriptorlength = %d\n", ape_ctx->descriptorlength); + av_log(NULL, AV_LOG_DEBUG, "headerlength = %d\n", ape_ctx->headerlength); + av_log(NULL, AV_LOG_DEBUG, "seektablelength = %d\n", ape_ctx->seektablelength); + av_log(NULL, AV_LOG_DEBUG, "wavheaderlength = %d\n", ape_ctx->wavheaderlength); + av_log(NULL, AV_LOG_DEBUG, "audiodatalength = %d\n", ape_ctx->audiodatalength); + av_log(NULL, AV_LOG_DEBUG, "audiodatalength_high = %d\n", ape_ctx->audiodatalength_high); + av_log(NULL, AV_LOG_DEBUG, "wavtaillength = %d\n", ape_ctx->wavtaillength); + av_log(NULL, AV_LOG_DEBUG, "md5 = "); + for (i = 0; i < 16; i++) + av_log(NULL, AV_LOG_DEBUG, "%02x", ape_ctx->md5[i]); + av_log(NULL, AV_LOG_DEBUG, "\n"); + + av_log(NULL, AV_LOG_DEBUG, "\nHeader Block:\n\n"); + + av_log(NULL, AV_LOG_DEBUG, "compressiontype = %d\n", ape_ctx->compressiontype); + av_log(NULL, AV_LOG_DEBUG, "formatflags = %d\n", ape_ctx->formatflags); + av_log(NULL, AV_LOG_DEBUG, "blocksperframe = %d\n", ape_ctx->blocksperframe); + av_log(NULL, AV_LOG_DEBUG, "finalframeblocks = %d\n", ape_ctx->finalframeblocks); + av_log(NULL, AV_LOG_DEBUG, "totalframes = %d\n", ape_ctx->totalframes); + av_log(NULL, AV_LOG_DEBUG, "bps = %d\n", ape_ctx->bps); + av_log(NULL, AV_LOG_DEBUG, "channels = %d\n", ape_ctx->channels); + av_log(NULL, AV_LOG_DEBUG, "samplerate = %d\n", ape_ctx->samplerate); + + av_log(NULL, AV_LOG_DEBUG, "\nSeektable\n\n"); + if ((ape_ctx->seektablelength / sizeof(uint32_t)) != ape_ctx->totalframes) { + av_log(NULL, AV_LOG_DEBUG, "No seektable\n"); + } else { + for (i = 0; i < ape_ctx->seektablelength / sizeof(uint32_t); i++) { + if (i < ape_ctx->totalframes - 1) { + av_log(NULL, AV_LOG_DEBUG, "%8d %d (%d bytes)\n", i, ape_ctx->seektable[i], ape_ctx->seektable[i + 1] - ape_ctx->seektable[i]); + } else { + av_log(NULL, AV_LOG_DEBUG, "%8d %d\n", i, ape_ctx->seektable[i]); + } + } + } + + av_log(NULL, AV_LOG_DEBUG, "\nFrames\n\n"); + for (i = 0; i < ape_ctx->totalframes; i++) + av_log(NULL, AV_LOG_DEBUG, "%8d %8lld %8d (%d samples)\n", i, ape_ctx->frames[i].pos, ape_ctx->frames[i].size, ape_ctx->frames[i].nblocks); + + av_log(NULL, AV_LOG_DEBUG, "\nCalculated information:\n\n"); + av_log(NULL, AV_LOG_DEBUG, "junklength = %d\n", ape_ctx->junklength); + av_log(NULL, AV_LOG_DEBUG, "firstframe = %d\n", ape_ctx->firstframe); + av_log(NULL, AV_LOG_DEBUG, "totalsamples = %d\n", ape_ctx->totalsamples); +#endif +} + +static int ape_read_header(AVFormatContext * s, AVFormatParameters * ap) +{ + ByteIOContext *pb = s->pb; + APEContext *ape = s->priv_data; + AVStream *st; + uint32_t tag; + int i; + int total_blocks; + int64_t pts; + + /* TODO: Skip any leading junk such as id3v2 tags */ + ape->junklength = 0; + + tag = get_le32(pb); + if (tag != MKTAG('M', 'A', 'C', ' ')) + return -1; + + ape->fileversion = get_le16(pb); + + if (ape->fileversion < APE_MIN_VERSION || ape->fileversion > APE_MAX_VERSION) { + av_log(s, AV_LOG_ERROR, "Unsupported file version - %d.%02d\n", ape->fileversion / 1000, (ape->fileversion % 1000) / 10); + return -1; + } + + if (ape->fileversion >= 3980) { + ape->padding1 = get_le16(pb); + ape->descriptorlength = get_le32(pb); + ape->headerlength = get_le32(pb); + ape->seektablelength = get_le32(pb); + ape->wavheaderlength = get_le32(pb); + ape->audiodatalength = get_le32(pb); + ape->audiodatalength_high = get_le32(pb); + ape->wavtaillength = get_le32(pb); + get_buffer(pb, ape->md5, 16); + + /* Skip any unknown bytes at the end of the descriptor. + This is for future compatibility */ + if (ape->descriptorlength > 52) + url_fseek(pb, ape->descriptorlength - 52, SEEK_CUR); + + /* Read header data */ + ape->compressiontype = get_le16(pb); + ape->formatflags = get_le16(pb); + ape->blocksperframe = get_le32(pb); + ape->finalframeblocks = get_le32(pb); + ape->totalframes = get_le32(pb); + ape->bps = get_le16(pb); + ape->channels = get_le16(pb); + ape->samplerate = get_le32(pb); + } else { + ape->descriptorlength = 0; + ape->headerlength = 32; + + ape->compressiontype = get_le16(pb); + ape->formatflags = get_le16(pb); + ape->channels = get_le16(pb); + ape->samplerate = get_le32(pb); + ape->wavheaderlength = get_le32(pb); + ape->wavtaillength = get_le32(pb); + ape->totalframes = get_le32(pb); + ape->finalframeblocks = get_le32(pb); + + if (ape->formatflags & MAC_FORMAT_FLAG_HAS_PEAK_LEVEL) { + url_fseek(pb, 4, SEEK_CUR); /* Skip the peak level */ + ape->headerlength += 4; + } + + if (ape->formatflags & MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS) { + ape->seektablelength = get_le32(pb); + ape->headerlength += 4; + ape->seektablelength *= sizeof(int32_t); + } else + ape->seektablelength = ape->totalframes * sizeof(int32_t); + + if (ape->formatflags & MAC_FORMAT_FLAG_8_BIT) + ape->bps = 8; + else if (ape->formatflags & MAC_FORMAT_FLAG_24_BIT) + ape->bps = 24; + else + ape->bps = 16; + + if (ape->fileversion >= 3950) + ape->blocksperframe = 73728 * 4; + else if (ape->fileversion >= 3900 || (ape->fileversion >= 3800 && ape->compressiontype >= 4000)) + ape->blocksperframe = 73728; + else + ape->blocksperframe = 9216; + + /* Skip any stored wav header */ + if (!(ape->formatflags & MAC_FORMAT_FLAG_CREATE_WAV_HEADER)) + url_fskip(pb, ape->wavheaderlength); + } + + if(ape->totalframes > UINT_MAX / sizeof(APEFrame)){ + av_log(s, AV_LOG_ERROR, "Too many frames: %d\n", ape->totalframes); + return -1; + } + ape->frames = av_malloc(ape->totalframes * sizeof(APEFrame)); + if(!ape->frames) + return AVERROR_NOMEM; + ape->firstframe = ape->junklength + ape->descriptorlength + ape->headerlength + ape->seektablelength + ape->wavheaderlength; + ape->currentframe = 0; + + + ape->totalsamples = ape->finalframeblocks; + if (ape->totalframes > 1) + ape->totalsamples += ape->blocksperframe * (ape->totalframes - 1); + + if (ape->seektablelength > 0) { + ape->seektable = av_malloc(ape->seektablelength); + for (i = 0; i < ape->seektablelength / sizeof(uint32_t); i++) + ape->seektable[i] = get_le32(pb); + } + + ape->frames[0].pos = ape->firstframe; + ape->frames[0].nblocks = ape->blocksperframe; + ape->frames[0].skip = 0; + for (i = 1; i < ape->totalframes; i++) { + ape->frames[i].pos = ape->seektable[i]; //ape->frames[i-1].pos + ape->blocksperframe; + ape->frames[i].nblocks = ape->blocksperframe; + ape->frames[i - 1].size = ape->frames[i].pos - ape->frames[i - 1].pos; + ape->frames[i].skip = (ape->frames[i].pos - ape->frames[0].pos) & 3; + } + ape->frames[ape->totalframes - 1].size = ape->finalframeblocks * 4; + ape->frames[ape->totalframes - 1].nblocks = ape->finalframeblocks; + + for (i = 0; i < ape->totalframes; i++) { + if(ape->frames[i].skip){ + ape->frames[i].pos -= ape->frames[i].skip; + ape->frames[i].size += ape->frames[i].skip; + } + ape->frames[i].size = (ape->frames[i].size + 3) & ~3; + } + + + ape_dumpinfo(ape); + + /* try to read APE tags */ + if (!url_is_streamed(pb)) { + ape_parse_tag(s); + url_fseek(pb, 0, SEEK_SET); + } + + av_log(s, AV_LOG_DEBUG, "Decoding file - v%d.%02d, compression level %d\n", ape->fileversion / 1000, (ape->fileversion % 1000) / 10, ape->compressiontype); + + /* now we are ready: build format streams */ + st = av_new_stream(s, 0); + if (!st) + return -1; + + total_blocks = (ape->totalframes == 0) ? 0 : ((ape->totalframes - 1) * ape->blocksperframe) + ape->finalframeblocks; + + st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_APE; + st->codec->codec_tag = MKTAG('A', 'P', 'E', ' '); + st->codec->channels = ape->channels; + st->codec->sample_rate = ape->samplerate; + st->codec->bits_per_sample = ape->bps; + st->codec->frame_size = MAC_SUBFRAME_SIZE; + + st->nb_frames = ape->totalframes; + s->start_time = 0; + s->duration = (int64_t) total_blocks * AV_TIME_BASE / ape->samplerate; + av_set_pts_info(st, 64, MAC_SUBFRAME_SIZE, ape->samplerate); + + st->codec->extradata = av_malloc(APE_EXTRADATA_SIZE); + st->codec->extradata_size = APE_EXTRADATA_SIZE; + AV_WL16(st->codec->extradata + 0, ape->fileversion); + AV_WL16(st->codec->extradata + 2, ape->compressiontype); + AV_WL16(st->codec->extradata + 4, ape->formatflags); + + pts = 0; + for (i = 0; i < ape->totalframes; i++) { + ape->frames[i].pts = pts; + av_add_index_entry(st, ape->frames[i].pos, ape->frames[i].pts, 0, 0, AVINDEX_KEYFRAME); + pts += ape->blocksperframe / MAC_SUBFRAME_SIZE; + } + + return 0; +} + +static int ape_read_packet(AVFormatContext * s, AVPacket * pkt) +{ + int ret; + int nblocks; + APEContext *ape = s->priv_data; + uint32_t extra_size = 8; + + if (url_feof(s->pb)) + return AVERROR_IO; + if (ape->currentframe > ape->totalframes) + return AVERROR_IO; + + url_fseek (s->pb, ape->frames[ape->currentframe].pos, SEEK_SET); + + /* Calculate how many blocks there are in this frame */ + if (ape->currentframe == (ape->totalframes - 1)) + nblocks = ape->finalframeblocks; + else + nblocks = ape->blocksperframe; + + if (av_new_packet(pkt, ape->frames[ape->currentframe].size + extra_size) < 0) + return AVERROR_NOMEM; + + AV_WL32(pkt->data , nblocks); + AV_WL32(pkt->data + 4, ape->frames[ape->currentframe].skip); + ret = get_buffer(s->pb, pkt->data + extra_size, ape->frames[ape->currentframe].size); + + pkt->pts = ape->frames[ape->currentframe].pts; + pkt->stream_index = 0; + + /* note: we need to modify the packet size here to handle the last + packet */ + pkt->size = ret + extra_size; + + ape->currentframe++; + + return 0; +} + +static int ape_read_close(AVFormatContext * s) +{ + APEContext *ape = s->priv_data; + + av_freep(&ape->frames); + av_freep(&ape->seektable); + return 0; +} + +static int ape_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) +{ + AVStream *st = s->streams[stream_index]; + APEContext *ape = s->priv_data; + int index = av_index_search_timestamp(st, timestamp, flags); + + if (index < 0) + return -1; + + ape->currentframe = index; + return 0; +} + +AVInputFormat ape_demuxer = { + "ape", + "Monkey's Audio", + sizeof(APEContext), + ape_probe, + ape_read_header, + ape_read_packet, + ape_read_close, + ape_read_seek, + .extensions = "ape,apl,mac" +}; diff --git a/contrib/ffmpeg/libavformat/asf-enc.c b/contrib/ffmpeg/libavformat/asf-enc.c index f1d9c6903..a12cda1e7 100644 --- a/contrib/ffmpeg/libavformat/asf-enc.c +++ b/contrib/ffmpeg/libavformat/asf-enc.c @@ -199,7 +199,7 @@ static const AVCodecTag codec_asf_bmp_tags[] = { static void put_guid(ByteIOContext *s, const GUID *g) { assert(sizeof(*g) == 16); - put_buffer(s, g, sizeof(*g)); + put_buffer(s, *g, sizeof(*g)); } static void put_str16_nolen(ByteIOContext *s, const char *tag); @@ -244,7 +244,7 @@ static void end_header(ByteIOContext *pb, int64_t pos) static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags) { ASFContext *asf = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int length; length = payload_length + 8; @@ -270,7 +270,7 @@ static int64_t unix_to_file_time(int ti) static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size) { ASFContext *asf = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int header_size, n, extra_size, extra_size2, wav_extra_size, file_time; int has_title; AVCodecContext *enc; @@ -493,17 +493,20 @@ static int asf_write_header(AVFormatContext *s) asf->nb_packets = 0; asf->last_indexed_pts = 0; - asf->index_ptr = (ASFIndex*)av_malloc( sizeof(ASFIndex) * ASF_INDEX_BLOCK ); + asf->index_ptr = av_malloc( sizeof(ASFIndex) * ASF_INDEX_BLOCK ); asf->nb_index_memory_alloc = ASF_INDEX_BLOCK; asf->nb_index_count = 0; asf->maximum_packet = 0; - if (asf_write_header1(s, 0, 0) < 0) { + /* the data-chunk-size has to be 50, which is data_size - asf->data_offset + * at the moment this function is done. It is needed to use asf as + * streamable format. */ + if (asf_write_header1(s, 0, 50) < 0) { //av_free(asf); return -1; } - put_flush_packet(&s->pb); + put_flush_packet(s->pb); asf->packet_nb_payloads = 0; asf->packet_timestamp_start = -1; @@ -532,7 +535,7 @@ static int put_payload_parsing_info( ) { ASFContext *asf = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int ppi_size, i; int64_t start= url_ftell(pb); @@ -581,6 +584,8 @@ static void flush_packet(AVFormatContext *s) ASFContext *asf = s->priv_data; int packet_hdr_size, packet_filled_size; + assert(asf->packet_timestamp_end >= asf->packet_timestamp_start); + if (asf->is_streamed) { put_chunk(s, 0x4424, asf->packet_size, 0); } @@ -597,9 +602,9 @@ static void flush_packet(AVFormatContext *s) assert(packet_hdr_size <= asf->packet_size_left); memset(asf->packet_buf + packet_filled_size, 0, asf->packet_size_left); - put_buffer(&s->pb, asf->packet_buf, asf->packet_size - packet_hdr_size); + put_buffer(s->pb, asf->packet_buf, asf->packet_size - packet_hdr_size); - put_flush_packet(&s->pb); + put_flush_packet(s->pb); asf->nb_packets++; asf->packet_nb_payloads = 0; asf->packet_timestamp_start = -1; @@ -677,8 +682,6 @@ static void put_frame( // multi payloads frag_len1 = asf->packet_size_left - PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS - PACKET_HEADER_MIN_SIZE - 1; - asf->packet_timestamp_start = timestamp; - if(frag_len1 < payload_len && avst->codec->codec_type == CODEC_TYPE_AUDIO){ flush_packet(s); continue; @@ -763,7 +766,7 @@ static int asf_write_packet(AVFormatContext *s, AVPacket *pkt) // static int asf_write_index(AVFormatContext *s, ASFIndex *index, uint16_t max, uint32_t count) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int i; put_guid(pb, &simple_index_header); @@ -790,22 +793,22 @@ static int asf_write_trailer(AVFormatContext *s) flush_packet(s); /* write index */ - data_size = url_ftell(&s->pb); + data_size = url_ftell(s->pb); if ((!asf->is_streamed) && (asf->nb_index_count != 0)) { asf_write_index(s, asf->index_ptr, asf->maximum_packet, asf->nb_index_count); } - put_flush_packet(&s->pb); + put_flush_packet(s->pb); - if (asf->is_streamed || url_is_streamed(&s->pb)) { + if (asf->is_streamed || url_is_streamed(s->pb)) { put_chunk(s, 0x4524, 0, 0); /* end of stream */ } else { /* rewrite an updated header */ - file_size = url_ftell(&s->pb); - url_fseek(&s->pb, 0, SEEK_SET); + file_size = url_ftell(s->pb); + url_fseek(s->pb, 0, SEEK_SET); asf_write_header1(s, file_size, data_size - asf->data_offset); } - put_flush_packet(&s->pb); + put_flush_packet(s->pb); av_free(asf->index_ptr); return 0; } diff --git a/contrib/ffmpeg/libavformat/asf.c b/contrib/ffmpeg/libavformat/asf.c index 498f6e79e..30330c535 100644 --- a/contrib/ffmpeg/libavformat/asf.c +++ b/contrib/ffmpeg/libavformat/asf.c @@ -23,6 +23,9 @@ #include "mpegaudio.h" #include "asf.h" #include "common.h" +#include "asfcrypt.h" + +extern void ff_mms_set_stream_selection(URLContext *h, AVFormatContext *format); #undef NDEBUG #include @@ -84,7 +87,7 @@ static void print_guid(const GUID *g) static void get_guid(ByteIOContext *s, GUID *g) { assert(sizeof(*g) == 16); - get_buffer(s, g, sizeof(*g)); + get_buffer(s, *g, sizeof(*g)); } #if 0 @@ -119,9 +122,6 @@ static void get_str16_nolen(ByteIOContext *pb, int len, char *buf, int buf_size) static int asf_probe(AVProbeData *pd) { /* check file header */ - if (pd->buf_size <= 32) - return 0; - if (!memcmp(pd->buf, &asf_header, sizeof(GUID))) return AVPROBE_SCORE_MAX; else @@ -142,14 +142,16 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) { ASFContext *asf = s->priv_data; GUID g; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVStream *st; ASFStream *asf_st; int size, i; int64_t gsize; AVRational dar[128]; + uint32_t bitrate[128]; memset(dar, 0, sizeof(dar)); + memset(bitrate, 0, sizeof(bitrate)); get_guid(pb, &g); if (memcmp(&g, &asf_header, sizeof(GUID))) @@ -197,8 +199,8 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) int type, type_specific_size, sizeX; uint64_t total_size; unsigned int tag1; - int64_t pos1, pos2; - int test_for_ext_stream_audio; + int64_t pos1, pos2, start_time; + int test_for_ext_stream_audio, is_dvr_ms_audio=0; pos1 = url_ftell(pb); @@ -210,10 +212,11 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) if (!asf_st) goto fail; st->priv_data = asf_st; - st->start_time = asf->hdr.preroll; + start_time = asf->hdr.preroll; + if(!(asf->hdr.flags & 0x01)) { // if we aren't streaming... st->duration = asf->hdr.send_time / - (10000000 / 1000) - st->start_time; + (10000000 / 1000) - start_time; } get_guid(pb, &g); @@ -244,6 +247,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) get_guid(pb, &g); if (!memcmp(&g, &ext_stream_audio_stream, sizeof(GUID))) { type = CODEC_TYPE_AUDIO; + is_dvr_ms_audio=1; get_guid(pb, &g); get_le32(pb); get_le32(pb); @@ -256,7 +260,13 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) st->codec->codec_type = type; if (type == CODEC_TYPE_AUDIO) { get_wav_header(pb, st->codec, type_specific_size); - st->need_parsing = 1; + if (is_dvr_ms_audio) { + // codec_id and codec_tag are unreliable in dvr_ms + // files. Set them later by probing stream. + st->codec->codec_id = CODEC_ID_NONE; + st->codec->codec_tag = 0; + } + st->need_parsing = AVSTREAM_PARSE_FULL; /* We have to init the frame size at some point .... */ pos2 = url_ftell(pb); if (gsize >= (pos2 + 8 - pos1 + 24)) { @@ -333,7 +343,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) st->codec->codec_tag = tag1; st->codec->codec_id = codec_get_id(codec_bmp_tags, tag1); if(tag1 == MKTAG('D', 'V', 'R', ' ')) - st->need_parsing = 1; + st->need_parsing = AVSTREAM_PARSE_FULL; } pos2 = url_ftell(pb); url_fskip(pb, gsize - (pos2 - pos1 + 24)); @@ -363,7 +373,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) bitrate= get_le32(pb); stream_id= (flags & 0x7f); // av_log(NULL, AV_LOG_ERROR, "flags: 0x%x stream id %d, bitrate %d\n", flags, stream_id, bitrate); - asf->stream_bitrates[stream_id-1]= bitrate; + asf->stream_bitrates[stream_id]= bitrate; } } else if (!memcmp(&g, &extended_content_header, sizeof(GUID))) { int desc_count, i; @@ -383,12 +393,27 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) { if (!strcmp(name,"WM/AlbumTitle")) get_str16_nolen(pb, value_len, s->album, sizeof(s->album)); else if(!strcmp(name,"WM/Genre" )) get_str16_nolen(pb, value_len, s->genre, sizeof(s->genre)); + else if(!strcmp(name,"WM/Year" )) { + char year[8]; + get_str16_nolen(pb, value_len, year, sizeof(year)); + s->year = atoi(year); + } + else if(!strcmp(name,"WM/Track") && s->track == 0) { + char track[8]; + get_str16_nolen(pb, value_len, track, sizeof(track)); + s->track = strtol(track, NULL, 10) + 1; + } + else if(!strcmp(name,"WM/TrackNumber")) { + char track[8]; + get_str16_nolen(pb, value_len, track, sizeof(track)); + s->track = strtol(track, NULL, 10); + } else url_fskip(pb, value_len); } if ((value_type >= 2) && (value_type <= 5)) // boolean or DWORD or QWORD or WORD { value_num= get_value(pb, value_type); - if (!strcmp(name,"WM/Track" )) s->track = value_num + 1; + if (!strcmp(name,"WM/Track" ) && s->track == 0) s->track = value_num + 1; if (!strcmp(name,"WM/TrackNumber")) s->track = value_num; } } @@ -407,7 +432,7 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) get_str16_nolen(pb, name_len, name, sizeof(name)); //av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d <%s>\n", i, stream_num, name_len, value_type, value_len, name); - value_num= get_le16(pb);//we should use get_value() here but it doesnt work 2 is le16 here but le32 elsewhere + value_num= get_le16(pb);//we should use get_value() here but it does not work 2 is le16 here but le32 elsewhere url_fskip(pb, value_len - 2); if(stream_num<128){ @@ -417,13 +442,13 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) } } else if (!memcmp(&g, &ext_stream_header, sizeof(GUID))) { int ext_len, payload_ext_ct, stream_ct; - uint32_t ext_d; + uint32_t ext_d, leak_rate, stream_num; int64_t pos_ex_st; pos_ex_st = url_ftell(pb); get_le64(pb); // starttime get_le64(pb); // endtime - get_le32(pb); // leak-datarate + leak_rate = get_le32(pb); // leak-datarate get_le32(pb); // bucket-datasize get_le32(pb); // init-bucket-fullness get_le32(pb); // alt-leak-datarate @@ -431,12 +456,15 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) get_le32(pb); // alt-init-bucket-fullness get_le32(pb); // max-object-size get_le32(pb); // flags (reliable,seekable,no_cleanpoints?,resend-live-cleanpoints, rest of bits reserved) - get_le16(pb); // stream-num + stream_num = get_le16(pb); // stream-num get_le16(pb); // stream-language-id-index get_le64(pb); // avg frametime in 100ns units stream_ct = get_le16(pb); //stream-name-count payload_ext_ct = get_le16(pb); //payload-extension-system-count + if (stream_num < 128) + bitrate[stream_num] = leak_rate; + for (i=0; iasfid2avid[i]; - if(stream_num>=0 && dar[i].num>0 && dar[i].den>0){ + if(stream_num>=0){ AVCodecContext *codec= s->streams[stream_num]->codec; - av_reduce(&codec->sample_aspect_ratio.num, - &codec->sample_aspect_ratio.den, - dar[i].num, dar[i].den, INT_MAX); + if (!codec->bit_rate) + codec->bit_rate = bitrate[i]; + if (dar[i].num > 0 && dar[i].den > 0) + av_reduce(&codec->sample_aspect_ratio.num, + &codec->sample_aspect_ratio.den, + dar[i].num, dar[i].den, INT_MAX); //av_log(NULL, AV_LOG_ERROR, "dar %d:%d sar=%d:%d\n", dar[i].num, dar[i].den, codec->sample_aspect_ratio.num, codec->sample_aspect_ratio.den); } } @@ -539,12 +570,12 @@ static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) static int asf_get_packet(AVFormatContext *s) { ASFContext *asf = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; uint32_t packet_length, padsize; int rsize = 8; int c, d, e, off; - off= (url_ftell(&s->pb) - s->data_offset) % asf->packet_size + 3; + off= (url_ftell(s->pb) - s->data_offset) % asf->packet_size + 3; c=d=e=-1; while(off-- > 0){ @@ -615,7 +646,7 @@ static int asf_get_packet(AVFormatContext *s) */ static int asf_read_frame_header(AVFormatContext *s){ ASFContext *asf = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int rsize = 1; int num = get_byte(pb); int64_t ts0, ts1; @@ -651,7 +682,7 @@ static int asf_read_frame_header(AVFormatContext *s){ url_fskip(pb, asf->packet_replic_size - 8); rsize += asf->packet_replic_size; // FIXME - check validity } else if (asf->packet_replic_size==1){ - // multipacket - frag_offset is begining timestamp + // multipacket - frag_offset is beginning timestamp asf->packet_time_start = asf->packet_frag_offset; asf->packet_frag_offset = 0; asf->packet_frag_timestamp = asf->packet_timestamp; @@ -688,11 +719,11 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) { ASFContext *asf = s->priv_data; ASFStream *asf_st = 0; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; //static int pc = 0; for (;;) { if(url_feof(pb)) - return AVERROR_IO; + return AVERROR(EIO); if (asf->packet_size_left < FRAME_HEADER_SIZE || asf->packet_segments < 1) { //asf->packet_size_left <= asf->packet_padsize) { @@ -702,10 +733,10 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) /* fail safe */ url_fskip(pb, ret); - asf->packet_pos= url_ftell(&s->pb); + asf->packet_pos= url_ftell(s->pb); if (asf->data_object_size != (uint64_t)-1 && (asf->packet_pos - asf->data_object_offset >= asf->data_object_size)) - return AVERROR_IO; /* Do not exceed the size of the data object */ + return AVERROR(EIO); /* Do not exceed the size of the data object */ ret = asf_get_packet(s); //printf("READ ASF PACKET %d r:%d c:%d\n", ret, asf->packet_size_left, pc++); if (ret < 0) @@ -735,7 +766,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) asf_st = asf->asf_st; if (asf->packet_replic_size == 1) { - // frag_offset is here used as the begining timestamp + // frag_offset is here used as the beginning timestamp asf->packet_frag_timestamp = asf->packet_time_start; asf->packet_time_start += asf->packet_time_delta; asf->packet_obj_size = asf->packet_frag_size = get_byte(pb); @@ -751,6 +782,15 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) asf->packet_multi_size -= asf->packet_obj_size; //printf("COMPRESS size %d %d %d ms:%d\n", asf->packet_obj_size, asf->packet_frag_timestamp, asf->packet_size_left, asf->packet_multi_size); } + if( /*asf->packet_frag_size == asf->packet_obj_size*/ + asf_st->frag_offset + asf->packet_frag_size <= asf_st->pkt.size + && asf_st->frag_offset + asf->packet_frag_size > asf->packet_obj_size){ + av_log(s, AV_LOG_INFO, "ignoring invalid packet_obj_size (%d %d %d %d)\n", + asf_st->frag_offset, asf->packet_frag_size, + asf->packet_obj_size, asf_st->pkt.size); + asf->packet_obj_size= asf_st->pkt.size; + } + if ( asf_st->pkt.size != asf->packet_obj_size || asf_st->frag_offset + asf->packet_frag_size > asf_st->pkt.size) { //FIXME is this condition sufficient? if(asf_st->pkt.data){ @@ -791,13 +831,29 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset, asf->packet_frag_size); + if (s->key && s->keylen == 20) + ff_asfcrypt_dec(s->key, asf_st->pkt.data + asf->packet_frag_offset, + asf->packet_frag_size); asf_st->frag_offset += asf->packet_frag_size; /* test if whole packet is read */ if (asf_st->frag_offset == asf_st->pkt.size) { + //workaround for macroshit radio DVR-MS files + if( s->streams[asf->stream_index]->codec->codec_id == CODEC_ID_MPEG2VIDEO + && asf_st->pkt.size > 100){ + int i; + for(i=0; ipkt.size && !asf_st->pkt.data[i]; i++); + if(i == asf_st->pkt.size){ + av_log(s, AV_LOG_DEBUG, "discarding ms fart\n"); + asf_st->frag_offset = 0; + av_free_packet(&asf_st->pkt); + continue; + } + } + /* return packet */ if (asf_st->ds_span > 1) { if(asf_st->pkt.size != asf_st->ds_packet_size * asf_st->ds_span){ - av_log(s, AV_LOG_ERROR, "pkt.size != ds_packet_size * ds_span\n"); + av_log(s, AV_LOG_ERROR, "pkt.size != ds_packet_size * ds_span (%d %d %d)\n", asf_st->pkt.size, asf_st->ds_packet_size, asf_st->ds_span); }else{ /* packet descrambling */ uint8_t *newdata = av_malloc(asf_st->pkt.size); @@ -833,18 +889,6 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) return 0; } -static int asf_read_close(AVFormatContext *s) -{ - int i; - - for(i=0;inb_streams;i++) { - AVStream *st = s->streams[i]; - av_free(st->priv_data); - av_free(st->codec->palctrl); - } - return 0; -} - // Added to support seeking after packets have been read // If information is not reset, read_packet fails due to // leftover information from previous reads @@ -883,6 +927,19 @@ static void asf_reset_header(AVFormatContext *s) asf->asf_st= NULL; } +static int asf_read_close(AVFormatContext *s) +{ + int i; + + asf_reset_header(s); + for(i=0;inb_streams;i++) { + AVStream *st = s->streams[i]; + av_free(st->priv_data); + av_free(st->codec->palctrl); + } + return 0; +} + static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit) { ASFContext *asf = s->priv_data; @@ -899,7 +956,7 @@ static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos, pos= (pos+asf->packet_size-1-s->data_offset)/asf->packet_size*asf->packet_size+ s->data_offset; *ppos= pos; - url_fseek(&s->pb, pos, SEEK_SET); + url_fseek(s->pb, pos, SEEK_SET); //printf("asf_read_pts\n"); asf_reset_header(s); @@ -943,21 +1000,21 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index) int i; int pct,ict; - current_pos = url_ftell(&s->pb); + current_pos = url_ftell(s->pb); - url_fseek(&s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET); - get_guid(&s->pb, &g); + url_fseek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET); + get_guid(s->pb, &g); if (!memcmp(&g, &index_guid, sizeof(GUID))) { - gsize = get_le64(&s->pb); - get_guid(&s->pb, &g); - itime=get_le64(&s->pb); - pct=get_le32(&s->pb); - ict=get_le32(&s->pb); + gsize = get_le64(s->pb); + get_guid(s->pb, &g); + itime=get_le64(s->pb); + pct=get_le32(s->pb); + ict=get_le32(s->pb); av_log(NULL, AV_LOG_DEBUG, "itime:0x%"PRIx64", pct:%d, ict:%d\n",itime,pct,ict); for (i=0;ipb); - int pktct =get_le16(&s->pb); + int pktnum=get_le32(s->pb); + int pktct =get_le16(s->pb); av_log(NULL, AV_LOG_DEBUG, "pktnum:%d, pktct:%d\n", pktnum, pktct); pos=s->data_offset + asf->packet_size*(int64_t)pktnum; @@ -967,7 +1024,7 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index) } asf->index_read= 1; } - url_fseek(&s->pb, current_pos, SEEK_SET); + url_fseek(s->pb, current_pos, SEEK_SET); } static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags) @@ -980,6 +1037,15 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int if (asf->packet_size <= 0) return -1; + /* Try using the protocol's read_seek if available */ + if(s->pb) { + int ret = av_url_read_fseek(s->pb, stream_index, pts, flags); + if(ret >= 0) + asf_reset_header(s); + if (ret != AVERROR(ENOSYS)) + return ret; + } + if (!asf->index_read) asf_build_simple_index(s, stream_index); @@ -997,10 +1063,10 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int // various attempts to find key frame have failed so far // asf_reset_header(s); - // url_fseek(&s->pb, pos, SEEK_SET); + // url_fseek(s->pb, pos, SEEK_SET); // key_pos = pos; // for(i=0;i<16;i++){ - // pos = url_ftell(&s->pb); + // pos = url_ftell(s->pb); // if (av_read_frame(s, &pkt) < 0){ // av_log(s, AV_LOG_INFO, "seek failed\n"); // return -1; @@ -1018,7 +1084,7 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int /* do the seek */ av_log(NULL, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos); - url_fseek(&s->pb, pos, SEEK_SET); + url_fseek(s->pb, pos, SEEK_SET); } asf_reset_header(s); return 0; diff --git a/contrib/ffmpeg/libavformat/asf.h b/contrib/ffmpeg/libavformat/asf.h index 6d76ebecb..2486d8a6f 100644 --- a/contrib/ffmpeg/libavformat/asf.h +++ b/contrib/ffmpeg/libavformat/asf.h @@ -17,6 +17,13 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#ifndef FFMPEG_ASF_H +#define FFMPEG_ASF_H + +#include +#include "avformat.h" + #define PACKET_SIZE 3200 typedef struct { @@ -49,7 +56,7 @@ typedef struct { uint64_t send_time; /**< time to send file, in 100-nanosecond units * invalid if broadcasting (could be ignored) */ uint32_t preroll; /**< timestamp of the first packet, in milliseconds - * if nonzero - substract from time */ + * if nonzero - subtract from time */ uint32_t ignore; ///< preroll is 64bit - but let's just ignore it uint32_t flags; /**< 0x01 - broadcast * 0x02 - seekable @@ -90,7 +97,7 @@ typedef struct { uint8_t packet_buf[PACKET_SIZE]; ByteIOContext pb; /* only for reading */ - uint64_t data_offset; ///< begining of the first data packet + uint64_t data_offset; ///< beginning of the first data packet uint64_t data_object_offset; ///< data object offset (excl. GUID & size) uint64_t data_object_size; ///< size of the data object int index_read; @@ -278,3 +285,5 @@ static const GUID my_guid = { #define ASF_PL_MASK_PAYLOAD_LENGTH_FIELD_SIZE 0xc0 //1100 0000 #define ASF_PL_FLAG_KEY_FRAME 0x80 //1000 0000 + +#endif /* FFMPEG_ASF_H */ diff --git a/contrib/ffmpeg/libavformat/asfcrypt.c b/contrib/ffmpeg/libavformat/asfcrypt.c new file mode 100644 index 000000000..10cc934b4 --- /dev/null +++ b/contrib/ffmpeg/libavformat/asfcrypt.c @@ -0,0 +1,172 @@ +/* + * ASF decryption + * Copyright (c) 2007 Reimar Doeffinger + * This is a rewrite of code contained in freeme/freeme2 + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "common.h" +#include "intreadwrite.h" +#include "bswap.h" +#include "des.h" +#include "rc4.h" +#include "asfcrypt.h" + +/** + * \brief find multiplicative inverse modulo 2 ^ 32 + * \param v number to invert, must be odd! + * \return number so that result * v = 1 (mod 2^32) + */ +static uint32_t inverse(uint32_t v) { + // v ^ 3 gives the inverse (mod 16), could also be implemented + // as table etc. (only lowest 4 bits matter!) + uint32_t inverse = v * v * v; + // uses a fixpoint-iteration that doubles the number + // of correct lowest bits each time + inverse *= 2 - v * inverse; + inverse *= 2 - v * inverse; + inverse *= 2 - v * inverse; + return inverse; +} + +/** + * \brief read keys from keybuf into keys + * \param keybuf buffer containing the keys + * \param keys output key array containing the keys for encryption in + * native endianness + */ +static void multiswap_init(const uint8_t keybuf[48], uint32_t keys[12]) { + int i; + for (i = 0; i < 12; i++) + keys[i] = AV_RL32(keybuf + (i << 2)) | 1; +} + +/** + * \brief invert the keys so that encryption become decryption keys and + * the other way round. + * \param keys key array of ints to invert + */ +static void multiswap_invert_keys(uint32_t keys[12]) { + int i; + for (i = 0; i < 5; i++) + keys[i] = inverse(keys[i]); + for (i = 6; i < 11; i++) + keys[i] = inverse(keys[i]); +} + +static uint32_t multiswap_step(const uint32_t keys[12], uint32_t v) { + int i; + v *= keys[0]; + for (i = 1; i < 5; i++) { + v = (v >> 16) | (v << 16); + v *= keys[i]; + } + v += keys[5]; + return v; +} + +static uint32_t multiswap_inv_step(const uint32_t keys[12], uint32_t v) { + int i; + v -= keys[5]; + for (i = 4; i > 0; i--) { + v *= keys[i]; + v = (v >> 16) | (v << 16); + } + v *= keys[0]; + return v; +} + +/** + * \brief "MultiSwap" encryption + * \param keys 32 bit numbers in machine endianness, + * 0-4 and 6-10 must be inverted from decryption + * \param key another key, this one must be the same for the decryption + * \param data data to encrypt + * \return encrypted data + */ +static uint64_t multiswap_enc(const uint32_t keys[12], uint64_t key, uint64_t data) { + uint32_t a = data; + uint32_t b = data >> 32; + uint32_t c; + uint32_t tmp; + a += key; + tmp = multiswap_step(keys , a); + b += tmp; + c = (key >> 32) + tmp; + tmp = multiswap_step(keys + 6, b); + c += tmp; + return ((uint64_t)c << 32) | tmp; +} + +/** + * \brief "MultiSwap" decryption + * \param keys 32 bit numbers in machine endianness, + * 0-4 and 6-10 must be inverted from encryption + * \param key another key, this one must be the same as for the encryption + * \param data data to decrypt + * \return decrypted data + */ +static uint64_t multiswap_dec(const uint32_t keys[12], uint64_t key, uint64_t data) { + uint32_t a; + uint32_t b; + uint32_t c = data >> 32; + uint32_t tmp = data; + c -= tmp; + b = multiswap_inv_step(keys + 6, tmp); + tmp = c - (key >> 32); + b -= tmp; + a = multiswap_inv_step(keys , tmp); + a -= key; + return ((uint64_t)b << 32) | a; +} + +void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len) { + int num_qwords = len >> 3; + uint64_t *qwords = (uint64_t *)data; + uint64_t rc4buff[8]; + uint64_t packetkey; + uint32_t ms_keys[12]; + uint64_t ms_state; + int i; + if (len < 16) { + for (i = 0; i < len; i++) + data[i] ^= key[i]; + return; + } + + memset(rc4buff, 0, sizeof(rc4buff)); + ff_rc4_enc(key, 12, (uint8_t *)rc4buff, sizeof(rc4buff)); + multiswap_init((uint8_t *)rc4buff, ms_keys); + + packetkey = qwords[num_qwords - 1]; + packetkey ^= rc4buff[7]; + packetkey = be2me_64(packetkey); + packetkey = ff_des_encdec(packetkey, AV_RB64(key + 12), 1); + packetkey = be2me_64(packetkey); + packetkey ^= rc4buff[6]; + + ff_rc4_enc((uint8_t *)&packetkey, 8, data, len); + + ms_state = 0; + for (i = 0; i < num_qwords - 1; i++, qwords++) + ms_state = multiswap_enc(ms_keys, ms_state, AV_RL64(qwords)); + multiswap_invert_keys(ms_keys); + packetkey = (packetkey << 32) | (packetkey >> 32); + packetkey = le2me_64(packetkey); + packetkey = multiswap_dec(ms_keys, ms_state, packetkey); + AV_WL64(qwords, packetkey); +} diff --git a/contrib/ffmpeg/libavformat/asfcrypt.h b/contrib/ffmpeg/libavformat/asfcrypt.h new file mode 100644 index 000000000..dcd9c1da7 --- /dev/null +++ b/contrib/ffmpeg/libavformat/asfcrypt.h @@ -0,0 +1,29 @@ +/* + * ASF decryption + * Copyright (c) 2007 Reimar Doeffinger + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_ASFCRYPT_H +#define FFMPEG_ASFCRYPT_H + +#include + +void ff_asfcrypt_dec(const uint8_t key[20], uint8_t *data, int len); + +#endif /* FFMPEG_ASFCRYPT_H */ diff --git a/contrib/ffmpeg/libavformat/au.c b/contrib/ffmpeg/libavformat/au.c index 9e84c9d31..c6d5026e9 100644 --- a/contrib/ffmpeg/libavformat/au.c +++ b/contrib/ffmpeg/libavformat/au.c @@ -28,7 +28,7 @@ */ #include "avformat.h" -#include "allformats.h" +#include "raw.h" #include "riff.h" /* if we don't know the size in advance */ @@ -37,6 +37,7 @@ /* The ffmpeg codecs we support, and the IDs they have in the file */ static const AVCodecTag codec_au_tags[] = { { CODEC_ID_PCM_MULAW, 1 }, + { CODEC_ID_PCM_S8, 2 }, { CODEC_ID_PCM_S16BE, 3 }, { CODEC_ID_PCM_ALAW, 27 }, { 0, 0 }, @@ -59,7 +60,7 @@ static int put_au_header(ByteIOContext *pb, AVCodecContext *enc) static int au_write_header(AVFormatContext *s) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; s->priv_data = NULL; @@ -75,17 +76,17 @@ static int au_write_header(AVFormatContext *s) static int au_write_packet(AVFormatContext *s, AVPacket *pkt) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; put_buffer(pb, pkt->data, pkt->size); return 0; } static int au_write_trailer(AVFormatContext *s) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; offset_t file_size; - if (!url_is_streamed(&s->pb)) { + if (!url_is_streamed(s->pb)) { /* update file size */ file_size = url_ftell(pb); @@ -103,8 +104,6 @@ static int au_write_trailer(AVFormatContext *s) static int au_probe(AVProbeData *p) { /* check file header */ - if (p->buf_size <= 24) - return 0; if (p->buf[0] == '.' && p->buf[1] == 's' && p->buf[2] == 'n' && p->buf[3] == 'd') return AVPROBE_SCORE_MAX; @@ -118,7 +117,7 @@ static int au_read_header(AVFormatContext *s, { int size; unsigned int tag; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; unsigned int id, codec, channels, rate; AVStream *st; @@ -160,11 +159,11 @@ static int au_read_packet(AVFormatContext *s, { int ret; - if (url_feof(&s->pb)) - return AVERROR_IO; - ret= av_get_packet(&s->pb, pkt, MAX_SIZE); + if (url_feof(s->pb)) + return AVERROR(EIO); + ret= av_get_packet(s->pb, pkt, MAX_SIZE); if (ret < 0) - return AVERROR_IO; + return AVERROR(EIO); pkt->stream_index = 0; /* note: we need to modify the packet size here to handle the last diff --git a/contrib/ffmpeg/libavformat/audio.c b/contrib/ffmpeg/libavformat/audio.c deleted file mode 100644 index a9e5bffd5..000000000 --- a/contrib/ffmpeg/libavformat/audio.c +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Linux audio play and grab interface - * Copyright (c) 2000, 2001 Fabrice Bellard. - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include "avformat.h" - -#include -#include -#include -#ifdef HAVE_SOUNDCARD_H -#include -#else -#include -#endif -#include -#include -#include -#include -#include - -#define AUDIO_BLOCK_SIZE 4096 - -typedef struct { - int fd; - int sample_rate; - int channels; - int frame_size; /* in bytes ! */ - int codec_id; - int flip_left : 1; - uint8_t buffer[AUDIO_BLOCK_SIZE]; - int buffer_ptr; -} AudioData; - -static int audio_open(AudioData *s, int is_output, const char *audio_device) -{ - int audio_fd; - int tmp, err; - char *flip = getenv("AUDIO_FLIP_LEFT"); - - if (is_output) - audio_fd = open(audio_device, O_WRONLY); - else - audio_fd = open(audio_device, O_RDONLY); - if (audio_fd < 0) { - perror(audio_device); - return AVERROR_IO; - } - - if (flip && *flip == '1') { - s->flip_left = 1; - } - - /* non blocking mode */ - if (!is_output) - fcntl(audio_fd, F_SETFL, O_NONBLOCK); - - s->frame_size = AUDIO_BLOCK_SIZE; -#if 0 - tmp = (NB_FRAGMENTS << 16) | FRAGMENT_BITS; - err = ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &tmp); - if (err < 0) { - perror("SNDCTL_DSP_SETFRAGMENT"); - } -#endif - - /* select format : favour native format */ - err = ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &tmp); - -#ifdef WORDS_BIGENDIAN - if (tmp & AFMT_S16_BE) { - tmp = AFMT_S16_BE; - } else if (tmp & AFMT_S16_LE) { - tmp = AFMT_S16_LE; - } else { - tmp = 0; - } -#else - if (tmp & AFMT_S16_LE) { - tmp = AFMT_S16_LE; - } else if (tmp & AFMT_S16_BE) { - tmp = AFMT_S16_BE; - } else { - tmp = 0; - } -#endif - - switch(tmp) { - case AFMT_S16_LE: - s->codec_id = CODEC_ID_PCM_S16LE; - break; - case AFMT_S16_BE: - s->codec_id = CODEC_ID_PCM_S16BE; - break; - default: - av_log(NULL, AV_LOG_ERROR, "Soundcard does not support 16 bit sample format\n"); - close(audio_fd); - return AVERROR_IO; - } - err=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &tmp); - if (err < 0) { - perror("SNDCTL_DSP_SETFMT"); - goto fail; - } - - tmp = (s->channels == 2); - err = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp); - if (err < 0) { - perror("SNDCTL_DSP_STEREO"); - goto fail; - } - if (tmp) - s->channels = 2; - - tmp = s->sample_rate; - err = ioctl(audio_fd, SNDCTL_DSP_SPEED, &tmp); - if (err < 0) { - perror("SNDCTL_DSP_SPEED"); - goto fail; - } - s->sample_rate = tmp; /* store real sample rate */ - s->fd = audio_fd; - - return 0; - fail: - close(audio_fd); - return AVERROR_IO; -} - -static int audio_close(AudioData *s) -{ - close(s->fd); - return 0; -} - -/* sound output support */ -static int audio_write_header(AVFormatContext *s1) -{ - AudioData *s = s1->priv_data; - AVStream *st; - int ret; - - st = s1->streams[0]; - s->sample_rate = st->codec->sample_rate; - s->channels = st->codec->channels; - ret = audio_open(s, 1, NULL); - if (ret < 0) { - return AVERROR_IO; - } else { - return 0; - } -} - -static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt) -{ - AudioData *s = s1->priv_data; - int len, ret; - int size= pkt->size; - uint8_t *buf= pkt->data; - - while (size > 0) { - len = AUDIO_BLOCK_SIZE - s->buffer_ptr; - if (len > size) - len = size; - memcpy(s->buffer + s->buffer_ptr, buf, len); - s->buffer_ptr += len; - if (s->buffer_ptr >= AUDIO_BLOCK_SIZE) { - for(;;) { - ret = write(s->fd, s->buffer, AUDIO_BLOCK_SIZE); - if (ret > 0) - break; - if (ret < 0 && (errno != EAGAIN && errno != EINTR)) - return AVERROR_IO; - } - s->buffer_ptr = 0; - } - buf += len; - size -= len; - } - return 0; -} - -static int audio_write_trailer(AVFormatContext *s1) -{ - AudioData *s = s1->priv_data; - - audio_close(s); - return 0; -} - -/* grab support */ - -static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap) -{ - AudioData *s = s1->priv_data; - AVStream *st; - int ret; - - if (ap->sample_rate <= 0 || ap->channels <= 0) - return -1; - - st = av_new_stream(s1, 0); - if (!st) { - return AVERROR(ENOMEM); - } - s->sample_rate = ap->sample_rate; - s->channels = ap->channels; - - ret = audio_open(s, 0, s1->filename); - if (ret < 0) { - av_free(st); - return AVERROR_IO; - } - - /* take real parameters */ - st->codec->codec_type = CODEC_TYPE_AUDIO; - st->codec->codec_id = s->codec_id; - st->codec->sample_rate = s->sample_rate; - st->codec->channels = s->channels; - - av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ - return 0; -} - -static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt) -{ - AudioData *s = s1->priv_data; - int ret, bdelay; - int64_t cur_time; - struct audio_buf_info abufi; - - if (av_new_packet(pkt, s->frame_size) < 0) - return AVERROR_IO; - for(;;) { - struct timeval tv; - fd_set fds; - - tv.tv_sec = 0; - tv.tv_usec = 30 * 1000; /* 30 msecs -- a bit shorter than 1 frame at 30fps */ - - FD_ZERO(&fds); - FD_SET(s->fd, &fds); - - /* This will block until data is available or we get a timeout */ - (void) select(s->fd + 1, &fds, 0, 0, &tv); - - ret = read(s->fd, pkt->data, pkt->size); - if (ret > 0) - break; - if (ret == -1 && (errno == EAGAIN || errno == EINTR)) { - av_free_packet(pkt); - pkt->size = 0; - pkt->pts = av_gettime(); - return 0; - } - if (!(ret == 0 || (ret == -1 && (errno == EAGAIN || errno == EINTR)))) { - av_free_packet(pkt); - return AVERROR_IO; - } - } - pkt->size = ret; - - /* compute pts of the start of the packet */ - cur_time = av_gettime(); - bdelay = ret; - if (ioctl(s->fd, SNDCTL_DSP_GETISPACE, &abufi) == 0) { - bdelay += abufi.bytes; - } - /* substract time represented by the number of bytes in the audio fifo */ - cur_time -= (bdelay * 1000000LL) / (s->sample_rate * s->channels); - - /* convert to wanted units */ - pkt->pts = cur_time; - - if (s->flip_left && s->channels == 2) { - int i; - short *p = (short *) pkt->data; - - for (i = 0; i < ret; i += 4) { - *p = ~*p; - p += 2; - } - } - return 0; -} - -static int audio_read_close(AVFormatContext *s1) -{ - AudioData *s = s1->priv_data; - - audio_close(s); - return 0; -} - -#ifdef CONFIG_AUDIO_DEMUXER -AVInputFormat audio_demuxer = { - "audio_device", - "audio grab and output", - sizeof(AudioData), - NULL, - audio_read_header, - audio_read_packet, - audio_read_close, - .flags = AVFMT_NOFILE, -}; -#endif - -#ifdef CONFIG_AUDIO_MUXER -AVOutputFormat audio_muxer = { - "audio_device", - "audio grab and output", - "", - "", - sizeof(AudioData), - /* XXX: we make the assumption that the soundcard accepts this format */ - /* XXX: find better solution with "preinit" method, needed also in - other formats */ -#ifdef WORDS_BIGENDIAN - CODEC_ID_PCM_S16BE, -#else - CODEC_ID_PCM_S16LE, -#endif - CODEC_ID_NONE, - audio_write_header, - audio_write_packet, - audio_write_trailer, - .flags = AVFMT_NOFILE, -}; -#endif diff --git a/contrib/ffmpeg/libavformat/avc.c b/contrib/ffmpeg/libavformat/avc.c new file mode 100644 index 000000000..0c180c86b --- /dev/null +++ b/contrib/ffmpeg/libavformat/avc.c @@ -0,0 +1,135 @@ +/* + * AVC helper functions for muxers + * Copyright (c) 2006 Baptiste Coudurier + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avformat.h" +#include "avio.h" + +const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end) +{ + const uint8_t *a = p + 4 - ((long)p & 3); + + for( end -= 3; p < a && p < end; p++ ) { + if( p[0] == 0 && p[1] == 0 && p[2] == 1 ) + return p; + } + + for( end -= 3; p < end; p += 4 ) { + uint32_t x = *(const uint32_t*)p; +// if( (x - 0x01000100) & (~x) & 0x80008000 ) // little endian +// if( (x - 0x00010001) & (~x) & 0x00800080 ) // big endian + if( (x - 0x01010101) & (~x) & 0x80808080 ) { // generic + if( p[1] == 0 ) { + if( p[0] == 0 && p[2] == 1 ) + return p-1; + if( p[2] == 0 && p[3] == 1 ) + return p; + } + if( p[3] == 0 ) { + if( p[2] == 0 && p[4] == 1 ) + return p+1; + if( p[4] == 0 && p[5] == 1 ) + return p+2; + } + } + } + + for( end += 3; p < end; p++ ) { + if( p[0] == 0 && p[1] == 0 && p[2] == 1 ) + return p; + } + + return end + 3; +} + +int ff_avc_parse_nal_units(const uint8_t *buf_in, uint8_t **buf, int *size) +{ + ByteIOContext *pb; + const uint8_t *p = buf_in; + const uint8_t *end = p + *size; + const uint8_t *nal_start, *nal_end; + int ret = url_open_dyn_buf(&pb); + if(ret < 0) + return ret; + + nal_start = ff_avc_find_startcode(p, end); + while (nal_start < end) { + while(!*(nal_start++)); + nal_end = ff_avc_find_startcode(nal_start, end); + put_be32(pb, nal_end - nal_start); + put_buffer(pb, nal_start, nal_end - nal_start); + nal_start = nal_end; + } + av_freep(buf); + *size = url_close_dyn_buf(pb, buf); + return 0; +} + +int ff_isom_write_avcc(ByteIOContext *pb, const uint8_t *data, int len) +{ + if (len > 6) { + /* check for h264 start code */ + if (AV_RB32(data) == 0x00000001) { + uint8_t *buf=NULL, *end, *start; + uint32_t sps_size=0, pps_size=0; + uint8_t *sps=0, *pps=0; + + int ret = ff_avc_parse_nal_units(data, &buf, &len); + if (ret < 0) + return ret; + start = buf; + end = buf + len; + + /* look for sps and pps */ + while (buf < end) { + unsigned int size; + uint8_t nal_type; + size = AV_RB32(buf); + nal_type = buf[4] & 0x1f; + if (nal_type == 7) { /* SPS */ + sps = buf + 4; + sps_size = size; + } else if (nal_type == 8) { /* PPS */ + pps = buf + 4; + pps_size = size; + } + buf += size + 4; + } + assert(sps); + assert(pps); + + put_byte(pb, 1); /* version */ + put_byte(pb, sps[1]); /* profile */ + put_byte(pb, sps[2]); /* profile compat */ + put_byte(pb, sps[3]); /* level */ + put_byte(pb, 0xff); /* 6 bits reserved (111111) + 2 bits nal size length - 1 (11) */ + put_byte(pb, 0xe1); /* 3 bits reserved (111) + 5 bits number of sps (00001) */ + + put_be16(pb, sps_size); + put_buffer(pb, sps, sps_size); + put_byte(pb, 1); /* number of pps */ + put_be16(pb, pps_size); + put_buffer(pb, pps, pps_size); + av_free(start); + } else { + put_buffer(pb, data, len); + } + } + return 0; +} diff --git a/contrib/ffmpeg/libavformat/avc.h b/contrib/ffmpeg/libavformat/avc.h new file mode 100644 index 000000000..334aa4347 --- /dev/null +++ b/contrib/ffmpeg/libavformat/avc.h @@ -0,0 +1,32 @@ +/* + * AVC helper functions for muxers + * Copyright (c) 2008 Aurelien Jacobs + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVC_H +#define AVC_H + +#include +#include "avio.h" + +int ff_avc_parse_nal_units(const uint8_t *buf_in, uint8_t **buf, int *size); +int ff_isom_write_avcc(ByteIOContext *pb, const uint8_t *data, int len); +const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end); + +#endif /* AVC_H */ diff --git a/contrib/ffmpeg/libavformat/avformat.h b/contrib/ffmpeg/libavformat/avformat.h index eb8c4e153..ad186e443 100644 --- a/contrib/ffmpeg/libavformat/avformat.h +++ b/contrib/ffmpeg/libavformat/avformat.h @@ -18,22 +18,26 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVFORMAT_H -#define AVFORMAT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define LIBAVFORMAT_VERSION_INT ((51<<16)+(11<<8)+0) -#define LIBAVFORMAT_VERSION 51.11.0 +#ifndef FFMPEG_AVFORMAT_H +#define FFMPEG_AVFORMAT_H + +#define LIBAVFORMAT_VERSION_MAJOR 52 +#define LIBAVFORMAT_VERSION_MINOR 7 +#define LIBAVFORMAT_VERSION_MICRO 0 + +#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ + LIBAVFORMAT_VERSION_MINOR, \ + LIBAVFORMAT_VERSION_MICRO) +#define LIBAVFORMAT_VERSION AV_VERSION(LIBAVFORMAT_VERSION_MAJOR, \ + LIBAVFORMAT_VERSION_MINOR, \ + LIBAVFORMAT_VERSION_MICRO) #define LIBAVFORMAT_BUILD LIBAVFORMAT_VERSION_INT #define LIBAVFORMAT_IDENT "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION) #include #include /* FILE */ -#include "avcodec.h" +#include "libavcodec/avcodec.h" #include "avio.h" @@ -60,20 +64,15 @@ void av_destruct_packet_nofree(AVPacket *pkt); */ void av_destruct_packet(AVPacket *pkt); -/* initialize optional fields of a packet */ -static inline void av_init_packet(AVPacket *pkt) -{ - pkt->pts = AV_NOPTS_VALUE; - pkt->dts = AV_NOPTS_VALUE; - pkt->pos = -1; - pkt->duration = 0; - pkt->flags = 0; - pkt->stream_index = 0; - pkt->destruct= av_destruct_packet_nofree; -} +/** + * Initialize optional fields of a packet to default values. + * + * @param pkt packet + */ +void av_init_packet(AVPacket *pkt); /** - * Allocate the payload of a packet and intialized its fields to default values. + * Allocate the payload of a packet and initialize its fields to default values. * * @param pkt packet * @param size wanted payload size @@ -82,7 +81,7 @@ static inline void av_init_packet(AVPacket *pkt) int av_new_packet(AVPacket *pkt, int size); /** - * Allocate and read the payload of a packet and intialized its fields to default values. + * Allocate and read the payload of a packet and initialize its fields to default values. * * @param pkt packet * @param size wanted payload size @@ -111,8 +110,11 @@ static inline void av_free_packet(AVPacket *pkt) /*************************************************/ /* fractional numbers for exact pts handling */ -/* the exact value of the fractional number is: 'val + num / den'. num - is assumed to be such as 0 <= num < den */ +/** + * the exact value of the fractional number is: 'val + num / den'. + * num is assumed to be such as 0 <= num < den + * @deprecated Use AVRational instead +*/ typedef struct AVFrac { int64_t val, num, den; } AVFrac attribute_deprecated; @@ -132,6 +134,7 @@ typedef struct AVProbeData { } AVProbeData; #define AVPROBE_SCORE_MAX 100 ///< max score, half of that is used for file extension based detection +#define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer typedef struct AVFormatParameters { AVRational time_base; @@ -141,19 +144,18 @@ typedef struct AVFormatParameters { int height; enum PixelFormat pix_fmt; int channel; /**< used to select dv channel */ -#if LIBAVFORMAT_VERSION_INT < (52<<16) - const char *device; /**< video, audio or DV device */ -#endif const char *standard; /**< tv standard, NTSC, PAL, SECAM */ int mpeg2ts_raw:1; /**< force raw MPEG2 transport stream output, if possible */ int mpeg2ts_compute_pcr:1; /**< compute exact PCR for each transport stream packet (only meaningful if - mpeg2ts_raw is TRUE */ + mpeg2ts_raw is TRUE) */ int initial_pause:1; /**< do not begin to play the stream immediately (RTSP only) */ int prealloced_context:1; +#if LIBAVFORMAT_VERSION_INT < (53<<16) enum CodecID video_codec_id; enum CodecID audio_codec_id; +#endif } AVFormatParameters; //! demuxer will use url_fopen, no opened file should be provided by the caller @@ -163,7 +165,7 @@ typedef struct AVFormatParameters { #define AVFMT_RAWPICTURE 0x0020 /**< format wants AVPicture structure for raw picture data */ #define AVFMT_GLOBALHEADER 0x0040 /**< format wants global header */ -#define AVFMT_NOTIMESTAMPS 0x0080 /**< format doesnt need / has any timestamps */ +#define AVFMT_NOTIMESTAMPS 0x0080 /**< format does not need / have any timestamps */ #define AVFMT_GENERIC_INDEX 0x0100 /**< use generic index building code */ typedef struct AVOutputFormat { @@ -191,6 +193,8 @@ typedef struct AVOutputFormat { */ const struct AVCodecTag **codec_tag; + enum CodecID subtitle_codec; /**< default subtitle codec */ + /* private fields */ struct AVOutputFormat *next; } AVOutputFormat; @@ -200,11 +204,15 @@ typedef struct AVInputFormat { const char *long_name; /** size of private data so that it can be allocated in the wrapper */ int priv_data_size; - /** tell if a given file has a chance of being parsing by this format */ + /** + * Tell if a given file has a chance of being parsed by this format. + * The buffer provided is guaranteed to be AVPROBE_PADDING_SIZE bytes + * big so you do not have to check for that unless you need more. + */ int (*read_probe)(AVProbeData *); /** read the format header and initialize the AVFormatContext structure. Return 0 if OK. 'ap' if non NULL contains - additionnal paramters. Only used in raw format right + additional paramters. Only used in raw format right now. 'av_new_stream' should be called to create new streams. */ int (*read_header)(struct AVFormatContext *, AVFormatParameters *ap); @@ -221,11 +229,13 @@ typedef struct AVInputFormat { * @param stream_index must not be -1 * @param flags selects which direction should be preferred if no exact * match is available + * @return >= 0 on success (but not necessarily the new offset) */ int (*read_seek)(struct AVFormatContext *, int stream_index, int64_t timestamp, int flags); /** - * gets the next timestamp in AV_TIME_BASE units. + * gets the next timestamp in stream[stream_index].time_base units. + * @return the timestamp or AV_NOPTS_VALUE if an error occured */ int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index, int64_t *pos, int64_t pos_limit); @@ -252,63 +262,84 @@ typedef struct AVInputFormat { struct AVInputFormat *next; } AVInputFormat; +enum AVStreamParseType { + AVSTREAM_PARSE_NONE, + AVSTREAM_PARSE_FULL, /**< full parsing and repack */ + AVSTREAM_PARSE_HEADERS, /**< only parse headers, don't repack */ + AVSTREAM_PARSE_TIMESTAMPS, /**< full parsing and interpolation of timestamps for frames not starting on packet boundary */ +}; + typedef struct AVIndexEntry { int64_t pos; int64_t timestamp; #define AVINDEX_KEYFRAME 0x0001 int flags:2; - int size:30; //yeah trying to keep the size of this small to reduce memory requirements (its 24 vs 32 byte due to possible 8byte align) + int size:30; //Yeah, trying to keep the size of this small to reduce memory requirements (it is 24 vs 32 byte due to possible 8byte align). int min_distance; /**< min distance between this and the previous keyframe, used to avoid unneeded searching */ } AVIndexEntry; +/** + * Stream structure. + * New fields can be added to the end with minor version bumps. + * Removal, reordering and changes to existing fields require a major + * version bump. + * sizeof(AVStream) must not be used outside libav*. + */ typedef struct AVStream { int index; /**< stream index in AVFormatContext */ int id; /**< format specific stream id */ AVCodecContext *codec; /**< codec context */ /** - * real base frame rate of the stream. - * this is the lowest framerate with which all timestamps can be - * represented accurately (its the least common multiple of all - * framerates in the stream), Note, this value is just a guess! - * for example if the timebase is 1/90000 and all frames have either - * approximately 3600 or 1800 timer ticks then r_frame_rate will be 50/1 + * Real base frame rate of the stream. + * This is the lowest frame rate with which all timestamps can be + * represented accurately (it is the least common multiple of all + * frame rates in the stream), Note, this value is just a guess! + * For example if the timebase is 1/90000 and all frames have either + * approximately 3600 or 1800 timer ticks then r_frame_rate will be 50/1. */ AVRational r_frame_rate; void *priv_data; -#if LIBAVFORMAT_VERSION_INT < (52<<16) + /* internal data used in av_find_stream_info() */ - int64_t codec_info_duration; - int codec_info_nb_frames; -#endif + int64_t first_dts; /** encoding: PTS generation when outputing stream */ - AVFrac pts; + struct AVFrac pts; /** - * this is the fundamental unit of time (in seconds) in terms - * of which frame timestamps are represented. for fixed-fps content, - * timebase should be 1/framerate and timestamp increments should be + * This is the fundamental unit of time (in seconds) in terms + * of which frame timestamps are represented. For fixed-fps content, + * timebase should be 1/frame rate and timestamp increments should be * identically 1. */ AVRational time_base; int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */ /* ffmpeg.c private use */ int stream_copy; /**< if set, just copy stream */ - enum AVDiscard discard; ///< selects which packets can be discarded at will and dont need to be demuxed + enum AVDiscard discard; ///< selects which packets can be discarded at will and do not need to be demuxed //FIXME move stuff to a flags field? /** quality, as it has been removed from AVCodecContext and put in AVVideoFrame - * MN:dunno if thats the right place, for it */ + * MN: dunno if that is the right place for it */ float quality; - /** decoding: position of the first frame of the component, in - AV_TIME_BASE fractional seconds. */ + /** + * Decoding: pts of the first frame of the stream, in stream time base. + * Only set this if you are absolutely 100% sure that the value you set + * it to really is the pts of the first frame. + * This may be undefined (AV_NOPTS_VALUE). + * @note The ASF header does NOT contain a correct start_time the ASF + * demuxer must NOT set this. + */ int64_t start_time; - /** decoding: duration of the stream, in AV_TIME_BASE fractional - seconds. */ + /** + * Decoding: duration of the stream, in stream time base. + * If a source file does not specify a duration, but does specify + * a bitrate, this value will be estimates from bit rate and file size. + */ int64_t duration; char language[4]; /** ISO 639 3-letter language code (empty string if undefined) */ /* av_read_frame() support */ - int need_parsing; ///< 1->full parsing needed, 2->only parse headers dont repack + enum AVStreamParseType need_parsing; struct AVCodecParserContext *parser; int64_t cur_dts; @@ -324,21 +355,47 @@ typedef struct AVStream { #define MAX_REORDER_DELAY 4 int64_t pts_buffer[MAX_REORDER_DELAY+1]; + + char *filename; /**< source filename of the stream */ } AVStream; +#define AV_PROGRAM_RUNNING 1 + +/** + * New fields can be added to the end with minor version bumps. + * Removal, reordering and changes to existing fields require a major + * version bump. + * sizeof(AVProgram) must not be used outside libav*. + */ +typedef struct AVProgram { + int id; + char *provider_name; ///< Network name for DVB streams + char *name; ///< Service name for DVB streams + int flags; + enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller + unsigned int *stream_index; + unsigned int nb_stream_indexes; +} AVProgram; + #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present (streams are added dynamically) */ #define MAX_STREAMS 20 -/* format I/O context */ +/** + * format I/O context. + * New fields can be added to the end with minor version bumps. + * Removal, reordering and changes to existing fields require a major + * version bump. + * sizeof(AVFormatContext) must not be used outside libav*. + */ typedef struct AVFormatContext { const AVClass *av_class; /**< set by av_alloc_format_context */ /* can only be iformat or oformat, not both at the same time */ struct AVInputFormat *iformat; struct AVOutputFormat *oformat; void *priv_data; - ByteIOContext pb; + ByteIOContext *pb; unsigned int nb_streams; AVStream *streams[MAX_STREAMS]; char filename[1024]; /**< input or output filename */ @@ -398,6 +455,7 @@ typedef struct AVFormatContext { int flags; #define AVFMT_FLAG_GENPTS 0x0001 ///< generate pts if missing even if it requires parsing future frames #define AVFMT_FLAG_IGNIDX 0x0002 ///< ignore index +#define AVFMT_FLAG_NONBLOCK 0x0004 ///< do not block when reading packets from input int loop_input; /** decoding: size of data to probe; encoding unused */ @@ -410,6 +468,37 @@ typedef struct AVFormatContext { const uint8_t *key; int keylen; + + unsigned int nb_programs; + AVProgram **programs; + + /** + * Forced video codec_id. + * demuxing: set by user + */ + enum CodecID video_codec_id; + /** + * Forced audio codec_id. + * demuxing: set by user + */ + enum CodecID audio_codec_id; + /** + * Forced subtitle codec_id. + * demuxing: set by user + */ + enum CodecID subtitle_codec_id; + + /** + * Maximum amount of memory in bytes to use per stream for the index. + * If the needed index exceeds this size entries will be discarded as + * needed to maintain a smaller size. This can lead to slower or less + * accurate seeking (depends on demuxer). + * Demuxers for which a full in memory index is mandatory will ignore + * this. + * muxing : unused + * demuxing: set by user + */ + unsigned int max_index_size; } AVFormatContext; typedef struct AVPacketList { @@ -417,18 +506,19 @@ typedef struct AVPacketList { struct AVPacketList *next; } AVPacketList; +#if LIBAVFORMAT_VERSION_INT < (53<<16) extern AVInputFormat *first_iformat; extern AVOutputFormat *first_oformat; +#endif + +AVInputFormat *av_iformat_next(AVInputFormat *f); +AVOutputFormat *av_oformat_next(AVOutputFormat *f); enum CodecID av_guess_image2_codec(const char *filename); /* XXX: use automatic init with either ELF sections or C file parser */ /* modules */ -#include "rtp.h" - -#include "rtsp.h" - /* utils.c */ void av_register_input_format(AVInputFormat *format); void av_register_output_format(AVOutputFormat *format); @@ -519,21 +609,25 @@ int av_open_input_stream(AVFormatContext **ic_ptr, AVInputFormat *fmt, AVFormatParameters *ap); /** - * Open a media file as input. The codec are not opened. Only the file + * Open a media file as input. The codecs are not opened. Only the file * header (if present) is read. * * @param ic_ptr the opened media file handle is put here * @param filename filename to open. * @param fmt if non NULL, force the file format to use * @param buf_size optional buffer size (zero if default is OK) - * @param ap additionnal parameters needed when opening the file (NULL if default) + * @param ap additional parameters needed when opening the file (NULL if default) * @return 0 if OK. AVERROR_xxx otherwise. */ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, AVInputFormat *fmt, int buf_size, AVFormatParameters *ap); -/** no av_open for output, so applications will need this: */ +/** + * Allocate an AVFormatContext. + * Can be freed with av_free() but do not forget to free everything you + * explicitly allocated as well! + */ AVFormatContext *av_alloc_format_context(void); /** @@ -546,14 +640,14 @@ AVFormatContext *av_alloc_format_context(void); * * @param ic media file handle * @return >=0 if OK. AVERROR_xxx if error. - * @todo let user decide somehow what information is needed so we dont waste time geting stuff the user doesnt need + * @todo Let user decide somehow what information is needed so we do not waste time getting stuff the user does not need. */ int av_find_stream_info(AVFormatContext *ic); /** * Read a transport packet from a media file. * - * This function is absolete and should never be used. + * This function is obsolete and should never be used. * Use av_read_frame() instead. * * @param s media file handle @@ -609,6 +703,12 @@ int av_read_play(AVFormatContext *s); */ int av_read_pause(AVFormatContext *s); +/** + * Free a AVFormatContext allocated by av_open_input_stream. + * @param s context to free + */ +void av_close_input_stream(AVFormatContext *s); + /** * Close a media file (but not its codecs). * @@ -627,6 +727,7 @@ void av_close_input_file(AVFormatContext *s); * @param id file format dependent stream id */ AVStream *av_new_stream(AVFormatContext *s, int id); +AVProgram *av_new_program(AVFormatContext *s, int id); /** * Set the pts for a given stream. @@ -656,6 +757,15 @@ int av_find_default_stream_index(AVFormatContext *s); */ int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags); +/** + * Ensures the index uses less memory than the maximum specified in + * AVFormatContext.max_index_size, by discarding entries if it grows + * too large. + * This function is not part of the public API and should only be called + * by demuxers. + */ +void ff_reduce_index(AVFormatContext *s, int stream_index); + /** * Add a index entry into a sorted list updateing if it is already there. * @@ -666,7 +776,7 @@ int av_add_index_entry(AVStream *st, /** * Does a binary search using av_index_search_timestamp() and AVCodec.read_timestamp(). - * this isnt supposed to be called directly by a user application, but by demuxers + * This is not supposed to be called directly by a user application, but by demuxers. * @param target_ts target timestamp in the time base of the given stream * @param stream_index stream number */ @@ -676,7 +786,7 @@ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts * Updates cur_dts of all streams based on given timestamp and AVStream. * * Stream ref_st unchanged, others set cur_dts in their native timebase - * only needed for timestamp wrapping or if (dts not set and pts!=dts) + * only needed for timestamp wrapping or if (dts not set and pts!=dts). * @param timestamp new dts expressed in time_base of param ref_st * @param ref_st reference stream giving time_base of param timestamp */ @@ -684,7 +794,7 @@ void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp); /** * Does a binary search using read_timestamp(). - * this isnt supposed to be called directly by a user application, but by demuxers + * This is not supposed to be called directly by a user application, but by demuxers. * @param target_ts target timestamp in the time base of the given stream * @param stream_index stream number */ @@ -694,8 +804,8 @@ int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, i int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap); /** - * allocate the stream private data and write the stream header to an - * output media file + * Allocate the stream private data and write the stream header to an + * output media file. * * @param s media file handle * @return 0 if OK. AVERROR_xxx if error. @@ -720,10 +830,10 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt); * * The packet must contain one audio or video frame. * If the packets are already correctly interleaved the application should - * call av_write_frame() instead as its slightly faster, its also important - * to keep in mind that completly non interleaved input will need huge amounts - * of memory to interleave with this, so its prefereable to interleave at the - * demuxer level + * call av_write_frame() instead as it is slightly faster. It is also important + * to keep in mind that completely non-interleaved input will need huge amounts + * of memory to interleave with this, so it is preferable to interleave at the + * demuxer level. * * @param s media file handle * @param pkt the packet, which contains the stream_index, buf/buf_size, dts/pts, ... @@ -763,28 +873,41 @@ void dump_format(AVFormatContext *ic, /** * parses width and height out of string str. + * @deprecated Use av_parse_video_frame_size instead. */ -int parse_image_size(int *width_ptr, int *height_ptr, const char *str); +attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr, const char *str); /** * Converts frame rate from string to a fraction. + * @deprecated Use av_parse_video_frame_rate instead. */ -int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg); +attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base, const char *arg); /** - * Converts date string to number of seconds since Jan 1st, 1970. - * + * Parses \p datestr and returns a corresponding number of microseconds. + * @param datestr String representing a date or a duration. + * - If a date the syntax is: * @code - * Syntax: - * - If not a duration: * [{YYYY-MM-DD|YYYYMMDD}]{T| }{HH[:MM[:SS[.m...]]][Z]|HH[MM[SS[.m...]]][Z]} - * Time is localtime unless Z is suffixed to the end. In this case GMT - * Return the date in micro seconds since 1970 - * - * - If a duration: - * HH[:MM[:SS[.m...]]] - * S+[.m...] * @endcode + * Time is localtime unless Z is appended, in which case it is + * interpreted as UTC. + * If the year-month-day part isn't specified it takes the current + * year-month-day. + * Returns the number of microseconds since 1st of January, 1970 up to + * the time of the parsed date or INT64_MIN if \p datestr cannot be + * successfully parsed. + * - If a duration the syntax is: + * @code + * [-]HH[:MM[:SS[.m...]]] + * [-]S+[.m...] + * @endcode + * Returns the number of microseconds contained in a time interval + * with the specified duration or INT64_MIN if \p datestr cannot be + * successfully parsed. + * @param duration Flag which tells how to interpret \p datestr, if + * not zero \p datestr is interpreted as a duration, otherwise as a + * date. */ int64_t parse_date(const char *datestr, int duration); @@ -813,7 +936,7 @@ int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info); * @param buf destination buffer * @param buf_size destination buffer size * @param path numbered sequence string - * @number frame number + * @param number frame number * @return 0 if OK, -1 if format error. */ int av_get_frame_filename(char *buf, int buf_size, @@ -827,23 +950,24 @@ int av_get_frame_filename(char *buf, int buf_size, */ int av_filename_number_test(const char *filename); -/* grab specific */ -int video_grab_init(void); -int audio_init(void); - -/* DV1394 */ -int dv1394_init(void); -int dc1394_init(void); +/** + * Generate an SDP for an RTP session. + * + * @param ac array of AVFormatContexts describing the RTP streams. If the + * array is composed by only one context, such context can contain + * multiple AVStreams (one AVStream per RTP stream). Otherwise, + * all the contexts in the array (an AVCodecContext per RTP stream) + * must contain only one AVStream + * @param n_files number of AVCodecContexts contained in ac + * @param buff buffer where the SDP will be stored (must be allocated by + * the caller + * @param size the size of the buffer + * @return 0 if OK. AVERROR_xxx if error. + */ +int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size); #ifdef HAVE_AV_CONFIG_H -#include "os_support.h" - -int strstart(const char *str, const char *val, const char **ptr); -int stristart(const char *str, const char *val, const char **ptr); -void pstrcpy(char *buf, int buf_size, const char *str); -char *pstrcat(char *buf, int buf_size, const char *s); - void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem); #ifdef __GNUC__ @@ -880,9 +1004,4 @@ int match_ext(const char *filename, const char *extensions); #endif /* HAVE_AV_CONFIG_H */ -#ifdef __cplusplus -} -#endif - -#endif /* AVFORMAT_H */ - +#endif /* FFMPEG_AVFORMAT_H */ diff --git a/contrib/ffmpeg/libavformat/avidec.c b/contrib/ffmpeg/libavformat/avidec.c index 23c130ab7..4b9bcf2a4 100644 --- a/contrib/ffmpeg/libavformat/avidec.c +++ b/contrib/ffmpeg/libavformat/avidec.c @@ -48,6 +48,7 @@ typedef struct AVIStream { typedef struct { int64_t riff_end; int64_t movi_end; + int64_t fsize; offset_t movi_list; int index_loaded; int is_odml; @@ -56,6 +57,15 @@ typedef struct { DVDemuxContext* dv_demux; } AVIContext; +static const char avi_headers[][8] = { + { 'R', 'I', 'F', 'F', 'A', 'V', 'I', ' ' }, + { 'R', 'I', 'F', 'F', 'A', 'V', 'I', 'X' }, + { 'R', 'I', 'F', 'F', 'A', 'V', 'I', 0x19}, + { 'O', 'N', '2', ' ', 'O', 'N', '2', 'f' }, + { 'R', 'I', 'F', 'F', 'A', 'M', 'V', ' ' }, + { 0 } +}; + static int avi_load_index(AVFormatContext *s); static int guess_ni_flag(AVFormatContext *s); @@ -73,27 +83,30 @@ static void print_tag(const char *str, unsigned int tag, int size) static int get_riff(AVIContext *avi, ByteIOContext *pb) { - uint32_t tag; - /* check RIFF header */ - tag = get_le32(pb); + char header[8]; + int i; - if (tag != MKTAG('R', 'I', 'F', 'F')) - return -1; + /* check RIFF header */ + get_buffer(pb, header, 4); avi->riff_end = get_le32(pb); /* RIFF chunk size */ avi->riff_end += url_ftell(pb); /* RIFF chunk end */ - tag = get_le32(pb); - if(tag == MKTAG('A', 'V', 'I', 0x19)) - av_log(NULL, AV_LOG_INFO, "file has been generated with a totally broken muxer\n"); - else - if (tag != MKTAG('A', 'V', 'I', ' ') && tag != MKTAG('A', 'V', 'I', 'X')) + get_buffer(pb, header+4, 4); + + for(i=0; avi_headers[i][0]; i++) + if(!memcmp(header, avi_headers[i], 8)) + break; + if(!avi_headers[i][0]) return -1; + if(header[7] == 0x19) + av_log(NULL, AV_LOG_INFO, "file has been generated with a totally broken muxer\n"); + return 0; } static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){ AVIContext *avi = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int longs_pre_entry= get_le16(pb); int index_sub_type = get_byte(pb); int index_type = get_byte(pb); @@ -105,7 +118,7 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){ AVIStream *ast; int i; int64_t last_pos= -1; - int64_t filesize= url_fsize(&s->pb); + int64_t filesize= url_fsize(s->pb); #ifdef DEBUG_SEEK av_log(s, AV_LOG_ERROR, "longs_pre_entry:%d index_type:%d entries_in_use:%d chunk_id:%X base:%16"PRIX64"\n", @@ -212,7 +225,7 @@ static int avi_read_tag(ByteIOContext *pb, char *buf, int maxlen, unsigned int static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) { AVIContext *avi = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; uint32_t tag, tag1, handler; int codec_type, stream_index, frame_period, bit_rate; unsigned int size, nb_frames; @@ -220,12 +233,18 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) AVStream *st; AVIStream *ast = NULL; char str_track[4]; + int avih_width=0, avih_height=0; + int amv_file_format=0; avi->stream_index= -1; if (get_riff(avi, pb) < 0) return -1; + avi->fsize = url_fsize(pb); + if(avi->fsize<=0) + avi->fsize= avi->riff_end; + /* first list tag */ stream_index = -1; codec_type = -1; @@ -260,6 +279,8 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) avi->is_odml = 1; url_fskip(pb, size + (size & 1)); break; + case MKTAG('a', 'm', 'v', 'h'): + amv_file_format=1; case MKTAG('a', 'v', 'i', 'h'): /* avi header */ /* using frame_period is bad idea */ @@ -270,8 +291,11 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) url_fskip(pb, 2 * 4); get_le32(pb); + get_le32(pb); + avih_width=get_le32(pb); + avih_height=get_le32(pb); - url_fskip(pb, size - 7 * 4); + url_fskip(pb, size - 10 * 4); break; case MKTAG('s', 't', 'r', 'h'): /* stream header */ @@ -293,6 +317,8 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) goto fail; st->priv_data = ast; } + if(amv_file_format) + tag1 = stream_index ? MKTAG('a','u','d','s') : MKTAG('v','i','d','s'); #ifdef DEBUG print_tag("strh", tag1, -1); @@ -400,6 +426,14 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) st = s->streams[stream_index]; switch(codec_type) { case CODEC_TYPE_VIDEO: + if(amv_file_format){ + st->codec->width=avih_width; + st->codec->height=avih_height; + st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_AMV; + url_fskip(pb, size); + break; + } get_le32(pb); /* size */ st->codec->width = get_le32(pb); st->codec->height = get_le32(pb); @@ -412,6 +446,13 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) get_le32(pb); /* ClrUsed */ get_le32(pb); /* ClrImportant */ + if (tag1 == MKTAG('D', 'X', 'S', 'B')) { + st->codec->codec_type = CODEC_TYPE_SUBTITLE; + st->codec->codec_tag = tag1; + st->codec->codec_id = CODEC_ID_XSUB; + break; + } + if(size > 10*4 && size<(1<<30)){ st->codec->extradata_size= size - 10*4; st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); @@ -442,7 +483,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_tag = tag1; st->codec->codec_id = codec_get_id(codec_bmp_tags, tag1); - st->need_parsing = 2; //only parse headers dont do slower repacketization, this is needed to get the pict type which is needed for generating correct pts + st->need_parsing = AVSTREAM_PARSE_HEADERS; // this is needed to get the pict type which is needed for generating correct pts // url_fskip(pb, size - 5 * 4); break; case CODEC_TYPE_AUDIO: @@ -452,17 +493,19 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) if (size%2) /* 2-aligned (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */ url_fskip(pb, 1); /* Force parsing as several audio frames can be in - * one packet. */ - st->need_parsing = 1; + * one packet and timestamps refer to packet start*/ + st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; /* ADTS header is in extradata, AAC without header must be stored as exact frames, parser not needed and it will fail */ if (st->codec->codec_id == CODEC_ID_AAC && st->codec->extradata_size) - st->need_parsing = 0; + st->need_parsing = AVSTREAM_PARSE_NONE; /* AVI files with Xan DPCM audio (wrongly) declare PCM * audio in the header but have Axan as stream_code_tag. */ if (st->codec->stream_codec_tag == ff_get_fourcc("Axan")){ st->codec->codec_id = CODEC_ID_XAN_DPCM; st->codec->codec_tag = 0; } + if (amv_file_format) + st->codec->codec_id = CODEC_ID_ADPCM_IMA_AMV; break; default: st->codec->codec_type = CODEC_TYPE_DATA; @@ -480,6 +523,31 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) } url_fseek(pb, i+size, SEEK_SET); break; + case MKTAG('v', 'p', 'r', 'p'): + if(stream_index < (unsigned)s->nb_streams && size > 9*4){ + AVRational active, active_aspect; + + st = s->streams[stream_index]; + get_le32(pb); + get_le32(pb); + get_le32(pb); + get_le32(pb); + get_le32(pb); + + active_aspect.num= get_le16(pb); + active_aspect.den= get_le16(pb); + active.num = get_le32(pb); + active.den = get_le32(pb); + get_le32(pb); //nbFieldsPerFrame + + if(active_aspect.num && active_aspect.den && active.num && active.den){ + st->codec->sample_aspect_ratio= av_div_q(active_aspect, active); +//av_log(s, AV_LOG_ERROR, "vprp %d/%d %d/%d\n", active_aspect.num, active_aspect.den, active.num, active.den); + } + size -= 9*4; + } + url_fseek(pb, size, SEEK_CUR); + break; case MKTAG('I', 'N', 'A', 'M'): avi_read_tag(pb, s->title, sizeof(s->title), size); break; @@ -540,7 +608,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) static int avi_read_packet(AVFormatContext *s, AVPacket *pkt) { AVIContext *avi = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int n, d[8], size; offset_t i, sync; void* dstr; @@ -585,7 +653,7 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt) if(i>=0){ int64_t pos= best_st->index_entries[i].pos; pos += best_ast->packet_size - best_ast->remaining; - url_fseek(&s->pb, pos + 8, SEEK_SET); + url_fseek(s->pb, pos + 8, SEEK_SET); // av_log(NULL, AV_LOG_DEBUG, "pos=%"PRId64"\n", pos); assert(best_ast->remaining <= best_ast->packet_size); @@ -662,14 +730,6 @@ resync: for(i=sync=url_ftell(pb); !url_feof(pb); i++) { int j; - if (i >= avi->movi_end) { - if (avi->is_odml) { - url_fskip(pb, avi->riff_end - i); - avi->riff_end = avi->movi_end = url_fsize(pb); - } else - break; - } - for(j=0; j<7; j++) d[j]= d[j+1]; d[7]= get_byte(pb); @@ -683,13 +743,14 @@ resync: n= 100; //invalid stream id } //av_log(NULL, AV_LOG_DEBUG, "%X %X %X %X %X %X %X %X %"PRId64" %d %d\n", d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n); - if(i + size > avi->movi_end || d[0]<0) + if(i + size > avi->fsize || d[0]<0) continue; //parse ix## if( (d[0] == 'i' && d[1] == 'x' && n < s->nb_streams) //parse JUNK - ||(d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K')){ + ||(d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K') + ||(d[0] == 'i' && d[1] == 'd' && d[2] == 'x' && d[3] == '1')){ url_fskip(pb, size); //av_log(NULL, AV_LOG_DEBUG, "SKIP\n"); goto resync; @@ -748,7 +809,7 @@ resync: if ( d[0] >= '0' && d[0] <= '9' && d[1] >= '0' && d[1] <= '9' && ((d[2] == 'p' && d[3] == 'c')) - && n < s->nb_streams && i + size <= avi->movi_end) { + && n < s->nb_streams && i + size <= avi->fsize) { AVStream *st; int first, clr, flags, k, p; @@ -783,7 +844,7 @@ resync: static int avi_read_idx1(AVFormatContext *s, int size) { AVIContext *avi = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int nb_index_entries, i; AVStream *st; AVIStream *ast; @@ -854,7 +915,7 @@ static int guess_ni_flag(AVFormatContext *s){ static int avi_load_index(AVFormatContext *s) { AVIContext *avi = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; uint32_t tag, size; offset_t pos= url_ftell(pb); @@ -929,7 +990,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp /* DV demux so it can synth correct timestamps */ dv_offset_reset(avi->dv_demux, timestamp); - url_fseek(&s->pb, pos, SEEK_SET); + url_fseek(s->pb, pos, SEEK_SET); avi->stream_index= -1; return 0; } @@ -969,7 +1030,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp } /* do the seek */ - url_fseek(&s->pb, pos, SEEK_SET); + url_fseek(s->pb, pos, SEEK_SET); avi->stream_index= -1; return 0; } @@ -994,16 +1055,15 @@ static int avi_read_close(AVFormatContext *s) static int avi_probe(AVProbeData *p) { + int i; + /* check file header */ - if (p->buf_size <= 32) - return 0; - if (p->buf[0] == 'R' && p->buf[1] == 'I' && - p->buf[2] == 'F' && p->buf[3] == 'F' && - p->buf[8] == 'A' && p->buf[9] == 'V' && - p->buf[10] == 'I' && (p->buf[11] == ' ' || p->buf[11] == 0x19)) - return AVPROBE_SCORE_MAX; - else - return 0; + for(i=0; avi_headers[i][0]; i++) + if(!memcmp(p->buf , avi_headers[i] , 4) && + !memcmp(p->buf+8, avi_headers[i]+4, 4)) + return AVPROBE_SCORE_MAX; + + return 0; } AVInputFormat avi_demuxer = { diff --git a/contrib/ffmpeg/libavformat/avienc.c b/contrib/ffmpeg/libavformat/avienc.c index ac8b2670d..6b62f76d8 100644 --- a/contrib/ffmpeg/libavformat/avienc.c +++ b/contrib/ffmpeg/libavformat/avienc.c @@ -105,7 +105,7 @@ static void avi_write_info_tag(ByteIOContext *pb, const char *tag, const char *s static int avi_write_counters(AVFormatContext* s, int riff_id) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVIContext *avi = s->priv_data; int n, au_byterate, au_ssize, au_scale, nb_frames = 0; offset_t file_size; @@ -138,7 +138,7 @@ static int avi_write_counters(AVFormatContext* s, int riff_id) static int avi_write_header(AVFormatContext *s) { AVIContext *avi = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale; AVCodecContext *stream, *video_enc; offset_t list1, list2, strh, strf; @@ -197,11 +197,6 @@ static int avi_write_header(AVFormatContext *s) stream = s->streams[i]->codec; - /* FourCC should really be set by the codec itself */ - if (! stream->codec_tag) { - stream->codec_tag = codec_get_bmp_tag(stream->codec_id); - } - /* stream generic header */ strh = start_tag(pb, "strh"); switch(stream->codec_type) { @@ -337,7 +332,7 @@ static int avi_write_header(AVFormatContext *s) static int avi_write_ix(AVFormatContext *s) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVIContext *avi = s->priv_data; char tag[5]; char ix_tag[] = "ix00"; @@ -394,7 +389,7 @@ static int avi_write_ix(AVFormatContext *s) static int avi_write_idx1(AVFormatContext *s) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVIContext *avi = s->priv_data; offset_t idx_chunk; int i; @@ -440,7 +435,7 @@ static int avi_write_idx1(AVFormatContext *s) static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) { AVIContext *avi = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; unsigned char tag[5]; unsigned int flags=0; const int stream_index= pkt->stream_index; @@ -481,7 +476,7 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) avi->audio_strm_length[stream_index] += size; } - if (!url_is_streamed(&s->pb)) { + if (!url_is_streamed(s->pb)) { AVIIndex* idx = &avi->indexes[stream_index]; int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE; int id = idx->entry % AVI_INDEX_CLUSTER_SIZE; @@ -514,7 +509,7 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) static int avi_write_trailer(AVFormatContext *s) { AVIContext *avi = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int res = 0; int i, j, n, nb_frames; offset_t file_size; diff --git a/contrib/ffmpeg/libavformat/avio.c b/contrib/ffmpeg/libavformat/avio.c index a22bd22f3..5f5bff158 100644 --- a/contrib/ffmpeg/libavformat/avio.c +++ b/contrib/ffmpeg/libavformat/avio.c @@ -19,12 +19,19 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avformat.h" +#include "avstring.h" static int default_interrupt_cb(void); URLProtocol *first_protocol = NULL; URLInterruptCB *url_interrupt_cb = default_interrupt_cb; +URLProtocol *av_protocol_next(URLProtocol *p) +{ + if(p) return p->next; + else return first_protocol; +} + int register_protocol(URLProtocol *protocol) { URLProtocol **p; @@ -75,9 +82,7 @@ int url_open(URLContext **puc, const char *filename, int flags) err = AVERROR(ENOMEM); goto fail; } -#if LIBAVFORMAT_VERSION_INT >= (52<<16) uc->filename = (char *) &uc[1]; -#endif strcpy(uc->filename, filename); uc->prot = up; uc->flags = flags; @@ -100,24 +105,22 @@ int url_read(URLContext *h, unsigned char *buf, int size) { int ret; if (h->flags & URL_WRONLY) - return AVERROR_IO; + return AVERROR(EIO); ret = h->prot->url_read(h, buf, size); return ret; } -#if defined(CONFIG_MUXERS) || defined(CONFIG_PROTOCOLS) int url_write(URLContext *h, unsigned char *buf, int size) { int ret; if (!(h->flags & (URL_WRONLY | URL_RDWR))) - return AVERROR_IO; + return AVERROR(EIO); /* avoid sending too big packets */ if (h->max_packet_size && size > h->max_packet_size) - return AVERROR_IO; + return AVERROR(EIO); ret = h->prot->url_write(h, buf, size); return ret; } -#endif //CONFIG_MUXERS || CONFIG_PROTOCOLS offset_t url_seek(URLContext *h, offset_t pos, int whence) { @@ -131,9 +134,11 @@ offset_t url_seek(URLContext *h, offset_t pos, int whence) int url_close(URLContext *h) { - int ret; + int ret = 0; + if (!h) return 0; /* can happen when url_open fails */ - ret = h->prot->url_close(h); + if (h->prot->url_close) + ret = h->prot->url_close(h); av_free(h); return ret; } @@ -169,7 +174,7 @@ int url_get_max_packet_size(URLContext *h) void url_get_filename(URLContext *h, char *buf, int buf_size) { - pstrcpy(buf, buf_size, h->filename); + av_strlcpy(buf, h->filename, buf_size); } @@ -184,3 +189,18 @@ void url_set_interrupt_cb(URLInterruptCB *interrupt_cb) interrupt_cb = default_interrupt_cb; url_interrupt_cb = interrupt_cb; } + +int av_url_read_pause(URLContext *h, int pause) +{ + if (!h->prot->url_read_pause) + return AVERROR(ENOSYS); + return h->prot->url_read_pause(h, pause); +} + +offset_t av_url_read_seek(URLContext *h, + int stream_index, int64_t timestamp, int flags) +{ + if (!h->prot->url_read_seek) + return AVERROR(ENOSYS); + return h->prot->url_read_seek(h, stream_index, timestamp, flags); +} diff --git a/contrib/ffmpeg/libavformat/avio.h b/contrib/ffmpeg/libavformat/avio.h index be78c9a7b..9443cb017 100644 --- a/contrib/ffmpeg/libavformat/avio.h +++ b/contrib/ffmpeg/libavformat/avio.h @@ -18,8 +18,10 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVIO_H -#define AVIO_H +#ifndef FFMPEG_AVIO_H +#define FFMPEG_AVIO_H + +#include /* output byte stream handling */ @@ -27,17 +29,20 @@ typedef int64_t offset_t; /* unbuffered I/O */ +/** + * URL Context. + * New fields can be added to the end with minor version bumps. + * Removal, reordering and changes to existing fields require a major + * version bump. + * sizeof(URLContext) must not be used outside libav*. + */ struct URLContext { struct URLProtocol *prot; int flags; int is_streamed; /**< true if streamed (no seek possible), default = false */ int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */ void *priv_data; -#if LIBAVFORMAT_VERSION_INT >= (52<<16) char *filename; /**< specified filename */ -#else - char filename[1]; /**< specified filename */ -#endif }; typedef struct URLContext URLContext; @@ -64,7 +69,7 @@ offset_t url_filesize(URLContext *h); /** * Return the maximum packet size associated to packetized file - * handle. If the file is not packetized (stream like http or file on + * handle. If the file is not packetized (stream like HTTP or file on * disk), then 0 is returned. * * @param h file handle @@ -74,10 +79,10 @@ int url_get_max_packet_size(URLContext *h); void url_get_filename(URLContext *h, char *buf, int buf_size); /** - * the callback is called in blocking functions to test regulary if + * The callback is called in blocking functions to test regulary if * asynchronous interruption is needed. AVERROR(EINTR) is returned * in this case by the interrupted function. 'NULL' means no interrupt - * callback is given. i + * callback is given. */ void url_set_interrupt_cb(URLInterruptCB *interrupt_cb); @@ -85,9 +90,36 @@ void url_set_interrupt_cb(URLInterruptCB *interrupt_cb); int url_poll(URLPollEntry *poll_table, int n, int timeout); /** - * passing this as the "whence" parameter to a seek function causes it to - * return the filesize without seeking anywhere, supporting this is optional - * if its not supprted then the seek function will return <0 + * Pause and resume playing - only meaningful if using a network streaming + * protocol (e.g. MMS). + * @param pause 1 for pause, 0 for resume + */ +int av_url_read_pause(URLContext *h, int pause); + +/** + * Seek to a given timestamp relative to some component stream. + * Only meaningful if using a network streaming protocol (e.g. MMS.). + * @param stream_index The stream index that the timestamp is relative to. + * If stream_index is (-1) the timestamp should be in AV_TIME_BASE + * units from the beginning of the presentation. + * If a stream_index >= 0 is used and the protocol does not support + * seeking based on component streams, the call will fail with ENOTSUP. + * @param timestamp timestamp in AVStream.time_base units + * or if there is no stream specified then in AV_TIME_BASE units. + * @param flags Optional combination of AVSEEK_FLAG_BACKWARD, AVSEEK_FLAG_BYTE + * and AVSEEK_FLAG_ANY. The protocol may silently ignore + * AVSEEK_FLAG_BACKWARD and AVSEEK_FLAG_ANY, but AVSEEK_FLAG_BYTE will + * fail with ENOTSUP if used and not supported. + * @return >= 0 on success + * @see AVInputFormat::read_seek + */ +offset_t av_url_read_seek(URLContext *h, + int stream_index, int64_t timestamp, int flags); + +/** + * Passing this as the "whence" parameter to a seek function causes it to + * return the filesize without seeking anywhere. Supporting this is optional. + * If it is not supported then the seek function will return <0. */ #define AVSEEK_SIZE 0x10000 @@ -99,13 +131,25 @@ typedef struct URLProtocol { offset_t (*url_seek)(URLContext *h, offset_t pos, int whence); int (*url_close)(URLContext *h); struct URLProtocol *next; + int (*url_read_pause)(URLContext *h, int pause); + offset_t (*url_read_seek)(URLContext *h, + int stream_index, int64_t timestamp, int flags); } URLProtocol; extern URLProtocol *first_protocol; extern URLInterruptCB *url_interrupt_cb; +URLProtocol *av_protocol_next(URLProtocol *p); + int register_protocol(URLProtocol *protocol); +/** + * Bytestream IO Context. + * New fields can be added to the end with minor version bumps. + * Removal, reordering and changes to existing fields require a major + * version bump. + * sizeof(ByteIOContext) must not be used outside libav*. + */ typedef struct { unsigned char *buffer; int buffer_size; @@ -124,6 +168,9 @@ typedef struct { unsigned char *checksum_ptr; unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size); int error; ///< contains the error code or 0 if no error happened + int (*read_pause)(void *opaque, int pause); + offset_t (*read_seek)(void *opaque, + int stream_index, int64_t timestamp, int flags); } ByteIOContext; int init_put_byte(ByteIOContext *s, @@ -134,6 +181,14 @@ int init_put_byte(ByteIOContext *s, int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), offset_t (*seek)(void *opaque, offset_t offset, int whence)); +ByteIOContext *av_alloc_put_byte( + unsigned char *buffer, + int buffer_size, + int write_flag, + void *opaque, + int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), + int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), + offset_t (*seek)(void *opaque, offset_t offset, int whence)); void put_byte(ByteIOContext *s, int b); void put_buffer(ByteIOContext *s, const unsigned char *buf, int size); @@ -156,6 +211,10 @@ offset_t url_fsize(ByteIOContext *s); int url_feof(ByteIOContext *s); int url_ferror(ByteIOContext *s); +int av_url_read_fpause(ByteIOContext *h, int pause); +offset_t av_url_read_fseek(ByteIOContext *h, + int stream_index, int64_t timestamp, int flags); + #define URL_EOF (-1) /** @note return URL_EOF (-1) if EOF */ int url_fgetc(ByteIOContext *s); @@ -190,19 +249,28 @@ unsigned int get_be24(ByteIOContext *s); unsigned int get_be32(ByteIOContext *s); uint64_t get_be64(ByteIOContext *s); +uint64_t ff_get_v(ByteIOContext *bc); + static inline int url_is_streamed(ByteIOContext *s) { return s->is_streamed; } -int url_fdopen(ByteIOContext *s, URLContext *h); +/** @note when opened as read/write, the buffers are only used for + writing */ +int url_fdopen(ByteIOContext **s, URLContext *h); /** @warning must be called before any I/O */ int url_setbufsize(ByteIOContext *s, int buf_size); +/** Reset the buffer for reading or writing. + * @note Will drop any data currently in the buffer without transmitting it. + * @param flags URL_RDONLY to set up the buffer for reading, or URL_WRONLY + * to set up the buffer for writing. */ +int url_resetbuf(ByteIOContext *s, int flags); /** @note when opened as read/write, the buffers are only used for - reading */ -int url_fopen(ByteIOContext *s, const char *filename, int flags); + writing */ +int url_fopen(ByteIOContext **s, const char *filename, int flags); int url_fclose(ByteIOContext *s); URLContext *url_fileno(ByteIOContext *s); @@ -211,12 +279,12 @@ URLContext *url_fileno(ByteIOContext *s); * handle. If the file is not packetized (stream like http or file on * disk), then 0 is returned. * - * @param h buffered file handle + * @param s buffered file handle * @return maximum packet size in bytes */ int url_fget_max_packet_size(ByteIOContext *s); -int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags); +int url_open_buf(ByteIOContext **s, uint8_t *buf, int buf_size, int flags); /** return the written or read size */ int url_close_buf(ByteIOContext *s); @@ -227,7 +295,7 @@ int url_close_buf(ByteIOContext *s); * @param s new IO context * @return zero if no error. */ -int url_open_dyn_buf(ByteIOContext *s); +int url_open_dyn_buf(ByteIOContext **s); /** * Open a write only packetized memory stream with a maximum packet @@ -238,35 +306,24 @@ int url_open_dyn_buf(ByteIOContext *s); * @param max_packet_size maximum packet size (must be > 0) * @return zero if no error. */ -int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size); +int url_open_dyn_packet_buf(ByteIOContext **s, int max_packet_size); /** * Return the written size and a pointer to the buffer. The buffer * must be freed with av_free(). * @param s IO context - * @param pointer to a byte buffer + * @param pbuffer pointer to a byte buffer * @return the length of the byte buffer */ int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer); +unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len); unsigned long get_checksum(ByteIOContext *s); void init_checksum(ByteIOContext *s, unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum); -/* file.c */ -extern URLProtocol file_protocol; -extern URLProtocol pipe_protocol; - /* udp.c */ -extern URLProtocol udp_protocol; int udp_set_remote_url(URLContext *h, const char *uri); int udp_get_local_port(URLContext *h); int udp_get_file_handle(URLContext *h); -/* tcp.c */ -extern URLProtocol tcp_protocol; - -/* http.c */ -extern URLProtocol http_protocol; - -#endif - +#endif /* FFMPEG_AVIO_H */ diff --git a/contrib/ffmpeg/libavformat/aviobuf.c b/contrib/ffmpeg/libavformat/aviobuf.c index 2cc247b62..3917270b1 100644 --- a/contrib/ffmpeg/libavformat/aviobuf.c +++ b/contrib/ffmpeg/libavformat/aviobuf.c @@ -20,6 +20,7 @@ */ #include "avformat.h" #include "avio.h" +#include "crc.h" #include #define IO_BUFFER_SIZE 32768 @@ -38,11 +39,7 @@ int init_put_byte(ByteIOContext *s, s->buffer = buffer; s->buffer_size = buffer_size; s->buf_ptr = buffer; - s->write_flag = write_flag; - if (!s->write_flag) - s->buf_end = buffer; - else - s->buf_end = buffer + buffer_size; + url_resetbuf(s, write_flag ? URL_WRONLY : URL_RDONLY); s->opaque = opaque; s->write_packet = write_packet; s->read_packet = read_packet; @@ -58,9 +55,25 @@ int init_put_byte(ByteIOContext *s, s->pos = buffer_size; s->buf_end = s->buffer + buffer_size; } + s->read_pause = NULL; + s->read_seek = NULL; return 0; } +ByteIOContext *av_alloc_put_byte( + unsigned char *buffer, + int buffer_size, + int write_flag, + void *opaque, + int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), + int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), + offset_t (*seek)(void *opaque, offset_t offset, int whence)) { + ByteIOContext *s = av_mallocz(sizeof(ByteIOContext)); + init_put_byte(s, buffer, buffer_size, write_flag, opaque, + read_packet, write_packet, seek); + return s; +} + static void flush_buffer(ByteIOContext *s) { if (s->buf_ptr > s->buffer) { @@ -114,7 +127,12 @@ void put_flush_packet(ByteIOContext *s) offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence) { offset_t offset1; - offset_t pos= s->pos - (s->write_flag ? 0 : (s->buf_end - s->buffer)); + offset_t pos; + + if(!s) + return AVERROR(EINVAL); + + pos = s->pos - (s->write_flag ? 0 : (s->buf_end - s->buffer)); if (whence != SEEK_CUR && whence != SEEK_SET) return AVERROR(EINVAL); @@ -134,6 +152,8 @@ offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence) offset1 >= 0 && offset1 < (s->buf_end - s->buffer) + (1<<16)){ while(s->pos < offset && !s->eof_reached) fill_buffer(s); + if (s->eof_reached) + return AVERROR(EPIPE); s->buf_ptr = s->buf_end + offset - s->pos; } else { offset_t res = AVERROR(EPIPE); @@ -170,6 +190,9 @@ offset_t url_fsize(ByteIOContext *s) { offset_t size; + if(!s) + return AVERROR(EINVAL); + if (!s->seek) return AVERROR(EPIPE); size = s->seek(s->opaque, 0, AVSEEK_SIZE); @@ -184,11 +207,15 @@ offset_t url_fsize(ByteIOContext *s) int url_feof(ByteIOContext *s) { + if(!s) + return 0; return s->eof_reached; } int url_ferror(ByteIOContext *s) { + if(!s) + return 0; return s->error; } @@ -263,7 +290,7 @@ void put_tag(ByteIOContext *s, const char *tag) static void fill_buffer(ByteIOContext *s) { - int len; + int len=0; /* no need to do anything if EOF already reached */ if (s->eof_reached) @@ -275,13 +302,14 @@ static void fill_buffer(ByteIOContext *s) s->checksum_ptr= s->buffer; } - len = s->read_packet(s->opaque, s->buffer, s->buffer_size); + if(s->read_packet) + len = s->read_packet(s->opaque, s->buffer, s->buffer_size); if (len <= 0) { /* do not modify buffer if EOF reached so that a seek back can be done without rereading data */ s->eof_reached = 1; - if(len<0) - s->error= len; + if(len<0) + s->error= len; } else { s->pos += len; s->buf_ptr = s->buffer; @@ -289,6 +317,10 @@ static void fill_buffer(ByteIOContext *s) } } +unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len){ + return av_crc(av_crc_get_table(AV_CRC_32_IEEE), checksum, buf, len); +} + unsigned long get_checksum(ByteIOContext *s){ s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr - s->checksum_ptr); s->update_checksum= NULL; @@ -341,7 +373,8 @@ int get_buffer(ByteIOContext *s, unsigned char *buf, int size) len = size; if (len == 0) { if(size > s->buffer_size && !s->update_checksum){ - len = s->read_packet(s->opaque, buf, size); + if(s->read_packet) + len = s->read_packet(s->opaque, buf, size); if (len <= 0) { /* do not modify buffer if EOF reached so that a seek back can be done without rereading data */ @@ -469,32 +502,18 @@ uint64_t get_be64(ByteIOContext *s) return val; } -/* link with avio functions */ - -#ifdef CONFIG_MUXERS -static int url_write_packet(void *opaque, uint8_t *buf, int buf_size) -{ - URLContext *h = opaque; - return url_write(h, buf, buf_size); -} -#else -#define url_write_packet NULL -#endif //CONFIG_MUXERS - -static int url_read_packet(void *opaque, uint8_t *buf, int buf_size) -{ - URLContext *h = opaque; - return url_read(h, buf, buf_size); -} +uint64_t ff_get_v(ByteIOContext *bc){ + uint64_t val = 0; + int tmp; -static offset_t url_seek_packet(void *opaque, offset_t offset, int whence) -{ - URLContext *h = opaque; - return url_seek(h, offset, whence); - //return 0; + do{ + tmp = get_byte(bc); + val= (val<<7) + (tmp&127); + }while(tmp&128); + return val; } -int url_fdopen(ByteIOContext *s, URLContext *h) +int url_fdopen(ByteIOContext **s, URLContext *h) { uint8_t *buffer; int buffer_size, max_packet_size; @@ -510,14 +529,25 @@ int url_fdopen(ByteIOContext *s, URLContext *h) if (!buffer) return AVERROR(ENOMEM); - if (init_put_byte(s, buffer, buffer_size, + *s = av_mallocz(sizeof(ByteIOContext)); + if(!*s) { + av_free(buffer); + return AVERROR(ENOMEM); + } + + if (init_put_byte(*s, buffer, buffer_size, (h->flags & URL_WRONLY || h->flags & URL_RDWR), h, - url_read_packet, url_write_packet, url_seek_packet) < 0) { + url_read, url_write, url_seek) < 0) { av_free(buffer); - return AVERROR_IO; + av_freep(s); + return AVERROR(EIO); + } + (*s)->is_streamed = h->is_streamed; + (*s)->max_packet_size = max_packet_size; + if(h->prot) { + (*s)->read_pause = (int (*)(void *, int))h->prot->url_read_pause; + (*s)->read_seek = (offset_t (*)(void *, int, int64_t, int))h->prot->url_read_seek; } - s->is_streamed = h->is_streamed; - s->max_packet_size = max_packet_size; return 0; } @@ -532,14 +562,27 @@ int url_setbufsize(ByteIOContext *s, int buf_size) s->buffer = buffer; s->buffer_size = buf_size; s->buf_ptr = buffer; - if (!s->write_flag) - s->buf_end = buffer; - else - s->buf_end = buffer + buf_size; + url_resetbuf(s, s->write_flag ? URL_WRONLY : URL_RDONLY); + return 0; +} + +int url_resetbuf(ByteIOContext *s, int flags) +{ + URLContext *h = s->opaque; + if ((flags & URL_RDWR) || (h && h->flags != flags && !h->flags & URL_RDWR)) + return AVERROR(EINVAL); + + if (flags & URL_WRONLY) { + s->buf_end = s->buffer + s->buffer_size; + s->write_flag = 1; + } else { + s->buf_end = s->buffer; + s->write_flag = 0; + } return 0; } -int url_fopen(ByteIOContext *s, const char *filename, int flags) +int url_fopen(ByteIOContext **s, const char *filename, int flags) { URLContext *h; int err; @@ -560,7 +603,7 @@ int url_fclose(ByteIOContext *s) URLContext *h = s->opaque; av_free(s->buffer); - memset(s, 0, sizeof(ByteIOContext)); + av_free(s); return url_close(h); } @@ -610,15 +653,44 @@ int url_fget_max_packet_size(ByteIOContext *s) return s->max_packet_size; } +int av_url_read_fpause(ByteIOContext *s, int pause) +{ + if (!s->read_pause) + return AVERROR(ENOSYS); + return s->read_pause(s->opaque, pause); +} + +offset_t av_url_read_fseek(ByteIOContext *s, + int stream_index, int64_t timestamp, int flags) +{ + URLContext *h = s->opaque; + offset_t ret; + if (!s->read_seek) + return AVERROR(ENOSYS); + ret = s->read_seek(h, stream_index, timestamp, flags); + if(ret >= 0) { + s->buf_ptr = s->buf_end; // Flush buffer + s->pos = s->seek(h, 0, SEEK_CUR); + } + return ret; +} + /* url_open_dyn_buf and url_close_dyn_buf are used in rtp.c to send a response * back to the server even if CONFIG_MUXERS is not set. */ #if defined(CONFIG_MUXERS) || defined(CONFIG_NETWORK) /* buffer handling */ -int url_open_buf(ByteIOContext *s, uint8_t *buf, int buf_size, int flags) +int url_open_buf(ByteIOContext **s, uint8_t *buf, int buf_size, int flags) { - return init_put_byte(s, buf, buf_size, - (flags & URL_WRONLY || flags & URL_RDWR), - NULL, NULL, NULL, NULL); + int ret; + *s = av_mallocz(sizeof(ByteIOContext)); + if(!*s) + return AVERROR(ENOMEM); + ret = init_put_byte(*s, buf, buf_size, + (flags & URL_WRONLY || flags & URL_RDWR), + NULL, NULL, NULL, NULL); + if(ret != 0) + av_freep(s); + return ret; } int url_close_buf(ByteIOContext *s) @@ -698,7 +770,7 @@ static offset_t dyn_buf_seek(void *opaque, offset_t offset, int whence) return 0; } -static int url_open_dyn_buf_internal(ByteIOContext *s, int max_packet_size) +static int url_open_dyn_buf_internal(ByteIOContext **s, int max_packet_size) { DynBuffer *d; int io_buffer_size, ret; @@ -713,27 +785,35 @@ static int url_open_dyn_buf_internal(ByteIOContext *s, int max_packet_size) d = av_malloc(sizeof(DynBuffer) + io_buffer_size); if (!d) return -1; + *s = av_mallocz(sizeof(ByteIOContext)); + if(!*s) { + av_free(d); + return AVERROR(ENOMEM); + } d->io_buffer_size = io_buffer_size; d->buffer = NULL; d->pos = 0; d->size = 0; d->allocated_size = 0; - ret = init_put_byte(s, d->io_buffer, io_buffer_size, + ret = init_put_byte(*s, d->io_buffer, io_buffer_size, 1, d, NULL, max_packet_size ? dyn_packet_buf_write : dyn_buf_write, max_packet_size ? NULL : dyn_buf_seek); if (ret == 0) { - s->max_packet_size = max_packet_size; + (*s)->max_packet_size = max_packet_size; + } else { + av_free(d); + av_freep(s); } return ret; } -int url_open_dyn_buf(ByteIOContext *s) +int url_open_dyn_buf(ByteIOContext **s) { return url_open_dyn_buf_internal(s, 0); } -int url_open_dyn_packet_buf(ByteIOContext *s, int max_packet_size) +int url_open_dyn_packet_buf(ByteIOContext **s, int max_packet_size) { if (max_packet_size <= 0) return -1; @@ -750,6 +830,7 @@ int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer) *pbuffer = d->buffer; size = d->size; av_free(d); + av_free(s); return size; } #endif /* CONFIG_MUXERS || CONFIG_NETWORK */ diff --git a/contrib/ffmpeg/libavformat/avisynth.c b/contrib/ffmpeg/libavformat/avisynth.c index 1afcdea5e..158cac1fc 100644 --- a/contrib/ffmpeg/libavformat/avisynth.c +++ b/contrib/ffmpeg/libavformat/avisynth.c @@ -156,10 +156,10 @@ static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt) stream = &avs->streams[stream_id]; if (stream->read >= stream->info.dwLength) - return AVERROR_IO; + return AVERROR(EIO); if (av_new_packet(pkt, stream->chunck_size)) - return AVERROR_IO; + return AVERROR(EIO); pkt->stream_index = stream_id; pkt->pts = avs->streams[stream_id].read / avs->streams[stream_id].chunck_samples; diff --git a/contrib/ffmpeg/libavformat/avs.c b/contrib/ffmpeg/libavformat/avs.c index 0fa77deff..b1d6f89e0 100644 --- a/contrib/ffmpeg/libavformat/avs.c +++ b/contrib/ffmpeg/libavformat/avs.c @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avformat.h" @@ -47,8 +47,6 @@ static int avs_probe(AVProbeData * p) { const uint8_t *d; - if (p->buf_size < 2) - return 0; d = p->buf; if (d[0] == 'w' && d[1] == 'W' && d[2] == 0x10 && d[3] == 0) return 50; @@ -62,12 +60,12 @@ static int avs_read_header(AVFormatContext * s, AVFormatParameters * ap) s->ctx_flags |= AVFMTCTX_NOHEADER; - url_fskip(&s->pb, 4); - avs->width = get_le16(&s->pb); - avs->height = get_le16(&s->pb); - avs->bits_per_sample = get_le16(&s->pb); - avs->fps = get_le16(&s->pb); - avs->nb_frames = get_le32(&s->pb); + url_fskip(s->pb, 4); + avs->width = get_le16(s->pb); + avs->height = get_le16(s->pb); + avs->bits_per_sample = get_le16(s->pb); + avs->fps = get_le16(s->pb); + avs->nb_frames = get_le32(s->pb); avs->remaining_frame_size = 0; avs->remaining_audio_size = 0; @@ -105,10 +103,10 @@ avs_read_video_packet(AVFormatContext * s, AVPacket * pkt, pkt->data[palette_size + 1] = type; pkt->data[palette_size + 2] = size & 0xFF; pkt->data[palette_size + 3] = (size >> 8) & 0xFF; - ret = get_buffer(&s->pb, pkt->data + palette_size + 4, size - 4) + 4; + ret = get_buffer(s->pb, pkt->data + palette_size + 4, size - 4) + 4; if (ret < size) { av_free_packet(pkt); - return AVERROR_IO; + return AVERROR(EIO); } pkt->size = ret + palette_size; @@ -124,12 +122,12 @@ static int avs_read_audio_packet(AVFormatContext * s, AVPacket * pkt) avs_format_t *avs = s->priv_data; int ret, size; - size = url_ftell(&s->pb); + size = url_ftell(s->pb); ret = voc_get_packet(s, pkt, avs->st_audio, avs->remaining_audio_size); - size = url_ftell(&s->pb) - size; + size = url_ftell(s->pb) - size; avs->remaining_audio_size -= size; - if (ret == AVERROR_IO) + if (ret == AVERROR(EIO)) return 0; /* this indicate EOS */ if (ret < 0) return ret; @@ -155,22 +153,22 @@ static int avs_read_packet(AVFormatContext * s, AVPacket * pkt) while (1) { if (avs->remaining_frame_size <= 0) { - if (!get_le16(&s->pb)) /* found EOF */ - return AVERROR_IO; - avs->remaining_frame_size = get_le16(&s->pb) - 4; + if (!get_le16(s->pb)) /* found EOF */ + return AVERROR(EIO); + avs->remaining_frame_size = get_le16(s->pb) - 4; } while (avs->remaining_frame_size > 0) { - sub_type = get_byte(&s->pb); - type = get_byte(&s->pb); - size = get_le16(&s->pb); + sub_type = get_byte(s->pb); + type = get_byte(s->pb); + size = get_le16(s->pb); avs->remaining_frame_size -= size; switch (type) { case AVS_PALETTE: - ret = get_buffer(&s->pb, palette, size - 4); + ret = get_buffer(s->pb, palette, size - 4); if (ret < size - 4) - return AVERROR_IO; + return AVERROR(EIO); palette_size = size; break; @@ -178,7 +176,7 @@ static int avs_read_packet(AVFormatContext * s, AVPacket * pkt) if (!avs->st_video) { avs->st_video = av_new_stream(s, AVS_VIDEO); if (avs->st_video == NULL) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); avs->st_video->codec->codec_type = CODEC_TYPE_VIDEO; avs->st_video->codec->codec_id = CODEC_ID_AVS; avs->st_video->codec->width = avs->width; @@ -195,7 +193,7 @@ static int avs_read_packet(AVFormatContext * s, AVPacket * pkt) if (!avs->st_audio) { avs->st_audio = av_new_stream(s, AVS_AUDIO); if (avs->st_audio == NULL) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); avs->st_audio->codec->codec_type = CODEC_TYPE_AUDIO; } avs->remaining_audio_size = size - 4; @@ -205,7 +203,7 @@ static int avs_read_packet(AVFormatContext * s, AVPacket * pkt) break; default: - url_fskip(&s->pb, size - 4); + url_fskip(s->pb, size - 4); } } } diff --git a/contrib/ffmpeg/libavformat/beosaudio.cpp b/contrib/ffmpeg/libavformat/beosaudio.cpp deleted file mode 100644 index 6c16f0048..000000000 --- a/contrib/ffmpeg/libavformat/beosaudio.cpp +++ /dev/null @@ -1,465 +0,0 @@ -/* - * BeOS audio play interface - * Copyright (c) 2000, 2001 Fabrice Bellard. - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include -#include -#include - -#include -#include - -extern "C" { -#include "avformat.h" -} - -#ifdef HAVE_BSOUNDRECORDER -#include -using namespace BPrivate::Media::Experimental; -#endif - -/* enable performance checks */ -//#define PERF_CHECK - -/* enable Media Kit latency checks */ -//#define LATENCY_CHECK - -#define AUDIO_BLOCK_SIZE 4096 -#define AUDIO_BLOCK_COUNT 8 - -#define AUDIO_BUFFER_SIZE (AUDIO_BLOCK_SIZE*AUDIO_BLOCK_COUNT) - -typedef struct { - int fd; // UNUSED - int sample_rate; - int channels; - int frame_size; /* in bytes ! */ - CodecID codec_id; - uint8_t buffer[AUDIO_BUFFER_SIZE]; - int buffer_ptr; - /* ring buffer */ - sem_id input_sem; - int input_index; - sem_id output_sem; - int output_index; - BSoundPlayer *player; -#ifdef HAVE_BSOUNDRECORDER - BSoundRecorder *recorder; -#endif - int has_quit; /* signal callbacks not to wait */ - volatile bigtime_t starve_time; -} AudioData; - -static thread_id main_thid; -static thread_id bapp_thid; -static int own_BApp_created = 0; -static int refcount = 0; - -/* create the BApplication and Run() it */ -static int32 bapp_thread(void *arg) -{ - new BApplication("application/x-vnd.ffmpeg"); - own_BApp_created = 1; - be_app->Run(); - /* kill the process group */ -// kill(0, SIGINT); -// kill(main_thid, SIGHUP); - return B_OK; -} - -/* create the BApplication only if needed */ -static void create_bapp_if_needed(void) -{ - if (refcount++ == 0) { - /* needed by libmedia */ - if (be_app == NULL) { - bapp_thid = spawn_thread(bapp_thread, "ffmpeg BApplication", B_NORMAL_PRIORITY, NULL); - resume_thread(bapp_thid); - while (!own_BApp_created) - snooze(50000); - } - } -} - -static void destroy_bapp_if_needed(void) -{ - if (--refcount == 0 && own_BApp_created) { - be_app->Lock(); - be_app->Quit(); - be_app = NULL; - } -} - -/* called back by BSoundPlayer */ -static void audioplay_callback(void *cookie, void *buffer, size_t bufferSize, const media_raw_audio_format &format) -{ - AudioData *s; - size_t len, amount; - unsigned char *buf = (unsigned char *)buffer; - - s = (AudioData *)cookie; - if (s->has_quit) - return; - while (bufferSize > 0) { -#ifdef PERF_CHECK - bigtime_t t; - t = system_time(); -#endif - len = MIN(AUDIO_BLOCK_SIZE, bufferSize); - if (acquire_sem_etc(s->output_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK) { - s->has_quit = 1; - s->player->SetHasData(false); - return; - } - amount = MIN(len, (AUDIO_BUFFER_SIZE - s->output_index)); - memcpy(buf, &s->buffer[s->output_index], amount); - s->output_index += amount; - if (s->output_index >= AUDIO_BUFFER_SIZE) { - s->output_index %= AUDIO_BUFFER_SIZE; - memcpy(buf + amount, &s->buffer[s->output_index], len - amount); - s->output_index += len-amount; - s->output_index %= AUDIO_BUFFER_SIZE; - } - release_sem_etc(s->input_sem, len, 0); -#ifdef PERF_CHECK - t = system_time() - t; - s->starve_time = MAX(s->starve_time, t); -#endif - buf += len; - bufferSize -= len; - } -} - -#ifdef HAVE_BSOUNDRECORDER -/* called back by BSoundRecorder */ -static void audiorecord_callback(void *cookie, bigtime_t timestamp, void *buffer, size_t bufferSize, const media_multi_audio_format &format) -{ - AudioData *s; - size_t len, amount; - unsigned char *buf = (unsigned char *)buffer; - - s = (AudioData *)cookie; - if (s->has_quit) - return; - - while (bufferSize > 0) { - len = MIN(bufferSize, AUDIO_BLOCK_SIZE); - //printf("acquire_sem(input, %d)\n", len); - if (acquire_sem_etc(s->input_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK) { - s->has_quit = 1; - return; - } - amount = MIN(len, (AUDIO_BUFFER_SIZE - s->input_index)); - memcpy(&s->buffer[s->input_index], buf, amount); - s->input_index += amount; - if (s->input_index >= AUDIO_BUFFER_SIZE) { - s->input_index %= AUDIO_BUFFER_SIZE; - memcpy(&s->buffer[s->input_index], buf + amount, len - amount); - s->input_index += len - amount; - } - release_sem_etc(s->output_sem, len, 0); - //printf("release_sem(output, %d)\n", len); - buf += len; - bufferSize -= len; - } -} -#endif - -static int audio_open(AudioData *s, int is_output, const char *audio_device) -{ - int p[2]; - int ret; - media_raw_audio_format format; - media_multi_audio_format iformat; - -#ifndef HAVE_BSOUNDRECORDER - if (!is_output) - return AVERROR(EIO); /* not for now */ -#endif - s->input_sem = create_sem(AUDIO_BUFFER_SIZE, "ffmpeg_ringbuffer_input"); - if (s->input_sem < B_OK) - return AVERROR(EIO); - s->output_sem = create_sem(0, "ffmpeg_ringbuffer_output"); - if (s->output_sem < B_OK) { - delete_sem(s->input_sem); - return AVERROR(EIO); - } - s->input_index = 0; - s->output_index = 0; - create_bapp_if_needed(); - s->frame_size = AUDIO_BLOCK_SIZE; - /* bump up the priority (avoid realtime though) */ - set_thread_priority(find_thread(NULL), B_DISPLAY_PRIORITY+1); -#ifdef HAVE_BSOUNDRECORDER - if (!is_output) { - bool wait_for_input = false; - if (audio_device && !strcmp(audio_device, "wait:")) - wait_for_input = true; - s->recorder = new BSoundRecorder(&iformat, wait_for_input, "ffmpeg input", audiorecord_callback); - if (wait_for_input && (s->recorder->InitCheck() == B_OK)) { - s->recorder->WaitForIncomingConnection(&iformat); - } - if (s->recorder->InitCheck() != B_OK || iformat.format != media_raw_audio_format::B_AUDIO_SHORT) { - delete s->recorder; - s->recorder = NULL; - if (s->input_sem) - delete_sem(s->input_sem); - if (s->output_sem) - delete_sem(s->output_sem); - return AVERROR(EIO); - } - s->codec_id = (iformat.byte_order == B_MEDIA_LITTLE_ENDIAN)?CODEC_ID_PCM_S16LE:CODEC_ID_PCM_S16BE; - s->channels = iformat.channel_count; - s->sample_rate = (int)iformat.frame_rate; - s->frame_size = iformat.buffer_size; - s->recorder->SetCookie(s); - s->recorder->SetVolume(1.0); - s->recorder->Start(); - return 0; - } -#endif - format = media_raw_audio_format::wildcard; - format.format = media_raw_audio_format::B_AUDIO_SHORT; - format.byte_order = B_HOST_IS_LENDIAN ? B_MEDIA_LITTLE_ENDIAN : B_MEDIA_BIG_ENDIAN; - format.channel_count = s->channels; - format.buffer_size = s->frame_size; - format.frame_rate = s->sample_rate; - s->player = new BSoundPlayer(&format, "ffmpeg output", audioplay_callback); - if (s->player->InitCheck() != B_OK) { - delete s->player; - s->player = NULL; - if (s->input_sem) - delete_sem(s->input_sem); - if (s->output_sem) - delete_sem(s->output_sem); - return AVERROR(EIO); - } - s->player->SetCookie(s); - s->player->SetVolume(1.0); - s->player->Start(); - s->player->SetHasData(true); - return 0; -} - -static int audio_close(AudioData *s) -{ - if (s->input_sem) - delete_sem(s->input_sem); - if (s->output_sem) - delete_sem(s->output_sem); - s->has_quit = 1; - if (s->player) { - s->player->Stop(); - } - if (s->player) - delete s->player; -#ifdef HAVE_BSOUNDRECORDER - if (s->recorder) - delete s->recorder; -#endif - destroy_bapp_if_needed(); - return 0; -} - -/* sound output support */ -static int audio_write_header(AVFormatContext *s1) -{ - AudioData *s = (AudioData *)s1->priv_data; - AVStream *st; - int ret; - - st = s1->streams[0]; - s->sample_rate = st->codec->sample_rate; - s->channels = st->codec->channels; - ret = audio_open(s, 1, NULL); - if (ret < 0) - return AVERROR(EIO); - return 0; -} - -static int audio_write_packet(AVFormatContext *s1, int stream_index, - const uint8_t *buf, int size, int64_t force_pts) -{ - AudioData *s = (AudioData *)s1->priv_data; - int len, ret; -#ifdef LATENCY_CHECK -bigtime_t lat1, lat2; -lat1 = s->player->Latency(); -#endif -#ifdef PERF_CHECK - bigtime_t t = s->starve_time; - s->starve_time = 0; - printf("starve_time: %lld \n", t); -#endif - while (size > 0) { - int amount; - len = MIN(size, AUDIO_BLOCK_SIZE); - if (acquire_sem_etc(s->input_sem, len, B_CAN_INTERRUPT, 0LL) < B_OK) - return AVERROR(EIO); - amount = MIN(len, (AUDIO_BUFFER_SIZE - s->input_index)); - memcpy(&s->buffer[s->input_index], buf, amount); - s->input_index += amount; - if (s->input_index >= AUDIO_BUFFER_SIZE) { - s->input_index %= AUDIO_BUFFER_SIZE; - memcpy(&s->buffer[s->input_index], buf + amount, len - amount); - s->input_index += len - amount; - } - release_sem_etc(s->output_sem, len, 0); - buf += len; - size -= len; - } -#ifdef LATENCY_CHECK -lat2 = s->player->Latency(); -printf("#### BSoundPlayer::Latency(): before= %lld, after= %lld\n", lat1, lat2); -#endif - return 0; -} - -static int audio_write_trailer(AVFormatContext *s1) -{ - AudioData *s = (AudioData *)s1->priv_data; - - audio_close(s); - return 0; -} - -/* grab support */ - -static int audio_read_header(AVFormatContext *s1, AVFormatParameters *ap) -{ - AudioData *s = (AudioData *)s1->priv_data; - AVStream *st; - int ret; - - if (!ap || ap->sample_rate <= 0 || ap->channels <= 0) - return -1; - - st = av_new_stream(s1, 0); - if (!st) { - return AVERROR(ENOMEM); - } - s->sample_rate = ap->sample_rate; - s->channels = ap->channels; - - ret = audio_open(s, 0, s1->filename); - if (ret < 0) { - av_free(st); - return AVERROR(EIO); - } - /* take real parameters */ - st->codec->codec_type = CODEC_TYPE_AUDIO; - st->codec->codec_id = s->codec_id; - st->codec->sample_rate = s->sample_rate; - st->codec->channels = s->channels; - return 0; - av_set_pts_info(s1, 48, 1, 1000000); /* 48 bits pts in us */ -} - -static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt) -{ - AudioData *s = (AudioData *)s1->priv_data; - int size; - size_t len, amount; - unsigned char *buf; - status_t err; - - if (av_new_packet(pkt, s->frame_size) < 0) - return AVERROR(EIO); - buf = (unsigned char *)pkt->data; - size = pkt->size; - while (size > 0) { - len = MIN(AUDIO_BLOCK_SIZE, size); - //printf("acquire_sem(output, %d)\n", len); - while ((err=acquire_sem_etc(s->output_sem, len, B_CAN_INTERRUPT, 0LL)) == B_INTERRUPTED); - if (err < B_OK) { - av_free_packet(pkt); - return AVERROR(EIO); - } - amount = MIN(len, (AUDIO_BUFFER_SIZE - s->output_index)); - memcpy(buf, &s->buffer[s->output_index], amount); - s->output_index += amount; - if (s->output_index >= AUDIO_BUFFER_SIZE) { - s->output_index %= AUDIO_BUFFER_SIZE; - memcpy(buf + amount, &s->buffer[s->output_index], len - amount); - s->output_index += len-amount; - s->output_index %= AUDIO_BUFFER_SIZE; - } - release_sem_etc(s->input_sem, len, 0); - //printf("release_sem(input, %d)\n", len); - buf += len; - size -= len; - } - //XXX: add pts info - return 0; -} - -static int audio_read_close(AVFormatContext *s1) -{ - AudioData *s = (AudioData *)s1->priv_data; - - audio_close(s); - return 0; -} - -static AVInputFormat audio_demuxer = { - "audio_device", - "audio grab and output", - sizeof(AudioData), - NULL, - audio_read_header, - audio_read_packet, - audio_read_close, - NULL, - AVFMT_NOFILE, -}; - -AVOutputFormat audio_muxer = { - "audio_device", - "audio grab and output", - "", - "", - sizeof(AudioData), -#ifdef WORDS_BIGENDIAN - CODEC_ID_PCM_S16BE, -#else - CODEC_ID_PCM_S16LE, -#endif - CODEC_ID_NONE, - audio_write_header, - audio_write_packet, - audio_write_trailer, - AVFMT_NOFILE, -}; - -extern "C" { - -int audio_init(void) -{ - main_thid = find_thread(NULL); - av_register_input_format(&audio_demuxer); - av_register_output_format(&audio_muxer); - return 0; -} - -} // "C" - diff --git a/contrib/ffmpeg/libavformat/bethsoftvid.c b/contrib/ffmpeg/libavformat/bethsoftvid.c new file mode 100644 index 000000000..594779698 --- /dev/null +++ b/contrib/ffmpeg/libavformat/bethsoftvid.c @@ -0,0 +1,233 @@ +/* + * Bethsoft VID format Demuxer + * Copyright (c) 2007 Nicholas Tung + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file bethsoftvid.c + * @brief Bethesda Softworks VID (.vid) file demuxer + * @author Nicholas Tung [ntung (at. ntung com] (2007-03) + * @sa http://wiki.multimedia.cx/index.php?title=Bethsoft_VID + * @sa http://www.svatopluk.com/andux/docs/dfvid.html + */ + +#include "avformat.h" +#include "bethsoftvideo.h" + +typedef struct BVID_DemuxContext +{ + int nframes; + /** delay value between frames, added to individual frame delay. + * custom units, which will be added to other custom units (~=16ms according + * to free, unofficial documentation) */ + int bethsoft_global_delay; + + /** video presentation time stamp. + * delay = 16 milliseconds * (global_delay + per_frame_delay) */ + int video_pts; + + int is_finished; + +} BVID_DemuxContext; + +static int vid_probe(AVProbeData *p) +{ + // little endian VID tag, file starts with "VID\0" + if (AV_RL32(p->buf) != MKTAG('V', 'I', 'D', 0)) + return 0; + + return AVPROBE_SCORE_MAX; +} + +static int vid_read_header(AVFormatContext *s, + AVFormatParameters *ap) +{ + BVID_DemuxContext *vid = s->priv_data; + ByteIOContext *pb = s->pb; + AVStream *stream; + + /* load main header. Contents: + * bytes: 'V' 'I' 'D' + * int16s: always_512, nframes, width, height, delay, always_14 + */ + url_fseek(pb, 5, SEEK_CUR); + vid->nframes = get_le16(pb); + + stream = av_new_stream(s, 0); + if (!stream) + return AVERROR(ENOMEM); + av_set_pts_info(stream, 32, 1, 60); // 16 ms increments, i.e. 60 fps + stream->codec->codec_type = CODEC_TYPE_VIDEO; + stream->codec->codec_id = CODEC_ID_BETHSOFTVID; + stream->codec->width = get_le16(pb); + stream->codec->height = get_le16(pb); + stream->codec->pix_fmt = PIX_FMT_PAL8; + vid->bethsoft_global_delay = get_le16(pb); + get_le16(pb); + + // done with video codec, set up audio codec + stream = av_new_stream(s, 0); + if (!stream) + return AVERROR(ENOMEM); + stream->codec->codec_type = CODEC_TYPE_AUDIO; + stream->codec->codec_id = CODEC_ID_PCM_U8; + stream->codec->channels = 1; + stream->codec->sample_rate = 11025; + stream->codec->bits_per_sample = 8; + stream->codec->bit_rate = stream->codec->channels * stream->codec->sample_rate * stream->codec->bits_per_sample; + + return 0; +} + +#define BUFFER_PADDING_SIZE 1000 +static int read_frame(BVID_DemuxContext *vid, ByteIOContext *pb, AVPacket *pkt, + uint8_t block_type, AVFormatContext *s, int npixels) +{ + uint8_t * vidbuf_start = NULL; + int vidbuf_nbytes = 0; + int code; + int bytes_copied = 0; + int position; + unsigned int vidbuf_capacity; + + vidbuf_start = av_malloc(vidbuf_capacity = BUFFER_PADDING_SIZE); + if(!vidbuf_start) + return AVERROR(ENOMEM); + + // save the file position for the packet, include block type + position = url_ftell(pb) - 1; + + vidbuf_start[vidbuf_nbytes++] = block_type; + + // get the video delay (next int16), and set the presentation time + vid->video_pts += vid->bethsoft_global_delay + get_le16(pb); + + // set the y offset if it exists (decoder header data should be in data section) + if(block_type == VIDEO_YOFF_P_FRAME){ + if(get_buffer(pb, &vidbuf_start[vidbuf_nbytes], 2) != 2) + goto fail; + vidbuf_nbytes += 2; + } + + do{ + vidbuf_start = av_fast_realloc(vidbuf_start, &vidbuf_capacity, vidbuf_nbytes + BUFFER_PADDING_SIZE); + if(!vidbuf_start) + return AVERROR(ENOMEM); + + code = get_byte(pb); + vidbuf_start[vidbuf_nbytes++] = code; + + if(code >= 0x80){ // rle sequence + if(block_type == VIDEO_I_FRAME) + vidbuf_start[vidbuf_nbytes++] = get_byte(pb); + } else if(code){ // plain sequence + if(get_buffer(pb, &vidbuf_start[vidbuf_nbytes], code) != code) + goto fail; + vidbuf_nbytes += code; + } + bytes_copied += code & 0x7F; + if(bytes_copied == npixels){ // sometimes no stop character is given, need to keep track of bytes copied + // may contain a 0 byte even if read all pixels + if(get_byte(pb)) + url_fseek(pb, -1, SEEK_CUR); + break; + } + if(bytes_copied > npixels) + goto fail; + } while(code); + + // copy data into packet + if(av_new_packet(pkt, vidbuf_nbytes) < 0) + goto fail; + memcpy(pkt->data, vidbuf_start, vidbuf_nbytes); + av_free(vidbuf_start); + + pkt->pos = position; + pkt->stream_index = 0; // use the video decoder, which was initialized as the first stream + pkt->pts = vid->video_pts; + + vid->nframes--; // used to check if all the frames were read + return vidbuf_nbytes; +fail: + av_free(vidbuf_start); + return -1; +} + +static int vid_read_packet(AVFormatContext *s, + AVPacket *pkt) +{ + BVID_DemuxContext *vid = s->priv_data; + ByteIOContext *pb = s->pb; + unsigned char block_type; + int audio_length; + int ret_value; + + if(vid->is_finished || url_feof(pb)) + return AVERROR(EIO); + + block_type = get_byte(pb); + switch(block_type){ + case PALETTE_BLOCK: + url_fseek(pb, -1, SEEK_CUR); // include block type + ret_value = av_get_packet(pb, pkt, 3 * 256 + 1); + if(ret_value != 3 * 256 + 1){ + av_free_packet(pkt); + return AVERROR(EIO); + } + pkt->stream_index = 0; + return ret_value; + + case FIRST_AUDIO_BLOCK: + get_le16(pb); + // soundblaster DAC used for sample rate, as on specification page (link above) + s->streams[1]->codec->sample_rate = 1000000 / (256 - get_byte(pb)); + s->streams[1]->codec->bit_rate = s->streams[1]->codec->channels * s->streams[1]->codec->sample_rate * s->streams[1]->codec->bits_per_sample; + case AUDIO_BLOCK: + audio_length = get_le16(pb); + ret_value = av_get_packet(pb, pkt, audio_length); + pkt->stream_index = 1; + return (ret_value != audio_length ? AVERROR(EIO) : ret_value); + + case VIDEO_P_FRAME: + case VIDEO_YOFF_P_FRAME: + case VIDEO_I_FRAME: + return read_frame(vid, pb, pkt, block_type, s, + s->streams[0]->codec->width * s->streams[0]->codec->height); + + case EOF_BLOCK: + if(vid->nframes != 0) + av_log(s, AV_LOG_VERBOSE, "reached terminating character but not all frames read.\n"); + vid->is_finished = 1; + return AVERROR(EIO); + default: + av_log(s, AV_LOG_ERROR, "unknown block (character = %c, decimal = %d, hex = %x)!!!\n", + block_type, block_type, block_type); return -1; + } + + return 0; +} + +AVInputFormat bethsoftvid_demuxer = { + "bethsoftvid", + "Bethesda Softworks 'Daggerfall' VID format", + sizeof(BVID_DemuxContext), + vid_probe, + vid_read_header, + vid_read_packet, +}; diff --git a/contrib/ffmpeg/libavformat/c93.c b/contrib/ffmpeg/libavformat/c93.c new file mode 100644 index 000000000..996012f6e --- /dev/null +++ b/contrib/ffmpeg/libavformat/c93.c @@ -0,0 +1,198 @@ +/* + * Interplay C93 demuxer + * Copyright (c) 2007 Anssi Hannula + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" +#include "voc.h" + +typedef struct { + uint16_t index; + uint8_t length; + uint8_t frames; +} C93BlockRecord; + +typedef struct { + voc_dec_context_t voc; + + C93BlockRecord block_records[512]; + int current_block; + + uint32_t frame_offsets[32]; + int current_frame; + int next_pkt_is_audio; + + AVStream *audio; +} C93DemuxContext; + +static int probe(AVProbeData *p) +{ + if (p->buf[0] == 0x01 && p->buf[1] == 0x00 && + p->buf[4] == 0x01 + p->buf[2] && + p->buf[8] == p->buf[4] + p->buf[6] && + p->buf[12] == p->buf[8] + p->buf[10]) + return AVPROBE_SCORE_MAX; + + return 0; +} + +static int read_header(AVFormatContext *s, + AVFormatParameters *ap) +{ + AVStream *video; + ByteIOContext *pb = s->pb; + C93DemuxContext *c93 = s->priv_data; + int i; + int framecount = 0; + + for (i = 0; i < 512; i++) { + c93->block_records[i].index = get_le16(pb); + c93->block_records[i].length = get_byte(pb); + c93->block_records[i].frames = get_byte(pb); + if (c93->block_records[i].frames > 32) { + av_log(s, AV_LOG_ERROR, "too many frames in block\n"); + return AVERROR_INVALIDDATA; + } + framecount += c93->block_records[i].frames; + } + + /* Audio streams are added if audio packets are found */ + s->ctx_flags |= AVFMTCTX_NOHEADER; + + video = av_new_stream(s, 0); + if (!video) + return AVERROR(ENOMEM); + + video->codec->codec_type = CODEC_TYPE_VIDEO; + video->codec->codec_id = CODEC_ID_C93; + video->codec->width = 320; + video->codec->height = 192; + /* 4:3 320x200 with 8 empty lines */ + video->codec->sample_aspect_ratio = (AVRational) { 5, 6 }; + video->time_base = (AVRational) { 2, 25 }; + video->nb_frames = framecount; + video->duration = framecount; + video->start_time = 0; + + c93->current_block = 0; + c93->current_frame = 0; + c93->next_pkt_is_audio = 0; + return 0; +} + +#define C93_HAS_PALETTE 0x01 +#define C93_FIRST_FRAME 0x02 + +static int read_packet(AVFormatContext *s, AVPacket *pkt) +{ + ByteIOContext *pb = s->pb; + C93DemuxContext *c93 = s->priv_data; + C93BlockRecord *br = &c93->block_records[c93->current_block]; + int datasize; + int ret, i; + + if (c93->next_pkt_is_audio) { + c93->current_frame++; + c93->next_pkt_is_audio = 0; + datasize = get_le16(pb); + if (datasize > 42) { + if (!c93->audio) { + c93->audio = av_new_stream(s, 1); + if (!c93->audio) + return AVERROR(ENOMEM); + c93->audio->codec->codec_type = CODEC_TYPE_AUDIO; + } + url_fskip(pb, 26); /* VOC header */ + ret = voc_get_packet(s, pkt, c93->audio, datasize - 26); + if (ret > 0) { + pkt->stream_index = 1; + pkt->flags |= PKT_FLAG_KEY; + return ret; + } + } + } + if (c93->current_frame >= br->frames) { + if (c93->current_block >= 511 || !br[1].length) + return AVERROR(EIO); + br++; + c93->current_block++; + c93->current_frame = 0; + } + + if (c93->current_frame == 0) { + url_fseek(pb, br->index * 2048, SEEK_SET); + for (i = 0; i < 32; i++) { + c93->frame_offsets[i] = get_le32(pb); + } + } + + url_fseek(pb,br->index * 2048 + + c93->frame_offsets[c93->current_frame], SEEK_SET); + datasize = get_le16(pb); /* video frame size */ + + ret = av_new_packet(pkt, datasize + 768 + 1); + if (ret < 0) + return ret; + pkt->data[0] = 0; + pkt->size = datasize + 1; + + ret = get_buffer(pb, pkt->data + 1, datasize); + if (ret < datasize) { + ret = AVERROR(EIO); + goto fail; + } + + datasize = get_le16(pb); /* palette size */ + if (datasize) { + if (datasize != 768) { + av_log(s, AV_LOG_ERROR, "invalid palette size %u\n", datasize); + ret = AVERROR_INVALIDDATA; + goto fail; + } + pkt->data[0] |= C93_HAS_PALETTE; + ret = get_buffer(pb, pkt->data + pkt->size, datasize); + if (ret < datasize) { + ret = AVERROR(EIO); + goto fail; + } + pkt->size += 768; + } + pkt->stream_index = 0; + c93->next_pkt_is_audio = 1; + + /* only the first frame is guaranteed to not reference previous frames */ + if (c93->current_block == 0 && c93->current_frame == 0) { + pkt->flags |= PKT_FLAG_KEY; + pkt->data[0] |= C93_FIRST_FRAME; + } + return 0; + + fail: + av_free_packet(pkt); + return ret; +} + +AVInputFormat c93_demuxer = { + "c93", + "Interplay C93", + sizeof(C93DemuxContext), + probe, + read_header, + read_packet, +}; diff --git a/contrib/ffmpeg/libavformat/crc.c b/contrib/ffmpeg/libavformat/crc.c deleted file mode 100644 index bdbe8bcff..000000000 --- a/contrib/ffmpeg/libavformat/crc.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * CRC decoder (for codec/format testing) - * Copyright (c) 2002 Fabrice Bellard. - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include "avformat.h" -#include "adler32.h" - -#ifdef CONFIG_CRC_MUXER -typedef struct CRCState { - uint32_t crcval; -} CRCState; - -static int crc_write_header(struct AVFormatContext *s) -{ - CRCState *crc = s->priv_data; - - /* init CRC */ - crc->crcval = 1; - - return 0; -} - -static int crc_write_packet(struct AVFormatContext *s, AVPacket *pkt) -{ - CRCState *crc = s->priv_data; - crc->crcval = av_adler32_update(crc->crcval, pkt->data, pkt->size); - return 0; -} - -static int crc_write_trailer(struct AVFormatContext *s) -{ - CRCState *crc = s->priv_data; - char buf[64]; - - snprintf(buf, sizeof(buf), "CRC=0x%08x\n", crc->crcval); - put_buffer(&s->pb, buf, strlen(buf)); - put_flush_packet(&s->pb); - return 0; -} -#endif - -#ifdef CONFIG_FRAMECRC_MUXER -static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt) -{ - uint32_t crc = av_adler32_update(0, pkt->data, pkt->size); - char buf[256]; - - snprintf(buf, sizeof(buf), "%d, %"PRId64", %d, 0x%08x\n", pkt->stream_index, pkt->dts, pkt->size, crc); - put_buffer(&s->pb, buf, strlen(buf)); - put_flush_packet(&s->pb); - return 0; -} -#endif - -#ifdef CONFIG_CRC_MUXER -AVOutputFormat crc_muxer = { - "crc", - "crc testing format", - NULL, - "", - sizeof(CRCState), - CODEC_ID_PCM_S16LE, - CODEC_ID_RAWVIDEO, - crc_write_header, - crc_write_packet, - crc_write_trailer, -}; -#endif -#ifdef CONFIG_FRAMECRC_MUXER -AVOutputFormat framecrc_muxer = { - "framecrc", - "framecrc testing format", - NULL, - "", - 0, - CODEC_ID_PCM_S16LE, - CODEC_ID_RAWVIDEO, - NULL, - framecrc_write_packet, - NULL, -}; -#endif diff --git a/contrib/ffmpeg/libavformat/crcenc.c b/contrib/ffmpeg/libavformat/crcenc.c new file mode 100644 index 000000000..dd8803161 --- /dev/null +++ b/contrib/ffmpeg/libavformat/crcenc.c @@ -0,0 +1,67 @@ +/* + * CRC encoder (for codec/format testing) + * Copyright (c) 2002 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avformat.h" +#include "adler32.h" + +typedef struct CRCState { + uint32_t crcval; +} CRCState; + +static int crc_write_header(struct AVFormatContext *s) +{ + CRCState *crc = s->priv_data; + + /* init CRC */ + crc->crcval = 1; + + return 0; +} + +static int crc_write_packet(struct AVFormatContext *s, AVPacket *pkt) +{ + CRCState *crc = s->priv_data; + crc->crcval = av_adler32_update(crc->crcval, pkt->data, pkt->size); + return 0; +} + +static int crc_write_trailer(struct AVFormatContext *s) +{ + CRCState *crc = s->priv_data; + char buf[64]; + + snprintf(buf, sizeof(buf), "CRC=0x%08x\n", crc->crcval); + put_buffer(s->pb, buf, strlen(buf)); + put_flush_packet(s->pb); + return 0; +} + +AVOutputFormat crc_muxer = { + "crc", + "crc testing format", + NULL, + "", + sizeof(CRCState), + CODEC_ID_PCM_S16LE, + CODEC_ID_RAWVIDEO, + crc_write_header, + crc_write_packet, + crc_write_trailer, +}; diff --git a/contrib/ffmpeg/libavformat/cutils.c b/contrib/ffmpeg/libavformat/cutils.c index 45959ec39..06c941112 100644 --- a/contrib/ffmpeg/libavformat/cutils.c +++ b/contrib/ffmpeg/libavformat/cutils.c @@ -20,96 +20,6 @@ */ #include "avformat.h" -#if !defined(CONFIG_NOCUTILS) -/** - * Return TRUE if val is a prefix of str. If it returns TRUE, ptr is - * set to the next character in 'str' after the prefix. - * - * @param str input string - * @param val prefix to test - * @param ptr updated after the prefix in str in there is a match - * @return TRUE if there is a match - */ -int strstart(const char *str, const char *val, const char **ptr) -{ - const char *p, *q; - p = str; - q = val; - while (*q != '\0') { - if (*p != *q) - return 0; - p++; - q++; - } - if (ptr) - *ptr = p; - return 1; -} - -/** - * Return TRUE if val is a prefix of str (case independent). If it - * returns TRUE, ptr is set to the next character in 'str' after the - * prefix. - * - * @param str input string - * @param val prefix to test - * @param ptr updated after the prefix in str in there is a match - * @return TRUE if there is a match */ -int stristart(const char *str, const char *val, const char **ptr) -{ - const char *p, *q; - p = str; - q = val; - while (*q != '\0') { - if (toupper(*(const unsigned char *)p) != toupper(*(const unsigned char *)q)) - return 0; - p++; - q++; - } - if (ptr) - *ptr = p; - return 1; -} - -/** - * Copy the string str to buf. If str length is bigger than buf_size - - * 1 then it is clamped to buf_size - 1. - * NOTE: this function does what strncpy should have done to be - * useful. NEVER use strncpy. - * - * @param buf destination buffer - * @param buf_size size of destination buffer - * @param str source string - */ -void pstrcpy(char *buf, int buf_size, const char *str) -{ - int c; - char *q = buf; - - if (buf_size <= 0) - return; - - for(;;) { - c = *str++; - if (c == 0 || q >= buf + buf_size - 1) - break; - *q++ = c; - } - *q = '\0'; -} - -/* strcat and truncate. */ -char *pstrcat(char *buf, int buf_size, const char *s) -{ - int len; - len = strlen(buf); - if (len < buf_size) - pstrcpy(buf + len, buf_size - len, s); - return buf; -} - -#endif - /* add one element to a dynamic array */ void __dynarray_add(unsigned long **tab_ptr, int *nb_ptr, unsigned long elem) { @@ -152,7 +62,7 @@ time_t mktimegm(struct tm *tm) #define ISLEAP(y) (((y) % 4 == 0) && (((y) % 100) != 0 || ((y) % 400) == 0)) #define LEAPS_COUNT(y) ((y)/4 - (y)/100 + (y)/400) -/* this is our own gmtime_r. it differs from its POSIX counterpart in a +/* This is our own gmtime_r. It differs from its POSIX counterpart in a couple of places, though. */ struct tm *brktimegm(time_t secs, struct tm *tm) { diff --git a/contrib/ffmpeg/libavformat/daud.c b/contrib/ffmpeg/libavformat/daud.c index ec81b7b1c..ff74d0502 100644 --- a/contrib/ffmpeg/libavformat/daud.c +++ b/contrib/ffmpeg/libavformat/daud.c @@ -1,6 +1,6 @@ /* * D-Cinema audio demuxer - * Copyright (c) 2005 Reimar Döffinger. + * Copyright (c) 2005 Reimar Döffinger * * This file is part of FFmpeg. * @@ -34,10 +34,10 @@ static int daud_header(AVFormatContext *s, AVFormatParameters *ap) { } static int daud_packet(AVFormatContext *s, AVPacket *pkt) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int ret, size; if (url_feof(pb)) - return AVERROR_IO; + return AVERROR(EIO); size = get_be16(pb); get_be16(pb); // unknown ret = av_get_packet(pb, pkt, size); diff --git a/contrib/ffmpeg/libavformat/dc1394.c b/contrib/ffmpeg/libavformat/dc1394.c deleted file mode 100644 index bf140c466..000000000 --- a/contrib/ffmpeg/libavformat/dc1394.c +++ /dev/null @@ -1,193 +0,0 @@ -/* - * IIDC1394 grab interface (uses libdc1394 and libraw1394) - * Copyright (c) 2004 Roman Shaposhnik - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "avformat.h" - -#include -#include - -#undef free - -typedef struct dc1394_data { - raw1394handle_t handle; - dc1394_cameracapture camera; - int current_frame; - int fps; - - AVPacket packet; -} dc1394_data; - -struct dc1394_frame_format { - int width; - int height; - enum PixelFormat pix_fmt; - int frame_size_id; -} dc1394_frame_formats[] = { - { 320, 240, PIX_FMT_UYVY422, MODE_320x240_YUV422 }, - { 640, 480, PIX_FMT_UYYVYY411, MODE_640x480_YUV411 }, - { 640, 480, PIX_FMT_UYVY422, MODE_640x480_YUV422 }, - { 0, 0, 0, MODE_320x240_YUV422 } /* default -- gotta be the last one */ -}; - -struct dc1394_frame_rate { - int frame_rate; - int frame_rate_id; -} dc1394_frame_rates[] = { - { 1875, FRAMERATE_1_875 }, - { 3750, FRAMERATE_3_75 }, - { 7500, FRAMERATE_7_5 }, - { 15000, FRAMERATE_15 }, - { 30000, FRAMERATE_30 }, - { 60000, FRAMERATE_60 }, - { 0, FRAMERATE_30 } /* default -- gotta be the last one */ -}; - -static int dc1394_read_header(AVFormatContext *c, AVFormatParameters * ap) -{ - dc1394_data* dc1394 = c->priv_data; - AVStream* vst; - nodeid_t* camera_nodes; - int res; - struct dc1394_frame_format *fmt; - struct dc1394_frame_rate *fps; - - for (fmt = dc1394_frame_formats; fmt->width; fmt++) - if (fmt->pix_fmt == ap->pix_fmt && fmt->width == ap->width && fmt->height == ap->height) - break; - - for (fps = dc1394_frame_rates; fps->frame_rate; fps++) - if (fps->frame_rate == av_rescale(1000, ap->time_base.den, ap->time_base.num)) - break; - - /* create a video stream */ - vst = av_new_stream(c, 0); - if (!vst) - return -1; - av_set_pts_info(vst, 64, 1, 1000); - vst->codec->codec_type = CODEC_TYPE_VIDEO; - vst->codec->codec_id = CODEC_ID_RAWVIDEO; - vst->codec->time_base.den = fps->frame_rate; - vst->codec->time_base.num = 1000; - vst->codec->width = fmt->width; - vst->codec->height = fmt->height; - vst->codec->pix_fmt = fmt->pix_fmt; - - /* packet init */ - av_init_packet(&dc1394->packet); - dc1394->packet.size = avpicture_get_size(fmt->pix_fmt, fmt->width, fmt->height); - dc1394->packet.stream_index = vst->index; - dc1394->packet.flags |= PKT_FLAG_KEY; - - dc1394->current_frame = 0; - dc1394->fps = fps->frame_rate; - - vst->codec->bit_rate = av_rescale(dc1394->packet.size * 8, fps->frame_rate, 1000); - - /* Now lets prep the hardware */ - dc1394->handle = dc1394_create_handle(0); /* FIXME: gotta have ap->port */ - if (!dc1394->handle) { - av_log(c, AV_LOG_ERROR, "Can't acquire dc1394 handle on port %d\n", 0 /* ap->port */); - goto out; - } - camera_nodes = dc1394_get_camera_nodes(dc1394->handle, &res, 1); - if (!camera_nodes || camera_nodes[ap->channel] == DC1394_NO_CAMERA) { - av_log(c, AV_LOG_ERROR, "There's no IIDC camera on the channel %d\n", ap->channel); - goto out_handle; - } - res = dc1394_dma_setup_capture(dc1394->handle, camera_nodes[ap->channel], - 0, - FORMAT_VGA_NONCOMPRESSED, - fmt->frame_size_id, - SPEED_400, - fps->frame_rate_id, 8, 1, - c->filename, - &dc1394->camera); - dc1394_free_camera_nodes(camera_nodes); - if (res != DC1394_SUCCESS) { - av_log(c, AV_LOG_ERROR, "Can't prepare camera for the DMA capture\n"); - goto out_handle; - } - - res = dc1394_start_iso_transmission(dc1394->handle, dc1394->camera.node); - if (res != DC1394_SUCCESS) { - av_log(c, AV_LOG_ERROR, "Can't start isochronous transmission\n"); - goto out_handle_dma; - } - - return 0; - -out_handle_dma: - dc1394_dma_unlisten(dc1394->handle, &dc1394->camera); - dc1394_dma_release_camera(dc1394->handle, &dc1394->camera); -out_handle: - dc1394_destroy_handle(dc1394->handle); -out: - return -1; -} - -static int dc1394_read_packet(AVFormatContext *c, AVPacket *pkt) -{ - struct dc1394_data *dc1394 = c->priv_data; - int res; - - /* discard stale frame */ - if (dc1394->current_frame++) { - if (dc1394_dma_done_with_buffer(&dc1394->camera) != DC1394_SUCCESS) - av_log(c, AV_LOG_ERROR, "failed to release %d frame\n", dc1394->current_frame); - } - - res = dc1394_dma_single_capture(&dc1394->camera); - - if (res == DC1394_SUCCESS) { - dc1394->packet.data = (uint8_t *)(dc1394->camera.capture_buffer); - dc1394->packet.pts = (dc1394->current_frame * 1000000) / dc1394->fps; - res = dc1394->packet.size; - } else { - av_log(c, AV_LOG_ERROR, "DMA capture failed\n"); - dc1394->packet.data = NULL; - res = -1; - } - - *pkt = dc1394->packet; - return res; -} - -static int dc1394_close(AVFormatContext * context) -{ - struct dc1394_data *dc1394 = context->priv_data; - - dc1394_stop_iso_transmission(dc1394->handle, dc1394->camera.node); - dc1394_dma_unlisten(dc1394->handle, &dc1394->camera); - dc1394_dma_release_camera(dc1394->handle, &dc1394->camera); - dc1394_destroy_handle(dc1394->handle); - - return 0; -} - -AVInputFormat dc1394_demuxer = { - .name = "dc1394", - .long_name = "dc1394 A/V grab", - .priv_data_size = sizeof(struct dc1394_data), - .read_header = dc1394_read_header, - .read_packet = dc1394_read_packet, - .read_close = dc1394_close, - .flags = AVFMT_NOFILE -}; diff --git a/contrib/ffmpeg/libavformat/dsicin.c b/contrib/ffmpeg/libavformat/dsicin.c index fb9cb50df..14f2be8af 100644 --- a/contrib/ffmpeg/libavformat/dsicin.c +++ b/contrib/ffmpeg/libavformat/dsicin.c @@ -58,9 +58,6 @@ typedef struct CinDemuxContext { static int cin_probe(AVProbeData *p) { - if (p->buf_size < 18) - return 0; - /* header starts with this special marker */ if (AV_RL32(&p->buf[0]) != 0x55AA0000) return 0; @@ -95,9 +92,9 @@ static int cin_read_file_header(CinDemuxContext *cin, ByteIOContext *pb) { static int cin_read_header(AVFormatContext *s, AVFormatParameters *ap) { int rc; - CinDemuxContext *cin = (CinDemuxContext *)s->priv_data; + CinDemuxContext *cin = s->priv_data; CinFileHeader *hdr = &cin->file_header; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVStream *st; rc = cin_read_file_header(cin, pb); @@ -111,7 +108,7 @@ static int cin_read_header(AVFormatContext *s, AVFormatParameters *ap) /* initialize the video decoder stream */ st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 32, 1, 12); cin->video_stream_index = st->index; @@ -124,7 +121,7 @@ static int cin_read_header(AVFormatContext *s, AVFormatParameters *ap) /* initialize the audio decoder stream */ st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 32, 1, 22050); cin->audio_stream_index = st->index; @@ -150,7 +147,7 @@ static int cin_read_frame_header(CinDemuxContext *cin, ByteIOContext *pb) { hdr->audio_frame_size = get_le32(pb); if (url_feof(pb) || url_ferror(pb)) - return AVERROR_IO; + return AVERROR(EIO); if (get_le32(pb) != 0xAA55AA55) return AVERROR_INVALIDDATA; @@ -160,8 +157,8 @@ static int cin_read_frame_header(CinDemuxContext *cin, ByteIOContext *pb) { static int cin_read_packet(AVFormatContext *s, AVPacket *pkt) { - CinDemuxContext *cin = (CinDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + CinDemuxContext *cin = s->priv_data; + ByteIOContext *pb = s->pb; CinFrameHeader *hdr = &cin->frame_header; int rc, palette_type, pkt_size; @@ -181,7 +178,7 @@ static int cin_read_packet(AVFormatContext *s, AVPacket *pkt) pkt_size = (palette_type + 3) * hdr->pal_colors_count + hdr->video_frame_size; if (av_new_packet(pkt, 4 + pkt_size)) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); pkt->stream_index = cin->video_stream_index; pkt->pts = cin->video_stream_pts++; @@ -192,7 +189,7 @@ static int cin_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->data[3] = hdr->video_frame_type; if (get_buffer(pb, &pkt->data[4], pkt_size) != pkt_size) - return AVERROR_IO; + return AVERROR(EIO); /* sound buffer will be processed on next read_packet() call */ cin->audio_buffer_size = hdr->audio_frame_size; @@ -201,14 +198,14 @@ static int cin_read_packet(AVFormatContext *s, AVPacket *pkt) /* audio packet */ if (av_new_packet(pkt, cin->audio_buffer_size)) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); pkt->stream_index = cin->audio_stream_index; pkt->pts = cin->audio_stream_pts; cin->audio_stream_pts += cin->audio_buffer_size * 2 / cin->file_header.audio_frame_size; if (get_buffer(pb, pkt->data, cin->audio_buffer_size) != cin->audio_buffer_size) - return AVERROR_IO; + return AVERROR(EIO); cin->audio_buffer_size = 0; return 0; diff --git a/contrib/ffmpeg/libavformat/dv.c b/contrib/ffmpeg/libavformat/dv.c index 10a306260..6fb27bfe0 100644 --- a/contrib/ffmpeg/libavformat/dv.c +++ b/contrib/ffmpeg/libavformat/dv.c @@ -347,7 +347,7 @@ static int64_t dv_frame_offset(AVFormatContext *s, DVDemuxContext *c, // FIXME: sys may be wrong if last dv_read_packet() failed (buffer is junk) const DVprofile* sys = dv_codec_profile(c->vst->codec); int64_t offset; - int64_t size = url_fsize(&s->pb); + int64_t size = url_fsize(s->pb); int64_t max_offset = ((size-1) / sys->frame_size) * sys->frame_size; offset = sys->frame_size * timestamp; @@ -386,9 +386,9 @@ static int dv_read_header(AVFormatContext *s, if (!c->dv_demux) return -1; - if (get_buffer(&s->pb, c->buf, DV_PROFILE_BYTES) <= 0 || - url_fseek(&s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0) - return AVERROR_IO; + if (get_buffer(s->pb, c->buf, DV_PROFILE_BYTES) <= 0 || + url_fseek(s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0) + return AVERROR(EIO); c->dv_demux->sys = dv_frame_profile(c->buf); s->bit_rate = av_rescale(c->dv_demux->sys->frame_size * 8, @@ -408,8 +408,8 @@ static int dv_read_packet(AVFormatContext *s, AVPacket *pkt) if (size < 0) { size = c->dv_demux->sys->frame_size; - if (get_buffer(&s->pb, c->buf, size) <= 0) - return AVERROR_IO; + if (get_buffer(s->pb, c->buf, size) <= 0) + return AVERROR(EIO); size = dv_produce_packet(c->dv_demux, pkt, c->buf, size); } @@ -426,7 +426,8 @@ static int dv_read_seek(AVFormatContext *s, int stream_index, dv_offset_reset(c, offset / c->sys->frame_size); - return url_fseek(&s->pb, offset, SEEK_SET); + offset = url_fseek(s->pb, offset, SEEK_SET); + return (offset < 0)?offset:0; } static int dv_read_close(AVFormatContext *s) diff --git a/contrib/ffmpeg/libavformat/dv.h b/contrib/ffmpeg/libavformat/dv.h index 2fa30036c..cfe93533a 100644 --- a/contrib/ffmpeg/libavformat/dv.h +++ b/contrib/ffmpeg/libavformat/dv.h @@ -25,6 +25,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef FFMPEG_DV_H +#define FFMPEG_DV_H + +#include "avformat.h" + typedef struct DVDemuxContext DVDemuxContext; DVDemuxContext* dv_init_demux(AVFormatContext* s); int dv_get_packet(DVDemuxContext*, AVPacket *); @@ -35,3 +40,5 @@ typedef struct DVMuxContext DVMuxContext; DVMuxContext* dv_init_mux(AVFormatContext* s); int dv_assemble_frame(DVMuxContext *c, AVStream*, const uint8_t*, int, uint8_t**); void dv_delete_mux(DVMuxContext*); + +#endif /* FFMPEG_DV_H */ diff --git a/contrib/ffmpeg/libavformat/dv1394.c b/contrib/ffmpeg/libavformat/dv1394.c deleted file mode 100644 index 3a5f479c8..000000000 --- a/contrib/ffmpeg/libavformat/dv1394.c +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Linux DV1394 interface - * Copyright (c) 2003 Max Krasnyansky - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "avformat.h" - -#undef DV1394_DEBUG - -#include "dv1394.h" -#include "dv.h" - -struct dv1394_data { - int fd; - int channel; - int format; - - uint8_t *ring; /* Ring buffer */ - int index; /* Current frame index */ - int avail; /* Number of frames available for reading */ - int done; /* Number of completed frames */ - - DVDemuxContext* dv_demux; /* Generic DV muxing/demuxing context */ -}; - -/* - * The trick here is to kludge around well known problem with kernel Ooopsing - * when you try to capture PAL on a device node configure for NTSC. That's - * why we have to configure the device node for PAL, and then read only NTSC - * amount of data. - */ -static int dv1394_reset(struct dv1394_data *dv) -{ - struct dv1394_init init; - - init.channel = dv->channel; - init.api_version = DV1394_API_VERSION; - init.n_frames = DV1394_RING_FRAMES; - init.format = DV1394_PAL; - - if (ioctl(dv->fd, DV1394_INIT, &init) < 0) - return -1; - - dv->avail = dv->done = 0; - return 0; -} - -static int dv1394_start(struct dv1394_data *dv) -{ - /* Tell DV1394 driver to enable receiver */ - if (ioctl(dv->fd, DV1394_START_RECEIVE, 0) < 0) { - perror("Failed to start receiver"); - return -1; - } - return 0; -} - -static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap) -{ - struct dv1394_data *dv = context->priv_data; - - dv->dv_demux = dv_init_demux(context); - if (!dv->dv_demux) - goto failed; - - if (ap->standard && !strcasecmp(ap->standard, "pal")) - dv->format = DV1394_PAL; - else - dv->format = DV1394_NTSC; - - if (ap->channel) - dv->channel = ap->channel; - else - dv->channel = DV1394_DEFAULT_CHANNEL; - - /* Open and initialize DV1394 device */ - dv->fd = open(context->filename, O_RDONLY); - if (dv->fd < 0) { - perror("Failed to open DV interface"); - goto failed; - } - - if (dv1394_reset(dv) < 0) { - perror("Failed to initialize DV interface"); - goto failed; - } - - dv->ring = mmap(NULL, DV1394_PAL_FRAME_SIZE * DV1394_RING_FRAMES, - PROT_READ, MAP_PRIVATE, dv->fd, 0); - if (dv->ring == MAP_FAILED) { - perror("Failed to mmap DV ring buffer"); - goto failed; - } - - if (dv1394_start(dv) < 0) - goto failed; - - return 0; - -failed: - close(dv->fd); - return AVERROR_IO; -} - -static int dv1394_read_packet(AVFormatContext *context, AVPacket *pkt) -{ - struct dv1394_data *dv = context->priv_data; - int size; - - size = dv_get_packet(dv->dv_demux, pkt); - if (size > 0) - return size; - - if (!dv->avail) { - struct dv1394_status s; - struct pollfd p; - - if (dv->done) { - /* Request more frames */ - if (ioctl(dv->fd, DV1394_RECEIVE_FRAMES, dv->done) < 0) { - /* This usually means that ring buffer overflowed. - * We have to reset :(. - */ - - av_log(context, AV_LOG_ERROR, "DV1394: Ring buffer overflow. Reseting ..\n"); - - dv1394_reset(dv); - dv1394_start(dv); - } - dv->done = 0; - } - - /* Wait until more frames are available */ -restart_poll: - p.fd = dv->fd; - p.events = POLLIN | POLLERR | POLLHUP; - if (poll(&p, 1, -1) < 0) { - if (errno == EAGAIN || errno == EINTR) - goto restart_poll; - perror("Poll failed"); - return AVERROR_IO; - } - - if (ioctl(dv->fd, DV1394_GET_STATUS, &s) < 0) { - perror("Failed to get status"); - return AVERROR_IO; - } -#ifdef DV1394_DEBUG - av_log(context, AV_LOG_DEBUG, "DV1394: status\n" - "\tactive_frame\t%d\n" - "\tfirst_clear_frame\t%d\n" - "\tn_clear_frames\t%d\n" - "\tdropped_frames\t%d\n", - s.active_frame, s.first_clear_frame, - s.n_clear_frames, s.dropped_frames); -#endif - - dv->avail = s.n_clear_frames; - dv->index = s.first_clear_frame; - dv->done = 0; - - if (s.dropped_frames) { - av_log(context, AV_LOG_ERROR, "DV1394: Frame drop detected (%d). Reseting ..\n", - s.dropped_frames); - - dv1394_reset(dv); - dv1394_start(dv); - } - } - -#ifdef DV1394_DEBUG - av_log(context, AV_LOG_DEBUG, "index %d, avail %d, done %d\n", dv->index, dv->avail, - dv->done); -#endif - - size = dv_produce_packet(dv->dv_demux, pkt, - dv->ring + (dv->index * DV1394_PAL_FRAME_SIZE), - DV1394_PAL_FRAME_SIZE); - dv->index = (dv->index + 1) % DV1394_RING_FRAMES; - dv->done++; dv->avail--; - - return size; -} - -static int dv1394_close(AVFormatContext * context) -{ - struct dv1394_data *dv = context->priv_data; - - /* Shutdown DV1394 receiver */ - if (ioctl(dv->fd, DV1394_SHUTDOWN, 0) < 0) - perror("Failed to shutdown DV1394"); - - /* Unmap ring buffer */ - if (munmap(dv->ring, DV1394_NTSC_FRAME_SIZE * DV1394_RING_FRAMES) < 0) - perror("Failed to munmap DV1394 ring buffer"); - - close(dv->fd); - av_free(dv->dv_demux); - - return 0; -} - -AVInputFormat dv1394_demuxer = { - .name = "dv1394", - .long_name = "dv1394 A/V grab", - .priv_data_size = sizeof(struct dv1394_data), - .read_header = dv1394_read_header, - .read_packet = dv1394_read_packet, - .read_close = dv1394_close, - .flags = AVFMT_NOFILE -}; diff --git a/contrib/ffmpeg/libavformat/dv1394.h b/contrib/ffmpeg/libavformat/dv1394.h deleted file mode 100644 index f7db40108..000000000 --- a/contrib/ffmpeg/libavformat/dv1394.h +++ /dev/null @@ -1,357 +0,0 @@ -/* - * dv1394.h - DV input/output over IEEE 1394 on OHCI chips - * Copyright (C)2001 Daniel Maas - * receive, proc_fs by Dan Dennedy - * - * based on: - * video1394.h - driver for OHCI 1394 boards - * Copyright (C)1999,2000 Sebastien Rougeaux - * Peter Schlaile - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef _DV_1394_H -#define _DV_1394_H - -#define DV1394_DEFAULT_CHANNEL 63 -#define DV1394_DEFAULT_CARD 0 -#define DV1394_RING_FRAMES 20 - -#define DV1394_WIDTH 720 -#define DV1394_NTSC_HEIGHT 480 -#define DV1394_PAL_HEIGHT 576 - -/* This is the public user-space interface. Try not to break it. */ - -#define DV1394_API_VERSION 0x20011127 - -/* ******************** - ** ** - ** DV1394 API ** - ** ** - ******************** - - There are two methods of operating the DV1394 DV output device. - - 1) - - The simplest is an interface based on write(): simply write - full DV frames of data to the device, and they will be transmitted - as quickly as possible. The FD may be set for non-blocking I/O, - in which case you can use select() or poll() to wait for output - buffer space. - - To set the DV output parameters (e.g. whether you want NTSC or PAL - video), use the DV1394_INIT ioctl, passing in the parameters you - want in a struct dv1394_init. - - Example 1: - To play a raw .DV file: cat foo.DV > /dev/dv1394 - (cat will use write() internally) - - Example 2: - static struct dv1394_init init = { - 0x63, (broadcast channel) - 4, (four-frame ringbuffer) - DV1394_NTSC, (send NTSC video) - 0, 0 (default empty packet rate) - } - - ioctl(fd, DV1394_INIT, &init); - - while(1) { - read(
, buf, DV1394_NTSC_FRAME_SIZE ); - write( , buf, DV1394_NTSC_FRAME_SIZE ); - } - - 2) - - For more control over buffering, and to avoid unnecessary copies - of the DV data, you can use the more sophisticated the mmap() interface. - First, call the DV1394_INIT ioctl to specify your parameters, - including the number of frames in the ringbuffer. Then, calling mmap() - on the dv1394 device will give you direct access to the ringbuffer - from which the DV card reads your frame data. - - The ringbuffer is simply one large, contiguous region of memory - containing two or more frames of packed DV data. Each frame of DV data - is 120000 bytes (NTSC) or 144000 bytes (PAL). - - Fill one or more frames in the ringbuffer, then use the DV1394_SUBMIT_FRAMES - ioctl to begin I/O. You can use either the DV1394_WAIT_FRAMES ioctl - or select()/poll() to wait until the frames are transmitted. Next, you'll - need to call the DV1394_GET_STATUS ioctl to determine which ringbuffer - frames are clear (ready to be filled with new DV data). Finally, use - DV1394_SUBMIT_FRAMES again to send the new data to the DV output. - - - Example: here is what a four-frame ringbuffer might look like - during DV transmission: - - - frame 0 frame 1 frame 2 frame 3 - - *--------------------------------------* - | CLEAR | DV data | DV data | CLEAR | - *--------------------------------------* - - - transmission goes in this direction --->>> - - - The DV hardware is currently transmitting the data in frame 1. - Once frame 1 is finished, it will automatically transmit frame 2. - (if frame 2 finishes before frame 3 is submitted, the device - will continue to transmit frame 2, and will increase the dropped_frames - counter each time it repeats the transmission). - - - If you called DV1394_GET_STATUS at this instant, you would - receive the following values: - - n_frames = 4 - active_frame = 1 - first_clear_frame = 3 - n_clear_frames = 2 - - At this point, you should write new DV data into frame 3 and optionally - frame 0. Then call DV1394_SUBMIT_FRAMES to inform the device that - it may transmit the new frames. - - ERROR HANDLING - - An error (buffer underflow/overflow or a break in the DV stream due - to a 1394 bus reset) can be detected by checking the dropped_frames - field of struct dv1394_status (obtained through the - DV1394_GET_STATUS ioctl). - - The best way to recover from such an error is to re-initialize - dv1394, either by using the DV1394_INIT ioctl call, or closing the - file descriptor and opening it again. (note that you must unmap all - ringbuffer mappings when closing the file descriptor, or else - dv1394 will still be considered 'in use'). - - MAIN LOOP - - For maximum efficiency and robustness against bus errors, you are - advised to model the main loop of your application after the - following pseudo-code example: - - (checks of system call return values omitted for brevity; always - check return values in your code!) - - while( frames left ) { - - struct pollfd *pfd = ...; - - pfd->fd = dv1394_fd; - pfd->revents = 0; - pfd->events = POLLOUT | POLLIN; (OUT for transmit, IN for receive) - - (add other sources of I/O here) - - poll(pfd, 1, -1); (or select(); add a timeout if you want) - - if(pfd->revents) { - struct dv1394_status status; - - ioctl(dv1394_fd, DV1394_GET_STATUS, &status); - - if(status.dropped_frames > 0) { - reset_dv1394(); - } else { - for(int i = 0; i < status.n_clear_frames; i++) { - copy_DV_frame(); - } - } - } - } - - where copy_DV_frame() reads or writes on the dv1394 file descriptor - (read/write mode) or copies data to/from the mmap ringbuffer and - then calls ioctl(DV1394_SUBMIT_FRAMES) to notify dv1394 that new - frames are availble (mmap mode). - - reset_dv1394() is called in the event of a buffer - underflow/overflow or a halt in the DV stream (e.g. due to a 1394 - bus reset). To guarantee recovery from the error, this function - should close the dv1394 file descriptor (and munmap() all - ringbuffer mappings, if you are using them), then re-open the - dv1394 device (and re-map the ringbuffer). - -*/ - - -/* maximum number of frames in the ringbuffer */ -#define DV1394_MAX_FRAMES 32 - -/* number of *full* isochronous packets per DV frame */ -#define DV1394_NTSC_PACKETS_PER_FRAME 250 -#define DV1394_PAL_PACKETS_PER_FRAME 300 - -/* size of one frame's worth of DV data, in bytes */ -#define DV1394_NTSC_FRAME_SIZE (480 * DV1394_NTSC_PACKETS_PER_FRAME) -#define DV1394_PAL_FRAME_SIZE (480 * DV1394_PAL_PACKETS_PER_FRAME) - - -/* ioctl() commands */ - -enum { - /* I don't like using 0 as a valid ioctl() */ - DV1394_INVALID = 0, - - - /* get the driver ready to transmit video. - pass a struct dv1394_init* as the parameter (see below), - or NULL to get default parameters */ - DV1394_INIT, - - - /* stop transmitting video and free the ringbuffer */ - DV1394_SHUTDOWN, - - - /* submit N new frames to be transmitted, where - the index of the first new frame is first_clear_buffer, - and the index of the last new frame is - (first_clear_buffer + N) % n_frames */ - DV1394_SUBMIT_FRAMES, - - - /* block until N buffers are clear (pass N as the parameter) - Because we re-transmit the last frame on underrun, there - will at most be n_frames - 1 clear frames at any time */ - DV1394_WAIT_FRAMES, - - /* capture new frames that have been received, where - the index of the first new frame is first_clear_buffer, - and the index of the last new frame is - (first_clear_buffer + N) % n_frames */ - DV1394_RECEIVE_FRAMES, - - - DV1394_START_RECEIVE, - - - /* pass a struct dv1394_status* as the parameter (see below) */ - DV1394_GET_STATUS, -}; - - - -enum pal_or_ntsc { - DV1394_NTSC = 0, - DV1394_PAL -}; - - - - -/* this is the argument to DV1394_INIT */ -struct dv1394_init { - /* DV1394_API_VERSION */ - unsigned int api_version; - - /* isochronous transmission channel to use */ - unsigned int channel; - - /* number of frames in the ringbuffer. Must be at least 2 - and at most DV1394_MAX_FRAMES. */ - unsigned int n_frames; - - /* send/receive PAL or NTSC video format */ - enum pal_or_ntsc format; - - /* the following are used only for transmission */ - - /* set these to zero unless you want a - non-default empty packet rate (see below) */ - unsigned long cip_n; - unsigned long cip_d; - - /* set this to zero unless you want a - non-default SYT cycle offset (default = 3 cycles) */ - unsigned int syt_offset; -}; - -/* NOTE: you may only allocate the DV frame ringbuffer once each time - you open the dv1394 device. DV1394_INIT will fail if you call it a - second time with different 'n_frames' or 'format' arguments (which - would imply a different size for the ringbuffer). If you need a - different buffer size, simply close and re-open the device, then - initialize it with your new settings. */ - -/* Q: What are cip_n and cip_d? */ - -/* - A: DV video streams do not utilize 100% of the potential bandwidth offered - by IEEE 1394 (FireWire). To achieve the correct rate of data transmission, - DV devices must periodically insert empty packets into the 1394 data stream. - Typically there is one empty packet per 14-16 data-carrying packets. - - Some DV devices will accept a wide range of empty packet rates, while others - require a precise rate. If the dv1394 driver produces empty packets at - a rate that your device does not accept, you may see ugly patterns on the - DV output, or even no output at all. - - The default empty packet insertion rate seems to work for many people; if - your DV output is stable, you can simply ignore this discussion. However, - we have exposed the empty packet rate as a parameter to support devices that - do not work with the default rate. - - The decision to insert an empty packet is made with a numerator/denominator - algorithm. Empty packets are produced at an average rate of CIP_N / CIP_D. - You can alter the empty packet rate by passing non-zero values for cip_n - and cip_d to the INIT ioctl. - - */ - - - -struct dv1394_status { - /* this embedded init struct returns the current dv1394 - parameters in use */ - struct dv1394_init init; - - /* the ringbuffer frame that is currently being - displayed. (-1 if the device is not transmitting anything) */ - int active_frame; - - /* index of the first buffer (ahead of active_frame) that - is ready to be filled with data */ - unsigned int first_clear_frame; - - /* how many buffers, including first_clear_buffer, are - ready to be filled with data */ - unsigned int n_clear_frames; - - /* how many times the DV stream has underflowed, overflowed, - or otherwise encountered an error, since the previous call - to DV1394_GET_STATUS */ - unsigned int dropped_frames; - - /* N.B. The dropped_frames counter is only a lower bound on the actual - number of dropped frames, with the special case that if dropped_frames - is zero, then it is guaranteed that NO frames have been dropped - since the last call to DV1394_GET_STATUS. - */ -}; - - -#endif /* _DV_1394_H */ diff --git a/contrib/ffmpeg/libavformat/dvenc.c b/contrib/ffmpeg/libavformat/dvenc.c index bdac43784..0d6002818 100644 --- a/contrib/ffmpeg/libavformat/dvenc.c +++ b/contrib/ffmpeg/libavformat/dvenc.c @@ -77,100 +77,100 @@ static int dv_write_pack(enum dv_pack_type pack_id, DVMuxContext *c, uint8_t* bu buf[0] = (uint8_t)pack_id; switch (pack_id) { case dv_timecode: - ct = (time_t)(c->frames / ((float)c->sys->frame_rate / - (float)c->sys->frame_rate_base)); - brktimegm(ct, &tc); - /* - * LTC drop-frame frame counter drops two frames (0 and 1) every - * minute, unless it is exactly divisible by 10 - */ - ltc_frame = (c->frames + 2*ct/60 - 2*ct/600) % c->sys->ltc_divisor; - buf[1] = (0 << 7) | /* Color fame: 0 - unsync; 1 - sync mode */ - (1 << 6) | /* Drop frame timecode: 0 - nondrop; 1 - drop */ - ((ltc_frame / 10) << 4) | /* Tens of frames */ - (ltc_frame % 10); /* Units of frames */ - buf[2] = (1 << 7) | /* Biphase mark polarity correction: 0 - even; 1 - odd */ - ((tc.tm_sec / 10) << 4) | /* Tens of seconds */ - (tc.tm_sec % 10); /* Units of seconds */ - buf[3] = (1 << 7) | /* Binary group flag BGF0 */ - ((tc.tm_min / 10) << 4) | /* Tens of minutes */ - (tc.tm_min % 10); /* Units of minutes */ - buf[4] = (1 << 7) | /* Binary group flag BGF2 */ - (1 << 6) | /* Binary group flag BGF1 */ - ((tc.tm_hour / 10) << 4) | /* Tens of hours */ - (tc.tm_hour % 10); /* Units of hours */ - break; + ct = (time_t)(c->frames / ((float)c->sys->frame_rate / + (float)c->sys->frame_rate_base)); + brktimegm(ct, &tc); + /* + * LTC drop-frame frame counter drops two frames (0 and 1) every + * minute, unless it is exactly divisible by 10 + */ + ltc_frame = (c->frames + 2*ct/60 - 2*ct/600) % c->sys->ltc_divisor; + buf[1] = (0 << 7) | /* Color fame: 0 - unsync; 1 - sync mode */ + (1 << 6) | /* Drop frame timecode: 0 - nondrop; 1 - drop */ + ((ltc_frame / 10) << 4) | /* Tens of frames */ + (ltc_frame % 10); /* Units of frames */ + buf[2] = (1 << 7) | /* Biphase mark polarity correction: 0 - even; 1 - odd */ + ((tc.tm_sec / 10) << 4) | /* Tens of seconds */ + (tc.tm_sec % 10); /* Units of seconds */ + buf[3] = (1 << 7) | /* Binary group flag BGF0 */ + ((tc.tm_min / 10) << 4) | /* Tens of minutes */ + (tc.tm_min % 10); /* Units of minutes */ + buf[4] = (1 << 7) | /* Binary group flag BGF2 */ + (1 << 6) | /* Binary group flag BGF1 */ + ((tc.tm_hour / 10) << 4) | /* Tens of hours */ + (tc.tm_hour % 10); /* Units of hours */ + break; case dv_audio_source: /* AAUX source pack */ - va_start(ap, buf); - buf[1] = (1 << 7) | /* locked mode -- SMPTE only supports locked mode */ - (1 << 6) | /* reserved -- always 1 */ - (dv_audio_frame_size(c->sys, c->frames) - - c->sys->audio_min_samples[0]); - /* # of samples */ - buf[2] = (0 << 7) | /* multi-stereo */ - (0 << 5) | /* #of audio channels per block: 0 -- 1 channel */ - (0 << 4) | /* pair bit: 0 -- one pair of channels */ - !!va_arg(ap, int); /* audio mode */ - buf[3] = (1 << 7) | /* res */ - (1 << 6) | /* multi-language flag */ - (c->sys->dsf << 5) | /* system: 60fields/50fields */ - (c->sys->n_difchan & 2); /* definition: 0 -- 25Mbps, 2 -- 50Mbps */ - buf[4] = (1 << 7) | /* emphasis: 1 -- off */ - (0 << 6) | /* emphasis time constant: 0 -- reserved */ - (0 << 3) | /* frequency: 0 -- 48Khz, 1 -- 44,1Khz, 2 -- 32Khz */ - 0; /* quantization: 0 -- 16bit linear, 1 -- 12bit nonlinear */ - va_end(ap); - break; + va_start(ap, buf); + buf[1] = (1 << 7) | /* locked mode -- SMPTE only supports locked mode */ + (1 << 6) | /* reserved -- always 1 */ + (dv_audio_frame_size(c->sys, c->frames) - + c->sys->audio_min_samples[0]); + /* # of samples */ + buf[2] = (0 << 7) | /* multi-stereo */ + (0 << 5) | /* #of audio channels per block: 0 -- 1 channel */ + (0 << 4) | /* pair bit: 0 -- one pair of channels */ + !!va_arg(ap, int); /* audio mode */ + buf[3] = (1 << 7) | /* res */ + (1 << 6) | /* multi-language flag */ + (c->sys->dsf << 5) | /* system: 60fields/50fields */ + (c->sys->n_difchan & 2); /* definition: 0 -- 25Mbps, 2 -- 50Mbps */ + buf[4] = (1 << 7) | /* emphasis: 1 -- off */ + (0 << 6) | /* emphasis time constant: 0 -- reserved */ + (0 << 3) | /* frequency: 0 -- 48Khz, 1 -- 44,1Khz, 2 -- 32Khz */ + 0; /* quantization: 0 -- 16bit linear, 1 -- 12bit nonlinear */ + va_end(ap); + break; case dv_audio_control: - buf[1] = (0 << 6) | /* copy protection: 0 -- unrestricted */ - (1 << 4) | /* input source: 1 -- digital input */ - (3 << 2) | /* compression: 3 -- no information */ - 0; /* misc. info/SMPTE emphasis off */ - buf[2] = (1 << 7) | /* recording start point: 1 -- no */ - (1 << 6) | /* recording end point: 1 -- no */ - (1 << 3) | /* recording mode: 1 -- original */ - 7; - buf[3] = (1 << 7) | /* direction: 1 -- forward */ - (c->sys->pix_fmt == PIX_FMT_YUV420P ? 0x20 : /* speed */ - c->sys->ltc_divisor*4); - buf[4] = (1 << 7) | /* reserved -- always 1 */ - 0x7f; /* genre category */ - break; + buf[1] = (0 << 6) | /* copy protection: 0 -- unrestricted */ + (1 << 4) | /* input source: 1 -- digital input */ + (3 << 2) | /* compression: 3 -- no information */ + 0; /* misc. info/SMPTE emphasis off */ + buf[2] = (1 << 7) | /* recording start point: 1 -- no */ + (1 << 6) | /* recording end point: 1 -- no */ + (1 << 3) | /* recording mode: 1 -- original */ + 7; + buf[3] = (1 << 7) | /* direction: 1 -- forward */ + (c->sys->pix_fmt == PIX_FMT_YUV420P ? 0x20 : /* speed */ + c->sys->ltc_divisor*4); + buf[4] = (1 << 7) | /* reserved -- always 1 */ + 0x7f; /* genre category */ + break; case dv_audio_recdate: case dv_video_recdate: /* VAUX recording date */ - ct = c->start_time + (time_t)(c->frames / - ((float)c->sys->frame_rate / (float)c->sys->frame_rate_base)); - brktimegm(ct, &tc); - buf[1] = 0xff; /* ds, tm, tens of time zone, units of time zone */ - /* 0xff is very likely to be "unknown" */ - buf[2] = (3 << 6) | /* reserved -- always 1 */ - ((tc.tm_mday / 10) << 4) | /* Tens of day */ - (tc.tm_mday % 10); /* Units of day */ - buf[3] = /* we set high 4 bits to 0, shouldn't we set them to week? */ - ((tc.tm_mon / 10) << 4) | /* Tens of month */ - (tc.tm_mon % 10); /* Units of month */ - buf[4] = (((tc.tm_year % 100) / 10) << 4) | /* Tens of year */ - (tc.tm_year % 10); /* Units of year */ - break; + ct = c->start_time + (time_t)(c->frames / + ((float)c->sys->frame_rate / (float)c->sys->frame_rate_base)); + brktimegm(ct, &tc); + buf[1] = 0xff; /* ds, tm, tens of time zone, units of time zone */ + /* 0xff is very likely to be "unknown" */ + buf[2] = (3 << 6) | /* reserved -- always 1 */ + ((tc.tm_mday / 10) << 4) | /* Tens of day */ + (tc.tm_mday % 10); /* Units of day */ + buf[3] = /* we set high 4 bits to 0, shouldn't we set them to week? */ + ((tc.tm_mon / 10) << 4) | /* Tens of month */ + (tc.tm_mon % 10); /* Units of month */ + buf[4] = (((tc.tm_year % 100) / 10) << 4) | /* Tens of year */ + (tc.tm_year % 10); /* Units of year */ + break; case dv_audio_rectime: /* AAUX recording time */ case dv_video_rectime: /* VAUX recording time */ - ct = c->start_time + (time_t)(c->frames / - ((float)c->sys->frame_rate / (float)c->sys->frame_rate_base)); - brktimegm(ct, &tc); - buf[1] = (3 << 6) | /* reserved -- always 1 */ - 0x3f; /* tens of frame, units of frame: 0x3f - "unknown" ? */ - buf[2] = (1 << 7) | /* reserved -- always 1 */ - ((tc.tm_sec / 10) << 4) | /* Tens of seconds */ - (tc.tm_sec % 10); /* Units of seconds */ - buf[3] = (1 << 7) | /* reserved -- always 1 */ - ((tc.tm_min / 10) << 4) | /* Tens of minutes */ - (tc.tm_min % 10); /* Units of minutes */ - buf[4] = (3 << 6) | /* reserved -- always 1 */ - ((tc.tm_hour / 10) << 4) | /* Tens of hours */ - (tc.tm_hour % 10); /* Units of hours */ - break; + ct = c->start_time + (time_t)(c->frames / + ((float)c->sys->frame_rate / (float)c->sys->frame_rate_base)); + brktimegm(ct, &tc); + buf[1] = (3 << 6) | /* reserved -- always 1 */ + 0x3f; /* tens of frame, units of frame: 0x3f - "unknown" ? */ + buf[2] = (1 << 7) | /* reserved -- always 1 */ + ((tc.tm_sec / 10) << 4) | /* Tens of seconds */ + (tc.tm_sec % 10); /* Units of seconds */ + buf[3] = (1 << 7) | /* reserved -- always 1 */ + ((tc.tm_min / 10) << 4) | /* Tens of minutes */ + (tc.tm_min % 10); /* Units of minutes */ + buf[4] = (3 << 6) | /* reserved -- always 1 */ + ((tc.tm_hour / 10) << 4) | /* Tens of hours */ + (tc.tm_hour % 10); /* Units of hours */ + break; default: - buf[1] = buf[2] = buf[3] = buf[4] = 0xff; + buf[1] = buf[2] = buf[3] = buf[4] = 0xff; } return 5; } @@ -181,19 +181,19 @@ static void dv_inject_audio(DVMuxContext *c, int channel, uint8_t* frame_ptr) size = 4 * dv_audio_frame_size(c->sys, c->frames); frame_ptr += channel * c->sys->difseg_size * 150 * 80; for (i = 0; i < c->sys->difseg_size; i++) { - frame_ptr += 6 * 80; /* skip DIF segment header */ - for (j = 0; j < 9; j++) { - dv_write_pack(dv_aaux_packs_dist[i][j], c, &frame_ptr[3], i >= c->sys->difseg_size/2); - for (d = 8; d < 80; d+=2) { - of = c->sys->audio_shuffle[i][j] + (d - 8)/2 * c->sys->audio_stride; - if (of*2 >= size) - continue; - - frame_ptr[d] = av_fifo_peek(&c->audio_data[channel], of*2+1); // FIXME: may be we have to admit - frame_ptr[d+1] = av_fifo_peek(&c->audio_data[channel], of*2); // that DV is a big endian PCM - } - frame_ptr += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */ - } + frame_ptr += 6 * 80; /* skip DIF segment header */ + for (j = 0; j < 9; j++) { + dv_write_pack(dv_aaux_packs_dist[i][j], c, &frame_ptr[3], i >= c->sys->difseg_size/2); + for (d = 8; d < 80; d+=2) { + of = c->sys->audio_shuffle[i][j] + (d - 8)/2 * c->sys->audio_stride; + if (of*2 >= size) + continue; + + frame_ptr[d] = av_fifo_peek(&c->audio_data[channel], of*2+1); // FIXME: may be we have to admit + frame_ptr[d+1] = av_fifo_peek(&c->audio_data[channel], of*2); // that DV is a big endian PCM + } + frame_ptr += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */ + } } } @@ -240,39 +240,41 @@ int dv_assemble_frame(DVMuxContext *c, AVStream* st, switch (st->codec->codec_type) { case CODEC_TYPE_VIDEO: - /* FIXME: we have to have more sensible approach than this one */ - if (c->has_video) - av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames); + /* FIXME: we have to have more sensible approach than this one */ + if (c->has_video) + av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames); - memcpy(*frame, data, c->sys->frame_size); - c->has_video = 1; - break; + memcpy(*frame, data, c->sys->frame_size); + c->has_video = 1; + break; case CODEC_TYPE_AUDIO: - for (i = 0; i < c->n_ast && st != c->ast[i]; i++); + for (i = 0; i < c->n_ast && st != c->ast[i]; i++); /* FIXME: we have to have more sensible approach than this one */ - if (av_fifo_size(&c->audio_data[i]) + data_size >= 100*AVCODEC_MAX_AUDIO_FRAME_SIZE) - av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames); - av_fifo_write(&c->audio_data[i], data, data_size); + if (av_fifo_size(&c->audio_data[i]) + data_size >= 100*AVCODEC_MAX_AUDIO_FRAME_SIZE) + av_log(st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames); + av_fifo_write(&c->audio_data[i], data, data_size); - /* Lets see if we've got enough audio for one DV frame */ - c->has_audio |= ((reqasize <= av_fifo_size(&c->audio_data[i])) << i); + /* Lets see if we've got enough audio for one DV frame */ + c->has_audio |= ((reqasize <= av_fifo_size(&c->audio_data[i])) << i); - break; + break; default: - break; + break; } /* Lets see if we have enough data to construct one DV frame */ if (c->has_video == 1 && c->has_audio + 1 == 1<n_ast) { dv_inject_metadata(c, *frame); + c->has_audio = 0; for (i=0; in_ast; i++) { - dv_inject_audio(c, i, *frame); - av_fifo_drain(&c->audio_data[i], reqasize); + dv_inject_audio(c, i, *frame); + av_fifo_drain(&c->audio_data[i], reqasize); + c->has_audio |= ((reqasize <= av_fifo_size(&c->audio_data[i])) << i); } c->has_video = 0; - c->has_audio = 0; + c->frames++; return c->sys->frame_size; @@ -283,7 +285,7 @@ int dv_assemble_frame(DVMuxContext *c, AVStream* st, DVMuxContext* dv_init_mux(AVFormatContext* s) { - DVMuxContext *c = (DVMuxContext *)s->priv_data; + DVMuxContext *c = s->priv_data; AVStream *vst = NULL; int i; @@ -296,16 +298,18 @@ DVMuxContext* dv_init_mux(AVFormatContext* s) /* We have to sort out where audio and where video stream is */ for (i=0; inb_streams; i++) { - switch (s->streams[i]->codec->codec_type) { - case CODEC_TYPE_VIDEO: - vst = s->streams[i]; - break; - case CODEC_TYPE_AUDIO: - c->ast[c->n_ast++] = s->streams[i]; - break; - default: - goto bail_out; - } + switch (s->streams[i]->codec->codec_type) { + case CODEC_TYPE_VIDEO: + if (vst) return NULL; + vst = s->streams[i]; + break; + case CODEC_TYPE_AUDIO: + if (c->n_ast > 1) return NULL; + c->ast[c->n_ast++] = s->streams[i]; + break; + default: + goto bail_out; + } } /* Some checks -- DV format is very picky about its incoming streams */ @@ -373,11 +377,11 @@ static int dv_write_packet(struct AVFormatContext *s, AVPacket *pkt) uint8_t* frame; int fsize; - fsize = dv_assemble_frame((DVMuxContext *)s->priv_data, s->streams[pkt->stream_index], + fsize = dv_assemble_frame(s->priv_data, s->streams[pkt->stream_index], pkt->data, pkt->size, &frame); if (fsize > 0) { - put_buffer(&s->pb, frame, fsize); - put_flush_packet(&s->pb); + put_buffer(s->pb, frame, fsize); + put_flush_packet(s->pb); } return 0; } @@ -390,7 +394,7 @@ static int dv_write_packet(struct AVFormatContext *s, AVPacket *pkt) */ static int dv_write_trailer(struct AVFormatContext *s) { - dv_delete_mux((DVMuxContext *)s->priv_data); + dv_delete_mux(s->priv_data); return 0; } #endif /* CONFIG_MUXERS */ diff --git a/contrib/ffmpeg/libavformat/dxa.c b/contrib/ffmpeg/libavformat/dxa.c index f49d3d4ac..2df73c7dd 100644 --- a/contrib/ffmpeg/libavformat/dxa.c +++ b/contrib/ffmpeg/libavformat/dxa.c @@ -36,8 +36,6 @@ typedef struct{ static int dxa_probe(AVProbeData *p) { /* check file header */ - if (p->buf_size <= 4) - return 0; if (p->buf[0] == 'D' && p->buf[1] == 'E' && p->buf[2] == 'X' && p->buf[3] == 'A') return AVPROBE_SCORE_MAX; @@ -47,7 +45,7 @@ static int dxa_probe(AVProbeData *p) static int dxa_read_header(AVFormatContext *s, AVFormatParameters *ap) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; DXAContext *c = s->priv_data; AVStream *st, *ast; uint32_t tag; @@ -146,54 +144,54 @@ static int dxa_read_packet(AVFormatContext *s, AVPacket *pkt) if(!c->readvid && c->has_sound && c->bytes_left){ c->readvid = 1; - url_fseek(&s->pb, c->wavpos, SEEK_SET); + url_fseek(s->pb, c->wavpos, SEEK_SET); size = FFMIN(c->bytes_left, c->bpc); - ret = av_get_packet(&s->pb, pkt, size); + ret = av_get_packet(s->pb, pkt, size); pkt->stream_index = 1; if(ret != size) - return AVERROR_IO; + return AVERROR(EIO); c->bytes_left -= size; - c->wavpos = url_ftell(&s->pb); + c->wavpos = url_ftell(s->pb); return 0; } - url_fseek(&s->pb, c->vidpos, SEEK_SET); - while(!url_feof(&s->pb) && c->frames){ - get_buffer(&s->pb, buf, 4); + url_fseek(s->pb, c->vidpos, SEEK_SET); + while(!url_feof(s->pb) && c->frames){ + get_buffer(s->pb, buf, 4); switch(AV_RL32(buf)){ case MKTAG('N', 'U', 'L', 'L'): if(av_new_packet(pkt, 4 + pal_size) < 0) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); pkt->stream_index = 0; if(pal_size) memcpy(pkt->data, pal, pal_size); memcpy(pkt->data + pal_size, buf, 4); c->frames--; - c->vidpos = url_ftell(&s->pb); + c->vidpos = url_ftell(s->pb); c->readvid = 0; return 0; case MKTAG('C', 'M', 'A', 'P'): pal_size = 768+4; memcpy(pal, buf, 4); - get_buffer(&s->pb, pal + 4, 768); + get_buffer(s->pb, pal + 4, 768); break; case MKTAG('F', 'R', 'A', 'M'): - get_buffer(&s->pb, buf + 4, DXA_EXTRA_SIZE - 4); + get_buffer(s->pb, buf + 4, DXA_EXTRA_SIZE - 4); size = AV_RB32(buf + 5); if(size > 0xFFFFFF){ av_log(s, AV_LOG_ERROR, "Frame size is too big: %d\n", size); return -1; } if(av_new_packet(pkt, size + DXA_EXTRA_SIZE + pal_size) < 0) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); memcpy(pkt->data + pal_size, buf, DXA_EXTRA_SIZE); - ret = get_buffer(&s->pb, pkt->data + DXA_EXTRA_SIZE + pal_size, size); + ret = get_buffer(s->pb, pkt->data + DXA_EXTRA_SIZE + pal_size, size); if(ret != size){ av_free_packet(pkt); - return AVERROR_IO; + return AVERROR(EIO); } if(pal_size) memcpy(pkt->data, pal, pal_size); pkt->stream_index = 0; c->frames--; - c->vidpos = url_ftell(&s->pb); + c->vidpos = url_ftell(s->pb); c->readvid = 0; return 0; default: diff --git a/contrib/ffmpeg/libavformat/eacdata.c b/contrib/ffmpeg/libavformat/eacdata.c new file mode 100644 index 000000000..ffaf85e0e --- /dev/null +++ b/contrib/ffmpeg/libavformat/eacdata.c @@ -0,0 +1,100 @@ +/* + * Electronic Arts .cdata file Demuxer + * Copyright (c) 2007 Peter Ross + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file eacdata.c + * Electronic Arts cdata Format Demuxer + * by Peter Ross (suxen_drol at hotmail dot com) + * + * Technical details here: + * http://wiki.multimedia.cx/index.php?title=EA_Command_And_Conquer_3_Audio_Codec + */ + +#include "avformat.h" + +typedef struct { + unsigned int channels; + unsigned int audio_pts; +} CdataDemuxContext; + +static int cdata_probe(AVProbeData *p) +{ + const uint8_t *b = p->buf; + + if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C)) + return AVPROBE_SCORE_MAX/8; + return 0; +} + +static int cdata_read_header(AVFormatContext *s, AVFormatParameters *ap) +{ + CdataDemuxContext *cdata = s->priv_data; + ByteIOContext *pb = s->pb; + unsigned int sample_rate, header; + AVStream *st; + + header = get_be16(pb); + switch (header) { + case 0x0400: cdata->channels = 1; break; + case 0x0404: cdata->channels = 2; break; + case 0x040C: cdata->channels = 4; break; + default: + av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header); + return -1; + }; + + sample_rate = get_be16(pb); + url_fskip(pb, 12); + + st = av_new_stream(s, 0); + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_tag = 0; /* no fourcc */ + st->codec->codec_id = CODEC_ID_ADPCM_EA_XAS; + st->codec->channels = cdata->channels; + st->codec->sample_rate = sample_rate; + av_set_pts_info(st, 64, 1, sample_rate); + + cdata->audio_pts = 0; + return 0; +} + +static int cdata_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + CdataDemuxContext *cdata = s->priv_data; + int packet_size = 76*cdata->channels; + + if (av_get_packet(s->pb, pkt, packet_size) != packet_size) + return AVERROR(EIO); + pkt->pts = cdata->audio_pts++; + return 1; +} + +AVInputFormat ea_cdata_demuxer = { + "ea_cdata", + "Electronic Arts cdata", + sizeof(CdataDemuxContext), + cdata_probe, + cdata_read_header, + cdata_read_packet, + .extensions = "cdata", +}; diff --git a/contrib/ffmpeg/libavformat/electronicarts.c b/contrib/ffmpeg/libavformat/electronicarts.c index 762d658ab..0201e8200 100644 --- a/contrib/ffmpeg/libavformat/electronicarts.c +++ b/contrib/ffmpeg/libavformat/electronicarts.c @@ -27,33 +27,42 @@ #include "avformat.h" #define SCHl_TAG MKTAG('S', 'C', 'H', 'l') +#define SEAD_TAG MKTAG('S', 'E', 'A', 'D') /* Sxxx header */ +#define SNDC_TAG MKTAG('S', 'N', 'D', 'C') /* Sxxx data */ +#define SEND_TAG MKTAG('S', 'E', 'N', 'D') /* Sxxx end */ +#define ISNh_TAG MKTAG('1', 'S', 'N', 'h') /* 1SNx header */ +#define EACS_TAG MKTAG('E', 'A', 'C', 'S') +#define ISNd_TAG MKTAG('1', 'S', 'N', 'd') /* 1SNx data */ +#define ISNe_TAG MKTAG('1', 'S', 'N', 'e') /* 1SNx end */ #define PT00_TAG MKTAG('P', 'T', 0x0, 0x0) +#define GSTR_TAG MKTAG('G', 'S', 'T', 'R') #define SCDl_TAG MKTAG('S', 'C', 'D', 'l') -#define pIQT_TAG MKTAG('p', 'I', 'Q', 'T') #define SCEl_TAG MKTAG('S', 'C', 'E', 'l') -#define _TAG MKTAG('', '', '', '') - -#define EA_SAMPLE_RATE 22050 -#define EA_BITS_PER_SAMPLE 16 -#define EA_PREAMBLE_SIZE 8 +#define kVGT_TAG MKTAG('k', 'V', 'G', 'T') /* TGV i-frame */ +#define MADk_TAG MKTAG('M', 'A', 'D', 'k') /* MAD i-frame */ +#define MPCh_TAG MKTAG('M', 'P', 'C', 'h') /* MPEG2 */ +#define MVhd_TAG MKTAG('M', 'V', 'h', 'd') +#define MV0K_TAG MKTAG('M', 'V', '0', 'K') +#define MV0F_TAG MKTAG('M', 'V', '0', 'F') +#define MVIh_TAG MKTAG('M', 'V', 'I', 'h') /* CMV header */ typedef struct EaDemuxContext { - int width; - int height; + int big_endian; + + int video_codec; + AVRational time_base; int video_stream_index; - int track_count; + int audio_codec; int audio_stream_index; int audio_frame_counter; int64_t audio_pts; - int64_t video_pts; - int video_pts_inc; - float fps; + int bytes; + int sample_rate; int num_channels; int num_samples; - int compression_type; } EaDemuxContext; static uint32_t read_arbitary(ByteIOContext *pb) { @@ -74,40 +83,24 @@ static uint32_t read_arbitary(ByteIOContext *pb) { } /* - * Process WVE file header - * Returns 1 if the WVE file is valid and successfully opened, 0 otherwise + * Process PT/GSTR sound header + * return 1 if success, 0 if invalid format, otherwise AVERROR_xxx */ -static int process_ea_header(AVFormatContext *s) { - int inHeader; - uint32_t blockid, size; - EaDemuxContext *ea = (EaDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; - - if (get_buffer(pb, (void*)&blockid, 4) != 4) { - return 0; - } - if (le2me_32(blockid) != SCHl_TAG) { - return 0; - } - - if (get_buffer(pb, (void*)&size, 4) != 4) { - return 0; - } - size = le2me_32(size); +static int process_audio_header_elements(AVFormatContext *s) +{ + int inHeader = 1; + EaDemuxContext *ea = s->priv_data; + ByteIOContext *pb = s->pb; + int compression_type = -1, revision = -1, revision2 = -1; - if (get_buffer(pb, (void*)&blockid, 4) != 4) { - return 0; - } - if (le2me_32(blockid) != PT00_TAG) { - av_log (s, AV_LOG_ERROR, "PT header missing\n"); - return 0; - } + ea->bytes = 2; + ea->sample_rate = -1; + ea->num_channels = 1; - inHeader = 1; while (inHeader) { int inSubheader; uint8_t byte; - byte = get_byte(pb) & 0xFF; + byte = get_byte(pb); switch (byte) { case 0xFD: @@ -115,16 +108,24 @@ static int process_ea_header(AVFormatContext *s) { inSubheader = 1; while (inSubheader) { uint8_t subbyte; - subbyte = get_byte(pb) & 0xFF; + subbyte = get_byte(pb); switch (subbyte) { + case 0x80: + revision = read_arbitary(pb); + av_log (s, AV_LOG_INFO, "revision (element 0x80) set to 0x%08x\n", revision); + break; case 0x82: ea->num_channels = read_arbitary(pb); av_log (s, AV_LOG_INFO, "num_channels (element 0x82) set to 0x%08x\n", ea->num_channels); break; case 0x83: - ea->compression_type = read_arbitary(pb); - av_log (s, AV_LOG_INFO, "compression_type (element 0x83) set to 0x%08x\n", ea->compression_type); + compression_type = read_arbitary(pb); + av_log (s, AV_LOG_INFO, "compression_type (element 0x83) set to 0x%08x\n", compression_type); + break; + case 0x84: + ea->sample_rate = read_arbitary(pb); + av_log (s, AV_LOG_INFO, "sample_rate (element 0x84) set to %i\n", ea->sample_rate); break; case 0x85: ea->num_samples = read_arbitary(pb); @@ -135,6 +136,15 @@ static int process_ea_header(AVFormatContext *s) { av_log (s, AV_LOG_INFO, "exited audio subheader\n"); inSubheader = 0; break; + case 0xA0: + revision2 = read_arbitary(pb); + av_log (s, AV_LOG_INFO, "revision2 (element 0xA0) set to 0x%08x\n", revision2); + break; + case 0xFF: + av_log (s, AV_LOG_INFO, "end of header block reached (within audio subheader)\n"); + inSubheader = 0; + inHeader = 0; + break; default: av_log (s, AV_LOG_INFO, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb)); break; @@ -151,67 +161,218 @@ static int process_ea_header(AVFormatContext *s) { } } - if ((ea->num_channels != 2) || (ea->compression_type != 7)) { - av_log (s, AV_LOG_ERROR, "unsupported stream type\n"); + switch (compression_type) { + case 0: ea->audio_codec = CODEC_ID_PCM_S16LE; break; + case 7: ea->audio_codec = CODEC_ID_ADPCM_EA; break; + case -1: + switch (revision) { + case 1: ea->audio_codec = CODEC_ID_ADPCM_EA_R1; break; + case 2: ea->audio_codec = CODEC_ID_ADPCM_EA_R2; break; + case 3: ea->audio_codec = CODEC_ID_ADPCM_EA_R3; break; + case -1: break; + default: + av_log(s, AV_LOG_ERROR, "unsupported stream type; revision=%i\n", revision); + return 0; + } + switch (revision2) { + case 8: ea->audio_codec = CODEC_ID_PCM_S16LE_PLANAR; break; + default: + av_log(s, AV_LOG_ERROR, "unsupported stream type; revision2=%i\n", revision2); + return 0; + } + break; + default: + av_log(s, AV_LOG_ERROR, "unsupported stream type; compression_type=%i\n", compression_type); return 0; } - /* skip to the start of the data */ - url_fseek(pb, size, SEEK_SET); + if (ea->sample_rate == -1) + ea->sample_rate = revision==3 ? 48000 : 22050; return 1; } +/* + * Process EACS sound header + * return 1 if success, 0 if invalid format, otherwise AVERROR_xxx + */ +static int process_audio_header_eacs(AVFormatContext *s) +{ + EaDemuxContext *ea = s->priv_data; + ByteIOContext *pb = s->pb; + int compression_type; -static int ea_probe(AVProbeData *p) + ea->sample_rate = ea->big_endian ? get_be32(pb) : get_le32(pb); + ea->bytes = get_byte(pb); /* 1=8-bit, 2=16-bit */ + ea->num_channels = get_byte(pb); + compression_type = get_byte(pb); + url_fskip(pb, 13); + + switch (compression_type) { + case 0: + switch (ea->bytes) { + case 1: ea->audio_codec = CODEC_ID_PCM_S8; break; + case 2: ea->audio_codec = CODEC_ID_PCM_S16LE; break; + } + break; + case 1: ea->audio_codec = CODEC_ID_PCM_MULAW; ea->bytes = 1; break; + case 2: ea->audio_codec = CODEC_ID_ADPCM_IMA_EA_EACS; break; + default: + av_log (s, AV_LOG_ERROR, "unsupported stream type; audio compression_type=%i\n", compression_type); + } + + return 1; +} + +/* + * Process SEAD sound header + * return 1 if success, 0 if invalid format, otherwise AVERROR_xxx + */ +static int process_audio_header_sead(AVFormatContext *s) { - if (p->buf_size < 4) - return 0; + EaDemuxContext *ea = s->priv_data; + ByteIOContext *pb = s->pb; - if (AV_RL32(&p->buf[0]) != SCHl_TAG) - return 0; + ea->sample_rate = get_le32(pb); + ea->bytes = get_le32(pb); /* 1=8-bit, 2=16-bit */ + ea->num_channels = get_le32(pb); + ea->audio_codec = CODEC_ID_ADPCM_IMA_EA_SEAD; + + return 1; +} + +static int process_video_header_vp6(AVFormatContext *s) +{ + EaDemuxContext *ea = s->priv_data; + ByteIOContext *pb = s->pb; - return AVPROBE_SCORE_MAX; + url_fskip(pb, 16); + ea->time_base.den = get_le32(pb); + ea->time_base.num = get_le32(pb); + ea->video_codec = CODEC_ID_VP6; + + return 1; +} + +/* + * Process EA file header + * Returns 1 if the EA file is valid and successfully opened, 0 otherwise + */ +static int process_ea_header(AVFormatContext *s) { + uint32_t blockid, size = 0; + EaDemuxContext *ea = s->priv_data; + ByteIOContext *pb = s->pb; + int i; + + for (i=0; i<5 && (!ea->audio_codec || !ea->video_codec); i++) { + unsigned int startpos = url_ftell(pb); + int err = 0; + + blockid = get_le32(pb); + size = get_le32(pb); + if (i == 0) + ea->big_endian = size > 0x000FFFFF; + if (ea->big_endian) + size = bswap_32(size); + + switch (blockid) { + case ISNh_TAG: + if (get_le32(pb) != EACS_TAG) { + av_log (s, AV_LOG_ERROR, "unknown 1SNh headerid\n"); + return 0; + } + err = process_audio_header_eacs(s); + break; + + case SCHl_TAG : + blockid = get_le32(pb); + if (blockid == GSTR_TAG) { + url_fskip(pb, 4); + } else if (blockid != PT00_TAG) { + av_log (s, AV_LOG_ERROR, "unknown SCHl headerid\n"); + return 0; + } + err = process_audio_header_elements(s); + break; + + case SEAD_TAG: + err = process_audio_header_sead(s); + break; + + case MVhd_TAG : + err = process_video_header_vp6(s); + break; + } + + if (err < 0) { + av_log(s, AV_LOG_ERROR, "error parsing header: %i\n", err); + return err; + } + + url_fseek(pb, startpos + size, SEEK_SET); + } + + url_fseek(pb, 0, SEEK_SET); + + return 1; +} + + +static int ea_probe(AVProbeData *p) +{ + switch (AV_RL32(&p->buf[0])) { + case ISNh_TAG: + case SCHl_TAG: + case SEAD_TAG: + case kVGT_TAG: + case MADk_TAG: + case MPCh_TAG: + case MVhd_TAG: + case MVIh_TAG: + return AVPROBE_SCORE_MAX; + } + return 0; } static int ea_read_header(AVFormatContext *s, AVFormatParameters *ap) { - EaDemuxContext *ea = (EaDemuxContext *)s->priv_data; + EaDemuxContext *ea = s->priv_data; AVStream *st; if (!process_ea_header(s)) - return AVERROR_IO; - -#if 0 - /* initialize the video decoder stream */ - st = av_new_stream(s, 0); - if (!st) - return AVERROR_NOMEM; - av_set_pts_info(st, 33, 1, 90000); - ea->video_stream_index = st->index; - st->codec->codec_type = CODEC_TYPE_VIDEO; - st->codec->codec_id = CODEC_ID_EA_MJPEG; - st->codec->codec_tag = 0; /* no fourcc */ -#endif - - /* initialize the audio decoder stream */ - st = av_new_stream(s, 0); - if (!st) - return AVERROR_NOMEM; - av_set_pts_info(st, 33, 1, EA_SAMPLE_RATE); - st->codec->codec_type = CODEC_TYPE_AUDIO; - st->codec->codec_id = CODEC_ID_ADPCM_EA; - st->codec->codec_tag = 0; /* no tag */ - st->codec->channels = ea->num_channels; - st->codec->sample_rate = EA_SAMPLE_RATE; - st->codec->bits_per_sample = EA_BITS_PER_SAMPLE; - st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * - st->codec->bits_per_sample / 4; - st->codec->block_align = st->codec->channels * st->codec->bits_per_sample; - - ea->audio_stream_index = st->index; - ea->audio_frame_counter = 0; + return AVERROR(EIO); + + if (ea->video_codec) { + /* initialize the video decoder stream */ + st = av_new_stream(s, 0); + if (!st) + return AVERROR(ENOMEM); + ea->video_stream_index = st->index; + st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_id = ea->video_codec; + st->codec->codec_tag = 0; /* no fourcc */ + st->codec->time_base = ea->time_base; + } + + if (ea->audio_codec) { + /* initialize the audio decoder stream */ + st = av_new_stream(s, 0); + if (!st) + return AVERROR(ENOMEM); + av_set_pts_info(st, 33, 1, ea->sample_rate); + st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_id = ea->audio_codec; + st->codec->codec_tag = 0; /* no tag */ + st->codec->channels = ea->num_channels; + st->codec->sample_rate = ea->sample_rate; + st->codec->bits_per_sample = ea->bytes * 8; + st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * + st->codec->bits_per_sample / 4; + st->codec->block_align = st->codec->channels*st->codec->bits_per_sample; + ea->audio_stream_index = st->index; + ea->audio_frame_counter = 0; + } return 1; } @@ -220,43 +381,76 @@ static int ea_read_packet(AVFormatContext *s, AVPacket *pkt) { EaDemuxContext *ea = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int ret = 0; int packet_read = 0; - unsigned char preamble[EA_PREAMBLE_SIZE]; unsigned int chunk_type, chunk_size; + int key = 0; while (!packet_read) { - - if (get_buffer(pb, preamble, EA_PREAMBLE_SIZE) != EA_PREAMBLE_SIZE) - return AVERROR_IO; - chunk_type = AV_RL32(&preamble[0]); - chunk_size = AV_RL32(&preamble[4]) - EA_PREAMBLE_SIZE; + chunk_type = get_le32(pb); + chunk_size = (ea->big_endian ? get_be32(pb) : get_le32(pb)) - 8; switch (chunk_type) { /* audio data */ + case ISNh_TAG: + /* header chunk also contains data; skip over the header portion*/ + url_fskip(pb, 32); + chunk_size -= 32; + case ISNd_TAG: case SCDl_TAG: + case SNDC_TAG: + if (!ea->audio_codec) { + url_fskip(pb, chunk_size); + break; + } else if (ea->audio_codec == CODEC_ID_PCM_S16LE_PLANAR) { + url_fskip(pb, 12); /* planar header */ + chunk_size -= 12; + } ret = av_get_packet(pb, pkt, chunk_size); if (ret != chunk_size) - ret = AVERROR_IO; + ret = AVERROR(EIO); else { pkt->stream_index = ea->audio_stream_index; pkt->pts = 90000; pkt->pts *= ea->audio_frame_counter; - pkt->pts /= EA_SAMPLE_RATE; + pkt->pts /= ea->sample_rate; + switch (ea->audio_codec) { + case CODEC_ID_ADPCM_EA: /* 2 samples/byte, 1 or 2 samples per frame depending * on stereo; chunk also has 12-byte header */ ea->audio_frame_counter += ((chunk_size - 12) * 2) / ea->num_channels; + break; + default: + ea->audio_frame_counter += chunk_size / + (ea->bytes * ea->num_channels); + } } packet_read = 1; break; /* ending tag */ + case 0: + case ISNe_TAG: case SCEl_TAG: - ret = AVERROR_IO; + case SEND_TAG: + ret = AVERROR(EIO); + packet_read = 1; + break; + + case MV0K_TAG: + key = PKT_FLAG_KEY; + case MV0F_TAG: + ret = av_get_packet(pb, pkt, chunk_size); + if (ret != chunk_size) + ret = AVERROR_IO; + else { + pkt->stream_index = ea->video_stream_index; + pkt->flags |= key; + } packet_read = 1; break; @@ -264,22 +458,11 @@ static int ea_read_packet(AVFormatContext *s, url_fseek(pb, chunk_size, SEEK_CUR); break; } - - /* ending packet */ - if (chunk_type == SCEl_TAG) { - } } return ret; } -static int ea_read_close(AVFormatContext *s) -{ -// EaDemuxContext *ea = (EaDemuxContext *)s->priv_data; - - return 0; -} - AVInputFormat ea_demuxer = { "ea", "Electronic Arts Multimedia Format", @@ -287,5 +470,4 @@ AVInputFormat ea_demuxer = { ea_probe, ea_read_header, ea_read_packet, - ea_read_close, }; diff --git a/contrib/ffmpeg/libavformat/ffm.c b/contrib/ffmpeg/libavformat/ffm.c index a2970ae42..872e6f0ba 100644 --- a/contrib/ffmpeg/libavformat/ffm.c +++ b/contrib/ffmpeg/libavformat/ffm.c @@ -64,7 +64,7 @@ static void flush_packet(AVFormatContext *s) { FFMContext *ffm = s->priv_data; int fill_size, h; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; fill_size = ffm->packet_end - ffm->packet_ptr; memset(ffm->packet_ptr, 0, fill_size); @@ -128,7 +128,7 @@ static int ffm_write_header(AVFormatContext *s) FFMContext *ffm = s->priv_data; AVStream *st; FFMStream *fst; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVCodecContext *codec; int bit_rate, i; @@ -278,7 +278,7 @@ static int ffm_write_packet(AVFormatContext *s, AVPacket *pkt) static int ffm_write_trailer(AVFormatContext *s) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; FFMContext *ffm = s->priv_data; /* flush packets */ @@ -314,7 +314,7 @@ static int ffm_is_avail_data(AVFormatContext *s, int size) if (size <= len) return 1; } - pos = url_ftell(&s->pb); + pos = url_ftell(s->pb); if (pos == ffm->write_index) { /* exactly at the end of stream */ return 0; @@ -335,7 +335,7 @@ static int ffm_read_data(AVFormatContext *s, uint8_t *buf, int size, int first) { FFMContext *ffm = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int len, fill_size, size1, frame_offset; size1 = size; @@ -393,7 +393,7 @@ static int ffm_read_data(AVFormatContext *s, static void adjust_write_index(AVFormatContext *s) { FFMContext *ffm = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int64_t pts; //offset_t orig_write_index = ffm->write_index; offset_t pos_min, pos_max; @@ -452,7 +452,7 @@ static int ffm_read_header(AVFormatContext *s, AVFormatParameters *ap) FFMContext *ffm = s->priv_data; AVStream *st; FFMStream *fst; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVCodecContext *codec; int i, nb_streams; uint32_t tag; @@ -585,7 +585,7 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt) } #if 0 printf("pos=%08"PRIx64" spos=%"PRIx64", write_index=%"PRIx64" size=%"PRIx64"\n", - url_ftell(&s->pb), s->pb.pos, ffm->write_index, ffm->file_size); + url_ftell(s->pb), s->pb.pos, ffm->write_index, ffm->file_size); #endif if (ffm_read_data(s, ffm->header, FRAME_HEADER_SIZE, 1) != FRAME_HEADER_SIZE) @@ -601,16 +601,16 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt) ffm->read_state = READ_DATA; /* fall thru */ case READ_DATA: - size = (ffm->header[2] << 16) | (ffm->header[3] << 8) | ffm->header[4]; + size = AV_RB24(ffm->header + 2); if (!ffm_is_avail_data(s, size)) { return AVERROR(EAGAIN); } - duration = (ffm->header[5] << 16) | (ffm->header[6] << 8) | ffm->header[7]; + duration = AV_RB24(ffm->header + 5); av_new_packet(pkt, size); pkt->stream_index = ffm->header[0]; - pkt->pos = url_ftell(&s->pb); + pkt->pos = url_ftell(s->pb); if (ffm->header[1] & FLAG_KEY_FRAME) pkt->flags |= PKT_FLAG_KEY; @@ -638,7 +638,7 @@ static int ffm_read_packet(AVFormatContext *s, AVPacket *pkt) static void ffm_seek1(AVFormatContext *s, offset_t pos1) { FFMContext *ffm = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; offset_t pos; pos = pos1 + ffm->write_index; @@ -652,7 +652,7 @@ static void ffm_seek1(AVFormatContext *s, offset_t pos1) static int64_t get_pts(AVFormatContext *s, offset_t pos) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int64_t pts; ffm_seek1(s, pos); @@ -665,7 +665,7 @@ static int64_t get_pts(AVFormatContext *s, offset_t pos) } /* seek to a given time in the file. The file read pointer is - positionned at or before pts. XXX: the following code is quite + positioned at or before pts. XXX: the following code is quite approximative */ static int ffm_seek(AVFormatContext *s, int stream_index, int64_t wanted_pts, int flags) { @@ -714,15 +714,10 @@ static int ffm_seek(AVFormatContext *s, int stream_index, int64_t wanted_pts, in offset_t ffm_read_write_index(int fd) { uint8_t buf[8]; - offset_t pos; - int i; lseek(fd, 8, SEEK_SET); read(fd, buf, 8); - pos = 0; - for(i=0;i<8;i++) - pos |= (int64_t)buf[i] << (56 - i * 8); - return pos; + return AV_RB64(buf); } void ffm_write_write_index(int fd, offset_t pos) @@ -758,7 +753,7 @@ static int ffm_read_close(AVFormatContext *s) static int ffm_probe(AVProbeData *p) { - if (p->buf_size >= 4 && + if ( p->buf[0] == 'F' && p->buf[1] == 'F' && p->buf[2] == 'M' && p->buf[3] == '1') return AVPROBE_SCORE_MAX + 1; diff --git a/contrib/ffmpeg/libavformat/file.c b/contrib/ffmpeg/libavformat/file.c index 3caf80a61..6285c1bba 100644 --- a/contrib/ffmpeg/libavformat/file.c +++ b/contrib/ffmpeg/libavformat/file.c @@ -19,9 +19,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avformat.h" +#include "avstring.h" #include #include #include +#include +#include "os_support.h" /* standard file protocol */ @@ -31,7 +34,7 @@ static int file_open(URLContext *h, const char *filename, int flags) int access; int fd; - strstart(filename, "file:", &filename); + av_strstart(filename, "file:", &filename); if (flags & URL_RDWR) { access = O_CREAT | O_TRUNC | O_RDWR; @@ -40,7 +43,7 @@ static int file_open(URLContext *h, const char *filename, int flags) } else { access = O_RDONLY; } -#if defined(__MINGW32__) || defined(CONFIG_OS2) || defined(__CYGWIN__) +#ifdef O_BINARY access |= O_BINARY; #endif fd = open(filename, access, 0666); @@ -89,13 +92,18 @@ URLProtocol file_protocol = { static int pipe_open(URLContext *h, const char *filename, int flags) { int fd; - - if (flags & URL_WRONLY) { - fd = 1; - } else { - fd = 0; + const char * final; + av_strstart(filename, "pipe:", &filename); + + fd = strtol(filename, &final, 10); + if((filename == final) || *final ) {/* No digits found, or something like 10ab */ + if (flags & URL_WRONLY) { + fd = 1; + } else { + fd = 0; + } } -#if defined(__MINGW32__) || defined(CONFIG_OS2) || defined(__CYGWIN__) +#ifdef O_BINARY setmode(fd, O_BINARY); #endif h->priv_data = (void *)(size_t)fd; @@ -103,28 +111,9 @@ static int pipe_open(URLContext *h, const char *filename, int flags) return 0; } -static int pipe_read(URLContext *h, unsigned char *buf, int size) -{ - int fd = (size_t)h->priv_data; - return read(fd, buf, size); -} - -static int pipe_write(URLContext *h, unsigned char *buf, int size) -{ - int fd = (size_t)h->priv_data; - return write(fd, buf, size); -} - -static int pipe_close(URLContext *h) -{ - return 0; -} - URLProtocol pipe_protocol = { "pipe", pipe_open, - pipe_read, - pipe_write, - NULL, - pipe_close, + file_read, + file_write, }; diff --git a/contrib/ffmpeg/libavformat/flic.c b/contrib/ffmpeg/libavformat/flic.c index 0c3a7f01f..b422fb09a 100644 --- a/contrib/ffmpeg/libavformat/flic.c +++ b/contrib/ffmpeg/libavformat/flic.c @@ -39,25 +39,21 @@ originated in Dave's Targa Animator (DTA) */ #define FLIC_CHUNK_MAGIC_1 0xF1FA #define FLIC_CHUNK_MAGIC_2 0xF5FA -#define FLIC_MC_PTS_INC 6000 /* pts increment for Magic Carpet game FLIs */ -#define FLIC_DEFAULT_PTS_INC 6000 /* for FLIs that have 0 speed */ +#define FLIC_MC_SPEED 5 /* speed for Magic Carpet game FLIs */ +#define FLIC_DEFAULT_SPEED 5 /* for FLIs that have 0 speed */ #define FLIC_HEADER_SIZE 128 #define FLIC_PREAMBLE_SIZE 6 typedef struct FlicDemuxContext { - int frame_pts_inc; - int64_t pts; int video_stream_index; + int frame_number; } FlicDemuxContext; static int flic_probe(AVProbeData *p) { int magic_number; - if (p->buf_size < 6) - return 0; - magic_number = AV_RL16(&p->buf[4]); if ((magic_number != FLIC_FILE_MAGIC_1) && (magic_number != FLIC_FILE_MAGIC_2) && @@ -70,26 +66,28 @@ static int flic_probe(AVProbeData *p) static int flic_read_header(AVFormatContext *s, AVFormatParameters *ap) { - FlicDemuxContext *flic = (FlicDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + FlicDemuxContext *flic = s->priv_data; + ByteIOContext *pb = s->pb; unsigned char header[FLIC_HEADER_SIZE]; AVStream *st; int speed; int magic_number; - flic->pts = 0; + flic->frame_number = 0; /* load the whole header and pull out the width and height */ if (get_buffer(pb, header, FLIC_HEADER_SIZE) != FLIC_HEADER_SIZE) - return AVERROR_IO; + return AVERROR(EIO); magic_number = AV_RL16(&header[4]); speed = AV_RL32(&header[0x10]); + if (speed == 0) + speed = FLIC_DEFAULT_SPEED; /* initialize the decoder streams */ st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); flic->video_stream_index = st->index; st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_FLIC; @@ -97,22 +95,26 @@ static int flic_read_header(AVFormatContext *s, st->codec->width = AV_RL16(&header[0x08]); st->codec->height = AV_RL16(&header[0x0A]); - if (!st->codec->width || !st->codec->height) - return AVERROR_INVALIDDATA; + if (!st->codec->width || !st->codec->height) { + /* Ugly hack needed for the following sample: */ + /* http://samples.mplayerhq.hu/fli-flc/fli-bugs/specular.flc */ + av_log(s, AV_LOG_WARNING, + "File with no specified width/height. Trying 640x480.\n"); + st->codec->width = 640; + st->codec->height = 480; + } /* send over the whole 128-byte FLIC header */ st->codec->extradata_size = FLIC_HEADER_SIZE; st->codec->extradata = av_malloc(FLIC_HEADER_SIZE); memcpy(st->codec->extradata, header, FLIC_HEADER_SIZE); - av_set_pts_info(st, 33, 1, 90000); - /* Time to figure out the framerate: If there is a FLIC chunk magic * number at offset 0x10, assume this is from the Bullfrog game, * Magic Carpet. */ if (AV_RL16(&header[0x10]) == FLIC_CHUNK_MAGIC_1) { - flic->frame_pts_inc = FLIC_MC_PTS_INC; + av_set_pts_info(st, 64, FLIC_MC_SPEED, 70); /* rewind the stream since the first chunk is at offset 12 */ url_fseek(pb, 12, SEEK_SET); @@ -124,44 +126,23 @@ static int flic_read_header(AVFormatContext *s, memcpy(st->codec->extradata, header, 12); } else if (magic_number == FLIC_FILE_MAGIC_1) { - /* - * in this case, the speed (n) is number of 1/70s ticks between frames: - * - * pts n * frame # - * -------- = ----------- => pts = n * (90000/70) * frame # - * 90000 70 - * - * therefore, the frame pts increment = n * 1285.7 - */ - flic->frame_pts_inc = speed * 1285.7; + av_set_pts_info(st, 64, speed, 70); } else if ((magic_number == FLIC_FILE_MAGIC_2) || (magic_number == FLIC_FILE_MAGIC_3)) { - /* - * in this case, the speed (n) is number of milliseconds between frames: - * - * pts n * frame # - * -------- = ----------- => pts = n * 90 * frame # - * 90000 1000 - * - * therefore, the frame pts increment = n * 90 - */ - flic->frame_pts_inc = speed * 90; + av_set_pts_info(st, 64, speed, 1000); } else { av_log(s, AV_LOG_INFO, "Invalid or unsupported magic chunk in file\n"); return AVERROR_INVALIDDATA; } - if (flic->frame_pts_inc == 0) - flic->frame_pts_inc = FLIC_DEFAULT_PTS_INC; - return 0; } static int flic_read_packet(AVFormatContext *s, AVPacket *pkt) { - FlicDemuxContext *flic = (FlicDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + FlicDemuxContext *flic = s->priv_data; + ByteIOContext *pb = s->pb; int packet_read = 0; unsigned int size; int magic; @@ -172,7 +153,7 @@ static int flic_read_packet(AVFormatContext *s, if ((ret = get_buffer(pb, preamble, FLIC_PREAMBLE_SIZE)) != FLIC_PREAMBLE_SIZE) { - ret = AVERROR_IO; + ret = AVERROR(EIO); break; } @@ -181,20 +162,19 @@ static int flic_read_packet(AVFormatContext *s, if (((magic == FLIC_CHUNK_MAGIC_1) || (magic == FLIC_CHUNK_MAGIC_2)) && size > FLIC_PREAMBLE_SIZE) { if (av_new_packet(pkt, size)) { - ret = AVERROR_IO; + ret = AVERROR(EIO); break; } pkt->stream_index = flic->video_stream_index; - pkt->pts = flic->pts; + pkt->pts = flic->frame_number++; pkt->pos = url_ftell(pb); memcpy(pkt->data, preamble, FLIC_PREAMBLE_SIZE); ret = get_buffer(pb, pkt->data + FLIC_PREAMBLE_SIZE, size - FLIC_PREAMBLE_SIZE); if (ret != size - FLIC_PREAMBLE_SIZE) { av_free_packet(pkt); - ret = AVERROR_IO; + ret = AVERROR(EIO); } - flic->pts += flic->frame_pts_inc; packet_read = 1; } else { /* not interested in this chunk */ @@ -207,7 +187,7 @@ static int flic_read_packet(AVFormatContext *s, static int flic_read_close(AVFormatContext *s) { -// FlicDemuxContext *flic = (FlicDemuxContext *)s->priv_data; +// FlicDemuxContext *flic = s->priv_data; return 0; } diff --git a/contrib/ffmpeg/libavformat/flv.h b/contrib/ffmpeg/libavformat/flv.h index 1484ac15d..4501527aa 100644 --- a/contrib/ffmpeg/libavformat/flv.h +++ b/contrib/ffmpeg/libavformat/flv.h @@ -21,8 +21,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef FLV_H -#define FLV_H +#ifndef FFMPEG_FLV_H +#define FFMPEG_FLV_H /* offsets for packed values */ #define FLV_AUDIO_SAMPLESSIZE_OFFSET 1 @@ -71,7 +71,7 @@ enum { }; enum { - FLV_CODECID_PCM_BE = 0, + FLV_CODECID_PCM = 0, FLV_CODECID_ADPCM = 1 << FLV_AUDIO_CODECID_OFFSET, FLV_CODECID_MP3 = 2 << FLV_AUDIO_CODECID_OFFSET, FLV_CODECID_PCM_LE = 3 << FLV_AUDIO_CODECID_OFFSET, @@ -107,4 +107,4 @@ typedef enum { AMF_DATA_TYPE_UNSUPPORTED = 0x0d, } AMFDataType; -#endif /* FLV_H */ +#endif /* FFMPEG_FLV_H */ diff --git a/contrib/ffmpeg/libavformat/flvdec.c b/contrib/ffmpeg/libavformat/flvdec.c index bf91fbbc7..f21f35296 100644 --- a/contrib/ffmpeg/libavformat/flvdec.c +++ b/contrib/ffmpeg/libavformat/flvdec.c @@ -2,6 +2,11 @@ * FLV demuxer * Copyright (c) 2003 The FFmpeg Project. * + * This demuxer will generate a 1 byte extradata for VP6F content. + * It is composed of: + * - upper 4bits: difference between encoded width and visible width + * - lower 4bits: difference between encoded height and visible height + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -17,12 +22,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * This demuxer will generate a 1 byte extradata for VP6F content. - * It is composed of: - * - upper 4bits: difference between encoded width and visible width - * - lower 4bits: difference between encoded height and visible height */ #include "avformat.h" #include "flv.h" @@ -31,8 +30,6 @@ static int flv_probe(AVProbeData *p) { const uint8_t *d; - if (p->buf_size < 6) - return 0; d = p->buf; if (d[0] == 'F' && d[1] == 'L' && d[2] == 'V' && d[3] < 5 && d[5]==0) { return AVPROBE_SCORE_MAX; @@ -44,15 +41,23 @@ static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, int flv_c AVCodecContext *acodec = astream->codec; switch(flv_codecid) { //no distinction between S16 and S8 PCM codec flags - case FLV_CODECID_PCM_BE: - acodec->codec_id = acodec->bits_per_sample == 8 ? CODEC_ID_PCM_S8 : CODEC_ID_PCM_S16BE; break; + case FLV_CODECID_PCM: + acodec->codec_id = acodec->bits_per_sample == 8 ? CODEC_ID_PCM_S8 : +#ifdef WORDS_BIGENDIAN + CODEC_ID_PCM_S16BE; +#else + CODEC_ID_PCM_S16LE; +#endif + break; case FLV_CODECID_PCM_LE: acodec->codec_id = acodec->bits_per_sample == 8 ? CODEC_ID_PCM_S8 : CODEC_ID_PCM_S16LE; break; case FLV_CODECID_ADPCM: acodec->codec_id = CODEC_ID_ADPCM_SWF; break; - case FLV_CODECID_MP3 : acodec->codec_id = CODEC_ID_MP3 ; astream->need_parsing = 1 ; break; + case FLV_CODECID_MP3 : acodec->codec_id = CODEC_ID_MP3 ; astream->need_parsing = AVSTREAM_PARSE_FULL; break; case FLV_CODECID_NELLYMOSER_8HZ_MONO: acodec->sample_rate = 8000; //in case metadata does not otherwise declare samplerate case FLV_CODECID_NELLYMOSER: + acodec->codec_id = CODEC_ID_NELLYMOSER; + break; default: av_log(s, AV_LOG_INFO, "Unsupported audio codec (%x)\n", flv_codecid >> FLV_AUDIO_CODECID_OFFSET); acodec->codec_tag = flv_codecid >> FLV_AUDIO_CODECID_OFFSET; @@ -65,11 +70,14 @@ static int flv_set_video_codec(AVFormatContext *s, AVStream *vstream, int flv_co case FLV_CODECID_H263 : vcodec->codec_id = CODEC_ID_FLV1 ; break; case FLV_CODECID_SCREEN: vcodec->codec_id = CODEC_ID_FLASHSV; break; case FLV_CODECID_VP6 : vcodec->codec_id = CODEC_ID_VP6F ; + case FLV_CODECID_VP6A : + if(flv_codecid == FLV_CODECID_VP6A) + vcodec->codec_id = CODEC_ID_VP6A; if(vcodec->extradata_size != 1) { vcodec->extradata_size = 1; vcodec->extradata = av_malloc(1); } - vcodec->extradata[0] = get_byte(&s->pb); + vcodec->extradata[0] = get_byte(s->pb); return 1; // 1 byte body size adjustment for flv_read_packet() default: av_log(s, AV_LOG_INFO, "Unsupported video codec (%x)\n", flv_codecid); @@ -101,7 +109,7 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vst double num_val; num_val = 0; - ioc = &s->pb; + ioc = s->pb; amf_type = get_byte(ioc); @@ -177,12 +185,14 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vst } else if(!strcmp(key, "audiosamplerate") && acodec && num_val >= 0) { //some tools, like FLVTool2, write consistently approximate metadata sample rates - switch((int)num_val) { - case 44000: acodec->sample_rate = 44100 ; break; - case 22000: acodec->sample_rate = 22050 ; break; - case 11000: acodec->sample_rate = 11025 ; break; - case 5000 : acodec->sample_rate = 5512 ; break; - default : acodec->sample_rate = num_val; + if (!acodec->sample_rate) { + switch((int)num_val) { + case 44000: acodec->sample_rate = 44100 ; break; + case 22000: acodec->sample_rate = 22050 ; break; + case 11000: acodec->sample_rate = 11025 ; break; + case 5000 : acodec->sample_rate = 5512 ; break; + default : acodec->sample_rate = num_val; + } } } } @@ -201,7 +211,7 @@ static int flv_read_metabody(AVFormatContext *s, unsigned int next_pos) { astream = NULL; vstream = NULL; keylen = 0; - ioc = &s->pb; + ioc = s->pb; //first object needs to be "onMetaData" string type = get_byte(ioc); @@ -222,14 +232,22 @@ static int flv_read_metabody(AVFormatContext *s, unsigned int next_pos) { return 0; } +static AVStream *create_stream(AVFormatContext *s, int is_audio){ + AVStream *st = av_new_stream(s, is_audio); + if (!st) + return NULL; + st->codec->codec_type = is_audio ? CODEC_TYPE_AUDIO : CODEC_TYPE_VIDEO; + av_set_pts_info(st, 24, 1, 1000); /* 24 bit pts in ms */ + return st; +} + static int flv_read_header(AVFormatContext *s, AVFormatParameters *ap) { int offset, flags; - AVStream *st; - url_fskip(&s->pb, 4); - flags = get_byte(&s->pb); + url_fskip(s->pb, 4); + flags = get_byte(s->pb); /* old flvtool cleared this field */ /* FIXME: better fix needed */ if (!flags) { @@ -238,22 +256,16 @@ static int flv_read_header(AVFormatContext *s, } if(flags & FLV_HEADER_FLAG_HASVIDEO){ - st = av_new_stream(s, 0); - if (!st) - return AVERROR_NOMEM; - st->codec->codec_type = CODEC_TYPE_VIDEO; - av_set_pts_info(st, 24, 1, 1000); /* 24 bit pts in ms */ + if(!create_stream(s, 0)) + return AVERROR(ENOMEM); } if(flags & FLV_HEADER_FLAG_HASAUDIO){ - st = av_new_stream(s, 1); - if (!st) - return AVERROR_NOMEM; - st->codec->codec_type = CODEC_TYPE_AUDIO; - av_set_pts_info(st, 24, 1, 1000); /* 24 bit pts in ms */ + if(!create_stream(s, 1)) + return AVERROR(ENOMEM); } - offset = get_be32(&s->pb); - url_fseek(&s->pb, offset, SEEK_SET); + offset = get_be32(s->pb); + url_fseek(s->pb, offset, SEEK_SET); s->start_time = 0; @@ -266,34 +278,35 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) AVStream *st = NULL; for(;;){ - pos = url_ftell(&s->pb); - url_fskip(&s->pb, 4); /* size of previous packet */ - type = get_byte(&s->pb); - size = get_be24(&s->pb); - pts = get_be24(&s->pb); + pos = url_ftell(s->pb); + url_fskip(s->pb, 4); /* size of previous packet */ + type = get_byte(s->pb); + size = get_be24(s->pb); + pts = get_be24(s->pb); + pts |= get_byte(s->pb) << 24; // av_log(s, AV_LOG_DEBUG, "type:%d, size:%d, pts:%d\n", type, size, pts); - if (url_feof(&s->pb)) - return AVERROR_IO; - url_fskip(&s->pb, 4); /* reserved */ + if (url_feof(s->pb)) + return AVERROR(EIO); + url_fskip(s->pb, 3); /* stream id, always 0 */ flags = 0; if(size == 0) continue; - next= size + url_ftell(&s->pb); + next= size + url_ftell(s->pb); if (type == FLV_TAG_TYPE_AUDIO) { is_audio=1; - flags = get_byte(&s->pb); + flags = get_byte(s->pb); } else if (type == FLV_TAG_TYPE_VIDEO) { is_audio=0; - flags = get_byte(&s->pb); + flags = get_byte(s->pb); } else { if (type == FLV_TAG_TYPE_META && size > 13+1+4) flv_read_metabody(s, next); else /* skip packet */ av_log(s, AV_LOG_ERROR, "skipping flv packet: type %d, size %d, flags %d\n", type, size, flags); - url_fseek(&s->pb, next, SEEK_SET); + url_fseek(s->pb, next, SEEK_SET); continue; } @@ -305,15 +318,14 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) } if(i == s->nb_streams){ av_log(NULL, AV_LOG_ERROR, "invalid stream\n"); - url_fseek(&s->pb, next, SEEK_SET); - continue; + st= create_stream(s, is_audio); } // av_log(NULL, AV_LOG_DEBUG, "%d %X %d \n", is_audio, flags, st->discard); if( (st->discard >= AVDISCARD_NONKEY && !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || is_audio)) ||(st->discard >= AVDISCARD_BIDIR && ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_DISP_INTER && !is_audio)) || st->discard >= AVDISCARD_ALL ){ - url_fseek(&s->pb, next, SEEK_SET); + url_fseek(s->pb, next, SEEK_SET); continue; } if ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY) @@ -322,17 +334,17 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) } // if not streamed and no duration from metadata then seek to end to find the duration from the timestamps - if(!url_is_streamed(&s->pb) && s->duration==AV_NOPTS_VALUE){ + if(!url_is_streamed(s->pb) && s->duration==AV_NOPTS_VALUE){ int size; - const int pos= url_ftell(&s->pb); - const int fsize= url_fsize(&s->pb); - url_fseek(&s->pb, fsize-4, SEEK_SET); - size= get_be32(&s->pb); - url_fseek(&s->pb, fsize-3-size, SEEK_SET); - if(size == get_be24(&s->pb) + 11){ - s->duration= get_be24(&s->pb) * (int64_t)AV_TIME_BASE / 1000; + const int pos= url_ftell(s->pb); + const int fsize= url_fsize(s->pb); + url_fseek(s->pb, fsize-4, SEEK_SET); + size= get_be32(s->pb); + url_fseek(s->pb, fsize-3-size, SEEK_SET); + if(size == get_be24(s->pb) + 11){ + s->duration= get_be24(s->pb) * (int64_t)AV_TIME_BASE / 1000; } - url_fseek(&s->pb, pos, SEEK_SET); + url_fseek(s->pb, pos, SEEK_SET); } if(is_audio){ @@ -349,9 +361,9 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) size -= flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK); } - ret= av_get_packet(&s->pb, pkt, size - 1); + ret= av_get_packet(s->pb, pkt, size - 1); if (ret <= 0) { - return AVERROR_IO; + return AVERROR(EIO); } /* note: we need to modify the packet size here to handle the last packet */ @@ -376,7 +388,7 @@ static int flv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp int index = av_index_search_timestamp(st, timestamp, flags); if (index < 0) return -1; - url_fseek(&s->pb, st->index_entries[index].pos, SEEK_SET); + url_fseek(s->pb, st->index_entries[index].pos, SEEK_SET); return 0; } diff --git a/contrib/ffmpeg/libavformat/flvenc.c b/contrib/ffmpeg/libavformat/flvenc.c index ece585d77..e5270ca32 100644 --- a/contrib/ffmpeg/libavformat/flvenc.c +++ b/contrib/ffmpeg/libavformat/flvenc.c @@ -35,8 +35,8 @@ static const AVCodecTag flv_video_codec_ids[] = { static const AVCodecTag flv_audio_codec_ids[] = { {CODEC_ID_MP3, FLV_CODECID_MP3 >> FLV_AUDIO_CODECID_OFFSET}, - {CODEC_ID_PCM_S8, FLV_CODECID_PCM_BE >> FLV_AUDIO_CODECID_OFFSET}, - {CODEC_ID_PCM_S16BE, FLV_CODECID_PCM_BE >> FLV_AUDIO_CODECID_OFFSET}, + {CODEC_ID_PCM_S8, FLV_CODECID_PCM >> FLV_AUDIO_CODECID_OFFSET}, + {CODEC_ID_PCM_S16BE, FLV_CODECID_PCM >> FLV_AUDIO_CODECID_OFFSET}, {CODEC_ID_PCM_S16LE, FLV_CODECID_PCM_LE >> FLV_AUDIO_CODECID_OFFSET}, {CODEC_ID_ADPCM_SWF, FLV_CODECID_ADPCM >> FLV_AUDIO_CODECID_OFFSET}, {CODEC_ID_NONE, 0} @@ -66,10 +66,12 @@ static int get_audio_flags(AVCodecContext *enc){ break; case 8000: //nellymoser only case 5512: //not mp3 - flags |= FLV_SAMPLERATE_SPECIAL; - break; + if(enc->codec_id != CODEC_ID_MP3){ + flags |= FLV_SAMPLERATE_SPECIAL; + break; + } default: - av_log(enc, AV_LOG_ERROR, "flv doesnt support that sample rate, choose from (44100, 22050, 11025)\n"); + av_log(enc, AV_LOG_ERROR, "flv does not support that sample rate, choose from (44100, 22050, 11025).\n"); return -1; } @@ -82,10 +84,10 @@ static int get_audio_flags(AVCodecContext *enc){ flags |= FLV_CODECID_MP3 | FLV_SAMPLESSIZE_16BIT; break; case CODEC_ID_PCM_S8: - flags |= FLV_CODECID_PCM_BE | FLV_SAMPLESSIZE_8BIT; + flags |= FLV_CODECID_PCM | FLV_SAMPLESSIZE_8BIT; break; case CODEC_ID_PCM_S16BE: - flags |= FLV_CODECID_PCM_BE | FLV_SAMPLESSIZE_16BIT; + flags |= FLV_CODECID_PCM | FLV_SAMPLESSIZE_16BIT; break; case CODEC_ID_PCM_S16LE: flags |= FLV_CODECID_PCM_LE | FLV_SAMPLESSIZE_16BIT; @@ -124,7 +126,7 @@ static void put_amf_bool(ByteIOContext *pb, int b) { static int flv_write_header(AVFormatContext *s) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; FLVContext *flv = s->priv_data; int i, width, height, samplerate, samplesize, channels, audiocodecid, videocodecid; double framerate = 0.0; @@ -254,7 +256,7 @@ static int flv_write_trailer(AVFormatContext *s) { int64_t file_size; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; FLVContext *flv = s->priv_data; file_size = url_ftell(pb); @@ -271,14 +273,19 @@ static int flv_write_trailer(AVFormatContext *s) static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVCodecContext *enc = s->streams[pkt->stream_index]->codec; FLVContext *flv = s->priv_data; int size= pkt->size; - int flags; + int flags, flags_size; // av_log(s, AV_LOG_DEBUG, "type:%d pts: %"PRId64" size:%d\n", enc->codec_type, timestamp, size); + if(enc->codec_id == CODEC_ID_VP6 || enc->codec_id == CODEC_ID_VP6F) + flags_size= 2; + else + flags_size= 1; + if (enc->codec_type == CODEC_TYPE_VIDEO) { put_byte(pb, FLV_TAG_TYPE_VIDEO); @@ -298,19 +305,17 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) put_byte(pb, FLV_TAG_TYPE_AUDIO); } - if ((enc->codec_id == CODEC_ID_VP6) || (enc->codec_id == CODEC_ID_VP6F)) - put_be24(pb,size+2); // include the extra byte needed for VP6 in flv and flags - else - put_be24(pb,size+1); // include flags + put_be24(pb,size + flags_size); put_be24(pb,pkt->pts); - put_be32(pb,flv->reserved); + put_byte(pb,pkt->pts >> 24); + put_be24(pb,flv->reserved); put_byte(pb,flags); if (enc->codec_id == CODEC_ID_VP6) put_byte(pb,0); if (enc->codec_id == CODEC_ID_VP6F) put_byte(pb, enc->extradata_size ? enc->extradata[0] : 0); put_buffer(pb, pkt->data, size); - put_be32(pb,size+1+11); // previous tag size + put_be32(pb,size+flags_size+11); // previous tag size flv->duration = pkt->pts + pkt->duration; put_flush_packet(pb); @@ -326,7 +331,7 @@ AVOutputFormat flv_muxer = { #ifdef CONFIG_LIBMP3LAME CODEC_ID_MP3, #else // CONFIG_LIBMP3LAME - CODEC_ID_NONE, + CODEC_ID_ADPCM_SWF, #endif // CONFIG_LIBMP3LAME CODEC_ID_FLV1, flv_write_header, diff --git a/contrib/ffmpeg/libavformat/framecrcenc.c b/contrib/ffmpeg/libavformat/framecrcenc.c new file mode 100644 index 000000000..c0133017c --- /dev/null +++ b/contrib/ffmpeg/libavformat/framecrcenc.c @@ -0,0 +1,46 @@ +/* + * frame CRC encoder (for codec/format testing) + * Copyright (c) 2002 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avformat.h" +#include "adler32.h" + +static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt) +{ + uint32_t crc = av_adler32_update(0, pkt->data, pkt->size); + char buf[256]; + + snprintf(buf, sizeof(buf), "%d, %"PRId64", %d, 0x%08x\n", pkt->stream_index, pkt->dts, pkt->size, crc); + put_buffer(s->pb, buf, strlen(buf)); + put_flush_packet(s->pb); + return 0; +} + +AVOutputFormat framecrc_muxer = { + "framecrc", + "framecrc testing format", + NULL, + "", + 0, + CODEC_ID_PCM_S16LE, + CODEC_ID_RAWVIDEO, + NULL, + framecrc_write_packet, + NULL, +}; diff --git a/contrib/ffmpeg/libavformat/framehook.c b/contrib/ffmpeg/libavformat/framehook.c index 8738f8030..eb5184f02 100644 --- a/contrib/ffmpeg/libavformat/framehook.c +++ b/contrib/ffmpeg/libavformat/framehook.c @@ -28,8 +28,8 @@ #endif -typedef struct _FrameHookEntry { - struct _FrameHookEntry *next; +typedef struct FrameHookEntry { + struct FrameHookEntry *next; FrameHookConfigureFn Configure; FrameHookProcessFn Process; FrameHookReleaseFn Release; diff --git a/contrib/ffmpeg/libavformat/framehook.h b/contrib/ffmpeg/libavformat/framehook.h index 06ed4f889..5568c138e 100644 --- a/contrib/ffmpeg/libavformat/framehook.h +++ b/contrib/ffmpeg/libavformat/framehook.h @@ -19,10 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _FRAMEHOOK_H -#define _FRAMEHOOK_H +#ifndef FFMPEG_FRAMEHOOK_H +#define FFMPEG_FRAMEHOOK_H -#warning VHOOK is deprecated please help porting libmpcodecs or a better filter system to ffmpeg instead of wasting your time writing new fiters for this crappy one +#warning VHOOK is deprecated. Please help finishing libavfilter instead of wasting your time writing new filters for this crappy filter system. /* * Prototypes for interface to .so that implement a video processing hook @@ -49,4 +49,4 @@ extern int frame_hook_add(int argc, char *argv[]); extern void frame_hook_process(struct AVPicture *pict, enum PixelFormat pix_fmt, int width, int height, int64_t pts); extern void frame_hook_release(void); -#endif +#endif /* FFMPEG_FRAMEHOOK_H */ diff --git a/contrib/ffmpeg/libavformat/gif.c b/contrib/ffmpeg/libavformat/gif.c index 1083710d5..7b71faea9 100644 --- a/contrib/ffmpeg/libavformat/gif.c +++ b/contrib/ffmpeg/libavformat/gif.c @@ -137,7 +137,7 @@ static void gif_put_bits_rev(PutBitContext *s, int n, unsigned int value) //printf("bitbuf = %08x\n", bit_buf); s->buf_ptr+=4; if (s->buf_ptr >= s->buf_end) - puts("bit buffer overflow !!"); // should never happen ! who got rid of the callback ??? + abort(); // flush_buffer_rev(s); bit_cnt=bit_cnt + n - 32; if (bit_cnt == 0) { @@ -313,7 +313,7 @@ typedef struct { static int gif_write_header(AVFormatContext *s) { GIFContext *gif = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVCodecContext *enc, *video_enc; int i, width, height, loop_count /*, rate*/; @@ -343,19 +343,19 @@ static int gif_write_header(AVFormatContext *s) if (video_enc->pix_fmt != PIX_FMT_RGB24) { av_log(s, AV_LOG_ERROR, "ERROR: gif only handles the rgb24 pixel format. Use -pix_fmt rgb24.\n"); - return AVERROR_IO; + return AVERROR(EIO); } gif_image_write_header(pb, width, height, loop_count, NULL); - put_flush_packet(&s->pb); + put_flush_packet(s->pb); return 0; } static int gif_write_video(AVFormatContext *s, AVCodecContext *enc, const uint8_t *buf, int size) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; GIFContext *gif = s->priv_data; int jiffies; int64_t delay; @@ -383,7 +383,7 @@ static int gif_write_video(AVFormatContext *s, gif_image_write_image(pb, 0, 0, enc->width, enc->height, buf, enc->width * 3, PIX_FMT_RGB24); - put_flush_packet(&s->pb); + put_flush_packet(s->pb); return 0; } @@ -398,10 +398,10 @@ static int gif_write_packet(AVFormatContext *s, AVPacket *pkt) static int gif_write_trailer(AVFormatContext *s) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; put_byte(pb, 0x3b); - put_flush_packet(&s->pb); + put_flush_packet(s->pb); return 0; } diff --git a/contrib/ffmpeg/libavformat/gifdec.c b/contrib/ffmpeg/libavformat/gifdec.c index 1d31211f6..5803e5e5d 100644 --- a/contrib/ffmpeg/libavformat/gifdec.c +++ b/contrib/ffmpeg/libavformat/gifdec.c @@ -500,21 +500,21 @@ static int gif_parse_next_image(GifState *s) switch (code) { case ',': if (gif_read_image(s) < 0) - return AVERROR_IO; + return AVERROR(EIO); ret = 0; goto the_end; case ';': /* end of image */ - ret = AVERROR_IO; + ret = AVERROR(EIO); goto the_end; case '!': if (gif_read_extension(s) < 0) - return AVERROR_IO; + return AVERROR(EIO); break; case EOF: default: /* error or errneous EOF */ - ret = AVERROR_IO; + ret = AVERROR(EIO); goto the_end; } } @@ -526,7 +526,7 @@ static int gif_read_header(AVFormatContext * s1, AVFormatParameters * ap) { GifState *s = s1->priv_data; - ByteIOContext *f = &s1->pb; + ByteIOContext *f = s1->pb; AVStream *st; s->f = f; @@ -567,7 +567,7 @@ static int gif_read_packet(AVFormatContext * s1, /* XXX: avoid copying */ if (av_new_packet(pkt, s->screen_width * s->screen_height * 3)) { - return AVERROR_IO; + return AVERROR(EIO); } pkt->stream_index = 0; memcpy(pkt->data, s->image_buf, s->screen_width * s->screen_height * 3); diff --git a/contrib/ffmpeg/libavformat/grab.c b/contrib/ffmpeg/libavformat/grab.c deleted file mode 100644 index 5e778ecc0..000000000 --- a/contrib/ffmpeg/libavformat/grab.c +++ /dev/null @@ -1,860 +0,0 @@ -/* - * Linux video grab interface - * Copyright (c) 2000,2001 Fabrice Bellard. - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include "avformat.h" -#include -#include -#include -#include -#include -#define _LINUX_TIME_H 1 -#include -#include - -typedef struct { - int fd; - int frame_format; /* see VIDEO_PALETTE_xxx */ - int use_mmap; - int width, height; - int frame_rate; - int frame_rate_base; - int64_t time_frame; - int frame_size; - struct video_capability video_cap; - struct video_audio audio_saved; - uint8_t *video_buf; - struct video_mbuf gb_buffers; - struct video_mmap gb_buf; - int gb_frame; - - /* ATI All In Wonder specific stuff */ - /* XXX: remove and merge in libavcodec/imgconvert.c */ - int aiw_enabled; - int deint; - int halfw; - uint8_t *src_mem; - uint8_t *lum_m4_mem; -} VideoData; - -static int aiw_init(VideoData *s); -static int aiw_read_picture(VideoData *s, uint8_t *data); -static int aiw_close(VideoData *s); - -static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) -{ - VideoData *s = s1->priv_data; - AVStream *st; - int width, height; - int video_fd, frame_size; - int ret, frame_rate, frame_rate_base; - int desired_palette, desired_depth; - struct video_tuner tuner; - struct video_audio audio; - struct video_picture pict; - int j; - - if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) { - av_log(s1, AV_LOG_ERROR, "Bad capture size (%dx%d) or wrong time base (%d)\n", - ap->width, ap->height, ap->time_base.den); - - return -1; - } - - width = ap->width; - height = ap->height; - frame_rate = ap->time_base.den; - frame_rate_base = ap->time_base.num; - - if((unsigned)width > 32767 || (unsigned)height > 32767) { - av_log(s1, AV_LOG_ERROR, "Capture size is out of range: %dx%d\n", - width, height); - - return -1; - } - - st = av_new_stream(s1, 0); - if (!st) - return AVERROR(ENOMEM); - av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ - - s->width = width; - s->height = height; - s->frame_rate = frame_rate; - s->frame_rate_base = frame_rate_base; - - video_fd = open(s1->filename, O_RDWR); - if (video_fd < 0) { - perror(s1->filename); - goto fail; - } - - if (ioctl(video_fd,VIDIOCGCAP, &s->video_cap) < 0) { - perror("VIDIOCGCAP"); - goto fail; - } - - if (!(s->video_cap.type & VID_TYPE_CAPTURE)) { - av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not handle capture\n"); - goto fail; - } - - desired_palette = -1; - desired_depth = -1; - if (ap->pix_fmt == PIX_FMT_YUV420P) { - desired_palette = VIDEO_PALETTE_YUV420P; - desired_depth = 12; - } else if (ap->pix_fmt == PIX_FMT_YUYV422) { - desired_palette = VIDEO_PALETTE_YUV422; - desired_depth = 16; - } else if (ap->pix_fmt == PIX_FMT_BGR24) { - desired_palette = VIDEO_PALETTE_RGB24; - desired_depth = 24; - } - - /* set tv standard */ - if (ap->standard && !ioctl(video_fd, VIDIOCGTUNER, &tuner)) { - if (!strcasecmp(ap->standard, "pal")) - tuner.mode = VIDEO_MODE_PAL; - else if (!strcasecmp(ap->standard, "secam")) - tuner.mode = VIDEO_MODE_SECAM; - else - tuner.mode = VIDEO_MODE_NTSC; - ioctl(video_fd, VIDIOCSTUNER, &tuner); - } - - /* unmute audio */ - audio.audio = 0; - ioctl(video_fd, VIDIOCGAUDIO, &audio); - memcpy(&s->audio_saved, &audio, sizeof(audio)); - audio.flags &= ~VIDEO_AUDIO_MUTE; - ioctl(video_fd, VIDIOCSAUDIO, &audio); - - ioctl(video_fd, VIDIOCGPICT, &pict); -#if 0 - printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n", - pict.colour, - pict.hue, - pict.brightness, - pict.contrast, - pict.whiteness); -#endif - /* try to choose a suitable video format */ - pict.palette = desired_palette; - pict.depth= desired_depth; - if (desired_palette == -1 || (ret = ioctl(video_fd, VIDIOCSPICT, &pict)) < 0) { - pict.palette=VIDEO_PALETTE_YUV420P; - pict.depth=12; - ret = ioctl(video_fd, VIDIOCSPICT, &pict); - if (ret < 0) { - pict.palette=VIDEO_PALETTE_YUV422; - pict.depth=16; - ret = ioctl(video_fd, VIDIOCSPICT, &pict); - if (ret < 0) { - pict.palette=VIDEO_PALETTE_RGB24; - pict.depth=24; - ret = ioctl(video_fd, VIDIOCSPICT, &pict); - if (ret < 0) { - pict.palette=VIDEO_PALETTE_GREY; - pict.depth=8; - ret = ioctl(video_fd, VIDIOCSPICT, &pict); - if (ret < 0) - goto fail1; - } - } - } - } - - ret = ioctl(video_fd,VIDIOCGMBUF,&s->gb_buffers); - if (ret < 0) { - /* try to use read based access */ - struct video_window win; - int val; - - win.x = 0; - win.y = 0; - win.width = width; - win.height = height; - win.chromakey = -1; - win.flags = 0; - - ioctl(video_fd, VIDIOCSWIN, &win); - - s->frame_format = pict.palette; - - val = 1; - ioctl(video_fd, VIDIOCCAPTURE, &val); - - s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base; - s->use_mmap = 0; - - /* ATI All In Wonder automatic activation */ - if (!strcmp(s->video_cap.name, "Km")) { - if (aiw_init(s) < 0) - goto fail; - s->aiw_enabled = 1; - /* force 420P format because convertion from YUV422 to YUV420P - is done in this driver (ugly) */ - s->frame_format = VIDEO_PALETTE_YUV420P; - } - } else { - s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,video_fd,0); - if ((unsigned char*)-1 == s->video_buf) { - s->video_buf = mmap(0,s->gb_buffers.size,PROT_READ|PROT_WRITE,MAP_PRIVATE,video_fd,0); - if ((unsigned char*)-1 == s->video_buf) { - perror("mmap"); - goto fail; - } - } - s->gb_frame = 0; - s->time_frame = av_gettime() * s->frame_rate / s->frame_rate_base; - - /* start to grab the first frame */ - s->gb_buf.frame = s->gb_frame % s->gb_buffers.frames; - s->gb_buf.height = height; - s->gb_buf.width = width; - s->gb_buf.format = pict.palette; - - ret = ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf); - if (ret < 0) { - if (errno != EAGAIN) { - fail1: - av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not support suitable format\n"); - } else { - av_log(s1, AV_LOG_ERROR,"Fatal: grab device does not receive any video signal\n"); - } - goto fail; - } - for (j = 1; j < s->gb_buffers.frames; j++) { - s->gb_buf.frame = j; - ioctl(video_fd, VIDIOCMCAPTURE, &s->gb_buf); - } - s->frame_format = s->gb_buf.format; - s->use_mmap = 1; - } - - switch(s->frame_format) { - case VIDEO_PALETTE_YUV420P: - frame_size = (width * height * 3) / 2; - st->codec->pix_fmt = PIX_FMT_YUV420P; - break; - case VIDEO_PALETTE_YUV422: - frame_size = width * height * 2; - st->codec->pix_fmt = PIX_FMT_YUYV422; - break; - case VIDEO_PALETTE_RGB24: - frame_size = width * height * 3; - st->codec->pix_fmt = PIX_FMT_BGR24; /* NOTE: v4l uses BGR24, not RGB24 ! */ - break; - case VIDEO_PALETTE_GREY: - frame_size = width * height * 1; - st->codec->pix_fmt = PIX_FMT_GRAY8; - break; - default: - goto fail; - } - s->fd = video_fd; - s->frame_size = frame_size; - - st->codec->codec_type = CODEC_TYPE_VIDEO; - st->codec->codec_id = CODEC_ID_RAWVIDEO; - st->codec->width = width; - st->codec->height = height; - st->codec->time_base.den = frame_rate; - st->codec->time_base.num = frame_rate_base; - st->codec->bit_rate = frame_size * 1/av_q2d(st->codec->time_base) * 8; - - return 0; - fail: - if (video_fd >= 0) - close(video_fd); - av_free(st); - return AVERROR_IO; -} - -static int v4l_mm_read_picture(VideoData *s, uint8_t *buf) -{ - uint8_t *ptr; - - while (ioctl(s->fd, VIDIOCSYNC, &s->gb_frame) < 0 && - (errno == EAGAIN || errno == EINTR)); - - ptr = s->video_buf + s->gb_buffers.offsets[s->gb_frame]; - memcpy(buf, ptr, s->frame_size); - - /* Setup to capture the next frame */ - s->gb_buf.frame = s->gb_frame; - if (ioctl(s->fd, VIDIOCMCAPTURE, &s->gb_buf) < 0) { - if (errno == EAGAIN) - av_log(NULL, AV_LOG_ERROR, "Cannot Sync\n"); - else - perror("VIDIOCMCAPTURE"); - return AVERROR_IO; - } - - /* This is now the grabbing frame */ - s->gb_frame = (s->gb_frame + 1) % s->gb_buffers.frames; - - return s->frame_size; -} - -static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt) -{ - VideoData *s = s1->priv_data; - int64_t curtime, delay; - struct timespec ts; - - /* Calculate the time of the next frame */ - s->time_frame += INT64_C(1000000); - - /* wait based on the frame rate */ - for(;;) { - curtime = av_gettime(); - delay = s->time_frame * s->frame_rate_base / s->frame_rate - curtime; - if (delay <= 0) { - if (delay < INT64_C(-1000000) * s->frame_rate_base / s->frame_rate) { - /* printf("grabbing is %d frames late (dropping)\n", (int) -(delay / 16666)); */ - s->time_frame += INT64_C(1000000); - } - break; - } - ts.tv_sec = delay / 1000000; - ts.tv_nsec = (delay % 1000000) * 1000; - nanosleep(&ts, NULL); - } - - if (av_new_packet(pkt, s->frame_size) < 0) - return AVERROR_IO; - - pkt->pts = curtime; - - /* read one frame */ - if (s->aiw_enabled) { - return aiw_read_picture(s, pkt->data); - } else if (s->use_mmap) { - return v4l_mm_read_picture(s, pkt->data); - } else { - if (read(s->fd, pkt->data, pkt->size) != pkt->size) - return AVERROR_IO; - return s->frame_size; - } -} - -static int grab_read_close(AVFormatContext *s1) -{ - VideoData *s = s1->priv_data; - - if (s->aiw_enabled) - aiw_close(s); - - if (s->use_mmap) - munmap(s->video_buf, s->gb_buffers.size); - - /* mute audio. we must force it because the BTTV driver does not - return its state correctly */ - s->audio_saved.flags |= VIDEO_AUDIO_MUTE; - ioctl(s->fd, VIDIOCSAUDIO, &s->audio_saved); - - close(s->fd); - return 0; -} - -AVInputFormat video_grab_device_demuxer = { - "video4linux", - "video grab", - sizeof(VideoData), - NULL, - grab_read_header, - grab_read_packet, - grab_read_close, - .flags = AVFMT_NOFILE, -}; - -/* All in Wonder specific stuff */ -/* XXX: remove and merge in libavcodec/imgconvert.c */ - -static int aiw_init(VideoData *s) -{ - int width, height; - - width = s->width; - height = s->height; - - if ((width == s->video_cap.maxwidth && height == s->video_cap.maxheight) || - (width == s->video_cap.maxwidth && height == s->video_cap.maxheight*2) || - (width == s->video_cap.maxwidth/2 && height == s->video_cap.maxheight)) { - - s->deint=0; - s->halfw=0; - if (height == s->video_cap.maxheight*2) s->deint=1; - if (width == s->video_cap.maxwidth/2) s->halfw=1; - } else { - av_log(NULL, AV_LOG_ERROR, "\nIncorrect Grab Size Supplied - Supported Sizes Are:\n"); - av_log(NULL, AV_LOG_ERROR, " %dx%d %dx%d %dx%d\n\n", - s->video_cap.maxwidth,s->video_cap.maxheight, - s->video_cap.maxwidth,s->video_cap.maxheight*2, - s->video_cap.maxwidth/2,s->video_cap.maxheight); - goto fail; - } - - if (s->halfw == 0) { - s->src_mem = av_malloc(s->width*2); - } else { - s->src_mem = av_malloc(s->width*4); - } - if (!s->src_mem) goto fail; - - s->lum_m4_mem = av_malloc(s->width); - if (!s->lum_m4_mem) - goto fail; - return 0; - fail: - av_freep(&s->src_mem); - av_freep(&s->lum_m4_mem); - return -1; -} - -#ifdef HAVE_MMX -#include "libavcodec/i386/mmx.h" - -#define LINE_WITH_UV \ - movq_m2r(ptr[0],mm0); \ - movq_m2r(ptr[8],mm1); \ - movq_r2r(mm0, mm4); \ - punpcklbw_r2r(mm1,mm0); \ - punpckhbw_r2r(mm1,mm4); \ - movq_r2r(mm0,mm5); \ - punpcklbw_r2r(mm4,mm0); \ - punpckhbw_r2r(mm4,mm5); \ - movq_r2r(mm0,mm1); \ - punpcklbw_r2r(mm5,mm1); \ - movq_r2m(mm1,lum[0]); \ - movq_m2r(ptr[16],mm2); \ - movq_m2r(ptr[24],mm1); \ - movq_r2r(mm2,mm4); \ - punpcklbw_r2r(mm1,mm2); \ - punpckhbw_r2r(mm1,mm4); \ - movq_r2r(mm2,mm3); \ - punpcklbw_r2r(mm4,mm2); \ - punpckhbw_r2r(mm4,mm3); \ - movq_r2r(mm2,mm1); \ - punpcklbw_r2r(mm3,mm1); \ - movq_r2m(mm1,lum[8]); \ - punpckhdq_r2r(mm2,mm0); \ - punpckhdq_r2r(mm3,mm5); \ - movq_r2m(mm0,cb[0]); \ - movq_r2m(mm5,cr[0]); - -#define LINE_NO_UV \ - movq_m2r(ptr[0],mm0);\ - movq_m2r(ptr[8],mm1);\ - movq_r2r(mm0, mm4);\ - punpcklbw_r2r(mm1,mm0); \ - punpckhbw_r2r(mm1,mm4);\ - movq_r2r(mm0,mm5);\ - punpcklbw_r2r(mm4,mm0);\ - punpckhbw_r2r(mm4,mm5);\ - movq_r2r(mm0,mm1);\ - punpcklbw_r2r(mm5,mm1);\ - movq_r2m(mm1,lum[0]);\ - movq_m2r(ptr[16],mm2);\ - movq_m2r(ptr[24],mm1);\ - movq_r2r(mm2,mm4);\ - punpcklbw_r2r(mm1,mm2);\ - punpckhbw_r2r(mm1,mm4);\ - movq_r2r(mm2,mm3);\ - punpcklbw_r2r(mm4,mm2);\ - punpckhbw_r2r(mm4,mm3);\ - movq_r2r(mm2,mm1);\ - punpcklbw_r2r(mm3,mm1);\ - movq_r2m(mm1,lum[8]); - -#define LINE_WITHUV_AVG \ - movq_m2r(ptr[0], mm0);\ - movq_m2r(ptr[8], mm1);\ - movq_r2r(mm0, mm4);\ - punpcklbw_r2r(mm1,mm0);\ - punpckhbw_r2r(mm1,mm4);\ - movq_r2r(mm0,mm5);\ - punpcklbw_r2r(mm4,mm0);\ - punpckhbw_r2r(mm4,mm5);\ - movq_r2r(mm0,mm1);\ - movq_r2r(mm5,mm2);\ - punpcklbw_r2r(mm7,mm1);\ - punpcklbw_r2r(mm7,mm2);\ - paddw_r2r(mm6,mm1);\ - paddw_r2r(mm2,mm1);\ - psraw_i2r(1,mm1);\ - packuswb_r2r(mm7,mm1);\ - movd_r2m(mm1,lum[0]);\ - movq_m2r(ptr[16],mm2);\ - movq_m2r(ptr[24],mm1);\ - movq_r2r(mm2,mm4);\ - punpcklbw_r2r(mm1,mm2);\ - punpckhbw_r2r(mm1,mm4);\ - movq_r2r(mm2,mm3);\ - punpcklbw_r2r(mm4,mm2);\ - punpckhbw_r2r(mm4,mm3);\ - movq_r2r(mm2,mm1);\ - movq_r2r(mm3,mm4);\ - punpcklbw_r2r(mm7,mm1);\ - punpcklbw_r2r(mm7,mm4);\ - paddw_r2r(mm6,mm1);\ - paddw_r2r(mm4,mm1);\ - psraw_i2r(1,mm1);\ - packuswb_r2r(mm7,mm1);\ - movd_r2m(mm1,lum[4]);\ - punpckhbw_r2r(mm7,mm0);\ - punpckhbw_r2r(mm7,mm2);\ - paddw_r2r(mm6,mm0);\ - paddw_r2r(mm2,mm0);\ - psraw_i2r(1,mm0);\ - packuswb_r2r(mm7,mm0);\ - punpckhbw_r2r(mm7,mm5);\ - punpckhbw_r2r(mm7,mm3);\ - paddw_r2r(mm6,mm5);\ - paddw_r2r(mm3,mm5);\ - psraw_i2r(1,mm5);\ - packuswb_r2r(mm7,mm5);\ - movd_r2m(mm0,cb[0]);\ - movd_r2m(mm5,cr[0]); - -#define LINE_NOUV_AVG \ - movq_m2r(ptr[0],mm0);\ - movq_m2r(ptr[8],mm1);\ - pand_r2r(mm5,mm0);\ - pand_r2r(mm5,mm1);\ - pmaddwd_r2r(mm6,mm0);\ - pmaddwd_r2r(mm6,mm1);\ - packssdw_r2r(mm1,mm0);\ - paddw_r2r(mm6,mm0);\ - psraw_i2r(1,mm0);\ - movq_m2r(ptr[16],mm2);\ - movq_m2r(ptr[24],mm3);\ - pand_r2r(mm5,mm2);\ - pand_r2r(mm5,mm3);\ - pmaddwd_r2r(mm6,mm2);\ - pmaddwd_r2r(mm6,mm3);\ - packssdw_r2r(mm3,mm2);\ - paddw_r2r(mm6,mm2);\ - psraw_i2r(1,mm2);\ - packuswb_r2r(mm2,mm0);\ - movq_r2m(mm0,lum[0]); - -#define DEINT_LINE_LUM(ptroff) \ - movd_m2r(lum_m4[(ptroff)],mm0);\ - movd_m2r(lum_m3[(ptroff)],mm1);\ - movd_m2r(lum_m2[(ptroff)],mm2);\ - movd_m2r(lum_m1[(ptroff)],mm3);\ - movd_m2r(lum[(ptroff)],mm4);\ - punpcklbw_r2r(mm7,mm0);\ - movd_r2m(mm2,lum_m4[(ptroff)]);\ - punpcklbw_r2r(mm7,mm1);\ - punpcklbw_r2r(mm7,mm2);\ - punpcklbw_r2r(mm7,mm3);\ - punpcklbw_r2r(mm7,mm4);\ - psllw_i2r(2,mm1);\ - psllw_i2r(1,mm2);\ - paddw_r2r(mm6,mm1);\ - psllw_i2r(2,mm3);\ - paddw_r2r(mm2,mm1);\ - paddw_r2r(mm4,mm0);\ - paddw_r2r(mm3,mm1);\ - psubusw_r2r(mm0,mm1);\ - psrlw_i2r(3,mm1);\ - packuswb_r2r(mm7,mm1);\ - movd_r2m(mm1,lum_m2[(ptroff)]); - -#else -#include "libavcodec/dsputil.h" - -#define LINE_WITH_UV \ - lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\ - cb[0]=ptr[1];cb[1]=ptr[5];\ - cr[0]=ptr[3];cr[1]=ptr[7];\ - lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\ - cb[2]=ptr[9];cb[3]=ptr[13];\ - cr[2]=ptr[11];cr[3]=ptr[15];\ - lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\ - cb[4]=ptr[17];cb[5]=ptr[21];\ - cr[4]=ptr[19];cr[5]=ptr[23];\ - lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30];\ - cb[6]=ptr[25];cb[7]=ptr[29];\ - cr[6]=ptr[27];cr[7]=ptr[31]; - -#define LINE_NO_UV \ - lum[0]=ptr[0];lum[1]=ptr[2];lum[2]=ptr[4];lum[3]=ptr[6];\ - lum[4]=ptr[8];lum[5]=ptr[10];lum[6]=ptr[12];lum[7]=ptr[14];\ - lum[8]=ptr[16];lum[9]=ptr[18];lum[10]=ptr[20];lum[11]=ptr[22];\ - lum[12]=ptr[24];lum[13]=ptr[26];lum[14]=ptr[28];lum[15]=ptr[30]; - -#define LINE_WITHUV_AVG \ - sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \ - sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \ - sum=(ptr[1]+ptr[5]+1) >> 1;cb[0]=sum; \ - sum=(ptr[3]+ptr[7]+1) >> 1;cr[0]=sum; \ - sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \ - sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \ - sum=(ptr[9]+ptr[13]+1) >> 1;cb[1]=sum; \ - sum=(ptr[11]+ptr[15]+1) >> 1;cr[1]=sum; \ - sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \ - sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \ - sum=(ptr[17]+ptr[21]+1) >> 1;cb[2]=sum; \ - sum=(ptr[19]+ptr[23]+1) >> 1;cr[2]=sum; \ - sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \ - sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum; \ - sum=(ptr[25]+ptr[29]+1) >> 1;cb[3]=sum; \ - sum=(ptr[27]+ptr[31]+1) >> 1;cr[3]=sum; - -#define LINE_NOUV_AVG \ - sum=(ptr[0]+ptr[2]+1) >> 1;lum[0]=sum; \ - sum=(ptr[4]+ptr[6]+1) >> 1;lum[1]=sum; \ - sum=(ptr[8]+ptr[10]+1) >> 1;lum[2]=sum; \ - sum=(ptr[12]+ptr[14]+1) >> 1;lum[3]=sum; \ - sum=(ptr[16]+ptr[18]+1) >> 1;lum[4]=sum; \ - sum=(ptr[20]+ptr[22]+1) >> 1;lum[5]=sum; \ - sum=(ptr[24]+ptr[26]+1) >> 1;lum[6]=sum; \ - sum=(ptr[28]+ptr[30]+1) >> 1;lum[7]=sum; - -#define DEINT_LINE_LUM(ptroff) \ - sum=(-lum_m4[(ptroff)]+(lum_m3[(ptroff)]<<2)+(lum_m2[(ptroff)]<<1)+(lum_m1[(ptroff)]<<2)-lum[(ptroff)]); \ - lum_m4[(ptroff)]=lum_m2[(ptroff)];\ - lum_m2[(ptroff)]=cm[(sum+4)>>3];\ - sum=(-lum_m4[(ptroff)+1]+(lum_m3[(ptroff)+1]<<2)+(lum_m2[(ptroff)+1]<<1)+(lum_m1[(ptroff)+1]<<2)-lum[(ptroff)+1]); \ - lum_m4[(ptroff)+1]=lum_m2[(ptroff)+1];\ - lum_m2[(ptroff)+1]=cm[(sum+4)>>3];\ - sum=(-lum_m4[(ptroff)+2]+(lum_m3[(ptroff)+2]<<2)+(lum_m2[(ptroff)+2]<<1)+(lum_m1[(ptroff)+2]<<2)-lum[(ptroff)+2]); \ - lum_m4[(ptroff)+2]=lum_m2[(ptroff)+2];\ - lum_m2[(ptroff)+2]=cm[(sum+4)>>3];\ - sum=(-lum_m4[(ptroff)+3]+(lum_m3[(ptroff)+3]<<2)+(lum_m2[(ptroff)+3]<<1)+(lum_m1[(ptroff)+3]<<2)-lum[(ptroff)+3]); \ - lum_m4[(ptroff)+3]=lum_m2[(ptroff)+3];\ - lum_m2[(ptroff)+3]=cm[(sum+4)>>3]; - -#endif - - -/* Read two fields separately. */ -static int aiw_read_picture(VideoData *s, uint8_t *data) -{ - uint8_t *ptr, *lum, *cb, *cr; - int h; -#ifndef HAVE_MMX - int sum; -#endif - uint8_t* src = s->src_mem; - uint8_t *ptrend = &src[s->width*2]; - lum=data; - cb=&lum[s->width*s->height]; - cr=&cb[(s->width*s->height)/4]; - if (s->deint == 0 && s->halfw == 0) { - while (read(s->fd,src,s->width*2) < 0) { - usleep(100); - } - for (h = 0; h < s->height-2; h+=2) { - for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) { - LINE_WITH_UV - } - read(s->fd,src,s->width*2); - for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) { - LINE_NO_UV - } - read(s->fd,src,s->width*2); - } - /* - * Do last two lines - */ - for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) { - LINE_WITH_UV - } - read(s->fd,src,s->width*2); - for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) { - LINE_NO_UV - } - /* drop second field */ - while (read(s->fd,src,s->width*2) < 0) { - usleep(100); - } - for (h = 0; h < s->height - 1; h++) { - read(s->fd,src,s->width*2); - } - } else if (s->halfw == 1) { -#ifdef HAVE_MMX - mmx_t rounder; - mmx_t masker; - rounder.uw[0]=1; - rounder.uw[1]=1; - rounder.uw[2]=1; - rounder.uw[3]=1; - masker.ub[0]=0xff; - masker.ub[1]=0; - masker.ub[2]=0xff; - masker.ub[3]=0; - masker.ub[4]=0xff; - masker.ub[5]=0; - masker.ub[6]=0xff; - masker.ub[7]=0; - pxor_r2r(mm7,mm7); - movq_m2r(rounder,mm6); -#endif - while (read(s->fd,src,s->width*4) < 0) { - usleep(100); - } - ptrend = &src[s->width*4]; - for (h = 0; h < s->height-2; h+=2) { - for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) { - LINE_WITHUV_AVG - } - read(s->fd,src,s->width*4); -#ifdef HAVE_MMX - movq_m2r(masker,mm5); -#endif - for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) { - LINE_NOUV_AVG - } - read(s->fd,src,s->width*4); - } - /* - * Do last two lines - */ - for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8, cb+=4, cr+=4) { - LINE_WITHUV_AVG - } - read(s->fd,src,s->width*4); -#ifdef HAVE_MMX - movq_m2r(masker,mm5); -#endif - for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=8) { - LINE_NOUV_AVG - } - /* drop second field */ - while (read(s->fd,src,s->width*4) < 0) { - usleep(100); - } - for (h = 0; h < s->height - 1; h++) { - read(s->fd,src,s->width*4); - } - } else { - uint8_t *lum_m1, *lum_m2, *lum_m3, *lum_m4; -#ifdef HAVE_MMX - mmx_t rounder; - rounder.uw[0]=4; - rounder.uw[1]=4; - rounder.uw[2]=4; - rounder.uw[3]=4; - movq_m2r(rounder,mm6); - pxor_r2r(mm7,mm7); -#else - uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; -#endif - - /* read two fields and deinterlace them */ - while (read(s->fd,src,s->width*2) < 0) { - usleep(100); - } - for (h = 0; h < (s->height/2)-2; h+=2) { - for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) { - LINE_WITH_UV - } - read(s->fd,src,s->width*2); - /* skip a luminance line - will be filled in later */ - lum += s->width; - for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) { - LINE_WITH_UV - } - /* skip a luminance line - will be filled in later */ - lum += s->width; - read(s->fd,src,s->width*2); - } - /* - * Do last two lines - */ - for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) { - LINE_WITH_UV - } - /* skip a luminance line - will be filled in later */ - lum += s->width; - read(s->fd,src,s->width*2); - for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, cb+=8, cr+=8) { - LINE_WITH_UV - } - /* - * - * SECOND FIELD - * - */ - lum=&data[s->width]; - while (read(s->fd,src,s->width*2) < 0) { - usleep(10); - } - /* First (and last) two lines not interlaced */ - for (h = 0; h < 2; h++) { - for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16) { - LINE_NO_UV - } - read(s->fd,src,s->width*2); - /* skip a luminance line */ - lum += s->width; - } - lum_m1=&lum[-s->width]; - lum_m2=&lum_m1[-s->width]; - lum_m3=&lum_m2[-s->width]; - memmove(s->lum_m4_mem,&lum_m3[-s->width],s->width); - for (; h < (s->height/2)-1; h++) { - lum_m4=s->lum_m4_mem; - for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16,lum_m1+=16,lum_m2+=16,lum_m3+=16,lum_m4+=16) { - LINE_NO_UV - - DEINT_LINE_LUM(0) - DEINT_LINE_LUM(4) - DEINT_LINE_LUM(8) - DEINT_LINE_LUM(12) - } - read(s->fd,src,s->width*2); - /* skip a luminance line */ - lum += s->width; - lum_m1 += s->width; - lum_m2 += s->width; - lum_m3 += s->width; - // lum_m4 += s->width; - } - /* - * Do last line - */ - lum_m4=s->lum_m4_mem; - for (ptr = &src[0]; ptr < ptrend; ptr+=32, lum+=16, lum_m1+=16, lum_m2+=16, lum_m3+=16, lum_m4+=16) { - LINE_NO_UV - - DEINT_LINE_LUM(0) - DEINT_LINE_LUM(4) - DEINT_LINE_LUM(8) - DEINT_LINE_LUM(12) - } - } -#ifdef HAVE_MMX - emms(); -#endif - return s->frame_size; -} - -static int aiw_close(VideoData *s) -{ - av_freep(&s->lum_m4_mem); - av_freep(&s->src_mem); - return 0; -} diff --git a/contrib/ffmpeg/libavformat/grab_bktr.c b/contrib/ffmpeg/libavformat/grab_bktr.c deleted file mode 100644 index 100653db7..000000000 --- a/contrib/ffmpeg/libavformat/grab_bktr.c +++ /dev/null @@ -1,320 +0,0 @@ -/* - * *BSD video grab interface - * Copyright (c) 2002 Steve O'Hara-Smith - * based on - * Linux video grab interface - * Copyright (c) 2000,2001 Gerard Lantau. - * and - * simple_grab.c Copyright (c) 1999 Roger Hardiman - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include "avformat.h" -#if defined (HAVE_DEV_BKTR_IOCTL_METEOR_H) && defined (HAVE_DEV_BKTR_IOCTL_BT848_H) -# include -# include -#elif defined (HAVE_MACHINE_IOCTL_METEOR_H) && defined (HAVE_MACHINE_IOCTL_BT848_H) -# include -# include -#elif defined (HAVE_DEV_VIDEO_METEOR_IOCTL_METEOR_H) && defined (HAVE_DEV_VIDEO_METEOR_IOCTL_BT848_H) -# include -# include -#elif HAVE_DEV_IC_BT8XX_H -# include -#endif -#include -#include -#include -#include -#include -#include - -typedef struct { - int video_fd; - int tuner_fd; - int width, height; - int frame_rate; - int frame_rate_base; - u_int64_t per_frame; -} VideoData; - - -#define PAL 1 -#define PALBDGHI 1 -#define NTSC 2 -#define NTSCM 2 -#define SECAM 3 -#define PALN 4 -#define PALM 5 -#define NTSCJ 6 - -/* PAL is 768 x 576. NTSC is 640 x 480 */ -#define PAL_HEIGHT 576 -#define SECAM_HEIGHT 576 -#define NTSC_HEIGHT 480 - -#ifndef VIDEO_FORMAT -#define VIDEO_FORMAT NTSC -#endif - -static int bktr_dev[] = { METEOR_DEV0, METEOR_DEV1, METEOR_DEV2, - METEOR_DEV3, METEOR_DEV_SVIDEO }; - -uint8_t *video_buf; -size_t video_buf_size; -u_int64_t last_frame_time; -volatile sig_atomic_t nsignals; - - -static void catchsignal(int signal) -{ - nsignals++; - return; -} - -static int bktr_init(const char *video_device, int width, int height, - int format, int *video_fd, int *tuner_fd, int idev, double frequency) -{ - struct meteor_geomet geo; - int h_max; - long ioctl_frequency; - char *arg; - int c; - struct sigaction act, old; - - if (idev < 0 || idev > 4) - { - arg = getenv ("BKTR_DEV"); - if (arg) - idev = atoi (arg); - if (idev < 0 || idev > 4) - idev = 1; - } - - if (format < 1 || format > 6) - { - arg = getenv ("BKTR_FORMAT"); - if (arg) - format = atoi (arg); - if (format < 1 || format > 6) - format = VIDEO_FORMAT; - } - - if (frequency <= 0) - { - arg = getenv ("BKTR_FREQUENCY"); - if (arg) - frequency = atof (arg); - if (frequency <= 0) - frequency = 0.0; - } - - memset(&act, 0, sizeof(act)); - sigemptyset(&act.sa_mask); - act.sa_handler = catchsignal; - sigaction(SIGUSR1, &act, &old); - - *tuner_fd = open("/dev/tuner0", O_RDONLY); - if (*tuner_fd < 0) - perror("Warning: Tuner not opened, continuing"); - - *video_fd = open(video_device, O_RDONLY); - if (*video_fd < 0) { - perror(video_device); - return -1; - } - - geo.rows = height; - geo.columns = width; - geo.frames = 1; - geo.oformat = METEOR_GEO_YUV_422 | METEOR_GEO_YUV_12; - - switch (format) { - case PAL: h_max = PAL_HEIGHT; c = BT848_IFORM_F_PALBDGHI; break; - case PALN: h_max = PAL_HEIGHT; c = BT848_IFORM_F_PALN; break; - case PALM: h_max = PAL_HEIGHT; c = BT848_IFORM_F_PALM; break; - case SECAM: h_max = SECAM_HEIGHT; c = BT848_IFORM_F_SECAM; break; - case NTSC: h_max = NTSC_HEIGHT; c = BT848_IFORM_F_NTSCM; break; - case NTSCJ: h_max = NTSC_HEIGHT; c = BT848_IFORM_F_NTSCJ; break; - default: h_max = PAL_HEIGHT; c = BT848_IFORM_F_PALBDGHI; break; - } - - if (height <= h_max / 2) - geo.oformat |= METEOR_GEO_EVEN_ONLY; - - if (ioctl(*video_fd, METEORSETGEO, &geo) < 0) { - perror("METEORSETGEO"); - return -1; - } - - if (ioctl(*video_fd, BT848SFMT, &c) < 0) { - perror("BT848SFMT"); - return -1; - } - - c = bktr_dev[idev]; - if (ioctl(*video_fd, METEORSINPUT, &c) < 0) { - perror("METEORSINPUT"); - return -1; - } - - video_buf_size = width * height * 12 / 8; - - video_buf = (uint8_t *)mmap((caddr_t)0, video_buf_size, - PROT_READ, MAP_SHARED, *video_fd, (off_t)0); - if (video_buf == MAP_FAILED) { - perror("mmap"); - return -1; - } - - if (frequency != 0.0) { - ioctl_frequency = (unsigned long)(frequency*16); - if (ioctl(*tuner_fd, TVTUNER_SETFREQ, &ioctl_frequency) < 0) - perror("TVTUNER_SETFREQ"); - } - - c = AUDIO_UNMUTE; - if (ioctl(*tuner_fd, BT848_SAUDIO, &c) < 0) - perror("TVTUNER_SAUDIO"); - - c = METEOR_CAP_CONTINOUS; - ioctl(*video_fd, METEORCAPTUR, &c); - - c = SIGUSR1; - ioctl(*video_fd, METEORSSIGNAL, &c); - - return 0; -} - -static void bktr_getframe(u_int64_t per_frame) -{ - u_int64_t curtime; - - curtime = av_gettime(); - if (!last_frame_time - || ((last_frame_time + per_frame) > curtime)) { - if (!usleep(last_frame_time + per_frame + per_frame / 8 - curtime)) { - if (!nsignals) - av_log(NULL, AV_LOG_INFO, - "SLEPT NO signals - %d microseconds late\n", - (int)(av_gettime() - last_frame_time - per_frame)); - } - } - nsignals = 0; - last_frame_time = curtime; -} - - -/* note: we support only one picture read at a time */ -static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt) -{ - VideoData *s = s1->priv_data; - - if (av_new_packet(pkt, video_buf_size) < 0) - return AVERROR(EIO); - - bktr_getframe(s->per_frame); - - pkt->pts = av_gettime(); - memcpy(pkt->data, video_buf, video_buf_size); - - return video_buf_size; -} - -static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) -{ - VideoData *s = s1->priv_data; - AVStream *st; - int width, height; - int frame_rate; - int frame_rate_base; - int format = -1; - - if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) - return -1; - - width = ap->width; - height = ap->height; - frame_rate = ap->time_base.den; - frame_rate_base = ap->time_base.num; - - st = av_new_stream(s1, 0); - if (!st) - return AVERROR(ENOMEM); - av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in use */ - - s->width = width; - s->height = height; - s->frame_rate = frame_rate; - s->frame_rate_base = frame_rate_base; - s->per_frame = ((u_int64_t)1000000 * s->frame_rate_base) / s->frame_rate; - - st->codec->codec_type = CODEC_TYPE_VIDEO; - st->codec->pix_fmt = PIX_FMT_YUV420P; - st->codec->codec_id = CODEC_ID_RAWVIDEO; - st->codec->width = width; - st->codec->height = height; - st->codec->time_base.den = frame_rate; - st->codec->time_base.num = frame_rate_base; - - if (ap->standard) { - if (!strcasecmp(ap->standard, "pal")) - format = PAL; - else if (!strcasecmp(ap->standard, "secam")) - format = SECAM; - else if (!strcasecmp(ap->standard, "ntsc")) - format = NTSC; - } - - if (bktr_init(s1->filename, width, height, format, - &(s->video_fd), &(s->tuner_fd), -1, 0.0) < 0) - return AVERROR(EIO); - - nsignals = 0; - last_frame_time = 0; - - return 0; -} - -static int grab_read_close(AVFormatContext *s1) -{ - VideoData *s = s1->priv_data; - int c; - - c = METEOR_CAP_STOP_CONT; - ioctl(s->video_fd, METEORCAPTUR, &c); - close(s->video_fd); - - c = AUDIO_MUTE; - ioctl(s->tuner_fd, BT848_SAUDIO, &c); - close(s->tuner_fd); - - munmap((caddr_t)video_buf, video_buf_size); - - return 0; -} - -AVInputFormat video_grab_device_demuxer = { - "bktr", - "video grab", - sizeof(VideoData), - NULL, - grab_read_header, - grab_read_packet, - grab_read_close, - .flags = AVFMT_NOFILE, -}; diff --git a/contrib/ffmpeg/libavformat/gxf.c b/contrib/ffmpeg/libavformat/gxf.c index ba2463ead..d4bf6f43b 100644 --- a/contrib/ffmpeg/libavformat/gxf.c +++ b/contrib/ffmpeg/libavformat/gxf.c @@ -20,33 +20,7 @@ */ #include "avformat.h" #include "common.h" - -typedef enum { - PKT_MAP = 0xbc, - PKT_MEDIA = 0xbf, - PKT_EOS = 0xfb, - PKT_FLT = 0xfc, - PKT_UMF = 0xfd -} pkt_type_t; - -typedef enum { - MAT_NAME = 0x40, - MAT_FIRST_FIELD = 0x41, - MAT_LAST_FIELD = 0x42, - MAT_MARK_IN = 0x43, - MAT_MARK_OUT = 0x44, - MAT_SIZE = 0x45 -} mat_tag_t; - -typedef enum { - TRACK_NAME = 0x4c, - TRACK_AUX = 0x4d, - TRACK_VER = 0x4e, - TRACK_MPG_AUX = 0x4f, - TRACK_FPS = 0x50, - TRACK_LINES = 0x51, - TRACK_FPF = 0x52 -} track_tag_t; +#include "gxf.h" typedef struct { int64_t first_field; @@ -87,8 +61,6 @@ static int parse_packet_header(ByteIOContext *pb, pkt_type_t *type, int *length) static int gxf_probe(AVProbeData *p) { static const uint8_t startcode[] = {0, 0, 0, 0, 1, 0xbc}; // start with map packet static const uint8_t endcode[] = {0, 0, 0, 0, 0xe1, 0xe2}; - if (p->buf_size < 16) - return 0; if (!memcmp(p->buf, startcode, sizeof(startcode)) && !memcmp(&p->buf[16 - sizeof(endcode)], endcode, sizeof(endcode))) return AVPROBE_SCORE_MAX; @@ -130,13 +102,13 @@ static int get_sindex(AVFormatContext *s, int id, int format) { case 20: st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_MPEG2VIDEO; - st->need_parsing = 2; // get keyframe flag etc. + st->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc. break; case 22: case 23: st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_MPEG1VIDEO; - st->need_parsing = 2; // get keyframe flag etc. + st->need_parsing = AVSTREAM_PARSE_HEADERS; //get keyframe flag etc. break; case 9: st->codec->codec_type = CODEC_TYPE_AUDIO; @@ -179,7 +151,7 @@ static int get_sindex(AVFormatContext *s, int id, int format) { /** * \brief filters out interesting tags from material information. - * \param len lenght of tag section, will be adjusted to contain remaining bytes + * \param len length of tag section, will be adjusted to contain remaining bytes * \param si struct to store collected information into */ static void gxf_material_tags(ByteIOContext *pb, int *len, st_info_t *si) { @@ -256,7 +228,7 @@ static void gxf_track_tags(ByteIOContext *pb, int *len, st_info_t *si) { * \brief read index from FLT packet into stream 0 av_index */ static void gxf_read_index(AVFormatContext *s, int pkt_len) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVStream *st = s->streams[0]; uint32_t fields_per_map = get_le32(pb); uint32_t map_cnt = get_le32(pb); @@ -280,7 +252,7 @@ static void gxf_read_index(AVFormatContext *s, int pkt_len) { } static int gxf_header(AVFormatContext *s, AVFormatParameters *ap) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; pkt_type_t pkt_type; int map_len; int len; @@ -406,7 +378,7 @@ static int64_t gxf_resync_media(AVFormatContext *s, uint64_t max_interval, int t int cur_track; int64_t cur_timestamp = AV_NOPTS_VALUE; int len; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; pkt_type_t type; tmp = get_be32(pb); start: @@ -436,7 +408,7 @@ out: } static int gxf_packet(AVFormatContext *s, AVPacket *pkt) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; pkt_type_t pkt_type; int pkt_len; while (!url_feof(pb)) { @@ -475,7 +447,7 @@ static int gxf_packet(AVFormatContext *s, AVPacket *pkt) { pkt->dts = field_nr; return ret; } - return AVERROR_IO; + return AVERROR(EIO); } static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { @@ -494,7 +466,7 @@ static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int if (idx < st->nb_index_entries - 2) maxlen = st->index_entries[idx + 2].pos - pos; maxlen = FFMAX(maxlen, 200 * 1024); - url_fseek(&s->pb, pos, SEEK_SET); + url_fseek(s->pb, pos, SEEK_SET); found = gxf_resync_media(s, maxlen, -1, timestamp); if (FFABS(found - timestamp) > 4) return -1; @@ -503,7 +475,7 @@ static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int static int64_t gxf_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos, int64_t pos_limit) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int64_t res; url_fseek(pb, *pos, SEEK_SET); res = gxf_resync_media(s, pos_limit - *pos, -1, -1); diff --git a/contrib/ffmpeg/libavformat/gxf.h b/contrib/ffmpeg/libavformat/gxf.h index 0e2a31ca4..ab37cb97f 100644 --- a/contrib/ffmpeg/libavformat/gxf.h +++ b/contrib/ffmpeg/libavformat/gxf.h @@ -24,11 +24,30 @@ /* gxf.c */ typedef enum { - PKT_MAP = 0xbc, - PKT_MEDIA = 0xbf, - PKT_EOS = 0xfb, - PKT_FLT = 0xfc, - PKT_UMF = 0xfd + PKT_MAP = 0xbc, + PKT_MEDIA = 0xbf, + PKT_EOS = 0xfb, + PKT_FLT = 0xfc, + PKT_UMF = 0xfd, } pkt_type_t; +typedef enum { + MAT_NAME = 0x40, + MAT_FIRST_FIELD = 0x41, + MAT_LAST_FIELD = 0x42, + MAT_MARK_IN = 0x43, + MAT_MARK_OUT = 0x44, + MAT_SIZE = 0x45, +} mat_tag_t; + +typedef enum { + TRACK_NAME = 0x4c, + TRACK_AUX = 0x4d, + TRACK_VER = 0x4e, + TRACK_MPG_AUX = 0x4f, + TRACK_FPS = 0x50, + TRACK_LINES = 0x51, + TRACK_FPF = 0x52, +} track_tag_t; + #endif /* FFMPEG_GXF_H */ diff --git a/contrib/ffmpeg/libavformat/gxfenc.c b/contrib/ffmpeg/libavformat/gxfenc.c index 39b9ed3e1..469105de5 100644 --- a/contrib/ffmpeg/libavformat/gxfenc.c +++ b/contrib/ffmpeg/libavformat/gxfenc.c @@ -4,18 +4,18 @@ * * This file is part of FFmpeg. * - * FFmpeg is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * FFmpeg 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. * * FFmpeg 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 General Public License for more details. + * 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 General Public License - * along with FFmpeg; if not, write to the Free Software + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -187,7 +187,7 @@ static int gxf_write_mpeg_auxiliary(ByteIOContext *pb, GXFStreamContext *ctx) (float)ctx->codec->bit_rate, ctx->p_per_gop, ctx->b_per_gop, ctx->codec->pix_fmt == PIX_FMT_YUV422P ? 2 : 1, ctx->first_gop_closed == 1, ctx->codec->height / 16); - put_byte(pb, 0x4F); + put_byte(pb, TRACK_MPG_AUX); put_byte(pb, size + 1); put_buffer(pb, (uint8_t *)buffer, size + 1); return size + 3; @@ -217,7 +217,7 @@ static int gxf_write_track_description(ByteIOContext *pb, GXFStreamContext *stre put_be16(pb, 0); /* size */ /* media file name */ - put_byte(pb, 0x4C); + put_byte(pb, TRACK_NAME); put_byte(pb, strlen(ES_NAME_PATTERN) + 3); put_tag(pb, ES_NAME_PATTERN); put_be16(pb, stream->media_info); @@ -225,7 +225,7 @@ static int gxf_write_track_description(ByteIOContext *pb, GXFStreamContext *stre if (stream->codec->codec_id != CODEC_ID_MPEG2VIDEO) { /* auxiliary information */ - put_byte(pb, 0x4D); + put_byte(pb, TRACK_AUX); put_byte(pb, 8); if (stream->codec->codec_id == CODEC_ID_NONE) gxf_write_timecode_auxiliary(pb, stream); @@ -234,7 +234,7 @@ static int gxf_write_track_description(ByteIOContext *pb, GXFStreamContext *stre } /* file system version */ - put_byte(pb, 0x4E); + put_byte(pb, TRACK_VER); put_byte(pb, 4); put_be32(pb, 0); @@ -242,17 +242,17 @@ static int gxf_write_track_description(ByteIOContext *pb, GXFStreamContext *stre gxf_write_mpeg_auxiliary(pb, stream); /* frame rate */ - put_byte(pb, 0x50); + put_byte(pb, TRACK_FPS); put_byte(pb, 4); put_be32(pb, stream->frame_rate_index); /* lines per frame */ - put_byte(pb, 0x51); + put_byte(pb, TRACK_LINES); put_byte(pb, 4); put_be32(pb, stream->lines_index); /* fields per frame */ - put_byte(pb, 0x52); + put_byte(pb, TRACK_FPF); put_byte(pb, 4); put_be32(pb, stream->fields); @@ -272,33 +272,33 @@ static int gxf_write_material_data_section(ByteIOContext *pb, GXFContext *ctx) filename++; else filename = ctx->fc->filename; - put_byte(pb, 0x40); + put_byte(pb, MAT_NAME); put_byte(pb, strlen(SERVER_PATH) + strlen(filename) + 1); put_tag(pb, SERVER_PATH); put_tag(pb, filename); put_byte(pb, 0); /* first field */ - put_byte(pb, 0x41); + put_byte(pb, MAT_FIRST_FIELD); put_byte(pb, 4); put_be32(pb, 0); /* last field */ - put_byte(pb, 0x42); + put_byte(pb, MAT_LAST_FIELD); put_byte(pb, 4); put_be32(pb, ctx->nb_frames); /* reserved */ - put_byte(pb, 0x43); + put_byte(pb, MAT_MARK_IN); put_byte(pb, 4); put_be32(pb, 0); - put_byte(pb, 0x44); + put_byte(pb, MAT_MARK_OUT); put_byte(pb, 4); put_be32(pb, ctx->nb_frames); /* estimated size */ - put_byte(pb, 0x45); + put_byte(pb, MAT_SIZE); put_byte(pb, 4); put_be32(pb, url_fsize(pb) / 1024); @@ -576,7 +576,7 @@ static int gxf_write_umf_packet(ByteIOContext *pb, GXFContext *ctx) static int gxf_write_header(AVFormatContext *s) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; GXFContext *gxf = s->priv_data; int i; @@ -671,7 +671,7 @@ static int gxf_write_eos_packet(ByteIOContext *pb, GXFContext *ctx) static int gxf_write_trailer(AVFormatContext *s) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; GXFContext *gxf = s->priv_data; offset_t end; int i; @@ -679,9 +679,9 @@ static int gxf_write_trailer(AVFormatContext *s) for (i = 0; i < s->nb_streams; ++i) { if (s->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO) { av_fifo_free(&gxf->streams[i].audio_buffer); - } - if (s->streams[i]->codec->frame_number > gxf->nb_frames) + } else if (s->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO) { gxf->nb_frames = 2 * s->streams[i]->codec->frame_number; + } } gxf_write_eos_packet(pb, gxf); @@ -710,7 +710,7 @@ static int gxf_parse_mpeg_frame(GXFStreamContext *sc, const uint8_t *buf, int si static int gxf_write_media_preamble(ByteIOContext *pb, GXFContext *ctx, AVPacket *pkt, int size) { GXFStreamContext *sc = &ctx->streams[pkt->stream_index]; - int64_t dts = av_rescale(pkt->dts, ctx->sample_rate, sc->codec->time_base.den); + int64_t dts = av_rescale_rnd(pkt->dts, ctx->sample_rate, sc->codec->time_base.den, AV_ROUND_UP); put_byte(pb, sc->media_type); put_byte(pb, sc->index); @@ -763,8 +763,8 @@ static int gxf_write_packet(AVFormatContext *s, AVPacket *pkt) { GXFContext *gxf = s->priv_data; - gxf_write_media_packet(&s->pb, gxf, pkt); - put_flush_packet(&s->pb); + gxf_write_media_packet(s->pb, gxf, pkt); + put_flush_packet(s->pb); return 0; } diff --git a/contrib/ffmpeg/libavformat/http.c b/contrib/ffmpeg/libavformat/http.c index e057d6efe..1d542061b 100644 --- a/contrib/ffmpeg/libavformat/http.c +++ b/contrib/ffmpeg/libavformat/http.c @@ -21,11 +21,13 @@ #include "avformat.h" #include #include "network.h" +#include "os_support.h" #include "base64.h" +#include "avstring.h" -/* XXX: POST protocol is not completly implemented because ffmpeg use - only a subset of it */ +/* XXX: POST protocol is not completely implemented because ffmpeg uses + only a subset of it. */ //#define DEBUG @@ -62,7 +64,7 @@ static int http_open_cnx(URLContext *h) proxy_path = getenv("http_proxy"); use_proxy = (proxy_path != NULL) && !getenv("no_proxy") && - strstart(proxy_path, "http://", NULL); + av_strstart(proxy_path, "http://", NULL); /* fill the dest addr */ redo: @@ -72,7 +74,7 @@ static int http_open_cnx(URLContext *h) if (port > 0) { snprintf(hoststr, sizeof(hoststr), "%s:%d", hostname, port); } else { - pstrcpy(hoststr, sizeof(hoststr), hostname); + av_strlcpy(hoststr, hostname, sizeof(hoststr)); } if (use_proxy) { @@ -100,7 +102,7 @@ static int http_open_cnx(URLContext *h) /* url moved, get next */ url_close(hd); if (redirects++ >= MAX_REDIRECTS) - return AVERROR_IO; + return AVERROR(EIO); location_changed = 0; goto redo; } @@ -108,7 +110,7 @@ static int http_open_cnx(URLContext *h) fail: if (hd) url_close(hd); - return AVERROR_IO; + return AVERROR(EIO); } static int http_open(URLContext *h, const char *uri, int flags) @@ -125,7 +127,7 @@ static int http_open(URLContext *h, const char *uri, int flags) h->priv_data = s; s->filesize = -1; s->off = 0; - pstrcpy (s->location, URL_SIZE, uri); + av_strlcpy(s->location, uri, URL_SIZE); ret = http_open_cnx(h); if (ret != 0) @@ -138,7 +140,7 @@ static int http_getc(HTTPContext *s) if (s->buf_ptr >= s->buf_end) { len = url_read(s->hd, s->buffer, BUFFER_SIZE); if (len < 0) { - return AVERROR_IO; + return AVERROR(EIO); } else if (len == 0) { return -1; } else { @@ -217,7 +219,7 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr, /* send http header */ post = h->flags & URL_WRONLY; auth_b64 = av_malloc(auth_b64_len); - av_base64_encode(auth_b64, auth_b64_len, (uint8_t *)auth, strlen(auth)); + av_base64_encode(auth_b64, auth_b64_len, auth, strlen(auth)); snprintf(s->buffer, sizeof(s->buffer), "%s %s HTTP/1.1\r\n" "User-Agent: %s\r\n" @@ -236,7 +238,7 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr, av_freep(&auth_b64); if (http_write(h, s->buffer, strlen(s->buffer)) < 0) - return AVERROR_IO; + return AVERROR(EIO); /* init input buffer */ s->buf_ptr = s->buffer; @@ -245,7 +247,6 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr, s->off = 0; s->filesize = -1; if (post) { - sleep(1); return 0; } @@ -254,7 +255,7 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr, for(;;) { ch = http_getc(s); if (ch < 0) - return AVERROR_IO; + return AVERROR(EIO); if (ch == '\n') { /* process line */ if (q > line && q[-1] == '\r') diff --git a/contrib/ffmpeg/libavformat/idcin.c b/contrib/ffmpeg/libavformat/idcin.c index e2c92f3b4..914a3532a 100644 --- a/contrib/ffmpeg/libavformat/idcin.c +++ b/contrib/ffmpeg/libavformat/idcin.c @@ -71,7 +71,7 @@ #include "avformat.h" #define HUFFMAN_TABLE_SIZE (64 * 1024) -#define FRAME_PTS_INC (90000 / 14) +#define IDCIN_FPS 14 typedef struct IdcinDemuxContext { int video_stream_index; @@ -104,10 +104,6 @@ static int idcin_probe(AVProbeData *p) * audio channels: 0 for no audio, or 1 or 2 */ - /* cannot proceed without 20 bytes */ - if (p->buf_size < 20) - return 0; - /* check the video width */ number = AV_RL32(&p->buf[0]); if ((number == 0) || (number > 1024)) @@ -140,8 +136,8 @@ static int idcin_probe(AVProbeData *p) static int idcin_read_header(AVFormatContext *s, AVFormatParameters *ap) { - ByteIOContext *pb = &s->pb; - IdcinDemuxContext *idcin = (IdcinDemuxContext *)s->priv_data; + ByteIOContext *pb = s->pb; + IdcinDemuxContext *idcin = s->priv_data; AVStream *st; unsigned int width, height; unsigned int sample_rate, bytes_per_sample, channels; @@ -155,8 +151,8 @@ static int idcin_read_header(AVFormatContext *s, st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; - av_set_pts_info(st, 33, 1, 90000); + return AVERROR(ENOMEM); + av_set_pts_info(st, 33, 1, IDCIN_FPS); idcin->video_stream_index = st->index; st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_IDCIN; @@ -169,7 +165,7 @@ static int idcin_read_header(AVFormatContext *s, st->codec->extradata = av_malloc(HUFFMAN_TABLE_SIZE); if (get_buffer(pb, st->codec->extradata, HUFFMAN_TABLE_SIZE) != HUFFMAN_TABLE_SIZE) - return AVERROR_IO; + return AVERROR(EIO); /* save a reference in order to transport the palette */ st->codec->palctrl = &idcin->palctrl; @@ -178,8 +174,8 @@ static int idcin_read_header(AVFormatContext *s, idcin->audio_present = 1; st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; - av_set_pts_info(st, 33, 1, 90000); + return AVERROR(ENOMEM); + av_set_pts_info(st, 33, 1, IDCIN_FPS); idcin->audio_stream_index = st->index; st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_tag = 1; @@ -218,25 +214,25 @@ static int idcin_read_packet(AVFormatContext *s, int ret; unsigned int command; unsigned int chunk_size; - IdcinDemuxContext *idcin = (IdcinDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + IdcinDemuxContext *idcin = s->priv_data; + ByteIOContext *pb = s->pb; int i; int palette_scale; unsigned char r, g, b; unsigned char palette_buffer[768]; - if (url_feof(&s->pb)) - return AVERROR_IO; + if (url_feof(s->pb)) + return AVERROR(EIO); if (idcin->next_chunk_is_video) { command = get_le32(pb); if (command == 2) { - return AVERROR_IO; + return AVERROR(EIO); } else if (command == 1) { /* trigger a palette change */ idcin->palctrl.palette_changed = 1; if (get_buffer(pb, palette_buffer, 768) != 768) - return AVERROR_IO; + return AVERROR(EIO); /* scale the palette as necessary */ palette_scale = 2; for (i = 0; i < 768; i++) @@ -259,7 +255,7 @@ static int idcin_read_packet(AVFormatContext *s, chunk_size -= 4; ret= av_get_packet(pb, pkt, chunk_size); if (ret != chunk_size) - return AVERROR_IO; + return AVERROR(EIO); pkt->stream_index = idcin->video_stream_index; pkt->pts = idcin->pts; } else { @@ -270,12 +266,12 @@ static int idcin_read_packet(AVFormatContext *s, chunk_size = idcin->audio_chunk_size1; ret= av_get_packet(pb, pkt, chunk_size); if (ret != chunk_size) - return AVERROR_IO; + return AVERROR(EIO); pkt->stream_index = idcin->audio_stream_index; pkt->pts = idcin->pts; idcin->current_audio_chunk ^= 1; - idcin->pts += FRAME_PTS_INC; + idcin->pts++; } if (idcin->audio_present) diff --git a/contrib/ffmpeg/libavformat/idroq.c b/contrib/ffmpeg/libavformat/idroq.c index b8ee176ab..394697fcd 100644 --- a/contrib/ffmpeg/libavformat/idroq.c +++ b/contrib/ffmpeg/libavformat/idroq.c @@ -58,9 +58,6 @@ typedef struct RoqDemuxContext { static int roq_probe(AVProbeData *p) { - if (p->buf_size < 6) - return 0; - if ((AV_RL16(&p->buf[0]) != RoQ_MAGIC_NUMBER) || (AV_RL32(&p->buf[2]) != 0xFFFFFFFF)) return 0; @@ -72,7 +69,7 @@ static int roq_read_header(AVFormatContext *s, AVFormatParameters *ap) { RoqDemuxContext *roq = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVStream *st; unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE]; int i; @@ -82,7 +79,7 @@ static int roq_read_header(AVFormatContext *s, /* get the main header */ if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != RoQ_CHUNK_PREAMBLE_SIZE) - return AVERROR_IO; + return AVERROR(EIO); roq->framerate = AV_RL16(&preamble[6]); roq->frame_pts_inc = 90000 / roq->framerate; @@ -94,7 +91,7 @@ static int roq_read_header(AVFormatContext *s, for (i = 0; i < RoQ_CHUNKS_TO_SCAN; i++) { if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != RoQ_CHUNK_PREAMBLE_SIZE) - return AVERROR_IO; + return AVERROR(EIO); chunk_type = AV_RL16(&preamble[0]); chunk_size = AV_RL32(&preamble[2]); @@ -105,7 +102,7 @@ static int roq_read_header(AVFormatContext *s, /* fetch the width and height; reuse the preamble bytes */ if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != RoQ_CHUNK_PREAMBLE_SIZE) - return AVERROR_IO; + return AVERROR(EIO); roq->width = AV_RL16(&preamble[0]); roq->height = AV_RL16(&preamble[2]); break; @@ -143,7 +140,7 @@ static int roq_read_header(AVFormatContext *s, /* initialize the decoders */ st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); /* set the pts reference (1 pts = 1/90000) */ av_set_pts_info(st, 33, 1, 90000); roq->video_stream_index = st->index; @@ -156,7 +153,7 @@ static int roq_read_header(AVFormatContext *s, if (roq->audio_channels) { st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 33, 1, 90000); roq->audio_stream_index = st->index; st->codec->codec_type = CODEC_TYPE_AUDIO; @@ -177,7 +174,7 @@ static int roq_read_packet(AVFormatContext *s, AVPacket *pkt) { RoqDemuxContext *roq = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int ret = 0; unsigned int chunk_size; unsigned int chunk_type; @@ -188,13 +185,13 @@ static int roq_read_packet(AVFormatContext *s, while (!packet_read) { - if (url_feof(&s->pb)) - return AVERROR_IO; + if (url_feof(s->pb)) + return AVERROR(EIO); /* get the next chunk preamble */ if ((ret = get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE)) != RoQ_CHUNK_PREAMBLE_SIZE) - return AVERROR_IO; + return AVERROR(EIO); chunk_type = AV_RL16(&preamble[0]); chunk_size = AV_RL32(&preamble[2]); @@ -215,7 +212,7 @@ static int roq_read_packet(AVFormatContext *s, url_fseek(pb, codebook_size, SEEK_CUR); if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != RoQ_CHUNK_PREAMBLE_SIZE) - return AVERROR_IO; + return AVERROR(EIO); chunk_size = AV_RL32(&preamble[2]) + RoQ_CHUNK_PREAMBLE_SIZE * 2 + codebook_size; @@ -225,7 +222,7 @@ static int roq_read_packet(AVFormatContext *s, /* load up the packet */ ret= av_get_packet(pb, pkt, chunk_size); if (ret != chunk_size) - return AVERROR_IO; + return AVERROR(EIO); pkt->stream_index = roq->video_stream_index; pkt->pts = roq->video_pts; @@ -238,7 +235,7 @@ static int roq_read_packet(AVFormatContext *s, case RoQ_QUAD_VQ: /* load up the packet */ if (av_new_packet(pkt, chunk_size + RoQ_CHUNK_PREAMBLE_SIZE)) - return AVERROR_IO; + return AVERROR(EIO); /* copy over preamble */ memcpy(pkt->data, preamble, RoQ_CHUNK_PREAMBLE_SIZE); @@ -258,7 +255,7 @@ static int roq_read_packet(AVFormatContext *s, ret = get_buffer(pb, pkt->data + RoQ_CHUNK_PREAMBLE_SIZE, chunk_size); if (ret != chunk_size) - ret = AVERROR_IO; + ret = AVERROR(EIO); packet_read = 1; break; @@ -275,7 +272,7 @@ static int roq_read_packet(AVFormatContext *s, static int roq_read_close(AVFormatContext *s) { -// RoqDemuxContext *roq = (RoqDemuxContext *)s->priv_data; +// RoqDemuxContext *roq = s->priv_data; return 0; } diff --git a/contrib/ffmpeg/libavformat/img2.c b/contrib/ffmpeg/libavformat/img2.c index fa67ee742..6e846df66 100644 --- a/contrib/ffmpeg/libavformat/img2.c +++ b/contrib/ffmpeg/libavformat/img2.c @@ -20,6 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avformat.h" +#include "avstring.h" typedef struct { int img_first; @@ -40,6 +41,7 @@ static const IdStrMap img_tags[] = { { CODEC_ID_MJPEG , "jpg"}, { CODEC_ID_LJPEG , "ljpg"}, { CODEC_ID_PNG , "png"}, + { CODEC_ID_PNG , "mng"}, { CODEC_ID_PPM , "ppm"}, { CODEC_ID_PGM , "pgm"}, { CODEC_ID_PGMYUV , "pgmyuv"}, @@ -54,6 +56,16 @@ static const IdStrMap img_tags[] = { { CODEC_ID_GIF , "gif"}, { CODEC_ID_TARGA , "tga"}, { CODEC_ID_TIFF , "tiff"}, + { CODEC_ID_SGI , "sgi"}, + { CODEC_ID_PTX , "ptx"}, + { CODEC_ID_PCX , "pcx"}, + { CODEC_ID_SUNRAST , "sun"}, + { CODEC_ID_SUNRAST , "ras"}, + { CODEC_ID_SUNRAST , "rs"}, + { CODEC_ID_SUNRAST , "im1"}, + { CODEC_ID_SUNRAST , "im8"}, + { CODEC_ID_SUNRAST , "im24"}, + { CODEC_ID_SUNRAST , "sunras"}, {0, NULL} }; @@ -180,7 +192,7 @@ static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap) return AVERROR(ENOMEM); } - pstrcpy(s->path, sizeof(s->path), s1->filename); + av_strlcpy(s->path, s1->filename, sizeof(s->path)); s->img_number = 0; s->img_count = 0; @@ -189,7 +201,7 @@ static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap) s->is_pipe = 0; else{ s->is_pipe = 1; - st->need_parsing= 1; + st->need_parsing = AVSTREAM_PARSE_FULL; } if (!ap->time_base.num) { @@ -205,7 +217,7 @@ static int img_read_header(AVFormatContext *s1, AVFormatParameters *ap) if (!s->is_pipe) { if (find_image_range(&first_index, &last_index, s->path) < 0) - return AVERROR_IO; + return AVERROR(EIO); s->img_first = first_index; s->img_last = last_index; s->img_number = first_index; @@ -236,7 +248,7 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt) char filename[1024]; int i; int size[3]={0}, ret[3]={0}; - ByteIOContext f1[3], *f[3]= {&f1[0], &f1[1], &f1[2]}; + ByteIOContext *f[3]; AVCodecContext *codec= s1->streams[0]->codec; if (!s->is_pipe) { @@ -246,10 +258,10 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt) } if (av_get_frame_filename(filename, sizeof(filename), s->path, s->img_number)<0 && s->img_number > 1) - return AVERROR_IO; + return AVERROR(EIO); for(i=0; i<3; i++){ - if (url_fopen(f[i], filename, URL_RDONLY) < 0) - return AVERROR_IO; + if (url_fopen(&f[i], filename, URL_RDONLY) < 0) + return AVERROR(EIO); size[i]= url_fsize(f[i]); if(codec->codec_id != CODEC_ID_RAWVIDEO) @@ -260,9 +272,9 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt) if(codec->codec_id == CODEC_ID_RAWVIDEO && !codec->width) infer_size(&codec->width, &codec->height, size[0]); } else { - f[0] = &s1->pb; + f[0] = s1->pb; if (url_feof(f[0])) - return AVERROR_IO; + return AVERROR(EIO); size[0]= 4096; } @@ -283,7 +295,7 @@ static int img_read_packet(AVFormatContext *s1, AVPacket *pkt) if (ret[0] <= 0 || ret[1]<0 || ret[2]<0) { av_free_packet(pkt); - return AVERROR_IO; /* signal EOF */ + return AVERROR(EIO); /* signal EOF */ } else { s->img_count++; s->img_number++; @@ -305,7 +317,7 @@ static int img_write_header(AVFormatContext *s) VideoData *img = s->priv_data; img->img_number = 1; - pstrcpy(img->path, sizeof(img->path), s->filename); + av_strlcpy(img->path, s->filename, sizeof(img->path)); /* find format */ if (s->oformat->flags & AVFMT_NOFILE) @@ -319,7 +331,7 @@ static int img_write_header(AVFormatContext *s) static int img_write_packet(AVFormatContext *s, AVPacket *pkt) { VideoData *img = s->priv_data; - ByteIOContext pb1[3], *pb[3]= {&pb1[0], &pb1[1], &pb1[2]}; + ByteIOContext *pb[3]; char filename[1024]; AVCodecContext *codec= s->streams[ pkt->stream_index ]->codec; int i; @@ -327,17 +339,17 @@ static int img_write_packet(AVFormatContext *s, AVPacket *pkt) if (!img->is_pipe) { if (av_get_frame_filename(filename, sizeof(filename), img->path, img->img_number) < 0 && img->img_number>1) - return AVERROR_IO; + return AVERROR(EIO); for(i=0; i<3; i++){ - if (url_fopen(pb[i], filename, URL_WRONLY) < 0) - return AVERROR_IO; + if (url_fopen(&pb[i], filename, URL_WRONLY) < 0) + return AVERROR(EIO); if(codec->codec_id != CODEC_ID_RAWVIDEO) break; filename[ strlen(filename) - 1 ]= 'U' + i; } } else { - pb[0] = &s->pb; + pb[0] = s->pb; } if(codec->codec_id == CODEC_ID_RAWVIDEO){ diff --git a/contrib/ffmpeg/libavformat/ipmovie.c b/contrib/ffmpeg/libavformat/ipmovie.c index 975bfd36b..311f29f49 100644 --- a/contrib/ffmpeg/libavformat/ipmovie.c +++ b/contrib/ffmpeg/libavformat/ipmovie.c @@ -507,8 +507,6 @@ static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb, static int ipmovie_probe(AVProbeData *p) { - if (p->buf_size < IPMOVIE_SIGNATURE_SIZE) - return 0; if (strncmp(p->buf, IPMOVIE_SIGNATURE, IPMOVIE_SIGNATURE_SIZE) != 0) return 0; @@ -518,8 +516,8 @@ static int ipmovie_probe(AVProbeData *p) static int ipmovie_read_header(AVFormatContext *s, AVFormatParameters *ap) { - IPMVEContext *ipmovie = (IPMVEContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + IPMVEContext *ipmovie = s->priv_data; + ByteIOContext *pb = s->pb; AVPacket pkt; AVStream *st; unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE]; @@ -541,7 +539,7 @@ static int ipmovie_read_header(AVFormatContext *s, * it; if it is the first video chunk, this is a silent file */ if (get_buffer(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) != CHUNK_PREAMBLE_SIZE) - return AVERROR_IO; + return AVERROR(EIO); chunk_type = AV_RL16(&chunk_preamble[2]); url_fseek(pb, -CHUNK_PREAMBLE_SIZE, SEEK_CUR); @@ -553,7 +551,7 @@ static int ipmovie_read_header(AVFormatContext *s, /* initialize the stream decoders */ st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 33, 1, 90000); ipmovie->video_stream_index = st->index; st->codec->codec_type = CODEC_TYPE_VIDEO; @@ -568,7 +566,7 @@ static int ipmovie_read_header(AVFormatContext *s, if (ipmovie->audio_type) { st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 33, 1, 90000); ipmovie->audio_stream_index = st->index; st->codec->codec_type = CODEC_TYPE_AUDIO; @@ -590,17 +588,17 @@ static int ipmovie_read_header(AVFormatContext *s, static int ipmovie_read_packet(AVFormatContext *s, AVPacket *pkt) { - IPMVEContext *ipmovie = (IPMVEContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + IPMVEContext *ipmovie = s->priv_data; + ByteIOContext *pb = s->pb; int ret; ret = process_ipmovie_chunk(ipmovie, pb, pkt); if (ret == CHUNK_BAD) ret = AVERROR_INVALIDDATA; else if (ret == CHUNK_EOF) - ret = AVERROR_IO; + ret = AVERROR(EIO); else if (ret == CHUNK_NOMEM) - ret = AVERROR_NOMEM; + ret = AVERROR(ENOMEM); else if (ret == CHUNK_VIDEO) ret = 0; else @@ -611,7 +609,7 @@ static int ipmovie_read_packet(AVFormatContext *s, static int ipmovie_read_close(AVFormatContext *s) { -// IPMVEContext *ipmovie = (IPMVEContext *)s->priv_data; +// IPMVEContext *ipmovie = s->priv_data; return 0; } diff --git a/contrib/ffmpeg/libavformat/isom.c b/contrib/ffmpeg/libavformat/isom.c index f913bc0a9..f6e81cdcf 100644 --- a/contrib/ffmpeg/libavformat/isom.c +++ b/contrib/ffmpeg/libavformat/isom.c @@ -26,12 +26,13 @@ #include "isom.h" /* http://www.mp4ra.org */ +/* ordered by muxing preference */ const AVCodecTag ff_mp4_obj_type[] = { { CODEC_ID_MPEG4 , 32 }, { CODEC_ID_H264 , 33 }, { CODEC_ID_AAC , 64 }, - { CODEC_ID_MPEG2VIDEO, 96 }, /* MPEG2 Simple */ { CODEC_ID_MPEG2VIDEO, 97 }, /* MPEG2 Main */ + { CODEC_ID_MPEG2VIDEO, 96 }, /* MPEG2 Simple */ { CODEC_ID_MPEG2VIDEO, 98 }, /* MPEG2 SNR */ { CODEC_ID_MPEG2VIDEO, 99 }, /* MPEG2 Spatial */ { CODEC_ID_MPEG2VIDEO, 100 }, /* MPEG2 High */ @@ -39,22 +40,16 @@ const AVCodecTag ff_mp4_obj_type[] = { { CODEC_ID_AAC , 102 }, /* MPEG2 AAC Main */ { CODEC_ID_AAC , 103 }, /* MPEG2 AAC Low */ { CODEC_ID_AAC , 104 }, /* MPEG2 AAC SSR */ + { CODEC_ID_MP3 , 107 }, /* 11172-3 */ { CODEC_ID_MP3 , 105 }, /* 13818-3 */ { CODEC_ID_MPEG1VIDEO, 106 }, /* 11172-2 */ - { CODEC_ID_MP3 , 107 }, /* 11172-3 */ { CODEC_ID_MJPEG , 108 }, /* 10918-1 */ { CODEC_ID_PNG , 109 }, { CODEC_ID_JPEG2000 , 110 }, /* 15444-1 */ { CODEC_ID_VC1 , 163 }, - { CODEC_ID_VORBIS , 221 }, - { CODEC_ID_PCM_S16LE , 224 }, + { CODEC_ID_VORBIS , 221 }, /* non standard, gpac uses it */ + { CODEC_ID_DVD_SUBTITLE, 224 }, /* non standard, see unsupported-embedded-subs-2.mp4 */ { CODEC_ID_QCELP , 225 }, - { CODEC_ID_AC3 , 226 }, - { CODEC_ID_PCM_ALAW , 227 }, - { CODEC_ID_PCM_MULAW , 228 }, - { CODEC_ID_PCM_S16BE , 230 }, - { CODEC_ID_H263 , 242 }, - { CODEC_ID_H261 , 243 }, { 0, 0 }, }; @@ -70,6 +65,7 @@ const AVCodecTag codec_movvideo_tags[] = { { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'a') }, /* Motion-JPEG (format A) */ { CODEC_ID_MJPEG, MKTAG('A', 'V', 'D', 'J') }, /* MJPEG with alpha-channel (AVID JFIF meridien compressed) */ /* { CODEC_ID_MJPEG, MKTAG('A', 'V', 'R', 'n') }, *//* MJPEG with alpha-channel (AVID ABVB/Truevision NuVista) */ + { CODEC_ID_MJPEG, MKTAG('d', 'm', 'b', '1') }, /* Motion JPEG OpenDML */ { CODEC_ID_MJPEGB, MKTAG('m', 'j', 'p', 'b') }, /* Motion-JPEG (format B) */ { CODEC_ID_SVQ1, MKTAG('S', 'V', 'Q', '1') }, /* Sorenson Video v1 */ @@ -111,8 +107,11 @@ const AVCodecTag codec_movvideo_tags[] = { { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '3') }, /* HDV produced by FCP */ { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '5', 'n') }, /* MPEG2 IMX NTSC 525/60 50mb/s produced by FCP */ { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '5', 'p') }, /* MPEG2 IMX PAL 625/50 50mb/s produced by FCP */ + { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '4', 'n') }, /* MPEG2 IMX NTSC 525/60 40mb/s produced by FCP */ + { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '4', 'p') }, /* MPEG2 IMX PAL 625/50 40mb/s produced by FCP */ { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '3', 'n') }, /* MPEG2 IMX NTSC 525/60 30mb/s produced by FCP */ { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '3', 'p') }, /* MPEG2 IMX PAL 625/50 30mb/s produced by FCP */ + { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', '2') }, /* XDCAM HD 1080i60 */ { CODEC_ID_MPEG2VIDEO, MKTAG('A', 'V', 'm', 'p') }, /* AVID IMX PAL */ //{ CODEC_ID_JPEG2000, MKTAG('m', 'j', 'p', '2') }, /* JPEG 2000 produced by FCP */ @@ -125,6 +124,7 @@ const AVCodecTag codec_movvideo_tags[] = { { CODEC_ID_VC1, MKTAG('v', 'c', '-', '1') }, /* SMPTE RP 2025 */ { CODEC_ID_DNXHD, MKTAG('A', 'V', 'd', 'n') }, /* AVID DNxHD */ + { CODEC_ID_SGI, MKTAG('s', 'g', 'i', ' ') }, /* SGI */ { CODEC_ID_NONE, 0 }, }; @@ -135,11 +135,11 @@ const AVCodecTag codec_movaudio_tags[] = { { CODEC_ID_PCM_S24BE, MKTAG('i', 'n', '2', '4') }, { CODEC_ID_PCM_S24LE, MKTAG('i', 'n', '2', '4') }, { CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') }, /* 16 bits */ - { CODEC_ID_PCM_S16BE, MKTAG('N', 'O', 'N', 'E') }, /* uncompressed */ { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, /* */ { CODEC_ID_PCM_S16LE, MKTAG('l', 'p', 'c', 'm') }, { CODEC_ID_PCM_S8, MKTAG('s', 'o', 'w', 't') }, { CODEC_ID_PCM_U8, MKTAG('r', 'a', 'w', ' ') }, /* 8 bits unsigned */ + { CODEC_ID_PCM_U8, MKTAG('N', 'O', 'N', 'E') }, /* uncompressed */ { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') }, /* */ { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') }, /* */ @@ -171,6 +171,12 @@ const AVCodecTag codec_movaudio_tags[] = { { CODEC_ID_NONE, 0 }, }; +const AVCodecTag ff_codec_movsubtitle_tags[] = { + { CODEC_ID_MOV_TEXT, MKTAG('t', 'e', 'x', 't') }, + { CODEC_ID_MOV_TEXT, MKTAG('t', 'x', '3', 'g') }, + { CODEC_ID_NONE, 0 }, +}; + /* map numeric codes from mdhd atom to ISO 639 */ /* cf. QTFileFormat.pdf p253, qtff.pdf p205 */ /* http://developer.apple.com/documentation/mac/Text/Text-368.html */ diff --git a/contrib/ffmpeg/libavformat/isom.h b/contrib/ffmpeg/libavformat/isom.h index efcb1fc42..7a66ce524 100644 --- a/contrib/ffmpeg/libavformat/isom.h +++ b/contrib/ffmpeg/libavformat/isom.h @@ -24,17 +24,20 @@ #ifndef FFMPEG_ISOM_H #define FFMPEG_ISOM_H +#include "riff.h" + /* isom.c */ extern const AVCodecTag ff_mp4_obj_type[]; extern const AVCodecTag codec_movvideo_tags[]; extern const AVCodecTag codec_movaudio_tags[]; +extern const AVCodecTag ff_codec_movsubtitle_tags[]; int ff_mov_iso639_to_lang(const char *lang, int mp4); int ff_mov_lang_to_iso639(int code, char *to); -typedef struct Time2Sample{ +typedef struct { int count; int duration; -}Time2Sample; +} MOV_stts_t; #endif /* FFMPEG_ISOM_H */ diff --git a/contrib/ffmpeg/libavformat/libnut.c b/contrib/ffmpeg/libavformat/libnut.c index 0f7b879a9..f5423069f 100644 --- a/contrib/ffmpeg/libavformat/libnut.c +++ b/contrib/ffmpeg/libavformat/libnut.c @@ -54,7 +54,7 @@ static int av_write(void * h, size_t len, const uint8_t * buf) { static int nut_write_header(AVFormatContext * avf) { NUTContext * priv = avf->priv_data; - ByteIOContext * bc = &avf->pb; + ByteIOContext * bc = avf->pb; nut_muxer_opts_t mopts = { .output = { .priv = bc, @@ -137,7 +137,7 @@ static int nut_write_packet(AVFormatContext * avf, AVPacket * pkt) { } static int nut_write_trailer(AVFormatContext * avf) { - ByteIOContext * bc = &avf->pb; + ByteIOContext * bc = avf->pb; NUTContext * priv = avf->priv_data; int i; @@ -151,7 +151,7 @@ static int nut_write_trailer(AVFormatContext * avf) { } AVOutputFormat libnut_muxer = { - "nut", + "libnut", "nut format", "video/x-nut", "nut", @@ -166,7 +166,7 @@ AVOutputFormat libnut_muxer = { #endif //CONFIG_MUXERS static int nut_probe(AVProbeData *p) { - if (p->buf_size >= ID_LENGTH && !memcmp(p->buf, ID_STRING, ID_LENGTH)) return AVPROBE_SCORE_MAX; + if (!memcmp(p->buf, ID_STRING, ID_LENGTH)) return AVPROBE_SCORE_MAX; return 0; } @@ -187,7 +187,7 @@ static off_t av_seek(void * h, long long pos, int whence) { static int nut_read_header(AVFormatContext * avf, AVFormatParameters * ap) { NUTContext * priv = avf->priv_data; - ByteIOContext * bc = &avf->pb; + ByteIOContext * bc = avf->pb; nut_demuxer_opts_t dopts = { .input = { .priv = bc, @@ -272,7 +272,7 @@ static int nut_read_packet(AVFormatContext * avf, AVPacket * pkt) { if (pd.flags & NUT_FLAG_KEY) pkt->flags |= PKT_FLAG_KEY; pkt->pts = pd.pts; pkt->stream_index = pd.stream; - pkt->pos = url_ftell(&avf->pb); + pkt->pos = url_ftell(avf->pb); ret = nut_read_frame(priv->nut, &pd.len, pkt->data); @@ -298,7 +298,7 @@ static int nut_read_close(AVFormatContext *s) { } AVInputFormat libnut_demuxer = { - "nut", + "libnut", "nut format", sizeof(NUTContext), nut_probe, diff --git a/contrib/ffmpeg/libavformat/lmlm4.c b/contrib/ffmpeg/libavformat/lmlm4.c new file mode 100644 index 000000000..6646a412b --- /dev/null +++ b/contrib/ffmpeg/libavformat/lmlm4.c @@ -0,0 +1,126 @@ +/* + * Linux Media Labs MPEG-4 demuxer + * Copyright (c) 2008 Ivo van Poorten + * + * Due to a lack of sample files, only files with one channel are supported. + * u-law and ADPCM audio are unsupported for the same reason. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" + +#define LMLM4_I_FRAME 0x00 +#define LMLM4_P_FRAME 0x01 +#define LMLM4_B_FRAME 0x02 +#define LMLM4_INVALID 0x03 +#define LMLM4_MPEG1L2 0x04 + +#define LMLM4_MAX_PACKET_SIZE 1024 * 1024 + +static int lmlm4_probe(AVProbeData * pd) { + unsigned char *buf = pd->buf; + unsigned int frame_type, packet_size; + + frame_type = AV_RB16(buf+2); + packet_size = AV_RB32(buf+4); + + if (!AV_RB16(buf) && frame_type <= LMLM4_MPEG1L2 && packet_size && + frame_type != LMLM4_INVALID && packet_size <= LMLM4_MAX_PACKET_SIZE) { + + if (frame_type == LMLM4_MPEG1L2) { + if ((AV_RB16(buf+8) & 0xfffe) != 0xfffc) + return 0; + /* I could calculate the audio framesize and compare with + * packet_size-8, but that seems overkill */ + return AVPROBE_SCORE_MAX / 3; + } else if (AV_RB24(buf+8) == 0x000001) { /* PES Signal */ + return AVPROBE_SCORE_MAX / 5; + } + } + + return 0; +} + +static int lmlm4_read_header(AVFormatContext *s, AVFormatParameters *ap) { + AVStream *st; + + if (!(st = av_new_stream(s, 0))) + return AVERROR(ENOMEM); + st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_MPEG4; + st->need_parsing = AVSTREAM_PARSE_HEADERS; + av_set_pts_info(st, 64, 1001, 30000); + + if (!(st = av_new_stream(s, 1))) + return AVERROR(ENOMEM); + st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_MP2; + st->need_parsing = AVSTREAM_PARSE_HEADERS; + + /* the parameters will be extracted from the compressed bitstream */ + return 0; +} + +static int lmlm4_read_packet(AVFormatContext *s, AVPacket *pkt) { + ByteIOContext *pb = s->pb; + int ret; + unsigned int frame_type, packet_size, padding, frame_size; + + get_be16(pb); /* channel number */ + frame_type = get_be16(pb); + packet_size = get_be32(pb); + padding = -packet_size & 511; + frame_size = packet_size - 8; + + if (frame_type > LMLM4_MPEG1L2 || frame_type == LMLM4_INVALID) { + av_log(s, AV_LOG_ERROR, "invalid or unsupported frame_type\n"); + return AVERROR(EIO); + } + if (packet_size > LMLM4_MAX_PACKET_SIZE) { + av_log(s, AV_LOG_ERROR, "packet size exceeds maximum\n"); + return AVERROR(EIO); + } + + if ((ret = av_get_packet(pb, pkt, frame_size)) <= 0) + return AVERROR(EIO); + + url_fskip(pb, padding); + + switch (frame_type) { + case LMLM4_I_FRAME: + pkt->flags = PKT_FLAG_KEY; + case LMLM4_P_FRAME: + case LMLM4_B_FRAME: + pkt->stream_index = 0; + break; + case LMLM4_MPEG1L2: + pkt->stream_index = 1; + break; + } + + return ret; +} + +AVInputFormat lmlm4_demuxer = { + "lmlm4", + "lmlm4 raw format", + 0, + lmlm4_probe, + lmlm4_read_header, + lmlm4_read_packet, +}; diff --git a/contrib/ffmpeg/libavformat/matroska.c b/contrib/ffmpeg/libavformat/matroska.c index 591530490..b62511f29 100644 --- a/contrib/ffmpeg/libavformat/matroska.c +++ b/contrib/ffmpeg/libavformat/matroska.c @@ -1,5 +1,5 @@ /* - * Matroska file demuxer (no muxer yet) + * Matroska common data * Copyright (c) 2003-2004 The ffmpeg Project * * This file is part of FFmpeg. @@ -19,190 +19,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/** - * @file matroska.c - * Matroska file demuxer - * by Ronald Bultje - * with a little help from Moritz Bunkus - * Specs available on the matroska project page: - * http://www.matroska.org/. - */ - -#include "avformat.h" -/* For codec_get_id(). */ -#include "riff.h" -#include "intfloat_readwrite.h" - -/* EBML version supported */ -#define EBML_VERSION 1 - -/* top-level master-IDs */ -#define EBML_ID_HEADER 0x1A45DFA3 - -/* IDs in the HEADER master */ -#define EBML_ID_EBMLVERSION 0x4286 -#define EBML_ID_EBMLREADVERSION 0x42F7 -#define EBML_ID_EBMLMAXIDLENGTH 0x42F2 -#define EBML_ID_EBMLMAXSIZELENGTH 0x42F3 -#define EBML_ID_DOCTYPE 0x4282 -#define EBML_ID_DOCTYPEVERSION 0x4287 -#define EBML_ID_DOCTYPEREADVERSION 0x4285 - -/* general EBML types */ -#define EBML_ID_VOID 0xEC - -/* - * Matroska element IDs. max. 32-bit. - */ - -/* toplevel segment */ -#define MATROSKA_ID_SEGMENT 0x18538067 - -/* matroska top-level master IDs */ -#define MATROSKA_ID_INFO 0x1549A966 -#define MATROSKA_ID_TRACKS 0x1654AE6B -#define MATROSKA_ID_CUES 0x1C53BB6B -#define MATROSKA_ID_TAGS 0x1254C367 -#define MATROSKA_ID_SEEKHEAD 0x114D9B74 -#define MATROSKA_ID_CLUSTER 0x1F43B675 - -/* IDs in the info master */ -#define MATROSKA_ID_TIMECODESCALE 0x2AD7B1 -#define MATROSKA_ID_DURATION 0x4489 -#define MATROSKA_ID_TITLE 0x7BA9 -#define MATROSKA_ID_WRITINGAPP 0x5741 -#define MATROSKA_ID_MUXINGAPP 0x4D80 -#define MATROSKA_ID_DATEUTC 0x4461 - -/* ID in the tracks master */ -#define MATROSKA_ID_TRACKENTRY 0xAE - -/* IDs in the trackentry master */ -#define MATROSKA_ID_TRACKNUMBER 0xD7 -#define MATROSKA_ID_TRACKUID 0x73C5 -#define MATROSKA_ID_TRACKTYPE 0x83 -#define MATROSKA_ID_TRACKAUDIO 0xE1 -#define MATROSKA_ID_TRACKVIDEO 0xE0 -#define MATROSKA_ID_CODECID 0x86 -#define MATROSKA_ID_CODECPRIVATE 0x63A2 -#define MATROSKA_ID_CODECNAME 0x258688 -#define MATROSKA_ID_CODECINFOURL 0x3B4040 -#define MATROSKA_ID_CODECDOWNLOADURL 0x26B240 -#define MATROSKA_ID_TRACKNAME 0x536E -#define MATROSKA_ID_TRACKLANGUAGE 0x22B59C -#define MATROSKA_ID_TRACKFLAGENABLED 0xB9 -#define MATROSKA_ID_TRACKFLAGDEFAULT 0x88 -#define MATROSKA_ID_TRACKFLAGLACING 0x9C -#define MATROSKA_ID_TRACKMINCACHE 0x6DE7 -#define MATROSKA_ID_TRACKMAXCACHE 0x6DF8 -#define MATROSKA_ID_TRACKDEFAULTDURATION 0x23E383 - -/* IDs in the trackvideo master */ -#define MATROSKA_ID_VIDEOFRAMERATE 0x2383E3 -#define MATROSKA_ID_VIDEODISPLAYWIDTH 0x54B0 -#define MATROSKA_ID_VIDEODISPLAYHEIGHT 0x54BA -#define MATROSKA_ID_VIDEOPIXELWIDTH 0xB0 -#define MATROSKA_ID_VIDEOPIXELHEIGHT 0xBA -#define MATROSKA_ID_VIDEOFLAGINTERLACED 0x9A -#define MATROSKA_ID_VIDEOSTEREOMODE 0x53B9 -#define MATROSKA_ID_VIDEOASPECTRATIO 0x54B3 -#define MATROSKA_ID_VIDEOCOLOURSPACE 0x2EB524 - -/* IDs in the trackaudio master */ -#define MATROSKA_ID_AUDIOSAMPLINGFREQ 0xB5 -#define MATROSKA_ID_AUDIOOUTSAMPLINGFREQ 0x78B5 - -#define MATROSKA_ID_AUDIOBITDEPTH 0x6264 -#define MATROSKA_ID_AUDIOCHANNELS 0x9F - -/* ID in the cues master */ -#define MATROSKA_ID_POINTENTRY 0xBB - -/* IDs in the pointentry master */ -#define MATROSKA_ID_CUETIME 0xB3 -#define MATROSKA_ID_CUETRACKPOSITION 0xB7 - -/* IDs in the cuetrackposition master */ -#define MATROSKA_ID_CUETRACK 0xF7 -#define MATROSKA_ID_CUECLUSTERPOSITION 0xF1 - -/* IDs in the tags master */ -/* TODO */ - -/* IDs in the seekhead master */ -#define MATROSKA_ID_SEEKENTRY 0x4DBB - -/* IDs in the seekpoint master */ -#define MATROSKA_ID_SEEKID 0x53AB -#define MATROSKA_ID_SEEKPOSITION 0x53AC - -/* IDs in the cluster master */ -#define MATROSKA_ID_CLUSTERTIMECODE 0xE7 -#define MATROSKA_ID_BLOCKGROUP 0xA0 -#define MATROSKA_ID_SIMPLEBLOCK 0xA3 - -/* IDs in the blockgroup master */ -#define MATROSKA_ID_BLOCK 0xA1 -#define MATROSKA_ID_BLOCKDURATION 0x9B -#define MATROSKA_ID_BLOCKREFERENCE 0xFB - -typedef enum { - MATROSKA_TRACK_TYPE_VIDEO = 0x1, - MATROSKA_TRACK_TYPE_AUDIO = 0x2, - MATROSKA_TRACK_TYPE_COMPLEX = 0x3, - MATROSKA_TRACK_TYPE_LOGO = 0x10, - MATROSKA_TRACK_TYPE_SUBTITLE = 0x11, - MATROSKA_TRACK_TYPE_CONTROL = 0x20, -} MatroskaTrackType; - -typedef enum { - MATROSKA_EYE_MODE_MONO = 0x0, - MATROSKA_EYE_MODE_RIGHT = 0x1, - MATROSKA_EYE_MODE_LEFT = 0x2, - MATROSKA_EYE_MODE_BOTH = 0x3, -} MatroskaEyeMode; - -typedef enum { - MATROSKA_ASPECT_RATIO_MODE_FREE = 0x0, - MATROSKA_ASPECT_RATIO_MODE_KEEP = 0x1, - MATROSKA_ASPECT_RATIO_MODE_FIXED = 0x2, -} MatroskaAspectRatioMode; - -/* - * These aren't in any way "matroska-form" things, - * it's just something I use in the muxer/demuxer. - */ - -typedef enum { - MATROSKA_TRACK_ENABLED = (1<<0), - MATROSKA_TRACK_DEFAULT = (1<<1), - MATROSKA_TRACK_LACING = (1<<2), - MATROSKA_TRACK_REAL_V = (1<<4), - MATROSKA_TRACK_REORDER = (1<<8), - MATROSKA_TRACK_SHIFT = (1<<16) -} MatroskaTrackFlags; - -typedef enum { - MATROSKA_VIDEOTRACK_INTERLACED = (MATROSKA_TRACK_SHIFT<<0) -} MatroskaVideoTrackFlags; - -/* - * Matroska Codec IDs. Strings. - */ - -typedef struct CodecTags{ - const char *str; - enum CodecID id; -}CodecTags; +#include "matroska.h" -#define MATROSKA_CODEC_ID_VIDEO_VFW_FOURCC "V_MS/VFW/FOURCC" -#define MATROSKA_CODEC_ID_AUDIO_ACM "A_MS/ACM" - -static CodecTags codec_tags[]={ +const CodecTags ff_mkv_codec_tags[]={ // {"V_MS/VFW/FOURCC" , CODEC_ID_NONE}, {"V_UNCOMPRESSED" , CODEC_ID_RAWVIDEO}, - {"V_MPEG4/ISO/SP" , CODEC_ID_MPEG4}, {"V_MPEG4/ISO/ASP" , CODEC_ID_MPEG4}, + {"V_MPEG4/ISO/SP" , CODEC_ID_MPEG4}, {"V_MPEG4/ISO/AP" , CODEC_ID_MPEG4}, {"V_MPEG4/ISO/AVC" , CODEC_ID_H264}, {"V_MPEG4/MS/V3" , CODEC_ID_MSMPEG4V3}, @@ -214,12 +37,13 @@ static CodecTags codec_tags[]={ {"V_REAL/RV30" , CODEC_ID_RV30}, {"V_REAL/RV40" , CODEC_ID_RV40}, {"V_THEORA" , CODEC_ID_THEORA}, + {"V_SNOW" , CODEC_ID_SNOW}, /* TODO: Real/Quicktime */ // {"A_MS/ACM" , CODEC_ID_NONE}, - {"A_MPEG/L1" , CODEC_ID_MP3}, - {"A_MPEG/L2" , CODEC_ID_MP3}, {"A_MPEG/L3" , CODEC_ID_MP3}, + {"A_MPEG/L2" , CODEC_ID_MP2}, + {"A_MPEG/L1" , CODEC_ID_MP2}, {"A_PCM/INT/BIG" , CODEC_ID_PCM_U16BE}, {"A_PCM/INT/LIT" , CODEC_ID_PCM_U16LE}, // {"A_PCM/FLOAT/IEEE" , CODEC_ID_NONE}, @@ -230,2621 +54,32 @@ static CodecTags codec_tags[]={ {"A_FLAC" , CODEC_ID_FLAC}, {"A_WAVPACK4" , CODEC_ID_WAVPACK}, {"A_TTA1" , CODEC_ID_TTA}, - {NULL , CODEC_ID_NONE} + {"A_REAL/14_4" , CODEC_ID_RA_144}, + {"A_REAL/28_8" , CODEC_ID_RA_288}, + {"A_REAL/ATRC" , CODEC_ID_ATRAC3}, + {"A_REAL/COOK" , CODEC_ID_COOK}, +// {"A_REAL/SIPR" , CODEC_ID_SIPRO}, + + {"S_TEXT/UTF8" , CODEC_ID_TEXT}, + {"S_TEXT/ASCII" , CODEC_ID_TEXT}, + {"S_TEXT/ASS" , CODEC_ID_SSA}, + {"S_TEXT/SSA" , CODEC_ID_SSA}, + {"S_ASS" , CODEC_ID_SSA}, + {"S_SSA" , CODEC_ID_SSA}, + {"S_VOBSUB" , CODEC_ID_DVD_SUBTITLE}, + + {"" , CODEC_ID_NONE} /* TODO: AC3-9/10 (?), Real, Musepack, Quicktime */ }; -/* max. depth in the EBML tree structure */ -#define EBML_MAX_DEPTH 16 - -typedef struct Track { - MatroskaTrackType type; - - /* Unique track number and track ID. stream_index is the index that - * the calling app uses for this track. */ - uint32_t num, - uid, - stream_index; - - char *name, - *language; - - char *codec_id, - *codec_name; - - unsigned char *codec_priv; - int codec_priv_size; - - uint64_t default_duration; - MatroskaTrackFlags flags; -} MatroskaTrack; - -typedef struct MatroskaVideoTrack { - MatroskaTrack track; - - int pixel_width, - pixel_height, - display_width, - display_height; - - uint32_t fourcc; - - MatroskaAspectRatioMode ar_mode; - MatroskaEyeMode eye_mode; - - //.. -} MatroskaVideoTrack; - -typedef struct MatroskaAudioTrack { - MatroskaTrack track; - - int channels, - bitdepth, - internal_samplerate, - samplerate; - //.. -} MatroskaAudioTrack; - -typedef struct MatroskaSubtitleTrack { - MatroskaTrack track; - - //.. -} MatroskaSubtitleTrack; - -#define MAX_TRACK_SIZE (FFMAX(FFMAX(sizeof(MatroskaVideoTrack), \ - sizeof(MatroskaAudioTrack)), \ - sizeof(MatroskaSubtitleTrack))) - -typedef struct MatroskaLevel { - uint64_t start, length; -} MatroskaLevel; - -typedef struct MatroskaDemuxIndex { - uint64_t pos; /* of the corresponding *cluster*! */ - uint16_t track; /* reference to 'num' */ - uint64_t time; /* in nanoseconds */ -} MatroskaDemuxIndex; - -typedef struct MatroskaDemuxContext { - AVFormatContext *ctx; - - /* ebml stuff */ - int num_levels; - MatroskaLevel levels[EBML_MAX_DEPTH]; - int level_up; - - /* matroska stuff */ - char *writing_app, - *muxing_app; - int64_t created; - - /* timescale in the file */ - int64_t time_scale; - - /* position (time, ns) */ - int64_t pos; - - /* num_streams is the number of streams that av_new_stream() was called - * for ( = that are available to the calling program). */ - int num_tracks, num_streams; - MatroskaTrack *tracks[MAX_STREAMS]; - - /* cache for ID peeking */ - uint32_t peek_id; - - /* byte position of the segment inside the stream */ - offset_t segment_start; - - /* The packet queue. */ - AVPacket **packets; - int num_packets; - /* Second packet queue used to reorder pts of some video track. */ - AVPacket **packets_reorder; - int num_packets_reorder; - uint64_t reorder_max_pts; - - /* have we already parse metadata/cues/clusters? */ - int metadata_parsed, - index_parsed, - done; - - /* The index for seeking. */ - int num_indexes; - MatroskaDemuxIndex *index; -} MatroskaDemuxContext; - -/* - * The first few functions handle EBML file parsing. The rest - * is the document interpretation. Matroska really just is a - * EBML file. - */ - -/* - * Return: the amount of levels in the hierarchy that the - * current element lies higher than the previous one. - * The opposite isn't done - that's auto-done using master - * element reading. - */ - -static int -ebml_read_element_level_up (MatroskaDemuxContext *matroska) -{ - ByteIOContext *pb = &matroska->ctx->pb; - offset_t pos = url_ftell(pb); - int num = 0; - - while (matroska->num_levels > 0) { - MatroskaLevel *level = &matroska->levels[matroska->num_levels - 1]; - - if (pos >= level->start + level->length) { - matroska->num_levels--; - num++; - } else { - break; - } - } - - return num; -} - -/* - * Read: an "EBML number", which is defined as a variable-length - * array of bytes. The first byte indicates the length by giving a - * number of 0-bits followed by a one. The position of the first - * "one" bit inside the first byte indicates the length of this - * number. - * Returns: num. of bytes read. < 0 on error. - */ - -static int -ebml_read_num (MatroskaDemuxContext *matroska, - int max_size, - uint64_t *number) -{ - ByteIOContext *pb = &matroska->ctx->pb; - int len_mask = 0x80, read = 1, n = 1; - int64_t total = 0; - - /* the first byte tells us the length in bytes - get_byte() can normally - * return 0, but since that's not a valid first ebmlID byte, we can - * use it safely here to catch EOS. */ - if (!(total = get_byte(pb))) { - /* we might encounter EOS here */ - if (!url_feof(pb)) { - offset_t pos = url_ftell(pb); - av_log(matroska->ctx, AV_LOG_ERROR, - "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", - pos, pos); - } - return AVERROR_IO; /* EOS or actual I/O error */ - } - - /* get the length of the EBML number */ - while (read <= max_size && !(total & len_mask)) { - read++; - len_mask >>= 1; - } - if (read > max_size) { - offset_t pos = url_ftell(pb) - 1; - av_log(matroska->ctx, AV_LOG_ERROR, - "Invalid EBML number size tag 0x%02x at pos %"PRIu64" (0x%"PRIx64")\n", - (uint8_t) total, pos, pos); - return AVERROR_INVALIDDATA; - } - - /* read out length */ - total &= ~len_mask; - while (n++ < read) - total = (total << 8) | get_byte(pb); - - *number = total; - - return read; -} - -/* - * Read: the element content data ID. - * Return: the number of bytes read or < 0 on error. - */ - -static int -ebml_read_element_id (MatroskaDemuxContext *matroska, - uint32_t *id, - int *level_up) -{ - int read; - uint64_t total; - - /* if we re-call this, use our cached ID */ - if (matroska->peek_id != 0) { - if (level_up) - *level_up = 0; - *id = matroska->peek_id; - return 0; - } - - /* read out the "EBML number", include tag in ID */ - if ((read = ebml_read_num(matroska, 4, &total)) < 0) - return read; - *id = matroska->peek_id = total | (1 << (read * 7)); - - /* level tracking */ - if (level_up) - *level_up = ebml_read_element_level_up(matroska); - - return read; -} - -/* - * Read: element content length. - * Return: the number of bytes read or < 0 on error. - */ - -static int -ebml_read_element_length (MatroskaDemuxContext *matroska, - uint64_t *length) -{ - /* clear cache since we're now beyond that data point */ - matroska->peek_id = 0; - - /* read out the "EBML number", include tag in ID */ - return ebml_read_num(matroska, 8, length); -} - -/* - * Return: the ID of the next element, or 0 on error. - * Level_up contains the amount of levels that this - * next element lies higher than the previous one. - */ - -static uint32_t -ebml_peek_id (MatroskaDemuxContext *matroska, - int *level_up) -{ - uint32_t id; - - assert(level_up != NULL); - - if (ebml_read_element_id(matroska, &id, level_up) < 0) - return 0; - - return id; -} - -/* - * Seek to a given offset. - * 0 is success, -1 is failure. - */ - -static int -ebml_read_seek (MatroskaDemuxContext *matroska, - offset_t offset) -{ - ByteIOContext *pb = &matroska->ctx->pb; - - /* clear ID cache, if any */ - matroska->peek_id = 0; - - return (url_fseek(pb, offset, SEEK_SET) == offset) ? 0 : -1; -} - -/* - * Skip the next element. - * 0 is success, -1 is failure. - */ - -static int -ebml_read_skip (MatroskaDemuxContext *matroska) -{ - ByteIOContext *pb = &matroska->ctx->pb; - uint32_t id; - uint64_t length; - int res; - - if ((res = ebml_read_element_id(matroska, &id, NULL)) < 0 || - (res = ebml_read_element_length(matroska, &length)) < 0) - return res; - - url_fskip(pb, length); - - return 0; -} - -/* - * Read the next element as an unsigned int. - * 0 is success, < 0 is failure. - */ - -static int -ebml_read_uint (MatroskaDemuxContext *matroska, - uint32_t *id, - uint64_t *num) -{ - ByteIOContext *pb = &matroska->ctx->pb; - int n = 0, size, res; - uint64_t rlength; - - if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || - (res = ebml_read_element_length(matroska, &rlength)) < 0) - return res; - size = rlength; - if (size < 1 || size > 8) { - offset_t pos = url_ftell(pb); - av_log(matroska->ctx, AV_LOG_ERROR, - "Invalid uint element size %d at position %"PRId64" (0x%"PRIx64")\n", - size, pos, pos); - return AVERROR_INVALIDDATA; - } - - /* big-endian ordening; build up number */ - *num = 0; - while (n++ < size) - *num = (*num << 8) | get_byte(pb); - - return 0; -} - -/* - * Read the next element as a signed int. - * 0 is success, < 0 is failure. - */ - -static int -ebml_read_sint (MatroskaDemuxContext *matroska, - uint32_t *id, - int64_t *num) -{ - ByteIOContext *pb = &matroska->ctx->pb; - int size, n = 1, negative = 0, res; - uint64_t rlength; - - if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || - (res = ebml_read_element_length(matroska, &rlength)) < 0) - return res; - size = rlength; - if (size < 1 || size > 8) { - offset_t pos = url_ftell(pb); - av_log(matroska->ctx, AV_LOG_ERROR, - "Invalid sint element size %d at position %"PRId64" (0x%"PRIx64")\n", - size, pos, pos); - return AVERROR_INVALIDDATA; - } - if ((*num = get_byte(pb)) & 0x80) { - negative = 1; - *num &= ~0x80; - } - while (n++ < size) - *num = (*num << 8) | get_byte(pb); - - /* make signed */ - if (negative) - *num = *num - (1LL << ((8 * size) - 1)); - - return 0; -} - -/* - * Read the next element as a float. - * 0 is success, < 0 is failure. - */ - -static int -ebml_read_float (MatroskaDemuxContext *matroska, - uint32_t *id, - double *num) -{ - ByteIOContext *pb = &matroska->ctx->pb; - int size, res; - uint64_t rlength; - - if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || - (res = ebml_read_element_length(matroska, &rlength)) < 0) - return res; - size = rlength; - - if (size == 4) { - *num= av_int2flt(get_be32(pb)); - } else if(size==8){ - *num= av_int2dbl(get_be64(pb)); - } else{ - offset_t pos = url_ftell(pb); - av_log(matroska->ctx, AV_LOG_ERROR, - "Invalid float element size %d at position %"PRIu64" (0x%"PRIx64")\n", - size, pos, pos); - return AVERROR_INVALIDDATA; - } - - return 0; -} - -/* - * Read the next element as an ASCII string. - * 0 is success, < 0 is failure. - */ - -static int -ebml_read_ascii (MatroskaDemuxContext *matroska, - uint32_t *id, - char **str) -{ - ByteIOContext *pb = &matroska->ctx->pb; - int size, res; - uint64_t rlength; - - if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || - (res = ebml_read_element_length(matroska, &rlength)) < 0) - return res; - size = rlength; - - /* ebml strings are usually not 0-terminated, so we allocate one - * byte more, read the string and NULL-terminate it ourselves. */ - if (size < 0 || !(*str = av_malloc(size + 1))) { - av_log(matroska->ctx, AV_LOG_ERROR, "Memory allocation failed\n"); - return AVERROR_NOMEM; - } - if (get_buffer(pb, (uint8_t *) *str, size) != size) { - offset_t pos = url_ftell(pb); - av_log(matroska->ctx, AV_LOG_ERROR, - "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos); - return AVERROR_IO; - } - (*str)[size] = '\0'; - - return 0; -} - -/* - * Read the next element as a UTF-8 string. - * 0 is success, < 0 is failure. - */ - -static int -ebml_read_utf8 (MatroskaDemuxContext *matroska, - uint32_t *id, - char **str) -{ - return ebml_read_ascii(matroska, id, str); -} - -/* - * Read the next element as a date (nanoseconds since 1/1/2000). - * 0 is success, < 0 is failure. - */ - -static int -ebml_read_date (MatroskaDemuxContext *matroska, - uint32_t *id, - int64_t *date) -{ - return ebml_read_sint(matroska, id, date); -} - -/* - * Read the next element, but only the header. The contents - * are supposed to be sub-elements which can be read separately. - * 0 is success, < 0 is failure. - */ - -static int -ebml_read_master (MatroskaDemuxContext *matroska, - uint32_t *id) -{ - ByteIOContext *pb = &matroska->ctx->pb; - uint64_t length; - MatroskaLevel *level; - int res; - - if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || - (res = ebml_read_element_length(matroska, &length)) < 0) - return res; - - /* protect... (Heaven forbids that the '>' is true) */ - if (matroska->num_levels >= EBML_MAX_DEPTH) { - av_log(matroska->ctx, AV_LOG_ERROR, - "File moves beyond max. allowed depth (%d)\n", EBML_MAX_DEPTH); - return AVERROR_NOTSUPP; - } - - /* remember level */ - level = &matroska->levels[matroska->num_levels++]; - level->start = url_ftell(pb); - level->length = length; - - return 0; -} - -/* - * Read the next element as binary data. - * 0 is success, < 0 is failure. - */ - -static int -ebml_read_binary (MatroskaDemuxContext *matroska, - uint32_t *id, - uint8_t **binary, - int *size) -{ - ByteIOContext *pb = &matroska->ctx->pb; - uint64_t rlength; - int res; - - if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || - (res = ebml_read_element_length(matroska, &rlength)) < 0) - return res; - *size = rlength; - - if (!(*binary = av_malloc(*size))) { - av_log(matroska->ctx, AV_LOG_ERROR, - "Memory allocation error\n"); - return AVERROR_NOMEM; - } - - if (get_buffer(pb, *binary, *size) != *size) { - offset_t pos = url_ftell(pb); - av_log(matroska->ctx, AV_LOG_ERROR, - "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos); - return AVERROR_IO; - } - - return 0; -} - -/* - * Read signed/unsigned "EBML" numbers. - * Return: number of bytes processed, < 0 on error. - * XXX: use ebml_read_num(). - */ - -static int -matroska_ebmlnum_uint (uint8_t *data, - uint32_t size, - uint64_t *num) -{ - int len_mask = 0x80, read = 1, n = 1, num_ffs = 0; - uint64_t total; - - if (size <= 0) - return AVERROR_INVALIDDATA; - - total = data[0]; - while (read <= 8 && !(total & len_mask)) { - read++; - len_mask >>= 1; - } - if (read > 8) - return AVERROR_INVALIDDATA; - - if ((total &= (len_mask - 1)) == len_mask - 1) - num_ffs++; - if (size < read) - return AVERROR_INVALIDDATA; - while (n < read) { - if (data[n] == 0xff) - num_ffs++; - total = (total << 8) | data[n]; - n++; - } - - if (read == num_ffs) - *num = (uint64_t)-1; - else - *num = total; - - return read; -} - -/* - * Same as above, but signed. - */ - -static int -matroska_ebmlnum_sint (uint8_t *data, - uint32_t size, - int64_t *num) -{ - uint64_t unum; - int res; - - /* read as unsigned number first */ - if ((res = matroska_ebmlnum_uint(data, size, &unum)) < 0) - return res; - - /* make signed (weird way) */ - if (unum == (uint64_t)-1) - *num = INT64_MAX; - else - *num = unum - ((1LL << ((7 * res) - 1)) - 1); - - return res; -} - -/* - * Read an EBML header. - * 0 is success, < 0 is failure. - */ - -static int -ebml_read_header (MatroskaDemuxContext *matroska, - char **doctype, - int *version) -{ - uint32_t id; - int level_up, res = 0; - - /* default init */ - if (doctype) - *doctype = NULL; - if (version) - *version = 1; - - if (!(id = ebml_peek_id(matroska, &level_up)) || - level_up != 0 || id != EBML_ID_HEADER) { - av_log(matroska->ctx, AV_LOG_ERROR, - "This is not an EBML file (id=0x%x/0x%x)\n", id, EBML_ID_HEADER); - return AVERROR_INVALIDDATA; - } - if ((res = ebml_read_master(matroska, &id)) < 0) - return res; - - while (res == 0) { - if (!(id = ebml_peek_id(matroska, &level_up))) - return AVERROR_IO; - - /* end-of-header */ - if (level_up) - break; - - switch (id) { - /* is our read version uptodate? */ - case EBML_ID_EBMLREADVERSION: { - uint64_t num; - - if ((res = ebml_read_uint(matroska, &id, &num)) < 0) - return res; - if (num > EBML_VERSION) { - av_log(matroska->ctx, AV_LOG_ERROR, - "EBML version %"PRIu64" (> %d) is not supported\n", - num, EBML_VERSION); - return AVERROR_INVALIDDATA; - } - break; - } - - /* we only handle 8 byte lengths at max */ - case EBML_ID_EBMLMAXSIZELENGTH: { - uint64_t num; - - if ((res = ebml_read_uint(matroska, &id, &num)) < 0) - return res; - if (num > sizeof(uint64_t)) { - av_log(matroska->ctx, AV_LOG_ERROR, - "Integers of size %"PRIu64" (> %zd) not supported\n", - num, sizeof(uint64_t)); - return AVERROR_INVALIDDATA; - } - break; - } - - /* we handle 4 byte IDs at max */ - case EBML_ID_EBMLMAXIDLENGTH: { - uint64_t num; - - if ((res = ebml_read_uint(matroska, &id, &num)) < 0) - return res; - if (num > sizeof(uint32_t)) { - av_log(matroska->ctx, AV_LOG_ERROR, - "IDs of size %"PRIu64" (> %zu) not supported\n", - num, sizeof(uint32_t)); - return AVERROR_INVALIDDATA; - } - break; - } - - case EBML_ID_DOCTYPE: { - char *text; - - if ((res = ebml_read_ascii(matroska, &id, &text)) < 0) - return res; - if (doctype) { - if (*doctype) - av_free(*doctype); - *doctype = text; - } else - av_free(text); - break; - } - - case EBML_ID_DOCTYPEREADVERSION: { - uint64_t num; - - if ((res = ebml_read_uint(matroska, &id, &num)) < 0) - return res; - if (version) - *version = num; - break; - } - - default: - av_log(matroska->ctx, AV_LOG_INFO, - "Unknown data type 0x%x in EBML header", id); - /* pass-through */ - - case EBML_ID_VOID: - /* we ignore these two, as they don't tell us anything we - * care about */ - case EBML_ID_EBMLVERSION: - case EBML_ID_DOCTYPEVERSION: - res = ebml_read_skip (matroska); - break; - } - } - - return 0; -} - -/* - * Put one packet in an application-supplied AVPacket struct. - * Returns 0 on success or -1 on failure. - */ - -static int -matroska_deliver_packet (MatroskaDemuxContext *matroska, - AVPacket *pkt) -{ - if (matroska->num_packets > 0) { - memcpy(pkt, matroska->packets[0], sizeof(AVPacket)); - av_free(matroska->packets[0]); - if (matroska->num_packets > 1) { - memmove(&matroska->packets[0], &matroska->packets[1], - (matroska->num_packets - 1) * sizeof(AVPacket *)); - matroska->packets = - av_realloc(matroska->packets, (matroska->num_packets - 1) * - sizeof(AVPacket *)); - } else { - av_freep(&matroska->packets); - } - matroska->num_packets--; - return 0; - } - - return -1; -} - -/* - * Put a packet into our internal queue. Will be delivered to the - * user/application during the next get_packet() call. - */ - -static void -matroska_queue_packet (MatroskaDemuxContext *matroska, - AVPacket *pkt) -{ - matroska->packets = - av_realloc(matroska->packets, (matroska->num_packets + 1) * - sizeof(AVPacket *)); - matroska->packets[matroska->num_packets] = pkt; - matroska->num_packets++; -} - -/* - * Put a packet into our internal reordering queue. Will be moved to the - * main packet queue when enough packets are available to reorder pts. - */ - -static void -matroska_queue_packet_reordered (MatroskaDemuxContext *matroska, - AVPacket *pkt, - int is_bframe) -{ - if (matroska->num_packets_reorder && !is_bframe - && pkt->pts > matroska->reorder_max_pts) { - /* reorder pts */ - int i, j, k = 1; - for (j=matroska->num_packets_reorder-1; j && k; j--) { - k = 0; - for (i=0; ipackets_reorder[i]->pts > matroska->packets_reorder[i+1]->pts) { - FFSWAP(uint64_t, matroska->packets_reorder[i]->pts, matroska->packets_reorder[i+1]->pts); - k = 1; - } - } - } - /* then really queue the packets */ - for (i=0; inum_packets_reorder; i++) - matroska_queue_packet (matroska, matroska->packets_reorder[i]); - matroska->num_packets_reorder = 0; - } - matroska->packets_reorder = - av_realloc(matroska->packets_reorder, - (matroska->num_packets_reorder + 1) * sizeof(AVPacket *)); - matroska->packets_reorder[matroska->num_packets_reorder++] = pkt; - if (pkt->pts > matroska->reorder_max_pts) - matroska->reorder_max_pts = pkt->pts; -} - - -/* - * Autodetecting... - */ - -static int -matroska_probe (AVProbeData *p) -{ - uint64_t total = 0; - int len_mask = 0x80, size = 1, n = 1; - uint8_t probe_data[] = { 'm', 'a', 't', 'r', 'o', 's', 'k', 'a' }; - - if (p->buf_size < 5) - return 0; - - /* ebml header? */ - if ((p->buf[0] << 24 | p->buf[1] << 16 | - p->buf[2] << 8 | p->buf[3]) != EBML_ID_HEADER) - return 0; - - /* length of header */ - total = p->buf[4]; - while (size <= 8 && !(total & len_mask)) { - size++; - len_mask >>= 1; - } - if (size > 8) - return 0; - total &= (len_mask - 1); - while (n < size) - total = (total << 8) | p->buf[4 + n++]; - - /* does the probe data contain the whole header? */ - if (p->buf_size < 4 + size + total) - return 0; - - /* the header must contain the document type 'matroska'. For now, - * we don't parse the whole header but simply check for the - * availability of that array of characters inside the header. - * Not fully fool-proof, but good enough. */ - for (n = 4 + size; n <= 4 + size + total - sizeof(probe_data); n++) - if (!memcmp (&p->buf[n], probe_data, sizeof(probe_data))) - return AVPROBE_SCORE_MAX; - - return 0; -} - -/* - * From here on, it's all XML-style DTD stuff... Needs no comments. - */ - -static int -matroska_parse_info (MatroskaDemuxContext *matroska) -{ - int res = 0; - uint32_t id; - - av_log(matroska->ctx, AV_LOG_DEBUG, "Parsing info...\n"); - - while (res == 0) { - if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { - res = AVERROR_IO; - break; - } else if (matroska->level_up) { - matroska->level_up--; - break; - } - - switch (id) { - /* cluster timecode */ - case MATROSKA_ID_TIMECODESCALE: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, &num)) < 0) - break; - matroska->time_scale = num; - break; - } - - case MATROSKA_ID_DURATION: { - double num; - if ((res = ebml_read_float(matroska, &id, &num)) < 0) - break; - matroska->ctx->duration = num * matroska->time_scale * 1000 / AV_TIME_BASE; - break; - } - - case MATROSKA_ID_TITLE: { - char *text; - if ((res = ebml_read_utf8(matroska, &id, &text)) < 0) - break; - strncpy(matroska->ctx->title, text, - sizeof(matroska->ctx->title)-1); - av_free(text); - break; - } - - case MATROSKA_ID_WRITINGAPP: { - char *text; - if ((res = ebml_read_utf8(matroska, &id, &text)) < 0) - break; - matroska->writing_app = text; - break; - } - - case MATROSKA_ID_MUXINGAPP: { - char *text; - if ((res = ebml_read_utf8(matroska, &id, &text)) < 0) - break; - matroska->muxing_app = text; - break; - } - - case MATROSKA_ID_DATEUTC: { - int64_t time; - if ((res = ebml_read_date(matroska, &id, &time)) < 0) - break; - matroska->created = time; - break; - } - - default: - av_log(matroska->ctx, AV_LOG_INFO, - "Unknown entry 0x%x in info header\n", id); - /* fall-through */ - - case EBML_ID_VOID: - res = ebml_read_skip(matroska); - break; - } - - if (matroska->level_up) { - matroska->level_up--; - break; - } - } - - return res; -} - -static int -matroska_add_stream (MatroskaDemuxContext *matroska) -{ - int res = 0; - uint32_t id; - MatroskaTrack *track; - - av_log(matroska->ctx, AV_LOG_DEBUG, "parsing track, adding stream..,\n"); - - /* Allocate a generic track. As soon as we know its type we'll realloc. */ - track = av_mallocz(MAX_TRACK_SIZE); - matroska->num_tracks++; - - /* start with the master */ - if ((res = ebml_read_master(matroska, &id)) < 0) - return res; - - /* try reading the trackentry headers */ - while (res == 0) { - if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { - res = AVERROR_IO; - break; - } else if (matroska->level_up > 0) { - matroska->level_up--; - break; - } - - switch (id) { - /* track number (unique stream ID) */ - case MATROSKA_ID_TRACKNUMBER: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, &num)) < 0) - break; - track->num = num; - break; - } - - /* track UID (unique identifier) */ - case MATROSKA_ID_TRACKUID: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, &num)) < 0) - break; - track->uid = num; - break; - } - - /* track type (video, audio, combined, subtitle, etc.) */ - case MATROSKA_ID_TRACKTYPE: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, &num)) < 0) - break; - if (track->type && track->type != num) { - av_log(matroska->ctx, AV_LOG_INFO, - "More than one tracktype in an entry - skip\n"); - break; - } - track->type = num; - - switch (track->type) { - case MATROSKA_TRACK_TYPE_VIDEO: - case MATROSKA_TRACK_TYPE_AUDIO: - case MATROSKA_TRACK_TYPE_SUBTITLE: - break; - case MATROSKA_TRACK_TYPE_COMPLEX: - case MATROSKA_TRACK_TYPE_LOGO: - case MATROSKA_TRACK_TYPE_CONTROL: - default: - av_log(matroska->ctx, AV_LOG_INFO, - "Unknown or unsupported track type 0x%x\n", - track->type); - track->type = 0; - break; - } - matroska->tracks[matroska->num_tracks - 1] = track; - break; - } - - /* tracktype specific stuff for video */ - case MATROSKA_ID_TRACKVIDEO: { - MatroskaVideoTrack *videotrack; - if (!track->type) - track->type = MATROSKA_TRACK_TYPE_VIDEO; - if (track->type != MATROSKA_TRACK_TYPE_VIDEO) { - av_log(matroska->ctx, AV_LOG_INFO, - "video data in non-video track - ignoring\n"); - res = AVERROR_INVALIDDATA; - break; - } else if ((res = ebml_read_master(matroska, &id)) < 0) - break; - videotrack = (MatroskaVideoTrack *)track; - - while (res == 0) { - if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { - res = AVERROR_IO; - break; - } else if (matroska->level_up > 0) { - matroska->level_up--; - break; - } - - switch (id) { - /* fixme, this should be one-up, but I get it here */ - case MATROSKA_ID_TRACKDEFAULTDURATION: { - uint64_t num; - if ((res = ebml_read_uint (matroska, &id, - &num)) < 0) - break; - track->default_duration = num/matroska->time_scale; - break; - } - - /* video framerate */ - case MATROSKA_ID_VIDEOFRAMERATE: { - double num; - if ((res = ebml_read_float(matroska, &id, - &num)) < 0) - break; - track->default_duration = 1000000000/(matroska->time_scale*num); - break; - } - - /* width of the size to display the video at */ - case MATROSKA_ID_VIDEODISPLAYWIDTH: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, - &num)) < 0) - break; - videotrack->display_width = num; - break; - } - - /* height of the size to display the video at */ - case MATROSKA_ID_VIDEODISPLAYHEIGHT: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, - &num)) < 0) - break; - videotrack->display_height = num; - break; - } - - /* width of the video in the file */ - case MATROSKA_ID_VIDEOPIXELWIDTH: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, - &num)) < 0) - break; - videotrack->pixel_width = num; - break; - } - - /* height of the video in the file */ - case MATROSKA_ID_VIDEOPIXELHEIGHT: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, - &num)) < 0) - break; - videotrack->pixel_height = num; - break; - } - - /* whether the video is interlaced */ - case MATROSKA_ID_VIDEOFLAGINTERLACED: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, - &num)) < 0) - break; - if (num) - track->flags |= - MATROSKA_VIDEOTRACK_INTERLACED; - else - track->flags &= - ~MATROSKA_VIDEOTRACK_INTERLACED; - break; - } - - /* stereo mode (whether the video has two streams, - * where one is for the left eye and the other for - * the right eye, which creates a 3D-like - * effect) */ - case MATROSKA_ID_VIDEOSTEREOMODE: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, - &num)) < 0) - break; - if (num != MATROSKA_EYE_MODE_MONO && - num != MATROSKA_EYE_MODE_LEFT && - num != MATROSKA_EYE_MODE_RIGHT && - num != MATROSKA_EYE_MODE_BOTH) { - av_log(matroska->ctx, AV_LOG_INFO, - "Ignoring unknown eye mode 0x%x\n", - (uint32_t) num); - break; - } - videotrack->eye_mode = num; - break; - } - - /* aspect ratio behaviour */ - case MATROSKA_ID_VIDEOASPECTRATIO: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, - &num)) < 0) - break; - if (num != MATROSKA_ASPECT_RATIO_MODE_FREE && - num != MATROSKA_ASPECT_RATIO_MODE_KEEP && - num != MATROSKA_ASPECT_RATIO_MODE_FIXED) { - av_log(matroska->ctx, AV_LOG_INFO, - "Ignoring unknown aspect ratio 0x%x\n", - (uint32_t) num); - break; - } - videotrack->ar_mode = num; - break; - } - - /* colourspace (only matters for raw video) - * fourcc */ - case MATROSKA_ID_VIDEOCOLOURSPACE: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, - &num)) < 0) - break; - videotrack->fourcc = num; - break; - } - - default: - av_log(matroska->ctx, AV_LOG_INFO, - "Unknown video track header entry " - "0x%x - ignoring\n", id); - /* pass-through */ - - case EBML_ID_VOID: - res = ebml_read_skip(matroska); - break; - } - - if (matroska->level_up) { - matroska->level_up--; - break; - } - } - break; - } - - /* tracktype specific stuff for audio */ - case MATROSKA_ID_TRACKAUDIO: { - MatroskaAudioTrack *audiotrack; - if (!track->type) - track->type = MATROSKA_TRACK_TYPE_AUDIO; - if (track->type != MATROSKA_TRACK_TYPE_AUDIO) { - av_log(matroska->ctx, AV_LOG_INFO, - "audio data in non-audio track - ignoring\n"); - res = AVERROR_INVALIDDATA; - break; - } else if ((res = ebml_read_master(matroska, &id)) < 0) - break; - audiotrack = (MatroskaAudioTrack *)track; - audiotrack->channels = 1; - audiotrack->samplerate = 8000; - - while (res == 0) { - if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { - res = AVERROR_IO; - break; - } else if (matroska->level_up > 0) { - matroska->level_up--; - break; - } - - switch (id) { - /* samplerate */ - case MATROSKA_ID_AUDIOSAMPLINGFREQ: { - double num; - if ((res = ebml_read_float(matroska, &id, - &num)) < 0) - break; - audiotrack->internal_samplerate = - audiotrack->samplerate = num; - break; - } - - case MATROSKA_ID_AUDIOOUTSAMPLINGFREQ: { - double num; - if ((res = ebml_read_float(matroska, &id, - &num)) < 0) - break; - audiotrack->samplerate = num; - break; - } - - /* bitdepth */ - case MATROSKA_ID_AUDIOBITDEPTH: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, - &num)) < 0) - break; - audiotrack->bitdepth = num; - break; - } - - /* channels */ - case MATROSKA_ID_AUDIOCHANNELS: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, - &num)) < 0) - break; - audiotrack->channels = num; - break; - } - - default: - av_log(matroska->ctx, AV_LOG_INFO, - "Unknown audio track header entry " - "0x%x - ignoring\n", id); - /* pass-through */ - - case EBML_ID_VOID: - res = ebml_read_skip(matroska); - break; - } - - if (matroska->level_up) { - matroska->level_up--; - break; - } - } - break; - } - - /* codec identifier */ - case MATROSKA_ID_CODECID: { - char *text; - if ((res = ebml_read_ascii(matroska, &id, &text)) < 0) - break; - track->codec_id = text; - break; - } - - /* codec private data */ - case MATROSKA_ID_CODECPRIVATE: { - uint8_t *data; - int size; - if ((res = ebml_read_binary(matroska, &id, &data, &size) < 0)) - break; - track->codec_priv = data; - track->codec_priv_size = size; - break; - } - - /* name of the codec */ - case MATROSKA_ID_CODECNAME: { - char *text; - if ((res = ebml_read_utf8(matroska, &id, &text)) < 0) - break; - track->codec_name = text; - break; - } - - /* name of this track */ - case MATROSKA_ID_TRACKNAME: { - char *text; - if ((res = ebml_read_utf8(matroska, &id, &text)) < 0) - break; - track->name = text; - break; - } - - /* language (matters for audio/subtitles, mostly) */ - case MATROSKA_ID_TRACKLANGUAGE: { - char *text; - if ((res = ebml_read_utf8(matroska, &id, &text)) < 0) - break; - track->language = text; - break; - } - - /* whether this is actually used */ - case MATROSKA_ID_TRACKFLAGENABLED: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, &num)) < 0) - break; - if (num) - track->flags |= MATROSKA_TRACK_ENABLED; - else - track->flags &= ~MATROSKA_TRACK_ENABLED; - break; - } - - /* whether it's the default for this track type */ - case MATROSKA_ID_TRACKFLAGDEFAULT: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, &num)) < 0) - break; - if (num) - track->flags |= MATROSKA_TRACK_DEFAULT; - else - track->flags &= ~MATROSKA_TRACK_DEFAULT; - break; - } - - /* lacing (like MPEG, where blocks don't end/start on frame - * boundaries) */ - case MATROSKA_ID_TRACKFLAGLACING: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, &num)) < 0) - break; - if (num) - track->flags |= MATROSKA_TRACK_LACING; - else - track->flags &= ~MATROSKA_TRACK_LACING; - break; - } - - /* default length (in time) of one data block in this track */ - case MATROSKA_ID_TRACKDEFAULTDURATION: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, &num)) < 0) - break; - track->default_duration = num / matroska->time_scale; - break; - } - - default: - av_log(matroska->ctx, AV_LOG_INFO, - "Unknown track header entry 0x%x - ignoring\n", id); - /* pass-through */ - - case EBML_ID_VOID: - /* we ignore these because they're nothing useful. */ - case MATROSKA_ID_CODECINFOURL: - case MATROSKA_ID_CODECDOWNLOADURL: - case MATROSKA_ID_TRACKMINCACHE: - case MATROSKA_ID_TRACKMAXCACHE: - res = ebml_read_skip(matroska); - break; - } - - if (matroska->level_up) { - matroska->level_up--; - break; - } - } - - return res; -} - -static int -matroska_parse_tracks (MatroskaDemuxContext *matroska) -{ - int res = 0; - uint32_t id; - - av_log(matroska->ctx, AV_LOG_DEBUG, "parsing tracks...\n"); - - while (res == 0) { - if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { - res = AVERROR_IO; - break; - } else if (matroska->level_up) { - matroska->level_up--; - break; - } - - switch (id) { - /* one track within the "all-tracks" header */ - case MATROSKA_ID_TRACKENTRY: - res = matroska_add_stream(matroska); - break; - - default: - av_log(matroska->ctx, AV_LOG_INFO, - "Unknown entry 0x%x in track header\n", id); - /* fall-through */ - - case EBML_ID_VOID: - res = ebml_read_skip(matroska); - break; - } - - if (matroska->level_up) { - matroska->level_up--; - break; - } - } - - return res; -} - -static int -matroska_parse_index (MatroskaDemuxContext *matroska) -{ - int res = 0; - uint32_t id; - MatroskaDemuxIndex idx; - - av_log(matroska->ctx, AV_LOG_DEBUG, "parsing index...\n"); - - while (res == 0) { - if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { - res = AVERROR_IO; - break; - } else if (matroska->level_up) { - matroska->level_up--; - break; - } - - switch (id) { - /* one single index entry ('point') */ - case MATROSKA_ID_POINTENTRY: - if ((res = ebml_read_master(matroska, &id)) < 0) - break; - - /* in the end, we hope to fill one entry with a - * timestamp, a file position and a tracknum */ - idx.pos = (uint64_t) -1; - idx.time = (uint64_t) -1; - idx.track = (uint16_t) -1; - - while (res == 0) { - if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { - res = AVERROR_IO; - break; - } else if (matroska->level_up) { - matroska->level_up--; - break; - } - - switch (id) { - /* one single index entry ('point') */ - case MATROSKA_ID_CUETIME: { - uint64_t time; - if ((res = ebml_read_uint(matroska, &id, - &time)) < 0) - break; - idx.time = time * matroska->time_scale; - break; - } - - /* position in the file + track to which it - * belongs */ - case MATROSKA_ID_CUETRACKPOSITION: - if ((res = ebml_read_master(matroska, &id)) < 0) - break; - - while (res == 0) { - if (!(id = ebml_peek_id (matroska, - &matroska->level_up))) { - res = AVERROR_IO; - break; - } else if (matroska->level_up) { - matroska->level_up--; - break; - } - - switch (id) { - /* track number */ - case MATROSKA_ID_CUETRACK: { - uint64_t num; - if ((res = ebml_read_uint(matroska, - &id, &num)) < 0) - break; - idx.track = num; - break; - } - - /* position in file */ - case MATROSKA_ID_CUECLUSTERPOSITION: { - uint64_t num; - if ((res = ebml_read_uint(matroska, - &id, &num)) < 0) - break; - idx.pos = num; - break; - } - - default: - av_log(matroska->ctx, AV_LOG_INFO, - "Unknown entry 0x%x in " - "CuesTrackPositions\n", id); - /* fall-through */ - - case EBML_ID_VOID: - res = ebml_read_skip(matroska); - break; - } - - if (matroska->level_up) { - matroska->level_up--; - break; - } - } - - break; - - default: - av_log(matroska->ctx, AV_LOG_INFO, - "Unknown entry 0x%x in cuespoint " - "index\n", id); - /* fall-through */ - - case EBML_ID_VOID: - res = ebml_read_skip(matroska); - break; - } - - if (matroska->level_up) { - matroska->level_up--; - break; - } - } - - /* so let's see if we got what we wanted */ - if (idx.pos != (uint64_t) -1 && - idx.time != (uint64_t) -1 && - idx.track != (uint16_t) -1) { - if (matroska->num_indexes % 32 == 0) { - /* re-allocate bigger index */ - matroska->index = - av_realloc(matroska->index, - (matroska->num_indexes + 32) * - sizeof(MatroskaDemuxIndex)); - } - matroska->index[matroska->num_indexes] = idx; - matroska->num_indexes++; - } - break; - - default: - av_log(matroska->ctx, AV_LOG_INFO, - "Unknown entry 0x%x in cues header\n", id); - /* fall-through */ - - case EBML_ID_VOID: - res = ebml_read_skip(matroska); - break; - } - - if (matroska->level_up) { - matroska->level_up--; - break; - } - } - - return res; -} - -static int -matroska_parse_metadata (MatroskaDemuxContext *matroska) -{ - int res = 0; - uint32_t id; - - while (res == 0) { - if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { - res = AVERROR_IO; - break; - } else if (matroska->level_up) { - matroska->level_up--; - break; - } - - switch (id) { - /* Hm, this is unsupported... */ - default: - av_log(matroska->ctx, AV_LOG_INFO, - "Unknown entry 0x%x in metadata header\n", id); - /* fall-through */ - - case EBML_ID_VOID: - res = ebml_read_skip(matroska); - break; - } - - if (matroska->level_up) { - matroska->level_up--; - break; - } - } - - return res; -} - -static int -matroska_parse_seekhead (MatroskaDemuxContext *matroska) -{ - int res = 0; - uint32_t id; - - av_log(matroska->ctx, AV_LOG_DEBUG, "parsing seekhead...\n"); - - while (res == 0) { - if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { - res = AVERROR_IO; - break; - } else if (matroska->level_up) { - matroska->level_up--; - break; - } - - switch (id) { - case MATROSKA_ID_SEEKENTRY: { - uint32_t seek_id = 0, peek_id_cache = 0; - uint64_t seek_pos = (uint64_t) -1, t; - - if ((res = ebml_read_master(matroska, &id)) < 0) - break; - - while (res == 0) { - if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { - res = AVERROR_IO; - break; - } else if (matroska->level_up) { - matroska->level_up--; - break; - } - - switch (id) { - case MATROSKA_ID_SEEKID: - res = ebml_read_uint(matroska, &id, &t); - seek_id = t; - break; - - case MATROSKA_ID_SEEKPOSITION: - res = ebml_read_uint(matroska, &id, &seek_pos); - break; - - default: - av_log(matroska->ctx, AV_LOG_INFO, - "Unknown seekhead ID 0x%x\n", id); - /* fall-through */ - - case EBML_ID_VOID: - res = ebml_read_skip(matroska); - break; - } - - if (matroska->level_up) { - matroska->level_up--; - break; - } - } - - if (!seek_id || seek_pos == (uint64_t) -1) { - av_log(matroska->ctx, AV_LOG_INFO, - "Incomplete seekhead entry (0x%x/%"PRIu64")\n", - seek_id, seek_pos); - break; - } - - switch (seek_id) { - case MATROSKA_ID_CUES: - case MATROSKA_ID_TAGS: { - uint32_t level_up = matroska->level_up; - offset_t before_pos; - uint64_t length; - MatroskaLevel level; - - /* remember the peeked ID and the current position */ - peek_id_cache = matroska->peek_id; - before_pos = url_ftell(&matroska->ctx->pb); - - /* seek */ - if ((res = ebml_read_seek(matroska, seek_pos + - matroska->segment_start)) < 0) - return res; - - /* we don't want to lose our seekhead level, so we add - * a dummy. This is a crude hack. */ - if (matroska->num_levels == EBML_MAX_DEPTH) { - av_log(matroska->ctx, AV_LOG_INFO, - "Max EBML element depth (%d) reached, " - "cannot parse further.\n", EBML_MAX_DEPTH); - return AVERROR_UNKNOWN; - } - - level.start = 0; - level.length = (uint64_t)-1; - matroska->levels[matroska->num_levels] = level; - matroska->num_levels++; - - /* check ID */ - if (!(id = ebml_peek_id (matroska, - &matroska->level_up))) - goto finish; - if (id != seek_id) { - av_log(matroska->ctx, AV_LOG_INFO, - "We looked for ID=0x%x but got " - "ID=0x%x (pos=%"PRIu64")", - seek_id, id, seek_pos + - matroska->segment_start); - goto finish; - } - - /* read master + parse */ - if ((res = ebml_read_master(matroska, &id)) < 0) - goto finish; - switch (id) { - case MATROSKA_ID_CUES: - if (!(res = matroska_parse_index(matroska)) || - url_feof(&matroska->ctx->pb)) { - matroska->index_parsed = 1; - res = 0; - } - break; - case MATROSKA_ID_TAGS: - if (!(res = matroska_parse_metadata(matroska)) || - url_feof(&matroska->ctx->pb)) { - matroska->metadata_parsed = 1; - res = 0; - } - break; - } - - finish: - /* remove dummy level */ - while (matroska->num_levels) { - matroska->num_levels--; - length = - matroska->levels[matroska->num_levels].length; - if (length == (uint64_t)-1) - break; - } - - /* seek back */ - if ((res = ebml_read_seek(matroska, before_pos)) < 0) - return res; - matroska->peek_id = peek_id_cache; - matroska->level_up = level_up; - break; - } - - default: - av_log(matroska->ctx, AV_LOG_INFO, - "Ignoring seekhead entry for ID=0x%x\n", - seek_id); - break; - } - - break; - } - - default: - av_log(matroska->ctx, AV_LOG_INFO, - "Unknown seekhead ID 0x%x\n", id); - /* fall-through */ - - case EBML_ID_VOID: - res = ebml_read_skip(matroska); - break; - } - - if (matroska->level_up) { - matroska->level_up--; - break; - } - } - - return res; -} - -#define ARRAY_SIZE(x) (sizeof(x)/sizeof(*x)) - -static int -matroska_aac_profile (char *codec_id) -{ - static const char *aac_profiles[] = { - "MAIN", "LC", "SSR" - }; - int profile; - - for (profile=0; profilepriv_data; - char *doctype; - int version, last_level, res = 0; - uint32_t id; - - matroska->ctx = s; - - /* First read the EBML header. */ - doctype = NULL; - if ((res = ebml_read_header(matroska, &doctype, &version)) < 0) - return res; - if ((doctype == NULL) || strcmp(doctype, "matroska")) { - av_log(matroska->ctx, AV_LOG_ERROR, - "Wrong EBML doctype ('%s' != 'matroska').\n", - doctype ? doctype : "(none)"); - if (doctype) - av_free(doctype); - return AVERROR_NOFMT; - } - av_free(doctype); - if (version > 2) { - av_log(matroska->ctx, AV_LOG_ERROR, - "Matroska demuxer version 2 too old for file version %d\n", - version); - return AVERROR_NOFMT; - } - - /* The next thing is a segment. */ - while (1) { - if (!(id = ebml_peek_id(matroska, &last_level))) - return AVERROR_IO; - if (id == MATROSKA_ID_SEGMENT) - break; - - /* oi! */ - av_log(matroska->ctx, AV_LOG_INFO, - "Expected a Segment ID (0x%x), but received 0x%x!\n", - MATROSKA_ID_SEGMENT, id); - if ((res = ebml_read_skip(matroska)) < 0) - return res; - } - - /* We now have a Matroska segment. - * Seeks are from the beginning of the segment, - * after the segment ID/length. */ - if ((res = ebml_read_master(matroska, &id)) < 0) - return res; - matroska->segment_start = url_ftell(&s->pb); - - matroska->time_scale = 1000000; - /* we've found our segment, start reading the different contents in here */ - while (res == 0) { - if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { - res = AVERROR_IO; - break; - } else if (matroska->level_up) { - matroska->level_up--; - break; - } - - switch (id) { - /* stream info */ - case MATROSKA_ID_INFO: { - if ((res = ebml_read_master(matroska, &id)) < 0) - break; - res = matroska_parse_info(matroska); - break; - } - - /* track info headers */ - case MATROSKA_ID_TRACKS: { - if ((res = ebml_read_master(matroska, &id)) < 0) - break; - res = matroska_parse_tracks(matroska); - break; - } - - /* stream index */ - case MATROSKA_ID_CUES: { - if (!matroska->index_parsed) { - if ((res = ebml_read_master(matroska, &id)) < 0) - break; - res = matroska_parse_index(matroska); - } else - res = ebml_read_skip(matroska); - break; - } - - /* metadata */ - case MATROSKA_ID_TAGS: { - if (!matroska->metadata_parsed) { - if ((res = ebml_read_master(matroska, &id)) < 0) - break; - res = matroska_parse_metadata(matroska); - } else - res = ebml_read_skip(matroska); - break; - } - - /* file index (if seekable, seek to Cues/Tags to parse it) */ - case MATROSKA_ID_SEEKHEAD: { - if ((res = ebml_read_master(matroska, &id)) < 0) - break; - res = matroska_parse_seekhead(matroska); - break; - } - - case MATROSKA_ID_CLUSTER: { - /* Do not read the master - this will be done in the next - * call to matroska_read_packet. */ - res = 1; - break; - } - - default: - av_log(matroska->ctx, AV_LOG_INFO, - "Unknown matroska file header ID 0x%x\n", id); - /* fall-through */ - - case EBML_ID_VOID: - res = ebml_read_skip(matroska); - break; - } - - if (matroska->level_up) { - matroska->level_up--; - break; - } - } - - /* Have we found a cluster? */ - if (ebml_peek_id(matroska, NULL) == MATROSKA_ID_CLUSTER) { - int i, j; - MatroskaTrack *track; - AVStream *st; - - for (i = 0; i < matroska->num_tracks; i++) { - enum CodecID codec_id = CODEC_ID_NONE; - uint8_t *extradata = NULL; - int extradata_size = 0; - int extradata_offset = 0; - track = matroska->tracks[i]; - - /* libavformat does not really support subtitles. - * Also apply some sanity checks. */ - if ((track->type == MATROSKA_TRACK_TYPE_SUBTITLE) || - (track->codec_id == NULL)) - continue; - - for(j=0; codec_tags[j].str; j++){ - if(!strncmp(codec_tags[j].str, track->codec_id, - strlen(codec_tags[j].str))){ - codec_id= codec_tags[j].id; - break; - } - } - - /* Set the FourCC from the CodecID. */ - /* This is the MS compatibility mode which stores a - * BITMAPINFOHEADER in the CodecPrivate. */ - if (!strcmp(track->codec_id, - MATROSKA_CODEC_ID_VIDEO_VFW_FOURCC) && - (track->codec_priv_size >= 40) && - (track->codec_priv != NULL)) { - unsigned char *p; - - /* Offset of biCompression. Stored in LE. */ - p = (unsigned char *)track->codec_priv + 16; - ((MatroskaVideoTrack *)track)->fourcc = (p[3] << 24) | - (p[2] << 16) | (p[1] << 8) | p[0]; - codec_id = codec_get_id(codec_bmp_tags, ((MatroskaVideoTrack *)track)->fourcc); - - } - - /* This is the MS compatibility mode which stores a - * WAVEFORMATEX in the CodecPrivate. */ - else if (!strcmp(track->codec_id, - MATROSKA_CODEC_ID_AUDIO_ACM) && - (track->codec_priv_size >= 18) && - (track->codec_priv != NULL)) { - unsigned char *p; - uint16_t tag; - - /* Offset of wFormatTag. Stored in LE. */ - p = (unsigned char *)track->codec_priv; - tag = (p[1] << 8) | p[0]; - codec_id = codec_get_id(codec_wav_tags, tag); - - } - - else if (codec_id == CODEC_ID_AAC && !track->codec_priv_size) { - MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *) track; - int profile = matroska_aac_profile(track->codec_id); - int sri = matroska_aac_sri(audiotrack->internal_samplerate); - extradata = av_malloc(5); - if (extradata == NULL) - return AVERROR_NOMEM; - extradata[0] = (profile << 3) | ((sri&0x0E) >> 1); - extradata[1] = ((sri&0x01) << 7) | (audiotrack->channels<<3); - if (strstr(track->codec_id, "SBR")) { - sri = matroska_aac_sri(audiotrack->samplerate); - extradata[2] = 0x56; - extradata[3] = 0xE5; - extradata[4] = 0x80 | (sri<<3); - extradata_size = 5; - } else { - extradata_size = 2; - } - track->default_duration = 1024*1000 / audiotrack->internal_samplerate; - } - - else if (codec_id == CODEC_ID_TTA) { - MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *) track; - ByteIOContext b; - extradata_size = 30; - extradata = av_mallocz(extradata_size); - if (extradata == NULL) - return AVERROR_NOMEM; - init_put_byte(&b, extradata, extradata_size, 1, - NULL, NULL, NULL, NULL); - put_buffer(&b, (uint8_t *) "TTA1", 4); - put_le16(&b, 1); - put_le16(&b, audiotrack->channels); - put_le16(&b, audiotrack->bitdepth); - put_le32(&b, audiotrack->samplerate); - put_le32(&b, matroska->ctx->duration * audiotrack->samplerate); - } - - else if (codec_id == CODEC_ID_RV10 || codec_id == CODEC_ID_RV20 || - codec_id == CODEC_ID_RV30 || codec_id == CODEC_ID_RV40) { - extradata_offset = 26; - track->codec_priv_size -= extradata_offset; - track->flags |= MATROSKA_TRACK_REAL_V; - } - - if (codec_id == CODEC_ID_NONE) { - av_log(matroska->ctx, AV_LOG_INFO, - "Unknown/unsupported CodecID %s.\n", - track->codec_id); - } - - track->stream_index = matroska->num_streams; - - matroska->num_streams++; - st = av_new_stream(s, track->stream_index); - if (st == NULL) - return AVERROR_NOMEM; - av_set_pts_info(st, 64, matroska->time_scale, 1000*1000*1000); /* 64 bit pts in ns */ - - st->codec->codec_id = codec_id; - - if (track->default_duration) - av_reduce(&st->codec->time_base.num, &st->codec->time_base.den, - track->default_duration, 1000, 30000); - - if(extradata){ - st->codec->extradata = extradata; - st->codec->extradata_size = extradata_size; - } else if(track->codec_priv && track->codec_priv_size > 0){ - st->codec->extradata = av_malloc(track->codec_priv_size); - if(st->codec->extradata == NULL) - return AVERROR_NOMEM; - st->codec->extradata_size = track->codec_priv_size; - memcpy(st->codec->extradata,track->codec_priv+extradata_offset, - track->codec_priv_size); - } - - if (track->type == MATROSKA_TRACK_TYPE_VIDEO) { - MatroskaVideoTrack *videotrack = (MatroskaVideoTrack *)track; - - st->codec->codec_type = CODEC_TYPE_VIDEO; - st->codec->codec_tag = videotrack->fourcc; - st->codec->width = videotrack->pixel_width; - st->codec->height = videotrack->pixel_height; - if (videotrack->display_width == 0) - videotrack->display_width= videotrack->pixel_width; - if (videotrack->display_height == 0) - videotrack->display_height= videotrack->pixel_height; - av_reduce(&st->codec->sample_aspect_ratio.num, - &st->codec->sample_aspect_ratio.den, - st->codec->height * videotrack->display_width, - st->codec-> width * videotrack->display_height, - 255); - st->need_parsing = 2; - } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) { - MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)track; - - st->codec->codec_type = CODEC_TYPE_AUDIO; - st->codec->sample_rate = audiotrack->samplerate; - st->codec->channels = audiotrack->channels; - } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) { - st->codec->codec_type = CODEC_TYPE_SUBTITLE; - } - - /* What do we do with private data? E.g. for Vorbis. */ - } - res = 0; - } - - return res; -} - -static int -matroska_find_track_by_num (MatroskaDemuxContext *matroska, - int num) -{ - int i; - - for (i = 0; i < matroska->num_tracks; i++) - if (matroska->tracks[i]->num == num) - return i; - - return -1; -} - -static inline int -rv_offset(uint8_t *data, int slice, int slices) -{ - return AV_RL32(data+8*slice+4) + 8*slices; -} - -static int -matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size, - int64_t pos, uint64_t cluster_time, uint64_t duration, - int is_keyframe, int is_bframe) -{ - int res = 0; - int track; - AVPacket *pkt; - uint8_t *origdata = data; - int16_t block_time; - uint32_t *lace_size = NULL; - int n, flags, laces = 0; - uint64_t num; - - /* first byte(s): tracknum */ - if ((n = matroska_ebmlnum_uint(data, size, &num)) < 0) { - av_log(matroska->ctx, AV_LOG_ERROR, "EBML block data error\n"); - av_free(origdata); - return res; - } - data += n; - size -= n; - - /* fetch track from num */ - track = matroska_find_track_by_num(matroska, num); - if (size <= 3 || track < 0 || track >= matroska->num_tracks) { - av_log(matroska->ctx, AV_LOG_INFO, - "Invalid stream %d or size %u\n", track, size); - av_free(origdata); - return res; - } - if(matroska->ctx->streams[ matroska->tracks[track]->stream_index ]->discard >= AVDISCARD_ALL){ - av_free(origdata); - return res; - } - if (duration == AV_NOPTS_VALUE) - duration = matroska->tracks[track]->default_duration; - - /* block_time (relative to cluster time) */ - block_time = (data[0] << 8) | data[1]; - data += 2; - size -= 2; - flags = *data; - data += 1; - size -= 1; - if (is_keyframe == -1) - is_keyframe = flags & 1 ? PKT_FLAG_KEY : 0; - switch ((flags & 0x06) >> 1) { - case 0x0: /* no lacing */ - laces = 1; - lace_size = av_mallocz(sizeof(int)); - lace_size[0] = size; - break; - - case 0x1: /* xiph lacing */ - case 0x2: /* fixed-size lacing */ - case 0x3: /* EBML lacing */ - if (size == 0) { - res = -1; - break; - } - laces = (*data) + 1; - data += 1; - size -= 1; - lace_size = av_mallocz(laces * sizeof(int)); - - switch ((flags & 0x06) >> 1) { - case 0x1: /* xiph lacing */ { - uint8_t temp; - uint32_t total = 0; - for (n = 0; res == 0 && n < laces - 1; n++) { - while (1) { - if (size == 0) { - res = -1; - break; - } - temp = *data; - lace_size[n] += temp; - data += 1; - size -= 1; - if (temp != 0xff) - break; - } - total += lace_size[n]; - } - lace_size[n] = size - total; - break; - } - - case 0x2: /* fixed-size lacing */ - for (n = 0; n < laces; n++) - lace_size[n] = size / laces; - break; - - case 0x3: /* EBML lacing */ { - uint32_t total; - n = matroska_ebmlnum_uint(data, size, &num); - if (n < 0) { - av_log(matroska->ctx, AV_LOG_INFO, - "EBML block data error\n"); - break; - } - data += n; - size -= n; - total = lace_size[0] = num; - for (n = 1; res == 0 && n < laces - 1; n++) { - int64_t snum; - int r; - r = matroska_ebmlnum_sint (data, size, &snum); - if (r < 0) { - av_log(matroska->ctx, AV_LOG_INFO, - "EBML block data error\n"); - break; - } - data += r; - size -= r; - lace_size[n] = lace_size[n - 1] + snum; - total += lace_size[n]; - } - lace_size[n] = size - total; - break; - } - } - break; - } - - if (res == 0) { - int real_v = matroska->tracks[track]->flags & MATROSKA_TRACK_REAL_V; - uint64_t timecode = AV_NOPTS_VALUE; - - if (cluster_time != (uint64_t)-1 && cluster_time + block_time >= 0) - timecode = cluster_time + block_time; - - for (n = 0; n < laces; n++) { - int slice, slices = 1; - - if (real_v) { - slices = *data++ + 1; - lace_size[n]--; - } - - for (slice=0; slicedata, data+slice_offset, slice_size); - - if (n == 0) - pkt->flags = is_keyframe; - pkt->stream_index = matroska->tracks[track]->stream_index; - - pkt->pts = timecode; - pkt->pos = pos; - pkt->duration = duration; - - if (matroska->tracks[track]->flags & MATROSKA_TRACK_REORDER) - matroska_queue_packet_reordered(matroska, pkt, is_bframe); - else - matroska_queue_packet(matroska, pkt); - - if (timecode != AV_NOPTS_VALUE) - timecode = duration ? timecode + duration : AV_NOPTS_VALUE; - } - data += lace_size[n]; - } - } - - av_free(lace_size); - av_free(origdata); - return res; -} - -static int -matroska_parse_blockgroup (MatroskaDemuxContext *matroska, - uint64_t cluster_time) -{ - int res = 0; - uint32_t id; - int is_bframe = 0; - int is_keyframe = PKT_FLAG_KEY, last_num_packets = matroska->num_packets; - uint64_t duration = AV_NOPTS_VALUE; - uint8_t *data; - int size = 0; - int64_t pos = 0; - - av_log(matroska->ctx, AV_LOG_DEBUG, "parsing blockgroup...\n"); - - while (res == 0) { - if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { - res = AVERROR_IO; - break; - } else if (matroska->level_up) { - matroska->level_up--; - break; - } - - switch (id) { - /* one block inside the group. Note, block parsing is one - * of the harder things, so this code is a bit complicated. - * See http://www.matroska.org/ for documentation. */ - case MATROSKA_ID_BLOCK: { - pos = url_ftell(&matroska->ctx->pb); - res = ebml_read_binary(matroska, &id, &data, &size); - break; - } - - case MATROSKA_ID_BLOCKDURATION: { - if ((res = ebml_read_uint(matroska, &id, &duration)) < 0) - break; - duration /= matroska->time_scale; - break; - } - - case MATROSKA_ID_BLOCKREFERENCE: { - int64_t num; - /* We've found a reference, so not even the first frame in - * the lace is a key frame. */ - is_keyframe = 0; - if (last_num_packets != matroska->num_packets) - matroska->packets[last_num_packets]->flags = 0; - if ((res = ebml_read_sint(matroska, &id, &num)) < 0) - break; - if (num > 0) - is_bframe = 1; - break; - } - - default: - av_log(matroska->ctx, AV_LOG_INFO, - "Unknown entry 0x%x in blockgroup data\n", id); - /* fall-through */ - - case EBML_ID_VOID: - res = ebml_read_skip(matroska); - break; - } - - if (matroska->level_up) { - matroska->level_up--; - break; - } - } - - if (res) - return res; - - if (size > 0) - res = matroska_parse_block(matroska, data, size, pos, cluster_time, - duration, is_keyframe, is_bframe); - - return res; -} - -static int -matroska_parse_cluster (MatroskaDemuxContext *matroska) -{ - int res = 0; - uint32_t id; - uint64_t cluster_time = 0; - uint8_t *data; - int64_t pos; - int size; - - av_log(matroska->ctx, AV_LOG_DEBUG, - "parsing cluster at %"PRId64"\n", url_ftell(&matroska->ctx->pb)); - - while (res == 0) { - if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { - res = AVERROR_IO; - break; - } else if (matroska->level_up) { - matroska->level_up--; - break; - } - - switch (id) { - /* cluster timecode */ - case MATROSKA_ID_CLUSTERTIMECODE: { - uint64_t num; - if ((res = ebml_read_uint(matroska, &id, &num)) < 0) - break; - cluster_time = num; - break; - } - - /* a group of blocks inside a cluster */ - case MATROSKA_ID_BLOCKGROUP: - if ((res = ebml_read_master(matroska, &id)) < 0) - break; - res = matroska_parse_blockgroup(matroska, cluster_time); - break; - - case MATROSKA_ID_SIMPLEBLOCK: - pos = url_ftell(&matroska->ctx->pb); - res = ebml_read_binary(matroska, &id, &data, &size); - if (res == 0) - res = matroska_parse_block(matroska, data, size, pos, - cluster_time, AV_NOPTS_VALUE, - -1, 0); - break; - - default: - av_log(matroska->ctx, AV_LOG_INFO, - "Unknown entry 0x%x in cluster data\n", id); - /* fall-through */ - - case EBML_ID_VOID: - res = ebml_read_skip(matroska); - break; - } - - if (matroska->level_up) { - matroska->level_up--; - break; - } - } - - return res; -} - -static int -matroska_read_packet (AVFormatContext *s, - AVPacket *pkt) -{ - MatroskaDemuxContext *matroska = s->priv_data; - int res = 0; - uint32_t id; - - /* Read stream until we have a packet queued. */ - while (matroska_deliver_packet(matroska, pkt)) { - - /* Have we already reached the end? */ - if (matroska->done) - return AVERROR_IO; - - while (res == 0) { - if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { - return AVERROR_IO; - } else if (matroska->level_up) { - matroska->level_up--; - break; - } - - switch (id) { - case MATROSKA_ID_CLUSTER: - if ((res = ebml_read_master(matroska, &id)) < 0) - break; - if ((res = matroska_parse_cluster(matroska)) == 0) - res = 1; /* Parsed one cluster, let's get out. */ - break; - - default: - case EBML_ID_VOID: - res = ebml_read_skip(matroska); - break; - } - - if (matroska->level_up) { - matroska->level_up--; - break; - } - } - - if (res == -1) - matroska->done = 1; - } - - return 0; -} - -static int -matroska_read_close (AVFormatContext *s) -{ - MatroskaDemuxContext *matroska = s->priv_data; - int n = 0; - - av_free(matroska->writing_app); - av_free(matroska->muxing_app); - av_free(matroska->index); - - if (matroska->packets != NULL) { - for (n = 0; n < matroska->num_packets; n++) { - av_free_packet(matroska->packets[n]); - av_free(matroska->packets[n]); - } - av_free(matroska->packets); - } - if (matroska->packets_reorder) { - for (n = 0; n < matroska->num_packets_reorder; n++) { - av_free_packet(matroska->packets_reorder[n]); - av_free(matroska->packets_reorder[n]); - } - av_free(matroska->packets_reorder); - } - - for (n = 0; n < matroska->num_tracks; n++) { - MatroskaTrack *track = matroska->tracks[n]; - av_free(track->codec_id); - av_free(track->codec_name); - av_free(track->codec_priv); - av_free(track->name); - av_free(track->language); - - av_free(track); - } - - return 0; -} +const CodecMime ff_mkv_mime_tags[] = { + {"text/plain" , CODEC_ID_TEXT}, + {"image/gif" , CODEC_ID_GIF}, + {"image/jpeg" , CODEC_ID_MJPEG}, + {"image/png" , CODEC_ID_PNG}, + {"image/tiff" , CODEC_ID_TIFF}, + {"application/x-truetype-font", CODEC_ID_TTF}, + {"application/x-font" , CODEC_ID_TTF}, -AVInputFormat matroska_demuxer = { - "matroska", - "Matroska file format", - sizeof(MatroskaDemuxContext), - matroska_probe, - matroska_read_header, - matroska_read_packet, - matroska_read_close, + {"" , CODEC_ID_NONE} }; diff --git a/contrib/ffmpeg/libavformat/matroska.h b/contrib/ffmpeg/libavformat/matroska.h new file mode 100644 index 000000000..370a8bfd8 --- /dev/null +++ b/contrib/ffmpeg/libavformat/matroska.h @@ -0,0 +1,210 @@ +/* + * Matroska constants + * Copyright (c) 2003-2004 The ffmpeg Project + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_MATROSKA_H +#define FFMPEG_MATROSKA_H + +#include "avcodec.h" + +/* EBML version supported */ +#define EBML_VERSION 1 + +/* top-level master-IDs */ +#define EBML_ID_HEADER 0x1A45DFA3 + +/* IDs in the HEADER master */ +#define EBML_ID_EBMLVERSION 0x4286 +#define EBML_ID_EBMLREADVERSION 0x42F7 +#define EBML_ID_EBMLMAXIDLENGTH 0x42F2 +#define EBML_ID_EBMLMAXSIZELENGTH 0x42F3 +#define EBML_ID_DOCTYPE 0x4282 +#define EBML_ID_DOCTYPEVERSION 0x4287 +#define EBML_ID_DOCTYPEREADVERSION 0x4285 + +/* general EBML types */ +#define EBML_ID_VOID 0xEC + +/* + * Matroska element IDs. max. 32-bit. + */ + +/* toplevel segment */ +#define MATROSKA_ID_SEGMENT 0x18538067 + +/* matroska top-level master IDs */ +#define MATROSKA_ID_INFO 0x1549A966 +#define MATROSKA_ID_TRACKS 0x1654AE6B +#define MATROSKA_ID_CUES 0x1C53BB6B +#define MATROSKA_ID_TAGS 0x1254C367 +#define MATROSKA_ID_SEEKHEAD 0x114D9B74 +#define MATROSKA_ID_ATTACHMENTS 0x1941A469 +#define MATROSKA_ID_CLUSTER 0x1F43B675 + +/* IDs in the info master */ +#define MATROSKA_ID_TIMECODESCALE 0x2AD7B1 +#define MATROSKA_ID_DURATION 0x4489 +#define MATROSKA_ID_TITLE 0x7BA9 +#define MATROSKA_ID_WRITINGAPP 0x5741 +#define MATROSKA_ID_MUXINGAPP 0x4D80 +#define MATROSKA_ID_DATEUTC 0x4461 +#define MATROSKA_ID_SEGMENTUID 0x73A4 + +/* ID in the tracks master */ +#define MATROSKA_ID_TRACKENTRY 0xAE + +/* IDs in the trackentry master */ +#define MATROSKA_ID_TRACKNUMBER 0xD7 +#define MATROSKA_ID_TRACKUID 0x73C5 +#define MATROSKA_ID_TRACKTYPE 0x83 +#define MATROSKA_ID_TRACKAUDIO 0xE1 +#define MATROSKA_ID_TRACKVIDEO 0xE0 +#define MATROSKA_ID_CODECID 0x86 +#define MATROSKA_ID_CODECPRIVATE 0x63A2 +#define MATROSKA_ID_CODECNAME 0x258688 +#define MATROSKA_ID_CODECINFOURL 0x3B4040 +#define MATROSKA_ID_CODECDOWNLOADURL 0x26B240 +#define MATROSKA_ID_TRACKNAME 0x536E +#define MATROSKA_ID_TRACKLANGUAGE 0x22B59C +#define MATROSKA_ID_TRACKFLAGENABLED 0xB9 +#define MATROSKA_ID_TRACKFLAGDEFAULT 0x88 +#define MATROSKA_ID_TRACKFLAGLACING 0x9C +#define MATROSKA_ID_TRACKMINCACHE 0x6DE7 +#define MATROSKA_ID_TRACKMAXCACHE 0x6DF8 +#define MATROSKA_ID_TRACKDEFAULTDURATION 0x23E383 + +/* IDs in the trackvideo master */ +#define MATROSKA_ID_VIDEOFRAMERATE 0x2383E3 +#define MATROSKA_ID_VIDEODISPLAYWIDTH 0x54B0 +#define MATROSKA_ID_VIDEODISPLAYHEIGHT 0x54BA +#define MATROSKA_ID_VIDEOPIXELWIDTH 0xB0 +#define MATROSKA_ID_VIDEOPIXELHEIGHT 0xBA +#define MATROSKA_ID_VIDEOFLAGINTERLACED 0x9A +#define MATROSKA_ID_VIDEOSTEREOMODE 0x53B9 +#define MATROSKA_ID_VIDEOASPECTRATIO 0x54B3 +#define MATROSKA_ID_VIDEOCOLORSPACE 0x2EB524 + +/* IDs in the trackaudio master */ +#define MATROSKA_ID_AUDIOSAMPLINGFREQ 0xB5 +#define MATROSKA_ID_AUDIOOUTSAMPLINGFREQ 0x78B5 + +#define MATROSKA_ID_AUDIOBITDEPTH 0x6264 +#define MATROSKA_ID_AUDIOCHANNELS 0x9F + +/* ID in the cues master */ +#define MATROSKA_ID_POINTENTRY 0xBB + +/* IDs in the pointentry master */ +#define MATROSKA_ID_CUETIME 0xB3 +#define MATROSKA_ID_CUETRACKPOSITION 0xB7 + +/* IDs in the cuetrackposition master */ +#define MATROSKA_ID_CUETRACK 0xF7 +#define MATROSKA_ID_CUECLUSTERPOSITION 0xF1 + +/* IDs in the tags master */ +/* TODO */ + +/* IDs in the seekhead master */ +#define MATROSKA_ID_SEEKENTRY 0x4DBB + +/* IDs in the seekpoint master */ +#define MATROSKA_ID_SEEKID 0x53AB +#define MATROSKA_ID_SEEKPOSITION 0x53AC + +/* IDs in the cluster master */ +#define MATROSKA_ID_CLUSTERTIMECODE 0xE7 +#define MATROSKA_ID_BLOCKGROUP 0xA0 +#define MATROSKA_ID_SIMPLEBLOCK 0xA3 + +/* IDs in the blockgroup master */ +#define MATROSKA_ID_BLOCK 0xA1 +#define MATROSKA_ID_BLOCKDURATION 0x9B +#define MATROSKA_ID_BLOCKREFERENCE 0xFB + +/* IDs in the attachments master */ +#define MATROSKA_ID_ATTACHEDFILE 0x61A7 +#define MATROSKA_ID_FILENAME 0x466E +#define MATROSKA_ID_FILEMIMETYPE 0x4660 +#define MATROSKA_ID_FILEDATA 0x465C +#define MATROSKA_ID_FILEUID 0x46AE + +typedef enum { + MATROSKA_TRACK_TYPE_VIDEO = 0x1, + MATROSKA_TRACK_TYPE_AUDIO = 0x2, + MATROSKA_TRACK_TYPE_COMPLEX = 0x3, + MATROSKA_TRACK_TYPE_LOGO = 0x10, + MATROSKA_TRACK_TYPE_SUBTITLE = 0x11, + MATROSKA_TRACK_TYPE_CONTROL = 0x20, +} MatroskaTrackType; + +typedef enum { + MATROSKA_EYE_MODE_MONO = 0x0, + MATROSKA_EYE_MODE_RIGHT = 0x1, + MATROSKA_EYE_MODE_LEFT = 0x2, + MATROSKA_EYE_MODE_BOTH = 0x3, +} MatroskaEyeMode; + +typedef enum { + MATROSKA_ASPECT_RATIO_MODE_FREE = 0x0, + MATROSKA_ASPECT_RATIO_MODE_KEEP = 0x1, + MATROSKA_ASPECT_RATIO_MODE_FIXED = 0x2, +} MatroskaAspectRatioMode; + +/* + * These aren't in any way "matroska-form" things, + * it's just something I use in the muxer/demuxer. + */ + +typedef enum { + MATROSKA_TRACK_ENABLED = (1<<0), + MATROSKA_TRACK_DEFAULT = (1<<1), + MATROSKA_TRACK_LACING = (1<<2), + MATROSKA_TRACK_SHIFT = (1<<16) +} MatroskaTrackFlags; + +typedef enum { + MATROSKA_VIDEOTRACK_INTERLACED = (MATROSKA_TRACK_SHIFT<<0) +} MatroskaVideoTrackFlags; + +/* + * Matroska Codec IDs. Strings. + */ + +typedef struct CodecTags{ + char str[16]; + enum CodecID id; +}CodecTags; + +typedef struct CodecMime{ + char str[32]; + enum CodecID id; +}CodecMime; + +#define MATROSKA_CODEC_ID_VIDEO_VFW_FOURCC "V_MS/VFW/FOURCC" +#define MATROSKA_CODEC_ID_AUDIO_ACM "A_MS/ACM" + +/* max. depth in the EBML tree structure */ +#define EBML_MAX_DEPTH 16 + +extern const CodecTags ff_mkv_codec_tags[]; +extern const CodecMime ff_mkv_mime_tags[]; + +#endif /* FFMPEG_MATROSKA_H */ diff --git a/contrib/ffmpeg/libavformat/matroskadec.c b/contrib/ffmpeg/libavformat/matroskadec.c new file mode 100644 index 000000000..d9fdcec28 --- /dev/null +++ b/contrib/ffmpeg/libavformat/matroskadec.c @@ -0,0 +1,2842 @@ +/* + * Matroska file demuxer (no muxer yet) + * Copyright (c) 2003-2004 The ffmpeg Project + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file matroskadec.c + * Matroska file demuxer + * by Ronald Bultje + * with a little help from Moritz Bunkus + * Specs available on the matroska project page: + * http://www.matroska.org/. + */ + +#include "avformat.h" +/* For codec_get_id(). */ +#include "riff.h" +#include "intfloat_readwrite.h" +#include "matroska.h" + +typedef struct Track { + MatroskaTrackType type; + + /* Unique track number and track ID. stream_index is the index that + * the calling app uses for this track. */ + uint32_t num; + uint32_t uid; + int stream_index; + + char *name; + char language[4]; + + char *codec_id; + char *codec_name; + + unsigned char *codec_priv; + int codec_priv_size; + + uint64_t default_duration; + MatroskaTrackFlags flags; +} MatroskaTrack; + +typedef struct MatroskaVideoTrack { + MatroskaTrack track; + + int pixel_width; + int pixel_height; + int display_width; + int display_height; + + uint32_t fourcc; + + MatroskaAspectRatioMode ar_mode; + MatroskaEyeMode eye_mode; + + //.. +} MatroskaVideoTrack; + +typedef struct MatroskaAudioTrack { + MatroskaTrack track; + + int channels; + int bitdepth; + int internal_samplerate; + int samplerate; + int block_align; + + /* real audio header */ + int coded_framesize; + int sub_packet_h; + int frame_size; + int sub_packet_size; + int sub_packet_cnt; + int pkt_cnt; + uint8_t *buf; + //.. +} MatroskaAudioTrack; + +typedef struct MatroskaSubtitleTrack { + MatroskaTrack track; + //.. +} MatroskaSubtitleTrack; + +#define MAX_TRACK_SIZE (FFMAX(FFMAX(sizeof(MatroskaVideoTrack), \ + sizeof(MatroskaAudioTrack)), \ + sizeof(MatroskaSubtitleTrack))) + +typedef struct MatroskaLevel { + uint64_t start; + uint64_t length; +} MatroskaLevel; + +typedef struct MatroskaDemuxIndex { + uint64_t pos; /* of the corresponding *cluster*! */ + uint16_t track; /* reference to 'num' */ + uint64_t time; /* in nanoseconds */ +} MatroskaDemuxIndex; + +typedef struct MatroskaDemuxContext { + AVFormatContext *ctx; + + /* ebml stuff */ + int num_levels; + MatroskaLevel levels[EBML_MAX_DEPTH]; + int level_up; + + /* matroska stuff */ + char *writing_app; + char *muxing_app; + int64_t created; + + /* timescale in the file */ + int64_t time_scale; + + /* num_streams is the number of streams that av_new_stream() was called + * for ( = that are available to the calling program). */ + int num_tracks; + int num_streams; + MatroskaTrack *tracks[MAX_STREAMS]; + + /* cache for ID peeking */ + uint32_t peek_id; + + /* byte position of the segment inside the stream */ + offset_t segment_start; + + /* The packet queue. */ + AVPacket **packets; + int num_packets; + + /* have we already parse metadata/cues/clusters? */ + int metadata_parsed; + int index_parsed; + int done; + + /* The index for seeking. */ + int num_indexes; + MatroskaDemuxIndex *index; + + /* What to skip before effectively reading a packet. */ + int skip_to_keyframe; + AVStream *skip_to_stream; +} MatroskaDemuxContext; + +/* + * The first few functions handle EBML file parsing. The rest + * is the document interpretation. Matroska really just is a + * EBML file. + */ + +/* + * Return: the amount of levels in the hierarchy that the + * current element lies higher than the previous one. + * The opposite isn't done - that's auto-done using master + * element reading. + */ + +static int +ebml_read_element_level_up (MatroskaDemuxContext *matroska) +{ + ByteIOContext *pb = matroska->ctx->pb; + offset_t pos = url_ftell(pb); + int num = 0; + + while (matroska->num_levels > 0) { + MatroskaLevel *level = &matroska->levels[matroska->num_levels - 1]; + + if (pos >= level->start + level->length) { + matroska->num_levels--; + num++; + } else { + break; + } + } + + return num; +} + +/* + * Read: an "EBML number", which is defined as a variable-length + * array of bytes. The first byte indicates the length by giving a + * number of 0-bits followed by a one. The position of the first + * "one" bit inside the first byte indicates the length of this + * number. + * Returns: num. of bytes read. < 0 on error. + */ + +static int +ebml_read_num (MatroskaDemuxContext *matroska, + int max_size, + uint64_t *number) +{ + ByteIOContext *pb = matroska->ctx->pb; + int len_mask = 0x80, read = 1, n = 1; + int64_t total = 0; + + /* the first byte tells us the length in bytes - get_byte() can normally + * return 0, but since that's not a valid first ebmlID byte, we can + * use it safely here to catch EOS. */ + if (!(total = get_byte(pb))) { + /* we might encounter EOS here */ + if (!url_feof(pb)) { + offset_t pos = url_ftell(pb); + av_log(matroska->ctx, AV_LOG_ERROR, + "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", + pos, pos); + } + return AVERROR(EIO); /* EOS or actual I/O error */ + } + + /* get the length of the EBML number */ + while (read <= max_size && !(total & len_mask)) { + read++; + len_mask >>= 1; + } + if (read > max_size) { + offset_t pos = url_ftell(pb) - 1; + av_log(matroska->ctx, AV_LOG_ERROR, + "Invalid EBML number size tag 0x%02x at pos %"PRIu64" (0x%"PRIx64")\n", + (uint8_t) total, pos, pos); + return AVERROR_INVALIDDATA; + } + + /* read out length */ + total &= ~len_mask; + while (n++ < read) + total = (total << 8) | get_byte(pb); + + *number = total; + + return read; +} + +/* + * Read: the element content data ID. + * Return: the number of bytes read or < 0 on error. + */ + +static int +ebml_read_element_id (MatroskaDemuxContext *matroska, + uint32_t *id, + int *level_up) +{ + int read; + uint64_t total; + + /* if we re-call this, use our cached ID */ + if (matroska->peek_id != 0) { + if (level_up) + *level_up = 0; + *id = matroska->peek_id; + return 0; + } + + /* read out the "EBML number", include tag in ID */ + if ((read = ebml_read_num(matroska, 4, &total)) < 0) + return read; + *id = matroska->peek_id = total | (1 << (read * 7)); + + /* level tracking */ + if (level_up) + *level_up = ebml_read_element_level_up(matroska); + + return read; +} + +/* + * Read: element content length. + * Return: the number of bytes read or < 0 on error. + */ + +static int +ebml_read_element_length (MatroskaDemuxContext *matroska, + uint64_t *length) +{ + /* clear cache since we're now beyond that data point */ + matroska->peek_id = 0; + + /* read out the "EBML number", include tag in ID */ + return ebml_read_num(matroska, 8, length); +} + +/* + * Return: the ID of the next element, or 0 on error. + * Level_up contains the amount of levels that this + * next element lies higher than the previous one. + */ + +static uint32_t +ebml_peek_id (MatroskaDemuxContext *matroska, + int *level_up) +{ + uint32_t id; + + if (ebml_read_element_id(matroska, &id, level_up) < 0) + return 0; + + return id; +} + +/* + * Seek to a given offset. + * 0 is success, -1 is failure. + */ + +static int +ebml_read_seek (MatroskaDemuxContext *matroska, + offset_t offset) +{ + ByteIOContext *pb = matroska->ctx->pb; + + /* clear ID cache, if any */ + matroska->peek_id = 0; + + return (url_fseek(pb, offset, SEEK_SET) == offset) ? 0 : -1; +} + +/* + * Skip the next element. + * 0 is success, -1 is failure. + */ + +static int +ebml_read_skip (MatroskaDemuxContext *matroska) +{ + ByteIOContext *pb = matroska->ctx->pb; + uint32_t id; + uint64_t length; + int res; + + if ((res = ebml_read_element_id(matroska, &id, NULL)) < 0 || + (res = ebml_read_element_length(matroska, &length)) < 0) + return res; + + url_fskip(pb, length); + + return 0; +} + +/* + * Read the next element as an unsigned int. + * 0 is success, < 0 is failure. + */ + +static int +ebml_read_uint (MatroskaDemuxContext *matroska, + uint32_t *id, + uint64_t *num) +{ + ByteIOContext *pb = matroska->ctx->pb; + int n = 0, size, res; + uint64_t rlength; + + if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || + (res = ebml_read_element_length(matroska, &rlength)) < 0) + return res; + size = rlength; + if (size < 1 || size > 8) { + offset_t pos = url_ftell(pb); + av_log(matroska->ctx, AV_LOG_ERROR, + "Invalid uint element size %d at position %"PRId64" (0x%"PRIx64")\n", + size, pos, pos); + return AVERROR_INVALIDDATA; + } + + /* big-endian ordening; build up number */ + *num = 0; + while (n++ < size) + *num = (*num << 8) | get_byte(pb); + + return 0; +} + +/* + * Read the next element as a signed int. + * 0 is success, < 0 is failure. + */ + +static int +ebml_read_sint (MatroskaDemuxContext *matroska, + uint32_t *id, + int64_t *num) +{ + ByteIOContext *pb = matroska->ctx->pb; + int size, n = 1, negative = 0, res; + uint64_t rlength; + + if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || + (res = ebml_read_element_length(matroska, &rlength)) < 0) + return res; + size = rlength; + if (size < 1 || size > 8) { + offset_t pos = url_ftell(pb); + av_log(matroska->ctx, AV_LOG_ERROR, + "Invalid sint element size %d at position %"PRId64" (0x%"PRIx64")\n", + size, pos, pos); + return AVERROR_INVALIDDATA; + } + if ((*num = get_byte(pb)) & 0x80) { + negative = 1; + *num &= ~0x80; + } + while (n++ < size) + *num = (*num << 8) | get_byte(pb); + + /* make signed */ + if (negative) + *num = *num - (1LL << ((8 * size) - 1)); + + return 0; +} + +/* + * Read the next element as a float. + * 0 is success, < 0 is failure. + */ + +static int +ebml_read_float (MatroskaDemuxContext *matroska, + uint32_t *id, + double *num) +{ + ByteIOContext *pb = matroska->ctx->pb; + int size, res; + uint64_t rlength; + + if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || + (res = ebml_read_element_length(matroska, &rlength)) < 0) + return res; + size = rlength; + + if (size == 4) { + *num= av_int2flt(get_be32(pb)); + } else if(size==8){ + *num= av_int2dbl(get_be64(pb)); + } else{ + offset_t pos = url_ftell(pb); + av_log(matroska->ctx, AV_LOG_ERROR, + "Invalid float element size %d at position %"PRIu64" (0x%"PRIx64")\n", + size, pos, pos); + return AVERROR_INVALIDDATA; + } + + return 0; +} + +/* + * Read the next element as an ASCII string. + * 0 is success, < 0 is failure. + */ + +static int +ebml_read_ascii (MatroskaDemuxContext *matroska, + uint32_t *id, + char **str) +{ + ByteIOContext *pb = matroska->ctx->pb; + int size, res; + uint64_t rlength; + + if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || + (res = ebml_read_element_length(matroska, &rlength)) < 0) + return res; + size = rlength; + + /* ebml strings are usually not 0-terminated, so we allocate one + * byte more, read the string and NULL-terminate it ourselves. */ + if (size < 0 || !(*str = av_malloc(size + 1))) { + av_log(matroska->ctx, AV_LOG_ERROR, "Memory allocation failed\n"); + return AVERROR(ENOMEM); + } + if (get_buffer(pb, (uint8_t *) *str, size) != size) { + offset_t pos = url_ftell(pb); + av_log(matroska->ctx, AV_LOG_ERROR, + "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos); + return AVERROR(EIO); + } + (*str)[size] = '\0'; + + return 0; +} + +/* + * Read the next element as a UTF-8 string. + * 0 is success, < 0 is failure. + */ + +static int +ebml_read_utf8 (MatroskaDemuxContext *matroska, + uint32_t *id, + char **str) +{ + return ebml_read_ascii(matroska, id, str); +} + +/* + * Read the next element as a date (nanoseconds since 1/1/2000). + * 0 is success, < 0 is failure. + */ + +static int +ebml_read_date (MatroskaDemuxContext *matroska, + uint32_t *id, + int64_t *date) +{ + return ebml_read_sint(matroska, id, date); +} + +/* + * Read the next element, but only the header. The contents + * are supposed to be sub-elements which can be read separately. + * 0 is success, < 0 is failure. + */ + +static int +ebml_read_master (MatroskaDemuxContext *matroska, + uint32_t *id) +{ + ByteIOContext *pb = matroska->ctx->pb; + uint64_t length; + MatroskaLevel *level; + int res; + + if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || + (res = ebml_read_element_length(matroska, &length)) < 0) + return res; + + /* protect... (Heaven forbids that the '>' is true) */ + if (matroska->num_levels >= EBML_MAX_DEPTH) { + av_log(matroska->ctx, AV_LOG_ERROR, + "File moves beyond max. allowed depth (%d)\n", EBML_MAX_DEPTH); + return AVERROR(ENOSYS); + } + + /* remember level */ + level = &matroska->levels[matroska->num_levels++]; + level->start = url_ftell(pb); + level->length = length; + + return 0; +} + +/* + * Read the next element as binary data. + * 0 is success, < 0 is failure. + */ + +static int +ebml_read_binary (MatroskaDemuxContext *matroska, + uint32_t *id, + uint8_t **binary, + int *size) +{ + ByteIOContext *pb = matroska->ctx->pb; + uint64_t rlength; + int res; + + if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || + (res = ebml_read_element_length(matroska, &rlength)) < 0) + return res; + *size = rlength; + + if (!(*binary = av_malloc(*size))) { + av_log(matroska->ctx, AV_LOG_ERROR, + "Memory allocation error\n"); + return AVERROR(ENOMEM); + } + + if (get_buffer(pb, *binary, *size) != *size) { + offset_t pos = url_ftell(pb); + av_log(matroska->ctx, AV_LOG_ERROR, + "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos); + return AVERROR(EIO); + } + + return 0; +} + +/* + * Read signed/unsigned "EBML" numbers. + * Return: number of bytes processed, < 0 on error. + * XXX: use ebml_read_num(). + */ + +static int +matroska_ebmlnum_uint (uint8_t *data, + uint32_t size, + uint64_t *num) +{ + int len_mask = 0x80, read = 1, n = 1, num_ffs = 0; + uint64_t total; + + if (size <= 0) + return AVERROR_INVALIDDATA; + + total = data[0]; + while (read <= 8 && !(total & len_mask)) { + read++; + len_mask >>= 1; + } + if (read > 8) + return AVERROR_INVALIDDATA; + + if ((total &= (len_mask - 1)) == len_mask - 1) + num_ffs++; + if (size < read) + return AVERROR_INVALIDDATA; + while (n < read) { + if (data[n] == 0xff) + num_ffs++; + total = (total << 8) | data[n]; + n++; + } + + if (read == num_ffs) + *num = (uint64_t)-1; + else + *num = total; + + return read; +} + +/* + * Same as above, but signed. + */ + +static int +matroska_ebmlnum_sint (uint8_t *data, + uint32_t size, + int64_t *num) +{ + uint64_t unum; + int res; + + /* read as unsigned number first */ + if ((res = matroska_ebmlnum_uint(data, size, &unum)) < 0) + return res; + + /* make signed (weird way) */ + if (unum == (uint64_t)-1) + *num = INT64_MAX; + else + *num = unum - ((1LL << ((7 * res) - 1)) - 1); + + return res; +} + +/* + * Read an EBML header. + * 0 is success, < 0 is failure. + */ + +static int +ebml_read_header (MatroskaDemuxContext *matroska, + char **doctype, + int *version) +{ + uint32_t id; + int level_up, res = 0; + + /* default init */ + if (doctype) + *doctype = NULL; + if (version) + *version = 1; + + if (!(id = ebml_peek_id(matroska, &level_up)) || + level_up != 0 || id != EBML_ID_HEADER) { + av_log(matroska->ctx, AV_LOG_ERROR, + "This is not an EBML file (id=0x%x/0x%x)\n", id, EBML_ID_HEADER); + return AVERROR_INVALIDDATA; + } + if ((res = ebml_read_master(matroska, &id)) < 0) + return res; + + while (res == 0) { + if (!(id = ebml_peek_id(matroska, &level_up))) + return AVERROR(EIO); + + /* end-of-header */ + if (level_up) + break; + + switch (id) { + /* is our read version uptodate? */ + case EBML_ID_EBMLREADVERSION: { + uint64_t num; + + if ((res = ebml_read_uint(matroska, &id, &num)) < 0) + return res; + if (num > EBML_VERSION) { + av_log(matroska->ctx, AV_LOG_ERROR, + "EBML version %"PRIu64" (> %d) is not supported\n", + num, EBML_VERSION); + return AVERROR_INVALIDDATA; + } + break; + } + + /* we only handle 8 byte lengths at max */ + case EBML_ID_EBMLMAXSIZELENGTH: { + uint64_t num; + + if ((res = ebml_read_uint(matroska, &id, &num)) < 0) + return res; + if (num > sizeof(uint64_t)) { + av_log(matroska->ctx, AV_LOG_ERROR, + "Integers of size %"PRIu64" (> %zd) not supported\n", + num, sizeof(uint64_t)); + return AVERROR_INVALIDDATA; + } + break; + } + + /* we handle 4 byte IDs at max */ + case EBML_ID_EBMLMAXIDLENGTH: { + uint64_t num; + + if ((res = ebml_read_uint(matroska, &id, &num)) < 0) + return res; + if (num > sizeof(uint32_t)) { + av_log(matroska->ctx, AV_LOG_ERROR, + "IDs of size %"PRIu64" (> %zu) not supported\n", + num, sizeof(uint32_t)); + return AVERROR_INVALIDDATA; + } + break; + } + + case EBML_ID_DOCTYPE: { + char *text; + + if ((res = ebml_read_ascii(matroska, &id, &text)) < 0) + return res; + if (doctype) { + if (*doctype) + av_free(*doctype); + *doctype = text; + } else + av_free(text); + break; + } + + case EBML_ID_DOCTYPEREADVERSION: { + uint64_t num; + + if ((res = ebml_read_uint(matroska, &id, &num)) < 0) + return res; + if (version) + *version = num; + break; + } + + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown data type 0x%x in EBML header", id); + /* pass-through */ + + case EBML_ID_VOID: + /* we ignore these two, as they don't tell us anything we + * care about */ + case EBML_ID_EBMLVERSION: + case EBML_ID_DOCTYPEVERSION: + res = ebml_read_skip (matroska); + break; + } + } + + return 0; +} + + +static int +matroska_find_track_by_num (MatroskaDemuxContext *matroska, + int num) +{ + int i; + + for (i = 0; i < matroska->num_tracks; i++) + if (matroska->tracks[i]->num == num) + return i; + + return -1; +} + + +/* + * Put one packet in an application-supplied AVPacket struct. + * Returns 0 on success or -1 on failure. + */ + +static int +matroska_deliver_packet (MatroskaDemuxContext *matroska, + AVPacket *pkt) +{ + if (matroska->num_packets > 0) { + memcpy(pkt, matroska->packets[0], sizeof(AVPacket)); + av_free(matroska->packets[0]); + if (matroska->num_packets > 1) { + memmove(&matroska->packets[0], &matroska->packets[1], + (matroska->num_packets - 1) * sizeof(AVPacket *)); + matroska->packets = + av_realloc(matroska->packets, (matroska->num_packets - 1) * + sizeof(AVPacket *)); + } else { + av_freep(&matroska->packets); + } + matroska->num_packets--; + return 0; + } + + return -1; +} + +/* + * Put a packet into our internal queue. Will be delivered to the + * user/application during the next get_packet() call. + */ + +static void +matroska_queue_packet (MatroskaDemuxContext *matroska, + AVPacket *pkt) +{ + matroska->packets = + av_realloc(matroska->packets, (matroska->num_packets + 1) * + sizeof(AVPacket *)); + matroska->packets[matroska->num_packets] = pkt; + matroska->num_packets++; +} + +/* + * Free all packets in our internal queue. + */ +static void +matroska_clear_queue (MatroskaDemuxContext *matroska) +{ + if (matroska->packets) { + int n; + for (n = 0; n < matroska->num_packets; n++) { + av_free_packet(matroska->packets[n]); + av_free(matroska->packets[n]); + } + av_free(matroska->packets); + matroska->packets = NULL; + matroska->num_packets = 0; + } +} + + +/* + * Autodetecting... + */ + +static int +matroska_probe (AVProbeData *p) +{ + uint64_t total = 0; + int len_mask = 0x80, size = 1, n = 1; + uint8_t probe_data[] = { 'm', 'a', 't', 'r', 'o', 's', 'k', 'a' }; + + /* ebml header? */ + if (AV_RB32(p->buf) != EBML_ID_HEADER) + return 0; + + /* length of header */ + total = p->buf[4]; + while (size <= 8 && !(total & len_mask)) { + size++; + len_mask >>= 1; + } + if (size > 8) + return 0; + total &= (len_mask - 1); + while (n < size) + total = (total << 8) | p->buf[4 + n++]; + + /* does the probe data contain the whole header? */ + if (p->buf_size < 4 + size + total) + return 0; + + /* the header must contain the document type 'matroska'. For now, + * we don't parse the whole header but simply check for the + * availability of that array of characters inside the header. + * Not fully fool-proof, but good enough. */ + for (n = 4 + size; n <= 4 + size + total - sizeof(probe_data); n++) + if (!memcmp (&p->buf[n], probe_data, sizeof(probe_data))) + return AVPROBE_SCORE_MAX; + + return 0; +} + +/* + * From here on, it's all XML-style DTD stuff... Needs no comments. + */ + +static int +matroska_parse_info (MatroskaDemuxContext *matroska) +{ + int res = 0; + uint32_t id; + + av_log(matroska->ctx, AV_LOG_DEBUG, "Parsing info...\n"); + + while (res == 0) { + if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { + res = AVERROR(EIO); + break; + } else if (matroska->level_up) { + matroska->level_up--; + break; + } + + switch (id) { + /* cluster timecode */ + case MATROSKA_ID_TIMECODESCALE: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, &num)) < 0) + break; + matroska->time_scale = num; + break; + } + + case MATROSKA_ID_DURATION: { + double num; + if ((res = ebml_read_float(matroska, &id, &num)) < 0) + break; + matroska->ctx->duration = num * matroska->time_scale * 1000 / AV_TIME_BASE; + break; + } + + case MATROSKA_ID_TITLE: { + char *text; + if ((res = ebml_read_utf8(matroska, &id, &text)) < 0) + break; + strncpy(matroska->ctx->title, text, + sizeof(matroska->ctx->title)-1); + av_free(text); + break; + } + + case MATROSKA_ID_WRITINGAPP: { + char *text; + if ((res = ebml_read_utf8(matroska, &id, &text)) < 0) + break; + matroska->writing_app = text; + break; + } + + case MATROSKA_ID_MUXINGAPP: { + char *text; + if ((res = ebml_read_utf8(matroska, &id, &text)) < 0) + break; + matroska->muxing_app = text; + break; + } + + case MATROSKA_ID_DATEUTC: { + int64_t time; + if ((res = ebml_read_date(matroska, &id, &time)) < 0) + break; + matroska->created = time; + break; + } + + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown entry 0x%x in info header\n", id); + /* fall-through */ + + case EBML_ID_VOID: + res = ebml_read_skip(matroska); + break; + } + + if (matroska->level_up) { + matroska->level_up--; + break; + } + } + + return res; +} + +static int +matroska_add_stream (MatroskaDemuxContext *matroska) +{ + int res = 0; + uint32_t id; + MatroskaTrack *track; + + av_log(matroska->ctx, AV_LOG_DEBUG, "parsing track, adding stream..,\n"); + + /* Allocate a generic track. As soon as we know its type we'll realloc. */ + track = av_mallocz(MAX_TRACK_SIZE); + matroska->num_tracks++; + strcpy(track->language, "eng"); + + /* start with the master */ + if ((res = ebml_read_master(matroska, &id)) < 0) + return res; + + /* try reading the trackentry headers */ + while (res == 0) { + if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { + res = AVERROR(EIO); + break; + } else if (matroska->level_up > 0) { + matroska->level_up--; + break; + } + + switch (id) { + /* track number (unique stream ID) */ + case MATROSKA_ID_TRACKNUMBER: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, &num)) < 0) + break; + track->num = num; + break; + } + + /* track UID (unique identifier) */ + case MATROSKA_ID_TRACKUID: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, &num)) < 0) + break; + track->uid = num; + break; + } + + /* track type (video, audio, combined, subtitle, etc.) */ + case MATROSKA_ID_TRACKTYPE: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, &num)) < 0) + break; + if (track->type && track->type != num) { + av_log(matroska->ctx, AV_LOG_INFO, + "More than one tracktype in an entry - skip\n"); + break; + } + track->type = num; + + switch (track->type) { + case MATROSKA_TRACK_TYPE_VIDEO: + case MATROSKA_TRACK_TYPE_AUDIO: + case MATROSKA_TRACK_TYPE_SUBTITLE: + break; + case MATROSKA_TRACK_TYPE_COMPLEX: + case MATROSKA_TRACK_TYPE_LOGO: + case MATROSKA_TRACK_TYPE_CONTROL: + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown or unsupported track type 0x%x\n", + track->type); + track->type = 0; + break; + } + matroska->tracks[matroska->num_tracks - 1] = track; + break; + } + + /* tracktype specific stuff for video */ + case MATROSKA_ID_TRACKVIDEO: { + MatroskaVideoTrack *videotrack; + if (!track->type) + track->type = MATROSKA_TRACK_TYPE_VIDEO; + if (track->type != MATROSKA_TRACK_TYPE_VIDEO) { + av_log(matroska->ctx, AV_LOG_INFO, + "video data in non-video track - ignoring\n"); + res = AVERROR_INVALIDDATA; + break; + } else if ((res = ebml_read_master(matroska, &id)) < 0) + break; + videotrack = (MatroskaVideoTrack *)track; + + while (res == 0) { + if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { + res = AVERROR(EIO); + break; + } else if (matroska->level_up > 0) { + matroska->level_up--; + break; + } + + switch (id) { + /* fixme, this should be one-up, but I get it here */ + case MATROSKA_ID_TRACKDEFAULTDURATION: { + uint64_t num; + if ((res = ebml_read_uint (matroska, &id, + &num)) < 0) + break; + track->default_duration = num; + break; + } + + /* video framerate */ + case MATROSKA_ID_VIDEOFRAMERATE: { + double num; + if ((res = ebml_read_float(matroska, &id, + &num)) < 0) + break; + if (!track->default_duration) + track->default_duration = 1000000000/num; + break; + } + + /* width of the size to display the video at */ + case MATROSKA_ID_VIDEODISPLAYWIDTH: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, + &num)) < 0) + break; + videotrack->display_width = num; + break; + } + + /* height of the size to display the video at */ + case MATROSKA_ID_VIDEODISPLAYHEIGHT: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, + &num)) < 0) + break; + videotrack->display_height = num; + break; + } + + /* width of the video in the file */ + case MATROSKA_ID_VIDEOPIXELWIDTH: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, + &num)) < 0) + break; + videotrack->pixel_width = num; + break; + } + + /* height of the video in the file */ + case MATROSKA_ID_VIDEOPIXELHEIGHT: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, + &num)) < 0) + break; + videotrack->pixel_height = num; + break; + } + + /* whether the video is interlaced */ + case MATROSKA_ID_VIDEOFLAGINTERLACED: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, + &num)) < 0) + break; + if (num) + track->flags |= + MATROSKA_VIDEOTRACK_INTERLACED; + else + track->flags &= + ~MATROSKA_VIDEOTRACK_INTERLACED; + break; + } + + /* stereo mode (whether the video has two streams, + * where one is for the left eye and the other for + * the right eye, which creates a 3D-like + * effect) */ + case MATROSKA_ID_VIDEOSTEREOMODE: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, + &num)) < 0) + break; + if (num != MATROSKA_EYE_MODE_MONO && + num != MATROSKA_EYE_MODE_LEFT && + num != MATROSKA_EYE_MODE_RIGHT && + num != MATROSKA_EYE_MODE_BOTH) { + av_log(matroska->ctx, AV_LOG_INFO, + "Ignoring unknown eye mode 0x%x\n", + (uint32_t) num); + break; + } + videotrack->eye_mode = num; + break; + } + + /* aspect ratio behaviour */ + case MATROSKA_ID_VIDEOASPECTRATIO: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, + &num)) < 0) + break; + if (num != MATROSKA_ASPECT_RATIO_MODE_FREE && + num != MATROSKA_ASPECT_RATIO_MODE_KEEP && + num != MATROSKA_ASPECT_RATIO_MODE_FIXED) { + av_log(matroska->ctx, AV_LOG_INFO, + "Ignoring unknown aspect ratio 0x%x\n", + (uint32_t) num); + break; + } + videotrack->ar_mode = num; + break; + } + + /* colorspace (only matters for raw video) + * fourcc */ + case MATROSKA_ID_VIDEOCOLORSPACE: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, + &num)) < 0) + break; + videotrack->fourcc = num; + break; + } + + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown video track header entry " + "0x%x - ignoring\n", id); + /* pass-through */ + + case EBML_ID_VOID: + res = ebml_read_skip(matroska); + break; + } + + if (matroska->level_up) { + matroska->level_up--; + break; + } + } + break; + } + + /* tracktype specific stuff for audio */ + case MATROSKA_ID_TRACKAUDIO: { + MatroskaAudioTrack *audiotrack; + if (!track->type) + track->type = MATROSKA_TRACK_TYPE_AUDIO; + if (track->type != MATROSKA_TRACK_TYPE_AUDIO) { + av_log(matroska->ctx, AV_LOG_INFO, + "audio data in non-audio track - ignoring\n"); + res = AVERROR_INVALIDDATA; + break; + } else if ((res = ebml_read_master(matroska, &id)) < 0) + break; + audiotrack = (MatroskaAudioTrack *)track; + audiotrack->channels = 1; + audiotrack->samplerate = 8000; + + while (res == 0) { + if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { + res = AVERROR(EIO); + break; + } else if (matroska->level_up > 0) { + matroska->level_up--; + break; + } + + switch (id) { + /* samplerate */ + case MATROSKA_ID_AUDIOSAMPLINGFREQ: { + double num; + if ((res = ebml_read_float(matroska, &id, + &num)) < 0) + break; + audiotrack->internal_samplerate = + audiotrack->samplerate = num; + break; + } + + case MATROSKA_ID_AUDIOOUTSAMPLINGFREQ: { + double num; + if ((res = ebml_read_float(matroska, &id, + &num)) < 0) + break; + audiotrack->samplerate = num; + break; + } + + /* bitdepth */ + case MATROSKA_ID_AUDIOBITDEPTH: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, + &num)) < 0) + break; + audiotrack->bitdepth = num; + break; + } + + /* channels */ + case MATROSKA_ID_AUDIOCHANNELS: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, + &num)) < 0) + break; + audiotrack->channels = num; + break; + } + + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown audio track header entry " + "0x%x - ignoring\n", id); + /* pass-through */ + + case EBML_ID_VOID: + res = ebml_read_skip(matroska); + break; + } + + if (matroska->level_up) { + matroska->level_up--; + break; + } + } + break; + } + + /* codec identifier */ + case MATROSKA_ID_CODECID: { + char *text; + if ((res = ebml_read_ascii(matroska, &id, &text)) < 0) + break; + track->codec_id = text; + break; + } + + /* codec private data */ + case MATROSKA_ID_CODECPRIVATE: { + uint8_t *data; + int size; + if ((res = ebml_read_binary(matroska, &id, &data, &size) < 0)) + break; + track->codec_priv = data; + track->codec_priv_size = size; + break; + } + + /* name of the codec */ + case MATROSKA_ID_CODECNAME: { + char *text; + if ((res = ebml_read_utf8(matroska, &id, &text)) < 0) + break; + track->codec_name = text; + break; + } + + /* name of this track */ + case MATROSKA_ID_TRACKNAME: { + char *text; + if ((res = ebml_read_utf8(matroska, &id, &text)) < 0) + break; + track->name = text; + break; + } + + /* language (matters for audio/subtitles, mostly) */ + case MATROSKA_ID_TRACKLANGUAGE: { + char *text, *end; + if ((res = ebml_read_utf8(matroska, &id, &text)) < 0) + break; + if ((end = strchr(text, '-'))) + *end = '\0'; + if (strlen(text) == 3) + strcpy(track->language, text); + av_free(text); + break; + } + + /* whether this is actually used */ + case MATROSKA_ID_TRACKFLAGENABLED: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, &num)) < 0) + break; + if (num) + track->flags |= MATROSKA_TRACK_ENABLED; + else + track->flags &= ~MATROSKA_TRACK_ENABLED; + break; + } + + /* whether it's the default for this track type */ + case MATROSKA_ID_TRACKFLAGDEFAULT: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, &num)) < 0) + break; + if (num) + track->flags |= MATROSKA_TRACK_DEFAULT; + else + track->flags &= ~MATROSKA_TRACK_DEFAULT; + break; + } + + /* lacing (like MPEG, where blocks don't end/start on frame + * boundaries) */ + case MATROSKA_ID_TRACKFLAGLACING: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, &num)) < 0) + break; + if (num) + track->flags |= MATROSKA_TRACK_LACING; + else + track->flags &= ~MATROSKA_TRACK_LACING; + break; + } + + /* default length (in time) of one data block in this track */ + case MATROSKA_ID_TRACKDEFAULTDURATION: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, &num)) < 0) + break; + track->default_duration = num; + break; + } + + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown track header entry 0x%x - ignoring\n", id); + /* pass-through */ + + case EBML_ID_VOID: + /* we ignore these because they're nothing useful. */ + case MATROSKA_ID_CODECINFOURL: + case MATROSKA_ID_CODECDOWNLOADURL: + case MATROSKA_ID_TRACKMINCACHE: + case MATROSKA_ID_TRACKMAXCACHE: + res = ebml_read_skip(matroska); + break; + } + + if (matroska->level_up) { + matroska->level_up--; + break; + } + } + + return res; +} + +static int +matroska_parse_tracks (MatroskaDemuxContext *matroska) +{ + int res = 0; + uint32_t id; + + av_log(matroska->ctx, AV_LOG_DEBUG, "parsing tracks...\n"); + + while (res == 0) { + if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { + res = AVERROR(EIO); + break; + } else if (matroska->level_up) { + matroska->level_up--; + break; + } + + switch (id) { + /* one track within the "all-tracks" header */ + case MATROSKA_ID_TRACKENTRY: + res = matroska_add_stream(matroska); + break; + + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown entry 0x%x in track header\n", id); + /* fall-through */ + + case EBML_ID_VOID: + res = ebml_read_skip(matroska); + break; + } + + if (matroska->level_up) { + matroska->level_up--; + break; + } + } + + return res; +} + +static int +matroska_parse_index (MatroskaDemuxContext *matroska) +{ + int res = 0; + uint32_t id; + MatroskaDemuxIndex idx; + + av_log(matroska->ctx, AV_LOG_DEBUG, "parsing index...\n"); + + while (res == 0) { + if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { + res = AVERROR(EIO); + break; + } else if (matroska->level_up) { + matroska->level_up--; + break; + } + + switch (id) { + /* one single index entry ('point') */ + case MATROSKA_ID_POINTENTRY: + if ((res = ebml_read_master(matroska, &id)) < 0) + break; + + /* in the end, we hope to fill one entry with a + * timestamp, a file position and a tracknum */ + idx.pos = (uint64_t) -1; + idx.time = (uint64_t) -1; + idx.track = (uint16_t) -1; + + while (res == 0) { + if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { + res = AVERROR(EIO); + break; + } else if (matroska->level_up) { + matroska->level_up--; + break; + } + + switch (id) { + /* one single index entry ('point') */ + case MATROSKA_ID_CUETIME: { + uint64_t time; + if ((res = ebml_read_uint(matroska, &id, + &time)) < 0) + break; + idx.time = time * matroska->time_scale; + break; + } + + /* position in the file + track to which it + * belongs */ + case MATROSKA_ID_CUETRACKPOSITION: + if ((res = ebml_read_master(matroska, &id)) < 0) + break; + + while (res == 0) { + if (!(id = ebml_peek_id (matroska, + &matroska->level_up))) { + res = AVERROR(EIO); + break; + } else if (matroska->level_up) { + matroska->level_up--; + break; + } + + switch (id) { + /* track number */ + case MATROSKA_ID_CUETRACK: { + uint64_t num; + if ((res = ebml_read_uint(matroska, + &id, &num)) < 0) + break; + idx.track = num; + break; + } + + /* position in file */ + case MATROSKA_ID_CUECLUSTERPOSITION: { + uint64_t num; + if ((res = ebml_read_uint(matroska, + &id, &num)) < 0) + break; + idx.pos = num+matroska->segment_start; + break; + } + + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown entry 0x%x in " + "CuesTrackPositions\n", id); + /* fall-through */ + + case EBML_ID_VOID: + res = ebml_read_skip(matroska); + break; + } + + if (matroska->level_up) { + matroska->level_up--; + break; + } + } + + break; + + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown entry 0x%x in cuespoint " + "index\n", id); + /* fall-through */ + + case EBML_ID_VOID: + res = ebml_read_skip(matroska); + break; + } + + if (matroska->level_up) { + matroska->level_up--; + break; + } + } + + /* so let's see if we got what we wanted */ + if (idx.pos != (uint64_t) -1 && + idx.time != (uint64_t) -1 && + idx.track != (uint16_t) -1) { + if (matroska->num_indexes % 32 == 0) { + /* re-allocate bigger index */ + matroska->index = + av_realloc(matroska->index, + (matroska->num_indexes + 32) * + sizeof(MatroskaDemuxIndex)); + } + matroska->index[matroska->num_indexes] = idx; + matroska->num_indexes++; + } + break; + + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown entry 0x%x in cues header\n", id); + /* fall-through */ + + case EBML_ID_VOID: + res = ebml_read_skip(matroska); + break; + } + + if (matroska->level_up) { + matroska->level_up--; + break; + } + } + + return res; +} + +static int +matroska_parse_metadata (MatroskaDemuxContext *matroska) +{ + int res = 0; + uint32_t id; + + while (res == 0) { + if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { + res = AVERROR(EIO); + break; + } else if (matroska->level_up) { + matroska->level_up--; + break; + } + + switch (id) { + /* Hm, this is unsupported... */ + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown entry 0x%x in metadata header\n", id); + /* fall-through */ + + case EBML_ID_VOID: + res = ebml_read_skip(matroska); + break; + } + + if (matroska->level_up) { + matroska->level_up--; + break; + } + } + + return res; +} + +static int +matroska_parse_seekhead (MatroskaDemuxContext *matroska) +{ + int res = 0; + uint32_t id; + + av_log(matroska->ctx, AV_LOG_DEBUG, "parsing seekhead...\n"); + + while (res == 0) { + if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { + res = AVERROR(EIO); + break; + } else if (matroska->level_up) { + matroska->level_up--; + break; + } + + switch (id) { + case MATROSKA_ID_SEEKENTRY: { + uint32_t seek_id = 0, peek_id_cache = 0; + uint64_t seek_pos = (uint64_t) -1, t; + + if ((res = ebml_read_master(matroska, &id)) < 0) + break; + + while (res == 0) { + if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { + res = AVERROR(EIO); + break; + } else if (matroska->level_up) { + matroska->level_up--; + break; + } + + switch (id) { + case MATROSKA_ID_SEEKID: + res = ebml_read_uint(matroska, &id, &t); + seek_id = t; + break; + + case MATROSKA_ID_SEEKPOSITION: + res = ebml_read_uint(matroska, &id, &seek_pos); + break; + + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown seekhead ID 0x%x\n", id); + /* fall-through */ + + case EBML_ID_VOID: + res = ebml_read_skip(matroska); + break; + } + + if (matroska->level_up) { + matroska->level_up--; + break; + } + } + + if (!seek_id || seek_pos == (uint64_t) -1) { + av_log(matroska->ctx, AV_LOG_INFO, + "Incomplete seekhead entry (0x%x/%"PRIu64")\n", + seek_id, seek_pos); + break; + } + + switch (seek_id) { + case MATROSKA_ID_CUES: + case MATROSKA_ID_TAGS: { + uint32_t level_up = matroska->level_up; + offset_t before_pos; + uint64_t length; + MatroskaLevel level; + + /* remember the peeked ID and the current position */ + peek_id_cache = matroska->peek_id; + before_pos = url_ftell(matroska->ctx->pb); + + /* seek */ + if ((res = ebml_read_seek(matroska, seek_pos + + matroska->segment_start)) < 0) + return res; + + /* we don't want to lose our seekhead level, so we add + * a dummy. This is a crude hack. */ + if (matroska->num_levels == EBML_MAX_DEPTH) { + av_log(matroska->ctx, AV_LOG_INFO, + "Max EBML element depth (%d) reached, " + "cannot parse further.\n", EBML_MAX_DEPTH); + return AVERROR_UNKNOWN; + } + + level.start = 0; + level.length = (uint64_t)-1; + matroska->levels[matroska->num_levels] = level; + matroska->num_levels++; + + /* check ID */ + if (!(id = ebml_peek_id (matroska, + &matroska->level_up))) + goto finish; + if (id != seek_id) { + av_log(matroska->ctx, AV_LOG_INFO, + "We looked for ID=0x%x but got " + "ID=0x%x (pos=%"PRIu64")", + seek_id, id, seek_pos + + matroska->segment_start); + goto finish; + } + + /* read master + parse */ + if ((res = ebml_read_master(matroska, &id)) < 0) + goto finish; + switch (id) { + case MATROSKA_ID_CUES: + if (!(res = matroska_parse_index(matroska)) || + url_feof(matroska->ctx->pb)) { + matroska->index_parsed = 1; + res = 0; + } + break; + case MATROSKA_ID_TAGS: + if (!(res = matroska_parse_metadata(matroska)) || + url_feof(matroska->ctx->pb)) { + matroska->metadata_parsed = 1; + res = 0; + } + break; + } + + finish: + /* remove dummy level */ + while (matroska->num_levels) { + matroska->num_levels--; + length = + matroska->levels[matroska->num_levels].length; + if (length == (uint64_t)-1) + break; + } + + /* seek back */ + if ((res = ebml_read_seek(matroska, before_pos)) < 0) + return res; + matroska->peek_id = peek_id_cache; + matroska->level_up = level_up; + break; + } + + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Ignoring seekhead entry for ID=0x%x\n", + seek_id); + break; + } + + break; + } + + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown seekhead ID 0x%x\n", id); + /* fall-through */ + + case EBML_ID_VOID: + res = ebml_read_skip(matroska); + break; + } + + if (matroska->level_up) { + matroska->level_up--; + break; + } + } + + return res; +} + +static int +matroska_parse_attachments(AVFormatContext *s) +{ + MatroskaDemuxContext *matroska = s->priv_data; + int res = 0; + uint32_t id; + + av_log(matroska->ctx, AV_LOG_DEBUG, "parsing attachments...\n"); + + while (res == 0) { + if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { + res = AVERROR(EIO); + break; + } else if (matroska->level_up) { + matroska->level_up--; + break; + } + + switch (id) { + case MATROSKA_ID_ATTACHEDFILE: { + char* name = NULL; + char* mime = NULL; + uint8_t* data = NULL; + int i, data_size = 0; + AVStream *st; + + if ((res = ebml_read_master(matroska, &id)) < 0) + break; + + while (res == 0) { + if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { + res = AVERROR(EIO); + break; + } else if (matroska->level_up) { + matroska->level_up--; + break; + } + + switch (id) { + case MATROSKA_ID_FILENAME: + res = ebml_read_utf8 (matroska, &id, &name); + break; + + case MATROSKA_ID_FILEMIMETYPE: + res = ebml_read_ascii (matroska, &id, &mime); + break; + + case MATROSKA_ID_FILEDATA: + res = ebml_read_binary(matroska, &id, &data, &data_size); + break; + + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown attachedfile ID 0x%x\n", id); + case EBML_ID_VOID: + res = ebml_read_skip(matroska); + break; + } + + if (matroska->level_up) { + matroska->level_up--; + break; + } + } + + if (!(name && mime && data && data_size > 0)) { + av_log(matroska->ctx, AV_LOG_ERROR, "incomplete attachment\n"); + break; + } + + st = av_new_stream(s, matroska->num_streams++); + if (st == NULL) + return AVERROR(ENOMEM); + st->filename = av_strdup(name); + st->codec->codec_id = CODEC_ID_NONE; + st->codec->codec_type = CODEC_TYPE_ATTACHMENT; + st->codec->extradata = av_malloc(data_size); + if(st->codec->extradata == NULL) + return AVERROR(ENOMEM); + st->codec->extradata_size = data_size; + memcpy(st->codec->extradata, data, data_size); + + for (i=0; ff_mkv_mime_tags[i].id != CODEC_ID_NONE; i++) { + if (!strncmp(ff_mkv_mime_tags[i].str, mime, + strlen(ff_mkv_mime_tags[i].str))) { + st->codec->codec_id = ff_mkv_mime_tags[i].id; + break; + } + } + + av_log(matroska->ctx, AV_LOG_DEBUG, "new attachment: %s, %s, size %d \n", name, mime, data_size); + break; + } + + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown attachments ID 0x%x\n", id); + /* fall-through */ + + case EBML_ID_VOID: + res = ebml_read_skip(matroska); + break; + } + + if (matroska->level_up) { + matroska->level_up--; + break; + } + } + + return res; +} + +#define ARRAY_SIZE(x) (sizeof(x)/sizeof(*x)) + +static int +matroska_aac_profile (char *codec_id) +{ + static const char *aac_profiles[] = { + "MAIN", "LC", "SSR" + }; + int profile; + + for (profile=0; profilepriv_data; + char *doctype; + int version, last_level, res = 0; + uint32_t id; + + matroska->ctx = s; + + /* First read the EBML header. */ + doctype = NULL; + if ((res = ebml_read_header(matroska, &doctype, &version)) < 0) + return res; + if ((doctype == NULL) || strcmp(doctype, "matroska")) { + av_log(matroska->ctx, AV_LOG_ERROR, + "Wrong EBML doctype ('%s' != 'matroska').\n", + doctype ? doctype : "(none)"); + if (doctype) + av_free(doctype); + return AVERROR_NOFMT; + } + av_free(doctype); + if (version > 2) { + av_log(matroska->ctx, AV_LOG_ERROR, + "Matroska demuxer version 2 too old for file version %d\n", + version); + return AVERROR_NOFMT; + } + + /* The next thing is a segment. */ + while (1) { + if (!(id = ebml_peek_id(matroska, &last_level))) + return AVERROR(EIO); + if (id == MATROSKA_ID_SEGMENT) + break; + + /* oi! */ + av_log(matroska->ctx, AV_LOG_INFO, + "Expected a Segment ID (0x%x), but received 0x%x!\n", + MATROSKA_ID_SEGMENT, id); + if ((res = ebml_read_skip(matroska)) < 0) + return res; + } + + /* We now have a Matroska segment. + * Seeks are from the beginning of the segment, + * after the segment ID/length. */ + if ((res = ebml_read_master(matroska, &id)) < 0) + return res; + matroska->segment_start = url_ftell(s->pb); + + matroska->time_scale = 1000000; + /* we've found our segment, start reading the different contents in here */ + while (res == 0) { + if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { + res = AVERROR(EIO); + break; + } else if (matroska->level_up) { + matroska->level_up--; + break; + } + + switch (id) { + /* stream info */ + case MATROSKA_ID_INFO: { + if ((res = ebml_read_master(matroska, &id)) < 0) + break; + res = matroska_parse_info(matroska); + break; + } + + /* track info headers */ + case MATROSKA_ID_TRACKS: { + if ((res = ebml_read_master(matroska, &id)) < 0) + break; + res = matroska_parse_tracks(matroska); + break; + } + + /* stream index */ + case MATROSKA_ID_CUES: { + if (!matroska->index_parsed) { + if ((res = ebml_read_master(matroska, &id)) < 0) + break; + res = matroska_parse_index(matroska); + } else + res = ebml_read_skip(matroska); + break; + } + + /* metadata */ + case MATROSKA_ID_TAGS: { + if (!matroska->metadata_parsed) { + if ((res = ebml_read_master(matroska, &id)) < 0) + break; + res = matroska_parse_metadata(matroska); + } else + res = ebml_read_skip(matroska); + break; + } + + /* file index (if seekable, seek to Cues/Tags to parse it) */ + case MATROSKA_ID_SEEKHEAD: { + if ((res = ebml_read_master(matroska, &id)) < 0) + break; + res = matroska_parse_seekhead(matroska); + break; + } + + case MATROSKA_ID_ATTACHMENTS: { + if ((res = ebml_read_master(matroska, &id)) < 0) + break; + res = matroska_parse_attachments(s); + break; + } + + case MATROSKA_ID_CLUSTER: { + /* Do not read the master - this will be done in the next + * call to matroska_read_packet. */ + res = 1; + break; + } + + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown matroska file header ID 0x%x\n", id); + /* fall-through */ + + case EBML_ID_VOID: + res = ebml_read_skip(matroska); + break; + } + + if (matroska->level_up) { + matroska->level_up--; + break; + } + } + + /* Have we found a cluster? */ + if (ebml_peek_id(matroska, NULL) == MATROSKA_ID_CLUSTER) { + int i, j; + MatroskaTrack *track; + AVStream *st; + + for (i = 0; i < matroska->num_tracks; i++) { + enum CodecID codec_id = CODEC_ID_NONE; + uint8_t *extradata = NULL; + int extradata_size = 0; + int extradata_offset = 0; + track = matroska->tracks[i]; + track->stream_index = -1; + + /* Apply some sanity checks. */ + if (track->codec_id == NULL) + continue; + + for(j=0; ff_mkv_codec_tags[j].id != CODEC_ID_NONE; j++){ + if(!strncmp(ff_mkv_codec_tags[j].str, track->codec_id, + strlen(ff_mkv_codec_tags[j].str))){ + codec_id= ff_mkv_codec_tags[j].id; + break; + } + } + + /* Set the FourCC from the CodecID. */ + /* This is the MS compatibility mode which stores a + * BITMAPINFOHEADER in the CodecPrivate. */ + if (!strcmp(track->codec_id, + MATROSKA_CODEC_ID_VIDEO_VFW_FOURCC) && + (track->codec_priv_size >= 40) && + (track->codec_priv != NULL)) { + MatroskaVideoTrack *vtrack = (MatroskaVideoTrack *) track; + + /* Offset of biCompression. Stored in LE. */ + vtrack->fourcc = AV_RL32(track->codec_priv + 16); + codec_id = codec_get_id(codec_bmp_tags, vtrack->fourcc); + + } + + /* This is the MS compatibility mode which stores a + * WAVEFORMATEX in the CodecPrivate. */ + else if (!strcmp(track->codec_id, + MATROSKA_CODEC_ID_AUDIO_ACM) && + (track->codec_priv_size >= 18) && + (track->codec_priv != NULL)) { + uint16_t tag; + + /* Offset of wFormatTag. Stored in LE. */ + tag = AV_RL16(track->codec_priv); + codec_id = codec_get_id(codec_wav_tags, tag); + + } + + else if (codec_id == CODEC_ID_AAC && !track->codec_priv_size) { + MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *) track; + int profile = matroska_aac_profile(track->codec_id); + int sri = matroska_aac_sri(audiotrack->internal_samplerate); + extradata = av_malloc(5); + if (extradata == NULL) + return AVERROR(ENOMEM); + extradata[0] = (profile << 3) | ((sri&0x0E) >> 1); + extradata[1] = ((sri&0x01) << 7) | (audiotrack->channels<<3); + if (strstr(track->codec_id, "SBR")) { + sri = matroska_aac_sri(audiotrack->samplerate); + extradata[2] = 0x56; + extradata[3] = 0xE5; + extradata[4] = 0x80 | (sri<<3); + extradata_size = 5; + } else { + extradata_size = 2; + } + } + + else if (codec_id == CODEC_ID_TTA) { + MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *) track; + ByteIOContext b; + extradata_size = 30; + extradata = av_mallocz(extradata_size); + if (extradata == NULL) + return AVERROR(ENOMEM); + init_put_byte(&b, extradata, extradata_size, 1, + NULL, NULL, NULL, NULL); + put_buffer(&b, "TTA1", 4); + put_le16(&b, 1); + put_le16(&b, audiotrack->channels); + put_le16(&b, audiotrack->bitdepth); + put_le32(&b, audiotrack->samplerate); + put_le32(&b, matroska->ctx->duration * audiotrack->samplerate); + } + + else if (codec_id == CODEC_ID_RV10 || codec_id == CODEC_ID_RV20 || + codec_id == CODEC_ID_RV30 || codec_id == CODEC_ID_RV40) { + extradata_offset = 26; + track->codec_priv_size -= extradata_offset; + } + + else if (codec_id == CODEC_ID_RA_144) { + MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)track; + audiotrack->samplerate = 8000; + audiotrack->channels = 1; + } + + else if (codec_id == CODEC_ID_RA_288 || + codec_id == CODEC_ID_COOK || + codec_id == CODEC_ID_ATRAC3) { + MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)track; + ByteIOContext b; + + init_put_byte(&b, track->codec_priv, track->codec_priv_size, 0, + NULL, NULL, NULL, NULL); + url_fskip(&b, 24); + audiotrack->coded_framesize = get_be32(&b); + url_fskip(&b, 12); + audiotrack->sub_packet_h = get_be16(&b); + audiotrack->frame_size = get_be16(&b); + audiotrack->sub_packet_size = get_be16(&b); + audiotrack->buf = av_malloc(audiotrack->frame_size * audiotrack->sub_packet_h); + if (codec_id == CODEC_ID_RA_288) { + audiotrack->block_align = audiotrack->coded_framesize; + track->codec_priv_size = 0; + } else { + audiotrack->block_align = audiotrack->sub_packet_size; + extradata_offset = 78; + track->codec_priv_size -= extradata_offset; + } + } + + if (codec_id == CODEC_ID_NONE) { + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown/unsupported CodecID %s.\n", + track->codec_id); + } + + track->stream_index = matroska->num_streams; + + matroska->num_streams++; + st = av_new_stream(s, track->stream_index); + if (st == NULL) + return AVERROR(ENOMEM); + av_set_pts_info(st, 64, matroska->time_scale, 1000*1000*1000); /* 64 bit pts in ns */ + + st->codec->codec_id = codec_id; + st->start_time = 0; + if (strcmp(track->language, "und")) + strcpy(st->language, track->language); + + if (track->default_duration) + av_reduce(&st->codec->time_base.num, &st->codec->time_base.den, + track->default_duration, 1000000000, 30000); + + if(extradata){ + st->codec->extradata = extradata; + st->codec->extradata_size = extradata_size; + } else if(track->codec_priv && track->codec_priv_size > 0){ + st->codec->extradata = av_malloc(track->codec_priv_size); + if(st->codec->extradata == NULL) + return AVERROR(ENOMEM); + st->codec->extradata_size = track->codec_priv_size; + memcpy(st->codec->extradata,track->codec_priv+extradata_offset, + track->codec_priv_size); + } + + if (track->type == MATROSKA_TRACK_TYPE_VIDEO) { + MatroskaVideoTrack *videotrack = (MatroskaVideoTrack *)track; + + st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_tag = videotrack->fourcc; + st->codec->width = videotrack->pixel_width; + st->codec->height = videotrack->pixel_height; + if (videotrack->display_width == 0) + videotrack->display_width= videotrack->pixel_width; + if (videotrack->display_height == 0) + videotrack->display_height= videotrack->pixel_height; + av_reduce(&st->codec->sample_aspect_ratio.num, + &st->codec->sample_aspect_ratio.den, + st->codec->height * videotrack->display_width, + st->codec-> width * videotrack->display_height, + 255); + st->need_parsing = AVSTREAM_PARSE_HEADERS; + } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) { + MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)track; + + st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->sample_rate = audiotrack->samplerate; + st->codec->channels = audiotrack->channels; + st->codec->block_align = audiotrack->block_align; + } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) { + st->codec->codec_type = CODEC_TYPE_SUBTITLE; + } + + /* What do we do with private data? E.g. for Vorbis. */ + } + res = 0; + } + + if (matroska->index_parsed) { + int i, track, stream; + for (i=0; inum_indexes; i++) { + MatroskaDemuxIndex *idx = &matroska->index[i]; + track = matroska_find_track_by_num(matroska, idx->track); + stream = matroska->tracks[track]->stream_index; + if (stream >= 0) + av_add_index_entry(matroska->ctx->streams[stream], + idx->pos, idx->time/matroska->time_scale, + 0, 0, AVINDEX_KEYFRAME); + } + } + + return res; +} + +static int +matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size, + int64_t pos, uint64_t cluster_time, uint64_t duration, + int is_keyframe, int is_bframe) +{ + int res = 0; + int track; + AVStream *st; + AVPacket *pkt; + uint8_t *origdata = data; + int16_t block_time; + uint32_t *lace_size = NULL; + int n, flags, laces = 0; + uint64_t num; + + /* first byte(s): tracknum */ + if ((n = matroska_ebmlnum_uint(data, size, &num)) < 0) { + av_log(matroska->ctx, AV_LOG_ERROR, "EBML block data error\n"); + av_free(origdata); + return res; + } + data += n; + size -= n; + + /* fetch track from num */ + track = matroska_find_track_by_num(matroska, num); + if (size <= 3 || track < 0 || track >= matroska->num_tracks) { + av_log(matroska->ctx, AV_LOG_INFO, + "Invalid stream %d or size %u\n", track, size); + av_free(origdata); + return res; + } + if (matroska->tracks[track]->stream_index < 0) { + av_free(origdata); + return res; + } + st = matroska->ctx->streams[matroska->tracks[track]->stream_index]; + if (st->discard >= AVDISCARD_ALL) { + av_free(origdata); + return res; + } + if (duration == AV_NOPTS_VALUE) + duration = matroska->tracks[track]->default_duration / matroska->time_scale; + + /* block_time (relative to cluster time) */ + block_time = AV_RB16(data); + data += 2; + flags = *data++; + size -= 3; + if (is_keyframe == -1) + is_keyframe = flags & 0x80 ? PKT_FLAG_KEY : 0; + + if (matroska->skip_to_keyframe) { + if (!is_keyframe || st != matroska->skip_to_stream) { + av_free(origdata); + return res; + } + matroska->skip_to_keyframe = 0; + } + + switch ((flags & 0x06) >> 1) { + case 0x0: /* no lacing */ + laces = 1; + lace_size = av_mallocz(sizeof(int)); + lace_size[0] = size; + break; + + case 0x1: /* xiph lacing */ + case 0x2: /* fixed-size lacing */ + case 0x3: /* EBML lacing */ + if (size == 0) { + res = -1; + break; + } + laces = (*data) + 1; + data += 1; + size -= 1; + lace_size = av_mallocz(laces * sizeof(int)); + + switch ((flags & 0x06) >> 1) { + case 0x1: /* xiph lacing */ { + uint8_t temp; + uint32_t total = 0; + for (n = 0; res == 0 && n < laces - 1; n++) { + while (1) { + if (size == 0) { + res = -1; + break; + } + temp = *data; + lace_size[n] += temp; + data += 1; + size -= 1; + if (temp != 0xff) + break; + } + total += lace_size[n]; + } + lace_size[n] = size - total; + break; + } + + case 0x2: /* fixed-size lacing */ + for (n = 0; n < laces; n++) + lace_size[n] = size / laces; + break; + + case 0x3: /* EBML lacing */ { + uint32_t total; + n = matroska_ebmlnum_uint(data, size, &num); + if (n < 0) { + av_log(matroska->ctx, AV_LOG_INFO, + "EBML block data error\n"); + break; + } + data += n; + size -= n; + total = lace_size[0] = num; + for (n = 1; res == 0 && n < laces - 1; n++) { + int64_t snum; + int r; + r = matroska_ebmlnum_sint (data, size, &snum); + if (r < 0) { + av_log(matroska->ctx, AV_LOG_INFO, + "EBML block data error\n"); + break; + } + data += r; + size -= r; + lace_size[n] = lace_size[n - 1] + snum; + total += lace_size[n]; + } + lace_size[n] = size - total; + break; + } + } + break; + } + + if (res == 0) { + uint64_t timecode = AV_NOPTS_VALUE; + + if (cluster_time != (uint64_t)-1 + && (block_time >= 0 || cluster_time >= -block_time)) + timecode = cluster_time + block_time; + + for (n = 0; n < laces; n++) { + if (st->codec->codec_id == CODEC_ID_RA_288 || + st->codec->codec_id == CODEC_ID_COOK || + st->codec->codec_id == CODEC_ID_ATRAC3) { + MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)matroska->tracks[track]; + int a = st->codec->block_align; + int sps = audiotrack->sub_packet_size; + int cfs = audiotrack->coded_framesize; + int h = audiotrack->sub_packet_h; + int y = audiotrack->sub_packet_cnt; + int w = audiotrack->frame_size; + int x; + + if (!audiotrack->pkt_cnt) { + if (st->codec->codec_id == CODEC_ID_RA_288) + for (x=0; xbuf+x*2*w+y*cfs, + data+x*cfs, cfs); + else + for (x=0; xbuf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), data+x*sps, sps); + + if (++audiotrack->sub_packet_cnt >= h) { + audiotrack->sub_packet_cnt = 0; + audiotrack->pkt_cnt = h*w / a; + } + } + while (audiotrack->pkt_cnt) { + pkt = av_mallocz(sizeof(AVPacket)); + av_new_packet(pkt, a); + memcpy(pkt->data, audiotrack->buf + + a * (h*w / a - audiotrack->pkt_cnt--), a); + pkt->pos = pos; + pkt->stream_index = matroska->tracks[track]->stream_index; + matroska_queue_packet(matroska, pkt); + } + } else { + int offset = 0; + + pkt = av_mallocz(sizeof(AVPacket)); + /* XXX: prevent data copy... */ + if (av_new_packet(pkt, lace_size[n]-offset) < 0) { + res = AVERROR(ENOMEM); + n = laces-1; + break; + } + memcpy (pkt->data, data+offset, lace_size[n]-offset); + + if (n == 0) + pkt->flags = is_keyframe; + pkt->stream_index = matroska->tracks[track]->stream_index; + + pkt->pts = timecode; + pkt->pos = pos; + pkt->duration = duration; + + matroska_queue_packet(matroska, pkt); + } + + if (timecode != AV_NOPTS_VALUE) + timecode = duration ? timecode + duration : AV_NOPTS_VALUE; + data += lace_size[n]; + } + } + + av_free(lace_size); + av_free(origdata); + return res; +} + +static int +matroska_parse_blockgroup (MatroskaDemuxContext *matroska, + uint64_t cluster_time) +{ + int res = 0; + uint32_t id; + int is_bframe = 0; + int is_keyframe = PKT_FLAG_KEY, last_num_packets = matroska->num_packets; + uint64_t duration = AV_NOPTS_VALUE; + uint8_t *data; + int size = 0; + int64_t pos = 0; + + av_log(matroska->ctx, AV_LOG_DEBUG, "parsing blockgroup...\n"); + + while (res == 0) { + if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { + res = AVERROR(EIO); + break; + } else if (matroska->level_up) { + matroska->level_up--; + break; + } + + switch (id) { + /* one block inside the group. Note, block parsing is one + * of the harder things, so this code is a bit complicated. + * See http://www.matroska.org/ for documentation. */ + case MATROSKA_ID_BLOCK: { + pos = url_ftell(matroska->ctx->pb); + res = ebml_read_binary(matroska, &id, &data, &size); + break; + } + + case MATROSKA_ID_BLOCKDURATION: { + if ((res = ebml_read_uint(matroska, &id, &duration)) < 0) + break; + break; + } + + case MATROSKA_ID_BLOCKREFERENCE: { + int64_t num; + /* We've found a reference, so not even the first frame in + * the lace is a key frame. */ + is_keyframe = 0; + if (last_num_packets != matroska->num_packets) + matroska->packets[last_num_packets]->flags = 0; + if ((res = ebml_read_sint(matroska, &id, &num)) < 0) + break; + if (num > 0) + is_bframe = 1; + break; + } + + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown entry 0x%x in blockgroup data\n", id); + /* fall-through */ + + case EBML_ID_VOID: + res = ebml_read_skip(matroska); + break; + } + + if (matroska->level_up) { + matroska->level_up--; + break; + } + } + + if (res) + return res; + + if (size > 0) + res = matroska_parse_block(matroska, data, size, pos, cluster_time, + duration, is_keyframe, is_bframe); + + return res; +} + +static int +matroska_parse_cluster (MatroskaDemuxContext *matroska) +{ + int res = 0; + uint32_t id; + uint64_t cluster_time = 0; + uint8_t *data; + int64_t pos; + int size; + + av_log(matroska->ctx, AV_LOG_DEBUG, + "parsing cluster at %"PRId64"\n", url_ftell(matroska->ctx->pb)); + + while (res == 0) { + if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { + res = AVERROR(EIO); + break; + } else if (matroska->level_up) { + matroska->level_up--; + break; + } + + switch (id) { + /* cluster timecode */ + case MATROSKA_ID_CLUSTERTIMECODE: { + uint64_t num; + if ((res = ebml_read_uint(matroska, &id, &num)) < 0) + break; + cluster_time = num; + break; + } + + /* a group of blocks inside a cluster */ + case MATROSKA_ID_BLOCKGROUP: + if ((res = ebml_read_master(matroska, &id)) < 0) + break; + res = matroska_parse_blockgroup(matroska, cluster_time); + break; + + case MATROSKA_ID_SIMPLEBLOCK: + pos = url_ftell(matroska->ctx->pb); + res = ebml_read_binary(matroska, &id, &data, &size); + if (res == 0) + res = matroska_parse_block(matroska, data, size, pos, + cluster_time, AV_NOPTS_VALUE, + -1, 0); + break; + + default: + av_log(matroska->ctx, AV_LOG_INFO, + "Unknown entry 0x%x in cluster data\n", id); + /* fall-through */ + + case EBML_ID_VOID: + res = ebml_read_skip(matroska); + break; + } + + if (matroska->level_up) { + matroska->level_up--; + break; + } + } + + return res; +} + +static int +matroska_read_packet (AVFormatContext *s, + AVPacket *pkt) +{ + MatroskaDemuxContext *matroska = s->priv_data; + int res; + uint32_t id; + + /* Read stream until we have a packet queued. */ + while (matroska_deliver_packet(matroska, pkt)) { + + /* Have we already reached the end? */ + if (matroska->done) + return AVERROR(EIO); + + res = 0; + while (res == 0) { + if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { + return AVERROR(EIO); + } else if (matroska->level_up) { + matroska->level_up--; + break; + } + + switch (id) { + case MATROSKA_ID_CLUSTER: + if ((res = ebml_read_master(matroska, &id)) < 0) + break; + if ((res = matroska_parse_cluster(matroska)) == 0) + res = 1; /* Parsed one cluster, let's get out. */ + break; + + default: + case EBML_ID_VOID: + res = ebml_read_skip(matroska); + break; + } + + if (matroska->level_up) { + matroska->level_up--; + break; + } + } + + if (res == -1) + matroska->done = 1; + } + + return 0; +} + +static int +matroska_read_seek (AVFormatContext *s, int stream_index, int64_t timestamp, + int flags) +{ + MatroskaDemuxContext *matroska = s->priv_data; + AVStream *st = s->streams[stream_index]; + int index; + + /* find index entry */ + index = av_index_search_timestamp(st, timestamp, flags); + if (index < 0) + return 0; + + matroska_clear_queue(matroska); + + /* do the seek */ + url_fseek(s->pb, st->index_entries[index].pos, SEEK_SET); + matroska->skip_to_keyframe = !(flags & AVSEEK_FLAG_ANY); + matroska->skip_to_stream = st; + matroska->peek_id = 0; + return 0; +} + +static int +matroska_read_close (AVFormatContext *s) +{ + MatroskaDemuxContext *matroska = s->priv_data; + int n = 0; + + av_free(matroska->writing_app); + av_free(matroska->muxing_app); + av_free(matroska->index); + + matroska_clear_queue(matroska); + + for (n = 0; n < matroska->num_tracks; n++) { + MatroskaTrack *track = matroska->tracks[n]; + av_free(track->codec_id); + av_free(track->codec_name); + av_free(track->codec_priv); + av_free(track->name); + + if (track->type == MATROSKA_TRACK_TYPE_AUDIO) { + MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)track; + av_free(audiotrack->buf); + } + + av_free(track); + } + + return 0; +} + +AVInputFormat matroska_demuxer = { + "matroska", + "Matroska file format", + sizeof(MatroskaDemuxContext), + matroska_probe, + matroska_read_header, + matroska_read_packet, + matroska_read_close, + matroska_read_seek, +}; diff --git a/contrib/ffmpeg/libavformat/matroskaenc.c b/contrib/ffmpeg/libavformat/matroskaenc.c new file mode 100644 index 000000000..d096f7204 --- /dev/null +++ b/contrib/ffmpeg/libavformat/matroskaenc.c @@ -0,0 +1,845 @@ +/* + * Matroska muxer + * Copyright (c) 2007 David Conrad + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" +#include "md5.h" +#include "riff.h" +#include "xiph.h" +#include "matroska.h" +#include "avc.h" + +typedef struct ebml_master { + offset_t pos; ///< absolute offset in the file where the master's elements start + int sizebytes; ///< how many bytes were reserved for the size +} ebml_master; + +typedef struct mkv_seekhead_entry { + unsigned int elementid; + uint64_t segmentpos; +} mkv_seekhead_entry; + +typedef struct mkv_seekhead { + offset_t filepos; + offset_t segment_offset; ///< the file offset to the beginning of the segment + int reserved_size; ///< -1 if appending to file + int max_entries; + mkv_seekhead_entry *entries; + int num_entries; +} mkv_seekhead; + +typedef struct { + uint64_t pts; + int tracknum; + offset_t cluster_pos; ///< file offset of the cluster containing the block +} mkv_cuepoint; + +typedef struct { + offset_t segment_offset; + mkv_cuepoint *entries; + int num_entries; +} mkv_cues; + +typedef struct MatroskaMuxContext { + ebml_master segment; + offset_t segment_offset; + offset_t segment_uid; + ebml_master cluster; + offset_t cluster_pos; ///< file offset of the current cluster + uint64_t cluster_pts; + offset_t duration_offset; + uint64_t duration; + mkv_seekhead *main_seekhead; + mkv_seekhead *cluster_seekhead; + mkv_cues *cues; + + struct AVMD5 *md5_ctx; +} MatroskaMuxContext; + + +/** 2 bytes * 3 for EBML IDs, 3 1-byte EBML lengths, 8 bytes for 64 bit + * offset, 4 bytes for target EBML ID */ +#define MAX_SEEKENTRY_SIZE 21 + +/** per-cuepoint-track - 3 1-byte EBML IDs, 3 1-byte EBML sizes, 2 + * 8-byte uint max */ +#define MAX_CUETRACKPOS_SIZE 22 + +/** per-cuepoint - 2 1-byte EBML IDs, 2 1-byte EBML sizes, 8-byte uint max */ +#define MAX_CUEPOINT_SIZE(num_tracks) 12 + MAX_CUETRACKPOS_SIZE*num_tracks + + +static int ebml_id_size(unsigned int id) +{ + return (av_log2(id+1)-1)/7+1; +} + +static void put_ebml_id(ByteIOContext *pb, unsigned int id) +{ + int i = ebml_id_size(id); + while (i--) + put_byte(pb, id >> (i*8)); +} + +/** + * Write an EBML size meaning "unknown size". + * + * @param bytes The number of bytes the size should occupy (maximum: 8). + */ +static void put_ebml_size_unknown(ByteIOContext *pb, int bytes) +{ + assert(bytes <= 8); + put_byte(pb, 0x1ff >> bytes); + while (--bytes) + put_byte(pb, 0xff); +} + +/** + * Calculate how many bytes are needed to represent a given number in EBML. + */ +static int ebml_num_size(uint64_t num) +{ + int bytes = 1; + while ((num+1) >> bytes*7) bytes++; + return bytes; +} + +/** + * Write a number in EBML variable length format. + * + * @param bytes The number of bytes that need to be used to write the number. + * If zero, any number of bytes can be used. + */ +static void put_ebml_num(ByteIOContext *pb, uint64_t num, int bytes) +{ + int i, needed_bytes = ebml_num_size(num); + + // sizes larger than this are currently undefined in EBML + assert(num < (1ULL<<56)-1); + + if (bytes == 0) + // don't care how many bytes are used, so use the min + bytes = needed_bytes; + // the bytes needed to write the given size would exceed the bytes + // that we need to use, so write unknown size. This shouldn't happen. + assert(bytes >= needed_bytes); + + num |= 1ULL << bytes*7; + for (i = bytes - 1; i >= 0; i--) + put_byte(pb, num >> i*8); +} + +static void put_ebml_uint(ByteIOContext *pb, unsigned int elementid, uint64_t val) +{ + int i, bytes = 1; + uint64_t tmp = val; + while (tmp>>=8) bytes++; + + put_ebml_id(pb, elementid); + put_ebml_num(pb, bytes, 0); + for (i = bytes - 1; i >= 0; i--) + put_byte(pb, val >> i*8); +} + +static void put_ebml_float(ByteIOContext *pb, unsigned int elementid, double val) +{ + put_ebml_id(pb, elementid); + put_ebml_num(pb, 8, 0); + put_be64(pb, av_dbl2int(val)); +} + +static void put_ebml_binary(ByteIOContext *pb, unsigned int elementid, + const uint8_t *buf, int size) +{ + put_ebml_id(pb, elementid); + put_ebml_num(pb, size, 0); + put_buffer(pb, buf, size); +} + +static void put_ebml_string(ByteIOContext *pb, unsigned int elementid, const char *str) +{ + put_ebml_binary(pb, elementid, str, strlen(str)); +} + +/** + * Writes a void element of a given size. Useful for reserving space in + * the file to be written to later. + * + * @param size The number of bytes to reserve, which must be at least 2. + */ +static void put_ebml_void(ByteIOContext *pb, uint64_t size) +{ + offset_t currentpos = url_ftell(pb); + + assert(size >= 2); + + put_ebml_id(pb, EBML_ID_VOID); + // we need to subtract the length needed to store the size from the + // size we need to reserve so 2 cases, we use 8 bytes to store the + // size if possible, 1 byte otherwise + if (size < 10) + put_ebml_num(pb, size-1, 0); + else + put_ebml_num(pb, size-9, 8); + while(url_ftell(pb) < currentpos + size) + put_byte(pb, 0); +} + +static ebml_master start_ebml_master(ByteIOContext *pb, unsigned int elementid, uint64_t expectedsize) +{ + int bytes = expectedsize ? ebml_num_size(expectedsize) : 8; + put_ebml_id(pb, elementid); + put_ebml_size_unknown(pb, bytes); + return (ebml_master){ url_ftell(pb), bytes }; +} + +static void end_ebml_master(ByteIOContext *pb, ebml_master master) +{ + offset_t pos = url_ftell(pb); + + // leave the unknown size for masters when streaming + if (url_is_streamed(pb)) + return; + + url_fseek(pb, master.pos - master.sizebytes, SEEK_SET); + put_ebml_num(pb, pos - master.pos, master.sizebytes); + url_fseek(pb, pos, SEEK_SET); +} + +static void put_xiph_size(ByteIOContext *pb, int size) +{ + int i; + for (i = 0; i < size / 255; i++) + put_byte(pb, 255); + put_byte(pb, size % 255); +} + +/** + * Initialize a mkv_seekhead element to be ready to index level 1 Matroska + * elements. If a maximum number of elements is specified, enough space + * will be reserved at the current file location to write a seek head of + * that size. + * + * @param segment_offset The absolute offset to the position in the file + * where the segment begins. + * @param numelements The maximum number of elements that will be indexed + * by this seek head, 0 if unlimited. + */ +static mkv_seekhead * mkv_start_seekhead(ByteIOContext *pb, offset_t segment_offset, int numelements) +{ + mkv_seekhead *new_seekhead = av_mallocz(sizeof(mkv_seekhead)); + if (new_seekhead == NULL) + return NULL; + + new_seekhead->segment_offset = segment_offset; + + if (numelements > 0) { + new_seekhead->filepos = url_ftell(pb); + // 21 bytes max for a seek entry, 10 bytes max for the SeekHead ID + // and size, and 3 bytes to guarantee that an EBML void element + // will fit afterwards + new_seekhead->reserved_size = numelements * MAX_SEEKENTRY_SIZE + 13; + new_seekhead->max_entries = numelements; + put_ebml_void(pb, new_seekhead->reserved_size); + } + return new_seekhead; +} + +static int mkv_add_seekhead_entry(mkv_seekhead *seekhead, unsigned int elementid, uint64_t filepos) +{ + mkv_seekhead_entry *entries = seekhead->entries; + + // don't store more elements than we reserved space for + if (seekhead->max_entries > 0 && seekhead->max_entries <= seekhead->num_entries) + return -1; + + entries = av_realloc(entries, (seekhead->num_entries + 1) * sizeof(mkv_seekhead_entry)); + if (entries == NULL) + return AVERROR(ENOMEM); + + entries[seekhead->num_entries ].elementid = elementid; + entries[seekhead->num_entries++].segmentpos = filepos - seekhead->segment_offset; + + seekhead->entries = entries; + return 0; +} + +/** + * Write the seek head to the file and free it. If a maximum number of + * elements was specified to mkv_start_seekhead(), the seek head will + * be written at the location reserved for it. Otherwise, it is written + * at the current location in the file. + * + * @return The file offset where the seekhead was written. + */ +static offset_t mkv_write_seekhead(ByteIOContext *pb, mkv_seekhead *seekhead) +{ + ebml_master metaseek, seekentry; + offset_t currentpos; + int i; + + currentpos = url_ftell(pb); + + if (seekhead->reserved_size > 0) + url_fseek(pb, seekhead->filepos, SEEK_SET); + + metaseek = start_ebml_master(pb, MATROSKA_ID_SEEKHEAD, seekhead->reserved_size); + for (i = 0; i < seekhead->num_entries; i++) { + mkv_seekhead_entry *entry = &seekhead->entries[i]; + + seekentry = start_ebml_master(pb, MATROSKA_ID_SEEKENTRY, MAX_SEEKENTRY_SIZE); + + put_ebml_id(pb, MATROSKA_ID_SEEKID); + put_ebml_num(pb, ebml_id_size(entry->elementid), 0); + put_ebml_id(pb, entry->elementid); + + put_ebml_uint(pb, MATROSKA_ID_SEEKPOSITION, entry->segmentpos); + end_ebml_master(pb, seekentry); + } + end_ebml_master(pb, metaseek); + + if (seekhead->reserved_size > 0) { + uint64_t remaining = seekhead->filepos + seekhead->reserved_size - url_ftell(pb); + put_ebml_void(pb, remaining); + url_fseek(pb, currentpos, SEEK_SET); + + currentpos = seekhead->filepos; + } + av_free(seekhead->entries); + av_free(seekhead); + + return currentpos; +} + +static mkv_cues * mkv_start_cues(offset_t segment_offset) +{ + mkv_cues *cues = av_mallocz(sizeof(mkv_cues)); + if (cues == NULL) + return NULL; + + cues->segment_offset = segment_offset; + return cues; +} + +static int mkv_add_cuepoint(mkv_cues *cues, AVPacket *pkt, offset_t cluster_pos) +{ + mkv_cuepoint *entries = cues->entries; + + entries = av_realloc(entries, (cues->num_entries + 1) * sizeof(mkv_cuepoint)); + if (entries == NULL) + return AVERROR(ENOMEM); + + entries[cues->num_entries ].pts = pkt->pts; + entries[cues->num_entries ].tracknum = pkt->stream_index + 1; + entries[cues->num_entries++].cluster_pos = cluster_pos - cues->segment_offset; + + cues->entries = entries; + return 0; +} + +static offset_t mkv_write_cues(ByteIOContext *pb, mkv_cues *cues, int num_tracks) +{ + ebml_master cues_element; + offset_t currentpos; + int i, j; + + currentpos = url_ftell(pb); + cues_element = start_ebml_master(pb, MATROSKA_ID_CUES, 0); + + for (i = 0; i < cues->num_entries; i++) { + ebml_master cuepoint, track_positions; + mkv_cuepoint *entry = &cues->entries[i]; + uint64_t pts = entry->pts; + + cuepoint = start_ebml_master(pb, MATROSKA_ID_POINTENTRY, MAX_CUEPOINT_SIZE(num_tracks)); + put_ebml_uint(pb, MATROSKA_ID_CUETIME, pts); + + // put all the entries from different tracks that have the exact same + // timestamp into the same CuePoint + for (j = 0; j < cues->num_entries - i && entry[j].pts == pts; j++) { + track_positions = start_ebml_master(pb, MATROSKA_ID_CUETRACKPOSITION, MAX_CUETRACKPOS_SIZE); + put_ebml_uint(pb, MATROSKA_ID_CUETRACK , entry[j].tracknum ); + put_ebml_uint(pb, MATROSKA_ID_CUECLUSTERPOSITION, entry[j].cluster_pos); + end_ebml_master(pb, track_positions); + } + i += j - 1; + end_ebml_master(pb, cuepoint); + } + end_ebml_master(pb, cues_element); + + av_free(cues->entries); + av_free(cues); + return currentpos; +} + +static int put_xiph_codecpriv(AVFormatContext *s, ByteIOContext *pb, AVCodecContext *codec) +{ + uint8_t *header_start[3]; + int header_len[3]; + int first_header_size; + int j; + + if (codec->codec_id == CODEC_ID_VORBIS) + first_header_size = 30; + else + first_header_size = 42; + + if (ff_split_xiph_headers(codec->extradata, codec->extradata_size, + first_header_size, header_start, header_len) < 0) { + av_log(s, AV_LOG_ERROR, "Extradata corrupt.\n"); + return -1; + } + + put_byte(pb, 2); // number packets - 1 + for (j = 0; j < 2; j++) { + put_xiph_size(pb, header_len[j]); + } + for (j = 0; j < 3; j++) + put_buffer(pb, header_start[j], header_len[j]); + + return 0; +} + +#define FLAC_STREAMINFO_SIZE 34 + +static int put_flac_codecpriv(AVFormatContext *s, ByteIOContext *pb, AVCodecContext *codec) +{ + // if the extradata_size is greater than FLAC_STREAMINFO_SIZE, + // assume that it's in Matroska's format already + if (codec->extradata_size < FLAC_STREAMINFO_SIZE) { + av_log(s, AV_LOG_ERROR, "Invalid FLAC extradata\n"); + return -1; + } else if (codec->extradata_size == FLAC_STREAMINFO_SIZE) { + // only the streaminfo packet + put_byte(pb, 0); + put_xiph_size(pb, codec->extradata_size); + av_log(s, AV_LOG_ERROR, "Only one packet\n"); + } + put_buffer(pb, codec->extradata, codec->extradata_size); + return 0; +} + +static void get_aac_sample_rates(AVFormatContext *s, AVCodecContext *codec, int *sample_rate, int *output_sample_rate) +{ + static const int aac_sample_rates[] = { + 96000, 88200, 64000, 48000, 44100, 32000, + 24000, 22050, 16000, 12000, 11025, 8000, + }; + int sri; + + if (codec->extradata_size < 2) { + av_log(s, AV_LOG_WARNING, "No AAC extradata, unable to determine samplerate.\n"); + return; + } + + sri = ((codec->extradata[0] << 1) & 0xE) | (codec->extradata[1] >> 7); + if (sri > 12) { + av_log(s, AV_LOG_WARNING, "AAC samplerate index out of bounds\n"); + return; + } + *sample_rate = aac_sample_rates[sri]; + + // if sbr, get output sample rate as well + if (codec->extradata_size == 5) { + sri = (codec->extradata[4] >> 3) & 0xF; + if (sri > 12) { + av_log(s, AV_LOG_WARNING, "AAC output samplerate index out of bounds\n"); + return; + } + *output_sample_rate = aac_sample_rates[sri]; + } +} + +static int mkv_write_codecprivate(AVFormatContext *s, ByteIOContext *pb, AVCodecContext *codec, int native_id) +{ + ByteIOContext *dyn_cp; + uint8_t *codecpriv; + int ret, codecpriv_size; + + ret = url_open_dyn_buf(&dyn_cp); + if(ret < 0) + return ret; + + if (native_id) { + if (codec->codec_id == CODEC_ID_VORBIS || codec->codec_id == CODEC_ID_THEORA) + ret = put_xiph_codecpriv(s, dyn_cp, codec); + else if (codec->codec_id == CODEC_ID_FLAC) + ret = put_flac_codecpriv(s, dyn_cp, codec); + else if (codec->codec_id == CODEC_ID_H264) + ret = ff_isom_write_avcc(dyn_cp, codec->extradata, codec->extradata_size); + else if (codec->extradata_size) + put_buffer(dyn_cp, codec->extradata, codec->extradata_size); + } else if (codec->codec_type == CODEC_TYPE_VIDEO) { + if (!codec->codec_tag) + codec->codec_tag = codec_get_tag(codec_bmp_tags, codec->codec_id); + if (!codec->codec_tag) { + av_log(s, AV_LOG_ERROR, "No bmp codec ID found."); + ret = -1; + } + + put_bmp_header(dyn_cp, codec, codec_bmp_tags, 0); + + } else if (codec->codec_type == CODEC_TYPE_AUDIO) { + if (!codec->codec_tag) + codec->codec_tag = codec_get_tag(codec_wav_tags, codec->codec_id); + if (!codec->codec_tag) { + av_log(s, AV_LOG_ERROR, "No wav codec ID found."); + ret = -1; + } + + put_wav_header(dyn_cp, codec); + } + + codecpriv_size = url_close_dyn_buf(dyn_cp, &codecpriv); + if (codecpriv_size) + put_ebml_binary(pb, MATROSKA_ID_CODECPRIVATE, codecpriv, codecpriv_size); + av_free(codecpriv); + return ret; +} + +static int mkv_write_tracks(AVFormatContext *s) +{ + MatroskaMuxContext *mkv = s->priv_data; + ByteIOContext *pb = s->pb; + ebml_master tracks; + int i, j, ret; + + ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_TRACKS, url_ftell(pb)); + if (ret < 0) return ret; + + tracks = start_ebml_master(pb, MATROSKA_ID_TRACKS, 0); + for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; + AVCodecContext *codec = st->codec; + ebml_master subinfo, track; + int native_id = 0; + int bit_depth = av_get_bits_per_sample(codec->codec_id); + int sample_rate = codec->sample_rate; + int output_sample_rate = 0; + + if (!bit_depth) + bit_depth = av_get_bits_per_sample_format(codec->sample_fmt); + + if (codec->codec_id == CODEC_ID_AAC) + get_aac_sample_rates(s, codec, &sample_rate, &output_sample_rate); + + track = start_ebml_master(pb, MATROSKA_ID_TRACKENTRY, 0); + put_ebml_uint (pb, MATROSKA_ID_TRACKNUMBER , i + 1); + put_ebml_uint (pb, MATROSKA_ID_TRACKUID , i + 1); + put_ebml_uint (pb, MATROSKA_ID_TRACKFLAGLACING , 0); // no lacing (yet) + + if (st->language[0]) + put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, st->language); + else + put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, "und"); + + // look for a codec ID string specific to mkv to use, + // if none are found, use AVI codes + for (j = 0; ff_mkv_codec_tags[j].id != CODEC_ID_NONE; j++) { + if (ff_mkv_codec_tags[j].id == codec->codec_id) { + put_ebml_string(pb, MATROSKA_ID_CODECID, ff_mkv_codec_tags[j].str); + native_id = 1; + break; + } + } + + switch (codec->codec_type) { + case CODEC_TYPE_VIDEO: + put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_VIDEO); + + if (!native_id) + // if there is no mkv-specific codec ID, use VFW mode + put_ebml_string(pb, MATROSKA_ID_CODECID, MATROSKA_CODEC_ID_VIDEO_VFW_FOURCC); + + subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKVIDEO, 0); + // XXX: interlace flag? + put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELWIDTH , codec->width); + put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELHEIGHT, codec->height); + if (codec->sample_aspect_ratio.num) { + AVRational dar = av_mul_q(codec->sample_aspect_ratio, + (AVRational){codec->width, codec->height}); + put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , dar.num); + put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, dar.den); + } + end_ebml_master(pb, subinfo); + break; + + case CODEC_TYPE_AUDIO: + put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_AUDIO); + + if (!native_id) + // no mkv-specific ID, use ACM mode + put_ebml_string(pb, MATROSKA_ID_CODECID, MATROSKA_CODEC_ID_AUDIO_ACM); + + subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKAUDIO, 0); + put_ebml_uint (pb, MATROSKA_ID_AUDIOCHANNELS , codec->channels); + put_ebml_float (pb, MATROSKA_ID_AUDIOSAMPLINGFREQ, sample_rate); + if (output_sample_rate) + put_ebml_float(pb, MATROSKA_ID_AUDIOOUTSAMPLINGFREQ, output_sample_rate); + if (bit_depth) + put_ebml_uint(pb, MATROSKA_ID_AUDIOBITDEPTH, bit_depth); + end_ebml_master(pb, subinfo); + break; + + case CODEC_TYPE_SUBTITLE: + put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_SUBTITLE); + break; + default: + av_log(s, AV_LOG_ERROR, "Only audio, video, and subtitles are supported for Matroska."); + break; + } + ret = mkv_write_codecprivate(s, pb, codec, native_id); + if (ret < 0) return ret; + + end_ebml_master(pb, track); + + // ms precision is the de-facto standard timescale for mkv files + av_set_pts_info(st, 64, 1, 1000); + } + end_ebml_master(pb, tracks); + return 0; +} + +static int mkv_write_header(AVFormatContext *s) +{ + MatroskaMuxContext *mkv = s->priv_data; + ByteIOContext *pb = s->pb; + ebml_master ebml_header, segment_info; + int ret; + + mkv->md5_ctx = av_mallocz(av_md5_size); + av_md5_init(mkv->md5_ctx); + + ebml_header = start_ebml_master(pb, EBML_ID_HEADER, 0); + put_ebml_uint (pb, EBML_ID_EBMLVERSION , 1); + put_ebml_uint (pb, EBML_ID_EBMLREADVERSION , 1); + put_ebml_uint (pb, EBML_ID_EBMLMAXIDLENGTH , 4); + put_ebml_uint (pb, EBML_ID_EBMLMAXSIZELENGTH , 8); + put_ebml_string (pb, EBML_ID_DOCTYPE , "matroska"); + put_ebml_uint (pb, EBML_ID_DOCTYPEVERSION , 2); + put_ebml_uint (pb, EBML_ID_DOCTYPEREADVERSION , 2); + end_ebml_master(pb, ebml_header); + + mkv->segment = start_ebml_master(pb, MATROSKA_ID_SEGMENT, 0); + mkv->segment_offset = url_ftell(pb); + + // we write 2 seek heads - one at the end of the file to point to each + // cluster, and one at the beginning to point to all other level one + // elements (including the seek head at the end of the file), which + // isn't more than 10 elements if we only write one of each other + // currently defined level 1 element + mkv->main_seekhead = mkv_start_seekhead(pb, mkv->segment_offset, 10); + mkv->cluster_seekhead = mkv_start_seekhead(pb, mkv->segment_offset, 0); + if (mkv->main_seekhead == NULL || mkv->cluster_seekhead == NULL) + return AVERROR(ENOMEM); + + ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_INFO, url_ftell(pb)); + if (ret < 0) return ret; + + segment_info = start_ebml_master(pb, MATROSKA_ID_INFO, 0); + put_ebml_uint(pb, MATROSKA_ID_TIMECODESCALE, 1000000); + if (strlen(s->title)) + put_ebml_string(pb, MATROSKA_ID_TITLE, s->title); + if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) { + put_ebml_string(pb, MATROSKA_ID_MUXINGAPP , LIBAVFORMAT_IDENT); + put_ebml_string(pb, MATROSKA_ID_WRITINGAPP, LIBAVFORMAT_IDENT); + + // reserve space to write the segment UID later + mkv->segment_uid = url_ftell(pb); + put_ebml_void(pb, 19); + } + + // reserve space for the duration + mkv->duration = 0; + mkv->duration_offset = url_ftell(pb); + put_ebml_void(pb, 11); // assumes double-precision float to be written + end_ebml_master(pb, segment_info); + + ret = mkv_write_tracks(s); + if (ret < 0) return ret; + + ret = mkv_add_seekhead_entry(mkv->cluster_seekhead, MATROSKA_ID_CLUSTER, url_ftell(pb)); + if (ret < 0) return ret; + + mkv->cluster_pos = url_ftell(pb); + mkv->cluster = start_ebml_master(pb, MATROSKA_ID_CLUSTER, 0); + put_ebml_uint(pb, MATROSKA_ID_CLUSTERTIMECODE, 0); + mkv->cluster_pts = 0; + + mkv->cues = mkv_start_cues(mkv->segment_offset); + if (mkv->cues == NULL) + return AVERROR(ENOMEM); + + return 0; +} + +static int mkv_block_size(AVPacket *pkt) +{ + int size = 4; // track num + timecode + flags + return size + pkt->size; +} + +static int mkv_blockgroup_size(AVPacket *pkt) +{ + int size = mkv_block_size(pkt); + size += ebml_num_size(size); + size += 2; // EBML ID for block and block duration + size += 8; // max size of block duration + size += ebml_num_size(size); + size += 1; // blockgroup EBML ID + return size; +} + +static void mkv_write_block(AVFormatContext *s, unsigned int blockid, AVPacket *pkt, int flags) +{ + MatroskaMuxContext *mkv = s->priv_data; + ByteIOContext *pb = s->pb; + + av_log(s, AV_LOG_DEBUG, "Writing block at offset %" PRIu64 ", size %d, " + "pts %" PRId64 ", dts %" PRId64 ", duration %d, flags %d\n", + url_ftell(pb), pkt->size, pkt->pts, pkt->dts, pkt->duration, flags); + put_ebml_id(pb, blockid); + put_ebml_num(pb, mkv_block_size(pkt), 0); + put_byte(pb, 0x80 | (pkt->stream_index + 1)); // this assumes stream_index is less than 126 + put_be16(pb, pkt->pts - mkv->cluster_pts); + put_byte(pb, flags); + put_buffer(pb, pkt->data, pkt->size); +} + +static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) +{ + MatroskaMuxContext *mkv = s->priv_data; + ByteIOContext *pb = s->pb; + AVCodecContext *codec = s->streams[pkt->stream_index]->codec; + int keyframe = !!(pkt->flags & PKT_FLAG_KEY); + int ret; + + // start a new cluster every 5 MB or 5 sec + if (url_ftell(pb) > mkv->cluster_pos + 5*1024*1024 || pkt->pts > mkv->cluster_pts + 5000) { + av_log(s, AV_LOG_DEBUG, "Starting new cluster at offset %" PRIu64 + " bytes, pts %" PRIu64 "\n", url_ftell(pb), pkt->pts); + end_ebml_master(pb, mkv->cluster); + + ret = mkv_add_seekhead_entry(mkv->cluster_seekhead, MATROSKA_ID_CLUSTER, url_ftell(pb)); + if (ret < 0) return ret; + + mkv->cluster_pos = url_ftell(pb); + mkv->cluster = start_ebml_master(pb, MATROSKA_ID_CLUSTER, 0); + put_ebml_uint(pb, MATROSKA_ID_CLUSTERTIMECODE, pkt->pts); + mkv->cluster_pts = pkt->pts; + av_md5_update(mkv->md5_ctx, pkt->data, FFMIN(200, pkt->size)); + } + + if (codec->codec_id == CODEC_ID_H264 && + codec->extradata_size > 0 && AV_RB32(codec->extradata) == 0x00000001) { + /* from x264 or from bytestream h264 */ + /* nal reformating needed */ + int ret = ff_avc_parse_nal_units(pkt->data, &pkt->data, &pkt->size); + if (ret < 0) + return ret; + assert(pkt->size); + } + + if (codec->codec_type != CODEC_TYPE_SUBTITLE) { + mkv_write_block(s, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe << 7); + } else { + ebml_master blockgroup = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP, mkv_blockgroup_size(pkt)); + mkv_write_block(s, MATROSKA_ID_BLOCK, pkt, 0); + put_ebml_uint(pb, MATROSKA_ID_DURATION, pkt->duration); + end_ebml_master(pb, blockgroup); + } + + if (codec->codec_type == CODEC_TYPE_VIDEO && keyframe) { + ret = mkv_add_cuepoint(mkv->cues, pkt, mkv->cluster_pos); + if (ret < 0) return ret; + } + + mkv->duration = FFMAX(mkv->duration, pkt->pts + pkt->duration); + return 0; +} + +static int mkv_write_trailer(AVFormatContext *s) +{ + MatroskaMuxContext *mkv = s->priv_data; + ByteIOContext *pb = s->pb; + offset_t currentpos, second_seekhead, cuespos; + int ret; + + end_ebml_master(pb, mkv->cluster); + + if (!url_is_streamed(pb)) { + cuespos = mkv_write_cues(pb, mkv->cues, s->nb_streams); + second_seekhead = mkv_write_seekhead(pb, mkv->cluster_seekhead); + + ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CUES , cuespos); + if (ret < 0) return ret; + ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_SEEKHEAD, second_seekhead); + if (ret < 0) return ret; + mkv_write_seekhead(pb, mkv->main_seekhead); + + // update the duration + av_log(s, AV_LOG_DEBUG, "end duration = %" PRIu64 "\n", mkv->duration); + currentpos = url_ftell(pb); + url_fseek(pb, mkv->duration_offset, SEEK_SET); + put_ebml_float(pb, MATROSKA_ID_DURATION, mkv->duration); + + // write the md5sum of some frames as the segment UID + if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) { + uint8_t segment_uid[16]; + av_md5_final(mkv->md5_ctx, segment_uid); + url_fseek(pb, mkv->segment_uid, SEEK_SET); + put_ebml_binary(pb, MATROSKA_ID_SEGMENTUID, segment_uid, 16); + } + url_fseek(pb, currentpos, SEEK_SET); + } + + end_ebml_master(pb, mkv->segment); + av_free(mkv->md5_ctx); + return 0; +} + +AVOutputFormat matroska_muxer = { + "matroska", + "Matroska File Format", + "video/x-matroska", + "mkv", + sizeof(MatroskaMuxContext), + CODEC_ID_MP2, + CODEC_ID_MPEG4, + mkv_write_header, + mkv_write_packet, + mkv_write_trailer, + .codec_tag = (const AVCodecTag*[]){codec_bmp_tags, codec_wav_tags, 0}, + .subtitle_codec = CODEC_ID_TEXT, +}; + +AVOutputFormat matroska_audio_muxer = { + "matroska", + "Matroska File Format", + "audio/x-matroska", + "mka", + sizeof(MatroskaMuxContext), + CODEC_ID_MP2, + CODEC_ID_NONE, + mkv_write_header, + mkv_write_packet, + mkv_write_trailer, + .codec_tag = (const AVCodecTag*[]){codec_wav_tags, 0}, +}; diff --git a/contrib/ffmpeg/libavformat/mm.c b/contrib/ffmpeg/libavformat/mm.c index 443b70929..4e6bac027 100644 --- a/contrib/ffmpeg/libavformat/mm.c +++ b/contrib/ffmpeg/libavformat/mm.c @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** @@ -59,8 +59,6 @@ typedef struct { static int mm_probe(AVProbeData *p) { /* the first chunk is always the header */ - if (p->buf_size < MM_PREAMBLE_SIZE) - return 0; if (AV_RL16(&p->buf[0]) != MM_TYPE_HEADER) return 0; if (AV_RL32(&p->buf[2]) != MM_HEADER_LEN_V && AV_RL32(&p->buf[2]) != MM_HEADER_LEN_AV) @@ -73,8 +71,8 @@ static int mm_probe(AVProbeData *p) static int mm_read_header(AVFormatContext *s, AVFormatParameters *ap) { - MmDemuxContext *mm = (MmDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + MmDemuxContext *mm = s->priv_data; + ByteIOContext *pb = s->pb; AVStream *st; unsigned int type, length; @@ -97,7 +95,7 @@ static int mm_read_header(AVFormatContext *s, /* video stream */ st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = CODEC_ID_MMVIDEO; st->codec->codec_tag = 0; /* no fourcc */ @@ -110,7 +108,7 @@ static int mm_read_header(AVFormatContext *s, if (length == MM_HEADER_LEN_AV) { st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_tag = 0; /* no fourcc */ st->codec->codec_id = CODEC_ID_PCM_U8; @@ -128,8 +126,8 @@ static int mm_read_header(AVFormatContext *s, static int mm_read_packet(AVFormatContext *s, AVPacket *pkt) { - MmDemuxContext *mm = (MmDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + MmDemuxContext *mm = s->priv_data; + ByteIOContext *pb = s->pb; unsigned char preamble[MM_PREAMBLE_SIZE]; unsigned char pal[MM_PALETTE_SIZE]; unsigned int type, length; @@ -138,7 +136,7 @@ static int mm_read_packet(AVFormatContext *s, while(1) { if (get_buffer(pb, preamble, MM_PREAMBLE_SIZE) != MM_PREAMBLE_SIZE) { - return AVERROR_IO; + return AVERROR(EIO); } type = AV_RL16(&preamble[0]); @@ -148,7 +146,7 @@ static int mm_read_packet(AVFormatContext *s, case MM_TYPE_PALETTE : url_fseek(pb, 4, SEEK_CUR); /* unknown data */ if (get_buffer(pb, pal, MM_PALETTE_SIZE) != MM_PALETTE_SIZE) - return AVERROR_IO; + return AVERROR(EIO); url_fseek(pb, length - (4 + MM_PALETTE_SIZE), SEEK_CUR); for (i=0; idata, preamble, MM_PREAMBLE_SIZE); if (get_buffer(pb, pkt->data + MM_PREAMBLE_SIZE, length) != length) - return AVERROR_IO; + return AVERROR(EIO); pkt->size = length + MM_PREAMBLE_SIZE; pkt->stream_index = 0; pkt->pts = mm->video_pts++; return 0; case MM_TYPE_AUDIO : - if (av_get_packet(&s->pb, pkt, length)<0) - return AVERROR_NOMEM; + if (av_get_packet(s->pb, pkt, length)<0) + return AVERROR(ENOMEM); pkt->size = length; pkt->stream_index = 1; pkt->pts = mm->audio_pts++; diff --git a/contrib/ffmpeg/libavformat/mmf.c b/contrib/ffmpeg/libavformat/mmf.c index 40b1a497c..84c21a01d 100644 --- a/contrib/ffmpeg/libavformat/mmf.c +++ b/contrib/ffmpeg/libavformat/mmf.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avformat.h" -#include "allformats.h" +#include "raw.h" #include "riff.h" typedef struct { @@ -60,7 +60,7 @@ static void end_tag_be(ByteIOContext *pb, offset_t start) static int mmf_write_header(AVFormatContext *s) { MMFContext *mmf = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; offset_t pos; int rate; @@ -108,7 +108,7 @@ static int mmf_write_header(AVFormatContext *s) static int mmf_write_packet(AVFormatContext *s, AVPacket *pkt) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; put_buffer(pb, pkt->data, pkt->size); return 0; } @@ -127,12 +127,12 @@ static void put_varlength(ByteIOContext *pb, int val) static int mmf_write_trailer(AVFormatContext *s) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; MMFContext *mmf = s->priv_data; offset_t pos, size; int gatetime; - if (!url_is_streamed(&s->pb)) { + if (!url_is_streamed(s->pb)) { /* Fill in length fields */ end_tag_be(pb, mmf->awapos); end_tag_be(pb, mmf->atrpos); @@ -168,8 +168,6 @@ static int mmf_write_trailer(AVFormatContext *s) static int mmf_probe(AVProbeData *p) { /* check file header */ - if (p->buf_size <= 32) - return 0; if (p->buf[0] == 'M' && p->buf[1] == 'M' && p->buf[2] == 'M' && p->buf[3] == 'D' && p->buf[8] == 'C' && p->buf[9] == 'N' && @@ -185,7 +183,7 @@ static int mmf_read_header(AVFormatContext *s, { MMFContext *mmf = s->priv_data; unsigned int tag; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVStream *st; offset_t file_size, size; int rate, params; @@ -244,7 +242,7 @@ static int mmf_read_header(AVFormatContext *s, st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_ADPCM_YAMAHA; @@ -267,8 +265,8 @@ static int mmf_read_packet(AVFormatContext *s, AVStream *st; int ret, size; - if (url_feof(&s->pb)) - return AVERROR_IO; + if (url_feof(s->pb)) + return AVERROR(EIO); st = s->streams[0]; size = MAX_SIZE; @@ -276,13 +274,13 @@ static int mmf_read_packet(AVFormatContext *s, size = mmf->data_size; if(!size) - return AVERROR_IO; + return AVERROR(EIO); if (av_new_packet(pkt, size)) - return AVERROR_IO; + return AVERROR(EIO); pkt->stream_index = 0; - ret = get_buffer(&s->pb, pkt->data, pkt->size); + ret = get_buffer(s->pb, pkt->data, pkt->size); if (ret < 0) av_free_packet(pkt); diff --git a/contrib/ffmpeg/libavformat/mov.c b/contrib/ffmpeg/libavformat/mov.c index e9b577576..a67604b0e 100644 --- a/contrib/ffmpeg/libavformat/mov.c +++ b/contrib/ffmpeg/libavformat/mov.c @@ -38,16 +38,8 @@ * * Features and limitations: * - reads most of the QT files I have (at least the structure), - * the exceptions are .mov with zlib compressed headers ('cmov' section). It shouldn't be hard to implement. - * FIXED, Francois Revol, 07/17/2002 - * - ffmpeg has nearly none of the usual QuickTime codecs, - * although I succesfully dumped raw and mp3 audio tracks off .mov files. * Sample QuickTime files with mp3 audio can be found at: http://www.3ivx.com/showcase.html - * - .mp4 parsing is still hazardous, although the format really is QuickTime with some minor changes - * (to make .mov parser crash maybe ?), despite what they say in the MPEG FAQ at - * http://mpeg.telecomitalialab.com/faq.htm * - the code is quite ugly... maybe I won't do it recursive next time :-) - * - seek is not supported with files that contain edit list * * Funny I didn't know about http://sourceforge.net/projects/qt-ffmpeg/ * when coding this :) (it's a writer anyway) @@ -71,11 +63,16 @@ * Here we just use what is needed to read the chunks */ -typedef struct MOV_sample_to_chunk_tbl { - long first; - long count; - long id; -} MOV_sample_to_chunk_tbl; +typedef struct { + int first; + int count; + int id; +} MOV_stsc_t; + +typedef struct { + uint32_t type; + char *path; +} MOV_dref_t; typedef struct { uint32_t type; @@ -83,94 +80,39 @@ typedef struct { int64_t size; /* total size (excluding the size and type fields) */ } MOV_atom_t; -typedef struct { - int seed; - int flags; - int size; - void* clrs; -} MOV_ctab_t; - -typedef struct MOV_mdat_atom_s { - offset_t offset; - int64_t size; -} MOV_mdat_atom_t; - -typedef struct { - uint8_t version; - uint32_t flags; // 24bit - - /* 0x03 ESDescrTag */ - uint16_t es_id; -#define MP4ODescrTag 0x01 -#define MP4IODescrTag 0x02 -#define MP4ESDescrTag 0x03 -#define MP4DecConfigDescrTag 0x04 -#define MP4DecSpecificDescrTag 0x05 -#define MP4SLConfigDescrTag 0x06 -#define MP4ContentIdDescrTag 0x07 -#define MP4SupplContentIdDescrTag 0x08 -#define MP4IPIPtrDescrTag 0x09 -#define MP4IPMPPtrDescrTag 0x0A -#define MP4IPMPDescrTag 0x0B -#define MP4RegistrationDescrTag 0x0D -#define MP4ESIDIncDescrTag 0x0E -#define MP4ESIDRefDescrTag 0x0F -#define MP4FileIODescrTag 0x10 -#define MP4FileODescrTag 0x11 -#define MP4ExtProfileLevelDescrTag 0x13 -#define MP4ExtDescrTagsStart 0x80 -#define MP4ExtDescrTagsEnd 0xFE - uint8_t stream_priority; - - /* 0x04 DecConfigDescrTag */ - uint8_t object_type_id; - uint8_t stream_type; - /* XXX: really streamType is - * only 6bit, followed by: - * 1bit upStream - * 1bit reserved - */ - uint32_t buffer_size_db; // 24 - uint32_t max_bitrate; - uint32_t avg_bitrate; - - /* 0x05 DecSpecificDescrTag */ - uint8_t decoder_cfg_len; - uint8_t *decoder_cfg; - - /* 0x06 SLConfigDescrTag */ - uint8_t sl_config_len; - uint8_t *sl_config; -} MOV_esds_t; - struct MOVParseTableEntry; typedef struct MOVStreamContext { + ByteIOContext *pb; int ffindex; /* the ffmpeg stream id */ - long next_chunk; + int next_chunk; unsigned int chunk_count; int64_t *chunk_offsets; unsigned int stts_count; - Time2Sample *stts_data; + MOV_stts_t *stts_data; unsigned int ctts_count; - Time2Sample *ctts_data; + MOV_stts_t *ctts_data; unsigned int edit_count; /* number of 'edit' (elst atom) */ unsigned int sample_to_chunk_sz; - MOV_sample_to_chunk_tbl *sample_to_chunk; + MOV_stsc_t *sample_to_chunk; int sample_to_ctime_index; int sample_to_ctime_sample; unsigned int sample_size; unsigned int sample_count; - long *sample_sizes; + int *sample_sizes; unsigned int keyframe_count; - long *keyframes; + int *keyframes; int time_scale; int time_rate; - long current_sample; - MOV_esds_t esds; + int current_sample; unsigned int bytes_per_frame; unsigned int samples_per_frame; int dv_audio_container; + int pseudo_stream_id; + int16_t audio_cid; ///< stsd audio compression id + unsigned drefs_count; + MOV_dref_t *drefs; + int dref_id; } MOVStreamContext; typedef struct MOVContext { @@ -179,18 +121,7 @@ typedef struct MOVContext { int64_t duration; /* duration of the longest track */ int found_moov; /* when both 'moov' and 'mdat' sections has been found */ int found_mdat; /* we suppose we have enough data to read the file */ - int64_t mdat_offset; - int total_streams; - MOVStreamContext *streams[MAX_STREAMS]; - - int ctab_size; - MOV_ctab_t **ctab; /* color tables */ - const struct MOVParseTableEntry *parse_table; /* could be eventually used to change the table */ - /* NOTE: for recursion save to/ restore from local variable! */ - AVPaletteControl palette_control; - MOV_mdat_atom_t *mdat_list; - int mdat_count; DVDemuxContext *dv_demux; AVFormatContext *dv_fctx; int isom; /* 1 if file is ISO Media (mp4/3gp) */ @@ -205,14 +136,14 @@ typedef struct MOVContext { 0: continue to parse next atom -1: error occured, exit */ -typedef int (*mov_parse_function)(MOVContext *ctx, ByteIOContext *pb, MOV_atom_t atom); - /* links atom IDs to parse functions */ typedef struct MOVParseTableEntry { uint32_t type; - mov_parse_function func; + int (*parse)(MOVContext *ctx, ByteIOContext *pb, MOV_atom_t atom); } MOVParseTableEntry; +static const MOVParseTableEntry mov_default_parse_table[]; + static int mov_read_default(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { int64_t total_size = 0; @@ -223,17 +154,18 @@ static int mov_read_default(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) a.offset = atom.offset; if (atom.size < 0) - atom.size = 0x7fffffffffffffffLL; + atom.size = INT64_MAX; while(((total_size + 8) < atom.size) && !url_feof(pb) && !err) { a.size = atom.size; - a.type=0L; + a.type=0; if(atom.size >= 8) { a.size = get_be32(pb); a.type = get_le32(pb); } total_size += 8; a.offset += 8; - dprintf(c->fc, "type: %08x %.4s sz: %"PRIx64" %"PRIx64" %"PRIx64"\n", a.type, (char*)&a.type, a.size, atom.size, total_size); + dprintf(c->fc, "type: %08x %.4s sz: %"PRIx64" %"PRIx64" %"PRIx64"\n", + a.type, (char*)&a.type, a.size, atom.size, total_size); if (a.size == 1) { /* 64 bit extended size */ a.size = get_be64(pb) - 8; a.offset += 8; @@ -245,19 +177,22 @@ static int mov_read_default(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) break; } a.size -= 8; - if(a.size < 0 || a.size > atom.size - total_size) + if(a.size < 0) break; + a.size = FFMIN(a.size, atom.size - total_size); - for (i = 0; c->parse_table[i].type != 0L - && c->parse_table[i].type != a.type; i++) + for (i = 0; mov_default_parse_table[i].type != 0 + && mov_default_parse_table[i].type != a.type; i++) /* empty */; - if (c->parse_table[i].type == 0) { /* skip leaf atoms data */ + if (mov_default_parse_table[i].type == 0) { /* skip leaf atoms data */ url_fskip(pb, a.size); } else { offset_t start_pos = url_ftell(pb); int64_t left; - err = (c->parse_table[i].func)(c, pb, a); + err = mov_default_parse_table[i].parse(c, pb, a); + if (c->found_moov && c->found_mdat) + break; left = a.size - url_ftell(pb) + start_pos; if (left > 0) /* skip garbage at atom end */ url_fskip(pb, left); @@ -274,27 +209,71 @@ static int mov_read_default(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) return err; } -static int mov_read_ctab(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) +static int mov_read_dref(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { -#if 1 - url_fskip(pb, atom.size); // for now -#else - VERY VERY BROKEN, NEVER execute this, needs rewrite - unsigned int len; - MOV_ctab_t *t; - c->ctab = av_realloc(c->ctab, ++c->ctab_size); - t = c->ctab[c->ctab_size]; - t->seed = get_be32(pb); - t->flags = get_be16(pb); - t->size = get_be16(pb) + 1; - len = 2 * t->size * 4; - if (len > 0) { - t->clrs = av_malloc(len); // 16bit A R G B - if (t->clrs) - get_buffer(pb, t->clrs, len); - } -#endif + AVStream *st = c->fc->streams[c->fc->nb_streams-1]; + MOVStreamContext *sc = st->priv_data; + int entries, i, j; + get_be32(pb); // version + flags + entries = get_be32(pb); + if (entries >= UINT_MAX / sizeof(*sc->drefs)) + return -1; + sc->drefs_count = entries; + sc->drefs = av_mallocz(entries * sizeof(*sc->drefs)); + + for (i = 0; i < sc->drefs_count; i++) { + MOV_dref_t *dref = &sc->drefs[i]; + uint32_t size = get_be32(pb); + offset_t next = url_ftell(pb) + size - 4; + + dref->type = get_le32(pb); + get_be32(pb); // version + flags + dprintf(c->fc, "type %.4s size %d\n", (char*)&dref->type, size); + + if (dref->type == MKTAG('a','l','i','s') && size > 150) { + /* macintosh alias record */ + uint16_t volume_len, len; + char volume[28]; + int16_t type; + + url_fskip(pb, 10); + + volume_len = get_byte(pb); + volume_len = FFMIN(volume_len, 27); + get_buffer(pb, volume, 27); + volume[volume_len] = 0; + av_log(c->fc, AV_LOG_DEBUG, "volume %s, len %d\n", volume, volume_len); + + url_fskip(pb, 112); + + for (type = 0; type != -1 && url_ftell(pb) < next; ) { + type = get_be16(pb); + len = get_be16(pb); + av_log(c->fc, AV_LOG_DEBUG, "type %d, len %d\n", type, len); + if (len&1) + len += 1; + if (type == 2) { // absolute path + av_free(dref->path); + dref->path = av_mallocz(len+1); + if (!dref->path) + return AVERROR(ENOMEM); + get_buffer(pb, dref->path, len); + if (len > volume_len && !strncmp(dref->path, volume, volume_len)) { + len -= volume_len; + memmove(dref->path, dref->path+volume_len, len); + dref->path[len] = 0; + } + for (j = 0; j < len; j++) + if (dref->path[j] == ':') + dref->path[j] = '/'; + av_log(c->fc, AV_LOG_DEBUG, "path %s\n", dref->path); + } else + url_fskip(pb, len); + } + } + url_fseek(pb, next, SEEK_SET); + } return 0; } @@ -311,8 +290,10 @@ static int mov_read_hdlr(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) ctype = get_le32(pb); type = get_le32(pb); /* component subtype */ - dprintf(c->fc, "ctype= %c%c%c%c (0x%08lx)\n", *((char *)&ctype), ((char *)&ctype)[1], ((char *)&ctype)[2], ((char *)&ctype)[3], (long) ctype); - dprintf(c->fc, "stype= %c%c%c%c\n", *((char *)&type), ((char *)&type)[1], ((char *)&type)[2], ((char *)&type)[3]); + dprintf(c->fc, "ctype= %c%c%c%c (0x%08x)\n", *((char *)&ctype), ((char *)&ctype)[1], + ((char *)&ctype)[2], ((char *)&ctype)[3], (int) ctype); + dprintf(c->fc, "stype= %c%c%c%c\n", + *((char *)&type), ((char *)&type)[1], ((char *)&type)[2], ((char *)&type)[3]); if(!ctype) c->isom = 1; if(type == MKTAG('v', 'i', 'd', 'e')) @@ -323,7 +304,6 @@ static int mov_read_hdlr(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) st->codec->codec_id = CODEC_ID_MP2; else if(type == MKTAG('s', 'u', 'b', 'p')) { st->codec->codec_type = CODEC_TYPE_SUBTITLE; - st->codec->codec_id = CODEC_ID_DVD_SUBTITLE; } get_be32(pb); /* component manufacture */ get_be32(pb); /* component flags */ @@ -336,7 +316,7 @@ static int mov_read_hdlr(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) return 0; } -static int mov_mp4_read_descr_len(ByteIOContext *pb) +static int mp4_read_descr_len(ByteIOContext *pb) { int len = 0; int count = 4; @@ -349,51 +329,55 @@ static int mov_mp4_read_descr_len(ByteIOContext *pb) return len; } -static int mov_mp4_read_descr(MOVContext *c, ByteIOContext *pb, int *tag) +static int mp4_read_descr(MOVContext *c, ByteIOContext *pb, int *tag) { int len; *tag = get_byte(pb); - len = mov_mp4_read_descr_len(pb); + len = mp4_read_descr_len(pb); dprintf(c->fc, "MPEG4 description: tag=0x%02x len=%d\n", *tag, len); return len; } +#define MP4ESDescrTag 0x03 +#define MP4DecConfigDescrTag 0x04 +#define MP4DecSpecificDescrTag 0x05 + static int mov_read_esds(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { AVStream *st = c->fc->streams[c->fc->nb_streams-1]; - MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; int tag, len; - /* Well, broken but suffisant for some MP4 streams */ get_be32(pb); /* version + flags */ - len = mov_mp4_read_descr(c, pb, &tag); + len = mp4_read_descr(c, pb, &tag); if (tag == MP4ESDescrTag) { get_be16(pb); /* ID */ get_byte(pb); /* priority */ } else get_be16(pb); /* ID */ - len = mov_mp4_read_descr(c, pb, &tag); + len = mp4_read_descr(c, pb, &tag); if (tag == MP4DecConfigDescrTag) { - sc->esds.object_type_id = get_byte(pb); - sc->esds.stream_type = get_byte(pb); - sc->esds.buffer_size_db = get_be24(pb); - sc->esds.max_bitrate = get_be32(pb); - sc->esds.avg_bitrate = get_be32(pb); - - st->codec->codec_id= codec_get_id(ff_mp4_obj_type, sc->esds.object_type_id); - dprintf(c->fc, "esds object type id %d\n", sc->esds.object_type_id); - len = mov_mp4_read_descr(c, pb, &tag); + int object_type_id = get_byte(pb); + get_byte(pb); /* stream type */ + get_be24(pb); /* buffer size db */ + get_be32(pb); /* max bitrate */ + get_be32(pb); /* avg bitrate */ + + st->codec->codec_id= codec_get_id(ff_mp4_obj_type, object_type_id); + dprintf(c->fc, "esds object type id %d\n", object_type_id); + len = mp4_read_descr(c, pb, &tag); if (tag == MP4DecSpecificDescrTag) { dprintf(c->fc, "Specific MPEG4 header len=%d\n", len); + if((uint64_t)len > (1<<30)) + return -1; st->codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE); - if (st->codec->extradata) { - get_buffer(pb, st->codec->extradata, len); - st->codec->extradata_size = len; - /* from mplayer */ - if ((*st->codec->extradata >> 3) == 29) { - st->codec->codec_id = CODEC_ID_MP3ON4; - } + if (!st->codec->extradata) + return AVERROR(ENOMEM); + get_buffer(pb, st->codec->extradata, len); + st->codec->extradata_size = len; + /* from mplayer */ + if ((*st->codec->extradata >> 3) == 29) { + st->codec->codec_id = CODEC_ID_MP3ON4; } } } @@ -405,12 +389,7 @@ static int mov_read_mdat(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { if(atom.size == 0) /* wrong one (MP4) */ return 0; - c->mdat_list = av_realloc(c->mdat_list, (c->mdat_count + 1) * sizeof(*c->mdat_list)); - c->mdat_list[c->mdat_count].offset = atom.offset; - c->mdat_list[c->mdat_count].size = atom.size; - c->mdat_count++; c->found_mdat=1; - c->mdat_offset = atom.offset; if(c->found_moov) return 1; /* found both, just go */ url_fskip(pb, atom.size); @@ -432,9 +411,8 @@ static int mov_read_ftyp(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) /* this atom should contain all header atoms */ static int mov_read_moov(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { - int err; - - err = mov_read_default(c, pb, atom); + if (mov_read_default(c, pb, atom) < 0) + return -1; /* we parsed the 'moov' atom, we can terminate the parsing as soon as we find the 'mdat' */ /* so we don't parse the whole file if over a network */ c->found_moov=1; @@ -447,7 +425,7 @@ static int mov_read_moov(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) static int mov_read_mdhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { AVStream *st = c->fc->streams[c->fc->nb_streams-1]; - MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; + MOVStreamContext *sc = st->priv_data; int version = get_byte(pb); int lang; @@ -488,9 +466,9 @@ static int mov_read_mvhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) get_be32(pb); /* modification time */ } c->time_scale = get_be32(pb); /* time scale */ -#ifdef DEBUG - av_log(NULL, AV_LOG_DEBUG, "time scale = %i\n", c->time_scale); -#endif + + dprintf(c->fc, "time scale = %i\n", c->time_scale); + c->duration = (version == 1) ? get_be64(pb) : get_be32(pb); /* duration */ get_be32(pb); /* preferred scale */ @@ -521,16 +499,13 @@ static int mov_read_smi(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) // currently SVQ3 decoder expect full STSD header - so let's fake it // this should be fixed and just SMI header should be passed av_free(st->codec->extradata); + st->codec->extradata = av_mallocz(atom.size + 0x5a + FF_INPUT_BUFFER_PADDING_SIZE); + if (!st->codec->extradata) + return AVERROR(ENOMEM); st->codec->extradata_size = 0x5a + atom.size; - st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - - if (st->codec->extradata) { - memcpy(st->codec->extradata, "SVQ3", 4); // fake - get_buffer(pb, st->codec->extradata + 0x5a, atom.size); - dprintf(c->fc, "Reading SMI %"PRId64" %s\n", atom.size, st->codec->extradata + 0x5a); - } else - url_fskip(pb, atom.size); - + memcpy(st->codec->extradata, "SVQ3", 4); // fake + get_buffer(pb, st->codec->extradata + 0x5a, atom.size); + dprintf(c->fc, "Reading SMI %"PRId64" %s\n", atom.size, st->codec->extradata + 0x5a); return 0; } @@ -558,16 +533,19 @@ static int mov_read_enda(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) static int mov_read_extradata(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { AVStream *st = c->fc->streams[c->fc->nb_streams-1]; - if((uint64_t)atom.size > (1<<30)) + uint64_t size= (uint64_t)st->codec->extradata_size + atom.size + 8 + FF_INPUT_BUFFER_PADDING_SIZE; + uint8_t *buf; + if(size > INT_MAX || (uint64_t)atom.size > INT_MAX) return -1; - av_free(st->codec->extradata); - st->codec->extradata_size = atom.size + 8; - st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - if (st->codec->extradata) { - AV_WL32(st->codec->extradata + 4, atom.type); - get_buffer(pb, st->codec->extradata + 8, atom.size); - } else - url_fskip(pb, atom.size); + buf= av_realloc(st->codec->extradata, size); + if(!buf) + return -1; + st->codec->extradata= buf; + buf+= st->codec->extradata_size; + st->codec->extradata_size= size - FF_INPUT_BUFFER_PADDING_SIZE; + AV_WB32( buf , atom.size + 8); + AV_WL32( buf + 4, atom.type); + get_buffer(pb, buf + 8, atom.size); return 0; } @@ -581,21 +559,24 @@ static int mov_read_wave(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) if (st->codec->codec_id == CODEC_ID_QDM2) { // pass all frma atom to codec, needed at least for QDM2 av_free(st->codec->extradata); + st->codec->extradata = av_mallocz(atom.size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!st->codec->extradata) + return AVERROR(ENOMEM); st->codec->extradata_size = atom.size; - st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - - if (st->codec->extradata) { - get_buffer(pb, st->codec->extradata, atom.size); - } else - url_fskip(pb, atom.size); + get_buffer(pb, st->codec->extradata, atom.size); } else if (atom.size > 8) { /* to read frma, esds atoms */ - mov_read_default(c, pb, atom); + if (mov_read_default(c, pb, atom) < 0) + return -1; } else url_fskip(pb, atom.size); return 0; } -static int mov_read_avcC(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) +/** + * This function reads atom content and puts data in extradata without tag + * nor size unlike mov_read_extradata. + */ +static int mov_read_glbl(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { AVStream *st = c->fc->streams[c->fc->nb_streams-1]; @@ -603,22 +584,18 @@ static int mov_read_avcC(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) return -1; av_free(st->codec->extradata); - + st->codec->extradata = av_mallocz(atom.size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!st->codec->extradata) + return AVERROR(ENOMEM); st->codec->extradata_size = atom.size; - st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - - if (st->codec->extradata) { - get_buffer(pb, st->codec->extradata, atom.size); - } else - url_fskip(pb, atom.size); - + get_buffer(pb, st->codec->extradata, atom.size); return 0; } static int mov_read_stco(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { AVStream *st = c->fc->streams[c->fc->nb_streams-1]; - MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; + MOVStreamContext *sc = st->priv_data; unsigned int i, entries; get_byte(pb); /* version */ @@ -650,21 +627,21 @@ static int mov_read_stco(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { AVStream *st = c->fc->streams[c->fc->nb_streams-1]; - MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; + MOVStreamContext *sc = st->priv_data; int entries, frames_per_sample; uint32_t format; uint8_t codec_name[32]; /* for palette traversal */ - int color_depth; - int color_start; - int color_count; - int color_end; + unsigned int color_depth; + unsigned int color_start; + unsigned int color_count; + unsigned int color_end; int color_index; int color_dec; int color_greyscale; - unsigned char *color_table; - int j; + const uint8_t *color_table; + int j, pseudo_stream_id; unsigned char r, g, b; get_byte(pb); /* version */ @@ -672,8 +649,9 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) entries = get_be32(pb); - while(entries--) { //Parsing Sample description table + for(pseudo_stream_id=0; pseudo_stream_idcodec->codec_tag) { - /* multiple fourcc, just skip for now */ + dref_id = get_be16(pb); + + if (st->codec->codec_tag && + (c->fc->video_codec_id ? codec_get_id(codec_movvideo_tags, format) != c->fc->video_codec_id + : st->codec->codec_tag != MKTAG('j', 'p', 'e', 'g')) + ){ + /* multiple fourcc, we skip jpeg, this isnt correct, we should export it as + seperate AVStream but this needs a few changes in the mov demuxer, patch + welcome */ url_fskip(pb, size - (url_ftell(pb) - start_pos)); continue; } + sc->pseudo_stream_id= pseudo_stream_id; + sc->dref_id= dref_id; st->codec->codec_tag = format; id = codec_get_id(codec_movaudio_tags, format); + if (id<=0 && (format&0xFFFF) == 'm' + ('s'<<8)) + id = codec_get_id(codec_wav_tags, bswap_32(format)&0xFFFF); + if (st->codec->codec_type != CODEC_TYPE_VIDEO && id > 0) { st->codec->codec_type = CODEC_TYPE_AUDIO; } else if (st->codec->codec_type != CODEC_TYPE_AUDIO && /* do not overwrite codec type */ @@ -700,12 +688,16 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) id = codec_get_id(codec_bmp_tags, format); if (id > 0) st->codec->codec_type = CODEC_TYPE_VIDEO; + else if(st->codec->codec_type == CODEC_TYPE_DATA){ + id = codec_get_id(ff_codec_movsubtitle_tags, format); + if(id > 0) + st->codec->codec_type = CODEC_TYPE_SUBTITLE; + } } - dprintf(c->fc, "size=%d 4CC= %c%c%c%c codec_type=%d\n", - size, - (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff, (format >> 24) & 0xff, - st->codec->codec_type); + dprintf(c->fc, "size=%d 4CC= %c%c%c%c codec_type=%d\n", size, + (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff, + (format >> 24) & 0xff, st->codec->codec_type); if(st->codec->codec_type==CODEC_TYPE_VIDEO) { st->codec->codec_id = id; @@ -713,7 +705,7 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) get_be16(pb); /* revision level */ get_be32(pb); /* vendor */ get_be32(pb); /* temporal quality */ - get_be32(pb); /* spacial quality */ + get_be32(pb); /* spatial quality */ st->codec->width = get_be16(pb); /* width */ st->codec->height = get_be16(pb); /* height */ @@ -722,9 +714,9 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) get_be32(pb); /* vert resolution */ get_be32(pb); /* data size, always 0 */ frames_per_sample = get_be16(pb); /* frames per samples */ -#ifdef DEBUG - av_log(NULL, AV_LOG_DEBUG, "frames/samples = %d\n", frames_per_sample); -#endif + + dprintf(c->fc, "frames/samples = %d\n", frames_per_sample); + get_buffer(pb, codec_name, 32); /* codec name, pascal string (FIXME: true for mp4?) */ if (codec_name[0] <= 31) { memcpy(st->codec->codec_name, &codec_name[1],codec_name[0]); @@ -733,7 +725,8 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) st->codec->bits_per_sample = get_be16(pb); /* depth */ st->codec->color_table_id = get_be16(pb); /* colortable id */ - + dprintf(c->fc, "depth %d, ctab id %d\n", + st->codec->bits_per_sample, st->codec->color_table_id); /* figure out the palette situation */ color_depth = st->codec->bits_per_sample & 0x1F; color_greyscale = st->codec->bits_per_sample & 0x20; @@ -741,10 +734,9 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) /* if the depth is 2, 4, or 8 bpp, file is palettized */ if ((color_depth == 2) || (color_depth == 4) || (color_depth == 8)) { - if (color_greyscale) { - /* compute the greyscale palette */ + st->codec->bits_per_sample = color_depth; color_count = 1 << color_depth; color_index = 255; color_dec = 256 / (color_count - 1); @@ -756,9 +748,7 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) if (color_index < 0) color_index = 0; } - } else if (st->codec->color_table_id & 0x08) { - /* if flag bit 3 is set, use the default palette */ color_count = 1 << color_depth; if (color_depth == 2) @@ -775,30 +765,30 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) c->palette_control.palette[j] = (r << 16) | (g << 8) | (b); } - } else { - /* load the palette from the file */ color_start = get_be32(pb); color_count = get_be16(pb); color_end = get_be16(pb); - for (j = color_start; j <= color_end; j++) { - /* each R, G, or B component is 16 bits; - * only use the top 8 bits; skip alpha bytes - * up front */ - get_byte(pb); - get_byte(pb); - r = get_byte(pb); - get_byte(pb); - g = get_byte(pb); - get_byte(pb); - b = get_byte(pb); - get_byte(pb); - c->palette_control.palette[j] = - (r << 16) | (g << 8) | (b); + if ((color_start <= 255) && + (color_end <= 255)) { + for (j = color_start; j <= color_end; j++) { + /* each R, G, or B component is 16 bits; + * only use the top 8 bits; skip alpha bytes + * up front */ + get_byte(pb); + get_byte(pb); + r = get_byte(pb); + get_byte(pb); + g = get_byte(pb); + get_byte(pb); + b = get_byte(pb); + get_byte(pb); + c->palette_control.palette[j] = + (r << 16) | (g << 8) | (b); + } } } - st->codec->palctrl = &c->palette_control; st->codec->palctrl->palette_changed = 1; } else @@ -814,10 +804,8 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) st->codec->channels = get_be16(pb); /* channel count */ dprintf(c->fc, "audio channels %d\n", st->codec->channels); st->codec->bits_per_sample = get_be16(pb); /* sample size */ - /* do we need to force to 16 for AMR ? */ - /* handle specific s8 codec */ - get_be16(pb); /* compression id = 0*/ + sc->audio_cid = get_be16(pb); get_be16(pb); /* packet size = 0 */ st->codec->sample_rate = ((get_be32(pb) >> 16)); @@ -835,11 +823,24 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) else if (st->codec->bits_per_sample == 24) st->codec->codec_id = CODEC_ID_PCM_S24BE; break; + /* set values for old format before stsd version 1 appeared */ + case CODEC_ID_MACE3: + sc->samples_per_frame = 6; + sc->bytes_per_frame = 2*st->codec->channels; + break; + case CODEC_ID_MACE6: + sc->samples_per_frame = 6; + sc->bytes_per_frame = 1*st->codec->channels; + break; + case CODEC_ID_ADPCM_IMA_QT: + sc->samples_per_frame = 64; + sc->bytes_per_frame = 34*st->codec->channels; + break; default: break; } - //Read QT version 1 fields. In version 0 theese dont exist + //Read QT version 1 fields. In version 0 these do not exist. dprintf(c->fc, "version =%d, isom =%d\n",version,c->isom); if(!c->isom) { if(version==1) { @@ -864,45 +865,26 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) st->codec->bits_per_sample = bits_per_sample; sc->sample_size = (bits_per_sample >> 3) * st->codec->channels; } + } else if(st->codec->codec_type==CODEC_TYPE_SUBTITLE){ + st->codec->codec_id= id; } else { /* other codec type, just skip (rtp, mp4s, tmcd ...) */ url_fskip(pb, size - (url_ftell(pb) - start_pos)); } /* this will read extra atoms at the end (wave, alac, damr, avcC, SMI ...) */ a.size = size - (url_ftell(pb) - start_pos); - if (a.size > 8) - mov_read_default(c, pb, a); - else if (a.size > 0) + if (a.size > 8) { + if (mov_read_default(c, pb, a) < 0) + return -1; + } else if (a.size > 0) url_fskip(pb, a.size); } - if(st->codec->codec_type==CODEC_TYPE_AUDIO && st->codec->sample_rate==0 && sc->time_scale>1) { + if(st->codec->codec_type==CODEC_TYPE_AUDIO && st->codec->sample_rate==0 && sc->time_scale>1) st->codec->sample_rate= sc->time_scale; - } /* special codec parameters handling */ switch (st->codec->codec_id) { -#ifdef CONFIG_H261_DECODER - case CODEC_ID_H261: -#endif -#ifdef CONFIG_H263_DECODER - case CODEC_ID_H263: -#endif -#ifdef CONFIG_MPEG4_DECODER - case CODEC_ID_MPEG4: -#endif - st->codec->width= 0; /* let decoder init width/height */ - st->codec->height= 0; - break; -#ifdef CONFIG_LIBFAAD - case CODEC_ID_AAC: -#endif -#ifdef CONFIG_VORBIS_DECODER - case CODEC_ID_VORBIS: -#endif - case CODEC_ID_MP3ON4: - st->codec->sample_rate= 0; /* let decoder init parameters properly */ - break; #ifdef CONFIG_DV_DEMUXER case CODEC_ID_DVAUDIO: c->dv_fctx = av_alloc_format_context(); @@ -927,7 +909,11 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) case CODEC_ID_MP2: case CODEC_ID_MP3: st->codec->codec_type = CODEC_TYPE_AUDIO; /* force type after stsd for m1a hdlr */ - st->need_parsing = 1; + st->need_parsing = AVSTREAM_PARSE_FULL; + break; + case CODEC_ID_ADPCM_MS: + case CODEC_ID_ADPCM_IMA_WAV: + st->codec->block_align = sc->bytes_per_frame; break; default: break; @@ -939,7 +925,7 @@ static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) static int mov_read_stsc(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { AVStream *st = c->fc->streams[c->fc->nb_streams-1]; - MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; + MOVStreamContext *sc = st->priv_data; unsigned int i, entries; get_byte(pb); /* version */ @@ -947,14 +933,13 @@ static int mov_read_stsc(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) entries = get_be32(pb); - if(entries >= UINT_MAX / sizeof(MOV_sample_to_chunk_tbl)) + if(entries >= UINT_MAX / sizeof(MOV_stsc_t)) return -1; -#ifdef DEBUG -av_log(NULL, AV_LOG_DEBUG, "track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries); -#endif + dprintf(c->fc, "track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries); + sc->sample_to_chunk_sz = entries; - sc->sample_to_chunk = av_malloc(entries * sizeof(MOV_sample_to_chunk_tbl)); + sc->sample_to_chunk = av_malloc(entries * sizeof(MOV_stsc_t)); if (!sc->sample_to_chunk) return -1; for(i=0; ifc->nb_streams-1, static int mov_read_stss(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { AVStream *st = c->fc->streams[c->fc->nb_streams-1]; - MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; + MOVStreamContext *sc = st->priv_data; unsigned int i, entries; get_byte(pb); /* version */ @@ -976,21 +961,19 @@ static int mov_read_stss(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) entries = get_be32(pb); - if(entries >= UINT_MAX / sizeof(long)) + if(entries >= UINT_MAX / sizeof(int)) return -1; sc->keyframe_count = entries; -#ifdef DEBUG - av_log(NULL, AV_LOG_DEBUG, "keyframe_count = %d\n", sc->keyframe_count); -#endif - sc->keyframes = av_malloc(entries * sizeof(long)); + + dprintf(c->fc, "keyframe_count = %d\n", sc->keyframe_count); + + sc->keyframes = av_malloc(entries * sizeof(int)); if (!sc->keyframes) return -1; for(i=0; ikeyframes[i] = get_be32(pb); -#ifdef DEBUG -/* av_log(NULL, AV_LOG_DEBUG, "keyframes[]=%ld\n", sc->keyframes[i]); */ -#endif + //dprintf(c->fc, "keyframes[]=%d\n", sc->keyframes[i]); } return 0; } @@ -998,7 +981,7 @@ static int mov_read_stss(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) static int mov_read_stsz(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { AVStream *st = c->fc->streams[c->fc->nb_streams-1]; - MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; + MOVStreamContext *sc = st->priv_data; unsigned int i, entries, sample_size; get_byte(pb); /* version */ @@ -1008,24 +991,21 @@ static int mov_read_stsz(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) if (!sc->sample_size) /* do not overwrite value computed in stsd */ sc->sample_size = sample_size; entries = get_be32(pb); - if(entries >= UINT_MAX / sizeof(long)) + if(entries >= UINT_MAX / sizeof(int)) return -1; sc->sample_count = entries; if (sample_size) return 0; -#ifdef DEBUG - av_log(NULL, AV_LOG_DEBUG, "sample_size = %d sample_count = %d\n", sc->sample_size, sc->sample_count); -#endif - sc->sample_sizes = av_malloc(entries * sizeof(long)); + dprintf(c->fc, "sample_size = %d sample_count = %d\n", sc->sample_size, sc->sample_count); + + sc->sample_sizes = av_malloc(entries * sizeof(int)); if (!sc->sample_sizes) return -1; for(i=0; isample_sizes[i] = get_be32(pb); -#ifdef DEBUG - av_log(NULL, AV_LOG_DEBUG, "sample_sizes[]=%ld\n", sc->sample_sizes[i]); -#endif + dprintf(c->fc, "sample_sizes[]=%d\n", sc->sample_sizes[i]); } return 0; } @@ -1033,7 +1013,7 @@ static int mov_read_stsz(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { AVStream *st = c->fc->streams[c->fc->nb_streams-1]; - MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; + MOVStreamContext *sc = st->priv_data; unsigned int i, entries; int64_t duration=0; int64_t total_sample_count=0; @@ -1041,15 +1021,14 @@ static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) get_byte(pb); /* version */ get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ entries = get_be32(pb); - if(entries >= UINT_MAX / sizeof(Time2Sample)) + if(entries >= UINT_MAX / sizeof(MOV_stts_t)) return -1; sc->stts_count = entries; - sc->stts_data = av_malloc(entries * sizeof(Time2Sample)); - -#ifdef DEBUG -av_log(NULL, AV_LOG_DEBUG, "track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries); -#endif + sc->stts_data = av_malloc(entries * sizeof(MOV_stts_t)); + if (!sc->stts_data) + return -1; + dprintf(c->fc, "track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries); sc->time_rate=0; @@ -1079,18 +1058,19 @@ av_log(NULL, AV_LOG_DEBUG, "track[%i].stts.entries = %i\n", c->fc->nb_streams-1, static int mov_read_ctts(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { AVStream *st = c->fc->streams[c->fc->nb_streams-1]; - MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; + MOVStreamContext *sc = st->priv_data; unsigned int i, entries; get_byte(pb); /* version */ get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ entries = get_be32(pb); - if(entries >= UINT_MAX / sizeof(Time2Sample)) + if(entries >= UINT_MAX / sizeof(MOV_stts_t)) return -1; sc->ctts_count = entries; - sc->ctts_data = av_malloc(entries * sizeof(Time2Sample)); - + sc->ctts_data = av_malloc(entries * sizeof(MOV_stts_t)); + if (!sc->ctts_data) + return -1; dprintf(c->fc, "track[%i].ctts.entries = %i\n", c->fc->nb_streams-1, entries); for(i=0; ipriv_data = sc; st->codec->codec_type = CODEC_TYPE_DATA; st->start_time = 0; /* XXX: check */ - c->streams[c->fc->nb_streams-1] = sc; return mov_read_default(c, pb, atom); } +static void mov_parse_udta_string(ByteIOContext *pb, char *str, int size) +{ + uint16_t str_size = get_be16(pb); /* string length */; + + get_be16(pb); /* skip language */ + get_buffer(pb, str, FFMIN(size, str_size)); +} + +static int mov_read_udta(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) +{ + uint64_t end = url_ftell(pb) + atom.size; + + while (url_ftell(pb) + 8 < end) { + uint32_t tag_size = get_be32(pb); + uint32_t tag = get_le32(pb); + uint64_t next = url_ftell(pb) + tag_size - 8; + + if (next > end) // stop if tag_size is wrong + break; + + switch (tag) { + case MKTAG(0xa9,'n','a','m'): + mov_parse_udta_string(pb, c->fc->title, sizeof(c->fc->title)); + break; + case MKTAG(0xa9,'w','r','t'): + mov_parse_udta_string(pb, c->fc->author, sizeof(c->fc->author)); + break; + case MKTAG(0xa9,'c','p','y'): + mov_parse_udta_string(pb, c->fc->copyright, sizeof(c->fc->copyright)); + break; + case MKTAG(0xa9,'i','n','f'): + mov_parse_udta_string(pb, c->fc->comment, sizeof(c->fc->comment)); + break; + default: + break; + } + + url_fseek(pb, next, SEEK_SET); + } + + return 0; +} + static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { AVStream *st = c->fc->streams[c->fc->nb_streams-1]; @@ -1252,18 +1274,23 @@ static int mov_read_cmov(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) /* edit list atom */ static int mov_read_elst(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) { + MOVStreamContext *sc = c->fc->streams[c->fc->nb_streams-1]->priv_data; int i, edit_count; get_byte(pb); /* version */ get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ - edit_count= c->streams[c->fc->nb_streams-1]->edit_count = get_be32(pb); /* entries */ + edit_count= sc->edit_count = get_be32(pb); /* entries */ for(i=0; ifc, AV_LOG_WARNING, "edit list not starting at 0, " + "a/v desync might occur, patch welcome\n"); } - dprintf(c->fc, "track[%i].edit_count = %i\n", c->fc->nb_streams-1, c->streams[c->fc->nb_streams-1]->edit_count); + dprintf(c->fc, "track[%i].edit_count = %i\n", c->fc->nb_streams-1, sc->edit_count); return 0; } @@ -1271,11 +1298,14 @@ static const MOVParseTableEntry mov_default_parse_table[] = { /* mp4 atoms */ { MKTAG( 'c', 'o', '6', '4' ), mov_read_stco }, { MKTAG( 'c', 't', 't', 's' ), mov_read_ctts }, /* composition time to sample */ +{ MKTAG( 'd', 'i', 'n', 'f' ), mov_read_default }, +{ MKTAG( 'd', 'r', 'e', 'f' ), mov_read_dref }, { MKTAG( 'e', 'd', 't', 's' ), mov_read_default }, { MKTAG( 'e', 'l', 's', 't' ), mov_read_elst }, { MKTAG( 'e', 'n', 'd', 'a' ), mov_read_enda }, { MKTAG( 'f', 'i', 'e', 'l' ), mov_read_extradata }, { MKTAG( 'f', 't', 'y', 'p' ), mov_read_ftyp }, +{ MKTAG( 'g', 'l', 'b', 'l' ), mov_read_glbl }, { MKTAG( 'h', 'd', 'l', 'r' ), mov_read_hdlr }, { MKTAG( 'j', 'p', '2', 'h' ), mov_read_extradata }, { MKTAG( 'm', 'd', 'a', 't' ), mov_read_mdat }, @@ -1286,7 +1316,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG( 'm', 'v', 'h', 'd' ), mov_read_mvhd }, { MKTAG( 'S', 'M', 'I', ' ' ), mov_read_smi }, /* Sorenson extension ??? */ { MKTAG( 'a', 'l', 'a', 'c' ), mov_read_extradata }, /* alac specific atom */ -{ MKTAG( 'a', 'v', 'c', 'C' ), mov_read_avcC }, +{ MKTAG( 'a', 'v', 'c', 'C' ), mov_read_glbl }, { MKTAG( 's', 't', 'b', 'l' ), mov_read_default }, { MKTAG( 's', 't', 'c', 'o' ), mov_read_stco }, { MKTAG( 's', 't', 's', 'c' ), mov_read_stsc }, @@ -1296,22 +1326,14 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG( 's', 't', 't', 's' ), mov_read_stts }, { MKTAG( 't', 'k', 'h', 'd' ), mov_read_tkhd }, /* track header */ { MKTAG( 't', 'r', 'a', 'k' ), mov_read_trak }, +{ MKTAG( 'u', 'd', 't', 'a' ), mov_read_udta }, { MKTAG( 'w', 'a', 'v', 'e' ), mov_read_wave }, -{ MKTAG( 'c', 't', 'a', 'b' ), mov_read_ctab }, { MKTAG( 'e', 's', 'd', 's' ), mov_read_esds }, { MKTAG( 'w', 'i', 'd', 'e' ), mov_read_wide }, /* place holder */ { MKTAG( 'c', 'm', 'o', 'v' ), mov_read_cmov }, -{ 0L, NULL } +{ 0, NULL } }; -static void mov_free_stream_context(MOVStreamContext *sc) -{ - if(sc) { - av_freep(&sc->ctts_data); - av_freep(&sc); - } -} - /* XXX: is it sufficient ? */ static int mov_probe(AVProbeData *p) { @@ -1320,8 +1342,6 @@ static int mov_probe(AVProbeData *p) int score = 0; /* check file header */ - if (p->buf_size <= 12) - return 0; offset = 0; for(;;) { /* ignore invalid offset */ @@ -1337,11 +1357,13 @@ static int mov_probe(AVProbeData *p) case MKTAG( 'u', 'd', 't', 'a' ): /* Packet Video PVAuthor adds this and a lot of more junk */ return AVPROBE_SCORE_MAX; /* those are more common words, so rate then a bit less */ + case MKTAG( 'e', 'd', 'i', 'w' ): /* xdcam files have reverted first tags */ case MKTAG( 'w', 'i', 'd', 'e' ): case MKTAG( 'f', 'r', 'e', 'e' ): case MKTAG( 'j', 'u', 'n', 'k' ): case MKTAG( 'p', 'i', 'c', 't' ): return AVPROBE_SCORE_MAX - 5; + case MKTAG(0x82,0x82,0x7f,0x7d ): case MKTAG( 'f', 't', 'y', 'p' ): case MKTAG( 's', 'k', 'i', 'p' ): case MKTAG( 'u', 'u', 'i', 'd' ): @@ -1365,34 +1387,40 @@ static void mov_build_index(MOVContext *mov, AVStream *st) unsigned int stts_index = 0; unsigned int stsc_index = 0; unsigned int stss_index = 0; - unsigned int i, j, k; + unsigned int i, j; - if (sc->sample_sizes || st->codec->codec_type == CODEC_TYPE_VIDEO || sc->dv_audio_container) { + if (sc->sample_sizes || st->codec->codec_type == CODEC_TYPE_VIDEO || + sc->audio_cid == -2) { unsigned int current_sample = 0; unsigned int stts_sample = 0; unsigned int keyframe, sample_size; unsigned int distance = 0; + int key_off = sc->keyframes && sc->keyframes[0] == 1; st->nb_frames = sc->sample_count; for (i = 0; i < sc->chunk_count; i++) { current_offset = sc->chunk_offsets[i]; - if (stsc_index + 1 < sc->sample_to_chunk_sz && i + 1 == sc->sample_to_chunk[stsc_index + 1].first) + if (stsc_index + 1 < sc->sample_to_chunk_sz && + i + 1 == sc->sample_to_chunk[stsc_index + 1].first) stsc_index++; for (j = 0; j < sc->sample_to_chunk[stsc_index].count; j++) { if (current_sample >= sc->sample_count) { av_log(mov->fc, AV_LOG_ERROR, "wrong sample count\n"); goto out; } - keyframe = !sc->keyframe_count || current_sample + 1 == sc->keyframes[stss_index]; + keyframe = !sc->keyframe_count || current_sample+key_off == sc->keyframes[stss_index]; if (keyframe) { distance = 0; if (stss_index + 1 < sc->keyframe_count) stss_index++; } sample_size = sc->sample_size > 0 ? sc->sample_size : sc->sample_sizes[current_sample]; - dprintf(mov->fc, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", size %d, distance %d, keyframe %d\n", - st->index, current_sample, current_offset, current_dts, sample_size, distance, keyframe); - av_add_index_entry(st, current_offset, current_dts, sample_size, distance, keyframe ? AVINDEX_KEYFRAME : 0); + dprintf(mov->fc, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", " + "size %d, distance %d, keyframe %d\n", st->index, current_sample, + current_offset, current_dts, sample_size, distance, keyframe); + if(sc->sample_to_chunk[stsc_index].id - 1 == sc->pseudo_stream_id) + av_add_index_entry(st, current_offset, current_dts, sample_size, distance, + keyframe ? AVINDEX_KEYFRAME : 0); current_offset += sample_size; assert(sc->stts_data[stts_index].duration % sc->time_rate == 0); current_dts += sc->stts_data[stts_index].duration / sc->time_rate; @@ -1407,63 +1435,51 @@ static void mov_build_index(MOVContext *mov, AVStream *st) } } else { /* read whole chunk */ unsigned int chunk_samples, chunk_size, chunk_duration; - + unsigned int frames = 1; for (i = 0; i < sc->chunk_count; i++) { current_offset = sc->chunk_offsets[i]; - if (stsc_index + 1 < sc->sample_to_chunk_sz && i + 1 == sc->sample_to_chunk[stsc_index + 1].first) + if (stsc_index + 1 < sc->sample_to_chunk_sz && + i + 1 == sc->sample_to_chunk[stsc_index + 1].first) stsc_index++; chunk_samples = sc->sample_to_chunk[stsc_index].count; - /* get chunk size */ - if (sc->sample_size > 1 || st->codec->codec_id == CODEC_ID_PCM_U8 || st->codec->codec_id == CODEC_ID_PCM_S8) - chunk_size = chunk_samples * sc->sample_size; - else if (sc->samples_per_frame > 0 && (chunk_samples * sc->bytes_per_frame % sc->samples_per_frame == 0)) - chunk_size = chunk_samples * sc->bytes_per_frame / sc->samples_per_frame; - else { /* workaround to find nearest next chunk offset */ - chunk_size = INT_MAX; - for (j = 0; j < mov->total_streams; j++) { - MOVStreamContext *msc = mov->streams[j]; - - for (k = msc->next_chunk; k < msc->chunk_count; k++) { - if (msc->chunk_offsets[k] > current_offset && msc->chunk_offsets[k] - current_offset < chunk_size) { - chunk_size = msc->chunk_offsets[k] - current_offset; - msc->next_chunk = k; - break; - } - } - } - /* check for last chunk */ - if (chunk_size == INT_MAX) - for (j = 0; j < mov->mdat_count; j++) { - dprintf(mov->fc, "mdat %d, offset %"PRIx64", size %"PRId64", current offset %"PRIx64"\n", - j, mov->mdat_list[j].offset, mov->mdat_list[j].size, current_offset); - if (mov->mdat_list[j].offset <= current_offset && mov->mdat_list[j].offset + mov->mdat_list[j].size > current_offset) - chunk_size = mov->mdat_list[j].offset + mov->mdat_list[j].size - current_offset; - } - assert(chunk_size != INT_MAX); - for (j = 0; j < mov->total_streams; j++) { - mov->streams[j]->next_chunk = 0; + /* get chunk size, beware of alaw/ulaw/mace */ + if (sc->samples_per_frame > 0 && + (chunk_samples * sc->bytes_per_frame % sc->samples_per_frame == 0)) { + if (sc->samples_per_frame < 1024) + chunk_size = chunk_samples * sc->bytes_per_frame / sc->samples_per_frame; + else { + chunk_size = sc->bytes_per_frame; + frames = chunk_samples / sc->samples_per_frame; + chunk_samples = sc->samples_per_frame; } + } else if (sc->sample_size > 1 || st->codec->bits_per_sample == 8) { + chunk_size = chunk_samples * sc->sample_size; + } else { + av_log(mov->fc, AV_LOG_ERROR, "could not determine chunk size, report problem\n"); + goto out; } - av_add_index_entry(st, current_offset, current_dts, chunk_size, 0, AVINDEX_KEYFRAME); - /* get chunk duration */ - chunk_duration = 0; - while (chunk_samples > 0) { - if (chunk_samples < sc->stts_data[stts_index].count) { - chunk_duration += sc->stts_data[stts_index].duration * chunk_samples; - sc->stts_data[stts_index].count -= chunk_samples; - break; - } else { - chunk_duration += sc->stts_data[stts_index].duration * chunk_samples; - chunk_samples -= sc->stts_data[stts_index].count; - if (stts_index + 1 < sc->stts_count) { - stts_index++; + for (j = 0; j < frames; j++) { + av_add_index_entry(st, current_offset, current_dts, chunk_size, 0, AVINDEX_KEYFRAME); + /* get chunk duration */ + chunk_duration = 0; + while (chunk_samples > 0) { + if (chunk_samples < sc->stts_data[stts_index].count) { + chunk_duration += sc->stts_data[stts_index].duration * chunk_samples; + sc->stts_data[stts_index].count -= chunk_samples; + break; + } else { + chunk_duration += sc->stts_data[stts_index].duration * chunk_samples; + chunk_samples -= sc->stts_data[stts_index].count; + if (stts_index + 1 < sc->stts_count) + stts_index++; } } + current_offset += sc->bytes_per_frame; + dprintf(mov->fc, "AVIndex stream %d, chunk %d, offset %"PRIx64", dts %"PRId64", size %d, " + "duration %d\n", st->index, i, current_offset, current_dts, chunk_size, chunk_duration); + assert(chunk_duration % sc->time_rate == 0); + current_dts += chunk_duration / sc->time_rate; } - dprintf(mov->fc, "AVIndex stream %d, chunk %d, offset %"PRIx64", dts %"PRId64", size %d, duration %d\n", - st->index, i, current_offset, current_dts, chunk_size, chunk_duration); - assert(chunk_duration % sc->time_rate == 0); - current_dts += chunk_duration / sc->time_rate; } } out: @@ -1473,18 +1489,17 @@ static void mov_build_index(MOVContext *mov, AVStream *st) static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap) { - MOVContext *mov = (MOVContext *) s->priv_data; - ByteIOContext *pb = &s->pb; + MOVContext *mov = s->priv_data; + ByteIOContext *pb = s->pb; int i, err; MOV_atom_t atom = { 0, 0, 0 }; mov->fc = s; - mov->parse_table = mov_default_parse_table; if(!url_is_streamed(pb)) /* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */ atom.size = url_fsize(pb); else - atom.size = 0x7FFFFFFFFFFFFFFFLL; + atom.size = INT64_MAX; /* check MOV header */ err = mov_read_default(mov, pb, atom); @@ -1495,15 +1510,9 @@ static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap) } dprintf(mov->fc, "on_parse_exit_offset=%d\n", (int) url_ftell(pb)); - /* some cleanup : make sure we are on the mdat atom */ - if(!url_is_streamed(pb) && (url_ftell(pb) != mov->mdat_offset)) - url_fseek(pb, mov->mdat_offset, SEEK_SET); - - mov->total_streams = s->nb_streams; - - for(i=0; itotal_streams; i++) { - MOVStreamContext *sc = mov->streams[i]; + for(i=0; inb_streams; i++) { AVStream *st = s->streams[i]; + MOVStreamContext *sc = st->priv_data; /* sanity checks */ if(!sc->stts_count || !sc->chunk_count || !sc->sample_to_chunk_sz || (!sc->sample_size && !sc->sample_count)){ @@ -1518,7 +1527,7 @@ static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap) av_set_pts_info(st, 64, sc->time_rate, sc->time_scale); if (st->codec->codec_type == CODEC_TYPE_AUDIO && sc->stts_count == 1) - st->codec->frame_size = sc->stts_data[0].duration; + st->codec->frame_size = av_rescale(sc->time_rate, st->codec->sample_rate, sc->time_scale); if(st->duration != AV_NOPTS_VALUE){ assert(st->duration % sc->time_rate == 0); @@ -1526,17 +1535,48 @@ static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap) } sc->ffindex = i; mov_build_index(mov, st); + + if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) { + if (url_fopen(&sc->pb, sc->drefs[sc->dref_id-1].path, URL_RDONLY) < 0) + av_log(s, AV_LOG_ERROR, "stream %d, error opening external essence: %s\n", + st->index, strerror(errno)); + } else + sc->pb = s->pb; + + switch (st->codec->codec_id) { +#ifdef CONFIG_H261_DECODER + case CODEC_ID_H261: +#endif +#ifdef CONFIG_H263_DECODER + case CODEC_ID_H263: +#endif +#ifdef CONFIG_MPEG4_DECODER + case CODEC_ID_MPEG4: +#endif + st->codec->width= 0; /* let decoder init width/height */ + st->codec->height= 0; + break; +#ifdef CONFIG_LIBFAAD + case CODEC_ID_AAC: +#endif +#ifdef CONFIG_VORBIS_DECODER + case CODEC_ID_VORBIS: +#endif + case CODEC_ID_MP3ON4: + st->codec->sample_rate= 0; /* let decoder init parameters properly */ + break; + } } - for(i=0; itotal_streams; i++) { - /* dont need those anymore */ - av_freep(&mov->streams[i]->chunk_offsets); - av_freep(&mov->streams[i]->sample_to_chunk); - av_freep(&mov->streams[i]->sample_sizes); - av_freep(&mov->streams[i]->keyframes); - av_freep(&mov->streams[i]->stts_data); + for(i=0; inb_streams; i++) { + MOVStreamContext *sc = s->streams[i]->priv_data; + /* Do not need those anymore. */ + av_freep(&sc->chunk_offsets); + av_freep(&sc->sample_to_chunk); + av_freep(&sc->sample_sizes); + av_freep(&sc->keyframes); + av_freep(&sc->stts_data); } - av_freep(&mov->mdat_list); return 0; } @@ -1548,15 +1588,19 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) int64_t best_dts = INT64_MAX; int i; - for (i = 0; i < mov->total_streams; i++) { - MOVStreamContext *msc = mov->streams[i]; - - if (s->streams[i]->discard != AVDISCARD_ALL && msc->current_sample < msc->sample_count) { - AVIndexEntry *current_sample = &s->streams[i]->index_entries[msc->current_sample]; - int64_t dts = av_rescale(current_sample->timestamp * (int64_t)msc->time_rate, AV_TIME_BASE, msc->time_scale); - - dprintf(s, "stream %d, sample %ld, dts %"PRId64"\n", i, msc->current_sample, dts); - if (dts < best_dts) { + for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; + MOVStreamContext *msc = st->priv_data; + if (st->discard != AVDISCARD_ALL && msc->pb && msc->current_sample < msc->sample_count) { + AVIndexEntry *current_sample = &st->index_entries[msc->current_sample]; + int64_t dts = av_rescale(current_sample->timestamp * (int64_t)msc->time_rate, + AV_TIME_BASE, msc->time_scale); + dprintf(s, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts); + if (!sample || (url_is_streamed(s->pb) && current_sample->pos < sample->pos) || + (!url_is_streamed(s->pb) && + ((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb && + ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) || + (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))))) { sample = current_sample; best_dts = dts; sc = msc; @@ -1567,24 +1611,19 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) return -1; /* must be done just before reading, to avoid infinite loop on sample */ sc->current_sample++; - if (sample->pos >= url_fsize(&s->pb)) { - av_log(mov->fc, AV_LOG_ERROR, "stream %d, offset 0x%"PRIx64": partial file\n", sc->ffindex, sample->pos); + if (url_fseek(sc->pb, sample->pos, SEEK_SET) != sample->pos) { + av_log(mov->fc, AV_LOG_ERROR, "stream %d, offset 0x%"PRIx64": partial file\n", + sc->ffindex, sample->pos); return -1; } + av_get_packet(sc->pb, pkt, sample->size); #ifdef CONFIG_DV_DEMUXER - if (sc->dv_audio_container) { - dv_get_packet(mov->dv_demux, pkt); - dprintf(s, "dv audio pkt size %d\n", pkt->size); - } else { -#endif - url_fseek(&s->pb, sample->pos, SEEK_SET); - av_get_packet(&s->pb, pkt, sample->size); -#ifdef CONFIG_DV_DEMUXER - if (mov->dv_demux) { - void *pkt_destruct_func = pkt->destruct; - dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size); - pkt->destruct = pkt_destruct_func; - } + if (mov->dv_demux && sc->dv_audio_container) { + dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size); + av_free(pkt->data); + pkt->size = 0; + if (dv_get_packet(mov->dv_demux, pkt) < 0) + return -1; } #endif pkt->stream_index = sc->ffindex; @@ -1594,7 +1633,8 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->pts = pkt->dts + sc->ctts_data[sc->sample_to_ctime_index].duration / sc->time_rate; /* update ctts context */ sc->sample_to_ctime_sample++; - if (sc->sample_to_ctime_index < sc->ctts_count && sc->ctts_data[sc->sample_to_ctime_index].count == sc->sample_to_ctime_sample) { + if (sc->sample_to_ctime_index < sc->ctts_count && + sc->ctts_data[sc->sample_to_ctime_index].count == sc->sample_to_ctime_sample) { sc->sample_to_ctime_index++; sc->sample_to_ctime_sample = 0; } @@ -1603,7 +1643,8 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) } pkt->flags |= sample->flags & AVINDEX_KEYFRAME ? PKT_FLAG_KEY : 0; pkt->pos = sample->pos; - dprintf(s, "stream %d, pts %"PRId64", dts %"PRId64", pos 0x%"PRIx64", duration %d\n", pkt->stream_index, pkt->pts, pkt->dts, pkt->pos, pkt->duration); + dprintf(s, "stream %d, pts %"PRId64", dts %"PRId64", pos 0x%"PRIx64", duration %d\n", + pkt->stream_index, pkt->pts, pkt->dts, pkt->pos, pkt->duration); return 0; } @@ -1618,17 +1659,18 @@ static int mov_seek_stream(AVStream *st, int64_t timestamp, int flags) if (sample < 0) /* not sure what to do */ return -1; sc->current_sample = sample; - dprintf(st->codec, "stream %d, found sample %ld\n", st->index, sc->current_sample); + dprintf(st->codec, "stream %d, found sample %d\n", st->index, sc->current_sample); /* adjust ctts index */ if (sc->ctts_data) { time_sample = 0; for (i = 0; i < sc->ctts_count; i++) { - time_sample += sc->ctts_data[i].count; - if (time_sample >= sc->current_sample) { + int next = time_sample + sc->ctts_data[i].count; + if (next > sc->current_sample) { sc->sample_to_ctime_index = i; - sc->sample_to_ctime_sample = time_sample - sc->current_sample; + sc->sample_to_ctime_sample = sc->current_sample - time_sample; break; } + time_sample = next; } } return sample; @@ -1665,13 +1707,17 @@ static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti static int mov_read_close(AVFormatContext *s) { - int i; - MOVContext *mov = (MOVContext *) s->priv_data; - for(i=0; itotal_streams; i++) - mov_free_stream_context(mov->streams[i]); - /* free color tabs */ - for(i=0; ictab_size; i++) - av_freep(&mov->ctab[i]); + int i, j; + MOVContext *mov = s->priv_data; + for(i=0; inb_streams; i++) { + MOVStreamContext *sc = s->streams[i]->priv_data; + av_freep(&sc->ctts_data); + for (j=0; jdrefs_count; j++) + av_freep(&sc->drefs[j].path); + av_freep(&sc->drefs); + if (sc->pb && sc->pb != s->pb) + url_fclose(sc->pb); + } if(mov->dv_demux){ for(i=0; idv_fctx->nb_streams; i++){ av_freep(&mov->dv_fctx->streams[i]->codec); @@ -1680,7 +1726,6 @@ static int mov_read_close(AVFormatContext *s) av_freep(&mov->dv_fctx); av_freep(&mov->dv_demux); } - av_freep(&mov->ctab); return 0; } diff --git a/contrib/ffmpeg/libavformat/movenc.c b/contrib/ffmpeg/libavformat/movenc.c index e93416914..501c44ebd 100644 --- a/contrib/ffmpeg/libavformat/movenc.c +++ b/contrib/ffmpeg/libavformat/movenc.c @@ -23,6 +23,7 @@ #include "riff.h" #include "avio.h" #include "isom.h" +#include "avc.h" #undef NDEBUG #include @@ -59,7 +60,7 @@ typedef struct MOVIndex { int hasBframes; int language; int trackID; - int tag; + int tag; ///< stsd fourcc AVCodecContext *enc; int vosLen; @@ -78,7 +79,7 @@ typedef struct MOVContext { MOVTrack tracks[MAX_STREAMS]; } MOVContext; -//FIXME supprt 64bit varaint with wide placeholders +//FIXME support 64 bit variant with wide placeholders static offset_t updateSize (ByteIOContext *pb, offset_t pos) { offset_t curpos = url_ftell(pb); @@ -140,7 +141,7 @@ static int mov_write_stsz_tag(ByteIOContext *pb, MOVTrack* track) put_be32(pb, 0); // sample size put_be32(pb, entries); // sample count for (i=0; ientry; i++) { - for ( j=0; jcluster[i].entries; j++) { + for (j=0; jcluster[i].entries; j++) { put_be32(pb, track->cluster[i].size / track->cluster[i].entries); } @@ -322,6 +323,14 @@ static int mov_write_wave_tag(ByteIOContext *pb, MOVTrack* track) return updateSize (pb, pos); } +static int mov_write_glbl_tag(ByteIOContext *pb, MOVTrack* track) +{ + put_be32(pb, track->vosLen+8); + put_tag(pb, "glbl"); + put_buffer(pb, track->vosData, track->vosLen); + return 8+track->vosLen; +} + static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack* track) { offset_t pos = url_ftell(pb); @@ -372,10 +381,12 @@ static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack* track) track->enc->codec_id == CODEC_ID_PCM_S24LE || track->enc->codec_id == CODEC_ID_PCM_S32LE)) mov_write_wave_tag(pb, track); - else if(track->enc->codec_id == CODEC_ID_AAC) + else if(track->tag == MKTAG('m','p','4','a')) mov_write_esds_tag(pb, track); else if(track->enc->codec_id == CODEC_ID_AMR_NB) mov_write_amr_tag(pb, track); + else if(track->vosLen > 0) + mov_write_glbl_tag(pb, track); return updateSize (pb, pos); } @@ -405,170 +416,128 @@ static int mov_write_svq3_tag(ByteIOContext *pb) return 0x15; } -static uint8_t *avc_find_startcode( uint8_t *p, uint8_t *end ) -{ - uint8_t *a = p + 4 - ((int)p & 3); - - for( end -= 3; p < a && p < end; p++ ) { - if( p[0] == 0 && p[1] == 0 && p[2] == 1 ) - return p; - } - - for( end -= 3; p < end; p += 4 ) { - uint32_t x = *(uint32_t*)p; -// if( (x - 0x01000100) & (~x) & 0x80008000 ) // little endian -// if( (x - 0x00010001) & (~x) & 0x00800080 ) // big endian - if( (x - 0x01010101) & (~x) & 0x80808080 ) { // generic - if( p[1] == 0 ) { - if( p[0] == 0 && p[2] == 1 ) - return p-1; - if( p[2] == 0 && p[3] == 1 ) - return p; - } - if( p[3] == 0 ) { - if( p[2] == 0 && p[4] == 1 ) - return p+1; - if( p[4] == 0 && p[5] == 1 ) - return p+2; - } - } - } - - for( end += 3; p < end; p++ ) { - if( p[0] == 0 && p[1] == 0 && p[2] == 1 ) - return p; - } - - return end + 3; -} - -static void avc_parse_nal_units(uint8_t **buf, int *size) -{ - ByteIOContext pb; - uint8_t *p = *buf; - uint8_t *end = p + *size; - uint8_t *nal_start, *nal_end; - - url_open_dyn_buf(&pb); - nal_start = avc_find_startcode(p, end); - while (nal_start < end) { - while(!*(nal_start++)); - nal_end = avc_find_startcode(nal_start, end); - put_be32(&pb, nal_end - nal_start); - put_buffer(&pb, nal_start, nal_end - nal_start); - nal_start = nal_end; - } - av_freep(buf); - *size = url_close_dyn_buf(&pb, buf); -} - static int mov_write_avcc_tag(ByteIOContext *pb, MOVTrack *track) { offset_t pos = url_ftell(pb); put_be32(pb, 0); put_tag(pb, "avcC"); - if (track->vosLen > 6) { - /* check for h264 start code */ - if (AV_RB32(track->vosData) == 0x00000001) { - uint8_t *buf, *end; - uint32_t sps_size=0, pps_size=0; - uint8_t *sps=0, *pps=0; - - avc_parse_nal_units(&track->vosData, &track->vosLen); - buf = track->vosData; - end = track->vosData + track->vosLen; - - /* look for sps and pps */ - while (buf < end) { - unsigned int size; - uint8_t nal_type; - size = AV_RB32(buf); - nal_type = buf[4] & 0x1f; - if (nal_type == 7) { /* SPS */ - sps = buf + 4; - sps_size = size; - } else if (nal_type == 8) { /* PPS */ - pps = buf + 4; - pps_size = size; - } - buf += size + 4; - } - assert(sps); - assert(pps); - - put_byte(pb, 1); /* version */ - put_byte(pb, sps[1]); /* profile */ - put_byte(pb, sps[2]); /* profile compat */ - put_byte(pb, sps[3]); /* level */ - put_byte(pb, 0xff); /* 6 bits reserved (111111) + 2 bits nal size length - 1 (11) */ - put_byte(pb, 0xe1); /* 3 bits reserved (111) + 5 bits number of sps (00001) */ - - put_be16(pb, sps_size); - put_buffer(pb, sps, sps_size); - put_byte(pb, 1); /* number of pps */ - put_be16(pb, pps_size); - put_buffer(pb, pps, pps_size); - } else { - put_buffer(pb, track->vosData, track->vosLen); - } - } + ff_isom_write_avcc(pb, track->vosData, track->vosLen); return updateSize(pb, pos); } -static int mov_find_video_codec_tag(AVFormatContext *s, MOVTrack *track) +/* also used by all avid codecs (dv, imx, meridien) and their variants */ +static int mov_write_avid_tag(ByteIOContext *pb, MOVTrack *track) { - int tag = track->enc->codec_tag; - if (!tag) { - if (track->enc->codec_id == CODEC_ID_DVVIDEO) { - if (track->enc->height == 480) { /* NTSC */ - if (track->enc->pix_fmt == PIX_FMT_YUV422P) - tag = MKTAG('d', 'v', '5', 'n'); - else - tag = MKTAG('d', 'v', 'c', ' '); - } else { /* assume PAL */ - if (track->enc->pix_fmt == PIX_FMT_YUV422P) - tag = MKTAG('d', 'v', '5', 'p'); - else if (track->enc->pix_fmt == PIX_FMT_YUV420P) - tag = MKTAG('d', 'v', 'c', 'p'); - else - tag = MKTAG('d', 'v', 'p', 'p'); - } - } else if (track->enc->codec_id == CODEC_ID_H263) { - if (track->mode == MODE_MOV) - tag = MKTAG('h', '2', '6', '3'); - else - tag = MKTAG('s', '2', '6', '3'); - } else { - tag = codec_get_tag(codec_movvideo_tags, track->enc->codec_id); - } - } - // if no mac fcc found, try with Microsoft tags - if (!tag) { - tag = codec_get_tag(codec_bmp_tags, track->enc->codec_id); - if (tag) { - av_log(s, AV_LOG_INFO, "Warning, using MS style video codec tag, the file may be unplayable!\n"); - } + int i; + put_be32(pb, 24); /* size */ + put_tag(pb, "ACLR"); + put_tag(pb, "ACLR"); + put_tag(pb, "0001"); + put_be32(pb, 1); /* yuv 1 / rgb 2 ? */ + put_be32(pb, 0); /* unknown */ + + put_be32(pb, 24); /* size */ + put_tag(pb, "APRG"); + put_tag(pb, "APRG"); + put_tag(pb, "0001"); + put_be32(pb, 1); /* unknown */ + put_be32(pb, 0); /* unknown */ + + put_be32(pb, 120); /* size */ + put_tag(pb, "ARES"); + put_tag(pb, "ARES"); + put_tag(pb, "0001"); + put_be32(pb, AV_RB32(track->vosData + 0x28)); /* dnxhd cid, some id ? */ + put_be32(pb, track->enc->width); + /* values below are based on samples created with quicktime and avid codecs */ + if (track->vosData[5] & 2) { // interlaced + put_be32(pb, track->enc->height/2); + put_be32(pb, 2); /* unknown */ + put_be32(pb, 0); /* unknown */ + put_be32(pb, 4); /* unknown */ + } else { + put_be32(pb, track->enc->height); + put_be32(pb, 1); /* unknown */ + put_be32(pb, 0); /* unknown */ + if (track->enc->height == 1080) + put_be32(pb, 5); /* unknown */ + else + put_be32(pb, 6); /* unknown */ } - assert(tag); - return tag; + /* padding */ + for (i = 0; i < 10; i++) + put_be64(pb, 0); + + /* extra padding for stsd needed */ + put_be32(pb, 0); + return 0; } -static int mov_find_audio_codec_tag(AVFormatContext *s, MOVTrack *track) +static const AVCodecTag codec_3gp_tags[] = { + { CODEC_ID_H263, MKTAG('s','2','6','3') }, + { CODEC_ID_H264, MKTAG('a','v','c','1') }, + { CODEC_ID_MPEG4, MKTAG('m','p','4','v') }, + { CODEC_ID_AAC, MKTAG('m','p','4','a') }, + { CODEC_ID_AMR_NB, MKTAG('s','a','m','r') }, + { CODEC_ID_AMR_WB, MKTAG('s','a','w','b') }, +}; + +static const AVCodecTag mov_pix_fmt_tags[] = { + { PIX_FMT_YUYV422, MKTAG('y','u','v','s') }, + { PIX_FMT_UYVY422, MKTAG('2','v','u','y') }, + { PIX_FMT_BGR555, MKTAG('r','a','w',' ') }, + { PIX_FMT_RGB24, MKTAG('r','a','w',' ') }, + { PIX_FMT_BGR32_1, MKTAG('r','a','w',' ') }, +}; + +static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track) { int tag = track->enc->codec_tag; - if (!tag) { - tag = codec_get_tag(codec_movaudio_tags, track->enc->codec_id); - } - // if no mac fcc found, try with Microsoft tags - if (!tag) { - int ms_tag = codec_get_tag(codec_wav_tags, track->enc->codec_id); - if (ms_tag) { - tag = MKTAG('m', 's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff)); - av_log(s, AV_LOG_INFO, "Warning, using MS style audio codec tag, the file may be unplayable!\n"); + if (track->mode == MODE_MP4 || track->mode == MODE_PSP) { + if (!codec_get_tag(ff_mp4_obj_type, track->enc->codec_id)) + return 0; + if (track->enc->codec_id == CODEC_ID_H264) tag = MKTAG('a','v','c','1'); + else if (track->enc->codec_type == CODEC_TYPE_VIDEO) tag = MKTAG('m','p','4','v'); + else if (track->enc->codec_type == CODEC_TYPE_AUDIO) tag = MKTAG('m','p','4','a'); + } else if (track->mode == MODE_3GP || track->mode == MODE_3G2) { + tag = codec_get_tag(codec_3gp_tags, track->enc->codec_id); + } else if (!tag || (track->enc->strict_std_compliance >= FF_COMPLIANCE_NORMAL && + (tag == MKTAG('d','v','c','p') || + track->enc->codec_id == CODEC_ID_RAWVIDEO))) { + if (track->enc->codec_id == CODEC_ID_DVVIDEO) { + if (track->enc->height == 480) /* NTSC */ + if (track->enc->pix_fmt == PIX_FMT_YUV422P) tag = MKTAG('d','v','5','n'); + else tag = MKTAG('d','v','c',' '); + else if (track->enc->pix_fmt == PIX_FMT_YUV422P) tag = MKTAG('d','v','5','p'); + else if (track->enc->pix_fmt == PIX_FMT_YUV420P) tag = MKTAG('d','v','c','p'); + else tag = MKTAG('d','v','p','p'); + } else if (track->enc->codec_id == CODEC_ID_RAWVIDEO) { + tag = codec_get_tag(mov_pix_fmt_tags, track->enc->pix_fmt); + if (!tag) // restore tag + tag = track->enc->codec_tag; + } else { + if (track->enc->codec_type == CODEC_TYPE_VIDEO) { + tag = codec_get_tag(codec_movvideo_tags, track->enc->codec_id); + if (!tag) { // if no mac fcc found, try with Microsoft tags + tag = codec_get_tag(codec_bmp_tags, track->enc->codec_id); + if (tag) + av_log(s, AV_LOG_INFO, "Warning, using MS style video codec tag, " + "the file may be unplayable!\n"); + } + } else if (track->enc->codec_type == CODEC_TYPE_AUDIO) { + tag = codec_get_tag(codec_movaudio_tags, track->enc->codec_id); + if (!tag) { // if no mac fcc found, try with Microsoft tags + int ms_tag = codec_get_tag(codec_wav_tags, track->enc->codec_id); + if (ms_tag) { + tag = MKTAG('m', 's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff)); + av_log(s, AV_LOG_INFO, "Warning, using MS style audio codec tag, " + "the file may be unplayable!\n"); + } + } + } } } - assert(tag); return tag; } @@ -613,9 +582,12 @@ static int mov_write_video_tag(ByteIOContext *pb, MOVTrack* track) put_byte(pb, strlen(compressor_name)); put_buffer(pb, compressor_name, 31); - put_be16(pb, 0x18); /* Reserved */ + if (track->mode == MODE_MOV && track->enc->bits_per_sample) + put_be16(pb, track->enc->bits_per_sample); + else + put_be16(pb, 0x18); /* Reserved */ put_be16(pb, 0xffff); /* Reserved */ - if(track->enc->codec_id == CODEC_ID_MPEG4) + if(track->tag == MKTAG('m','p','4','v')) mov_write_esds_tag(pb, track); else if(track->enc->codec_id == CODEC_ID_H263) mov_write_d263_tag(pb); @@ -623,6 +595,10 @@ static int mov_write_video_tag(ByteIOContext *pb, MOVTrack* track) mov_write_svq3_tag(pb); else if(track->enc->codec_id == CODEC_ID_H264) mov_write_avcc_tag(pb, track); + else if(track->enc->codec_id == CODEC_ID_DNXHD) + mov_write_avid_tag(pb, track); + else if(track->vosLen > 0) + mov_write_glbl_tag(pb, track); return updateSize (pb, pos); } @@ -643,7 +619,7 @@ static int mov_write_stsd_tag(ByteIOContext *pb, MOVTrack* track) static int mov_write_ctts_tag(ByteIOContext *pb, MOVTrack* track) { - Time2Sample *ctts_entries; + MOV_stts_t *ctts_entries; uint32_t entries = 0; uint32_t atom_size; int i; @@ -677,7 +653,7 @@ static int mov_write_ctts_tag(ByteIOContext *pb, MOVTrack* track) /* Time to sample atom */ static int mov_write_stts_tag(ByteIOContext *pb, MOVTrack* track) { - Time2Sample *stts_entries; + MOV_stts_t *stts_entries; uint32_t entries = -1; uint32_t atom_size; int i; @@ -845,6 +821,14 @@ static int mov_write_mdhd_tag(ByteIOContext *pb, MOVTrack* track) (version == 1) ? put_be64(pb, track->trackDuration) : put_be32(pb, track->trackDuration); /* duration */ put_be16(pb, track->language); /* language */ put_be16(pb, 0); /* reserved (quality) */ + + if(version!=0 && track->mode == MODE_MOV){ + av_log(NULL, AV_LOG_ERROR, + "FATAL error, file duration too long for timebase, this file will not be\n" + "playable with quicktime. Choose a different timebase or a different\n" + "container format\n"); + } + return 32; } @@ -903,7 +887,7 @@ static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack* track) /* Track width and height, for visual only */ if(track->enc->codec_type == CODEC_TYPE_VIDEO) { double sample_aspect_ratio = av_q2d(track->enc->sample_aspect_ratio); - if( !sample_aspect_ratio ) sample_aspect_ratio = 1; + if(!sample_aspect_ratio) sample_aspect_ratio = 1; put_be32(pb, sample_aspect_ratio * track->enc->width*0x10000); put_be32(pb, track->enc->height*0x10000); } @@ -1075,7 +1059,7 @@ static int mov_write_string_data_tag(ByteIOContext *pb, const char *data, int lo static int mov_write_string_tag(ByteIOContext *pb, const char *name, const char *value, int long_style){ int size = 0; - if ( value && value[0] ) { + if (value && value[0]) { offset_t pos = url_ftell(pb); put_be32(pb, 0); /* size */ put_tag(pb, name); @@ -1101,7 +1085,7 @@ static int mov_write_trkn_tag(ByteIOContext *pb, MOVContext* mov, AVFormatContext *s) { int size = 0; - if ( s->track ) { + if (s->track) { offset_t pos = url_ftell(pb); put_be32(pb, 0); /* size */ put_tag(pb, "trkn"); @@ -1149,8 +1133,8 @@ static int mov_write_meta_tag(ByteIOContext *pb, MOVContext* mov, int size = 0; // only save meta tag if required - if ( s->title[0] || s->author[0] || s->album[0] || s->year || - s->comment[0] || s->genre[0] || s->track ) { + if (s->title[0] || s->author[0] || s->album[0] || s->year || + s->comment[0] || s->genre[0] || s->track) { offset_t pos = url_ftell(pb); put_be32(pb, 0); /* size */ put_tag(pb, "meta"); @@ -1165,40 +1149,52 @@ static int mov_write_meta_tag(ByteIOContext *pb, MOVContext* mov, static int mov_write_udta_tag(ByteIOContext *pb, MOVContext* mov, AVFormatContext *s) { - offset_t pos = url_ftell(pb); - int i; - - put_be32(pb, 0); /* size */ - put_tag(pb, "udta"); - - /* iTunes meta data */ - mov_write_meta_tag(pb, mov, s); + int i, req = 0; - if(mov->mode == MODE_MOV){ // the title field breaks gtkpod with mp4 and my suspicion is that stuff isnt valid in mp4 /* Requirements */ for (i=0; inb_streams; i++) { if(mov->tracks[i].entry <= 0) continue; if (mov->tracks[i].enc->codec_id == CODEC_ID_AAC || mov->tracks[i].enc->codec_id == CODEC_ID_MPEG4) { - mov_write_string_tag(pb, "\251req", "QuickTime 6.0 or greater", 0); + req = 1; break; } } - mov_write_string_tag(pb, "\251nam", s->title , 0); - mov_write_string_tag(pb, "\251aut", s->author , 0); - mov_write_string_tag(pb, "\251alb", s->album , 0); - mov_write_day_tag(pb, s->year, 0); - if(mov->tracks[0].enc && !(mov->tracks[0].enc->flags & CODEC_FLAG_BITEXACT)) - mov_write_string_tag(pb, "\251enc", LIBAVFORMAT_IDENT, 0); - mov_write_string_tag(pb, "\251des", s->comment , 0); - mov_write_string_tag(pb, "\251gen", s->genre , 0); - } + if (s->title[0] || s->author[0] || s->album[0] || s->year || + s->comment[0] || s->genre[0] || s->track || + (mov->mode == MODE_MOV && + ((mov->tracks[0].enc && !mov->tracks[0].enc->flags & CODEC_FLAG_BITEXACT) || req))) { + offset_t pos = url_ftell(pb); - return updateSize(pb, pos); + put_be32(pb, 0); /* size */ + put_tag(pb, "udta"); + + /* iTunes meta data */ + mov_write_meta_tag(pb, mov, s); + + if(mov->mode == MODE_MOV){ // the title field breaks gtkpod with mp4 and my suspicion is that stuff is not valid in mp4 + /* Requirements */ + if (req) + mov_write_string_tag(pb, "\251req", "QuickTime 6.0 or greater", 0); + + mov_write_string_tag(pb, "\251nam", s->title , 0); + mov_write_string_tag(pb, "\251aut", s->author , 0); + mov_write_string_tag(pb, "\251alb", s->album , 0); + mov_write_day_tag(pb, s->year, 0); + if(mov->tracks[0].enc && !(mov->tracks[0].enc->flags & CODEC_FLAG_BITEXACT)) + mov_write_string_tag(pb, "\251enc", LIBAVFORMAT_IDENT, 0); + mov_write_string_tag(pb, "\251des", s->comment , 0); + mov_write_string_tag(pb, "\251gen", s->genre , 0); + } + + return updateSize(pb, pos); + } + + return 0; } -static int utf8len(uint8_t *b){ +static int utf8len(const uint8_t *b){ int len=0; int val; while(*b){ @@ -1208,7 +1204,7 @@ static int utf8len(uint8_t *b){ return len; } -static int ascii_to_wc (ByteIOContext *pb, uint8_t *b) +static int ascii_to_wc (ByteIOContext *pb, const uint8_t *b) { int val; while(*b){ @@ -1235,9 +1231,9 @@ static int mov_write_uuidusmt_tag (ByteIOContext *pb, AVFormatContext *s) put_be32(pb, 0); /* size placeholder*/ put_tag(pb, "uuid"); put_tag(pb, "USMT"); - put_be32(pb, 0x21d24fce ); /* 96 bit UUID */ - put_be32(pb, 0xbb88695c ); - put_be32(pb, 0xfac9c740 ); + put_be32(pb, 0x21d24fce); /* 96 bit UUID */ + put_be32(pb, 0xbb88695c); + put_be32(pb, 0xfac9c740); size += 24; put_be32(pb, 0); /* size placeholder*/ @@ -1328,7 +1324,7 @@ static int mov_write_moov_tag(ByteIOContext *pb, MOVContext *mov, if (mov->mode == MODE_PSP) mov_write_uuidusmt_tag(pb, s); - else + else if (mov->mode != MODE_3GP && mov->mode != MODE_3G2) mov_write_udta_tag(pb, mov, s); return updateSize(pb, pos); @@ -1350,29 +1346,29 @@ static void mov_write_ftyp_tag (ByteIOContext *pb, AVFormatContext *s) { MOVContext *mov = s->priv_data; - put_be32(pb, 0x14 ); /* size */ + put_be32(pb, 0x14); /* size */ put_tag(pb, "ftyp"); - if ( mov->mode == MODE_3GP ) + if (mov->mode == MODE_3GP) put_tag(pb, "3gp4"); - else if ( mov->mode == MODE_3G2 ) + else if (mov->mode == MODE_3G2) put_tag(pb, "3g2a"); - else if ( mov->mode == MODE_PSP ) + else if (mov->mode == MODE_PSP) put_tag(pb, "MSNV"); - else if ( mov->mode == MODE_MP4 ) + else if (mov->mode == MODE_MP4) put_tag(pb, "isom"); else put_tag(pb, "qt "); - put_be32(pb, 0x200 ); + put_be32(pb, 0x200); - if ( mov->mode == MODE_3GP ) + if (mov->mode == MODE_3GP) put_tag(pb, "3gp4"); - else if ( mov->mode == MODE_3G2 ) + else if (mov->mode == MODE_3G2) put_tag(pb, "3g2a"); - else if ( mov->mode == MODE_PSP ) + else if (mov->mode == MODE_PSP) put_tag(pb, "MSNV"); - else if ( mov->mode == MODE_MP4 ) + else if (mov->mode == MODE_MP4) put_tag(pb, "mp41"); else put_tag(pb, "qt "); @@ -1387,49 +1383,49 @@ static void mov_write_uuidprof_tag(ByteIOContext *pb, AVFormatContext *s) int audio_kbitrate= AudioCodec->bit_rate / 1000; int video_kbitrate= FFMIN(VideoCodec->bit_rate / 1000, 800 - audio_kbitrate); - put_be32(pb, 0x94 ); /* size */ + put_be32(pb, 0x94); /* size */ put_tag(pb, "uuid"); put_tag(pb, "PROF"); - put_be32(pb, 0x21d24fce ); /* 96 bit UUID */ - put_be32(pb, 0xbb88695c ); - put_be32(pb, 0xfac9c740 ); + put_be32(pb, 0x21d24fce); /* 96 bit UUID */ + put_be32(pb, 0xbb88695c); + put_be32(pb, 0xfac9c740); - put_be32(pb, 0x0 ); /* ? */ - put_be32(pb, 0x3 ); /* 3 sections ? */ + put_be32(pb, 0x0); /* ? */ + put_be32(pb, 0x3); /* 3 sections ? */ - put_be32(pb, 0x14 ); /* size */ + put_be32(pb, 0x14); /* size */ put_tag(pb, "FPRF"); - put_be32(pb, 0x0 ); /* ? */ - put_be32(pb, 0x0 ); /* ? */ - put_be32(pb, 0x0 ); /* ? */ + put_be32(pb, 0x0); /* ? */ + put_be32(pb, 0x0); /* ? */ + put_be32(pb, 0x0); /* ? */ - put_be32(pb, 0x2c ); /* size */ + put_be32(pb, 0x2c); /* size */ put_tag(pb, "APRF"); /* audio */ - put_be32(pb, 0x0 ); - put_be32(pb, 0x2 ); /* TrackID */ + put_be32(pb, 0x0); + put_be32(pb, 0x2); /* TrackID */ put_tag(pb, "mp4a"); - put_be32(pb, 0x20f ); - put_be32(pb, 0x0 ); + put_be32(pb, 0x20f); + put_be32(pb, 0x0); put_be32(pb, audio_kbitrate); put_be32(pb, audio_kbitrate); - put_be32(pb, AudioRate ); - put_be32(pb, AudioCodec->channels ); + put_be32(pb, AudioRate); + put_be32(pb, AudioCodec->channels); - put_be32(pb, 0x34 ); /* size */ + put_be32(pb, 0x34); /* size */ put_tag(pb, "VPRF"); /* video */ - put_be32(pb, 0x0 ); - put_be32(pb, 0x1 ); /* TrackID */ + put_be32(pb, 0x0); + put_be32(pb, 0x1); /* TrackID */ if (VideoCodec->codec_id == CODEC_ID_H264) { put_tag(pb, "avc1"); - put_be16(pb, 0x014D ); - put_be16(pb, 0x0015 ); + put_be16(pb, 0x014D); + put_be16(pb, 0x0015); } else { put_tag(pb, "mp4v"); - put_be16(pb, 0x0000 ); - put_be16(pb, 0x0103 ); + put_be16(pb, 0x0000); + put_be16(pb, 0x0103); } - put_be32(pb, 0x0 ); + put_be32(pb, 0x0); put_be32(pb, video_kbitrate); put_be32(pb, video_kbitrate); put_be32(pb, FrameRate); @@ -1441,10 +1437,15 @@ static void mov_write_uuidprof_tag(ByteIOContext *pb, AVFormatContext *s) static int mov_write_header(AVFormatContext *s) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; MOVContext *mov = s->priv_data; int i; + if (url_is_streamed(s->pb)) { + av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n"); + return -1; + } + /* Default mode == MP4 */ mov->mode = MODE_MP4; @@ -1455,8 +1456,8 @@ static int mov_write_header(AVFormatContext *s) else if (!strcmp("psp", s->oformat->name)) mov->mode = MODE_PSP; mov_write_ftyp_tag(pb,s); - if ( mov->mode == MODE_PSP ) { - if ( s->nb_streams != 2 ) { + if (mov->mode == MODE_PSP) { + if (s->nb_streams != 2) { av_log(s, AV_LOG_ERROR, "PSP mode need one video and one audio stream\n"); return -1; } @@ -1471,12 +1472,20 @@ static int mov_write_header(AVFormatContext *s) track->enc = st->codec; track->language = ff_mov_iso639_to_lang(st->language, mov->mode != MODE_MOV); track->mode = mov->mode; + track->tag = mov_find_codec_tag(s, track); + if (!track->tag) { + av_log(s, AV_LOG_ERROR, "track %d: could not find tag for codec\n", i); + return -1; + } if(st->codec->codec_type == CODEC_TYPE_VIDEO){ - track->tag = mov_find_video_codec_tag(s, track); track->timescale = st->codec->time_base.den; av_set_pts_info(st, 64, 1, st->codec->time_base.den); + if (track->mode == MODE_MOV && track->timescale > 100000) + av_log(s, AV_LOG_WARNING, + "WARNING codec timebase is very high. If duration is too long,\n" + "file may not be playable by quicktime. Specify a shorter timebase\n" + "or choose different container.\n"); }else if(st->codec->codec_type == CODEC_TYPE_AUDIO){ - track->tag = mov_find_audio_codec_tag(s, track); track->timescale = st->codec->sample_rate; av_set_pts_info(st, 64, 1, st->codec->sample_rate); if(!st->codec->frame_size){ @@ -1502,13 +1511,13 @@ static int mov_write_header(AVFormatContext *s) static int mov_write_packet(AVFormatContext *s, AVPacket *pkt) { MOVContext *mov = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; MOVTrack *trk = &mov->tracks[pkt->stream_index]; AVCodecContext *enc = trk->enc; unsigned int samplesInChunk = 0; int size= pkt->size; - if (url_is_streamed(&s->pb)) return 0; /* Can't handle that */ + if (url_is_streamed(s->pb)) return 0; /* Can't handle that */ if (!size) return 0; /* Discard 0 sized packets */ if (enc->codec_id == CODEC_ID_AMR_NB) { @@ -1522,7 +1531,7 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt) samplesInChunk++; } if(samplesInChunk > 1){ - av_log(s, AV_LOG_ERROR, "fatal error, input is not a single packet, inplement a AVParser for it\n"); + av_log(s, AV_LOG_ERROR, "fatal error, input is not a single packet, implement a AVParser for it\n"); return -1; } } else if (trk->sampleSize) @@ -1540,9 +1549,18 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt) if (enc->codec_id == CODEC_ID_H264 && trk->vosLen > 0 && *(uint8_t *)trk->vosData != 1) { /* from x264 or from bytestream h264 */ /* nal reformating needed */ - avc_parse_nal_units(&pkt->data, &pkt->size); + int ret = ff_avc_parse_nal_units(pkt->data, &pkt->data, &pkt->size); + if (ret < 0) + return ret; assert(pkt->size); size = pkt->size; + } else if (enc->codec_id == CODEC_ID_DNXHD && !trk->vosLen) { + /* copy frame header to create needed atoms */ + if (size < 640) + return -1; + trk->vosLen = 640; + trk->vosData = av_malloc(trk->vosLen); + memcpy(trk->vosData, pkt->data, 640); } if (!(trk->entry % MOV_INDEX_CLUSTER_SIZE)) { @@ -1579,7 +1597,7 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt) static int mov_write_trailer(AVFormatContext *s) { MOVContext *mov = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int res = 0; int i; @@ -1603,7 +1621,7 @@ static int mov_write_trailer(AVFormatContext *s) for (i=0; inb_streams; i++) { av_freep(&mov->tracks[i].cluster); - if( mov->tracks[i].vosLen ) av_free( mov->tracks[i].vosData ); + if(mov->tracks[i].vosLen) av_free(mov->tracks[i].vosData); } @@ -1625,6 +1643,7 @@ AVOutputFormat mov_muxer = { mov_write_packet, mov_write_trailer, .flags = AVFMT_GLOBALHEADER, + .codec_tag = (const AVCodecTag*[]){codec_movvideo_tags, codec_movaudio_tags, 0}, }; #endif #ifdef CONFIG_TGP_MUXER @@ -1640,6 +1659,7 @@ AVOutputFormat tgp_muxer = { mov_write_packet, mov_write_trailer, .flags = AVFMT_GLOBALHEADER, + .codec_tag = (const AVCodecTag*[]){codec_3gp_tags, 0}, }; #endif #ifdef CONFIG_MP4_MUXER @@ -1655,6 +1675,7 @@ AVOutputFormat mp4_muxer = { mov_write_packet, mov_write_trailer, .flags = AVFMT_GLOBALHEADER, + .codec_tag = (const AVCodecTag*[]){ff_mp4_obj_type, 0}, }; #endif #ifdef CONFIG_PSP_MUXER @@ -1670,6 +1691,7 @@ AVOutputFormat psp_muxer = { mov_write_packet, mov_write_trailer, .flags = AVFMT_GLOBALHEADER, + .codec_tag = (const AVCodecTag*[]){ff_mp4_obj_type, 0}, }; #endif #ifdef CONFIG_TG2_MUXER @@ -1685,5 +1707,6 @@ AVOutputFormat tg2_muxer = { mov_write_packet, mov_write_trailer, .flags = AVFMT_GLOBALHEADER, + .codec_tag = (const AVCodecTag*[]){codec_3gp_tags, 0}, }; #endif diff --git a/contrib/ffmpeg/libavformat/mp3.c b/contrib/ffmpeg/libavformat/mp3.c index e86ea14c8..64e0ce285 100644 --- a/contrib/ffmpeg/libavformat/mp3.c +++ b/contrib/ffmpeg/libavformat/mp3.c @@ -20,13 +20,15 @@ */ #include "avformat.h" #include "mpegaudio.h" +#include "avstring.h" +#include "mpegaudiodecheader.h" -#define ID3_HEADER_SIZE 10 -#define ID3_TAG_SIZE 128 +#define ID3v2_HEADER_SIZE 10 +#define ID3v1_TAG_SIZE 128 -#define ID3_GENRE_MAX 125 +#define ID3v1_GENRE_MAX 125 -static const char *id3_genre_str[ID3_GENRE_MAX + 1] = { +static const char *id3v1_genre_str[ID3v1_GENRE_MAX + 1] = { [0] = "Blues", [1] = "Classic Rock", [2] = "Country", @@ -155,8 +157,8 @@ static const char *id3_genre_str[ID3_GENRE_MAX + 1] = { [125] = "Dance Hall", }; -/* buf must be ID3_HEADER_SIZE byte long */ -static int id3_match(const uint8_t *buf) +/* buf must be ID3v2_HEADER_SIZE byte long */ +static int id3v2_match(const uint8_t *buf) { return (buf[0] == 'I' && buf[1] == 'D' && @@ -169,8 +171,152 @@ static int id3_match(const uint8_t *buf) (buf[9] & 0x80) == 0); } -static void id3_get_string(char *str, int str_size, - const uint8_t *buf, int buf_size) +static unsigned int id3v2_get_size(ByteIOContext *s, int len) +{ + int v=0; + while(len--) + v= (v<<7) + (get_byte(s)&0x7F); + return v; +} + +static void id3v2_read_ttag(AVFormatContext *s, int taglen, char *dst, int dstlen) +{ + char *q; + int len; + + if(taglen < 1) + return; + + taglen--; /* account for encoding type byte */ + dstlen--; /* Leave space for zero terminator */ + + switch(get_byte(s->pb)) { /* encoding type */ + + case 0: /* ISO-8859-1 (0 - 255 maps directly into unicode) */ + q = dst; + while(taglen--) { + uint8_t tmp; + PUT_UTF8(get_byte(s->pb), tmp, if (q - dst < dstlen - 1) *q++ = tmp;) + } + *q = '\0'; + break; + + case 3: /* UTF-8 */ + len = FFMIN(taglen, dstlen); + get_buffer(s->pb, dst, len); + dst[len] = 0; + break; + } +} + +/** + * ID3v2 parser + * + * Handles ID3v2.2, 2.3 and 2.4. + * + */ + +static void id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags) +{ + int isv34, tlen; + uint32_t tag; + offset_t next; + char tmp[16]; + int taghdrlen; + const char *reason; + + switch(version) { + case 2: + if(flags & 0x40) { + reason = "compression"; + goto error; + } + isv34 = 0; + taghdrlen = 6; + break; + + case 3: + case 4: + isv34 = 1; + taghdrlen = 10; + break; + + default: + reason = "version"; + goto error; + } + + if(flags & 0x80) { + reason = "unsynchronization"; + goto error; + } + + if(isv34 && flags & 0x40) /* Extended header present, just skip over it */ + url_fskip(s->pb, id3v2_get_size(s->pb, 4)); + + while(len >= taghdrlen) { + if(isv34) { + tag = get_be32(s->pb); + tlen = id3v2_get_size(s->pb, 4); + get_be16(s->pb); /* flags */ + } else { + tag = get_be24(s->pb); + tlen = id3v2_get_size(s->pb, 3); + } + len -= taghdrlen + tlen; + + if(len < 0) + break; + + next = url_ftell(s->pb) + tlen; + + switch(tag) { + case MKBETAG('T', 'I', 'T', '2'): + case MKBETAG(0, 'T', 'T', '2'): + id3v2_read_ttag(s, tlen, s->title, sizeof(s->title)); + break; + case MKBETAG('T', 'P', 'E', '1'): + case MKBETAG(0, 'T', 'P', '1'): + id3v2_read_ttag(s, tlen, s->author, sizeof(s->author)); + break; + case MKBETAG('T', 'A', 'L', 'B'): + case MKBETAG(0, 'T', 'A', 'L'): + id3v2_read_ttag(s, tlen, s->album, sizeof(s->album)); + break; + case MKBETAG('T', 'C', 'O', 'N'): + case MKBETAG(0, 'T', 'C', 'O'): + id3v2_read_ttag(s, tlen, s->genre, sizeof(s->genre)); + break; + case MKBETAG('T', 'C', 'O', 'P'): + case MKBETAG(0, 'T', 'C', 'R'): + id3v2_read_ttag(s, tlen, s->copyright, sizeof(s->copyright)); + break; + case MKBETAG('T', 'R', 'C', 'K'): + case MKBETAG(0, 'T', 'R', 'K'): + id3v2_read_ttag(s, tlen, tmp, sizeof(tmp)); + s->track = atoi(tmp); + break; + case 0: + /* padding, skip to end */ + url_fskip(s->pb, len); + len = 0; + continue; + } + /* Skip to end of tag */ + url_fseek(s->pb, next, SEEK_SET); + } + + if(version == 4 && flags & 0x10) /* Footer preset, always 10 bytes, skip over it */ + url_fskip(s->pb, 10); + return; + + error: + av_log(s, AV_LOG_INFO, "ID3v2.%d tag skipped, cannot handle %s\n", version, reason); + url_fskip(s->pb, len); +} + +static void id3v1_get_string(char *str, int str_size, + const uint8_t *buf, int buf_size) { int i, c; char *q; @@ -187,8 +333,8 @@ static void id3_get_string(char *str, int str_size, *q = '\0'; } -/* 'buf' must be ID3_TAG_SIZE byte long */ -static int id3_parse_tag(AVFormatContext *s, const uint8_t *buf) +/* 'buf' must be ID3v1_TAG_SIZE byte long */ +static int id3v1_parse_tag(AVFormatContext *s, const uint8_t *buf) { char str[5]; int genre; @@ -197,25 +343,25 @@ static int id3_parse_tag(AVFormatContext *s, const uint8_t *buf) buf[1] == 'A' && buf[2] == 'G')) return -1; - id3_get_string(s->title, sizeof(s->title), buf + 3, 30); - id3_get_string(s->author, sizeof(s->author), buf + 33, 30); - id3_get_string(s->album, sizeof(s->album), buf + 63, 30); - id3_get_string(str, sizeof(str), buf + 93, 4); + id3v1_get_string(s->title, sizeof(s->title), buf + 3, 30); + id3v1_get_string(s->author, sizeof(s->author), buf + 33, 30); + id3v1_get_string(s->album, sizeof(s->album), buf + 63, 30); + id3v1_get_string(str, sizeof(str), buf + 93, 4); s->year = atoi(str); - id3_get_string(s->comment, sizeof(s->comment), buf + 97, 30); + id3v1_get_string(s->comment, sizeof(s->comment), buf + 97, 30); if (buf[125] == 0 && buf[126] != 0) s->track = buf[126]; genre = buf[127]; - if (genre <= ID3_GENRE_MAX) - pstrcpy(s->genre, sizeof(s->genre), id3_genre_str[genre]); + if (genre <= ID3v1_GENRE_MAX) + av_strlcpy(s->genre, id3v1_genre_str[genre], sizeof(s->genre)); return 0; } -static void id3_create_tag(AVFormatContext *s, uint8_t *buf) +static void id3v1_create_tag(AVFormatContext *s, uint8_t *buf) { int v, i; - memset(buf, 0, ID3_TAG_SIZE); /* fail safe */ + memset(buf, 0, ID3v1_TAG_SIZE); /* fail safe */ buf[0] = 'T'; buf[1] = 'A'; buf[2] = 'G'; @@ -234,8 +380,8 @@ static void id3_create_tag(AVFormatContext *s, uint8_t *buf) buf[125] = 0; buf[126] = s->track; } - for(i = 0; i <= ID3_GENRE_MAX; i++) { - if (!strcasecmp(s->genre, id3_genre_str[i])) { + for(i = 0; i <= ID3v1_GENRE_MAX; i++) { + if (!strcasecmp(s->genre, id3v1_genre_str[i])) { buf[127] = i; break; } @@ -246,28 +392,25 @@ static void id3_create_tag(AVFormatContext *s, uint8_t *buf) static int mp3_read_probe(AVProbeData *p) { - int max_frames, first_frames; + int max_frames, first_frames = 0; int fsize, frames, sample_rate; uint32_t header; uint8_t *buf, *buf2, *end; AVCodecContext avctx; - if(p->buf_size < ID3_HEADER_SIZE) - return 0; - - if(id3_match(p->buf)) - return AVPROBE_SCORE_MAX/2+1; // this must be less then mpeg-ps because some retards put id3 tage before mpeg-ps files + if(id3v2_match(p->buf)) + return AVPROBE_SCORE_MAX/2+1; // this must be less than mpeg-ps because some retards put id3v2 tags before mpeg-ps files max_frames = 0; buf = p->buf; - end = buf + FFMIN(4096, p->buf_size - sizeof(uint32_t)); + end = buf + p->buf_size - sizeof(uint32_t); - for(; buf < end; buf++) { + for(; buf < end; buf= buf2+1) { buf2 = buf; for(frames = 0; buf2 < end; frames++) { - header = (buf2[0] << 24) | (buf2[1] << 16) | (buf2[2] << 8) | buf2[3]; - fsize = mpa_decode_header(&avctx, header, &sample_rate); + header = AV_RB32(buf2); + fsize = ff_mpa_decode_header(&avctx, header, &sample_rate); if(fsize < 0) break; buf2 += fsize; @@ -277,55 +420,109 @@ static int mp3_read_probe(AVProbeData *p) first_frames= frames; } if (first_frames>=3) return AVPROBE_SCORE_MAX/2+1; + else if(max_frames>500)return AVPROBE_SCORE_MAX/2; else if(max_frames>=3) return AVPROBE_SCORE_MAX/4; else if(max_frames>=1) return 1; else return 0; } +/** + * Try to find Xing/Info/VBRI tags and compute duration from info therein + */ +static void mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, offset_t base) +{ + uint32_t v, spf; + int frames = -1; /* Total number of frames in file */ + const offset_t xing_offtbl[2][2] = {{32, 17}, {17,9}}; + MPADecodeContext c; + + v = get_be32(s->pb); + if(ff_mpa_check_header(v) < 0) + return; + + ff_mpegaudio_decode_header(&c, v); + if(c.layer != 3) + return; + + /* Check for Xing / Info tag */ + url_fseek(s->pb, xing_offtbl[c.lsf == 1][c.nb_channels == 1], SEEK_CUR); + v = get_be32(s->pb); + if(v == MKBETAG('X', 'i', 'n', 'g') || v == MKBETAG('I', 'n', 'f', 'o')) { + v = get_be32(s->pb); + if(v & 0x1) + frames = get_be32(s->pb); + } + + /* Check for VBRI tag (always 32 bytes after end of mpegaudio header) */ + url_fseek(s->pb, base + 4 + 32, SEEK_SET); + v = get_be32(s->pb); + if(v == MKBETAG('V', 'B', 'R', 'I')) { + /* Check tag version */ + if(get_be16(s->pb) == 1) { + /* skip delay, quality and total bytes */ + url_fseek(s->pb, 8, SEEK_CUR); + frames = get_be32(s->pb); + } + } + + if(frames < 0) + return; + + spf = c.lsf ? 576 : 1152; /* Samples per frame, layer 3 */ + st->duration = av_rescale_q(frames, (AVRational){spf, c.sample_rate}, + st->time_base); +} + static int mp3_read_header(AVFormatContext *s, AVFormatParameters *ap) { AVStream *st; - uint8_t buf[ID3_TAG_SIZE]; + uint8_t buf[ID3v1_TAG_SIZE]; int len, ret, filesize; + offset_t off; st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_MP3; - st->need_parsing = 1; + st->need_parsing = AVSTREAM_PARSE_FULL; + st->start_time = 0; /* try to get the TAG */ - if (!url_is_streamed(&s->pb)) { + if (!url_is_streamed(s->pb)) { /* XXX: change that */ - filesize = url_fsize(&s->pb); + filesize = url_fsize(s->pb); if (filesize > 128) { - url_fseek(&s->pb, filesize - 128, SEEK_SET); - ret = get_buffer(&s->pb, buf, ID3_TAG_SIZE); - if (ret == ID3_TAG_SIZE) { - id3_parse_tag(s, buf); + url_fseek(s->pb, filesize - 128, SEEK_SET); + ret = get_buffer(s->pb, buf, ID3v1_TAG_SIZE); + if (ret == ID3v1_TAG_SIZE) { + id3v1_parse_tag(s, buf); } - url_fseek(&s->pb, 0, SEEK_SET); + url_fseek(s->pb, 0, SEEK_SET); } } - /* if ID3 header found, skip it */ - ret = get_buffer(&s->pb, buf, ID3_HEADER_SIZE); - if (ret != ID3_HEADER_SIZE) + /* if ID3v2 header found, skip it */ + ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE); + if (ret != ID3v2_HEADER_SIZE) return -1; - if (id3_match(buf)) { - /* skip ID3 header */ + if (id3v2_match(buf)) { + /* parse ID3v2 header */ len = ((buf[6] & 0x7f) << 21) | ((buf[7] & 0x7f) << 14) | ((buf[8] & 0x7f) << 7) | (buf[9] & 0x7f); - url_fskip(&s->pb, len); + id3v2_parse(s, len, buf[3], buf[5]); } else { - url_fseek(&s->pb, 0, SEEK_SET); + url_fseek(s->pb, 0, SEEK_SET); } + off = url_ftell(s->pb); + mp3_parse_vbr_tags(s, st, off); + url_fseek(s->pb, off, SEEK_SET); + /* the parameters will be extracted from the compressed bitstream */ return 0; } @@ -339,11 +536,11 @@ static int mp3_read_packet(AVFormatContext *s, AVPacket *pkt) size= MP3_PACKET_SIZE; - ret= av_get_packet(&s->pb, pkt, size); + ret= av_get_packet(s->pb, pkt, size); pkt->stream_index = 0; if (ret <= 0) { - return AVERROR_IO; + return AVERROR(EIO); } /* note: we need to modify the packet size here to handle the last packet */ @@ -358,27 +555,88 @@ static int mp3_read_close(AVFormatContext *s) #ifdef CONFIG_MUXERS /* simple formats */ + +static void id3v2_put_size(AVFormatContext *s, int size) +{ + put_byte(s->pb, size >> 21 & 0x7f); + put_byte(s->pb, size >> 14 & 0x7f); + put_byte(s->pb, size >> 7 & 0x7f); + put_byte(s->pb, size & 0x7f); +} + +static void id3v2_put_ttag(AVFormatContext *s, const char *string, uint32_t tag) +{ + int len = strlen(string); + put_be32(s->pb, tag); + id3v2_put_size(s, len + 1); + put_be16(s->pb, 0); + put_byte(s->pb, 3); /* UTF-8 */ + put_buffer(s->pb, string, len); +} + + +/** + * Write an ID3v2.4 header at beginning of stream + */ + static int mp3_write_header(struct AVFormatContext *s) { + int totlen = 0; + char tracktxt[10]; + char yeartxt[10]; + + if(s->track) + snprintf(tracktxt, sizeof(tracktxt), "%d", s->track); + if(s->year) + snprintf( yeartxt, sizeof(yeartxt) , "%d", s->year ); + + if(s->title[0]) totlen += 11 + strlen(s->title); + if(s->author[0]) totlen += 11 + strlen(s->author); + if(s->album[0]) totlen += 11 + strlen(s->album); + if(s->genre[0]) totlen += 11 + strlen(s->genre); + if(s->copyright[0]) totlen += 11 + strlen(s->copyright); + if(s->track) totlen += 11 + strlen(tracktxt); + if(s->year) totlen += 11 + strlen(yeartxt); + if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) + totlen += strlen(LIBAVFORMAT_IDENT) + 11; + + if(totlen == 0) + return 0; + + put_be32(s->pb, MKBETAG('I', 'D', '3', 0x04)); /* ID3v2.4 */ + put_byte(s->pb, 0); + put_byte(s->pb, 0); /* flags */ + + id3v2_put_size(s, totlen); + + if(s->title[0]) id3v2_put_ttag(s, s->title, MKBETAG('T', 'I', 'T', '2')); + if(s->author[0]) id3v2_put_ttag(s, s->author, MKBETAG('T', 'P', 'E', '1')); + if(s->album[0]) id3v2_put_ttag(s, s->album, MKBETAG('T', 'A', 'L', 'B')); + if(s->genre[0]) id3v2_put_ttag(s, s->genre, MKBETAG('T', 'C', 'O', 'N')); + if(s->copyright[0]) id3v2_put_ttag(s, s->copyright, MKBETAG('T', 'C', 'O', 'P')); + if(s->track) id3v2_put_ttag(s, tracktxt, MKBETAG('T', 'R', 'C', 'K')); + if(s->year) id3v2_put_ttag(s, yeartxt, MKBETAG('T', 'Y', 'E', 'R')); + if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) + id3v2_put_ttag(s, LIBAVFORMAT_IDENT, MKBETAG('T', 'E', 'N', 'C')); return 0; } static int mp3_write_packet(struct AVFormatContext *s, AVPacket *pkt) { - put_buffer(&s->pb, pkt->data, pkt->size); - put_flush_packet(&s->pb); + put_buffer(s->pb, pkt->data, pkt->size); + put_flush_packet(s->pb); return 0; } static int mp3_write_trailer(struct AVFormatContext *s) { - uint8_t buf[ID3_TAG_SIZE]; + uint8_t buf[ID3v1_TAG_SIZE]; - /* write the id3 header */ + /* write the id3v1 tag */ if (s->title[0] != '\0') { - id3_create_tag(s, buf); - put_buffer(&s->pb, buf, ID3_TAG_SIZE); - put_flush_packet(&s->pb); + id3v1_create_tag(s, buf); + put_buffer(s->pb, buf, ID3v1_TAG_SIZE); + put_flush_packet(s->pb); } return 0; } @@ -410,7 +668,7 @@ AVOutputFormat mp2_muxer = { 0, CODEC_ID_MP2, 0, - mp3_write_header, + NULL, mp3_write_packet, mp3_write_trailer, }; diff --git a/contrib/ffmpeg/libavformat/mpc.c b/contrib/ffmpeg/libavformat/mpc.c index a28efb16d..8e6c573df 100644 --- a/contrib/ffmpeg/libavformat/mpc.c +++ b/contrib/ffmpeg/libavformat/mpc.c @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avformat.h" #include "bitstream.h" @@ -42,8 +42,6 @@ typedef struct { static int mpc_probe(AVProbeData *p) { const uint8_t *d = p->buf; - if (p->buf_size < 32) - return 0; if (d[0] == 'M' && d[1] == 'P' && d[2] == '+' && (d[3] == 0x17 || d[3] == 0x7)) return AVPROBE_SCORE_MAX; if (d[0] == 'I' && d[1] == 'D' && d[2] == '3') @@ -57,31 +55,31 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap) AVStream *st; int t; - t = get_le24(&s->pb); + t = get_le24(s->pb); if(t != MKTAG('M', 'P', '+', 0)){ if(t != MKTAG('I', 'D', '3', 0)){ av_log(s, AV_LOG_ERROR, "Not a Musepack file\n"); return -1; } /* skip ID3 tags and try again */ - url_fskip(&s->pb, 3); - t = get_byte(&s->pb) << 21; - t |= get_byte(&s->pb) << 14; - t |= get_byte(&s->pb) << 7; - t |= get_byte(&s->pb); + url_fskip(s->pb, 3); + t = get_byte(s->pb) << 21; + t |= get_byte(s->pb) << 14; + t |= get_byte(s->pb) << 7; + t |= get_byte(s->pb); av_log(s, AV_LOG_DEBUG, "Skipping %d(%X) bytes of ID3 data\n", t, t); - url_fskip(&s->pb, t); - if(get_le24(&s->pb) != MKTAG('M', 'P', '+', 0)){ + url_fskip(s->pb, t); + if(get_le24(s->pb) != MKTAG('M', 'P', '+', 0)){ av_log(s, AV_LOG_ERROR, "Not a Musepack file\n"); return -1; } } - c->ver = get_byte(&s->pb); + c->ver = get_byte(s->pb); if(c->ver != 0x07 && c->ver != 0x17){ av_log(s, AV_LOG_ERROR, "Can demux Musepack SV7, got version %02X\n", c->ver); return -1; } - c->fcount = get_le32(&s->pb); + c->fcount = get_le32(s->pb); if((int64_t)c->fcount * sizeof(MPCFrame) >= UINT_MAX){ av_log(s, AV_LOG_ERROR, "Too many frames, seeking is not possible\n"); return -1; @@ -94,7 +92,7 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap) st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_MUSEPACK7; st->codec->channels = 2; @@ -102,7 +100,7 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap) st->codec->extradata_size = 16; st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE); - get_buffer(&s->pb, st->codec->extradata, 16); + get_buffer(s->pb, st->codec->extradata, 16); st->codec->sample_rate = mpc_rate[st->codec->extradata[2] & 3]; av_set_pts_info(st, 32, MPC_FRAMESIZE, st->codec->sample_rate); /* scan for seekpoints */ @@ -122,22 +120,22 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt) return -1; if(c->curframe != c->lastframe + 1){ - url_fseek(&s->pb, c->frames[c->curframe].pos, SEEK_SET); + url_fseek(s->pb, c->frames[c->curframe].pos, SEEK_SET); c->curbits = c->frames[c->curframe].skip; } c->lastframe = c->curframe; c->curframe++; curbits = c->curbits; - pos = url_ftell(&s->pb); - tmp = get_le32(&s->pb); + pos = url_ftell(s->pb); + tmp = get_le32(s->pb); if(curbits <= 12){ size2 = (tmp >> (12 - curbits)) & 0xFFFFF; }else{ - tmp = (tmp << 32) | get_le32(&s->pb); + tmp = (tmp << 32) | get_le32(s->pb); size2 = (tmp >> (44 - curbits)) & 0xFFFFF; } curbits += 20; - url_fseek(&s->pb, pos, SEEK_SET); + url_fseek(s->pb, pos, SEEK_SET); size = ((size2 + curbits + 31) & ~31) >> 3; if(cur == c->frames_noted){ @@ -150,19 +148,19 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt) c->curbits = (curbits + size2) & 0x1F; if (av_new_packet(pkt, size) < 0) - return AVERROR_IO; + return AVERROR(EIO); pkt->data[0] = curbits; pkt->data[1] = (c->curframe > c->fcount); pkt->stream_index = 0; pkt->pts = cur; - ret = get_buffer(&s->pb, pkt->data + 4, size); + ret = get_buffer(s->pb, pkt->data + 4, size); if(c->curbits) - url_fseek(&s->pb, -4, SEEK_CUR); + url_fseek(s->pb, -4, SEEK_CUR); if(ret < size){ av_free_packet(pkt); - return AVERROR_IO; + return AVERROR(EIO); } pkt->size = ret + 4; diff --git a/contrib/ffmpeg/libavformat/mpc8.c b/contrib/ffmpeg/libavformat/mpc8.c new file mode 100644 index 000000000..879c7d236 --- /dev/null +++ b/contrib/ffmpeg/libavformat/mpc8.c @@ -0,0 +1,244 @@ +/* + * Musepack SV8 demuxer + * Copyright (c) 2007 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avformat.h" +#include "bitstream.h" +#include "unary.h" + +/// Two-byte MPC tag +#define MKMPCTAG(a, b) (a | (b << 8)) + +#define TAG_MPCK MKTAG('M','P','C','K') + +/// Reserved MPC tags +enum MPCPacketTags{ + TAG_STREAMHDR = MKMPCTAG('S','H'), + TAG_STREAMEND = MKMPCTAG('S','E'), + + TAG_AUDIOPACKET = MKMPCTAG('A','P'), + + TAG_SEEKTBLOFF = MKMPCTAG('S','O'), + TAG_SEEKTABLE = MKMPCTAG('S','T'), + + TAG_REPLAYGAIN = MKMPCTAG('R','G'), + TAG_ENCINFO = MKMPCTAG('E','I'), +}; + +static const int mpc8_rate[8] = { 44100, 48000, 37800, 32000, -1, -1, -1, -1 }; + +typedef struct { + int ver; + int frame; + int64_t header_pos; + int64_t samples; +} MPCContext; + +static int mpc8_probe(AVProbeData *p) +{ + if (AV_RL32(p->buf) == TAG_MPCK) + return AVPROBE_SCORE_MAX; + return 0; +} + +static inline int64_t gb_get_v(GetBitContext *gb) +{ + int64_t v = 0; + int bits = 0; + while(get_bits1(gb) && bits < 64-7){ + v <<= 7; + v |= get_bits(gb, 7); + bits += 7; + } + v <<= 7; + v |= get_bits(gb, 7); + + return v; +} + +static void mpc8_get_chunk_header(ByteIOContext *pb, int *tag, int64_t *size) +{ + int64_t pos; + pos = url_ftell(pb); + *tag = get_le16(pb); + *size = ff_get_v(pb); + *size -= url_ftell(pb) - pos; +} + +static void mpc8_parse_seektable(AVFormatContext *s, int64_t off) +{ + MPCContext *c = s->priv_data; + int tag; + int64_t size, pos, ppos[2]; + uint8_t *buf; + int i, t, seekd; + GetBitContext gb; + + url_fseek(s->pb, off, SEEK_SET); + mpc8_get_chunk_header(s->pb, &tag, &size); + if(tag != TAG_SEEKTABLE){ + av_log(s, AV_LOG_ERROR, "No seek table at given position\n"); + return; + } + if(!(buf = av_malloc(size))) + return; + get_buffer(s->pb, buf, size); + init_get_bits(&gb, buf, size * 8); + size = gb_get_v(&gb); + if(size > UINT_MAX/4 || size > c->samples/1152){ + av_log(s, AV_LOG_ERROR, "Seek table is too big\n"); + return; + } + seekd = get_bits(&gb, 4); + for(i = 0; i < 2; i++){ + pos = gb_get_v(&gb) + c->header_pos; + ppos[1 - i] = pos; + av_add_index_entry(s->streams[0], pos, i, 0, 0, AVINDEX_KEYFRAME); + } + for(; i < size; i++){ + t = get_unary(&gb, 1, 33) << 12; + t += get_bits(&gb, 12); + if(t & 1) + t = -(t & ~1); + pos = (t >> 1) + ppos[0]*2 - ppos[1]; + av_add_index_entry(s->streams[0], pos, i << seekd, 0, 0, AVINDEX_KEYFRAME); + ppos[1] = ppos[0]; + ppos[0] = pos; + } + av_free(buf); +} + +static void mpc8_handle_chunk(AVFormatContext *s, int tag, int64_t chunk_pos, int64_t size) +{ + ByteIOContext *pb = s->pb; + int64_t pos, off; + + switch(tag){ + case TAG_SEEKTBLOFF: + pos = url_ftell(pb) + size; + off = ff_get_v(pb); + mpc8_parse_seektable(s, chunk_pos + off); + url_fseek(pb, pos, SEEK_SET); + break; + default: + url_fskip(pb, size); + } +} + +static int mpc8_read_header(AVFormatContext *s, AVFormatParameters *ap) +{ + MPCContext *c = s->priv_data; + ByteIOContext *pb = s->pb; + AVStream *st; + int tag = 0; + int64_t size, pos; + + c->header_pos = url_ftell(pb); + if(get_le32(pb) != TAG_MPCK){ + av_log(s, AV_LOG_ERROR, "Not a Musepack8 file\n"); + return -1; + } + + while(!url_feof(pb)){ + pos = url_ftell(pb); + mpc8_get_chunk_header(pb, &tag, &size); + if(tag == TAG_STREAMHDR) + break; + mpc8_handle_chunk(s, tag, pos, size); + } + if(tag != TAG_STREAMHDR){ + av_log(s, AV_LOG_ERROR, "Stream header not found\n"); + return -1; + } + pos = url_ftell(pb); + url_fskip(pb, 4); //CRC + c->ver = get_byte(pb); + if(c->ver != 8){ + av_log(s, AV_LOG_ERROR, "Unknown stream version %d\n", c->ver); + return -1; + } + c->samples = ff_get_v(pb); + ff_get_v(pb); //silence samples at the beginning + + st = av_new_stream(s, 0); + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_MUSEPACK8; + st->codec->bits_per_sample = 16; + + st->codec->extradata_size = 2; + st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); + get_buffer(pb, st->codec->extradata, st->codec->extradata_size); + + st->codec->channels = (st->codec->extradata[1] >> 4) + 1; + st->codec->sample_rate = mpc8_rate[st->codec->extradata[0] >> 5]; + av_set_pts_info(st, 32, 1152 << (st->codec->extradata[1]&3)*2, st->codec->sample_rate); + st->duration = c->samples / (1152 << (st->codec->extradata[1]&3)*2); + size -= url_ftell(pb) - pos; + + return 0; +} + +static int mpc8_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + MPCContext *c = s->priv_data; + int tag; + int64_t pos, size; + + while(!url_feof(s->pb)){ + pos = url_ftell(s->pb); + mpc8_get_chunk_header(s->pb, &tag, &size); + if(tag == TAG_AUDIOPACKET){ + if(av_get_packet(s->pb, pkt, size) < 0) + return AVERROR(ENOMEM); + pkt->stream_index = 0; + pkt->pts = c->frame; + return 0; + } + if(tag == TAG_STREAMEND) + return AVERROR(EIO); + mpc8_handle_chunk(s, tag, pos, size); + } + return 0; +} + +static int mpc8_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) +{ + AVStream *st = s->streams[stream_index]; + MPCContext *c = s->priv_data; + int index = av_index_search_timestamp(st, timestamp, flags); + + if(index < 0) return -1; + url_fseek(s->pb, st->index_entries[index].pos, SEEK_SET); + c->frame = st->index_entries[index].timestamp; + return 0; +} + + +AVInputFormat mpc8_demuxer = { + "mpc8", + "musepack8", + sizeof(MPCContext), + mpc8_probe, + mpc8_read_header, + mpc8_read_packet, + NULL, + mpc8_read_seek, +}; diff --git a/contrib/ffmpeg/libavformat/mpeg.c b/contrib/ffmpeg/libavformat/mpeg.c index ae47fa60a..97b2a637a 100644 --- a/contrib/ffmpeg/libavformat/mpeg.c +++ b/contrib/ffmpeg/libavformat/mpeg.c @@ -1,5 +1,5 @@ /* - * MPEG1/2 muxer and demuxer + * MPEG1/2 demuxer * Copyright (c) 2000, 2001, 2002 Fabrice Bellard. * * This file is part of FFmpeg. @@ -18,1290 +18,72 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + #include "avformat.h" -#include "bitstream.h" -#include "fifo.h" +#include "mpeg.h" -#define MAX_PAYLOAD_SIZE 4096 //#define DEBUG_SEEK #undef NDEBUG #include -typedef struct PacketDesc { - int64_t pts; - int64_t dts; - int size; - int unwritten_size; - int flags; - struct PacketDesc *next; -} PacketDesc; - -typedef struct { - AVFifoBuffer fifo; - uint8_t id; - int max_buffer_size; /* in bytes */ - int buffer_index; - PacketDesc *predecode_packet; - PacketDesc *premux_packet; - PacketDesc **next_packet; - int packet_number; - uint8_t lpcm_header[3]; - int lpcm_align; - int bytes_to_iframe; - int align_iframe; - int64_t vobu_start_pts; -} StreamInfo; - -typedef struct { - int packet_size; /* required packet size */ - int packet_number; - int pack_header_freq; /* frequency (in packets^-1) at which we send pack headers */ - int system_header_freq; - int system_header_size; - int mux_rate; /* bitrate in units of 50 bytes/s */ - /* stream info */ - int audio_bound; - int video_bound; - int is_mpeg2; - int is_vcd; - int is_svcd; - int is_dvd; - int64_t last_scr; /* current system clock */ - - double vcd_padding_bitrate; //FIXME floats - int64_t vcd_padding_bytes_written; - -} MpegMuxContext; - -#define PACK_START_CODE ((unsigned int)0x000001ba) -#define SYSTEM_HEADER_START_CODE ((unsigned int)0x000001bb) -#define SEQUENCE_END_CODE ((unsigned int)0x000001b7) -#define PACKET_START_CODE_MASK ((unsigned int)0xffffff00) -#define PACKET_START_CODE_PREFIX ((unsigned int)0x00000100) -#define ISO_11172_END_CODE ((unsigned int)0x000001b9) - -/* mpeg2 */ -#define PROGRAM_STREAM_MAP 0x1bc -#define PRIVATE_STREAM_1 0x1bd -#define PADDING_STREAM 0x1be -#define PRIVATE_STREAM_2 0x1bf - - -#define AUDIO_ID 0xc0 -#define VIDEO_ID 0xe0 -#define AC3_ID 0x80 -#define DTS_ID 0x8a -#define LPCM_ID 0xa0 -#define SUB_ID 0x20 - -#define STREAM_TYPE_VIDEO_MPEG1 0x01 -#define STREAM_TYPE_VIDEO_MPEG2 0x02 -#define STREAM_TYPE_AUDIO_MPEG1 0x03 -#define STREAM_TYPE_AUDIO_MPEG2 0x04 -#define STREAM_TYPE_PRIVATE_SECTION 0x05 -#define STREAM_TYPE_PRIVATE_DATA 0x06 -#define STREAM_TYPE_AUDIO_AAC 0x0f -#define STREAM_TYPE_VIDEO_MPEG4 0x10 -#define STREAM_TYPE_VIDEO_H264 0x1b - -#define STREAM_TYPE_AUDIO_AC3 0x81 -#define STREAM_TYPE_AUDIO_DTS 0x8a - -static const int lpcm_freq_tab[4] = { 48000, 96000, 44100, 32000 }; - -#ifdef CONFIG_MUXERS -AVOutputFormat mpeg1system_muxer; -AVOutputFormat mpeg1vcd_muxer; -AVOutputFormat mpeg2vob_muxer; -AVOutputFormat mpeg2svcd_muxer; -AVOutputFormat mpeg2dvd_muxer; - -static int put_pack_header(AVFormatContext *ctx, - uint8_t *buf, int64_t timestamp) -{ - MpegMuxContext *s = ctx->priv_data; - PutBitContext pb; - - init_put_bits(&pb, buf, 128); - - put_bits(&pb, 32, PACK_START_CODE); - if (s->is_mpeg2) { - put_bits(&pb, 2, 0x1); - } else { - put_bits(&pb, 4, 0x2); - } - put_bits(&pb, 3, (uint32_t)((timestamp >> 30) & 0x07)); - put_bits(&pb, 1, 1); - put_bits(&pb, 15, (uint32_t)((timestamp >> 15) & 0x7fff)); - put_bits(&pb, 1, 1); - put_bits(&pb, 15, (uint32_t)((timestamp) & 0x7fff)); - put_bits(&pb, 1, 1); - if (s->is_mpeg2) { - /* clock extension */ - put_bits(&pb, 9, 0); - } - put_bits(&pb, 1, 1); - put_bits(&pb, 22, s->mux_rate); - put_bits(&pb, 1, 1); - if (s->is_mpeg2) { - put_bits(&pb, 1, 1); - put_bits(&pb, 5, 0x1f); /* reserved */ - put_bits(&pb, 3, 0); /* stuffing length */ - } - flush_put_bits(&pb); - return pbBufPtr(&pb) - pb.buf; -} - -static int put_system_header(AVFormatContext *ctx, uint8_t *buf,int only_for_stream_id) -{ - MpegMuxContext *s = ctx->priv_data; - int size, i, private_stream_coded, id; - PutBitContext pb; - - init_put_bits(&pb, buf, 128); - - put_bits(&pb, 32, SYSTEM_HEADER_START_CODE); - put_bits(&pb, 16, 0); - put_bits(&pb, 1, 1); - - put_bits(&pb, 22, s->mux_rate); /* maximum bit rate of the multiplexed stream */ - put_bits(&pb, 1, 1); /* marker */ - if (s->is_vcd && only_for_stream_id==VIDEO_ID) { - /* This header applies only to the video stream (see VCD standard p. IV-7)*/ - put_bits(&pb, 6, 0); - } else - put_bits(&pb, 6, s->audio_bound); - - if (s->is_vcd) { - /* see VCD standard, p. IV-7*/ - put_bits(&pb, 1, 0); - put_bits(&pb, 1, 1); - } else { - put_bits(&pb, 1, 0); /* variable bitrate*/ - put_bits(&pb, 1, 0); /* non constrainted bit stream */ - } - - if (s->is_vcd || s->is_dvd) { - /* see VCD standard p IV-7 */ - put_bits(&pb, 1, 1); /* audio locked */ - put_bits(&pb, 1, 1); /* video locked */ - } else { - put_bits(&pb, 1, 0); /* audio locked */ - put_bits(&pb, 1, 0); /* video locked */ - } - - put_bits(&pb, 1, 1); /* marker */ - - if (s->is_vcd && only_for_stream_id==AUDIO_ID) { - /* This header applies only to the audio stream (see VCD standard p. IV-7)*/ - put_bits(&pb, 5, 0); - } else - put_bits(&pb, 5, s->video_bound); - - if (s->is_dvd) { - put_bits(&pb, 1, 0); /* packet_rate_restriction_flag */ - put_bits(&pb, 7, 0x7f); /* reserved byte */ - } else - put_bits(&pb, 8, 0xff); /* reserved byte */ - - /* DVD-Video Stream_bound entries - id (0xB9) video, maximum P-STD for stream 0xE0. (P-STD_buffer_bound_scale = 1) - id (0xB8) audio, maximum P-STD for any MPEG audio (0xC0 to 0xC7) streams. If there are none set to 4096 (32x128). (P-STD_buffer_bound_scale = 0) - id (0xBD) private stream 1 (audio other than MPEG and subpictures). (P-STD_buffer_bound_scale = 1) - id (0xBF) private stream 2, NAV packs, set to 2x1024. */ - if (s->is_dvd) { - - int P_STD_max_video = 0; - int P_STD_max_mpeg_audio = 0; - int P_STD_max_mpeg_PS1 = 0; - - for(i=0;inb_streams;i++) { - StreamInfo *stream = ctx->streams[i]->priv_data; - - id = stream->id; - if (id == 0xbd && stream->max_buffer_size > P_STD_max_mpeg_PS1) { - P_STD_max_mpeg_PS1 = stream->max_buffer_size; - } else if (id >= 0xc0 && id <= 0xc7 && stream->max_buffer_size > P_STD_max_mpeg_audio) { - P_STD_max_mpeg_audio = stream->max_buffer_size; - } else if (id == 0xe0 && stream->max_buffer_size > P_STD_max_video) { - P_STD_max_video = stream->max_buffer_size; - } - } - - /* video */ - put_bits(&pb, 8, 0xb9); /* stream ID */ - put_bits(&pb, 2, 3); - put_bits(&pb, 1, 1); - put_bits(&pb, 13, P_STD_max_video / 1024); - - /* audio */ - if (P_STD_max_mpeg_audio == 0) - P_STD_max_mpeg_audio = 4096; - put_bits(&pb, 8, 0xb8); /* stream ID */ - put_bits(&pb, 2, 3); - put_bits(&pb, 1, 0); - put_bits(&pb, 13, P_STD_max_mpeg_audio / 128); - - /* private stream 1 */ - put_bits(&pb, 8, 0xbd); /* stream ID */ - put_bits(&pb, 2, 3); - put_bits(&pb, 1, 0); - put_bits(&pb, 13, P_STD_max_mpeg_PS1 / 128); - - /* private stream 2 */ - put_bits(&pb, 8, 0xbf); /* stream ID */ - put_bits(&pb, 2, 3); - put_bits(&pb, 1, 1); - put_bits(&pb, 13, 2); - } - else { - /* audio stream info */ - private_stream_coded = 0; - for(i=0;inb_streams;i++) { - StreamInfo *stream = ctx->streams[i]->priv_data; - - - /* For VCDs, only include the stream info for the stream - that the pack which contains this system belongs to. - (see VCD standard p. IV-7) */ - if ( !s->is_vcd || stream->id==only_for_stream_id - || only_for_stream_id==0) { - - id = stream->id; - if (id < 0xc0) { - /* special case for private streams (AC3 use that) */ - if (private_stream_coded) - continue; - private_stream_coded = 1; - id = 0xbd; - } - put_bits(&pb, 8, id); /* stream ID */ - put_bits(&pb, 2, 3); - if (id < 0xe0) { - /* audio */ - put_bits(&pb, 1, 0); - put_bits(&pb, 13, stream->max_buffer_size / 128); - } else { - /* video */ - put_bits(&pb, 1, 1); - put_bits(&pb, 13, stream->max_buffer_size / 1024); - } - } - } - } - - flush_put_bits(&pb); - size = pbBufPtr(&pb) - pb.buf; - /* patch packet size */ - buf[4] = (size - 6) >> 8; - buf[5] = (size - 6) & 0xff; - - return size; -} - -static int get_system_header_size(AVFormatContext *ctx) -{ - int buf_index, i, private_stream_coded; - StreamInfo *stream; - MpegMuxContext *s = ctx->priv_data; - - if (s->is_dvd) - return 18; // DVD-Video system headers are 18 bytes fixed length. - - buf_index = 12; - private_stream_coded = 0; - for(i=0;inb_streams;i++) { - stream = ctx->streams[i]->priv_data; - if (stream->id < 0xc0) { - if (private_stream_coded) - continue; - private_stream_coded = 1; - } - buf_index += 3; - } - return buf_index; -} - -static int mpeg_mux_init(AVFormatContext *ctx) -{ - MpegMuxContext *s = ctx->priv_data; - int bitrate, i, mpa_id, mpv_id, mps_id, ac3_id, dts_id, lpcm_id, j; - AVStream *st; - StreamInfo *stream; - int audio_bitrate; - int video_bitrate; - - s->packet_number = 0; - s->is_vcd = (ctx->oformat == &mpeg1vcd_muxer); - s->is_svcd = (ctx->oformat == &mpeg2svcd_muxer); - s->is_mpeg2 = (ctx->oformat == &mpeg2vob_muxer || ctx->oformat == &mpeg2svcd_muxer || ctx->oformat == &mpeg2dvd_muxer); - s->is_dvd = (ctx->oformat == &mpeg2dvd_muxer); - - if(ctx->packet_size) - s->packet_size = ctx->packet_size; - else - s->packet_size = 2048; - - s->vcd_padding_bytes_written = 0; - s->vcd_padding_bitrate=0; - - s->audio_bound = 0; - s->video_bound = 0; - mpa_id = AUDIO_ID; - ac3_id = AC3_ID; - dts_id = DTS_ID; - mpv_id = VIDEO_ID; - mps_id = SUB_ID; - lpcm_id = LPCM_ID; - for(i=0;inb_streams;i++) { - st = ctx->streams[i]; - stream = av_mallocz(sizeof(StreamInfo)); - if (!stream) - goto fail; - st->priv_data = stream; - - av_set_pts_info(st, 64, 1, 90000); - - switch(st->codec->codec_type) { - case CODEC_TYPE_AUDIO: - if (st->codec->codec_id == CODEC_ID_AC3) { - stream->id = ac3_id++; - } else if (st->codec->codec_id == CODEC_ID_DTS) { - stream->id = dts_id++; - } else if (st->codec->codec_id == CODEC_ID_PCM_S16BE) { - stream->id = lpcm_id++; - for(j = 0; j < 4; j++) { - if (lpcm_freq_tab[j] == st->codec->sample_rate) - break; - } - if (j == 4) - goto fail; - if (st->codec->channels > 8) - return -1; - stream->lpcm_header[0] = 0x0c; - stream->lpcm_header[1] = (st->codec->channels - 1) | (j << 4); - stream->lpcm_header[2] = 0x80; - stream->lpcm_align = st->codec->channels * 2; - } else { - stream->id = mpa_id++; - } - - /* This value HAS to be used for VCD (see VCD standard, p. IV-7). - Right now it is also used for everything else.*/ - stream->max_buffer_size = 4 * 1024; - s->audio_bound++; - break; - case CODEC_TYPE_VIDEO: - stream->id = mpv_id++; - if (st->codec->rc_buffer_size) - stream->max_buffer_size = 6*1024 + st->codec->rc_buffer_size/8; - else - stream->max_buffer_size = 230*1024; //FIXME this is probably too small as default -#if 0 - /* see VCD standard, p. IV-7*/ - stream->max_buffer_size = 46 * 1024; - else - /* This value HAS to be used for SVCD (see SVCD standard, p. 26 V.2.3.2). - Right now it is also used for everything else.*/ - stream->max_buffer_size = 230 * 1024; -#endif - s->video_bound++; - break; - case CODEC_TYPE_SUBTITLE: - stream->id = mps_id++; - stream->max_buffer_size = 16 * 1024; - break; - default: - return -1; - } - av_fifo_init(&stream->fifo, 16); - } - bitrate = 0; - audio_bitrate = 0; - video_bitrate = 0; - for(i=0;inb_streams;i++) { - int codec_rate; - st = ctx->streams[i]; - stream = (StreamInfo*) st->priv_data; - - if(st->codec->rc_max_rate || stream->id==VIDEO_ID) - codec_rate= st->codec->rc_max_rate; - else - codec_rate= st->codec->bit_rate; - - if(!codec_rate) - codec_rate= (1<<21)*8*50/ctx->nb_streams; - - bitrate += codec_rate; - - if (stream->id==AUDIO_ID) - audio_bitrate += codec_rate; - else if (stream->id==VIDEO_ID) - video_bitrate += codec_rate; - } - - if(ctx->mux_rate){ - s->mux_rate= (ctx->mux_rate + (8 * 50) - 1) / (8 * 50); - } else { - /* we increase slightly the bitrate to take into account the - headers. XXX: compute it exactly */ - bitrate += bitrate*5/100; - bitrate += 10000; - s->mux_rate = (bitrate + (8 * 50) - 1) / (8 * 50); - } - - if (s->is_vcd) { - double overhead_rate; - - /* The VCD standard mandates that the mux_rate field is 3528 - (see standard p. IV-6). - The value is actually "wrong", i.e. if you calculate - it using the normal formula and the 75 sectors per second transfer - rate you get a different value because the real pack size is 2324, - not 2352. But the standard explicitly specifies that the mux_rate - field in the header must have this value.*/ -// s->mux_rate=2352 * 75 / 50; /* = 3528*/ - - /* The VCD standard states that the muxed stream must be - exactly 75 packs / second (the data rate of a single speed cdrom). - Since the video bitrate (probably 1150000 bits/sec) will be below - the theoretical maximum we have to add some padding packets - to make up for the lower data rate. - (cf. VCD standard p. IV-6 )*/ - - /* Add the header overhead to the data rate. - 2279 data bytes per audio pack, 2294 data bytes per video pack*/ - overhead_rate = ((audio_bitrate / 8.0) / 2279) * (2324 - 2279); - overhead_rate += ((video_bitrate / 8.0) / 2294) * (2324 - 2294); - overhead_rate *= 8; - - /* Add padding so that the full bitrate is 2324*75 bytes/sec */ - s->vcd_padding_bitrate = 2324 * 75 * 8 - (bitrate + overhead_rate); - } - - if (s->is_vcd || s->is_mpeg2) - /* every packet */ - s->pack_header_freq = 1; - else - /* every 2 seconds */ - s->pack_header_freq = 2 * bitrate / s->packet_size / 8; - - /* the above seems to make pack_header_freq zero sometimes */ - if (s->pack_header_freq == 0) - s->pack_header_freq = 1; - - if (s->is_mpeg2) - /* every 200 packets. Need to look at the spec. */ - s->system_header_freq = s->pack_header_freq * 40; - else if (s->is_vcd) - /* the standard mandates that there are only two system headers - in the whole file: one in the first packet of each stream. - (see standard p. IV-7 and IV-8) */ - s->system_header_freq = 0x7fffffff; - else - s->system_header_freq = s->pack_header_freq * 5; - - for(i=0;inb_streams;i++) { - stream = ctx->streams[i]->priv_data; - stream->packet_number = 0; - } - s->system_header_size = get_system_header_size(ctx); - s->last_scr = 0; - return 0; - fail: - for(i=0;inb_streams;i++) { - av_free(ctx->streams[i]->priv_data); - } - return AVERROR(ENOMEM); -} - -static inline void put_timestamp(ByteIOContext *pb, int id, int64_t timestamp) -{ - put_byte(pb, - (id << 4) | - (((timestamp >> 30) & 0x07) << 1) | - 1); - put_be16(pb, (uint16_t)((((timestamp >> 15) & 0x7fff) << 1) | 1)); - put_be16(pb, (uint16_t)((((timestamp) & 0x7fff) << 1) | 1)); -} - - -/* return the number of padding bytes that should be inserted into - the multiplexed stream.*/ -static int get_vcd_padding_size(AVFormatContext *ctx, int64_t pts) -{ - MpegMuxContext *s = ctx->priv_data; - int pad_bytes = 0; - - if (s->vcd_padding_bitrate > 0 && pts!=AV_NOPTS_VALUE) - { - int64_t full_pad_bytes; - - full_pad_bytes = (int64_t)((s->vcd_padding_bitrate * (pts / 90000.0)) / 8.0); //FIXME this is wrong - pad_bytes = (int) (full_pad_bytes - s->vcd_padding_bytes_written); - - if (pad_bytes<0) - /* might happen if we have already padded to a later timestamp. This - can occur if another stream has already advanced further.*/ - pad_bytes=0; - } - - return pad_bytes; -} - - -#if 0 /* unused, remove? */ -/* return the exact available payload size for the next packet for - stream 'stream_index'. 'pts' and 'dts' are only used to know if - timestamps are needed in the packet header. */ -static int get_packet_payload_size(AVFormatContext *ctx, int stream_index, - int64_t pts, int64_t dts) -{ - MpegMuxContext *s = ctx->priv_data; - int buf_index; - StreamInfo *stream; - - stream = ctx->streams[stream_index]->priv_data; - - buf_index = 0; - if (((s->packet_number % s->pack_header_freq) == 0)) { - /* pack header size */ - if (s->is_mpeg2) - buf_index += 14; - else - buf_index += 12; - - if (s->is_vcd) { - /* there is exactly one system header for each stream in a VCD MPEG, - One in the very first video packet and one in the very first - audio packet (see VCD standard p. IV-7 and IV-8).*/ - - if (stream->packet_number==0) - /* The system headers refer only to the stream they occur in, - so they have a constant size.*/ - buf_index += 15; - - } else { - if ((s->packet_number % s->system_header_freq) == 0) - buf_index += s->system_header_size; - } - } - - if ((s->is_vcd && stream->packet_number==0) - || (s->is_svcd && s->packet_number==0)) - /* the first pack of each stream contains only the pack header, - the system header and some padding (see VCD standard p. IV-6) - Add the padding size, so that the actual payload becomes 0.*/ - buf_index += s->packet_size - buf_index; - else { - /* packet header size */ - buf_index += 6; - if (s->is_mpeg2) { - buf_index += 3; - if (stream->packet_number==0) - buf_index += 3; /* PES extension */ - buf_index += 1; /* obligatory stuffing byte */ - } - if (pts != AV_NOPTS_VALUE) { - if (dts != pts) - buf_index += 5 + 5; - else - buf_index += 5; - - } else { - if (!s->is_mpeg2) - buf_index++; - } - - if (stream->id < 0xc0) { - /* AC3/LPCM private data header */ - buf_index += 4; - if (stream->id >= 0xa0) { - int n; - buf_index += 3; - /* NOTE: we round the payload size to an integer number of - LPCM samples */ - n = (s->packet_size - buf_index) % stream->lpcm_align; - if (n) - buf_index += (stream->lpcm_align - n); - } - } - - if (s->is_vcd && stream->id == AUDIO_ID) - /* The VCD standard demands that 20 zero bytes follow - each audio packet (see standard p. IV-8).*/ - buf_index+=20; - } - return s->packet_size - buf_index; -} -#endif - -/* Write an MPEG padding packet header. */ -static void put_padding_packet(AVFormatContext *ctx, ByteIOContext *pb,int packet_bytes) -{ - MpegMuxContext *s = ctx->priv_data; - int i; - - put_be32(pb, PADDING_STREAM); - put_be16(pb, packet_bytes - 6); - if (!s->is_mpeg2) { - put_byte(pb, 0x0f); - packet_bytes -= 7; - } else - packet_bytes -= 6; - - for(i=0;ipremux_packet; - - while(len>0){ - if(pkt_desc->size == pkt_desc->unwritten_size) - nb_frames++; - len -= pkt_desc->unwritten_size; - pkt_desc= pkt_desc->next; - } - - return nb_frames; -} - -/* flush the packet on stream stream_index */ -static int flush_packet(AVFormatContext *ctx, int stream_index, - int64_t pts, int64_t dts, int64_t scr, int trailer_size) -{ - MpegMuxContext *s = ctx->priv_data; - StreamInfo *stream = ctx->streams[stream_index]->priv_data; - uint8_t *buf_ptr; - int size, payload_size, startcode, id, stuffing_size, i, header_len; - int packet_size; - uint8_t buffer[128]; - int zero_trail_bytes = 0; - int pad_packet_bytes = 0; - int pes_flags; - int general_pack = 0; /*"general" pack without data specific to one stream?*/ - int nb_frames; - - id = stream->id; - -#if 0 - printf("packet ID=%2x PTS=%0.3f\n", - id, pts / 90000.0); -#endif - - buf_ptr = buffer; - - if ((s->packet_number % s->pack_header_freq) == 0 || s->last_scr != scr) { - /* output pack and systems header if needed */ - size = put_pack_header(ctx, buf_ptr, scr); - buf_ptr += size; - s->last_scr= scr; - - if (s->is_vcd) { - /* there is exactly one system header for each stream in a VCD MPEG, - One in the very first video packet and one in the very first - audio packet (see VCD standard p. IV-7 and IV-8).*/ - - if (stream->packet_number==0) { - size = put_system_header(ctx, buf_ptr, id); - buf_ptr += size; - } - } else if (s->is_dvd) { - if (stream->align_iframe || s->packet_number == 0){ - int PES_bytes_to_fill = s->packet_size - size - 10; - - if (pts != AV_NOPTS_VALUE) { - if (dts != pts) - PES_bytes_to_fill -= 5 + 5; - else - PES_bytes_to_fill -= 5; - } - - if (stream->bytes_to_iframe == 0 || s->packet_number == 0) { - size = put_system_header(ctx, buf_ptr, 0); - buf_ptr += size; - size = buf_ptr - buffer; - put_buffer(&ctx->pb, buffer, size); - - put_be32(&ctx->pb, PRIVATE_STREAM_2); - put_be16(&ctx->pb, 0x03d4); // length - put_byte(&ctx->pb, 0x00); // substream ID, 00=PCI - for (i = 0; i < 979; i++) - put_byte(&ctx->pb, 0x00); - - put_be32(&ctx->pb, PRIVATE_STREAM_2); - put_be16(&ctx->pb, 0x03fa); // length - put_byte(&ctx->pb, 0x01); // substream ID, 01=DSI - for (i = 0; i < 1017; i++) - put_byte(&ctx->pb, 0x00); - - memset(buffer, 0, 128); - buf_ptr = buffer; - s->packet_number++; - stream->align_iframe = 0; - scr += s->packet_size*90000LL / (s->mux_rate*50LL); //FIXME rounding and first few bytes of each packet - size = put_pack_header(ctx, buf_ptr, scr); - s->last_scr= scr; - buf_ptr += size; - /* GOP Start */ - } else if (stream->bytes_to_iframe < PES_bytes_to_fill) { - pad_packet_bytes = PES_bytes_to_fill - stream->bytes_to_iframe; - } - } - } else { - if ((s->packet_number % s->system_header_freq) == 0) { - size = put_system_header(ctx, buf_ptr, 0); - buf_ptr += size; - } - } - } - size = buf_ptr - buffer; - put_buffer(&ctx->pb, buffer, size); - - packet_size = s->packet_size - size; - - if (s->is_vcd && id == AUDIO_ID) - /* The VCD standard demands that 20 zero bytes follow - each audio pack (see standard p. IV-8).*/ - zero_trail_bytes += 20; - - if ((s->is_vcd && stream->packet_number==0) - || (s->is_svcd && s->packet_number==0)) { - /* for VCD the first pack of each stream contains only the pack header, - the system header and lots of padding (see VCD standard p. IV-6). - In the case of an audio pack, 20 zero bytes are also added at - the end.*/ - /* For SVCD we fill the very first pack to increase compatibility with - some DVD players. Not mandated by the standard.*/ - if (s->is_svcd) - general_pack = 1; /* the system header refers to both streams and no stream data*/ - pad_packet_bytes = packet_size - zero_trail_bytes; - } - - packet_size -= pad_packet_bytes + zero_trail_bytes; - - if (packet_size > 0) { - - /* packet header size */ - packet_size -= 6; - - /* packet header */ - if (s->is_mpeg2) { - header_len = 3; - if (stream->packet_number==0) - header_len += 3; /* PES extension */ - header_len += 1; /* obligatory stuffing byte */ - } else { - header_len = 0; - } - if (pts != AV_NOPTS_VALUE) { - if (dts != pts) - header_len += 5 + 5; - else - header_len += 5; - } else { - if (!s->is_mpeg2) - header_len++; - } - - payload_size = packet_size - header_len; - if (id < 0xc0) { - startcode = PRIVATE_STREAM_1; - payload_size -= 1; - if (id >= 0x40) { - payload_size -= 3; - if (id >= 0xa0) - payload_size -= 3; - } - } else { - startcode = 0x100 + id; - } - - stuffing_size = payload_size - av_fifo_size(&stream->fifo); - - // first byte doesnt fit -> reset pts/dts + stuffing - if(payload_size <= trailer_size && pts != AV_NOPTS_VALUE){ - int timestamp_len=0; - if(dts != pts) - timestamp_len += 5; - if(pts != AV_NOPTS_VALUE) - timestamp_len += s->is_mpeg2 ? 5 : 4; - pts=dts= AV_NOPTS_VALUE; - header_len -= timestamp_len; - if (s->is_dvd && stream->align_iframe) { - pad_packet_bytes += timestamp_len; - packet_size -= timestamp_len; - } else { - payload_size += timestamp_len; - } - stuffing_size += timestamp_len; - if(payload_size > trailer_size) - stuffing_size += payload_size - trailer_size; - } - - if (pad_packet_bytes > 0 && pad_packet_bytes <= 7) { // can't use padding, so use stuffing - packet_size += pad_packet_bytes; - payload_size += pad_packet_bytes; // undo the previous adjustment - if (stuffing_size < 0) { - stuffing_size = pad_packet_bytes; - } else { - stuffing_size += pad_packet_bytes; - } - pad_packet_bytes = 0; - } - - if (stuffing_size < 0) - stuffing_size = 0; - if (stuffing_size > 16) { /*<=16 for MPEG-1, <=32 for MPEG-2*/ - pad_packet_bytes += stuffing_size; - packet_size -= stuffing_size; - payload_size -= stuffing_size; - stuffing_size = 0; - } - - nb_frames= get_nb_frames(ctx, stream, payload_size - stuffing_size); - - put_be32(&ctx->pb, startcode); - - put_be16(&ctx->pb, packet_size); - - if (!s->is_mpeg2) - for(i=0;ipb, 0xff); - - if (s->is_mpeg2) { - put_byte(&ctx->pb, 0x80); /* mpeg2 id */ - - pes_flags=0; - - if (pts != AV_NOPTS_VALUE) { - pes_flags |= 0x80; - if (dts != pts) - pes_flags |= 0x40; - } - - /* Both the MPEG-2 and the SVCD standards demand that the - P-STD_buffer_size field be included in the first packet of - every stream. (see SVCD standard p. 26 V.2.3.1 and V.2.3.2 - and MPEG-2 standard 2.7.7) */ - if (stream->packet_number == 0) - pes_flags |= 0x01; - - put_byte(&ctx->pb, pes_flags); /* flags */ - put_byte(&ctx->pb, header_len - 3 + stuffing_size); - - if (pes_flags & 0x80) /*write pts*/ - put_timestamp(&ctx->pb, (pes_flags & 0x40) ? 0x03 : 0x02, pts); - if (pes_flags & 0x40) /*write dts*/ - put_timestamp(&ctx->pb, 0x01, dts); - - if (pes_flags & 0x01) { /*write pes extension*/ - put_byte(&ctx->pb, 0x10); /* flags */ - - /* P-STD buffer info */ - if (id == AUDIO_ID) - put_be16(&ctx->pb, 0x4000 | stream->max_buffer_size/128); - else - put_be16(&ctx->pb, 0x6000 | stream->max_buffer_size/1024); - } - - } else { - if (pts != AV_NOPTS_VALUE) { - if (dts != pts) { - put_timestamp(&ctx->pb, 0x03, pts); - put_timestamp(&ctx->pb, 0x01, dts); - } else { - put_timestamp(&ctx->pb, 0x02, pts); - } - } else { - put_byte(&ctx->pb, 0x0f); - } - } - - if (s->is_mpeg2) { - /* special stuffing byte that is always written - to prevent accidental generation of start codes. */ - put_byte(&ctx->pb, 0xff); - - for(i=0;ipb, 0xff); - } - - if (startcode == PRIVATE_STREAM_1) { - put_byte(&ctx->pb, id); - if (id >= 0xa0) { - /* LPCM (XXX: check nb_frames) */ - put_byte(&ctx->pb, 7); - put_be16(&ctx->pb, 4); /* skip 3 header bytes */ - put_byte(&ctx->pb, stream->lpcm_header[0]); - put_byte(&ctx->pb, stream->lpcm_header[1]); - put_byte(&ctx->pb, stream->lpcm_header[2]); - } else if (id >= 0x40) { - /* AC3 */ - put_byte(&ctx->pb, nb_frames); - put_be16(&ctx->pb, trailer_size+1); - } - } - - /* output data */ - if(av_fifo_generic_read(&stream->fifo, payload_size - stuffing_size, &put_buffer, &ctx->pb) < 0) - return -1; - stream->bytes_to_iframe -= payload_size - stuffing_size; - }else{ - payload_size= - stuffing_size= 0; - } - - if (pad_packet_bytes > 0) - put_padding_packet(ctx,&ctx->pb, pad_packet_bytes); - - for(i=0;ipb, 0x00); - - put_flush_packet(&ctx->pb); - - s->packet_number++; - - /* only increase the stream packet number if this pack actually contains - something that is specific to this stream! I.e. a dedicated header - or some data.*/ - if (!general_pack) - stream->packet_number++; - - return payload_size - stuffing_size; -} - -static void put_vcd_padding_sector(AVFormatContext *ctx) -{ - /* There are two ways to do this padding: writing a sector/pack - of 0 values, or writing an MPEG padding pack. Both seem to - work with most decoders, BUT the VCD standard only allows a 0-sector - (see standard p. IV-4, IV-5). - So a 0-sector it is...*/ - - MpegMuxContext *s = ctx->priv_data; - int i; - - for(i=0;ipacket_size;i++) - put_byte(&ctx->pb, 0); - - s->vcd_padding_bytes_written += s->packet_size; - - put_flush_packet(&ctx->pb); - - /* increasing the packet number is correct. The SCR of the following packs - is calculated from the packet_number and it has to include the padding - sector (it represents the sector index, not the MPEG pack index) - (see VCD standard p. IV-6)*/ - s->packet_number++; -} - -#if 0 /* unused, remove? */ -static int64_t get_vcd_scr(AVFormatContext *ctx,int stream_index,int64_t pts) -{ - MpegMuxContext *s = ctx->priv_data; - int64_t scr; - - /* Since the data delivery rate is constant, SCR is computed - using the formula C + i * 1200 where C is the start constant - and i is the pack index. - It is recommended that SCR 0 is at the beginning of the VCD front - margin (a sequence of empty Form 2 sectors on the CD). - It is recommended that the front margin is 30 sectors long, so - we use C = 30*1200 = 36000 - (Note that even if the front margin is not 30 sectors the file - will still be correct according to the standard. It just won't have - the "recommended" value).*/ - scr = 36000 + s->packet_number * 1200; - - return scr; -} -#endif - -static int remove_decoded_packets(AVFormatContext *ctx, int64_t scr){ -// MpegMuxContext *s = ctx->priv_data; - int i; - - for(i=0; inb_streams; i++){ - AVStream *st = ctx->streams[i]; - StreamInfo *stream = st->priv_data; - PacketDesc *pkt_desc= stream->predecode_packet; - - while(pkt_desc && scr > pkt_desc->dts){ //FIXME > vs >= - if(stream->buffer_index < pkt_desc->size || - stream->predecode_packet == stream->premux_packet){ - av_log(ctx, AV_LOG_ERROR, "buffer underflow\n"); - break; - } - stream->buffer_index -= pkt_desc->size; - - stream->predecode_packet= pkt_desc->next; - av_freep(&pkt_desc); - } - } - - return 0; -} - -static int output_packet(AVFormatContext *ctx, int flush){ - MpegMuxContext *s = ctx->priv_data; - AVStream *st; - StreamInfo *stream; - int i, avail_space, es_size, trailer_size; - int best_i= -1; - int best_score= INT_MIN; - int ignore_constraints=0; - int64_t scr= s->last_scr; - PacketDesc *timestamp_packet; - const int64_t max_delay= av_rescale(ctx->max_delay, 90000, AV_TIME_BASE); - -retry: - for(i=0; inb_streams; i++){ - AVStream *st = ctx->streams[i]; - StreamInfo *stream = st->priv_data; - const int avail_data= av_fifo_size(&stream->fifo); - const int space= stream->max_buffer_size - stream->buffer_index; - int rel_space= 1024*space / stream->max_buffer_size; - PacketDesc *next_pkt= stream->premux_packet; - - /* for subtitle, a single PES packet must be generated, - so we flush after every single subtitle packet */ - if(s->packet_size > avail_data && !flush - && st->codec->codec_type != CODEC_TYPE_SUBTITLE) - return 0; - if(avail_data==0) - continue; - assert(avail_data>0); - - if(space < s->packet_size && !ignore_constraints) - continue; - - if(next_pkt && next_pkt->dts - scr > max_delay) - continue; - - if(rel_space > best_score){ - best_score= rel_space; - best_i = i; - avail_space= space; - } - } - - if(best_i < 0){ - int64_t best_dts= INT64_MAX; - - for(i=0; inb_streams; i++){ - AVStream *st = ctx->streams[i]; - StreamInfo *stream = st->priv_data; - PacketDesc *pkt_desc= stream->predecode_packet; - if(pkt_desc && pkt_desc->dts < best_dts) - best_dts= pkt_desc->dts; - } - -#if 0 - av_log(ctx, AV_LOG_DEBUG, "bumping scr, scr:%f, dts:%f\n", - scr/90000.0, best_dts/90000.0); -#endif - if(best_dts == INT64_MAX) - return 0; - - if(scr >= best_dts+1 && !ignore_constraints){ - av_log(ctx, AV_LOG_ERROR, "packet too large, ignoring buffer limits to mux it\n"); - ignore_constraints= 1; - } - scr= FFMAX(best_dts+1, scr); - if(remove_decoded_packets(ctx, scr) < 0) - return -1; - goto retry; - } - - assert(best_i >= 0); - - st = ctx->streams[best_i]; - stream = st->priv_data; - - assert(av_fifo_size(&stream->fifo) > 0); - - assert(avail_space >= s->packet_size || ignore_constraints); - - timestamp_packet= stream->premux_packet; - if(timestamp_packet->unwritten_size == timestamp_packet->size){ - trailer_size= 0; - }else{ - trailer_size= timestamp_packet->unwritten_size; - timestamp_packet= timestamp_packet->next; - } - - if(timestamp_packet){ -//av_log(ctx, AV_LOG_DEBUG, "dts:%f pts:%f scr:%f stream:%d\n", timestamp_packet->dts/90000.0, timestamp_packet->pts/90000.0, scr/90000.0, best_i); - es_size= flush_packet(ctx, best_i, timestamp_packet->pts, timestamp_packet->dts, scr, trailer_size); - }else{ - assert(av_fifo_size(&stream->fifo) == trailer_size); - es_size= flush_packet(ctx, best_i, AV_NOPTS_VALUE, AV_NOPTS_VALUE, scr, trailer_size); - } - - if (s->is_vcd) { - /* Write one or more padding sectors, if necessary, to reach - the constant overall bitrate.*/ - int vcd_pad_bytes; - - while((vcd_pad_bytes = get_vcd_padding_size(ctx,stream->premux_packet->pts) ) >= s->packet_size){ //FIXME pts cannot be correct here - put_vcd_padding_sector(ctx); - s->last_scr += s->packet_size*90000LL / (s->mux_rate*50LL); //FIXME rounding and first few bytes of each packet - } - } - - stream->buffer_index += es_size; - s->last_scr += s->packet_size*90000LL / (s->mux_rate*50LL); //FIXME rounding and first few bytes of each packet - - while(stream->premux_packet && stream->premux_packet->unwritten_size <= es_size){ - es_size -= stream->premux_packet->unwritten_size; - stream->premux_packet= stream->premux_packet->next; - } - if(es_size) - stream->premux_packet->unwritten_size -= es_size; - - if(remove_decoded_packets(ctx, s->last_scr) < 0) - return -1; - - return 1; -} - -static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt) -{ - MpegMuxContext *s = ctx->priv_data; - int stream_index= pkt->stream_index; - int size= pkt->size; - uint8_t *buf= pkt->data; - AVStream *st = ctx->streams[stream_index]; - StreamInfo *stream = st->priv_data; - int64_t pts, dts; - PacketDesc *pkt_desc; - const int preload= av_rescale(ctx->preload, 90000, AV_TIME_BASE); - const int is_iframe = st->codec->codec_type == CODEC_TYPE_VIDEO && (pkt->flags & PKT_FLAG_KEY); - - pts= pkt->pts; - dts= pkt->dts; - - if(pts != AV_NOPTS_VALUE) pts += preload; - if(dts != AV_NOPTS_VALUE) dts += preload; - -//av_log(ctx, AV_LOG_DEBUG, "dts:%f pts:%f flags:%d stream:%d nopts:%d\n", dts/90000.0, pts/90000.0, pkt->flags, pkt->stream_index, pts != AV_NOPTS_VALUE); - if (!stream->premux_packet) - stream->next_packet = &stream->premux_packet; - *stream->next_packet= - pkt_desc= av_mallocz(sizeof(PacketDesc)); - pkt_desc->pts= pts; - pkt_desc->dts= dts; - pkt_desc->unwritten_size= - pkt_desc->size= size; - if(!stream->predecode_packet) - stream->predecode_packet= pkt_desc; - stream->next_packet= &pkt_desc->next; - - av_fifo_realloc(&stream->fifo, av_fifo_size(&stream->fifo) + size + 1); - - if (s->is_dvd){ - if (is_iframe && (s->packet_number == 0 || (pts - stream->vobu_start_pts >= 36000))) { // min VOBU length 0.4 seconds (mpucoder) - stream->bytes_to_iframe = av_fifo_size(&stream->fifo); - stream->align_iframe = 1; - stream->vobu_start_pts = pts; - } else { - stream->align_iframe = 0; - } - } - - av_fifo_write(&stream->fifo, buf, size); - - for(;;){ - int ret= output_packet(ctx, 0); - if(ret<=0) - return ret; - } -} - -static int mpeg_mux_end(AVFormatContext *ctx) -{ -// MpegMuxContext *s = ctx->priv_data; - StreamInfo *stream; - int i; - - for(;;){ - int ret= output_packet(ctx, 1); - if(ret<0) - return ret; - else if(ret==0) - break; - } - - /* End header according to MPEG1 systems standard. We do not write - it as it is usually not needed by decoders and because it - complicates MPEG stream concatenation. */ - //put_be32(&ctx->pb, ISO_11172_END_CODE); - //put_flush_packet(&ctx->pb); - - for(i=0;inb_streams;i++) { - stream = ctx->streams[i]->priv_data; - - assert(av_fifo_size(&stream->fifo) == 0); - av_fifo_free(&stream->fifo); - } - return 0; -} -#endif //CONFIG_MUXERS - /*********************************************/ /* demux code */ #define MAX_SYNC_SIZE 100000 -static int cdxa_probe(AVProbeData *p) -{ - /* check file header */ - if (p->buf_size <= 32) - return 0; - if (p->buf[0] == 'R' && p->buf[1] == 'I' && - p->buf[2] == 'F' && p->buf[3] == 'F' && - p->buf[8] == 'C' && p->buf[9] == 'D' && - p->buf[10] == 'X' && p->buf[11] == 'A') - return AVPROBE_SCORE_MAX; - else - return 0; +static int check_pes(uint8_t *p, uint8_t *end){ + int pes1; + int pes2= (p[3] & 0xC0) == 0x80 + && (p[4] & 0xC0) != 0x40 + &&((p[4] & 0xC0) == 0x00 || (p[4]&0xC0)>>2 == (p[6]&0xF0)); + + for(p+=3; p 0) return score; - - /* Search for MPEG stream */ for(i=0; ibuf_size; i++){ code = (code<<8) + p->buf[i]; if ((code & 0xffffff00) == 0x100) { + int pes= check_pes(p->buf+i, p->buf+p->buf_size); + if(code == SYSTEM_HEADER_START_CODE) sys++; else if(code == PRIVATE_STREAM_1) priv1++; else if(code == PACK_START_CODE) pspack++; - else if((code & 0xf0) == VIDEO_ID) vid++; - else if((code & 0xe0) == AUDIO_ID) audio++; + else if((code & 0xf0) == VIDEO_ID && pes) vid++; + else if((code & 0xe0) == AUDIO_ID && pes) audio++; + + else if((code & 0xf0) == VIDEO_ID && !pes) invalid++; + else if((code & 0xe0) == AUDIO_ID && !pes) invalid++; } } - if(vid || audio) /* invalid VDR files nd short PES streams */ + if(vid+audio > invalid) /* invalid VDR files nd short PES streams */ score= AVPROBE_SCORE_MAX/4; -//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d\n", sys, priv1, pspack,vid, audio); - if(sys && sys*9 <= pspack*10) +//av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d len:%d\n", sys, priv1, pspack,vid, audio, p->buf_size); + if(sys>invalid && sys*9 <= pspack*10) return AVPROBE_SCORE_MAX/2+2; // +1 for .mpg - if((priv1 || vid || audio) && (priv1+vid+audio)*9 <= pspack*10) + if(priv1 + vid + audio > invalid && (priv1+vid+audio)*9 <= pspack*10) return AVPROBE_SCORE_MAX/2+2; // +1 for .mpg - if((!!vid ^ !!audio) && (audio+vid > 1) && !sys && !pspack) /* PES stream */ + if((!!vid ^ !!audio) && (audio+vid > 1) && !sys && !pspack && p->buf_size>2048) /* PES stream */ return AVPROBE_SCORE_MAX/2+2; //02-Penguin.flac has sys:0 priv1:0 pspack:0 vid:0 audio:1 @@ -1312,32 +94,38 @@ static int mpegps_probe(AVProbeData *p) typedef struct MpegDemuxContext { int32_t header_state; unsigned char psm_es_type[256]; + int sofdec; } MpegDemuxContext; static int mpegps_read_header(AVFormatContext *s, AVFormatParameters *ap) { MpegDemuxContext *m = s->priv_data; + const char *sofdec = "Sofdec"; + int v, i = 0; + m->header_state = 0xff; s->ctx_flags |= AVFMTCTX_NOHEADER; + m->sofdec = -1; + do { + v = get_byte(s->pb); + m->header_state = m->header_state << 8 | v; + m->sofdec++; + } while (v == sofdec[i] && i++ < 6); + /* no need to do more */ return 0; } static int64_t get_pts(ByteIOContext *pb, int c) { - int64_t pts; - int val; + uint8_t buf[5]; + + buf[0] = c<0 ? get_byte(pb) : c; + get_buffer(pb, buf+1, 4); - if (c < 0) - c = get_byte(pb); - pts = (int64_t)((c >> 1) & 0x07) << 30; - val = get_be16(pb); - pts |= (int64_t)(val >> 1) << 15; - val = get_be16(pb); - pts |= (int64_t)(val >> 1); - return pts; + return ff_parse_pes_pts(buf); } static int find_next_start_code(ByteIOContext *pb, int *size_ptr, @@ -1447,32 +235,46 @@ static int mpegps_read_pes_header(AVFormatContext *s, int len, size, startcode, c, flags, header_len; int pes_ext, ext2_len, id_ext, skip; int64_t pts, dts; - int64_t last_sync= url_ftell(&s->pb); + int64_t last_sync= url_ftell(s->pb); error_redo: - url_fseek(&s->pb, last_sync, SEEK_SET); + url_fseek(s->pb, last_sync, SEEK_SET); redo: /* next start code (should be immediately after) */ m->header_state = 0xff; size = MAX_SYNC_SIZE; - startcode = find_next_start_code(&s->pb, &size, &m->header_state); - last_sync = url_ftell(&s->pb); - //printf("startcode=%x pos=0x%"PRIx64"\n", startcode, url_ftell(&s->pb)); + startcode = find_next_start_code(s->pb, &size, &m->header_state); + last_sync = url_ftell(s->pb); + //printf("startcode=%x pos=0x%"PRIx64"\n", startcode, url_ftell(s->pb)); if (startcode < 0) - return AVERROR_IO; + return AVERROR(EIO); if (startcode == PACK_START_CODE) goto redo; if (startcode == SYSTEM_HEADER_START_CODE) goto redo; - if (startcode == PADDING_STREAM || - startcode == PRIVATE_STREAM_2) { - /* skip them */ - len = get_be16(&s->pb); - url_fskip(&s->pb, len); + if (startcode == PADDING_STREAM) { + url_fskip(s->pb, get_be16(s->pb)); + goto redo; + } + if (startcode == PRIVATE_STREAM_2) { + len = get_be16(s->pb); + if (!m->sofdec) { + while (len-- >= 6) { + if (get_byte(s->pb) == 'S') { + uint8_t buf[5]; + get_buffer(s->pb, buf, sizeof(buf)); + m->sofdec = !memcmp(buf, "ofdec", 5); + len -= sizeof(buf); + break; + } + } + m->sofdec -= !m->sofdec; + } + url_fskip(s->pb, len); goto redo; } if (startcode == PROGRAM_STREAM_MAP) { - mpegps_psm_parse(m, &s->pb); + mpegps_psm_parse(m, s->pb); goto redo; } @@ -1482,16 +284,16 @@ static int mpegps_read_pes_header(AVFormatContext *s, (startcode == 0x1bd) || (startcode == 0x1fd))) goto redo; if (ppos) { - *ppos = url_ftell(&s->pb) - 4; + *ppos = url_ftell(s->pb) - 4; } - len = get_be16(&s->pb); + len = get_be16(s->pb); pts = dts = AV_NOPTS_VALUE; /* stuffing */ for(;;) { if (len < 1) goto error_redo; - c = get_byte(&s->pb); + c = get_byte(s->pb); len--; /* XXX: for mpeg1, should test only bit 7 */ if (c != 0xff) @@ -1499,15 +301,15 @@ static int mpegps_read_pes_header(AVFormatContext *s, } if ((c & 0xc0) == 0x40) { /* buffer scale & size */ - get_byte(&s->pb); - c = get_byte(&s->pb); + get_byte(s->pb); + c = get_byte(s->pb); len -= 2; } if ((c & 0xe0) == 0x20) { - dts = pts = get_pts(&s->pb, c); + dts = pts = get_pts(s->pb, c); len -= 4; if (c & 0x10){ - dts = get_pts(&s->pb, -1); + dts = get_pts(s->pb, -1); len -= 5; } } else if ((c & 0xc0) == 0x80) { @@ -1518,22 +320,22 @@ static int mpegps_read_pes_header(AVFormatContext *s, goto redo; } #endif - flags = get_byte(&s->pb); - header_len = get_byte(&s->pb); + flags = get_byte(s->pb); + header_len = get_byte(s->pb); len -= 2; if (header_len > len) goto error_redo; len -= header_len; if (flags & 0x80) { - dts = pts = get_pts(&s->pb, -1); + dts = pts = get_pts(s->pb, -1); header_len -= 5; if (flags & 0x40) { - dts = get_pts(&s->pb, -1); + dts = get_pts(s->pb, -1); header_len -= 5; } } if (flags & 0x01) { /* PES extension */ - pes_ext = get_byte(&s->pb); + pes_ext = get_byte(s->pb); header_len--; if (pes_ext & 0x40) { /* pack header - should be zero in PS */ goto error_redo; @@ -1541,14 +343,14 @@ static int mpegps_read_pes_header(AVFormatContext *s, /* Skip PES private data, program packet sequence counter and P-STD buffer */ skip = (pes_ext >> 4) & 0xb; skip += skip & 0x9; - url_fskip(&s->pb, skip); + url_fskip(s->pb, skip); header_len -= skip; if (pes_ext & 0x01) { /* PES extension 2 */ - ext2_len = get_byte(&s->pb); + ext2_len = get_byte(s->pb); header_len--; if ((ext2_len & 0x7f) > 0) { - id_ext = get_byte(&s->pb); + id_ext = get_byte(s->pb); if ((id_ext & 0x80) == 0) startcode = ((startcode & 0xff) << 8) | id_ext; header_len--; @@ -1557,23 +359,23 @@ static int mpegps_read_pes_header(AVFormatContext *s, } if(header_len < 0) goto error_redo; - url_fskip(&s->pb, header_len); + url_fskip(s->pb, header_len); } else if( c!= 0xf ) goto redo; if (startcode == PRIVATE_STREAM_1 && !m->psm_es_type[startcode & 0xff]) { - startcode = get_byte(&s->pb); + startcode = get_byte(s->pb); len--; if (startcode >= 0x80 && startcode <= 0xcf) { /* audio: skip header */ - get_byte(&s->pb); - get_byte(&s->pb); - get_byte(&s->pb); + get_byte(s->pb); + get_byte(s->pb); + get_byte(s->pb); len -= 3; if (startcode >= 0xb0 && startcode <= 0xbf) { /* MLP/TrueHD audio has a 4-byte header */ - get_byte(&s->pb); + get_byte(s->pb); len--; } } @@ -1583,7 +385,9 @@ static int mpegps_read_pes_header(AVFormatContext *s, if(dts != AV_NOPTS_VALUE && ppos){ int i; for(i=0; inb_streams; i++){ - if(startcode == s->streams[i]->id) { + if(startcode == s->streams[i]->id && + !url_is_streamed(s->pb) /* index useless on streams anyway */) { + ff_reduce_index(s, i); av_add_index_entry(s->streams[i], *ppos, dts, 0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */); } } @@ -1645,8 +449,8 @@ static int mpegps_read_packet(AVFormatContext *s, } else if (startcode >= 0x1e0 && startcode <= 0x1ef) { static const unsigned char avs_seqh[4] = { 0, 0, 1, 0xb0 }; unsigned char buf[8]; - get_buffer(&s->pb, buf, 8); - url_fseek(&s->pb, -8, SEEK_CUR); + get_buffer(s->pb, buf, 8); + url_fseek(s->pb, -8, SEEK_CUR); if(!memcmp(buf, avs_seqh, 4) && (buf[6] != 0 || buf[7] != 1)) codec_id = CODEC_ID_CAVS; else @@ -1654,7 +458,7 @@ static int mpegps_read_packet(AVFormatContext *s, type = CODEC_TYPE_VIDEO; } else if (startcode >= 0x1c0 && startcode <= 0x1df) { type = CODEC_TYPE_AUDIO; - codec_id = CODEC_ID_MP2; + codec_id = m->sofdec > 0 ? CODEC_ID_ADPCM_ADX : CODEC_ID_MP2; } else if (startcode >= 0x80 && startcode <= 0x87) { type = CODEC_TYPE_AUDIO; codec_id = CODEC_ID_AC3; @@ -1682,7 +486,7 @@ static int mpegps_read_packet(AVFormatContext *s, } else { skip: /* skip packet */ - url_fskip(&s->pb, len); + url_fskip(s->pb, len); goto redo; } /* no stream found: add a new stream */ @@ -1692,7 +496,7 @@ static int mpegps_read_packet(AVFormatContext *s, st->codec->codec_type = type; st->codec->codec_id = codec_id; if (codec_id != CODEC_ID_PCM_S16BE) - st->need_parsing = 1; + st->need_parsing = AVSTREAM_PARSE_FULL; found: if(st->discard >= AVDISCARD_ALL) goto skip; @@ -1703,9 +507,9 @@ static int mpegps_read_packet(AVFormatContext *s, audio data */ if (len <= 3) goto skip; - get_byte(&s->pb); /* emphasis (1), muse(1), reserved(1), frame number(5) */ - b1 = get_byte(&s->pb); /* quant (2), freq(2), reserved(1), channels(3) */ - get_byte(&s->pb); /* dynamic range control (0x80 = off) */ + get_byte(s->pb); /* emphasis (1), muse(1), reserved(1), frame number(5) */ + b1 = get_byte(s->pb); /* quant (2), freq(2), reserved(1), channels(3) */ + get_byte(s->pb); /* dynamic range control (0x80 = off) */ len -= 3; freq = (b1 >> 4) & 3; st->codec->sample_rate = lpcm_freq_tab[freq]; @@ -1713,7 +517,7 @@ static int mpegps_read_packet(AVFormatContext *s, st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * 2; } av_new_packet(pkt, len); - get_buffer(&s->pb, pkt->data, pkt->size); + get_buffer(s->pb, pkt->data, pkt->size); pkt->pts = pts; pkt->dts = dts; pkt->stream_index = st->index; @@ -1740,7 +544,7 @@ static int64_t mpegps_read_dts(AVFormatContext *s, int stream_index, #ifdef DEBUG_SEEK printf("read_dts: pos=0x%"PRIx64" next=%d -> ", pos, find_next); #endif - url_fseek(&s->pb, pos, SEEK_SET); + url_fseek(s->pb, pos, SEEK_SET); for(;;) { len = mpegps_read_pes_header(s, &pos, &startcode, &pts, &dts); if (len < 0) { @@ -1753,7 +557,7 @@ static int64_t mpegps_read_dts(AVFormatContext *s, int stream_index, dts != AV_NOPTS_VALUE) { break; } - url_fskip(&s->pb, len); + url_fskip(s->pb, len); } #ifdef DEBUG_SEEK printf("pos=0x%"PRIx64" dts=0x%"PRIx64" %0.3f\n", pos, dts, dts / 90000.0); @@ -1762,82 +566,6 @@ static int64_t mpegps_read_dts(AVFormatContext *s, int stream_index, return dts; } -#ifdef CONFIG_MPEG1SYSTEM_MUXER -AVOutputFormat mpeg1system_muxer = { - "mpeg", - "MPEG1 System format", - "video/mpeg", - "mpg,mpeg", - sizeof(MpegMuxContext), - CODEC_ID_MP2, - CODEC_ID_MPEG1VIDEO, - mpeg_mux_init, - mpeg_mux_write_packet, - mpeg_mux_end, -}; -#endif -#ifdef CONFIG_MPEG1VCD_MUXER -AVOutputFormat mpeg1vcd_muxer = { - "vcd", - "MPEG1 System format (VCD)", - "video/mpeg", - NULL, - sizeof(MpegMuxContext), - CODEC_ID_MP2, - CODEC_ID_MPEG1VIDEO, - mpeg_mux_init, - mpeg_mux_write_packet, - mpeg_mux_end, -}; -#endif -#ifdef CONFIG_MPEG2VOB_MUXER -AVOutputFormat mpeg2vob_muxer = { - "vob", - "MPEG2 PS format (VOB)", - "video/mpeg", - "vob", - sizeof(MpegMuxContext), - CODEC_ID_MP2, - CODEC_ID_MPEG2VIDEO, - mpeg_mux_init, - mpeg_mux_write_packet, - mpeg_mux_end, -}; -#endif - -/* Same as mpeg2vob_mux except that the pack size is 2324 */ -#ifdef CONFIG_MPEG2SVCD_MUXER -AVOutputFormat mpeg2svcd_muxer = { - "svcd", - "MPEG2 PS format (VOB)", - "video/mpeg", - "vob", - sizeof(MpegMuxContext), - CODEC_ID_MP2, - CODEC_ID_MPEG2VIDEO, - mpeg_mux_init, - mpeg_mux_write_packet, - mpeg_mux_end, -}; -#endif - -/* Same as mpeg2vob_mux except the 'is_dvd' flag is set to produce NAV pkts */ -#ifdef CONFIG_MPEG2DVD_MUXER -AVOutputFormat mpeg2dvd_muxer = { - "dvd", - "MPEG2 PS format (DVD VOB)", - "video/mpeg", - "dvd", - sizeof(MpegMuxContext), - CODEC_ID_MP2, - CODEC_ID_MPEG2VIDEO, - mpeg_mux_init, - mpeg_mux_write_packet, - mpeg_mux_end, -}; -#endif - -#ifdef CONFIG_MPEGPS_DEMUXER AVInputFormat mpegps_demuxer = { "mpeg", "MPEG PS format", @@ -1850,4 +578,3 @@ AVInputFormat mpegps_demuxer = { mpegps_read_dts, .flags = AVFMT_SHOW_IDS, }; -#endif diff --git a/contrib/ffmpeg/libavformat/mpeg.h b/contrib/ffmpeg/libavformat/mpeg.h new file mode 100644 index 000000000..9283101d1 --- /dev/null +++ b/contrib/ffmpeg/libavformat/mpeg.h @@ -0,0 +1,69 @@ +/* + * MPEG1/2 muxer and demuxer common defines + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_MPEG_H +#define FFMPEG_MPEG_H + +#define PACK_START_CODE ((unsigned int)0x000001ba) +#define SYSTEM_HEADER_START_CODE ((unsigned int)0x000001bb) +#define SEQUENCE_END_CODE ((unsigned int)0x000001b7) +#define PACKET_START_CODE_MASK ((unsigned int)0xffffff00) +#define PACKET_START_CODE_PREFIX ((unsigned int)0x00000100) +#define ISO_11172_END_CODE ((unsigned int)0x000001b9) + +/* mpeg2 */ +#define PROGRAM_STREAM_MAP 0x1bc +#define PRIVATE_STREAM_1 0x1bd +#define PADDING_STREAM 0x1be +#define PRIVATE_STREAM_2 0x1bf + +#define AUDIO_ID 0xc0 +#define VIDEO_ID 0xe0 +#define AC3_ID 0x80 +#define DTS_ID 0x8a +#define LPCM_ID 0xa0 +#define SUB_ID 0x20 + +#define STREAM_TYPE_VIDEO_MPEG1 0x01 +#define STREAM_TYPE_VIDEO_MPEG2 0x02 +#define STREAM_TYPE_AUDIO_MPEG1 0x03 +#define STREAM_TYPE_AUDIO_MPEG2 0x04 +#define STREAM_TYPE_PRIVATE_SECTION 0x05 +#define STREAM_TYPE_PRIVATE_DATA 0x06 +#define STREAM_TYPE_AUDIO_AAC 0x0f +#define STREAM_TYPE_VIDEO_MPEG4 0x10 +#define STREAM_TYPE_VIDEO_H264 0x1b + +#define STREAM_TYPE_AUDIO_AC3 0x81 +#define STREAM_TYPE_AUDIO_DTS 0x8a + +static const int lpcm_freq_tab[4] = { 48000, 96000, 44100, 32000 }; + +/** + * Parse MPEG-PES five-byte timestamp + */ +static inline int64_t ff_parse_pes_pts(uint8_t *buf) { + return (int64_t)(*buf & 0x0e) << 29 | + (AV_RB16(buf+1) >> 1) << 15 | + AV_RB16(buf+3) >> 1; +} + +#endif /* FFMPEG_MPEG_H */ diff --git a/contrib/ffmpeg/libavformat/mpegenc.c b/contrib/ffmpeg/libavformat/mpegenc.c new file mode 100644 index 000000000..0558226b8 --- /dev/null +++ b/contrib/ffmpeg/libavformat/mpegenc.c @@ -0,0 +1,1294 @@ +/* + * MPEG1/2 muxer + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" +#include "bitstream.h" +#include "fifo.h" +#include "mpeg.h" + +#define MAX_PAYLOAD_SIZE 4096 +//#define DEBUG_SEEK + +#undef NDEBUG +#include + +typedef struct PacketDesc { + int64_t pts; + int64_t dts; + int size; + int unwritten_size; + int flags; + struct PacketDesc *next; +} PacketDesc; + +typedef struct { + AVFifoBuffer fifo; + uint8_t id; + int max_buffer_size; /* in bytes */ + int buffer_index; + PacketDesc *predecode_packet; + PacketDesc *premux_packet; + PacketDesc **next_packet; + int packet_number; + uint8_t lpcm_header[3]; + int lpcm_align; + int bytes_to_iframe; + int align_iframe; + int64_t vobu_start_pts; +} StreamInfo; + +typedef struct { + int packet_size; /* required packet size */ + int packet_number; + int pack_header_freq; /* frequency (in packets^-1) at which we send pack headers */ + int system_header_freq; + int system_header_size; + int mux_rate; /* bitrate in units of 50 bytes/s */ + /* stream info */ + int audio_bound; + int video_bound; + int is_mpeg2; + int is_vcd; + int is_svcd; + int is_dvd; + int64_t last_scr; /* current system clock */ + + double vcd_padding_bitrate; //FIXME floats + int64_t vcd_padding_bytes_written; + +} MpegMuxContext; + +extern AVOutputFormat mpeg1vcd_muxer; +extern AVOutputFormat mpeg2dvd_muxer; +extern AVOutputFormat mpeg2svcd_muxer; +extern AVOutputFormat mpeg2vob_muxer; + +static int put_pack_header(AVFormatContext *ctx, + uint8_t *buf, int64_t timestamp) +{ + MpegMuxContext *s = ctx->priv_data; + PutBitContext pb; + + init_put_bits(&pb, buf, 128); + + put_bits(&pb, 32, PACK_START_CODE); + if (s->is_mpeg2) { + put_bits(&pb, 2, 0x1); + } else { + put_bits(&pb, 4, 0x2); + } + put_bits(&pb, 3, (uint32_t)((timestamp >> 30) & 0x07)); + put_bits(&pb, 1, 1); + put_bits(&pb, 15, (uint32_t)((timestamp >> 15) & 0x7fff)); + put_bits(&pb, 1, 1); + put_bits(&pb, 15, (uint32_t)((timestamp) & 0x7fff)); + put_bits(&pb, 1, 1); + if (s->is_mpeg2) { + /* clock extension */ + put_bits(&pb, 9, 0); + } + put_bits(&pb, 1, 1); + put_bits(&pb, 22, s->mux_rate); + put_bits(&pb, 1, 1); + if (s->is_mpeg2) { + put_bits(&pb, 1, 1); + put_bits(&pb, 5, 0x1f); /* reserved */ + put_bits(&pb, 3, 0); /* stuffing length */ + } + flush_put_bits(&pb); + return pbBufPtr(&pb) - pb.buf; +} + +static int put_system_header(AVFormatContext *ctx, uint8_t *buf,int only_for_stream_id) +{ + MpegMuxContext *s = ctx->priv_data; + int size, i, private_stream_coded, id; + PutBitContext pb; + + init_put_bits(&pb, buf, 128); + + put_bits(&pb, 32, SYSTEM_HEADER_START_CODE); + put_bits(&pb, 16, 0); + put_bits(&pb, 1, 1); + + put_bits(&pb, 22, s->mux_rate); /* maximum bit rate of the multiplexed stream */ + put_bits(&pb, 1, 1); /* marker */ + if (s->is_vcd && only_for_stream_id==VIDEO_ID) { + /* This header applies only to the video stream (see VCD standard p. IV-7)*/ + put_bits(&pb, 6, 0); + } else + put_bits(&pb, 6, s->audio_bound); + + if (s->is_vcd) { + /* see VCD standard, p. IV-7*/ + put_bits(&pb, 1, 0); + put_bits(&pb, 1, 1); + } else { + put_bits(&pb, 1, 0); /* variable bitrate*/ + put_bits(&pb, 1, 0); /* non constrainted bit stream */ + } + + if (s->is_vcd || s->is_dvd) { + /* see VCD standard p IV-7 */ + put_bits(&pb, 1, 1); /* audio locked */ + put_bits(&pb, 1, 1); /* video locked */ + } else { + put_bits(&pb, 1, 0); /* audio locked */ + put_bits(&pb, 1, 0); /* video locked */ + } + + put_bits(&pb, 1, 1); /* marker */ + + if (s->is_vcd && only_for_stream_id==AUDIO_ID) { + /* This header applies only to the audio stream (see VCD standard p. IV-7)*/ + put_bits(&pb, 5, 0); + } else + put_bits(&pb, 5, s->video_bound); + + if (s->is_dvd) { + put_bits(&pb, 1, 0); /* packet_rate_restriction_flag */ + put_bits(&pb, 7, 0x7f); /* reserved byte */ + } else + put_bits(&pb, 8, 0xff); /* reserved byte */ + + /* DVD-Video Stream_bound entries + id (0xB9) video, maximum P-STD for stream 0xE0. (P-STD_buffer_bound_scale = 1) + id (0xB8) audio, maximum P-STD for any MPEG audio (0xC0 to 0xC7) streams. If there are none set to 4096 (32x128). (P-STD_buffer_bound_scale = 0) + id (0xBD) private stream 1 (audio other than MPEG and subpictures). (P-STD_buffer_bound_scale = 1) + id (0xBF) private stream 2, NAV packs, set to 2x1024. */ + if (s->is_dvd) { + + int P_STD_max_video = 0; + int P_STD_max_mpeg_audio = 0; + int P_STD_max_mpeg_PS1 = 0; + + for(i=0;inb_streams;i++) { + StreamInfo *stream = ctx->streams[i]->priv_data; + + id = stream->id; + if (id == 0xbd && stream->max_buffer_size > P_STD_max_mpeg_PS1) { + P_STD_max_mpeg_PS1 = stream->max_buffer_size; + } else if (id >= 0xc0 && id <= 0xc7 && stream->max_buffer_size > P_STD_max_mpeg_audio) { + P_STD_max_mpeg_audio = stream->max_buffer_size; + } else if (id == 0xe0 && stream->max_buffer_size > P_STD_max_video) { + P_STD_max_video = stream->max_buffer_size; + } + } + + /* video */ + put_bits(&pb, 8, 0xb9); /* stream ID */ + put_bits(&pb, 2, 3); + put_bits(&pb, 1, 1); + put_bits(&pb, 13, P_STD_max_video / 1024); + + /* audio */ + if (P_STD_max_mpeg_audio == 0) + P_STD_max_mpeg_audio = 4096; + put_bits(&pb, 8, 0xb8); /* stream ID */ + put_bits(&pb, 2, 3); + put_bits(&pb, 1, 0); + put_bits(&pb, 13, P_STD_max_mpeg_audio / 128); + + /* private stream 1 */ + put_bits(&pb, 8, 0xbd); /* stream ID */ + put_bits(&pb, 2, 3); + put_bits(&pb, 1, 0); + put_bits(&pb, 13, P_STD_max_mpeg_PS1 / 128); + + /* private stream 2 */ + put_bits(&pb, 8, 0xbf); /* stream ID */ + put_bits(&pb, 2, 3); + put_bits(&pb, 1, 1); + put_bits(&pb, 13, 2); + } + else { + /* audio stream info */ + private_stream_coded = 0; + for(i=0;inb_streams;i++) { + StreamInfo *stream = ctx->streams[i]->priv_data; + + + /* For VCDs, only include the stream info for the stream + that the pack which contains this system belongs to. + (see VCD standard p. IV-7) */ + if ( !s->is_vcd || stream->id==only_for_stream_id + || only_for_stream_id==0) { + + id = stream->id; + if (id < 0xc0) { + /* special case for private streams (AC3 use that) */ + if (private_stream_coded) + continue; + private_stream_coded = 1; + id = 0xbd; + } + put_bits(&pb, 8, id); /* stream ID */ + put_bits(&pb, 2, 3); + if (id < 0xe0) { + /* audio */ + put_bits(&pb, 1, 0); + put_bits(&pb, 13, stream->max_buffer_size / 128); + } else { + /* video */ + put_bits(&pb, 1, 1); + put_bits(&pb, 13, stream->max_buffer_size / 1024); + } + } + } + } + + flush_put_bits(&pb); + size = pbBufPtr(&pb) - pb.buf; + /* patch packet size */ + buf[4] = (size - 6) >> 8; + buf[5] = (size - 6) & 0xff; + + return size; +} + +static int get_system_header_size(AVFormatContext *ctx) +{ + int buf_index, i, private_stream_coded; + StreamInfo *stream; + MpegMuxContext *s = ctx->priv_data; + + if (s->is_dvd) + return 18; // DVD-Video system headers are 18 bytes fixed length. + + buf_index = 12; + private_stream_coded = 0; + for(i=0;inb_streams;i++) { + stream = ctx->streams[i]->priv_data; + if (stream->id < 0xc0) { + if (private_stream_coded) + continue; + private_stream_coded = 1; + } + buf_index += 3; + } + return buf_index; +} + +static int mpeg_mux_init(AVFormatContext *ctx) +{ + MpegMuxContext *s = ctx->priv_data; + int bitrate, i, mpa_id, mpv_id, mps_id, ac3_id, dts_id, lpcm_id, j; + AVStream *st; + StreamInfo *stream; + int audio_bitrate; + int video_bitrate; + + s->packet_number = 0; + s->is_vcd = (ENABLE_MPEG1VCD_MUXER && ctx->oformat == &mpeg1vcd_muxer); + s->is_svcd = (ENABLE_MPEG2SVCD_MUXER && ctx->oformat == &mpeg2svcd_muxer); + s->is_mpeg2 = ((ENABLE_MPEG2VOB_MUXER && ctx->oformat == &mpeg2vob_muxer) || + (ENABLE_MPEG2DVD_MUXER && ctx->oformat == &mpeg2dvd_muxer) || + (ENABLE_MPEG2SVCD_MUXER && ctx->oformat == &mpeg2svcd_muxer)); + s->is_dvd = (ENABLE_MPEG2DVD_MUXER && ctx->oformat == &mpeg2dvd_muxer); + + if(ctx->packet_size) + s->packet_size = ctx->packet_size; + else + s->packet_size = 2048; + + s->vcd_padding_bytes_written = 0; + s->vcd_padding_bitrate=0; + + s->audio_bound = 0; + s->video_bound = 0; + mpa_id = AUDIO_ID; + ac3_id = AC3_ID; + dts_id = DTS_ID; + mpv_id = VIDEO_ID; + mps_id = SUB_ID; + lpcm_id = LPCM_ID; + for(i=0;inb_streams;i++) { + st = ctx->streams[i]; + stream = av_mallocz(sizeof(StreamInfo)); + if (!stream) + goto fail; + st->priv_data = stream; + + av_set_pts_info(st, 64, 1, 90000); + + switch(st->codec->codec_type) { + case CODEC_TYPE_AUDIO: + if (st->codec->codec_id == CODEC_ID_AC3) { + stream->id = ac3_id++; + } else if (st->codec->codec_id == CODEC_ID_DTS) { + stream->id = dts_id++; + } else if (st->codec->codec_id == CODEC_ID_PCM_S16BE) { + stream->id = lpcm_id++; + for(j = 0; j < 4; j++) { + if (lpcm_freq_tab[j] == st->codec->sample_rate) + break; + } + if (j == 4) + goto fail; + if (st->codec->channels > 8) + return -1; + stream->lpcm_header[0] = 0x0c; + stream->lpcm_header[1] = (st->codec->channels - 1) | (j << 4); + stream->lpcm_header[2] = 0x80; + stream->lpcm_align = st->codec->channels * 2; + } else { + stream->id = mpa_id++; + } + + /* This value HAS to be used for VCD (see VCD standard, p. IV-7). + Right now it is also used for everything else.*/ + stream->max_buffer_size = 4 * 1024; + s->audio_bound++; + break; + case CODEC_TYPE_VIDEO: + stream->id = mpv_id++; + if (st->codec->rc_buffer_size) + stream->max_buffer_size = 6*1024 + st->codec->rc_buffer_size/8; + else + stream->max_buffer_size = 230*1024; //FIXME this is probably too small as default +#if 0 + /* see VCD standard, p. IV-7*/ + stream->max_buffer_size = 46 * 1024; + else + /* This value HAS to be used for SVCD (see SVCD standard, p. 26 V.2.3.2). + Right now it is also used for everything else.*/ + stream->max_buffer_size = 230 * 1024; +#endif + s->video_bound++; + break; + case CODEC_TYPE_SUBTITLE: + stream->id = mps_id++; + stream->max_buffer_size = 16 * 1024; + break; + default: + return -1; + } + av_fifo_init(&stream->fifo, 16); + } + bitrate = 0; + audio_bitrate = 0; + video_bitrate = 0; + for(i=0;inb_streams;i++) { + int codec_rate; + st = ctx->streams[i]; + stream = (StreamInfo*) st->priv_data; + + if(st->codec->rc_max_rate || stream->id==VIDEO_ID) + codec_rate= st->codec->rc_max_rate; + else + codec_rate= st->codec->bit_rate; + + if(!codec_rate) + codec_rate= (1<<21)*8*50/ctx->nb_streams; + + bitrate += codec_rate; + + if (stream->id==AUDIO_ID) + audio_bitrate += codec_rate; + else if (stream->id==VIDEO_ID) + video_bitrate += codec_rate; + } + + if(ctx->mux_rate){ + s->mux_rate= (ctx->mux_rate + (8 * 50) - 1) / (8 * 50); + } else { + /* we increase slightly the bitrate to take into account the + headers. XXX: compute it exactly */ + bitrate += bitrate*5/100; + bitrate += 10000; + s->mux_rate = (bitrate + (8 * 50) - 1) / (8 * 50); + } + + if (s->is_vcd) { + double overhead_rate; + + /* The VCD standard mandates that the mux_rate field is 3528 + (see standard p. IV-6). + The value is actually "wrong", i.e. if you calculate + it using the normal formula and the 75 sectors per second transfer + rate you get a different value because the real pack size is 2324, + not 2352. But the standard explicitly specifies that the mux_rate + field in the header must have this value.*/ +// s->mux_rate=2352 * 75 / 50; /* = 3528*/ + + /* The VCD standard states that the muxed stream must be + exactly 75 packs / second (the data rate of a single speed cdrom). + Since the video bitrate (probably 1150000 bits/sec) will be below + the theoretical maximum we have to add some padding packets + to make up for the lower data rate. + (cf. VCD standard p. IV-6 )*/ + + /* Add the header overhead to the data rate. + 2279 data bytes per audio pack, 2294 data bytes per video pack*/ + overhead_rate = ((audio_bitrate / 8.0) / 2279) * (2324 - 2279); + overhead_rate += ((video_bitrate / 8.0) / 2294) * (2324 - 2294); + overhead_rate *= 8; + + /* Add padding so that the full bitrate is 2324*75 bytes/sec */ + s->vcd_padding_bitrate = 2324 * 75 * 8 - (bitrate + overhead_rate); + } + + if (s->is_vcd || s->is_mpeg2) + /* every packet */ + s->pack_header_freq = 1; + else + /* every 2 seconds */ + s->pack_header_freq = 2 * bitrate / s->packet_size / 8; + + /* the above seems to make pack_header_freq zero sometimes */ + if (s->pack_header_freq == 0) + s->pack_header_freq = 1; + + if (s->is_mpeg2) + /* every 200 packets. Need to look at the spec. */ + s->system_header_freq = s->pack_header_freq * 40; + else if (s->is_vcd) + /* the standard mandates that there are only two system headers + in the whole file: one in the first packet of each stream. + (see standard p. IV-7 and IV-8) */ + s->system_header_freq = 0x7fffffff; + else + s->system_header_freq = s->pack_header_freq * 5; + + for(i=0;inb_streams;i++) { + stream = ctx->streams[i]->priv_data; + stream->packet_number = 0; + } + s->system_header_size = get_system_header_size(ctx); + s->last_scr = 0; + return 0; + fail: + for(i=0;inb_streams;i++) { + av_free(ctx->streams[i]->priv_data); + } + return AVERROR(ENOMEM); +} + +static inline void put_timestamp(ByteIOContext *pb, int id, int64_t timestamp) +{ + put_byte(pb, + (id << 4) | + (((timestamp >> 30) & 0x07) << 1) | + 1); + put_be16(pb, (uint16_t)((((timestamp >> 15) & 0x7fff) << 1) | 1)); + put_be16(pb, (uint16_t)((((timestamp) & 0x7fff) << 1) | 1)); +} + + +/* return the number of padding bytes that should be inserted into + the multiplexed stream.*/ +static int get_vcd_padding_size(AVFormatContext *ctx, int64_t pts) +{ + MpegMuxContext *s = ctx->priv_data; + int pad_bytes = 0; + + if (s->vcd_padding_bitrate > 0 && pts!=AV_NOPTS_VALUE) + { + int64_t full_pad_bytes; + + full_pad_bytes = (int64_t)((s->vcd_padding_bitrate * (pts / 90000.0)) / 8.0); //FIXME this is wrong + pad_bytes = (int) (full_pad_bytes - s->vcd_padding_bytes_written); + + if (pad_bytes<0) + /* might happen if we have already padded to a later timestamp. This + can occur if another stream has already advanced further.*/ + pad_bytes=0; + } + + return pad_bytes; +} + + +#if 0 /* unused, remove? */ +/* return the exact available payload size for the next packet for + stream 'stream_index'. 'pts' and 'dts' are only used to know if + timestamps are needed in the packet header. */ +static int get_packet_payload_size(AVFormatContext *ctx, int stream_index, + int64_t pts, int64_t dts) +{ + MpegMuxContext *s = ctx->priv_data; + int buf_index; + StreamInfo *stream; + + stream = ctx->streams[stream_index]->priv_data; + + buf_index = 0; + if (((s->packet_number % s->pack_header_freq) == 0)) { + /* pack header size */ + if (s->is_mpeg2) + buf_index += 14; + else + buf_index += 12; + + if (s->is_vcd) { + /* there is exactly one system header for each stream in a VCD MPEG, + One in the very first video packet and one in the very first + audio packet (see VCD standard p. IV-7 and IV-8).*/ + + if (stream->packet_number==0) + /* The system headers refer only to the stream they occur in, + so they have a constant size.*/ + buf_index += 15; + + } else { + if ((s->packet_number % s->system_header_freq) == 0) + buf_index += s->system_header_size; + } + } + + if ((s->is_vcd && stream->packet_number==0) + || (s->is_svcd && s->packet_number==0)) + /* the first pack of each stream contains only the pack header, + the system header and some padding (see VCD standard p. IV-6) + Add the padding size, so that the actual payload becomes 0.*/ + buf_index += s->packet_size - buf_index; + else { + /* packet header size */ + buf_index += 6; + if (s->is_mpeg2) { + buf_index += 3; + if (stream->packet_number==0) + buf_index += 3; /* PES extension */ + buf_index += 1; /* obligatory stuffing byte */ + } + if (pts != AV_NOPTS_VALUE) { + if (dts != pts) + buf_index += 5 + 5; + else + buf_index += 5; + + } else { + if (!s->is_mpeg2) + buf_index++; + } + + if (stream->id < 0xc0) { + /* AC3/LPCM private data header */ + buf_index += 4; + if (stream->id >= 0xa0) { + int n; + buf_index += 3; + /* NOTE: we round the payload size to an integer number of + LPCM samples */ + n = (s->packet_size - buf_index) % stream->lpcm_align; + if (n) + buf_index += (stream->lpcm_align - n); + } + } + + if (s->is_vcd && stream->id == AUDIO_ID) + /* The VCD standard demands that 20 zero bytes follow + each audio packet (see standard p. IV-8).*/ + buf_index+=20; + } + return s->packet_size - buf_index; +} +#endif + +/* Write an MPEG padding packet header. */ +static void put_padding_packet(AVFormatContext *ctx, ByteIOContext *pb,int packet_bytes) +{ + MpegMuxContext *s = ctx->priv_data; + int i; + + put_be32(pb, PADDING_STREAM); + put_be16(pb, packet_bytes - 6); + if (!s->is_mpeg2) { + put_byte(pb, 0x0f); + packet_bytes -= 7; + } else + packet_bytes -= 6; + + for(i=0;ipremux_packet; + + while(len>0){ + if(pkt_desc->size == pkt_desc->unwritten_size) + nb_frames++; + len -= pkt_desc->unwritten_size; + pkt_desc= pkt_desc->next; + } + + return nb_frames; +} + +/* flush the packet on stream stream_index */ +static int flush_packet(AVFormatContext *ctx, int stream_index, + int64_t pts, int64_t dts, int64_t scr, int trailer_size) +{ + MpegMuxContext *s = ctx->priv_data; + StreamInfo *stream = ctx->streams[stream_index]->priv_data; + uint8_t *buf_ptr; + int size, payload_size, startcode, id, stuffing_size, i, header_len; + int packet_size; + uint8_t buffer[128]; + int zero_trail_bytes = 0; + int pad_packet_bytes = 0; + int pes_flags; + int general_pack = 0; /*"general" pack without data specific to one stream?*/ + int nb_frames; + + id = stream->id; + +#if 0 + printf("packet ID=%2x PTS=%0.3f\n", + id, pts / 90000.0); +#endif + + buf_ptr = buffer; + + if ((s->packet_number % s->pack_header_freq) == 0 || s->last_scr != scr) { + /* output pack and systems header if needed */ + size = put_pack_header(ctx, buf_ptr, scr); + buf_ptr += size; + s->last_scr= scr; + + if (s->is_vcd) { + /* there is exactly one system header for each stream in a VCD MPEG, + One in the very first video packet and one in the very first + audio packet (see VCD standard p. IV-7 and IV-8).*/ + + if (stream->packet_number==0) { + size = put_system_header(ctx, buf_ptr, id); + buf_ptr += size; + } + } else if (s->is_dvd) { + if (stream->align_iframe || s->packet_number == 0){ + int PES_bytes_to_fill = s->packet_size - size - 10; + + if (pts != AV_NOPTS_VALUE) { + if (dts != pts) + PES_bytes_to_fill -= 5 + 5; + else + PES_bytes_to_fill -= 5; + } + + if (stream->bytes_to_iframe == 0 || s->packet_number == 0) { + size = put_system_header(ctx, buf_ptr, 0); + buf_ptr += size; + size = buf_ptr - buffer; + put_buffer(ctx->pb, buffer, size); + + put_be32(ctx->pb, PRIVATE_STREAM_2); + put_be16(ctx->pb, 0x03d4); // length + put_byte(ctx->pb, 0x00); // substream ID, 00=PCI + for (i = 0; i < 979; i++) + put_byte(ctx->pb, 0x00); + + put_be32(ctx->pb, PRIVATE_STREAM_2); + put_be16(ctx->pb, 0x03fa); // length + put_byte(ctx->pb, 0x01); // substream ID, 01=DSI + for (i = 0; i < 1017; i++) + put_byte(ctx->pb, 0x00); + + memset(buffer, 0, 128); + buf_ptr = buffer; + s->packet_number++; + stream->align_iframe = 0; + scr += s->packet_size*90000LL / (s->mux_rate*50LL); //FIXME rounding and first few bytes of each packet + size = put_pack_header(ctx, buf_ptr, scr); + s->last_scr= scr; + buf_ptr += size; + /* GOP Start */ + } else if (stream->bytes_to_iframe < PES_bytes_to_fill) { + pad_packet_bytes = PES_bytes_to_fill - stream->bytes_to_iframe; + } + } + } else { + if ((s->packet_number % s->system_header_freq) == 0) { + size = put_system_header(ctx, buf_ptr, 0); + buf_ptr += size; + } + } + } + size = buf_ptr - buffer; + put_buffer(ctx->pb, buffer, size); + + packet_size = s->packet_size - size; + + if (s->is_vcd && id == AUDIO_ID) + /* The VCD standard demands that 20 zero bytes follow + each audio pack (see standard p. IV-8).*/ + zero_trail_bytes += 20; + + if ((s->is_vcd && stream->packet_number==0) + || (s->is_svcd && s->packet_number==0)) { + /* for VCD the first pack of each stream contains only the pack header, + the system header and lots of padding (see VCD standard p. IV-6). + In the case of an audio pack, 20 zero bytes are also added at + the end.*/ + /* For SVCD we fill the very first pack to increase compatibility with + some DVD players. Not mandated by the standard.*/ + if (s->is_svcd) + general_pack = 1; /* the system header refers to both streams and no stream data*/ + pad_packet_bytes = packet_size - zero_trail_bytes; + } + + packet_size -= pad_packet_bytes + zero_trail_bytes; + + if (packet_size > 0) { + + /* packet header size */ + packet_size -= 6; + + /* packet header */ + if (s->is_mpeg2) { + header_len = 3; + if (stream->packet_number==0) + header_len += 3; /* PES extension */ + header_len += 1; /* obligatory stuffing byte */ + } else { + header_len = 0; + } + if (pts != AV_NOPTS_VALUE) { + if (dts != pts) + header_len += 5 + 5; + else + header_len += 5; + } else { + if (!s->is_mpeg2) + header_len++; + } + + payload_size = packet_size - header_len; + if (id < 0xc0) { + startcode = PRIVATE_STREAM_1; + payload_size -= 1; + if (id >= 0x40) { + payload_size -= 3; + if (id >= 0xa0) + payload_size -= 3; + } + } else { + startcode = 0x100 + id; + } + + stuffing_size = payload_size - av_fifo_size(&stream->fifo); + + // first byte does not fit -> reset pts/dts + stuffing + if(payload_size <= trailer_size && pts != AV_NOPTS_VALUE){ + int timestamp_len=0; + if(dts != pts) + timestamp_len += 5; + if(pts != AV_NOPTS_VALUE) + timestamp_len += s->is_mpeg2 ? 5 : 4; + pts=dts= AV_NOPTS_VALUE; + header_len -= timestamp_len; + if (s->is_dvd && stream->align_iframe) { + pad_packet_bytes += timestamp_len; + packet_size -= timestamp_len; + } else { + payload_size += timestamp_len; + } + stuffing_size += timestamp_len; + if(payload_size > trailer_size) + stuffing_size += payload_size - trailer_size; + } + + if (pad_packet_bytes > 0 && pad_packet_bytes <= 7) { // can't use padding, so use stuffing + packet_size += pad_packet_bytes; + payload_size += pad_packet_bytes; // undo the previous adjustment + if (stuffing_size < 0) { + stuffing_size = pad_packet_bytes; + } else { + stuffing_size += pad_packet_bytes; + } + pad_packet_bytes = 0; + } + + if (stuffing_size < 0) + stuffing_size = 0; + if (stuffing_size > 16) { /*<=16 for MPEG-1, <=32 for MPEG-2*/ + pad_packet_bytes += stuffing_size; + packet_size -= stuffing_size; + payload_size -= stuffing_size; + stuffing_size = 0; + } + + nb_frames= get_nb_frames(ctx, stream, payload_size - stuffing_size); + + put_be32(ctx->pb, startcode); + + put_be16(ctx->pb, packet_size); + + if (!s->is_mpeg2) + for(i=0;ipb, 0xff); + + if (s->is_mpeg2) { + put_byte(ctx->pb, 0x80); /* mpeg2 id */ + + pes_flags=0; + + if (pts != AV_NOPTS_VALUE) { + pes_flags |= 0x80; + if (dts != pts) + pes_flags |= 0x40; + } + + /* Both the MPEG-2 and the SVCD standards demand that the + P-STD_buffer_size field be included in the first packet of + every stream. (see SVCD standard p. 26 V.2.3.1 and V.2.3.2 + and MPEG-2 standard 2.7.7) */ + if (stream->packet_number == 0) + pes_flags |= 0x01; + + put_byte(ctx->pb, pes_flags); /* flags */ + put_byte(ctx->pb, header_len - 3 + stuffing_size); + + if (pes_flags & 0x80) /*write pts*/ + put_timestamp(ctx->pb, (pes_flags & 0x40) ? 0x03 : 0x02, pts); + if (pes_flags & 0x40) /*write dts*/ + put_timestamp(ctx->pb, 0x01, dts); + + if (pes_flags & 0x01) { /*write pes extension*/ + put_byte(ctx->pb, 0x10); /* flags */ + + /* P-STD buffer info */ + if (id == AUDIO_ID) + put_be16(ctx->pb, 0x4000 | stream->max_buffer_size/128); + else + put_be16(ctx->pb, 0x6000 | stream->max_buffer_size/1024); + } + + } else { + if (pts != AV_NOPTS_VALUE) { + if (dts != pts) { + put_timestamp(ctx->pb, 0x03, pts); + put_timestamp(ctx->pb, 0x01, dts); + } else { + put_timestamp(ctx->pb, 0x02, pts); + } + } else { + put_byte(ctx->pb, 0x0f); + } + } + + if (s->is_mpeg2) { + /* special stuffing byte that is always written + to prevent accidental generation of start codes. */ + put_byte(ctx->pb, 0xff); + + for(i=0;ipb, 0xff); + } + + if (startcode == PRIVATE_STREAM_1) { + put_byte(ctx->pb, id); + if (id >= 0xa0) { + /* LPCM (XXX: check nb_frames) */ + put_byte(ctx->pb, 7); + put_be16(ctx->pb, 4); /* skip 3 header bytes */ + put_byte(ctx->pb, stream->lpcm_header[0]); + put_byte(ctx->pb, stream->lpcm_header[1]); + put_byte(ctx->pb, stream->lpcm_header[2]); + } else if (id >= 0x40) { + /* AC3 */ + put_byte(ctx->pb, nb_frames); + put_be16(ctx->pb, trailer_size+1); + } + } + + /* output data */ + if(av_fifo_generic_read(&stream->fifo, payload_size - stuffing_size, &put_buffer, ctx->pb) < 0) + return -1; + stream->bytes_to_iframe -= payload_size - stuffing_size; + }else{ + payload_size= + stuffing_size= 0; + } + + if (pad_packet_bytes > 0) + put_padding_packet(ctx,ctx->pb, pad_packet_bytes); + + for(i=0;ipb, 0x00); + + put_flush_packet(ctx->pb); + + s->packet_number++; + + /* only increase the stream packet number if this pack actually contains + something that is specific to this stream! I.e. a dedicated header + or some data.*/ + if (!general_pack) + stream->packet_number++; + + return payload_size - stuffing_size; +} + +static void put_vcd_padding_sector(AVFormatContext *ctx) +{ + /* There are two ways to do this padding: writing a sector/pack + of 0 values, or writing an MPEG padding pack. Both seem to + work with most decoders, BUT the VCD standard only allows a 0-sector + (see standard p. IV-4, IV-5). + So a 0-sector it is...*/ + + MpegMuxContext *s = ctx->priv_data; + int i; + + for(i=0;ipacket_size;i++) + put_byte(ctx->pb, 0); + + s->vcd_padding_bytes_written += s->packet_size; + + put_flush_packet(ctx->pb); + + /* increasing the packet number is correct. The SCR of the following packs + is calculated from the packet_number and it has to include the padding + sector (it represents the sector index, not the MPEG pack index) + (see VCD standard p. IV-6)*/ + s->packet_number++; +} + +#if 0 /* unused, remove? */ +static int64_t get_vcd_scr(AVFormatContext *ctx,int stream_index,int64_t pts) +{ + MpegMuxContext *s = ctx->priv_data; + int64_t scr; + + /* Since the data delivery rate is constant, SCR is computed + using the formula C + i * 1200 where C is the start constant + and i is the pack index. + It is recommended that SCR 0 is at the beginning of the VCD front + margin (a sequence of empty Form 2 sectors on the CD). + It is recommended that the front margin is 30 sectors long, so + we use C = 30*1200 = 36000 + (Note that even if the front margin is not 30 sectors the file + will still be correct according to the standard. It just won't have + the "recommended" value).*/ + scr = 36000 + s->packet_number * 1200; + + return scr; +} +#endif + +static int remove_decoded_packets(AVFormatContext *ctx, int64_t scr){ +// MpegMuxContext *s = ctx->priv_data; + int i; + + for(i=0; inb_streams; i++){ + AVStream *st = ctx->streams[i]; + StreamInfo *stream = st->priv_data; + PacketDesc *pkt_desc; + + while((pkt_desc= stream->predecode_packet) + && scr > pkt_desc->dts){ //FIXME > vs >= + if(stream->buffer_index < pkt_desc->size || + stream->predecode_packet == stream->premux_packet){ + av_log(ctx, AV_LOG_ERROR, + "buffer underflow i=%d bufi=%d size=%d\n", + i, stream->buffer_index, pkt_desc->size); + break; + } + stream->buffer_index -= pkt_desc->size; + + stream->predecode_packet= pkt_desc->next; + av_freep(&pkt_desc); + } + } + + return 0; +} + +static int output_packet(AVFormatContext *ctx, int flush){ + MpegMuxContext *s = ctx->priv_data; + AVStream *st; + StreamInfo *stream; + int i, avail_space=0, es_size, trailer_size; + int best_i= -1; + int best_score= INT_MIN; + int ignore_constraints=0; + int64_t scr= s->last_scr; + PacketDesc *timestamp_packet; + const int64_t max_delay= av_rescale(ctx->max_delay, 90000, AV_TIME_BASE); + +retry: + for(i=0; inb_streams; i++){ + AVStream *st = ctx->streams[i]; + StreamInfo *stream = st->priv_data; + const int avail_data= av_fifo_size(&stream->fifo); + const int space= stream->max_buffer_size - stream->buffer_index; + int rel_space= 1024*space / stream->max_buffer_size; + PacketDesc *next_pkt= stream->premux_packet; + + /* for subtitle, a single PES packet must be generated, + so we flush after every single subtitle packet */ + if(s->packet_size > avail_data && !flush + && st->codec->codec_type != CODEC_TYPE_SUBTITLE) + return 0; + if(avail_data==0) + continue; + assert(avail_data>0); + + if(space < s->packet_size && !ignore_constraints) + continue; + + if(next_pkt && next_pkt->dts - scr > max_delay) + continue; + + if(rel_space > best_score){ + best_score= rel_space; + best_i = i; + avail_space= space; + } + } + + if(best_i < 0){ + int64_t best_dts= INT64_MAX; + + for(i=0; inb_streams; i++){ + AVStream *st = ctx->streams[i]; + StreamInfo *stream = st->priv_data; + PacketDesc *pkt_desc= stream->predecode_packet; + if(pkt_desc && pkt_desc->dts < best_dts) + best_dts= pkt_desc->dts; + } + +#if 0 + av_log(ctx, AV_LOG_DEBUG, "bumping scr, scr:%f, dts:%f\n", + scr/90000.0, best_dts/90000.0); +#endif + if(best_dts == INT64_MAX) + return 0; + + if(scr >= best_dts+1 && !ignore_constraints){ + av_log(ctx, AV_LOG_ERROR, "packet too large, ignoring buffer limits to mux it\n"); + ignore_constraints= 1; + } + scr= FFMAX(best_dts+1, scr); + if(remove_decoded_packets(ctx, scr) < 0) + return -1; + goto retry; + } + + assert(best_i >= 0); + + st = ctx->streams[best_i]; + stream = st->priv_data; + + assert(av_fifo_size(&stream->fifo) > 0); + + assert(avail_space >= s->packet_size || ignore_constraints); + + timestamp_packet= stream->premux_packet; + if(timestamp_packet->unwritten_size == timestamp_packet->size){ + trailer_size= 0; + }else{ + trailer_size= timestamp_packet->unwritten_size; + timestamp_packet= timestamp_packet->next; + } + + if(timestamp_packet){ +//av_log(ctx, AV_LOG_DEBUG, "dts:%f pts:%f scr:%f stream:%d\n", timestamp_packet->dts/90000.0, timestamp_packet->pts/90000.0, scr/90000.0, best_i); + es_size= flush_packet(ctx, best_i, timestamp_packet->pts, timestamp_packet->dts, scr, trailer_size); + }else{ + assert(av_fifo_size(&stream->fifo) == trailer_size); + es_size= flush_packet(ctx, best_i, AV_NOPTS_VALUE, AV_NOPTS_VALUE, scr, trailer_size); + } + + if (s->is_vcd) { + /* Write one or more padding sectors, if necessary, to reach + the constant overall bitrate.*/ + int vcd_pad_bytes; + + while((vcd_pad_bytes = get_vcd_padding_size(ctx,stream->premux_packet->pts) ) >= s->packet_size){ //FIXME pts cannot be correct here + put_vcd_padding_sector(ctx); + s->last_scr += s->packet_size*90000LL / (s->mux_rate*50LL); //FIXME rounding and first few bytes of each packet + } + } + + stream->buffer_index += es_size; + s->last_scr += s->packet_size*90000LL / (s->mux_rate*50LL); //FIXME rounding and first few bytes of each packet + + while(stream->premux_packet && stream->premux_packet->unwritten_size <= es_size){ + es_size -= stream->premux_packet->unwritten_size; + stream->premux_packet= stream->premux_packet->next; + } + if(es_size) + stream->premux_packet->unwritten_size -= es_size; + + if(remove_decoded_packets(ctx, s->last_scr) < 0) + return -1; + + return 1; +} + +static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt) +{ + MpegMuxContext *s = ctx->priv_data; + int stream_index= pkt->stream_index; + int size= pkt->size; + uint8_t *buf= pkt->data; + AVStream *st = ctx->streams[stream_index]; + StreamInfo *stream = st->priv_data; + int64_t pts, dts; + PacketDesc *pkt_desc; + const int preload= av_rescale(ctx->preload, 90000, AV_TIME_BASE); + const int is_iframe = st->codec->codec_type == CODEC_TYPE_VIDEO && (pkt->flags & PKT_FLAG_KEY); + + pts= pkt->pts; + dts= pkt->dts; + + if(pts != AV_NOPTS_VALUE) pts += preload; + if(dts != AV_NOPTS_VALUE) dts += preload; + +//av_log(ctx, AV_LOG_DEBUG, "dts:%f pts:%f flags:%d stream:%d nopts:%d\n", dts/90000.0, pts/90000.0, pkt->flags, pkt->stream_index, pts != AV_NOPTS_VALUE); + if (!stream->premux_packet) + stream->next_packet = &stream->premux_packet; + *stream->next_packet= + pkt_desc= av_mallocz(sizeof(PacketDesc)); + pkt_desc->pts= pts; + pkt_desc->dts= dts; + pkt_desc->unwritten_size= + pkt_desc->size= size; + if(!stream->predecode_packet) + stream->predecode_packet= pkt_desc; + stream->next_packet= &pkt_desc->next; + + av_fifo_realloc(&stream->fifo, av_fifo_size(&stream->fifo) + size + 1); + + if (s->is_dvd){ + if (is_iframe && (s->packet_number == 0 || (pts - stream->vobu_start_pts >= 36000))) { // min VOBU length 0.4 seconds (mpucoder) + stream->bytes_to_iframe = av_fifo_size(&stream->fifo); + stream->align_iframe = 1; + stream->vobu_start_pts = pts; + } + } + + av_fifo_write(&stream->fifo, buf, size); + + for(;;){ + int ret= output_packet(ctx, 0); + if(ret<=0) + return ret; + } +} + +static int mpeg_mux_end(AVFormatContext *ctx) +{ +// MpegMuxContext *s = ctx->priv_data; + StreamInfo *stream; + int i; + + for(;;){ + int ret= output_packet(ctx, 1); + if(ret<0) + return ret; + else if(ret==0) + break; + } + + /* End header according to MPEG1 systems standard. We do not write + it as it is usually not needed by decoders and because it + complicates MPEG stream concatenation. */ + //put_be32(ctx->pb, ISO_11172_END_CODE); + //put_flush_packet(ctx->pb); + + for(i=0;inb_streams;i++) { + stream = ctx->streams[i]->priv_data; + + assert(av_fifo_size(&stream->fifo) == 0); + av_fifo_free(&stream->fifo); + } + return 0; +} + +#ifdef CONFIG_MPEG1SYSTEM_MUXER +AVOutputFormat mpeg1system_muxer = { + "mpeg", + "MPEG1 System format", + "video/mpeg", + "mpg,mpeg", + sizeof(MpegMuxContext), + CODEC_ID_MP2, + CODEC_ID_MPEG1VIDEO, + mpeg_mux_init, + mpeg_mux_write_packet, + mpeg_mux_end, +}; +#endif +#ifdef CONFIG_MPEG1VCD_MUXER +AVOutputFormat mpeg1vcd_muxer = { + "vcd", + "MPEG1 System format (VCD)", + "video/mpeg", + NULL, + sizeof(MpegMuxContext), + CODEC_ID_MP2, + CODEC_ID_MPEG1VIDEO, + mpeg_mux_init, + mpeg_mux_write_packet, + mpeg_mux_end, +}; +#endif +#ifdef CONFIG_MPEG2VOB_MUXER +AVOutputFormat mpeg2vob_muxer = { + "vob", + "MPEG2 PS format (VOB)", + "video/mpeg", + "vob", + sizeof(MpegMuxContext), + CODEC_ID_MP2, + CODEC_ID_MPEG2VIDEO, + mpeg_mux_init, + mpeg_mux_write_packet, + mpeg_mux_end, +}; +#endif + +/* Same as mpeg2vob_mux except that the pack size is 2324 */ +#ifdef CONFIG_MPEG2SVCD_MUXER +AVOutputFormat mpeg2svcd_muxer = { + "svcd", + "MPEG2 PS format (VOB)", + "video/mpeg", + "vob", + sizeof(MpegMuxContext), + CODEC_ID_MP2, + CODEC_ID_MPEG2VIDEO, + mpeg_mux_init, + mpeg_mux_write_packet, + mpeg_mux_end, +}; +#endif + +/* Same as mpeg2vob_mux except the 'is_dvd' flag is set to produce NAV pkts */ +#ifdef CONFIG_MPEG2DVD_MUXER +AVOutputFormat mpeg2dvd_muxer = { + "dvd", + "MPEG2 PS format (DVD VOB)", + "video/mpeg", + "dvd", + sizeof(MpegMuxContext), + CODEC_ID_MP2, + CODEC_ID_MPEG2VIDEO, + mpeg_mux_init, + mpeg_mux_write_packet, + mpeg_mux_end, +}; +#endif diff --git a/contrib/ffmpeg/libavformat/mpegts.c b/contrib/ffmpeg/libavformat/mpegts.c index c466710ee..ab046199a 100644 --- a/contrib/ffmpeg/libavformat/mpegts.c +++ b/contrib/ffmpeg/libavformat/mpegts.c @@ -31,25 +31,30 @@ /* maximum size in which we look for synchronisation if synchronisation is lost */ #define MAX_RESYNC_SIZE 4096 +#define REGISTRATION_DESCRIPTOR 5 typedef struct PESContext PESContext; -static PESContext* add_pes_stream(MpegTSContext *ts, int pid, int stream_type); +static PESContext* add_pes_stream(MpegTSContext *ts, int pid, int pcr_pid, int stream_type); static AVStream* new_pes_av_stream(PESContext *pes, uint32_t code); +extern void av_set_program_name(AVProgram *program, char *provider_name, char *name); +extern void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx); enum MpegTSFilterType { MPEGTS_PES, MPEGTS_SECTION, }; -typedef void PESCallback(void *opaque, const uint8_t *buf, int len, int is_start); +typedef struct MpegTSFilter MpegTSFilter; + +typedef void PESCallback(MpegTSFilter *f, const uint8_t *buf, int len, int is_start); typedef struct MpegTSPESFilter { PESCallback *pes_cb; void *opaque; } MpegTSPESFilter; -typedef void SectionCallback(void *opaque, const uint8_t *buf, int len); +typedef void SectionCallback(MpegTSFilter *f, const uint8_t *buf, int len); typedef void SetServiceCallback(void *opaque, int ret); @@ -63,7 +68,7 @@ typedef struct MpegTSSectionFilter { void *opaque; } MpegTSSectionFilter; -typedef struct MpegTSFilter { +struct MpegTSFilter { int pid; int last_cc; /* last cc code (-1 if first packet) */ enum MpegTSFilterType type; @@ -71,14 +76,14 @@ typedef struct MpegTSFilter { MpegTSPESFilter pes_filter; MpegTSSectionFilter section_filter; } u; -} MpegTSFilter; +}; -typedef struct MpegTSService { - int running:1; - int sid; /**< MPEG Program Number of stream */ - char *provider_name; /**< DVB Network name, "" if not DVB stream */ - char *name; /**< DVB Service name, "MPEG Program [sid]" if not DVB stream*/ -} MpegTSService; +#define MAX_PIDS_PER_PROGRAM 64 +typedef struct { + unsigned int id; //program id/service id + unsigned int nb_pids; + unsigned int pids[MAX_PIDS_PER_PROGRAM]; +} Program_t; struct MpegTSContext { /* user data */ @@ -87,16 +92,12 @@ struct MpegTSContext { int raw_packet_size; /** if true, all pids are analyzed to find streams */ int auto_guess; - int set_service_ret; - /** force raw MPEG2 transport stream output, if possible */ - int mpeg2ts_raw; /** compute exact PCR for each transport stream packet */ int mpeg2ts_compute_pcr; int64_t cur_pcr; /**< used to estimate the exact PCR */ int pcr_incr; /**< used to estimate the exact PCR */ - int pcr_pid; /**< used to estimate the exact PCR */ /* data needed to handle file based ts */ /** stop parsing loop */ @@ -107,26 +108,125 @@ struct MpegTSContext { /******************************************/ /* private mpegts data */ /* scan context */ - MpegTSFilter *sdt_filter; - /** number of PMTs in the last PAT seen */ - int nb_services; - /** list of PMTs in the last PAT seen */ - MpegTSService **services; - - /* set service context (XXX: allocated it ?) */ - SetServiceCallback *set_service_cb; - void *set_service_opaque; - /** filter for the PAT */ - MpegTSFilter *pat_filter; - /** filter for the PMT for the MPEG program number specified by req_sid */ - MpegTSFilter *pmt_filter; - /** MPEG program number of stream we want to decode */ - int req_sid; + /** structure to keep track of Program->pids mapping */ + unsigned int nb_prg; + Program_t *prg; + /** filters for various streams specified by PMT + for the PAT and PMT */ MpegTSFilter *pids[NB_PID_MAX]; }; +/* TS stream handling */ + +enum MpegTSState { + MPEGTS_HEADER = 0, + MPEGTS_PESHEADER_FILL, + MPEGTS_PAYLOAD, + MPEGTS_SKIP, +}; + +/* enough for PES header + length */ +#define PES_START_SIZE 9 +#define MAX_PES_HEADER_SIZE (9 + 255) + +struct PESContext { + int pid; + int pcr_pid; /**< if -1 then all packets containing PCR are considered */ + int stream_type; + MpegTSContext *ts; + AVFormatContext *stream; + AVStream *st; + enum MpegTSState state; + /* used to get the format */ + int data_index; + int total_size; + int pes_header_size; + int64_t pts, dts; + uint8_t header[MAX_PES_HEADER_SIZE]; +}; + +extern AVInputFormat mpegts_demuxer; + +static void clear_program(MpegTSContext *ts, unsigned int programid) +{ + int i; + + for(i=0; inb_prg; i++) + if(ts->prg[i].id == programid) + ts->prg[i].nb_pids = 0; +} + +static void clear_programs(MpegTSContext *ts) +{ + av_freep(&ts->prg); + ts->nb_prg=0; +} + +static void add_pat_entry(MpegTSContext *ts, unsigned int programid) +{ + Program_t *p; + void *tmp = av_realloc(ts->prg, (ts->nb_prg+1)*sizeof(Program_t)); + if(!tmp) + return; + ts->prg = tmp; + p = &ts->prg[ts->nb_prg]; + p->id = programid; + p->nb_pids = 0; + ts->nb_prg++; +} + +static void add_pid_to_pmt(MpegTSContext *ts, unsigned int programid, unsigned int pid) +{ + int i; + Program_t *p = NULL; + for(i=0; inb_prg; i++) { + if(ts->prg[i].id == programid) { + p = &ts->prg[i]; + break; + } + } + if(!p) + return; + + if(p->nb_pids >= MAX_PIDS_PER_PROGRAM) + return; + p->pids[p->nb_pids++] = pid; +} + +/** + * \brief discard_pid() decides if the pid is to be discarded according + * to caller's programs selection + * \param ts : - TS context + * \param pid : - pid + * \return 1 if the pid is only comprised in programs that have .discard=AVDISCARD_ALL + * 0 otherwise + */ +static int discard_pid(MpegTSContext *ts, unsigned int pid) +{ + int i, j, k; + int used = 0, discarded = 0; + Program_t *p; + for(i=0; inb_prg; i++) { + p = &ts->prg[i]; + for(j=0; jnb_pids; j++) { + if(p->pids[j] != pid) + continue; + //is program with id p->id set to be discarded? + for(k=0; kstream->nb_programs; k++) { + if(ts->stream->programs[k]->id == p->id) { + if(ts->stream->programs[k]->discard == AVDISCARD_ALL) + discarded++; + else + used++; + } + } + } + } + + return (!used && discarded); +} + /** * Assembles PES packets out of TS packets, and then calls the "section_cb" * function when they are complete. @@ -154,7 +254,7 @@ static void write_section_data(AVFormatContext *s, MpegTSFilter *tss1, /* compute section length if possible */ if (tss->section_h_size == -1 && tss->section_index >= 3) { - len = (((tss->section_buf[1] & 0xf) << 8) | tss->section_buf[2]) + 3; + len = (AV_RB16(tss->section_buf + 1) & 0xfff) + 3; if (len > 4096) return; tss->section_h_size = len; @@ -163,8 +263,9 @@ static void write_section_data(AVFormatContext *s, MpegTSFilter *tss1, if (tss->section_h_size != -1 && tss->section_index >= tss->section_h_size) { tss->end_of_section_reached = 1; if (!tss->check_crc || - av_crc(av_crc04C11DB7, -1, tss->section_buf, tss->section_h_size) == 0) - tss->section_cb(tss->opaque, tss->section_buf, tss->section_h_size); + av_crc(av_crc_get_table(AV_CRC_32_IEEE), -1, + tss->section_buf, tss->section_h_size) == 0) + tss->section_cb(tss1, tss->section_buf, tss->section_h_size); } } @@ -308,7 +409,7 @@ static inline int get16(const uint8_t **pp, const uint8_t *p_end) p = *pp; if ((p + 1) >= p_end) return -1; - c = (p[0] << 8) | p[1]; + c = AV_RB16(p); p += 2; *pp = p; return c; @@ -366,30 +467,10 @@ static int parse_section_header(SectionHeader *h, return 0; } -static MpegTSService *new_service(MpegTSContext *ts, int sid, - char *provider_name, char *name) -{ - MpegTSService *service; - -#ifdef DEBUG_SI - av_log(ts->stream, AV_LOG_DEBUG, "new_service: " - "sid=0x%04x provider='%s' name='%s'\n", - sid, provider_name, name); -#endif - - service = av_mallocz(sizeof(MpegTSService)); - if (!service) - return NULL; - service->sid = sid; - service->provider_name = provider_name; - service->name = name; - dynarray_add(&ts->services, &ts->nb_services, service); - return service; -} -static void pmt_cb(void *opaque, const uint8_t *section, int section_len) +static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) { - MpegTSContext *ts = opaque; + MpegTSContext *ts = filter->u.section_filter.opaque; SectionHeader h1, *h = &h1; PESContext *pes; AVStream *st; @@ -397,7 +478,8 @@ static void pmt_cb(void *opaque, const uint8_t *section, int section_len) int program_info_length, pcr_pid, pid, stream_type; int desc_list_len, desc_len, desc_tag; int comp_page = 0, anc_page = 0; /* initialize to kill warnings */ - char language[4]; + char language[4] = {0}; /* initialize to kill warnings */ + int has_hdmv_descr = 0; #ifdef DEBUG_SI av_log(ts->stream, AV_LOG_DEBUG, "PMT: len %i\n", section_len); @@ -411,19 +493,41 @@ static void pmt_cb(void *opaque, const uint8_t *section, int section_len) av_log(ts->stream, AV_LOG_DEBUG, "sid=0x%x sec_num=%d/%d\n", h->id, h->sec_num, h->last_sec_num); #endif - if (h->tid != PMT_TID || (ts->req_sid >= 0 && h->id != ts->req_sid) ) + if (h->tid != PMT_TID) return; + clear_program(ts, h->id); pcr_pid = get16(&p, p_end) & 0x1fff; if (pcr_pid < 0) return; - ts->pcr_pid = pcr_pid; + add_pid_to_pmt(ts, h->id, pcr_pid); #ifdef DEBUG_SI av_log(ts->stream, AV_LOG_DEBUG, "pcr_pid=0x%x\n", pcr_pid); #endif program_info_length = get16(&p, p_end) & 0xfff; if (program_info_length < 0) return; + while(program_info_length >= 2) { + uint8_t tag, len; + tag = get8(&p, p_end); + len = get8(&p, p_end); + if(len > program_info_length - 2) + //something else is broken, exit the program_descriptors_loop + break; + program_info_length -= len + 2; + if(tag == REGISTRATION_DESCRIPTOR && len >= 4) { + uint8_t bytes[4]; + bytes[0] = get8(&p, p_end); + bytes[1] = get8(&p, p_end); + bytes[2] = get8(&p, p_end); + bytes[3] = get8(&p, p_end); + len -= 4; + if(bytes[0] == 'H' && bytes[1] == 'D' && + bytes[2] == 'M' && bytes[3] == 'V') + has_hdmv_descr = 1; + } + p += len; + } p += program_info_length; if (p >= p_end) return; @@ -507,10 +611,22 @@ static void pmt_cb(void *opaque, const uint8_t *section, int section_len) case STREAM_TYPE_AUDIO_AAC: case STREAM_TYPE_AUDIO_AC3: case STREAM_TYPE_AUDIO_DTS: + case STREAM_TYPE_AUDIO_HDMV_DTS: case STREAM_TYPE_SUBTITLE_DVB: - pes = add_pes_stream(ts, pid, stream_type); - if (pes) - st = new_pes_av_stream(pes, 0); + if(stream_type == STREAM_TYPE_AUDIO_HDMV_DTS && !has_hdmv_descr) + break; + if(ts->pids[pid] && ts->pids[pid]->type == MPEGTS_PES){ + pes= ts->pids[pid]->u.pes_filter.opaque; + st= pes->st; + }else{ + if (ts->pids[pid]) mpegts_close_filter(ts, ts->pids[pid]); //wrongly added sdt filter probably + pes = add_pes_stream(ts, pid, pcr_pid, stream_type); + if (pes) + st = new_pes_av_stream(pes, 0); + } + add_pid_to_pmt(ts, h->id, pid); + if(st) + av_program_add_stream_index(ts->stream, h->id, st->index); break; default: /* we ignore the other streams */ @@ -519,10 +635,7 @@ static void pmt_cb(void *opaque, const uint8_t *section, int section_len) if (st) { if (language[0] != 0) { - st->language[0] = language[0]; - st->language[1] = language[1]; - st->language[2] = language[2]; - st->language[3] = language[3]; + memcpy(st->language, language, 4); } if (stream_type == STREAM_TYPE_SUBTITLE_DVB) { @@ -531,14 +644,13 @@ static void pmt_cb(void *opaque, const uint8_t *section, int section_len) } } /* all parameters are there */ - ts->set_service_cb(ts->set_service_opaque, 0); - mpegts_close_filter(ts, ts->pmt_filter); - ts->pmt_filter = NULL; + ts->stop_parse++; + mpegts_close_filter(ts, filter); } -static void pat_cb(void *opaque, const uint8_t *section, int section_len) +static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) { - MpegTSContext *ts = opaque; + MpegTSContext *ts = filter->u.section_filter.opaque; SectionHeader h1, *h = &h1; const uint8_t *p, *p_end; int sid, pmt_pid; @@ -554,6 +666,7 @@ static void pat_cb(void *opaque, const uint8_t *section, int section_len) if (h->tid != PAT_TID) return; + clear_programs(ts); for(;;) { sid = get16(&p, p_end); if (sid < 0) @@ -567,87 +680,29 @@ static void pat_cb(void *opaque, const uint8_t *section, int section_len) if (sid == 0x0000) { /* NIT info */ } else { - if (ts->req_sid == sid) { - ts->pmt_filter = mpegts_open_section_filter(ts, pmt_pid, - pmt_cb, ts, 1); - goto found; - } + av_new_program(ts->stream, sid); + ts->stop_parse--; + mpegts_open_section_filter(ts, pmt_pid, pmt_cb, ts, 1); + add_pat_entry(ts, sid); + add_pid_to_pmt(ts, sid, 0); //add pat pid to program + add_pid_to_pmt(ts, sid, pmt_pid); } } /* not found */ - ts->set_service_cb(ts->set_service_opaque, -1); + ts->stop_parse++; - found: - mpegts_close_filter(ts, ts->pat_filter); - ts->pat_filter = NULL; + mpegts_close_filter(ts, filter); } -/* add all services found in the PAT */ -static void pat_scan_cb(void *opaque, const uint8_t *section, int section_len) +static void mpegts_set_service(MpegTSContext *ts) { - MpegTSContext *ts = opaque; - SectionHeader h1, *h = &h1; - const uint8_t *p, *p_end; - int sid, pmt_pid; - char *provider_name, *name; - char buf[256]; - -#ifdef DEBUG_SI - av_log(ts->stream, AV_LOG_DEBUG, "PAT:\n"); - av_hex_dump_log(ts->stream, AV_LOG_DEBUG, (uint8_t *)section, section_len); -#endif - p_end = section + section_len - 4; - p = section; - if (parse_section_header(h, &p, p_end) < 0) - return; - if (h->tid != PAT_TID) - return; - - for(;;) { - sid = get16(&p, p_end); - if (sid < 0) - break; - pmt_pid = get16(&p, p_end) & 0x1fff; - if (pmt_pid < 0) - break; -#ifdef DEBUG_SI - av_log(ts->stream, AV_LOG_DEBUG, "sid=0x%x pid=0x%x\n", sid, pmt_pid); -#endif - if (sid == 0x0000) { - /* NIT info */ - } else { - /* add the service with a dummy name */ - snprintf(buf, sizeof(buf), "Service %x\n", sid); - name = av_strdup(buf); - provider_name = av_strdup(""); - if (name && provider_name) { - new_service(ts, sid, provider_name, name); - } else { - av_freep(&name); - av_freep(&provider_name); - } - } - } - ts->stop_parse = 1; - - /* remove filter */ - mpegts_close_filter(ts, ts->pat_filter); - ts->pat_filter = NULL; -} - -static void mpegts_set_service(MpegTSContext *ts, int sid, - SetServiceCallback *set_service_cb, void *opaque) -{ - ts->set_service_cb = set_service_cb; - ts->set_service_opaque = opaque; - ts->req_sid = sid; - ts->pat_filter = mpegts_open_section_filter(ts, PAT_PID, + mpegts_open_section_filter(ts, PAT_PID, pat_cb, ts, 1); } -static void sdt_cb(void *opaque, const uint8_t *section, int section_len) +static void sdt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) { - MpegTSContext *ts = opaque; + MpegTSContext *ts = filter->u.section_filter.opaque; SectionHeader h1, *h = &h1; const uint8_t *p, *p_end, *desc_list_end, *desc_end; int onid, val, sid, desc_list_len, desc_tag, desc_len, service_type; @@ -704,9 +759,11 @@ static void sdt_cb(void *opaque, const uint8_t *section, int section_len) if (!provider_name) break; name = getstr8(&p, p_end); - if (!name) - break; - new_service(ts, sid, provider_name, name); + if (name) { + AVProgram *program = av_new_program(ts->stream, sid); + if(program) + av_set_program_name(program, provider_name, name); + } break; default: break; @@ -715,78 +772,35 @@ static void sdt_cb(void *opaque, const uint8_t *section, int section_len) } p = desc_list_end; } - ts->stop_parse = 1; - - /* remove filter */ - mpegts_close_filter(ts, ts->sdt_filter); - ts->sdt_filter = NULL; } /* scan services in a transport stream by looking at the SDT */ static void mpegts_scan_sdt(MpegTSContext *ts) { - ts->sdt_filter = mpegts_open_section_filter(ts, SDT_PID, + mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1); } -/* scan services in a transport stream by looking at the PAT (better - than nothing !) */ -static void mpegts_scan_pat(MpegTSContext *ts) -{ - ts->pat_filter = mpegts_open_section_filter(ts, PAT_PID, - pat_scan_cb, ts, 1); -} - -/* TS stream handling */ - -enum MpegTSState { - MPEGTS_HEADER = 0, - MPEGTS_PESHEADER_FILL, - MPEGTS_PAYLOAD, - MPEGTS_SKIP, -}; - -/* enough for PES header + length */ -#define PES_START_SIZE 9 -#define MAX_PES_HEADER_SIZE (9 + 255) - -struct PESContext { - int pid; - int stream_type; - MpegTSContext *ts; - AVFormatContext *stream; - AVStream *st; - enum MpegTSState state; - /* used to get the format */ - int data_index; - int total_size; - int pes_header_size; - int64_t pts, dts; - uint8_t header[MAX_PES_HEADER_SIZE]; -}; - static int64_t get_pts(const uint8_t *p) { - int64_t pts; - int val; - - pts = (int64_t)((p[0] >> 1) & 0x07) << 30; - val = (p[1] << 8) | p[2]; - pts |= (int64_t)(val >> 1) << 15; - val = (p[3] << 8) | p[4]; - pts |= (int64_t)(val >> 1); + int64_t pts = (int64_t)((p[0] >> 1) & 0x07) << 30; + pts |= (AV_RB16(p + 1) >> 1) << 15; + pts |= AV_RB16(p + 3) >> 1; return pts; } /* return non zero if a packet could be constructed */ -static void mpegts_push_data(void *opaque, +static void mpegts_push_data(MpegTSFilter *filter, const uint8_t *buf, int buf_size, int is_start) { - PESContext *pes = opaque; + PESContext *pes = filter->u.pes_filter.opaque; MpegTSContext *ts = pes->ts; const uint8_t *p; int len, code; + if(!ts->pkt) + return; + if (is_start) { pes->state = MPEGTS_HEADER; pes->data_index = 0; @@ -821,7 +835,7 @@ static void mpegts_push_data(void *opaque, new_pes_av_stream(pes, code); } pes->state = MPEGTS_PESHEADER_FILL; - pes->total_size = (pes->header[4] << 8) | pes->header[5]; + pes->total_size = AV_RB16(pes->header + 4); /* NOTE: a zero total size means the PES size is unbounded */ if (pes->total_size) @@ -935,6 +949,7 @@ static AVStream* new_pes_av_stream(PESContext *pes, uint32_t code) codec_id = CODEC_ID_AC3; break; case STREAM_TYPE_AUDIO_DTS: + case STREAM_TYPE_AUDIO_HDMV_DTS: codec_type = CODEC_TYPE_AUDIO; codec_id = CODEC_ID_DTS; break; @@ -961,14 +976,14 @@ static AVStream* new_pes_av_stream(PESContext *pes, uint32_t code) st->priv_data = pes; st->codec->codec_type = codec_type; st->codec->codec_id = codec_id; - st->need_parsing = 1; + st->need_parsing = AVSTREAM_PARSE_FULL; pes->st = st; } return st; } -static PESContext *add_pes_stream(MpegTSContext *ts, int pid, int stream_type) +static PESContext *add_pes_stream(MpegTSContext *ts, int pid, int pcr_pid, int stream_type) { MpegTSFilter *tss; PESContext *pes; @@ -980,6 +995,7 @@ static PESContext *add_pes_stream(MpegTSContext *ts, int pid, int stream_type) pes->ts = ts; pes->stream = ts->stream; pes->pid = pid; + pes->pcr_pid = pcr_pid; pes->stream_type = stream_type; tss = mpegts_open_pes_filter(ts, pid, mpegts_push_data, pes); if (!tss) { @@ -997,11 +1013,13 @@ static void handle_packet(MpegTSContext *ts, const uint8_t *packet) int len, pid, cc, cc_ok, afc, is_start; const uint8_t *p, *p_end; - pid = ((packet[1] & 0x1f) << 8) | packet[2]; + pid = AV_RB16(packet + 1) & 0x1fff; + if(pid && discard_pid(ts, pid)) + return; is_start = packet[1] & 0x40; tss = ts->pids[pid]; if (ts->auto_guess && tss == NULL && is_start) { - add_pes_stream(ts, pid, 0); + add_pes_stream(ts, pid, -1, 0); tss = ts->pids[pid]; } if (!tss) @@ -1054,7 +1072,7 @@ static void handle_packet(MpegTSContext *ts, const uint8_t *packet) } } } else { - tss->u.pes_filter.pes_cb(tss->u.pes_filter.opaque, + tss->u.pes_filter.pes_cb(tss, p, p_end - p, is_start); } } @@ -1086,7 +1104,7 @@ static int read_packet(ByteIOContext *pb, uint8_t *buf, int raw_packet_size) for(;;) { len = get_buffer(pb, buf, TS_PACKET_SIZE); if (len != TS_PACKET_SIZE) - return AVERROR_IO; + return AVERROR(EIO); /* check paquet sync byte */ if (buf[0] != 0x47) { /* find a new packet start */ @@ -1108,14 +1126,14 @@ static int read_packet(ByteIOContext *pb, uint8_t *buf, int raw_packet_size) static int handle_packets(MpegTSContext *ts, int nb_packets) { AVFormatContext *s = ts->stream; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; uint8_t packet[TS_PACKET_SIZE]; int packet_num, ret; ts->stop_parse = 0; packet_num = 0; for(;;) { - if (ts->stop_parse) + if (ts->stop_parse>0) break; packet_num++; if (nb_packets != 0 && packet_num >= nb_packets) @@ -1157,13 +1175,6 @@ static int mpegts_probe(AVProbeData *p) #endif } -static void set_service_cb(void *opaque, int ret) -{ - MpegTSContext *ts = opaque; - ts->set_service_ret = ret; - ts->stop_parse = 1; -} - /* return the 90 kHz PCR and the extension for the 27 MHz PCR. return (-1) if not available */ static int parse_pcr(int64_t *ppcr_high, int *ppcr_low, @@ -1187,7 +1198,7 @@ static int parse_pcr(int64_t *ppcr_high, int *ppcr_low, return -1; if (len < 6) return -1; - v = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; + v = AV_RB32(p); *ppcr_high = ((int64_t)v << 1) | (p[4] >> 7); *ppcr_low = ((p[4] & 1) << 8) | p[5]; return 0; @@ -1197,15 +1208,17 @@ static int mpegts_read_header(AVFormatContext *s, AVFormatParameters *ap) { MpegTSContext *ts = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; uint8_t buf[1024]; - int len, sid, i; + int len; int64_t pos; - MpegTSService *service; if (ap) { - ts->mpeg2ts_raw = ap->mpeg2ts_raw; ts->mpeg2ts_compute_pcr = ap->mpeg2ts_compute_pcr; + if(ap->mpeg2ts_raw){ + av_log(s, AV_LOG_ERROR, "use mpegtsraw_demuxer!\n"); + return -1; + } } /* read the first 1024 bytes to get packet size */ @@ -1219,73 +1232,23 @@ static int mpegts_read_header(AVFormatContext *s, ts->stream = s; ts->auto_guess = 0; -goto_auto_guess: - if (!ts->mpeg2ts_raw) { + if (s->iformat == &mpegts_demuxer) { /* normal demux */ - if (!ts->auto_guess) { - ts->set_service_ret = -1; - - /* first do a scaning to get all the services */ - url_fseek(pb, pos, SEEK_SET); - mpegts_scan_sdt(ts); + /* first do a scaning to get all the services */ + url_fseek(pb, pos, SEEK_SET); + mpegts_scan_sdt(ts); - handle_packets(ts, s->probesize); + mpegts_set_service(ts); - if (ts->nb_services <= 0) { - /* no SDT found, we try to look at the PAT */ + handle_packets(ts, s->probesize); + /* if could not find service, enable auto_guess */ - /* First remove the SDT filters from each PID */ - int i; - for (i=0; i < NB_PID_MAX; i++) { - if (ts->pids[i]) - mpegts_close_filter(ts, ts->pids[i]); - } - url_fseek(pb, pos, SEEK_SET); - mpegts_scan_pat(ts); - - handle_packets(ts, s->probesize); - } + ts->auto_guess = 1; - if (ts->nb_services <= 0) { - /* raw transport stream */ - ts->auto_guess = 1; - s->ctx_flags |= AVFMTCTX_NOHEADER; - goto do_pcr; - } - - /* tune to first service found */ - for(i=0; inb_services && ts->set_service_ret; i++){ - service = ts->services[i]; - sid = service->sid; #ifdef DEBUG_SI - av_log(ts->stream, AV_LOG_DEBUG, "tuning to '%s'\n", service->name); + av_log(ts->stream, AV_LOG_DEBUG, "tuning done\n"); #endif - - /* now find the info for the first service if we found any, - otherwise try to filter all PATs */ - - url_fseek(pb, pos, SEEK_SET); - mpegts_set_service(ts, sid, set_service_cb, ts); - - handle_packets(ts, s->probesize); - } - /* if could not find service, exit */ - - if (ts->set_service_ret != 0) { - if(ts->auto_guess) - return -1; - else { - //let's retry with auto_guess set - ts->auto_guess = 1; - goto goto_auto_guess; - } - } - -#ifdef DEBUG_SI - av_log(ts->stream, AV_LOG_DEBUG, "tuning done\n"); -#endif - } s->ctx_flags |= AVFMTCTX_NOHEADER; } else { AVStream *st; @@ -1296,7 +1259,6 @@ goto_auto_guess: /* only read packets */ - do_pcr: st = av_new_stream(s, 0); if (!st) goto fail; @@ -1309,10 +1271,10 @@ goto_auto_guess: nb_pcrs = 0; nb_packets = 0; for(;;) { - ret = read_packet(&s->pb, packet, ts->raw_packet_size); + ret = read_packet(s->pb, packet, ts->raw_packet_size); if (ret < 0) return -1; - pid = ((packet[1] & 0x1f) << 8) | packet[2]; + pid = AV_RB16(packet + 1) & 0x1fff; if ((pcr_pid == -1 || pcr_pid == pid) && parse_pcr(&pcr_h, &pcr_l, packet) == 0) { pcr_pid = pid; @@ -1324,7 +1286,6 @@ goto_auto_guess: } nb_packets++; } - ts->pcr_pid = pcr_pid; /* NOTE1: the bitrate is computed without the FEC */ /* NOTE2: it is only the bitrate of the start of the stream */ @@ -1358,8 +1319,8 @@ static int mpegts_raw_read_packet(AVFormatContext *s, if (av_new_packet(pkt, TS_PACKET_SIZE) < 0) return AVERROR(ENOMEM); - pkt->pos= url_ftell(&s->pb); - ret = read_packet(&s->pb, pkt->data, ts->raw_packet_size); + pkt->pos= url_ftell(s->pb); + ret = read_packet(s->pb, pkt->data, ts->raw_packet_size); if (ret < 0) { av_free_packet(pkt); return ret; @@ -1368,10 +1329,10 @@ static int mpegts_raw_read_packet(AVFormatContext *s, /* compute exact PCR for each packet */ if (parse_pcr(&pcr_h, &pcr_l, pkt->data) == 0) { /* we read the next PCR (XXX: optimize it by using a bigger buffer */ - pos = url_ftell(&s->pb); + pos = url_ftell(s->pb); for(i = 0; i < MAX_PACKET_READAHEAD; i++) { - url_fseek(&s->pb, pos + i * ts->raw_packet_size, SEEK_SET); - get_buffer(&s->pb, pcr_buf, 12); + url_fseek(s->pb, pos + i * ts->raw_packet_size, SEEK_SET); + get_buffer(s->pb, pcr_buf, 12); if (parse_pcr(&next_pcr_h, &next_pcr_l, pcr_buf) == 0) { /* XXX: not precise enough */ ts->pcr_incr = ((next_pcr_h - pcr_h) * 300 + (next_pcr_l - pcr_l)) / @@ -1379,7 +1340,7 @@ static int mpegts_raw_read_packet(AVFormatContext *s, break; } } - url_fseek(&s->pb, pos, SEEK_SET); + url_fseek(s->pb, pos, SEEK_SET); /* no next PCR found: we use previous increment */ ts->cur_pcr = pcr_h * 300 + pcr_l; } @@ -1396,12 +1357,8 @@ static int mpegts_read_packet(AVFormatContext *s, { MpegTSContext *ts = s->priv_data; - if (!ts->mpeg2ts_raw) { - ts->pkt = pkt; - return handle_packets(ts, 0); - } else { - return mpegts_raw_read_packet(s, pkt); - } + ts->pkt = pkt; + return handle_packets(ts, 0); } static int mpegts_read_close(AVFormatContext *s) @@ -1411,13 +1368,6 @@ static int mpegts_read_close(AVFormatContext *s) for(i=0;ipids[i]) mpegts_close_filter(ts, ts->pids[i]); - for(i = 0; i < ts->nb_services; i++){ - av_free(ts->services[i]->provider_name); - av_free(ts->services[i]->name); - av_free(ts->services[i]); - } - av_freep(&ts->services); - return 0; } @@ -1427,16 +1377,15 @@ static int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index, MpegTSContext *ts = s->priv_data; int64_t pos, timestamp; uint8_t buf[TS_PACKET_SIZE]; - int pcr_l, pid; + int pcr_l, pcr_pid = ((PESContext*)s->streams[stream_index]->priv_data)->pcr_pid; const int find_next= 1; pos = ((*ppos + ts->raw_packet_size - 1) / ts->raw_packet_size) * ts->raw_packet_size; if (find_next) { for(;;) { - url_fseek(&s->pb, pos, SEEK_SET); - if (get_buffer(&s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) + url_fseek(s->pb, pos, SEEK_SET); + if (get_buffer(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) return AV_NOPTS_VALUE; - pid = ((buf[1] & 0x1f) << 8) | buf[2]; - if (pid == ts->pcr_pid && + if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) && parse_pcr(×tamp, &pcr_l, buf) == 0) { break; } @@ -1447,11 +1396,10 @@ static int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index, pos -= ts->raw_packet_size; if (pos < 0) return AV_NOPTS_VALUE; - url_fseek(&s->pb, pos, SEEK_SET); - if (get_buffer(&s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) + url_fseek(s->pb, pos, SEEK_SET); + if (get_buffer(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) return AV_NOPTS_VALUE; - pid = ((buf[1] & 0x1f) << 8) | buf[2]; - if (pid == ts->pcr_pid && + if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) && parse_pcr(×tamp, &pcr_l, buf) == 0) { break; } @@ -1470,17 +1418,17 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, in if(av_seek_frame_binary(s, stream_index, target_ts, flags) < 0) return -1; - pos= url_ftell(&s->pb); + pos= url_ftell(s->pb); for(;;) { - url_fseek(&s->pb, pos, SEEK_SET); - if (get_buffer(&s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) + url_fseek(s->pb, pos, SEEK_SET); + if (get_buffer(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) return -1; -// pid = ((buf[1] & 0x1f) << 8) | buf[2]; +// pid = AV_RB16(buf + 1) & 0x1fff; if(buf[1] & 0x40) break; pos += ts->raw_packet_size; } - url_fseek(&s->pb, pos, SEEK_SET); + url_fseek(s->pb, pos, SEEK_SET); return 0; } @@ -1513,7 +1461,7 @@ int mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt, ts->pkt = pkt; ts->stop_parse = 0; for(;;) { - if (ts->stop_parse) + if (ts->stop_parse>0) break; if (len < TS_PACKET_SIZE) return -1; @@ -1550,3 +1498,16 @@ AVInputFormat mpegts_demuxer = { mpegts_get_pcr, .flags = AVFMT_SHOW_IDS, }; + +AVInputFormat mpegtsraw_demuxer = { + "mpegtsraw", + "MPEG2 raw transport stream format", + sizeof(MpegTSContext), + mpegts_probe, + mpegts_read_header, + mpegts_raw_read_packet, + mpegts_read_close, + read_seek, + mpegts_get_pcr, + .flags = AVFMT_SHOW_IDS, +}; diff --git a/contrib/ffmpeg/libavformat/mpegts.h b/contrib/ffmpeg/libavformat/mpegts.h index 771becbd4..bdfc760b3 100644 --- a/contrib/ffmpeg/libavformat/mpegts.h +++ b/contrib/ffmpeg/libavformat/mpegts.h @@ -19,6 +19,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef FFMPEG_MPEGTS_H +#define FFMPEG_MPEGTS_H + +#include "avformat.h" + #define TS_FEC_PACKET_SIZE 204 #define TS_DVHS_PACKET_SIZE 192 #define TS_PACKET_SIZE 188 @@ -50,14 +55,15 @@ #define STREAM_TYPE_AUDIO_AC3 0x81 #define STREAM_TYPE_AUDIO_DTS 0x8a +#define STREAM_TYPE_AUDIO_HDMV_DTS 0x82 #define STREAM_TYPE_SUBTITLE_DVB 0x100 -extern AVOutputFormat mpegts_muxer; - typedef struct MpegTSContext MpegTSContext; MpegTSContext *mpegts_parse_open(AVFormatContext *s); int mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt, const uint8_t *buf, int len); void mpegts_parse_close(MpegTSContext *ts); + +#endif /* FFMPEG_MPEGTS_H */ diff --git a/contrib/ffmpeg/libavformat/mpegtsenc.c b/contrib/ffmpeg/libavformat/mpegtsenc.c index c521b68b8..49d29aa2b 100644 --- a/contrib/ffmpeg/libavformat/mpegtsenc.c +++ b/contrib/ffmpeg/libavformat/mpegtsenc.c @@ -43,7 +43,7 @@ static void mpegts_write_section(MpegTSSection *s, uint8_t *buf, int len) unsigned char *q; int first, b, len1, left; - crc = bswap_32(av_crc(av_crc04C11DB7, -1, buf, len - 4)); + crc = bswap_32(av_crc(av_crc_get_table(AV_CRC_32_IEEE), -1, buf, len - 4)); buf[len - 4] = (crc >> 24) & 0xff; buf[len - 3] = (crc >> 16) & 0xff; buf[len - 2] = (crc >> 8) & 0xff; @@ -353,7 +353,7 @@ static MpegTSService *mpegts_add_service(MpegTSWrite *ts, static void section_write_packet(MpegTSSection *s, const uint8_t *packet) { AVFormatContext *ctx = s->opaque; - put_buffer(&ctx->pb, packet, TS_PACKET_SIZE); + put_buffer(ctx->pb, packet, TS_PACKET_SIZE); } static int mpegts_write_header(AVFormatContext *s) @@ -431,7 +431,7 @@ static int mpegts_write_header(AVFormatContext *s) for(i = 0; i < ts->nb_services; i++) { mpegts_write_pmt(s, ts->services[i]); } - put_flush_packet(&s->pb); + put_flush_packet(s->pb); return 0; @@ -608,9 +608,9 @@ static void mpegts_write_pes(AVFormatContext *s, AVStream *st, memcpy(buf + TS_PACKET_SIZE - len, payload, len); payload += len; payload_size -= len; - put_buffer(&s->pb, buf, TS_PACKET_SIZE); + put_buffer(s->pb, buf, TS_PACKET_SIZE); } - put_flush_packet(&s->pb); + put_flush_packet(s->pb); } static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt) @@ -668,7 +668,7 @@ static int mpegts_write_end(AVFormatContext *s) ts_st->payload_pts, ts_st->payload_dts); } } - put_flush_packet(&s->pb); + put_flush_packet(s->pb); for(i = 0; i < ts->nb_services; i++) { service = ts->services[i]; diff --git a/contrib/ffmpeg/libavformat/mpjpeg.c b/contrib/ffmpeg/libavformat/mpjpeg.c index 937917313..2e745721b 100644 --- a/contrib/ffmpeg/libavformat/mpjpeg.c +++ b/contrib/ffmpeg/libavformat/mpjpeg.c @@ -29,8 +29,8 @@ static int mpjpeg_write_header(AVFormatContext *s) uint8_t buf1[256]; snprintf(buf1, sizeof(buf1), "--%s\n", BOUNDARY_TAG); - put_buffer(&s->pb, buf1, strlen(buf1)); - put_flush_packet(&s->pb); + put_buffer(s->pb, buf1, strlen(buf1)); + put_flush_packet(s->pb); return 0; } @@ -39,12 +39,12 @@ static int mpjpeg_write_packet(AVFormatContext *s, AVPacket *pkt) uint8_t buf1[256]; snprintf(buf1, sizeof(buf1), "Content-type: image/jpeg\n\n"); - put_buffer(&s->pb, buf1, strlen(buf1)); - put_buffer(&s->pb, pkt->data, pkt->size); + put_buffer(s->pb, buf1, strlen(buf1)); + put_buffer(s->pb, pkt->data, pkt->size); snprintf(buf1, sizeof(buf1), "\n--%s\n", BOUNDARY_TAG); - put_buffer(&s->pb, buf1, strlen(buf1)); - put_flush_packet(&s->pb); + put_buffer(s->pb, buf1, strlen(buf1)); + put_flush_packet(s->pb); return 0; } diff --git a/contrib/ffmpeg/libavformat/mtv.c b/contrib/ffmpeg/libavformat/mtv.c index 7a68ea97f..32057e623 100644 --- a/contrib/ffmpeg/libavformat/mtv.c +++ b/contrib/ffmpeg/libavformat/mtv.c @@ -54,9 +54,6 @@ typedef struct MTVDemuxContext { static int mtv_probe(AVProbeData *p) { - if(p->buf_size < 3) - return 0; - /* Magic is 'AMV' */ if(*(p->buf) != 'A' || *(p->buf+1) != 'M' || *(p->buf+2) != 'V') @@ -68,7 +65,7 @@ static int mtv_probe(AVProbeData *p) static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap) { MTVDemuxContext *mtv = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVStream *st; @@ -89,7 +86,7 @@ static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap) /* FIXME Add sanity check here */ - /* first packet is allways audio*/ + /* first packet is always audio*/ mtv->audio_packet_count = 1; @@ -99,7 +96,7 @@ static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap) st = av_new_stream(s, VIDEO_SID); if(!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 64, 1, mtv->video_fps); st->codec->codec_type = CODEC_TYPE_VIDEO; @@ -114,18 +111,18 @@ static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap) st = av_new_stream(s, AUDIO_SID); if(!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 64, 1, AUDIO_SAMPLING_RATE); st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_MP3; st->codec->bit_rate = mtv->audio_br; - st->need_parsing=1; + st->need_parsing = AVSTREAM_PARSE_FULL; /* Jump over header */ if(url_fseek(pb, MTV_HEADER_SIZE, SEEK_SET) != MTV_HEADER_SIZE) - return AVERROR_IO; + return AVERROR(EIO); return(0); @@ -134,7 +131,7 @@ static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap) static int mtv_read_packet(AVFormatContext *s, AVPacket *pkt) { MTVDemuxContext *mtv = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int ret; #ifndef WORDS_BIGENDIAN int i; @@ -148,7 +145,7 @@ static int mtv_read_packet(AVFormatContext *s, AVPacket *pkt) ret = av_get_packet(pb, pkt, MTV_ASUBCHUNK_DATA_SIZE); if(ret != MTV_ASUBCHUNK_DATA_SIZE) - return AVERROR_IO; + return AVERROR(EIO); mtv->audio_packet_count++; pkt->stream_index = AUDIO_SID; @@ -157,7 +154,7 @@ static int mtv_read_packet(AVFormatContext *s, AVPacket *pkt) { ret = av_get_packet(pb, pkt, mtv->img_segment_size); if(ret != mtv->img_segment_size) - return AVERROR_IO; + return AVERROR(EIO); #ifndef WORDS_BIGENDIAN diff --git a/contrib/ffmpeg/libavformat/mxf.c b/contrib/ffmpeg/libavformat/mxf.c index 677e023f0..0c69cd2e1 100644 --- a/contrib/ffmpeg/libavformat/mxf.c +++ b/contrib/ffmpeg/libavformat/mxf.c @@ -47,6 +47,7 @@ #include "avformat.h" #include "aes.h" +#include "bytestream.h" typedef uint8_t UID[16]; @@ -60,18 +61,16 @@ enum MXFMetadataSetType { MultipleDescriptor, Descriptor, Track, - EssenceContainerData, CryptoContext, }; -typedef struct MXFCryptoContext { +typedef struct { UID uid; enum MXFMetadataSetType type; - UID context_uid; UID source_container_ul; } MXFCryptoContext; -typedef struct MXFStructuralComponent { +typedef struct { UID uid; enum MXFMetadataSetType type; UID source_package_uid; @@ -81,7 +80,7 @@ typedef struct MXFStructuralComponent { int source_track_id; } MXFStructuralComponent; -typedef struct MXFSequence { +typedef struct { UID uid; enum MXFMetadataSetType type; UID data_definition_ul; @@ -90,7 +89,7 @@ typedef struct MXFSequence { int64_t duration; } MXFSequence; -typedef struct MXFTrack { +typedef struct { UID uid; enum MXFMetadataSetType type; MXFSequence *sequence; /* mandatory, and only one */ @@ -100,7 +99,7 @@ typedef struct MXFTrack { AVRational edit_rate; } MXFTrack; -typedef struct MXFDescriptor { +typedef struct { UID uid; enum MXFMetadataSetType type; UID essence_container_ul; @@ -118,7 +117,7 @@ typedef struct MXFDescriptor { int extradata_size; } MXFDescriptor; -typedef struct MXFPackage { +typedef struct { UID uid; enum MXFMetadataSetType type; UID package_uid; @@ -128,28 +127,23 @@ typedef struct MXFPackage { UID descriptor_ref; } MXFPackage; -typedef struct MXFEssenceContainerData { - UID uid; - enum MXFMetadataSetType type; - UID linked_package_uid; -} MXFEssenceContainerData; - typedef struct { UID uid; enum MXFMetadataSetType type; } MXFMetadataSet; -typedef struct MXFContext { +typedef struct { UID *packages_refs; int packages_count; MXFMetadataSet **metadata_sets; int metadata_sets_count; - const uint8_t *sync_key; AVFormatContext *fc; struct AVAES *aesc; + uint8_t *local_tags; + int local_tags_count; } MXFContext; -typedef struct KLVPacket { +typedef struct { UID key; offset_t offset; uint64_t length; @@ -160,18 +154,18 @@ enum MXFWrappingScheme { Clip, }; -typedef struct MXFCodecUL { +typedef struct { UID uid; + unsigned matching_len; enum CodecID id; - enum MXFWrappingScheme wrapping; } MXFCodecUL; -typedef struct MXFDataDefinitionUL { +typedef struct { UID uid; enum CodecType type; } MXFDataDefinitionUL; -typedef struct MXFMetadataReadTableEntry { +typedef struct { const UID key; int (*read)(); int ctx_size; @@ -181,9 +175,12 @@ typedef struct MXFMetadataReadTableEntry { /* partial keys to match */ static const uint8_t mxf_header_partition_pack_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02 }; static const uint8_t mxf_essence_element_key[] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01 }; +static const uint8_t mxf_klv_key[] = { 0x06,0x0e,0x2b,0x34 }; /* complete keys to match */ +static const uint8_t mxf_crypto_source_container_ul[] = { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x09,0x06,0x01,0x01,0x02,0x02,0x00,0x00,0x00 }; static const uint8_t mxf_encrypted_triplet_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x04,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x7e,0x01,0x00 }; static const uint8_t mxf_encrypted_essence_container[] = { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x07,0x0d,0x01,0x03,0x01,0x02,0x0b,0x01,0x00 }; +static const uint8_t mxf_sony_mpeg4_extradata[] = { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x01,0x0e,0x06,0x06,0x02,0x02,0x01,0x00,0x00 }; #define IS_KLV_KEY(x, y) (!memcmp(x, y, sizeof(y))) @@ -205,10 +202,26 @@ static int64_t klv_decode_ber_length(ByteIOContext *pb) return size; } +static int mxf_read_sync(ByteIOContext *pb, const uint8_t *key, unsigned size) +{ + int i, b; + for (i = 0; i < size && !url_feof(pb); i++) { + b = get_byte(pb); + if (b == key[0]) + i = 0; + else if (b != key[i]) + i = -1; + } + return i == size; +} + static int klv_read_packet(KLVPacket *klv, ByteIOContext *pb) { - klv->offset = url_ftell(pb); - get_buffer(pb, klv->key, 16); + if (!mxf_read_sync(pb, mxf_klv_key, 4)) + return -1; + klv->offset = url_ftell(pb) - 4; + memcpy(klv->key, mxf_klv_key, 4); + get_buffer(pb, klv->key + 4, 12); klv->length = klv_decode_ber_length(pb); return klv->length == -1 ? -1 : 0; } @@ -231,7 +244,9 @@ static int mxf_get_stream_index(AVFormatContext *s, KLVPacket *klv) static int mxf_get_d10_aes3_packet(ByteIOContext *pb, AVStream *st, AVPacket *pkt, int64_t length) { uint8_t buffer[61444]; - uint8_t *buf_ptr, *end_ptr, *data_ptr; + const uint8_t *buf_ptr, *end_ptr; + uint8_t *data_ptr; + int i; if (length > 61444) /* worst case PAL 1920 samples 8 channels */ return -1; @@ -240,17 +255,15 @@ static int mxf_get_d10_aes3_packet(ByteIOContext *pb, AVStream *st, AVPacket *pk data_ptr = pkt->data; end_ptr = buffer + length; buf_ptr = buffer + 4; /* skip SMPTE 331M header */ - for (; buf_ptr < end_ptr; buf_ptr += 4) { - if (st->codec->bits_per_sample == 24) { - data_ptr[0] = (buf_ptr[2] >> 4) | ((buf_ptr[3] & 0x0f) << 4); - data_ptr[1] = (buf_ptr[1] >> 4) | ((buf_ptr[2] & 0x0f) << 4); - data_ptr[2] = (buf_ptr[0] >> 4) | ((buf_ptr[1] & 0x0f) << 4); - data_ptr += 3; - } else { - data_ptr[0] = (buf_ptr[2] >> 4) | ((buf_ptr[3] & 0x0f) << 4); - data_ptr[1] = (buf_ptr[1] >> 4) | ((buf_ptr[2] & 0x0f) << 4); - data_ptr += 2; + for (; buf_ptr < end_ptr; ) { + for (i = 0; i < st->codec->channels; i++) { + uint32_t sample = bytestream_get_le32(&buf_ptr); + if (st->codec->bits_per_sample == 24) + bytestream_put_le24(&data_ptr, (sample >> 4) & 0xffffff); + else + bytestream_put_le16(&data_ptr, (sample >> 12) & 0xffff); } + buf_ptr += 32 - st->codec->channels*4; // always 8 channels stored SMPTE 331M } pkt->size = data_ptr - pkt->data; return 0; @@ -260,7 +273,7 @@ static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv { static const uint8_t checkv[16] = {0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b}; MXFContext *mxf = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; offset_t end = url_ftell(pb) + klv->length; uint64_t size; uint64_t orig_size; @@ -271,6 +284,8 @@ static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv if (!mxf->aesc && s->key && s->keylen == 16) { mxf->aesc = av_malloc(av_aes_size); + if (!mxf->aesc) + return -1; av_aes_init(mxf->aesc, s->key, 128, 1); } // crypto context @@ -281,16 +296,20 @@ static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv // source klv key klv_decode_ber_length(pb); get_buffer(pb, klv->key, 16); - if (!IS_KLV_KEY(klv, mxf_essence_element_key)) goto err_out; + if (!IS_KLV_KEY(klv, mxf_essence_element_key)) + return -1; index = mxf_get_stream_index(s, klv); - if (index < 0) goto err_out; + if (index < 0) + return -1; // source size klv_decode_ber_length(pb); orig_size = get_be64(pb); - if (orig_size < plaintext_size) goto err_out; + if (orig_size < plaintext_size) + return -1; // enc. code size = klv_decode_ber_length(pb); - if (size < 32 || size - 32 < orig_size) goto err_out; + if (size < 32 || size - 32 < orig_size) + return -1; get_buffer(pb, ivec, 16); get_buffer(pb, tmpbuf, 16); if (mxf->aesc) @@ -307,28 +326,20 @@ static int mxf_decrypt_triplet(AVFormatContext *s, AVPacket *pkt, KLVPacket *klv pkt->stream_index = index; url_fskip(pb, end - url_ftell(pb)); return 0; - -err_out: - url_fskip(pb, end - url_ftell(pb)); - return -1; } static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt) { - MXFContext *mxf = s->priv_data; KLVPacket klv; - while (!url_feof(&s->pb)) { - if (klv_read_packet(&klv, &s->pb) < 0) { - av_log(s, AV_LOG_ERROR, "error reading KLV packet\n"); + while (!url_feof(s->pb)) { + if (klv_read_packet(&klv, s->pb) < 0) return -1; - } #ifdef DEBUG PRINT_KEY(s, "read packet", klv.key); #endif if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key)) { int res = mxf_decrypt_triplet(s, pkt, &klv); - mxf->sync_key = mxf_encrypted_triplet_key; if (res < 0) { av_log(s, AV_LOG_ERROR, "invalid encoded triplet\n"); return -1; @@ -339,47 +350,66 @@ static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt) int index = mxf_get_stream_index(s, &klv); if (index < 0) { av_log(s, AV_LOG_ERROR, "error getting stream index\n"); - url_fskip(&s->pb, klv.length); + url_fskip(s->pb, klv.length); return -1; } /* check for 8 channels AES3 element */ if (klv.key[12] == 0x06 && klv.key[13] == 0x01 && klv.key[14] == 0x10) { - if (mxf_get_d10_aes3_packet(&s->pb, s->streams[index], pkt, klv.length) < 0) { + if (mxf_get_d10_aes3_packet(s->pb, s->streams[index], pkt, klv.length) < 0) { av_log(s, AV_LOG_ERROR, "error reading D-10 aes3 frame\n"); return -1; } } else - av_get_packet(&s->pb, pkt, klv.length); + av_get_packet(s->pb, pkt, klv.length); pkt->stream_index = index; + pkt->pos = klv.offset; return 0; } else - url_fskip(&s->pb, klv.length); + url_fskip(s->pb, klv.length); + } + return AVERROR(EIO); +} + +static int mxf_read_primer_pack(MXFContext *mxf) +{ + ByteIOContext *pb = mxf->fc->pb; + int item_num = get_be32(pb); + int item_len = get_be32(pb); + + if (item_len != 18) { + av_log(mxf->fc, AV_LOG_ERROR, "unsupported primer pack item length\n"); + return -1; } - return AVERROR_IO; + if (item_num > UINT_MAX / item_len) + return -1; + mxf->local_tags_count = item_num; + mxf->local_tags = av_malloc(item_num*item_len); + if (!mxf->local_tags) + return -1; + get_buffer(pb, mxf->local_tags, item_num*item_len); + return 0; } static int mxf_add_metadata_set(MXFContext *mxf, void *metadata_set) { mxf->metadata_sets = av_realloc(mxf->metadata_sets, (mxf->metadata_sets_count + 1) * sizeof(*mxf->metadata_sets)); + if (!mxf->metadata_sets) + return -1; mxf->metadata_sets[mxf->metadata_sets_count] = metadata_set; mxf->metadata_sets_count++; return 0; } -static int mxf_read_metadata_cryptographic_context(MXFCryptoContext *cryptocontext, ByteIOContext *pb, int tag) +static int mxf_read_cryptographic_context(MXFCryptoContext *cryptocontext, ByteIOContext *pb, int tag, int size, UID uid) { - switch(tag) { - case 0xFFFE: - get_buffer(pb, cryptocontext->context_uid, 16); - break; - case 0xFFFD: + if (size != 16) + return -1; + if (IS_KLV_KEY(uid, mxf_crypto_source_container_ul)) get_buffer(pb, cryptocontext->source_container_ul, 16); - break; - } return 0; } -static int mxf_read_metadata_content_storage(MXFContext *mxf, ByteIOContext *pb, int tag) +static int mxf_read_content_storage(MXFContext *mxf, ByteIOContext *pb, int tag) { switch (tag) { case 0x1901: @@ -387,6 +417,8 @@ static int mxf_read_metadata_content_storage(MXFContext *mxf, ByteIOContext *pb, if (mxf->packages_count >= UINT_MAX / sizeof(UID)) return -1; mxf->packages_refs = av_malloc(mxf->packages_count * sizeof(UID)); + if (!mxf->packages_refs) + return -1; url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */ get_buffer(pb, (uint8_t *)mxf->packages_refs, mxf->packages_count * sizeof(UID)); break; @@ -394,7 +426,7 @@ static int mxf_read_metadata_content_storage(MXFContext *mxf, ByteIOContext *pb, return 0; } -static int mxf_read_metadata_source_clip(MXFStructuralComponent *source_clip, ByteIOContext *pb, int tag) +static int mxf_read_source_clip(MXFStructuralComponent *source_clip, ByteIOContext *pb, int tag) { switch(tag) { case 0x0202: @@ -415,7 +447,7 @@ static int mxf_read_metadata_source_clip(MXFStructuralComponent *source_clip, By return 0; } -static int mxf_read_metadata_material_package(MXFPackage *package, ByteIOContext *pb, int tag) +static int mxf_read_material_package(MXFPackage *package, ByteIOContext *pb, int tag) { switch(tag) { case 0x4403: @@ -423,6 +455,8 @@ static int mxf_read_metadata_material_package(MXFPackage *package, ByteIOContext if (package->tracks_count >= UINT_MAX / sizeof(UID)) return -1; package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID)); + if (!package->tracks_refs) + return -1; url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */ get_buffer(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID)); break; @@ -430,7 +464,7 @@ static int mxf_read_metadata_material_package(MXFPackage *package, ByteIOContext return 0; } -static int mxf_read_metadata_track(MXFTrack *track, ByteIOContext *pb, int tag) +static int mxf_read_track(MXFTrack *track, ByteIOContext *pb, int tag) { switch(tag) { case 0x4801: @@ -450,7 +484,7 @@ static int mxf_read_metadata_track(MXFTrack *track, ByteIOContext *pb, int tag) return 0; } -static int mxf_read_metadata_sequence(MXFSequence *sequence, ByteIOContext *pb, int tag) +static int mxf_read_sequence(MXFSequence *sequence, ByteIOContext *pb, int tag) { switch(tag) { case 0x0202: @@ -464,6 +498,8 @@ static int mxf_read_metadata_sequence(MXFSequence *sequence, ByteIOContext *pb, if (sequence->structural_components_count >= UINT_MAX / sizeof(UID)) return -1; sequence->structural_components_refs = av_malloc(sequence->structural_components_count * sizeof(UID)); + if (!sequence->structural_components_refs) + return -1; url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */ get_buffer(pb, (uint8_t *)sequence->structural_components_refs, sequence->structural_components_count * sizeof(UID)); break; @@ -471,7 +507,7 @@ static int mxf_read_metadata_sequence(MXFSequence *sequence, ByteIOContext *pb, return 0; } -static int mxf_read_metadata_source_package(MXFPackage *package, ByteIOContext *pb, int tag) +static int mxf_read_source_package(MXFPackage *package, ByteIOContext *pb, int tag) { switch(tag) { case 0x4403: @@ -479,6 +515,8 @@ static int mxf_read_metadata_source_package(MXFPackage *package, ByteIOContext * if (package->tracks_count >= UINT_MAX / sizeof(UID)) return -1; package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID)); + if (!package->tracks_refs) + return -1; url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */ get_buffer(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID)); break; @@ -494,7 +532,7 @@ static int mxf_read_metadata_source_package(MXFPackage *package, ByteIOContext * return 0; } -static void mxf_read_metadata_pixel_layout(ByteIOContext *pb, MXFDescriptor *descriptor) +static void mxf_read_pixel_layout(ByteIOContext *pb, MXFDescriptor *descriptor) { int code; @@ -517,7 +555,7 @@ static void mxf_read_metadata_pixel_layout(ByteIOContext *pb, MXFDescriptor *des } while (code != 0); /* SMPTE 377M E.2.46 */ } -static int mxf_read_metadata_generic_descriptor(MXFDescriptor *descriptor, ByteIOContext *pb, int tag, int size) +static int mxf_read_generic_descriptor(MXFDescriptor *descriptor, ByteIOContext *pb, int tag, int size, UID uid) { switch(tag) { case 0x3F01: @@ -525,6 +563,8 @@ static int mxf_read_metadata_generic_descriptor(MXFDescriptor *descriptor, ByteI if (descriptor->sub_descriptors_count >= UINT_MAX / sizeof(UID)) return -1; descriptor->sub_descriptors_refs = av_malloc(descriptor->sub_descriptors_count * sizeof(UID)); + if (!descriptor->sub_descriptors_refs) + return -1; url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */ get_buffer(pb, (uint8_t *)descriptor->sub_descriptors_refs, descriptor->sub_descriptors_count * sizeof(UID)); break; @@ -561,12 +601,17 @@ static int mxf_read_metadata_generic_descriptor(MXFDescriptor *descriptor, ByteI descriptor->bits_per_sample = get_be32(pb); break; case 0x3401: - mxf_read_metadata_pixel_layout(pb, descriptor); + mxf_read_pixel_layout(pb, descriptor); break; - case 0x8201: /* Private tag used by SONY C0023S01.mxf */ - descriptor->extradata = av_malloc(size); - descriptor->extradata_size = size; - get_buffer(pb, descriptor->extradata, size); + default: + /* Private uid used by SONY C0023S01.mxf */ + if (IS_KLV_KEY(uid, mxf_sony_mpeg4_extradata)) { + descriptor->extradata = av_malloc(size); + if (!descriptor->extradata) + return -1; + descriptor->extradata_size = size; + get_buffer(pb, descriptor->extradata, size); + } break; } return 0; @@ -582,55 +627,56 @@ static const MXFDataDefinitionUL mxf_data_definition_uls[] = { static const MXFCodecUL mxf_codec_uls[] = { /* PictureEssenceCoding */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x02,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* 422P@ML I-Frame */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x02,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* 422P@HL I-Frame */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x03,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* 422P@HL Long GoP */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x11,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* MP@ML Long GoP */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x02,0x03,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* 422P@ML Long GoP */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x03,0x00 }, CODEC_ID_MPEG2VIDEO, Frame }, /* MP@HL Long GoP */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x20,0x02,0x03 }, CODEC_ID_MPEG4, Frame }, /* XDCAM proxy_pal030926.mxf */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x20,0x02,0x04 }, CODEC_ID_MPEG4, Frame }, /* XDCAM Proxy C0023S01.mxf */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x05 }, CODEC_ID_MPEG2VIDEO, Frame }, /* D-10 30Mbps PAL */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x01 }, CODEC_ID_MPEG2VIDEO, Frame }, /* D-10 50Mbps PAL */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x04,0x00 }, CODEC_ID_DVVIDEO, Frame }, /* DVCPRO50 PAL */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x02,0x02,0x00 }, CODEC_ID_DVVIDEO, Frame }, /* DVCPRO25 PAL */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x01,0x02,0x00 }, CODEC_ID_DVVIDEO, Frame }, /* DV25 IEC PAL */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x07,0x04,0x01,0x02,0x02,0x03,0x01,0x01,0x00 }, CODEC_ID_JPEG2000, Frame }, /* JPEG2000 Codestream */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x01,0x7F,0x00,0x00,0x00 }, CODEC_ID_RAWVIDEO, Frame }, /* Uncompressed */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x11,0x00 }, 14, CODEC_ID_MPEG2VIDEO }, /* MP@ML Long GoP */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x01 }, 14, CODEC_ID_MPEG2VIDEO }, /* D-10 50Mbps PAL */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x03,0x00 }, 14, CODEC_ID_MPEG2VIDEO }, /* MP@HL Long GoP */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x02,0x00 }, 14, CODEC_ID_MPEG2VIDEO }, /* 422P@HL I-Frame */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x20,0x02,0x03 }, 14, CODEC_ID_MPEG4 }, /* XDCAM proxy_pal030926.mxf */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x01,0x02,0x00 }, 13, CODEC_ID_DVVIDEO }, /* DV25 IEC PAL */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x07,0x04,0x01,0x02,0x02,0x03,0x01,0x01,0x00 }, 14, CODEC_ID_JPEG2000 }, /* JPEG2000 Codestream */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x01,0x7F,0x00,0x00,0x00 }, 13, CODEC_ID_RAWVIDEO }, /* Uncompressed */ /* SoundEssenceCompression */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, CODEC_ID_PCM_S16LE, Frame }, /* Uncompressed */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x7F,0x00,0x00,0x00 }, CODEC_ID_PCM_S16LE, Frame }, - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x07,0x04,0x02,0x02,0x01,0x7E,0x00,0x00,0x00 }, CODEC_ID_PCM_S16BE, Frame }, /* From Omneon MXF file */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x01,0x01,0x00 }, CODEC_ID_PCM_ALAW, Frame }, - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x04,0x04,0x02,0x02,0x02,0x03,0x01,0x01,0x00 }, CODEC_ID_PCM_ALAW, Frame }, /* XDCAM Proxy C0023S01.mxf */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x01,0x00 }, CODEC_ID_AC3, Frame }, - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x05,0x00 }, CODEC_ID_MP2, Frame }, /* MP2 or MP3 */ - //{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x1C,0x00 }, CODEC_ID_DOLBY_E, Frame }, /* Dolby-E */ - { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, CODEC_ID_NONE, Frame }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, 13, CODEC_ID_PCM_S16LE }, /* Uncompressed */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x7F,0x00,0x00,0x00 }, 13, CODEC_ID_PCM_S16LE }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x07,0x04,0x02,0x02,0x01,0x7E,0x00,0x00,0x00 }, 13, CODEC_ID_PCM_S16BE }, /* From Omneon MXF file */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x04,0x04,0x02,0x02,0x02,0x03,0x01,0x01,0x00 }, 15, CODEC_ID_PCM_ALAW }, /* XDCAM Proxy C0023S01.mxf */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x01,0x00 }, 15, CODEC_ID_AC3 }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x05,0x00 }, 15, CODEC_ID_MP2 }, /* MP2 or MP3 */ + //{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x1C,0x00 }, 15, CODEC_ID_DOLBY_E }, /* Dolby-E */ + { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, CODEC_ID_NONE }, }; static const MXFCodecUL mxf_picture_essence_container_uls[] = { - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 }, CODEC_ID_MPEG2VIDEO, Frame }, /* MPEG-ES Frame wrapped */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0xe0,0x02 }, CODEC_ID_MPEG2VIDEO, Clip }, /* MPEG-ES Clip wrapped, 0xe0 MPV stream id */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x04,0x61,0x07 }, CODEC_ID_MPEG2VIDEO, Clip }, /* MPEG-ES Custom wrapped, 0x61 ??? stream id */ - { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, CODEC_ID_NONE, Frame }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 }, 14, CODEC_ID_MPEG2VIDEO }, /* MPEG-ES Frame wrapped */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x41,0x01 }, 14, CODEC_ID_DVVIDEO }, /* DV 625 25mbps */ + { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, CODEC_ID_NONE }, }; static const MXFCodecUL mxf_sound_essence_container_uls[] = { - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 }, CODEC_ID_PCM_S16LE, Frame }, /* BWF Frame wrapped */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x03,0x00 }, CODEC_ID_PCM_S16LE, Frame }, /* AES Frame wrapped */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x40,0x01 }, CODEC_ID_MP2, Frame }, /* MPEG-ES Frame wrapped, 0x40 ??? stream id */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0xc0,0x01 }, CODEC_ID_MP2, Frame }, /* MPEG-ES Frame wrapped, 0xc0 MPA stream id */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0xc0,0x02 }, CODEC_ID_MP2, Clip }, /* MPEG-ES Clip wrapped, 0xc0 MPA stream id */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x05,0x01 }, CODEC_ID_PCM_S16BE, Frame }, /* D-10 Mapping 30Mbps PAL Extended Template */ - { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, CODEC_ID_PCM_S16BE, Frame }, /* D-10 Mapping 50Mbps PAL Extended Template */ - { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, CODEC_ID_NONE, Frame }, + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 }, 14, CODEC_ID_PCM_S16LE }, /* BWF Frame wrapped */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x40,0x01 }, 14, CODEC_ID_MP2 }, /* MPEG-ES Frame wrapped, 0x40 ??? stream id */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, 14, CODEC_ID_PCM_S16LE }, /* D-10 Mapping 50Mbps PAL Extended Template */ + { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, CODEC_ID_NONE }, }; +/* + * Match an uid independently of the version byte and up to len common bytes + * Returns: boolean + */ +static int mxf_match_uid(const UID key, const UID uid, int len) +{ + int i; + for (i = 0; i < len; i++) { + if (i != 7 && key[i] != uid[i]) + return 0; + } + return 1; +} + static const MXFCodecUL *mxf_get_codec_ul(const MXFCodecUL *uls, UID *uid) { while (uls->id != CODEC_ID_NONE) { - if(!memcmp(uls->uid, *uid, 16)) + if(mxf_match_uid(uls->uid, *uid, uls->matching_len)) break; uls++; } @@ -640,7 +686,7 @@ static const MXFCodecUL *mxf_get_codec_ul(const MXFCodecUL *uls, UID *uid) static enum CodecType mxf_get_codec_type(const MXFDataDefinitionUL *uls, UID *uid) { while (uls->type != CODEC_TYPE_DATA) { - if(!memcmp(uls->uid, *uid, 16)) + if(mxf_match_uid(uls->uid, *uid, 16)) break; uls++; } @@ -740,6 +786,10 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) continue; st = av_new_stream(mxf->fc, source_track->track_id); + if (!st) { + av_log(mxf->fc, AV_LOG_ERROR, "could not allocate stream\n"); + return -1; + } st->priv_data = source_track; st->duration = component->duration; if (st->duration == -1) @@ -810,7 +860,7 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) st->codec->width = descriptor->width; st->codec->height = descriptor->height; st->codec->bits_per_sample = descriptor->bits_per_sample; /* Uncompressed */ - st->need_parsing = 2; /* only parse headers */ + st->need_parsing = AVSTREAM_PARSE_HEADERS; } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) { container_ul = mxf_get_codec_ul(mxf_sound_essence_container_uls, essence_container_ul); if (st->codec->codec_id == CODEC_ID_NONE) @@ -829,71 +879,73 @@ static int mxf_parse_structural_metadata(MXFContext *mxf) st->codec->codec_id = CODEC_ID_PCM_S24BE; else if (descriptor->bits_per_sample == 32) st->codec->codec_id = CODEC_ID_PCM_S32BE; - if (descriptor->essence_container_ul[13] == 0x01) /* D-10 Mapping */ - st->codec->channels = 8; /* force channels to 8 */ } else if (st->codec->codec_id == CODEC_ID_MP2) { - st->need_parsing = 1; + st->need_parsing = AVSTREAM_PARSE_FULL; } } - if (container_ul && container_ul->wrapping == Clip) { - dprintf(mxf->fc, "stream %d: clip wrapped essence\n", st->index); - st->need_parsing = 1; + if (st->codec->codec_type != CODEC_TYPE_DATA && (*essence_container_ul)[15] > 0x01) { + av_log(mxf->fc, AV_LOG_WARNING, "only frame wrapped mappings are correctly supported\n"); + st->need_parsing = AVSTREAM_PARSE_FULL; } } return 0; } static const MXFMetadataReadTableEntry mxf_metadata_read_table[] = { - { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x18,0x00 }, mxf_read_metadata_content_storage, 0, AnyType }, - { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 }, mxf_read_metadata_source_package, sizeof(MXFPackage), SourcePackage }, - { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x36,0x00 }, mxf_read_metadata_material_package, sizeof(MXFPackage), MaterialPackage }, - { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x0F,0x00 }, mxf_read_metadata_sequence, sizeof(MXFSequence), Sequence }, - { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x11,0x00 }, mxf_read_metadata_source_clip, sizeof(MXFStructuralComponent), SourceClip }, - { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x44,0x00 }, mxf_read_metadata_generic_descriptor, sizeof(MXFDescriptor), MultipleDescriptor }, - { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x42,0x00 }, mxf_read_metadata_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* Generic Sound */ - { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x28,0x00 }, mxf_read_metadata_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* CDCI */ - { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x29,0x00 }, mxf_read_metadata_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* RGBA */ - { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 }, mxf_read_metadata_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* MPEG 2 Video */ - { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 }, mxf_read_metadata_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* Wave */ - { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 }, mxf_read_metadata_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* AES3 */ - { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3A,0x00 }, mxf_read_metadata_track, sizeof(MXFTrack), Track }, /* Static Track */ - { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3B,0x00 }, mxf_read_metadata_track, sizeof(MXFTrack), Track }, /* Generic Track */ - { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x04,0x01,0x02,0x02,0x00,0x00 }, mxf_read_metadata_cryptographic_context, sizeof(MXFCryptoContext), CryptoContext }, + { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x05,0x01,0x00 }, mxf_read_primer_pack }, + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x18,0x00 }, mxf_read_content_storage, 0, AnyType }, + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 }, mxf_read_source_package, sizeof(MXFPackage), SourcePackage }, + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x36,0x00 }, mxf_read_material_package, sizeof(MXFPackage), MaterialPackage }, + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x0F,0x00 }, mxf_read_sequence, sizeof(MXFSequence), Sequence }, + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x11,0x00 }, mxf_read_source_clip, sizeof(MXFStructuralComponent), SourceClip }, + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x44,0x00 }, mxf_read_generic_descriptor, sizeof(MXFDescriptor), MultipleDescriptor }, + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x42,0x00 }, mxf_read_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* Generic Sound */ + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x28,0x00 }, mxf_read_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* CDCI */ + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x29,0x00 }, mxf_read_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* RGBA */ + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 }, mxf_read_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* MPEG 2 Video */ + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x48,0x00 }, mxf_read_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* Wave */ + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x47,0x00 }, mxf_read_generic_descriptor, sizeof(MXFDescriptor), Descriptor }, /* AES3 */ + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3A,0x00 }, mxf_read_track, sizeof(MXFTrack), Track }, /* Static Track */ + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x3B,0x00 }, mxf_read_track, sizeof(MXFTrack), Track }, /* Generic Track */ + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x04,0x01,0x02,0x02,0x00,0x00 }, mxf_read_cryptographic_context, sizeof(MXFCryptoContext), CryptoContext }, { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, NULL, 0, AnyType }, }; -static int mxf_read_sync(ByteIOContext *pb, const uint8_t *key, unsigned size) -{ - int i, b; - for (i = 0; i < size && !url_feof(pb); i++) { - b = get_byte(pb); - if (b == key[0]) - i = 0; - else if (b != key[i]) - i = -1; - } - return i == size; -} - static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, int (*read_child)(), int ctx_size, enum MXFMetadataSetType type) { - ByteIOContext *pb = &mxf->fc->pb; + ByteIOContext *pb = mxf->fc->pb; MXFMetadataSet *ctx = ctx_size ? av_mallocz(ctx_size) : mxf; - uint64_t klv_end= url_ftell(pb) + klv->length; + uint64_t klv_end = url_ftell(pb) + klv->length; + if (!ctx) + return -1; while (url_ftell(pb) + 4 < klv_end) { int tag = get_be16(pb); int size = get_be16(pb); /* KLV specified by 0x53 */ - uint64_t next= url_ftell(pb) + size; + uint64_t next = url_ftell(pb) + size; + UID uid = {0}; if (!size) { /* ignore empty tag, needed for some files with empty UMID tag */ av_log(mxf->fc, AV_LOG_ERROR, "local tag 0x%04X with 0 size\n", tag); continue; } - if(ctx_size && tag == 0x3C0A) + if (tag > 0x7FFF) { /* dynamic tag */ + int i; + for (i = 0; i < mxf->local_tags_count; i++) { + int local_tag = AV_RB16(mxf->local_tags+i*18); + if (local_tag == tag) { + memcpy(uid, mxf->local_tags+i*18+2, 16); + dprintf(mxf->fc, "local tag 0x%04X\n", local_tag); +#ifdef DEBUG + PRINT_KEY(mxf->fc, "uid", uid); +#endif + } + } + } + if (ctx_size && tag == 0x3C0A) get_buffer(pb, ctx->uid, 16); - else - read_child(ctx, pb, tag, size); + else if (read_child(ctx, pb, tag, size, uid) < 0) + return -1; url_fseek(pb, next, SEEK_SET); } @@ -906,33 +958,31 @@ static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap) MXFContext *mxf = s->priv_data; KLVPacket klv; - mxf->sync_key = mxf_essence_element_key; - if (!mxf_read_sync(&s->pb, mxf_header_partition_pack_key, 14)) { + if (!mxf_read_sync(s->pb, mxf_header_partition_pack_key, 14)) { av_log(s, AV_LOG_ERROR, "could not find header partition pack key\n"); return -1; } - url_fseek(&s->pb, -14, SEEK_CUR); + url_fseek(s->pb, -14, SEEK_CUR); mxf->fc = s; - while (!url_feof(&s->pb)) { + while (!url_feof(s->pb)) { const MXFMetadataReadTableEntry *metadata; - if (klv_read_packet(&klv, &s->pb) < 0) { - av_log(s, AV_LOG_ERROR, "error reading KLV packet\n"); + if (klv_read_packet(&klv, s->pb) < 0) return -1; - } #ifdef DEBUG PRINT_KEY(s, "read header", klv.key); #endif if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key) || IS_KLV_KEY(klv.key, mxf_essence_element_key)) { /* FIXME avoid seek */ - url_fseek(&s->pb, klv.offset, SEEK_SET); + url_fseek(s->pb, klv.offset, SEEK_SET); break; } for (metadata = mxf_metadata_read_table; metadata->read; metadata++) { if (IS_KLV_KEY(klv.key, metadata->key)) { - if (mxf_read_local_tags(mxf, &klv, metadata->read, metadata->ctx_size, metadata->type) < 0) { + int (*read)() = klv.key[5] == 0x53 ? mxf_read_local_tags : metadata->read; + if (read(mxf, &klv, metadata->read, metadata->ctx_size, metadata->type) < 0) { av_log(s, AV_LOG_ERROR, "error reading header metadata\n"); return -1; } @@ -940,7 +990,7 @@ static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap) } } if (!metadata->read) - url_fskip(&s->pb, klv.length); + url_fskip(s->pb, klv.length); } return mxf_parse_structural_metadata(mxf); } @@ -970,6 +1020,7 @@ static int mxf_read_close(AVFormatContext *s) } av_freep(&mxf->metadata_sets); av_freep(&mxf->aesc); + av_freep(&mxf->local_tags); return 0; } @@ -989,11 +1040,10 @@ static int mxf_probe(AVProbeData *p) { return 0; } -/* rudimentary binary seek */ +/* rudimentary byte seek */ /* XXX: use MXF Index */ static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_time, int flags) { - MXFContext *mxf = s->priv_data; AVStream *st = s->streams[stream_index]; int64_t seconds; @@ -1002,12 +1052,7 @@ static int mxf_read_seek(AVFormatContext *s, int stream_index, int64_t sample_ti if (sample_time < 0) sample_time = 0; seconds = av_rescale(sample_time, st->time_base.num, st->time_base.den); - url_fseek(&s->pb, (s->bit_rate * seconds) >> 3, SEEK_SET); - if (!mxf_read_sync(&s->pb, mxf->sync_key, 12)) - return -1; - - /* found KLV key */ - url_fseek(&s->pb, -12, SEEK_CUR); + url_fseek(s->pb, (s->bit_rate * seconds) >> 3, SEEK_SET); av_update_cur_dts(s, st, sample_time); return 0; } diff --git a/contrib/ffmpeg/libavformat/network.h b/contrib/ffmpeg/libavformat/network.h index 3aa8ba836..d897722c9 100644 --- a/contrib/ffmpeg/libavformat/network.h +++ b/contrib/ffmpeg/libavformat/network.h @@ -18,20 +18,52 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef NETWORK_H -#define NETWORK_H +#ifndef FFMPEG_NETWORK_H +#define FFMPEG_NETWORK_H +#ifdef HAVE_WINSOCK2_H +#include +#include + +#define ff_neterrno() WSAGetLastError() +#define FF_NETERROR(err) WSA##err +#define WSAEAGAIN WSAEWOULDBLOCK +#else #include #include #include +#include + +#define ff_neterrno() errno +#define FF_NETERROR(err) err +#endif + #ifdef HAVE_ARPA_INET_H #include #endif -#include + +int ff_socket_nonblock(int socket, int enable); + +static inline int ff_network_init(void) +{ +#ifdef HAVE_WINSOCK2_H + WSADATA wsaData; + if (WSAStartup(MAKEWORD(1,1), &wsaData)) + return 0; +#endif + return 1; +} + +static inline void ff_network_close(void) +{ +#ifdef HAVE_WINSOCK2_H + WSACleanup(); +#endif +} #if !defined(HAVE_INET_ATON) /* in os_support.c */ int inet_aton (const char * str, struct in_addr * add); #endif -#endif +#endif /* FFMPEG_NETWORK_H */ diff --git a/contrib/ffmpeg/libavformat/nsvdec.c b/contrib/ffmpeg/libavformat/nsvdec.c index 2753edbd9..a115fe571 100644 --- a/contrib/ffmpeg/libavformat/nsvdec.c +++ b/contrib/ffmpeg/libavformat/nsvdec.c @@ -91,7 +91,7 @@ struct NSVf_header { uint32_t chunk_tag; /* 'NSVf' */ uint32_t chunk_size; - uint32_t file_size; /* max 4GB ??? noone learns anything it seems :^) */ + uint32_t file_size; /* max 4GB ??? no one learns anything it seems :^) */ uint32_t file_length; //unknown1; /* what about MSB of file_size ? */ uint32_t info_strings_size; /* size of the info strings */ //unknown2; uint32_t table_entries; @@ -197,7 +197,7 @@ static const AVCodecTag nsv_codec_video_tags[] = { { CODEC_ID_VP4, MKTAG('V', 'P', '4', ' ') }, { CODEC_ID_VP4, MKTAG('V', 'P', '4', '0') }, */ - { CODEC_ID_XVID, MKTAG('X', 'V', 'I', 'D') }, /* cf sample xvid decoder from nsv_codec_sdk.zip */ + { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D') }, /* cf sample xvid decoder from nsv_codec_sdk.zip */ { CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', '3') }, { 0, 0 }, }; @@ -228,7 +228,7 @@ static void print_tag(const char *str, unsigned int tag, int size) static int nsv_resync(AVFormatContext *s) { NSVContext *nsv = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; uint32_t v = 0; int i; @@ -275,7 +275,7 @@ static int nsv_resync(AVFormatContext *s) static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap) { NSVContext *nsv = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; unsigned int file_size, size; int64_t duration; int strings_size; @@ -394,7 +394,7 @@ static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap) static int nsv_parse_NSVs_header(AVFormatContext *s, AVFormatParameters *ap) { NSVContext *nsv = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; uint32_t vtag, atag; uint16_t vwidth, vheight; AVRational framerate; @@ -474,7 +474,7 @@ static int nsv_parse_NSVs_header(AVFormatContext *s, AVFormatParameters *ap) st->codec->codec_tag = atag; st->codec->codec_id = codec_get_id(nsv_codec_audio_tags, atag); - st->need_parsing = 1; /* for PCM we will read a chunk later and put correct info */ + st->need_parsing = AVSTREAM_PARSE_FULL; /* for PCM we will read a chunk later and put correct info */ /* set timebase to common denominator of ms and framerate */ av_set_pts_info(st, 64, 1, framerate.num*1000); @@ -533,7 +533,7 @@ static int nsv_read_header(AVFormatContext *s, AVFormatParameters *ap) static int nsv_read_chunk(AVFormatContext *s, int fill_header) { NSVContext *nsv = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVStream *st[2] = {NULL, NULL}; NSVStream *nst; AVPacket *pkt; @@ -609,7 +609,8 @@ null_chunk_retry: PRINT(("NSV video: [%d] = %02x\n", i, pkt->data[i])); */ } - ((NSVStream*)st[NSV_ST_VIDEO]->priv_data)->frame_offset++; + if(st[NSV_ST_VIDEO]) + ((NSVStream*)st[NSV_ST_VIDEO]->priv_data)->frame_offset++; if (asize/*st[NSV_ST_AUDIO]*/) { nst = st[NSV_ST_AUDIO]->priv_data; @@ -626,7 +627,7 @@ null_chunk_retry: asize-=4; PRINT(("NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate)); if (fill_header) { - st[NSV_ST_AUDIO]->need_parsing = 0; /* we know everything */ + st[NSV_ST_AUDIO]->need_parsing = AVSTREAM_PARSE_NONE; /* we know everything */ if (bps != 16) { PRINT(("NSV AUDIO bit/sample != 16 (%d)!!!\n", bps)); } @@ -728,14 +729,9 @@ static int nsv_probe(AVProbeData *p) int i; // PRINT(("nsv_probe(), buf_size %d\n", p->buf_size)); /* check file header */ - if (p->buf_size <= 32) - return 0; - if (p->buf[0] == 'N' && p->buf[1] == 'S' && - p->buf[2] == 'V' && p->buf[3] == 'f') - return AVPROBE_SCORE_MAX; /* streamed files might not have any header */ if (p->buf[0] == 'N' && p->buf[1] == 'S' && - p->buf[2] == 'V' && p->buf[3] == 's') + p->buf[2] == 'V' && (p->buf[3] == 'f' || p->buf[3] == 's')) return AVPROBE_SCORE_MAX; /* XXX: do streamed files always start at chunk boundary ?? */ /* or do we need to search NSVs in the byte stream ? */ @@ -748,7 +744,7 @@ static int nsv_probe(AVProbeData *p) } /* so we'll have more luck on extension... */ if (match_ext(p->filename, "nsv")) - return AVPROBE_SCORE_MAX-20; + return AVPROBE_SCORE_MAX/2; /* FIXME: add mime-type check */ return 0; } diff --git a/contrib/ffmpeg/libavformat/nut.c b/contrib/ffmpeg/libavformat/nut.c index 995149951..fdcaac6a3 100644 --- a/contrib/ffmpeg/libavformat/nut.c +++ b/contrib/ffmpeg/libavformat/nut.c @@ -1,7 +1,6 @@ /* - * "NUT" Container Format muxer and demuxer (DRAFT-200403??) - * Copyright (c) 2003 Alex Beregszaszi - * Copyright (c) 2004 Michael Niedermayer + * nut + * Copyright (c) 2004-2007 Michael Niedermayer * * This file is part of FFmpeg. * @@ -18,1440 +17,46 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - * Visit the official site at http://www.nut.hu/ - * */ -/* - * TODO: - * - index writing - * - index packet reading support -*/ - -//#define DEBUG 1 - -#include -#include "avformat.h" -#include "mpegaudio.h" -#include "riff.h" -#include "adler32.h" - -#undef NDEBUG -#include - -//#define TRACE - -//from /dev/random - -#define MAIN_STARTCODE (0x7A561F5F04ADULL + (((uint64_t)('N'<<8) + 'M')<<48)) -#define STREAM_STARTCODE (0x11405BF2F9DBULL + (((uint64_t)('N'<<8) + 'S')<<48)) -#define KEYFRAME_STARTCODE (0xE4ADEECA4569ULL + (((uint64_t)('N'<<8) + 'K')<<48)) -#define INDEX_STARTCODE (0xDD672F23E64EULL + (((uint64_t)('N'<<8) + 'X')<<48)) -#define INFO_STARTCODE (0xAB68B596BA78ULL + (((uint64_t)('N'<<8) + 'I')<<48)) - -#define ID_STRING "nut/multimedia container\0" - -#define MAX_DISTANCE (1024*16-1) -#define MAX_SHORT_DISTANCE (1024*4-1) - -#define FLAG_DATA_SIZE 1 -#define FLAG_KEY_FRAME 2 -#define FLAG_INVALID 4 - -typedef struct { - uint8_t flags; - uint8_t stream_id_plus1; - uint16_t size_mul; - uint16_t size_lsb; - int16_t timestamp_delta; - uint8_t reserved_count; -} FrameCode; - -typedef struct { - int last_key_frame; - int msb_timestamp_shift; - int rate_num; - int rate_den; - int64_t last_pts; - int64_t last_sync_pos; /// startcode less, 1-> short startcode 2-> long startcodes - FrameCode frame_code[256]; - unsigned int stream_count; - uint64_t next_startcode; ///< stores the next startcode if it has alraedy been parsed but the stream isnt seekable - StreamContext *stream; - int max_distance; - int max_short_distance; - int rate_num; - int rate_den; - int short_startcode; -} NUTContext; - -static char *info_table[][2]={ - {NULL , NULL }, // end - {NULL , NULL }, - {NULL , "UTF8"}, - {NULL , "v"}, - {NULL , "s"}, - {"StreamId" , "v"}, - {"SegmentId" , "v"}, - {"StartTimestamp" , "v"}, - {"EndTimestamp" , "v"}, - {"Author" , "UTF8"}, - {"Title" , "UTF8"}, - {"Description" , "UTF8"}, - {"Copyright" , "UTF8"}, - {"Encoder" , "UTF8"}, - {"Keyword" , "UTF8"}, - {"Cover" , "JPEG"}, - {"Cover" , "PNG"}, -}; - -static void update(NUTContext *nut, int stream_index, int64_t frame_start, int frame_type, int frame_code, int key_frame, int size, int64_t pts){ - StreamContext *stream= &nut->stream[stream_index]; - - stream->last_key_frame= key_frame; - nut->packet_start[ frame_type ]= frame_start; - stream->last_pts= pts; -} +#include "nut.h" +#include "tree.h" -static void reset(AVFormatContext *s, int64_t global_ts){ - NUTContext *nut = s->priv_data; +void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val){ int i; - - for(i=0; inb_streams; i++){ - StreamContext *stream= &nut->stream[i]; - - stream->last_key_frame= 1; - - stream->last_pts= av_rescale(global_ts, stream->rate_num*(int64_t)nut->rate_den, stream->rate_den*(int64_t)nut->rate_num); - } -} - -static void build_frame_code(AVFormatContext *s){ - NUTContext *nut = s->priv_data; - int key_frame, index, pred, stream_id; - int start=0; - int end= 255; - int keyframe_0_esc= s->nb_streams > 2; - int pred_table[10]; - - if(keyframe_0_esc){ - /* keyframe = 0 escape */ - FrameCode *ft= &nut->frame_code[start]; - ft->flags= FLAG_DATA_SIZE; - ft->stream_id_plus1= 0; - ft->size_mul=1; - ft->timestamp_delta=0; - start++; - } - - for(stream_id= 0; stream_idnb_streams; stream_id++){ - int start2= start + (end-start)*stream_id / s->nb_streams; - int end2 = start + (end-start)*(stream_id+1) / s->nb_streams; - AVCodecContext *codec = s->streams[stream_id]->codec; - int is_audio= codec->codec_type == CODEC_TYPE_AUDIO; - int intra_only= /*codec->intra_only || */is_audio; - int pred_count; - - for(key_frame=0; key_frame<2; key_frame++){ - if(intra_only && keyframe_0_esc && key_frame==0) - continue; - - { - FrameCode *ft= &nut->frame_code[start2]; - ft->flags= FLAG_KEY_FRAME*key_frame; - ft->flags|= FLAG_DATA_SIZE; - ft->stream_id_plus1= stream_id + 1; - ft->size_mul=1; - ft->timestamp_delta=0; - start2++; - } - } - - key_frame= intra_only; -#if 1 - if(is_audio){ - int frame_bytes= codec->frame_size*(int64_t)codec->bit_rate / (8*codec->sample_rate); - int pts; - for(pts=0; pts<2; pts++){ - for(pred=0; pred<2; pred++){ - FrameCode *ft= &nut->frame_code[start2]; - ft->flags= FLAG_KEY_FRAME*key_frame; - ft->stream_id_plus1= stream_id + 1; - ft->size_mul=frame_bytes + 2; - ft->size_lsb=frame_bytes + pred; - ft->timestamp_delta=pts; - start2++; - } - } - }else{ - FrameCode *ft= &nut->frame_code[start2]; - ft->flags= FLAG_KEY_FRAME | FLAG_DATA_SIZE; - ft->stream_id_plus1= stream_id + 1; - ft->size_mul=1; - ft->timestamp_delta=1; - start2++; - } -#endif - - if(codec->has_b_frames){ - pred_count=5; - pred_table[0]=-2; - pred_table[1]=-1; - pred_table[2]=1; - pred_table[3]=3; - pred_table[4]=4; - }else if(codec->codec_id == CODEC_ID_VORBIS){ - pred_count=3; - pred_table[0]=2; - pred_table[1]=9; - pred_table[2]=16; - }else{ - pred_count=1; - pred_table[0]=1; - } - - for(pred=0; predframe_code[index]; - ft->flags= FLAG_KEY_FRAME*key_frame; - ft->flags|= FLAG_DATA_SIZE; - ft->stream_id_plus1= stream_id + 1; -//FIXME use single byte size and pred from last - ft->size_mul= end3-start3; - ft->size_lsb= index - start3; - ft->timestamp_delta= pred_table[pred]; - } - } - } - memmove(&nut->frame_code['N'+1], &nut->frame_code['N'], sizeof(FrameCode)*(255-'N')); - nut->frame_code['N'].flags= FLAG_INVALID; -} - -static uint64_t get_v(ByteIOContext *bc) -{ - uint64_t val = 0; - - for(;;) - { - int tmp = get_byte(bc); - - if (tmp&0x80) - val= (val<<7) + tmp - 0x80; - else{ -//av_log(NULL, AV_LOG_DEBUG, "get_v()= %"PRId64"\n", (val<<7) + tmp); - return (val<<7) + tmp; - } + for(i=0; iavf->nb_streams; i++){ + nut->stream[i].last_pts= av_rescale_rnd( + val, + time_base.num * (int64_t)nut->stream[i].time_base->den, + time_base.den * (int64_t)nut->stream[i].time_base->num, + AV_ROUND_DOWN); } - return -1; -} - -static int get_str(ByteIOContext *bc, char *string, unsigned int maxlen){ - unsigned int len= get_v(bc); - - if(len && maxlen) - get_buffer(bc, string, FFMIN(len, maxlen)); - while(len > maxlen){ - get_byte(bc); - len--; - } - - if(maxlen) - string[FFMIN(len, maxlen-1)]= 0; - - if(maxlen == len) - return -1; - else - return 0; -} - -static int64_t get_s(ByteIOContext *bc){ - int64_t v = get_v(bc) + 1; - - if (v&1) return -(v>>1); - else return (v>>1); -} - -static uint64_t get_vb(ByteIOContext *bc){ - uint64_t val=0; - unsigned int i= get_v(bc); - - if(i>8) - return UINT64_MAX; - - while(i--) - val = (val<<8) + get_byte(bc); - -//av_log(NULL, AV_LOG_DEBUG, "get_vb()= %"PRId64"\n", val); - return val; -} - -#ifdef TRACE -static inline uint64_t get_v_trace(ByteIOContext *bc, char *file, char *func, int line){ - uint64_t v= get_v(bc); - - printf("get_v %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); - return v; -} - -static inline int64_t get_s_trace(ByteIOContext *bc, char *file, char *func, int line){ - int64_t v= get_s(bc); - - printf("get_s %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); - return v; -} - -static inline uint64_t get_vb_trace(ByteIOContext *bc, char *file, char *func, int line){ - uint64_t v= get_vb(bc); - - printf("get_vb %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); - return v; -} -#define get_v(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__) -#define get_s(bc) get_s_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__) -#define get_vb(bc) get_vb_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__) -#endif - - -static int get_packetheader(NUTContext *nut, ByteIOContext *bc, int calculate_checksum) -{ - int64_t start, size; - start= url_ftell(bc) - 8; - - size= get_v(bc); - - init_checksum(bc, calculate_checksum ? av_adler32_update : NULL, 1); - - nut->packet_start[2] = start; - nut->written_packet_size= size; - - return size; -} - -static int check_checksum(ByteIOContext *bc){ - unsigned long checksum= get_checksum(bc); - return checksum != get_be32(bc); -} - -/** - * - */ -static int get_length(uint64_t val){ - int i; - - for (i=7; val>>i; i+=7); - - return i; } -static uint64_t find_any_startcode(ByteIOContext *bc, int64_t pos){ - uint64_t state=0; - - if(pos >= 0) - url_fseek(bc, pos, SEEK_SET); //note, this may fail if the stream isnt seekable, but that shouldnt matter, as in this case we simply start where we are currently - - while(!url_feof(bc)){ - state= (state<<8) | get_byte(bc); - if((state>>56) != 'N') - continue; - switch(state){ - case MAIN_STARTCODE: - case STREAM_STARTCODE: - case KEYFRAME_STARTCODE: - case INFO_STARTCODE: - case INDEX_STARTCODE: - return state; - } - } - - return 0; -} - -/** - * find the given startcode. - * @param code the startcode - * @param pos the start position of the search, or -1 if the current position - * @returns the position of the startcode or -1 if not found - */ -static int64_t find_startcode(ByteIOContext *bc, uint64_t code, int64_t pos){ - for(;;){ - uint64_t startcode= find_any_startcode(bc, pos); - if(startcode == code) - return url_ftell(bc) - 8; - else if(startcode == 0) - return -1; - pos=-1; - } -} - -static int64_t lsb2full(StreamContext *stream, int64_t lsb){ - int64_t mask = (1<msb_timestamp_shift)-1; +int64_t ff_lsb2full(StreamContext *stream, int64_t lsb){ + int64_t mask = (1<msb_pts_shift)-1; int64_t delta= stream->last_pts - mask/2; return ((lsb - delta)&mask) + delta; } -#ifdef CONFIG_MUXERS - -static void put_v(ByteIOContext *bc, uint64_t val) -{ - int i; - -//av_log(NULL, AV_LOG_DEBUG, "put_v()= %"PRId64"\n", val); - val &= 0x7FFFFFFFFFFFFFFFULL; // FIXME can only encode upto 63 bits currently - i= get_length(val); - - for (i-=7; i>0; i-=7){ - put_byte(bc, 0x80 | (val>>i)); - } - - put_byte(bc, val&0x7f); -} - -/** - * stores a string as vb. - */ -static void put_str(ByteIOContext *bc, const char *string){ - int len= strlen(string); - - put_v(bc, len); - put_buffer(bc, string, len); -} - -static void put_s(ByteIOContext *bc, int64_t val){ - if (val<=0) put_v(bc, -2*val ); - else put_v(bc, 2*val-1); -} - -static void put_vb(ByteIOContext *bc, uint64_t val){ - int i; - - for (i=8; val>>i; i+=8); - - put_v(bc, i>>3); - for(i-=8; i>=0; i-=8) - put_byte(bc, (val>>i)&0xFF); -} - -#ifdef TRACE -static inline void put_v_trace(ByteIOContext *bc, uint64_t v, char *file, char *func, int line){ - printf("get_v %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); - - put_v(bc, v); -} - -static inline void put_s_trace(ByteIOContext *bc, int64_t v, char *file, char *func, int line){ - printf("get_s %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); - - put_s(bc, v); -} - -static inline void put_vb_trace(ByteIOContext *bc, uint64_t v, char *file, char *func, int line){ - printf("get_vb %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); - - put_vb(bc, v); -} -#define put_v(bc, v) put_v_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__) -#define put_s(bc, v) put_s_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__) -#define put_vb(bc, v) put_vb_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__) -#endif - -static int put_packetheader(NUTContext *nut, ByteIOContext *bc, int max_size, int calculate_checksum) -{ - put_flush_packet(bc); - nut->packet_start[2]= url_ftell(bc) - 8; - nut->written_packet_size = max_size; - - /* packet header */ - put_v(bc, nut->written_packet_size); /* forward ptr */ - - if(calculate_checksum) - init_checksum(bc, av_adler32_update, 1); - - return 0; -} - -/** - * - * must not be called more then once per packet - */ -static int update_packetheader(NUTContext *nut, ByteIOContext *bc, int additional_size, int calculate_checksum){ - int64_t start= nut->packet_start[2]; - int64_t cur= url_ftell(bc); - int size= cur - start - get_length(nut->written_packet_size)/7 - 8; - - if(calculate_checksum) - size += 4; - - if(size != nut->written_packet_size){ - int i; - - assert( size <= nut->written_packet_size ); - - url_fseek(bc, start + 8, SEEK_SET); - for(i=get_length(size); i < get_length(nut->written_packet_size); i+=7) - put_byte(bc, 0x80); - put_v(bc, size); - - url_fseek(bc, cur, SEEK_SET); - nut->written_packet_size= size; //FIXME may fail if multiple updates with differing sizes, as get_length may differ - - if(calculate_checksum) - put_be32(bc, get_checksum(bc)); - } - - return 0; -} - -static int nut_write_header(AVFormatContext *s) -{ - NUTContext *nut = s->priv_data; - ByteIOContext *bc = &s->pb; - AVCodecContext *codec; - int i, j, tmp_time, tmp_flags,tmp_stream, tmp_mul, tmp_size, tmp_fields; - - if (strcmp(s->filename, "./data/b-libav.nut")) { - av_log(s, AV_LOG_ERROR, " libavformat NUT is non-compliant and disabled\n"); - return -1; - } - - nut->avf= s; - - nut->stream = - av_mallocz(sizeof(StreamContext)*s->nb_streams); - - - put_buffer(bc, ID_STRING, strlen(ID_STRING)); - put_byte(bc, 0); - nut->packet_start[2]= url_ftell(bc); - - /* main header */ - put_be64(bc, MAIN_STARTCODE); - put_packetheader(nut, bc, 120+5*256, 1); - put_v(bc, 2); /* version */ - put_v(bc, s->nb_streams); - put_v(bc, MAX_DISTANCE); - put_v(bc, MAX_SHORT_DISTANCE); - - put_v(bc, nut->rate_num=1); - put_v(bc, nut->rate_den=2); - put_v(bc, nut->short_startcode=0x4EFE79); - - build_frame_code(s); - assert(nut->frame_code['N'].flags == FLAG_INVALID); - - tmp_time= tmp_flags= tmp_stream= tmp_mul= tmp_size= /*tmp_res=*/ INT_MAX; - for(i=0; i<256;){ - tmp_fields=0; - tmp_size= 0; - if(tmp_time != nut->frame_code[i].timestamp_delta) tmp_fields=1; - if(tmp_mul != nut->frame_code[i].size_mul ) tmp_fields=2; - if(tmp_stream != nut->frame_code[i].stream_id_plus1) tmp_fields=3; - if(tmp_size != nut->frame_code[i].size_lsb ) tmp_fields=4; -// if(tmp_res != nut->frame_code[i].res ) tmp_fields=5; - - tmp_time = nut->frame_code[i].timestamp_delta; - tmp_flags = nut->frame_code[i].flags; - tmp_stream= nut->frame_code[i].stream_id_plus1; - tmp_mul = nut->frame_code[i].size_mul; - tmp_size = nut->frame_code[i].size_lsb; -// tmp_res = nut->frame_code[i].res; - - for(j=0; i<256; j++,i++){ - if(nut->frame_code[i].timestamp_delta != tmp_time ) break; - if(nut->frame_code[i].flags != tmp_flags ) break; - if(nut->frame_code[i].stream_id_plus1 != tmp_stream) break; - if(nut->frame_code[i].size_mul != tmp_mul ) break; - if(nut->frame_code[i].size_lsb != tmp_size+j) break; -// if(nut->frame_code[i].res != tmp_res ) break; - } - if(j != tmp_mul - tmp_size) tmp_fields=6; - - put_v(bc, tmp_flags); - put_v(bc, tmp_fields); - if(tmp_fields>0) put_s(bc, tmp_time); - if(tmp_fields>1) put_v(bc, tmp_mul); - if(tmp_fields>2) put_v(bc, tmp_stream); - if(tmp_fields>3) put_v(bc, tmp_size); - if(tmp_fields>4) put_v(bc, 0 /*tmp_res*/); - if(tmp_fields>5) put_v(bc, j); - } - - update_packetheader(nut, bc, 0, 1); - - /* stream headers */ - for (i = 0; i < s->nb_streams; i++) - { - int nom, denom, ssize; - - codec = s->streams[i]->codec; - - put_be64(bc, STREAM_STARTCODE); - put_packetheader(nut, bc, 120 + codec->extradata_size, 1); - put_v(bc, i /*s->streams[i]->index*/); - switch(codec->codec_type){ - case CODEC_TYPE_VIDEO: put_v(bc, 0); break; - case CODEC_TYPE_AUDIO: put_v(bc, 1); break; -// case CODEC_TYPE_TEXT : put_v(bc, 2); break; - case CODEC_TYPE_DATA : put_v(bc, 3); break; - default: return -1; - } - if (codec->codec_tag) - put_vb(bc, codec->codec_tag); - else if (codec->codec_type == CODEC_TYPE_VIDEO) - { - put_vb(bc, codec_get_bmp_tag(codec->codec_id)); - } - else if (codec->codec_type == CODEC_TYPE_AUDIO) - { - put_vb(bc, codec_get_wav_tag(codec->codec_id)); - } - else - put_vb(bc, 0); - - ff_parse_specific_params(codec, &nom, &ssize, &denom); - - nut->stream[i].rate_num= nom; - nut->stream[i].rate_den= denom; - av_set_pts_info(s->streams[i], 60, denom, nom); - - put_v(bc, codec->bit_rate); - put_vb(bc, 0); /* no language code */ - put_v(bc, nom); - put_v(bc, denom); - if(nom / denom < 1000) - nut->stream[i].msb_timestamp_shift = 7; - else - nut->stream[i].msb_timestamp_shift = 14; - put_v(bc, nut->stream[i].msb_timestamp_shift); - put_v(bc, codec->has_b_frames); - put_byte(bc, 0); /* flags: 0x1 - fixed_fps, 0x2 - index_present */ - - if(codec->extradata_size){ - put_v(bc, 1); - put_v(bc, codec->extradata_size); - put_buffer(bc, codec->extradata, codec->extradata_size); - } - put_v(bc, 0); /* end of codec specific headers */ - - switch(codec->codec_type) - { - case CODEC_TYPE_AUDIO: - put_v(bc, codec->sample_rate); - put_v(bc, 1); - put_v(bc, codec->channels); - break; - case CODEC_TYPE_VIDEO: - put_v(bc, codec->width); - put_v(bc, codec->height); - put_v(bc, codec->sample_aspect_ratio.num); - put_v(bc, codec->sample_aspect_ratio.den); - put_v(bc, 0); /* csp type -- unknown */ - break; - default: - break; - } - update_packetheader(nut, bc, 0, 1); - } - - /* info header */ - put_be64(bc, INFO_STARTCODE); - put_packetheader(nut, bc, 30+strlen(s->author)+strlen(s->title)+ - strlen(s->comment)+strlen(s->copyright)+strlen(LIBAVFORMAT_IDENT), 1); - if (s->author[0]) - { - put_v(bc, 9); /* type */ - put_str(bc, s->author); - } - if (s->title[0]) - { - put_v(bc, 10); /* type */ - put_str(bc, s->title); - } - if (s->comment[0]) - { - put_v(bc, 11); /* type */ - put_str(bc, s->comment); - } - if (s->copyright[0]) - { - put_v(bc, 12); /* type */ - put_str(bc, s->copyright); - } - /* encoder */ - if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)){ - put_v(bc, 13); /* type */ - put_str(bc, LIBAVFORMAT_IDENT); - } - - put_v(bc, 0); /* eof info */ - update_packetheader(nut, bc, 0, 1); - - put_flush_packet(bc); - - return 0; -} - -static int nut_write_packet(AVFormatContext *s, AVPacket *pkt) -{ - NUTContext *nut = s->priv_data; - StreamContext *stream= &nut->stream[pkt->stream_index]; - ByteIOContext *bc = &s->pb; - int key_frame = 0, full_pts=0; - AVCodecContext *enc; - int64_t coded_pts; - int frame_type, best_length, frame_code, flags, i, size_mul, size_lsb, time_delta; - const int64_t frame_start= url_ftell(bc); - int64_t pts= pkt->pts; - int size= pkt->size; - int stream_index= pkt->stream_index; - - enc = s->streams[stream_index]->codec; - key_frame = !!(pkt->flags & PKT_FLAG_KEY); - - frame_type=0; - if(frame_start + size + 20 - FFMAX(nut->packet_start[1], nut->packet_start[2]) > MAX_DISTANCE) - frame_type=2; - if(key_frame && !stream->last_key_frame) - frame_type=2; - - if(frame_type>1){ - int64_t global_ts= av_rescale(pts, stream->rate_den*(int64_t)nut->rate_num, stream->rate_num*(int64_t)nut->rate_den); - reset(s, global_ts); - put_be64(bc, KEYFRAME_STARTCODE); - put_v(bc, global_ts); - } - assert(stream->last_pts != AV_NOPTS_VALUE); - coded_pts = pts & ((1<msb_timestamp_shift)-1); - if(lsb2full(stream, coded_pts) != pts) - full_pts=1; - - if(full_pts) - coded_pts= pts + (1<msb_timestamp_shift); - - best_length=INT_MAX; - frame_code= -1; - for(i=0; i<256; i++){ - int stream_id_plus1= nut->frame_code[i].stream_id_plus1; - int fc_key_frame; - int length=0; - size_mul= nut->frame_code[i].size_mul; - size_lsb= nut->frame_code[i].size_lsb; - time_delta= nut->frame_code[i].timestamp_delta; - flags= nut->frame_code[i].flags; - - assert(size_mul > size_lsb); - - if(stream_id_plus1 == 0) length+= get_length(stream_index); - else if(stream_id_plus1 - 1 != stream_index) - continue; - fc_key_frame= !!(flags & FLAG_KEY_FRAME); - - assert(key_frame==0 || key_frame==1); - if(fc_key_frame != key_frame) - continue; - - if(flags & FLAG_DATA_SIZE){ - if(size % size_mul != size_lsb) - continue; - length += get_length(size / size_mul); - }else if(size != size_lsb) - continue; - - if(full_pts && time_delta) - continue; - - if(!time_delta){ - length += get_length(coded_pts); - }else{ - if(time_delta != pts - stream->last_pts) - continue; - } - - if(length < best_length){ - best_length= length; - frame_code=i; - } -// av_log(s, AV_LOG_DEBUG, "%d %d %d %d %d %d %d %d %d %d\n", key_frame, frame_type, full_pts, size, stream_index, flags, size_mul, size_lsb, stream_id_plus1, length); - } - - assert(frame_code != -1); - flags= nut->frame_code[frame_code].flags; - size_mul= nut->frame_code[frame_code].size_mul; - size_lsb= nut->frame_code[frame_code].size_lsb; - time_delta= nut->frame_code[frame_code].timestamp_delta; -#ifdef TRACE - best_length /= 7; - best_length ++; //frame_code - if(frame_type==2){ - best_length += 8; // startcode - } - av_log(s, AV_LOG_DEBUG, "kf:%d ft:%d pt:%d fc:%2X len:%2d size:%d stream:%d flag:%d mul:%d lsb:%d s+1:%d pts_delta:%d pts:%"PRId64" fs:%"PRId64"\n", key_frame, frame_type, full_pts ? 1 : 0, frame_code, best_length, size, stream_index, flags, size_mul, size_lsb, nut->frame_code[frame_code].stream_id_plus1,(int)(pts - stream->last_pts), pts, frame_start); -// av_log(s, AV_LOG_DEBUG, "%d %d %d\n", stream->lru_pts_delta[0], stream->lru_pts_delta[1], stream->lru_pts_delta[2]); -#endif - - assert(frame_type != 1); //short startcode not implemented yet - put_byte(bc, frame_code); - - if(nut->frame_code[frame_code].stream_id_plus1 == 0) - put_v(bc, stream_index); - if (!time_delta){ - put_v(bc, coded_pts); - } - if(flags & FLAG_DATA_SIZE) - put_v(bc, size / size_mul); - else - assert(size == size_lsb); - if(size > MAX_DISTANCE){ - assert(frame_type > 1); - } - - put_buffer(bc, pkt->data, size); - - update(nut, stream_index, frame_start, frame_type, frame_code, key_frame, size, pts); - - return 0; +int ff_nut_sp_pos_cmp(syncpoint_t *a, syncpoint_t *b){ + return ((a->pos - b->pos) >> 32) - ((b->pos - a->pos) >> 32); } -static int nut_write_trailer(AVFormatContext *s) -{ - NUTContext *nut = s->priv_data; - ByteIOContext *bc = &s->pb; - -#if 0 - int i; - - /* WRITE INDEX */ - - for (i = 0; s->nb_streams; i++) - { - put_be64(bc, INDEX_STARTCODE); - put_packetheader(nut, bc, 64, 1); - put_v(bc, s->streams[i]->id); - put_v(bc, ...); - update_packetheader(nut, bc, 0, 1); - } -#endif - - put_flush_packet(bc); - - av_freep(&nut->stream); - - return 0; +int ff_nut_sp_pts_cmp(syncpoint_t *a, syncpoint_t *b){ + return ((a->ts - b->ts) >> 32) - ((b->ts - a->ts) >> 32); } -#endif //CONFIG_MUXERS -static int nut_probe(AVProbeData *p) -{ - int i; - uint64_t code= 0xff; +void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts){ + syncpoint_t *sp= av_mallocz(sizeof(syncpoint_t)); + struct AVTreeNode *node= av_mallocz(av_tree_node_size); - for (i = 0; i < p->buf_size; i++) { - code = (code << 8) | p->buf[i]; - if (code == MAIN_STARTCODE) - return AVPROBE_SCORE_MAX; + sp->pos= pos; + sp->back_ptr= back_ptr; + sp->ts= ts; + av_tree_insert(&nut->syncpoints, sp, ff_nut_sp_pos_cmp, &node); + if(node){ + av_free(sp); + av_free(node); } - return 0; } - -static int decode_main_header(NUTContext *nut){ - AVFormatContext *s= nut->avf; - ByteIOContext *bc = &s->pb; - uint64_t tmp; - int i, j, tmp_stream, tmp_mul, tmp_time, tmp_size, count, tmp_res; - - get_packetheader(nut, bc, 1); - - tmp = get_v(bc); - if (tmp != 2){ - av_log(s, AV_LOG_ERROR, "bad version (%"PRId64")\n", tmp); - return -1; - } - - nut->stream_count = get_v(bc); - if(nut->stream_count > MAX_STREAMS){ - av_log(s, AV_LOG_ERROR, "too many streams\n"); - return -1; - } - nut->max_distance = get_v(bc); - nut->max_short_distance = get_v(bc); - nut->rate_num= get_v(bc); - nut->rate_den= get_v(bc); - nut->short_startcode= get_v(bc); - if(nut->short_startcode>>16 != 'N'){ - av_log(s, AV_LOG_ERROR, "invalid short startcode %X\n", nut->short_startcode); - return -1; - } - - for(i=0; i<256;){ - int tmp_flags = get_v(bc); - int tmp_fields= get_v(bc); - if(tmp_fields>0) tmp_time = get_s(bc); - if(tmp_fields>1) tmp_mul = get_v(bc); - if(tmp_fields>2) tmp_stream= get_v(bc); - if(tmp_fields>3) tmp_size = get_v(bc); - else tmp_size = 0; - if(tmp_fields>4) tmp_res = get_v(bc); - else tmp_res = 0; - if(tmp_fields>5) count = get_v(bc); - else count = tmp_mul - tmp_size; - - while(tmp_fields-- > 6) - get_v(bc); - - if(count == 0 || i+count > 256){ - av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i); - return -1; - } - if(tmp_stream > nut->stream_count + 1){ - av_log(s, AV_LOG_ERROR, "illegal stream number\n"); - return -1; - } - - for(j=0; jframe_code[i].flags = tmp_flags ; - nut->frame_code[i].timestamp_delta = tmp_time ; - nut->frame_code[i].stream_id_plus1 = tmp_stream; - nut->frame_code[i].size_mul = tmp_mul ; - nut->frame_code[i].size_lsb = tmp_size+j; - nut->frame_code[i].reserved_count = tmp_res ; - } - } - if(nut->frame_code['N'].flags != FLAG_INVALID){ - av_log(s, AV_LOG_ERROR, "illegal frame_code table\n"); - return -1; - } - - if(check_checksum(bc)){ - av_log(s, AV_LOG_ERROR, "Main header checksum mismatch\n"); - return -1; - } - - return 0; -} - -static int decode_stream_header(NUTContext *nut){ - AVFormatContext *s= nut->avf; - ByteIOContext *bc = &s->pb; - int class, nom, denom, stream_id; - uint64_t tmp; - AVStream *st; - - get_packetheader(nut, bc, 1); - stream_id= get_v(bc); - if(stream_id >= nut->stream_count || s->streams[stream_id]) - return -1; - - st = av_new_stream(s, stream_id); - if (!st) - return AVERROR_NOMEM; - - class = get_v(bc); - tmp = get_vb(bc); - st->codec->codec_tag= tmp; - switch(class) - { - case 0: - st->codec->codec_type = CODEC_TYPE_VIDEO; - st->codec->codec_id = codec_get_bmp_id(tmp); - if (st->codec->codec_id == CODEC_ID_NONE) - av_log(s, AV_LOG_ERROR, "Unknown codec?!\n"); - break; - case 1: - case 32: //compatibility - st->codec->codec_type = CODEC_TYPE_AUDIO; - st->codec->codec_id = codec_get_wav_id(tmp); - if (st->codec->codec_id == CODEC_ID_NONE) - av_log(s, AV_LOG_ERROR, "Unknown codec?!\n"); - break; - case 2: -// st->codec->codec_type = CODEC_TYPE_TEXT; -// break; - case 3: - st->codec->codec_type = CODEC_TYPE_DATA; - break; - default: - av_log(s, AV_LOG_ERROR, "Unknown stream class (%d)\n", class); - return -1; - } - s->bit_rate += get_v(bc); - get_vb(bc); /* language code */ - nom = get_v(bc); - denom = get_v(bc); - nut->stream[stream_id].msb_timestamp_shift = get_v(bc); - st->codec->has_b_frames= - nut->stream[stream_id].decode_delay= get_v(bc); - get_byte(bc); /* flags */ - - /* codec specific data headers */ - while(get_v(bc) != 0){ - st->codec->extradata_size= get_v(bc); - if((unsigned)st->codec->extradata_size > (1<<30)) - return -1; - st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - get_buffer(bc, st->codec->extradata, st->codec->extradata_size); -// url_fskip(bc, get_v(bc)); - } - - if (st->codec->codec_type == CODEC_TYPE_VIDEO) /* VIDEO */ - { - st->codec->width = get_v(bc); - st->codec->height = get_v(bc); - st->codec->sample_aspect_ratio.num= get_v(bc); - st->codec->sample_aspect_ratio.den= get_v(bc); - get_v(bc); /* csp type */ - } - if (st->codec->codec_type == CODEC_TYPE_AUDIO) /* AUDIO */ - { - st->codec->sample_rate = get_v(bc); - get_v(bc); // samplerate_den - st->codec->channels = get_v(bc); - } - if(check_checksum(bc)){ - av_log(s, AV_LOG_ERROR, "Stream header %d checksum mismatch\n", stream_id); - return -1; - } - av_set_pts_info(s->streams[stream_id], 60, denom, nom); - nut->stream[stream_id].rate_num= nom; - nut->stream[stream_id].rate_den= denom; - return 0; -} - -static int decode_info_header(NUTContext *nut){ - AVFormatContext *s= nut->avf; - ByteIOContext *bc = &s->pb; - - get_packetheader(nut, bc, 1); - - for(;;){ - int id= get_v(bc); - char *name, *type, custom_name[256], custom_type[256]; - - if(!id) - break; - else if(id >= sizeof(info_table)/sizeof(info_table[0])){ - av_log(s, AV_LOG_ERROR, "info id is too large %d %zd\n", id, sizeof(info_table)/sizeof(info_table[0])); - return -1; - } - - type= info_table[id][1]; - name= info_table[id][0]; -//av_log(s, AV_LOG_DEBUG, "%d %s %s\n", id, type, name); - - if(!type){ - get_str(bc, custom_type, sizeof(custom_type)); - type= custom_type; - } - if(!name){ - get_str(bc, custom_name, sizeof(custom_name)); - name= custom_name; - } - - if(!strcmp(type, "v")){ - get_v(bc); - }else{ - if(!strcmp(name, "Author")) - get_str(bc, s->author, sizeof(s->author)); - else if(!strcmp(name, "Title")) - get_str(bc, s->title, sizeof(s->title)); - else if(!strcmp(name, "Copyright")) - get_str(bc, s->copyright, sizeof(s->copyright)); - else if(!strcmp(name, "Description")) - get_str(bc, s->comment, sizeof(s->comment)); - else - get_str(bc, NULL, 0); - } - } - if(check_checksum(bc)){ - av_log(s, AV_LOG_ERROR, "Info header checksum mismatch\n"); - return -1; - } - return 0; -} - -static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap) -{ - NUTContext *nut = s->priv_data; - ByteIOContext *bc = &s->pb; - int64_t pos; - int inited_stream_count; - - nut->avf= s; - - /* main header */ - pos=0; - for(;;){ - pos= find_startcode(bc, MAIN_STARTCODE, pos)+1; - if (pos<0){ - av_log(s, AV_LOG_ERROR, "no main startcode found\n"); - return -1; - } - if(decode_main_header(nut) >= 0) - break; - } - - - s->bit_rate = 0; - - nut->stream = av_malloc(sizeof(StreamContext)*nut->stream_count); - - /* stream headers */ - pos=0; - for(inited_stream_count=0; inited_stream_count < nut->stream_count;){ - pos= find_startcode(bc, STREAM_STARTCODE, pos)+1; - if (pos<0+1){ - av_log(s, AV_LOG_ERROR, "not all stream headers found\n"); - return -1; - } - if(decode_stream_header(nut) >= 0) - inited_stream_count++; - } - - /* info headers */ - pos=0; - for(;;){ - uint64_t startcode= find_any_startcode(bc, pos); - pos= url_ftell(bc); - - if(startcode==0){ - av_log(s, AV_LOG_ERROR, "EOF before video frames\n"); - return -1; - }else if(startcode == KEYFRAME_STARTCODE){ - nut->next_startcode= startcode; - break; - }else if(startcode != INFO_STARTCODE){ - continue; - } - - decode_info_header(nut); - } - - return 0; -} - -static int decode_frame_header(NUTContext *nut, int *key_frame_ret, int64_t *pts_ret, int *stream_id_ret, int frame_code, int frame_type, int64_t frame_start){ - AVFormatContext *s= nut->avf; - StreamContext *stream; - ByteIOContext *bc = &s->pb; - int size, flags, size_mul, size_lsb, stream_id, time_delta; - int64_t pts = 0; - - if(frame_type < 2 && frame_start - nut->packet_start[2] > nut->max_distance){ - av_log(s, AV_LOG_ERROR, "last frame must have been damaged\n"); - return -1; - } - - if(frame_type) - nut->packet_start[ frame_type ]= frame_start; //otherwise 1 goto 1 may happen - - flags= nut->frame_code[frame_code].flags; - size_mul= nut->frame_code[frame_code].size_mul; - size_lsb= nut->frame_code[frame_code].size_lsb; - stream_id= nut->frame_code[frame_code].stream_id_plus1 - 1; - time_delta= nut->frame_code[frame_code].timestamp_delta; - - if(stream_id==-1) - stream_id= get_v(bc); - if(stream_id >= s->nb_streams){ - av_log(s, AV_LOG_ERROR, "illegal stream_id\n"); - return -1; - } - stream= &nut->stream[stream_id]; - -// av_log(s, AV_LOG_DEBUG, "ft:%d ppts:%d %d %d\n", frame_type, stream->lru_pts_delta[0], stream->lru_pts_delta[1], stream->lru_pts_delta[2]); - - *key_frame_ret= !!(flags & FLAG_KEY_FRAME); - - if(!time_delta){ - int64_t mask = (1<msb_timestamp_shift)-1; - pts= get_v(bc); - if(pts > mask){ - pts -= mask+1; - }else{ - if(stream->last_pts == AV_NOPTS_VALUE){ - av_log(s, AV_LOG_ERROR, "no reference pts available\n"); - return -1; - } - pts= lsb2full(stream, pts); - } - }else{ - if(stream->last_pts == AV_NOPTS_VALUE){ - av_log(s, AV_LOG_ERROR, "no reference pts available\n"); - return -1; - } - pts= stream->last_pts + time_delta; - } - - if(*key_frame_ret){ -// av_log(s, AV_LOG_DEBUG, "stream:%d start:%"PRId64" pts:%"PRId64" length:%"PRId64"\n",stream_id, frame_start, av_pts, frame_start - nut->stream[stream_id].last_sync_pos); - av_add_index_entry( - s->streams[stream_id], - frame_start, - pts, - 0, - frame_start - nut->stream[stream_id].last_sync_pos, - AVINDEX_KEYFRAME); - nut->stream[stream_id].last_sync_pos= frame_start; -// assert(nut->packet_start == frame_start); - } - - assert(size_mul > size_lsb); - size= size_lsb; - if(flags & FLAG_DATA_SIZE) - size+= size_mul*get_v(bc); - -#ifdef TRACE -av_log(s, AV_LOG_DEBUG, "fs:%"PRId64" fc:%d ft:%d kf:%d pts:%"PRId64" size:%d mul:%d lsb:%d flags:%d delta:%d\n", frame_start, frame_code, frame_type, *key_frame_ret, pts, size, size_mul, size_lsb, flags, time_delta); -#endif - - if(frame_type==0 && url_ftell(bc) - nut->packet_start[2] + size > nut->max_distance){ - av_log(s, AV_LOG_ERROR, "frame size too large\n"); - return -1; - } - - *stream_id_ret = stream_id; - *pts_ret = pts; - - update(nut, stream_id, frame_start, frame_type, frame_code, *key_frame_ret, size, pts); - - return size; -} - -static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code, int frame_type, int64_t frame_start){ - AVFormatContext *s= nut->avf; - ByteIOContext *bc = &s->pb; - int size, stream_id, key_frame, discard; - int64_t pts, last_IP_pts; - - size= decode_frame_header(nut, &key_frame, &pts, &stream_id, frame_code, frame_type, frame_start); - if(size < 0) - return -1; - - discard= s->streams[ stream_id ]->discard; - last_IP_pts= s->streams[ stream_id ]->last_IP_pts; - if( (discard >= AVDISCARD_NONKEY && !key_frame) - ||(discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE && last_IP_pts > pts) - || discard >= AVDISCARD_ALL){ - url_fskip(bc, size); - return 1; - } - - av_get_packet(bc, pkt, size); - pkt->stream_index = stream_id; - if (key_frame) - pkt->flags |= PKT_FLAG_KEY; - pkt->pts = pts; - - return 0; -} - -static int nut_read_packet(AVFormatContext *s, AVPacket *pkt) -{ - NUTContext *nut = s->priv_data; - ByteIOContext *bc = &s->pb; - int i, frame_code=0, ret; - - for(;;){ - int64_t pos= url_ftell(bc); - int frame_type= 0; - uint64_t tmp= nut->next_startcode; - nut->next_startcode=0; - - if (url_feof(bc)) - return -1; - - if(tmp){ - pos-=8; - }else{ - frame_code = get_byte(bc); - if(frame_code == 'N'){ - tmp= frame_code; - for(i=1; i<8; i++) - tmp = (tmp<<8) + get_byte(bc); - } - } - switch(tmp){ - case MAIN_STARTCODE: - case STREAM_STARTCODE: - case INDEX_STARTCODE: - get_packetheader(nut, bc, 0); - assert(nut->packet_start[2] == pos); - url_fseek(bc, nut->written_packet_size, SEEK_CUR); - break; - case INFO_STARTCODE: - if(decode_info_header(nut)<0) - goto resync; - break; - case KEYFRAME_STARTCODE: - frame_type = 2; - reset(s, get_v(bc)); - frame_code = get_byte(bc); - case 0: - ret= decode_frame(nut, pkt, frame_code, frame_type, pos); - if(ret==0) - return 0; - else if(ret==1) //ok but discard packet - break; - default: -resync: -av_log(s, AV_LOG_DEBUG, "syncing from %"PRId64"\n", nut->packet_start[2]+1); - tmp= find_any_startcode(bc, nut->packet_start[2]+1); - if(tmp==0) - return -1; -av_log(s, AV_LOG_DEBUG, "sync\n"); - nut->next_startcode= tmp; - } - } -} - -static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos_arg, int64_t pos_limit){ - NUTContext *nut = s->priv_data; - StreamContext *stream; - ByteIOContext *bc = &s->pb; - int64_t pos, pts; - uint64_t code; - int frame_code,step, stream_id, i,size, key_frame; -av_log(s, AV_LOG_DEBUG, "read_timestamp(X,%d,%"PRId64",%"PRId64")\n", stream_index, *pos_arg, pos_limit); - - if(*pos_arg < 0) - return AV_NOPTS_VALUE; - - pos= *pos_arg; - step= FFMIN(16*1024, pos); - do{ - pos-= step; - code= find_any_startcode(bc, pos); - - if(code && url_ftell(bc) - 8 <= *pos_arg) - break; - step= FFMIN(2*step, pos); - }while(step); - - if(!code) //nothing found, not even after pos_arg - return AV_NOPTS_VALUE; - - url_fseek(bc, -8, SEEK_CUR); - for(i=0; inb_streams; i++) - nut->stream[i].last_sync_pos= url_ftell(bc); - - for(;;){ - int frame_type=0; - int64_t pos= url_ftell(bc); - uint64_t tmp=0; - - if(pos > pos_limit || url_feof(bc)) - return AV_NOPTS_VALUE; - - frame_code = get_byte(bc); - if(frame_code == 'N'){ - tmp= frame_code; - for(i=1; i<8; i++) - tmp = (tmp<<8) + get_byte(bc); - } -//av_log(s, AV_LOG_DEBUG, "before switch %"PRIX64" at=%"PRId64"\n", tmp, pos); - - switch(tmp){ - case MAIN_STARTCODE: - case STREAM_STARTCODE: - case INDEX_STARTCODE: - case INFO_STARTCODE: - get_packetheader(nut, bc, 0); - assert(nut->packet_start[2]==pos); - url_fseek(bc, nut->written_packet_size, SEEK_CUR); - break; - case KEYFRAME_STARTCODE: - frame_type=2; - reset(s, get_v(bc)); - frame_code = get_byte(bc); - case 0: - size= decode_frame_header(nut, &key_frame, &pts, &stream_id, frame_code, frame_type, pos); - if(size < 0) - goto resync; - - stream= &nut->stream[stream_id]; - if(stream_id != stream_index || !key_frame || pos < *pos_arg){ - url_fseek(bc, size, SEEK_CUR); - break; - } - - *pos_arg= pos; - return pts; - default: -resync: -av_log(s, AV_LOG_DEBUG, "syncing from %"PRId64"\n", nut->packet_start[2]+1); - if(!find_any_startcode(bc, nut->packet_start[2]+1)) - return AV_NOPTS_VALUE; - - url_fseek(bc, -8, SEEK_CUR); - } - } - return AV_NOPTS_VALUE; -} - -static int nut_read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){ -// NUTContext *nut = s->priv_data; - int64_t pos; - - if(av_seek_frame_binary(s, stream_index, target_ts, flags) < 0) - return -1; - - pos= url_ftell(&s->pb); - nut_read_timestamp(s, stream_index, &pos, pos-1); - - return 0; -} - -static int nut_read_close(AVFormatContext *s) -{ - NUTContext *nut = s->priv_data; - - av_freep(&nut->stream); - - return 0; -} - -#ifdef CONFIG_NUT_DEMUXER -AVInputFormat nut_demuxer = { - "nut", - "nut format", - sizeof(NUTContext), - nut_probe, - nut_read_header, - nut_read_packet, - nut_read_close, - nut_read_seek, - nut_read_timestamp, - .extensions = "nut", -}; -#endif -#ifdef CONFIG_NUT_MUXER -AVOutputFormat nut_muxer = { - "nut", - "nut format", - "video/x-nut", - "nut", - sizeof(NUTContext), -#ifdef CONFIG_LIBVORBIS - CODEC_ID_VORBIS, -#elif defined(CONFIG_LIBMP3LAME) - CODEC_ID_MP3, -#else - CODEC_ID_MP2, /* AC3 needs liba52 decoder */ -#endif - CODEC_ID_MPEG4, - nut_write_header, - nut_write_packet, - nut_write_trailer, - .flags = AVFMT_GLOBALHEADER, -}; -#endif diff --git a/contrib/ffmpeg/libavformat/nut.h b/contrib/ffmpeg/libavformat/nut.h index 82bbf6f17..943914603 100644 --- a/contrib/ffmpeg/libavformat/nut.h +++ b/contrib/ffmpeg/libavformat/nut.h @@ -17,12 +17,13 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ +#ifndef FFMPEG_NUT_H +#define FFMPEG_NUT_H + //#include #include "avformat.h" -#include "crc.h" //#include "mpegaudio.h" #include "riff.h" //#include "adler32.h" @@ -43,10 +44,12 @@ typedef enum{ FLAG_CODED_PTS = 8, /// startcode less, 1-> short startcode 2-> long startcodes +// int64_t packet_start; FrameCode frame_code[256]; - uint64_t next_startcode; ///< stores the next startcode if it has alraedy been parsed but the stream isnt seekable + uint8_t header_len[128]; + const uint8_t *header[128]; + uint64_t next_startcode; ///< stores the next startcode if it has already been parsed but the stream is not seekable StreamContext *stream; unsigned int max_distance; unsigned int time_base_count; int64_t last_syncpoint_pos; + int header_count; AVRational *time_base; struct AVTreeNode *syncpoints; } NUTContext; +void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val); +int64_t ff_lsb2full(StreamContext *stream, int64_t lsb); +int ff_nut_sp_pos_cmp(syncpoint_t *a, syncpoint_t *b); +int ff_nut_sp_pts_cmp(syncpoint_t *a, syncpoint_t *b); +void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts); -//FIXME move to a common spot, like crc.c/h -static unsigned long av_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len){ - return av_crc(av_crc04C11DB7, checksum, buf, len); -} +#endif /* FFMPEG_NUT_H */ diff --git a/contrib/ffmpeg/libavformat/nutdec.c b/contrib/ffmpeg/libavformat/nutdec.c index c0f331c27..e072e7ed7 100644 --- a/contrib/ffmpeg/libavformat/nutdec.c +++ b/contrib/ffmpeg/libavformat/nutdec.c @@ -18,28 +18,17 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ #include "tree.h" #include "nut.h" +#include "avstring.h" #undef NDEBUG #include -static uint64_t get_v(ByteIOContext *bc){ - uint64_t val = 0; - int tmp; - - do{ - tmp = get_byte(bc); - val= (val<<7) + (tmp&127); - }while(tmp&128); - return val; -} - static int get_str(ByteIOContext *bc, char *string, unsigned int maxlen){ - unsigned int len= get_v(bc); + unsigned int len= ff_get_v(bc); if(len && maxlen) get_buffer(bc, string, FFMIN(len, maxlen)); @@ -58,14 +47,14 @@ static int get_str(ByteIOContext *bc, char *string, unsigned int maxlen){ } static int64_t get_s(ByteIOContext *bc){ - int64_t v = get_v(bc) + 1; + int64_t v = ff_get_v(bc) + 1; if (v&1) return -(v>>1); else return (v>>1); } static uint64_t get_fourcc(ByteIOContext *bc){ - unsigned int len= get_v(bc); + unsigned int len= ff_get_v(bc); if (len==2) return get_le16(bc); else if(len==4) return get_le32(bc); @@ -74,43 +63,46 @@ static uint64_t get_fourcc(ByteIOContext *bc){ #ifdef TRACE static inline uint64_t get_v_trace(ByteIOContext *bc, char *file, char *func, int line){ - uint64_t v= get_v(bc); + uint64_t v= ff_get_v(bc); - printf("get_v %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); + av_log(NULL, AV_LOG_DEBUG, "get_v %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); return v; } static inline int64_t get_s_trace(ByteIOContext *bc, char *file, char *func, int line){ int64_t v= get_s(bc); - printf("get_s %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); + av_log(NULL, AV_LOG_DEBUG, "get_s %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); return v; } static inline uint64_t get_vb_trace(ByteIOContext *bc, char *file, char *func, int line){ uint64_t v= get_vb(bc); - printf("get_vb %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); + av_log(NULL, AV_LOG_DEBUG, "get_vb %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); return v; } -#define get_v(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__) +#define ff_get_v(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define get_s(bc) get_s_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define get_vb(bc) get_vb_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__) #endif -static int get_packetheader(NUTContext *nut, ByteIOContext *bc, int calculate_checksum) +static int get_packetheader(NUTContext *nut, ByteIOContext *bc, int calculate_checksum, uint64_t startcode) { - int64_t start, size; + int64_t size; // start= url_ftell(bc) - 8; - size= get_v(bc); - if(size > 4096) - get_be32(bc); //FIXME check this + startcode= be2me_64(startcode); + startcode= ff_crc04C11DB7_update(0, &startcode, 8); - init_checksum(bc, calculate_checksum ? av_crc04C11DB7_update : NULL, 0); + init_checksum(bc, ff_crc04C11DB7_update, startcode); + size= ff_get_v(bc); + if(size > 4096) + get_be32(bc); + if(get_checksum(bc) && size > 4096) + return -1; -// nut->packet_start[2] = start; -// nut->written_packet_size= size; + init_checksum(bc, calculate_checksum ? ff_crc04C11DB7_update : NULL, 0); return size; } @@ -119,7 +111,7 @@ static uint64_t find_any_startcode(ByteIOContext *bc, int64_t pos){ uint64_t state=0; if(pos >= 0) - url_fseek(bc, pos, SEEK_SET); //note, this may fail if the stream isnt seekable, but that shouldnt matter, as in this case we simply start where we are currently + url_fseek(bc, pos, SEEK_SET); //note, this may fail if the stream is not seekable, but that should not matter, as in this case we simply start where we are currently while(!url_feof(bc)){ state= (state<<8) | get_byte(bc); @@ -139,7 +131,7 @@ static uint64_t find_any_startcode(ByteIOContext *bc, int64_t pos){ } /** - * find the given startcode. + * Find the given startcode. * @param code the startcode * @param pos the start position of the search, or -1 if the current position * @returns the position of the startcode or -1 if not found @@ -155,12 +147,6 @@ static int64_t find_startcode(ByteIOContext *bc, uint64_t code, int64_t pos){ } } -static int64_t lsb2full(StreamContext *stream, int64_t lsb){ - int64_t mask = (1<msb_pts_shift)-1; - int64_t delta= stream->last_pts - mask/2; - return ((lsb - delta)&mask) + delta; -} - static int nut_probe(AVProbeData *p){ int i; uint64_t code= 0; @@ -174,7 +160,7 @@ static int nut_probe(AVProbeData *p){ } #define GET_V(dst, check) \ - tmp= get_v(bc);\ + tmp= ff_get_v(bc);\ if(!(check)){\ av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp);\ return -1;\ @@ -195,18 +181,19 @@ static int skip_reserved(ByteIOContext *bc, int64_t pos){ static int decode_main_header(NUTContext *nut){ AVFormatContext *s= nut->avf; - ByteIOContext *bc = &s->pb; + ByteIOContext *bc = s->pb; uint64_t tmp, end; unsigned int stream_count; - int i, j, tmp_stream, tmp_mul, tmp_pts, tmp_size, count, tmp_res; + int i, j, tmp_stream, tmp_mul, tmp_pts, tmp_size, count, tmp_res, tmp_head_idx; + int64_t tmp_match; - end= get_packetheader(nut, bc, 1); + end= get_packetheader(nut, bc, 1, MAIN_STARTCODE); end += url_ftell(bc); GET_V(tmp , tmp >=2 && tmp <= 3) GET_V(stream_count , tmp > 0 && tmp <=MAX_STREAMS) - nut->max_distance = get_v(bc); + nut->max_distance = ff_get_v(bc); if(nut->max_distance > 65536){ av_log(s, AV_LOG_DEBUG, "max_distance %d\n", nut->max_distance); nut->max_distance= 65536; @@ -226,21 +213,25 @@ static int decode_main_header(NUTContext *nut){ tmp_pts=0; tmp_mul=1; tmp_stream=0; + tmp_match= 1-(1LL<<62); + tmp_head_idx= 0; for(i=0; i<256;){ - int tmp_flags = get_v(bc); - int tmp_fields= get_v(bc); + int tmp_flags = ff_get_v(bc); + int tmp_fields= ff_get_v(bc); if(tmp_fields>0) tmp_pts = get_s(bc); - if(tmp_fields>1) tmp_mul = get_v(bc); - if(tmp_fields>2) tmp_stream= get_v(bc); - if(tmp_fields>3) tmp_size = get_v(bc); + if(tmp_fields>1) tmp_mul = ff_get_v(bc); + if(tmp_fields>2) tmp_stream= ff_get_v(bc); + if(tmp_fields>3) tmp_size = ff_get_v(bc); else tmp_size = 0; - if(tmp_fields>4) tmp_res = get_v(bc); + if(tmp_fields>4) tmp_res = ff_get_v(bc); else tmp_res = 0; - if(tmp_fields>5) count = get_v(bc); + if(tmp_fields>5) count = ff_get_v(bc); else count = tmp_mul - tmp_size; + if(tmp_fields>6) tmp_match = get_s(bc); + if(tmp_fields>7) tmp_head_idx= ff_get_v(bc); - while(tmp_fields-- > 6) - get_v(bc); + while(tmp_fields-- > 8) + ff_get_v(bc); if(count == 0 || i+count > 256){ av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i); @@ -263,12 +254,30 @@ static int decode_main_header(NUTContext *nut){ nut->frame_code[i].size_mul = tmp_mul ; nut->frame_code[i].size_lsb = tmp_size+j; nut->frame_code[i].reserved_count = tmp_res ; + nut->frame_code[i].header_idx = tmp_head_idx; } } assert(nut->frame_code['N'].flags == FLAG_INVALID); + if(end > url_ftell(bc) + 4){ + int rem= 1024; + GET_V(nut->header_count, tmp<128U) + nut->header_count++; + for(i=1; iheader_count; i++){ + GET_V(nut->header_len[i], tmp>0 && tmp<256); + rem -= nut->header_len[i]; + if(rem < 0){ + av_log(s, AV_LOG_ERROR, "invalid elision header\n"); + return -1; + } + nut->header[i]= av_malloc(nut->header_len[i]); + get_buffer(bc, nut->header[i], nut->header_len[i]); + } + assert(nut->header_len[0]==0); + } + if(skip_reserved(bc, end) || get_checksum(bc)){ - av_log(s, AV_LOG_ERROR, "Main header checksum mismatch\n"); + av_log(s, AV_LOG_ERROR, "main header checksum mismatch\n"); return -1; } @@ -282,36 +291,36 @@ static int decode_main_header(NUTContext *nut){ static int decode_stream_header(NUTContext *nut){ AVFormatContext *s= nut->avf; - ByteIOContext *bc = &s->pb; + ByteIOContext *bc = s->pb; StreamContext *stc; int class, stream_id; uint64_t tmp, end; AVStream *st; - end= get_packetheader(nut, bc, 1); + end= get_packetheader(nut, bc, 1, STREAM_STARTCODE); end += url_ftell(bc); - GET_V(stream_id, tmp < s->nb_streams && !nut->stream[tmp].time_base.num); + GET_V(stream_id, tmp < s->nb_streams && !nut->stream[tmp].time_base); stc= &nut->stream[stream_id]; st = s->streams[stream_id]; if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); - class = get_v(bc); + class = ff_get_v(bc); tmp = get_fourcc(bc); st->codec->codec_tag= tmp; switch(class) { case 0: st->codec->codec_type = CODEC_TYPE_VIDEO; - st->codec->codec_id = codec_get_bmp_id(tmp); + st->codec->codec_id = codec_get_id(codec_bmp_tags, tmp); if (st->codec->codec_id == CODEC_ID_NONE) av_log(s, AV_LOG_ERROR, "Unknown codec?!\n"); break; case 1: st->codec->codec_type = CODEC_TYPE_AUDIO; - st->codec->codec_id = codec_get_wav_id(tmp); + st->codec->codec_id = codec_get_id(codec_wav_tags, tmp); if (st->codec->codec_id == CODEC_ID_NONE) av_log(s, AV_LOG_ERROR, "Unknown codec?!\n"); break; @@ -322,15 +331,15 @@ static int decode_stream_header(NUTContext *nut){ st->codec->codec_type = CODEC_TYPE_DATA; break; default: - av_log(s, AV_LOG_ERROR, "Unknown stream class (%d)\n", class); + av_log(s, AV_LOG_ERROR, "unknown stream class (%d)\n", class); return -1; } GET_V(stc->time_base_id , tmp < nut->time_base_count); GET_V(stc->msb_pts_shift , tmp < 16); - stc->max_pts_distance= get_v(bc); - GET_V(stc->decode_delay , tmp < 1000); //sanity limit, raise this if moors law is true + stc->max_pts_distance= ff_get_v(bc); + GET_V(stc->decode_delay , tmp < 1000); //sanity limit, raise this if Moore's law is true st->codec->has_b_frames= stc->decode_delay; - get_v(bc); //stream flags + ff_get_v(bc); //stream flags GET_V(st->codec->extradata_size, tmp < (1<<30)); if(st->codec->extradata_size){ @@ -341,48 +350,45 @@ static int decode_stream_header(NUTContext *nut){ if (st->codec->codec_type == CODEC_TYPE_VIDEO){ GET_V(st->codec->width , tmp > 0) GET_V(st->codec->height, tmp > 0) - st->codec->sample_aspect_ratio.num= get_v(bc); - st->codec->sample_aspect_ratio.den= get_v(bc); + st->codec->sample_aspect_ratio.num= ff_get_v(bc); + st->codec->sample_aspect_ratio.den= ff_get_v(bc); if((!st->codec->sample_aspect_ratio.num) != (!st->codec->sample_aspect_ratio.den)){ - av_log(s, AV_LOG_ERROR, "invalid aspect ratio\n"); + av_log(s, AV_LOG_ERROR, "invalid aspect ratio %d/%d\n", st->codec->sample_aspect_ratio.num, st->codec->sample_aspect_ratio.den); return -1; } - get_v(bc); /* csp type */ + ff_get_v(bc); /* csp type */ }else if (st->codec->codec_type == CODEC_TYPE_AUDIO){ GET_V(st->codec->sample_rate , tmp > 0) - tmp= get_v(bc); // samplerate_den - if(tmp > st->codec->sample_rate){ - av_log(s, AV_LOG_ERROR, "bleh, libnut muxed this ;)\n"); - st->codec->sample_rate= tmp; - } + ff_get_v(bc); // samplerate_den GET_V(st->codec->channels, tmp > 0) } if(skip_reserved(bc, end) || get_checksum(bc)){ - av_log(s, AV_LOG_ERROR, "Stream header %d checksum mismatch\n", stream_id); + av_log(s, AV_LOG_ERROR, "stream header %d checksum mismatch\n", stream_id); return -1; } - stc->time_base= nut->time_base[stc->time_base_id]; - av_set_pts_info(s->streams[stream_id], 63, stc->time_base.num, stc->time_base.den); + stc->time_base= &nut->time_base[stc->time_base_id]; + av_set_pts_info(s->streams[stream_id], 63, stc->time_base->num, stc->time_base->den); return 0; } static int decode_info_header(NUTContext *nut){ AVFormatContext *s= nut->avf; - ByteIOContext *bc = &s->pb; + ByteIOContext *bc = s->pb; uint64_t tmp; unsigned int stream_id_plus1, chapter_start, chapter_len, count; int chapter_id, i; int64_t value, end; - char name[256], str_value[1024], type_str[256], *type= type_str; + char name[256], str_value[1024], type_str[256]; + const char *type; - end= get_packetheader(nut, bc, 1); + end= get_packetheader(nut, bc, 1, INFO_STARTCODE); end += url_ftell(bc); GET_V(stream_id_plus1, tmp <= s->nb_streams) chapter_id = get_s(bc); - chapter_start= get_v(bc); - chapter_len = get_v(bc); - count = get_v(bc); + chapter_start= ff_get_v(bc); + chapter_len = ff_get_v(bc); + count = ff_get_v(bc); for(i=0; iauthor , sizeof(s->author) , str_value); + av_strlcpy(s->author , str_value, sizeof(s->author)); else if(!strcmp(name, "Title")) - pstrcpy(s->title , sizeof(s->title) , str_value); + av_strlcpy(s->title , str_value, sizeof(s->title)); else if(!strcmp(name, "Copyright")) - pstrcpy(s->copyright, sizeof(s->copyright), str_value); + av_strlcpy(s->copyright, str_value, sizeof(s->copyright)); else if(!strcmp(name, "Description")) - pstrcpy(s->comment , sizeof(s->comment) , str_value); + av_strlcpy(s->comment , str_value, sizeof(s->comment)); } } if(skip_reserved(bc, end) || get_checksum(bc)){ - av_log(s, AV_LOG_ERROR, "Info header checksum mismatch\n"); + av_log(s, AV_LOG_ERROR, "info header checksum mismatch\n"); return -1; } return 0; } -int sp_pos_cmp(syncpoint_t *a, syncpoint_t *b){ - return (a->pos - b->pos>>32) - (b->pos - a->pos>>32); -} - -int sp_pts_cmp(syncpoint_t *a, syncpoint_t *b){ - return (a->ts - b->ts>>32) - (b->ts - a->ts>>32); -} - -static void add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts){ - syncpoint_t *sp2, *sp= av_mallocz(sizeof(syncpoint_t)); - - sp->pos= pos; - sp->back_ptr= back_ptr; - sp->ts= ts; - sp2= av_tree_insert(&nut->syncpoints, sp, sp_pos_cmp); - if(sp2 && sp2 != sp) - av_free(sp); -} - static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr){ AVFormatContext *s= nut->avf; - ByteIOContext *bc = &s->pb; + ByteIOContext *bc = s->pb; int64_t end, tmp; - int i; - AVRational time_base; nut->last_syncpoint_pos= url_ftell(bc)-8; - end= get_packetheader(nut, bc, 1); + end= get_packetheader(nut, bc, 1, SYNCPOINT_STARTCODE); end += url_ftell(bc); - tmp= get_v(bc); - *back_ptr= nut->last_syncpoint_pos - 16*get_v(bc); + tmp= ff_get_v(bc); + *back_ptr= nut->last_syncpoint_pos - 16*ff_get_v(bc); if(*back_ptr < 0) return -1; - time_base= nut->time_base[tmp % nut->time_base_count]; - for(i=0; inb_streams; i++){ - nut->stream[i].last_pts= av_rescale_rnd( - tmp / nut->time_base_count, - time_base.num * (int64_t)nut->stream[i].time_base.den, - time_base.den * (int64_t)nut->stream[i].time_base.num, - AV_ROUND_DOWN); - //last_key_frame ? - } - //FIXME put this in a reset func maybe + ff_nut_reset_ts(nut, nut->time_base[tmp % nut->time_base_count], tmp / nut->time_base_count); if(skip_reserved(bc, end) || get_checksum(bc)){ av_log(s, AV_LOG_ERROR, "sync point checksum mismatch\n"); @@ -477,14 +454,14 @@ static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr){ } *ts= tmp / s->nb_streams * av_q2d(nut->time_base[tmp % s->nb_streams])*AV_TIME_BASE; - add_sp(nut, nut->last_syncpoint_pos, *back_ptr, *ts); + ff_nut_add_sp(nut, nut->last_syncpoint_pos, *back_ptr, *ts); return 0; } static int find_and_decode_index(NUTContext *nut){ AVFormatContext *s= nut->avf; - ByteIOContext *bc = &s->pb; + ByteIOContext *bc = s->pb; uint64_t tmp, end; int i, j, syncpoint_count; int64_t filesize= url_fsize(bc); @@ -498,10 +475,10 @@ static int find_and_decode_index(NUTContext *nut){ return -1; } - end= get_packetheader(nut, bc, 1); + end= get_packetheader(nut, bc, 1, INDEX_STARTCODE); end += url_ftell(bc); - get_v(bc); //max_pts + ff_get_v(bc); //max_pts GET_V(syncpoint_count, tmp < INT_MAX/8 && tmp > 0) syncpoints= av_malloc(sizeof(int64_t)*syncpoint_count); has_keyframe= av_malloc(sizeof(int8_t)*(syncpoint_count+1)); @@ -514,7 +491,7 @@ static int find_and_decode_index(NUTContext *nut){ for(i=0; inb_streams; i++){ int64_t last_pts= -1; for(j=0; j>=1; @@ -543,12 +520,12 @@ static int find_and_decode_index(NUTContext *nut){ return -1; } assert(n<=syncpoint_count+1); - for(; jpriv_data; - ByteIOContext *bc = &s->pb; + ByteIOContext *bc = s->pb; int64_t pos; - int inited_stream_count; + int initialized_stream_count; nut->avf= s; @@ -586,21 +563,21 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap) do{ pos= find_startcode(bc, MAIN_STARTCODE, pos)+1; if (pos<0+1){ - av_log(s, AV_LOG_ERROR, "no main startcode found\n"); + av_log(s, AV_LOG_ERROR, "No main startcode found.\n"); return -1; } }while(decode_main_header(nut) < 0); /* stream headers */ pos=0; - for(inited_stream_count=0; inited_stream_count < s->nb_streams;){ + for(initialized_stream_count=0; initialized_stream_count < s->nb_streams;){ pos= find_startcode(bc, STREAM_STARTCODE, pos)+1; if (pos<0+1){ - av_log(s, AV_LOG_ERROR, "not all stream headers found\n"); + av_log(s, AV_LOG_ERROR, "Not all stream headers found.\n"); return -1; } if(decode_stream_header(nut) >= 0) - inited_stream_count++; + initialized_stream_count++; } /* info headers */ @@ -634,15 +611,15 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap) return 0; } -static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id, int frame_code){ +static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id, uint8_t *header_idx, int frame_code){ AVFormatContext *s= nut->avf; - ByteIOContext *bc = &s->pb; + ByteIOContext *bc = s->pb; StreamContext *stc; int size, flags, size_mul, pts_delta, i, reserved_count; uint64_t tmp; if(url_ftell(bc) > nut->last_syncpoint_pos + nut->max_distance){ - av_log(s, AV_LOG_ERROR, "last frame must have been damaged %Ld > %Ld + %d\n", url_ftell(bc), nut->last_syncpoint_pos, nut->max_distance); + av_log(s, AV_LOG_ERROR, "Last frame must have been damaged %"PRId64" > %"PRId64" + %d\n", url_ftell(bc), nut->last_syncpoint_pos, nut->max_distance); return -1; } @@ -652,31 +629,45 @@ static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id, in *stream_id = nut->frame_code[frame_code].stream_id; pts_delta = nut->frame_code[frame_code].pts_delta; reserved_count = nut->frame_code[frame_code].reserved_count; + *header_idx = nut->frame_code[frame_code].header_idx; if(flags & FLAG_INVALID) return -1; if(flags & FLAG_CODED) - flags ^= get_v(bc); + flags ^= ff_get_v(bc); if(flags & FLAG_STREAM_ID){ GET_V(*stream_id, tmp < s->nb_streams) } stc= &nut->stream[*stream_id]; if(flags&FLAG_CODED_PTS){ - int coded_pts= get_v(bc); + int coded_pts= ff_get_v(bc); //FIXME check last_pts validity? if(coded_pts < (1<msb_pts_shift)){ - *pts=lsb2full(stc, coded_pts); + *pts=ff_lsb2full(stc, coded_pts); }else *pts=coded_pts - (1<msb_pts_shift); }else *pts= stc->last_pts + pts_delta; if(flags&FLAG_SIZE_MSB){ - size += size_mul*get_v(bc); + size += size_mul*ff_get_v(bc); } + if(flags&FLAG_MATCH_TIME) + get_s(bc); + if(flags&FLAG_HEADER_IDX) + *header_idx= ff_get_v(bc); if(flags&FLAG_RESERVED) - reserved_count= get_v(bc); + reserved_count= ff_get_v(bc); for(i=0; i= (unsigned)nut->header_count){ + av_log(s, AV_LOG_ERROR, "header_idx invalid\n"); + return -1; + } + if(size > 4096) + *header_idx=0; + size -= nut->header_len[*header_idx]; + if(flags&FLAG_CHECKSUM){ get_be32(bc); //FIXME check this }else if(size > 2*nut->max_distance || FFABS(stc->last_pts - *pts) > stc->max_pts_distance){ @@ -692,12 +683,13 @@ static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id, in static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code){ AVFormatContext *s= nut->avf; - ByteIOContext *bc = &s->pb; + ByteIOContext *bc = s->pb; int size, stream_id, discard; int64_t pts, last_IP_pts; StreamContext *stc; + uint8_t header_idx; - size= decode_frame_header(nut, &pts, &stream_id, frame_code); + size= decode_frame_header(nut, &pts, &stream_id, &header_idx, frame_code); if(size < 0) return -1; @@ -716,7 +708,11 @@ static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code){ return 1; } - av_get_packet(bc, pkt, size); + av_new_packet(pkt, size + nut->header_len[header_idx]); + memcpy(pkt->data, nut->header[header_idx], nut->header_len[header_idx]); + pkt->pos= url_ftell(bc); //FIXME + get_buffer(bc, pkt->data + nut->header_len[header_idx], size); + pkt->stream_index = stream_id; if (stc->last_flags & FLAG_KEY) pkt->flags |= PKT_FLAG_KEY; @@ -728,7 +724,7 @@ static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code){ static int nut_read_packet(AVFormatContext *s, AVPacket *pkt) { NUTContext *nut = s->priv_data; - ByteIOContext *bc = &s->pb; + ByteIOContext *bc = s->pb; int i, frame_code=0, ret, skip; int64_t ts, back_ptr; @@ -753,7 +749,7 @@ static int nut_read_packet(AVFormatContext *s, AVPacket *pkt) case MAIN_STARTCODE: case STREAM_STARTCODE: case INDEX_STARTCODE: - skip= get_packetheader(nut, bc, 0); + skip= get_packetheader(nut, bc, 0, tmp); url_fseek(bc, skip, SEEK_CUR); break; case INFO_STARTCODE: @@ -784,24 +780,23 @@ av_log(s, AV_LOG_DEBUG, "sync\n"); static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos_arg, int64_t pos_limit){ NUTContext *nut = s->priv_data; - ByteIOContext *bc = &s->pb; + ByteIOContext *bc = s->pb; int64_t pos, pts, back_ptr; av_log(s, AV_LOG_DEBUG, "read_timestamp(X,%d,%"PRId64",%"PRId64")\n", stream_index, *pos_arg, pos_limit); pos= *pos_arg; -resync: do{ pos= find_startcode(bc, SYNCPOINT_STARTCODE, pos)+1; if(pos < 1){ assert(nut->next_startcode == 0); - av_log(s, AV_LOG_ERROR, "read_timestamp failed\n"); + av_log(s, AV_LOG_ERROR, "read_timestamp failed.\n"); return AV_NOPTS_VALUE; } }while(decode_syncpoint(nut, &pts, &back_ptr) < 0); *pos_arg = pos-1; assert(nut->last_syncpoint_pos == *pos_arg); - av_log(s, AV_LOG_DEBUG, "return %Ld %Ld\n", pts,back_ptr ); + av_log(s, AV_LOG_DEBUG, "return %"PRId64" %"PRId64"\n", pts,back_ptr ); if (stream_index == -1) return pts; else if(stream_index == -2) return back_ptr; @@ -825,8 +820,8 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flag pos2= st->index_entries[index].pos; ts = st->index_entries[index].timestamp; }else{ - av_tree_find(nut->syncpoints, &dummy, sp_pts_cmp, next_node); - av_log(s, AV_LOG_DEBUG, "%Ld-%Ld %Ld-%Ld\n", next_node[0]->pos, next_node[1]->pos, + av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pts_cmp, next_node); + av_log(s, AV_LOG_DEBUG, "%"PRIu64"-%"PRIu64" %"PRId64"-%"PRId64"\n", next_node[0]->pos, next_node[1]->pos, next_node[0]->ts , next_node[1]->ts); pos= av_gen_search(s, -1, dummy.ts, next_node[0]->pos, next_node[1]->pos, next_node[1]->pos, next_node[0]->ts , next_node[1]->ts, AVSEEK_FLAG_BACKWARD, &ts, nut_read_timestamp); @@ -834,22 +829,22 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flag if(!(flags & AVSEEK_FLAG_BACKWARD)){ dummy.pos= pos+16; next_node[1]= &nopts_sp; - av_tree_find(nut->syncpoints, &dummy, sp_pos_cmp, next_node); + av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, next_node); pos2= av_gen_search(s, -2, dummy.pos, next_node[0]->pos , next_node[1]->pos, next_node[1]->pos, next_node[0]->back_ptr, next_node[1]->back_ptr, flags, &ts, nut_read_timestamp); if(pos2>=0) pos= pos2; - //FIXME dir but i think it doesnt matter + //FIXME dir but i think it does not matter } dummy.pos= pos; - sp= av_tree_find(nut->syncpoints, &dummy, sp_pos_cmp, NULL); + sp= av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, NULL); assert(sp); pos2= sp->back_ptr - 15; } av_log(NULL, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos2); - pos= find_startcode(&s->pb, SYNCPOINT_STARTCODE, pos2); - url_fseek(&s->pb, pos, SEEK_SET); + pos= find_startcode(s->pb, SYNCPOINT_STARTCODE, pos2); + url_fseek(s->pb, pos, SEEK_SET); av_log(NULL, AV_LOG_DEBUG, "SP: %"PRId64"\n", pos); if(pos2 > pos || pos2 + 15 < pos){ av_log(NULL, AV_LOG_ERROR, "no syncpoint at backptr pos\n"); diff --git a/contrib/ffmpeg/libavformat/nutenc.c b/contrib/ffmpeg/libavformat/nutenc.c new file mode 100644 index 000000000..5c0975c28 --- /dev/null +++ b/contrib/ffmpeg/libavformat/nutenc.c @@ -0,0 +1,775 @@ +/* + * nut muxer + * Copyright (c) 2004-2007 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "nut.h" +#include "tree.h" +#include "mpegaudiodata.h" + +static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint8_t out[64]){ + int sample_rate= c->sample_rate; + + if(size>4096) + return 0; + + AV_WB24(out, 1); + + if(c->codec_id == CODEC_ID_MPEG4){ + if(key_frame){ + return 3; + }else{ + out[3]= 0xB6; + return 4; + } + }else if(c->codec_id == CODEC_ID_MPEG1VIDEO || c->codec_id == CODEC_ID_MPEG2VIDEO){ + return 3; + }else if(c->codec_id == CODEC_ID_H264){ + return 3; + }else if(c->codec_id == CODEC_ID_MP3 || c->codec_id == CODEC_ID_MP2){ + int lsf, mpeg25, sample_rate_index, bitrate_index, frame_size; + int layer= c->codec_id == CODEC_ID_MP3 ? 3 : 2; + unsigned int header= 0xFFF00000; + + lsf = sample_rate < (24000+32000)/2; + mpeg25 = sample_rate < (12000+16000)/2; + sample_rate <<= lsf + mpeg25; + if (sample_rate < (32000 + 44100)/2) sample_rate_index=2; + else if(sample_rate < (44100 + 48000)/2) sample_rate_index=0; + else sample_rate_index=1; + + sample_rate= ff_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); + + for(bitrate_index=2; bitrate_index<30; bitrate_index++){ + frame_size = ff_mpa_bitrate_tab[lsf][layer-1][bitrate_index>>1]; + frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1); + + if(frame_size == size) + break; + } + + header |= (!lsf)<<19; + header |= (4-layer)<<17; + header |= 1<<16; //no crc + AV_WB32(out, header); + if(size <= 0) + return 2; //we guess theres no crc, if there is one the user clearly doesnt care about overhead + if(bitrate_index == 30) + return -1; //something is wrong ... + + header |= (bitrate_index>>1)<<12; + header |= sample_rate_index<<10; + header |= (bitrate_index&1)<<9; + + return 2; //FIXME actually put the needed ones in build_elision_headers() + return 3; //we guess that the private bit isnt set +//FIXME the above asumtations should be checked, if these turn out false too often something should be done + } + return 0; +} + +static int find_header_idx(AVFormatContext *s, AVCodecContext *c, int size, int frame_type){ + NUTContext *nut = s->priv_data; + uint8_t out[64]; + int i; + int len= find_expected_header(c, size, frame_type, out); + +//av_log(NULL, AV_LOG_ERROR, "expected_h len=%d size=%d codec_id=%d\n", len, size, c->codec_id); + + for(i=1; iheader_count; i++){ + if( len == nut->header_len[i] + && !memcmp(out, nut->header[i], len)){ +// av_log(NULL, AV_LOG_ERROR, "found %d\n", i); + return i; + } + } +// av_log(NULL, AV_LOG_ERROR, "nothing found\n"); + return 0; +} + +static void build_elision_headers(AVFormatContext *s){ + NUTContext *nut = s->priv_data; + int i; + //FIXME this is lame + //FIXME write a 2pass mode to find the maximal headers + const static uint8_t headers[][5]={ + {3, 0x00, 0x00, 0x01}, + {4, 0x00, 0x00, 0x01, 0xB6}, + {2, 0xFF, 0xFA}, //mp3+crc + {2, 0xFF, 0xFB}, //mp3 + {2, 0xFF, 0xFC}, //mp2+crc + {2, 0xFF, 0xFD}, //mp2 + }; + + nut->header_count= 7; + for(i=1; iheader_count; i++){ + nut->header_len[i]= headers[i-1][0]; + nut->header [i]= &headers[i-1][1]; + } +} + +static void build_frame_code(AVFormatContext *s){ + NUTContext *nut = s->priv_data; + int key_frame, index, pred, stream_id; + int start=1; + int end= 254; + int keyframe_0_esc= s->nb_streams > 2; + int pred_table[10]; + FrameCode *ft; + + ft= &nut->frame_code[start]; + ft->flags= FLAG_CODED; + ft->size_mul=1; + ft->pts_delta=1; + start++; + + if(keyframe_0_esc){ + /* keyframe = 0 escape */ + FrameCode *ft= &nut->frame_code[start]; + ft->flags= FLAG_STREAM_ID | FLAG_SIZE_MSB | FLAG_CODED_PTS; + ft->size_mul=1; + start++; + } + + for(stream_id= 0; stream_idnb_streams; stream_id++){ + int start2= start + (end-start)*stream_id / s->nb_streams; + int end2 = start + (end-start)*(stream_id+1) / s->nb_streams; + AVCodecContext *codec = s->streams[stream_id]->codec; + int is_audio= codec->codec_type == CODEC_TYPE_AUDIO; + int intra_only= /*codec->intra_only || */is_audio; + int pred_count; + + for(key_frame=0; key_frame<2; key_frame++){ + if(intra_only && keyframe_0_esc && key_frame==0) + continue; + + { + FrameCode *ft= &nut->frame_code[start2]; + ft->flags= FLAG_KEY*key_frame; + ft->flags|= FLAG_SIZE_MSB | FLAG_CODED_PTS; + ft->stream_id= stream_id; + ft->size_mul=1; + if(is_audio) + ft->header_idx= find_header_idx(s, codec, -1, key_frame); + start2++; + } + } + + key_frame= intra_only; +#if 1 + if(is_audio){ + int frame_bytes= codec->frame_size*(int64_t)codec->bit_rate / (8*codec->sample_rate); + int pts; + for(pts=0; pts<2; pts++){ + for(pred=0; pred<2; pred++){ + FrameCode *ft= &nut->frame_code[start2]; + ft->flags= FLAG_KEY*key_frame; + ft->stream_id= stream_id; + ft->size_mul=frame_bytes + 2; + ft->size_lsb=frame_bytes + pred; + ft->pts_delta=pts; + ft->header_idx= find_header_idx(s, codec, frame_bytes + pred, key_frame); + start2++; + } + } + }else{ + FrameCode *ft= &nut->frame_code[start2]; + ft->flags= FLAG_KEY | FLAG_SIZE_MSB; + ft->stream_id= stream_id; + ft->size_mul=1; + ft->pts_delta=1; + start2++; + } +#endif + + if(codec->has_b_frames){ + pred_count=5; + pred_table[0]=-2; + pred_table[1]=-1; + pred_table[2]=1; + pred_table[3]=3; + pred_table[4]=4; + }else if(codec->codec_id == CODEC_ID_VORBIS){ + pred_count=3; + pred_table[0]=2; + pred_table[1]=9; + pred_table[2]=16; + }else{ + pred_count=1; + pred_table[0]=1; + } + + for(pred=0; predframe_code[index]; + ft->flags= FLAG_KEY*key_frame; + ft->flags|= FLAG_SIZE_MSB; + ft->stream_id= stream_id; +//FIXME use single byte size and pred from last + ft->size_mul= end3-start3; + ft->size_lsb= index - start3; + ft->pts_delta= pred_table[pred]; + if(is_audio) + ft->header_idx= find_header_idx(s, codec, -1, key_frame); + } + } + } + memmove(&nut->frame_code['N'+1], &nut->frame_code['N'], sizeof(FrameCode)*(255-'N')); + nut->frame_code[ 0].flags= + nut->frame_code[255].flags= + nut->frame_code['N'].flags= FLAG_INVALID; +} + +/** + * Gets the length in bytes which is needed to store val as v. + */ +static int get_length(uint64_t val){ + int i=1; + + while(val>>=7) + i++; + + return i; +} + +static void put_v(ByteIOContext *bc, uint64_t val){ + int i= get_length(val); + + while(--i>0) + put_byte(bc, 128 | (val>>(7*i))); + + put_byte(bc, val&127); +} + +static void put_t(NUTContext *nut, StreamContext *nus, ByteIOContext *bc, uint64_t val){ + val *= nut->time_base_count; + val += nus->time_base - nut->time_base; + put_v(bc, val); +} + +/** + * Stores a string as vb. + */ +static void put_str(ByteIOContext *bc, const char *string){ + int len= strlen(string); + + put_v(bc, len); + put_buffer(bc, string, len); +} + +static void put_s(ByteIOContext *bc, int64_t val){ + put_v(bc, 2*FFABS(val) - (val>0)); +} + +#ifdef TRACE +static inline void put_v_trace(ByteIOContext *bc, uint64_t v, char *file, char *func, int line){ + av_log(NULL, AV_LOG_DEBUG, "put_v %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); + + put_v(bc, v); +} + +static inline void put_s_trace(ByteIOContext *bc, int64_t v, char *file, char *func, int line){ + av_log(NULL, AV_LOG_DEBUG, "put_s %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); + + put_s(bc, v); +} +#define put_v(bc, v) put_v_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__) +#define put_s(bc, v) put_s_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__) +#endif + +//FIXME remove calculate_checksum +static void put_packet(NUTContext *nut, ByteIOContext *bc, ByteIOContext *dyn_bc, int calculate_checksum, uint64_t startcode){ + uint8_t *dyn_buf=NULL; + int dyn_size= url_close_dyn_buf(dyn_bc, &dyn_buf); + int forw_ptr= dyn_size + 4*calculate_checksum; + + if(forw_ptr > 4096) + init_checksum(bc, ff_crc04C11DB7_update, 0); + put_be64(bc, startcode); + put_v(bc, forw_ptr); + if(forw_ptr > 4096) + put_le32(bc, get_checksum(bc)); + + if(calculate_checksum) + init_checksum(bc, ff_crc04C11DB7_update, 0); + put_buffer(bc, dyn_buf, dyn_size); + if(calculate_checksum) + put_le32(bc, get_checksum(bc)); + + av_free(dyn_buf); +} + +static void write_mainheader(NUTContext *nut, ByteIOContext *bc){ + int i, j, tmp_pts, tmp_flags, tmp_stream, tmp_mul, tmp_size, tmp_fields, tmp_head_idx; + int64_t tmp_match; + + put_v(bc, 3); /* version */ + put_v(bc, nut->avf->nb_streams); + put_v(bc, nut->max_distance); + put_v(bc, nut->time_base_count); + + for(i=0; itime_base_count; i++){ + put_v(bc, nut->time_base[i].num); + put_v(bc, nut->time_base[i].den); + } + + tmp_pts=0; + tmp_mul=1; + tmp_stream=0; + tmp_match= 1-(1LL<<62); + tmp_head_idx= 0; + for(i=0; i<256;){ + tmp_fields=0; + tmp_size=0; +// tmp_res=0; + if(tmp_pts != nut->frame_code[i].pts_delta) tmp_fields=1; + if(tmp_mul != nut->frame_code[i].size_mul ) tmp_fields=2; + if(tmp_stream != nut->frame_code[i].stream_id) tmp_fields=3; + if(tmp_size != nut->frame_code[i].size_lsb ) tmp_fields=4; +// if(tmp_res != nut->frame_code[i].res ) tmp_fields=5; + if(tmp_head_idx!=nut->frame_code[i].header_idx)tmp_fields=8; + + tmp_pts = nut->frame_code[i].pts_delta; + tmp_flags = nut->frame_code[i].flags; + tmp_stream= nut->frame_code[i].stream_id; + tmp_mul = nut->frame_code[i].size_mul; + tmp_size = nut->frame_code[i].size_lsb; +// tmp_res = nut->frame_code[i].res; + tmp_head_idx= nut->frame_code[i].header_idx; + + for(j=0; i<256; j++,i++){ + if(i == 'N'){ + j--; + continue; + } + if(nut->frame_code[i].pts_delta != tmp_pts ) break; + if(nut->frame_code[i].flags != tmp_flags ) break; + if(nut->frame_code[i].stream_id != tmp_stream) break; + if(nut->frame_code[i].size_mul != tmp_mul ) break; + if(nut->frame_code[i].size_lsb != tmp_size+j) break; +// if(nut->frame_code[i].res != tmp_res ) break; + if(nut->frame_code[i].header_idx!= tmp_head_idx) break; + } + if(j != tmp_mul - tmp_size) tmp_fields=6; + + put_v(bc, tmp_flags); + put_v(bc, tmp_fields); + if(tmp_fields>0) put_s(bc, tmp_pts); + if(tmp_fields>1) put_v(bc, tmp_mul); + if(tmp_fields>2) put_v(bc, tmp_stream); + if(tmp_fields>3) put_v(bc, tmp_size); + if(tmp_fields>4) put_v(bc, 0 /*tmp_res*/); + if(tmp_fields>5) put_v(bc, j); + if(tmp_fields>6) put_v(bc, tmp_match); + if(tmp_fields>7) put_v(bc, tmp_head_idx); + } + put_v(bc, nut->header_count-1); + for(i=1; iheader_count; i++){ + put_v(bc, nut->header_len[i]); + put_buffer(bc, nut->header[i], nut->header_len[i]); + } +} + +static int write_streamheader(NUTContext *nut, ByteIOContext *bc, AVCodecContext *codec, int i){ + put_v(bc, i); + switch(codec->codec_type){ + case CODEC_TYPE_VIDEO: put_v(bc, 0); break; + case CODEC_TYPE_AUDIO: put_v(bc, 1); break; +// case CODEC_TYPE_TEXT : put_v(bc, 2); break; + default : put_v(bc, 3); break; + } + put_v(bc, 4); + if (codec->codec_tag){ + put_le32(bc, codec->codec_tag); + }else + return -1; + + put_v(bc, nut->stream[i].time_base - nut->time_base); + put_v(bc, nut->stream[i].msb_pts_shift); + put_v(bc, nut->stream[i].max_pts_distance); + put_v(bc, codec->has_b_frames); + put_byte(bc, 0); /* flags: 0x1 - fixed_fps, 0x2 - index_present */ + + put_v(bc, codec->extradata_size); + put_buffer(bc, codec->extradata, codec->extradata_size); + + switch(codec->codec_type){ + case CODEC_TYPE_AUDIO: + put_v(bc, codec->sample_rate); + put_v(bc, 1); + put_v(bc, codec->channels); + break; + case CODEC_TYPE_VIDEO: + put_v(bc, codec->width); + put_v(bc, codec->height); + + if(codec->sample_aspect_ratio.num<=0 || codec->sample_aspect_ratio.den<=0){ + put_v(bc, 0); + put_v(bc, 0); + }else{ + put_v(bc, codec->sample_aspect_ratio.num); + put_v(bc, codec->sample_aspect_ratio.den); + } + put_v(bc, 0); /* csp type -- unknown */ + break; + default: + break; + } + return 0; +} + +static int add_info(ByteIOContext *bc, const char *type, const char *value){ + put_str(bc, type); + put_s(bc, -1); + put_str(bc, value); + return 1; +} + +static int write_globalinfo(NUTContext *nut, ByteIOContext *bc){ + AVFormatContext *s= nut->avf; + ByteIOContext *dyn_bc; + uint8_t *dyn_buf=NULL; + int count=0, dyn_size; + int ret = url_open_dyn_buf(&dyn_bc); + if(ret < 0) + return ret; + + if(s->title [0]) count+= add_info(dyn_bc, "Title" , s->title); + if(s->author [0]) count+= add_info(dyn_bc, "Author" , s->author); + if(s->copyright[0]) count+= add_info(dyn_bc, "Copyright", s->copyright); + if(!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) + count+= add_info(dyn_bc, "Encoder" , LIBAVFORMAT_IDENT); + + put_v(bc, 0); //stream_if_plus1 + put_v(bc, 0); //chapter_id + put_v(bc, 0); //timestamp_start + put_v(bc, 0); //length + + put_v(bc, count); + + dyn_size= url_close_dyn_buf(dyn_bc, &dyn_buf); + put_buffer(bc, dyn_buf, dyn_size); + av_free(dyn_buf); + return 0; +} + +static int write_headers(NUTContext *nut, ByteIOContext *bc){ + ByteIOContext *dyn_bc; + int i, ret; + + ret = url_open_dyn_buf(&dyn_bc); + if(ret < 0) + return ret; + write_mainheader(nut, dyn_bc); + put_packet(nut, bc, dyn_bc, 1, MAIN_STARTCODE); + + for (i=0; i < nut->avf->nb_streams; i++){ + AVCodecContext *codec = nut->avf->streams[i]->codec; + + ret = url_open_dyn_buf(&dyn_bc); + if(ret < 0) + return ret; + write_streamheader(nut, dyn_bc, codec, i); + put_packet(nut, bc, dyn_bc, 1, STREAM_STARTCODE); + } + + ret = url_open_dyn_buf(&dyn_bc); + if(ret < 0) + return ret; + write_globalinfo(nut, dyn_bc); + put_packet(nut, bc, dyn_bc, 1, INFO_STARTCODE); + + nut->last_syncpoint_pos= INT_MIN; + nut->header_count++; + return 0; +} + +static int write_header(AVFormatContext *s){ + NUTContext *nut = s->priv_data; + ByteIOContext *bc = s->pb; + int i, j; + + nut->avf= s; + + nut->stream = av_mallocz(sizeof(StreamContext)*s->nb_streams); + nut->time_base= av_mallocz(sizeof(AVRational )*s->nb_streams); + + for(i=0; inb_streams; i++){ + AVStream *st= s->streams[i]; + int ssize; + AVRational time_base; + ff_parse_specific_params(st->codec, &time_base.den, &ssize, &time_base.num); + + av_set_pts_info(st, 64, time_base.num, time_base.den); + + for(j=0; jtime_base_count; j++){ + if(!memcmp(&time_base, &nut->time_base[j], sizeof(AVRational))){ + break; + } + } + nut->time_base[j]= time_base; + nut->stream[i].time_base= &nut->time_base[j]; + if(j==nut->time_base_count) + nut->time_base_count++; + + if(av_q2d(time_base) >= 0.001) + nut->stream[i].msb_pts_shift = 7; + else + nut->stream[i].msb_pts_shift = 14; + nut->stream[i].max_pts_distance= FFMAX(1/av_q2d(time_base), 1); + } + + nut->max_distance = MAX_DISTANCE; + build_elision_headers(s); + build_frame_code(s); + assert(nut->frame_code['N'].flags == FLAG_INVALID); + + put_buffer(bc, ID_STRING, strlen(ID_STRING)); + put_byte(bc, 0); + + write_headers(nut, bc); + + put_flush_packet(bc); + + //FIXME index + + return 0; +} + +static int get_needed_flags(NUTContext *nut, StreamContext *nus, FrameCode *fc, AVPacket *pkt){ + int flags= 0; + + if(pkt->flags & PKT_FLAG_KEY ) flags |= FLAG_KEY; + if(pkt->stream_index != fc->stream_id ) flags |= FLAG_STREAM_ID; + if(pkt->size / fc->size_mul ) flags |= FLAG_SIZE_MSB; + if(pkt->pts - nus->last_pts != fc->pts_delta) flags |= FLAG_CODED_PTS; + if(pkt->size > 2*nut->max_distance ) flags |= FLAG_CHECKSUM; + if(FFABS(pkt->pts - nus->last_pts) + > nus->max_pts_distance) flags |= FLAG_CHECKSUM; + if( pkt->size < nut->header_len[fc->header_idx] + || (pkt->size > 4096 && fc->header_idx) + || memcmp(pkt->data, nut->header[fc->header_idx], nut->header_len[fc->header_idx])) + flags |= FLAG_HEADER_IDX; + + return flags | (fc->flags & FLAG_CODED); +} + +static int find_best_header_idx(NUTContext *nut, AVPacket *pkt){ + int i; + int best_i = 0; + int best_len= 0; + + if(pkt->size > 4096) + return 0; + + for(i=1; iheader_count; i++){ + if( pkt->size >= nut->header_len[i] + && nut->header_len[i] > best_len + && !memcmp(pkt->data, nut->header[i], nut->header_len[i])){ + best_i= i; + best_len= nut->header_len[i]; + } + } + return best_i; +} + +static int write_packet(AVFormatContext *s, AVPacket *pkt){ + NUTContext *nut = s->priv_data; + StreamContext *nus= &nut->stream[pkt->stream_index]; + ByteIOContext *bc = s->pb, *dyn_bc; + FrameCode *fc; + int64_t coded_pts; + int best_length, frame_code, flags, needed_flags, i, header_idx, best_header_idx; + int key_frame = !!(pkt->flags & PKT_FLAG_KEY); + int store_sp=0; + int ret; + + if(1LL<<(20+3*nut->header_count) <= url_ftell(bc)) + write_headers(nut, bc); + + if(key_frame && !(nus->last_flags & FLAG_KEY)) + store_sp= 1; + + if(pkt->size + 30/*FIXME check*/ + url_ftell(bc) >= nut->last_syncpoint_pos + nut->max_distance) + store_sp= 1; + +//FIXME: Ensure store_sp is 1 in the first place. + + if(store_sp){ + syncpoint_t *sp, dummy= {.pos= INT64_MAX}; + + ff_nut_reset_ts(nut, *nus->time_base, pkt->dts); + for(i=0; inb_streams; i++){ + AVStream *st= s->streams[i]; + int64_t dts_tb = av_rescale_rnd(pkt->dts, + nus->time_base->num * (int64_t)nut->stream[i].time_base->den, + nus->time_base->den * (int64_t)nut->stream[i].time_base->num, + AV_ROUND_DOWN); + int index= av_index_search_timestamp(st, dts_tb, AVSEEK_FLAG_BACKWARD); + if(index>=0) dummy.pos= FFMIN(dummy.pos, st->index_entries[index].pos); + } + if(dummy.pos == INT64_MAX) + dummy.pos= 0; + sp= av_tree_find(nut->syncpoints, &dummy, ff_nut_sp_pos_cmp, NULL); + + nut->last_syncpoint_pos= url_ftell(bc); + ret = url_open_dyn_buf(&dyn_bc); + if(ret < 0) + return ret; + put_t(nut, nus, dyn_bc, pkt->dts); + put_v(dyn_bc, sp ? (nut->last_syncpoint_pos - sp->pos)>>4 : 0); + put_packet(nut, bc, dyn_bc, 1, SYNCPOINT_STARTCODE); + + ff_nut_add_sp(nut, nut->last_syncpoint_pos, 0/*unused*/, pkt->dts); + } + assert(nus->last_pts != AV_NOPTS_VALUE); + + coded_pts = pkt->pts & ((1<msb_pts_shift)-1); + if(ff_lsb2full(nus, coded_pts) != pkt->pts) + coded_pts= pkt->pts + (1<msb_pts_shift); + + best_header_idx= find_best_header_idx(nut, pkt); + + best_length=INT_MAX; + frame_code= -1; + for(i=0; i<256; i++){ + int length= 0; + FrameCode *fc= &nut->frame_code[i]; + int flags= fc->flags; + + if(flags & FLAG_INVALID) + continue; + needed_flags= get_needed_flags(nut, nus, fc, pkt); + + if(flags & FLAG_CODED){ + length++; + flags = needed_flags; + } + + if((flags & needed_flags) != needed_flags) + continue; + + if((flags ^ needed_flags) & FLAG_KEY) + continue; + + if(flags & FLAG_STREAM_ID) + length+= get_length(pkt->stream_index); + + if(pkt->size % fc->size_mul != fc->size_lsb) + continue; + if(flags & FLAG_SIZE_MSB) + length += get_length(pkt->size / fc->size_mul); + + if(flags & FLAG_CHECKSUM) + length+=4; + + if(flags & FLAG_CODED_PTS) + length += get_length(coded_pts); + + if( (flags & FLAG_CODED) + && nut->header_len[best_header_idx] > nut->header_len[fc->header_idx]+1){ + flags |= FLAG_HEADER_IDX; + } + + if(flags & FLAG_HEADER_IDX){ + length += 1 - nut->header_len[best_header_idx]; + }else{ + length -= nut->header_len[fc->header_idx]; + } + + length*=4; + length+= !(flags & FLAG_CODED_PTS); + length+= !(flags & FLAG_CHECKSUM); + + if(length < best_length){ + best_length= length; + frame_code=i; + } + } + assert(frame_code != -1); + fc= &nut->frame_code[frame_code]; + flags= fc->flags; + needed_flags= get_needed_flags(nut, nus, fc, pkt); + header_idx= fc->header_idx; + + init_checksum(bc, ff_crc04C11DB7_update, 0); + put_byte(bc, frame_code); + if(flags & FLAG_CODED){ + put_v(bc, (flags^needed_flags) & ~(FLAG_CODED)); + flags = needed_flags; + } + if(flags & FLAG_STREAM_ID) put_v(bc, pkt->stream_index); + if(flags & FLAG_CODED_PTS) put_v(bc, coded_pts); + if(flags & FLAG_SIZE_MSB) put_v(bc, pkt->size / fc->size_mul); + if(flags & FLAG_HEADER_IDX) put_v(bc, header_idx= best_header_idx); + + if(flags & FLAG_CHECKSUM) put_le32(bc, get_checksum(bc)); + else get_checksum(bc); + + put_buffer(bc, pkt->data + nut->header_len[header_idx], pkt->size - nut->header_len[header_idx]); + nus->last_flags= flags; + nus->last_pts= pkt->pts; + + //FIXME just store one per syncpoint + if(flags & FLAG_KEY) + av_add_index_entry( + s->streams[pkt->stream_index], + nut->last_syncpoint_pos, + pkt->pts, + 0, + 0, + AVINDEX_KEYFRAME); + + return 0; +} + +static int write_trailer(AVFormatContext *s){ + NUTContext *nut= s->priv_data; + ByteIOContext *bc= s->pb; + + while(nut->header_count<3) + write_headers(nut, bc); + put_flush_packet(bc); + + return 0; +} + +AVOutputFormat nut_muxer = { + "nut", + "nut format", + "video/x-nut", + "nut", + sizeof(NUTContext), +#ifdef CONFIG_LIBVORBIS + CODEC_ID_VORBIS, +#elif defined(CONFIG_LIBMP3LAME) + CODEC_ID_MP3, +#else + CODEC_ID_MP2, /* AC3 needs liba52 decoder */ +#endif + CODEC_ID_MPEG4, + write_header, + write_packet, + write_trailer, + .flags = AVFMT_GLOBALHEADER, + .codec_tag= (const AVCodecTag*[]){codec_bmp_tags, codec_wav_tags, 0}, +}; diff --git a/contrib/ffmpeg/libavformat/nuv.c b/contrib/ffmpeg/libavformat/nuv.c index 7e04222ee..f56d116ff 100644 --- a/contrib/ffmpeg/libavformat/nuv.c +++ b/contrib/ffmpeg/libavformat/nuv.c @@ -24,6 +24,7 @@ typedef struct { int v_id; int a_id; + int rtjpg_video; } NUVContext; typedef enum { @@ -35,8 +36,6 @@ typedef enum { } frametype_t; static int nuv_probe(AVProbeData *p) { - if (p->buf_size < 12) - return 0; if (!memcmp(p->buf, "NuppelVideo", 12)) return AVPROBE_SCORE_MAX; if (!memcmp(p->buf, "MythTVVideo", 12)) @@ -86,6 +85,8 @@ static int get_codec_data(ByteIOContext *pb, AVStream *vst, vst->codec->codec_tag = get_le32(pb); vst->codec->codec_id = codec_get_id(codec_bmp_tags, vst->codec->codec_tag); + if (vst->codec->codec_tag == MKTAG('R', 'J', 'P', 'G')) + vst->codec->codec_id = CODEC_ID_NUV; } else url_fskip(pb, 4); @@ -97,6 +98,7 @@ static int get_codec_data(ByteIOContext *pb, AVStream *vst, ast->codec->codec_id = wav_codec_get_id(ast->codec->codec_tag, ast->codec->bits_per_sample); + ast->need_parsing = AVSTREAM_PARSE_FULL; } else url_fskip(pb, 4 * 4); @@ -117,8 +119,8 @@ static int get_codec_data(ByteIOContext *pb, AVStream *vst, } static int nuv_header(AVFormatContext *s, AVFormatParameters *ap) { - NUVContext *ctx = (NUVContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + NUVContext *ctx = s->priv_data; + ByteIOContext *pb = s->pb; char id_string[12], version_string[5]; double aspect, fps; int is_mythtv, width, height, v_packs, a_packs; @@ -149,7 +151,6 @@ static int nuv_header(AVFormatContext *s, AVFormatParameters *ap) { vst = av_new_stream(s, ctx->v_id); vst->codec->codec_type = CODEC_TYPE_VIDEO; vst->codec->codec_id = CODEC_ID_NUV; - vst->codec->codec_tag = MKTAG('R', 'J', 'P', 'G'); vst->codec->width = width; vst->codec->height = height; vst->codec->bits_per_sample = 10; @@ -174,39 +175,45 @@ static int nuv_header(AVFormatContext *s, AVFormatParameters *ap) { ctx->a_id = -1; get_codec_data(pb, vst, ast, is_mythtv); + ctx->rtjpg_video = vst->codec->codec_id == CODEC_ID_NUV; return 0; } #define HDRSIZE 12 static int nuv_packet(AVFormatContext *s, AVPacket *pkt) { - NUVContext *ctx = (NUVContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + NUVContext *ctx = s->priv_data; + ByteIOContext *pb = s->pb; uint8_t hdr[HDRSIZE]; frametype_t frametype; int ret, size; while (!url_feof(pb)) { + int copyhdrsize = ctx->rtjpg_video ? HDRSIZE : 0; ret = get_buffer(pb, hdr, HDRSIZE); if (ret <= 0) return ret ? ret : -1; frametype = hdr[0]; size = PKTSIZE(AV_RL32(&hdr[8])); switch (frametype) { - case NUV_VIDEO: case NUV_EXTRADATA: + if (!ctx->rtjpg_video) { + url_fskip(pb, size); + break; + } + case NUV_VIDEO: if (ctx->v_id < 0) { av_log(s, AV_LOG_ERROR, "Video packet in file without video stream!\n"); url_fskip(pb, size); break; } - ret = av_new_packet(pkt, HDRSIZE + size); + ret = av_new_packet(pkt, copyhdrsize + size); if (ret < 0) return ret; - pkt->pos = url_ftell(pb); + pkt->pos = url_ftell(pb) - copyhdrsize; pkt->pts = AV_RL32(&hdr[4]); pkt->stream_index = ctx->v_id; - memcpy(pkt->data, hdr, HDRSIZE); - ret = get_buffer(pb, pkt->data + HDRSIZE, size); + memcpy(pkt->data, hdr, copyhdrsize); + ret = get_buffer(pb, pkt->data + copyhdrsize, size); return ret; case NUV_AUDIO: if (ctx->a_id < 0) { @@ -226,7 +233,7 @@ static int nuv_packet(AVFormatContext *s, AVPacket *pkt) { break; } } - return AVERROR_IO; + return AVERROR(EIO); } AVInputFormat nuv_demuxer = { diff --git a/contrib/ffmpeg/libavformat/ogg.c b/contrib/ffmpeg/libavformat/ogg.c deleted file mode 100644 index c98bb2273..000000000 --- a/contrib/ffmpeg/libavformat/ogg.c +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Ogg bitstream support - * Mark Hills - * - * Uses libogg, but requires libvorbisenc to construct correct headers - * when containing Vorbis stream -- currently the only format supported - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#include - -#include "avformat.h" - -#undef NDEBUG -#include - -#define DECODER_BUFFER_SIZE 4096 - - -typedef struct OggContext { - /* output */ - ogg_stream_state os ; - int header_handled ; - ogg_packet op; - - /* input */ - ogg_sync_state oy ; -} OggContext ; - - -#ifdef CONFIG_MUXERS -static int ogg_write_header(AVFormatContext *avfcontext) -{ - OggContext *context = avfcontext->priv_data; - ogg_packet *op= &context->op; - int n; - - ogg_stream_init(&context->os, 31415); - - for(n = 0 ; n < avfcontext->nb_streams ; n++) { - AVCodecContext *codec = avfcontext->streams[n]->codec; - uint8_t *headers = codec->extradata; - int headers_len = codec->extradata_size; - uint8_t *header_start[3]; - int header_len[3]; - int i, j; - - av_set_pts_info(avfcontext->streams[n], 60, 1, AV_TIME_BASE); - - for(j=1,i=0;i<2;++i, ++j) { - header_len[i]=0; - while(jbytes = header_len[i]; - - op->packet= header_start[i]; - op->b_o_s= op->packetno==0; - - ogg_stream_packetin(&context->os, op); - - op->packetno++; //FIXME multiple streams - } - - context->header_handled = 0 ; - } - - return 0 ; -} - -static int ogg_write_packet(AVFormatContext *avfcontext, AVPacket *pkt) -{ - OggContext *context = avfcontext->priv_data ; - AVCodecContext *avctx= avfcontext->streams[pkt->stream_index]->codec; - ogg_packet *op= &context->op; - ogg_page og ; - int64_t pts; - - pts= av_rescale(pkt->pts, avctx->sample_rate, AV_TIME_BASE); - -// av_log(avfcontext, AV_LOG_DEBUG, "M%d\n", size); - - /* flush header packets so audio starts on a new page */ - - if(!context->header_handled) { - while(ogg_stream_flush(&context->os, &og)) { - put_buffer(&avfcontext->pb, og.header, og.header_len) ; - put_buffer(&avfcontext->pb, og.body, og.body_len) ; - put_flush_packet(&avfcontext->pb); - } - context->header_handled = 1 ; - } - - op->packet = (uint8_t*) pkt->data; - op->bytes = pkt->size; - op->b_o_s = op->packetno == 0; - op->granulepos= pts; - - /* correct the fields in the packet -- essential for streaming */ - - ogg_stream_packetin(&context->os, op); - - while(ogg_stream_pageout(&context->os, &og)) { - put_buffer(&avfcontext->pb, og.header, og.header_len); - put_buffer(&avfcontext->pb, og.body, og.body_len); - put_flush_packet(&avfcontext->pb); - } - op->packetno++; - - return 0; -} - - -static int ogg_write_trailer(AVFormatContext *avfcontext) { - OggContext *context = avfcontext->priv_data ; - ogg_page og ; - - while(ogg_stream_flush(&context->os, &og)) { - put_buffer(&avfcontext->pb, og.header, og.header_len) ; - put_buffer(&avfcontext->pb, og.body, og.body_len) ; - put_flush_packet(&avfcontext->pb); - } - - ogg_stream_clear(&context->os) ; - return 0 ; -} - - -AVOutputFormat ogg_muxer = { - "ogg", - "Ogg format", - "application/ogg", - "ogg", - sizeof(OggContext), - CODEC_ID_VORBIS, - 0, - ogg_write_header, - ogg_write_packet, - ogg_write_trailer, -} ; -#endif //CONFIG_MUXERS - -#if 0 -static int next_packet(AVFormatContext *avfcontext, ogg_packet *op) { - OggContext *context = avfcontext->priv_data ; - ogg_page og ; - char *buf ; - - while(ogg_stream_packetout(&context->os, op) != 1) { - - /* while no pages are available, read in more data to the sync */ - while(ogg_sync_pageout(&context->oy, &og) != 1) { - buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ; - if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0) - return 1 ; - ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ; - } - - /* got a page. Feed it into the stream and get the packet */ - if(ogg_stream_pagein(&context->os, &og) != 0) - return 1 ; - } - - return 0 ; -} - - -static int ogg_read_header(AVFormatContext *avfcontext, AVFormatParameters *ap) -{ - OggContext *context = avfcontext->priv_data; - ogg_packet op ; - char *buf ; - ogg_page og ; - AVStream *ast ; - AVCodecContext *codec; - uint8_t *p; - int i; - - ogg_sync_init(&context->oy) ; - buf = ogg_sync_buffer(&context->oy, DECODER_BUFFER_SIZE) ; - - if(get_buffer(&avfcontext->pb, buf, DECODER_BUFFER_SIZE) <= 0) - return AVERROR_IO ; - - ogg_sync_wrote(&context->oy, DECODER_BUFFER_SIZE) ; - ogg_sync_pageout(&context->oy, &og) ; - ogg_stream_init(&context->os, ogg_page_serialno(&og)) ; - ogg_stream_pagein(&context->os, &og) ; - - /* currently only one vorbis stream supported */ - - ast = av_new_stream(avfcontext, 0) ; - if(!ast) - return AVERROR_NOMEM ; - av_set_pts_info(ast, 60, 1, AV_TIME_BASE); - - codec= &ast->codec; - codec->codec_type = CODEC_TYPE_AUDIO; - codec->codec_id = CODEC_ID_VORBIS; - for(i=0; i<3; i++){ - if(next_packet(avfcontext, &op)){ - return -1; - } - if(op.bytes >= (1<<16) || op.bytes < 0) - return -1; - codec->extradata_size+= 2 + op.bytes; - codec->extradata= av_realloc(codec->extradata, codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - memset(codec->extradata + codec->extradata_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); - p= codec->extradata + codec->extradata_size - 2 - op.bytes; - *(p++)= op.bytes>>8; - *(p++)= op.bytes&0xFF; - memcpy(p, op.packet, op.bytes); - } - - return 0 ; -} - - -static int ogg_read_packet(AVFormatContext *avfcontext, AVPacket *pkt) { - ogg_packet op ; - - if(next_packet(avfcontext, &op)) - return AVERROR_IO ; - if(av_new_packet(pkt, op.bytes) < 0) - return AVERROR_IO ; - pkt->stream_index = 0 ; - memcpy(pkt->data, op.packet, op.bytes); - if(avfcontext->streams[0]->codec.sample_rate && op.granulepos!=-1) - pkt->pts= av_rescale(op.granulepos, AV_TIME_BASE, avfcontext->streams[0]->codec.sample_rate); -// printf("%"PRId64" %d %d\n", pkt->pts, (int)op.granulepos, avfcontext->streams[0]->codec.sample_rate); - - return op.bytes; -} - - -static int ogg_read_close(AVFormatContext *avfcontext) { - OggContext *context = avfcontext->priv_data ; - - ogg_stream_clear(&context->os) ; - ogg_sync_clear(&context->oy) ; - - return 0 ; -} - - -static AVInputFormat ogg_iformat = { - "ogg", - "Ogg Vorbis", - sizeof(OggContext), - NULL, - ogg_read_header, - ogg_read_packet, - ogg_read_close, - .extensions = "ogg", -} ; -#endif diff --git a/contrib/ffmpeg/libavformat/ogg2.c b/contrib/ffmpeg/libavformat/ogg2.c deleted file mode 100644 index 8ca7b2d13..000000000 --- a/contrib/ffmpeg/libavformat/ogg2.c +++ /dev/null @@ -1,700 +0,0 @@ -/* - * Ogg bitstream support - * Luca Barbato - * Based on tcvp implementation - * - */ - -/** - Copyright (C) 2005 Michael Ahlberg, MÃ¥ns RullgÃ¥rd - - Permission is hereby granted, free of charge, to any person - obtaining a copy of this software and associated documentation - files (the "Software"), to deal in the Software without - restriction, including without limitation the rights to use, copy, - modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -**/ - - -#include -#include "ogg2.h" -#include "avformat.h" - -#define MAX_PAGE_SIZE 65307 -#define DECODER_BUFFER_SIZE MAX_PAGE_SIZE - -static ogg_codec_t *ogg_codecs[] = { - &vorbis_codec, - &theora_codec, - &flac_codec, - &ogm_video_codec, - &ogm_audio_codec, - &ogm_old_codec, - NULL -}; - -#if 0 // CONFIG_MUXERS -static int -ogg_write_header (AVFormatContext * avfcontext) -{ -} - -static int -ogg_write_packet (AVFormatContext * avfcontext, AVPacket * pkt) -{ -} - - -static int -ogg_write_trailer (AVFormatContext * avfcontext) -{ -} - - -AVOutputFormat ogg_muxer = { - "ogg", - "Ogg format", - "application/ogg", - "ogg", - sizeof (OggContext), - CODEC_ID_VORBIS, - 0, - ogg_write_header, - ogg_write_packet, - ogg_write_trailer, -}; -#endif //CONFIG_MUXERS - -//FIXME We could avoid some structure duplication -static int -ogg_save (AVFormatContext * s) -{ - ogg_t *ogg = s->priv_data; - ogg_state_t *ost = - av_malloc(sizeof (*ost) + (ogg->nstreams-1) * sizeof (*ogg->streams)); - int i; - ost->pos = url_ftell (&s->pb);; - ost->curidx = ogg->curidx; - ost->next = ogg->state; - ost->nstreams = ogg->nstreams; - memcpy(ost->streams, ogg->streams, ogg->nstreams * sizeof(*ogg->streams)); - - for (i = 0; i < ogg->nstreams; i++){ - ogg_stream_t *os = ogg->streams + i; - os->buf = av_malloc (os->bufsize); - memset (os->buf, 0, os->bufsize); - memcpy (os->buf, ost->streams[i].buf, os->bufpos); - } - - ogg->state = ost; - - return 0; -} - -static int -ogg_restore (AVFormatContext * s, int discard) -{ - ogg_t *ogg = s->priv_data; - ByteIOContext *bc = &s->pb; - ogg_state_t *ost = ogg->state; - int i; - - if (!ost) - return 0; - - ogg->state = ost->next; - - if (!discard){ - for (i = 0; i < ogg->nstreams; i++) - av_free (ogg->streams[i].buf); - - url_fseek (bc, ost->pos, SEEK_SET); - ogg->curidx = ost->curidx; - ogg->nstreams = ost->nstreams; - memcpy(ogg->streams, ost->streams, - ost->nstreams * sizeof(*ogg->streams)); - } - - av_free (ost); - - return 0; -} - -static int -ogg_reset (ogg_t * ogg) -{ - int i; - - for (i = 0; i < ogg->nstreams; i++){ - ogg_stream_t *os = ogg->streams + i; - os->bufpos = 0; - os->pstart = 0; - os->psize = 0; - os->granule = -1; - os->lastgp = -1; - os->nsegs = 0; - os->segp = 0; - } - - ogg->curidx = -1; - - return 0; -} - -static ogg_codec_t * -ogg_find_codec (uint8_t * buf, int size) -{ - int i; - - for (i = 0; ogg_codecs[i]; i++) - if (size >= ogg_codecs[i]->magicsize && - !memcmp (buf, ogg_codecs[i]->magic, ogg_codecs[i]->magicsize)) - return ogg_codecs[i]; - - return NULL; -} - -static int -ogg_find_stream (ogg_t * ogg, int serial) -{ - int i; - - for (i = 0; i < ogg->nstreams; i++) - if (ogg->streams[i].serial == serial) - return i; - - return -1; -} - -static int -ogg_new_stream (AVFormatContext * s, uint32_t serial) -{ - - ogg_t *ogg = s->priv_data; - int idx = ogg->nstreams++; - AVStream *st; - ogg_stream_t *os; - - ogg->streams = av_realloc (ogg->streams, - ogg->nstreams * sizeof (*ogg->streams)); - memset (ogg->streams + idx, 0, sizeof (*ogg->streams)); - os = ogg->streams + idx; - os->serial = serial; - os->bufsize = DECODER_BUFFER_SIZE; - os->buf = av_malloc(os->bufsize); - os->header = -1; - - st = av_new_stream (s, idx); - if (!st) - return AVERROR_NOMEM; - - av_set_pts_info(st, 64, 1, 1000000); - - return idx; -} - -static int -ogg_new_buf(ogg_t *ogg, int idx) -{ - ogg_stream_t *os = ogg->streams + idx; - uint8_t *nb = av_malloc(os->bufsize); - int size = os->bufpos - os->pstart; - if(os->buf){ - memcpy(nb, os->buf + os->pstart, size); - av_free(os->buf); - } - os->buf = nb; - os->bufpos = size; - os->pstart = 0; - - return 0; -} - -static int -ogg_read_page (AVFormatContext * s, int *str) -{ - ByteIOContext *bc = &s->pb; - ogg_t *ogg = s->priv_data; - ogg_stream_t *os; - int i = 0; - int flags, nsegs; - uint64_t gp; - uint32_t serial; - uint32_t seq; - uint32_t crc; - int size, idx; - uint8_t sync[4]; - int sp = 0; - - if (get_buffer (bc, sync, 4) < 4) - return -1; - - do{ - int c; - - if (sync[sp & 3] == 'O' && - sync[(sp + 1) & 3] == 'g' && - sync[(sp + 2) & 3] == 'g' && sync[(sp + 3) & 3] == 'S') - break; - - c = url_fgetc (bc); - if (c < 0) - return -1; - sync[sp++ & 3] = c; - }while (i++ < MAX_PAGE_SIZE); - - if (i >= MAX_PAGE_SIZE){ - av_log (s, AV_LOG_INFO, "ogg, can't find sync word\n"); - return -1; - } - - if (url_fgetc (bc) != 0) /* version */ - return -1; - - flags = url_fgetc (bc); - gp = get_le64 (bc); - serial = get_le32 (bc); - seq = get_le32 (bc); - crc = get_le32 (bc); - nsegs = url_fgetc (bc); - - idx = ogg_find_stream (ogg, serial); - if (idx < 0){ - idx = ogg_new_stream (s, serial); - if (idx < 0) - return -1; - } - - os = ogg->streams + idx; - - if(os->psize > 0) - ogg_new_buf(ogg, idx); - - if (get_buffer (bc, os->segments, nsegs) < nsegs) - return -1; - - os->nsegs = nsegs; - os->segp = 0; - - size = 0; - for (i = 0; i < nsegs; i++) - size += os->segments[i]; - - if (flags & OGG_FLAG_CONT){ - if (!os->psize){ - while (os->segp < os->nsegs){ - int seg = os->segments[os->segp++]; - os->pstart += seg; - if (seg < 255) - break; - } - } - }else{ - os->psize = 0; - } - - if (os->bufsize - os->bufpos < size){ - uint8_t *nb = av_malloc (os->bufsize *= 2); - memcpy (nb, os->buf, os->bufpos); - av_free (os->buf); - os->buf = nb; - } - - if (get_buffer (bc, os->buf + os->bufpos, size) < size) - return -1; - - os->lastgp = os->granule; - os->bufpos += size; - os->granule = gp; - os->flags = flags; - - if (str) - *str = idx; - - return 0; -} - -static int -ogg_packet (AVFormatContext * s, int *str, int *dstart, int *dsize) -{ - ogg_t *ogg = s->priv_data; - int idx; - ogg_stream_t *os; - int complete = 0; - int segp = 0, psize = 0; - -#if 0 - av_log (s, AV_LOG_DEBUG, "ogg_packet: curidx=%i\n", ogg->curidx); -#endif - - do{ - idx = ogg->curidx; - - while (idx < 0){ - if (ogg_read_page (s, &idx) < 0) - return -1; - } - - os = ogg->streams + idx; - -#if 0 - av_log (s, AV_LOG_DEBUG, - "ogg_packet: idx=%d pstart=%d psize=%d segp=%d nsegs=%d\n", - idx, os->pstart, os->psize, os->segp, os->nsegs); -#endif - - if (!os->codec){ - if (os->header < 0){ - os->codec = ogg_find_codec (os->buf, os->bufpos); - if (!os->codec){ - os->header = 0; - return 0; - } - }else{ - return 0; - } - } - - segp = os->segp; - psize = os->psize; - - while (os->segp < os->nsegs){ - int ss = os->segments[os->segp++]; - os->psize += ss; - if (ss < 255){ - complete = 1; - break; - } - } - - if (!complete && os->segp == os->nsegs){ - ogg->curidx = -1; - } - }while (!complete); - -#if 0 - av_log (s, AV_LOG_DEBUG, - "ogg_packet: idx %i, frame size %i, start %i\n", - idx, os->psize, os->pstart); -#endif - - ogg->curidx = idx; - - if (os->header < 0){ - int hdr = os->codec->header (s, idx); - if (!hdr){ - os->header = os->seq; - os->segp = segp; - os->psize = psize; - ogg->headers = 1; - }else{ - os->pstart += os->psize; - os->psize = 0; - } - } - - if (os->header > -1 && os->seq > os->header){ - if (os->codec && os->codec->packet) - os->codec->packet (s, idx); - if (str) - *str = idx; - if (dstart) - *dstart = os->pstart; - if (dsize) - *dsize = os->psize; - os->pstart += os->psize; - os->psize = 0; - } - - os->seq++; - if (os->segp == os->nsegs) - ogg->curidx = -1; - - return 0; -} - -static int -ogg_get_headers (AVFormatContext * s) -{ - ogg_t *ogg = s->priv_data; - - do{ - if (ogg_packet (s, NULL, NULL, NULL) < 0) - return -1; - }while (!ogg->headers); - -#if 0 - av_log (s, AV_LOG_DEBUG, "found headers\n"); -#endif - - return 0; -} - -static uint64_t -ogg_gptopts (AVFormatContext * s, int i, uint64_t gp) -{ - ogg_t *ogg = s->priv_data; - ogg_stream_t *os = ogg->streams + i; - uint64_t pts = AV_NOPTS_VALUE; - - if(os->codec->gptopts){ - pts = os->codec->gptopts(s, i, gp); - } else { - pts = gp; - } - - return pts; -} - - -static int -ogg_get_length (AVFormatContext * s) -{ - ogg_t *ogg = s->priv_data; - int idx = -1, i; - offset_t size, end; - - if(s->pb.is_streamed) - return 0; - -// already set - if (s->duration != AV_NOPTS_VALUE) - return 0; - - size = url_fsize(&s->pb); - if(size < 0) - return 0; - end = size > MAX_PAGE_SIZE? size - MAX_PAGE_SIZE: size; - - ogg_save (s); - url_fseek (&s->pb, end, SEEK_SET); - - while (!ogg_read_page (s, &i)){ - if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 && - ogg->streams[i].codec) - idx = i; - } - - if (idx != -1){ - s->streams[idx]->duration = - ogg_gptopts (s, idx, ogg->streams[idx].granule); - } - - ogg->size = size; - ogg_restore (s, 0); - ogg_save (s); - while (!ogg_read_page (s, &i)) { - if (i == idx && ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0) - break; - } - if (i == idx) { - s->streams[idx]->start_time = ogg_gptopts (s, idx, ogg->streams[idx].granule); - s->streams[idx]->duration -= s->streams[idx]->start_time; - } - ogg_restore (s, 0); - - return 0; -} - - -static int -ogg_read_header (AVFormatContext * s, AVFormatParameters * ap) -{ - ogg_t *ogg = s->priv_data; - ogg->curidx = -1; - //linear headers seek from start - if (ogg_get_headers (s) < 0){ - return -1; - } - - //linear granulepos seek from end - ogg_get_length (s); - - //fill the extradata in the per codec callbacks - return 0; -} - - -static int -ogg_read_packet (AVFormatContext * s, AVPacket * pkt) -{ - ogg_t *ogg; - ogg_stream_t *os; - int idx = -1; - int pstart, psize; - - //Get an ogg packet - do{ - if (ogg_packet (s, &idx, &pstart, &psize) < 0) - return AVERROR_IO; - }while (idx < 0 || !s->streams[idx]); - - ogg = s->priv_data; - os = ogg->streams + idx; - - //Alloc a pkt - if (av_new_packet (pkt, psize) < 0) - return AVERROR_IO; - pkt->stream_index = idx; - memcpy (pkt->data, os->buf + pstart, psize); - if (os->lastgp != -1LL){ - pkt->pts = ogg_gptopts (s, idx, os->lastgp); - os->lastgp = -1; - } - - return psize; -} - - -static int -ogg_read_close (AVFormatContext * s) -{ - ogg_t *ogg = s->priv_data; - int i; - - for (i = 0; i < ogg->nstreams; i++){ - av_free (ogg->streams[i].buf); - av_free (ogg->streams[i].private); - } - av_free (ogg->streams); - return 0; -} - - -static int -ogg_read_seek (AVFormatContext * s, int stream_index, int64_t target_ts, - int flags) -{ - AVStream *st = s->streams[stream_index]; - ogg_t *ogg = s->priv_data; - ByteIOContext *bc = &s->pb; - uint64_t min = 0, max = ogg->size; - uint64_t tmin = st->start_time, tmax = st->start_time + st->duration; - int64_t pts = AV_NOPTS_VALUE; - - ogg_save (s); - - if ((uint64_t)target_ts < tmin || target_ts < 0) - target_ts = tmin; - while (min <= max && tmin < tmax){ - uint64_t p = min + (max - min) * (target_ts - tmin) / (tmax - tmin); - int i = -1; - - url_fseek (bc, p, SEEK_SET); - - while (!ogg_read_page (s, &i)){ - if (i == stream_index && ogg->streams[i].granule != 0 && - ogg->streams[i].granule != -1) - break; - } - - if (i == -1) - break; - - pts = ogg_gptopts (s, i, ogg->streams[i].granule); - p = url_ftell (bc); - - if (FFABS (pts - target_ts) * st->time_base.num < st->time_base.den) - break; - - if (pts > target_ts){ - if (max == p && tmax == pts) { - // probably our tmin is wrong, causing us to always end up too late in the file - tmin = (target_ts + tmin + 1) / 2; - if (tmin == target_ts) { - url_fseek(bc, min, SEEK_SET); - break; - } - } - max = p; - tmax = pts; - }else{ - if (min == p && tmin == pts) { - // probably our tmax is wrong, causing us to always end up too early in the file - tmax = (target_ts + tmax) / 2; - if (tmax == target_ts) { - url_fseek(bc, max, SEEK_SET); - break; - } - } - min = p; - tmin = pts; - } - } - - if (FFABS (pts - target_ts) * st->time_base.num < st->time_base.den){ - ogg_restore (s, 1); - ogg_reset (ogg); - }else{ - ogg_restore (s, 0); - pts = AV_NOPTS_VALUE; - } - - av_update_cur_dts(s, st, pts); - return 0; - -#if 0 - //later... - int64_t pos; - if (av_seek_frame_binary (s, stream_index, target_ts, flags) < 0) - return -1; - pos = url_ftell (&s->pb); - ogg_read_timestamp (s, stream_index, &pos, pos - 1); -#endif - -} - -#if 0 -static int64_t -ogg_read_timestamp (AVFormatContext * s, int stream_index, int64_t * pos_arg, - int64_t pos_limit) -{ - ogg_t *ogg = s->priv_data; - ByteIOContext *bc = &s->pb; - int64_t pos, pts; - - if (*pos_arg < 0) - return AV_NOPTS_VALUE; - - pos = *pos_arg; -} -#endif - -static int ogg_probe(AVProbeData *p) -{ - if (p->buf_size < 6) - return 0; - if (p->buf[0] == 'O' && p->buf[1] == 'g' && - p->buf[2] == 'g' && p->buf[3] == 'S' && - p->buf[4] == 0x0 && p->buf[5] <= 0x7 ) - return AVPROBE_SCORE_MAX; - else - return 0; -} - -AVInputFormat ogg_demuxer = { - "ogg", - "Ogg", - sizeof (ogg_t), - ogg_probe, - ogg_read_header, - ogg_read_packet, - ogg_read_close, - ogg_read_seek, -// ogg_read_timestamp, - .extensions = "ogg", -}; diff --git a/contrib/ffmpeg/libavformat/ogg2.h b/contrib/ffmpeg/libavformat/ogg2.h deleted file mode 100644 index 6b7c6b22e..000000000 --- a/contrib/ffmpeg/libavformat/ogg2.h +++ /dev/null @@ -1,86 +0,0 @@ -/** - Copyright (C) 2005 Michael Ahlberg, MÃ¥ns RullgÃ¥rd - - Permission is hereby granted, free of charge, to any person - obtaining a copy of this software and associated documentation - files (the "Software"), to deal in the Software without - restriction, including without limitation the rights to use, copy, - modify, merge, publish, distribute, sublicense, and/or sell copies - of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - DEALINGS IN THE SOFTWARE. -**/ - -#ifndef OGG_H -#define OGG_H - -#include "avformat.h" - -typedef struct ogg_codec { - int8_t *magic; - uint8_t magicsize; - int8_t *name; - int (*header)(AVFormatContext *, int); - int (*packet)(AVFormatContext *, int); - uint64_t (*gptopts)(AVFormatContext *, int, uint64_t); -} ogg_codec_t; - -typedef struct ogg_stream { - uint8_t *buf; - unsigned int bufsize; - unsigned int bufpos; - unsigned int pstart; - unsigned int psize; - uint32_t serial; - uint32_t seq; - uint64_t granule, lastgp; - int flags; - ogg_codec_t *codec; - int header; - int nsegs, segp; - uint8_t segments[255]; - void *private; -} ogg_stream_t; - -typedef struct ogg_state { - uint64_t pos; - int curidx; - struct ogg_state *next; - int nstreams; - ogg_stream_t streams[1]; -} ogg_state_t; - -typedef struct ogg { - ogg_stream_t *streams; - int nstreams; - int headers; - int curidx; - uint64_t size; - ogg_state_t *state; -} ogg_t; - -#define OGG_FLAG_CONT 1 -#define OGG_FLAG_BOS 2 -#define OGG_FLAG_EOS 4 - -extern ogg_codec_t vorbis_codec; -extern ogg_codec_t theora_codec; -extern ogg_codec_t flac_codec; -extern ogg_codec_t ogm_video_codec; -extern ogg_codec_t ogm_audio_codec; -extern ogg_codec_t ogm_old_codec; - -extern int vorbis_comment(AVFormatContext *ms, uint8_t *buf, int size); - -#endif diff --git a/contrib/ffmpeg/libavformat/oggdec.c b/contrib/ffmpeg/libavformat/oggdec.c new file mode 100644 index 000000000..96d16a873 --- /dev/null +++ b/contrib/ffmpeg/libavformat/oggdec.c @@ -0,0 +1,596 @@ +/* + * Ogg bitstream support + * Luca Barbato + * Based on tcvp implementation + * + */ + +/** + Copyright (C) 2005 Michael Ahlberg, MÃ¥ns RullgÃ¥rd + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, copy, + modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +**/ + + +#include +#include "oggdec.h" +#include "avformat.h" + +#define MAX_PAGE_SIZE 65307 +#define DECODER_BUFFER_SIZE MAX_PAGE_SIZE + +static ogg_codec_t *ogg_codecs[] = { + &speex_codec, + &vorbis_codec, + &theora_codec, + &flac_codec, + &old_flac_codec, + &ogm_video_codec, + &ogm_audio_codec, + &ogm_text_codec, + &ogm_old_codec, + NULL +}; + +//FIXME We could avoid some structure duplication +static int +ogg_save (AVFormatContext * s) +{ + ogg_t *ogg = s->priv_data; + ogg_state_t *ost = + av_malloc(sizeof (*ost) + (ogg->nstreams-1) * sizeof (*ogg->streams)); + int i; + ost->pos = url_ftell (s->pb); + ost->curidx = ogg->curidx; + ost->next = ogg->state; + ost->nstreams = ogg->nstreams; + memcpy(ost->streams, ogg->streams, ogg->nstreams * sizeof(*ogg->streams)); + + for (i = 0; i < ogg->nstreams; i++){ + ogg_stream_t *os = ogg->streams + i; + os->buf = av_malloc (os->bufsize); + memset (os->buf, 0, os->bufsize); + memcpy (os->buf, ost->streams[i].buf, os->bufpos); + } + + ogg->state = ost; + + return 0; +} + +static int +ogg_restore (AVFormatContext * s, int discard) +{ + ogg_t *ogg = s->priv_data; + ByteIOContext *bc = s->pb; + ogg_state_t *ost = ogg->state; + int i; + + if (!ost) + return 0; + + ogg->state = ost->next; + + if (!discard){ + for (i = 0; i < ogg->nstreams; i++) + av_free (ogg->streams[i].buf); + + url_fseek (bc, ost->pos, SEEK_SET); + ogg->curidx = ost->curidx; + ogg->nstreams = ost->nstreams; + memcpy(ogg->streams, ost->streams, + ost->nstreams * sizeof(*ogg->streams)); + } + + av_free (ost); + + return 0; +} + +static int +ogg_reset (ogg_t * ogg) +{ + int i; + + for (i = 0; i < ogg->nstreams; i++){ + ogg_stream_t *os = ogg->streams + i; + os->bufpos = 0; + os->pstart = 0; + os->psize = 0; + os->granule = -1; + os->lastgp = -1; + os->nsegs = 0; + os->segp = 0; + } + + ogg->curidx = -1; + + return 0; +} + +static ogg_codec_t * +ogg_find_codec (uint8_t * buf, int size) +{ + int i; + + for (i = 0; ogg_codecs[i]; i++) + if (size >= ogg_codecs[i]->magicsize && + !memcmp (buf, ogg_codecs[i]->magic, ogg_codecs[i]->magicsize)) + return ogg_codecs[i]; + + return NULL; +} + +static int +ogg_find_stream (ogg_t * ogg, int serial) +{ + int i; + + for (i = 0; i < ogg->nstreams; i++) + if (ogg->streams[i].serial == serial) + return i; + + return -1; +} + +static int +ogg_new_stream (AVFormatContext * s, uint32_t serial) +{ + + ogg_t *ogg = s->priv_data; + int idx = ogg->nstreams++; + AVStream *st; + ogg_stream_t *os; + + ogg->streams = av_realloc (ogg->streams, + ogg->nstreams * sizeof (*ogg->streams)); + memset (ogg->streams + idx, 0, sizeof (*ogg->streams)); + os = ogg->streams + idx; + os->serial = serial; + os->bufsize = DECODER_BUFFER_SIZE; + os->buf = av_malloc(os->bufsize); + os->header = -1; + + st = av_new_stream (s, idx); + if (!st) + return AVERROR(ENOMEM); + + av_set_pts_info(st, 64, 1, 1000000); + + return idx; +} + +static int +ogg_new_buf(ogg_t *ogg, int idx) +{ + ogg_stream_t *os = ogg->streams + idx; + uint8_t *nb = av_malloc(os->bufsize); + int size = os->bufpos - os->pstart; + if(os->buf){ + memcpy(nb, os->buf + os->pstart, size); + av_free(os->buf); + } + os->buf = nb; + os->bufpos = size; + os->pstart = 0; + + return 0; +} + +static int +ogg_read_page (AVFormatContext * s, int *str) +{ + ByteIOContext *bc = s->pb; + ogg_t *ogg = s->priv_data; + ogg_stream_t *os; + int i = 0; + int flags, nsegs; + uint64_t gp; + uint32_t serial; + uint32_t seq; + uint32_t crc; + int size, idx; + uint8_t sync[4]; + int sp = 0; + + if (get_buffer (bc, sync, 4) < 4) + return -1; + + do{ + int c; + + if (sync[sp & 3] == 'O' && + sync[(sp + 1) & 3] == 'g' && + sync[(sp + 2) & 3] == 'g' && sync[(sp + 3) & 3] == 'S') + break; + + c = url_fgetc (bc); + if (c < 0) + return -1; + sync[sp++ & 3] = c; + }while (i++ < MAX_PAGE_SIZE); + + if (i >= MAX_PAGE_SIZE){ + av_log (s, AV_LOG_INFO, "ogg, can't find sync word\n"); + return -1; + } + + if (url_fgetc (bc) != 0) /* version */ + return -1; + + flags = url_fgetc (bc); + gp = get_le64 (bc); + serial = get_le32 (bc); + seq = get_le32 (bc); + crc = get_le32 (bc); + nsegs = url_fgetc (bc); + + idx = ogg_find_stream (ogg, serial); + if (idx < 0){ + idx = ogg_new_stream (s, serial); + if (idx < 0) + return -1; + } + + os = ogg->streams + idx; + + if(os->psize > 0) + ogg_new_buf(ogg, idx); + + if (get_buffer (bc, os->segments, nsegs) < nsegs) + return -1; + + os->nsegs = nsegs; + os->segp = 0; + + size = 0; + for (i = 0; i < nsegs; i++) + size += os->segments[i]; + + if (flags & OGG_FLAG_CONT){ + if (!os->psize){ + while (os->segp < os->nsegs){ + int seg = os->segments[os->segp++]; + os->pstart += seg; + if (seg < 255) + break; + } + } + }else{ + os->psize = 0; + } + + if (os->bufsize - os->bufpos < size){ + uint8_t *nb = av_malloc (os->bufsize *= 2); + memcpy (nb, os->buf, os->bufpos); + av_free (os->buf); + os->buf = nb; + } + + if (get_buffer (bc, os->buf + os->bufpos, size) < size) + return -1; + + os->lastgp = os->granule; + os->bufpos += size; + os->granule = gp; + os->flags = flags; + + if (str) + *str = idx; + + return 0; +} + +static int +ogg_packet (AVFormatContext * s, int *str, int *dstart, int *dsize) +{ + ogg_t *ogg = s->priv_data; + int idx; + ogg_stream_t *os; + int complete = 0; + int segp = 0, psize = 0; + +#if 0 + av_log (s, AV_LOG_DEBUG, "ogg_packet: curidx=%i\n", ogg->curidx); +#endif + + do{ + idx = ogg->curidx; + + while (idx < 0){ + if (ogg_read_page (s, &idx) < 0) + return -1; + } + + os = ogg->streams + idx; + +#if 0 + av_log (s, AV_LOG_DEBUG, + "ogg_packet: idx=%d pstart=%d psize=%d segp=%d nsegs=%d\n", + idx, os->pstart, os->psize, os->segp, os->nsegs); +#endif + + if (!os->codec){ + if (os->header < 0){ + os->codec = ogg_find_codec (os->buf, os->bufpos); + if (!os->codec){ + os->header = 0; + return 0; + } + }else{ + return 0; + } + } + + segp = os->segp; + psize = os->psize; + + while (os->segp < os->nsegs){ + int ss = os->segments[os->segp++]; + os->psize += ss; + if (ss < 255){ + complete = 1; + break; + } + } + + if (!complete && os->segp == os->nsegs){ + ogg->curidx = -1; + } + }while (!complete); + +#if 0 + av_log (s, AV_LOG_DEBUG, + "ogg_packet: idx %i, frame size %i, start %i\n", + idx, os->psize, os->pstart); +#endif + + ogg->curidx = idx; + + if (os->header < 0){ + int hdr = os->codec->header (s, idx); + if (!hdr){ + os->header = os->seq; + os->segp = segp; + os->psize = psize; + ogg->headers = 1; + }else{ + os->pstart += os->psize; + os->psize = 0; + } + } + + if (os->header > -1 && os->seq > os->header){ + os->pflags = 0; + if (os->codec && os->codec->packet) + os->codec->packet (s, idx); + if (str) + *str = idx; + if (dstart) + *dstart = os->pstart; + if (dsize) + *dsize = os->psize; + os->pstart += os->psize; + os->psize = 0; + } + + os->seq++; + if (os->segp == os->nsegs) + ogg->curidx = -1; + + return 0; +} + +static int +ogg_get_headers (AVFormatContext * s) +{ + ogg_t *ogg = s->priv_data; + + do{ + if (ogg_packet (s, NULL, NULL, NULL) < 0) + return -1; + }while (!ogg->headers); + +#if 0 + av_log (s, AV_LOG_DEBUG, "found headers\n"); +#endif + + return 0; +} + +static uint64_t +ogg_gptopts (AVFormatContext * s, int i, uint64_t gp) +{ + ogg_t *ogg = s->priv_data; + ogg_stream_t *os = ogg->streams + i; + uint64_t pts = AV_NOPTS_VALUE; + + if(os->codec->gptopts){ + pts = os->codec->gptopts(s, i, gp); + } else { + pts = gp; + } + + return pts; +} + + +static int +ogg_get_length (AVFormatContext * s) +{ + ogg_t *ogg = s->priv_data; + int idx = -1, i; + offset_t size, end; + + if(url_is_streamed(s->pb)) + return 0; + +// already set + if (s->duration != AV_NOPTS_VALUE) + return 0; + + size = url_fsize(s->pb); + if(size < 0) + return 0; + end = size > MAX_PAGE_SIZE? size - MAX_PAGE_SIZE: size; + + ogg_save (s); + url_fseek (s->pb, end, SEEK_SET); + + while (!ogg_read_page (s, &i)){ + if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 && + ogg->streams[i].codec) + idx = i; + } + + if (idx != -1){ + s->streams[idx]->duration = + ogg_gptopts (s, idx, ogg->streams[idx].granule); + } + + ogg->size = size; + ogg_restore (s, 0); + ogg_save (s); + while (!ogg_read_page (s, &i)) { + if (i == idx && ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0) + break; + } + if (i == idx) { + s->streams[idx]->start_time = ogg_gptopts (s, idx, ogg->streams[idx].granule); + s->streams[idx]->duration -= s->streams[idx]->start_time; + } + ogg_restore (s, 0); + + return 0; +} + + +static int +ogg_read_header (AVFormatContext * s, AVFormatParameters * ap) +{ + ogg_t *ogg = s->priv_data; + ogg->curidx = -1; + //linear headers seek from start + if (ogg_get_headers (s) < 0){ + return -1; + } + + //linear granulepos seek from end + ogg_get_length (s); + + //fill the extradata in the per codec callbacks + return 0; +} + + +static int +ogg_read_packet (AVFormatContext * s, AVPacket * pkt) +{ + ogg_t *ogg; + ogg_stream_t *os; + int idx = -1; + int pstart, psize; + + //Get an ogg packet + do{ + if (ogg_packet (s, &idx, &pstart, &psize) < 0) + return AVERROR(EIO); + }while (idx < 0 || !s->streams[idx]); + + ogg = s->priv_data; + os = ogg->streams + idx; + + //Alloc a pkt + if (av_new_packet (pkt, psize) < 0) + return AVERROR(EIO); + pkt->stream_index = idx; + memcpy (pkt->data, os->buf + pstart, psize); + if (os->lastgp != -1LL){ + pkt->pts = ogg_gptopts (s, idx, os->lastgp); + os->lastgp = -1; + } + + pkt->flags = os->pflags; + + return psize; +} + + +static int +ogg_read_close (AVFormatContext * s) +{ + ogg_t *ogg = s->priv_data; + int i; + + for (i = 0; i < ogg->nstreams; i++){ + av_free (ogg->streams[i].buf); + av_free (ogg->streams[i].private); + } + av_free (ogg->streams); + return 0; +} + + +static int64_t +ogg_read_timestamp (AVFormatContext * s, int stream_index, int64_t * pos_arg, + int64_t pos_limit) +{ + ogg_t *ogg = s->priv_data; + ByteIOContext *bc = s->pb; + int64_t pts = AV_NOPTS_VALUE; + int i; + url_fseek(bc, *pos_arg, SEEK_SET); + while (url_ftell(bc) < pos_limit && !ogg_read_page (s, &i)) { + if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 && + ogg->streams[i].codec && i == stream_index) { + pts = ogg_gptopts(s, i, ogg->streams[i].granule); + // FIXME: this is the position of the packet after the one with above + // pts. + *pos_arg = url_ftell(bc); + break; + } + } + ogg_reset(ogg); + return pts; +} + +static int ogg_probe(AVProbeData *p) +{ + if (p->buf[0] == 'O' && p->buf[1] == 'g' && + p->buf[2] == 'g' && p->buf[3] == 'S' && + p->buf[4] == 0x0 && p->buf[5] <= 0x7 ) + return AVPROBE_SCORE_MAX; + else + return 0; +} + +AVInputFormat ogg_demuxer = { + "ogg", + "Ogg", + sizeof (ogg_t), + ogg_probe, + ogg_read_header, + ogg_read_packet, + ogg_read_close, + NULL, + ogg_read_timestamp, + .extensions = "ogg", +}; diff --git a/contrib/ffmpeg/libavformat/oggdec.h b/contrib/ffmpeg/libavformat/oggdec.h new file mode 100644 index 000000000..4e88d0e39 --- /dev/null +++ b/contrib/ffmpeg/libavformat/oggdec.h @@ -0,0 +1,90 @@ +/** + Copyright (C) 2005 Michael Ahlberg, MÃ¥ns RullgÃ¥rd + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, copy, + modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +**/ + +#ifndef FFMPEG_OGGDEC_H +#define FFMPEG_OGGDEC_H + +#include "avformat.h" + +typedef struct ogg_codec { + const int8_t *magic; + uint8_t magicsize; + const int8_t *name; + int (*header)(AVFormatContext *, int); + int (*packet)(AVFormatContext *, int); + uint64_t (*gptopts)(AVFormatContext *, int, uint64_t); +} ogg_codec_t; + +typedef struct ogg_stream { + uint8_t *buf; + unsigned int bufsize; + unsigned int bufpos; + unsigned int pstart; + unsigned int psize; + unsigned int pflags; + uint32_t serial; + uint32_t seq; + uint64_t granule, lastgp; + int flags; + ogg_codec_t *codec; + int header; + int nsegs, segp; + uint8_t segments[255]; + void *private; +} ogg_stream_t; + +typedef struct ogg_state { + uint64_t pos; + int curidx; + struct ogg_state *next; + int nstreams; + ogg_stream_t streams[1]; +} ogg_state_t; + +typedef struct ogg { + ogg_stream_t *streams; + int nstreams; + int headers; + int curidx; + uint64_t size; + ogg_state_t *state; +} ogg_t; + +#define OGG_FLAG_CONT 1 +#define OGG_FLAG_BOS 2 +#define OGG_FLAG_EOS 4 + +extern ogg_codec_t flac_codec; +extern ogg_codec_t ogm_audio_codec; +extern ogg_codec_t ogm_old_codec; +extern ogg_codec_t ogm_text_codec; +extern ogg_codec_t ogm_video_codec; +extern ogg_codec_t old_flac_codec; +extern ogg_codec_t speex_codec; +extern ogg_codec_t theora_codec; +extern ogg_codec_t vorbis_codec; + +extern int vorbis_comment(AVFormatContext *ms, uint8_t *buf, int size); + +#endif /* FFMPEG_OGGDEC_H */ diff --git a/contrib/ffmpeg/libavformat/oggenc.c b/contrib/ffmpeg/libavformat/oggenc.c new file mode 100644 index 000000000..af2c5de12 --- /dev/null +++ b/contrib/ffmpeg/libavformat/oggenc.c @@ -0,0 +1,292 @@ +/* + * Ogg muxer + * Copyright (c) 2007 Baptiste Coudurier + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" +#include "crc.h" +#include "xiph.h" +#include "bytestream.h" + +typedef struct { + int64_t duration; + unsigned page_counter; + uint8_t *header[3]; + int header_len[3]; + /** for theora granule */ + int kfgshift; + int64_t last_kf_pts; + int vrev; + int eos; +} OGGStreamContext; + +static void ogg_update_checksum(AVFormatContext *s, offset_t crc_offset) +{ + offset_t pos = url_ftell(s->pb); + uint32_t checksum = get_checksum(s->pb); + url_fseek(s->pb, crc_offset, SEEK_SET); + put_be32(s->pb, checksum); + url_fseek(s->pb, pos, SEEK_SET); +} + +static int ogg_write_page(AVFormatContext *s, const uint8_t *data, int size, + int64_t granule, int stream_index, int flags) +{ + OGGStreamContext *oggstream = s->streams[stream_index]->priv_data; + offset_t crc_offset; + int page_segments, i; + + if (size >= 255*255) { + granule = -1; + size = 255*255; + } else if (oggstream->eos) + flags |= 4; + + page_segments = FFMIN((size/255)+!!size, 255); + + init_checksum(s->pb, ff_crc04C11DB7_update, 0); + put_tag(s->pb, "OggS"); + put_byte(s->pb, 0); + put_byte(s->pb, flags); + put_le64(s->pb, granule); + put_le32(s->pb, stream_index); + put_le32(s->pb, oggstream->page_counter++); + crc_offset = url_ftell(s->pb); + put_le32(s->pb, 0); // crc + put_byte(s->pb, page_segments); + for (i = 0; i < page_segments-1; i++) + put_byte(s->pb, 255); + if (size) { + put_byte(s->pb, size - (page_segments-1)*255); + put_buffer(s->pb, data, size); + } + ogg_update_checksum(s, crc_offset); + put_flush_packet(s->pb); + return size; +} + +static int ogg_build_flac_headers(const uint8_t *extradata, int extradata_size, + OGGStreamContext *oggstream, int bitexact) +{ + const char *vendor = bitexact ? "ffmpeg" : LIBAVFORMAT_IDENT; + uint8_t *p; + if (extradata_size != 34) + return -1; + oggstream->header_len[0] = 79; + oggstream->header[0] = av_mallocz(79); // per ogg flac specs + p = oggstream->header[0]; + bytestream_put_byte(&p, 0x7F); + bytestream_put_buffer(&p, "FLAC", 4); + bytestream_put_byte(&p, 1); // major version + bytestream_put_byte(&p, 0); // minor version + bytestream_put_be16(&p, 1); // headers packets without this one + bytestream_put_buffer(&p, "fLaC", 4); + bytestream_put_byte(&p, 0x00); // streaminfo + bytestream_put_be24(&p, 34); + bytestream_put_buffer(&p, extradata, 34); + oggstream->header_len[1] = 1+3+4+strlen(vendor)+4; + oggstream->header[1] = av_mallocz(oggstream->header_len[1]); + p = oggstream->header[1]; + bytestream_put_byte(&p, 0x84); // last metadata block and vorbis comment + bytestream_put_be24(&p, oggstream->header_len[1] - 4); + bytestream_put_le32(&p, strlen(vendor)); + bytestream_put_buffer(&p, vendor, strlen(vendor)); + bytestream_put_le32(&p, 0); // user comment list length + return 0; +} + +static int ogg_write_header(AVFormatContext *s) +{ + OGGStreamContext *oggstream; + int i, j; + for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; + if (st->codec->codec_type == CODEC_TYPE_AUDIO) + av_set_pts_info(st, 64, 1, st->codec->sample_rate); + else if (st->codec->codec_type == CODEC_TYPE_VIDEO) + av_set_pts_info(st, 64, st->codec->time_base.num, st->codec->time_base.den); + if (st->codec->codec_id != CODEC_ID_VORBIS && + st->codec->codec_id != CODEC_ID_THEORA && + st->codec->codec_id != CODEC_ID_FLAC) { + av_log(s, AV_LOG_ERROR, "Unsupported codec id in stream %d\n", i); + return -1; + } + + if (!st->codec->extradata || !st->codec->extradata_size) { + av_log(s, AV_LOG_ERROR, "No extradata present\n"); + return -1; + } + oggstream = av_mallocz(sizeof(*oggstream)); + st->priv_data = oggstream; + if (st->codec->codec_id == CODEC_ID_FLAC) { + if (ogg_build_flac_headers(st->codec->extradata, st->codec->extradata_size, + oggstream, st->codec->flags & CODEC_FLAG_BITEXACT) < 0) { + av_log(s, AV_LOG_ERROR, "Extradata corrupted\n"); + av_freep(&st->priv_data); + } + } else { + if (ff_split_xiph_headers(st->codec->extradata, st->codec->extradata_size, + st->codec->codec_id == CODEC_ID_VORBIS ? 30 : 42, + oggstream->header, oggstream->header_len) < 0) { + av_log(s, AV_LOG_ERROR, "Extradata corrupted\n"); + av_freep(&st->priv_data); + return -1; + } + if (st->codec->codec_id == CODEC_ID_THEORA) { + /** KFGSHIFT is the width of the less significant section of the granule position + The less significant section is the frame count since the last keyframe */ + oggstream->kfgshift = ((oggstream->header[0][40]&3)<<3)|(oggstream->header[0][41]>>5); + oggstream->vrev = oggstream->header[0][9]; + av_log(s, AV_LOG_DEBUG, "theora kfgshift %d, vrev %d\n", + oggstream->kfgshift, oggstream->vrev); + } + } + } + for (i = 0; i < 3; i++) { + for (j = 0; j < s->nb_streams; j++) { + AVStream *st = s->streams[j]; + OGGStreamContext *oggstream = st->priv_data; + if (oggstream && oggstream->header_len[i]) { + ogg_write_page(s, oggstream->header[i], oggstream->header_len[i], + 0, st->index, i ? 0 : 2); // bos + } + } + } + return 0; +} + +static int ogg_write_packet(AVFormatContext *s, AVPacket *pkt) +{ + AVStream *st = s->streams[pkt->stream_index]; + OGGStreamContext *oggstream = st->priv_data; + uint8_t *ptr = pkt->data; + int ret, size = pkt->size; + int64_t granule; + + if (st->codec->codec_id == CODEC_ID_THEORA) { + int64_t pts = oggstream->vrev < 1 ? pkt->pts : pkt->pts + pkt->duration; + int pframe_count; + if (pkt->flags & PKT_FLAG_KEY) + oggstream->last_kf_pts = pts; + pframe_count = pts - oggstream->last_kf_pts; + // prevent frame count from overflow if key frame flag is not set + if (pframe_count >= (1<kfgshift)) { + oggstream->last_kf_pts += pframe_count; + pframe_count = 0; + } + granule = (oggstream->last_kf_pts<kfgshift) | pframe_count; + } else + granule = pkt->pts + pkt->duration; + oggstream->duration = granule; + do { + ret = ogg_write_page(s, ptr, size, granule, pkt->stream_index, ptr != pkt->data); + ptr += ret; size -= ret; + } while (size > 0 || ret == 255*255); // need to output a last nil page + + return 0; +} + +int ogg_interleave_per_granule(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush) +{ + AVPacketList *pktl, **next_point, *this_pktl; + int stream_count = 0; + int streams[MAX_STREAMS] = {0}; + int interleaved = 0; + + if (pkt) { + AVStream *st = s->streams[pkt->stream_index]; + this_pktl = av_mallocz(sizeof(AVPacketList)); + this_pktl->pkt = *pkt; + if (pkt->destruct == av_destruct_packet) + pkt->destruct = NULL; // not shared -> must keep original from being freed + else + av_dup_packet(&this_pktl->pkt); // shared -> must dup + next_point = &s->packet_buffer; + while (*next_point) { + AVStream *st2 = s->streams[(*next_point)->pkt.stream_index]; + AVPacket *next_pkt = &(*next_point)->pkt; + int64_t cur_granule, next_granule; + next_granule = av_rescale_q(next_pkt->pts + next_pkt->duration, + st2->time_base, AV_TIME_BASE_Q); + cur_granule = av_rescale_q(pkt->pts + pkt->duration, + st->time_base, AV_TIME_BASE_Q); + if (next_granule > cur_granule) + break; + next_point= &(*next_point)->next; + } + this_pktl->next= *next_point; + *next_point= this_pktl; + } + + pktl = s->packet_buffer; + while (pktl) { + if (streams[pktl->pkt.stream_index] == 0) + stream_count++; + streams[pktl->pkt.stream_index]++; + // need to buffer at least one packet to set eos flag + if (streams[pktl->pkt.stream_index] == 2) + interleaved++; + pktl = pktl->next; + } + + if ((s->nb_streams == stream_count && interleaved == stream_count) || + (flush && stream_count)) { + pktl= s->packet_buffer; + *out= pktl->pkt; + s->packet_buffer = pktl->next; + if (flush && streams[out->stream_index] == 1) { + OGGStreamContext *ogg = s->streams[out->stream_index]->priv_data; + ogg->eos = 1; + } + av_freep(&pktl); + return 1; + } else { + av_init_packet(out); + return 0; + } +} + +static int ogg_write_trailer(AVFormatContext *s) +{ + int i; + for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; + OGGStreamContext *oggstream = st->priv_data; + if (st->codec->codec_id == CODEC_ID_FLAC) { + av_free(oggstream->header[0]); + av_free(oggstream->header[1]); + } + av_freep(&st->priv_data); + } + return 0; +} + +AVOutputFormat ogg_muxer = { + "ogg", + "Ogg format", + "application/ogg", + "ogg", + 0, + CODEC_ID_FLAC, + CODEC_ID_THEORA, + ogg_write_header, + ogg_write_packet, + ogg_write_trailer, + .interleave_packet = ogg_interleave_per_granule, +}; diff --git a/contrib/ffmpeg/libavformat/oggparseflac.c b/contrib/ffmpeg/libavformat/oggparseflac.c index 8960088d8..611a8c5a1 100644 --- a/contrib/ffmpeg/libavformat/oggparseflac.c +++ b/contrib/ffmpeg/libavformat/oggparseflac.c @@ -21,7 +21,7 @@ #include #include "avformat.h" #include "bitstream.h" -#include "ogg2.h" +#include "oggdec.h" #define FLAC_STREAMINFO_SIZE 0x22 @@ -49,7 +49,7 @@ flac_header (AVFormatContext * s, int idx) skip_bits(&gb, 4*8); /* "fLaC" */ /* METADATA_BLOCK_HEADER */ - if (get_bits(&gb, 32) != FLAC_STREAMINFO_SIZE) + if (get_bits_long(&gb, 32) != FLAC_STREAMINFO_SIZE) return -1; skip_bits(&gb, 16*2+24*2); @@ -75,8 +75,24 @@ flac_header (AVFormatContext * s, int idx) return 1; } +static int +old_flac_header (AVFormatContext * s, int idx) +{ + AVStream *st = s->streams[idx]; + st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_FLAC; + + return 0; +} + ogg_codec_t flac_codec = { .magic = "\177FLAC", .magicsize = 5, .header = flac_header }; + +ogg_codec_t old_flac_codec = { + .magic = "fLaC", + .magicsize = 4, + .header = old_flac_header +}; diff --git a/contrib/ffmpeg/libavformat/oggparseogm.c b/contrib/ffmpeg/libavformat/oggparseogm.c index 8788e5d41..70e53948f 100644 --- a/contrib/ffmpeg/libavformat/oggparseogm.c +++ b/contrib/ffmpeg/libavformat/oggparseogm.c @@ -25,8 +25,9 @@ #include #include "avformat.h" #include "bitstream.h" -#include "bswap.h" -#include "ogg2.h" +#include "bytestream.h" +#include "intreadwrite.h" +#include "oggdec.h" #include "riff.h" static int @@ -35,7 +36,7 @@ ogm_header(AVFormatContext *s, int idx) ogg_t *ogg = s->priv_data; ogg_stream_t *os = ogg->streams + idx; AVStream *st = s->streams[idx]; - uint8_t *p = os->buf + os->pstart; + const uint8_t *p = os->buf + os->pstart; uint64_t time_unit; uint64_t spu; uint32_t default_len; @@ -51,42 +52,42 @@ ogm_header(AVFormatContext *s, int idx) int tag; st->codec->codec_type = CODEC_TYPE_VIDEO; p += 8; - tag = le2me_32(unaligned32(p)); - st->codec->codec_id = codec_get_bmp_id(tag); + tag = bytestream_get_le32(&p); + st->codec->codec_id = codec_get_id(codec_bmp_tags, tag); st->codec->codec_tag = tag; + } else if (*p == 't') { + st->codec->codec_type = CODEC_TYPE_SUBTITLE; + st->codec->codec_id = CODEC_ID_TEXT; + p += 12; } else { + uint8_t acid[5]; int cid; st->codec->codec_type = CODEC_TYPE_AUDIO; p += 8; - p[4] = 0; - cid = strtol(p, NULL, 16); - st->codec->codec_id = codec_get_wav_id(cid); + bytestream_get_buffer(&p, acid, 4); + acid[4] = 0; + cid = strtol(acid, NULL, 16); + st->codec->codec_id = codec_get_id(codec_wav_tags, cid); } - p += 4; p += 4; /* useless size field */ - time_unit = le2me_64(unaligned64(p)); - p += 8; - spu = le2me_64(unaligned64(p)); - p += 8; - default_len = le2me_32(unaligned32(p)); - p += 4; + time_unit = bytestream_get_le64(&p); + spu = bytestream_get_le64(&p); + default_len = bytestream_get_le32(&p); p += 8; /* buffersize + bits_per_sample */ if(st->codec->codec_type == CODEC_TYPE_VIDEO){ - st->codec->width = le2me_32(unaligned32(p)); - p += 4; - st->codec->height = le2me_32(unaligned32(p)); + st->codec->width = bytestream_get_le32(&p); + st->codec->height = bytestream_get_le32(&p); st->codec->time_base.den = spu * 10000000; st->codec->time_base.num = time_unit; st->time_base = st->codec->time_base; } else { - st->codec->channels = le2me_16(unaligned16(p)); - p += 2; + st->codec->channels = bytestream_get_le16(&p); p += 2; /* block_align */ - st->codec->bit_rate = le2me_32(unaligned32(p)) * 8; + st->codec->bit_rate = bytestream_get_le32(&p) * 8; st->codec->sample_rate = spu * 10000000 / time_unit; st->time_base.num = 1; st->time_base.den = st->codec->sample_rate; @@ -109,21 +110,21 @@ ogm_dshow_header(AVFormatContext *s, int idx) if(*p != 1) return 1; - t = le2me_32(unaligned32(p + 96)); + t = AV_RL32(p + 96); if(t == 0x05589f80){ st->codec->codec_type = CODEC_TYPE_VIDEO; - st->codec->codec_id = codec_get_bmp_id(le2me_32(unaligned32(p + 68))); + st->codec->codec_id = codec_get_id(codec_bmp_tags, AV_RL32(p + 68)); st->codec->time_base.den = 10000000; - st->codec->time_base.num = le2me_64(unaligned64(p + 164)); - st->codec->width = le2me_32(unaligned32(p + 176)); - st->codec->height = le2me_32(unaligned32(p + 180)); + st->codec->time_base.num = AV_RL64(p + 164); + st->codec->width = AV_RL32(p + 176); + st->codec->height = AV_RL32(p + 180); } else if(t == 0x05589f81){ st->codec->codec_type = CODEC_TYPE_AUDIO; - st->codec->codec_id = codec_get_wav_id(le2me_16(unaligned16(p+124))); - st->codec->channels = le2me_16(unaligned16(p + 126)); - st->codec->sample_rate = le2me_32(unaligned32(p + 128)); - st->codec->bit_rate = le2me_32(unaligned32(p + 132)) * 8; + st->codec->codec_id = codec_get_id(codec_wav_tags, AV_RL16(p + 124)); + st->codec->channels = AV_RL16(p + 126); + st->codec->sample_rate = AV_RL32(p + 128); + st->codec->bit_rate = AV_RL32(p + 132) * 8; } return 1; @@ -137,6 +138,9 @@ ogm_packet(AVFormatContext *s, int idx) uint8_t *p = os->buf + os->pstart; int lb; + if(*p & 8) + os->pflags |= PKT_FLAG_KEY; + lb = ((*p & 2) << 1) | ((*p >> 6) & 3); os->pstart += lb + 1; os->psize -= lb + 1; @@ -158,6 +162,13 @@ ogg_codec_t ogm_audio_codec = { .packet = ogm_packet }; +ogg_codec_t ogm_text_codec = { + .magic = "\001text", + .magicsize = 5, + .header = ogm_header, + .packet = ogm_packet +}; + ogg_codec_t ogm_old_codec = { .magic = "\001Direct Show Samples embedded in Ogg", .magicsize = 35, diff --git a/contrib/ffmpeg/libavformat/oggparsespeex.c b/contrib/ffmpeg/libavformat/oggparsespeex.c new file mode 100644 index 000000000..a6c44271e --- /dev/null +++ b/contrib/ffmpeg/libavformat/oggparsespeex.c @@ -0,0 +1,61 @@ +/* + Copyright (C) 2008 Reimar Döffinger + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, copy, + modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +**/ + +#include +#include "avformat.h" +#include "bitstream.h" +#include "bytestream.h" +#include "bswap.h" +#include "oggdec.h" +#include "avstring.h" + +static int speex_header(AVFormatContext *s, int idx) { + ogg_t *ogg = s->priv_data; + ogg_stream_t *os = ogg->streams + idx; + AVStream *st = s->streams[idx]; + uint8_t *p = os->buf + os->pstart; + + if (os->psize < 80) + return 1; + + st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_SPEEX; + + st->codec->sample_rate = AV_RL32(p + 36); + st->codec->channels = AV_RL32(p + 48); + st->codec->extradata_size = os->psize; + st->codec->extradata = av_malloc(st->codec->extradata_size); + memcpy(st->codec->extradata, p, st->codec->extradata_size); + + st->time_base.num = 1; + st->time_base.den = st->codec->sample_rate; + + return 0; +} + +ogg_codec_t speex_codec = { + .magic = "Speex ", + .magicsize = 8, + .header = speex_header +}; diff --git a/contrib/ffmpeg/libavformat/oggparsetheora.c b/contrib/ffmpeg/libavformat/oggparsetheora.c index 9052bbbea..b976dcb70 100644 --- a/contrib/ffmpeg/libavformat/oggparsetheora.c +++ b/contrib/ffmpeg/libavformat/oggparsetheora.c @@ -26,7 +26,7 @@ #include "avformat.h" #include "bitstream.h" #include "bswap.h" -#include "ogg2.h" +#include "oggdec.h" typedef struct theora_params { int gpshift; @@ -53,16 +53,14 @@ theora_header (AVFormatContext * s, int idx) if (os->buf[os->pstart] == 0x80) { GetBitContext gb; + int width, height; int version; init_get_bits(&gb, os->buf + os->pstart, os->psize*8); skip_bits(&gb, 7*8); /* 0x80"theora" */ - version = get_bits(&gb, 8) << 16; - version |= get_bits(&gb, 8) << 8; - version |= get_bits(&gb, 8); - + version = get_bits_long(&gb, 24); if (version < 0x030100) { av_log(s, AV_LOG_ERROR, @@ -70,19 +68,27 @@ theora_header (AVFormatContext * s, int idx) return -1; } - st->codec->width = get_bits(&gb, 16) << 4; - st->codec->height = get_bits(&gb, 16) << 4; + width = get_bits(&gb, 16) << 4; + height = get_bits(&gb, 16) << 4; + avcodec_set_dimensions(st->codec, width, height); if (version >= 0x030400) - skip_bits(&gb, 164); - else if (version >= 0x030200) - skip_bits(&gb, 64); - st->codec->time_base.den = get_bits(&gb, 32); - st->codec->time_base.num = get_bits(&gb, 32); + skip_bits(&gb, 100); + + width = get_bits_long(&gb, 24); + height = get_bits_long(&gb, 24); + if ( width <= st->codec->width && width > st->codec->width-16 + && height <= st->codec->height && height > st->codec->height-16) + avcodec_set_dimensions(st->codec, width, height); + + if (version >= 0x030200) + skip_bits(&gb, 16); + st->codec->time_base.den = get_bits_long(&gb, 32); + st->codec->time_base.num = get_bits_long(&gb, 32); st->time_base = st->codec->time_base; - st->codec->sample_aspect_ratio.num = get_bits(&gb, 24); - st->codec->sample_aspect_ratio.den = get_bits(&gb, 24); + st->codec->sample_aspect_ratio.num = get_bits_long(&gb, 24); + st->codec->sample_aspect_ratio.den = get_bits_long(&gb, 24); if (version >= 0x030200) skip_bits(&gb, 38); @@ -118,6 +124,9 @@ theora_gptopts(AVFormatContext *ctx, int idx, uint64_t gp) uint64_t iframe = gp >> thp->gpshift; uint64_t pframe = gp & thp->gpmask; + if(!pframe) + os->pflags |= PKT_FLAG_KEY; + return iframe + pframe; } diff --git a/contrib/ffmpeg/libavformat/oggparsevorbis.c b/contrib/ffmpeg/libavformat/oggparsevorbis.c index 5de221cb4..cc914ce39 100644 --- a/contrib/ffmpeg/libavformat/oggparsevorbis.c +++ b/contrib/ffmpeg/libavformat/oggparsevorbis.c @@ -25,49 +25,44 @@ #include #include "avformat.h" #include "bitstream.h" +#include "bytestream.h" #include "bswap.h" -#include "ogg2.h" +#include "oggdec.h" +#include "avstring.h" extern int -vorbis_comment (AVFormatContext * as, uint8_t *buf, int size) +vorbis_comment(AVFormatContext * as, uint8_t *buf, int size) { - char *p = buf; - int s, n, j; + const uint8_t *p = buf; + const uint8_t *end = buf + size; + unsigned s, n, j; - if (size < 4) + if (size < 8) /* must have vendor_length and user_comment_list_length */ return -1; - s = le2me_32 (unaligned32 (p)); - p += 4; - size -= 4; + s = bytestream_get_le32(&p); - if (size < s + 4) + if (end - p < s) return -1; p += s; - size -= s; - n = le2me_32 (unaligned32 (p)); - p += 4; - size -= 4; + n = bytestream_get_le32(&p); - while (size >= 4){ - char *t, *v; + while (p < end && n > 0) { + const char *t, *v; int tl, vl; - s = le2me_32 (unaligned32 (p)); - p += 4; - size -= 4; + s = bytestream_get_le32(&p); - if (size < s) + if (end - p < s) break; t = p; p += s; - size -= s; n--; - v = memchr (t, '=', s); + v = memchr(t, '=', s); if (!v) continue; @@ -75,39 +70,40 @@ vorbis_comment (AVFormatContext * as, uint8_t *buf, int size) vl = s - tl - 1; v++; - if (tl && vl){ + if (tl && vl) { char tt[tl + 1]; char ct[vl + 1]; for (j = 0; j < tl; j++) - tt[j] = toupper (t[j]); + tt[j] = toupper(t[j]); tt[tl] = 0; - memcpy (ct, v, vl); + memcpy(ct, v, vl); ct[vl] = 0; // took from Vorbis_I_spec - if (!strcmp (tt, "AUTHOR")) - strncpy (as->author, ct, FFMIN(sizeof (as->author), vl)); - else if (!strcmp (tt, "TITLE")) - strncpy (as->title, ct, FFMIN(sizeof (as->title), vl)); - else if (!strcmp (tt, "COPYRIGHT")) - strncpy (as->copyright, ct, FFMIN(sizeof (as->copyright), vl)); - else if (!strcmp (tt, "DESCRIPTION")) - strncpy (as->comment, ct, FFMIN(sizeof (as->comment), vl)); - else if (!strcmp (tt, "GENRE")) - strncpy (as->genre, ct, FFMIN(sizeof (as->genre), vl)); - else if (!strcmp (tt, "TRACKNUMBER")) - as->track = atoi (ct); - //Too bored to add others for today + if (!strcmp(tt, "AUTHOR") || !strcmp(tt, "ARTIST")) + av_strlcpy(as->author, ct, sizeof(as->author)); + else if (!strcmp(tt, "TITLE")) + av_strlcpy(as->title, ct, sizeof(as->title)); + else if (!strcmp(tt, "COPYRIGHT")) + av_strlcpy(as->copyright, ct, sizeof(as->copyright)); + else if (!strcmp(tt, "DESCRIPTION")) + av_strlcpy(as->comment, ct, sizeof(as->comment)); + else if (!strcmp(tt, "GENRE")) + av_strlcpy(as->genre, ct, sizeof(as->genre)); + else if (!strcmp(tt, "TRACKNUMBER")) + as->track = atoi(ct); + else if (!strcmp(tt, "ALBUM")) + av_strlcpy(as->album, ct, sizeof(as->album)); } } - if (size > 0) - av_log (as, AV_LOG_INFO, "%i bytes of comment header remain\n", size); + if (p != end) + av_log(as, AV_LOG_INFO, "%ti bytes of comment header remain\n", p-end); if (n > 0) - av_log (as, AV_LOG_INFO, - "truncated comment header, %i comments not found\n", n); + av_log(as, AV_LOG_INFO, + "truncated comment header, %i comments not found\n", n); return 0; } @@ -134,7 +130,7 @@ typedef struct { static unsigned int fixup_vorbis_headers(AVFormatContext * as, oggvorbis_private_t *priv, - void **buf) + uint8_t **buf) { int i,offset, len; unsigned char *ptr; @@ -146,7 +142,7 @@ fixup_vorbis_headers(AVFormatContext * as, oggvorbis_private_t *priv, offset = 1; offset += av_xiphlacing(&ptr[offset], priv->len[0]); offset += av_xiphlacing(&ptr[offset], priv->len[1]); - for(i = 0; i < 3; i++) { + for (i = 0; i < 3; i++) { memcpy(&ptr[offset], priv->packet[i], priv->len[i]); offset += priv->len[i]; } @@ -166,22 +162,46 @@ vorbis_header (AVFormatContext * s, int idx) if (os->seq > 2) return 0; - if(os->seq == 0) { + if (os->seq == 0) { os->private = av_mallocz(sizeof(oggvorbis_private_t)); - if(!os->private) + if (!os->private) return 0; } + if (os->psize < 1) + return -1; + priv = os->private; priv->len[os->seq] = os->psize; priv->packet[os->seq] = av_mallocz(os->psize); memcpy(priv->packet[os->seq], os->buf + os->pstart, os->psize); if (os->buf[os->pstart] == 1) { - uint8_t *p = os->buf + os->pstart + 11; //skip up to the audio channels - st->codec->channels = *p++; - st->codec->sample_rate = le2me_32 (unaligned32 (p)); - p += 8; //skip maximum and and nominal bitrate - st->codec->bit_rate = le2me_32 (unaligned32 (p)); //Minimum bitrate + const uint8_t *p = os->buf + os->pstart + 7; /* skip "\001vorbis" tag */ + unsigned blocksize, bs0, bs1; + + if (os->psize != 30) + return -1; + + if (bytestream_get_le32(&p) != 0) /* vorbis_version */ + return -1; + + st->codec->channels = bytestream_get_byte(&p); + st->codec->sample_rate = bytestream_get_le32(&p); + p += 4; // skip maximum bitrate + st->codec->bit_rate = bytestream_get_le32(&p); // nominal bitrate + p += 4; // skip minimum bitrate + + blocksize = bytestream_get_byte(&p); + bs0 = blocksize & 15; + bs1 = blocksize >> 4; + + if (bs0 > bs1) + return -1; + if (bs0 < 6 || bs1 > 13) + return -1; + + if (bytestream_get_byte(&p) != 1) /* framing_flag */ + return -1; st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_VORBIS; @@ -189,7 +209,8 @@ vorbis_header (AVFormatContext * s, int idx) st->time_base.num = 1; st->time_base.den = st->codec->sample_rate; } else if (os->buf[os->pstart] == 3) { - vorbis_comment (s, os->buf + os->pstart + 7, os->psize - 8); + if (os->psize > 8) + vorbis_comment (s, os->buf + os->pstart + 7, os->psize - 8); } else { st->codec->extradata_size = fixup_vorbis_headers(s, priv, &st->codec->extradata); diff --git a/contrib/ffmpeg/libavformat/os_support.c b/contrib/ffmpeg/libavformat/os_support.c index 7a4be8fa7..cc109d596 100644 --- a/contrib/ffmpeg/libavformat/os_support.c +++ b/contrib/ffmpeg/libavformat/os_support.c @@ -21,90 +21,69 @@ */ #include "config.h" #include "avformat.h" -#if defined(CONFIG_WINCE) -/* Skip includes on WinCE. */ -#elif defined(__MINGW32__) -#include -#include -#elif defined(CONFIG_OS2) -#include -#include -#else #include #include -#include -#endif -#include +#include "os_support.h" -#ifndef HAVE_SYS_POLL_H -#if defined(__MINGW32__) +#ifdef CONFIG_NETWORK +#ifndef HAVE_POLL_H +#ifdef HAVE_WINSOCK2_H #include -#else +#elif defined (HAVE_SYS_SELECT_H) #include #endif #endif -/** - * gets the current time in micro seconds. - */ -int64_t av_gettime(void) -{ -#if defined(CONFIG_WINCE) - return timeGetTime() * INT64_C(1000); -#elif defined(__MINGW32__) - struct timeb tb; - _ftime(&tb); - return ((int64_t)tb.time * INT64_C(1000) + (int64_t)tb.millitm) * INT64_C(1000); -#else - struct timeval tv; - gettimeofday(&tv,NULL); - return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec; -#endif -} - -#if !defined(CONFIG_WINCE) && !defined(HAVE_LOCALTIME_R) -struct tm *localtime_r(const time_t *t, struct tm *tp) -{ - struct tm *l; - - l = localtime(t); - if (!l) - return 0; - *tp = *l; - return tp; -} -#endif /* !defined(CONFIG_WINCE) && !defined(HAVE_LOCALTIME_R) */ +#include "network.h" -#if !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK) +#if !defined(HAVE_INET_ATON) #include #include -#include "network.h" int inet_aton (const char * str, struct in_addr * add) { - const char * pch = str; unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0; - add1 = atoi(pch); - pch = strpbrk(pch,"."); - if (pch == 0 || ++pch == 0) goto done; - add2 = atoi(pch); - pch = strpbrk(pch,"."); - if (pch == 0 || ++pch == 0) goto done; - add3 = atoi(pch); - pch = strpbrk(pch,"."); - if (pch == 0 || ++pch == 0) goto done; - add4 = atoi(pch); - -done: + if (sscanf(str, "%d.%d.%d.%d", &add1, &add2, &add3, &add4) != 4) + return 0; + + if (!add1 || (add1|add2|add3|add4) > 255) return 0; + add->s_addr=(add4<<24)+(add3<<16)+(add2<<8)+add1; return 1; } -#endif /* !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK) */ +#endif /* !defined(HAVE_INET_ATON) */ + +/* resolve host with also IP address parsing */ +int resolve_host(struct in_addr *sin_addr, const char *hostname) +{ + struct hostent *hp; + + if (!inet_aton(hostname, sin_addr)) { + hp = gethostbyname(hostname); + if (!hp) + return -1; + memcpy(sin_addr, hp->h_addr, sizeof(struct in_addr)); + } + return 0; +} + +int ff_socket_nonblock(int socket, int enable) +{ +#ifdef HAVE_WINSOCK2_H + return ioctlsocket(socket, FIONBIO, &enable); +#else + if (enable) + return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) | O_NONBLOCK); + else + return fcntl(socket, F_SETFL, fcntl(socket, F_GETFL) & ~O_NONBLOCK); +#endif +} +#endif /* CONFIG_NETWORK */ #ifdef CONFIG_FFSERVER -#ifndef HAVE_SYS_POLL_H +#ifndef HAVE_POLL_H int poll(struct pollfd *fds, nfds_t numfds, int timeout) { fd_set read_set; @@ -114,6 +93,13 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout) int n; int rc; +#ifdef HAVE_WINSOCK2_H + if (numfds >= FD_SETSIZE) { + errno = EINVAL; + return -1; + } +#endif + FD_ZERO(&read_set); FD_ZERO(&write_set); FD_ZERO(&exception_set); @@ -122,10 +108,12 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout) for(i = 0; i < numfds; i++) { if (fds[i].fd < 0) continue; +#ifndef HAVE_WINSOCK2_H if (fds[i].fd >= FD_SETSIZE) { errno = EINVAL; return -1; } +#endif if (fds[i].events & POLLIN) FD_SET(fds[i].fd, &read_set); if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &write_set); @@ -162,6 +150,6 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout) return rc; } -#endif /* HAVE_SYS_POLL_H */ +#endif /* HAVE_POLL_H */ #endif /* CONFIG_FFSERVER */ diff --git a/contrib/ffmpeg/libavformat/os_support.h b/contrib/ffmpeg/libavformat/os_support.h index 424d6dabd..67d586ab6 100644 --- a/contrib/ffmpeg/libavformat/os_support.h +++ b/contrib/ffmpeg/libavformat/os_support.h @@ -19,23 +19,15 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _OS_SUPPORT_H -#define _OS_SUPPORT_H +#ifndef FFMPEG_OS_SUPPORT_H +#define FFMPEG_OS_SUPPORT_H /** * @file os_support.h * miscellaneous OS support macros and functions. - * - * - socklen_t typedef (BeOS, Innotek libc) - * - usleep() (Win32, BeOS, OS/2) - * - lseek() (Win32) - * - floatf() (OS/2) - * - strcasecmp() (OS/2) - * - closesocket() - * - poll() (BeOS, MinGW) */ -#if defined(__BEOS__) || defined(__INNOTEK_LIBC__) +#ifndef HAVE_SOCKLEN_T typedef int socklen_t; #endif @@ -45,16 +37,12 @@ __declspec(dllimport) void __stdcall Sleep(unsigned long dwMilliseconds); # define usleep(t) Sleep((t) / 1000) # include # define lseek(f,p,w) _lseeki64((f), (p), (w)) -# define HAVE_CLOSESOCKET 1 #endif #ifdef __BEOS__ # include # include /* not net_server ? */ -# if IPPROTO_TCP != 6 -# define HAVE_CLOSESOCKET 1 -# endif # include /* R5 didn't have usleep, fake it. Haiku and Zeta has it now. */ # if B_BEOS_VERSION <= B_BEOS_VERSION_5 @@ -68,19 +56,13 @@ __declspec(dllimport) void __stdcall Sleep(unsigned long dwMilliseconds); # endif #endif -#if defined(CONFIG_OS2) -#include -static inline int usleep(unsigned int t) { return _sleep2(t / 1000); } -static inline int strcasecmp(const char* s1, const char* s2) { return stricmp(s1,s2); } -#endif - /* most of the time closing a socket is just closing an fd */ -#if HAVE_CLOSESOCKET != 1 +#ifndef HAVE_CLOSESOCKET #define closesocket close #endif #ifdef CONFIG_FFSERVER -#ifndef HAVE_SYS_POLL_H +#ifndef HAVE_POLL_H typedef unsigned long nfds_t; struct pollfd { @@ -105,7 +87,7 @@ struct pollfd { extern int poll(struct pollfd *fds, nfds_t numfds, int timeout); -#endif /* HAVE_SYS_POLL_H */ +#endif /* HAVE_POLL_H */ #endif /* CONFIG_FFSERVER */ -#endif /* _OS_SUPPORT_H */ +#endif /* FFMPEG_OS_SUPPORT_H */ diff --git a/contrib/ffmpeg/libavformat/psxstr.c b/contrib/ffmpeg/libavformat/psxstr.c index 2f1a3dc73..3d4cac7f8 100644 --- a/contrib/ffmpeg/libavformat/psxstr.c +++ b/contrib/ffmpeg/libavformat/psxstr.c @@ -125,8 +125,8 @@ static void dump(unsigned char *buf,size_t len) static int str_read_header(AVFormatContext *s, AVFormatParameters *ap) { - ByteIOContext *pb = &s->pb; - StrDemuxContext *str = (StrDemuxContext *)s->priv_data; + ByteIOContext *pb = s->pb; + StrDemuxContext *str = s->priv_data; AVStream *st; unsigned char sector[RAW_CD_SECTOR_SIZE]; int start; @@ -142,7 +142,7 @@ static int str_read_header(AVFormatContext *s, /* skip over any RIFF header */ if (get_buffer(pb, sector, RIFF_HEADER_SIZE) != RIFF_HEADER_SIZE) - return AVERROR_IO; + return AVERROR(EIO); if (AV_RL32(§or[0]) == RIFF_TAG) start = RIFF_HEADER_SIZE; else @@ -153,7 +153,7 @@ static int str_read_header(AVFormatContext *s, /* check through the first 32 sectors for individual channels */ for (i = 0; i < 32; i++) { if (get_buffer(pb, sector, RAW_CD_SECTOR_SIZE) != RAW_CD_SECTOR_SIZE) - return AVERROR_IO; + return AVERROR(EIO); //printf("%02x %02x %02x %02x\n",sector[0x10],sector[0x11],sector[0x12],sector[0x13]); @@ -178,7 +178,7 @@ static int str_read_header(AVFormatContext *s, /* allocate a new AVStream */ st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 64, 1, 15); str->channels[channel].video_stream_index = st->index; @@ -207,7 +207,7 @@ static int str_read_header(AVFormatContext *s, /* allocate a new AVStream */ st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 64, 128, str->channels[channel].sample_rate); str->channels[channel].audio_stream_index = st->index; @@ -249,8 +249,8 @@ if (str->audio_channel != -1) static int str_read_packet(AVFormatContext *s, AVPacket *ret_pkt) { - ByteIOContext *pb = &s->pb; - StrDemuxContext *str = (StrDemuxContext *)s->priv_data; + ByteIOContext *pb = s->pb; + StrDemuxContext *str = s->priv_data; unsigned char sector[RAW_CD_SECTOR_SIZE]; int channel; int packet_read = 0; @@ -260,7 +260,7 @@ static int str_read_packet(AVFormatContext *s, while (!packet_read) { if (get_buffer(pb, sector, RAW_CD_SECTOR_SIZE) != RAW_CD_SECTOR_SIZE) - return AVERROR_IO; + return AVERROR(EIO); channel = sector[0x11]; if (channel >= 32) @@ -282,7 +282,7 @@ static int str_read_packet(AVFormatContext *s, pkt = &str->tmp_pkt; if (current_sector == 0) { if (av_new_packet(pkt, frame_size)) - return AVERROR_IO; + return AVERROR(EIO); pkt->pos= url_ftell(pb) - RAW_CD_SECTOR_SIZE; pkt->stream_index = @@ -319,7 +319,7 @@ printf (" dropping audio sector\n"); if (channel == str->audio_channel) { pkt = ret_pkt; if (av_new_packet(pkt, 2304)) - return AVERROR_IO; + return AVERROR(EIO); memcpy(pkt->data,sector+24,2304); pkt->stream_index = @@ -338,7 +338,7 @@ printf (" dropping other sector\n"); } if (url_feof(pb)) - return AVERROR_IO; + return AVERROR(EIO); } return ret; @@ -346,7 +346,7 @@ printf (" dropping other sector\n"); static int str_read_close(AVFormatContext *s) { - StrDemuxContext *str = (StrDemuxContext *)s->priv_data; + StrDemuxContext *str = s->priv_data; av_free(str->video_chunk); diff --git a/contrib/ffmpeg/libavformat/pva.c b/contrib/ffmpeg/libavformat/pva.c new file mode 100644 index 000000000..03b92bf3d --- /dev/null +++ b/contrib/ffmpeg/libavformat/pva.c @@ -0,0 +1,211 @@ +/* + * TechnoTrend PVA (.pva) demuxer + * Copyright (c) 2007, 2008 Ivo van Poorten + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" +#include "mpeg.h" + +#define PVA_MAX_PAYLOAD_LENGTH 0x17f8 +#define PVA_VIDEO_PAYLOAD 0x01 +#define PVA_AUDIO_PAYLOAD 0x02 +#define PVA_MAGIC (('A' << 8) + 'V') + +typedef struct { + int continue_pes; +} PVAContext; + +static int pva_probe(AVProbeData * pd) { + unsigned char *buf = pd->buf; + + if (AV_RB16(buf) == PVA_MAGIC && buf[2] && buf[2] < 3 && buf[4] == 0x55) + return AVPROBE_SCORE_MAX / 2; + + return 0; +} + +static int pva_read_header(AVFormatContext *s, AVFormatParameters *ap) { + AVStream *st; + + if (!(st = av_new_stream(s, 0))) + return AVERROR(ENOMEM); + st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_MPEG2VIDEO; + st->need_parsing = AVSTREAM_PARSE_FULL; + av_set_pts_info(st, 32, 1, 90000); + av_add_index_entry(st, 0, 0, 0, 0, AVINDEX_KEYFRAME); + + if (!(st = av_new_stream(s, 1))) + return AVERROR(ENOMEM); + st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_MP2; + st->need_parsing = AVSTREAM_PARSE_HEADERS; + av_set_pts_info(st, 33, 1, 90000); + av_add_index_entry(st, 0, 0, 0, 0, AVINDEX_KEYFRAME); + + /* the parameters will be extracted from the compressed bitstream */ + return 0; +} + +#define pva_log if (read_packet) av_log + +static int read_part_of_packet(AVFormatContext *s, int64_t *pts, + int *len, int *strid, int read_packet) { + ByteIOContext *pb = s->pb; + PVAContext *pvactx = s->priv_data; + int syncword, streamid, reserved, flags, length, pts_flag; + int64_t pva_pts = AV_NOPTS_VALUE, startpos; + +recover: + startpos = url_ftell(pb); + + syncword = get_be16(pb); + streamid = get_byte(pb); + get_byte(pb); /* counter not used */ + reserved = get_byte(pb); + flags = get_byte(pb); + length = get_be16(pb); + + pts_flag = flags & 0x10; + + if (syncword != PVA_MAGIC) { + pva_log(s, AV_LOG_ERROR, "invalid syncword\n"); + return AVERROR(EIO); + } + if (streamid != PVA_VIDEO_PAYLOAD && streamid != PVA_AUDIO_PAYLOAD) { + pva_log(s, AV_LOG_ERROR, "invalid streamid\n"); + return AVERROR(EIO); + } + if (reserved != 0x55) { + pva_log(s, AV_LOG_WARNING, "expected reserved byte to be 0x55\n"); + } + if (length > PVA_MAX_PAYLOAD_LENGTH) { + pva_log(s, AV_LOG_ERROR, "invalid payload length %u\n", length); + return AVERROR(EIO); + } + + if (streamid == PVA_VIDEO_PAYLOAD && pts_flag) { + pva_pts = get_be32(pb); + length -= 4; + } else if (streamid == PVA_AUDIO_PAYLOAD) { + /* PVA Audio Packets either start with a signaled PES packet or + * are a continuation of the previous PES packet. New PES packets + * always start at the beginning of a PVA Packet, never somewhere in + * the middle. */ + if (!pvactx->continue_pes) { + int pes_signal, pes_header_data_length, pes_packet_length, + pes_flags; + unsigned char pes_header_data[256]; + + pes_signal = get_be24(pb); + get_byte(pb); + pes_packet_length = get_be16(pb); + pes_flags = get_be16(pb); + pes_header_data_length = get_byte(pb); + + if (pes_signal != 1) { + pva_log(s, AV_LOG_WARNING, "expected signaled PES packet, " + "trying to recover\n"); + url_fskip(pb, length - 9); + if (!read_packet) + return AVERROR(EIO); + goto recover; + } + + get_buffer(pb, pes_header_data, pes_header_data_length); + length -= 9 + pes_header_data_length; + + pes_packet_length -= 3 + pes_header_data_length; + + pvactx->continue_pes = pes_packet_length; + + if (pes_flags & 0x80 && (pes_header_data[0] & 0xf0) == 0x20) + pva_pts = ff_parse_pes_pts(pes_header_data); + } + + pvactx->continue_pes -= length; + + if (pvactx->continue_pes < 0) { + pva_log(s, AV_LOG_WARNING, "audio data corruption\n"); + pvactx->continue_pes = 0; + } + } + + if (pva_pts != AV_NOPTS_VALUE) + av_add_index_entry(s->streams[streamid-1], startpos, pva_pts, 0, 0, AVINDEX_KEYFRAME); + + *pts = pva_pts; + *len = length; + *strid = streamid; + return 0; +} + +static int pva_read_packet(AVFormatContext *s, AVPacket *pkt) { + ByteIOContext *pb = s->pb; + int64_t pva_pts; + int ret, length, streamid; + + if (read_part_of_packet(s, &pva_pts, &length, &streamid, 1) < 0 || + (ret = av_get_packet(pb, pkt, length)) <= 0) + return AVERROR(EIO); + + pkt->stream_index = streamid - 1; + pkt->pts = pva_pts; + + return ret; +} + +static int64_t pva_read_timestamp(struct AVFormatContext *s, int stream_index, + int64_t *pos, int64_t pos_limit) { + ByteIOContext *pb = s->pb; + PVAContext *pvactx = s->priv_data; + int length, streamid; + int64_t res; + + pos_limit = FFMIN(*pos+PVA_MAX_PAYLOAD_LENGTH*8, (uint64_t)*pos+pos_limit); + + while (*pos < pos_limit) { + res = AV_NOPTS_VALUE; + url_fseek(pb, *pos, SEEK_SET); + + pvactx->continue_pes = 0; + if (read_part_of_packet(s, &res, &length, &streamid, 0)) { + (*pos)++; + continue; + } + if (streamid - 1 != stream_index || res == AV_NOPTS_VALUE) { + *pos = url_ftell(pb) + length; + continue; + } + break; + } + + pvactx->continue_pes = 0; + return res; +} + +AVInputFormat pva_demuxer = { + "pva", + "pva file and stream format", + sizeof(PVAContext), + pva_probe, + pva_read_header, + pva_read_packet, + .read_timestamp = pva_read_timestamp +}; diff --git a/contrib/ffmpeg/libavformat/qtpalette.h b/contrib/ffmpeg/libavformat/qtpalette.h index 183600fde..0c6c44f47 100644 --- a/contrib/ffmpeg/libavformat/qtpalette.h +++ b/contrib/ffmpeg/libavformat/qtpalette.h @@ -20,17 +20,19 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef QTPALETTE_H -#define QTPALETTE_H +#ifndef FFMPEG_QTPALETTE_H +#define FFMPEG_QTPALETTE_H -unsigned char ff_qt_default_palette_4[4 * 4] = { +#include + +static const uint8_t ff_qt_default_palette_4[4 * 4] = { 0x93, 0x65, 0x5E, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0xDF, 0xD0, 0xAB, 0x00, 0x00, 0x00, 0x00, 0x00 }; -unsigned char ff_qt_default_palette_16[16 * 4] = { +static const uint8_t ff_qt_default_palette_16[16 * 4] = { 0xFF, 0xFB, 0xFF, 0x00, 0xEF, 0xD9, 0xBB, 0x00, 0xE8, 0xC9, 0xB1, 0x00, @@ -49,7 +51,7 @@ unsigned char ff_qt_default_palette_16[16 * 4] = { 0x00, 0x00, 0x00, 0x00 }; -unsigned char ff_qt_default_palette_256[256 * 4] = { +static const uint8_t ff_qt_default_palette_256[256 * 4] = { /* 0, 0x00 */ 0xFF, 0xFF, 0xFF, 0x00, /* 1, 0x01 */ 0xFF, 0xFF, 0xCC, 0x00, /* 2, 0x02 */ 0xFF, 0xFF, 0x99, 0x00, @@ -308,4 +310,4 @@ unsigned char ff_qt_default_palette_256[256 * 4] = { /* 255, 0xFF */ 0x00, 0x00, 0x00, 0x00 }; -#endif +#endif /* FFMPEG_QTPALETTE_H */ diff --git a/contrib/ffmpeg/libavformat/raw.c b/contrib/ffmpeg/libavformat/raw.c index 73a20379a..d4b138953 100644 --- a/contrib/ffmpeg/libavformat/raw.c +++ b/contrib/ffmpeg/libavformat/raw.c @@ -20,15 +20,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avformat.h" -#include "ac3.h" +#include "ac3_parser.h" +#include "raw.h" #ifdef CONFIG_MUXERS /* simple formats */ -static int raw_write_header(struct AVFormatContext *s) -{ - return 0; -} - static int flac_write_header(struct AVFormatContext *s) { static const uint8_t header[8] = { @@ -37,21 +33,29 @@ static int flac_write_header(struct AVFormatContext *s) uint8_t *streaminfo = s->streams[0]->codec->extradata; int len = s->streams[0]->codec->extradata_size; if(streaminfo != NULL && len > 0) { - put_buffer(&s->pb, header, 8); - put_buffer(&s->pb, streaminfo, len); + put_buffer(s->pb, header, 8); + put_buffer(s->pb, streaminfo, len); } return 0; } -static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt) + +static int roq_write_header(struct AVFormatContext *s) { - put_buffer(&s->pb, pkt->data, pkt->size); - put_flush_packet(&s->pb); + static const uint8_t header[] = { + 0x84, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x1E, 0x00 + }; + + put_buffer(s->pb, header, 8); + put_flush_packet(s->pb); + return 0; } -static int raw_write_trailer(struct AVFormatContext *s) +static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt) { + put_buffer(s->pb, pkt->data, pkt->size); + put_flush_packet(s->pb); return 0; } #endif //CONFIG_MUXERS @@ -64,7 +68,7 @@ static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap) st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); id = s->iformat->value; if (id == CODEC_ID_RAWVIDEO) { @@ -81,7 +85,10 @@ static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap) av_set_pts_info(st, 64, 1, st->codec->sample_rate); break; case CODEC_TYPE_VIDEO: - av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den); + if(ap->time_base.num) + av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den); + else + av_set_pts_info(st, 64, 1, 25); st->codec->width = ap->width; st->codec->height = ap->height; st->codec->pix_fmt = ap->pix_fmt; @@ -98,20 +105,26 @@ static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap) static int raw_read_packet(AVFormatContext *s, AVPacket *pkt) { - int ret, size; + int ret, size, bps; // AVStream *st = s->streams[0]; size= RAW_PACKET_SIZE; - ret= av_get_packet(&s->pb, pkt, size); + ret= av_get_packet(s->pb, pkt, size); pkt->stream_index = 0; if (ret <= 0) { - return AVERROR_IO; + return AVERROR(EIO); } /* note: we need to modify the packet size here to handle the last packet */ pkt->size = ret; + + bps= av_get_bits_per_sample(s->streams[0]->codec->codec_id); + assert(bps); // if false there IS a bug elsewhere (NOT in this function) + pkt->dts= + pkt->pts= pkt->pos*8 / (bps * s->streams[0]->codec->channels); + return ret; } @@ -122,14 +135,14 @@ static int raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt) size = RAW_PACKET_SIZE; if (av_new_packet(pkt, size) < 0) - return AVERROR_IO; + return AVERROR(EIO); - pkt->pos= url_ftell(&s->pb); + pkt->pos= url_ftell(s->pb); pkt->stream_index = 0; - ret = get_partial_buffer(&s->pb, pkt->data, size); + ret = get_partial_buffer(s->pb, pkt->data, size); if (ret <= 0) { av_free_packet(pkt); - return AVERROR_IO; + return AVERROR(EIO); } pkt->size = ret; return ret; @@ -140,32 +153,32 @@ static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt) { int ret, size, w, h, unk1, unk2; - if (get_le32(&s->pb) != MKTAG('M', 'J', 'P', 'G')) - return AVERROR_IO; // FIXME + if (get_le32(s->pb) != MKTAG('M', 'J', 'P', 'G')) + return AVERROR(EIO); // FIXME - size = get_le32(&s->pb); + size = get_le32(s->pb); - w = get_le16(&s->pb); - h = get_le16(&s->pb); + w = get_le16(s->pb); + h = get_le16(s->pb); - url_fskip(&s->pb, 8); // zero + size (padded?) - url_fskip(&s->pb, 2); - unk1 = get_le16(&s->pb); - unk2 = get_le16(&s->pb); - url_fskip(&s->pb, 22); // ascii timestamp + url_fskip(s->pb, 8); // zero + size (padded?) + url_fskip(s->pb, 2); + unk1 = get_le16(s->pb); + unk2 = get_le16(s->pb); + url_fskip(s->pb, 22); // ascii timestamp av_log(NULL, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n", size, w, h, unk1, unk2); if (av_new_packet(pkt, size) < 0) - return AVERROR_IO; + return AVERROR(EIO); - pkt->pos = url_ftell(&s->pb); + pkt->pos = url_ftell(s->pb); pkt->stream_index = 0; - ret = get_buffer(&s->pb, pkt->data, size); + ret = get_buffer(s->pb, pkt->data, size); if (ret <= 0) { av_free_packet(pkt); - return AVERROR_IO; + return AVERROR(EIO); } pkt->size = ret; return ret; @@ -202,7 +215,7 @@ int pcm_read_seek(AVFormatContext *s, /* recompute exact position */ st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num); - url_fseek(&s->pb, pos + s->data_offset, SEEK_SET); + url_fseek(s->pb, pos + s->data_offset, SEEK_SET); return 0; } @@ -214,11 +227,11 @@ static int ac3_read_header(AVFormatContext *s, st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_AC3; - st->need_parsing = 1; + st->need_parsing = AVSTREAM_PARSE_FULL; /* the parameters will be extracted from the compressed bitstream */ return 0; } @@ -230,10 +243,10 @@ static int shorten_read_header(AVFormatContext *s, st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_SHORTEN; - st->need_parsing = 1; + st->need_parsing = AVSTREAM_PARSE_FULL; /* the parameters will be extracted from the compressed bitstream */ return 0; } @@ -246,10 +259,10 @@ static int flac_read_header(AVFormatContext *s, st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_FLAC; - st->need_parsing = 1; + st->need_parsing = AVSTREAM_PARSE_FULL; /* the parameters will be extracted from the compressed bitstream */ return 0; } @@ -262,11 +275,11 @@ static int dts_read_header(AVFormatContext *s, st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_DTS; - st->need_parsing = 1; + st->need_parsing = AVSTREAM_PARSE_FULL; /* the parameters will be extracted from the compressed bitstream */ return 0; } @@ -279,11 +292,11 @@ static int aac_read_header(AVFormatContext *s, st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_AAC; - st->need_parsing = 1; + st->need_parsing = AVSTREAM_PARSE_FULL; /* the parameters will be extracted from the compressed bitstream */ return 0; } @@ -296,14 +309,14 @@ static int video_read_header(AVFormatContext *s, st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = s->iformat->value; - st->need_parsing = 1; + st->need_parsing = AVSTREAM_PARSE_FULL; /* for mjpeg, specify frame rate */ - /* for mpeg4 specify it too (most mpeg4 streams dont have the fixed_vop_rate set ...)*/ + /* for mpeg4 specify it too (most mpeg4 streams do not have the fixed_vop_rate set ...)*/ if (ap->time_base.num) { av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den); } else if ( st->codec->codec_id == CODEC_ID_MJPEG || @@ -347,32 +360,29 @@ static int mpegvideo_probe(AVProbeData *p) return 0; } -#define VIDEO_OBJECT_START_CODE 0x00000100 -#define VIDEO_OBJECT_LAYER_START_CODE 0x00000120 #define VISUAL_OBJECT_START_CODE 0x000001b5 #define VOP_START_CODE 0x000001b6 static int mpeg4video_probe(AVProbeData *probe_packet) { uint32_t temp_buffer= -1; - int VO=0, VOL=0, VOP = 0, VISO = 0; + int VO=0, VOL=0, VOP = 0, VISO = 0, res=0; int i; for(i=0; ibuf_size; i++){ temp_buffer = (temp_buffer<<8) + probe_packet->buf[i]; - if ((temp_buffer & 0xffffff00) == 0x100) { - switch(temp_buffer){ - case VOP_START_CODE: VOP++; break; - case VISUAL_OBJECT_START_CODE: VISO++; break; - } - switch(temp_buffer & 0xfffffff0){ - case VIDEO_OBJECT_START_CODE: VO++; break; - case VIDEO_OBJECT_LAYER_START_CODE: VOL++; break; - } - } + if ((temp_buffer & 0xffffff00) != 0x100) + continue; + + if (temp_buffer == VOP_START_CODE) VOP++; + else if (temp_buffer == VISUAL_OBJECT_START_CODE) VISO++; + else if (temp_buffer < 0x120) VO++; + else if (temp_buffer < 0x130) VOL++; + else if ( !(0x1AF < temp_buffer && temp_buffer < 0x1B7) + && !(0x1B9 < temp_buffer && temp_buffer < 0x1C4)) res++; } - if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0) + if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0) return AVPROBE_SCORE_MAX/2; return 0; } @@ -382,8 +392,6 @@ static int h263_probe(AVProbeData *p) int code; const uint8_t *d; - if (p->buf_size < 6) - return 0; d = p->buf; code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2); if (code == 0x20) { @@ -397,8 +405,6 @@ static int h261_probe(AVProbeData *p) int code; const uint8_t *d; - if (p->buf_size < 6) - return 0; d = p->buf; code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4); if (code == 0x10) { @@ -409,16 +415,13 @@ static int h261_probe(AVProbeData *p) static int ac3_probe(AVProbeData *p) { - int max_frames, first_frames, frames; + int max_frames, first_frames = 0, frames; uint8_t *buf, *buf2, *end; AC3HeaderInfo hdr; - if(p->buf_size < 7) - return 0; - max_frames = 0; buf = p->buf; - end = buf + FFMIN(4096, p->buf_size - 7); + end = buf + p->buf_size; for(; buf < end; buf++) { buf2 = buf; @@ -438,6 +441,12 @@ static int ac3_probe(AVProbeData *p) else return 0; } +static int flac_probe(AVProbeData *p) +{ + if(memcmp(p->buf, "fLaC", 4)) return 0; + else return AVPROBE_SCORE_MAX / 2; +} + AVInputFormat shorten_demuxer = { "shn", "raw shorten", @@ -454,7 +463,7 @@ AVInputFormat flac_demuxer = { "flac", "raw flac", 0, - NULL, + flac_probe, flac_read_header, raw_read_partial_packet, raw_read_close, @@ -473,11 +482,11 @@ AVOutputFormat flac_muxer = { 0, flac_write_header, raw_write_packet, - raw_write_trailer, .flags= AVFMT_NOTIMESTAMPS, }; #endif //CONFIG_MUXERS +#ifdef CONFIG_AC3_DEMUXER AVInputFormat ac3_demuxer = { "ac3", "raw ac3", @@ -489,6 +498,7 @@ AVInputFormat ac3_demuxer = { .flags= AVFMT_GENERIC_INDEX, .extensions = "ac3", }; +#endif #ifdef CONFIG_MUXERS AVOutputFormat ac3_muxer = { @@ -499,9 +509,8 @@ AVOutputFormat ac3_muxer = { 0, CODEC_ID_AC3, 0, - raw_write_header, + NULL, raw_write_packet, - raw_write_trailer, .flags= AVFMT_NOTIMESTAMPS, }; #endif //CONFIG_MUXERS @@ -530,6 +539,21 @@ AVInputFormat aac_demuxer = { .extensions = "aac", }; +#ifdef CONFIG_ROQ_MUXER +AVOutputFormat roq_muxer = +{ + "RoQ", + "Id RoQ format", + NULL, + "roq", + 0, + CODEC_ID_ROQ_DPCM, + CODEC_ID_ROQ, + roq_write_header, + raw_write_packet, +}; +#endif //CONFIG_ROQ_MUXER + AVInputFormat h261_demuxer = { "h261", "raw h261", @@ -552,9 +576,8 @@ AVOutputFormat h261_muxer = { 0, 0, CODEC_ID_H261, - raw_write_header, + NULL, raw_write_packet, - raw_write_trailer, .flags= AVFMT_NOTIMESTAMPS, }; #endif //CONFIG_MUXERS @@ -581,9 +604,8 @@ AVOutputFormat h263_muxer = { 0, 0, CODEC_ID_H263, - raw_write_header, + NULL, raw_write_packet, - raw_write_trailer, .flags= AVFMT_NOTIMESTAMPS, }; #endif //CONFIG_MUXERS @@ -610,9 +632,8 @@ AVOutputFormat m4v_muxer = { 0, CODEC_ID_NONE, CODEC_ID_MPEG4, - raw_write_header, + NULL, raw_write_packet, - raw_write_trailer, .flags= AVFMT_NOTIMESTAMPS, }; #endif //CONFIG_MUXERS @@ -639,9 +660,8 @@ AVOutputFormat h264_muxer = { 0, CODEC_ID_NONE, CODEC_ID_H264, - raw_write_header, + NULL, raw_write_packet, - raw_write_trailer, .flags= AVFMT_NOTIMESTAMPS, }; #endif //CONFIG_MUXERS @@ -667,9 +687,8 @@ AVOutputFormat mpeg1video_muxer = { 0, 0, CODEC_ID_MPEG1VIDEO, - raw_write_header, + NULL, raw_write_packet, - raw_write_trailer, .flags= AVFMT_NOTIMESTAMPS, }; #endif //CONFIG_MUXERS @@ -683,9 +702,8 @@ AVOutputFormat mpeg2video_muxer = { 0, 0, CODEC_ID_MPEG2VIDEO, - raw_write_header, + NULL, raw_write_packet, - raw_write_trailer, .flags= AVFMT_NOTIMESTAMPS, }; #endif //CONFIG_MUXERS @@ -725,9 +743,8 @@ AVOutputFormat mjpeg_muxer = { 0, 0, CODEC_ID_MJPEG, - raw_write_header, + NULL, raw_write_packet, - raw_write_trailer, .flags= AVFMT_NOTIMESTAMPS, }; #endif //CONFIG_MUXERS @@ -770,9 +787,8 @@ AVOutputFormat pcm_ ## name ## _muxer = {\ 0,\ codec,\ 0,\ - raw_write_header,\ + NULL,\ raw_write_packet,\ - raw_write_trailer,\ .flags= AVFMT_NOTIMESTAMPS,\ }; @@ -836,11 +852,13 @@ static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt) if (packet_size < 0) return -1; - ret= av_get_packet(&s->pb, pkt, packet_size); + ret= av_get_packet(s->pb, pkt, packet_size); + pkt->pts= + pkt->dts= pkt->pos / packet_size; pkt->stream_index = 0; if (ret != packet_size) { - return AVERROR_IO; + return AVERROR(EIO); } else { return 0; } @@ -855,7 +873,7 @@ AVInputFormat rawvideo_demuxer = { rawvideo_read_packet, raw_read_close, .flags= AVFMT_GENERIC_INDEX, - .extensions = "yuv,cif,qcif", + .extensions = "yuv,cif,qcif,rgb", .value = CODEC_ID_RAWVIDEO, }; @@ -864,13 +882,12 @@ AVOutputFormat rawvideo_muxer = { "rawvideo", "raw video format", NULL, - "yuv", + "yuv,rgb", 0, CODEC_ID_NONE, CODEC_ID_RAWVIDEO, - raw_write_header, + NULL, raw_write_packet, - raw_write_trailer, .flags= AVFMT_NOTIMESTAMPS, }; #endif //CONFIG_MUXERS @@ -893,9 +910,8 @@ AVOutputFormat null_muxer = { CODEC_ID_PCM_S16LE, #endif CODEC_ID_RAWVIDEO, - raw_write_header, + NULL, null_write_packet, - raw_write_trailer, .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS, }; #endif //CONFIG_MUXERS diff --git a/contrib/ffmpeg/libavformat/raw.h b/contrib/ffmpeg/libavformat/raw.h new file mode 100644 index 000000000..3d851c829 --- /dev/null +++ b/contrib/ffmpeg/libavformat/raw.h @@ -0,0 +1,30 @@ +/* + * RAW muxer and demuxer + * Copyright (C) 2007 Aurelien Jacobs + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_RAW_H +#define FFMPEG_RAW_H + +#include "avformat.h" + +int pcm_read_seek(AVFormatContext *s, + int stream_index, int64_t timestamp, int flags); + +#endif /* FFMPEG_RAW_H */ diff --git a/contrib/ffmpeg/libavformat/riff.c b/contrib/ffmpeg/libavformat/riff.c index 4a5553fa4..64891db3e 100644 --- a/contrib/ffmpeg/libavformat/riff.c +++ b/contrib/ffmpeg/libavformat/riff.c @@ -22,7 +22,6 @@ #include "avformat.h" #include "avcodec.h" #include "riff.h" -#include "allformats.h" // for asf_muxer /* Note: when encoding, the first matching tag is used, so order is important if multiple tags possible for a given codec. */ @@ -88,6 +87,8 @@ const AVCodecTag codec_bmp_tags[] = { { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', 'd') }, { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'l') }, { CODEC_ID_DVVIDEO, MKTAG('d', 'v', '2', '5') }, + { CODEC_ID_DVVIDEO, MKTAG('d', 'v', '5', '0') }, + { CODEC_ID_DVVIDEO, MKTAG('c', 'd', 'v', 'c') }, // Canopus DV { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '1') }, { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '2') }, { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'p', 'g', '2') }, @@ -97,15 +98,16 @@ const AVCodecTag codec_bmp_tags[] = { { CODEC_ID_MPEG1VIDEO, 0x10000001 }, { CODEC_ID_MPEG2VIDEO, 0x10000002 }, { CODEC_ID_MPEG2VIDEO, MKTAG('D', 'V', 'R', ' ') }, + { CODEC_ID_MPEG2VIDEO, MKTAG('M', 'M', 'E', 'S') }, { CODEC_ID_MJPEG, MKTAG('M', 'J', 'P', 'G') }, { CODEC_ID_MJPEG, MKTAG('L', 'J', 'P', 'G') }, { CODEC_ID_LJPEG, MKTAG('L', 'J', 'P', 'G') }, { CODEC_ID_MJPEG, MKTAG('J', 'P', 'G', 'L') }, /* Pegasus lossless JPEG */ + { CODEC_ID_JPEGLS,MKTAG('M', 'J', 'L', 'S') }, /* JPEG-LS custom FOURCC for avi - encoder */ { CODEC_ID_MJPEG, MKTAG('M', 'J', 'L', 'S') }, /* JPEG-LS custom FOURCC for avi - decoder */ { CODEC_ID_MJPEG, MKTAG('j', 'p', 'e', 'g') }, { CODEC_ID_MJPEG, MKTAG('I', 'J', 'P', 'G') }, { CODEC_ID_MJPEG, MKTAG('A', 'V', 'R', 'n') }, - { CODEC_ID_JPEGLS, MKTAG('M', 'J', 'L', 'S') }, /* JPEG-LS custom FOURCC for avi - encoder */ { CODEC_ID_HUFFYUV, MKTAG('H', 'F', 'Y', 'U') }, { CODEC_ID_FFVHUFF, MKTAG('F', 'F', 'V', 'H') }, { CODEC_ID_CYUV, MKTAG('C', 'Y', 'U', 'V') }, @@ -117,8 +119,11 @@ const AVCodecTag codec_bmp_tags[] = { { CODEC_ID_RAWVIDEO, MKTAG('U', 'Y', 'V', 'Y') }, { CODEC_ID_RAWVIDEO, MKTAG('I', 'Y', 'U', 'V') }, { CODEC_ID_RAWVIDEO, MKTAG('Y', '8', '0', '0') }, + { CODEC_ID_RAWVIDEO, MKTAG('H', 'D', 'Y', 'C') }, { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '1') }, { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '2') }, + { CODEC_ID_INDEO4, MKTAG('I', 'V', '4', '1') }, + { CODEC_ID_INDEO5, MKTAG('I', 'V', '5', '0') }, { CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') }, { CODEC_ID_VP3, MKTAG('V', 'P', '3', '0') }, { CODEC_ID_VP5, MKTAG('V', 'P', '5', '0') }, @@ -175,107 +180,49 @@ const AVCodecTag codec_bmp_tags[] = { }; const AVCodecTag codec_wav_tags[] = { - { CODEC_ID_MP2, 0x50 }, - { CODEC_ID_MP3, 0x55 }, - { CODEC_ID_AC3, 0x2000 }, - { CODEC_ID_DTS, 0x2001 }, - { CODEC_ID_PCM_S16LE, 0x01 }, - { CODEC_ID_PCM_U8, 0x01 }, /* must come after s16le in this list */ - { CODEC_ID_PCM_S24LE, 0x01 }, - { CODEC_ID_PCM_S32LE, 0x01 }, - { CODEC_ID_PCM_ALAW, 0x06 }, - { CODEC_ID_PCM_MULAW, 0x07 }, - { CODEC_ID_ADPCM_MS, 0x02 }, - { CODEC_ID_ADPCM_IMA_WAV, 0x11 }, - { CODEC_ID_ADPCM_YAMAHA, 0x20 }, - { CODEC_ID_ADPCM_G726, 0x45 }, - { CODEC_ID_ADPCM_IMA_DK4, 0x61 }, /* rogue format number */ - { CODEC_ID_ADPCM_IMA_DK3, 0x62 }, /* rogue format number */ - { CODEC_ID_WMAV1, 0x160 }, - { CODEC_ID_WMAV2, 0x161 }, - { CODEC_ID_AAC, 0x706d }, - { CODEC_ID_AAC, 0xff }, - { CODEC_ID_VORBIS, ('V'<<8)+'o' }, //HACK/FIXME, does vorbis in WAV/AVI have an (in)official id? - { CODEC_ID_SONIC, 0x2048 }, - { CODEC_ID_SONIC_LS, 0x2048 }, - { CODEC_ID_ADPCM_CT, 0x200 }, - { CODEC_ID_ADPCM_SWF, ('S'<<8)+'F' }, - { CODEC_ID_TRUESPEECH, 0x22 }, - { CODEC_ID_FLAC, 0xF1AC }, - { CODEC_ID_IMC, 0x401 }, - { CODEC_ID_GSM_MS, 0x31 }, + { CODEC_ID_PCM_S16LE, 0x0001 }, + { CODEC_ID_PCM_U8, 0x0001 }, /* must come after s16le in this list */ + { CODEC_ID_PCM_S24LE, 0x0001 }, + { CODEC_ID_PCM_S32LE, 0x0001 }, + { CODEC_ID_ADPCM_MS, 0x0002 }, + { CODEC_ID_PCM_ALAW, 0x0006 }, + { CODEC_ID_PCM_MULAW, 0x0007 }, + { CODEC_ID_WMAVOICE, 0x000A }, + { CODEC_ID_ADPCM_IMA_WAV, 0x0011 }, + { CODEC_ID_ADPCM_YAMAHA, 0x0020 }, + { CODEC_ID_TRUESPEECH, 0x0022 }, + { CODEC_ID_GSM_MS, 0x0031 }, + { CODEC_ID_ADPCM_G726, 0x0045 }, + { CODEC_ID_MP2, 0x0050 }, + { CODEC_ID_MP3, 0x0055 }, + { CODEC_ID_ADPCM_IMA_DK4, 0x0061 }, /* rogue format number */ + { CODEC_ID_ADPCM_IMA_DK3, 0x0062 }, /* rogue format number */ + { CODEC_ID_VOXWARE, 0x0075 }, + { CODEC_ID_AAC, 0x00ff }, + { CODEC_ID_WMAV1, 0x0160 }, + { CODEC_ID_WMAV2, 0x0161 }, + { CODEC_ID_WMAPRO, 0x0162 }, + { CODEC_ID_WMALOSSLESS, 0x0163 }, + { CODEC_ID_ADPCM_CT, 0x0200 }, + { CODEC_ID_ATRAC3, 0x0270 }, + { CODEC_ID_IMC, 0x0401 }, + { CODEC_ID_AC3, 0x2000 }, + { CODEC_ID_DTS, 0x2001 }, + { CODEC_ID_SONIC, 0x2048 }, + { CODEC_ID_SONIC_LS, 0x2048 }, + { CODEC_ID_AAC, 0x706d }, + { CODEC_ID_FLAC, 0xF1AC }, + { CODEC_ID_ADPCM_SWF, ('S'<<8)+'F' }, + { CODEC_ID_VORBIS, ('V'<<8)+'o' }, //HACK/FIXME, does vorbis in WAV/AVI have an (in)official id? /* FIXME: All of the IDs below are not 16 bit and thus illegal. */ // for NuppelVideo (nuv.c) { CODEC_ID_PCM_S16LE, MKTAG('R', 'A', 'W', 'A') }, - { CODEC_ID_MP3, MKTAG('L', 'A', 'M', 'E') }, - { CODEC_ID_MP3, MKTAG('M', 'P', '3', ' ') }, + { CODEC_ID_MP3, MKTAG('L', 'A', 'M', 'E') }, + { CODEC_ID_MP3, MKTAG('M', 'P', '3', ' ') }, { 0, 0 }, }; -unsigned int codec_get_tag(const AVCodecTag *tags, int id) -{ - while (tags->id != CODEC_ID_NONE) { - if (tags->id == id) - return tags->tag; - tags++; - } - return 0; -} - -enum CodecID codec_get_id(const AVCodecTag *tags, unsigned int tag) -{ - while (tags->id != CODEC_ID_NONE) { - if( toupper((tag >> 0)&0xFF) == toupper((tags->tag >> 0)&0xFF) - && toupper((tag >> 8)&0xFF) == toupper((tags->tag >> 8)&0xFF) - && toupper((tag >>16)&0xFF) == toupper((tags->tag >>16)&0xFF) - && toupper((tag >>24)&0xFF) == toupper((tags->tag >>24)&0xFF)) - return tags->id; - tags++; - } - return CODEC_ID_NONE; -} - -unsigned int av_codec_get_tag(const AVCodecTag *tags[4], enum CodecID id) -{ - int i; - for(i=0; tags && tags[i]; i++){ - int tag= codec_get_tag(tags[i], id); - if(tag) return tag; - } - return 0; -} - -enum CodecID av_codec_get_id(const AVCodecTag *tags[4], unsigned int tag) -{ - int i; - for(i=0; tags && tags[i]; i++){ - enum CodecID id= codec_get_id(tags[i], tag); - if(id!=CODEC_ID_NONE) return id; - } - return CODEC_ID_NONE; -} - -unsigned int codec_get_bmp_tag(int id) -{ - return codec_get_tag(codec_bmp_tags, id); -} - -unsigned int codec_get_wav_tag(int id) -{ - return codec_get_tag(codec_wav_tags, id); -} - -enum CodecID codec_get_bmp_id(unsigned int tag) -{ - return codec_get_id(codec_bmp_tags, tag); -} - -enum CodecID codec_get_wav_id(unsigned int tag) -{ - return codec_get_id(codec_wav_tags, tag); -} - #ifdef CONFIG_MUXERS offset_t start_tag(ByteIOContext *pb, const char *tag) { @@ -327,7 +274,7 @@ int put_wav_header(ByteIOContext *pb, AVCodecContext *enc) } if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3 || enc->codec_id == CODEC_ID_GSM_MS) { - blkalign = enc->frame_size; //this is wrong, but seems many demuxers dont work if this is set correctly + blkalign = enc->frame_size; //this is wrong, but it seems many demuxers do not work if this is set correctly //blkalign = 144 * enc->bit_rate/enc->sample_rate; } else if (enc->codec_id == CODEC_ID_ADPCM_G726) { // blkalign = 1; @@ -475,6 +422,8 @@ int wav_codec_get_id(unsigned int tag, int bps) id = CODEC_ID_PCM_S24LE; if (id == CODEC_ID_PCM_S16LE && bps == 32) id = CODEC_ID_PCM_S32LE; + if (id == CODEC_ID_ADPCM_IMA_WAV && bps == 8) + id = CODEC_ID_PCM_ZORK; return id; } #endif // CONFIG_DEMUXERS diff --git a/contrib/ffmpeg/libavformat/riff.h b/contrib/ffmpeg/libavformat/riff.h index 45c72dde6..dc970f619 100644 --- a/contrib/ffmpeg/libavformat/riff.h +++ b/contrib/ffmpeg/libavformat/riff.h @@ -25,8 +25,11 @@ * do NOT include this in end user applications */ -#ifndef FF_RIFF_H -#define FF_RIFF_H +#ifndef FFMPEG_RIFF_H +#define FFMPEG_RIFF_H + +#include "avcodec.h" +#include "avio.h" offset_t start_tag(ByteIOContext *pb, const char *tag); void end_tag(ByteIOContext *pb, offset_t start); @@ -46,10 +49,6 @@ extern const AVCodecTag codec_wav_tags[]; unsigned int codec_get_tag(const AVCodecTag *tags, int id); enum CodecID codec_get_id(const AVCodecTag *tags, unsigned int tag); -unsigned int codec_get_bmp_tag(int id) attribute_deprecated; //use av_codec_get_tag -unsigned int codec_get_wav_tag(int id) attribute_deprecated; //use av_codec_get_tag -enum CodecID codec_get_bmp_id(unsigned int tag) attribute_deprecated; //use av_codec_get_id -enum CodecID codec_get_wav_id(unsigned int tag) attribute_deprecated; //use av_codec_get_id void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale); -#endif +#endif /* FFMPEG_RIFF_H */ diff --git a/contrib/ffmpeg/libavformat/rm.c b/contrib/ffmpeg/libavformat/rm.c deleted file mode 100644 index ad2f5ff27..000000000 --- a/contrib/ffmpeg/libavformat/rm.c +++ /dev/null @@ -1,1147 +0,0 @@ -/* - * "Real" compatible muxer and demuxer. - * Copyright (c) 2000, 2001 Fabrice Bellard. - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include "avformat.h" - -/* in ms */ -#define BUFFER_DURATION 0 - -typedef struct { - int nb_packets; - int packet_total_size; - int packet_max_size; - /* codec related output */ - int bit_rate; - float frame_rate; - int nb_frames; /* current frame number */ - int total_frames; /* total number of frames */ - int num; - AVCodecContext *enc; -} StreamInfo; - -typedef struct { - StreamInfo streams[2]; - StreamInfo *audio_stream, *video_stream; - int data_pos; /* position of the data after the header */ - int nb_packets; - int old_format; - int current_stream; - int remaining_len; - /// Audio descrambling matrix parameters - uint8_t *audiobuf; ///< place to store reordered audio data - int64_t audiotimestamp; ///< Audio packet timestamp - int sub_packet_cnt; // Subpacket counter, used while reading - int sub_packet_size, sub_packet_h, coded_framesize; ///< Descrambling parameters from container - int audio_stream_num; ///< Stream number for audio packets - int audio_pkt_cnt; ///< Output packet counter - int audio_framesize; /// Audio frame size from container - int sub_packet_lengths[16]; /// Length of each aac subpacket -} RMContext; - -#ifdef CONFIG_MUXERS -static void put_str(ByteIOContext *s, const char *tag) -{ - put_be16(s,strlen(tag)); - while (*tag) { - put_byte(s, *tag++); - } -} - -static void put_str8(ByteIOContext *s, const char *tag) -{ - put_byte(s, strlen(tag)); - while (*tag) { - put_byte(s, *tag++); - } -} - -static void rv10_write_header(AVFormatContext *ctx, - int data_size, int index_pos) -{ - RMContext *rm = ctx->priv_data; - ByteIOContext *s = &ctx->pb; - StreamInfo *stream; - unsigned char *data_offset_ptr, *start_ptr; - const char *desc, *mimetype; - int nb_packets, packet_total_size, packet_max_size, size, packet_avg_size, i; - int bit_rate, v, duration, flags, data_pos; - - start_ptr = s->buf_ptr; - - put_tag(s, ".RMF"); - put_be32(s,18); /* header size */ - put_be16(s,0); - put_be32(s,0); - put_be32(s,4 + ctx->nb_streams); /* num headers */ - - put_tag(s,"PROP"); - put_be32(s, 50); - put_be16(s, 0); - packet_max_size = 0; - packet_total_size = 0; - nb_packets = 0; - bit_rate = 0; - duration = 0; - for(i=0;inb_streams;i++) { - StreamInfo *stream = &rm->streams[i]; - bit_rate += stream->bit_rate; - if (stream->packet_max_size > packet_max_size) - packet_max_size = stream->packet_max_size; - nb_packets += stream->nb_packets; - packet_total_size += stream->packet_total_size; - /* select maximum duration */ - v = (int) (1000.0 * (float)stream->total_frames / stream->frame_rate); - if (v > duration) - duration = v; - } - put_be32(s, bit_rate); /* max bit rate */ - put_be32(s, bit_rate); /* avg bit rate */ - put_be32(s, packet_max_size); /* max packet size */ - if (nb_packets > 0) - packet_avg_size = packet_total_size / nb_packets; - else - packet_avg_size = 0; - put_be32(s, packet_avg_size); /* avg packet size */ - put_be32(s, nb_packets); /* num packets */ - put_be32(s, duration); /* duration */ - put_be32(s, BUFFER_DURATION); /* preroll */ - put_be32(s, index_pos); /* index offset */ - /* computation of data the data offset */ - data_offset_ptr = s->buf_ptr; - put_be32(s, 0); /* data offset : will be patched after */ - put_be16(s, ctx->nb_streams); /* num streams */ - flags = 1 | 2; /* save allowed & perfect play */ - if (url_is_streamed(s)) - flags |= 4; /* live broadcast */ - put_be16(s, flags); - - /* comments */ - - put_tag(s,"CONT"); - size = strlen(ctx->title) + strlen(ctx->author) + strlen(ctx->copyright) + - strlen(ctx->comment) + 4 * 2 + 10; - put_be32(s,size); - put_be16(s,0); - put_str(s, ctx->title); - put_str(s, ctx->author); - put_str(s, ctx->copyright); - put_str(s, ctx->comment); - - for(i=0;inb_streams;i++) { - int codec_data_size; - - stream = &rm->streams[i]; - - if (stream->enc->codec_type == CODEC_TYPE_AUDIO) { - desc = "The Audio Stream"; - mimetype = "audio/x-pn-realaudio"; - codec_data_size = 73; - } else { - desc = "The Video Stream"; - mimetype = "video/x-pn-realvideo"; - codec_data_size = 34; - } - - put_tag(s,"MDPR"); - size = 10 + 9 * 4 + strlen(desc) + strlen(mimetype) + codec_data_size; - put_be32(s, size); - put_be16(s, 0); - - put_be16(s, i); /* stream number */ - put_be32(s, stream->bit_rate); /* max bit rate */ - put_be32(s, stream->bit_rate); /* avg bit rate */ - put_be32(s, stream->packet_max_size); /* max packet size */ - if (stream->nb_packets > 0) - packet_avg_size = stream->packet_total_size / - stream->nb_packets; - else - packet_avg_size = 0; - put_be32(s, packet_avg_size); /* avg packet size */ - put_be32(s, 0); /* start time */ - put_be32(s, BUFFER_DURATION); /* preroll */ - /* duration */ - if (url_is_streamed(s) || !stream->total_frames) - put_be32(s, (int)(3600 * 1000)); - else - put_be32(s, (int)(stream->total_frames * 1000 / stream->frame_rate)); - put_str8(s, desc); - put_str8(s, mimetype); - put_be32(s, codec_data_size); - - if (stream->enc->codec_type == CODEC_TYPE_AUDIO) { - int coded_frame_size, fscode, sample_rate; - sample_rate = stream->enc->sample_rate; - coded_frame_size = (stream->enc->bit_rate * - stream->enc->frame_size) / (8 * sample_rate); - /* audio codec info */ - put_tag(s, ".ra"); - put_byte(s, 0xfd); - put_be32(s, 0x00040000); /* version */ - put_tag(s, ".ra4"); - put_be32(s, 0x01b53530); /* stream length */ - put_be16(s, 4); /* unknown */ - put_be32(s, 0x39); /* header size */ - - switch(sample_rate) { - case 48000: - case 24000: - case 12000: - fscode = 1; - break; - default: - case 44100: - case 22050: - case 11025: - fscode = 2; - break; - case 32000: - case 16000: - case 8000: - fscode = 3; - } - put_be16(s, fscode); /* codec additional info, for AC3, seems - to be a frequency code */ - /* special hack to compensate rounding errors... */ - if (coded_frame_size == 557) - coded_frame_size--; - put_be32(s, coded_frame_size); /* frame length */ - put_be32(s, 0x51540); /* unknown */ - put_be32(s, 0x249f0); /* unknown */ - put_be32(s, 0x249f0); /* unknown */ - put_be16(s, 0x01); - /* frame length : seems to be very important */ - put_be16(s, coded_frame_size); - put_be32(s, 0); /* unknown */ - put_be16(s, stream->enc->sample_rate); /* sample rate */ - put_be32(s, 0x10); /* unknown */ - put_be16(s, stream->enc->channels); - put_str8(s, "Int0"); /* codec name */ - put_str8(s, "dnet"); /* codec name */ - put_be16(s, 0); /* title length */ - put_be16(s, 0); /* author length */ - put_be16(s, 0); /* copyright length */ - put_byte(s, 0); /* end of header */ - } else { - /* video codec info */ - put_be32(s,34); /* size */ - if(stream->enc->codec_id == CODEC_ID_RV10) - put_tag(s,"VIDORV10"); - else - put_tag(s,"VIDORV20"); - put_be16(s, stream->enc->width); - put_be16(s, stream->enc->height); - put_be16(s, (int) stream->frame_rate); /* frames per seconds ? */ - put_be32(s,0); /* unknown meaning */ - put_be16(s, (int) stream->frame_rate); /* unknown meaning */ - put_be32(s,0); /* unknown meaning */ - put_be16(s, 8); /* unknown meaning */ - /* Seems to be the codec version: only use basic H263. The next - versions seems to add a diffential DC coding as in - MPEG... nothing new under the sun */ - if(stream->enc->codec_id == CODEC_ID_RV10) - put_be32(s,0x10000000); - else - put_be32(s,0x20103001); - //put_be32(s,0x10003000); - } - } - - /* patch data offset field */ - data_pos = s->buf_ptr - start_ptr; - rm->data_pos = data_pos; - data_offset_ptr[0] = data_pos >> 24; - data_offset_ptr[1] = data_pos >> 16; - data_offset_ptr[2] = data_pos >> 8; - data_offset_ptr[3] = data_pos; - - /* data stream */ - put_tag(s,"DATA"); - put_be32(s,data_size + 10 + 8); - put_be16(s,0); - - put_be32(s, nb_packets); /* number of packets */ - put_be32(s,0); /* next data header */ -} - -static void write_packet_header(AVFormatContext *ctx, StreamInfo *stream, - int length, int key_frame) -{ - int timestamp; - ByteIOContext *s = &ctx->pb; - - stream->nb_packets++; - stream->packet_total_size += length; - if (length > stream->packet_max_size) - stream->packet_max_size = length; - - put_be16(s,0); /* version */ - put_be16(s,length + 12); - put_be16(s, stream->num); /* stream number */ - timestamp = (1000 * (float)stream->nb_frames) / stream->frame_rate; - put_be32(s, timestamp); /* timestamp */ - put_byte(s, 0); /* reserved */ - put_byte(s, key_frame ? 2 : 0); /* flags */ -} - -static int rm_write_header(AVFormatContext *s) -{ - RMContext *rm = s->priv_data; - StreamInfo *stream; - int n; - AVCodecContext *codec; - - for(n=0;nnb_streams;n++) { - s->streams[n]->id = n; - codec = s->streams[n]->codec; - stream = &rm->streams[n]; - memset(stream, 0, sizeof(StreamInfo)); - stream->num = n; - stream->bit_rate = codec->bit_rate; - stream->enc = codec; - - switch(codec->codec_type) { - case CODEC_TYPE_AUDIO: - rm->audio_stream = stream; - stream->frame_rate = (float)codec->sample_rate / (float)codec->frame_size; - /* XXX: dummy values */ - stream->packet_max_size = 1024; - stream->nb_packets = 0; - stream->total_frames = stream->nb_packets; - break; - case CODEC_TYPE_VIDEO: - rm->video_stream = stream; - stream->frame_rate = (float)codec->time_base.den / (float)codec->time_base.num; - /* XXX: dummy values */ - stream->packet_max_size = 4096; - stream->nb_packets = 0; - stream->total_frames = stream->nb_packets; - break; - default: - return -1; - } - } - - rv10_write_header(s, 0, 0); - put_flush_packet(&s->pb); - return 0; -} - -static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size, int flags) -{ - uint8_t *buf1; - RMContext *rm = s->priv_data; - ByteIOContext *pb = &s->pb; - StreamInfo *stream = rm->audio_stream; - int i; - - /* XXX: suppress this malloc */ - buf1= (uint8_t*) av_malloc( size * sizeof(uint8_t) ); - - write_packet_header(s, stream, size, !!(flags & PKT_FLAG_KEY)); - - /* for AC3, the words seems to be reversed */ - for(i=0;inb_frames++; - av_free(buf1); - return 0; -} - -static int rm_write_video(AVFormatContext *s, const uint8_t *buf, int size, int flags) -{ - RMContext *rm = s->priv_data; - ByteIOContext *pb = &s->pb; - StreamInfo *stream = rm->video_stream; - int key_frame = !!(flags & PKT_FLAG_KEY); - - /* XXX: this is incorrect: should be a parameter */ - - /* Well, I spent some time finding the meaning of these bits. I am - not sure I understood everything, but it works !! */ -#if 1 - write_packet_header(s, stream, size + 7, key_frame); - /* bit 7: '1' if final packet of a frame converted in several packets */ - put_byte(pb, 0x81); - /* bit 7: '1' if I frame. bits 6..0 : sequence number in current - frame starting from 1 */ - if (key_frame) { - put_byte(pb, 0x81); - } else { - put_byte(pb, 0x01); - } - put_be16(pb, 0x4000 + (size)); /* total frame size */ - put_be16(pb, 0x4000 + (size)); /* offset from the start or the end */ -#else - /* full frame */ - write_packet_header(s, size + 6); - put_byte(pb, 0xc0); - put_be16(pb, 0x4000 + size); /* total frame size */ - put_be16(pb, 0x4000 + packet_number * 126); /* position in stream */ -#endif - put_byte(pb, stream->nb_frames & 0xff); - - put_buffer(pb, buf, size); - put_flush_packet(pb); - - stream->nb_frames++; - return 0; -} - -static int rm_write_packet(AVFormatContext *s, AVPacket *pkt) -{ - if (s->streams[pkt->stream_index]->codec->codec_type == - CODEC_TYPE_AUDIO) - return rm_write_audio(s, pkt->data, pkt->size, pkt->flags); - else - return rm_write_video(s, pkt->data, pkt->size, pkt->flags); -} - -static int rm_write_trailer(AVFormatContext *s) -{ - RMContext *rm = s->priv_data; - int data_size, index_pos, i; - ByteIOContext *pb = &s->pb; - - if (!url_is_streamed(&s->pb)) { - /* end of file: finish to write header */ - index_pos = url_fseek(pb, 0, SEEK_CUR); - data_size = index_pos - rm->data_pos; - - /* index */ - put_tag(pb, "INDX"); - put_be32(pb, 10 + 10 * s->nb_streams); - put_be16(pb, 0); - - for(i=0;inb_streams;i++) { - put_be32(pb, 0); /* zero indices */ - put_be16(pb, i); /* stream number */ - put_be32(pb, 0); /* next index */ - } - /* undocumented end header */ - put_be32(pb, 0); - put_be32(pb, 0); - - url_fseek(pb, 0, SEEK_SET); - for(i=0;inb_streams;i++) - rm->streams[i].total_frames = rm->streams[i].nb_frames; - rv10_write_header(s, data_size, index_pos); - } else { - /* undocumented end header */ - put_be32(pb, 0); - put_be32(pb, 0); - } - put_flush_packet(pb); - return 0; -} -#endif //CONFIG_MUXERS - -/***************************************************/ - -static void get_str(ByteIOContext *pb, char *buf, int buf_size) -{ - int len, i; - char *q; - - len = get_be16(pb); - q = buf; - for(i=0;ipriv_data; - ByteIOContext *pb = &s->pb; - char buf[256]; - uint32_t version; - int i; - - /* ra type header */ - version = get_be32(pb); /* version */ - if (((version >> 16) & 0xff) == 3) { - int64_t startpos = url_ftell(pb); - /* very old version */ - for(i = 0; i < 14; i++) - get_byte(pb); - get_str8(pb, s->title, sizeof(s->title)); - get_str8(pb, s->author, sizeof(s->author)); - get_str8(pb, s->copyright, sizeof(s->copyright)); - get_str8(pb, s->comment, sizeof(s->comment)); - if ((startpos + (version & 0xffff)) >= url_ftell(pb) + 2) { - // fourcc (should always be "lpcJ") - get_byte(pb); - get_str8(pb, buf, sizeof(buf)); - } - // Skip extra header crap (this should never happen) - if ((startpos + (version & 0xffff)) > url_ftell(pb)) - url_fskip(pb, (version & 0xffff) + startpos - url_ftell(pb)); - st->codec->sample_rate = 8000; - st->codec->channels = 1; - st->codec->codec_type = CODEC_TYPE_AUDIO; - st->codec->codec_id = CODEC_ID_RA_144; - } else { - int flavor, sub_packet_h, coded_framesize, sub_packet_size; - /* old version (4) */ - get_be32(pb); /* .ra4 */ - get_be32(pb); /* data size */ - get_be16(pb); /* version2 */ - get_be32(pb); /* header size */ - flavor= get_be16(pb); /* add codec info / flavor */ - rm->coded_framesize = coded_framesize = get_be32(pb); /* coded frame size */ - get_be32(pb); /* ??? */ - get_be32(pb); /* ??? */ - get_be32(pb); /* ??? */ - rm->sub_packet_h = sub_packet_h = get_be16(pb); /* 1 */ - st->codec->block_align= get_be16(pb); /* frame size */ - rm->sub_packet_size = sub_packet_size = get_be16(pb); /* sub packet size */ - get_be16(pb); /* ??? */ - if (((version >> 16) & 0xff) == 5) { - get_be16(pb); get_be16(pb); get_be16(pb); } - st->codec->sample_rate = get_be16(pb); - get_be32(pb); - st->codec->channels = get_be16(pb); - if (((version >> 16) & 0xff) == 5) { - get_be32(pb); - buf[0] = get_byte(pb); - buf[1] = get_byte(pb); - buf[2] = get_byte(pb); - buf[3] = get_byte(pb); - buf[4] = 0; - } else { - get_str8(pb, buf, sizeof(buf)); /* desc */ - get_str8(pb, buf, sizeof(buf)); /* desc */ - } - st->codec->codec_type = CODEC_TYPE_AUDIO; - if (!strcmp(buf, "dnet")) { - st->codec->codec_id = CODEC_ID_AC3; - } else if (!strcmp(buf, "28_8")) { - st->codec->codec_id = CODEC_ID_RA_288; - st->codec->extradata_size= 0; - rm->audio_framesize = st->codec->block_align; - st->codec->block_align = coded_framesize; - - if(rm->audio_framesize >= UINT_MAX / sub_packet_h){ - av_log(s, AV_LOG_ERROR, "rm->audio_framesize * sub_packet_h too large\n"); - return -1; - } - - rm->audiobuf = av_malloc(rm->audio_framesize * sub_packet_h); - } else if (!strcmp(buf, "cook")) { - int codecdata_length, i; - get_be16(pb); get_byte(pb); - if (((version >> 16) & 0xff) == 5) - get_byte(pb); - codecdata_length = get_be32(pb); - if(codecdata_length + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){ - av_log(s, AV_LOG_ERROR, "codecdata_length too large\n"); - return -1; - } - - st->codec->codec_id = CODEC_ID_COOK; - st->codec->extradata_size= codecdata_length; - st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - for(i = 0; i < codecdata_length; i++) - ((uint8_t*)st->codec->extradata)[i] = get_byte(pb); - rm->audio_framesize = st->codec->block_align; - st->codec->block_align = rm->sub_packet_size; - - if(rm->audio_framesize >= UINT_MAX / sub_packet_h){ - av_log(s, AV_LOG_ERROR, "rm->audio_framesize * sub_packet_h too large\n"); - return -1; - } - - rm->audiobuf = av_malloc(rm->audio_framesize * sub_packet_h); - } else if (!strcmp(buf, "raac") || !strcmp(buf, "racp")) { - int codecdata_length, i; - get_be16(pb); get_byte(pb); - if (((version >> 16) & 0xff) == 5) - get_byte(pb); - st->codec->codec_id = CODEC_ID_AAC; - codecdata_length = get_be32(pb); - if(codecdata_length + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){ - av_log(s, AV_LOG_ERROR, "codecdata_length too large\n"); - return -1; - } - if (codecdata_length >= 1) { - st->codec->extradata_size = codecdata_length - 1; - st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - get_byte(pb); - for(i = 0; i < st->codec->extradata_size; i++) - ((uint8_t*)st->codec->extradata)[i] = get_byte(pb); - } - } else { - st->codec->codec_id = CODEC_ID_NONE; - pstrcpy(st->codec->codec_name, sizeof(st->codec->codec_name), - buf); - } - if (read_all) { - get_byte(pb); - get_byte(pb); - get_byte(pb); - - get_str8(pb, s->title, sizeof(s->title)); - get_str8(pb, s->author, sizeof(s->author)); - get_str8(pb, s->copyright, sizeof(s->copyright)); - get_str8(pb, s->comment, sizeof(s->comment)); - } - } - return 0; -} - -static int rm_read_header_old(AVFormatContext *s, AVFormatParameters *ap) -{ - RMContext *rm = s->priv_data; - AVStream *st; - - rm->old_format = 1; - st = av_new_stream(s, 0); - if (!st) - return -1; - return rm_read_audio_stream_info(s, st, 1); -} - -static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap) -{ - RMContext *rm = s->priv_data; - AVStream *st; - ByteIOContext *pb = &s->pb; - unsigned int tag, v; - int tag_size, size, codec_data_size, i; - int64_t codec_pos; - unsigned int start_time, duration; - char buf[128]; - int flags = 0; - - tag = get_le32(pb); - if (tag == MKTAG('.', 'r', 'a', 0xfd)) { - /* very old .ra format */ - return rm_read_header_old(s, ap); - } else if (tag != MKTAG('.', 'R', 'M', 'F')) { - return AVERROR_IO; - } - - get_be32(pb); /* header size */ - get_be16(pb); - get_be32(pb); - get_be32(pb); /* number of headers */ - - for(;;) { - if (url_feof(pb)) - goto fail; - tag = get_le32(pb); - tag_size = get_be32(pb); - get_be16(pb); -#if 0 - printf("tag=%c%c%c%c (%08x) size=%d\n", - (tag) & 0xff, - (tag >> 8) & 0xff, - (tag >> 16) & 0xff, - (tag >> 24) & 0xff, - tag, - tag_size); -#endif - if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A')) - goto fail; - switch(tag) { - case MKTAG('P', 'R', 'O', 'P'): - /* file header */ - get_be32(pb); /* max bit rate */ - get_be32(pb); /* avg bit rate */ - get_be32(pb); /* max packet size */ - get_be32(pb); /* avg packet size */ - get_be32(pb); /* nb packets */ - get_be32(pb); /* duration */ - get_be32(pb); /* preroll */ - get_be32(pb); /* index offset */ - get_be32(pb); /* data offset */ - get_be16(pb); /* nb streams */ - flags = get_be16(pb); /* flags */ - break; - case MKTAG('C', 'O', 'N', 'T'): - get_str(pb, s->title, sizeof(s->title)); - get_str(pb, s->author, sizeof(s->author)); - get_str(pb, s->copyright, sizeof(s->copyright)); - get_str(pb, s->comment, sizeof(s->comment)); - break; - case MKTAG('M', 'D', 'P', 'R'): - st = av_new_stream(s, 0); - if (!st) - goto fail; - st->id = get_be16(pb); - get_be32(pb); /* max bit rate */ - st->codec->bit_rate = get_be32(pb); /* bit rate */ - get_be32(pb); /* max packet size */ - get_be32(pb); /* avg packet size */ - start_time = get_be32(pb); /* start time */ - get_be32(pb); /* preroll */ - duration = get_be32(pb); /* duration */ - st->start_time = start_time; - st->duration = duration; - get_str8(pb, buf, sizeof(buf)); /* desc */ - get_str8(pb, buf, sizeof(buf)); /* mimetype */ - codec_data_size = get_be32(pb); - codec_pos = url_ftell(pb); - st->codec->codec_type = CODEC_TYPE_DATA; - av_set_pts_info(st, 64, 1, 1000); - - v = get_be32(pb); - if (v == MKTAG(0xfd, 'a', 'r', '.')) { - /* ra type header */ - if (rm_read_audio_stream_info(s, st, 0)) - return -1; - } else { - int fps, fps2; - if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) { - fail1: - av_log(st->codec, AV_LOG_ERROR, "Unsupported video codec\n"); - goto skip; - } - st->codec->codec_tag = get_le32(pb); -// av_log(NULL, AV_LOG_DEBUG, "%X %X\n", st->codec->codec_tag, MKTAG('R', 'V', '2', '0')); - if ( st->codec->codec_tag != MKTAG('R', 'V', '1', '0') - && st->codec->codec_tag != MKTAG('R', 'V', '2', '0') - && st->codec->codec_tag != MKTAG('R', 'V', '3', '0') - && st->codec->codec_tag != MKTAG('R', 'V', '4', '0')) - goto fail1; - st->codec->width = get_be16(pb); - st->codec->height = get_be16(pb); - st->codec->time_base.num= 1; - fps= get_be16(pb); - st->codec->codec_type = CODEC_TYPE_VIDEO; - get_be32(pb); - fps2= get_be16(pb); - get_be16(pb); - - st->codec->extradata_size= codec_data_size - (url_ftell(pb) - codec_pos); - - if(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codec->extradata_size){ - //check is redundant as get_buffer() will catch this - av_log(s, AV_LOG_ERROR, "st->codec->extradata_size too large\n"); - return -1; - } - st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - get_buffer(pb, st->codec->extradata, st->codec->extradata_size); - -// av_log(NULL, AV_LOG_DEBUG, "fps= %d fps2= %d\n", fps, fps2); - st->codec->time_base.den = fps * st->codec->time_base.num; - switch(((uint8_t*)st->codec->extradata)[4]>>4){ - case 1: st->codec->codec_id = CODEC_ID_RV10; break; - case 2: st->codec->codec_id = CODEC_ID_RV20; break; - case 3: st->codec->codec_id = CODEC_ID_RV30; break; - case 4: st->codec->codec_id = CODEC_ID_RV40; break; - default: goto fail1; - } - } -skip: - /* skip codec info */ - size = url_ftell(pb) - codec_pos; - url_fskip(pb, codec_data_size - size); - break; - case MKTAG('D', 'A', 'T', 'A'): - goto header_end; - default: - /* unknown tag: skip it */ - url_fskip(pb, tag_size - 10); - break; - } - } - header_end: - rm->nb_packets = get_be32(pb); /* number of packets */ - if (!rm->nb_packets && (flags & 4)) - rm->nb_packets = 3600 * 25; - get_be32(pb); /* next data header */ - return 0; - - fail: - for(i=0;inb_streams;i++) { - av_free(s->streams[i]); - } - return AVERROR_IO; -} - -static int get_num(ByteIOContext *pb, int *len) -{ - int n, n1; - - n = get_be16(pb); - (*len)-=2; - if (n >= 0x4000) { - return n - 0x4000; - } else { - n1 = get_be16(pb); - (*len)-=2; - return (n << 16) | n1; - } -} - -/* multiple of 20 bytes for ra144 (ugly) */ -#define RAW_PACKET_SIZE 1000 - -static int sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_index, int64_t *pos){ - RMContext *rm = s->priv_data; - ByteIOContext *pb = &s->pb; - int len, num, res, i; - AVStream *st; - uint32_t state=0xFFFFFFFF; - - while(!url_feof(pb)){ - *pos= url_ftell(pb); - if(rm->remaining_len > 0){ - num= rm->current_stream; - len= rm->remaining_len; - *timestamp = AV_NOPTS_VALUE; - *flags= 0; - }else{ - state= (state<<8) + get_byte(pb); - - if(state == MKBETAG('I', 'N', 'D', 'X')){ - len = get_be16(pb) - 6; - if(len<0) - continue; - goto skip; - } - - if(state > (unsigned)0xFFFF || state < 12) - continue; - len=state; - state= 0xFFFFFFFF; - - num = get_be16(pb); - *timestamp = get_be32(pb); - res= get_byte(pb); /* reserved */ - *flags = get_byte(pb); /* flags */ - - - len -= 12; - } - for(i=0;inb_streams;i++) { - st = s->streams[i]; - if (num == st->id) - break; - } - if (i == s->nb_streams) { -skip: - /* skip packet if unknown number */ - url_fskip(pb, len); - rm->remaining_len -= len; - continue; - } - *stream_index= i; - - return len; - } - return -1; -} - -static int rm_read_packet(AVFormatContext *s, AVPacket *pkt) -{ - RMContext *rm = s->priv_data; - ByteIOContext *pb = &s->pb; - AVStream *st; - int i, len, tmp, j; - int64_t timestamp, pos; - uint8_t *ptr; - int flags; - - if (rm->audio_pkt_cnt) { - // If there are queued audio packet return them first - st = s->streams[rm->audio_stream_num]; - if (st->codec->codec_id == CODEC_ID_AAC) - av_get_packet(pb, pkt, rm->sub_packet_lengths[rm->sub_packet_cnt - rm->audio_pkt_cnt]); - else { - av_new_packet(pkt, st->codec->block_align); - memcpy(pkt->data, rm->audiobuf + st->codec->block_align * - (rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - rm->audio_pkt_cnt), - st->codec->block_align); - } - rm->audio_pkt_cnt--; - pkt->flags = 0; - pkt->stream_index = rm->audio_stream_num; - } else if (rm->old_format) { - st = s->streams[0]; - if (st->codec->codec_id == CODEC_ID_RA_288) { - int x, y; - - for (y = 0; y < rm->sub_packet_h; y++) - for (x = 0; x < rm->sub_packet_h/2; x++) - if (get_buffer(pb, rm->audiobuf+x*2*rm->audio_framesize+y*rm->coded_framesize, rm->coded_framesize) <= 0) - return AVERROR_IO; - rm->audio_stream_num = 0; - rm->audio_pkt_cnt = rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - 1; - // Release first audio packet - av_new_packet(pkt, st->codec->block_align); - memcpy(pkt->data, rm->audiobuf, st->codec->block_align); - pkt->flags |= PKT_FLAG_KEY; // Mark first packet as keyframe - pkt->stream_index = 0; - } else { - /* just read raw bytes */ - len = RAW_PACKET_SIZE; - len= av_get_packet(pb, pkt, len); - pkt->stream_index = 0; - if (len <= 0) { - return AVERROR_IO; - } - pkt->size = len; - } - } else { - int seq=1; -resync: - len=sync(s, ×tamp, &flags, &i, &pos); - if(len<0) - return AVERROR_IO; - st = s->streams[i]; - - if (st->codec->codec_type == CODEC_TYPE_VIDEO) { - int h, pic_num, len2, pos; - - h= get_byte(pb); len--; - if(!(h & 0x40)){ - seq = get_byte(pb); len--; - } - - if((h & 0xc0) == 0x40){ - len2= pos= 0; - }else{ - len2 = get_num(pb, &len); - pos = get_num(pb, &len); - } - /* picture number */ - pic_num= get_byte(pb); len--; - rm->remaining_len= len; - rm->current_stream= st->id; - -// av_log(NULL, AV_LOG_DEBUG, "%X len:%d pos:%d len2:%d pic_num:%d\n",h, len, pos, len2, pic_num); - if(len2 && len2remaining_len-= len; - av_get_packet(pb, pkt, len); - - } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) { - if ((st->codec->codec_id == CODEC_ID_RA_288) || - (st->codec->codec_id == CODEC_ID_COOK)) { - int x; - int sps = rm->sub_packet_size; - int cfs = rm->coded_framesize; - int h = rm->sub_packet_h; - int y = rm->sub_packet_cnt; - int w = rm->audio_framesize; - - if (flags & 2) - y = rm->sub_packet_cnt = 0; - if (!y) - rm->audiotimestamp = timestamp; - - switch(st->codec->codec_id) { - case CODEC_ID_RA_288: - for (x = 0; x < h/2; x++) - get_buffer(pb, rm->audiobuf+x*2*w+y*cfs, cfs); - break; - case CODEC_ID_COOK: - for (x = 0; x < w/sps; x++) - get_buffer(pb, rm->audiobuf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps); - break; - } - - if (++(rm->sub_packet_cnt) < h) - goto resync; - else { - rm->sub_packet_cnt = 0; - rm->audio_stream_num = i; - rm->audio_pkt_cnt = h * w / st->codec->block_align - 1; - // Release first audio packet - av_new_packet(pkt, st->codec->block_align); - memcpy(pkt->data, rm->audiobuf, st->codec->block_align); - timestamp = rm->audiotimestamp; - flags = 2; // Mark first packet as keyframe - } - } else if (st->codec->codec_id == CODEC_ID_AAC) { - int x; - rm->audio_stream_num = i; - rm->sub_packet_cnt = (get_be16(pb) & 0xf0) >> 4; - if (rm->sub_packet_cnt) { - for (x = 0; x < rm->sub_packet_cnt; x++) - rm->sub_packet_lengths[x] = get_be16(pb); - // Release first audio packet - rm->audio_pkt_cnt = rm->sub_packet_cnt - 1; - av_get_packet(pb, pkt, rm->sub_packet_lengths[0]); - flags = 2; // Mark first packet as keyframe - } - } else - av_get_packet(pb, pkt, len); - - } else - av_get_packet(pb, pkt, len); - - if( (st->discard >= AVDISCARD_NONKEY && !(flags&2)) - || st->discard >= AVDISCARD_ALL){ - av_free_packet(pkt); - goto resync; - } - - pkt->stream_index = i; - -#if 0 - if (st->codec->codec_type == CODEC_TYPE_VIDEO) { - if(st->codec->codec_id == CODEC_ID_RV20){ - int seq= 128*(pkt->data[2]&0x7F) + (pkt->data[3]>>1); - av_log(NULL, AV_LOG_DEBUG, "%d %"PRId64" %d\n", timestamp, timestamp*512LL/25, seq); - - seq |= (timestamp&~0x3FFF); - if(seq - timestamp > 0x2000) seq -= 0x4000; - if(seq - timestamp < -0x2000) seq += 0x4000; - } - } -#endif - pkt->pts= timestamp; - if(flags&2){ - pkt->flags |= PKT_FLAG_KEY; - if((seq&0x7F) == 1) - av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME); - } - } - - /* for AC3, needs to swap bytes */ - if (st->codec->codec_id == CODEC_ID_AC3) { - ptr = pkt->data; - for(j=0;jpriv_data; - - av_free(rm->audiobuf); - return 0; -} - -static int rm_probe(AVProbeData *p) -{ - /* check file header */ - if (p->buf_size <= 32) - return 0; - if ((p->buf[0] == '.' && p->buf[1] == 'R' && - p->buf[2] == 'M' && p->buf[3] == 'F' && - p->buf[4] == 0 && p->buf[5] == 0) || - (p->buf[0] == '.' && p->buf[1] == 'r' && - p->buf[2] == 'a' && p->buf[3] == 0xfd)) - return AVPROBE_SCORE_MAX; - else - return 0; -} - -static int64_t rm_read_dts(AVFormatContext *s, int stream_index, - int64_t *ppos, int64_t pos_limit) -{ - RMContext *rm = s->priv_data; - int64_t pos, dts; - int stream_index2, flags, len, h; - - pos = *ppos; - - if(rm->old_format) - return AV_NOPTS_VALUE; - - url_fseek(&s->pb, pos, SEEK_SET); - rm->remaining_len=0; - for(;;){ - int seq=1; - AVStream *st; - - len=sync(s, &dts, &flags, &stream_index2, &pos); - if(len<0) - return AV_NOPTS_VALUE; - - st = s->streams[stream_index2]; - if (st->codec->codec_type == CODEC_TYPE_VIDEO) { - h= get_byte(&s->pb); len--; - if(!(h & 0x40)){ - seq = get_byte(&s->pb); len--; - } - } - - if((flags&2) && (seq&0x7F) == 1){ -// av_log(s, AV_LOG_DEBUG, "%d %d-%d %"PRId64" %d\n", flags, stream_index2, stream_index, dts, seq); - av_add_index_entry(st, pos, dts, 0, 0, AVINDEX_KEYFRAME); - if(stream_index2 == stream_index) - break; - } - - url_fskip(&s->pb, len); - } - *ppos = pos; - return dts; -} - -#ifdef CONFIG_RM_DEMUXER -AVInputFormat rm_demuxer = { - "rm", - "rm format", - sizeof(RMContext), - rm_probe, - rm_read_header, - rm_read_packet, - rm_read_close, - NULL, - rm_read_dts, -}; -#endif -#ifdef CONFIG_RM_MUXER -AVOutputFormat rm_muxer = { - "rm", - "rm format", - "application/vnd.rn-realmedia", - "rm,ra", - sizeof(RMContext), - CODEC_ID_AC3, - CODEC_ID_RV10, - rm_write_header, - rm_write_packet, - rm_write_trailer, -}; -#endif diff --git a/contrib/ffmpeg/libavformat/rm.h b/contrib/ffmpeg/libavformat/rm.h new file mode 100644 index 000000000..2f7f8df2e --- /dev/null +++ b/contrib/ffmpeg/libavformat/rm.h @@ -0,0 +1,108 @@ +/* + * "Real" compatible muxer and demuxer. + * Copyright (c) 2000, 2001 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_RM_H +#define FFMPEG_RM_H + +#include "avformat.h" + + +typedef struct { + int nb_packets; + int packet_total_size; + int packet_max_size; + /* codec related output */ + int bit_rate; + float frame_rate; + int nb_frames; /* current frame number */ + int total_frames; /* total number of frames */ + int num; + AVCodecContext *enc; +} StreamInfo; + +typedef struct { + StreamInfo streams[2]; + StreamInfo *audio_stream, *video_stream; + int data_pos; /* position of the data after the header */ + int nb_packets; + int old_format; + int current_stream; + int remaining_len; + uint8_t *videobuf; ///< place to store merged video frame + int videobufsize; ///< current assembled frame size + int videobufpos; ///< position for the next slice in the video buffer + int curpic_num; ///< picture number of current frame + int cur_slice, slices; + int64_t pktpos; ///< first slice position in file + /// Audio descrambling matrix parameters + uint8_t *audiobuf; ///< place to store reordered audio data + int64_t audiotimestamp; ///< Audio packet timestamp + int sub_packet_cnt; // Subpacket counter, used while reading + int sub_packet_size, sub_packet_h, coded_framesize; ///< Descrambling parameters from container + int audio_stream_num; ///< Stream number for audio packets + int audio_pkt_cnt; ///< Output packet counter + int audio_framesize; /// Audio frame size from container + int sub_packet_lengths[16]; /// Length of each aac subpacket +} RMContext; + +/** + * Read the MDPR chunk, which contains stream-specific codec initialization + * parameters. + * + * @param s context containing RMContext and ByteIOContext for stream reading + * @param st the stream that the MDPR chunk belongs to and where to store the + * parameters read from the chunk into + * @return 0 on success, errno codes on error + */ +int ff_rm_read_mdpr_codecdata (AVFormatContext *s, AVStream *st); + +/** + * Parse one rm-stream packet from the input bytestream. + * + * @param s context containing RMContext and ByteIOContext for stream reading + * @param st stream to which the packet to be read belongs + * @param len packet length to read from the input + * @param pkt packet location to store the parsed packet data + * @param seq pointer to an integer containing the sequence number, may be + * updated + * @param flags pointer to an integer containing the packet flags, may be + updated + * @param ts pointer to timestamp, may be updated + * @return 0 on success, errno codes on error + */ +int ff_rm_parse_packet (AVFormatContext *s, AVStream *st, int len, + AVPacket *pkt, int *seq, int *flags, int64_t *ts); + +/** + * Retrieve one cached packet from the rm-context. The real container can + * store several packets (as interpreted by the codec) in a single container + * packet, which means the demuxer holds some back when the first container + * packet is parsed and returned. The result is that rm->audio_pkt_cnt is + * a positive number, the amount of cached packets. Using this function, each + * of those packets can be retrieved sequentially. + * + * @param s context containing RMContext and ByteIOContext for stream reading + * @param st stream that this packet belongs to + * @param pkt location to store the packet data + */ +void ff_rm_retrieve_cache (AVFormatContext *s, AVStream *st, AVPacket *pkt); + +#endif /* FFMPEG_RM_H */ diff --git a/contrib/ffmpeg/libavformat/rmdec.c b/contrib/ffmpeg/libavformat/rmdec.c new file mode 100644 index 000000000..9a770cf4d --- /dev/null +++ b/contrib/ffmpeg/libavformat/rmdec.c @@ -0,0 +1,801 @@ +/* + * "Real" compatible demuxer. + * Copyright (c) 2000, 2001 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avformat.h" +#include "rm.h" +#include "avstring.h" + +static inline void get_strl(ByteIOContext *pb, char *buf, int buf_size, int len) +{ + int i; + char *q, r; + + q = buf; + for(i=0;i 0) *q = '\0'; +} + +static void get_str16(ByteIOContext *pb, char *buf, int buf_size) +{ + get_strl(pb, buf, buf_size, get_be16(pb)); +} + +static void get_str8(ByteIOContext *pb, char *buf, int buf_size) +{ + get_strl(pb, buf, buf_size, get_byte(pb)); +} + +static int rm_read_audio_stream_info(AVFormatContext *s, AVStream *st, + int read_all) +{ + RMContext *rm = s->priv_data; + ByteIOContext *pb = s->pb; + char buf[256]; + uint32_t version; + int i; + + /* ra type header */ + version = get_be32(pb); /* version */ + if (((version >> 16) & 0xff) == 3) { + int64_t startpos = url_ftell(pb); + /* very old version */ + for(i = 0; i < 14; i++) + get_byte(pb); + get_str8(pb, s->title, sizeof(s->title)); + get_str8(pb, s->author, sizeof(s->author)); + get_str8(pb, s->copyright, sizeof(s->copyright)); + get_str8(pb, s->comment, sizeof(s->comment)); + if ((startpos + (version & 0xffff)) >= url_ftell(pb) + 2) { + // fourcc (should always be "lpcJ") + get_byte(pb); + get_str8(pb, buf, sizeof(buf)); + } + // Skip extra header crap (this should never happen) + if ((startpos + (version & 0xffff)) > url_ftell(pb)) + url_fskip(pb, (version & 0xffff) + startpos - url_ftell(pb)); + st->codec->sample_rate = 8000; + st->codec->channels = 1; + st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_RA_144; + } else { + int flavor, sub_packet_h, coded_framesize, sub_packet_size; + /* old version (4) */ + get_be32(pb); /* .ra4 */ + get_be32(pb); /* data size */ + get_be16(pb); /* version2 */ + get_be32(pb); /* header size */ + flavor= get_be16(pb); /* add codec info / flavor */ + rm->coded_framesize = coded_framesize = get_be32(pb); /* coded frame size */ + get_be32(pb); /* ??? */ + get_be32(pb); /* ??? */ + get_be32(pb); /* ??? */ + rm->sub_packet_h = sub_packet_h = get_be16(pb); /* 1 */ + st->codec->block_align= get_be16(pb); /* frame size */ + rm->sub_packet_size = sub_packet_size = get_be16(pb); /* sub packet size */ + get_be16(pb); /* ??? */ + if (((version >> 16) & 0xff) == 5) { + get_be16(pb); get_be16(pb); get_be16(pb); } + st->codec->sample_rate = get_be16(pb); + get_be32(pb); + st->codec->channels = get_be16(pb); + if (((version >> 16) & 0xff) == 5) { + get_be32(pb); + buf[0] = get_byte(pb); + buf[1] = get_byte(pb); + buf[2] = get_byte(pb); + buf[3] = get_byte(pb); + buf[4] = 0; + } else { + get_str8(pb, buf, sizeof(buf)); /* desc */ + get_str8(pb, buf, sizeof(buf)); /* desc */ + } + st->codec->codec_type = CODEC_TYPE_AUDIO; + if (!strcmp(buf, "dnet")) { + st->codec->codec_id = CODEC_ID_AC3; + st->need_parsing = AVSTREAM_PARSE_FULL; + } else if (!strcmp(buf, "28_8")) { + st->codec->codec_id = CODEC_ID_RA_288; + st->codec->extradata_size= 0; + rm->audio_framesize = st->codec->block_align; + st->codec->block_align = coded_framesize; + + if(rm->audio_framesize >= UINT_MAX / sub_packet_h){ + av_log(s, AV_LOG_ERROR, "rm->audio_framesize * sub_packet_h too large\n"); + return -1; + } + + rm->audiobuf = av_malloc(rm->audio_framesize * sub_packet_h); + } else if ((!strcmp(buf, "cook")) || (!strcmp(buf, "atrc"))) { + int codecdata_length, i; + get_be16(pb); get_byte(pb); + if (((version >> 16) & 0xff) == 5) + get_byte(pb); + codecdata_length = get_be32(pb); + if(codecdata_length + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){ + av_log(s, AV_LOG_ERROR, "codecdata_length too large\n"); + return -1; + } + + if (!strcmp(buf, "cook")) st->codec->codec_id = CODEC_ID_COOK; + else st->codec->codec_id = CODEC_ID_ATRAC3; + st->codec->extradata_size= codecdata_length; + st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); + for(i = 0; i < codecdata_length; i++) + ((uint8_t*)st->codec->extradata)[i] = get_byte(pb); + rm->audio_framesize = st->codec->block_align; + st->codec->block_align = rm->sub_packet_size; + + if(rm->audio_framesize >= UINT_MAX / sub_packet_h){ + av_log(s, AV_LOG_ERROR, "rm->audio_framesize * sub_packet_h too large\n"); + return -1; + } + + rm->audiobuf = av_malloc(rm->audio_framesize * sub_packet_h); + } else if (!strcmp(buf, "raac") || !strcmp(buf, "racp")) { + int codecdata_length, i; + get_be16(pb); get_byte(pb); + if (((version >> 16) & 0xff) == 5) + get_byte(pb); + st->codec->codec_id = CODEC_ID_AAC; + codecdata_length = get_be32(pb); + if(codecdata_length + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){ + av_log(s, AV_LOG_ERROR, "codecdata_length too large\n"); + return -1; + } + if (codecdata_length >= 1) { + st->codec->extradata_size = codecdata_length - 1; + st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); + get_byte(pb); + for(i = 0; i < st->codec->extradata_size; i++) + ((uint8_t*)st->codec->extradata)[i] = get_byte(pb); + } + } else { + st->codec->codec_id = CODEC_ID_NONE; + av_strlcpy(st->codec->codec_name, buf, sizeof(st->codec->codec_name)); + } + if (read_all) { + get_byte(pb); + get_byte(pb); + get_byte(pb); + + get_str8(pb, s->title, sizeof(s->title)); + get_str8(pb, s->author, sizeof(s->author)); + get_str8(pb, s->copyright, sizeof(s->copyright)); + get_str8(pb, s->comment, sizeof(s->comment)); + } + } + return 0; +} + +int +ff_rm_read_mdpr_codecdata (AVFormatContext *s, AVStream *st) +{ + ByteIOContext *pb = s->pb; + unsigned int v; + int codec_data_size, size; + int64_t codec_pos; + + codec_data_size = get_be32(pb); + codec_pos = url_ftell(pb); + v = get_be32(pb); + if (v == MKTAG(0xfd, 'a', 'r', '.')) { + /* ra type header */ + if (rm_read_audio_stream_info(s, st, 0)) + return -1; + } else { + int fps, fps2; + if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) { + fail1: + av_log(st->codec, AV_LOG_ERROR, "Unsupported video codec\n"); + goto skip; + } + st->codec->codec_tag = get_le32(pb); +// av_log(NULL, AV_LOG_DEBUG, "%X %X\n", st->codec->codec_tag, MKTAG('R', 'V', '2', '0')); + if ( st->codec->codec_tag != MKTAG('R', 'V', '1', '0') + && st->codec->codec_tag != MKTAG('R', 'V', '2', '0') + && st->codec->codec_tag != MKTAG('R', 'V', '3', '0') + && st->codec->codec_tag != MKTAG('R', 'V', '4', '0')) + goto fail1; + st->codec->width = get_be16(pb); + st->codec->height = get_be16(pb); + st->codec->time_base.num= 1; + fps= get_be16(pb); + st->codec->codec_type = CODEC_TYPE_VIDEO; + get_be32(pb); + fps2= get_be16(pb); + get_be16(pb); + + st->codec->extradata_size= codec_data_size - (url_ftell(pb) - codec_pos); + + if(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codec->extradata_size){ + //check is redundant as get_buffer() will catch this + av_log(s, AV_LOG_ERROR, "st->codec->extradata_size too large\n"); + return -1; + } + st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); + get_buffer(pb, st->codec->extradata, st->codec->extradata_size); + +// av_log(NULL, AV_LOG_DEBUG, "fps= %d fps2= %d\n", fps, fps2); + st->codec->time_base.den = fps * st->codec->time_base.num; + switch(((uint8_t*)st->codec->extradata)[4]>>4){ + case 1: st->codec->codec_id = CODEC_ID_RV10; break; + case 2: st->codec->codec_id = CODEC_ID_RV20; break; + case 3: st->codec->codec_id = CODEC_ID_RV30; break; + case 4: st->codec->codec_id = CODEC_ID_RV40; break; + default: goto fail1; + } + } + +skip: + /* skip codec info */ + size = url_ftell(pb) - codec_pos; + url_fskip(pb, codec_data_size - size); + + return 0; +} + + +static int rm_read_header_old(AVFormatContext *s, AVFormatParameters *ap) +{ + RMContext *rm = s->priv_data; + AVStream *st; + + rm->old_format = 1; + st = av_new_stream(s, 0); + if (!st) + return -1; + return rm_read_audio_stream_info(s, st, 1); +} + +static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap) +{ + RMContext *rm = s->priv_data; + AVStream *st; + ByteIOContext *pb = s->pb; + unsigned int tag; + int tag_size, i; + unsigned int start_time, duration; + char buf[128]; + int flags = 0; + + tag = get_le32(pb); + if (tag == MKTAG('.', 'r', 'a', 0xfd)) { + /* very old .ra format */ + return rm_read_header_old(s, ap); + } else if (tag != MKTAG('.', 'R', 'M', 'F')) { + return AVERROR(EIO); + } + + get_be32(pb); /* header size */ + get_be16(pb); + get_be32(pb); + get_be32(pb); /* number of headers */ + + for(;;) { + if (url_feof(pb)) + goto fail; + tag = get_le32(pb); + tag_size = get_be32(pb); + get_be16(pb); +#if 0 + printf("tag=%c%c%c%c (%08x) size=%d\n", + (tag) & 0xff, + (tag >> 8) & 0xff, + (tag >> 16) & 0xff, + (tag >> 24) & 0xff, + tag, + tag_size); +#endif + if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A')) + goto fail; + switch(tag) { + case MKTAG('P', 'R', 'O', 'P'): + /* file header */ + get_be32(pb); /* max bit rate */ + get_be32(pb); /* avg bit rate */ + get_be32(pb); /* max packet size */ + get_be32(pb); /* avg packet size */ + get_be32(pb); /* nb packets */ + get_be32(pb); /* duration */ + get_be32(pb); /* preroll */ + get_be32(pb); /* index offset */ + get_be32(pb); /* data offset */ + get_be16(pb); /* nb streams */ + flags = get_be16(pb); /* flags */ + break; + case MKTAG('C', 'O', 'N', 'T'): + get_str16(pb, s->title, sizeof(s->title)); + get_str16(pb, s->author, sizeof(s->author)); + get_str16(pb, s->copyright, sizeof(s->copyright)); + get_str16(pb, s->comment, sizeof(s->comment)); + break; + case MKTAG('M', 'D', 'P', 'R'): + st = av_new_stream(s, 0); + if (!st) + goto fail; + st->id = get_be16(pb); + get_be32(pb); /* max bit rate */ + st->codec->bit_rate = get_be32(pb); /* bit rate */ + get_be32(pb); /* max packet size */ + get_be32(pb); /* avg packet size */ + start_time = get_be32(pb); /* start time */ + get_be32(pb); /* preroll */ + duration = get_be32(pb); /* duration */ + st->start_time = start_time; + st->duration = duration; + get_str8(pb, buf, sizeof(buf)); /* desc */ + get_str8(pb, buf, sizeof(buf)); /* mimetype */ + st->codec->codec_type = CODEC_TYPE_DATA; + av_set_pts_info(st, 64, 1, 1000); + if (ff_rm_read_mdpr_codecdata(s, st) < 0) + return -1; + break; + case MKTAG('D', 'A', 'T', 'A'): + goto header_end; + default: + /* unknown tag: skip it */ + url_fskip(pb, tag_size - 10); + break; + } + } + header_end: + rm->nb_packets = get_be32(pb); /* number of packets */ + if (!rm->nb_packets && (flags & 4)) + rm->nb_packets = 3600 * 25; + get_be32(pb); /* next data header */ + rm->curpic_num = -1; + return 0; + + fail: + for(i=0;inb_streams;i++) { + av_free(s->streams[i]); + } + return AVERROR(EIO); +} + +static int get_num(ByteIOContext *pb, int *len) +{ + int n, n1; + + n = get_be16(pb); + (*len)-=2; + n &= 0x7FFF; + if (n >= 0x4000) { + return n - 0x4000; + } else { + n1 = get_be16(pb); + (*len)-=2; + return (n << 16) | n1; + } +} + +/* multiple of 20 bytes for ra144 (ugly) */ +#define RAW_PACKET_SIZE 1000 + +static int sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_index, int64_t *pos){ + RMContext *rm = s->priv_data; + ByteIOContext *pb = s->pb; + int len, num, res, i; + AVStream *st; + uint32_t state=0xFFFFFFFF; + + while(!url_feof(pb)){ + *pos= url_ftell(pb); + if(rm->remaining_len > 0){ + num= rm->current_stream; + len= rm->remaining_len; + *timestamp = AV_NOPTS_VALUE; + *flags= 0; + }else{ + state= (state<<8) + get_byte(pb); + + if(state == MKBETAG('I', 'N', 'D', 'X')){ + len = get_be16(pb) - 6; + if(len<0) + continue; + goto skip; + } + + if(state > (unsigned)0xFFFF || state < 12) + continue; + len=state; + state= 0xFFFFFFFF; + + num = get_be16(pb); + *timestamp = get_be32(pb); + res= get_byte(pb); /* reserved */ + *flags = get_byte(pb); /* flags */ + + + len -= 12; + } + for(i=0;inb_streams;i++) { + st = s->streams[i]; + if (num == st->id) + break; + } + if (i == s->nb_streams) { +skip: + /* skip packet if unknown number */ + url_fskip(pb, len); + rm->remaining_len -= len; + continue; + } + *stream_index= i; + + return len; + } + return -1; +} + +static int rm_assemble_video_frame(AVFormatContext *s, RMContext *rm, AVPacket *pkt, int len) +{ + ByteIOContext *pb = s->pb; + int hdr, seq, pic_num, len2, pos; + int type; + + hdr = get_byte(pb); len--; + type = hdr >> 6; + switch(type){ + case 0: // slice + case 2: // last slice + seq = get_byte(pb); len--; + len2 = get_num(pb, &len); + pos = get_num(pb, &len); + pic_num = get_byte(pb); len--; + rm->remaining_len = len; + break; + case 1: //whole frame + seq = get_byte(pb); len--; + if(av_new_packet(pkt, len + 9) < 0) + return AVERROR(EIO); + pkt->data[0] = 0; + AV_WL32(pkt->data + 1, 1); + AV_WL32(pkt->data + 5, 0); + get_buffer(pb, pkt->data + 9, len); + rm->remaining_len = 0; + return 0; + case 3: //frame as a part of packet + len2 = get_num(pb, &len); + pos = get_num(pb, &len); + pic_num = get_byte(pb); len--; + rm->remaining_len = len - len2; + if(av_new_packet(pkt, len2 + 9) < 0) + return AVERROR(EIO); + pkt->data[0] = 0; + AV_WL32(pkt->data + 1, 1); + AV_WL32(pkt->data + 5, 0); + get_buffer(pb, pkt->data + 9, len2); + return 0; + } + //now we have to deal with single slice + + if((seq & 0x7F) == 1 || rm->curpic_num != pic_num){ + rm->slices = ((hdr & 0x3F) << 1) + 1; + rm->videobufsize = len2 + 8*rm->slices + 1; + av_free(rm->videobuf); + if(!(rm->videobuf = av_malloc(rm->videobufsize))) + return AVERROR(ENOMEM); + rm->videobufpos = 8*rm->slices + 1; + rm->cur_slice = 0; + rm->curpic_num = pic_num; + rm->pktpos = url_ftell(pb); + } + if(type == 2) + len = FFMIN(len, pos); + + if(++rm->cur_slice > rm->slices) + return 1; + AV_WL32(rm->videobuf - 7 + 8*rm->cur_slice, 1); + AV_WL32(rm->videobuf - 3 + 8*rm->cur_slice, rm->videobufpos - 8*rm->slices - 1); + if(rm->videobufpos + len > rm->videobufsize) + return 1; + if (get_buffer(pb, rm->videobuf + rm->videobufpos, len) != len) + return AVERROR(EIO); + rm->videobufpos += len; + rm->remaining_len-= len; + + if(type == 2 || (rm->videobufpos) == rm->videobufsize){ + rm->videobuf[0] = rm->cur_slice-1; + if(av_new_packet(pkt, rm->videobufpos - 8*(rm->slices - rm->cur_slice)) < 0) + return AVERROR(ENOMEM); + memcpy(pkt->data, rm->videobuf, 1 + 8*rm->cur_slice); + memcpy(pkt->data + 1 + 8*rm->cur_slice, rm->videobuf + 1 + 8*rm->slices, + rm->videobufpos - 1 - 8*rm->slices); + pkt->pts = AV_NOPTS_VALUE; + pkt->pos = rm->pktpos; + return 0; + } + + return 1; +} + +static inline void +rm_ac3_swap_bytes (AVStream *st, AVPacket *pkt) +{ + uint8_t *ptr; + int j; + + if (st->codec->codec_id == CODEC_ID_AC3) { + ptr = pkt->data; + for (j=0;jsize;j+=2) { + FFSWAP(int, ptr[0], ptr[1]); + ptr += 2; + } + } +} + +int +ff_rm_parse_packet (AVFormatContext *s, AVStream *st, int len, AVPacket *pkt, + int *seq, int *flags, int64_t *timestamp) +{ + ByteIOContext *pb = s->pb; + RMContext *rm = s->priv_data; + + if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + rm->current_stream= st->id; + if(rm_assemble_video_frame(s, rm, pkt, len) == 1) + return -1; //got partial frame + } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) { + if ((st->codec->codec_id == CODEC_ID_RA_288) || + (st->codec->codec_id == CODEC_ID_COOK) || + (st->codec->codec_id == CODEC_ID_ATRAC3)) { + int x; + int sps = rm->sub_packet_size; + int cfs = rm->coded_framesize; + int h = rm->sub_packet_h; + int y = rm->sub_packet_cnt; + int w = rm->audio_framesize; + + if (*flags & 2) + y = rm->sub_packet_cnt = 0; + if (!y) + rm->audiotimestamp = *timestamp; + + switch(st->codec->codec_id) { + case CODEC_ID_RA_288: + for (x = 0; x < h/2; x++) + get_buffer(pb, rm->audiobuf+x*2*w+y*cfs, cfs); + break; + case CODEC_ID_ATRAC3: + case CODEC_ID_COOK: + for (x = 0; x < w/sps; x++) + get_buffer(pb, rm->audiobuf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps); + break; + } + + if (++(rm->sub_packet_cnt) < h) + return -1; + else { + rm->sub_packet_cnt = 0; + rm->audio_stream_num = st->index; + rm->audio_pkt_cnt = h * w / st->codec->block_align - 1; + // Release first audio packet + av_new_packet(pkt, st->codec->block_align); + memcpy(pkt->data, rm->audiobuf, st->codec->block_align); + *timestamp = rm->audiotimestamp; + *flags = 2; // Mark first packet as keyframe + } + } else if (st->codec->codec_id == CODEC_ID_AAC) { + int x; + rm->audio_stream_num = st->index; + rm->sub_packet_cnt = (get_be16(pb) & 0xf0) >> 4; + if (rm->sub_packet_cnt) { + for (x = 0; x < rm->sub_packet_cnt; x++) + rm->sub_packet_lengths[x] = get_be16(pb); + // Release first audio packet + rm->audio_pkt_cnt = rm->sub_packet_cnt - 1; + av_get_packet(pb, pkt, rm->sub_packet_lengths[0]); + *flags = 2; // Mark first packet as keyframe + } + } else { + av_get_packet(pb, pkt, len); + rm_ac3_swap_bytes(st, pkt); + } + } else + av_get_packet(pb, pkt, len); + + if( (st->discard >= AVDISCARD_NONKEY && !(*flags&2)) + || st->discard >= AVDISCARD_ALL){ + av_free_packet(pkt); + return -1; + } + + pkt->stream_index = st->index; + +#if 0 + if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + if(st->codec->codec_id == CODEC_ID_RV20){ + int seq= 128*(pkt->data[2]&0x7F) + (pkt->data[3]>>1); + av_log(NULL, AV_LOG_DEBUG, "%d %"PRId64" %d\n", *timestamp, *timestamp*512LL/25, seq); + + seq |= (*timestamp&~0x3FFF); + if(seq - *timestamp > 0x2000) seq -= 0x4000; + if(seq - *timestamp < -0x2000) seq += 0x4000; + } + } +#endif + + pkt->pts= *timestamp; + if (*flags & 2) + pkt->flags |= PKT_FLAG_KEY; + + return 0; +} + +void +ff_rm_retrieve_cache (AVFormatContext *s, AVStream *st, AVPacket *pkt) +{ + ByteIOContext *pb = s->pb; + RMContext *rm = s->priv_data; + + assert (rm->audio_pkt_cnt > 0); + + if (st->codec->codec_id == CODEC_ID_AAC) + av_get_packet(pb, pkt, rm->sub_packet_lengths[rm->sub_packet_cnt - rm->audio_pkt_cnt]); + else { + av_new_packet(pkt, st->codec->block_align); + memcpy(pkt->data, rm->audiobuf + st->codec->block_align * + (rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - rm->audio_pkt_cnt), + st->codec->block_align); + } + rm->audio_pkt_cnt--; + pkt->flags = 0; + pkt->stream_index = st->index; +} + +static int rm_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + RMContext *rm = s->priv_data; + ByteIOContext *pb = s->pb; + AVStream *st; + int i, len; + int64_t timestamp, pos; + int flags; + + if (rm->audio_pkt_cnt) { + // If there are queued audio packet return them first + st = s->streams[rm->audio_stream_num]; + ff_rm_retrieve_cache(s, st, pkt); + } else if (rm->old_format) { + st = s->streams[0]; + if (st->codec->codec_id == CODEC_ID_RA_288) { + int x, y; + + for (y = 0; y < rm->sub_packet_h; y++) + for (x = 0; x < rm->sub_packet_h/2; x++) + if (get_buffer(pb, rm->audiobuf+x*2*rm->audio_framesize+y*rm->coded_framesize, rm->coded_framesize) <= 0) + return AVERROR(EIO); + rm->audio_stream_num = 0; + rm->audio_pkt_cnt = rm->sub_packet_h * rm->audio_framesize / st->codec->block_align - 1; + // Release first audio packet + av_new_packet(pkt, st->codec->block_align); + memcpy(pkt->data, rm->audiobuf, st->codec->block_align); + pkt->flags |= PKT_FLAG_KEY; // Mark first packet as keyframe + pkt->stream_index = 0; + } else { + /* just read raw bytes */ + len = RAW_PACKET_SIZE; + len= av_get_packet(pb, pkt, len); + pkt->stream_index = 0; + if (len <= 0) { + return AVERROR(EIO); + } + pkt->size = len; + } + rm_ac3_swap_bytes(st, pkt); + } else { + int seq=1; +resync: + len=sync(s, ×tamp, &flags, &i, &pos); + if(len<0) + return AVERROR(EIO); + st = s->streams[i]; + + if (ff_rm_parse_packet (s, st, len, pkt, &seq, &flags, ×tamp) < 0) + goto resync; + + if((flags&2) && (seq&0x7F) == 1) + av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME); + } + + return 0; +} + +static int rm_read_close(AVFormatContext *s) +{ + RMContext *rm = s->priv_data; + + av_free(rm->audiobuf); + av_free(rm->videobuf); + return 0; +} + +static int rm_probe(AVProbeData *p) +{ + /* check file header */ + if ((p->buf[0] == '.' && p->buf[1] == 'R' && + p->buf[2] == 'M' && p->buf[3] == 'F' && + p->buf[4] == 0 && p->buf[5] == 0) || + (p->buf[0] == '.' && p->buf[1] == 'r' && + p->buf[2] == 'a' && p->buf[3] == 0xfd)) + return AVPROBE_SCORE_MAX; + else + return 0; +} + +static int64_t rm_read_dts(AVFormatContext *s, int stream_index, + int64_t *ppos, int64_t pos_limit) +{ + RMContext *rm = s->priv_data; + int64_t pos, dts; + int stream_index2, flags, len, h; + + pos = *ppos; + + if(rm->old_format) + return AV_NOPTS_VALUE; + + url_fseek(s->pb, pos, SEEK_SET); + rm->remaining_len=0; + for(;;){ + int seq=1; + AVStream *st; + + len=sync(s, &dts, &flags, &stream_index2, &pos); + if(len<0) + return AV_NOPTS_VALUE; + + st = s->streams[stream_index2]; + if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + h= get_byte(s->pb); len--; + if(!(h & 0x40)){ + seq = get_byte(s->pb); len--; + } + } + + if((flags&2) && (seq&0x7F) == 1){ +// av_log(s, AV_LOG_DEBUG, "%d %d-%d %"PRId64" %d\n", flags, stream_index2, stream_index, dts, seq); + av_add_index_entry(st, pos, dts, 0, 0, AVINDEX_KEYFRAME); + if(stream_index2 == stream_index) + break; + } + + url_fskip(s->pb, len); + } + *ppos = pos; + return dts; +} + +AVInputFormat rm_demuxer = { + "rm", + "rm format", + sizeof(RMContext), + rm_probe, + rm_read_header, + rm_read_packet, + rm_read_close, + NULL, + rm_read_dts, +}; diff --git a/contrib/ffmpeg/libavformat/rmenc.c b/contrib/ffmpeg/libavformat/rmenc.c new file mode 100644 index 000000000..3a3525d96 --- /dev/null +++ b/contrib/ffmpeg/libavformat/rmenc.c @@ -0,0 +1,444 @@ +/* + * "Real" compatible muxer. + * Copyright (c) 2000, 2001 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avformat.h" +#include "rm.h" + +/* in ms */ +#define BUFFER_DURATION 0 + + +static void put_str(ByteIOContext *s, const char *tag) +{ + put_be16(s,strlen(tag)); + while (*tag) { + put_byte(s, *tag++); + } +} + +static void put_str8(ByteIOContext *s, const char *tag) +{ + put_byte(s, strlen(tag)); + while (*tag) { + put_byte(s, *tag++); + } +} + +static void rv10_write_header(AVFormatContext *ctx, + int data_size, int index_pos) +{ + RMContext *rm = ctx->priv_data; + ByteIOContext *s = ctx->pb; + StreamInfo *stream; + unsigned char *data_offset_ptr, *start_ptr; + const char *desc, *mimetype; + int nb_packets, packet_total_size, packet_max_size, size, packet_avg_size, i; + int bit_rate, v, duration, flags, data_pos; + + start_ptr = s->buf_ptr; + + put_tag(s, ".RMF"); + put_be32(s,18); /* header size */ + put_be16(s,0); + put_be32(s,0); + put_be32(s,4 + ctx->nb_streams); /* num headers */ + + put_tag(s,"PROP"); + put_be32(s, 50); + put_be16(s, 0); + packet_max_size = 0; + packet_total_size = 0; + nb_packets = 0; + bit_rate = 0; + duration = 0; + for(i=0;inb_streams;i++) { + StreamInfo *stream = &rm->streams[i]; + bit_rate += stream->bit_rate; + if (stream->packet_max_size > packet_max_size) + packet_max_size = stream->packet_max_size; + nb_packets += stream->nb_packets; + packet_total_size += stream->packet_total_size; + /* select maximum duration */ + v = (int) (1000.0 * (float)stream->total_frames / stream->frame_rate); + if (v > duration) + duration = v; + } + put_be32(s, bit_rate); /* max bit rate */ + put_be32(s, bit_rate); /* avg bit rate */ + put_be32(s, packet_max_size); /* max packet size */ + if (nb_packets > 0) + packet_avg_size = packet_total_size / nb_packets; + else + packet_avg_size = 0; + put_be32(s, packet_avg_size); /* avg packet size */ + put_be32(s, nb_packets); /* num packets */ + put_be32(s, duration); /* duration */ + put_be32(s, BUFFER_DURATION); /* preroll */ + put_be32(s, index_pos); /* index offset */ + /* computation of data the data offset */ + data_offset_ptr = s->buf_ptr; + put_be32(s, 0); /* data offset : will be patched after */ + put_be16(s, ctx->nb_streams); /* num streams */ + flags = 1 | 2; /* save allowed & perfect play */ + if (url_is_streamed(s)) + flags |= 4; /* live broadcast */ + put_be16(s, flags); + + /* comments */ + + put_tag(s,"CONT"); + size = strlen(ctx->title) + strlen(ctx->author) + strlen(ctx->copyright) + + strlen(ctx->comment) + 4 * 2 + 10; + put_be32(s,size); + put_be16(s,0); + put_str(s, ctx->title); + put_str(s, ctx->author); + put_str(s, ctx->copyright); + put_str(s, ctx->comment); + + for(i=0;inb_streams;i++) { + int codec_data_size; + + stream = &rm->streams[i]; + + if (stream->enc->codec_type == CODEC_TYPE_AUDIO) { + desc = "The Audio Stream"; + mimetype = "audio/x-pn-realaudio"; + codec_data_size = 73; + } else { + desc = "The Video Stream"; + mimetype = "video/x-pn-realvideo"; + codec_data_size = 34; + } + + put_tag(s,"MDPR"); + size = 10 + 9 * 4 + strlen(desc) + strlen(mimetype) + codec_data_size; + put_be32(s, size); + put_be16(s, 0); + + put_be16(s, i); /* stream number */ + put_be32(s, stream->bit_rate); /* max bit rate */ + put_be32(s, stream->bit_rate); /* avg bit rate */ + put_be32(s, stream->packet_max_size); /* max packet size */ + if (stream->nb_packets > 0) + packet_avg_size = stream->packet_total_size / + stream->nb_packets; + else + packet_avg_size = 0; + put_be32(s, packet_avg_size); /* avg packet size */ + put_be32(s, 0); /* start time */ + put_be32(s, BUFFER_DURATION); /* preroll */ + /* duration */ + if (url_is_streamed(s) || !stream->total_frames) + put_be32(s, (int)(3600 * 1000)); + else + put_be32(s, (int)(stream->total_frames * 1000 / stream->frame_rate)); + put_str8(s, desc); + put_str8(s, mimetype); + put_be32(s, codec_data_size); + + if (stream->enc->codec_type == CODEC_TYPE_AUDIO) { + int coded_frame_size, fscode, sample_rate; + sample_rate = stream->enc->sample_rate; + coded_frame_size = (stream->enc->bit_rate * + stream->enc->frame_size) / (8 * sample_rate); + /* audio codec info */ + put_tag(s, ".ra"); + put_byte(s, 0xfd); + put_be32(s, 0x00040000); /* version */ + put_tag(s, ".ra4"); + put_be32(s, 0x01b53530); /* stream length */ + put_be16(s, 4); /* unknown */ + put_be32(s, 0x39); /* header size */ + + switch(sample_rate) { + case 48000: + case 24000: + case 12000: + fscode = 1; + break; + default: + case 44100: + case 22050: + case 11025: + fscode = 2; + break; + case 32000: + case 16000: + case 8000: + fscode = 3; + } + put_be16(s, fscode); /* codec additional info, for AC3, seems + to be a frequency code */ + /* special hack to compensate rounding errors... */ + if (coded_frame_size == 557) + coded_frame_size--; + put_be32(s, coded_frame_size); /* frame length */ + put_be32(s, 0x51540); /* unknown */ + put_be32(s, 0x249f0); /* unknown */ + put_be32(s, 0x249f0); /* unknown */ + put_be16(s, 0x01); + /* frame length : seems to be very important */ + put_be16(s, coded_frame_size); + put_be32(s, 0); /* unknown */ + put_be16(s, stream->enc->sample_rate); /* sample rate */ + put_be32(s, 0x10); /* unknown */ + put_be16(s, stream->enc->channels); + put_str8(s, "Int0"); /* codec name */ + put_str8(s, "dnet"); /* codec name */ + put_be16(s, 0); /* title length */ + put_be16(s, 0); /* author length */ + put_be16(s, 0); /* copyright length */ + put_byte(s, 0); /* end of header */ + } else { + /* video codec info */ + put_be32(s,34); /* size */ + if(stream->enc->codec_id == CODEC_ID_RV10) + put_tag(s,"VIDORV10"); + else + put_tag(s,"VIDORV20"); + put_be16(s, stream->enc->width); + put_be16(s, stream->enc->height); + put_be16(s, (int) stream->frame_rate); /* frames per seconds ? */ + put_be32(s,0); /* unknown meaning */ + put_be16(s, (int) stream->frame_rate); /* unknown meaning */ + put_be32(s,0); /* unknown meaning */ + put_be16(s, 8); /* unknown meaning */ + /* Seems to be the codec version: only use basic H263. The next + versions seems to add a diffential DC coding as in + MPEG... nothing new under the sun */ + if(stream->enc->codec_id == CODEC_ID_RV10) + put_be32(s,0x10000000); + else + put_be32(s,0x20103001); + //put_be32(s,0x10003000); + } + } + + /* patch data offset field */ + data_pos = s->buf_ptr - start_ptr; + rm->data_pos = data_pos; + data_offset_ptr[0] = data_pos >> 24; + data_offset_ptr[1] = data_pos >> 16; + data_offset_ptr[2] = data_pos >> 8; + data_offset_ptr[3] = data_pos; + + /* data stream */ + put_tag(s,"DATA"); + put_be32(s,data_size + 10 + 8); + put_be16(s,0); + + put_be32(s, nb_packets); /* number of packets */ + put_be32(s,0); /* next data header */ +} + +static void write_packet_header(AVFormatContext *ctx, StreamInfo *stream, + int length, int key_frame) +{ + int timestamp; + ByteIOContext *s = ctx->pb; + + stream->nb_packets++; + stream->packet_total_size += length; + if (length > stream->packet_max_size) + stream->packet_max_size = length; + + put_be16(s,0); /* version */ + put_be16(s,length + 12); + put_be16(s, stream->num); /* stream number */ + timestamp = (1000 * (float)stream->nb_frames) / stream->frame_rate; + put_be32(s, timestamp); /* timestamp */ + put_byte(s, 0); /* reserved */ + put_byte(s, key_frame ? 2 : 0); /* flags */ +} + +static int rm_write_header(AVFormatContext *s) +{ + RMContext *rm = s->priv_data; + StreamInfo *stream; + int n; + AVCodecContext *codec; + + for(n=0;nnb_streams;n++) { + s->streams[n]->id = n; + codec = s->streams[n]->codec; + stream = &rm->streams[n]; + memset(stream, 0, sizeof(StreamInfo)); + stream->num = n; + stream->bit_rate = codec->bit_rate; + stream->enc = codec; + + switch(codec->codec_type) { + case CODEC_TYPE_AUDIO: + rm->audio_stream = stream; + stream->frame_rate = (float)codec->sample_rate / (float)codec->frame_size; + /* XXX: dummy values */ + stream->packet_max_size = 1024; + stream->nb_packets = 0; + stream->total_frames = stream->nb_packets; + break; + case CODEC_TYPE_VIDEO: + rm->video_stream = stream; + stream->frame_rate = (float)codec->time_base.den / (float)codec->time_base.num; + /* XXX: dummy values */ + stream->packet_max_size = 4096; + stream->nb_packets = 0; + stream->total_frames = stream->nb_packets; + break; + default: + return -1; + } + } + + rv10_write_header(s, 0, 0); + put_flush_packet(s->pb); + return 0; +} + +static int rm_write_audio(AVFormatContext *s, const uint8_t *buf, int size, int flags) +{ + uint8_t *buf1; + RMContext *rm = s->priv_data; + ByteIOContext *pb = s->pb; + StreamInfo *stream = rm->audio_stream; + int i; + + /* XXX: suppress this malloc */ + buf1= (uint8_t*) av_malloc( size * sizeof(uint8_t) ); + + write_packet_header(s, stream, size, !!(flags & PKT_FLAG_KEY)); + + /* for AC3, the words seems to be reversed */ + for(i=0;inb_frames++; + av_free(buf1); + return 0; +} + +static int rm_write_video(AVFormatContext *s, const uint8_t *buf, int size, int flags) +{ + RMContext *rm = s->priv_data; + ByteIOContext *pb = s->pb; + StreamInfo *stream = rm->video_stream; + int key_frame = !!(flags & PKT_FLAG_KEY); + + /* XXX: this is incorrect: should be a parameter */ + + /* Well, I spent some time finding the meaning of these bits. I am + not sure I understood everything, but it works !! */ +#if 1 + write_packet_header(s, stream, size + 7 + (size >= 0x4000)*4, key_frame); + /* bit 7: '1' if final packet of a frame converted in several packets */ + put_byte(pb, 0x81); + /* bit 7: '1' if I frame. bits 6..0 : sequence number in current + frame starting from 1 */ + if (key_frame) { + put_byte(pb, 0x81); + } else { + put_byte(pb, 0x01); + } + if(size >= 0x4000){ + put_be32(pb, size); /* total frame size */ + put_be32(pb, size); /* offset from the start or the end */ + }else{ + put_be16(pb, 0x4000 | size); /* total frame size */ + put_be16(pb, 0x4000 | size); /* offset from the start or the end */ + } +#else + /* full frame */ + write_packet_header(s, size + 6); + put_byte(pb, 0xc0); + put_be16(pb, 0x4000 + size); /* total frame size */ + put_be16(pb, 0x4000 + packet_number * 126); /* position in stream */ +#endif + put_byte(pb, stream->nb_frames & 0xff); + + put_buffer(pb, buf, size); + put_flush_packet(pb); + + stream->nb_frames++; + return 0; +} + +static int rm_write_packet(AVFormatContext *s, AVPacket *pkt) +{ + if (s->streams[pkt->stream_index]->codec->codec_type == + CODEC_TYPE_AUDIO) + return rm_write_audio(s, pkt->data, pkt->size, pkt->flags); + else + return rm_write_video(s, pkt->data, pkt->size, pkt->flags); +} + +static int rm_write_trailer(AVFormatContext *s) +{ + RMContext *rm = s->priv_data; + int data_size, index_pos, i; + ByteIOContext *pb = s->pb; + + if (!url_is_streamed(s->pb)) { + /* end of file: finish to write header */ + index_pos = url_fseek(pb, 0, SEEK_CUR); + data_size = index_pos - rm->data_pos; + + /* index */ + put_tag(pb, "INDX"); + put_be32(pb, 10 + 10 * s->nb_streams); + put_be16(pb, 0); + + for(i=0;inb_streams;i++) { + put_be32(pb, 0); /* zero indices */ + put_be16(pb, i); /* stream number */ + put_be32(pb, 0); /* next index */ + } + /* undocumented end header */ + put_be32(pb, 0); + put_be32(pb, 0); + + url_fseek(pb, 0, SEEK_SET); + for(i=0;inb_streams;i++) + rm->streams[i].total_frames = rm->streams[i].nb_frames; + rv10_write_header(s, data_size, index_pos); + } else { + /* undocumented end header */ + put_be32(pb, 0); + put_be32(pb, 0); + } + put_flush_packet(pb); + return 0; +} + + +AVOutputFormat rm_muxer = { + "rm", + "rm format", + "application/vnd.rn-realmedia", + "rm,ra", + sizeof(RMContext), + CODEC_ID_AC3, + CODEC_ID_RV10, + rm_write_header, + rm_write_packet, + rm_write_trailer, +}; diff --git a/contrib/ffmpeg/libavformat/rtp.c b/contrib/ffmpeg/libavformat/rtp.c index 493a89cf3..6b038c825 100644 --- a/contrib/ffmpeg/libavformat/rtp.c +++ b/contrib/ffmpeg/libavformat/rtp.c @@ -19,29 +19,25 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avformat.h" -#include "mpegts.h" #include "bitstream.h" #include #include "network.h" #include "rtp_internal.h" -#include "rtp_h264.h" //#define DEBUG - -/* TODO: - add RTCP statistics reporting (should be optional). - - - add support for h263/mpeg4 packetized output : IDEA: send a - buffer to 'rtp_write_packet' contains all the packets for ONE - frame. Each packet should have a four byte header containing - the length in big endian format (same trick as - 'url_open_dyn_packet_buf') -*/ - /* from http://www.iana.org/assignments/rtp-parameters last updated 05 January 2005 */ -AVRtpPayloadType_t AVRtpPayloadTypes[]= +static const struct +{ + int pt; + const char enc_name[50]; /* XXX: why 50 ? */ + enum CodecType codec_type; + enum CodecID codec_id; + int clock_rate; + int audio_channels; +} AVRtpPayloadTypes[]= { {0, "PCMU", CODEC_TYPE_AUDIO, CODEC_ID_PCM_MULAW, 8000, 1}, {1, "Reserved", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, @@ -76,6 +72,7 @@ AVRtpPayloadType_t AVRtpPayloadTypes[]= {30, "unassigned", CODEC_TYPE_VIDEO, CODEC_ID_NONE, -1, -1}, {31, "H261", CODEC_TYPE_VIDEO, CODEC_ID_H261, 90000, -1}, {32, "MPV", CODEC_TYPE_VIDEO, CODEC_ID_MPEG1VIDEO, 90000, -1}, + {32, "MPV", CODEC_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO, 90000, -1}, {33, "MP2T", CODEC_TYPE_DATA, CODEC_ID_MPEG2TS, 90000, -1}, {34, "H263", CODEC_TYPE_VIDEO, CODEC_ID_H263, 90000, -1}, {35, "unassigned", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1}, @@ -174,36 +171,22 @@ AVRtpPayloadType_t AVRtpPayloadTypes[]= {-1, "", CODEC_TYPE_UNKNOWN, CODEC_ID_NONE, -1, -1} }; -/* statistics functions */ -RTPDynamicProtocolHandler *RTPFirstDynamicPayloadHandler= NULL; - -static RTPDynamicProtocolHandler mp4v_es_handler= {"MP4V-ES", CODEC_TYPE_VIDEO, CODEC_ID_MPEG4}; -static RTPDynamicProtocolHandler mpeg4_generic_handler= {"mpeg4-generic", CODEC_TYPE_AUDIO, CODEC_ID_AAC}; - -static void register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler) -{ - handler->next= RTPFirstDynamicPayloadHandler; - RTPFirstDynamicPayloadHandler= handler; -} - -void av_register_rtp_dynamic_payload_handlers() -{ - register_dynamic_payload_handler(&mp4v_es_handler); - register_dynamic_payload_handler(&mpeg4_generic_handler); - register_dynamic_payload_handler(&ff_h264_dynamic_handler); -} - int rtp_get_codec_info(AVCodecContext *codec, int payload_type) { - if (AVRtpPayloadTypes[payload_type].codec_id != CODEC_ID_NONE) { - codec->codec_type = AVRtpPayloadTypes[payload_type].codec_type; - codec->codec_id = AVRtpPayloadTypes[payload_type].codec_id; - if (AVRtpPayloadTypes[payload_type].audio_channels > 0) - codec->channels = AVRtpPayloadTypes[payload_type].audio_channels; - if (AVRtpPayloadTypes[payload_type].clock_rate > 0) - codec->sample_rate = AVRtpPayloadTypes[payload_type].clock_rate; - return 0; - } + int i = 0; + + for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++) + if (AVRtpPayloadTypes[i].pt == payload_type) { + if (AVRtpPayloadTypes[i].codec_id != CODEC_ID_NONE) { + codec->codec_type = AVRtpPayloadTypes[i].codec_type; + codec->codec_id = AVRtpPayloadTypes[i].codec_id; + if (AVRtpPayloadTypes[i].audio_channels > 0) + codec->channels = AVRtpPayloadTypes[i].audio_channels; + if (AVRtpPayloadTypes[i].clock_rate > 0) + codec->sample_rate = AVRtpPayloadTypes[i].clock_rate; + return 0; + } + } return -1; } @@ -222,864 +205,26 @@ int rtp_get_payload_type(AVCodecContext *codec) return payload_type; } -static inline uint32_t decode_be32(const uint8_t *p) -{ - return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; -} - -static inline uint64_t decode_be64(const uint8_t *p) -{ - return ((uint64_t)decode_be32(p) << 32) | decode_be32(p + 4); -} - -static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf, int len) -{ - if (buf[1] != 200) - return -1; - s->last_rtcp_ntp_time = decode_be64(buf + 8); - if (s->first_rtcp_ntp_time == AV_NOPTS_VALUE) - s->first_rtcp_ntp_time = s->last_rtcp_ntp_time; - s->last_rtcp_timestamp = decode_be32(buf + 16); - return 0; -} - -#define RTP_SEQ_MOD (1<<16) - -/** -* called on parse open packet -*/ -static void rtp_init_statistics(RTPStatistics *s, uint16_t base_sequence) // called on parse open packet. -{ - memset(s, 0, sizeof(RTPStatistics)); - s->max_seq= base_sequence; - s->probation= 1; -} - -/** -* called whenever there is a large jump in sequence numbers, or when they get out of probation... -*/ -static void rtp_init_sequence(RTPStatistics *s, uint16_t seq) -{ - s->max_seq= seq; - s->cycles= 0; - s->base_seq= seq -1; - s->bad_seq= RTP_SEQ_MOD + 1; - s->received= 0; - s->expected_prior= 0; - s->received_prior= 0; - s->jitter= 0; - s->transit= 0; -} - -/** -* returns 1 if we should handle this packet. -*/ -static int rtp_valid_packet_in_sequence(RTPStatistics *s, uint16_t seq) -{ - uint16_t udelta= seq - s->max_seq; - const int MAX_DROPOUT= 3000; - const int MAX_MISORDER = 100; - const int MIN_SEQUENTIAL = 2; - - /* source not valid until MIN_SEQUENTIAL packets with sequence seq. numbers have been received */ - if(s->probation) - { - if(seq==s->max_seq + 1) { - s->probation--; - s->max_seq= seq; - if(s->probation==0) { - rtp_init_sequence(s, seq); - s->received++; - return 1; - } - } else { - s->probation= MIN_SEQUENTIAL - 1; - s->max_seq = seq; - } - } else if (udelta < MAX_DROPOUT) { - // in order, with permissible gap - if(seq < s->max_seq) { - //sequence number wrapped; count antother 64k cycles - s->cycles += RTP_SEQ_MOD; - } - s->max_seq= seq; - } else if (udelta <= RTP_SEQ_MOD - MAX_MISORDER) { - // sequence made a large jump... - if(seq==s->bad_seq) { - // two sequential packets-- assume that the other side restarted without telling us; just resync. - rtp_init_sequence(s, seq); - } else { - s->bad_seq= (seq + 1) & (RTP_SEQ_MOD-1); - return 0; - } - } else { - // duplicate or reordered packet... - } - s->received++; - return 1; -} - -#if 0 -/** -* This function is currently unused; without a valid local ntp time, I don't see how we could calculate the -* difference between the arrival and sent timestamp. As a result, the jitter and transit statistics values -* never change. I left this in in case someone else can see a way. (rdm) -*/ -static void rtcp_update_jitter(RTPStatistics *s, uint32_t sent_timestamp, uint32_t arrival_timestamp) -{ - uint32_t transit= arrival_timestamp - sent_timestamp; - int d; - s->transit= transit; - d= FFABS(transit - s->transit); - s->jitter += d - ((s->jitter + 8)>>4); -} -#endif - -int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count) -{ - ByteIOContext pb; - uint8_t *buf; - int len; - int rtcp_bytes; - RTPStatistics *stats= &s->statistics; - uint32_t lost; - uint32_t extended_max; - uint32_t expected_interval; - uint32_t received_interval; - uint32_t lost_interval; - uint32_t expected; - uint32_t fraction; - uint64_t ntp_time= s->last_rtcp_ntp_time; // TODO: Get local ntp time? - - if (!s->rtp_ctx || (count < 1)) - return -1; - - /* TODO: I think this is way too often; RFC 1889 has algorithm for this */ - /* XXX: mpeg pts hardcoded. RTCP send every 0.5 seconds */ - s->octet_count += count; - rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) / - RTCP_TX_RATIO_DEN; - rtcp_bytes /= 50; // mmu_man: that's enough for me... VLC sends much less btw !? - if (rtcp_bytes < 28) - return -1; - s->last_octet_count = s->octet_count; - - if (url_open_dyn_buf(&pb) < 0) - return -1; - - // Receiver Report - put_byte(&pb, (RTP_VERSION << 6) + 1); /* 1 report block */ - put_byte(&pb, 201); - put_be16(&pb, 7); /* length in words - 1 */ - put_be32(&pb, s->ssrc); // our own SSRC - put_be32(&pb, s->ssrc); // XXX: should be the server's here! - // some placeholders we should really fill... - // RFC 1889/p64 - extended_max= stats->cycles + stats->max_seq; - expected= extended_max - stats->base_seq + 1; - lost= expected - stats->received; - lost= FFMIN(lost, 0xffffff); // clamp it since it's only 24 bits... - expected_interval= expected - stats->expected_prior; - stats->expected_prior= expected; - received_interval= stats->received - stats->received_prior; - stats->received_prior= stats->received; - lost_interval= expected_interval - received_interval; - if (expected_interval==0 || lost_interval<=0) fraction= 0; - else fraction = (lost_interval<<8)/expected_interval; - - fraction= (fraction<<24) | lost; - - put_be32(&pb, fraction); /* 8 bits of fraction, 24 bits of total packets lost */ - put_be32(&pb, extended_max); /* max sequence received */ - put_be32(&pb, stats->jitter>>4); /* jitter */ - - if(s->last_rtcp_ntp_time==AV_NOPTS_VALUE) - { - put_be32(&pb, 0); /* last SR timestamp */ - put_be32(&pb, 0); /* delay since last SR */ - } else { - uint32_t middle_32_bits= s->last_rtcp_ntp_time>>16; // this is valid, right? do we need to handle 64 bit values special? - uint32_t delay_since_last= ntp_time - s->last_rtcp_ntp_time; - - put_be32(&pb, middle_32_bits); /* last SR timestamp */ - put_be32(&pb, delay_since_last); /* delay since last SR */ - } - - // CNAME - put_byte(&pb, (RTP_VERSION << 6) + 1); /* 1 report block */ - put_byte(&pb, 202); - len = strlen(s->hostname); - put_be16(&pb, (6 + len + 3) / 4); /* length in words - 1 */ - put_be32(&pb, s->ssrc); - put_byte(&pb, 0x01); - put_byte(&pb, len); - put_buffer(&pb, s->hostname, len); - // padding - for (len = (6 + len) % 4; len % 4; len++) { - put_byte(&pb, 0); - } - - put_flush_packet(&pb); - len = url_close_dyn_buf(&pb, &buf); - if ((len > 0) && buf) { - int result; -#if defined(DEBUG) - printf("sending %d bytes of RR\n", len); -#endif - result= url_write(s->rtp_ctx, buf, len); -#if defined(DEBUG) - printf("result from url_write: %d\n", result); -#endif - av_free(buf); - } - return 0; -} - -/** - * open a new RTP parse context for stream 'st'. 'st' can be NULL for - * MPEG2TS streams to indicate that they should be demuxed inside the - * rtp demux (otherwise CODEC_ID_MPEG2TS packets are returned) - * TODO: change this to not take rtp_payload data, and use the new dynamic payload system. - */ -RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, rtp_payload_data_t *rtp_payload_data) -{ - RTPDemuxContext *s; - - s = av_mallocz(sizeof(RTPDemuxContext)); - if (!s) - return NULL; - s->payload_type = payload_type; - s->last_rtcp_ntp_time = AV_NOPTS_VALUE; - s->first_rtcp_ntp_time = AV_NOPTS_VALUE; - s->ic = s1; - s->st = st; - s->rtp_payload_data = rtp_payload_data; - rtp_init_statistics(&s->statistics, 0); // do we know the initial sequence from sdp? - if (!strcmp(AVRtpPayloadTypes[payload_type].enc_name, "MP2T")) { - s->ts = mpegts_parse_open(s->ic); - if (s->ts == NULL) { - av_free(s); - return NULL; - } - } else { - switch(st->codec->codec_id) { - case CODEC_ID_MPEG1VIDEO: - case CODEC_ID_MPEG2VIDEO: - case CODEC_ID_MP2: - case CODEC_ID_MP3: - case CODEC_ID_MPEG4: - case CODEC_ID_H264: - st->need_parsing = 1; - break; - default: - break; - } - } - // needed to send back RTCP RR in RTSP sessions - s->rtp_ctx = rtpc; - gethostname(s->hostname, sizeof(s->hostname)); - return s; -} - -static int rtp_parse_mp4_au(RTPDemuxContext *s, const uint8_t *buf) -{ - int au_headers_length, au_header_size, i; - GetBitContext getbitcontext; - rtp_payload_data_t *infos; - - infos = s->rtp_payload_data; - - if (infos == NULL) - return -1; - - /* decode the first 2 bytes where are stored the AUHeader sections - length in bits */ - au_headers_length = AV_RB16(buf); - - if (au_headers_length > RTP_MAX_PACKET_LENGTH) - return -1; - - infos->au_headers_length_bytes = (au_headers_length + 7) / 8; - - /* skip AU headers length section (2 bytes) */ - buf += 2; - - init_get_bits(&getbitcontext, buf, infos->au_headers_length_bytes * 8); - - /* XXX: Wrong if optionnal additional sections are present (cts, dts etc...) */ - au_header_size = infos->sizelength + infos->indexlength; - if (au_header_size <= 0 || (au_headers_length % au_header_size != 0)) - return -1; - - infos->nb_au_headers = au_headers_length / au_header_size; - infos->au_headers = av_malloc(sizeof(struct AUHeaders) * infos->nb_au_headers); - - /* XXX: We handle multiple AU Section as only one (need to fix this for interleaving) - In my test, the faad decoder doesnt behave correctly when sending each AU one by one - but does when sending the whole as one big packet... */ - infos->au_headers[0].size = 0; - infos->au_headers[0].index = 0; - for (i = 0; i < infos->nb_au_headers; ++i) { - infos->au_headers[0].size += get_bits_long(&getbitcontext, infos->sizelength); - infos->au_headers[0].index = get_bits_long(&getbitcontext, infos->indexlength); - } - - infos->nb_au_headers = 1; - - return 0; -} - -/** - * This was the second switch in rtp_parse packet. Normalizes time, if required, sets stream_index, etc. - */ -static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp) -{ - switch(s->st->codec->codec_id) { - case CODEC_ID_MP2: - case CODEC_ID_MPEG1VIDEO: - if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE) { - int64_t addend; - - int delta_timestamp; - /* XXX: is it really necessary to unify the timestamp base ? */ - /* compute pts from timestamp with received ntp_time */ - delta_timestamp = timestamp - s->last_rtcp_timestamp; - /* convert to 90 kHz without overflow */ - addend = (s->last_rtcp_ntp_time - s->first_rtcp_ntp_time) >> 14; - addend = (addend * 5625) >> 14; - pkt->pts = addend + delta_timestamp; - } - break; - case CODEC_ID_AAC: - case CODEC_ID_H264: - case CODEC_ID_MPEG4: - pkt->pts = timestamp; - break; - default: - /* no timestamp info yet */ - break; - } - pkt->stream_index = s->st->index; -} - -/** - * Parse an RTP or RTCP packet directly sent as a buffer. - * @param s RTP parse context. - * @param pkt returned packet - * @param buf input buffer or NULL to read the next packets - * @param len buffer len - * @return 0 if a packet is returned, 1 if a packet is returned and more can follow - * (use buf as NULL to read the next). -1 if no packet (error or no more packet). - */ -int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, - const uint8_t *buf, int len) -{ - unsigned int ssrc, h; - int payload_type, seq, ret; - AVStream *st; - uint32_t timestamp; - int rv= 0; - - if (!buf) { - /* return the next packets, if any */ - if(s->st && s->parse_packet) { - timestamp= 0; ///< Should not be used if buf is NULL, but should be set to the timestamp of the packet returned.... - rv= s->parse_packet(s, pkt, ×tamp, NULL, 0); - finalize_packet(s, pkt, timestamp); - return rv; - } else { - // TODO: Move to a dynamic packet handler (like above) - if (s->read_buf_index >= s->read_buf_size) - return -1; - ret = mpegts_parse_packet(s->ts, pkt, s->buf + s->read_buf_index, - s->read_buf_size - s->read_buf_index); - if (ret < 0) - return -1; - s->read_buf_index += ret; - if (s->read_buf_index < s->read_buf_size) - return 1; - else - return 0; - } - } - - if (len < 12) - return -1; - - if ((buf[0] & 0xc0) != (RTP_VERSION << 6)) - return -1; - if (buf[1] >= 200 && buf[1] <= 204) { - rtcp_parse_packet(s, buf, len); - return -1; - } - payload_type = buf[1] & 0x7f; - seq = (buf[2] << 8) | buf[3]; - timestamp = decode_be32(buf + 4); - ssrc = decode_be32(buf + 8); - /* store the ssrc in the RTPDemuxContext */ - s->ssrc = ssrc; - - /* NOTE: we can handle only one payload type */ - if (s->payload_type != payload_type) - return -1; - - st = s->st; - // only do something with this if all the rtp checks pass... - if(!rtp_valid_packet_in_sequence(&s->statistics, seq)) - { - av_log(st?st->codec:NULL, AV_LOG_ERROR, "RTP: PT=%02x: bad cseq %04x expected=%04x\n", - payload_type, seq, ((s->seq + 1) & 0xffff)); - return -1; - } - - s->seq = seq; - len -= 12; - buf += 12; - - if (!st) { - /* specific MPEG2TS demux support */ - ret = mpegts_parse_packet(s->ts, pkt, buf, len); - if (ret < 0) - return -1; - if (ret < len) { - s->read_buf_size = len - ret; - memcpy(s->buf, buf + ret, s->read_buf_size); - s->read_buf_index = 0; - return 1; - } - } else { - // at this point, the RTP header has been stripped; This is ASSUMING that there is only 1 CSRC, which in't wise. - switch(st->codec->codec_id) { - case CODEC_ID_MP2: - /* better than nothing: skip mpeg audio RTP header */ - if (len <= 4) - return -1; - h = decode_be32(buf); - len -= 4; - buf += 4; - av_new_packet(pkt, len); - memcpy(pkt->data, buf, len); - break; - case CODEC_ID_MPEG1VIDEO: - /* better than nothing: skip mpeg video RTP header */ - if (len <= 4) - return -1; - h = decode_be32(buf); - buf += 4; - len -= 4; - if (h & (1 << 26)) { - /* mpeg2 */ - if (len <= 4) - return -1; - buf += 4; - len -= 4; - } - av_new_packet(pkt, len); - memcpy(pkt->data, buf, len); - break; - // moved from below, verbatim. this is because this section handles packets, and the lower switch handles - // timestamps. - // TODO: Put this into a dynamic packet handler... - case CODEC_ID_AAC: - if (rtp_parse_mp4_au(s, buf)) - return -1; - { - rtp_payload_data_t *infos = s->rtp_payload_data; - if (infos == NULL) - return -1; - buf += infos->au_headers_length_bytes + 2; - len -= infos->au_headers_length_bytes + 2; - - /* XXX: Fixme we only handle the case where rtp_parse_mp4_au define - one au_header */ - av_new_packet(pkt, infos->au_headers[0].size); - memcpy(pkt->data, buf, infos->au_headers[0].size); - buf += infos->au_headers[0].size; - len -= infos->au_headers[0].size; - } - s->read_buf_size = len; - s->buf_ptr = buf; - rv= 0; - break; - default: - if(s->parse_packet) { - rv= s->parse_packet(s, pkt, ×tamp, buf, len); - } else { - av_new_packet(pkt, len); - memcpy(pkt->data, buf, len); - } - break; - } - - // now perform timestamp things.... - finalize_packet(s, pkt, timestamp); - } - return rv; -} - -void rtp_parse_close(RTPDemuxContext *s) -{ - // TODO: fold this into the protocol specific data fields. - if (!strcmp(AVRtpPayloadTypes[s->payload_type].enc_name, "MP2T")) { - mpegts_parse_close(s->ts); - } - av_free(s); -} - -/* rtp output */ - -static int rtp_write_header(AVFormatContext *s1) -{ - RTPDemuxContext *s = s1->priv_data; - int payload_type, max_packet_size, n; - AVStream *st; - - if (s1->nb_streams != 1) - return -1; - st = s1->streams[0]; - - payload_type = rtp_get_payload_type(st->codec); - if (payload_type < 0) - payload_type = RTP_PT_PRIVATE; /* private payload type */ - s->payload_type = payload_type; - -// following 2 FIXMies could be set based on the current time, theres normaly no info leak, as rtp will likely be transmitted immedeatly - s->base_timestamp = 0; /* FIXME: was random(), what should this be? */ - s->timestamp = s->base_timestamp; - s->ssrc = 0; /* FIXME: was random(), what should this be? */ - s->first_packet = 1; - - max_packet_size = url_fget_max_packet_size(&s1->pb); - if (max_packet_size <= 12) - return AVERROR_IO; - s->max_payload_size = max_packet_size - 12; - - switch(st->codec->codec_id) { - case CODEC_ID_MP2: - case CODEC_ID_MP3: - s->buf_ptr = s->buf + 4; - s->cur_timestamp = 0; - break; - case CODEC_ID_MPEG1VIDEO: - s->cur_timestamp = 0; - break; - case CODEC_ID_MPEG2TS: - n = s->max_payload_size / TS_PACKET_SIZE; - if (n < 1) - n = 1; - s->max_payload_size = n * TS_PACKET_SIZE; - s->buf_ptr = s->buf; - break; - default: - s->buf_ptr = s->buf; - break; - } - - return 0; -} - -/* send an rtcp sender report packet */ -static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time) -{ - RTPDemuxContext *s = s1->priv_data; -#if defined(DEBUG) - printf("RTCP: %02x %"PRIx64" %x\n", s->payload_type, ntp_time, s->timestamp); -#endif - put_byte(&s1->pb, (RTP_VERSION << 6)); - put_byte(&s1->pb, 200); - put_be16(&s1->pb, 6); /* length in words - 1 */ - put_be32(&s1->pb, s->ssrc); - put_be64(&s1->pb, ntp_time); - put_be32(&s1->pb, s->timestamp); - put_be32(&s1->pb, s->packet_count); - put_be32(&s1->pb, s->octet_count); - put_flush_packet(&s1->pb); -} - -/* send an rtp packet. sequence number is incremented, but the caller - must update the timestamp itself */ -static void rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m) -{ - RTPDemuxContext *s = s1->priv_data; - -#ifdef DEBUG - printf("rtp_send_data size=%d\n", len); -#endif - - /* build the RTP header */ - put_byte(&s1->pb, (RTP_VERSION << 6)); - put_byte(&s1->pb, (s->payload_type & 0x7f) | ((m & 0x01) << 7)); - put_be16(&s1->pb, s->seq); - put_be32(&s1->pb, s->timestamp); - put_be32(&s1->pb, s->ssrc); - - put_buffer(&s1->pb, buf1, len); - put_flush_packet(&s1->pb); - - s->seq++; - s->octet_count += len; - s->packet_count++; -} - -/* send an integer number of samples and compute time stamp and fill - the rtp send buffer before sending. */ -static void rtp_send_samples(AVFormatContext *s1, - const uint8_t *buf1, int size, int sample_size) +const char *ff_rtp_enc_name(int payload_type) { - RTPDemuxContext *s = s1->priv_data; - int len, max_packet_size, n; + int i; - max_packet_size = (s->max_payload_size / sample_size) * sample_size; - /* not needed, but who nows */ - if ((size % sample_size) != 0) - av_abort(); - while (size > 0) { - len = (max_packet_size - (s->buf_ptr - s->buf)); - if (len > size) - len = size; - - /* copy data */ - memcpy(s->buf_ptr, buf1, len); - s->buf_ptr += len; - buf1 += len; - size -= len; - n = (s->buf_ptr - s->buf); - /* if buffer full, then send it */ - if (n >= max_packet_size) { - rtp_send_data(s1, s->buf, n, 0); - s->buf_ptr = s->buf; - /* update timestamp */ - s->timestamp += n / sample_size; + for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++) + if (AVRtpPayloadTypes[i].pt == payload_type) { + return AVRtpPayloadTypes[i].enc_name; } - } -} -/* NOTE: we suppose that exactly one frame is given as argument here */ -/* XXX: test it */ -static void rtp_send_mpegaudio(AVFormatContext *s1, - const uint8_t *buf1, int size) -{ - RTPDemuxContext *s = s1->priv_data; - AVStream *st = s1->streams[0]; - int len, count, max_packet_size; - - max_packet_size = s->max_payload_size; - - /* test if we must flush because not enough space */ - len = (s->buf_ptr - s->buf); - if ((len + size) > max_packet_size) { - if (len > 4) { - rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0); - s->buf_ptr = s->buf + 4; - /* 90 KHz time stamp */ - s->timestamp = s->base_timestamp + - (s->cur_timestamp * 90000LL) / st->codec->sample_rate; - } - } - - /* add the packet */ - if (size > max_packet_size) { - /* big packet: fragment */ - count = 0; - while (size > 0) { - len = max_packet_size - 4; - if (len > size) - len = size; - /* build fragmented packet */ - s->buf[0] = 0; - s->buf[1] = 0; - s->buf[2] = count >> 8; - s->buf[3] = count; - memcpy(s->buf + 4, buf1, len); - rtp_send_data(s1, s->buf, len + 4, 0); - size -= len; - buf1 += len; - count += len; - } - } else { - if (s->buf_ptr == s->buf + 4) { - /* no fragmentation possible */ - s->buf[0] = 0; - s->buf[1] = 0; - s->buf[2] = 0; - s->buf[3] = 0; - } - memcpy(s->buf_ptr, buf1, size); - s->buf_ptr += size; - } - s->cur_timestamp += st->codec->frame_size; + return ""; } -/* NOTE: a single frame must be passed with sequence header if - needed. XXX: use slices. */ -static void rtp_send_mpegvideo(AVFormatContext *s1, - const uint8_t *buf1, int size) +enum CodecID ff_rtp_codec_id(const char *buf, enum CodecType codec_type) { - RTPDemuxContext *s = s1->priv_data; - AVStream *st = s1->streams[0]; - int len, h, max_packet_size; - uint8_t *q; - - max_packet_size = s->max_payload_size; - - while (size > 0) { - /* XXX: more correct headers */ - h = 0; - if (st->codec->sub_id == 2) - h |= 1 << 26; /* mpeg 2 indicator */ - q = s->buf; - *q++ = h >> 24; - *q++ = h >> 16; - *q++ = h >> 8; - *q++ = h; + int i; - if (st->codec->sub_id == 2) { - h = 0; - *q++ = h >> 24; - *q++ = h >> 16; - *q++ = h >> 8; - *q++ = h; + for (i = 0; AVRtpPayloadTypes[i].pt >= 0; i++) + if (!strcmp(buf, AVRtpPayloadTypes[i].enc_name) && (codec_type == AVRtpPayloadTypes[i].codec_type)){ + return AVRtpPayloadTypes[i].codec_id; } - len = max_packet_size - (q - s->buf); - if (len > size) - len = size; - - memcpy(q, buf1, len); - q += len; - - /* 90 KHz time stamp */ - s->timestamp = s->base_timestamp + - av_rescale((int64_t)s->cur_timestamp * st->codec->time_base.num, 90000, st->codec->time_base.den); //FIXME pass timestamps - rtp_send_data(s1, s->buf, q - s->buf, (len == size)); - - buf1 += len; - size -= len; - } - s->cur_timestamp++; + return CODEC_ID_NONE; } - -static void rtp_send_raw(AVFormatContext *s1, - const uint8_t *buf1, int size) -{ - RTPDemuxContext *s = s1->priv_data; - AVStream *st = s1->streams[0]; - int len, max_packet_size; - - max_packet_size = s->max_payload_size; - - while (size > 0) { - len = max_packet_size; - if (len > size) - len = size; - - /* 90 KHz time stamp */ - s->timestamp = s->base_timestamp + - av_rescale((int64_t)s->cur_timestamp * st->codec->time_base.num, 90000, st->codec->time_base.den); //FIXME pass timestamps - rtp_send_data(s1, buf1, len, (len == size)); - - buf1 += len; - size -= len; - } - s->cur_timestamp++; -} - -/* NOTE: size is assumed to be an integer multiple of TS_PACKET_SIZE */ -static void rtp_send_mpegts_raw(AVFormatContext *s1, - const uint8_t *buf1, int size) -{ - RTPDemuxContext *s = s1->priv_data; - int len, out_len; - - while (size >= TS_PACKET_SIZE) { - len = s->max_payload_size - (s->buf_ptr - s->buf); - if (len > size) - len = size; - memcpy(s->buf_ptr, buf1, len); - buf1 += len; - size -= len; - s->buf_ptr += len; - - out_len = s->buf_ptr - s->buf; - if (out_len >= s->max_payload_size) { - rtp_send_data(s1, s->buf, out_len, 0); - s->buf_ptr = s->buf; - } - } -} - -/* write an RTP packet. 'buf1' must contain a single specific frame. */ -static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) -{ - RTPDemuxContext *s = s1->priv_data; - AVStream *st = s1->streams[0]; - int rtcp_bytes; - int64_t ntp_time; - int size= pkt->size; - uint8_t *buf1= pkt->data; - -#ifdef DEBUG - printf("%d: write len=%d\n", pkt->stream_index, size); -#endif - - /* XXX: mpeg pts hardcoded. RTCP send every 0.5 seconds */ - rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) / - RTCP_TX_RATIO_DEN; - if (s->first_packet || rtcp_bytes >= 28) { - /* compute NTP time */ - /* XXX: 90 kHz timestamp hardcoded */ - ntp_time = (pkt->pts << 28) / 5625; - rtcp_send_sr(s1, ntp_time); - s->last_octet_count = s->octet_count; - s->first_packet = 0; - } - - switch(st->codec->codec_id) { - case CODEC_ID_PCM_MULAW: - case CODEC_ID_PCM_ALAW: - case CODEC_ID_PCM_U8: - case CODEC_ID_PCM_S8: - rtp_send_samples(s1, buf1, size, 1 * st->codec->channels); - break; - case CODEC_ID_PCM_U16BE: - case CODEC_ID_PCM_U16LE: - case CODEC_ID_PCM_S16BE: - case CODEC_ID_PCM_S16LE: - rtp_send_samples(s1, buf1, size, 2 * st->codec->channels); - break; - case CODEC_ID_MP2: - case CODEC_ID_MP3: - rtp_send_mpegaudio(s1, buf1, size); - break; - case CODEC_ID_MPEG1VIDEO: - rtp_send_mpegvideo(s1, buf1, size); - break; - case CODEC_ID_MPEG2TS: - rtp_send_mpegts_raw(s1, buf1, size); - break; - default: - /* better than nothing : send the codec raw data */ - rtp_send_raw(s1, buf1, size); - break; - } - return 0; -} - -static int rtp_write_trailer(AVFormatContext *s1) -{ - // RTPDemuxContext *s = s1->priv_data; - return 0; -} - -AVOutputFormat rtp_muxer = { - "rtp", - "RTP output format", - NULL, - NULL, - sizeof(RTPDemuxContext), - CODEC_ID_PCM_MULAW, - CODEC_ID_NONE, - rtp_write_header, - rtp_write_packet, - rtp_write_trailer, -}; diff --git a/contrib/ffmpeg/libavformat/rtp.h b/contrib/ffmpeg/libavformat/rtp.h index fec763051..21cfdb4cf 100644 --- a/contrib/ffmpeg/libavformat/rtp.h +++ b/contrib/ffmpeg/libavformat/rtp.h @@ -18,13 +18,15 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef RTP_H -#define RTP_H +#ifndef FFMPEG_RTP_H +#define FFMPEG_RTP_H + +#include "avcodec.h" +#include "avformat.h" #define RTP_MIN_PACKET_LENGTH 12 #define RTP_MAX_PACKET_LENGTH 1500 /* XXX: suppress this define */ -int rtp_init(void); int rtp_get_codec_info(AVCodecContext *codec, int payload_type); /** return < 0 if unknown payload type */ @@ -37,9 +39,6 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, const uint8_t *buf, int len); void rtp_parse_close(RTPDemuxContext *s); -extern AVOutputFormat rtp_muxer; -extern AVInputFormat rtp_demuxer; - int rtp_get_local_port(URLContext *h); int rtp_set_remote_url(URLContext *h, const char *uri); void rtp_get_file_handles(URLContext *h, int *prtp_fd, int *prtcp_fd); @@ -51,8 +50,6 @@ void rtp_get_file_handles(URLContext *h, int *prtp_fd, int *prtcp_fd); */ int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count); -extern URLProtocol rtp_protocol; - #define RTP_PT_PRIVATE 96 #define RTP_VERSION 2 #define RTP_MAX_SDES 256 /**< maximum text length for SDES */ @@ -88,16 +85,6 @@ typedef struct rtp_payload_data_s int cur_au_index; } rtp_payload_data_t; -typedef struct AVRtpPayloadType_s -{ - int pt; - const char enc_name[50]; /* XXX: why 50 ? */ - enum CodecType codec_type; - enum CodecID codec_id; - int clock_rate; - int audio_channels; -} AVRtpPayloadType_t; - #if 0 typedef enum { RTCP_SR = 200, @@ -123,5 +110,4 @@ typedef enum { } rtcp_sdes_type_t; #endif -extern AVRtpPayloadType_t AVRtpPayloadTypes[]; -#endif /* RTP_H */ +#endif /* FFMPEG_RTP_H */ diff --git a/contrib/ffmpeg/libavformat/rtp_aac.c b/contrib/ffmpeg/libavformat/rtp_aac.c new file mode 100644 index 000000000..4cd8e129d --- /dev/null +++ b/contrib/ffmpeg/libavformat/rtp_aac.c @@ -0,0 +1,88 @@ +/* + * copyright (c) 2007 Luca Abeni + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" +#include "rtp_aac.h" +#include "rtp_internal.h" + +#define MAX_FRAMES_PER_PACKET (s->max_frames_per_packet ? s->max_frames_per_packet : 5) +#define MAX_AU_HEADERS_SIZE (2 + 2 * MAX_FRAMES_PER_PACKET) + +void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size) +{ + RTPDemuxContext *s = s1->priv_data; + int len, max_packet_size; + uint8_t *p; + + /* skip ADTS header, if present */ + if ((s1->streams[0]->codec->extradata_size) == 0) { + size -= 7; + buff += 7; + } + max_packet_size = s->max_payload_size - MAX_AU_HEADERS_SIZE; + + /* test if the packet must be sent */ + len = (s->buf_ptr - s->buf); + if ((s->read_buf_index == MAX_FRAMES_PER_PACKET) || (len && (len + size) > max_packet_size)) { + int au_size = s->read_buf_index * 2; + + p = s->buf + MAX_AU_HEADERS_SIZE - au_size - 2; + if (p != s->buf) { + memmove(p + 2, s->buf + 2, au_size); + } + /* Write the AU header size */ + p[0] = ((au_size * 8) & 0xFF) >> 8; + p[1] = (au_size * 8) & 0xFF; + + ff_rtp_send_data(s1, p, s->buf_ptr - p, 1); + + s->read_buf_index = 0; + } + if (s->read_buf_index == 0) { + s->buf_ptr = s->buf + MAX_AU_HEADERS_SIZE; + s->timestamp = s->cur_timestamp; + } + + if (size < max_packet_size) { + p = s->buf + s->read_buf_index++ * 2 + 2; + *p++ = size >> 5; + *p = (size & 0x1F) << 3; + memcpy(s->buf_ptr, buff, size); + s->buf_ptr += size; + } else { + if (s->buf_ptr != s->buf + MAX_AU_HEADERS_SIZE) { + av_log(s1, AV_LOG_ERROR, "Strange...\n"); + av_abort(); + } + max_packet_size = s->max_payload_size - 4; + p = s->buf; + p[0] = 0; + p[1] = 16; + while (size > 0) { + len = FFMIN(size, max_packet_size); + p[2] = len >> 5; + p[3] = (size & 0x1F) << 3; + memcpy(p + 4, buff, len); + ff_rtp_send_data(s1, p, len + 4, len == size); + size -= len; + buff += len; + } + } +} diff --git a/contrib/ffmpeg/libavformat/rtp_aac.h b/contrib/ffmpeg/libavformat/rtp_aac.h new file mode 100644 index 000000000..24b41cc42 --- /dev/null +++ b/contrib/ffmpeg/libavformat/rtp_aac.h @@ -0,0 +1,27 @@ +/* + * RTP definitions + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef FFMPEG_RTP_AAC_H +#define FFMPEG_RTP_AAC_H + +#include "avformat.h" + +void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size); + +#endif /* FFMPEG_RTP_AAC_H */ diff --git a/contrib/ffmpeg/libavformat/rtp_h264.c b/contrib/ffmpeg/libavformat/rtp_h264.c index d38e8780d..3e0fc3add 100644 --- a/contrib/ffmpeg/libavformat/rtp_h264.c +++ b/contrib/ffmpeg/libavformat/rtp_h264.c @@ -47,6 +47,7 @@ #include "rtp_internal.h" #include "rtp_h264.h" #include "base64.h" +#include "avstring.h" /** RTP/H264 specific private data. @@ -77,8 +78,8 @@ static void sdp_parse_fmtp_config_h264(AVStream * stream, assert(h264_data != NULL); if (!strcmp(attr, "packetization-mode")) { - av_log(NULL, AV_LOG_DEBUG, "H.264/RTP Packetization Mode: %d\n", atoi(attr)); - h264_data->packetization_mode = atoi(attr); + av_log(NULL, AV_LOG_DEBUG, "H.264/RTP Packetization Mode: %d\n", atoi(value)); + h264_data->packetization_mode = atoi(value); /* Packetization Mode: 0 or not present: Single NAL mode (Only nals from 1-23 are allowed) @@ -162,7 +163,7 @@ static int h264_handle_packet(RTPDemuxContext * s, AVPacket * pkt, uint32_t * timestamp, const uint8_t * buf, - int len) + int len, int flags) { #ifdef DEBUG h264_rtp_extra_data *data = s->dynamic_protocol_context; @@ -270,14 +271,14 @@ static int h264_handle_packet(RTPDemuxContext * s, // these are the same as above, we just redo them here for clarity... uint8_t fu_indicator = nal; uint8_t fu_header = *buf; // read the fu_header. - uint8_t start_bit = (fu_header & 0x80) >> 7; + uint8_t start_bit = fu_header >> 7; // uint8_t end_bit = (fu_header & 0x40) >> 6; uint8_t nal_type = (fu_header & 0x1f); uint8_t reconstructed_nal; // reconstruct this packet's true nal; only the data follows.. reconstructed_nal = fu_indicator & (0xe0); // the original nal forbidden bit and NRI are stored in this packet's nal; - reconstructed_nal |= (nal_type & 0x1f); + reconstructed_nal |= nal_type; // skip the fu_header... buf++; @@ -285,7 +286,7 @@ static int h264_handle_packet(RTPDemuxContext * s, #ifdef DEBUG if (start_bit) - data->packet_types_received[nal_type & 0x1f]++; + data->packet_types_received[nal_type]++; #endif if(start_bit) { // copy in the start sequence, and the reconstructed nal.... @@ -312,7 +313,7 @@ static int h264_handle_packet(RTPDemuxContext * s, } /* ---------------- public code */ -static void *h264_new_extradata() +static void *h264_new_extradata(void) { h264_rtp_extra_data *data = av_mallocz(sizeof(h264_rtp_extra_data) + @@ -357,7 +358,7 @@ static int parse_h264_sdp_line(AVStream * stream, void *data, assert(h264_data->cookie == MAGIC_COOKIE); - if (strstart(p, "framesize:", &p)) { + if (av_strstart(p, "framesize:", &p)) { char buf1[50]; char *dst = buf1; @@ -375,7 +376,7 @@ static int parse_h264_sdp_line(AVStream * stream, void *data, codec->width = atoi(buf1); codec->height = atoi(p + 1); // skip the - codec->pix_fmt = PIX_FMT_YUV420P; - } else if (strstart(p, "fmtp:", &p)) { + } else if (av_strstart(p, "fmtp:", &p)) { char attr[256]; char value[4096]; @@ -390,7 +391,7 @@ static int parse_h264_sdp_line(AVStream * stream, void *data, /* grab the codec extra_data from the config parameter of the fmtp line */ sdp_parse_fmtp_config_h264(stream, h264_data, attr, value); } - } else if (strstart(p, "cliprect:", &p)) { + } else if (av_strstart(p, "cliprect:", &p)) { // could use this if we wanted. } diff --git a/contrib/ffmpeg/libavformat/rtp_h264.h b/contrib/ffmpeg/libavformat/rtp_h264.h index 19508574d..0f23e525c 100644 --- a/contrib/ffmpeg/libavformat/rtp_h264.h +++ b/contrib/ffmpeg/libavformat/rtp_h264.h @@ -19,8 +19,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef RTP_H264_H -#define RTP_H264_H +#ifndef FFMPEG_RTP_H264_H +#define FFMPEG_RTP_H264_H + +#include "rtp_internal.h" extern RTPDynamicProtocolHandler ff_h264_dynamic_handler; -#endif /* RTP_H264_H */ +void ff_rtp_send_h264(AVFormatContext *s1, const uint8_t *buf1, int size); + +#endif /* FFMPEG_RTP_H264_H */ diff --git a/contrib/ffmpeg/libavformat/rtp_internal.h b/contrib/ffmpeg/libavformat/rtp_internal.h index 3edcf49c8..e9d6cb390 100644 --- a/contrib/ffmpeg/libavformat/rtp_internal.h +++ b/contrib/ffmpeg/libavformat/rtp_internal.h @@ -20,8 +20,12 @@ */ // this is a bit of a misnomer, because rtp & rtsp internal structures and prototypes are in here. -#ifndef RTP_INTERNAL_H -#define RTP_INTERNAL_H +#ifndef FFMPEG_RTP_INTERNAL_H +#define FFMPEG_RTP_INTERNAL_H + +#include +#include "avcodec.h" +#include "rtp.h" // these statistics are used for rtcp receiver reports... typedef struct { @@ -37,12 +41,21 @@ typedef struct { uint32_t jitter; ///< estimated jitter. } RTPStatistics; - +/** + * Packet parsing for "private" payloads in the RTP specs. + * + * @param s stream context + * @param pkt packet in which to write the parsed data + * @param timestamp pointer in which to write the timestamp of this RTP packet + * @param buf pointer to raw RTP packet data + * @param len length of buf + * @param flags flags from the RTP packet header (PKT_FLAG_*) + */ typedef int (*DynamicPayloadPacketHandlerProc) (struct RTPDemuxContext * s, AVPacket * pkt, uint32_t *timestamp, const uint8_t * buf, - int len); + int len, int flags); typedef struct RTPDynamicProtocolHandler_s { // fields from AVRtpDynamicPayloadType_s @@ -101,10 +114,18 @@ struct RTPDemuxContext { /* dynamic payload stuff */ DynamicPayloadPacketHandlerProc parse_packet; ///< This is also copied from the dynamic protocol handler structure void *dynamic_protocol_context; ///< This is a copy from the values setup from the sdp parsing, in rtsp.c don't free me. + int max_frames_per_packet; }; extern RTPDynamicProtocolHandler *RTPFirstDynamicPayloadHandler; int rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size); ///< from rtsp.c, but used by rtp dynamic protocol handlers. -#endif /* RTP_INTERNAL_H */ + +void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m); +const char *ff_rtp_enc_name(int payload_type); +enum CodecID ff_rtp_codec_id(const char *buf, enum CodecType codec_type); + +void av_register_rtp_dynamic_payload_handlers(void); + +#endif /* FFMPEG_RTP_INTERNAL_H */ diff --git a/contrib/ffmpeg/libavformat/rtp_mpv.c b/contrib/ffmpeg/libavformat/rtp_mpv.c new file mode 100644 index 000000000..c8bf81f9a --- /dev/null +++ b/contrib/ffmpeg/libavformat/rtp_mpv.c @@ -0,0 +1,118 @@ +/* + * RTP packetization for MPEG video + * Copyright (c) 2002 Fabrice Bellard. + * Copyright (c) 2007 Luca Abeni. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avformat.h" +#include "rtp_internal.h" + +#include "mpegvideo.h" + +/* NOTE: a single frame must be passed with sequence header if + needed. XXX: use slices. */ +void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size) +{ + RTPDemuxContext *s = s1->priv_data; + int len, h, max_packet_size; + uint8_t *q; + int begin_of_slice, end_of_slice, frame_type, temporal_reference; + + max_packet_size = s->max_payload_size; + begin_of_slice = 1; + end_of_slice = 0; + frame_type = 0; + temporal_reference = 0; + + while (size > 0) { + int begin_of_sequence; + + begin_of_sequence = 0; + len = max_packet_size - 4; + + if (len >= size) { + len = size; + end_of_slice = 1; + } else { + const uint8_t *r, *r1; + int start_code; + + r1 = buf1; + while (1) { + start_code = -1; + r = ff_find_start_code(r1, buf1 + size, &start_code); + if((start_code & 0xFFFFFF00) == 0x100) { + /* New start code found */ + if (start_code == 0x100) { + frame_type = (r[1] & 0x38) >> 3; + temporal_reference = (int)r[0] << 2 | r[1] >> 6; + } + if (start_code == 0x1B8) { + begin_of_sequence = 1; + } + + if (r - buf1 < len) { + /* The current slice fits in the packet */ + if (begin_of_slice == 0) { + /* no slice at the beginning of the packet... */ + end_of_slice = 1; + len = r - buf1 - 4; + break; + } + r1 = r; + } else { + if (r - r1 < max_packet_size) { + len = r1 - buf1 - 4; + end_of_slice = 1; + } + break; + } + } else { + break; + } + } + } + + h = 0; + h |= temporal_reference << 16; + h |= begin_of_sequence << 13; + h |= begin_of_slice << 12; + h |= end_of_slice << 11; + h |= frame_type << 8; + + q = s->buf; + *q++ = h >> 24; + *q++ = h >> 16; + *q++ = h >> 8; + *q++ = h; + + memcpy(q, buf1, len); + q += len; + + /* 90 KHz time stamp */ + s->timestamp = s->cur_timestamp; + ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size)); + + buf1 += len; + size -= len; + begin_of_slice = end_of_slice; + end_of_slice = 0; + } +} + + diff --git a/contrib/ffmpeg/libavformat/rtp_mpv.h b/contrib/ffmpeg/libavformat/rtp_mpv.h new file mode 100644 index 000000000..36e649a89 --- /dev/null +++ b/contrib/ffmpeg/libavformat/rtp_mpv.h @@ -0,0 +1,27 @@ +/* + * RTP definitions + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef FFMPEG_RTP_MPV_H +#define FFMPEG_RTP_MPV_H + +#include "avformat.h" + +void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size); + +#endif /* FFMPEG_RTP_MPV_H */ diff --git a/contrib/ffmpeg/libavformat/rtpdec.c b/contrib/ffmpeg/libavformat/rtpdec.c new file mode 100644 index 000000000..7bdfca30a --- /dev/null +++ b/contrib/ffmpeg/libavformat/rtpdec.c @@ -0,0 +1,552 @@ +/* + * RTP input format + * Copyright (c) 2002 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avformat.h" +#include "mpegts.h" +#include "bitstream.h" + +#include +#include "network.h" + +#include "rtp_internal.h" +#include "rtp_h264.h" + +//#define DEBUG + +/* TODO: - add RTCP statistics reporting (should be optional). + + - add support for h263/mpeg4 packetized output : IDEA: send a + buffer to 'rtp_write_packet' contains all the packets for ONE + frame. Each packet should have a four byte header containing + the length in big endian format (same trick as + 'url_open_dyn_packet_buf') +*/ + +/* statistics functions */ +RTPDynamicProtocolHandler *RTPFirstDynamicPayloadHandler= NULL; + +static RTPDynamicProtocolHandler mp4v_es_handler= {"MP4V-ES", CODEC_TYPE_VIDEO, CODEC_ID_MPEG4}; +static RTPDynamicProtocolHandler mpeg4_generic_handler= {"mpeg4-generic", CODEC_TYPE_AUDIO, CODEC_ID_AAC}; + +static void register_dynamic_payload_handler(RTPDynamicProtocolHandler *handler) +{ + handler->next= RTPFirstDynamicPayloadHandler; + RTPFirstDynamicPayloadHandler= handler; +} + +void av_register_rtp_dynamic_payload_handlers(void) +{ + register_dynamic_payload_handler(&mp4v_es_handler); + register_dynamic_payload_handler(&mpeg4_generic_handler); + register_dynamic_payload_handler(&ff_h264_dynamic_handler); +} + +static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf, int len) +{ + if (buf[1] != 200) + return -1; + s->last_rtcp_ntp_time = AV_RB64(buf + 8); + if (s->first_rtcp_ntp_time == AV_NOPTS_VALUE) + s->first_rtcp_ntp_time = s->last_rtcp_ntp_time; + s->last_rtcp_timestamp = AV_RB32(buf + 16); + return 0; +} + +#define RTP_SEQ_MOD (1<<16) + +/** +* called on parse open packet +*/ +static void rtp_init_statistics(RTPStatistics *s, uint16_t base_sequence) // called on parse open packet. +{ + memset(s, 0, sizeof(RTPStatistics)); + s->max_seq= base_sequence; + s->probation= 1; +} + +/** +* called whenever there is a large jump in sequence numbers, or when they get out of probation... +*/ +static void rtp_init_sequence(RTPStatistics *s, uint16_t seq) +{ + s->max_seq= seq; + s->cycles= 0; + s->base_seq= seq -1; + s->bad_seq= RTP_SEQ_MOD + 1; + s->received= 0; + s->expected_prior= 0; + s->received_prior= 0; + s->jitter= 0; + s->transit= 0; +} + +/** +* returns 1 if we should handle this packet. +*/ +static int rtp_valid_packet_in_sequence(RTPStatistics *s, uint16_t seq) +{ + uint16_t udelta= seq - s->max_seq; + const int MAX_DROPOUT= 3000; + const int MAX_MISORDER = 100; + const int MIN_SEQUENTIAL = 2; + + /* source not valid until MIN_SEQUENTIAL packets with sequence seq. numbers have been received */ + if(s->probation) + { + if(seq==s->max_seq + 1) { + s->probation--; + s->max_seq= seq; + if(s->probation==0) { + rtp_init_sequence(s, seq); + s->received++; + return 1; + } + } else { + s->probation= MIN_SEQUENTIAL - 1; + s->max_seq = seq; + } + } else if (udelta < MAX_DROPOUT) { + // in order, with permissible gap + if(seq < s->max_seq) { + //sequence number wrapped; count antother 64k cycles + s->cycles += RTP_SEQ_MOD; + } + s->max_seq= seq; + } else if (udelta <= RTP_SEQ_MOD - MAX_MISORDER) { + // sequence made a large jump... + if(seq==s->bad_seq) { + // two sequential packets-- assume that the other side restarted without telling us; just resync. + rtp_init_sequence(s, seq); + } else { + s->bad_seq= (seq + 1) & (RTP_SEQ_MOD-1); + return 0; + } + } else { + // duplicate or reordered packet... + } + s->received++; + return 1; +} + +#if 0 +/** +* This function is currently unused; without a valid local ntp time, I don't see how we could calculate the +* difference between the arrival and sent timestamp. As a result, the jitter and transit statistics values +* never change. I left this in in case someone else can see a way. (rdm) +*/ +static void rtcp_update_jitter(RTPStatistics *s, uint32_t sent_timestamp, uint32_t arrival_timestamp) +{ + uint32_t transit= arrival_timestamp - sent_timestamp; + int d; + s->transit= transit; + d= FFABS(transit - s->transit); + s->jitter += d - ((s->jitter + 8)>>4); +} +#endif + +int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count) +{ + ByteIOContext *pb; + uint8_t *buf; + int len; + int rtcp_bytes; + RTPStatistics *stats= &s->statistics; + uint32_t lost; + uint32_t extended_max; + uint32_t expected_interval; + uint32_t received_interval; + uint32_t lost_interval; + uint32_t expected; + uint32_t fraction; + uint64_t ntp_time= s->last_rtcp_ntp_time; // TODO: Get local ntp time? + + if (!s->rtp_ctx || (count < 1)) + return -1; + + /* TODO: I think this is way too often; RFC 1889 has algorithm for this */ + /* XXX: mpeg pts hardcoded. RTCP send every 0.5 seconds */ + s->octet_count += count; + rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) / + RTCP_TX_RATIO_DEN; + rtcp_bytes /= 50; // mmu_man: that's enough for me... VLC sends much less btw !? + if (rtcp_bytes < 28) + return -1; + s->last_octet_count = s->octet_count; + + if (url_open_dyn_buf(&pb) < 0) + return -1; + + // Receiver Report + put_byte(pb, (RTP_VERSION << 6) + 1); /* 1 report block */ + put_byte(pb, 201); + put_be16(pb, 7); /* length in words - 1 */ + put_be32(pb, s->ssrc); // our own SSRC + put_be32(pb, s->ssrc); // XXX: should be the server's here! + // some placeholders we should really fill... + // RFC 1889/p64 + extended_max= stats->cycles + stats->max_seq; + expected= extended_max - stats->base_seq + 1; + lost= expected - stats->received; + lost= FFMIN(lost, 0xffffff); // clamp it since it's only 24 bits... + expected_interval= expected - stats->expected_prior; + stats->expected_prior= expected; + received_interval= stats->received - stats->received_prior; + stats->received_prior= stats->received; + lost_interval= expected_interval - received_interval; + if (expected_interval==0 || lost_interval<=0) fraction= 0; + else fraction = (lost_interval<<8)/expected_interval; + + fraction= (fraction<<24) | lost; + + put_be32(pb, fraction); /* 8 bits of fraction, 24 bits of total packets lost */ + put_be32(pb, extended_max); /* max sequence received */ + put_be32(pb, stats->jitter>>4); /* jitter */ + + if(s->last_rtcp_ntp_time==AV_NOPTS_VALUE) + { + put_be32(pb, 0); /* last SR timestamp */ + put_be32(pb, 0); /* delay since last SR */ + } else { + uint32_t middle_32_bits= s->last_rtcp_ntp_time>>16; // this is valid, right? do we need to handle 64 bit values special? + uint32_t delay_since_last= ntp_time - s->last_rtcp_ntp_time; + + put_be32(pb, middle_32_bits); /* last SR timestamp */ + put_be32(pb, delay_since_last); /* delay since last SR */ + } + + // CNAME + put_byte(pb, (RTP_VERSION << 6) + 1); /* 1 report block */ + put_byte(pb, 202); + len = strlen(s->hostname); + put_be16(pb, (6 + len + 3) / 4); /* length in words - 1 */ + put_be32(pb, s->ssrc); + put_byte(pb, 0x01); + put_byte(pb, len); + put_buffer(pb, s->hostname, len); + // padding + for (len = (6 + len) % 4; len % 4; len++) { + put_byte(pb, 0); + } + + put_flush_packet(pb); + len = url_close_dyn_buf(pb, &buf); + if ((len > 0) && buf) { + int result; +#if defined(DEBUG) + printf("sending %d bytes of RR\n", len); +#endif + result= url_write(s->rtp_ctx, buf, len); +#if defined(DEBUG) + printf("result from url_write: %d\n", result); +#endif + av_free(buf); + } + return 0; +} + +/** + * open a new RTP parse context for stream 'st'. 'st' can be NULL for + * MPEG2TS streams to indicate that they should be demuxed inside the + * rtp demux (otherwise CODEC_ID_MPEG2TS packets are returned) + * TODO: change this to not take rtp_payload data, and use the new dynamic payload system. + */ +RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, rtp_payload_data_t *rtp_payload_data) +{ + RTPDemuxContext *s; + + s = av_mallocz(sizeof(RTPDemuxContext)); + if (!s) + return NULL; + s->payload_type = payload_type; + s->last_rtcp_ntp_time = AV_NOPTS_VALUE; + s->first_rtcp_ntp_time = AV_NOPTS_VALUE; + s->ic = s1; + s->st = st; + s->rtp_payload_data = rtp_payload_data; + rtp_init_statistics(&s->statistics, 0); // do we know the initial sequence from sdp? + if (!strcmp(ff_rtp_enc_name(payload_type), "MP2T")) { + s->ts = mpegts_parse_open(s->ic); + if (s->ts == NULL) { + av_free(s); + return NULL; + } + } else { + switch(st->codec->codec_id) { + case CODEC_ID_MPEG1VIDEO: + case CODEC_ID_MPEG2VIDEO: + case CODEC_ID_MP2: + case CODEC_ID_MP3: + case CODEC_ID_MPEG4: + case CODEC_ID_H264: + st->need_parsing = AVSTREAM_PARSE_FULL; + break; + default: + break; + } + } + // needed to send back RTCP RR in RTSP sessions + s->rtp_ctx = rtpc; + gethostname(s->hostname, sizeof(s->hostname)); + return s; +} + +static int rtp_parse_mp4_au(RTPDemuxContext *s, const uint8_t *buf) +{ + int au_headers_length, au_header_size, i; + GetBitContext getbitcontext; + rtp_payload_data_t *infos; + + infos = s->rtp_payload_data; + + if (infos == NULL) + return -1; + + /* decode the first 2 bytes where are stored the AUHeader sections + length in bits */ + au_headers_length = AV_RB16(buf); + + if (au_headers_length > RTP_MAX_PACKET_LENGTH) + return -1; + + infos->au_headers_length_bytes = (au_headers_length + 7) / 8; + + /* skip AU headers length section (2 bytes) */ + buf += 2; + + init_get_bits(&getbitcontext, buf, infos->au_headers_length_bytes * 8); + + /* XXX: Wrong if optionnal additional sections are present (cts, dts etc...) */ + au_header_size = infos->sizelength + infos->indexlength; + if (au_header_size <= 0 || (au_headers_length % au_header_size != 0)) + return -1; + + infos->nb_au_headers = au_headers_length / au_header_size; + infos->au_headers = av_malloc(sizeof(struct AUHeaders) * infos->nb_au_headers); + + /* XXX: We handle multiple AU Section as only one (need to fix this for interleaving) + In my test, the FAAD decoder does not behave correctly when sending each AU one by one + but does when sending the whole as one big packet... */ + infos->au_headers[0].size = 0; + infos->au_headers[0].index = 0; + for (i = 0; i < infos->nb_au_headers; ++i) { + infos->au_headers[0].size += get_bits_long(&getbitcontext, infos->sizelength); + infos->au_headers[0].index = get_bits_long(&getbitcontext, infos->indexlength); + } + + infos->nb_au_headers = 1; + + return 0; +} + +/** + * This was the second switch in rtp_parse packet. Normalizes time, if required, sets stream_index, etc. + */ +static void finalize_packet(RTPDemuxContext *s, AVPacket *pkt, uint32_t timestamp) +{ + switch(s->st->codec->codec_id) { + case CODEC_ID_MP2: + case CODEC_ID_MPEG1VIDEO: + case CODEC_ID_MPEG2VIDEO: + if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE) { + int64_t addend; + + int delta_timestamp; + /* XXX: is it really necessary to unify the timestamp base ? */ + /* compute pts from timestamp with received ntp_time */ + delta_timestamp = timestamp - s->last_rtcp_timestamp; + /* convert to 90 kHz without overflow */ + addend = (s->last_rtcp_ntp_time - s->first_rtcp_ntp_time) >> 14; + addend = (addend * 5625) >> 14; + pkt->pts = addend + delta_timestamp; + } + break; + case CODEC_ID_AAC: + case CODEC_ID_H264: + case CODEC_ID_MPEG4: + pkt->pts = timestamp; + break; + default: + /* no timestamp info yet */ + break; + } + pkt->stream_index = s->st->index; +} + +/** + * Parse an RTP or RTCP packet directly sent as a buffer. + * @param s RTP parse context. + * @param pkt returned packet + * @param buf input buffer or NULL to read the next packets + * @param len buffer len + * @return 0 if a packet is returned, 1 if a packet is returned and more can follow + * (use buf as NULL to read the next). -1 if no packet (error or no more packet). + */ +int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, + const uint8_t *buf, int len) +{ + unsigned int ssrc, h; + int payload_type, seq, ret, flags = 0; + AVStream *st; + uint32_t timestamp; + int rv= 0; + + if (!buf) { + /* return the next packets, if any */ + if(s->st && s->parse_packet) { + timestamp= 0; ///< Should not be used if buf is NULL, but should be set to the timestamp of the packet returned.... + rv= s->parse_packet(s, pkt, ×tamp, NULL, 0, flags); + finalize_packet(s, pkt, timestamp); + return rv; + } else { + // TODO: Move to a dynamic packet handler (like above) + if (s->read_buf_index >= s->read_buf_size) + return -1; + ret = mpegts_parse_packet(s->ts, pkt, s->buf + s->read_buf_index, + s->read_buf_size - s->read_buf_index); + if (ret < 0) + return -1; + s->read_buf_index += ret; + if (s->read_buf_index < s->read_buf_size) + return 1; + else + return 0; + } + } + + if (len < 12) + return -1; + + if ((buf[0] & 0xc0) != (RTP_VERSION << 6)) + return -1; + if (buf[1] >= 200 && buf[1] <= 204) { + rtcp_parse_packet(s, buf, len); + return -1; + } + payload_type = buf[1] & 0x7f; + seq = AV_RB16(buf + 2); + timestamp = AV_RB32(buf + 4); + ssrc = AV_RB32(buf + 8); + /* store the ssrc in the RTPDemuxContext */ + s->ssrc = ssrc; + + /* NOTE: we can handle only one payload type */ + if (s->payload_type != payload_type) + return -1; + + st = s->st; + // only do something with this if all the rtp checks pass... + if(!rtp_valid_packet_in_sequence(&s->statistics, seq)) + { + av_log(st?st->codec:NULL, AV_LOG_ERROR, "RTP: PT=%02x: bad cseq %04x expected=%04x\n", + payload_type, seq, ((s->seq + 1) & 0xffff)); + return -1; + } + + s->seq = seq; + len -= 12; + buf += 12; + + if (!st) { + /* specific MPEG2TS demux support */ + ret = mpegts_parse_packet(s->ts, pkt, buf, len); + if (ret < 0) + return -1; + if (ret < len) { + s->read_buf_size = len - ret; + memcpy(s->buf, buf + ret, s->read_buf_size); + s->read_buf_index = 0; + return 1; + } + } else if (s->parse_packet) { + rv = s->parse_packet(s, pkt, ×tamp, buf, len, flags); + } else { + // at this point, the RTP header has been stripped; This is ASSUMING that there is only 1 CSRC, which in't wise. + switch(st->codec->codec_id) { + case CODEC_ID_MP2: + /* better than nothing: skip mpeg audio RTP header */ + if (len <= 4) + return -1; + h = AV_RB32(buf); + len -= 4; + buf += 4; + av_new_packet(pkt, len); + memcpy(pkt->data, buf, len); + break; + case CODEC_ID_MPEG1VIDEO: + case CODEC_ID_MPEG2VIDEO: + /* better than nothing: skip mpeg video RTP header */ + if (len <= 4) + return -1; + h = AV_RB32(buf); + buf += 4; + len -= 4; + if (h & (1 << 26)) { + /* mpeg2 */ + if (len <= 4) + return -1; + buf += 4; + len -= 4; + } + av_new_packet(pkt, len); + memcpy(pkt->data, buf, len); + break; + // moved from below, verbatim. this is because this section handles packets, and the lower switch handles + // timestamps. + // TODO: Put this into a dynamic packet handler... + case CODEC_ID_AAC: + if (rtp_parse_mp4_au(s, buf)) + return -1; + { + rtp_payload_data_t *infos = s->rtp_payload_data; + if (infos == NULL) + return -1; + buf += infos->au_headers_length_bytes + 2; + len -= infos->au_headers_length_bytes + 2; + + /* XXX: Fixme we only handle the case where rtp_parse_mp4_au define + one au_header */ + av_new_packet(pkt, infos->au_headers[0].size); + memcpy(pkt->data, buf, infos->au_headers[0].size); + buf += infos->au_headers[0].size; + len -= infos->au_headers[0].size; + } + s->read_buf_size = len; + rv= 0; + break; + default: + av_new_packet(pkt, len); + memcpy(pkt->data, buf, len); + break; + } + + // now perform timestamp things.... + finalize_packet(s, pkt, timestamp); + } + return rv; +} + +void rtp_parse_close(RTPDemuxContext *s) +{ + // TODO: fold this into the protocol specific data fields. + if (!strcmp(ff_rtp_enc_name(s->payload_type), "MP2T")) { + mpegts_parse_close(s->ts); + } + av_free(s); +} diff --git a/contrib/ffmpeg/libavformat/rtpenc.c b/contrib/ffmpeg/libavformat/rtpenc.c new file mode 100644 index 000000000..19e4f19fe --- /dev/null +++ b/contrib/ffmpeg/libavformat/rtpenc.c @@ -0,0 +1,366 @@ +/* + * RTP output format + * Copyright (c) 2002 Fabrice Bellard. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "avformat.h" +#include "mpegts.h" +#include "bitstream.h" + +#include +#include "network.h" + +#include "rtp_internal.h" +#include "rtp_mpv.h" +#include "rtp_aac.h" +#include "rtp_h264.h" + +//#define DEBUG + +#define RTCP_SR_SIZE 28 +#define NTP_OFFSET 2208988800ULL +#define NTP_OFFSET_US (NTP_OFFSET * 1000000ULL) + +static uint64_t ntp_time(void) +{ + return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US; +} + +static int rtp_write_header(AVFormatContext *s1) +{ + RTPDemuxContext *s = s1->priv_data; + int payload_type, max_packet_size, n; + AVStream *st; + + if (s1->nb_streams != 1) + return -1; + st = s1->streams[0]; + + payload_type = rtp_get_payload_type(st->codec); + if (payload_type < 0) + payload_type = RTP_PT_PRIVATE; /* private payload type */ + s->payload_type = payload_type; + +// following 2 FIXMEs could be set based on the current time, there is normally no info leak, as RTP will likely be transmitted immediately + s->base_timestamp = 0; /* FIXME: was random(), what should this be? */ + s->timestamp = s->base_timestamp; + s->cur_timestamp = 0; + s->ssrc = 0; /* FIXME: was random(), what should this be? */ + s->first_packet = 1; + s->first_rtcp_ntp_time = AV_NOPTS_VALUE; + + max_packet_size = url_fget_max_packet_size(s1->pb); + if (max_packet_size <= 12) + return AVERROR(EIO); + s->max_payload_size = max_packet_size - 12; + + s->max_frames_per_packet = 0; + if (s1->max_delay) { + if (st->codec->codec_type == CODEC_TYPE_AUDIO) { + if (st->codec->frame_size == 0) { + av_log(s1, AV_LOG_ERROR, "Cannot respect max delay: frame size = 0\n"); + } else { + s->max_frames_per_packet = av_rescale_rnd(s1->max_delay, st->codec->sample_rate, AV_TIME_BASE * st->codec->frame_size, AV_ROUND_DOWN); + } + } + if (st->codec->codec_type == CODEC_TYPE_VIDEO) { + /* FIXME: We should round down here... */ + s->max_frames_per_packet = av_rescale_q(s1->max_delay, AV_TIME_BASE_Q, st->codec->time_base); + } + } + + av_set_pts_info(st, 32, 1, 90000); + switch(st->codec->codec_id) { + case CODEC_ID_MP2: + case CODEC_ID_MP3: + s->buf_ptr = s->buf + 4; + break; + case CODEC_ID_MPEG1VIDEO: + case CODEC_ID_MPEG2VIDEO: + break; + case CODEC_ID_MPEG2TS: + n = s->max_payload_size / TS_PACKET_SIZE; + if (n < 1) + n = 1; + s->max_payload_size = n * TS_PACKET_SIZE; + s->buf_ptr = s->buf; + break; + case CODEC_ID_AAC: + s->read_buf_index = 0; + default: + if (st->codec->codec_type == CODEC_TYPE_AUDIO) { + av_set_pts_info(st, 32, 1, st->codec->sample_rate); + } + s->buf_ptr = s->buf; + break; + } + + return 0; +} + +/* send an rtcp sender report packet */ +static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time) +{ + RTPDemuxContext *s = s1->priv_data; + uint32_t rtp_ts; + +#if defined(DEBUG) + printf("RTCP: %02x %"PRIx64" %x\n", s->payload_type, ntp_time, s->timestamp); +#endif + + if (s->first_rtcp_ntp_time == AV_NOPTS_VALUE) s->first_rtcp_ntp_time = ntp_time; + s->last_rtcp_ntp_time = ntp_time; + rtp_ts = av_rescale_q(ntp_time - s->first_rtcp_ntp_time, AV_TIME_BASE_Q, + s1->streams[0]->time_base) + s->base_timestamp; + put_byte(s1->pb, (RTP_VERSION << 6)); + put_byte(s1->pb, 200); + put_be16(s1->pb, 6); /* length in words - 1 */ + put_be32(s1->pb, s->ssrc); + put_be32(s1->pb, ntp_time / 1000000); + put_be32(s1->pb, ((ntp_time % 1000000) << 32) / 1000000); + put_be32(s1->pb, rtp_ts); + put_be32(s1->pb, s->packet_count); + put_be32(s1->pb, s->octet_count); + put_flush_packet(s1->pb); +} + +/* send an rtp packet. sequence number is incremented, but the caller + must update the timestamp itself */ +void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m) +{ + RTPDemuxContext *s = s1->priv_data; + +#ifdef DEBUG + printf("rtp_send_data size=%d\n", len); +#endif + + /* build the RTP header */ + put_byte(s1->pb, (RTP_VERSION << 6)); + put_byte(s1->pb, (s->payload_type & 0x7f) | ((m & 0x01) << 7)); + put_be16(s1->pb, s->seq); + put_be32(s1->pb, s->timestamp); + put_be32(s1->pb, s->ssrc); + + put_buffer(s1->pb, buf1, len); + put_flush_packet(s1->pb); + + s->seq++; + s->octet_count += len; + s->packet_count++; +} + +/* send an integer number of samples and compute time stamp and fill + the rtp send buffer before sending. */ +static void rtp_send_samples(AVFormatContext *s1, + const uint8_t *buf1, int size, int sample_size) +{ + RTPDemuxContext *s = s1->priv_data; + int len, max_packet_size, n; + + max_packet_size = (s->max_payload_size / sample_size) * sample_size; + /* not needed, but who nows */ + if ((size % sample_size) != 0) + av_abort(); + n = 0; + while (size > 0) { + s->buf_ptr = s->buf; + len = FFMIN(max_packet_size, size); + + /* copy data */ + memcpy(s->buf_ptr, buf1, len); + s->buf_ptr += len; + buf1 += len; + size -= len; + s->timestamp = s->cur_timestamp + n / sample_size; + ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0); + n += (s->buf_ptr - s->buf); + } +} + +/* NOTE: we suppose that exactly one frame is given as argument here */ +/* XXX: test it */ +static void rtp_send_mpegaudio(AVFormatContext *s1, + const uint8_t *buf1, int size) +{ + RTPDemuxContext *s = s1->priv_data; + int len, count, max_packet_size; + + max_packet_size = s->max_payload_size; + + /* test if we must flush because not enough space */ + len = (s->buf_ptr - s->buf); + if ((len + size) > max_packet_size) { + if (len > 4) { + ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0); + s->buf_ptr = s->buf + 4; + } + } + if (s->buf_ptr == s->buf + 4) { + s->timestamp = s->cur_timestamp; + } + + /* add the packet */ + if (size > max_packet_size) { + /* big packet: fragment */ + count = 0; + while (size > 0) { + len = max_packet_size - 4; + if (len > size) + len = size; + /* build fragmented packet */ + s->buf[0] = 0; + s->buf[1] = 0; + s->buf[2] = count >> 8; + s->buf[3] = count; + memcpy(s->buf + 4, buf1, len); + ff_rtp_send_data(s1, s->buf, len + 4, 0); + size -= len; + buf1 += len; + count += len; + } + } else { + if (s->buf_ptr == s->buf + 4) { + /* no fragmentation possible */ + s->buf[0] = 0; + s->buf[1] = 0; + s->buf[2] = 0; + s->buf[3] = 0; + } + memcpy(s->buf_ptr, buf1, size); + s->buf_ptr += size; + } +} + +static void rtp_send_raw(AVFormatContext *s1, + const uint8_t *buf1, int size) +{ + RTPDemuxContext *s = s1->priv_data; + int len, max_packet_size; + + max_packet_size = s->max_payload_size; + + while (size > 0) { + len = max_packet_size; + if (len > size) + len = size; + + s->timestamp = s->cur_timestamp; + ff_rtp_send_data(s1, buf1, len, (len == size)); + + buf1 += len; + size -= len; + } +} + +/* NOTE: size is assumed to be an integer multiple of TS_PACKET_SIZE */ +static void rtp_send_mpegts_raw(AVFormatContext *s1, + const uint8_t *buf1, int size) +{ + RTPDemuxContext *s = s1->priv_data; + int len, out_len; + + while (size >= TS_PACKET_SIZE) { + len = s->max_payload_size - (s->buf_ptr - s->buf); + if (len > size) + len = size; + memcpy(s->buf_ptr, buf1, len); + buf1 += len; + size -= len; + s->buf_ptr += len; + + out_len = s->buf_ptr - s->buf; + if (out_len >= s->max_payload_size) { + ff_rtp_send_data(s1, s->buf, out_len, 0); + s->buf_ptr = s->buf; + } + } +} + +/* write an RTP packet. 'buf1' must contain a single specific frame. */ +static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt) +{ + RTPDemuxContext *s = s1->priv_data; + AVStream *st = s1->streams[0]; + int rtcp_bytes; + int size= pkt->size; + uint8_t *buf1= pkt->data; + +#ifdef DEBUG + printf("%d: write len=%d\n", pkt->stream_index, size); +#endif + + /* XXX: mpeg pts hardcoded. RTCP send every 0.5 seconds */ + rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) / + RTCP_TX_RATIO_DEN; + if (s->first_packet || ((rtcp_bytes >= RTCP_SR_SIZE) && + (ntp_time() - s->last_rtcp_ntp_time > 5000000))) { + rtcp_send_sr(s1, ntp_time()); + s->last_octet_count = s->octet_count; + s->first_packet = 0; + } + s->cur_timestamp = s->base_timestamp + pkt->pts; + + switch(st->codec->codec_id) { + case CODEC_ID_PCM_MULAW: + case CODEC_ID_PCM_ALAW: + case CODEC_ID_PCM_U8: + case CODEC_ID_PCM_S8: + rtp_send_samples(s1, buf1, size, 1 * st->codec->channels); + break; + case CODEC_ID_PCM_U16BE: + case CODEC_ID_PCM_U16LE: + case CODEC_ID_PCM_S16BE: + case CODEC_ID_PCM_S16LE: + rtp_send_samples(s1, buf1, size, 2 * st->codec->channels); + break; + case CODEC_ID_MP2: + case CODEC_ID_MP3: + rtp_send_mpegaudio(s1, buf1, size); + break; + case CODEC_ID_MPEG1VIDEO: + case CODEC_ID_MPEG2VIDEO: + ff_rtp_send_mpegvideo(s1, buf1, size); + break; + case CODEC_ID_AAC: + ff_rtp_send_aac(s1, buf1, size); + break; + case CODEC_ID_MPEG2TS: + rtp_send_mpegts_raw(s1, buf1, size); + break; + case CODEC_ID_H264: + ff_rtp_send_h264(s1, buf1, size); + break; + default: + /* better than nothing : send the codec raw data */ + rtp_send_raw(s1, buf1, size); + break; + } + return 0; +} + +AVOutputFormat rtp_muxer = { + "rtp", + "RTP output format", + NULL, + NULL, + sizeof(RTPDemuxContext), + CODEC_ID_PCM_MULAW, + CODEC_ID_NONE, + rtp_write_header, + rtp_write_packet, +}; diff --git a/contrib/ffmpeg/libavformat/rtpenc_h264.c b/contrib/ffmpeg/libavformat/rtpenc_h264.c new file mode 100644 index 000000000..95d5fff81 --- /dev/null +++ b/contrib/ffmpeg/libavformat/rtpenc_h264.c @@ -0,0 +1,78 @@ +/* + * RTP packetization for H.264 (RFC3984) + * Copyright (c) 2008 Luca Abeni. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file rtpenc_h264.c + * @brief H.264 packetization + * @author Luca Abeni + */ + +#include "avformat.h" +#include "avc.h" +#include "rtp_h264.h" + +static void nal_send(AVFormatContext *s1, const uint8_t *buf, int size, int last) +{ + RTPDemuxContext *s = s1->priv_data; + + av_log(s1, AV_LOG_DEBUG, "Sending NAL %x of len %d M=%d\n", buf[0] & 0x1F, size, last); + if (size <= s->max_payload_size) { + ff_rtp_send_data(s1, buf, size, last); + } else { + uint8_t type = buf[0] & 0x1F; + uint8_t nri = buf[0] & 0x60; + + av_log(s1, AV_LOG_DEBUG, "NAL size %d > %d\n", size, s->max_payload_size); + s->buf[0] = 28; /* FU Indicator; Type = 28 ---> FU-A */ + s->buf[0] |= nri; + s->buf[1] = type; + s->buf[1] |= 1 << 7; + buf += 1; + size -= 1; + while (size + 2 > s->max_payload_size) { + memcpy(&s->buf[2], buf, s->max_payload_size - 2); + ff_rtp_send_data(s1, s->buf, s->max_payload_size, 0); + buf += s->max_payload_size - 2; + size -= s->max_payload_size - 2; + s->buf[1] &= ~(1 << 7); + } + s->buf[1] |= 1 << 6; + memcpy(&s->buf[2], buf, size); + ff_rtp_send_data(s1, s->buf, size + 2, 1); + } +} + +void ff_rtp_send_h264(AVFormatContext *s1, const uint8_t *buf1, int size) +{ + const uint8_t *r; + RTPDemuxContext *s = s1->priv_data; + + s->timestamp = s->cur_timestamp; + r = ff_avc_find_startcode(buf1, buf1 + size); + while (r < buf1 + size) { + const uint8_t *r1; + + while(!*(r++)); + r1 = ff_avc_find_startcode(r, buf1 + size); + nal_send(s1, r, r1 - r, (r1 == buf1 + size)); + r = r1; + } +} diff --git a/contrib/ffmpeg/libavformat/rtpproto.c b/contrib/ffmpeg/libavformat/rtpproto.c index 4d32e667d..d1d5a9247 100644 --- a/contrib/ffmpeg/libavformat/rtpproto.c +++ b/contrib/ffmpeg/libavformat/rtpproto.c @@ -19,10 +19,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avformat.h" +#include "avstring.h" #include #include #include "network.h" +#include "os_support.h" #include #define RTP_TX_BUF_SIZE (64 * 1024) @@ -72,11 +74,11 @@ static void url_add_option(char *buf, int buf_size, const char *fmt, ...) va_start(ap, fmt); if (strchr(buf, '?')) - pstrcat(buf, buf_size, "&"); + av_strlcat(buf, "&", buf_size); else - pstrcat(buf, buf_size, "?"); + av_strlcat(buf, "?", buf_size); vsnprintf(buf1, sizeof(buf1), fmt, ap); - pstrcat(buf, buf_size, buf1); + av_strlcat(buf, buf1, buf_size); va_end(ap); } @@ -138,7 +140,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) if (url_open(&s->rtp_hd, buf, flags) < 0) goto fail; local_port = udp_get_local_port(s->rtp_hd); - /* XXX: need to open another connexion if the port is not even */ + /* XXX: need to open another connection if the port is not even */ /* well, should suppress localport in path */ @@ -162,7 +164,7 @@ static int rtp_open(URLContext *h, const char *uri, int flags) if (s->rtcp_hd) url_close(s->rtcp_hd); av_free(s); - return AVERROR_IO; + return AVERROR(EIO); } static int rtp_read(URLContext *h, uint8_t *buf, int size) @@ -178,9 +180,10 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size) len = recvfrom (s->rtp_fd, buf, size, 0, (struct sockaddr *)&from, &from_len); if (len < 0) { - if (errno == EAGAIN || errno == EINTR) + if (ff_neterrno() == FF_NETERROR(EAGAIN) || + ff_neterrno() == FF_NETERROR(EINTR)) continue; - return AVERROR_IO; + return AVERROR(EIO); } break; } @@ -201,9 +204,10 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size) len = recvfrom (s->rtcp_fd, buf, size, 0, (struct sockaddr *)&from, &from_len); if (len < 0) { - if (errno == EAGAIN || errno == EINTR) + if (ff_neterrno() == FF_NETERROR(EAGAIN) || + ff_neterrno() == FF_NETERROR(EINTR)) continue; - return AVERROR_IO; + return AVERROR(EIO); } break; } @@ -213,9 +217,10 @@ static int rtp_read(URLContext *h, uint8_t *buf, int size) len = recvfrom (s->rtp_fd, buf, size, 0, (struct sockaddr *)&from, &from_len); if (len < 0) { - if (errno == EAGAIN || errno == EINTR) + if (ff_neterrno() == FF_NETERROR(EAGAIN) || + ff_neterrno() == FF_NETERROR(EINTR)) continue; - return AVERROR_IO; + return AVERROR(EIO); } break; } @@ -262,7 +267,7 @@ static int rtp_close(URLContext *h) } /** - * Return the local port used by the RTP connexion + * Return the local port used by the RTP connection * @param s1 media file context * @return the local port number */ diff --git a/contrib/ffmpeg/libavformat/rtsp.c b/contrib/ffmpeg/libavformat/rtsp.c index 7d4c6bf78..14f0a5ce4 100644 --- a/contrib/ffmpeg/libavformat/rtsp.c +++ b/contrib/ffmpeg/libavformat/rtsp.c @@ -23,6 +23,8 @@ #include #include /* for select() prototype */ #include "network.h" +#include "avstring.h" +#include "rtsp.h" #include "rtp_internal.h" @@ -75,13 +77,13 @@ static int rtsp_read_play(AVFormatContext *s); /* XXX: currently, the only way to change the protocols consists in changing this variable */ +#if LIBAVFORMAT_VERSION_INT < (53 << 16) int rtsp_default_protocols = (1 << RTSP_PROTOCOL_RTP_UDP); - -FFRTSPCallback *ff_rtsp_callback = NULL; +#endif static int rtsp_probe(AVProbeData *p) { - if (strstart(p->filename, "rtsp:", NULL)) + if (av_strstart(p->filename, "rtsp:", NULL)) return AVPROBE_SCORE_MAX; return 0; } @@ -167,11 +169,7 @@ static int sdp_parse_rtpmap(AVCodecContext *codec, RTSPStream *rtsp_st, int payl } else { /* We are in a standard case ( from http://www.iana.org/assignments/rtp-parameters) */ /* search into AVRtpPayloadTypes[] */ - for (i = 0; AVRtpPayloadTypes[i].pt >= 0; ++i) - if (!strcmp(buf, AVRtpPayloadTypes[i].enc_name) && (codec->codec_type == AVRtpPayloadTypes[i].codec_type)){ - codec->codec_id = AVRtpPayloadTypes[i].codec_id; - break; - } + codec->codec_id = ff_rtp_codec_id(buf, codec->codec_type); } c = avcodec_find_decoder(codec->codec_id); @@ -339,7 +337,7 @@ static void rtsp_parse_range_npt(const char *p, int64_t *start, int64_t *end) char buf[256]; skip_spaces(&p); - if (!stristart(p, "npt=", &p)) + if (!av_stristart(p, "npt=", &p)) return; *start = AV_NOPTS_VALUE; @@ -407,11 +405,11 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, } break; case 's': - pstrcpy(s->title, sizeof(s->title), p); + av_strlcpy(s->title, p, sizeof(s->title)); break; case 'i': if (s->nb_streams == 0) { - pstrcpy(s->comment, sizeof(s->comment), p); + av_strlcpy(s->comment, p, sizeof(s->comment)); break; } break; @@ -443,7 +441,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, get_word(buf1, sizeof(buf1), &p); /* format list */ rtsp_st->sdp_payload_type = atoi(buf1); - if (!strcmp(AVRtpPayloadTypes[rtsp_st->sdp_payload_type].enc_name, "MP2T")) { + if (!strcmp(ff_rtp_enc_name(rtsp_st->sdp_payload_type), "MP2T")) { /* no corresponding stream */ } else { st = av_new_stream(s, 0); @@ -458,10 +456,10 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, } } /* put a default control url */ - pstrcpy(rtsp_st->control_url, sizeof(rtsp_st->control_url), s->filename); + av_strlcpy(rtsp_st->control_url, s->filename, sizeof(rtsp_st->control_url)); break; case 'a': - if (strstart(p, "control:", &p) && s->nb_streams > 0) { + if (av_strstart(p, "control:", &p) && s->nb_streams > 0) { char proto[32]; /* get the control url */ st = s->streams[s->nb_streams - 1]; @@ -471,12 +469,12 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, url_split(proto, sizeof(proto), NULL, 0, NULL, 0, NULL, NULL, 0, p); if (proto[0] == '\0') { /* relative control URL */ - pstrcat(rtsp_st->control_url, sizeof(rtsp_st->control_url), "/"); - pstrcat(rtsp_st->control_url, sizeof(rtsp_st->control_url), p); + av_strlcat(rtsp_st->control_url, "/", sizeof(rtsp_st->control_url)); + av_strlcat(rtsp_st->control_url, p, sizeof(rtsp_st->control_url)); } else { - pstrcpy(rtsp_st->control_url, sizeof(rtsp_st->control_url), p); + av_strlcpy(rtsp_st->control_url, p, sizeof(rtsp_st->control_url)); } - } else if (strstart(p, "rtpmap:", &p)) { + } else if (av_strstart(p, "rtpmap:", &p)) { /* NOTE: rtpmap is only supported AFTER the 'm=' tag */ get_word(buf1, sizeof(buf1), &p); payload_type = atoi(buf1); @@ -487,7 +485,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, sdp_parse_rtpmap(st->codec, rtsp_st, payload_type, p); } } - } else if (strstart(p, "fmtp:", &p)) { + } else if (av_strstart(p, "fmtp:", &p)) { /* NOTE: fmtp is only supported AFTER the 'a=rtpmap:xxx' tag */ get_word(buf1, sizeof(buf1), &p); payload_type = atoi(buf1); @@ -504,7 +502,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, } } } - } else if(strstart(p, "framesize:", &p)) { + } else if(av_strstart(p, "framesize:", &p)) { // let dynamic protocol handlers have a stab at the line. get_word(buf1, sizeof(buf1), &p); payload_type = atoi(buf1); @@ -517,7 +515,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, } } } - } else if(strstart(p, "range:", &p)) { + } else if(av_strstart(p, "range:", &p)) { int64_t start, end; // this is so that seeking on a streamed file can work. @@ -608,12 +606,19 @@ static void rtsp_parse_transport(RTSPHeader *reply, const char *p) "/", &p); if (*p == '/') p++; - get_word_sep(profile, sizeof(profile), "/;,", &p); - lower_transport[0] = '\0'; - if (*p == '/') { - p++; - get_word_sep(lower_transport, sizeof(lower_transport), - ";,", &p); + if (!strcasecmp (transport_protocol, "rtp")) { + get_word_sep(profile, sizeof(profile), "/;,", &p); + lower_transport[0] = '\0'; + /* rtp/avp/ */ + if (*p == '/') { + p++; + get_word_sep(lower_transport, sizeof(lower_transport), + ";,", &p); + } + } else if (!strcasecmp (transport_protocol, "x-pn-tng")) { + /* x-pn-tng/ */ + get_word_sep(lower_transport, sizeof(lower_transport), "/;,", &p); + profile[0] = '\0'; } if (!strcasecmp(lower_transport, "TCP")) th->protocol = RTSP_PROTOCOL_RTP_TCP; @@ -684,15 +689,15 @@ void rtsp_parse_line(RTSPHeader *reply, const char *buf) /* NOTE: we do case independent match for broken servers */ p = buf; - if (stristart(p, "Session:", &p)) { + if (av_stristart(p, "Session:", &p)) { get_word_sep(reply->session_id, sizeof(reply->session_id), ";", &p); - } else if (stristart(p, "Content-Length:", &p)) { + } else if (av_stristart(p, "Content-Length:", &p)) { reply->content_length = strtol(p, NULL, 10); - } else if (stristart(p, "Transport:", &p)) { + } else if (av_stristart(p, "Transport:", &p)) { rtsp_parse_transport(reply, p); - } else if (stristart(p, "CSeq:", &p)) { + } else if (av_stristart(p, "CSeq:", &p)) { reply->seq = strtol(p, NULL, 10); - } else if (stristart(p, "Range:", &p)) { + } else if (av_stristart(p, "Range:", &p)) { rtsp_parse_range_npt(p, &reply->range_start, &reply->range_end); } } @@ -721,7 +726,7 @@ static void rtsp_skip_packet(AVFormatContext *s) ret = url_readbuf(rt->rtsp_hd, buf, 3); if (ret != 3) return; - len = (buf[1] << 8) | buf[2]; + len = AV_RB16(buf + 1); #ifdef DEBUG printf("skipping RTP packet len=%d\n", len); #endif @@ -751,14 +756,14 @@ static void rtsp_send_cmd(AVFormatContext *s, memset(reply, 0, sizeof(RTSPHeader)); rt->seq++; - pstrcpy(buf, sizeof(buf), cmd); + av_strlcpy(buf, cmd, sizeof(buf)); snprintf(buf1, sizeof(buf1), "CSeq: %d\r\n", rt->seq); - pstrcat(buf, sizeof(buf), buf1); + av_strlcat(buf, buf1, sizeof(buf)); if (rt->session_id[0] != '\0' && !strstr(cmd, "\nIf-Match:")) { snprintf(buf1, sizeof(buf1), "Session: %s\r\n", rt->session_id); - pstrcat(buf, sizeof(buf), buf1); + av_strlcat(buf, buf1, sizeof(buf)); } - pstrcat(buf, sizeof(buf), "\r\n"); + av_strlcat(buf, "\r\n", sizeof(buf)); #ifdef DEBUG printf("Sending:\n%s--\n", buf); #endif @@ -797,14 +802,14 @@ static void rtsp_send_cmd(AVFormatContext *s, reply->status_code = atoi(buf1); } else { rtsp_parse_line(reply, p); - pstrcat(rt->last_reply, sizeof(rt->last_reply), p); - pstrcat(rt->last_reply, sizeof(rt->last_reply), "\n"); + av_strlcat(rt->last_reply, p, sizeof(rt->last_reply)); + av_strlcat(rt->last_reply, "\n", sizeof(rt->last_reply)); } line_count++; } if (rt->session_id[0] == '\0' && reply->session_id[0] != '\0') - pstrcpy(rt->session_id, sizeof(rt->session_id), reply->session_id); + av_strlcpy(rt->session_id, reply->session_id, sizeof(rt->session_id)); content_length = reply->content_length; if (content_length > 0) { @@ -815,12 +820,8 @@ static void rtsp_send_cmd(AVFormatContext *s, } if (content_ptr) *content_ptr = content; -} - - -void rtsp_set_callback(FFRTSPCallback *rtsp_cb) -{ - ff_rtsp_callback = rtsp_cb; + else + av_free(content); } @@ -849,13 +850,13 @@ static int rtsp_read_header(AVFormatContext *s, AVFormatParameters *ap) { RTSPState *rt = s->priv_data; - char host[1024], path[1024], tcpname[1024], cmd[2048]; + char host[1024], path[1024], tcpname[1024], cmd[2048], *option_list, *option; URLContext *rtsp_hd; int port, i, j, ret, err; RTSPHeader reply1, *reply = &reply1; unsigned char *content = NULL; RTSPStream *rtsp_st; - int protocol_mask; + int protocol_mask = 0; AVStream *st; /* extract hostname and port */ @@ -864,10 +865,34 @@ static int rtsp_read_header(AVFormatContext *s, if (port < 0) port = RTSP_DEFAULT_PORT; + /* search for options */ + option_list = strchr(path, '?'); + if (option_list) { + /* remove the options from the path */ + *option_list++ = 0; + while(option_list) { + /* move the option pointer */ + option = option_list; + option_list = strchr(option_list, '&'); + if (option_list) + *(option_list++) = 0; + /* handle the options */ + if (strcmp(option, "udp") == 0) + protocol_mask = (1<< RTSP_PROTOCOL_RTP_UDP); + else if (strcmp(option, "multicast") == 0) + protocol_mask = (1<< RTSP_PROTOCOL_RTP_UDP_MULTICAST); + else if (strcmp(option, "tcp") == 0) + protocol_mask = (1<< RTSP_PROTOCOL_RTP_TCP); + } + } + + if (!protocol_mask) + protocol_mask = rtsp_default_protocols; + /* open the tcp connexion */ snprintf(tcpname, sizeof(tcpname), "tcp://%s:%d", host, port); if (url_open(&rtsp_hd, tcpname, URL_RDWR) < 0) - return AVERROR_IO; + return AVERROR(EIO); rt->rtsp_hd = rtsp_hd; rt->seq = 0; @@ -894,8 +919,6 @@ static int rtsp_read_header(AVFormatContext *s, goto fail; } - protocol_mask = rtsp_default_protocols; - /* for each stream, make the setup request */ /* XXX: we assume the same server is used for the control of each RTSP stream */ @@ -915,9 +938,9 @@ static int rtsp_read_header(AVFormatContext *s, /* first try in specified port range */ if (RTSP_RTP_PORT_MIN != 0) { while(j <= RTSP_RTP_PORT_MAX) { - snprintf(buf, sizeof(buf), "rtp://?localport=%d", j); + snprintf(buf, sizeof(buf), "rtp://%s?localport=%d", host, j); + j += 2; /* we will use two port by rtp stream (rtp and rtcp) */ if (url_open(&rtsp_st->rtp_handle, buf, URL_RDWR) == 0) { - j += 2; /* we will use two port by rtp stream (rtp and rtcp) */ goto rtp_opened; } } @@ -933,7 +956,7 @@ static int rtsp_read_header(AVFormatContext *s, rtp_opened: port = rtp_get_local_port(rtsp_st->rtp_handle); if (transport[0] != '\0') - pstrcat(transport, sizeof(transport), ","); + av_strlcat(transport, ",", sizeof(transport)); snprintf(transport + strlen(transport), sizeof(transport) - strlen(transport) - 1, "RTP/AVP/UDP;unicast;client_port=%d-%d", port, port + 1); @@ -942,14 +965,14 @@ static int rtsp_read_header(AVFormatContext *s, /* RTP/TCP */ else if (protocol_mask & (1 << RTSP_PROTOCOL_RTP_TCP)) { if (transport[0] != '\0') - pstrcat(transport, sizeof(transport), ","); + av_strlcat(transport, ",", sizeof(transport)); snprintf(transport + strlen(transport), sizeof(transport) - strlen(transport) - 1, "RTP/AVP/TCP"); } else if (protocol_mask & (1 << RTSP_PROTOCOL_RTP_UDP_MULTICAST)) { if (transport[0] != '\0') - pstrcat(transport, sizeof(transport), ","); + av_strlcat(transport, ",", sizeof(transport)); snprintf(transport + strlen(transport), sizeof(transport) - strlen(transport) - 1, "RTP/AVP/UDP;multicast"); @@ -1004,15 +1027,13 @@ static int rtsp_read_header(AVFormatContext *s, case RTSP_PROTOCOL_RTP_UDP_MULTICAST: { char url[1024]; - int ttl; + struct in_addr in; - ttl = reply->transports[0].ttl; - if (!ttl) - ttl = 16; + in.s_addr = htonl(reply->transports[0].destination); snprintf(url, sizeof(url), "rtp://%s:%d?multicast=1&ttl=%d", - host, - reply->transports[0].server_port_min, - ttl); + inet_ntoa(in), + reply->transports[0].port_min, + reply->transports[0].ttl); if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { err = AVERROR_INVALIDDATA; goto fail; @@ -1029,7 +1050,7 @@ static int rtsp_read_header(AVFormatContext *s, rtsp_st->rtp_ctx = rtp_parse_open(s, st, rtsp_st->rtp_handle, rtsp_st->sdp_payload_type, &rtsp_st->rtp_payload_data); if (!rtsp_st->rtp_ctx) { - err = AVERROR_NOMEM; + err = AVERROR(ENOMEM); goto fail; } else { if(rtsp_st->dynamic_handler) { @@ -1039,16 +1060,6 @@ static int rtsp_read_header(AVFormatContext *s, } } - /* use callback if available to extend setup */ - if (ff_rtsp_callback) { - if (ff_rtsp_callback(RTSP_ACTION_CLIENT_SETUP, rt->session_id, - NULL, 0, rt->last_reply) < 0) { - err = AVERROR_INVALIDDATA; - goto fail; - } - } - - rt->state = RTSP_STATE_IDLE; rt->seek_timestamp = 0; /* default is to start stream at position zero */ @@ -1093,7 +1104,7 @@ static int tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, if (ret != 3) return -1; id = buf[0]; - len = (buf[1] << 8) | buf[2]; + len = AV_RB16(buf + 1); #ifdef DEBUG_RTP_TCP printf("id=%d len=%d\n", id, len); #endif @@ -1128,7 +1139,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, for(;;) { if (url_interrupt_cb()) - return -1; + return AVERROR(EINTR); FD_ZERO(&rfds); fd_max = -1; for(i = 0; i < rt->nb_rtsp_streams; i++) { @@ -1189,12 +1200,12 @@ static int rtsp_read_packet(AVFormatContext *s, case RTSP_PROTOCOL_RTP_UDP: case RTSP_PROTOCOL_RTP_UDP_MULTICAST: len = udp_read_packet(s, &rtsp_st, buf, sizeof(buf)); - if (rtsp_st->rtp_ctx) + if (len >=0 && rtsp_st->rtp_ctx) rtp_check_and_send_back_rr(rtsp_st->rtp_ctx, len); break; } if (len < 0) - return AVERROR_IO; + return len; ret = rtp_parse_packet(rtsp_st->rtp_ctx, pkt, buf, len); if (ret < 0) goto redo; @@ -1262,7 +1273,7 @@ static int rtsp_read_seek(AVFormatContext *s, int stream_index, { RTSPState *rt = s->priv_data; - rt->seek_timestamp = timestamp; + rt->seek_timestamp = av_rescale_q(timestamp, s->streams[stream_index]->time_base, AV_TIME_BASE_Q); switch(rt->state) { default: case RTSP_STATE_IDLE: @@ -1295,16 +1306,12 @@ static int rtsp_read_close(AVFormatContext *s) s->filename); rtsp_send_cmd(s, cmd, reply, NULL); - if (ff_rtsp_callback) { - ff_rtsp_callback(RTSP_ACTION_CLIENT_TEARDOWN, rt->session_id, - NULL, 0, NULL); - } - rtsp_close_streams(rt); url_close(rt->rtsp_hd); return 0; } +#ifdef CONFIG_RTSP_DEMUXER AVInputFormat rtsp_demuxer = { "rtsp", "RTSP input format", @@ -1318,6 +1325,7 @@ AVInputFormat rtsp_demuxer = { .read_play = rtsp_read_play, .read_pause = rtsp_read_pause, }; +#endif static int sdp_probe(AVProbeData *p1) { @@ -1325,7 +1333,7 @@ static int sdp_probe(AVProbeData *p1) /* we look for a line beginning "c=IN IP4" */ while (p < p_end && *p != '\0') { - if (p + sizeof("c=IN IP4") - 1 < p_end && strstart(p, "c=IN IP4", NULL)) + if (p + sizeof("c=IN IP4") - 1 < p_end && av_strstart(p, "c=IN IP4", NULL)) return AVPROBE_SCORE_MAX / 2; while(p < p_end - 1 && *p != '\n') p++; @@ -1352,7 +1360,7 @@ static int sdp_read_header(AVFormatContext *s, /* read the whole sdp file */ /* XXX: better loading */ content = av_malloc(SDP_MAX_SIZE); - size = get_buffer(&s->pb, content, SDP_MAX_SIZE - 1); + size = get_buffer(s->pb, content, SDP_MAX_SIZE - 1); if (size <= 0) { av_free(content); return AVERROR_INVALIDDATA; @@ -1382,7 +1390,7 @@ static int sdp_read_header(AVFormatContext *s, s->ctx_flags |= AVFMTCTX_NOHEADER; rtsp_st->rtp_ctx = rtp_parse_open(s, st, rtsp_st->rtp_handle, rtsp_st->sdp_payload_type, &rtsp_st->rtp_payload_data); if (!rtsp_st->rtp_ctx) { - err = AVERROR_NOMEM; + err = AVERROR(ENOMEM); goto fail; } else { if(rtsp_st->dynamic_handler) { @@ -1422,6 +1430,7 @@ AVInputFormat sdp_demuxer = { }; #endif +#ifdef CONFIG_REDIR_DEMUXER /* dummy redirector format (used directly in av_open_input_file now) */ static int redir_probe(AVProbeData *pd) { @@ -1429,18 +1438,18 @@ static int redir_probe(AVProbeData *pd) p = pd->buf; while (redir_isspace(*p)) p++; - if (strstart(p, "http://", NULL) || - strstart(p, "rtsp://", NULL)) + if (av_strstart(p, "http://", NULL) || + av_strstart(p, "rtsp://", NULL)) return AVPROBE_SCORE_MAX; return 0; } -/* called from utils.c */ -int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f) +static int redir_read_header(AVFormatContext *s, AVFormatParameters *ap) { char buf[4096], *q; int c; AVFormatContext *ic = NULL; + ByteIOContext *f = s->pb; /* parse each URL and try to open it */ c = url_fgetc(f); @@ -1468,11 +1477,13 @@ int redir_open(AVFormatContext **ic_ptr, ByteIOContext *f) if (av_open_input_file(&ic, buf, NULL, 0, NULL) == 0) break; } - *ic_ptr = ic; if (!ic) - return AVERROR_IO; - else - return 0; + return AVERROR(EIO); + + *s = *ic; + url_fclose(f); + + return 0; } AVInputFormat redir_demuxer = { @@ -1480,7 +1491,8 @@ AVInputFormat redir_demuxer = { "Redirector format", 0, redir_probe, - NULL, + redir_read_header, NULL, NULL, }; +#endif diff --git a/contrib/ffmpeg/libavformat/rtsp.h b/contrib/ffmpeg/libavformat/rtsp.h index 481e2ba49..6adadbc81 100644 --- a/contrib/ffmpeg/libavformat/rtsp.h +++ b/contrib/ffmpeg/libavformat/rtsp.h @@ -18,9 +18,11 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef RTSP_H -#define RTSP_H +#ifndef FFMPEG_RTSP_H +#define FFMPEG_RTSP_H +#include +#include "avformat.h" #include "rtspcodes.h" enum RTSPProtocol { @@ -76,19 +78,16 @@ typedef int FFRTSPCallback(enum RTSPCallbackAction action, char *buf, int buf_size, void *arg); -/** useful for modules: set RTSP callback function */ -void rtsp_set_callback(FFRTSPCallback *rtsp_cb); - int rtsp_init(void); void rtsp_parse_line(RTSPHeader *reply, const char *buf); +#if LIBAVFORMAT_VERSION_INT < (53 << 16) extern int rtsp_default_protocols; +#endif extern int rtsp_rtp_port_min; extern int rtsp_rtp_port_max; -extern FFRTSPCallback *ff_rtsp_callback; -extern AVInputFormat rtsp_demuxer; int rtsp_pause(AVFormatContext *s); int rtsp_resume(AVFormatContext *s); -#endif /* RTSP_H */ +#endif /* FFMPEG_RTSP_H */ diff --git a/contrib/ffmpeg/libavformat/rtspcodes.h b/contrib/ffmpeg/libavformat/rtspcodes.h index 74cfb5d5b..d4ad25b76 100644 --- a/contrib/ffmpeg/libavformat/rtspcodes.h +++ b/contrib/ffmpeg/libavformat/rtspcodes.h @@ -19,6 +19,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef FFMPEG_RTSPCODES_H +#define FFMPEG_RTSPCODES_H + /** RTSP handling */ enum RTSPStatusCode { RTSP_STATUS_OK =200, /**< OK */ @@ -34,3 +37,4 @@ RTSP_STATUS_SERVICE =503, /**< Service Unavailable */ RTSP_STATUS_VERSION =505, /**< RTSP Version not supported */ }; +#endif /* FFMPEG_RTSPCODES_H */ diff --git a/contrib/ffmpeg/libavformat/sdp.c b/contrib/ffmpeg/libavformat/sdp.c new file mode 100644 index 000000000..3a71afcbe --- /dev/null +++ b/contrib/ffmpeg/libavformat/sdp.c @@ -0,0 +1,320 @@ +/* + * copyright (c) 2007 Luca Abeni + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avstring.h" +#include "avformat.h" +#include "avc.h" +#include "base64.h" +#include "rtp.h" + +#ifdef CONFIG_RTP_MUXER +#define MAX_EXTRADATA_SIZE ((INT_MAX - 10) / 2) + +struct sdp_session_level { + int sdp_version; /**< protocol version (currently 0) */ + int id; /**< session id */ + int version; /**< session version */ + int start_time; /**< session start time (NTP time, in seconds), + or 0 in case of permanent session */ + int end_time; /**< session end time (NTP time, in seconds), + or 0 if the session is not bounded */ + int ttl; /**< TTL, in case of multicast stream */ + const char *user; /**< username of the session's creator */ + const char *src_addr; /**< IP address of the machine from which the session was created */ + const char *dst_addr; /**< destination IP address (can be multicast) */ + const char *name; /**< session name (can be an empty string) */ +}; + +static void dest_write(char *buff, int size, const char *dest_addr, int ttl) +{ + if (dest_addr) { + if (ttl > 0) { + av_strlcatf(buff, size, "c=IN IP4 %s/%d\r\n", dest_addr, ttl); + } else { + av_strlcatf(buff, size, "c=IN IP4 %s\r\n", dest_addr); + } + } +} + +static void sdp_write_header(char *buff, int size, struct sdp_session_level *s) +{ + av_strlcatf(buff, size, "v=%d\r\n" + "o=- %d %d IN IPV4 %s\r\n" + "t=%d %d\r\n" + "s=%s\r\n" + "a=tool:libavformat\r\n", + s->sdp_version, + s->id, s->version, s->src_addr, + s->start_time, s->end_time, + s->name[0] ? s->name : "No Name"); + dest_write(buff, size, s->dst_addr, s->ttl); +} + +static int get_address(char *dest_addr, int size, int *ttl, const char *url) +{ + int port; + const char *p; + + url_split(NULL, 0, NULL, 0, dest_addr, size, &port, NULL, 0, url); + + *ttl = 0; + p = strchr(url, '?'); + if (p) { + char buff[64]; + int is_multicast = find_info_tag(buff, sizeof(buff), "multicast", p); + + if (is_multicast) { + if (find_info_tag(buff, sizeof(buff), "ttl", p)) { + *ttl = strtol(buff, NULL, 10); + } else { + *ttl = 5; + } + } + } + + return port; +} + +#define MAX_PSET_SIZE 1024 +static char *extradata2psets(AVCodecContext *c) +{ + char *psets, *p; + const uint8_t *r; + const char *pset_string = "; sprop-parameter-sets="; + + if (c->extradata_size > MAX_EXTRADATA_SIZE) { + av_log(c, AV_LOG_ERROR, "Too many extra data!\n"); + + return NULL; + } + + psets = av_mallocz(MAX_PSET_SIZE); + if (psets == NULL) { + av_log(c, AV_LOG_ERROR, "Cannot allocate memory for the parameter sets\n"); + return NULL; + } + memcpy(psets, pset_string, strlen(pset_string)); + p = psets + strlen(pset_string); + r = ff_avc_find_startcode(c->extradata, c->extradata + c->extradata_size); + while (r < c->extradata + c->extradata_size) { + const uint8_t *r1; + + while (!*(r++)); + r1 = ff_avc_find_startcode(r, c->extradata + c->extradata_size); + if (p != (psets + strlen(pset_string))) { + *p = ','; + p++; + } + if (av_base64_encode(p, MAX_PSET_SIZE - (p - psets), r, r1 - r) == NULL) { + av_log(c, AV_LOG_ERROR, "Cannot BASE64 encode %d %d!\n", MAX_PSET_SIZE - (p - psets), r1 - r); + av_free(psets); + + return NULL; + } + p += strlen(p); + r = r1; + } + + return psets; +} + +static void digit_to_char(char *dst, uint8_t src) +{ + if (src < 10) { + *dst = '0' + src; + } else { + *dst = 'A' + src - 10; + } +} + +static char *data_to_hex(char *buff, const uint8_t *src, int s) +{ + int i; + + for(i = 0; i < s; i++) { + digit_to_char(buff + 2 * i, src[i] >> 4); + digit_to_char(buff + 2 * i + 1, src[i] & 0xF); + } + + return buff; +} + +static char *extradata2config(AVCodecContext *c) +{ + char *config; + + if (c->extradata_size > MAX_EXTRADATA_SIZE) { + av_log(c, AV_LOG_ERROR, "Too many extra data!\n"); + + return NULL; + } + config = av_malloc(10 + c->extradata_size * 2); + if (config == NULL) { + av_log(c, AV_LOG_ERROR, "Cannot allocate memory for the config info\n"); + return NULL; + } + memcpy(config, "; config=", 9); + data_to_hex(config + 9, c->extradata, c->extradata_size); + config[9 + c->extradata_size * 2] = 0; + + return config; +} + +static char *sdp_media_attributes(char *buff, int size, AVCodecContext *c, int payload_type) +{ + char *config = NULL; + + switch (c->codec_id) { + case CODEC_ID_H264: + if (c->extradata_size) { + config = extradata2psets(c); + } + av_strlcatf(buff, size, "a=rtpmap:%d H264/90000\r\n" + "a=fmtp:%d packetization-mode=1%s\r\n", + payload_type, + payload_type, config ? config : ""); + break; + case CODEC_ID_MPEG4: + if (c->extradata_size) { + config = extradata2config(c); + } + av_strlcatf(buff, size, "a=rtpmap:%d MP4V-ES/90000\r\n" + "a=fmtp:%d profile-level-id=1%s\r\n", + payload_type, + payload_type, config ? config : ""); + break; + case CODEC_ID_AAC: + if (c->extradata_size) { + config = extradata2config(c); + } else { + /* FIXME: maybe we can forge config information based on the + * codec parameters... + */ + av_log(c, AV_LOG_ERROR, "AAC with no global headers is currently not supported\n"); + return NULL; + } + if (config == NULL) { + return NULL; + } + av_strlcatf(buff, size, "a=rtpmap:%d MPEG4-GENERIC/%d/%d\r\n" + "a=fmtp:%d profile-level-id=1;" + "mode=AAC-hbr;sizelength=13;indexlength=3;" + "indexdeltalength=3%s\r\n", + payload_type, c->sample_rate, c->channels, + payload_type, config); + break; + case CODEC_ID_PCM_S16BE: + if (payload_type >= 96) + av_strlcatf(buff, size, "a=rtpmap:%d L16/%d/%d\r\n", + payload_type, + c->sample_rate, c->channels); + break; + case CODEC_ID_PCM_MULAW: + if (payload_type >= 96) + av_strlcatf(buff, size, "a=rtpmap:%d PCMU/%d/%d\r\n", + payload_type, + c->sample_rate, c->channels); + break; + case CODEC_ID_PCM_ALAW: + if (payload_type >= 96) + av_strlcatf(buff, size, "a=rtpmap:%d PCMA/%d/%d\r\n", + payload_type, + c->sample_rate, c->channels); + break; + default: + /* Nothing special to do, here... */ + break; + } + + av_free(config); + + return buff; +} + +static void sdp_write_media(char *buff, int size, AVCodecContext *c, const char *dest_addr, int port, int ttl) +{ + const char *type; + int payload_type; + + payload_type = rtp_get_payload_type(c); + if (payload_type < 0) { + payload_type = 96; /* FIXME: how to assign a private pt? rtp.c is broken too */ + } + + switch (c->codec_type) { + case CODEC_TYPE_VIDEO : type = "video" ; break; + case CODEC_TYPE_AUDIO : type = "audio" ; break; + case CODEC_TYPE_SUBTITLE: type = "text" ; break; + default : type = "application"; break; + } + + av_strlcatf(buff, size, "m=%s %d RTP/AVP %d\r\n", type, port, payload_type); + dest_write(buff, size, dest_addr, ttl); + + sdp_media_attributes(buff, size, c, payload_type); +} + +int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size) +{ + struct sdp_session_level s; + int i, j, port, ttl; + char dst[32]; + + memset(buff, 0, size); + memset(&s, 0, sizeof(struct sdp_session_level)); + s.user = "-"; + s.src_addr = "127.0.0.1"; /* FIXME: Properly set this */ + s.name = ac[0]->title; + + port = 0; + ttl = 0; + if (n_files == 1) { + port = get_address(dst, sizeof(dst), &ttl, ac[0]->filename); + if (port > 0) { + s.dst_addr = dst; + s.ttl = ttl; + } + } + sdp_write_header(buff, size, &s); + + dst[0] = 0; + for (i = 0; i < n_files; i++) { + if (n_files != 1) { + port = get_address(dst, sizeof(dst), &ttl, ac[i]->filename); + } + for (j = 0; j < ac[i]->nb_streams; j++) { + sdp_write_media(buff, size, + ac[i]->streams[j]->codec, dst[0] ? dst : NULL, + (port > 0) ? port + j * 2 : 0, ttl); + if (port <= 0) { + av_strlcatf(buff, size, + "a=control:streamid=%d\r\n", i + j); + } + } + } + + return 0; +} +#else +int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size) +{ + return AVERROR(ENOSYS); +} +#endif diff --git a/contrib/ffmpeg/libavformat/segafilm.c b/contrib/ffmpeg/libavformat/segafilm.c index b5375ccf7..5b149a7ca 100644 --- a/contrib/ffmpeg/libavformat/segafilm.c +++ b/contrib/ffmpeg/libavformat/segafilm.c @@ -66,9 +66,6 @@ typedef struct FilmDemuxContext { static int film_probe(AVProbeData *p) { - if (p->buf_size < 4) - return 0; - if (AV_RB32(&p->buf[0]) != FILM_TAG) return 0; @@ -78,8 +75,8 @@ static int film_probe(AVProbeData *p) static int film_read_header(AVFormatContext *s, AVFormatParameters *ap) { - FilmDemuxContext *film = (FilmDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + FilmDemuxContext *film = s->priv_data; + ByteIOContext *pb = s->pb; AVStream *st; unsigned char scratch[256]; int i; @@ -92,7 +89,7 @@ static int film_read_header(AVFormatContext *s, /* load the main FILM header */ if (get_buffer(pb, scratch, 16) != 16) - return AVERROR_IO; + return AVERROR(EIO); data_offset = AV_RB32(&scratch[4]); film->version = AV_RB32(&scratch[8]); @@ -100,7 +97,7 @@ static int film_read_header(AVFormatContext *s, if (film->version == 0) { /* special case for Lemmings .film files; 20-byte header */ if (get_buffer(pb, scratch, 20) != 20) - return AVERROR_IO; + return AVERROR(EIO); /* make some assumptions about the audio parameters */ film->audio_type = CODEC_ID_PCM_S8; film->audio_samplerate = 22050; @@ -109,8 +106,8 @@ static int film_read_header(AVFormatContext *s, } else { /* normal Saturn .cpk files; 32-byte header */ if (get_buffer(pb, scratch, 32) != 32) - return AVERROR_IO; - film->audio_samplerate = AV_RB16(&scratch[24]);; + return AVERROR(EIO); + film->audio_samplerate = AV_RB16(&scratch[24]); film->audio_channels = scratch[21]; film->audio_bits = scratch[22]; if (film->audio_bits == 8) @@ -133,7 +130,7 @@ static int film_read_header(AVFormatContext *s, if (film->video_type) { st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); film->video_stream_index = st->index; st->codec->codec_type = CODEC_TYPE_VIDEO; st->codec->codec_id = film->video_type; @@ -145,7 +142,7 @@ static int film_read_header(AVFormatContext *s, if (film->audio_type) { st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); film->audio_stream_index = st->index; st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = film->audio_type; @@ -161,7 +158,7 @@ static int film_read_header(AVFormatContext *s, /* load the sample table */ if (get_buffer(pb, scratch, 16) != 16) - return AVERROR_IO; + return AVERROR(EIO); if (AV_RB32(&scratch[0]) != STAB_TAG) return AVERROR_INVALIDDATA; film->base_clock = AV_RB32(&scratch[8]); @@ -178,7 +175,7 @@ static int film_read_header(AVFormatContext *s, /* load the next sample record and transfer it to an internal struct */ if (get_buffer(pb, scratch, 16) != 16) { av_free(film->sample_table); - return AVERROR_IO; + return AVERROR(EIO); } film->sample_table[i].sample_offset = data_offset + AV_RB32(&scratch[0]); @@ -206,15 +203,15 @@ static int film_read_header(AVFormatContext *s, static int film_read_packet(AVFormatContext *s, AVPacket *pkt) { - FilmDemuxContext *film = (FilmDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + FilmDemuxContext *film = s->priv_data; + ByteIOContext *pb = s->pb; film_sample_t *sample; int ret = 0; int i; int left, right; if (film->current_sample >= film->sample_count) - return AVERROR_IO; + return AVERROR(EIO); sample = &film->sample_table[film->current_sample]; @@ -226,14 +223,14 @@ static int film_read_packet(AVFormatContext *s, (film->video_type == CODEC_ID_CINEPAK)) { pkt->pos= url_ftell(pb); if (av_new_packet(pkt, sample->sample_size)) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); get_buffer(pb, pkt->data, sample->sample_size); } else if ((sample->stream == film->audio_stream_index) && (film->audio_channels == 2)) { /* stereo PCM needs to be interleaved */ if (av_new_packet(pkt, sample->sample_size)) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); /* make sure the interleave buffer is large enough */ if (sample->sample_size > film->stereo_buffer_size) { @@ -245,7 +242,7 @@ static int film_read_packet(AVFormatContext *s, pkt->pos= url_ftell(pb); ret = get_buffer(pb, film->stereo_buffer, sample->sample_size); if (ret != sample->sample_size) - ret = AVERROR_IO; + ret = AVERROR(EIO); left = 0; right = sample->sample_size / 2; @@ -263,7 +260,7 @@ static int film_read_packet(AVFormatContext *s, } else { ret= av_get_packet(pb, pkt, sample->sample_size); if (ret != sample->sample_size) - ret = AVERROR_IO; + ret = AVERROR(EIO); } pkt->stream_index = sample->stream; @@ -276,7 +273,7 @@ static int film_read_packet(AVFormatContext *s, static int film_read_close(AVFormatContext *s) { - FilmDemuxContext *film = (FilmDemuxContext *)s->priv_data; + FilmDemuxContext *film = s->priv_data; av_free(film->sample_table); av_free(film->stereo_buffer); diff --git a/contrib/ffmpeg/libavformat/sierravmd.c b/contrib/ffmpeg/libavformat/sierravmd.c index 3e1c8597d..5e68a81c4 100644 --- a/contrib/ffmpeg/libavformat/sierravmd.c +++ b/contrib/ffmpeg/libavformat/sierravmd.c @@ -59,9 +59,6 @@ typedef struct VmdDemuxContext { static int vmd_probe(AVProbeData *p) { - if (p->buf_size < 2) - return 0; - /* check if the first 2 bytes of the file contain the appropriate size * of a VMD header chunk */ if (AV_RL16(&p->buf[0]) != VMD_HEADER_SIZE - 2) @@ -74,9 +71,9 @@ static int vmd_probe(AVProbeData *p) static int vmd_read_header(AVFormatContext *s, AVFormatParameters *ap) { - VmdDemuxContext *vmd = (VmdDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; - AVStream *st, *vst; + VmdDemuxContext *vmd = s->priv_data; + ByteIOContext *pb = s->pb; + AVStream *st = NULL, *vst; unsigned int toc_offset; unsigned char *raw_frame_table; int raw_frame_table_size; @@ -92,12 +89,12 @@ static int vmd_read_header(AVFormatContext *s, /* fetch the main header, including the 2 header length bytes */ url_fseek(pb, 0, SEEK_SET); if (get_buffer(pb, vmd->vmd_header, VMD_HEADER_SIZE) != VMD_HEADER_SIZE) - return AVERROR_IO; + return AVERROR(EIO); /* start up the decoders */ vst = av_new_stream(s, 0); if (!vst) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(vst, 33, 1, 10); vmd->video_stream_index = vst->index; vst->codec->codec_type = CODEC_TYPE_VIDEO; @@ -114,7 +111,7 @@ static int vmd_read_header(AVFormatContext *s, if (vmd->sample_rate) { st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); vmd->audio_stream_index = st->index; st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_VMDAUDIO; @@ -158,13 +155,13 @@ static int vmd_read_header(AVFormatContext *s, if (!raw_frame_table || !vmd->frame_table) { av_free(raw_frame_table); av_free(vmd->frame_table); - return AVERROR_NOMEM; + return AVERROR(ENOMEM); } if (get_buffer(pb, raw_frame_table, raw_frame_table_size) != raw_frame_table_size) { av_free(raw_frame_table); av_free(vmd->frame_table); - return AVERROR_IO; + return AVERROR(EIO); } total_frames = 0; @@ -184,6 +181,7 @@ static int vmd_read_header(AVFormatContext *s, continue; switch(type) { case 1: /* Audio Chunk */ + if (!st) break; /* first audio chunk contains several audio buffers */ if(current_audio_pts){ vmd->frame_table[total_frames].frame_offset = current_offset; @@ -247,20 +245,20 @@ static int vmd_read_header(AVFormatContext *s, static int vmd_read_packet(AVFormatContext *s, AVPacket *pkt) { - VmdDemuxContext *vmd = (VmdDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + VmdDemuxContext *vmd = s->priv_data; + ByteIOContext *pb = s->pb; int ret = 0; vmd_frame_t *frame; if (vmd->current_frame >= vmd->frame_count) - return AVERROR_IO; + return AVERROR(EIO); frame = &vmd->frame_table[vmd->current_frame]; /* position the stream (will probably be there already) */ url_fseek(pb, frame->frame_offset, SEEK_SET); if (av_new_packet(pkt, frame->frame_size + BYTES_PER_FRAME_RECORD)) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); pkt->pos= url_ftell(pb); memcpy(pkt->data, frame->frame_record, BYTES_PER_FRAME_RECORD); ret = get_buffer(pb, pkt->data + BYTES_PER_FRAME_RECORD, @@ -268,11 +266,11 @@ static int vmd_read_packet(AVFormatContext *s, if (ret != frame->frame_size) { av_free_packet(pkt); - ret = AVERROR_IO; + ret = AVERROR(EIO); } pkt->stream_index = frame->stream_index; pkt->pts = frame->pts; - av_log(NULL, AV_LOG_INFO, " dispatching %s frame with %d bytes and pts %"PRId64"\n", + av_log(NULL, AV_LOG_DEBUG, " dispatching %s frame with %d bytes and pts %"PRId64"\n", (frame->frame_record[0] == 0x02) ? "video" : "audio", frame->frame_size + BYTES_PER_FRAME_RECORD, pkt->pts); @@ -284,7 +282,7 @@ static int vmd_read_packet(AVFormatContext *s, static int vmd_read_close(AVFormatContext *s) { - VmdDemuxContext *vmd = (VmdDemuxContext *)s->priv_data; + VmdDemuxContext *vmd = s->priv_data; av_free(vmd->frame_table); diff --git a/contrib/ffmpeg/libavformat/siff.c b/contrib/ffmpeg/libavformat/siff.c new file mode 100644 index 000000000..00b4eaa9d --- /dev/null +++ b/contrib/ffmpeg/libavformat/siff.c @@ -0,0 +1,237 @@ +/* + * Beam Software SIFF demuxer + * Copyright (c) 2007 Konstantin Shishkov. + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" +#include "riff.h" + +enum SIFFTags{ + TAG_SIFF = MKTAG('S', 'I', 'F', 'F'), + TAG_BODY = MKTAG('B', 'O', 'D', 'Y'), + TAG_VBHD = MKTAG('V', 'B', 'H', 'D'), + TAG_SHDR = MKTAG('S', 'H', 'D', 'R'), + TAG_VBV1 = MKTAG('V', 'B', 'V', '1'), + TAG_SOUN = MKTAG('S', 'O', 'U', 'N'), +}; + +enum VBFlags{ + VB_HAS_GMC = 0x01, + VB_HAS_AUDIO = 0x04, + VB_HAS_VIDEO = 0x08, + VB_HAS_PALETTE = 0x10, + VB_HAS_LENGTH = 0x20 +}; + +typedef struct SIFFContext{ + int frames; + int cur_frame; + int rate; + int bits; + int block_align; + + int has_video; + int has_audio; + + int curstrm; + int pktsize; + int gmcsize; + int sndsize; + + int flags; + uint8_t gmc[4]; +}SIFFContext; + +static int siff_probe(AVProbeData *p) +{ + /* check file header */ + if (AV_RL32(p->buf) == TAG_SIFF) + return AVPROBE_SCORE_MAX; + else + return 0; +} + +static int create_audio_stream(AVFormatContext *s, SIFFContext *c) +{ + AVStream *ast; + ast = av_new_stream(s, 0); + if (!ast) + return -1; + ast->codec->codec_type = CODEC_TYPE_AUDIO; + ast->codec->codec_id = CODEC_ID_PCM_U8; + ast->codec->channels = 1; + ast->codec->bits_per_sample = c->bits; + ast->codec->sample_rate = c->rate; + ast->codec->frame_size = c->block_align; + av_set_pts_info(ast, 16, 1, c->rate); + return 0; +} + +static int siff_parse_vbv1(AVFormatContext *s, SIFFContext *c, ByteIOContext *pb) +{ + AVStream *st; + int width, height; + + if (get_le32(pb) != TAG_VBHD){ + av_log(s, AV_LOG_ERROR, "Header chunk is missing\n"); + return -1; + } + if(get_be32(pb) != 32){ + av_log(s, AV_LOG_ERROR, "Header chunk size is incorrect\n"); + return -1; + } + if(get_le16(pb) != 1){ + av_log(s, AV_LOG_ERROR, "Incorrect header version\n"); + return -1; + } + width = get_le16(pb); + height = get_le16(pb); + url_fskip(pb, 4); + c->frames = get_le16(pb); + if(!c->frames){ + av_log(s, AV_LOG_ERROR, "File contains no frames ???\n"); + return -1; + } + c->bits = get_le16(pb); + c->rate = get_le16(pb); + c->block_align = c->rate * (c->bits >> 3); + + url_fskip(pb, 16); //zeroes + + st = av_new_stream(s, 0); + if (!st) + return -1; + st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_VB; + st->codec->codec_tag = MKTAG('V', 'B', 'V', '1'); + st->codec->width = width; + st->codec->height = height; + st->codec->pix_fmt = PIX_FMT_PAL8; + av_set_pts_info(st, 16, 1, 12); + + c->cur_frame = 0; + c->has_video = 1; + c->has_audio = !!c->rate; + c->curstrm = -1; + if (c->has_audio && create_audio_stream(s, c) < 0) + return -1; + return 0; +} + +static int siff_parse_soun(AVFormatContext *s, SIFFContext *c, ByteIOContext *pb) +{ + if (get_le32(pb) != TAG_SHDR){ + av_log(s, AV_LOG_ERROR, "Header chunk is missing\n"); + return -1; + } + if(get_be32(pb) != 8){ + av_log(s, AV_LOG_ERROR, "Header chunk size is incorrect\n"); + return -1; + } + url_fskip(pb, 4); //unknown value + c->rate = get_le16(pb); + c->bits = get_le16(pb); + c->block_align = c->rate * (c->bits >> 3); + return create_audio_stream(s, c); +} + +static int siff_read_header(AVFormatContext *s, AVFormatParameters *ap) +{ + ByteIOContext *pb = s->pb; + SIFFContext *c = s->priv_data; + uint32_t tag; + + if (get_le32(pb) != TAG_SIFF) + return -1; + url_fskip(pb, 4); //ignore size + tag = get_le32(pb); + + if (tag != TAG_VBV1 && tag != TAG_SOUN){ + av_log(s, AV_LOG_ERROR, "Not a VBV file\n"); + return -1; + } + + if (tag == TAG_VBV1 && siff_parse_vbv1(s, c, pb) < 0) + return -1; + if (tag == TAG_SOUN && siff_parse_soun(s, c, pb) < 0) + return -1; + if (get_le32(pb) != MKTAG('B', 'O', 'D', 'Y')){ + av_log(s, AV_LOG_ERROR, "'BODY' chunk is missing\n"); + return -1; + } + url_fskip(pb, 4); //ignore size + + return 0; +} + +static int siff_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + SIFFContext *c = s->priv_data; + int size; + + if (c->has_video){ + if (c->cur_frame >= c->frames) + return AVERROR(EIO); + if (c->curstrm == -1){ + c->pktsize = get_le32(s->pb) - 4; + c->flags = get_le16(s->pb); + c->gmcsize = (c->flags & VB_HAS_GMC) ? 4 : 0; + if (c->gmcsize) + get_buffer(s->pb, c->gmc, c->gmcsize); + c->sndsize = (c->flags & VB_HAS_AUDIO) ? get_le32(s->pb): 0; + c->curstrm = !!(c->flags & VB_HAS_AUDIO); + } + + if (!c->curstrm){ + size = c->pktsize - c->sndsize; + if (av_new_packet(pkt, size) < 0) + return AVERROR(ENOMEM); + AV_WL16(pkt->data, c->flags); + if (c->gmcsize) + memcpy(pkt->data + 2, c->gmc, c->gmcsize); + get_buffer(s->pb, pkt->data + 2 + c->gmcsize, size - c->gmcsize - 2); + pkt->stream_index = 0; + c->curstrm = -1; + }else{ + if (av_get_packet(s->pb, pkt, c->sndsize - 4) < 0) + return AVERROR(EIO); + pkt->stream_index = 1; + c->curstrm = 0; + } + if(!c->cur_frame || c->curstrm) + pkt->flags |= PKT_FLAG_KEY; + if (c->curstrm == -1) + c->cur_frame++; + }else{ + size = av_get_packet(s->pb, pkt, c->block_align); + if(size <= 0) + return AVERROR(EIO); + } + return pkt->size; +} + +AVInputFormat siff_demuxer = { + "siff", + "Beam Software SIFF", + sizeof(SIFFContext), + siff_probe, + siff_read_header, + siff_read_packet, + .extensions = "vb,son" +}; diff --git a/contrib/ffmpeg/libavformat/smacker.c b/contrib/ffmpeg/libavformat/smacker.c index 04fde3d03..562a41616 100644 --- a/contrib/ffmpeg/libavformat/smacker.c +++ b/contrib/ffmpeg/libavformat/smacker.c @@ -28,6 +28,7 @@ #include "bswap.h" #define SMACKER_PAL 0x01 +#define SMACKER_FLAG_RING_FRAME 0x01 enum SAudFlags { SMK_AUD_PACKED = 0x80000000, @@ -88,8 +89,6 @@ static const uint8_t smk_pal[64] = { static int smacker_probe(AVProbeData *p) { - if (p->buf_size < 4) - return 0; if(p->buf[0] == 'S' && p->buf[1] == 'M' && p->buf[2] == 'K' && (p->buf[3] == '2' || p->buf[3] == '4')) return AVPROBE_SCORE_MAX; @@ -99,8 +98,8 @@ static int smacker_probe(AVProbeData *p) static int smacker_read_header(AVFormatContext *s, AVFormatParameters *ap) { - ByteIOContext *pb = &s->pb; - SmackerContext *smk = (SmackerContext *)s->priv_data; + ByteIOContext *pb = s->pb; + SmackerContext *smk = s->priv_data; AVStream *st, *ast[7]; int i, ret; int tbase; @@ -114,6 +113,8 @@ static int smacker_read_header(AVFormatContext *s, AVFormatParameters *ap) smk->frames = get_le32(pb); smk->pts_inc = (int32_t)get_le32(pb); smk->flags = get_le32(pb); + if(smk->flags & SMACKER_FLAG_RING_FRAME) + smk->frames++; for(i = 0; i < 7; i++) smk->audio[i] = get_le32(pb); smk->treesize = get_le32(pb); @@ -201,7 +202,7 @@ static int smacker_read_header(AVFormatContext *s, AVFormatParameters *ap) if(ret != st->codec->extradata_size - 16){ av_free(smk->frm_size); av_free(smk->frm_flags); - return AVERROR_IO; + return AVERROR(EIO); } ((int32_t*)st->codec->extradata)[0] = le2me_32(smk->mmap_size); ((int32_t*)st->codec->extradata)[1] = le2me_32(smk->mclr_size); @@ -217,7 +218,7 @@ static int smacker_read_header(AVFormatContext *s, AVFormatParameters *ap) static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt) { - SmackerContext *smk = (SmackerContext *)s->priv_data; + SmackerContext *smk = s->priv_data; int flags; int ret; int i; @@ -225,35 +226,35 @@ static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt) int palchange = 0; int pos; - if (url_feof(&s->pb) || smk->cur_frame >= smk->frames) + if (url_feof(s->pb) || smk->cur_frame >= smk->frames) return AVERROR(EIO); /* if we demuxed all streams, pass another frame */ if(smk->curstream < 0) { - url_fseek(&s->pb, smk->nextpos, 0); + url_fseek(s->pb, smk->nextpos, 0); frame_size = smk->frm_size[smk->cur_frame] & (~3); flags = smk->frm_flags[smk->cur_frame]; /* handle palette change event */ - pos = url_ftell(&s->pb); + pos = url_ftell(s->pb); if(flags & SMACKER_PAL){ int size, sz, t, off, j, pos; uint8_t *pal = smk->pal; uint8_t oldpal[768]; memcpy(oldpal, pal, 768); - size = get_byte(&s->pb); + size = get_byte(s->pb); size = size * 4 - 1; frame_size -= size; frame_size--; sz = 0; - pos = url_ftell(&s->pb) + size; + pos = url_ftell(s->pb) + size; while(sz < 256){ - t = get_byte(&s->pb); + t = get_byte(s->pb); if(t & 0x80){ /* skip palette entries */ sz += (t & 0x7F) + 1; pal += ((t & 0x7F) + 1) * 3; } else if(t & 0x40){ /* copy with offset */ - off = get_byte(&s->pb) * 3; + off = get_byte(s->pb) * 3; j = (t & 0x3F) + 1; while(j-- && sz < 256) { *pal++ = oldpal[off + 0]; @@ -264,12 +265,12 @@ static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt) } } else { /* new entries */ *pal++ = smk_pal[t]; - *pal++ = smk_pal[get_byte(&s->pb) & 0x3F]; - *pal++ = smk_pal[get_byte(&s->pb) & 0x3F]; + *pal++ = smk_pal[get_byte(s->pb) & 0x3F]; + *pal++ = smk_pal[get_byte(s->pb) & 0x3F]; sz++; } } - url_fseek(&s->pb, pos, 0); + url_fseek(s->pb, pos, 0); palchange |= 1; } flags >>= 1; @@ -278,35 +279,35 @@ static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt) for(i = 0; i < 7; i++) { if(flags & 1) { int size; - size = get_le32(&s->pb) - 4; + size = get_le32(s->pb) - 4; frame_size -= size; frame_size -= 4; smk->curstream++; smk->bufs[smk->curstream] = av_realloc(smk->bufs[smk->curstream], size); smk->buf_sizes[smk->curstream] = size; - ret = get_buffer(&s->pb, smk->bufs[smk->curstream], size); + ret = get_buffer(s->pb, smk->bufs[smk->curstream], size); if(ret != size) - return AVERROR_IO; + return AVERROR(EIO); smk->stream_id[smk->curstream] = smk->indexes[i]; } flags >>= 1; } if (av_new_packet(pkt, frame_size + 768)) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); if(smk->frm_size[smk->cur_frame] & 1) palchange |= 2; pkt->data[0] = palchange; memcpy(pkt->data + 1, smk->pal, 768); - ret = get_buffer(&s->pb, pkt->data + 769, frame_size); + ret = get_buffer(s->pb, pkt->data + 769, frame_size); if(ret != frame_size) - return AVERROR_IO; + return AVERROR(EIO); pkt->stream_index = smk->videoindex; pkt->size = ret + 769; smk->cur_frame++; - smk->nextpos = url_ftell(&s->pb); + smk->nextpos = url_ftell(s->pb); } else { if (av_new_packet(pkt, smk->buf_sizes[smk->curstream])) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); memcpy(pkt->data, smk->bufs[smk->curstream], smk->buf_sizes[smk->curstream]); pkt->size = smk->buf_sizes[smk->curstream]; pkt->stream_index = smk->stream_id[smk->curstream]; @@ -320,7 +321,7 @@ static int smacker_read_packet(AVFormatContext *s, AVPacket *pkt) static int smacker_read_close(AVFormatContext *s) { - SmackerContext *smk = (SmackerContext *)s->priv_data; + SmackerContext *smk = s->priv_data; int i; for(i = 0; i < 7; i++) diff --git a/contrib/ffmpeg/libavformat/sol.c b/contrib/ffmpeg/libavformat/sol.c index 951ec6eb9..97ebfdb5e 100644 --- a/contrib/ffmpeg/libavformat/sol.c +++ b/contrib/ffmpeg/libavformat/sol.c @@ -24,7 +24,7 @@ */ #include "avformat.h" -#include "allformats.h" +#include "raw.h" #include "riff.h" #include "bswap.h" @@ -35,8 +35,6 @@ static int sol_probe(AVProbeData *p) { /* check file header */ uint16_t magic; - if (p->buf_size <= 14) - return 0; magic=le2me_16(*((uint16_t*)p->buf)); if ((magic == 0x0B8D || magic == 0x0C0D || magic == 0x0C8D) && p->buf[2] == 'S' && p->buf[3] == 'O' && @@ -90,7 +88,7 @@ static int sol_read_header(AVFormatContext *s, { int size; unsigned int magic,tag; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; unsigned int id, codec, channels, rate, type; AVStream *st; @@ -132,9 +130,9 @@ static int sol_read_packet(AVFormatContext *s, { int ret; - if (url_feof(&s->pb)) + if (url_feof(s->pb)) return AVERROR(EIO); - ret= av_get_packet(&s->pb, pkt, MAX_SIZE); + ret= av_get_packet(s->pb, pkt, MAX_SIZE); pkt->stream_index = 0; /* note: we need to modify the packet size here to handle the last diff --git a/contrib/ffmpeg/libavformat/swf.c b/contrib/ffmpeg/libavformat/swf.c index 7d889af7d..387a96c5f 100644 --- a/contrib/ffmpeg/libavformat/swf.c +++ b/contrib/ffmpeg/libavformat/swf.c @@ -40,6 +40,7 @@ #define TAG_STREAMHEAD2 45 #define TAG_VIDEOSTREAM 60 #define TAG_VIDEOFRAME 61 +#define TAG_FILEATTRIBUTES 69 #define TAG_LONG 0x100 @@ -96,7 +97,7 @@ static const AVCodecTag swf_audio_codec_tags[] = { static void put_swf_tag(AVFormatContext *s, int tag) { SWFContext *swf = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; swf->tag_pos = url_ftell(pb); swf->tag = tag; @@ -112,7 +113,7 @@ static void put_swf_tag(AVFormatContext *s, int tag) static void put_swf_end_tag(AVFormatContext *s) { SWFContext *swf = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; offset_t pos; int tag_len, tag; @@ -187,17 +188,17 @@ static void put_swf_line_edge(PutBitContext *pb, int dx, int dy) mask = (1 << nbits) - 1; put_bits(pb, 4, nbits - 2); /* 16 bits precision */ if (dx == 0) { - put_bits(pb, 1, 0); - put_bits(pb, 1, 1); - put_bits(pb, nbits, dy & mask); + put_bits(pb, 1, 0); + put_bits(pb, 1, 1); + put_bits(pb, nbits, dy & mask); } else if (dy == 0) { - put_bits(pb, 1, 0); - put_bits(pb, 1, 0); - put_bits(pb, nbits, dx & mask); + put_bits(pb, 1, 0); + put_bits(pb, 1, 0); + put_bits(pb, nbits, dx & mask); } else { - put_bits(pb, 1, 1); - put_bits(pb, nbits, dx & mask); - put_bits(pb, nbits, dy & mask); + put_bits(pb, 1, 1); + put_bits(pb, nbits, dx & mask); + put_bits(pb, nbits, dy & mask); } } @@ -244,11 +245,12 @@ static void put_swf_matrix(ByteIOContext *pb, static int swf_write_header(AVFormatContext *s) { SWFContext *swf = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVCodecContext *enc, *audio_enc, *video_enc; PutBitContext p; uint8_t buf1[256]; int i, width, height, rate, rate_base; + int is_avm2; swf->audio_in_pos = 0; swf->sound_samples = 0; @@ -271,9 +273,9 @@ static int swf_write_header(AVFormatContext *s) return -1; } } else { - if ( enc->codec_id == CODEC_ID_VP6F || - enc->codec_id == CODEC_ID_FLV1 || - enc->codec_id == CODEC_ID_MJPEG ) { + if (enc->codec_id == CODEC_ID_VP6F || + enc->codec_id == CODEC_ID_FLV1 || + enc->codec_id == CODEC_ID_MJPEG) { video_enc = enc; } else { av_log(s, AV_LOG_ERROR, "SWF muxer only supports VP6, FLV1 and MJPEG\n"); @@ -283,7 +285,7 @@ static int swf_write_header(AVFormatContext *s) } if (!video_enc) { - /* currenty, cannot work correctly if audio only */ + /* currently, cannot work correctly if audio only */ swf->video_type = 0; width = 320; height = 200; @@ -297,18 +299,22 @@ static int swf_write_header(AVFormatContext *s) rate_base = video_enc->time_base.num; } - if (!audio_enc ) { + if (!audio_enc) { swf->audio_type = 0; - swf->samples_per_frame = ( 44100. * rate_base ) / rate; + swf->samples_per_frame = (44100. * rate_base) / rate; } else { swf->audio_type = audio_enc->codec_id; - swf->samples_per_frame = ( ( audio_enc->sample_rate ) * rate_base ) / rate; + swf->samples_per_frame = (audio_enc->sample_rate * rate_base) / rate; } + is_avm2 = !strcmp("avm2", s->oformat->name); + put_tag(pb, "FWS"); - if ( video_enc && video_enc->codec_id == CODEC_ID_VP6F ) { + if (is_avm2) { + put_byte(pb, 9); + } else if (video_enc && video_enc->codec_id == CODEC_ID_VP6F) { put_byte(pb, 8); /* version (version 8 and above support VP6 codec) */ - } else if ( video_enc && video_enc->codec_id == CODEC_ID_FLV1 ) { + } else if (video_enc && video_enc->codec_id == CODEC_ID_FLV1) { put_byte(pb, 6); /* version (version 6 and above support FLV1 codec) */ } else { put_byte(pb, 4); /* version (should use 4 for mpeg audio support) */ @@ -321,10 +327,17 @@ static int swf_write_header(AVFormatContext *s) swf->duration_pos = url_ftell(pb); put_le16(pb, (uint16_t)(DUMMY_DURATION * (int64_t)rate / rate_base)); /* frame count */ + /* avm2/swf v9 (also v8?) files require a file attribute tag */ + if (is_avm2) { + put_swf_tag(s, TAG_FILEATTRIBUTES); + put_le32(pb, 1<<3); /* set ActionScript v3/AVM2 flag */ + put_swf_end_tag(s); + } + /* define a shape with the jpeg inside */ - if ( video_enc && (video_enc->codec_id == CODEC_ID_VP6F || - video_enc->codec_id == CODEC_ID_FLV1 )) { - } else if ( video_enc && video_enc->codec_id == CODEC_ID_MJPEG ) { + if (video_enc && (video_enc->codec_id == CODEC_ID_VP6F || + video_enc->codec_id == CODEC_ID_FLV1)) { + } else if (video_enc && video_enc->codec_id == CODEC_ID_MJPEG) { put_swf_tag(s, TAG_DEFINESHAPE); put_le16(pb, SHAPE_ID); /* ID of shape */ @@ -336,7 +349,7 @@ static int swf_write_header(AVFormatContext *s) put_le16(pb, BITMAP_ID); /* bitmap ID */ /* position of the bitmap */ put_swf_matrix(pb, (int)(1.0 * (1 << FRAC_BITS)), 0, - 0, (int)(1.0 * (1 << FRAC_BITS)), 0, 0); + 0, (int)(1.0 * (1 << FRAC_BITS)), 0, 0); put_byte(pb, 0); /* no line style */ /* shape drawing */ @@ -367,7 +380,7 @@ static int swf_write_header(AVFormatContext *s) put_swf_end_tag(s); } - if (audio_enc && audio_enc->codec_id == CODEC_ID_MP3 ) { + if (audio_enc && audio_enc->codec_id == CODEC_ID_MP3) { int v; /* start sound */ @@ -386,22 +399,22 @@ static int swf_write_header(AVFormatContext *s) break; default: /* not supported */ - av_log(s, AV_LOG_ERROR, "swf doesnt support that sample rate, choose from (44100, 22050, 11025)\n"); + av_log(s, AV_LOG_ERROR, "swf does not support that sample rate, choose from (44100, 22050, 11025).\n"); return -1; } v |= 0x02; /* 16 bit playback */ if (audio_enc->channels == 2) v |= 0x01; /* stereo playback */ - put_byte(&s->pb, v); + put_byte(s->pb, v); v |= 0x20; /* mp3 compressed */ - put_byte(&s->pb, v); - put_le16(&s->pb, swf->samples_per_frame); /* avg samples per frame */ - put_le16(&s->pb, 0); + put_byte(s->pb, v); + put_le16(s->pb, swf->samples_per_frame); /* avg samples per frame */ + put_le16(s->pb, 0); put_swf_end_tag(s); } - put_flush_packet(&s->pb); + put_flush_packet(s->pb); return 0; } @@ -409,95 +422,95 @@ static int swf_write_video(AVFormatContext *s, AVCodecContext *enc, const uint8_t *buf, int size) { SWFContext *swf = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; /* Flash Player limit */ - if ( swf->swf_frame_number == 16000 ) { + if (swf->swf_frame_number == 16000) { av_log(enc, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n"); } - if ( swf->video_type == CODEC_ID_VP6F || - swf->video_type == CODEC_ID_FLV1 ) { - if ( swf->video_frame_number == 0 ) { - /* create a new video object */ - put_swf_tag(s, TAG_VIDEOSTREAM); - put_le16(pb, VIDEO_ID); - put_le16(pb, 15000 ); /* hard flash player limit */ - put_le16(pb, enc->width); - put_le16(pb, enc->height); - put_byte(pb, 0); - put_byte(pb,codec_get_tag(swf_codec_tags,swf->video_type)); - put_swf_end_tag(s); - - /* place the video object for the first time */ - put_swf_tag(s, TAG_PLACEOBJECT2); - put_byte(pb, 0x36); - put_le16(pb, 1); - put_le16(pb, VIDEO_ID); - put_swf_matrix(pb, 1 << FRAC_BITS, 0, 0, 1 << FRAC_BITS, 0, 0); - put_le16(pb, swf->video_frame_number ); - put_byte(pb, 'v'); - put_byte(pb, 'i'); - put_byte(pb, 'd'); - put_byte(pb, 'e'); - put_byte(pb, 'o'); - put_byte(pb, 0x00); - put_swf_end_tag(s); - } else { - /* mark the character for update */ - put_swf_tag(s, TAG_PLACEOBJECT2); - put_byte(pb, 0x11); - put_le16(pb, 1); - put_le16(pb, swf->video_frame_number ); - put_swf_end_tag(s); - } + if (swf->video_type == CODEC_ID_VP6F || + swf->video_type == CODEC_ID_FLV1) { + if (swf->video_frame_number == 0) { + /* create a new video object */ + put_swf_tag(s, TAG_VIDEOSTREAM); + put_le16(pb, VIDEO_ID); + put_le16(pb, 15000); /* hard flash player limit */ + put_le16(pb, enc->width); + put_le16(pb, enc->height); + put_byte(pb, 0); + put_byte(pb,codec_get_tag(swf_codec_tags,swf->video_type)); + put_swf_end_tag(s); + + /* place the video object for the first time */ + put_swf_tag(s, TAG_PLACEOBJECT2); + put_byte(pb, 0x36); + put_le16(pb, 1); + put_le16(pb, VIDEO_ID); + put_swf_matrix(pb, 1 << FRAC_BITS, 0, 0, 1 << FRAC_BITS, 0, 0); + put_le16(pb, swf->video_frame_number); + put_byte(pb, 'v'); + put_byte(pb, 'i'); + put_byte(pb, 'd'); + put_byte(pb, 'e'); + put_byte(pb, 'o'); + put_byte(pb, 0x00); + put_swf_end_tag(s); + } else { + /* mark the character for update */ + put_swf_tag(s, TAG_PLACEOBJECT2); + put_byte(pb, 0x11); + put_le16(pb, 1); + put_le16(pb, swf->video_frame_number); + put_swf_end_tag(s); + } - /* set video frame data */ - put_swf_tag(s, TAG_VIDEOFRAME | TAG_LONG); - put_le16(pb, VIDEO_ID); - put_le16(pb, swf->video_frame_number++ ); - put_buffer(pb, buf, size); - put_swf_end_tag(s); - } else if ( swf->video_type == CODEC_ID_MJPEG ) { - if (swf->swf_frame_number > 0) { - /* remove the shape */ - put_swf_tag(s, TAG_REMOVEOBJECT); - put_le16(pb, SHAPE_ID); /* shape ID */ - put_le16(pb, 1); /* depth */ - put_swf_end_tag(s); - - /* free the bitmap */ - put_swf_tag(s, TAG_FREECHARACTER); - put_le16(pb, BITMAP_ID); - put_swf_end_tag(s); - } + /* set video frame data */ + put_swf_tag(s, TAG_VIDEOFRAME | TAG_LONG); + put_le16(pb, VIDEO_ID); + put_le16(pb, swf->video_frame_number++); + put_buffer(pb, buf, size); + put_swf_end_tag(s); + } else if (swf->video_type == CODEC_ID_MJPEG) { + if (swf->swf_frame_number > 0) { + /* remove the shape */ + put_swf_tag(s, TAG_REMOVEOBJECT); + put_le16(pb, SHAPE_ID); /* shape ID */ + put_le16(pb, 1); /* depth */ + put_swf_end_tag(s); + + /* free the bitmap */ + put_swf_tag(s, TAG_FREECHARACTER); + put_le16(pb, BITMAP_ID); + put_swf_end_tag(s); + } - put_swf_tag(s, TAG_JPEG2 | TAG_LONG); + put_swf_tag(s, TAG_JPEG2 | TAG_LONG); - put_le16(pb, BITMAP_ID); /* ID of the image */ + put_le16(pb, BITMAP_ID); /* ID of the image */ - /* a dummy jpeg header seems to be required */ - put_byte(pb, 0xff); - put_byte(pb, 0xd8); - put_byte(pb, 0xff); - put_byte(pb, 0xd9); - /* write the jpeg image */ - put_buffer(pb, buf, size); + /* a dummy jpeg header seems to be required */ + put_byte(pb, 0xff); + put_byte(pb, 0xd8); + put_byte(pb, 0xff); + put_byte(pb, 0xd9); + /* write the jpeg image */ + put_buffer(pb, buf, size); - put_swf_end_tag(s); + put_swf_end_tag(s); - /* draw the shape */ + /* draw the shape */ - put_swf_tag(s, TAG_PLACEOBJECT); - put_le16(pb, SHAPE_ID); /* shape ID */ - put_le16(pb, 1); /* depth */ - put_swf_matrix(pb, 20 << FRAC_BITS, 0, 0, 20 << FRAC_BITS, 0, 0); - put_swf_end_tag(s); - } else { - /* invalid codec */ - } + put_swf_tag(s, TAG_PLACEOBJECT); + put_le16(pb, SHAPE_ID); /* shape ID */ + put_le16(pb, 1); /* depth */ + put_swf_matrix(pb, 20 << FRAC_BITS, 0, 0, 20 << FRAC_BITS, 0, 0); + put_swf_end_tag(s); + } else { + /* invalid codec */ + } - swf->swf_frame_number ++; + swf->swf_frame_number ++; /* streaming sound always should be placed just before showframe tags */ if (swf->audio_type && swf->audio_in_pos) { @@ -516,7 +529,7 @@ static int swf_write_video(AVFormatContext *s, put_swf_tag(s, TAG_SHOWFRAME); put_swf_end_tag(s); - put_flush_packet(&s->pb); + put_flush_packet(s->pb); return 0; } @@ -527,7 +540,7 @@ static int swf_write_audio(AVFormatContext *s, SWFContext *swf = s->priv_data; /* Flash Player limit */ - if ( swf->swf_frame_number == 16000 ) { + if (swf->swf_frame_number == 16000) { av_log(enc, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n"); } @@ -541,7 +554,7 @@ static int swf_write_audio(AVFormatContext *s, swf->sound_samples += enc->frame_size; /* if audio only stream make sure we add swf frames */ - if ( swf->video_type == 0 ) { + if (swf->video_type == 0) { swf_write_video(s, enc, 0, 0); } @@ -560,7 +573,7 @@ static int swf_write_packet(AVFormatContext *s, AVPacket *pkt) static int swf_write_trailer(AVFormatContext *s) { SWFContext *swf = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVCodecContext *enc, *video_enc; int file_size, i; @@ -574,10 +587,10 @@ static int swf_write_trailer(AVFormatContext *s) put_swf_tag(s, TAG_END); put_swf_end_tag(s); - put_flush_packet(&s->pb); + put_flush_packet(s->pb); /* patch file size and number of frames if not streamed */ - if (!url_is_streamed(&s->pb) && video_enc) { + if (!url_is_streamed(s->pb) && video_enc) { file_size = url_ftell(pb); url_fseek(pb, 4, SEEK_SET); put_le32(pb, file_size); @@ -618,8 +631,6 @@ static int get_swf_tag(ByteIOContext *pb, int *len_ptr) static int swf_probe(AVProbeData *p) { /* check file header */ - if (p->buf_size <= 16) - return 0; if ((p->buf[0] == 'F' || p->buf[0] == 'C') && p->buf[1] == 'W' && p->buf[2] == 'S') return AVPROBE_SCORE_MAX; @@ -630,21 +641,17 @@ static int swf_probe(AVProbeData *p) static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap) { SWFContext *swf = s->priv_data; - ByteIOContext *pb = &s->pb; - int nbits, len, tag, v; - offset_t frame_offset = -1; - AVStream *ast = 0; - AVStream *vst = 0; + ByteIOContext *pb = s->pb; + int nbits, len, tag; tag = get_be32(pb) & 0xffffff00; - if (tag == MKBETAG('C', 'W', 'S', 0)) - { + if (tag == MKBETAG('C', 'W', 'S', 0)) { av_log(s, AV_LOG_ERROR, "Compressed SWF format not supported\n"); - return AVERROR_IO; + return AVERROR(EIO); } if (tag != MKBETAG('F', 'W', 'S', 0)) - return AVERROR_IO; + return AVERROR(EIO); get_le32(pb); /* skip rectangle size */ nbits = get_byte(pb) >> 3; @@ -654,15 +661,22 @@ static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap) get_le16(pb); /* frame count */ swf->samples_per_frame = 0; + s->ctx_flags |= AVFMTCTX_NOHEADER; + return 0; +} + +static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + SWFContext *swf = s->priv_data; + ByteIOContext *pb = s->pb; + AVStream *vst = NULL, *ast = NULL, *st = 0; + int tag, len, i, frame, v; for(;;) { - offset_t tag_offset = url_ftell(pb); tag = get_swf_tag(pb, &len); - if (tag < 0 || tag == TAG_VIDEOFRAME || tag == TAG_STREAMBLOCK) { - url_fseek(pb, frame_offset == -1 ? tag_offset : frame_offset, SEEK_SET); - break; - } - if ( tag == TAG_VIDEOSTREAM && !vst) { + if (tag < 0) + return AVERROR(EIO); + if (tag == TAG_VIDEOSTREAM && !vst) { int ch_id = get_le16(pb); get_le16(pb); get_le16(pb); @@ -670,58 +684,37 @@ static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap) get_byte(pb); /* Check for FLV1 */ vst = av_new_stream(s, ch_id); + if (!vst) + return -1; vst->codec->codec_type = CODEC_TYPE_VIDEO; vst->codec->codec_id = codec_get_id(swf_codec_tags, get_byte(pb)); - } else if ( ( tag == TAG_STREAMHEAD || tag == TAG_STREAMHEAD2 ) && !ast) { + av_set_pts_info(vst, 64, 256, swf->frame_rate); + vst->codec->time_base = (AVRational){ 256, swf->frame_rate }; + len -= 10; + } else if ((tag == TAG_STREAMHEAD || tag == TAG_STREAMHEAD2) && !ast) { /* streaming found */ int sample_rate_code; get_byte(pb); v = get_byte(pb); swf->samples_per_frame = get_le16(pb); ast = av_new_stream(s, -1); /* -1 to avoid clash with video stream ch_id */ + if (!ast) + return -1; swf->audio_stream_index = ast->index; ast->codec->channels = 1 + (v&1); ast->codec->codec_type = CODEC_TYPE_AUDIO; ast->codec->codec_id = codec_get_id(swf_audio_codec_tags, (v>>4) & 15); - ast->need_parsing = 1; + ast->need_parsing = AVSTREAM_PARSE_FULL; sample_rate_code= (v>>2) & 3; if (!sample_rate_code) - return AVERROR_IO; + return AVERROR(EIO); ast->codec->sample_rate = 11025 << (sample_rate_code-1); av_set_pts_info(ast, 64, 1, ast->codec->sample_rate); - if (len > 4) - url_fskip(pb,len-4); - - } else if (tag == TAG_JPEG2 && !vst) { - vst = av_new_stream(s, -2); /* -2 to avoid clash with video stream and audio stream */ - vst->codec->codec_type = CODEC_TYPE_VIDEO; - vst->codec->codec_id = CODEC_ID_MJPEG; - url_fskip(pb, len); - frame_offset = tag_offset; - } else { - url_fskip(pb, len); - } - } - if (vst) - av_set_pts_info(vst, 64, 256, swf->frame_rate); - return 0; -} - -static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) -{ - SWFContext *swf = s->priv_data; - ByteIOContext *pb = &s->pb; - AVStream *st = 0; - int tag, len, i, frame; - - for(;;) { - tag = get_swf_tag(pb, &len); - if (tag < 0) - return AVERROR_IO; - if (tag == TAG_VIDEOFRAME) { + len -= 4; + } else if (tag == TAG_VIDEOFRAME) { int ch_id = get_le16(pb); len -= 2; - for( i=0; inb_streams; i++ ) { + for(i=0; inb_streams; i++) { st = s->streams[i]; if (st->codec->codec_type == CODEC_TYPE_VIDEO && st->id == ch_id) { frame = get_le16(pb); @@ -744,21 +737,33 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) } else if (tag == TAG_JPEG2) { for (i=0; inb_streams; i++) { st = s->streams[i]; - if (st->id == -2) { - get_le16(pb); /* BITMAP_ID */ - av_new_packet(pkt, len-2); - get_buffer(pb, pkt->data, 4); - if (AV_RB32(pkt->data) == 0xffd8ffd9) { - /* old SWF files containing SOI/EOI as data start */ - pkt->size -= 4; - get_buffer(pb, pkt->data, pkt->size); - } else { - get_buffer(pb, pkt->data + 4, pkt->size - 4); - } - pkt->stream_index = st->index; - return pkt->size; - } + if (st->id == -2) + break; } + if (i == s->nb_streams) { + vst = av_new_stream(s, -2); /* -2 to avoid clash with video stream and audio stream */ + if (!vst) + return -1; + vst->codec->codec_type = CODEC_TYPE_VIDEO; + vst->codec->codec_id = CODEC_ID_MJPEG; + av_set_pts_info(vst, 64, 256, swf->frame_rate); + vst->codec->time_base = (AVRational){ 256, swf->frame_rate }; + st = vst; + } + get_le16(pb); /* BITMAP_ID */ + av_new_packet(pkt, len-2); + get_buffer(pb, pkt->data, 4); + if (AV_RB32(pkt->data) == 0xffd8ffd9 || + AV_RB32(pkt->data) == 0xffd9ffd8) { + /* old SWF files containing SOI/EOI as data start */ + /* files created by swink have reversed tag */ + pkt->size -= 4; + get_buffer(pb, pkt->data, pkt->size); + } else { + get_buffer(pb, pkt->data + 4, pkt->size - 4); + } + pkt->stream_index = st->index; + return pkt->size; } url_fskip(pb, len); } @@ -767,7 +772,7 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) static int swf_read_close(AVFormatContext *s) { - return 0; + return 0; } #ifdef CONFIG_SWF_DEMUXER @@ -795,3 +800,17 @@ AVOutputFormat swf_muxer = { swf_write_trailer, }; #endif +#ifdef CONFIG_AVM2_MUXER +AVOutputFormat avm2_muxer = { + "avm2", + "Flash 9 (AVM2) format", + "application/x-shockwave-flash", + NULL, + sizeof(SWFContext), + CODEC_ID_MP3, + CODEC_ID_FLV1, + swf_write_header, + swf_write_packet, + swf_write_trailer, +}; +#endif diff --git a/contrib/ffmpeg/libavformat/tcp.c b/contrib/ffmpeg/libavformat/tcp.c index a5539be4c..bea0fb909 100644 --- a/contrib/ffmpeg/libavformat/tcp.c +++ b/contrib/ffmpeg/libavformat/tcp.c @@ -21,27 +21,13 @@ #include "avformat.h" #include #include "network.h" +#include "os_support.h" #include -#include typedef struct TCPContext { int fd; } TCPContext; -/* resolve host with also IP address parsing */ -int resolve_host(struct in_addr *sin_addr, const char *hostname) -{ - struct hostent *hp; - - if ((inet_aton(hostname, sin_addr)) == 0) { - hp = gethostbyname(hostname); - if (!hp) - return -1; - memcpy (sin_addr, hp->h_addr, sizeof(struct in_addr)); - } - return 0; -} - /* return non zero if error */ static int tcp_open(URLContext *h, const char *uri, int flags) { @@ -68,6 +54,9 @@ static int tcp_open(URLContext *h, const char *uri, int flags) if (port <= 0 || port >= 65536) goto fail; + if(!ff_network_init()) + return AVERROR(EIO); + dest_addr.sin_family = AF_INET; dest_addr.sin_port = htons(port); if (resolve_host(&dest_addr.sin_addr, hostname) < 0) @@ -76,15 +65,16 @@ static int tcp_open(URLContext *h, const char *uri, int flags) fd = socket(AF_INET, SOCK_STREAM, 0); if (fd < 0) goto fail; - fcntl(fd, F_SETFL, O_NONBLOCK); + ff_socket_nonblock(fd, 1); redo: ret = connect(fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)); if (ret < 0) { - if (errno == EINTR) + if (ff_neterrno() == FF_NETERROR(EINTR)) goto redo; - if (errno != EINPROGRESS) + if (ff_neterrno() != FF_NETERROR(EINPROGRESS) && + ff_neterrno() != FF_NETERROR(EAGAIN)) goto fail; /* wait until we are connected or until abort */ @@ -113,7 +103,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags) return 0; fail: - ret = AVERROR_IO; + ret = AVERROR(EIO); fail1: if (fd >= 0) closesocket(fd); @@ -140,7 +130,8 @@ static int tcp_read(URLContext *h, uint8_t *buf, int size) if (ret > 0 && FD_ISSET(s->fd, &rfds)) { len = recv(s->fd, buf, size, 0); if (len < 0) { - if (errno != EINTR && errno != EAGAIN) + if (ff_neterrno() != FF_NETERROR(EINTR) && + ff_neterrno() != FF_NETERROR(EAGAIN)) return AVERROR(errno); } else return len; } else if (ret < 0) { @@ -169,7 +160,8 @@ static int tcp_write(URLContext *h, uint8_t *buf, int size) if (ret > 0 && FD_ISSET(s->fd, &wfds)) { len = send(s->fd, buf, size, 0); if (len < 0) { - if (errno != EINTR && errno != EAGAIN) + if (ff_neterrno() != FF_NETERROR(EINTR) && + ff_neterrno() != FF_NETERROR(EAGAIN)) return AVERROR(errno); continue; } @@ -186,6 +178,7 @@ static int tcp_close(URLContext *h) { TCPContext *s = h->priv_data; closesocket(s->fd); + ff_network_close(); av_free(s); return 0; } diff --git a/contrib/ffmpeg/libavformat/thp.c b/contrib/ffmpeg/libavformat/thp.c index d0d80428c..a0747ecad 100644 --- a/contrib/ffmpeg/libavformat/thp.c +++ b/contrib/ffmpeg/libavformat/thp.c @@ -21,7 +21,6 @@ #include "avformat.h" -#include "allformats.h" typedef struct ThpDemuxContext { int version; @@ -35,19 +34,18 @@ typedef struct ThpDemuxContext { int next_frame; int next_framesz; int video_stream_index; + int audio_stream_index; int compcount; unsigned char components[16]; AVStream* vst; int has_audio; + int audiosize; } ThpDemuxContext; static int thp_probe(AVProbeData *p) { /* check file header */ - if (p->buf_size < 4) - return 0; - if (AV_RL32(p->buf) == MKTAG('T', 'H', 'P', '\0')) return AVPROBE_SCORE_MAX; else @@ -57,106 +55,135 @@ static int thp_probe(AVProbeData *p) static int thp_read_header(AVFormatContext *s, AVFormatParameters *ap) { - ThpDemuxContext *thp = s->priv_data; - AVStream *st; - ByteIOContext *pb = &s->pb; - int i; - - /* Read the file header. */ - - get_be32(pb); /* Skip Magic. */ - thp->version = get_be32(pb); - - get_be32(pb); /* Max buf size. */ - get_be32(pb); /* Max samples. */ - - thp->fps = av_d2q(av_int2flt(get_be32(pb)), INT_MAX); - thp->framecnt = get_be32(pb); - thp->first_framesz = get_be32(pb); - get_be32(pb); /* Data size. */ - - thp->compoff = get_be32(pb); - get_be32(pb); /* offsetDataOffset. */ - thp->first_frame = get_be32(pb); - thp->last_frame = get_be32(pb); - - thp->next_framesz = thp->first_framesz; - thp->next_frame = thp->first_frame; - - /* Read the component structure. */ - url_fseek (pb, thp->compoff, SEEK_SET); - thp->compcount = get_be32(pb); - - /* Read the list of component types. */ - get_buffer(pb, thp->components, 16); - - for (i = 0; i < thp->compcount; i++) { - if (thp->components[i] == 0) { - if (thp->vst != 0) - break; - - /* Video component. */ - st = av_new_stream(s, 0); - if (!st) - return AVERROR_NOMEM; - - /* The denominator and numerator are switched because 1/fps - is required. */ - av_set_pts_info(st, 64, thp->fps.den, thp->fps.num); - st->codec->codec_type = CODEC_TYPE_VIDEO; - st->codec->codec_id = CODEC_ID_THP; - st->codec->codec_tag = 0; /* no fourcc */ - st->codec->width = get_be32(pb); - st->codec->height = get_be32(pb); - st->codec->sample_rate = av_q2d(thp->fps); - thp->vst = st; - thp->video_stream_index = st->index; - - if (thp->version == 0x11000) - get_be32(pb); /* Unknown. */ + ThpDemuxContext *thp = s->priv_data; + AVStream *st; + ByteIOContext *pb = s->pb; + int i; + + /* Read the file header. */ + get_be32(pb); /* Skip Magic. */ + thp->version = get_be32(pb); + + get_be32(pb); /* Max buf size. */ + get_be32(pb); /* Max samples. */ + + thp->fps = av_d2q(av_int2flt(get_be32(pb)), INT_MAX); + thp->framecnt = get_be32(pb); + thp->first_framesz = get_be32(pb); + get_be32(pb); /* Data size. */ + + thp->compoff = get_be32(pb); + get_be32(pb); /* offsetDataOffset. */ + thp->first_frame = get_be32(pb); + thp->last_frame = get_be32(pb); + + thp->next_framesz = thp->first_framesz; + thp->next_frame = thp->first_frame; + + /* Read the component structure. */ + url_fseek (pb, thp->compoff, SEEK_SET); + thp->compcount = get_be32(pb); + + /* Read the list of component types. */ + get_buffer(pb, thp->components, 16); + + for (i = 0; i < thp->compcount; i++) { + if (thp->components[i] == 0) { + if (thp->vst != 0) + break; + + /* Video component. */ + st = av_new_stream(s, 0); + if (!st) + return AVERROR(ENOMEM); + + /* The denominator and numerator are switched because 1/fps + is required. */ + av_set_pts_info(st, 64, thp->fps.den, thp->fps.num); + st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_THP; + st->codec->codec_tag = 0; /* no fourcc */ + st->codec->width = get_be32(pb); + st->codec->height = get_be32(pb); + st->codec->sample_rate = av_q2d(thp->fps); + thp->vst = st; + thp->video_stream_index = st->index; + + if (thp->version == 0x11000) + get_be32(pb); /* Unknown. */ + } else if (thp->components[i] == 1) { + if (thp->has_audio != 0) + break; + + /* Audio component. */ + st = av_new_stream(s, 0); + if (!st) + return AVERROR(ENOMEM); + + st->codec->codec_type = CODEC_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_ADPCM_THP; + st->codec->codec_tag = 0; /* no fourcc */ + st->codec->channels = get_be32(pb); /* numChannels. */ + st->codec->sample_rate = get_be32(pb); /* Frequency. */ + + av_set_pts_info(st, 64, 1, st->codec->sample_rate); + + thp->audio_stream_index = st->index; + thp->has_audio = 1; } - else if (thp->components[i] == 1) { - /* XXX: Required for audio playback. */ - thp->has_audio = 1; - } } - return 0; + return 0; } static int thp_read_packet(AVFormatContext *s, AVPacket *pkt) { ThpDemuxContext *thp = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int size; int ret; - /* Terminate when last frame is reached. */ - if (thp->frame >= thp->framecnt) - return AVERROR_IO; + if (thp->audiosize == 0) { + /* Terminate when last frame is reached. */ + if (thp->frame >= thp->framecnt) + return AVERROR(EIO); - url_fseek(pb, thp->next_frame, SEEK_SET); + url_fseek(pb, thp->next_frame, SEEK_SET); - /* Locate the next frame and read out its size. */ - thp->next_frame += thp->next_framesz; - thp->next_framesz = get_be32(pb); + /* Locate the next frame and read out its size. */ + thp->next_frame += thp->next_framesz; + thp->next_framesz = get_be32(pb); get_be32(pb); /* Previous total size. */ - size = get_be32(pb); /* Total size of this frame. */ + size = get_be32(pb); /* Total size of this frame. */ + + /* Store the audiosize so the next time this function is called, + the audio can be read. */ + if (thp->has_audio) + thp->audiosize = get_be32(pb); /* Audio size. */ + else + thp->frame++; + + ret = av_get_packet(pb, pkt, size); + if (ret != size) { + av_free_packet(pkt); + return AVERROR(EIO); + } - if (thp->has_audio) - get_be32(pb); /* Audio size. */ + pkt->stream_index = thp->video_stream_index; + } else { + ret = av_get_packet(pb, pkt, thp->audiosize); + if (ret != thp->audiosize) { + av_free_packet(pkt); + return AVERROR(EIO); + } - ret = av_get_packet(pb, pkt, size); - if (ret != size) { - av_free_packet(pkt); - return AVERROR_IO; + pkt->stream_index = thp->audio_stream_index; + thp->audiosize = 0; + thp->frame++; } - pkt->stream_index = thp->video_stream_index; - thp->frame++; - return 0; } diff --git a/contrib/ffmpeg/libavformat/tiertexseq.c b/contrib/ffmpeg/libavformat/tiertexseq.c index 8f565824a..457185b63 100644 --- a/contrib/ffmpeg/libavformat/tiertexseq.c +++ b/contrib/ffmpeg/libavformat/tiertexseq.c @@ -95,7 +95,7 @@ static int seq_init_frame_buffers(SeqDemuxContext *seq, ByteIOContext *pb) seq_buffer->data_size = sz; seq_buffer->data = av_malloc(sz); if (!seq_buffer->data) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); } } seq->frame_buffers_count = i; @@ -115,7 +115,7 @@ static int seq_fill_buffer(SeqDemuxContext *seq, ByteIOContext *pb, int buffer_n url_fseek(pb, seq->current_frame_offs + data_offs, SEEK_SET); if (get_buffer(pb, seq_buffer->data + seq_buffer->fill_size, data_size) != data_size) - return AVERROR_IO; + return AVERROR(EIO); seq_buffer->fill_size += data_size; return 0; @@ -183,8 +183,8 @@ static int seq_parse_frame_data(SeqDemuxContext *seq, ByteIOContext *pb) static int seq_read_header(AVFormatContext *s, AVFormatParameters *ap) { int i, rc; - SeqDemuxContext *seq = (SeqDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + SeqDemuxContext *seq = s->priv_data; + ByteIOContext *pb = s->pb; AVStream *st; /* init internal buffers */ @@ -208,7 +208,7 @@ static int seq_read_header(AVFormatContext *s, AVFormatParameters *ap) /* initialize the video decoder stream */ st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 32, 1, SEQ_FRAME_RATE); seq->video_stream_index = st->index; @@ -221,7 +221,7 @@ static int seq_read_header(AVFormatContext *s, AVFormatParameters *ap) /* initialize the audio decoder stream */ st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 32, 1, SEQ_SAMPLE_RATE); seq->audio_stream_index = st->index; @@ -240,8 +240,8 @@ static int seq_read_header(AVFormatContext *s, AVFormatParameters *ap) static int seq_read_packet(AVFormatContext *s, AVPacket *pkt) { int rc; - SeqDemuxContext *seq = (SeqDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + SeqDemuxContext *seq = s->priv_data; + ByteIOContext *pb = s->pb; if (!seq->audio_buffer_full) { rc = seq_parse_frame_data(seq, pb); @@ -251,14 +251,14 @@ static int seq_read_packet(AVFormatContext *s, AVPacket *pkt) /* video packet */ if (seq->current_pal_data_size + seq->current_video_data_size != 0) { if (av_new_packet(pkt, 1 + seq->current_pal_data_size + seq->current_video_data_size)) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); pkt->data[0] = 0; if (seq->current_pal_data_size != 0) { pkt->data[0] |= 1; url_fseek(pb, seq->current_frame_offs + seq->current_pal_data_offs, SEEK_SET); if (get_buffer(pb, &pkt->data[1], seq->current_pal_data_size) != seq->current_pal_data_size) - return AVERROR_IO; + return AVERROR(EIO); } if (seq->current_video_data_size != 0) { pkt->data[0] |= 2; @@ -277,7 +277,7 @@ static int seq_read_packet(AVFormatContext *s, AVPacket *pkt) /* audio packet */ if (seq->current_audio_data_offs == 0) /* end of data reached */ - return AVERROR_IO; + return AVERROR(EIO); url_fseek(pb, seq->current_frame_offs + seq->current_audio_data_offs, SEEK_SET); rc = av_get_packet(pb, pkt, seq->current_audio_data_size); @@ -294,7 +294,7 @@ static int seq_read_packet(AVFormatContext *s, AVPacket *pkt) static int seq_read_close(AVFormatContext *s) { int i; - SeqDemuxContext *seq = (SeqDemuxContext *)s->priv_data; + SeqDemuxContext *seq = s->priv_data; for (i = 0; i < SEQ_NUM_FRAME_BUFFERS; i++) av_free(seq->frame_buffers[i].data); diff --git a/contrib/ffmpeg/libavformat/tta.c b/contrib/ffmpeg/libavformat/tta.c index a3709437e..2cd0101f1 100644 --- a/contrib/ffmpeg/libavformat/tta.c +++ b/contrib/ffmpeg/libavformat/tta.c @@ -16,21 +16,18 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avformat.h" #include "bitstream.h" typedef struct { int totalframes, currentframe; - uint32_t *seektable; } TTAContext; static int tta_probe(AVProbeData *p) { const uint8_t *d = p->buf; - if (p->buf_size < 4) - return 0; if (d[0] == 'T' && d[1] == 'T' && d[2] == 'A' && d[3] == '1') return 80; return 0; @@ -41,26 +38,27 @@ static int tta_read_header(AVFormatContext *s, AVFormatParameters *ap) TTAContext *c = s->priv_data; AVStream *st; int i, channels, bps, samplerate, datalen, framelen; + uint64_t framepos; - if (get_le32(&s->pb) != ff_get_fourcc("TTA1")) + if (get_le32(s->pb) != ff_get_fourcc("TTA1")) return -1; // not tta file - url_fskip(&s->pb, 2); // FIXME: flags - channels = get_le16(&s->pb); - bps = get_le16(&s->pb); - samplerate = get_le32(&s->pb); + url_fskip(s->pb, 2); // FIXME: flags + channels = get_le16(s->pb); + bps = get_le16(s->pb); + samplerate = get_le32(s->pb); if(samplerate <= 0 || samplerate > 1000000){ av_log(s, AV_LOG_ERROR, "nonsense samplerate\n"); return -1; } - datalen = get_le32(&s->pb); + datalen = get_le32(s->pb); if(datalen < 0){ av_log(s, AV_LOG_ERROR, "nonsense datalen\n"); return -1; } - url_fskip(&s->pb, 4); // header crc + url_fskip(s->pb, 4); // header crc framelen = samplerate*256/245; c->totalframes = datalen / framelen + ((datalen % framelen) ? 1 : 0); @@ -70,33 +68,39 @@ static int tta_read_header(AVFormatContext *s, AVFormatParameters *ap) av_log(s, AV_LOG_ERROR, "totalframes too large\n"); return -1; } - c->seektable = av_mallocz(sizeof(uint32_t)*c->totalframes); - if (!c->seektable) - return AVERROR_NOMEM; - - for (i = 0; i < c->totalframes; i++) - c->seektable[i] = get_le32(&s->pb); - url_fskip(&s->pb, 4); // seektable crc st = av_new_stream(s, 0); -// av_set_pts_info(st, 32, 1, 1000); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); + + av_set_pts_info(st, 64, 1, samplerate); + st->start_time = 0; + st->duration = datalen; + + framepos = url_ftell(s->pb) + 4*c->totalframes + 4; + + for (i = 0; i < c->totalframes; i++) { + uint32_t size = get_le32(s->pb); + av_add_index_entry(st, framepos, i*framelen, size, 0, AVINDEX_KEYFRAME); + framepos += size; + } + url_fskip(s->pb, 4); // seektable crc + st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = CODEC_ID_TTA; st->codec->channels = channels; st->codec->sample_rate = samplerate; st->codec->bits_per_sample = bps; - st->codec->extradata_size = url_ftell(&s->pb); + st->codec->extradata_size = url_ftell(s->pb); if(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codec->extradata_size){ //this check is redundant as get_buffer should fail av_log(s, AV_LOG_ERROR, "extradata_size too large\n"); return -1; } st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE); - url_fseek(&s->pb, 0, SEEK_SET); - get_buffer(&s->pb, st->codec->extradata, st->codec->extradata_size); + url_fseek(s->pb, 0, SEEK_SET); + get_buffer(s->pb, st->codec->extradata, st->codec->extradata_size); return 0; } @@ -104,37 +108,31 @@ static int tta_read_header(AVFormatContext *s, AVFormatParameters *ap) static int tta_read_packet(AVFormatContext *s, AVPacket *pkt) { TTAContext *c = s->priv_data; - int ret, size; + AVStream *st = s->streams[0]; + int size, ret; // FIXME! if (c->currentframe > c->totalframes) - size = 0; - else - size = c->seektable[c->currentframe]; - - c->currentframe++; + return -1; - if (av_new_packet(pkt, size) < 0) - return AVERROR_IO; + size = st->index_entries[c->currentframe].size; - pkt->pos = url_ftell(&s->pb); - pkt->stream_index = 0; - ret = get_buffer(&s->pb, pkt->data, size); - if (ret <= 0) { - av_free_packet(pkt); - return AVERROR_IO; - } - pkt->size = ret; -// av_log(s, AV_LOG_INFO, "TTA packet #%d desired size: %d read size: %d at pos %d\n", -// c->currentframe, size, ret, pkt->pos); - return 0; //ret; + ret = av_get_packet(s->pb, pkt, size); + pkt->dts = st->index_entries[c->currentframe++].timestamp; + return ret; } -static int tta_read_close(AVFormatContext *s) +static int tta_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { TTAContext *c = s->priv_data; - if (c->seektable) - av_free(c->seektable); + AVStream *st = s->streams[stream_index]; + int index = av_index_search_timestamp(st, timestamp, flags); + if (index < 0) + return -1; + + c->currentframe = index; + url_fseek(s->pb, st->index_entries[index].pos, SEEK_SET); + return 0; } @@ -145,6 +143,7 @@ AVInputFormat tta_demuxer = { tta_probe, tta_read_header, tta_read_packet, - tta_read_close, + NULL, + tta_read_seek, .extensions = "tta", }; diff --git a/contrib/ffmpeg/libavformat/txd.c b/contrib/ffmpeg/libavformat/txd.c new file mode 100644 index 000000000..8092a41a4 --- /dev/null +++ b/contrib/ffmpeg/libavformat/txd.c @@ -0,0 +1,103 @@ +/* + * Renderware TeXture Dictionary (.txd) demuxer + * Copyright (c) 2007 Ivo van Poorten + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "avformat.h" + +#define TXD_FILE 0x16 +#define TXD_INFO 0x01 +#define TXD_EXTRA 0x03 +#define TXD_TEXTURE 0x15 +#define TXD_TEXTURE_DATA 0x01 +#define TXD_MARKER 0x1803ffff +#define TXD_MARKER2 0x1003ffff + +static int txd_probe(AVProbeData * pd) { + if (AV_RL32(pd->buf ) == TXD_FILE && + (AV_RL32(pd->buf+8) == TXD_MARKER || AV_RL32(pd->buf+8) == TXD_MARKER2)) + return AVPROBE_SCORE_MAX; + return 0; +} + +static int txd_read_header(AVFormatContext *s, AVFormatParameters *ap) { + AVStream *st; + + st = av_new_stream(s, 0); + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_TXD; + st->codec->time_base.den = 5; + st->codec->time_base.num = 1; + /* the parameters will be extracted from the compressed bitstream */ + return 0; +} + +static int txd_read_packet(AVFormatContext *s, AVPacket *pkt) { + ByteIOContext *pb = s->pb; + unsigned int id, chunk_size, marker; + int ret; + +next_chunk: + id = get_le32(pb); + chunk_size = get_le32(pb); + marker = get_le32(pb); + + if (url_feof(s->pb)) + return AVERROR(EIO); + if (marker != TXD_MARKER && marker != TXD_MARKER2) { + av_log(NULL, AV_LOG_ERROR, "marker does not match\n"); + return AVERROR(EIO); + } + + switch (id) { + case TXD_INFO: + if (chunk_size > 100) + break; + case TXD_EXTRA: + url_fskip(s->pb, chunk_size); + case TXD_FILE: + case TXD_TEXTURE: + goto next_chunk; + default: + av_log(NULL, AV_LOG_ERROR, "unknown chunk id %i\n", id); + return AVERROR(EIO); + } + + ret = av_get_packet(s->pb, pkt, chunk_size); + pkt->stream_index = 0; + + return ret <= 0 ? AVERROR(EIO) : ret; +} + +static int txd_read_close(AVFormatContext *s) { + return 0; +} + +AVInputFormat txd_demuxer = +{ + "txd", + "txd format", + 0, + txd_probe, + txd_read_header, + txd_read_packet, + txd_read_close, +}; diff --git a/contrib/ffmpeg/libavformat/udp.c b/contrib/ffmpeg/libavformat/udp.c index bbf8ca2ec..da3e25382 100644 --- a/contrib/ffmpeg/libavformat/udp.c +++ b/contrib/ffmpeg/libavformat/udp.c @@ -21,6 +21,7 @@ #include "avformat.h" #include #include "network.h" +#include "os_support.h" #ifndef IPV6_ADD_MEMBERSHIP #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP @@ -34,91 +35,98 @@ typedef struct { int local_port; int reuse_socket; #ifndef CONFIG_IPV6 - struct ip_mreq mreq; struct sockaddr_in dest_addr; #else struct sockaddr_storage dest_addr; - size_t dest_addr_len; #endif + size_t dest_addr_len; } UDPContext; #define UDP_TX_BUF_SIZE 32768 +#define UDP_MAX_PKT_SIZE 65536 -#ifdef CONFIG_IPV6 - -static int udp_ipv6_is_multicast_address(const struct sockaddr *addr) { - if (addr->sa_family == AF_INET) - return IN_MULTICAST(ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr)); - if (addr->sa_family == AF_INET6) - return IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)addr)->sin6_addr); - return -1; -} - -static int udp_ipv6_set_multicast_ttl(int sockfd, int mcastTTL, struct sockaddr *addr) { +static int udp_set_multicast_ttl(int sockfd, int mcastTTL, struct sockaddr *addr) { +#ifdef IP_MULTICAST_TTL if (addr->sa_family == AF_INET) { if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)) < 0) { - perror("setsockopt(IP_MULTICAST_TTL)"); + av_log(NULL, AV_LOG_ERROR, "setsockopt(IP_MULTICAST_TTL): %s\n", strerror(errno)); return -1; } } +#endif +#ifdef CONFIG_IPV6 if (addr->sa_family == AF_INET6) { if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &mcastTTL, sizeof(mcastTTL)) < 0) { - perror("setsockopt(IPV6_MULTICAST_HOPS)"); + av_log(NULL, AV_LOG_ERROR, "setsockopt(IPV6_MULTICAST_HOPS): %s\n", strerror(errno)); return -1; } } +#endif return 0; } -static int udp_ipv6_join_multicast_group(int sockfd, struct sockaddr *addr) { - struct ip_mreq mreq; - struct ipv6_mreq mreq6; +static int udp_join_multicast_group(int sockfd, struct sockaddr *addr) { +#ifdef IP_ADD_MEMBERSHIP if (addr->sa_family == AF_INET) { + struct ip_mreq mreq; + mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; mreq.imr_interface.s_addr= INADDR_ANY; if (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) { - perror("setsockopt(IP_ADD_MEMBERSHIP)"); + av_log(NULL, AV_LOG_ERROR, "setsockopt(IP_ADD_MEMBERSHIP): %s\n", strerror(errno)); return -1; } } +#endif +#ifdef CONFIG_IPV6 if (addr->sa_family == AF_INET6) { + struct ipv6_mreq mreq6; + memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr)); mreq6.ipv6mr_interface= 0; if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) { - perror("setsockopt(IPV6_ADD_MEMBERSHIP)"); + av_log(NULL, AV_LOG_ERROR, "setsockopt(IPV6_ADD_MEMBERSHIP): %s\n", strerror(errno)); return -1; } } +#endif return 0; } -static int udp_ipv6_leave_multicast_group(int sockfd, struct sockaddr *addr) { - struct ip_mreq mreq; - struct ipv6_mreq mreq6; +static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr) { +#ifdef IP_DROP_MEMBERSHIP if (addr->sa_family == AF_INET) { + struct ip_mreq mreq; + mreq.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; mreq.imr_interface.s_addr= INADDR_ANY; if (setsockopt(sockfd, IPPROTO_IP, IP_DROP_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) { - perror("setsockopt(IP_DROP_MEMBERSHIP)"); + av_log(NULL, AV_LOG_ERROR, "setsockopt(IP_DROP_MEMBERSHIP): %s\n", strerror(errno)); return -1; } } +#endif +#ifdef CONFIG_IPV6 if (addr->sa_family == AF_INET6) { + struct ipv6_mreq mreq6; + memcpy(&mreq6.ipv6mr_multiaddr, &(((struct sockaddr_in6 *)addr)->sin6_addr), sizeof(struct in6_addr)); mreq6.ipv6mr_interface= 0; if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) { - perror("setsockopt(IPV6_DROP_MEMBERSHIP)"); + av_log(NULL, AV_LOG_ERROR, "setsockopt(IPV6_DROP_MEMBERSHIP): %s\n", strerror(errno)); return -1; } } +#endif return 0; } +#ifdef CONFIG_IPV6 static struct addrinfo* udp_ipv6_resolve_host(const char *hostname, int port, int type, int family, int flags) { struct addrinfo hints, *res = 0; int error; char sport[16]; - const char *node = 0, *service = 0; + const char *node = 0, *service = "0"; if (port > 0) { snprintf(sport, sizeof(sport), "%d", port); @@ -127,80 +135,54 @@ static struct addrinfo* udp_ipv6_resolve_host(const char *hostname, int port, in if ((hostname) && (hostname[0] != '\0') && (hostname[0] != '?')) { node = hostname; } - if ((node) || (service)) { - memset(&hints, 0, sizeof(hints)); - hints.ai_socktype = type; - hints.ai_family = family; - hints.ai_flags = flags; - if ((error = getaddrinfo(node, service, &hints, &res))) { - av_log(NULL, AV_LOG_ERROR, "udp_ipv6_resolve_host: %s\n", gai_strerror(error)); - } + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = type; + hints.ai_family = family; + hints.ai_flags = flags; + if ((error = getaddrinfo(node, service, &hints, &res))) { + av_log(NULL, AV_LOG_ERROR, "udp_ipv6_resolve_host: %s\n", gai_strerror(error)); } + return res; } -static int udp_ipv6_set_remote_url(URLContext *h, const char *uri) { - UDPContext *s = h->priv_data; - char hostname[256]; - int port; +static int udp_set_url(struct sockaddr_storage *addr, const char *hostname, int port) { struct addrinfo *res0; - url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri); + int addr_len; + res0 = udp_ipv6_resolve_host(hostname, port, SOCK_DGRAM, AF_UNSPEC, 0); - if (res0 == 0) return AVERROR_IO; - memcpy(&s->dest_addr, res0->ai_addr, res0->ai_addrlen); - s->dest_addr_len = res0->ai_addrlen; + if (res0 == 0) return AVERROR(EIO); + memcpy(addr, res0->ai_addr, res0->ai_addrlen); + addr_len = res0->ai_addrlen; freeaddrinfo(res0); - return 0; + + return addr_len; } -static int udp_ipv6_set_local(URLContext *h) { - UDPContext *s = h->priv_data; +static int udp_socket_create(UDPContext *s, struct sockaddr_storage *addr, int *addr_len) +{ int udp_fd = -1; - struct sockaddr_storage clientaddr; - socklen_t addrlen; - char sbuf[NI_MAXSERV]; - char hbuf[NI_MAXHOST]; struct addrinfo *res0 = NULL, *res = NULL; + int family = AF_UNSPEC; - if (s->local_port != 0) { - res0 = udp_ipv6_resolve_host(0, s->local_port, SOCK_DGRAM, AF_UNSPEC, AI_PASSIVE); - if (res0 == 0) - goto fail; - for (res = res0; res; res=res->ai_next) { - udp_fd = socket(res->ai_family, SOCK_DGRAM, 0); - if (udp_fd > 0) break; - perror("socket"); - } - } else { - udp_fd = socket(s->dest_addr.ss_family, SOCK_DGRAM, 0); - if (udp_fd < 0) - perror("socket"); - } - - if (udp_fd < 0) + if (((struct sockaddr *) &s->dest_addr)->sa_family) + family = ((struct sockaddr *) &s->dest_addr)->sa_family; + res0 = udp_ipv6_resolve_host(0, s->local_port, SOCK_DGRAM, family, AI_PASSIVE); + if (res0 == 0) goto fail; - - if (s->local_port != 0) { - if (bind(udp_fd, res0->ai_addr, res0->ai_addrlen) < 0) { - perror("bind"); - goto fail; - } - freeaddrinfo(res0); - res0 = NULL; + for (res = res0; res; res=res->ai_next) { + udp_fd = socket(res->ai_family, SOCK_DGRAM, 0); + if (udp_fd > 0) break; + av_log(NULL, AV_LOG_ERROR, "socket: %s\n", strerror(errno)); } - addrlen = sizeof(clientaddr); - if (getsockname(udp_fd, (struct sockaddr *)&clientaddr, &addrlen) < 0) { - perror("getsockname"); + if (udp_fd < 0) goto fail; - } - if (getnameinfo((struct sockaddr *)&clientaddr, addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV) != 0) { - perror("getnameinfo"); - goto fail; - } + memcpy(addr, res->ai_addr, res->ai_addrlen); + *addr_len = res->ai_addrlen; - s->local_port = strtol(sbuf, NULL, 10); + freeaddrinfo(res0); return udp_fd; @@ -212,7 +194,52 @@ static int udp_ipv6_set_local(URLContext *h) { return -1; } -#endif +static int udp_port(struct sockaddr_storage *addr, int addr_len) +{ + char sbuf[sizeof(int)*3+1]; + + if (getnameinfo((struct sockaddr *)addr, addr_len, NULL, 0, sbuf, sizeof(sbuf), NI_NUMERICSERV) != 0) { + av_log(NULL, AV_LOG_ERROR, "getnameinfo: %s\n", strerror(errno)); + return -1; + } + + return strtol(sbuf, NULL, 10); +} + +#else + +static int udp_set_url(struct sockaddr_in *addr, const char *hostname, int port) +{ + /* set the destination address */ + if (resolve_host(&addr->sin_addr, hostname) < 0) + return AVERROR(EIO); + addr->sin_family = AF_INET; + addr->sin_port = htons(port); + + return sizeof(struct sockaddr_in); +} + +static int udp_socket_create(UDPContext *s, struct sockaddr_in *addr, int *addr_len) +{ + int fd; + + fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd < 0) + return -1; + + addr->sin_family = AF_INET; + addr->sin_addr.s_addr = htonl (INADDR_ANY); + addr->sin_port = htons(s->local_port); + *addr_len = sizeof(struct sockaddr_in); + + return fd; +} + +static int udp_port(struct sockaddr_in *addr, int len) +{ + return ntohs(addr->sin_port); +} +#endif /* CONFIG_IPV6 */ /** @@ -233,9 +260,6 @@ static int udp_ipv6_set_local(URLContext *h) { */ int udp_set_remote_url(URLContext *h, const char *uri) { -#ifdef CONFIG_IPV6 - return udp_ipv6_set_remote_url(h, uri); -#else UDPContext *s = h->priv_data; char hostname[256]; int port; @@ -243,12 +267,12 @@ int udp_set_remote_url(URLContext *h, const char *uri) url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri); /* set the destination address */ - if (resolve_host(&s->dest_addr.sin_addr, hostname) < 0) - return AVERROR_IO; - s->dest_addr.sin_family = AF_INET; - s->dest_addr.sin_port = htons(port); + s->dest_addr_len = udp_set_url(&s->dest_addr, hostname, port); + if (s->dest_addr_len < 0) { + return AVERROR(EIO); + } + return 0; -#endif } /** @@ -284,24 +308,23 @@ static int udp_open(URLContext *h, const char *uri, int flags) const char *p; char buf[256]; #ifndef CONFIG_IPV6 - struct sockaddr_in my_addr, my_addr1; - int len; + struct sockaddr_in my_addr; +#else + struct sockaddr_storage my_addr; #endif + int len; h->is_streamed = 1; h->max_packet_size = 1472; is_output = (flags & URL_WRONLY); - s = av_malloc(sizeof(UDPContext)); + s = av_mallocz(sizeof(UDPContext)); if (!s) return AVERROR(ENOMEM); h->priv_data = s; s->ttl = 16; - s->is_multicast = 0; - s->local_port = 0; - s->reuse_socket = 0; p = strchr(uri, '?'); if (p) { s->is_multicast = find_info_tag(buf, sizeof(buf), "multicast", p); @@ -329,78 +352,51 @@ static int udp_open(URLContext *h, const char *uri, int flags) udp_set_remote_url(h, uri); } -#ifndef CONFIG_IPV6 - udp_fd = socket(AF_INET, SOCK_DGRAM, 0); + if(!ff_network_init()) + return AVERROR(EIO); + + if (s->is_multicast && !(h->flags & URL_WRONLY)) + s->local_port = port; + udp_fd = udp_socket_create(s, &my_addr, &len); if (udp_fd < 0) goto fail; - my_addr.sin_family = AF_INET; - my_addr.sin_addr.s_addr = htonl (INADDR_ANY); - if (s->is_multicast && !(h->flags & URL_WRONLY)) { - /* special case: the bind must be done on the multicast address port */ - my_addr.sin_port = s->dest_addr.sin_port; - } else { - my_addr.sin_port = htons(s->local_port); - } - if (s->reuse_socket) if (setsockopt (udp_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0) goto fail; /* the bind is needed to give a port to the socket now */ - if (bind(udp_fd,(struct sockaddr *)&my_addr, sizeof(my_addr)) < 0) + if (bind(udp_fd,(struct sockaddr *)&my_addr, len) < 0) goto fail; - len = sizeof(my_addr1); - getsockname(udp_fd, (struct sockaddr *)&my_addr1, &len); - s->local_port = ntohs(my_addr1.sin_port); + len = sizeof(my_addr); + getsockname(udp_fd, (struct sockaddr *)&my_addr, &len); + s->local_port = udp_port(&my_addr, len); -#ifdef IP_MULTICAST_TTL if (s->is_multicast) { if (h->flags & URL_WRONLY) { /* output */ - if (setsockopt(udp_fd, IPPROTO_IP, IP_MULTICAST_TTL, - &s->ttl, sizeof(s->ttl)) < 0) { - perror("IP_MULTICAST_TTL"); + if (udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0) goto fail; - } } else { /* input */ - memset(&s->mreq, 0, sizeof(s->mreq)); - s->mreq.imr_multiaddr = s->dest_addr.sin_addr; - s->mreq.imr_interface.s_addr = htonl (INADDR_ANY); - if (setsockopt(udp_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, - &s->mreq, sizeof(s->mreq)) < 0) { - perror("rtp: IP_ADD_MEMBERSHIP"); + if (udp_join_multicast_group(udp_fd, (struct sockaddr *)&s->dest_addr) < 0) goto fail; - } } } -#endif -#else - if (s->is_multicast && !(h->flags & URL_WRONLY)) - s->local_port = port; - udp_fd = udp_ipv6_set_local(h); - if (udp_fd < 0) - goto fail; - if (s->is_multicast) { - if (h->flags & URL_WRONLY) { - if (udp_ipv6_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0) - goto fail; - } else { - if (udp_ipv6_join_multicast_group(udp_fd, (struct sockaddr *)&s->dest_addr) < 0) - goto fail; - } - } -#endif if (is_output) { /* limit the tx buf size to limit latency */ tmp = UDP_TX_BUF_SIZE; if (setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) { - perror("setsockopt sndbuf"); + av_log(NULL, AV_LOG_ERROR, "setsockopt(SO_SNDBUF): %s\n", strerror(errno)); goto fail; } + } else { + /* set udp recv buffer size to the largest possible udp packet size to + * avoid losing data on OSes that set this too low by default. */ + tmp = UDP_MAX_PKT_SIZE; + setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp)); } s->udp_fd = udp_fd; @@ -409,27 +405,20 @@ static int udp_open(URLContext *h, const char *uri, int flags) if (udp_fd >= 0) closesocket(udp_fd); av_free(s); - return AVERROR_IO; + return AVERROR(EIO); } static int udp_read(URLContext *h, uint8_t *buf, int size) { UDPContext *s = h->priv_data; -#ifndef CONFIG_IPV6 - struct sockaddr_in from; -#else - struct sockaddr_storage from; -#endif - socklen_t from_len; int len; for(;;) { - from_len = sizeof(from); - len = recvfrom (s->udp_fd, buf, size, 0, - (struct sockaddr *)&from, &from_len); + len = recv(s->udp_fd, buf, size, 0); if (len < 0) { - if (errno != EAGAIN && errno != EINTR) - return AVERROR_IO; + if (ff_neterrno() != FF_NETERROR(EAGAIN) && + ff_neterrno() != FF_NETERROR(EINTR)) + return AVERROR(EIO); } else { break; } @@ -445,14 +434,11 @@ static int udp_write(URLContext *h, uint8_t *buf, int size) for(;;) { ret = sendto (s->udp_fd, buf, size, 0, (struct sockaddr *) &s->dest_addr, -#ifndef CONFIG_IPV6 - sizeof (s->dest_addr)); -#else s->dest_addr_len); -#endif if (ret < 0) { - if (errno != EINTR && errno != EAGAIN) - return AVERROR_IO; + if (ff_neterrno() != FF_NETERROR(EINTR) && + ff_neterrno() != FF_NETERROR(EAGAIN)) + return AVERROR(EIO); } else { break; } @@ -464,20 +450,10 @@ static int udp_close(URLContext *h) { UDPContext *s = h->priv_data; -#ifndef CONFIG_IPV6 -#ifdef IP_DROP_MEMBERSHIP - if (s->is_multicast && !(h->flags & URL_WRONLY)) { - if (setsockopt(s->udp_fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, - &s->mreq, sizeof(s->mreq)) < 0) { - perror("IP_DROP_MEMBERSHIP"); - } - } -#endif -#else if (s->is_multicast && !(h->flags & URL_WRONLY)) - udp_ipv6_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr); -#endif + udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr); closesocket(s->udp_fd); + ff_network_close(); av_free(s); return 0; } diff --git a/contrib/ffmpeg/libavformat/utils.c b/contrib/ffmpeg/libavformat/utils.c index 36cb269b5..caf8df4eb 100644 --- a/contrib/ffmpeg/libavformat/utils.c +++ b/contrib/ffmpeg/libavformat/utils.c @@ -1,5 +1,5 @@ /* - * Various utilities for ffmpeg system + * various utility functions for use within FFmpeg * Copyright (c) 2000, 2001, 2002 Fabrice Bellard * * This file is part of FFmpeg. @@ -19,25 +19,40 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avformat.h" -#include "allformats.h" #include "opt.h" +#include "avstring.h" +#include "riff.h" +#include +#include #undef NDEBUG #include /** * @file libavformat/utils.c - * Various utility functions for using ffmpeg library. + * various utility functions for use within FFmpeg */ static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den); static void av_frac_add(AVFrac *f, int64_t incr); -/** head of registered input format linked list. */ +/** head of registered input format linked list */ AVInputFormat *first_iformat = NULL; -/** head of registered output format linked list. */ +/** head of registered output format linked list */ AVOutputFormat *first_oformat = NULL; +AVInputFormat *av_iformat_next(AVInputFormat *f) +{ + if(f) return f->next; + else return first_iformat; +} + +AVOutputFormat *av_oformat_next(AVOutputFormat *f) +{ + if(f) return f->next; + else return first_oformat; +} + void av_register_input_format(AVInputFormat *format) { AVInputFormat **p; @@ -97,7 +112,7 @@ AVOutputFormat *guess_format(const char *short_name, const char *filename, return guess_format("image2", NULL, NULL); } #endif - /* find the proper file type */ + /* Find the proper file type. */ fmt_found = NULL; score_max = 0; fmt = first_oformat; @@ -176,14 +191,25 @@ void av_destruct_packet(AVPacket *pkt) pkt->data = NULL; pkt->size = 0; } +void av_init_packet(AVPacket *pkt) +{ + pkt->pts = AV_NOPTS_VALUE; + pkt->dts = AV_NOPTS_VALUE; + pkt->pos = -1; + pkt->duration = 0; + pkt->flags = 0; + pkt->stream_index = 0; + pkt->destruct= av_destruct_packet_nofree; +} + int av_new_packet(AVPacket *pkt, int size) { uint8_t *data; if((unsigned)size > (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); if (!data) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); memset(data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE); av_init_packet(pkt); @@ -215,13 +241,12 @@ int av_dup_packet(AVPacket *pkt) { if (pkt->destruct != av_destruct_packet) { uint8_t *data; - /* we duplicate the packet and don't forget to put the padding - again */ + /* We duplicate the packet and don't forget to add the padding again. */ if((unsigned)pkt->size > (unsigned)pkt->size + FF_INPUT_BUFFER_PADDING_SIZE) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); data = av_malloc(pkt->size + FF_INPUT_BUFFER_PADDING_SIZE); if (!data) { - return AVERROR_NOMEM; + return AVERROR(ENOMEM); } memcpy(data, pkt->data, pkt->size); memset(data + pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE); @@ -282,7 +307,7 @@ static const char* format_to_name(void* ptr) } #define OFFSET(x) offsetof(AVFormatContext,x) -#define DEFAULT 0 //should be NAN but it doesnt work as its not a constant in glibc as required by ANSI/ISO C +#define DEFAULT 0 //should be NAN but it does not work as it is not a constant in glibc as required by ANSI/ISO C //these names are too long to be readable #define E AV_OPT_FLAG_ENCODING_PARAM #define D AV_OPT_FLAG_DECODING_PARAM @@ -296,7 +321,9 @@ static const AVOption options[]={ {"genpts", "generate pts", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_GENPTS, INT_MIN, INT_MAX, D, "fflags"}, {"track", " set the track number", OFFSET(track), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E}, {"year", "set the year", OFFSET(year), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, E}, -{"analyzeduration", NULL, OFFSET(max_analyze_duration), FF_OPT_TYPE_INT, 3*AV_TIME_BASE, 0, INT_MAX, D}, +{"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), FF_OPT_TYPE_INT, 3*AV_TIME_BASE, 0, INT_MAX, D}, +{"cryptokey", "decryption key", OFFSET(key), FF_OPT_TYPE_BINARY, 0, 0, 0, D}, +{"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), FF_OPT_TYPE_INT, 1<<20, 0, INT_MAX, D}, {NULL}, }; @@ -343,21 +370,20 @@ int av_open_input_stream(AVFormatContext **ic_ptr, else ic = *ic_ptr; if (!ic) { - err = AVERROR_NOMEM; + err = AVERROR(ENOMEM); goto fail; } ic->iformat = fmt; - if (pb) - ic->pb = *pb; + ic->pb = pb; ic->duration = AV_NOPTS_VALUE; ic->start_time = AV_NOPTS_VALUE; - pstrcpy(ic->filename, sizeof(ic->filename), filename); + av_strlcpy(ic->filename, filename, sizeof(ic->filename)); /* allocate private data */ if (fmt->priv_data_size > 0) { ic->priv_data = av_mallocz(fmt->priv_data_size); if (!ic->priv_data) { - err = AVERROR_NOMEM; + err = AVERROR(ENOMEM); goto fail; } } else { @@ -369,7 +395,7 @@ int av_open_input_stream(AVFormatContext **ic_ptr, goto fail; if (pb && !ic->data_offset) - ic->data_offset = url_ftell(&ic->pb); + ic->data_offset = url_ftell(ic->pb); *ic_ptr = ic; return 0; @@ -382,7 +408,7 @@ int av_open_input_stream(AVFormatContext **ic_ptr, return err; } -/** Size of probe buffer, for guessing file type from file contents. */ +/** size of probe buffer, for guessing file type from file contents */ #define PROBE_BUF_MIN 2048 #define PROBE_BUF_MAX (1<<20) @@ -391,11 +417,10 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, int buf_size, AVFormatParameters *ap) { - int err, must_open_file, file_opened, probe_size; + int err, probe_size; AVProbeData probe_data, *pd = &probe_data; - ByteIOContext pb1, *pb = &pb1; + ByteIOContext *pb = NULL; - file_opened = 0; pd->filename = ""; if (filename) pd->filename = filename; @@ -403,25 +428,17 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, pd->buf_size = 0; if (!fmt) { - /* guess format if no file can be opened */ + /* guess format if no file can be opened */ fmt = av_probe_input_format(pd, 0); } - /* do not open file if the format does not need it. XXX: specific + /* Do not open file if the format does not need it. XXX: specific hack needed to handle RTSP/TCP */ - must_open_file = 1; - if (fmt && (fmt->flags & AVFMT_NOFILE)) { - must_open_file = 0; - pb= NULL; //FIXME this or memset(pb, 0, sizeof(ByteIOContext)); otherwise its uninitalized - } - - if (!fmt || must_open_file) { + if (!fmt || !(fmt->flags & AVFMT_NOFILE)) { /* if no file needed do not try to open one */ - if (url_fopen(pb, filename, URL_RDONLY) < 0) { - err = AVERROR_IO; + if ((err=url_fopen(&pb, filename, URL_RDONLY)) < 0) { goto fail; } - file_opened = 1; if (buf_size > 0) { url_setbufsize(pb, buf_size); } @@ -429,13 +446,14 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, for(probe_size= PROBE_BUF_MIN; probe_size<=PROBE_BUF_MAX && !fmt; probe_size<<=1){ int score= probe_size < PROBE_BUF_MAX ? AVPROBE_SCORE_MAX/4 : 0; /* read probe data */ - pd->buf= av_realloc(pd->buf, probe_size); + pd->buf= av_realloc(pd->buf, probe_size + AVPROBE_PADDING_SIZE); pd->buf_size = get_buffer(pb, pd->buf, probe_size); + memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE); if (url_fseek(pb, 0, SEEK_SET) < 0) { url_fclose(pb); - if (url_fopen(pb, filename, URL_RDONLY) < 0) { - file_opened = 0; - err = AVERROR_IO; + if (url_fopen(&pb, filename, URL_RDONLY) < 0) { + pb = NULL; + err = AVERROR(EIO); goto fail; } } @@ -451,16 +469,7 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, goto fail; } - /* XXX: suppress this hack for redirectors */ -#ifdef CONFIG_NETWORK - if (fmt == &redir_demuxer) { - err = redir_open(ic_ptr, pb); - url_fclose(pb); - return err; - } -#endif - - /* check filename in case of an image number is expected */ + /* check filename in case an image number is expected */ if (fmt->flags & AVFMT_NEEDNUMBER) { if (!av_filename_number_test(filename)) { err = AVERROR_NUMEXPECTED; @@ -473,7 +482,7 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, return 0; fail: av_freep(&pd->buf); - if (file_opened) + if (pb) url_fclose(pb); *ic_ptr = NULL; return err; @@ -484,13 +493,33 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, int av_read_packet(AVFormatContext *s, AVPacket *pkt) { - return s->iformat->read_packet(s, pkt); + int ret; + AVStream *st; + av_init_packet(pkt); + ret= s->iformat->read_packet(s, pkt); + if (ret < 0) + return ret; + st= s->streams[pkt->stream_index]; + + switch(st->codec->codec_type){ + case CODEC_TYPE_VIDEO: + if(s->video_codec_id) st->codec->codec_id= s->video_codec_id; + break; + case CODEC_TYPE_AUDIO: + if(s->audio_codec_id) st->codec->codec_id= s->audio_codec_id; + break; + case CODEC_TYPE_SUBTITLE: + if(s->subtitle_codec_id)st->codec->codec_id= s->subtitle_codec_id; + break; + } + + return ret; } /**********************************************************/ /** - * Get the number of samples of an audio frame. Return (-1) if error. + * Get the number of samples of an audio frame. Return -1 on error. */ static int get_audio_frame_size(AVCodecContext *enc, int size) { @@ -517,7 +546,7 @@ static int get_audio_frame_size(AVCodecContext *enc, int size) /** - * Return the frame duration in seconds, return 0 if not available. + * Return the frame duration in seconds. Return 0 if not available. */ static void compute_frame_duration(int *pnum, int *pden, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt) @@ -574,35 +603,87 @@ static int is_intra_only(AVCodecContext *enc){ return 0; } -static int64_t lsb2full(int64_t lsb, int64_t last_ts, int lsb_bits){ - int64_t mask = lsb_bits < 64 ? (1LL<streams[stream_index]; + AVPacketList *pktl= s->packet_buffer; + + if(st->first_dts != AV_NOPTS_VALUE || dts == AV_NOPTS_VALUE) + return; + + st->first_dts= dts - st->cur_dts; + st->cur_dts= dts; + + for(; pktl; pktl= pktl->next){ + if(pktl->pkt.stream_index != stream_index) + continue; + //FIXME think more about this check + if(pktl->pkt.pts != AV_NOPTS_VALUE && pktl->pkt.pts == pktl->pkt.dts) + pktl->pkt.pts += st->first_dts; + + if(pktl->pkt.dts != AV_NOPTS_VALUE) + pktl->pkt.dts += st->first_dts; + + if(st->start_time == AV_NOPTS_VALUE && pktl->pkt.pts != AV_NOPTS_VALUE) + st->start_time= pktl->pkt.pts; + } + if (st->start_time == AV_NOPTS_VALUE) + st->start_time = pts; +} + +static void update_initial_durations(AVFormatContext *s, AVStream *st, AVPacket *pkt) +{ + AVPacketList *pktl= s->packet_buffer; + + assert(pkt->duration && !st->cur_dts); + + for(; pktl; pktl= pktl->next){ + if(pktl->pkt.stream_index != pkt->stream_index) + continue; + if(pktl->pkt.pts == pktl->pkt.dts && pktl->pkt.dts == AV_NOPTS_VALUE + && !pktl->pkt.duration){ + pktl->pkt.pts= pktl->pkt.dts= st->cur_dts; + st->cur_dts += pkt->duration; + pktl->pkt.duration= pkt->duration; + }else + break; + } } static void compute_pkt_fields(AVFormatContext *s, AVStream *st, AVCodecParserContext *pc, AVPacket *pkt) { int num, den, presentation_delayed, delay, i; - /* handle wrapping */ - if(st->cur_dts != AV_NOPTS_VALUE){ - if(pkt->pts != AV_NOPTS_VALUE) - pkt->pts= lsb2full(pkt->pts, st->cur_dts, st->pts_wrap_bits); - if(pkt->dts != AV_NOPTS_VALUE) - pkt->dts= lsb2full(pkt->dts, st->cur_dts, st->pts_wrap_bits); + int64_t offset; + + if(pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && pkt->dts > pkt->pts && st->pts_wrap_bits<63 + /*&& pkt->dts-(1LL<pts_wrap_bits) < pkt->pts*/){ + pkt->dts -= 1LL<pts_wrap_bits; } if (pkt->duration == 0) { compute_frame_duration(&num, &den, st, pc, pkt); if (den && num) { pkt->duration = av_rescale(1, num * (int64_t)st->time_base.den, den * (int64_t)st->time_base.num); + + if(st->cur_dts == 0) + update_initial_durations(s, st, pkt); } } - if(is_intra_only(st->codec)) - pkt->flags |= PKT_FLAG_KEY; + /* correct timestamps with byte offset if demuxers only have timestamps + on packet boundaries */ + if(pc && st->need_parsing == AVSTREAM_PARSE_TIMESTAMPS && pkt->size){ + /* this will estimate bitrate based on this frame's duration and size */ + offset = av_rescale(pc->offset, pkt->duration, pkt->size); + if(pkt->pts != AV_NOPTS_VALUE) + pkt->pts += offset; + if(pkt->dts != AV_NOPTS_VALUE) + pkt->dts += offset; + } - /* do we have a video B frame ? */ + /* do we have a video B-frame ? */ delay= st->codec->has_b_frames; presentation_delayed = 0; /* XXX: need has_b_frame, but cannot get it if the codec is @@ -610,34 +691,35 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, if (delay && pc && pc->pict_type != FF_B_TYPE) presentation_delayed = 1; - /* this may be redundant, but it shouldnt hurt */ + /* This may be redundant, but it should not hurt. */ if(pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts > pkt->dts) presentation_delayed = 1; if(st->cur_dts == AV_NOPTS_VALUE){ - st->cur_dts = -delay * pkt->duration; + st->cur_dts = 0; //FIXME maybe set it to 0 during init } // av_log(NULL, AV_LOG_DEBUG, "IN delayed:%d pts:%"PRId64", dts:%"PRId64" cur_dts:%"PRId64" st:%d pc:%p\n", presentation_delayed, pkt->pts, pkt->dts, st->cur_dts, pkt->stream_index, pc); /* interpolate PTS and DTS if they are not present */ if(delay <=1){ if (presentation_delayed) { - /* DTS = decompression time stamp */ - /* PTS = presentation time stamp */ + /* DTS = decompression timestamp */ + /* PTS = presentation timestamp */ if (pkt->dts == AV_NOPTS_VALUE) pkt->dts = st->last_IP_pts; + update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts); if (pkt->dts == AV_NOPTS_VALUE) pkt->dts = st->cur_dts; /* this is tricky: the dts must be incremented by the duration - of the frame we are displaying, i.e. the last I or P frame */ + of the frame we are displaying, i.e. the last I- or P-frame */ if (st->last_IP_duration == 0) st->last_IP_duration = pkt->duration; st->cur_dts = pkt->dts + st->last_IP_duration; st->last_IP_duration = pkt->duration; st->last_IP_pts= pkt->pts; /* cannot compute PTS if not present (we can compute it only - by knowing the futur */ + by knowing the future */ } else if(pkt->pts != AV_NOPTS_VALUE || pkt->dts != AV_NOPTS_VALUE || pkt->duration){ if(pkt->pts != AV_NOPTS_VALUE && pkt->duration){ int64_t old_diff= FFABS(st->cur_dts - pkt->duration - pkt->pts); @@ -651,6 +733,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, /* presentation is not delayed : PTS and DTS are the same */ if(pkt->pts == AV_NOPTS_VALUE) pkt->pts = pkt->dts; + update_initial_timestamps(s, pkt->stream_index, pkt->pts, pkt->pts); if(pkt->pts == AV_NOPTS_VALUE) pkt->pts = st->cur_dts; pkt->dts = pkt->pts; @@ -666,6 +749,9 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i+1]); if(pkt->dts == AV_NOPTS_VALUE) pkt->dts= st->pts_buffer[0]; + if(delay>1){ + update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts); // this should happen on the first packet + } if(pkt->dts > st->cur_dts) st->cur_dts = pkt->dts; } @@ -673,9 +759,11 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, // av_log(NULL, AV_LOG_ERROR, "OUTdelayed:%d/%d pts:%"PRId64", dts:%"PRId64" cur_dts:%"PRId64"\n", presentation_delayed, delay, pkt->pts, pkt->dts, st->cur_dts); /* update flags */ - if (pc) { + if(is_intra_only(st->codec)) + pkt->flags |= PKT_FLAG_KEY; + else if (pc) { pkt->flags = 0; - /* key frame computation */ + /* keyframe computation */ if (pc->pict_type == FF_I_TYPE) pkt->flags |= PKT_FLAG_KEY; } @@ -691,6 +779,8 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) AVStream *st; int len, ret, i; + av_init_packet(pkt); + for(;;) { /* select current input stream component */ st = s->cur_st; @@ -715,6 +805,7 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) /* return packet if any */ if (pkt->size) { got_packet: + pkt->pos = s->cur_pkt.pos; // Isn't quite accurate but close. pkt->duration = 0; pkt->stream_index = st->index; pkt->pts = st->parser->pts; @@ -723,6 +814,7 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) compute_pkt_fields(s, st, st->parser, pkt); if((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & PKT_FLAG_KEY){ + ff_reduce_index(s, st->index); av_add_index_entry(st, st->parser->frame_offset, pkt->dts, 0, 0, AVINDEX_KEYFRAME); } @@ -752,7 +844,7 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) goto got_packet; } } - /* no more packets: really terminates parsing */ + /* no more packets: really terminate parsing */ return ret; } @@ -770,9 +862,9 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) if (st->need_parsing && !st->parser) { st->parser = av_parser_init(st->codec->codec_id); if (!st->parser) { - /* no parser available : just output the raw packets */ - st->need_parsing = 0; - }else if(st->need_parsing == 2){ + /* no parser available: just output the raw packets */ + st->need_parsing = AVSTREAM_PARSE_NONE; + }else if(st->need_parsing == AVSTREAM_PARSE_HEADERS){ st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; } if(st->parser && (s->iformat->flags & AVFMT_GENERIC_INDEX)){ @@ -792,6 +884,22 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) return 0; } +static AVPacket *add_to_pktbuf(AVFormatContext *s, AVPacket *pkt){ + AVPacketList *pktl= s->packet_buffer; + AVPacketList **plast_pktl= &s->packet_buffer; + + while(*plast_pktl) plast_pktl= &(*plast_pktl)->next; //FIXME maybe maintain pointer to the last? + + pktl = av_mallocz(sizeof(AVPacketList)); + if (!pktl) + return NULL; + + /* add the packet in the buffered packet list */ + *plast_pktl = pktl; + pktl->pkt= *pkt; + return &pktl->pkt; +} + int av_read_frame(AVFormatContext *s, AVPacket *pkt) { AVPacketList *pktl; @@ -827,7 +935,6 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) } } if(genpts){ - AVPacketList **plast_pktl= &s->packet_buffer; int ret= av_read_frame_internal(s, pkt); if(ret<0){ if(pktl && ret != AVERROR(EAGAIN)){ @@ -837,19 +944,8 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) return ret; } - /* duplicate the packet */ - if (av_dup_packet(pkt) < 0) - return AVERROR_NOMEM; - - while(*plast_pktl) plast_pktl= &(*plast_pktl)->next; //FIXME maybe maintain pointer to the last? - - pktl = av_mallocz(sizeof(AVPacketList)); - if (!pktl) - return AVERROR_NOMEM; - - /* add the packet in the buffered packet list */ - *plast_pktl = pktl; - pktl->pkt= *pkt; + if(av_dup_packet(add_to_pktbuf(s, pkt)) < 0) + return AVERROR(ENOMEM); }else{ assert(!s->packet_buffer); return av_read_frame_internal(s, pkt); @@ -936,6 +1032,19 @@ void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp){ } } +void ff_reduce_index(AVFormatContext *s, int stream_index) +{ + AVStream *st= s->streams[stream_index]; + unsigned int max_entries= s->max_index_size / sizeof(AVIndexEntry); + + if((unsigned)st->nb_index_entries >= max_entries){ + int i; + for(i=0; 2*inb_index_entries; i++) + st->index_entries[i]= st->index_entries[2*i]; + st->nb_index_entries= i; + } +} + int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags) { @@ -967,7 +1076,7 @@ int av_add_index_entry(AVStream *st, return -1; memmove(entries + index + 1, entries + index, sizeof(AVIndexEntry)*(st->nb_index_entries - index)); st->nb_index_entries++; - }else if(ie->pos == pos && distance < ie->min_distance) //dont reduce the distance + }else if(ie->pos == pos && distance < ie->min_distance) //do not reduce the distance distance= ie->min_distance; } @@ -980,49 +1089,6 @@ int av_add_index_entry(AVStream *st, return index; } -/** - * build an index for raw streams using a parser. - */ -static void av_build_index_raw(AVFormatContext *s) -{ - AVPacket pkt1, *pkt = &pkt1; - int ret; - AVStream *st; - - st = s->streams[0]; - av_read_frame_flush(s); - url_fseek(&s->pb, s->data_offset, SEEK_SET); - - for(;;) { - ret = av_read_frame(s, pkt); - if (ret < 0) - break; - if (pkt->stream_index == 0 && st->parser && - (pkt->flags & PKT_FLAG_KEY)) { - av_add_index_entry(st, st->parser->frame_offset, pkt->dts, - 0, 0, AVINDEX_KEYFRAME); - } - av_free_packet(pkt); - } -} - -/** - * Returns TRUE if we deal with a raw stream. - * - * Raw codec data and parsing needed. - */ -static int is_raw_stream(AVFormatContext *s) -{ - AVStream *st; - - if (s->nb_streams != 1) - return 0; - st = s->streams[0]; - if (!st->need_parsing) - return 0; - return 1; -} - int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, int flags) { @@ -1073,13 +1139,13 @@ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts ts_max= ts_min= AV_NOPTS_VALUE; - pos_limit= -1; //gcc falsely says it may be uninitalized + pos_limit= -1; //gcc falsely says it may be uninitialized st= s->streams[stream_index]; if(st->index_entries){ AVIndexEntry *e; - index= av_index_search_timestamp(st, target_ts, flags | AVSEEK_FLAG_BACKWARD); //FIXME whole func must be checked for non keyframe entries in index case, especially read_timestamp() + index= av_index_search_timestamp(st, target_ts, flags | AVSEEK_FLAG_BACKWARD); //FIXME whole func must be checked for non-keyframe entries in index case, especially read_timestamp() index= FFMAX(index, 0); e= &st->index_entries[index]; @@ -1114,7 +1180,7 @@ int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts return -1; /* do the seek */ - url_fseek(&s->pb, pos, SEEK_SET); + url_fseek(s->pb, pos, SEEK_SET); av_update_cur_dts(s, st, ts); @@ -1139,7 +1205,7 @@ int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, i if(ts_max == AV_NOPTS_VALUE){ int step= 1024; - filesize = url_fsize(&s->pb); + filesize = url_fsize(s->pb); pos_max = filesize - 1; do{ pos_max -= step; @@ -1186,7 +1252,8 @@ int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, i // bisection, if interpolation failed to change min or max pos last time pos = (pos_min + pos_limit)>>1; }else{ - // linear search if bisection failed, can only happen if there are very few or no keframes between min/max + /* linear search if bisection failed, can only happen if there + are very few or no keyframes between min/max */ pos=pos_min; } if(pos <= pos_min) @@ -1203,6 +1270,10 @@ int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, i #ifdef DEBUG_SEEK av_log(s, AV_LOG_DEBUG, "%"PRId64" %"PRId64" %"PRId64" / %"PRId64" %"PRId64" %"PRId64" target:%"PRId64" limit:%"PRId64" start:%"PRId64" noc:%d\n", pos_min, pos, pos_max, ts_min, ts, ts_max, target_ts, pos_limit, start_pos, no_change); #endif + if(ts == AV_NOPTS_VALUE){ + av_log(s, AV_LOG_ERROR, "read_timestamp() failed in the middle\n"); + return -1; + } assert(ts != AV_NOPTS_VALUE); if (target_ts <= ts) { pos_limit = start_pos - 1; @@ -1241,12 +1312,12 @@ static int av_seek_frame_byte(AVFormatContext *s, int stream_index, int64_t pos, #endif pos_min = s->data_offset; - pos_max = url_fsize(&s->pb) - 1; + pos_max = url_fsize(s->pb) - 1; if (pos < pos_min) pos= pos_min; else if(pos > pos_max) pos= pos_max; - url_fseek(&s->pb, pos, SEEK_SET); + url_fseek(s->pb, pos, SEEK_SET); #if 0 av_update_cur_dts(s, st, ts); @@ -1265,16 +1336,16 @@ static int av_seek_frame_generic(AVFormatContext *s, index = av_index_search_timestamp(st, timestamp, flags); - if(index < 0){ + if(index < 0 || index==st->nb_index_entries-1){ int i; AVPacket pkt; if(st->index_entries && st->nb_index_entries){ ie= &st->index_entries[st->nb_index_entries-1]; - url_fseek(&s->pb, ie->pos, SEEK_SET); + url_fseek(s->pb, ie->pos, SEEK_SET); av_update_cur_dts(s, st, ie->timestamp); }else - url_fseek(&s->pb, 0, SEEK_SET); + url_fseek(s->pb, 0, SEEK_SET); for(i=0;; i++) { int ret = av_read_frame(s, &pkt); @@ -1297,7 +1368,7 @@ static int av_seek_frame_generic(AVFormatContext *s, return 0; } ie = &st->index_entries[index]; - url_fseek(&s->pb, ie->pos, SEEK_SET); + url_fseek(s->pb, ie->pos, SEEK_SET); av_update_cur_dts(s, st, ie->timestamp); @@ -1343,19 +1414,18 @@ int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int f /*******************************************************/ /** - * Returns TRUE if the stream has accurate timings in any stream. + * Returns TRUE if the stream has accurate duration in any stream. * - * @return TRUE if the stream has accurate timings for at least one component. + * @return TRUE if the stream has accurate duration for at least one component. */ -static int av_has_timings(AVFormatContext *ic) +static int av_has_duration(AVFormatContext *ic) { int i; AVStream *st; for(i = 0;i < ic->nb_streams; i++) { st = ic->streams[i]; - if (st->start_time != AV_NOPTS_VALUE && - st->duration != AV_NOPTS_VALUE) + if (st->duration != AV_NOPTS_VALUE) return 1; } return 0; @@ -1369,14 +1439,16 @@ static int av_has_timings(AVFormatContext *ic) static void av_update_stream_timings(AVFormatContext *ic) { int64_t start_time, start_time1, end_time, end_time1; + int64_t duration, duration1; int i; AVStream *st; start_time = INT64_MAX; end_time = INT64_MIN; + duration = INT64_MIN; for(i = 0;i < ic->nb_streams; i++) { st = ic->streams[i]; - if (st->start_time != AV_NOPTS_VALUE) { + if (st->start_time != AV_NOPTS_VALUE && st->time_base.den) { start_time1= av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q); if (start_time1 < start_time) start_time = start_time1; @@ -1387,19 +1459,27 @@ static void av_update_stream_timings(AVFormatContext *ic) end_time = end_time1; } } + if (st->duration != AV_NOPTS_VALUE) { + duration1 = av_rescale_q(st->duration, st->time_base, AV_TIME_BASE_Q); + if (duration1 > duration) + duration = duration1; + } } if (start_time != INT64_MAX) { ic->start_time = start_time; if (end_time != INT64_MIN) { - ic->duration = end_time - start_time; - if (ic->file_size > 0) { - /* compute the bit rate */ - ic->bit_rate = (double)ic->file_size * 8.0 * AV_TIME_BASE / - (double)ic->duration; - } + if (end_time - start_time > duration) + duration = end_time - start_time; + } + } + if (duration != INT64_MIN) { + ic->duration = duration; + if (ic->file_size > 0) { + /* compute the bitrate */ + ic->bit_rate = (double)ic->file_size * 8.0 * AV_TIME_BASE / + (double)ic->duration; } } - } static void fill_all_stream_timings(AVFormatContext *ic) @@ -1444,11 +1524,8 @@ static void av_estimate_timings_from_bit_rate(AVFormatContext *ic) for(i = 0; i < ic->nb_streams; i++) { st = ic->streams[i]; duration= av_rescale(8*filesize, st->time_base.den, ic->bit_rate*(int64_t)st->time_base.num); - if (st->start_time == AV_NOPTS_VALUE || - st->duration == AV_NOPTS_VALUE) { - st->start_time = 0; + if (st->duration == AV_NOPTS_VALUE) st->duration = duration; - } } } } @@ -1465,11 +1542,25 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, offset_t old_offse int64_t end_time; int64_t filesize, offset, duration; - av_read_frame_flush(ic); + /* free previous packet */ + if (ic->cur_st && ic->cur_st->parser) + av_free_packet(&ic->cur_pkt); + ic->cur_st = NULL; + + /* flush packet queue */ + flush_packet_queue(ic); + + for(i=0;inb_streams;i++) { + st = ic->streams[i]; + if (st->parser) { + av_parser_close(st->parser); + st->parser= NULL; + } + } /* we read the first packets to get the first PTS (not fully accurate, but it is enough now) */ - url_fseek(&ic->pb, 0, SEEK_SET); + url_fseek(ic->pb, 0, SEEK_SET); read_size = 0; for(;;) { if (read_size >= DURATION_MAX_READ_SIZE) @@ -1502,26 +1593,19 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, offset_t old_offse if (offset < 0) offset = 0; - url_fseek(&ic->pb, offset, SEEK_SET); + url_fseek(ic->pb, offset, SEEK_SET); read_size = 0; for(;;) { if (read_size >= DURATION_MAX_READ_SIZE) break; - /* if all info is available, we can stop */ - for(i = 0;i < ic->nb_streams; i++) { - st = ic->streams[i]; - if (st->duration == AV_NOPTS_VALUE) - break; - } - if (i == ic->nb_streams) - break; ret = av_read_packet(ic, pkt); if (ret != 0) break; read_size += pkt->size; st = ic->streams[pkt->stream_index]; - if (pkt->pts != AV_NOPTS_VALUE) { + if (pkt->pts != AV_NOPTS_VALUE && + st->start_time != AV_NOPTS_VALUE) { end_time = pkt->pts; duration = end_time - st->start_time; if (duration > 0) { @@ -1535,7 +1619,12 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, offset_t old_offse fill_all_stream_timings(ic); - url_fseek(&ic->pb, old_offset, SEEK_SET); + url_fseek(ic->pb, old_offset, SEEK_SET); + for(i=0; inb_streams; i++){ + st= ic->streams[i]; + st->cur_dts= st->first_dts; + st->last_IP_pts = AV_NOPTS_VALUE; + } } static void av_estimate_timings(AVFormatContext *ic, offset_t old_offset) @@ -1546,7 +1635,7 @@ static void av_estimate_timings(AVFormatContext *ic, offset_t old_offset) if (ic->iformat->flags & AVFMT_NOFILE) { file_size = 0; } else { - file_size = url_fsize(&ic->pb); + file_size = url_fsize(ic->pb); if (file_size < 0) file_size = 0; } @@ -1554,15 +1643,15 @@ static void av_estimate_timings(AVFormatContext *ic, offset_t old_offset) if ((!strcmp(ic->iformat->name, "mpeg") || !strcmp(ic->iformat->name, "mpegts")) && - file_size && !ic->pb.is_streamed) { + file_size && !url_is_streamed(ic->pb)) { /* get accurate estimate from the PTSes */ av_estimate_timings_from_pts(ic, old_offset); - } else if (av_has_timings(ic)) { - /* at least one components has timings - we use them for all + } else if (av_has_duration(ic)) { + /* at least one component has timings - we use them for all the components */ fill_all_stream_timings(ic); } else { - /* less precise: use bit rate info */ + /* less precise: use bitrate info */ av_estimate_timings_from_bit_rate(ic); } av_update_stream_timings(ic); @@ -1599,7 +1688,7 @@ static int has_codec_parameters(AVCodecContext *enc) val = 1; break; } - return (val != 0); + return (enc->codec_id != CODEC_ID_NONE && val != 0); } static int try_decode_frame(AVStream *st, const uint8_t *data, int size) @@ -1622,7 +1711,7 @@ static int try_decode_frame(AVStream *st, const uint8_t *data, int size) switch(st->codec->codec_type) { case CODEC_TYPE_VIDEO: ret = avcodec_decode_video(st->codec, &picture, - &got_picture, (uint8_t *)data, size); + &got_picture, data, size); break; case CODEC_TYPE_AUDIO: data_size = FFMAX(size, AVCODEC_MAX_AUDIO_FRAME_SIZE); @@ -1630,7 +1719,7 @@ static int try_decode_frame(AVStream *st, const uint8_t *data, int size) if (!samples) goto fail; ret = avcodec_decode_audio2(st->codec, samples, - &data_size, (uint8_t *)data, size); + &data_size, data, size); av_free(samples); break; default: @@ -1641,6 +1730,67 @@ static int try_decode_frame(AVStream *st, const uint8_t *data, int size) return ret; } +static int set_codec_from_probe_data(AVStream *st, AVProbeData *pd, int score) +{ + AVInputFormat *fmt; + fmt = av_probe_input_format2(pd, 1, &score); + + if (fmt) { + if (strncmp(fmt->name, "mp3", 3) == 0) + st->codec->codec_id = CODEC_ID_MP3; + else if (strncmp(fmt->name, "ac3", 3) == 0) + st->codec->codec_id = CODEC_ID_AC3; + } + return !!fmt; +} + +unsigned int codec_get_tag(const AVCodecTag *tags, int id) +{ + while (tags->id != CODEC_ID_NONE) { + if (tags->id == id) + return tags->tag; + tags++; + } + return 0; +} + +enum CodecID codec_get_id(const AVCodecTag *tags, unsigned int tag) +{ + int i; + for(i=0; tags[i].id != CODEC_ID_NONE;i++) { + if(tag == tags[i].tag) + return tags[i].id; + } + for(i=0; tags[i].id != CODEC_ID_NONE; i++) { + if( toupper((tag >> 0)&0xFF) == toupper((tags[i].tag >> 0)&0xFF) + && toupper((tag >> 8)&0xFF) == toupper((tags[i].tag >> 8)&0xFF) + && toupper((tag >>16)&0xFF) == toupper((tags[i].tag >>16)&0xFF) + && toupper((tag >>24)&0xFF) == toupper((tags[i].tag >>24)&0xFF)) + return tags[i].id; + } + return CODEC_ID_NONE; +} + +unsigned int av_codec_get_tag(const AVCodecTag *tags[4], enum CodecID id) +{ + int i; + for(i=0; tags && tags[i]; i++){ + int tag= codec_get_tag(tags[i], id); + if(tag) return tag; + } + return 0; +} + +enum CodecID av_codec_get_id(const AVCodecTag *tags[4], unsigned int tag) +{ + int i; + for(i=0; tags && tags[i]; i++){ + enum CodecID id= codec_get_id(tags[i], tag); + if(id!=CODEC_ID_NONE) return id; + } + return CODEC_ID_NONE; +} + /* absolute maximum size we read until we abort */ #define MAX_READ_SIZE 5000000 @@ -1650,21 +1800,40 @@ static int get_std_framerate(int i){ else return ((int[]){24,30,60,12,15})[i-60*12]*1000*12; } +/* + * Is the time base unreliable. + * This is a heuristic to balance between quick acceptance of the values in + * the headers vs. some extra checks. + * Old DivX and Xvid often have nonsense timebases like 1fps or 2fps. + * MPEG-2 commonly misuses field repeat flags to store different framerates. + * And there are "variable" fps files this needs to detect as well. + */ +static int tb_unreliable(AVCodecContext *c){ + if( c->time_base.den >= 101L*c->time_base.num + || c->time_base.den < 5L*c->time_base.num +/* || c->codec_tag == ff_get_fourcc("DIVX") + || c->codec_tag == ff_get_fourcc("XVID")*/ + || c->codec_id == CODEC_ID_MPEG2VIDEO) + return 1; + return 0; +} + int av_find_stream_info(AVFormatContext *ic) { int i, count, ret, read_size, j; AVStream *st; AVPacket pkt1, *pkt; - AVPacketList *pktl=NULL, **ppktl; int64_t last_dts[MAX_STREAMS]; int duration_count[MAX_STREAMS]={0}; double (*duration_error)[MAX_STD_TIMEBASES]; - offset_t old_offset = url_ftell(&ic->pb); + offset_t old_offset = url_ftell(ic->pb); int64_t codec_info_duration[MAX_STREAMS]={0}; int codec_info_nb_frames[MAX_STREAMS]={0}; + AVProbeData probe_data[MAX_STREAMS]; + int codec_identified[MAX_STREAMS]={0}; duration_error = av_mallocz(MAX_STREAMS * sizeof(*duration_error)); - if (!duration_error) return AVERROR_NOMEM; + if (!duration_error) return AVERROR(ENOMEM); for(i=0;inb_streams;i++) { st = ic->streams[i]; @@ -1677,7 +1846,7 @@ int av_find_stream_info(AVFormatContext *ic) //only for the split stuff if (!st->parser) { st->parser = av_parser_init(st->codec->codec_id); - if(st->need_parsing == 2 && st->parser){ + if(st->need_parsing == AVSTREAM_PARSE_HEADERS && st->parser){ st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; } } @@ -1687,9 +1856,9 @@ int av_find_stream_info(AVFormatContext *ic) last_dts[i]= AV_NOPTS_VALUE; } + memset(probe_data, 0, sizeof(probe_data)); count = 0; read_size = 0; - ppktl = &ic->packet_buffer; for(;;) { /* check if one codec still needs to be handled */ for(i=0;inb_streams;i++) { @@ -1697,11 +1866,13 @@ int av_find_stream_info(AVFormatContext *ic) if (!has_codec_parameters(st->codec)) break; /* variable fps and no guess at the real fps */ - if( (st->codec->time_base.den >= 101LL*st->codec->time_base.num || st->codec->codec_id == CODEC_ID_MPEG2VIDEO) + if( tb_unreliable(st->codec) && duration_count[i]<20 && st->codec->codec_type == CODEC_TYPE_VIDEO) break; if(st->parser && st->parser->parser->split && !st->codec->extradata) break; + if(st->first_dts == AV_NOPTS_VALUE) + break; } if (i == ic->nb_streams) { /* NOTE: if the format has no header, then we need to read @@ -1738,24 +1909,9 @@ int av_find_stream_info(AVFormatContext *ic) break; } - pktl = av_mallocz(sizeof(AVPacketList)); - if (!pktl) { - ret = AVERROR_NOMEM; - break; - } - - /* add the packet in the buffered packet list */ - *ppktl = pktl; - ppktl = &pktl->next; - - pkt = &pktl->pkt; - *pkt = pkt1; - - /* duplicate the packet */ - if (av_dup_packet(pkt) < 0) { - ret = AVERROR_NOMEM; - break; - } + pkt= add_to_pktbuf(ic, &pkt1); + if(av_dup_packet(pkt) < 0) + return AVERROR(ENOMEM); read_size += pkt->size; @@ -1787,6 +1943,14 @@ int av_find_stream_info(AVFormatContext *ic) } if(last == AV_NOPTS_VALUE || duration_count[index]<=1) last_dts[pkt->stream_index]= pkt->dts; + + if (st->codec->codec_id == CODEC_ID_NONE) { + AVProbeData *pd = &(probe_data[st->index]); + pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE); + memcpy(pd->buf+pd->buf_size, pkt->data, pkt->size); + pd->buf_size += pkt->size; + memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE); + } } if(st->parser && st->parser->parser->split && !st->codec->extradata){ int i= st->parser->parser->split(st->codec, pkt->data, pkt->size); @@ -1800,8 +1964,8 @@ int av_find_stream_info(AVFormatContext *ic) /* if still no information, we try to open the codec and to decompress the frame. We try to avoid that in most cases as - it takes longer and uses more memory. For MPEG4, we need to - decompress for Quicktime. */ + it takes longer and uses more memory. For MPEG-4, we need to + decompress for QuickTime. */ if (!has_codec_parameters(st->codec) /*&& (st->codec->codec_id == CODEC_ID_FLV1 || st->codec->codec_id == CODEC_ID_H264 || @@ -1819,7 +1983,7 @@ int av_find_stream_info(AVFormatContext *ic) (st->codec->codec_id == CODEC_ID_MPEG4 && !st->need_parsing))*/) try_decode_frame(st, pkt->data, pkt->size); - if (av_rescale_q(codec_info_duration[st->index], st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration) { + if (st->time_base.den > 0 && av_rescale_q(codec_info_duration[st->index], st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration) { break; } count++; @@ -1838,8 +2002,8 @@ int av_find_stream_info(AVFormatContext *ic) st->codec->codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt); if(duration_count[i] - && (st->codec->time_base.num*101LL <= st->codec->time_base.den || st->codec->codec_id == CODEC_ID_MPEG2VIDEO) /*&& - //FIXME we should not special case mpeg2, but this needs testing with non mpeg2 ... + && tb_unreliable(st->codec) /*&& + //FIXME we should not special-case MPEG-2, but this needs testing with non-MPEG-2 ... st->time_base.num*duration_sum[i]/duration_count[i]*101LL > st->time_base.den*/){ double best_error= 2*av_q2d(st->time_base); best_error= best_error*best_error*duration_count[i]*1000*12*30; @@ -1866,14 +2030,39 @@ int av_find_stream_info(AVFormatContext *ic) } } }else if(st->codec->codec_type == CODEC_TYPE_AUDIO) { + if (st->codec->codec_id == CODEC_ID_NONE && probe_data[st->index].buf_size > 0) { + codec_identified[st->index] = set_codec_from_probe_data(st, &(probe_data[st->index]), 1); + if (codec_identified[st->index]) { + st->need_parsing = AVSTREAM_PARSE_FULL; + } + } if(!st->codec->bits_per_sample) st->codec->bits_per_sample= av_get_bits_per_sample(st->codec->codec_id); } } av_estimate_timings(ic, old_offset); + + for(i=0;inb_streams;i++) { + st = ic->streams[i]; + if (codec_identified[st->index]) + break; + } + //FIXME this is a mess + if(i!=ic->nb_streams){ + av_read_frame_flush(ic); + for(i=0;inb_streams;i++) { + st = ic->streams[i]; + if (codec_identified[st->index]) { + av_seek_frame(ic, st->index, 0.0, 0); + } + st->cur_dts= st->first_dts; + } + url_fseek(ic->pb, ic->data_offset, SEEK_SET); + } + #if 0 - /* correct DTS for b frame streams with no timestamps */ + /* correct DTS for B-frame streams with no timestamps */ for(i=0;inb_streams;i++) { st = ic->streams[i]; if (st->codec->codec_type == CODEC_TYPE_VIDEO) { @@ -1898,6 +2087,9 @@ int av_find_stream_info(AVFormatContext *ic) #endif av_free(duration_error); + for(i=0;iiformat->read_play) - return AVERROR_NOTSUPP; - return s->iformat->read_play(s); + if (s->iformat->read_play) + return s->iformat->read_play(s); + if (s->pb) + return av_url_read_fpause(s->pb, 0); + return AVERROR(ENOSYS); } int av_read_pause(AVFormatContext *s) { - if (!s->iformat->read_pause) - return AVERROR_NOTSUPP; - return s->iformat->read_pause(s); + if (s->iformat->read_pause) + return s->iformat->read_pause(s); + if (s->pb) + return av_url_read_fpause(s->pb, 1); + return AVERROR(ENOSYS); } -void av_close_input_file(AVFormatContext *s) +void av_close_input_stream(AVFormatContext *s) { - int i, must_open_file; + int i; AVStream *st; /* free previous packet */ @@ -1938,20 +2134,28 @@ void av_close_input_file(AVFormatContext *s) av_free(st->index_entries); av_free(st->codec->extradata); av_free(st->codec); + av_free(st->filename); av_free(st); } - flush_packet_queue(s); - must_open_file = 1; - if (s->iformat->flags & AVFMT_NOFILE) { - must_open_file = 0; - } - if (must_open_file) { - url_fclose(&s->pb); + for(i=s->nb_programs-1; i>=0; i--) { + av_freep(&s->programs[i]->provider_name); + av_freep(&s->programs[i]->name); + av_freep(&s->programs[i]->stream_index); + av_freep(&s->programs[i]); } + flush_packet_queue(s); av_freep(&s->priv_data); av_free(s); } +void av_close_input_file(AVFormatContext *s) +{ + ByteIOContext *pb = s->iformat->flags & AVFMT_NOFILE ? NULL : s->pb; + av_close_input_stream(s); + if (pb) + url_fclose(pb); +} + AVStream *av_new_stream(AVFormatContext *s, int id) { AVStream *st; @@ -1974,8 +2178,9 @@ AVStream *av_new_stream(AVFormatContext *s, int id) st->start_time = AV_NOPTS_VALUE; st->duration = AV_NOPTS_VALUE; st->cur_dts = AV_NOPTS_VALUE; + st->first_dts = AV_NOPTS_VALUE; - /* default pts settings is MPEG like */ + /* default pts setting is MPEG-like */ av_set_pts_info(st, 33, 1, 90000); st->last_IP_pts = AV_NOPTS_VALUE; for(i=0; inb_programs; i++) + if(ac->programs[i]->id == id) + program = ac->programs[i]; + + if(!program){ + program = av_mallocz(sizeof(AVProgram)); + if (!program) + return NULL; + dynarray_add(&ac->programs, &ac->nb_programs, program); + program->discard = AVDISCARD_NONE; + } + program->id = id; + + return program; +} + +void av_set_program_name(AVProgram *program, char *provider_name, char *name) +{ + assert(!provider_name == !name); + if(name){ + av_free(program->provider_name); + av_free(program-> name); + program->provider_name = av_strdup(provider_name); + program-> name = av_strdup( name); + } +} + + /************************************************************/ /* output media file */ @@ -1995,7 +2237,7 @@ int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap) if (s->oformat->priv_data_size > 0) { s->priv_data = av_mallocz(s->oformat->priv_data_size); if (!s->priv_data) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); } else s->priv_data = NULL; @@ -2039,7 +2281,7 @@ int av_write_header(AVFormatContext *s) if(st->codec->codec_tag){ //FIXME //check that tag + id is in the table - //if neither is in the table -> ok + //if neither is in the table -> OK //if tag is in the table with another id -> FAIL //if id is in the table with another tag -> FAIL unless strict < ? }else @@ -2050,7 +2292,7 @@ int av_write_header(AVFormatContext *s) if (!s->priv_data && s->oformat->priv_data_size > 0) { s->priv_data = av_mallocz(s->oformat->priv_data_size); if (!s->priv_data) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); } if(s->oformat->write_header){ @@ -2120,12 +2362,11 @@ static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){ } if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && st->cur_dts >= pkt->dts){ - av_log(NULL, AV_LOG_ERROR, "error, non monotone timestamps %"PRId64" >= %"PRId64" st:%d\n", st->cur_dts, pkt->dts, st->index); + av_log(NULL, AV_LOG_ERROR, "error, non monotone timestamps %"PRId64" >= %"PRId64"\n", st->cur_dts, pkt->dts); return -1; } if(pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts){ - av_log(NULL, AV_LOG_ERROR, "error, pts < dts (%"PRId64" < %"PRId64")\n", - pkt->pts, pkt->dts); + av_log(NULL, AV_LOG_ERROR, "error, pts < dts\n"); return -1; } @@ -2138,8 +2379,9 @@ static int compute_pkt_fields2(AVStream *st, AVPacket *pkt){ case CODEC_TYPE_AUDIO: frame_size = get_audio_frame_size(st->codec, pkt->size); - /* HACK/FIXME, we skip the initial 0-size packets as they are most likely equal to the encoder delay, - but it would be better if we had the real timestamps from the encoder */ + /* HACK/FIXME, we skip the initial 0 size packets as they are most + likely equal to the encoder delay, but it would be better if we + had the real timestamps from the encoder */ if (frame_size >= 0 && (pkt->size || st->pts.num!=st->pts.den>>1 || st->pts.val)) { av_frac_add(&st->pts, (int64_t)st->time_base.den * frame_size); } @@ -2157,7 +2399,7 @@ static void truncate_ts(AVStream *st, AVPacket *pkt){ int64_t pts_mask = (2LL << (st->pts_wrap_bits-1)) - 1; // if(pkt->dts < 0) -// pkt->dts= 0; //this happens for low_delay=0 and b frames, FIXME, needs further invstigation about what we should do here +// pkt->dts= 0; //this happens for low_delay=0 and B-frames, FIXME, needs further investigation about what we should do here if (pkt->pts != AV_NOPTS_VALUE) pkt->pts &= pts_mask; @@ -2177,7 +2419,7 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt) ret= s->oformat->write_packet(s, pkt); if(!ret) - ret= url_ferror(&s->pb); + ret= url_ferror(s->pb); return ret; } @@ -2194,7 +2436,7 @@ int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pk this_pktl = av_mallocz(sizeof(AVPacketList)); this_pktl->pkt= *pkt; if(pkt->destruct == av_destruct_packet) - pkt->destruct= NULL; // non shared -> must keep original from being freed + pkt->destruct= NULL; // not shared -> must keep original from being freed else av_dup_packet(&this_pktl->pkt); //shared -> must dup @@ -2235,7 +2477,7 @@ int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pk } /** - * Interleaves a AVPacket correctly so it can be muxed. + * Interleaves an AVPacket correctly so it can be muxed. * @param out the interleaved packet will be output here * @param in the input packet * @param flush 1 if no further packets are available as input and all @@ -2278,8 +2520,8 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){ if(ret<0) return ret; - if(url_ferror(&s->pb)) - return url_ferror(&s->pb); + if(url_ferror(s->pb)) + return url_ferror(s->pb); } } @@ -2302,7 +2544,7 @@ int av_write_trailer(AVFormatContext *s) if(ret<0) goto fail; - if(url_ferror(&s->pb)) + if(url_ferror(s->pb)) goto fail; } @@ -2310,22 +2552,70 @@ int av_write_trailer(AVFormatContext *s) ret = s->oformat->write_trailer(s); fail: if(ret == 0) - ret=url_ferror(&s->pb); + ret=url_ferror(s->pb); for(i=0;inb_streams;i++) av_freep(&s->streams[i]->priv_data); av_freep(&s->priv_data); return ret; } +void av_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx) +{ + int i, j; + AVProgram *program=NULL; + void *tmp; + + for(i=0; inb_programs; i++){ + if(ac->programs[i]->id != progid) + continue; + program = ac->programs[i]; + for(j=0; jnb_stream_indexes; j++) + if(program->stream_index[j] == idx) + return; + + tmp = av_realloc(program->stream_index, sizeof(unsigned int)*(program->nb_stream_indexes+1)); + if(!tmp) + return; + program->stream_index = tmp; + program->stream_index[program->nb_stream_indexes++] = idx; + return; + } +} + /* "user interface" functions */ +static void dump_stream_format(AVFormatContext *ic, int i, int index, int is_output) +{ + char buf[256]; + int flags = (is_output ? ic->oformat->flags : ic->iformat->flags); + AVStream *st = ic->streams[i]; + int g = ff_gcd(st->time_base.num, st->time_base.den); + avcodec_string(buf, sizeof(buf), st->codec, is_output); + av_log(NULL, AV_LOG_INFO, " Stream #%d.%d", index, i); + /* the pid is an important information, so we display it */ + /* XXX: add a generic system */ + if (flags & AVFMT_SHOW_IDS) + av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id); + if (strlen(st->language) > 0) + av_log(NULL, AV_LOG_INFO, "(%s)", st->language); + av_log(NULL, AV_LOG_DEBUG, ", %d/%d", st->time_base.num/g, st->time_base.den/g); + av_log(NULL, AV_LOG_INFO, ": %s", buf); + if(st->codec->codec_type == CODEC_TYPE_VIDEO){ + if(st->r_frame_rate.den && st->r_frame_rate.num) + av_log(NULL, AV_LOG_INFO, ", %5.2f tb(r)", av_q2d(st->r_frame_rate)); +/* else if(st->time_base.den && st->time_base.num) + av_log(NULL, AV_LOG_INFO, ", %5.2f tb(m)", 1/av_q2d(st->time_base));*/ + else + av_log(NULL, AV_LOG_INFO, ", %5.2f tb(c)", 1/av_q2d(st->codec->time_base)); + } + av_log(NULL, AV_LOG_INFO, "\n"); +} void dump_format(AVFormatContext *ic, int index, const char *url, int is_output) { - int i, flags; - char buf[256]; + int i; av_log(NULL, AV_LOG_INFO, "%s #%d, %s, %s '%s':\n", is_output ? "Output" : "Input", @@ -2363,124 +2653,43 @@ void dump_format(AVFormatContext *ic, } av_log(NULL, AV_LOG_INFO, "\n"); } - for(i=0;inb_streams;i++) { - AVStream *st = ic->streams[i]; - int g= ff_gcd(st->time_base.num, st->time_base.den); - avcodec_string(buf, sizeof(buf), st->codec, is_output); - av_log(NULL, AV_LOG_INFO, " Stream #%d.%d", index, i); - /* the pid is an important information, so we display it */ - /* XXX: add a generic system */ - if (is_output) - flags = ic->oformat->flags; - else - flags = ic->iformat->flags; - if (flags & AVFMT_SHOW_IDS) { - av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id); - } - if (strlen(st->language) > 0) { - av_log(NULL, AV_LOG_INFO, "(%s)", st->language); - } - av_log(NULL, AV_LOG_DEBUG, ", %d/%d", st->time_base.num/g, st->time_base.den/g); - av_log(NULL, AV_LOG_INFO, ": %s", buf); - if(st->codec->codec_type == CODEC_TYPE_VIDEO){ - if(st->r_frame_rate.den && st->r_frame_rate.num) - av_log(NULL, AV_LOG_INFO, ", %5.2f fps(r)", av_q2d(st->r_frame_rate)); -/* else if(st->time_base.den && st->time_base.num) - av_log(NULL, AV_LOG_INFO, ", %5.2f fps(m)", 1/av_q2d(st->time_base));*/ - else - av_log(NULL, AV_LOG_INFO, ", %5.2f fps(c)", 1/av_q2d(st->codec->time_base)); - } - av_log(NULL, AV_LOG_INFO, "\n"); - } + if(ic->nb_programs) { + int j, k; + for(j=0; jnb_programs; j++) { + av_log(NULL, AV_LOG_INFO, " Program %d %s\n", ic->programs[j]->id, + ic->programs[j]->name ? ic->programs[j]->name : ""); + for(k=0; kprograms[j]->nb_stream_indexes; k++) + dump_stream_format(ic, ic->programs[j]->stream_index[k], index, is_output); + } + } else + for(i=0;inb_streams;i++) + dump_stream_format(ic, i, index, is_output); } -typedef struct { - const char *abv; - int width, height; - int frame_rate, frame_rate_base; -} AbvEntry; - -static AbvEntry frame_abvs[] = { - { "ntsc", 720, 480, 30000, 1001 }, - { "pal", 720, 576, 25, 1 }, - { "qntsc", 352, 240, 30000, 1001 }, /* VCD compliant ntsc */ - { "qpal", 352, 288, 25, 1 }, /* VCD compliant pal */ - { "sntsc", 640, 480, 30000, 1001 }, /* square pixel ntsc */ - { "spal", 768, 576, 25, 1 }, /* square pixel pal */ - { "film", 352, 240, 24, 1 }, - { "ntsc-film", 352, 240, 24000, 1001 }, - { "sqcif", 128, 96, 0, 0 }, - { "qcif", 176, 144, 0, 0 }, - { "cif", 352, 288, 0, 0 }, - { "4cif", 704, 576, 0, 0 }, -}; - int parse_image_size(int *width_ptr, int *height_ptr, const char *str) { - int i; - int n = sizeof(frame_abvs) / sizeof(AbvEntry); - const char *p; - int frame_width = 0, frame_height = 0; - - for(i=0;idts / AV_TIME_BASE); - /* PTS may be not known if B frames are present */ + /* PTS may not be known if B-frames are present. */ PRINT(" pts="); if (pkt->pts == AV_NOPTS_VALUE) PRINT("N/A"); @@ -2765,68 +2981,58 @@ void url_split(char *proto, int proto_size, char *path, int path_size, const char *url) { - const char *p; - char *q; - int port; + const char *p, *ls, *at, *col, *brk; - port = -1; + if (port_ptr) *port_ptr = -1; + if (proto_size > 0) proto[0] = 0; + if (authorization_size > 0) authorization[0] = 0; + if (hostname_size > 0) hostname[0] = 0; + if (path_size > 0) path[0] = 0; - p = url; - q = proto; - while (*p != ':' && *p != '\0') { - if ((q - proto) < proto_size - 1) - *q++ = *p; - p++; - } - if (proto_size > 0) - *q = '\0'; - if (authorization_size > 0) - authorization[0] = '\0'; - if (*p == '\0') { - if (proto_size > 0) - proto[0] = '\0'; - if (hostname_size > 0) - hostname[0] = '\0'; - p = url; + /* parse protocol */ + if ((p = strchr(url, ':'))) { + av_strlcpy(proto, url, FFMIN(proto_size, p + 1 - url)); + p++; /* skip ':' */ + if (*p == '/') p++; + if (*p == '/') p++; } else { - char *at,*slash; // PETR: position of '@' character and '/' character + /* no protocol means plain filename */ + av_strlcpy(path, url, path_size); + return; + } - p++; - if (*p == '/') - p++; - if (*p == '/') - p++; - at = strchr(p,'@'); // PETR: get the position of '@' - slash = strchr(p,'/'); // PETR: get position of '/' - end of hostname - if (at && slash && at > slash) at = NULL; // PETR: not interested in '@' behind '/' - - q = at ? authorization : hostname; // PETR: if '@' exists starting with auth. - - while ((at || *p != ':') && *p != '/' && *p != '?' && *p != '\0') { // PETR: - if (*p == '@') { // PETR: passed '@' - if (authorization_size > 0) - *q = '\0'; - q = hostname; - at = NULL; - } else if (!at) { // PETR: hostname - if ((q - hostname) < hostname_size - 1) - *q++ = *p; - } else { - if ((q - authorization) < authorization_size - 1) - *q++ = *p; - } - p++; - } - if (hostname_size > 0) - *q = '\0'; - if (*p == ':') { - p++; - port = strtoul(p, (char **)&p, 10); + /* separate path from hostname */ + ls = strchr(p, '/'); + if(!ls) + ls = strchr(p, '?'); + if(ls) + av_strlcpy(path, ls, path_size); + else + ls = &p[strlen(p)]; // XXX + + /* the rest is hostname, use that to parse auth/port */ + if (ls != p) { + /* authorization (user[:pass]@hostname) */ + if ((at = strchr(p, '@')) && at < ls) { + av_strlcpy(authorization, p, + FFMIN(authorization_size, at + 1 - p)); + p = at + 1; /* skip '@' */ } + + if (*p == '[' && (brk = strchr(p, ']')) && brk < ls) { + /* [host]:port */ + av_strlcpy(hostname, p + 1, + FFMIN(hostname_size, brk - p)); + if (brk[1] == ':' && port_ptr) + *port_ptr = atoi(brk + 2); + } else if ((col = strchr(p, ':')) && col < ls) { + av_strlcpy(hostname, p, + FFMIN(col + 1 - p, hostname_size)); + if (port_ptr) *port_ptr = atoi(col + 1); + } else + av_strlcpy(hostname, p, + FFMIN(ls + 1 - p, hostname_size)); } - if (port_ptr) - *port_ptr = port; - pstrcpy(path, path_size, p); } void av_set_pts_info(AVStream *s, int pts_wrap_bits, @@ -2862,7 +3068,7 @@ static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den) } /** - * Fractionnal addition to f: f = f + (incr / f->den). + * Fractional addition to f: f = f + (incr / f->den). * * @param f fractional number * @param incr increment, can be positive or negative diff --git a/contrib/ffmpeg/libavformat/v4l2.c b/contrib/ffmpeg/libavformat/v4l2.c deleted file mode 100644 index aeaac3347..000000000 --- a/contrib/ffmpeg/libavformat/v4l2.c +++ /dev/null @@ -1,631 +0,0 @@ -/* - * Video4Linux2 grab interface - * Copyright (c) 2000,2001 Fabrice Bellard. - * Copyright (c) 2006 Luca Abeni. - * - * Part of this file is based on the V4L2 video capture example - * (http://v4l2spec.bytesex.org/v4l2spec/capture.c) - * - * Thanks to Michael Niedermayer for providing the mapping between - * V4L2_PIX_FMT_* and PIX_FMT_* - * - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include "avformat.h" -#include -#include -#include -#include -#include -#include -#include -#include - -static const int desired_video_buffers = 256; - -enum io_method { - io_read, - io_mmap, - io_userptr -}; - -struct video_data { - int fd; - int frame_format; /* V4L2_PIX_FMT_* */ - enum io_method io_method; - int width, height; - int frame_rate; - int frame_rate_base; - int frame_size; - int top_field_first; - - int buffers; - void **buf_start; - unsigned int *buf_len; -}; - -struct buff_data { - int index; - int fd; -}; - -struct fmt_map { - enum PixelFormat ff_fmt; - int32_t v4l2_fmt; -}; - -static struct fmt_map fmt_conversion_table[] = { - { - .ff_fmt = PIX_FMT_YUV420P, - .v4l2_fmt = V4L2_PIX_FMT_YUV420, - }, - { - .ff_fmt = PIX_FMT_YUV422P, - .v4l2_fmt = V4L2_PIX_FMT_YUV422P, - }, - { - .ff_fmt = PIX_FMT_YUYV422, - .v4l2_fmt = V4L2_PIX_FMT_YUYV, - }, - { - .ff_fmt = PIX_FMT_UYVY422, - .v4l2_fmt = V4L2_PIX_FMT_UYVY, - }, - { - .ff_fmt = PIX_FMT_YUV411P, - .v4l2_fmt = V4L2_PIX_FMT_YUV411P, - }, - { - .ff_fmt = PIX_FMT_YUV410P, - .v4l2_fmt = V4L2_PIX_FMT_YUV410, - }, - { - .ff_fmt = PIX_FMT_BGR24, - .v4l2_fmt = V4L2_PIX_FMT_BGR24, - }, - { - .ff_fmt = PIX_FMT_RGB24, - .v4l2_fmt = V4L2_PIX_FMT_RGB24, - }, - /* - { - .ff_fmt = PIX_FMT_RGB32, - .v4l2_fmt = V4L2_PIX_FMT_BGR32, - }, - */ - { - .ff_fmt = PIX_FMT_GRAY8, - .v4l2_fmt = V4L2_PIX_FMT_GREY, - }, -}; - -static int device_open(AVFormatContext *ctx, uint32_t *capabilities) -{ - struct v4l2_capability cap; - int fd; - int res; - - fd = open(ctx->filename, O_RDWR /*| O_NONBLOCK*/, 0); - if (fd < 0) { - av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s : %s\n", - ctx->filename, strerror(errno)); - - return -1; - } - - res = ioctl(fd, VIDIOC_QUERYCAP, &cap); - // ENOIOCTLCMD definition only availble on __KERNEL__ - if (res < 0 && errno == 515) - { - av_log(ctx, AV_LOG_ERROR, "QUERYCAP not implemented, probably V4L device but not supporting V4L2\n"); - close(fd); - - return -1; - } - if (res < 0) { - av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n", - strerror(errno)); - close(fd); - - return -1; - } - if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) { - av_log(ctx, AV_LOG_ERROR, "Not a video capture device\n"); - close(fd); - - return -1; - } - *capabilities = cap.capabilities; - - return fd; -} - -static int device_init(AVFormatContext *ctx, int *width, int *height, int pix_fmt) -{ - struct video_data *s = ctx->priv_data; - int fd = s->fd; - struct v4l2_format fmt; - int res; - - memset(&fmt, 0, sizeof(struct v4l2_format)); - fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - fmt.fmt.pix.width = *width; - fmt.fmt.pix.height = *height; - fmt.fmt.pix.pixelformat = pix_fmt; - fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; - res = ioctl(fd, VIDIOC_S_FMT, &fmt); - if ((*width != fmt.fmt.pix.width) || (*height != fmt.fmt.pix.height)) { - av_log(ctx, AV_LOG_INFO, "The V4L2 driver changed the video from %dx%d to %dx%d\n", *width, *height, fmt.fmt.pix.width, fmt.fmt.pix.height); - *width = fmt.fmt.pix.width; - *height = fmt.fmt.pix.height; - } - - return res; -} - -static int first_field(int fd) -{ - int res; - v4l2_std_id std; - - res = ioctl(fd, VIDIOC_G_STD, &std); - if (res < 0) { - return 0; - } - if (std & V4L2_STD_NTSC) { - return 0; - } - - return 1; -} - -static uint32_t fmt_ff2v4l(enum PixelFormat pix_fmt) -{ - int i; - - for (i = 0; i < sizeof(fmt_conversion_table) / sizeof(struct fmt_map); i++) { - if (fmt_conversion_table[i].ff_fmt == pix_fmt) { - return fmt_conversion_table[i].v4l2_fmt; - } - } - - return 0; -} - -static enum PixelFormat fmt_v4l2ff(uint32_t pix_fmt) -{ - int i; - - for (i = 0; i < sizeof(fmt_conversion_table) / sizeof(struct fmt_map); i++) { - if (fmt_conversion_table[i].v4l2_fmt == pix_fmt) { - return fmt_conversion_table[i].ff_fmt; - } - } - - return -1; -} - -static int mmap_init(AVFormatContext *ctx) -{ - struct video_data *s = ctx->priv_data; - struct v4l2_requestbuffers req; - int i, res; - - memset(&req, 0, sizeof(struct v4l2_requestbuffers)); - req.count = desired_video_buffers; - req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - req.memory = V4L2_MEMORY_MMAP; - res = ioctl (s->fd, VIDIOC_REQBUFS, &req); - if (res < 0) { - if (errno == EINVAL) { - av_log(ctx, AV_LOG_ERROR, "Device does not support mmap\n"); - } else { - av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_REQBUFS)\n"); - } - - return -1; - } - - if (req.count < 2) { - av_log(ctx, AV_LOG_ERROR, "Insufficient buffer memory\n"); - - return -1; - } - s->buffers = req.count; - s->buf_start = av_malloc(sizeof(void *) * s->buffers); - if (s->buf_start == NULL) { - av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer pointers\n"); - - return -1; - } - s->buf_len = av_malloc(sizeof(unsigned int) * s->buffers); - if (s->buf_len == NULL) { - av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer sizes\n"); - av_free(s->buf_start); - - return -1; - } - - for (i = 0; i < req.count; i++) { - struct v4l2_buffer buf; - - memset(&buf, 0, sizeof(struct v4l2_buffer)); - buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf.memory = V4L2_MEMORY_MMAP; - buf.index = i; - res = ioctl (s->fd, VIDIOC_QUERYBUF, &buf); - if (res < 0) { - av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYBUF)\n"); - - return -1; - } - - s->buf_len[i] = buf.length; - if (s->buf_len[i] < s->frame_size) { - av_log(ctx, AV_LOG_ERROR, "Buffer len [%d] = %d != %d\n", i, s->buf_len[i], s->frame_size); - - return -1; - } - s->buf_start[i] = mmap (NULL, buf.length, - PROT_READ | PROT_WRITE, MAP_SHARED, s->fd, buf.m.offset); - if (s->buf_start[i] == MAP_FAILED) { - av_log(ctx, AV_LOG_ERROR, "mmap: %s\n", strerror(errno)); - - return -1; - } - } - - return 0; -} - -static int read_init(AVFormatContext *ctx) -{ - return -1; -} - -static void mmap_release_buffer(AVPacket *pkt) -{ - struct v4l2_buffer buf; - int res, fd; - struct buff_data *buf_descriptor = pkt->priv; - - memset(&buf, 0, sizeof(struct v4l2_buffer)); - buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf.memory = V4L2_MEMORY_MMAP; - buf.index = buf_descriptor->index; - fd = buf_descriptor->fd; - av_free(buf_descriptor); - - res = ioctl (fd, VIDIOC_QBUF, &buf); - if (res < 0) { - av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF)\n"); - } - pkt->data = NULL; - pkt->size = 0; -} - -static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt) -{ - struct video_data *s = ctx->priv_data; - struct v4l2_buffer buf; - struct buff_data *buf_descriptor; - int res; - - memset(&buf, 0, sizeof(struct v4l2_buffer)); - buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf.memory = V4L2_MEMORY_MMAP; - - /* FIXME: Some special treatment might be needed in case of loss of signal... */ - while ((res = ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 && - ((errno == EAGAIN) || (errno == EINTR))); - if (res < 0) { - av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n", strerror(errno)); - - return -1; - } - assert (buf.index < s->buffers); - if (buf.bytesused != s->frame_size) { - av_log(ctx, AV_LOG_ERROR, "The v4l2 frame is %d bytes, but %d bytes are expected\n", buf.bytesused, s->frame_size); - - return -1; - } - - /* Image is at s->buff_start[buf.index] */ - pkt->data= s->buf_start[buf.index]; - pkt->size = buf.bytesused; - pkt->pts = buf.timestamp.tv_sec * INT64_C(1000000) + buf.timestamp.tv_usec; - pkt->destruct = mmap_release_buffer; - buf_descriptor = av_malloc(sizeof(struct buff_data)); - if (buf_descriptor == NULL) { - /* Something went wrong... Since av_malloc() failed, we cannot even - * allocate a buffer for memcopying into it - */ - av_log(ctx, AV_LOG_ERROR, "Failed to allocate a buffer descriptor\n"); - res = ioctl (s->fd, VIDIOC_QBUF, &buf); - - return -1; - } - buf_descriptor->fd = s->fd; - buf_descriptor->index = buf.index; - pkt->priv = buf_descriptor; - - return s->buf_len[buf.index]; -} - -static int read_frame(AVFormatContext *ctx, AVPacket *pkt) -{ - return -1; -} - -static int mmap_start(AVFormatContext *ctx) -{ - struct video_data *s = ctx->priv_data; - enum v4l2_buf_type type; - int i, res; - - for (i = 0; i < s->buffers; i++) { - struct v4l2_buffer buf; - - memset(&buf, 0, sizeof(struct v4l2_buffer)); - buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf.memory = V4L2_MEMORY_MMAP; - buf.index = i; - - res = ioctl (s->fd, VIDIOC_QBUF, &buf); - if (res < 0) { - av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n", strerror(errno)); - - return -1; - } - } - - type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - res = ioctl (s->fd, VIDIOC_STREAMON, &type); - if (res < 0) { - av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_STREAMON): %s\n", strerror(errno)); - - return -1; - } - - return 0; -} - -static void mmap_close(struct video_data *s) -{ - enum v4l2_buf_type type; - int i; - - type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - /* We do not check for the result, because we could - * not do anything about it anyway... - */ - ioctl(s->fd, VIDIOC_STREAMOFF, &type); - for (i = 0; i < s->buffers; i++) { - munmap(s->buf_start[i], s->buf_len[i]); - } - av_free(s->buf_start); - av_free(s->buf_len); -} - -static int v4l2_set_parameters( AVFormatContext *s1, AVFormatParameters *ap ) -{ - struct video_data *s = s1->priv_data; - struct v4l2_input input; - struct v4l2_standard standard; - int i; - - /* set tv video input */ - memset (&input, 0, sizeof (input)); - input.index = ap->channel; - if(ioctl (s->fd, VIDIOC_ENUMINPUT, &input) < 0) { - av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum input failed:\n"); - return AVERROR_IO; - } - - av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, input: %s\n", - ap->channel, input.name); - if(ioctl (s->fd, VIDIOC_S_INPUT, &input.index) < 0 ) { - av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set input(%d) failed\n", - ap->channel); - return AVERROR_IO; - } - - av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s\n", - ap->standard ); - /* set tv standard */ - memset (&standard, 0, sizeof (standard)); - for(i=0;;i++) { - standard.index = i; - if (ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) { - av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set standard(%s) failed\n", - ap->standard); - return AVERROR_IO; - } - - if(!strcasecmp(standard.name, ap->standard)) { - break; - } - } - - av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s, id: %"PRIu64"\n", - ap->standard, standard.id); - if (ioctl(s->fd, VIDIOC_S_STD, &standard.id) < 0) { - av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set standard(%s) failed\n", - ap->standard); - return AVERROR_IO; - } - - return 0; -} - -static int v4l2_read_header(AVFormatContext *s1, AVFormatParameters *ap) -{ - struct video_data *s = s1->priv_data; - AVStream *st; - int width, height; - int res, frame_rate, frame_rate_base; - uint32_t desired_format, capabilities; - - if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) { - av_log(s1, AV_LOG_ERROR, "Missing/Wrong parameters\n"); - - return -1; - } - - width = ap->width; - height = ap->height; - frame_rate = ap->time_base.den; - frame_rate_base = ap->time_base.num; - - if((unsigned)width > 32767 || (unsigned)height > 32767) { - av_log(s1, AV_LOG_ERROR, "Wrong size %dx%d\n", width, height); - - return -1; - } - - st = av_new_stream(s1, 0); - if (!st) { - return AVERROR(ENOMEM); - } - av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ - - s->width = width; - s->height = height; - s->frame_rate = frame_rate; - s->frame_rate_base = frame_rate_base; - - capabilities = 0; - s->fd = device_open(s1, &capabilities); - if (s->fd < 0) { - av_free(st); - - return AVERROR_IO; - } - av_log(s1, AV_LOG_INFO, "[%d]Capabilities: %x\n", s->fd, capabilities); - - desired_format = fmt_ff2v4l(ap->pix_fmt); - if (desired_format == 0 || (device_init(s1, &width, &height, desired_format) < 0)) { - int i, done; - - done = 0; i = 0; - while (!done) { - desired_format = fmt_conversion_table[i].v4l2_fmt; - if (device_init(s1, &width, &height, desired_format) < 0) { - desired_format = 0; - i++; - } else { - done = 1; - } - if (i == sizeof(fmt_conversion_table) / sizeof(struct fmt_map)) { - done = 1; - } - } - } - if (desired_format == 0) { - av_log(s1, AV_LOG_ERROR, "Cannot find a proper format.\n"); - close(s->fd); - av_free(st); - - return AVERROR_IO; - } - s->frame_format = desired_format; - - if( v4l2_set_parameters( s1, ap ) < 0 ) - return AVERROR_IO; - - st->codec->pix_fmt = fmt_v4l2ff(desired_format); - s->frame_size = avpicture_get_size(st->codec->pix_fmt, width, height); - if (capabilities & V4L2_CAP_STREAMING) { - s->io_method = io_mmap; - res = mmap_init(s1); - if (res == 0) { - res = mmap_start(s1); - } - } else { - s->io_method = io_read; - res = read_init(s1); - } - if (res < 0) { - close(s->fd); - av_free(st); - - return AVERROR_IO; - } - s->top_field_first = first_field(s->fd); - - st->codec->codec_type = CODEC_TYPE_VIDEO; - st->codec->codec_id = CODEC_ID_RAWVIDEO; - st->codec->width = width; - st->codec->height = height; - st->codec->time_base.den = frame_rate; - st->codec->time_base.num = frame_rate_base; - st->codec->bit_rate = s->frame_size * 1/av_q2d(st->codec->time_base) * 8; - - return 0; -} - -static int v4l2_read_packet(AVFormatContext *s1, AVPacket *pkt) -{ - struct video_data *s = s1->priv_data; - int res; - - if (s->io_method == io_mmap) { - av_init_packet(pkt); - res = mmap_read_frame(s1, pkt); - } else if (s->io_method == io_read) { - if (av_new_packet(pkt, s->frame_size) < 0) - return AVERROR_IO; - - res = read_frame(s1, pkt); - } else { - return AVERROR_IO; - } - if (res < 0) { - return AVERROR_IO; - } - - if (s1->streams[0]->codec->coded_frame) { - s1->streams[0]->codec->coded_frame->interlaced_frame = 1; - s1->streams[0]->codec->coded_frame->top_field_first = s->top_field_first; - } - - return s->frame_size; -} - -static int v4l2_read_close(AVFormatContext *s1) -{ - struct video_data *s = s1->priv_data; - - if (s->io_method == io_mmap) { - mmap_close(s); - } - - close(s->fd); - return 0; -} - -AVInputFormat v4l2_demuxer = { - "video4linux2", - "video grab", - sizeof(struct video_data), - NULL, - v4l2_read_header, - v4l2_read_packet, - v4l2_read_close, - .flags = AVFMT_NOFILE, -}; diff --git a/contrib/ffmpeg/libavformat/vc1test.c b/contrib/ffmpeg/libavformat/vc1test.c new file mode 100644 index 000000000..c8340179c --- /dev/null +++ b/contrib/ffmpeg/libavformat/vc1test.c @@ -0,0 +1,112 @@ +/* + * VC1 Test Bitstreams Format Demuxer + * Copyright (c) 2006, 2008 Konstantin Shishkov + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file vc1test.c + * VC1 test bitstream file demuxer + * by Konstantin Shishkov + * Format specified in SMPTE standard 421 Annex L + */ + +#include "avformat.h" + +#define VC1_EXTRADATA_SIZE 4 + +static int vc1t_probe(AVProbeData *p) +{ + if (p->buf[3] != 0xC5 && AV_RL32(&p->buf[4]) != 4) + return 0; + + return AVPROBE_SCORE_MAX; +} + +static int vc1t_read_header(AVFormatContext *s, + AVFormatParameters *ap) +{ + ByteIOContext *pb = s->pb; + AVStream *st; + int fps, frames; + + frames = get_le24(pb); + if(get_byte(pb) != 0xC5 || get_le32(pb) != 4) + return -1; + + /* init video codec */ + st = av_new_stream(s, 0); + if (!st) + return -1; + + st->codec->codec_type = CODEC_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_WMV3; + + st->codec->extradata = av_malloc(VC1_EXTRADATA_SIZE); + st->codec->extradata_size = VC1_EXTRADATA_SIZE; + get_buffer(pb, st->codec->extradata, VC1_EXTRADATA_SIZE); + st->codec->height = get_le32(pb); + st->codec->width = get_le32(pb); + if(get_le32(pb) != 0xC) + return -1; + url_fskip(pb, 8); + fps = get_le32(pb); + if(fps == -1) + av_set_pts_info(st, 32, 1, 1000); + else{ + av_set_pts_info(st, 24, 1, fps); + st->duration = frames; + } + + return 0; +} + +static int vc1t_read_packet(AVFormatContext *s, + AVPacket *pkt) +{ + ByteIOContext *pb = s->pb; + int frame_size; + int keyframe = 0; + uint32_t pts; + + if(url_feof(pb)) + return AVERROR(EIO); + + frame_size = get_le24(pb); + if(get_byte(pb) & 0x80) + keyframe = 1; + pts = get_le32(pb); + if(av_get_packet(pb, pkt, frame_size) < 0) + return AVERROR(EIO); + if(s->streams[0]->time_base.den == 1000) + pkt->pts = pts; + pkt->flags |= keyframe ? PKT_FLAG_KEY : 0; + pkt->pos -= 8; + + return pkt->size; +} + +AVInputFormat vc1t_demuxer = { + "vc1test", + "VC1 test bitstream format", + 0, + vc1t_probe, + vc1t_read_header, + vc1t_read_packet, + .flags = AVFMT_GENERIC_INDEX, +}; diff --git a/contrib/ffmpeg/libavformat/voc.c b/contrib/ffmpeg/libavformat/voc.c index 97b73d163..750f78d15 100644 --- a/contrib/ffmpeg/libavformat/voc.c +++ b/contrib/ffmpeg/libavformat/voc.c @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "voc.h" diff --git a/contrib/ffmpeg/libavformat/voc.h b/contrib/ffmpeg/libavformat/voc.h index 9b2bb8cce..606f2152e 100644 --- a/contrib/ffmpeg/libavformat/voc.h +++ b/contrib/ffmpeg/libavformat/voc.h @@ -16,11 +16,11 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef VOC_H -#define VOC_H +#ifndef FFMPEG_VOC_H +#define FFMPEG_VOC_H #include "avformat.h" #include "riff.h" /* for CodecTag */ @@ -48,4 +48,4 @@ extern const AVCodecTag voc_codec_tags[]; int voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size); -#endif +#endif /* FFMPEG_VOC_H */ diff --git a/contrib/ffmpeg/libavformat/vocdec.c b/contrib/ffmpeg/libavformat/vocdec.c index 85d304dff..7c50fa588 100644 --- a/contrib/ffmpeg/libavformat/vocdec.c +++ b/contrib/ffmpeg/libavformat/vocdec.c @@ -16,24 +16,20 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "voc.h" - - static int voc_probe(AVProbeData *p) { int version, check; - if (p->buf_size < 26) - return 0; if (memcmp(p->buf, voc_magic, sizeof(voc_magic) - 1)) return 0; - version = p->buf[22] | (p->buf[23] << 8); - check = p->buf[24] | (p->buf[25] << 8); + version = AV_RL16(p->buf + 22); + check = AV_RL16(p->buf + 24); if (~version + 0x1234 != check) return 10; @@ -43,7 +39,7 @@ static int voc_probe(AVProbeData *p) static int voc_read_header(AVFormatContext *s, AVFormatParameters *ap) { voc_dec_context_t *voc = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int header_size; AVStream *st; @@ -51,12 +47,12 @@ static int voc_read_header(AVFormatContext *s, AVFormatParameters *ap) header_size = get_le16(pb) - 22; if (header_size != 4) { av_log(s, AV_LOG_ERROR, "unknown header size: %d\n", header_size); - return AVERROR_NOTSUPP; + return AVERROR(ENOSYS); } url_fskip(pb, header_size); st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); st->codec->codec_type = CODEC_TYPE_AUDIO; voc->remaining_size = 0; @@ -68,7 +64,7 @@ voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size) { voc_dec_context_t *voc = s->priv_data; AVCodecContext *dec = st->codec; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; voc_type_t type; int size; int sample_rate = 0; @@ -77,7 +73,7 @@ voc_get_packet(AVFormatContext *s, AVPacket *pkt, AVStream *st, int max_size) while (!voc->remaining_size) { type = get_byte(pb); if (type == VOC_TYPE_EOF) - return AVERROR_IO; + return AVERROR(EIO); voc->remaining_size = get_le24(pb); max_size -= 4; @@ -138,11 +134,6 @@ static int voc_read_packet(AVFormatContext *s, AVPacket *pkt) return voc_get_packet(s, pkt, s->streams[0], 0); } -static int voc_read_close(AVFormatContext *s) -{ - return 0; -} - AVInputFormat voc_demuxer = { "voc", "Creative Voice File format", @@ -150,6 +141,5 @@ AVInputFormat voc_demuxer = { voc_probe, voc_read_header, voc_read_packet, - voc_read_close, .codec_tag=(const AVCodecTag*[]){voc_codec_tags, 0}, }; diff --git a/contrib/ffmpeg/libavformat/vocenc.c b/contrib/ffmpeg/libavformat/vocenc.c index 6a07c92dd..d967fae09 100644 --- a/contrib/ffmpeg/libavformat/vocenc.c +++ b/contrib/ffmpeg/libavformat/vocenc.c @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "voc.h" @@ -28,13 +28,13 @@ typedef struct voc_enc_context { static int voc_write_header(AVFormatContext *s) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; const int header_size = 26; const int version = 0x0114; if (s->nb_streams != 1 || s->streams[0]->codec->codec_type != CODEC_TYPE_AUDIO) - return AVERROR_NOTSUPP; + return AVERROR_PATCHWELCOME; put_buffer(pb, voc_magic, sizeof(voc_magic) - 1); put_le16(pb, header_size); @@ -48,7 +48,7 @@ static int voc_write_packet(AVFormatContext *s, AVPacket *pkt) { voc_enc_context_t *voc = s->priv_data; AVCodecContext *enc = s->streams[0]->codec; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; if (!voc->param_written) { if (enc->codec_tag > 0xFF) { @@ -84,7 +84,7 @@ static int voc_write_packet(AVFormatContext *s, AVPacket *pkt) static int voc_write_trailer(AVFormatContext *s) { - put_byte(&s->pb, 0); + put_byte(s->pb, 0); return 0; } diff --git a/contrib/ffmpeg/libavformat/wav.c b/contrib/ffmpeg/libavformat/wav.c index 0699bec70..5053d1500 100644 --- a/contrib/ffmpeg/libavformat/wav.c +++ b/contrib/ffmpeg/libavformat/wav.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "avformat.h" -#include "allformats.h" +#include "raw.h" #include "riff.h" typedef struct { @@ -34,7 +34,7 @@ typedef struct { static int wav_write_header(AVFormatContext *s) { WAVContext *wav = s->priv_data; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; offset_t fmt, fact; put_tag(pb, "RIFF"); @@ -50,7 +50,7 @@ static int wav_write_header(AVFormatContext *s) end_tag(pb, fmt); if(s->streams[0]->codec->codec_tag != 0x01 /* hence for all other than PCM */ - && !url_is_streamed(&s->pb)) { + && !url_is_streamed(s->pb)) { fact = start_tag(pb, "fact"); put_le32(pb, 0); end_tag(pb, fact); @@ -70,7 +70,7 @@ static int wav_write_header(AVFormatContext *s) static int wav_write_packet(AVFormatContext *s, AVPacket *pkt) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; WAVContext *wav = s->priv_data; put_buffer(pb, pkt->data, pkt->size); if(pkt->pts != AV_NOPTS_VALUE) { @@ -84,11 +84,11 @@ static int wav_write_packet(AVFormatContext *s, AVPacket *pkt) static int wav_write_trailer(AVFormatContext *s) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; WAVContext *wav = s->priv_data; offset_t file_size; - if (!url_is_streamed(&s->pb)) { + if (!url_is_streamed(s->pb)) { end_tag(pb, wav->data); /* update file size */ @@ -156,7 +156,7 @@ static int wav_read_header(AVFormatContext *s, { int size; unsigned int tag; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVStream *st; WAVContext *wav = s->priv_data; @@ -176,10 +176,10 @@ static int wav_read_header(AVFormatContext *s, return -1; st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); get_wav_header(pb, st->codec, size); - st->need_parsing = 1; + st->need_parsing = AVSTREAM_PARSE_FULL; av_set_pts_info(st, 64, 1, st->codec->sample_rate); @@ -199,17 +199,17 @@ static int wav_read_packet(AVFormatContext *s, AVStream *st; WAVContext *wav = s->priv_data; - if (url_feof(&s->pb)) - return AVERROR_IO; + if (url_feof(s->pb)) + return AVERROR(EIO); st = s->streams[0]; - left= wav->data_end - url_ftell(&s->pb); + left= wav->data_end - url_ftell(s->pb); if(left <= 0){ - left = find_tag(&(s->pb), MKTAG('d', 'a', 't', 'a')); + left = find_tag(s->pb, MKTAG('d', 'a', 't', 'a')); if (left < 0) { - return AVERROR_IO; + return AVERROR(EIO); } - wav->data_end= url_ftell(&s->pb) + left; + wav->data_end= url_ftell(s->pb) + left; } size = MAX_SIZE; @@ -219,9 +219,9 @@ static int wav_read_packet(AVFormatContext *s, size = (size / st->codec->block_align) * st->codec->block_align; } size= FFMIN(size, left); - ret= av_get_packet(&s->pb, pkt, size); + ret= av_get_packet(s->pb, pkt, size); if (ret <= 0) - return AVERROR_IO; + return AVERROR(EIO); pkt->stream_index = 0; /* note: we need to modify the packet size here to handle the last diff --git a/contrib/ffmpeg/libavformat/wc3movie.c b/contrib/ffmpeg/libavformat/wc3movie.c index 3e58a1bba..00efb02ca 100644 --- a/contrib/ffmpeg/libavformat/wc3movie.c +++ b/contrib/ffmpeg/libavformat/wc3movie.c @@ -33,7 +33,7 @@ #define FORM_TAG MKTAG('F', 'O', 'R', 'M') #define MOVE_TAG MKTAG('M', 'O', 'V', 'E') -#define _PC__TAG MKTAG('_', 'P', 'C', '_') +#define PC__TAG MKTAG('_', 'P', 'C', '_') #define SOND_TAG MKTAG('S', 'O', 'N', 'D') #define BNAM_TAG MKTAG('B', 'N', 'A', 'M') #define SIZE_TAG MKTAG('S', 'I', 'Z', 'E') @@ -125,8 +125,8 @@ static int wc3_probe(AVProbeData *p) static int wc3_read_header(AVFormatContext *s, AVFormatParameters *ap) { - Wc3DemuxContext *wc3 = (Wc3DemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + Wc3DemuxContext *wc3 = s->priv_data; + ByteIOContext *pb = s->pb; unsigned int fourcc_tag; unsigned int size; AVStream *st; @@ -152,7 +152,7 @@ static int wc3_read_header(AVFormatContext *s, * the first BRCH tag */ if ((ret = get_buffer(pb, preamble, WC3_PREAMBLE_SIZE)) != WC3_PREAMBLE_SIZE) - return AVERROR_IO; + return AVERROR(EIO); fourcc_tag = AV_RL32(&preamble[0]); size = (AV_RB32(&preamble[4]) + 1) & (~1); @@ -165,11 +165,11 @@ static int wc3_read_header(AVFormatContext *s, url_fseek(pb, size, SEEK_CUR); break; - case _PC__TAG: + case PC__TAG: /* need the number of palettes */ url_fseek(pb, 8, SEEK_CUR); if ((ret = get_buffer(pb, preamble, 4)) != 4) - return AVERROR_IO; + return AVERROR(EIO); wc3->palette_count = AV_RL32(&preamble[0]); if((unsigned)wc3->palette_count >= UINT_MAX / PALETTE_SIZE){ wc3->palette_count= 0; @@ -185,14 +185,14 @@ static int wc3_read_header(AVFormatContext *s, else bytes_to_read = 512; if ((ret = get_buffer(pb, s->title, bytes_to_read)) != bytes_to_read) - return AVERROR_IO; + return AVERROR(EIO); break; case SIZE_TAG: /* video resolution override */ if ((ret = get_buffer(pb, preamble, WC3_PREAMBLE_SIZE)) != WC3_PREAMBLE_SIZE) - return AVERROR_IO; + return AVERROR(EIO); wc3->width = AV_RL32(&preamble[0]); wc3->height = AV_RL32(&preamble[4]); break; @@ -204,7 +204,7 @@ static int wc3_read_header(AVFormatContext *s, if ((ret = get_buffer(pb, &wc3->palettes[current_palette * PALETTE_SIZE], PALETTE_SIZE)) != PALETTE_SIZE) - return AVERROR_IO; + return AVERROR(EIO); /* transform the current palette in place */ for (i = current_palette * PALETTE_SIZE; @@ -228,7 +228,7 @@ static int wc3_read_header(AVFormatContext *s, if ((ret = get_buffer(pb, preamble, WC3_PREAMBLE_SIZE)) != WC3_PREAMBLE_SIZE) - return AVERROR_IO; + return AVERROR(EIO); fourcc_tag = AV_RL32(&preamble[0]); /* chunk sizes are 16-bit aligned */ size = (AV_RB32(&preamble[4]) + 1) & (~1); @@ -238,7 +238,7 @@ static int wc3_read_header(AVFormatContext *s, /* initialize the decoder streams */ st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 33, 1, 90000); wc3->video_stream_index = st->index; st->codec->codec_type = CODEC_TYPE_VIDEO; @@ -252,7 +252,7 @@ static int wc3_read_header(AVFormatContext *s, st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 33, 1, 90000); wc3->audio_stream_index = st->index; st->codec->codec_type = CODEC_TYPE_AUDIO; @@ -271,8 +271,8 @@ static int wc3_read_header(AVFormatContext *s, static int wc3_read_packet(AVFormatContext *s, AVPacket *pkt) { - Wc3DemuxContext *wc3 = (Wc3DemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + Wc3DemuxContext *wc3 = s->priv_data; + ByteIOContext *pb = s->pb; unsigned int fourcc_tag; unsigned int size; int packet_read = 0; @@ -289,7 +289,7 @@ static int wc3_read_packet(AVFormatContext *s, /* get the next chunk preamble */ if ((ret = get_buffer(pb, preamble, WC3_PREAMBLE_SIZE)) != WC3_PREAMBLE_SIZE) - ret = AVERROR_IO; + ret = AVERROR(EIO); fourcc_tag = AV_RL32(&preamble[0]); /* chunk sizes are 16-bit aligned */ @@ -304,7 +304,7 @@ static int wc3_read_packet(AVFormatContext *s, case SHOT_TAG: /* load up new palette */ if ((ret = get_buffer(pb, preamble, 4)) != 4) - return AVERROR_IO; + return AVERROR(EIO); palette_number = AV_RL32(&preamble[0]); if (palette_number >= wc3->palette_count) return AVERROR_INVALIDDATA; @@ -324,7 +324,7 @@ static int wc3_read_packet(AVFormatContext *s, pkt->stream_index = wc3->video_stream_index; pkt->pts = wc3->pts; if (ret != size) - ret = AVERROR_IO; + ret = AVERROR(EIO); packet_read = 1; break; @@ -334,7 +334,7 @@ static int wc3_read_packet(AVFormatContext *s, url_fseek(pb, size, SEEK_CUR); #else if ((unsigned)size > sizeof(text) || (ret = get_buffer(pb, text, size)) != size) - ret = AVERROR_IO; + ret = AVERROR(EIO); else { int i = 0; av_log (s, AV_LOG_DEBUG, "Subtitle time!\n"); @@ -353,7 +353,7 @@ static int wc3_read_packet(AVFormatContext *s, pkt->stream_index = wc3->audio_stream_index; pkt->pts = wc3->pts; if (ret != size) - ret = AVERROR_IO; + ret = AVERROR(EIO); /* time to advance pts */ wc3->pts += WC3_FRAME_PTS_INC; @@ -376,7 +376,7 @@ static int wc3_read_packet(AVFormatContext *s, static int wc3_read_close(AVFormatContext *s) { - Wc3DemuxContext *wc3 = (Wc3DemuxContext *)s->priv_data; + Wc3DemuxContext *wc3 = s->priv_data; av_free(wc3->palettes); diff --git a/contrib/ffmpeg/libavformat/westwood.c b/contrib/ffmpeg/libavformat/westwood.c index bed2f0d14..268f2e71e 100644 --- a/contrib/ffmpeg/libavformat/westwood.c +++ b/contrib/ffmpeg/libavformat/westwood.c @@ -117,13 +117,13 @@ static int wsaud_probe(AVProbeData *p) static int wsaud_read_header(AVFormatContext *s, AVFormatParameters *ap) { - WsAudDemuxContext *wsaud = (WsAudDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + WsAudDemuxContext *wsaud = s->priv_data; + ByteIOContext *pb = s->pb; AVStream *st; unsigned char header[AUD_HEADER_SIZE]; if (get_buffer(pb, header, AUD_HEADER_SIZE) != AUD_HEADER_SIZE) - return AVERROR_IO; + return AVERROR(EIO); wsaud->audio_samplerate = AV_RL16(&header[0]); if (header[11] == 99) wsaud->audio_type = CODEC_ID_ADPCM_IMA_WS; @@ -138,7 +138,7 @@ static int wsaud_read_header(AVFormatContext *s, /* initialize the audio decoder stream */ st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 33, 1, wsaud->audio_samplerate); st->codec->codec_type = CODEC_TYPE_AUDIO; st->codec->codec_id = wsaud->audio_type; @@ -159,15 +159,15 @@ static int wsaud_read_header(AVFormatContext *s, static int wsaud_read_packet(AVFormatContext *s, AVPacket *pkt) { - WsAudDemuxContext *wsaud = (WsAudDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + WsAudDemuxContext *wsaud = s->priv_data; + ByteIOContext *pb = s->pb; unsigned char preamble[AUD_CHUNK_PREAMBLE_SIZE]; unsigned int chunk_size; int ret = 0; if (get_buffer(pb, preamble, AUD_CHUNK_PREAMBLE_SIZE) != AUD_CHUNK_PREAMBLE_SIZE) - return AVERROR_IO; + return AVERROR(EIO); /* validate the chunk */ if (AV_RL32(&preamble[4]) != AUD_CHUNK_SIGNATURE) @@ -176,7 +176,7 @@ static int wsaud_read_packet(AVFormatContext *s, chunk_size = AV_RL16(&preamble[0]); ret= av_get_packet(pb, pkt, chunk_size); if (ret != chunk_size) - return AVERROR_IO; + return AVERROR(EIO); pkt->stream_index = wsaud->audio_stream_index; pkt->pts = wsaud->audio_frame_counter; pkt->pts /= wsaud->audio_samplerate; @@ -189,7 +189,7 @@ static int wsaud_read_packet(AVFormatContext *s, static int wsaud_read_close(AVFormatContext *s) { -// WsAudDemuxContext *wsaud = (WsAudDemuxContext *)s->priv_data; +// WsAudDemuxContext *wsaud = s->priv_data; return 0; } @@ -212,8 +212,8 @@ static int wsvqa_probe(AVProbeData *p) static int wsvqa_read_header(AVFormatContext *s, AVFormatParameters *ap) { - WsVqaDemuxContext *wsvqa = (WsVqaDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + WsVqaDemuxContext *wsvqa = s->priv_data; + ByteIOContext *pb = s->pb; AVStream *st; unsigned char *header; unsigned char scratch[VQA_PREAMBLE_SIZE]; @@ -223,7 +223,7 @@ static int wsvqa_read_header(AVFormatContext *s, /* initialize the video decoder stream */ st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 33, 1, VQA_FRAMERATE); wsvqa->video_stream_index = st->index; st->codec->codec_type = CODEC_TYPE_VIDEO; @@ -240,7 +240,7 @@ static int wsvqa_read_header(AVFormatContext *s, if (get_buffer(pb, st->codec->extradata, VQA_HEADER_SIZE) != VQA_HEADER_SIZE) { av_free(st->codec->extradata); - return AVERROR_IO; + return AVERROR(EIO); } st->codec->width = AV_RL16(&header[6]); st->codec->height = AV_RL16(&header[8]); @@ -249,7 +249,7 @@ static int wsvqa_read_header(AVFormatContext *s, if (AV_RL16(&header[24]) || (AV_RL16(&header[0]) == 1 && AV_RL16(&header[2]) == 1)) { st = av_new_stream(s, 0); if (!st) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); av_set_pts_info(st, 33, 1, VQA_FRAMERATE); st->codec->codec_type = CODEC_TYPE_AUDIO; if (AV_RL16(&header[0]) == 1) @@ -279,7 +279,7 @@ static int wsvqa_read_header(AVFormatContext *s, do { if (get_buffer(pb, scratch, VQA_PREAMBLE_SIZE) != VQA_PREAMBLE_SIZE) { av_free(st->codec->extradata); - return AVERROR_IO; + return AVERROR(EIO); } chunk_tag = AV_RB32(&scratch[0]); chunk_size = AV_RB32(&scratch[4]); @@ -314,8 +314,8 @@ static int wsvqa_read_header(AVFormatContext *s, static int wsvqa_read_packet(AVFormatContext *s, AVPacket *pkt) { - WsVqaDemuxContext *wsvqa = (WsVqaDemuxContext *)s->priv_data; - ByteIOContext *pb = &s->pb; + WsVqaDemuxContext *wsvqa = s->priv_data; + ByteIOContext *pb = s->pb; int ret = -1; unsigned char preamble[VQA_PREAMBLE_SIZE]; unsigned int chunk_type; @@ -330,11 +330,11 @@ static int wsvqa_read_packet(AVFormatContext *s, if ((chunk_type == SND1_TAG) || (chunk_type == SND2_TAG) || (chunk_type == VQFR_TAG)) { if (av_new_packet(pkt, chunk_size)) - return AVERROR_IO; + return AVERROR(EIO); ret = get_buffer(pb, pkt->data, chunk_size); if (ret != chunk_size) { av_free_packet(pkt); - return AVERROR_IO; + return AVERROR(EIO); } if (chunk_type == SND2_TAG) { @@ -371,7 +371,7 @@ static int wsvqa_read_packet(AVFormatContext *s, static int wsvqa_read_close(AVFormatContext *s) { -// WsVqaDemuxContext *wsvqa = (WsVqaDemuxContext *)s->priv_data; +// WsVqaDemuxContext *wsvqa = s->priv_data; return 0; } diff --git a/contrib/ffmpeg/libavformat/wv.c b/contrib/ffmpeg/libavformat/wv.c index ed1eefeea..2240dfde2 100644 --- a/contrib/ffmpeg/libavformat/wv.c +++ b/contrib/ffmpeg/libavformat/wv.c @@ -20,7 +20,6 @@ */ #include "avformat.h" -#include "allformats.h" #include "bswap.h" // specs say that maximum block size is 1Mb @@ -86,7 +85,7 @@ static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb) } wc->blksize = size; ver = get_le16(pb); - if(ver < 0x402 || ver > 0x40F){ + if(ver < 0x402 || ver > 0x410){ av_log(ctx, AV_LOG_ERROR, "Unsupported version %03X\n", ver); return -1; } @@ -105,10 +104,6 @@ static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb) av_log(ctx, AV_LOG_ERROR, "Hybrid coding mode is not supported\n"); return -1; } - if(wc->flags & WV_INT32){ - av_log(ctx, AV_LOG_ERROR, "Integer point data is not supported\n"); - return -1; - } bpp = ((wc->flags & 3) + 1) << 3; chan = 1 + !(wc->flags & WV_MONO); @@ -140,7 +135,7 @@ static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb) static int wv_read_header(AVFormatContext *s, AVFormatParameters *ap) { - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; WVContext *wc = s->priv_data; AVStream *st; @@ -169,20 +164,20 @@ static int wv_read_packet(AVFormatContext *s, WVContext *wc = s->priv_data; int ret; - if (url_feof(&s->pb)) + if (url_feof(s->pb)) return AVERROR(EIO); if(wc->block_parsed){ - if(wv_read_block_header(s, &s->pb) < 0) + if(wv_read_block_header(s, s->pb) < 0) return -1; } if(av_new_packet(pkt, wc->blksize + WV_EXTRA_SIZE) < 0) - return AVERROR_NOMEM; + return AVERROR(ENOMEM); memcpy(pkt->data, wc->extra, WV_EXTRA_SIZE); - ret = get_buffer(&s->pb, pkt->data + WV_EXTRA_SIZE, wc->blksize); + ret = get_buffer(s->pb, pkt->data + WV_EXTRA_SIZE, wc->blksize); if(ret != wc->blksize){ av_free_packet(pkt); - return AVERROR_IO; + return AVERROR(EIO); } pkt->stream_index = 0; wc->block_parsed = 1; @@ -209,18 +204,18 @@ static int wv_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, /* if found, seek there */ if (index >= 0){ wc->block_parsed = 1; - url_fseek(&s->pb, st->index_entries[index].pos, SEEK_SET); + url_fseek(s->pb, st->index_entries[index].pos, SEEK_SET); return 0; } /* if timestamp is out of bounds, return error */ if(timestamp < 0 || timestamp >= s->duration) return -1; - pos = url_ftell(&s->pb); + pos = url_ftell(s->pb); do{ ret = av_read_frame(s, pkt); if (ret < 0){ - url_fseek(&s->pb, pos, SEEK_SET); + url_fseek(s->pb, pos, SEEK_SET); return -1; } pts = pkt->pts; diff --git a/contrib/ffmpeg/libavformat/x11grab.c b/contrib/ffmpeg/libavformat/x11grab.c deleted file mode 100644 index 8916d799a..000000000 --- a/contrib/ffmpeg/libavformat/x11grab.c +++ /dev/null @@ -1,529 +0,0 @@ -/* - * X11 video grab interface - * - * This file is part of FFmpeg. - * - * FFmpeg integration: - * Copyright (C) 2006 Clemens Fruhwirth - * Edouard Gomez - * - * This file contains code from grab.c: - * Copyright (c) 2000-2001 Fabrice Bellard - * - * This file contains code from the xvidcap project: - * Copyright (C) 1997-1998 Rasca, Berlin - * 2003-2004 Karl H. Beckers, Frankfurt - * - * FFmpeg is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * FFmpeg 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with FFmpeg; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -/** - * @file x11grab.c - * X11 frame device demuxer by Clemens Fruhwirth - * and Edouard Gomez . - */ - -#include "avformat.h" -#include -#include -#include -#include -#include -#define _LINUX_TIME_H 1 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/** - * X11 Device Demuxer context - */ -typedef struct x11_grab_s -{ - int frame_size; /**< Size in bytes of a grabbed frame */ - AVRational time_base; /**< Time base */ - int64_t time_frame; /**< Current time */ - - int height; /**< Height of the grab frame */ - int width; /**< Width of the grab frame */ - int x_off; /**< Horizontal top-left corner coordinate */ - int y_off; /**< Vertical top-left corner coordinate */ - - Display *dpy; /**< X11 display from which x11grab grabs frames */ - XImage *image; /**< X11 image holding the grab */ - int use_shm; /**< !0 when using XShm extension */ - XShmSegmentInfo shminfo; /**< When using XShm, keeps track of XShm infos */ - int mouse_warning_shown; -} x11_grab_t; - -/** - * Initializes the x11 grab device demuxer (public device demuxer API). - * - * @param s1 Context from avformat core - * @param ap Parameters from avformat core - * @return
    - *
  • ENOMEM no memory left
  • - *
  • AVERROR_IO other failure case
  • - *
  • 0 success
  • - *
- */ -static int -x11grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) -{ - x11_grab_t *x11grab = s1->priv_data; - Display *dpy; - AVStream *st = NULL; - int input_pixfmt; - XImage *image; - int x_off = 0; - int y_off = 0; - int use_shm; - char *param, *offset; - - param = av_strdup(s1->filename); - offset = strchr(param, '+'); - if (offset) { - sscanf(offset, "%d,%d", &x_off, &y_off); - *offset= 0; - } - - av_log(s1, AV_LOG_INFO, "device: %s -> display: %s x: %d y: %d width: %d height: %d\n", s1->filename, param, x_off, y_off, ap->width, ap->height); - - dpy = XOpenDisplay(param); - if(!dpy) { - av_log(s1, AV_LOG_ERROR, "Could not open X display.\n"); - return AVERROR_IO; - } - - if (!ap || ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) { - av_log(s1, AV_LOG_ERROR, "AVParameters don't have any video size. Use -s.\n"); - return AVERROR_IO; - } - - st = av_new_stream(s1, 0); - if (!st) { - return AVERROR(ENOMEM); - } - av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ - - use_shm = XShmQueryExtension(dpy); - av_log(s1, AV_LOG_INFO, "shared memory extension %s found\n", use_shm ? "" : "not"); - - if(use_shm) { - int scr = XDefaultScreen(dpy); - image = XShmCreateImage(dpy, - DefaultVisual(dpy, scr), - DefaultDepth(dpy, scr), - ZPixmap, - NULL, - &x11grab->shminfo, - ap->width, ap->height); - x11grab->shminfo.shmid = shmget(IPC_PRIVATE, - image->bytes_per_line * image->height, - IPC_CREAT|0777); - if (x11grab->shminfo.shmid == -1) { - av_log(s1, AV_LOG_ERROR, "Fatal: Can't get shared memory!\n"); - return AVERROR(ENOMEM); - } - x11grab->shminfo.shmaddr = image->data = shmat(x11grab->shminfo.shmid, 0, 0); - x11grab->shminfo.readOnly = False; - - if (!XShmAttach(dpy, &x11grab->shminfo)) { - av_log(s1, AV_LOG_ERROR, "Fatal: Failed to attach shared memory!\n"); - /* needs some better error subroutine :) */ - return AVERROR_IO; - } - } else { - image = XGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), - x_off,y_off, - ap->width,ap->height, - AllPlanes, ZPixmap); - } - - switch (image->bits_per_pixel) { - case 8: - av_log (s1, AV_LOG_DEBUG, "8 bit palette\n"); - input_pixfmt = PIX_FMT_PAL8; - break; - case 16: - if ( image->red_mask == 0xf800 && - image->green_mask == 0x07e0 && - image->blue_mask == 0x001f ) { - av_log (s1, AV_LOG_DEBUG, "16 bit RGB565\n"); - input_pixfmt = PIX_FMT_RGB565; - } else if (image->red_mask == 0x7c00 && - image->green_mask == 0x03e0 && - image->blue_mask == 0x001f ) { - av_log(s1, AV_LOG_DEBUG, "16 bit RGB555\n"); - input_pixfmt = PIX_FMT_RGB555; - } else { - av_log(s1, AV_LOG_ERROR, "RGB ordering at image depth %i not supported ... aborting\n", image->bits_per_pixel); - av_log(s1, AV_LOG_ERROR, "color masks: r 0x%.6lx g 0x%.6lx b 0x%.6lx\n", image->red_mask, image->green_mask, image->blue_mask); - return AVERROR_IO; - } - break; - case 24: - if ( image->red_mask == 0xff0000 && - image->green_mask == 0x00ff00 && - image->blue_mask == 0x0000ff ) { - input_pixfmt = PIX_FMT_BGR24; - } else if ( image->red_mask == 0x0000ff && - image->green_mask == 0x00ff00 && - image->blue_mask == 0xff0000 ) { - input_pixfmt = PIX_FMT_RGB24; - } else { - av_log(s1, AV_LOG_ERROR,"rgb ordering at image depth %i not supported ... aborting\n", image->bits_per_pixel); - av_log(s1, AV_LOG_ERROR, "color masks: r 0x%.6lx g 0x%.6lx b 0x%.6lx\n", image->red_mask, image->green_mask, image->blue_mask); - return AVERROR_IO; - } - break; - case 32: -#if 0 - GetColorInfo (image, &c_info); - if ( c_info.alpha_mask == 0xff000000 && image->green_mask == 0x0000ff00) { - /* byte order is relevant here, not endianness - * endianness is handled by avcodec, but atm no such thing - * as having ABGR, instead of ARGB in a word. Since we - * need this for Solaris/SPARC, but need to do the conversion - * for every frame we do it outside of this loop, cf. below - * this matches both ARGB32 and ABGR32 */ - input_pixfmt = PIX_FMT_ARGB32; - } else { - av_log(s1, AV_LOG_ERROR,"image depth %i not supported ... aborting\n", image->bits_per_pixel); - return AVERROR_IO; - } -#endif - input_pixfmt = PIX_FMT_RGB32; - break; - default: - av_log(s1, AV_LOG_ERROR, "image depth %i not supported ... aborting\n", image->bits_per_pixel); - return -1; - } - - x11grab->frame_size = ap->width * ap->height * image->bits_per_pixel/8; - x11grab->dpy = dpy; - x11grab->width = ap->width; - x11grab->height = ap->height; - x11grab->time_base = ap->time_base; - x11grab->time_frame = av_gettime() / av_q2d(ap->time_base); - x11grab->x_off = x_off; - x11grab->y_off = y_off; - x11grab->image = image; - x11grab->use_shm = use_shm; - x11grab->mouse_warning_shown = 0; - - st->codec->codec_type = CODEC_TYPE_VIDEO; - st->codec->codec_id = CODEC_ID_RAWVIDEO; - st->codec->width = ap->width; - st->codec->height = ap->height; - st->codec->pix_fmt = input_pixfmt; - st->codec->time_base = ap->time_base; - st->codec->bit_rate = x11grab->frame_size * 1/av_q2d(ap->time_base) * 8; - - return 0; -} - -/** - * Get pointer coordinates from X11. - * - * @param x Integer where horizontal coordinate will be returned - * @param y Integer where vertical coordinate will be returned - * @param dpy X11 display from where pointer coordinates are retrieved - * @param s1 Context used for logging errors if necessary - */ -static void -get_pointer_coordinates(int *x, int *y, Display *dpy, AVFormatContext *s1) -{ - Window mrootwindow, childwindow; - int dummy; - - mrootwindow = DefaultRootWindow(dpy); - - if (XQueryPointer(dpy, mrootwindow, &mrootwindow, &childwindow, - x, y, &dummy, &dummy, (unsigned int*)&dummy)) { - } else { - x11_grab_t *s = s1->priv_data; - if (!s->mouse_warning_shown) { - av_log(s1, AV_LOG_INFO, "couldn't find mouse pointer\n"); - s->mouse_warning_shown = 1; - } - *x = -1; - *y = -1; - } -} - -/** - * Mouse painting helper function that applies an 'and' and 'or' mask pair to - * '*dst' pixel. It actually draws a mouse pointer pixel to grabbed frame. - * - * @param dst Destination pixel - * @param and Part of the mask that must be applied using a bitwise 'and' - * operator - * @param or Part of the mask that must be applied using a bitwise 'or' - * operator - * @param bits_per_pixel Bits per pixel used in the grabbed image - */ -static void inline -apply_masks(uint8_t *dst, int and, int or, int bits_per_pixel) -{ - switch (bits_per_pixel) { - case 32: - *(uint32_t*)dst = (*(uint32_t*)dst & and) | or; - break; - case 16: - *(uint16_t*)dst = (*(uint16_t*)dst & and) | or; - break; - case 8: - *dst = !!or; - break; - } -} - -/** - * Paints a mouse pointer in an X11 image. - * - * @param image Image where to paint the mouse pointer - * @param s context used to retrieve original grabbing rectangle - * coordinates - * @param x Mouse pointer coordinate - * @param y Mouse pointer coordinate - */ -static void -paint_mouse_pointer(XImage *image, x11_grab_t *s, int x, int y) -{ - /* 16x20x1bpp bitmap for the black channel of the mouse pointer */ - static const uint16_t const mousePointerBlack[] = - { - 0x0000, 0x0003, 0x0005, 0x0009, 0x0011, - 0x0021, 0x0041, 0x0081, 0x0101, 0x0201, - 0x03c1, 0x0049, 0x0095, 0x0093, 0x0120, - 0x0120, 0x0240, 0x0240, 0x0380, 0x0000 - }; - - /* 16x20x1bpp bitmap for the white channel of the mouse pointer */ - static const uint16_t const mousePointerWhite[] = - { - 0x0000, 0x0000, 0x0002, 0x0006, 0x000e, - 0x001e, 0x003e, 0x007e, 0x00fe, 0x01fe, - 0x003e, 0x0036, 0x0062, 0x0060, 0x00c0, - 0x00c0, 0x0180, 0x0180, 0x0000, 0x0000 - }; - - int x_off = s->x_off; - int y_off = s->y_off; - int width = s->width; - int height = s->height; - - if ( x - x_off >= 0 && x < width + x_off - && y - y_off >= 0 && y < height + y_off) { - uint8_t *im_data = (uint8_t*)image->data; - int bytes_per_pixel; - int line; - int masks; - - /* Select correct masks and pixel size */ - if (image->bits_per_pixel == 8) { - masks = 1; - } else { - masks = (image->red_mask|image->green_mask|image->blue_mask); - } - bytes_per_pixel = image->bits_per_pixel>>3; - - /* Shift to right line */ - im_data += image->bytes_per_line * (y - y_off); - /* Shift to right pixel in the line */ - im_data += bytes_per_pixel * (x - x_off); - - /* Draw the cursor - proper loop */ - for (line = 0; line < FFMIN(20, (y_off + height) - y); line++) { - uint8_t *cursor = im_data; - int column; - uint16_t bm_b; - uint16_t bm_w; - - bm_b = mousePointerBlack[line]; - bm_w = mousePointerWhite[line]; - - for (column = 0; column < FFMIN(16, (x_off + width) - x); column++) { - apply_masks(cursor, ~(masks*(bm_b&1)), masks*(bm_w&1), - image->bits_per_pixel); - cursor += bytes_per_pixel; - bm_b >>= 1; - bm_w >>= 1; - } - im_data += image->bytes_per_line; - } - } -} - - -/** - * Reads new data in the image structure. - * - * @param dpy X11 display to grab from - * @param d - * @param image Image where the grab will be put - * @param x Top-Left grabbing rectangle horizontal coordinate - * @param y Top-Left grabbing rectangle vertical coordinate - * @return 0 if error, !0 if successful - */ -static int -xget_zpixmap(Display *dpy, Drawable d, XImage *image, int x, int y) -{ - xGetImageReply rep; - xGetImageReq *req; - long nbytes; - - if (!image) { - return 0; - } - - LockDisplay(dpy); - GetReq(GetImage, req); - - /* First set up the standard stuff in the request */ - req->drawable = d; - req->x = x; - req->y = y; - req->width = image->width; - req->height = image->height; - req->planeMask = (unsigned int)AllPlanes; - req->format = ZPixmap; - - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse) || !rep.length) { - UnlockDisplay(dpy); - SyncHandle(); - return 0; - } - - nbytes = (long)rep.length << 2; - _XReadPad(dpy, image->data, nbytes); - - UnlockDisplay(dpy); - SyncHandle(); - return 1; -} - -/** - * Grabs a frame from x11 (public device demuxer API). - * - * @param s1 Context from avformat core - * @param pkt Packet holding the brabbed frame - * @return frame size in bytes - */ -static int -x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt) -{ - x11_grab_t *s = s1->priv_data; - Display *dpy = s->dpy; - XImage *image = s->image; - int x_off = s->x_off; - int y_off = s->y_off; - - int64_t curtime, delay; - struct timespec ts; - - /* Calculate the time of the next frame */ - s->time_frame += INT64_C(1000000); - - /* wait based on the frame rate */ - for(;;) { - curtime = av_gettime(); - delay = s->time_frame * av_q2d(s->time_base) - curtime; - if (delay <= 0) { - if (delay < INT64_C(-1000000) * av_q2d(s->time_base)) { - s->time_frame += INT64_C(1000000); - } - break; - } - ts.tv_sec = delay / 1000000; - ts.tv_nsec = (delay % 1000000) * 1000; - nanosleep(&ts, NULL); - } - - if (av_new_packet(pkt, s->frame_size) < 0) { - return AVERROR_IO; - } - - pkt->pts = curtime; - - if(s->use_shm) { - if (!XShmGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, x_off, y_off, AllPlanes)) { - av_log (s1, AV_LOG_INFO, "XShmGetImage() failed\n"); - } - } else { - if (!xget_zpixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, x_off, y_off)) { - av_log (s1, AV_LOG_INFO, "XGetZPixmap() failed\n"); - } - } - - { - int pointer_x, pointer_y; - get_pointer_coordinates(&pointer_x, &pointer_y, dpy, s1); - paint_mouse_pointer(image, s, pointer_x, pointer_y); - } - - - /* XXX: avoid memcpy */ - memcpy(pkt->data, image->data, s->frame_size); - return s->frame_size; -} - -/** - * Closes x11 frame grabber (public device demuxer API). - * - * @param s1 Context from avformat core - * @return 0 success, !0 failure - */ -static int -x11grab_read_close(AVFormatContext *s1) -{ - x11_grab_t *x11grab = s1->priv_data; - - /* Detach cleanly from shared mem */ - if (x11grab->use_shm) { - XShmDetach(x11grab->dpy, &x11grab->shminfo); - shmdt(x11grab->shminfo.shmaddr); - shmctl(x11grab->shminfo.shmid, IPC_RMID, NULL); - } - - /* Destroy X11 image */ - if (x11grab->image) { - XDestroyImage(x11grab->image); - x11grab->image = NULL; - } - - /* Free X11 display */ - XCloseDisplay(x11grab->dpy); - return 0; -} - -/** x11 grabber device demuxer declaration */ -AVInputFormat x11_grab_device_demuxer = -{ - "x11grab", - "X11grab", - sizeof(x11_grab_t), - NULL, - x11grab_read_header, - x11grab_read_packet, - x11grab_read_close, - .flags = AVFMT_NOFILE, -}; diff --git a/contrib/ffmpeg/libavformat/yuv4mpeg.c b/contrib/ffmpeg/libavformat/yuv4mpeg.c index 70214ae00..7913e417a 100644 --- a/contrib/ffmpeg/libavformat/yuv4mpeg.c +++ b/contrib/ffmpeg/libavformat/yuv4mpeg.c @@ -87,7 +87,7 @@ static int yuv4_generate_header(AVFormatContext *s, char* buf) static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt) { AVStream *st = s->streams[pkt->stream_index]; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; AVPicture *picture; int* first_pkt = s->priv_data; int width, height, h_chroma_shift, v_chroma_shift; @@ -103,7 +103,7 @@ static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt) *first_pkt = 0; if (yuv4_generate_header(s, buf2) < 0) { av_log(s, AV_LOG_ERROR, "Error. YUV4MPEG stream header write failed.\n"); - return AVERROR_IO; + return AVERROR(EIO); } else { put_buffer(pb, buf2, strlen(buf2)); } @@ -149,7 +149,7 @@ static int yuv4_write_header(AVFormatContext *s) int* first_pkt = s->priv_data; if (s->nb_streams != 1) - return AVERROR_IO; + return AVERROR(EIO); if (s->streams[0]->codec->pix_fmt == PIX_FMT_YUV411P) { av_log(s, AV_LOG_ERROR, "Warning: generating rarely used 4:1:1 YUV stream, some mjpegtools might not work.\n"); @@ -159,18 +159,13 @@ static int yuv4_write_header(AVFormatContext *s) (s->streams[0]->codec->pix_fmt != PIX_FMT_GRAY8) && (s->streams[0]->codec->pix_fmt != PIX_FMT_YUV444P)) { av_log(s, AV_LOG_ERROR, "ERROR: yuv4mpeg only handles yuv444p, yuv422p, yuv420p, yuv411p and gray pixel formats. Use -pix_fmt to select one.\n"); - return AVERROR_IO; + return AVERROR(EIO); } *first_pkt = 1; return 0; } -static int yuv4_write_trailer(AVFormatContext *s) -{ - return 0; -} - #ifdef CONFIG_YUV4MPEGPIPE_MUXER AVOutputFormat yuv4mpegpipe_muxer = { "yuv4mpegpipe", @@ -182,7 +177,6 @@ AVOutputFormat yuv4mpegpipe_muxer = { CODEC_ID_RAWVIDEO, yuv4_write_header, yuv4_write_packet, - yuv4_write_trailer, .flags = AVFMT_RAWPICTURE, }; #endif @@ -196,7 +190,7 @@ static int yuv4_read_header(AVFormatContext *s, AVFormatParameters *ap) char header[MAX_YUV4_HEADER+10]; // Include headroom for the longest option char *tokstart,*tokend,*header_end; int i; - ByteIOContext *pb = &s->pb; + ByteIOContext *pb = s->pb; int width=-1, height=-1, raten=0, rated=0, aspectn=0, aspectd=0; enum PixelFormat pix_fmt=PIX_FMT_NONE,alt_pix_fmt=PIX_FMT_NONE; AVStream *st; @@ -350,7 +344,7 @@ static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt) struct frame_attributes *s1 = s->priv_data; for (i=0; ipb); + header[i] = get_byte(s->pb); if (header[i] == '\n') { header[i+1] = 0; break; @@ -366,8 +360,8 @@ static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt) if (packet_size < 0) return -1; - if (av_get_packet(&s->pb, pkt, packet_size) != packet_size) - return AVERROR_IO; + if (av_get_packet(s->pb, pkt, packet_size) != packet_size) + return AVERROR(EIO); if (s->streams[0]->codec->coded_frame) { s->streams[0]->codec->coded_frame->interlaced_frame = s1->interlaced_frame; @@ -386,8 +380,6 @@ static int yuv4_read_close(AVFormatContext *s) static int yuv4_probe(AVProbeData *pd) { /* check file header */ - if (pd->buf_size <= sizeof(Y4M_MAGIC)) - return 0; if (strncmp(pd->buf, Y4M_MAGIC, sizeof(Y4M_MAGIC)-1)==0) return AVPROBE_SCORE_MAX; else diff --git a/contrib/ffmpeg/libavutil/Makefile b/contrib/ffmpeg/libavutil/Makefile index a760401ab..0cf55f50f 100644 --- a/contrib/ffmpeg/libavutil/Makefile +++ b/contrib/ffmpeg/libavutil/Makefile @@ -1,27 +1,51 @@ include ../config.mak -OBJS= mathematics.o \ - rational.o \ - intfloat_readwrite.o \ - crc.o \ - md5.o \ - lls.o \ - adler32.o \ - log.o \ - mem.o \ - fifo.o \ - tree.o \ - lzo.o \ - random.o \ - aes.o \ - base64.o \ +OBJS = adler32.o \ + aes.o \ + base64.o \ + crc.o \ + des.o \ + fifo.o \ + intfloat_readwrite.o \ + lls.o \ + log.o \ + lzo.o \ + mathematics.o \ + md5.o \ + mem.o \ + random.o \ + rational.o \ + rc4.o \ + sha1.o \ + string.o \ + tree.o \ -HEADERS = avutil.h common.h mathematics.h integer.h rational.h \ - intfloat_readwrite.h md5.h adler32.h log.h fifo.h lzo.h \ - random.h mem.h base64.h +HEADERS = adler32.h \ + avstring.h \ + avutil.h \ + base64.h \ + common.h \ + crc.h \ + fifo.h \ + intfloat_readwrite.h \ + log.h \ + lzo.h \ + mathematics.h \ + md5.h \ + mem.h \ + random.h \ + rational.h \ + sha1.h NAME=avutil LIBVERSION=$(LAVUVERSION) LIBMAJOR=$(LAVUMAJOR) +TESTS = $(addsuffix -test$(EXESUF), adler32 aes crc des lls md5 sha1 softfloat tree) + include ../common.mak + +lzo-test$(EXESUF): EXTRALIBS += -llzo2 + +clean:: + rm -f lzo-test$(EXESUF) diff --git a/contrib/ffmpeg/libavutil/adler32.c b/contrib/ffmpeg/libavutil/adler32.c index 50d57470b..148664e53 100644 --- a/contrib/ffmpeg/libavutil/adler32.c +++ b/contrib/ffmpeg/libavutil/adler32.c @@ -18,7 +18,6 @@ * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. - * */ #include "common.h" @@ -55,7 +54,7 @@ unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigne #include "log.h" #define LEN 7001 volatile int checksum; -int main(){ +int main(void){ int i; char data[LEN]; av_log_level = AV_LOG_DEBUG; @@ -67,5 +66,6 @@ int main(){ STOP_TIMER("adler") } av_log(NULL, AV_LOG_DEBUG, "%X == 50E6E508\n", checksum); + return 0; } #endif diff --git a/contrib/ffmpeg/libavutil/adler32.h b/contrib/ffmpeg/libavutil/adler32.h index f56d416fb..2e29e05b2 100644 --- a/contrib/ffmpeg/libavutil/adler32.h +++ b/contrib/ffmpeg/libavutil/adler32.h @@ -18,10 +18,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef ADLER32_H -#define ADLER32_H +#ifndef FFMPEG_ADLER32_H +#define FFMPEG_ADLER32_H + +#include unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigned int len); -#endif +#endif /* FFMPEG_ADLER32_H */ diff --git a/contrib/ffmpeg/libavutil/aes.c b/contrib/ffmpeg/libavutil/aes.c index 55ae0d4f3..5030dac48 100644 --- a/contrib/ffmpeg/libavutil/aes.c +++ b/contrib/ffmpeg/libavutil/aes.c @@ -1,6 +1,8 @@ /* * copyright (c) 2007 Michael Niedermayer * + * some optimization ideas from aes128.c by Reimar Doeffinger + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -16,14 +18,14 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * some optimization ideas from aes128.c by Reimar Doeffinger */ #include "common.h" #include "aes.h" typedef struct AVAES{ + // Note: round_key[16] is accessed in the init code, but this only + // overwrites state, which does not matter (see also r7471). uint8_t round_key[15][4][4]; uint8_t state[2][4][4]; int rounds; @@ -128,7 +130,7 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) { uint8_t log8[256]; uint8_t alog8[512]; - if(!enc_multbl[4][1023]){ + if(!enc_multbl[0][sizeof(enc_multbl)/sizeof(enc_multbl[0][0])-1]){ j=1; for(i=0; i<255; i++){ alog8[i]= @@ -192,7 +194,9 @@ int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) { #ifdef TEST #include "log.h" -int main(){ +#undef random + +int main(void){ int i,j; AVAES ae, ad, b; uint8_t rkey[2][16]= { diff --git a/contrib/ffmpeg/libavutil/aes.h b/contrib/ffmpeg/libavutil/aes.h index 34ba0a2fa..438ba170e 100644 --- a/contrib/ffmpeg/libavutil/aes.h +++ b/contrib/ffmpeg/libavutil/aes.h @@ -18,15 +18,17 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AES_H -#define AES_H +#ifndef FFMPEG_AES_H +#define FFMPEG_AES_H + +#include extern const int av_aes_size; struct AVAES; /** - * initalizes a AVAES context + * initializes an AVAES context * @param key_bits 128, 192 or 256 * @param decrypt 0 for encryption, 1 for decryption */ @@ -37,9 +39,9 @@ int av_aes_init(struct AVAES *a, const uint8_t *key, int key_bits, int decrypt); * @param count number of 16 byte blocks * @param dst destination array, can be equal to src * @param src source array, can be equal to dst - * @param iv initalization vector for CBC mode, if NULL then ECB will be used + * @param iv initialization vector for CBC mode, if NULL then ECB will be used * @param decrypt 0 for encryption, 1 for decryption */ void av_aes_crypt(struct AVAES *a, uint8_t *dst, uint8_t *src, int count, uint8_t *iv, int decrypt); -#endif /* AES_H */ +#endif /* FFMPEG_AES_H */ diff --git a/contrib/ffmpeg/libavutil/avstring.h b/contrib/ffmpeg/libavutil/avstring.h new file mode 100644 index 000000000..ecac9e623 --- /dev/null +++ b/contrib/ffmpeg/libavutil/avstring.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2007 Mans Rullgard + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_AVSTRING_H +#define FFMPEG_AVSTRING_H + +#include + +/** + * Return non-zero if pfx is a prefix of str. If it is, *ptr is set to + * the address of the first character in str after the prefix. + * + * @param str input string + * @param pfx prefix to test + * @param ptr updated after the prefix in str in there is a match + * @return non-zero if the prefix matches, zero otherwise + */ +int av_strstart(const char *str, const char *pfx, const char **ptr); + +/** + * Return non-zero if pfx is a prefix of str independent of case. If + * it is, *ptr is set to the address of the first character in str + * after the prefix. + * + * @param str input string + * @param pfx prefix to test + * @param ptr updated after the prefix in str in there is a match + * @return non-zero if the prefix matches, zero otherwise + */ +int av_stristart(const char *str, const char *pfx, const char **ptr); + +/** + * Copy the string src to dst, but no more than size - 1 bytes, and + * null terminate dst. + * + * This function is the same as BSD strlcpy(). + * + * @param dst destination buffer + * @param src source string + * @param size size of destination buffer + * @return the length of src + */ +size_t av_strlcpy(char *dst, const char *src, size_t size); + +/** + * Append the string src to the string dst, but to a total length of + * no more than size - 1 bytes, and null terminate dst. + * + * This function is similar to BSD strlcat(), but differs when + * size <= strlen(dst). + * + * @param dst destination buffer + * @param src source string + * @param size size of destination buffer + * @return the total length of src and dst + */ +size_t av_strlcat(char *dst, const char *src, size_t size); + +/** + * Append output to a string, according to a format. Never write out of + * the destination buffer, and and always put a terminating 0 within + * the buffer. + * @param dst destination buffer (string to which the output is + * appended) + * @param size total size of the destination buffer + * @param fmt printf-compatible format string, specifying how the + * following parameters are used + * @return the length of the string that would have been generated + * if enough space had been available + */ +size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...); + +#endif /* FFMPEG_AVSTRING_H */ diff --git a/contrib/ffmpeg/libavutil/avutil.h b/contrib/ffmpeg/libavutil/avutil.h index 32bc40bfb..3d2bd4be2 100644 --- a/contrib/ffmpeg/libavutil/avutil.h +++ b/contrib/ffmpeg/libavutil/avutil.h @@ -18,8 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVUTIL_H -#define AVUTIL_H +#ifndef FFMPEG_AVUTIL_H +#define FFMPEG_AVUTIL_H /** * @file avutil.h @@ -27,15 +27,23 @@ */ -#ifdef __cplusplus -extern "C" { -#endif - #define AV_STRINGIFY(s) AV_TOSTRING(s) #define AV_TOSTRING(s) #s -#define LIBAVUTIL_VERSION_INT ((49<<16)+(4<<8)+0) -#define LIBAVUTIL_VERSION 49.4.0 +#define AV_VERSION_INT(a, b, c) (a<<16 | b<<8 | c) +#define AV_VERSION_DOT(a, b, c) a ##.## b ##.## c +#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c) + +#define LIBAVUTIL_VERSION_MAJOR 49 +#define LIBAVUTIL_VERSION_MINOR 6 +#define LIBAVUTIL_VERSION_MICRO 0 + +#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ + LIBAVUTIL_VERSION_MINOR, \ + LIBAVUTIL_VERSION_MICRO) +#define LIBAVUTIL_VERSION AV_VERSION(LIBAVUTIL_VERSION_MAJOR, \ + LIBAVUTIL_VERSION_MINOR, \ + LIBAVUTIL_VERSION_MICRO) #define LIBAVUTIL_BUILD LIBAVUTIL_VERSION_INT #define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION) @@ -44,7 +52,6 @@ extern "C" { #include "common.h" #include "mathematics.h" #include "rational.h" -#include "integer.h" #include "intfloat_readwrite.h" #include "log.h" @@ -80,8 +87,8 @@ enum PixelFormat { PIX_FMT_RGB565, ///< Packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), in cpu endianness PIX_FMT_RGB555, ///< Packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), in cpu endianness most significant bit to 0 PIX_FMT_GRAY8, ///< Y , 8bpp - PIX_FMT_MONOWHITE, ///< Y , 1bpp, 1 is white - PIX_FMT_MONOBLACK, ///< Y , 1bpp, 0 is black + PIX_FMT_MONOWHITE, ///< Y , 1bpp, 0 is white, 1 is black + PIX_FMT_MONOBLACK, ///< Y , 1bpp, 0 is black, 1 is white PIX_FMT_PAL8, ///< 8 bit with PIX_FMT_RGB32 palette PIX_FMT_YUVJ420P, ///< Planar YUV 4:2:0, 12bpp, full scale (jpeg) PIX_FMT_YUVJ422P, ///< Planar YUV 4:2:2, 16bpp, full scale (jpeg) @@ -107,6 +114,9 @@ enum PixelFormat { PIX_FMT_GRAY16BE, ///< Y , 16bpp, big-endian PIX_FMT_GRAY16LE, ///< Y , 16bpp, little-endian + PIX_FMT_YUV440P, ///< Planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples) + PIX_FMT_YUVJ440P, ///< Planar YUV 4:4:0 full scale (jpeg) + PIX_FMT_YUVA420P, ///< Planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples) PIX_FMT_NB, ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions }; @@ -130,8 +140,4 @@ enum PixelFormat { #define PIX_FMT_YUV422 PIX_FMT_YUYV422 #endif -#ifdef __cplusplus -} -#endif - -#endif /* AVUTIL_H */ +#endif /* FFMPEG_AVUTIL_H */ diff --git a/contrib/ffmpeg/libavutil/base64.c b/contrib/ffmpeg/libavutil/base64.c index bee800c82..8567c9924 100644 --- a/contrib/ffmpeg/libavutil/base64.c +++ b/contrib/ffmpeg/libavutil/base64.c @@ -29,7 +29,7 @@ #include "base64.h" /* ---------------- private code */ -static uint8_t map2[] = +static const uint8_t map2[] = { 0x3e, 0xff, 0xff, 0xff, 0x3f, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0xff, @@ -70,7 +70,7 @@ int av_base64_decode(uint8_t * out, const char *in, int out_length) * fixed edge cases and made it work from data (vs. strings) by ryan. *****************************************************************************/ -char *av_base64_encode(char * buf, int buf_len, uint8_t * src, int len) +char *av_base64_encode(char * buf, int buf_len, const uint8_t * src, int len) { static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -83,20 +83,18 @@ char *av_base64_encode(char * buf, int buf_len, uint8_t * src, int len) buf_len < len * 4 / 3 + 12) return NULL; ret = dst = buf; - if (len) { // special edge case, what should we really do here? - while (bytes_remaining) { - i_bits = (i_bits << 8) + *src++; - bytes_remaining--; - i_shift += 8; - - do { - *dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f]; - i_shift -= 6; - } while (i_shift > 6 || (bytes_remaining == 0 && i_shift > 0)); - } - while ((dst - ret) & 3) - *dst++ = '='; + while (bytes_remaining) { + i_bits = (i_bits << 8) + *src++; + bytes_remaining--; + i_shift += 8; + + do { + *dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f]; + i_shift -= 6; + } while (i_shift > 6 || (bytes_remaining == 0 && i_shift > 0)); } + while ((dst - ret) & 3) + *dst++ = '='; *dst = '\0'; return ret; diff --git a/contrib/ffmpeg/libavutil/base64.h b/contrib/ffmpeg/libavutil/base64.h index 3d905313c..e95e4ea3e 100644 --- a/contrib/ffmpeg/libavutil/base64.h +++ b/contrib/ffmpeg/libavutil/base64.h @@ -19,6 +19,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef FFMPEG_BASE64_H +#define FFMPEG_BASE64_H + +#include + /** * decodes base64 * param order as strncpy() @@ -30,5 +35,6 @@ int av_base64_decode(uint8_t * out, const char *in, int out_length); * @param src data, not a string * @param buf output string */ -char *av_base64_encode(char * buf, int buf_len, uint8_t * src, int len); +char *av_base64_encode(char * buf, int buf_len, const uint8_t * src, int len); +#endif /* FFMPEG_BASE64_H */ diff --git a/contrib/ffmpeg/libavutil/bswap.h b/contrib/ffmpeg/libavutil/bswap.h index 03d613db2..ee75f88c3 100644 --- a/contrib/ffmpeg/libavutil/bswap.h +++ b/contrib/ffmpeg/libavutil/bswap.h @@ -23,8 +23,11 @@ * byte swap. */ -#ifndef __BSWAP_H__ -#define __BSWAP_H__ +#ifndef FFMPEG_BSWAP_H +#define FFMPEG_BSWAP_H + +#include +#include "common.h" #ifdef HAVE_BYTESWAP_H #include @@ -36,101 +39,58 @@ # define LEGACY_REGS "=q" #endif -#if defined(ARCH_X86) static av_always_inline uint16_t bswap_16(uint16_t x) { - __asm("rorw $8, %0" : - LEGACY_REGS (x) : - "0" (x)); +#if defined(ARCH_X86) + __asm("rorw $8, %0" : + LEGACY_REGS (x) : + "0" (x)); +#elif defined(ARCH_SH4) + __asm__("swap.b %0,%0":"=r"(x):"0"(x)); +#else + x= (x>>8) | (x<<8); +#endif return x; } static av_always_inline uint32_t bswap_32(uint32_t x) { +#if defined(ARCH_X86) #if __CPU__ != 386 - __asm("bswap %0": - "=r" (x) : + __asm("bswap %0": + "=r" (x) : #else - __asm("xchgb %b0,%h0\n" - " rorl $16,%0\n" - " xchgb %b0,%h0": - LEGACY_REGS (x) : + __asm("xchgb %b0,%h0\n" + "rorl $16,%0 \n" + "xchgb %b0,%h0": + LEGACY_REGS (x) : #endif - "0" (x)); - return x; -} - -static inline uint64_t bswap_64(uint64_t x) -{ -#ifdef ARCH_X86_64 - __asm("bswap %0": - "=r" (x) : - "0" (x)); - return x; -#else - union { - uint64_t ll; - struct { - uint32_t l,h; - } l; - } r; - r.l.l = bswap_32 (x); - r.l.h = bswap_32 (x>>32); - return r.ll; -#endif -} - + "0" (x)); #elif defined(ARCH_SH4) - -static av_always_inline uint16_t bswap_16(uint16_t x) { - __asm__("swap.b %0,%0":"=r"(x):"0"(x)); - return x; -} - -static av_always_inline uint32_t bswap_32(uint32_t x) { - __asm__( - "swap.b %0,%0\n" - "swap.w %0,%0\n" - "swap.b %0,%0\n" - :"=r"(x):"0"(x)); - return x; -} - -static inline uint64_t bswap_64(uint64_t x) -{ - union { - uint64_t ll; - struct { - uint32_t l,h; - } l; - } r; - r.l.l = bswap_32 (x); - r.l.h = bswap_32 (x>>32); - return r.ll; -} -#else - -static av_always_inline uint16_t bswap_16(uint16_t x){ - return (x>>8) | (x<<8); -} - -#ifdef ARCH_ARM -static av_always_inline uint32_t bswap_32(uint32_t x){ + __asm__("swap.b %0,%0\n" + "swap.w %0,%0\n" + "swap.b %0,%0\n" + :"=r"(x):"0"(x)); +#elif defined(ARCH_ARM) uint32_t t; - __asm__ ( - "eor %1, %0, %0, ror #16 \n\t" - "bic %1, %1, #0xFF0000 \n\t" - "mov %0, %0, ror #8 \n\t" - "eor %0, %0, %1, lsr #8 \n\t" - : "+r"(x), "+r"(t)); - return x; -} + __asm__ ("eor %1, %0, %0, ror #16 \n\t" + "bic %1, %1, #0xFF0000 \n\t" + "mov %0, %0, ror #8 \n\t" + "eor %0, %0, %1, lsr #8 \n\t" + : "+r"(x), "+r"(t)); +#elif defined(ARCH_BFIN) + unsigned tmp; + asm("%1 = %0 >> 8 (V); \n\t" + "%0 = %0 << 8 (V); \n\t" + "%0 = %0 | %1; \n\t" + "%0 = PACK(%0.L, %0.H); \n\t" + : "+d"(x), "=&d"(tmp)); #else -static av_always_inline uint32_t bswap_32(uint32_t x){ x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); - return (x>>16) | (x<<16); -} + x= (x>>16) | (x<<16); #endif + return x; +} static inline uint64_t bswap_64(uint64_t x) { @@ -138,6 +98,11 @@ static inline uint64_t bswap_64(uint64_t x) x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL); x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL); return (x>>32) | (x<<32); +#elif defined(ARCH_X86_64) + __asm("bswap %0": + "=r" (x) : + "0" (x)); + return x; #else union { uint64_t ll; @@ -149,7 +114,6 @@ static inline uint64_t bswap_64(uint64_t x) return r.ll; #endif } -#endif /* defined(ARCH_X86) */ #endif /* !HAVE_BYTESWAP_H */ @@ -172,4 +136,4 @@ static inline uint64_t bswap_64(uint64_t x) #define le2me_64(x) (x) #endif -#endif /* __BSWAP_H__ */ +#endif /* FFMPEG_BSWAP_H */ diff --git a/contrib/ffmpeg/libavutil/common.h b/contrib/ffmpeg/libavutil/common.h index 9ec5c7c78..ce017b090 100644 --- a/contrib/ffmpeg/libavutil/common.h +++ b/contrib/ffmpeg/libavutil/common.h @@ -23,8 +23,8 @@ * common internal and external api header. */ -#ifndef COMMON_H -#define COMMON_H +#ifndef FFMPEG_COMMON_H +#define FFMPEG_COMMON_H #include @@ -44,9 +44,15 @@ #ifndef av_always_inline #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) # define av_always_inline __attribute__((always_inline)) inline -# define av_noinline __attribute__((noinline)) #else # define av_always_inline inline +#endif +#endif + +#ifndef av_noinline +#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) +# define av_noinline __attribute__((noinline)) +#else # define av_noinline #endif #endif @@ -63,6 +69,14 @@ #endif #endif +#ifndef av_unused +#if defined(__GNUC__) +# define av_unused __attribute__((unused)) +#else +# define av_unused +#endif +#endif + #include "mem.h" //rounded divison & shift @@ -82,9 +96,7 @@ extern const uint8_t ff_log2_tab[256]; static inline int av_log2(unsigned int v) { - int n; - - n = 0; + int n = 0; if (v & 0xffff0000) { v >>= 16; n += 16; @@ -100,9 +112,7 @@ static inline int av_log2(unsigned int v) static inline int av_log2_16bit(unsigned int v) { - int n; - - n = 0; + int n = 0; if (v & 0xff00) { v >>= 8; n += 8; @@ -162,7 +172,7 @@ static inline int mid_pred(int a, int b, int c) */ static inline int av_clip(int a, int amin, int amax) { - if (a < amin) return amin; + if (a < amin) return amin; else if (a > amax) return amax; else return a; } @@ -178,6 +188,17 @@ static inline uint8_t av_clip_uint8(int a) else return a; } +/** + * clip a signed integer value into the -32768,32767 range + * @param a value to clip + * @return clipped value + */ +static inline int16_t av_clip_int16(int a) +{ + if ((a+32768) & ~65535) return (a>>31) ^ 32767; + else return a; +} + /* math */ int64_t ff_gcd(int64_t a, int64_t b); @@ -197,14 +218,14 @@ static inline int ff_get_fourcc(const char *s){ /*! * \def GET_UTF8(val, GET_BYTE, ERROR) - * converts a utf-8 character (up to 4 bytes long) to its 32-bit ucs-4 encoded form + * converts a UTF-8 character (up to 4 bytes long) to its 32-bit UCS-4 encoded form * \param val is the output and should be of type uint32_t. It holds the converted - * ucs-4 character and should be a left value. - * \param GET_BYTE gets utf-8 encoded bytes from any proper source. It can be + * UCS-4 character and should be a left value. + * \param GET_BYTE gets UTF-8 encoded bytes from any proper source. It can be * a function or a statement whose return value or evaluated value is of type - * uint8_t. It will be executed up to 4 times for values in the valid utf-8 range, + * uint8_t. It will be executed up to 4 times for values in the valid UTF-8 range, * and up to 7 times in the general case. - * \param ERROR action that should be taken when an invalid utf-8 byte is returned + * \param ERROR action that should be taken when an invalid UTF-8 byte is returned * from GET_BYTE. It should be a statement that jumps out of the macro, * like exit(), goto, return, break, or continue. */ @@ -225,17 +246,17 @@ static inline int ff_get_fourcc(const char *s){ /*! * \def PUT_UTF8(val, tmp, PUT_BYTE) - * converts a 32-bit unicode character to its utf-8 encoded form (up to 4 bytes long). + * converts a 32-bit unicode character to its UTF-8 encoded form (up to 4 bytes long). * \param val is an input only argument and should be of type uint32_t. It holds - * a ucs4 encoded unicode character that is to be converted to utf-8. If + * a ucs4 encoded unicode character that is to be converted to UTF-8. If * val is given as a function it's executed only once. * \param tmp is a temporary variable and should be of type uint8_t. It * represents an intermediate value during conversion that is to be * outputted by PUT_BYTE. - * \param PUT_BYTE writes the converted utf-8 bytes to any proper destination. + * \param PUT_BYTE writes the converted UTF-8 bytes to any proper destination. * It could be a function or a statement, and uses tmp as the input byte. * For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be - * executed up to 4 times for values in the valid utf-8 range and up to + * executed up to 4 times for values in the valid UTF-8 range and up to * 7 times in the general case, depending on the length of the converted * unicode character. */ @@ -259,24 +280,36 @@ static inline int ff_get_fourcc(const char *s){ }\ } -#if defined(ARCH_X86) || defined(ARCH_POWERPC) +#if defined(ARCH_X86) || defined(ARCH_POWERPC) || defined(ARCH_BFIN) +#define AV_READ_TIME read_time #if defined(ARCH_X86_64) static inline uint64_t read_time(void) { - uint64_t a, d; - asm volatile( "rdtsc\n\t" - : "=a" (a), "=d" (d) - ); - return (d << 32) | (a & 0xffffffff); + uint64_t a, d; + asm volatile("rdtsc\n\t" + : "=a" (a), "=d" (d)); + return (d << 32) | (a & 0xffffffff); } #elif defined(ARCH_X86_32) static inline long long read_time(void) { - long long l; - asm volatile( "rdtsc\n\t" - : "=A" (l) - ); - return l; + long long l; + asm volatile("rdtsc\n\t" + : "=A" (l)); + return l; +} +#elif ARCH_BFIN +static inline uint64_t read_time(void) +{ + union { + struct { + unsigned lo; + unsigned hi; + } p; + unsigned long long c; + } t; + asm volatile ("%0=cycles; %1=cycles2;" : "=d" (t.p.lo), "=d" (t.p.hi)); + return t.c; } #else //FIXME check ppc64 static inline uint64_t read_time(void) @@ -298,29 +331,34 @@ static inline uint64_t read_time(void) return (((uint64_t)tbu)<<32) | (uint64_t)tbl; } #endif +#elif defined(HAVE_GETHRTIME) +#define AV_READ_TIME gethrtime +#endif +#ifdef AV_READ_TIME #define START_TIMER \ uint64_t tend;\ -uint64_t tstart= read_time();\ +uint64_t tstart= AV_READ_TIME();\ #define STOP_TIMER(id) \ -tend= read_time();\ +tend= AV_READ_TIME();\ {\ - static uint64_t tsum=0;\ - static int tcount=0;\ - static int tskip_count=0;\ - if(tcount<2 || tend - tstart < FFMAX(8*tsum/tcount, 2000)){\ - tsum+= tend - tstart;\ - tcount++;\ - }else\ - tskip_count++;\ - if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\ - av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\ - }\ + static uint64_t tsum=0;\ + static int tcount=0;\ + static int tskip_count=0;\ + if(tcount<2 || tend - tstart < FFMAX(8*tsum/tcount, 2000)){\ + tsum+= tend - tstart;\ + tcount++;\ + }else\ + tskip_count++;\ + if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\ + av_log(NULL, AV_LOG_DEBUG, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\ + tsum*10/tcount, id, tcount, tskip_count);\ + }\ } #else #define START_TIMER #define STOP_TIMER(id) {} #endif -#endif /* COMMON_H */ +#endif /* FFMPEG_COMMON_H */ diff --git a/contrib/ffmpeg/libavutil/crc.c b/contrib/ffmpeg/libavutil/crc.c index 02fb860b8..743a64038 100644 --- a/contrib/ffmpeg/libavutil/crc.c +++ b/contrib/ffmpeg/libavutil/crc.c @@ -21,22 +21,36 @@ #include "common.h" #include "crc.h" -#if LIBAVUTIL_VERSION_INT < (50<<16) -AVCRC *av_crcEDB88320; -AVCRC *av_crc04C11DB7; -AVCRC *av_crc8005 ; -AVCRC *av_crc07 ; +#ifdef CONFIG_HARDCODED_TABLES +#include "crc_data.h" #else -AVCRC av_crcEDB88320[257]; -AVCRC av_crc04C11DB7[257]; -AVCRC av_crc8005 [257]; -AVCRC av_crc07 [257]; +static struct { + uint8_t le; + uint8_t bits; + uint32_t poly; +} av_crc_table_params[AV_CRC_MAX] = { + [AV_CRC_8_ATM] = { 0, 8, 0x07 }, + [AV_CRC_16_ANSI] = { 0, 16, 0x8005 }, + [AV_CRC_16_CCITT] = { 0, 16, 0x1021 }, + [AV_CRC_32_IEEE] = { 0, 32, 0x04C11DB7 }, + [AV_CRC_32_IEEE_LE] = { 1, 32, 0xEDB88320 }, +}; +static AVCRC av_crc_table[AV_CRC_MAX][257]; #endif /** * Inits a crc table. * @param ctx must be an array of sizeof(AVCRC)*257 or sizeof(AVCRC)*1024 * @param cts_size size of ctx in bytes + * @param le if 1, lowest bit represents coefficient for highest exponent + * of corresponding polynomial (both for poly and actual CRC). + * If 0, you must swap the crc parameter and the result of av_crc + * if you need the standard representation (can be simplified in + * most cases to e.g. bswap16): + * bswap_32(crc << (32-bits)) + * @param bits number of bits for the CRC + * @param poly generator polynomial without the x**bits coefficient, in the + * representation as specified by le * @return <0 on failure */ int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size){ @@ -70,13 +84,38 @@ int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size){ return 0; } +/** + * Get an initialized standard CRC table. + * @param crc_id ID of a standard CRC + * @return a pointer to the CRC table or NULL on failure + */ +const AVCRC *av_crc_get_table(AVCRCId crc_id){ +#ifndef CONFIG_HARDCODED_TABLES + if (!av_crc_table[crc_id][sizeof(av_crc_table[crc_id])/sizeof(av_crc_table[crc_id][0])-1]) + if (av_crc_init(av_crc_table[crc_id], + av_crc_table_params[crc_id].le, + av_crc_table_params[crc_id].bits, + av_crc_table_params[crc_id].poly, + sizeof(av_crc_table[crc_id])) < 0) + return NULL; +#endif + return av_crc_table[crc_id]; +} + +/** + * Calculate the CRC of a block + * @param crc CRC of previous blocks if any or initial value for CRC. + * @return CRC updated with the data from the given block + * + * @see av_crc_init() "le" parameter + */ uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length){ const uint8_t *end= buffer+length; #ifndef CONFIG_SMALL if(!ctx[256]) while(buffer>8 )&0xFF)] ^ctx[1*256 + ((crc>>16)&0xFF)] @@ -91,21 +130,22 @@ uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t le #ifdef TEST #undef printf -main(){ +int main(void){ uint8_t buf[1999]; int i; - int p[4][4]={{1, 32, 0xedb88320L, 0x3D5CDD04}, - {0, 32, 0x04c11db7L, 0xC0F5BAE0}, - {0, 16, 0x8005 , 0x1FBB }, - {0, 8, 0x07 , 0xE3 },}; - AVCRC ctx[1 ? 1024:257]; + int p[4][3]={{AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04}, + {AV_CRC_32_IEEE , 0x04C11DB7, 0xC0F5BAE0}, + {AV_CRC_16_ANSI , 0x8005, 0x1FBB }, + {AV_CRC_8_ATM , 0x07, 0xE3 },}; + const AVCRC *ctx; for(i=0; i +#include typedef uint32_t AVCRC; -#if LIBAVUTIL_VERSION_INT < (50<<16) -extern AVCRC *av_crcEDB88320; -extern AVCRC *av_crc04C11DB7; -extern AVCRC *av_crc8005 ; -extern AVCRC *av_crc07 ; -#else -extern AVCRC av_crcEDB88320[]; -extern AVCRC av_crc04C11DB7[]; -extern AVCRC av_crc8005 []; -extern AVCRC av_crc07 []; -#endif +typedef enum { + AV_CRC_8_ATM, + AV_CRC_16_ANSI, + AV_CRC_16_CCITT, + AV_CRC_32_IEEE, + AV_CRC_32_IEEE_LE, /*< reversed bitorder version of AV_CRC_32_IEEE */ + AV_CRC_MAX, /*< not part of public API! don't use outside lavu */ +}AVCRCId; int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size); +const AVCRC *av_crc_get_table(AVCRCId crc_id); uint32_t av_crc(const AVCRC *ctx, uint32_t start_crc, const uint8_t *buffer, size_t length); -#endif /* CRC_H */ +#endif /* FFMPEG_CRC_H */ diff --git a/contrib/ffmpeg/libavutil/crc_data.h b/contrib/ffmpeg/libavutil/crc_data.h new file mode 100644 index 000000000..857678dd6 --- /dev/null +++ b/contrib/ffmpeg/libavutil/crc_data.h @@ -0,0 +1,213 @@ +/* + * copyright (c) 2008 Aurelien Jacobs + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_CRC_DATA_H +#define FFMPEG_CRC_DATA_H + +#include "crc.h" + +static const AVCRC av_crc_table[AV_CRC_MAX][257] = { + [AV_CRC_8_ATM] = { + 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31, + 0x24, 0x23, 0x2A, 0x2D, 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65, + 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D, 0xE0, 0xE7, 0xEE, 0xE9, + 0xFC, 0xFB, 0xF2, 0xF5, 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD, + 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85, 0xA8, 0xAF, 0xA6, 0xA1, + 0xB4, 0xB3, 0xBA, 0xBD, 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2, + 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA, 0xB7, 0xB0, 0xB9, 0xBE, + 0xAB, 0xAC, 0xA5, 0xA2, 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A, + 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32, 0x1F, 0x18, 0x11, 0x16, + 0x03, 0x04, 0x0D, 0x0A, 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42, + 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A, 0x89, 0x8E, 0x87, 0x80, + 0x95, 0x92, 0x9B, 0x9C, 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4, + 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC, 0xC1, 0xC6, 0xCF, 0xC8, + 0xDD, 0xDA, 0xD3, 0xD4, 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C, + 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44, 0x19, 0x1E, 0x17, 0x10, + 0x05, 0x02, 0x0B, 0x0C, 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34, + 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B, 0x76, 0x71, 0x78, 0x7F, + 0x6A, 0x6D, 0x64, 0x63, 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B, + 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13, 0xAE, 0xA9, 0xA0, 0xA7, + 0xB2, 0xB5, 0xBC, 0xBB, 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83, + 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF, + 0xFA, 0xFD, 0xF4, 0xF3, 0x01 + }, + [AV_CRC_16_ANSI] = { + 0x0000, 0x0580, 0x0F80, 0x0A00, 0x1B80, 0x1E00, 0x1400, 0x1180, + 0x3380, 0x3600, 0x3C00, 0x3980, 0x2800, 0x2D80, 0x2780, 0x2200, + 0x6380, 0x6600, 0x6C00, 0x6980, 0x7800, 0x7D80, 0x7780, 0x7200, + 0x5000, 0x5580, 0x5F80, 0x5A00, 0x4B80, 0x4E00, 0x4400, 0x4180, + 0xC380, 0xC600, 0xCC00, 0xC980, 0xD800, 0xDD80, 0xD780, 0xD200, + 0xF000, 0xF580, 0xFF80, 0xFA00, 0xEB80, 0xEE00, 0xE400, 0xE180, + 0xA000, 0xA580, 0xAF80, 0xAA00, 0xBB80, 0xBE00, 0xB400, 0xB180, + 0x9380, 0x9600, 0x9C00, 0x9980, 0x8800, 0x8D80, 0x8780, 0x8200, + 0x8381, 0x8601, 0x8C01, 0x8981, 0x9801, 0x9D81, 0x9781, 0x9201, + 0xB001, 0xB581, 0xBF81, 0xBA01, 0xAB81, 0xAE01, 0xA401, 0xA181, + 0xE001, 0xE581, 0xEF81, 0xEA01, 0xFB81, 0xFE01, 0xF401, 0xF181, + 0xD381, 0xD601, 0xDC01, 0xD981, 0xC801, 0xCD81, 0xC781, 0xC201, + 0x4001, 0x4581, 0x4F81, 0x4A01, 0x5B81, 0x5E01, 0x5401, 0x5181, + 0x7381, 0x7601, 0x7C01, 0x7981, 0x6801, 0x6D81, 0x6781, 0x6201, + 0x2381, 0x2601, 0x2C01, 0x2981, 0x3801, 0x3D81, 0x3781, 0x3201, + 0x1001, 0x1581, 0x1F81, 0x1A01, 0x0B81, 0x0E01, 0x0401, 0x0181, + 0x0383, 0x0603, 0x0C03, 0x0983, 0x1803, 0x1D83, 0x1783, 0x1203, + 0x3003, 0x3583, 0x3F83, 0x3A03, 0x2B83, 0x2E03, 0x2403, 0x2183, + 0x6003, 0x6583, 0x6F83, 0x6A03, 0x7B83, 0x7E03, 0x7403, 0x7183, + 0x5383, 0x5603, 0x5C03, 0x5983, 0x4803, 0x4D83, 0x4783, 0x4203, + 0xC003, 0xC583, 0xCF83, 0xCA03, 0xDB83, 0xDE03, 0xD403, 0xD183, + 0xF383, 0xF603, 0xFC03, 0xF983, 0xE803, 0xED83, 0xE783, 0xE203, + 0xA383, 0xA603, 0xAC03, 0xA983, 0xB803, 0xBD83, 0xB783, 0xB203, + 0x9003, 0x9583, 0x9F83, 0x9A03, 0x8B83, 0x8E03, 0x8403, 0x8183, + 0x8002, 0x8582, 0x8F82, 0x8A02, 0x9B82, 0x9E02, 0x9402, 0x9182, + 0xB382, 0xB602, 0xBC02, 0xB982, 0xA802, 0xAD82, 0xA782, 0xA202, + 0xE382, 0xE602, 0xEC02, 0xE982, 0xF802, 0xFD82, 0xF782, 0xF202, + 0xD002, 0xD582, 0xDF82, 0xDA02, 0xCB82, 0xCE02, 0xC402, 0xC182, + 0x4382, 0x4602, 0x4C02, 0x4982, 0x5802, 0x5D82, 0x5782, 0x5202, + 0x7002, 0x7582, 0x7F82, 0x7A02, 0x6B82, 0x6E02, 0x6402, 0x6182, + 0x2002, 0x2582, 0x2F82, 0x2A02, 0x3B82, 0x3E02, 0x3402, 0x3182, + 0x1382, 0x1602, 0x1C02, 0x1982, 0x0802, 0x0D82, 0x0782, 0x0202, + 0x0001 + }, + [AV_CRC_16_CCITT] = { + 0x0000, 0x2110, 0x4220, 0x6330, 0x8440, 0xA550, 0xC660, 0xE770, + 0x0881, 0x2991, 0x4AA1, 0x6BB1, 0x8CC1, 0xADD1, 0xCEE1, 0xEFF1, + 0x3112, 0x1002, 0x7332, 0x5222, 0xB552, 0x9442, 0xF772, 0xD662, + 0x3993, 0x1883, 0x7BB3, 0x5AA3, 0xBDD3, 0x9CC3, 0xFFF3, 0xDEE3, + 0x6224, 0x4334, 0x2004, 0x0114, 0xE664, 0xC774, 0xA444, 0x8554, + 0x6AA5, 0x4BB5, 0x2885, 0x0995, 0xEEE5, 0xCFF5, 0xACC5, 0x8DD5, + 0x5336, 0x7226, 0x1116, 0x3006, 0xD776, 0xF666, 0x9556, 0xB446, + 0x5BB7, 0x7AA7, 0x1997, 0x3887, 0xDFF7, 0xFEE7, 0x9DD7, 0xBCC7, + 0xC448, 0xE558, 0x8668, 0xA778, 0x4008, 0x6118, 0x0228, 0x2338, + 0xCCC9, 0xEDD9, 0x8EE9, 0xAFF9, 0x4889, 0x6999, 0x0AA9, 0x2BB9, + 0xF55A, 0xD44A, 0xB77A, 0x966A, 0x711A, 0x500A, 0x333A, 0x122A, + 0xFDDB, 0xDCCB, 0xBFFB, 0x9EEB, 0x799B, 0x588B, 0x3BBB, 0x1AAB, + 0xA66C, 0x877C, 0xE44C, 0xC55C, 0x222C, 0x033C, 0x600C, 0x411C, + 0xAEED, 0x8FFD, 0xECCD, 0xCDDD, 0x2AAD, 0x0BBD, 0x688D, 0x499D, + 0x977E, 0xB66E, 0xD55E, 0xF44E, 0x133E, 0x322E, 0x511E, 0x700E, + 0x9FFF, 0xBEEF, 0xDDDF, 0xFCCF, 0x1BBF, 0x3AAF, 0x599F, 0x788F, + 0x8891, 0xA981, 0xCAB1, 0xEBA1, 0x0CD1, 0x2DC1, 0x4EF1, 0x6FE1, + 0x8010, 0xA100, 0xC230, 0xE320, 0x0450, 0x2540, 0x4670, 0x6760, + 0xB983, 0x9893, 0xFBA3, 0xDAB3, 0x3DC3, 0x1CD3, 0x7FE3, 0x5EF3, + 0xB102, 0x9012, 0xF322, 0xD232, 0x3542, 0x1452, 0x7762, 0x5672, + 0xEAB5, 0xCBA5, 0xA895, 0x8985, 0x6EF5, 0x4FE5, 0x2CD5, 0x0DC5, + 0xE234, 0xC324, 0xA014, 0x8104, 0x6674, 0x4764, 0x2454, 0x0544, + 0xDBA7, 0xFAB7, 0x9987, 0xB897, 0x5FE7, 0x7EF7, 0x1DC7, 0x3CD7, + 0xD326, 0xF236, 0x9106, 0xB016, 0x5766, 0x7676, 0x1546, 0x3456, + 0x4CD9, 0x6DC9, 0x0EF9, 0x2FE9, 0xC899, 0xE989, 0x8AB9, 0xABA9, + 0x4458, 0x6548, 0x0678, 0x2768, 0xC018, 0xE108, 0x8238, 0xA328, + 0x7DCB, 0x5CDB, 0x3FEB, 0x1EFB, 0xF98B, 0xD89B, 0xBBAB, 0x9ABB, + 0x754A, 0x545A, 0x376A, 0x167A, 0xF10A, 0xD01A, 0xB32A, 0x923A, + 0x2EFD, 0x0FED, 0x6CDD, 0x4DCD, 0xAABD, 0x8BAD, 0xE89D, 0xC98D, + 0x267C, 0x076C, 0x645C, 0x454C, 0xA23C, 0x832C, 0xE01C, 0xC10C, + 0x1FEF, 0x3EFF, 0x5DCF, 0x7CDF, 0x9BAF, 0xBABF, 0xD98F, 0xF89F, + 0x176E, 0x367E, 0x554E, 0x745E, 0x932E, 0xB23E, 0xD10E, 0xF01E, + 0x0001 + }, + [AV_CRC_32_IEEE] = { + 0x00000000, 0xB71DC104, 0x6E3B8209, 0xD926430D, 0xDC760413, 0x6B6BC517, + 0xB24D861A, 0x0550471E, 0xB8ED0826, 0x0FF0C922, 0xD6D68A2F, 0x61CB4B2B, + 0x649B0C35, 0xD386CD31, 0x0AA08E3C, 0xBDBD4F38, 0x70DB114C, 0xC7C6D048, + 0x1EE09345, 0xA9FD5241, 0xACAD155F, 0x1BB0D45B, 0xC2969756, 0x758B5652, + 0xC836196A, 0x7F2BD86E, 0xA60D9B63, 0x11105A67, 0x14401D79, 0xA35DDC7D, + 0x7A7B9F70, 0xCD665E74, 0xE0B62398, 0x57ABE29C, 0x8E8DA191, 0x39906095, + 0x3CC0278B, 0x8BDDE68F, 0x52FBA582, 0xE5E66486, 0x585B2BBE, 0xEF46EABA, + 0x3660A9B7, 0x817D68B3, 0x842D2FAD, 0x3330EEA9, 0xEA16ADA4, 0x5D0B6CA0, + 0x906D32D4, 0x2770F3D0, 0xFE56B0DD, 0x494B71D9, 0x4C1B36C7, 0xFB06F7C3, + 0x2220B4CE, 0x953D75CA, 0x28803AF2, 0x9F9DFBF6, 0x46BBB8FB, 0xF1A679FF, + 0xF4F63EE1, 0x43EBFFE5, 0x9ACDBCE8, 0x2DD07DEC, 0x77708634, 0xC06D4730, + 0x194B043D, 0xAE56C539, 0xAB068227, 0x1C1B4323, 0xC53D002E, 0x7220C12A, + 0xCF9D8E12, 0x78804F16, 0xA1A60C1B, 0x16BBCD1F, 0x13EB8A01, 0xA4F64B05, + 0x7DD00808, 0xCACDC90C, 0x07AB9778, 0xB0B6567C, 0x69901571, 0xDE8DD475, + 0xDBDD936B, 0x6CC0526F, 0xB5E61162, 0x02FBD066, 0xBF469F5E, 0x085B5E5A, + 0xD17D1D57, 0x6660DC53, 0x63309B4D, 0xD42D5A49, 0x0D0B1944, 0xBA16D840, + 0x97C6A5AC, 0x20DB64A8, 0xF9FD27A5, 0x4EE0E6A1, 0x4BB0A1BF, 0xFCAD60BB, + 0x258B23B6, 0x9296E2B2, 0x2F2BAD8A, 0x98366C8E, 0x41102F83, 0xF60DEE87, + 0xF35DA999, 0x4440689D, 0x9D662B90, 0x2A7BEA94, 0xE71DB4E0, 0x500075E4, + 0x892636E9, 0x3E3BF7ED, 0x3B6BB0F3, 0x8C7671F7, 0x555032FA, 0xE24DF3FE, + 0x5FF0BCC6, 0xE8ED7DC2, 0x31CB3ECF, 0x86D6FFCB, 0x8386B8D5, 0x349B79D1, + 0xEDBD3ADC, 0x5AA0FBD8, 0xEEE00C69, 0x59FDCD6D, 0x80DB8E60, 0x37C64F64, + 0x3296087A, 0x858BC97E, 0x5CAD8A73, 0xEBB04B77, 0x560D044F, 0xE110C54B, + 0x38368646, 0x8F2B4742, 0x8A7B005C, 0x3D66C158, 0xE4408255, 0x535D4351, + 0x9E3B1D25, 0x2926DC21, 0xF0009F2C, 0x471D5E28, 0x424D1936, 0xF550D832, + 0x2C769B3F, 0x9B6B5A3B, 0x26D61503, 0x91CBD407, 0x48ED970A, 0xFFF0560E, + 0xFAA01110, 0x4DBDD014, 0x949B9319, 0x2386521D, 0x0E562FF1, 0xB94BEEF5, + 0x606DADF8, 0xD7706CFC, 0xD2202BE2, 0x653DEAE6, 0xBC1BA9EB, 0x0B0668EF, + 0xB6BB27D7, 0x01A6E6D3, 0xD880A5DE, 0x6F9D64DA, 0x6ACD23C4, 0xDDD0E2C0, + 0x04F6A1CD, 0xB3EB60C9, 0x7E8D3EBD, 0xC990FFB9, 0x10B6BCB4, 0xA7AB7DB0, + 0xA2FB3AAE, 0x15E6FBAA, 0xCCC0B8A7, 0x7BDD79A3, 0xC660369B, 0x717DF79F, + 0xA85BB492, 0x1F467596, 0x1A163288, 0xAD0BF38C, 0x742DB081, 0xC3307185, + 0x99908A5D, 0x2E8D4B59, 0xF7AB0854, 0x40B6C950, 0x45E68E4E, 0xF2FB4F4A, + 0x2BDD0C47, 0x9CC0CD43, 0x217D827B, 0x9660437F, 0x4F460072, 0xF85BC176, + 0xFD0B8668, 0x4A16476C, 0x93300461, 0x242DC565, 0xE94B9B11, 0x5E565A15, + 0x87701918, 0x306DD81C, 0x353D9F02, 0x82205E06, 0x5B061D0B, 0xEC1BDC0F, + 0x51A69337, 0xE6BB5233, 0x3F9D113E, 0x8880D03A, 0x8DD09724, 0x3ACD5620, + 0xE3EB152D, 0x54F6D429, 0x7926A9C5, 0xCE3B68C1, 0x171D2BCC, 0xA000EAC8, + 0xA550ADD6, 0x124D6CD2, 0xCB6B2FDF, 0x7C76EEDB, 0xC1CBA1E3, 0x76D660E7, + 0xAFF023EA, 0x18EDE2EE, 0x1DBDA5F0, 0xAAA064F4, 0x738627F9, 0xC49BE6FD, + 0x09FDB889, 0xBEE0798D, 0x67C63A80, 0xD0DBFB84, 0xD58BBC9A, 0x62967D9E, + 0xBBB03E93, 0x0CADFF97, 0xB110B0AF, 0x060D71AB, 0xDF2B32A6, 0x6836F3A2, + 0x6D66B4BC, 0xDA7B75B8, 0x035D36B5, 0xB440F7B1, 0x00000001 + }, + [AV_CRC_32_IEEE_LE] = { + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, + 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, + 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, + 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, + 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, + 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, + 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, + 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, + 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, + 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, + 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106, + 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, + 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, + 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, + 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, + 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, + 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, + 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, + 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, + 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, + 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, + 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, + 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, + 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, + 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, + 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, + 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, + 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, + 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, + 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, + 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, + 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, + 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, + 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, + 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, + 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, + 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, + 0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, + 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, + 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, + 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, + 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, + 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D, 0x00000001 + }, +}; + +#endif /* FFMPEG_CRC_DATA_H */ diff --git a/contrib/ffmpeg/libavutil/des.c b/contrib/ffmpeg/libavutil/des.c new file mode 100644 index 000000000..36f90ffaa --- /dev/null +++ b/contrib/ffmpeg/libavutil/des.c @@ -0,0 +1,330 @@ +/* + * DES encryption/decryption + * Copyright (c) 2007 Reimar Doeffinger + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include +#include "des.h" + +#define T(a, b, c, d, e, f, g, h) 64-a,64-b,64-c,64-d,64-e,64-f,64-g,64-h +static const uint8_t IP_shuffle[] = { + T(58, 50, 42, 34, 26, 18, 10, 2), + T(60, 52, 44, 36, 28, 20, 12, 4), + T(62, 54, 46, 38, 30, 22, 14, 6), + T(64, 56, 48, 40, 32, 24, 16, 8), + T(57, 49, 41, 33, 25, 17, 9, 1), + T(59, 51, 43, 35, 27, 19, 11, 3), + T(61, 53, 45, 37, 29, 21, 13, 5), + T(63, 55, 47, 39, 31, 23, 15, 7) +}; +#undef T + +#define T(a, b, c, d) 32-a,32-b,32-c,32-d +static const uint8_t P_shuffle[] = { + T(16, 7, 20, 21), + T(29, 12, 28, 17), + T( 1, 15, 23, 26), + T( 5, 18, 31, 10), + T( 2, 8, 24, 14), + T(32, 27, 3, 9), + T(19, 13, 30, 6), + T(22, 11, 4, 25) +}; +#undef T + +#define T(a, b, c, d, e, f, g) 64-a,64-b,64-c,64-d,64-e,64-f,64-g +static const uint8_t PC1_shuffle[] = { + T(57, 49, 41, 33, 25, 17, 9), + T( 1, 58, 50, 42, 34, 26, 18), + T(10, 2, 59, 51, 43, 35, 27), + T(19, 11, 3, 60, 52, 44, 36), + T(63, 55, 47, 39, 31, 23, 15), + T( 7, 62, 54, 46, 38, 30, 22), + T(14, 6, 61, 53, 45, 37, 29), + T(21, 13, 5, 28, 20, 12, 4) +}; +#undef T + +#define T(a, b, c, d, e, f) 56-a,56-b,56-c,56-d,56-e,56-f +static const uint8_t PC2_shuffle[] = { + T(14, 17, 11, 24, 1, 5), + T( 3, 28, 15, 6, 21, 10), + T(23, 19, 12, 4, 26, 8), + T(16, 7, 27, 20, 13, 2), + T(41, 52, 31, 37, 47, 55), + T(30, 40, 51, 45, 33, 48), + T(44, 49, 39, 56, 34, 53), + T(46, 42, 50, 36, 29, 32) +}; +#undef T + +#ifdef CONFIG_SMALL +static const uint8_t S_boxes[8][32] = { + { + 0x0e, 0xf4, 0x7d, 0x41, 0xe2, 0x2f, 0xdb, 0x18, 0xa3, 0x6a, 0xc6, 0xbc, 0x95, 0x59, 0x30, 0x87, + 0xf4, 0xc1, 0x8e, 0x28, 0x4d, 0x96, 0x12, 0x7b, 0x5f, 0xbc, 0x39, 0xe7, 0xa3, 0x0a, 0x65, 0xd0, + }, { + 0x3f, 0xd1, 0x48, 0x7e, 0xf6, 0x2b, 0x83, 0xe4, 0xc9, 0x07, 0x12, 0xad, 0x6c, 0x90, 0xb5, 0x5a, + 0xd0, 0x8e, 0xa7, 0x1b, 0x3a, 0xf4, 0x4d, 0x21, 0xb5, 0x68, 0x7c, 0xc6, 0x09, 0x53, 0xe2, 0x9f, + }, { + 0xda, 0x70, 0x09, 0x9e, 0x36, 0x43, 0x6f, 0xa5, 0x21, 0x8d, 0x5c, 0xe7, 0xcb, 0xb4, 0xf2, 0x18, + 0x1d, 0xa6, 0xd4, 0x09, 0x68, 0x9f, 0x83, 0x70, 0x4b, 0xf1, 0xe2, 0x3c, 0xb5, 0x5a, 0x2e, 0xc7, + }, { + 0xd7, 0x8d, 0xbe, 0x53, 0x60, 0xf6, 0x09, 0x3a, 0x41, 0x72, 0x28, 0xc5, 0x1b, 0xac, 0xe4, 0x9f, + 0x3a, 0xf6, 0x09, 0x60, 0xac, 0x1b, 0xd7, 0x8d, 0x9f, 0x41, 0x53, 0xbe, 0xc5, 0x72, 0x28, 0xe4, + }, { + 0xe2, 0xbc, 0x24, 0xc1, 0x47, 0x7a, 0xdb, 0x16, 0x58, 0x05, 0xf3, 0xaf, 0x3d, 0x90, 0x8e, 0x69, + 0xb4, 0x82, 0xc1, 0x7b, 0x1a, 0xed, 0x27, 0xd8, 0x6f, 0xf9, 0x0c, 0x95, 0xa6, 0x43, 0x50, 0x3e, + }, { + 0xac, 0xf1, 0x4a, 0x2f, 0x79, 0xc2, 0x96, 0x58, 0x60, 0x1d, 0xd3, 0xe4, 0x0e, 0xb7, 0x35, 0x8b, + 0x49, 0x3e, 0x2f, 0xc5, 0x92, 0x58, 0xfc, 0xa3, 0xb7, 0xe0, 0x14, 0x7a, 0x61, 0x0d, 0x8b, 0xd6, + }, { + 0xd4, 0x0b, 0xb2, 0x7e, 0x4f, 0x90, 0x18, 0xad, 0xe3, 0x3c, 0x59, 0xc7, 0x25, 0xfa, 0x86, 0x61, + 0x61, 0xb4, 0xdb, 0x8d, 0x1c, 0x43, 0xa7, 0x7e, 0x9a, 0x5f, 0x06, 0xf8, 0xe0, 0x25, 0x39, 0xc2, + }, { + 0x1d, 0xf2, 0xd8, 0x84, 0xa6, 0x3f, 0x7b, 0x41, 0xca, 0x59, 0x63, 0xbe, 0x05, 0xe0, 0x9c, 0x27, + 0x27, 0x1b, 0xe4, 0x71, 0x49, 0xac, 0x8e, 0xd2, 0xf0, 0xc6, 0x9a, 0x0d, 0x3f, 0x53, 0x65, 0xb8, + } +}; +#else +/** + * This table contains the results of applying both the S-box and P-shuffle. + * It can be regenerated by compiling this file with -DCONFIG_SMALL -DTEST -DGENTABLES + */ +static const uint32_t S_boxes_P_shuffle[8][64] = { + { + 0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, 0x00000002, 0x00008000, + 0x00000200, 0x00808200, 0x00808202, 0x00000200, 0x00800202, 0x00808002, 0x00800000, 0x00000002, + 0x00000202, 0x00800200, 0x00800200, 0x00008200, 0x00008200, 0x00808000, 0x00808000, 0x00800202, + 0x00008002, 0x00800002, 0x00800002, 0x00008002, 0x00000000, 0x00000202, 0x00008202, 0x00800000, + 0x00008000, 0x00808202, 0x00000002, 0x00808000, 0x00808200, 0x00800000, 0x00800000, 0x00000200, + 0x00808002, 0x00008000, 0x00008200, 0x00800002, 0x00000200, 0x00000002, 0x00800202, 0x00008202, + 0x00808202, 0x00008002, 0x00808000, 0x00800202, 0x00800002, 0x00000202, 0x00008202, 0x00808200, + 0x00000202, 0x00800200, 0x00800200, 0x00000000, 0x00008002, 0x00008200, 0x00000000, 0x00808002, + }, + { + 0x40084010, 0x40004000, 0x00004000, 0x00084010, 0x00080000, 0x00000010, 0x40080010, 0x40004010, + 0x40000010, 0x40084010, 0x40084000, 0x40000000, 0x40004000, 0x00080000, 0x00000010, 0x40080010, + 0x00084000, 0x00080010, 0x40004010, 0x00000000, 0x40000000, 0x00004000, 0x00084010, 0x40080000, + 0x00080010, 0x40000010, 0x00000000, 0x00084000, 0x00004010, 0x40084000, 0x40080000, 0x00004010, + 0x00000000, 0x00084010, 0x40080010, 0x00080000, 0x40004010, 0x40080000, 0x40084000, 0x00004000, + 0x40080000, 0x40004000, 0x00000010, 0x40084010, 0x00084010, 0x00000010, 0x00004000, 0x40000000, + 0x00004010, 0x40084000, 0x00080000, 0x40000010, 0x00080010, 0x40004010, 0x40000010, 0x00080010, + 0x00084000, 0x00000000, 0x40004000, 0x00004010, 0x40000000, 0x40080010, 0x40084010, 0x00084000, + }, + { + 0x00000104, 0x04010100, 0x00000000, 0x04010004, 0x04000100, 0x00000000, 0x00010104, 0x04000100, + 0x00010004, 0x04000004, 0x04000004, 0x00010000, 0x04010104, 0x00010004, 0x04010000, 0x00000104, + 0x04000000, 0x00000004, 0x04010100, 0x00000100, 0x00010100, 0x04010000, 0x04010004, 0x00010104, + 0x04000104, 0x00010100, 0x00010000, 0x04000104, 0x00000004, 0x04010104, 0x00000100, 0x04000000, + 0x04010100, 0x04000000, 0x00010004, 0x00000104, 0x00010000, 0x04010100, 0x04000100, 0x00000000, + 0x00000100, 0x00010004, 0x04010104, 0x04000100, 0x04000004, 0x00000100, 0x00000000, 0x04010004, + 0x04000104, 0x00010000, 0x04000000, 0x04010104, 0x00000004, 0x00010104, 0x00010100, 0x04000004, + 0x04010000, 0x04000104, 0x00000104, 0x04010000, 0x00010104, 0x00000004, 0x04010004, 0x00010100, + }, + { + 0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x00401040, 0x80400040, 0x80400000, 0x80001000, + 0x00000000, 0x00401000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00400040, 0x80400000, + 0x80000000, 0x00001000, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x80001000, 0x00001040, + 0x80400040, 0x80000000, 0x00001040, 0x00400040, 0x00001000, 0x00401040, 0x80401040, 0x80000040, + 0x00400040, 0x80400000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00000000, 0x00401000, + 0x00001040, 0x00400040, 0x80400040, 0x80000000, 0x80401000, 0x80001040, 0x80001040, 0x00000040, + 0x80401040, 0x80000040, 0x80000000, 0x00001000, 0x80400000, 0x80001000, 0x00401040, 0x80400040, + 0x80001000, 0x00001040, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x00001000, 0x00401040, + }, + { + 0x00000080, 0x01040080, 0x01040000, 0x21000080, 0x00040000, 0x00000080, 0x20000000, 0x01040000, + 0x20040080, 0x00040000, 0x01000080, 0x20040080, 0x21000080, 0x21040000, 0x00040080, 0x20000000, + 0x01000000, 0x20040000, 0x20040000, 0x00000000, 0x20000080, 0x21040080, 0x21040080, 0x01000080, + 0x21040000, 0x20000080, 0x00000000, 0x21000000, 0x01040080, 0x01000000, 0x21000000, 0x00040080, + 0x00040000, 0x21000080, 0x00000080, 0x01000000, 0x20000000, 0x01040000, 0x21000080, 0x20040080, + 0x01000080, 0x20000000, 0x21040000, 0x01040080, 0x20040080, 0x00000080, 0x01000000, 0x21040000, + 0x21040080, 0x00040080, 0x21000000, 0x21040080, 0x01040000, 0x00000000, 0x20040000, 0x21000000, + 0x00040080, 0x01000080, 0x20000080, 0x00040000, 0x00000000, 0x20040000, 0x01040080, 0x20000080, + }, + { + 0x10000008, 0x10200000, 0x00002000, 0x10202008, 0x10200000, 0x00000008, 0x10202008, 0x00200000, + 0x10002000, 0x00202008, 0x00200000, 0x10000008, 0x00200008, 0x10002000, 0x10000000, 0x00002008, + 0x00000000, 0x00200008, 0x10002008, 0x00002000, 0x00202000, 0x10002008, 0x00000008, 0x10200008, + 0x10200008, 0x00000000, 0x00202008, 0x10202000, 0x00002008, 0x00202000, 0x10202000, 0x10000000, + 0x10002000, 0x00000008, 0x10200008, 0x00202000, 0x10202008, 0x00200000, 0x00002008, 0x10000008, + 0x00200000, 0x10002000, 0x10000000, 0x00002008, 0x10000008, 0x10202008, 0x00202000, 0x10200000, + 0x00202008, 0x10202000, 0x00000000, 0x10200008, 0x00000008, 0x00002000, 0x10200000, 0x00202008, + 0x00002000, 0x00200008, 0x10002008, 0x00000000, 0x10202000, 0x10000000, 0x00200008, 0x10002008, + }, + { + 0x00100000, 0x02100001, 0x02000401, 0x00000000, 0x00000400, 0x02000401, 0x00100401, 0x02100400, + 0x02100401, 0x00100000, 0x00000000, 0x02000001, 0x00000001, 0x02000000, 0x02100001, 0x00000401, + 0x02000400, 0x00100401, 0x00100001, 0x02000400, 0x02000001, 0x02100000, 0x02100400, 0x00100001, + 0x02100000, 0x00000400, 0x00000401, 0x02100401, 0x00100400, 0x00000001, 0x02000000, 0x00100400, + 0x02000000, 0x00100400, 0x00100000, 0x02000401, 0x02000401, 0x02100001, 0x02100001, 0x00000001, + 0x00100001, 0x02000000, 0x02000400, 0x00100000, 0x02100400, 0x00000401, 0x00100401, 0x02100400, + 0x00000401, 0x02000001, 0x02100401, 0x02100000, 0x00100400, 0x00000000, 0x00000001, 0x02100401, + 0x00000000, 0x00100401, 0x02100000, 0x00000400, 0x02000001, 0x02000400, 0x00000400, 0x00100001, + }, + { + 0x08000820, 0x00000800, 0x00020000, 0x08020820, 0x08000000, 0x08000820, 0x00000020, 0x08000000, + 0x00020020, 0x08020000, 0x08020820, 0x00020800, 0x08020800, 0x00020820, 0x00000800, 0x00000020, + 0x08020000, 0x08000020, 0x08000800, 0x00000820, 0x00020800, 0x00020020, 0x08020020, 0x08020800, + 0x00000820, 0x00000000, 0x00000000, 0x08020020, 0x08000020, 0x08000800, 0x00020820, 0x00020000, + 0x00020820, 0x00020000, 0x08020800, 0x00000800, 0x00000020, 0x08020020, 0x00000800, 0x00020820, + 0x08000800, 0x00000020, 0x08000020, 0x08020000, 0x08020020, 0x08000000, 0x00020000, 0x08000820, + 0x00000000, 0x08020820, 0x00020020, 0x08000020, 0x08020000, 0x08000800, 0x08000820, 0x00000000, + 0x08020820, 0x00020800, 0x00020800, 0x00000820, 0x00000820, 0x00020020, 0x08000000, 0x08020800, + }, +}; +#endif + +static uint64_t shuffle(uint64_t in, const uint8_t *shuffle, int shuffle_len) { + int i; + uint64_t res = 0; + for (i = 0; i < shuffle_len; i++) + res += res + ((in >> *shuffle++) & 1); + return res; +} + +static uint64_t shuffle_inv(uint64_t in, const uint8_t *shuffle, int shuffle_len) { + int i; + uint64_t res = 0; + shuffle += shuffle_len - 1; + for (i = 0; i < shuffle_len; i++) { + res |= (in & 1) << *shuffle--; + in >>= 1; + } + return res; +} + +static uint32_t f_func(uint32_t r, uint64_t k) { + int i; + uint32_t out = 0; + // rotate to get first part of E-shuffle in the lowest 6 bits + r = (r << 1) | (r >> 31); + // apply S-boxes, those compress the data again from 8 * 6 to 8 * 4 bits + for (i = 7; i >= 0; i--) { + uint8_t tmp = (r ^ k) & 0x3f; +#ifdef CONFIG_SMALL + uint8_t v = S_boxes[i][tmp >> 1]; + if (tmp & 1) v >>= 4; + out = (out >> 4) | (v << 28); +#else + out |= S_boxes_P_shuffle[i][tmp]; +#endif + // get next 6 bits of E-shuffle and round key k into the lowest bits + r = (r >> 4) | (r << 28); + k >>= 6; + } +#ifdef CONFIG_SMALL + out = shuffle(out, P_shuffle, sizeof(P_shuffle)); +#endif + return out; +} + +/** + * \brief rotate the two halves of the expanded 56 bit key each 1 bit left + * + * Note: the specification calls this "shift", so I kept it although + * it is confusing. + */ +static uint64_t key_shift_left(uint64_t CDn) { + uint64_t carries = (CDn >> 27) & 0x10000001; + CDn <<= 1; + CDn &= ~0x10000001; + CDn |= carries; + return CDn; +} + +uint64_t ff_des_encdec(uint64_t in, uint64_t key, int decrypt) { + int i; + uint64_t K[16]; + // discard parity bits from key and shuffle it into C and D parts + uint64_t CDn = shuffle(key, PC1_shuffle, sizeof(PC1_shuffle)); + // generate round keys + for (i = 0; i < 16; i++) { + CDn = key_shift_left(CDn); + if (i > 1 && i != 8 && i != 15) + CDn = key_shift_left(CDn); + K[i] = shuffle(CDn, PC2_shuffle, sizeof(PC2_shuffle)); + } + // used to apply round keys in reverse order for decryption + decrypt = decrypt ? 15 : 0; + // shuffle irrelevant to security but to ease hardware implementations + in = shuffle(in, IP_shuffle, sizeof(IP_shuffle)); + for (i = 0; i < 16; i++) { + uint32_t f_res; + f_res = f_func(in, K[decrypt ^ i]); + in = (in << 32) | (in >> 32); + in ^= f_res; + } + in = (in << 32) | (in >> 32); + // reverse shuffle used to ease hardware implementations + in = shuffle_inv(in, IP_shuffle, sizeof(IP_shuffle)); + return in; +} + +#ifdef TEST +#include +#include +#include +static uint64_t rand64(void) { + uint64_t r = rand(); + r = (r << 32) | rand(); + return r; +} + +int main(void) { + int i, j; + struct timeval tv; + uint64_t key; + uint64_t data; + uint64_t ct; + gettimeofday(&tv, NULL); + srand(tv.tv_sec * 1000 * 1000 + tv.tv_usec); + key = 0x123456789abcdef0ULL; + data = 0xfedcba9876543210ULL; + if (ff_des_encdec(data, key, 0) != 0x4ab65b3d4b061518ULL) { + printf("Test 1 failed\n"); + return 1; + } + for (i = 0; i < 1000000; i++) { + key = rand64(); + data = rand64(); + ct = ff_des_encdec(data, key, 0); + if (ff_des_encdec(ct, key, 1) != data) { + printf("Test 2 failed\n"); + return 1; + } + } +#ifdef GENTABLES + printf("static const uint32_t S_boxes_P_shuffle[8][64] = {\n"); + for (i = 0; i < 8; i++) { + printf(" {"); + for (j = 0; j < 64; j++) { + uint32_t v = S_boxes[i][j >> 1]; + v = j & 1 ? v >> 4 : v & 0xf; + v <<= 28 - 4 * i; + v = shuffle(v, P_shuffle, sizeof(P_shuffle)); + printf((j & 7) == 0 ? "\n " : " "); + printf("0x%08X,", v); + } + printf("\n },\n"); + } + printf("};\n"); +#endif + return 0; +} +#endif diff --git a/contrib/ffmpeg/libavutil/des.h b/contrib/ffmpeg/libavutil/des.h new file mode 100644 index 000000000..70f89937c --- /dev/null +++ b/contrib/ffmpeg/libavutil/des.h @@ -0,0 +1,39 @@ +/* + * DES encryption/decryption + * Copyright (c) 2007 Reimar Doeffinger + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_DES_H +#define FFMPEG_DES_H + +#include + +/** + * \brief en- or decrypt an 64-bit block of data with DES + * \param in data to process. + * \param key key to use for en-/decryption. + * \param decrypt if 0 encrypt, else decrypt. + * \return processed data + * + * If your input data is in 8-bit blocks treat it as big-endian + * (use e.g. AV_RB64 and AV_WB64). + */ +uint64_t ff_des_encdec(uint64_t in, uint64_t key, int decrypt); + +#endif /* FFMPEG_DES_H */ diff --git a/contrib/ffmpeg/libavutil/fifo.h b/contrib/ffmpeg/libavutil/fifo.h index e1e85293d..817a8a6b6 100644 --- a/contrib/ffmpeg/libavutil/fifo.h +++ b/contrib/ffmpeg/libavutil/fifo.h @@ -21,8 +21,10 @@ * A very simple circular buffer FIFO implementation. */ -#ifndef FIFO_H -#define FIFO_H +#ifndef FFMPEG_FIFO_H +#define FFMPEG_FIFO_H + +#include typedef struct AVFifoBuffer { uint8_t *buffer; @@ -97,4 +99,4 @@ static inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs) ptr -= f->end - f->buffer; return *ptr; } -#endif /* FIFO_H */ +#endif /* FFMPEG_FIFO_H */ diff --git a/contrib/ffmpeg/libavutil/integer.c b/contrib/ffmpeg/libavutil/integer.c index 3269a366a..a7ab5c97f 100644 --- a/contrib/ffmpeg/libavutil/integer.c +++ b/contrib/ffmpeg/libavutil/integer.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -157,7 +156,7 @@ int64_t av_i2int(AVInteger a){ return out; } -#if 0 +#ifdef TEST #undef NDEBUG #include @@ -172,7 +171,7 @@ const uint8_t ff_log2_tab[256]={ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 }; -main(){ +int main(void){ int64_t a,b; for(a=7; a<256*256*256; a+=13215){ @@ -193,5 +192,6 @@ main(){ assert(av_i2int(av_div_i(ai,bi)) == a/b); } } + return 0; } #endif diff --git a/contrib/ffmpeg/libavutil/integer.h b/contrib/ffmpeg/libavutil/integer.h index 2a4d70316..f539125d1 100644 --- a/contrib/ffmpeg/libavutil/integer.h +++ b/contrib/ffmpeg/libavutil/integer.h @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -26,8 +25,10 @@ * @author Michael Niedermayer */ -#ifndef INTEGER_H -#define INTEGER_H +#ifndef FFMPEG_INTEGER_H +#define FFMPEG_INTEGER_H + +#include #define AV_INTEGER_SIZE 8 @@ -79,4 +80,4 @@ AVInteger av_int2i(int64_t a); */ int64_t av_i2int(AVInteger a); -#endif // INTEGER_H +#endif /* FFMPEG_INTEGER_H */ diff --git a/contrib/ffmpeg/libavutil/internal.h b/contrib/ffmpeg/libavutil/internal.h index eefbfa1e4..749a85c45 100644 --- a/contrib/ffmpeg/libavutil/internal.h +++ b/contrib/ffmpeg/libavutil/internal.h @@ -23,8 +23,24 @@ * common internal api header. */ -#ifndef INTERNAL_H -#define INTERNAL_H +#ifndef FFMPEG_INTERNAL_H +#define FFMPEG_INTERNAL_H + +#if !defined(DEBUG) && !defined(NDEBUG) +# define NDEBUG +#endif + +#include +#include +#include + +#ifndef attribute_align_arg +#if defined(__GNUC__) && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__>1) +# define attribute_align_arg __attribute__((force_align_arg_pointer)) +#else +# define attribute_align_arg +#endif +#endif #ifndef attribute_used #if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) @@ -34,12 +50,11 @@ #endif #endif -#ifndef attribute_unused -#if defined(__GNUC__) -# define attribute_unused __attribute__((unused)) +/* Use Apple-specific AltiVec syntax for vector declarations when necessary. */ +#ifdef __APPLE_CC__ +#define AVV(x...) (x) #else -# define attribute_unused -#endif +#define AVV(x...) {x} #endif #ifndef M_PI @@ -93,38 +108,17 @@ #include "intreadwrite.h" #include "bswap.h" -#include #ifndef offsetof # define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F)) #endif -#ifdef __MINGW32__ -# ifdef _DEBUG -# define DEBUG -# endif - -# define snprintf _snprintf -# define vsnprintf _vsnprintf - -# ifdef CONFIG_WINCE -# define perror(a) -# define abort() -# endif - -/* __MINGW32__ end */ -#elif defined (CONFIG_OS2) -/* OS/2 EMX */ - -# include - -#endif /* !__MINGW32__ && CONFIG_OS2 */ - #ifdef USE_FASTMEMCPY # include "libvo/fastmemcpy.h" +# define memcpy(a,b,c) fast_memcpy(a,b,c) #endif // Use rip-relative addressing if compiling PIC code on x86-64. -#if defined(__MINGW32__) || defined(__CYGWIN__) || \ +#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__DJGPP__) || \ defined(__OS2__) || (defined (__OpenBSD__) && !defined(__ELF__)) # if defined(ARCH_X86_64) && defined(PIC) # define MANGLE(a) "_" #a"(%%rip)" @@ -134,7 +128,7 @@ #else # if defined(ARCH_X86_64) && defined(PIC) # define MANGLE(a) #a"(%%rip)" -# elif defined(CONFIG_DARWIN) +# elif defined(__APPLE__) # define MANGLE(a) "_" #a # else # define MANGLE(a) #a @@ -143,11 +137,6 @@ /* debug stuff */ -#if !defined(DEBUG) && !defined(NDEBUG) -# define NDEBUG -#endif -#include - /* dprintf macros */ #ifdef DEBUG # define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__) @@ -189,30 +178,34 @@ extern const uint32_t ff_inverse[256]; # define FASTDIV(a,b) ((a)/(b)) #endif -extern const uint8_t ff_sqrt_tab[128]; +extern const uint8_t ff_sqrt_tab[256]; + +static inline int av_log2_16bit(unsigned int v); -static inline int ff_sqrt(int a) +static inline unsigned int ff_sqrt(unsigned int a) { - int ret=0; - int s; - int ret_sq=0; - - if(a<128) return ff_sqrt_tab[a]; - - for(s=15; s>=0; s--){ - int b= ret_sq + (1<<(s*2)) + (ret<>4; + else if(a<(1<<12)) b= ff_sqrt_tab[a>>4 ]>>2; +#ifndef CONFIG_SMALL + else if(a<(1<<14)) b= ff_sqrt_tab[a>>6 ]>>1; + else if(a<(1<<16)) b= ff_sqrt_tab[a>>8 ] ; +#endif + else{ + int s= av_log2_16bit(a>>16)>>1; + unsigned int c= a>>(s+2); + b= ff_sqrt_tab[c>>(s+8)]; + b= FASTDIV(c,b) + (b< 0) ? floor(x + 0.5) : ceil(x - 0.5); +} +#endif /* HAVE_ROUND */ + +#ifndef HAVE_ROUNDF +static av_always_inline float roundf(float x) +{ + return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5); +} +#endif /* HAVE_ROUNDF */ + +#endif /* FFMPEG_INTERNAL_H */ diff --git a/contrib/ffmpeg/libavutil/intfloat_readwrite.h b/contrib/ffmpeg/libavutil/intfloat_readwrite.h index c535b64c8..fe7fe3520 100644 --- a/contrib/ffmpeg/libavutil/intfloat_readwrite.h +++ b/contrib/ffmpeg/libavutil/intfloat_readwrite.h @@ -18,8 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef INTFLOAT_READWRITE_H -#define INTFLOAT_READWRITE_H +#ifndef FFMPEG_INTFLOAT_READWRITE_H +#define FFMPEG_INTFLOAT_READWRITE_H #include "common.h" @@ -36,4 +36,4 @@ int64_t av_dbl2int(double d); int32_t av_flt2int(float d); AVExtFloat av_dbl2ext(double d); -#endif /* INTFLOAT_READWRITE_H */ +#endif /* FFMPEG_INTFLOAT_READWRITE_H */ diff --git a/contrib/ffmpeg/libavutil/intreadwrite.h b/contrib/ffmpeg/libavutil/intreadwrite.h index 7225f0b67..dd77104f2 100644 --- a/contrib/ffmpeg/libavutil/intreadwrite.h +++ b/contrib/ffmpeg/libavutil/intreadwrite.h @@ -16,8 +16,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef INTREADWRITE_H -#define INTREADWRITE_H +#ifndef FFMPEG_INTREADWRITE_H +#define FFMPEG_INTREADWRITE_H + +#include +#include "bswap.h" #ifdef __GNUC__ @@ -25,75 +28,162 @@ struct unaligned_64 { uint64_t l; } __attribute__((packed)); struct unaligned_32 { uint32_t l; } __attribute__((packed)); struct unaligned_16 { uint16_t l; } __attribute__((packed)); -#define LD16(a) (((const struct unaligned_16 *) (a))->l) -#define LD32(a) (((const struct unaligned_32 *) (a))->l) -#define LD64(a) (((const struct unaligned_64 *) (a))->l) +#define AV_RN16(a) (((const struct unaligned_16 *) (a))->l) +#define AV_RN32(a) (((const struct unaligned_32 *) (a))->l) +#define AV_RN64(a) (((const struct unaligned_64 *) (a))->l) -#define ST16(a, b) (((struct unaligned_16 *) (a))->l) = (b) -#define ST32(a, b) (((struct unaligned_32 *) (a))->l) = (b) +#define AV_WN16(a, b) (((struct unaligned_16 *) (a))->l) = (b) +#define AV_WN32(a, b) (((struct unaligned_32 *) (a))->l) = (b) +#define AV_WN64(a, b) (((struct unaligned_64 *) (a))->l) = (b) #else /* __GNUC__ */ -#define LD16(a) (*((uint16_t*)(a))) -#define LD32(a) (*((uint32_t*)(a))) -#define LD64(a) (*((uint64_t*)(a))) +#define AV_RN16(a) (*((const uint16_t*)(a))) +#define AV_RN32(a) (*((const uint32_t*)(a))) +#define AV_RN64(a) (*((const uint64_t*)(a))) -#define ST16(a, b) *((uint16_t*)(a)) = (b) -#define ST32(a, b) *((uint32_t*)(a)) = (b) +#define AV_WN16(a, b) *((uint16_t*)(a)) = (b) +#define AV_WN32(a, b) *((uint32_t*)(a)) = (b) +#define AV_WN64(a, b) *((uint64_t*)(a)) = (b) #endif /* !__GNUC__ */ /* endian macros */ -#define AV_RB8(x) (((uint8_t*)(x))[0]) -#define AV_WB8(p, d) { ((uint8_t*)(p))[0] = (d); } +#define AV_RB8(x) (((const uint8_t*)(x))[0]) +#define AV_WB8(p, d) do { ((uint8_t*)(p))[0] = (d); } while(0) + +#define AV_RL8(x) AV_RB8(x) +#define AV_WL8(p, d) AV_WB8(p, d) -#define AV_RB16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1]) -#define AV_WB16(p, d) { \ +#ifdef HAVE_FAST_UNALIGNED +# ifdef WORDS_BIGENDIAN +# define AV_RB16(x) AV_RN16(x) +# define AV_WB16(p, d) AV_WN16(p, d) + +# define AV_RL16(x) bswap_16(AV_RN16(x)) +# define AV_WL16(p, d) AV_WN16(p, bswap_16(d)) +# else /* WORDS_BIGENDIAN */ +# define AV_RB16(x) bswap_16(AV_RN16(x)) +# define AV_WB16(p, d) AV_WN16(p, bswap_16(d)) + +# define AV_RL16(x) AV_RN16(x) +# define AV_WL16(p, d) AV_WN16(p, d) +# endif +#else /* HAVE_FAST_UNALIGNED */ +#define AV_RB16(x) ((((const uint8_t*)(x))[0] << 8) | ((const uint8_t*)(x))[1]) +#define AV_WB16(p, d) do { \ ((uint8_t*)(p))[1] = (d); \ - ((uint8_t*)(p))[0] = (d)>>8; } + ((uint8_t*)(p))[0] = (d)>>8; } while(0) + +#define AV_RL16(x) ((((const uint8_t*)(x))[1] << 8) | \ + ((const uint8_t*)(x))[0]) +#define AV_WL16(p, d) do { \ + ((uint8_t*)(p))[0] = (d); \ + ((uint8_t*)(p))[1] = (d)>>8; } while(0) +#endif -#define AV_RB24(x) ((((uint8_t*)(x))[0] << 16) | \ - (((uint8_t*)(x))[1] << 8) | \ - ((uint8_t*)(x))[2]) -#define AV_WB24(p, d) { \ +#define AV_RB24(x) ((((const uint8_t*)(x))[0] << 16) | \ + (((const uint8_t*)(x))[1] << 8) | \ + ((const uint8_t*)(x))[2]) +#define AV_WB24(p, d) do { \ ((uint8_t*)(p))[2] = (d); \ ((uint8_t*)(p))[1] = (d)>>8; \ - ((uint8_t*)(p))[0] = (d)>>16; } + ((uint8_t*)(p))[0] = (d)>>16; } while(0) -#define AV_RB32(x) ((((uint8_t*)(x))[0] << 24) | \ - (((uint8_t*)(x))[1] << 16) | \ - (((uint8_t*)(x))[2] << 8) | \ - ((uint8_t*)(x))[3]) -#define AV_WB32(p, d) { \ +#define AV_RL24(x) ((((const uint8_t*)(x))[2] << 16) | \ + (((const uint8_t*)(x))[1] << 8) | \ + ((const uint8_t*)(x))[0]) +#define AV_WL24(p, d) do { \ + ((uint8_t*)(p))[0] = (d); \ + ((uint8_t*)(p))[1] = (d)>>8; \ + ((uint8_t*)(p))[2] = (d)>>16; } while(0) + +#ifdef HAVE_FAST_UNALIGNED +# ifdef WORDS_BIGENDIAN +# define AV_RB32(x) AV_RN32(x) +# define AV_WB32(p, d) AV_WN32(p, d) + +# define AV_RL32(x) bswap_32(AV_RN32(x)) +# define AV_WL32(p, d) AV_WN32(p, bswap_32(d)) +# else /* WORDS_BIGENDIAN */ +# define AV_RB32(x) bswap_32(AV_RN32(x)) +# define AV_WB32(p, d) AV_WN32(p, bswap_32(d)) + +# define AV_RL32(x) AV_RN32(x) +# define AV_WL32(p, d) AV_WN32(p, d) +# endif +#else /* HAVE_FAST_UNALIGNED */ +#define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \ + (((const uint8_t*)(x))[1] << 16) | \ + (((const uint8_t*)(x))[2] << 8) | \ + ((const uint8_t*)(x))[3]) +#define AV_WB32(p, d) do { \ ((uint8_t*)(p))[3] = (d); \ ((uint8_t*)(p))[2] = (d)>>8; \ ((uint8_t*)(p))[1] = (d)>>16; \ - ((uint8_t*)(p))[0] = (d)>>24; } - -#define AV_RL8(x) AV_RB8(x) -#define AV_WL8(p, d) AV_WB8(p, d) - -#define AV_RL16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0]) -#define AV_WL16(p, d) { \ - ((uint8_t*)(p))[0] = (d); \ - ((uint8_t*)(p))[1] = (d)>>8; } - -#define AV_RL24(x) ((((uint8_t*)(x))[2] << 16) | \ - (((uint8_t*)(x))[1] << 8) | \ - ((uint8_t*)(x))[0]) -#define AV_WL24(p, d) { \ - ((uint8_t*)(p))[0] = (d); \ - ((uint8_t*)(p))[1] = (d)>>8; \ - ((uint8_t*)(p))[2] = (d)>>16; } + ((uint8_t*)(p))[0] = (d)>>24; } while(0) -#define AV_RL32(x) ((((uint8_t*)(x))[3] << 24) | \ - (((uint8_t*)(x))[2] << 16) | \ - (((uint8_t*)(x))[1] << 8) | \ - ((uint8_t*)(x))[0]) -#define AV_WL32(p, d) { \ +#define AV_RL32(x) ((((const uint8_t*)(x))[3] << 24) | \ + (((const uint8_t*)(x))[2] << 16) | \ + (((const uint8_t*)(x))[1] << 8) | \ + ((const uint8_t*)(x))[0]) +#define AV_WL32(p, d) do { \ ((uint8_t*)(p))[0] = (d); \ ((uint8_t*)(p))[1] = (d)>>8; \ ((uint8_t*)(p))[2] = (d)>>16; \ - ((uint8_t*)(p))[3] = (d)>>24; } - -#endif /* INTREADWRITE_H */ + ((uint8_t*)(p))[3] = (d)>>24; } while(0) +#endif + +#ifdef HAVE_FAST_UNALIGNED +# ifdef WORDS_BIGENDIAN +# define AV_RB64(x) AV_RN64(x) +# define AV_WB64(p, d) AV_WN64(p, d) + +# define AV_RL64(x) bswap_64(AV_RN64(x)) +# define AV_WL64(p, d) AV_WN64(p, bswap_64(d)) +# else /* WORDS_BIGENDIAN */ +# define AV_RB64(x) bswap_64(AV_RN64(x)) +# define AV_WB64(p, d) AV_WN64(p, bswap_64(d)) + +# define AV_RL64(x) AV_RN64(x) +# define AV_WL64(p, d) AV_WN64(p, d) +# endif +#else /* HAVE_FAST_UNALIGNED */ +#define AV_RB64(x) (((uint64_t)((const uint8_t*)(x))[0] << 56) | \ + ((uint64_t)((const uint8_t*)(x))[1] << 48) | \ + ((uint64_t)((const uint8_t*)(x))[2] << 40) | \ + ((uint64_t)((const uint8_t*)(x))[3] << 32) | \ + ((uint64_t)((const uint8_t*)(x))[4] << 24) | \ + ((uint64_t)((const uint8_t*)(x))[5] << 16) | \ + ((uint64_t)((const uint8_t*)(x))[6] << 8) | \ + (uint64_t)((const uint8_t*)(x))[7]) +#define AV_WB64(p, d) do { \ + ((uint8_t*)(p))[7] = (d); \ + ((uint8_t*)(p))[6] = (d)>>8; \ + ((uint8_t*)(p))[5] = (d)>>16; \ + ((uint8_t*)(p))[4] = (d)>>24; \ + ((uint8_t*)(p))[3] = (d)>>32; \ + ((uint8_t*)(p))[2] = (d)>>40; \ + ((uint8_t*)(p))[1] = (d)>>48; \ + ((uint8_t*)(p))[0] = (d)>>56; } while(0) + +#define AV_RL64(x) (((uint64_t)((const uint8_t*)(x))[7] << 56) | \ + ((uint64_t)((const uint8_t*)(x))[6] << 48) | \ + ((uint64_t)((const uint8_t*)(x))[5] << 40) | \ + ((uint64_t)((const uint8_t*)(x))[4] << 32) | \ + ((uint64_t)((const uint8_t*)(x))[3] << 24) | \ + ((uint64_t)((const uint8_t*)(x))[2] << 16) | \ + ((uint64_t)((const uint8_t*)(x))[1] << 8) | \ + (uint64_t)((const uint8_t*)(x))[0]) +#define AV_WL64(p, d) do { \ + ((uint8_t*)(p))[0] = (d); \ + ((uint8_t*)(p))[1] = (d)>>8; \ + ((uint8_t*)(p))[2] = (d)>>16; \ + ((uint8_t*)(p))[3] = (d)>>24; \ + ((uint8_t*)(p))[4] = (d)>>32; \ + ((uint8_t*)(p))[5] = (d)>>40; \ + ((uint8_t*)(p))[6] = (d)>>48; \ + ((uint8_t*)(p))[7] = (d)>>56; } while(0) +#endif + +#endif /* FFMPEG_INTREADWRITE_H */ diff --git a/contrib/ffmpeg/libavutil/lls.c b/contrib/ffmpeg/libavutil/lls.c index aa9467dce..b9d2d8168 100644 --- a/contrib/ffmpeg/libavutil/lls.c +++ b/contrib/ffmpeg/libavutil/lls.c @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** @@ -53,8 +53,8 @@ void av_update_lls(LLSModel *m, double *var, double decay){ void av_solve_lls(LLSModel *m, double threshold, int min_order){ int i,j,k; - double (*factor)[MAX_VARS+1]= &m->covariance[1][0]; - double (*covar )[MAX_VARS+1]= &m->covariance[1][1]; + double (*factor)[MAX_VARS+1]= (void*)&m->covariance[1][0]; + double (*covar )[MAX_VARS+1]= (void*)&m->covariance[1][1]; double *covar_y = m->covariance[0]; int count= m->indep_count; @@ -113,7 +113,7 @@ double av_evaluate_lls(LLSModel *m, double *param, int order){ #include #include -int main(){ +int main(void){ LLSModel m; int i, order; @@ -121,7 +121,7 @@ int main(){ for(i=0; i<100; i++){ double var[4]; - double eval, variance; + double eval; #if 0 var[1] = rand() / (double)RAND_MAX; var[2] = rand() / (double)RAND_MAX; diff --git a/contrib/ffmpeg/libavutil/lls.h b/contrib/ffmpeg/libavutil/lls.h index 59ad2e958..90b2332aa 100644 --- a/contrib/ffmpeg/libavutil/lls.h +++ b/contrib/ffmpeg/libavutil/lls.h @@ -17,11 +17,11 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef LLS_H -#define LLS_H +#ifndef FFMPEG_LLS_H +#define FFMPEG_LLS_H #define MAX_VARS 32 @@ -42,4 +42,4 @@ void av_update_lls(LLSModel *m, double *param, double decay); void av_solve_lls(LLSModel *m, double threshold, int min_order); double av_evaluate_lls(LLSModel *m, double *param, int order); -#endif +#endif /* FFMPEG_LLS_H */ diff --git a/contrib/ffmpeg/libavutil/log.c b/contrib/ffmpeg/libavutil/log.c index 4fd503d0d..fed0ce80a 100644 --- a/contrib/ffmpeg/libavutil/log.c +++ b/contrib/ffmpeg/libavutil/log.c @@ -45,11 +45,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) vfprintf(stderr, fmt, vl); } -#if LIBAVUTIL_VERSION_INT < (50<<16) static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback; -#else -void (*av_vlog)(void*, int, const char*, va_list) = av_log_default_callback; -#endif void av_log(void* avcl, int level, const char *fmt, ...) { @@ -59,7 +55,6 @@ void av_log(void* avcl, int level, const char *fmt, ...) va_end(vl); } -#if LIBAVUTIL_VERSION_INT < (50<<16) void av_vlog(void* avcl, int level, const char *fmt, va_list vl) { av_log_callback(avcl, level, fmt, vl); @@ -79,4 +74,3 @@ void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)) { av_log_callback = callback; } -#endif diff --git a/contrib/ffmpeg/libavutil/log.h b/contrib/ffmpeg/libavutil/log.h index fa88f5fb2..5d18197ef 100644 --- a/contrib/ffmpeg/libavutil/log.h +++ b/contrib/ffmpeg/libavutil/log.h @@ -18,8 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef LOG_H -#define LOG_H +#ifndef FFMPEG_LOG_H +#define FFMPEG_LOG_H #include @@ -81,7 +81,10 @@ struct AVCLASS { */ #define AV_LOG_DEBUG 48 #endif + +#if LIBAVUTIL_VERSION_INT < (50<<16) extern int av_log_level; +#endif /** * Send the specified message to the log if the level is less than or equal to @@ -103,14 +106,10 @@ extern void av_log(void*, int level, const char *fmt, ...) __attribute__ ((__for extern void av_log(void*, int level, const char *fmt, ...); #endif -#if LIBAVUTIL_VERSION_INT < (50<<16) extern void av_vlog(void*, int level, const char *fmt, va_list); extern int av_log_get_level(void); extern void av_log_set_level(int); extern void av_log_set_callback(void (*)(void*, int, const char*, va_list)); extern void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl); -#else -extern void (*av_vlog)(void*, int, const char*, va_list); -#endif -#endif /* LOG_H */ +#endif /* FFMPEG_LOG_H */ diff --git a/contrib/ffmpeg/libavutil/lzo.c b/contrib/ffmpeg/libavutil/lzo.c index d3849a743..d5d11867f 100644 --- a/contrib/ffmpeg/libavutil/lzo.c +++ b/contrib/ffmpeg/libavutil/lzo.c @@ -29,7 +29,7 @@ //! define if we may read up to 8 bytes beyond the input buffer #define INBUF_PADDED 1 typedef struct LZOContext { - uint8_t *in, *in_end; + const uint8_t *in, *in_end; uint8_t *out_start, *out, *out_end; int error; } LZOContext; @@ -84,7 +84,7 @@ static inline int get_len(LZOContext *c, int x, int mask) { * \param cnt number of bytes to copy, must be >= 0 */ static inline void copy(LZOContext *c, int cnt) { - register uint8_t *src = c->in; + register const uint8_t *src = c->in; register uint8_t *dst = c->out; if (cnt > c->in_end - src) { cnt = FFMAX(c->in_end - src, 0); @@ -115,7 +115,7 @@ static inline void copy(LZOContext *c, int cnt) { * thus creating a repeating pattern with a period length of back. */ static inline void copy_backptr(LZOContext *c, int back, int cnt) { - register uint8_t *src = &c->out[-back]; + register const uint8_t *src = &c->out[-back]; register uint8_t *dst = c->out; if (src < c->out_start || src > dst) { c->error |= LZO_INVALID_BACKPTR; @@ -171,12 +171,12 @@ static inline void copy_backptr(LZOContext *c, int back, int cnt) { * make sure all buffers are appropriately padded, in must provide * LZO_INPUT_PADDING, out must provide LZO_OUTPUT_PADDING additional bytes */ -int lzo1x_decode(void *out, int *outlen, void *in, int *inlen) { +int lzo1x_decode(void *out, int *outlen, const void *in, int *inlen) { int state= 0; int x; LZOContext c; c.in = in; - c.in_end = (uint8_t *)in + *inlen; + c.in_end = (const uint8_t *)in + *inlen; c.out = c.out_start = out; c.out_end = (uint8_t *)out + * outlen; c.error = 0; diff --git a/contrib/ffmpeg/libavutil/lzo.h b/contrib/ffmpeg/libavutil/lzo.h index 5b3d98f40..e7795f771 100644 --- a/contrib/ffmpeg/libavutil/lzo.h +++ b/contrib/ffmpeg/libavutil/lzo.h @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef LZO_H -#define LZO_H +#ifndef FFMPEG_LZO_H +#define FFMPEG_LZO_H #define LZO_INPUT_DEPLETED 1 #define LZO_OUTPUT_FULL 2 @@ -30,6 +30,6 @@ #define LZO_INPUT_PADDING 8 #define LZO_OUTPUT_PADDING 12 -int lzo1x_decode(void *out, int *outlen, void *in, int *inlen); +int lzo1x_decode(void *out, int *outlen, const void *in, int *inlen); -#endif +#endif /* FFMPEG_LZO_H */ diff --git a/contrib/ffmpeg/libavutil/mathematics.c b/contrib/ffmpeg/libavutil/mathematics.c index 4be027d9d..ef93ba4a1 100644 --- a/contrib/ffmpeg/libavutil/mathematics.c +++ b/contrib/ffmpeg/libavutil/mathematics.c @@ -26,11 +26,15 @@ #include "common.h" #include "mathematics.h" -const uint8_t ff_sqrt_tab[128]={ - 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, - 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11 +const uint8_t ff_sqrt_tab[256]={ + 0, 16, 23, 28, 32, 36, 40, 43, 46, 48, 51, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 77, 79, 80, 82, 84, 85, 87, 88, 90, + 91, 92, 94, 95, 96, 98, 99,100,102,103,104,105,107,108,109,110,111,112,114,115,116,117,118,119,120,121,122,123,124,125,126,127, +128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,144,145,146,147,148,149,150,151,151,152,153,154,155,156,156, +157,158,159,160,160,161,162,163,164,164,165,166,167,168,168,169,170,171,171,172,173,174,174,175,176,176,177,178,179,179,180,181, +182,182,183,184,184,185,186,186,187,188,188,189,190,190,191,192,192,193,194,194,195,196,196,197,198,198,199,200,200,201,202,202, +203,204,204,205,205,206,207,207,208,208,209,210,210,211,212,212,213,213,214,215,215,216,216,217,218,218,219,219,220,220,221,222, +222,223,223,224,224,225,226,226,227,227,228,228,229,230,230,231,231,232,232,233,233,234,235,235,236,236,237,237,238,238,239,239, +240,240,241,242,242,243,243,244,244,245,245,246,246,247,247,248,248,249,249,250,250,251,251,252,252,253,253,254,254,255,255,255 }; const uint8_t ff_log2_tab[256]={ @@ -110,10 +114,11 @@ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){ int64_t c= cq.num * (int64_t)bq.den; return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); } -#if 0 + +#ifdef TEST #include "integer.h" #undef printf -main(){ +int main(void){ int64_t a,b,c,d,e; for(a=7; a<(1LL<<62); a+=a/3+1){ @@ -135,5 +140,6 @@ main(){ } } } + return 0; } #endif diff --git a/contrib/ffmpeg/libavutil/mathematics.h b/contrib/ffmpeg/libavutil/mathematics.h index 0b74b254b..a0c286249 100644 --- a/contrib/ffmpeg/libavutil/mathematics.h +++ b/contrib/ffmpeg/libavutil/mathematics.h @@ -18,8 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef MATHEMATICS_H -#define MATHEMATICS_H +#ifndef FFMPEG_MATHEMATICS_H +#define FFMPEG_MATHEMATICS_H #include "rational.h" @@ -48,4 +48,4 @@ int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding); */ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq); -#endif /* MATHEMATICS_H */ +#endif /* FFMPEG_MATHEMATICS_H */ diff --git a/contrib/ffmpeg/libavutil/md5.c b/contrib/ffmpeg/libavutil/md5.c index f71703124..ee39de131 100644 --- a/contrib/ffmpeg/libavutil/md5.c +++ b/contrib/ffmpeg/libavutil/md5.c @@ -2,6 +2,17 @@ * Copyright (C) 2006 Michael Niedermayer (michaelni@gmx.at) * Copyright (C) 2003-2005 by Christopher R. Hertel (crh@ubiqx.mn.org) * + * References: + * IETF RFC 1321: The MD5 Message-Digest Algorithm + * Ron Rivest. IETF, April, 1992 + * + * based on http://ubiqx.org/libcifs/source/Auth/MD5.c + * from Christopher R. Hertel (crh@ubiqx.mn.org) + * Simplified, cleaned and IMO redundant comments removed by michael. + * + * If you use gcc, then version 4.1 or later and -fomit-frame-pointer is + * strongly recommended. + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -17,17 +28,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * References: - * IETF RFC 1321: The MD5 Message-Digest Algorithm - * Ron Rivest. IETF, April, 1992 - * - * based on http://ubiqx.org/libcifs/source/Auth/MD5.c - * from Christopher R. Hertel (crh@ubiqx.mn.org) - * simplified, cleaned and IMO redundant comments removed by michael - * - * if you use gcc, then version 4.1 or later and -fomit-frame-pointer is - * strongly recommended */ #include "common.h" @@ -87,7 +87,7 @@ static const uint32_t T[64] = { // T[i]= fabs(sin(i+1)<<32) static void body(uint32_t ABCD[4], uint32_t X[16]){ int t; - int i attribute_unused; + int i av_unused; unsigned int a= ABCD[3]; unsigned int b= ABCD[2]; unsigned int c= ABCD[1]; @@ -147,7 +147,7 @@ void av_md5_final(AVMD5 *ctx, uint8_t *dst){ while((ctx->len & 63)<56) av_md5_update(ctx, "", 1); - av_md5_update(ctx, &finalcount, 8); + av_md5_update(ctx, (uint8_t*)&finalcount, 8); for(i=0; i<4; i++) ((uint32_t*)dst)[i]= le2me_32(ctx->ABCD[3-i]); @@ -164,7 +164,7 @@ void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len){ #ifdef TEST #include #undef printf -main(){ +int main(void){ uint64_t md5val; int i; uint8_t in[1000]; @@ -176,5 +176,7 @@ main(){ av_md5_sum( (uint8_t*)&md5val, in, 65); printf("%"PRId64"\n", md5val); for(i=0; i<1000; i++) in[i]= i % 127; av_md5_sum( (uint8_t*)&md5val, in, 999); printf("%"PRId64"\n", md5val); + + return 0; } #endif diff --git a/contrib/ffmpeg/libavutil/md5.h b/contrib/ffmpeg/libavutil/md5.h index 8d1b4b5fe..7d63df01b 100644 --- a/contrib/ffmpeg/libavutil/md5.h +++ b/contrib/ffmpeg/libavutil/md5.h @@ -18,8 +18,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef MD5_H -#define MD5_H +#ifndef FFMPEG_MD5_H +#define FFMPEG_MD5_H + +#include extern const int av_md5_size; @@ -30,5 +32,5 @@ void av_md5_update(struct AVMD5 *ctx, const uint8_t *src, const int len); void av_md5_final(struct AVMD5 *ctx, uint8_t *dst); void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len); -#endif /* MD5_H */ +#endif /* FFMPEG_MD5_H */ diff --git a/contrib/ffmpeg/libavutil/mem.c b/contrib/ffmpeg/libavutil/mem.c index a91ac4a07..244475968 100644 --- a/contrib/ffmpeg/libavutil/mem.c +++ b/contrib/ffmpeg/libavutil/mem.c @@ -55,7 +55,7 @@ void *av_malloc(unsigned int size) if(!ptr) return ptr; diff= ((-(long)ptr - 1)&15) + 1; - ptr += diff; + ptr = (char*)ptr + diff; ((char*)ptr)[-1]= diff; #elif defined (HAVE_MEMALIGN) ptr = memalign(16,size); @@ -105,7 +105,7 @@ void *av_realloc(void *ptr, unsigned int size) //FIXME this isn't aligned correctly, though it probably isn't needed if(!ptr) return av_malloc(size); diff= ((char*)ptr)[-1]; - return realloc(ptr - diff, size + diff) + diff; + return (char*)realloc((char*)ptr - diff, size + diff) + diff; #else return realloc(ptr, size); #endif @@ -116,7 +116,7 @@ void av_free(void *ptr) /* XXX: this test should not be needed on most libcs */ if (ptr) #ifdef CONFIG_MEMALIGN_HACK - free(ptr - ((char*)ptr)[-1]); + free((char*)ptr - ((char*)ptr)[-1]); #else free(ptr); #endif diff --git a/contrib/ffmpeg/libavutil/mem.h b/contrib/ffmpeg/libavutil/mem.h index 4ebdad8f5..7bf707001 100644 --- a/contrib/ffmpeg/libavutil/mem.h +++ b/contrib/ffmpeg/libavutil/mem.h @@ -23,43 +23,84 @@ * Memory handling functions. */ -#ifndef AV_MEM_H -#define AV_MEM_H +#ifndef FFMPEG_MEM_H +#define FFMPEG_MEM_H -#ifdef __GNUC__ - #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n))) +#ifdef __ICC + #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n))) + #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v +#elif defined(__GNUC__) + #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n))) + #define DECLARE_ASM_CONST(n,t,v) static const t v attribute_used __attribute__ ((aligned (n))) +#elif defined(_MSC_VER) + #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v + #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v #else - #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v +// #warning No align and asm directives, this might fail. + #define DECLARE_ALIGNED(n,t,v) t v + #define DECLARE_ASM_CONST(n,t,v) static const t v #endif /** - * Memory allocation of size byte with alignment suitable for all - * memory accesses (including vectors if available on the - * CPU). av_malloc(0) must return a non NULL pointer. + * Allocate a block of \p size bytes with alignment suitable for all + * memory accesses (including vectors if available on the CPU). + * @param size Size in bytes for the memory block to be allocated. + * @return Pointer to the allocated block, NULL if it cannot allocate + * it. + * @see av_mallocz() */ void *av_malloc(unsigned int size); /** - * av_realloc semantics (same as glibc): if ptr is NULL and size > 0, - * identical to malloc(size). If size is zero, it is identical to - * free(ptr) and NULL is returned. + * Allocate or reallocate a block of memory. + * If \p ptr is NULL and \p size > 0, allocate a new block. If \p + * size is zero, free the memory block pointed by \p ptr. + * @param size Size in bytes for the memory block to be allocated or + * reallocated. + * @param ptr Pointer to a memory block already allocated with + * av_malloc(z)() or av_realloc() or NULL. + * @return Pointer to a newly reallocated block or NULL if it cannot + * reallocate or the function is used to free the memory block. + * @see av_fast_realloc() */ void *av_realloc(void *ptr, unsigned int size); /** - * Free memory which has been allocated with av_malloc(z)() or av_realloc(). - * NOTE: ptr = NULL is explicetly allowed - * Note2: it is recommended that you use av_freep() instead + * Free a memory block which has been allocated with av_malloc(z)() or + * av_realloc(). + * @param ptr Pointer to the memory block which should be freed. + * @note ptr = NULL is explicitly allowed. + * @note It is recommended that you use av_freep() instead. + * @see av_freep() */ void av_free(void *ptr); +/** + * Allocate a block of \p size bytes with alignment suitable for all + * memory accesses (including vectors if available on the CPU) and + * set to zeroes all the bytes of the block. + * @param size Size in bytes for the memory block to be allocated. + * @return Pointer to the allocated block, NULL if it cannot allocate + * it. + * @see av_malloc() + */ void *av_mallocz(unsigned int size); + +/** + * Duplicate the string \p s. + * @param s String to be duplicated. + * @return Pointer to a newly allocated string containing a + * copy of \p s or NULL if it cannot be allocated. + */ char *av_strdup(const char *s); /** - * Frees memory and sets the pointer to NULL. - * @param ptr pointer to the pointer which should be freed + * Free a memory block which has been allocated with av_malloc(z)() or + * av_realloc() and set to NULL the pointer to it. + * @param ptr Pointer to the pointer to the memory block which should + * be freed. + * @see av_free() */ void av_freep(void *ptr); -#endif /* AV_MEM_H */ +#endif /* FFMPEG_MEM_H */ diff --git a/contrib/ffmpeg/libavutil/random.h b/contrib/ffmpeg/libavutil/random.h index d9d08a5de..4d00d7e00 100644 --- a/contrib/ffmpeg/libavutil/random.h +++ b/contrib/ffmpeg/libavutil/random.h @@ -21,8 +21,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AV_RANDOM_H -#define AV_RANDOM_H +#ifndef FFMPEG_RANDOM_H +#define FFMPEG_RANDOM_H #define AV_RANDOM_N 624 @@ -65,5 +65,5 @@ static inline double av_random_real1(AVRandomState *state) // only available if DEBUG is defined in the .c file void av_benchmark_random(void); -#endif // AV_RANDOM_H +#endif /* FFMPEG_RANDOM_H */ diff --git a/contrib/ffmpeg/libavutil/rational.c b/contrib/ffmpeg/libavutil/rational.c index ac0c9d371..96a4c5462 100644 --- a/contrib/ffmpeg/libavutil/rational.c +++ b/contrib/ffmpeg/libavutil/rational.c @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** diff --git a/contrib/ffmpeg/libavutil/rational.h b/contrib/ffmpeg/libavutil/rational.h index 63c0b150f..f53f27861 100644 --- a/contrib/ffmpeg/libavutil/rational.h +++ b/contrib/ffmpeg/libavutil/rational.h @@ -17,7 +17,6 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ /** @@ -26,8 +25,10 @@ * @author Michael Niedermayer */ -#ifndef RATIONAL_H -#define RATIONAL_H +#ifndef FFMPEG_RATIONAL_H +#define FFMPEG_RATIONAL_H + +#include /** * Rational number num/den. @@ -99,7 +100,7 @@ AVRational av_add_q(AVRational b, AVRational c); * Subtracts one rational from another. * @param b first rational. * @param c second rational. - * returns b-c. + * @return b-c. */ AVRational av_sub_q(AVRational b, AVRational c); @@ -111,4 +112,4 @@ AVRational av_sub_q(AVRational b, AVRational c); */ AVRational av_d2q(double d, int max); -#endif // RATIONAL_H +#endif /* FFMPEG_RATIONAL_H */ diff --git a/contrib/ffmpeg/libavutil/rc4.c b/contrib/ffmpeg/libavutil/rc4.c new file mode 100644 index 000000000..0cf71a419 --- /dev/null +++ b/contrib/ffmpeg/libavutil/rc4.c @@ -0,0 +1,48 @@ +/* + * RC4 encryption/decryption/pseudo-random number generator + * Copyright (c) 2007 Reimar Doeffinger + * + * loosely based on LibTomCrypt by Tom St Denis + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "common.h" +#include "rc4.h" + +void ff_rc4_enc(const uint8_t *key, int keylen, uint8_t *data, int datalen) { + int i, j; + uint8_t x, y; + uint8_t state[256]; + for (i = 0; i < 256; i++) + state[i] = i; + y = 0; + // j is i % keylen + for (j = 0, i = 0; i < 256; i++, j++) { + if (j == keylen) j = 0; + y += state[i] + key[j]; + FFSWAP(uint8_t, state[i], state[y]); + } + // state initialized, now do the real encryption + x = 1; y = state[1]; + while (datalen-- > 0) { + uint8_t sum = state[x] + state[y]; + FFSWAP(uint8_t, state[x], state[y]); + *data++ ^= state[sum]; + x++; + y += state[x]; + } +} diff --git a/contrib/ffmpeg/libavutil/rc4.h b/contrib/ffmpeg/libavutil/rc4.h new file mode 100644 index 000000000..e06e12e9e --- /dev/null +++ b/contrib/ffmpeg/libavutil/rc4.h @@ -0,0 +1,28 @@ +/* + * RC4 encryption/decryption/pseudo-random number generator + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_RC4_H +#define FFMPEG_RC4_H + +#include + +void ff_rc4_enc(const uint8_t *key, int keylen, uint8_t *data, int datalen); + +#endif /* FFMPEG_RC4_H */ diff --git a/contrib/ffmpeg/libavutil/sha1.c b/contrib/ffmpeg/libavutil/sha1.c index 6c10791f4..61ad38de2 100644 --- a/contrib/ffmpeg/libavutil/sha1.c +++ b/contrib/ffmpeg/libavutil/sha1.c @@ -1,8 +1,26 @@ -// SHA-1 code Copyright 2007 Michael Nidermayer -// license LGPL -// based on public domain SHA-1 code by Steve Reid +/* + * Copyright (C) 2007 Michael Niedermayer + * based on public domain SHA-1 code by Steve Reid + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ #include "common.h" +#include "bswap.h" #include "sha1.h" typedef struct AVSHA1 { @@ -11,10 +29,12 @@ typedef struct AVSHA1 { uint32_t state[5]; } AVSHA1; +const int av_sha1_size = sizeof(AVSHA1); + #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ -#define blk0(i) (block[i] = be2me_32(((uint32_t*)buffer)[i])) +#define blk0(i) (block[i] = be2me_32(((const uint32_t*)buffer)[i])) #define blk(i) (block[i] = rol(block[i-3]^block[i-8]^block[i-14]^block[i-16],1)) #define R0(v,w,x,y,z,i) z+=((w&(x^y))^y) +blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); @@ -25,7 +45,7 @@ typedef struct AVSHA1 { /* Hash a single 512-bit block. This is the core of the algorithm. */ -static void transform(uint32_t state[5], uint8_t buffer[64]){ +static void transform(uint32_t state[5], const uint8_t buffer[64]){ uint32_t block[80]; unsigned int i, a, b, c, d, e; @@ -85,7 +105,7 @@ void av_sha1_init(AVSHA1* ctx){ ctx->count = 0; } -void av_sha1_update(AVSHA1* ctx, uint8_t* data, unsigned int len){ +void av_sha1_update(AVSHA1* ctx, const uint8_t* data, unsigned int len){ unsigned int i, j; j = ctx->count & 63; @@ -120,7 +140,7 @@ void av_sha1_final(AVSHA1* ctx, uint8_t digest[20]){ while ((ctx->count & 63) != 56) { av_sha1_update(ctx, "", 1); } - av_sha1_update(ctx, &finalcount, 8); /* Should cause a transform() */ + av_sha1_update(ctx, (uint8_t *)&finalcount, 8); /* Should cause a transform() */ for(i=0; i<5; i++) ((uint32_t*)digest)[i]= be2me_32(ctx->state[i]); } @@ -131,7 +151,7 @@ void av_sha1_final(AVSHA1* ctx, uint8_t digest[20]){ #include #undef printf -int main(){ +int main(void){ int i, k; AVSHA1 ctx; unsigned char digest[20]; diff --git a/contrib/ffmpeg/libavutil/sha1.h b/contrib/ffmpeg/libavutil/sha1.h index 8739cbde9..fc5bf0825 100644 --- a/contrib/ffmpeg/libavutil/sha1.h +++ b/contrib/ffmpeg/libavutil/sha1.h @@ -1,11 +1,34 @@ -#ifndef AV_SHA1_H -#define AV_SHA1_H +/* + * Copyright (C) 2007 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef FFMPEG_SHA1_H +#define FFMPEG_SHA1_H + +#include extern const int av_sha1_size; struct AVSHA1; void av_sha1_init(struct AVSHA1* context); -void av_sha1_update(struct AVSHA1* context, uint8_t* data, unsigned int len); +void av_sha1_update(struct AVSHA1* context, const uint8_t* data, unsigned int len); void av_sha1_final(struct AVSHA1* context, uint8_t digest[20]); -#endif + +#endif /* FFMPEG_SHA1_H */ diff --git a/contrib/ffmpeg/libavutil/softfloat.c b/contrib/ffmpeg/libavutil/softfloat.c index f12fd17a0..a5757c270 100644 --- a/contrib/ffmpeg/libavutil/softfloat.c +++ b/contrib/ffmpeg/libavutil/softfloat.c @@ -27,7 +27,7 @@ #undef printf -int main(){ +int main(void){ SoftFloat one= av_int2sf(1, 0); SoftFloat sf1, sf2; double d1, d2; diff --git a/contrib/ffmpeg/libavutil/softfloat.h b/contrib/ffmpeg/libavutil/softfloat.h index 5bb2c1cbc..d1a1901ea 100644 --- a/contrib/ffmpeg/libavutil/softfloat.h +++ b/contrib/ffmpeg/libavutil/softfloat.h @@ -16,9 +16,13 @@ * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ +#ifndef FFMPEG_SOFTFLOAT_H +#define FFMPEG_SOFTFLOAT_H + +#include + #define MIN_EXP -126 #define MAX_EXP 126 #define ONE_BITS 29 @@ -120,3 +124,5 @@ static inline int av_sf2int(SoftFloat v, int frac_bits){ if(v.exp >= 0) return v.mant << v.exp ; else return v.mant >>(-v.exp); } + +#endif /* FFMPEG_SOFTFLOAT_H */ diff --git a/contrib/ffmpeg/libavutil/string.c b/contrib/ffmpeg/libavutil/string.c new file mode 100644 index 000000000..8ee2a6b12 --- /dev/null +++ b/contrib/ffmpeg/libavutil/string.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard + * Copyright (c) 2007 Mans Rullgard + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include "avstring.h" + +int av_strstart(const char *str, const char *pfx, const char **ptr) +{ + while (*pfx && *pfx == *str) { + pfx++; + str++; + } + if (!*pfx && ptr) + *ptr = str; + return !*pfx; +} + +int av_stristart(const char *str, const char *pfx, const char **ptr) +{ + while (*pfx && toupper((unsigned)*pfx) == toupper((unsigned)*str)) { + pfx++; + str++; + } + if (!*pfx && ptr) + *ptr = str; + return !*pfx; +} + +size_t av_strlcpy(char *dst, const char *src, size_t size) +{ + size_t len = 0; + while (++len < size && *src) + *dst++ = *src++; + if (len <= size) + *dst = 0; + return len + strlen(src) - 1; +} + +size_t av_strlcat(char *dst, const char *src, size_t size) +{ + size_t len = strlen(dst); + if (size <= len + 1) + return len + strlen(src); + return len + av_strlcpy(dst + len, src, size - len); +} + +size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) +{ + int len = strlen(dst); + va_list vl; + + va_start(vl, fmt); + len += vsnprintf(dst + len, size > len ? size - len : 0, fmt, vl); + va_end(vl); + + return len; +} diff --git a/contrib/ffmpeg/libavutil/tree.c b/contrib/ffmpeg/libavutil/tree.c index c929e4819..cb442ff4b 100644 --- a/contrib/ffmpeg/libavutil/tree.c +++ b/contrib/ffmpeg/libavutil/tree.c @@ -28,58 +28,97 @@ typedef struct AVTreeNode{ int state; }AVTreeNode; +const int av_tree_node_size = sizeof(AVTreeNode); + void *av_tree_find(const AVTreeNode *t, void *key, int (*cmp)(void *key, const void *b), void *next[2]){ if(t){ - unsigned int v= cmp(t->elem, key); + unsigned int v= cmp(key, t->elem); if(v){ - if(next) next[(v>>31)^1]= t->elem; - return av_tree_find(t->child[v>>31], key, cmp, next); + if(next) next[v>>31]= t->elem; + return av_tree_find(t->child[(v>>31)^1], key, cmp, next); }else{ + if(next){ + av_tree_find(t->child[0], key, cmp, next); + av_tree_find(t->child[1], key, cmp, next); + } return t->elem; } } return NULL; } -void *av_tree_insert(AVTreeNode **tp, void *key, int (*cmp)(void *key, const void *b)){ +void *av_tree_insert(AVTreeNode **tp, void *key, int (*cmp)(void *key, const void *b), AVTreeNode **next){ AVTreeNode *t= *tp; if(t){ unsigned int v= cmp(t->elem, key); - if(v){ - int i= v>>31; + void *ret; + if(!v){ + if(*next) + return t->elem; + else if(t->child[0]||t->child[1]){ + int i= !t->child[0]; + void *next_elem[2]; + av_tree_find(t->child[i], key, cmp, next_elem); + key= t->elem= next_elem[i]; + v= -i; + }else{ + *next= t; + *tp=NULL; + return NULL; + } + } + ret= av_tree_insert(&t->child[v>>31], key, cmp, next); + if(!ret){ + int i= (v>>31) ^ !!*next; AVTreeNode **child= &t->child[i]; - void *ret= av_tree_insert(child, key, cmp); - if(!ret){ - t->state -= ((int)v>>31)|1; - if(!(t->state&1)){ - if(t->state){ - if((*child)->state*2 == t->state){ - *tp= *child; - *child= (*child)->child[i^1]; - (*tp)->child[i^1]= t; - t->state= 0; - }else{ - *tp= (*child)->child[i^1]; - (*child)->child[i^1]= (*tp)->child[i]; - (*tp)->child[i]= *child; - *child= (*tp)->child[i^1]; - (*tp)->child[i^1]= t; - - i= (*tp)->state > 0; - (*tp)->child[i ]->state= 0; - (*tp)->child[i^1]->state= -(*tp)->state; - } + t->state += 2*i - 1; + + if(!(t->state&1)){ + if(t->state){ + /* The following code is equivalent to + if((*child)->state*2 == -t->state) + rotate(child, i^1); + rotate(tp, i); + + with rotate(): + static void rotate(AVTreeNode **tp, int i){ + AVTreeNode *t= *tp; + + *tp= t->child[i]; + t->child[i]= t->child[i]->child[i^1]; + (*tp)->child[i^1]= t; + i= 4*t->state + 2*(*tp)->state + 12; + t ->state= ((0x614586 >> i) & 3)-1; + (*tp)->state= ((*tp)->state>>1) + ((0x400EEA >> i) & 3)-1; + } + but such a rotate function is both bigger and slower + */ + if((*child)->state*2 == -t->state){ + *tp= (*child)->child[i^1]; + (*child)->child[i^1]= (*tp)->child[i]; + (*tp)->child[i]= *child; + *child= (*tp)->child[i^1]; + (*tp)->child[i^1]= t; + + (*tp)->child[0]->state= -((*tp)->state>0); + (*tp)->child[1]->state= (*tp)->state<0 ; (*tp)->state=0; + }else{ + *tp= *child; + *child= (*child)->child[i^1]; + (*tp)->child[i^1]= t; + if((*tp)->state) t->state = 0; + else t->state>>= 1; + (*tp)->state= -t->state; } - return key; } } - return ret; - }else{ - return t->elem; + if(!(*tp)->state ^ !!*next) + return key; } + return ret; }else{ - *tp= av_mallocz(sizeof(AVTreeNode)); + *tp= *next; *next= NULL; (*tp)->elem= key; return NULL; } @@ -100,7 +139,7 @@ void av_tree_enumerate(AVTreeNode *t, void *opaque, int (*f)(void *opaque, void #endif #ifdef TEST - +#undef random static int check(AVTreeNode *t){ if(t){ int left= check(t->child[0]); @@ -132,19 +171,32 @@ int cmp(const void *a, const void *b){ return a-b; } -int main(){ - int i,j,k; - AVTreeNode *root= NULL; +int main(void){ + int i,k; + AVTreeNode *root= NULL, *node=NULL; for(i=0; i<10000; i++){ - int j= (random()%863294); + int j= (random()%86294); if(check(root) > 999){ av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i); print(root, 0); return -1; } av_log(NULL, AV_LOG_ERROR, "inserting %4d\n", j); - av_tree_insert(&root, (void*)(j+1), cmp); + if(!node) + node= av_mallocz(av_tree_node_size); + av_tree_insert(&root, (void*)(j+1), cmp, &node); + + j= (random()%86294); + k= av_tree_find(root, (void*)(j+1), cmp, NULL); + if(k){ + AVTreeNode *node2=NULL; + av_log(NULL, AV_LOG_ERROR, "removing %4d\n", j); + av_tree_insert(&root, (void*)(j+1), cmp, &node2); + k= av_tree_find(root, (void*)(j+1), cmp, NULL); + if(k) + av_log(NULL, AV_LOG_ERROR, "removial failure %d\n", i); + } } return 0; } diff --git a/contrib/ffmpeg/libavutil/tree.h b/contrib/ffmpeg/libavutil/tree.h index be1735858..111ea81a0 100644 --- a/contrib/ffmpeg/libavutil/tree.h +++ b/contrib/ffmpeg/libavutil/tree.h @@ -21,13 +21,16 @@ /** * @file tree.h * A tree container. + * Insertion, Removial, Finding equal, largest which is smaller than and + * smallest which is larger than all have O(log n) worst case time. * @author Michael Niedermayer */ -#ifndef TREE_H -#define TREE_H +#ifndef FFMPEG_TREE_H +#define FFMPEG_TREE_H struct AVTreeNode; +extern const int av_tree_node_size; /** * Finds an element. @@ -41,18 +44,39 @@ struct AVTreeNode; void *av_tree_find(const struct AVTreeNode *root, void *key, int (*cmp)(void *key, const void *b), void *next[2]); /** - * Finds a element for which cmp(key, elem)==0, if no such element is found key - * is inserted into the tree. + * Inserts or removes an element. + * If *next is NULL then the element supplied will be removed, if no such + * element exists behavior is undefined. + * If *next is not NULL then the element supplied will be inserted, unless + * it already exists in the tree. * @param rootp A pointer to a pointer to the root node of the tree. Note that * the root node can change during insertions, this is required * to keep the tree balanced. + * @param next Used to allocate and free AVTreeNodes. For insertion the user + * must set it to an allocated and zeroed object of at least + * av_tree_node_size bytes size. av_tree_insert() will set it to + * NULL if it has been consumed. + * For deleting elements *next is set to NULL by the user and + * av_tree_node_size() will set it to the AVTreeNode which was + * used for the removed element. + * This allows the use of flat arrays, which have + * lower overhead compared to many malloced elements. + * You might want to define a function like: + * void *tree_insert(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b), AVTreeNode **next){ + * if(!*next) *next= av_mallocz(av_tree_node_size); + * return av_tree_insert(rootp, key, cmp, next); + * } + * void *tree_remove(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b, AVTreeNode **next)){ + * if(*next) av_freep(next); + * return av_tree_insert(rootp, key, cmp, next); + * } * * @return If no insertion happened, the found element. - * If an insertion happened, then either key or NULL will be returned. + * If an insertion or removial happened, then either key or NULL will be returned. * Which one it is depends on the tree state and the implementation. You * should make no assumptions that it's one or the other in the code. */ -void *av_tree_insert(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b)); +void *av_tree_insert(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b), struct AVTreeNode **next); void av_tree_destroy(struct AVTreeNode *t); -#endif /* TREE_H */ +#endif /* FFMPEG_TREE_H */ diff --git a/contrib/ffmpeg/libavutil/x86_cpu.h b/contrib/ffmpeg/libavutil/x86_cpu.h index 67d4cd9aa..5ab570405 100644 --- a/contrib/ffmpeg/libavutil/x86_cpu.h +++ b/contrib/ffmpeg/libavutil/x86_cpu.h @@ -18,47 +18,51 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef AVUTIL_X86CPU_H -#define AVUTIL_X86CPU_H +#ifndef FFMPEG_X86CPU_H +#define FFMPEG_X86CPU_H #ifdef ARCH_X86_64 -# define REG_a "rax" -# define REG_b "rbx" -# define REG_c "rcx" -# define REG_d "rdx" -# define REG_D "rdi" -# define REG_S "rsi" -# define PTR_SIZE "8" +# define REG_a "rax" +# define REG_b "rbx" +# define REG_c "rcx" +# define REG_d "rdx" +# define REG_D "rdi" +# define REG_S "rsi" +# define PTR_SIZE "8" -# define REG_SP "rsp" -# define REG_BP "rbp" -# define REGBP rbp -# define REGa rax -# define REGb rbx -# define REGc rcx -# define REGSP rsp +# define REG_SP "rsp" +# define REG_BP "rbp" +# define REGBP rbp +# define REGa rax +# define REGb rbx +# define REGc rcx +# define REGSP rsp #else -# define REG_a "eax" -# define REG_b "ebx" -# define REG_c "ecx" -# define REG_d "edx" -# define REG_D "edi" -# define REG_S "esi" -# define PTR_SIZE "4" +# define REG_a "eax" +# define REG_b "ebx" +# define REG_c "ecx" +# define REG_d "edx" +# define REG_D "edi" +# define REG_S "esi" +# define PTR_SIZE "4" -# define REG_SP "esp" -# define REG_BP "ebp" -# define REGBP ebp -# define REGa eax -# define REGb ebx -# define REGc ecx -# define REGSP esp +# define REG_SP "esp" +# define REG_BP "ebp" +# define REGBP ebp +# define REGa eax +# define REGb ebx +# define REGc ecx +# define REGSP esp #endif -#if defined(ARCH_X86_64) || (defined(ARCH_X86_32) && defined(CONFIG_EBX_AVAILABLE) && defined(CONFIG_EBP_AVAILABLE)) -# define CONFIG_7REGS 1 +#if defined(ARCH_X86_64) || (defined(ARCH_X86_32) && defined(HAVE_EBX_AVAILABLE) && defined(HAVE_EBP_AVAILABLE)) +# define HAVE_7REGS 1 #endif -#endif /* AVUTIL_X86CPU_H */ +#if defined(ARCH_X86_64) && defined(PIC) +# define BROKEN_RELOCATIONS 1 +#endif + +#endif /* FFMPEG_X86CPU_H */ diff --git a/contrib/ffmpeg/libpostproc/Makefile b/contrib/ffmpeg/libpostproc/Makefile index d30b4a18d..8a285c6b0 100644 --- a/contrib/ffmpeg/libpostproc/Makefile +++ b/contrib/ffmpeg/libpostproc/Makefile @@ -1,24 +1,14 @@ include ../config.mak -# Overload incdir, postproc include files go in a different directory. -incdir=$(prefix)/include/postproc - EXTRALIBS := -L$(BUILD_ROOT)/libavutil -lavutil$(BUILDSUF) $(EXTRALIBS) NAME=postproc LIBVERSION=$(SPPVERSION) LIBMAJOR=$(SPPMAJOR) -STATIC_OBJS=postprocess.o -SHARED_OBJS=postprocess_pic.o - HEADERS = postprocess.h -include ../common.mak - -depend dep: postprocess.c - -postprocess_pic.o: postprocess.c - $(CC) -c $(CFLAGS) -fomit-frame-pointer -fPIC -DPIC -o $@ $< +OBJS = postprocess.o +include ../common.mak diff --git a/contrib/ffmpeg/libpostproc/mangle.h b/contrib/ffmpeg/libpostproc/mangle.h deleted file mode 100644 index 3521fa9bb..000000000 --- a/contrib/ffmpeg/libpostproc/mangle.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * mangle.h - This file has some CPP macros to deal with different symbol - * mangling across binary formats. - * - * (c)2002 by Felix Buenemann - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * FFmpeg 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef __MANGLE_H -#define __MANGLE_H - -/* Feel free to add more to the list, eg. a.out IMO */ -/* Use rip-relative addressing if compiling PIC code on x86-64. */ -#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__OS2__) || \ - (defined(__OpenBSD__) && !defined(__ELF__)) -#if defined(ARCH_X86_64) && defined(PIC) -#define MANGLE(a) "_" #a"(%%rip)" -#else -#define MANGLE(a) "_" #a -#endif -#else -#if defined(ARCH_X86_64) && defined(PIC) -#define MANGLE(a) #a"(%%rip)" -#elif defined(CONFIG_DARWIN) -#define MANGLE(a) "_" #a -#else -#define MANGLE(a) #a -#endif -#endif - -#endif /* !__MANGLE_H */ - diff --git a/contrib/ffmpeg/libpostproc/postprocess.c b/contrib/ffmpeg/libpostproc/postprocess.c index f68c8a723..b274bb47c 100644 --- a/contrib/ffmpeg/libpostproc/postprocess.c +++ b/contrib/ffmpeg/libpostproc/postprocess.c @@ -47,8 +47,8 @@ LinBlendDeinterlace e E E* MedianDeinterlace# E Ec Ec TempDeNoiser# E e e Ec -* i dont have a 3dnow CPU -> its untested, but noone said it doesnt work so it seems to work -# more or less selfinvented filters so the exactness isnt too meaningfull +* i do not have a 3DNow! CPU -> it is untested, but no one said it does not work so it seems to work +# more or less selfinvented filters so the exactness is not too meaningful E = Exact implementation e = allmost exact implementation (slightly different rounding,...) a = alternative / approximate impl @@ -87,14 +87,9 @@ try to unroll inner for(x=0 ... loop to avoid these damn if(x ... checks //#undef HAVE_MMX //#undef ARCH_X86 //#define DEBUG_BRIGHTNESS -#ifdef USE_FASTMEMCPY -#include "libvo/fastmemcpy.h" -#endif #include "postprocess.h" #include "postprocess_internal.h" -#include "mangle.h" //FIXME should be supressed - #ifdef HAVE_ALTIVEC_H #include #endif @@ -106,20 +101,17 @@ try to unroll inner for(x=0 ... loop to avoid these damn if(x ... checks //#define NUM_BLOCKS_AT_ONCE 16 //not used yet #if defined(ARCH_X86) -static uint64_t __attribute__((aligned(8))) attribute_used w05= 0x0005000500050005LL; -static uint64_t __attribute__((aligned(8))) attribute_used w04= 0x0004000400040004LL; -static uint64_t __attribute__((aligned(8))) attribute_used w20= 0x0020002000200020LL; -static uint64_t __attribute__((aligned(8))) attribute_used b00= 0x0000000000000000LL; -static uint64_t __attribute__((aligned(8))) attribute_used b01= 0x0101010101010101LL; -static uint64_t __attribute__((aligned(8))) attribute_used b02= 0x0202020202020202LL; -static uint64_t __attribute__((aligned(8))) attribute_used b08= 0x0808080808080808LL; -static uint64_t __attribute__((aligned(8))) attribute_used b80= 0x8080808080808080LL; +DECLARE_ASM_CONST(8, uint64_t, w05)= 0x0005000500050005LL; +DECLARE_ASM_CONST(8, uint64_t, w04)= 0x0004000400040004LL; +DECLARE_ASM_CONST(8, uint64_t, w20)= 0x0020002000200020LL; +DECLARE_ASM_CONST(8, uint64_t, b00)= 0x0000000000000000LL; +DECLARE_ASM_CONST(8, uint64_t, b01)= 0x0101010101010101LL; +DECLARE_ASM_CONST(8, uint64_t, b02)= 0x0202020202020202LL; +DECLARE_ASM_CONST(8, uint64_t, b08)= 0x0808080808080808LL; +DECLARE_ASM_CONST(8, uint64_t, b80)= 0x8080808080808080LL; #endif -static uint8_t clip_table[3*256]; -static uint8_t * const clip_tab= clip_table + 256; - -static const int attribute_used deringThreshold= 20; +DECLARE_ASM_CONST(8, int, deringThreshold)= 20; static struct PPFilter filters[]= @@ -147,11 +139,11 @@ static struct PPFilter filters[]= static const char *replaceTable[]= { - "default", "hdeblock:a,vdeblock:a,dering:a", - "de", "hdeblock:a,vdeblock:a,dering:a", - "fast", "x1hdeblock:a,x1vdeblock:a,dering:a", - "fa", "x1hdeblock:a,x1vdeblock:a,dering:a", - "ac", "ha:a:128:7,va:a,dering:a", + "default", "hb:a,vb:a,dr:a", + "de", "hb:a,vb:a,dr:a", + "fast", "h1:a,v1:a,dr:a", + "fa", "h1:a,v1:a,dr:a", + "ac", "ha:a:128:7,va:a,dr:a", NULL //End Marker }; @@ -401,8 +393,8 @@ static inline void doHorizLowPass_C(uint8_t dst[], int stride, PPContext *c) * Experimental Filter 1 (Horizontal) * will not damage linear gradients * Flat blocks should look like they where passed through the (1,1,2,2,4,2,2,1,1) 9-Tap filter - * can only smooth blocks at the expected locations (it cant smooth them if they did move) - * MMX2 version does correct clipping C version doesnt + * can only smooth blocks at the expected locations (it cannot smooth them if they did move) + * MMX2 version does correct clipping C version does not * not identical with the vertical one */ static inline void horizX1Filter(uint8_t *src, int stride, int QP) @@ -649,18 +641,18 @@ static av_always_inline void do_a_deblock_C(uint8_t *src, int step, int stride, #include "postprocess_template.c" #endif -// minor note: the HAVE_xyz is messed up after that line so dont use it +// minor note: the HAVE_xyz is messed up after that line so do not use it. -static inline void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height, - QP_STORE_T QPs[], int QPStride, int isColor, pp_mode_t *vm, pp_context_t *vc) +static inline void postProcess(const uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height, + const QP_STORE_T QPs[], int QPStride, int isColor, pp_mode_t *vm, pp_context_t *vc) { PPContext *c= (PPContext *)vc; PPMode *ppMode= (PPMode *)vm; c->ppMode= *ppMode; //FIXME - // useing ifs here as they are faster than function pointers allthough the - // difference wouldnt be messureable here but its much better because - // someone might exchange the cpu whithout restarting mplayer ;) + // Using ifs here as they are faster than function pointers although the + // difference would not be measureable here but it is much better because + // someone might exchange the CPU whithout restarting MPlayer ;) #ifdef RUNTIME_CPUDETECT #if defined(ARCH_X86) // ordered per speed fasterst first @@ -702,7 +694,11 @@ static inline void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int /* -pp Command line Help */ -char *pp_help= +#if LIBPOSTPROC_VERSION_INT < (52<<16) +const char *const pp_help= +#else +const char pp_help[] = +#endif "Available postprocessing filters:\n" "Filters Options\n" "short long name short long option Description\n" @@ -746,12 +742,12 @@ char *pp_help= "\n" ; -pp_mode_t *pp_get_mode_by_name_and_quality(char *name, int quality) +pp_mode_t *pp_get_mode_by_name_and_quality(const char *name, int quality) { char temp[GET_MODE_BUFFER_SIZE]; char *p= temp; - const char *filterDelimiters= ",/"; - const char *optionDelimiters= ":"; + static const char filterDelimiters[] = ",/"; + static const char optionDelimiters[] = ":"; struct PPMode *ppMode; char *filterToken; @@ -964,7 +960,7 @@ static void reallocBuffers(PPContext *c, int width, int height, int stride, int for(i=0; i<3; i++) { - //Note:the +17*1024 is just there so i dont have to worry about r/w over te end + //Note: The +17*1024 is just there so i do not have to worry about r/w over the end. reallocAlign((void **)&c->tempBlured[i], 8, stride*mbHeight*16 + 17*1024); reallocAlign((void **)&c->tempBluredPast[i], 8, 256*((height+7)&(~7))/2 + 17*1024);//FIXME size } @@ -975,27 +971,17 @@ static void reallocBuffers(PPContext *c, int width, int height, int stride, int reallocAlign((void **)&c->forcedQPTable, 8, mbWidth*sizeof(QP_STORE_T)); } -static void global_init(void){ - int i; - memset(clip_table, 0, 256); - for(i=256; i<512; i++) - clip_table[i]= i; - memset(clip_table+512, 0, 256); -} - static const char * context_to_name(void * ptr) { return "postproc"; } -static AVClass av_codec_context_class = { "Postproc", context_to_name, NULL }; +static const AVClass av_codec_context_class = { "Postproc", context_to_name, NULL }; pp_context_t *pp_get_context(int width, int height, int cpuCaps){ PPContext *c= av_malloc(sizeof(PPContext)); int stride= (width+15)&(~15); //assumed / will realloc if needed int qpStride= (width+15)/16 + 2; //assumed / will realloc if needed - global_init(); - memset(c, 0, sizeof(PPContext)); c->av_class = &av_codec_context_class; c->cpuCaps= cpuCaps; @@ -1035,10 +1021,10 @@ void pp_free_context(void *vc){ av_free(c); } -void pp_postprocess(uint8_t * src[3], int srcStride[3], - uint8_t * dst[3], int dstStride[3], +void pp_postprocess(const uint8_t * src[3], const int srcStride[3], + uint8_t * dst[3], const int dstStride[3], int width, int height, - QP_STORE_T *QP_store, int QPStride, + const QP_STORE_T *QP_store, int QPStride, pp_mode_t *vm, void *vc, int pict_type) { int mbWidth = (width+15)>>4; @@ -1060,16 +1046,16 @@ void pp_postprocess(uint8_t * src[3], int srcStride[3], QP_store= c->forcedQPTable; absQPStride = QPStride = 0; if(mode->lumMode & FORCE_QUANT) - for(i=0; iforcedQuant; + for(i=0; iforcedQPTable[i]= mode->forcedQuant; else - for(i=0; iforcedQPTable[i]= 1; } if(pict_type & PP_PICT_TYPE_QP2){ int i; const int count= mbHeight * absQPStride; for(i=0; i<(count>>2); i++){ - ((uint32_t*)c->stdQPTable)[i] = (((uint32_t*)QP_store)[i]>>1) & 0x7F7F7F7F; + ((uint32_t*)c->stdQPTable)[i] = (((const uint32_t*)QP_store)[i]>>1) & 0x7F7F7F7F; } for(i<<=2; istdQPTable[i] = QP_store[i]>>1; @@ -1095,7 +1081,7 @@ for(y=0; y>2); i++){ - ((uint32_t*)c->nonBQPTable)[i] = ((uint32_t*)QP_store)[i] & 0x3F3F3F3F; + ((uint32_t*)c->nonBQPTable)[i] = ((const uint32_t*)QP_store)[i] & 0x3F3F3F3F; } for(i<<=2; inonBQPTable[i] = QP_store[i] & 0x3F; diff --git a/contrib/ffmpeg/libpostproc/postprocess.h b/contrib/ffmpeg/libpostproc/postprocess.h index eed92ba6d..818fb41ba 100644 --- a/contrib/ffmpeg/libpostproc/postprocess.h +++ b/contrib/ffmpeg/libpostproc/postprocess.h @@ -18,8 +18,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef NEWPOSTPROCESS_H -#define NEWPOSTPROCESS_H +#ifndef FFMPEG_POSTPROCESS_H +#define FFMPEG_POSTPROCESS_H /** * @file postprocess.h @@ -27,12 +27,18 @@ * external api for the pp stuff */ -#ifdef __cplusplus -extern "C" { -#endif +#include "libavutil/avutil.h" + +#define LIBPOSTPROC_VERSION_MAJOR 51 +#define LIBPOSTPROC_VERSION_MINOR 1 +#define LIBPOSTPROC_VERSION_MICRO 0 -#define LIBPOSTPROC_VERSION_INT ((51<<16)+(1<<8)+0) -#define LIBPOSTPROC_VERSION 51.1.0 +#define LIBPOSTPROC_VERSION_INT AV_VERSION_INT(LIBPOSTPROC_VERSION_MAJOR, \ + LIBPOSTPROC_VERSION_MINOR, \ + LIBPOSTPROC_VERSION_MICRO) +#define LIBPOSTPROC_VERSION AV_VERSION(LIBPOSTPROC_VERSION_MAJOR, \ + LIBPOSTPROC_VERSION_MINOR, \ + LIBPOSTPROC_VERSION_MICRO) #define LIBPOSTPROC_BUILD LIBPOSTPROC_VERSION_INT #define LIBPOSTPROC_IDENT "postproc" AV_STRINGIFY(LIBPOSTPROC_VERSION) @@ -41,15 +47,21 @@ extern "C" { #define QP_STORE_T int8_t +#include + typedef void pp_context_t; typedef void pp_mode_t; -extern char *pp_help; ///< a simple help text +#if LIBPOSTPROC_VERSION_INT < (52<<16) +extern const char *const pp_help; ///< a simple help text +#else +extern const char pp_help[]; ///< a simple help text +#endif -void pp_postprocess(uint8_t * src[3], int srcStride[3], - uint8_t * dst[3], int dstStride[3], +void pp_postprocess(const uint8_t * src[3], const int srcStride[3], + uint8_t * dst[3], const int dstStride[3], int horizontalSize, int verticalSize, - QP_STORE_T *QP_store, int QP_stride, + const QP_STORE_T *QP_store, int QP_stride, pp_mode_t *mode, pp_context_t *ppContext, int pict_type); @@ -58,7 +70,7 @@ void pp_postprocess(uint8_t * src[3], int srcStride[3], * name is the string after "-pp" on the command line * quality is a number from 0 to PP_QUALITY_MAX */ -pp_mode_t *pp_get_mode_by_name_and_quality(char *name, int quality); +pp_mode_t *pp_get_mode_by_name_and_quality(const char *name, int quality); void pp_free_mode(pp_mode_t *mode); pp_context_t *pp_get_context(int width, int height, int flags); @@ -77,8 +89,4 @@ void pp_free_context(pp_context_t *ppContext); #define PP_PICT_TYPE_QP2 0x00000010 ///< MPEG2 style QScale -#ifdef __cplusplus -} -#endif - -#endif +#endif /* FFMPEG_POSTPROCESS_H */ diff --git a/contrib/ffmpeg/libpostproc/postprocess_altivec_template.c b/contrib/ffmpeg/libpostproc/postprocess_altivec_template.c index 6a76c0eb7..e93ce7ef8 100644 --- a/contrib/ffmpeg/libpostproc/postprocess_altivec_template.c +++ b/contrib/ffmpeg/libpostproc/postprocess_altivec_template.c @@ -22,12 +22,6 @@ #include "avutil.h" -#ifdef CONFIG_DARWIN -#define AVV(x...) (x) -#else -#define AVV(x...) {x} -#endif - #define ALTIVEC_TRANSPOSE_8x8_SHORT(src_a,src_b,src_c,src_d,src_e,src_f,src_g,src_h) \ do { \ __typeof__(src_a) tempA1, tempB1, tempC1, tempD1; \ @@ -200,7 +194,7 @@ static inline void doVertLowPass_altivec(uint8_t *src, int stride, PPContext *c) One could remove the recomputation of the perm vector by assuming (stride % 16) == 0, unfortunately this is not always true. Quite a lot of load/stores - can be removed by assuming proper alignement of + can be removed by assuming proper alignment of src & stride :-( */ uint8_t *src2 = src; @@ -388,7 +382,7 @@ static inline void doVertDefFilter_altivec(uint8_t src[], int stride, PPContext One could remove the recomputation of the perm vector by assuming (stride % 16) == 0, unfortunately this is not always true. Quite a lot of load/stores - can be removed by assuming proper alignement of + can be removed by assuming proper alignment of src & stride :-( */ uint8_t *src2 = src; @@ -475,7 +469,7 @@ static inline void doVertDefFilter_altivec(uint8_t src[], int stride, PPContext const vector signed short dornotd = vec_sel((vector signed short)zero, dclampedfinal, vec_cmplt(absmE, vqp)); - /* add/substract to l4 and l5 */ + /* add/subtract to l4 and l5 */ const vector signed short vb4minusd = vec_sub(vb4, dornotd); const vector signed short vb5plusd = vec_add(vb5, dornotd); /* finally, stores */ @@ -512,7 +506,7 @@ static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { One could remove the recomputation of the perm vector by assuming (stride % 16) == 0, unfortunately this is not always true. Quite a lot of load/stores - can be removed by assuming proper alignement of + can be removed by assuming proper alignment of src & stride :-( */ uint8_t *srcCopy = src; diff --git a/contrib/ffmpeg/libpostproc/postprocess_internal.h b/contrib/ffmpeg/libpostproc/postprocess_internal.h index 537d728c0..f2d40e1d5 100644 --- a/contrib/ffmpeg/libpostproc/postprocess_internal.h +++ b/contrib/ffmpeg/libpostproc/postprocess_internal.h @@ -23,7 +23,11 @@ * internal api header. */ +#ifndef FFMPEG_POSTPROCESS_INTERNAL_H +#define FFMPEG_POSTPROCESS_INTERNAL_H + #include "avutil.h" +#include "postprocess.h" #define V_DEBLOCK 0x01 #define H_DEBLOCK 0x02 @@ -62,27 +66,16 @@ #define TEMP_NOISE_FILTER 0x100000 #define FORCE_QUANT 0x200000 -#if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC) -# define PIC -#endif - -//use if u want a faster postprocessing code -//cant differentiate between chroma & luma filters (both on or both off) -//obviosly the -pp option at the commandline has no effect except turning the here selected +//use if you want a faster postprocessing code +//cannot differentiate between chroma & luma filters (both on or both off) +//obviously the -pp option on the command line has no effect except turning the here selected //filters on //#define COMPILE_TIME_MODE 0x77 -#if 1 static inline int CLIP(int a){ if(a&256) return ((a)>>31)^(-1); else return a; } -//#define CLIP(a) (((a)&256) ? ((a)>>31)^(-1) : (a)) -#elif 0 -#define CLIP(a) clip_tab[a] -#else -#define CLIP(a) (a) -#endif /** * Postprocessng filter. */ @@ -122,7 +115,7 @@ typedef struct PPContext{ /** * info on struct for av_log */ - AVClass *av_class; + const AVClass *av_class; uint8_t *tempBlocks; /// 0) { memcpy(dest, src, lines*stride); } else { - memcpy(dest+(lines-1)*stride, src+(lines-1)*stride, -lines*stride); + memcpy((uint8_t*)dest+(lines-1)*stride, (const uint8_t*)src+(lines-1)*stride, -lines*stride); } } + +#endif /* FFMPEG_POSTPROCESS_INTERNAL_H */ diff --git a/contrib/ffmpeg/libpostproc/postprocess_template.c b/contrib/ffmpeg/libpostproc/postprocess_template.c index f084130a6..bdc23250a 100644 --- a/contrib/ffmpeg/libpostproc/postprocess_template.c +++ b/contrib/ffmpeg/libpostproc/postprocess_template.c @@ -16,7 +16,7 @@ * You should have received a copy of the GNU General Public License * along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + */ /** * @file postprocess_template.c @@ -73,7 +73,7 @@ "paddb " #a ", " #b " \n\t" #endif -//FIXME? |255-0| = 1 (shouldnt be a problem ...) +//FIXME? |255-0| = 1 (should not be a problem ...) #ifdef HAVE_MMX /** * Check if the middle 8x8 Block in the given 8x16 block is flat @@ -373,7 +373,8 @@ static inline void RENAME(doVertLowPass)(uint8_t *src, int stride, PPContext *c) * Experimental implementation of the filter (Algorithm 1) described in a paper from Ramkishor & Karandikar * values are correctly clipped (MMX2) * values are wraparound (C) - * conclusion: its fast, but introduces ugly horizontal patterns if there is a continious gradient + * Conclusion: It is fast, but introduces ugly horizontal patterns + * if there is a continuous gradient. 0 8 16 24 x = 8 x/2 = 4 @@ -478,8 +479,8 @@ static inline void RENAME(vertRK1Filter)(uint8_t *src, int stride, int QP) * Experimental Filter 1 * will not damage linear gradients * Flat blocks should look like they where passed through the (1,1,2,2,4,2,2,1,1) 9-Tap filter - * can only smooth blocks at the expected locations (it cant smooth them if they did move) - * MMX2 version does correct clipping C version doesnt + * can only smooth blocks at the expected locations (it cannot smooth them if they did move) + * MMX2 version does correct clipping C version does not */ static inline void RENAME(vertX1Filter)(uint8_t *src, int stride, PPContext *co) { @@ -3179,16 +3180,16 @@ asm volatile( } #endif //HAVE_MMX -static void RENAME(postProcess)(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height, - QP_STORE_T QPs[], int QPStride, int isColor, PPContext *c); +static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height, + const QP_STORE_T QPs[], int QPStride, int isColor, PPContext *c); /** - * Copies a block from src to dst and fixes the blacklevel - * levelFix == 0 -> dont touch the brighness & contrast + * Copies a block from src to dst and fixes the blacklevel. + * levelFix == 0 -> do not touch the brighness & contrast */ #undef SCALED_CPY -static inline void RENAME(blockCopy)(uint8_t dst[], int dstStride, uint8_t src[], int srcStride, +static inline void RENAME(blockCopy)(uint8_t dst[], int dstStride, const uint8_t src[], int srcStride, int levelFix, int64_t *packedOffsetAndScale) { #ifndef HAVE_MMX @@ -3345,10 +3346,10 @@ static inline void RENAME(duplicate)(uint8_t src[], int stride) /** * Filters array of bytes (Y or U or V values) */ -static void RENAME(postProcess)(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height, - QP_STORE_T QPs[], int QPStride, int isColor, PPContext *c2) +static void RENAME(postProcess)(const uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height, + const QP_STORE_T QPs[], int QPStride, int isColor, PPContext *c2) { - PPContext __attribute__((aligned(8))) c= *c2; //copy to stack for faster access + DECLARE_ALIGNED(8, PPContext, c)= *c2; //copy to stack for faster access int x,y; #ifdef COMPILE_TIME_MODE const int mode= COMPILE_TIME_MODE; @@ -3415,7 +3416,7 @@ static void RENAME(postProcess)(uint8_t src[], int srcStride, uint8_t dst[], int sum+= yHistogram[i]; } - /* we allways get a completly black picture first */ + /* We always get a completely black picture first. */ maxClipped= (uint64_t)(sum * c.ppMode.maxClippedThreshold); clipped= sum; @@ -3461,7 +3462,7 @@ static void RENAME(postProcess)(uint8_t src[], int srcStride, uint8_t dst[], int /* copy & deinterlace first row of blocks */ y=-BLOCK_SIZE; { - uint8_t *srcBlock= &(src[y*srcStride]); + const uint8_t *srcBlock= &(src[y*srcStride]); uint8_t *dstBlock= tempDst + dstStride; // From this point on it is guaranteed that we can read and write 16 lines downward @@ -3498,7 +3499,7 @@ static void RENAME(postProcess)(uint8_t src[], int srcStride, uint8_t dst[], int ); #elif defined(HAVE_3DNOW) -//FIXME check if this is faster on an 3dnow chip or if its faster without the prefetch or ... +//FIXME check if this is faster on an 3dnow chip or if it is faster without the prefetch or ... /* prefetch(srcBlock + (((x>>3)&3) + 5)*srcStride + 32); prefetch(srcBlock + (((x>>3)&3) + 9)*srcStride + 32); prefetchw(dstBlock + (((x>>3)&3) + 5)*dstStride + 32); @@ -3544,13 +3545,13 @@ static void RENAME(postProcess)(uint8_t src[], int srcStride, uint8_t dst[], int for(y=0; y>qpVShift)*QPStride]; + const int8_t *QPptr= &QPs[(y>>qpVShift)*QPStride]; int8_t *nonBQPptr= &c.nonBQPTable[(y>>qpVShift)*FFABS(QPStride)]; int QP=0; /* can we mess with a 8x16 block from srcBlock/dstBlock downwards and 1 line upwards @@ -3642,7 +3643,7 @@ static void RENAME(postProcess)(uint8_t src[], int srcStride, uint8_t dst[], int ); #elif defined(HAVE_3DNOW) -//FIXME check if this is faster on an 3dnow chip or if its faster without the prefetch or ... +//FIXME check if this is faster on an 3dnow chip or if it is faster without the prefetch or ... /* prefetch(srcBlock + (((x>>3)&3) + 5)*srcStride + 32); prefetch(srcBlock + (((x>>3)&3) + 9)*srcStride + 32); prefetchw(dstBlock + (((x>>3)&3) + 5)*dstStride + 32); @@ -3717,7 +3718,7 @@ static void RENAME(postProcess)(uint8_t src[], int srcStride, uint8_t dst[], int else if(mode & H_DEBLOCK) { #ifdef HAVE_ALTIVEC - unsigned char __attribute__ ((aligned(16))) tempBlock[272]; + DECLARE_ALIGNED(16, unsigned char, tempBlock[272]); transpose_16x8_char_toPackedAlign_altivec(tempBlock, dstBlock - (4 + 1), stride); const int t=vertClassify_altivec(tempBlock-48, 16, &c); diff --git a/contrib/ffmpeg/libswscale/Makefile b/contrib/ffmpeg/libswscale/Makefile index a1c25a76a..14a65b92c 100644 --- a/contrib/ffmpeg/libswscale/Makefile +++ b/contrib/ffmpeg/libswscale/Makefile @@ -7,18 +7,24 @@ LIBMAJOR=$(SWSMAJOR) EXTRALIBS := -L$(BUILD_ROOT)/libavutil -lavutil$(BUILDSUF) $(EXTRALIBS) -OBJS= swscale.o rgb2rgb.o +OBJS = rgb2rgb.o swscale.o -OBJS-$(TARGET_ALTIVEC) += yuv2rgb_altivec.o OBJS-$(CONFIG_GPL) += yuv2rgb.o +OBJS-$(HAVE_ALTIVEC) += yuv2rgb_altivec.o + +OBJS-$(ARCH_BFIN) += swscale_bfin.o \ + yuv2rgb_bfin.o \ + +ASM_OBJS-$(ARCH_BFIN) += internal_bfin.o HEADERS = swscale.h rgb2rgb.h include ../common.mak -cs_test: cs_test.o $(LIB) +cs_test: cs_test.o $(LIBNAME) -swscale-example: swscale-example.o $(LIB) -lm +swscale-example: swscale-example.o $(LIBNAME) +swscale-example: EXTRALIBS += -lm clean:: rm -f cs_test swscale-example diff --git a/contrib/ffmpeg/libswscale/cs_test.c b/contrib/ffmpeg/libswscale/cs_test.c index cd0100618..2bb74865b 100644 --- a/contrib/ffmpeg/libswscale/cs_test.c +++ b/contrib/ffmpeg/libswscale/cs_test.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include @@ -31,6 +31,7 @@ #define srcByte 0x55 #define dstByte 0xBB +#define FUNC(s,d,n) {s,d,#n,n} static int cpu_caps; @@ -59,245 +60,116 @@ static char *args_parse(int argc, char *argv[]) int main(int argc, char **argv) { - int i, funcNum; - uint8_t *srcBuffer= (uint8_t*)av_malloc(SIZE); - uint8_t *dstBuffer= (uint8_t*)av_malloc(SIZE); - int failedNum=0; - int passedNum=0; - - av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n"); - args_parse(argc, argv); - av_log(NULL, AV_LOG_INFO, "CPU capabilities forced to %x\n", cpu_caps); - sws_rgb2rgb_init(cpu_caps); - - for(funcNum=0; funcNum<100; funcNum++){ - int width; - int failed=0; - int srcBpp=0; - int dstBpp=0; + int i, funcNum; + uint8_t *srcBuffer= (uint8_t*)av_malloc(SIZE); + uint8_t *dstBuffer= (uint8_t*)av_malloc(SIZE); + int failedNum=0; + int passedNum=0; - av_log(NULL, AV_LOG_INFO,"."); - memset(srcBuffer, srcByte, SIZE); + av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n"); + args_parse(argc, argv); + av_log(NULL, AV_LOG_INFO, "CPU capabilities forced to %x\n", cpu_caps); + sws_rgb2rgb_init(cpu_caps); - for(width=32; width<64; width++){ - int dstOffset; - for(dstOffset=128; dstOffset<196; dstOffset+=4){ - int srcOffset; - memset(dstBuffer, dstByte, SIZE); + for(funcNum=0; ; funcNum++){ + struct func_info_s { + int src_bpp; + int dst_bpp; + char *name; + void (*func)(const uint8_t *src, uint8_t *dst, long src_size); + } func_info[] = { + FUNC(2, 2, rgb15to16), + FUNC(2, 3, rgb15to24), + FUNC(2, 4, rgb15to32), + FUNC(2, 3, rgb16to24), + FUNC(2, 4, rgb16to32), + FUNC(3, 2, rgb24to15), + FUNC(3, 2, rgb24to16), + FUNC(3, 4, rgb24to32), + FUNC(4, 2, rgb32to15), + FUNC(4, 2, rgb32to16), + FUNC(4, 3, rgb32to24), + FUNC(2, 2, rgb16to15), + FUNC(2, 2, rgb15tobgr15), + FUNC(2, 2, rgb15tobgr16), + FUNC(2, 3, rgb15tobgr24), + FUNC(2, 4, rgb15tobgr32), + FUNC(2, 2, rgb16tobgr15), + FUNC(2, 2, rgb16tobgr16), + FUNC(2, 3, rgb16tobgr24), + FUNC(2, 4, rgb16tobgr32), + FUNC(3, 2, rgb24tobgr15), + FUNC(3, 2, rgb24tobgr16), + FUNC(3, 3, rgb24tobgr24), + FUNC(3, 4, rgb24tobgr32), + FUNC(4, 2, rgb32tobgr15), + FUNC(4, 2, rgb32tobgr16), + FUNC(4, 3, rgb32tobgr24), + FUNC(4, 4, rgb32tobgr32), + FUNC(0, 0, NULL) + }; + int width; + int failed=0; + int srcBpp=0; + int dstBpp=0; - for(srcOffset=128; srcOffset<196; srcOffset+=4){ - uint8_t *src= srcBuffer+srcOffset; - uint8_t *dst= dstBuffer+dstOffset; - char *name=NULL; - - if(failed) break; //don't fill the screen with shit ... + if (!func_info[funcNum].func) break; - switch(funcNum){ - case 0: - srcBpp=2; - dstBpp=2; - name="rgb15to16"; - rgb15to16(src, dst, width*srcBpp); - break; - case 1: - srcBpp=2; - dstBpp=3; - name="rgb15to24"; - rgb15to24(src, dst, width*srcBpp); - break; - case 2: - srcBpp=2; - dstBpp=4; - name="rgb15to32"; - rgb15to32(src, dst, width*srcBpp); - break; - case 3: - srcBpp=2; - dstBpp=3; - name="rgb16to24"; - rgb16to24(src, dst, width*srcBpp); - break; - case 4: - srcBpp=2; - dstBpp=4; - name="rgb16to32"; - rgb16to32(src, dst, width*srcBpp); - break; - case 5: - srcBpp=3; - dstBpp=2; - name="rgb24to15"; - rgb24to15(src, dst, width*srcBpp); - break; - case 6: - srcBpp=3; - dstBpp=2; - name="rgb24to16"; - rgb24to16(src, dst, width*srcBpp); - break; - case 7: - srcBpp=3; - dstBpp=4; - name="rgb24to32"; - rgb24to32(src, dst, width*srcBpp); - break; - case 8: - srcBpp=4; - dstBpp=2; - name="rgb32to15"; - //((*s++) << TGA_SHIFT32) | TGA_ALPHA32; - rgb32to15(src, dst, width*srcBpp); - break; - case 9: - srcBpp=4; - dstBpp=2; - name="rgb32to16"; - rgb32to16(src, dst, width*srcBpp); - break; - case 10: - srcBpp=4; - dstBpp=3; - name="rgb32to24"; - rgb32to24(src, dst, width*srcBpp); - break; - case 11: - srcBpp=2; - dstBpp=2; - name="rgb16to15"; - rgb16to15(src, dst, width*srcBpp); - break; - - case 14: - srcBpp=2; - dstBpp=2; - name="rgb15tobgr15"; - rgb15tobgr15(src, dst, width*srcBpp); - break; - case 15: - srcBpp=2; - dstBpp=2; - name="rgb15tobgr16"; - rgb15tobgr16(src, dst, width*srcBpp); - break; - case 16: - srcBpp=2; - dstBpp=3; - name="rgb15tobgr24"; - rgb15tobgr24(src, dst, width*srcBpp); - break; - case 17: - srcBpp=2; - dstBpp=4; - name="rgb15tobgr32"; - rgb15tobgr32(src, dst, width*srcBpp); - break; - case 18: - srcBpp=2; - dstBpp=2; - name="rgb16tobgr15"; - rgb16tobgr15(src, dst, width*srcBpp); - break; - case 19: - srcBpp=2; - dstBpp=2; - name="rgb16tobgr16"; - rgb16tobgr16(src, dst, width*srcBpp); - break; - case 20: - srcBpp=2; - dstBpp=3; - name="rgb16tobgr24"; - rgb16tobgr24(src, dst, width*srcBpp); - break; - case 21: - srcBpp=2; - dstBpp=4; - name="rgb16tobgr32"; - rgb16tobgr32(src, dst, width*srcBpp); - break; - case 22: - srcBpp=3; - dstBpp=2; - name="rgb24tobgr15"; - rgb24tobgr15(src, dst, width*srcBpp); - break; - case 23: - srcBpp=3; - dstBpp=2; - name="rgb24tobgr16"; - rgb24tobgr16(src, dst, width*srcBpp); - break; - case 24: - srcBpp=3; - dstBpp=3; - name="rgb24tobgr24"; - rgb24tobgr24(src, dst, width*srcBpp); - break; - case 25: - srcBpp=3; - dstBpp=4; - name="rgb24tobgr32"; - rgb24tobgr32(src, dst, width*srcBpp); - break; - case 26: - srcBpp=4; - dstBpp=2; - name="rgb32tobgr15"; - rgb32tobgr15(src, dst, width*srcBpp); - break; - case 27: - srcBpp=4; - dstBpp=2; - name="rgb32tobgr16"; - rgb32tobgr16(src, dst, width*srcBpp); - break; - case 28: - srcBpp=4; - dstBpp=3; - name="rgb32tobgr24"; - rgb32tobgr24(src, dst, width*srcBpp); - break; - case 29: - srcBpp=4; - dstBpp=4; - name="rgb32tobgr32"; - rgb32tobgr32(src, dst, width*srcBpp); - break; + av_log(NULL, AV_LOG_INFO,"."); + memset(srcBuffer, srcByte, SIZE); - } - if(!srcBpp) break; + for(width=63; width>0; width--){ + int dstOffset; + for(dstOffset=128; dstOffset<196; dstOffset+=4){ + int srcOffset; + memset(dstBuffer, dstByte, SIZE); - for(i=0; i + * April 20, 2007 + * + * Blackfin Video Color Space Converters Operations + * convert I420 YV12 to RGB in various formats, + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +/* + YUV420 to RGB565 conversion. This routine takes a YUV 420 planar macroblock + and converts it to RGB565. R:5 bits, G:6 bits, B:5 bits.. packed into shorts + + + The following calculation is used for the conversion: + + r = clipz((y-oy)*cy + crv*(v-128)) + g = clipz((y-oy)*cy + cgv*(v-128) + cgu*(u-128)) + b = clipz((y-oy)*cy + cbu*(u-128)) + + y,u,v are pre scaled by a factor of 4 i.e. left shifted to gain precision. + + + New factorization to eliminate the truncation error which was + occuring due to the byteop3p. + + + 1) use the bytop16m to subtract quad bytes we use this in U8 this + then so the offsets need to be renormalized to 8bits. + + 2) scale operands up by a factor of 4 not 8 because Blackfin + multiplies include a shift. + + 3) compute into the accumulators cy*yx0, cy*yx1 + + 4) compute each of the linear equations + r = clipz((y-oy)*cy + crv*(v-128)) + + g = clipz((y-oy)*cy + cgv*(v-128) + cgu*(u-128)) + + b = clipz((y-oy)*cy + cbu*(u-128)) + + reuse of the accumulators requires that we actually multiply + twice once with addition and the second time with a subtaction. + + because of this we need to compute the equations in the order R B + then G saving the writes for B in the case of 24/32 bit color + formats. + + api: yuv2rgb_kind (uint8_t *Y, uint8_t *U, uint8_t *V, int *out, + int dW, uint32_t *coeffs); + + A B + --- --- + i2 = cb i3 = cr + i1 = coeff i0 = y + + Where coeffs have the following layout in memory. + + uint32_t oy,oc,zero,cy,crv,rmask,cbu,bmask,cgu,cgv; + + coeffs is a pointer to oy. + + the {rgb} masks are only utilized by the 565 packing algorithm. Note the data + replication is used to simplify the internal algorithms for the dual mac architecture + of BlackFin. + + All routines are exported with _ff_bfin_ as a symbol prefix + + rough performance gain compared against -O3: + + 2779809/1484290 187.28% + + which translates to ~33c/pel to ~57c/pel for the reference vs 17.5 + c/pel for the optimized implementations. Not sure why there is such a + huge variation on the reference codes on Blackfin I guess it must have + to do with the memory system. + +*/ + +#define mL3 .text +#ifdef __FDPIC__ +#define mL1 .l1.text +#else +#define mL1 mL3 +#endif +#define MEM mL1 + +#define DEFUN(fname,where,interface) \ + .section where; \ + .global _ff_bfin_ ## fname; \ + .type _ff_bfin_ ## fname, STT_FUNC; \ + .align 8; \ + _ff_bfin_ ## fname + +#define DEFUN_END(fname) \ + .size _ff_bfin_ ## fname, . - _ff_bfin_ ## fname + + +.text + +#define COEFF_LEN 11*4 +#define COEFF_REL_CY_OFF 4*4 + +#define ARG_OUT 20 +#define ARG_W 24 +#define ARG_COEFF 28 + +DEFUN(yuv2rgb565_line,MEM, + (uint8_t *Y, uint8_t *U, uint8_t *V, int *out, int dW, uint32_t *coeffs)): + link 0; + [--sp] = (r7:4); + p1 = [fp+ARG_OUT]; + r3 = [fp+ARG_W]; + + i0 = r0; + i2 = r1; + i3 = r2; + + r0 = [fp+ARG_COEFF]; + i1 = r0; + b1 = i1; + l1 = COEFF_LEN; + m0 = COEFF_REL_CY_OFF; + p0 = r3; + + r0 = [i0++]; // 2Y + r1.l = w[i2++]; // 2u + r1.h = w[i3++]; // 2v + p0 = p0>>2; + + lsetup (.L0565, .L1565) lc0 = p0; + + /* + uint32_t oy,oc,zero,cy,crv,rmask,cbu,bmask,cgu,cgv + r0 -- used to load 4ys + r1 -- used to load 2us,2vs + r4 -- y3,y2 + r5 -- y1,y0 + r6 -- u1,u0 + r7 -- v1,v0 + */ + r2=[i1++]; // oy +.L0565: + /* + rrrrrrrr gggggggg bbbbbbbb + 5432109876543210 + bbbbb >>3 + gggggggg <<3 + rrrrrrrr <<8 + rrrrrggggggbbbbb + */ + (r4,r5) = byteop16m (r1:0, r3:2) || r3=[i1++]; // oc + (r7,r6) = byteop16m (r1:0, r3:2) (r); + r5 = r5 << 2 (v); // y1,y0 + r4 = r4 << 2 (v); // y3,y2 + r6 = r6 << 2 (v) || r0=[i1++]; // u1,u0, r0=zero + r7 = r7 << 2 (v) || r1=[i1++]; // v1,v0 r1=cy + /* Y' = y*cy */ + a1 = r1.h*r5.h, a0 = r1.l*r5.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + a1 -= r1.h*r7.l, a0 -= r1.l*r7.l || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2 = r2 >> 3 (v); + r3 = r2 & r5; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.l), r2.l = (a0 += r1.l*r6.l); + a1 -= r1.h*r6.l, a0 -= r1.l*r6.l || r5=[i1++]; // bmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + r2 = r2 << 8 (v); + r2 = r2 & r5; + r3 = r3 | r2; + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.l, a0 += r1.l*r6.l || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + r2 = byteop3p(r3:2, r1:0)(LO) || r5=[i1++m0]; // gmask + r2 = r2 << 3 (v); + r2 = r2 & r5; + r3 = r3 | r2; + [p1++]=r3 || r1=[i1++]; // cy + + /* Y' = y*cy */ + + a1 = r1.h*r4.h, a0 = r1.l*r4.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h); + a1 -= r1.h*r7.h, a0 -= r1.l*r7.h || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2 = r2 >> 3 (v); + r3 = r2 & r5; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.h), r2.l = (a0 += r1.l*r6.h); + a1 -= r1.h*r6.h, a0 -= r1.l*r6.h || r5=[i1++]; // bmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + r2 = r2 << 8 (v); + r2 = r2 & r5; + r3 = r3 | r2; + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.h, a0 += r1.l*r6.h || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h) || r5=[i1++]; // gmask + r2 = byteop3p(r3:2, r1:0)(LO) || r0 = [i0++]; // 2Y + r2 = r2 << 3 (v) || r1.l = w[i2++]; // 2u + r2 = r2 & r5; + r3 = r3 | r2; + [p1++]=r3 || r1.h = w[i3++]; // 2v +.L1565: r2=[i1++]; // oy + + l1 = 0; + + (r7:4) = [sp++]; + unlink; + rts; +DEFUN_END(yuv2rgb565_line) + +DEFUN(yuv2rgb555_line,MEM, + (uint8_t *Y, uint8_t *U, uint8_t *V, int *out, int dW, uint32_t *coeffs)): + link 0; + [--sp] = (r7:4); + p1 = [fp+ARG_OUT]; + r3 = [fp+ARG_W]; + + i0 = r0; + i2 = r1; + i3 = r2; + + r0 = [fp+ARG_COEFF]; + i1 = r0; + b1 = i1; + l1 = COEFF_LEN; + m0 = COEFF_REL_CY_OFF; + p0 = r3; + + r0 = [i0++]; // 2Y + r1.l = w[i2++]; // 2u + r1.h = w[i3++]; // 2v + p0 = p0>>2; + + lsetup (.L0555, .L1555) lc0 = p0; + + /* + uint32_t oy,oc,zero,cy,crv,rmask,cbu,bmask,cgu,cgv + r0 -- used to load 4ys + r1 -- used to load 2us,2vs + r4 -- y3,y2 + r5 -- y1,y0 + r6 -- u1,u0 + r7 -- v1,v0 + */ + r2=[i1++]; // oy +.L0555: + /* + rrrrrrrr gggggggg bbbbbbbb + 5432109876543210 + bbbbb >>3 + gggggggg <<2 + rrrrrrrr <<7 + xrrrrrgggggbbbbb + */ + + (r4,r5) = byteop16m (r1:0, r3:2) || r3=[i1++]; // oc + (r7,r6) = byteop16m (r1:0, r3:2) (r); + r5 = r5 << 2 (v); // y1,y0 + r4 = r4 << 2 (v); // y3,y2 + r6 = r6 << 2 (v) || r0=[i1++]; // u1,u0, r0=zero + r7 = r7 << 2 (v) || r1=[i1++]; // v1,v0 r1=cy + /* Y' = y*cy */ + a1 = r1.h*r5.h, a0 = r1.l*r5.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + a1 -= r1.h*r7.l, a0 -= r1.l*r7.l || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2 = r2 >> 3 (v); + r3 = r2 & r5; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.l), r2.l = (a0 += r1.l*r6.l); + a1 -= r1.h*r6.l, a0 -= r1.l*r6.l || r5=[i1++]; // bmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + r2 = r2 << 7 (v); + r2 = r2 & r5; + r3 = r3 | r2; + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.l, a0 += r1.l*r6.l || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + r2 = byteop3p(r3:2, r1:0)(LO) || r5=[i1++m0]; // gmask + r2 = r2 << 2 (v); + r2 = r2 & r5; + r3 = r3 | r2; + [p1++]=r3 || r1=[i1++]; // cy + + /* Y' = y*cy */ + + a1 = r1.h*r4.h, a0 = r1.l*r4.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h); + a1 -= r1.h*r7.h, a0 -= r1.l*r7.h || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2 = r2 >> 3 (v); + r3 = r2 & r5; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.h), r2.l = (a0 += r1.l*r6.h); + a1 -= r1.h*r6.h, a0 -= r1.l*r6.h || r5=[i1++]; // bmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + r2 = r2 << 7 (v); + r2 = r2 & r5; + r3 = r3 | r2; + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.h, a0 += r1.l*r6.h || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h) || r5=[i1++]; // gmask + r2 = byteop3p(r3:2, r1:0)(LO) || r0=[i0++]; // 4Y + r2 = r2 << 2 (v) || r1.l=w[i2++]; // 2u + r2 = r2 & r5; + r3 = r3 | r2; + [p1++]=r3 || r1.h=w[i3++]; // 2v + +.L1555: r2=[i1++]; // oy + + l1 = 0; + + (r7:4) = [sp++]; + unlink; + rts; +DEFUN_END(yuv2rgb555_line) + +DEFUN(yuv2rgb24_line,MEM, + (uint8_t *Y, uint8_t *U, uint8_t *V, int *out, int dW, uint32_t *coeffs)): + link 0; + [--sp] = (r7:4); + p1 = [fp+ARG_OUT]; + r3 = [fp+ARG_W]; + p2 = p1; + p2 += 3; + + i0 = r0; + i2 = r1; + i3 = r2; + + r0 = [fp+ARG_COEFF]; // coeff buffer + i1 = r0; + b1 = i1; + l1 = COEFF_LEN; + m0 = COEFF_REL_CY_OFF; + p0 = r3; + + r0 = [i0++]; // 2Y + r1.l = w[i2++]; // 2u + r1.h = w[i3++]; // 2v + p0 = p0>>2; + + lsetup (.L0888, .L1888) lc0 = p0; + + /* + uint32_t oy,oc,zero,cy,crv,rmask,cbu,bmask,cgu,cgv + r0 -- used to load 4ys + r1 -- used to load 2us,2vs + r4 -- y3,y2 + r5 -- y1,y0 + r6 -- u1,u0 + r7 -- v1,v0 + */ + r2=[i1++]; // oy +.L0888: + (r4,r5) = byteop16m (r1:0, r3:2) || r3=[i1++]; // oc + (r7,r6) = byteop16m (r1:0, r3:2) (r); + r5 = r5 << 2 (v); // y1,y0 + r4 = r4 << 2 (v); // y3,y2 + r6 = r6 << 2 (v) || r0=[i1++]; // u1,u0, r0=zero + r7 = r7 << 2 (v) || r1=[i1++]; // v1,v0 r1=cy + + /* Y' = y*cy */ + a1 = r1.h*r5.h, a0 = r1.l*r5.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + a1 -= r1.h*r7.l, a0 -= r1.l*r7.l || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2=r2>>16 || B[p1++]=r2; + B[p2++]=r2; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.l), r2.l = (a0 += r1.l*r6.l); + a1 -= r1.h*r6.l, a0 -= r1.l*r6.l || r5=[i1++]; // bmask + r3 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.l, a0 += r1.l*r6.l || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.l), r2.l = (a0 += r1.l*r7.l); + r2 = byteop3p(r3:2, r1:0)(LO) || r5=[i1++m0]; // gmask, oy,cy,zero + + r2=r2>>16 || B[p1++]=r2; + B[p2++]=r2; + + r3=r3>>16 || B[p1++]=r3; + B[p2++]=r3 || r1=[i1++]; // cy + + p1+=3; + p2+=3; + /* Y' = y*cy */ + a1 = r1.h*r4.h, a0 = r1.l*r4.l || r1=[i1++]; // crv + + /* R = Y+ crv*(Cr-128) */ + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h); + a1 -= r1.h*r7.h, a0 -= r1.l*r7.h || r5=[i1++]; // rmask + r2 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cbu + r2=r2>>16 || B[p1++]=r2; + B[p2++]=r2; + + /* B = Y+ cbu*(Cb-128) */ + r2.h = (a1 += r1.h*r6.h), r2.l = (a0 += r1.l*r6.h); + a1 -= r1.h*r6.h, a0 -= r1.l*r6.h || r5=[i1++]; // bmask + r3 = byteop3p(r3:2, r1:0)(LO) || r1=[i1++]; // cgu + + /* G = Y+ cgu*(Cb-128)+cgv*(Cr-128) */ + a1 += r1.h*r6.h, a0 += r1.l*r6.h || r1=[i1++]; // cgv + r2.h = (a1 += r1.h*r7.h), r2.l = (a0 += r1.l*r7.h); + r2 = byteop3p(r3:2, r1:0)(LO) || r5=[i1++]; // gmask + r2=r2>>16 || B[p1++]=r2 || r0 = [i0++]; // 4y + B[p2++]=r2 || r1.l = w[i2++]; // 2u + r3=r3>>16 || B[p1++]=r3 || r1.h = w[i3++]; // 2v + B[p2++]=r3 || r2=[i1++]; // oy + + p1+=3; +.L1888: p2+=3; + + l1 = 0; + + (r7:4) = [sp++]; + unlink; + rts; +DEFUN_END(yuv2rgb24_line) + + + +#define ARG_vdst 20 +#define ARG_width 24 +#define ARG_height 28 +#define ARG_lumStride 32 +#define ARG_chromStride 36 +#define ARG_srcStride 40 + +DEFUN(uyvytoyv12, mL3, (const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, + long width, long height, + long lumStride, long chromStride, long srcStride)): + link 0; + [--sp] = (r7:4,p5:4); + + p0 = r1; // Y top even + + i2 = r2; // *u + r2 = [fp + ARG_vdst]; + i3 = r2; // *v + + r1 = [fp + ARG_srcStride]; + r2 = r0 + r1; + r1 += -8; // i0,i1 is pre read need to correct + m0 = r1; + + i0 = r0; // uyvy_T even + i1 = r2; // uyvy_B odd + + p2 = [fp + ARG_lumStride]; + p1 = p0 + p2; // Y bot odd + + p5 = [fp + ARG_width]; + p4 = [fp + ARG_height]; + r0 = p5; + p4 = p4 >> 1; + p5 = p5 >> 2; + + r2 = [fp + ARG_chromStride]; + r0 = r0 >> 1; + r2 = r2 - r0; + m1 = r2; + + /* I0,I1 - src input line pointers + * p0,p1 - luma output line pointers + * I2 - dstU + * I3 - dstV + */ + + lsetup (0f, 1f) lc1 = p4; // H/2 +0: r0 = [i0++] || r2 = [i1++]; + r1 = [i0++] || r3 = [i1++]; + r4 = byteop1p(r1:0, r3:2); + r5 = byteop1p(r1:0, r3:2) (r); + lsetup (2f, 3f) lc0 = p5; // W/4 +2: r0 = r0 >> 8(v); + r1 = r1 >> 8(v); + r2 = r2 >> 8(v); + r3 = r3 >> 8(v); + r0 = bytepack(r0, r1); + r2 = bytepack(r2, r3) || [p0++] = r0; // yyyy + r6 = pack(r5.l, r4.l) || [p1++] = r2; // yyyy + r7 = pack(r5.h, r4.h) || r0 = [i0++] || r2 = [i1++]; + r6 = bytepack(r6, r7) || r1 = [i0++] || r3 = [i1++]; + r4 = byteop1p(r1:0, r3:2) || w[i2++] = r6.l; // uu +3: r5 = byteop1p(r1:0, r3:2) (r) || w[i3++] = r6.h; // vv + + i0 += m0; + i1 += m0; + i2 += m1; + i3 += m1; + p0 = p0 + p2; +1: p1 = p1 + p2; + + (r7:4,p5:4) = [sp++]; + unlink; + rts; +DEFUN_END(uyvytoyv12) + +DEFUN(yuyvtoyv12, mL3, (const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, + long width, long height, + long lumStride, long chromStride, long srcStride)): + link 0; + [--sp] = (r7:4,p5:4); + + p0 = r1; // Y top even + + i2 = r2; // *u + r2 = [fp + ARG_vdst]; + i3 = r2; // *v + + r1 = [fp + ARG_srcStride]; + r2 = r0 + r1; + r1 += -8; // i0,i1 is pre read need to correct + m0 = r1; + + i0 = r0; // uyvy_T even + i1 = r2; // uyvy_B odd + + p2 = [fp + ARG_lumStride]; + p1 = p0 + p2; // Y bot odd + + p5 = [fp + ARG_width]; + p4 = [fp + ARG_height]; + r0 = p5; + p4 = p4 >> 1; + p5 = p5 >> 2; + + r2 = [fp + ARG_chromStride]; + r0 = r0 >> 1; + r2 = r2 - r0; + m1 = r2; + + /* I0,I1 - src input line pointers + * p0,p1 - luma output line pointers + * I2 - dstU + * I3 - dstV + */ + + lsetup (0f, 1f) lc1 = p4; // H/2 +0: r0 = [i0++] || r2 = [i1++]; + r1 = [i0++] || r3 = [i1++]; + r4 = bytepack(r0, r1); + r5 = bytepack(r2, r3); + lsetup (2f, 3f) lc0 = p5; // W/4 +2: r0 = r0 >> 8(v) || [p0++] = r4; // yyyy-even + r1 = r1 >> 8(v) || [p1++] = r5; // yyyy-odd + r2 = r2 >> 8(v); + r3 = r3 >> 8(v); + r4 = byteop1p(r1:0, r3:2); + r5 = byteop1p(r1:0, r3:2) (r); + r6 = pack(r5.l, r4.l); + r7 = pack(r5.h, r4.h) || r0 = [i0++] || r2 = [i1++]; + r6 = bytepack(r6, r7) || r1 = [i0++] || r3 = [i1++]; + r4 = bytepack(r0, r1) || w[i2++] = r6.l; // uu +3: r5 = bytepack(r2, r3) || w[i3++] = r6.h; // vv + + i0 += m0; + i1 += m0; + i2 += m1; + i3 += m1; + p0 = p0 + p2; +1: p1 = p1 + p2; + + (r7:4,p5:4) = [sp++]; + unlink; + rts; +DEFUN_END(yuyvtoyv12) diff --git a/contrib/ffmpeg/libswscale/rgb2rgb.c b/contrib/ffmpeg/libswscale/rgb2rgb.c index a938abfc9..faf3e95c6 100644 --- a/contrib/ffmpeg/libswscale/rgb2rgb.c +++ b/contrib/ffmpeg/libswscale/rgb2rgb.c @@ -1,5 +1,4 @@ /* - * * rgb2rgb.c, Software RGB to RGB convertor * pluralize by Software PAL8 to RGB convertor * Software YUV to YUV convertor @@ -21,8 +20,8 @@ * * You should have received a copy of the GNU General Public License * along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * * the C code (not assembly, mmx, ...) of this file can be used * under the LGPL license too */ @@ -33,24 +32,21 @@ #include "swscale_internal.h" #include "x86_cpu.h" #include "bswap.h" -#ifdef USE_FASTMEMCPY -#include "libvo/fastmemcpy.h" -#endif #define FAST_BGR2YV12 // use 7 bit coeffs instead of 15bit -void (*rgb24to32)(const uint8_t *src,uint8_t *dst,long src_size); -void (*rgb24to16)(const uint8_t *src,uint8_t *dst,long src_size); -void (*rgb24to15)(const uint8_t *src,uint8_t *dst,long src_size); -void (*rgb32to24)(const uint8_t *src,uint8_t *dst,long src_size); -void (*rgb32to16)(const uint8_t *src,uint8_t *dst,long src_size); -void (*rgb32to15)(const uint8_t *src,uint8_t *dst,long src_size); -void (*rgb15to16)(const uint8_t *src,uint8_t *dst,long src_size); -void (*rgb15to24)(const uint8_t *src,uint8_t *dst,long src_size); -void (*rgb15to32)(const uint8_t *src,uint8_t *dst,long src_size); -void (*rgb16to15)(const uint8_t *src,uint8_t *dst,long src_size); -void (*rgb16to24)(const uint8_t *src,uint8_t *dst,long src_size); -void (*rgb16to32)(const uint8_t *src,uint8_t *dst,long src_size); +void (*rgb24to32)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb24to16)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb24to15)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb32to24)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb32to16)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb32to15)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb15to16)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb15to24)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb15to32)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb16to15)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb16to24)(const uint8_t *src, uint8_t *dst, long src_size); +void (*rgb16to32)(const uint8_t *src, uint8_t *dst, long src_size); //void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size); void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size); @@ -61,83 +57,70 @@ void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size); void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size); void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, - long width, long height, - long lumStride, long chromStride, long dstStride); + long width, long height, + long lumStride, long chromStride, long dstStride); void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, - long width, long height, - long lumStride, long chromStride, long dstStride); + long width, long height, + long lumStride, long chromStride, long dstStride); void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, - long width, long height, - long lumStride, long chromStride, long dstStride); + long width, long height, + long lumStride, long chromStride, long dstStride); void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, - long width, long height, - long lumStride, long chromStride, long srcStride); + long width, long height, + long lumStride, long chromStride, long srcStride); void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, - long width, long height, - long lumStride, long chromStride, long srcStride); + long width, long height, + long lumStride, long chromStride, long srcStride); void (*planar2x)(const uint8_t *src, uint8_t *dst, long width, long height, - long srcStride, long dstStride); + long srcStride, long dstStride); void (*interleaveBytes)(uint8_t *src1, uint8_t *src2, uint8_t *dst, - long width, long height, long src1Stride, - long src2Stride, long dstStride); + long width, long height, long src1Stride, + long src2Stride, long dstStride); void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2, - uint8_t *dst1, uint8_t *dst2, - long width, long height, - long srcStride1, long srcStride2, - long dstStride1, long dstStride2); + uint8_t *dst1, uint8_t *dst2, + long width, long height, + long srcStride1, long srcStride2, + long dstStride1, long dstStride2); void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, - uint8_t *dst, - long width, long height, - long srcStride1, long srcStride2, - long srcStride3, long dstStride); + uint8_t *dst, + long width, long height, + long srcStride1, long srcStride2, + long srcStride3, long dstStride); #if defined(ARCH_X86) && defined(CONFIG_GPL) -static const uint64_t mmx_null __attribute__((aligned(8))) = 0x0000000000000000ULL; -static const uint64_t mmx_one __attribute__((aligned(8))) = 0xFFFFFFFFFFFFFFFFULL; -static const uint64_t mask32b attribute_used __attribute__((aligned(8))) = 0x000000FF000000FFULL; -static const uint64_t mask32g attribute_used __attribute__((aligned(8))) = 0x0000FF000000FF00ULL; -static const uint64_t mask32r attribute_used __attribute__((aligned(8))) = 0x00FF000000FF0000ULL; -static const uint64_t mask32 __attribute__((aligned(8))) = 0x00FFFFFF00FFFFFFULL; -static const uint64_t mask3216br __attribute__((aligned(8)))=0x00F800F800F800F8ULL; -static const uint64_t mask3216g __attribute__((aligned(8)))=0x0000FC000000FC00ULL; -static const uint64_t mask3215g __attribute__((aligned(8)))=0x0000F8000000F800ULL; -static const uint64_t mul3216 __attribute__((aligned(8))) = 0x2000000420000004ULL; -static const uint64_t mul3215 __attribute__((aligned(8))) = 0x2000000820000008ULL; -static const uint64_t mask24b attribute_used __attribute__((aligned(8))) = 0x00FF0000FF0000FFULL; -static const uint64_t mask24g attribute_used __attribute__((aligned(8))) = 0xFF0000FF0000FF00ULL; -static const uint64_t mask24r attribute_used __attribute__((aligned(8))) = 0x0000FF0000FF0000ULL; -static const uint64_t mask24l __attribute__((aligned(8))) = 0x0000000000FFFFFFULL; -static const uint64_t mask24h __attribute__((aligned(8))) = 0x0000FFFFFF000000ULL; -static const uint64_t mask24hh __attribute__((aligned(8))) = 0xffff000000000000ULL; -static const uint64_t mask24hhh __attribute__((aligned(8))) = 0xffffffff00000000ULL; -static const uint64_t mask24hhhh __attribute__((aligned(8))) = 0xffffffffffff0000ULL; -static const uint64_t mask15b __attribute__((aligned(8))) = 0x001F001F001F001FULL; /* 00000000 00011111 xxB */ -static const uint64_t mask15rg __attribute__((aligned(8))) = 0x7FE07FE07FE07FE0ULL; /* 01111111 11100000 RGx */ -static const uint64_t mask15s __attribute__((aligned(8))) = 0xFFE0FFE0FFE0FFE0ULL; -static const uint64_t mask15g __attribute__((aligned(8))) = 0x03E003E003E003E0ULL; -static const uint64_t mask15r __attribute__((aligned(8))) = 0x7C007C007C007C00ULL; +DECLARE_ASM_CONST(8, uint64_t, mmx_null) = 0x0000000000000000ULL; +DECLARE_ASM_CONST(8, uint64_t, mmx_one) = 0xFFFFFFFFFFFFFFFFULL; +DECLARE_ASM_CONST(8, uint64_t, mask32b) = 0x000000FF000000FFULL; +DECLARE_ASM_CONST(8, uint64_t, mask32g) = 0x0000FF000000FF00ULL; +DECLARE_ASM_CONST(8, uint64_t, mask32r) = 0x00FF000000FF0000ULL; +DECLARE_ASM_CONST(8, uint64_t, mask32) = 0x00FFFFFF00FFFFFFULL; +DECLARE_ASM_CONST(8, uint64_t, mask3216br) = 0x00F800F800F800F8ULL; +DECLARE_ASM_CONST(8, uint64_t, mask3216g) = 0x0000FC000000FC00ULL; +DECLARE_ASM_CONST(8, uint64_t, mask3215g) = 0x0000F8000000F800ULL; +DECLARE_ASM_CONST(8, uint64_t, mul3216) = 0x2000000420000004ULL; +DECLARE_ASM_CONST(8, uint64_t, mul3215) = 0x2000000820000008ULL; +DECLARE_ASM_CONST(8, uint64_t, mask24b) = 0x00FF0000FF0000FFULL; +DECLARE_ASM_CONST(8, uint64_t, mask24g) = 0xFF0000FF0000FF00ULL; +DECLARE_ASM_CONST(8, uint64_t, mask24r) = 0x0000FF0000FF0000ULL; +DECLARE_ASM_CONST(8, uint64_t, mask24l) = 0x0000000000FFFFFFULL; +DECLARE_ASM_CONST(8, uint64_t, mask24h) = 0x0000FFFFFF000000ULL; +DECLARE_ASM_CONST(8, uint64_t, mask24hh) = 0xffff000000000000ULL; +DECLARE_ASM_CONST(8, uint64_t, mask24hhh) = 0xffffffff00000000ULL; +DECLARE_ASM_CONST(8, uint64_t, mask24hhhh) = 0xffffffffffff0000ULL; +DECLARE_ASM_CONST(8, uint64_t, mask15b) = 0x001F001F001F001FULL; /* 00000000 00011111 xxB */ +DECLARE_ASM_CONST(8, uint64_t, mask15rg) = 0x7FE07FE07FE07FE0ULL; /* 01111111 11100000 RGx */ +DECLARE_ASM_CONST(8, uint64_t, mask15s) = 0xFFE0FFE0FFE0FFE0ULL; +DECLARE_ASM_CONST(8, uint64_t, mask15g) = 0x03E003E003E003E0ULL; +DECLARE_ASM_CONST(8, uint64_t, mask15r) = 0x7C007C007C007C00ULL; #define mask16b mask15b -static const uint64_t mask16g __attribute__((aligned(8))) = 0x07E007E007E007E0ULL; -static const uint64_t mask16r __attribute__((aligned(8))) = 0xF800F800F800F800ULL; -static const uint64_t red_16mask __attribute__((aligned(8))) = 0x0000f8000000f800ULL; -static const uint64_t green_16mask __attribute__((aligned(8)))= 0x000007e0000007e0ULL; -static const uint64_t blue_16mask __attribute__((aligned(8))) = 0x0000001f0000001fULL; -static const uint64_t red_15mask __attribute__((aligned(8))) = 0x00007c000000f800ULL; -static const uint64_t green_15mask __attribute__((aligned(8)))= 0x000003e0000007e0ULL; -static const uint64_t blue_15mask __attribute__((aligned(8))) = 0x0000001f0000001fULL; - -#ifdef FAST_BGR2YV12 -static const uint64_t bgr2YCoeff attribute_used __attribute__((aligned(8))) = 0x000000210041000DULL; -static const uint64_t bgr2UCoeff attribute_used __attribute__((aligned(8))) = 0x0000FFEEFFDC0038ULL; -static const uint64_t bgr2VCoeff attribute_used __attribute__((aligned(8))) = 0x00000038FFD2FFF8ULL; -#else -static const uint64_t bgr2YCoeff attribute_used __attribute__((aligned(8))) = 0x000020E540830C8BULL; -static const uint64_t bgr2UCoeff attribute_used __attribute__((aligned(8))) = 0x0000ED0FDAC23831ULL; -static const uint64_t bgr2VCoeff attribute_used __attribute__((aligned(8))) = 0x00003831D0E6F6EAULL; -#endif -static const uint64_t bgr2YOffset attribute_used __attribute__((aligned(8))) = 0x1010101010101010ULL; -static const uint64_t bgr2UVOffset attribute_used __attribute__((aligned(8)))= 0x8080808080808080ULL; -static const uint64_t w1111 attribute_used __attribute__((aligned(8))) = 0x0001000100010001ULL; +DECLARE_ASM_CONST(8, uint64_t, mask16g) = 0x07E007E007E007E0ULL; +DECLARE_ASM_CONST(8, uint64_t, mask16r) = 0xF800F800F800F800ULL; +DECLARE_ASM_CONST(8, uint64_t, red_16mask) = 0x0000f8000000f800ULL; +DECLARE_ASM_CONST(8, uint64_t, green_16mask) = 0x000007e0000007e0ULL; +DECLARE_ASM_CONST(8, uint64_t, blue_16mask) = 0x0000001f0000001fULL; +DECLARE_ASM_CONST(8, uint64_t, red_15mask) = 0x00007c0000007c00ULL; +DECLARE_ASM_CONST(8, uint64_t, green_15mask) = 0x000003e0000003e0ULL; +DECLARE_ASM_CONST(8, uint64_t, blue_15mask) = 0x0000001f0000001fULL; #if 0 static volatile uint64_t __attribute__((aligned(8))) b5Dither; @@ -146,12 +129,12 @@ static volatile uint64_t __attribute__((aligned(8))) g6Dither; static volatile uint64_t __attribute__((aligned(8))) r5Dither; static uint64_t __attribute__((aligned(8))) dither4[2]={ - 0x0103010301030103LL, - 0x0200020002000200LL,}; + 0x0103010301030103LL, + 0x0200020002000200LL,}; static uint64_t __attribute__((aligned(8))) dither8[2]={ - 0x0602060206020602LL, - 0x0004000400040004LL,}; + 0x0602060206020602LL, + 0x0004000400040004LL,}; #endif #endif /* defined(ARCH_X86) */ @@ -215,129 +198,15 @@ static uint64_t __attribute__((aligned(8))) dither8[2]={ void sws_rgb2rgb_init(int flags){ #if (defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX)) && defined(CONFIG_GPL) - if(flags & SWS_CPU_CAPS_MMX2){ - rgb15to16= rgb15to16_MMX2; - rgb15to24= rgb15to24_MMX2; - rgb15to32= rgb15to32_MMX2; - rgb16to24= rgb16to24_MMX2; - rgb16to32= rgb16to32_MMX2; - rgb16to15= rgb16to15_MMX2; - rgb24to16= rgb24to16_MMX2; - rgb24to15= rgb24to15_MMX2; - rgb24to32= rgb24to32_MMX2; - rgb32to16= rgb32to16_MMX2; - rgb32to15= rgb32to15_MMX2; - rgb32to24= rgb32to24_MMX2; - rgb24tobgr15= rgb24tobgr15_MMX2; - rgb24tobgr16= rgb24tobgr16_MMX2; - rgb24tobgr24= rgb24tobgr24_MMX2; - rgb32tobgr32= rgb32tobgr32_MMX2; - rgb32tobgr16= rgb32tobgr16_MMX2; - rgb32tobgr15= rgb32tobgr15_MMX2; - yv12toyuy2= yv12toyuy2_MMX2; - yv12touyvy= yv12touyvy_MMX2; - yuv422ptoyuy2= yuv422ptoyuy2_MMX2; - yuy2toyv12= yuy2toyv12_MMX2; -// uyvytoyv12= uyvytoyv12_MMX2; -// yvu9toyv12= yvu9toyv12_MMX2; - planar2x= planar2x_MMX2; - rgb24toyv12= rgb24toyv12_MMX2; - interleaveBytes= interleaveBytes_MMX2; - vu9_to_vu12= vu9_to_vu12_MMX2; - yvu9_to_yuy2= yvu9_to_yuy2_MMX2; - }else if(flags & SWS_CPU_CAPS_3DNOW){ - rgb15to16= rgb15to16_3DNOW; - rgb15to24= rgb15to24_3DNOW; - rgb15to32= rgb15to32_3DNOW; - rgb16to24= rgb16to24_3DNOW; - rgb16to32= rgb16to32_3DNOW; - rgb16to15= rgb16to15_3DNOW; - rgb24to16= rgb24to16_3DNOW; - rgb24to15= rgb24to15_3DNOW; - rgb24to32= rgb24to32_3DNOW; - rgb32to16= rgb32to16_3DNOW; - rgb32to15= rgb32to15_3DNOW; - rgb32to24= rgb32to24_3DNOW; - rgb24tobgr15= rgb24tobgr15_3DNOW; - rgb24tobgr16= rgb24tobgr16_3DNOW; - rgb24tobgr24= rgb24tobgr24_3DNOW; - rgb32tobgr32= rgb32tobgr32_3DNOW; - rgb32tobgr16= rgb32tobgr16_3DNOW; - rgb32tobgr15= rgb32tobgr15_3DNOW; - yv12toyuy2= yv12toyuy2_3DNOW; - yv12touyvy= yv12touyvy_3DNOW; - yuv422ptoyuy2= yuv422ptoyuy2_3DNOW; - yuy2toyv12= yuy2toyv12_3DNOW; -// uyvytoyv12= uyvytoyv12_3DNOW; -// yvu9toyv12= yvu9toyv12_3DNOW; - planar2x= planar2x_3DNOW; - rgb24toyv12= rgb24toyv12_3DNOW; - interleaveBytes= interleaveBytes_3DNOW; - vu9_to_vu12= vu9_to_vu12_3DNOW; - yvu9_to_yuy2= yvu9_to_yuy2_3DNOW; - }else if(flags & SWS_CPU_CAPS_MMX){ - rgb15to16= rgb15to16_MMX; - rgb15to24= rgb15to24_MMX; - rgb15to32= rgb15to32_MMX; - rgb16to24= rgb16to24_MMX; - rgb16to32= rgb16to32_MMX; - rgb16to15= rgb16to15_MMX; - rgb24to16= rgb24to16_MMX; - rgb24to15= rgb24to15_MMX; - rgb24to32= rgb24to32_MMX; - rgb32to16= rgb32to16_MMX; - rgb32to15= rgb32to15_MMX; - rgb32to24= rgb32to24_MMX; - rgb24tobgr15= rgb24tobgr15_MMX; - rgb24tobgr16= rgb24tobgr16_MMX; - rgb24tobgr24= rgb24tobgr24_MMX; - rgb32tobgr32= rgb32tobgr32_MMX; - rgb32tobgr16= rgb32tobgr16_MMX; - rgb32tobgr15= rgb32tobgr15_MMX; - yv12toyuy2= yv12toyuy2_MMX; - yv12touyvy= yv12touyvy_MMX; - yuv422ptoyuy2= yuv422ptoyuy2_MMX; - yuy2toyv12= yuy2toyv12_MMX; -// uyvytoyv12= uyvytoyv12_MMX; -// yvu9toyv12= yvu9toyv12_MMX; - planar2x= planar2x_MMX; - rgb24toyv12= rgb24toyv12_MMX; - interleaveBytes= interleaveBytes_MMX; - vu9_to_vu12= vu9_to_vu12_MMX; - yvu9_to_yuy2= yvu9_to_yuy2_MMX; - }else + if (flags & SWS_CPU_CAPS_MMX2) + rgb2rgb_init_MMX2(); + else if (flags & SWS_CPU_CAPS_3DNOW) + rgb2rgb_init_3DNOW(); + else if (flags & SWS_CPU_CAPS_MMX) + rgb2rgb_init_MMX(); + else #endif /* defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX) */ - { - rgb15to16= rgb15to16_C; - rgb15to24= rgb15to24_C; - rgb15to32= rgb15to32_C; - rgb16to24= rgb16to24_C; - rgb16to32= rgb16to32_C; - rgb16to15= rgb16to15_C; - rgb24to16= rgb24to16_C; - rgb24to15= rgb24to15_C; - rgb24to32= rgb24to32_C; - rgb32to16= rgb32to16_C; - rgb32to15= rgb32to15_C; - rgb32to24= rgb32to24_C; - rgb24tobgr15= rgb24tobgr15_C; - rgb24tobgr16= rgb24tobgr16_C; - rgb24tobgr24= rgb24tobgr24_C; - rgb32tobgr32= rgb32tobgr32_C; - rgb32tobgr16= rgb32tobgr16_C; - rgb32tobgr15= rgb32tobgr15_C; - yv12toyuy2= yv12toyuy2_C; - yv12touyvy= yv12touyvy_C; - yuv422ptoyuy2= yuv422ptoyuy2_C; - yuy2toyv12= yuy2toyv12_C; -// uyvytoyv12= uyvytoyv12_C; -// yvu9toyv12= yvu9toyv12_C; - planar2x= planar2x_C; - rgb24toyv12= rgb24toyv12_C; - interleaveBytes= interleaveBytes_C; - vu9_to_vu12= vu9_to_vu12_C; - yvu9_to_yuy2= yvu9_to_yuy2_C; - } + rgb2rgb_init_C(); } /** @@ -345,49 +214,49 @@ void sws_rgb2rgb_init(int flags){ */ void palette8torgb32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) { - long i; + long i; /* - for(i=0; i> 2; - for(i=0; i BGR24 (= B,G,R) */ - dst[3*i + 0] = src[4*i + 1]; - dst[3*i + 1] = src[4*i + 2]; - dst[3*i + 2] = src[4*i + 3]; - #else - dst[3*i + 0] = src[4*i + 2]; - dst[3*i + 1] = src[4*i + 1]; - dst[3*i + 2] = src[4*i + 0]; - #endif - } + long i; + long num_pixels = src_size >> 2; + for (i=0; i BGR24 (= B,G,R) */ + dst[3*i + 0] = src[4*i + 1]; + dst[3*i + 1] = src[4*i + 2]; + dst[3*i + 2] = src[4*i + 3]; + #else + dst[3*i + 0] = src[4*i + 2]; + dst[3*i + 1] = src[4*i + 1]; + dst[3*i + 2] = src[4*i + 0]; + #endif + } } void rgb24tobgr32(const uint8_t *src, uint8_t *dst, long src_size) { - long i; - for(i=0; 3*i BGR32 (= A,R,G,B) */ - dst[4*i + 0] = 0; - dst[4*i + 1] = src[3*i + 0]; - dst[4*i + 2] = src[3*i + 1]; - dst[4*i + 3] = src[3*i + 2]; - #else - dst[4*i + 0] = src[3*i + 2]; - dst[4*i + 1] = src[3*i + 1]; - dst[4*i + 2] = src[3*i + 0]; - dst[4*i + 3] = 0; - #endif - } + long i; + for (i=0; 3*i BGR32 (= A,R,G,B) */ + dst[4*i + 0] = 0; + dst[4*i + 1] = src[3*i + 0]; + dst[4*i + 2] = src[3*i + 1]; + dst[4*i + 3] = src[3*i + 2]; + #else + dst[4*i + 0] = src[3*i + 2]; + dst[4*i + 1] = src[3*i + 1]; + dst[4*i + 2] = src[3*i + 0]; + dst[4*i + 3] = 0; + #endif + } } void rgb16tobgr32(const uint8_t *src, uint8_t *dst, long src_size) { - const uint16_t *end; - uint8_t *d = (uint8_t *)dst; - const uint16_t *s = (uint16_t *)src; - end = s + src_size/2; - while(s < end) - { - register uint16_t bgr; - bgr = *s++; - #ifdef WORDS_BIGENDIAN - *d++ = 0; - *d++ = (bgr&0x1F)<<3; - *d++ = (bgr&0x7E0)>>3; - *d++ = (bgr&0xF800)>>8; - #else - *d++ = (bgr&0xF800)>>8; - *d++ = (bgr&0x7E0)>>3; - *d++ = (bgr&0x1F)<<3; - *d++ = 0; - #endif - } + const uint16_t *end; + uint8_t *d = (uint8_t *)dst; + const uint16_t *s = (uint16_t *)src; + end = s + src_size/2; + while (s < end) + { + register uint16_t bgr; + bgr = *s++; + #ifdef WORDS_BIGENDIAN + *d++ = 0; + *d++ = (bgr&0x1F)<<3; + *d++ = (bgr&0x7E0)>>3; + *d++ = (bgr&0xF800)>>8; + #else + *d++ = (bgr&0xF800)>>8; + *d++ = (bgr&0x7E0)>>3; + *d++ = (bgr&0x1F)<<3; + *d++ = 0; + #endif + } } void rgb16tobgr24(const uint8_t *src, uint8_t *dst, long src_size) { - const uint16_t *end; - uint8_t *d = (uint8_t *)dst; - const uint16_t *s = (const uint16_t *)src; - end = s + src_size/2; - while(s < end) - { - register uint16_t bgr; - bgr = *s++; - *d++ = (bgr&0xF800)>>8; - *d++ = (bgr&0x7E0)>>3; - *d++ = (bgr&0x1F)<<3; - } + const uint16_t *end; + uint8_t *d = (uint8_t *)dst; + const uint16_t *s = (const uint16_t *)src; + end = s + src_size/2; + while (s < end) + { + register uint16_t bgr; + bgr = *s++; + *d++ = (bgr&0xF800)>>8; + *d++ = (bgr&0x7E0)>>3; + *d++ = (bgr&0x1F)<<3; + } } void rgb16tobgr16(const uint8_t *src, uint8_t *dst, long src_size) { - long i; - long num_pixels = src_size >> 1; - - for(i=0; i>5; - b = (rgb&0xF800)>>11; - dst[2*i] = (b&0x1F) | ((g&0x3F)<<5) | ((r&0x1F)<<11); - } + long i; + long num_pixels = src_size >> 1; + + for (i=0; i>5; + b = (rgb&0xF800)>>11; + dst[2*i] = (b&0x1F) | ((g&0x3F)<<5) | ((r&0x1F)<<11); + } } void rgb16tobgr15(const uint8_t *src, uint8_t *dst, long src_size) { - long i; - long num_pixels = src_size >> 1; - - for(i=0; i>5; - b = (rgb&0xF800)>>11; - dst[2*i] = (b&0x1F) | ((g&0x1F)<<5) | ((r&0x1F)<<10); - } + long i; + long num_pixels = src_size >> 1; + + for (i=0; i>5; + b = (rgb&0xF800)>>11; + dst[2*i] = (b&0x1F) | ((g&0x1F)<<5) | ((r&0x1F)<<10); + } } void rgb15tobgr32(const uint8_t *src, uint8_t *dst, long src_size) { - const uint16_t *end; - uint8_t *d = (uint8_t *)dst; - const uint16_t *s = (const uint16_t *)src; - end = s + src_size/2; - while(s < end) - { - register uint16_t bgr; - bgr = *s++; - #ifdef WORDS_BIGENDIAN - *d++ = 0; - *d++ = (bgr&0x1F)<<3; - *d++ = (bgr&0x3E0)>>2; - *d++ = (bgr&0x7C00)>>7; - #else - *d++ = (bgr&0x7C00)>>7; - *d++ = (bgr&0x3E0)>>2; - *d++ = (bgr&0x1F)<<3; - *d++ = 0; - #endif - } + const uint16_t *end; + uint8_t *d = (uint8_t *)dst; + const uint16_t *s = (const uint16_t *)src; + end = s + src_size/2; + while (s < end) + { + register uint16_t bgr; + bgr = *s++; + #ifdef WORDS_BIGENDIAN + *d++ = 0; + *d++ = (bgr&0x1F)<<3; + *d++ = (bgr&0x3E0)>>2; + *d++ = (bgr&0x7C00)>>7; + #else + *d++ = (bgr&0x7C00)>>7; + *d++ = (bgr&0x3E0)>>2; + *d++ = (bgr&0x1F)<<3; + *d++ = 0; + #endif + } } void rgb15tobgr24(const uint8_t *src, uint8_t *dst, long src_size) { - const uint16_t *end; - uint8_t *d = (uint8_t *)dst; - const uint16_t *s = (uint16_t *)src; - end = s + src_size/2; - while(s < end) - { - register uint16_t bgr; - bgr = *s++; - *d++ = (bgr&0x7C00)>>7; - *d++ = (bgr&0x3E0)>>2; - *d++ = (bgr&0x1F)<<3; - } + const uint16_t *end; + uint8_t *d = (uint8_t *)dst; + const uint16_t *s = (uint16_t *)src; + end = s + src_size/2; + while (s < end) + { + register uint16_t bgr; + bgr = *s++; + *d++ = (bgr&0x7C00)>>7; + *d++ = (bgr&0x3E0)>>2; + *d++ = (bgr&0x1F)<<3; + } } void rgb15tobgr16(const uint8_t *src, uint8_t *dst, long src_size) { - long i; - long num_pixels = src_size >> 1; - - for(i=0; i>5; - b = (rgb&0x7C00)>>10; - dst[2*i] = (b&0x1F) | ((g&0x3F)<<5) | ((r&0x1F)<<11); - } + long i; + long num_pixels = src_size >> 1; + + for (i=0; i>5; + b = (rgb&0x7C00)>>10; + dst[2*i] = (b&0x1F) | ((g&0x3F)<<5) | ((r&0x1F)<<11); + } } void rgb15tobgr15(const uint8_t *src, uint8_t *dst, long src_size) { - long i; - long num_pixels = src_size >> 1; - - for(i=0; i>5; - b = (rgb&0x7C00)>>10; - dst[2*i] = (b&0x1F) | ((g&0x1F)<<5) | ((r&0x1F)<<10); - } + long i; + long num_pixels = src_size >> 1; + + for (i=0; i>5; + b = (rgb&0x7C00)>>10; + dst[2*i] = (b&0x1F) | ((g&0x1F)<<5) | ((r&0x1F)<<10); + } } void rgb8tobgr8(const uint8_t *src, uint8_t *dst, long src_size) { - long i; - long num_pixels = src_size; - for(i=0; i>3; - b = (rgb&0xC0)>>6; - dst[i] = ((b<<1)&0x07) | ((g&0x07)<<3) | ((r&0x03)<<6); - } + long i; + long num_pixels = src_size; + for (i=0; i>3; + b = (rgb&0xC0)>>6; + dst[i] = ((b<<1)&0x07) | ((g&0x07)<<3) | ((r&0x03)<<6); + } } diff --git a/contrib/ffmpeg/libswscale/rgb2rgb.h b/contrib/ffmpeg/libswscale/rgb2rgb.h index 4b5cc0a69..260732f73 100644 --- a/contrib/ffmpeg/libswscale/rgb2rgb.h +++ b/contrib/ffmpeg/libswscale/rgb2rgb.h @@ -1,5 +1,4 @@ /* - * * rgb2rgb.h, Software RGB to RGB convertor * pluralize by Software PAL8 to RGB convertor * Software YUV to YUV convertor @@ -21,27 +20,27 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef RGB2RGB_INCLUDED -#define RGB2RGB_INCLUDED +#ifndef FFMPEG_RGB2RGB_H +#define FFMPEG_RGB2RGB_H -// Note: do not fix the dependence on stdio.h +#include /* A full collection of rgb to rgb(bgr) convertors */ -extern void (*rgb24to32)(const uint8_t *src,uint8_t *dst,long src_size); -extern void (*rgb24to16)(const uint8_t *src,uint8_t *dst,long src_size); -extern void (*rgb24to15)(const uint8_t *src,uint8_t *dst,long src_size); -extern void (*rgb32to24)(const uint8_t *src,uint8_t *dst,long src_size); -extern void (*rgb32to16)(const uint8_t *src,uint8_t *dst,long src_size); -extern void (*rgb32to15)(const uint8_t *src,uint8_t *dst,long src_size); -extern void (*rgb15to16)(const uint8_t *src,uint8_t *dst,long src_size); -extern void (*rgb15to24)(const uint8_t *src,uint8_t *dst,long src_size); -extern void (*rgb15to32)(const uint8_t *src,uint8_t *dst,long src_size); -extern void (*rgb16to15)(const uint8_t *src,uint8_t *dst,long src_size); -extern void (*rgb16to24)(const uint8_t *src,uint8_t *dst,long src_size); -extern void (*rgb16to32)(const uint8_t *src,uint8_t *dst,long src_size); +extern void (*rgb24to32) (const uint8_t *src, uint8_t *dst, long src_size); +extern void (*rgb24to16) (const uint8_t *src, uint8_t *dst, long src_size); +extern void (*rgb24to15) (const uint8_t *src, uint8_t *dst, long src_size); +extern void (*rgb32to24) (const uint8_t *src, uint8_t *dst, long src_size); +extern void (*rgb32to16) (const uint8_t *src, uint8_t *dst, long src_size); +extern void (*rgb32to15) (const uint8_t *src, uint8_t *dst, long src_size); +extern void (*rgb15to16) (const uint8_t *src, uint8_t *dst, long src_size); +extern void (*rgb15to24) (const uint8_t *src, uint8_t *dst, long src_size); +extern void (*rgb15to32) (const uint8_t *src, uint8_t *dst, long src_size); +extern void (*rgb16to15) (const uint8_t *src, uint8_t *dst, long src_size); +extern void (*rgb16to24) (const uint8_t *src, uint8_t *dst, long src_size); +extern void (*rgb16to32) (const uint8_t *src, uint8_t *dst, long src_size); extern void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); extern void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size); extern void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size); @@ -59,7 +58,7 @@ extern void rgb15tobgr32(const uint8_t *src, uint8_t *dst, long src_size); extern void rgb15tobgr24(const uint8_t *src, uint8_t *dst, long src_size); extern void rgb15tobgr16(const uint8_t *src, uint8_t *dst, long src_size); extern void rgb15tobgr15(const uint8_t *src, uint8_t *dst, long src_size); -extern void rgb8tobgr8(const uint8_t *src, uint8_t *dst, long src_size); +extern void rgb8tobgr8 (const uint8_t *src, uint8_t *dst, long src_size); extern void palette8torgb32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); @@ -85,16 +84,16 @@ extern void palette8tobgr15(const uint8_t *src, uint8_t *dst, long num_pixels, c * problem for anyone then tell me, and ill fix it) */ extern void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, - long width, long height, - long lumStride, long chromStride, long dstStride); + long width, long height, + long lumStride, long chromStride, long dstStride); /** * * width should be a multiple of 16 */ extern void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, - long width, long height, - long lumStride, long chromStride, long dstStride); + long width, long height, + long lumStride, long chromStride, long dstStride); /** * @@ -102,8 +101,8 @@ extern void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uin * problem for anyone then tell me, and ill fix it) */ extern void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, - long width, long height, - long lumStride, long chromStride, long srcStride); + long width, long height, + long lumStride, long chromStride, long srcStride); /** * @@ -111,8 +110,8 @@ extern void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint * problem for anyone then tell me, and ill fix it) */ extern void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, - long width, long height, - long lumStride, long chromStride, long dstStride); + long width, long height, + long lumStride, long chromStride, long dstStride); /** * @@ -121,27 +120,27 @@ extern void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_ * chrominance data is only taken from every secound line others are ignored FIXME write HQ version */ extern void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, - long width, long height, - long lumStride, long chromStride, long srcStride); + long width, long height, + long lumStride, long chromStride, long srcStride); extern void (*planar2x)(const uint8_t *src, uint8_t *dst, long width, long height, - long srcStride, long dstStride); + long srcStride, long dstStride); extern void (*interleaveBytes)(uint8_t *src1, uint8_t *src2, uint8_t *dst, - long width, long height, long src1Stride, - long src2Stride, long dstStride); + long width, long height, long src1Stride, + long src2Stride, long dstStride); extern void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2, - uint8_t *dst1, uint8_t *dst2, - long width, long height, - long srcStride1, long srcStride2, - long dstStride1, long dstStride2); + uint8_t *dst1, uint8_t *dst2, + long width, long height, + long srcStride1, long srcStride2, + long dstStride1, long dstStride2); extern void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, - uint8_t *dst, - long width, long height, - long srcStride1, long srcStride2, - long srcStride3, long dstStride); - + uint8_t *dst, + long width, long height, + long srcStride1, long srcStride2, + long srcStride3, long dstStride); + void sws_rgb2rgb_init(int flags); -#endif +#endif /* FFMPEG_RGB2RGB_H */ diff --git a/contrib/ffmpeg/libswscale/rgb2rgb_template.c b/contrib/ffmpeg/libswscale/rgb2rgb_template.c index d9511c955..4aa607d9a 100644 --- a/contrib/ffmpeg/libswscale/rgb2rgb_template.c +++ b/contrib/ffmpeg/libswscale/rgb2rgb_template.c @@ -1,5 +1,4 @@ /* - * * rgb2rgb.c, Software RGB to RGB convertor * pluralize by Software PAL8 to RGB convertor * Software YUV to YUV convertor @@ -22,17 +21,17 @@ * * You should have received a copy of the GNU General Public License * along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - * the C code (not assembly, mmx, ...) of this file can be used - * under the LGPL license too + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * The C code (not assembly, mmx, ...) of this file can be used + * under the LGPL license. */ #include #include /* for __WORDSIZE */ #ifndef __WORDSIZE -// #warning You have misconfigured system and probably will lose performance! +// #warning You have a misconfigured system and will probably lose performance! #define __WORDSIZE MP_WORDSIZE #endif @@ -53,11 +52,11 @@ #ifdef HAVE_3DNOW #define PREFETCH "prefetch" #define PREFETCHW "prefetchw" -#define PAVGB "pavgusb" -#elif defined ( HAVE_MMX2 ) +#define PAVGB "pavgusb" +#elif defined (HAVE_MMX2) #define PREFETCH "prefetchnta" #define PREFETCHW "prefetcht0" -#define PAVGB "pavgb" +#define PAVGB "pavgb" #else #ifdef __APPLE__ #define PREFETCH "#" @@ -69,7 +68,7 @@ #endif #ifdef HAVE_3DNOW -/* On K6 femms is faster of emms. On K7 femms is directly mapped on emms. */ +/* On K6 femms is faster than emms. On K7 femms is directly mapped on emms. */ #define EMMS "femms" #else #define EMMS "emms" @@ -83,836 +82,838 @@ #define SFENCE " # nop" #endif -static inline void RENAME(rgb24to32)(const uint8_t *src,uint8_t *dst,long src_size) +static inline void RENAME(rgb24to32)(const uint8_t *src, uint8_t *dst, long src_size) { - uint8_t *dest = dst; - const uint8_t *s = src; - const uint8_t *end; -#ifdef HAVE_MMX - const uint8_t *mm_end; -#endif - end = s + src_size; -#ifdef HAVE_MMX - __asm __volatile(PREFETCH" %0"::"m"(*s):"memory"); - mm_end = end - 23; - __asm __volatile("movq %0, %%mm7"::"m"(mask32):"memory"); - while(s < mm_end) - { - __asm __volatile( - PREFETCH" 32%1\n\t" - "movd %1, %%mm0\n\t" - "punpckldq 3%1, %%mm0\n\t" - "movd 6%1, %%mm1\n\t" - "punpckldq 9%1, %%mm1\n\t" - "movd 12%1, %%mm2\n\t" - "punpckldq 15%1, %%mm2\n\t" - "movd 18%1, %%mm3\n\t" - "punpckldq 21%1, %%mm3\n\t" - "pand %%mm7, %%mm0\n\t" - "pand %%mm7, %%mm1\n\t" - "pand %%mm7, %%mm2\n\t" - "pand %%mm7, %%mm3\n\t" - MOVNTQ" %%mm0, %0\n\t" - MOVNTQ" %%mm1, 8%0\n\t" - MOVNTQ" %%mm2, 16%0\n\t" - MOVNTQ" %%mm3, 24%0" - :"=m"(*dest) - :"m"(*s) - :"memory"); - dest += 32; - s += 24; - } - __asm __volatile(SFENCE:::"memory"); - __asm __volatile(EMMS:::"memory"); -#endif - while(s < end) - { -#ifdef WORDS_BIGENDIAN - /* RGB24 (= R,G,B) -> RGB32 (= A,B,G,R) */ - *dest++ = 0; - *dest++ = s[2]; - *dest++ = s[1]; - *dest++ = s[0]; - s+=3; -#else - *dest++ = *s++; - *dest++ = *s++; - *dest++ = *s++; - *dest++ = 0; -#endif - } + uint8_t *dest = dst; + const uint8_t *s = src; + const uint8_t *end; + #ifdef HAVE_MMX + const uint8_t *mm_end; + #endif + end = s + src_size; + #ifdef HAVE_MMX + asm volatile(PREFETCH" %0"::"m"(*s):"memory"); + mm_end = end - 23; + asm volatile("movq %0, %%mm7"::"m"(mask32):"memory"); + while (s < mm_end) + { + asm volatile( + PREFETCH" 32%1 \n\t" + "movd %1, %%mm0 \n\t" + "punpckldq 3%1, %%mm0 \n\t" + "movd 6%1, %%mm1 \n\t" + "punpckldq 9%1, %%mm1 \n\t" + "movd 12%1, %%mm2 \n\t" + "punpckldq 15%1, %%mm2 \n\t" + "movd 18%1, %%mm3 \n\t" + "punpckldq 21%1, %%mm3 \n\t" + "pand %%mm7, %%mm0 \n\t" + "pand %%mm7, %%mm1 \n\t" + "pand %%mm7, %%mm2 \n\t" + "pand %%mm7, %%mm3 \n\t" + MOVNTQ" %%mm0, %0 \n\t" + MOVNTQ" %%mm1, 8%0 \n\t" + MOVNTQ" %%mm2, 16%0 \n\t" + MOVNTQ" %%mm3, 24%0" + :"=m"(*dest) + :"m"(*s) + :"memory"); + dest += 32; + s += 24; + } + asm volatile(SFENCE:::"memory"); + asm volatile(EMMS:::"memory"); + #endif + while (s < end) + { + #ifdef WORDS_BIGENDIAN + /* RGB24 (= R,G,B) -> RGB32 (= A,B,G,R) */ + *dest++ = 0; + *dest++ = s[2]; + *dest++ = s[1]; + *dest++ = s[0]; + s+=3; + #else + *dest++ = *s++; + *dest++ = *s++; + *dest++ = *s++; + *dest++ = 0; + #endif + } } -static inline void RENAME(rgb32to24)(const uint8_t *src,uint8_t *dst,long src_size) +static inline void RENAME(rgb32to24)(const uint8_t *src, uint8_t *dst, long src_size) { - uint8_t *dest = dst; - const uint8_t *s = src; - const uint8_t *end; + uint8_t *dest = dst; + const uint8_t *s = src; + const uint8_t *end; #ifdef HAVE_MMX - const uint8_t *mm_end; + const uint8_t *mm_end; #endif - end = s + src_size; + end = s + src_size; #ifdef HAVE_MMX - __asm __volatile(PREFETCH" %0"::"m"(*s):"memory"); - mm_end = end - 31; - while(s < mm_end) - { - __asm __volatile( - PREFETCH" 32%1\n\t" - "movq %1, %%mm0\n\t" - "movq 8%1, %%mm1\n\t" - "movq 16%1, %%mm4\n\t" - "movq 24%1, %%mm5\n\t" - "movq %%mm0, %%mm2\n\t" - "movq %%mm1, %%mm3\n\t" - "movq %%mm4, %%mm6\n\t" - "movq %%mm5, %%mm7\n\t" - "psrlq $8, %%mm2\n\t" - "psrlq $8, %%mm3\n\t" - "psrlq $8, %%mm6\n\t" - "psrlq $8, %%mm7\n\t" - "pand %2, %%mm0\n\t" - "pand %2, %%mm1\n\t" - "pand %2, %%mm4\n\t" - "pand %2, %%mm5\n\t" - "pand %3, %%mm2\n\t" - "pand %3, %%mm3\n\t" - "pand %3, %%mm6\n\t" - "pand %3, %%mm7\n\t" - "por %%mm2, %%mm0\n\t" - "por %%mm3, %%mm1\n\t" - "por %%mm6, %%mm4\n\t" - "por %%mm7, %%mm5\n\t" - - "movq %%mm1, %%mm2\n\t" - "movq %%mm4, %%mm3\n\t" - "psllq $48, %%mm2\n\t" - "psllq $32, %%mm3\n\t" - "pand %4, %%mm2\n\t" - "pand %5, %%mm3\n\t" - "por %%mm2, %%mm0\n\t" - "psrlq $16, %%mm1\n\t" - "psrlq $32, %%mm4\n\t" - "psllq $16, %%mm5\n\t" - "por %%mm3, %%mm1\n\t" - "pand %6, %%mm5\n\t" - "por %%mm5, %%mm4\n\t" - - MOVNTQ" %%mm0, %0\n\t" - MOVNTQ" %%mm1, 8%0\n\t" - MOVNTQ" %%mm4, 16%0" - :"=m"(*dest) - :"m"(*s),"m"(mask24l), - "m"(mask24h),"m"(mask24hh),"m"(mask24hhh),"m"(mask24hhhh) - :"memory"); - dest += 24; - s += 32; - } - __asm __volatile(SFENCE:::"memory"); - __asm __volatile(EMMS:::"memory"); -#endif - while(s < end) - { + asm volatile(PREFETCH" %0"::"m"(*s):"memory"); + mm_end = end - 31; + while (s < mm_end) + { + asm volatile( + PREFETCH" 32%1 \n\t" + "movq %1, %%mm0 \n\t" + "movq 8%1, %%mm1 \n\t" + "movq 16%1, %%mm4 \n\t" + "movq 24%1, %%mm5 \n\t" + "movq %%mm0, %%mm2 \n\t" + "movq %%mm1, %%mm3 \n\t" + "movq %%mm4, %%mm6 \n\t" + "movq %%mm5, %%mm7 \n\t" + "psrlq $8, %%mm2 \n\t" + "psrlq $8, %%mm3 \n\t" + "psrlq $8, %%mm6 \n\t" + "psrlq $8, %%mm7 \n\t" + "pand %2, %%mm0 \n\t" + "pand %2, %%mm1 \n\t" + "pand %2, %%mm4 \n\t" + "pand %2, %%mm5 \n\t" + "pand %3, %%mm2 \n\t" + "pand %3, %%mm3 \n\t" + "pand %3, %%mm6 \n\t" + "pand %3, %%mm7 \n\t" + "por %%mm2, %%mm0 \n\t" + "por %%mm3, %%mm1 \n\t" + "por %%mm6, %%mm4 \n\t" + "por %%mm7, %%mm5 \n\t" + + "movq %%mm1, %%mm2 \n\t" + "movq %%mm4, %%mm3 \n\t" + "psllq $48, %%mm2 \n\t" + "psllq $32, %%mm3 \n\t" + "pand %4, %%mm2 \n\t" + "pand %5, %%mm3 \n\t" + "por %%mm2, %%mm0 \n\t" + "psrlq $16, %%mm1 \n\t" + "psrlq $32, %%mm4 \n\t" + "psllq $16, %%mm5 \n\t" + "por %%mm3, %%mm1 \n\t" + "pand %6, %%mm5 \n\t" + "por %%mm5, %%mm4 \n\t" + + MOVNTQ" %%mm0, %0 \n\t" + MOVNTQ" %%mm1, 8%0 \n\t" + MOVNTQ" %%mm4, 16%0" + :"=m"(*dest) + :"m"(*s),"m"(mask24l), + "m"(mask24h),"m"(mask24hh),"m"(mask24hhh),"m"(mask24hhhh) + :"memory"); + dest += 24; + s += 32; + } + asm volatile(SFENCE:::"memory"); + asm volatile(EMMS:::"memory"); +#endif + while (s < end) + { #ifdef WORDS_BIGENDIAN - /* RGB32 (= A,B,G,R) -> RGB24 (= R,G,B) */ - s++; - dest[2] = *s++; - dest[1] = *s++; - dest[0] = *s++; - dest += 3; + /* RGB32 (= A,B,G,R) -> RGB24 (= R,G,B) */ + s++; + dest[2] = *s++; + dest[1] = *s++; + dest[0] = *s++; + dest += 3; #else - *dest++ = *s++; - *dest++ = *s++; - *dest++ = *s++; - s++; + *dest++ = *s++; + *dest++ = *s++; + *dest++ = *s++; + s++; #endif - } + } } /* Original by Strepto/Astral ported to gcc & bugfixed : A'rpi MMX2, 3DNOW optimization by Nick Kurshev - 32bit c version, and and&add trick by Michael Niedermayer + 32 bit C version, and and&add trick by Michael Niedermayer */ -static inline void RENAME(rgb15to16)(const uint8_t *src,uint8_t *dst,long src_size) +static inline void RENAME(rgb15to16)(const uint8_t *src, uint8_t *dst, long src_size) { - register const uint8_t* s=src; - register uint8_t* d=dst; - register const uint8_t *end; - const uint8_t *mm_end; - end = s + src_size; + register const uint8_t* s=src; + register uint8_t* d=dst; + register const uint8_t *end; + const uint8_t *mm_end; + end = s + src_size; #ifdef HAVE_MMX - __asm __volatile(PREFETCH" %0"::"m"(*s)); - __asm __volatile("movq %0, %%mm4"::"m"(mask15s)); - mm_end = end - 15; - while(s>1)&0x7FE07FE0) | (x&0x001F001F); - s+=4; - d+=4; + register uint32_t x= *((uint32_t *)s); + *((uint32_t *)d) = ((x>>1)&0x7FE07FE0) | (x&0x001F001F); + s+=4; + d+=4; } - if(s < end) + if (s < end) { - register uint16_t x= *((uint16_t *)s); - *((uint16_t *)d) = ((x>>1)&0x7FE0) | (x&0x001F); - s+=2; - d+=2; + register uint16_t x= *((uint16_t *)s); + *((uint16_t *)d) = ((x>>1)&0x7FE0) | (x&0x001F); + s+=2; + d+=2; } } static inline void RENAME(rgb32to16)(const uint8_t *src, uint8_t *dst, long src_size) { - const uint8_t *s = src; - const uint8_t *end; + const uint8_t *s = src; + const uint8_t *end; #ifdef HAVE_MMX - const uint8_t *mm_end; + const uint8_t *mm_end; #endif - uint16_t *d = (uint16_t *)dst; - end = s + src_size; + uint16_t *d = (uint16_t *)dst; + end = s + src_size; #ifdef HAVE_MMX - mm_end = end - 15; -#if 1 //is faster only if multiplies are reasonable fast (FIXME figure out on which cpus this is faster, on Athlon its slightly faster) - asm volatile( - "movq %3, %%mm5 \n\t" - "movq %4, %%mm6 \n\t" - "movq %5, %%mm7 \n\t" - ASMALIGN(4) - "1: \n\t" - PREFETCH" 32(%1) \n\t" - "movd (%1), %%mm0 \n\t" - "movd 4(%1), %%mm3 \n\t" - "punpckldq 8(%1), %%mm0 \n\t" - "punpckldq 12(%1), %%mm3 \n\t" - "movq %%mm0, %%mm1 \n\t" - "movq %%mm3, %%mm4 \n\t" - "pand %%mm6, %%mm0 \n\t" - "pand %%mm6, %%mm3 \n\t" - "pmaddwd %%mm7, %%mm0 \n\t" - "pmaddwd %%mm7, %%mm3 \n\t" - "pand %%mm5, %%mm1 \n\t" - "pand %%mm5, %%mm4 \n\t" - "por %%mm1, %%mm0 \n\t" - "por %%mm4, %%mm3 \n\t" - "psrld $5, %%mm0 \n\t" - "pslld $11, %%mm3 \n\t" - "por %%mm3, %%mm0 \n\t" - MOVNTQ" %%mm0, (%0) \n\t" - "add $16, %1 \n\t" - "add $8, %0 \n\t" - "cmp %2, %1 \n\t" - " jb 1b \n\t" - : "+r" (d), "+r"(s) - : "r" (mm_end), "m" (mask3216g), "m" (mask3216br), "m" (mul3216) - ); + mm_end = end - 15; +#if 1 //is faster only if multiplies are reasonably fast (FIXME figure out on which CPUs this is faster, on Athlon it is slightly faster) + asm volatile( + "movq %3, %%mm5 \n\t" + "movq %4, %%mm6 \n\t" + "movq %5, %%mm7 \n\t" + "jmp 2f \n\t" + ASMALIGN(4) + "1: \n\t" + PREFETCH" 32(%1) \n\t" + "movd (%1), %%mm0 \n\t" + "movd 4(%1), %%mm3 \n\t" + "punpckldq 8(%1), %%mm0 \n\t" + "punpckldq 12(%1), %%mm3 \n\t" + "movq %%mm0, %%mm1 \n\t" + "movq %%mm3, %%mm4 \n\t" + "pand %%mm6, %%mm0 \n\t" + "pand %%mm6, %%mm3 \n\t" + "pmaddwd %%mm7, %%mm0 \n\t" + "pmaddwd %%mm7, %%mm3 \n\t" + "pand %%mm5, %%mm1 \n\t" + "pand %%mm5, %%mm4 \n\t" + "por %%mm1, %%mm0 \n\t" + "por %%mm4, %%mm3 \n\t" + "psrld $5, %%mm0 \n\t" + "pslld $11, %%mm3 \n\t" + "por %%mm3, %%mm0 \n\t" + MOVNTQ" %%mm0, (%0) \n\t" + "add $16, %1 \n\t" + "add $8, %0 \n\t" + "2: \n\t" + "cmp %2, %1 \n\t" + " jb 1b \n\t" + : "+r" (d), "+r"(s) + : "r" (mm_end), "m" (mask3216g), "m" (mask3216br), "m" (mul3216) + ); #else - __asm __volatile(PREFETCH" %0"::"m"(*src):"memory"); - __asm __volatile( - "movq %0, %%mm7\n\t" - "movq %1, %%mm6\n\t" - ::"m"(red_16mask),"m"(green_16mask)); - while(s < mm_end) - { - __asm __volatile( - PREFETCH" 32%1\n\t" - "movd %1, %%mm0\n\t" - "movd 4%1, %%mm3\n\t" - "punpckldq 8%1, %%mm0\n\t" - "punpckldq 12%1, %%mm3\n\t" - "movq %%mm0, %%mm1\n\t" - "movq %%mm0, %%mm2\n\t" - "movq %%mm3, %%mm4\n\t" - "movq %%mm3, %%mm5\n\t" - "psrlq $3, %%mm0\n\t" - "psrlq $3, %%mm3\n\t" - "pand %2, %%mm0\n\t" - "pand %2, %%mm3\n\t" - "psrlq $5, %%mm1\n\t" - "psrlq $5, %%mm4\n\t" - "pand %%mm6, %%mm1\n\t" - "pand %%mm6, %%mm4\n\t" - "psrlq $8, %%mm2\n\t" - "psrlq $8, %%mm5\n\t" - "pand %%mm7, %%mm2\n\t" - "pand %%mm7, %%mm5\n\t" - "por %%mm1, %%mm0\n\t" - "por %%mm4, %%mm3\n\t" - "por %%mm2, %%mm0\n\t" - "por %%mm5, %%mm3\n\t" - "psllq $16, %%mm3\n\t" - "por %%mm3, %%mm0\n\t" - MOVNTQ" %%mm0, %0\n\t" - :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory"); - d += 4; - s += 16; - } -#endif - __asm __volatile(SFENCE:::"memory"); - __asm __volatile(EMMS:::"memory"); -#endif - while(s < end) - { - register int rgb = *(uint32_t*)s; s += 4; - *d++ = ((rgb&0xFF)>>3) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>8); - } + asm volatile(PREFETCH" %0"::"m"(*src):"memory"); + asm volatile( + "movq %0, %%mm7 \n\t" + "movq %1, %%mm6 \n\t" + ::"m"(red_16mask),"m"(green_16mask)); + while (s < mm_end) + { + asm volatile( + PREFETCH" 32%1 \n\t" + "movd %1, %%mm0 \n\t" + "movd 4%1, %%mm3 \n\t" + "punpckldq 8%1, %%mm0 \n\t" + "punpckldq 12%1, %%mm3 \n\t" + "movq %%mm0, %%mm1 \n\t" + "movq %%mm0, %%mm2 \n\t" + "movq %%mm3, %%mm4 \n\t" + "movq %%mm3, %%mm5 \n\t" + "psrlq $3, %%mm0 \n\t" + "psrlq $3, %%mm3 \n\t" + "pand %2, %%mm0 \n\t" + "pand %2, %%mm3 \n\t" + "psrlq $5, %%mm1 \n\t" + "psrlq $5, %%mm4 \n\t" + "pand %%mm6, %%mm1 \n\t" + "pand %%mm6, %%mm4 \n\t" + "psrlq $8, %%mm2 \n\t" + "psrlq $8, %%mm5 \n\t" + "pand %%mm7, %%mm2 \n\t" + "pand %%mm7, %%mm5 \n\t" + "por %%mm1, %%mm0 \n\t" + "por %%mm4, %%mm3 \n\t" + "por %%mm2, %%mm0 \n\t" + "por %%mm5, %%mm3 \n\t" + "psllq $16, %%mm3 \n\t" + "por %%mm3, %%mm0 \n\t" + MOVNTQ" %%mm0, %0 \n\t" + :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory"); + d += 4; + s += 16; + } +#endif + asm volatile(SFENCE:::"memory"); + asm volatile(EMMS:::"memory"); +#endif + while (s < end) + { + register int rgb = *(uint32_t*)s; s += 4; + *d++ = ((rgb&0xFF)>>3) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>8); + } } static inline void RENAME(rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size) { - const uint8_t *s = src; - const uint8_t *end; + const uint8_t *s = src; + const uint8_t *end; #ifdef HAVE_MMX - const uint8_t *mm_end; + const uint8_t *mm_end; #endif - uint16_t *d = (uint16_t *)dst; - end = s + src_size; + uint16_t *d = (uint16_t *)dst; + end = s + src_size; #ifdef HAVE_MMX - __asm __volatile(PREFETCH" %0"::"m"(*src):"memory"); - __asm __volatile( - "movq %0, %%mm7\n\t" - "movq %1, %%mm6\n\t" - ::"m"(red_16mask),"m"(green_16mask)); - mm_end = end - 15; - while(s < mm_end) - { - __asm __volatile( - PREFETCH" 32%1\n\t" - "movd %1, %%mm0\n\t" - "movd 4%1, %%mm3\n\t" - "punpckldq 8%1, %%mm0\n\t" - "punpckldq 12%1, %%mm3\n\t" - "movq %%mm0, %%mm1\n\t" - "movq %%mm0, %%mm2\n\t" - "movq %%mm3, %%mm4\n\t" - "movq %%mm3, %%mm5\n\t" - "psllq $8, %%mm0\n\t" - "psllq $8, %%mm3\n\t" - "pand %%mm7, %%mm0\n\t" - "pand %%mm7, %%mm3\n\t" - "psrlq $5, %%mm1\n\t" - "psrlq $5, %%mm4\n\t" - "pand %%mm6, %%mm1\n\t" - "pand %%mm6, %%mm4\n\t" - "psrlq $19, %%mm2\n\t" - "psrlq $19, %%mm5\n\t" - "pand %2, %%mm2\n\t" - "pand %2, %%mm5\n\t" - "por %%mm1, %%mm0\n\t" - "por %%mm4, %%mm3\n\t" - "por %%mm2, %%mm0\n\t" - "por %%mm5, %%mm3\n\t" - "psllq $16, %%mm3\n\t" - "por %%mm3, %%mm0\n\t" - MOVNTQ" %%mm0, %0\n\t" - :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory"); - d += 4; - s += 16; - } - __asm __volatile(SFENCE:::"memory"); - __asm __volatile(EMMS:::"memory"); -#endif - while(s < end) - { - register int rgb = *(uint32_t*)s; s += 4; - *d++ = ((rgb&0xF8)<<8) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>19); - } + asm volatile(PREFETCH" %0"::"m"(*src):"memory"); + asm volatile( + "movq %0, %%mm7 \n\t" + "movq %1, %%mm6 \n\t" + ::"m"(red_16mask),"m"(green_16mask)); + mm_end = end - 15; + while (s < mm_end) + { + asm volatile( + PREFETCH" 32%1 \n\t" + "movd %1, %%mm0 \n\t" + "movd 4%1, %%mm3 \n\t" + "punpckldq 8%1, %%mm0 \n\t" + "punpckldq 12%1, %%mm3 \n\t" + "movq %%mm0, %%mm1 \n\t" + "movq %%mm0, %%mm2 \n\t" + "movq %%mm3, %%mm4 \n\t" + "movq %%mm3, %%mm5 \n\t" + "psllq $8, %%mm0 \n\t" + "psllq $8, %%mm3 \n\t" + "pand %%mm7, %%mm0 \n\t" + "pand %%mm7, %%mm3 \n\t" + "psrlq $5, %%mm1 \n\t" + "psrlq $5, %%mm4 \n\t" + "pand %%mm6, %%mm1 \n\t" + "pand %%mm6, %%mm4 \n\t" + "psrlq $19, %%mm2 \n\t" + "psrlq $19, %%mm5 \n\t" + "pand %2, %%mm2 \n\t" + "pand %2, %%mm5 \n\t" + "por %%mm1, %%mm0 \n\t" + "por %%mm4, %%mm3 \n\t" + "por %%mm2, %%mm0 \n\t" + "por %%mm5, %%mm3 \n\t" + "psllq $16, %%mm3 \n\t" + "por %%mm3, %%mm0 \n\t" + MOVNTQ" %%mm0, %0 \n\t" + :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory"); + d += 4; + s += 16; + } + asm volatile(SFENCE:::"memory"); + asm volatile(EMMS:::"memory"); +#endif + while (s < end) + { + register int rgb = *(uint32_t*)s; s += 4; + *d++ = ((rgb&0xF8)<<8) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>19); + } } static inline void RENAME(rgb32to15)(const uint8_t *src, uint8_t *dst, long src_size) { - const uint8_t *s = src; - const uint8_t *end; + const uint8_t *s = src; + const uint8_t *end; #ifdef HAVE_MMX - const uint8_t *mm_end; + const uint8_t *mm_end; #endif - uint16_t *d = (uint16_t *)dst; - end = s + src_size; + uint16_t *d = (uint16_t *)dst; + end = s + src_size; #ifdef HAVE_MMX - mm_end = end - 15; -#if 1 //is faster only if multiplies are reasonable fast (FIXME figure out on which cpus this is faster, on Athlon its slightly faster) - asm volatile( - "movq %3, %%mm5 \n\t" - "movq %4, %%mm6 \n\t" - "movq %5, %%mm7 \n\t" - ASMALIGN(4) - "1: \n\t" - PREFETCH" 32(%1) \n\t" - "movd (%1), %%mm0 \n\t" - "movd 4(%1), %%mm3 \n\t" - "punpckldq 8(%1), %%mm0 \n\t" - "punpckldq 12(%1), %%mm3 \n\t" - "movq %%mm0, %%mm1 \n\t" - "movq %%mm3, %%mm4 \n\t" - "pand %%mm6, %%mm0 \n\t" - "pand %%mm6, %%mm3 \n\t" - "pmaddwd %%mm7, %%mm0 \n\t" - "pmaddwd %%mm7, %%mm3 \n\t" - "pand %%mm5, %%mm1 \n\t" - "pand %%mm5, %%mm4 \n\t" - "por %%mm1, %%mm0 \n\t" - "por %%mm4, %%mm3 \n\t" - "psrld $6, %%mm0 \n\t" - "pslld $10, %%mm3 \n\t" - "por %%mm3, %%mm0 \n\t" - MOVNTQ" %%mm0, (%0) \n\t" - "add $16, %1 \n\t" - "add $8, %0 \n\t" - "cmp %2, %1 \n\t" - " jb 1b \n\t" - : "+r" (d), "+r"(s) - : "r" (mm_end), "m" (mask3215g), "m" (mask3216br), "m" (mul3215) - ); + mm_end = end - 15; +#if 1 //is faster only if multiplies are reasonably fast (FIXME figure out on which CPUs this is faster, on Athlon it is slightly faster) + asm volatile( + "movq %3, %%mm5 \n\t" + "movq %4, %%mm6 \n\t" + "movq %5, %%mm7 \n\t" + "jmp 2f \n\t" + ASMALIGN(4) + "1: \n\t" + PREFETCH" 32(%1) \n\t" + "movd (%1), %%mm0 \n\t" + "movd 4(%1), %%mm3 \n\t" + "punpckldq 8(%1), %%mm0 \n\t" + "punpckldq 12(%1), %%mm3 \n\t" + "movq %%mm0, %%mm1 \n\t" + "movq %%mm3, %%mm4 \n\t" + "pand %%mm6, %%mm0 \n\t" + "pand %%mm6, %%mm3 \n\t" + "pmaddwd %%mm7, %%mm0 \n\t" + "pmaddwd %%mm7, %%mm3 \n\t" + "pand %%mm5, %%mm1 \n\t" + "pand %%mm5, %%mm4 \n\t" + "por %%mm1, %%mm0 \n\t" + "por %%mm4, %%mm3 \n\t" + "psrld $6, %%mm0 \n\t" + "pslld $10, %%mm3 \n\t" + "por %%mm3, %%mm0 \n\t" + MOVNTQ" %%mm0, (%0) \n\t" + "add $16, %1 \n\t" + "add $8, %0 \n\t" + "2: \n\t" + "cmp %2, %1 \n\t" + " jb 1b \n\t" + : "+r" (d), "+r"(s) + : "r" (mm_end), "m" (mask3215g), "m" (mask3216br), "m" (mul3215) + ); #else - __asm __volatile(PREFETCH" %0"::"m"(*src):"memory"); - __asm __volatile( - "movq %0, %%mm7\n\t" - "movq %1, %%mm6\n\t" - ::"m"(red_15mask),"m"(green_15mask)); - while(s < mm_end) - { - __asm __volatile( - PREFETCH" 32%1\n\t" - "movd %1, %%mm0\n\t" - "movd 4%1, %%mm3\n\t" - "punpckldq 8%1, %%mm0\n\t" - "punpckldq 12%1, %%mm3\n\t" - "movq %%mm0, %%mm1\n\t" - "movq %%mm0, %%mm2\n\t" - "movq %%mm3, %%mm4\n\t" - "movq %%mm3, %%mm5\n\t" - "psrlq $3, %%mm0\n\t" - "psrlq $3, %%mm3\n\t" - "pand %2, %%mm0\n\t" - "pand %2, %%mm3\n\t" - "psrlq $6, %%mm1\n\t" - "psrlq $6, %%mm4\n\t" - "pand %%mm6, %%mm1\n\t" - "pand %%mm6, %%mm4\n\t" - "psrlq $9, %%mm2\n\t" - "psrlq $9, %%mm5\n\t" - "pand %%mm7, %%mm2\n\t" - "pand %%mm7, %%mm5\n\t" - "por %%mm1, %%mm0\n\t" - "por %%mm4, %%mm3\n\t" - "por %%mm2, %%mm0\n\t" - "por %%mm5, %%mm3\n\t" - "psllq $16, %%mm3\n\t" - "por %%mm3, %%mm0\n\t" - MOVNTQ" %%mm0, %0\n\t" - :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); - d += 4; - s += 16; - } -#endif - __asm __volatile(SFENCE:::"memory"); - __asm __volatile(EMMS:::"memory"); -#endif - while(s < end) - { - register int rgb = *(uint32_t*)s; s += 4; - *d++ = ((rgb&0xFF)>>3) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>9); - } + asm volatile(PREFETCH" %0"::"m"(*src):"memory"); + asm volatile( + "movq %0, %%mm7 \n\t" + "movq %1, %%mm6 \n\t" + ::"m"(red_15mask),"m"(green_15mask)); + while (s < mm_end) + { + asm volatile( + PREFETCH" 32%1 \n\t" + "movd %1, %%mm0 \n\t" + "movd 4%1, %%mm3 \n\t" + "punpckldq 8%1, %%mm0 \n\t" + "punpckldq 12%1, %%mm3 \n\t" + "movq %%mm0, %%mm1 \n\t" + "movq %%mm0, %%mm2 \n\t" + "movq %%mm3, %%mm4 \n\t" + "movq %%mm3, %%mm5 \n\t" + "psrlq $3, %%mm0 \n\t" + "psrlq $3, %%mm3 \n\t" + "pand %2, %%mm0 \n\t" + "pand %2, %%mm3 \n\t" + "psrlq $6, %%mm1 \n\t" + "psrlq $6, %%mm4 \n\t" + "pand %%mm6, %%mm1 \n\t" + "pand %%mm6, %%mm4 \n\t" + "psrlq $9, %%mm2 \n\t" + "psrlq $9, %%mm5 \n\t" + "pand %%mm7, %%mm2 \n\t" + "pand %%mm7, %%mm5 \n\t" + "por %%mm1, %%mm0 \n\t" + "por %%mm4, %%mm3 \n\t" + "por %%mm2, %%mm0 \n\t" + "por %%mm5, %%mm3 \n\t" + "psllq $16, %%mm3 \n\t" + "por %%mm3, %%mm0 \n\t" + MOVNTQ" %%mm0, %0 \n\t" + :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); + d += 4; + s += 16; + } +#endif + asm volatile(SFENCE:::"memory"); + asm volatile(EMMS:::"memory"); +#endif + while (s < end) + { + register int rgb = *(uint32_t*)s; s += 4; + *d++ = ((rgb&0xFF)>>3) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>9); + } } static inline void RENAME(rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size) { - const uint8_t *s = src; - const uint8_t *end; + const uint8_t *s = src; + const uint8_t *end; #ifdef HAVE_MMX - const uint8_t *mm_end; + const uint8_t *mm_end; #endif - uint16_t *d = (uint16_t *)dst; - end = s + src_size; + uint16_t *d = (uint16_t *)dst; + end = s + src_size; #ifdef HAVE_MMX - __asm __volatile(PREFETCH" %0"::"m"(*src):"memory"); - __asm __volatile( - "movq %0, %%mm7\n\t" - "movq %1, %%mm6\n\t" - ::"m"(red_15mask),"m"(green_15mask)); - mm_end = end - 15; - while(s < mm_end) - { - __asm __volatile( - PREFETCH" 32%1\n\t" - "movd %1, %%mm0\n\t" - "movd 4%1, %%mm3\n\t" - "punpckldq 8%1, %%mm0\n\t" - "punpckldq 12%1, %%mm3\n\t" - "movq %%mm0, %%mm1\n\t" - "movq %%mm0, %%mm2\n\t" - "movq %%mm3, %%mm4\n\t" - "movq %%mm3, %%mm5\n\t" - "psllq $7, %%mm0\n\t" - "psllq $7, %%mm3\n\t" - "pand %%mm7, %%mm0\n\t" - "pand %%mm7, %%mm3\n\t" - "psrlq $6, %%mm1\n\t" - "psrlq $6, %%mm4\n\t" - "pand %%mm6, %%mm1\n\t" - "pand %%mm6, %%mm4\n\t" - "psrlq $19, %%mm2\n\t" - "psrlq $19, %%mm5\n\t" - "pand %2, %%mm2\n\t" - "pand %2, %%mm5\n\t" - "por %%mm1, %%mm0\n\t" - "por %%mm4, %%mm3\n\t" - "por %%mm2, %%mm0\n\t" - "por %%mm5, %%mm3\n\t" - "psllq $16, %%mm3\n\t" - "por %%mm3, %%mm0\n\t" - MOVNTQ" %%mm0, %0\n\t" - :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); - d += 4; - s += 16; - } - __asm __volatile(SFENCE:::"memory"); - __asm __volatile(EMMS:::"memory"); -#endif - while(s < end) - { - register int rgb = *(uint32_t*)s; s += 4; - *d++ = ((rgb&0xF8)<<7) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>19); - } + asm volatile(PREFETCH" %0"::"m"(*src):"memory"); + asm volatile( + "movq %0, %%mm7 \n\t" + "movq %1, %%mm6 \n\t" + ::"m"(red_15mask),"m"(green_15mask)); + mm_end = end - 15; + while (s < mm_end) + { + asm volatile( + PREFETCH" 32%1 \n\t" + "movd %1, %%mm0 \n\t" + "movd 4%1, %%mm3 \n\t" + "punpckldq 8%1, %%mm0 \n\t" + "punpckldq 12%1, %%mm3 \n\t" + "movq %%mm0, %%mm1 \n\t" + "movq %%mm0, %%mm2 \n\t" + "movq %%mm3, %%mm4 \n\t" + "movq %%mm3, %%mm5 \n\t" + "psllq $7, %%mm0 \n\t" + "psllq $7, %%mm3 \n\t" + "pand %%mm7, %%mm0 \n\t" + "pand %%mm7, %%mm3 \n\t" + "psrlq $6, %%mm1 \n\t" + "psrlq $6, %%mm4 \n\t" + "pand %%mm6, %%mm1 \n\t" + "pand %%mm6, %%mm4 \n\t" + "psrlq $19, %%mm2 \n\t" + "psrlq $19, %%mm5 \n\t" + "pand %2, %%mm2 \n\t" + "pand %2, %%mm5 \n\t" + "por %%mm1, %%mm0 \n\t" + "por %%mm4, %%mm3 \n\t" + "por %%mm2, %%mm0 \n\t" + "por %%mm5, %%mm3 \n\t" + "psllq $16, %%mm3 \n\t" + "por %%mm3, %%mm0 \n\t" + MOVNTQ" %%mm0, %0 \n\t" + :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); + d += 4; + s += 16; + } + asm volatile(SFENCE:::"memory"); + asm volatile(EMMS:::"memory"); +#endif + while (s < end) + { + register int rgb = *(uint32_t*)s; s += 4; + *d++ = ((rgb&0xF8)<<7) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>19); + } } static inline void RENAME(rgb24to16)(const uint8_t *src, uint8_t *dst, long src_size) { - const uint8_t *s = src; - const uint8_t *end; + const uint8_t *s = src; + const uint8_t *end; #ifdef HAVE_MMX - const uint8_t *mm_end; + const uint8_t *mm_end; #endif - uint16_t *d = (uint16_t *)dst; - end = s + src_size; + uint16_t *d = (uint16_t *)dst; + end = s + src_size; #ifdef HAVE_MMX - __asm __volatile(PREFETCH" %0"::"m"(*src):"memory"); - __asm __volatile( - "movq %0, %%mm7\n\t" - "movq %1, %%mm6\n\t" - ::"m"(red_16mask),"m"(green_16mask)); - mm_end = end - 11; - while(s < mm_end) - { - __asm __volatile( - PREFETCH" 32%1\n\t" - "movd %1, %%mm0\n\t" - "movd 3%1, %%mm3\n\t" - "punpckldq 6%1, %%mm0\n\t" - "punpckldq 9%1, %%mm3\n\t" - "movq %%mm0, %%mm1\n\t" - "movq %%mm0, %%mm2\n\t" - "movq %%mm3, %%mm4\n\t" - "movq %%mm3, %%mm5\n\t" - "psrlq $3, %%mm0\n\t" - "psrlq $3, %%mm3\n\t" - "pand %2, %%mm0\n\t" - "pand %2, %%mm3\n\t" - "psrlq $5, %%mm1\n\t" - "psrlq $5, %%mm4\n\t" - "pand %%mm6, %%mm1\n\t" - "pand %%mm6, %%mm4\n\t" - "psrlq $8, %%mm2\n\t" - "psrlq $8, %%mm5\n\t" - "pand %%mm7, %%mm2\n\t" - "pand %%mm7, %%mm5\n\t" - "por %%mm1, %%mm0\n\t" - "por %%mm4, %%mm3\n\t" - "por %%mm2, %%mm0\n\t" - "por %%mm5, %%mm3\n\t" - "psllq $16, %%mm3\n\t" - "por %%mm3, %%mm0\n\t" - MOVNTQ" %%mm0, %0\n\t" - :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory"); - d += 4; - s += 12; - } - __asm __volatile(SFENCE:::"memory"); - __asm __volatile(EMMS:::"memory"); -#endif - while(s < end) - { - const int b= *s++; - const int g= *s++; - const int r= *s++; - *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8); - } + asm volatile(PREFETCH" %0"::"m"(*src):"memory"); + asm volatile( + "movq %0, %%mm7 \n\t" + "movq %1, %%mm6 \n\t" + ::"m"(red_16mask),"m"(green_16mask)); + mm_end = end - 11; + while (s < mm_end) + { + asm volatile( + PREFETCH" 32%1 \n\t" + "movd %1, %%mm0 \n\t" + "movd 3%1, %%mm3 \n\t" + "punpckldq 6%1, %%mm0 \n\t" + "punpckldq 9%1, %%mm3 \n\t" + "movq %%mm0, %%mm1 \n\t" + "movq %%mm0, %%mm2 \n\t" + "movq %%mm3, %%mm4 \n\t" + "movq %%mm3, %%mm5 \n\t" + "psrlq $3, %%mm0 \n\t" + "psrlq $3, %%mm3 \n\t" + "pand %2, %%mm0 \n\t" + "pand %2, %%mm3 \n\t" + "psrlq $5, %%mm1 \n\t" + "psrlq $5, %%mm4 \n\t" + "pand %%mm6, %%mm1 \n\t" + "pand %%mm6, %%mm4 \n\t" + "psrlq $8, %%mm2 \n\t" + "psrlq $8, %%mm5 \n\t" + "pand %%mm7, %%mm2 \n\t" + "pand %%mm7, %%mm5 \n\t" + "por %%mm1, %%mm0 \n\t" + "por %%mm4, %%mm3 \n\t" + "por %%mm2, %%mm0 \n\t" + "por %%mm5, %%mm3 \n\t" + "psllq $16, %%mm3 \n\t" + "por %%mm3, %%mm0 \n\t" + MOVNTQ" %%mm0, %0 \n\t" + :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory"); + d += 4; + s += 12; + } + asm volatile(SFENCE:::"memory"); + asm volatile(EMMS:::"memory"); +#endif + while (s < end) + { + const int b = *s++; + const int g = *s++; + const int r = *s++; + *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8); + } } static inline void RENAME(rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size) { - const uint8_t *s = src; - const uint8_t *end; + const uint8_t *s = src; + const uint8_t *end; #ifdef HAVE_MMX - const uint8_t *mm_end; + const uint8_t *mm_end; #endif - uint16_t *d = (uint16_t *)dst; - end = s + src_size; + uint16_t *d = (uint16_t *)dst; + end = s + src_size; #ifdef HAVE_MMX - __asm __volatile(PREFETCH" %0"::"m"(*src):"memory"); - __asm __volatile( - "movq %0, %%mm7\n\t" - "movq %1, %%mm6\n\t" - ::"m"(red_16mask),"m"(green_16mask)); - mm_end = end - 15; - while(s < mm_end) - { - __asm __volatile( - PREFETCH" 32%1\n\t" - "movd %1, %%mm0\n\t" - "movd 3%1, %%mm3\n\t" - "punpckldq 6%1, %%mm0\n\t" - "punpckldq 9%1, %%mm3\n\t" - "movq %%mm0, %%mm1\n\t" - "movq %%mm0, %%mm2\n\t" - "movq %%mm3, %%mm4\n\t" - "movq %%mm3, %%mm5\n\t" - "psllq $8, %%mm0\n\t" - "psllq $8, %%mm3\n\t" - "pand %%mm7, %%mm0\n\t" - "pand %%mm7, %%mm3\n\t" - "psrlq $5, %%mm1\n\t" - "psrlq $5, %%mm4\n\t" - "pand %%mm6, %%mm1\n\t" - "pand %%mm6, %%mm4\n\t" - "psrlq $19, %%mm2\n\t" - "psrlq $19, %%mm5\n\t" - "pand %2, %%mm2\n\t" - "pand %2, %%mm5\n\t" - "por %%mm1, %%mm0\n\t" - "por %%mm4, %%mm3\n\t" - "por %%mm2, %%mm0\n\t" - "por %%mm5, %%mm3\n\t" - "psllq $16, %%mm3\n\t" - "por %%mm3, %%mm0\n\t" - MOVNTQ" %%mm0, %0\n\t" - :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory"); - d += 4; - s += 12; - } - __asm __volatile(SFENCE:::"memory"); - __asm __volatile(EMMS:::"memory"); -#endif - while(s < end) - { - const int r= *s++; - const int g= *s++; - const int b= *s++; - *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8); - } + asm volatile(PREFETCH" %0"::"m"(*src):"memory"); + asm volatile( + "movq %0, %%mm7 \n\t" + "movq %1, %%mm6 \n\t" + ::"m"(red_16mask),"m"(green_16mask)); + mm_end = end - 15; + while (s < mm_end) + { + asm volatile( + PREFETCH" 32%1 \n\t" + "movd %1, %%mm0 \n\t" + "movd 3%1, %%mm3 \n\t" + "punpckldq 6%1, %%mm0 \n\t" + "punpckldq 9%1, %%mm3 \n\t" + "movq %%mm0, %%mm1 \n\t" + "movq %%mm0, %%mm2 \n\t" + "movq %%mm3, %%mm4 \n\t" + "movq %%mm3, %%mm5 \n\t" + "psllq $8, %%mm0 \n\t" + "psllq $8, %%mm3 \n\t" + "pand %%mm7, %%mm0 \n\t" + "pand %%mm7, %%mm3 \n\t" + "psrlq $5, %%mm1 \n\t" + "psrlq $5, %%mm4 \n\t" + "pand %%mm6, %%mm1 \n\t" + "pand %%mm6, %%mm4 \n\t" + "psrlq $19, %%mm2 \n\t" + "psrlq $19, %%mm5 \n\t" + "pand %2, %%mm2 \n\t" + "pand %2, %%mm5 \n\t" + "por %%mm1, %%mm0 \n\t" + "por %%mm4, %%mm3 \n\t" + "por %%mm2, %%mm0 \n\t" + "por %%mm5, %%mm3 \n\t" + "psllq $16, %%mm3 \n\t" + "por %%mm3, %%mm0 \n\t" + MOVNTQ" %%mm0, %0 \n\t" + :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory"); + d += 4; + s += 12; + } + asm volatile(SFENCE:::"memory"); + asm volatile(EMMS:::"memory"); +#endif + while (s < end) + { + const int r = *s++; + const int g = *s++; + const int b = *s++; + *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8); + } } static inline void RENAME(rgb24to15)(const uint8_t *src, uint8_t *dst, long src_size) { - const uint8_t *s = src; - const uint8_t *end; + const uint8_t *s = src; + const uint8_t *end; #ifdef HAVE_MMX - const uint8_t *mm_end; + const uint8_t *mm_end; #endif - uint16_t *d = (uint16_t *)dst; - end = s + src_size; + uint16_t *d = (uint16_t *)dst; + end = s + src_size; #ifdef HAVE_MMX - __asm __volatile(PREFETCH" %0"::"m"(*src):"memory"); - __asm __volatile( - "movq %0, %%mm7\n\t" - "movq %1, %%mm6\n\t" - ::"m"(red_15mask),"m"(green_15mask)); - mm_end = end - 11; - while(s < mm_end) - { - __asm __volatile( - PREFETCH" 32%1\n\t" - "movd %1, %%mm0\n\t" - "movd 3%1, %%mm3\n\t" - "punpckldq 6%1, %%mm0\n\t" - "punpckldq 9%1, %%mm3\n\t" - "movq %%mm0, %%mm1\n\t" - "movq %%mm0, %%mm2\n\t" - "movq %%mm3, %%mm4\n\t" - "movq %%mm3, %%mm5\n\t" - "psrlq $3, %%mm0\n\t" - "psrlq $3, %%mm3\n\t" - "pand %2, %%mm0\n\t" - "pand %2, %%mm3\n\t" - "psrlq $6, %%mm1\n\t" - "psrlq $6, %%mm4\n\t" - "pand %%mm6, %%mm1\n\t" - "pand %%mm6, %%mm4\n\t" - "psrlq $9, %%mm2\n\t" - "psrlq $9, %%mm5\n\t" - "pand %%mm7, %%mm2\n\t" - "pand %%mm7, %%mm5\n\t" - "por %%mm1, %%mm0\n\t" - "por %%mm4, %%mm3\n\t" - "por %%mm2, %%mm0\n\t" - "por %%mm5, %%mm3\n\t" - "psllq $16, %%mm3\n\t" - "por %%mm3, %%mm0\n\t" - MOVNTQ" %%mm0, %0\n\t" - :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); - d += 4; - s += 12; - } - __asm __volatile(SFENCE:::"memory"); - __asm __volatile(EMMS:::"memory"); -#endif - while(s < end) - { - const int b= *s++; - const int g= *s++; - const int r= *s++; - *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7); - } + asm volatile(PREFETCH" %0"::"m"(*src):"memory"); + asm volatile( + "movq %0, %%mm7 \n\t" + "movq %1, %%mm6 \n\t" + ::"m"(red_15mask),"m"(green_15mask)); + mm_end = end - 11; + while (s < mm_end) + { + asm volatile( + PREFETCH" 32%1 \n\t" + "movd %1, %%mm0 \n\t" + "movd 3%1, %%mm3 \n\t" + "punpckldq 6%1, %%mm0 \n\t" + "punpckldq 9%1, %%mm3 \n\t" + "movq %%mm0, %%mm1 \n\t" + "movq %%mm0, %%mm2 \n\t" + "movq %%mm3, %%mm4 \n\t" + "movq %%mm3, %%mm5 \n\t" + "psrlq $3, %%mm0 \n\t" + "psrlq $3, %%mm3 \n\t" + "pand %2, %%mm0 \n\t" + "pand %2, %%mm3 \n\t" + "psrlq $6, %%mm1 \n\t" + "psrlq $6, %%mm4 \n\t" + "pand %%mm6, %%mm1 \n\t" + "pand %%mm6, %%mm4 \n\t" + "psrlq $9, %%mm2 \n\t" + "psrlq $9, %%mm5 \n\t" + "pand %%mm7, %%mm2 \n\t" + "pand %%mm7, %%mm5 \n\t" + "por %%mm1, %%mm0 \n\t" + "por %%mm4, %%mm3 \n\t" + "por %%mm2, %%mm0 \n\t" + "por %%mm5, %%mm3 \n\t" + "psllq $16, %%mm3 \n\t" + "por %%mm3, %%mm0 \n\t" + MOVNTQ" %%mm0, %0 \n\t" + :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); + d += 4; + s += 12; + } + asm volatile(SFENCE:::"memory"); + asm volatile(EMMS:::"memory"); +#endif + while (s < end) + { + const int b = *s++; + const int g = *s++; + const int r = *s++; + *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7); + } } static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size) { - const uint8_t *s = src; - const uint8_t *end; + const uint8_t *s = src; + const uint8_t *end; #ifdef HAVE_MMX - const uint8_t *mm_end; + const uint8_t *mm_end; #endif - uint16_t *d = (uint16_t *)dst; - end = s + src_size; + uint16_t *d = (uint16_t *)dst; + end = s + src_size; #ifdef HAVE_MMX - __asm __volatile(PREFETCH" %0"::"m"(*src):"memory"); - __asm __volatile( - "movq %0, %%mm7\n\t" - "movq %1, %%mm6\n\t" - ::"m"(red_15mask),"m"(green_15mask)); - mm_end = end - 15; - while(s < mm_end) - { - __asm __volatile( - PREFETCH" 32%1\n\t" - "movd %1, %%mm0\n\t" - "movd 3%1, %%mm3\n\t" - "punpckldq 6%1, %%mm0\n\t" - "punpckldq 9%1, %%mm3\n\t" - "movq %%mm0, %%mm1\n\t" - "movq %%mm0, %%mm2\n\t" - "movq %%mm3, %%mm4\n\t" - "movq %%mm3, %%mm5\n\t" - "psllq $7, %%mm0\n\t" - "psllq $7, %%mm3\n\t" - "pand %%mm7, %%mm0\n\t" - "pand %%mm7, %%mm3\n\t" - "psrlq $6, %%mm1\n\t" - "psrlq $6, %%mm4\n\t" - "pand %%mm6, %%mm1\n\t" - "pand %%mm6, %%mm4\n\t" - "psrlq $19, %%mm2\n\t" - "psrlq $19, %%mm5\n\t" - "pand %2, %%mm2\n\t" - "pand %2, %%mm5\n\t" - "por %%mm1, %%mm0\n\t" - "por %%mm4, %%mm3\n\t" - "por %%mm2, %%mm0\n\t" - "por %%mm5, %%mm3\n\t" - "psllq $16, %%mm3\n\t" - "por %%mm3, %%mm0\n\t" - MOVNTQ" %%mm0, %0\n\t" - :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); - d += 4; - s += 12; - } - __asm __volatile(SFENCE:::"memory"); - __asm __volatile(EMMS:::"memory"); -#endif - while(s < end) - { - const int r= *s++; - const int g= *s++; - const int b= *s++; - *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7); - } + asm volatile(PREFETCH" %0"::"m"(*src):"memory"); + asm volatile( + "movq %0, %%mm7 \n\t" + "movq %1, %%mm6 \n\t" + ::"m"(red_15mask),"m"(green_15mask)); + mm_end = end - 15; + while (s < mm_end) + { + asm volatile( + PREFETCH" 32%1 \n\t" + "movd %1, %%mm0 \n\t" + "movd 3%1, %%mm3 \n\t" + "punpckldq 6%1, %%mm0 \n\t" + "punpckldq 9%1, %%mm3 \n\t" + "movq %%mm0, %%mm1 \n\t" + "movq %%mm0, %%mm2 \n\t" + "movq %%mm3, %%mm4 \n\t" + "movq %%mm3, %%mm5 \n\t" + "psllq $7, %%mm0 \n\t" + "psllq $7, %%mm3 \n\t" + "pand %%mm7, %%mm0 \n\t" + "pand %%mm7, %%mm3 \n\t" + "psrlq $6, %%mm1 \n\t" + "psrlq $6, %%mm4 \n\t" + "pand %%mm6, %%mm1 \n\t" + "pand %%mm6, %%mm4 \n\t" + "psrlq $19, %%mm2 \n\t" + "psrlq $19, %%mm5 \n\t" + "pand %2, %%mm2 \n\t" + "pand %2, %%mm5 \n\t" + "por %%mm1, %%mm0 \n\t" + "por %%mm4, %%mm3 \n\t" + "por %%mm2, %%mm0 \n\t" + "por %%mm5, %%mm3 \n\t" + "psllq $16, %%mm3 \n\t" + "por %%mm3, %%mm0 \n\t" + MOVNTQ" %%mm0, %0 \n\t" + :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); + d += 4; + s += 12; + } + asm volatile(SFENCE:::"memory"); + asm volatile(EMMS:::"memory"); +#endif + while (s < end) + { + const int r = *s++; + const int g = *s++; + const int b = *s++; + *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7); + } } /* - I use here less accurate approximation by simply - left-shifting the input - value and filling the low order bits with - zeroes. This method improves png's - compression but this scheme cannot reproduce white exactly, since it does not - generate an all-ones maximum value; the net effect is to darken the + I use less accurate approximation here by simply left-shifting the input + value and filling the low order bits with zeroes. This method improves PNG + compression but this scheme cannot reproduce white exactly, since it does + not generate an all-ones maximum value; the net effect is to darken the image slightly. The better method should be "left bit replication": @@ -931,1758 +932,1806 @@ static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long s */ static inline void RENAME(rgb15to24)(const uint8_t *src, uint8_t *dst, long src_size) { - const uint16_t *end; + const uint16_t *end; #ifdef HAVE_MMX - const uint16_t *mm_end; + const uint16_t *mm_end; #endif - uint8_t *d = (uint8_t *)dst; - const uint16_t *s = (uint16_t *)src; - end = s + src_size/2; + uint8_t *d = (uint8_t *)dst; + const uint16_t *s = (uint16_t *)src; + end = s + src_size/2; #ifdef HAVE_MMX - __asm __volatile(PREFETCH" %0"::"m"(*s):"memory"); - mm_end = end - 7; - while(s < mm_end) - { - __asm __volatile( - PREFETCH" 32%1\n\t" - "movq %1, %%mm0\n\t" - "movq %1, %%mm1\n\t" - "movq %1, %%mm2\n\t" - "pand %2, %%mm0\n\t" - "pand %3, %%mm1\n\t" - "pand %4, %%mm2\n\t" - "psllq $3, %%mm0\n\t" - "psrlq $2, %%mm1\n\t" - "psrlq $7, %%mm2\n\t" - "movq %%mm0, %%mm3\n\t" - "movq %%mm1, %%mm4\n\t" - "movq %%mm2, %%mm5\n\t" - "punpcklwd %5, %%mm0\n\t" - "punpcklwd %5, %%mm1\n\t" - "punpcklwd %5, %%mm2\n\t" - "punpckhwd %5, %%mm3\n\t" - "punpckhwd %5, %%mm4\n\t" - "punpckhwd %5, %%mm5\n\t" - "psllq $8, %%mm1\n\t" - "psllq $16, %%mm2\n\t" - "por %%mm1, %%mm0\n\t" - "por %%mm2, %%mm0\n\t" - "psllq $8, %%mm4\n\t" - "psllq $16, %%mm5\n\t" - "por %%mm4, %%mm3\n\t" - "por %%mm5, %%mm3\n\t" - - "movq %%mm0, %%mm6\n\t" - "movq %%mm3, %%mm7\n\t" - - "movq 8%1, %%mm0\n\t" - "movq 8%1, %%mm1\n\t" - "movq 8%1, %%mm2\n\t" - "pand %2, %%mm0\n\t" - "pand %3, %%mm1\n\t" - "pand %4, %%mm2\n\t" - "psllq $3, %%mm0\n\t" - "psrlq $2, %%mm1\n\t" - "psrlq $7, %%mm2\n\t" - "movq %%mm0, %%mm3\n\t" - "movq %%mm1, %%mm4\n\t" - "movq %%mm2, %%mm5\n\t" - "punpcklwd %5, %%mm0\n\t" - "punpcklwd %5, %%mm1\n\t" - "punpcklwd %5, %%mm2\n\t" - "punpckhwd %5, %%mm3\n\t" - "punpckhwd %5, %%mm4\n\t" - "punpckhwd %5, %%mm5\n\t" - "psllq $8, %%mm1\n\t" - "psllq $16, %%mm2\n\t" - "por %%mm1, %%mm0\n\t" - "por %%mm2, %%mm0\n\t" - "psllq $8, %%mm4\n\t" - "psllq $16, %%mm5\n\t" - "por %%mm4, %%mm3\n\t" - "por %%mm5, %%mm3\n\t" - - :"=m"(*d) - :"m"(*s),"m"(mask15b),"m"(mask15g),"m"(mask15r), "m"(mmx_null) - :"memory"); - /* Borrowed 32 to 24 */ - __asm __volatile( - "movq %%mm0, %%mm4\n\t" - "movq %%mm3, %%mm5\n\t" - "movq %%mm6, %%mm0\n\t" - "movq %%mm7, %%mm1\n\t" - - "movq %%mm4, %%mm6\n\t" - "movq %%mm5, %%mm7\n\t" - "movq %%mm0, %%mm2\n\t" - "movq %%mm1, %%mm3\n\t" - - "psrlq $8, %%mm2\n\t" - "psrlq $8, %%mm3\n\t" - "psrlq $8, %%mm6\n\t" - "psrlq $8, %%mm7\n\t" - "pand %2, %%mm0\n\t" - "pand %2, %%mm1\n\t" - "pand %2, %%mm4\n\t" - "pand %2, %%mm5\n\t" - "pand %3, %%mm2\n\t" - "pand %3, %%mm3\n\t" - "pand %3, %%mm6\n\t" - "pand %3, %%mm7\n\t" - "por %%mm2, %%mm0\n\t" - "por %%mm3, %%mm1\n\t" - "por %%mm6, %%mm4\n\t" - "por %%mm7, %%mm5\n\t" - - "movq %%mm1, %%mm2\n\t" - "movq %%mm4, %%mm3\n\t" - "psllq $48, %%mm2\n\t" - "psllq $32, %%mm3\n\t" - "pand %4, %%mm2\n\t" - "pand %5, %%mm3\n\t" - "por %%mm2, %%mm0\n\t" - "psrlq $16, %%mm1\n\t" - "psrlq $32, %%mm4\n\t" - "psllq $16, %%mm5\n\t" - "por %%mm3, %%mm1\n\t" - "pand %6, %%mm5\n\t" - "por %%mm5, %%mm4\n\t" - - MOVNTQ" %%mm0, %0\n\t" - MOVNTQ" %%mm1, 8%0\n\t" - MOVNTQ" %%mm4, 16%0" - - :"=m"(*d) - :"m"(*s),"m"(mask24l),"m"(mask24h),"m"(mask24hh),"m"(mask24hhh),"m"(mask24hhhh) - :"memory"); - d += 24; - s += 8; - } - __asm __volatile(SFENCE:::"memory"); - __asm __volatile(EMMS:::"memory"); -#endif - while(s < end) - { - register uint16_t bgr; - bgr = *s++; - *d++ = (bgr&0x1F)<<3; - *d++ = (bgr&0x3E0)>>2; - *d++ = (bgr&0x7C00)>>7; - } + asm volatile(PREFETCH" %0"::"m"(*s):"memory"); + mm_end = end - 7; + while (s < mm_end) + { + asm volatile( + PREFETCH" 32%1 \n\t" + "movq %1, %%mm0 \n\t" + "movq %1, %%mm1 \n\t" + "movq %1, %%mm2 \n\t" + "pand %2, %%mm0 \n\t" + "pand %3, %%mm1 \n\t" + "pand %4, %%mm2 \n\t" + "psllq $3, %%mm0 \n\t" + "psrlq $2, %%mm1 \n\t" + "psrlq $7, %%mm2 \n\t" + "movq %%mm0, %%mm3 \n\t" + "movq %%mm1, %%mm4 \n\t" + "movq %%mm2, %%mm5 \n\t" + "punpcklwd %5, %%mm0 \n\t" + "punpcklwd %5, %%mm1 \n\t" + "punpcklwd %5, %%mm2 \n\t" + "punpckhwd %5, %%mm3 \n\t" + "punpckhwd %5, %%mm4 \n\t" + "punpckhwd %5, %%mm5 \n\t" + "psllq $8, %%mm1 \n\t" + "psllq $16, %%mm2 \n\t" + "por %%mm1, %%mm0 \n\t" + "por %%mm2, %%mm0 \n\t" + "psllq $8, %%mm4 \n\t" + "psllq $16, %%mm5 \n\t" + "por %%mm4, %%mm3 \n\t" + "por %%mm5, %%mm3 \n\t" + + "movq %%mm0, %%mm6 \n\t" + "movq %%mm3, %%mm7 \n\t" + + "movq 8%1, %%mm0 \n\t" + "movq 8%1, %%mm1 \n\t" + "movq 8%1, %%mm2 \n\t" + "pand %2, %%mm0 \n\t" + "pand %3, %%mm1 \n\t" + "pand %4, %%mm2 \n\t" + "psllq $3, %%mm0 \n\t" + "psrlq $2, %%mm1 \n\t" + "psrlq $7, %%mm2 \n\t" + "movq %%mm0, %%mm3 \n\t" + "movq %%mm1, %%mm4 \n\t" + "movq %%mm2, %%mm5 \n\t" + "punpcklwd %5, %%mm0 \n\t" + "punpcklwd %5, %%mm1 \n\t" + "punpcklwd %5, %%mm2 \n\t" + "punpckhwd %5, %%mm3 \n\t" + "punpckhwd %5, %%mm4 \n\t" + "punpckhwd %5, %%mm5 \n\t" + "psllq $8, %%mm1 \n\t" + "psllq $16, %%mm2 \n\t" + "por %%mm1, %%mm0 \n\t" + "por %%mm2, %%mm0 \n\t" + "psllq $8, %%mm4 \n\t" + "psllq $16, %%mm5 \n\t" + "por %%mm4, %%mm3 \n\t" + "por %%mm5, %%mm3 \n\t" + + :"=m"(*d) + :"m"(*s),"m"(mask15b),"m"(mask15g),"m"(mask15r), "m"(mmx_null) + :"memory"); + /* Borrowed 32 to 24 */ + asm volatile( + "movq %%mm0, %%mm4 \n\t" + "movq %%mm3, %%mm5 \n\t" + "movq %%mm6, %%mm0 \n\t" + "movq %%mm7, %%mm1 \n\t" + + "movq %%mm4, %%mm6 \n\t" + "movq %%mm5, %%mm7 \n\t" + "movq %%mm0, %%mm2 \n\t" + "movq %%mm1, %%mm3 \n\t" + + "psrlq $8, %%mm2 \n\t" + "psrlq $8, %%mm3 \n\t" + "psrlq $8, %%mm6 \n\t" + "psrlq $8, %%mm7 \n\t" + "pand %2, %%mm0 \n\t" + "pand %2, %%mm1 \n\t" + "pand %2, %%mm4 \n\t" + "pand %2, %%mm5 \n\t" + "pand %3, %%mm2 \n\t" + "pand %3, %%mm3 \n\t" + "pand %3, %%mm6 \n\t" + "pand %3, %%mm7 \n\t" + "por %%mm2, %%mm0 \n\t" + "por %%mm3, %%mm1 \n\t" + "por %%mm6, %%mm4 \n\t" + "por %%mm7, %%mm5 \n\t" + + "movq %%mm1, %%mm2 \n\t" + "movq %%mm4, %%mm3 \n\t" + "psllq $48, %%mm2 \n\t" + "psllq $32, %%mm3 \n\t" + "pand %4, %%mm2 \n\t" + "pand %5, %%mm3 \n\t" + "por %%mm2, %%mm0 \n\t" + "psrlq $16, %%mm1 \n\t" + "psrlq $32, %%mm4 \n\t" + "psllq $16, %%mm5 \n\t" + "por %%mm3, %%mm1 \n\t" + "pand %6, %%mm5 \n\t" + "por %%mm5, %%mm4 \n\t" + + MOVNTQ" %%mm0, %0 \n\t" + MOVNTQ" %%mm1, 8%0 \n\t" + MOVNTQ" %%mm4, 16%0" + + :"=m"(*d) + :"m"(*s),"m"(mask24l),"m"(mask24h),"m"(mask24hh),"m"(mask24hhh),"m"(mask24hhhh) + :"memory"); + d += 24; + s += 8; + } + asm volatile(SFENCE:::"memory"); + asm volatile(EMMS:::"memory"); +#endif + while (s < end) + { + register uint16_t bgr; + bgr = *s++; + *d++ = (bgr&0x1F)<<3; + *d++ = (bgr&0x3E0)>>2; + *d++ = (bgr&0x7C00)>>7; + } } static inline void RENAME(rgb16to24)(const uint8_t *src, uint8_t *dst, long src_size) { - const uint16_t *end; + const uint16_t *end; #ifdef HAVE_MMX - const uint16_t *mm_end; + const uint16_t *mm_end; #endif - uint8_t *d = (uint8_t *)dst; - const uint16_t *s = (const uint16_t *)src; - end = s + src_size/2; + uint8_t *d = (uint8_t *)dst; + const uint16_t *s = (const uint16_t *)src; + end = s + src_size/2; #ifdef HAVE_MMX - __asm __volatile(PREFETCH" %0"::"m"(*s):"memory"); - mm_end = end - 7; - while(s < mm_end) - { - __asm __volatile( - PREFETCH" 32%1\n\t" - "movq %1, %%mm0\n\t" - "movq %1, %%mm1\n\t" - "movq %1, %%mm2\n\t" - "pand %2, %%mm0\n\t" - "pand %3, %%mm1\n\t" - "pand %4, %%mm2\n\t" - "psllq $3, %%mm0\n\t" - "psrlq $3, %%mm1\n\t" - "psrlq $8, %%mm2\n\t" - "movq %%mm0, %%mm3\n\t" - "movq %%mm1, %%mm4\n\t" - "movq %%mm2, %%mm5\n\t" - "punpcklwd %5, %%mm0\n\t" - "punpcklwd %5, %%mm1\n\t" - "punpcklwd %5, %%mm2\n\t" - "punpckhwd %5, %%mm3\n\t" - "punpckhwd %5, %%mm4\n\t" - "punpckhwd %5, %%mm5\n\t" - "psllq $8, %%mm1\n\t" - "psllq $16, %%mm2\n\t" - "por %%mm1, %%mm0\n\t" - "por %%mm2, %%mm0\n\t" - "psllq $8, %%mm4\n\t" - "psllq $16, %%mm5\n\t" - "por %%mm4, %%mm3\n\t" - "por %%mm5, %%mm3\n\t" - - "movq %%mm0, %%mm6\n\t" - "movq %%mm3, %%mm7\n\t" - - "movq 8%1, %%mm0\n\t" - "movq 8%1, %%mm1\n\t" - "movq 8%1, %%mm2\n\t" - "pand %2, %%mm0\n\t" - "pand %3, %%mm1\n\t" - "pand %4, %%mm2\n\t" - "psllq $3, %%mm0\n\t" - "psrlq $3, %%mm1\n\t" - "psrlq $8, %%mm2\n\t" - "movq %%mm0, %%mm3\n\t" - "movq %%mm1, %%mm4\n\t" - "movq %%mm2, %%mm5\n\t" - "punpcklwd %5, %%mm0\n\t" - "punpcklwd %5, %%mm1\n\t" - "punpcklwd %5, %%mm2\n\t" - "punpckhwd %5, %%mm3\n\t" - "punpckhwd %5, %%mm4\n\t" - "punpckhwd %5, %%mm5\n\t" - "psllq $8, %%mm1\n\t" - "psllq $16, %%mm2\n\t" - "por %%mm1, %%mm0\n\t" - "por %%mm2, %%mm0\n\t" - "psllq $8, %%mm4\n\t" - "psllq $16, %%mm5\n\t" - "por %%mm4, %%mm3\n\t" - "por %%mm5, %%mm3\n\t" - :"=m"(*d) - :"m"(*s),"m"(mask16b),"m"(mask16g),"m"(mask16r),"m"(mmx_null) - :"memory"); - /* Borrowed 32 to 24 */ - __asm __volatile( - "movq %%mm0, %%mm4\n\t" - "movq %%mm3, %%mm5\n\t" - "movq %%mm6, %%mm0\n\t" - "movq %%mm7, %%mm1\n\t" - - "movq %%mm4, %%mm6\n\t" - "movq %%mm5, %%mm7\n\t" - "movq %%mm0, %%mm2\n\t" - "movq %%mm1, %%mm3\n\t" - - "psrlq $8, %%mm2\n\t" - "psrlq $8, %%mm3\n\t" - "psrlq $8, %%mm6\n\t" - "psrlq $8, %%mm7\n\t" - "pand %2, %%mm0\n\t" - "pand %2, %%mm1\n\t" - "pand %2, %%mm4\n\t" - "pand %2, %%mm5\n\t" - "pand %3, %%mm2\n\t" - "pand %3, %%mm3\n\t" - "pand %3, %%mm6\n\t" - "pand %3, %%mm7\n\t" - "por %%mm2, %%mm0\n\t" - "por %%mm3, %%mm1\n\t" - "por %%mm6, %%mm4\n\t" - "por %%mm7, %%mm5\n\t" - - "movq %%mm1, %%mm2\n\t" - "movq %%mm4, %%mm3\n\t" - "psllq $48, %%mm2\n\t" - "psllq $32, %%mm3\n\t" - "pand %4, %%mm2\n\t" - "pand %5, %%mm3\n\t" - "por %%mm2, %%mm0\n\t" - "psrlq $16, %%mm1\n\t" - "psrlq $32, %%mm4\n\t" - "psllq $16, %%mm5\n\t" - "por %%mm3, %%mm1\n\t" - "pand %6, %%mm5\n\t" - "por %%mm5, %%mm4\n\t" - - MOVNTQ" %%mm0, %0\n\t" - MOVNTQ" %%mm1, 8%0\n\t" - MOVNTQ" %%mm4, 16%0" - - :"=m"(*d) - :"m"(*s),"m"(mask24l),"m"(mask24h),"m"(mask24hh),"m"(mask24hhh),"m"(mask24hhhh) - :"memory"); - d += 24; - s += 8; - } - __asm __volatile(SFENCE:::"memory"); - __asm __volatile(EMMS:::"memory"); -#endif - while(s < end) - { - register uint16_t bgr; - bgr = *s++; - *d++ = (bgr&0x1F)<<3; - *d++ = (bgr&0x7E0)>>3; - *d++ = (bgr&0xF800)>>8; - } + asm volatile(PREFETCH" %0"::"m"(*s):"memory"); + mm_end = end - 7; + while (s < mm_end) + { + asm volatile( + PREFETCH" 32%1 \n\t" + "movq %1, %%mm0 \n\t" + "movq %1, %%mm1 \n\t" + "movq %1, %%mm2 \n\t" + "pand %2, %%mm0 \n\t" + "pand %3, %%mm1 \n\t" + "pand %4, %%mm2 \n\t" + "psllq $3, %%mm0 \n\t" + "psrlq $3, %%mm1 \n\t" + "psrlq $8, %%mm2 \n\t" + "movq %%mm0, %%mm3 \n\t" + "movq %%mm1, %%mm4 \n\t" + "movq %%mm2, %%mm5 \n\t" + "punpcklwd %5, %%mm0 \n\t" + "punpcklwd %5, %%mm1 \n\t" + "punpcklwd %5, %%mm2 \n\t" + "punpckhwd %5, %%mm3 \n\t" + "punpckhwd %5, %%mm4 \n\t" + "punpckhwd %5, %%mm5 \n\t" + "psllq $8, %%mm1 \n\t" + "psllq $16, %%mm2 \n\t" + "por %%mm1, %%mm0 \n\t" + "por %%mm2, %%mm0 \n\t" + "psllq $8, %%mm4 \n\t" + "psllq $16, %%mm5 \n\t" + "por %%mm4, %%mm3 \n\t" + "por %%mm5, %%mm3 \n\t" + + "movq %%mm0, %%mm6 \n\t" + "movq %%mm3, %%mm7 \n\t" + + "movq 8%1, %%mm0 \n\t" + "movq 8%1, %%mm1 \n\t" + "movq 8%1, %%mm2 \n\t" + "pand %2, %%mm0 \n\t" + "pand %3, %%mm1 \n\t" + "pand %4, %%mm2 \n\t" + "psllq $3, %%mm0 \n\t" + "psrlq $3, %%mm1 \n\t" + "psrlq $8, %%mm2 \n\t" + "movq %%mm0, %%mm3 \n\t" + "movq %%mm1, %%mm4 \n\t" + "movq %%mm2, %%mm5 \n\t" + "punpcklwd %5, %%mm0 \n\t" + "punpcklwd %5, %%mm1 \n\t" + "punpcklwd %5, %%mm2 \n\t" + "punpckhwd %5, %%mm3 \n\t" + "punpckhwd %5, %%mm4 \n\t" + "punpckhwd %5, %%mm5 \n\t" + "psllq $8, %%mm1 \n\t" + "psllq $16, %%mm2 \n\t" + "por %%mm1, %%mm0 \n\t" + "por %%mm2, %%mm0 \n\t" + "psllq $8, %%mm4 \n\t" + "psllq $16, %%mm5 \n\t" + "por %%mm4, %%mm3 \n\t" + "por %%mm5, %%mm3 \n\t" + :"=m"(*d) + :"m"(*s),"m"(mask16b),"m"(mask16g),"m"(mask16r),"m"(mmx_null) + :"memory"); + /* Borrowed 32 to 24 */ + asm volatile( + "movq %%mm0, %%mm4 \n\t" + "movq %%mm3, %%mm5 \n\t" + "movq %%mm6, %%mm0 \n\t" + "movq %%mm7, %%mm1 \n\t" + + "movq %%mm4, %%mm6 \n\t" + "movq %%mm5, %%mm7 \n\t" + "movq %%mm0, %%mm2 \n\t" + "movq %%mm1, %%mm3 \n\t" + + "psrlq $8, %%mm2 \n\t" + "psrlq $8, %%mm3 \n\t" + "psrlq $8, %%mm6 \n\t" + "psrlq $8, %%mm7 \n\t" + "pand %2, %%mm0 \n\t" + "pand %2, %%mm1 \n\t" + "pand %2, %%mm4 \n\t" + "pand %2, %%mm5 \n\t" + "pand %3, %%mm2 \n\t" + "pand %3, %%mm3 \n\t" + "pand %3, %%mm6 \n\t" + "pand %3, %%mm7 \n\t" + "por %%mm2, %%mm0 \n\t" + "por %%mm3, %%mm1 \n\t" + "por %%mm6, %%mm4 \n\t" + "por %%mm7, %%mm5 \n\t" + + "movq %%mm1, %%mm2 \n\t" + "movq %%mm4, %%mm3 \n\t" + "psllq $48, %%mm2 \n\t" + "psllq $32, %%mm3 \n\t" + "pand %4, %%mm2 \n\t" + "pand %5, %%mm3 \n\t" + "por %%mm2, %%mm0 \n\t" + "psrlq $16, %%mm1 \n\t" + "psrlq $32, %%mm4 \n\t" + "psllq $16, %%mm5 \n\t" + "por %%mm3, %%mm1 \n\t" + "pand %6, %%mm5 \n\t" + "por %%mm5, %%mm4 \n\t" + + MOVNTQ" %%mm0, %0 \n\t" + MOVNTQ" %%mm1, 8%0 \n\t" + MOVNTQ" %%mm4, 16%0" + + :"=m"(*d) + :"m"(*s),"m"(mask24l),"m"(mask24h),"m"(mask24hh),"m"(mask24hhh),"m"(mask24hhhh) + :"memory"); + d += 24; + s += 8; + } + asm volatile(SFENCE:::"memory"); + asm volatile(EMMS:::"memory"); +#endif + while (s < end) + { + register uint16_t bgr; + bgr = *s++; + *d++ = (bgr&0x1F)<<3; + *d++ = (bgr&0x7E0)>>3; + *d++ = (bgr&0xF800)>>8; + } } static inline void RENAME(rgb15to32)(const uint8_t *src, uint8_t *dst, long src_size) { - const uint16_t *end; + const uint16_t *end; #ifdef HAVE_MMX - const uint16_t *mm_end; + const uint16_t *mm_end; #endif - uint8_t *d = (uint8_t *)dst; - const uint16_t *s = (const uint16_t *)src; - end = s + src_size/2; + uint8_t *d = (uint8_t *)dst; + const uint16_t *s = (const uint16_t *)src; + end = s + src_size/2; #ifdef HAVE_MMX - __asm __volatile(PREFETCH" %0"::"m"(*s):"memory"); - __asm __volatile("pxor %%mm7,%%mm7\n\t":::"memory"); - mm_end = end - 3; - while(s < mm_end) - { - __asm __volatile( - PREFETCH" 32%1\n\t" - "movq %1, %%mm0\n\t" - "movq %1, %%mm1\n\t" - "movq %1, %%mm2\n\t" - "pand %2, %%mm0\n\t" - "pand %3, %%mm1\n\t" - "pand %4, %%mm2\n\t" - "psllq $3, %%mm0\n\t" - "psrlq $2, %%mm1\n\t" - "psrlq $7, %%mm2\n\t" - "movq %%mm0, %%mm3\n\t" - "movq %%mm1, %%mm4\n\t" - "movq %%mm2, %%mm5\n\t" - "punpcklwd %%mm7, %%mm0\n\t" - "punpcklwd %%mm7, %%mm1\n\t" - "punpcklwd %%mm7, %%mm2\n\t" - "punpckhwd %%mm7, %%mm3\n\t" - "punpckhwd %%mm7, %%mm4\n\t" - "punpckhwd %%mm7, %%mm5\n\t" - "psllq $8, %%mm1\n\t" - "psllq $16, %%mm2\n\t" - "por %%mm1, %%mm0\n\t" - "por %%mm2, %%mm0\n\t" - "psllq $8, %%mm4\n\t" - "psllq $16, %%mm5\n\t" - "por %%mm4, %%mm3\n\t" - "por %%mm5, %%mm3\n\t" - MOVNTQ" %%mm0, %0\n\t" - MOVNTQ" %%mm3, 8%0\n\t" - :"=m"(*d) - :"m"(*s),"m"(mask15b),"m"(mask15g),"m"(mask15r) - :"memory"); - d += 16; - s += 4; - } - __asm __volatile(SFENCE:::"memory"); - __asm __volatile(EMMS:::"memory"); -#endif - while(s < end) - { -#if 0 //slightly slower on athlon - int bgr= *s++; - *((uint32_t*)d)++ = ((bgr&0x1F)<<3) + ((bgr&0x3E0)<<6) + ((bgr&0x7C00)<<9); + asm volatile(PREFETCH" %0"::"m"(*s):"memory"); + asm volatile("pxor %%mm7,%%mm7 \n\t":::"memory"); + mm_end = end - 3; + while (s < mm_end) + { + asm volatile( + PREFETCH" 32%1 \n\t" + "movq %1, %%mm0 \n\t" + "movq %1, %%mm1 \n\t" + "movq %1, %%mm2 \n\t" + "pand %2, %%mm0 \n\t" + "pand %3, %%mm1 \n\t" + "pand %4, %%mm2 \n\t" + "psllq $3, %%mm0 \n\t" + "psrlq $2, %%mm1 \n\t" + "psrlq $7, %%mm2 \n\t" + "movq %%mm0, %%mm3 \n\t" + "movq %%mm1, %%mm4 \n\t" + "movq %%mm2, %%mm5 \n\t" + "punpcklwd %%mm7, %%mm0 \n\t" + "punpcklwd %%mm7, %%mm1 \n\t" + "punpcklwd %%mm7, %%mm2 \n\t" + "punpckhwd %%mm7, %%mm3 \n\t" + "punpckhwd %%mm7, %%mm4 \n\t" + "punpckhwd %%mm7, %%mm5 \n\t" + "psllq $8, %%mm1 \n\t" + "psllq $16, %%mm2 \n\t" + "por %%mm1, %%mm0 \n\t" + "por %%mm2, %%mm0 \n\t" + "psllq $8, %%mm4 \n\t" + "psllq $16, %%mm5 \n\t" + "por %%mm4, %%mm3 \n\t" + "por %%mm5, %%mm3 \n\t" + MOVNTQ" %%mm0, %0 \n\t" + MOVNTQ" %%mm3, 8%0 \n\t" + :"=m"(*d) + :"m"(*s),"m"(mask15b),"m"(mask15g),"m"(mask15r) + :"memory"); + d += 16; + s += 4; + } + asm volatile(SFENCE:::"memory"); + asm volatile(EMMS:::"memory"); +#endif + while (s < end) + { +#if 0 //slightly slower on Athlon + int bgr= *s++; + *((uint32_t*)d)++ = ((bgr&0x1F)<<3) + ((bgr&0x3E0)<<6) + ((bgr&0x7C00)<<9); #else - register uint16_t bgr; - bgr = *s++; + register uint16_t bgr; + bgr = *s++; #ifdef WORDS_BIGENDIAN - *d++ = 0; - *d++ = (bgr&0x7C00)>>7; - *d++ = (bgr&0x3E0)>>2; - *d++ = (bgr&0x1F)<<3; + *d++ = 0; + *d++ = (bgr&0x7C00)>>7; + *d++ = (bgr&0x3E0)>>2; + *d++ = (bgr&0x1F)<<3; #else - *d++ = (bgr&0x1F)<<3; - *d++ = (bgr&0x3E0)>>2; - *d++ = (bgr&0x7C00)>>7; - *d++ = 0; + *d++ = (bgr&0x1F)<<3; + *d++ = (bgr&0x3E0)>>2; + *d++ = (bgr&0x7C00)>>7; + *d++ = 0; #endif #endif - } + } } static inline void RENAME(rgb16to32)(const uint8_t *src, uint8_t *dst, long src_size) { - const uint16_t *end; + const uint16_t *end; #ifdef HAVE_MMX - const uint16_t *mm_end; + const uint16_t *mm_end; #endif - uint8_t *d = (uint8_t *)dst; - const uint16_t *s = (uint16_t *)src; - end = s + src_size/2; + uint8_t *d = (uint8_t *)dst; + const uint16_t *s = (uint16_t *)src; + end = s + src_size/2; #ifdef HAVE_MMX - __asm __volatile(PREFETCH" %0"::"m"(*s):"memory"); - __asm __volatile("pxor %%mm7,%%mm7\n\t":::"memory"); - mm_end = end - 3; - while(s < mm_end) - { - __asm __volatile( - PREFETCH" 32%1\n\t" - "movq %1, %%mm0\n\t" - "movq %1, %%mm1\n\t" - "movq %1, %%mm2\n\t" - "pand %2, %%mm0\n\t" - "pand %3, %%mm1\n\t" - "pand %4, %%mm2\n\t" - "psllq $3, %%mm0\n\t" - "psrlq $3, %%mm1\n\t" - "psrlq $8, %%mm2\n\t" - "movq %%mm0, %%mm3\n\t" - "movq %%mm1, %%mm4\n\t" - "movq %%mm2, %%mm5\n\t" - "punpcklwd %%mm7, %%mm0\n\t" - "punpcklwd %%mm7, %%mm1\n\t" - "punpcklwd %%mm7, %%mm2\n\t" - "punpckhwd %%mm7, %%mm3\n\t" - "punpckhwd %%mm7, %%mm4\n\t" - "punpckhwd %%mm7, %%mm5\n\t" - "psllq $8, %%mm1\n\t" - "psllq $16, %%mm2\n\t" - "por %%mm1, %%mm0\n\t" - "por %%mm2, %%mm0\n\t" - "psllq $8, %%mm4\n\t" - "psllq $16, %%mm5\n\t" - "por %%mm4, %%mm3\n\t" - "por %%mm5, %%mm3\n\t" - MOVNTQ" %%mm0, %0\n\t" - MOVNTQ" %%mm3, 8%0\n\t" - :"=m"(*d) - :"m"(*s),"m"(mask16b),"m"(mask16g),"m"(mask16r) - :"memory"); - d += 16; - s += 4; - } - __asm __volatile(SFENCE:::"memory"); - __asm __volatile(EMMS:::"memory"); -#endif - while(s < end) - { - register uint16_t bgr; - bgr = *s++; + asm volatile(PREFETCH" %0"::"m"(*s):"memory"); + asm volatile("pxor %%mm7,%%mm7 \n\t":::"memory"); + mm_end = end - 3; + while (s < mm_end) + { + asm volatile( + PREFETCH" 32%1 \n\t" + "movq %1, %%mm0 \n\t" + "movq %1, %%mm1 \n\t" + "movq %1, %%mm2 \n\t" + "pand %2, %%mm0 \n\t" + "pand %3, %%mm1 \n\t" + "pand %4, %%mm2 \n\t" + "psllq $3, %%mm0 \n\t" + "psrlq $3, %%mm1 \n\t" + "psrlq $8, %%mm2 \n\t" + "movq %%mm0, %%mm3 \n\t" + "movq %%mm1, %%mm4 \n\t" + "movq %%mm2, %%mm5 \n\t" + "punpcklwd %%mm7, %%mm0 \n\t" + "punpcklwd %%mm7, %%mm1 \n\t" + "punpcklwd %%mm7, %%mm2 \n\t" + "punpckhwd %%mm7, %%mm3 \n\t" + "punpckhwd %%mm7, %%mm4 \n\t" + "punpckhwd %%mm7, %%mm5 \n\t" + "psllq $8, %%mm1 \n\t" + "psllq $16, %%mm2 \n\t" + "por %%mm1, %%mm0 \n\t" + "por %%mm2, %%mm0 \n\t" + "psllq $8, %%mm4 \n\t" + "psllq $16, %%mm5 \n\t" + "por %%mm4, %%mm3 \n\t" + "por %%mm5, %%mm3 \n\t" + MOVNTQ" %%mm0, %0 \n\t" + MOVNTQ" %%mm3, 8%0 \n\t" + :"=m"(*d) + :"m"(*s),"m"(mask16b),"m"(mask16g),"m"(mask16r) + :"memory"); + d += 16; + s += 4; + } + asm volatile(SFENCE:::"memory"); + asm volatile(EMMS:::"memory"); +#endif + while (s < end) + { + register uint16_t bgr; + bgr = *s++; #ifdef WORDS_BIGENDIAN - *d++ = 0; - *d++ = (bgr&0xF800)>>8; - *d++ = (bgr&0x7E0)>>3; - *d++ = (bgr&0x1F)<<3; + *d++ = 0; + *d++ = (bgr&0xF800)>>8; + *d++ = (bgr&0x7E0)>>3; + *d++ = (bgr&0x1F)<<3; #else - *d++ = (bgr&0x1F)<<3; - *d++ = (bgr&0x7E0)>>3; - *d++ = (bgr&0xF800)>>8; - *d++ = 0; + *d++ = (bgr&0x1F)<<3; + *d++ = (bgr&0x7E0)>>3; + *d++ = (bgr&0xF800)>>8; + *d++ = 0; #endif - } + } } static inline void RENAME(rgb32tobgr32)(const uint8_t *src, uint8_t *dst, long src_size) { + long idx = 15 - src_size; + uint8_t *s = (uint8_t *) src-idx, *d = dst-idx; #ifdef HAVE_MMX -/* TODO: unroll this loop */ - asm volatile ( - "xor %%"REG_a", %%"REG_a" \n\t" - ASMALIGN(4) - "1: \n\t" - PREFETCH" 32(%0, %%"REG_a") \n\t" - "movq (%0, %%"REG_a"), %%mm0 \n\t" - "movq %%mm0, %%mm1 \n\t" - "movq %%mm0, %%mm2 \n\t" - "pslld $16, %%mm0 \n\t" - "psrld $16, %%mm1 \n\t" - "pand "MANGLE(mask32r)", %%mm0 \n\t" - "pand "MANGLE(mask32g)", %%mm2 \n\t" - "pand "MANGLE(mask32b)", %%mm1 \n\t" - "por %%mm0, %%mm2 \n\t" - "por %%mm1, %%mm2 \n\t" - MOVNTQ" %%mm2, (%1, %%"REG_a") \n\t" - "add $8, %%"REG_a" \n\t" - "cmp %2, %%"REG_a" \n\t" - " jb 1b \n\t" - :: "r" (src), "r"(dst), "r" (src_size-7) - : "%"REG_a - ); - - __asm __volatile(SFENCE:::"memory"); - __asm __volatile(EMMS:::"memory"); -#else - unsigned i; - unsigned num_pixels = src_size >> 2; - for(i=0; i>16) + g + (v<<16); + } } static inline void RENAME(rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size) { - unsigned i; + unsigned i; #ifdef HAVE_MMX - long mmx_size= 23 - src_size; - asm volatile ( - "movq "MANGLE(mask24r)", %%mm5 \n\t" - "movq "MANGLE(mask24g)", %%mm6 \n\t" - "movq "MANGLE(mask24b)", %%mm7 \n\t" - ASMALIGN(4) - "1: \n\t" - PREFETCH" 32(%1, %%"REG_a") \n\t" - "movq (%1, %%"REG_a"), %%mm0 \n\t" // BGR BGR BG - "movq (%1, %%"REG_a"), %%mm1 \n\t" // BGR BGR BG - "movq 2(%1, %%"REG_a"), %%mm2 \n\t" // R BGR BGR B - "psllq $16, %%mm0 \n\t" // 00 BGR BGR - "pand %%mm5, %%mm0 \n\t" - "pand %%mm6, %%mm1 \n\t" - "pand %%mm7, %%mm2 \n\t" - "por %%mm0, %%mm1 \n\t" - "por %%mm2, %%mm1 \n\t" - "movq 6(%1, %%"REG_a"), %%mm0 \n\t" // BGR BGR BG - MOVNTQ" %%mm1, (%2, %%"REG_a")\n\t" // RGB RGB RG - "movq 8(%1, %%"REG_a"), %%mm1 \n\t" // R BGR BGR B - "movq 10(%1, %%"REG_a"), %%mm2 \n\t" // GR BGR BGR - "pand %%mm7, %%mm0 \n\t" - "pand %%mm5, %%mm1 \n\t" - "pand %%mm6, %%mm2 \n\t" - "por %%mm0, %%mm1 \n\t" - "por %%mm2, %%mm1 \n\t" - "movq 14(%1, %%"REG_a"), %%mm0 \n\t" // R BGR BGR B - MOVNTQ" %%mm1, 8(%2, %%"REG_a")\n\t" // B RGB RGB R - "movq 16(%1, %%"REG_a"), %%mm1 \n\t" // GR BGR BGR - "movq 18(%1, %%"REG_a"), %%mm2 \n\t" // BGR BGR BG - "pand %%mm6, %%mm0 \n\t" - "pand %%mm7, %%mm1 \n\t" - "pand %%mm5, %%mm2 \n\t" - "por %%mm0, %%mm1 \n\t" - "por %%mm2, %%mm1 \n\t" - MOVNTQ" %%mm1, 16(%2, %%"REG_a")\n\t" - "add $24, %%"REG_a" \n\t" - " js 1b \n\t" - : "+a" (mmx_size) - : "r" (src-mmx_size), "r"(dst-mmx_size) - ); - - __asm __volatile(SFENCE:::"memory"); - __asm __volatile(EMMS:::"memory"); - - if(mmx_size==23) return; //finihsed, was multiple of 8 - - src+= src_size; - dst+= src_size; - src_size= 23-mmx_size; - src-= src_size; - dst-= src_size; -#endif - for(i=0; i>1; - for(y=0; y>1; + for (y=0; y= 64 - int i; - uint64_t *ldst = (uint64_t *) dst; - const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc; - for(i = 0; i < chromWidth; i += 2){ - uint64_t k, l; - k = yc[0] + (uc[0] << 8) + - (yc[1] << 16) + (vc[0] << 24); - l = yc[2] + (uc[1] << 8) + - (yc[3] << 16) + (vc[1] << 24); - *ldst++ = k + (l << 32); - yc += 4; - uc += 2; - vc += 2; - } + int i; + uint64_t *ldst = (uint64_t *) dst; + const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc; + for (i = 0; i < chromWidth; i += 2){ + uint64_t k, l; + k = yc[0] + (uc[0] << 8) + + (yc[1] << 16) + (vc[0] << 24); + l = yc[2] + (uc[1] << 8) + + (yc[3] << 16) + (vc[1] << 24); + *ldst++ = k + (l << 32); + yc += 4; + uc += 2; + vc += 2; + } #else - int i, *idst = (int32_t *) dst; - const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc; - for(i = 0; i < chromWidth; i++){ + int i, *idst = (int32_t *) dst; + const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc; + for (i = 0; i < chromWidth; i++){ #ifdef WORDS_BIGENDIAN - *idst++ = (yc[0] << 24)+ (uc[0] << 16) + - (yc[1] << 8) + (vc[0] << 0); + *idst++ = (yc[0] << 24)+ (uc[0] << 16) + + (yc[1] << 8) + (vc[0] << 0); #else - *idst++ = yc[0] + (uc[0] << 8) + - (yc[1] << 16) + (vc[0] << 24); -#endif - yc += 2; - uc++; - vc++; - } -#endif -#endif - if((y&(vertLumPerChroma-1))==(vertLumPerChroma-1) ) - { - usrc += chromStride; - vsrc += chromStride; - } - ysrc += lumStride; - dst += dstStride; - } + *idst++ = yc[0] + (uc[0] << 8) + + (yc[1] << 16) + (vc[0] << 24); +#endif + yc += 2; + uc++; + vc++; + } +#endif +#endif + if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) + { + usrc += chromStride; + vsrc += chromStride; + } + ysrc += lumStride; + dst += dstStride; + } #ifdef HAVE_MMX -asm( EMMS" \n\t" - SFENCE" \n\t" +asm( EMMS" \n\t" + SFENCE" \n\t" :::"memory"); #endif } /** - * - * height should be a multiple of 2 and width should be a multiple of 16 (if this is a - * problem for anyone then tell me, and ill fix it) + * Height should be a multiple of 2 and width should be a multiple of 16 (if + * this is a problem for anyone then tell me, and I will fix it). */ static inline void RENAME(yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, - long width, long height, - long lumStride, long chromStride, long dstStride) + long width, long height, + long lumStride, long chromStride, long dstStride) { - //FIXME interpolate chroma - RENAME(yuvPlanartoyuy2)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 2); + //FIXME interpolate chroma + RENAME(yuvPlanartoyuy2)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 2); } static inline void RENAME(yuvPlanartouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, - long width, long height, - long lumStride, long chromStride, long dstStride, long vertLumPerChroma) + long width, long height, + long lumStride, long chromStride, long dstStride, long vertLumPerChroma) { - long y; - const long chromWidth= width>>1; - for(y=0; y>1; + for (y=0; yyuy2 +//FIXME adapt the Alpha ASM code from yv12->yuy2 #if __WORDSIZE >= 64 - int i; - uint64_t *ldst = (uint64_t *) dst; - const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc; - for(i = 0; i < chromWidth; i += 2){ - uint64_t k, l; - k = uc[0] + (yc[0] << 8) + - (vc[0] << 16) + (yc[1] << 24); - l = uc[1] + (yc[2] << 8) + - (vc[1] << 16) + (yc[3] << 24); - *ldst++ = k + (l << 32); - yc += 4; - uc += 2; - vc += 2; - } + int i; + uint64_t *ldst = (uint64_t *) dst; + const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc; + for (i = 0; i < chromWidth; i += 2){ + uint64_t k, l; + k = uc[0] + (yc[0] << 8) + + (vc[0] << 16) + (yc[1] << 24); + l = uc[1] + (yc[2] << 8) + + (vc[1] << 16) + (yc[3] << 24); + *ldst++ = k + (l << 32); + yc += 4; + uc += 2; + vc += 2; + } #else - int i, *idst = (int32_t *) dst; - const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc; - for(i = 0; i < chromWidth; i++){ + int i, *idst = (int32_t *) dst; + const uint8_t *yc = ysrc, *uc = usrc, *vc = vsrc; + for (i = 0; i < chromWidth; i++){ #ifdef WORDS_BIGENDIAN - *idst++ = (uc[0] << 24)+ (yc[0] << 16) + - (vc[0] << 8) + (yc[1] << 0); + *idst++ = (uc[0] << 24)+ (yc[0] << 16) + + (vc[0] << 8) + (yc[1] << 0); #else - *idst++ = uc[0] + (yc[0] << 8) + - (vc[0] << 16) + (yc[1] << 24); -#endif - yc += 2; - uc++; - vc++; - } -#endif -#endif - if((y&(vertLumPerChroma-1))==(vertLumPerChroma-1) ) - { - usrc += chromStride; - vsrc += chromStride; - } - ysrc += lumStride; - dst += dstStride; - } + *idst++ = uc[0] + (yc[0] << 8) + + (vc[0] << 16) + (yc[1] << 24); +#endif + yc += 2; + uc++; + vc++; + } +#endif +#endif + if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) + { + usrc += chromStride; + vsrc += chromStride; + } + ysrc += lumStride; + dst += dstStride; + } #ifdef HAVE_MMX -asm( EMMS" \n\t" - SFENCE" \n\t" +asm( EMMS" \n\t" + SFENCE" \n\t" :::"memory"); #endif } /** - * - * height should be a multiple of 2 and width should be a multiple of 16 (if this is a - * problem for anyone then tell me, and ill fix it) + * Height should be a multiple of 2 and width should be a multiple of 16 (if + * this is a problem for anyone then tell me, and I will fix it). */ static inline void RENAME(yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, - long width, long height, - long lumStride, long chromStride, long dstStride) + long width, long height, + long lumStride, long chromStride, long dstStride) { - //FIXME interpolate chroma - RENAME(yuvPlanartouyvy)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 2); + //FIXME interpolate chroma + RENAME(yuvPlanartouyvy)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 2); } /** - * - * width should be a multiple of 16 + * Width should be a multiple of 16. */ static inline void RENAME(yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, - long width, long height, - long lumStride, long chromStride, long dstStride) + long width, long height, + long lumStride, long chromStride, long dstStride) { - RENAME(yuvPlanartoyuy2)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 1); + RENAME(yuvPlanartoyuy2)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 1); } /** - * - * height should be a multiple of 2 and width should be a multiple of 16 (if this is a - * problem for anyone then tell me, and ill fix it) + * Height should be a multiple of 2 and width should be a multiple of 16 (if + * this is a problem for anyone then tell me, and I will fix it). */ static inline void RENAME(yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, - long width, long height, - long lumStride, long chromStride, long srcStride) + long width, long height, + long lumStride, long chromStride, long srcStride) { - long y; - const long chromWidth= width>>1; - for(y=0; y>1; + for (y=0; y>2; - dst[2*x+2]= ( src[x] + 3*src[x+1])>>2; - } - dst[2*srcWidth-1]= src[srcWidth-1]; - + long x,y; + + dst[0]= src[0]; + + // first line + for (x=0; x>2; + dst[2*x+2]= ( src[x] + 3*src[x+1])>>2; + } + dst[2*srcWidth-1]= src[srcWidth-1]; + dst+= dstStride; - for(y=1; y>2; - dst[dstStride]= ( src[0] + 3*src[srcStride])>>2; - - for(x=mmxSize-1; x>2; - dst[2*x+dstStride+2]= ( src[x+0] + 3*src[x+srcStride+1])>>2; - dst[2*x+dstStride+1]= ( src[x+1] + 3*src[x+srcStride ])>>2; - dst[2*x +2]= (3*src[x+1] + src[x+srcStride ])>>2; - } - dst[srcWidth*2 -1 ]= (3*src[srcWidth-1] + src[srcWidth-1 + srcStride])>>2; - dst[srcWidth*2 -1 + dstStride]= ( src[srcWidth-1] + 3*src[srcWidth-1 + srcStride])>>2; - - dst+=dstStride*2; - src+=srcStride; - } - - // last line + const long mmxSize=1; +#endif + dst[0 ]= (3*src[0] + src[srcStride])>>2; + dst[dstStride]= ( src[0] + 3*src[srcStride])>>2; + + for (x=mmxSize-1; x>2; + dst[2*x+dstStride+2]= ( src[x+0] + 3*src[x+srcStride+1])>>2; + dst[2*x+dstStride+1]= ( src[x+1] + 3*src[x+srcStride ])>>2; + dst[2*x +2]= (3*src[x+1] + src[x+srcStride ])>>2; + } + dst[srcWidth*2 -1 ]= (3*src[srcWidth-1] + src[srcWidth-1 + srcStride])>>2; + dst[srcWidth*2 -1 + dstStride]= ( src[srcWidth-1] + 3*src[srcWidth-1 + srcStride])>>2; + + dst+=dstStride*2; + src+=srcStride; + } + + // last line #if 1 - dst[0]= src[0]; - - for(x=0; x>2; - dst[2*x+2]= ( src[x] + 3*src[x+1])>>2; - } - dst[2*srcWidth-1]= src[srcWidth-1]; + dst[0]= src[0]; + + for (x=0; x>2; + dst[2*x+2]= ( src[x] + 3*src[x+1])>>2; + } + dst[2*srcWidth-1]= src[srcWidth-1]; #else - for(x=0; x>1; - for(y=0; y>1; + for (y=0; y>1; + long y; + const long chromWidth= width>>1; #ifdef HAVE_MMX - for(y=0; y>RGB2YUV_SHIFT) + 16; - unsigned int V = ((RV*r + GV*g + BV*b)>>RGB2YUV_SHIFT) + 128; - unsigned int U = ((RU*r + GU*g + BU*b)>>RGB2YUV_SHIFT) + 128; - - udst[i] = U; - vdst[i] = V; - ydst[2*i] = Y; - - b= src[6*i+3]; - g= src[6*i+4]; - r= src[6*i+5]; - - Y = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16; - ydst[2*i+1] = Y; - } - ydst += lumStride; - src += srcStride; - - for(i=0; i>RGB2YUV_SHIFT) + 16; - - ydst[2*i] = Y; - - b= src[6*i+3]; - g= src[6*i+4]; - r= src[6*i+5]; - - Y = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16; - ydst[2*i+1] = Y; - } - udst += chromStride; - vdst += chromStride; - ydst += lumStride; - src += srcStride; - } + y=0; +#endif + for (; y>RGB2YUV_SHIFT) + 16; + unsigned int V = ((RV*r + GV*g + BV*b)>>RGB2YUV_SHIFT) + 128; + unsigned int U = ((RU*r + GU*g + BU*b)>>RGB2YUV_SHIFT) + 128; + + udst[i] = U; + vdst[i] = V; + ydst[2*i] = Y; + + b = src[6*i+3]; + g = src[6*i+4]; + r = src[6*i+5]; + + Y = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16; + ydst[2*i+1] = Y; + } + ydst += lumStride; + src += srcStride; + + for (i=0; i>RGB2YUV_SHIFT) + 16; + + ydst[2*i] = Y; + + b = src[6*i+3]; + g = src[6*i+4]; + r = src[6*i+5]; + + Y = ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16; + ydst[2*i+1] = Y; + } + udst += chromStride; + vdst += chromStride; + ydst += lumStride; + src += srcStride; + } } void RENAME(interleaveBytes)(uint8_t *src1, uint8_t *src2, uint8_t *dest, - long width, long height, long src1Stride, - long src2Stride, long dstStride){ - long h; + long width, long height, long src1Stride, + long src2Stride, long dstStride){ + long h; - for(h=0; h < height; h++) - { - long w; + for (h=0; h < height; h++) + { + long w; #ifdef HAVE_MMX #ifdef HAVE_SSE2 - asm( - "xor %%"REG_a", %%"REG_a" \n\t" - "1: \n\t" - PREFETCH" 64(%1, %%"REG_a") \n\t" - PREFETCH" 64(%2, %%"REG_a") \n\t" - "movdqa (%1, %%"REG_a"), %%xmm0 \n\t" - "movdqa (%1, %%"REG_a"), %%xmm1 \n\t" - "movdqa (%2, %%"REG_a"), %%xmm2 \n\t" - "punpcklbw %%xmm2, %%xmm0 \n\t" - "punpckhbw %%xmm2, %%xmm1 \n\t" - "movntdq %%xmm0, (%0, %%"REG_a", 2)\n\t" - "movntdq %%xmm1, 16(%0, %%"REG_a", 2)\n\t" - "add $16, %%"REG_a" \n\t" - "cmp %3, %%"REG_a" \n\t" - " jb 1b \n\t" - ::"r"(dest), "r"(src1), "r"(src2), "r" (width-15) - : "memory", "%"REG_a"" - ); + asm( + "xor %%"REG_a", %%"REG_a" \n\t" + "1: \n\t" + PREFETCH" 64(%1, %%"REG_a") \n\t" + PREFETCH" 64(%2, %%"REG_a") \n\t" + "movdqa (%1, %%"REG_a"), %%xmm0 \n\t" + "movdqa (%1, %%"REG_a"), %%xmm1 \n\t" + "movdqa (%2, %%"REG_a"), %%xmm2 \n\t" + "punpcklbw %%xmm2, %%xmm0 \n\t" + "punpckhbw %%xmm2, %%xmm1 \n\t" + "movntdq %%xmm0, (%0, %%"REG_a", 2) \n\t" + "movntdq %%xmm1, 16(%0, %%"REG_a", 2) \n\t" + "add $16, %%"REG_a" \n\t" + "cmp %3, %%"REG_a" \n\t" + " jb 1b \n\t" + ::"r"(dest), "r"(src1), "r"(src2), "r" (width-15) + : "memory", "%"REG_a"" + ); #else - asm( - "xor %%"REG_a", %%"REG_a" \n\t" - "1: \n\t" - PREFETCH" 64(%1, %%"REG_a") \n\t" - PREFETCH" 64(%2, %%"REG_a") \n\t" - "movq (%1, %%"REG_a"), %%mm0 \n\t" - "movq 8(%1, %%"REG_a"), %%mm2 \n\t" - "movq %%mm0, %%mm1 \n\t" - "movq %%mm2, %%mm3 \n\t" - "movq (%2, %%"REG_a"), %%mm4 \n\t" - "movq 8(%2, %%"REG_a"), %%mm5 \n\t" - "punpcklbw %%mm4, %%mm0 \n\t" - "punpckhbw %%mm4, %%mm1 \n\t" - "punpcklbw %%mm5, %%mm2 \n\t" - "punpckhbw %%mm5, %%mm3 \n\t" - MOVNTQ" %%mm0, (%0, %%"REG_a", 2)\n\t" - MOVNTQ" %%mm1, 8(%0, %%"REG_a", 2)\n\t" - MOVNTQ" %%mm2, 16(%0, %%"REG_a", 2)\n\t" - MOVNTQ" %%mm3, 24(%0, %%"REG_a", 2)\n\t" - "add $16, %%"REG_a" \n\t" - "cmp %3, %%"REG_a" \n\t" - " jb 1b \n\t" - ::"r"(dest), "r"(src1), "r"(src2), "r" (width-15) - : "memory", "%"REG_a - ); -#endif - for(w= (width&(~15)); w < width; w++) - { - dest[2*w+0] = src1[w]; - dest[2*w+1] = src2[w]; - } + asm( + "xor %%"REG_a", %%"REG_a" \n\t" + "1: \n\t" + PREFETCH" 64(%1, %%"REG_a") \n\t" + PREFETCH" 64(%2, %%"REG_a") \n\t" + "movq (%1, %%"REG_a"), %%mm0 \n\t" + "movq 8(%1, %%"REG_a"), %%mm2 \n\t" + "movq %%mm0, %%mm1 \n\t" + "movq %%mm2, %%mm3 \n\t" + "movq (%2, %%"REG_a"), %%mm4 \n\t" + "movq 8(%2, %%"REG_a"), %%mm5 \n\t" + "punpcklbw %%mm4, %%mm0 \n\t" + "punpckhbw %%mm4, %%mm1 \n\t" + "punpcklbw %%mm5, %%mm2 \n\t" + "punpckhbw %%mm5, %%mm3 \n\t" + MOVNTQ" %%mm0, (%0, %%"REG_a", 2) \n\t" + MOVNTQ" %%mm1, 8(%0, %%"REG_a", 2) \n\t" + MOVNTQ" %%mm2, 16(%0, %%"REG_a", 2) \n\t" + MOVNTQ" %%mm3, 24(%0, %%"REG_a", 2) \n\t" + "add $16, %%"REG_a" \n\t" + "cmp %3, %%"REG_a" \n\t" + " jb 1b \n\t" + ::"r"(dest), "r"(src1), "r"(src2), "r" (width-15) + : "memory", "%"REG_a + ); +#endif + for (w= (width&(~15)); w < width; w++) + { + dest[2*w+0] = src1[w]; + dest[2*w+1] = src2[w]; + } #else - for(w=0; w < width; w++) - { - dest[2*w+0] = src1[w]; - dest[2*w+1] = src2[w]; - } + for (w=0; w < width; w++) + { + dest[2*w+0] = src1[w]; + dest[2*w+1] = src2[w]; + } #endif - dest += dstStride; + dest += dstStride; src1 += src1Stride; src2 += src2Stride; - } + } #ifdef HAVE_MMX - asm( - EMMS" \n\t" - SFENCE" \n\t" - ::: "memory" - ); + asm( + EMMS" \n\t" + SFENCE" \n\t" + ::: "memory" + ); #endif } static inline void RENAME(vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2, - uint8_t *dst1, uint8_t *dst2, - long width, long height, - long srcStride1, long srcStride2, - long dstStride1, long dstStride2) + uint8_t *dst1, uint8_t *dst2, + long width, long height, + long srcStride1, long srcStride2, + long dstStride1, long dstStride2) { long y,x,w,h; w=width/2; h=height/2; #ifdef HAVE_MMX asm volatile( - PREFETCH" %0\n\t" - PREFETCH" %1\n\t" - ::"m"(*(src1+srcStride1)),"m"(*(src2+srcStride2)):"memory"); -#endif - for(y=0;y>1); - uint8_t* d=dst1+dstStride1*y; - x=0; + PREFETCH" %0 \n\t" + PREFETCH" %1 \n\t" + ::"m"(*(src1+srcStride1)),"m"(*(src2+srcStride2)):"memory"); +#endif + for (y=0;y>1); + uint8_t* d=dst1+dstStride1*y; + x=0; #ifdef HAVE_MMX - for(;x>1); - uint8_t* d=dst2+dstStride2*y; - x=0; + for (y=0;y>1); + uint8_t* d=dst2+dstStride2*y; + x=0; #ifdef HAVE_MMX - for(;x>2); - const uint8_t* vp=src3+srcStride3*(y>>2); - uint8_t* d=dst+dstStride*y; - x=0; + for (y=0;y>2); + const uint8_t* vp=src3+srcStride3*(y>>2); + uint8_t* d=dst+dstStride*y; + x=0; #ifdef HAVE_MMX - for(;x @@ -31,129 +31,129 @@ #include "rgb2rgb.h" static uint64_t getSSD(uint8_t *src1, uint8_t *src2, int stride1, int stride2, int w, int h){ - int x,y; - uint64_t ssd=0; + int x,y; + uint64_t ssd=0; //printf("%d %d\n", w, h); - - for(y=0; y src -> dst -> out & compare out against ref // ref & out are YV12 -static int doTest(uint8_t *ref[3], int refStride[3], int w, int h, int srcFormat, int dstFormat, - int srcW, int srcH, int dstW, int dstH, int flags){ - uint8_t *src[3]; - uint8_t *dst[3]; - uint8_t *out[3]; - int srcStride[3], dstStride[3]; - int i; - uint64_t ssdY, ssdU, ssdV; - struct SwsContext *srcContext, *dstContext, *outContext; - int res; - - res = 0; - for(i=0; i<3; i++){ - // avoid stride % bpp != 0 - if(srcFormat==PIX_FMT_RGB24 || srcFormat==PIX_FMT_BGR24) - srcStride[i]= srcW*3; - else - srcStride[i]= srcW*4; - - if(dstFormat==PIX_FMT_RGB24 || dstFormat==PIX_FMT_BGR24) - dstStride[i]= dstW*3; - else - dstStride[i]= dstW*4; - - src[i]= (uint8_t*) malloc(srcStride[i]*srcH); - dst[i]= (uint8_t*) malloc(dstStride[i]*dstH); - out[i]= (uint8_t*) malloc(refStride[i]*h); - if ((src[i] == NULL) || (dst[i] == NULL) || (out[i] == NULL)) { - perror("Malloc"); - res = -1; - - goto end; - } - } - - dstContext = outContext = NULL; - srcContext= sws_getContext(w, h, PIX_FMT_YUV420P, srcW, srcH, srcFormat, flags, NULL, NULL, NULL); - if (srcContext == NULL) { - fprintf(stderr, "Failed to get %s ---> %s\n", - sws_format_name(PIX_FMT_YUV420P), - sws_format_name(srcFormat)); - res = -1; - - goto end; - } - dstContext= sws_getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flags, NULL, NULL, NULL); - if (dstContext == NULL) { - fprintf(stderr, "Failed to get %s ---> %s\n", - sws_format_name(srcFormat), - sws_format_name(dstFormat)); - res = -1; - - goto end; - } - outContext= sws_getContext(dstW, dstH, dstFormat, w, h, PIX_FMT_YUV420P, flags, NULL, NULL, NULL); - if (outContext == NULL) { - fprintf(stderr, "Failed to get %s ---> %s\n", - sws_format_name(dstFormat), - sws_format_name(PIX_FMT_YUV420P)); - res = -1; - - goto end; - } -// printf("test %X %X %X -> %X %X %X\n", (int)ref[0], (int)ref[1], (int)ref[2], -// (int)src[0], (int)src[1], (int)src[2]); - - sws_scale(srcContext, ref, refStride, 0, h , src, srcStride); - sws_scale(dstContext, src, srcStride, 0, srcH, dst, dstStride); - sws_scale(outContext, dst, dstStride, 0, dstH, out, refStride); +static int doTest(uint8_t *ref[3], int refStride[3], int w, int h, int srcFormat, int dstFormat, + int srcW, int srcH, int dstW, int dstH, int flags){ + uint8_t *src[3]; + uint8_t *dst[3]; + uint8_t *out[3]; + int srcStride[3], dstStride[3]; + int i; + uint64_t ssdY, ssdU, ssdV; + struct SwsContext *srcContext, *dstContext, *outContext; + int res; + + res = 0; + for (i=0; i<3; i++){ + // avoid stride % bpp != 0 + if (srcFormat==PIX_FMT_RGB24 || srcFormat==PIX_FMT_BGR24) + srcStride[i]= srcW*3; + else + srcStride[i]= srcW*4; + + if (dstFormat==PIX_FMT_RGB24 || dstFormat==PIX_FMT_BGR24) + dstStride[i]= dstW*3; + else + dstStride[i]= dstW*4; + + src[i]= (uint8_t*) malloc(srcStride[i]*srcH); + dst[i]= (uint8_t*) malloc(dstStride[i]*dstH); + out[i]= (uint8_t*) malloc(refStride[i]*h); + if (!src[i] || !dst[i] || !out[i]) { + perror("Malloc"); + res = -1; + + goto end; + } + } + + dstContext = outContext = NULL; + srcContext= sws_getContext(w, h, PIX_FMT_YUV420P, srcW, srcH, srcFormat, flags, NULL, NULL, NULL); + if (!srcContext) { + fprintf(stderr, "Failed to get %s ---> %s\n", + sws_format_name(PIX_FMT_YUV420P), + sws_format_name(srcFormat)); + res = -1; + + goto end; + } + dstContext= sws_getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flags, NULL, NULL, NULL); + if (!dstContext) { + fprintf(stderr, "Failed to get %s ---> %s\n", + sws_format_name(srcFormat), + sws_format_name(dstFormat)); + res = -1; + + goto end; + } + outContext= sws_getContext(dstW, dstH, dstFormat, w, h, PIX_FMT_YUV420P, flags, NULL, NULL, NULL); + if (!outContext) { + fprintf(stderr, "Failed to get %s ---> %s\n", + sws_format_name(dstFormat), + sws_format_name(PIX_FMT_YUV420P)); + res = -1; + + goto end; + } +// printf("test %X %X %X -> %X %X %X\n", (int)ref[0], (int)ref[1], (int)ref[2], +// (int)src[0], (int)src[1], (int)src[2]); + + sws_scale(srcContext, ref, refStride, 0, h , src, srcStride); + sws_scale(dstContext, src, srcStride, 0, srcH, dst, dstStride); + sws_scale(outContext, dst, dstStride, 0, dstH, out, refStride); #if defined(ARCH_X86) - asm volatile ("emms\n\t"); + asm volatile ("emms\n\t"); #endif - - ssdY= getSSD(ref[0], out[0], refStride[0], refStride[0], w, h); - ssdU= getSSD(ref[1], out[1], refStride[1], refStride[1], (w+1)>>1, (h+1)>>1); - ssdV= getSSD(ref[2], out[2], refStride[2], refStride[2], (w+1)>>1, (h+1)>>1); - - if(srcFormat == PIX_FMT_GRAY8 || dstFormat==PIX_FMT_GRAY8) ssdU=ssdV=0; //FIXME check that output is really gray - - ssdY/= w*h; - ssdU/= w*h/4; - ssdV/= w*h/4; - - if(ssdY>100 || ssdU>100 || ssdV>100){ - printf(" %s %dx%d -> %s %4dx%4d flags=%2d SSD=%5lld,%5lld,%5lld\n", - sws_format_name(srcFormat), srcW, srcH, - sws_format_name(dstFormat), dstW, dstH, - flags, - ssdY, ssdU, ssdV); - } - - end: - - sws_freeContext(srcContext); - sws_freeContext(dstContext); - sws_freeContext(outContext); - - for(i=0; i<3; i++){ - free(src[i]); - free(dst[i]); - free(out[i]); - } - - return res; + + ssdY= getSSD(ref[0], out[0], refStride[0], refStride[0], w, h); + ssdU= getSSD(ref[1], out[1], refStride[1], refStride[1], (w+1)>>1, (h+1)>>1); + ssdV= getSSD(ref[2], out[2], refStride[2], refStride[2], (w+1)>>1, (h+1)>>1); + + if (srcFormat == PIX_FMT_GRAY8 || dstFormat==PIX_FMT_GRAY8) ssdU=ssdV=0; //FIXME check that output is really gray + + ssdY/= w*h; + ssdU/= w*h/4; + ssdV/= w*h/4; + + if (ssdY>100 || ssdU>100 || ssdV>100){ + printf(" %s %dx%d -> %s %4dx%4d flags=%2d SSD=%5lld,%5lld,%5lld\n", + sws_format_name(srcFormat), srcW, srcH, + sws_format_name(dstFormat), dstW, dstH, + flags, + ssdY, ssdU, ssdV); + } + + end: + + sws_freeContext(srcContext); + sws_freeContext(dstContext); + sws_freeContext(outContext); + + for (i=0; i<3; i++){ + free(src[i]); + free(dst[i]); + free(out[i]); + } + + return res; } void fast_memcpy(void *a, void *b, int s){ //FIXME @@ -161,69 +161,69 @@ void fast_memcpy(void *a, void *b, int s){ //FIXME } static void selfTest(uint8_t *src[3], int stride[3], int w, int h){ - enum PixelFormat srcFormat, dstFormat; - int srcW, srcH, dstW, dstH; - int flags; - - for(srcFormat = 0; srcFormat < PIX_FMT_NB; srcFormat++) { - for(dstFormat = 0; dstFormat < PIX_FMT_NB; dstFormat++) { - printf("%s -> %s\n", - sws_format_name(srcFormat), - sws_format_name(dstFormat)); - - srcW= w; - srcH= h; - for(dstW=w - w/3; dstW<= 4*w/3; dstW+= w/3){ - for(dstH=h - h/3; dstH<= 4*h/3; dstH+= h/3){ - for(flags=1; flags<33; flags*=2) { - int res; - - res = doTest(src, stride, w, h, srcFormat, dstFormat, - srcW, srcH, dstW, dstH, flags); - if (res < 0) { - dstW = 4 * w / 3; - dstH = 4 * h / 3; - flags = 33; - } - } - } - } - } - } + enum PixelFormat srcFormat, dstFormat; + int srcW, srcH, dstW, dstH; + int flags; + + for (srcFormat = 0; srcFormat < PIX_FMT_NB; srcFormat++) { + for (dstFormat = 0; dstFormat < PIX_FMT_NB; dstFormat++) { + printf("%s -> %s\n", + sws_format_name(srcFormat), + sws_format_name(dstFormat)); + + srcW= w; + srcH= h; + for (dstW=w - w/3; dstW<= 4*w/3; dstW+= w/3){ + for (dstH=h - h/3; dstH<= 4*h/3; dstH+= h/3){ + for (flags=1; flags<33; flags*=2) { + int res; + + res = doTest(src, stride, w, h, srcFormat, dstFormat, + srcW, srcH, dstW, dstH, flags); + if (res < 0) { + dstW = 4 * w / 3; + dstH = 4 * h / 3; + flags = 33; + } + } + } + } + } + } } #define W 96 #define H 96 int main(int argc, char **argv){ - uint8_t rgb_data[W*H*4]; - uint8_t *rgb_src[3]= {rgb_data, NULL, NULL}; - int rgb_stride[3]={4*W, 0, 0}; - uint8_t data[3][W*H]; - uint8_t *src[3]= {data[0], data[1], data[2]}; - int stride[3]={W, W, W}; - int x, y; - struct SwsContext *sws; - - sws= sws_getContext(W/12, H/12, PIX_FMT_RGB32, W, H, PIX_FMT_YUV420P, 2, NULL, NULL, NULL); - - for(y=0; y {BGR,RGB}{1,4,8,15,16,24,32} x -> x @@ -37,7 +37,7 @@ BGR15 -> BGR16 */ -/* +/* tested special converters (most are tested actually but i didnt write it down ...) YV12 -> BGR16 YV12 -> YV12 @@ -46,7 +46,7 @@ tested special converters (most are tested actually but i didnt write it down .. YVU9 -> YV12 untested special converters - YV12/I420 -> BGR15/BGR24/BGR32 (its the yuv2rgb stuff, so it should be ok) + YV12/I420 -> BGR15/BGR24/BGR32 (it is the yuv2rgb stuff, so it should be ok) YV12/I420 -> YV12/I420 YUY2/BGR15/BGR24/BGR32/RGB24/RGB32 -> same format BGR24 -> BGR32 & RGB24 -> RGB32 @@ -72,9 +72,7 @@ untested special converters #include "x86_cpu.h" #include "bswap.h" #include "rgb2rgb.h" -#ifdef USE_FASTMEMCPY -#include "libvo/fastmemcpy.h" -#endif +#include "libavcodec/opt.h" #undef MOVNTQ #undef PAVGB @@ -102,22 +100,56 @@ untested special converters #define PI 3.14159265358979323846 #endif -#define isSupportedIn(x) ((x)==PIX_FMT_YUV420P || (x)==PIX_FMT_YUYV422 || (x)==PIX_FMT_UYVY422\ - || (x)==PIX_FMT_RGB32|| (x)==PIX_FMT_BGR24|| (x)==PIX_FMT_BGR565|| (x)==PIX_FMT_BGR555\ - || (x)==PIX_FMT_BGR32|| (x)==PIX_FMT_RGB24|| (x)==PIX_FMT_RGB565|| (x)==PIX_FMT_RGB555\ - || (x)==PIX_FMT_GRAY8 || (x)==PIX_FMT_YUV410P\ - || (x)==PIX_FMT_GRAY16BE || (x)==PIX_FMT_GRAY16LE\ - || (x)==PIX_FMT_YUV444P || (x)==PIX_FMT_YUV422P || (x)==PIX_FMT_YUV411P\ - || (x)==PIX_FMT_PAL8 || (x)==PIX_FMT_BGR8 || (x)==PIX_FMT_RGB8\ - || (x)==PIX_FMT_BGR4_BYTE || (x)==PIX_FMT_RGB4_BYTE) -#define isSupportedOut(x) ((x)==PIX_FMT_YUV420P || (x)==PIX_FMT_YUYV422 || (x)==PIX_FMT_UYVY422\ - || (x)==PIX_FMT_YUV444P || (x)==PIX_FMT_YUV422P || (x)==PIX_FMT_YUV411P\ - || isRGB(x) || isBGR(x)\ - || (x)==PIX_FMT_NV12 || (x)==PIX_FMT_NV21\ - || (x)==PIX_FMT_GRAY16BE || (x)==PIX_FMT_GRAY16LE\ - || (x)==PIX_FMT_GRAY8 || (x)==PIX_FMT_YUV410P) -#define isPacked(x) ((x)==PIX_FMT_PAL8 || (x)==PIX_FMT_YUYV422 ||\ - (x)==PIX_FMT_UYVY422 || isRGB(x) || isBGR(x)) +#define isSupportedIn(x) ( \ + (x)==PIX_FMT_YUV420P \ + || (x)==PIX_FMT_YUVA420P \ + || (x)==PIX_FMT_YUYV422 \ + || (x)==PIX_FMT_UYVY422 \ + || (x)==PIX_FMT_RGB32 \ + || (x)==PIX_FMT_BGR24 \ + || (x)==PIX_FMT_BGR565 \ + || (x)==PIX_FMT_BGR555 \ + || (x)==PIX_FMT_BGR32 \ + || (x)==PIX_FMT_RGB24 \ + || (x)==PIX_FMT_RGB565 \ + || (x)==PIX_FMT_RGB555 \ + || (x)==PIX_FMT_GRAY8 \ + || (x)==PIX_FMT_YUV410P \ + || (x)==PIX_FMT_GRAY16BE \ + || (x)==PIX_FMT_GRAY16LE \ + || (x)==PIX_FMT_YUV444P \ + || (x)==PIX_FMT_YUV422P \ + || (x)==PIX_FMT_YUV411P \ + || (x)==PIX_FMT_PAL8 \ + || (x)==PIX_FMT_BGR8 \ + || (x)==PIX_FMT_RGB8 \ + || (x)==PIX_FMT_BGR4_BYTE \ + || (x)==PIX_FMT_RGB4_BYTE \ + || (x)==PIX_FMT_YUV440P \ + ) +#define isSupportedOut(x) ( \ + (x)==PIX_FMT_YUV420P \ + || (x)==PIX_FMT_YUYV422 \ + || (x)==PIX_FMT_UYVY422 \ + || (x)==PIX_FMT_YUV444P \ + || (x)==PIX_FMT_YUV422P \ + || (x)==PIX_FMT_YUV411P \ + || isRGB(x) \ + || isBGR(x) \ + || (x)==PIX_FMT_NV12 \ + || (x)==PIX_FMT_NV21 \ + || (x)==PIX_FMT_GRAY16BE \ + || (x)==PIX_FMT_GRAY16LE \ + || (x)==PIX_FMT_GRAY8 \ + || (x)==PIX_FMT_YUV410P \ + ) +#define isPacked(x) ( \ + (x)==PIX_FMT_PAL8 \ + || (x)==PIX_FMT_YUYV422 \ + || (x)==PIX_FMT_UYVY422 \ + || isRGB(x) \ + || isBGR(x) \ + ) #define RGB2YUV_SHIFT 16 #define BY ((int)( 0.098*(1<BGR scaler */ #if defined(ARCH_X86) && defined (CONFIG_GPL) -static uint64_t attribute_used __attribute__((aligned(8))) bF8= 0xF8F8F8F8F8F8F8F8LL; -static uint64_t attribute_used __attribute__((aligned(8))) bFC= 0xFCFCFCFCFCFCFCFCLL; -static uint64_t __attribute__((aligned(8))) w10= 0x0010001000100010LL; -static uint64_t attribute_used __attribute__((aligned(8))) w02= 0x0002000200020002LL; -static uint64_t attribute_used __attribute__((aligned(8))) bm00001111=0x00000000FFFFFFFFLL; -static uint64_t attribute_used __attribute__((aligned(8))) bm00000111=0x0000000000FFFFFFLL; -static uint64_t attribute_used __attribute__((aligned(8))) bm11111000=0xFFFFFFFFFF000000LL; -static uint64_t attribute_used __attribute__((aligned(8))) bm01010101=0x00FF00FF00FF00FFLL; +DECLARE_ASM_CONST(8, uint64_t, bF8)= 0xF8F8F8F8F8F8F8F8LL; +DECLARE_ASM_CONST(8, uint64_t, bFC)= 0xFCFCFCFCFCFCFCFCLL; +DECLARE_ASM_CONST(8, uint64_t, w10)= 0x0010001000100010LL; +DECLARE_ASM_CONST(8, uint64_t, w02)= 0x0002000200020002LL; +DECLARE_ASM_CONST(8, uint64_t, bm00001111)=0x00000000FFFFFFFFLL; +DECLARE_ASM_CONST(8, uint64_t, bm00000111)=0x0000000000FFFFFFLL; +DECLARE_ASM_CONST(8, uint64_t, bm11111000)=0xFFFFFFFFFF000000LL; +DECLARE_ASM_CONST(8, uint64_t, bm01010101)=0x00FF00FF00FF00FFLL; static volatile uint64_t attribute_used __attribute__((aligned(8))) b5Dither; static volatile uint64_t attribute_used __attribute__((aligned(8))) g5Dither; static volatile uint64_t attribute_used __attribute__((aligned(8))) g6Dither; static volatile uint64_t attribute_used __attribute__((aligned(8))) r5Dither; -static uint64_t __attribute__((aligned(8))) dither4[2]={ - 0x0103010301030103LL, - 0x0200020002000200LL,}; +const DECLARE_ALIGNED(8, uint64_t, ff_dither4[2]) = { + 0x0103010301030103LL, + 0x0200020002000200LL,}; -static uint64_t __attribute__((aligned(8))) dither8[2]={ - 0x0602060206020602LL, - 0x0004000400040004LL,}; +const DECLARE_ALIGNED(8, uint64_t, ff_dither8[2]) = { + 0x0602060206020602LL, + 0x0004000400040004LL,}; -static uint64_t __attribute__((aligned(8))) b16Mask= 0x001F001F001F001FLL; -static uint64_t attribute_used __attribute__((aligned(8))) g16Mask= 0x07E007E007E007E0LL; -static uint64_t attribute_used __attribute__((aligned(8))) r16Mask= 0xF800F800F800F800LL; -static uint64_t __attribute__((aligned(8))) b15Mask= 0x001F001F001F001FLL; -static uint64_t attribute_used __attribute__((aligned(8))) g15Mask= 0x03E003E003E003E0LL; -static uint64_t attribute_used __attribute__((aligned(8))) r15Mask= 0x7C007C007C007C00LL; +DECLARE_ASM_CONST(8, uint64_t, b16Mask)= 0x001F001F001F001FLL; +DECLARE_ASM_CONST(8, uint64_t, g16Mask)= 0x07E007E007E007E0LL; +DECLARE_ASM_CONST(8, uint64_t, r16Mask)= 0xF800F800F800F800LL; +DECLARE_ASM_CONST(8, uint64_t, b15Mask)= 0x001F001F001F001FLL; +DECLARE_ASM_CONST(8, uint64_t, g15Mask)= 0x03E003E003E003E0LL; +DECLARE_ASM_CONST(8, uint64_t, r15Mask)= 0x7C007C007C007C00LL; -static uint64_t attribute_used __attribute__((aligned(8))) M24A= 0x00FF0000FF0000FFLL; -static uint64_t attribute_used __attribute__((aligned(8))) M24B= 0xFF0000FF0000FF00LL; -static uint64_t attribute_used __attribute__((aligned(8))) M24C= 0x0000FF0000FF0000LL; +DECLARE_ALIGNED(8, const uint64_t, ff_M24A) = 0x00FF0000FF0000FFLL; +DECLARE_ALIGNED(8, const uint64_t, ff_M24B) = 0xFF0000FF0000FF00LL; +DECLARE_ALIGNED(8, const uint64_t, ff_M24C) = 0x0000FF0000FF0000LL; #ifdef FAST_BGR2YV12 -static const uint64_t bgr2YCoeff attribute_used __attribute__((aligned(8))) = 0x000000210041000DULL; -static const uint64_t bgr2UCoeff attribute_used __attribute__((aligned(8))) = 0x0000FFEEFFDC0038ULL; -static const uint64_t bgr2VCoeff attribute_used __attribute__((aligned(8))) = 0x00000038FFD2FFF8ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YCoeff) = 0x000000210041000DULL; +DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UCoeff) = 0x0000FFEEFFDC0038ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_bgr2VCoeff) = 0x00000038FFD2FFF8ULL; #else -static const uint64_t bgr2YCoeff attribute_used __attribute__((aligned(8))) = 0x000020E540830C8BULL; -static const uint64_t bgr2UCoeff attribute_used __attribute__((aligned(8))) = 0x0000ED0FDAC23831ULL; -static const uint64_t bgr2VCoeff attribute_used __attribute__((aligned(8))) = 0x00003831D0E6F6EAULL; +DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YCoeff) = 0x000020E540830C8BULL; +DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UCoeff) = 0x0000ED0FDAC23831ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_bgr2VCoeff) = 0x00003831D0E6F6EAULL; #endif /* FAST_BGR2YV12 */ -static const uint64_t bgr2YOffset attribute_used __attribute__((aligned(8))) = 0x1010101010101010ULL; -static const uint64_t bgr2UVOffset attribute_used __attribute__((aligned(8)))= 0x8080808080808080ULL; -static const uint64_t w1111 attribute_used __attribute__((aligned(8))) = 0x0001000100010001ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YOffset) = 0x1010101010101010ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UVOffset) = 0x8080808080808080ULL; +DECLARE_ALIGNED(8, const uint64_t, ff_w1111) = 0x0001000100010001ULL; #endif /* defined(ARCH_X86) */ // clipping helper table for C implementations: static unsigned char clip_table[768]; static SwsVector *sws_getConvVec(SwsVector *a, SwsVector *b); - + extern const uint8_t dither_2x2_4[2][8]; extern const uint8_t dither_2x2_8[2][8]; extern const uint8_t dither_8x8_32[8][8]; @@ -210,13 +242,47 @@ static const char * sws_context_to_name(void * ptr) { return "swscaler"; } -static AVClass sws_context_class = { "SWScaler", sws_context_to_name, NULL }; +#define OFFSET(x) offsetof(SwsContext, x) +#define DEFAULT 0 +#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM + +static const AVOption options[] = { + { "sws_flags", "scaler/cpu flags", OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "fast_bilinear", "fast bilinear", 0, FF_OPT_TYPE_CONST, SWS_FAST_BILINEAR, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "bilinear", "bilinear", 0, FF_OPT_TYPE_CONST, SWS_BILINEAR, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "bicubic", "bicubic", 0, FF_OPT_TYPE_CONST, SWS_BICUBIC, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "experimental", "experimental", 0, FF_OPT_TYPE_CONST, SWS_X, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "neighbor", "nearest neighbor", 0, FF_OPT_TYPE_CONST, SWS_POINT, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "area", "averaging area", 0, FF_OPT_TYPE_CONST, SWS_AREA, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "bicublin", "luma bicubic, chroma bilinear", 0, FF_OPT_TYPE_CONST, SWS_BICUBLIN, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "gauss", "gaussian", 0, FF_OPT_TYPE_CONST, SWS_GAUSS, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "sinc", "sinc", 0, FF_OPT_TYPE_CONST, SWS_SINC, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "lanczos", "lanczos", 0, FF_OPT_TYPE_CONST, SWS_LANCZOS, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "spline", "natural bicubic spline", 0, FF_OPT_TYPE_CONST, SWS_SPLINE, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "print_info", "print info", 0, FF_OPT_TYPE_CONST, SWS_PRINT_INFO, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "accurate_rnd", "accurate rounding", 0, FF_OPT_TYPE_CONST, SWS_ACCURATE_RND, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "mmx", "MMX SIMD acceleration", 0, FF_OPT_TYPE_CONST, SWS_CPU_CAPS_MMX, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "mmx2", "MMX2 SIMD acceleration", 0, FF_OPT_TYPE_CONST, SWS_CPU_CAPS_MMX2, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "3dnow", "3DNOW SIMD acceleration", 0, FF_OPT_TYPE_CONST, SWS_CPU_CAPS_3DNOW, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "altivec", "AltiVec SIMD acceleration", 0, FF_OPT_TYPE_CONST, SWS_CPU_CAPS_ALTIVEC, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "bfin", "Blackfin SIMD acceleration", 0, FF_OPT_TYPE_CONST, SWS_CPU_CAPS_BFIN, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "full_chroma_int", "full chroma interpolation", 0 , FF_OPT_TYPE_CONST, SWS_FULL_CHR_H_INT, INT_MIN, INT_MAX, VE, "sws_flags" }, + { "full_chroma_inp", "full chroma input", 0 , FF_OPT_TYPE_CONST, SWS_FULL_CHR_H_INP, INT_MIN, INT_MAX, VE, "sws_flags" }, + { NULL } +}; + +#undef VE +#undef DEFAULT + +static AVClass sws_context_class = { "SWScaler", sws_context_to_name, options }; char *sws_format_name(enum PixelFormat format) { switch (format) { case PIX_FMT_YUV420P: return "yuv420p"; + case PIX_FMT_YUVA420P: + return "yuva420p"; case PIX_FMT_YUYV422: return "yuyv422"; case PIX_FMT_RGB24: @@ -289,6 +355,8 @@ char *sws_format_name(enum PixelFormat format) return "nv12"; case PIX_FMT_NV21: return "nv21"; + case PIX_FMT_YUV440P: + return "yuv440p"; default: return "Unknown format"; } @@ -297,511 +365,511 @@ char *sws_format_name(enum PixelFormat format) #if defined(ARCH_X86) && defined (CONFIG_GPL) void in_asm_used_var_warning_killer() { - volatile int i= bF8+bFC+w10+ - bm00001111+bm00000111+bm11111000+b16Mask+g16Mask+r16Mask+b15Mask+g15Mask+r15Mask+ - M24A+M24B+M24C+w02 + b5Dither+g5Dither+r5Dither+g6Dither+dither4[0]+dither8[0]+bm01010101; - if(i) i=0; + volatile int i= bF8+bFC+w10+ + bm00001111+bm00000111+bm11111000+b16Mask+g16Mask+r16Mask+b15Mask+g15Mask+r15Mask+ + ff_M24A+ff_M24B+ff_M24C+w02 + b5Dither+g5Dither+r5Dither+g6Dither+ff_dither4[0]+ff_dither8[0]+bm01010101; + if (i) i=0; } #endif static inline void yuv2yuvXinC(int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize, - int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, - uint8_t *dest, uint8_t *uDest, uint8_t *vDest, int dstW, int chrDstW) + int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, + uint8_t *dest, uint8_t *uDest, uint8_t *vDest, int dstW, int chrDstW) { - //FIXME Optimize (just quickly writen not opti..) - int i; - for(i=0; i>19); - } - - if(uDest != NULL) - for(i=0; i>19); - vDest[i]= av_clip_uint8(v>>19); - } + //FIXME Optimize (just quickly writen not opti..) + int i; + for (i=0; i>19); + } + + if (uDest) + for (i=0; i>19); + vDest[i]= av_clip_uint8(v>>19); + } } static inline void yuv2nv12XinC(int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize, - int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, - uint8_t *dest, uint8_t *uDest, int dstW, int chrDstW, int dstFormat) + int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, + uint8_t *dest, uint8_t *uDest, int dstW, int chrDstW, int dstFormat) { - //FIXME Optimize (just quickly writen not opti..) - int i; - for(i=0; i>19); - } - - if(uDest == NULL) - return; - - if(dstFormat == PIX_FMT_NV12) - for(i=0; i>19); - uDest[2*i+1]= av_clip_uint8(v>>19); - } - else - for(i=0; i>19); - uDest[2*i+1]= av_clip_uint8(u>>19); - } + //FIXME Optimize (just quickly writen not opti..) + int i; + for (i=0; i>19); + } + + if (!uDest) + return; + + if (dstFormat == PIX_FMT_NV12) + for (i=0; i>19); + uDest[2*i+1]= av_clip_uint8(v>>19); + } + else + for (i=0; i>19); + uDest[2*i+1]= av_clip_uint8(u>>19); + } } #define YSCALE_YUV_2_PACKEDX_C(type) \ - for(i=0; i<(dstW>>1); i++){\ - int j;\ - int Y1=1<<18;\ - int Y2=1<<18;\ - int U=1<<18;\ - int V=1<<18;\ - type attribute_unused *r, *b, *g;\ - const int i2= 2*i;\ - \ - for(j=0; j>=19;\ - Y2>>=19;\ - U >>=19;\ - V >>=19;\ - if((Y1|Y2|U|V)&256)\ - {\ - if(Y1>255) Y1=255;\ - else if(Y1<0)Y1=0;\ - if(Y2>255) Y2=255;\ - else if(Y2<0)Y2=0;\ - if(U>255) U=255;\ - else if(U<0) U=0;\ - if(V>255) V=255;\ - else if(V<0) V=0;\ - } - + for (i=0; i<(dstW>>1); i++){\ + int j;\ + int Y1 = 1<<18;\ + int Y2 = 1<<18;\ + int U = 1<<18;\ + int V = 1<<18;\ + type av_unused *r, *b, *g;\ + const int i2= 2*i;\ + \ + for (j=0; j>=19;\ + Y2>>=19;\ + U >>=19;\ + V >>=19;\ + if ((Y1|Y2|U|V)&256)\ + {\ + if (Y1>255) Y1=255; \ + else if (Y1<0)Y1=0; \ + if (Y2>255) Y2=255; \ + else if (Y2<0)Y2=0; \ + if (U>255) U=255; \ + else if (U<0) U=0; \ + if (V>255) V=255; \ + else if (V<0) V=0; \ + } + #define YSCALE_YUV_2_RGBX_C(type) \ - YSCALE_YUV_2_PACKEDX_C(type)\ - r = (type *)c->table_rV[V];\ - g = (type *)(c->table_gU[U] + c->table_gV[V]);\ - b = (type *)c->table_bU[U];\ - -#define YSCALE_YUV_2_PACKED2_C \ - for(i=0; i<(dstW>>1); i++){\ - const int i2= 2*i;\ - int Y1= (buf0[i2 ]*yalpha1+buf1[i2 ]*yalpha)>>19;\ - int Y2= (buf0[i2+1]*yalpha1+buf1[i2+1]*yalpha)>>19;\ - int U= (uvbuf0[i ]*uvalpha1+uvbuf1[i ]*uvalpha)>>19;\ - int V= (uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19;\ + YSCALE_YUV_2_PACKEDX_C(type) \ + r = (type *)c->table_rV[V]; \ + g = (type *)(c->table_gU[U] + c->table_gV[V]); \ + b = (type *)c->table_bU[U]; \ + +#define YSCALE_YUV_2_PACKED2_C \ + for (i=0; i<(dstW>>1); i++){ \ + const int i2= 2*i; \ + int Y1= (buf0[i2 ]*yalpha1+buf1[i2 ]*yalpha)>>19; \ + int Y2= (buf0[i2+1]*yalpha1+buf1[i2+1]*yalpha)>>19; \ + int U= (uvbuf0[i ]*uvalpha1+uvbuf1[i ]*uvalpha)>>19; \ + int V= (uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19; \ #define YSCALE_YUV_2_RGB2_C(type) \ - YSCALE_YUV_2_PACKED2_C\ - type *r, *b, *g;\ - r = (type *)c->table_rV[V];\ - g = (type *)(c->table_gU[U] + c->table_gV[V]);\ - b = (type *)c->table_bU[U];\ + YSCALE_YUV_2_PACKED2_C\ + type *r, *b, *g;\ + r = (type *)c->table_rV[V];\ + g = (type *)(c->table_gU[U] + c->table_gV[V]);\ + b = (type *)c->table_bU[U];\ #define YSCALE_YUV_2_PACKED1_C \ - for(i=0; i<(dstW>>1); i++){\ - const int i2= 2*i;\ - int Y1= buf0[i2 ]>>7;\ - int Y2= buf0[i2+1]>>7;\ - int U= (uvbuf1[i ])>>7;\ - int V= (uvbuf1[i+2048])>>7;\ + for (i=0; i<(dstW>>1); i++){\ + const int i2= 2*i;\ + int Y1= buf0[i2 ]>>7;\ + int Y2= buf0[i2+1]>>7;\ + int U= (uvbuf1[i ])>>7;\ + int V= (uvbuf1[i+2048])>>7;\ #define YSCALE_YUV_2_RGB1_C(type) \ - YSCALE_YUV_2_PACKED1_C\ - type *r, *b, *g;\ - r = (type *)c->table_rV[V];\ - g = (type *)(c->table_gU[U] + c->table_gV[V]);\ - b = (type *)c->table_bU[U];\ + YSCALE_YUV_2_PACKED1_C\ + type *r, *b, *g;\ + r = (type *)c->table_rV[V];\ + g = (type *)(c->table_gU[U] + c->table_gV[V]);\ + b = (type *)c->table_bU[U];\ #define YSCALE_YUV_2_PACKED1B_C \ - for(i=0; i<(dstW>>1); i++){\ - const int i2= 2*i;\ - int Y1= buf0[i2 ]>>7;\ - int Y2= buf0[i2+1]>>7;\ - int U= (uvbuf0[i ] + uvbuf1[i ])>>8;\ - int V= (uvbuf0[i+2048] + uvbuf1[i+2048])>>8;\ + for (i=0; i<(dstW>>1); i++){\ + const int i2= 2*i;\ + int Y1= buf0[i2 ]>>7;\ + int Y2= buf0[i2+1]>>7;\ + int U= (uvbuf0[i ] + uvbuf1[i ])>>8;\ + int V= (uvbuf0[i+2048] + uvbuf1[i+2048])>>8;\ #define YSCALE_YUV_2_RGB1B_C(type) \ - YSCALE_YUV_2_PACKED1B_C\ - type *r, *b, *g;\ - r = (type *)c->table_rV[V];\ - g = (type *)(c->table_gU[U] + c->table_gV[V]);\ - b = (type *)c->table_bU[U];\ + YSCALE_YUV_2_PACKED1B_C\ + type *r, *b, *g;\ + r = (type *)c->table_rV[V];\ + g = (type *)(c->table_gU[U] + c->table_gV[V]);\ + b = (type *)c->table_bU[U];\ #define YSCALE_YUV_2_ANYRGB_C(func, func2)\ - switch(c->dstFormat)\ - {\ - case PIX_FMT_RGB32:\ - case PIX_FMT_BGR32:\ - func(uint32_t)\ - ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1];\ - ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2];\ - } \ - break;\ - case PIX_FMT_RGB24:\ - func(uint8_t)\ - ((uint8_t*)dest)[0]= r[Y1];\ - ((uint8_t*)dest)[1]= g[Y1];\ - ((uint8_t*)dest)[2]= b[Y1];\ - ((uint8_t*)dest)[3]= r[Y2];\ - ((uint8_t*)dest)[4]= g[Y2];\ - ((uint8_t*)dest)[5]= b[Y2];\ - dest+=6;\ - }\ - break;\ - case PIX_FMT_BGR24:\ - func(uint8_t)\ - ((uint8_t*)dest)[0]= b[Y1];\ - ((uint8_t*)dest)[1]= g[Y1];\ - ((uint8_t*)dest)[2]= r[Y1];\ - ((uint8_t*)dest)[3]= b[Y2];\ - ((uint8_t*)dest)[4]= g[Y2];\ - ((uint8_t*)dest)[5]= r[Y2];\ - dest+=6;\ - }\ - break;\ - case PIX_FMT_RGB565:\ - case PIX_FMT_BGR565:\ - {\ - const int dr1= dither_2x2_8[y&1 ][0];\ - const int dg1= dither_2x2_4[y&1 ][0];\ - const int db1= dither_2x2_8[(y&1)^1][0];\ - const int dr2= dither_2x2_8[y&1 ][1];\ - const int dg2= dither_2x2_4[y&1 ][1];\ - const int db2= dither_2x2_8[(y&1)^1][1];\ - func(uint16_t)\ - ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1];\ - ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2];\ - }\ - }\ - break;\ - case PIX_FMT_RGB555:\ - case PIX_FMT_BGR555:\ - {\ - const int dr1= dither_2x2_8[y&1 ][0];\ - const int dg1= dither_2x2_8[y&1 ][1];\ - const int db1= dither_2x2_8[(y&1)^1][0];\ - const int dr2= dither_2x2_8[y&1 ][1];\ - const int dg2= dither_2x2_8[y&1 ][0];\ - const int db2= dither_2x2_8[(y&1)^1][1];\ - func(uint16_t)\ - ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1];\ - ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2];\ - }\ - }\ - break;\ - case PIX_FMT_RGB8:\ - case PIX_FMT_BGR8:\ - {\ - const uint8_t * const d64= dither_8x8_73[y&7];\ - const uint8_t * const d32= dither_8x8_32[y&7];\ - func(uint8_t)\ - ((uint8_t*)dest)[i2+0]= r[Y1+d32[(i2+0)&7]] + g[Y1+d32[(i2+0)&7]] + b[Y1+d64[(i2+0)&7]];\ - ((uint8_t*)dest)[i2+1]= r[Y2+d32[(i2+1)&7]] + g[Y2+d32[(i2+1)&7]] + b[Y2+d64[(i2+1)&7]];\ - }\ - }\ - break;\ - case PIX_FMT_RGB4:\ - case PIX_FMT_BGR4:\ - {\ - const uint8_t * const d64= dither_8x8_73 [y&7];\ - const uint8_t * const d128=dither_8x8_220[y&7];\ - func(uint8_t)\ - ((uint8_t*)dest)[i]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]]\ - + ((r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]])<<4);\ - }\ - }\ - break;\ - case PIX_FMT_RGB4_BYTE:\ - case PIX_FMT_BGR4_BYTE:\ - {\ - const uint8_t * const d64= dither_8x8_73 [y&7];\ - const uint8_t * const d128=dither_8x8_220[y&7];\ - func(uint8_t)\ - ((uint8_t*)dest)[i2+0]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]];\ - ((uint8_t*)dest)[i2+1]= r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]];\ - }\ - }\ - break;\ - case PIX_FMT_MONOBLACK:\ - {\ - const uint8_t * const d128=dither_8x8_220[y&7];\ - uint8_t *g= c->table_gU[128] + c->table_gV[128];\ - for(i=0; i>19) + d128[0]];\ - acc+= acc + g[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19) + d128[1]];\ - acc+= acc + g[((buf0[i+2]*yalpha1+buf1[i+2]*yalpha)>>19) + d128[2]];\ - acc+= acc + g[((buf0[i+3]*yalpha1+buf1[i+3]*yalpha)>>19) + d128[3]];\ - acc+= acc + g[((buf0[i+4]*yalpha1+buf1[i+4]*yalpha)>>19) + d128[4]];\ - acc+= acc + g[((buf0[i+5]*yalpha1+buf1[i+5]*yalpha)>>19) + d128[5]];\ - acc+= acc + g[((buf0[i+6]*yalpha1+buf1[i+6]*yalpha)>>19) + d128[6]];\ - acc+= acc + g[((buf0[i+7]*yalpha1+buf1[i+7]*yalpha)>>19) + d128[7]];\ - ((uint8_t*)dest)[0]= acc;\ - dest++;\ - }\ + switch(c->dstFormat)\ + {\ + case PIX_FMT_RGB32:\ + case PIX_FMT_BGR32:\ + func(uint32_t)\ + ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1];\ + ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2];\ + } \ + break;\ + case PIX_FMT_RGB24:\ + func(uint8_t)\ + ((uint8_t*)dest)[0]= r[Y1];\ + ((uint8_t*)dest)[1]= g[Y1];\ + ((uint8_t*)dest)[2]= b[Y1];\ + ((uint8_t*)dest)[3]= r[Y2];\ + ((uint8_t*)dest)[4]= g[Y2];\ + ((uint8_t*)dest)[5]= b[Y2];\ + dest+=6;\ + }\ + break;\ + case PIX_FMT_BGR24:\ + func(uint8_t)\ + ((uint8_t*)dest)[0]= b[Y1];\ + ((uint8_t*)dest)[1]= g[Y1];\ + ((uint8_t*)dest)[2]= r[Y1];\ + ((uint8_t*)dest)[3]= b[Y2];\ + ((uint8_t*)dest)[4]= g[Y2];\ + ((uint8_t*)dest)[5]= r[Y2];\ + dest+=6;\ + }\ + break;\ + case PIX_FMT_RGB565:\ + case PIX_FMT_BGR565:\ + {\ + const int dr1= dither_2x2_8[y&1 ][0];\ + const int dg1= dither_2x2_4[y&1 ][0];\ + const int db1= dither_2x2_8[(y&1)^1][0];\ + const int dr2= dither_2x2_8[y&1 ][1];\ + const int dg2= dither_2x2_4[y&1 ][1];\ + const int db2= dither_2x2_8[(y&1)^1][1];\ + func(uint16_t)\ + ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1];\ + ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2];\ + }\ + }\ + break;\ + case PIX_FMT_RGB555:\ + case PIX_FMT_BGR555:\ + {\ + const int dr1= dither_2x2_8[y&1 ][0];\ + const int dg1= dither_2x2_8[y&1 ][1];\ + const int db1= dither_2x2_8[(y&1)^1][0];\ + const int dr2= dither_2x2_8[y&1 ][1];\ + const int dg2= dither_2x2_8[y&1 ][0];\ + const int db2= dither_2x2_8[(y&1)^1][1];\ + func(uint16_t)\ + ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1];\ + ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2];\ + }\ + }\ + break;\ + case PIX_FMT_RGB8:\ + case PIX_FMT_BGR8:\ + {\ + const uint8_t * const d64= dither_8x8_73[y&7];\ + const uint8_t * const d32= dither_8x8_32[y&7];\ + func(uint8_t)\ + ((uint8_t*)dest)[i2+0]= r[Y1+d32[(i2+0)&7]] + g[Y1+d32[(i2+0)&7]] + b[Y1+d64[(i2+0)&7]];\ + ((uint8_t*)dest)[i2+1]= r[Y2+d32[(i2+1)&7]] + g[Y2+d32[(i2+1)&7]] + b[Y2+d64[(i2+1)&7]];\ + }\ + }\ + break;\ + case PIX_FMT_RGB4:\ + case PIX_FMT_BGR4:\ + {\ + const uint8_t * const d64= dither_8x8_73 [y&7];\ + const uint8_t * const d128=dither_8x8_220[y&7];\ + func(uint8_t)\ + ((uint8_t*)dest)[i]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]]\ + + ((r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]])<<4);\ + }\ + }\ + break;\ + case PIX_FMT_RGB4_BYTE:\ + case PIX_FMT_BGR4_BYTE:\ + {\ + const uint8_t * const d64= dither_8x8_73 [y&7];\ + const uint8_t * const d128=dither_8x8_220[y&7];\ + func(uint8_t)\ + ((uint8_t*)dest)[i2+0]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]];\ + ((uint8_t*)dest)[i2+1]= r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]];\ + }\ + }\ + break;\ + case PIX_FMT_MONOBLACK:\ + {\ + const uint8_t * const d128=dither_8x8_220[y&7];\ + uint8_t *g= c->table_gU[128] + c->table_gV[128];\ + for (i=0; i>19) + d128[0]];\ + acc+= acc + g[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19) + d128[1]];\ + acc+= acc + g[((buf0[i+2]*yalpha1+buf1[i+2]*yalpha)>>19) + d128[2]];\ + acc+= acc + g[((buf0[i+3]*yalpha1+buf1[i+3]*yalpha)>>19) + d128[3]];\ + acc+= acc + g[((buf0[i+4]*yalpha1+buf1[i+4]*yalpha)>>19) + d128[4]];\ + acc+= acc + g[((buf0[i+5]*yalpha1+buf1[i+5]*yalpha)>>19) + d128[5]];\ + acc+= acc + g[((buf0[i+6]*yalpha1+buf1[i+6]*yalpha)>>19) + d128[6]];\ + acc+= acc + g[((buf0[i+7]*yalpha1+buf1[i+7]*yalpha)>>19) + d128[7]];\ + ((uint8_t*)dest)[0]= acc;\ + dest++;\ + }\ \ /*\ ((uint8_t*)dest)-= dstW>>4;\ {\ - int acc=0;\ - int left=0;\ - static int top[1024];\ - static int last_new[1024][1024];\ - static int last_in3[1024][1024];\ - static int drift[1024][1024];\ - int topLeft=0;\ - int shift=0;\ - int count=0;\ - const uint8_t * const d128=dither_8x8_220[y&7];\ - int error_new=0;\ - int error_in3=0;\ - int f=0;\ - \ - for(i=dstW>>1; i>19);\ - int in2 = (76309 * (in - 16) + 32768) >> 16;\ - int in3 = (in2 < 0) ? 0 : ((in2 > 255) ? 255 : in2);\ - int old= (left*7 + topLeft + top[i]*5 + top[i+1]*3)/20 + in3\ - + (last_new[y][i] - in3)*f/256;\ - int new= old> 128 ? 255 : 0;\ + int acc=0;\ + int left=0;\ + static int top[1024];\ + static int last_new[1024][1024];\ + static int last_in3[1024][1024];\ + static int drift[1024][1024];\ + int topLeft=0;\ + int shift=0;\ + int count=0;\ + const uint8_t * const d128=dither_8x8_220[y&7];\ + int error_new=0;\ + int error_in3=0;\ + int f=0;\ + \ + for (i=dstW>>1; i>19);\ + int in2 = (76309 * (in - 16) + 32768) >> 16;\ + int in3 = (in2 < 0) ? 0 : ((in2 > 255) ? 255 : in2);\ + int old= (left*7 + topLeft + top[i]*5 + top[i+1]*3)/20 + in3\ + + (last_new[y][i] - in3)*f/256;\ + int new= old> 128 ? 255 : 0;\ \ - error_new+= FFABS(last_new[y][i] - new);\ - error_in3+= FFABS(last_in3[y][i] - in3);\ - f= error_new - error_in3*4;\ - if(f<0) f=0;\ - if(f>256) f=256;\ + error_new+= FFABS(last_new[y][i] - new);\ + error_in3+= FFABS(last_in3[y][i] - in3);\ + f= error_new - error_in3*4;\ + if (f<0) f=0;\ + if (f>256) f=256;\ \ - topLeft= top[i];\ - left= top[i]= old - new;\ - last_new[y][i]= new;\ - last_in3[y][i]= in3;\ + topLeft= top[i];\ + left= top[i]= old - new;\ + last_new[y][i]= new;\ + last_in3[y][i]= in3;\ \ - acc+= acc + (new&1);\ - if((i&7)==6){\ - ((uint8_t*)dest)[0]= acc;\ - ((uint8_t*)dest)++;\ - }\ - }\ + acc+= acc + (new&1);\ + if ((i&7)==6){\ + ((uint8_t*)dest)[0]= acc;\ + ((uint8_t*)dest)++;\ + }\ + }\ }\ */\ - }\ - break;\ - case PIX_FMT_YUYV422:\ - func2\ - ((uint8_t*)dest)[2*i2+0]= Y1;\ - ((uint8_t*)dest)[2*i2+1]= U;\ - ((uint8_t*)dest)[2*i2+2]= Y2;\ - ((uint8_t*)dest)[2*i2+3]= V;\ - } \ - break;\ - case PIX_FMT_UYVY422:\ - func2\ - ((uint8_t*)dest)[2*i2+0]= U;\ - ((uint8_t*)dest)[2*i2+1]= Y1;\ - ((uint8_t*)dest)[2*i2+2]= V;\ - ((uint8_t*)dest)[2*i2+3]= Y2;\ - } \ - break;\ - }\ + }\ + break;\ + case PIX_FMT_YUYV422:\ + func2\ + ((uint8_t*)dest)[2*i2+0]= Y1;\ + ((uint8_t*)dest)[2*i2+1]= U;\ + ((uint8_t*)dest)[2*i2+2]= Y2;\ + ((uint8_t*)dest)[2*i2+3]= V;\ + } \ + break;\ + case PIX_FMT_UYVY422:\ + func2\ + ((uint8_t*)dest)[2*i2+0]= U;\ + ((uint8_t*)dest)[2*i2+1]= Y1;\ + ((uint8_t*)dest)[2*i2+2]= V;\ + ((uint8_t*)dest)[2*i2+3]= Y2;\ + } \ + break;\ + }\ static inline void yuv2packedXinC(SwsContext *c, int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize, - int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, - uint8_t *dest, int dstW, int y) + int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, + uint8_t *dest, int dstW, int y) { - int i; - switch(c->dstFormat) - { - case PIX_FMT_BGR32: - case PIX_FMT_RGB32: - YSCALE_YUV_2_RGBX_C(uint32_t) - ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1]; - ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2]; - } - break; - case PIX_FMT_RGB24: - YSCALE_YUV_2_RGBX_C(uint8_t) - ((uint8_t*)dest)[0]= r[Y1]; - ((uint8_t*)dest)[1]= g[Y1]; - ((uint8_t*)dest)[2]= b[Y1]; - ((uint8_t*)dest)[3]= r[Y2]; - ((uint8_t*)dest)[4]= g[Y2]; - ((uint8_t*)dest)[5]= b[Y2]; - dest+=6; - } - break; - case PIX_FMT_BGR24: - YSCALE_YUV_2_RGBX_C(uint8_t) - ((uint8_t*)dest)[0]= b[Y1]; - ((uint8_t*)dest)[1]= g[Y1]; - ((uint8_t*)dest)[2]= r[Y1]; - ((uint8_t*)dest)[3]= b[Y2]; - ((uint8_t*)dest)[4]= g[Y2]; - ((uint8_t*)dest)[5]= r[Y2]; - dest+=6; - } - break; - case PIX_FMT_RGB565: - case PIX_FMT_BGR565: - { - const int dr1= dither_2x2_8[y&1 ][0]; - const int dg1= dither_2x2_4[y&1 ][0]; - const int db1= dither_2x2_8[(y&1)^1][0]; - const int dr2= dither_2x2_8[y&1 ][1]; - const int dg2= dither_2x2_4[y&1 ][1]; - const int db2= dither_2x2_8[(y&1)^1][1]; - YSCALE_YUV_2_RGBX_C(uint16_t) - ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1]; - ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2]; - } - } - break; - case PIX_FMT_RGB555: - case PIX_FMT_BGR555: - { - const int dr1= dither_2x2_8[y&1 ][0]; - const int dg1= dither_2x2_8[y&1 ][1]; - const int db1= dither_2x2_8[(y&1)^1][0]; - const int dr2= dither_2x2_8[y&1 ][1]; - const int dg2= dither_2x2_8[y&1 ][0]; - const int db2= dither_2x2_8[(y&1)^1][1]; - YSCALE_YUV_2_RGBX_C(uint16_t) - ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1]; - ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2]; - } - } - break; - case PIX_FMT_RGB8: - case PIX_FMT_BGR8: - { - const uint8_t * const d64= dither_8x8_73[y&7]; - const uint8_t * const d32= dither_8x8_32[y&7]; - YSCALE_YUV_2_RGBX_C(uint8_t) - ((uint8_t*)dest)[i2+0]= r[Y1+d32[(i2+0)&7]] + g[Y1+d32[(i2+0)&7]] + b[Y1+d64[(i2+0)&7]]; - ((uint8_t*)dest)[i2+1]= r[Y2+d32[(i2+1)&7]] + g[Y2+d32[(i2+1)&7]] + b[Y2+d64[(i2+1)&7]]; - } - } - break; - case PIX_FMT_RGB4: - case PIX_FMT_BGR4: - { - const uint8_t * const d64= dither_8x8_73 [y&7]; - const uint8_t * const d128=dither_8x8_220[y&7]; - YSCALE_YUV_2_RGBX_C(uint8_t) - ((uint8_t*)dest)[i]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]] - +((r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]])<<4); - } - } - break; - case PIX_FMT_RGB4_BYTE: - case PIX_FMT_BGR4_BYTE: - { - const uint8_t * const d64= dither_8x8_73 [y&7]; - const uint8_t * const d128=dither_8x8_220[y&7]; - YSCALE_YUV_2_RGBX_C(uint8_t) - ((uint8_t*)dest)[i2+0]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]]; - ((uint8_t*)dest)[i2+1]= r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]]; - } - } - break; - case PIX_FMT_MONOBLACK: - { - const uint8_t * const d128=dither_8x8_220[y&7]; - uint8_t *g= c->table_gU[128] + c->table_gV[128]; - int acc=0; - for(i=0; i>=19; - Y2>>=19; - if((Y1|Y2)&256) - { - if(Y1>255) Y1=255; - else if(Y1<0)Y1=0; - if(Y2>255) Y2=255; - else if(Y2<0)Y2=0; - } - acc+= acc + g[Y1+d128[(i+0)&7]]; - acc+= acc + g[Y2+d128[(i+1)&7]]; - if((i&7)==6){ - ((uint8_t*)dest)[0]= acc; - dest++; - } - } - } - break; - case PIX_FMT_YUYV422: - YSCALE_YUV_2_PACKEDX_C(void) - ((uint8_t*)dest)[2*i2+0]= Y1; - ((uint8_t*)dest)[2*i2+1]= U; - ((uint8_t*)dest)[2*i2+2]= Y2; - ((uint8_t*)dest)[2*i2+3]= V; - } - break; - case PIX_FMT_UYVY422: - YSCALE_YUV_2_PACKEDX_C(void) - ((uint8_t*)dest)[2*i2+0]= U; - ((uint8_t*)dest)[2*i2+1]= Y1; - ((uint8_t*)dest)[2*i2+2]= V; - ((uint8_t*)dest)[2*i2+3]= Y2; - } - break; - } + int i; + switch(c->dstFormat) + { + case PIX_FMT_BGR32: + case PIX_FMT_RGB32: + YSCALE_YUV_2_RGBX_C(uint32_t) + ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1]; + ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2]; + } + break; + case PIX_FMT_RGB24: + YSCALE_YUV_2_RGBX_C(uint8_t) + ((uint8_t*)dest)[0]= r[Y1]; + ((uint8_t*)dest)[1]= g[Y1]; + ((uint8_t*)dest)[2]= b[Y1]; + ((uint8_t*)dest)[3]= r[Y2]; + ((uint8_t*)dest)[4]= g[Y2]; + ((uint8_t*)dest)[5]= b[Y2]; + dest+=6; + } + break; + case PIX_FMT_BGR24: + YSCALE_YUV_2_RGBX_C(uint8_t) + ((uint8_t*)dest)[0]= b[Y1]; + ((uint8_t*)dest)[1]= g[Y1]; + ((uint8_t*)dest)[2]= r[Y1]; + ((uint8_t*)dest)[3]= b[Y2]; + ((uint8_t*)dest)[4]= g[Y2]; + ((uint8_t*)dest)[5]= r[Y2]; + dest+=6; + } + break; + case PIX_FMT_RGB565: + case PIX_FMT_BGR565: + { + const int dr1= dither_2x2_8[y&1 ][0]; + const int dg1= dither_2x2_4[y&1 ][0]; + const int db1= dither_2x2_8[(y&1)^1][0]; + const int dr2= dither_2x2_8[y&1 ][1]; + const int dg2= dither_2x2_4[y&1 ][1]; + const int db2= dither_2x2_8[(y&1)^1][1]; + YSCALE_YUV_2_RGBX_C(uint16_t) + ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1]; + ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2]; + } + } + break; + case PIX_FMT_RGB555: + case PIX_FMT_BGR555: + { + const int dr1= dither_2x2_8[y&1 ][0]; + const int dg1= dither_2x2_8[y&1 ][1]; + const int db1= dither_2x2_8[(y&1)^1][0]; + const int dr2= dither_2x2_8[y&1 ][1]; + const int dg2= dither_2x2_8[y&1 ][0]; + const int db2= dither_2x2_8[(y&1)^1][1]; + YSCALE_YUV_2_RGBX_C(uint16_t) + ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1]; + ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2]; + } + } + break; + case PIX_FMT_RGB8: + case PIX_FMT_BGR8: + { + const uint8_t * const d64= dither_8x8_73[y&7]; + const uint8_t * const d32= dither_8x8_32[y&7]; + YSCALE_YUV_2_RGBX_C(uint8_t) + ((uint8_t*)dest)[i2+0]= r[Y1+d32[(i2+0)&7]] + g[Y1+d32[(i2+0)&7]] + b[Y1+d64[(i2+0)&7]]; + ((uint8_t*)dest)[i2+1]= r[Y2+d32[(i2+1)&7]] + g[Y2+d32[(i2+1)&7]] + b[Y2+d64[(i2+1)&7]]; + } + } + break; + case PIX_FMT_RGB4: + case PIX_FMT_BGR4: + { + const uint8_t * const d64= dither_8x8_73 [y&7]; + const uint8_t * const d128=dither_8x8_220[y&7]; + YSCALE_YUV_2_RGBX_C(uint8_t) + ((uint8_t*)dest)[i]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]] + +((r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]])<<4); + } + } + break; + case PIX_FMT_RGB4_BYTE: + case PIX_FMT_BGR4_BYTE: + { + const uint8_t * const d64= dither_8x8_73 [y&7]; + const uint8_t * const d128=dither_8x8_220[y&7]; + YSCALE_YUV_2_RGBX_C(uint8_t) + ((uint8_t*)dest)[i2+0]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]]; + ((uint8_t*)dest)[i2+1]= r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]]; + } + } + break; + case PIX_FMT_MONOBLACK: + { + const uint8_t * const d128=dither_8x8_220[y&7]; + uint8_t *g= c->table_gU[128] + c->table_gV[128]; + int acc=0; + for (i=0; i>=19; + Y2>>=19; + if ((Y1|Y2)&256) + { + if (Y1>255) Y1=255; + else if (Y1<0)Y1=0; + if (Y2>255) Y2=255; + else if (Y2<0)Y2=0; + } + acc+= acc + g[Y1+d128[(i+0)&7]]; + acc+= acc + g[Y2+d128[(i+1)&7]]; + if ((i&7)==6){ + ((uint8_t*)dest)[0]= acc; + dest++; + } + } + } + break; + case PIX_FMT_YUYV422: + YSCALE_YUV_2_PACKEDX_C(void) + ((uint8_t*)dest)[2*i2+0]= Y1; + ((uint8_t*)dest)[2*i2+1]= U; + ((uint8_t*)dest)[2*i2+2]= Y2; + ((uint8_t*)dest)[2*i2+3]= V; + } + break; + case PIX_FMT_UYVY422: + YSCALE_YUV_2_PACKEDX_C(void) + ((uint8_t*)dest)[2*i2+0]= U; + ((uint8_t*)dest)[2*i2+1]= Y1; + ((uint8_t*)dest)[2*i2+2]= V; + ((uint8_t*)dest)[2*i2+3]= Y2; + } + break; + } } @@ -902,1630 +970,1674 @@ static inline void yuv2packedXinC(SwsContext *c, int16_t *lumFilter, int16_t **l static double getSplineCoeff(double a, double b, double c, double d, double dist) { -// printf("%f %f %f %f %f\n", a,b,c,d,dist); - if(dist<=1.0) return ((d*dist + c)*dist + b)*dist +a; - else return getSplineCoeff( 0.0, - b+ 2.0*c + 3.0*d, - c + 3.0*d, - -b- 3.0*c - 6.0*d, - dist-1.0); +// printf("%f %f %f %f %f\n", a,b,c,d,dist); + if (dist<=1.0) return ((d*dist + c)*dist + b)*dist +a; + else return getSplineCoeff( 0.0, + b+ 2.0*c + 3.0*d, + c + 3.0*d, + -b- 3.0*c - 6.0*d, + dist-1.0); } static inline int initFilter(int16_t **outFilter, int16_t **filterPos, int *outFilterSize, int xInc, - int srcW, int dstW, int filterAlign, int one, int flags, - SwsVector *srcFilter, SwsVector *dstFilter, double param[2]) + int srcW, int dstW, int filterAlign, int one, int flags, + SwsVector *srcFilter, SwsVector *dstFilter, double param[2]) { - int i; - int filterSize; - int filter2Size; - int minFilterSize; - double *filter=NULL; - double *filter2=NULL; + int i; + int filterSize; + int filter2Size; + int minFilterSize; + double *filter=NULL; + double *filter2=NULL; #if defined(ARCH_X86) - if(flags & SWS_CPU_CAPS_MMX) - asm volatile("emms\n\t"::: "memory"); //FIXME this shouldnt be required but it IS (even for non mmx versions) + if (flags & SWS_CPU_CAPS_MMX) + asm volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions) #endif - // Note the +1 is for the MMXscaler which reads over the end - *filterPos = av_malloc((dstW+1)*sizeof(int16_t)); - - if(FFABS(xInc - 0x10000) <10) // unscaled - { - int i; - filterSize= 1; - filter= av_malloc(dstW*sizeof(double)*filterSize); - for(i=0; i>16; - - (*filterPos)[i]= xx; - filter[i]= 1.0; - xDstInSrc+= xInc; - } - } - else if((xInc <= (1<<16) && (flags&SWS_AREA)) || (flags&SWS_FAST_BILINEAR)) // bilinear upscale - { - int i; - int xDstInSrc; - if (flags&SWS_BICUBIC) filterSize= 4; - else if(flags&SWS_X ) filterSize= 4; - else filterSize= 2; // SWS_BILINEAR / SWS_AREA - filter= av_malloc(dstW*sizeof(double)*filterSize); - - xDstInSrc= xInc/2 - 0x8000; - for(i=0; i>16; - int j; - - (*filterPos)[i]= xx; - //Bilinear upscale / linear interpolate / Area averaging - for(j=0; j srcW-2) filterSize=srcW-2; - - filter= av_malloc(dstW*sizeof(double)*filterSize); - - xDstInSrc= xInc1 / 2.0 - 0.5; - for(i=0; ip) coeff=0; - } - else if(flags & SWS_BILINEAR) - { - coeff= 1.0 - d; - if(coeff<0) coeff=0; - } - else if(flags & SWS_SPLINE) - { - double p=-2.196152422706632; - coeff = getSplineCoeff(1.0, 0.0, p, -p-1.0, d); - } - else { - coeff= 0.0; //GCC warning killer - ASSERT(0) - } - - filter[i*filterSize + j]= coeff; - xx++; - } - xDstInSrc+= xInc1; - } - } - - /* apply src & dst Filter to filter -> filter2 - av_free(filter); - */ - ASSERT(filterSize>0) - filter2Size= filterSize; - if(srcFilter) filter2Size+= srcFilter->length - 1; - if(dstFilter) filter2Size+= dstFilter->length - 1; - ASSERT(filter2Size>0) - filter2= av_malloc(filter2Size*dstW*sizeof(double)); - - for(i=0; ilength == filter2Size) - //FIXME dstFilter - - for(j=0; jlength; j++) - { - filter2[i*filter2Size + j]= outVec->coeff[j]; - } - - (*filterPos)[i]+= (filterSize-1)/2 - (filter2Size-1)/2; - - if(outVec != &scaleFilter) sws_freeVec(outVec); - } - av_free(filter); filter=NULL; - - /* try to reduce the filter-size (step1 find size and shift left) */ - // Assume its near normalized (*0.5 or *2.0 is ok but * 0.001 is not) - minFilterSize= 0; - for(i=dstW-1; i>=0; i--) - { - int min= filter2Size; - int j; - double cutOff=0.0; - - /* get rid off near zero elements on the left by shifting left */ - for(j=0; j SWS_MAX_REDUCE_CUTOFF) break; - - /* preserve Monotonicity because the core can't handle the filter otherwise */ - if(i= (*filterPos)[i+1]) break; - - // Move filter coeffs left - for(k=1; k0; j--) - { - cutOff += FFABS(filter2[i*filter2Size + j]); - - if(cutOff > SWS_MAX_REDUCE_CUTOFF) break; - min--; - } - - if(min>minFilterSize) minFilterSize= min; - } - - if (flags & SWS_CPU_CAPS_ALTIVEC) { - // we can handle the special case 4, - // so we don't want to go to the full 8 - if (minFilterSize < 5) + // Note the +1 is for the MMXscaler which reads over the end + *filterPos = av_malloc((dstW+1)*sizeof(int16_t)); + + if (FFABS(xInc - 0x10000) <10) // unscaled + { + int i; + filterSize= 1; + filter= av_malloc(dstW*sizeof(double)*filterSize); + for (i=0; i>16; + + (*filterPos)[i]= xx; + filter[i]= 1.0; + xDstInSrc+= xInc; + } + } + else if ((xInc <= (1<<16) && (flags&SWS_AREA)) || (flags&SWS_FAST_BILINEAR)) // bilinear upscale + { + int i; + int xDstInSrc; + if (flags&SWS_BICUBIC) filterSize= 4; + else if (flags&SWS_X ) filterSize= 4; + else filterSize= 2; // SWS_BILINEAR / SWS_AREA + filter= av_malloc(dstW*sizeof(double)*filterSize); + + xDstInSrc= xInc/2 - 0x8000; + for (i=0; i>16; + int j; + + (*filterPos)[i]= xx; + //Bilinear upscale / linear interpolate / Area averaging + for (j=0; j srcW-2) filterSize=srcW-2; + + filter= av_malloc(dstW*sizeof(double)*filterSize); + + xDstInSrc= xInc1 / 2.0 - 0.5; + for (i=0; ip) coeff=0; + } + else if (flags & SWS_BILINEAR) + { + coeff= 1.0 - d; + if (coeff<0) coeff=0; + } + else if (flags & SWS_SPLINE) + { + double p=-2.196152422706632; + coeff = getSplineCoeff(1.0, 0.0, p, -p-1.0, d); + } + else { + coeff= 0.0; //GCC warning killer + ASSERT(0) + } + + filter[i*filterSize + j]= coeff; + xx++; + } + xDstInSrc+= xInc1; + } + } + + /* apply src & dst Filter to filter -> filter2 + av_free(filter); + */ + ASSERT(filterSize>0) + filter2Size= filterSize; + if (srcFilter) filter2Size+= srcFilter->length - 1; + if (dstFilter) filter2Size+= dstFilter->length - 1; + ASSERT(filter2Size>0) + filter2= av_malloc(filter2Size*dstW*sizeof(double)); + + for (i=0; ilength == filter2Size) + //FIXME dstFilter + + for (j=0; jlength; j++) + { + filter2[i*filter2Size + j]= outVec->coeff[j]; + } + + (*filterPos)[i]+= (filterSize-1)/2 - (filter2Size-1)/2; + + if (outVec != &scaleFilter) sws_freeVec(outVec); + } + av_free(filter); filter=NULL; + + /* try to reduce the filter-size (step1 find size and shift left) */ + // Assume it is near normalized (*0.5 or *2.0 is OK but * 0.001 is not). + minFilterSize= 0; + for (i=dstW-1; i>=0; i--) + { + int min= filter2Size; + int j; + double cutOff=0.0; + + /* get rid off near zero elements on the left by shifting left */ + for (j=0; j SWS_MAX_REDUCE_CUTOFF) break; + + /* preserve monotonicity because the core can't handle the filter otherwise */ + if (i= (*filterPos)[i+1]) break; + + // Move filter coeffs left + for (k=1; k0; j--) + { + cutOff += FFABS(filter2[i*filter2Size + j]); + + if (cutOff > SWS_MAX_REDUCE_CUTOFF) break; + min--; + } + + if (min>minFilterSize) minFilterSize= min; + } + + if (flags & SWS_CPU_CAPS_ALTIVEC) { + // we can handle the special case 4, + // so we don't want to go to the full 8 + if (minFilterSize < 5) filterAlign = 4; - // we really don't want to waste our time - // doing useless computation, so fall-back on - // the scalar C code for very small filter. - // vectorizing is worth it only if you have - // decent-sized vector. - if (minFilterSize < 3) + // we really don't want to waste our time + // doing useless computation, so fall-back on + // the scalar C code for very small filter. + // vectorizing is worth it only if you have + // decent-sized vector. + if (minFilterSize < 3) filterAlign = 1; + } + + if (flags & SWS_CPU_CAPS_MMX) { + // special case for unscaled vertical filtering + if (minFilterSize == 1 && filterAlign == 2) + filterAlign= 1; + } + + ASSERT(minFilterSize > 0) + filterSize= (minFilterSize +(filterAlign-1)) & (~(filterAlign-1)); + ASSERT(filterSize > 0) + filter= av_malloc(filterSize*dstW*sizeof(double)); + if (filterSize >= MAX_FILTER_SIZE) + return -1; + *outFilterSize= filterSize; + + if (flags&SWS_PRINT_INFO) + av_log(NULL, AV_LOG_VERBOSE, "SwScaler: reducing / aligning filtersize %d -> %d\n", filter2Size, filterSize); + /* try to reduce the filter-size (step2 reduce it) */ + for (i=0; i=filter2Size) filter[i*filterSize + j]= 0.0; + else filter[i*filterSize + j]= filter2[i*filter2Size + j]; + } + } + av_free(filter2); filter2=NULL; + + + //FIXME try to align filterpos if possible + + //fix borders + for (i=0; i srcW) + { + int shift= (*filterPos)[i] + filterSize - srcW; + // Move filter coeffs right to compensate for filterPos + for (j=filterSize-2; j>=0; j--) + { + int right= FFMIN(j + shift, filterSize-1); + filter[i*filterSize +right] += filter[i*filterSize +j]; + filter[i*filterSize +j]=0; + } + (*filterPos)[i]= srcW - filterSize; } + } - ASSERT(minFilterSize > 0) - filterSize= (minFilterSize +(filterAlign-1)) & (~(filterAlign-1)); - ASSERT(filterSize > 0) - filter= av_malloc(filterSize*dstW*sizeof(double)); - if(filterSize >= MAX_FILTER_SIZE) - return -1; - *outFilterSize= filterSize; - - if(flags&SWS_PRINT_INFO) - av_log(NULL, AV_LOG_VERBOSE, "SwScaler: reducing / aligning filtersize %d -> %d\n", filter2Size, filterSize); - /* try to reduce the filter-size (step2 reduce it) */ - for(i=0; i=filter2Size) filter[i*filterSize + j]= 0.0; - else filter[i*filterSize + j]= filter2[i*filter2Size + j]; - } - } - av_free(filter2); filter2=NULL; - - - //FIXME try to align filterpos if possible - - //fix borders - for(i=0; i srcW) - { - int shift= (*filterPos)[i] + filterSize - srcW; - // Move filter coeffs right to compensate for filterPos - for(j=filterSize-2; j>=0; j--) - { - int right= FFMIN(j + shift, filterSize-1); - filter[i*filterSize +right] += filter[i*filterSize +j]; - filter[i*filterSize +j]=0; - } - (*filterPos)[i]= srcW - filterSize; - } - } - - // Note the +1 is for the MMXscaler which reads over the end - /* align at 16 for AltiVec (needed by hScale_altivec_real) */ - *outFilter= av_mallocz(*outFilterSize*(dstW+1)*sizeof(int16_t)); - - /* Normalize & Store in outFilter */ - for(i=0; i>16; - - if((i&3) == 0) - { - int a=0; - int b=((xpos+xInc)>>16) - xx; - int c=((xpos+xInc*2)>>16) - xx; - int d=((xpos+xInc*3)>>16) - xx; - - filter[i ] = (( xpos & 0xFFFF) ^ 0xFFFF)>>9; - filter[i+1] = (((xpos+xInc ) & 0xFFFF) ^ 0xFFFF)>>9; - filter[i+2] = (((xpos+xInc*2) & 0xFFFF) ^ 0xFFFF)>>9; - filter[i+3] = (((xpos+xInc*3) & 0xFFFF) ^ 0xFFFF)>>9; - filterPos[i/2]= xx; - - if(d+1<4) - { - int maxShift= 3-(d+1); - int shift=0; - - memcpy(funnyCode + fragmentPos, fragmentB, fragmentLengthB); - - funnyCode[fragmentPos + imm8OfPShufW1B]= - (a+1) | ((b+1)<<2) | ((c+1)<<4) | ((d+1)<<6); - funnyCode[fragmentPos + imm8OfPShufW2B]= - a | (b<<2) | (c<<4) | (d<<6); - - if(i+3>=dstW) shift=maxShift; //avoid overread - else if((filterPos[i/2]&3) <= maxShift) shift=filterPos[i/2]&3; //Align - - if(shift && i>=shift) - { - funnyCode[fragmentPos + imm8OfPShufW1B]+= 0x55*shift; - funnyCode[fragmentPos + imm8OfPShufW2B]+= 0x55*shift; - filterPos[i/2]-=shift; - } - - fragmentPos+= fragmentLengthB; - } - else - { - int maxShift= 3-d; - int shift=0; - - memcpy(funnyCode + fragmentPos, fragmentA, fragmentLengthA); - - funnyCode[fragmentPos + imm8OfPShufW1A]= - funnyCode[fragmentPos + imm8OfPShufW2A]= - a | (b<<2) | (c<<4) | (d<<6); - - if(i+4>=dstW) shift=maxShift; //avoid overread - else if((filterPos[i/2]&3) <= maxShift) shift=filterPos[i/2]&3; //partial align - - if(shift && i>=shift) - { - funnyCode[fragmentPos + imm8OfPShufW1A]+= 0x55*shift; - funnyCode[fragmentPos + imm8OfPShufW2A]+= 0x55*shift; - filterPos[i/2]-=shift; - } - - fragmentPos+= fragmentLengthA; - } - - funnyCode[fragmentPos]= RET; - } - xpos+=xInc; - } - filterPos[i/2]= xpos>>16; // needed to jump to the next part + uint8_t *fragmentA; + long imm8OfPShufW1A; + long imm8OfPShufW2A; + long fragmentLengthA; + uint8_t *fragmentB; + long imm8OfPShufW1B; + long imm8OfPShufW2B; + long fragmentLengthB; + int fragmentPos; + + int xpos, i; + + // create an optimized horizontal scaling routine + + //code fragment + + asm volatile( + "jmp 9f \n\t" + // Begin + "0: \n\t" + "movq (%%"REG_d", %%"REG_a"), %%mm3 \n\t" + "movd (%%"REG_c", %%"REG_S"), %%mm0 \n\t" + "movd 1(%%"REG_c", %%"REG_S"), %%mm1 \n\t" + "punpcklbw %%mm7, %%mm1 \n\t" + "punpcklbw %%mm7, %%mm0 \n\t" + "pshufw $0xFF, %%mm1, %%mm1 \n\t" + "1: \n\t" + "pshufw $0xFF, %%mm0, %%mm0 \n\t" + "2: \n\t" + "psubw %%mm1, %%mm0 \n\t" + "movl 8(%%"REG_b", %%"REG_a"), %%esi \n\t" + "pmullw %%mm3, %%mm0 \n\t" + "psllw $7, %%mm1 \n\t" + "paddw %%mm1, %%mm0 \n\t" + + "movq %%mm0, (%%"REG_D", %%"REG_a") \n\t" + + "add $8, %%"REG_a" \n\t" + // End + "9: \n\t" +// "int $3 \n\t" + "lea 0b, %0 \n\t" + "lea 1b, %1 \n\t" + "lea 2b, %2 \n\t" + "dec %1 \n\t" + "dec %2 \n\t" + "sub %0, %1 \n\t" + "sub %0, %2 \n\t" + "lea 9b, %3 \n\t" + "sub %0, %3 \n\t" + + + :"=r" (fragmentA), "=r" (imm8OfPShufW1A), "=r" (imm8OfPShufW2A), + "=r" (fragmentLengthA) + ); + + asm volatile( + "jmp 9f \n\t" + // Begin + "0: \n\t" + "movq (%%"REG_d", %%"REG_a"), %%mm3 \n\t" + "movd (%%"REG_c", %%"REG_S"), %%mm0 \n\t" + "punpcklbw %%mm7, %%mm0 \n\t" + "pshufw $0xFF, %%mm0, %%mm1 \n\t" + "1: \n\t" + "pshufw $0xFF, %%mm0, %%mm0 \n\t" + "2: \n\t" + "psubw %%mm1, %%mm0 \n\t" + "movl 8(%%"REG_b", %%"REG_a"), %%esi \n\t" + "pmullw %%mm3, %%mm0 \n\t" + "psllw $7, %%mm1 \n\t" + "paddw %%mm1, %%mm0 \n\t" + + "movq %%mm0, (%%"REG_D", %%"REG_a") \n\t" + + "add $8, %%"REG_a" \n\t" + // End + "9: \n\t" +// "int $3 \n\t" + "lea 0b, %0 \n\t" + "lea 1b, %1 \n\t" + "lea 2b, %2 \n\t" + "dec %1 \n\t" + "dec %2 \n\t" + "sub %0, %1 \n\t" + "sub %0, %2 \n\t" + "lea 9b, %3 \n\t" + "sub %0, %3 \n\t" + + + :"=r" (fragmentB), "=r" (imm8OfPShufW1B), "=r" (imm8OfPShufW2B), + "=r" (fragmentLengthB) + ); + + xpos= 0; //lumXInc/2 - 0x8000; // difference between pixel centers + fragmentPos=0; + + for (i=0; i>16; + + if ((i&3) == 0) + { + int a=0; + int b=((xpos+xInc)>>16) - xx; + int c=((xpos+xInc*2)>>16) - xx; + int d=((xpos+xInc*3)>>16) - xx; + + filter[i ] = (( xpos & 0xFFFF) ^ 0xFFFF)>>9; + filter[i+1] = (((xpos+xInc ) & 0xFFFF) ^ 0xFFFF)>>9; + filter[i+2] = (((xpos+xInc*2) & 0xFFFF) ^ 0xFFFF)>>9; + filter[i+3] = (((xpos+xInc*3) & 0xFFFF) ^ 0xFFFF)>>9; + filterPos[i/2]= xx; + + if (d+1<4) + { + int maxShift= 3-(d+1); + int shift=0; + + memcpy(funnyCode + fragmentPos, fragmentB, fragmentLengthB); + + funnyCode[fragmentPos + imm8OfPShufW1B]= + (a+1) | ((b+1)<<2) | ((c+1)<<4) | ((d+1)<<6); + funnyCode[fragmentPos + imm8OfPShufW2B]= + a | (b<<2) | (c<<4) | (d<<6); + + if (i+3>=dstW) shift=maxShift; //avoid overread + else if ((filterPos[i/2]&3) <= maxShift) shift=filterPos[i/2]&3; //Align + + if (shift && i>=shift) + { + funnyCode[fragmentPos + imm8OfPShufW1B]+= 0x55*shift; + funnyCode[fragmentPos + imm8OfPShufW2B]+= 0x55*shift; + filterPos[i/2]-=shift; + } + + fragmentPos+= fragmentLengthB; + } + else + { + int maxShift= 3-d; + int shift=0; + + memcpy(funnyCode + fragmentPos, fragmentA, fragmentLengthA); + + funnyCode[fragmentPos + imm8OfPShufW1A]= + funnyCode[fragmentPos + imm8OfPShufW2A]= + a | (b<<2) | (c<<4) | (d<<6); + + if (i+4>=dstW) shift=maxShift; //avoid overread + else if ((filterPos[i/2]&3) <= maxShift) shift=filterPos[i/2]&3; //partial align + + if (shift && i>=shift) + { + funnyCode[fragmentPos + imm8OfPShufW1A]+= 0x55*shift; + funnyCode[fragmentPos + imm8OfPShufW2A]+= 0x55*shift; + filterPos[i/2]-=shift; + } + + fragmentPos+= fragmentLengthA; + } + + funnyCode[fragmentPos]= RET; + } + xpos+=xInc; + } + filterPos[i/2]= xpos>>16; // needed to jump to the next part } #endif /* COMPILE_MMX2 */ static void globalInit(void){ // generating tables: int i; - for(i=0; i<768; i++){ - int c= av_clip_uint8(i-256); - clip_table[i]=c; + for (i=0; i<768; i++){ + int c= av_clip_uint8(i-256); + clip_table[i]=c; } } static SwsFunc getSwsFunc(int flags){ - + #if defined(RUNTIME_CPUDETECT) && defined (CONFIG_GPL) #if defined(ARCH_X86) - // ordered per speed fasterst first - if(flags & SWS_CPU_CAPS_MMX2) - return swScale_MMX2; - else if(flags & SWS_CPU_CAPS_3DNOW) - return swScale_3DNow; - else if(flags & SWS_CPU_CAPS_MMX) - return swScale_MMX; - else - return swScale_C; + // ordered per speed fastest first + if (flags & SWS_CPU_CAPS_MMX2) + return swScale_MMX2; + else if (flags & SWS_CPU_CAPS_3DNOW) + return swScale_3DNow; + else if (flags & SWS_CPU_CAPS_MMX) + return swScale_MMX; + else + return swScale_C; #else #ifdef ARCH_POWERPC - if(flags & SWS_CPU_CAPS_ALTIVEC) - return swScale_altivec; - else - return swScale_C; + if (flags & SWS_CPU_CAPS_ALTIVEC) + return swScale_altivec; + else + return swScale_C; #endif - return swScale_C; + return swScale_C; #endif /* defined(ARCH_X86) */ #else //RUNTIME_CPUDETECT #ifdef HAVE_MMX2 - return swScale_MMX2; + return swScale_MMX2; #elif defined (HAVE_3DNOW) - return swScale_3DNow; + return swScale_3DNow; #elif defined (HAVE_MMX) - return swScale_MMX; + return swScale_MMX; #elif defined (HAVE_ALTIVEC) - return swScale_altivec; + return swScale_altivec; #else - return swScale_C; + return swScale_C; #endif #endif //!RUNTIME_CPUDETECT } static int PlanarToNV12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dstParam[], int dstStride[]){ - uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; - /* Copy Y plane */ - if(dstStride[0]==srcStride[0] && srcStride[0] > 0) - memcpy(dst, src[0], srcSliceH*dstStride[0]); - else - { - int i; - uint8_t *srcPtr= src[0]; - uint8_t *dstPtr= dst; - for(i=0; isrcW); - srcPtr+= srcStride[0]; - dstPtr+= dstStride[0]; - } - } - dst = dstParam[1] + dstStride[1]*srcSliceY/2; - if (c->dstFormat == PIX_FMT_NV12) - interleaveBytes( src[1],src[2],dst,c->srcW/2,srcSliceH/2,srcStride[1],srcStride[2],dstStride[0] ); - else - interleaveBytes( src[2],src[1],dst,c->srcW/2,srcSliceH/2,srcStride[2],srcStride[1],dstStride[0] ); - - return srcSliceH; + int srcSliceH, uint8_t* dstParam[], int dstStride[]){ + uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; + /* Copy Y plane */ + if (dstStride[0]==srcStride[0] && srcStride[0] > 0) + memcpy(dst, src[0], srcSliceH*dstStride[0]); + else + { + int i; + uint8_t *srcPtr= src[0]; + uint8_t *dstPtr= dst; + for (i=0; isrcW); + srcPtr+= srcStride[0]; + dstPtr+= dstStride[0]; + } + } + dst = dstParam[1] + dstStride[1]*srcSliceY/2; + if (c->dstFormat == PIX_FMT_NV12) + interleaveBytes(src[1], src[2], dst, c->srcW/2, srcSliceH/2, srcStride[1], srcStride[2], dstStride[0]); + else + interleaveBytes(src[2], src[1], dst, c->srcW/2, srcSliceH/2, srcStride[2], srcStride[1], dstStride[0]); + + return srcSliceH; } static int PlanarToYuy2Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dstParam[], int dstStride[]){ - uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; + int srcSliceH, uint8_t* dstParam[], int dstStride[]){ + uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; - yv12toyuy2( src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0] ); + yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); - return srcSliceH; + return srcSliceH; } static int PlanarToUyvyWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dstParam[], int dstStride[]){ - uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; + int srcSliceH, uint8_t* dstParam[], int dstStride[]){ + uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; - yv12touyvy( src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0] ); + yv12touyvy(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); - return srcSliceH; + return srcSliceH; } /* {RGB,BGR}{15,16,24,32} -> {RGB,BGR}{15,16,24,32} */ static int rgb2rgbWrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]){ - const int srcFormat= c->srcFormat; - const int dstFormat= c->dstFormat; - const int srcBpp= (fmt_depth(srcFormat) + 7) >> 3; - const int dstBpp= (fmt_depth(dstFormat) + 7) >> 3; - const int srcId= fmt_depth(srcFormat) >> 2; /* 1:0, 4:1, 8:2, 15:3, 16:4, 24:6, 32:8 */ - const int dstId= fmt_depth(dstFormat) >> 2; - void (*conv)(const uint8_t *src, uint8_t *dst, long src_size)=NULL; - - /* BGR -> BGR */ - if( (isBGR(srcFormat) && isBGR(dstFormat)) - || (isRGB(srcFormat) && isRGB(dstFormat))){ - switch(srcId | (dstId<<4)){ - case 0x34: conv= rgb16to15; break; - case 0x36: conv= rgb24to15; break; - case 0x38: conv= rgb32to15; break; - case 0x43: conv= rgb15to16; break; - case 0x46: conv= rgb24to16; break; - case 0x48: conv= rgb32to16; break; - case 0x63: conv= rgb15to24; break; - case 0x64: conv= rgb16to24; break; - case 0x68: conv= rgb32to24; break; - case 0x83: conv= rgb15to32; break; - case 0x84: conv= rgb16to32; break; - case 0x86: conv= rgb24to32; break; - default: av_log(c, AV_LOG_ERROR, "swScaler: internal error %s -> %s converter\n", - sws_format_name(srcFormat), sws_format_name(dstFormat)); break; - } - }else if( (isBGR(srcFormat) && isRGB(dstFormat)) - || (isRGB(srcFormat) && isBGR(dstFormat))){ - switch(srcId | (dstId<<4)){ - case 0x33: conv= rgb15tobgr15; break; - case 0x34: conv= rgb16tobgr15; break; - case 0x36: conv= rgb24tobgr15; break; - case 0x38: conv= rgb32tobgr15; break; - case 0x43: conv= rgb15tobgr16; break; - case 0x44: conv= rgb16tobgr16; break; - case 0x46: conv= rgb24tobgr16; break; - case 0x48: conv= rgb32tobgr16; break; - case 0x63: conv= rgb15tobgr24; break; - case 0x64: conv= rgb16tobgr24; break; - case 0x66: conv= rgb24tobgr24; break; - case 0x68: conv= rgb32tobgr24; break; - case 0x83: conv= rgb15tobgr32; break; - case 0x84: conv= rgb16tobgr32; break; - case 0x86: conv= rgb24tobgr32; break; - case 0x88: conv= rgb32tobgr32; break; - default: av_log(c, AV_LOG_ERROR, "swScaler: internal error %s -> %s converter\n", - sws_format_name(srcFormat), sws_format_name(dstFormat)); break; - } - }else{ - av_log(c, AV_LOG_ERROR, "swScaler: internal error %s -> %s converter\n", - sws_format_name(srcFormat), sws_format_name(dstFormat)); - } - - if(dstStride[0]*srcBpp == srcStride[0]*dstBpp) - conv(src[0], dst[0] + dstStride[0]*srcSliceY, srcSliceH*srcStride[0]); - else - { - int i; - uint8_t *srcPtr= src[0]; - uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; - - for(i=0; isrcW*srcBpp); - srcPtr+= srcStride[0]; - dstPtr+= dstStride[0]; - } - } - return srcSliceH; + int srcSliceH, uint8_t* dst[], int dstStride[]){ + const int srcFormat= c->srcFormat; + const int dstFormat= c->dstFormat; + const int srcBpp= (fmt_depth(srcFormat) + 7) >> 3; + const int dstBpp= (fmt_depth(dstFormat) + 7) >> 3; + const int srcId= fmt_depth(srcFormat) >> 2; /* 1:0, 4:1, 8:2, 15:3, 16:4, 24:6, 32:8 */ + const int dstId= fmt_depth(dstFormat) >> 2; + void (*conv)(const uint8_t *src, uint8_t *dst, long src_size)=NULL; + + /* BGR -> BGR */ + if ( (isBGR(srcFormat) && isBGR(dstFormat)) + || (isRGB(srcFormat) && isRGB(dstFormat))){ + switch(srcId | (dstId<<4)){ + case 0x34: conv= rgb16to15; break; + case 0x36: conv= rgb24to15; break; + case 0x38: conv= rgb32to15; break; + case 0x43: conv= rgb15to16; break; + case 0x46: conv= rgb24to16; break; + case 0x48: conv= rgb32to16; break; + case 0x63: conv= rgb15to24; break; + case 0x64: conv= rgb16to24; break; + case 0x68: conv= rgb32to24; break; + case 0x83: conv= rgb15to32; break; + case 0x84: conv= rgb16to32; break; + case 0x86: conv= rgb24to32; break; + default: av_log(c, AV_LOG_ERROR, "swScaler: internal error %s -> %s converter\n", + sws_format_name(srcFormat), sws_format_name(dstFormat)); break; + } + }else if ( (isBGR(srcFormat) && isRGB(dstFormat)) + || (isRGB(srcFormat) && isBGR(dstFormat))){ + switch(srcId | (dstId<<4)){ + case 0x33: conv= rgb15tobgr15; break; + case 0x34: conv= rgb16tobgr15; break; + case 0x36: conv= rgb24tobgr15; break; + case 0x38: conv= rgb32tobgr15; break; + case 0x43: conv= rgb15tobgr16; break; + case 0x44: conv= rgb16tobgr16; break; + case 0x46: conv= rgb24tobgr16; break; + case 0x48: conv= rgb32tobgr16; break; + case 0x63: conv= rgb15tobgr24; break; + case 0x64: conv= rgb16tobgr24; break; + case 0x66: conv= rgb24tobgr24; break; + case 0x68: conv= rgb32tobgr24; break; + case 0x83: conv= rgb15tobgr32; break; + case 0x84: conv= rgb16tobgr32; break; + case 0x86: conv= rgb24tobgr32; break; + case 0x88: conv= rgb32tobgr32; break; + default: av_log(c, AV_LOG_ERROR, "swScaler: internal error %s -> %s converter\n", + sws_format_name(srcFormat), sws_format_name(dstFormat)); break; + } + }else{ + av_log(c, AV_LOG_ERROR, "swScaler: internal error %s -> %s converter\n", + sws_format_name(srcFormat), sws_format_name(dstFormat)); + } + + if(conv) + { + if (dstStride[0]*srcBpp == srcStride[0]*dstBpp && srcStride[0] > 0) + conv(src[0], dst[0] + dstStride[0]*srcSliceY, srcSliceH*srcStride[0]); + else + { + int i; + uint8_t *srcPtr= src[0]; + uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; + + for (i=0; isrcW*srcBpp); + srcPtr+= srcStride[0]; + dstPtr+= dstStride[0]; + } + } + } + return srcSliceH; } static int bgr24toyv12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]){ - - rgb24toyv12( - src[0], - dst[0]+ srcSliceY *dstStride[0], - dst[1]+(srcSliceY>>1)*dstStride[1], - dst[2]+(srcSliceY>>1)*dstStride[2], - c->srcW, srcSliceH, - dstStride[0], dstStride[1], srcStride[0]); - return srcSliceH; + int srcSliceH, uint8_t* dst[], int dstStride[]){ + + rgb24toyv12( + src[0], + dst[0]+ srcSliceY *dstStride[0], + dst[1]+(srcSliceY>>1)*dstStride[1], + dst[2]+(srcSliceY>>1)*dstStride[2], + c->srcW, srcSliceH, + dstStride[0], dstStride[1], srcStride[0]); + return srcSliceH; } static int yvu9toyv12Wrapper(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]){ - int i; - - /* copy Y */ - if(srcStride[0]==dstStride[0] && srcStride[0] > 0) - memcpy(dst[0]+ srcSliceY*dstStride[0], src[0], srcStride[0]*srcSliceH); - else{ - uint8_t *srcPtr= src[0]; - uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; - - for(i=0; isrcW); - srcPtr+= srcStride[0]; - dstPtr+= dstStride[0]; - } - } - - if(c->dstFormat==PIX_FMT_YUV420P){ - planar2x(src[1], dst[1], c->chrSrcW, c->chrSrcH, srcStride[1], dstStride[1]); - planar2x(src[2], dst[2], c->chrSrcW, c->chrSrcH, srcStride[2], dstStride[2]); - }else{ - planar2x(src[1], dst[2], c->chrSrcW, c->chrSrcH, srcStride[1], dstStride[2]); - planar2x(src[2], dst[1], c->chrSrcW, c->chrSrcH, srcStride[2], dstStride[1]); - } - return srcSliceH; + int srcSliceH, uint8_t* dst[], int dstStride[]){ + int i; + + /* copy Y */ + if (srcStride[0]==dstStride[0] && srcStride[0] > 0) + memcpy(dst[0]+ srcSliceY*dstStride[0], src[0], srcStride[0]*srcSliceH); + else{ + uint8_t *srcPtr= src[0]; + uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; + + for (i=0; isrcW); + srcPtr+= srcStride[0]; + dstPtr+= dstStride[0]; + } + } + + if (c->dstFormat==PIX_FMT_YUV420P){ + planar2x(src[1], dst[1], c->chrSrcW, c->chrSrcH, srcStride[1], dstStride[1]); + planar2x(src[2], dst[2], c->chrSrcW, c->chrSrcH, srcStride[2], dstStride[2]); + }else{ + planar2x(src[1], dst[2], c->chrSrcW, c->chrSrcH, srcStride[1], dstStride[2]); + planar2x(src[2], dst[1], c->chrSrcW, c->chrSrcH, srcStride[2], dstStride[1]); + } + return srcSliceH; } /* unscaled copy like stuff (assumes nearly identical formats) */ static int simpleCopy(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]){ - - if(isPacked(c->srcFormat)) - { - if(dstStride[0]==srcStride[0] && srcStride[0] > 0) - memcpy(dst[0] + dstStride[0]*srcSliceY, src[0], srcSliceH*dstStride[0]); - else - { - int i; - uint8_t *srcPtr= src[0]; - uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; - int length=0; - - /* universal length finder */ - while(length+c->srcW <= FFABS(dstStride[0]) - && length+c->srcW <= FFABS(srcStride[0])) length+= c->srcW; - ASSERT(length!=0); - - for(i=0; isrcW : -((-c->srcW )>>c->chrDstHSubSample); - int y= plane==0 ? srcSliceY: -((-srcSliceY)>>c->chrDstVSubSample); - int height= plane==0 ? srcSliceH: -((-srcSliceH)>>c->chrDstVSubSample); - - if((isGray(c->srcFormat) || isGray(c->dstFormat)) && plane>0) - { - if(!isGray(c->dstFormat)) - memset(dst[plane], 128, dstStride[plane]*height); - } - else - { - if(dstStride[plane]==srcStride[plane] && srcStride[plane] > 0) - memcpy(dst[plane] + dstStride[plane]*y, src[plane], height*dstStride[plane]); - else - { - int i; - uint8_t *srcPtr= src[plane]; - uint8_t *dstPtr= dst[plane] + dstStride[plane]*y; - for(i=0; isrcFormat)) + { + if (dstStride[0]==srcStride[0] && srcStride[0] > 0) + memcpy(dst[0] + dstStride[0]*srcSliceY, src[0], srcSliceH*dstStride[0]); + else + { + int i; + uint8_t *srcPtr= src[0]; + uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; + int length=0; + + /* universal length finder */ + while(length+c->srcW <= FFABS(dstStride[0]) + && length+c->srcW <= FFABS(srcStride[0])) length+= c->srcW; + ASSERT(length!=0); + + for (i=0; isrcW : -((-c->srcW )>>c->chrDstHSubSample); + int y= plane==0 ? srcSliceY: -((-srcSliceY)>>c->chrDstVSubSample); + int height= plane==0 ? srcSliceH: -((-srcSliceH)>>c->chrDstVSubSample); + + if ((isGray(c->srcFormat) || isGray(c->dstFormat)) && plane>0) + { + if (!isGray(c->dstFormat)) + memset(dst[plane], 128, dstStride[plane]*height); + } + else + { + if (dstStride[plane]==srcStride[plane] && srcStride[plane] > 0) + memcpy(dst[plane] + dstStride[plane]*y, src[plane], height*dstStride[plane]); + else + { + int i; + uint8_t *srcPtr= src[plane]; + uint8_t *dstPtr= dst[plane] + dstStride[plane]*y; + for (i=0; isrcW; - int y= srcSliceY; - int height= srcSliceH; - int i, j; - uint8_t *srcPtr= src[0]; - uint8_t *dstPtr= dst[0] + dstStride[0]*y; - - if(!isGray(c->dstFormat)){ - int height= -((-srcSliceH)>>c->chrDstVSubSample); - memset(dst[1], 128, dstStride[1]*height); - memset(dst[2], 128, dstStride[2]*height); - } - if(c->srcFormat == PIX_FMT_GRAY16LE) srcPtr++; - for(i=0; isrcW; + int y= srcSliceY; + int height= srcSliceH; + int i, j; + uint8_t *srcPtr= src[0]; + uint8_t *dstPtr= dst[0] + dstStride[0]*y; + + if (!isGray(c->dstFormat)){ + int height= -((-srcSliceH)>>c->chrDstVSubSample); + memset(dst[1], 128, dstStride[1]*height); + memset(dst[2], 128, dstStride[2]*height); + } + if (c->srcFormat == PIX_FMT_GRAY16LE) srcPtr++; + for (i=0; isrcW; - int y= srcSliceY; - int height= srcSliceH; - int i, j; - uint8_t *srcPtr= src[0]; - uint8_t *dstPtr= dst[0] + dstStride[0]*y; - for(i=0; isrcW; + int y= srcSliceY; + int height= srcSliceH; + int i, j; + uint8_t *srcPtr= src[0]; + uint8_t *dstPtr= dst[0] + dstStride[0]*y; + for (i=0; isrcW; - int y= srcSliceY; - int height= srcSliceH; - int i, j; - uint16_t *srcPtr= src[0]; - uint16_t *dstPtr= dst[0] + dstStride[0]*y/2; - for(i=0; isrcW; + int y= srcSliceY; + int height= srcSliceH; + int i, j; + uint16_t *srcPtr= src[0]; + uint16_t *dstPtr= dst[0] + dstStride[0]*y/2; + for (i=0; i>16; - if(r<-0x7FFF) return 0x8000; - else if(r> 0x7FFF) return 0x7FFF; - else return r; + int r= (f + (1<<15))>>16; + if (r<-0x7FFF) return 0x8000; + else if (r> 0x7FFF) return 0x7FFF; + else return r; } /** * @param inv_table the yuv2rgb coeffs, normally Inverse_Table_6_9[x] - * @param fullRange if 1 then the luma range is 0..255 if 0 its 16..235 + * @param fullRange if 1 then the luma range is 0..255 if 0 it is 16..235 * @return -1 if not supported */ int sws_setColorspaceDetails(SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation){ - int64_t crv = inv_table[0]; - int64_t cbu = inv_table[1]; - int64_t cgu = -inv_table[2]; - int64_t cgv = -inv_table[3]; - int64_t cy = 1<<16; - int64_t oy = 0; - - if(isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1; - memcpy(c->srcColorspaceTable, inv_table, sizeof(int)*4); - memcpy(c->dstColorspaceTable, table, sizeof(int)*4); - - c->brightness= brightness; - c->contrast = contrast; - c->saturation= saturation; - c->srcRange = srcRange; - c->dstRange = dstRange; - - c->uOffset= 0x0400040004000400LL; - c->vOffset= 0x0400040004000400LL; - - if(!srcRange){ - cy= (cy*255) / 219; - oy= 16<<16; - }else{ - crv= (crv*224) / 255; - cbu= (cbu*224) / 255; - cgu= (cgu*224) / 255; - cgv= (cgv*224) / 255; - } + int64_t crv = inv_table[0]; + int64_t cbu = inv_table[1]; + int64_t cgu = -inv_table[2]; + int64_t cgv = -inv_table[3]; + int64_t cy = 1<<16; + int64_t oy = 0; + + if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1; + memcpy(c->srcColorspaceTable, inv_table, sizeof(int)*4); + memcpy(c->dstColorspaceTable, table, sizeof(int)*4); + + c->brightness= brightness; + c->contrast = contrast; + c->saturation= saturation; + c->srcRange = srcRange; + c->dstRange = dstRange; + + c->uOffset= 0x0400040004000400LL; + c->vOffset= 0x0400040004000400LL; + + if (!srcRange){ + cy= (cy*255) / 219; + oy= 16<<16; + }else{ + crv= (crv*224) / 255; + cbu= (cbu*224) / 255; + cgu= (cgu*224) / 255; + cgv= (cgv*224) / 255; + } - cy = (cy *contrast )>>16; - crv= (crv*contrast * saturation)>>32; - cbu= (cbu*contrast * saturation)>>32; - cgu= (cgu*contrast * saturation)>>32; - cgv= (cgv*contrast * saturation)>>32; + cy = (cy *contrast )>>16; + crv= (crv*contrast * saturation)>>32; + cbu= (cbu*contrast * saturation)>>32; + cgu= (cgu*contrast * saturation)>>32; + cgv= (cgv*contrast * saturation)>>32; - oy -= 256*brightness; + oy -= 256*brightness; - c->yCoeff= roundToInt16(cy *8192) * 0x0001000100010001ULL; - c->vrCoeff= roundToInt16(crv*8192) * 0x0001000100010001ULL; - c->ubCoeff= roundToInt16(cbu*8192) * 0x0001000100010001ULL; - c->vgCoeff= roundToInt16(cgv*8192) * 0x0001000100010001ULL; - c->ugCoeff= roundToInt16(cgu*8192) * 0x0001000100010001ULL; - c->yOffset= roundToInt16(oy * 8) * 0x0001000100010001ULL; + c->yCoeff= roundToInt16(cy *8192) * 0x0001000100010001ULL; + c->vrCoeff= roundToInt16(crv*8192) * 0x0001000100010001ULL; + c->ubCoeff= roundToInt16(cbu*8192) * 0x0001000100010001ULL; + c->vgCoeff= roundToInt16(cgv*8192) * 0x0001000100010001ULL; + c->ugCoeff= roundToInt16(cgu*8192) * 0x0001000100010001ULL; + c->yOffset= roundToInt16(oy * 8) * 0x0001000100010001ULL; - yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness, contrast, saturation); - //FIXME factorize + yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness, contrast, saturation); + //FIXME factorize #ifdef COMPILE_ALTIVEC - if (c->flags & SWS_CPU_CAPS_ALTIVEC) - yuv2rgb_altivec_init_tables (c, inv_table, brightness, contrast, saturation); -#endif - return 0; + if (c->flags & SWS_CPU_CAPS_ALTIVEC) + yuv2rgb_altivec_init_tables (c, inv_table, brightness, contrast, saturation); +#endif + return 0; } /** * @return -1 if not supported */ int sws_getColorspaceDetails(SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation){ - if(isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1; - - *inv_table = c->srcColorspaceTable; - *table = c->dstColorspaceTable; - *srcRange = c->srcRange; - *dstRange = c->dstRange; - *brightness= c->brightness; - *contrast = c->contrast; - *saturation= c->saturation; - - return 0; + if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1; + + *inv_table = c->srcColorspaceTable; + *table = c->dstColorspaceTable; + *srcRange = c->srcRange; + *dstRange = c->dstRange; + *brightness= c->brightness; + *contrast = c->contrast; + *saturation= c->saturation; + + return 0; } static int handle_jpeg(int *format) { - switch (*format) { - case PIX_FMT_YUVJ420P: - *format = PIX_FMT_YUV420P; - return 1; - case PIX_FMT_YUVJ422P: - *format = PIX_FMT_YUV422P; - return 1; - case PIX_FMT_YUVJ444P: - *format = PIX_FMT_YUV444P; - return 1; - default: - return 0; - } + switch (*format) { + case PIX_FMT_YUVJ420P: + *format = PIX_FMT_YUV420P; + return 1; + case PIX_FMT_YUVJ422P: + *format = PIX_FMT_YUV422P; + return 1; + case PIX_FMT_YUVJ444P: + *format = PIX_FMT_YUV444P; + return 1; + case PIX_FMT_YUVJ440P: + *format = PIX_FMT_YUV440P; + return 1; + default: + return 0; + } } SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags, - SwsFilter *srcFilter, SwsFilter *dstFilter, double *param){ - - SwsContext *c; - int i; - int usesVFilter, usesHFilter; - int unscaled, needsDither; - int srcRange, dstRange; - SwsFilter dummyFilter= {NULL, NULL, NULL, NULL}; + SwsFilter *srcFilter, SwsFilter *dstFilter, double *param){ + + SwsContext *c; + int i; + int usesVFilter, usesHFilter; + int unscaled, needsDither; + int srcRange, dstRange; + SwsFilter dummyFilter= {NULL, NULL, NULL, NULL}; #if defined(ARCH_X86) - if(flags & SWS_CPU_CAPS_MMX) - asm volatile("emms\n\t"::: "memory"); + if (flags & SWS_CPU_CAPS_MMX) + asm volatile("emms\n\t"::: "memory"); #endif #if !defined(RUNTIME_CPUDETECT) || !defined (CONFIG_GPL) //ensure that the flags match the compiled variant if cpudetect is off - flags &= ~(SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2|SWS_CPU_CAPS_3DNOW|SWS_CPU_CAPS_ALTIVEC); + flags &= ~(SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2|SWS_CPU_CAPS_3DNOW|SWS_CPU_CAPS_ALTIVEC|SWS_CPU_CAPS_BFIN); #ifdef HAVE_MMX2 - flags |= SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2; + flags |= SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_MMX2; #elif defined (HAVE_3DNOW) - flags |= SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_3DNOW; + flags |= SWS_CPU_CAPS_MMX|SWS_CPU_CAPS_3DNOW; #elif defined (HAVE_MMX) - flags |= SWS_CPU_CAPS_MMX; + flags |= SWS_CPU_CAPS_MMX; #elif defined (HAVE_ALTIVEC) - flags |= SWS_CPU_CAPS_ALTIVEC; + flags |= SWS_CPU_CAPS_ALTIVEC; +#elif defined (ARCH_BFIN) + flags |= SWS_CPU_CAPS_BFIN; #endif #endif /* RUNTIME_CPUDETECT */ - if(clip_table[512] != 255) globalInit(); - if(rgb15to16 == NULL) sws_rgb2rgb_init(flags); - - unscaled = (srcW == dstW && srcH == dstH); - needsDither= (isBGR(dstFormat) || isRGB(dstFormat)) - && (fmt_depth(dstFormat))<24 - && ((fmt_depth(dstFormat))<(fmt_depth(srcFormat)) || (!(isRGB(srcFormat) || isBGR(srcFormat)))); - - srcRange = handle_jpeg(&srcFormat); - dstRange = handle_jpeg(&dstFormat); - - if(!isSupportedIn(srcFormat)) - { - av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as input format\n", sws_format_name(srcFormat)); - return NULL; - } - if(!isSupportedOut(dstFormat)) - { - av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as output format\n", sws_format_name(dstFormat)); - return NULL; - } - - /* sanity check */ - if(srcW<4 || srcH<1 || dstW<8 || dstH<1) //FIXME check if these are enough and try to lowwer them after fixing the relevant parts of the code - { - av_log(NULL, AV_LOG_ERROR, "swScaler: %dx%d -> %dx%d is invalid scaling dimension\n", - srcW, srcH, dstW, dstH); - return NULL; - } - - if(!dstFilter) dstFilter= &dummyFilter; - if(!srcFilter) srcFilter= &dummyFilter; - - c= av_mallocz(sizeof(SwsContext)); - - c->av_class = &sws_context_class; - c->srcW= srcW; - c->srcH= srcH; - c->dstW= dstW; - c->dstH= dstH; - c->lumXInc= ((srcW<<16) + (dstW>>1))/dstW; - c->lumYInc= ((srcH<<16) + (dstH>>1))/dstH; - c->flags= flags; - c->dstFormat= dstFormat; - c->srcFormat= srcFormat; - c->vRounder= 4* 0x0001000100010001ULL; - - usesHFilter= usesVFilter= 0; - if(dstFilter->lumV!=NULL && dstFilter->lumV->length>1) usesVFilter=1; - if(dstFilter->lumH!=NULL && dstFilter->lumH->length>1) usesHFilter=1; - if(dstFilter->chrV!=NULL && dstFilter->chrV->length>1) usesVFilter=1; - if(dstFilter->chrH!=NULL && dstFilter->chrH->length>1) usesHFilter=1; - if(srcFilter->lumV!=NULL && srcFilter->lumV->length>1) usesVFilter=1; - if(srcFilter->lumH!=NULL && srcFilter->lumH->length>1) usesHFilter=1; - if(srcFilter->chrV!=NULL && srcFilter->chrV->length>1) usesVFilter=1; - if(srcFilter->chrH!=NULL && srcFilter->chrH->length>1) usesHFilter=1; - - getSubSampleFactors(&c->chrSrcHSubSample, &c->chrSrcVSubSample, srcFormat); - getSubSampleFactors(&c->chrDstHSubSample, &c->chrDstVSubSample, dstFormat); - - // reuse chroma for 2 pixles rgb/bgr unless user wants full chroma interpolation - if((isBGR(dstFormat) || isRGB(dstFormat)) && !(flags&SWS_FULL_CHR_H_INT)) c->chrDstHSubSample=1; - - // drop some chroma lines if the user wants it - c->vChrDrop= (flags&SWS_SRC_V_CHR_DROP_MASK)>>SWS_SRC_V_CHR_DROP_SHIFT; - c->chrSrcVSubSample+= c->vChrDrop; - - // drop every 2. pixel for chroma calculation unless user wants full chroma - if((isBGR(srcFormat) || isRGB(srcFormat)) && !(flags&SWS_FULL_CHR_H_INP)) - c->chrSrcHSubSample=1; - - if(param){ - c->param[0] = param[0]; - c->param[1] = param[1]; - }else{ - c->param[0] = - c->param[1] = SWS_PARAM_DEFAULT; - } - - c->chrIntHSubSample= c->chrDstHSubSample; - c->chrIntVSubSample= c->chrSrcVSubSample; - - // note the -((-x)>>y) is so that we allways round toward +inf - c->chrSrcW= -((-srcW) >> c->chrSrcHSubSample); - c->chrSrcH= -((-srcH) >> c->chrSrcVSubSample); - c->chrDstW= -((-dstW) >> c->chrDstHSubSample); - c->chrDstH= -((-dstH) >> c->chrDstVSubSample); - - sws_setColorspaceDetails(c, Inverse_Table_6_9[SWS_CS_DEFAULT], srcRange, Inverse_Table_6_9[SWS_CS_DEFAULT] /* FIXME*/, dstRange, 0, 1<<16, 1<<16); - - /* unscaled special Cases */ - if(unscaled && !usesHFilter && !usesVFilter) - { - /* yv12_to_nv12 */ - if(srcFormat == PIX_FMT_YUV420P && (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21)) - { - c->swScale= PlanarToNV12Wrapper; - } + if (clip_table[512] != 255) globalInit(); + if (!rgb15to16) sws_rgb2rgb_init(flags); + + unscaled = (srcW == dstW && srcH == dstH); + needsDither= (isBGR(dstFormat) || isRGB(dstFormat)) + && (fmt_depth(dstFormat))<24 + && ((fmt_depth(dstFormat))<(fmt_depth(srcFormat)) || (!(isRGB(srcFormat) || isBGR(srcFormat)))); + + srcRange = handle_jpeg(&srcFormat); + dstRange = handle_jpeg(&dstFormat); + + if (!isSupportedIn(srcFormat)) + { + av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as input pixel format\n", sws_format_name(srcFormat)); + return NULL; + } + if (!isSupportedOut(dstFormat)) + { + av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as output pixel format\n", sws_format_name(dstFormat)); + return NULL; + } + + /* sanity check */ + if (srcW<4 || srcH<1 || dstW<8 || dstH<1) //FIXME check if these are enough and try to lowwer them after fixing the relevant parts of the code + { + av_log(NULL, AV_LOG_ERROR, "swScaler: %dx%d -> %dx%d is invalid scaling dimension\n", + srcW, srcH, dstW, dstH); + return NULL; + } + + if (!dstFilter) dstFilter= &dummyFilter; + if (!srcFilter) srcFilter= &dummyFilter; + + c= av_mallocz(sizeof(SwsContext)); + + c->av_class = &sws_context_class; + c->srcW= srcW; + c->srcH= srcH; + c->dstW= dstW; + c->dstH= dstH; + c->lumXInc= ((srcW<<16) + (dstW>>1))/dstW; + c->lumYInc= ((srcH<<16) + (dstH>>1))/dstH; + c->flags= flags; + c->dstFormat= dstFormat; + c->srcFormat= srcFormat; + c->vRounder= 4* 0x0001000100010001ULL; + + usesHFilter= usesVFilter= 0; + if (dstFilter->lumV && dstFilter->lumV->length>1) usesVFilter=1; + if (dstFilter->lumH && dstFilter->lumH->length>1) usesHFilter=1; + if (dstFilter->chrV && dstFilter->chrV->length>1) usesVFilter=1; + if (dstFilter->chrH && dstFilter->chrH->length>1) usesHFilter=1; + if (srcFilter->lumV && srcFilter->lumV->length>1) usesVFilter=1; + if (srcFilter->lumH && srcFilter->lumH->length>1) usesHFilter=1; + if (srcFilter->chrV && srcFilter->chrV->length>1) usesVFilter=1; + if (srcFilter->chrH && srcFilter->chrH->length>1) usesHFilter=1; + + getSubSampleFactors(&c->chrSrcHSubSample, &c->chrSrcVSubSample, srcFormat); + getSubSampleFactors(&c->chrDstHSubSample, &c->chrDstVSubSample, dstFormat); + + // reuse chroma for 2 pixles rgb/bgr unless user wants full chroma interpolation + if ((isBGR(dstFormat) || isRGB(dstFormat)) && !(flags&SWS_FULL_CHR_H_INT)) c->chrDstHSubSample=1; + + // drop some chroma lines if the user wants it + c->vChrDrop= (flags&SWS_SRC_V_CHR_DROP_MASK)>>SWS_SRC_V_CHR_DROP_SHIFT; + c->chrSrcVSubSample+= c->vChrDrop; + + // drop every 2. pixel for chroma calculation unless user wants full chroma + if ((isBGR(srcFormat) || isRGB(srcFormat)) && !(flags&SWS_FULL_CHR_H_INP) + && srcFormat!=PIX_FMT_RGB8 && srcFormat!=PIX_FMT_BGR8 + && srcFormat!=PIX_FMT_RGB4 && srcFormat!=PIX_FMT_BGR4 + && srcFormat!=PIX_FMT_RGB4_BYTE && srcFormat!=PIX_FMT_BGR4_BYTE) + c->chrSrcHSubSample=1; + + if (param){ + c->param[0] = param[0]; + c->param[1] = param[1]; + }else{ + c->param[0] = + c->param[1] = SWS_PARAM_DEFAULT; + } + + c->chrIntHSubSample= c->chrDstHSubSample; + c->chrIntVSubSample= c->chrSrcVSubSample; + + // Note the -((-x)>>y) is so that we always round toward +inf. + c->chrSrcW= -((-srcW) >> c->chrSrcHSubSample); + c->chrSrcH= -((-srcH) >> c->chrSrcVSubSample); + c->chrDstW= -((-dstW) >> c->chrDstHSubSample); + c->chrDstH= -((-dstH) >> c->chrDstVSubSample); + + sws_setColorspaceDetails(c, Inverse_Table_6_9[SWS_CS_DEFAULT], srcRange, Inverse_Table_6_9[SWS_CS_DEFAULT] /* FIXME*/, dstRange, 0, 1<<16, 1<<16); + + /* unscaled special Cases */ + if (unscaled && !usesHFilter && !usesVFilter) + { + /* yv12_to_nv12 */ + if (srcFormat == PIX_FMT_YUV420P && (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21)) + { + c->swScale= PlanarToNV12Wrapper; + } #ifdef CONFIG_GPL - /* yuv2bgr */ - if((srcFormat==PIX_FMT_YUV420P || srcFormat==PIX_FMT_YUV422P) && (isBGR(dstFormat) || isRGB(dstFormat))) - { - c->swScale= yuv2rgb_get_func_ptr(c); - } + /* yuv2bgr */ + if ((srcFormat==PIX_FMT_YUV420P || srcFormat==PIX_FMT_YUV422P) && (isBGR(dstFormat) || isRGB(dstFormat))) + { + c->swScale= yuv2rgb_get_func_ptr(c); + } #endif - - if( srcFormat==PIX_FMT_YUV410P && dstFormat==PIX_FMT_YUV420P ) - { - c->swScale= yvu9toyv12Wrapper; - } - - /* bgr24toYV12 */ - if(srcFormat==PIX_FMT_BGR24 && dstFormat==PIX_FMT_YUV420P) - c->swScale= bgr24toyv12Wrapper; - - /* rgb/bgr -> rgb/bgr (no dither needed forms) */ - if( (isBGR(srcFormat) || isRGB(srcFormat)) - && (isBGR(dstFormat) || isRGB(dstFormat)) - && !needsDither) - c->swScale= rgb2rgbWrapper; - - /* LQ converters if -sws 0 or -sws 4*/ - if(c->flags&(SWS_FAST_BILINEAR|SWS_POINT)){ - /* rgb/bgr -> rgb/bgr (dither needed forms) */ - if( (isBGR(srcFormat) || isRGB(srcFormat)) - && (isBGR(dstFormat) || isRGB(dstFormat)) - && needsDither) - c->swScale= rgb2rgbWrapper; - - /* yv12_to_yuy2 */ - if(srcFormat == PIX_FMT_YUV420P && - (dstFormat == PIX_FMT_YUYV422 || dstFormat == PIX_FMT_UYVY422)) - { - if (dstFormat == PIX_FMT_YUYV422) - c->swScale= PlanarToYuy2Wrapper; - else - c->swScale= PlanarToUyvyWrapper; - } - } + + if (srcFormat==PIX_FMT_YUV410P && dstFormat==PIX_FMT_YUV420P) + { + c->swScale= yvu9toyv12Wrapper; + } + + /* bgr24toYV12 */ + if (srcFormat==PIX_FMT_BGR24 && dstFormat==PIX_FMT_YUV420P) + c->swScale= bgr24toyv12Wrapper; + + /* rgb/bgr -> rgb/bgr (no dither needed forms) */ + if ( (isBGR(srcFormat) || isRGB(srcFormat)) + && (isBGR(dstFormat) || isRGB(dstFormat)) + && srcFormat != PIX_FMT_BGR8 && dstFormat != PIX_FMT_BGR8 + && srcFormat != PIX_FMT_RGB8 && dstFormat != PIX_FMT_RGB8 + && srcFormat != PIX_FMT_BGR4 && dstFormat != PIX_FMT_BGR4 + && srcFormat != PIX_FMT_RGB4 && dstFormat != PIX_FMT_RGB4 + && srcFormat != PIX_FMT_BGR4_BYTE && dstFormat != PIX_FMT_BGR4_BYTE + && srcFormat != PIX_FMT_RGB4_BYTE && dstFormat != PIX_FMT_RGB4_BYTE + && srcFormat != PIX_FMT_MONOBLACK && dstFormat != PIX_FMT_MONOBLACK + && !needsDither) + c->swScale= rgb2rgbWrapper; + + /* LQ converters if -sws 0 or -sws 4*/ + if (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)){ + /* rgb/bgr -> rgb/bgr (dither needed forms) */ + if ( (isBGR(srcFormat) || isRGB(srcFormat)) + && (isBGR(dstFormat) || isRGB(dstFormat)) + && needsDither) + c->swScale= rgb2rgbWrapper; + + /* yv12_to_yuy2 */ + if (srcFormat == PIX_FMT_YUV420P && + (dstFormat == PIX_FMT_YUYV422 || dstFormat == PIX_FMT_UYVY422)) + { + if (dstFormat == PIX_FMT_YUYV422) + c->swScale= PlanarToYuy2Wrapper; + else + c->swScale= PlanarToUyvyWrapper; + } + } #ifdef COMPILE_ALTIVEC - if ((c->flags & SWS_CPU_CAPS_ALTIVEC) && - ((srcFormat == PIX_FMT_YUV420P && - (dstFormat == PIX_FMT_YUYV422 || dstFormat == PIX_FMT_UYVY422)))) { - // unscaled YV12 -> packed YUV, we want speed - if (dstFormat == PIX_FMT_YUYV422) - c->swScale= yv12toyuy2_unscaled_altivec; - else - c->swScale= yv12touyvy_unscaled_altivec; - } + if ((c->flags & SWS_CPU_CAPS_ALTIVEC) && + ((srcFormat == PIX_FMT_YUV420P && + (dstFormat == PIX_FMT_YUYV422 || dstFormat == PIX_FMT_UYVY422)))) { + // unscaled YV12 -> packed YUV, we want speed + if (dstFormat == PIX_FMT_YUYV422) + c->swScale= yv12toyuy2_unscaled_altivec; + else + c->swScale= yv12touyvy_unscaled_altivec; + } +#endif + + /* simple copy */ + if ( srcFormat == dstFormat + || (isPlanarYUV(srcFormat) && isGray(dstFormat)) + || (isPlanarYUV(dstFormat) && isGray(srcFormat))) + { + c->swScale= simpleCopy; + } + + /* gray16{le,be} conversions */ + if (isGray16(srcFormat) && (isPlanarYUV(dstFormat) || (dstFormat == PIX_FMT_GRAY8))) + { + c->swScale= gray16togray; + } + if ((isPlanarYUV(srcFormat) || (srcFormat == PIX_FMT_GRAY8)) && isGray16(dstFormat)) + { + c->swScale= graytogray16; + } + if (srcFormat != dstFormat && isGray16(srcFormat) && isGray16(dstFormat)) + { + c->swScale= gray16swap; + } + +#ifdef ARCH_BFIN + if (flags & SWS_CPU_CAPS_BFIN) + ff_bfin_get_unscaled_swscale (c); #endif - /* simple copy */ - if( srcFormat == dstFormat - || (isPlanarYUV(srcFormat) && isGray(dstFormat)) - || (isPlanarYUV(dstFormat) && isGray(srcFormat)) - ) - { - c->swScale= simpleCopy; - } - - /* gray16{le,be} conversions */ - if(isGray16(srcFormat) && (isPlanarYUV(dstFormat) || (dstFormat == PIX_FMT_GRAY8))) - { - c->swScale= gray16togray; - } - if((isPlanarYUV(srcFormat) || (srcFormat == PIX_FMT_GRAY8)) && isGray16(dstFormat)) - { - c->swScale= graytogray16; - } - if(srcFormat != dstFormat && isGray16(srcFormat) && isGray16(dstFormat)) - { - c->swScale= gray16swap; - } - - if(c->swScale){ - if(flags&SWS_PRINT_INFO) - av_log(c, AV_LOG_INFO, "SwScaler: using unscaled %s -> %s special converter\n", - sws_format_name(srcFormat), sws_format_name(dstFormat)); - return c; - } - } - - if(flags & SWS_CPU_CAPS_MMX2) - { - c->canMMX2BeUsed= (dstW >=srcW && (dstW&31)==0 && (srcW&15)==0) ? 1 : 0; - if(!c->canMMX2BeUsed && dstW >=srcW && (srcW&15)==0 && (flags&SWS_FAST_BILINEAR)) - { - if(flags&SWS_PRINT_INFO) - av_log(c, AV_LOG_INFO, "SwScaler: output Width is not a multiple of 32 -> no MMX2 scaler\n"); - } - if(usesHFilter) c->canMMX2BeUsed=0; - } - else - c->canMMX2BeUsed=0; - - c->chrXInc= ((c->chrSrcW<<16) + (c->chrDstW>>1))/c->chrDstW; - c->chrYInc= ((c->chrSrcH<<16) + (c->chrDstH>>1))/c->chrDstH; - - // match pixel 0 of the src to pixel 0 of dst and match pixel n-2 of src to pixel n-2 of dst - // but only for the FAST_BILINEAR mode otherwise do correct scaling - // n-2 is the last chrominance sample available - // this is not perfect, but noone shuld notice the difference, the more correct variant - // would be like the vertical one, but that would require some special code for the - // first and last pixel - if(flags&SWS_FAST_BILINEAR) - { - if(c->canMMX2BeUsed) - { - c->lumXInc+= 20; - c->chrXInc+= 20; - } - //we don't use the x86asm scaler if mmx is available - else if(flags & SWS_CPU_CAPS_MMX) - { - c->lumXInc = ((srcW-2)<<16)/(dstW-2) - 20; - c->chrXInc = ((c->chrSrcW-2)<<16)/(c->chrDstW-2) - 20; - } - } - - /* precalculate horizontal scaler filter coefficients */ - { - const int filterAlign= - (flags & SWS_CPU_CAPS_MMX) ? 4 : - (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 : - 1; - - initFilter(&c->hLumFilter, &c->hLumFilterPos, &c->hLumFilterSize, c->lumXInc, - srcW , dstW, filterAlign, 1<<14, - (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, - srcFilter->lumH, dstFilter->lumH, c->param); - initFilter(&c->hChrFilter, &c->hChrFilterPos, &c->hChrFilterSize, c->chrXInc, - c->chrSrcW, c->chrDstW, filterAlign, 1<<14, - (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, - srcFilter->chrH, dstFilter->chrH, c->param); + if (c->swScale){ + if (flags&SWS_PRINT_INFO) + av_log(c, AV_LOG_INFO, "SwScaler: using unscaled %s -> %s special converter\n", + sws_format_name(srcFormat), sws_format_name(dstFormat)); + return c; + } + } + + if (flags & SWS_CPU_CAPS_MMX2) + { + c->canMMX2BeUsed= (dstW >=srcW && (dstW&31)==0 && (srcW&15)==0) ? 1 : 0; + if (!c->canMMX2BeUsed && dstW >=srcW && (srcW&15)==0 && (flags&SWS_FAST_BILINEAR)) + { + if (flags&SWS_PRINT_INFO) + av_log(c, AV_LOG_INFO, "SwScaler: output Width is not a multiple of 32 -> no MMX2 scaler\n"); + } + if (usesHFilter) c->canMMX2BeUsed=0; + } + else + c->canMMX2BeUsed=0; + + c->chrXInc= ((c->chrSrcW<<16) + (c->chrDstW>>1))/c->chrDstW; + c->chrYInc= ((c->chrSrcH<<16) + (c->chrDstH>>1))/c->chrDstH; + + // match pixel 0 of the src to pixel 0 of dst and match pixel n-2 of src to pixel n-2 of dst + // but only for the FAST_BILINEAR mode otherwise do correct scaling + // n-2 is the last chrominance sample available + // this is not perfect, but no one should notice the difference, the more correct variant + // would be like the vertical one, but that would require some special code for the + // first and last pixel + if (flags&SWS_FAST_BILINEAR) + { + if (c->canMMX2BeUsed) + { + c->lumXInc+= 20; + c->chrXInc+= 20; + } + //we don't use the x86asm scaler if mmx is available + else if (flags & SWS_CPU_CAPS_MMX) + { + c->lumXInc = ((srcW-2)<<16)/(dstW-2) - 20; + c->chrXInc = ((c->chrSrcW-2)<<16)/(c->chrDstW-2) - 20; + } + } + + /* precalculate horizontal scaler filter coefficients */ + { + const int filterAlign= + (flags & SWS_CPU_CAPS_MMX) ? 4 : + (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 : + 1; + + initFilter(&c->hLumFilter, &c->hLumFilterPos, &c->hLumFilterSize, c->lumXInc, + srcW , dstW, filterAlign, 1<<14, + (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, + srcFilter->lumH, dstFilter->lumH, c->param); + initFilter(&c->hChrFilter, &c->hChrFilterPos, &c->hChrFilterSize, c->chrXInc, + c->chrSrcW, c->chrDstW, filterAlign, 1<<14, + (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, + srcFilter->chrH, dstFilter->chrH, c->param); #define MAX_FUNNY_CODE_SIZE 10000 #if defined(COMPILE_MMX2) // can't downscale !!! - if(c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR)) - { + if (c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR)) + { #ifdef MAP_ANONYMOUS - c->funnyYCode = (uint8_t*)mmap(NULL, MAX_FUNNY_CODE_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); - c->funnyUVCode = (uint8_t*)mmap(NULL, MAX_FUNNY_CODE_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + c->funnyYCode = (uint8_t*)mmap(NULL, MAX_FUNNY_CODE_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); + c->funnyUVCode = (uint8_t*)mmap(NULL, MAX_FUNNY_CODE_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); #else - c->funnyYCode = av_malloc(MAX_FUNNY_CODE_SIZE); - c->funnyUVCode = av_malloc(MAX_FUNNY_CODE_SIZE); + c->funnyYCode = av_malloc(MAX_FUNNY_CODE_SIZE); + c->funnyUVCode = av_malloc(MAX_FUNNY_CODE_SIZE); #endif - c->lumMmx2Filter = av_malloc((dstW /8+8)*sizeof(int16_t)); - c->chrMmx2Filter = av_malloc((c->chrDstW /4+8)*sizeof(int16_t)); - c->lumMmx2FilterPos= av_malloc((dstW /2/8+8)*sizeof(int32_t)); - c->chrMmx2FilterPos= av_malloc((c->chrDstW/2/4+8)*sizeof(int32_t)); + c->lumMmx2Filter = av_malloc((dstW /8+8)*sizeof(int16_t)); + c->chrMmx2Filter = av_malloc((c->chrDstW /4+8)*sizeof(int16_t)); + c->lumMmx2FilterPos= av_malloc((dstW /2/8+8)*sizeof(int32_t)); + c->chrMmx2FilterPos= av_malloc((c->chrDstW/2/4+8)*sizeof(int32_t)); - initMMX2HScaler( dstW, c->lumXInc, c->funnyYCode , c->lumMmx2Filter, c->lumMmx2FilterPos, 8); - initMMX2HScaler(c->chrDstW, c->chrXInc, c->funnyUVCode, c->chrMmx2Filter, c->chrMmx2FilterPos, 4); - } + initMMX2HScaler( dstW, c->lumXInc, c->funnyYCode , c->lumMmx2Filter, c->lumMmx2FilterPos, 8); + initMMX2HScaler(c->chrDstW, c->chrXInc, c->funnyUVCode, c->chrMmx2Filter, c->chrMmx2FilterPos, 4); + } #endif /* defined(COMPILE_MMX2) */ - } // Init Horizontal stuff + } // Init Horizontal stuff - /* precalculate vertical scaler filter coefficients */ - { - const int filterAlign= - (flags & SWS_CPU_CAPS_MMX) && (flags & SWS_ACCURATE_RND) ? 2 : - (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 : - 1; + /* precalculate vertical scaler filter coefficients */ + { + const int filterAlign= + (flags & SWS_CPU_CAPS_MMX) && (flags & SWS_ACCURATE_RND) ? 2 : + (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 : + 1; - initFilter(&c->vLumFilter, &c->vLumFilterPos, &c->vLumFilterSize, c->lumYInc, - srcH , dstH, filterAlign, (1<<12)-4, - (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, - srcFilter->lumV, dstFilter->lumV, c->param); - initFilter(&c->vChrFilter, &c->vChrFilterPos, &c->vChrFilterSize, c->chrYInc, - c->chrSrcH, c->chrDstH, filterAlign, (1<<12)-4, - (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, - srcFilter->chrV, dstFilter->chrV, c->param); + initFilter(&c->vLumFilter, &c->vLumFilterPos, &c->vLumFilterSize, c->lumYInc, + srcH , dstH, filterAlign, (1<<12)-4, + (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, + srcFilter->lumV, dstFilter->lumV, c->param); + initFilter(&c->vChrFilter, &c->vChrFilterPos, &c->vChrFilterSize, c->chrYInc, + c->chrSrcH, c->chrDstH, filterAlign, (1<<12)-4, + (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, + srcFilter->chrV, dstFilter->chrV, c->param); #ifdef HAVE_ALTIVEC - c->vYCoeffsBank = av_malloc(sizeof (vector signed short)*c->vLumFilterSize*c->dstH); - c->vCCoeffsBank = av_malloc(sizeof (vector signed short)*c->vChrFilterSize*c->chrDstH); - - for (i=0;ivLumFilterSize*c->dstH;i++) { - int j; - short *p = (short *)&c->vYCoeffsBank[i]; - for (j=0;j<8;j++) - p[j] = c->vLumFilter[i]; - } - - for (i=0;ivChrFilterSize*c->chrDstH;i++) { - int j; - short *p = (short *)&c->vCCoeffsBank[i]; - for (j=0;j<8;j++) - p[j] = c->vChrFilter[i]; - } + c->vYCoeffsBank = av_malloc(sizeof (vector signed short)*c->vLumFilterSize*c->dstH); + c->vCCoeffsBank = av_malloc(sizeof (vector signed short)*c->vChrFilterSize*c->chrDstH); + + for (i=0;ivLumFilterSize*c->dstH;i++) { + int j; + short *p = (short *)&c->vYCoeffsBank[i]; + for (j=0;j<8;j++) + p[j] = c->vLumFilter[i]; + } + + for (i=0;ivChrFilterSize*c->chrDstH;i++) { + int j; + short *p = (short *)&c->vCCoeffsBank[i]; + for (j=0;j<8;j++) + p[j] = c->vChrFilter[i]; + } #endif - } - - // Calculate Buffer Sizes so that they won't run out while handling these damn slices - c->vLumBufSize= c->vLumFilterSize; - c->vChrBufSize= c->vChrFilterSize; - for(i=0; ichrDstH / dstH; - int nextSlice= FFMAX(c->vLumFilterPos[i ] + c->vLumFilterSize - 1, - ((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)<chrSrcVSubSample)); - - nextSlice>>= c->chrSrcVSubSample; - nextSlice<<= c->chrSrcVSubSample; - if(c->vLumFilterPos[i ] + c->vLumBufSize < nextSlice) - c->vLumBufSize= nextSlice - c->vLumFilterPos[i ]; - if(c->vChrFilterPos[chrI] + c->vChrBufSize < (nextSlice>>c->chrSrcVSubSample)) - c->vChrBufSize= (nextSlice>>c->chrSrcVSubSample) - c->vChrFilterPos[chrI]; - } - - // allocate pixbufs (we use dynamic allocation because otherwise we would need to - c->lumPixBuf= av_malloc(c->vLumBufSize*2*sizeof(int16_t*)); - c->chrPixBuf= av_malloc(c->vChrBufSize*2*sizeof(int16_t*)); - //Note we need at least one pixel more at the end because of the mmx code (just in case someone wanna replace the 4000/8000) - /* align at 16 bytes for AltiVec */ - for(i=0; ivLumBufSize; i++) - c->lumPixBuf[i]= c->lumPixBuf[i+c->vLumBufSize]= av_mallocz(4000); - for(i=0; ivChrBufSize; i++) - c->chrPixBuf[i]= c->chrPixBuf[i+c->vChrBufSize]= av_malloc(8000); - - //try to avoid drawing green stuff between the right end and the stride end - for(i=0; ivChrBufSize; i++) memset(c->chrPixBuf[i], 64, 8000); - - ASSERT(c->chrDstH <= dstH) - - if(flags&SWS_PRINT_INFO) - { + } + + // Calculate Buffer Sizes so that they won't run out while handling these damn slices + c->vLumBufSize= c->vLumFilterSize; + c->vChrBufSize= c->vChrFilterSize; + for (i=0; ichrDstH / dstH; + int nextSlice= FFMAX(c->vLumFilterPos[i ] + c->vLumFilterSize - 1, + ((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)<chrSrcVSubSample)); + + nextSlice>>= c->chrSrcVSubSample; + nextSlice<<= c->chrSrcVSubSample; + if (c->vLumFilterPos[i ] + c->vLumBufSize < nextSlice) + c->vLumBufSize= nextSlice - c->vLumFilterPos[i]; + if (c->vChrFilterPos[chrI] + c->vChrBufSize < (nextSlice>>c->chrSrcVSubSample)) + c->vChrBufSize= (nextSlice>>c->chrSrcVSubSample) - c->vChrFilterPos[chrI]; + } + + // allocate pixbufs (we use dynamic allocation because otherwise we would need to + c->lumPixBuf= av_malloc(c->vLumBufSize*2*sizeof(int16_t*)); + c->chrPixBuf= av_malloc(c->vChrBufSize*2*sizeof(int16_t*)); + //Note we need at least one pixel more at the end because of the mmx code (just in case someone wanna replace the 4000/8000) + /* align at 16 bytes for AltiVec */ + for (i=0; ivLumBufSize; i++) + c->lumPixBuf[i]= c->lumPixBuf[i+c->vLumBufSize]= av_mallocz(4000); + for (i=0; ivChrBufSize; i++) + c->chrPixBuf[i]= c->chrPixBuf[i+c->vChrBufSize]= av_malloc(8000); + + //try to avoid drawing green stuff between the right end and the stride end + for (i=0; ivChrBufSize; i++) memset(c->chrPixBuf[i], 64, 8000); + + ASSERT(c->chrDstH <= dstH) + + if (flags&SWS_PRINT_INFO) + { #ifdef DITHER1XBPP - char *dither= " dithered"; + char *dither= " dithered"; #else - char *dither= ""; + char *dither= ""; #endif - if(flags&SWS_FAST_BILINEAR) - av_log(c, AV_LOG_INFO, "SwScaler: FAST_BILINEAR scaler, "); - else if(flags&SWS_BILINEAR) - av_log(c, AV_LOG_INFO, "SwScaler: BILINEAR scaler, "); - else if(flags&SWS_BICUBIC) - av_log(c, AV_LOG_INFO, "SwScaler: BICUBIC scaler, "); - else if(flags&SWS_X) - av_log(c, AV_LOG_INFO, "SwScaler: Experimental scaler, "); - else if(flags&SWS_POINT) - av_log(c, AV_LOG_INFO, "SwScaler: Nearest Neighbor / POINT scaler, "); - else if(flags&SWS_AREA) - av_log(c, AV_LOG_INFO, "SwScaler: Area Averageing scaler, "); - else if(flags&SWS_BICUBLIN) - av_log(c, AV_LOG_INFO, "SwScaler: luma BICUBIC / chroma BILINEAR scaler, "); - else if(flags&SWS_GAUSS) - av_log(c, AV_LOG_INFO, "SwScaler: Gaussian scaler, "); - else if(flags&SWS_SINC) - av_log(c, AV_LOG_INFO, "SwScaler: Sinc scaler, "); - else if(flags&SWS_LANCZOS) - av_log(c, AV_LOG_INFO, "SwScaler: Lanczos scaler, "); - else if(flags&SWS_SPLINE) - av_log(c, AV_LOG_INFO, "SwScaler: Bicubic spline scaler, "); - else - av_log(c, AV_LOG_INFO, "SwScaler: ehh flags invalid?! "); - - if(dstFormat==PIX_FMT_BGR555 || dstFormat==PIX_FMT_BGR565) - av_log(c, AV_LOG_INFO, "from %s to%s %s ", - sws_format_name(srcFormat), dither, sws_format_name(dstFormat)); - else - av_log(c, AV_LOG_INFO, "from %s to %s ", - sws_format_name(srcFormat), sws_format_name(dstFormat)); - - if(flags & SWS_CPU_CAPS_MMX2) - av_log(c, AV_LOG_INFO, "using MMX2\n"); - else if(flags & SWS_CPU_CAPS_3DNOW) - av_log(c, AV_LOG_INFO, "using 3DNOW\n"); - else if(flags & SWS_CPU_CAPS_MMX) - av_log(c, AV_LOG_INFO, "using MMX\n"); - else if(flags & SWS_CPU_CAPS_ALTIVEC) - av_log(c, AV_LOG_INFO, "using AltiVec\n"); - else - av_log(c, AV_LOG_INFO, "using C\n"); - } - - if(flags & SWS_PRINT_INFO) - { - if(flags & SWS_CPU_CAPS_MMX) - { - if(c->canMMX2BeUsed && (flags&SWS_FAST_BILINEAR)) - av_log(c, AV_LOG_VERBOSE, "SwScaler: using FAST_BILINEAR MMX2 scaler for horizontal scaling\n"); - else - { - if(c->hLumFilterSize==4) - av_log(c, AV_LOG_VERBOSE, "SwScaler: using 4-tap MMX scaler for horizontal luminance scaling\n"); - else if(c->hLumFilterSize==8) - av_log(c, AV_LOG_VERBOSE, "SwScaler: using 8-tap MMX scaler for horizontal luminance scaling\n"); - else - av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap MMX scaler for horizontal luminance scaling\n"); - - if(c->hChrFilterSize==4) - av_log(c, AV_LOG_VERBOSE, "SwScaler: using 4-tap MMX scaler for horizontal chrominance scaling\n"); - else if(c->hChrFilterSize==8) - av_log(c, AV_LOG_VERBOSE, "SwScaler: using 8-tap MMX scaler for horizontal chrominance scaling\n"); - else - av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap MMX scaler for horizontal chrominance scaling\n"); - } - } - else - { + if (flags&SWS_FAST_BILINEAR) + av_log(c, AV_LOG_INFO, "SwScaler: FAST_BILINEAR scaler, "); + else if (flags&SWS_BILINEAR) + av_log(c, AV_LOG_INFO, "SwScaler: BILINEAR scaler, "); + else if (flags&SWS_BICUBIC) + av_log(c, AV_LOG_INFO, "SwScaler: BICUBIC scaler, "); + else if (flags&SWS_X) + av_log(c, AV_LOG_INFO, "SwScaler: Experimental scaler, "); + else if (flags&SWS_POINT) + av_log(c, AV_LOG_INFO, "SwScaler: Nearest Neighbor / POINT scaler, "); + else if (flags&SWS_AREA) + av_log(c, AV_LOG_INFO, "SwScaler: Area Averageing scaler, "); + else if (flags&SWS_BICUBLIN) + av_log(c, AV_LOG_INFO, "SwScaler: luma BICUBIC / chroma BILINEAR scaler, "); + else if (flags&SWS_GAUSS) + av_log(c, AV_LOG_INFO, "SwScaler: Gaussian scaler, "); + else if (flags&SWS_SINC) + av_log(c, AV_LOG_INFO, "SwScaler: Sinc scaler, "); + else if (flags&SWS_LANCZOS) + av_log(c, AV_LOG_INFO, "SwScaler: Lanczos scaler, "); + else if (flags&SWS_SPLINE) + av_log(c, AV_LOG_INFO, "SwScaler: Bicubic spline scaler, "); + else + av_log(c, AV_LOG_INFO, "SwScaler: ehh flags invalid?! "); + + if (dstFormat==PIX_FMT_BGR555 || dstFormat==PIX_FMT_BGR565) + av_log(c, AV_LOG_INFO, "from %s to%s %s ", + sws_format_name(srcFormat), dither, sws_format_name(dstFormat)); + else + av_log(c, AV_LOG_INFO, "from %s to %s ", + sws_format_name(srcFormat), sws_format_name(dstFormat)); + + if (flags & SWS_CPU_CAPS_MMX2) + av_log(c, AV_LOG_INFO, "using MMX2\n"); + else if (flags & SWS_CPU_CAPS_3DNOW) + av_log(c, AV_LOG_INFO, "using 3DNOW\n"); + else if (flags & SWS_CPU_CAPS_MMX) + av_log(c, AV_LOG_INFO, "using MMX\n"); + else if (flags & SWS_CPU_CAPS_ALTIVEC) + av_log(c, AV_LOG_INFO, "using AltiVec\n"); + else + av_log(c, AV_LOG_INFO, "using C\n"); + } + + if (flags & SWS_PRINT_INFO) + { + if (flags & SWS_CPU_CAPS_MMX) + { + if (c->canMMX2BeUsed && (flags&SWS_FAST_BILINEAR)) + av_log(c, AV_LOG_VERBOSE, "SwScaler: using FAST_BILINEAR MMX2 scaler for horizontal scaling\n"); + else + { + if (c->hLumFilterSize==4) + av_log(c, AV_LOG_VERBOSE, "SwScaler: using 4-tap MMX scaler for horizontal luminance scaling\n"); + else if (c->hLumFilterSize==8) + av_log(c, AV_LOG_VERBOSE, "SwScaler: using 8-tap MMX scaler for horizontal luminance scaling\n"); + else + av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap MMX scaler for horizontal luminance scaling\n"); + + if (c->hChrFilterSize==4) + av_log(c, AV_LOG_VERBOSE, "SwScaler: using 4-tap MMX scaler for horizontal chrominance scaling\n"); + else if (c->hChrFilterSize==8) + av_log(c, AV_LOG_VERBOSE, "SwScaler: using 8-tap MMX scaler for horizontal chrominance scaling\n"); + else + av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap MMX scaler for horizontal chrominance scaling\n"); + } + } + else + { #if defined(ARCH_X86) - av_log(c, AV_LOG_VERBOSE, "SwScaler: using X86-Asm scaler for horizontal scaling\n"); + av_log(c, AV_LOG_VERBOSE, "SwScaler: using X86-Asm scaler for horizontal scaling\n"); #else - if(flags & SWS_FAST_BILINEAR) - av_log(c, AV_LOG_VERBOSE, "SwScaler: using FAST_BILINEAR C scaler for horizontal scaling\n"); - else - av_log(c, AV_LOG_VERBOSE, "SwScaler: using C scaler for horizontal scaling\n"); + if (flags & SWS_FAST_BILINEAR) + av_log(c, AV_LOG_VERBOSE, "SwScaler: using FAST_BILINEAR C scaler for horizontal scaling\n"); + else + av_log(c, AV_LOG_VERBOSE, "SwScaler: using C scaler for horizontal scaling\n"); #endif - } - if(isPlanarYUV(dstFormat)) - { - if(c->vLumFilterSize==1) - av_log(c, AV_LOG_VERBOSE, "SwScaler: using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); - else - av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap %s scaler for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); - } - else - { - if(c->vLumFilterSize==1 && c->vChrFilterSize==2) - av_log(c, AV_LOG_VERBOSE, "SwScaler: using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n" - "SwScaler: 2-tap scaler for vertical chrominance scaling (BGR)\n",(flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); - else if(c->vLumFilterSize==2 && c->vChrFilterSize==2) - av_log(c, AV_LOG_VERBOSE, "SwScaler: using 2-tap linear %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); - else - av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); - } - - if(dstFormat==PIX_FMT_BGR24) - av_log(c, AV_LOG_VERBOSE, "SwScaler: using %s YV12->BGR24 Converter\n", - (flags & SWS_CPU_CAPS_MMX2) ? "MMX2" : ((flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C")); - else if(dstFormat==PIX_FMT_RGB32) - av_log(c, AV_LOG_VERBOSE, "SwScaler: using %s YV12->BGR32 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); - else if(dstFormat==PIX_FMT_BGR565) - av_log(c, AV_LOG_VERBOSE, "SwScaler: using %s YV12->BGR16 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); - else if(dstFormat==PIX_FMT_BGR555) - av_log(c, AV_LOG_VERBOSE, "SwScaler: using %s YV12->BGR15 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); - - av_log(c, AV_LOG_VERBOSE, "SwScaler: %dx%d -> %dx%d\n", srcW, srcH, dstW, dstH); - } - if(flags & SWS_PRINT_INFO) - { - av_log(c, AV_LOG_DEBUG, "SwScaler:Lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", - c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc); - av_log(c, AV_LOG_DEBUG, "SwScaler:Chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", - c->chrSrcW, c->chrSrcH, c->chrDstW, c->chrDstH, c->chrXInc, c->chrYInc); - } - - c->swScale= getSwsFunc(flags); - return c; + } + if (isPlanarYUV(dstFormat)) + { + if (c->vLumFilterSize==1) + av_log(c, AV_LOG_VERBOSE, "SwScaler: using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + else + av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap %s scaler for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + } + else + { + if (c->vLumFilterSize==1 && c->vChrFilterSize==2) + av_log(c, AV_LOG_VERBOSE, "SwScaler: using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n" + "SwScaler: 2-tap scaler for vertical chrominance scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + else if (c->vLumFilterSize==2 && c->vChrFilterSize==2) + av_log(c, AV_LOG_VERBOSE, "SwScaler: using 2-tap linear %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + else + av_log(c, AV_LOG_VERBOSE, "SwScaler: using n-tap %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + } + + if (dstFormat==PIX_FMT_BGR24) + av_log(c, AV_LOG_VERBOSE, "SwScaler: using %s YV12->BGR24 Converter\n", + (flags & SWS_CPU_CAPS_MMX2) ? "MMX2" : ((flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C")); + else if (dstFormat==PIX_FMT_RGB32) + av_log(c, AV_LOG_VERBOSE, "SwScaler: using %s YV12->BGR32 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + else if (dstFormat==PIX_FMT_BGR565) + av_log(c, AV_LOG_VERBOSE, "SwScaler: using %s YV12->BGR16 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + else if (dstFormat==PIX_FMT_BGR555) + av_log(c, AV_LOG_VERBOSE, "SwScaler: using %s YV12->BGR15 Converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); + + av_log(c, AV_LOG_VERBOSE, "SwScaler: %dx%d -> %dx%d\n", srcW, srcH, dstW, dstH); + } + if (flags & SWS_PRINT_INFO) + { + av_log(c, AV_LOG_DEBUG, "SwScaler:Lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", + c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc); + av_log(c, AV_LOG_DEBUG, "SwScaler:Chr srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", + c->chrSrcW, c->chrSrcH, c->chrDstW, c->chrDstH, c->chrXInc, c->chrYInc); + } + + c->swScale= getSwsFunc(flags); + return c; } /** - * swscale warper, so we don't need to export the SwsContext. + * swscale wrapper, so we don't need to export the SwsContext. * assumes planar YUV to be in YUV order instead of YVU */ int sws_scale(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]){ - if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) { - av_log(c, AV_LOG_ERROR, "swScaler: slices start in the middle!\n"); - return 0; - } - if (c->sliceDir == 0) { - if (srcSliceY == 0) c->sliceDir = 1; else c->sliceDir = -1; - } - - // copy strides, so they can safely be modified - if (c->sliceDir == 1) { - uint8_t* src2[4]= {src[0], src[1], src[2]}; - // slices go from top to bottom - int srcStride2[4]= {srcStride[0], srcStride[1], srcStride[2]}; - int dstStride2[4]= {dstStride[0], dstStride[1], dstStride[2]}; - return c->swScale(c, src2, srcStride2, srcSliceY, srcSliceH, dst, dstStride2); - } else { - // slices go from bottom to top => we flip the image internally - uint8_t* src2[4]= {src[0] + (srcSliceH-1)*srcStride[0], - src[1] + ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[1], - src[2] + ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[2] - }; - uint8_t* dst2[4]= {dst[0] + (c->dstH-1)*dstStride[0], - dst[1] + ((c->dstH>>c->chrDstVSubSample)-1)*dstStride[1], - dst[2] + ((c->dstH>>c->chrDstVSubSample)-1)*dstStride[2]}; - int srcStride2[4]= {-srcStride[0], -srcStride[1], -srcStride[2]}; - int dstStride2[4]= {-dstStride[0], -dstStride[1], -dstStride[2]}; - - return c->swScale(c, src2, srcStride2, c->srcH-srcSliceY-srcSliceH, srcSliceH, dst2, dstStride2); - } + int srcSliceH, uint8_t* dst[], int dstStride[]){ + int i; + uint8_t* src2[4]= {src[0], src[1], src[2]}; + uint32_t pal[256]; + if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) { + av_log(c, AV_LOG_ERROR, "swScaler: slices start in the middle!\n"); + return 0; + } + if (c->sliceDir == 0) { + if (srcSliceY == 0) c->sliceDir = 1; else c->sliceDir = -1; + } + + if (c->srcFormat == PIX_FMT_PAL8){ + for (i=0; i<256; i++){ + int p= ((uint32_t*)(src[1]))[i]; + int r= (p>>16)&0xFF; + int g= (p>> 8)&0xFF; + int b= p &0xFF; + int y= av_clip_uint8(((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16 ); + int u= av_clip_uint8(((RU*r + GU*g + BU*b)>>RGB2YUV_SHIFT) + 128); + int v= av_clip_uint8(((RV*r + GV*g + BV*b)>>RGB2YUV_SHIFT) + 128); + pal[i]= y + (u<<8) + (v<<16); + } + src2[1]= pal; + } + + // copy strides, so they can safely be modified + if (c->sliceDir == 1) { + // slices go from top to bottom + int srcStride2[4]= {srcStride[0], srcStride[1], srcStride[2]}; + int dstStride2[4]= {dstStride[0], dstStride[1], dstStride[2]}; + return c->swScale(c, src2, srcStride2, srcSliceY, srcSliceH, dst, dstStride2); + } else { + // slices go from bottom to top => we flip the image internally + uint8_t* dst2[4]= {dst[0] + (c->dstH-1)*dstStride[0], + dst[1] + ((c->dstH>>c->chrDstVSubSample)-1)*dstStride[1], + dst[2] + ((c->dstH>>c->chrDstVSubSample)-1)*dstStride[2]}; + int srcStride2[4]= {-srcStride[0], -srcStride[1], -srcStride[2]}; + int dstStride2[4]= {-dstStride[0], -dstStride[1], -dstStride[2]}; + + src2[0] += (srcSliceH-1)*srcStride[0]; + if (c->srcFormat != PIX_FMT_PAL8) + src2[1] += ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[1]; + src2[2] += ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[2]; + + return c->swScale(c, src2, srcStride2, c->srcH-srcSliceY-srcSliceH, srcSliceH, dst2, dstStride2); + } } /** - * swscale warper, so we don't need to export the SwsContext + * swscale wrapper, so we don't need to export the SwsContext */ int sws_scale_ordered(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]){ - return sws_scale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride); + int srcSliceH, uint8_t* dst[], int dstStride[]){ + return sws_scale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride); } -SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, - float lumaSharpen, float chromaSharpen, - float chromaHShift, float chromaVShift, - int verbose) +SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, + float lumaSharpen, float chromaSharpen, + float chromaHShift, float chromaVShift, + int verbose) { - SwsFilter *filter= av_malloc(sizeof(SwsFilter)); - - if(lumaGBlur!=0.0){ - filter->lumH= sws_getGaussianVec(lumaGBlur, 3.0); - filter->lumV= sws_getGaussianVec(lumaGBlur, 3.0); - }else{ - filter->lumH= sws_getIdentityVec(); - filter->lumV= sws_getIdentityVec(); - } - - if(chromaGBlur!=0.0){ - filter->chrH= sws_getGaussianVec(chromaGBlur, 3.0); - filter->chrV= sws_getGaussianVec(chromaGBlur, 3.0); - }else{ - filter->chrH= sws_getIdentityVec(); - filter->chrV= sws_getIdentityVec(); - } - - if(chromaSharpen!=0.0){ - SwsVector *id= sws_getIdentityVec(); - sws_scaleVec(filter->chrH, -chromaSharpen); - sws_scaleVec(filter->chrV, -chromaSharpen); - sws_addVec(filter->chrH, id); - sws_addVec(filter->chrV, id); - sws_freeVec(id); - } - - if(lumaSharpen!=0.0){ - SwsVector *id= sws_getIdentityVec(); - sws_scaleVec(filter->lumH, -lumaSharpen); - sws_scaleVec(filter->lumV, -lumaSharpen); - sws_addVec(filter->lumH, id); - sws_addVec(filter->lumV, id); - sws_freeVec(id); - } - - if(chromaHShift != 0.0) - sws_shiftVec(filter->chrH, (int)(chromaHShift+0.5)); - - if(chromaVShift != 0.0) - sws_shiftVec(filter->chrV, (int)(chromaVShift+0.5)); - - sws_normalizeVec(filter->chrH, 1.0); - sws_normalizeVec(filter->chrV, 1.0); - sws_normalizeVec(filter->lumH, 1.0); - sws_normalizeVec(filter->lumV, 1.0); - - if(verbose) sws_printVec(filter->chrH); - if(verbose) sws_printVec(filter->lumH); - - return filter; + SwsFilter *filter= av_malloc(sizeof(SwsFilter)); + + if (lumaGBlur!=0.0){ + filter->lumH= sws_getGaussianVec(lumaGBlur, 3.0); + filter->lumV= sws_getGaussianVec(lumaGBlur, 3.0); + }else{ + filter->lumH= sws_getIdentityVec(); + filter->lumV= sws_getIdentityVec(); + } + + if (chromaGBlur!=0.0){ + filter->chrH= sws_getGaussianVec(chromaGBlur, 3.0); + filter->chrV= sws_getGaussianVec(chromaGBlur, 3.0); + }else{ + filter->chrH= sws_getIdentityVec(); + filter->chrV= sws_getIdentityVec(); + } + + if (chromaSharpen!=0.0){ + SwsVector *id= sws_getIdentityVec(); + sws_scaleVec(filter->chrH, -chromaSharpen); + sws_scaleVec(filter->chrV, -chromaSharpen); + sws_addVec(filter->chrH, id); + sws_addVec(filter->chrV, id); + sws_freeVec(id); + } + + if (lumaSharpen!=0.0){ + SwsVector *id= sws_getIdentityVec(); + sws_scaleVec(filter->lumH, -lumaSharpen); + sws_scaleVec(filter->lumV, -lumaSharpen); + sws_addVec(filter->lumH, id); + sws_addVec(filter->lumV, id); + sws_freeVec(id); + } + + if (chromaHShift != 0.0) + sws_shiftVec(filter->chrH, (int)(chromaHShift+0.5)); + + if (chromaVShift != 0.0) + sws_shiftVec(filter->chrV, (int)(chromaVShift+0.5)); + + sws_normalizeVec(filter->chrH, 1.0); + sws_normalizeVec(filter->chrV, 1.0); + sws_normalizeVec(filter->lumH, 1.0); + sws_normalizeVec(filter->lumV, 1.0); + + if (verbose) sws_printVec(filter->chrH); + if (verbose) sws_printVec(filter->lumH); + + return filter; } /** @@ -2533,303 +2645,303 @@ SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, * quality=3 is high quality, lowwer is lowwer quality */ SwsVector *sws_getGaussianVec(double variance, double quality){ - const int length= (int)(variance*quality + 0.5) | 1; - int i; - double *coeff= av_malloc(length*sizeof(double)); - double middle= (length-1)*0.5; - SwsVector *vec= av_malloc(sizeof(SwsVector)); + const int length= (int)(variance*quality + 0.5) | 1; + int i; + double *coeff= av_malloc(length*sizeof(double)); + double middle= (length-1)*0.5; + SwsVector *vec= av_malloc(sizeof(SwsVector)); - vec->coeff= coeff; - vec->length= length; + vec->coeff= coeff; + vec->length= length; - for(i=0; icoeff= coeff; - vec->length= length; + vec->coeff= coeff; + vec->length= length; - for(i=0; ilength; i++) - sum+= a->coeff[i]; + for (i=0; ilength; i++) + sum+= a->coeff[i]; - return sum; + return sum; } void sws_scaleVec(SwsVector *a, double scalar){ - int i; + int i; - for(i=0; ilength; i++) - a->coeff[i]*= scalar; + for (i=0; ilength; i++) + a->coeff[i]*= scalar; } void sws_normalizeVec(SwsVector *a, double height){ - sws_scaleVec(a, height/sws_dcVec(a)); + sws_scaleVec(a, height/sws_dcVec(a)); } static SwsVector *sws_getConvVec(SwsVector *a, SwsVector *b){ - int length= a->length + b->length - 1; - double *coeff= av_malloc(length*sizeof(double)); - int i, j; - SwsVector *vec= av_malloc(sizeof(SwsVector)); + int length= a->length + b->length - 1; + double *coeff= av_malloc(length*sizeof(double)); + int i, j; + SwsVector *vec= av_malloc(sizeof(SwsVector)); - vec->coeff= coeff; - vec->length= length; + vec->coeff= coeff; + vec->length= length; - for(i=0; ilength; i++) - { - for(j=0; jlength; j++) - { - coeff[i+j]+= a->coeff[i]*b->coeff[j]; - } - } + for (i=0; ilength; i++) + { + for (j=0; jlength; j++) + { + coeff[i+j]+= a->coeff[i]*b->coeff[j]; + } + } - return vec; + return vec; } static SwsVector *sws_sumVec(SwsVector *a, SwsVector *b){ - int length= FFMAX(a->length, b->length); - double *coeff= av_malloc(length*sizeof(double)); - int i; - SwsVector *vec= av_malloc(sizeof(SwsVector)); + int length= FFMAX(a->length, b->length); + double *coeff= av_malloc(length*sizeof(double)); + int i; + SwsVector *vec= av_malloc(sizeof(SwsVector)); - vec->coeff= coeff; - vec->length= length; + vec->coeff= coeff; + vec->length= length; - for(i=0; ilength; i++) coeff[i + (length-1)/2 - (a->length-1)/2]+= a->coeff[i]; - for(i=0; ilength; i++) coeff[i + (length-1)/2 - (b->length-1)/2]+= b->coeff[i]; + for (i=0; ilength; i++) coeff[i + (length-1)/2 - (a->length-1)/2]+= a->coeff[i]; + for (i=0; ilength; i++) coeff[i + (length-1)/2 - (b->length-1)/2]+= b->coeff[i]; - return vec; + return vec; } static SwsVector *sws_diffVec(SwsVector *a, SwsVector *b){ - int length= FFMAX(a->length, b->length); - double *coeff= av_malloc(length*sizeof(double)); - int i; - SwsVector *vec= av_malloc(sizeof(SwsVector)); + int length= FFMAX(a->length, b->length); + double *coeff= av_malloc(length*sizeof(double)); + int i; + SwsVector *vec= av_malloc(sizeof(SwsVector)); - vec->coeff= coeff; - vec->length= length; + vec->coeff= coeff; + vec->length= length; - for(i=0; ilength; i++) coeff[i + (length-1)/2 - (a->length-1)/2]+= a->coeff[i]; - for(i=0; ilength; i++) coeff[i + (length-1)/2 - (b->length-1)/2]-= b->coeff[i]; + for (i=0; ilength; i++) coeff[i + (length-1)/2 - (a->length-1)/2]+= a->coeff[i]; + for (i=0; ilength; i++) coeff[i + (length-1)/2 - (b->length-1)/2]-= b->coeff[i]; - return vec; + return vec; } /* shift left / or right if "shift" is negative */ static SwsVector *sws_getShiftedVec(SwsVector *a, int shift){ - int length= a->length + FFABS(shift)*2; - double *coeff= av_malloc(length*sizeof(double)); - int i; - SwsVector *vec= av_malloc(sizeof(SwsVector)); + int length= a->length + FFABS(shift)*2; + double *coeff= av_malloc(length*sizeof(double)); + int i; + SwsVector *vec= av_malloc(sizeof(SwsVector)); - vec->coeff= coeff; - vec->length= length; + vec->coeff= coeff; + vec->length= length; - for(i=0; ilength; i++) - { - coeff[i + (length-1)/2 - (a->length-1)/2 - shift]= a->coeff[i]; - } + for (i=0; ilength; i++) + { + coeff[i + (length-1)/2 - (a->length-1)/2 - shift]= a->coeff[i]; + } - return vec; + return vec; } void sws_shiftVec(SwsVector *a, int shift){ - SwsVector *shifted= sws_getShiftedVec(a, shift); - av_free(a->coeff); - a->coeff= shifted->coeff; - a->length= shifted->length; - av_free(shifted); + SwsVector *shifted= sws_getShiftedVec(a, shift); + av_free(a->coeff); + a->coeff= shifted->coeff; + a->length= shifted->length; + av_free(shifted); } void sws_addVec(SwsVector *a, SwsVector *b){ - SwsVector *sum= sws_sumVec(a, b); - av_free(a->coeff); - a->coeff= sum->coeff; - a->length= sum->length; - av_free(sum); + SwsVector *sum= sws_sumVec(a, b); + av_free(a->coeff); + a->coeff= sum->coeff; + a->length= sum->length; + av_free(sum); } void sws_subVec(SwsVector *a, SwsVector *b){ - SwsVector *diff= sws_diffVec(a, b); - av_free(a->coeff); - a->coeff= diff->coeff; - a->length= diff->length; - av_free(diff); + SwsVector *diff= sws_diffVec(a, b); + av_free(a->coeff); + a->coeff= diff->coeff; + a->length= diff->length; + av_free(diff); } void sws_convVec(SwsVector *a, SwsVector *b){ - SwsVector *conv= sws_getConvVec(a, b); - av_free(a->coeff); - a->coeff= conv->coeff; - a->length= conv->length; - av_free(conv); + SwsVector *conv= sws_getConvVec(a, b); + av_free(a->coeff); + a->coeff= conv->coeff; + a->length= conv->length; + av_free(conv); } SwsVector *sws_cloneVec(SwsVector *a){ - double *coeff= av_malloc(a->length*sizeof(double)); - int i; - SwsVector *vec= av_malloc(sizeof(SwsVector)); + double *coeff= av_malloc(a->length*sizeof(double)); + int i; + SwsVector *vec= av_malloc(sizeof(SwsVector)); - vec->coeff= coeff; - vec->length= a->length; + vec->coeff= coeff; + vec->length= a->length; - for(i=0; ilength; i++) coeff[i]= a->coeff[i]; + for (i=0; ilength; i++) coeff[i]= a->coeff[i]; - return vec; + return vec; } void sws_printVec(SwsVector *a){ - int i; - double max=0; - double min=0; - double range; - - for(i=0; ilength; i++) - if(a->coeff[i]>max) max= a->coeff[i]; - - for(i=0; ilength; i++) - if(a->coeff[i]coeff[i]; - - range= max - min; - - for(i=0; ilength; i++) - { - int x= (int)((a->coeff[i]-min)*60.0/range +0.5); - av_log(NULL, AV_LOG_DEBUG, "%1.3f ", a->coeff[i]); - for(;x>0; x--) av_log(NULL, AV_LOG_DEBUG, " "); - av_log(NULL, AV_LOG_DEBUG, "|\n"); - } + int i; + double max=0; + double min=0; + double range; + + for (i=0; ilength; i++) + if (a->coeff[i]>max) max= a->coeff[i]; + + for (i=0; ilength; i++) + if (a->coeff[i]coeff[i]; + + range= max - min; + + for (i=0; ilength; i++) + { + int x= (int)((a->coeff[i]-min)*60.0/range +0.5); + av_log(NULL, AV_LOG_DEBUG, "%1.3f ", a->coeff[i]); + for (;x>0; x--) av_log(NULL, AV_LOG_DEBUG, " "); + av_log(NULL, AV_LOG_DEBUG, "|\n"); + } } void sws_freeVec(SwsVector *a){ - if(!a) return; - av_free(a->coeff); - a->coeff=NULL; - a->length=0; - av_free(a); + if (!a) return; + av_free(a->coeff); + a->coeff=NULL; + a->length=0; + av_free(a); } void sws_freeFilter(SwsFilter *filter){ - if(!filter) return; + if (!filter) return; - if(filter->lumH) sws_freeVec(filter->lumH); - if(filter->lumV) sws_freeVec(filter->lumV); - if(filter->chrH) sws_freeVec(filter->chrH); - if(filter->chrV) sws_freeVec(filter->chrV); - av_free(filter); + if (filter->lumH) sws_freeVec(filter->lumH); + if (filter->lumV) sws_freeVec(filter->lumV); + if (filter->chrH) sws_freeVec(filter->chrH); + if (filter->chrV) sws_freeVec(filter->chrV); + av_free(filter); } void sws_freeContext(SwsContext *c){ - int i; - if(!c) return; - - if(c->lumPixBuf) - { - for(i=0; ivLumBufSize; i++) - { - av_free(c->lumPixBuf[i]); - c->lumPixBuf[i]=NULL; - } - av_free(c->lumPixBuf); - c->lumPixBuf=NULL; - } - - if(c->chrPixBuf) - { - for(i=0; ivChrBufSize; i++) - { - av_free(c->chrPixBuf[i]); - c->chrPixBuf[i]=NULL; - } - av_free(c->chrPixBuf); - c->chrPixBuf=NULL; - } - - av_free(c->vLumFilter); - c->vLumFilter = NULL; - av_free(c->vChrFilter); - c->vChrFilter = NULL; - av_free(c->hLumFilter); - c->hLumFilter = NULL; - av_free(c->hChrFilter); - c->hChrFilter = NULL; + int i; + if (!c) return; + + if (c->lumPixBuf) + { + for (i=0; ivLumBufSize; i++) + { + av_free(c->lumPixBuf[i]); + c->lumPixBuf[i]=NULL; + } + av_free(c->lumPixBuf); + c->lumPixBuf=NULL; + } + + if (c->chrPixBuf) + { + for (i=0; ivChrBufSize; i++) + { + av_free(c->chrPixBuf[i]); + c->chrPixBuf[i]=NULL; + } + av_free(c->chrPixBuf); + c->chrPixBuf=NULL; + } + + av_free(c->vLumFilter); + c->vLumFilter = NULL; + av_free(c->vChrFilter); + c->vChrFilter = NULL; + av_free(c->hLumFilter); + c->hLumFilter = NULL; + av_free(c->hChrFilter); + c->hChrFilter = NULL; #ifdef HAVE_ALTIVEC - av_free(c->vYCoeffsBank); - c->vYCoeffsBank = NULL; - av_free(c->vCCoeffsBank); - c->vCCoeffsBank = NULL; + av_free(c->vYCoeffsBank); + c->vYCoeffsBank = NULL; + av_free(c->vCCoeffsBank); + c->vCCoeffsBank = NULL; #endif - av_free(c->vLumFilterPos); - c->vLumFilterPos = NULL; - av_free(c->vChrFilterPos); - c->vChrFilterPos = NULL; - av_free(c->hLumFilterPos); - c->hLumFilterPos = NULL; - av_free(c->hChrFilterPos); - c->hChrFilterPos = NULL; + av_free(c->vLumFilterPos); + c->vLumFilterPos = NULL; + av_free(c->vChrFilterPos); + c->vChrFilterPos = NULL; + av_free(c->hLumFilterPos); + c->hLumFilterPos = NULL; + av_free(c->hChrFilterPos); + c->hChrFilterPos = NULL; #if defined(ARCH_X86) && defined(CONFIG_GPL) #ifdef MAP_ANONYMOUS - if(c->funnyYCode) munmap(c->funnyYCode, MAX_FUNNY_CODE_SIZE); - if(c->funnyUVCode) munmap(c->funnyUVCode, MAX_FUNNY_CODE_SIZE); + if (c->funnyYCode) munmap(c->funnyYCode, MAX_FUNNY_CODE_SIZE); + if (c->funnyUVCode) munmap(c->funnyUVCode, MAX_FUNNY_CODE_SIZE); #else - av_free(c->funnyYCode); - av_free(c->funnyUVCode); + av_free(c->funnyYCode); + av_free(c->funnyUVCode); #endif - c->funnyYCode=NULL; - c->funnyUVCode=NULL; + c->funnyYCode=NULL; + c->funnyUVCode=NULL; #endif /* defined(ARCH_X86) */ - av_free(c->lumMmx2Filter); - c->lumMmx2Filter=NULL; - av_free(c->chrMmx2Filter); - c->chrMmx2Filter=NULL; - av_free(c->lumMmx2FilterPos); - c->lumMmx2FilterPos=NULL; - av_free(c->chrMmx2FilterPos); - c->chrMmx2FilterPos=NULL; - av_free(c->yuvTable); - c->yuvTable=NULL; - - av_free(c); + av_free(c->lumMmx2Filter); + c->lumMmx2Filter=NULL; + av_free(c->chrMmx2Filter); + c->chrMmx2Filter=NULL; + av_free(c->lumMmx2FilterPos); + c->lumMmx2FilterPos=NULL; + av_free(c->chrMmx2FilterPos); + c->chrMmx2FilterPos=NULL; + av_free(c->yuvTable); + c->yuvTable=NULL; + + av_free(c); } /** @@ -2843,25 +2955,30 @@ void sws_freeContext(SwsContext *c){ * asumed to remain valid. */ struct SwsContext *sws_getCachedContext(struct SwsContext *context, - int srcW, int srcH, int srcFormat, - int dstW, int dstH, int dstFormat, int flags, - SwsFilter *srcFilter, SwsFilter *dstFilter, double *param) + int srcW, int srcH, int srcFormat, + int dstW, int dstH, int dstFormat, int flags, + SwsFilter *srcFilter, SwsFilter *dstFilter, double *param) { - if (context != NULL) { - if ((context->srcW != srcW) || (context->srcH != srcH) || - (context->srcFormat != srcFormat) || - (context->dstW != dstW) || (context->dstH != dstH) || - (context->dstFormat != dstFormat) || (context->flags != flags) || - (context->param != param)) + static const double default_param[2] = {SWS_PARAM_DEFAULT, SWS_PARAM_DEFAULT}; + + if (!param) + param = default_param; + + if (context) { + if (context->srcW != srcW || context->srcH != srcH || + context->srcFormat != srcFormat || + context->dstW != dstW || context->dstH != dstH || + context->dstFormat != dstFormat || context->flags != flags || + context->param[0] != param[0] || context->param[1] != param[1]) { sws_freeContext(context); context = NULL; } } - if (context == NULL) { + if (!context) { return sws_getContext(srcW, srcH, srcFormat, - dstW, dstH, dstFormat, flags, - srcFilter, dstFilter, param); + dstW, dstH, dstFormat, flags, + srcFilter, dstFilter, param); } return context; } diff --git a/contrib/ffmpeg/libswscale/swscale.h b/contrib/ffmpeg/libswscale/swscale.h index 27d1aa3ef..afd3ff375 100644 --- a/contrib/ffmpeg/libswscale/swscale.h +++ b/contrib/ffmpeg/libswscale/swscale.h @@ -15,91 +15,93 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef SWSCALE_H -#define SWSCALE_H +#ifndef FFMPEG_SWSCALE_H +#define FFMPEG_SWSCALE_H /** * @file swscale.h - * @brief + * @brief * external api for the swscale stuff */ -#include "avutil.h" +#include "libavutil/avutil.h" -#ifdef __cplusplus -extern "C" { -#endif +#define LIBSWSCALE_VERSION_MAJOR 0 +#define LIBSWSCALE_VERSION_MINOR 5 +#define LIBSWSCALE_VERSION_MICRO 0 -#define AV_STRINGIFY(s) AV_TOSTRING(s) -#define AV_TOSTRING(s) #s - -#define LIBSWSCALE_VERSION_INT ((0<<16)+(5<<8)+0) -#define LIBSWSCALE_VERSION 0.5.0 +#define LIBSWSCALE_VERSION_INT AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \ + LIBSWSCALE_VERSION_MINOR, \ + LIBSWSCALE_VERSION_MICRO) +#define LIBSWSCALE_VERSION AV_VERSION(LIBSWSCALE_VERSION_MAJOR, \ + LIBSWSCALE_VERSION_MINOR, \ + LIBSWSCALE_VERSION_MICRO) #define LIBSWSCALE_BUILD LIBSWSCALE_VERSION_INT #define LIBSWSCALE_IDENT "SwS" AV_STRINGIFY(LIBSWSCALE_VERSION) /* values for the flags, the stuff on the command line is different */ -#define SWS_FAST_BILINEAR 1 -#define SWS_BILINEAR 2 -#define SWS_BICUBIC 4 -#define SWS_X 8 -#define SWS_POINT 0x10 -#define SWS_AREA 0x20 -#define SWS_BICUBLIN 0x40 -#define SWS_GAUSS 0x80 -#define SWS_SINC 0x100 -#define SWS_LANCZOS 0x200 -#define SWS_SPLINE 0x400 - -#define SWS_SRC_V_CHR_DROP_MASK 0x30000 -#define SWS_SRC_V_CHR_DROP_SHIFT 16 - -#define SWS_PARAM_DEFAULT 123456 - -#define SWS_PRINT_INFO 0x1000 - -//the following 3 flags are not completly implemented -//internal chrominace subsamling info -#define SWS_FULL_CHR_H_INT 0x2000 +#define SWS_FAST_BILINEAR 1 +#define SWS_BILINEAR 2 +#define SWS_BICUBIC 4 +#define SWS_X 8 +#define SWS_POINT 0x10 +#define SWS_AREA 0x20 +#define SWS_BICUBLIN 0x40 +#define SWS_GAUSS 0x80 +#define SWS_SINC 0x100 +#define SWS_LANCZOS 0x200 +#define SWS_SPLINE 0x400 + +#define SWS_SRC_V_CHR_DROP_MASK 0x30000 +#define SWS_SRC_V_CHR_DROP_SHIFT 16 + +#define SWS_PARAM_DEFAULT 123456 + +#define SWS_PRINT_INFO 0x1000 + +//the following 3 flags are not completely implemented +//internal chrominace subsampling info +#define SWS_FULL_CHR_H_INT 0x2000 //input subsampling info -#define SWS_FULL_CHR_H_INP 0x4000 -#define SWS_DIRECT_BGR 0x8000 -#define SWS_ACCURATE_RND 0x40000 +#define SWS_FULL_CHR_H_INP 0x4000 +#define SWS_DIRECT_BGR 0x8000 +#define SWS_ACCURATE_RND 0x40000 -#define SWS_CPU_CAPS_MMX 0x80000000 -#define SWS_CPU_CAPS_MMX2 0x20000000 -#define SWS_CPU_CAPS_3DNOW 0x40000000 -#define SWS_CPU_CAPS_ALTIVEC 0x10000000 +#define SWS_CPU_CAPS_MMX 0x80000000 +#define SWS_CPU_CAPS_MMX2 0x20000000 +#define SWS_CPU_CAPS_3DNOW 0x40000000 +#define SWS_CPU_CAPS_ALTIVEC 0x10000000 +#define SWS_CPU_CAPS_BFIN 0x01000000 #define SWS_MAX_REDUCE_CUTOFF 0.002 -#define SWS_CS_ITU709 1 -#define SWS_CS_FCC 4 -#define SWS_CS_ITU601 5 -#define SWS_CS_ITU624 5 -#define SWS_CS_SMPTE170M 5 -#define SWS_CS_SMPTE240M 7 -#define SWS_CS_DEFAULT 5 +#define SWS_CS_ITU709 1 +#define SWS_CS_FCC 4 +#define SWS_CS_ITU601 5 +#define SWS_CS_ITU624 5 +#define SWS_CS_SMPTE170M 5 +#define SWS_CS_SMPTE240M 7 +#define SWS_CS_DEFAULT 5 // when used for filters they must have an odd number of elements // coeffs cannot be shared between vectors typedef struct { - double *coeff; - int length; + double *coeff; + int length; } SwsVector; // vectors can be shared typedef struct { - SwsVector *lumH; - SwsVector *lumV; - SwsVector *chrH; - SwsVector *chrV; + SwsVector *lumH; + SwsVector *lumV; + SwsVector *chrH; + SwsVector *chrV; } SwsFilter; struct SwsContext; @@ -107,11 +109,11 @@ struct SwsContext; void sws_freeContext(struct SwsContext *swsContext); struct SwsContext *sws_getContext(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags, - SwsFilter *srcFilter, SwsFilter *dstFilter, double *param); + SwsFilter *srcFilter, SwsFilter *dstFilter, double *param); int sws_scale(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]); + int srcSliceH, uint8_t* dst[], int dstStride[]); int sws_scale_ordered(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]) attribute_deprecated; + int srcSliceH, uint8_t* dst[], int dstStride[]) attribute_deprecated; int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4], int srcRange, const int table[4], int dstRange, int brightness, int contrast, int saturation); @@ -130,19 +132,15 @@ SwsVector *sws_cloneVec(SwsVector *a); void sws_printVec(SwsVector *a); void sws_freeVec(SwsVector *a); -SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, - float lumaSarpen, float chromaSharpen, - float chromaHShift, float chromaVShift, - int verbose); +SwsFilter *sws_getDefaultFilter(float lumaGBlur, float chromaGBlur, + float lumaSarpen, float chromaSharpen, + float chromaHShift, float chromaVShift, + int verbose); void sws_freeFilter(SwsFilter *filter); struct SwsContext *sws_getCachedContext(struct SwsContext *context, - int srcW, int srcH, int srcFormat, - int dstW, int dstH, int dstFormat, int flags, - SwsFilter *srcFilter, SwsFilter *dstFilter, double *param); - -#ifdef __cplusplus -} -#endif + int srcW, int srcH, int srcFormat, + int dstW, int dstH, int dstFormat, int flags, + SwsFilter *srcFilter, SwsFilter *dstFilter, double *param); -#endif +#endif /* FFMPEG_SWSCALE_H */ diff --git a/contrib/ffmpeg/libswscale/swscale_altivec_template.c b/contrib/ffmpeg/libswscale/swscale_altivec_template.c index 251b38ca1..47b7e0dc6 100644 --- a/contrib/ffmpeg/libswscale/swscale_altivec_template.c +++ b/contrib/ffmpeg/libswscale/swscale_altivec_template.c @@ -2,7 +2,7 @@ * AltiVec-enhanced yuv2yuvX * * Copyright (C) 2004 Romain Dolbeau - * based on the equivalent C code in "postproc/swscale.c" + * based on the equivalent C code in swscale.c * * This file is part of FFmpeg. * @@ -18,531 +18,521 @@ * * You should have received a copy of the GNU General Public License * along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifdef CONFIG_DARWIN -#define AVV(x...) (x) -#else -#define AVV(x...) {x} -#endif - #define vzero vec_splat_s32(0) static inline void altivec_packIntArrayToCharArray(int *val, uint8_t* dest, int dstW) { - register int i; - vector unsigned int altivec_vectorShiftInt19 = - vec_add(vec_splat_u32(10),vec_splat_u32(9)); - if ((unsigned long)dest % 16) { - /* badly aligned store, we force store alignement */ - /* and will handle load misalignement on val w/ vec_perm */ - vector unsigned char perm1; - vector signed int v1; - for (i = 0 ; (i < dstW) && - (((unsigned long)dest + i) % 16) ; i++) { - int t = val[i] >> 19; - dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t); - } - perm1 = vec_lvsl(i << 2, val); - v1 = vec_ld(i << 2, val); - for ( ; i < (dstW - 15); i+=16) { - int offset = i << 2; - vector signed int v2 = vec_ld(offset + 16, val); - vector signed int v3 = vec_ld(offset + 32, val); - vector signed int v4 = vec_ld(offset + 48, val); - vector signed int v5 = vec_ld(offset + 64, val); - vector signed int v12 = vec_perm(v1,v2,perm1); - vector signed int v23 = vec_perm(v2,v3,perm1); - vector signed int v34 = vec_perm(v3,v4,perm1); - vector signed int v45 = vec_perm(v4,v5,perm1); - - vector signed int vA = vec_sra(v12, altivec_vectorShiftInt19); - vector signed int vB = vec_sra(v23, altivec_vectorShiftInt19); - vector signed int vC = vec_sra(v34, altivec_vectorShiftInt19); - vector signed int vD = vec_sra(v45, altivec_vectorShiftInt19); - vector unsigned short vs1 = vec_packsu(vA, vB); - vector unsigned short vs2 = vec_packsu(vC, vD); - vector unsigned char vf = vec_packsu(vs1, vs2); - vec_st(vf, i, dest); - v1 = v5; + register int i; + vector unsigned int altivec_vectorShiftInt19 = + vec_add(vec_splat_u32(10), vec_splat_u32(9)); + if ((unsigned long)dest % 16) { + /* badly aligned store, we force store alignment */ + /* and will handle load misalignment on val w/ vec_perm */ + vector unsigned char perm1; + vector signed int v1; + for (i = 0 ; (i < dstW) && + (((unsigned long)dest + i) % 16) ; i++) { + int t = val[i] >> 19; + dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t); + } + perm1 = vec_lvsl(i << 2, val); + v1 = vec_ld(i << 2, val); + for ( ; i < (dstW - 15); i+=16) { + int offset = i << 2; + vector signed int v2 = vec_ld(offset + 16, val); + vector signed int v3 = vec_ld(offset + 32, val); + vector signed int v4 = vec_ld(offset + 48, val); + vector signed int v5 = vec_ld(offset + 64, val); + vector signed int v12 = vec_perm(v1, v2, perm1); + vector signed int v23 = vec_perm(v2, v3, perm1); + vector signed int v34 = vec_perm(v3, v4, perm1); + vector signed int v45 = vec_perm(v4, v5, perm1); + + vector signed int vA = vec_sra(v12, altivec_vectorShiftInt19); + vector signed int vB = vec_sra(v23, altivec_vectorShiftInt19); + vector signed int vC = vec_sra(v34, altivec_vectorShiftInt19); + vector signed int vD = vec_sra(v45, altivec_vectorShiftInt19); + vector unsigned short vs1 = vec_packsu(vA, vB); + vector unsigned short vs2 = vec_packsu(vC, vD); + vector unsigned char vf = vec_packsu(vs1, vs2); + vec_st(vf, i, dest); + v1 = v5; + } + } else { // dest is properly aligned, great + for (i = 0; i < (dstW - 15); i+=16) { + int offset = i << 2; + vector signed int v1 = vec_ld(offset, val); + vector signed int v2 = vec_ld(offset + 16, val); + vector signed int v3 = vec_ld(offset + 32, val); + vector signed int v4 = vec_ld(offset + 48, val); + vector signed int v5 = vec_sra(v1, altivec_vectorShiftInt19); + vector signed int v6 = vec_sra(v2, altivec_vectorShiftInt19); + vector signed int v7 = vec_sra(v3, altivec_vectorShiftInt19); + vector signed int v8 = vec_sra(v4, altivec_vectorShiftInt19); + vector unsigned short vs1 = vec_packsu(v5, v6); + vector unsigned short vs2 = vec_packsu(v7, v8); + vector unsigned char vf = vec_packsu(vs1, vs2); + vec_st(vf, i, dest); + } } - } else { // dest is properly aligned, great - for (i = 0; i < (dstW - 15); i+=16) { - int offset = i << 2; - vector signed int v1 = vec_ld(offset, val); - vector signed int v2 = vec_ld(offset + 16, val); - vector signed int v3 = vec_ld(offset + 32, val); - vector signed int v4 = vec_ld(offset + 48, val); - vector signed int v5 = vec_sra(v1, altivec_vectorShiftInt19); - vector signed int v6 = vec_sra(v2, altivec_vectorShiftInt19); - vector signed int v7 = vec_sra(v3, altivec_vectorShiftInt19); - vector signed int v8 = vec_sra(v4, altivec_vectorShiftInt19); - vector unsigned short vs1 = vec_packsu(v5, v6); - vector unsigned short vs2 = vec_packsu(v7, v8); - vector unsigned char vf = vec_packsu(vs1, vs2); - vec_st(vf, i, dest); + for ( ; i < dstW ; i++) { + int t = val[i] >> 19; + dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t); } - } - for ( ; i < dstW ; i++) { - int t = val[i] >> 19; - dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t); - } } static inline void yuv2yuvX_altivec_real(int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize, - int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, - uint8_t *dest, uint8_t *uDest, uint8_t *vDest, int dstW, int chrDstW) + int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, + uint8_t *dest, uint8_t *uDest, uint8_t *vDest, int dstW, int chrDstW) { - const vector signed int vini = {(1 << 18), (1 << 18), (1 << 18), (1 << 18)}; - register int i, j; - { - int __attribute__ ((aligned (16))) val[dstW]; - - for (i = 0; i < (dstW -7); i+=4) { - vec_st(vini, i << 2, val); - } - for (; i < dstW; i++) { - val[i] = (1 << 18); - } - - for (j = 0; j < lumFilterSize; j++) { - vector signed short l1, vLumFilter = vec_ld(j << 1, lumFilter); - vector unsigned char perm, perm0 = vec_lvsl(j << 1, lumFilter); - vLumFilter = vec_perm(vLumFilter, vLumFilter, perm0); - vLumFilter = vec_splat(vLumFilter, 0); // lumFilter[j] is loaded 8 times in vLumFilter - - perm = vec_lvsl(0, lumSrc[j]); - l1 = vec_ld(0, lumSrc[j]); - - for (i = 0; i < (dstW - 7); i+=8) { - int offset = i << 2; - vector signed short l2 = vec_ld((i << 1) + 16, lumSrc[j]); - - vector signed int v1 = vec_ld(offset, val); - vector signed int v2 = vec_ld(offset + 16, val); - - vector signed short ls = vec_perm(l1, l2, perm); // lumSrc[j][i] ... lumSrc[j][i+7] - - vector signed int i1 = vec_mule(vLumFilter, ls); - vector signed int i2 = vec_mulo(vLumFilter, ls); - - vector signed int vf1 = vec_mergeh(i1, i2); - vector signed int vf2 = vec_mergel(i1, i2); // lumSrc[j][i] * lumFilter[j] ... lumSrc[j][i+7] * lumFilter[j] - - vector signed int vo1 = vec_add(v1, vf1); - vector signed int vo2 = vec_add(v2, vf2); - - vec_st(vo1, offset, val); - vec_st(vo2, offset + 16, val); - - l1 = l2; - } - for ( ; i < dstW; i++) { - val[i] += lumSrc[j][i] * lumFilter[j]; - } - } - altivec_packIntArrayToCharArray(val,dest,dstW); - } - if (uDest != 0) { - int __attribute__ ((aligned (16))) u[chrDstW]; - int __attribute__ ((aligned (16))) v[chrDstW]; - - for (i = 0; i < (chrDstW -7); i+=4) { - vec_st(vini, i << 2, u); - vec_st(vini, i << 2, v); - } - for (; i < chrDstW; i++) { - u[i] = (1 << 18); - v[i] = (1 << 18); + const vector signed int vini = {(1 << 18), (1 << 18), (1 << 18), (1 << 18)}; + register int i, j; + { + int __attribute__ ((aligned (16))) val[dstW]; + + for (i = 0; i < (dstW -7); i+=4) { + vec_st(vini, i << 2, val); + } + for (; i < dstW; i++) { + val[i] = (1 << 18); + } + + for (j = 0; j < lumFilterSize; j++) { + vector signed short l1, vLumFilter = vec_ld(j << 1, lumFilter); + vector unsigned char perm, perm0 = vec_lvsl(j << 1, lumFilter); + vLumFilter = vec_perm(vLumFilter, vLumFilter, perm0); + vLumFilter = vec_splat(vLumFilter, 0); // lumFilter[j] is loaded 8 times in vLumFilter + + perm = vec_lvsl(0, lumSrc[j]); + l1 = vec_ld(0, lumSrc[j]); + + for (i = 0; i < (dstW - 7); i+=8) { + int offset = i << 2; + vector signed short l2 = vec_ld((i << 1) + 16, lumSrc[j]); + + vector signed int v1 = vec_ld(offset, val); + vector signed int v2 = vec_ld(offset + 16, val); + + vector signed short ls = vec_perm(l1, l2, perm); // lumSrc[j][i] ... lumSrc[j][i+7] + + vector signed int i1 = vec_mule(vLumFilter, ls); + vector signed int i2 = vec_mulo(vLumFilter, ls); + + vector signed int vf1 = vec_mergeh(i1, i2); + vector signed int vf2 = vec_mergel(i1, i2); // lumSrc[j][i] * lumFilter[j] ... lumSrc[j][i+7] * lumFilter[j] + + vector signed int vo1 = vec_add(v1, vf1); + vector signed int vo2 = vec_add(v2, vf2); + + vec_st(vo1, offset, val); + vec_st(vo2, offset + 16, val); + + l1 = l2; + } + for ( ; i < dstW; i++) { + val[i] += lumSrc[j][i] * lumFilter[j]; + } + } + altivec_packIntArrayToCharArray(val, dest, dstW); } - - for (j = 0; j < chrFilterSize; j++) { - vector signed short l1, l1_V, vChrFilter = vec_ld(j << 1, chrFilter); - vector unsigned char perm, perm0 = vec_lvsl(j << 1, chrFilter); - vChrFilter = vec_perm(vChrFilter, vChrFilter, perm0); - vChrFilter = vec_splat(vChrFilter, 0); // chrFilter[j] is loaded 8 times in vChrFilter - - perm = vec_lvsl(0, chrSrc[j]); - l1 = vec_ld(0, chrSrc[j]); - l1_V = vec_ld(2048 << 1, chrSrc[j]); - - for (i = 0; i < (chrDstW - 7); i+=8) { - int offset = i << 2; - vector signed short l2 = vec_ld((i << 1) + 16, chrSrc[j]); - vector signed short l2_V = vec_ld(((i + 2048) << 1) + 16, chrSrc[j]); - - vector signed int v1 = vec_ld(offset, u); - vector signed int v2 = vec_ld(offset + 16, u); - vector signed int v1_V = vec_ld(offset, v); - vector signed int v2_V = vec_ld(offset + 16, v); - - vector signed short ls = vec_perm(l1, l2, perm); // chrSrc[j][i] ... chrSrc[j][i+7] - vector signed short ls_V = vec_perm(l1_V, l2_V, perm); // chrSrc[j][i+2048] ... chrSrc[j][i+2055] - - vector signed int i1 = vec_mule(vChrFilter, ls); - vector signed int i2 = vec_mulo(vChrFilter, ls); - vector signed int i1_V = vec_mule(vChrFilter, ls_V); - vector signed int i2_V = vec_mulo(vChrFilter, ls_V); - - vector signed int vf1 = vec_mergeh(i1, i2); - vector signed int vf2 = vec_mergel(i1, i2); // chrSrc[j][i] * chrFilter[j] ... chrSrc[j][i+7] * chrFilter[j] - vector signed int vf1_V = vec_mergeh(i1_V, i2_V); - vector signed int vf2_V = vec_mergel(i1_V, i2_V); // chrSrc[j][i] * chrFilter[j] ... chrSrc[j][i+7] * chrFilter[j] - - vector signed int vo1 = vec_add(v1, vf1); - vector signed int vo2 = vec_add(v2, vf2); - vector signed int vo1_V = vec_add(v1_V, vf1_V); - vector signed int vo2_V = vec_add(v2_V, vf2_V); - - vec_st(vo1, offset, u); - vec_st(vo2, offset + 16, u); - vec_st(vo1_V, offset, v); - vec_st(vo2_V, offset + 16, v); - - l1 = l2; - l1_V = l2_V; - } - for ( ; i < chrDstW; i++) { - u[i] += chrSrc[j][i] * chrFilter[j]; - v[i] += chrSrc[j][i + 2048] * chrFilter[j]; - } + if (uDest != 0) { + int __attribute__ ((aligned (16))) u[chrDstW]; + int __attribute__ ((aligned (16))) v[chrDstW]; + + for (i = 0; i < (chrDstW -7); i+=4) { + vec_st(vini, i << 2, u); + vec_st(vini, i << 2, v); + } + for (; i < chrDstW; i++) { + u[i] = (1 << 18); + v[i] = (1 << 18); + } + + for (j = 0; j < chrFilterSize; j++) { + vector signed short l1, l1_V, vChrFilter = vec_ld(j << 1, chrFilter); + vector unsigned char perm, perm0 = vec_lvsl(j << 1, chrFilter); + vChrFilter = vec_perm(vChrFilter, vChrFilter, perm0); + vChrFilter = vec_splat(vChrFilter, 0); // chrFilter[j] is loaded 8 times in vChrFilter + + perm = vec_lvsl(0, chrSrc[j]); + l1 = vec_ld(0, chrSrc[j]); + l1_V = vec_ld(2048 << 1, chrSrc[j]); + + for (i = 0; i < (chrDstW - 7); i+=8) { + int offset = i << 2; + vector signed short l2 = vec_ld((i << 1) + 16, chrSrc[j]); + vector signed short l2_V = vec_ld(((i + 2048) << 1) + 16, chrSrc[j]); + + vector signed int v1 = vec_ld(offset, u); + vector signed int v2 = vec_ld(offset + 16, u); + vector signed int v1_V = vec_ld(offset, v); + vector signed int v2_V = vec_ld(offset + 16, v); + + vector signed short ls = vec_perm(l1, l2, perm); // chrSrc[j][i] ... chrSrc[j][i+7] + vector signed short ls_V = vec_perm(l1_V, l2_V, perm); // chrSrc[j][i+2048] ... chrSrc[j][i+2055] + + vector signed int i1 = vec_mule(vChrFilter, ls); + vector signed int i2 = vec_mulo(vChrFilter, ls); + vector signed int i1_V = vec_mule(vChrFilter, ls_V); + vector signed int i2_V = vec_mulo(vChrFilter, ls_V); + + vector signed int vf1 = vec_mergeh(i1, i2); + vector signed int vf2 = vec_mergel(i1, i2); // chrSrc[j][i] * chrFilter[j] ... chrSrc[j][i+7] * chrFilter[j] + vector signed int vf1_V = vec_mergeh(i1_V, i2_V); + vector signed int vf2_V = vec_mergel(i1_V, i2_V); // chrSrc[j][i] * chrFilter[j] ... chrSrc[j][i+7] * chrFilter[j] + + vector signed int vo1 = vec_add(v1, vf1); + vector signed int vo2 = vec_add(v2, vf2); + vector signed int vo1_V = vec_add(v1_V, vf1_V); + vector signed int vo2_V = vec_add(v2_V, vf2_V); + + vec_st(vo1, offset, u); + vec_st(vo2, offset + 16, u); + vec_st(vo1_V, offset, v); + vec_st(vo2_V, offset + 16, v); + + l1 = l2; + l1_V = l2_V; + } + for ( ; i < chrDstW; i++) { + u[i] += chrSrc[j][i] * chrFilter[j]; + v[i] += chrSrc[j][i + 2048] * chrFilter[j]; + } + } + altivec_packIntArrayToCharArray(u, uDest, chrDstW); + altivec_packIntArrayToCharArray(v, vDest, chrDstW); } - altivec_packIntArrayToCharArray(u,uDest,chrDstW); - altivec_packIntArrayToCharArray(v,vDest,chrDstW); - } } static inline void hScale_altivec_real(int16_t *dst, int dstW, uint8_t *src, int srcW, int xInc, int16_t *filter, int16_t *filterPos, int filterSize) { - register int i; - int __attribute__ ((aligned (16))) tempo[4]; - - if (filterSize % 4) { - for(i=0; i>7, 0, (1<<15)-1); + register int i; + int __attribute__ ((aligned (16))) tempo[4]; + + if (filterSize % 4) { + for (i=0; i>7, 0, (1<<15)-1); + } } - } - else - switch (filterSize) { - case 4: + else + switch (filterSize) { + case 4: { - for(i=0; i 12) { - src_v1 = vec_ld(srcPos + 16, src); - } - src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src)); - - src_v = // vec_unpackh sign-extends... - (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); - // now put our elements in the even slots - src_v = vec_mergeh(src_v, (vector signed short)vzero); - - filter_v = vec_ld(i << 3, filter); + for (i=0; i 12) { + src_v1 = vec_ld(srcPos + 16, src); + } + src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src)); + + src_v = // vec_unpackh sign-extends... + (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); + // now put our elements in the even slots + src_v = vec_mergeh(src_v, (vector signed short)vzero); + + filter_v = vec_ld(i << 3, filter); // the 3 above is 2 (filterSize == 4) + 1 (sizeof(short) == 2) // the neat trick : we only care for half the elements, // high or low depending on (i<<3)%16 (it's 0 or 8 here), // and we're going to use vec_mule, so we chose // carefully how to "unpack" the elements into the even slots - if ((i << 3) % 16) - filter_v = vec_mergel(filter_v,(vector signed short)vzero); - else - filter_v = vec_mergeh(filter_v,(vector signed short)vzero); - - val_vEven = vec_mule(src_v, filter_v); - val_s = vec_sums(val_vEven, vzero); - vec_st(val_s, 0, tempo); - dst[i] = av_clip(tempo[3]>>7, 0, (1<<15)-1); - } + if ((i << 3) % 16) + filter_v = vec_mergel(filter_v, (vector signed short)vzero); + else + filter_v = vec_mergeh(filter_v, (vector signed short)vzero); + + val_vEven = vec_mule(src_v, filter_v); + val_s = vec_sums(val_vEven, vzero); + vec_st(val_s, 0, tempo); + dst[i] = av_clip(tempo[3]>>7, 0, (1<<15)-1); + } } break; - case 8: + case 8: { - for(i=0; i 8) { - src_v1 = vec_ld(srcPos + 16, src); - } - src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src)); - - src_v = // vec_unpackh sign-extends... - (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); - filter_v = vec_ld(i << 4, filter); + for (i=0; i 8) { + src_v1 = vec_ld(srcPos + 16, src); + } + src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src)); + + src_v = // vec_unpackh sign-extends... + (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); + filter_v = vec_ld(i << 4, filter); // the 4 above is 3 (filterSize == 8) + 1 (sizeof(short) == 2) - val_v = vec_msums(src_v, filter_v, (vector signed int)vzero); - val_s = vec_sums(val_v, vzero); - vec_st(val_s, 0, tempo); - dst[i] = av_clip(tempo[3]>>7, 0, (1<<15)-1); - } + val_v = vec_msums(src_v, filter_v, (vector signed int)vzero); + val_s = vec_sums(val_v, vzero); + vec_st(val_s, 0, tempo); + dst[i] = av_clip(tempo[3]>>7, 0, (1<<15)-1); + } } break; - case 16: + case 16: { - for(i=0; i>7, 0, (1<<15)-1); - } + vec_st(val_s, 0, tempo); + dst[i] = av_clip(tempo[3]>>7, 0, (1<<15)-1); + } } break; - - default: + + default: { - for(i=0; i 8) { - src_v1 = vec_ld(srcPos + j + 16, src); - } - src_vF = vec_perm(src_v0, src_v1, permS); - - src_v = // vec_unpackh sign-extends... - (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); - // loading filter_v0R is useless, it's already done above - //vector signed short filter_v0R = vec_ld((i * 2 * filterSize) + j, filter); - filter_v1R = vec_ld((i * 2 * filterSize) + (j * 2) + 16, filter); - filter_v = vec_perm(filter_v0R, filter_v1R, permF); - - val_v = vec_msums(src_v, filter_v, val_v); + if (j < filterSize-7) { + // loading src_v0 is useless, it's already done above + //vector unsigned char src_v0 = vec_ld(srcPos + j, src); + vector unsigned char src_v1, src_vF; + vector signed short src_v, filter_v1R, filter_v; + if ((((int)src + srcPos)% 16) > 8) { + src_v1 = vec_ld(srcPos + j + 16, src); + } + src_vF = vec_perm(src_v0, src_v1, permS); + + src_v = // vec_unpackh sign-extends... + (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); + // loading filter_v0R is useless, it's already done above + //vector signed short filter_v0R = vec_ld((i * 2 * filterSize) + j, filter); + filter_v1R = vec_ld((i * 2 * filterSize) + (j * 2) + 16, filter); + filter_v = vec_perm(filter_v0R, filter_v1R, permF); + + val_v = vec_msums(src_v, filter_v, val_v); } val_s = vec_sums(val_v, vzero); - + vec_st(val_s, 0, tempo); - dst[i] = av_clip(tempo[3]>>7, 0, (1<<15)-1); - } - + dst[i] = av_clip(tempo[3]>>7, 0, (1<<15)-1); + } + + } } - } } static inline int yv12toyuy2_unscaled_altivec(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dstParam[], int dstStride_a[]) { - uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY; - // yv12toyuy2( src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0] ); - uint8_t *ysrc = src[0]; - uint8_t *usrc = src[1]; - uint8_t *vsrc = src[2]; - const int width = c->srcW; - const int height = srcSliceH; - const int lumStride = srcStride[0]; - const int chromStride = srcStride[1]; - const int dstStride = dstStride_a[0]; - const vector unsigned char yperm = vec_lvsl(0, ysrc); - const int vertLumPerChroma = 2; - register unsigned int y; - - if(width&15){ - yv12toyuy2( ysrc, usrc, vsrc, dst,c->srcW,srcSliceH, lumStride, chromStride, dstStride); - return srcSliceH; - } - - /* this code assume: + int srcSliceH, uint8_t* dstParam[], int dstStride_a[]) { + uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY; + // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); + uint8_t *ysrc = src[0]; + uint8_t *usrc = src[1]; + uint8_t *vsrc = src[2]; + const int width = c->srcW; + const int height = srcSliceH; + const int lumStride = srcStride[0]; + const int chromStride = srcStride[1]; + const int dstStride = dstStride_a[0]; + const vector unsigned char yperm = vec_lvsl(0, ysrc); + const int vertLumPerChroma = 2; + register unsigned int y; + + if (width&15) { + yv12toyuy2(ysrc, usrc, vsrc, dst, c->srcW, srcSliceH, lumStride, chromStride, dstStride); + return srcSliceH; + } - 1) dst is 16 bytes-aligned - 2) dstStride is a multiple of 16 - 3) width is a multiple of 16 - 4) lum&chrom stride are multiple of 8 - */ - - for(y=0; y> 1; - vector unsigned char v_yA = vec_ld(i, ysrc); - vector unsigned char v_yB = vec_ld(i + 16, ysrc); - vector unsigned char v_yC = vec_ld(i + 32, ysrc); - vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm); - vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm); - vector unsigned char v_uA = vec_ld(j, usrc); - vector unsigned char v_uB = vec_ld(j + 16, usrc); - vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc)); - vector unsigned char v_vA = vec_ld(j, vsrc); - vector unsigned char v_vB = vec_ld(j + 16, vsrc); - vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc)); - vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); - vector unsigned char v_uv_b = vec_mergel(v_u, v_v); - vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a); - vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a); - vector unsigned char v_yuy2_2 = vec_mergeh(v_y2, v_uv_b); - vector unsigned char v_yuy2_3 = vec_mergel(v_y2, v_uv_b); - vec_st(v_yuy2_0, (i << 1), dst); - vec_st(v_yuy2_1, (i << 1) + 16, dst); - vec_st(v_yuy2_2, (i << 1) + 32, dst); - vec_st(v_yuy2_3, (i << 1) + 48, dst); - } - if (i < width) { - const unsigned int j = i >> 1; - vector unsigned char v_y1 = vec_ld(i, ysrc); - vector unsigned char v_u = vec_ld(j, usrc); - vector unsigned char v_v = vec_ld(j, vsrc); - vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); - vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a); - vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a); - vec_st(v_yuy2_0, (i << 1), dst); - vec_st(v_yuy2_1, (i << 1) + 16, dst); - } - if((y&(vertLumPerChroma-1))==(vertLumPerChroma-1) ) - { - usrc += chromStride; - vsrc += chromStride; - } - ysrc += lumStride; - dst += dstStride; + /* this code assume: + + 1) dst is 16 bytes-aligned + 2) dstStride is a multiple of 16 + 3) width is a multiple of 16 + 4) lum&chrom stride are multiple of 8 + */ + + for (y=0; y> 1; + vector unsigned char v_yA = vec_ld(i, ysrc); + vector unsigned char v_yB = vec_ld(i + 16, ysrc); + vector unsigned char v_yC = vec_ld(i + 32, ysrc); + vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm); + vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm); + vector unsigned char v_uA = vec_ld(j, usrc); + vector unsigned char v_uB = vec_ld(j + 16, usrc); + vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc)); + vector unsigned char v_vA = vec_ld(j, vsrc); + vector unsigned char v_vB = vec_ld(j + 16, vsrc); + vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc)); + vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); + vector unsigned char v_uv_b = vec_mergel(v_u, v_v); + vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a); + vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a); + vector unsigned char v_yuy2_2 = vec_mergeh(v_y2, v_uv_b); + vector unsigned char v_yuy2_3 = vec_mergel(v_y2, v_uv_b); + vec_st(v_yuy2_0, (i << 1), dst); + vec_st(v_yuy2_1, (i << 1) + 16, dst); + vec_st(v_yuy2_2, (i << 1) + 32, dst); + vec_st(v_yuy2_3, (i << 1) + 48, dst); + } + if (i < width) { + const unsigned int j = i >> 1; + vector unsigned char v_y1 = vec_ld(i, ysrc); + vector unsigned char v_u = vec_ld(j, usrc); + vector unsigned char v_v = vec_ld(j, vsrc); + vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); + vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a); + vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a); + vec_st(v_yuy2_0, (i << 1), dst); + vec_st(v_yuy2_1, (i << 1) + 16, dst); + } + if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) { + usrc += chromStride; + vsrc += chromStride; + } + ysrc += lumStride; + dst += dstStride; } - - return srcSliceH; -} -static inline int yv12touyvy_unscaled_altivec(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dstParam[], int dstStride_a[]) { - uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY; - // yv12toyuy2( src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0] ); - uint8_t *ysrc = src[0]; - uint8_t *usrc = src[1]; - uint8_t *vsrc = src[2]; - const int width = c->srcW; - const int height = srcSliceH; - const int lumStride = srcStride[0]; - const int chromStride = srcStride[1]; - const int dstStride = dstStride_a[0]; - const int vertLumPerChroma = 2; - const vector unsigned char yperm = vec_lvsl(0, ysrc); - register unsigned int y; - - if(width&15){ - yv12touyvy( ysrc, usrc, vsrc, dst,c->srcW,srcSliceH, lumStride, chromStride, dstStride); return srcSliceH; - } +} - /* this code assume: +static inline int yv12touyvy_unscaled_altivec(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dstParam[], int dstStride_a[]) { + uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY; + // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); + uint8_t *ysrc = src[0]; + uint8_t *usrc = src[1]; + uint8_t *vsrc = src[2]; + const int width = c->srcW; + const int height = srcSliceH; + const int lumStride = srcStride[0]; + const int chromStride = srcStride[1]; + const int dstStride = dstStride_a[0]; + const int vertLumPerChroma = 2; + const vector unsigned char yperm = vec_lvsl(0, ysrc); + register unsigned int y; + + if (width&15) { + yv12touyvy(ysrc, usrc, vsrc, dst, c->srcW, srcSliceH, lumStride, chromStride, dstStride); + return srcSliceH; + } - 1) dst is 16 bytes-aligned - 2) dstStride is a multiple of 16 - 3) width is a multiple of 16 - 4) lum&chrom stride are multiple of 8 - */ - - for(y=0; y> 1; - vector unsigned char v_yA = vec_ld(i, ysrc); - vector unsigned char v_yB = vec_ld(i + 16, ysrc); - vector unsigned char v_yC = vec_ld(i + 32, ysrc); - vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm); - vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm); - vector unsigned char v_uA = vec_ld(j, usrc); - vector unsigned char v_uB = vec_ld(j + 16, usrc); - vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc)); - vector unsigned char v_vA = vec_ld(j, vsrc); - vector unsigned char v_vB = vec_ld(j + 16, vsrc); - vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc)); - vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); - vector unsigned char v_uv_b = vec_mergel(v_u, v_v); - vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1); - vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1); - vector unsigned char v_uyvy_2 = vec_mergeh(v_uv_b, v_y2); - vector unsigned char v_uyvy_3 = vec_mergel(v_uv_b, v_y2); - vec_st(v_uyvy_0, (i << 1), dst); - vec_st(v_uyvy_1, (i << 1) + 16, dst); - vec_st(v_uyvy_2, (i << 1) + 32, dst); - vec_st(v_uyvy_3, (i << 1) + 48, dst); - } - if (i < width) { - const unsigned int j = i >> 1; - vector unsigned char v_y1 = vec_ld(i, ysrc); - vector unsigned char v_u = vec_ld(j, usrc); - vector unsigned char v_v = vec_ld(j, vsrc); - vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); - vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1); - vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1); - vec_st(v_uyvy_0, (i << 1), dst); - vec_st(v_uyvy_1, (i << 1) + 16, dst); - } - if((y&(vertLumPerChroma-1))==(vertLumPerChroma-1) ) - { - usrc += chromStride; - vsrc += chromStride; - } - ysrc += lumStride; - dst += dstStride; + /* this code assume: + + 1) dst is 16 bytes-aligned + 2) dstStride is a multiple of 16 + 3) width is a multiple of 16 + 4) lum&chrom stride are multiple of 8 + */ + + for (y=0; y> 1; + vector unsigned char v_yA = vec_ld(i, ysrc); + vector unsigned char v_yB = vec_ld(i + 16, ysrc); + vector unsigned char v_yC = vec_ld(i + 32, ysrc); + vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm); + vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm); + vector unsigned char v_uA = vec_ld(j, usrc); + vector unsigned char v_uB = vec_ld(j + 16, usrc); + vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc)); + vector unsigned char v_vA = vec_ld(j, vsrc); + vector unsigned char v_vB = vec_ld(j + 16, vsrc); + vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc)); + vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); + vector unsigned char v_uv_b = vec_mergel(v_u, v_v); + vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1); + vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1); + vector unsigned char v_uyvy_2 = vec_mergeh(v_uv_b, v_y2); + vector unsigned char v_uyvy_3 = vec_mergel(v_uv_b, v_y2); + vec_st(v_uyvy_0, (i << 1), dst); + vec_st(v_uyvy_1, (i << 1) + 16, dst); + vec_st(v_uyvy_2, (i << 1) + 32, dst); + vec_st(v_uyvy_3, (i << 1) + 48, dst); + } + if (i < width) { + const unsigned int j = i >> 1; + vector unsigned char v_y1 = vec_ld(i, ysrc); + vector unsigned char v_u = vec_ld(j, usrc); + vector unsigned char v_v = vec_ld(j, vsrc); + vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); + vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1); + vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1); + vec_st(v_uyvy_0, (i << 1), dst); + vec_st(v_uyvy_1, (i << 1) + 16, dst); + } + if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) { + usrc += chromStride; + vsrc += chromStride; + } + ysrc += lumStride; + dst += dstStride; } - return srcSliceH; + return srcSliceH; } diff --git a/contrib/ffmpeg/libswscale/swscale_bfin.c b/contrib/ffmpeg/libswscale/swscale_bfin.c new file mode 100644 index 000000000..bbc304dfe --- /dev/null +++ b/contrib/ffmpeg/libswscale/swscale_bfin.c @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2007 Marc Hoffman + * + * Blackfin Software Video SCALER Operations + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include +#include "config.h" +#ifdef HAVE_MALLOC_H +#include +#endif +#include +#include "rgb2rgb.h" +#include "swscale.h" +#include "swscale_internal.h" + +#ifdef __FDPIC__ +#define L1CODE __attribute__ ((l1_text)) +#else +#define L1CODE +#endif + +extern int ff_bfin_uyvytoyv12 (const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, + long width, long height, + long lumStride, long chromStride, long srcStride) L1CODE; + +extern int ff_bfin_yuyvtoyv12 (const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, + long width, long height, + long lumStride, long chromStride, long srcStride) L1CODE; + +static int uyvytoyv12_unscaled (SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dst[], int dstStride[]) +{ + uint8_t *dsty = dst[0] + dstStride[0]*srcSliceY; + uint8_t *dstu = dst[1] + dstStride[1]*srcSliceY/2; + uint8_t *dstv = dst[2] + dstStride[2]*srcSliceY/2; + uint8_t *ip = src[0] + srcStride[0]*srcSliceY; + int w = dstStride[0]; + + ff_bfin_uyvytoyv12 (ip, dsty, dstu, dstv, w, srcSliceH, dstStride[0], dstStride[1], srcStride[0]); + + return srcSliceH; +} + +static int yuyvtoyv12_unscaled (SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dst[], int dstStride[]) +{ + uint8_t *dsty = dst[0] + dstStride[0]*srcSliceY; + uint8_t *dstu = dst[1] + dstStride[1]*srcSliceY/2; + uint8_t *dstv = dst[2] + dstStride[2]*srcSliceY/2; + uint8_t *ip = src[0] + srcStride[0]*srcSliceY; + int w = dstStride[0]; + + ff_bfin_yuyvtoyv12 (ip, dsty, dstu, dstv, w, srcSliceH, dstStride[0], dstStride[1], srcStride[0]); + + return srcSliceH; +} + + +void ff_bfin_get_unscaled_swscale (SwsContext *c) +{ + SwsFunc swScale = c->swScale; + if (c->flags & SWS_CPU_CAPS_BFIN) + if (c->dstFormat == PIX_FMT_YUV420P) + if (c->srcFormat == PIX_FMT_UYVY422) { + av_log (NULL, AV_LOG_VERBOSE, "selecting Blackfin optimized uyvytoyv12_unscaled\n"); + c->swScale = uyvytoyv12_unscaled; + } + if (c->dstFormat == PIX_FMT_YUV420P) + if (c->srcFormat == PIX_FMT_YUYV422) { + av_log (NULL, AV_LOG_VERBOSE, "selecting Blackfin optimized yuyvtoyv12_unscaled\n"); + c->swScale = yuyvtoyv12_unscaled; + } +} diff --git a/contrib/ffmpeg/libswscale/swscale_internal.h b/contrib/ffmpeg/libswscale/swscale_internal.h index 5b62ea065..aa583a6b1 100644 --- a/contrib/ffmpeg/libswscale/swscale_internal.h +++ b/contrib/ffmpeg/libswscale/swscale_internal.h @@ -15,11 +15,13 @@ * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef SWSCALE_INTERNAL_H -#define SWSCALE_INTERNAL_H +#ifndef FFMPEG_SWSCALE_INTERNAL_H +#define FFMPEG_SWSCALE_INTERNAL_H + +#include "config.h" #ifdef HAVE_ALTIVEC_H #include @@ -27,12 +29,6 @@ #include "avutil.h" -#ifdef CONFIG_DARWIN -#define AVV(x...) (x) -#else -#define AVV(x...) {x} -#endif - #define MAX_FILTER_SIZE 256 typedef int (*SwsFunc)(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY, @@ -40,114 +36,114 @@ typedef int (*SwsFunc)(struct SwsContext *context, uint8_t* src[], int srcStride /* this struct should be aligned on at least 32-byte boundary */ typedef struct SwsContext{ - /** - * info on struct for av_log - */ - AVClass *av_class; - - /** - * - * Note the src,dst,srcStride,dstStride will be copied, in the sws_scale() warper so they can freely be modified here - */ - SwsFunc swScale; - int srcW, srcH, dstH; - int chrSrcW, chrSrcH, chrDstW, chrDstH; - int lumXInc, chrXInc; - int lumYInc, chrYInc; - int dstFormat, srcFormat; ///< format 4:2:0 type is allways YV12 - int origDstFormat, origSrcFormat; ///< format - int chrSrcHSubSample, chrSrcVSubSample; - int chrIntHSubSample, chrIntVSubSample; - int chrDstHSubSample, chrDstVSubSample; - int vChrDrop; - int sliceDir; - double param[2]; - - int16_t **lumPixBuf; - int16_t **chrPixBuf; - int16_t *hLumFilter; - int16_t *hLumFilterPos; - int16_t *hChrFilter; - int16_t *hChrFilterPos; - int16_t *vLumFilter; - int16_t *vLumFilterPos; - int16_t *vChrFilter; - int16_t *vChrFilterPos; - - uint8_t formatConvBuffer[4000]; //FIXME dynamic alloc, but we have to change a lot of code for this to be useful - - int hLumFilterSize; - int hChrFilterSize; - int vLumFilterSize; - int vChrFilterSize; - int vLumBufSize; - int vChrBufSize; - - uint8_t *funnyYCode; - uint8_t *funnyUVCode; - int32_t *lumMmx2FilterPos; - int32_t *chrMmx2FilterPos; - int16_t *lumMmx2Filter; - int16_t *chrMmx2Filter; - - int canMMX2BeUsed; - - int lastInLumBuf; - int lastInChrBuf; - int lumBufIndex; - int chrBufIndex; - int dstY; - int flags; - void * yuvTable; // pointer to the yuv->rgb table start so it can be freed() - uint8_t * table_rV[256]; - uint8_t * table_gU[256]; - int table_gV[256]; - uint8_t * table_bU[256]; - - //Colorspace stuff - int contrast, brightness, saturation; // for sws_getColorspaceDetails - int srcColorspaceTable[4]; - int dstColorspaceTable[4]; - int srcRange, dstRange; - -#define RED_DITHER "0*8" -#define GREEN_DITHER "1*8" -#define BLUE_DITHER "2*8" -#define Y_COEFF "3*8" -#define VR_COEFF "4*8" -#define UB_COEFF "5*8" -#define VG_COEFF "6*8" -#define UG_COEFF "7*8" -#define Y_OFFSET "8*8" -#define U_OFFSET "9*8" -#define V_OFFSET "10*8" + /** + * info on struct for av_log + */ + AVClass *av_class; + + /** + * Note that src, dst, srcStride, dstStride will be copied in the + * sws_scale() wrapper so they can be freely modified here. + */ + SwsFunc swScale; + int srcW, srcH, dstH; + int chrSrcW, chrSrcH, chrDstW, chrDstH; + int lumXInc, chrXInc; + int lumYInc, chrYInc; + int dstFormat, srcFormat; ///< format 4:2:0 type is always YV12 + int origDstFormat, origSrcFormat; ///< format + int chrSrcHSubSample, chrSrcVSubSample; + int chrIntHSubSample, chrIntVSubSample; + int chrDstHSubSample, chrDstVSubSample; + int vChrDrop; + int sliceDir; + double param[2]; + + int16_t **lumPixBuf; + int16_t **chrPixBuf; + int16_t *hLumFilter; + int16_t *hLumFilterPos; + int16_t *hChrFilter; + int16_t *hChrFilterPos; + int16_t *vLumFilter; + int16_t *vLumFilterPos; + int16_t *vChrFilter; + int16_t *vChrFilterPos; + + uint8_t formatConvBuffer[4000]; //FIXME dynamic alloc, but we have to change a lot of code for this to be useful + + int hLumFilterSize; + int hChrFilterSize; + int vLumFilterSize; + int vChrFilterSize; + int vLumBufSize; + int vChrBufSize; + + uint8_t *funnyYCode; + uint8_t *funnyUVCode; + int32_t *lumMmx2FilterPos; + int32_t *chrMmx2FilterPos; + int16_t *lumMmx2Filter; + int16_t *chrMmx2Filter; + + int canMMX2BeUsed; + + int lastInLumBuf; + int lastInChrBuf; + int lumBufIndex; + int chrBufIndex; + int dstY; + int flags; + void * yuvTable; // pointer to the yuv->rgb table start so it can be freed() + uint8_t * table_rV[256]; + uint8_t * table_gU[256]; + int table_gV[256]; + uint8_t * table_bU[256]; + + //Colorspace stuff + int contrast, brightness, saturation; // for sws_getColorspaceDetails + int srcColorspaceTable[4]; + int dstColorspaceTable[4]; + int srcRange, dstRange; + +#define RED_DITHER "0*8" +#define GREEN_DITHER "1*8" +#define BLUE_DITHER "2*8" +#define Y_COEFF "3*8" +#define VR_COEFF "4*8" +#define UB_COEFF "5*8" +#define VG_COEFF "6*8" +#define UG_COEFF "7*8" +#define Y_OFFSET "8*8" +#define U_OFFSET "9*8" +#define V_OFFSET "10*8" #define LUM_MMX_FILTER_OFFSET "11*8" #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256" -#define DSTW_OFFSET "11*8+4*4*256*2" //do not change, its hardcoded in the asm -#define ESP_OFFSET "11*8+4*4*256*2+8" -#define VROUNDER_OFFSET "11*8+4*4*256*2+16" -#define U_TEMP "11*8+4*4*256*2+24" -#define V_TEMP "11*8+4*4*256*2+32" - - uint64_t redDither __attribute__((aligned(8))); - uint64_t greenDither __attribute__((aligned(8))); - uint64_t blueDither __attribute__((aligned(8))); - - uint64_t yCoeff __attribute__((aligned(8))); - uint64_t vrCoeff __attribute__((aligned(8))); - uint64_t ubCoeff __attribute__((aligned(8))); - uint64_t vgCoeff __attribute__((aligned(8))); - uint64_t ugCoeff __attribute__((aligned(8))); - uint64_t yOffset __attribute__((aligned(8))); - uint64_t uOffset __attribute__((aligned(8))); - uint64_t vOffset __attribute__((aligned(8))); - int32_t lumMmxFilter[4*MAX_FILTER_SIZE]; - int32_t chrMmxFilter[4*MAX_FILTER_SIZE]; - int dstW; - uint64_t esp __attribute__((aligned(8))); - uint64_t vRounder __attribute__((aligned(8))); - uint64_t u_temp __attribute__((aligned(8))); - uint64_t v_temp __attribute__((aligned(8))); +#define DSTW_OFFSET "11*8+4*4*256*2" //do not change, it is hardcoded in the asm +#define ESP_OFFSET "11*8+4*4*256*2+8" +#define VROUNDER_OFFSET "11*8+4*4*256*2+16" +#define U_TEMP "11*8+4*4*256*2+24" +#define V_TEMP "11*8+4*4*256*2+32" + + uint64_t redDither __attribute__((aligned(8))); + uint64_t greenDither __attribute__((aligned(8))); + uint64_t blueDither __attribute__((aligned(8))); + + uint64_t yCoeff __attribute__((aligned(8))); + uint64_t vrCoeff __attribute__((aligned(8))); + uint64_t ubCoeff __attribute__((aligned(8))); + uint64_t vgCoeff __attribute__((aligned(8))); + uint64_t ugCoeff __attribute__((aligned(8))); + uint64_t yOffset __attribute__((aligned(8))); + uint64_t uOffset __attribute__((aligned(8))); + uint64_t vOffset __attribute__((aligned(8))); + int32_t lumMmxFilter[4*MAX_FILTER_SIZE]; + int32_t chrMmxFilter[4*MAX_FILTER_SIZE]; + int dstW; + uint64_t esp __attribute__((aligned(8))); + uint64_t vRounder __attribute__((aligned(8))); + uint64_t u_temp __attribute__((aligned(8))); + uint64_t v_temp __attribute__((aligned(8))); #ifdef HAVE_ALTIVEC @@ -158,8 +154,27 @@ typedef struct SwsContext{ vector signed short CGV; vector signed short OY; vector unsigned short CSHIFT; - vector signed short *vYCoeffsBank, *vCCoeffsBank; + vector signed short *vYCoeffsBank, *vCCoeffsBank; + +#endif + +#ifdef ARCH_BFIN + uint32_t oy __attribute__((aligned(4))); + uint32_t oc __attribute__((aligned(4))); + uint32_t zero __attribute__((aligned(4))); + uint32_t cy __attribute__((aligned(4))); + uint32_t crv __attribute__((aligned(4))); + uint32_t rmask __attribute__((aligned(4))); + uint32_t cbu __attribute__((aligned(4))); + uint32_t bmask __attribute__((aligned(4))); + uint32_t cgu __attribute__((aligned(4))); + uint32_t cgv __attribute__((aligned(4))); + uint32_t gmask __attribute__((aligned(4))); +#endif + +#ifdef HAVE_VIS + uint64_t sparc_coeffs[10] __attribute__((aligned(8))); #endif } SwsContext; @@ -168,24 +183,60 @@ typedef struct SwsContext{ SwsFunc yuv2rgb_get_func_ptr (SwsContext *c); int yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation); +void yuv2rgb_altivec_init_tables (SwsContext *c, const int inv_table[4],int brightness,int contrast, int saturation); +SwsFunc yuv2rgb_init_altivec (SwsContext *c); +void altivec_yuv2packedX (SwsContext *c, + int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize, + int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, + uint8_t *dest, int dstW, int dstY); + char *sws_format_name(int format); //FIXME replace this with something faster -#define isPlanarYUV(x) ((x)==PIX_FMT_YUV410P || (x)==PIX_FMT_YUV420P \ - || (x)==PIX_FMT_YUV411P || (x)==PIX_FMT_YUV422P \ - || (x)==PIX_FMT_YUV444P || (x)==PIX_FMT_NV12 \ - || (x)==PIX_FMT_NV21) -#define isYUV(x) ((x)==PIX_FMT_UYVY422 || (x)==PIX_FMT_YUYV422 || isPlanarYUV(x)) -#define isGray(x) ((x)==PIX_FMT_GRAY8 || (x)==PIX_FMT_GRAY16BE || (x)==PIX_FMT_GRAY16LE) -#define isGray16(x) ((x)==PIX_FMT_GRAY16BE || (x)==PIX_FMT_GRAY16LE) -#define isRGB(x) ((x)==PIX_FMT_BGR32 || (x)==PIX_FMT_RGB24 \ - || (x)==PIX_FMT_RGB565 || (x)==PIX_FMT_RGB555 \ - || (x)==PIX_FMT_RGB8 || (x)==PIX_FMT_RGB4 || (x)==PIX_FMT_RGB4_BYTE \ - || (x)==PIX_FMT_MONOBLACK) -#define isBGR(x) ((x)==PIX_FMT_RGB32 || (x)==PIX_FMT_BGR24 \ - || (x)==PIX_FMT_BGR565 || (x)==PIX_FMT_BGR555 \ - || (x)==PIX_FMT_BGR8 || (x)==PIX_FMT_BGR4 || (x)==PIX_FMT_BGR4_BYTE \ - || (x)==PIX_FMT_MONOBLACK) +#define isPlanarYUV(x) ( \ + (x)==PIX_FMT_YUV410P \ + || (x)==PIX_FMT_YUV420P \ + || (x)==PIX_FMT_YUV411P \ + || (x)==PIX_FMT_YUV422P \ + || (x)==PIX_FMT_YUV444P \ + || (x)==PIX_FMT_YUV440P \ + || (x)==PIX_FMT_NV12 \ + || (x)==PIX_FMT_NV21 \ + ) +#define isYUV(x) ( \ + (x)==PIX_FMT_UYVY422 \ + || (x)==PIX_FMT_YUYV422 \ + || isPlanarYUV(x) \ + ) +#define isGray(x) ( \ + (x)==PIX_FMT_GRAY8 \ + || (x)==PIX_FMT_GRAY16BE \ + || (x)==PIX_FMT_GRAY16LE \ + ) +#define isGray16(x) ( \ + (x)==PIX_FMT_GRAY16BE \ + || (x)==PIX_FMT_GRAY16LE \ + ) +#define isRGB(x) ( \ + (x)==PIX_FMT_BGR32 \ + || (x)==PIX_FMT_RGB24 \ + || (x)==PIX_FMT_RGB565 \ + || (x)==PIX_FMT_RGB555 \ + || (x)==PIX_FMT_RGB8 \ + || (x)==PIX_FMT_RGB4 \ + || (x)==PIX_FMT_RGB4_BYTE \ + || (x)==PIX_FMT_MONOBLACK \ + ) +#define isBGR(x) ( \ + (x)==PIX_FMT_RGB32 \ + || (x)==PIX_FMT_BGR24 \ + || (x)==PIX_FMT_BGR565 \ + || (x)==PIX_FMT_BGR555 \ + || (x)==PIX_FMT_BGR8 \ + || (x)==PIX_FMT_BGR4 \ + || (x)==PIX_FMT_BGR4_BYTE \ + || (x)==PIX_FMT_MONOBLACK \ + ) static inline int fmt_depth(int fmt) { @@ -221,4 +272,7 @@ static inline int fmt_depth(int fmt) } } -#endif +extern const DECLARE_ALIGNED(8, uint64_t, ff_dither4[2]); +extern const DECLARE_ALIGNED(8, uint64_t, ff_dither8[2]); + +#endif /* FFMPEG_SWSCALE_INTERNAL_H */ diff --git a/contrib/ffmpeg/libswscale/swscale_template.c b/contrib/ffmpeg/libswscale/swscale_template.c index ad46be127..50bb260f2 100644 --- a/contrib/ffmpeg/libswscale/swscale_template.c +++ b/contrib/ffmpeg/libswscale/swscale_template.c @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * the C code (not assembly, mmx, ...) of this file can be used * under the LGPL license too @@ -39,7 +39,7 @@ #ifdef HAVE_3DNOW #define PREFETCH "prefetch" #define PREFETCHW "prefetchw" -#elif defined ( HAVE_MMX2 ) +#elif defined (HAVE_MMX2) #define PREFETCH "prefetchnta" #define PREFETCHW "prefetcht0" #else @@ -71,835 +71,835 @@ #endif #define YSCALEYUV2YV12X(x, offset, dest, width) \ - asm volatile(\ - "xor %%"REG_a", %%"REG_a" \n\t"\ - "movq "VROUNDER_OFFSET"(%0), %%mm3\n\t"\ - "movq %%mm3, %%mm4 \n\t"\ - "lea " offset "(%0), %%"REG_d" \n\t"\ - "mov (%%"REG_d"), %%"REG_S" \n\t"\ - ASMALIGN(4) /* FIXME Unroll? */\ - "1: \n\t"\ - "movq 8(%%"REG_d"), %%mm0 \n\t" /* filterCoeff */\ - "movq " #x "(%%"REG_S", %%"REG_a", 2), %%mm2\n\t" /* srcData */\ - "movq 8+" #x "(%%"REG_S", %%"REG_a", 2), %%mm5\n\t" /* srcData */\ - "add $16, %%"REG_d" \n\t"\ - "mov (%%"REG_d"), %%"REG_S" \n\t"\ - "test %%"REG_S", %%"REG_S" \n\t"\ - "pmulhw %%mm0, %%mm2 \n\t"\ - "pmulhw %%mm0, %%mm5 \n\t"\ - "paddw %%mm2, %%mm3 \n\t"\ - "paddw %%mm5, %%mm4 \n\t"\ - " jnz 1b \n\t"\ - "psraw $3, %%mm3 \n\t"\ - "psraw $3, %%mm4 \n\t"\ - "packuswb %%mm4, %%mm3 \n\t"\ - MOVNTQ(%%mm3, (%1, %%REGa))\ - "add $8, %%"REG_a" \n\t"\ - "cmp %2, %%"REG_a" \n\t"\ - "movq "VROUNDER_OFFSET"(%0), %%mm3\n\t"\ - "movq %%mm3, %%mm4 \n\t"\ - "lea " offset "(%0), %%"REG_d" \n\t"\ - "mov (%%"REG_d"), %%"REG_S" \n\t"\ - "jb 1b \n\t"\ - :: "r" (&c->redDither),\ - "r" (dest), "g" (width)\ - : "%"REG_a, "%"REG_d, "%"REG_S\ - ); + asm volatile(\ + "xor %%"REG_a", %%"REG_a" \n\t"\ + "movq "VROUNDER_OFFSET"(%0), %%mm3 \n\t"\ + "movq %%mm3, %%mm4 \n\t"\ + "lea " offset "(%0), %%"REG_d" \n\t"\ + "mov (%%"REG_d"), %%"REG_S" \n\t"\ + ASMALIGN(4) /* FIXME Unroll? */\ + "1: \n\t"\ + "movq 8(%%"REG_d"), %%mm0 \n\t" /* filterCoeff */\ + "movq " #x "(%%"REG_S", %%"REG_a", 2), %%mm2 \n\t" /* srcData */\ + "movq 8+" #x "(%%"REG_S", %%"REG_a", 2), %%mm5 \n\t" /* srcData */\ + "add $16, %%"REG_d" \n\t"\ + "mov (%%"REG_d"), %%"REG_S" \n\t"\ + "test %%"REG_S", %%"REG_S" \n\t"\ + "pmulhw %%mm0, %%mm2 \n\t"\ + "pmulhw %%mm0, %%mm5 \n\t"\ + "paddw %%mm2, %%mm3 \n\t"\ + "paddw %%mm5, %%mm4 \n\t"\ + " jnz 1b \n\t"\ + "psraw $3, %%mm3 \n\t"\ + "psraw $3, %%mm4 \n\t"\ + "packuswb %%mm4, %%mm3 \n\t"\ + MOVNTQ(%%mm3, (%1, %%REGa))\ + "add $8, %%"REG_a" \n\t"\ + "cmp %2, %%"REG_a" \n\t"\ + "movq "VROUNDER_OFFSET"(%0), %%mm3 \n\t"\ + "movq %%mm3, %%mm4 \n\t"\ + "lea " offset "(%0), %%"REG_d" \n\t"\ + "mov (%%"REG_d"), %%"REG_S" \n\t"\ + "jb 1b \n\t"\ + :: "r" (&c->redDither),\ + "r" (dest), "g" (width)\ + : "%"REG_a, "%"REG_d, "%"REG_S\ + ); #define YSCALEYUV2YV12X_ACCURATE(x, offset, dest, width) \ - asm volatile(\ - "lea " offset "(%0), %%"REG_d" \n\t"\ - "xor %%"REG_a", %%"REG_a" \n\t"\ - "pxor %%mm4, %%mm4 \n\t"\ - "pxor %%mm5, %%mm5 \n\t"\ - "pxor %%mm6, %%mm6 \n\t"\ - "pxor %%mm7, %%mm7 \n\t"\ - "mov (%%"REG_d"), %%"REG_S" \n\t"\ - ASMALIGN(4) \ - "1: \n\t"\ - "movq " #x "(%%"REG_S", %%"REG_a", 2), %%mm0\n\t" /* srcData */\ - "movq 8+" #x "(%%"REG_S", %%"REG_a", 2), %%mm2\n\t" /* srcData */\ - "mov 4(%%"REG_d"), %%"REG_S" \n\t"\ - "movq " #x "(%%"REG_S", %%"REG_a", 2), %%mm1\n\t" /* srcData */\ - "movq %%mm0, %%mm3 \n\t"\ - "punpcklwd %%mm1, %%mm0 \n\t"\ - "punpckhwd %%mm1, %%mm3 \n\t"\ - "movq 8(%%"REG_d"), %%mm1 \n\t" /* filterCoeff */\ - "pmaddwd %%mm1, %%mm0 \n\t"\ - "pmaddwd %%mm1, %%mm3 \n\t"\ - "paddd %%mm0, %%mm4 \n\t"\ - "paddd %%mm3, %%mm5 \n\t"\ - "movq 8+" #x "(%%"REG_S", %%"REG_a", 2), %%mm3\n\t" /* srcData */\ - "mov 16(%%"REG_d"), %%"REG_S" \n\t"\ - "add $16, %%"REG_d" \n\t"\ - "test %%"REG_S", %%"REG_S" \n\t"\ - "movq %%mm2, %%mm0 \n\t"\ - "punpcklwd %%mm3, %%mm2 \n\t"\ - "punpckhwd %%mm3, %%mm0 \n\t"\ - "pmaddwd %%mm1, %%mm2 \n\t"\ - "pmaddwd %%mm1, %%mm0 \n\t"\ - "paddd %%mm2, %%mm6 \n\t"\ - "paddd %%mm0, %%mm7 \n\t"\ - " jnz 1b \n\t"\ - "psrad $16, %%mm4 \n\t"\ - "psrad $16, %%mm5 \n\t"\ - "psrad $16, %%mm6 \n\t"\ - "psrad $16, %%mm7 \n\t"\ - "movq "VROUNDER_OFFSET"(%0), %%mm0\n\t"\ - "packssdw %%mm5, %%mm4 \n\t"\ - "packssdw %%mm7, %%mm6 \n\t"\ - "paddw %%mm0, %%mm4 \n\t"\ - "paddw %%mm0, %%mm6 \n\t"\ - "psraw $3, %%mm4 \n\t"\ - "psraw $3, %%mm6 \n\t"\ - "packuswb %%mm6, %%mm4 \n\t"\ - MOVNTQ(%%mm4, (%1, %%REGa))\ - "add $8, %%"REG_a" \n\t"\ - "cmp %2, %%"REG_a" \n\t"\ - "lea " offset "(%0), %%"REG_d" \n\t"\ - "pxor %%mm4, %%mm4 \n\t"\ - "pxor %%mm5, %%mm5 \n\t"\ - "pxor %%mm6, %%mm6 \n\t"\ - "pxor %%mm7, %%mm7 \n\t"\ - "mov (%%"REG_d"), %%"REG_S" \n\t"\ - "jb 1b \n\t"\ - :: "r" (&c->redDither),\ - "r" (dest), "g" (width)\ - : "%"REG_a, "%"REG_d, "%"REG_S\ - ); + asm volatile(\ + "lea " offset "(%0), %%"REG_d" \n\t"\ + "xor %%"REG_a", %%"REG_a" \n\t"\ + "pxor %%mm4, %%mm4 \n\t"\ + "pxor %%mm5, %%mm5 \n\t"\ + "pxor %%mm6, %%mm6 \n\t"\ + "pxor %%mm7, %%mm7 \n\t"\ + "mov (%%"REG_d"), %%"REG_S" \n\t"\ + ASMALIGN(4) \ + "1: \n\t"\ + "movq " #x "(%%"REG_S", %%"REG_a", 2), %%mm0 \n\t" /* srcData */\ + "movq 8+" #x "(%%"REG_S", %%"REG_a", 2), %%mm2 \n\t" /* srcData */\ + "mov 4(%%"REG_d"), %%"REG_S" \n\t"\ + "movq " #x "(%%"REG_S", %%"REG_a", 2), %%mm1 \n\t" /* srcData */\ + "movq %%mm0, %%mm3 \n\t"\ + "punpcklwd %%mm1, %%mm0 \n\t"\ + "punpckhwd %%mm1, %%mm3 \n\t"\ + "movq 8(%%"REG_d"), %%mm1 \n\t" /* filterCoeff */\ + "pmaddwd %%mm1, %%mm0 \n\t"\ + "pmaddwd %%mm1, %%mm3 \n\t"\ + "paddd %%mm0, %%mm4 \n\t"\ + "paddd %%mm3, %%mm5 \n\t"\ + "movq 8+" #x "(%%"REG_S", %%"REG_a", 2), %%mm3 \n\t" /* srcData */\ + "mov 16(%%"REG_d"), %%"REG_S" \n\t"\ + "add $16, %%"REG_d" \n\t"\ + "test %%"REG_S", %%"REG_S" \n\t"\ + "movq %%mm2, %%mm0 \n\t"\ + "punpcklwd %%mm3, %%mm2 \n\t"\ + "punpckhwd %%mm3, %%mm0 \n\t"\ + "pmaddwd %%mm1, %%mm2 \n\t"\ + "pmaddwd %%mm1, %%mm0 \n\t"\ + "paddd %%mm2, %%mm6 \n\t"\ + "paddd %%mm0, %%mm7 \n\t"\ + " jnz 1b \n\t"\ + "psrad $16, %%mm4 \n\t"\ + "psrad $16, %%mm5 \n\t"\ + "psrad $16, %%mm6 \n\t"\ + "psrad $16, %%mm7 \n\t"\ + "movq "VROUNDER_OFFSET"(%0), %%mm0 \n\t"\ + "packssdw %%mm5, %%mm4 \n\t"\ + "packssdw %%mm7, %%mm6 \n\t"\ + "paddw %%mm0, %%mm4 \n\t"\ + "paddw %%mm0, %%mm6 \n\t"\ + "psraw $3, %%mm4 \n\t"\ + "psraw $3, %%mm6 \n\t"\ + "packuswb %%mm6, %%mm4 \n\t"\ + MOVNTQ(%%mm4, (%1, %%REGa))\ + "add $8, %%"REG_a" \n\t"\ + "cmp %2, %%"REG_a" \n\t"\ + "lea " offset "(%0), %%"REG_d" \n\t"\ + "pxor %%mm4, %%mm4 \n\t"\ + "pxor %%mm5, %%mm5 \n\t"\ + "pxor %%mm6, %%mm6 \n\t"\ + "pxor %%mm7, %%mm7 \n\t"\ + "mov (%%"REG_d"), %%"REG_S" \n\t"\ + "jb 1b \n\t"\ + :: "r" (&c->redDither),\ + "r" (dest), "g" (width)\ + : "%"REG_a, "%"REG_d, "%"REG_S\ + ); #define YSCALEYUV2YV121 \ - "mov %2, %%"REG_a" \n\t"\ - ASMALIGN(4) /* FIXME Unroll? */\ - "1: \n\t"\ - "movq (%0, %%"REG_a", 2), %%mm0 \n\t"\ - "movq 8(%0, %%"REG_a", 2), %%mm1\n\t"\ - "psraw $7, %%mm0 \n\t"\ - "psraw $7, %%mm1 \n\t"\ - "packuswb %%mm1, %%mm0 \n\t"\ - MOVNTQ(%%mm0, (%1, %%REGa))\ - "add $8, %%"REG_a" \n\t"\ - "jnc 1b \n\t" + "mov %2, %%"REG_a" \n\t"\ + ASMALIGN(4) /* FIXME Unroll? */\ + "1: \n\t"\ + "movq (%0, %%"REG_a", 2), %%mm0 \n\t"\ + "movq 8(%0, %%"REG_a", 2), %%mm1 \n\t"\ + "psraw $7, %%mm0 \n\t"\ + "psraw $7, %%mm1 \n\t"\ + "packuswb %%mm1, %%mm0 \n\t"\ + MOVNTQ(%%mm0, (%1, %%REGa))\ + "add $8, %%"REG_a" \n\t"\ + "jnc 1b \n\t" /* - :: "m" (-lumFilterSize), "m" (-chrFilterSize), - "m" (lumMmxFilter+lumFilterSize*4), "m" (chrMmxFilter+chrFilterSize*4), - "r" (dest), "m" (dstW), - "m" (lumSrc+lumFilterSize), "m" (chrSrc+chrFilterSize) - : "%eax", "%ebx", "%ecx", "%edx", "%esi" + :: "m" (-lumFilterSize), "m" (-chrFilterSize), + "m" (lumMmxFilter+lumFilterSize*4), "m" (chrMmxFilter+chrFilterSize*4), + "r" (dest), "m" (dstW), + "m" (lumSrc+lumFilterSize), "m" (chrSrc+chrFilterSize) + : "%eax", "%ebx", "%ecx", "%edx", "%esi" */ #define YSCALEYUV2PACKEDX \ - asm volatile(\ - "xor %%"REG_a", %%"REG_a" \n\t"\ - ASMALIGN(4)\ - "nop \n\t"\ - "1: \n\t"\ - "lea "CHR_MMX_FILTER_OFFSET"(%0), %%"REG_d"\n\t"\ - "mov (%%"REG_d"), %%"REG_S" \n\t"\ - "movq "VROUNDER_OFFSET"(%0), %%mm3\n\t"\ - "movq %%mm3, %%mm4 \n\t"\ - ASMALIGN(4)\ - "2: \n\t"\ - "movq 8(%%"REG_d"), %%mm0 \n\t" /* filterCoeff */\ - "movq (%%"REG_S", %%"REG_a"), %%mm2 \n\t" /* UsrcData */\ - "movq 4096(%%"REG_S", %%"REG_a"), %%mm5 \n\t" /* VsrcData */\ - "add $16, %%"REG_d" \n\t"\ - "mov (%%"REG_d"), %%"REG_S" \n\t"\ - "pmulhw %%mm0, %%mm2 \n\t"\ - "pmulhw %%mm0, %%mm5 \n\t"\ - "paddw %%mm2, %%mm3 \n\t"\ - "paddw %%mm5, %%mm4 \n\t"\ - "test %%"REG_S", %%"REG_S" \n\t"\ - " jnz 2b \n\t"\ + asm volatile(\ + "xor %%"REG_a", %%"REG_a" \n\t"\ + ASMALIGN(4)\ + "nop \n\t"\ + "1: \n\t"\ + "lea "CHR_MMX_FILTER_OFFSET"(%0), %%"REG_d" \n\t"\ + "mov (%%"REG_d"), %%"REG_S" \n\t"\ + "movq "VROUNDER_OFFSET"(%0), %%mm3 \n\t"\ + "movq %%mm3, %%mm4 \n\t"\ + ASMALIGN(4)\ + "2: \n\t"\ + "movq 8(%%"REG_d"), %%mm0 \n\t" /* filterCoeff */\ + "movq (%%"REG_S", %%"REG_a"), %%mm2 \n\t" /* UsrcData */\ + "movq 4096(%%"REG_S", %%"REG_a"), %%mm5 \n\t" /* VsrcData */\ + "add $16, %%"REG_d" \n\t"\ + "mov (%%"REG_d"), %%"REG_S" \n\t"\ + "pmulhw %%mm0, %%mm2 \n\t"\ + "pmulhw %%mm0, %%mm5 \n\t"\ + "paddw %%mm2, %%mm3 \n\t"\ + "paddw %%mm5, %%mm4 \n\t"\ + "test %%"REG_S", %%"REG_S" \n\t"\ + " jnz 2b \n\t"\ \ - "lea "LUM_MMX_FILTER_OFFSET"(%0), %%"REG_d"\n\t"\ - "mov (%%"REG_d"), %%"REG_S" \n\t"\ - "movq "VROUNDER_OFFSET"(%0), %%mm1\n\t"\ - "movq %%mm1, %%mm7 \n\t"\ - ASMALIGN(4)\ - "2: \n\t"\ - "movq 8(%%"REG_d"), %%mm0 \n\t" /* filterCoeff */\ - "movq (%%"REG_S", %%"REG_a", 2), %%mm2 \n\t" /* Y1srcData */\ - "movq 8(%%"REG_S", %%"REG_a", 2), %%mm5 \n\t" /* Y2srcData */\ - "add $16, %%"REG_d" \n\t"\ - "mov (%%"REG_d"), %%"REG_S" \n\t"\ - "pmulhw %%mm0, %%mm2 \n\t"\ - "pmulhw %%mm0, %%mm5 \n\t"\ - "paddw %%mm2, %%mm1 \n\t"\ - "paddw %%mm5, %%mm7 \n\t"\ - "test %%"REG_S", %%"REG_S" \n\t"\ - " jnz 2b \n\t"\ - -#define YSCALEYUV2PACKEDX_END\ - :: "r" (&c->redDither), \ - "m" (dummy), "m" (dummy), "m" (dummy),\ - "r" (dest), "m" (dstW)\ - : "%"REG_a, "%"REG_d, "%"REG_S\ - ); + "lea "LUM_MMX_FILTER_OFFSET"(%0), %%"REG_d" \n\t"\ + "mov (%%"REG_d"), %%"REG_S" \n\t"\ + "movq "VROUNDER_OFFSET"(%0), %%mm1 \n\t"\ + "movq %%mm1, %%mm7 \n\t"\ + ASMALIGN(4)\ + "2: \n\t"\ + "movq 8(%%"REG_d"), %%mm0 \n\t" /* filterCoeff */\ + "movq (%%"REG_S", %%"REG_a", 2), %%mm2 \n\t" /* Y1srcData */\ + "movq 8(%%"REG_S", %%"REG_a", 2), %%mm5 \n\t" /* Y2srcData */\ + "add $16, %%"REG_d" \n\t"\ + "mov (%%"REG_d"), %%"REG_S" \n\t"\ + "pmulhw %%mm0, %%mm2 \n\t"\ + "pmulhw %%mm0, %%mm5 \n\t"\ + "paddw %%mm2, %%mm1 \n\t"\ + "paddw %%mm5, %%mm7 \n\t"\ + "test %%"REG_S", %%"REG_S" \n\t"\ + " jnz 2b \n\t"\ + +#define YSCALEYUV2PACKEDX_END \ + :: "r" (&c->redDither), \ + "m" (dummy), "m" (dummy), "m" (dummy),\ + "r" (dest), "m" (dstW) \ + : "%"REG_a, "%"REG_d, "%"REG_S \ + ); #define YSCALEYUV2PACKEDX_ACCURATE \ - asm volatile(\ - "xor %%"REG_a", %%"REG_a" \n\t"\ - ASMALIGN(4)\ - "nop \n\t"\ - "1: \n\t"\ - "lea "CHR_MMX_FILTER_OFFSET"(%0), %%"REG_d"\n\t"\ - "mov (%%"REG_d"), %%"REG_S" \n\t"\ - "pxor %%mm4, %%mm4 \n\t"\ - "pxor %%mm5, %%mm5 \n\t"\ - "pxor %%mm6, %%mm6 \n\t"\ - "pxor %%mm7, %%mm7 \n\t"\ - ASMALIGN(4)\ - "2: \n\t"\ - "movq (%%"REG_S", %%"REG_a"), %%mm0 \n\t" /* UsrcData */\ - "movq 4096(%%"REG_S", %%"REG_a"), %%mm2 \n\t" /* VsrcData */\ - "mov 4(%%"REG_d"), %%"REG_S" \n\t"\ - "movq (%%"REG_S", %%"REG_a"), %%mm1 \n\t" /* UsrcData */\ - "movq %%mm0, %%mm3 \n\t"\ - "punpcklwd %%mm1, %%mm0 \n\t"\ - "punpckhwd %%mm1, %%mm3 \n\t"\ - "movq 8(%%"REG_d"), %%mm1 \n\t" /* filterCoeff */\ - "pmaddwd %%mm1, %%mm0 \n\t"\ - "pmaddwd %%mm1, %%mm3 \n\t"\ - "paddd %%mm0, %%mm4 \n\t"\ - "paddd %%mm3, %%mm5 \n\t"\ - "movq 4096(%%"REG_S", %%"REG_a"), %%mm3 \n\t" /* VsrcData */\ - "mov 16(%%"REG_d"), %%"REG_S" \n\t"\ - "add $16, %%"REG_d" \n\t"\ - "test %%"REG_S", %%"REG_S" \n\t"\ - "movq %%mm2, %%mm0 \n\t"\ - "punpcklwd %%mm3, %%mm2 \n\t"\ - "punpckhwd %%mm3, %%mm0 \n\t"\ - "pmaddwd %%mm1, %%mm2 \n\t"\ - "pmaddwd %%mm1, %%mm0 \n\t"\ - "paddd %%mm2, %%mm6 \n\t"\ - "paddd %%mm0, %%mm7 \n\t"\ - " jnz 2b \n\t"\ - "psrad $16, %%mm4 \n\t"\ - "psrad $16, %%mm5 \n\t"\ - "psrad $16, %%mm6 \n\t"\ - "psrad $16, %%mm7 \n\t"\ - "movq "VROUNDER_OFFSET"(%0), %%mm0\n\t"\ - "packssdw %%mm5, %%mm4 \n\t"\ - "packssdw %%mm7, %%mm6 \n\t"\ - "paddw %%mm0, %%mm4 \n\t"\ - "paddw %%mm0, %%mm6 \n\t"\ - "movq %%mm4, "U_TEMP"(%0) \n\t"\ - "movq %%mm6, "V_TEMP"(%0) \n\t"\ + asm volatile(\ + "xor %%"REG_a", %%"REG_a" \n\t"\ + ASMALIGN(4)\ + "nop \n\t"\ + "1: \n\t"\ + "lea "CHR_MMX_FILTER_OFFSET"(%0), %%"REG_d" \n\t"\ + "mov (%%"REG_d"), %%"REG_S" \n\t"\ + "pxor %%mm4, %%mm4 \n\t"\ + "pxor %%mm5, %%mm5 \n\t"\ + "pxor %%mm6, %%mm6 \n\t"\ + "pxor %%mm7, %%mm7 \n\t"\ + ASMALIGN(4)\ + "2: \n\t"\ + "movq (%%"REG_S", %%"REG_a"), %%mm0 \n\t" /* UsrcData */\ + "movq 4096(%%"REG_S", %%"REG_a"), %%mm2 \n\t" /* VsrcData */\ + "mov 4(%%"REG_d"), %%"REG_S" \n\t"\ + "movq (%%"REG_S", %%"REG_a"), %%mm1 \n\t" /* UsrcData */\ + "movq %%mm0, %%mm3 \n\t"\ + "punpcklwd %%mm1, %%mm0 \n\t"\ + "punpckhwd %%mm1, %%mm3 \n\t"\ + "movq 8(%%"REG_d"), %%mm1 \n\t" /* filterCoeff */\ + "pmaddwd %%mm1, %%mm0 \n\t"\ + "pmaddwd %%mm1, %%mm3 \n\t"\ + "paddd %%mm0, %%mm4 \n\t"\ + "paddd %%mm3, %%mm5 \n\t"\ + "movq 4096(%%"REG_S", %%"REG_a"), %%mm3 \n\t" /* VsrcData */\ + "mov 16(%%"REG_d"), %%"REG_S" \n\t"\ + "add $16, %%"REG_d" \n\t"\ + "test %%"REG_S", %%"REG_S" \n\t"\ + "movq %%mm2, %%mm0 \n\t"\ + "punpcklwd %%mm3, %%mm2 \n\t"\ + "punpckhwd %%mm3, %%mm0 \n\t"\ + "pmaddwd %%mm1, %%mm2 \n\t"\ + "pmaddwd %%mm1, %%mm0 \n\t"\ + "paddd %%mm2, %%mm6 \n\t"\ + "paddd %%mm0, %%mm7 \n\t"\ + " jnz 2b \n\t"\ + "psrad $16, %%mm4 \n\t"\ + "psrad $16, %%mm5 \n\t"\ + "psrad $16, %%mm6 \n\t"\ + "psrad $16, %%mm7 \n\t"\ + "movq "VROUNDER_OFFSET"(%0), %%mm0 \n\t"\ + "packssdw %%mm5, %%mm4 \n\t"\ + "packssdw %%mm7, %%mm6 \n\t"\ + "paddw %%mm0, %%mm4 \n\t"\ + "paddw %%mm0, %%mm6 \n\t"\ + "movq %%mm4, "U_TEMP"(%0) \n\t"\ + "movq %%mm6, "V_TEMP"(%0) \n\t"\ \ - "lea "LUM_MMX_FILTER_OFFSET"(%0), %%"REG_d"\n\t"\ - "mov (%%"REG_d"), %%"REG_S" \n\t"\ - "pxor %%mm1, %%mm1 \n\t"\ - "pxor %%mm5, %%mm5 \n\t"\ - "pxor %%mm7, %%mm7 \n\t"\ - "pxor %%mm6, %%mm6 \n\t"\ - ASMALIGN(4)\ - "2: \n\t"\ - "movq (%%"REG_S", %%"REG_a", 2), %%mm0 \n\t" /* Y1srcData */\ - "movq 8(%%"REG_S", %%"REG_a", 2), %%mm2 \n\t" /* Y2srcData */\ - "mov 4(%%"REG_d"), %%"REG_S" \n\t"\ - "movq (%%"REG_S", %%"REG_a", 2), %%mm4 \n\t" /* Y1srcData */\ - "movq %%mm0, %%mm3 \n\t"\ - "punpcklwd %%mm4, %%mm0 \n\t"\ - "punpckhwd %%mm4, %%mm3 \n\t"\ - "movq 8(%%"REG_d"), %%mm4 \n\t" /* filterCoeff */\ - "pmaddwd %%mm4, %%mm0 \n\t"\ - "pmaddwd %%mm4, %%mm3 \n\t"\ - "paddd %%mm0, %%mm1 \n\t"\ - "paddd %%mm3, %%mm5 \n\t"\ - "movq 8(%%"REG_S", %%"REG_a", 2), %%mm3 \n\t" /* Y2srcData */\ - "mov 16(%%"REG_d"), %%"REG_S" \n\t"\ - "add $16, %%"REG_d" \n\t"\ - "test %%"REG_S", %%"REG_S" \n\t"\ - "movq %%mm2, %%mm0 \n\t"\ - "punpcklwd %%mm3, %%mm2 \n\t"\ - "punpckhwd %%mm3, %%mm0 \n\t"\ - "pmaddwd %%mm4, %%mm2 \n\t"\ - "pmaddwd %%mm4, %%mm0 \n\t"\ - "paddd %%mm2, %%mm7 \n\t"\ - "paddd %%mm0, %%mm6 \n\t"\ - " jnz 2b \n\t"\ - "psrad $16, %%mm1 \n\t"\ - "psrad $16, %%mm5 \n\t"\ - "psrad $16, %%mm7 \n\t"\ - "psrad $16, %%mm6 \n\t"\ - "movq "VROUNDER_OFFSET"(%0), %%mm0\n\t"\ - "packssdw %%mm5, %%mm1 \n\t"\ - "packssdw %%mm6, %%mm7 \n\t"\ - "paddw %%mm0, %%mm1 \n\t"\ - "paddw %%mm0, %%mm7 \n\t"\ - "movq "U_TEMP"(%0), %%mm3 \n\t"\ - "movq "V_TEMP"(%0), %%mm4 \n\t"\ + "lea "LUM_MMX_FILTER_OFFSET"(%0), %%"REG_d" \n\t"\ + "mov (%%"REG_d"), %%"REG_S" \n\t"\ + "pxor %%mm1, %%mm1 \n\t"\ + "pxor %%mm5, %%mm5 \n\t"\ + "pxor %%mm7, %%mm7 \n\t"\ + "pxor %%mm6, %%mm6 \n\t"\ + ASMALIGN(4)\ + "2: \n\t"\ + "movq (%%"REG_S", %%"REG_a", 2), %%mm0 \n\t" /* Y1srcData */\ + "movq 8(%%"REG_S", %%"REG_a", 2), %%mm2 \n\t" /* Y2srcData */\ + "mov 4(%%"REG_d"), %%"REG_S" \n\t"\ + "movq (%%"REG_S", %%"REG_a", 2), %%mm4 \n\t" /* Y1srcData */\ + "movq %%mm0, %%mm3 \n\t"\ + "punpcklwd %%mm4, %%mm0 \n\t"\ + "punpckhwd %%mm4, %%mm3 \n\t"\ + "movq 8(%%"REG_d"), %%mm4 \n\t" /* filterCoeff */\ + "pmaddwd %%mm4, %%mm0 \n\t"\ + "pmaddwd %%mm4, %%mm3 \n\t"\ + "paddd %%mm0, %%mm1 \n\t"\ + "paddd %%mm3, %%mm5 \n\t"\ + "movq 8(%%"REG_S", %%"REG_a", 2), %%mm3 \n\t" /* Y2srcData */\ + "mov 16(%%"REG_d"), %%"REG_S" \n\t"\ + "add $16, %%"REG_d" \n\t"\ + "test %%"REG_S", %%"REG_S" \n\t"\ + "movq %%mm2, %%mm0 \n\t"\ + "punpcklwd %%mm3, %%mm2 \n\t"\ + "punpckhwd %%mm3, %%mm0 \n\t"\ + "pmaddwd %%mm4, %%mm2 \n\t"\ + "pmaddwd %%mm4, %%mm0 \n\t"\ + "paddd %%mm2, %%mm7 \n\t"\ + "paddd %%mm0, %%mm6 \n\t"\ + " jnz 2b \n\t"\ + "psrad $16, %%mm1 \n\t"\ + "psrad $16, %%mm5 \n\t"\ + "psrad $16, %%mm7 \n\t"\ + "psrad $16, %%mm6 \n\t"\ + "movq "VROUNDER_OFFSET"(%0), %%mm0 \n\t"\ + "packssdw %%mm5, %%mm1 \n\t"\ + "packssdw %%mm6, %%mm7 \n\t"\ + "paddw %%mm0, %%mm1 \n\t"\ + "paddw %%mm0, %%mm7 \n\t"\ + "movq "U_TEMP"(%0), %%mm3 \n\t"\ + "movq "V_TEMP"(%0), %%mm4 \n\t"\ #define YSCALEYUV2RGBX \ - "psubw "U_OFFSET"(%0), %%mm3 \n\t" /* (U-128)8*/\ - "psubw "V_OFFSET"(%0), %%mm4 \n\t" /* (V-128)8*/\ - "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ - "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\ - "pmulhw "UG_COEFF"(%0), %%mm3 \n\t"\ - "pmulhw "VG_COEFF"(%0), %%mm4 \n\t"\ - /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\ - "pmulhw "UB_COEFF"(%0), %%mm2 \n\t"\ - "pmulhw "VR_COEFF"(%0), %%mm5 \n\t"\ - "psubw "Y_OFFSET"(%0), %%mm1 \n\t" /* 8(Y-16)*/\ - "psubw "Y_OFFSET"(%0), %%mm7 \n\t" /* 8(Y-16)*/\ - "pmulhw "Y_COEFF"(%0), %%mm1 \n\t"\ - "pmulhw "Y_COEFF"(%0), %%mm7 \n\t"\ - /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\ - "paddw %%mm3, %%mm4 \n\t"\ - "movq %%mm2, %%mm0 \n\t"\ - "movq %%mm5, %%mm6 \n\t"\ - "movq %%mm4, %%mm3 \n\t"\ - "punpcklwd %%mm2, %%mm2 \n\t"\ - "punpcklwd %%mm5, %%mm5 \n\t"\ - "punpcklwd %%mm4, %%mm4 \n\t"\ - "paddw %%mm1, %%mm2 \n\t"\ - "paddw %%mm1, %%mm5 \n\t"\ - "paddw %%mm1, %%mm4 \n\t"\ - "punpckhwd %%mm0, %%mm0 \n\t"\ - "punpckhwd %%mm6, %%mm6 \n\t"\ - "punpckhwd %%mm3, %%mm3 \n\t"\ - "paddw %%mm7, %%mm0 \n\t"\ - "paddw %%mm7, %%mm6 \n\t"\ - "paddw %%mm7, %%mm3 \n\t"\ - /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\ - "packuswb %%mm0, %%mm2 \n\t"\ - "packuswb %%mm6, %%mm5 \n\t"\ - "packuswb %%mm3, %%mm4 \n\t"\ - "pxor %%mm7, %%mm7 \n\t" + "psubw "U_OFFSET"(%0), %%mm3 \n\t" /* (U-128)8*/\ + "psubw "V_OFFSET"(%0), %%mm4 \n\t" /* (V-128)8*/\ + "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ + "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\ + "pmulhw "UG_COEFF"(%0), %%mm3 \n\t"\ + "pmulhw "VG_COEFF"(%0), %%mm4 \n\t"\ +/* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\ + "pmulhw "UB_COEFF"(%0), %%mm2 \n\t"\ + "pmulhw "VR_COEFF"(%0), %%mm5 \n\t"\ + "psubw "Y_OFFSET"(%0), %%mm1 \n\t" /* 8(Y-16)*/\ + "psubw "Y_OFFSET"(%0), %%mm7 \n\t" /* 8(Y-16)*/\ + "pmulhw "Y_COEFF"(%0), %%mm1 \n\t"\ + "pmulhw "Y_COEFF"(%0), %%mm7 \n\t"\ +/* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\ + "paddw %%mm3, %%mm4 \n\t"\ + "movq %%mm2, %%mm0 \n\t"\ + "movq %%mm5, %%mm6 \n\t"\ + "movq %%mm4, %%mm3 \n\t"\ + "punpcklwd %%mm2, %%mm2 \n\t"\ + "punpcklwd %%mm5, %%mm5 \n\t"\ + "punpcklwd %%mm4, %%mm4 \n\t"\ + "paddw %%mm1, %%mm2 \n\t"\ + "paddw %%mm1, %%mm5 \n\t"\ + "paddw %%mm1, %%mm4 \n\t"\ + "punpckhwd %%mm0, %%mm0 \n\t"\ + "punpckhwd %%mm6, %%mm6 \n\t"\ + "punpckhwd %%mm3, %%mm3 \n\t"\ + "paddw %%mm7, %%mm0 \n\t"\ + "paddw %%mm7, %%mm6 \n\t"\ + "paddw %%mm7, %%mm3 \n\t"\ + /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\ + "packuswb %%mm0, %%mm2 \n\t"\ + "packuswb %%mm6, %%mm5 \n\t"\ + "packuswb %%mm3, %%mm4 \n\t"\ + "pxor %%mm7, %%mm7 \n\t" #if 0 #define FULL_YSCALEYUV2RGB \ - "pxor %%mm7, %%mm7 \n\t"\ - "movd %6, %%mm6 \n\t" /*yalpha1*/\ - "punpcklwd %%mm6, %%mm6 \n\t"\ - "punpcklwd %%mm6, %%mm6 \n\t"\ - "movd %7, %%mm5 \n\t" /*uvalpha1*/\ - "punpcklwd %%mm5, %%mm5 \n\t"\ - "punpcklwd %%mm5, %%mm5 \n\t"\ - "xor %%"REG_a", %%"REG_a" \n\t"\ - ASMALIGN(4)\ - "1: \n\t"\ - "movq (%0, %%"REG_a", 2), %%mm0 \n\t" /*buf0[eax]*/\ - "movq (%1, %%"REG_a", 2), %%mm1 \n\t" /*buf1[eax]*/\ - "movq (%2, %%"REG_a",2), %%mm2 \n\t" /* uvbuf0[eax]*/\ - "movq (%3, %%"REG_a",2), %%mm3 \n\t" /* uvbuf1[eax]*/\ - "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\ - "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\ - "pmulhw %%mm6, %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ - "pmulhw %%mm5, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\ - "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ - "movq 4096(%2, %%"REG_a",2), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\ - "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\ - "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ - "movq 4096(%3, %%"REG_a",2), %%mm0 \n\t" /* uvbuf1[eax+2048]*/\ - "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\ - "psubw %%mm0, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\ - "psubw "MANGLE(w80)", %%mm1 \n\t" /* 8(Y-16)*/\ - "psubw "MANGLE(w400)", %%mm3 \n\t" /* 8(U-128)*/\ - "pmulhw "MANGLE(yCoeff)", %%mm1 \n\t"\ + "pxor %%mm7, %%mm7 \n\t"\ + "movd %6, %%mm6 \n\t" /*yalpha1*/\ + "punpcklwd %%mm6, %%mm6 \n\t"\ + "punpcklwd %%mm6, %%mm6 \n\t"\ + "movd %7, %%mm5 \n\t" /*uvalpha1*/\ + "punpcklwd %%mm5, %%mm5 \n\t"\ + "punpcklwd %%mm5, %%mm5 \n\t"\ + "xor %%"REG_a", %%"REG_a" \n\t"\ + ASMALIGN(4)\ + "1: \n\t"\ + "movq (%0, %%"REG_a",2), %%mm0 \n\t" /*buf0[eax]*/\ + "movq (%1, %%"REG_a",2), %%mm1 \n\t" /*buf1[eax]*/\ + "movq (%2, %%"REG_a",2), %%mm2 \n\t" /* uvbuf0[eax]*/\ + "movq (%3, %%"REG_a",2), %%mm3 \n\t" /* uvbuf1[eax]*/\ + "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\ + "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\ + "pmulhw %%mm6, %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ + "pmulhw %%mm5, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\ + "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ + "movq 4096(%2, %%"REG_a",2), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\ + "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\ + "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ + "movq 4096(%3, %%"REG_a",2), %%mm0 \n\t" /* uvbuf1[eax+2048]*/\ + "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\ + "psubw %%mm0, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\ + "psubw "MANGLE(w80)", %%mm1 \n\t" /* 8(Y-16)*/\ + "psubw "MANGLE(w400)", %%mm3 \n\t" /* 8(U-128)*/\ + "pmulhw "MANGLE(yCoeff)", %%mm1 \n\t"\ \ \ - "pmulhw %%mm5, %%mm4 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\ - "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ - "pmulhw "MANGLE(ubCoeff)", %%mm3\n\t"\ - "psraw $4, %%mm0 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\ - "pmulhw "MANGLE(ugCoeff)", %%mm2\n\t"\ - "paddw %%mm4, %%mm0 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\ - "psubw "MANGLE(w400)", %%mm0 \n\t" /* (V-128)8*/\ + "pmulhw %%mm5, %%mm4 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\ + "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ + "pmulhw "MANGLE(ubCoeff)", %%mm3 \n\t"\ + "psraw $4, %%mm0 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\ + "pmulhw "MANGLE(ugCoeff)", %%mm2 \n\t"\ + "paddw %%mm4, %%mm0 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\ + "psubw "MANGLE(w400)", %%mm0 \n\t" /* (V-128)8*/\ \ \ - "movq %%mm0, %%mm4 \n\t" /* (V-128)8*/\ - "pmulhw "MANGLE(vrCoeff)", %%mm0\n\t"\ - "pmulhw "MANGLE(vgCoeff)", %%mm4\n\t"\ - "paddw %%mm1, %%mm3 \n\t" /* B*/\ - "paddw %%mm1, %%mm0 \n\t" /* R*/\ - "packuswb %%mm3, %%mm3 \n\t"\ + "movq %%mm0, %%mm4 \n\t" /* (V-128)8*/\ + "pmulhw "MANGLE(vrCoeff)", %%mm0 \n\t"\ + "pmulhw "MANGLE(vgCoeff)", %%mm4 \n\t"\ + "paddw %%mm1, %%mm3 \n\t" /* B*/\ + "paddw %%mm1, %%mm0 \n\t" /* R*/\ + "packuswb %%mm3, %%mm3 \n\t"\ \ - "packuswb %%mm0, %%mm0 \n\t"\ - "paddw %%mm4, %%mm2 \n\t"\ - "paddw %%mm2, %%mm1 \n\t" /* G*/\ + "packuswb %%mm0, %%mm0 \n\t"\ + "paddw %%mm4, %%mm2 \n\t"\ + "paddw %%mm2, %%mm1 \n\t" /* G*/\ \ - "packuswb %%mm1, %%mm1 \n\t" + "packuswb %%mm1, %%mm1 \n\t" #endif #define REAL_YSCALEYUV2PACKED(index, c) \ - "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0\n\t"\ - "movq "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm1\n\t"\ - "psraw $3, %%mm0 \n\t"\ - "psraw $3, %%mm1 \n\t"\ - "movq %%mm0, "CHR_MMX_FILTER_OFFSET"+8("#c")\n\t"\ - "movq %%mm1, "LUM_MMX_FILTER_OFFSET"+8("#c")\n\t"\ - "xor "#index", "#index" \n\t"\ - ASMALIGN(4)\ - "1: \n\t"\ - "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ - "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ - "movq 4096(%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ - "movq 4096(%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ - "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\ - "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\ - "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0\n\t"\ - "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\ - "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\ - "psraw $7, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\ - "psraw $7, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\ - "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\ - "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\ - "movq (%0, "#index", 2), %%mm0 \n\t" /*buf0[eax]*/\ - "movq (%1, "#index", 2), %%mm1 \n\t" /*buf1[eax]*/\ - "movq 8(%0, "#index", 2), %%mm6 \n\t" /*buf0[eax]*/\ - "movq 8(%1, "#index", 2), %%mm7 \n\t" /*buf1[eax]*/\ - "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\ - "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\ - "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0\n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ - "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6\n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ - "psraw $7, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ - "psraw $7, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ - "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ - "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ - + "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\ + "movq "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm1 \n\t"\ + "psraw $3, %%mm0 \n\t"\ + "psraw $3, %%mm1 \n\t"\ + "movq %%mm0, "CHR_MMX_FILTER_OFFSET"+8("#c") \n\t"\ + "movq %%mm1, "LUM_MMX_FILTER_OFFSET"+8("#c") \n\t"\ + "xor "#index", "#index" \n\t"\ + ASMALIGN(4)\ + "1: \n\t"\ + "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ + "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ + "movq 4096(%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ + "movq 4096(%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ + "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\ + "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\ + "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\ + "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\ + "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\ + "psraw $7, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\ + "psraw $7, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\ + "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\ + "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\ + "movq (%0, "#index", 2), %%mm0 \n\t" /*buf0[eax]*/\ + "movq (%1, "#index", 2), %%mm1 \n\t" /*buf1[eax]*/\ + "movq 8(%0, "#index", 2), %%mm6 \n\t" /*buf0[eax]*/\ + "movq 8(%1, "#index", 2), %%mm7 \n\t" /*buf1[eax]*/\ + "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\ + "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\ + "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ + "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ + "psraw $7, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ + "psraw $7, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ + "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ + "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ + #define YSCALEYUV2PACKED(index, c) REAL_YSCALEYUV2PACKED(index, c) - + #define REAL_YSCALEYUV2RGB(index, c) \ - "xor "#index", "#index" \n\t"\ - ASMALIGN(4)\ - "1: \n\t"\ - "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ - "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ - "movq 4096(%2, "#index"), %%mm5\n\t" /* uvbuf0[eax+2048]*/\ - "movq 4096(%3, "#index"), %%mm4\n\t" /* uvbuf1[eax+2048]*/\ - "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\ - "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\ - "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0\n\t"\ - "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\ - "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\ - "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\ - "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\ - "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\ - "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\ - "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\ - "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\ - "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ - "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\ - "pmulhw "UG_COEFF"("#c"), %%mm3\n\t"\ - "pmulhw "VG_COEFF"("#c"), %%mm4\n\t"\ - /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\ - "movq (%0, "#index", 2), %%mm0 \n\t" /*buf0[eax]*/\ - "movq (%1, "#index", 2), %%mm1 \n\t" /*buf1[eax]*/\ - "movq 8(%0, "#index", 2), %%mm6\n\t" /*buf0[eax]*/\ - "movq 8(%1, "#index", 2), %%mm7\n\t" /*buf1[eax]*/\ - "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\ - "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\ - "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0\n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ - "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6\n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ - "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ - "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ - "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ - "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ - "pmulhw "UB_COEFF"("#c"), %%mm2\n\t"\ - "pmulhw "VR_COEFF"("#c"), %%mm5\n\t"\ - "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\ - "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\ - "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\ - "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\ - /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\ - "paddw %%mm3, %%mm4 \n\t"\ - "movq %%mm2, %%mm0 \n\t"\ - "movq %%mm5, %%mm6 \n\t"\ - "movq %%mm4, %%mm3 \n\t"\ - "punpcklwd %%mm2, %%mm2 \n\t"\ - "punpcklwd %%mm5, %%mm5 \n\t"\ - "punpcklwd %%mm4, %%mm4 \n\t"\ - "paddw %%mm1, %%mm2 \n\t"\ - "paddw %%mm1, %%mm5 \n\t"\ - "paddw %%mm1, %%mm4 \n\t"\ - "punpckhwd %%mm0, %%mm0 \n\t"\ - "punpckhwd %%mm6, %%mm6 \n\t"\ - "punpckhwd %%mm3, %%mm3 \n\t"\ - "paddw %%mm7, %%mm0 \n\t"\ - "paddw %%mm7, %%mm6 \n\t"\ - "paddw %%mm7, %%mm3 \n\t"\ - /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\ - "packuswb %%mm0, %%mm2 \n\t"\ - "packuswb %%mm6, %%mm5 \n\t"\ - "packuswb %%mm3, %%mm4 \n\t"\ - "pxor %%mm7, %%mm7 \n\t" + "xor "#index", "#index" \n\t"\ + ASMALIGN(4)\ + "1: \n\t"\ + "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ + "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ + "movq 4096(%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ + "movq 4096(%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ + "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\ + "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\ + "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\ + "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\ + "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\ + "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\ + "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\ + "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\ + "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\ + "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\ + "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\ + "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ + "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\ + "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\ + "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\ + /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\ + "movq (%0, "#index", 2), %%mm0 \n\t" /*buf0[eax]*/\ + "movq (%1, "#index", 2), %%mm1 \n\t" /*buf1[eax]*/\ + "movq 8(%0, "#index", 2), %%mm6 \n\t" /*buf0[eax]*/\ + "movq 8(%1, "#index", 2), %%mm7 \n\t" /*buf1[eax]*/\ + "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\ + "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\ + "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ + "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ + "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ + "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ + "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ + "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ + "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\ + "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\ + "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\ + "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\ + "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\ + "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\ + /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\ + "paddw %%mm3, %%mm4 \n\t"\ + "movq %%mm2, %%mm0 \n\t"\ + "movq %%mm5, %%mm6 \n\t"\ + "movq %%mm4, %%mm3 \n\t"\ + "punpcklwd %%mm2, %%mm2 \n\t"\ + "punpcklwd %%mm5, %%mm5 \n\t"\ + "punpcklwd %%mm4, %%mm4 \n\t"\ + "paddw %%mm1, %%mm2 \n\t"\ + "paddw %%mm1, %%mm5 \n\t"\ + "paddw %%mm1, %%mm4 \n\t"\ + "punpckhwd %%mm0, %%mm0 \n\t"\ + "punpckhwd %%mm6, %%mm6 \n\t"\ + "punpckhwd %%mm3, %%mm3 \n\t"\ + "paddw %%mm7, %%mm0 \n\t"\ + "paddw %%mm7, %%mm6 \n\t"\ + "paddw %%mm7, %%mm3 \n\t"\ + /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\ + "packuswb %%mm0, %%mm2 \n\t"\ + "packuswb %%mm6, %%mm5 \n\t"\ + "packuswb %%mm3, %%mm4 \n\t"\ + "pxor %%mm7, %%mm7 \n\t" #define YSCALEYUV2RGB(index, c) REAL_YSCALEYUV2RGB(index, c) - + #define REAL_YSCALEYUV2PACKED1(index, c) \ - "xor "#index", "#index" \n\t"\ - ASMALIGN(4)\ - "1: \n\t"\ - "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\ - "movq 4096(%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\ - "psraw $7, %%mm3 \n\t" \ - "psraw $7, %%mm4 \n\t" \ - "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\ - "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\ - "psraw $7, %%mm1 \n\t" \ - "psraw $7, %%mm7 \n\t" \ - + "xor "#index", "#index" \n\t"\ + ASMALIGN(4)\ + "1: \n\t"\ + "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\ + "movq 4096(%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\ + "psraw $7, %%mm3 \n\t" \ + "psraw $7, %%mm4 \n\t" \ + "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\ + "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\ + "psraw $7, %%mm1 \n\t" \ + "psraw $7, %%mm7 \n\t" \ + #define YSCALEYUV2PACKED1(index, c) REAL_YSCALEYUV2PACKED1(index, c) - + #define REAL_YSCALEYUV2RGB1(index, c) \ - "xor "#index", "#index" \n\t"\ - ASMALIGN(4)\ - "1: \n\t"\ - "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\ - "movq 4096(%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\ - "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\ - "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\ - "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\ - "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\ - "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ - "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\ - "pmulhw "UG_COEFF"("#c"), %%mm3\n\t"\ - "pmulhw "VG_COEFF"("#c"), %%mm4\n\t"\ - /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\ - "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\ - "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\ - "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ - "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ - "pmulhw "UB_COEFF"("#c"), %%mm2\n\t"\ - "pmulhw "VR_COEFF"("#c"), %%mm5\n\t"\ - "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\ - "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\ - "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\ - "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\ - /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\ - "paddw %%mm3, %%mm4 \n\t"\ - "movq %%mm2, %%mm0 \n\t"\ - "movq %%mm5, %%mm6 \n\t"\ - "movq %%mm4, %%mm3 \n\t"\ - "punpcklwd %%mm2, %%mm2 \n\t"\ - "punpcklwd %%mm5, %%mm5 \n\t"\ - "punpcklwd %%mm4, %%mm4 \n\t"\ - "paddw %%mm1, %%mm2 \n\t"\ - "paddw %%mm1, %%mm5 \n\t"\ - "paddw %%mm1, %%mm4 \n\t"\ - "punpckhwd %%mm0, %%mm0 \n\t"\ - "punpckhwd %%mm6, %%mm6 \n\t"\ - "punpckhwd %%mm3, %%mm3 \n\t"\ - "paddw %%mm7, %%mm0 \n\t"\ - "paddw %%mm7, %%mm6 \n\t"\ - "paddw %%mm7, %%mm3 \n\t"\ - /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\ - "packuswb %%mm0, %%mm2 \n\t"\ - "packuswb %%mm6, %%mm5 \n\t"\ - "packuswb %%mm3, %%mm4 \n\t"\ - "pxor %%mm7, %%mm7 \n\t" + "xor "#index", "#index" \n\t"\ + ASMALIGN(4)\ + "1: \n\t"\ + "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\ + "movq 4096(%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\ + "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\ + "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\ + "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\ + "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\ + "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ + "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\ + "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\ + "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\ + /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\ + "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\ + "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\ + "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ + "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ + "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\ + "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\ + "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\ + "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\ + "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\ + "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\ + /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\ + "paddw %%mm3, %%mm4 \n\t"\ + "movq %%mm2, %%mm0 \n\t"\ + "movq %%mm5, %%mm6 \n\t"\ + "movq %%mm4, %%mm3 \n\t"\ + "punpcklwd %%mm2, %%mm2 \n\t"\ + "punpcklwd %%mm5, %%mm5 \n\t"\ + "punpcklwd %%mm4, %%mm4 \n\t"\ + "paddw %%mm1, %%mm2 \n\t"\ + "paddw %%mm1, %%mm5 \n\t"\ + "paddw %%mm1, %%mm4 \n\t"\ + "punpckhwd %%mm0, %%mm0 \n\t"\ + "punpckhwd %%mm6, %%mm6 \n\t"\ + "punpckhwd %%mm3, %%mm3 \n\t"\ + "paddw %%mm7, %%mm0 \n\t"\ + "paddw %%mm7, %%mm6 \n\t"\ + "paddw %%mm7, %%mm3 \n\t"\ + /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\ + "packuswb %%mm0, %%mm2 \n\t"\ + "packuswb %%mm6, %%mm5 \n\t"\ + "packuswb %%mm3, %%mm4 \n\t"\ + "pxor %%mm7, %%mm7 \n\t" #define YSCALEYUV2RGB1(index, c) REAL_YSCALEYUV2RGB1(index, c) #define REAL_YSCALEYUV2PACKED1b(index, c) \ - "xor "#index", "#index" \n\t"\ - ASMALIGN(4)\ - "1: \n\t"\ - "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ - "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ - "movq 4096(%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ - "movq 4096(%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ - "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\ - "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\ - "psrlw $8, %%mm3 \n\t" \ - "psrlw $8, %%mm4 \n\t" \ - "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\ - "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\ - "psraw $7, %%mm1 \n\t" \ - "psraw $7, %%mm7 \n\t" + "xor "#index", "#index" \n\t"\ + ASMALIGN(4)\ + "1: \n\t"\ + "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ + "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ + "movq 4096(%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ + "movq 4096(%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ + "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\ + "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\ + "psrlw $8, %%mm3 \n\t" \ + "psrlw $8, %%mm4 \n\t" \ + "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\ + "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\ + "psraw $7, %%mm1 \n\t" \ + "psraw $7, %%mm7 \n\t" #define YSCALEYUV2PACKED1b(index, c) REAL_YSCALEYUV2PACKED1b(index, c) - + // do vertical chrominance interpolation #define REAL_YSCALEYUV2RGB1b(index, c) \ - "xor "#index", "#index" \n\t"\ - ASMALIGN(4)\ - "1: \n\t"\ - "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ - "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ - "movq 4096(%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ - "movq 4096(%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ - "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\ - "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\ - "psrlw $5, %%mm3 \n\t" /*FIXME might overflow*/\ - "psrlw $5, %%mm4 \n\t" /*FIXME might overflow*/\ - "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\ - "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\ - "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ - "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\ - "pmulhw "UG_COEFF"("#c"), %%mm3\n\t"\ - "pmulhw "VG_COEFF"("#c"), %%mm4\n\t"\ - /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\ - "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\ - "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\ - "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ - "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ - "pmulhw "UB_COEFF"("#c"), %%mm2\n\t"\ - "pmulhw "VR_COEFF"("#c"), %%mm5\n\t"\ - "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\ - "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\ - "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\ - "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\ - /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\ - "paddw %%mm3, %%mm4 \n\t"\ - "movq %%mm2, %%mm0 \n\t"\ - "movq %%mm5, %%mm6 \n\t"\ - "movq %%mm4, %%mm3 \n\t"\ - "punpcklwd %%mm2, %%mm2 \n\t"\ - "punpcklwd %%mm5, %%mm5 \n\t"\ - "punpcklwd %%mm4, %%mm4 \n\t"\ - "paddw %%mm1, %%mm2 \n\t"\ - "paddw %%mm1, %%mm5 \n\t"\ - "paddw %%mm1, %%mm4 \n\t"\ - "punpckhwd %%mm0, %%mm0 \n\t"\ - "punpckhwd %%mm6, %%mm6 \n\t"\ - "punpckhwd %%mm3, %%mm3 \n\t"\ - "paddw %%mm7, %%mm0 \n\t"\ - "paddw %%mm7, %%mm6 \n\t"\ - "paddw %%mm7, %%mm3 \n\t"\ - /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\ - "packuswb %%mm0, %%mm2 \n\t"\ - "packuswb %%mm6, %%mm5 \n\t"\ - "packuswb %%mm3, %%mm4 \n\t"\ - "pxor %%mm7, %%mm7 \n\t" + "xor "#index", "#index" \n\t"\ + ASMALIGN(4)\ + "1: \n\t"\ + "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ + "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ + "movq 4096(%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ + "movq 4096(%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ + "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\ + "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\ + "psrlw $5, %%mm3 \n\t" /*FIXME might overflow*/\ + "psrlw $5, %%mm4 \n\t" /*FIXME might overflow*/\ + "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\ + "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\ + "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ + "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\ + "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\ + "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\ + /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\ + "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\ + "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\ + "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ + "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ + "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\ + "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\ + "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\ + "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\ + "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\ + "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\ + /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\ + "paddw %%mm3, %%mm4 \n\t"\ + "movq %%mm2, %%mm0 \n\t"\ + "movq %%mm5, %%mm6 \n\t"\ + "movq %%mm4, %%mm3 \n\t"\ + "punpcklwd %%mm2, %%mm2 \n\t"\ + "punpcklwd %%mm5, %%mm5 \n\t"\ + "punpcklwd %%mm4, %%mm4 \n\t"\ + "paddw %%mm1, %%mm2 \n\t"\ + "paddw %%mm1, %%mm5 \n\t"\ + "paddw %%mm1, %%mm4 \n\t"\ + "punpckhwd %%mm0, %%mm0 \n\t"\ + "punpckhwd %%mm6, %%mm6 \n\t"\ + "punpckhwd %%mm3, %%mm3 \n\t"\ + "paddw %%mm7, %%mm0 \n\t"\ + "paddw %%mm7, %%mm6 \n\t"\ + "paddw %%mm7, %%mm3 \n\t"\ + /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\ + "packuswb %%mm0, %%mm2 \n\t"\ + "packuswb %%mm6, %%mm5 \n\t"\ + "packuswb %%mm3, %%mm4 \n\t"\ + "pxor %%mm7, %%mm7 \n\t" #define YSCALEYUV2RGB1b(index, c) REAL_YSCALEYUV2RGB1b(index, c) #define REAL_WRITEBGR32(dst, dstw, index) \ - /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\ - "movq %%mm2, %%mm1 \n\t" /* B */\ - "movq %%mm5, %%mm6 \n\t" /* R */\ - "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\ - "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\ - "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\ - "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\ - "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\ - "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\ - "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\ - "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\ - "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\ - "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\ + /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\ + "movq %%mm2, %%mm1 \n\t" /* B */\ + "movq %%mm5, %%mm6 \n\t" /* R */\ + "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\ + "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\ + "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\ + "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\ + "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\ + "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\ + "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\ + "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\ + "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\ + "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\ \ - MOVNTQ(%%mm0, (dst, index, 4))\ - MOVNTQ(%%mm2, 8(dst, index, 4))\ - MOVNTQ(%%mm1, 16(dst, index, 4))\ - MOVNTQ(%%mm3, 24(dst, index, 4))\ + MOVNTQ(%%mm0, (dst, index, 4))\ + MOVNTQ(%%mm2, 8(dst, index, 4))\ + MOVNTQ(%%mm1, 16(dst, index, 4))\ + MOVNTQ(%%mm3, 24(dst, index, 4))\ \ - "add $8, "#index" \n\t"\ - "cmp "#dstw", "#index" \n\t"\ - " jb 1b \n\t" + "add $8, "#index" \n\t"\ + "cmp "#dstw", "#index" \n\t"\ + " jb 1b \n\t" #define WRITEBGR32(dst, dstw, index) REAL_WRITEBGR32(dst, dstw, index) #define REAL_WRITEBGR16(dst, dstw, index) \ - "pand "MANGLE(bF8)", %%mm2 \n\t" /* B */\ - "pand "MANGLE(bFC)", %%mm4 \n\t" /* G */\ - "pand "MANGLE(bF8)", %%mm5 \n\t" /* R */\ - "psrlq $3, %%mm2 \n\t"\ + "pand "MANGLE(bF8)", %%mm2 \n\t" /* B */\ + "pand "MANGLE(bFC)", %%mm4 \n\t" /* G */\ + "pand "MANGLE(bF8)", %%mm5 \n\t" /* R */\ + "psrlq $3, %%mm2 \n\t"\ \ - "movq %%mm2, %%mm1 \n\t"\ - "movq %%mm4, %%mm3 \n\t"\ + "movq %%mm2, %%mm1 \n\t"\ + "movq %%mm4, %%mm3 \n\t"\ \ - "punpcklbw %%mm7, %%mm3 \n\t"\ - "punpcklbw %%mm5, %%mm2 \n\t"\ - "punpckhbw %%mm7, %%mm4 \n\t"\ - "punpckhbw %%mm5, %%mm1 \n\t"\ + "punpcklbw %%mm7, %%mm3 \n\t"\ + "punpcklbw %%mm5, %%mm2 \n\t"\ + "punpckhbw %%mm7, %%mm4 \n\t"\ + "punpckhbw %%mm5, %%mm1 \n\t"\ \ - "psllq $3, %%mm3 \n\t"\ - "psllq $3, %%mm4 \n\t"\ + "psllq $3, %%mm3 \n\t"\ + "psllq $3, %%mm4 \n\t"\ \ - "por %%mm3, %%mm2 \n\t"\ - "por %%mm4, %%mm1 \n\t"\ + "por %%mm3, %%mm2 \n\t"\ + "por %%mm4, %%mm1 \n\t"\ \ - MOVNTQ(%%mm2, (dst, index, 2))\ - MOVNTQ(%%mm1, 8(dst, index, 2))\ + MOVNTQ(%%mm2, (dst, index, 2))\ + MOVNTQ(%%mm1, 8(dst, index, 2))\ \ - "add $8, "#index" \n\t"\ - "cmp "#dstw", "#index" \n\t"\ - " jb 1b \n\t" + "add $8, "#index" \n\t"\ + "cmp "#dstw", "#index" \n\t"\ + " jb 1b \n\t" #define WRITEBGR16(dst, dstw, index) REAL_WRITEBGR16(dst, dstw, index) #define REAL_WRITEBGR15(dst, dstw, index) \ - "pand "MANGLE(bF8)", %%mm2 \n\t" /* B */\ - "pand "MANGLE(bF8)", %%mm4 \n\t" /* G */\ - "pand "MANGLE(bF8)", %%mm5 \n\t" /* R */\ - "psrlq $3, %%mm2 \n\t"\ - "psrlq $1, %%mm5 \n\t"\ + "pand "MANGLE(bF8)", %%mm2 \n\t" /* B */\ + "pand "MANGLE(bF8)", %%mm4 \n\t" /* G */\ + "pand "MANGLE(bF8)", %%mm5 \n\t" /* R */\ + "psrlq $3, %%mm2 \n\t"\ + "psrlq $1, %%mm5 \n\t"\ \ - "movq %%mm2, %%mm1 \n\t"\ - "movq %%mm4, %%mm3 \n\t"\ + "movq %%mm2, %%mm1 \n\t"\ + "movq %%mm4, %%mm3 \n\t"\ \ - "punpcklbw %%mm7, %%mm3 \n\t"\ - "punpcklbw %%mm5, %%mm2 \n\t"\ - "punpckhbw %%mm7, %%mm4 \n\t"\ - "punpckhbw %%mm5, %%mm1 \n\t"\ + "punpcklbw %%mm7, %%mm3 \n\t"\ + "punpcklbw %%mm5, %%mm2 \n\t"\ + "punpckhbw %%mm7, %%mm4 \n\t"\ + "punpckhbw %%mm5, %%mm1 \n\t"\ \ - "psllq $2, %%mm3 \n\t"\ - "psllq $2, %%mm4 \n\t"\ + "psllq $2, %%mm3 \n\t"\ + "psllq $2, %%mm4 \n\t"\ \ - "por %%mm3, %%mm2 \n\t"\ - "por %%mm4, %%mm1 \n\t"\ + "por %%mm3, %%mm2 \n\t"\ + "por %%mm4, %%mm1 \n\t"\ \ - MOVNTQ(%%mm2, (dst, index, 2))\ - MOVNTQ(%%mm1, 8(dst, index, 2))\ + MOVNTQ(%%mm2, (dst, index, 2))\ + MOVNTQ(%%mm1, 8(dst, index, 2))\ \ - "add $8, "#index" \n\t"\ - "cmp "#dstw", "#index" \n\t"\ - " jb 1b \n\t" + "add $8, "#index" \n\t"\ + "cmp "#dstw", "#index" \n\t"\ + " jb 1b \n\t" #define WRITEBGR15(dst, dstw, index) REAL_WRITEBGR15(dst, dstw, index) #define WRITEBGR24OLD(dst, dstw, index) \ - /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\ - "movq %%mm2, %%mm1 \n\t" /* B */\ - "movq %%mm5, %%mm6 \n\t" /* R */\ - "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\ - "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\ - "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\ - "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\ - "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\ - "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\ - "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\ - "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\ - "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\ - "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\ + /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\ + "movq %%mm2, %%mm1 \n\t" /* B */\ + "movq %%mm5, %%mm6 \n\t" /* R */\ + "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\ + "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\ + "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\ + "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\ + "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\ + "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\ + "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\ + "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\ + "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\ + "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\ \ - "movq %%mm0, %%mm4 \n\t" /* 0RGB0RGB 0 */\ - "psrlq $8, %%mm0 \n\t" /* 00RGB0RG 0 */\ - "pand "MANGLE(bm00000111)", %%mm4\n\t" /* 00000RGB 0 */\ - "pand "MANGLE(bm11111000)", %%mm0\n\t" /* 00RGB000 0.5 */\ - "por %%mm4, %%mm0 \n\t" /* 00RGBRGB 0 */\ - "movq %%mm2, %%mm4 \n\t" /* 0RGB0RGB 1 */\ - "psllq $48, %%mm2 \n\t" /* GB000000 1 */\ - "por %%mm2, %%mm0 \n\t" /* GBRGBRGB 0 */\ + "movq %%mm0, %%mm4 \n\t" /* 0RGB0RGB 0 */\ + "psrlq $8, %%mm0 \n\t" /* 00RGB0RG 0 */\ + "pand "MANGLE(bm00000111)", %%mm4 \n\t" /* 00000RGB 0 */\ + "pand "MANGLE(bm11111000)", %%mm0 \n\t" /* 00RGB000 0.5 */\ + "por %%mm4, %%mm0 \n\t" /* 00RGBRGB 0 */\ + "movq %%mm2, %%mm4 \n\t" /* 0RGB0RGB 1 */\ + "psllq $48, %%mm2 \n\t" /* GB000000 1 */\ + "por %%mm2, %%mm0 \n\t" /* GBRGBRGB 0 */\ \ - "movq %%mm4, %%mm2 \n\t" /* 0RGB0RGB 1 */\ - "psrld $16, %%mm4 \n\t" /* 000R000R 1 */\ - "psrlq $24, %%mm2 \n\t" /* 0000RGB0 1.5 */\ - "por %%mm4, %%mm2 \n\t" /* 000RRGBR 1 */\ - "pand "MANGLE(bm00001111)", %%mm2\n\t" /* 0000RGBR 1 */\ - "movq %%mm1, %%mm4 \n\t" /* 0RGB0RGB 2 */\ - "psrlq $8, %%mm1 \n\t" /* 00RGB0RG 2 */\ - "pand "MANGLE(bm00000111)", %%mm4\n\t" /* 00000RGB 2 */\ - "pand "MANGLE(bm11111000)", %%mm1\n\t" /* 00RGB000 2.5 */\ - "por %%mm4, %%mm1 \n\t" /* 00RGBRGB 2 */\ - "movq %%mm1, %%mm4 \n\t" /* 00RGBRGB 2 */\ - "psllq $32, %%mm1 \n\t" /* BRGB0000 2 */\ - "por %%mm1, %%mm2 \n\t" /* BRGBRGBR 1 */\ + "movq %%mm4, %%mm2 \n\t" /* 0RGB0RGB 1 */\ + "psrld $16, %%mm4 \n\t" /* 000R000R 1 */\ + "psrlq $24, %%mm2 \n\t" /* 0000RGB0 1.5 */\ + "por %%mm4, %%mm2 \n\t" /* 000RRGBR 1 */\ + "pand "MANGLE(bm00001111)", %%mm2 \n\t" /* 0000RGBR 1 */\ + "movq %%mm1, %%mm4 \n\t" /* 0RGB0RGB 2 */\ + "psrlq $8, %%mm1 \n\t" /* 00RGB0RG 2 */\ + "pand "MANGLE(bm00000111)", %%mm4 \n\t" /* 00000RGB 2 */\ + "pand "MANGLE(bm11111000)", %%mm1 \n\t" /* 00RGB000 2.5 */\ + "por %%mm4, %%mm1 \n\t" /* 00RGBRGB 2 */\ + "movq %%mm1, %%mm4 \n\t" /* 00RGBRGB 2 */\ + "psllq $32, %%mm1 \n\t" /* BRGB0000 2 */\ + "por %%mm1, %%mm2 \n\t" /* BRGBRGBR 1 */\ \ - "psrlq $32, %%mm4 \n\t" /* 000000RG 2.5 */\ - "movq %%mm3, %%mm5 \n\t" /* 0RGB0RGB 3 */\ - "psrlq $8, %%mm3 \n\t" /* 00RGB0RG 3 */\ - "pand "MANGLE(bm00000111)", %%mm5\n\t" /* 00000RGB 3 */\ - "pand "MANGLE(bm11111000)", %%mm3\n\t" /* 00RGB000 3.5 */\ - "por %%mm5, %%mm3 \n\t" /* 00RGBRGB 3 */\ - "psllq $16, %%mm3 \n\t" /* RGBRGB00 3 */\ - "por %%mm4, %%mm3 \n\t" /* RGBRGBRG 2.5 */\ + "psrlq $32, %%mm4 \n\t" /* 000000RG 2.5 */\ + "movq %%mm3, %%mm5 \n\t" /* 0RGB0RGB 3 */\ + "psrlq $8, %%mm3 \n\t" /* 00RGB0RG 3 */\ + "pand "MANGLE(bm00000111)", %%mm5 \n\t" /* 00000RGB 3 */\ + "pand "MANGLE(bm11111000)", %%mm3 \n\t" /* 00RGB000 3.5 */\ + "por %%mm5, %%mm3 \n\t" /* 00RGBRGB 3 */\ + "psllq $16, %%mm3 \n\t" /* RGBRGB00 3 */\ + "por %%mm4, %%mm3 \n\t" /* RGBRGBRG 2.5 */\ \ - MOVNTQ(%%mm0, (dst))\ - MOVNTQ(%%mm2, 8(dst))\ - MOVNTQ(%%mm3, 16(dst))\ - "add $24, "#dst" \n\t"\ + MOVNTQ(%%mm0, (dst))\ + MOVNTQ(%%mm2, 8(dst))\ + MOVNTQ(%%mm3, 16(dst))\ + "add $24, "#dst" \n\t"\ \ - "add $8, "#index" \n\t"\ - "cmp "#dstw", "#index" \n\t"\ - " jb 1b \n\t" + "add $8, "#index" \n\t"\ + "cmp "#dstw", "#index" \n\t"\ + " jb 1b \n\t" #define WRITEBGR24MMX(dst, dstw, index) \ - /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\ - "movq %%mm2, %%mm1 \n\t" /* B */\ - "movq %%mm5, %%mm6 \n\t" /* R */\ - "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\ - "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\ - "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\ - "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\ - "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\ - "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\ - "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\ - "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\ - "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\ - "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\ + /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\ + "movq %%mm2, %%mm1 \n\t" /* B */\ + "movq %%mm5, %%mm6 \n\t" /* R */\ + "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\ + "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\ + "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\ + "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\ + "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\ + "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\ + "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\ + "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\ + "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\ + "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\ \ - "movq %%mm0, %%mm4 \n\t" /* 0RGB0RGB 0 */\ - "movq %%mm2, %%mm6 \n\t" /* 0RGB0RGB 1 */\ - "movq %%mm1, %%mm5 \n\t" /* 0RGB0RGB 2 */\ - "movq %%mm3, %%mm7 \n\t" /* 0RGB0RGB 3 */\ + "movq %%mm0, %%mm4 \n\t" /* 0RGB0RGB 0 */\ + "movq %%mm2, %%mm6 \n\t" /* 0RGB0RGB 1 */\ + "movq %%mm1, %%mm5 \n\t" /* 0RGB0RGB 2 */\ + "movq %%mm3, %%mm7 \n\t" /* 0RGB0RGB 3 */\ \ - "psllq $40, %%mm0 \n\t" /* RGB00000 0 */\ - "psllq $40, %%mm2 \n\t" /* RGB00000 1 */\ - "psllq $40, %%mm1 \n\t" /* RGB00000 2 */\ - "psllq $40, %%mm3 \n\t" /* RGB00000 3 */\ + "psllq $40, %%mm0 \n\t" /* RGB00000 0 */\ + "psllq $40, %%mm2 \n\t" /* RGB00000 1 */\ + "psllq $40, %%mm1 \n\t" /* RGB00000 2 */\ + "psllq $40, %%mm3 \n\t" /* RGB00000 3 */\ \ - "punpckhdq %%mm4, %%mm0 \n\t" /* 0RGBRGB0 0 */\ - "punpckhdq %%mm6, %%mm2 \n\t" /* 0RGBRGB0 1 */\ - "punpckhdq %%mm5, %%mm1 \n\t" /* 0RGBRGB0 2 */\ - "punpckhdq %%mm7, %%mm3 \n\t" /* 0RGBRGB0 3 */\ + "punpckhdq %%mm4, %%mm0 \n\t" /* 0RGBRGB0 0 */\ + "punpckhdq %%mm6, %%mm2 \n\t" /* 0RGBRGB0 1 */\ + "punpckhdq %%mm5, %%mm1 \n\t" /* 0RGBRGB0 2 */\ + "punpckhdq %%mm7, %%mm3 \n\t" /* 0RGBRGB0 3 */\ \ - "psrlq $8, %%mm0 \n\t" /* 00RGBRGB 0 */\ - "movq %%mm2, %%mm6 \n\t" /* 0RGBRGB0 1 */\ - "psllq $40, %%mm2 \n\t" /* GB000000 1 */\ - "por %%mm2, %%mm0 \n\t" /* GBRGBRGB 0 */\ - MOVNTQ(%%mm0, (dst))\ + "psrlq $8, %%mm0 \n\t" /* 00RGBRGB 0 */\ + "movq %%mm2, %%mm6 \n\t" /* 0RGBRGB0 1 */\ + "psllq $40, %%mm2 \n\t" /* GB000000 1 */\ + "por %%mm2, %%mm0 \n\t" /* GBRGBRGB 0 */\ + MOVNTQ(%%mm0, (dst))\ \ - "psrlq $24, %%mm6 \n\t" /* 0000RGBR 1 */\ - "movq %%mm1, %%mm5 \n\t" /* 0RGBRGB0 2 */\ - "psllq $24, %%mm1 \n\t" /* BRGB0000 2 */\ - "por %%mm1, %%mm6 \n\t" /* BRGBRGBR 1 */\ - MOVNTQ(%%mm6, 8(dst))\ + "psrlq $24, %%mm6 \n\t" /* 0000RGBR 1 */\ + "movq %%mm1, %%mm5 \n\t" /* 0RGBRGB0 2 */\ + "psllq $24, %%mm1 \n\t" /* BRGB0000 2 */\ + "por %%mm1, %%mm6 \n\t" /* BRGBRGBR 1 */\ + MOVNTQ(%%mm6, 8(dst))\ \ - "psrlq $40, %%mm5 \n\t" /* 000000RG 2 */\ - "psllq $8, %%mm3 \n\t" /* RGBRGB00 3 */\ - "por %%mm3, %%mm5 \n\t" /* RGBRGBRG 2 */\ - MOVNTQ(%%mm5, 16(dst))\ + "psrlq $40, %%mm5 \n\t" /* 000000RG 2 */\ + "psllq $8, %%mm3 \n\t" /* RGBRGB00 3 */\ + "por %%mm3, %%mm5 \n\t" /* RGBRGBRG 2 */\ + MOVNTQ(%%mm5, 16(dst))\ \ - "add $24, "#dst" \n\t"\ + "add $24, "#dst" \n\t"\ \ - "add $8, "#index" \n\t"\ - "cmp "#dstw", "#index" \n\t"\ - " jb 1b \n\t" + "add $8, "#index" \n\t"\ + "cmp "#dstw", "#index" \n\t"\ + " jb 1b \n\t" #define WRITEBGR24MMX2(dst, dstw, index) \ - /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\ - "movq "MANGLE(M24A)", %%mm0 \n\t"\ - "movq "MANGLE(M24C)", %%mm7 \n\t"\ - "pshufw $0x50, %%mm2, %%mm1 \n\t" /* B3 B2 B3 B2 B1 B0 B1 B0 */\ - "pshufw $0x50, %%mm4, %%mm3 \n\t" /* G3 G2 G3 G2 G1 G0 G1 G0 */\ - "pshufw $0x00, %%mm5, %%mm6 \n\t" /* R1 R0 R1 R0 R1 R0 R1 R0 */\ + /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\ + "movq "MANGLE(ff_M24A)", %%mm0 \n\t"\ + "movq "MANGLE(ff_M24C)", %%mm7 \n\t"\ + "pshufw $0x50, %%mm2, %%mm1 \n\t" /* B3 B2 B3 B2 B1 B0 B1 B0 */\ + "pshufw $0x50, %%mm4, %%mm3 \n\t" /* G3 G2 G3 G2 G1 G0 G1 G0 */\ + "pshufw $0x00, %%mm5, %%mm6 \n\t" /* R1 R0 R1 R0 R1 R0 R1 R0 */\ \ - "pand %%mm0, %%mm1 \n\t" /* B2 B1 B0 */\ - "pand %%mm0, %%mm3 \n\t" /* G2 G1 G0 */\ - "pand %%mm7, %%mm6 \n\t" /* R1 R0 */\ + "pand %%mm0, %%mm1 \n\t" /* B2 B1 B0 */\ + "pand %%mm0, %%mm3 \n\t" /* G2 G1 G0 */\ + "pand %%mm7, %%mm6 \n\t" /* R1 R0 */\ \ - "psllq $8, %%mm3 \n\t" /* G2 G1 G0 */\ - "por %%mm1, %%mm6 \n\t"\ - "por %%mm3, %%mm6 \n\t"\ - MOVNTQ(%%mm6, (dst))\ + "psllq $8, %%mm3 \n\t" /* G2 G1 G0 */\ + "por %%mm1, %%mm6 \n\t"\ + "por %%mm3, %%mm6 \n\t"\ + MOVNTQ(%%mm6, (dst))\ \ - "psrlq $8, %%mm4 \n\t" /* 00 G7 G6 G5 G4 G3 G2 G1 */\ - "pshufw $0xA5, %%mm2, %%mm1 \n\t" /* B5 B4 B5 B4 B3 B2 B3 B2 */\ - "pshufw $0x55, %%mm4, %%mm3 \n\t" /* G4 G3 G4 G3 G4 G3 G4 G3 */\ - "pshufw $0xA5, %%mm5, %%mm6 \n\t" /* R5 R4 R5 R4 R3 R2 R3 R2 */\ + "psrlq $8, %%mm4 \n\t" /* 00 G7 G6 G5 G4 G3 G2 G1 */\ + "pshufw $0xA5, %%mm2, %%mm1 \n\t" /* B5 B4 B5 B4 B3 B2 B3 B2 */\ + "pshufw $0x55, %%mm4, %%mm3 \n\t" /* G4 G3 G4 G3 G4 G3 G4 G3 */\ + "pshufw $0xA5, %%mm5, %%mm6 \n\t" /* R5 R4 R5 R4 R3 R2 R3 R2 */\ \ - "pand "MANGLE(M24B)", %%mm1 \n\t" /* B5 B4 B3 */\ - "pand %%mm7, %%mm3 \n\t" /* G4 G3 */\ - "pand %%mm0, %%mm6 \n\t" /* R4 R3 R2 */\ + "pand "MANGLE(ff_M24B)", %%mm1 \n\t" /* B5 B4 B3 */\ + "pand %%mm7, %%mm3 \n\t" /* G4 G3 */\ + "pand %%mm0, %%mm6 \n\t" /* R4 R3 R2 */\ \ - "por %%mm1, %%mm3 \n\t" /* B5 G4 B4 G3 B3 */\ - "por %%mm3, %%mm6 \n\t"\ - MOVNTQ(%%mm6, 8(dst))\ + "por %%mm1, %%mm3 \n\t" /* B5 G4 B4 G3 B3 */\ + "por %%mm3, %%mm6 \n\t"\ + MOVNTQ(%%mm6, 8(dst))\ \ - "pshufw $0xFF, %%mm2, %%mm1 \n\t" /* B7 B6 B7 B6 B7 B6 B6 B7 */\ - "pshufw $0xFA, %%mm4, %%mm3 \n\t" /* 00 G7 00 G7 G6 G5 G6 G5 */\ - "pshufw $0xFA, %%mm5, %%mm6 \n\t" /* R7 R6 R7 R6 R5 R4 R5 R4 */\ + "pshufw $0xFF, %%mm2, %%mm1 \n\t" /* B7 B6 B7 B6 B7 B6 B6 B7 */\ + "pshufw $0xFA, %%mm4, %%mm3 \n\t" /* 00 G7 00 G7 G6 G5 G6 G5 */\ + "pshufw $0xFA, %%mm5, %%mm6 \n\t" /* R7 R6 R7 R6 R5 R4 R5 R4 */\ \ - "pand %%mm7, %%mm1 \n\t" /* B7 B6 */\ - "pand %%mm0, %%mm3 \n\t" /* G7 G6 G5 */\ - "pand "MANGLE(M24B)", %%mm6 \n\t" /* R7 R6 R5 */\ + "pand %%mm7, %%mm1 \n\t" /* B7 B6 */\ + "pand %%mm0, %%mm3 \n\t" /* G7 G6 G5 */\ + "pand "MANGLE(ff_M24B)", %%mm6 \n\t" /* R7 R6 R5 */\ \ - "por %%mm1, %%mm3 \n\t"\ - "por %%mm3, %%mm6 \n\t"\ - MOVNTQ(%%mm6, 16(dst))\ + "por %%mm1, %%mm3 \n\t"\ + "por %%mm3, %%mm6 \n\t"\ + MOVNTQ(%%mm6, 16(dst))\ \ - "add $24, "#dst" \n\t"\ + "add $24, "#dst" \n\t"\ \ - "add $8, "#index" \n\t"\ - "cmp "#dstw", "#index" \n\t"\ - " jb 1b \n\t" + "add $8, "#index" \n\t"\ + "cmp "#dstw", "#index" \n\t"\ + " jb 1b \n\t" #ifdef HAVE_MMX2 #undef WRITEBGR24 @@ -910,122 +910,122 @@ #endif #define REAL_WRITEYUY2(dst, dstw, index) \ - "packuswb %%mm3, %%mm3 \n\t"\ - "packuswb %%mm4, %%mm4 \n\t"\ - "packuswb %%mm7, %%mm1 \n\t"\ - "punpcklbw %%mm4, %%mm3 \n\t"\ - "movq %%mm1, %%mm7 \n\t"\ - "punpcklbw %%mm3, %%mm1 \n\t"\ - "punpckhbw %%mm3, %%mm7 \n\t"\ + "packuswb %%mm3, %%mm3 \n\t"\ + "packuswb %%mm4, %%mm4 \n\t"\ + "packuswb %%mm7, %%mm1 \n\t"\ + "punpcklbw %%mm4, %%mm3 \n\t"\ + "movq %%mm1, %%mm7 \n\t"\ + "punpcklbw %%mm3, %%mm1 \n\t"\ + "punpckhbw %%mm3, %%mm7 \n\t"\ \ - MOVNTQ(%%mm1, (dst, index, 2))\ - MOVNTQ(%%mm7, 8(dst, index, 2))\ + MOVNTQ(%%mm1, (dst, index, 2))\ + MOVNTQ(%%mm7, 8(dst, index, 2))\ \ - "add $8, "#index" \n\t"\ - "cmp "#dstw", "#index" \n\t"\ - " jb 1b \n\t" + "add $8, "#index" \n\t"\ + "cmp "#dstw", "#index" \n\t"\ + " jb 1b \n\t" #define WRITEYUY2(dst, dstw, index) REAL_WRITEYUY2(dst, dstw, index) static inline void RENAME(yuv2yuvX)(SwsContext *c, int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize, - int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, - uint8_t *dest, uint8_t *uDest, uint8_t *vDest, long dstW, long chrDstW) + int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, + uint8_t *dest, uint8_t *uDest, uint8_t *vDest, long dstW, long chrDstW) { #ifdef HAVE_MMX - if(c->flags & SWS_ACCURATE_RND){ - if(uDest){ - YSCALEYUV2YV12X_ACCURATE( 0, CHR_MMX_FILTER_OFFSET, uDest, chrDstW) - YSCALEYUV2YV12X_ACCURATE(4096, CHR_MMX_FILTER_OFFSET, vDest, chrDstW) - } - - YSCALEYUV2YV12X_ACCURATE(0, LUM_MMX_FILTER_OFFSET, dest, dstW) - }else{ - if(uDest){ - YSCALEYUV2YV12X( 0, CHR_MMX_FILTER_OFFSET, uDest, chrDstW) - YSCALEYUV2YV12X(4096, CHR_MMX_FILTER_OFFSET, vDest, chrDstW) - } + if (c->flags & SWS_ACCURATE_RND){ + if (uDest){ + YSCALEYUV2YV12X_ACCURATE( 0, CHR_MMX_FILTER_OFFSET, uDest, chrDstW) + YSCALEYUV2YV12X_ACCURATE(4096, CHR_MMX_FILTER_OFFSET, vDest, chrDstW) + } - YSCALEYUV2YV12X(0, LUM_MMX_FILTER_OFFSET, dest, dstW) + YSCALEYUV2YV12X_ACCURATE(0, LUM_MMX_FILTER_OFFSET, dest, dstW) + }else{ + if (uDest){ + YSCALEYUV2YV12X( 0, CHR_MMX_FILTER_OFFSET, uDest, chrDstW) + YSCALEYUV2YV12X(4096, CHR_MMX_FILTER_OFFSET, vDest, chrDstW) } + + YSCALEYUV2YV12X(0, LUM_MMX_FILTER_OFFSET, dest, dstW) + } #else #ifdef HAVE_ALTIVEC yuv2yuvX_altivec_real(lumFilter, lumSrc, lumFilterSize, - chrFilter, chrSrc, chrFilterSize, - dest, uDest, vDest, dstW, chrDstW); + chrFilter, chrSrc, chrFilterSize, + dest, uDest, vDest, dstW, chrDstW); #else //HAVE_ALTIVEC yuv2yuvXinC(lumFilter, lumSrc, lumFilterSize, - chrFilter, chrSrc, chrFilterSize, - dest, uDest, vDest, dstW, chrDstW); + chrFilter, chrSrc, chrFilterSize, + dest, uDest, vDest, dstW, chrDstW); #endif //!HAVE_ALTIVEC -#endif +#endif /* HAVE_MMX */ } static inline void RENAME(yuv2nv12X)(SwsContext *c, int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize, - int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, - uint8_t *dest, uint8_t *uDest, int dstW, int chrDstW, int dstFormat) + int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, + uint8_t *dest, uint8_t *uDest, int dstW, int chrDstW, int dstFormat) { yuv2nv12XinC(lumFilter, lumSrc, lumFilterSize, - chrFilter, chrSrc, chrFilterSize, - dest, uDest, dstW, chrDstW, dstFormat); + chrFilter, chrSrc, chrFilterSize, + dest, uDest, dstW, chrDstW, dstFormat); } static inline void RENAME(yuv2yuv1)(int16_t *lumSrc, int16_t *chrSrc, - uint8_t *dest, uint8_t *uDest, uint8_t *vDest, long dstW, long chrDstW) + uint8_t *dest, uint8_t *uDest, uint8_t *vDest, long dstW, long chrDstW) { #ifdef HAVE_MMX - if(uDest != NULL) - { - asm volatile( - YSCALEYUV2YV121 - :: "r" (chrSrc + chrDstW), "r" (uDest + chrDstW), - "g" (-chrDstW) - : "%"REG_a - ); - - asm volatile( - YSCALEYUV2YV121 - :: "r" (chrSrc + 2048 + chrDstW), "r" (vDest + chrDstW), - "g" (-chrDstW) - : "%"REG_a - ); - } - - asm volatile( - YSCALEYUV2YV121 - :: "r" (lumSrc + dstW), "r" (dest + dstW), - "g" (-dstW) - : "%"REG_a - ); + if (uDest) + { + asm volatile( + YSCALEYUV2YV121 + :: "r" (chrSrc + chrDstW), "r" (uDest + chrDstW), + "g" (-chrDstW) + : "%"REG_a + ); + + asm volatile( + YSCALEYUV2YV121 + :: "r" (chrSrc + 2048 + chrDstW), "r" (vDest + chrDstW), + "g" (-chrDstW) + : "%"REG_a + ); + } + + asm volatile( + YSCALEYUV2YV121 + :: "r" (lumSrc + dstW), "r" (dest + dstW), + "g" (-dstW) + : "%"REG_a + ); #else - int i; - for(i=0; i>7; - - if(val&256){ - if(val<0) val=0; - else val=255; - } - - dest[i]= val; - } - - if(uDest != NULL) - for(i=0; i>7; - int v=chrSrc[i + 2048]>>7; - - if((u|v)&256){ - if(u<0) u=0; - else if (u>255) u=255; - if(v<0) v=0; - else if (v>255) v=255; - } - - uDest[i]= u; - vDest[i]= v; - } + int i; + for (i=0; i>7; + + if (val&256){ + if (val<0) val=0; + else val=255; + } + + dest[i]= val; + } + + if (uDest) + for (i=0; i>7; + int v=chrSrc[i + 2048]>>7; + + if ((u|v)&256){ + if (u<0) u=0; + else if (u>255) u=255; + if (v<0) v=0; + else if (v>255) v=255; + } + + uDest[i]= u; + vDest[i]= v; + } #endif } @@ -1034,463 +1034,462 @@ static inline void RENAME(yuv2yuv1)(int16_t *lumSrc, int16_t *chrSrc, * vertical scale YV12 to RGB */ static inline void RENAME(yuv2packedX)(SwsContext *c, int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize, - int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, - uint8_t *dest, long dstW, long dstY) + int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, + uint8_t *dest, long dstW, long dstY) { #ifdef HAVE_MMX long dummy=0; - if(c->flags & SWS_ACCURATE_RND){ - switch(c->dstFormat){ - case PIX_FMT_RGB32: - YSCALEYUV2PACKEDX_ACCURATE - YSCALEYUV2RGBX - WRITEBGR32(%4, %5, %%REGa) - - YSCALEYUV2PACKEDX_END - return; - case PIX_FMT_BGR24: - YSCALEYUV2PACKEDX_ACCURATE - YSCALEYUV2RGBX - "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c"\n\t" //FIXME optimize - "add %4, %%"REG_c" \n\t" - WRITEBGR24(%%REGc, %5, %%REGa) - - - :: "r" (&c->redDither), - "m" (dummy), "m" (dummy), "m" (dummy), - "r" (dest), "m" (dstW) - : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S - ); - return; - case PIX_FMT_BGR555: - YSCALEYUV2PACKEDX_ACCURATE - YSCALEYUV2RGBX - /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ + if (c->flags & SWS_ACCURATE_RND){ + switch(c->dstFormat){ + case PIX_FMT_RGB32: + YSCALEYUV2PACKEDX_ACCURATE + YSCALEYUV2RGBX + WRITEBGR32(%4, %5, %%REGa) + + YSCALEYUV2PACKEDX_END + return; + case PIX_FMT_BGR24: + YSCALEYUV2PACKEDX_ACCURATE + YSCALEYUV2RGBX + "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c"\n\t" //FIXME optimize + "add %4, %%"REG_c" \n\t" + WRITEBGR24(%%REGc, %5, %%REGa) + + + :: "r" (&c->redDither), + "m" (dummy), "m" (dummy), "m" (dummy), + "r" (dest), "m" (dstW) + : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S + ); + return; + case PIX_FMT_BGR555: + YSCALEYUV2PACKEDX_ACCURATE + YSCALEYUV2RGBX + /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP - "paddusb "MANGLE(b5Dither)", %%mm2\n\t" - "paddusb "MANGLE(g5Dither)", %%mm4\n\t" - "paddusb "MANGLE(r5Dither)", %%mm5\n\t" -#endif - - WRITEBGR15(%4, %5, %%REGa) - YSCALEYUV2PACKEDX_END - return; - case PIX_FMT_BGR565: - YSCALEYUV2PACKEDX_ACCURATE - YSCALEYUV2RGBX - /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ + "paddusb "MANGLE(b5Dither)", %%mm2\n\t" + "paddusb "MANGLE(g5Dither)", %%mm4\n\t" + "paddusb "MANGLE(r5Dither)", %%mm5\n\t" +#endif + + WRITEBGR15(%4, %5, %%REGa) + YSCALEYUV2PACKEDX_END + return; + case PIX_FMT_BGR565: + YSCALEYUV2PACKEDX_ACCURATE + YSCALEYUV2RGBX + /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP - "paddusb "MANGLE(b5Dither)", %%mm2\n\t" - "paddusb "MANGLE(g6Dither)", %%mm4\n\t" - "paddusb "MANGLE(r5Dither)", %%mm5\n\t" -#endif - - WRITEBGR16(%4, %5, %%REGa) - YSCALEYUV2PACKEDX_END - return; - case PIX_FMT_YUYV422: - YSCALEYUV2PACKEDX_ACCURATE - /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ - - "psraw $3, %%mm3 \n\t" - "psraw $3, %%mm4 \n\t" - "psraw $3, %%mm1 \n\t" - "psraw $3, %%mm7 \n\t" - WRITEYUY2(%4, %5, %%REGa) - YSCALEYUV2PACKEDX_END - return; - } + "paddusb "MANGLE(b5Dither)", %%mm2\n\t" + "paddusb "MANGLE(g6Dither)", %%mm4\n\t" + "paddusb "MANGLE(r5Dither)", %%mm5\n\t" +#endif + + WRITEBGR16(%4, %5, %%REGa) + YSCALEYUV2PACKEDX_END + return; + case PIX_FMT_YUYV422: + YSCALEYUV2PACKEDX_ACCURATE + /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ + + "psraw $3, %%mm3 \n\t" + "psraw $3, %%mm4 \n\t" + "psraw $3, %%mm1 \n\t" + "psraw $3, %%mm7 \n\t" + WRITEYUY2(%4, %5, %%REGa) + YSCALEYUV2PACKEDX_END + return; + } }else{ - switch(c->dstFormat) - { - case PIX_FMT_RGB32: - YSCALEYUV2PACKEDX - YSCALEYUV2RGBX - WRITEBGR32(%4, %5, %%REGa) - YSCALEYUV2PACKEDX_END - return; - case PIX_FMT_BGR24: - YSCALEYUV2PACKEDX - YSCALEYUV2RGBX - "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c"\n\t" //FIXME optimize - "add %4, %%"REG_c" \n\t" - WRITEBGR24(%%REGc, %5, %%REGa) - - :: "r" (&c->redDither), - "m" (dummy), "m" (dummy), "m" (dummy), - "r" (dest), "m" (dstW) - : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S - ); - return; - case PIX_FMT_BGR555: - YSCALEYUV2PACKEDX - YSCALEYUV2RGBX - /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ + switch(c->dstFormat) + { + case PIX_FMT_RGB32: + YSCALEYUV2PACKEDX + YSCALEYUV2RGBX + WRITEBGR32(%4, %5, %%REGa) + YSCALEYUV2PACKEDX_END + return; + case PIX_FMT_BGR24: + YSCALEYUV2PACKEDX + YSCALEYUV2RGBX + "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c" \n\t" //FIXME optimize + "add %4, %%"REG_c" \n\t" + WRITEBGR24(%%REGc, %5, %%REGa) + + :: "r" (&c->redDither), + "m" (dummy), "m" (dummy), "m" (dummy), + "r" (dest), "m" (dstW) + : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S + ); + return; + case PIX_FMT_BGR555: + YSCALEYUV2PACKEDX + YSCALEYUV2RGBX + /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP - "paddusb "MANGLE(b5Dither)", %%mm2\n\t" - "paddusb "MANGLE(g5Dither)", %%mm4\n\t" - "paddusb "MANGLE(r5Dither)", %%mm5\n\t" -#endif - - WRITEBGR15(%4, %5, %%REGa) - YSCALEYUV2PACKEDX_END - return; - case PIX_FMT_BGR565: - YSCALEYUV2PACKEDX - YSCALEYUV2RGBX - /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ + "paddusb "MANGLE(b5Dither)", %%mm2 \n\t" + "paddusb "MANGLE(g5Dither)", %%mm4 \n\t" + "paddusb "MANGLE(r5Dither)", %%mm5 \n\t" +#endif + + WRITEBGR15(%4, %5, %%REGa) + YSCALEYUV2PACKEDX_END + return; + case PIX_FMT_BGR565: + YSCALEYUV2PACKEDX + YSCALEYUV2RGBX + /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP - "paddusb "MANGLE(b5Dither)", %%mm2\n\t" - "paddusb "MANGLE(g6Dither)", %%mm4\n\t" - "paddusb "MANGLE(r5Dither)", %%mm5\n\t" -#endif - - WRITEBGR16(%4, %5, %%REGa) - YSCALEYUV2PACKEDX_END - return; - case PIX_FMT_YUYV422: - YSCALEYUV2PACKEDX - /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ - - "psraw $3, %%mm3 \n\t" - "psraw $3, %%mm4 \n\t" - "psraw $3, %%mm1 \n\t" - "psraw $3, %%mm7 \n\t" - WRITEYUY2(%4, %5, %%REGa) - YSCALEYUV2PACKEDX_END - return; + "paddusb "MANGLE(b5Dither)", %%mm2 \n\t" + "paddusb "MANGLE(g6Dither)", %%mm4 \n\t" + "paddusb "MANGLE(r5Dither)", %%mm5 \n\t" +#endif + + WRITEBGR16(%4, %5, %%REGa) + YSCALEYUV2PACKEDX_END + return; + case PIX_FMT_YUYV422: + YSCALEYUV2PACKEDX + /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ + + "psraw $3, %%mm3 \n\t" + "psraw $3, %%mm4 \n\t" + "psraw $3, %%mm1 \n\t" + "psraw $3, %%mm7 \n\t" + WRITEYUY2(%4, %5, %%REGa) + YSCALEYUV2PACKEDX_END + return; } } -#endif +#endif /* HAVE_MMX */ #ifdef HAVE_ALTIVEC - /* The following list of supported dstFormat values should - match what's found in the body of altivec_yuv2packedX() */ - if(c->dstFormat==PIX_FMT_ABGR || c->dstFormat==PIX_FMT_BGRA || - c->dstFormat==PIX_FMT_BGR24 || c->dstFormat==PIX_FMT_RGB24 || - c->dstFormat==PIX_FMT_RGBA || c->dstFormat==PIX_FMT_ARGB) - altivec_yuv2packedX (c, lumFilter, lumSrc, lumFilterSize, - chrFilter, chrSrc, chrFilterSize, - dest, dstW, dstY); - else -#endif - yuv2packedXinC(c, lumFilter, lumSrc, lumFilterSize, - chrFilter, chrSrc, chrFilterSize, - dest, dstW, dstY); + /* The following list of supported dstFormat values should + match what's found in the body of altivec_yuv2packedX() */ + if (c->dstFormat==PIX_FMT_ABGR || c->dstFormat==PIX_FMT_BGRA || + c->dstFormat==PIX_FMT_BGR24 || c->dstFormat==PIX_FMT_RGB24 || + c->dstFormat==PIX_FMT_RGBA || c->dstFormat==PIX_FMT_ARGB) + altivec_yuv2packedX (c, lumFilter, lumSrc, lumFilterSize, + chrFilter, chrSrc, chrFilterSize, + dest, dstW, dstY); + else +#endif + yuv2packedXinC(c, lumFilter, lumSrc, lumFilterSize, + chrFilter, chrSrc, chrFilterSize, + dest, dstW, dstY); } /** * vertical bilinear scale YV12 to RGB */ static inline void RENAME(yuv2packed2)(SwsContext *c, uint16_t *buf0, uint16_t *buf1, uint16_t *uvbuf0, uint16_t *uvbuf1, - uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) + uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) { - int yalpha1=yalpha^4095; - int uvalpha1=uvalpha^4095; - int i; + int yalpha1=yalpha^4095; + int uvalpha1=uvalpha^4095; + int i; #if 0 //isn't used - if(flags&SWS_FULL_CHR_H_INT) - { - switch(dstFormat) - { + if (flags&SWS_FULL_CHR_H_INT) + { + switch(dstFormat) + { #ifdef HAVE_MMX - case PIX_FMT_RGB32: - asm volatile( + case PIX_FMT_RGB32: + asm volatile( FULL_YSCALEYUV2RGB - "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG - "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0 - - "movq %%mm3, %%mm1 \n\t" - "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0 - "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0 + "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG + "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0 - MOVNTQ(%%mm3, (%4, %%REGa, 4)) - MOVNTQ(%%mm1, 8(%4, %%REGa, 4)) + "movq %%mm3, %%mm1 \n\t" + "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0 + "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0 - "add $4, %%"REG_a" \n\t" - "cmp %5, %%"REG_a" \n\t" - " jb 1b \n\t" + MOVNTQ(%%mm3, (%4, %%REGa, 4)) + MOVNTQ(%%mm1, 8(%4, %%REGa, 4)) + "add $4, %%"REG_a" \n\t" + "cmp %5, %%"REG_a" \n\t" + " jb 1b \n\t" - :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" ((long)dstW), - "m" (yalpha1), "m" (uvalpha1) - : "%"REG_a - ); - break; - case PIX_FMT_BGR24: - asm volatile( + :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" ((long)dstW), + "m" (yalpha1), "m" (uvalpha1) + : "%"REG_a + ); + break; + case PIX_FMT_BGR24: + asm volatile( FULL_YSCALEYUV2RGB - // lsb ... msb - "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG - "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0 + // lsb ... msb + "punpcklbw %%mm1, %%mm3 \n\t" // BGBGBGBG + "punpcklbw %%mm7, %%mm0 \n\t" // R0R0R0R0 - "movq %%mm3, %%mm1 \n\t" - "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0 - "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0 + "movq %%mm3, %%mm1 \n\t" + "punpcklwd %%mm0, %%mm3 \n\t" // BGR0BGR0 + "punpckhwd %%mm0, %%mm1 \n\t" // BGR0BGR0 - "movq %%mm3, %%mm2 \n\t" // BGR0BGR0 - "psrlq $8, %%mm3 \n\t" // GR0BGR00 - "pand "MANGLE(bm00000111)", %%mm2\n\t" // BGR00000 - "pand "MANGLE(bm11111000)", %%mm3\n\t" // 000BGR00 - "por %%mm2, %%mm3 \n\t" // BGRBGR00 - "movq %%mm1, %%mm2 \n\t" - "psllq $48, %%mm1 \n\t" // 000000BG - "por %%mm1, %%mm3 \n\t" // BGRBGRBG + "movq %%mm3, %%mm2 \n\t" // BGR0BGR0 + "psrlq $8, %%mm3 \n\t" // GR0BGR00 + "pand "MANGLE(bm00000111)", %%mm2 \n\t" // BGR00000 + "pand "MANGLE(bm11111000)", %%mm3 \n\t" // 000BGR00 + "por %%mm2, %%mm3 \n\t" // BGRBGR00 + "movq %%mm1, %%mm2 \n\t" + "psllq $48, %%mm1 \n\t" // 000000BG + "por %%mm1, %%mm3 \n\t" // BGRBGRBG - "movq %%mm2, %%mm1 \n\t" // BGR0BGR0 - "psrld $16, %%mm2 \n\t" // R000R000 - "psrlq $24, %%mm1 \n\t" // 0BGR0000 - "por %%mm2, %%mm1 \n\t" // RBGRR000 + "movq %%mm2, %%mm1 \n\t" // BGR0BGR0 + "psrld $16, %%mm2 \n\t" // R000R000 + "psrlq $24, %%mm1 \n\t" // 0BGR0000 + "por %%mm2, %%mm1 \n\t" // RBGRR000 - "mov %4, %%"REG_b" \n\t" - "add %%"REG_a", %%"REG_b" \n\t" + "mov %4, %%"REG_b" \n\t" + "add %%"REG_a", %%"REG_b" \n\t" #ifdef HAVE_MMX2 - //FIXME Alignment - "movntq %%mm3, (%%"REG_b", %%"REG_a", 2)\n\t" - "movntq %%mm1, 8(%%"REG_b", %%"REG_a", 2)\n\t" + //FIXME Alignment + "movntq %%mm3, (%%"REG_b", %%"REG_a", 2) \n\t" + "movntq %%mm1, 8(%%"REG_b", %%"REG_a", 2) \n\t" #else - "movd %%mm3, (%%"REG_b", %%"REG_a", 2) \n\t" - "psrlq $32, %%mm3 \n\t" - "movd %%mm3, 4(%%"REG_b", %%"REG_a", 2) \n\t" - "movd %%mm1, 8(%%"REG_b", %%"REG_a", 2) \n\t" -#endif - "add $4, %%"REG_a" \n\t" - "cmp %5, %%"REG_a" \n\t" - " jb 1b \n\t" - - :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstW), - "m" (yalpha1), "m" (uvalpha1) - : "%"REG_a, "%"REG_b - ); - break; - case PIX_FMT_BGR555: - asm volatile( + "movd %%mm3, (%%"REG_b", %%"REG_a", 2) \n\t" + "psrlq $32, %%mm3 \n\t" + "movd %%mm3, 4(%%"REG_b", %%"REG_a", 2) \n\t" + "movd %%mm1, 8(%%"REG_b", %%"REG_a", 2) \n\t" +#endif + "add $4, %%"REG_a" \n\t" + "cmp %5, %%"REG_a" \n\t" + " jb 1b \n\t" + + :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "m" (dest), "m" (dstW), + "m" (yalpha1), "m" (uvalpha1) + : "%"REG_a, "%"REG_b + ); + break; + case PIX_FMT_BGR555: + asm volatile( FULL_YSCALEYUV2RGB #ifdef DITHER1XBPP - "paddusb "MANGLE(g5Dither)", %%mm1\n\t" - "paddusb "MANGLE(r5Dither)", %%mm0\n\t" - "paddusb "MANGLE(b5Dither)", %%mm3\n\t" + "paddusb "MANGLE(g5Dither)", %%mm1 \n\t" + "paddusb "MANGLE(r5Dither)", %%mm0 \n\t" + "paddusb "MANGLE(b5Dither)", %%mm3 \n\t" #endif - "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G - "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B - "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R + "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G + "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B + "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R - "psrlw $3, %%mm3 \n\t" - "psllw $2, %%mm1 \n\t" - "psllw $7, %%mm0 \n\t" - "pand "MANGLE(g15Mask)", %%mm1 \n\t" - "pand "MANGLE(r15Mask)", %%mm0 \n\t" + "psrlw $3, %%mm3 \n\t" + "psllw $2, %%mm1 \n\t" + "psllw $7, %%mm0 \n\t" + "pand "MANGLE(g15Mask)", %%mm1 \n\t" + "pand "MANGLE(r15Mask)", %%mm0 \n\t" - "por %%mm3, %%mm1 \n\t" - "por %%mm1, %%mm0 \n\t" + "por %%mm3, %%mm1 \n\t" + "por %%mm1, %%mm0 \n\t" - MOVNTQ(%%mm0, (%4, %%REGa, 2)) + MOVNTQ(%%mm0, (%4, %%REGa, 2)) - "add $4, %%"REG_a" \n\t" - "cmp %5, %%"REG_a" \n\t" - " jb 1b \n\t" + "add $4, %%"REG_a" \n\t" + "cmp %5, %%"REG_a" \n\t" + " jb 1b \n\t" - :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW), - "m" (yalpha1), "m" (uvalpha1) - : "%"REG_a - ); - break; - case PIX_FMT_BGR565: - asm volatile( + :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW), + "m" (yalpha1), "m" (uvalpha1) + : "%"REG_a + ); + break; + case PIX_FMT_BGR565: + asm volatile( FULL_YSCALEYUV2RGB #ifdef DITHER1XBPP - "paddusb "MANGLE(g6Dither)", %%mm1\n\t" - "paddusb "MANGLE(r5Dither)", %%mm0\n\t" - "paddusb "MANGLE(b5Dither)", %%mm3\n\t" -#endif - "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G - "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B - "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R - - "psrlw $3, %%mm3 \n\t" - "psllw $3, %%mm1 \n\t" - "psllw $8, %%mm0 \n\t" - "pand "MANGLE(g16Mask)", %%mm1 \n\t" - "pand "MANGLE(r16Mask)", %%mm0 \n\t" - - "por %%mm3, %%mm1 \n\t" - "por %%mm1, %%mm0 \n\t" - - MOVNTQ(%%mm0, (%4, %%REGa, 2)) - - "add $4, %%"REG_a" \n\t" - "cmp %5, %%"REG_a" \n\t" - " jb 1b \n\t" - - :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW), - "m" (yalpha1), "m" (uvalpha1) - : "%"REG_a - ); - break; -#endif - case PIX_FMT_BGR32: + "paddusb "MANGLE(g6Dither)", %%mm1 \n\t" + "paddusb "MANGLE(r5Dither)", %%mm0 \n\t" + "paddusb "MANGLE(b5Dither)", %%mm3 \n\t" +#endif + "punpcklbw %%mm7, %%mm1 \n\t" // 0G0G0G0G + "punpcklbw %%mm7, %%mm3 \n\t" // 0B0B0B0B + "punpcklbw %%mm7, %%mm0 \n\t" // 0R0R0R0R + + "psrlw $3, %%mm3 \n\t" + "psllw $3, %%mm1 \n\t" + "psllw $8, %%mm0 \n\t" + "pand "MANGLE(g16Mask)", %%mm1 \n\t" + "pand "MANGLE(r16Mask)", %%mm0 \n\t" + + "por %%mm3, %%mm1 \n\t" + "por %%mm1, %%mm0 \n\t" + + MOVNTQ(%%mm0, (%4, %%REGa, 2)) + + "add $4, %%"REG_a" \n\t" + "cmp %5, %%"REG_a" \n\t" + " jb 1b \n\t" + + :: "r" (buf0), "r" (buf1), "r" (uvbuf0), "r" (uvbuf1), "r" (dest), "m" (dstW), + "m" (yalpha1), "m" (uvalpha1) + : "%"REG_a + ); + break; +#endif /* HAVE_MMX */ + case PIX_FMT_BGR32: #ifndef HAVE_MMX - case PIX_FMT_RGB32: + case PIX_FMT_RGB32: #endif - if(dstFormat==PIX_FMT_RGB32) - { - int i; + if (dstFormat==PIX_FMT_RGB32) + { + int i; #ifdef WORDS_BIGENDIAN - dest++; -#endif - for(i=0;i>19)]; - int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); - int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); - dest[0]=clip_table[((Y + yuvtab_40cf[U]) >>13)]; - dest[1]=clip_table[((Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13)]; - dest[2]=clip_table[((Y + yuvtab_3343[V]) >>13)]; - dest+= 4; - } - } - else if(dstFormat==PIX_FMT_BGR24) - { - int i; - for(i=0;i>19)]; - int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); - int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); - dest[0]=clip_table[((Y + yuvtab_40cf[U]) >>13)]; - dest[1]=clip_table[((Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13)]; - dest[2]=clip_table[((Y + yuvtab_3343[V]) >>13)]; - dest+= 3; - } - } - else if(dstFormat==PIX_FMT_BGR565) - { - int i; - for(i=0;i>19)]; - int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); - int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); - - ((uint16_t*)dest)[i] = - clip_table16b[(Y + yuvtab_40cf[U]) >>13] | - clip_table16g[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13] | - clip_table16r[(Y + yuvtab_3343[V]) >>13]; - } - } - else if(dstFormat==PIX_FMT_BGR555) - { - int i; - for(i=0;i>19)]; - int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); - int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); - - ((uint16_t*)dest)[i] = - clip_table15b[(Y + yuvtab_40cf[U]) >>13] | - clip_table15g[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13] | - clip_table15r[(Y + yuvtab_3343[V]) >>13]; - } - } - }//FULL_UV_IPOL - else - { + dest++; +#endif + for (i=0;i>19)]; + int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); + int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); + dest[0]=clip_table[((Y + yuvtab_40cf[U]) >>13)]; + dest[1]=clip_table[((Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13)]; + dest[2]=clip_table[((Y + yuvtab_3343[V]) >>13)]; + dest+= 4; + } + } + else if (dstFormat==PIX_FMT_BGR24) + { + int i; + for (i=0;i>19)]; + int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); + int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); + dest[0]=clip_table[((Y + yuvtab_40cf[U]) >>13)]; + dest[1]=clip_table[((Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13)]; + dest[2]=clip_table[((Y + yuvtab_3343[V]) >>13)]; + dest+= 3; + } + } + else if (dstFormat==PIX_FMT_BGR565) + { + int i; + for (i=0;i>19)]; + int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); + int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); + + ((uint16_t*)dest)[i] = + clip_table16b[(Y + yuvtab_40cf[U]) >>13] | + clip_table16g[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13] | + clip_table16r[(Y + yuvtab_3343[V]) >>13]; + } + } + else if (dstFormat==PIX_FMT_BGR555) + { + int i; + for (i=0;i>19)]; + int U=((uvbuf0[i]*uvalpha1+uvbuf1[i]*uvalpha)>>19); + int V=((uvbuf0[i+2048]*uvalpha1+uvbuf1[i+2048]*uvalpha)>>19); + + ((uint16_t*)dest)[i] = + clip_table15b[(Y + yuvtab_40cf[U]) >>13] | + clip_table15g[(Y + yuvtab_1a1e[V] + yuvtab_0c92[U]) >>13] | + clip_table15r[(Y + yuvtab_3343[V]) >>13]; + } + } + }//FULL_UV_IPOL + else + { #endif // if 0 #ifdef HAVE_MMX - switch(c->dstFormat) - { -//Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :( - case PIX_FMT_RGB32: - asm volatile( - "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" - "mov %4, %%"REG_b" \n\t" - "push %%"REG_BP" \n\t" - YSCALEYUV2RGB(%%REGBP, %5) - WRITEBGR32(%%REGb, 8280(%5), %%REGBP) - "pop %%"REG_BP" \n\t" - "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" - - :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), - "a" (&c->redDither) - ); - return; - case PIX_FMT_BGR24: - asm volatile( - "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" - "mov %4, %%"REG_b" \n\t" - "push %%"REG_BP" \n\t" - YSCALEYUV2RGB(%%REGBP, %5) - WRITEBGR24(%%REGb, 8280(%5), %%REGBP) - "pop %%"REG_BP" \n\t" - "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" - :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), - "a" (&c->redDither) - ); - return; - case PIX_FMT_BGR555: - asm volatile( - "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" - "mov %4, %%"REG_b" \n\t" - "push %%"REG_BP" \n\t" - YSCALEYUV2RGB(%%REGBP, %5) - /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ + switch(c->dstFormat) + { + //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :( + case PIX_FMT_RGB32: + asm volatile( + "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" + "mov %4, %%"REG_b" \n\t" + "push %%"REG_BP" \n\t" + YSCALEYUV2RGB(%%REGBP, %5) + WRITEBGR32(%%REGb, 8280(%5), %%REGBP) + "pop %%"REG_BP" \n\t" + "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" + + :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), + "a" (&c->redDither) + ); + return; + case PIX_FMT_BGR24: + asm volatile( + "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" + "mov %4, %%"REG_b" \n\t" + "push %%"REG_BP" \n\t" + YSCALEYUV2RGB(%%REGBP, %5) + WRITEBGR24(%%REGb, 8280(%5), %%REGBP) + "pop %%"REG_BP" \n\t" + "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" + :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), + "a" (&c->redDither) + ); + return; + case PIX_FMT_BGR555: + asm volatile( + "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" + "mov %4, %%"REG_b" \n\t" + "push %%"REG_BP" \n\t" + YSCALEYUV2RGB(%%REGBP, %5) + /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP - "paddusb "MANGLE(b5Dither)", %%mm2\n\t" - "paddusb "MANGLE(g5Dither)", %%mm4\n\t" - "paddusb "MANGLE(r5Dither)", %%mm5\n\t" + "paddusb "MANGLE(b5Dither)", %%mm2 \n\t" + "paddusb "MANGLE(g5Dither)", %%mm4 \n\t" + "paddusb "MANGLE(r5Dither)", %%mm5 \n\t" #endif - WRITEBGR15(%%REGb, 8280(%5), %%REGBP) - "pop %%"REG_BP" \n\t" - "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" - - :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), - "a" (&c->redDither) - ); - return; - case PIX_FMT_BGR565: - asm volatile( - "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" - "mov %4, %%"REG_b" \n\t" - "push %%"REG_BP" \n\t" - YSCALEYUV2RGB(%%REGBP, %5) - /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ + WRITEBGR15(%%REGb, 8280(%5), %%REGBP) + "pop %%"REG_BP" \n\t" + "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" + + :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), + "a" (&c->redDither) + ); + return; + case PIX_FMT_BGR565: + asm volatile( + "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" + "mov %4, %%"REG_b" \n\t" + "push %%"REG_BP" \n\t" + YSCALEYUV2RGB(%%REGBP, %5) + /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP - "paddusb "MANGLE(b5Dither)", %%mm2\n\t" - "paddusb "MANGLE(g6Dither)", %%mm4\n\t" - "paddusb "MANGLE(r5Dither)", %%mm5\n\t" + "paddusb "MANGLE(b5Dither)", %%mm2 \n\t" + "paddusb "MANGLE(g6Dither)", %%mm4 \n\t" + "paddusb "MANGLE(r5Dither)", %%mm5 \n\t" #endif - WRITEBGR16(%%REGb, 8280(%5), %%REGBP) - "pop %%"REG_BP" \n\t" - "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" - :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), - "a" (&c->redDither) - ); - return; - case PIX_FMT_YUYV422: - asm volatile( - "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" - "mov %4, %%"REG_b" \n\t" - "push %%"REG_BP" \n\t" - YSCALEYUV2PACKED(%%REGBP, %5) - WRITEYUY2(%%REGb, 8280(%5), %%REGBP) - "pop %%"REG_BP" \n\t" - "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" - :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), - "a" (&c->redDither) - ); - return; - default: break; - } + WRITEBGR16(%%REGb, 8280(%5), %%REGBP) + "pop %%"REG_BP" \n\t" + "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" + :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), + "a" (&c->redDither) + ); + return; + case PIX_FMT_YUYV422: + asm volatile( + "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" + "mov %4, %%"REG_b" \n\t" + "push %%"REG_BP" \n\t" + YSCALEYUV2PACKED(%%REGBP, %5) + WRITEYUY2(%%REGb, 8280(%5), %%REGBP) + "pop %%"REG_BP" \n\t" + "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" + :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), + "a" (&c->redDither) + ); + return; + default: break; + } #endif //HAVE_MMX YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB2_C, YSCALE_YUV_2_PACKED2_C) } @@ -1499,206 +1498,206 @@ YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB2_C, YSCALE_YUV_2_PACKED2_C) * YV12 to RGB without scaling or interpolating */ static inline void RENAME(yuv2packed1)(SwsContext *c, uint16_t *buf0, uint16_t *uvbuf0, uint16_t *uvbuf1, - uint8_t *dest, int dstW, int uvalpha, int dstFormat, int flags, int y) + uint8_t *dest, int dstW, int uvalpha, int dstFormat, int flags, int y) { - const int yalpha1=0; - int i; - - uint16_t *buf1= buf0; //FIXME needed for the rgb1/bgr1 - const int yalpha= 4096; //FIXME ... - - if(flags&SWS_FULL_CHR_H_INT) - { - RENAME(yuv2packed2)(c, buf0, buf0, uvbuf0, uvbuf1, dest, dstW, 0, uvalpha, y); - return; - } + const int yalpha1=0; + int i; + + uint16_t *buf1= buf0; //FIXME needed for the rgb1/bgr1 + const int yalpha= 4096; //FIXME ... + + if (flags&SWS_FULL_CHR_H_INT) + { + RENAME(yuv2packed2)(c, buf0, buf0, uvbuf0, uvbuf1, dest, dstW, 0, uvalpha, y); + return; + } #ifdef HAVE_MMX - if( uvalpha < 2048 ) // note this is not correct (shifts chrominance by 0.5 pixels) but its a bit faster - { - switch(dstFormat) - { - case PIX_FMT_RGB32: - asm volatile( - "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" - "mov %4, %%"REG_b" \n\t" - "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1(%%REGBP, %5) - WRITEBGR32(%%REGb, 8280(%5), %%REGBP) - "pop %%"REG_BP" \n\t" - "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" - - :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), - "a" (&c->redDither) - ); - return; - case PIX_FMT_BGR24: - asm volatile( - "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" - "mov %4, %%"REG_b" \n\t" - "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1(%%REGBP, %5) - WRITEBGR24(%%REGb, 8280(%5), %%REGBP) - "pop %%"REG_BP" \n\t" - "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" - - :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), - "a" (&c->redDither) - ); - return; - case PIX_FMT_BGR555: - asm volatile( - "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" - "mov %4, %%"REG_b" \n\t" - "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1(%%REGBP, %5) - /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ + if (uvalpha < 2048) // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster + { + switch(dstFormat) + { + case PIX_FMT_RGB32: + asm volatile( + "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" + "mov %4, %%"REG_b" \n\t" + "push %%"REG_BP" \n\t" + YSCALEYUV2RGB1(%%REGBP, %5) + WRITEBGR32(%%REGb, 8280(%5), %%REGBP) + "pop %%"REG_BP" \n\t" + "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" + + :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), + "a" (&c->redDither) + ); + return; + case PIX_FMT_BGR24: + asm volatile( + "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" + "mov %4, %%"REG_b" \n\t" + "push %%"REG_BP" \n\t" + YSCALEYUV2RGB1(%%REGBP, %5) + WRITEBGR24(%%REGb, 8280(%5), %%REGBP) + "pop %%"REG_BP" \n\t" + "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" + + :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), + "a" (&c->redDither) + ); + return; + case PIX_FMT_BGR555: + asm volatile( + "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" + "mov %4, %%"REG_b" \n\t" + "push %%"REG_BP" \n\t" + YSCALEYUV2RGB1(%%REGBP, %5) + /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP - "paddusb "MANGLE(b5Dither)", %%mm2\n\t" - "paddusb "MANGLE(g5Dither)", %%mm4\n\t" - "paddusb "MANGLE(r5Dither)", %%mm5\n\t" -#endif - WRITEBGR15(%%REGb, 8280(%5), %%REGBP) - "pop %%"REG_BP" \n\t" - "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" - - :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), - "a" (&c->redDither) - ); - return; - case PIX_FMT_BGR565: - asm volatile( - "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" - "mov %4, %%"REG_b" \n\t" - "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1(%%REGBP, %5) - /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ + "paddusb "MANGLE(b5Dither)", %%mm2 \n\t" + "paddusb "MANGLE(g5Dither)", %%mm4 \n\t" + "paddusb "MANGLE(r5Dither)", %%mm5 \n\t" +#endif + WRITEBGR15(%%REGb, 8280(%5), %%REGBP) + "pop %%"REG_BP" \n\t" + "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" + + :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), + "a" (&c->redDither) + ); + return; + case PIX_FMT_BGR565: + asm volatile( + "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" + "mov %4, %%"REG_b" \n\t" + "push %%"REG_BP" \n\t" + YSCALEYUV2RGB1(%%REGBP, %5) + /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP - "paddusb "MANGLE(b5Dither)", %%mm2\n\t" - "paddusb "MANGLE(g6Dither)", %%mm4\n\t" - "paddusb "MANGLE(r5Dither)", %%mm5\n\t" -#endif - - WRITEBGR16(%%REGb, 8280(%5), %%REGBP) - "pop %%"REG_BP" \n\t" - "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" - - :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), - "a" (&c->redDither) - ); - return; - case PIX_FMT_YUYV422: - asm volatile( - "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" - "mov %4, %%"REG_b" \n\t" - "push %%"REG_BP" \n\t" - YSCALEYUV2PACKED1(%%REGBP, %5) - WRITEYUY2(%%REGb, 8280(%5), %%REGBP) - "pop %%"REG_BP" \n\t" - "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" - - :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), - "a" (&c->redDither) - ); - return; - } - } - else - { - switch(dstFormat) - { - case PIX_FMT_RGB32: - asm volatile( - "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" - "mov %4, %%"REG_b" \n\t" - "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1b(%%REGBP, %5) - WRITEBGR32(%%REGb, 8280(%5), %%REGBP) - "pop %%"REG_BP" \n\t" - "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" - - :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), - "a" (&c->redDither) - ); - return; - case PIX_FMT_BGR24: - asm volatile( - "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" - "mov %4, %%"REG_b" \n\t" - "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1b(%%REGBP, %5) - WRITEBGR24(%%REGb, 8280(%5), %%REGBP) - "pop %%"REG_BP" \n\t" - "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" - - :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), - "a" (&c->redDither) - ); - return; - case PIX_FMT_BGR555: - asm volatile( - "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" - "mov %4, %%"REG_b" \n\t" - "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1b(%%REGBP, %5) - /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ + "paddusb "MANGLE(b5Dither)", %%mm2 \n\t" + "paddusb "MANGLE(g6Dither)", %%mm4 \n\t" + "paddusb "MANGLE(r5Dither)", %%mm5 \n\t" +#endif + + WRITEBGR16(%%REGb, 8280(%5), %%REGBP) + "pop %%"REG_BP" \n\t" + "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" + + :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), + "a" (&c->redDither) + ); + return; + case PIX_FMT_YUYV422: + asm volatile( + "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" + "mov %4, %%"REG_b" \n\t" + "push %%"REG_BP" \n\t" + YSCALEYUV2PACKED1(%%REGBP, %5) + WRITEYUY2(%%REGb, 8280(%5), %%REGBP) + "pop %%"REG_BP" \n\t" + "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" + + :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), + "a" (&c->redDither) + ); + return; + } + } + else + { + switch(dstFormat) + { + case PIX_FMT_RGB32: + asm volatile( + "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" + "mov %4, %%"REG_b" \n\t" + "push %%"REG_BP" \n\t" + YSCALEYUV2RGB1b(%%REGBP, %5) + WRITEBGR32(%%REGb, 8280(%5), %%REGBP) + "pop %%"REG_BP" \n\t" + "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" + + :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), + "a" (&c->redDither) + ); + return; + case PIX_FMT_BGR24: + asm volatile( + "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" + "mov %4, %%"REG_b" \n\t" + "push %%"REG_BP" \n\t" + YSCALEYUV2RGB1b(%%REGBP, %5) + WRITEBGR24(%%REGb, 8280(%5), %%REGBP) + "pop %%"REG_BP" \n\t" + "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" + + :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), + "a" (&c->redDither) + ); + return; + case PIX_FMT_BGR555: + asm volatile( + "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" + "mov %4, %%"REG_b" \n\t" + "push %%"REG_BP" \n\t" + YSCALEYUV2RGB1b(%%REGBP, %5) + /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP - "paddusb "MANGLE(b5Dither)", %%mm2\n\t" - "paddusb "MANGLE(g5Dither)", %%mm4\n\t" - "paddusb "MANGLE(r5Dither)", %%mm5\n\t" -#endif - WRITEBGR15(%%REGb, 8280(%5), %%REGBP) - "pop %%"REG_BP" \n\t" - "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" - - :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), - "a" (&c->redDither) - ); - return; - case PIX_FMT_BGR565: - asm volatile( - "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" - "mov %4, %%"REG_b" \n\t" - "push %%"REG_BP" \n\t" - YSCALEYUV2RGB1b(%%REGBP, %5) - /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ + "paddusb "MANGLE(b5Dither)", %%mm2 \n\t" + "paddusb "MANGLE(g5Dither)", %%mm4 \n\t" + "paddusb "MANGLE(r5Dither)", %%mm5 \n\t" +#endif + WRITEBGR15(%%REGb, 8280(%5), %%REGBP) + "pop %%"REG_BP" \n\t" + "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" + + :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), + "a" (&c->redDither) + ); + return; + case PIX_FMT_BGR565: + asm volatile( + "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" + "mov %4, %%"REG_b" \n\t" + "push %%"REG_BP" \n\t" + YSCALEYUV2RGB1b(%%REGBP, %5) + /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ #ifdef DITHER1XBPP - "paddusb "MANGLE(b5Dither)", %%mm2\n\t" - "paddusb "MANGLE(g6Dither)", %%mm4\n\t" - "paddusb "MANGLE(r5Dither)", %%mm5\n\t" -#endif - - WRITEBGR16(%%REGb, 8280(%5), %%REGBP) - "pop %%"REG_BP" \n\t" - "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" - - :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), - "a" (&c->redDither) - ); - return; - case PIX_FMT_YUYV422: - asm volatile( - "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" - "mov %4, %%"REG_b" \n\t" - "push %%"REG_BP" \n\t" - YSCALEYUV2PACKED1b(%%REGBP, %5) - WRITEYUY2(%%REGb, 8280(%5), %%REGBP) - "pop %%"REG_BP" \n\t" - "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" - - :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), - "a" (&c->redDither) - ); - return; - } - } -#endif - if( uvalpha < 2048 ) - { - YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1_C, YSCALE_YUV_2_PACKED1_C) - }else{ - YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1B_C, YSCALE_YUV_2_PACKED1B_C) - } + "paddusb "MANGLE(b5Dither)", %%mm2 \n\t" + "paddusb "MANGLE(g6Dither)", %%mm4 \n\t" + "paddusb "MANGLE(r5Dither)", %%mm5 \n\t" +#endif + + WRITEBGR16(%%REGb, 8280(%5), %%REGBP) + "pop %%"REG_BP" \n\t" + "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" + + :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), + "a" (&c->redDither) + ); + return; + case PIX_FMT_YUYV422: + asm volatile( + "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" + "mov %4, %%"REG_b" \n\t" + "push %%"REG_BP" \n\t" + YSCALEYUV2PACKED1b(%%REGBP, %5) + WRITEYUY2(%%REGb, 8280(%5), %%REGBP) + "pop %%"REG_BP" \n\t" + "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" + + :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), + "a" (&c->redDither) + ); + return; + } + } +#endif /* HAVE_MMX */ + if (uvalpha < 2048) + { + YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1_C, YSCALE_YUV_2_PACKED1_C) + }else{ + YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1B_C, YSCALE_YUV_2_PACKED1B_C) + } } //FIXME yuy2* can read upto 7 samples to much @@ -1706,910 +1705,896 @@ static inline void RENAME(yuv2packed1)(SwsContext *c, uint16_t *buf0, uint16_t * static inline void RENAME(yuy2ToY)(uint8_t *dst, uint8_t *src, long width) { #ifdef HAVE_MMX - asm volatile( - "movq "MANGLE(bm01010101)", %%mm2\n\t" - "mov %0, %%"REG_a" \n\t" - "1: \n\t" - "movq (%1, %%"REG_a",2), %%mm0 \n\t" - "movq 8(%1, %%"REG_a",2), %%mm1 \n\t" - "pand %%mm2, %%mm0 \n\t" - "pand %%mm2, %%mm1 \n\t" - "packuswb %%mm1, %%mm0 \n\t" - "movq %%mm0, (%2, %%"REG_a") \n\t" - "add $8, %%"REG_a" \n\t" - " js 1b \n\t" - : : "g" (-width), "r" (src+width*2), "r" (dst+width) - : "%"REG_a - ); + asm volatile( + "movq "MANGLE(bm01010101)", %%mm2 \n\t" + "mov %0, %%"REG_a" \n\t" + "1: \n\t" + "movq (%1, %%"REG_a",2), %%mm0 \n\t" + "movq 8(%1, %%"REG_a",2), %%mm1 \n\t" + "pand %%mm2, %%mm0 \n\t" + "pand %%mm2, %%mm1 \n\t" + "packuswb %%mm1, %%mm0 \n\t" + "movq %%mm0, (%2, %%"REG_a") \n\t" + "add $8, %%"REG_a" \n\t" + " js 1b \n\t" + : : "g" (-width), "r" (src+width*2), "r" (dst+width) + : "%"REG_a + ); #else - int i; - for(i=0; i>8)&0xFF; - int r= (((uint32_t*)src)[i]>>16)&0xFF; - - dst[i]= ((RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1)) )>>RGB2YUV_SHIFT); - } + int i; + for (i=0; i>8)&0xFF; + int r= (((uint32_t*)src)[i]>>16)&0xFF; + + dst[i]= ((RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT); + } } static inline void RENAME(bgr32ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width) { - int i; - assert(src1 == src2); - for(i=0; i>8; - const int r= l>>16; - - dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1)) + 128; - dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128; - } + int i; + assert(src1 == src2); + for (i=0; i>8; + const int r= l>>16; + + dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1)) + 128; + dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128; + } } static inline void RENAME(bgr24ToY)(uint8_t *dst, uint8_t *src, long width) { #ifdef HAVE_MMX - asm volatile( - "mov %2, %%"REG_a" \n\t" - "movq "MANGLE(bgr2YCoeff)", %%mm6 \n\t" - "movq "MANGLE(w1111)", %%mm5 \n\t" - "pxor %%mm7, %%mm7 \n\t" - "lea (%%"REG_a", %%"REG_a", 2), %%"REG_d"\n\t" - ASMALIGN(4) - "1: \n\t" - PREFETCH" 64(%0, %%"REG_d") \n\t" - "movd (%0, %%"REG_d"), %%mm0 \n\t" - "movd 3(%0, %%"REG_d"), %%mm1 \n\t" - "punpcklbw %%mm7, %%mm0 \n\t" - "punpcklbw %%mm7, %%mm1 \n\t" - "movd 6(%0, %%"REG_d"), %%mm2 \n\t" - "movd 9(%0, %%"REG_d"), %%mm3 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" - "punpcklbw %%mm7, %%mm3 \n\t" - "pmaddwd %%mm6, %%mm0 \n\t" - "pmaddwd %%mm6, %%mm1 \n\t" - "pmaddwd %%mm6, %%mm2 \n\t" - "pmaddwd %%mm6, %%mm3 \n\t" + asm volatile( + "mov %2, %%"REG_a" \n\t" + "movq "MANGLE(ff_bgr2YCoeff)", %%mm6 \n\t" + "movq "MANGLE(ff_w1111)", %%mm5 \n\t" + "pxor %%mm7, %%mm7 \n\t" + "lea (%%"REG_a", %%"REG_a", 2), %%"REG_d" \n\t" + ASMALIGN(4) + "1: \n\t" + PREFETCH" 64(%0, %%"REG_d") \n\t" + "movd (%0, %%"REG_d"), %%mm0 \n\t" + "movd 3(%0, %%"REG_d"), %%mm1 \n\t" + "punpcklbw %%mm7, %%mm0 \n\t" + "punpcklbw %%mm7, %%mm1 \n\t" + "movd 6(%0, %%"REG_d"), %%mm2 \n\t" + "movd 9(%0, %%"REG_d"), %%mm3 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" + "punpcklbw %%mm7, %%mm3 \n\t" + "pmaddwd %%mm6, %%mm0 \n\t" + "pmaddwd %%mm6, %%mm1 \n\t" + "pmaddwd %%mm6, %%mm2 \n\t" + "pmaddwd %%mm6, %%mm3 \n\t" #ifndef FAST_BGR2YV12 - "psrad $8, %%mm0 \n\t" - "psrad $8, %%mm1 \n\t" - "psrad $8, %%mm2 \n\t" - "psrad $8, %%mm3 \n\t" -#endif - "packssdw %%mm1, %%mm0 \n\t" - "packssdw %%mm3, %%mm2 \n\t" - "pmaddwd %%mm5, %%mm0 \n\t" - "pmaddwd %%mm5, %%mm2 \n\t" - "packssdw %%mm2, %%mm0 \n\t" - "psraw $7, %%mm0 \n\t" - - "movd 12(%0, %%"REG_d"), %%mm4 \n\t" - "movd 15(%0, %%"REG_d"), %%mm1 \n\t" - "punpcklbw %%mm7, %%mm4 \n\t" - "punpcklbw %%mm7, %%mm1 \n\t" - "movd 18(%0, %%"REG_d"), %%mm2 \n\t" - "movd 21(%0, %%"REG_d"), %%mm3 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" - "punpcklbw %%mm7, %%mm3 \n\t" - "pmaddwd %%mm6, %%mm4 \n\t" - "pmaddwd %%mm6, %%mm1 \n\t" - "pmaddwd %%mm6, %%mm2 \n\t" - "pmaddwd %%mm6, %%mm3 \n\t" + "psrad $8, %%mm0 \n\t" + "psrad $8, %%mm1 \n\t" + "psrad $8, %%mm2 \n\t" + "psrad $8, %%mm3 \n\t" +#endif + "packssdw %%mm1, %%mm0 \n\t" + "packssdw %%mm3, %%mm2 \n\t" + "pmaddwd %%mm5, %%mm0 \n\t" + "pmaddwd %%mm5, %%mm2 \n\t" + "packssdw %%mm2, %%mm0 \n\t" + "psraw $7, %%mm0 \n\t" + + "movd 12(%0, %%"REG_d"), %%mm4 \n\t" + "movd 15(%0, %%"REG_d"), %%mm1 \n\t" + "punpcklbw %%mm7, %%mm4 \n\t" + "punpcklbw %%mm7, %%mm1 \n\t" + "movd 18(%0, %%"REG_d"), %%mm2 \n\t" + "movd 21(%0, %%"REG_d"), %%mm3 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" + "punpcklbw %%mm7, %%mm3 \n\t" + "pmaddwd %%mm6, %%mm4 \n\t" + "pmaddwd %%mm6, %%mm1 \n\t" + "pmaddwd %%mm6, %%mm2 \n\t" + "pmaddwd %%mm6, %%mm3 \n\t" #ifndef FAST_BGR2YV12 - "psrad $8, %%mm4 \n\t" - "psrad $8, %%mm1 \n\t" - "psrad $8, %%mm2 \n\t" - "psrad $8, %%mm3 \n\t" -#endif - "packssdw %%mm1, %%mm4 \n\t" - "packssdw %%mm3, %%mm2 \n\t" - "pmaddwd %%mm5, %%mm4 \n\t" - "pmaddwd %%mm5, %%mm2 \n\t" - "add $24, %%"REG_d" \n\t" - "packssdw %%mm2, %%mm4 \n\t" - "psraw $7, %%mm4 \n\t" - - "packuswb %%mm4, %%mm0 \n\t" - "paddusb "MANGLE(bgr2YOffset)", %%mm0 \n\t" - - "movq %%mm0, (%1, %%"REG_a") \n\t" - "add $8, %%"REG_a" \n\t" - " js 1b \n\t" - : : "r" (src+width*3), "r" (dst+width), "g" (-width) - : "%"REG_a, "%"REG_d - ); + "psrad $8, %%mm4 \n\t" + "psrad $8, %%mm1 \n\t" + "psrad $8, %%mm2 \n\t" + "psrad $8, %%mm3 \n\t" +#endif + "packssdw %%mm1, %%mm4 \n\t" + "packssdw %%mm3, %%mm2 \n\t" + "pmaddwd %%mm5, %%mm4 \n\t" + "pmaddwd %%mm5, %%mm2 \n\t" + "add $24, %%"REG_d" \n\t" + "packssdw %%mm2, %%mm4 \n\t" + "psraw $7, %%mm4 \n\t" + + "packuswb %%mm4, %%mm0 \n\t" + "paddusb "MANGLE(ff_bgr2YOffset)", %%mm0 \n\t" + + "movq %%mm0, (%1, %%"REG_a") \n\t" + "add $8, %%"REG_a" \n\t" + " js 1b \n\t" + : : "r" (src+width*3), "r" (dst+width), "g" (-width) + : "%"REG_a, "%"REG_d + ); #else - int i; - for(i=0; i>RGB2YUV_SHIFT); - } -#endif + int i; + for (i=0; i>RGB2YUV_SHIFT); + } +#endif /* HAVE_MMX */ } static inline void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, long width) { #ifdef HAVE_MMX - asm volatile( - "mov %3, %%"REG_a" \n\t" - "movq "MANGLE(w1111)", %%mm5 \n\t" - "movq "MANGLE(bgr2UCoeff)", %%mm6 \n\t" - "pxor %%mm7, %%mm7 \n\t" - "lea (%%"REG_a", %%"REG_a", 2), %%"REG_d" \n\t" - "add %%"REG_d", %%"REG_d" \n\t" - ASMALIGN(4) - "1: \n\t" - PREFETCH" 64(%0, %%"REG_d") \n\t" + asm volatile( + "mov %3, %%"REG_a" \n\t" + "movq "MANGLE(ff_w1111)", %%mm5 \n\t" + "movq "MANGLE(ff_bgr2UCoeff)", %%mm6 \n\t" + "pxor %%mm7, %%mm7 \n\t" + "lea (%%"REG_a", %%"REG_a", 2), %%"REG_d" \n\t" + "add %%"REG_d", %%"REG_d" \n\t" + ASMALIGN(4) + "1: \n\t" + PREFETCH" 64(%0, %%"REG_d") \n\t" #if defined (HAVE_MMX2) || defined (HAVE_3DNOW) - "movq (%0, %%"REG_d"), %%mm0 \n\t" - "movq 6(%0, %%"REG_d"), %%mm2 \n\t" - "movq %%mm0, %%mm1 \n\t" - "movq %%mm2, %%mm3 \n\t" - "psrlq $24, %%mm0 \n\t" - "psrlq $24, %%mm2 \n\t" - PAVGB(%%mm1, %%mm0) - PAVGB(%%mm3, %%mm2) - "punpcklbw %%mm7, %%mm0 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" + "movq (%0, %%"REG_d"), %%mm0 \n\t" + "movq 6(%0, %%"REG_d"), %%mm2 \n\t" + "movq %%mm0, %%mm1 \n\t" + "movq %%mm2, %%mm3 \n\t" + "psrlq $24, %%mm0 \n\t" + "psrlq $24, %%mm2 \n\t" + PAVGB(%%mm1, %%mm0) + PAVGB(%%mm3, %%mm2) + "punpcklbw %%mm7, %%mm0 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" #else - "movd (%0, %%"REG_d"), %%mm0 \n\t" - "movd 3(%0, %%"REG_d"), %%mm2 \n\t" - "punpcklbw %%mm7, %%mm0 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" - "paddw %%mm2, %%mm0 \n\t" - "movd 6(%0, %%"REG_d"), %%mm4 \n\t" - "movd 9(%0, %%"REG_d"), %%mm2 \n\t" - "punpcklbw %%mm7, %%mm4 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" - "paddw %%mm4, %%mm2 \n\t" - "psrlw $1, %%mm0 \n\t" - "psrlw $1, %%mm2 \n\t" -#endif - "movq "MANGLE(bgr2VCoeff)", %%mm1 \n\t" - "movq "MANGLE(bgr2VCoeff)", %%mm3 \n\t" - - "pmaddwd %%mm0, %%mm1 \n\t" - "pmaddwd %%mm2, %%mm3 \n\t" - "pmaddwd %%mm6, %%mm0 \n\t" - "pmaddwd %%mm6, %%mm2 \n\t" + "movd (%0, %%"REG_d"), %%mm0 \n\t" + "movd 3(%0, %%"REG_d"), %%mm2 \n\t" + "punpcklbw %%mm7, %%mm0 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" + "paddw %%mm2, %%mm0 \n\t" + "movd 6(%0, %%"REG_d"), %%mm4 \n\t" + "movd 9(%0, %%"REG_d"), %%mm2 \n\t" + "punpcklbw %%mm7, %%mm4 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" + "paddw %%mm4, %%mm2 \n\t" + "psrlw $1, %%mm0 \n\t" + "psrlw $1, %%mm2 \n\t" +#endif + "movq "MANGLE(ff_bgr2VCoeff)", %%mm1 \n\t" + "movq "MANGLE(ff_bgr2VCoeff)", %%mm3 \n\t" + + "pmaddwd %%mm0, %%mm1 \n\t" + "pmaddwd %%mm2, %%mm3 \n\t" + "pmaddwd %%mm6, %%mm0 \n\t" + "pmaddwd %%mm6, %%mm2 \n\t" #ifndef FAST_BGR2YV12 - "psrad $8, %%mm0 \n\t" - "psrad $8, %%mm1 \n\t" - "psrad $8, %%mm2 \n\t" - "psrad $8, %%mm3 \n\t" -#endif - "packssdw %%mm2, %%mm0 \n\t" - "packssdw %%mm3, %%mm1 \n\t" - "pmaddwd %%mm5, %%mm0 \n\t" - "pmaddwd %%mm5, %%mm1 \n\t" - "packssdw %%mm1, %%mm0 \n\t" // V1 V0 U1 U0 - "psraw $7, %%mm0 \n\t" + "psrad $8, %%mm0 \n\t" + "psrad $8, %%mm1 \n\t" + "psrad $8, %%mm2 \n\t" + "psrad $8, %%mm3 \n\t" +#endif + "packssdw %%mm2, %%mm0 \n\t" + "packssdw %%mm3, %%mm1 \n\t" + "pmaddwd %%mm5, %%mm0 \n\t" + "pmaddwd %%mm5, %%mm1 \n\t" + "packssdw %%mm1, %%mm0 \n\t" // V1 V0 U1 U0 + "psraw $7, %%mm0 \n\t" #if defined (HAVE_MMX2) || defined (HAVE_3DNOW) - "movq 12(%0, %%"REG_d"), %%mm4 \n\t" - "movq 18(%0, %%"REG_d"), %%mm2 \n\t" - "movq %%mm4, %%mm1 \n\t" - "movq %%mm2, %%mm3 \n\t" - "psrlq $24, %%mm4 \n\t" - "psrlq $24, %%mm2 \n\t" - PAVGB(%%mm1, %%mm4) - PAVGB(%%mm3, %%mm2) - "punpcklbw %%mm7, %%mm4 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" + "movq 12(%0, %%"REG_d"), %%mm4 \n\t" + "movq 18(%0, %%"REG_d"), %%mm2 \n\t" + "movq %%mm4, %%mm1 \n\t" + "movq %%mm2, %%mm3 \n\t" + "psrlq $24, %%mm4 \n\t" + "psrlq $24, %%mm2 \n\t" + PAVGB(%%mm1, %%mm4) + PAVGB(%%mm3, %%mm2) + "punpcklbw %%mm7, %%mm4 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" #else - "movd 12(%0, %%"REG_d"), %%mm4 \n\t" - "movd 15(%0, %%"REG_d"), %%mm2 \n\t" - "punpcklbw %%mm7, %%mm4 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" - "paddw %%mm2, %%mm4 \n\t" - "movd 18(%0, %%"REG_d"), %%mm5 \n\t" - "movd 21(%0, %%"REG_d"), %%mm2 \n\t" - "punpcklbw %%mm7, %%mm5 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" - "paddw %%mm5, %%mm2 \n\t" - "movq "MANGLE(w1111)", %%mm5 \n\t" - "psrlw $2, %%mm4 \n\t" - "psrlw $2, %%mm2 \n\t" -#endif - "movq "MANGLE(bgr2VCoeff)", %%mm1 \n\t" - "movq "MANGLE(bgr2VCoeff)", %%mm3 \n\t" - - "pmaddwd %%mm4, %%mm1 \n\t" - "pmaddwd %%mm2, %%mm3 \n\t" - "pmaddwd %%mm6, %%mm4 \n\t" - "pmaddwd %%mm6, %%mm2 \n\t" + "movd 12(%0, %%"REG_d"), %%mm4 \n\t" + "movd 15(%0, %%"REG_d"), %%mm2 \n\t" + "punpcklbw %%mm7, %%mm4 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" + "paddw %%mm2, %%mm4 \n\t" + "movd 18(%0, %%"REG_d"), %%mm5 \n\t" + "movd 21(%0, %%"REG_d"), %%mm2 \n\t" + "punpcklbw %%mm7, %%mm5 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" + "paddw %%mm5, %%mm2 \n\t" + "movq "MANGLE(ff_w1111)", %%mm5 \n\t" + "psrlw $2, %%mm4 \n\t" + "psrlw $2, %%mm2 \n\t" +#endif + "movq "MANGLE(ff_bgr2VCoeff)", %%mm1 \n\t" + "movq "MANGLE(ff_bgr2VCoeff)", %%mm3 \n\t" + + "pmaddwd %%mm4, %%mm1 \n\t" + "pmaddwd %%mm2, %%mm3 \n\t" + "pmaddwd %%mm6, %%mm4 \n\t" + "pmaddwd %%mm6, %%mm2 \n\t" #ifndef FAST_BGR2YV12 - "psrad $8, %%mm4 \n\t" - "psrad $8, %%mm1 \n\t" - "psrad $8, %%mm2 \n\t" - "psrad $8, %%mm3 \n\t" -#endif - "packssdw %%mm2, %%mm4 \n\t" - "packssdw %%mm3, %%mm1 \n\t" - "pmaddwd %%mm5, %%mm4 \n\t" - "pmaddwd %%mm5, %%mm1 \n\t" - "add $24, %%"REG_d" \n\t" - "packssdw %%mm1, %%mm4 \n\t" // V3 V2 U3 U2 - "psraw $7, %%mm4 \n\t" - - "movq %%mm0, %%mm1 \n\t" - "punpckldq %%mm4, %%mm0 \n\t" - "punpckhdq %%mm4, %%mm1 \n\t" - "packsswb %%mm1, %%mm0 \n\t" - "paddb "MANGLE(bgr2UVOffset)", %%mm0 \n\t" - - "movd %%mm0, (%1, %%"REG_a") \n\t" - "punpckhdq %%mm0, %%mm0 \n\t" - "movd %%mm0, (%2, %%"REG_a") \n\t" - "add $4, %%"REG_a" \n\t" - " js 1b \n\t" - : : "r" (src1+width*6), "r" (dstU+width), "r" (dstV+width), "g" (-width) - : "%"REG_a, "%"REG_d - ); + "psrad $8, %%mm4 \n\t" + "psrad $8, %%mm1 \n\t" + "psrad $8, %%mm2 \n\t" + "psrad $8, %%mm3 \n\t" +#endif + "packssdw %%mm2, %%mm4 \n\t" + "packssdw %%mm3, %%mm1 \n\t" + "pmaddwd %%mm5, %%mm4 \n\t" + "pmaddwd %%mm5, %%mm1 \n\t" + "add $24, %%"REG_d" \n\t" + "packssdw %%mm1, %%mm4 \n\t" // V3 V2 U3 U2 + "psraw $7, %%mm4 \n\t" + + "movq %%mm0, %%mm1 \n\t" + "punpckldq %%mm4, %%mm0 \n\t" + "punpckhdq %%mm4, %%mm1 \n\t" + "packsswb %%mm1, %%mm0 \n\t" + "paddb "MANGLE(ff_bgr2UVOffset)", %%mm0 \n\t" + + "movd %%mm0, (%1, %%"REG_a") \n\t" + "punpckhdq %%mm0, %%mm0 \n\t" + "movd %%mm0, (%2, %%"REG_a") \n\t" + "add $4, %%"REG_a" \n\t" + " js 1b \n\t" + : : "r" (src1+width*6), "r" (dstU+width), "r" (dstV+width), "g" (-width) + : "%"REG_a, "%"REG_d + ); #else - int i; - for(i=0; i>(RGB2YUV_SHIFT+1)) + 128; - dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128; - } -#endif - assert(src1 == src2); + int i; + for (i=0; i>(RGB2YUV_SHIFT+1)) + 128; + dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128; + } +#endif /* HAVE_MMX */ + assert(src1 == src2); } -static inline void RENAME(bgr16ToY)(uint8_t *dst, uint8_t *src, int width) +static inline void RENAME(rgb16ToY)(uint8_t *dst, uint8_t *src, int width) { - int i; - for(i=0; i>5)&0x3F; - int r= (d>>11)&0x1F; - - dst[i]= ((2*RY*r + GY*g + 2*BY*b)>>(RGB2YUV_SHIFT-2)) + 16; - } + int i; + for (i=0; i>5)&0x3F; + int r= (d>>11)&0x1F; + + dst[i]= ((2*RY*r + GY*g + 2*BY*b)>>(RGB2YUV_SHIFT-2)) + 16; + } } -static inline void RENAME(bgr16ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width) +static inline void RENAME(rgb16ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width) { - int i; - assert(src1==src2); - for(i=0; i>5)&0x07C0F83F); - - int dh2= (dh>>11) + (dh<<21); - int d= dh2 + dl; - - int b= d&0x7F; - int r= (d>>11)&0x7F; - int g= d>>21; - dstU[i]= ((2*RU*r + GU*g + 2*BU*b)>>(RGB2YUV_SHIFT+1-2)) + 128; - dstV[i]= ((2*RV*r + GV*g + 2*BV*b)>>(RGB2YUV_SHIFT+1-2)) + 128; - } + int i; + assert(src1==src2); + for (i=0; i>5)&0x07C0F83F); + + int dh2= (dh>>11) + (dh<<21); + int d= dh2 + dl; + + int b= d&0x7F; + int r= (d>>11)&0x7F; + int g= d>>21; + dstU[i]= ((2*RU*r + GU*g + 2*BU*b)>>(RGB2YUV_SHIFT+1-2)) + 128; + dstV[i]= ((2*RV*r + GV*g + 2*BV*b)>>(RGB2YUV_SHIFT+1-2)) + 128; + } } -static inline void RENAME(bgr15ToY)(uint8_t *dst, uint8_t *src, int width) +static inline void RENAME(rgb15ToY)(uint8_t *dst, uint8_t *src, int width) { - int i; - for(i=0; i>5)&0x1F; - int r= (d>>10)&0x1F; - - dst[i]= ((RY*r + GY*g + BY*b)>>(RGB2YUV_SHIFT-3)) + 16; - } + int i; + for (i=0; i>5)&0x1F; + int r= (d>>10)&0x1F; + + dst[i]= ((RY*r + GY*g + BY*b)>>(RGB2YUV_SHIFT-3)) + 16; + } } -static inline void RENAME(bgr15ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width) +static inline void RENAME(rgb15ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width) { - int i; - assert(src1==src2); - for(i=0; i>5)&0x03E0F81F); - - int dh2= (dh>>11) + (dh<<21); - int d= dh2 + dl; - - int b= d&0x7F; - int r= (d>>10)&0x7F; - int g= d>>21; - dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1-3)) + 128; - dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1-3)) + 128; - } + int i; + assert(src1==src2); + for (i=0; i>5)&0x03E0F81F); + + int dh2= (dh>>11) + (dh<<21); + int d= dh2 + dl; + + int b= d&0x7F; + int r= (d>>10)&0x7F; + int g= d>>21; + dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1-3)) + 128; + dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1-3)) + 128; + } } static inline void RENAME(rgb32ToY)(uint8_t *dst, uint8_t *src, int width) { - int i; - for(i=0; i>8)&0xFF; - int b= (((uint32_t*)src)[i]>>16)&0xFF; - - dst[i]= ((RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1)) )>>RGB2YUV_SHIFT); - } + int i; + for (i=0; i>8)&0xFF; + int b= (((uint32_t*)src)[i]>>16)&0xFF; + + dst[i]= ((RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT); + } } static inline void RENAME(rgb32ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width) { - int i; - assert(src1==src2); - for(i=0; i>8; - const int b= l>>16; - - dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1)) + 128; - dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128; - } + int i; + assert(src1==src2); + for (i=0; i>8; + const int b= l>>16; + + dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1)) + 128; + dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128; + } } static inline void RENAME(rgb24ToY)(uint8_t *dst, uint8_t *src, int width) { - int i; - for(i=0; i>RGB2YUV_SHIFT); - } + int i; + for (i=0; i>RGB2YUV_SHIFT); + } } static inline void RENAME(rgb24ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width) { - int i; - assert(src1==src2); - for(i=0; i>(RGB2YUV_SHIFT+1)) + 128; - dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128; - } + int i; + assert(src1==src2); + for (i=0; i>(RGB2YUV_SHIFT+1)) + 128; + dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128; + } } -static inline void RENAME(rgb16ToY)(uint8_t *dst, uint8_t *src, int width) +static inline void RENAME(bgr16ToY)(uint8_t *dst, uint8_t *src, int width) { - int i; - for(i=0; i>5)&0x3F; - int b= (d>>11)&0x1F; - - dst[i]= ((2*RY*r + GY*g + 2*BY*b)>>(RGB2YUV_SHIFT-2)) + 16; - } + int i; + for (i=0; i>5)&0x3F; + int b= (d>>11)&0x1F; + + dst[i]= ((2*RY*r + GY*g + 2*BY*b)>>(RGB2YUV_SHIFT-2)) + 16; + } } -static inline void RENAME(rgb16ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width) +static inline void RENAME(bgr16ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width) { - int i; - assert(src1 == src2); - for(i=0; i>5)&0x07C0F83F); - - int dh2= (dh>>11) + (dh<<21); - int d= dh2 + dl; - - int r= d&0x7F; - int b= (d>>11)&0x7F; - int g= d>>21; - dstU[i]= ((2*RU*r + GU*g + 2*BU*b)>>(RGB2YUV_SHIFT+1-2)) + 128; - dstV[i]= ((2*RV*r + GV*g + 2*BV*b)>>(RGB2YUV_SHIFT+1-2)) + 128; - } + int i; + assert(src1 == src2); + for (i=0; i>16) + (d0<<16))&0x07E0F81F); + + int r= d&0x3F; + int b= (d>>11)&0x3F; + int g= d>>21; + dstU[i]= ((2*RU*r + GU*g + 2*BU*b)>>(RGB2YUV_SHIFT+1-2)) + 128; + dstV[i]= ((2*RV*r + GV*g + 2*BV*b)>>(RGB2YUV_SHIFT+1-2)) + 128; + } } -static inline void RENAME(rgb15ToY)(uint8_t *dst, uint8_t *src, int width) +static inline void RENAME(bgr15ToY)(uint8_t *dst, uint8_t *src, int width) { - int i; - for(i=0; i>5)&0x1F; - int b= (d>>10)&0x1F; - - dst[i]= ((RY*r + GY*g + BY*b)>>(RGB2YUV_SHIFT-3)) + 16; - } + int i; + for (i=0; i>5)&0x1F; + int b= (d>>10)&0x1F; + + dst[i]= ((RY*r + GY*g + BY*b)>>(RGB2YUV_SHIFT-3)) + 16; + } } -static inline void RENAME(rgb15ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width) +static inline void RENAME(bgr15ToUV)(uint8_t *dstU, uint8_t *dstV, uint8_t *src1, uint8_t *src2, int width) { - int i; - assert(src1 == src2); - for(i=0; i>5)&0x03E0F81F); - - int dh2= (dh>>11) + (dh<<21); - int d= dh2 + dl; - - int g= d&0x7F; - int r= (d>>10)&0x7F; - int b= d>>21; - dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1-3)) + 128; - dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1-3)) + 128; - } + int i; + assert(src1 == src2); + for (i=0; i>16) + (d0<<16))&0x03E07C1F); + + int r= d&0x3F; + int b= (d>>10)&0x3F; + int g= d>>21; + dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1-3)) + 128; + dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1-3)) + 128; + } } static inline void RENAME(palToY)(uint8_t *dst, uint8_t *src, int width, uint32_t *pal) { - int i; - for(i=0; i>8 )&0xFF; - int r= pal[d]>>16; - - dst[i]= ((RY*r + GY*g + BY*b)>>RGB2YUV_SHIFT) + 16; - } + int i; + for (i=0; i>8; - int b= p&0x1FF; - int r= p>>16; - - dstU[i]= ((RU*r + GU*g + BU*b)>>(RGB2YUV_SHIFT+1)) + 128; - dstV[i]= ((RV*r + GV*g + BV*b)>>(RGB2YUV_SHIFT+1)) + 128; - } + int i; + assert(src1 == src2); + for (i=0; i>8; + dstV[i]= p>>16; + } } // Bilinear / Bicubic scaling static inline void RENAME(hScale)(int16_t *dst, int dstW, uint8_t *src, int srcW, int xInc, - int16_t *filter, int16_t *filterPos, long filterSize) + int16_t *filter, int16_t *filterPos, long filterSize) { #ifdef HAVE_MMX - assert(filterSize % 4 == 0 && filterSize>0); - if(filterSize==4) // allways true for upscaling, sometimes for down too - { - long counter= -2*dstW; - filter-= counter*2; - filterPos-= counter/2; - dst-= counter/2; - asm volatile( + assert(filterSize % 4 == 0 && filterSize>0); + if (filterSize==4) // Always true for upscaling, sometimes for down, too. + { + long counter= -2*dstW; + filter-= counter*2; + filterPos-= counter/2; + dst-= counter/2; + asm volatile( #if defined(PIC) - "push %%"REG_b" \n\t" -#endif - "pxor %%mm7, %%mm7 \n\t" - "movq "MANGLE(w02)", %%mm6 \n\t" - "push %%"REG_BP" \n\t" // we use 7 regs here ... - "mov %%"REG_a", %%"REG_BP" \n\t" - ASMALIGN(4) - "1: \n\t" - "movzwl (%2, %%"REG_BP"), %%eax \n\t" - "movzwl 2(%2, %%"REG_BP"), %%ebx\n\t" - "movq (%1, %%"REG_BP", 4), %%mm1\n\t" - "movq 8(%1, %%"REG_BP", 4), %%mm3\n\t" - "movd (%3, %%"REG_a"), %%mm0 \n\t" - "movd (%3, %%"REG_b"), %%mm2 \n\t" - "punpcklbw %%mm7, %%mm0 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" - "pmaddwd %%mm1, %%mm0 \n\t" - "pmaddwd %%mm2, %%mm3 \n\t" - "psrad $8, %%mm0 \n\t" - "psrad $8, %%mm3 \n\t" - "packssdw %%mm3, %%mm0 \n\t" - "pmaddwd %%mm6, %%mm0 \n\t" - "packssdw %%mm0, %%mm0 \n\t" - "movd %%mm0, (%4, %%"REG_BP") \n\t" - "add $4, %%"REG_BP" \n\t" - " jnc 1b \n\t" - - "pop %%"REG_BP" \n\t" + "push %%"REG_b" \n\t" +#endif + "pxor %%mm7, %%mm7 \n\t" + "movq "MANGLE(w02)", %%mm6 \n\t" + "push %%"REG_BP" \n\t" // we use 7 regs here ... + "mov %%"REG_a", %%"REG_BP" \n\t" + ASMALIGN(4) + "1: \n\t" + "movzwl (%2, %%"REG_BP"), %%eax \n\t" + "movzwl 2(%2, %%"REG_BP"), %%ebx \n\t" + "movq (%1, %%"REG_BP", 4), %%mm1 \n\t" + "movq 8(%1, %%"REG_BP", 4), %%mm3 \n\t" + "movd (%3, %%"REG_a"), %%mm0 \n\t" + "movd (%3, %%"REG_b"), %%mm2 \n\t" + "punpcklbw %%mm7, %%mm0 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" + "pmaddwd %%mm1, %%mm0 \n\t" + "pmaddwd %%mm2, %%mm3 \n\t" + "psrad $8, %%mm0 \n\t" + "psrad $8, %%mm3 \n\t" + "packssdw %%mm3, %%mm0 \n\t" + "pmaddwd %%mm6, %%mm0 \n\t" + "packssdw %%mm0, %%mm0 \n\t" + "movd %%mm0, (%4, %%"REG_BP") \n\t" + "add $4, %%"REG_BP" \n\t" + " jnc 1b \n\t" + + "pop %%"REG_BP" \n\t" #if defined(PIC) - "pop %%"REG_b" \n\t" + "pop %%"REG_b" \n\t" #endif - : "+a" (counter) - : "c" (filter), "d" (filterPos), "S" (src), "D" (dst) + : "+a" (counter) + : "c" (filter), "d" (filterPos), "S" (src), "D" (dst) #if !defined(PIC) - : "%"REG_b + : "%"REG_b #endif - ); - } - else if(filterSize==8) - { - long counter= -2*dstW; - filter-= counter*4; - filterPos-= counter/2; - dst-= counter/2; - asm volatile( + ); + } + else if (filterSize==8) + { + long counter= -2*dstW; + filter-= counter*4; + filterPos-= counter/2; + dst-= counter/2; + asm volatile( #if defined(PIC) - "push %%"REG_b" \n\t" -#endif - "pxor %%mm7, %%mm7 \n\t" - "movq "MANGLE(w02)", %%mm6 \n\t" - "push %%"REG_BP" \n\t" // we use 7 regs here ... - "mov %%"REG_a", %%"REG_BP" \n\t" - ASMALIGN(4) - "1: \n\t" - "movzwl (%2, %%"REG_BP"), %%eax \n\t" - "movzwl 2(%2, %%"REG_BP"), %%ebx\n\t" - "movq (%1, %%"REG_BP", 8), %%mm1\n\t" - "movq 16(%1, %%"REG_BP", 8), %%mm3\n\t" - "movd (%3, %%"REG_a"), %%mm0 \n\t" - "movd (%3, %%"REG_b"), %%mm2 \n\t" - "punpcklbw %%mm7, %%mm0 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" - "pmaddwd %%mm1, %%mm0 \n\t" - "pmaddwd %%mm2, %%mm3 \n\t" - - "movq 8(%1, %%"REG_BP", 8), %%mm1\n\t" - "movq 24(%1, %%"REG_BP", 8), %%mm5\n\t" - "movd 4(%3, %%"REG_a"), %%mm4 \n\t" - "movd 4(%3, %%"REG_b"), %%mm2 \n\t" - "punpcklbw %%mm7, %%mm4 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" - "pmaddwd %%mm1, %%mm4 \n\t" - "pmaddwd %%mm2, %%mm5 \n\t" - "paddd %%mm4, %%mm0 \n\t" - "paddd %%mm5, %%mm3 \n\t" - - "psrad $8, %%mm0 \n\t" - "psrad $8, %%mm3 \n\t" - "packssdw %%mm3, %%mm0 \n\t" - "pmaddwd %%mm6, %%mm0 \n\t" - "packssdw %%mm0, %%mm0 \n\t" - "movd %%mm0, (%4, %%"REG_BP") \n\t" - "add $4, %%"REG_BP" \n\t" - " jnc 1b \n\t" - - "pop %%"REG_BP" \n\t" + "push %%"REG_b" \n\t" +#endif + "pxor %%mm7, %%mm7 \n\t" + "movq "MANGLE(w02)", %%mm6 \n\t" + "push %%"REG_BP" \n\t" // we use 7 regs here ... + "mov %%"REG_a", %%"REG_BP" \n\t" + ASMALIGN(4) + "1: \n\t" + "movzwl (%2, %%"REG_BP"), %%eax \n\t" + "movzwl 2(%2, %%"REG_BP"), %%ebx \n\t" + "movq (%1, %%"REG_BP", 8), %%mm1 \n\t" + "movq 16(%1, %%"REG_BP", 8), %%mm3 \n\t" + "movd (%3, %%"REG_a"), %%mm0 \n\t" + "movd (%3, %%"REG_b"), %%mm2 \n\t" + "punpcklbw %%mm7, %%mm0 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" + "pmaddwd %%mm1, %%mm0 \n\t" + "pmaddwd %%mm2, %%mm3 \n\t" + + "movq 8(%1, %%"REG_BP", 8), %%mm1 \n\t" + "movq 24(%1, %%"REG_BP", 8), %%mm5 \n\t" + "movd 4(%3, %%"REG_a"), %%mm4 \n\t" + "movd 4(%3, %%"REG_b"), %%mm2 \n\t" + "punpcklbw %%mm7, %%mm4 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" + "pmaddwd %%mm1, %%mm4 \n\t" + "pmaddwd %%mm2, %%mm5 \n\t" + "paddd %%mm4, %%mm0 \n\t" + "paddd %%mm5, %%mm3 \n\t" + + "psrad $8, %%mm0 \n\t" + "psrad $8, %%mm3 \n\t" + "packssdw %%mm3, %%mm0 \n\t" + "pmaddwd %%mm6, %%mm0 \n\t" + "packssdw %%mm0, %%mm0 \n\t" + "movd %%mm0, (%4, %%"REG_BP") \n\t" + "add $4, %%"REG_BP" \n\t" + " jnc 1b \n\t" + + "pop %%"REG_BP" \n\t" #if defined(PIC) - "pop %%"REG_b" \n\t" + "pop %%"REG_b" \n\t" #endif - : "+a" (counter) - : "c" (filter), "d" (filterPos), "S" (src), "D" (dst) + : "+a" (counter) + : "c" (filter), "d" (filterPos), "S" (src), "D" (dst) #if !defined(PIC) - : "%"REG_b + : "%"REG_b #endif - ); - } - else - { - uint8_t *offset = src+filterSize; - long counter= -2*dstW; -// filter-= counter*filterSize/2; - filterPos-= counter/2; - dst-= counter/2; - asm volatile( - "pxor %%mm7, %%mm7 \n\t" - "movq "MANGLE(w02)", %%mm6 \n\t" - ASMALIGN(4) - "1: \n\t" - "mov %2, %%"REG_c" \n\t" - "movzwl (%%"REG_c", %0), %%eax \n\t" - "movzwl 2(%%"REG_c", %0), %%edx \n\t" - "mov %5, %%"REG_c" \n\t" - "pxor %%mm4, %%mm4 \n\t" - "pxor %%mm5, %%mm5 \n\t" - "2: \n\t" - "movq (%1), %%mm1 \n\t" - "movq (%1, %6), %%mm3 \n\t" - "movd (%%"REG_c", %%"REG_a"), %%mm0\n\t" - "movd (%%"REG_c", %%"REG_d"), %%mm2\n\t" - "punpcklbw %%mm7, %%mm0 \n\t" - "punpcklbw %%mm7, %%mm2 \n\t" - "pmaddwd %%mm1, %%mm0 \n\t" - "pmaddwd %%mm2, %%mm3 \n\t" - "paddd %%mm3, %%mm5 \n\t" - "paddd %%mm0, %%mm4 \n\t" - "add $8, %1 \n\t" - "add $4, %%"REG_c" \n\t" - "cmp %4, %%"REG_c" \n\t" - " jb 2b \n\t" - "add %6, %1 \n\t" - "psrad $8, %%mm4 \n\t" - "psrad $8, %%mm5 \n\t" - "packssdw %%mm5, %%mm4 \n\t" - "pmaddwd %%mm6, %%mm4 \n\t" - "packssdw %%mm4, %%mm4 \n\t" - "mov %3, %%"REG_a" \n\t" - "movd %%mm4, (%%"REG_a", %0) \n\t" - "add $4, %0 \n\t" - " jnc 1b \n\t" - - : "+r" (counter), "+r" (filter) - : "m" (filterPos), "m" (dst), "m"(offset), - "m" (src), "r" (filterSize*2) - : "%"REG_a, "%"REG_c, "%"REG_d - ); - } + ); + } + else + { + uint8_t *offset = src+filterSize; + long counter= -2*dstW; + //filter-= counter*filterSize/2; + filterPos-= counter/2; + dst-= counter/2; + asm volatile( + "pxor %%mm7, %%mm7 \n\t" + "movq "MANGLE(w02)", %%mm6 \n\t" + ASMALIGN(4) + "1: \n\t" + "mov %2, %%"REG_c" \n\t" + "movzwl (%%"REG_c", %0), %%eax \n\t" + "movzwl 2(%%"REG_c", %0), %%edx \n\t" + "mov %5, %%"REG_c" \n\t" + "pxor %%mm4, %%mm4 \n\t" + "pxor %%mm5, %%mm5 \n\t" + "2: \n\t" + "movq (%1), %%mm1 \n\t" + "movq (%1, %6), %%mm3 \n\t" + "movd (%%"REG_c", %%"REG_a"), %%mm0 \n\t" + "movd (%%"REG_c", %%"REG_d"), %%mm2 \n\t" + "punpcklbw %%mm7, %%mm0 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" + "pmaddwd %%mm1, %%mm0 \n\t" + "pmaddwd %%mm2, %%mm3 \n\t" + "paddd %%mm3, %%mm5 \n\t" + "paddd %%mm0, %%mm4 \n\t" + "add $8, %1 \n\t" + "add $4, %%"REG_c" \n\t" + "cmp %4, %%"REG_c" \n\t" + " jb 2b \n\t" + "add %6, %1 \n\t" + "psrad $8, %%mm4 \n\t" + "psrad $8, %%mm5 \n\t" + "packssdw %%mm5, %%mm4 \n\t" + "pmaddwd %%mm6, %%mm4 \n\t" + "packssdw %%mm4, %%mm4 \n\t" + "mov %3, %%"REG_a" \n\t" + "movd %%mm4, (%%"REG_a", %0) \n\t" + "add $4, %0 \n\t" + " jnc 1b \n\t" + + : "+r" (counter), "+r" (filter) + : "m" (filterPos), "m" (dst), "m"(offset), + "m" (src), "r" (filterSize*2) + : "%"REG_a, "%"REG_c, "%"REG_d + ); + } #else #ifdef HAVE_ALTIVEC - hScale_altivec_real(dst, dstW, src, srcW, xInc, filter, filterPos, filterSize); + hScale_altivec_real(dst, dstW, src, srcW, xInc, filter, filterPos, filterSize); #else - int i; - for(i=0; i>7, 0, (1<<15)-1); // the cubic equation does overflow ... -// dst[i] = val>>7; - } -#endif -#endif + int i; + for (i=0; i>7, 0, (1<<15)-1); // the cubic equation does overflow ... + //dst[i] = val>>7; + } +#endif /* HAVE_ALTIVEC */ +#endif /* HAVE_MMX */ } // *** horizontal scale Y line to temp buffer static inline void RENAME(hyscale)(uint16_t *dst, long dstWidth, uint8_t *src, int srcW, int xInc, - int flags, int canMMX2BeUsed, int16_t *hLumFilter, - int16_t *hLumFilterPos, int hLumFilterSize, void *funnyYCode, - int srcFormat, uint8_t *formatConvBuffer, int16_t *mmx2Filter, - int32_t *mmx2FilterPos, uint8_t *pal) + int flags, int canMMX2BeUsed, int16_t *hLumFilter, + int16_t *hLumFilterPos, int hLumFilterSize, void *funnyYCode, + int srcFormat, uint8_t *formatConvBuffer, int16_t *mmx2Filter, + int32_t *mmx2FilterPos, uint8_t *pal) { - if(srcFormat==PIX_FMT_YUYV422 || srcFormat==PIX_FMT_GRAY16BE) + if (srcFormat==PIX_FMT_YUYV422 || srcFormat==PIX_FMT_GRAY16BE) { - RENAME(yuy2ToY)(formatConvBuffer, src, srcW); - src= formatConvBuffer; + RENAME(yuy2ToY)(formatConvBuffer, src, srcW); + src= formatConvBuffer; } - else if(srcFormat==PIX_FMT_UYVY422 || srcFormat==PIX_FMT_GRAY16LE) + else if (srcFormat==PIX_FMT_UYVY422 || srcFormat==PIX_FMT_GRAY16LE) { - RENAME(uyvyToY)(formatConvBuffer, src, srcW); - src= formatConvBuffer; + RENAME(uyvyToY)(formatConvBuffer, src, srcW); + src= formatConvBuffer; } - else if(srcFormat==PIX_FMT_RGB32) + else if (srcFormat==PIX_FMT_RGB32) { - RENAME(bgr32ToY)(formatConvBuffer, src, srcW); - src= formatConvBuffer; + RENAME(bgr32ToY)(formatConvBuffer, src, srcW); + src= formatConvBuffer; } - else if(srcFormat==PIX_FMT_BGR24) + else if (srcFormat==PIX_FMT_BGR24) { - RENAME(bgr24ToY)(formatConvBuffer, src, srcW); - src= formatConvBuffer; + RENAME(bgr24ToY)(formatConvBuffer, src, srcW); + src= formatConvBuffer; } - else if(srcFormat==PIX_FMT_BGR565) + else if (srcFormat==PIX_FMT_BGR565) { - RENAME(bgr16ToY)(formatConvBuffer, src, srcW); - src= formatConvBuffer; + RENAME(bgr16ToY)(formatConvBuffer, src, srcW); + src= formatConvBuffer; } - else if(srcFormat==PIX_FMT_BGR555) + else if (srcFormat==PIX_FMT_BGR555) { - RENAME(bgr15ToY)(formatConvBuffer, src, srcW); - src= formatConvBuffer; + RENAME(bgr15ToY)(formatConvBuffer, src, srcW); + src= formatConvBuffer; } - else if(srcFormat==PIX_FMT_BGR32) + else if (srcFormat==PIX_FMT_BGR32) { - RENAME(rgb32ToY)(formatConvBuffer, src, srcW); - src= formatConvBuffer; + RENAME(rgb32ToY)(formatConvBuffer, src, srcW); + src= formatConvBuffer; } - else if(srcFormat==PIX_FMT_RGB24) + else if (srcFormat==PIX_FMT_RGB24) { - RENAME(rgb24ToY)(formatConvBuffer, src, srcW); - src= formatConvBuffer; + RENAME(rgb24ToY)(formatConvBuffer, src, srcW); + src= formatConvBuffer; } - else if(srcFormat==PIX_FMT_RGB565) + else if (srcFormat==PIX_FMT_RGB565) { - RENAME(rgb16ToY)(formatConvBuffer, src, srcW); - src= formatConvBuffer; + RENAME(rgb16ToY)(formatConvBuffer, src, srcW); + src= formatConvBuffer; } - else if(srcFormat==PIX_FMT_RGB555) + else if (srcFormat==PIX_FMT_RGB555) { - RENAME(rgb15ToY)(formatConvBuffer, src, srcW); - src= formatConvBuffer; + RENAME(rgb15ToY)(formatConvBuffer, src, srcW); + src= formatConvBuffer; } - else if(srcFormat==PIX_FMT_RGB8 || srcFormat==PIX_FMT_BGR8 || srcFormat==PIX_FMT_PAL8 || srcFormat==PIX_FMT_BGR4_BYTE || srcFormat==PIX_FMT_RGB4_BYTE) + else if (srcFormat==PIX_FMT_RGB8 || srcFormat==PIX_FMT_BGR8 || srcFormat==PIX_FMT_PAL8 || srcFormat==PIX_FMT_BGR4_BYTE || srcFormat==PIX_FMT_RGB4_BYTE) { - RENAME(palToY)(formatConvBuffer, src, srcW, pal); - src= formatConvBuffer; + RENAME(palToY)(formatConvBuffer, src, srcW, pal); + src= formatConvBuffer; } #ifdef HAVE_MMX - // use the new MMX scaler if the mmx2 can't be used (its faster than the x86asm one) - if(!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed)) + // use the new MMX scaler if the mmx2 can't be used (it is faster than the x86 ASM one) + if (!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed)) #else - if(!(flags&SWS_FAST_BILINEAR)) + if (!(flags&SWS_FAST_BILINEAR)) #endif { - RENAME(hScale)(dst, dstWidth, src, srcW, xInc, hLumFilter, hLumFilterPos, hLumFilterSize); + RENAME(hScale)(dst, dstWidth, src, srcW, xInc, hLumFilter, hLumFilterPos, hLumFilterSize); } else // Fast Bilinear upscale / crap downscale { #if defined(ARCH_X86) #ifdef HAVE_MMX2 - int i; + int i; #if defined(PIC) - uint64_t ebxsave __attribute__((aligned(8))); + uint64_t ebxsave __attribute__((aligned(8))); #endif - if(canMMX2BeUsed) - { - asm volatile( + if (canMMX2BeUsed) + { + asm volatile( #if defined(PIC) - "mov %%"REG_b", %5 \n\t" -#endif - "pxor %%mm7, %%mm7 \n\t" - "mov %0, %%"REG_c" \n\t" - "mov %1, %%"REG_D" \n\t" - "mov %2, %%"REG_d" \n\t" - "mov %3, %%"REG_b" \n\t" - "xor %%"REG_a", %%"REG_a" \n\t" // i - PREFETCH" (%%"REG_c") \n\t" - PREFETCH" 32(%%"REG_c") \n\t" - PREFETCH" 64(%%"REG_c") \n\t" + "mov %%"REG_b", %5 \n\t" +#endif + "pxor %%mm7, %%mm7 \n\t" + "mov %0, %%"REG_c" \n\t" + "mov %1, %%"REG_D" \n\t" + "mov %2, %%"REG_d" \n\t" + "mov %3, %%"REG_b" \n\t" + "xor %%"REG_a", %%"REG_a" \n\t" // i + PREFETCH" (%%"REG_c") \n\t" + PREFETCH" 32(%%"REG_c") \n\t" + PREFETCH" 64(%%"REG_c") \n\t" #ifdef ARCH_X86_64 #define FUNNY_Y_CODE \ - "movl (%%"REG_b"), %%esi \n\t"\ - "call *%4 \n\t"\ - "movl (%%"REG_b", %%"REG_a"), %%esi\n\t"\ - "add %%"REG_S", %%"REG_c" \n\t"\ - "add %%"REG_a", %%"REG_D" \n\t"\ - "xor %%"REG_a", %%"REG_a" \n\t"\ + "movl (%%"REG_b"), %%esi \n\t"\ + "call *%4 \n\t"\ + "movl (%%"REG_b", %%"REG_a"), %%esi \n\t"\ + "add %%"REG_S", %%"REG_c" \n\t"\ + "add %%"REG_a", %%"REG_D" \n\t"\ + "xor %%"REG_a", %%"REG_a" \n\t"\ #else #define FUNNY_Y_CODE \ - "movl (%%"REG_b"), %%esi \n\t"\ - "call *%4 \n\t"\ - "addl (%%"REG_b", %%"REG_a"), %%"REG_c"\n\t"\ - "add %%"REG_a", %%"REG_D" \n\t"\ - "xor %%"REG_a", %%"REG_a" \n\t"\ + "movl (%%"REG_b"), %%esi \n\t"\ + "call *%4 \n\t"\ + "addl (%%"REG_b", %%"REG_a"), %%"REG_c" \n\t"\ + "add %%"REG_a", %%"REG_D" \n\t"\ + "xor %%"REG_a", %%"REG_a" \n\t"\ -#endif +#endif /* ARCH_X86_64 */ FUNNY_Y_CODE FUNNY_Y_CODE @@ -2621,225 +2606,225 @@ FUNNY_Y_CODE FUNNY_Y_CODE #if defined(PIC) - "mov %5, %%"REG_b" \n\t" + "mov %5, %%"REG_b" \n\t" #endif - :: "m" (src), "m" (dst), "m" (mmx2Filter), "m" (mmx2FilterPos), - "m" (funnyYCode) + :: "m" (src), "m" (dst), "m" (mmx2Filter), "m" (mmx2FilterPos), + "m" (funnyYCode) #if defined(PIC) - ,"m" (ebxsave) + ,"m" (ebxsave) #endif - : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D + : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D #if !defined(PIC) - ,"%"REG_b -#endif - ); - for(i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) dst[i] = src[srcW-1]*128; - } - else - { + ,"%"REG_b #endif - long xInc_shr16 = xInc >> 16; - uint16_t xInc_mask = xInc & 0xffff; - //NO MMX just normal asm ... - asm volatile( - "xor %%"REG_a", %%"REG_a" \n\t" // i - "xor %%"REG_d", %%"REG_d" \n\t" // xx - "xorl %%ecx, %%ecx \n\t" // 2*xalpha - ASMALIGN(4) - "1: \n\t" - "movzbl (%0, %%"REG_d"), %%edi \n\t" //src[xx] - "movzbl 1(%0, %%"REG_d"), %%esi \n\t" //src[xx+1] - "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx] - "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha - "shll $16, %%edi \n\t" - "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha) - "mov %1, %%"REG_D" \n\t" - "shrl $9, %%esi \n\t" - "movw %%si, (%%"REG_D", %%"REG_a", 2)\n\t" - "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF - "adc %3, %%"REG_d" \n\t" //xx+= xInc>>8 + carry - - "movzbl (%0, %%"REG_d"), %%edi \n\t" //src[xx] - "movzbl 1(%0, %%"REG_d"), %%esi \n\t" //src[xx+1] - "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx] - "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha - "shll $16, %%edi \n\t" - "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha) - "mov %1, %%"REG_D" \n\t" - "shrl $9, %%esi \n\t" - "movw %%si, 2(%%"REG_D", %%"REG_a", 2)\n\t" - "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF - "adc %3, %%"REG_d" \n\t" //xx+= xInc>>8 + carry - - - "add $2, %%"REG_a" \n\t" - "cmp %2, %%"REG_a" \n\t" - " jb 1b \n\t" - - - :: "r" (src), "m" (dst), "m" (dstWidth), "m" (xInc_shr16), "m" (xInc_mask) - : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi" - ); + ); + for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) dst[i] = src[srcW-1]*128; + } + else + { +#endif /* HAVE_MMX2 */ + long xInc_shr16 = xInc >> 16; + uint16_t xInc_mask = xInc & 0xffff; + //NO MMX just normal asm ... + asm volatile( + "xor %%"REG_a", %%"REG_a" \n\t" // i + "xor %%"REG_d", %%"REG_d" \n\t" // xx + "xorl %%ecx, %%ecx \n\t" // 2*xalpha + ASMALIGN(4) + "1: \n\t" + "movzbl (%0, %%"REG_d"), %%edi \n\t" //src[xx] + "movzbl 1(%0, %%"REG_d"), %%esi \n\t" //src[xx+1] + "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx] + "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha + "shll $16, %%edi \n\t" + "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha) + "mov %1, %%"REG_D" \n\t" + "shrl $9, %%esi \n\t" + "movw %%si, (%%"REG_D", %%"REG_a", 2) \n\t" + "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF + "adc %3, %%"REG_d" \n\t" //xx+= xInc>>8 + carry + + "movzbl (%0, %%"REG_d"), %%edi \n\t" //src[xx] + "movzbl 1(%0, %%"REG_d"), %%esi \n\t" //src[xx+1] + "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx] + "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha + "shll $16, %%edi \n\t" + "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha) + "mov %1, %%"REG_D" \n\t" + "shrl $9, %%esi \n\t" + "movw %%si, 2(%%"REG_D", %%"REG_a", 2) \n\t" + "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF + "adc %3, %%"REG_d" \n\t" //xx+= xInc>>8 + carry + + + "add $2, %%"REG_a" \n\t" + "cmp %2, %%"REG_a" \n\t" + " jb 1b \n\t" + + + :: "r" (src), "m" (dst), "m" (dstWidth), "m" (xInc_shr16), "m" (xInc_mask) + : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi" + ); #ifdef HAVE_MMX2 - } //if MMX2 can't be used + } //if MMX2 can't be used #endif #else - int i; - unsigned int xpos=0; - for(i=0;i>16; - register unsigned int xalpha=(xpos&0xFFFF)>>9; - dst[i]= (src[xx]<<7) + (src[xx+1] - src[xx])*xalpha; - xpos+=xInc; - } -#endif + int i; + unsigned int xpos=0; + for (i=0;i>16; + register unsigned int xalpha=(xpos&0xFFFF)>>9; + dst[i]= (src[xx]<<7) + (src[xx+1] - src[xx])*xalpha; + xpos+=xInc; + } +#endif /* defined(ARCH_X86) */ } } inline static void RENAME(hcscale)(uint16_t *dst, long dstWidth, uint8_t *src1, uint8_t *src2, - int srcW, int xInc, int flags, int canMMX2BeUsed, int16_t *hChrFilter, - int16_t *hChrFilterPos, int hChrFilterSize, void *funnyUVCode, - int srcFormat, uint8_t *formatConvBuffer, int16_t *mmx2Filter, - int32_t *mmx2FilterPos, uint8_t *pal) + int srcW, int xInc, int flags, int canMMX2BeUsed, int16_t *hChrFilter, + int16_t *hChrFilterPos, int hChrFilterSize, void *funnyUVCode, + int srcFormat, uint8_t *formatConvBuffer, int16_t *mmx2Filter, + int32_t *mmx2FilterPos, uint8_t *pal) { - if(srcFormat==PIX_FMT_YUYV422) + if (srcFormat==PIX_FMT_YUYV422) { - RENAME(yuy2ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); - src1= formatConvBuffer; - src2= formatConvBuffer+2048; + RENAME(yuy2ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); + src1= formatConvBuffer; + src2= formatConvBuffer+2048; } - else if(srcFormat==PIX_FMT_UYVY422) + else if (srcFormat==PIX_FMT_UYVY422) { - RENAME(uyvyToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); - src1= formatConvBuffer; - src2= formatConvBuffer+2048; + RENAME(uyvyToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); + src1= formatConvBuffer; + src2= formatConvBuffer+2048; } - else if(srcFormat==PIX_FMT_RGB32) + else if (srcFormat==PIX_FMT_RGB32) { - RENAME(bgr32ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); - src1= formatConvBuffer; - src2= formatConvBuffer+2048; + RENAME(bgr32ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); + src1= formatConvBuffer; + src2= formatConvBuffer+2048; } - else if(srcFormat==PIX_FMT_BGR24) + else if (srcFormat==PIX_FMT_BGR24) { - RENAME(bgr24ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); - src1= formatConvBuffer; - src2= formatConvBuffer+2048; + RENAME(bgr24ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); + src1= formatConvBuffer; + src2= formatConvBuffer+2048; } - else if(srcFormat==PIX_FMT_BGR565) + else if (srcFormat==PIX_FMT_BGR565) { - RENAME(bgr16ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); - src1= formatConvBuffer; - src2= formatConvBuffer+2048; + RENAME(bgr16ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); + src1= formatConvBuffer; + src2= formatConvBuffer+2048; } - else if(srcFormat==PIX_FMT_BGR555) + else if (srcFormat==PIX_FMT_BGR555) { - RENAME(bgr15ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); - src1= formatConvBuffer; - src2= formatConvBuffer+2048; + RENAME(bgr15ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); + src1= formatConvBuffer; + src2= formatConvBuffer+2048; } - else if(srcFormat==PIX_FMT_BGR32) + else if (srcFormat==PIX_FMT_BGR32) { - RENAME(rgb32ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); - src1= formatConvBuffer; - src2= formatConvBuffer+2048; + RENAME(rgb32ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); + src1= formatConvBuffer; + src2= formatConvBuffer+2048; } - else if(srcFormat==PIX_FMT_RGB24) + else if (srcFormat==PIX_FMT_RGB24) { - RENAME(rgb24ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); - src1= formatConvBuffer; - src2= formatConvBuffer+2048; + RENAME(rgb24ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); + src1= formatConvBuffer; + src2= formatConvBuffer+2048; } - else if(srcFormat==PIX_FMT_RGB565) + else if (srcFormat==PIX_FMT_RGB565) { - RENAME(rgb16ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); - src1= formatConvBuffer; - src2= formatConvBuffer+2048; + RENAME(rgb16ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); + src1= formatConvBuffer; + src2= formatConvBuffer+2048; } - else if(srcFormat==PIX_FMT_RGB555) + else if (srcFormat==PIX_FMT_RGB555) { - RENAME(rgb15ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); - src1= formatConvBuffer; - src2= formatConvBuffer+2048; + RENAME(rgb15ToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW); + src1= formatConvBuffer; + src2= formatConvBuffer+2048; } - else if(isGray(srcFormat)) + else if (isGray(srcFormat)) { - return; + return; } - else if(srcFormat==PIX_FMT_RGB8 || srcFormat==PIX_FMT_BGR8 || srcFormat==PIX_FMT_PAL8 || srcFormat==PIX_FMT_BGR4_BYTE || srcFormat==PIX_FMT_RGB4_BYTE) + else if (srcFormat==PIX_FMT_RGB8 || srcFormat==PIX_FMT_BGR8 || srcFormat==PIX_FMT_PAL8 || srcFormat==PIX_FMT_BGR4_BYTE || srcFormat==PIX_FMT_RGB4_BYTE) { - RENAME(palToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW, pal); - src1= formatConvBuffer; - src2= formatConvBuffer+2048; + RENAME(palToUV)(formatConvBuffer, formatConvBuffer+2048, src1, src2, srcW, pal); + src1= formatConvBuffer; + src2= formatConvBuffer+2048; } #ifdef HAVE_MMX - // use the new MMX scaler if the mmx2 can't be used (its faster than the x86asm one) - if(!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed)) + // use the new MMX scaler if the mmx2 can't be used (it is faster than the x86 ASM one) + if (!(flags&SWS_FAST_BILINEAR) || (!canMMX2BeUsed)) #else - if(!(flags&SWS_FAST_BILINEAR)) + if (!(flags&SWS_FAST_BILINEAR)) #endif { - RENAME(hScale)(dst , dstWidth, src1, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize); - RENAME(hScale)(dst+2048, dstWidth, src2, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize); + RENAME(hScale)(dst , dstWidth, src1, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize); + RENAME(hScale)(dst+2048, dstWidth, src2, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize); } else // Fast Bilinear upscale / crap downscale { #if defined(ARCH_X86) #ifdef HAVE_MMX2 - int i; + int i; #if defined(PIC) - uint64_t ebxsave __attribute__((aligned(8))); + uint64_t ebxsave __attribute__((aligned(8))); #endif - if(canMMX2BeUsed) - { - asm volatile( + if (canMMX2BeUsed) + { + asm volatile( #if defined(PIC) - "mov %%"REG_b", %6 \n\t" -#endif - "pxor %%mm7, %%mm7 \n\t" - "mov %0, %%"REG_c" \n\t" - "mov %1, %%"REG_D" \n\t" - "mov %2, %%"REG_d" \n\t" - "mov %3, %%"REG_b" \n\t" - "xor %%"REG_a", %%"REG_a" \n\t" // i - PREFETCH" (%%"REG_c") \n\t" - PREFETCH" 32(%%"REG_c") \n\t" - PREFETCH" 64(%%"REG_c") \n\t" + "mov %%"REG_b", %6 \n\t" +#endif + "pxor %%mm7, %%mm7 \n\t" + "mov %0, %%"REG_c" \n\t" + "mov %1, %%"REG_D" \n\t" + "mov %2, %%"REG_d" \n\t" + "mov %3, %%"REG_b" \n\t" + "xor %%"REG_a", %%"REG_a" \n\t" // i + PREFETCH" (%%"REG_c") \n\t" + PREFETCH" 32(%%"REG_c") \n\t" + PREFETCH" 64(%%"REG_c") \n\t" #ifdef ARCH_X86_64 #define FUNNY_UV_CODE \ - "movl (%%"REG_b"), %%esi \n\t"\ - "call *%4 \n\t"\ - "movl (%%"REG_b", %%"REG_a"), %%esi\n\t"\ - "add %%"REG_S", %%"REG_c" \n\t"\ - "add %%"REG_a", %%"REG_D" \n\t"\ - "xor %%"REG_a", %%"REG_a" \n\t"\ + "movl (%%"REG_b"), %%esi \n\t"\ + "call *%4 \n\t"\ + "movl (%%"REG_b", %%"REG_a"), %%esi \n\t"\ + "add %%"REG_S", %%"REG_c" \n\t"\ + "add %%"REG_a", %%"REG_D" \n\t"\ + "xor %%"REG_a", %%"REG_a" \n\t"\ #else #define FUNNY_UV_CODE \ - "movl (%%"REG_b"), %%esi \n\t"\ - "call *%4 \n\t"\ - "addl (%%"REG_b", %%"REG_a"), %%"REG_c"\n\t"\ - "add %%"REG_a", %%"REG_D" \n\t"\ - "xor %%"REG_a", %%"REG_a" \n\t"\ + "movl (%%"REG_b"), %%esi \n\t"\ + "call *%4 \n\t"\ + "addl (%%"REG_b", %%"REG_a"), %%"REG_c" \n\t"\ + "add %%"REG_a", %%"REG_D" \n\t"\ + "xor %%"REG_a", %%"REG_a" \n\t"\ -#endif +#endif /* ARCH_X86_64 */ FUNNY_UV_CODE FUNNY_UV_CODE FUNNY_UV_CODE FUNNY_UV_CODE - "xor %%"REG_a", %%"REG_a" \n\t" // i - "mov %5, %%"REG_c" \n\t" // src - "mov %1, %%"REG_D" \n\t" // buf1 - "add $4096, %%"REG_D" \n\t" - PREFETCH" (%%"REG_c") \n\t" - PREFETCH" 32(%%"REG_c") \n\t" - PREFETCH" 64(%%"REG_c") \n\t" + "xor %%"REG_a", %%"REG_a" \n\t" // i + "mov %5, %%"REG_c" \n\t" // src + "mov %1, %%"REG_D" \n\t" // buf1 + "add $4096, %%"REG_D" \n\t" + PREFETCH" (%%"REG_c") \n\t" + PREFETCH" 32(%%"REG_c") \n\t" + PREFETCH" 64(%%"REG_c") \n\t" FUNNY_UV_CODE FUNNY_UV_CODE @@ -2847,442 +2832,442 @@ FUNNY_UV_CODE FUNNY_UV_CODE #if defined(PIC) - "mov %6, %%"REG_b" \n\t" + "mov %6, %%"REG_b" \n\t" #endif - :: "m" (src1), "m" (dst), "m" (mmx2Filter), "m" (mmx2FilterPos), - "m" (funnyUVCode), "m" (src2) + :: "m" (src1), "m" (dst), "m" (mmx2Filter), "m" (mmx2FilterPos), + "m" (funnyUVCode), "m" (src2) #if defined(PIC) - ,"m" (ebxsave) + ,"m" (ebxsave) #endif - : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D + : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D #if !defined(PIC) - ,"%"REG_b -#endif - ); - for(i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) - { -// printf("%d %d %d\n", dstWidth, i, srcW); - dst[i] = src1[srcW-1]*128; - dst[i+2048] = src2[srcW-1]*128; - } - } - else - { -#endif - long xInc_shr16 = (long) (xInc >> 16); - uint16_t xInc_mask = xInc & 0xffff; - asm volatile( - "xor %%"REG_a", %%"REG_a" \n\t" // i - "xor %%"REG_d", %%"REG_d" \n\t" // xx - "xorl %%ecx, %%ecx \n\t" // 2*xalpha - ASMALIGN(4) - "1: \n\t" - "mov %0, %%"REG_S" \n\t" - "movzbl (%%"REG_S", %%"REG_d"), %%edi \n\t" //src[xx] - "movzbl 1(%%"REG_S", %%"REG_d"), %%esi \n\t" //src[xx+1] - "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx] - "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha - "shll $16, %%edi \n\t" - "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha) - "mov %1, %%"REG_D" \n\t" - "shrl $9, %%esi \n\t" - "movw %%si, (%%"REG_D", %%"REG_a", 2)\n\t" - - "movzbl (%5, %%"REG_d"), %%edi \n\t" //src[xx] - "movzbl 1(%5, %%"REG_d"), %%esi \n\t" //src[xx+1] - "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx] - "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha - "shll $16, %%edi \n\t" - "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha) - "mov %1, %%"REG_D" \n\t" - "shrl $9, %%esi \n\t" - "movw %%si, 4096(%%"REG_D", %%"REG_a", 2)\n\t" - - "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF - "adc %3, %%"REG_d" \n\t" //xx+= xInc>>8 + carry - "add $1, %%"REG_a" \n\t" - "cmp %2, %%"REG_a" \n\t" - " jb 1b \n\t" + ,"%"REG_b +#endif + ); + for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) + { + //printf("%d %d %d\n", dstWidth, i, srcW); + dst[i] = src1[srcW-1]*128; + dst[i+2048] = src2[srcW-1]*128; + } + } + else + { +#endif /* HAVE_MMX2 */ + long xInc_shr16 = (long) (xInc >> 16); + uint16_t xInc_mask = xInc & 0xffff; + asm volatile( + "xor %%"REG_a", %%"REG_a" \n\t" // i + "xor %%"REG_d", %%"REG_d" \n\t" // xx + "xorl %%ecx, %%ecx \n\t" // 2*xalpha + ASMALIGN(4) + "1: \n\t" + "mov %0, %%"REG_S" \n\t" + "movzbl (%%"REG_S", %%"REG_d"), %%edi \n\t" //src[xx] + "movzbl 1(%%"REG_S", %%"REG_d"), %%esi \n\t" //src[xx+1] + "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx] + "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha + "shll $16, %%edi \n\t" + "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha) + "mov %1, %%"REG_D" \n\t" + "shrl $9, %%esi \n\t" + "movw %%si, (%%"REG_D", %%"REG_a", 2) \n\t" + + "movzbl (%5, %%"REG_d"), %%edi \n\t" //src[xx] + "movzbl 1(%5, %%"REG_d"), %%esi \n\t" //src[xx+1] + "subl %%edi, %%esi \n\t" //src[xx+1] - src[xx] + "imull %%ecx, %%esi \n\t" //(src[xx+1] - src[xx])*2*xalpha + "shll $16, %%edi \n\t" + "addl %%edi, %%esi \n\t" //src[xx+1]*2*xalpha + src[xx]*(1-2*xalpha) + "mov %1, %%"REG_D" \n\t" + "shrl $9, %%esi \n\t" + "movw %%si, 4096(%%"REG_D", %%"REG_a", 2) \n\t" + + "addw %4, %%cx \n\t" //2*xalpha += xInc&0xFF + "adc %3, %%"REG_d" \n\t" //xx+= xInc>>8 + carry + "add $1, %%"REG_a" \n\t" + "cmp %2, %%"REG_a" \n\t" + " jb 1b \n\t" /* GCC-3.3 makes MPlayer crash on IA-32 machines when using "g" operand here, which is needed to support GCC-4.0 */ -#if defined(ARCH_X86_64) && ((__GNUC__ > 3) || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 4)) - :: "m" (src1), "m" (dst), "g" ((long)dstWidth), "m" (xInc_shr16), "m" (xInc_mask), +#if defined(ARCH_X86_64) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) + :: "m" (src1), "m" (dst), "g" ((long)dstWidth), "m" (xInc_shr16), "m" (xInc_mask), #else - :: "m" (src1), "m" (dst), "m" ((long)dstWidth), "m" (xInc_shr16), "m" (xInc_mask), + :: "m" (src1), "m" (dst), "m" ((long)dstWidth), "m" (xInc_shr16), "m" (xInc_mask), #endif - "r" (src2) - : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi" - ); + "r" (src2) + : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi" + ); #ifdef HAVE_MMX2 - } //if MMX2 can't be used + } //if MMX2 can't be used #endif #else - int i; - unsigned int xpos=0; - for(i=0;i>16; - register unsigned int xalpha=(xpos&0xFFFF)>>9; - dst[i]=(src1[xx]*(xalpha^127)+src1[xx+1]*xalpha); - dst[i+2048]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha); -/* slower - dst[i]= (src1[xx]<<7) + (src1[xx+1] - src1[xx])*xalpha; - dst[i+2048]=(src2[xx]<<7) + (src2[xx+1] - src2[xx])*xalpha; -*/ - xpos+=xInc; - } -#endif - } + int i; + unsigned int xpos=0; + for (i=0;i>16; + register unsigned int xalpha=(xpos&0xFFFF)>>9; + dst[i]=(src1[xx]*(xalpha^127)+src1[xx+1]*xalpha); + dst[i+2048]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha); + /* slower + dst[i]= (src1[xx]<<7) + (src1[xx+1] - src1[xx])*xalpha; + dst[i+2048]=(src2[xx]<<7) + (src2[xx+1] - src2[xx])*xalpha; + */ + xpos+=xInc; + } +#endif /* defined(ARCH_X86) */ + } } static int RENAME(swScale)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]){ - - /* load a few things into local vars to make the code more readable? and faster */ - const int srcW= c->srcW; - const int dstW= c->dstW; - const int dstH= c->dstH; - const int chrDstW= c->chrDstW; - const int chrSrcW= c->chrSrcW; - const int lumXInc= c->lumXInc; - const int chrXInc= c->chrXInc; - const int dstFormat= c->dstFormat; - const int srcFormat= c->srcFormat; - const int flags= c->flags; - const int canMMX2BeUsed= c->canMMX2BeUsed; - int16_t *vLumFilterPos= c->vLumFilterPos; - int16_t *vChrFilterPos= c->vChrFilterPos; - int16_t *hLumFilterPos= c->hLumFilterPos; - int16_t *hChrFilterPos= c->hChrFilterPos; - int16_t *vLumFilter= c->vLumFilter; - int16_t *vChrFilter= c->vChrFilter; - int16_t *hLumFilter= c->hLumFilter; - int16_t *hChrFilter= c->hChrFilter; - int32_t *lumMmxFilter= c->lumMmxFilter; - int32_t *chrMmxFilter= c->chrMmxFilter; - const int vLumFilterSize= c->vLumFilterSize; - const int vChrFilterSize= c->vChrFilterSize; - const int hLumFilterSize= c->hLumFilterSize; - const int hChrFilterSize= c->hChrFilterSize; - int16_t **lumPixBuf= c->lumPixBuf; - int16_t **chrPixBuf= c->chrPixBuf; - const int vLumBufSize= c->vLumBufSize; - const int vChrBufSize= c->vChrBufSize; - uint8_t *funnyYCode= c->funnyYCode; - uint8_t *funnyUVCode= c->funnyUVCode; - uint8_t *formatConvBuffer= c->formatConvBuffer; - const int chrSrcSliceY= srcSliceY >> c->chrSrcVSubSample; - const int chrSrcSliceH= -((-srcSliceH) >> c->chrSrcVSubSample); - int lastDstY; - uint8_t *pal=NULL; - - /* vars whch will change and which we need to storw back in the context */ - int dstY= c->dstY; - int lumBufIndex= c->lumBufIndex; - int chrBufIndex= c->chrBufIndex; - int lastInLumBuf= c->lastInLumBuf; - int lastInChrBuf= c->lastInChrBuf; - - if(isPacked(c->srcFormat)){ - pal= src[1]; - src[0]= - src[1]= - src[2]= src[0]; - srcStride[0]= - srcStride[1]= - srcStride[2]= srcStride[0]; - } - srcStride[1]<<= c->vChrDrop; - srcStride[2]<<= c->vChrDrop; - -// printf("swscale %X %X %X -> %X %X %X\n", (int)src[0], (int)src[1], (int)src[2], -// (int)dst[0], (int)dst[1], (int)dst[2]); + int srcSliceH, uint8_t* dst[], int dstStride[]){ + + /* load a few things into local vars to make the code more readable? and faster */ + const int srcW= c->srcW; + const int dstW= c->dstW; + const int dstH= c->dstH; + const int chrDstW= c->chrDstW; + const int chrSrcW= c->chrSrcW; + const int lumXInc= c->lumXInc; + const int chrXInc= c->chrXInc; + const int dstFormat= c->dstFormat; + const int srcFormat= c->srcFormat; + const int flags= c->flags; + const int canMMX2BeUsed= c->canMMX2BeUsed; + int16_t *vLumFilterPos= c->vLumFilterPos; + int16_t *vChrFilterPos= c->vChrFilterPos; + int16_t *hLumFilterPos= c->hLumFilterPos; + int16_t *hChrFilterPos= c->hChrFilterPos; + int16_t *vLumFilter= c->vLumFilter; + int16_t *vChrFilter= c->vChrFilter; + int16_t *hLumFilter= c->hLumFilter; + int16_t *hChrFilter= c->hChrFilter; + int32_t *lumMmxFilter= c->lumMmxFilter; + int32_t *chrMmxFilter= c->chrMmxFilter; + const int vLumFilterSize= c->vLumFilterSize; + const int vChrFilterSize= c->vChrFilterSize; + const int hLumFilterSize= c->hLumFilterSize; + const int hChrFilterSize= c->hChrFilterSize; + int16_t **lumPixBuf= c->lumPixBuf; + int16_t **chrPixBuf= c->chrPixBuf; + const int vLumBufSize= c->vLumBufSize; + const int vChrBufSize= c->vChrBufSize; + uint8_t *funnyYCode= c->funnyYCode; + uint8_t *funnyUVCode= c->funnyUVCode; + uint8_t *formatConvBuffer= c->formatConvBuffer; + const int chrSrcSliceY= srcSliceY >> c->chrSrcVSubSample; + const int chrSrcSliceH= -((-srcSliceH) >> c->chrSrcVSubSample); + int lastDstY; + uint8_t *pal=NULL; + + /* vars whch will change and which we need to storw back in the context */ + int dstY= c->dstY; + int lumBufIndex= c->lumBufIndex; + int chrBufIndex= c->chrBufIndex; + int lastInLumBuf= c->lastInLumBuf; + int lastInChrBuf= c->lastInChrBuf; + + if (isPacked(c->srcFormat)){ + pal= src[1]; + src[0]= + src[1]= + src[2]= src[0]; + srcStride[0]= + srcStride[1]= + srcStride[2]= srcStride[0]; + } + srcStride[1]<<= c->vChrDrop; + srcStride[2]<<= c->vChrDrop; + + //printf("swscale %X %X %X -> %X %X %X\n", (int)src[0], (int)src[1], (int)src[2], + // (int)dst[0], (int)dst[1], (int)dst[2]); #if 0 //self test FIXME move to a vfilter or something -{ -static volatile int i=0; -i++; -if(srcFormat==PIX_FMT_YUV420P && i==1 && srcSliceH>= c->srcH) - selfTest(src, srcStride, c->srcW, c->srcH); -i--; -} + { + static volatile int i=0; + i++; + if (srcFormat==PIX_FMT_YUV420P && i==1 && srcSliceH>= c->srcH) + selfTest(src, srcStride, c->srcW, c->srcH); + i--; + } #endif -//printf("sws Strides:%d %d %d -> %d %d %d\n", srcStride[0],srcStride[1],srcStride[2], -//dstStride[0],dstStride[1],dstStride[2]); - - if(dstStride[0]%8 !=0 || dstStride[1]%8 !=0 || dstStride[2]%8 !=0) - { - static int firstTime=1; //FIXME move this into the context perhaps - if(flags & SWS_PRINT_INFO && firstTime) - { - av_log(c, AV_LOG_WARNING, "SwScaler: Warning: dstStride is not aligned!\n" - "SwScaler: ->cannot do aligned memory acesses anymore\n"); - firstTime=0; - } - } - - /* Note the user might start scaling the picture in the middle so this will not get executed - this is not really intended but works currently, so ppl might do it */ - if(srcSliceY ==0){ - lumBufIndex=0; - chrBufIndex=0; - dstY=0; - lastInLumBuf= -1; - lastInChrBuf= -1; - } - - lastDstY= dstY; - - for(;dstY < dstH; dstY++){ - unsigned char *dest =dst[0]+dstStride[0]*dstY; - const int chrDstY= dstY>>c->chrDstVSubSample; - unsigned char *uDest=dst[1]+dstStride[1]*chrDstY; - unsigned char *vDest=dst[2]+dstStride[2]*chrDstY; - - const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input - const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input - const int lastLumSrcY= firstLumSrcY + vLumFilterSize -1; // Last line needed as input - const int lastChrSrcY= firstChrSrcY + vChrFilterSize -1; // Last line needed as input - -//printf("dstY:%d dstH:%d firstLumSrcY:%d lastInLumBuf:%d vLumBufSize: %d vChrBufSize: %d slice: %d %d vLumFilterSize: %d firstChrSrcY: %d vChrFilterSize: %d c->chrSrcVSubSample: %d\n", -// dstY, dstH, firstLumSrcY, lastInLumBuf, vLumBufSize, vChrBufSize, srcSliceY, srcSliceH, vLumFilterSize, firstChrSrcY, vChrFilterSize, c->chrSrcVSubSample); - //handle holes (FAST_BILINEAR & weird filters) - if(firstLumSrcY > lastInLumBuf) lastInLumBuf= firstLumSrcY-1; - if(firstChrSrcY > lastInChrBuf) lastInChrBuf= firstChrSrcY-1; -//printf("%d %d %d\n", firstChrSrcY, lastInChrBuf, vChrBufSize); - ASSERT(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1) - ASSERT(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1) - - // Do we have enough lines in this slice to output the dstY line - if(lastLumSrcY < srcSliceY + srcSliceH && lastChrSrcY < -((-srcSliceY - srcSliceH)>>c->chrSrcVSubSample)) - { - //Do horizontal scaling - while(lastInLumBuf < lastLumSrcY) - { - uint8_t *s= src[0]+(lastInLumBuf + 1 - srcSliceY)*srcStride[0]; - lumBufIndex++; -// printf("%d %d %d %d\n", lumBufIndex, vLumBufSize, lastInLumBuf, lastLumSrcY); - ASSERT(lumBufIndex < 2*vLumBufSize) - ASSERT(lastInLumBuf + 1 - srcSliceY < srcSliceH) - ASSERT(lastInLumBuf + 1 - srcSliceY >= 0) -// printf("%d %d\n", lumBufIndex, vLumBufSize); - RENAME(hyscale)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc, - flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize, - funnyYCode, c->srcFormat, formatConvBuffer, - c->lumMmx2Filter, c->lumMmx2FilterPos, pal); - lastInLumBuf++; - } - while(lastInChrBuf < lastChrSrcY) - { - uint8_t *src1= src[1]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[1]; - uint8_t *src2= src[2]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[2]; - chrBufIndex++; - ASSERT(chrBufIndex < 2*vChrBufSize) - ASSERT(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH)) - ASSERT(lastInChrBuf + 1 - chrSrcSliceY >= 0) - //FIXME replace parameters through context struct (some at least) - - if(!(isGray(srcFormat) || isGray(dstFormat))) - RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, chrSrcW, chrXInc, - flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize, - funnyUVCode, c->srcFormat, formatConvBuffer, - c->chrMmx2Filter, c->chrMmx2FilterPos, pal); - lastInChrBuf++; - } - //wrap buf index around to stay inside the ring buffer - if(lumBufIndex >= vLumBufSize ) lumBufIndex-= vLumBufSize; - if(chrBufIndex >= vChrBufSize ) chrBufIndex-= vChrBufSize; - } - else // not enough lines left in this slice -> load the rest in the buffer - { -/* printf("%d %d Last:%d %d LastInBuf:%d %d Index:%d %d Y:%d FSize: %d %d BSize: %d %d\n", - firstChrSrcY,firstLumSrcY,lastChrSrcY,lastLumSrcY, - lastInChrBuf,lastInLumBuf,chrBufIndex,lumBufIndex,dstY,vChrFilterSize,vLumFilterSize, - vChrBufSize, vLumBufSize);*/ - - //Do horizontal scaling - while(lastInLumBuf+1 < srcSliceY + srcSliceH) - { - uint8_t *s= src[0]+(lastInLumBuf + 1 - srcSliceY)*srcStride[0]; - lumBufIndex++; - ASSERT(lumBufIndex < 2*vLumBufSize) - ASSERT(lastInLumBuf + 1 - srcSliceY < srcSliceH) - ASSERT(lastInLumBuf + 1 - srcSliceY >= 0) - RENAME(hyscale)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc, - flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize, - funnyYCode, c->srcFormat, formatConvBuffer, - c->lumMmx2Filter, c->lumMmx2FilterPos, pal); - lastInLumBuf++; - } - while(lastInChrBuf+1 < (chrSrcSliceY + chrSrcSliceH)) - { - uint8_t *src1= src[1]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[1]; - uint8_t *src2= src[2]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[2]; - chrBufIndex++; - ASSERT(chrBufIndex < 2*vChrBufSize) - ASSERT(lastInChrBuf + 1 - chrSrcSliceY < chrSrcSliceH) - ASSERT(lastInChrBuf + 1 - chrSrcSliceY >= 0) - - if(!(isGray(srcFormat) || isGray(dstFormat))) - RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, chrSrcW, chrXInc, - flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize, - funnyUVCode, c->srcFormat, formatConvBuffer, - c->chrMmx2Filter, c->chrMmx2FilterPos, pal); - lastInChrBuf++; - } - //wrap buf index around to stay inside the ring buffer - if(lumBufIndex >= vLumBufSize ) lumBufIndex-= vLumBufSize; - if(chrBufIndex >= vChrBufSize ) chrBufIndex-= vChrBufSize; - break; //we can't output a dstY line so let's try with the next slice - } + //printf("sws Strides:%d %d %d -> %d %d %d\n", srcStride[0],srcStride[1],srcStride[2], + //dstStride[0],dstStride[1],dstStride[2]); + + if (dstStride[0]%8 !=0 || dstStride[1]%8 !=0 || dstStride[2]%8 !=0) + { + static int firstTime=1; //FIXME move this into the context perhaps + if (flags & SWS_PRINT_INFO && firstTime) + { + av_log(c, AV_LOG_WARNING, "SwScaler: Warning: dstStride is not aligned!\n" + "SwScaler: ->cannot do aligned memory acesses anymore\n"); + firstTime=0; + } + } + + /* Note the user might start scaling the picture in the middle so this will not get executed + this is not really intended but works currently, so ppl might do it */ + if (srcSliceY ==0){ + lumBufIndex=0; + chrBufIndex=0; + dstY=0; + lastInLumBuf= -1; + lastInChrBuf= -1; + } + + lastDstY= dstY; + + for (;dstY < dstH; dstY++){ + unsigned char *dest =dst[0]+dstStride[0]*dstY; + const int chrDstY= dstY>>c->chrDstVSubSample; + unsigned char *uDest=dst[1]+dstStride[1]*chrDstY; + unsigned char *vDest=dst[2]+dstStride[2]*chrDstY; + + const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input + const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input + const int lastLumSrcY= firstLumSrcY + vLumFilterSize -1; // Last line needed as input + const int lastChrSrcY= firstChrSrcY + vChrFilterSize -1; // Last line needed as input + + //printf("dstY:%d dstH:%d firstLumSrcY:%d lastInLumBuf:%d vLumBufSize: %d vChrBufSize: %d slice: %d %d vLumFilterSize: %d firstChrSrcY: %d vChrFilterSize: %d c->chrSrcVSubSample: %d\n", + // dstY, dstH, firstLumSrcY, lastInLumBuf, vLumBufSize, vChrBufSize, srcSliceY, srcSliceH, vLumFilterSize, firstChrSrcY, vChrFilterSize, c->chrSrcVSubSample); + //handle holes (FAST_BILINEAR & weird filters) + if (firstLumSrcY > lastInLumBuf) lastInLumBuf= firstLumSrcY-1; + if (firstChrSrcY > lastInChrBuf) lastInChrBuf= firstChrSrcY-1; + //printf("%d %d %d\n", firstChrSrcY, lastInChrBuf, vChrBufSize); + ASSERT(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1) + ASSERT(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1) + + // Do we have enough lines in this slice to output the dstY line + if (lastLumSrcY < srcSliceY + srcSliceH && lastChrSrcY < -((-srcSliceY - srcSliceH)>>c->chrSrcVSubSample)) + { + //Do horizontal scaling + while(lastInLumBuf < lastLumSrcY) + { + uint8_t *s= src[0]+(lastInLumBuf + 1 - srcSliceY)*srcStride[0]; + lumBufIndex++; + //printf("%d %d %d %d\n", lumBufIndex, vLumBufSize, lastInLumBuf, lastLumSrcY); + ASSERT(lumBufIndex < 2*vLumBufSize) + ASSERT(lastInLumBuf + 1 - srcSliceY < srcSliceH) + ASSERT(lastInLumBuf + 1 - srcSliceY >= 0) + //printf("%d %d\n", lumBufIndex, vLumBufSize); + RENAME(hyscale)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc, + flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize, + funnyYCode, c->srcFormat, formatConvBuffer, + c->lumMmx2Filter, c->lumMmx2FilterPos, pal); + lastInLumBuf++; + } + while(lastInChrBuf < lastChrSrcY) + { + uint8_t *src1= src[1]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[1]; + uint8_t *src2= src[2]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[2]; + chrBufIndex++; + ASSERT(chrBufIndex < 2*vChrBufSize) + ASSERT(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH)) + ASSERT(lastInChrBuf + 1 - chrSrcSliceY >= 0) + //FIXME replace parameters through context struct (some at least) + + if (!(isGray(srcFormat) || isGray(dstFormat))) + RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, chrSrcW, chrXInc, + flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize, + funnyUVCode, c->srcFormat, formatConvBuffer, + c->chrMmx2Filter, c->chrMmx2FilterPos, pal); + lastInChrBuf++; + } + //wrap buf index around to stay inside the ring buffer + if (lumBufIndex >= vLumBufSize) lumBufIndex-= vLumBufSize; + if (chrBufIndex >= vChrBufSize) chrBufIndex-= vChrBufSize; + } + else // not enough lines left in this slice -> load the rest in the buffer + { + /* printf("%d %d Last:%d %d LastInBuf:%d %d Index:%d %d Y:%d FSize: %d %d BSize: %d %d\n", + firstChrSrcY,firstLumSrcY,lastChrSrcY,lastLumSrcY, + lastInChrBuf,lastInLumBuf,chrBufIndex,lumBufIndex,dstY,vChrFilterSize,vLumFilterSize, + vChrBufSize, vLumBufSize);*/ + + //Do horizontal scaling + while(lastInLumBuf+1 < srcSliceY + srcSliceH) + { + uint8_t *s= src[0]+(lastInLumBuf + 1 - srcSliceY)*srcStride[0]; + lumBufIndex++; + ASSERT(lumBufIndex < 2*vLumBufSize) + ASSERT(lastInLumBuf + 1 - srcSliceY < srcSliceH) + ASSERT(lastInLumBuf + 1 - srcSliceY >= 0) + RENAME(hyscale)(lumPixBuf[ lumBufIndex ], dstW, s, srcW, lumXInc, + flags, canMMX2BeUsed, hLumFilter, hLumFilterPos, hLumFilterSize, + funnyYCode, c->srcFormat, formatConvBuffer, + c->lumMmx2Filter, c->lumMmx2FilterPos, pal); + lastInLumBuf++; + } + while(lastInChrBuf+1 < (chrSrcSliceY + chrSrcSliceH)) + { + uint8_t *src1= src[1]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[1]; + uint8_t *src2= src[2]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[2]; + chrBufIndex++; + ASSERT(chrBufIndex < 2*vChrBufSize) + ASSERT(lastInChrBuf + 1 - chrSrcSliceY < chrSrcSliceH) + ASSERT(lastInChrBuf + 1 - chrSrcSliceY >= 0) + + if (!(isGray(srcFormat) || isGray(dstFormat))) + RENAME(hcscale)(chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, chrSrcW, chrXInc, + flags, canMMX2BeUsed, hChrFilter, hChrFilterPos, hChrFilterSize, + funnyUVCode, c->srcFormat, formatConvBuffer, + c->chrMmx2Filter, c->chrMmx2FilterPos, pal); + lastInChrBuf++; + } + //wrap buf index around to stay inside the ring buffer + if (lumBufIndex >= vLumBufSize) lumBufIndex-= vLumBufSize; + if (chrBufIndex >= vChrBufSize) chrBufIndex-= vChrBufSize; + break; //we can't output a dstY line so let's try with the next slice + } #ifdef HAVE_MMX - b5Dither= dither8[dstY&1]; - g6Dither= dither4[dstY&1]; - g5Dither= dither8[dstY&1]; - r5Dither= dither8[(dstY+1)&1]; -#endif - if(dstY < dstH-2) - { - int16_t **lumSrcPtr= lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize; - int16_t **chrSrcPtr= chrPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; + b5Dither= ff_dither8[dstY&1]; + g6Dither= ff_dither4[dstY&1]; + g5Dither= ff_dither8[dstY&1]; + r5Dither= ff_dither8[(dstY+1)&1]; +#endif + if (dstY < dstH-2) + { + int16_t **lumSrcPtr= lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize; + int16_t **chrSrcPtr= chrPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; #ifdef HAVE_MMX - int i; - if(flags & SWS_ACCURATE_RND){ - for(i=0; i1)]; - lumMmxFilter[2*i+2]= - lumMmxFilter[2*i+3]= vLumFilter[dstY*vLumFilterSize + i ] - + (vLumFilterSize>1 ? vLumFilter[dstY*vLumFilterSize + i + 1]<<16 : 0); - } - for(i=0; i1)]; - chrMmxFilter[2*i+2]= - chrMmxFilter[2*i+3]= vChrFilter[chrDstY*vChrFilterSize + i ] - + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1]<<16 : 0); - } - }else{ - for(i=0; i> 32; - lumMmxFilter[4*i+2]= - lumMmxFilter[4*i+3]= - ((uint16_t)vLumFilter[dstY*vLumFilterSize + i])*0x10001; - } - for(i=0; i> 32; - chrMmxFilter[4*i+2]= - chrMmxFilter[4*i+3]= - ((uint16_t)vChrFilter[chrDstY*vChrFilterSize + i])*0x10001; - } + int i; + if (flags & SWS_ACCURATE_RND){ + for (i=0; i1)]; + lumMmxFilter[2*i+2]= + lumMmxFilter[2*i+3]= vLumFilter[dstY*vLumFilterSize + i ] + + (vLumFilterSize>1 ? vLumFilter[dstY*vLumFilterSize + i + 1]<<16 : 0); + } + for (i=0; i1)]; + chrMmxFilter[2*i+2]= + chrMmxFilter[2*i+3]= vChrFilter[chrDstY*vChrFilterSize + i ] + + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1]<<16 : 0); + } + }else{ + for (i=0; i> 32; + lumMmxFilter[4*i+2]= + lumMmxFilter[4*i+3]= + ((uint16_t)vLumFilter[dstY*vLumFilterSize + i])*0x10001; + } + for (i=0; i> 32; + chrMmxFilter[4*i+2]= + chrMmxFilter[4*i+3]= + ((uint16_t)vChrFilter[chrDstY*vChrFilterSize + i])*0x10001; } + } #endif - if(dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21){ - const int chrSkipMask= (1<chrDstVSubSample)-1; - if(dstY&chrSkipMask) uDest= NULL; //FIXME split functions in lumi / chromi - RENAME(yuv2nv12X)(c, - vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, - vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, - dest, uDest, dstW, chrDstW, dstFormat); - } - else if(isPlanarYUV(dstFormat) || isGray(dstFormat)) //YV12 like - { - const int chrSkipMask= (1<chrDstVSubSample)-1; - if((dstY&chrSkipMask) || isGray(dstFormat)) uDest=vDest= NULL; //FIXME split functions in lumi / chromi - if(vLumFilterSize == 1 && vChrFilterSize == 1) // Unscaled YV12 - { - int16_t *lumBuf = lumPixBuf[0]; - int16_t *chrBuf= chrPixBuf[0]; - RENAME(yuv2yuv1)(lumBuf, chrBuf, dest, uDest, vDest, dstW, chrDstW); - } - else //General YV12 - { - RENAME(yuv2yuvX)(c, - vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, - vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, - dest, uDest, vDest, dstW, chrDstW); - } - } - else - { - ASSERT(lumSrcPtr + vLumFilterSize - 1 < lumPixBuf + vLumBufSize*2); - ASSERT(chrSrcPtr + vChrFilterSize - 1 < chrPixBuf + vChrBufSize*2); - if(vLumFilterSize == 1 && vChrFilterSize == 2) //Unscaled RGB - { - int chrAlpha= vChrFilter[2*dstY+1]; - RENAME(yuv2packed1)(c, *lumSrcPtr, *chrSrcPtr, *(chrSrcPtr+1), - dest, dstW, chrAlpha, dstFormat, flags, dstY); - } - else if(vLumFilterSize == 2 && vChrFilterSize == 2) //BiLinear Upscale RGB - { - int lumAlpha= vLumFilter[2*dstY+1]; - int chrAlpha= vChrFilter[2*dstY+1]; - lumMmxFilter[2]= - lumMmxFilter[3]= vLumFilter[2*dstY ]*0x10001; - chrMmxFilter[2]= - chrMmxFilter[3]= vChrFilter[2*chrDstY]*0x10001; - RENAME(yuv2packed2)(c, *lumSrcPtr, *(lumSrcPtr+1), *chrSrcPtr, *(chrSrcPtr+1), - dest, dstW, lumAlpha, chrAlpha, dstY); - } - else //General RGB - { - RENAME(yuv2packedX)(c, - vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize, - vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, - dest, dstW, dstY); - } - } + if (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21){ + const int chrSkipMask= (1<chrDstVSubSample)-1; + if (dstY&chrSkipMask) uDest= NULL; //FIXME split functions in lumi / chromi + RENAME(yuv2nv12X)(c, + vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, + vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, + dest, uDest, dstW, chrDstW, dstFormat); + } + else if (isPlanarYUV(dstFormat) || isGray(dstFormat)) //YV12 like + { + const int chrSkipMask= (1<chrDstVSubSample)-1; + if ((dstY&chrSkipMask) || isGray(dstFormat)) uDest=vDest= NULL; //FIXME split functions in lumi / chromi + if (vLumFilterSize == 1 && vChrFilterSize == 1) // Unscaled YV12 + { + int16_t *lumBuf = lumPixBuf[0]; + int16_t *chrBuf= chrPixBuf[0]; + RENAME(yuv2yuv1)(lumBuf, chrBuf, dest, uDest, vDest, dstW, chrDstW); + } + else //General YV12 + { + RENAME(yuv2yuvX)(c, + vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, + vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, + dest, uDest, vDest, dstW, chrDstW); + } + } + else + { + ASSERT(lumSrcPtr + vLumFilterSize - 1 < lumPixBuf + vLumBufSize*2); + ASSERT(chrSrcPtr + vChrFilterSize - 1 < chrPixBuf + vChrBufSize*2); + if (vLumFilterSize == 1 && vChrFilterSize == 2) //Unscaled RGB + { + int chrAlpha= vChrFilter[2*dstY+1]; + RENAME(yuv2packed1)(c, *lumSrcPtr, *chrSrcPtr, *(chrSrcPtr+1), + dest, dstW, chrAlpha, dstFormat, flags, dstY); + } + else if (vLumFilterSize == 2 && vChrFilterSize == 2) //BiLinear Upscale RGB + { + int lumAlpha= vLumFilter[2*dstY+1]; + int chrAlpha= vChrFilter[2*dstY+1]; + lumMmxFilter[2]= + lumMmxFilter[3]= vLumFilter[2*dstY ]*0x10001; + chrMmxFilter[2]= + chrMmxFilter[3]= vChrFilter[2*chrDstY]*0x10001; + RENAME(yuv2packed2)(c, *lumSrcPtr, *(lumSrcPtr+1), *chrSrcPtr, *(chrSrcPtr+1), + dest, dstW, lumAlpha, chrAlpha, dstY); + } + else //General RGB + { + RENAME(yuv2packedX)(c, + vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize, + vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, + dest, dstW, dstY); + } } - else // hmm looks like we can't use MMX here without overwriting this array's tail - { - int16_t **lumSrcPtr= lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize; - int16_t **chrSrcPtr= chrPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; - if(dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21){ - const int chrSkipMask= (1<chrDstVSubSample)-1; - if(dstY&chrSkipMask) uDest= NULL; //FIXME split functions in lumi / chromi - yuv2nv12XinC( - vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, - vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, - dest, uDest, dstW, chrDstW, dstFormat); - } - else if(isPlanarYUV(dstFormat) || isGray(dstFormat)) //YV12 - { - const int chrSkipMask= (1<chrDstVSubSample)-1; - if((dstY&chrSkipMask) || isGray(dstFormat)) uDest=vDest= NULL; //FIXME split functions in lumi / chromi - yuv2yuvXinC( - vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, - vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, - dest, uDest, vDest, dstW, chrDstW); - } - else - { - ASSERT(lumSrcPtr + vLumFilterSize - 1 < lumPixBuf + vLumBufSize*2); - ASSERT(chrSrcPtr + vChrFilterSize - 1 < chrPixBuf + vChrBufSize*2); - yuv2packedXinC(c, - vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize, - vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, - dest, dstW, dstY); - } - } - } + } + else // hmm looks like we can't use MMX here without overwriting this array's tail + { + int16_t **lumSrcPtr= lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize; + int16_t **chrSrcPtr= chrPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; + if (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21){ + const int chrSkipMask= (1<chrDstVSubSample)-1; + if (dstY&chrSkipMask) uDest= NULL; //FIXME split functions in lumi / chromi + yuv2nv12XinC( + vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, + vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, + dest, uDest, dstW, chrDstW, dstFormat); + } + else if (isPlanarYUV(dstFormat) || isGray(dstFormat)) //YV12 + { + const int chrSkipMask= (1<chrDstVSubSample)-1; + if ((dstY&chrSkipMask) || isGray(dstFormat)) uDest=vDest= NULL; //FIXME split functions in lumi / chromi + yuv2yuvXinC( + vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, + vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, + dest, uDest, vDest, dstW, chrDstW); + } + else + { + ASSERT(lumSrcPtr + vLumFilterSize - 1 < lumPixBuf + vLumBufSize*2); + ASSERT(chrSrcPtr + vChrFilterSize - 1 < chrPixBuf + vChrBufSize*2); + yuv2packedXinC(c, + vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize, + vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, + dest, dstW, dstY); + } + } + } #ifdef HAVE_MMX - __asm __volatile(SFENCE:::"memory"); - __asm __volatile(EMMS:::"memory"); + asm volatile(SFENCE:::"memory"); + asm volatile(EMMS:::"memory"); #endif - /* store changed local vars back in the context */ - c->dstY= dstY; - c->lumBufIndex= lumBufIndex; - c->chrBufIndex= chrBufIndex; - c->lastInLumBuf= lastInLumBuf; - c->lastInChrBuf= lastInChrBuf; - - return dstY - lastDstY; + /* store changed local vars back in the context */ + c->dstY= dstY; + c->lumBufIndex= lumBufIndex; + c->chrBufIndex= chrBufIndex; + c->lastInLumBuf= lastInLumBuf; + c->lastInChrBuf= lastInChrBuf; + + return dstY - lastDstY; } diff --git a/contrib/ffmpeg/libswscale/yuv2rgb.c b/contrib/ffmpeg/libswscale/yuv2rgb.c index af7f86f40..8b4622311 100644 --- a/contrib/ffmpeg/libswscale/yuv2rgb.c +++ b/contrib/ffmpeg/libswscale/yuv2rgb.c @@ -1,14 +1,17 @@ /* - * yuv2rgb.c, Software YUV to RGB coverter + * yuv2rgb.c, Software YUV to RGB converter * * Copyright (C) 1999, Aaron Holtzman - * All Rights Reserved. * * Functions broken out from display_x11.c and several new modes - * added by Håkan Hjort + * added by HÃ¥kan Hjort * * 15 & 16 bpp support by Franck Sicard * + * MMX/MMX2 template stuff (needed for fast movntq support), + * 1,4,8bpp support and context / deglobalize stuff + * by Michael Niedermayer (michaelni@gmx.at) + * * This file is part of mpeg2dec, a free MPEG-2 video decoder * * mpeg2dec is free software; you can redistribute it and/or modify @@ -24,10 +27,6 @@ * You should have received a copy of the GNU General Public License * along with mpeg2dec; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * MMX/MMX2 Template stuff from Michael Niedermayer (michaelni@gmx.at) (needed for fast movntq support) - * 1,4,8bpp support by Michael Niedermayer (michaelni@gmx.at) - * context / deglobalize stuff by Michael Niedermayer */ #include @@ -40,6 +39,10 @@ #include "swscale.h" #include "swscale_internal.h" +#ifdef HAVE_VIS +#include "yuv2rgb_vis.c" +#endif + #ifdef HAVE_MLIB #include "yuv2rgb_mlib.c" #endif @@ -156,13 +159,9 @@ const uint8_t __attribute__((aligned(8))) dither_8x8_220[8][8]={ #ifdef HAVE_MMX /* hope these constant values are cache line aligned */ -static uint64_t attribute_used __attribute__((aligned(8))) mmx_00ffw = 0x00ff00ff00ff00ffULL; -static uint64_t attribute_used __attribute__((aligned(8))) mmx_redmask = 0xf8f8f8f8f8f8f8f8ULL; -static uint64_t attribute_used __attribute__((aligned(8))) mmx_grnmask = 0xfcfcfcfcfcfcfcfcULL; - -static uint64_t attribute_used __attribute__((aligned(8))) M24A= 0x00FF0000FF0000FFULL; -static uint64_t attribute_used __attribute__((aligned(8))) M24B= 0xFF0000FF0000FF00ULL; -static uint64_t attribute_used __attribute__((aligned(8))) M24C= 0x0000FF0000FF0000ULL; +DECLARE_ASM_CONST(8, uint64_t, mmx_00ffw) = 0x00ff00ff00ff00ffULL; +DECLARE_ASM_CONST(8, uint64_t, mmx_redmask) = 0xf8f8f8f8f8f8f8f8ULL; +DECLARE_ASM_CONST(8, uint64_t, mmx_grnmask) = 0xfcfcfcfcfcfcfcfcULL; // the volatile is required because gcc otherwise optimizes some writes away not knowing that these // are read in the asm block @@ -171,14 +170,6 @@ static volatile uint64_t attribute_used __attribute__((aligned(8))) g5Dither; static volatile uint64_t attribute_used __attribute__((aligned(8))) g6Dither; static volatile uint64_t attribute_used __attribute__((aligned(8))) r5Dither; -static uint64_t __attribute__((aligned(8))) dither4[2]={ - 0x0103010301030103LL, - 0x0200020002000200LL,}; - -static uint64_t __attribute__((aligned(8))) dither8[2]={ - 0x0602060206020602LL, - 0x0004000400040004LL,}; - #undef HAVE_MMX //MMX versions @@ -210,404 +201,452 @@ const int32_t Inverse_Table_6_9[8][4] = { {117579, 136230, 16907, 35559} /* SMPTE 240M (1987) */ }; -#define RGB(i) \ - U = pu[i]; \ - V = pv[i]; \ - r = (void *)c->table_rV[V]; \ - g = (void *)(c->table_gU[U] + c->table_gV[V]); \ - b = (void *)c->table_bU[U]; - -#define DST1(i) \ - Y = py_1[2*i]; \ - dst_1[2*i] = r[Y] + g[Y] + b[Y]; \ - Y = py_1[2*i+1]; \ - dst_1[2*i+1] = r[Y] + g[Y] + b[Y]; - -#define DST2(i) \ - Y = py_2[2*i]; \ - dst_2[2*i] = r[Y] + g[Y] + b[Y]; \ - Y = py_2[2*i+1]; \ - dst_2[2*i+1] = r[Y] + g[Y] + b[Y]; - -#define DST1RGB(i) \ - Y = py_1[2*i]; \ - dst_1[6*i] = r[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = b[Y]; \ - Y = py_1[2*i+1]; \ - dst_1[6*i+3] = r[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = b[Y]; - -#define DST2RGB(i) \ - Y = py_2[2*i]; \ - dst_2[6*i] = r[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = b[Y]; \ - Y = py_2[2*i+1]; \ - dst_2[6*i+3] = r[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = b[Y]; - -#define DST1BGR(i) \ - Y = py_1[2*i]; \ - dst_1[6*i] = b[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = r[Y]; \ - Y = py_1[2*i+1]; \ - dst_1[6*i+3] = b[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = r[Y]; - -#define DST2BGR(i) \ - Y = py_2[2*i]; \ - dst_2[6*i] = b[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = r[Y]; \ - Y = py_2[2*i+1]; \ - dst_2[6*i+3] = b[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = r[Y]; +#define RGB(i) \ + U = pu[i]; \ + V = pv[i]; \ + r = (void *)c->table_rV[V]; \ + g = (void *)(c->table_gU[U] + c->table_gV[V]); \ + b = (void *)c->table_bU[U]; + +#define DST1(i) \ + Y = py_1[2*i]; \ + dst_1[2*i] = r[Y] + g[Y] + b[Y]; \ + Y = py_1[2*i+1]; \ + dst_1[2*i+1] = r[Y] + g[Y] + b[Y]; + +#define DST2(i) \ + Y = py_2[2*i]; \ + dst_2[2*i] = r[Y] + g[Y] + b[Y]; \ + Y = py_2[2*i+1]; \ + dst_2[2*i+1] = r[Y] + g[Y] + b[Y]; + +#define DST1RGB(i) \ + Y = py_1[2*i]; \ + dst_1[6*i] = r[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = b[Y]; \ + Y = py_1[2*i+1]; \ + dst_1[6*i+3] = r[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = b[Y]; + +#define DST2RGB(i) \ + Y = py_2[2*i]; \ + dst_2[6*i] = r[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = b[Y]; \ + Y = py_2[2*i+1]; \ + dst_2[6*i+3] = r[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = b[Y]; + +#define DST1BGR(i) \ + Y = py_1[2*i]; \ + dst_1[6*i] = b[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = r[Y]; \ + Y = py_1[2*i+1]; \ + dst_1[6*i+3] = b[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = r[Y]; + +#define DST2BGR(i) \ + Y = py_2[2*i]; \ + dst_2[6*i] = b[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = r[Y]; \ + Y = py_2[2*i+1]; \ + dst_2[6*i+3] = b[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = r[Y]; #define PROLOG(func_name, dst_type) \ static int func_name(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, \ - int srcSliceH, uint8_t* dst[], int dstStride[]){\ + int srcSliceH, uint8_t* dst[], int dstStride[]){\ int y;\ \ - if(c->srcFormat == PIX_FMT_YUV422P){\ - srcStride[1] *= 2;\ - srcStride[2] *= 2;\ + if (c->srcFormat == PIX_FMT_YUV422P){\ + srcStride[1] *= 2;\ + srcStride[2] *= 2;\ }\ - for(y=0; y>1)*srcStride[1];\ - uint8_t *pv= src[2] + (y>>1)*srcStride[2];\ - unsigned int h_size= c->dstW>>3;\ - while (h_size--) {\ - int attribute_unused U, V;\ - int Y;\ - -#define EPILOG(dst_delta)\ - pu += 4;\ - pv += 4;\ - py_1 += 8;\ - py_2 += 8;\ - dst_1 += dst_delta;\ - dst_2 += dst_delta;\ - }\ + for (y=0; y>1)*srcStride[1];\ + uint8_t *pv= src[2] + (y>>1)*srcStride[2];\ + unsigned int h_size= c->dstW>>3;\ + while (h_size--) {\ + int av_unused U, V;\ + int Y;\ + +#define EPILOG1(dst_delta)\ + pu += 4;\ + pv += 4;\ + py_1 += 8;\ + py_2 += 8;\ + dst_1 += dst_delta;\ + dst_2 += dst_delta;\ + }\ + if (c->dstW & 4) {\ + int av_unused U, V;\ + int Y;\ + +#define EPILOG2()\ + }\ }\ return srcSliceH;\ } -PROLOG(yuv2rgb_c_32, uint32_t) - RGB(0); - DST1(0); - DST2(0); - - RGB(1); - DST2(1); - DST1(1); - - RGB(2); - DST1(2); - DST2(2); +#define EPILOG(dst_delta)\ + EPILOG1(dst_delta)\ + EPILOG2() - RGB(3); - DST2(3); - DST1(3); -EPILOG(8) +PROLOG(yuv2rgb_c_32, uint32_t) + RGB(0); + DST1(0); + DST2(0); + + RGB(1); + DST2(1); + DST1(1); + + RGB(2); + DST1(2); + DST2(2); + + RGB(3); + DST2(3); + DST1(3); +EPILOG1(8) + RGB(0); + DST1(0); + DST2(0); + + RGB(1); + DST2(1); + DST1(1); +EPILOG2() PROLOG(yuv2rgb_c_24_rgb, uint8_t) - RGB(0); - DST1RGB(0); - DST2RGB(0); - - RGB(1); - DST2RGB(1); - DST1RGB(1); - - RGB(2); - DST1RGB(2); - DST2RGB(2); - - RGB(3); - DST2RGB(3); - DST1RGB(3); -EPILOG(24) + RGB(0); + DST1RGB(0); + DST2RGB(0); + + RGB(1); + DST2RGB(1); + DST1RGB(1); + + RGB(2); + DST1RGB(2); + DST2RGB(2); + + RGB(3); + DST2RGB(3); + DST1RGB(3); +EPILOG1(24) + RGB(0); + DST1RGB(0); + DST2RGB(0); + + RGB(1); + DST2RGB(1); + DST1RGB(1); +EPILOG2() // only trivial mods from yuv2rgb_c_24_rgb PROLOG(yuv2rgb_c_24_bgr, uint8_t) - RGB(0); - DST1BGR(0); - DST2BGR(0); - - RGB(1); - DST2BGR(1); - DST1BGR(1); - - RGB(2); - DST1BGR(2); - DST2BGR(2); - - RGB(3); - DST2BGR(3); - DST1BGR(3); -EPILOG(24) + RGB(0); + DST1BGR(0); + DST2BGR(0); + + RGB(1); + DST2BGR(1); + DST1BGR(1); + + RGB(2); + DST1BGR(2); + DST2BGR(2); + + RGB(3); + DST2BGR(3); + DST1BGR(3); +EPILOG1(24) + RGB(0); + DST1BGR(0); + DST2BGR(0); + + RGB(1); + DST2BGR(1); + DST1BGR(1); +EPILOG2() // This is exactly the same code as yuv2rgb_c_32 except for the types of // r, g, b, dst_1, dst_2 PROLOG(yuv2rgb_c_16, uint16_t) - RGB(0); - DST1(0); - DST2(0); + RGB(0); + DST1(0); + DST2(0); - RGB(1); - DST2(1); - DST1(1); + RGB(1); + DST2(1); + DST1(1); - RGB(2); - DST1(2); - DST2(2); + RGB(2); + DST1(2); + DST2(2); - RGB(3); - DST2(3); - DST1(3); + RGB(3); + DST2(3); + DST1(3); EPILOG(8) // This is exactly the same code as yuv2rgb_c_32 except for the types of // r, g, b, dst_1, dst_2 PROLOG(yuv2rgb_c_8, uint8_t) - RGB(0); - DST1(0); - DST2(0); + RGB(0); + DST1(0); + DST2(0); - RGB(1); - DST2(1); - DST1(1); + RGB(1); + DST2(1); + DST1(1); - RGB(2); - DST1(2); - DST2(2); + RGB(2); + DST1(2); + DST2(2); - RGB(3); - DST2(3); - DST1(3); + RGB(3); + DST2(3); + DST1(3); EPILOG(8) // r, g, b, dst_1, dst_2 PROLOG(yuv2rgb_c_8_ordered_dither, uint8_t) - const uint8_t *d32= dither_8x8_32[y&7]; - const uint8_t *d64= dither_8x8_73[y&7]; -#define DST1bpp8(i,o) \ - Y = py_1[2*i]; \ - dst_1[2*i] = r[Y+d32[0+o]] + g[Y+d32[0+o]] + b[Y+d64[0+o]]; \ - Y = py_1[2*i+1]; \ - dst_1[2*i+1] = r[Y+d32[1+o]] + g[Y+d32[1+o]] + b[Y+d64[1+o]]; - -#define DST2bpp8(i,o) \ - Y = py_2[2*i]; \ - dst_2[2*i] = r[Y+d32[8+o]] + g[Y+d32[8+o]] + b[Y+d64[8+o]]; \ - Y = py_2[2*i+1]; \ - dst_2[2*i+1] = r[Y+d32[9+o]] + g[Y+d32[9+o]] + b[Y+d64[9+o]]; - - - RGB(0); - DST1bpp8(0,0); - DST2bpp8(0,0); - - RGB(1); - DST2bpp8(1,2); - DST1bpp8(1,2); - - RGB(2); - DST1bpp8(2,4); - DST2bpp8(2,4); - - RGB(3); - DST2bpp8(3,6); - DST1bpp8(3,6); + const uint8_t *d32= dither_8x8_32[y&7]; + const uint8_t *d64= dither_8x8_73[y&7]; +#define DST1bpp8(i,o) \ + Y = py_1[2*i]; \ + dst_1[2*i] = r[Y+d32[0+o]] + g[Y+d32[0+o]] + b[Y+d64[0+o]]; \ + Y = py_1[2*i+1]; \ + dst_1[2*i+1] = r[Y+d32[1+o]] + g[Y+d32[1+o]] + b[Y+d64[1+o]]; + +#define DST2bpp8(i,o) \ + Y = py_2[2*i]; \ + dst_2[2*i] = r[Y+d32[8+o]] + g[Y+d32[8+o]] + b[Y+d64[8+o]]; \ + Y = py_2[2*i+1]; \ + dst_2[2*i+1] = r[Y+d32[9+o]] + g[Y+d32[9+o]] + b[Y+d64[9+o]]; + + + RGB(0); + DST1bpp8(0,0); + DST2bpp8(0,0); + + RGB(1); + DST2bpp8(1,2); + DST1bpp8(1,2); + + RGB(2); + DST1bpp8(2,4); + DST2bpp8(2,4); + + RGB(3); + DST2bpp8(3,6); + DST1bpp8(3,6); EPILOG(8) // This is exactly the same code as yuv2rgb_c_32 except for the types of // r, g, b, dst_1, dst_2 PROLOG(yuv2rgb_c_4, uint8_t) - int acc; -#define DST1_4(i) \ - Y = py_1[2*i]; \ - acc = r[Y] + g[Y] + b[Y]; \ - Y = py_1[2*i+1]; \ - acc |= (r[Y] + g[Y] + b[Y])<<4;\ - dst_1[i] = acc; - -#define DST2_4(i) \ - Y = py_2[2*i]; \ - acc = r[Y] + g[Y] + b[Y]; \ - Y = py_2[2*i+1]; \ - acc |= (r[Y] + g[Y] + b[Y])<<4;\ - dst_2[i] = acc; - - RGB(0); - DST1_4(0); - DST2_4(0); - - RGB(1); - DST2_4(1); - DST1_4(1); - - RGB(2); - DST1_4(2); - DST2_4(2); - - RGB(3); - DST2_4(3); - DST1_4(3); + int acc; +#define DST1_4(i) \ + Y = py_1[2*i]; \ + acc = r[Y] + g[Y] + b[Y]; \ + Y = py_1[2*i+1]; \ + acc |= (r[Y] + g[Y] + b[Y])<<4; \ + dst_1[i] = acc; + +#define DST2_4(i) \ + Y = py_2[2*i]; \ + acc = r[Y] + g[Y] + b[Y]; \ + Y = py_2[2*i+1]; \ + acc |= (r[Y] + g[Y] + b[Y])<<4; \ + dst_2[i] = acc; + + RGB(0); + DST1_4(0); + DST2_4(0); + + RGB(1); + DST2_4(1); + DST1_4(1); + + RGB(2); + DST1_4(2); + DST2_4(2); + + RGB(3); + DST2_4(3); + DST1_4(3); EPILOG(4) PROLOG(yuv2rgb_c_4_ordered_dither, uint8_t) - const uint8_t *d64= dither_8x8_73[y&7]; - const uint8_t *d128=dither_8x8_220[y&7]; - int acc; - -#define DST1bpp4(i,o) \ - Y = py_1[2*i]; \ - acc = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \ - Y = py_1[2*i+1]; \ - acc |= (r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]])<<4;\ - dst_1[i]= acc; - -#define DST2bpp4(i,o) \ - Y = py_2[2*i]; \ - acc = r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]]; \ - Y = py_2[2*i+1]; \ - acc |= (r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]])<<4;\ - dst_2[i]= acc; - - - RGB(0); - DST1bpp4(0,0); - DST2bpp4(0,0); - - RGB(1); - DST2bpp4(1,2); - DST1bpp4(1,2); - - RGB(2); - DST1bpp4(2,4); - DST2bpp4(2,4); - - RGB(3); - DST2bpp4(3,6); - DST1bpp4(3,6); + const uint8_t *d64= dither_8x8_73[y&7]; + const uint8_t *d128=dither_8x8_220[y&7]; + int acc; + +#define DST1bpp4(i,o) \ + Y = py_1[2*i]; \ + acc = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \ + Y = py_1[2*i+1]; \ + acc |= (r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]])<<4; \ + dst_1[i]= acc; + +#define DST2bpp4(i,o) \ + Y = py_2[2*i]; \ + acc = r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]]; \ + Y = py_2[2*i+1]; \ + acc |= (r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]])<<4; \ + dst_2[i]= acc; + + + RGB(0); + DST1bpp4(0,0); + DST2bpp4(0,0); + + RGB(1); + DST2bpp4(1,2); + DST1bpp4(1,2); + + RGB(2); + DST1bpp4(2,4); + DST2bpp4(2,4); + + RGB(3); + DST2bpp4(3,6); + DST1bpp4(3,6); EPILOG(4) // This is exactly the same code as yuv2rgb_c_32 except for the types of // r, g, b, dst_1, dst_2 PROLOG(yuv2rgb_c_4b, uint8_t) - RGB(0); - DST1(0); - DST2(0); + RGB(0); + DST1(0); + DST2(0); - RGB(1); - DST2(1); - DST1(1); + RGB(1); + DST2(1); + DST1(1); - RGB(2); - DST1(2); - DST2(2); + RGB(2); + DST1(2); + DST2(2); - RGB(3); - DST2(3); - DST1(3); + RGB(3); + DST2(3); + DST1(3); EPILOG(8) PROLOG(yuv2rgb_c_4b_ordered_dither, uint8_t) - const uint8_t *d64= dither_8x8_73[y&7]; - const uint8_t *d128=dither_8x8_220[y&7]; + const uint8_t *d64= dither_8x8_73[y&7]; + const uint8_t *d128=dither_8x8_220[y&7]; -#define DST1bpp4b(i,o) \ - Y = py_1[2*i]; \ - dst_1[2*i] = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \ - Y = py_1[2*i+1]; \ - dst_1[2*i+1] = r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]]; +#define DST1bpp4b(i,o) \ + Y = py_1[2*i]; \ + dst_1[2*i] = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]]; \ + Y = py_1[2*i+1]; \ + dst_1[2*i+1] = r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]]; -#define DST2bpp4b(i,o) \ - Y = py_2[2*i]; \ - dst_2[2*i] = r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]]; \ - Y = py_2[2*i+1]; \ - dst_2[2*i+1] = r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]]; +#define DST2bpp4b(i,o) \ + Y = py_2[2*i]; \ + dst_2[2*i] = r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]]; \ + Y = py_2[2*i+1]; \ + dst_2[2*i+1] = r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]]; - RGB(0); - DST1bpp4b(0,0); - DST2bpp4b(0,0); + RGB(0); + DST1bpp4b(0,0); + DST2bpp4b(0,0); - RGB(1); - DST2bpp4b(1,2); - DST1bpp4b(1,2); + RGB(1); + DST2bpp4b(1,2); + DST1bpp4b(1,2); - RGB(2); - DST1bpp4b(2,4); - DST2bpp4b(2,4); + RGB(2); + DST1bpp4b(2,4); + DST2bpp4b(2,4); - RGB(3); - DST2bpp4b(3,6); - DST1bpp4b(3,6); + RGB(3); + DST2bpp4b(3,6); + DST1bpp4b(3,6); EPILOG(8) PROLOG(yuv2rgb_c_1_ordered_dither, uint8_t) - const uint8_t *d128=dither_8x8_220[y&7]; - char out_1=0, out_2=0; - g= c->table_gU[128] + c->table_gV[128]; - -#define DST1bpp1(i,o) \ - Y = py_1[2*i]; \ - out_1+= out_1 + g[Y+d128[0+o]]; \ - Y = py_1[2*i+1]; \ - out_1+= out_1 + g[Y+d128[1+o]]; - -#define DST2bpp1(i,o) \ - Y = py_2[2*i]; \ - out_2+= out_2 + g[Y+d128[8+o]]; \ - Y = py_2[2*i+1]; \ - out_2+= out_2 + g[Y+d128[9+o]]; - - DST1bpp1(0,0); - DST2bpp1(0,0); - - DST2bpp1(1,2); - DST1bpp1(1,2); - - DST1bpp1(2,4); - DST2bpp1(2,4); - - DST2bpp1(3,6); - DST1bpp1(3,6); - - dst_1[0]= out_1; - dst_2[0]= out_2; + const uint8_t *d128=dither_8x8_220[y&7]; + char out_1=0, out_2=0; + g= c->table_gU[128] + c->table_gV[128]; + +#define DST1bpp1(i,o) \ + Y = py_1[2*i]; \ + out_1+= out_1 + g[Y+d128[0+o]]; \ + Y = py_1[2*i+1]; \ + out_1+= out_1 + g[Y+d128[1+o]]; + +#define DST2bpp1(i,o) \ + Y = py_2[2*i]; \ + out_2+= out_2 + g[Y+d128[8+o]]; \ + Y = py_2[2*i+1]; \ + out_2+= out_2 + g[Y+d128[9+o]]; + + DST1bpp1(0,0); + DST2bpp1(0,0); + + DST2bpp1(1,2); + DST1bpp1(1,2); + + DST1bpp1(2,4); + DST2bpp1(2,4); + + DST2bpp1(3,6); + DST1bpp1(3,6); + + dst_1[0]= out_1; + dst_2[0]= out_2; EPILOG(1) SwsFunc yuv2rgb_get_func_ptr (SwsContext *c) { #if defined(HAVE_MMX2) || defined(HAVE_MMX) - if(c->flags & SWS_CPU_CAPS_MMX2){ - switch(c->dstFormat){ - case PIX_FMT_RGB32: return yuv420_rgb32_MMX2; - case PIX_FMT_BGR24: return yuv420_rgb24_MMX2; - case PIX_FMT_BGR565: return yuv420_rgb16_MMX2; - case PIX_FMT_BGR555: return yuv420_rgb15_MMX2; - } + if (c->flags & SWS_CPU_CAPS_MMX2){ + switch(c->dstFormat){ + case PIX_FMT_RGB32: return yuv420_rgb32_MMX2; + case PIX_FMT_BGR24: return yuv420_rgb24_MMX2; + case PIX_FMT_BGR565: return yuv420_rgb16_MMX2; + case PIX_FMT_BGR555: return yuv420_rgb15_MMX2; + } } - if(c->flags & SWS_CPU_CAPS_MMX){ - switch(c->dstFormat){ - case PIX_FMT_RGB32: return yuv420_rgb32_MMX; - case PIX_FMT_BGR24: return yuv420_rgb24_MMX; - case PIX_FMT_BGR565: return yuv420_rgb16_MMX; - case PIX_FMT_BGR555: return yuv420_rgb15_MMX; - } + if (c->flags & SWS_CPU_CAPS_MMX){ + switch(c->dstFormat){ + case PIX_FMT_RGB32: return yuv420_rgb32_MMX; + case PIX_FMT_BGR24: return yuv420_rgb24_MMX; + case PIX_FMT_BGR565: return yuv420_rgb16_MMX; + case PIX_FMT_BGR555: return yuv420_rgb15_MMX; + } + } +#endif +#ifdef HAVE_VIS + { + SwsFunc t= yuv2rgb_init_vis(c); + if (t) return t; } #endif #ifdef HAVE_MLIB { - SwsFunc t= yuv2rgb_init_mlib(c); - if(t) return t; + SwsFunc t= yuv2rgb_init_mlib(c); + if (t) return t; } #endif #ifdef HAVE_ALTIVEC if (c->flags & SWS_CPU_CAPS_ALTIVEC) { - SwsFunc t = yuv2rgb_init_altivec(c); - if(t) return t; + SwsFunc t = yuv2rgb_init_altivec(c); + if (t) return t; + } +#endif + +#ifdef ARCH_BFIN + if (c->flags & SWS_CPU_CAPS_BFIN) + { + SwsFunc t = ff_bfin_yuv2rgb_get_func_ptr (c); + if (t) return t; } #endif @@ -630,7 +669,7 @@ SwsFunc yuv2rgb_get_func_ptr (SwsContext *c) case PIX_FMT_BGR4_BYTE: return yuv2rgb_c_4b_ordered_dither; case PIX_FMT_MONOBLACK: return yuv2rgb_c_1_ordered_dither; default: - assert(0); + assert(0); } return NULL; } @@ -638,13 +677,13 @@ SwsFunc yuv2rgb_get_func_ptr (SwsContext *c) static int div_round (int dividend, int divisor) { if (dividend > 0) - return (dividend + (divisor>>1)) / divisor; + return (dividend + (divisor>>1)) / divisor; else - return -((-dividend + (divisor>>1)) / divisor); + return -((-dividend + (divisor>>1)) / divisor); } int yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation) -{ +{ const int isRgb = isBGR(c->dstFormat); const int bpp = fmt_depth(c->dstFormat); int i; @@ -667,16 +706,16 @@ int yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, int64_t oy = 0; //printf("%lld %lld %lld %lld %lld\n", cy, crv, cbu, cgu, cgv); - if(!fullRange){ - cy= (cy*255) / 219; - oy= 16<<16; + if (!fullRange){ + cy= (cy*255) / 219; + oy= 16<<16; }else{ crv= (crv*224) / 255; cbu= (cbu*224) / 255; cgu= (cgu*224) / 255; cgv= (cgv*224) / 255; } - + cy = (cy *contrast )>>16; crv= (crv*contrast * saturation)>>32; cbu= (cbu*contrast * saturation)>>32; @@ -686,163 +725,163 @@ int yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, oy -= 256*brightness; for (i = 0; i < 1024; i++) { - int j; + int j; - j= (cy*(((i - 384)<<16) - oy) + (1<<31))>>32; - j = (j < 0) ? 0 : ((j > 255) ? 255 : j); - table_Y[i] = j; + j= (cy*(((i - 384)<<16) - oy) + (1<<31))>>32; + j = (j < 0) ? 0 : ((j > 255) ? 255 : j); + table_Y[i] = j; } switch (bpp) { case 32: - table_start= table_32 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t)); + table_start= table_32 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t)); - entry_size = sizeof (uint32_t); - table_r = table_32 + 197; - table_b = table_32 + 197 + 685; - table_g = table_32 + 197 + 2*682; + entry_size = sizeof (uint32_t); + table_r = table_32 + 197; + table_b = table_32 + 197 + 685; + table_g = table_32 + 197 + 2*682; - for (i = -197; i < 256+197; i++) - ((uint32_t *)table_r)[i] = table_Y[i+384] << (isRgb ? 16 : 0); - for (i = -132; i < 256+132; i++) - ((uint32_t *)table_g)[i] = table_Y[i+384] << 8; - for (i = -232; i < 256+232; i++) - ((uint32_t *)table_b)[i] = table_Y[i+384] << (isRgb ? 0 : 16); - break; + for (i = -197; i < 256+197; i++) + ((uint32_t *)table_r)[i] = table_Y[i+384] << (isRgb ? 16 : 0); + for (i = -132; i < 256+132; i++) + ((uint32_t *)table_g)[i] = table_Y[i+384] << 8; + for (i = -232; i < 256+232; i++) + ((uint32_t *)table_b)[i] = table_Y[i+384] << (isRgb ? 0 : 16); + break; case 24: - table_start= table_8 = av_malloc ((256 + 2*232) * sizeof (uint8_t)); + table_start= table_8 = av_malloc ((256 + 2*232) * sizeof (uint8_t)); - entry_size = sizeof (uint8_t); - table_r = table_g = table_b = table_8 + 232; + entry_size = sizeof (uint8_t); + table_r = table_g = table_b = table_8 + 232; - for (i = -232; i < 256+232; i++) - ((uint8_t * )table_b)[i] = table_Y[i+384]; - break; + for (i = -232; i < 256+232; i++) + ((uint8_t * )table_b)[i] = table_Y[i+384]; + break; case 15: case 16: - table_start= table_16 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t)); + table_start= table_16 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t)); - entry_size = sizeof (uint16_t); - table_r = table_16 + 197; - table_b = table_16 + 197 + 685; - table_g = table_16 + 197 + 2*682; + entry_size = sizeof (uint16_t); + table_r = table_16 + 197; + table_b = table_16 + 197 + 685; + table_g = table_16 + 197 + 2*682; - for (i = -197; i < 256+197; i++) { - int j = table_Y[i+384] >> 3; + for (i = -197; i < 256+197; i++) { + int j = table_Y[i+384] >> 3; - if (isRgb) - j <<= ((bpp==16) ? 11 : 10); + if (isRgb) + j <<= ((bpp==16) ? 11 : 10); - ((uint16_t *)table_r)[i] = j; - } - for (i = -132; i < 256+132; i++) { - int j = table_Y[i+384] >> ((bpp==16) ? 2 : 3); + ((uint16_t *)table_r)[i] = j; + } + for (i = -132; i < 256+132; i++) { + int j = table_Y[i+384] >> ((bpp==16) ? 2 : 3); - ((uint16_t *)table_g)[i] = j << 5; - } - for (i = -232; i < 256+232; i++) { - int j = table_Y[i+384] >> 3; + ((uint16_t *)table_g)[i] = j << 5; + } + for (i = -232; i < 256+232; i++) { + int j = table_Y[i+384] >> 3; - if (!isRgb) - j <<= ((bpp==16) ? 11 : 10); + if (!isRgb) + j <<= ((bpp==16) ? 11 : 10); - ((uint16_t *)table_b)[i] = j; - } - break; + ((uint16_t *)table_b)[i] = j; + } + break; case 8: - table_start= table_332 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t)); + table_start= table_332 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t)); - entry_size = sizeof (uint8_t); - table_r = table_332 + 197; - table_b = table_332 + 197 + 685; - table_g = table_332 + 197 + 2*682; + entry_size = sizeof (uint8_t); + table_r = table_332 + 197; + table_b = table_332 + 197 + 685; + table_g = table_332 + 197 + 2*682; - for (i = -197; i < 256+197; i++) { - int j = (table_Y[i+384 - 16] + 18)/36; + for (i = -197; i < 256+197; i++) { + int j = (table_Y[i+384 - 16] + 18)/36; - if (isRgb) - j <<= 5; + if (isRgb) + j <<= 5; - ((uint8_t *)table_r)[i] = j; - } - for (i = -132; i < 256+132; i++) { - int j = (table_Y[i+384 - 16] + 18)/36; + ((uint8_t *)table_r)[i] = j; + } + for (i = -132; i < 256+132; i++) { + int j = (table_Y[i+384 - 16] + 18)/36; - if (!isRgb) - j <<= 1; + if (!isRgb) + j <<= 1; - ((uint8_t *)table_g)[i] = j << 2; - } - for (i = -232; i < 256+232; i++) { - int j = (table_Y[i+384 - 37] + 43)/85; + ((uint8_t *)table_g)[i] = j << 2; + } + for (i = -232; i < 256+232; i++) { + int j = (table_Y[i+384 - 37] + 43)/85; - if (!isRgb) - j <<= 6; + if (!isRgb) + j <<= 6; - ((uint8_t *)table_b)[i] = j; - } - break; + ((uint8_t *)table_b)[i] = j; + } + break; case 4: case 4|128: - table_start= table_121 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t)); + table_start= table_121 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t)); - entry_size = sizeof (uint8_t); - table_r = table_121 + 197; - table_b = table_121 + 197 + 685; - table_g = table_121 + 197 + 2*682; + entry_size = sizeof (uint8_t); + table_r = table_121 + 197; + table_b = table_121 + 197 + 685; + table_g = table_121 + 197 + 2*682; - for (i = -197; i < 256+197; i++) { - int j = table_Y[i+384 - 110] >> 7; + for (i = -197; i < 256+197; i++) { + int j = table_Y[i+384 - 110] >> 7; - if (isRgb) - j <<= 3; + if (isRgb) + j <<= 3; - ((uint8_t *)table_r)[i] = j; - } - for (i = -132; i < 256+132; i++) { - int j = (table_Y[i+384 - 37]+ 43)/85; + ((uint8_t *)table_r)[i] = j; + } + for (i = -132; i < 256+132; i++) { + int j = (table_Y[i+384 - 37]+ 43)/85; - ((uint8_t *)table_g)[i] = j << 1; - } - for (i = -232; i < 256+232; i++) { - int j =table_Y[i+384 - 110] >> 7; + ((uint8_t *)table_g)[i] = j << 1; + } + for (i = -232; i < 256+232; i++) { + int j =table_Y[i+384 - 110] >> 7; - if (!isRgb) - j <<= 3; + if (!isRgb) + j <<= 3; - ((uint8_t *)table_b)[i] = j; - } - break; + ((uint8_t *)table_b)[i] = j; + } + break; case 1: - table_start= table_1 = av_malloc (256*2 * sizeof (uint8_t)); + table_start= table_1 = av_malloc (256*2 * sizeof (uint8_t)); - entry_size = sizeof (uint8_t); - table_g = table_1; - table_r = table_b = NULL; + entry_size = sizeof (uint8_t); + table_g = table_1; + table_r = table_b = NULL; - for (i = 0; i < 256+256; i++) { - int j = table_Y[i + 384 - 110]>>7; + for (i = 0; i < 256+256; i++) { + int j = table_Y[i + 384 - 110]>>7; - ((uint8_t *)table_g)[i] = j; - } - break; + ((uint8_t *)table_g)[i] = j; + } + break; default: - table_start= NULL; - av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp); - //free mem? - return -1; + table_start= NULL; + av_log(c, AV_LOG_ERROR, "%ibpp not supported by yuv2rgb\n", bpp); + //free mem? + return -1; } for (i = 0; i < 256; i++) { - c->table_rV[i] = (uint8_t *)table_r + entry_size * div_round (crv * (i-128), 76309); - c->table_gU[i] = (uint8_t *)table_g + entry_size * div_round (cgu * (i-128), 76309); - c->table_gV[i] = entry_size * div_round (cgv * (i-128), 76309); - c->table_bU[i] = (uint8_t *)table_b + entry_size * div_round (cbu * (i-128), 76309); + c->table_rV[i] = (uint8_t *)table_r + entry_size * div_round (crv * (i-128), 76309); + c->table_gU[i] = (uint8_t *)table_g + entry_size * div_round (cgu * (i-128), 76309); + c->table_gV[i] = entry_size * div_round (cgv * (i-128), 76309); + c->table_bU[i] = (uint8_t *)table_b + entry_size * div_round (cbu * (i-128), 76309); } av_free(c->yuvTable); diff --git a/contrib/ffmpeg/libswscale/yuv2rgb_altivec.c b/contrib/ffmpeg/libswscale/yuv2rgb_altivec.c index 72e418e8d..ebc9a6497 100644 --- a/contrib/ffmpeg/libswscale/yuv2rgb_altivec.c +++ b/contrib/ffmpeg/libswscale/yuv2rgb_altivec.c @@ -1,7 +1,7 @@ /* marc.hoffman@analog.com March 8, 2004 - Altivec Acceleration for Color Space Conversion revision 0.2 + AltiVec acceleration for colorspace conversion revision 0.2 convert I420 YV12 to RGB in various formats, it rejects images that are not in 420 formats @@ -59,7 +59,7 @@ NOTE quartz vo driver ARGB32_to_RGB24 consumes 30% of the processor - Integrated luma prescaling adjustment for saturation/contrast/brightness adjustment. + Integrated luma prescaling adjustment for saturation/contrast/brightness adjustment. */ /* @@ -77,7 +77,7 @@ * * You should have received a copy of the GNU General Public License * along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include @@ -139,70 +139,70 @@ typedef signed char sbyte; static const vector unsigned char perm_rgb_0 = (const vector unsigned char)AVV(0x00,0x01,0x10,0x02,0x03,0x11,0x04,0x05, - 0x12,0x06,0x07,0x13,0x08,0x09,0x14,0x0a), + 0x12,0x06,0x07,0x13,0x08,0x09,0x14,0x0a), perm_rgb_1 = (const vector unsigned char)AVV(0x0b,0x15,0x0c,0x0d,0x16,0x0e,0x0f,0x17, - 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f), + 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f), perm_rgb_2 = (const vector unsigned char)AVV(0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, - 0x00,0x01,0x18,0x02,0x03,0x19,0x04,0x05), + 0x00,0x01,0x18,0x02,0x03,0x19,0x04,0x05), perm_rgb_3 = (const vector unsigned char)AVV(0x1a,0x06,0x07,0x1b,0x08,0x09,0x1c,0x0a, - 0x0b,0x1d,0x0c,0x0d,0x1e,0x0e,0x0f,0x1f); - -#define vec_merge3(x2,x1,x0,y0,y1,y2) \ -do { \ - typeof(x0) o0,o2,o3; \ - o0 = vec_mergeh (x0,x1); \ - y0 = vec_perm (o0, x2, perm_rgb_0);\ - o2 = vec_perm (o0, x2, perm_rgb_1);\ - o3 = vec_mergel (x0,x1); \ - y1 = vec_perm (o3,o2,perm_rgb_2); \ - y2 = vec_perm (o3,o2,perm_rgb_3); \ + 0x0b,0x1d,0x0c,0x0d,0x1e,0x0e,0x0f,0x1f); + +#define vec_merge3(x2,x1,x0,y0,y1,y2) \ +do { \ + typeof(x0) o0,o2,o3; \ + o0 = vec_mergeh (x0,x1); \ + y0 = vec_perm (o0, x2, perm_rgb_0); \ + o2 = vec_perm (o0, x2, perm_rgb_1); \ + o3 = vec_mergel (x0,x1); \ + y1 = vec_perm (o3,o2,perm_rgb_2); \ + y2 = vec_perm (o3,o2,perm_rgb_3); \ } while(0) -#define vec_mstbgr24(x0,x1,x2,ptr) \ -do { \ - typeof(x0) _0,_1,_2; \ - vec_merge3 (x0,x1,x2,_0,_1,_2); \ - vec_st (_0, 0, ptr++); \ - vec_st (_1, 0, ptr++); \ - vec_st (_2, 0, ptr++); \ +#define vec_mstbgr24(x0,x1,x2,ptr) \ +do { \ + typeof(x0) _0,_1,_2; \ + vec_merge3 (x0,x1,x2,_0,_1,_2); \ + vec_st (_0, 0, ptr++); \ + vec_st (_1, 0, ptr++); \ + vec_st (_2, 0, ptr++); \ } while (0); -#define vec_mstrgb24(x0,x1,x2,ptr) \ -do { \ - typeof(x0) _0,_1,_2; \ - vec_merge3 (x2,x1,x0,_0,_1,_2); \ - vec_st (_0, 0, ptr++); \ - vec_st (_1, 0, ptr++); \ - vec_st (_2, 0, ptr++); \ +#define vec_mstrgb24(x0,x1,x2,ptr) \ +do { \ + typeof(x0) _0,_1,_2; \ + vec_merge3 (x2,x1,x0,_0,_1,_2); \ + vec_st (_0, 0, ptr++); \ + vec_st (_1, 0, ptr++); \ + vec_st (_2, 0, ptr++); \ } while (0); /* pack the pixels in rgb0 format msb R lsb 0 */ -#define vec_mstrgb32(T,x0,x1,x2,x3,ptr) \ -do { \ - T _0,_1,_2,_3; \ - _0 = vec_mergeh (x0,x1); \ - _1 = vec_mergeh (x2,x3); \ - _2 = (T)vec_mergeh ((vector unsigned short)_0,(vector unsigned short)_1); \ - _3 = (T)vec_mergel ((vector unsigned short)_0,(vector unsigned short)_1); \ - vec_st (_2, 0*16, (T *)ptr); \ - vec_st (_3, 1*16, (T *)ptr); \ - _0 = vec_mergel (x0,x1); \ - _1 = vec_mergel (x2,x3); \ - _2 = (T)vec_mergeh ((vector unsigned short)_0,(vector unsigned short)_1); \ - _3 = (T)vec_mergel ((vector unsigned short)_0,(vector unsigned short)_1); \ - vec_st (_2, 2*16, (T *)ptr); \ - vec_st (_3, 3*16, (T *)ptr); \ - ptr += 4; \ +#define vec_mstrgb32(T,x0,x1,x2,x3,ptr) \ +do { \ + T _0,_1,_2,_3; \ + _0 = vec_mergeh (x0,x1); \ + _1 = vec_mergeh (x2,x3); \ + _2 = (T)vec_mergeh ((vector unsigned short)_0,(vector unsigned short)_1); \ + _3 = (T)vec_mergel ((vector unsigned short)_0,(vector unsigned short)_1); \ + vec_st (_2, 0*16, (T *)ptr); \ + vec_st (_3, 1*16, (T *)ptr); \ + _0 = vec_mergel (x0,x1); \ + _1 = vec_mergel (x2,x3); \ + _2 = (T)vec_mergeh ((vector unsigned short)_0,(vector unsigned short)_1); \ + _3 = (T)vec_mergel ((vector unsigned short)_0,(vector unsigned short)_1); \ + vec_st (_2, 2*16, (T *)ptr); \ + vec_st (_3, 3*16, (T *)ptr); \ + ptr += 4; \ } while (0); /* | 1 0 1.4021 | | Y | | 1 -0.3441 -0.7142 |x| Cb| - | 1 1.7718 0 | | Cr| + | 1 1.7718 0 | | Cr| Y: [-128 127] @@ -216,51 +216,51 @@ do { \ #define vec_unh(x) \ - (vector signed short) \ - vec_perm(x,(typeof(x))AVV(0),\ - (vector unsigned char)AVV(0x10,0x00,0x10,0x01,0x10,0x02,0x10,0x03,\ - 0x10,0x04,0x10,0x05,0x10,0x06,0x10,0x07)) + (vector signed short) \ + vec_perm(x,(typeof(x))AVV(0),\ + (vector unsigned char)AVV(0x10,0x00,0x10,0x01,0x10,0x02,0x10,0x03,\ + 0x10,0x04,0x10,0x05,0x10,0x06,0x10,0x07)) #define vec_unl(x) \ - (vector signed short) \ - vec_perm(x,(typeof(x))AVV(0),\ - (vector unsigned char)AVV(0x10,0x08,0x10,0x09,0x10,0x0A,0x10,0x0B,\ - 0x10,0x0C,0x10,0x0D,0x10,0x0E,0x10,0x0F)) + (vector signed short) \ + vec_perm(x,(typeof(x))AVV(0),\ + (vector unsigned char)AVV(0x10,0x08,0x10,0x09,0x10,0x0A,0x10,0x0B,\ + 0x10,0x0C,0x10,0x0D,0x10,0x0E,0x10,0x0F)) #define vec_clip_s16(x) \ - vec_max (vec_min (x, (vector signed short)AVV(235,235,235,235,235,235,235,235)),\ - (vector signed short)AVV(16, 16, 16, 16, 16, 16, 16, 16 )) + vec_max (vec_min (x, (vector signed short)AVV(235,235,235,235,235,235,235,235)),\ + (vector signed short)AVV( 16, 16, 16, 16, 16, 16, 16, 16)) #define vec_packclp(x,y) \ - (vector unsigned char)vec_packs \ - ((vector unsigned short)vec_max (x,(vector signed short) AVV(0)), \ - (vector unsigned short)vec_max (y,(vector signed short) AVV(0))) + (vector unsigned char)vec_packs \ + ((vector unsigned short)vec_max (x,(vector signed short) AVV(0)), \ + (vector unsigned short)vec_max (y,(vector signed short) AVV(0))) //#define out_pixels(a,b,c,ptr) vec_mstrgb32(typeof(a),((typeof (a))AVV(0)),a,a,a,ptr) static inline void cvtyuvtoRGB (SwsContext *c, - vector signed short Y, vector signed short U, vector signed short V, - vector signed short *R, vector signed short *G, vector signed short *B) + vector signed short Y, vector signed short U, vector signed short V, + vector signed short *R, vector signed short *G, vector signed short *B) { - vector signed short vx,ux,uvx; + vector signed short vx,ux,uvx; - Y = vec_mradds (Y, c->CY, c->OY); - U = vec_sub (U,(vector signed short) - vec_splat((vector signed short)AVV(128),0)); - V = vec_sub (V,(vector signed short) - vec_splat((vector signed short)AVV(128),0)); + Y = vec_mradds (Y, c->CY, c->OY); + U = vec_sub (U,(vector signed short) + vec_splat((vector signed short)AVV(128),0)); + V = vec_sub (V,(vector signed short) + vec_splat((vector signed short)AVV(128),0)); - // ux = (CBU*(u<CSHIFT)+0x4000)>>15; - ux = vec_sl (U, c->CSHIFT); - *B = vec_mradds (ux, c->CBU, Y); + // ux = (CBU*(u<CSHIFT)+0x4000)>>15; + ux = vec_sl (U, c->CSHIFT); + *B = vec_mradds (ux, c->CBU, Y); - // vx = (CRV*(v<CSHIFT)+0x4000)>>15; - vx = vec_sl (V, c->CSHIFT); - *R = vec_mradds (vx, c->CRV, Y); + // vx = (CRV*(v<CSHIFT)+0x4000)>>15; + vx = vec_sl (V, c->CSHIFT); + *R = vec_mradds (vx, c->CRV, Y); - // uvx = ((CGU*u) + (CGV*v))>>15; - uvx = vec_mradds (U, c->CGU, Y); - *G = vec_mradds (V, c->CGV, uvx); + // uvx = ((CGU*u) + (CGV*v))>>15; + uvx = vec_mradds (U, c->CGU, Y); + *G = vec_mradds (V, c->CGV, uvx); } @@ -271,164 +271,168 @@ static inline void cvtyuvtoRGB (SwsContext *c, */ -#define DEFCSP420_CVT(name,out_pixels) \ -static int altivec_##name (SwsContext *c, \ - unsigned char **in, int *instrides, \ - int srcSliceY, int srcSliceH, \ - unsigned char **oplanes, int *outstrides) \ -{ \ - int w = c->srcW; \ - int h = srcSliceH; \ - int i,j; \ - int instrides_scl[3]; \ - vector unsigned char y0,y1; \ - \ - vector signed char u,v; \ - \ - vector signed short Y0,Y1,Y2,Y3; \ - vector signed short U,V; \ - vector signed short vx,ux,uvx; \ - vector signed short vx0,ux0,uvx0; \ - vector signed short vx1,ux1,uvx1; \ - vector signed short R0,G0,B0; \ - vector signed short R1,G1,B1; \ - vector unsigned char R,G,B; \ - \ - vector unsigned char *y1ivP, *y2ivP, *uivP, *vivP; \ - vector unsigned char align_perm; \ - \ - vector signed short \ - lCY = c->CY, \ - lOY = c->OY, \ - lCRV = c->CRV, \ - lCBU = c->CBU, \ - lCGU = c->CGU, \ - lCGV = c->CGV; \ - \ - vector unsigned short lCSHIFT = c->CSHIFT; \ - \ - ubyte *y1i = in[0]; \ - ubyte *y2i = in[0]+instrides[0]; \ - ubyte *ui = in[1]; \ - ubyte *vi = in[2]; \ - \ - vector unsigned char *oute \ - = (vector unsigned char *) \ - (oplanes[0]+srcSliceY*outstrides[0]); \ - vector unsigned char *outo \ - = (vector unsigned char *) \ - (oplanes[0]+srcSliceY*outstrides[0]+outstrides[0]); \ - \ - \ - instrides_scl[0] = instrides[0]*2-w; /* the loop moves y{1,2}i by w */ \ - instrides_scl[1] = instrides[1]-w/2; /* the loop moves ui by w/2 */ \ - instrides_scl[2] = instrides[2]-w/2; /* the loop moves vi by w/2 */ \ - \ - \ - for (i=0;i>15 */ \ - ux = vec_sl (U, lCSHIFT); \ - ux = vec_mradds (ux, lCBU, (vector signed short)AVV(0)); \ - ux0 = vec_mergeh (ux,ux); \ - ux1 = vec_mergel (ux,ux); \ - \ - /* vx = (CRV*(v<>15; */ \ - vx = vec_sl (V, lCSHIFT); \ - vx = vec_mradds (vx, lCRV, (vector signed short)AVV(0)); \ - vx0 = vec_mergeh (vx,vx); \ - vx1 = vec_mergel (vx,vx); \ - \ - /* uvx = ((CGU*u) + (CGV*v))>>15 */ \ - uvx = vec_mradds (U, lCGU, (vector signed short)AVV(0)); \ - uvx = vec_mradds (V, lCGV, uvx); \ - uvx0 = vec_mergeh (uvx,uvx); \ - uvx1 = vec_mergel (uvx,uvx); \ - \ - R0 = vec_add (Y0,vx0); \ - G0 = vec_add (Y0,uvx0); \ - B0 = vec_add (Y0,ux0); \ - R1 = vec_add (Y1,vx1); \ - G1 = vec_add (Y1,uvx1); \ - B1 = vec_add (Y1,ux1); \ - \ - R = vec_packclp (R0,R1); \ - G = vec_packclp (G0,G1); \ - B = vec_packclp (B0,B1); \ - \ - out_pixels(R,G,B,oute); \ - \ - R0 = vec_add (Y2,vx0); \ - G0 = vec_add (Y2,uvx0); \ - B0 = vec_add (Y2,ux0); \ - R1 = vec_add (Y3,vx1); \ - G1 = vec_add (Y3,uvx1); \ - B1 = vec_add (Y3,ux1); \ - R = vec_packclp (R0,R1); \ - G = vec_packclp (G0,G1); \ - B = vec_packclp (B0,B1); \ - \ - \ - out_pixels(R,G,B,outo); \ - \ - y1i += 16; \ - y2i += 16; \ - ui += 8; \ - vi += 8; \ - \ - } \ - \ - outo += (outstrides[0])>>4; \ - oute += (outstrides[0])>>4; \ - \ - ui += instrides_scl[1]; \ - vi += instrides_scl[2]; \ - y1i += instrides_scl[0]; \ - y2i += instrides_scl[0]; \ - } \ - return srcSliceH; \ +#define DEFCSP420_CVT(name,out_pixels) \ +static int altivec_##name (SwsContext *c, \ + unsigned char **in, int *instrides, \ + int srcSliceY, int srcSliceH, \ + unsigned char **oplanes, int *outstrides) \ +{ \ + int w = c->srcW; \ + int h = srcSliceH; \ + int i,j; \ + int instrides_scl[3]; \ + vector unsigned char y0,y1; \ + \ + vector signed char u,v; \ + \ + vector signed short Y0,Y1,Y2,Y3; \ + vector signed short U,V; \ + vector signed short vx,ux,uvx; \ + vector signed short vx0,ux0,uvx0; \ + vector signed short vx1,ux1,uvx1; \ + vector signed short R0,G0,B0; \ + vector signed short R1,G1,B1; \ + vector unsigned char R,G,B; \ + \ + vector unsigned char *y1ivP, *y2ivP, *uivP, *vivP; \ + vector unsigned char align_perm; \ + \ + vector signed short \ + lCY = c->CY, \ + lOY = c->OY, \ + lCRV = c->CRV, \ + lCBU = c->CBU, \ + lCGU = c->CGU, \ + lCGV = c->CGV; \ + \ + vector unsigned short lCSHIFT = c->CSHIFT; \ + \ + ubyte *y1i = in[0]; \ + ubyte *y2i = in[0]+instrides[0]; \ + ubyte *ui = in[1]; \ + ubyte *vi = in[2]; \ + \ + vector unsigned char *oute \ + = (vector unsigned char *) \ + (oplanes[0]+srcSliceY*outstrides[0]); \ + vector unsigned char *outo \ + = (vector unsigned char *) \ + (oplanes[0]+srcSliceY*outstrides[0]+outstrides[0]); \ + \ + \ + instrides_scl[0] = instrides[0]*2-w; /* the loop moves y{1,2}i by w */ \ + instrides_scl[1] = instrides[1]-w/2; /* the loop moves ui by w/2 */ \ + instrides_scl[2] = instrides[2]-w/2; /* the loop moves vi by w/2 */ \ + \ + \ + for (i=0;i>15 */ \ + ux = vec_sl (U, lCSHIFT); \ + ux = vec_mradds (ux, lCBU, (vector signed short)AVV(0)); \ + ux0 = vec_mergeh (ux,ux); \ + ux1 = vec_mergel (ux,ux); \ + \ + /* vx = (CRV*(v<>15; */ \ + vx = vec_sl (V, lCSHIFT); \ + vx = vec_mradds (vx, lCRV, (vector signed short)AVV(0)); \ + vx0 = vec_mergeh (vx,vx); \ + vx1 = vec_mergel (vx,vx); \ + \ + /* uvx = ((CGU*u) + (CGV*v))>>15 */ \ + uvx = vec_mradds (U, lCGU, (vector signed short)AVV(0)); \ + uvx = vec_mradds (V, lCGV, uvx); \ + uvx0 = vec_mergeh (uvx,uvx); \ + uvx1 = vec_mergel (uvx,uvx); \ + \ + R0 = vec_add (Y0,vx0); \ + G0 = vec_add (Y0,uvx0); \ + B0 = vec_add (Y0,ux0); \ + R1 = vec_add (Y1,vx1); \ + G1 = vec_add (Y1,uvx1); \ + B1 = vec_add (Y1,ux1); \ + \ + R = vec_packclp (R0,R1); \ + G = vec_packclp (G0,G1); \ + B = vec_packclp (B0,B1); \ + \ + out_pixels(R,G,B,oute); \ + \ + R0 = vec_add (Y2,vx0); \ + G0 = vec_add (Y2,uvx0); \ + B0 = vec_add (Y2,ux0); \ + R1 = vec_add (Y3,vx1); \ + G1 = vec_add (Y3,uvx1); \ + B1 = vec_add (Y3,ux1); \ + R = vec_packclp (R0,R1); \ + G = vec_packclp (G0,G1); \ + B = vec_packclp (B0,B1); \ + \ + \ + out_pixels(R,G,B,outo); \ + \ + y1i += 16; \ + y2i += 16; \ + ui += 8; \ + vi += 8; \ + \ + } \ + \ + outo += (outstrides[0])>>4; \ + oute += (outstrides[0])>>4; \ + \ + ui += instrides_scl[1]; \ + vi += instrides_scl[2]; \ + y1i += instrides_scl[0]; \ + y2i += instrides_scl[0]; \ + } \ + return srcSliceH; \ } @@ -443,151 +447,151 @@ DEFCSP420_CVT (yuv2_abgr, out_abgr) #if 1 DEFCSP420_CVT (yuv2_bgra, out_bgra) #else -static int altivec_yuv2_bgra32 (SwsContext *c, - unsigned char **in, int *instrides, - int srcSliceY, int srcSliceH, - unsigned char **oplanes, int *outstrides) -{ - int w = c->srcW; - int h = srcSliceH; - int i,j; - int instrides_scl[3]; - vector unsigned char y0,y1; - - vector signed char u,v; - - vector signed short Y0,Y1,Y2,Y3; - vector signed short U,V; - vector signed short vx,ux,uvx; - vector signed short vx0,ux0,uvx0; - vector signed short vx1,ux1,uvx1; - vector signed short R0,G0,B0; - vector signed short R1,G1,B1; - vector unsigned char R,G,B; - - vector unsigned char *uivP, *vivP; - vector unsigned char align_perm; - - vector signed short - lCY = c->CY, - lOY = c->OY, - lCRV = c->CRV, - lCBU = c->CBU, - lCGU = c->CGU, - lCGV = c->CGV; - - vector unsigned short lCSHIFT = c->CSHIFT; - - ubyte *y1i = in[0]; - ubyte *y2i = in[0]+w; - ubyte *ui = in[1]; - ubyte *vi = in[2]; - - vector unsigned char *oute - = (vector unsigned char *) - (oplanes[0]+srcSliceY*outstrides[0]); - vector unsigned char *outo - = (vector unsigned char *) - (oplanes[0]+srcSliceY*outstrides[0]+outstrides[0]); - - - instrides_scl[0] = instrides[0]; - instrides_scl[1] = instrides[1]-w/2; /* the loop moves ui by w/2 */ - instrides_scl[2] = instrides[2]-w/2; /* the loop moves vi by w/2 */ - - - for (i=0;i>15 */ - ux = vec_sl (U, lCSHIFT); - ux = vec_mradds (ux, lCBU, (vector signed short)AVV(0)); - ux0 = vec_mergeh (ux,ux); - ux1 = vec_mergel (ux,ux); - - /* vx = (CRV*(v<>15; */ - vx = vec_sl (V, lCSHIFT); - vx = vec_mradds (vx, lCRV, (vector signed short)AVV(0)); - vx0 = vec_mergeh (vx,vx); - vx1 = vec_mergel (vx,vx); - /* uvx = ((CGU*u) + (CGV*v))>>15 */ - uvx = vec_mradds (U, lCGU, (vector signed short)AVV(0)); - uvx = vec_mradds (V, lCGV, uvx); - uvx0 = vec_mergeh (uvx,uvx); - uvx1 = vec_mergel (uvx,uvx); - R0 = vec_add (Y0,vx0); - G0 = vec_add (Y0,uvx0); - B0 = vec_add (Y0,ux0); - R1 = vec_add (Y1,vx1); - G1 = vec_add (Y1,uvx1); - B1 = vec_add (Y1,ux1); - R = vec_packclp (R0,R1); - G = vec_packclp (G0,G1); - B = vec_packclp (B0,B1); - - out_argb(R,G,B,oute); - R0 = vec_add (Y2,vx0); - G0 = vec_add (Y2,uvx0); - B0 = vec_add (Y2,ux0); - R1 = vec_add (Y3,vx1); - G1 = vec_add (Y3,uvx1); - B1 = vec_add (Y3,ux1); - R = vec_packclp (R0,R1); - G = vec_packclp (G0,G1); - B = vec_packclp (B0,B1); - - out_argb(R,G,B,outo); - y1i += 16; - y2i += 16; - ui += 8; - vi += 8; - - } - - outo += (outstrides[0])>>4; - oute += (outstrides[0])>>4; - - ui += instrides_scl[1]; - vi += instrides_scl[2]; - y1i += instrides_scl[0]; - y2i += instrides_scl[0]; - } - return srcSliceH; +static int altivec_yuv2_bgra32 (SwsContext *c, + unsigned char **in, int *instrides, + int srcSliceY, int srcSliceH, + unsigned char **oplanes, int *outstrides) +{ + int w = c->srcW; + int h = srcSliceH; + int i,j; + int instrides_scl[3]; + vector unsigned char y0,y1; + + vector signed char u,v; + + vector signed short Y0,Y1,Y2,Y3; + vector signed short U,V; + vector signed short vx,ux,uvx; + vector signed short vx0,ux0,uvx0; + vector signed short vx1,ux1,uvx1; + vector signed short R0,G0,B0; + vector signed short R1,G1,B1; + vector unsigned char R,G,B; + + vector unsigned char *uivP, *vivP; + vector unsigned char align_perm; + + vector signed short + lCY = c->CY, + lOY = c->OY, + lCRV = c->CRV, + lCBU = c->CBU, + lCGU = c->CGU, + lCGV = c->CGV; + + vector unsigned short lCSHIFT = c->CSHIFT; + + ubyte *y1i = in[0]; + ubyte *y2i = in[0]+w; + ubyte *ui = in[1]; + ubyte *vi = in[2]; + + vector unsigned char *oute + = (vector unsigned char *) + (oplanes[0]+srcSliceY*outstrides[0]); + vector unsigned char *outo + = (vector unsigned char *) + (oplanes[0]+srcSliceY*outstrides[0]+outstrides[0]); + + + instrides_scl[0] = instrides[0]; + instrides_scl[1] = instrides[1]-w/2; /* the loop moves ui by w/2 */ + instrides_scl[2] = instrides[2]-w/2; /* the loop moves vi by w/2 */ + + + for (i=0;i>15 */ + ux = vec_sl (U, lCSHIFT); + ux = vec_mradds (ux, lCBU, (vector signed short)AVV(0)); + ux0 = vec_mergeh (ux,ux); + ux1 = vec_mergel (ux,ux); + + /* vx = (CRV*(v<>15; */ + vx = vec_sl (V, lCSHIFT); + vx = vec_mradds (vx, lCRV, (vector signed short)AVV(0)); + vx0 = vec_mergeh (vx,vx); + vx1 = vec_mergel (vx,vx); + /* uvx = ((CGU*u) + (CGV*v))>>15 */ + uvx = vec_mradds (U, lCGU, (vector signed short)AVV(0)); + uvx = vec_mradds (V, lCGV, uvx); + uvx0 = vec_mergeh (uvx,uvx); + uvx1 = vec_mergel (uvx,uvx); + R0 = vec_add (Y0,vx0); + G0 = vec_add (Y0,uvx0); + B0 = vec_add (Y0,ux0); + R1 = vec_add (Y1,vx1); + G1 = vec_add (Y1,uvx1); + B1 = vec_add (Y1,ux1); + R = vec_packclp (R0,R1); + G = vec_packclp (G0,G1); + B = vec_packclp (B0,B1); + + out_argb(R,G,B,oute); + R0 = vec_add (Y2,vx0); + G0 = vec_add (Y2,uvx0); + B0 = vec_add (Y2,ux0); + R1 = vec_add (Y3,vx1); + G1 = vec_add (Y3,uvx1); + B1 = vec_add (Y3,ux1); + R = vec_packclp (R0,R1); + G = vec_packclp (G0,G1); + B = vec_packclp (B0,B1); + + out_argb(R,G,B,outo); + y1i += 16; + y2i += 16; + ui += 8; + vi += 8; + + } + + outo += (outstrides[0])>>4; + oute += (outstrides[0])>>4; + + ui += instrides_scl[1]; + vi += instrides_scl[2]; + y1i += instrides_scl[0]; + y2i += instrides_scl[0]; + } + return srcSliceH; } #endif @@ -603,77 +607,77 @@ DEFCSP420_CVT (yuv2_bgr24, out_bgr24) // 0123 4567 89ab cdef static const vector unsigned char - demux_u = (const vector unsigned char)AVV(0x10,0x00,0x10,0x00, - 0x10,0x04,0x10,0x04, - 0x10,0x08,0x10,0x08, - 0x10,0x0c,0x10,0x0c), - demux_v = (const vector unsigned char)AVV(0x10,0x02,0x10,0x02, - 0x10,0x06,0x10,0x06, - 0x10,0x0A,0x10,0x0A, - 0x10,0x0E,0x10,0x0E), - demux_y = (const vector unsigned char)AVV(0x10,0x01,0x10,0x03, - 0x10,0x05,0x10,0x07, - 0x10,0x09,0x10,0x0B, - 0x10,0x0D,0x10,0x0F); + demux_u = (const vector unsigned char)AVV(0x10,0x00,0x10,0x00, + 0x10,0x04,0x10,0x04, + 0x10,0x08,0x10,0x08, + 0x10,0x0c,0x10,0x0c), + demux_v = (const vector unsigned char)AVV(0x10,0x02,0x10,0x02, + 0x10,0x06,0x10,0x06, + 0x10,0x0A,0x10,0x0A, + 0x10,0x0E,0x10,0x0E), + demux_y = (const vector unsigned char)AVV(0x10,0x01,0x10,0x03, + 0x10,0x05,0x10,0x07, + 0x10,0x09,0x10,0x0B, + 0x10,0x0D,0x10,0x0F); /* this is so I can play live CCIR raw video */ static int altivec_uyvy_rgb32 (SwsContext *c, - unsigned char **in, int *instrides, - int srcSliceY, int srcSliceH, - unsigned char **oplanes, int *outstrides) + unsigned char **in, int *instrides, + int srcSliceY, int srcSliceH, + unsigned char **oplanes, int *outstrides) { - int w = c->srcW; - int h = srcSliceH; - int i,j; - vector unsigned char uyvy; - vector signed short Y,U,V; - vector signed short R0,G0,B0,R1,G1,B1; - vector unsigned char R,G,B; - vector unsigned char *out; - ubyte *img; + int w = c->srcW; + int h = srcSliceH; + int i,j; + vector unsigned char uyvy; + vector signed short Y,U,V; + vector signed short R0,G0,B0,R1,G1,B1; + vector unsigned char R,G,B; + vector unsigned char *out; + ubyte *img; - img = in[0]; - out = (vector unsigned char *)(oplanes[0]+srcSliceY*outstrides[0]); + img = in[0]; + out = (vector unsigned char *)(oplanes[0]+srcSliceY*outstrides[0]); - for (i=0;iflags & SWS_CPU_CAPS_ALTIVEC)) - return NULL; + if (!(c->flags & SWS_CPU_CAPS_ALTIVEC)) + return NULL; - /* - and this seems not to matter too much I tried a bunch of - videos with abnormal widths and mplayer crashes else where. - mplayer -vo x11 -rawvideo on:w=350:h=240 raw-350x240.eyuv - boom with X11 bad match. - - */ - if ((c->srcW & 0xf) != 0) return NULL; - - switch (c->srcFormat) { - case PIX_FMT_YUV410P: - case PIX_FMT_YUV420P: - /*case IMGFMT_CLPL: ??? */ - case PIX_FMT_GRAY8: - case PIX_FMT_NV12: - case PIX_FMT_NV21: - if ((c->srcH & 0x1) != 0) - return NULL; - - switch(c->dstFormat){ - case PIX_FMT_RGB24: - av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGB24\n"); - return altivec_yuv2_rgb24; - case PIX_FMT_BGR24: - av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space BGR24\n"); - return altivec_yuv2_bgr24; - case PIX_FMT_ARGB: - av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space ARGB\n"); - return altivec_yuv2_argb; - case PIX_FMT_ABGR: - av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space ABGR\n"); - return altivec_yuv2_abgr; - case PIX_FMT_RGBA: - av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGBA\n"); - return altivec_yuv2_rgba; - case PIX_FMT_BGRA: - av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space BGRA\n"); - return altivec_yuv2_bgra; - default: return NULL; - } - break; - - case PIX_FMT_UYVY422: - switch(c->dstFormat){ - case PIX_FMT_BGR32: - av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space UYVY -> RGB32\n"); - return altivec_uyvy_rgb32; - default: return NULL; - } - break; + /* + and this seems not to matter too much I tried a bunch of + videos with abnormal widths and mplayer crashes else where. + mplayer -vo x11 -rawvideo on:w=350:h=240 raw-350x240.eyuv + boom with X11 bad match. - } - return NULL; + */ + if ((c->srcW & 0xf) != 0) return NULL; + + switch (c->srcFormat) { + case PIX_FMT_YUV410P: + case PIX_FMT_YUV420P: + /*case IMGFMT_CLPL: ??? */ + case PIX_FMT_GRAY8: + case PIX_FMT_NV12: + case PIX_FMT_NV21: + if ((c->srcH & 0x1) != 0) + return NULL; + + switch(c->dstFormat){ + case PIX_FMT_RGB24: + av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGB24\n"); + return altivec_yuv2_rgb24; + case PIX_FMT_BGR24: + av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space BGR24\n"); + return altivec_yuv2_bgr24; + case PIX_FMT_ARGB: + av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space ARGB\n"); + return altivec_yuv2_argb; + case PIX_FMT_ABGR: + av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space ABGR\n"); + return altivec_yuv2_abgr; + case PIX_FMT_RGBA: + av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space RGBA\n"); + return altivec_yuv2_rgba; + case PIX_FMT_BGRA: + av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space BGRA\n"); + return altivec_yuv2_bgra; + default: return NULL; + } + break; + + case PIX_FMT_UYVY422: + switch(c->dstFormat){ + case PIX_FMT_BGR32: + av_log(c, AV_LOG_WARNING, "ALTIVEC: Color Space UYVY -> RGB32\n"); + return altivec_uyvy_rgb32; + default: return NULL; + } + break; + + } + return NULL; } static uint16_t roundToInt16(int64_t f){ - int r= (f + (1<<15))>>16; - if(r<-0x7FFF) return 0x8000; - else if(r> 0x7FFF) return 0x7FFF; - else return r; + int r= (f + (1<<15))>>16; + if (r<-0x7FFF) return 0x8000; + else if (r> 0x7FFF) return 0x7FFF; + else return r; } void yuv2rgb_altivec_init_tables (SwsContext *c, const int inv_table[4],int brightness,int contrast, int saturation) { - union { - signed short tmp[8] __attribute__ ((aligned(16))); - vector signed short vec; - } buf; - - buf.tmp[0] = ( (0xffffLL) * contrast>>8 )>>9; //cy - buf.tmp[1] = -256*brightness; //oy - buf.tmp[2] = (inv_table[0]>>3) *(contrast>>16)*(saturation>>16); //crv - buf.tmp[3] = (inv_table[1]>>3) *(contrast>>16)*(saturation>>16); //cbu - buf.tmp[4] = -((inv_table[2]>>1)*(contrast>>16)*(saturation>>16)); //cgu - buf.tmp[5] = -((inv_table[3]>>1)*(contrast>>16)*(saturation>>16)); //cgv - - - c->CSHIFT = (vector unsigned short)vec_splat_u16(2); - c->CY = vec_splat ((vector signed short)buf.vec, 0); - c->OY = vec_splat ((vector signed short)buf.vec, 1); - c->CRV = vec_splat ((vector signed short)buf.vec, 2); - c->CBU = vec_splat ((vector signed short)buf.vec, 3); - c->CGU = vec_splat ((vector signed short)buf.vec, 4); - c->CGV = vec_splat ((vector signed short)buf.vec, 5); + union { + signed short tmp[8] __attribute__ ((aligned(16))); + vector signed short vec; + } buf; + + buf.tmp[0] = ((0xffffLL) * contrast>>8)>>9; //cy + buf.tmp[1] = -256*brightness; //oy + buf.tmp[2] = (inv_table[0]>>3) *(contrast>>16)*(saturation>>16); //crv + buf.tmp[3] = (inv_table[1]>>3) *(contrast>>16)*(saturation>>16); //cbu + buf.tmp[4] = -((inv_table[2]>>1)*(contrast>>16)*(saturation>>16)); //cgu + buf.tmp[5] = -((inv_table[3]>>1)*(contrast>>16)*(saturation>>16)); //cgv + + + c->CSHIFT = (vector unsigned short)vec_splat_u16(2); + c->CY = vec_splat ((vector signed short)buf.vec, 0); + c->OY = vec_splat ((vector signed short)buf.vec, 1); + c->CRV = vec_splat ((vector signed short)buf.vec, 2); + c->CBU = vec_splat ((vector signed short)buf.vec, 3); + c->CGU = vec_splat ((vector signed short)buf.vec, 4); + c->CGV = vec_splat ((vector signed short)buf.vec, 5); #if 0 -{ -int i; -char *v[6]={"cy","oy","crv","cbu","cgu","cgv"}; -for (i=0; i<6;i++) - printf("%s %d ", v[i],buf.tmp[i] ); - printf("\n"); -} + { + int i; + char *v[6]={"cy","oy","crv","cbu","cgu","cgv"}; + for (i=0; i<6; i++) + printf("%s %d ", v[i],buf.tmp[i] ); + printf("\n"); + } #endif - return; + return; } void altivec_yuv2packedX (SwsContext *c, - int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize, - int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, - uint8_t *dest, int dstW, int dstY) + int16_t *lumFilter, int16_t **lumSrc, int lumFilterSize, + int16_t *chrFilter, int16_t **chrSrc, int chrFilterSize, + uint8_t *dest, int dstW, int dstY) { - int i,j; - vector signed short X,X0,X1,Y0,U0,V0,Y1,U1,V1,U,V; - vector signed short R0,G0,B0,R1,G1,B1; + int i,j; + vector signed short X,X0,X1,Y0,U0,V0,Y1,U1,V1,U,V; + vector signed short R0,G0,B0,R1,G1,B1; - vector unsigned char R,G,B; - vector unsigned char *out,*nout; + vector unsigned char R,G,B; + vector unsigned char *out,*nout; - vector signed short RND = vec_splat_s16(1<<3); - vector unsigned short SCL = vec_splat_u16(4); - unsigned long scratch[16] __attribute__ ((aligned (16))); + vector signed short RND = vec_splat_s16(1<<3); + vector unsigned short SCL = vec_splat_u16(4); + unsigned long scratch[16] __attribute__ ((aligned (16))); - vector signed short *YCoeffs, *CCoeffs; + vector signed short *YCoeffs, *CCoeffs; - YCoeffs = c->vYCoeffsBank+dstY*lumFilterSize; - CCoeffs = c->vCCoeffsBank+dstY*chrFilterSize; + YCoeffs = c->vYCoeffsBank+dstY*lumFilterSize; + CCoeffs = c->vCCoeffsBank+dstY*chrFilterSize; - out = (vector unsigned char *)dest; + out = (vector unsigned char *)dest; - for(i=0; idstFormat) { - case PIX_FMT_ABGR: out_abgr (R,G,B,out); break; - case PIX_FMT_BGRA: out_bgra (R,G,B,out); break; - case PIX_FMT_RGBA: out_rgba (R,G,B,out); break; - case PIX_FMT_ARGB: out_argb (R,G,B,out); break; - case PIX_FMT_RGB24: out_rgb24 (R,G,B,out); break; - case PIX_FMT_BGR24: out_bgr24 (R,G,B,out); break; - default: - { - /* If this is reached, the caller should have called yuv2packedXinC - instead. */ - static int printed_error_message; - if(!printed_error_message) { - av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n", - sws_format_name(c->dstFormat)); - printed_error_message=1; - } - return; + U = RND; + V = RND; + /* extract 8 coeffs from U,V */ + for (j=0; jdstFormat) { + case PIX_FMT_ABGR: out_abgr (R,G,B,out); break; + case PIX_FMT_BGRA: out_bgra (R,G,B,out); break; + case PIX_FMT_RGBA: out_rgba (R,G,B,out); break; + case PIX_FMT_ARGB: out_argb (R,G,B,out); break; + case PIX_FMT_RGB24: out_rgb24 (R,G,B,out); break; + case PIX_FMT_BGR24: out_bgr24 (R,G,B,out); break; + default: + { + /* If this is reached, the caller should have called yuv2packedXinC + instead. */ + static int printed_error_message; + if (!printed_error_message) { + av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n", + sws_format_name(c->dstFormat)); + printed_error_message=1; + } + return; + } + } } - /* scale and clip signals */ - Y0 = vec_sra (Y0, SCL); - Y1 = vec_sra (Y1, SCL); - U = vec_sra (U, SCL); - V = vec_sra (V, SCL); - - Y0 = vec_clip_s16 (Y0); - Y1 = vec_clip_s16 (Y1); - U = vec_clip_s16 (U); - V = vec_clip_s16 (V); + if (i < dstW) { + i -= 16; + + Y0 = RND; + Y1 = RND; + /* extract 16 coeffs from lumSrc */ + for (j=0; jdstFormat) { + case PIX_FMT_ABGR: out_abgr (R,G,B,nout); break; + case PIX_FMT_BGRA: out_bgra (R,G,B,nout); break; + case PIX_FMT_RGBA: out_rgba (R,G,B,nout); break; + case PIX_FMT_ARGB: out_argb (R,G,B,nout); break; + case PIX_FMT_RGB24: out_rgb24 (R,G,B,nout); break; + case PIX_FMT_BGR24: out_bgr24 (R,G,B,nout); break; + default: + /* Unreachable, I think. */ + av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n", + sws_format_name(c->dstFormat)); + return; + } - U0 = vec_mergeh (U,U); - V0 = vec_mergeh (V,V); - - U1 = vec_mergel (U,U); - V1 = vec_mergel (V,V); - - cvtyuvtoRGB (c, Y0,U0,V0,&R0,&G0,&B0); - cvtyuvtoRGB (c, Y1,U1,V1,&R1,&G1,&B1); - - R = vec_packclp (R0,R1); - G = vec_packclp (G0,G1); - B = vec_packclp (B0,B1); - - nout = (vector unsigned char *)scratch; - switch(c->dstFormat) { - case PIX_FMT_ABGR: out_abgr (R,G,B,nout); break; - case PIX_FMT_BGRA: out_bgra (R,G,B,nout); break; - case PIX_FMT_RGBA: out_rgba (R,G,B,nout); break; - case PIX_FMT_ARGB: out_argb (R,G,B,nout); break; - case PIX_FMT_RGB24: out_rgb24 (R,G,B,nout); break; - case PIX_FMT_BGR24: out_bgr24 (R,G,B,nout); break; - default: - /* Unreachable, I think. */ - av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n", - sws_format_name(c->dstFormat)); - return; + memcpy (&((uint32_t*)dest)[i], scratch, (dstW-i)/4); } - memcpy (&((uint32_t*)dest)[i], scratch, (dstW-i)/4); - } - } diff --git a/contrib/ffmpeg/libswscale/yuv2rgb_bfin.c b/contrib/ffmpeg/libswscale/yuv2rgb_bfin.c new file mode 100644 index 000000000..d2770793b --- /dev/null +++ b/contrib/ffmpeg/libswscale/yuv2rgb_bfin.c @@ -0,0 +1,207 @@ +/* + * Copyright (C) 2007 Marc Hoffman + * April 20, 2007 + * + * Blackfin Video Color Space Converters Operations + * convert I420 YV12 to RGB in various formats, + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include +#include "config.h" +#ifdef HAVE_MALLOC_H +#include +#endif +#include +#include "rgb2rgb.h" +#include "swscale.h" +#include "swscale_internal.h" + +#ifdef __FDPIC__ +#define L1CODE __attribute__ ((l1_text)) +#else +#define L1CODE +#endif + +extern void ff_bfin_yuv2rgb555_line (uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out, + int w, uint32_t *coeffs) L1CODE; + +extern void ff_bfin_yuv2rgb565_line (uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out, + int w, uint32_t *coeffs) L1CODE; + +extern void ff_bfin_yuv2rgb24_line (uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out, + int w, uint32_t *coeffs) L1CODE; + +typedef void (* ltransform_t)(uint8_t *Y, uint8_t *U, uint8_t *V, uint8_t *out, + int w, uint32_t *coeffs); + + +static void bfin_prepare_coefficients (SwsContext *c, int rgb, int masks) +{ + int oy; + oy = c->yOffset&0xffff; + oy = oy >> 3; // keep everything U8.0 for offset calculation + + c->oc = 128*0x01010101U; + c->oy = oy*0x01010101U; + + /* copy 64bit vector coeffs down to 32bit vector coeffs */ + c->cy = c->yCoeff; + c->zero = 0; + + if (rgb) { + c->crv = c->vrCoeff; + c->cbu = c->ubCoeff; + c->cgu = c->ugCoeff; + c->cgv = c->vgCoeff; + } else { + c->crv = c->ubCoeff; + c->cbu = c->vrCoeff; + c->cgu = c->vgCoeff; + c->cgv = c->ugCoeff; + } + + + if (masks == 555) { + c->rmask = 0x001f * 0x00010001U; + c->gmask = 0x03e0 * 0x00010001U; + c->bmask = 0x7c00 * 0x00010001U; + } else if (masks == 565) { + c->rmask = 0x001f * 0x00010001U; + c->gmask = 0x07e0 * 0x00010001U; + c->bmask = 0xf800 * 0x00010001U; + } +} + +static int core_yuv420_rgb (SwsContext *c, + uint8_t **in, int *instrides, + int srcSliceY, int srcSliceH, + uint8_t **oplanes, int *outstrides, + ltransform_t lcscf, int rgb, int masks) +{ + uint8_t *py,*pu,*pv,*op; + int w = instrides[0]; + int h2 = srcSliceH>>1; + int i; + + bfin_prepare_coefficients (c, rgb, masks); + + py = in[0]; + pu = in[1+(1^rgb)]; + pv = in[1+(0^rgb)]; + + op = oplanes[0] + srcSliceY*outstrides[0]; + + for (i=0;ioy); + + py += instrides[0]; + op += outstrides[0]; + + lcscf (py, pu, pv, op, w, &c->oy); + + py += instrides[0]; + pu += instrides[1]; + pv += instrides[2]; + op += outstrides[0]; + } + + return srcSliceH; +} + + +static int bfin_yuv420_rgb555 (SwsContext *c, + uint8_t **in, int *instrides, + int srcSliceY, int srcSliceH, + uint8_t **oplanes, int *outstrides) +{ + return core_yuv420_rgb (c, in, instrides, srcSliceY, srcSliceH, oplanes, outstrides, + ff_bfin_yuv2rgb555_line, 1, 555); +} + +static int bfin_yuv420_bgr555 (SwsContext *c, + uint8_t **in, int *instrides, + int srcSliceY, int srcSliceH, + uint8_t **oplanes, int *outstrides) +{ + return core_yuv420_rgb (c, in, instrides, srcSliceY, srcSliceH, oplanes, outstrides, + ff_bfin_yuv2rgb555_line, 0, 555); +} + +static int bfin_yuv420_rgb24 (SwsContext *c, + uint8_t **in, int *instrides, + int srcSliceY, int srcSliceH, + uint8_t **oplanes, int *outstrides) +{ + return core_yuv420_rgb (c, in, instrides, srcSliceY, srcSliceH, oplanes, outstrides, + ff_bfin_yuv2rgb24_line, 1, 888); +} + +static int bfin_yuv420_bgr24 (SwsContext *c, + uint8_t **in, int *instrides, + int srcSliceY, int srcSliceH, + uint8_t **oplanes, int *outstrides) +{ + return core_yuv420_rgb (c, in, instrides, srcSliceY, srcSliceH, oplanes, outstrides, + ff_bfin_yuv2rgb24_line, 0, 888); +} + +static int bfin_yuv420_rgb565 (SwsContext *c, + uint8_t **in, int *instrides, + int srcSliceY, int srcSliceH, + uint8_t **oplanes, int *outstrides) +{ + return core_yuv420_rgb (c, in, instrides, srcSliceY, srcSliceH, oplanes, outstrides, + ff_bfin_yuv2rgb565_line, 1, 565); +} + +static int bfin_yuv420_bgr565 (SwsContext *c, + uint8_t **in, int *instrides, + int srcSliceY, int srcSliceH, + uint8_t **oplanes, int *outstrides) +{ + return core_yuv420_rgb (c, in, instrides, srcSliceY, srcSliceH, oplanes, outstrides, + ff_bfin_yuv2rgb565_line, 0, 565); +} + + +SwsFunc ff_bfin_yuv2rgb_get_func_ptr (SwsContext *c) +{ + SwsFunc f; + + switch(c->dstFormat) { + case PIX_FMT_RGB555: f = bfin_yuv420_rgb555; break; + case PIX_FMT_BGR555: f = bfin_yuv420_bgr555; break; + case PIX_FMT_RGB565: f = bfin_yuv420_rgb565; break; + case PIX_FMT_BGR565: f = bfin_yuv420_bgr565; break; + case PIX_FMT_RGB24: f = bfin_yuv420_rgb24; break; + case PIX_FMT_BGR24: f = bfin_yuv420_bgr24; break; + default: + return 0; + } + + av_log(c, AV_LOG_INFO, "BlackFin Accelerated Color Space Converter %s\n", + sws_format_name (c->dstFormat)); + + return f; +} diff --git a/contrib/ffmpeg/libswscale/yuv2rgb_init.c b/contrib/ffmpeg/libswscale/yuv2rgb_init.c deleted file mode 100644 index 371dce5da..000000000 --- a/contrib/ffmpeg/libswscale/yuv2rgb_init.c +++ /dev/null @@ -1,412 +0,0 @@ -#include "avutil.h" -#include "swscale.h" -#include "swscale_internal.h" - -#define YTABLE_MIN 384 - -/** - * YUV -> RGB conversion matrixes (inverse of table 6.9 in MPEG2 standard) - * - * An YUV -> RGB conversion matrix is in the form - * | 1 0 Rv | - * | 1 Gu Gv | - * | 1 Bu 0 | - * - * Inverse_Table_6_9 stores | Rv Bu Gv Gu | * 255/224*2^16. - * \arg Maximum Rv value: 117570 - * \arg Maximum Bu value: 138420 - * \arg Maximum Gv + Gu value: 25642 + 53281 = 78923 - * - * These values are needed to allocate table_{r, g, b}. If you modify - * this table, please update allocate_tables() accordingly - */ -const int32_t Inverse_Table_6_9[8][4] = { - {0, 0, 0, 0}, /* no sequence_display_extension */ - {117500, 138420, -13985, -34933}, /* ITU-R Rec. 709 (1990) */ - {0, 0, 0, 0}, /* unspecified */ - {0, 0, 0, 0}, /* reserved */ - {104480, 132820, -24811, -53150}, /* FCC */ - {104570, 132210, -25642, -53281}, /* ITU-R Rec. 624-4 System B, G */ - {104570, 132210, -25642, -53281}, /* SMPTE 170M */ - {117570, 136230, -16892, -35552} /* SMPTE 240M (1987) */ -}; - - -/** - * Dithering matrixes (these are bayer ordered dither matrixes - * with some manual changes by Michael) - */ -const uint8_t __attribute__((aligned(8))) dither_2x2_4[2][8]={ -{ 1, 3, 1, 3, 1, 3, 1, 3, }, -{ 2, 0, 2, 0, 2, 0, 2, 0, }, -}; - -const uint8_t __attribute__((aligned(8))) dither_2x2_8[2][8]={ -{ 6, 2, 6, 2, 6, 2, 6, 2, }, -{ 0, 4, 0, 4, 0, 4, 0, 4, }, -}; - -const uint8_t __attribute__((aligned(8))) dither_8x8_32[8][8]={ -{ 17, 9, 23, 15, 16, 8, 22, 14, }, -{ 5, 29, 3, 27, 4, 28, 2, 26, }, -{ 21, 13, 19, 11, 20, 12, 18, 10, }, -{ 0, 24, 6, 30, 1, 25, 7, 31, }, -{ 16, 8, 22, 14, 17, 9, 23, 15, }, -{ 4, 28, 2, 26, 5, 29, 3, 27, }, -{ 20, 12, 18, 10, 21, 13, 19, 11, }, -{ 1, 25, 7, 31, 0, 24, 6, 30, }, -}; - -#if 0 -const uint8_t __attribute__((aligned(8))) dither_8x8_64[8][8]={ -{ 0, 48, 12, 60, 3, 51, 15, 63, }, -{ 32, 16, 44, 28, 35, 19, 47, 31, }, -{ 8, 56, 4, 52, 11, 59, 7, 55, }, -{ 40, 24, 36, 20, 43, 27, 39, 23, }, -{ 2, 50, 14, 62, 1, 49, 13, 61, }, -{ 34, 18, 46, 30, 33, 17, 45, 29, }, -{ 10, 58, 6, 54, 9, 57, 5, 53, }, -{ 42, 26, 38, 22, 41, 25, 37, 21, }, -}; -#endif - -const uint8_t __attribute__((aligned(8))) dither_8x8_73[8][8]={ -{ 0, 55, 14, 68, 3, 58, 17, 72, }, -{ 37, 18, 50, 32, 40, 22, 54, 35, }, -{ 9, 64, 5, 59, 13, 67, 8, 63, }, -{ 46, 27, 41, 23, 49, 31, 44, 26, }, -{ 2, 57, 16, 71, 1, 56, 15, 70, }, -{ 39, 21, 52, 34, 38, 19, 51, 33, }, -{ 11, 66, 7, 62, 10, 65, 6, 60, }, -{ 48, 30, 43, 25, 47, 29, 42, 24, }, -}; - -#if 0 -const uint8_t __attribute__((aligned(8))) dither_8x8_128[8][8]={ -{ 68, 36, 92, 60, 66, 34, 90, 58, }, -{ 20, 116, 12, 108, 18, 114, 10, 106, }, -{ 84, 52, 76, 44, 82, 50, 74, 42, }, -{ 0, 96, 24, 120, 6, 102, 30, 126, }, -{ 64, 32, 88, 56, 70, 38, 94, 62, }, -{ 16, 112, 8, 104, 22, 118, 14, 110, }, -{ 80, 48, 72, 40, 86, 54, 78, 46, }, -{ 4, 100, 28, 124, 2, 98, 26, 122, }, -}; -#endif - -#if 1 -const uint8_t __attribute__((aligned(8))) dither_8x8_220[8][8]={ -{117, 62, 158, 103, 113, 58, 155, 100, }, -{ 34, 199, 21, 186, 31, 196, 17, 182, }, -{144, 89, 131, 76, 141, 86, 127, 72, }, -{ 0, 165, 41, 206, 10, 175, 52, 217, }, -{110, 55, 151, 96, 120, 65, 162, 107, }, -{ 28, 193, 14, 179, 38, 203, 24, 189, }, -{138, 83, 124, 69, 148, 93, 134, 79, }, -{ 7, 172, 48, 213, 3, 168, 45, 210, }, -}; -#elif 1 -// tries to correct a gamma of 1.5 -const uint8_t __attribute__((aligned(8))) dither_8x8_220[8][8]={ -{ 0, 143, 18, 200, 2, 156, 25, 215, }, -{ 78, 28, 125, 64, 89, 36, 138, 74, }, -{ 10, 180, 3, 161, 16, 195, 8, 175, }, -{109, 51, 93, 38, 121, 60, 105, 47, }, -{ 1, 152, 23, 210, 0, 147, 20, 205, }, -{ 85, 33, 134, 71, 81, 30, 130, 67, }, -{ 14, 190, 6, 171, 12, 185, 5, 166, }, -{117, 57, 101, 44, 113, 54, 97, 41, }, -}; -#elif 1 -// tries to correct a gamma of 2.0 -const uint8_t __attribute__((aligned(8))) dither_8x8_220[8][8]={ -{ 0, 124, 8, 193, 0, 140, 12, 213, }, -{ 55, 14, 104, 42, 66, 19, 119, 52, }, -{ 3, 168, 1, 145, 6, 187, 3, 162, }, -{ 86, 31, 70, 21, 99, 39, 82, 28, }, -{ 0, 134, 11, 206, 0, 129, 9, 200, }, -{ 62, 17, 114, 48, 58, 16, 109, 45, }, -{ 5, 181, 2, 157, 4, 175, 1, 151, }, -{ 95, 36, 78, 26, 90, 34, 74, 24, }, -}; -#else -// tries to correct a gamma of 2.5 -const uint8_t __attribute__((aligned(8))) dither_8x8_220[8][8]={ -{ 0, 107, 3, 187, 0, 125, 6, 212, }, -{ 39, 7, 86, 28, 49, 11, 102, 36, }, -{ 1, 158, 0, 131, 3, 180, 1, 151, }, -{ 68, 19, 52, 12, 81, 25, 64, 17, }, -{ 0, 119, 5, 203, 0, 113, 4, 195, }, -{ 45, 9, 96, 33, 42, 8, 91, 30, }, -{ 2, 172, 1, 144, 2, 165, 0, 137, }, -{ 77, 23, 60, 15, 72, 21, 56, 14, }, -}; -#endif - -static int get_entry_size(int bpp) -{ - switch(bpp) { - case 32: - return 4; - case 16: - case 15: - return 2; - case 24: - case 8: - case 4: - case 1: - return 1; - default: - return -1; - } -} - -/** - * Allocate table_r, table_g, and table_b - * - * For cache efficency reasons, these three tables are allocated - * together, so that they are contiguous in memory - * - * table_r is indexed in the range - * [-128 * 117570 / 76309, 255 + 127 * 117570 / 76309] = - * [-197.21, 451.67] ---> [-198, 452] - * table_b is indexed in the range - * [-128 * 138420 / 76309, 255 + 127 * 138420 / 76309] = - * [232.18, 485.37] ---> [-233, 486] - * table_g is indexed in the range - * [-128 * 78923 / 76309, 255 + 127 * 78923 / 76309] = - * [-132.38, 386.35] ---> [-133, 387] - * - * Please look at the comments after Inverse_Table_6_9 to see where these - * numbers are coming from. - */ -static void *allocate_tables(uint8_t **table_r, uint8_t **table_g, uint8_t **table_b, int bpp) -{ - uint8_t *table; - int entry_size; - - entry_size = get_entry_size(bpp); - - /* First allocate the memory... */ - switch (bpp) { - case 32: - case 15: - case 16: - case 8: - case 4: - table = av_malloc((198 + 452 + 233 + 486 + 133 + 387) * entry_size); - break; - case 24: - table = av_malloc(256 + 2 * 233); - break; - case 1: - table = av_malloc (256 * 2); - break; - default: - table = NULL; - } - if (table == NULL) { - MSG_ERR("Cannot allocate memory for the YUV -> RGB tables!\n"); - - return NULL; - } - - /* ...and then, assign the table_* value */ - switch (bpp) { - case 32: - case 15: - case 16: - case 8: - case 4: - *table_r = table + 198 * entry_size; - *table_b = table + (198 + 452 + 133 + 387 + 233) * entry_size; - *table_g = table + (198 + 452 + 133) * entry_size; - break; - case 24: - *table_r = *table_g = *table_b = table + 233; - break; - case 1: - *table_g = table; - *table_r = *table_b = NULL; - break; - } - - return table; -} - -/** - * Initialize the table_rV, table_gU[i], table_gV, and table_bU fields - * in SwsContext - * - * @param inv_table the YUV -> RGB table (this is a line of Inverse_Table_6_9) - * @param fullRange 0->MPEG YUV space 1->JPEG YUV space -*/ -int yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation) -{ - int i; - static uint8_t ytable[1024]; - int64_t cy, oy; - int64_t crv, cbu, cgu, cgv; - int entry_size = 0; - uint8_t *table_r, *table_g, *table_b; - int value; - - if ((inv_table[0] == 0) || (inv_table[1] == 0) || (inv_table[2] == 0) || (inv_table[3] == 0)) { - MSG_ERR("Invalid YUV ---> RGB table!\n"); - - return -1; - } - crv = inv_table[0]; - cbu = inv_table[1]; - cgu = inv_table[2]; - cgv = inv_table[3]; - if (fullRange) { - cy = 1 << 16; - oy = 0; - crv= (crv*224) / 255; - cbu= (cbu*224) / 255; - cgu= (cgu*224) / 255; - cgv= (cgv*224) / 255; - //FIXME maybe its cleaner if the tables where based on full range (*244/255) - } else { - cy = ((1 << 16) * 255) / 219; - oy= 16 << 16; - } - - cy = (cy *contrast )>>16; - crv= (crv*contrast * saturation)>>32; - cbu= (cbu*contrast * saturation)>>32; - cgu= (cgu*contrast * saturation)>>32; - cgv= (cgv*contrast * saturation)>>32; - oy -= 256*brightness; - - for (i = 0; i < 1024; i++) { - value = (cy*(((i - YTABLE_MIN)<<16) - oy) + (1<<31))>>32; - ytable[i] = av_clip_uint8(value); - } - - entry_size = get_entry_size(fmt_depth(c->dstFormat)); - av_free(c->yuvTable); - c->yuvTable = allocate_tables(&table_r, &table_g, &table_b, fmt_depth(c->dstFormat)); - if (c->yuvTable == NULL) { - return -1; - } - - switch (fmt_depth(c->dstFormat)) { - case 32: - for (i = -198; i < 256 + 197; i++) { - value = ytable[i + YTABLE_MIN]; - if (isBGR(c->dstFormat)) { - value <<= 16; - } - ((uint32_t *)table_r)[i] = value; - } - for (i = -133; i < 256 + 132; i++) { - ((uint32_t *)table_g)[i] = ytable[i + YTABLE_MIN] << 8; - } - for (i = -233; i < 256 + 232; i++) { - value = ytable[i + YTABLE_MIN]; - if (!isBGR(c->dstFormat)) { - value <<= 16; - } - ((uint32_t *)table_b)[i] = value; - } - break; - - case 24: - for (i = -233; i < 256 + 232; i++) { - ((uint8_t * )table_b)[i] = ytable[i + YTABLE_MIN]; - } - break; - - case 15: - case 16: - for (i = -198; i < 256 + 197; i++) { - value = ytable[i + YTABLE_MIN] >> 3; - if (isBGR(c->dstFormat)) { - value <<= ((fmt_depth(c->dstFormat) == 16) ? 11 : 10); - } - ((uint16_t *)table_r)[i] = value; - } - for (i = -133; i < 256 + 132; i++) { - value = ytable[i + YTABLE_MIN]; - value >>= ((fmt_depth(c->dstFormat) == 16) ? 2 : 3); - ((uint16_t *)table_g)[i] = value << 5; - } - for (i = -233; i < 256 + 232; i++) { - value = ytable[i + YTABLE_MIN] >> 3; - if (!isBGR(c->dstFormat)) { - value <<= ((fmt_depth(c->dstFormat) == 16) ? 11 : 10); - } - ((uint16_t *)table_b)[i] = value; - } - break; - case 8: - for (i = -198; i < 256 + 197; i++) { - value = (ytable[i + YTABLE_MIN - 16] + 18) / 36; - if (isBGR(c->dstFormat)) { - value <<= 5; - } - ((uint8_t *)table_r)[i] = value; - } - for (i = -133; i < 256 + 132; i++) { - value = (ytable[i + YTABLE_MIN - 16] + 18) / 36; - if (!isBGR(c->dstFormat)) { - value <<= 1; - } - ((uint8_t *)table_g)[i] = value << 2; - } - for (i = -233; i < 256 + 232; i++) { - value = (ytable[i + YTABLE_MIN - 37] + 43) / 85; - if (!isBGR(c->dstFormat)) { - value <<= 6; - } - ((uint8_t *)table_b)[i] = value; - } - break; - case 4: - for (i = -198; i < 256 + 197; i++) { - value = ytable[i + YTABLE_MIN - 110] >> 7; - if (isBGR(c->dstFormat)) { - value <<= 3; - } - ((uint8_t *)table_r)[i] = value; - } - for (i = -133; i < 256 + 132; i++) { - value = (ytable[i + YTABLE_MIN - 37]+ 43) / 85; - ((uint8_t *)table_g)[i] = value << 1; - } - for (i = -233; i < 256 + 232; i++) { - value = ytable[i + YTABLE_MIN - 110] >> 7; - if (!isBGR(c->dstFormat)) { - value <<= 3; - } - ((uint8_t *)table_b)[i] = value; - } - break; - case 1: - for (i = 0; i < 256 + 256; i++) { - value = ytable[i + YTABLE_MIN - 110] >> 7; - ((uint8_t *)table_g)[i] = value; - } - break; - default: - MSG_ERR("%ibpp not supported by yuv2rgb\n", fmt_depth(c->dstFormat)); - av_free(c->yuvTable); - c->yuvTable = NULL; - - return -1; - } - - for (i = 0; i < 256; i++) { - c->table_rV[i] = table_r + - entry_size * ROUNDED_DIV(crv * (i - 128), 76309); - c->table_gU[i] = table_g + - entry_size * ROUNDED_DIV(cgu * (i - 128), 76309); - c->table_gV[i] = entry_size * ROUNDED_DIV(cgv * (i - 128), 76309); - c->table_bU[i] = table_b + - entry_size * ROUNDED_DIV(cbu * (i - 128), 76309); - } - - return 0; -} diff --git a/contrib/ffmpeg/libswscale/yuv2rgb_mlib.c b/contrib/ffmpeg/libswscale/yuv2rgb_mlib.c index c99e019cd..ad271410f 100644 --- a/contrib/ffmpeg/libswscale/yuv2rgb_mlib.c +++ b/contrib/ffmpeg/libswscale/yuv2rgb_mlib.c @@ -1,24 +1,22 @@ -/* - * yuv2rgb_mlib.c, Software YUV to RGB coverter using mediaLib +/* + * yuv2rgb_mlib.c, Software YUV to RGB converter using mediaLib + * Copyright (C) 2003 Michael Niedermayer * - * Copyright (C) 2000, Håkan Hjort - * All Rights Reserved. + * This file is part of FFmpeg. * - * This file is part of mpeg2dec, a free MPEG-2 video decoder + * FFmpeg 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. * - * mpeg2dec is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. + * FFmpeg 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. * - * mpeg2dec 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with mpeg2dec; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include @@ -31,56 +29,56 @@ #include "swscale.h" -static int mlib_YUV2ARGB420_32(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]){ +static int mlib_YUV2ARGB420_32(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dst[], int dstStride[]){ if(c->srcFormat == PIX_FMT_YUV422P){ - srcStride[1] *= 2; - srcStride[2] *= 2; + srcStride[1] *= 2; + srcStride[2] *= 2; } - + assert(srcStride[1] == srcStride[2]); - + mlib_VideoColorYUV2ARGB420(dst[0]+srcSliceY*dstStride[0], src[0], src[1], src[2], c->dstW, - srcSliceH, dstStride[0], srcStride[0], srcStride[1]); + srcSliceH, dstStride[0], srcStride[0], srcStride[1]); return srcSliceH; } -static int mlib_YUV2ABGR420_32(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]){ +static int mlib_YUV2ABGR420_32(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dst[], int dstStride[]){ if(c->srcFormat == PIX_FMT_YUV422P){ - srcStride[1] *= 2; - srcStride[2] *= 2; + srcStride[1] *= 2; + srcStride[2] *= 2; } - + assert(srcStride[1] == srcStride[2]); - + mlib_VideoColorYUV2ABGR420(dst[0]+srcSliceY*dstStride[0], src[0], src[1], src[2], c->dstW, - srcSliceH, dstStride[0], srcStride[0], srcStride[1]); + srcSliceH, dstStride[0], srcStride[0], srcStride[1]); return srcSliceH; } -static int mlib_YUV2RGB420_24(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]){ +static int mlib_YUV2RGB420_24(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dst[], int dstStride[]){ if(c->srcFormat == PIX_FMT_YUV422P){ - srcStride[1] *= 2; - srcStride[2] *= 2; + srcStride[1] *= 2; + srcStride[2] *= 2; } - + assert(srcStride[1] == srcStride[2]); - + mlib_VideoColorYUV2RGB420(dst[0]+srcSliceY*dstStride[0], src[0], src[1], src[2], c->dstW, - srcSliceH, dstStride[0], srcStride[0], srcStride[1]); + srcSliceH, dstStride[0], srcStride[0], srcStride[1]); return srcSliceH; } -SwsFunc yuv2rgb_init_mlib(SwsContext *c) +SwsFunc yuv2rgb_init_mlib(SwsContext *c) { - switch(c->dstFormat){ - case PIX_FMT_RGB24: return mlib_YUV2RGB420_24; - case PIX_FMT_BGR32: return mlib_YUV2ARGB420_32; - case PIX_FMT_RGB32: return mlib_YUV2ABGR420_32; - default: return NULL; - } + switch(c->dstFormat){ + case PIX_FMT_RGB24: return mlib_YUV2RGB420_24; + case PIX_FMT_BGR32: return mlib_YUV2ARGB420_32; + case PIX_FMT_RGB32: return mlib_YUV2ABGR420_32; + default: return NULL; + } } diff --git a/contrib/ffmpeg/libswscale/yuv2rgb_template.c b/contrib/ffmpeg/libswscale/yuv2rgb_template.c index 28ee24add..d86bc4b94 100644 --- a/contrib/ffmpeg/libswscale/yuv2rgb_template.c +++ b/contrib/ffmpeg/libswscale/yuv2rgb_template.c @@ -1,12 +1,14 @@ - /* - * yuv2rgb_mmx.c, Software YUV to RGB coverter with Intel MMX "technology" + * yuv2rgb_mmx.c, Software YUV to RGB converter with Intel MMX "technology" * * Copyright (C) 2000, Silicon Integrated System Corp. - * All Rights Reserved. * * Author: Olie Lho * + * 15,24 bpp and dithering from Michael Niedermayer (michaelni@gmx.at) + * MMX/MMX2 Template stuff from Michael Niedermayer (needed for fast movntq support) + * context / deglobalize stuff by Michael Niedermayer + * * This file is part of mpeg2dec, a free MPEG-2 video decoder * * mpeg2dec is free software; you can redistribute it and/or modify @@ -22,10 +24,6 @@ * You should have received a copy of the GNU General Public License * along with mpeg2dec; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * 15,24 bpp and dithering from Michael Niedermayer (michaelni@gmx.at) - * MMX/MMX2 Template stuff from Michael Niedermayer (needed for fast movntq support) - * context / deglobalize stuff by Michael Niedermayer */ #undef MOVNTQ @@ -48,259 +46,259 @@ #endif #define YUV2RGB \ - /* Do the multiply part of the conversion for even and odd pixels, - register usage: - mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels, - mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels, - mm6 -> Y even, mm7 -> Y odd */\ - /* convert the chroma part */\ - "punpcklbw %%mm4, %%mm0;" /* scatter 4 Cb 00 u3 00 u2 00 u1 00 u0 */ \ - "punpcklbw %%mm4, %%mm1;" /* scatter 4 Cr 00 v3 00 v2 00 v1 00 v0 */ \ + /* Do the multiply part of the conversion for even and odd pixels, + register usage: + mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels, + mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels, + mm6 -> Y even, mm7 -> Y odd */\ + /* convert the chroma part */\ + "punpcklbw %%mm4, %%mm0;" /* scatter 4 Cb 00 u3 00 u2 00 u1 00 u0 */ \ + "punpcklbw %%mm4, %%mm1;" /* scatter 4 Cr 00 v3 00 v2 00 v1 00 v0 */ \ \ - "psllw $3, %%mm0;" /* Promote precision */ \ - "psllw $3, %%mm1;" /* Promote precision */ \ + "psllw $3, %%mm0;" /* Promote precision */ \ + "psllw $3, %%mm1;" /* Promote precision */ \ \ - "psubsw "U_OFFSET"(%4), %%mm0;" /* Cb -= 128 */ \ - "psubsw "V_OFFSET"(%4), %%mm1;" /* Cr -= 128 */ \ + "psubsw "U_OFFSET"(%4), %%mm0;" /* Cb -= 128 */ \ + "psubsw "V_OFFSET"(%4), %%mm1;" /* Cr -= 128 */ \ \ - "movq %%mm0, %%mm2;" /* Copy 4 Cb 00 u3 00 u2 00 u1 00 u0 */ \ - "movq %%mm1, %%mm3;" /* Copy 4 Cr 00 v3 00 v2 00 v1 00 v0 */ \ + "movq %%mm0, %%mm2;" /* Copy 4 Cb 00 u3 00 u2 00 u1 00 u0 */ \ + "movq %%mm1, %%mm3;" /* Copy 4 Cr 00 v3 00 v2 00 v1 00 v0 */ \ \ - "pmulhw "UG_COEFF"(%4), %%mm2;" /* Mul Cb with green coeff -> Cb green */ \ - "pmulhw "VG_COEFF"(%4), %%mm3;" /* Mul Cr with green coeff -> Cr green */ \ + "pmulhw "UG_COEFF"(%4), %%mm2;" /* Mul Cb with green coeff -> Cb green */ \ + "pmulhw "VG_COEFF"(%4), %%mm3;" /* Mul Cr with green coeff -> Cr green */ \ \ - "pmulhw "UB_COEFF"(%4), %%mm0;" /* Mul Cb -> Cblue 00 b3 00 b2 00 b1 00 b0 */\ - "pmulhw "VR_COEFF"(%4), %%mm1;" /* Mul Cr -> Cred 00 r3 00 r2 00 r1 00 r0 */\ + "pmulhw "UB_COEFF"(%4), %%mm0;" /* Mul Cb -> Cblue 00 b3 00 b2 00 b1 00 b0 */\ + "pmulhw "VR_COEFF"(%4), %%mm1;" /* Mul Cr -> Cred 00 r3 00 r2 00 r1 00 r0 */\ \ - "paddsw %%mm3, %%mm2;" /* Cb green + Cr green -> Cgreen */\ + "paddsw %%mm3, %%mm2;" /* Cb green + Cr green -> Cgreen */\ \ - /* convert the luma part */\ - "movq %%mm6, %%mm7;" /* Copy 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */\ - "pand "MANGLE(mmx_00ffw)", %%mm6;" /* get Y even 00 Y6 00 Y4 00 Y2 00 Y0 */\ + /* convert the luma part */\ + "movq %%mm6, %%mm7;" /* Copy 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */\ + "pand "MANGLE(mmx_00ffw)", %%mm6;" /* get Y even 00 Y6 00 Y4 00 Y2 00 Y0 */\ \ - "psrlw $8, %%mm7;" /* get Y odd 00 Y7 00 Y5 00 Y3 00 Y1 */\ + "psrlw $8, %%mm7;" /* get Y odd 00 Y7 00 Y5 00 Y3 00 Y1 */\ \ - "psllw $3, %%mm6;" /* Promote precision */\ - "psllw $3, %%mm7;" /* Promote precision */\ + "psllw $3, %%mm6;" /* Promote precision */\ + "psllw $3, %%mm7;" /* Promote precision */\ \ - "psubw "Y_OFFSET"(%4), %%mm6;" /* Y -= 16 */\ - "psubw "Y_OFFSET"(%4), %%mm7;" /* Y -= 16 */\ + "psubw "Y_OFFSET"(%4), %%mm6;" /* Y -= 16 */\ + "psubw "Y_OFFSET"(%4), %%mm7;" /* Y -= 16 */\ \ - "pmulhw "Y_COEFF"(%4), %%mm6;" /* Mul 4 Y even 00 y6 00 y4 00 y2 00 y0 */\ - "pmulhw "Y_COEFF"(%4), %%mm7;" /* Mul 4 Y odd 00 y7 00 y5 00 y3 00 y1 */\ + "pmulhw "Y_COEFF"(%4), %%mm6;" /* Mul 4 Y even 00 y6 00 y4 00 y2 00 y0 */\ + "pmulhw "Y_COEFF"(%4), %%mm7;" /* Mul 4 Y odd 00 y7 00 y5 00 y3 00 y1 */\ \ - /* Do the addition part of the conversion for even and odd pixels, - register usage: - mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels, - mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels, - mm6 -> Y even, mm7 -> Y odd */\ - "movq %%mm0, %%mm3;" /* Copy Cblue */\ - "movq %%mm1, %%mm4;" /* Copy Cred */\ - "movq %%mm2, %%mm5;" /* Copy Cgreen */\ + /* Do the addition part of the conversion for even and odd pixels, + register usage: + mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels, + mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels, + mm6 -> Y even, mm7 -> Y odd */\ + "movq %%mm0, %%mm3;" /* Copy Cblue */\ + "movq %%mm1, %%mm4;" /* Copy Cred */\ + "movq %%mm2, %%mm5;" /* Copy Cgreen */\ \ - "paddsw %%mm6, %%mm0;" /* Y even + Cblue 00 B6 00 B4 00 B2 00 B0 */\ - "paddsw %%mm7, %%mm3;" /* Y odd + Cblue 00 B7 00 B5 00 B3 00 B1 */\ + "paddsw %%mm6, %%mm0;" /* Y even + Cblue 00 B6 00 B4 00 B2 00 B0 */\ + "paddsw %%mm7, %%mm3;" /* Y odd + Cblue 00 B7 00 B5 00 B3 00 B1 */\ \ - "paddsw %%mm6, %%mm1;" /* Y even + Cred 00 R6 00 R4 00 R2 00 R0 */\ - "paddsw %%mm7, %%mm4;" /* Y odd + Cred 00 R7 00 R5 00 R3 00 R1 */\ + "paddsw %%mm6, %%mm1;" /* Y even + Cred 00 R6 00 R4 00 R2 00 R0 */\ + "paddsw %%mm7, %%mm4;" /* Y odd + Cred 00 R7 00 R5 00 R3 00 R1 */\ \ - "paddsw %%mm6, %%mm2;" /* Y even + Cgreen 00 G6 00 G4 00 G2 00 G0 */\ - "paddsw %%mm7, %%mm5;" /* Y odd + Cgreen 00 G7 00 G5 00 G3 00 G1 */\ + "paddsw %%mm6, %%mm2;" /* Y even + Cgreen 00 G6 00 G4 00 G2 00 G0 */\ + "paddsw %%mm7, %%mm5;" /* Y odd + Cgreen 00 G7 00 G5 00 G3 00 G1 */\ \ - /* Limit RGB even to 0..255 */\ - "packuswb %%mm0, %%mm0;" /* B6 B4 B2 B0 B6 B4 B2 B0 */\ - "packuswb %%mm1, %%mm1;" /* R6 R4 R2 R0 R6 R4 R2 R0 */\ - "packuswb %%mm2, %%mm2;" /* G6 G4 G2 G0 G6 G4 G2 G0 */\ + /* Limit RGB even to 0..255 */\ + "packuswb %%mm0, %%mm0;" /* B6 B4 B2 B0 B6 B4 B2 B0 */\ + "packuswb %%mm1, %%mm1;" /* R6 R4 R2 R0 R6 R4 R2 R0 */\ + "packuswb %%mm2, %%mm2;" /* G6 G4 G2 G0 G6 G4 G2 G0 */\ \ - /* Limit RGB odd to 0..255 */\ - "packuswb %%mm3, %%mm3;" /* B7 B5 B3 B1 B7 B5 B3 B1 */\ - "packuswb %%mm4, %%mm4;" /* R7 R5 R3 R1 R7 R5 R3 R1 */\ - "packuswb %%mm5, %%mm5;" /* G7 G5 G3 G1 G7 G5 G3 G1 */\ + /* Limit RGB odd to 0..255 */\ + "packuswb %%mm3, %%mm3;" /* B7 B5 B3 B1 B7 B5 B3 B1 */\ + "packuswb %%mm4, %%mm4;" /* R7 R5 R3 R1 R7 R5 R3 R1 */\ + "packuswb %%mm5, %%mm5;" /* G7 G5 G3 G1 G7 G5 G3 G1 */\ \ - /* Interleave RGB even and odd */\ - "punpcklbw %%mm3, %%mm0;" /* B7 B6 B5 B4 B3 B2 B1 B0 */\ - "punpcklbw %%mm4, %%mm1;" /* R7 R6 R5 R4 R3 R2 R1 R0 */\ - "punpcklbw %%mm5, %%mm2;" /* G7 G6 G5 G4 G3 G2 G1 G0 */\ + /* Interleave RGB even and odd */\ + "punpcklbw %%mm3, %%mm0;" /* B7 B6 B5 B4 B3 B2 B1 B0 */\ + "punpcklbw %%mm4, %%mm1;" /* R7 R6 R5 R4 R3 R2 R1 R0 */\ + "punpcklbw %%mm5, %%mm2;" /* G7 G6 G5 G4 G3 G2 G1 G0 */\ static inline int RENAME(yuv420_rgb16)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]){ + int srcSliceH, uint8_t* dst[], int dstStride[]){ int y, h_size; if(c->srcFormat == PIX_FMT_YUV422P){ - srcStride[1] *= 2; - srcStride[2] *= 2; + srcStride[1] *= 2; + srcStride[2] *= 2; } h_size= (c->dstW+7)&~7; if(h_size*2 > FFABS(dstStride[0])) h_size-=8; - + __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ ); -//printf("%X %X %X %X %X %X %X %X %X %X\n", (int)&c->redDither, (int)&b5Dither, (int)src[0], (int)src[1], (int)src[2], (int)dst[0], -//srcStride[0],srcStride[1],srcStride[2],dstStride[0]); + //printf("%X %X %X %X %X %X %X %X %X %X\n", (int)&c->redDither, (int)&b5Dither, (int)src[0], (int)src[1], (int)src[2], (int)dst[0], + //srcStride[0],srcStride[1],srcStride[2],dstStride[0]); for (y= 0; y>1)*srcStride[1]; - uint8_t *_pv = src[2] + (y>>1)*srcStride[2]; - long index= -h_size/2; - - b5Dither= dither8[y&1]; - g6Dither= dither4[y&1]; - g5Dither= dither8[y&1]; - r5Dither= dither8[(y+1)&1]; - /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8 - pixels in each iteration */ - __asm__ __volatile__ ( - /* load data for start of next scan line */ - "movd (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ - "movd (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ - "movq (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ -// ".balign 16 \n\t" - "1: \n\t" -/* no speed diference on my p3@500 with prefetch, - * if it is faster for anyone with -benchmark then tell me - PREFETCH" 64(%0) \n\t" - PREFETCH" 64(%1) \n\t" - PREFETCH" 64(%2) \n\t" -*/ + uint8_t *image = dst[0] + (y+srcSliceY)*dstStride[0]; + uint8_t *py = src[0] + y*srcStride[0]; + uint8_t *pu = src[1] + (y>>1)*srcStride[1]; + uint8_t *pv = src[2] + (y>>1)*srcStride[2]; + long index= -h_size/2; + + b5Dither= ff_dither8[y&1]; + g6Dither= ff_dither4[y&1]; + g5Dither= ff_dither8[y&1]; + r5Dither= ff_dither8[(y+1)&1]; + /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8 + pixels in each iteration */ + __asm__ __volatile__ ( + /* load data for start of next scan line */ + "movd (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ + "movd (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ + "movq (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ + //".balign 16 \n\t" + "1: \n\t" + /* no speed diference on my p3@500 with prefetch, + * if it is faster for anyone with -benchmark then tell me + PREFETCH" 64(%0) \n\t" + PREFETCH" 64(%1) \n\t" + PREFETCH" 64(%2) \n\t" + */ YUV2RGB #ifdef DITHER1XBPP - "paddusb "MANGLE(b5Dither)", %%mm0;" - "paddusb "MANGLE(g6Dither)", %%mm2;" - "paddusb "MANGLE(r5Dither)", %%mm1;" + "paddusb "MANGLE(b5Dither)", %%mm0;" + "paddusb "MANGLE(g6Dither)", %%mm2;" + "paddusb "MANGLE(r5Dither)", %%mm1;" #endif - /* mask unneeded bits off */ - "pand "MANGLE(mmx_redmask)", %%mm0;" /* b7b6b5b4 b3_0_0_0 b7b6b5b4 b3_0_0_0 */ - "pand "MANGLE(mmx_grnmask)", %%mm2;" /* g7g6g5g4 g3g2_0_0 g7g6g5g4 g3g2_0_0 */ - "pand "MANGLE(mmx_redmask)", %%mm1;" /* r7r6r5r4 r3_0_0_0 r7r6r5r4 r3_0_0_0 */ - - "psrlw $3,%%mm0;" /* 0_0_0_b7 b6b5b4b3 0_0_0_b7 b6b5b4b3 */ - "pxor %%mm4, %%mm4;" /* zero mm4 */ - - "movq %%mm0, %%mm5;" /* Copy B7-B0 */ - "movq %%mm2, %%mm7;" /* Copy G7-G0 */ - - /* convert rgb24 plane to rgb16 pack for pixel 0-3 */ - "punpcklbw %%mm4, %%mm2;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0 */ - "punpcklbw %%mm1, %%mm0;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ - - "psllw $3, %%mm2;" /* 0_0_0_0 0_g7g6g5 g4g3g2_0 0_0_0_0 */ - "por %%mm2, %%mm0;" /* r7r6r5r4 r3g7g6g5 g4g3g2b7 b6b5b4b3 */ - - "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ - MOVNTQ " %%mm0, (%1);" /* store pixel 0-3 */ - - /* convert rgb24 plane to rgb16 pack for pixel 0-3 */ - "punpckhbw %%mm4, %%mm7;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0 */ - "punpckhbw %%mm1, %%mm5;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ - - "psllw $3, %%mm7;" /* 0_0_0_0 0_g7g6g5 g4g3g2_0 0_0_0_0 */ - "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ - - "por %%mm7, %%mm5;" /* r7r6r5r4 r3g7g6g5 g4g3g2b7 b6b5b4b3 */ - "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ - - MOVNTQ " %%mm5, 8 (%1);" /* store pixel 4-7 */ - - "add $16, %1 \n\t" - "add $4, %0 \n\t" - " js 1b \n\t" - - : "+r" (index), "+r" (_image) - : "r" (_pu - index), "r" (_pv - index), "r"(&c->redDither), "r" (_py - 2*index) - ); + /* mask unneeded bits off */ + "pand "MANGLE(mmx_redmask)", %%mm0;" /* b7b6b5b4 b3_0_0_0 b7b6b5b4 b3_0_0_0 */ + "pand "MANGLE(mmx_grnmask)", %%mm2;" /* g7g6g5g4 g3g2_0_0 g7g6g5g4 g3g2_0_0 */ + "pand "MANGLE(mmx_redmask)", %%mm1;" /* r7r6r5r4 r3_0_0_0 r7r6r5r4 r3_0_0_0 */ + + "psrlw $3, %%mm0;" /* 0_0_0_b7 b6b5b4b3 0_0_0_b7 b6b5b4b3 */ + "pxor %%mm4, %%mm4;" /* zero mm4 */ + + "movq %%mm0, %%mm5;" /* Copy B7-B0 */ + "movq %%mm2, %%mm7;" /* Copy G7-G0 */ + + /* convert rgb24 plane to rgb16 pack for pixel 0-3 */ + "punpcklbw %%mm4, %%mm2;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0 */ + "punpcklbw %%mm1, %%mm0;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ + + "psllw $3, %%mm2;" /* 0_0_0_0 0_g7g6g5 g4g3g2_0 0_0_0_0 */ + "por %%mm2, %%mm0;" /* r7r6r5r4 r3g7g6g5 g4g3g2b7 b6b5b4b3 */ + + "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ + MOVNTQ " %%mm0, (%1);" /* store pixel 0-3 */ + + /* convert rgb24 plane to rgb16 pack for pixel 0-3 */ + "punpckhbw %%mm4, %%mm7;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0 */ + "punpckhbw %%mm1, %%mm5;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ + + "psllw $3, %%mm7;" /* 0_0_0_0 0_g7g6g5 g4g3g2_0 0_0_0_0 */ + "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ + + "por %%mm7, %%mm5;" /* r7r6r5r4 r3g7g6g5 g4g3g2b7 b6b5b4b3 */ + "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ + + MOVNTQ " %%mm5, 8 (%1);" /* store pixel 4-7 */ + + "add $16, %1 \n\t" + "add $4, %0 \n\t" + " js 1b \n\t" + + : "+r" (index), "+r" (image) + : "r" (pu - index), "r" (pv - index), "r"(&c->redDither), "r" (py - 2*index) + ); } __asm__ __volatile__ (EMMS); - + return srcSliceH; } static inline int RENAME(yuv420_rgb15)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]){ + int srcSliceH, uint8_t* dst[], int dstStride[]){ int y, h_size; if(c->srcFormat == PIX_FMT_YUV422P){ - srcStride[1] *= 2; - srcStride[2] *= 2; + srcStride[1] *= 2; + srcStride[2] *= 2; } h_size= (c->dstW+7)&~7; if(h_size*2 > FFABS(dstStride[0])) h_size-=8; - + __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ ); -//printf("%X %X %X %X %X %X %X %X %X %X\n", (int)&c->redDither, (int)&b5Dither, (int)src[0], (int)src[1], (int)src[2], (int)dst[0], -//srcStride[0],srcStride[1],srcStride[2],dstStride[0]); + //printf("%X %X %X %X %X %X %X %X %X %X\n", (int)&c->redDither, (int)&b5Dither, (int)src[0], (int)src[1], (int)src[2], (int)dst[0], + //srcStride[0],srcStride[1],srcStride[2],dstStride[0]); for (y= 0; y>1)*srcStride[1]; - uint8_t *_pv = src[2] + (y>>1)*srcStride[2]; - long index= -h_size/2; - - b5Dither= dither8[y&1]; - g6Dither= dither4[y&1]; - g5Dither= dither8[y&1]; - r5Dither= dither8[(y+1)&1]; - /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8 - pixels in each iteration */ - __asm__ __volatile__ ( - /* load data for start of next scan line */ - "movd (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ - "movd (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ - "movq (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ -// ".balign 16 \n\t" - "1: \n\t" + uint8_t *image = dst[0] + (y+srcSliceY)*dstStride[0]; + uint8_t *py = src[0] + y*srcStride[0]; + uint8_t *pu = src[1] + (y>>1)*srcStride[1]; + uint8_t *pv = src[2] + (y>>1)*srcStride[2]; + long index= -h_size/2; + + b5Dither= ff_dither8[y&1]; + g6Dither= ff_dither4[y&1]; + g5Dither= ff_dither8[y&1]; + r5Dither= ff_dither8[(y+1)&1]; + /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8 + pixels in each iteration */ + __asm__ __volatile__ ( + /* load data for start of next scan line */ + "movd (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ + "movd (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ + "movq (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ + //".balign 16 \n\t" + "1: \n\t" YUV2RGB #ifdef DITHER1XBPP - "paddusb "MANGLE(b5Dither)", %%mm0 \n\t" - "paddusb "MANGLE(g5Dither)", %%mm2 \n\t" - "paddusb "MANGLE(r5Dither)", %%mm1 \n\t" + "paddusb "MANGLE(b5Dither)", %%mm0 \n\t" + "paddusb "MANGLE(g5Dither)", %%mm2 \n\t" + "paddusb "MANGLE(r5Dither)", %%mm1 \n\t" #endif - /* mask unneeded bits off */ - "pand "MANGLE(mmx_redmask)", %%mm0;" /* b7b6b5b4 b3_0_0_0 b7b6b5b4 b3_0_0_0 */ - "pand "MANGLE(mmx_redmask)", %%mm2;" /* g7g6g5g4 g3_0_0_0 g7g6g5g4 g3_0_0_0 */ - "pand "MANGLE(mmx_redmask)", %%mm1;" /* r7r6r5r4 r3_0_0_0 r7r6r5r4 r3_0_0_0 */ + /* mask unneeded bits off */ + "pand "MANGLE(mmx_redmask)", %%mm0;" /* b7b6b5b4 b3_0_0_0 b7b6b5b4 b3_0_0_0 */ + "pand "MANGLE(mmx_redmask)", %%mm2;" /* g7g6g5g4 g3_0_0_0 g7g6g5g4 g3_0_0_0 */ + "pand "MANGLE(mmx_redmask)", %%mm1;" /* r7r6r5r4 r3_0_0_0 r7r6r5r4 r3_0_0_0 */ + + "psrlw $3, %%mm0;" /* 0_0_0_b7 b6b5b4b3 0_0_0_b7 b6b5b4b3 */ + "psrlw $1, %%mm1;" /* 0_r7r6r5 r4r3_0_0 0_r7r6r5 r4r3_0_0 */ + "pxor %%mm4, %%mm4;" /* zero mm4 */ - "psrlw $3,%%mm0;" /* 0_0_0_b7 b6b5b4b3 0_0_0_b7 b6b5b4b3 */ - "psrlw $1,%%mm1;" /* 0_r7r6r5 r4r3_0_0 0_r7r6r5 r4r3_0_0 */ - "pxor %%mm4, %%mm4;" /* zero mm4 */ + "movq %%mm0, %%mm5;" /* Copy B7-B0 */ + "movq %%mm2, %%mm7;" /* Copy G7-G0 */ - "movq %%mm0, %%mm5;" /* Copy B7-B0 */ - "movq %%mm2, %%mm7;" /* Copy G7-G0 */ + /* convert rgb24 plane to rgb16 pack for pixel 0-3 */ + "punpcklbw %%mm4, %%mm2;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3_0_0_0 */ + "punpcklbw %%mm1, %%mm0;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ - /* convert rgb24 plane to rgb16 pack for pixel 0-3 */ - "punpcklbw %%mm4, %%mm2;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3_0_0_0 */ - "punpcklbw %%mm1, %%mm0;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ + "psllw $2, %%mm2;" /* 0_0_0_0 0_0_g7g6 g5g4g3_0 0_0_0_0 */ + "por %%mm2, %%mm0;" /* 0_r7r6r5 r4r3g7g6 g5g4g3b7 b6b5b4b3 */ - "psllw $2, %%mm2;" /* 0_0_0_0 0_0_g7g6 g5g4g3_0 0_0_0_0 */ - "por %%mm2, %%mm0;" /* 0_r7r6r5 r4r3g7g6 g5g4g3b7 b6b5b4b3 */ + "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ + MOVNTQ " %%mm0, (%1);" /* store pixel 0-3 */ - "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ - MOVNTQ " %%mm0, (%1);" /* store pixel 0-3 */ + /* convert rgb24 plane to rgb16 pack for pixel 0-3 */ + "punpckhbw %%mm4, %%mm7;" /* 0_0_0_0 0_0_0_0 0_g7g6g5 g4g3_0_0 */ + "punpckhbw %%mm1, %%mm5;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ - /* convert rgb24 plane to rgb16 pack for pixel 0-3 */ - "punpckhbw %%mm4, %%mm7;" /* 0_0_0_0 0_0_0_0 0_g7g6g5 g4g3_0_0 */ - "punpckhbw %%mm1, %%mm5;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */ + "psllw $2, %%mm7;" /* 0_0_0_0 0_0_g7g6 g5g4g3_0 0_0_0_0 */ + "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ - "psllw $2, %%mm7;" /* 0_0_0_0 0_0_g7g6 g5g4g3_0 0_0_0_0 */ - "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ + "por %%mm7, %%mm5;" /* 0_r7r6r5 r4r3g7g6 g5g4g3b7 b6b5b4b3 */ + "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ - "por %%mm7, %%mm5;" /* 0_r7r6r5 r4r3g7g6 g5g4g3b7 b6b5b4b3 */ - "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ + MOVNTQ " %%mm5, 8 (%1);" /* store pixel 4-7 */ - MOVNTQ " %%mm5, 8 (%1);" /* store pixel 4-7 */ - - "add $16, %1 \n\t" - "add $4, %0 \n\t" - " js 1b \n\t" - : "+r" (index), "+r" (_image) - : "r" (_pu - index), "r" (_pv - index), "r"(&c->redDither), "r" (_py - 2*index) - ); + "add $16, %1 \n\t" + "add $4, %0 \n\t" + " js 1b \n\t" + : "+r" (index), "+r" (image) + : "r" (pu - index), "r" (pv - index), "r"(&c->redDither), "r" (py - 2*index) + ); } __asm__ __volatile__ (EMMS); @@ -308,145 +306,145 @@ YUV2RGB } static inline int RENAME(yuv420_rgb24)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]){ + int srcSliceH, uint8_t* dst[], int dstStride[]){ int y, h_size; if(c->srcFormat == PIX_FMT_YUV422P){ - srcStride[1] *= 2; - srcStride[2] *= 2; + srcStride[1] *= 2; + srcStride[2] *= 2; } h_size= (c->dstW+7)&~7; if(h_size*3 > FFABS(dstStride[0])) h_size-=8; - + __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ ); for (y= 0; y>1)*srcStride[1]; - uint8_t *_pv = src[2] + (y>>1)*srcStride[2]; - long index= -h_size/2; - - /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8 - pixels in each iteration */ - __asm__ __volatile__ ( - /* load data for start of next scan line */ - "movd (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ - "movd (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ - "movq (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ -// ".balign 16 \n\t" - "1: \n\t" + uint8_t *image = dst[0] + (y+srcSliceY)*dstStride[0]; + uint8_t *py = src[0] + y*srcStride[0]; + uint8_t *pu = src[1] + (y>>1)*srcStride[1]; + uint8_t *pv = src[2] + (y>>1)*srcStride[2]; + long index= -h_size/2; + + /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8 + pixels in each iteration */ + __asm__ __volatile__ ( + /* load data for start of next scan line */ + "movd (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ + "movd (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ + "movq (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ + //".balign 16 \n\t" + "1: \n\t" YUV2RGB - /* mm0=B, %%mm2=G, %%mm1=R */ + /* mm0=B, %%mm2=G, %%mm1=R */ #ifdef HAVE_MMX2 - "movq "MANGLE(M24A)", %%mm4 \n\t" - "movq "MANGLE(M24C)", %%mm7 \n\t" - "pshufw $0x50, %%mm0, %%mm5 \n\t" /* B3 B2 B3 B2 B1 B0 B1 B0 */ - "pshufw $0x50, %%mm2, %%mm3 \n\t" /* G3 G2 G3 G2 G1 G0 G1 G0 */ - "pshufw $0x00, %%mm1, %%mm6 \n\t" /* R1 R0 R1 R0 R1 R0 R1 R0 */ - - "pand %%mm4, %%mm5 \n\t" /* B2 B1 B0 */ - "pand %%mm4, %%mm3 \n\t" /* G2 G1 G0 */ - "pand %%mm7, %%mm6 \n\t" /* R1 R0 */ - - "psllq $8, %%mm3 \n\t" /* G2 G1 G0 */ - "por %%mm5, %%mm6 \n\t" - "por %%mm3, %%mm6 \n\t" - MOVNTQ" %%mm6, (%1) \n\t" - - "psrlq $8, %%mm2 \n\t" /* 00 G7 G6 G5 G4 G3 G2 G1 */ - "pshufw $0xA5, %%mm0, %%mm5 \n\t" /* B5 B4 B5 B4 B3 B2 B3 B2 */ - "pshufw $0x55, %%mm2, %%mm3 \n\t" /* G4 G3 G4 G3 G4 G3 G4 G3 */ - "pshufw $0xA5, %%mm1, %%mm6 \n\t" /* R5 R4 R5 R4 R3 R2 R3 R2 */ - - "pand "MANGLE(M24B)", %%mm5 \n\t" /* B5 B4 B3 */ - "pand %%mm7, %%mm3 \n\t" /* G4 G3 */ - "pand %%mm4, %%mm6 \n\t" /* R4 R3 R2 */ - - "por %%mm5, %%mm3 \n\t" /* B5 G4 B4 G3 B3 */ - "por %%mm3, %%mm6 \n\t" - MOVNTQ" %%mm6, 8(%1) \n\t" - - "pshufw $0xFF, %%mm0, %%mm5 \n\t" /* B7 B6 B7 B6 B7 B6 B6 B7 */ - "pshufw $0xFA, %%mm2, %%mm3 \n\t" /* 00 G7 00 G7 G6 G5 G6 G5 */ - "pshufw $0xFA, %%mm1, %%mm6 \n\t" /* R7 R6 R7 R6 R5 R4 R5 R4 */ - "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ - - "pand %%mm7, %%mm5 \n\t" /* B7 B6 */ - "pand %%mm4, %%mm3 \n\t" /* G7 G6 G5 */ - "pand "MANGLE(M24B)", %%mm6 \n\t" /* R7 R6 R5 */ - "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ + "movq "MANGLE(ff_M24A)", %%mm4 \n\t" + "movq "MANGLE(ff_M24C)", %%mm7 \n\t" + "pshufw $0x50, %%mm0, %%mm5 \n\t" /* B3 B2 B3 B2 B1 B0 B1 B0 */ + "pshufw $0x50, %%mm2, %%mm3 \n\t" /* G3 G2 G3 G2 G1 G0 G1 G0 */ + "pshufw $0x00, %%mm1, %%mm6 \n\t" /* R1 R0 R1 R0 R1 R0 R1 R0 */ + + "pand %%mm4, %%mm5 \n\t" /* B2 B1 B0 */ + "pand %%mm4, %%mm3 \n\t" /* G2 G1 G0 */ + "pand %%mm7, %%mm6 \n\t" /* R1 R0 */ + + "psllq $8, %%mm3 \n\t" /* G2 G1 G0 */ + "por %%mm5, %%mm6 \n\t" + "por %%mm3, %%mm6 \n\t" + MOVNTQ" %%mm6, (%1) \n\t" + + "psrlq $8, %%mm2 \n\t" /* 00 G7 G6 G5 G4 G3 G2 G1 */ + "pshufw $0xA5, %%mm0, %%mm5 \n\t" /* B5 B4 B5 B4 B3 B2 B3 B2 */ + "pshufw $0x55, %%mm2, %%mm3 \n\t" /* G4 G3 G4 G3 G4 G3 G4 G3 */ + "pshufw $0xA5, %%mm1, %%mm6 \n\t" /* R5 R4 R5 R4 R3 R2 R3 R2 */ + + "pand "MANGLE(ff_M24B)", %%mm5 \n\t" /* B5 B4 B3 */ + "pand %%mm7, %%mm3 \n\t" /* G4 G3 */ + "pand %%mm4, %%mm6 \n\t" /* R4 R3 R2 */ + + "por %%mm5, %%mm3 \n\t" /* B5 G4 B4 G3 B3 */ + "por %%mm3, %%mm6 \n\t" + MOVNTQ" %%mm6, 8(%1) \n\t" + + "pshufw $0xFF, %%mm0, %%mm5 \n\t" /* B7 B6 B7 B6 B7 B6 B6 B7 */ + "pshufw $0xFA, %%mm2, %%mm3 \n\t" /* 00 G7 00 G7 G6 G5 G6 G5 */ + "pshufw $0xFA, %%mm1, %%mm6 \n\t" /* R7 R6 R7 R6 R5 R4 R5 R4 */ + "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ + + "pand %%mm7, %%mm5 \n\t" /* B7 B6 */ + "pand %%mm4, %%mm3 \n\t" /* G7 G6 G5 */ + "pand "MANGLE(ff_M24B)", %%mm6 \n\t" /* R7 R6 R5 */ + "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ \ - "por %%mm5, %%mm3 \n\t" - "por %%mm3, %%mm6 \n\t" - MOVNTQ" %%mm6, 16(%1) \n\t" - "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ - "pxor %%mm4, %%mm4 \n\t" + "por %%mm5, %%mm3 \n\t" + "por %%mm3, %%mm6 \n\t" + MOVNTQ" %%mm6, 16(%1) \n\t" + "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ + "pxor %%mm4, %%mm4 \n\t" #else - "pxor %%mm4, %%mm4 \n\t" - "movq %%mm0, %%mm5 \n\t" /* B */ - "movq %%mm1, %%mm6 \n\t" /* R */ - "punpcklbw %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */ - "punpcklbw %%mm4, %%mm1 \n\t" /* 0R0R0R0R 0 */ - "punpckhbw %%mm2, %%mm5 \n\t" /* GBGBGBGB 2 */ - "punpckhbw %%mm4, %%mm6 \n\t" /* 0R0R0R0R 2 */ - "movq %%mm0, %%mm7 \n\t" /* GBGBGBGB 0 */ - "movq %%mm5, %%mm3 \n\t" /* GBGBGBGB 2 */ - "punpcklwd %%mm1, %%mm7 \n\t" /* 0RGB0RGB 0 */ - "punpckhwd %%mm1, %%mm0 \n\t" /* 0RGB0RGB 1 */ - "punpcklwd %%mm6, %%mm5 \n\t" /* 0RGB0RGB 2 */ - "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */ - - "movq %%mm7, %%mm2 \n\t" /* 0RGB0RGB 0 */ - "movq %%mm0, %%mm6 \n\t" /* 0RGB0RGB 1 */ - "movq %%mm5, %%mm1 \n\t" /* 0RGB0RGB 2 */ - "movq %%mm3, %%mm4 \n\t" /* 0RGB0RGB 3 */ - - "psllq $40, %%mm7 \n\t" /* RGB00000 0 */ - "psllq $40, %%mm0 \n\t" /* RGB00000 1 */ - "psllq $40, %%mm5 \n\t" /* RGB00000 2 */ - "psllq $40, %%mm3 \n\t" /* RGB00000 3 */ - - "punpckhdq %%mm2, %%mm7 \n\t" /* 0RGBRGB0 0 */ - "punpckhdq %%mm6, %%mm0 \n\t" /* 0RGBRGB0 1 */ - "punpckhdq %%mm1, %%mm5 \n\t" /* 0RGBRGB0 2 */ - "punpckhdq %%mm4, %%mm3 \n\t" /* 0RGBRGB0 3 */ - - "psrlq $8, %%mm7 \n\t" /* 00RGBRGB 0 */ - "movq %%mm0, %%mm6 \n\t" /* 0RGBRGB0 1 */ - "psllq $40, %%mm0 \n\t" /* GB000000 1 */ - "por %%mm0, %%mm7 \n\t" /* GBRGBRGB 0 */ - MOVNTQ" %%mm7, (%1) \n\t" - - "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ - - "psrlq $24, %%mm6 \n\t" /* 0000RGBR 1 */ - "movq %%mm5, %%mm1 \n\t" /* 0RGBRGB0 2 */ - "psllq $24, %%mm5 \n\t" /* BRGB0000 2 */ - "por %%mm5, %%mm6 \n\t" /* BRGBRGBR 1 */ - MOVNTQ" %%mm6, 8(%1) \n\t" - - "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ - - "psrlq $40, %%mm1 \n\t" /* 000000RG 2 */ - "psllq $8, %%mm3 \n\t" /* RGBRGB00 3 */ - "por %%mm3, %%mm1 \n\t" /* RGBRGBRG 2 */ - MOVNTQ" %%mm1, 16(%1) \n\t" - - "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ - "pxor %%mm4, %%mm4 \n\t" + "pxor %%mm4, %%mm4 \n\t" + "movq %%mm0, %%mm5 \n\t" /* B */ + "movq %%mm1, %%mm6 \n\t" /* R */ + "punpcklbw %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */ + "punpcklbw %%mm4, %%mm1 \n\t" /* 0R0R0R0R 0 */ + "punpckhbw %%mm2, %%mm5 \n\t" /* GBGBGBGB 2 */ + "punpckhbw %%mm4, %%mm6 \n\t" /* 0R0R0R0R 2 */ + "movq %%mm0, %%mm7 \n\t" /* GBGBGBGB 0 */ + "movq %%mm5, %%mm3 \n\t" /* GBGBGBGB 2 */ + "punpcklwd %%mm1, %%mm7 \n\t" /* 0RGB0RGB 0 */ + "punpckhwd %%mm1, %%mm0 \n\t" /* 0RGB0RGB 1 */ + "punpcklwd %%mm6, %%mm5 \n\t" /* 0RGB0RGB 2 */ + "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */ + + "movq %%mm7, %%mm2 \n\t" /* 0RGB0RGB 0 */ + "movq %%mm0, %%mm6 \n\t" /* 0RGB0RGB 1 */ + "movq %%mm5, %%mm1 \n\t" /* 0RGB0RGB 2 */ + "movq %%mm3, %%mm4 \n\t" /* 0RGB0RGB 3 */ + + "psllq $40, %%mm7 \n\t" /* RGB00000 0 */ + "psllq $40, %%mm0 \n\t" /* RGB00000 1 */ + "psllq $40, %%mm5 \n\t" /* RGB00000 2 */ + "psllq $40, %%mm3 \n\t" /* RGB00000 3 */ + + "punpckhdq %%mm2, %%mm7 \n\t" /* 0RGBRGB0 0 */ + "punpckhdq %%mm6, %%mm0 \n\t" /* 0RGBRGB0 1 */ + "punpckhdq %%mm1, %%mm5 \n\t" /* 0RGBRGB0 2 */ + "punpckhdq %%mm4, %%mm3 \n\t" /* 0RGBRGB0 3 */ + + "psrlq $8, %%mm7 \n\t" /* 00RGBRGB 0 */ + "movq %%mm0, %%mm6 \n\t" /* 0RGBRGB0 1 */ + "psllq $40, %%mm0 \n\t" /* GB000000 1 */ + "por %%mm0, %%mm7 \n\t" /* GBRGBRGB 0 */ + MOVNTQ" %%mm7, (%1) \n\t" + + "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ + + "psrlq $24, %%mm6 \n\t" /* 0000RGBR 1 */ + "movq %%mm5, %%mm1 \n\t" /* 0RGBRGB0 2 */ + "psllq $24, %%mm5 \n\t" /* BRGB0000 2 */ + "por %%mm5, %%mm6 \n\t" /* BRGBRGBR 1 */ + MOVNTQ" %%mm6, 8(%1) \n\t" + + "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ + + "psrlq $40, %%mm1 \n\t" /* 000000RG 2 */ + "psllq $8, %%mm3 \n\t" /* RGBRGB00 3 */ + "por %%mm3, %%mm1 \n\t" /* RGBRGBRG 2 */ + MOVNTQ" %%mm1, 16(%1) \n\t" + + "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ + "pxor %%mm4, %%mm4 \n\t" #endif - - "add $24, %1 \n\t" - "add $4, %0 \n\t" - " js 1b \n\t" - - : "+r" (index), "+r" (_image) - : "r" (_pu - index), "r" (_pv - index), "r"(&c->redDither), "r" (_py - 2*index) - ); + + "add $24, %1 \n\t" + "add $4, %0 \n\t" + " js 1b \n\t" + + : "+r" (index), "+r" (image) + : "r" (pu - index), "r" (pv - index), "r"(&c->redDither), "r" (py - 2*index) + ); } __asm__ __volatile__ (EMMS); @@ -454,85 +452,85 @@ YUV2RGB } static inline int RENAME(yuv420_rgb32)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, - int srcSliceH, uint8_t* dst[], int dstStride[]){ + int srcSliceH, uint8_t* dst[], int dstStride[]){ int y, h_size; if(c->srcFormat == PIX_FMT_YUV422P){ - srcStride[1] *= 2; - srcStride[2] *= 2; + srcStride[1] *= 2; + srcStride[2] *= 2; } h_size= (c->dstW+7)&~7; if(h_size*4 > FFABS(dstStride[0])) h_size-=8; - + __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ ); for (y= 0; y>1)*srcStride[1]; - uint8_t *_pv = src[2] + (y>>1)*srcStride[2]; - long index= -h_size/2; - - /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8 - pixels in each iteration */ - __asm__ __volatile__ ( - /* load data for start of next scan line */ - "movd (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ - "movd (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ - "movq (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ -// ".balign 16 \n\t" - "1: \n\t" + uint8_t *image = dst[0] + (y+srcSliceY)*dstStride[0]; + uint8_t *py = src[0] + y*srcStride[0]; + uint8_t *pu = src[1] + (y>>1)*srcStride[1]; + uint8_t *pv = src[2] + (y>>1)*srcStride[2]; + long index= -h_size/2; + + /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8 + pixels in each iteration */ + __asm__ __volatile__ ( + /* load data for start of next scan line */ + "movd (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ + "movd (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ + "movq (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ + //".balign 16 \n\t" + "1: \n\t" YUV2RGB - /* convert RGB plane to RGB packed format, - mm0 -> B, mm1 -> R, mm2 -> G, mm3 -> 0, - mm4 -> GB, mm5 -> AR pixel 4-7, - mm6 -> GB, mm7 -> AR pixel 0-3 */ - "pxor %%mm3, %%mm3;" /* zero mm3 */ + /* convert RGB plane to RGB packed format, + mm0 -> B, mm1 -> R, mm2 -> G, mm3 -> 0, + mm4 -> GB, mm5 -> AR pixel 4-7, + mm6 -> GB, mm7 -> AR pixel 0-3 */ + "pxor %%mm3, %%mm3;" /* zero mm3 */ + + "movq %%mm0, %%mm6;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ + "movq %%mm1, %%mm7;" /* R7 R6 R5 R4 R3 R2 R1 R0 */ - "movq %%mm0, %%mm6;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ - "movq %%mm1, %%mm7;" /* R7 R6 R5 R4 R3 R2 R1 R0 */ + "movq %%mm0, %%mm4;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ + "movq %%mm1, %%mm5;" /* R7 R6 R5 R4 R3 R2 R1 R0 */ - "movq %%mm0, %%mm4;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ - "movq %%mm1, %%mm5;" /* R7 R6 R5 R4 R3 R2 R1 R0 */ + "punpcklbw %%mm2, %%mm6;" /* G3 B3 G2 B2 G1 B1 G0 B0 */ + "punpcklbw %%mm3, %%mm7;" /* 00 R3 00 R2 00 R1 00 R0 */ - "punpcklbw %%mm2, %%mm6;" /* G3 B3 G2 B2 G1 B1 G0 B0 */ - "punpcklbw %%mm3, %%mm7;" /* 00 R3 00 R2 00 R1 00 R0 */ + "punpcklwd %%mm7, %%mm6;" /* 00 R1 B1 G1 00 R0 B0 G0 */ + MOVNTQ " %%mm6, (%1);" /* Store ARGB1 ARGB0 */ - "punpcklwd %%mm7, %%mm6;" /* 00 R1 B1 G1 00 R0 B0 G0 */ - MOVNTQ " %%mm6, (%1);" /* Store ARGB1 ARGB0 */ + "movq %%mm0, %%mm6;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ + "punpcklbw %%mm2, %%mm6;" /* G3 B3 G2 B2 G1 B1 G0 B0 */ - "movq %%mm0, %%mm6;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ - "punpcklbw %%mm2, %%mm6;" /* G3 B3 G2 B2 G1 B1 G0 B0 */ + "punpckhwd %%mm7, %%mm6;" /* 00 R3 G3 B3 00 R2 B3 G2 */ + MOVNTQ " %%mm6, 8 (%1);" /* Store ARGB3 ARGB2 */ - "punpckhwd %%mm7, %%mm6;" /* 00 R3 G3 B3 00 R2 B3 G2 */ - MOVNTQ " %%mm6, 8 (%1);" /* Store ARGB3 ARGB2 */ + "punpckhbw %%mm2, %%mm4;" /* G7 B7 G6 B6 G5 B5 G4 B4 */ + "punpckhbw %%mm3, %%mm5;" /* 00 R7 00 R6 00 R5 00 R4 */ - "punpckhbw %%mm2, %%mm4;" /* G7 B7 G6 B6 G5 B5 G4 B4 */ - "punpckhbw %%mm3, %%mm5;" /* 00 R7 00 R6 00 R5 00 R4 */ + "punpcklwd %%mm5, %%mm4;" /* 00 R5 B5 G5 00 R4 B4 G4 */ + MOVNTQ " %%mm4, 16 (%1);" /* Store ARGB5 ARGB4 */ - "punpcklwd %%mm5, %%mm4;" /* 00 R5 B5 G5 00 R4 B4 G4 */ - MOVNTQ " %%mm4, 16 (%1);" /* Store ARGB5 ARGB4 */ + "movq %%mm0, %%mm4;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ + "punpckhbw %%mm2, %%mm4;" /* G7 B7 G6 B6 G5 B5 G4 B4 */ - "movq %%mm0, %%mm4;" /* B7 B6 B5 B4 B3 B2 B1 B0 */ - "punpckhbw %%mm2, %%mm4;" /* G7 B7 G6 B6 G5 B5 G4 B4 */ + "punpckhwd %%mm5, %%mm4;" /* 00 R7 G7 B7 00 R6 B6 G6 */ + MOVNTQ " %%mm4, 24 (%1);" /* Store ARGB7 ARGB6 */ - "punpckhwd %%mm5, %%mm4;" /* 00 R7 G7 B7 00 R6 B6 G6 */ - MOVNTQ " %%mm4, 24 (%1);" /* Store ARGB7 ARGB6 */ + "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ + "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ - "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */ - "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */ + "pxor %%mm4, %%mm4;" /* zero mm4 */ + "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ - "pxor %%mm4, %%mm4;" /* zero mm4 */ - "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */ + "add $32, %1 \n\t" + "add $4, %0 \n\t" + " js 1b \n\t" - "add $32, %1 \n\t" - "add $4, %0 \n\t" - " js 1b \n\t" - - : "+r" (index), "+r" (_image) - : "r" (_pu - index), "r" (_pv - index), "r"(&c->redDither), "r" (_py - 2*index) - ); + : "+r" (index), "+r" (image) + : "r" (pu - index), "r" (pv - index), "r"(&c->redDither), "r" (py - 2*index) + ); } __asm__ __volatile__ (EMMS); diff --git a/contrib/ffmpeg/libswscale/yuv2rgb_vis.c b/contrib/ffmpeg/libswscale/yuv2rgb_vis.c new file mode 100644 index 000000000..618508c47 --- /dev/null +++ b/contrib/ffmpeg/libswscale/yuv2rgb_vis.c @@ -0,0 +1,206 @@ +/* + * VIS optimized software YUV to RGB converter + * Copyright (c) 2007 Denes Balatoni + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +#include "swscale.h" + +#define YUV2RGB_INIT \ + "wr %%g0, 0x10, %%gsr \n\t" \ + "ldd [%5], %%f32 \n\t" \ + "ldd [%5+8], %%f34 \n\t" \ + "ldd [%5+16], %%f36 \n\t" \ + "ldd [%5+24], %%f38 \n\t" \ + "ldd [%5+32], %%f40 \n\t" \ + "ldd [%5+40], %%f42 \n\t" \ + "ldd [%5+48], %%f44 \n\t" \ + "ldd [%5+56], %%f46 \n\t" \ + "ldd [%5+64], %%f48 \n\t" \ + "ldd [%5+72], %%f50 \n\t" + +#define YUV2RGB_KERNEL \ + /* ^^^^ f0=Y f3=u f5=v */ \ + "fmul8x16 %%f3, %%f48, %%f6 \n\t" \ + "fmul8x16 %%f19, %%f48, %%f22 \n\t" \ + "fmul8x16 %%f5, %%f44, %%f8 \n\t" \ + "fmul8x16 %%f21, %%f44, %%f24 \n\t" \ + "fmul8x16 %%f0, %%f42, %%f0 \n\t" \ + "fmul8x16 %%f16, %%f42, %%f16 \n\t" \ + "fmul8x16 %%f3, %%f50, %%f2 \n\t" \ + "fmul8x16 %%f19, %%f50, %%f18 \n\t" \ + "fmul8x16 %%f5, %%f46, %%f4 \n\t" \ + "fmul8x16 %%f21, %%f46, %%f20 \n\t" \ + \ + "fpsub16 %%f6, %%f34, %%f6 \n\t" /* 1 */ \ + "fpsub16 %%f22, %%f34, %%f22 \n\t" /* 1 */ \ + "fpsub16 %%f8, %%f38, %%f8 \n\t" /* 3 */ \ + "fpsub16 %%f24, %%f38, %%f24 \n\t" /* 3 */ \ + "fpsub16 %%f0, %%f32, %%f0 \n\t" /* 0 */ \ + "fpsub16 %%f16, %%f32, %%f16 \n\t" /* 0 */ \ + "fpsub16 %%f2, %%f36, %%f2 \n\t" /* 2 */ \ + "fpsub16 %%f18, %%f36, %%f18 \n\t" /* 2 */ \ + "fpsub16 %%f4, %%f40, %%f4 \n\t" /* 4 */ \ + "fpsub16 %%f20, %%f40, %%f20 \n\t" /* 4 */ \ + \ + "fpadd16 %%f0, %%f8, %%f8 \n\t" /* Gt */ \ + "fpadd16 %%f16, %%f24, %%f24 \n\t" /* Gt */ \ + "fpadd16 %%f0, %%f4, %%f4 \n\t" /* R */ \ + "fpadd16 %%f16, %%f20, %%f20 \n\t" /* R */ \ + "fpadd16 %%f0, %%f6, %%f6 \n\t" /* B */ \ + "fpadd16 %%f16, %%f22, %%f22 \n\t" /* B */ \ + "fpadd16 %%f8, %%f2, %%f2 \n\t" /* G */ \ + "fpadd16 %%f24, %%f18, %%f18 \n\t" /* G */ \ + \ + "fpack16 %%f4, %%f4 \n\t" \ + "fpack16 %%f20, %%f20 \n\t" \ + "fpack16 %%f6, %%f6 \n\t" \ + "fpack16 %%f22, %%f22 \n\t" \ + "fpack16 %%f2, %%f2 \n\t" \ + "fpack16 %%f18, %%f18 \n\t" + + + +static int vis_420P_ARGB32(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dst[], int dstStride[]){ + int y, out1, out2, out3, out4, out5, out6; + + for(y=0;y < srcSliceH;++y) { + asm volatile ( + YUV2RGB_INIT + "wr %%g0, 0xd2, %%asi \n\t" /* ASI_FL16_P */ + "1: \n\t" + "ldda [%1] %%asi, %%f2 \n\t" + "ldda [%1+2] %%asi, %%f18 \n\t" + "ldda [%2] %%asi, %%f4 \n\t" + "ldda [%2+2] %%asi, %%f20 \n\t" + "ld [%0], %%f0 \n\t" + "ld [%0+4], %%f16 \n\t" + "fpmerge %%f3, %%f3, %%f2 \n\t" + "fpmerge %%f19, %%f19, %%f18 \n\t" + "fpmerge %%f5, %%f5, %%f4 \n\t" + "fpmerge %%f21, %%f21, %%f20 \n\t" + YUV2RGB_KERNEL + "fzero %%f0 \n\t" + "fpmerge %%f4, %%f6, %%f8 \n\t" // r,b,t1 + "fpmerge %%f20, %%f22, %%f24 \n\t" // r,b,t1 + "fpmerge %%f0, %%f2, %%f10 \n\t" // 0,g,t2 + "fpmerge %%f0, %%f18, %%f26 \n\t" // 0,g,t2 + "fpmerge %%f10, %%f8, %%f4 \n\t" // t2,t1,msb + "fpmerge %%f26, %%f24, %%f20 \n\t" // t2,t1,msb + "fpmerge %%f11, %%f9, %%f6 \n\t" // t2,t1,lsb + "fpmerge %%f27, %%f25, %%f22 \n\t" // t2,t1,lsb + "std %%f4, [%3] \n\t" + "std %%f20, [%3+16] \n\t" + "std %%f6, [%3+8] \n\t" + "std %%f22, [%3+24] \n\t" + + "add %0, 8, %0 \n\t" + "add %1, 4, %1 \n\t" + "add %2, 4, %2 \n\t" + "subcc %4, 8, %4 \n\t" + "bne 1b \n\t" + "add %3, 32, %3 \n\t" //delay slot + : "=r" (out1), "=r" (out2), "=r" (out3), "=r" (out4), "=r" (out5), "=r" (out6) + : "0" (src[0]+(y+srcSliceY)*srcStride[0]), "1" (src[1]+((y+srcSliceY)>>1)*srcStride[1]), + "2" (src[2]+((y+srcSliceY)>>1)*srcStride[2]), "3" (dst[0]+(y+srcSliceY)*dstStride[0]), + "4" (c->dstW), + "5" (c->sparc_coeffs) + ); + } + + return srcSliceH; +} + +static int vis_422P_ARGB32(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, + int srcSliceH, uint8_t* dst[], int dstStride[]){ + int y, out1, out2, out3, out4, out5, out6; + + for(y=0;y < srcSliceH;++y) { + asm volatile ( + YUV2RGB_INIT + "wr %%g0, 0xd2, %%asi \n\t" /* ASI_FL16_P */ + "1: \n\t" + "ldda [%1] %%asi, %%f2 \n\t" + "ldda [%1+2] %%asi, %%f18 \n\t" + "ldda [%2] %%asi, %%f4 \n\t" + "ldda [%2+2] %%asi, %%f20 \n\t" + "ld [%0], %%f0 \n\t" + "ld [%0+4], %%f16 \n\t" + "fpmerge %%f3, %%f3, %%f2 \n\t" + "fpmerge %%f19, %%f19, %%f18 \n\t" + "fpmerge %%f5, %%f5, %%f4 \n\t" + "fpmerge %%f21, %%f21, %%f20 \n\t" + YUV2RGB_KERNEL + "fzero %%f0 \n\t" + "fpmerge %%f4, %%f6, %%f8 \n\t" // r,b,t1 + "fpmerge %%f20, %%f22, %%f24 \n\t" // r,b,t1 + "fpmerge %%f0, %%f2, %%f10 \n\t" // 0,g,t2 + "fpmerge %%f0, %%f18, %%f26 \n\t" // 0,g,t2 + "fpmerge %%f10, %%f8, %%f4 \n\t" // t2,t1,msb + "fpmerge %%f26, %%f24, %%f20 \n\t" // t2,t1,msb + "fpmerge %%f11, %%f9, %%f6 \n\t" // t2,t1,lsb + "fpmerge %%f27, %%f25, %%f22 \n\t" // t2,t1,lsb + "std %%f4, [%3] \n\t" + "std %%f20, [%3+16] \n\t" + "std %%f6, [%3+8] \n\t" + "std %%f22, [%3+24] \n\t" + + "add %0, 8, %0 \n\t" + "add %1, 4, %1 \n\t" + "add %2, 4, %2 \n\t" + "subcc %4, 8, %4 \n\t" + "bne 1b \n\t" + "add %3, 32, %3 \n\t" //delay slot + : "=r" (out1), "=r" (out2), "=r" (out3), "=r" (out4), "=r" (out5), "=r" (out6) + : "0" (src[0]+(y+srcSliceY)*srcStride[0]), "1" (src[1]+(y+srcSliceY)*srcStride[1]), + "2" (src[2]+(y+srcSliceY)*srcStride[2]), "3" (dst[0]+(y+srcSliceY)*dstStride[0]), + "4" (c->dstW), + "5" (c->sparc_coeffs) + ); + } + + return srcSliceH; +} + +SwsFunc yuv2rgb_init_vis(SwsContext *c) { + c->sparc_coeffs[5]=c->yCoeff; + c->sparc_coeffs[6]=c->vgCoeff; + c->sparc_coeffs[7]=c->vrCoeff; + c->sparc_coeffs[8]=c->ubCoeff; + c->sparc_coeffs[9]=c->ugCoeff; + + c->sparc_coeffs[0]=(((int16_t)c->yOffset*(int16_t)c->yCoeff >>11) & 0xffff) * 0x0001000100010001ULL; + c->sparc_coeffs[1]=(((int16_t)c->uOffset*(int16_t)c->ubCoeff>>11) & 0xffff) * 0x0001000100010001ULL; + c->sparc_coeffs[2]=(((int16_t)c->uOffset*(int16_t)c->ugCoeff>>11) & 0xffff) * 0x0001000100010001ULL; + c->sparc_coeffs[3]=(((int16_t)c->vOffset*(int16_t)c->vgCoeff>>11) & 0xffff) * 0x0001000100010001ULL; + c->sparc_coeffs[4]=(((int16_t)c->vOffset*(int16_t)c->vrCoeff>>11) & 0xffff) * 0x0001000100010001ULL; + + if (c->dstFormat == PIX_FMT_RGB32 && c->srcFormat == PIX_FMT_YUV422P && (c->dstW & 7)==0) { + av_log(c, AV_LOG_INFO, "SPARC VIS accelerated YUV422P -> RGB32\n"); + return vis_422P_ARGB32; + } + else if (c->dstFormat == PIX_FMT_RGB32 && c->srcFormat == PIX_FMT_YUV420P && (c->dstW & 7)==0) { + av_log(c, AV_LOG_INFO, "SPARC VIS accelerated YUV420P -> RGB32\n"); + return vis_420P_ARGB32; + } + return NULL; +} diff --git a/contrib/ffmpeg/output_example.c b/contrib/ffmpeg/output_example.c index ca12b783f..36b0921d2 100644 --- a/contrib/ffmpeg/output_example.c +++ b/contrib/ffmpeg/output_example.c @@ -34,6 +34,8 @@ #include "avformat.h" #include "swscale.h" +#undef exit + /* 5 seconds stream duration */ #define STREAM_DURATION 5.0 #define STREAM_FRAME_RATE 25 /* 25 images/s */ @@ -215,9 +217,9 @@ static AVStream *add_video_stream(AVFormatContext *oc, int codec_id) c->max_b_frames = 2; } if (c->codec_id == CODEC_ID_MPEG1VIDEO){ - /* needed to avoid using macroblocks in which some coeffs overflow - this doesnt happen with normal video, it just happens here as the - motion of the chroma plane doesnt match the luma plane */ + /* Needed to avoid using macroblocks in which some coeffs overflow. + This does not happen with normal video, it just happens here as + the motion of the chroma plane does not match the luma plane. */ c->mb_decision=2; } // some formats want stream headers to be separate @@ -536,7 +538,7 @@ int main(int argc, char **argv) if (!(fmt->flags & AVFMT_NOFILE)) { /* close the output file */ - url_fclose(&oc->pb); + url_fclose(oc->pb); } /* free the stream */ diff --git a/contrib/ffmpeg/pktdumper.c b/contrib/ffmpeg/pktdumper.c deleted file mode 100644 index d43f46b45..000000000 --- a/contrib/ffmpeg/pktdumper.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2005 Francois Revol - * - * This file is part of FFmpeg. - * - * FFmpeg 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. - * - * FFmpeg 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 FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include -#include -#include -#include -#include -#include -#include - -#define PKTFILESUFF "_%08"PRId64"_%02d_%010"PRId64"_%06d_%c.bin" - -static int usage(int ret) -{ - fprintf(stderr, "dump (up to maxpkts) AVPackets as they are demuxed by libavformat.\n"); - fprintf(stderr, "each packet is dumped in its own file named like `basename file.ext`_$PKTNUM_$STREAMINDEX_$STAMP_$SIZE_$FLAGS.bin\n"); - fprintf(stderr, "pktdumper [-nw] file [maxpkts]\n"); - fprintf(stderr, "-n\twrite No file at all, only demux.\n"); - fprintf(stderr, "-w\tWait at end of processing instead of quitting.\n"); - return ret; -} - -int main(int argc, char **argv) -{ - char fntemplate[PATH_MAX]; - char pktfilename[PATH_MAX]; - AVFormatContext *fctx; - AVPacket pkt; - int64_t pktnum = 0; - int64_t maxpkts = 0; - int dontquit = 0; - int nowrite = 0; - int err; - - if ((argc > 1) && !strncmp(argv[1], "-", 1)) { - if (strchr(argv[1], 'w')) - dontquit = 1; - if (strchr(argv[1], 'n')) - nowrite = 1; - argv++; - argc--; - } - if (argc < 2) - return usage(1); - if (argc > 2) - maxpkts = atoi(argv[2]); - strncpy(fntemplate, argv[1], PATH_MAX-1); - if (strrchr(argv[1], '/')) - strncpy(fntemplate, strrchr(argv[1], '/')+1, PATH_MAX-1); - if (strrchr(fntemplate, '.')) - *strrchr(fntemplate, '.') = '\0'; - if (strchr(fntemplate, '%')) { - fprintf(stderr, "can't use filenames containing '%%'\n"); - return usage(1); - } - if (strlen(fntemplate) + sizeof(PKTFILESUFF) >= PATH_MAX-1) { - fprintf(stderr, "filename too long\n"); - return usage(1); - } - strcat(fntemplate, PKTFILESUFF); - printf("FNTEMPLATE: '%s'\n", fntemplate); - - // register all file formats - av_register_all(); - - err = av_open_input_file(&fctx, argv[1], NULL, 0, NULL); - if (err < 0) { - fprintf(stderr, "av_open_input_file: error %d\n", err); - return 1; - } - - err = av_find_stream_info(fctx); - if (err < 0) { - fprintf(stderr, "av_find_stream_info: error %d\n", err); - return 1; - } - - av_init_packet(&pkt); - - while ((err = av_read_frame(fctx, &pkt)) >= 0) { - int fd; - snprintf(pktfilename, PATH_MAX-1, fntemplate, pktnum, pkt.stream_index, pkt.pts, pkt.size, (pkt.flags & PKT_FLAG_KEY)?'K':'_'); - printf(PKTFILESUFF"\n", pktnum, pkt.stream_index, pkt.pts, pkt.size, (pkt.flags & PKT_FLAG_KEY)?'K':'_'); - //printf("open(\"%s\")\n", pktfilename); - if (!nowrite) { - fd = open(pktfilename, O_WRONLY|O_CREAT, 0644); - write(fd, pkt.data, pkt.size); - close(fd); - } - pktnum++; - if (maxpkts && (pktnum >= maxpkts)) - break; - } - - while (dontquit) - sleep(60); - - return 0; -} diff --git a/contrib/ffmpeg/qt-faststart.c b/contrib/ffmpeg/qt-faststart.c deleted file mode 100644 index 2cbf12b1d..000000000 --- a/contrib/ffmpeg/qt-faststart.c +++ /dev/null @@ -1,311 +0,0 @@ -/* - * qt-faststart.c, v0.1 - * by Mike Melanson (melanson@pcisys.net) - * This file is placed in the public domain. Use the program however you - * see fit. - * - * This utility rearranges a Quicktime file such that the moov atom - * is in front of the data, thus facilitating network streaming. - * - * Compile this program using: - * make qt-faststart - * Invoke the program with: - * qt-faststart - * - * Notes: Quicktime files can come in many configurations of top-level - * atoms. This utility stipulates that the very last atom in the file needs - * to be a moov atom. When given such a file, this utility will rearrange - * the top-level atoms by shifting the moov atom from the back of the file - * to the front, and patch the chunk offsets along the way. This utility - * presently only operates on uncompressed moov atoms. - */ - -#include -#include -#include - -#ifdef __MINGW32__ -#define fseeko(x,y,z) fseeko64(x,y,z) -#define ftello(x) ftello64(x) -#endif - -#define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1]) -#define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \ - (((uint8_t*)(x))[1] << 16) | \ - (((uint8_t*)(x))[2] << 8) | \ - ((uint8_t*)(x))[3]) -#define BE_64(x) (((uint64_t)(((uint8_t*)(x))[0]) << 56) | \ - ((uint64_t)(((uint8_t*)(x))[1]) << 48) | \ - ((uint64_t)(((uint8_t*)(x))[2]) << 40) | \ - ((uint64_t)(((uint8_t*)(x))[3]) << 32) | \ - ((uint64_t)(((uint8_t*)(x))[4]) << 24) | \ - ((uint64_t)(((uint8_t*)(x))[5]) << 16) | \ - ((uint64_t)(((uint8_t*)(x))[6]) << 8) | \ - ((uint64_t)((uint8_t*)(x))[7])) - -#define BE_FOURCC( ch0, ch1, ch2, ch3 ) \ - ( (uint32_t)(unsigned char)(ch3) | \ - ( (uint32_t)(unsigned char)(ch2) << 8 ) | \ - ( (uint32_t)(unsigned char)(ch1) << 16 ) | \ - ( (uint32_t)(unsigned char)(ch0) << 24 ) ) - -#define QT_ATOM BE_FOURCC -/* top level atoms */ -#define FREE_ATOM QT_ATOM('f', 'r', 'e', 'e') -#define JUNK_ATOM QT_ATOM('j', 'u', 'n', 'k') -#define MDAT_ATOM QT_ATOM('m', 'd', 'a', 't') -#define MOOV_ATOM QT_ATOM('m', 'o', 'o', 'v') -#define PNOT_ATOM QT_ATOM('p', 'n', 'o', 't') -#define SKIP_ATOM QT_ATOM('s', 'k', 'i', 'p') -#define WIDE_ATOM QT_ATOM('w', 'i', 'd', 'e') -#define PICT_ATOM QT_ATOM('P', 'I', 'C', 'T') -#define FTYP_ATOM QT_ATOM('f', 't', 'y', 'p') - -#define CMOV_ATOM QT_ATOM('c', 'm', 'o', 'v') -#define STCO_ATOM QT_ATOM('s', 't', 'c', 'o') -#define CO64_ATOM QT_ATOM('c', 'o', '6', '4') - -#define ATOM_PREAMBLE_SIZE 8 -#define COPY_BUFFER_SIZE 1024 - -int main(int argc, char *argv[]) -{ - FILE *infile; - FILE *outfile; - unsigned char atom_bytes[ATOM_PREAMBLE_SIZE]; - uint32_t atom_type = 0; - uint64_t atom_size = 0; - uint64_t last_offset; - unsigned char *moov_atom; - unsigned char *ftyp_atom = 0; - uint64_t moov_atom_size; - uint64_t ftyp_atom_size = 0; - uint64_t i, j; - uint32_t offset_count; - uint64_t current_offset; - uint64_t start_offset = 0; - unsigned char copy_buffer[COPY_BUFFER_SIZE]; - int bytes_to_copy; - - if (argc != 3) { - printf ("Usage: qt-faststart \n"); - return 0; - } - - infile = fopen(argv[1], "rb"); - if (!infile) { - perror(argv[1]); - return 1; - } - - /* traverse through the atoms in the file to make sure that 'moov' is - * at the end */ - while (!feof(infile)) { - if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) { - break; - } - atom_size = (uint32_t)BE_32(&atom_bytes[0]); - atom_type = BE_32(&atom_bytes[4]); - - if ((atom_type != FREE_ATOM) && - (atom_type != JUNK_ATOM) && - (atom_type != MDAT_ATOM) && - (atom_type != MOOV_ATOM) && - (atom_type != PNOT_ATOM) && - (atom_type != SKIP_ATOM) && - (atom_type != WIDE_ATOM) && - (atom_type != PICT_ATOM) && - (atom_type != FTYP_ATOM)) { - printf ("encountered non-QT top-level atom (is this a Quicktime file?)\n"); - break; - } - - /* keep ftyp atom */ - if (atom_type == FTYP_ATOM) { - ftyp_atom_size = atom_size; - ftyp_atom = malloc(ftyp_atom_size); - if (!ftyp_atom) { - printf ("could not allocate 0x%llX byte for ftyp atom\n", - atom_size); - fclose(infile); - return 1; - } - fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR); - if (fread(ftyp_atom, atom_size, 1, infile) != 1) { - perror(argv[1]); - free(ftyp_atom); - fclose(infile); - return 1; - } - start_offset = ftello(infile); - continue; - } - - /* 64-bit special case */ - if (atom_size == 1) { - if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) { - break; - } - atom_size = BE_64(&atom_bytes[0]); - fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE * 2, SEEK_CUR); - } else { - fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE, SEEK_CUR); - } - } - - if (atom_type != MOOV_ATOM) { - printf ("last atom in file was not a moov atom\n"); - fclose(infile); - return 0; - } - - /* moov atom was, in fact, the last atom in the chunk; load the whole - * moov atom */ - fseeko(infile, -atom_size, SEEK_END); - last_offset = ftello(infile); - moov_atom_size = atom_size; - moov_atom = malloc(moov_atom_size); - if (!moov_atom) { - printf ("could not allocate 0x%llX byte for moov atom\n", - atom_size); - fclose(infile); - return 1; - } - if (fread(moov_atom, atom_size, 1, infile) != 1) { - perror(argv[1]); - free(moov_atom); - fclose(infile); - return 1; - } - - /* this utility does not support compressed atoms yet, so disqualify - * files with compressed QT atoms */ - if (BE_32(&moov_atom[12]) == CMOV_ATOM) { - printf ("this utility does not support compressed moov atoms yet\n"); - free(moov_atom); - fclose(infile); - return 1; - } - - /* close; will be re-opened later */ - fclose(infile); - - /* crawl through the moov chunk in search of stco or co64 atoms */ - for (i = 4; i < moov_atom_size - 4; i++) { - atom_type = BE_32(&moov_atom[i]); - if (atom_type == STCO_ATOM) { - printf (" patching stco atom...\n"); - atom_size = BE_32(&moov_atom[i - 4]); - if (i + atom_size - 4 > moov_atom_size) { - printf (" bad atom size\n"); - free(moov_atom); - return 1; - } - offset_count = BE_32(&moov_atom[i + 8]); - for (j = 0; j < offset_count; j++) { - current_offset = BE_32(&moov_atom[i + 12 + j * 4]); - current_offset += moov_atom_size; - moov_atom[i + 12 + j * 4 + 0] = (current_offset >> 24) & 0xFF; - moov_atom[i + 12 + j * 4 + 1] = (current_offset >> 16) & 0xFF; - moov_atom[i + 12 + j * 4 + 2] = (current_offset >> 8) & 0xFF; - moov_atom[i + 12 + j * 4 + 3] = (current_offset >> 0) & 0xFF; - } - i += atom_size - 4; - } else if (atom_type == CO64_ATOM) { - printf (" patching co64 atom...\n"); - atom_size = BE_32(&moov_atom[i - 4]); - if (i + atom_size - 4 > moov_atom_size) { - printf (" bad atom size\n"); - free(moov_atom); - return 1; - } - offset_count = BE_32(&moov_atom[i + 8]); - for (j = 0; j < offset_count; j++) { - current_offset = BE_64(&moov_atom[i + 12 + j * 8]); - current_offset += moov_atom_size; - moov_atom[i + 12 + j * 8 + 0] = (current_offset >> 56) & 0xFF; - moov_atom[i + 12 + j * 8 + 1] = (current_offset >> 48) & 0xFF; - moov_atom[i + 12 + j * 8 + 2] = (current_offset >> 40) & 0xFF; - moov_atom[i + 12 + j * 8 + 3] = (current_offset >> 32) & 0xFF; - moov_atom[i + 12 + j * 8 + 4] = (current_offset >> 24) & 0xFF; - moov_atom[i + 12 + j * 8 + 5] = (current_offset >> 16) & 0xFF; - moov_atom[i + 12 + j * 8 + 6] = (current_offset >> 8) & 0xFF; - moov_atom[i + 12 + j * 8 + 7] = (current_offset >> 0) & 0xFF; - } - i += atom_size - 4; - } - } - - /* re-open the input file and open the output file */ - infile = fopen(argv[1], "rb"); - if (!infile) { - perror(argv[1]); - free(moov_atom); - return 1; - } - - if (start_offset > 0) { /* seek after ftyp atom */ - fseeko(infile, start_offset, SEEK_SET); - last_offset -= start_offset; - } - - outfile = fopen(argv[2], "wb"); - if (!outfile) { - perror(argv[2]); - fclose(outfile); - free(moov_atom); - return 1; - } - - /* dump the same ftyp atom */ - if (ftyp_atom_size > 0) { - printf (" writing ftyp atom...\n"); - if (fwrite(ftyp_atom, ftyp_atom_size, 1, outfile) != 1) { - perror(argv[2]); - goto error_out; - } - } - - /* dump the new moov atom */ - printf (" writing moov atom...\n"); - if (fwrite(moov_atom, moov_atom_size, 1, outfile) != 1) { - perror(argv[2]); - goto error_out; - } - - /* copy the remainder of the infile, from offset 0 -> last_offset - 1 */ - printf (" copying rest of file...\n"); - while (last_offset) { - if (last_offset > COPY_BUFFER_SIZE) - bytes_to_copy = COPY_BUFFER_SIZE; - else - bytes_to_copy = last_offset; - - if (fread(copy_buffer, bytes_to_copy, 1, infile) != 1) { - perror(argv[1]); - goto error_out; - } - if (fwrite(copy_buffer, bytes_to_copy, 1, outfile) != 1) { - perror(argv[2]); - goto error_out; - } - - last_offset -= bytes_to_copy; - } - - fclose(infile); - fclose(outfile); - free(moov_atom); - if (ftyp_atom_size > 0) - free(ftyp_atom); - - return 0; - -error_out: - fclose(infile); - fclose(outfile); - free(moov_atom); - if (ftyp_atom_size > 0) - free(ftyp_atom); - return 1; -} diff --git a/contrib/ffmpeg/tests/Makefile b/contrib/ffmpeg/tests/Makefile deleted file mode 100644 index 3417c687e..000000000 --- a/contrib/ffmpeg/tests/Makefile +++ /dev/null @@ -1,114 +0,0 @@ -# -# Makefile for tests -# (c) 2002 Fabrice Bellard -# -include ../config.mak - -VPATH=$(SRC_PATH_BARE)/tests -SRC_DIR=$(SRC_PATH)/tests -BUILD_DIR=$(BUILD_ROOT)/tests -CFLAGS=-O2 -Wall -g - -REFFILE1=$(SRC_DIR)/ffmpeg.regression.ref -REFFILE2=$(SRC_DIR)/rotozoom.regression.ref - -SERVER_REFFILE=$(SRC_DIR)/ffserver.regression.ref - -LIBAV_REFFILE=$(SRC_DIR)/libav.regression.ref - -SEEK_REFFILE=$(SRC_DIR)/seek.regression.ref - -all fulltest test: codectest libavtest - -test-server: vsynth1/00.pgm asynth1.sw - @echo - @echo "Unfortunately ffserver is broken and therefore its regression" - @echo "test fails randomly. Treat the results accordingly." - @echo - @$(SRC_DIR)/server-regression.sh $(SERVER_REFFILE) $(SRC_DIR)/test.conf - -# fast regression tests for all codecs -codectest mpeg4 mpeg ac3 snow snowll: vsynth1/00.pgm vsynth2/00.pgm asynth1.sw tiny_psnr$(EXESUF) - @$(SRC_DIR)/regression.sh $@ $(REFFILE1) vsynth1 - @$(SRC_DIR)/regression.sh $@ $(REFFILE2) vsynth2 - -# fast regression for libav formats -ifeq ($(CONFIG_GPL),yes) -libavtest: vsynth1/00.pgm asynth1.sw - @$(SRC_DIR)/regression.sh $@ $(LIBAV_REFFILE) vsynth1 -else -libavtest: - @echo - @echo "This test requires FFmpeg to be compiled with --enable-gpl." - @echo -endif - -ifeq ($(CONFIG_SWSCALER),yes) -test-server codectest mpeg4 mpeg ac3 snow snowll libavtest: swscale_error -swscale_error: - @echo - @echo "This regression test is incompatible with --enable-swscaler." - @echo - @exit 1 -endif - -seektest: seek_test$(EXESUF) - @$(SRC_DIR)/seek_test.sh $(SEEK_REFFILE) - -# video generation - -vsynth1/00.pgm: videogen$(EXESUF) - @mkdir -p vsynth1 - $(BUILD_DIR)/$< 'vsynth1/' - -vsynth2/00.pgm: rotozoom$(EXESUF) - @mkdir -p vsynth2 - $(BUILD_DIR)/$< 'vsynth2/' $(SRC_DIR)/lena.pnm - -videogen$(EXESUF): videogen.c - $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $< - -rotozoom$(EXESUF): rotozoom.c - $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $< - -# audio generation - -asynth1.sw: audiogen$(EXESUF) - $(BUILD_DIR)/$< $@ - -audiogen$(EXESUF): audiogen.c - $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $< - -tiny_psnr$(EXESUF): tiny_psnr.c - $(CC) $(LDFLAGS) $(CFLAGS) -o $@ $< - -#FIXME cleanup shit below -seek_test$(EXESUF): seek_test.c - $(CC) $(LDFLAGS) $(CFLAGS) -DHAVE_AV_CONFIG_H -I.. -I$(SRC_PATH)/libavformat/ -I$(SRC_PATH)/libavcodec/ -I$(SRC_PATH)/libavutil/ -o $@ $< $(SRC_PATH)/libavformat/libavformat.a $(SRC_PATH)/libavcodec/libavcodec.a $(SRC_PATH)/libavutil/libavutil.a $(EXTRALIBS) - -DSPDEPS = $(SRC_PATH)/libavcodec/i386/dsputil_mmx.c \ - $(SRC_PATH)/libavcodec/i386/dsputil_mmx_avg.h \ - $(SRC_PATH)/libavcodec/i386/dsputil_mmx_rnd.h \ - $(SRC_PATH)/libavcodec/i386/fdct_mmx.c \ - $(SRC_PATH)/libavcodec/i386/idct_mmx.c \ - $(SRC_PATH)/libavcodec/i386/motion_est_mmx.c \ - $(SRC_PATH)/libavcodec/i386/simple_idct_mmx.c \ - $(SRC_PATH)/libavcodec/dsputil.c \ - $(SRC_PATH)/libavcodec/dsputil.h \ - $(SRC_PATH)/libavcodec/simple_idct.c - -DSPCFLAGS = -O4 -fomit-frame-pointer -DHAVE_AV_CONFIG_H -I.. \ - -I$(SRC_PATH)/libavutil/ -I$(SRC_PATH)/libavcodec/i386 \ - -I$(SRC_PATH)/libavcodec/ -lm - -dsptestpic: dsptest.c $(DSPDEPS) - $(CC) -fPIC -DPIC $(DSPCFLAGS) -o $@ $< -dsptest: dsptest.c $(DSPDEPS) - $(CC) $(DSPCFLAGS) -o $@ $< - -distclean clean: - rm -rf vsynth1 vsynth2 data - rm -f asynth1.sw *~ audiogen$(EXESUF) videogen$(EXESUF) rotozoom$(EXESUF) tiny_psnr$(EXESUF) - -.PHONY: all fulltest test codectest libavtest test-server seektest -.PHONY: mpeg4 mpeg ac3 snow snowll distclean clean diff --git a/contrib/ffmpeg/tests/audiogen.c b/contrib/ffmpeg/tests/audiogen.c index 68ae13586..f96110e96 100644 --- a/contrib/ffmpeg/tests/audiogen.c +++ b/contrib/ffmpeg/tests/audiogen.c @@ -1,6 +1,6 @@ /* * Generates a synthetic stereo sound - * NOTE: no floats are used to guaranty a bit exact output. + * NOTE: No floats are used to guarantee a bit exact output. * * Copyright (c) 2002 Fabrice Bellard * diff --git a/contrib/ffmpeg/tests/dsptest.c b/contrib/ffmpeg/tests/dsptest.c deleted file mode 100644 index 06a185202..000000000 --- a/contrib/ffmpeg/tests/dsptest.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - * MMX optimized DSP utils - * Copyright (c) 2000, 2001, 2002 Fabrice Bellard. - * - * This library 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 of the License, or (at your option) any later version. - * - * This library 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 this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#define TESTCPU_MAIN -#include "avcodec.h" -#include "dsputil.h" -#include "mpegvideo.h" -#include "mpeg12data.h" -#include "mpeg4data.h" -#include "../libavcodec/i386/cputest.c" -#include "../libavcodec/i386/dsputil_mmx.c" - -#include "../libavcodec/i386/fdct_mmx.c" -#include "../libavcodec/i386/idct_mmx.c" -#include "../libavcodec/i386/motion_est_mmx.c" -#include "../libavcodec/i386/simple_idct_mmx.c" -#include "../libavcodec/dsputil.c" -#include "../libavcodec/simple_idct.c" -#include "../libavcodec/jfdctfst.c" - -#undef TESTCPU_MAIN - -#define PAD 0x10000 -/* - * for testing speed of various routine - should be probably extended - * for a general purpose regression test later - * - * currently only for i386 - FIXME - */ - -#define PIX_FUNC_C(a) \ - { #a "_c", a ## _c, 0 }, \ - { #a "_mmx", a ## _mmx, MM_MMX }, \ - { #a "_mmx2", a ## _mmx2, MM_MMXEXT | PAD } - -#define PIX_FUNC(a) \ - { #a "_mmx", a ## _mmx, MM_MMX }, \ - { #a "_3dnow", a ## _3dnow, MM_3DNOW }, \ - { #a "_mmx2", a ## _mmx2, MM_MMXEXT | PAD } - -#define PIX_FUNC_MMX(a) \ - { #a "_mmx", a ## _mmx, MM_MMX | PAD } - -/* - PIX_FUNC_C(pix_abs16x16), - PIX_FUNC_C(pix_abs16x16_x2), - PIX_FUNC_C(pix_abs16x16_y2), - PIX_FUNC_C(pix_abs16x16_xy2), - PIX_FUNC_C(pix_abs8x8), - PIX_FUNC_C(pix_abs8x8_x2), - PIX_FUNC_C(pix_abs8x8_y2), - PIX_FUNC_C(pix_abs8x8_xy2), -*/ - -static const struct pix_func { - char* name; - op_pixels_func func; - int mm_flags; -} pix_func[] = { - - PIX_FUNC_MMX(put_pixels), - //PIX_FUNC_MMX(get_pixels), - //PIX_FUNC_MMX(put_pixels_clamped), -#if 1 - PIX_FUNC(put_pixels_x2), - PIX_FUNC(put_pixels_y2), - PIX_FUNC_MMX(put_pixels_xy2), - - PIX_FUNC(put_no_rnd_pixels_x2), - PIX_FUNC(put_no_rnd_pixels_y2), - PIX_FUNC_MMX(put_no_rnd_pixels_xy2), - - PIX_FUNC(avg_pixels), - PIX_FUNC(avg_pixels_x2), - PIX_FUNC(avg_pixels_y2), - PIX_FUNC(avg_pixels_xy2), - - PIX_FUNC_MMX(avg_no_rnd_pixels), - PIX_FUNC_MMX(avg_no_rnd_pixels_x2), - PIX_FUNC_MMX(avg_no_rnd_pixels_y2), - PIX_FUNC_MMX(avg_no_rnd_pixels_xy2), -#endif - { 0, 0 } -}; - -static inline long long rdtsc() -{ - long long l; - asm volatile( "rdtsc\n\t" - : "=A" (l) - ); - return l; -} - -static test_speed(int step) -{ - const struct pix_func* pix = pix_func; - const int linesize = 720; - char empty[32768]; - char* bu =(char*)(((long)empty + 32) & ~0xf); - - int sum = 0; - - while (pix->name) - { - int i; - uint64_t te, ts; - op_pixels_func func = pix->func; - char* im = bu; - - if (pix->mm_flags & mm_flags) - { - printf("%30s... ", pix->name); - fflush(stdout); - ts = rdtsc(); - for(i=0; i<100000; i++){ - func(im, im + 1000, linesize, 16); - im += step; - if (im > bu + 20000) - im = bu; - } - te = rdtsc(); - emms(); - printf("% 9d\n", (int)(te - ts)); - sum += (te - ts) / 100000; - if (pix->mm_flags & PAD) - puts(""); - } - pix++; - } - - printf("Total sum: %d\n", sum); -} - -int main(int argc, char* argv[]) -{ - int step = 16; - - if (argc > 1) - { - // something simple for now - if (argc > 2 && (strcmp("-s", argv[1]) == 0 - || strcmp("-step", argv[1]) == 0)) - step = atoi(argv[2]); - } - - mm_flags = mm_support(); - printf("%s: detected CPU flags:", argv[0]); - if (mm_flags & MM_MMX) - printf(" mmx"); - if (mm_flags & MM_MMXEXT) - printf(" mmxext"); - if (mm_flags & MM_3DNOW) - printf(" 3dnow"); - if (mm_flags & MM_SSE) - printf(" sse"); - if (mm_flags & MM_SSE2) - printf(" sse2"); - printf("\n"); - - printf("Using step: %d\n", step); - test_speed(step); -} diff --git a/contrib/ffmpeg/tests/ffmpeg.regression.ref b/contrib/ffmpeg/tests/ffmpeg.regression.ref index ae5355406..1ff9ecd5a 100644 --- a/contrib/ffmpeg/tests/ffmpeg.regression.ref +++ b/contrib/ffmpeg/tests/ffmpeg.regression.ref @@ -1,198 +1,205 @@ -ffmpeg regression test -dd4c189859399f7f251876be8e26e4f3 *./data/a-mpeg1.mpg -722848 ./data/a-mpeg1.mpg -78d202830e5ce5a67495ab14ebe6469e *./data/out.yuv +dd4c189859399f7f251876be8e26e4f3 *./tests/data/a-mpeg1.mpg +722848 ./tests/data/a-mpeg1.mpg +78d202830e5ce5a67495ab14ebe6469e *./tests/data/mpeg.vsynth.out.yuv stddev: 7.65 PSNR:30.44 bytes:7602176 -f3b008355f68394b6cad694f3488ea2b *./data/a-mpeg2.mpg -736978 ./data/a-mpeg2.mpg -9f364a477987c3b14412e303b94377ca *./data/out.yuv +f3b008355f68394b6cad694f3488ea2b *./tests/data/a-mpeg2.mpg +736978 ./tests/data/a-mpeg2.mpg +9f364a477987c3b14412e303b94377ca *./tests/data/mpeg2.vsynth.out.yuv stddev: 7.68 PSNR:30.41 bytes:7602176 -1716f466ea82b4d90677868b2ce1f8e2 *./data/a-mpeg2ivlc-qprd.mpg -708232 ./data/a-mpeg2ivlc-qprd.mpg -40746946d5661606f7a649c62b6c4bee *./data/out.yuv -stddev: 12.21 PSNR:26.38 bytes:7602176 -2566ea5760247a9485c8281cb52291a8 *./data/a-mpeg2.mpg -735853 ./data/a-mpeg2.mpg -55c22a09e4924977ee2cc4180078d3ae *./data/out.yuv +103f4b5f90feaec3c04e200409501982 *./tests/data/a-mpeg2ivlc-qprd.mpg +787469 ./tests/data/a-mpeg2ivlc-qprd.mpg +985170ca0ab1ec1edbb37c44d8cfde90 *./tests/data/mpeg2.vsynth.out.yuv +stddev: 10.09 PSNR:28.04 bytes:7602176 +2566ea5760247a9485c8281cb52291a8 *./tests/data/a-mpeg2.mpg +735853 ./tests/data/a-mpeg2.mpg +55c22a09e4924977ee2cc4180078d3ae *./tests/data/mpeg2.vsynth.out.yuv stddev: 7.67 PSNR:30.42 bytes:7602176 -0093ab9141105dec8dc4452ba8f0ab6f *./data/a-mpeg2i.mpg -749746 ./data/a-mpeg2i.mpg -5189af71e6aa96cc2f6452e7f6b29287 *./data/out.yuv +0093ab9141105dec8dc4452ba8f0ab6f *./tests/data/a-mpeg2i.mpg +749746 ./tests/data/a-mpeg2i.mpg +5189af71e6aa96cc2f6452e7f6b29287 *./tests/data/mpeg2.vsynth.out.yuv stddev: 7.68 PSNR:30.41 bytes:7602176 -69576facff13d45171e3a6c53b8018c4 *./data/a-mpeg2thread.mpg -813459 ./data/a-mpeg2thread.mpg -c0e8cbde76ff8377494fe6843fd03e11 *./data/out.yuv +69576facff13d45171e3a6c53b8018c4 *./tests/data/a-mpeg2thread.mpg +813459 ./tests/data/a-mpeg2thread.mpg +c0e8cbde76ff8377494fe6843fd03e11 *./tests/data/mpeg2thread.vsynth.out.yuv stddev: 7.63 PSNR:30.47 bytes:7602176 -17af99d1a7fc391242a809b0782263af *./data/a-mpeg2threadivlc.mpg -803833 ./data/a-mpeg2threadivlc.mpg -c0e8cbde76ff8377494fe6843fd03e11 *./data/out.yuv +17af99d1a7fc391242a809b0782263af *./tests/data/a-mpeg2threadivlc.mpg +803833 ./tests/data/a-mpeg2threadivlc.mpg +c0e8cbde76ff8377494fe6843fd03e11 *./tests/data/mpeg2thread.vsynth.out.yuv stddev: 7.63 PSNR:30.47 bytes:7602176 -c8d8b07b5fa97e0affb4a52d4d30a2b6 *./data/a-mpeg2reuse.mpg -2102956 ./data/a-mpeg2reuse.mpg -75d3dfc8133f0122cb9e272a21bc8c5c *./data/out.yuv +c8d8b07b5fa97e0affb4a52d4d30a2b6 *./tests/data/a-mpeg2reuse.mpg +2102956 ./tests/data/a-mpeg2reuse.mpg +75d3dfc8133f0122cb9e272a21bc8c5c *./tests/data/mpeg2thread.vsynth.out.yuv stddev: 7.67 PSNR:30.42 bytes:7602176 -c83ae8d8f3e2b4506df58e6a2f7e3b2a *./data/a-msmpeg4v2.avi -636512 ./data/a-msmpeg4v2.avi -279c33c2f6f58b7eb3d2daaa87160cb5 *./data/out.yuv +c83ae8d8f3e2b4506df58e6a2f7e3b2a *./tests/data/a-msmpeg4v2.avi +636512 ./tests/data/a-msmpeg4v2.avi +279c33c2f6f58b7eb3d2daaa87160cb5 *./tests/data/msmpeg4v2.vsynth.out.yuv stddev: 8.00 PSNR:30.06 bytes:7602176 -f546e8d0ada1917bc470584477f83e0e *./data/a-msmpeg4.avi -639406 ./data/a-msmpeg4.avi -8692a2e9ddb8081c4f00cb1557e2388e *./data/out.yuv +f546e8d0ada1917bc470584477f83e0e *./tests/data/a-msmpeg4.avi +639406 ./tests/data/a-msmpeg4.avi +8692a2e9ddb8081c4f00cb1557e2388e *./tests/data/msmpeg4.vsynth.out.yuv stddev: 8.00 PSNR:30.05 bytes:7602176 -44c11ce4aa20af1aa609f68e544e5479 *./data/a-wmv1.avi -641448 ./data/a-wmv1.avi -69454f78ca636e83a600834e5a90660e *./data/out.yuv +3c119e9ee8c8f45d36a0e8f976505f6b *./tests/data/a-wmv1.avi +641178 ./tests/data/a-wmv1.avi +69454f78ca636e83a600834e5a90660e *./tests/data/wmv1.vsynth.out.yuv stddev: 8.01 PSNR:30.04 bytes:7602176 -044b1b5bd5899d54a8fe09eac2181d8b *./data/a-wmv2.avi -675342 ./data/a-wmv2.avi -69454f78ca636e83a600834e5a90660e *./data/out.yuv +d69fe03a838479a0a52da0765d49d42e *./tests/data/a-wmv2.avi +675138 ./tests/data/a-wmv2.avi +69454f78ca636e83a600834e5a90660e *./tests/data/wmv2.vsynth.out.yuv stddev: 8.01 PSNR:30.04 bytes:7602176 -12d215719748b4cf1adeaca4e519ba6c *./data/a-h261.avi -727616 ./data/a-h261.avi -bb2e71de01899ade4f850c180f9b0258 *./data/out.yuv +12d215719748b4cf1adeaca4e519ba6c *./tests/data/a-h261.avi +727616 ./tests/data/a-h261.avi +bb2e71de01899ade4f850c180f9b0258 *./tests/data/h261.vsynth.out.yuv stddev: 9.13 PSNR:28.90 bytes:7602176 -66d36048d15c3b04bd7bfc08ab977fae *./data/a-h263.avi -673694 ./data/a-h263.avi -d507be4253a9c8211a3738c58ba28118 *./data/out.yuv +66d36048d15c3b04bd7bfc08ab977fae *./tests/data/a-h263.avi +673694 ./tests/data/a-h263.avi +d507be4253a9c8211a3738c58ba28118 *./tests/data/h263.vsynth.out.yuv stddev: 8.06 PSNR:29.99 bytes:7602176 -e9e884a7c6b77d1aeeb4cb56ac150f92 *./data/a-h263p.avi -2389564 ./data/a-h263p.avi -0bb16a352798c997cb36e167f4fa8f3c *./data/out.yuv +e9e884a7c6b77d1aeeb4cb56ac150f92 *./tests/data/a-h263p.avi +2389564 ./tests/data/a-h263p.avi +0bb16a352798c997cb36e167f4fa8f3c *./tests/data/h263p.vsynth.out.yuv stddev: 2.07 PSNR:41.77 bytes:7602176 -3ee2dd25f141d520f61e5c01d08bdef1 *./data/a-odivx.mp4 -550787 ./data/a-odivx.mp4 -a1c691f3be526ecbf3be3152d5bab88c *./data/out.yuv +eedd720a38629ea0990685b30b697404 *./tests/data/a-odivx.mp4 +550779 ./tests/data/a-odivx.mp4 +a1c691f3be526ecbf3be3152d5bab88c *./tests/data/mpeg4.vsynth.out.yuv stddev: 7.99 PSNR:30.06 bytes:7602176 -6c58e5707afe056b072d2ce21b3b8e4f *./data/a-huffyuv.avi -7933744 ./data/a-huffyuv.avi -799d3db687f6cdd7a837ec156efc171f *./data/out.yuv +6c58e5707afe056b072d2ce21b3b8e4f *./tests/data/a-huffyuv.avi +7933744 ./tests/data/a-huffyuv.avi +799d3db687f6cdd7a837ec156efc171f *./tests/data/huffyuv.vsynth.out.yuv stddev: 0.00 PSNR:99.99 bytes:7602176 -b27e911f1563455700c93e6ae39715ca *./data/a-mpeg4-rc.avi -813988 ./data/a-mpeg4-rc.avi -f57311745de96b6551c175679b138efc *./data/out.yuv +b27e911f1563455700c93e6ae39715ca *./tests/data/a-mpeg4-rc.avi +813988 ./tests/data/a-mpeg4-rc.avi +f57311745de96b6551c175679b138efc *./tests/data/rc.vsynth.out.yuv stddev: 10.40 PSNR:27.78 bytes:7602176 -85e2456a673041d528b242d78318fb65 *./data/a-mpeg4-adv.avi -600188 ./data/a-mpeg4-adv.avi -60edc5a67271e425d0a2a52981895b81 *./data/out.yuv -stddev: 10.25 PSNR:27.91 bytes:7602176 -d099307d14c1a4daa145618ca0522888 *./data/a-mpeg4-qprd.avi -657996 ./data/a-mpeg4-qprd.avi -8a52c562082bad78cabb40ffa292ceec *./data/out.yuv -stddev: 12.12 PSNR:26.44 bytes:7602176 -9192b10ae298ba325d53abf7b5b91ba3 *./data/a-mpeg4-adap.avi -400650 ./data/a-mpeg4-adap.avi -0ce1d1fbebc9e9178e1a1d4a32a5804c *./data/out.yuv -stddev: 14.66 PSNR:24.80 bytes:7602176 -41b27141442f773eca9ef3d48d8d555a *./data/a-mpeg4-Q.avi -878264 ./data/a-mpeg4-Q.avi -8995abbcc97ed4767fcbc0bf46accd01 *./data/out.yuv +76d3b26ef7e51146e1194956cb0275e6 *./tests/data/a-mpeg4-adv.avi +604580 ./tests/data/a-mpeg4-adv.avi +ee7f2a0be286f09e20372e127364d690 *./tests/data/mpeg4adv.vsynth.out.yuv +stddev: 6.99 PSNR:31.23 bytes:7602176 +13bc53ae93709323b8989cc4f8ea4b1e *./tests/data/a-mpeg4-qprd.avi +736920 ./tests/data/a-mpeg4-qprd.avi +745ccd9185f579cde533c1500fc4adc7 *./tests/data/mpeg4adv.vsynth.out.yuv +stddev: 10.04 PSNR:28.08 bytes:7602176 +5b105ca591f94fa1c2b420cd74b290a1 *./tests/data/a-mpeg4-adap.avi +409360 ./tests/data/a-mpeg4-adap.avi +6ae220d766c44af3bd58e3d2f5aefa8d *./tests/data/mpeg4adv.vsynth.out.yuv +stddev: 14.15 PSNR:25.10 bytes:7602176 +41b27141442f773eca9ef3d48d8d555a *./tests/data/a-mpeg4-Q.avi +878264 ./tests/data/a-mpeg4-Q.avi +8995abbcc97ed4767fcbc0bf46accd01 *./tests/data/mpeg4adv.vsynth.out.yuv stddev: 5.61 PSNR:33.13 bytes:7602176 -5fff534f0b958547dfdb811d4f289931 *./data/a-mpeg4-thread.avi -761170 ./data/a-mpeg4-thread.avi -fe1d119938f8a26174b38eeaa18dff85 *./data/out.yuv -stddev: 12.31 PSNR:26.31 bytes:7602176 -c1dae02bddd79790266bc0a9f7d6eb0e *./data/a-mpeg4-PSP.mp4 -406449 ./data/a-mpeg4-PSP.mp4 -7315281e07830456208dff61337c982b *./data/a-error-mpeg4-adv.avi -731526 ./data/a-error-mpeg4-adv.avi -6ce2c82a0a9cf67a6991694473e9a306 *./data/out.yuv +6271c9f3b8a6ec3a78315699952d9a99 *./tests/data/a-mpeg4-thread.avi +778604 ./tests/data/a-mpeg4-thread.avi +152d46da2a9d7fa3c22c56767c1760db *./tests/data/mpeg4thread.vsynth.out.yuv +stddev: 10.26 PSNR:27.89 bytes:7602176 +743cf18c1e8941591f8ab41350247c42 *./tests/data/a-mpeg4-PSP.mp4 +406441 ./tests/data/a-mpeg4-PSP.mp4 +7315281e07830456208dff61337c982b *./tests/data/a-error-mpeg4-adv.avi +731526 ./tests/data/a-error-mpeg4-adv.avi +6ce2c82a0a9cf67a6991694473e9a306 *./tests/data/error.vsynth.out.yuv stddev: 18.23 PSNR:22.90 bytes:7602176 -b699b2fd005571dda3f8d34cb0ce7aec *./data/a-mpeg4-nr.avi -688676 ./data/a-mpeg4-nr.avi -2c16e13b1367022d52b0e75d93a734ba *./data/out.yuv +b699b2fd005571dda3f8d34cb0ce7aec *./tests/data/a-mpeg4-nr.avi +688676 ./tests/data/a-mpeg4-nr.avi +2c16e13b1367022d52b0e75d93a734ba *./tests/data/mpeg4nr.vsynth.out.yuv stddev: 7.02 PSNR:31.18 bytes:7602176 -225ab004f6ac16e5ade3b453f45b9d96 *./data/a-mpeg1b.mpg -1026429 ./data/a-mpeg1b.mpg -dd9a471c6b2d1004a90e42f34707becf *./data/out.yuv +225ab004f6ac16e5ade3b453f45b9d96 *./tests/data/a-mpeg1b.mpg +1026429 ./tests/data/a-mpeg1b.mpg +dd9a471c6b2d1004a90e42f34707becf *./tests/data/mpeg1b.vsynth.out.yuv stddev: 6.34 PSNR:32.07 bytes:7602176 -2f9cb2ede35f7d12f6b518c50e20d81c *./data/a-mjpeg.avi -1567580 ./data/a-mjpeg.avi -18c3a76f984e717dd886d21fa04355f6 *./data/out.yuv +2f9cb2ede35f7d12f6b518c50e20d81c *./tests/data/a-mjpeg.avi +1567580 ./tests/data/a-mjpeg.avi +18c3a76f984e717dd886d21fa04355f6 *./tests/data/mjpeg.vsynth.out.yuv stddev: 7.93 PSNR:30.13 bytes:7602176 -5a662e3833d900b56cca79ba5ed5ec06 *./data/a-ljpeg.avi -6264498 ./data/a-ljpeg.avi -799d3db687f6cdd7a837ec156efc171f *./data/out.yuv +5a662e3833d900b56cca79ba5ed5ec06 *./tests/data/a-ljpeg.avi +6264498 ./tests/data/a-ljpeg.avi +799d3db687f6cdd7a837ec156efc171f *./tests/data/ljpeg.vsynth.out.yuv stddev: 0.00 PSNR:99.99 bytes:7602176 -dca9d700da7857217408c310c501b9bc *./data/a-jpegls.avi -9086676 ./data/a-jpegls.avi -0f8637e9b861230aff9894825af83720 *./data/out.yuv +dca9d700da7857217408c310c501b9bc *./tests/data/a-jpegls.avi +9086676 ./tests/data/a-jpegls.avi +0f8637e9b861230aff9894825af83720 *./tests/data/jpegls.vsynth.out.yuv stddev: 2.84 PSNR:39.04 bytes:7602176 -7eee6367442884321e27d15a26bc032a *./data/a-rv10.rm -667915 ./data/a-rv10.rm -d507be4253a9c8211a3738c58ba28118 *./data/out.yuv +99ef24bf57718fd29a7a91b22af2b3fe *./tests/data/a-rv10.rm +667935 ./tests/data/a-rv10.rm +d507be4253a9c8211a3738c58ba28118 *./tests/data/rv10.vsynth.out.yuv stddev: 8.06 PSNR:29.99 bytes:7602176 -55c73229105f35cbb06ee0dda215df2f *./data/a-rv20.rm -640856 ./data/a-rv20.rm -297dc46da1a256c0a97158c036c30c7f *./data/out.yuv +d1caf150a7b53db8fd5eb8c1d0701daf *./tests/data/a-rv20.rm +640876 ./tests/data/a-rv20.rm +297dc46da1a256c0a97158c036c30c7f *./tests/data/rv20.vsynth.out.yuv stddev: 8.26 PSNR:29.77 bytes:7602176 -d13292f4583618d1b7b525a9ee010dff *./data/a-asv1.avi -1488864 ./data/a-asv1.avi -925320b74c7dfda5dc8378dd879ae2c3 *./data/out.yuv +d13292f4583618d1b7b525a9ee010dff *./tests/data/a-asv1.avi +1488864 ./tests/data/a-asv1.avi +925320b74c7dfda5dc8378dd879ae2c3 *./tests/data/asv1.vsynth.out.yuv stddev: 20.00 PSNR:22.10 bytes:7602176 -2e50b590f32bf98bde82dbfaf180007a *./data/a-asv2.avi -1454536 ./data/a-asv2.avi -0b310840a6d3970595983491687669df *./data/out.yuv +2e50b590f32bf98bde82dbfaf180007a *./tests/data/a-asv2.avi +1454536 ./tests/data/a-asv2.avi +0b310840a6d3970595983491687669df *./tests/data/asv2.vsynth.out.yuv stddev: 18.82 PSNR:22.63 bytes:7602176 -cbdb25fe5bb6a895baf9799b8ccb3038 *./data/a-flv.flv -649040 ./data/a-flv.flv -40281942d6ee254f7d3027b8593b19be *./data/out.yuv +cbdb25fe5bb6a895baf9799b8ccb3038 *./tests/data/a-flv.flv +649040 ./tests/data/a-flv.flv +40281942d6ee254f7d3027b8593b19be *./tests/data/flv.vsynth.out.yuv stddev: 8.06 PSNR:29.99 bytes:7602176 -f8f51fa737add17f7fecaefa118b57ed *./data/a-ffv1.avi -2654678 ./data/a-ffv1.avi -799d3db687f6cdd7a837ec156efc171f *./data/out.yuv +f8f51fa737add17f7fecaefa118b57ed *./tests/data/a-ffv1.avi +2654678 ./tests/data/a-ffv1.avi +799d3db687f6cdd7a837ec156efc171f *./tests/data/ffv1.vsynth.out.yuv stddev: 0.00 PSNR:99.99 bytes:7602176 -9078723c943de5d79490f54b99e6ea9e *./data/a-snow.avi -156656 ./data/a-snow.avi -f2932084b52e2ede167c9ba21eae0656 *./data/out.yuv -stddev: 23.14 PSNR:20.83 bytes:7602176 -ba999e86070aa971376e7f317a022c37 *./data/a-snow53.avi -3519486 ./data/a-snow53.avi -799d3db687f6cdd7a837ec156efc171f *./data/out.yuv +5b3430252fdbbc7de5ffedc36150b0bf *./tests/data/a-snow.avi +156726 ./tests/data/a-snow.avi +3de2b39f90fd8331f27e627e68e076f7 *./tests/data/snow.vsynth.out.yuv +stddev: 23.15 PSNR:20.83 bytes:7602176 +c7397d2ceb420f7564dcc785948bff84 *./tests/data/a-snow53.avi +3520692 ./tests/data/a-snow53.avi +799d3db687f6cdd7a837ec156efc171f *./tests/data/snowll.vsynth.out.yuv stddev: 0.00 PSNR:99.99 bytes:7602176 -c299f64c3e85b928c5bfe71629cee006 *./data/a-dv.dv -7200000 ./data/a-dv.dv -3b9ead854b912e43ead976e4e86aab3b *./data/out.yuv +c299f64c3e85b928c5bfe71629cee006 *./tests/data/a-dv.dv +7200000 ./tests/data/a-dv.dv +3b9ead854b912e43ead976e4e86aab3b *./tests/data/dv.vsynth.out.yuv stddev: 8.91 PSNR:29.12 bytes:7602176 -70dc9a58345e603094dedcac71e2dcd2 *./data/a-dv.dv -14400000 ./data/a-dv.dv -d727da8c7ce387ebe68845a1be916ee3 *./data/out.yuv +70dc9a58345e603094dedcac71e2dcd2 *./tests/data/a-dv50.dv +14400000 ./tests/data/a-dv50.dv +d727da8c7ce387ebe68845a1be916ee3 *./tests/data/dv50.vsynth.out.yuv stddev: 8.50 PSNR:29.52 bytes:7602176 -6860534864cad0de4b1af9f987aaf9bf *./data/a-svq1.mov -1365791 ./data/a-svq1.mov -fb0a97094a89d6f379535f615783d00c *./data/out.yuv +95d08d714679c0f1a96b6da353c64660 *./tests/data/a-svq1.mov +1365783 ./tests/data/a-svq1.mov +fb0a97094a89d6f379535f615783d00c *./tests/data/svq1.vsynth.out.yuv stddev: 10.98 PSNR:27.30 bytes:7602176 -21f8ff9f1daacd9133683bb4ea0f50a4 *./data/a-mp2.mp2 -95712 ./data/a-mp2.mp2 -83f8df5d5f84480566af548bb037fceb *./data/out.wav +7f1f97c37bfff641d0f137f9774c0112 *./tests/data/a-flashsv.flv +14685499 ./tests/data/a-flashsv.flv +0f8637e9b861230aff9894825af83720 *./tests/data/flashsv.vsynth.out.yuv +stddev: 2.84 PSNR:39.04 bytes:7602176 +21f8ff9f1daacd9133683bb4ea0f50a4 *./tests/data/a-mp2.mp2 +95712 ./tests/data/a-mp2.mp2 +83f8df5d5f84480566af548bb037fceb *./tests/data/mp2.vsynth.out.wav stddev:9330.70 PSNR:16.92 bytes:1054720 stddev:4396.13 PSNR:23.46 bytes:1052672 -aefe11ab5067621a1c674859d6413891 *./data/a-ac3.rm -98203 ./data/a-ac3.rm -39878597b1d65cce473639a7d8c93b02 *./data/a-g726.wav -24279 ./data/a-g726.wav -888f2f016e608d044a1bacbca5497ed2 *./data/out.wav +aefe11ab5067621a1c674859d6413891 *./tests/data/a-ac3.rm +98203 ./tests/data/a-ac3.rm +39878597b1d65cce473639a7d8c93b02 *./tests/data/a-g726.wav +24279 ./tests/data/a-g726.wav +888f2f016e608d044a1bacbca5497ed2 *./tests/data/g726.vsynth.out.wav stddev:8368.02 PSNR:17.87 bytes:96256 -de3f0e1f50b19bd8572fdd3dee2e72c4 *./data/a-adpcm_ima.wav -266300 ./data/a-adpcm_ima.wav -60178d48204f5662d91776e36eddc82e *./data/out.wav -stddev:11441.89 PSNR:15.15 bytes:1054720 -628d4789cf9ee16a756ac54b7fd8650d *./data/a-adpcm_ms.wav -267320 ./data/a-adpcm_ms.wav -91a84bb4f319a3a0bf0c0441b3d3a529 *./data/out.wav +3b969c43e45582f713e3c35faee9e0cc *./tests/data/a-adpcm_ima.wav +266300 ./tests/data/a-adpcm_ima.wav +947196b1739a9d6fe0c29424cf61cd8c *./tests/data/adpcm_ima_wav.vsynth.out.wav +stddev:904.20 PSNR:37.19 bytes:1056768 +628d4789cf9ee16a756ac54b7fd8650d *./tests/data/a-adpcm_ms.wav +267320 ./tests/data/a-adpcm_ms.wav +91a84bb4f319a3a0bf0c0441b3d3a529 *./tests/data/adpcm_ms.vsynth.out.wav stddev:1050.18 PSNR:35.89 bytes:1054720 -ab11d9151644cbff27827b7e89f37aa9 *./data/a-adpcm_yam.wav -264248 ./data/a-adpcm_yam.wav -e92cec8c07913ffb91ad2b11f79cdc00 *./data/out.wav +ab11d9151644cbff27827b7e89f37aa9 *./tests/data/a-adpcm_yam.wav +264248 ./tests/data/a-adpcm_yam.wav +e92cec8c07913ffb91ad2b11f79cdc00 *./tests/data/adpcm_yam.vsynth.out.wav stddev:18312.68 PSNR:11.06 bytes:1056768 -c3382f03ce2efb5d475240d288a33898 *./data/a-flac.flac -353368 ./data/a-flac.flac -c4228df189aad9567a037727d0e763e4 *./data/out.wav +de1122d20d56c44cf49f028e25a67788 *./tests/data/a-adpcm_swf.flv +267073 ./tests/data/a-adpcm_swf.flv +e48b800e2d9be6afcd430d4f08a34eb6 *./tests/data/adpcm_swf.vsynth.out.wav +stddev:934.30 PSNR:36.91 bytes:1056768 +c3382f03ce2efb5d475240d288a33898 *./tests/data/a-flac.flac +353368 ./tests/data/a-flac.flac +c4228df189aad9567a037727d0e763e4 *./tests/data/flac.vsynth.out.wav stddev: 33.31 PSNR:65.87 bytes:1040384 -0c406c4e4586ca27064e28637b662631 *./data/a-wmav1.asf -106004 ./data/a-wmav1.asf +a1e56bb034c2773438ba1c830c4cea07 *./tests/data/a-wmav1.asf +106004 ./tests/data/a-wmav1.asf stddev:12251.50 PSNR:14.56 bytes:1056768 stddev:2106.00 PSNR:29.85 bytes:1048576 -82442aaa5fdbd327769e4c4ad369147e *./data/a-wmav2.asf -106044 ./data/a-wmav2.asf +5e25c447c80fa937f74ed8752b0e26fb *./tests/data/a-wmav2.asf +106044 ./tests/data/a-wmav2.asf stddev:12255.92 PSNR:14.55 bytes:1056768 stddev:2099.31 PSNR:29.88 bytes:1048576 diff --git a/contrib/ffmpeg/tests/libav.regression.ref b/contrib/ffmpeg/tests/libav.regression.ref index a498d6799..bb85fe162 100644 --- a/contrib/ffmpeg/tests/libav.regression.ref +++ b/contrib/ffmpeg/tests/libav.regression.ref @@ -1,113 +1,129 @@ -ffmpeg regression test -8a0536ccfe36f4fff408b3327d33e1dd *./data/b-libav.avi -340344 ./data/b-libav.avi -./data/b-libav.avi CRC=0x400c29e9 -786446e80ead936e5faa8f5908f19281 *./data/b-libav.asf -339775 ./data/b-libav.asf -./data/b-libav.asf CRC=0x74113749 -1ce78eeb6881ffe5b649a9b5105de919 *./data/b-libav.rm -355405 ./data/b-libav.rm -bdb7484c68db722f66ba1630cf79844c *./data/b-libav.mpg -378880 ./data/b-libav.mpg -./data/b-libav.mpg CRC=0x2b71a386 -322d59758fe9446147223a607d1699bc *./data/b-libav.ts -471692 ./data/b-libav.ts -./data/b-libav.ts CRC=0xcc4948e1 -d6fdeb9f7083cc827f9510c6c4517dc0 *./data/b-libav.swf -335771 ./data/b-libav.swf -./data/b-libav.swf CRC=0xe14e8847 -a1cd7fff97d5e4c83f0d18a22d51c552 *./data/b-libav.ffm -380928 ./data/b-libav.ffm -./data/b-libav.ffm CRC=0x01522b4a -f8ad5bd78f4d012a8ce9570aa395ac54 *./data/b-libav.flv -335833 ./data/b-libav.flv -./data/b-libav.flv CRC=0xe14e8847 -16518706f425cb537362bfc1c58b8de5 *./data/b-libav.mov -366923 ./data/b-libav.mov -./data/b-libav.mov CRC=0x45079dca -7820fa85ab86c62028d8dbda94589573 *./data/b-libav.dv -3600000 ./data/b-libav.dv -./data/b-libav.dv CRC=0xf517e829 -feb04ba3cf4f607d5527664eb69ec72e *./data/b-libav.gxf -814640 ./data/b-libav.gxf -./data/b-libav.gxf CRC=0xa376c09e -9a9da315747599f7718cc9a9a09c21ff *./data/b-libav.pbm - 317075 ./data/b-libav.pbm -./data/b-libav.pbm CRC=0xb92906cb -6ea0e1faf08f6fcdb44db4a104361b57 *./data/b-libav.pgm -2534775 ./data/b-libav.pgm -./data/b-libav.pgm CRC=0xf4aa7c47 -0c5fe86621b7377705837f304d4ba1e9 *./data/b-libav.ppm -7603575 ./data/b-libav.ppm -./data/b-libav.ppm CRC=0xb2bb8e92 -88a98269295fbfce7816558ad84e1259 *./data/b-libav.gif -2906382 ./data/b-libav.gif -b977a4fedff90a79baf70c8e02986820 *./data/b-libav.y4m -3801810 ./data/b-libav.y4m -./data/b-libav%02d.pgm CRC=0x84c09106 -de216b43403f51e57e644fbf812568bf *./data/b-libav02.pgm -./data/b-libav%02d.ppm CRC=0x25c06ecf -86bbdb77afa289ff363120f8044f29df *./data/b-libav02.ppm -./data/b-libav%02d.bmp CRC=0xf3a66ecf -c3a9f333ddebff6eae3f4360bad2de29 *./data/b-libav02.bmp -./data/b-libav%02d.tga CRC=0xf3a66ecf -f558eef0740c4b247f1eb17e1dbf7adf *./data/b-libav02.tga -./data/b-libav%02d.jpg CRC=0x62328baa -5d6c53e5297c4485e26c25e37885376f *./data/b-libav02.jpg -b0a8c8063d81921db5d7c8f50a1cc454 *./data/b-libav.wav - 89132 ./data/b-libav.wav -./data/b-libav.wav CRC=0x2a09519c -e2a6d6fae17394dfe87cb5bb8ae11837 *./data/b-libav.al - 44544 ./data/b-libav.al -./data/b-libav.al CRC=0xefdf94c3 -4574d7e2c09e1e13663e61bd2889f12d *./data/b-libav.ul - 44544 ./data/b-libav.ul -./data/b-libav.ul CRC=0x6064b2f8 -7a21ff174e3cca1702e0826c4ca0eccf *./data/b-libav.au - 89112 ./data/b-libav.au -./data/b-libav.au CRC=0x2a09519c -272b91d8fc31ed43b08246d182719751 *./data/b-libav.mmf - 22609 ./data/b-libav.mmf -./data/b-libav.mmf CRC=0x03633476 -ae3a23a7ea13c92a2909445ca8144dcd *./data/b-libav.aif -89142 ./data/b-libav.aif -./data/b-libav.aif CRC=0x2a09519c -8d117c49d6b210abe783d1b0b897cec7 *./data/b-libav.voc - 32768 ./data/b-libav.voc -./data/b-libav.voc CRC=0x49972c8c -ce356ce2708cb6033ab5d762da93cfd4 *./data/b-libav-yuv420p.yuv - 304128 ./data/b-libav-yuv420p.yuv -ce356ce2708cb6033ab5d762da93cfd4 *./data/b-libav-yuv422p.yuv - 304128 ./data/b-libav-yuv422p.yuv -ce356ce2708cb6033ab5d762da93cfd4 *./data/b-libav-yuv444p.yuv - 304128 ./data/b-libav-yuv444p.yuv -ce356ce2708cb6033ab5d762da93cfd4 *./data/b-libav-yuyv422.yuv - 304128 ./data/b-libav-yuyv422.yuv -545f61c353a8b4419808785cb4f0069d *./data/b-libav-yuv410p.yuv - 304128 ./data/b-libav-yuv410p.yuv -d6c03f930018ff859bd43f52b92e9321 *./data/b-libav-yuv411p.yuv - 304128 ./data/b-libav-yuv411p.yuv -14117c4d7956775a7bbceabfc38da808 *./data/b-libav-yuvj420p.yuv - 304128 ./data/b-libav-yuvj420p.yuv -14117c4d7956775a7bbceabfc38da808 *./data/b-libav-yuvj422p.yuv - 304128 ./data/b-libav-yuvj422p.yuv -14117c4d7956775a7bbceabfc38da808 *./data/b-libav-yuvj444p.yuv - 304128 ./data/b-libav-yuvj444p.yuv -deb2f7ebe297df2c1fe264d19b34d2fb *./data/b-libav-rgb24.yuv - 304128 ./data/b-libav-rgb24.yuv -deb2f7ebe297df2c1fe264d19b34d2fb *./data/b-libav-bgr24.yuv - 304128 ./data/b-libav-bgr24.yuv -deb2f7ebe297df2c1fe264d19b34d2fb *./data/b-libav-rgb32.yuv - 304128 ./data/b-libav-rgb32.yuv -5d395f62bff8ac475f743268c772ca3a *./data/b-libav-rgb565.yuv - 304128 ./data/b-libav-rgb565.yuv -2ffd6871fcbfe9570454e8703ac8ea01 *./data/b-libav-rgb555.yuv - 304128 ./data/b-libav-rgb555.yuv -0b62dcf9b57b294dbaa5d9e99b1ee192 *./data/b-libav-gray.yuv - 304128 ./data/b-libav-gray.yuv -e197450dae2feba9e757b551e1e9145c *./data/b-libav-monow.yuv - 304128 ./data/b-libav-monow.yuv -e197450dae2feba9e757b551e1e9145c *./data/b-libav-monob.yuv - 304128 ./data/b-libav-monob.yuv -7a319375916cae4e691ecb74295e5d2a *./data/b-libav-pal8.yuv - 304128 ./data/b-libav-pal8.yuv +8a0536ccfe36f4fff408b3327d33e1dd *./tests/data/b-libav.avi +340344 ./tests/data/b-libav.avi +./tests/data/b-libav.avi CRC=0x400c29e9 +7b859661e93df32e51942a4e0531d58e *./tests/data/b-libav.asf +339775 ./tests/data/b-libav.asf +./tests/data/b-libav.asf CRC=0x74113749 +c351132527ccb1e8cab06cc0822fde23 *./tests/data/b-libav.rm +355417 ./tests/data/b-libav.rm +bdb7484c68db722f66ba1630cf79844c *./tests/data/b-libav.mpg +378880 ./tests/data/b-libav.mpg +./tests/data/b-libav.mpg CRC=0x2b71a386 +322d59758fe9446147223a607d1699bc *./tests/data/b-libav.ts +471692 ./tests/data/b-libav.ts +./tests/data/b-libav.ts CRC=0xcc4948e1 +d6fdeb9f7083cc827f9510c6c4517dc0 *./tests/data/b-libav.swf +335771 ./tests/data/b-libav.swf +./tests/data/b-libav.swf CRC=0xe14e8847 +745e811e246f3727dc80a7504a18b129 *./tests/data/b-libav.ffm +380928 ./tests/data/b-libav.ffm +./tests/data/b-libav.ffm CRC=0x01522b4a +f8ad5bd78f4d012a8ce9570aa395ac54 *./tests/data/b-libav.flv +335833 ./tests/data/b-libav.flv +./tests/data/b-libav.flv CRC=0xe14e8847 +16518706f425cb537362bfc1c58b8de5 *./tests/data/b-libav.mov +366923 ./tests/data/b-libav.mov +./tests/data/b-libav.mov CRC=0x45079dca +7820fa85ab86c62028d8dbda94589573 *./tests/data/b-libav.dv +3600000 ./tests/data/b-libav.dv +./tests/data/b-libav.dv CRC=0xf517e829 +2ba41cf880aa5cb87e8a08fdb735398d *./tests/data/b-libav.gxf +814640 ./tests/data/b-libav.gxf +./tests/data/b-libav.gxf CRC=0xa376c09e +66a6584f9e83e8ea3af822a3ba71fbbe *./tests/data/b-libav.nut +329264 ./tests/data/b-libav.nut +./tests/data/b-libav.nut CRC=0x400c29e9 +43238b15f1012aa27536c2be20bb2383 *./tests/data/b-libav.mkv +329854 ./tests/data/b-libav.mkv +./tests/data/b-libav.mkv CRC=0x400c29e9 +9a9da315747599f7718cc9a9a09c21ff *./tests/data/b-pbmpipe.pbm + 317075 ./tests/data/b-pbmpipe.pbm +./tests/data/b-pbmpipe.pbm CRC=0xb92906cb +6ea0e1faf08f6fcdb44db4a104361b57 *./tests/data/b-pgmpipe.pgm +2534775 ./tests/data/b-pgmpipe.pgm +./tests/data/b-pgmpipe.pgm CRC=0xf4aa7c47 +0c5fe86621b7377705837f304d4ba1e9 *./tests/data/b-ppmpipe.ppm +7603575 ./tests/data/b-ppmpipe.ppm +./tests/data/b-ppmpipe.ppm CRC=0xb2bb8e92 +88a98269295fbfce7816558ad84e1259 *./tests/data/b-libav.gif +2906382 ./tests/data/b-libav.gif +b977a4fedff90a79baf70c8e02986820 *./tests/data/b-libav.y4m +3801810 ./tests/data/b-libav.y4m +./tests/data/b-libav%02d.pgm CRC=0x84c09106 +de216b43403f51e57e644fbf812568bf *./tests/data/b-libav02.pgm +./tests/data/b-libav%02d.ppm CRC=0x25c06ecf +86bbdb77afa289ff363120f8044f29df *./tests/data/b-libav02.ppm +./tests/data/b-libav%02d.bmp CRC=0xf3a66ecf +c3a9f333ddebff6eae3f4360bad2de29 *./tests/data/b-libav02.bmp +./tests/data/b-libav%02d.tga CRC=0xf3a66ecf +f558eef0740c4b247f1eb17e1dbf7adf *./tests/data/b-libav02.tga +./tests/data/b-libav%02d.tiff CRC=0x25c06ecf +3076b16ac0c8a39a796e69944f6a40dc *./tests/data/b-libav02.tiff +./tests/data/b-libav%02d.sgi CRC=0x00000001 +c6cab058a2b0a33ee843bd096b280075 *./tests/data/b-libav02.sgi +./tests/data/b-libav%02d.jpg CRC=0x62328baa +5d6c53e5297c4485e26c25e37885376f *./tests/data/b-libav02.jpg +b0a8c8063d81921db5d7c8f50a1cc454 *./tests/data/b-libav.wav + 89132 ./tests/data/b-libav.wav +./tests/data/b-libav.wav CRC=0x2a09519c +e2a6d6fae17394dfe87cb5bb8ae11837 *./tests/data/b-libav.al + 44544 ./tests/data/b-libav.al +./tests/data/b-libav.al CRC=0xefdf94c3 +4574d7e2c09e1e13663e61bd2889f12d *./tests/data/b-libav.ul + 44544 ./tests/data/b-libav.ul +./tests/data/b-libav.ul CRC=0x6064b2f8 +7a21ff174e3cca1702e0826c4ca0eccf *./tests/data/b-libav.au + 89112 ./tests/data/b-libav.au +./tests/data/b-libav.au CRC=0x2a09519c +272b91d8fc31ed43b08246d182719751 *./tests/data/b-libav.mmf + 22609 ./tests/data/b-libav.mmf +./tests/data/b-libav.mmf CRC=0x03633476 +ae3a23a7ea13c92a2909445ca8144dcd *./tests/data/b-libav.aif +89142 ./tests/data/b-libav.aif +./tests/data/b-libav.aif CRC=0x2a09519c +8d117c49d6b210abe783d1b0b897cec7 *./tests/data/b-libav.voc + 32768 ./tests/data/b-libav.voc +./tests/data/b-libav.voc CRC=0x49972c8c +d7e6e9091a600b7208b29500be94aa89 *./tests/data/b-libav.ogg +23624 ./tests/data/b-libav.ogg +./tests/data/b-libav.ogg CRC=0x93baa056 +ce356ce2708cb6033ab5d762da93cfd4 *./tests/data/b-libav-yuv420p.yuv + 304128 ./tests/data/b-libav-yuv420p.yuv +ce356ce2708cb6033ab5d762da93cfd4 *./tests/data/b-libav-yuv422p.yuv + 304128 ./tests/data/b-libav-yuv422p.yuv +ce356ce2708cb6033ab5d762da93cfd4 *./tests/data/b-libav-yuv444p.yuv + 304128 ./tests/data/b-libav-yuv444p.yuv +ce356ce2708cb6033ab5d762da93cfd4 *./tests/data/b-libav-yuyv422.yuv + 304128 ./tests/data/b-libav-yuyv422.yuv +545f61c353a8b4419808785cb4f0069d *./tests/data/b-libav-yuv410p.yuv + 304128 ./tests/data/b-libav-yuv410p.yuv +d6c03f930018ff859bd43f52b92e9321 *./tests/data/b-libav-yuv411p.yuv + 304128 ./tests/data/b-libav-yuv411p.yuv +14117c4d7956775a7bbceabfc38da808 *./tests/data/b-libav-yuvj420p.yuv + 304128 ./tests/data/b-libav-yuvj420p.yuv +14117c4d7956775a7bbceabfc38da808 *./tests/data/b-libav-yuvj422p.yuv + 304128 ./tests/data/b-libav-yuvj422p.yuv +14117c4d7956775a7bbceabfc38da808 *./tests/data/b-libav-yuvj444p.yuv + 304128 ./tests/data/b-libav-yuvj444p.yuv +deb2f7ebe297df2c1fe264d19b34d2fb *./tests/data/b-libav-rgb24.yuv + 304128 ./tests/data/b-libav-rgb24.yuv +deb2f7ebe297df2c1fe264d19b34d2fb *./tests/data/b-libav-bgr24.yuv + 304128 ./tests/data/b-libav-bgr24.yuv +deb2f7ebe297df2c1fe264d19b34d2fb *./tests/data/b-libav-rgb32.yuv + 304128 ./tests/data/b-libav-rgb32.yuv +5d395f62bff8ac475f743268c772ca3a *./tests/data/b-libav-rgb565.yuv + 304128 ./tests/data/b-libav-rgb565.yuv +2ffd6871fcbfe9570454e8703ac8ea01 *./tests/data/b-libav-rgb555.yuv + 304128 ./tests/data/b-libav-rgb555.yuv +0b62dcf9b57b294dbaa5d9e99b1ee192 *./tests/data/b-libav-gray.yuv + 304128 ./tests/data/b-libav-gray.yuv +e197450dae2feba9e757b551e1e9145c *./tests/data/b-libav-monow.yuv + 304128 ./tests/data/b-libav-monow.yuv +e197450dae2feba9e757b551e1e9145c *./tests/data/b-libav-monob.yuv + 304128 ./tests/data/b-libav-monob.yuv +7a319375916cae4e691ecb74295e5d2a *./tests/data/b-libav-pal8.yuv + 304128 ./tests/data/b-libav-pal8.yuv +ce356ce2708cb6033ab5d762da93cfd4 *./tests/data/b-libav-yuv440p.yuv + 304128 ./tests/data/b-libav-yuv440p.yuv +14117c4d7956775a7bbceabfc38da808 *./tests/data/b-libav-yuvj440p.yuv + 304128 ./tests/data/b-libav-yuvj440p.yuv diff --git a/contrib/ffmpeg/tests/regression.sh b/contrib/ffmpeg/tests/regression.sh index c4c2f776b..44bf9ebf2 100755 --- a/contrib/ffmpeg/tests/regression.sh +++ b/contrib/ffmpeg/tests/regression.sh @@ -4,105 +4,32 @@ # # #set -x -# Even in the 21st century some diffs do not support -u. -diff -u "$0" "$0" > /dev/null 2>&1 -if [ $? -eq 0 ]; then - diff_cmd="diff -u" -else - diff_cmd="diff" -fi - -diff -w "$0" "$0" > /dev/null 2>&1 -if [ $? -eq 0 ]; then - diff_cmd="$diff_cmd -w" -fi set -e -datadir="./data" - -logfile="$datadir/ffmpeg.regression" -outfile="$datadir/a-" - -# tests to run -if [ "$1" = "mpeg4" ] ; then - do_mpeg4=y -elif [ "$1" = "mpeg" ] ; then - do_mpeg=y - do_mpeg2=y -elif [ "$1" = "ac3" ] ; then - do_ac3=y -elif [ "$1" = "huffyuv" ] ; then - do_huffyuv=y -elif [ "$1" = "mpeg2thread" ] ; then - do_mpeg2thread=y -elif [ "$1" = "snow" ] ; then - do_snow=y -elif [ "$1" = "snowll" ] ; then - do_snowll=y -elif [ "$1" = "libavtest" ] ; then - do_libavtest=y - logfile="$datadir/libav.regression" - outfile="$datadir/b-" -else - do_mpeg=y - do_mpeg2=y - do_mpeg2thread=y - do_msmpeg4v2=y - do_msmpeg4=y - do_wmv1=y - do_wmv2=y - do_h261=y - do_h263=y - do_h263p=y - do_mpeg4=y - do_mp4psp=y - do_huffyuv=y - do_mjpeg=y - do_ljpeg=y - do_jpegls=y - do_rv10=y - do_rv20=y - do_mp2=y - do_ac3=y - do_g726=y - do_adpcm_ima_wav=y - do_adpcm_ms=y - do_flac=y - do_wma=y - do_vorbis=y - do_rc=y - do_mpeg4adv=y - do_mpeg4thread=y - do_mpeg4nr=y - do_mpeg1b=y - do_asv1=y - do_asv2=y - do_flv=y - do_ffv1=y - do_error=y - do_svq1=y - do_snow=y - do_snowll=y - do_adpcm_yam=y - do_dv=y - do_dv50=y -fi +datadir="./tests/data" + +test="${1#regtest-}" +this="$test.$2" +logfile="$datadir/$this.regression" +outfile="$datadir/$4-" +eval do_$test=y # various files -ffmpeg="../ffmpeg_g" -tiny_psnr="./tiny_psnr" -reffile="$2" -benchfile="$datadir/ffmpeg.bench" -bench="$datadir/bench.tmp" -bench2="$datadir/bench2.tmp" +ffmpeg="./ffmpeg_g" +tiny_psnr="tests/tiny_psnr" +benchfile="$datadir/$this.bench" +bench="$datadir/$this.bench.tmp" +bench2="$datadir/$this.bench2.tmp" raw_src="$3/%02d.pgm" -raw_dst="$datadir/out.yuv" -raw_ref="$datadir/ref.yuv" -pcm_src="asynth1.sw" -pcm_dst="$datadir/out.wav" -pcm_ref="$datadir/ref.wav" +raw_dst="$datadir/$this.out.yuv" +raw_ref="$datadir/$2.ref.yuv" +pcm_src="tests/asynth1.sw" +pcm_dst="$datadir/$this.out.wav" +pcm_ref="$datadir/$2.ref.wav" +crcfile="$datadir/$this.crc" + if [ X"`echo | md5sum 2> /dev/null`" != X ]; then do_md5sum() { md5sum -b $1; } elif [ -x /sbin/md5 ]; then @@ -159,11 +86,12 @@ do_ffmpeg_crc() { f="$1" shift - echo $ffmpeg $FFMPEG_OPTS $* -f crc $datadir/ffmpeg.crc - $ffmpeg $FFMPEG_OPTS $* -f crc $datadir/ffmpeg.crc > /tmp/ffmpeg$$ 2>&1 + echo $ffmpeg $FFMPEG_OPTS $* -f crc "$crcfile" + $ffmpeg $FFMPEG_OPTS $* -f crc "$crcfile" > /tmp/ffmpeg$$ 2>&1 egrep -v "^(Stream|Press|Input|Output|frame| Stream| Duration|video:|ffmpeg version| configuration| built)" /tmp/ffmpeg$$ || true rm -f /tmp/ffmpeg$$ - echo "$f `cat $datadir/ffmpeg.crc`" >> $logfile + echo "$f `cat $crcfile`" >> $logfile + rm -f "$crcfile" } do_ffmpeg_nocheck() @@ -181,6 +109,7 @@ do_ffmpeg_nocheck() do_video_decoding() { do_ffmpeg $raw_dst -y $1 -i $file -f rawvideo $2 $raw_dst + rm -f $raw_dst } do_video_encoding() @@ -210,7 +139,7 @@ do_libav() do_streamed_images() { - file=${outfile}libav.$1 + file=${outfile}${1}pipe.$1 do_ffmpeg $file -t 1 -y -qscale 10 -f pgmyuv -i $raw_src -f image2pipe $file do_ffmpeg_crc $file -f image2pipe -i $file } @@ -218,7 +147,7 @@ do_streamed_images() do_image_formats() { file=${outfile}libav%02d.$1 - $ffmpeg -t 0.5 -y -qscale 10 -f pgmyuv -i $raw_src $2 $3 $file + $ffmpeg -t 0.5 -y -qscale 10 -f pgmyuv -i $raw_src $2 $3 -flags +bitexact $file do_ffmpeg_crc $file $3 -i $file do_md5sum ${outfile}libav02.$1 >> $logfile } @@ -230,22 +159,21 @@ do_audio_only() do_ffmpeg_crc $file -i $file } -echo "ffmpeg regression test" > $logfile -echo "ffmpeg benchmarks" > $benchfile +rm -f "$logfile" +rm -f "$benchfile" -################################### # generate reference for quality check +if [ -n "$do_ref" ]; then do_ffmpeg_nocheck $raw_ref -y -f pgmyuv -i $raw_src -an -f rawvideo $raw_ref do_ffmpeg_nocheck $pcm_ref -y -ab 128k -ac 2 -ar 44100 -f s16le -i $pcm_src -f wav $pcm_ref +fi -################################### if [ -n "$do_mpeg" ] ; then # mpeg1 do_video_encoding mpeg1.mpg "-qscale 10" pgmyuv "-f mpeg1video" do_video_decoding fi -################################### if [ -n "$do_mpeg2" ] ; then # mpeg2 do_video_encoding mpeg2.mpg "-qscale 10" pgmyuv "-vcodec mpeg2video -f mpeg1video" @@ -268,7 +196,6 @@ do_video_encoding mpeg2i.mpg "-qscale 10" pgmyuv "-vcodec mpeg2video -f mpeg1vid do_video_decoding fi -################################### if [ -n "$do_mpeg2thread" ] ; then # mpeg2 encoding interlaced do_video_encoding mpeg2thread.mpg "-qscale 10" pgmyuv "-vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -threads 2" @@ -290,279 +217,210 @@ do_ffmpeg $file -y -sameq -me_threshold 256 -mb_threshold 1024 -i ${outfile}mpeg do_video_decoding fi -################################### if [ -n "$do_msmpeg4v2" ] ; then -# msmpeg4 do_video_encoding msmpeg4v2.avi "-qscale 10" pgmyuv "-an -vcodec msmpeg4v2" do_video_decoding fi -################################### if [ -n "$do_msmpeg4" ] ; then -# msmpeg4 do_video_encoding msmpeg4.avi "-qscale 10" pgmyuv "-an -vcodec msmpeg4" do_video_decoding fi -################################### if [ -n "$do_wmv1" ] ; then -# wmv1 do_video_encoding wmv1.avi "-qscale 10" pgmyuv "-an -vcodec wmv1" do_video_decoding fi -################################### if [ -n "$do_wmv2" ] ; then -# wmv2 do_video_encoding wmv2.avi "-qscale 10" pgmyuv "-an -vcodec wmv2" do_video_decoding fi -################################### if [ -n "$do_h261" ] ; then -# h261 do_video_encoding h261.avi "-qscale 11" pgmyuv "-s 352x288 -an -vcodec h261" do_video_decoding fi -################################### if [ -n "$do_h263" ] ; then -# h263 do_video_encoding h263.avi "-qscale 10" pgmyuv "-s 352x288 -an -vcodec h263" do_video_decoding fi -################################### if [ -n "$do_h263p" ] ; then -# h263p do_video_encoding h263p.avi "-qscale 2 -flags +umv+aiv+aic" pgmyuv "-s 352x288 -an -vcodec h263p -ps 300" do_video_decoding fi -################################### if [ -n "$do_mpeg4" ] ; then -# mpeg4 do_video_encoding odivx.mp4 "-flags +mv4 -mbd bits -qscale 10" pgmyuv "-an -vcodec mpeg4" do_video_decoding fi -################################### if [ -n "$do_huffyuv" ] ; then -# huffyuv do_video_encoding huffyuv.avi "" pgmyuv "-an -vcodec huffyuv -pix_fmt yuv422p" do_video_decoding "" "-strict -2 -pix_fmt yuv420p" fi -################################### if [ -n "$do_rc" ] ; then -# mpeg4 rate control do_video_encoding mpeg4-rc.avi "-b 400k -bf 2" pgmyuv "-an -vcodec mpeg4" do_video_decoding fi -################################### if [ -n "$do_mpeg4adv" ] ; then -# mpeg4 do_video_encoding mpeg4-adv.avi "-qscale 9 -flags +mv4+part+aic+trell -mbd bits -ps 200" pgmyuv "-an -vcodec mpeg4" do_video_decoding -# mpeg4 do_video_encoding mpeg4-qprd.avi "-b 450k -bf 2 -flags +mv4+trell+qprd+mv0 -cmp 2 -subcmp 2 -mbd rd" pgmyuv "-an -vcodec mpeg4" do_video_decoding -# mpeg4 do_video_encoding mpeg4-adap.avi "-b 550k -bf 2 -flags +mv4+trell+mv0 -cmp 1 -subcmp 2 -mbd rd -scplx_mask 0.3" pgmyuv "-an -vcodec mpeg4" do_video_decoding -# mpeg4 do_video_encoding mpeg4-Q.avi "-qscale 7 -flags +mv4+qpel -mbd 2 -bf 2 -cmp 1 -subcmp 2" pgmyuv "-an -vcodec mpeg4" do_video_decoding fi -################################### if [ -n "$do_mpeg4thread" ] ; then -# mpeg4 do_video_encoding mpeg4-thread.avi "-b 500k -flags +mv4+part+aic+trell -mbd bits -ps 200 -bf 2" pgmyuv "-an -vcodec mpeg4 -threads 2" do_video_decoding fi -################################### if [ -n "$do_mp4psp" ] ; then -# mp4 PSP style do_video_encoding mpeg4-PSP.mp4 "-vb 768k -s 320x240" psp "-ar 24000 -ab 32k -i $raw_src" fi -################################### if [ -n "$do_error" ] ; then -# damaged mpeg4 do_video_encoding error-mpeg4-adv.avi "-qscale 7 -flags +mv4+part+aic -mbd rd -ps 250 -error 10" pgmyuv "-an -vcodec mpeg4" do_video_decoding fi -################################### if [ -n "$do_mpeg4nr" ] ; then -# noise reduction do_video_encoding mpeg4-nr.avi "-qscale 8 -flags +mv4 -mbd rd -nr 200" pgmyuv "-an -vcodec mpeg4" do_video_decoding fi -################################### if [ -n "$do_mpeg1b" ] ; then -# mpeg1 do_video_encoding mpeg1b.mpg "-qscale 8 -bf 3 -ps 200" pgmyuv "-an -vcodec mpeg1video -f mpeg1video" do_video_decoding fi -################################### if [ -n "$do_mjpeg" ] ; then -# mjpeg do_video_encoding mjpeg.avi "-qscale 10" pgmyuv "-an -vcodec mjpeg -pix_fmt yuvj420p" do_video_decoding "" "-pix_fmt yuv420p" fi -################################### if [ -n "$do_ljpeg" ] ; then -# ljpeg do_video_encoding ljpeg.avi "" pgmyuv "-an -vcodec ljpeg -strict -1" do_video_decoding fi -################################### if [ -n "$do_jpegls" ] ; then -# jpeg ls do_video_encoding jpegls.avi "" pgmyuv "-an -vcodec jpegls -vtag MJPG" do_video_decoding "" "-pix_fmt yuv420p" fi -################################### if [ -n "$do_rv10" ] ; then -# rv10 encoding do_video_encoding rv10.rm "-qscale 10" pgmyuv "-an" do_video_decoding fi -################################### if [ -n "$do_rv20" ] ; then -# rv20 encoding do_video_encoding rv20.rm "-qscale 10" pgmyuv "-vcodec rv20 -an" do_video_decoding fi -################################### if [ -n "$do_asv1" ] ; then -# asv1 encoding do_video_encoding asv1.avi "-qscale 10" pgmyuv "-an -vcodec asv1" do_video_decoding fi -################################### if [ -n "$do_asv2" ] ; then -# asv2 encoding do_video_encoding asv2.avi "-qscale 10" pgmyuv "-an -vcodec asv2" do_video_decoding fi -################################### if [ -n "$do_flv" ] ; then -# flv encoding do_video_encoding flv.flv "-qscale 10" pgmyuv "-an -vcodec flv" do_video_decoding fi -################################### if [ -n "$do_ffv1" ] ; then -# ffv1 encoding do_video_encoding ffv1.avi "-strict -2" pgmyuv "-an -vcodec ffv1" do_video_decoding fi -################################### if [ -n "$do_snow" ] ; then -# snow do_video_encoding snow.avi "-strict -2" pgmyuv "-an -vcodec snow -qscale 2 -flags +qpel -me iter -dia_size 2 -cmp 12 -subcmp 12 -s 128x64" do_video_decoding "" "-s 352x288" fi -################################### if [ -n "$do_snowll" ] ; then -# snow do_video_encoding snow53.avi "-strict -2" pgmyuv "-an -vcodec snow -qscale .001 -pred 1 -flags +mv4+qpel" do_video_decoding fi -################################### if [ -n "$do_dv" ] ; then -# dv do_video_encoding dv.dv "-dct int" pgmyuv "-s pal -an" do_video_decoding "" "-s cif" fi -################################### if [ -n "$do_dv50" ] ; then -# dv50 -do_video_encoding dv.dv "-dct int" pgmyuv "-s pal -pix_fmt yuv422p -an" +do_video_encoding dv50.dv "-dct int" pgmyuv "-s pal -pix_fmt yuv422p -an" do_video_decoding "" "-s cif -pix_fmt yuv420p" fi - -################################### if [ -n "$do_svq1" ] ; then -# svq1 do_video_encoding svq1.mov "" pgmyuv "-an -vcodec svq1 -qscale 3 -pix_fmt yuv410p" do_video_decoding "" "-pix_fmt yuv420p" fi -################################### +if [ -n "$do_flashsv" ] ; then +do_video_encoding flashsv.flv "" pgmyuv "-an -vcodec flashsv " +do_video_decoding "" "-pix_fmt yuv420p" +fi + if [ -n "$do_mp2" ] ; then -# mp2 do_audio_encoding mp2.mp2 "-ar 44100" do_audio_decoding $tiny_psnr $pcm_dst $pcm_ref 2 1924 >> $logfile fi -################################### if [ -n "$do_ac3" ] ; then -# ac3 do_audio_encoding ac3.rm "" -vn #do_audio_decoding fi -################################### if [ -n "$do_g726" ] ; then -# g726 do_audio_encoding g726.wav "-ar 44100" "-ab 32k -ac 1 -ar 8000 -acodec g726" do_audio_decoding fi -################################### if [ -n "$do_adpcm_ima_wav" ] ; then -# adpcm ima do_audio_encoding adpcm_ima.wav "-ar 44100" "-acodec adpcm_ima_wav" do_audio_decoding fi -################################### if [ -n "$do_adpcm_ms" ] ; then -# adpcm ms do_audio_encoding adpcm_ms.wav "-ar 44100" "-acodec adpcm_ms" do_audio_decoding fi -################################### if [ -n "$do_adpcm_yam" ] ; then -# adpcm yamaha do_audio_encoding adpcm_yam.wav "-ar 44100" "-acodec adpcm_yamaha" do_audio_decoding fi -################################### +if [ -n "$do_adpcm_swf" ] ; then +do_audio_encoding adpcm_swf.flv "-ar 44100" "-acodec adpcm_swf" +do_audio_decoding +fi + if [ -n "$do_flac" ] ; then -# flac do_audio_encoding flac.flac "-ar 44100" "-acodec flac -compression_level 2" do_audio_decoding fi -################################### if [ -n "$do_wma" ] ; then # wmav1 do_audio_encoding wmav1.asf "-ar 44100" "-acodec wmav1" @@ -574,131 +432,171 @@ do_ffmpeg_nomd5 $pcm_dst -y -i $file -f wav $pcm_dst $tiny_psnr $pcm_dst $pcm_ref 2 8192 >> $logfile fi -################################### #if [ -n "$do_vorbis" ] ; then # vorbis -#disabled because its broken +#disabled because it is broken #do_audio_encoding vorbis.asf "-ar 44100" "-acodec vorbis" #do_audio_decoding #fi -################################### # libavformat testing -################################### - -if [ -n "$do_libavtest" ] ; then -# avi +if [ -n "$do_avi" ] ; then do_libav avi +fi -# asf +if [ -n "$do_asf" ] ; then do_libav asf "-acodec mp2" "-r 25" +fi -# rm +if [ -n "$do_rm" ] ; then file=${outfile}libav.rm do_ffmpeg $file -t 1 -y -qscale 10 -f pgmyuv -i $raw_src -f s16le -i $pcm_src $file # broken #do_ffmpeg_crc $file -i $file +fi -# mpegps +if [ -n "$do_mpg" ] ; then do_libav mpg +fi -# mpegts +if [ -n "$do_ts" ] ; then do_libav ts +fi -# swf +if [ -n "$do_swf" ] ; then do_libav swf -an +fi -# ffm +if [ -n "$do_ffm" ] ; then do_libav ffm +fi -# flv +if [ -n "$do_flv_fmt" ] ; then do_libav flv -an +fi -# mov +if [ -n "$do_mov" ] ; then do_libav mov "-acodec pcm_alaw" +fi -# nut -#do_libav nut "-acodec mp2" - -# dv +if [ -n "$do_dv_fmt" ] ; then do_libav dv "-ar 48000 -r 25 -s pal -ac 2" +fi -# gxf +if [ -n "$do_gxf" ] ; then do_libav gxf "-ar 48000 -r 25 -s pal -ac 1" +fi + +if [ -n "$do_nut" ] ; then +do_libav nut "-acodec mp2" +fi + +if [ -n "$do_mkv" ] ; then +do_libav mkv +fi + -#################### # streamed images # mjpeg #file=${outfile}libav.mjpeg #do_ffmpeg $file -t 1 -y -qscale 10 -f pgmyuv -i $raw_src $file #do_ffmpeg_crc $file -i $file -# pbmpipe +if [ -n "$do_pbmpipe" ] ; then do_streamed_images pbm +fi -# pgmpipe +if [ -n "$do_pgmpipe" ] ; then do_streamed_images pgm +fi -# ppmpipe +if [ -n "$do_ppmpipe" ] ; then do_streamed_images ppm +fi -# gif +if [ -n "$do_gif" ] ; then file=${outfile}libav.gif do_ffmpeg $file -t 1 -y -qscale 10 -f pgmyuv -i $raw_src -pix_fmt rgb24 $file #do_ffmpeg_crc $file -i $file +fi -# yuv4mpeg +if [ -n "$do_yuv4mpeg" ] ; then file=${outfile}libav.y4m do_ffmpeg $file -t 1 -y -qscale 10 -f pgmyuv -i $raw_src $file #do_ffmpeg_crc $file -i $file +fi -#################### # image formats -# pgm + +if [ -n "$do_pgm" ] ; then do_image_formats pgm +fi -# ppm +if [ -n "$do_ppm" ] ; then do_image_formats ppm +fi -# bmp +if [ -n "$do_bmp" ] ; then do_image_formats bmp +fi -# tga +if [ -n "$do_tga" ] ; then do_image_formats tga +fi + +if [ -n "$do_tiff" ] ; then +do_image_formats tiff "-pix_fmt rgb24" +fi + +if [ -n "$do_sgi" ] ; then +do_image_formats sgi +fi -# jpeg +if [ -n "$do_jpg" ] ; then do_image_formats jpg "-flags +bitexact -dct fastint -idct simple -pix_fmt yuvj420p" "-f image2" +fi -#################### # audio only -# wav +if [ -n "$do_wav" ] ; then do_audio_only wav +fi -# alaw +if [ -n "$do_alaw" ] ; then do_audio_only al +fi -# mulaw +if [ -n "$do_mulaw" ] ; then do_audio_only ul +fi -# au +if [ -n "$do_au" ] ; then do_audio_only au +fi -# mmf +if [ -n "$do_mmf" ] ; then do_audio_only mmf +fi -# aiff +if [ -n "$do_aiff" ] ; then do_audio_only aif +fi -# voc +if [ -n "$do_voc" ] ; then do_audio_only voc +fi + +if [ -n "$do_ogg" ] ; then +do_audio_only ogg +fi -#################### # pix_fmt conversions + +if [ -n "$do_pixfmt" ] ; then conversions="yuv420p yuv422p yuv444p yuyv422 yuv410p yuv411p yuvj420p \ yuvj422p yuvj444p rgb24 bgr24 rgb32 rgb565 rgb555 gray monow \ - monob pal8" + monob pal8 yuv440p yuvj440p" for pix_fmt in $conversions ; do file=${outfile}libav-${pix_fmt}.yuv do_ffmpeg_nocheck $file -r 1 -t 1 -y -f pgmyuv -i $raw_src \ @@ -706,17 +604,6 @@ for pix_fmt in $conversions ; do do_ffmpeg $file -f rawvideo -s 352x288 -pix_fmt $pix_fmt -i $raw_dst \ -f rawvideo -s 352x288 -pix_fmt yuv444p $file done - -fi # [ -n "$do_libavtest" ] - - - -if $diff_cmd "$logfile" "$reffile" ; then - echo - echo Regression test succeeded. - exit 0 -else - echo - echo Regression test: Error. - exit 1 fi + +rm -f "$bench" "$bench2" diff --git a/contrib/ffmpeg/tests/rotozoom.regression.ref b/contrib/ffmpeg/tests/rotozoom.regression.ref index 94c4e1b72..68cc3e720 100644 --- a/contrib/ffmpeg/tests/rotozoom.regression.ref +++ b/contrib/ffmpeg/tests/rotozoom.regression.ref @@ -1,198 +1,205 @@ -ffmpeg regression test -73ca6f1deab02d1d67a0e8495c026a9e *./data/a-mpeg1.mpg -192783 ./data/a-mpeg1.mpg -56147e94b12f08df7213e610e177823d *./data/out.yuv +73ca6f1deab02d1d67a0e8495c026a9e *./tests/data/a-mpeg1.mpg +192783 ./tests/data/a-mpeg1.mpg +56147e94b12f08df7213e610e177823d *./tests/data/mpeg.rotozoom.out.yuv stddev: 4.95 PSNR:34.21 bytes:7602176 -2d55ce623a7be4e8136f80266e487678 *./data/a-mpeg2.mpg -198667 ./data/a-mpeg2.mpg -b7cae8a1f751b821cddcbe4d5dbc518c *./data/out.yuv +2d55ce623a7be4e8136f80266e487678 *./tests/data/a-mpeg2.mpg +198667 ./tests/data/a-mpeg2.mpg +b7cae8a1f751b821cddcbe4d5dbc518c *./tests/data/mpeg2.rotozoom.out.yuv stddev: 4.96 PSNR:34.19 bytes:7602176 -4dd6e884eeccfb5c0d9b5542349e3d62 *./data/a-mpeg2ivlc-qprd.mpg -249692 ./data/a-mpeg2ivlc-qprd.mpg -99214c2a75ece2a0bf4f5afebc0f8ed7 *./data/out.yuv -stddev: 4.41 PSNR:35.22 bytes:7602176 -f979bcca866e6e4cad5dc6cb06e56cfb *./data/a-mpeg2.mpg -198041 ./data/a-mpeg2.mpg -f6d9bf24ff8676a7f6076c05cd2c81a3 *./data/out.yuv +788b83a7c8c6c1e648c05076dd40dc30 *./tests/data/a-mpeg2ivlc-qprd.mpg +247161 ./tests/data/a-mpeg2ivlc-qprd.mpg +cc6f08c1a24b58c19de325e79cfa40a3 *./tests/data/mpeg2.rotozoom.out.yuv +stddev: 4.25 PSNR:35.55 bytes:7602176 +f979bcca866e6e4cad5dc6cb06e56cfb *./tests/data/a-mpeg2.mpg +198041 ./tests/data/a-mpeg2.mpg +f6d9bf24ff8676a7f6076c05cd2c81a3 *./tests/data/mpeg2.rotozoom.out.yuv stddev: 4.97 PSNR:34.18 bytes:7602176 -f90197a8b6e62ae25f82625337f27240 *./data/a-mpeg2i.mpg -204579 ./data/a-mpeg2i.mpg -ea5057b60146c06d40449cdfc686bf13 *./data/out.yuv +f90197a8b6e62ae25f82625337f27240 *./tests/data/a-mpeg2i.mpg +204579 ./tests/data/a-mpeg2i.mpg +ea5057b60146c06d40449cdfc686bf13 *./tests/data/mpeg2.rotozoom.out.yuv stddev: 4.98 PSNR:34.17 bytes:7602176 -c346717be44450e41d9d6e07f59d1490 *./data/a-mpeg2thread.mpg -182959 ./data/a-mpeg2thread.mpg -02b85a7f67ced2d146a5c4e8000712b6 *./data/out.yuv +c346717be44450e41d9d6e07f59d1490 *./tests/data/a-mpeg2thread.mpg +182959 ./tests/data/a-mpeg2thread.mpg +02b85a7f67ced2d146a5c4e8000712b6 *./tests/data/mpeg2thread.rotozoom.out.yuv stddev: 4.75 PSNR:34.57 bytes:7602176 -ff30b3df75626398873ac4f30093a5ae *./data/a-mpeg2threadivlc.mpg -182105 ./data/a-mpeg2threadivlc.mpg -02b85a7f67ced2d146a5c4e8000712b6 *./data/out.yuv +ff30b3df75626398873ac4f30093a5ae *./tests/data/a-mpeg2threadivlc.mpg +182105 ./tests/data/a-mpeg2threadivlc.mpg +02b85a7f67ced2d146a5c4e8000712b6 *./tests/data/mpeg2thread.rotozoom.out.yuv stddev: 4.75 PSNR:34.57 bytes:7602176 -3942f86a6aa6fe5aea586fedf210e33e *./data/a-mpeg2reuse.mpg -394265 ./data/a-mpeg2reuse.mpg -afbc483eaa769925259e6094cfda2c72 *./data/out.yuv +3942f86a6aa6fe5aea586fedf210e33e *./tests/data/a-mpeg2reuse.mpg +394265 ./tests/data/a-mpeg2reuse.mpg +afbc483eaa769925259e6094cfda2c72 *./tests/data/mpeg2thread.rotozoom.out.yuv stddev: 4.76 PSNR:34.56 bytes:7602176 -c09815e40a9d260628e1ebad8b2b3774 *./data/a-msmpeg4v2.avi -129918 ./data/a-msmpeg4v2.avi -8920194f8bf8f9cdd6c65b3df9e1a292 *./data/out.yuv +c09815e40a9d260628e1ebad8b2b3774 *./tests/data/a-msmpeg4v2.avi +129918 ./tests/data/a-msmpeg4v2.avi +8920194f8bf8f9cdd6c65b3df9e1a292 *./tests/data/msmpeg4v2.rotozoom.out.yuv stddev: 5.33 PSNR:33.58 bytes:7602176 -3069f95f2ffca1f20c8ea36e2625fabc *./data/a-msmpeg4.avi -127680 ./data/a-msmpeg4.avi -0e1c6e25c71c6a8fa8e506e3d97ca4c9 *./data/out.yuv +3069f95f2ffca1f20c8ea36e2625fabc *./tests/data/a-msmpeg4.avi +127680 ./tests/data/a-msmpeg4.avi +0e1c6e25c71c6a8fa8e506e3d97ca4c9 *./tests/data/msmpeg4.rotozoom.out.yuv stddev: 5.33 PSNR:33.58 bytes:7602176 -6896c9bdf765953d272c25e34795b934 *./data/a-wmv1.avi -129548 ./data/a-wmv1.avi -81eee429b665254d19a06607463c0b5e *./data/out.yuv +1011e26e7d351c96d7bbfe106d831b69 *./tests/data/a-wmv1.avi +129530 ./tests/data/a-wmv1.avi +81eee429b665254d19a06607463c0b5e *./tests/data/wmv1.rotozoom.out.yuv stddev: 5.33 PSNR:33.59 bytes:7602176 -34b40c67036c8e09740f7acfe3d43df6 *./data/a-wmv2.avi -129864 ./data/a-wmv2.avi -81eee429b665254d19a06607463c0b5e *./data/out.yuv +1f6598e9776ed00aebdc44cc8d48cb7c *./tests/data/a-wmv2.avi +129860 ./tests/data/a-wmv2.avi +81eee429b665254d19a06607463c0b5e *./tests/data/wmv2.rotozoom.out.yuv stddev: 5.33 PSNR:33.59 bytes:7602176 -dfd005d4c9030a0dc889c828a6408b9c *./data/a-h261.avi -191086 ./data/a-h261.avi -db7ceff174823b98834faa2320ca89ac *./data/out.yuv +dfd005d4c9030a0dc889c828a6408b9c *./tests/data/a-h261.avi +191086 ./tests/data/a-h261.avi +db7ceff174823b98834faa2320ca89ac *./tests/data/h261.rotozoom.out.yuv stddev: 6.38 PSNR:32.02 bytes:7602176 -9a368687ab34c48079f11a202839a6bc *./data/a-h263.avi -160106 ./data/a-h263.avi -61213b91b359697ebcefb9e0a53ac54a *./data/out.yuv +9a368687ab34c48079f11a202839a6bc *./tests/data/a-h263.avi +160106 ./tests/data/a-h263.avi +61213b91b359697ebcefb9e0a53ac54a *./tests/data/h263.rotozoom.out.yuv stddev: 5.43 PSNR:33.41 bytes:7602176 -c7644d40e9f40bbd98e5a978f9f94bb4 *./data/a-h263p.avi -868018 ./data/a-h263p.avi -4b0ee791f280029dc03c528f76f195d4 *./data/out.yuv +c7644d40e9f40bbd98e5a978f9f94bb4 *./tests/data/a-h263p.avi +868018 ./tests/data/a-h263p.avi +4b0ee791f280029dc03c528f76f195d4 *./tests/data/h263p.rotozoom.out.yuv stddev: 1.91 PSNR:42.49 bytes:7602176 -f15f07988bfdb2851f88ebe3036b72d3 *./data/a-odivx.mp4 -119797 ./data/a-odivx.mp4 -90a3577850239083a9042bef33c50e85 *./data/out.yuv +15a7e083ad743c0bcfe68e6b18f11098 *./tests/data/a-odivx.mp4 +119789 ./tests/data/a-odivx.mp4 +90a3577850239083a9042bef33c50e85 *./tests/data/mpeg4.rotozoom.out.yuv stddev: 5.34 PSNR:33.56 bytes:7602176 -a1323da0c8b437cd6961f8c90451880b *./data/a-huffyuv.avi -6455232 ./data/a-huffyuv.avi -dde5895817ad9d219f79a52d0bdfb001 *./data/out.yuv +a1323da0c8b437cd6961f8c90451880b *./tests/data/a-huffyuv.avi +6455232 ./tests/data/a-huffyuv.avi +dde5895817ad9d219f79a52d0bdfb001 *./tests/data/huffyuv.rotozoom.out.yuv stddev: 0.00 PSNR:99.99 bytes:7602176 -968ca132d8cf46f84e657abcf8473b7c *./data/a-mpeg4-rc.avi -227934 ./data/a-mpeg4-rc.avi -895773fe8250c806a0d1592a6dd12401 *./data/out.yuv -stddev: 4.24 PSNR:35.56 bytes:7602176 -9001cf571eb7f26fa5592bdec6538583 *./data/a-mpeg4-adv.avi -173590 ./data/a-mpeg4-adv.avi -699edf05648fdc42196b7bebef9be269 *./data/out.yuv -stddev: 4.84 PSNR:34.41 bytes:7602176 -1e12bb209dae0ab4b64265b0a4262257 *./data/a-mpeg4-qprd.avi -234048 ./data/a-mpeg4-qprd.avi -1ec355ffb30d2adf302a550cf5812636 *./data/out.yuv -stddev: 4.23 PSNR:35.58 bytes:7602176 -d581d6f4a331325905b8ffb05cd3bfd3 *./data/a-mpeg4-adap.avi -204284 ./data/a-mpeg4-adap.avi -c2c7f1c7844ab92d34247ccb70198c61 *./data/out.yuv -stddev: 4.04 PSNR:35.99 bytes:7602176 -a5150067914ee1dee50f8fc8dcaee841 *./data/a-mpeg4-Q.avi -165802 ./data/a-mpeg4-Q.avi -4dcc71ad79bee90777cf5299044be362 *./data/out.yuv +b517389e425d3065ab26ef4cc0658237 *./tests/data/a-mpeg4-rc.avi +227762 ./tests/data/a-mpeg4-rc.avi +cc947bbac9187bf08d3e2d425556aaa5 *./tests/data/rc.rotozoom.out.yuv +stddev: 4.26 PSNR:35.53 bytes:7602176 +dee7be19486a76d96c88d18eefba8f86 *./tests/data/a-mpeg4-adv.avi +141546 ./tests/data/a-mpeg4-adv.avi +3f3a21e9db85a9c0f7022f557a5374c1 *./tests/data/mpeg4adv.rotozoom.out.yuv +stddev: 4.94 PSNR:34.24 bytes:7602176 +1b1a692e11969deb1fe3c7144f8cb103 *./tests/data/a-mpeg4-qprd.avi +233604 ./tests/data/a-mpeg4-qprd.avi +95860ad446ca0665d873ae6781736095 *./tests/data/mpeg4adv.rotozoom.out.yuv +stddev: 4.01 PSNR:36.05 bytes:7602176 +78c93c522b23bcc7f84f8b592b0191b6 *./tests/data/a-mpeg4-adap.avi +200120 ./tests/data/a-mpeg4-adap.avi +fd7db0b14fa76d0734bbfa36dbb513f8 *./tests/data/mpeg4adv.rotozoom.out.yuv +stddev: 3.78 PSNR:36.57 bytes:7602176 +a5150067914ee1dee50f8fc8dcaee841 *./tests/data/a-mpeg4-Q.avi +165802 ./tests/data/a-mpeg4-Q.avi +4dcc71ad79bee90777cf5299044be362 *./tests/data/mpeg4adv.rotozoom.out.yuv stddev: 4.00 PSNR:36.08 bytes:7602176 -8cd8940d7451925784536fe9b2f2a5e3 *./data/a-mpeg4-thread.avi -254260 ./data/a-mpeg4-thread.avi -d160a4224ea1af66c85178912f8d3a7c *./data/out.yuv -stddev: 4.03 PSNR:36.01 bytes:7602176 -5b5b88ce610114e346a5df4f46995bb9 *./data/a-mpeg4-PSP.mp4 -325006 ./data/a-mpeg4-PSP.mp4 -90e65096aa9ebafa3fe3f44a5a47cdc4 *./data/a-error-mpeg4-adv.avi -176588 ./data/a-error-mpeg4-adv.avi -113defd3f8daf878e0b3fc03fafb4c09 *./data/out.yuv +8496ffe953dc3398c657d99e962e4d77 *./tests/data/a-mpeg4-thread.avi +250162 ./tests/data/a-mpeg4-thread.avi +58165c879707aedeab460bab86dae4ef *./tests/data/mpeg4thread.rotozoom.out.yuv +stddev: 3.73 PSNR:36.67 bytes:7602176 +6cd200bf844fd1c0e48c23d542a860e8 *./tests/data/a-mpeg4-PSP.mp4 +324998 ./tests/data/a-mpeg4-PSP.mp4 +90e65096aa9ebafa3fe3f44a5a47cdc4 *./tests/data/a-error-mpeg4-adv.avi +176588 ./tests/data/a-error-mpeg4-adv.avi +113defd3f8daf878e0b3fc03fafb4c09 *./tests/data/error.rotozoom.out.yuv stddev: 9.02 PSNR:29.01 bytes:7602176 -c41187c99588fb7229ad330b2f80d28b *./data/a-mpeg4-nr.avi -155044 ./data/a-mpeg4-nr.avi -f7fc191308679f709405e62271f5c65f *./data/out.yuv +c41187c99588fb7229ad330b2f80d28b *./tests/data/a-mpeg4-nr.avi +155044 ./tests/data/a-mpeg4-nr.avi +f7fc191308679f709405e62271f5c65f *./tests/data/mpeg4nr.rotozoom.out.yuv stddev: 4.73 PSNR:34.62 bytes:7602176 -977f3caf286e8f36c6ab4c7464632f26 *./data/a-mpeg1b.mpg -229806 ./data/a-mpeg1b.mpg -f41c60846bfb8cb6dcf6071c846c82b4 *./data/out.yuv +977f3caf286e8f36c6ab4c7464632f26 *./tests/data/a-mpeg1b.mpg +229806 ./tests/data/a-mpeg1b.mpg +f41c60846bfb8cb6dcf6071c846c82b4 *./tests/data/mpeg1b.rotozoom.out.yuv stddev: 4.13 PSNR:35.79 bytes:7602176 -b179402bba391073b5f5f9324a834061 *./data/a-mjpeg.avi -703564 ./data/a-mjpeg.avi -b1aa72cfb6f9cc3f525b27abc86a8f51 *./data/out.yuv +b179402bba391073b5f5f9324a834061 *./tests/data/a-mjpeg.avi +703564 ./tests/data/a-mjpeg.avi +b1aa72cfb6f9cc3f525b27abc86a8f51 *./tests/data/mjpeg.rotozoom.out.yuv stddev: 4.38 PSNR:35.28 bytes:7602176 -bc0d8c868c1a05db0ff03f41768f6c5e *./data/a-ljpeg.avi -4766558 ./data/a-ljpeg.avi -dde5895817ad9d219f79a52d0bdfb001 *./data/out.yuv +bc0d8c868c1a05db0ff03f41768f6c5e *./tests/data/a-ljpeg.avi +4766558 ./tests/data/a-ljpeg.avi +dde5895817ad9d219f79a52d0bdfb001 *./tests/data/ljpeg.rotozoom.out.yuv stddev: 0.00 PSNR:99.99 bytes:7602176 -f67cd488dfd06c03ad1d6d94d81b80c8 *./data/a-jpegls.avi -8334488 ./data/a-jpegls.avi -a63d4e3ea1f0b0c0d44821da9e09b8f4 *./data/out.yuv +f67cd488dfd06c03ad1d6d94d81b80c8 *./tests/data/a-jpegls.avi +8334488 ./tests/data/a-jpegls.avi +a63d4e3ea1f0b0c0d44821da9e09b8f4 *./tests/data/jpegls.rotozoom.out.yuv stddev: 0.67 PSNR:51.57 bytes:7602176 -989a42671603dc1a7e6b156dccf0e820 *./data/a-rv10.rm -154330 ./data/a-rv10.rm -61213b91b359697ebcefb9e0a53ac54a *./data/out.yuv +989a42671603dc1a7e6b156dccf0e820 *./tests/data/a-rv10.rm +154330 ./tests/data/a-rv10.rm +61213b91b359697ebcefb9e0a53ac54a *./tests/data/rv10.rotozoom.out.yuv stddev: 5.43 PSNR:33.41 bytes:7602176 -1b1cbff8e78602de498b4314cb991e72 *./data/a-rv20.rm -132754 ./data/a-rv20.rm -c66afdcc0daac2f1b4167b9811968877 *./data/out.yuv +1b1cbff8e78602de498b4314cb991e72 *./tests/data/a-rv20.rm +132754 ./tests/data/a-rv20.rm +c66afdcc0daac2f1b4167b9811968877 *./tests/data/rv20.rotozoom.out.yuv stddev: 5.42 PSNR:33.44 bytes:7602176 -4eb34d2de25f67a2706456e999338fe9 *./data/a-asv1.avi -832512 ./data/a-asv1.avi -c96ff7fd17c52f99ddb7922a4cb9168f *./data/out.yuv +4eb34d2de25f67a2706456e999338fe9 *./tests/data/a-asv1.avi +832512 ./tests/data/a-asv1.avi +c96ff7fd17c52f99ddb7922a4cb9168f *./tests/data/asv1.rotozoom.out.yuv stddev: 10.47 PSNR:27.72 bytes:7602176 -9649a4b68fb1107bad13e8a7574cc72d *./data/a-asv2.avi -789072 ./data/a-asv2.avi -74a78015b64b2cf8cb9da2e44f508a69 *./data/out.yuv +9649a4b68fb1107bad13e8a7574cc72d *./tests/data/a-asv2.avi +789072 ./tests/data/a-asv2.avi +74a78015b64b2cf8cb9da2e44f508a69 *./tests/data/asv2.rotozoom.out.yuv stddev: 10.28 PSNR:27.88 bytes:7602176 -7163b470e93feb36b3f01e82168a3d31 *./data/a-flv.flv -131360 ./data/a-flv.flv -8999c8264fb0941561f64c4a736e9d88 *./data/out.yuv +7163b470e93feb36b3f01e82168a3d31 *./tests/data/a-flv.flv +131360 ./tests/data/a-flv.flv +8999c8264fb0941561f64c4a736e9d88 *./tests/data/flv.rotozoom.out.yuv stddev: 5.33 PSNR:33.58 bytes:7602176 -d72b0960e162d4998b9acbabb07e99ab *./data/a-ffv1.avi -3525804 ./data/a-ffv1.avi -dde5895817ad9d219f79a52d0bdfb001 *./data/out.yuv +d72b0960e162d4998b9acbabb07e99ab *./tests/data/a-ffv1.avi +3525804 ./tests/data/a-ffv1.avi +dde5895817ad9d219f79a52d0bdfb001 *./tests/data/ffv1.rotozoom.out.yuv stddev: 0.00 PSNR:99.99 bytes:7602176 -40a6e938ac2bd92ee12cd57925e86454 *./data/a-snow.avi -68758 ./data/a-snow.avi -1e356854142898c7c4aab4bfedadf235 *./data/out.yuv -stddev: 10.86 PSNR:27.40 bytes:7602176 -3d0da6aeec9b80c6ee0ff4b747bdd0f0 *./data/a-snow53.avi -2721980 ./data/a-snow53.avi -dde5895817ad9d219f79a52d0bdfb001 *./data/out.yuv +0b404d5372a5c6c93f6087614020b096 *./tests/data/a-snow.avi +69068 ./tests/data/a-snow.avi +63ea1d2fe1693be57d3ab7d351af7c55 *./tests/data/snow.rotozoom.out.yuv +stddev: 10.87 PSNR:27.39 bytes:7602176 +a8fccf278bbb17d37a756ecf11672b09 *./tests/data/a-snow53.avi +2721758 ./tests/data/a-snow53.avi +dde5895817ad9d219f79a52d0bdfb001 *./tests/data/snowll.rotozoom.out.yuv stddev: 0.00 PSNR:99.99 bytes:7602176 -54cdeaee32d1007666a1e487e739daf6 *./data/a-dv.dv -7200000 ./data/a-dv.dv -75bf724e37f667f36af50e2051846574 *./data/out.yuv +54cdeaee32d1007666a1e487e739daf6 *./tests/data/a-dv.dv +7200000 ./tests/data/a-dv.dv +75bf724e37f667f36af50e2051846574 *./tests/data/dv.rotozoom.out.yuv stddev: 3.11 PSNR:38.24 bytes:7602176 -ac6741e4c79e9ed18f179c4124ede29c *./data/a-dv.dv -14400000 ./data/a-dv.dv -ad9907f4ef608f025f5fc38b4b067b37 *./data/out.yuv +ac6741e4c79e9ed18f179c4124ede29c *./tests/data/a-dv50.dv +14400000 ./tests/data/a-dv50.dv +ad9907f4ef608f025f5fc38b4b067b37 *./tests/data/dv50.rotozoom.out.yuv stddev: 3.11 PSNR:38.25 bytes:7602176 -7ba9292d663819a9a1d1cdecc6f1b079 *./data/a-svq1.mov -768407 ./data/a-svq1.mov -6bc10518bc387c3bdf117997713ee69a *./data/out.yuv +c15016c75394199660ae405c5d396e28 *./tests/data/a-svq1.mov +768399 ./tests/data/a-svq1.mov +6bc10518bc387c3bdf117997713ee69a *./tests/data/svq1.rotozoom.out.yuv stddev: 3.44 PSNR:37.39 bytes:7602176 -21f8ff9f1daacd9133683bb4ea0f50a4 *./data/a-mp2.mp2 -95712 ./data/a-mp2.mp2 -83f8df5d5f84480566af548bb037fceb *./data/out.wav +e0b42dde0cc71c294664da94721395ac *./tests/data/a-flashsv.flv +12368839 ./tests/data/a-flashsv.flv +a63d4e3ea1f0b0c0d44821da9e09b8f4 *./tests/data/flashsv.rotozoom.out.yuv +stddev: 0.67 PSNR:51.57 bytes:7602176 +21f8ff9f1daacd9133683bb4ea0f50a4 *./tests/data/a-mp2.mp2 +95712 ./tests/data/a-mp2.mp2 +83f8df5d5f84480566af548bb037fceb *./tests/data/mp2.rotozoom.out.wav stddev:9330.70 PSNR:16.92 bytes:1054720 stddev:4396.13 PSNR:23.46 bytes:1052672 -aefe11ab5067621a1c674859d6413891 *./data/a-ac3.rm -98203 ./data/a-ac3.rm -39878597b1d65cce473639a7d8c93b02 *./data/a-g726.wav -24279 ./data/a-g726.wav -888f2f016e608d044a1bacbca5497ed2 *./data/out.wav +aefe11ab5067621a1c674859d6413891 *./tests/data/a-ac3.rm +98203 ./tests/data/a-ac3.rm +39878597b1d65cce473639a7d8c93b02 *./tests/data/a-g726.wav +24279 ./tests/data/a-g726.wav +888f2f016e608d044a1bacbca5497ed2 *./tests/data/g726.rotozoom.out.wav stddev:8368.02 PSNR:17.87 bytes:96256 -de3f0e1f50b19bd8572fdd3dee2e72c4 *./data/a-adpcm_ima.wav -266300 ./data/a-adpcm_ima.wav -60178d48204f5662d91776e36eddc82e *./data/out.wav -stddev:11441.89 PSNR:15.15 bytes:1054720 -628d4789cf9ee16a756ac54b7fd8650d *./data/a-adpcm_ms.wav -267320 ./data/a-adpcm_ms.wav -91a84bb4f319a3a0bf0c0441b3d3a529 *./data/out.wav +3b969c43e45582f713e3c35faee9e0cc *./tests/data/a-adpcm_ima.wav +266300 ./tests/data/a-adpcm_ima.wav +947196b1739a9d6fe0c29424cf61cd8c *./tests/data/adpcm_ima_wav.rotozoom.out.wav +stddev:904.20 PSNR:37.19 bytes:1056768 +628d4789cf9ee16a756ac54b7fd8650d *./tests/data/a-adpcm_ms.wav +267320 ./tests/data/a-adpcm_ms.wav +91a84bb4f319a3a0bf0c0441b3d3a529 *./tests/data/adpcm_ms.rotozoom.out.wav stddev:1050.18 PSNR:35.89 bytes:1054720 -ab11d9151644cbff27827b7e89f37aa9 *./data/a-adpcm_yam.wav -264248 ./data/a-adpcm_yam.wav -e92cec8c07913ffb91ad2b11f79cdc00 *./data/out.wav +ab11d9151644cbff27827b7e89f37aa9 *./tests/data/a-adpcm_yam.wav +264248 ./tests/data/a-adpcm_yam.wav +e92cec8c07913ffb91ad2b11f79cdc00 *./tests/data/adpcm_yam.rotozoom.out.wav stddev:18312.68 PSNR:11.06 bytes:1056768 -c3382f03ce2efb5d475240d288a33898 *./data/a-flac.flac -353368 ./data/a-flac.flac -c4228df189aad9567a037727d0e763e4 *./data/out.wav +de1122d20d56c44cf49f028e25a67788 *./tests/data/a-adpcm_swf.flv +267073 ./tests/data/a-adpcm_swf.flv +e48b800e2d9be6afcd430d4f08a34eb6 *./tests/data/adpcm_swf.rotozoom.out.wav +stddev:934.30 PSNR:36.91 bytes:1056768 +c3382f03ce2efb5d475240d288a33898 *./tests/data/a-flac.flac +353368 ./tests/data/a-flac.flac +c4228df189aad9567a037727d0e763e4 *./tests/data/flac.rotozoom.out.wav stddev: 33.31 PSNR:65.87 bytes:1040384 -0c406c4e4586ca27064e28637b662631 *./data/a-wmav1.asf -106004 ./data/a-wmav1.asf +a1e56bb034c2773438ba1c830c4cea07 *./tests/data/a-wmav1.asf +106004 ./tests/data/a-wmav1.asf stddev:12251.50 PSNR:14.56 bytes:1056768 stddev:2106.00 PSNR:29.85 bytes:1048576 -82442aaa5fdbd327769e4c4ad369147e *./data/a-wmav2.asf -106044 ./data/a-wmav2.asf +5e25c447c80fa937f74ed8752b0e26fb *./tests/data/a-wmav2.asf +106044 ./tests/data/a-wmav2.asf stddev:12255.92 PSNR:14.55 bytes:1056768 stddev:2099.31 PSNR:29.88 bytes:1048576 diff --git a/contrib/ffmpeg/tests/seek.regression.ref b/contrib/ffmpeg/tests/seek.regression.ref new file mode 100644 index 000000000..715a1a008 --- /dev/null +++ b/contrib/ffmpeg/tests/seek.regression.ref @@ -0,0 +1,3685 @@ +---------------- +tests/data/a-ac3.rm +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:271 size:556 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:37355.520000 pts:37355.520000 pos:49793 size:558 flags:1 +ret:-1 st:-1 ts:1.894167 flags:1 +ret:-1 st: 0 ts:0.788000 flags:0 +ret: 0 st: 0 ts:-0.317000 flags:1 +ret: 0 st: 0 dts:37355.520000 pts:37355.520000 pos:49793 size:558 flags:1 +ret: 0 st:-1 ts:2.576668 flags:0 +ret: 0 st: 0 dts:37224.448000 pts:37224.448000 pos:68581 size:556 flags:1 +ret:-1 st:-1 ts:1.470835 flags:1 +ret:-1 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 ts:-0.741000 flags:1 +ret: 0 st: 0 dts:37355.520000 pts:37355.520000 pos:49793 size:558 flags:1 +ret: 0 st:-1 ts:2.153336 flags:0 +ret: 0 st: 0 dts:37224.448000 pts:37224.448000 pos:68581 size:556 flags:1 +ret:-1 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 ts:-0.058000 flags:0 +ret: 0 st: 0 dts:37355.520000 pts:37355.520000 pos:49793 size:558 flags:1 +ret: 0 st: 0 ts:2.836000 flags:1 +ret: 0 st: 0 dts:37224.448000 pts:37224.448000 pos:42963 size:556 flags:1 +ret:-1 st:-1 ts:1.730004 flags:0 +ret:-1 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 ts:-0.482000 flags:0 +ret: 0 st: 0 dts:37355.520000 pts:37355.520000 pos:49793 size:558 flags:1 +ret:-1 st: 0 ts:2.413000 flags:1 +ret:-1 st:-1 ts:1.306672 flags:0 +ret:-1 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 ts:-0.905000 flags:0 +ret: 0 st: 0 dts:37355.520000 pts:37355.520000 pos:49793 size:558 flags:1 +ret: 0 st: 0 ts:1.989000 flags:1 +ret: 0 st: 0 dts:37355.520000 pts:37355.520000 pos:34423 size:558 flags:1 +ret:-1 st:-1 ts:0.883340 flags:0 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret: 0 st: 0 dts:37355.520000 pts:37355.520000 pos:49793 size:558 flags:1 +ret:-1 st: 0 ts:2.672000 flags:0 +ret:-1 st: 0 ts:1.566000 flags:1 +ret:-1 st:-1 ts:0.460008 flags:0 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:37355.520000 pts:37355.520000 pos:49793 size:558 flags:1 +---------------- +tests/data/a-adpcm_ima.wav +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:60 size:4096 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:-0.960000 pts:-0.960000 pos:65536 size:4096 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.856009 pts:1.856009 pos:29756 size:4096 flags:1 +ret: 0 st: 0 ts:0.788345 flags:0 +ret: 0 st: 0 dts:0.831995 pts:0.831995 pos:13372 size:4096 flags:1 +ret: 0 st: 0 ts:-0.317506 flags:1 +ret: 0 st: 0 dts:-0.320000 pts:-0.320000 pos:46140 size:4096 flags:1 +ret: 0 st:-1 ts:2.576668 flags:0 +ret: 0 st: 0 dts:2.623991 pts:2.623991 pos:42044 size:4096 flags:1 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.408005 pts:1.408005 pos:22588 size:4096 flags:1 +ret: 0 st: 0 ts:0.365011 flags:0 +ret: 0 st: 0 dts:0.383991 pts:0.383991 pos:6204 size:4096 flags:1 +ret: 0 st: 0 ts:-0.740839 flags:1 +ret: 0 st: 0 dts:-0.768005 pts:-0.768005 pos:38972 size:4096 flags:1 +ret: 0 st:-1 ts:2.153336 flags:0 +ret: 0 st: 0 dts:2.176009 pts:2.176009 pos:34876 size:4096 flags:1 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.023991 pts:1.023991 pos:16444 size:4096 flags:1 +ret: 0 st: 0 ts:-0.058322 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:60 size:4096 flags:1 +ret: 0 st: 0 ts:2.835828 flags:1 +ret: 0 st: 0 dts:2.816009 pts:2.816009 pos:45116 size:4096 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.791995 pts:1.791995 pos:28732 size:4096 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.576009 pts:0.576009 pos:9276 size:4096 flags:1 +ret: 0 st: 0 ts:-0.481655 flags:0 +ret: 0 st: 0 dts:-0.448005 pts:-0.448005 pos:42044 size:4096 flags:1 +ret: 0 st: 0 ts:2.412494 flags:1 +ret: 0 st: 0 dts:2.368005 pts:2.368005 pos:37948 size:4096 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.343991 pts:1.343991 pos:21564 size:4096 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.191995 pts:0.191995 pos:3132 size:4096 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:-0.896009 pts:-0.896009 pos:35900 size:4096 flags:1 +ret: 0 st: 0 ts:1.989184 flags:1 +ret: 0 st: 0 dts:1.983991 pts:1.983991 pos:31804 size:4096 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.896009 pts:0.896009 pos:14396 size:4096 flags:1 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret: 0 st: 0 dts:-0.256009 pts:-0.256009 pos:47164 size:4096 flags:1 +ret: 0 st: 0 ts:2.671678 flags:0 +ret: 0 st: 0 dts:2.688005 pts:2.688005 pos:43068 size:4096 flags:1 +ret: 0 st: 0 ts:1.565850 flags:1 +ret: 0 st: 0 dts:1.536009 pts:1.536009 pos:24636 size:4096 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.511995 pts:0.511995 pos:8252 size:4096 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:-0.703991 pts:-0.703991 pos:41020 size:4096 flags:1 +---------------- +tests/data/a-adpcm_ms.wav +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:56 size:4096 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:-0.960000 pts:-0.960000 pos:65536 size:4096 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.856009 pts:1.856009 pos:29752 size:4096 flags:1 +ret: 0 st: 0 ts:0.788345 flags:0 +ret: 0 st: 0 dts:0.831995 pts:0.831995 pos:13368 size:4096 flags:1 +ret: 0 st: 0 ts:-0.317506 flags:1 +ret: 0 st: 0 dts:-0.320000 pts:-0.320000 pos:46136 size:4096 flags:1 +ret: 0 st:-1 ts:2.576668 flags:0 +ret: 0 st: 0 dts:2.623991 pts:2.623991 pos:42040 size:4096 flags:1 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.408005 pts:1.408005 pos:22584 size:4096 flags:1 +ret: 0 st: 0 ts:0.365011 flags:0 +ret: 0 st: 0 dts:0.383991 pts:0.383991 pos:6200 size:4096 flags:1 +ret: 0 st: 0 ts:-0.740839 flags:1 +ret: 0 st: 0 dts:-0.768005 pts:-0.768005 pos:38968 size:4096 flags:1 +ret: 0 st:-1 ts:2.153336 flags:0 +ret: 0 st: 0 dts:2.176009 pts:2.176009 pos:34872 size:4096 flags:1 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.023991 pts:1.023991 pos:16440 size:4096 flags:1 +ret: 0 st: 0 ts:-0.058322 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:56 size:4096 flags:1 +ret: 0 st: 0 ts:2.835828 flags:1 +ret: 0 st: 0 dts:2.816009 pts:2.816009 pos:45112 size:4096 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.791995 pts:1.791995 pos:28728 size:4096 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.576009 pts:0.576009 pos:9272 size:4096 flags:1 +ret: 0 st: 0 ts:-0.481655 flags:0 +ret: 0 st: 0 dts:-0.448005 pts:-0.448005 pos:42040 size:4096 flags:1 +ret: 0 st: 0 ts:2.412494 flags:1 +ret: 0 st: 0 dts:2.368005 pts:2.368005 pos:37944 size:4096 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.343991 pts:1.343991 pos:21560 size:4096 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.191995 pts:0.191995 pos:3128 size:4096 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:-0.896009 pts:-0.896009 pos:35896 size:4096 flags:1 +ret: 0 st: 0 ts:1.989184 flags:1 +ret: 0 st: 0 dts:1.983991 pts:1.983991 pos:31800 size:4096 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.896009 pts:0.896009 pos:14392 size:4096 flags:1 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret: 0 st: 0 dts:-0.256009 pts:-0.256009 pos:47160 size:4096 flags:1 +ret: 0 st: 0 ts:2.671678 flags:0 +ret: 0 st: 0 dts:2.688005 pts:2.688005 pos:43064 size:4096 flags:1 +ret: 0 st: 0 ts:1.565850 flags:1 +ret: 0 st: 0 dts:1.536009 pts:1.536009 pos:24632 size:4096 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.511995 pts:0.511995 pos:8248 size:4096 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:-0.703991 pts:-0.703991 pos:41016 size:4096 flags:1 +---------------- +tests/data/a-adpcm_swf.flv +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:184 size:2053 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:184 size:2053 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:184 size:2053 flags:1 +ret: 0 st: 0 ts:0.788000 flags:0 +ret: 0 st: 0 dts:0.789000 pts:0.789000 pos:35357 size:2053 flags:1 +ret:-1 st: 0 ts:-0.317000 flags:1 +ret: 0 st:-1 ts:2.576668 flags:0 +ret: 0 st: 0 dts:2.601000 pts:2.601000 pos:116048 size:2053 flags:1 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:64323 size:2053 flags:1 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:0.372000 pts:0.372000 pos:16736 size:2053 flags:1 +ret:-1 st: 0 ts:-0.741000 flags:1 +ret: 0 st:-1 ts:2.153336 flags:0 +ret: 0 st: 0 dts:2.183000 pts:2.183000 pos:97427 size:2053 flags:1 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.022000 pts:1.022000 pos:45702 size:2053 flags:1 +ret: 0 st: 0 ts:-0.058000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:184 size:2053 flags:1 +ret: 0 st: 0 ts:2.836000 flags:1 +ret: 0 st: 0 dts:2.601000 pts:2.601000 pos:116048 size:2053 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.765000 pts:1.765000 pos:78806 size:2053 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.604000 pts:0.604000 pos:27081 size:2053 flags:1 +ret: 0 st: 0 ts:-0.482000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:184 size:2053 flags:1 +ret: 0 st: 0 ts:2.413000 flags:1 +ret: 0 st: 0 dts:2.368000 pts:2.368000 pos:105703 size:2053 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.347000 pts:1.347000 pos:60185 size:2053 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.186000 pts:0.186000 pos:8460 size:2053 flags:1 +ret: 0 st: 0 ts:-0.905000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:184 size:2053 flags:1 +ret: 0 st: 0 ts:1.989000 flags:1 +ret: 0 st: 0 dts:1.950000 pts:1.950000 pos:87082 size:2053 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.929000 pts:0.929000 pos:41564 size:2053 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret: 0 st: 0 ts:2.672000 flags:0 +ret: 0 st: 0 dts:2.694000 pts:2.694000 pos:120186 size:2053 flags:1 +ret: 0 st: 0 ts:1.566000 flags:1 +ret: 0 st: 0 dts:1.533000 pts:1.533000 pos:68461 size:2053 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.464000 pts:0.464000 pos:20874 size:2053 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-adpcm_yam.wav +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:56 size:4096 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:-0.960000 pts:-0.960000 pos:65536 size:4096 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.856009 pts:1.856009 pos:29752 size:4096 flags:1 +ret: 0 st: 0 ts:0.788345 flags:0 +ret: 0 st: 0 dts:0.831995 pts:0.831995 pos:13368 size:4096 flags:1 +ret: 0 st: 0 ts:-0.317506 flags:1 +ret: 0 st: 0 dts:-0.320000 pts:-0.320000 pos:46136 size:4096 flags:1 +ret: 0 st:-1 ts:2.576668 flags:0 +ret: 0 st: 0 dts:2.623991 pts:2.623991 pos:42040 size:4096 flags:1 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.408005 pts:1.408005 pos:22584 size:4096 flags:1 +ret: 0 st: 0 ts:0.365011 flags:0 +ret: 0 st: 0 dts:0.383991 pts:0.383991 pos:6200 size:4096 flags:1 +ret: 0 st: 0 ts:-0.740839 flags:1 +ret: 0 st: 0 dts:-0.768005 pts:-0.768005 pos:38968 size:4096 flags:1 +ret: 0 st:-1 ts:2.153336 flags:0 +ret: 0 st: 0 dts:2.176009 pts:2.176009 pos:34872 size:4096 flags:1 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.023991 pts:1.023991 pos:16440 size:4096 flags:1 +ret: 0 st: 0 ts:-0.058322 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:56 size:4096 flags:1 +ret: 0 st: 0 ts:2.835828 flags:1 +ret: 0 st: 0 dts:2.816009 pts:2.816009 pos:45112 size:4096 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.791995 pts:1.791995 pos:28728 size:4096 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.576009 pts:0.576009 pos:9272 size:4096 flags:1 +ret: 0 st: 0 ts:-0.481655 flags:0 +ret: 0 st: 0 dts:-0.448005 pts:-0.448005 pos:42040 size:4096 flags:1 +ret: 0 st: 0 ts:2.412494 flags:1 +ret: 0 st: 0 dts:2.368005 pts:2.368005 pos:37944 size:4096 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.343991 pts:1.343991 pos:21560 size:4096 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.191995 pts:0.191995 pos:3128 size:4096 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:-0.896009 pts:-0.896009 pos:35896 size:4096 flags:1 +ret: 0 st: 0 ts:1.989184 flags:1 +ret: 0 st: 0 dts:1.983991 pts:1.983991 pos:31800 size:4096 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.896009 pts:0.896009 pos:14392 size:4096 flags:1 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret: 0 st: 0 dts:-0.256009 pts:-0.256009 pos:47160 size:4096 flags:1 +ret: 0 st: 0 ts:2.671678 flags:0 +ret: 0 st: 0 dts:2.688005 pts:2.688005 pos:43064 size:4096 flags:1 +ret: 0 st: 0 ts:1.565850 flags:1 +ret: 0 st: 0 dts:1.536009 pts:1.536009 pos:24632 size:4096 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.511995 pts:0.511995 pos:8248 size:4096 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:-0.703991 pts:-0.703991 pos:41016 size:4096 flags:1 +---------------- +tests/data/a-asv1.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5668 size:14316 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5668 size:14316 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.880000 pts:1.880000 pos:776852 size:18256 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.800000 pts:0.800000 pos:305364 size:16180 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.480000 pts:1.480000 pos:595460 size:17980 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.360000 pts:0.360000 pos:135528 size:14868 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.040000 pts:1.040000 pos:404112 size:16856 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5668 size:14316 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:813408 size:18296 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.720000 pts:1.720000 pos:704148 size:18140 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.640000 pts:0.640000 pos:241776 size:15736 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5668 size:14316 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:813408 size:18296 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.320000 pts:1.320000 pos:524500 size:17548 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.200000 pts:0.200000 pos:77032 size:14496 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5668 size:14316 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:813408 size:18296 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:337820 size:16388 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.560000 pts:1.560000 pos:631596 size:18188 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:180224 size:15168 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-asv2.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5668 size:13732 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5668 size:13732 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.880000 pts:1.880000 pos:736164 size:17340 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.800000 pts:0.800000 pos:289720 size:15300 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.480000 pts:1.480000 pos:564152 size:17016 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.360000 pts:0.360000 pos:128576 size:14052 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.040000 pts:1.040000 pos:383256 size:15896 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5668 size:13732 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:770864 size:17400 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.720000 pts:1.720000 pos:667028 size:17172 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.640000 pts:0.640000 pos:229400 size:14956 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5668 size:13732 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:770864 size:17400 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.320000 pts:1.320000 pos:496944 size:16564 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.200000 pts:0.200000 pos:73188 size:13664 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5668 size:13732 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:770864 size:17400 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:320456 size:15592 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.560000 pts:1.560000 pos:598300 size:17180 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:171024 size:14392 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-dv.dv +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.880000 pts:1.880000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.800000 pts:0.800000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:-0.320000 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:2.576668 flags:0 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.480000 pts:1.480000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.360000 pts:0.360000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:-0.760000 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:2.153336 flags:0 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.040000 pts:1.040000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.720000 pts:1.720000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.640000 pts:0.640000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.320000 pts:1.320000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.200000 pts:0.200000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.560000 pts:1.560000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +---------------- +tests/data/a-dv50.dv +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:288000 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:288000 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.880000 pts:1.880000 pos:-1 size:288000 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.800000 pts:0.800000 pos:-1 size:288000 flags:1 +ret: 0 st: 0 ts:-0.320000 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:288000 flags:1 +ret: 0 st:-1 ts:2.576668 flags:0 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:288000 flags:1 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.480000 pts:1.480000 pos:-1 size:288000 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.360000 pts:0.360000 pos:-1 size:288000 flags:1 +ret: 0 st: 0 ts:-0.760000 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:288000 flags:1 +ret: 0 st:-1 ts:2.153336 flags:0 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:288000 flags:1 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.040000 pts:1.040000 pos:-1 size:288000 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:288000 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:288000 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.720000 pts:1.720000 pos:-1 size:288000 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.640000 pts:0.640000 pos:-1 size:288000 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:288000 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:288000 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.320000 pts:1.320000 pos:-1 size:288000 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.200000 pts:0.200000 pos:-1 size:288000 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:288000 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:288000 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:-1 size:288000 flags:1 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:288000 flags:1 +ret: 0 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:288000 flags:1 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.560000 pts:1.560000 pos:-1 size:288000 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:-1 size:288000 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:288000 flags:1 +---------------- +tests/data/a-error-mpeg4-adv.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:9564 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:9564 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:113142 size:12795 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:71660 size:11680 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:113142 size:12795 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:36782 size:10310 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:71660 size:11680 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:9564 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:159370 size:13895 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:159370 size:13895 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:36782 size:10310 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:9564 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:159370 size:13895 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:113142 size:12795 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:9564 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:9564 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:159370 size:13895 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:71660 size:11680 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:113142 size:12795 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:36782 size:10310 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-ffv1.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:70200 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:70200 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:2485810 size:74128 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:1622716 size:71128 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:2485810 size:74128 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:796840 size:67971 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:1622716 size:71128 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:70200 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:3374440 size:75606 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:3374440 size:75606 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:796840 size:67971 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:70200 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:3374440 size:75606 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:2485810 size:74128 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:70200 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:70200 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:3374440 size:75606 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:1622716 size:71128 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:2485810 size:74128 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:796840 size:67971 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-flac.flac +ret: 0 st: 0 dts:-102481911520608.625000 pts:-102481911520608.625000 pos:0 size:1024 flags:1 +ret:-1 st:-1 ts:-1.000000 flags:0 +ret:-1 st:-1 ts:1.894167 flags:1 +ret:-1 st: 0 ts:0.788333 flags:0 +ret:-1 st: 0 ts:-0.317500 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret:-1 st:-1 ts:1.470835 flags:1 +ret:-1 st: 0 ts:0.365000 flags:0 +ret:-1 st: 0 ts:-0.740833 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret:-1 st:-1 ts:1.047503 flags:1 +ret:-1 st: 0 ts:-0.058333 flags:0 +ret:-1 st: 0 ts:2.835833 flags:1 +ret:-1 st:-1 ts:1.730004 flags:0 +ret:-1 st:-1 ts:0.624171 flags:1 +ret:-1 st: 0 ts:-0.481667 flags:0 +ret:-1 st: 0 ts:2.412500 flags:1 +ret:-1 st:-1 ts:1.306672 flags:0 +ret:-1 st:-1 ts:0.200839 flags:1 +ret:-1 st: 0 ts:-0.904989 flags:0 +ret:-1 st: 0 ts:1.989178 flags:1 +ret:-1 st:-1 ts:0.883340 flags:0 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.671678 flags:0 +ret:-1 st: 0 ts:1.565844 flags:1 +ret:-1 st:-1 ts:0.460008 flags:0 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-flashsv.flv +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:240780 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:240780 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:0.800000 pts:0.800000 pos:4820523 size:245529 flags:1 +ret: 0 st: 0 ts:0.788000 flags:0 +ret: 0 st: 0 dts:0.800000 pts:0.800000 pos:4820523 size:245529 flags:1 +ret:-1 st: 0 ts:-0.317000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:8811872 size:253019 flags:1 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:0.400000 pts:0.400000 pos:2387438 size:241071 flags:1 +ret:-1 st: 0 ts:-0.741000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.040000 pts:1.040000 pos:6302761 size:248908 flags:1 +ret: 0 st: 0 ts:-0.058000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:240780 flags:1 +ret: 0 st: 0 ts:2.836000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:12114602 size:254233 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.760000 pts:1.760000 pos:10843511 size:253928 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.600000 pts:0.600000 pos:3598850 size:243415 flags:1 +ret: 0 st: 0 ts:-0.482000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:240780 flags:1 +ret: 0 st: 0 ts:2.413000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:12114602 size:254233 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.320000 pts:1.320000 pos:8053620 size:252181 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.200000 pts:0.200000 pos:1187811 size:238542 flags:1 +ret: 0 st: 0 ts:-0.905000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:240780 flags:1 +ret: 0 st: 0 ts:1.989000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:12114602 size:254233 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.920000 pts:0.920000 pos:5559227 size:247287 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.672000 flags:0 +ret: 0 st: 0 ts:1.566000 flags:1 +ret: 0 st: 0 dts:1.560000 pts:1.560000 pos:9572141 size:254223 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:2870244 size:242355 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-flv.flv +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:10380 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:10380 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:25960 size:10089 flags:1 +ret: 0 st: 0 ts:0.788000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:52585 size:11127 flags:1 +ret:-1 st: 0 ts:-0.317000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:83240 size:12295 flags:1 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:25960 size:10089 flags:1 +ret:-1 st: 0 ts:-0.741000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:52585 size:11127 flags:1 +ret: 0 st: 0 ts:-0.058000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:10380 flags:1 +ret: 0 st: 0 ts:2.836000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:117158 size:12730 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:117158 size:12730 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:25960 size:10089 flags:1 +ret: 0 st: 0 ts:-0.482000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:10380 flags:1 +ret: 0 st: 0 ts:2.413000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:117158 size:12730 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:83240 size:12295 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:10380 flags:1 +ret: 0 st: 0 ts:-0.905000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:10380 flags:1 +ret: 0 st: 0 ts:1.989000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:117158 size:12730 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:52585 size:11127 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.672000 flags:0 +ret: 0 st: 0 ts:1.566000 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:83240 size:12295 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:25960 size:10089 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-g726.wav +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:56 size:4096 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret:-5 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.894000 pts:1.894000 pos:7632 size:4096 flags:1 +ret: 0 st: 0 ts:0.788375 flags:0 +ret: 0 st: 0 dts:0.788500 pts:0.788500 pos:3210 size:4096 flags:1 +ret: 0 st: 0 ts:-0.317500 flags:1 +ret:-5 +ret: 0 st:-1 ts:2.576668 flags:0 +ret: 0 st: 0 dts:2.576750 pts:2.576750 pos:10363 size:4096 flags:1 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.470750 pts:1.470750 pos:5939 size:4096 flags:1 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:0.365000 pts:0.365000 pos:1516 size:4096 flags:1 +ret: 0 st: 0 ts:-0.740875 flags:1 +ret:-5 +ret: 0 st:-1 ts:2.153336 flags:0 +ret: 0 st: 0 dts:2.153500 pts:2.153500 pos:8670 size:4096 flags:1 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.047500 pts:1.047500 pos:4246 size:4096 flags:1 +ret: 0 st: 0 ts:-0.058375 flags:0 +ret:-5 +ret: 0 st: 0 ts:2.835875 flags:1 +ret: 0 st: 0 dts:2.835750 pts:2.835750 pos:11399 size:4096 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.730000 pts:1.730000 pos:6976 size:4096 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.624000 pts:0.624000 pos:2552 size:4096 flags:1 +ret: 0 st: 0 ts:-0.481625 flags:0 +ret:-5 +ret: 0 st: 0 ts:2.412500 flags:1 +ret: 0 st: 0 dts:2.412500 pts:2.412500 pos:9706 size:4096 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.306750 pts:1.306750 pos:5283 size:4096 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.200750 pts:0.200750 pos:859 size:4096 flags:1 +ret: 0 st: 0 ts:-0.905000 flags:0 +ret:-5 +ret: 0 st: 0 ts:1.989125 flags:1 +ret: 0 st: 0 dts:1.989000 pts:1.989000 pos:8012 size:4096 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.883500 pts:0.883500 pos:3590 size:4096 flags:1 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret:-5 +ret: 0 st: 0 ts:2.671625 flags:0 +ret: 0 st: 0 dts:2.671750 pts:2.671750 pos:10743 size:4096 flags:1 +ret: 0 st: 0 ts:1.565875 flags:1 +ret: 0 st: 0 dts:1.565750 pts:1.565750 pos:6319 size:4096 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.460000 pts:0.460000 pos:1896 size:4096 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret:-5 +---------------- +tests/data/a-h261.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:15314 size:9645 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:15314 size:9645 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:137900 size:11377 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:92402 size:10322 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:137900 size:11377 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:54090 size:9404 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:92402 size:10322 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:15314 size:9645 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:187598 size:11707 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:187598 size:11707 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:54090 size:9404 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:15314 size:9645 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:187598 size:11707 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:137900 size:11377 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:15314 size:9645 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:15314 size:9645 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:187598 size:11707 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:92402 size:10322 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:137900 size:11377 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:54090 size:9404 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-h263.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:16050 size:10381 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:16050 size:10381 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:116018 size:12296 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:77940 size:11128 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:116018 size:12296 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:46548 size:10090 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:77940 size:11128 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:16050 size:10381 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:157298 size:12731 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:157298 size:12731 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:46548 size:10090 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:16050 size:10381 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:157298 size:12731 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:116018 size:12296 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:16050 size:10381 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:16050 size:10381 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:157298 size:12731 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:77940 size:11128 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:116018 size:12296 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:46548 size:10090 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-h263p.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:41876 size:36208 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:41876 size:36208 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:615098 size:45151 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:396904 size:40907 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:615098 size:45151 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:207578 size:36515 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:396904 size:40907 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:41876 size:36208 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:850798 size:46411 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:850798 size:46411 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:207578 size:36515 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:41876 size:36208 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:850798 size:46411 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:615098 size:45151 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:41876 size:36208 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:41876 size:36208 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:850798 size:46411 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:396904 size:40907 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:615098 size:45151 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:207578 size:36515 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-huffyuv.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5736 size:129760 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5736 size:129760 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.880000 pts:1.880000 pos:6069184 size:128520 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.800000 pts:0.800000 pos:2579624 size:129192 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.480000 pts:1.480000 pos:4778240 size:129424 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.360000 pts:0.360000 pos:1160260 size:128504 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.040000 pts:1.040000 pos:3355296 size:129424 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5736 size:129760 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:6326136 size:128288 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.720000 pts:1.720000 pos:5554008 size:129016 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.640000 pts:0.640000 pos:2062504 size:129204 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5736 size:129760 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:6326136 size:128288 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.320000 pts:1.320000 pos:4260872 size:129280 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.200000 pts:0.200000 pos:646920 size:128204 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5736 size:129760 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:6326136 size:128288 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:2838080 size:129268 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.560000 pts:1.560000 pos:5037036 size:129284 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:1546184 size:128860 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-jpegls.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:169698 size:164030 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:169698 size:164030 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.880000 pts:1.880000 pos:7980356 size:176323 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.800000 pts:0.800000 pos:3337352 size:164695 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.480000 pts:1.480000 pos:6226960 size:174093 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.360000 pts:0.360000 pos:1559556 size:157316 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.040000 pts:1.040000 pos:4338572 size:168415 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:169698 size:164030 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:176753 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.720000 pts:1.720000 pos:7277068 size:175370 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.640000 pts:0.640000 pos:2681730 size:162510 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:169698 size:164030 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:176753 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.320000 pts:1.320000 pos:5532842 size:172194 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.200000 pts:0.200000 pos:934334 size:154553 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:169698 size:164030 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:176753 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:3668754 size:165988 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.560000 pts:1.560000 pos:6576202 size:174822 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:2036046 size:159683 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-ljpeg.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:101714 size:96046 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:101714 size:96046 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.880000 pts:1.880000 pos:4576420 size:94867 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.800000 pts:0.800000 pos:1997656 size:95452 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.480000 pts:1.480000 pos:3623216 size:95720 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.360000 pts:0.360000 pos:949522 size:94624 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.040000 pts:1.040000 pos:2571070 size:95642 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:101714 size:96046 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:94581 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.720000 pts:1.720000 pos:4196396 size:95340 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.640000 pts:0.640000 pos:1615596 size:95411 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:101714 size:96046 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:94581 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.320000 pts:1.320000 pos:3240494 size:95577 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.200000 pts:0.200000 pos:571462 size:94255 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:101714 size:96046 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:94581 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:2188690 size:95527 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.560000 pts:1.560000 pos:3814484 size:95608 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:1234190 size:95024 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-mjpeg.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:18314 size:12645 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:18314 size:12645 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.880000 pts:1.880000 pos:671614 size:15502 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.800000 pts:0.800000 pos:271636 size:13495 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.480000 pts:1.480000 pos:517438 size:15178 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.360000 pts:0.360000 pos:128076 size:12462 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.040000 pts:1.040000 pos:355100 size:14162 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:18314 size:12645 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:15563 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.720000 pts:1.720000 pos:609712 size:15417 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.640000 pts:0.640000 pos:218052 size:13266 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:18314 size:12645 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:15563 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.320000 pts:1.320000 pos:457048 size:14771 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.200000 pts:0.200000 pos:78566 size:12235 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:18314 size:12645 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:-1 size:15563 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:299054 size:13721 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.560000 pts:1.560000 pos:548116 size:15319 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:165884 size:12719 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-mp2.mp2 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:417 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.026122 pts:0.026122 pos:417 size:418 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.880800 pts:1.880800 pos:30093 size:418 flags:1 +ret: 0 st: 0 ts:0.788333 flags:0 +ret: 0 st: 0 dts:0.809789 pts:0.809789 pos:12956 size:418 flags:1 +ret: 0 st: 0 ts:-0.317500 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:417 flags:1 +ret: 0 st:-1 ts:2.576668 flags:0 +ret: 0 st: 0 dts:2.586100 pts:2.586100 pos:41377 size:418 flags:1 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.462844 pts:1.462844 pos:23405 size:418 flags:1 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:0.365711 pts:0.365711 pos:5851 size:418 flags:1 +ret: 0 st: 0 ts:-0.740833 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:417 flags:1 +ret: 0 st:-1 ts:2.153336 flags:0 +ret: 0 st: 0 dts:2.168144 pts:2.168144 pos:34690 size:418 flags:1 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.044889 pts:1.044889 pos:16718 size:418 flags:1 +ret: 0 st: 0 ts:-0.058333 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:417 flags:1 +ret: 0 st: 0 ts:2.835833 flags:1 +ret: 0 st: 0 dts:2.821200 pts:2.821200 pos:45139 size:418 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.750189 pts:1.750189 pos:28003 size:418 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.600811 pts:0.600811 pos:9613 size:418 flags:1 +ret: 0 st: 0 ts:-0.481667 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:417 flags:1 +ret: 0 st: 0 ts:2.412500 flags:1 +ret: 0 st: 0 dts:2.403244 pts:2.403244 pos:38452 size:418 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.332233 pts:1.332233 pos:21315 size:418 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.182856 pts:0.182856 pos:2925 size:418 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:417 flags:1 +ret: 0 st: 0 ts:1.989178 flags:1 +ret: 0 st: 0 dts:1.985289 pts:1.985289 pos:31764 size:418 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.888156 pts:0.888156 pos:14210 size:418 flags:1 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:417 flags:1 +ret: 0 st: 0 ts:2.671678 flags:0 +ret: 0 st: 0 dts:2.690589 pts:2.690589 pos:43049 size:418 flags:1 +ret: 0 st: 0 ts:1.565844 flags:1 +ret: 0 st: 0 dts:1.541211 pts:1.541211 pos:24659 size:418 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.470200 pts:0.470200 pos:7523 size:418 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:417 flags:1 +---------------- +tests/data/a-mpeg1.mpg +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:9216 size:9779 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9779 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:-102481911520608.625000 pos:135509 size:11796 flags:1 +ret: 0 st: 0 ts:0.788333 flags:0 +ret: 0 st: 0 dts:0.960000 pts:-102481911520608.625000 pos:86934 size:10792 flags:1 +ret:-1 st: 0 ts:-0.317500 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:-102481911520608.625000 pos:135509 size:11796 flags:1 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:-102481911520608.625000 pos:46937 size:9873 flags:1 +ret:-1 st: 0 ts:-0.740833 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:-102481911520608.625000 pos:86934 size:10792 flags:1 +ret: 0 st: 0 ts:-0.058333 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9779 flags:1 +ret: 0 st: 0 ts:2.835833 flags:1 +ret: 0 st: 0 dts:1.920000 pts:-102481911520608.625000 pos:188353 size:12057 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:-102481911520608.625000 pos:188353 size:12057 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:-102481911520608.625000 pos:46937 size:9873 flags:1 +ret: 0 st: 0 ts:-0.481667 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9779 flags:1 +ret: 0 st: 0 ts:2.412500 flags:1 +ret: 0 st: 0 dts:1.920000 pts:-102481911520608.625000 pos:188353 size:12057 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:-102481911520608.625000 pos:135509 size:11796 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9779 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9779 flags:1 +ret: 0 st: 0 ts:1.989178 flags:1 +ret: 0 st: 0 dts:1.920000 pts:-102481911520608.625000 pos:188353 size:12057 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:-102481911520608.625000 pos:86934 size:10792 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.671678 flags:0 +ret: 0 st: 0 ts:1.565844 flags:1 +ret: 0 st: 0 dts:1.440000 pts:-102481911520608.625000 pos:135509 size:11796 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:-102481911520608.625000 pos:46937 size:9873 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-mpeg1b.mpg +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:11264 size:11817 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:11264 size:11817 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.800000 pts:-102481911520608.625000 pos:212858 size:14837 flags:1 +ret: 0 st: 0 ts:0.788333 flags:0 +ret: 0 st: 0 dts:0.840000 pts:-102481911520608.625000 pos:94832 size:13267 flags:1 +ret:-1 st: 0 ts:-0.317500 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.320000 pts:-102481911520608.625000 pos:151065 size:14470 flags:1 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:0.840000 pts:-102481911520608.625000 pos:94832 size:13267 flags:1 +ret:-1 st: 0 ts:-0.740833 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.840000 pts:-102481911520608.625000 pos:94832 size:13267 flags:1 +ret: 0 st: 0 ts:-0.058333 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:11264 size:11817 flags:1 +ret: 0 st: 0 ts:2.835833 flags:1 +ret: 0 st: 0 dts:1.800000 pts:-102481911520608.625000 pos:212858 size:14837 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.800000 pts:-102481911520608.625000 pos:212858 size:14837 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.360000 pts:-102481911520608.625000 pos:46883 size:12009 flags:1 +ret: 0 st: 0 ts:-0.481667 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:11264 size:11817 flags:1 +ret: 0 st: 0 ts:2.412500 flags:1 +ret: 0 st: 0 dts:1.800000 pts:-102481911520608.625000 pos:212858 size:14837 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.320000 pts:-102481911520608.625000 pos:151065 size:14470 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:11264 size:11817 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:11264 size:11817 flags:1 +ret: 0 st: 0 ts:1.989178 flags:1 +ret: 0 st: 0 dts:1.800000 pts:-102481911520608.625000 pos:212858 size:14837 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:1.320000 pts:-102481911520608.625000 pos:151065 size:14470 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.671678 flags:0 +ret: 0 st: 0 ts:1.565844 flags:1 +ret: 0 st: 0 dts:1.320000 pts:-102481911520608.625000 pos:151065 size:14470 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.840000 pts:-102481911520608.625000 pos:94832 size:13267 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-mpeg2.mpg +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9911 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9911 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:-102481911520608.625000 pos:139189 size:11918 flags:1 +ret: 0 st: 0 ts:0.788333 flags:0 +ret: 0 st: 0 dts:0.960000 pts:-102481911520608.625000 pos:89343 size:10909 flags:1 +ret:-1 st: 0 ts:-0.317500 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:-102481911520608.625000 pos:139189 size:11918 flags:1 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:-102481911520608.625000 pos:48208 size:9985 flags:1 +ret:-1 st: 0 ts:-0.740833 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:-102481911520608.625000 pos:89343 size:10909 flags:1 +ret: 0 st: 0 ts:-0.058333 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9911 flags:1 +ret: 0 st: 0 ts:2.835833 flags:1 +ret: 0 st: 0 dts:1.920000 pts:-102481911520608.625000 pos:193402 size:12183 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:-102481911520608.625000 pos:193402 size:12183 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:-102481911520608.625000 pos:48208 size:9985 flags:1 +ret: 0 st: 0 ts:-0.481667 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9911 flags:1 +ret: 0 st: 0 ts:2.412500 flags:1 +ret: 0 st: 0 dts:1.920000 pts:-102481911520608.625000 pos:193402 size:12183 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:-102481911520608.625000 pos:139189 size:11918 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9911 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9911 flags:1 +ret: 0 st: 0 ts:1.989178 flags:1 +ret: 0 st: 0 dts:1.920000 pts:-102481911520608.625000 pos:193402 size:12183 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:-102481911520608.625000 pos:89343 size:10909 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.671678 flags:0 +ret: 0 st: 0 ts:1.565844 flags:1 +ret: 0 st: 0 dts:1.440000 pts:-102481911520608.625000 pos:139189 size:11918 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:-102481911520608.625000 pos:48208 size:9985 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-mpeg2i.mpg +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9961 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9961 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:-102481911520608.625000 pos:143871 size:11970 flags:1 +ret: 0 st: 0 ts:0.788333 flags:0 +ret: 0 st: 0 dts:0.960000 pts:-102481911520608.625000 pos:92392 size:10965 flags:1 +ret:-1 st: 0 ts:-0.317500 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:-102481911520608.625000 pos:143871 size:11970 flags:1 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:-102481911520608.625000 pos:49762 size:10045 flags:1 +ret:-1 st: 0 ts:-0.740833 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:-102481911520608.625000 pos:92392 size:10965 flags:1 +ret: 0 st: 0 ts:-0.058333 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9961 flags:1 +ret: 0 st: 0 ts:2.835833 flags:1 +ret: 0 st: 0 dts:1.920000 pts:-102481911520608.625000 pos:199693 size:12232 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:-102481911520608.625000 pos:199693 size:12232 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:-102481911520608.625000 pos:49762 size:10045 flags:1 +ret: 0 st: 0 ts:-0.481667 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9961 flags:1 +ret: 0 st: 0 ts:2.412500 flags:1 +ret: 0 st: 0 dts:1.920000 pts:-102481911520608.625000 pos:199693 size:12232 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:-102481911520608.625000 pos:143871 size:11970 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9961 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9961 flags:1 +ret: 0 st: 0 ts:1.989178 flags:1 +ret: 0 st: 0 dts:1.920000 pts:-102481911520608.625000 pos:199693 size:12232 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:-102481911520608.625000 pos:92392 size:10965 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.671678 flags:0 +ret: 0 st: 0 ts:1.565844 flags:1 +ret: 0 st: 0 dts:1.440000 pts:-102481911520608.625000 pos:143871 size:11970 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:-102481911520608.625000 pos:49762 size:10045 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-mpeg2ivlc-qprd.mpg +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:15360 size:16239 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:15360 size:16239 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:241597 size:12278 flags:1 +ret: 0 st: 0 ts:0.788333 flags:0 +ret: 0 st: 0 dts:0.880000 pts:-102481911520608.625000 pos:181240 size:13625 flags:1 +ret:-1 st: 0 ts:-0.317500 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.360000 pts:-102481911520608.625000 pos:212338 size:12777 flags:1 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:0.400000 pts:-102481911520608.625000 pos:130237 size:29165 flags:1 +ret:-1 st: 0 ts:-0.740833 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.880000 pts:-102481911520608.625000 pos:181240 size:13625 flags:1 +ret: 0 st: 0 ts:-0.058333 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:15360 size:16239 flags:1 +ret: 0 st: 0 ts:2.835833 flags:1 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:241597 size:12278 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:241597 size:12278 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.400000 pts:-102481911520608.625000 pos:130237 size:29165 flags:1 +ret: 0 st: 0 ts:-0.481667 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:15360 size:16239 flags:1 +ret: 0 st: 0 ts:2.412500 flags:1 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:241597 size:12278 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.360000 pts:-102481911520608.625000 pos:212338 size:12777 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:15360 size:16239 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:15360 size:16239 flags:1 +ret: 0 st: 0 ts:1.989178 flags:1 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:241597 size:12278 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:1.360000 pts:-102481911520608.625000 pos:212338 size:12777 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.671678 flags:0 +ret: 0 st: 0 ts:1.565844 flags:1 +ret: 0 st: 0 dts:1.360000 pts:-102481911520608.625000 pos:212338 size:12777 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.880000 pts:-102481911520608.625000 pos:181240 size:13625 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-mpeg2reuse.mpg +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:20480 size:20829 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:20480 size:20829 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:373661 size:26840 flags:1 +ret: 0 st: 0 ts:0.788333 flags:0 +ret: 0 st: 0 dts:0.880000 pts:-102481911520608.625000 pos:167721 size:23537 flags:1 +ret:-1 st: 0 ts:-0.317500 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.360000 pts:-102481911520608.625000 pos:264461 size:26192 flags:1 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:0.400000 pts:-102481911520608.625000 pos:85877 size:21295 flags:1 +ret:-1 st: 0 ts:-0.740833 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.880000 pts:-102481911520608.625000 pos:167721 size:23537 flags:1 +ret: 0 st: 0 ts:-0.058333 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:20480 size:20829 flags:1 +ret: 0 st: 0 ts:2.835833 flags:1 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:373661 size:26840 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:373661 size:26840 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.400000 pts:-102481911520608.625000 pos:85877 size:21295 flags:1 +ret: 0 st: 0 ts:-0.481667 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:20480 size:20829 flags:1 +ret: 0 st: 0 ts:2.412500 flags:1 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:373661 size:26840 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.360000 pts:-102481911520608.625000 pos:264461 size:26192 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:20480 size:20829 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:20480 size:20829 flags:1 +ret: 0 st: 0 ts:1.989178 flags:1 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:373661 size:26840 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:1.360000 pts:-102481911520608.625000 pos:264461 size:26192 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.671678 flags:0 +ret: 0 st: 0 ts:1.565844 flags:1 +ret: 0 st: 0 dts:1.360000 pts:-102481911520608.625000 pos:264461 size:26192 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.880000 pts:-102481911520608.625000 pos:167721 size:23537 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-mpeg2thread.mpg +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9961 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9961 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:172485 size:12232 flags:1 +ret: 0 st: 0 ts:0.788333 flags:0 +ret: 0 st: 0 dts:0.880000 pts:-102481911520608.625000 pos:79253 size:10965 flags:1 +ret:-1 st: 0 ts:-0.317500 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.360000 pts:-102481911520608.625000 pos:123712 size:11970 flags:1 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:0.400000 pts:-102481911520608.625000 pos:40457 size:10045 flags:1 +ret:-1 st: 0 ts:-0.740833 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.880000 pts:-102481911520608.625000 pos:79253 size:10965 flags:1 +ret: 0 st: 0 ts:-0.058333 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9961 flags:1 +ret: 0 st: 0 ts:2.835833 flags:1 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:172485 size:12232 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:172485 size:12232 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.400000 pts:-102481911520608.625000 pos:40457 size:10045 flags:1 +ret: 0 st: 0 ts:-0.481667 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9961 flags:1 +ret: 0 st: 0 ts:2.412500 flags:1 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:172485 size:12232 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.360000 pts:-102481911520608.625000 pos:123712 size:11970 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9961 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9961 flags:1 +ret: 0 st: 0 ts:1.989178 flags:1 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:172485 size:12232 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:1.360000 pts:-102481911520608.625000 pos:123712 size:11970 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.671678 flags:0 +ret: 0 st: 0 ts:1.565844 flags:1 +ret: 0 st: 0 dts:1.360000 pts:-102481911520608.625000 pos:123712 size:11970 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.880000 pts:-102481911520608.625000 pos:79253 size:10965 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-mpeg2threadivlc.mpg +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9954 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9954 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:171933 size:11930 flags:1 +ret: 0 st: 0 ts:0.788333 flags:0 +ret: 0 st: 0 dts:0.880000 pts:-102481911520608.625000 pos:79182 size:10791 flags:1 +ret:-1 st: 0 ts:-0.317500 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.360000 pts:-102481911520608.625000 pos:123457 size:11697 flags:1 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:0.400000 pts:-102481911520608.625000 pos:40451 size:9980 flags:1 +ret:-1 st: 0 ts:-0.740833 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.880000 pts:-102481911520608.625000 pos:79182 size:10791 flags:1 +ret: 0 st: 0 ts:-0.058333 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9954 flags:1 +ret: 0 st: 0 ts:2.835833 flags:1 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:171933 size:11930 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:171933 size:11930 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.400000 pts:-102481911520608.625000 pos:40451 size:9980 flags:1 +ret: 0 st: 0 ts:-0.481667 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9954 flags:1 +ret: 0 st: 0 ts:2.412500 flags:1 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:171933 size:11930 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.360000 pts:-102481911520608.625000 pos:123457 size:11697 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9954 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:9216 size:9954 flags:1 +ret: 0 st: 0 ts:1.989178 flags:1 +ret: 0 st: 0 dts:1.840000 pts:-102481911520608.625000 pos:171933 size:11930 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:1.360000 pts:-102481911520608.625000 pos:123457 size:11697 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.671678 flags:0 +ret: 0 st: 0 ts:1.565844 flags:1 +ret: 0 st: 0 dts:1.360000 pts:-102481911520608.625000 pos:123457 size:11697 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.880000 pts:-102481911520608.625000 pos:79182 size:10791 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-mpeg4-PSP.mp4 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:17075 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:17075 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:242961 size:21719 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:179481 size:19311 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:242961 size:21719 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:108454 size:21469 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:179481 size:19311 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:17075 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:302824 size:18559 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:302824 size:18559 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:108454 size:21469 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:17075 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:302824 size:18559 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:242961 size:21719 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:17075 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:17075 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:302824 size:18559 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:179481 size:19311 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:242961 size:21719 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:108454 size:21469 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-mpeg4-Q.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:11942 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:11942 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:142978 size:15562 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:64442 size:13382 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.360000 pts:1.360000 pos:101236 size:15057 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.400000 pts:0.400000 pos:32850 size:11813 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:64442 size:13382 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:11942 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:142978 size:15562 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:142978 size:15562 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.400000 pts:0.400000 pos:32850 size:11813 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:11942 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:142978 size:15562 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.360000 pts:1.360000 pos:101236 size:15057 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:11942 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:11942 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:142978 size:15562 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:64442 size:13382 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.360000 pts:1.360000 pos:101236 size:15057 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:64442 size:13382 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-mpeg4-adap.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:6855 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:6855 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:175668 size:16884 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:99006 size:16933 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.360000 pts:1.360000 pos:136592 size:17435 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.400000 pts:0.400000 pos:59872 size:17261 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:99006 size:16933 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:6855 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:175668 size:16884 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:175668 size:16884 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.400000 pts:0.400000 pos:59872 size:17261 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:6855 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:175668 size:16884 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.360000 pts:1.360000 pos:136592 size:17435 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:6855 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:6855 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:175668 size:16884 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:99006 size:16933 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.360000 pts:1.360000 pos:136592 size:17435 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:99006 size:16933 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-mpeg4-adv.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8653 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8653 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:91730 size:11013 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:59504 size:9815 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:91730 size:11013 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:31944 size:8753 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:59504 size:9815 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8653 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:127624 size:11279 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:127624 size:11279 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:31944 size:8753 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8653 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:127624 size:11279 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:91730 size:11013 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8653 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8653 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:127624 size:11279 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:59504 size:9815 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:91730 size:11013 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:31944 size:8753 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-mpeg4-nr.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:10673 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:10673 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:100640 size:12464 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:65480 size:11181 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:100640 size:12464 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:35312 size:9987 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:65480 size:11181 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:10673 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:139424 size:12911 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:139424 size:12911 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:35312 size:9987 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:10673 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:139424 size:12911 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:100640 size:12464 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:10673 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:10673 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:139424 size:12911 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:65480 size:11181 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:100640 size:12464 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:35312 size:9987 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-mpeg4-qprd.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:14873 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:14873 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:215220 size:13087 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:159706 size:12679 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.360000 pts:1.360000 pos:187334 size:12986 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.400000 pts:0.400000 pos:99648 size:29366 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:159706 size:12679 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:14873 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:215220 size:13087 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:215220 size:13087 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.400000 pts:0.400000 pos:99648 size:29366 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:14873 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:215220 size:13087 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.360000 pts:1.360000 pos:187334 size:12986 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:14873 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:14873 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:215220 size:13087 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:159706 size:12679 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.360000 pts:1.360000 pos:187334 size:12986 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:159706 size:12679 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-mpeg4-rc.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:15766 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:15766 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:209236 size:13826 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:154792 size:13382 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.360000 pts:1.360000 pos:182316 size:13326 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.400000 pts:0.400000 pos:95408 size:32807 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:154792 size:13382 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:15766 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:209236 size:13826 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:209236 size:13826 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.400000 pts:0.400000 pos:95408 size:32807 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:15766 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:209236 size:13826 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.360000 pts:1.360000 pos:182316 size:13326 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:15766 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:15766 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:209236 size:13826 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:154792 size:13382 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.360000 pts:1.360000 pos:182316 size:13326 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:154792 size:13382 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-mpeg4-thread.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:14874 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:14874 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:229568 size:14638 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:163772 size:16380 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.360000 pts:1.360000 pos:196664 size:16051 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.400000 pts:0.400000 pos:98760 size:33020 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:163772 size:16380 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:14874 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:229568 size:14638 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:229568 size:14638 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.400000 pts:0.400000 pos:98760 size:33020 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:14874 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:229568 size:14638 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.360000 pts:1.360000 pos:196664 size:16051 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:14874 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:14874 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.840000 pts:1.840000 pos:229568 size:14638 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:163772 size:16380 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.360000 pts:1.360000 pos:196664 size:16051 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:163772 size:16380 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-msmpeg4.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8637 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8637 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:82520 size:10783 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:53858 size:9624 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:82520 size:10783 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:29400 size:8502 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:53858 size:9624 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8637 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:114276 size:11180 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:114276 size:11180 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:29400 size:8502 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8637 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:114276 size:11180 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:82520 size:10783 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8637 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8637 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:114276 size:11180 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:53858 size:9624 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:82520 size:10783 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:29400 size:8502 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-msmpeg4v2.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:9003 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:9003 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:83882 size:11165 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:54790 size:10010 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:83882 size:11165 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:29782 size:8869 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:54790 size:10010 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:9003 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:116112 size:11578 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:116112 size:11578 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:29782 size:8869 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:9003 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:116112 size:11578 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:83882 size:11165 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:9003 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:9003 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:116112 size:11578 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:54790 size:10010 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:83882 size:11165 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:29782 size:8869 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-odivx.mp4 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:8719 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:8719 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:75132 size:10776 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:47220 size:9634 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:75132 size:10776 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:23263 size:8524 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:47220 size:9634 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:8719 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:106159 size:11182 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:106159 size:11182 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:23263 size:8524 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:8719 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:106159 size:11182 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:75132 size:10776 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:8719 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:8719 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:106159 size:11182 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:47220 size:9634 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:75132 size:10776 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:23263 size:8524 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-rv10.rm +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:239 size:10388 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:10637 size:1571 flags:0 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.480000 pts:1.480000 pos:110921 size:2049 flags:0 +ret: 0 st: 0 ts:0.788000 flags:0 +ret: 0 st: 0 dts:1.000000 pts:1.000000 pos:72737 size:1639 flags:0 +ret: 0 st: 0 ts:-0.317000 flags:1 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:10637 size:1571 flags:0 +ret: 0 st:-1 ts:2.576668 flags:0 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:152304 size:2007 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.480000 pts:1.480000 pos:110921 size:2049 flags:0 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:0.520000 pts:0.520000 pos:41239 size:1400 flags:0 +ret: 0 st: 0 ts:-0.741000 flags:1 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:10637 size:1571 flags:0 +ret: 0 st:-1 ts:2.153336 flags:0 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:152304 size:2007 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.000000 pts:1.000000 pos:72737 size:1639 flags:0 +ret: 0 st: 0 ts:-0.058000 flags:0 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:10637 size:1571 flags:0 +ret: 0 st: 0 ts:2.836000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:152304 size:2007 flags:0 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:152304 size:2007 flags:0 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.520000 pts:0.520000 pos:41239 size:1400 flags:0 +ret: 0 st: 0 ts:-0.482000 flags:0 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:10637 size:1571 flags:0 +ret: 0 st: 0 ts:2.413000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:152304 size:2007 flags:0 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.480000 pts:1.480000 pos:110921 size:2049 flags:0 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:10637 size:1571 flags:0 +ret: 0 st: 0 ts:-0.905000 flags:0 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:10637 size:1571 flags:0 +ret: 0 st: 0 ts:1.989000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:152304 size:2007 flags:0 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:1.000000 pts:1.000000 pos:72737 size:1639 flags:0 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:10637 size:1571 flags:0 +ret: 0 st: 0 ts:2.672000 flags:0 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:152304 size:2007 flags:0 +ret: 0 st: 0 ts:1.566000 flags:1 +ret: 0 st: 0 dts:1.480000 pts:1.480000 pos:110921 size:2049 flags:0 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.520000 pts:0.520000 pos:41239 size:1400 flags:0 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:10637 size:1571 flags:0 +---------------- +tests/data/a-rv20.rm +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:239 size:9361 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:9610 size:1084 flags:0 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.480000 pts:1.480000 pos:95674 size:1900 flags:0 +ret: 0 st: 0 ts:0.788000 flags:0 +ret: 0 st: 0 dts:1.000000 pts:1.000000 pos:63237 size:1657 flags:0 +ret: 0 st: 0 ts:-0.317000 flags:1 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:9610 size:1084 flags:0 +ret: 0 st:-1 ts:2.576668 flags:0 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:130821 size:1914 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.480000 pts:1.480000 pos:95674 size:1900 flags:0 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:0.520000 pts:0.520000 pos:35101 size:1447 flags:0 +ret: 0 st: 0 ts:-0.741000 flags:1 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:9610 size:1084 flags:0 +ret: 0 st:-1 ts:2.153336 flags:0 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:130821 size:1914 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.000000 pts:1.000000 pos:63237 size:1657 flags:0 +ret: 0 st: 0 ts:-0.058000 flags:0 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:9610 size:1084 flags:0 +ret: 0 st: 0 ts:2.836000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:130821 size:1914 flags:0 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:130821 size:1914 flags:0 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.520000 pts:0.520000 pos:35101 size:1447 flags:0 +ret: 0 st: 0 ts:-0.482000 flags:0 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:9610 size:1084 flags:0 +ret: 0 st: 0 ts:2.413000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:130821 size:1914 flags:0 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.480000 pts:1.480000 pos:95674 size:1900 flags:0 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:9610 size:1084 flags:0 +ret: 0 st: 0 ts:-0.905000 flags:0 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:9610 size:1084 flags:0 +ret: 0 st: 0 ts:1.989000 flags:1 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:130821 size:1914 flags:0 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:1.000000 pts:1.000000 pos:63237 size:1657 flags:0 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:9610 size:1084 flags:0 +ret: 0 st: 0 ts:2.672000 flags:0 +ret: 0 st: 0 dts:1.960000 pts:1.960000 pos:130821 size:1914 flags:0 +ret: 0 st: 0 ts:1.566000 flags:1 +ret: 0 st: 0 dts:1.480000 pts:1.480000 pos:95674 size:1900 flags:0 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.520000 pts:0.520000 pos:35101 size:1447 flags:0 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:9610 size:1084 flags:0 +---------------- +tests/data/a-snow.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:2987 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:2987 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:47008 size:3663 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:31774 size:3478 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:47008 size:3663 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:18018 size:3229 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:31774 size:3478 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:2987 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:63544 size:3635 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:63544 size:3635 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:18018 size:3229 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:2987 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:63544 size:3635 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:47008 size:3663 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:2987 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:2987 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:63544 size:3635 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:31774 size:3478 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:47008 size:3663 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:18018 size:3229 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-snow53.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:72476 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:72476 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:1902800 size:78837 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:1239102 size:74994 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:1902800 size:78837 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:605640 size:71059 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:1239102 size:74994 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:72476 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:2585626 size:79731 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:2585626 size:79731 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:605640 size:71059 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:72476 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:2585626 size:79731 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:1902800 size:78837 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:72476 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:72476 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:2585626 size:79731 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:1239102 size:74994 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:1902800 size:78837 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:605640 size:71059 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-svq1.mov +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:22272 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:22272 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:518616 size:25696 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:327196 size:23556 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:518616 size:25696 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:157248 size:21908 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:327196 size:23556 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:22272 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:724244 size:25912 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:724244 size:25912 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:157248 size:21908 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:22272 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:724244 size:25912 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:518616 size:25696 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:22272 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:22272 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:724244 size:25912 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:327196 size:23556 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:518616 size:25696 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:157248 size:21908 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-wmav1.asf +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:3.286000 pts:3.286000 pos:3604 size:743 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st: 0 ts:0.788000 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st: 0 ts:-0.317000 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st:-1 ts:2.576668 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st: 0 ts:-0.741000 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st:-1 ts:2.153336 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st: 0 ts:-0.058000 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st: 0 ts:2.836000 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st: 0 ts:-0.482000 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st: 0 ts:2.413000 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st: 0 ts:-0.905000 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st: 0 ts:1.989000 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st: 0 ts:2.672000 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st: 0 ts:1.566000 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:404 size:743 flags:1 +---------------- +tests/data/a-wmav2.asf +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:3.286000 pts:3.286000 pos:3644 size:743 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st: 0 ts:0.788000 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st: 0 ts:-0.317000 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st:-1 ts:2.576668 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st: 0 ts:-0.741000 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st:-1 ts:2.153336 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st: 0 ts:-0.058000 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st: 0 ts:2.836000 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st: 0 ts:-0.482000 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st: 0 ts:2.413000 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st: 0 ts:-0.905000 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st: 0 ts:1.989000 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st: 0 ts:2.672000 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st: 0 ts:1.566000 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:444 size:743 flags:1 +---------------- +tests/data/a-wmv1.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8990 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8990 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:83754 size:11099 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:54770 size:9931 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:83754 size:11099 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:29806 size:8796 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:54770 size:9931 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8990 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:115824 size:11487 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:115824 size:11487 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:29806 size:8796 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8990 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:115824 size:11487 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:83754 size:11099 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8990 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5660 size:8990 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:115824 size:11487 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:54770 size:9931 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:83754 size:11099 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:29806 size:8796 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/a-wmv2.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5664 size:8917 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5664 size:8917 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:83802 size:11170 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:54584 size:9989 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:83802 size:11170 flags:1 +ret: 0 st: 0 ts:0.360000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:29644 size:8839 flags:1 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:54584 size:9989 flags:1 +ret: 0 st: 0 ts:-0.040000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5664 size:8917 flags:1 +ret: 0 st: 0 ts:2.840000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:116070 size:11554 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:116070 size:11554 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:29644 size:8839 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5664 size:8917 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:116070 size:11554 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:83802 size:11170 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5664 size:8917 flags:1 +ret: 0 st: 0 ts:-0.920000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:5664 size:8917 flags:1 +ret: 0 st: 0 ts:2.000000 flags:1 +ret: 0 st: 0 dts:1.920000 pts:1.920000 pos:116070 size:11554 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:54584 size:9989 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret: 0 st: 0 ts:1.560000 flags:1 +ret: 0 st: 0 dts:1.440000 pts:1.440000 pos:83802 size:11170 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:29644 size:8839 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/b-libav.aif +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:54 size:4096 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret:-5 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:167120 size:0 flags:1 +ret: 0 st: 0 ts:0.788345 flags:0 +ret: 0 st: 0 dts:0.788345 pts:0.788345 pos:69586 size:4096 flags:1 +ret: 0 st: 0 ts:-0.317506 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:89142 size:0 flags:1 +ret: 0 st:-1 ts:2.576668 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:227316 size:0 flags:1 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:129782 size:0 flags:1 +ret: 0 st: 0 ts:0.365011 flags:0 +ret: 0 st: 0 dts:0.365011 pts:0.365011 pos:32248 size:4096 flags:1 +ret: 0 st: 0 ts:-0.740839 flags:1 +ret: 0 st: 0 dts:-0.740839 pts:-0.740839 pos:65016 size:4096 flags:1 +ret: 0 st:-1 ts:2.153336 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:189978 size:0 flags:1 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:92444 size:0 flags:1 +ret: 0 st: 0 ts:-0.058322 flags:0 +ret:-5 +ret: 0 st: 0 ts:2.835828 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:250174 size:0 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:152640 size:0 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.624172 pts:0.624172 pos:55106 size:4096 flags:1 +ret: 0 st: 0 ts:-0.481655 flags:0 +ret: 0 st: 0 dts:-0.481655 pts:-0.481655 pos:87874 size:1268 flags:1 +ret: 0 st: 0 ts:2.412494 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:212836 size:0 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:115302 size:0 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.200839 pts:0.200839 pos:17768 size:4096 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:-0.904989 pts:-0.904989 pos:50536 size:4096 flags:1 +ret: 0 st: 0 ts:1.989184 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:175500 size:0 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.883333 pts:0.883333 pos:77964 size:4096 flags:1 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:89142 size:0 flags:1 +ret: 0 st: 0 ts:2.671678 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:235696 size:0 flags:1 +ret: 0 st: 0 ts:1.565850 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:138162 size:0 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.460000 pts:0.460000 pos:40626 size:4096 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:-0.645828 pts:-0.645828 pos:73394 size:4096 flags:1 +---------------- +tests/data/b-libav.al +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:1024 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:1.486077 pts:1.486077 pos:32768 size:1024 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.894150 pts:1.894150 pos:41766 size:1024 flags:1 +ret: 0 st: 0 ts:0.788345 flags:0 +ret: 0 st: 0 dts:0.788345 pts:0.788345 pos:17383 size:1024 flags:1 +ret: 0 st: 0 ts:-0.317506 flags:1 +ret:-5 +ret: 0 st:-1 ts:2.576668 flags:0 +ret:-5 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.470839 pts:1.470839 pos:32432 size:1024 flags:1 +ret: 0 st: 0 ts:0.364989 flags:0 +ret: 0 st: 0 dts:0.364989 pts:0.364989 pos:8048 size:1024 flags:1 +ret: 0 st: 0 ts:-0.740816 flags:1 +ret: 0 st: 0 dts:1.851066 pts:1.851066 pos:40816 size:1024 flags:1 +ret: 0 st:-1 ts:2.153336 flags:0 +ret:-5 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.047483 pts:1.047483 pos:23097 size:1024 flags:1 +ret: 0 st: 0 ts:-0.058322 flags:0 +ret:-5 +ret: 0 st: 0 ts:2.835828 flags:1 +ret:-5 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.730023 pts:1.730023 pos:38147 size:1024 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.624172 pts:0.624172 pos:13763 size:1024 flags:1 +ret: 0 st: 0 ts:-0.481678 flags:0 +ret:-5 +ret: 0 st: 0 ts:2.412517 flags:1 +ret:-5 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.306667 pts:1.306667 pos:28812 size:1024 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.200816 pts:0.200816 pos:4428 size:1024 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:1.686893 pts:1.686893 pos:37196 size:1024 flags:1 +ret: 0 st: 0 ts:1.989161 flags:1 +ret: 0 st: 0 dts:1.989161 pts:1.989161 pos:43861 size:683 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.883356 pts:0.883356 pos:19478 size:1024 flags:1 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret:-5 +ret: 0 st: 0 ts:2.671655 flags:0 +ret:-5 +ret: 0 st: 0 ts:1.565850 flags:1 +ret: 0 st: 0 dts:1.565850 pts:1.565850 pos:34527 size:1024 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.460000 pts:0.460000 pos:10143 size:1024 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:1.946077 pts:1.946077 pos:42911 size:1024 flags:1 +---------------- +tests/data/b-libav.asf +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 1 dts:3.544000 pts:3.544000 pos:150975 size:209 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +ret: 0 st: 0 ts:0.788000 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +ret: 0 st: 0 ts:-0.317000 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +ret: 0 st: 1 ts:2.577000 flags:0 +ret: 0 st: 1 dts:3.100000 pts:3.100000 pos:29375 size:208 flags:1 +ret: 0 st: 1 ts:1.471000 flags:1 +ret: 0 st: 1 dts:3.100000 pts:3.100000 pos:29375 size:208 flags:1 +ret: 0 st:-1 ts:0.365002 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +ret: 0 st:-1 ts:-0.740831 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +ret: 0 st: 0 ts:2.153000 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +ret: 0 st: 0 ts:1.048000 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +ret: 0 st: 1 ts:-0.058000 flags:0 +ret: 0 st: 1 dts:3.100000 pts:3.100000 pos:29375 size:208 flags:1 +ret: 0 st: 1 ts:2.836000 flags:1 +ret: 0 st: 1 dts:3.100000 pts:3.100000 pos:29375 size:208 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +ret: 0 st: 0 ts:-0.482000 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +ret: 0 st: 0 ts:2.413000 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +ret: 0 st: 1 ts:1.307000 flags:0 +ret: 0 st: 1 dts:3.100000 pts:3.100000 pos:29375 size:208 flags:1 +ret: 0 st: 1 ts:0.201000 flags:1 +ret: 0 st: 1 dts:3.100000 pts:3.100000 pos:29375 size:208 flags:1 +ret: 0 st:-1 ts:-0.904994 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +ret: 0 st:-1 ts:1.989173 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +ret: 0 st: 0 ts:0.883000 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +ret: 0 st: 0 ts:-0.222000 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +ret: 0 st: 1 ts:2.672000 flags:0 +ret: 0 st: 1 dts:3.100000 pts:3.100000 pos:29375 size:208 flags:1 +ret: 0 st: 1 ts:1.566000 flags:1 +ret: 0 st: 1 dts:3.100000 pts:3.100000 pos:29375 size:208 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:3.100000 pts:3.100000 pos:575 size:28874 flags:1 +---------------- +tests/data/b-libav.au +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:24 size:4096 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret:-5 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:167090 size:0 flags:1 +ret: 0 st: 0 ts:0.788345 flags:0 +ret: 0 st: 0 dts:0.788345 pts:0.788345 pos:69556 size:4096 flags:1 +ret: 0 st: 0 ts:-0.317506 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:89112 size:0 flags:1 +ret: 0 st:-1 ts:2.576668 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:227286 size:0 flags:1 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:129752 size:0 flags:1 +ret: 0 st: 0 ts:0.365011 flags:0 +ret: 0 st: 0 dts:0.365011 pts:0.365011 pos:32218 size:4096 flags:1 +ret: 0 st: 0 ts:-0.740839 flags:1 +ret: 0 st: 0 dts:-0.740839 pts:-0.740839 pos:64986 size:4096 flags:1 +ret: 0 st:-1 ts:2.153336 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:189948 size:0 flags:1 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:92414 size:0 flags:1 +ret: 0 st: 0 ts:-0.058322 flags:0 +ret:-5 +ret: 0 st: 0 ts:2.835828 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:250144 size:0 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:152610 size:0 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.624172 pts:0.624172 pos:55076 size:4096 flags:1 +ret: 0 st: 0 ts:-0.481655 flags:0 +ret: 0 st: 0 dts:-0.481655 pts:-0.481655 pos:87844 size:1268 flags:1 +ret: 0 st: 0 ts:2.412494 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:212806 size:0 flags:1 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:115272 size:0 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.200839 pts:0.200839 pos:17738 size:4096 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:-0.904989 pts:-0.904989 pos:50506 size:4096 flags:1 +ret: 0 st: 0 ts:1.989184 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:175470 size:0 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.883333 pts:0.883333 pos:77934 size:4096 flags:1 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:89112 size:0 flags:1 +ret: 0 st: 0 ts:2.671678 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:235666 size:0 flags:1 +ret: 0 st: 0 ts:1.565850 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:138132 size:0 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.460000 pts:0.460000 pos:40596 size:4096 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:-0.645828 pts:-0.645828 pos:73364 size:4096 flags:1 +---------------- +tests/data/b-libav.avi +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:9908 size:28118 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:9908 size:28118 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:310948 size:27927 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:310948 size:27927 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st: 1 ts:2.586122 flags:0 +ret: 0 st: 1 ts:1.462857 flags:1 +ret: 0 st: 1 dts:0.992653 pts:0.992653 pos:339102 size:209 flags:1 +ret: 0 st:-1 ts:0.365002 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:158912 size:27442 flags:1 +ret:-1 st:-1 ts:-0.740831 flags:1 +ret:-1 st: 0 ts:2.160000 flags:0 +ret: 0 st: 0 ts:1.040000 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:310948 size:27927 flags:1 +ret: 0 st: 1 ts:-0.052245 flags:0 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:38034 size:208 flags:1 +ret: 0 st: 1 ts:2.847347 flags:1 +ret: 0 st: 1 dts:0.992653 pts:0.992653 pos:339102 size:209 flags:1 +ret:-1 st:-1 ts:1.730004 flags:0 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:158912 size:27442 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:9908 size:28118 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:310948 size:27927 flags:1 +ret:-1 st: 1 ts:1.306122 flags:0 +ret: 0 st: 1 ts:0.208980 flags:1 +ret: 0 st: 1 dts:0.208980 pts:0.208980 pos:92738 size:209 flags:1 +ret: 0 st:-1 ts:-0.904994 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:9908 size:28118 flags:1 +ret: 0 st:-1 ts:1.989173 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:310948 size:27927 flags:1 +ret: 0 st: 0 ts:0.880000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:310948 size:27927 flags:1 +ret:-1 st: 0 ts:-0.240000 flags:1 +ret:-1 st: 1 ts:2.664490 flags:0 +ret: 0 st: 1 ts:1.567347 flags:1 +ret: 0 st: 1 dts:0.992653 pts:0.992653 pos:339102 size:209 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:158912 size:27442 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/b-libav.dv +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.800000 pts:0.800000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:-0.320000 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +ret: 0 st: 1 ts:2.576667 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:-1 size:144000 flags:1 +ret: 0 st: 1 ts:1.470833 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:0.365002 flags:0 +ret: 0 st: 0 dts:0.360000 pts:0.360000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:-0.740831 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:2.160000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:1.040000 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:-1 size:144000 flags:1 +ret: 0 st: 1 ts:-0.058333 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +ret: 0 st: 1 ts:2.835833 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.640000 pts:0.640000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:-1 size:144000 flags:1 +ret: 0 st: 1 ts:1.306667 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:-1 size:144000 flags:1 +ret: 0 st: 1 ts:0.200833 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:-0.904994 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:1.989173 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:0.880000 flags:0 +ret: 0 st: 0 dts:0.880000 pts:0.880000 pos:-1 size:144000 flags:1 +ret: 0 st: 0 ts:-0.240000 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +ret: 0 st: 1 ts:2.671667 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:-1 size:144000 flags:1 +ret: 0 st: 1 ts:1.565833 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:-1 size:144000 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:144000 flags:1 +---------------- +tests/data/b-libav.ffm +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:8192 size:24795 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret:-11 +ret: 0 st:-1 ts:1.894167 flags:1 +ret:-11 +ret: 0 st: 0 ts:0.788334 flags:0 +ret: 0 st: 0 dts:0.840000 pts:0.840000 pos:311296 size:12220 flags:0 +ret: 0 st: 0 ts:-0.317499 flags:1 +ret:-11 +ret: 0 st: 1 ts:2.576668 flags:0 +ret:-11 +ret: 0 st: 1 ts:1.470835 flags:1 +ret:-11 +ret: 0 st:-1 ts:0.365002 flags:0 +ret:-11 +ret: 0 st:-1 ts:-0.740831 flags:1 +ret:-11 +ret: 0 st: 0 ts:2.153336 flags:0 +ret:-11 +ret: 0 st: 0 ts:1.047503 flags:1 +ret:-11 +ret: 0 st: 1 ts:-0.058330 flags:0 +ret:-11 +ret: 0 st: 1 ts:2.835837 flags:1 +ret:-11 +ret: 0 st:-1 ts:1.730004 flags:0 +ret:-11 +ret: 0 st:-1 ts:0.624171 flags:1 +ret:-11 +ret: 0 st: 0 ts:-0.481662 flags:0 +ret:-11 +ret: 0 st: 0 ts:2.412505 flags:1 +ret:-11 +ret: 0 st: 1 ts:1.306672 flags:0 +ret:-11 +ret: 0 st: 1 ts:0.200839 flags:1 +ret:-11 +ret: 0 st:-1 ts:-0.904994 flags:0 +ret:-11 +ret: 0 st:-1 ts:1.989173 flags:1 +ret:-11 +ret: 0 st: 0 ts:0.883340 flags:0 +ret:-11 +ret: 0 st: 0 ts:-0.222493 flags:1 +ret:-11 +ret: 0 st: 1 ts:2.671674 flags:0 +ret:-11 +ret: 0 st: 1 ts:1.565841 flags:1 +ret:-11 +ret: 0 st:-1 ts:0.460008 flags:0 +ret:-11 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret:-11 +---------------- +tests/data/b-libav.flv +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:31385 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:31385 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:150381 size:30541 flags:1 +ret: 0 st: 0 ts:0.788000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:304714 size:31115 flags:1 +ret:-1 st: 0 ts:-0.317000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:304714 size:31115 flags:1 +ret: 0 st: 0 ts:0.365000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:150381 size:30541 flags:1 +ret:-1 st: 0 ts:-0.741000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:304714 size:31115 flags:1 +ret: 0 st: 0 ts:-0.058000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:31385 flags:1 +ret: 0 st: 0 ts:2.836000 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:304714 size:31115 flags:1 +ret:-1 st:-1 ts:1.730004 flags:0 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:150381 size:30541 flags:1 +ret: 0 st: 0 ts:-0.482000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:31385 flags:1 +ret: 0 st: 0 ts:2.413000 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:304714 size:31115 flags:1 +ret:-1 st:-1 ts:1.306672 flags:0 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:31385 flags:1 +ret: 0 st: 0 ts:-0.905000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:199 size:31385 flags:1 +ret: 0 st: 0 ts:1.989000 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:304714 size:31115 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:304714 size:31115 flags:1 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.672000 flags:0 +ret: 0 st: 0 ts:1.566000 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:304714 size:31115 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:150381 size:30541 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/b-libav.gif +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:2906382 flags:1 +ret:-1 st:-1 ts:-1.000000 flags:0 +ret:-1 st:-1 ts:1.894167 flags:1 +ret:-1 st: 0 ts:0.800000 flags:0 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret:-1 st:-1 ts:1.470835 flags:1 +ret:-1 st: 0 ts:0.360000 flags:0 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret:-1 st:-1 ts:1.047503 flags:1 +ret:-1 st: 0 ts:-0.040000 flags:0 +ret:-1 st: 0 ts:2.840000 flags:1 +ret:-1 st:-1 ts:1.730004 flags:0 +ret:-1 st:-1 ts:0.624171 flags:1 +ret:-1 st: 0 ts:-0.480000 flags:0 +ret:-1 st: 0 ts:2.400000 flags:1 +ret:-1 st:-1 ts:1.306672 flags:0 +ret:-1 st:-1 ts:0.200839 flags:1 +ret:-1 st: 0 ts:-0.920000 flags:0 +ret:-1 st: 0 ts:2.000000 flags:1 +ret:-1 st:-1 ts:0.883340 flags:0 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret:-1 st: 0 ts:1.560000 flags:1 +ret:-1 st:-1 ts:0.460008 flags:0 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/b-libav.gxf +ret: 0 st: 0 dts:0.000000 pts:-184467440737095520.000000 pos:748 size:55568 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:56348 size:65536 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:759676 size:54948 flags:1 +ret: 0 st: 0 ts:0.780000 flags:0 +ret: 0 st: 0 dts:0.800000 pts:-184467440737095520.000000 pos:670060 size:23072 flags:0 +ret: 0 st: 0 ts:-0.320000 flags:1 +ret: 0 st: 0 dts:0.000000 pts:-184467440737095520.000000 pos:748 size:55568 flags:1 +ret: 0 st: 1 ts:2.580000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:759676 size:54948 flags:1 +ret: 0 st: 1 ts:1.480000 flags:1 +ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:759676 size:54948 flags:1 +ret: 0 st:-1 ts:0.365002 flags:0 +ret: 0 st: 0 dts:0.360000 pts:-184467440737095520.000000 pos:306784 size:24028 flags:0 +ret: 0 st:-1 ts:-0.740831 flags:1 +ret: 0 st: 0 dts:0.000000 pts:-184467440737095520.000000 pos:748 size:55568 flags:1 +ret: 0 st: 0 ts:2.160000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:759676 size:54948 flags:1 +ret: 0 st: 0 ts:1.040000 flags:1 +ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:759676 size:54948 flags:1 +ret: 0 st: 1 ts:-0.060000 flags:0 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:56348 size:65536 flags:1 +ret: 0 st: 1 ts:2.840000 flags:1 +ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:759676 size:54948 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:759676 size:54948 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.600000 pts:-184467440737095520.000000 pos:483508 size:23568 flags:0 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:56348 size:65536 flags:1 +ret: 0 st: 0 ts:2.420000 flags:1 +ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:759676 size:54948 flags:1 +ret: 0 st: 1 ts:1.300000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:759676 size:54948 flags:1 +ret: 0 st: 1 ts:0.200000 flags:1 +ret: 0 st: 0 dts:0.200000 pts:-184467440737095520.000000 pos:213328 size:21332 flags:0 +ret: 0 st:-1 ts:-0.904994 flags:0 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:56348 size:65536 flags:1 +ret: 0 st:-1 ts:1.989173 flags:1 +ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:759676 size:54948 flags:1 +ret: 0 st: 0 ts:0.880000 flags:0 +ret: 0 st: 0 dts:0.880000 pts:-184467440737095520.000000 pos:716384 size:20464 flags:0 +ret: 0 st: 0 ts:-0.220000 flags:1 +ret: 0 st: 0 dts:0.000000 pts:-184467440737095520.000000 pos:748 size:55568 flags:1 +ret: 0 st: 1 ts:2.680000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:759676 size:54948 flags:1 +ret: 0 st: 1 ts:1.560000 flags:1 +ret: 0 st: 0 dts:0.960000 pts:-184467440737095520.000000 pos:759676 size:54948 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:-184467440737095520.000000 pos:376324 size:54324 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:0.000000 pts:-184467440737095520.000000 pos:748 size:55568 flags:1 +---------------- +tests/data/b-libav.mkv +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:469 size:28118 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:469 size:28118 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:469 size:28118 flags:1 +ret: 0 st: 0 ts:0.788000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:469 size:28118 flags:1 +ret: 0 st: 0 ts:-0.317000 flags:1 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:28595 size:208 flags:1 +ret: 0 st: 1 ts:2.577000 flags:0 +ret: 0 st: 1 dts:0.026000 pts:0.026000 pos:28810 size:209 flags:1 +ret: 0 st: 1 ts:1.471000 flags:1 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:29026 size:10153 flags:0 +ret: 0 st:-1 ts:0.365002 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:469 size:28118 flags:1 +ret: 0 st:-1 ts:-0.740831 flags:1 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:28595 size:208 flags:1 +ret: 0 st: 0 ts:2.153000 flags:0 +ret: 0 st: 1 dts:0.026000 pts:0.026000 pos:28810 size:209 flags:1 +ret: 0 st: 0 ts:1.048000 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:469 size:28118 flags:1 +ret: 0 st: 1 ts:-0.058000 flags:0 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:28595 size:208 flags:1 +ret: 0 st: 1 ts:2.836000 flags:1 +ret: 0 st: 1 dts:0.026000 pts:0.026000 pos:28810 size:209 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:29026 size:10153 flags:0 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:469 size:28118 flags:1 +ret: 0 st: 0 ts:-0.482000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:469 size:28118 flags:1 +ret: 0 st: 0 ts:2.413000 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:469 size:28118 flags:1 +ret: 0 st: 1 ts:1.307000 flags:0 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:28595 size:208 flags:1 +ret: 0 st: 1 ts:0.201000 flags:1 +ret: 0 st: 1 dts:0.026000 pts:0.026000 pos:28810 size:209 flags:1 +ret: 0 st:-1 ts:-0.904994 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:469 size:28118 flags:1 +ret: 0 st:-1 ts:1.989173 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:469 size:28118 flags:1 +ret: 0 st: 0 ts:0.883000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:469 size:28118 flags:1 +ret: 0 st: 0 ts:-0.222000 flags:1 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:28595 size:208 flags:1 +ret: 0 st: 1 ts:2.672000 flags:0 +ret: 0 st: 1 dts:0.026000 pts:0.026000 pos:28810 size:209 flags:1 +ret: 0 st: 1 ts:1.566000 flags:1 +ret: 0 st: 0 dts:0.040000 pts:0.040000 pos:29026 size:10153 flags:0 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:469 size:28118 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:28595 size:208 flags:1 +---------------- +tests/data/b-libav.mmf +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:4096 flags:1 +ret:-1 st:-1 ts:-1.000000 flags:0 +ret:-1 st:-1 ts:1.894167 flags:1 +ret:-1 st: 0 ts:0.788345 flags:0 +ret:-1 st: 0 ts:-0.317506 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret:-1 st:-1 ts:1.470835 flags:1 +ret:-1 st: 0 ts:0.365011 flags:0 +ret:-1 st: 0 ts:-0.740839 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret:-1 st:-1 ts:1.047503 flags:1 +ret:-1 st: 0 ts:-0.058322 flags:0 +ret:-1 st: 0 ts:2.835828 flags:1 +ret:-1 st:-1 ts:1.730004 flags:0 +ret:-1 st:-1 ts:0.624171 flags:1 +ret:-1 st: 0 ts:-0.481655 flags:0 +ret:-1 st: 0 ts:2.412494 flags:1 +ret:-1 st:-1 ts:1.306672 flags:0 +ret:-1 st:-1 ts:0.200839 flags:1 +ret:-1 st: 0 ts:-0.904989 flags:0 +ret:-1 st: 0 ts:1.989184 flags:1 +ret:-1 st:-1 ts:0.883340 flags:0 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.671678 flags:0 +ret:-1 st: 0 ts:1.565850 flags:1 +ret:-1 st:-1 ts:0.460008 flags:0 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/b-libav.mov +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:28088 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:28088 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 1 dts:0.952018 pts:0.952018 pos:334735 size:512 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:335247 size:27897 flags:1 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st: 1 ts:2.576667 flags:0 +ret: 0 st: 1 ts:1.470839 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:335247 size:27897 flags:1 +ret: 0 st:-1 ts:0.365002 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:166272 size:27412 flags:1 +ret:-1 st:-1 ts:-0.740831 flags:1 +ret:-1 st: 0 ts:2.160000 flags:0 +ret: 0 st: 0 ts:1.040000 flags:1 +ret: 0 st: 1 dts:0.952018 pts:0.952018 pos:334735 size:512 flags:1 +ret: 0 st: 1 ts:-0.058322 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:28088 flags:1 +ret: 0 st: 1 ts:2.835828 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:335247 size:27897 flags:1 +ret:-1 st:-1 ts:1.730004 flags:0 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 1 dts:0.476009 pts:0.476009 pos:165760 size:512 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:28088 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 1 dts:0.952018 pts:0.952018 pos:334735 size:512 flags:1 +ret:-1 st: 1 ts:1.306667 flags:0 +ret: 0 st: 1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:28088 flags:1 +ret: 0 st:-1 ts:-0.904994 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:36 size:28088 flags:1 +ret: 0 st:-1 ts:1.989173 flags:1 +ret: 0 st: 1 dts:0.952018 pts:0.952018 pos:334735 size:512 flags:1 +ret: 0 st: 0 ts:0.880000 flags:0 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:335247 size:27897 flags:1 +ret:-1 st: 0 ts:-0.240000 flags:1 +ret:-1 st: 1 ts:2.671678 flags:0 +ret: 0 st: 1 ts:1.565850 flags:1 +ret: 0 st: 0 dts:0.960000 pts:0.960000 pos:335247 size:27897 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:166272 size:27412 flags:1 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/b-libav.mpg +ret: 0 st: 1 dts:0.500000 pts:0.500000 pos:-1 size:208 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 1 dts:0.500000 pts:0.500000 pos:-1 size:208 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 1 dts:1.022444 pts:1.022444 pos:-1 size:209 flags:1 +ret: 0 st: 0 ts:0.788333 flags:0 +ret: 0 st: 1 dts:0.761222 pts:0.761222 pos:-1 size:209 flags:1 +ret: 0 st: 0 ts:-0.317500 flags:1 +ret: 0 st: 1 dts:0.500000 pts:0.500000 pos:-1 size:208 flags:1 +ret: 0 st: 1 ts:2.576667 flags:0 +ret: 0 st: 1 dts:1.283678 pts:1.283678 pos:-1 size:209 flags:1 +ret: 0 st: 1 ts:1.470833 flags:1 +ret: 0 st: 1 dts:1.283678 pts:1.283678 pos:-1 size:209 flags:1 +ret: 0 st:-1 ts:0.365002 flags:0 +ret: 0 st: 1 dts:0.500000 pts:0.500000 pos:-1 size:208 flags:1 +ret: 0 st:-1 ts:-0.740831 flags:1 +ret: 0 st: 1 dts:0.500000 pts:0.500000 pos:-1 size:208 flags:1 +ret: 0 st: 0 ts:2.153333 flags:0 +ret: 0 st: 1 dts:1.022444 pts:1.022444 pos:-1 size:209 flags:1 +ret: 0 st: 0 ts:1.047500 flags:1 +ret: 0 st: 0 dts:1.020000 pts:1.060000 pos:-1 size:14482 flags:0 +ret: 0 st: 1 ts:-0.058333 flags:0 +ret: 0 st: 1 dts:0.500000 pts:0.500000 pos:-1 size:208 flags:1 +ret: 0 st: 1 ts:2.835833 flags:1 +ret: 0 st: 1 dts:1.283678 pts:1.283678 pos:-1 size:209 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 1 dts:1.022444 pts:1.022444 pos:-1 size:209 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.620000 pts:0.660000 pos:-1 size:15270 flags:0 +ret: 0 st: 0 ts:-0.481667 flags:0 +ret: 0 st: 1 dts:0.500000 pts:0.500000 pos:-1 size:208 flags:1 +ret: 0 st: 0 ts:2.412500 flags:1 +ret: 0 st: 1 dts:1.022444 pts:1.022444 pos:-1 size:209 flags:1 +ret: 0 st: 1 ts:1.306667 flags:0 +ret: 0 st: 1 dts:1.283678 pts:1.283678 pos:-1 size:209 flags:1 +ret: 0 st: 1 ts:0.200844 flags:1 +ret: 0 st: 1 dts:0.500000 pts:0.500000 pos:-1 size:208 flags:1 +ret: 0 st:-1 ts:-0.904994 flags:0 +ret: 0 st: 1 dts:0.500000 pts:0.500000 pos:-1 size:208 flags:1 +ret: 0 st:-1 ts:1.989173 flags:1 +ret: 0 st: 1 dts:1.022444 pts:1.022444 pos:-1 size:209 flags:1 +ret: 0 st: 0 ts:0.883344 flags:0 +ret: 0 st: 0 dts:0.900000 pts:0.940000 pos:-1 size:13124 flags:0 +ret: 0 st: 0 ts:-0.222489 flags:1 +ret: 0 st: 1 dts:0.500000 pts:0.500000 pos:-1 size:208 flags:1 +ret: 0 st: 1 ts:2.671678 flags:0 +ret: 0 st: 1 dts:1.283678 pts:1.283678 pos:-1 size:209 flags:1 +ret: 0 st: 1 ts:1.565844 flags:1 +ret: 0 st: 1 dts:1.283678 pts:1.283678 pos:-1 size:209 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.500000 pts:0.540000 pos:-1 size:16335 flags:0 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 1 dts:0.500000 pts:0.500000 pos:-1 size:208 flags:1 +---------------- +tests/data/b-libav.nut +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:279 size:28088 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:279 size:28088 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149091 size:27412 flags:1 +ret: 0 st: 0 ts:0.800000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149091 size:27412 flags:1 +ret: 0 st: 0 ts:-0.320000 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:279 size:28088 flags:1 +ret: 0 st: 1 ts:2.586122 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149091 size:27412 flags:1 +ret: 0 st: 1 ts:1.462857 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149091 size:27412 flags:1 +ret: 0 st:-1 ts:0.365002 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:279 size:28088 flags:1 +ret: 0 st:-1 ts:-0.740831 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:279 size:28088 flags:1 +ret: 0 st: 0 ts:2.160000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149091 size:27412 flags:1 +ret: 0 st: 0 ts:1.040000 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149091 size:27412 flags:1 +ret: 0 st: 1 ts:-0.052245 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:279 size:28088 flags:1 +ret: 0 st: 1 ts:2.847347 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149091 size:27412 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149091 size:27412 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149091 size:27412 flags:1 +ret: 0 st: 0 ts:-0.480000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:279 size:28088 flags:1 +ret: 0 st: 0 ts:2.400000 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149091 size:27412 flags:1 +ret: 0 st: 1 ts:1.306122 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149091 size:27412 flags:1 +ret: 0 st: 1 ts:0.208980 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:279 size:28088 flags:1 +ret: 0 st:-1 ts:-0.904994 flags:0 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:279 size:28088 flags:1 +ret: 0 st:-1 ts:1.989173 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149091 size:27412 flags:1 +ret: 0 st: 0 ts:0.880000 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149091 size:27412 flags:1 +ret: 0 st: 0 ts:-0.240000 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:279 size:28088 flags:1 +ret: 0 st: 1 ts:2.664490 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149091 size:27412 flags:1 +ret: 0 st: 1 ts:1.567347 flags:1 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149091 size:27412 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.480000 pts:0.480000 pos:149091 size:27412 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:279 size:28088 flags:1 +---------------- +tests/data/b-libav.ogg +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:2352 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:-1 size:2331 flags:1 +ret:-1 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 ts:0.788345 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:-1 size:2251 flags:1 +ret: 0 st: 0 ts:-0.317506 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:-1 size:2280 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret:-1 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 ts:0.365011 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:-1 size:2331 flags:1 +ret: 0 st: 0 ts:-0.740839 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:-1 size:2280 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret:-1 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 ts:-0.058322 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:-1 size:2331 flags:1 +ret:-1 st: 0 ts:2.835828 flags:1 +ret:-1 st:-1 ts:1.730004 flags:0 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:-1 size:2292 flags:1 +ret: 0 st: 0 ts:-0.481655 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:-1 size:2331 flags:1 +ret:-1 st: 0 ts:2.412494 flags:1 +ret:-1 st:-1 ts:1.306672 flags:0 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:-1 size:2280 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:-1 size:2331 flags:1 +ret:-1 st: 0 ts:1.989184 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:-1 size:2370 flags:1 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:-1 size:2280 flags:1 +ret:-1 st: 0 ts:2.671678 flags:0 +ret:-1 st: 0 ts:1.565850 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:-1 size:2292 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:-209146758205323.718750 pts:-209146758205323.718750 pos:-1 size:2280 flags:1 +---------------- +tests/data/b-pbmpipe.pbm +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:317075 flags:1 +ret:-1 st:-1 ts:-1.000000 flags:0 +ret:-1 st:-1 ts:1.894167 flags:1 +ret:-1 st: 0 ts:0.800000 flags:0 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret:-1 st:-1 ts:1.470835 flags:1 +ret:-1 st: 0 ts:0.360000 flags:0 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret:-1 st:-1 ts:1.047503 flags:1 +ret:-1 st: 0 ts:-0.040000 flags:0 +ret:-1 st: 0 ts:2.840000 flags:1 +ret:-1 st:-1 ts:1.730004 flags:0 +ret:-1 st:-1 ts:0.624171 flags:1 +ret:-1 st: 0 ts:-0.480000 flags:0 +ret:-1 st: 0 ts:2.400000 flags:1 +ret:-1 st:-1 ts:1.306672 flags:0 +ret:-1 st:-1 ts:0.200839 flags:1 +ret:-1 st: 0 ts:-0.920000 flags:0 +ret:-1 st: 0 ts:2.000000 flags:1 +ret:-1 st:-1 ts:0.883340 flags:0 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret:-1 st: 0 ts:1.560000 flags:1 +ret:-1 st:-1 ts:0.460008 flags:0 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/b-pgmpipe.pgm +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:2534775 flags:1 +ret:-1 st:-1 ts:-1.000000 flags:0 +ret:-1 st:-1 ts:1.894167 flags:1 +ret:-1 st: 0 ts:0.800000 flags:0 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret:-1 st:-1 ts:1.470835 flags:1 +ret:-1 st: 0 ts:0.360000 flags:0 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret:-1 st:-1 ts:1.047503 flags:1 +ret:-1 st: 0 ts:-0.040000 flags:0 +ret:-1 st: 0 ts:2.840000 flags:1 +ret:-1 st:-1 ts:1.730004 flags:0 +ret:-1 st:-1 ts:0.624171 flags:1 +ret:-1 st: 0 ts:-0.480000 flags:0 +ret:-1 st: 0 ts:2.400000 flags:1 +ret:-1 st:-1 ts:1.306672 flags:0 +ret:-1 st:-1 ts:0.200839 flags:1 +ret:-1 st: 0 ts:-0.920000 flags:0 +ret:-1 st: 0 ts:2.000000 flags:1 +ret:-1 st:-1 ts:0.883340 flags:0 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret:-1 st: 0 ts:1.560000 flags:1 +ret:-1 st:-1 ts:0.460008 flags:0 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/b-ppmpipe.ppm +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:-1 size:7603575 flags:1 +ret:-1 st:-1 ts:-1.000000 flags:0 +ret:-1 st:-1 ts:1.894167 flags:1 +ret:-1 st: 0 ts:0.800000 flags:0 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret:-1 st:-1 ts:1.470835 flags:1 +ret:-1 st: 0 ts:0.360000 flags:0 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret:-1 st:-1 ts:1.047503 flags:1 +ret:-1 st: 0 ts:-0.040000 flags:0 +ret:-1 st: 0 ts:2.840000 flags:1 +ret:-1 st:-1 ts:1.730004 flags:0 +ret:-1 st:-1 ts:0.624171 flags:1 +ret:-1 st: 0 ts:-0.480000 flags:0 +ret:-1 st: 0 ts:2.400000 flags:1 +ret:-1 st:-1 ts:1.306672 flags:0 +ret:-1 st:-1 ts:0.200839 flags:1 +ret:-1 st: 0 ts:-0.920000 flags:0 +ret:-1 st: 0 ts:2.000000 flags:1 +ret:-1 st:-1 ts:0.883340 flags:0 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret:-1 st: 0 ts:1.560000 flags:1 +ret:-1 st:-1 ts:0.460008 flags:0 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/b-libav.rm +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:398 size:31393 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:31794 size:278 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 1 dts:0.975000 pts:0.975000 pos:355101 size:278 flags:1 +ret: 0 st: 0 ts:0.788000 flags:0 +ret: 0 st: 1 dts:0.975000 pts:0.975000 pos:355101 size:278 flags:1 +ret: 0 st: 0 ts:-0.317000 flags:1 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:31794 size:278 flags:1 +ret: 0 st: 1 ts:2.577000 flags:0 +ret:-5 +ret: 0 st: 1 ts:1.471000 flags:1 +ret:-5 +ret: 0 st:-1 ts:0.365002 flags:0 +ret: 0 st: 1 dts:0.487000 pts:0.487000 pos:191482 size:278 flags:1 +ret: 0 st:-1 ts:-0.740831 flags:1 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:31794 size:278 flags:1 +ret: 0 st: 0 ts:2.153000 flags:0 +ret: 0 st: 1 dts:0.975000 pts:0.975000 pos:355101 size:278 flags:1 +ret: 0 st: 0 ts:1.048000 flags:1 +ret: 0 st: 1 dts:0.975000 pts:0.975000 pos:355101 size:278 flags:1 +ret: 0 st: 1 ts:-0.058000 flags:0 +ret: 0 st: 1 dts:0.069000 pts:0.069000 pos:42717 size:278 flags:1 +ret: 0 st: 1 ts:2.836000 flags:1 +ret:-5 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 1 dts:0.975000 pts:0.975000 pos:355101 size:278 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 1 dts:0.487000 pts:0.487000 pos:191482 size:278 flags:1 +ret: 0 st: 0 ts:-0.482000 flags:0 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:31794 size:278 flags:1 +ret: 0 st: 0 ts:2.413000 flags:1 +ret: 0 st: 1 dts:0.975000 pts:0.975000 pos:355101 size:278 flags:1 +ret: 0 st: 1 ts:1.307000 flags:0 +ret:-5 +ret: 0 st: 1 ts:0.201000 flags:1 +ret: 0 st: 1 dts:0.208000 pts:0.208000 pos:90745 size:278 flags:1 +ret: 0 st:-1 ts:-0.904994 flags:0 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:31794 size:278 flags:1 +ret: 0 st:-1 ts:1.989173 flags:1 +ret: 0 st: 1 dts:0.975000 pts:0.975000 pos:355101 size:278 flags:1 +ret: 0 st: 0 ts:0.883000 flags:0 +ret: 0 st: 1 dts:0.975000 pts:0.975000 pos:355101 size:278 flags:1 +ret: 0 st: 0 ts:-0.222000 flags:1 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:31794 size:278 flags:1 +ret: 0 st: 1 ts:2.672000 flags:0 +ret:-5 +ret: 0 st: 1 ts:1.566000 flags:1 +ret:-5 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 1 dts:0.487000 pts:0.487000 pos:191482 size:278 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:31794 size:278 flags:1 +---------------- +tests/data/b-libav.swf +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:65 size:31385 flags:0 +ret:-1 st:-1 ts:-1.000000 flags:0 +ret:-1 st:-1 ts:1.894167 flags:1 +ret:-1 st: 0 ts:0.800000 flags:0 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret:-1 st:-1 ts:1.470835 flags:1 +ret:-1 st: 0 ts:0.360000 flags:0 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret:-1 st:-1 ts:1.047503 flags:1 +ret:-1 st: 0 ts:-0.040000 flags:0 +ret:-1 st: 0 ts:2.840000 flags:1 +ret:-1 st:-1 ts:1.730004 flags:0 +ret:-1 st:-1 ts:0.624171 flags:1 +ret:-1 st: 0 ts:-0.480000 flags:0 +ret:-1 st: 0 ts:2.400000 flags:1 +ret:-1 st:-1 ts:1.306672 flags:0 +ret:-1 st:-1 ts:0.200839 flags:1 +ret:-1 st: 0 ts:-0.920000 flags:0 +ret:-1 st: 0 ts:2.000000 flags:1 +ret:-1 st:-1 ts:0.883340 flags:0 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret:-1 st: 0 ts:1.560000 flags:1 +ret:-1 st:-1 ts:0.460008 flags:0 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/b-libav.ts +ret: 0 st: 0 dts:-0.040000 pts:0.000000 pos:-1 size:24921 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:-1 size:22036 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1 +ret: 0 st: 0 ts:0.788333 flags:0 +ret: 0 st: 0 dts:0.760000 pts:0.800000 pos:-1 size:12351 flags:1 +ret: 0 st: 0 ts:-0.317500 flags:1 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:-1 size:22036 flags:1 +ret: 0 st: 1 ts:2.576667 flags:0 +ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1 +ret: 0 st: 1 ts:1.470833 flags:1 +ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1 +ret: 0 st:-1 ts:0.365002 flags:0 +ret: 0 st: 1 dts:0.000000 pts:0.000000 pos:-1 size:208 flags:1 +ret: 0 st:-1 ts:-0.740831 flags:1 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:-1 size:22036 flags:1 +ret: 0 st: 0 ts:2.153333 flags:0 +ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1 +ret: 0 st: 0 ts:1.047500 flags:1 +ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1 +ret: 0 st: 1 ts:-0.058333 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:-1 size:22036 flags:1 +ret: 0 st: 1 ts:2.835833 flags:1 +ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.600000 pts:0.640000 pos:-1 size:14233 flags:1 +ret: 0 st: 0 ts:-0.481667 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:-1 size:22036 flags:1 +ret: 0 st: 0 ts:2.412500 flags:1 +ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1 +ret: 0 st: 1 ts:1.306667 flags:0 +ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1 +ret: 0 st: 1 ts:0.200844 flags:1 +ret: 0 st: 0 dts:0.200000 pts:0.240000 pos:-1 size:13938 flags:1 +ret: 0 st:-1 ts:-0.904994 flags:0 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:-1 size:22036 flags:1 +ret: 0 st:-1 ts:1.989173 flags:1 +ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1 +ret: 0 st: 0 ts:0.883344 flags:0 +ret: 0 st: 0 dts:0.920000 pts:-102481911520608.625000 pos:-1 size:7258 flags:1 +ret: 0 st: 0 ts:-0.222489 flags:1 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:-1 size:22036 flags:1 +ret: 0 st: 1 ts:2.671678 flags:0 +ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1 +ret: 0 st: 1 ts:1.565844 flags:1 +ret: 0 st: 1 dts:0.731433 pts:0.731433 pos:-1 size:209 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.440000 pts:0.480000 pos:-1 size:21317 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:0.000000 pts:-102481911520608.625000 pos:-1 size:22036 flags:1 +---------------- +tests/data/b-libav.ul +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:0 size:1024 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret: 0 st: 0 dts:1.486077 pts:1.486077 pos:32768 size:1024 flags:1 +ret: 0 st:-1 ts:1.894167 flags:1 +ret: 0 st: 0 dts:1.894150 pts:1.894150 pos:41766 size:1024 flags:1 +ret: 0 st: 0 ts:0.788345 flags:0 +ret: 0 st: 0 dts:0.788345 pts:0.788345 pos:17383 size:1024 flags:1 +ret: 0 st: 0 ts:-0.317506 flags:1 +ret:-5 +ret: 0 st:-1 ts:2.576668 flags:0 +ret:-5 +ret: 0 st:-1 ts:1.470835 flags:1 +ret: 0 st: 0 dts:1.470839 pts:1.470839 pos:32432 size:1024 flags:1 +ret: 0 st: 0 ts:0.364989 flags:0 +ret: 0 st: 0 dts:0.364989 pts:0.364989 pos:8048 size:1024 flags:1 +ret: 0 st: 0 ts:-0.740816 flags:1 +ret: 0 st: 0 dts:1.851066 pts:1.851066 pos:40816 size:1024 flags:1 +ret: 0 st:-1 ts:2.153336 flags:0 +ret:-5 +ret: 0 st:-1 ts:1.047503 flags:1 +ret: 0 st: 0 dts:1.047483 pts:1.047483 pos:23097 size:1024 flags:1 +ret: 0 st: 0 ts:-0.058322 flags:0 +ret:-5 +ret: 0 st: 0 ts:2.835828 flags:1 +ret:-5 +ret: 0 st:-1 ts:1.730004 flags:0 +ret: 0 st: 0 dts:1.730023 pts:1.730023 pos:38147 size:1024 flags:1 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.624172 pts:0.624172 pos:13763 size:1024 flags:1 +ret: 0 st: 0 ts:-0.481678 flags:0 +ret:-5 +ret: 0 st: 0 ts:2.412517 flags:1 +ret:-5 +ret: 0 st:-1 ts:1.306672 flags:0 +ret: 0 st: 0 dts:1.306667 pts:1.306667 pos:28812 size:1024 flags:1 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.200816 pts:0.200816 pos:4428 size:1024 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:1.686893 pts:1.686893 pos:37196 size:1024 flags:1 +ret: 0 st: 0 ts:1.989161 flags:1 +ret: 0 st: 0 dts:1.989161 pts:1.989161 pos:43861 size:683 flags:1 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.883356 pts:0.883356 pos:19478 size:1024 flags:1 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret:-5 +ret: 0 st: 0 ts:2.671655 flags:0 +ret:-5 +ret: 0 st: 0 ts:1.565850 flags:1 +ret: 0 st: 0 dts:1.565850 pts:1.565850 pos:34527 size:1024 flags:1 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.460000 pts:0.460000 pos:10143 size:1024 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:1.946077 pts:1.946077 pos:42911 size:1024 flags:1 +---------------- +tests/data/b-libav.voc +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:32 size:512 flags:1 +ret:-1 st:-1 ts:-1.000000 flags:0 +ret:-1 st:-1 ts:1.894167 flags:1 +ret:-1 st: 0 ts:0.788333 flags:0 +ret:-1 st: 0 ts:-0.317500 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret:-1 st:-1 ts:1.470835 flags:1 +ret:-1 st: 0 ts:0.365000 flags:0 +ret:-1 st: 0 ts:-0.740833 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret:-1 st:-1 ts:1.047503 flags:1 +ret:-1 st: 0 ts:-0.058333 flags:0 +ret:-1 st: 0 ts:2.835833 flags:1 +ret:-1 st:-1 ts:1.730004 flags:0 +ret:-1 st:-1 ts:0.624171 flags:1 +ret:-1 st: 0 ts:-0.481667 flags:0 +ret:-1 st: 0 ts:2.412500 flags:1 +ret:-1 st:-1 ts:1.306672 flags:0 +ret:-1 st:-1 ts:0.200839 flags:1 +ret:-1 st: 0 ts:-0.904989 flags:0 +ret:-1 st: 0 ts:1.989178 flags:1 +ret:-1 st:-1 ts:0.883340 flags:0 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.671678 flags:0 +ret:-1 st: 0 ts:1.565844 flags:1 +ret:-1 st:-1 ts:0.460008 flags:0 +ret:-1 st:-1 ts:-0.645825 flags:1 +---------------- +tests/data/b-libav.wav +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:44 size:4096 flags:1 +ret: 0 st:-1 ts:-1.000000 flags:0 +ret:-5 +ret: 0 st:-1 ts:1.894167 flags:1 +ret:-5 +ret: 0 st: 0 ts:0.788345 flags:0 +ret: 0 st: 0 dts:0.788345 pts:0.788345 pos:69576 size:4096 flags:1 +ret: 0 st: 0 ts:-0.317506 flags:1 +ret:-5 +ret: 0 st:-1 ts:2.576668 flags:0 +ret:-5 +ret: 0 st:-1 ts:1.470835 flags:1 +ret:-5 +ret: 0 st: 0 ts:0.365011 flags:0 +ret: 0 st: 0 dts:0.365011 pts:0.365011 pos:32238 size:4096 flags:1 +ret: 0 st: 0 ts:-0.740839 flags:1 +ret: 0 st: 0 dts:-0.740839 pts:-0.740839 pos:65006 size:4096 flags:1 +ret: 0 st:-1 ts:2.153336 flags:0 +ret:-5 +ret: 0 st:-1 ts:1.047503 flags:1 +ret:-5 +ret: 0 st: 0 ts:-0.058322 flags:0 +ret:-5 +ret: 0 st: 0 ts:2.835828 flags:1 +ret:-5 +ret: 0 st:-1 ts:1.730004 flags:0 +ret:-5 +ret: 0 st:-1 ts:0.624171 flags:1 +ret: 0 st: 0 dts:0.624172 pts:0.624172 pos:55096 size:4096 flags:1 +ret: 0 st: 0 ts:-0.481655 flags:0 +ret: 0 st: 0 dts:-0.481655 pts:-0.481655 pos:87864 size:1268 flags:1 +ret: 0 st: 0 ts:2.412494 flags:1 +ret:-5 +ret: 0 st:-1 ts:1.306672 flags:0 +ret:-5 +ret: 0 st:-1 ts:0.200839 flags:1 +ret: 0 st: 0 dts:0.200839 pts:0.200839 pos:17758 size:4096 flags:1 +ret: 0 st: 0 ts:-0.904989 flags:0 +ret: 0 st: 0 dts:-0.904989 pts:-0.904989 pos:50526 size:4096 flags:1 +ret: 0 st: 0 ts:1.989184 flags:1 +ret:-5 +ret: 0 st:-1 ts:0.883340 flags:0 +ret: 0 st: 0 dts:0.883333 pts:0.883333 pos:77954 size:4096 flags:1 +ret: 0 st:-1 ts:-0.222493 flags:1 +ret:-5 +ret: 0 st: 0 ts:2.671678 flags:0 +ret:-5 +ret: 0 st: 0 ts:1.565850 flags:1 +ret:-5 +ret: 0 st:-1 ts:0.460008 flags:0 +ret: 0 st: 0 dts:0.460000 pts:0.460000 pos:40616 size:4096 flags:1 +ret: 0 st:-1 ts:-0.645825 flags:1 +ret: 0 st: 0 dts:-0.645828 pts:-0.645828 pos:73384 size:4096 flags:1 +---------------- +tests/data/b-libav.y4m +ret: 0 st: 0 dts:0.000000 pts:0.000000 pos:66 size:152064 flags:1 +ret:-1 st:-1 ts:-1.000000 flags:0 +ret:-1 st:-1 ts:1.894167 flags:1 +ret:-1 st: 0 ts:0.800000 flags:0 +ret:-1 st: 0 ts:-0.320000 flags:1 +ret:-1 st:-1 ts:2.576668 flags:0 +ret:-1 st:-1 ts:1.470835 flags:1 +ret:-1 st: 0 ts:0.360000 flags:0 +ret:-1 st: 0 ts:-0.760000 flags:1 +ret:-1 st:-1 ts:2.153336 flags:0 +ret:-1 st:-1 ts:1.047503 flags:1 +ret:-1 st: 0 ts:-0.040000 flags:0 +ret:-1 st: 0 ts:2.840000 flags:1 +ret:-1 st:-1 ts:1.730004 flags:0 +ret:-1 st:-1 ts:0.624171 flags:1 +ret:-1 st: 0 ts:-0.480000 flags:0 +ret:-1 st: 0 ts:2.400000 flags:1 +ret:-1 st:-1 ts:1.306672 flags:0 +ret:-1 st:-1 ts:0.200839 flags:1 +ret:-1 st: 0 ts:-0.920000 flags:0 +ret:-1 st: 0 ts:2.000000 flags:1 +ret:-1 st:-1 ts:0.883340 flags:0 +ret:-1 st:-1 ts:-0.222493 flags:1 +ret:-1 st: 0 ts:2.680000 flags:0 +ret:-1 st: 0 ts:1.560000 flags:1 +ret:-1 st:-1 ts:0.460008 flags:0 +ret:-1 st:-1 ts:-0.645825 flags:1 diff --git a/contrib/ffmpeg/tests/seek_test.c b/contrib/ffmpeg/tests/seek_test.c index e17409439..b1a2c939a 100644 --- a/contrib/ffmpeg/tests/seek_test.c +++ b/contrib/ffmpeg/tests/seek_test.c @@ -23,12 +23,18 @@ #include "avformat.h" +#undef exit + int main(int argc, char **argv) { const char *filename; AVFormatContext *ic; int i, ret, stream_id; int64_t timestamp; + AVFormatParameters params, *ap= ¶ms; + memset(ap, 0, sizeof(params)); + ap->channels=1; + ap->sample_rate= 22050; /* initialize libavcodec, and register all codecs and formats */ av_register_all(); @@ -48,9 +54,9 @@ int main(int argc, char **argv) exit(1); } - ret = av_open_input_file(&ic, filename, NULL, 0, NULL); + ret = av_open_input_file(&ic, filename, NULL, 0, ap); if (ret < 0) { - fprintf(stderr, "cant open %s\n", filename); + fprintf(stderr, "cannot open %s\n", filename); exit(1); } @@ -70,7 +76,7 @@ int main(int argc, char **argv) printf("ret:%2d", ret); if(ret>=0){ st= ic->streams[pkt.stream_index]; - printf(" st:%2d dts:%f pts:%f pos:%Ld size:%d flags:%d", pkt.stream_index, pkt.dts*av_q2d(st->time_base), pkt.pts*av_q2d(st->time_base), pkt.pos, pkt.size, pkt.flags); + printf(" st:%2d dts:%f pts:%f pos:%" PRId64 " size:%d flags:%d", pkt.stream_index, pkt.dts*av_q2d(st->time_base), pkt.pts*av_q2d(st->time_base), pkt.pos, pkt.size, pkt.flags); } printf("\n"); } diff --git a/contrib/ffmpeg/tests/seek_test.sh b/contrib/ffmpeg/tests/seek_test.sh index eeac747b1..7132a2590 100755 --- a/contrib/ffmpeg/tests/seek_test.sh +++ b/contrib/ffmpeg/tests/seek_test.sh @@ -1,25 +1,27 @@ #!/bin/sh -#feel free to clean this up ive made no attempt to write this overly portable ... -datadir="./data" +LC_ALL=C +export LC_ALL + +datadir="tests/data" logfile="$datadir/seek.regression" reffile="$1" -list=`ls data/a-* data/b-* | sort` -rm $logfile +list=`grep '^tests/data/[ab]-' "$reffile"` +rm -f $logfile for i in $list ; do - echo ---------------- >>$logfile - echo $i >>$logfile - ./seek_test $i >> $logfile + echo ---------------- >> $logfile + echo $i >> $logfile + tests/seek_test $i >> $logfile done -if diff -u "$logfile" "$reffile" ; then +if diff -u "$reffile" "$logfile" ; then echo - echo Regression test succeeded. + echo seek regression test: success exit 0 else echo - echo Regression test: Error. + echo seek regression test: error exit 1 fi diff --git a/contrib/ffmpeg/tests/server-regression.sh b/contrib/ffmpeg/tests/server-regression.sh index 1f561aa54..8e764410f 100755 --- a/contrib/ffmpeg/tests/server-regression.sh +++ b/contrib/ffmpeg/tests/server-regression.sh @@ -1,30 +1,23 @@ -#!/bin/bash -# Even in the 21st century some diffs are not supporting -u. -diff -u $0 $0 > /dev/null 2>&1 -if [ $? -eq 0 ]; then - diff_cmd="diff -u" -else - diff_cmd="diff" -fi +#!/bin/sh # Make sure that the data directory exists -mkdir -p data +mkdir -p tests/data -#perl -e 'chomp($wd = `pwd`); print map { s!data/!!; "\nFile $wd/data/$_\n\n\n" } @ARGV' data/a* >> data/test.conf -#perl -e 'chomp($wd = `pwd`); print map { s!data/!!; "\nFile $wd/data/$_\n\n\n" } @ARGV' data/a* >> data/test.conf +#perl -e 'chomp($wd = `pwd`); print map { s!tests/data/!!; "\nFile $wd/tests/data/$_\n\n\n" } @ARGV' tests/data/a* >> tests/data/test.conf +#perl -e 'chomp($wd = `pwd`); print map { s!tests/data/!!; "\nFile $wd/tests/data/$_\n\n\n" } @ARGV' tests/data/a* >> tests/data/test.conf -FILES=`sed -n 's/^[^#]*.*/\1/p' test.conf | grep -v html` +FILES=`sed -n 's/^[^#]*.*/\1/p' $2 | grep -v html` -rm -f feed1.ffm -../ffserver -d -f test.conf 2> /dev/null & +rm -f tests/feed1.ffm +./ffserver -d -f tests/test.conf 2> /dev/null & FFSERVER_PID=$! sleep 2 echo "Waiting for feeds to startup..." -../ffmpeg -loop_input -flags +bitexact -dct fastint -idct simple -y -f pgmyuv -i vsynth1/%02d.pgm http://localhost:9999/feed1.ffm 2> /dev/null & +./ffmpeg -loop_input -flags +bitexact -dct fastint -idct simple -y -f pgmyuv -i tests/vsynth1/%02d.pgm http://localhost:9999/feed1.ffm 2> /dev/null & FFMPEG_PID=$! sleep 5 ( - cd data || exit $? + cd tests/data || exit $? rm -f ff-*; WGET_OPTIONS="--user-agent=NSPlayer -q --proxy=off -e verbose=off -e server_response=off" for file in $FILES; do @@ -42,8 +35,8 @@ sleep 5 kill $FFMPEG_PID kill $FFSERVER_PID wait > /dev/null 2>&1 -rm -f feed1.ffm -if $diff_cmd data/ffserver.regression "$1" ; then +rm -f tests/feed1.ffm +if diff -u tests/data/ffserver.regression "$1" ; then echo echo Server regression test succeeded. exit 0 diff --git a/contrib/ffmpeg/tests/tiny_psnr.c b/contrib/ffmpeg/tests/tiny_psnr.c index d8bce2b7b..31a7a1b5e 100644 --- a/contrib/ffmpeg/tests/tiny_psnr.c +++ b/contrib/ffmpeg/tests/tiny_psnr.c @@ -1,20 +1,21 @@ /* * Copyright (c) 2003 Michael Niedermayer * - * This library is free software; you can redistribute it and/or + * This file is part of FFmpeg. + * + * FFmpeg 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 of the License, or (at your option) any later version. + * version 2.1 of the License, or (at your option) any later version. * - * This library is distributed in the hope that it will be useful, + * FFmpeg 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 this library; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * */ #include @@ -48,7 +49,8 @@ uint64_t exp16_table[21]={ 195360063, 582360139072LL, }; -#if 1 + +#if 0 // 16.16 fixpoint exp() static unsigned int exp16(unsigned int a){ int i; @@ -61,6 +63,8 @@ static unsigned int exp16(unsigned int a){ return out; } +#endif + // 16.16 fixpoint log() static int64_t log16(uint64_t a){ int i; @@ -79,7 +83,6 @@ static int64_t log16(uint64_t a){ return out; } -#endif static uint64_t int_sqrt(uint64_t a) { uint64_t ret=0; diff --git a/contrib/ffmpeg/tests/videogen.c b/contrib/ffmpeg/tests/videogen.c index 39d85a26a..226c4dd4f 100644 --- a/contrib/ffmpeg/tests/videogen.c +++ b/contrib/ffmpeg/tests/videogen.c @@ -1,6 +1,6 @@ /* * Generates a synthetic YUV video sequence suitable for codec testing. - * NOTE: no floats are used to guaranty a bit exact output. + * NOTE: No floats are used to guarantee a bit exact output. * * Copyright (c) 2002 Fabrice Bellard * diff --git a/contrib/ffmpeg/tools/build_avopt b/contrib/ffmpeg/tools/build_avopt new file mode 100755 index 000000000..fcf165765 --- /dev/null +++ b/contrib/ffmpeg/tools/build_avopt @@ -0,0 +1,9 @@ +#!/bin/sh +sed 's/unsigned//g' |\ + sed 's/enum//g' |\ + egrep '^ *(int|float|double|AVRational|char *\*) *[a-zA-Z_0-9]* *;' |\ + sed 's/^ *\([^ ]*\)[ *]*\([^;]*\);.*$/{"\2", NULL, OFFSET(\2), FF_OPT_TYPE_\U\1, DEFAULT, \1_MIN, \1_MAX},/' |\ + sed 's/AVRATIONAL_M/INT_M/g'|\ + sed 's/TYPE_AVRATIONAL/TYPE_RATIONAL/g'|\ + sed 's/FLOAT_M/FLT_M/g'|\ + sed 's/FF_OPT_TYPE_CHAR/FF_OPT_TYPE_STRING/g' diff --git a/contrib/ffmpeg/tools/clean-diff b/contrib/ffmpeg/tools/clean-diff new file mode 100755 index 000000000..98e26a79f --- /dev/null +++ b/contrib/ffmpeg/tools/clean-diff @@ -0,0 +1,11 @@ +#!/bin/sh +sed '/^+[^+]/!s/ /TaBBaT/g' |\ + expand -t `seq -s , 9 8 200` |\ + sed 's/TaBBaT/ /g' |\ + sed '/^+[^+]/s/ * $//' |\ + tr -d '\015' |\ + tr '\n' '°' |\ + sed 's/\(@@[^@]*@@°[^@]*\)/\n\1/g' |\ + egrep -v '@@[^@]*@@°(( [^°]*°)|([+-][[:space:]]*°)|(-[[:space:]]*([^°]*)°\+[[:space:]]*\5°))*$' |\ + tr -d '\n' |\ + tr '°' '\n' diff --git a/contrib/ffmpeg/tools/cws2fws.c b/contrib/ffmpeg/tools/cws2fws.c new file mode 100644 index 000000000..aa7d690be --- /dev/null +++ b/contrib/ffmpeg/tools/cws2fws.c @@ -0,0 +1,130 @@ +/* + * cws2fws by Alex Beregszaszi + * This file is placed in the public domain. + * Use the program however you see fit. + * + * This utility converts compressed Macromedia Flash files to uncompressed ones. + */ + +#include +#include +#include +#include +#include +#include + +#ifdef DEBUG +#define dbgprintf printf +#else +#define dbgprintf(...) +#endif + +int main(int argc, char *argv[]) +{ + int fd_in, fd_out, comp_len, uncomp_len, i, last_out; + char buf_in[1024], buf_out[65536]; + z_stream zstream; + struct stat statbuf; + + if (argc < 3) + { + printf("Usage: %s \n", argv[0]); + exit(1); + } + + fd_in = open(argv[1], O_RDONLY); + if (fd_in < 0) + { + perror("Error while opening: "); + exit(1); + } + + fd_out = open(argv[2], O_WRONLY|O_CREAT, 00644); + if (fd_out < 0) + { + perror("Error while opening: "); + close(fd_in); + exit(1); + } + + if (read(fd_in, &buf_in, 8) != 8) + { + printf("Header error\n"); + close(fd_in); + close(fd_out); + exit(1); + } + + if (buf_in[0] != 'C' || buf_in[1] != 'W' || buf_in[2] != 'S') + { + printf("Not a compressed flash file\n"); + exit(1); + } + + fstat(fd_in, &statbuf); + comp_len = statbuf.st_size; + uncomp_len = buf_in[4] | (buf_in[5] << 8) | (buf_in[6] << 16) | (buf_in[7] << 24); + + printf("Compressed size: %d Uncompressed size: %d\n", comp_len-4, uncomp_len-4); + + // write out modified header + buf_in[0] = 'F'; + write(fd_out, &buf_in, 8); + + zstream.zalloc = NULL; + zstream.zfree = NULL; + zstream.opaque = NULL; + inflateInit(&zstream); + + for (i = 0; i < comp_len-8;) + { + int ret, len = read(fd_in, &buf_in, 1024); + + dbgprintf("read %d bytes\n", len); + + last_out = zstream.total_out; + + zstream.next_in = &buf_in[0]; + zstream.avail_in = len; + zstream.next_out = &buf_out[0]; + zstream.avail_out = 65536; + + ret = inflate(&zstream, Z_SYNC_FLUSH); + if (ret != Z_STREAM_END && ret != Z_OK) + { + printf("Error while decompressing: %d\n", ret); + inflateEnd(&zstream); + exit(1); + } + + dbgprintf("a_in: %d t_in: %lu a_out: %d t_out: %lu -- %lu out\n", + zstream.avail_in, zstream.total_in, zstream.avail_out, zstream.total_out, + zstream.total_out-last_out); + + write(fd_out, &buf_out, zstream.total_out-last_out); + + i += len; + + if (ret == Z_STREAM_END || ret == Z_BUF_ERROR) + break; + } + + if (zstream.total_out != uncomp_len-8) + { + printf("Size mismatch (%lu != %d), updating header...\n", + zstream.total_out, uncomp_len-8); + + buf_in[0] = (zstream.total_out+8) & 0xff; + buf_in[1] = ((zstream.total_out+8) >> 8) & 0xff; + buf_in[2] = ((zstream.total_out+8) >> 16) & 0xff; + buf_in[3] = ((zstream.total_out+8) >> 24) & 0xff; + + lseek(fd_out, 4, SEEK_SET); + write(fd_out, &buf_in, 4); + } + + inflateEnd(&zstream); + close(fd_in); + close(fd_out); + return 0; +} diff --git a/contrib/ffmpeg/tools/pktdumper.c b/contrib/ffmpeg/tools/pktdumper.c new file mode 100644 index 000000000..2d5a3b721 --- /dev/null +++ b/contrib/ffmpeg/tools/pktdumper.c @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2005 Francois Revol + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include +#include +#include + +#define PKTFILESUFF "_%08"PRId64"_%02d_%010"PRId64"_%06d_%c.bin" + +#undef strcat + +static int usage(int ret) +{ + fprintf(stderr, "dump (up to maxpkts) AVPackets as they are demuxed by libavformat.\n"); + fprintf(stderr, "each packet is dumped in its own file named like `basename file.ext`_$PKTNUM_$STREAMINDEX_$STAMP_$SIZE_$FLAGS.bin\n"); + fprintf(stderr, "pktdumper [-nw] file [maxpkts]\n"); + fprintf(stderr, "-n\twrite No file at all, only demux.\n"); + fprintf(stderr, "-w\tWait at end of processing instead of quitting.\n"); + return ret; +} + +int main(int argc, char **argv) +{ + char fntemplate[PATH_MAX]; + char pktfilename[PATH_MAX]; + AVFormatContext *fctx; + AVPacket pkt; + int64_t pktnum = 0; + int64_t maxpkts = 0; + int donotquit = 0; + int nowrite = 0; + int err; + + if ((argc > 1) && !strncmp(argv[1], "-", 1)) { + if (strchr(argv[1], 'w')) + donotquit = 1; + if (strchr(argv[1], 'n')) + nowrite = 1; + argv++; + argc--; + } + if (argc < 2) + return usage(1); + if (argc > 2) + maxpkts = atoi(argv[2]); + strncpy(fntemplate, argv[1], PATH_MAX-1); + if (strrchr(argv[1], '/')) + strncpy(fntemplate, strrchr(argv[1], '/')+1, PATH_MAX-1); + if (strrchr(fntemplate, '.')) + *strrchr(fntemplate, '.') = '\0'; + if (strchr(fntemplate, '%')) { + fprintf(stderr, "can't use filenames containing '%%'\n"); + return usage(1); + } + if (strlen(fntemplate) + sizeof(PKTFILESUFF) >= PATH_MAX-1) { + fprintf(stderr, "filename too long\n"); + return usage(1); + } + strcat(fntemplate, PKTFILESUFF); + printf("FNTEMPLATE: '%s'\n", fntemplate); + + // register all file formats + av_register_all(); + + err = av_open_input_file(&fctx, argv[1], NULL, 0, NULL); + if (err < 0) { + fprintf(stderr, "av_open_input_file: error %d\n", err); + return 1; + } + + err = av_find_stream_info(fctx); + if (err < 0) { + fprintf(stderr, "av_find_stream_info: error %d\n", err); + return 1; + } + + av_init_packet(&pkt); + + while ((err = av_read_frame(fctx, &pkt)) >= 0) { + int fd; + snprintf(pktfilename, PATH_MAX-1, fntemplate, pktnum, pkt.stream_index, pkt.pts, pkt.size, (pkt.flags & PKT_FLAG_KEY)?'K':'_'); + printf(PKTFILESUFF"\n", pktnum, pkt.stream_index, pkt.pts, pkt.size, (pkt.flags & PKT_FLAG_KEY)?'K':'_'); + //printf("open(\"%s\")\n", pktfilename); + if (!nowrite) { + fd = open(pktfilename, O_WRONLY|O_CREAT, 0644); + write(fd, pkt.data, pkt.size); + close(fd); + } + pktnum++; + if (maxpkts && (pktnum >= maxpkts)) + break; + } + + while (donotquit) + sleep(60); + + return 0; +} diff --git a/contrib/ffmpeg/tools/qt-faststart.c b/contrib/ffmpeg/tools/qt-faststart.c new file mode 100644 index 000000000..2cbf12b1d --- /dev/null +++ b/contrib/ffmpeg/tools/qt-faststart.c @@ -0,0 +1,311 @@ +/* + * qt-faststart.c, v0.1 + * by Mike Melanson (melanson@pcisys.net) + * This file is placed in the public domain. Use the program however you + * see fit. + * + * This utility rearranges a Quicktime file such that the moov atom + * is in front of the data, thus facilitating network streaming. + * + * Compile this program using: + * make qt-faststart + * Invoke the program with: + * qt-faststart + * + * Notes: Quicktime files can come in many configurations of top-level + * atoms. This utility stipulates that the very last atom in the file needs + * to be a moov atom. When given such a file, this utility will rearrange + * the top-level atoms by shifting the moov atom from the back of the file + * to the front, and patch the chunk offsets along the way. This utility + * presently only operates on uncompressed moov atoms. + */ + +#include +#include +#include + +#ifdef __MINGW32__ +#define fseeko(x,y,z) fseeko64(x,y,z) +#define ftello(x) ftello64(x) +#endif + +#define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1]) +#define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \ + (((uint8_t*)(x))[1] << 16) | \ + (((uint8_t*)(x))[2] << 8) | \ + ((uint8_t*)(x))[3]) +#define BE_64(x) (((uint64_t)(((uint8_t*)(x))[0]) << 56) | \ + ((uint64_t)(((uint8_t*)(x))[1]) << 48) | \ + ((uint64_t)(((uint8_t*)(x))[2]) << 40) | \ + ((uint64_t)(((uint8_t*)(x))[3]) << 32) | \ + ((uint64_t)(((uint8_t*)(x))[4]) << 24) | \ + ((uint64_t)(((uint8_t*)(x))[5]) << 16) | \ + ((uint64_t)(((uint8_t*)(x))[6]) << 8) | \ + ((uint64_t)((uint8_t*)(x))[7])) + +#define BE_FOURCC( ch0, ch1, ch2, ch3 ) \ + ( (uint32_t)(unsigned char)(ch3) | \ + ( (uint32_t)(unsigned char)(ch2) << 8 ) | \ + ( (uint32_t)(unsigned char)(ch1) << 16 ) | \ + ( (uint32_t)(unsigned char)(ch0) << 24 ) ) + +#define QT_ATOM BE_FOURCC +/* top level atoms */ +#define FREE_ATOM QT_ATOM('f', 'r', 'e', 'e') +#define JUNK_ATOM QT_ATOM('j', 'u', 'n', 'k') +#define MDAT_ATOM QT_ATOM('m', 'd', 'a', 't') +#define MOOV_ATOM QT_ATOM('m', 'o', 'o', 'v') +#define PNOT_ATOM QT_ATOM('p', 'n', 'o', 't') +#define SKIP_ATOM QT_ATOM('s', 'k', 'i', 'p') +#define WIDE_ATOM QT_ATOM('w', 'i', 'd', 'e') +#define PICT_ATOM QT_ATOM('P', 'I', 'C', 'T') +#define FTYP_ATOM QT_ATOM('f', 't', 'y', 'p') + +#define CMOV_ATOM QT_ATOM('c', 'm', 'o', 'v') +#define STCO_ATOM QT_ATOM('s', 't', 'c', 'o') +#define CO64_ATOM QT_ATOM('c', 'o', '6', '4') + +#define ATOM_PREAMBLE_SIZE 8 +#define COPY_BUFFER_SIZE 1024 + +int main(int argc, char *argv[]) +{ + FILE *infile; + FILE *outfile; + unsigned char atom_bytes[ATOM_PREAMBLE_SIZE]; + uint32_t atom_type = 0; + uint64_t atom_size = 0; + uint64_t last_offset; + unsigned char *moov_atom; + unsigned char *ftyp_atom = 0; + uint64_t moov_atom_size; + uint64_t ftyp_atom_size = 0; + uint64_t i, j; + uint32_t offset_count; + uint64_t current_offset; + uint64_t start_offset = 0; + unsigned char copy_buffer[COPY_BUFFER_SIZE]; + int bytes_to_copy; + + if (argc != 3) { + printf ("Usage: qt-faststart \n"); + return 0; + } + + infile = fopen(argv[1], "rb"); + if (!infile) { + perror(argv[1]); + return 1; + } + + /* traverse through the atoms in the file to make sure that 'moov' is + * at the end */ + while (!feof(infile)) { + if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) { + break; + } + atom_size = (uint32_t)BE_32(&atom_bytes[0]); + atom_type = BE_32(&atom_bytes[4]); + + if ((atom_type != FREE_ATOM) && + (atom_type != JUNK_ATOM) && + (atom_type != MDAT_ATOM) && + (atom_type != MOOV_ATOM) && + (atom_type != PNOT_ATOM) && + (atom_type != SKIP_ATOM) && + (atom_type != WIDE_ATOM) && + (atom_type != PICT_ATOM) && + (atom_type != FTYP_ATOM)) { + printf ("encountered non-QT top-level atom (is this a Quicktime file?)\n"); + break; + } + + /* keep ftyp atom */ + if (atom_type == FTYP_ATOM) { + ftyp_atom_size = atom_size; + ftyp_atom = malloc(ftyp_atom_size); + if (!ftyp_atom) { + printf ("could not allocate 0x%llX byte for ftyp atom\n", + atom_size); + fclose(infile); + return 1; + } + fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR); + if (fread(ftyp_atom, atom_size, 1, infile) != 1) { + perror(argv[1]); + free(ftyp_atom); + fclose(infile); + return 1; + } + start_offset = ftello(infile); + continue; + } + + /* 64-bit special case */ + if (atom_size == 1) { + if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) { + break; + } + atom_size = BE_64(&atom_bytes[0]); + fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE * 2, SEEK_CUR); + } else { + fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE, SEEK_CUR); + } + } + + if (atom_type != MOOV_ATOM) { + printf ("last atom in file was not a moov atom\n"); + fclose(infile); + return 0; + } + + /* moov atom was, in fact, the last atom in the chunk; load the whole + * moov atom */ + fseeko(infile, -atom_size, SEEK_END); + last_offset = ftello(infile); + moov_atom_size = atom_size; + moov_atom = malloc(moov_atom_size); + if (!moov_atom) { + printf ("could not allocate 0x%llX byte for moov atom\n", + atom_size); + fclose(infile); + return 1; + } + if (fread(moov_atom, atom_size, 1, infile) != 1) { + perror(argv[1]); + free(moov_atom); + fclose(infile); + return 1; + } + + /* this utility does not support compressed atoms yet, so disqualify + * files with compressed QT atoms */ + if (BE_32(&moov_atom[12]) == CMOV_ATOM) { + printf ("this utility does not support compressed moov atoms yet\n"); + free(moov_atom); + fclose(infile); + return 1; + } + + /* close; will be re-opened later */ + fclose(infile); + + /* crawl through the moov chunk in search of stco or co64 atoms */ + for (i = 4; i < moov_atom_size - 4; i++) { + atom_type = BE_32(&moov_atom[i]); + if (atom_type == STCO_ATOM) { + printf (" patching stco atom...\n"); + atom_size = BE_32(&moov_atom[i - 4]); + if (i + atom_size - 4 > moov_atom_size) { + printf (" bad atom size\n"); + free(moov_atom); + return 1; + } + offset_count = BE_32(&moov_atom[i + 8]); + for (j = 0; j < offset_count; j++) { + current_offset = BE_32(&moov_atom[i + 12 + j * 4]); + current_offset += moov_atom_size; + moov_atom[i + 12 + j * 4 + 0] = (current_offset >> 24) & 0xFF; + moov_atom[i + 12 + j * 4 + 1] = (current_offset >> 16) & 0xFF; + moov_atom[i + 12 + j * 4 + 2] = (current_offset >> 8) & 0xFF; + moov_atom[i + 12 + j * 4 + 3] = (current_offset >> 0) & 0xFF; + } + i += atom_size - 4; + } else if (atom_type == CO64_ATOM) { + printf (" patching co64 atom...\n"); + atom_size = BE_32(&moov_atom[i - 4]); + if (i + atom_size - 4 > moov_atom_size) { + printf (" bad atom size\n"); + free(moov_atom); + return 1; + } + offset_count = BE_32(&moov_atom[i + 8]); + for (j = 0; j < offset_count; j++) { + current_offset = BE_64(&moov_atom[i + 12 + j * 8]); + current_offset += moov_atom_size; + moov_atom[i + 12 + j * 8 + 0] = (current_offset >> 56) & 0xFF; + moov_atom[i + 12 + j * 8 + 1] = (current_offset >> 48) & 0xFF; + moov_atom[i + 12 + j * 8 + 2] = (current_offset >> 40) & 0xFF; + moov_atom[i + 12 + j * 8 + 3] = (current_offset >> 32) & 0xFF; + moov_atom[i + 12 + j * 8 + 4] = (current_offset >> 24) & 0xFF; + moov_atom[i + 12 + j * 8 + 5] = (current_offset >> 16) & 0xFF; + moov_atom[i + 12 + j * 8 + 6] = (current_offset >> 8) & 0xFF; + moov_atom[i + 12 + j * 8 + 7] = (current_offset >> 0) & 0xFF; + } + i += atom_size - 4; + } + } + + /* re-open the input file and open the output file */ + infile = fopen(argv[1], "rb"); + if (!infile) { + perror(argv[1]); + free(moov_atom); + return 1; + } + + if (start_offset > 0) { /* seek after ftyp atom */ + fseeko(infile, start_offset, SEEK_SET); + last_offset -= start_offset; + } + + outfile = fopen(argv[2], "wb"); + if (!outfile) { + perror(argv[2]); + fclose(outfile); + free(moov_atom); + return 1; + } + + /* dump the same ftyp atom */ + if (ftyp_atom_size > 0) { + printf (" writing ftyp atom...\n"); + if (fwrite(ftyp_atom, ftyp_atom_size, 1, outfile) != 1) { + perror(argv[2]); + goto error_out; + } + } + + /* dump the new moov atom */ + printf (" writing moov atom...\n"); + if (fwrite(moov_atom, moov_atom_size, 1, outfile) != 1) { + perror(argv[2]); + goto error_out; + } + + /* copy the remainder of the infile, from offset 0 -> last_offset - 1 */ + printf (" copying rest of file...\n"); + while (last_offset) { + if (last_offset > COPY_BUFFER_SIZE) + bytes_to_copy = COPY_BUFFER_SIZE; + else + bytes_to_copy = last_offset; + + if (fread(copy_buffer, bytes_to_copy, 1, infile) != 1) { + perror(argv[1]); + goto error_out; + } + if (fwrite(copy_buffer, bytes_to_copy, 1, outfile) != 1) { + perror(argv[2]); + goto error_out; + } + + last_offset -= bytes_to_copy; + } + + fclose(infile); + fclose(outfile); + free(moov_atom); + if (ftyp_atom_size > 0) + free(ftyp_atom); + + return 0; + +error_out: + fclose(infile); + fclose(outfile); + free(moov_atom); + if (ftyp_atom_size > 0) + free(ftyp_atom); + return 1; +} diff --git a/contrib/ffmpeg/tools/trasher.c b/contrib/ffmpeg/tools/trasher.c new file mode 100644 index 000000000..9e1961f85 --- /dev/null +++ b/contrib/ffmpeg/tools/trasher.c @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2007 Michael Niedermayer + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include + +int main(int argc, char** argv) +{ + FILE *f; + int count, maxburst, length; + + if (argc < 4){ + printf("USAGE: trasher \n"); + return 1; + } + + f= fopen(argv[1], "rb+"); + if (!f){ + perror(argv[1]); + return 2; + } + count= atoi(argv[2]); + maxburst= atoi(argv[3]); + + srand (time (0)); + + fseek(f, 0, SEEK_END); + length= ftell(f); + fseek(f, 0, SEEK_SET); + + while(count--){ + int burst= 1 + random() * (uint64_t) (abs(maxburst)-1) / RAND_MAX; + int pos= random() * (uint64_t) length / RAND_MAX; + fseek(f, pos, SEEK_SET); + + if(maxburst<0) burst= -maxburst; + + if(pos + burst > length) + continue; + + while(burst--){ + int val= random() * 256ULL / RAND_MAX; + + if(maxburst<0) val=0; + + fwrite(&val, 1, 1, f); + } + } + + return 0; +} diff --git a/contrib/ffmpeg/tools/unwrap-diff b/contrib/ffmpeg/tools/unwrap-diff new file mode 100755 index 000000000..ccea99b7b --- /dev/null +++ b/contrib/ffmpeg/tools/unwrap-diff @@ -0,0 +1,2 @@ +#!/bin/sh +tr '\n' '\001' | sed 's/\x01\x01/\x01 \x01/g' | sed 's/\x01\([^-+ @]\)/ \1/g' | tr '\001' '\n' diff --git a/contrib/ffmpeg/unwrap-diff b/contrib/ffmpeg/unwrap-diff deleted file mode 100755 index ccea99b7b..000000000 --- a/contrib/ffmpeg/unwrap-diff +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -tr '\n' '\001' | sed 's/\x01\x01/\x01 \x01/g' | sed 's/\x01\([^-+ @]\)/ \1/g' | tr '\001' '\n' diff --git a/contrib/ffmpeg/version.sh b/contrib/ffmpeg/version.sh index c04822f46..f8b111cc7 100755 --- a/contrib/ffmpeg/version.sh +++ b/contrib/ffmpeg/version.sh @@ -1,11 +1,21 @@ #!/bin/sh -svn_revision=`cd "$1" && LC_ALL=C svn info 2> /dev/null | grep Revision | cut -d' ' -f2` -test $svn_revision || svn_revision=`cd "$1" && grep revision .svn/entries | \ - cut -d '"' -f2 2> /dev/null` -test $svn_revision || svn_revision=UNKNOWN +# check for SVN revision number +revision=`cd "$1" && LC_ALL=C svn info 2> /dev/null | grep Revision | cut -d' ' -f2` +test $revision || revision=`cd "$1" && grep revision .svn/entries 2>/dev/null | cut -d '"' -f2` +test $revision || revision=`cd "$1" && sed -n -e '/^dir$/{n;p;q}' .svn/entries 2>/dev/null` +test $revision && revision=SVN-r$revision -NEW_REVISION="#define FFMPEG_VERSION \"SVN-r$svn_revision\"" +# check for git short hash +if ! test $revision; then + revision=`cd "$1" && git log -1 --pretty=format:%h` + test $revision && revision=git-$revision +fi + +# no version number found +test $revision || revision=UNKNOWN + +NEW_REVISION="#define FFMPEG_VERSION \"$revision\"" OLD_REVISION=`cat version.h 2> /dev/null` # Update version.h only on revision changes to avoid spurious rebuilds diff --git a/contrib/ffmpeg/vhook/Makefile b/contrib/ffmpeg/vhook/Makefile deleted file mode 100644 index 167b8bfb0..000000000 --- a/contrib/ffmpeg/vhook/Makefile +++ /dev/null @@ -1,50 +0,0 @@ -include ../config.mak - -VPATH=$(SRC_PATH_BARE)/vhook - -CFLAGS=-I$(BUILD_ROOT) -I$(SRC_PATH) -I$(SRC_PATH)/libavutil -I$(SRC_PATH)/libavcodec \ - -I$(SRC_PATH)/libavformat -I$(SRC_PATH)/libswscale $(VHOOKCFLAGS) -DHAVE_AV_CONFIG_H -LDFLAGS+= -g - -HOOKS=null$(SLIBSUF) fish$(SLIBSUF) ppm$(SLIBSUF) watermark$(SLIBSUF) -ALLHOOKS=$(HOOKS) imlib2$(SLIBSUF) drawtext$(SLIBSUF) - -ifeq ($(HAVE_IMLIB2),yes) - HOOKS += imlib2$(SLIBSUF) - CFLAGS += `imlib2-config --cflags` - LIBS_imlib2$(SLIBSUF) = `imlib2-config --libs` -endif - -ifeq ($(HAVE_FREETYPE2),yes) - HOOKS += drawtext$(SLIBSUF) - CFLAGS += `freetype-config --cflags` - LIBS_drawtext$(SLIBSUF) = `freetype-config --libs` -endif - -SRCS := $(HOOKS:$(SLIBSUF)=.c) - -all: $(HOOKS) - -depend dep: $(SRCS) - $(CC) -MM $(CFLAGS) $^ 1>.depend - -install: $(HOOKS) - install -d "$(shlibdir)/vhook" - install -m 755 $(HOOKS) "$(shlibdir)/vhook" - -uninstall: - rm -f $(addprefix $(shlibdir)/vhook/,$(ALLHOOKS)) - -rmdir "$(shlibdir)/vhook/" - -%$(SLIBSUF): %.o - $(CC) $(LDFLAGS) -o $@ $(VHOOKSHFLAGS) $< $(VHOOKLIBS) $(LIBS_$@) - -clean: - rm -f *.o *.d *~ *.a *.lib *.so *.dylib *.dll - -distclean: clean - rm -f .depend - -.PHONY: all depend dep clean distclean install* uninstall* - --include .depend diff --git a/contrib/ffmpeg/vhook/drawtext.c b/contrib/ffmpeg/vhook/drawtext.c index 081847620..d3ca767fe 100644 --- a/contrib/ffmpeg/vhook/drawtext.c +++ b/contrib/ffmpeg/vhook/drawtext.c @@ -172,7 +172,7 @@ int Configure(void **ctxp, int argc, char *argv[]) ci->outline = 0; ci->text_height = 0; - optind = 0; + optind = 1; while ((c = getopt(argc, argv, "f:t:T:x:y:s:c:C:bo")) > 0) { switch (c) { case 'f': @@ -203,7 +203,7 @@ int Configure(void **ctxp, int argc, char *argv[]) case 'C': if (ParseColor(optarg, ci->bgcolor) == -1) { - av_log(NULL, AV_LOG_ERROR, "Invalid foreground color: '%s'. You must specify the color in the internet way(packaged hex): #RRGGBB, ie: -c #ffffff (for white foreground)\n", optarg); + av_log(NULL, AV_LOG_ERROR, "Invalid background color: '%s'. You must specify the color in the internet way(packaged hex): #RRGGBB, ie: -C #ffffff (for white background)\n", optarg); return -1; } break; @@ -506,7 +506,7 @@ void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, if ( ( (c == '_') && (text == ci->text) ) || /* skip '_' (consider as space) IF text was specified in cmd line - (which doesn't like neasted quotes) */ + (which doesn't like nested quotes) */ ( c == '\n' ) /* Skip new line char, just go to new line */ ) continue; diff --git a/contrib/ffmpeg/vhook/fish.c b/contrib/ffmpeg/vhook/fish.c index 1571cf9b9..be23dc644 100644 --- a/contrib/ffmpeg/vhook/fish.c +++ b/contrib/ffmpeg/vhook/fish.c @@ -124,7 +124,7 @@ int Configure(void **ctxp, int argc, char *argv[]) *ctxp = av_mallocz(sizeof(ContextInfo)); ci = (ContextInfo *) *ctxp; - optind = 0; + optind = 1; ci->dir = "/tmp"; ci->threshold = 100; diff --git a/contrib/ffmpeg/vhook/imlib2.c b/contrib/ffmpeg/vhook/imlib2.c index 4e6ffb67c..7df4c0aca 100644 --- a/contrib/ffmpeg/vhook/imlib2.c +++ b/contrib/ffmpeg/vhook/imlib2.c @@ -2,52 +2,6 @@ * imlib2 based hook * Copyright (c) 2002 Philip Gladstone * - * This module implements a text overlay for a video image. Currently it - * supports a fixed overlay or reading the text from a file. The string - * is passed through strftime so that it is easy to imprint the date and - * time onto the image. - * - * You may also overlay an image (even semi-transparent) like TV stations do. - * You may move either the text or the image around your video to create - * scrolling credits, for example. - * - * Text fonts are being looked for in FONTPATH - * - * Options: - * - * -c The color of the text - * -F The font face and size - * -t The text - * -f The filename to read text from - * -x X coordinate of text or image - * -y Y coordinate of text or image - * -i The filename to read a image from - * - * Expresions are functions of: - * N // frame number (starting at zero) - * H // frame height - * W // frame width - * h // image height - * w // image width - * X // previous x - * Y // previous y - * - - Examples: - - FONTPATH="/cygdrive/c/WINDOWS/Fonts/" - FONTPATH="$FONTPATH:/usr/share/imlib2/data/fonts/" - FONTPATH="$FONTPATH:/usr/X11R6/lib/X11/fonts/TTF/" - export FONTPATH - - ffmpeg -i input.avi -vhook \ - 'vhook/imlib2.dll -x W*(0.5+0.25*sin(N/47*PI))-w/2 -y H*(0.5+0.50*cos(N/97*PI))-h/2 -i /usr/share/imlib2/data/images/bulb.png' - -acodec copy -sameq output.avi - - ffmpeg -i input.avi -vhook \ - 'vhook/imlib2.dll -c red -F Vera.ttf/20 -x 150+0.5*N -y 70+0.25*N -t Hello' - -acodec copy -sameq output.avi - * This module is very much intended as an example of what could be done. * * One caution is that this is an expensive process -- in particular the @@ -126,10 +80,13 @@ typedef struct { Imlib_Font fn; char *text; char *file; - int r, g, b; + int r, g, b, a; + AVEvalExpr *eval_r, *eval_g, *eval_b, *eval_a; + char *expr_R, *expr_G, *expr_B, *expr_A; + int eval_colors; double x, y; char *fileImage; - struct _CachedImage *cache; + struct CachedImage *cache; Imlib_Image imageOverlaid; AVEvalExpr *eval_x, *eval_y; char *expr_x, *expr_y; @@ -142,8 +99,8 @@ typedef struct { struct SwsContext *fromRGB_convert_ctx; } ContextInfo; -typedef struct _CachedImage { - struct _CachedImage *next; +typedef struct CachedImage { + struct CachedImage *next; Imlib_Image image; int width; int height; @@ -164,8 +121,19 @@ void Release(void *ctx) imlib_context_set_image(ci->imageOverlaid); imlib_free_image(); } - ff_eval_free(ci->expr_x); - ff_eval_free(ci->expr_y); + ff_eval_free(ci->eval_x); + ff_eval_free(ci->eval_y); + ff_eval_free(ci->eval_r); + ff_eval_free(ci->eval_g); + ff_eval_free(ci->eval_b); + ff_eval_free(ci->eval_a); + + av_free(ci->expr_x); + av_free(ci->expr_y); + av_free(ci->expr_R); + av_free(ci->expr_G); + av_free(ci->expr_B); + av_free(ci->expr_A); sws_freeContext(ci->toRGB_convert_ctx); sws_freeContext(ci->fromRGB_convert_ctx); av_free(ctx); @@ -176,11 +144,13 @@ int Configure(void **ctxp, int argc, char *argv[]) { int c; ContextInfo *ci; + char *rgbtxt = 0; char *font = "LucidaSansDemiBold/16"; char *fp = getenv("FONTPATH"); char *color = 0; FILE *f; char *p; + char *error; *ctxp = av_mallocz(sizeof(ContextInfo)); ci = (ContextInfo *) *ctxp; @@ -190,7 +160,7 @@ int Configure(void **ctxp, int argc, char *argv[]) ci->expr_x = "0.0"; ci->expr_y = "0.0"; - optind = 0; + optind = 1; /* Use ':' to split FONTPATH */ if (fp) @@ -203,8 +173,26 @@ int Configure(void **ctxp, int argc, char *argv[]) imlib_add_path_to_font_path(fp); - while ((c = getopt(argc, argv, "c:f:F:t:x:y:i:")) > 0) { + while ((c = getopt(argc, argv, "R:G:B:A:C:c:f:F:t:x:y:i:")) > 0) { switch (c) { + case 'R': + ci->expr_R = av_strdup(optarg); + ci->eval_colors = 1; + break; + case 'G': + ci->expr_G = av_strdup(optarg); + ci->eval_colors = 1; + break; + case 'B': + ci->expr_B = av_strdup(optarg); + ci->eval_colors = 1; + break; + case 'A': + ci->expr_A = av_strdup(optarg); + break; + case 'C': + rgbtxt = optarg; + break; case 'c': color = optarg; break; @@ -232,25 +220,42 @@ int Configure(void **ctxp, int argc, char *argv[]) } } - if (ci->text || ci->file) { - ci->fn = imlib_load_font(font); - if (!ci->fn) { - fprintf(stderr, "Failed to load font '%s'\n", font); + if (ci->eval_colors && !(ci->expr_R && ci->expr_G && ci->expr_B)) + { + fprintf(stderr, "You must specify expressions for all or no colors.\n"); return -1; } - imlib_context_set_font(ci->fn); - imlib_context_set_direction(IMLIB_TEXT_TO_RIGHT); + + if (ci->text || ci->file) { + ci->fn = imlib_load_font(font); + if (!ci->fn) { + fprintf(stderr, "Failed to load font '%s'\n", font); + return -1; + } + imlib_context_set_font(ci->fn); + imlib_context_set_direction(IMLIB_TEXT_TO_RIGHT); } if (color) { char buff[256]; int done = 0; - f = fopen("/usr/share/X11/rgb.txt", "r"); - if (!f) - f = fopen("/usr/lib/X11/rgb.txt", "r"); + if (ci->eval_colors) + { + fprintf(stderr, "You must not specify both a color name and expressions for the colors.\n"); + return -1; + } + + if (rgbtxt) + f = fopen(rgbtxt, "r"); + else + { + f = fopen("/usr/share/X11/rgb.txt", "r"); + if (!f) + f = fopen("/usr/lib/X11/rgb.txt", "r"); + } if (!f) { - fprintf(stderr, "Failed to find rgb.txt\n"); + fprintf(stderr, "Failed to find RGB color names file\n"); return -1; } while (fgets(buff, sizeof(buff), f)) { @@ -272,8 +277,32 @@ int Configure(void **ctxp, int argc, char *argv[]) fprintf(stderr, "Unable to find color '%s' in rgb.txt\n", color); return -1; } + } else if (ci->eval_colors) { + if (!(ci->eval_r = ff_parse(ci->expr_R, const_names, NULL, NULL, NULL, NULL, &error))){ + av_log(NULL, AV_LOG_ERROR, "Couldn't parse R expression '%s': %s\n", ci->expr_R, error); + return -1; + } + if (!(ci->eval_g = ff_parse(ci->expr_G, const_names, NULL, NULL, NULL, NULL, &error))){ + av_log(NULL, AV_LOG_ERROR, "Couldn't parse G expression '%s': %s\n", ci->expr_G, error); + return -1; + } + if (!(ci->eval_b = ff_parse(ci->expr_B, const_names, NULL, NULL, NULL, NULL, &error))){ + av_log(NULL, AV_LOG_ERROR, "Couldn't parse B expression '%s': %s\n", ci->expr_B, error); + return -1; + } } - imlib_context_set_color(ci->r, ci->g, ci->b, 255); + + if (ci->expr_A) { + if (!(ci->eval_a = ff_parse(ci->expr_A, const_names, NULL, NULL, NULL, NULL, &error))){ + av_log(NULL, AV_LOG_ERROR, "Couldn't parse A expression '%s': %s\n", ci->expr_A, error); + return -1; + } + } else { + ci->a = 255; + } + + if (!(ci->eval_colors || ci->eval_a)) + imlib_context_set_color(ci->r, ci->g, ci->b, ci->a); /* load the image (for example, credits for a movie) */ if (ci->fileImage) { @@ -287,13 +316,13 @@ int Configure(void **ctxp, int argc, char *argv[]) ci->imageOverlaid_height = imlib_image_get_height(); } - if (!(ci->eval_x = ff_parse(ci->expr_x, const_names, NULL, NULL, NULL, NULL, NULL))){ - av_log(NULL, AV_LOG_ERROR, "Couldn't parse x expression '%s'\n", ci->expr_x); + if (!(ci->eval_x = ff_parse(ci->expr_x, const_names, NULL, NULL, NULL, NULL, &error))){ + av_log(NULL, AV_LOG_ERROR, "Couldn't parse x expression '%s': %s\n", ci->expr_x, error); return -1; } - if (!(ci->eval_y = ff_parse(ci->expr_y, const_names, NULL, NULL, NULL, NULL, NULL))){ - av_log(NULL, AV_LOG_ERROR, "Couldn't parse y expression '%s'\n", ci->expr_y); + if (!(ci->eval_y = ff_parse(ci->expr_y, const_names, NULL, NULL, NULL, NULL, &error))){ + av_log(NULL, AV_LOG_ERROR, "Couldn't parse y expression '%s': %s\n", ci->expr_y, error); return -1; } @@ -340,7 +369,7 @@ void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, imlib_context_set_image(image); data = imlib_image_get_data(); - avpicture_fill(&picture1, (uint8_t *) data, PIX_FMT_RGB32, width, height); + avpicture_fill(&picture1, (uint8_t *) data, PIX_FMT_RGB32, width, height); // if we already got a SWS context, let's realloc if is not re-useable ci->toRGB_convert_ctx = sws_getCachedContext(ci->toRGB_convert_ctx, @@ -410,6 +439,20 @@ void Process(void *ctx, AVPicture *picture, enum PixelFormat pix_fmt, int width, ci->y = ff_parse_eval(ci->eval_y, const_values, ci); y = ci->y; + if (ci->eval_a) { + ci->a = ff_parse_eval(ci->eval_a, const_values, ci); + } + + if (ci->eval_colors) { + ci->r = ff_parse_eval(ci->eval_r, const_values, ci); + ci->g = ff_parse_eval(ci->eval_g, const_values, ci); + ci->b = ff_parse_eval(ci->eval_b, const_values, ci); + } + + if (ci->eval_colors || ci->eval_a) { + imlib_context_set_color(ci->r, ci->g, ci->b, ci->a); + } + if (!(ci->imageOverlaid)) for (p = buff; p; p = q) { q = strchr(p, '\n'); diff --git a/contrib/ffmpeg/vhook/ppm.c b/contrib/ffmpeg/vhook/ppm.c index 9f618e55b..db76998b5 100644 --- a/contrib/ffmpeg/vhook/ppm.c +++ b/contrib/ffmpeg/vhook/ppm.c @@ -28,6 +28,7 @@ #include "framehook.h" #include "avformat.h" #include "swscale.h" +#include "avstring.h" static int sws_flags = SWS_BICUBIC; @@ -68,8 +69,8 @@ static rwpipe *rwpipe_open( int argc, char *argv[] ) strcpy( command, "" ); for ( i = 0; i < argc; i ++ ) { - pstrcat( command, COMMAND_SIZE, argv[ i ] ); - pstrcat( command, COMMAND_SIZE, " " ); + av_strlcat( command, argv[ i ], COMMAND_SIZE ); + av_strlcat( command, " ", COMMAND_SIZE ); } dup2( output[ 0 ], STDIN_FILENO ); diff --git a/contrib/ffmpeg/vhook/watermark.c b/contrib/ffmpeg/vhook/watermark.c index aa6fee63c..a8f7d5728 100644 --- a/contrib/ffmpeg/vhook/watermark.c +++ b/contrib/ffmpeg/vhook/watermark.c @@ -435,9 +435,9 @@ void Process(void *ctx, { ContextInfo *ci = (ContextInfo *) ctx; if (1 == ci->mode) { - return Process1(ctx, picture, pix_fmt, src_width, src_height, pts); + Process1(ctx, picture, pix_fmt, src_width, src_height, pts); } else { - return Process0(ctx, picture, pix_fmt, src_width, src_height, pts); + Process0(ctx, picture, pix_fmt, src_width, src_height, pts); } } @@ -544,10 +544,6 @@ int get_watermark_picture(ContextInfo *ci, int cleanup) return -1; } - // Inform the codec that we can handle truncated bitstreams -- i.e., - // bitstreams where frame boundaries can fall in the middle of packets - if (ci->pCodec->capabilities & CODEC_CAP_TRUNCATED) - ci->pCodecCtx->flags|=CODEC_FLAG_TRUNCATED; // Open codec if(avcodec_open(ci->pCodecCtx, ci->pCodec)<0) { -- cgit v1.2.3 From a1508e2f58d2c4b32d032d798f6f137262717e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Sat, 1 Mar 2008 03:07:38 +0100 Subject: Add extra include, dvaudio always have to use internal copy. --- src/combined/ffmpeg/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/combined/ffmpeg/Makefile.am b/src/combined/ffmpeg/Makefile.am index 93d9b8143..b9f0eac5c 100644 --- a/src/combined/ffmpeg/Makefile.am +++ b/src/combined/ffmpeg/Makefile.am @@ -57,4 +57,4 @@ xineplug_decode_ff_la_LDFLAGS = $(AM_LDFLAGS) $(IMPURE_TEXT_LDFLAGS) xineplug_decode_dvaudio_la_SOURCES = ff_dvaudio_decoder.c xineplug_decode_dvaudio_la_LIBADD = $(XINE_LIB) $(LTLIBINTL) -xineplug_decode_dvaudio_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/contrib/ffmpeg +xineplug_decode_dvaudio_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/contrib/ffmpeg -I$(top_srcdir)/contrib/ffmpeg/libavutil -- cgit v1.2.3